|
|
求大神给下面的程序做注解,请稍详细些,谢谢。' o/ u" Y, |* _9 b* b
#include <linux/init.h>
6 o e8 q% h2 N- y' O6 z#include <linux/module.h>
' M4 C* T( R4 y d; v( Y#include <linux/kernel.h>
( X& g6 `& {! Q* I#include <linux/types.h>: x' n5 |1 R$ F- p- l; ]
#include <linux/gpio.h>1 G, u7 U* g8 p7 S$ Y# i$ z4 Q) u
#include <linux/leds.h>. K6 W7 _) Z! w f* _. X2 b
#include <linux/platform_device.h>( y5 v, c( ^) r" X% v
) X# Z% _. r8 u9 ?! D8 }#include <asm/mach-types.h>
5 v9 ?& |) B$ I; r8 m#include <asm/mach/arch.h>( ~8 u; U3 Q9 A, f8 c$ l
#include <mach/da8xx.h>. H2 j Z* A9 `) }+ h$ j
#include <mach/mux.h>; i( S" G( u( ?- ]! g
. O( i$ t/ f3 B& S& |#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
: a2 c9 }! q" q/ I0 f#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
# E4 D, a2 I/ t5 C#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)% K/ F8 W! J* f3 T
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)- t( n" ^# H+ K C3 n
9 P# W) D6 V2 P: Q. {+ E; S! D/* assign the tl som board LED-GPIOs*/4 t3 t8 f3 Q+ ?; _9 X$ K
static const short da850_evm_tl_user_led_pins[] = {6 _0 p; K1 W C* F0 h
/* These pins are definition at <mach/mux.h> file */9 A- o# t) I7 |; D) p: \) B
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
! q7 @+ f# n7 |5 a P -1
$ N2 G) L( p9 d};
* ~( n# H9 Y# i/ D4 N6 V j6 S; s: l! Y' p3 K
static struct gpio_led da850_evm_tl_leds[] = {
/ q2 ?3 \' p9 r m {
3 s/ M" S7 m- C0 }0 y/ u7 {8 K .active_low = 0,: D d4 n% { @1 V
.gpio = DA850_USER_LED0,
! |0 Q0 M5 z9 H* S# W .name = "user_led0",
% N$ K7 _0 |& M: Y .default_trigger = "default-on",9 A, l& l) C' ^( G; J; w
},0 Z3 K) G0 `1 ]+ w
{
5 ?6 b3 q6 S% P; h6 o .active_low = 0,
' L$ E% s2 R+ J+ A$ w .gpio = DA850_USER_LED1,
$ V2 F- @, d, D .name = "user_led1",
: z) r3 L4 [1 D' l: |6 c .default_trigger = "default-on",
" `6 |* h: s/ t! @+ K Q: J },, A H+ R" g% r, e1 \$ ]0 M% C
{, w$ b" b* ^" u$ B1 k
.active_low = 0,
8 B" `" J( Y8 t" {2 \$ | .gpio = DA850_USER_LED2,: R! z4 Q8 Z6 A" j4 Z+ k1 H/ \- d6 W
.name = "user_led2",
5 g* ?/ \! P) J1 o, [ .default_trigger = "default-on",4 u* ~& r2 ~% E7 u( R. R- b2 q
},
- b+ ]) x$ l) I- F {
3 E( n/ J* K$ I .active_low = 0,
' Q' E$ H2 p1 J* Y" U .gpio = DA850_USER_LED3,3 E( P$ {9 |* @) O
.name = "user_led3",5 {& t9 D2 Y) g8 n+ C2 d
.default_trigger = "default-on",/ Y1 `. h* U# i" B
},: M3 s2 {8 j, |6 D
};
; Z, }+ J/ A' T0 B# c- \
/ W' v4 p1 `8 _static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {) N3 [9 r( Y1 Y9 Y
.leds = da850_evm_tl_leds,
: F+ R0 {5 @2 Z+ j; D0 I5 V .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
# q1 |! w! _, U) ]$ l};
$ h# S6 s1 X9 H" a: U
; h3 D' [' B7 @0 h nstatic void led_dev_release(struct device *dev)
8 ?& X, U0 Q9 v7 ]+ d+ X6 [{& R! r/ ^" ?; F0 o7 I2 V
};9 g1 m4 H/ j) x: v# q
2 E6 M9 @; t$ T% M7 b2 k
static struct platform_device da850_evm_tl_leds_device = {
7 ?- I2 ]; O6 z( a, A0 I: r( a .name = "leds-gpio",3 z0 Y) J) a& o
.id = 1, u- S) T% m/ K0 f' n$ ?' q6 l
.dev = {
7 j G7 Z& K, j; `- p! w .platform_data = &da850_evm_tl_leds_pdata,
0 n6 A0 d0 [! x .release = led_dev_release,
; E8 y0 l" P& F; M' Y }7 G! A5 s2 j& j" o" B' X9 x h6 X
};! U `. M' p% F# [2 W
8 D, y% J, W" nstatic int __init led_platform_init(void)2 a6 O7 R% r# t) v% @3 U
{% p) j1 {; ]0 W
int ret;" A: I6 }: C1 w7 C$ j0 G1 S: Z+ G
#if 0
) t ^1 p* I8 x; h9 r( o5 b) O ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);" l3 |6 Q7 z0 g/ {! M4 ~
if (ret)
' @2 J4 J0 t1 q4 R( M pr_warning("da850_evm_tl_leds_init : User LED mux failed :"# s& G* N7 f# p$ F4 s" b* O8 ~7 b
"%d\n", ret);
1 m% s& _5 Y' |* C#endif- m6 _- N5 Y* k5 m. W2 s0 I6 s" T
ret = platform_device_register(&da850_evm_tl_leds_device);; ^4 x+ k# ~7 w9 ^% z
if (ret). B! Z0 P5 u9 d7 e; k0 R- X# L) m
pr_warning("Could not register som GPIO expander LEDS");! Z7 N' l# _' i1 o3 V
else
1 g7 ~+ b- I& z M( V) s+ p* W printk(KERN_INFO "LED register sucessful!\n");/ t9 o5 Z: e" l, M; a
2 g( k" Q, v/ l% D/ S; K
return ret;7 K3 x3 z+ r# R4 y7 ]1 `; m
}
( P* [1 _* ?! n I2 _5 G7 ]
) B3 _$ h b- U- \static void __exit led_platform_exit(void)7 J: [& R& k# i, y5 v( l% y# r; X1 P
{7 N' I% y: h) Y
platform_device_unregister(&da850_evm_tl_leds_device);% R- s# i5 N4 ?- F# z4 {9 s: F
4 o" @: A6 @; J3 O printk(KERN_INFO "LED unregister!\n");
? N5 [5 M3 M' \1 k8 M5 e4 o8 x}
R: n4 F8 L' r! }9 p/ \: C9 w6 V7 M" ~! O
module_init(led_platform_init);" R* A" n* X5 `; k; f; K2 V' ~( f: O- h
module_exit(led_platform_exit);: u2 e( e6 J! W0 D! \% }+ t' z6 U
3 v+ D8 } v" \1 a: k& H; F
MODULE_DESCRIPTION("Led platform driver"); d- w5 l6 N, P, `1 W; c! s. h& c
MODULE_AUTHOR("Tronlong");2 |+ N. g) @: b( D0 S' U6 W
MODULE_LICENSE("GPL");
& Q9 u6 p- v- p& ]) U* Y
1 \( O8 O8 @" @& t |
|