|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
" n( k( d w* r! a; p& o#include <linux/init.h>" l. W& ~3 b6 m7 G5 ?
#include <linux/module.h>
2 S* U! p. Y4 `/ ^. g: `, q5 d#include <linux/kernel.h>
4 z7 {* x1 |; O- n. e2 Y4 c#include <linux/types.h>2 i& s! z' T4 J3 R! P% E+ I
#include <linux/gpio.h>
- F/ H& l2 q, l& R#include <linux/leds.h>5 u, o; { T. t2 h' D8 e0 k! f1 [
#include <linux/platform_device.h>
$ r2 ~* N: J* d0 _9 J. \# K+ ?2 y6 e- d+ O) o
#include <asm/mach-types.h>
+ l) I4 ?0 b" U#include <asm/mach/arch.h>
4 w6 ~+ \4 h1 x5 z& M8 ~#include <mach/da8xx.h>0 T7 B o; Z. i0 P" @" p) ]
#include <mach/mux.h>; i7 z7 a6 ]: x1 D
; I( b2 ^1 n9 Y; d3 _1 N/ @ m#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
, o+ M; O/ e0 E1 T: l#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
0 f) o3 h3 P) r$ y- }/ g( A( H$ j#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)7 P, D2 y0 K- N5 m+ f1 Z7 O3 i
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
2 y0 k3 U/ K: R' q0 z6 X- k
# _; y- k# g) L2 `) c. B/* assign the tl som board LED-GPIOs*/
; H1 l$ B4 M2 S0 cstatic const short da850_evm_tl_user_led_pins[] = {
+ K; o% C8 [$ P /* These pins are definition at <mach/mux.h> file */+ |$ h3 _0 h* @1 A1 D1 K! a
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
- K8 q1 v4 W/ M -1; S3 x2 c; ^- s1 ~$ S1 k/ ^! |1 J
};
a; `9 p% u7 L
6 a3 p9 I( X _' `6 Z7 \: _# Mstatic struct gpio_led da850_evm_tl_leds[] = {
$ F- J2 ]4 i9 a b/ B' O9 u {" ?5 x2 `' Q" \
.active_low = 0,0 @4 |" C9 \% U. W: x
.gpio = DA850_USER_LED0," g& i' w( ~& R$ y, G- d
.name = "user_led0",( x! c7 l+ F; S6 J9 _, @( ~
.default_trigger = "default-on",
" B! w' L0 O$ K% \7 m },
3 }: _ d0 Q$ T; m+ D) u/ {- L {) i9 k0 ?& w0 V% M; @# s" X
.active_low = 0,
- D$ B! P+ ?2 l! n8 Y' I% j .gpio = DA850_USER_LED1,
4 x' s* ~7 Y. z' S. b8 U) L) B .name = "user_led1",
4 T( A. \, `5 I9 @' ^: T5 x .default_trigger = "default-on",- u) I1 ~- `: Q5 C
},8 e% O9 E, W, Y8 {6 d0 W5 k( `
{1 Q6 q2 X4 s) h
.active_low = 0,
# b' c/ s* e z. U .gpio = DA850_USER_LED2,& U* k9 Y0 N8 F$ U
.name = "user_led2",
9 s/ o# ^# Y+ T* F9 c .default_trigger = "default-on",
9 T6 P b% t- u# {' H, ?5 {/ p& q },
1 Q* n# t% t) p/ a, _3 P {4 M: o9 q* v: i, \
.active_low = 0,
+ p; M* j9 ~$ I1 N .gpio = DA850_USER_LED3,
. y. l! [% o- y1 d# x2 B/ |& t .name = "user_led3",3 l) R3 ]: m1 P
.default_trigger = "default-on",/ z4 l3 Z) a9 B; Z# t
},
0 f1 R. {8 n/ r- Q};4 Q4 v; X n! U6 D8 s* Z- j
" @+ E3 w8 s3 Fstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {5 L$ Z' h9 N- d8 k2 I# F
.leds = da850_evm_tl_leds,
! y P5 d L$ x! z5 X% L9 k) K+ j( N .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
1 ], e) O( L$ [2 A};
7 ?) }- o+ g9 X* u/ K) f7 H, U- M* F: h3 q5 S+ d, b: v6 ], I, Y" u) r5 v
static void led_dev_release(struct device *dev)' Y+ O, _/ Z) E; W8 a. ]8 j' d
{
2 w o9 [- s; V9 x$ m};- D- `8 f) D* n
2 I% \9 k O# C/ L; J" [static struct platform_device da850_evm_tl_leds_device = {7 K, Q& I& O$ K6 G9 l2 t
.name = "leds-gpio",
* L' i4 j$ m! E) S .id = 1,
+ `. s+ Y! s; A5 Y. T; y, c .dev = {4 x( J4 D1 e2 s+ Y8 `0 r* S# V/ U
.platform_data = &da850_evm_tl_leds_pdata,
; N8 k$ G+ H$ t .release = led_dev_release,
3 H1 F0 Z$ F/ w2 d6 m* q- r* ?7 H }' e- j" o: d- F! n5 ~% f6 k
};
8 w6 T. N* ?1 D: h) \8 k4 d5 V0 R: Q* B8 [: M- f$ m& ^
static int __init led_platform_init(void)5 q( D1 O, r# C2 O
{) D1 r2 p7 U8 T- K9 J- t0 |5 _
int ret;
) l8 q* E) Z# V" `0 H2 q+ j#if 0
" b$ R9 I# m6 ^( x1 R ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);5 V z+ [3 P# m% k; ]+ b
if (ret) Y1 E, Y: h# C) O8 p9 I
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"' O9 {. x0 b1 [. A8 z1 { Z- k- B# b
"%d\n", ret);% u; O! R2 u$ I- G% N6 |
#endif) Y: F% ^# B' R' P* y+ L1 l) C4 d* i
ret = platform_device_register(&da850_evm_tl_leds_device);
8 t* v! g: `1 D6 A+ G, F. v/ A if (ret)3 Z( P& m d+ b, U. o* c: o+ ^9 K2 h
pr_warning("Could not register som GPIO expander LEDS");9 w5 \6 Q5 o/ t: E1 d& Z6 N4 S
else
& v! y6 j' W" R' x x4 T printk(KERN_INFO "LED register sucessful!\n");
) B, ^( m5 \8 C' g5 l- F
9 Y( }# z8 b+ ~: t5 r return ret;
) L. P. i5 C F" D$ }" j' ^+ V9 l}# B+ X8 [, m2 i1 j1 m1 _
; c9 L8 B- ^7 q7 `: astatic void __exit led_platform_exit(void)2 u# k m I; V- n' [7 f
{1 z6 I1 n# k6 X& f" y# X
platform_device_unregister(&da850_evm_tl_leds_device);/ e( N G$ A7 T8 L j
! C% m2 C3 |8 U: E printk(KERN_INFO "LED unregister!\n");
' K7 T. D: Q/ X3 S* N$ F& y4 W' ]}
g# ~( Q$ g/ R$ c5 |3 x- Q
( {+ c9 ~) L5 c; n( ]& S) Umodule_init(led_platform_init);
( e, S8 }% K( x0 Y9 ]module_exit(led_platform_exit);# t: `9 ^. U( J) D; r( k8 I
; P s& y" B. g! }% M% C* N% v
MODULE_DESCRIPTION("Led platform driver");
5 l( u1 O$ b& t6 W9 ?" KMODULE_AUTHOR("Tronlong");' e; U; V+ r/ v
MODULE_LICENSE("GPL");5 E2 }- }5 A- N J6 b
/ B2 E9 @' N( s; m+ q+ r1 H |
|