|
|
求大神给下面的程序做注解,请稍详细些,谢谢。2 } n/ i! e2 @* N" i# R
#include <linux/init.h>7 _- b3 a; c1 \8 Z+ D
#include <linux/module.h>8 h2 E6 L+ N, I v& p
#include <linux/kernel.h>
P& j( E/ v0 B$ o. M0 Y#include <linux/types.h>
0 s5 W& K4 ?* _3 W#include <linux/gpio.h>
X3 H% B$ f, f+ _#include <linux/leds.h>
8 o+ {. c/ \% i6 M# G#include <linux/platform_device.h>9 `. [0 b$ l# ]( ]( |, z" a; x
6 ~' S6 W5 a2 S' W$ {# `) V/ s#include <asm/mach-types.h>
) y$ G, M7 d* \) [#include <asm/mach/arch.h>1 t( b5 j2 z1 z2 z
#include <mach/da8xx.h>
4 T* _& K" g9 L6 T#include <mach/mux.h># R) ?! \( X/ T
" A9 o& }# Y/ F! `#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)3 l. L" w8 v% n3 z( q$ U3 n
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)9 ^7 f& t2 ~ b: b7 s
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1): T0 ^$ z4 c/ h( k, K- v
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)4 u) R( X& F* G* _
- ~ d9 ~% ^% y
/* assign the tl som board LED-GPIOs*/
5 E/ O6 D5 x3 i( \% estatic const short da850_evm_tl_user_led_pins[] = {$ H M7 i: n. L
/* These pins are definition at <mach/mux.h> file */ B' V2 b6 Z1 p
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,, n' u0 t# `: h. s( K# b
-1, H; n) z3 X, Q3 N: y/ u
};
5 S3 b, `! E+ P2 A# K/ Y) ~4 v1 H2 V* K! B8 Y9 s
static struct gpio_led da850_evm_tl_leds[] = {
$ t+ Z. x6 P, z8 g# A6 G' z2 m5 R, y {1 s/ O2 z, t3 R
.active_low = 0,
+ y( V: ~+ Y+ | E4 A .gpio = DA850_USER_LED0,
. S- p) @5 N) F$ _7 L# k .name = "user_led0",
. Q" Y* N8 {9 u/ d+ F' F O .default_trigger = "default-on",
, q* y4 R4 Z" Z$ ^$ ~ },- u- C" C3 ^" k+ Q8 ~! p- `
{
1 A' J" M i; z% Z" t& J9 z S0 T& o .active_low = 0,. j9 _- y' I/ R$ _' {0 X6 P
.gpio = DA850_USER_LED1,
9 r. P9 A+ `% ~& B" r9 Z .name = "user_led1",$ ]% C, M# G) i% ^
.default_trigger = "default-on",# _. L1 l/ Z2 g
},
" G7 K! U$ u' L* j: Z& q% G {) A; ~, n0 |. i
.active_low = 0,, I' \2 s4 `! C
.gpio = DA850_USER_LED2,
; X$ |, D0 h5 w: f5 `( M .name = "user_led2",
; ~- C5 ]1 i+ @ .default_trigger = "default-on",7 N$ X+ q( V2 g% Q, e: k
},
5 k& C- S+ y7 @) n {, f6 Z6 `1 w/ z; R& N2 s3 T4 Q
.active_low = 0,
) r, h! t. s6 n& F G .gpio = DA850_USER_LED3,
6 k5 \/ s9 B* G8 h .name = "user_led3",
4 |7 A+ y( j& C# T/ J .default_trigger = "default-on",
) p6 M* [0 t% s },
* R: `) ~, a5 h! N! k};: ^2 W; N* v8 d9 a5 \ ^
3 J* W0 H! n, p U: H4 vstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
0 h7 T& E/ F' _ .leds = da850_evm_tl_leds,
0 g+ z% A6 b. R' R6 z% h .num_leds = ARRAY_SIZE(da850_evm_tl_leds),) S0 i$ ]) r8 |8 L$ m/ [% y) K4 N
};
* y# i3 k5 R! C: ^& a- P, r6 w. g. `+ g/ Z% M% D/ w
static void led_dev_release(struct device *dev)
6 ?) C- l, L- x5 L; g2 n1 ]: ]% e{ h% {: r% X8 s
};
" U8 a. ^, ~* G: {4 Y6 ~+ b3 S/ ?2 L$ f( J% K; c) M2 S
static struct platform_device da850_evm_tl_leds_device = {
* I( r1 }+ Z! b3 E) Y .name = "leds-gpio",- m; q# |: P; n( }0 Z# ]% @5 N+ v
.id = 1,2 `+ X/ t0 ^2 [
.dev = {
P3 j' `, |5 c3 K+ n4 i6 C4 ~ .platform_data = &da850_evm_tl_leds_pdata,% K0 } b2 |7 H: m: T6 h2 f l
.release = led_dev_release,% K' G$ Y4 }- S; |; ?# g3 I
}) s ?: | E0 |
};
2 n' F/ k3 v( i6 M# H' H+ Z5 k- R
. X# Y' P6 O2 a! W! Sstatic int __init led_platform_init(void)
. \1 t3 Y) F4 ] u{
! m0 z( W4 W( l+ ]8 y% p2 S9 a$ y; Z int ret;! u _) @6 Q# y- o4 D& E
#if 04 I; C/ u3 j: Y- \. _
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
9 o8 c2 D5 K Y) U2 f* U- j- c" v9 P if (ret)" t5 W7 U2 y& R8 O8 I
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
+ }* u5 T9 M2 P6 e& D# v% K "%d\n", ret);! W; a ]* L* {
#endif
2 {6 R. O8 c8 [% c" j' u7 Z- B ret = platform_device_register(&da850_evm_tl_leds_device);
7 v3 z3 K) \- v9 @% g6 i if (ret)
w6 o- r+ p t$ B pr_warning("Could not register som GPIO expander LEDS");3 t+ B. B; O3 Y9 W; S7 O
else
0 r' v! @ B( x( y, k7 o printk(KERN_INFO "LED register sucessful!\n");
6 n |2 o0 {7 |7 z3 z$ x. c# l
" `7 c+ Q2 `( T/ @8 B& A return ret;+ ^& O! j1 j: s+ D( }
}
- ^ A9 }) j8 e: Z+ M
1 P" t% p" ^+ Q2 M9 Z: n1 @static void __exit led_platform_exit(void)" ?" t* m1 G' b! }
{
0 X8 Y7 s0 G1 }* S2 } j4 p platform_device_unregister(&da850_evm_tl_leds_device); d( n- A5 D* D. t0 ~6 y5 t
9 J' `' y4 Z( z/ T; J
printk(KERN_INFO "LED unregister!\n");2 r0 ]# { H2 u; Z3 a: b) z4 K. J4 ?, @
}
! v+ A5 D1 _, z. c6 q/ w' O1 q" _% [8 g
module_init(led_platform_init);
% @3 {8 t% O/ c( E) ?module_exit(led_platform_exit);! b+ C$ f7 S3 r! a% j' p5 z
4 F/ l9 `: q1 I, {# ?" v& K4 xMODULE_DESCRIPTION("Led platform driver");, L4 _" m1 Y5 o2 _. ]) J2 A* Q
MODULE_AUTHOR("Tronlong");
4 l& `2 [! l: BMODULE_LICENSE("GPL");
: [' E5 ^2 b. m* L9 L3 H9 r6 A
, }/ G: M( d. r7 _0 T |
|