|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
% w; ^; M9 }. X W, E#include <linux/init.h>
& j: R0 V* @1 _! p1 |4 t4 y) X#include <linux/module.h>
" G* l8 I# q+ \+ f1 x#include <linux/kernel.h>6 A* }7 S% _# P6 ^
#include <linux/types.h>
- M# U3 d+ P: L% }/ ~+ H6 N3 o#include <linux/gpio.h>
+ R4 N" ?* j8 B" d2 L }#include <linux/leds.h>
* ~! z6 c# w/ ^% P/ a/ Z% x7 R3 \#include <linux/platform_device.h>
/ s6 \) {$ k$ S k: L
1 h% i6 J# [! A; }+ x& D#include <asm/mach-types.h>
' Q0 k9 i8 G( [) k8 ]7 z5 b2 [#include <asm/mach/arch.h>6 {2 G; [4 j/ {3 `
#include <mach/da8xx.h>, P- N! C4 V+ A; B$ u, Q0 M" a$ ?
#include <mach/mux.h>2 W% y2 w8 p# P1 W0 i; y
! H1 k5 U3 G, u/ h* K. }#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
5 e' P! y: w6 Y3 v#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)5 i$ L. e5 S- K3 ], H! H
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)6 M- |3 V4 a4 j9 h
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
7 C/ ], g, l; D2 _ M
$ r) `* M9 K/ w/ t4 l# Z- y/* assign the tl som board LED-GPIOs*/: d- q# h* f/ ?/ c& F( [
static const short da850_evm_tl_user_led_pins[] = {
* ~% a: o9 v1 D% U /* These pins are definition at <mach/mux.h> file */. n4 w8 a5 I! U9 y6 G1 _. I" n
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
7 d" K- H8 h) b" @4 s8 y" a -1+ A9 Z& O9 _) P! I$ i1 ?) O M
};/ l* ^. `# C8 l v3 S5 y3 J/ Q0 T
+ E/ p4 i. K3 U+ T, q7 hstatic struct gpio_led da850_evm_tl_leds[] = {
9 u; g. c; C2 {0 P6 m {+ n+ \& O' l4 R L8 o9 z
.active_low = 0,
# c3 L/ r& b, _" l; w% c .gpio = DA850_USER_LED0,; q- y; _- L4 ]
.name = "user_led0",
3 K) J2 v; G0 S* d .default_trigger = "default-on",' W+ Z2 y/ |8 k% ~# y; d0 c& a. S6 ?
},. K9 @8 Y/ [( N# \3 c4 ?" E
{" n2 ~/ ~7 J/ o# M* z& m9 k" ]
.active_low = 0,
2 c J8 i- c( N, N' _* {" H, | .gpio = DA850_USER_LED1,
4 s0 c! W; y( y4 L0 Y .name = "user_led1",
* e' C2 Q$ P' _, }2 ]" f4 B .default_trigger = "default-on",
5 o8 \2 T4 r2 j% }6 Q, R5 C! b' ` }," \4 U, K0 o h# C7 y6 K5 p- v* _
{
4 c/ }$ j, J: I' ~- s .active_low = 0,
" A6 Y* y7 v7 w! h .gpio = DA850_USER_LED2,
0 Q: ^! L6 O& r1 N1 s! Z .name = "user_led2",
, S4 j0 m; n2 q0 V7 M .default_trigger = "default-on",, k# Q! h/ j$ K) ]
},/ O9 M5 F" V3 i) m( r( j
{$ f! o1 {; x" K$ n0 b
.active_low = 0,
" ] Y& W" P9 F g7 X$ @! w# k .gpio = DA850_USER_LED3,
) m+ u) B I4 h2 W% Q. t4 Y .name = "user_led3",
4 [+ {/ |3 g# ]: B. r .default_trigger = "default-on",
/ |# X6 i0 _+ Y e3 F },
# O. v" |% E: u" J! V};- {* M$ [0 h) v- [& X% o" U
5 Q5 ?7 t3 |0 T" Y- Y1 Astatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
3 a; _* M/ h3 _) @6 v% A0 g5 _/ ?3 v .leds = da850_evm_tl_leds,
% b% X0 g5 S8 f" J7 A .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
2 b- q/ j7 c/ M- g; X};
. L0 O V' U! z8 B3 [
) f, x" t" D- f* Dstatic void led_dev_release(struct device *dev): e, j, u6 u0 B( D$ U
{& M3 y$ Q- L. ]& F. e/ u
};
+ A. K0 [' _# ?. u9 F) z. ?; C
$ E, L& A) t# I5 N5 dstatic struct platform_device da850_evm_tl_leds_device = {
. T1 Q, O. M* J5 G .name = "leds-gpio",
4 R5 n0 I8 c1 Z; [( \) b- M .id = 1,% b T( x! r) w% q, M ]1 \, \
.dev = {7 {$ U% R8 Y/ y
.platform_data = &da850_evm_tl_leds_pdata,
y# z0 M# |7 P. b6 _* z .release = led_dev_release,
3 b1 o2 {' z+ h/ \# ]8 { }
8 V, q/ ?( p6 x6 W0 b# W8 F. D};. o6 ?$ `9 D/ F3 w/ \3 D2 u
) v& X, f( b' i1 N, T; ?
static int __init led_platform_init(void). f! j0 r& P1 @: [
{
) ?3 \- a: A/ L9 _" e int ret;1 i/ x& }, I4 z0 |& |
#if 00 v; ~/ o3 ~$ Y" W) d
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
1 w0 { \3 r* s/ T, D if (ret)
3 P( E. ~- ]. H- z; ? pr_warning("da850_evm_tl_leds_init : User LED mux failed :"# m w6 k/ [" N8 u
"%d\n", ret);
+ D9 P- K5 M, N+ i0 l( x% f4 k#endif
, R! S* a: P; v2 @ ret = platform_device_register(&da850_evm_tl_leds_device);
+ ]6 j. [) K% |& _3 P if (ret)
" C1 n# t% T7 m" i' Y" k pr_warning("Could not register som GPIO expander LEDS");" B n M& h( A+ o9 z6 R
else
4 \/ w5 s h6 X3 m. E9 E printk(KERN_INFO "LED register sucessful!\n");3 D+ g# i0 v; [& W
# f- _% m% h# I: F0 c% t } return ret;
) t) h1 D+ C8 ^6 r' ?}
+ |7 P; f- a% N b2 D! a6 H* H; | o6 r* U2 _/ _- Y
static void __exit led_platform_exit(void)6 ~$ k7 l) m* B. ~9 A
{
8 F1 @. \+ ]: e8 X, H5 V platform_device_unregister(&da850_evm_tl_leds_device);5 M- r8 p; x& x; Y" A/ S0 v
2 T* U$ x0 M! V+ x9 A
printk(KERN_INFO "LED unregister!\n");
& b5 t! ^& F1 y/ v/ ?}5 I9 @; F8 ?# p" d, P
9 ^2 n3 V5 A7 p3 ^: @module_init(led_platform_init);2 D9 V+ y, t) @) f/ h* q
module_exit(led_platform_exit);' @5 n+ E8 N6 D' |6 B2 S. n2 @
5 V8 {7 t. f8 U# e" v) ZMODULE_DESCRIPTION("Led platform driver");5 r3 z; k3 Q& l3 p
MODULE_AUTHOR("Tronlong");- s0 e: F: S0 [
MODULE_LICENSE("GPL");! a! @2 G9 h: ?1 t( N9 t9 k8 f" t
$ S, U( A4 @- @$ D
|
|