|
|
求大神给下面的程序做注解,请稍详细些,谢谢。2 n# Z& h e8 Y$ f
#include <linux/init.h># y- _" w6 ?6 M* Z* v
#include <linux/module.h>
0 i$ G ]( q. @5 _0 D#include <linux/kernel.h>; i: e& K0 C( q# R' h% h
#include <linux/types.h>) I% S$ s9 V5 I# H2 n
#include <linux/gpio.h>& d# m U. k' K7 d, x4 S
#include <linux/leds.h>
$ {: B, R) q2 {# c# B) ^# ^#include <linux/platform_device.h>
7 }3 L( U* E4 b
8 {% T* E! ]4 n. ?#include <asm/mach-types.h>
2 P4 S1 d- w( v1 w) H8 t#include <asm/mach/arch.h># Z- C3 V2 [, S
#include <mach/da8xx.h>
2 Z7 v- W5 x3 L3 Y ^#include <mach/mux.h>: ?5 S+ D; O0 r4 z
5 M* N0 ~ ?, Y; d$ f Q. `#define DA850_USER_LED0 GPIO_TO_PIN(0, 0): o6 T O( D5 u7 H/ A6 A0 @
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
2 y" ~% Y) l8 V; @ o. C/ i#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)# D9 z: k" s& p9 [; ]
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
* u& `* D" b d- G1 s/ c$ q+ x4 ^
4 q& V# I$ a3 S9 n/ ]6 h/* assign the tl som board LED-GPIOs*/
. k7 K4 F- M9 wstatic const short da850_evm_tl_user_led_pins[] = {
: I/ ^6 G0 g: C, y) @ /* These pins are definition at <mach/mux.h> file */# W ^" H. c- n, w* |
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,. Q) `6 Z, x$ y5 ], U3 ~! Z6 K1 r
-1 r# h3 _7 S* x
};# r% o- _5 K( V! \) U+ Z3 A
/ F- t- A* J `% j; C! Y) V
static struct gpio_led da850_evm_tl_leds[] = {
4 {: m! x; S- I6 C+ t { ?0 t$ X1 P9 }7 z' \ R
.active_low = 0,
/ T1 [* n. \, _7 |7 C$ r. v .gpio = DA850_USER_LED0," R5 y9 r: p9 P
.name = "user_led0",- y1 C; \ ^. M- Q
.default_trigger = "default-on",! s j" M1 m, B: I, F9 W
},
8 M* {5 @% X) b4 ]) T. @9 A2 I m {
. h6 t8 ?' A) m6 K, ?1 Z .active_low = 0,
, O0 ?9 x2 R. `9 [5 `: d .gpio = DA850_USER_LED1,* S: w" F0 _/ | K; z
.name = "user_led1",7 D7 s; G- N+ b
.default_trigger = "default-on",
" e8 H4 s, C7 k8 M },9 M+ {, `; K5 T* l# v; F
{! f* c8 W W4 P# n
.active_low = 0,
6 t& O3 v q8 p8 J .gpio = DA850_USER_LED2,
; M1 B7 ]! b. x0 z( K9 L3 S. D .name = "user_led2",
4 l: t" F( `: T: e# U! _ .default_trigger = "default-on",
% A& t$ Y8 n% m8 s1 C },
9 o2 n4 w. ]/ ?; J2 J, D# a( x! N {
1 }2 m, e( m7 ?4 I9 x; a+ G& k .active_low = 0,
3 C* Q8 z- X& U9 M .gpio = DA850_USER_LED3,# o+ x' w: r4 o, F; i& h( W
.name = "user_led3",, q: A1 ]4 g* e0 ?7 h! D
.default_trigger = "default-on",* K( J, C {% O' }4 m
},
# R. J9 F0 Y5 D3 U* L};' A% y% ]3 ~8 I' f- N7 R0 M
# L0 Q, B) f r+ D' H( Vstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {0 q b9 N. b0 g( V) m
.leds = da850_evm_tl_leds,6 L- x% i5 f' d/ P1 T9 y5 B, Z
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
( w; }( i. J. {4 i/ ]) Y};0 j* P/ U: ~; a
, V: z: Y/ k1 C. n; k( v8 D; f6 u
static void led_dev_release(struct device *dev)
: Q. E: g5 N% E/ x9 n P d+ [8 T8 }% A{
4 w v+ Z4 y* K0 m' C+ y1 K};* |0 T9 v, Q% c/ A" ?3 M0 i
& t% I' D" A4 V' O1 ~
static struct platform_device da850_evm_tl_leds_device = {! ~& L# B" c( c) u1 Y p! h' K
.name = "leds-gpio", l3 m- I' o4 n
.id = 1,- a/ G Y" e: G/ U; A4 b8 N
.dev = { w4 \0 B6 _1 O5 D' a4 D
.platform_data = &da850_evm_tl_leds_pdata,$ L+ r0 a0 q" M+ b! \* d# w
.release = led_dev_release,& ^2 ?9 ` i( z% v
}5 N$ w1 ]7 h8 C) h! w5 a
};. }+ t/ `/ T% F5 h
, E6 U2 K' E) `
static int __init led_platform_init(void)
: V* i, \3 |0 q- W$ {{# W. b7 J1 x1 f
int ret;- X7 D* B6 @ p+ }. }: s7 @& r
#if 0! N1 s% |8 W+ {
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);9 O$ q2 o! Z( T U6 q6 u1 ]
if (ret)
* O8 l% A9 k0 y: T7 m# v pr_warning("da850_evm_tl_leds_init : User LED mux failed :"1 a& u2 p) }1 ~; ]
"%d\n", ret);
; W2 u) m; T/ i4 c1 a3 Z' w9 c#endif
1 @# Y* h4 _9 \/ l& P. A T0 d ret = platform_device_register(&da850_evm_tl_leds_device);
5 T9 u2 P/ R1 Z. ^$ W3 c/ W if (ret)4 H/ N: z& ~# l
pr_warning("Could not register som GPIO expander LEDS");
3 W' n( M, d2 y" t0 c. M7 ?0 Z2 x else
5 M* t* W' R& y8 F( J printk(KERN_INFO "LED register sucessful!\n");
: {9 p/ H @& p) c: s
: v. Y6 Q. y D& r return ret;
4 @& L4 C( C4 p# t/ s! g, j5 ~}1 n- F; [, ^. I
' K/ x' M' X8 l# L7 i0 n
static void __exit led_platform_exit(void)0 @' m/ i& R2 x: o5 k
{0 ?) Y3 [# ^+ B& Q$ j1 _" n
platform_device_unregister(&da850_evm_tl_leds_device);
- _. H( e6 e! Q: Z9 C: H( ~7 k" m. o' Y7 E; P5 K& ]! i. J0 A
printk(KERN_INFO "LED unregister!\n");
+ V5 Q7 q. v3 k6 |& U}
# E) q+ \# d$ E" |6 d) U/ I6 m$ e$ h9 c# s; k+ S
module_init(led_platform_init);
3 j9 h' j& q1 i4 n* d9 B1 d4 q4 Bmodule_exit(led_platform_exit);+ p( o) z/ d! v4 v) _& d) ]
+ i6 T- i. X" Z/ I! O& l3 {
MODULE_DESCRIPTION("Led platform driver");
( _4 C& g) }# \0 h7 c& N% v7 m8 xMODULE_AUTHOR("Tronlong");
* U+ O2 H. @1 {# lMODULE_LICENSE("GPL");
$ O& r2 x9 D. l* ]0 S
# q4 e- J5 O4 V; Y& b |
|