|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
5 z1 S4 G4 a# s, |1 \4 e#include <linux/init.h>
9 ], `6 R% h" y6 f; r4 i* T#include <linux/module.h>
7 M" x9 q1 Z: x: n5 q8 ?/ ~#include <linux/kernel.h>
& \! U. O: e4 R" r* G: _#include <linux/types.h>& i: @3 @+ r/ }. V/ F; g
#include <linux/gpio.h>
3 \" o! b$ R" M# |) F#include <linux/leds.h>
4 Q' a- e9 I7 ^; v#include <linux/platform_device.h>
7 H. Z d( ~4 s- E* l5 }3 H, T" K% I
#include <asm/mach-types.h>5 d. E& v& O0 g2 t# ?( a7 `
#include <asm/mach/arch.h>
7 {6 s* o$ ~, G3 M4 O+ _* A#include <mach/da8xx.h>" i/ z9 y* z6 }( t* T4 q; N+ b
#include <mach/mux.h>$ q I; L( @1 {) ]# l) D
1 v, V# Z _6 k
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
1 q- f# p' g9 L, V- S& s6 m#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)+ U9 J2 s, O1 t6 u% `) |
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
6 l4 t2 g$ q1 `$ _/ A$ G! {5 z#define DA850_USER_LED3 GPIO_TO_PIN(0, 2): W. ]( k0 g- Q2 O! d0 q6 B
, C: A* N; d ]/ V
/* assign the tl som board LED-GPIOs*/1 g% f1 W; a& R
static const short da850_evm_tl_user_led_pins[] = {
: e4 b$ ]9 x0 d9 q! D w5 k /* These pins are definition at <mach/mux.h> file */
5 \) ^* O/ E8 I; J4 o: @: @" i C' D DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,/ z S2 t: t1 l+ W8 {
-1
- Q6 u3 X0 A. U; h: l};6 c% ~( W# V, _
( H/ @4 ~; L: N' n
static struct gpio_led da850_evm_tl_leds[] = {2 Y3 E1 M7 E" e
{4 A$ Z2 J6 ?+ w1 n' t0 c* V
.active_low = 0," n( w/ e6 M' k0 \; j
.gpio = DA850_USER_LED0,
" X; M) b) g. a# D6 S .name = "user_led0",) G, G2 w% |" H- D
.default_trigger = "default-on",
0 Y, R( F: G& G },
2 ~; g7 Y- }8 W. x {
- d) I+ ?. K- }2 Q) `/ u! H .active_low = 0,7 s; p/ e, d3 ~2 }1 M& d3 F
.gpio = DA850_USER_LED1,
* u, c6 m& h6 p9 Y; s, T2 J$ ? .name = "user_led1",
: e6 @6 Q* g: d5 e .default_trigger = "default-on",
e) X. _$ s' T! C, r ^ },8 P E2 ~+ l' C1 ^4 s; ]' n- Z
{
* J4 i3 Q( i2 T .active_low = 0,9 Z- u5 M, l. a3 h6 b( |
.gpio = DA850_USER_LED2,, c0 B, \$ T8 f) C+ O9 S: c
.name = "user_led2",0 v+ d; s- q0 v* m5 ?! {
.default_trigger = "default-on",& g r9 V+ }2 M5 E- M" }2 c
},9 ^; D" v4 ~! u6 G8 `1 x0 j- M6 V2 K
{
- z# ?0 F. n( U8 G' r# E .active_low = 0,2 T3 ? M4 D. |7 U$ y
.gpio = DA850_USER_LED3,
. ^: ?& g# Q3 f! b% B+ M- y( b .name = "user_led3",6 i5 b3 E! u K, J8 D
.default_trigger = "default-on",- R7 t- U; `4 ]1 w! ~8 p: k; q4 l
},
, P. k* A \; ]7 @$ ]2 q};
9 d4 u# c* Y! t
0 |- m' @5 c* q2 Tstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
0 X/ a2 p0 a3 B: f$ t- ~ \ .leds = da850_evm_tl_leds,
1 ^7 z5 P- v$ l4 P .num_leds = ARRAY_SIZE(da850_evm_tl_leds),! \3 f6 k1 I: W. |; u) J3 a, W7 G8 b
};2 t- U6 H4 y5 P
' G! i/ F3 l+ d. f5 y- U6 S L3 Ystatic void led_dev_release(struct device *dev)
# |# Y( X: t. L5 R" s{
5 [0 _* z9 V5 B3 I( P, p }};% k: a- J2 y% I9 b
* e: p+ f) A3 A( V6 S, Z
static struct platform_device da850_evm_tl_leds_device = {3 f: G3 K0 m- K
.name = "leds-gpio",# P( i+ x1 A6 A& M( t
.id = 1,) N2 t4 A6 n. H- i h
.dev = {( {1 b3 s% ~% L! _; A( K
.platform_data = &da850_evm_tl_leds_pdata,/ p9 j3 A/ n- M4 K! v: r
.release = led_dev_release,
7 A2 e, @* R9 }- V }
- w/ h3 R; [5 {) i};
+ b: G j7 X" p7 O9 K' G: O( G2 w2 y" s. _5 g2 q" }% |2 @' E
static int __init led_platform_init(void)
0 o: v3 \! J1 H& M7 |{
( b: F) N$ |2 e$ K+ K( i1 T int ret;
C4 ~: m& S; _" r#if 0* U+ L5 Q3 }1 O( } N9 m, U
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
' y% [' G+ i$ m ~ if (ret), i3 j F. ~ H b3 U
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
! @& L* L8 G' }& g2 g "%d\n", ret);$ Y+ g: o& o1 F0 n# T/ v. y5 x
#endif; d& R( P( ^* O. _6 x: v
ret = platform_device_register(&da850_evm_tl_leds_device);
5 S( L# }6 u% `2 q& ^ if (ret)
! J$ V1 P4 P$ s# a* I# e! C8 f pr_warning("Could not register som GPIO expander LEDS");
; V$ ?! Z" t8 P z else5 s- E' u9 P8 o; O
printk(KERN_INFO "LED register sucessful!\n");! U8 W# m X. ]+ z: e6 H/ e
" X$ K" k: h: w/ ?# d' j return ret;) d, ?0 I& C4 [/ B" [. x
}% B9 q! M4 \5 H$ {* D; R
3 U; ~6 H6 p% A* w6 Bstatic void __exit led_platform_exit(void)
s0 [; u8 g6 P$ e4 @2 s{$ c* E' ]& ?9 W: q7 C
platform_device_unregister(&da850_evm_tl_leds_device);
& e1 ~: S) Z- K- z) V" Y T1 `/ Y8 `# i5 X; y
printk(KERN_INFO "LED unregister!\n");$ F9 a3 E. E3 _3 U
}% \5 q; g! b, O) Z# n% s
* H8 t, w* E0 ~1 s" @: zmodule_init(led_platform_init);( @5 t& y5 m p7 }1 v. ]4 i0 w
module_exit(led_platform_exit);
7 K( q% f- V- U8 `' Y0 g3 S
& c) j, o2 r9 C5 ZMODULE_DESCRIPTION("Led platform driver");
' |9 o* _( N, LMODULE_AUTHOR("Tronlong");
5 ?2 X, r4 u0 c* `1 rMODULE_LICENSE("GPL");- ^9 O7 c$ n; m
7 D. o+ c; v! [: F; V
|
|