|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
/ X }! L" `% T/ W p#include <linux/init.h>
$ t+ u' ~' E8 X+ K ~$ y9 e$ B#include <linux/module.h>7 p: S% s7 C) M4 x, _# N- c
#include <linux/kernel.h>5 I3 h) d5 c$ L: j5 N9 U
#include <linux/types.h>
, C* T# Q1 [6 I0 a3 c Y% _#include <linux/gpio.h>* ], l/ W/ c! C1 c
#include <linux/leds.h>
. N, V, [$ v; {2 g8 a#include <linux/platform_device.h>
4 f3 ]/ W$ y/ u
7 \; e% s/ m4 F4 P; b#include <asm/mach-types.h>
0 c9 c* K p, S1 [1 V3 p#include <asm/mach/arch.h>6 t5 u1 Y$ I( @7 M
#include <mach/da8xx.h>- @6 y( \; R" M5 G2 ^
#include <mach/mux.h>
# ]& e) q3 M( i( `5 @: N9 R. y2 g! v& g( L% U V9 `
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)+ w+ t; J* D0 x+ }
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
: L. U. B2 ]. {/ z#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
) h& j% Q+ T0 ]( ?( y- v2 \#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
/ @6 ~, Q% K! }0 Y% [7 j# _( W! c' G1 D, y4 L* E
/* assign the tl som board LED-GPIOs*/" M* e& S" i$ r0 u2 w
static const short da850_evm_tl_user_led_pins[] = {- c$ T* @ V w7 W0 t
/* These pins are definition at <mach/mux.h> file */2 J1 u" @9 V4 R- P
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,. L2 I% j) y. W2 t
-1
+ p- Q' T$ C4 A$ C};' x: W6 L% o4 c) W0 X$ L8 v
]; t Q* f4 X! Xstatic struct gpio_led da850_evm_tl_leds[] = {
# y( D, j8 S+ p1 \0 B: Z6 d! B {: y7 [; y+ b L; e q N
.active_low = 0,
{8 K. J* O5 ^: x6 G9 e7 T .gpio = DA850_USER_LED0,
) N; Q! t' h5 w) K( t, g" f; { .name = "user_led0",
/ K% _+ L9 F0 v0 N2 x% ?3 Z! Z m( j .default_trigger = "default-on",
: T5 X' S) H* o& B" _ },
( D# h6 f9 a- A. x- d4 D9 \2 T {
0 x' e; [: v2 ]1 ` .active_low = 0,' e! d$ H5 G0 A4 P4 P& w
.gpio = DA850_USER_LED1,
2 A/ E7 W& G9 X) r2 t .name = "user_led1",1 |' B' A0 B6 ?. s/ ^. B" R
.default_trigger = "default-on",8 e1 s9 x& W2 }# F& h" `+ ^8 X
},
0 @" B( `2 Z/ E {
) I; U+ f9 Q6 k5 N, K' j l .active_low = 0,
) U5 U! \" {; Y+ e1 M5 |3 {5 H .gpio = DA850_USER_LED2,
* \6 j# P3 I. w2 p9 ~- [1 S .name = "user_led2",
! I e( J2 C! c .default_trigger = "default-on",
9 Y& ~% h5 |+ P& z. d: S },2 c+ t1 x' W5 d; ?7 b
{( f, Z" r9 l3 }, Z
.active_low = 0,* g( C5 W* n8 x1 G& m
.gpio = DA850_USER_LED3,0 o' v/ I( _+ n& `3 P# D. d
.name = "user_led3",
# `2 t3 i7 l, b$ e .default_trigger = "default-on",+ p! N4 ]7 ]9 n( X- G5 Q
},
- \% C- P6 d$ x" W9 m};& q! s3 `+ N: O& s2 F# H3 O2 I, r5 z
9 I2 z" V; p' y& mstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
5 v+ p5 ?. D& x" w9 O4 u1 ~, | .leds = da850_evm_tl_leds,* p, W% I# i! l% p+ p3 i! \
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
) b! ]9 K% `4 N! T4 L3 U};
( J& F" j6 Z* ?! s* H( ~9 N( D" s, w6 E
static void led_dev_release(struct device *dev)
% L3 G' I2 b# i( J9 E' F1 _. Q! C{, \) k9 T% d7 I+ t3 }5 G) r
};
3 z& ]3 n. p$ |; V
7 n# m) u6 Z# k* J. T: r# ~static struct platform_device da850_evm_tl_leds_device = {
7 \/ [: U5 g7 }) R4 I .name = "leds-gpio",8 a* N0 Z8 c1 a) L! S: I
.id = 1,5 h. P/ ~* Z5 ?- y
.dev = {
+ N9 t0 |" n1 J1 t% m6 z .platform_data = &da850_evm_tl_leds_pdata,
1 [+ E' E' G( R8 L2 A# j. E y .release = led_dev_release,4 }+ I! c+ O! {7 X1 w/ g. j
}8 w8 S3 j; I T* W3 Z `# U# d' F! F
};+ o1 c3 [8 d7 i' X0 M1 i$ Q# ] z0 a
: T& | {' V' ]7 X0 t" e
static int __init led_platform_init(void)
) h1 z% o" K# h" c. t4 X5 k{: b6 w: a8 {8 N$ K& b$ @
int ret;9 n' m/ G: u8 I6 p! m0 W
#if 0: @9 @1 i( d a0 T
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
3 G& H8 ]8 b. _& _. s* n if (ret)
. u. |2 k" C+ \# B8 a. c# u# R5 L+ r pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
" S+ \$ \. a6 ] k) @. ~2 R "%d\n", ret);* b% S4 q: i+ A: G: u! f
#endif M1 K. Q. m- d/ _
ret = platform_device_register(&da850_evm_tl_leds_device);
$ |: \! [% z; ]7 C( H3 U5 b) `$ W if (ret)
5 h6 n0 G7 b$ N" \: X) n pr_warning("Could not register som GPIO expander LEDS");" |9 M! t$ A1 B( V1 Q' |
else
* T: t. ?' t7 x printk(KERN_INFO "LED register sucessful!\n");
2 ?- v( G: M4 u3 |/ o
( ]# s% E; A+ O: Q$ X2 p' p return ret;7 Q- ]1 ?" ?" Q' R; E
}
5 L0 [- u% j* Y) ^6 {9 p* {1 R/ ^$ h2 H5 B
static void __exit led_platform_exit(void)* J \% [6 G" q R& u7 V
{9 B5 D; C9 [# h% ?" r$ T
platform_device_unregister(&da850_evm_tl_leds_device);2 [ B7 ?: X1 {5 B3 y
3 R' p6 C) G6 j6 s0 b8 L% \ printk(KERN_INFO "LED unregister!\n");
# R! M7 f! S' C* K}
, G5 n! {( w4 c9 `
" S4 n( f# C1 \) Gmodule_init(led_platform_init);
+ P7 Y4 V' {( `( p7 g! \ k2 Mmodule_exit(led_platform_exit);
) Q. ]7 x+ r) x4 G& s
/ S. a; h- X; `3 H/ sMODULE_DESCRIPTION("Led platform driver"); A7 w% K8 V. k, |
MODULE_AUTHOR("Tronlong");
. j3 f9 o3 f6 k' D/ cMODULE_LICENSE("GPL");
7 p; V0 c4 \% p; R) |: ]) P6 y! \
; x5 y# }$ T! w) ^ |
|