|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
% H9 C- N1 q! a5 t# O#include <linux/init.h>
) E' O7 S: p& V# x" r$ r# b/ z5 O#include <linux/module.h>
7 f0 `: t. o0 n, g* E! _* y#include <linux/kernel.h>
& g- y9 _ W- ]4 q/ O- A#include <linux/types.h>
0 D% D$ T5 r' \) o9 S* V( {6 H#include <linux/gpio.h>
4 B- |2 b9 [2 M' f R" f#include <linux/leds.h>* v' b) }! a; g2 ]
#include <linux/platform_device.h>9 n2 R9 w h/ L. u
2 F3 K. d7 ]4 `# t#include <asm/mach-types.h>
- w9 B+ t/ d7 S2 k' v0 u#include <asm/mach/arch.h>: o# J& Y: M8 i& ?- S
#include <mach/da8xx.h>
* w. D$ c% X; X8 W* P( V#include <mach/mux.h>
1 o8 e8 F1 s, f7 W
2 r7 _, N8 {1 y9 _+ L#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)) E R. I! C7 y: P" E
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
/ o0 I% h" h5 \8 D, ~#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)6 a: f$ G% S7 F1 A) \; R$ f9 s x
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)8 f: j7 G+ i3 h6 E( Y/ b
1 d( `+ [9 U$ t9 M9 [! J3 ]
/* assign the tl som board LED-GPIOs*/( E( r) M* `& P* B. H) M
static const short da850_evm_tl_user_led_pins[] = {
! v$ {% C3 Y2 u9 L7 E, n. l' l9 e /* These pins are definition at <mach/mux.h> file */: k* ?) U; {2 c" L C5 a5 p# R3 P
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,+ R( _% \' _0 R' ^% z( c2 X1 Y$ G
-1( t% q$ E- ^9 o( L
};
* B M, h8 T" T1 w
6 N4 ?7 U% v7 ~+ wstatic struct gpio_led da850_evm_tl_leds[] = {
/ [. |& y7 f( l# s {3 w" c j& R5 k; B: w, O
.active_low = 0,8 u1 N' O2 @# F, Y
.gpio = DA850_USER_LED0,
3 L2 T6 q$ G+ Z .name = "user_led0",) A! t1 R7 C3 z% j
.default_trigger = "default-on",0 U* d7 I* @% k" Y+ ]. w
},: ^8 ^' f! p: I4 q
{
' h( V; [' l% i! i7 N7 G" C .active_low = 0,
" S6 U5 b$ } b6 ^- t) s .gpio = DA850_USER_LED1,# n. [1 d& ^) [* |
.name = "user_led1",
' W, K4 R' m e' ^' h .default_trigger = "default-on",
& B+ K, V; E$ m8 o/ [% j },
3 c! ^5 d3 \( C2 l9 N" ` {- w! p1 ?3 G5 H- c' l/ h" T2 o
.active_low = 0,0 e7 D: r9 h" V T, O: j
.gpio = DA850_USER_LED2,- Z4 @7 \8 ~" l/ W: p( W
.name = "user_led2",
' n9 i8 ` y' E* T- w4 H .default_trigger = "default-on",
' v O2 _$ A% F },
9 @# ^; O% M8 G/ j, _5 t {, q) O7 ?2 ~& b5 H8 m; h
.active_low = 0,# g4 N# f3 I" A# i0 q4 h! d* |
.gpio = DA850_USER_LED3,
; I0 H: E9 Z$ |0 P" J( j" A6 o3 y .name = "user_led3",7 `& A7 O) w7 |3 h+ b) A' \
.default_trigger = "default-on",( `6 Z h, ~( D4 T( p
},, U" d5 y. o+ p/ `2 D; E, ~
};
2 G4 I8 T2 b. r( l/ r3 }
& Z. S% w' U% [static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
/ y% F* a. |) p1 r6 I .leds = da850_evm_tl_leds,
3 _9 c1 w" @5 P' _8 C( B .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
' ?4 V' K$ e/ b( m6 I};9 o6 S6 j# N. ^' c$ U2 s
/ _ l7 o3 F5 r& B/ ~static void led_dev_release(struct device *dev)
. G% F3 u7 B9 `& Q{
' T2 Z1 d8 U$ ~- J, `};
# y1 O4 s& J: G5 Y/ `4 T6 K. U' X- o r* q5 F8 a }" e! C* O
static struct platform_device da850_evm_tl_leds_device = {
) K2 f, H% U2 O8 K" C; Z# g .name = "leds-gpio",% B2 }5 l1 S3 ^9 `/ b: U0 @1 m% R- f
.id = 1,) N3 m+ e. g; T. B6 H" X
.dev = {* d0 }$ g! [* Q
.platform_data = &da850_evm_tl_leds_pdata,
8 T- y/ B9 C' k5 X; K$ Q .release = led_dev_release,
/ @9 P% O6 p1 H9 d9 x) c" Y }
) h- C; ~/ r$ C% w; t7 J};
4 E2 X3 Q6 G2 z4 q0 u7 I5 p& s F5 R/ o& E; |
static int __init led_platform_init(void)6 S2 q) x' f, _% U: R) g( H
{! q3 D8 X. K) S/ _0 B. b
int ret;
8 D2 _/ Y9 W+ a# h! S#if 0
7 T. s+ Q# y: o- k. y! D" {; _0 \, ^4 X ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);/ L4 w: W; @0 H
if (ret)
7 B3 K0 ^% x+ B* j. ^- B' ` pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
1 Y2 [2 t! A: g5 n. ^ "%d\n", ret);& X9 \* \1 S" u- f6 n7 P
#endif2 O& q+ Y/ P8 v9 z9 c
ret = platform_device_register(&da850_evm_tl_leds_device); D( H4 l. l7 a$ i5 G' f. x2 {, t7 h2 B
if (ret); Z+ [3 R: p7 K' B4 [" }. g
pr_warning("Could not register som GPIO expander LEDS");# T, F5 c; N8 \5 j3 h5 G' f8 x
else
& c( [0 C* N- v printk(KERN_INFO "LED register sucessful!\n");
2 Q' R& d9 @" t+ L3 T/ D/ a, G5 f7 f. J6 C% f
return ret;, J) ]- t$ H+ T( q v$ \
} C0 l3 c8 k- v$ ]: @" ]! B! a
5 n; [0 A2 E* r% A
static void __exit led_platform_exit(void)' a( V% |4 Y# E' a+ ?4 t
{
$ D' [7 _9 I; |" ~( D8 a platform_device_unregister(&da850_evm_tl_leds_device);* A9 U5 r0 x9 o" b) q9 Z
+ m4 v1 A3 p% T T. T1 ^- R printk(KERN_INFO "LED unregister!\n");7 f& s/ V; i6 ^. S, {
}
/ f7 |: N" ^( M8 E" R7 L% o" A9 h; g( d% ?; k2 k& B, E
module_init(led_platform_init);
1 D' \8 R# Z* ~7 J5 M! qmodule_exit(led_platform_exit);
$ S# v, t6 ^" ~% G9 z1 H# g# _+ T& L
MODULE_DESCRIPTION("Led platform driver");
% [6 j. m" w4 ?1 {$ w$ OMODULE_AUTHOR("Tronlong");4 h, h: R. `7 W: d5 h. c1 j& z o
MODULE_LICENSE("GPL");
% |1 ?- _! X6 e- G6 {: g+ f8 S2 c2 m5 Z/ a) b& k% j3 K) Z
|
|