|
|
求大神给下面的程序做注解,请稍详细些,谢谢。 d: N# p# h6 {) `
#include <linux/init.h>- n2 u0 x! O# E8 f$ ^( n
#include <linux/module.h>7 y" d8 h- u6 @9 F5 t% J
#include <linux/kernel.h>1 ~1 _6 n) v( H1 X, O! C3 d2 R
#include <linux/types.h># c+ z! L- @1 h& H- q
#include <linux/gpio.h>+ N6 M7 ^1 Z" n2 h
#include <linux/leds.h>2 `: @1 m" o: q7 h
#include <linux/platform_device.h>4 \/ L; c7 j6 A8 c3 K
* n. r* D- ~/ I4 S# R6 b6 P' o#include <asm/mach-types.h>' w/ q4 I, N Q. w; g f6 g
#include <asm/mach/arch.h>" v$ p9 G& W0 @' j0 m
#include <mach/da8xx.h>5 B+ T+ P6 w) X* k" |& U! w0 M* Z
#include <mach/mux.h>
+ c1 i- v. }! ~# I) H8 [% Q
) ~; M5 _1 ?. L#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)6 t7 m3 h8 Z4 _1 I d
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)) O8 M" c. M2 A3 p+ I9 o! _
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
I& {5 ?7 D4 W6 S) |( u#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)+ R1 ~4 J: p- p4 b
& Q0 ~# Y. V k' C+ t
/* assign the tl som board LED-GPIOs*/
8 L& [' I3 V+ y0 z* g* {5 A9 I5 u* Ustatic const short da850_evm_tl_user_led_pins[] = {
+ s; M1 H, p; |7 Z /* These pins are definition at <mach/mux.h> file */ e: ]0 z; s0 U- h
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,, m4 Z* Q$ J. N
-1
; k- G. Z" Z1 {0 X$ k4 B' V};( Y$ y. Q: W' D- }
' s' J4 I; O, Ustatic struct gpio_led da850_evm_tl_leds[] = {
2 S/ M2 _6 i; e6 G. }$ v }. V {. q/ T+ ]! x4 s' H/ I
.active_low = 0,
% @7 f# t, W& ]. F .gpio = DA850_USER_LED0,' {! `7 L/ {+ F+ A
.name = "user_led0",( p! Q" z. I- y$ e8 p) V" V& x6 Z
.default_trigger = "default-on",
; I3 }" E6 @; X \' ] },
' j' y$ P# D6 z0 _# `) w {$ Z1 J& D! y. Z- S0 X
.active_low = 0,
6 d0 M2 I: c" W7 B( [+ H; o. t2 e .gpio = DA850_USER_LED1,
7 N9 i/ Q. J5 W4 R .name = "user_led1",3 f# M; K) n' I7 Q8 ]" c# Y$ d3 K
.default_trigger = "default-on",
_% a N/ x& d; l, y. } }, j2 `5 M- L, V6 U
{! R+ N7 \7 }# t F8 P( `
.active_low = 0,
; y& y ]; e) S4 c% } .gpio = DA850_USER_LED2,* A: n& y) j0 n) V
.name = "user_led2",
$ k* ~. e! m( S .default_trigger = "default-on",
$ }* Z! A. C; H" p3 o( a4 R },. |. Q& \) E$ O) r1 n
{
/ W1 x* e! |; h e) I6 q1 s1 K( M .active_low = 0,. h" c7 u% M6 a3 D# }4 w' x5 @
.gpio = DA850_USER_LED3,
# M! [7 g3 f5 Q* ^. l9 a; J) @ .name = "user_led3",
! O/ x; `9 n+ Q5 x6 [9 F* S .default_trigger = "default-on",; D5 k/ {' O( z+ y
},
% l+ A1 D! _% f$ @% ]" c};
8 E3 c0 ~* c- N: K" ?
/ e2 n, Y8 {% ` y6 T* bstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {! Z" n- x( f% [+ }+ c0 }. h
.leds = da850_evm_tl_leds, S2 @% e) s/ g2 s) ?
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),( F6 a, k) b9 R
};6 g# |0 i3 g/ b2 V2 E5 X
1 a) J6 L$ j2 i% F7 E1 s3 G
static void led_dev_release(struct device *dev)' C+ f: H) R& q1 I- m# x8 i5 G5 j
{% d# C, g, e6 d3 R" u
};
, o+ x+ {, \% z4 [* Q" P3 ^ `5 I( O% |* _# ^
static struct platform_device da850_evm_tl_leds_device = {
; S$ d. v# |& X, E3 r: l: t1 a0 H .name = "leds-gpio",
1 q: J8 }* \9 S, v* x z6 g .id = 1,
" J8 E' v/ h! t1 L# _( R .dev = {+ u, K3 d; V' M0 B- B
.platform_data = &da850_evm_tl_leds_pdata,
% ^& f: Z4 H( G .release = led_dev_release,( b% |2 c, h" A5 J$ @/ ?
}( p! g; {7 L* E# W8 b# ]8 i! w
};5 e3 _9 q2 H- E$ E# o6 L
( R- z! O; W7 ~- e1 `+ {% _
static int __init led_platform_init(void)
% a0 {: K/ p9 ? u# E, E: O{
( e' \/ K x1 k% \6 X3 f* r7 _1 L int ret;
+ b5 P6 L- O7 v; U#if 00 g- t" }0 g3 l
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);' `! i* g: \4 Z( C5 ~, ~7 W) K
if (ret)4 R+ T. E: e0 K: v6 W) _: p
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
: }2 w2 q3 d0 }0 ^# p/ v "%d\n", ret);
b6 X- X. c5 x% N9 F- e#endif$ W( L, x$ v+ | E- f
ret = platform_device_register(&da850_evm_tl_leds_device);
# ]- N% ]& r4 D; ] if (ret)7 {7 J) d8 a( ^& S" n+ l S
pr_warning("Could not register som GPIO expander LEDS");, {/ S/ P! O1 f. s8 `
else1 a/ D0 I; z6 q0 a1 x
printk(KERN_INFO "LED register sucessful!\n");
6 t% v0 k0 a U/ U$ N# C' o0 u0 i# f) B5 \/ P: Z. R
return ret;! Z5 p3 Z {0 `1 h: [0 R$ d& I+ e
}8 S8 t9 T4 @, J8 B5 k% }
( w) @. ~/ ^6 d% k
static void __exit led_platform_exit(void)
# ^/ \. ?0 U) _* X6 j: D{9 b* M' \1 S! O, O0 _( p8 F
platform_device_unregister(&da850_evm_tl_leds_device);
4 c: `# [, H- E; g, E2 D9 f1 [
9 y; M- l9 g- l! v; |, ^ printk(KERN_INFO "LED unregister!\n");
h U! ~, ]: i# A# D3 p. r. i}
. r# b* ^/ b4 y. V1 p
7 A. m' r% \5 \$ S: j lmodule_init(led_platform_init);/ l! N: {1 E' {* [$ \
module_exit(led_platform_exit);
. n: \( n# U! d1 S! Q6 H$ x
! d% {+ r6 R) S4 B* wMODULE_DESCRIPTION("Led platform driver");5 }2 X! m& e: o- u2 r
MODULE_AUTHOR("Tronlong");# i+ A6 |5 X, d* h! G' W( O! Q
MODULE_LICENSE("GPL");" H4 Y; N' } d4 u+ M
# Y0 K) E& r) C# ?5 ^4 o3 ? |
|