|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
9 V, r7 x7 w. q4 r#include <linux/init.h>" k# f, Q" t! t5 I, z7 V
#include <linux/module.h>
& o9 A' x( L+ R6 T$ {" m6 n/ c#include <linux/kernel.h>
4 j! ?0 b: K# I2 ^7 u#include <linux/types.h>6 {. I: Y0 |, J( h# s9 J
#include <linux/gpio.h>
3 {( M6 k6 i6 x0 X3 m8 ?#include <linux/leds.h>
% Z8 ?1 w' [: R- U% e" F#include <linux/platform_device.h>
' q* B4 D5 ~9 D# ^, ?. L W) `
) V6 Z- L- ]( {9 H; g#include <asm/mach-types.h>2 H5 X( O% O& C! z/ H! x; [7 G0 P
#include <asm/mach/arch.h>
6 `( @7 g) e. P$ N. T! |#include <mach/da8xx.h>
" i: @5 O* Q8 W#include <mach/mux.h>
% v0 A$ @2 A3 t& ~8 b7 s0 P
' ~ u, Z1 M/ z8 e% f1 D( ^#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
+ F2 u0 a! t% j( l$ \/ i6 P#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
; \2 }# X' Q- T, f d) g. a#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
$ ]+ e E: |! o% L" y9 f L7 H* b+ ]#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)1 R1 i7 W5 |8 {! t- x
, a) m( I" v1 ^* L6 r
/* assign the tl som board LED-GPIOs*/
& D, |$ N$ r gstatic const short da850_evm_tl_user_led_pins[] = {9 Z8 S ^; j: j( y; ]- [
/* These pins are definition at <mach/mux.h> file */
1 G9 N v8 B4 [0 H( A DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
5 h8 Z9 R8 f6 F -15 B6 A2 C# M1 u) H- u& U
};
; S0 T% B/ S, l- I; s& W0 c' ], a+ R. u( ~" P4 L
static struct gpio_led da850_evm_tl_leds[] = {! [4 X% b8 l4 J' p2 t [6 a
{' |* I! H0 g4 h5 {/ _+ W
.active_low = 0,
3 q; F% ?2 ]4 m4 A9 a$ S! r .gpio = DA850_USER_LED0,5 q4 R+ d v7 q) B/ B2 y' W
.name = "user_led0",, s9 R# _2 ]+ T# n1 b' `, b1 G
.default_trigger = "default-on",) X& f/ P3 |1 z( u
},6 ?1 Z) w4 `3 p4 p; |3 h: x& u
{
, d! _- r2 X; z2 L7 l3 Z a2 r .active_low = 0,& k3 Q- C( W: A! c
.gpio = DA850_USER_LED1,
$ G- s5 ^7 q( l8 [ .name = "user_led1",
/ C; M/ b9 \% }$ j .default_trigger = "default-on",
% E6 i# d+ v% g9 {" K' Q },
* n, B7 N1 u5 y `( P {
+ b% U9 O" t a9 I' W! ^$ e$ O .active_low = 0,
9 F# w' `- ]6 U- {& I .gpio = DA850_USER_LED2,
. V) {0 l: T+ X4 ~ i0 P .name = "user_led2", A! F4 s# _1 R7 _
.default_trigger = "default-on",7 s5 v/ Z& W& P a
},
& {0 I7 B& q8 k P* S9 r {
* `; Z `8 ^) V/ h. M. q5 e+ n. G .active_low = 0,
3 L; u2 n- ]( Q1 H .gpio = DA850_USER_LED3,
! {* t3 D# x; s8 \ .name = "user_led3",4 a+ ]! }: I5 E" N2 l- T& O
.default_trigger = "default-on",
( V$ T% [. J Y, n: o },
; F# K: n0 g" ^) r};
4 |" D3 G# I8 s! L6 e* M/ K; o
7 i: F+ f6 G% pstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {7 C, _. @) j0 C3 i3 a* ~
.leds = da850_evm_tl_leds,
* a+ }# m+ [6 M& g/ }5 P .num_leds = ARRAY_SIZE(da850_evm_tl_leds),! D3 O% l/ L. }6 P
};
/ m3 {) I0 b) v* P3 Q$ b) l2 Q% t+ Q. {5 x$ w" Q U/ p6 u2 o5 }
static void led_dev_release(struct device *dev)* D7 I9 ^- | O; S
{ P4 x- u! W: k4 ~
};
! I$ Y* p% I, |* t: x# M! C5 ?: m! O$ r' \2 Q" T+ \6 k
static struct platform_device da850_evm_tl_leds_device = {5 @- |- W# o1 g
.name = "leds-gpio",
. q! P8 m7 Z% ]6 c9 n .id = 1,8 E) b& ^6 ?7 h/ _" i4 S) @
.dev = {
z6 c6 K2 ~: o8 s" O .platform_data = &da850_evm_tl_leds_pdata,5 p. ~* m7 a; H
.release = led_dev_release,% s I! m/ u' S' L3 ?# Q9 O
}
) }" x# I7 [6 m$ Q/ a};" W8 q0 f) R% |. r
" c; F3 L$ F0 f6 d3 l7 m0 R+ W
static int __init led_platform_init(void)+ k) F$ L7 v0 q
{; |9 q7 f/ i/ p0 `+ F
int ret;
2 A; [' u' n% `, b: x# H3 ^$ Y#if 0
+ ?+ W8 w. [4 F; h" Y/ B ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
4 O0 y- P' }: U7 r5 b if (ret)3 |3 b3 n. Z, a4 m' D
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
2 I7 ]/ u0 R. ? Y9 M "%d\n", ret);: M$ B! S2 y9 y1 c# c' S
#endif
- l2 W$ O4 w7 M/ l+ n# e7 n- t8 v! s ret = platform_device_register(&da850_evm_tl_leds_device);
- r7 X* B6 A" ?% B! s if (ret)
: W, q% {+ ~" U) d* p! x' E. ]" b pr_warning("Could not register som GPIO expander LEDS");$ n0 j- k, ]) e4 ^8 z* Q1 ]
else3 w2 I. S& S. l8 k6 \
printk(KERN_INFO "LED register sucessful!\n");% q F8 h5 u/ p5 x/ {9 w
- v& F o- l c N3 m4 U& T# D return ret;: w! U( g4 M2 m. H/ x8 L6 ^
}
: Y" w$ {& f2 L0 J# J2 ?1 m
0 [- j0 Q! _9 g+ _3 Dstatic void __exit led_platform_exit(void)$ \% b; Q6 U/ q- v0 F* c/ ?
{4 A! s# w$ L6 r: j, t+ E
platform_device_unregister(&da850_evm_tl_leds_device);
7 X& K1 Z2 i* U/ D* c$ W3 \: M9 r5 i. Q- r7 C) s3 a
printk(KERN_INFO "LED unregister!\n");5 a' e; R: l7 ^- `$ v; t
}; V- G9 H8 ^2 \9 U( r8 ^- M8 [1 N
- U1 y' U/ K7 l/ u, f3 i8 C' [1 Wmodule_init(led_platform_init);; e+ i( O( I0 l8 s8 m z
module_exit(led_platform_exit);
9 [5 r5 N; |: u& B6 z
8 n5 R9 u5 ]1 a% P5 e! S/ ?MODULE_DESCRIPTION("Led platform driver");3 X, V# m2 V/ t* g/ P
MODULE_AUTHOR("Tronlong");: N- z" T2 X3 |9 t' u9 h) G& t
MODULE_LICENSE("GPL");& [+ {- [& i8 s/ d: H; \
* u; I$ S4 X; b3 U |
|