|
|
求大神给下面的程序做注解,请稍详细些,谢谢。* E/ \& K2 b* |& E8 M' z) w; c% |
#include <linux/init.h>4 N+ k% o! M: H1 n4 x4 B$ h- @
#include <linux/module.h>
8 n: p6 I/ j1 n+ d0 D% G3 G#include <linux/kernel.h>
! E3 K# k; u% W9 u; U#include <linux/types.h>- i, [7 [% e. g
#include <linux/gpio.h>% t" g7 v: s5 U
#include <linux/leds.h># Z/ R+ h- |8 j( B; N' I
#include <linux/platform_device.h>2 d- i! \% R* Z! L, ^. D: S
. S- l& Y3 B6 {+ i! Q0 ~' A6 N, p3 H#include <asm/mach-types.h>
& r) C: l# f: n9 t#include <asm/mach/arch.h>
) v# N7 Y+ X9 {9 s#include <mach/da8xx.h>
! r5 n6 _! C' t5 s% T/ @#include <mach/mux.h>6 W, Z6 s$ }2 F; d
1 u. K" I$ U# k' m3 V4 y) b7 S
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
5 }6 F2 ~5 k( o* E0 L E#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
2 Q+ Y5 S O1 }5 O7 z#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
# [" o6 \* O! O/ c. o+ N' R#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
Y" b P& h2 C0 t8 G4 a# s6 X: W# k- B) S# u
/* assign the tl som board LED-GPIOs*/4 Q% y h+ e; q1 y2 f. C, t
static const short da850_evm_tl_user_led_pins[] = {
1 A' T6 u& }1 y( z* A& F" q /* These pins are definition at <mach/mux.h> file */7 a. Y3 w6 H' d, s \* G3 B
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
) c2 _8 B: P8 L: u1 m -1
9 B$ K2 P4 s" B" s};
, n1 s3 i+ ~3 D% Y' N! y& a
9 G- g' O. d. Vstatic struct gpio_led da850_evm_tl_leds[] = {
8 z' I" [1 b' l* Q0 w4 _ {
) c( P4 E; s9 n7 f3 G6 E .active_low = 0,
6 i/ l4 e. f( T( g& [! Z! \( {- X$ D .gpio = DA850_USER_LED0,
. K, `! {: E9 y- t- w .name = "user_led0",
( T& u; [/ L+ {8 W .default_trigger = "default-on",
- D8 l7 h2 q) I" Q. K },( ?. Z7 G ~3 T) Q0 c' ~2 R
{- @1 E- N) z8 i+ z% j$ d0 J
.active_low = 0,
1 J& K! M+ F5 \# R+ |6 T+ r, _ .gpio = DA850_USER_LED1,
' S5 X6 e$ a& q) ]9 W( }% B) c2 F .name = "user_led1",4 @% F! f8 x" t% ]
.default_trigger = "default-on",) X7 V* V$ s+ X6 F- M8 q
},. ]& k9 m- y9 j$ P# f: ~
{; j0 {6 D+ t: L7 h3 [+ |& j
.active_low = 0,
4 ~6 A5 F8 N8 t: t: q& @ .gpio = DA850_USER_LED2,, O8 a. b# Q, T/ ?- ^9 q1 J" r* t
.name = "user_led2",
1 `/ Q6 |- l3 s7 x4 f% G8 C .default_trigger = "default-on",5 C: v J9 Z" o, y- Q
},
& H: `8 ~5 ^& S- ~3 m {! \# a4 ]/ r( o9 \+ [4 O
.active_low = 0,+ S3 p% H8 h" w. ?& G
.gpio = DA850_USER_LED3,
) D/ U5 v& a# ]- I! q .name = "user_led3",
3 X. D8 V K; ~# h' y .default_trigger = "default-on",
& ]5 |( M; V1 p( c1 g },
9 H* d) \" i' J3 t+ f6 f};
' {$ `* N# V7 F- \7 [; n" y E! }! H* x: d7 k6 x+ \6 e* T
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {) C1 a/ E1 N9 B; D1 _$ z
.leds = da850_evm_tl_leds,
, h i, ^4 P7 \0 |* j$ z( u$ |, z .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
3 b6 e! X" Z# k: E5 I};! F# W2 h6 g; l
4 u/ U M' n+ L; V: Z& P' ?# q! kstatic void led_dev_release(struct device *dev)9 ^4 f2 ?6 y/ `: z9 e9 f8 `! J0 T
{
+ B; `$ V- O0 }7 k* w. J};4 V6 |0 R, T, b0 C0 H
! g$ [0 p$ M1 g" Hstatic struct platform_device da850_evm_tl_leds_device = {
# K: h1 `7 S9 u7 a6 q .name = "leds-gpio",
. s: L3 h0 {0 `" g' ~! \ .id = 1,# ] h9 v9 ]7 g# z9 m m
.dev = {' f* A3 ^/ T' W( g( F
.platform_data = &da850_evm_tl_leds_pdata,4 K6 F8 ]: D# D" V8 Z8 u; w/ r
.release = led_dev_release,) T3 B: F$ ?" X7 d( ^% B% a
}0 T- F, @% s6 H. _, _" c
};2 ?7 A7 c# [3 X2 U( j
- E6 e0 f! `" z1 z( c3 xstatic int __init led_platform_init(void)
& x, e1 r9 R- y1 S{; r7 ~# _3 L8 d
int ret;
. q: e6 @7 q- b( v, _& e#if 0$ i" c" n0 F" g% M( d& D9 V. F6 V
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
: n& T. ]$ F/ Z if (ret), N2 P1 c# P5 J! h
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"$ Y1 W6 f8 M4 N, Q% W3 _( l# b
"%d\n", ret);$ b# g5 |) p& S6 ^
#endif3 r+ l" |" S$ o: ]$ Z5 Y6 `
ret = platform_device_register(&da850_evm_tl_leds_device);
5 e2 Z1 |0 C- K1 p/ Y if (ret)
% E: B M: N6 x; y/ C pr_warning("Could not register som GPIO expander LEDS"); K- n4 } M' f2 z9 y. m0 S+ D+ ?: v
else$ x0 p* R# o9 W+ x7 H+ }
printk(KERN_INFO "LED register sucessful!\n");; k! m' I0 b3 Q% h- J/ P
8 v. @4 s. \( e2 [: k
return ret;* W! a- A4 {& B: h8 K c
}
! @2 G1 k+ n; e5 d5 ~
: M9 k! V3 R6 V/ I0 `) istatic void __exit led_platform_exit(void)6 H8 d; v, n* T; ~1 P. o
{
# w6 @, u7 P- |! q- @5 u2 _% j6 n- a platform_device_unregister(&da850_evm_tl_leds_device);" l9 [, V. b+ N1 g9 ]
, v- k+ [: z- O
printk(KERN_INFO "LED unregister!\n");" ~$ Z0 Y2 i" @
}
* ~) b0 e+ O, [- f. L$ E8 r/ B
* Y7 `! n0 y: V6 Z8 m$ I3 t+ Umodule_init(led_platform_init);% n! H/ m( ^8 q
module_exit(led_platform_exit);
3 S; Y* }3 E) h$ u/ q2 @4 K7 R! F. |5 l* d) X
MODULE_DESCRIPTION("Led platform driver");( S) @% Z( r8 d m* G6 g0 f
MODULE_AUTHOR("Tronlong");7 |+ B) V& I' U
MODULE_LICENSE("GPL");$ i. ~# q; I* _0 x% b5 g* a
+ r+ w K4 b |- d# y |
|