|
|
求大神给下面的程序做注解,请稍详细些,谢谢。- |( e% s) ?0 L4 a' d
#include <linux/init.h>
) C/ e% E' r ~3 }: q" l#include <linux/module.h>
( X0 n! O" z5 v% N# c9 T#include <linux/kernel.h>* k4 |# z& J; W* `4 A8 J
#include <linux/types.h>
2 G* s3 A1 z# a$ M! ~3 x T#include <linux/gpio.h>
. n" K+ x7 f8 O/ m#include <linux/leds.h>" I9 P& s/ h3 `: b% _0 d) B5 b
#include <linux/platform_device.h>) H+ v. y7 L: J' I1 J0 |" h$ X
R6 C( _: @" E
#include <asm/mach-types.h>
- s# I' t: e$ q5 C) \2 M6 H+ t. B#include <asm/mach/arch.h>
; g5 C& G7 t1 m8 U q% o2 e#include <mach/da8xx.h>
2 n" Q) D" |0 c: C J- Y#include <mach/mux.h> d8 ~* x8 F1 x+ G" O
4 S' `* W, d+ j7 ~3 Y; Y3 [6 Q, g
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)% I7 L/ i. q8 G Z5 ]* Y: w
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
5 `( ~, U6 F! f2 n3 h# p3 V8 e#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
1 M3 G5 i9 H9 [" y. X#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
; D- h: I8 S9 d' @# }6 {8 M5 [8 W9 ~; S( |
/* assign the tl som board LED-GPIOs*/
4 }2 G" m5 g P9 M! K" zstatic const short da850_evm_tl_user_led_pins[] = { v% |8 h N9 S! g6 l
/* These pins are definition at <mach/mux.h> file */0 p1 r: O( v& M% U9 N# e2 _
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
1 f" o2 i; z8 G -1
( D1 |3 L' q$ v+ l) L$ d' d" }};1 O' k; \$ m6 z5 f$ l3 J
" x% X8 q. p3 R1 tstatic struct gpio_led da850_evm_tl_leds[] = {9 c, V0 H0 W; k, h
{; b5 e4 }& t; O3 M4 O9 U
.active_low = 0,# l% T5 F3 \% Z1 {9 S/ O# y. r
.gpio = DA850_USER_LED0,
+ }) g$ H+ y: a% | .name = "user_led0",
0 C/ ]$ M5 a2 V" ? .default_trigger = "default-on",
9 W- D, S% T+ v, T$ G0 ` },9 ]! \: x4 K: C1 f- s" a4 R! \, i
{* a6 }. D# p% S, V$ `2 U7 I' v
.active_low = 0,
3 N+ A a( Y: C; H c$ l# t9 u: Q3 p .gpio = DA850_USER_LED1,' S3 Y- ]" l8 U
.name = "user_led1",
! p1 N0 H+ y9 ]/ r% h" c1 _ .default_trigger = "default-on",3 {' o4 [4 |; Y& o
},: M) K. H. Q% {
{
7 `+ f7 J. k, P# O* R4 P .active_low = 0,
; [3 O: z, X- W7 {3 C .gpio = DA850_USER_LED2,; R5 T. K1 f' A4 U/ J
.name = "user_led2",. }9 C9 S% K$ H/ b% j' \1 S
.default_trigger = "default-on",
+ P" a' j6 |/ u5 c6 c! x },
4 T+ K1 j& t! R% P: ?; L {0 Q2 x) E' T- Q6 H. e- M+ H* X
.active_low = 0,
+ A) _; X+ r# d) c0 Q- G5 ]1 ]( Q .gpio = DA850_USER_LED3,7 l! a, ?# T, c, O' F3 F9 `
.name = "user_led3",% g4 ?1 x( o! H3 N( c
.default_trigger = "default-on",; g+ n* G2 P( ^0 w
},
) I+ |: c5 N% d# Q7 b) `5 y};: n6 X' g) m; `# r. w
$ w" C* n( G6 Y& d" Mstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {3 r1 l6 U% j7 A @; p+ c- [' E
.leds = da850_evm_tl_leds,
; h8 a) ~3 T% }( G8 f+ O' | .num_leds = ARRAY_SIZE(da850_evm_tl_leds),) J9 P4 m. y+ J3 U( y G
};. j& a7 t' z& L3 q; Q) f" ^" x
& g+ f) S" w; c/ [7 G8 Zstatic void led_dev_release(struct device *dev)0 ~: N4 h/ ~6 d2 B5 }* g b3 @
{4 @/ I) t/ q$ O1 u' u- H
};
1 f5 F- I2 x9 a }' ^5 G& E: Y, E2 D2 Q( O2 O9 S3 s2 w) ]* F
static struct platform_device da850_evm_tl_leds_device = {' q8 T% z- v& l9 l) j" r
.name = "leds-gpio",. l5 O3 U$ \! L1 n, G8 L
.id = 1,# G9 R/ w! m; u5 d" L- F; A7 ]
.dev = {
- J) M4 j8 L: @1 C% k* U" k .platform_data = &da850_evm_tl_leds_pdata,
l9 [ P Z+ i) q+ {- o6 E2 R$ Z .release = led_dev_release,
/ E; W) w6 o# J0 e }& l* t* S a% j ]* P/ B
};) G6 R2 K7 n. L' n' D, u1 h6 O
R2 ?$ v' c, {7 v0 ~static int __init led_platform_init(void)
+ x0 }( s' w( a4 U8 Q2 J- m8 @{
/ y" \+ D# p# q+ s# W% w int ret;
/ _; h. F( v3 J1 s! w$ C#if 0
) K; l5 l: J" d2 T ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
& t, r1 H# O' Q: I0 H8 R1 u if (ret)& V- P, x: |2 q4 U- N L
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"4 W: H* v' c1 a2 V
"%d\n", ret);! k' l# g0 i4 ~( ]& L5 K1 s
#endif; X' a' Z: d% X
ret = platform_device_register(&da850_evm_tl_leds_device);
1 n% O8 ~2 @6 O0 u if (ret)8 C& r3 q6 k! g9 P8 f4 O3 @
pr_warning("Could not register som GPIO expander LEDS");4 n* q+ _' ~, J( z; @
else
9 {1 J$ y; ^; m( J printk(KERN_INFO "LED register sucessful!\n");8 p' y, D3 S2 x3 W
2 D3 K, m3 y+ J% b! `
return ret;; a! [2 O& ~7 s. k, s
}) W9 B# ~+ I! p6 B5 p6 m
) }6 o, |: ^/ ?- d8 V% q, }" k
static void __exit led_platform_exit(void)! k6 @$ t/ q8 y7 I! ^! Y# x
{
% ]$ w* {3 i. `2 s platform_device_unregister(&da850_evm_tl_leds_device);. E8 U) M V* i h; [
9 T& Z2 q" B3 l! E
printk(KERN_INFO "LED unregister!\n");
f# P7 ^7 o( U% d/ ?% R* k4 o}: n O: C! \! E3 h) B# m" T6 \
. P, K6 |- _2 w- g0 R7 xmodule_init(led_platform_init);
+ z6 R: X! I. W6 O- T+ d/ ^8 amodule_exit(led_platform_exit);: @0 M% p% R y- i
" |+ |+ ?- T3 g t" H4 Y
MODULE_DESCRIPTION("Led platform driver");
; V3 F% G( C3 `0 L' s) P" I6 _* KMODULE_AUTHOR("Tronlong");4 N% J% k5 e& t3 `
MODULE_LICENSE("GPL");
* r$ S- G% P6 Y4 {, n5 f3 G5 A2 r a
|
|