|
|
求大神给下面的程序做注解,请稍详细些,谢谢。: H7 C* e5 U7 O
#include <linux/init.h>
) v4 O" i |" |1 d' a* l" H- ]#include <linux/module.h>
5 C/ _9 f6 [/ X( G/ k& F#include <linux/kernel.h>
. J% b, d5 W+ k2 L& k7 l: e! R#include <linux/types.h>
m# r! F' Y p' n6 P) j: i#include <linux/gpio.h>, b, o- ~ @/ Q9 `, j" @4 b
#include <linux/leds.h>
5 C2 F/ S) p) F#include <linux/platform_device.h>
0 o: z8 E% a3 [" K4 s# J0 M; Z$ h \
#include <asm/mach-types.h>3 L7 M; K9 t, v6 f9 i
#include <asm/mach/arch.h>8 t. J7 c7 E* O, \- R; F
#include <mach/da8xx.h>' E/ ?9 K6 X, n& R8 y+ m7 G
#include <mach/mux.h>
0 R: E9 H8 C3 s [- n' O+ V! [6 N3 o! ?8 Q5 V& U% \
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0). f* o% s) ?, j% Z: Q$ Q: `9 c: M0 ?
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)6 z; A L- M* ~5 `9 G1 }. a4 d
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
! _; x6 ?. T+ I% q#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)) s' L, ~$ X- D2 E' }, W
- q0 u3 A. d/ v# |+ X/* assign the tl som board LED-GPIOs*/
- }4 [: \9 L$ E) s$ [0 M% n0 r) _static const short da850_evm_tl_user_led_pins[] = {4 `: c& ^/ ]% e. F8 Y" I
/* These pins are definition at <mach/mux.h> file */
2 A9 v( w1 M; } DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,7 D2 i' g0 X% N6 @5 R/ d
-11 `$ U; L% Y6 b/ J* Y5 l& Q# S
};: A+ o- `# n* M
) M2 {) v+ Q7 o+ K, L
static struct gpio_led da850_evm_tl_leds[] = {: M% R x2 E4 x" D! R) r+ f
{
: V. l+ Q2 f1 O J .active_low = 0," m6 ]1 \2 N6 E, C9 @3 ^
.gpio = DA850_USER_LED0,
. ?* z# D6 \! H$ h) M .name = "user_led0",5 G; h V0 q0 Q0 q3 m
.default_trigger = "default-on",# w( {6 W2 v% m' T3 Q# v( O, A
},
' R( U _9 H9 j {* H1 z8 s. v( l ~4 y
.active_low = 0,
; N: a0 f7 b% X .gpio = DA850_USER_LED1,
; f; K6 U. }+ E+ O .name = "user_led1",( \) X7 A: W6 j; W5 ~0 N9 L
.default_trigger = "default-on",
5 z: q/ a- J6 U& O+ @7 l% | },$ Z1 U7 m# x8 J" m6 E5 [3 R6 v
{/ L# j1 t' h! c5 x/ q4 v" {8 \( L
.active_low = 0,' J- {% F; u8 k+ X- w; ^
.gpio = DA850_USER_LED2,
( `. h1 X: X( w+ X7 h .name = "user_led2",6 m) S' H5 q; ^% M
.default_trigger = "default-on",
/ G! p6 j' t3 W0 F1 Q* E" S# w },
( h t/ M9 F3 v" X3 i$ i6 d' T {
# I" P8 K( M, U* D# s .active_low = 0,5 k- g G) j7 i1 G) A2 x& i
.gpio = DA850_USER_LED3,0 F- X# M& V r: ^* o0 W
.name = "user_led3",5 m+ A6 r- J+ o6 j; ?
.default_trigger = "default-on",
6 L, ?0 ~0 V4 A! o, I },* o4 q7 w! z: b/ O
};) e& E# J/ l5 n: m' n$ ~
! S! C; n: R! gstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {0 V. ?) G/ o7 e. C# X# @
.leds = da850_evm_tl_leds,& e h% L' U) e; o; J5 D5 F
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
3 _. i5 k! ]7 i& \};
. P+ Z- |) `3 M0 T9 \; h7 {: M
static void led_dev_release(struct device *dev)7 h: s: U1 D5 r. O4 b) _- v
{
0 V2 _! }6 O/ t# }6 c" m}; y8 A$ n+ K/ I' ~
4 |4 W- C6 ^+ ostatic struct platform_device da850_evm_tl_leds_device = {
* b4 K8 |* V$ h% {" _# T .name = "leds-gpio",- S2 h3 Z7 W3 j0 l
.id = 1, b1 N$ W& s5 `; l1 B
.dev = {
& m4 m1 s# ~( Z6 `9 \ .platform_data = &da850_evm_tl_leds_pdata,
+ t* O. e1 f. F .release = led_dev_release,4 H2 P3 J7 F( f2 q5 L% I
}
1 x6 O" H! u) [. Z};9 K4 ]/ u) [, F- r' M4 w- r" P
9 V1 V. S4 u# P: C: u
static int __init led_platform_init(void) M$ x0 }7 S3 [ ^! i* h5 W0 g
{* g. R5 p6 N+ r8 G
int ret;
4 S. H& U' s: h#if 0
6 U: a5 e' b8 K8 n6 R' |. ` ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
$ W2 g. J; e2 C+ ~! ~8 Q' V if (ret)7 b" L. S% B4 [! d) u$ o
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
; F' w; e1 {; a "%d\n", ret);
; V2 r Z( J6 n7 X, k& B: Q) ?. `$ R#endif
; e# X7 }! q7 \9 u1 G ret = platform_device_register(&da850_evm_tl_leds_device);5 u: z: ^$ I/ n) m
if (ret)) U- ]' h; }/ U8 G, r* h0 T
pr_warning("Could not register som GPIO expander LEDS");3 K3 z% O; @2 ^% B% m) c$ S
else
2 `- v: r2 V7 a3 D printk(KERN_INFO "LED register sucessful!\n");
0 e2 O4 `8 ?; N( r( Z6 ], m$ f* w8 q" q5 n* P, ~- P: k" g
return ret;
$ P5 b; E, H/ q7 d4 p5 z}
$ `4 ?- k5 N( a, x4 [+ Z# s o6 v: }( Z0 @* G9 ~7 R1 o
static void __exit led_platform_exit(void)
- r, H( H% I% O; ?% Q* n{
. o! \1 J2 d' K' i; B$ @0 w5 C platform_device_unregister(&da850_evm_tl_leds_device);
" @3 P# ]' B6 _+ {5 b3 h$ d$ K% O; X- {& z: N' }
printk(KERN_INFO "LED unregister!\n");: p z+ `: ^3 b6 c- d: ]6 m
}' G' U2 O4 d6 T: z8 V2 E- P! j
& U9 c7 q4 j( j4 y+ h5 M2 s) d8 ^" `
module_init(led_platform_init);
, e q2 d# p, B2 kmodule_exit(led_platform_exit);
) L) Q: |% n; W# G: O
7 w1 J" T& k) j+ NMODULE_DESCRIPTION("Led platform driver");
4 s- r: T; Z6 |& I# D$ wMODULE_AUTHOR("Tronlong");
: F9 o' @$ G) I h1 S! z3 J2 b) qMODULE_LICENSE("GPL");9 _- y" s; V4 X3 ?
) R( J$ G5 G; b; F( S
|
|