|
求大神给下面的程序做注解,请稍详细些,谢谢。9 p, |1 Z0 B, ]" r- J4 R! c
#include <linux/init.h>* T' B! Z, S+ o% Z
#include <linux/module.h>4 l/ u9 Y4 j5 a5 R4 _
#include <linux/kernel.h>
# \) p+ ^- p* [2 c, p#include <linux/types.h>
$ m. d! k- R1 C& n# \+ O1 m#include <linux/gpio.h>
: i8 C) n: f9 ~1 y#include <linux/leds.h>: Z" e: M7 r( W0 A( O/ u
#include <linux/platform_device.h>/ I v. i) G4 \
b9 {: S+ i+ F' g9 X/ Z- ?#include <asm/mach-types.h>1 j6 [4 l v6 K. L
#include <asm/mach/arch.h>
{0 v' O1 ]7 l& ~" X" p#include <mach/da8xx.h>9 D3 V! ~( y/ i% D3 y# K; f4 p
#include <mach/mux.h>* g! \( x8 k% S; }1 ^# ]
5 E) c( g5 i0 v#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)9 g) P( \3 g" |2 O! n
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)( }# `4 S8 S3 _( m! b7 U
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
# z; ^9 v: C2 {- W3 N! C7 k#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
5 h! C$ }% Y9 ?. G9 q8 K6 ^- j) u) E! b8 ]/ a1 G- T
/* assign the tl som board LED-GPIOs*/
7 n* T: B6 G+ S9 v8 S) d8 l8 b7 [static const short da850_evm_tl_user_led_pins[] = {
) c3 p$ c4 ~& C. q8 K7 i /* These pins are definition at <mach/mux.h> file */$ k9 D* q! Z& j! j% i9 f" B+ V
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,% _1 m; a0 w: @3 u5 w+ e5 X
-1# x* L/ P9 M9 `. F
};
7 b" o" X, k# B9 x8 w( O
9 @ t' t9 h4 c2 Nstatic struct gpio_led da850_evm_tl_leds[] = {9 P- I+ @, |0 N( ~0 k# t. W/ C9 k6 b
{
t! _& f: K4 ^( A .active_low = 0,6 _7 B" ^1 P# ^* B* Y$ X
.gpio = DA850_USER_LED0,% P' m: t$ f r# Q' H D
.name = "user_led0",
0 l }8 N# Y6 y .default_trigger = "default-on",
* i c! f; o+ N" i3 ?5 D* W$ @ },
* E3 x) j' P, \3 }. z& K, Y {
- H9 l* r! U; |5 H8 ]4 i .active_low = 0,3 n0 x# m. Z9 S6 v+ t0 J( n8 m! W( ?
.gpio = DA850_USER_LED1,
4 C6 o9 m: R, D# n' V& b/ q" A .name = "user_led1",
# f& w! X" n e5 A& _% N .default_trigger = "default-on",9 A5 N! W( I4 g) g0 [
},$ m$ a/ Z. R# t+ k, u
{
$ p9 v7 u" ~% z5 Z! c# _* H .active_low = 0,- j+ X" f* [6 }% e1 A4 C: A% s
.gpio = DA850_USER_LED2,
( f1 J3 g' J; c/ E .name = "user_led2",6 E9 Z/ P$ B4 l! t+ a
.default_trigger = "default-on",
/ G$ T/ G& k, K1 m1 [9 x },! S7 X8 l, W( S5 A
{9 }+ U! j" ]" Y& z7 j6 E# S
.active_low = 0,- {9 O- e3 i! w! E" j
.gpio = DA850_USER_LED3,+ {( ^2 I) t* q4 h
.name = "user_led3",
4 Y; {' @6 V9 c3 { .default_trigger = "default-on",% Q- s7 i1 R: W; g
},
2 ^3 C% M; D) W; r" B};
/ A5 i- M) Z F" d; [/ V1 l& O$ a$ r- j8 F! }4 l6 k4 F% i
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {4 A5 q% Y- R# S3 t9 D+ H
.leds = da850_evm_tl_leds,
* c& r, B) ^* Q .num_leds = ARRAY_SIZE(da850_evm_tl_leds),- o! z5 R; S9 ^( o
};
. t% o/ ]+ M4 L+ I7 C7 y
) D$ Q: m" [% S$ m, C7 D* i- E& y5 x0 \static void led_dev_release(struct device *dev)
4 t& [2 _' u L0 M- e{" T) ~7 K" c$ B+ E8 E. Q, w
};
6 R, I" q' C: a- l W H
: ~' B+ ~0 J7 S5 Ustatic struct platform_device da850_evm_tl_leds_device = {
: p, r* H% w3 o* l$ A; `0 \+ b& C .name = "leds-gpio",
( g0 N/ F7 C4 _# Z6 P, j* m .id = 1,/ X# B& o8 k0 S0 H& V2 a; n( N% }7 f
.dev = {2 t5 V8 Y: y) h0 x! I; \
.platform_data = &da850_evm_tl_leds_pdata,+ Q1 O( \+ N' e+ ^2 C
.release = led_dev_release, J) k0 q8 t7 L7 S, R1 E' n' Z, b
}/ t0 J% G7 H% ?: b+ F' q
};
1 X0 Z3 H# G4 {' Z. c% q: b9 o; m. H& J1 N
static int __init led_platform_init(void)
, B/ u! I2 ?' S$ J. {5 `{, a3 O- e+ d0 R* m$ J
int ret;
; N+ Q& b, `1 {' t#if 0
- ?3 @& f: a5 `$ k/ l* Q4 C ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);' ^1 O0 _% ?; _: _
if (ret)
3 R0 R5 a1 J: U, t0 k q pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
( b* c: v6 I4 U0 Q# p0 u "%d\n", ret);, ~, J- z9 L5 U' C) V
#endif+ v8 e7 @- G: s' t$ {4 R; }
ret = platform_device_register(&da850_evm_tl_leds_device);/ \0 [( {- k: n
if (ret)! c4 b4 f/ r5 }4 g) a
pr_warning("Could not register som GPIO expander LEDS");
# w0 E0 V/ x a: h% {- q else/ v, [- \ z# c: a+ `5 ?) i6 t
printk(KERN_INFO "LED register sucessful!\n");
2 n$ c4 T1 {, Y9 i+ s. [( @" V9 ~/ B$ N: O0 c1 ^: @6 `! p
return ret;
2 M6 C F* ~+ D5 B1 ^}
$ p7 j, r1 `: q9 \% X! p% T6 v9 H: a; c) }' @
static void __exit led_platform_exit(void); _- e* Y, k, x% L8 _' d
{
, N! A N; h8 v. C9 ]# q platform_device_unregister(&da850_evm_tl_leds_device);! z& {9 c W+ z* u
- h3 p. z9 M1 [! }" S printk(KERN_INFO "LED unregister!\n");/ T1 G( x s0 U
}& K. G& Y/ H* A& Q( x( @& m1 v( f
+ q$ a7 |4 `7 |; P' c8 u; f1 j
module_init(led_platform_init);$ v, g1 Z; A/ l9 k
module_exit(led_platform_exit);
9 X: `6 T: Q2 |1 v. J- A8 a6 E+ h2 Z7 z0 U3 u; z1 h
MODULE_DESCRIPTION("Led platform driver");
! d R7 K9 H- J- u, U% ~MODULE_AUTHOR("Tronlong");1 ^8 ~ t4 T( b
MODULE_LICENSE("GPL");9 q) y2 z' H; |: A6 e8 P
( R& B- F1 W7 l9 W |
|