|
|
求大神给下面的程序做注解,请稍详细些,谢谢。) |% A# }$ z0 j7 b5 ]
#include <linux/init.h>! k' }' d9 n5 r5 o3 e* L
#include <linux/module.h># x- ~$ o* V6 v' b( D
#include <linux/kernel.h>
1 S4 _' U# m6 l* _% J' ?#include <linux/types.h>
7 ~, D, C2 q( }- @1 ?#include <linux/gpio.h>
( h$ m9 W& H- \& k" O. N#include <linux/leds.h>7 G2 a' ]7 T; S7 v, i" x/ c
#include <linux/platform_device.h>1 {7 R9 Q1 P1 a" K
( G/ m8 q" T; L2 x0 X#include <asm/mach-types.h>1 U2 C O B1 n! P+ @( s
#include <asm/mach/arch.h>! w: Y- b$ `; L* I, p" C2 U+ {+ }
#include <mach/da8xx.h>
2 J: M: b( q3 c- D7 f# Q/ _% H#include <mach/mux.h>; G$ v% x1 g" w# E' X1 |2 w
. j. B& [9 G' V$ R
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)1 d6 j- g3 N/ l, q
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)% O; b' z2 u/ R+ G! V* D( w: S
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
( b& X' T& q1 J' |2 n) I#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
! `2 Y: ] J J3 Z% n$ R# J ]8 e1 v% L: W w' ]
/* assign the tl som board LED-GPIOs*/" P; i+ N, X) I% s5 u& g
static const short da850_evm_tl_user_led_pins[] = {
& x+ v- t6 |' i0 c /* These pins are definition at <mach/mux.h> file */
' b3 x# D8 z) r! H/ C2 Q DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,( P1 g- f9 n5 a
-1& R4 S: I0 H# f
};
6 `- j7 x* Z: E+ t4 W/ T' v+ D6 ^ V [$ m! H( x
static struct gpio_led da850_evm_tl_leds[] = {
5 F) P4 S0 G' K; @% T {
/ G! ]2 k% q4 r5 I- f .active_low = 0,
+ H9 O; f+ P2 Z! x* A .gpio = DA850_USER_LED0,
}$ x6 m1 C5 r8 H, J .name = "user_led0",
. d9 j5 W' M( n$ v .default_trigger = "default-on",
! x8 t2 e1 b% R },9 B1 H1 Y _' ?
{3 f) @ g# n( K: n. e. C
.active_low = 0,
9 a- y* {9 T; B& l; O, H: ~# f .gpio = DA850_USER_LED1,4 V0 [) ?/ m6 [& @4 r, B
.name = "user_led1",
* G2 a4 A$ J/ B$ A7 [8 ^+ Y .default_trigger = "default-on",
6 p# ]7 y' Z+ ]* h' u3 V* N },
% Q2 V8 {& P% D+ e {
) S% f7 z& }4 I .active_low = 0,
3 f, `5 t; l3 v- U* m .gpio = DA850_USER_LED2,: h- ]" q4 S V4 k5 X
.name = "user_led2",
* {" o) b( l- x1 k .default_trigger = "default-on",
8 y- `7 {* f' n& ` },
# y& a& k6 v1 w2 B3 R. ? {4 J/ f; q( K+ h5 r) d% k% a+ U
.active_low = 0,4 {; a4 x4 r: o6 [- ]# @
.gpio = DA850_USER_LED3,( h: B, m3 h) B6 }3 d% D* c z5 F
.name = "user_led3",
* |1 o, u+ ]+ R: W# G3 k .default_trigger = "default-on",) c% ~# j2 x6 w3 ?9 w$ ~. J
},6 C% l) X$ a5 D) l d l
};
3 F% k8 D$ D" B' Y: u2 j5 q |
3 n, u) x3 o" Cstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {. d- S" S3 S9 E+ I, b
.leds = da850_evm_tl_leds,& Z5 ~. Z# K$ p j9 _7 T1 f! [0 p5 Q
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),6 Y; `# |) M* k4 P
};
7 u6 Z$ q- @' s" n% S
I( X5 n% _( N' c' [$ M, Mstatic void led_dev_release(struct device *dev)9 q/ v: K! `, Q" P' }( U, z
{
+ l# V1 y5 m! K B4 h& q0 W+ B' p};
6 t; D* B' k, C2 ?% o2 \$ j7 W: p
3 Y3 z* P! F- W3 ~7 f! }: kstatic struct platform_device da850_evm_tl_leds_device = {5 K( O+ Q+ @7 N( R
.name = "leds-gpio",7 L1 ]6 I6 G& L5 ?5 T
.id = 1,* C+ q- h( \/ A
.dev = {
! R% O) d! ?( o .platform_data = &da850_evm_tl_leds_pdata,
9 P( }* G! |* `/ h# h/ T0 I* R .release = led_dev_release,- e7 ^% S* L* o
}- w2 o% c+ S# m7 w; ~- v$ f
};7 U& f( M q4 D6 H2 q' n9 M' ]) n
" }5 W, o# l. g. g( R
static int __init led_platform_init(void)
- c4 j( a* O( a& B8 n* m5 y+ B{
! D# q4 a; K% Y/ r3 \' Z: a+ z int ret;
& z4 t* D7 X( H: O#if 09 w0 g8 k3 ^9 s
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
/ g q' x+ T# I if (ret)
, Z- @. G, g* H2 J7 Y0 G pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
" c. B! X: h( H/ B, Q/ C {/ u6 j "%d\n", ret);0 C# q7 {) _( R
#endif1 t$ C" p5 a& v( x1 Y+ `# q( u% b
ret = platform_device_register(&da850_evm_tl_leds_device);& R* X5 F( C4 V& a# p% d
if (ret)
7 z& |3 t& ?5 E! R pr_warning("Could not register som GPIO expander LEDS");% {0 w; e* O) w7 [( }8 j+ ?9 ?8 L* C
else6 F4 |" F% e! H/ c
printk(KERN_INFO "LED register sucessful!\n");
) L4 f! s4 X1 \' I) K. }! }* |( S/ B# s+ j8 ?' V& n3 W9 n7 ~) ]5 g" j
return ret;# d' L! y9 s% U; F2 w
}
9 ]: k: @4 X& G0 C7 h4 J% l+ h. ^. \3 g/ f7 M3 i `7 C
static void __exit led_platform_exit(void)
% t* W1 p0 p4 h+ h{
' Y& r" W8 q2 b! d+ y; D platform_device_unregister(&da850_evm_tl_leds_device);6 D* g+ P3 T* @0 l4 k2 O1 ], L% H
6 k% p" f$ w o+ h& p- ? printk(KERN_INFO "LED unregister!\n");3 E/ ^/ r6 }/ T7 Q I' j
}
3 {: K0 L! ~+ N r
- a0 [3 l1 F, E( y: j* f" @/ z* W! s& m+ \module_init(led_platform_init);
/ J) j! R8 M: \ {0 O8 fmodule_exit(led_platform_exit);8 x6 w% s$ O+ N+ Y- P
I. M! T d3 ~! F( I: P2 n
MODULE_DESCRIPTION("Led platform driver");: E5 b: W6 ?( I* f v# @- o
MODULE_AUTHOR("Tronlong");+ `8 G* G! v4 D5 ~+ E" V
MODULE_LICENSE("GPL");( W1 F" p x! D" Y& c8 x$ B
, @( S1 f8 Q( U& b8 N7 v' ? |
|