|
|
求大神给下面的程序做注解,请稍详细些,谢谢。$ k" W8 U4 \( v) i# A
#include <linux/init.h>
W' f; I! s+ f#include <linux/module.h>
. H+ F' {; k6 _. K/ G; n- m#include <linux/kernel.h>: k% R7 p% Z! N, V
#include <linux/types.h>
7 ~ t2 ~! k Z$ H& k2 u5 W#include <linux/gpio.h>4 i. @! k5 { v8 x$ g0 p7 f
#include <linux/leds.h>
/ D, e+ y7 O+ L/ U#include <linux/platform_device.h>
, t# r+ x9 |/ B& _$ {9 S
" U) B: C1 c- A* {7 r9 Z! b% |#include <asm/mach-types.h># d7 |& Y6 k( h- C5 C
#include <asm/mach/arch.h>: @7 v% R7 X. @* F5 b4 n
#include <mach/da8xx.h>
7 T* ]9 ~6 N9 h6 P#include <mach/mux.h>
* o% l2 X: R0 @) M7 G6 p2 B# _+ w/ ~3 W. u
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)* h! |! v! L/ c, ~, \. ^
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5); `4 j9 [% {2 P
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
: h. n6 B. I. f/ s6 c#define DA850_USER_LED3 GPIO_TO_PIN(0, 2) _, y% U$ e F
1 T8 o' [- _7 O- @1 S( [/* assign the tl som board LED-GPIOs*/4 `5 O: `8 `% v+ l: R3 T( f; J
static const short da850_evm_tl_user_led_pins[] = {9 P! }$ o, {- S* P2 h8 `
/* These pins are definition at <mach/mux.h> file */, o9 f! ]1 d: w: l7 A% ?6 q
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,2 w& r' B3 |! W' P" f
-1
3 ^4 W8 k$ G. n2 {! w};( {2 h$ k$ ~# O% i- q
/ V+ H/ g/ m! q! J+ n' Istatic struct gpio_led da850_evm_tl_leds[] = {( Y k2 T( @) b1 O0 B) g7 R
{8 ?1 w) ~ `1 x* n' ]
.active_low = 0,5 h+ x3 z, o; a1 n5 v
.gpio = DA850_USER_LED0,! r- R3 F, M% S3 U; y) o1 J' Y
.name = "user_led0", a' _* ?& B: e* n% ^
.default_trigger = "default-on",8 ]7 {& Y% x- t9 r4 j7 N. s! W
},0 Z6 L F+ z4 ^8 A. J+ k3 r
{
7 t) ]4 F) P1 y+ w v; r .active_low = 0,! p8 K9 t4 P+ @! H5 c( K2 t- c2 v; f
.gpio = DA850_USER_LED1,& }" k) \; Y2 S3 B4 a
.name = "user_led1",
% _- g; h d$ `4 O2 \ .default_trigger = "default-on"," D2 }2 j) j! A
},
/ Z( _6 R" z" i G1 Q9 O4 b8 p {/ c3 {2 h$ g& M! G5 R
.active_low = 0,
, j6 l2 {( k! Q9 e" c .gpio = DA850_USER_LED2,
8 A: V% s7 j7 c R7 l4 r' O+ a .name = "user_led2",
/ M; f7 S6 |, S- f" S- L .default_trigger = "default-on",2 u# @1 ?- V. q( p* R7 Q! E4 l
},
0 G6 J& ?- T1 v1 I6 j {
, L, g- F1 E% ~+ I+ o9 \8 j+ | .active_low = 0,! m& H+ g- [2 y' S$ m1 o" x/ _
.gpio = DA850_USER_LED3,$ l N) ^5 s3 w2 ~ Q, R
.name = "user_led3",) k/ R C3 v$ c' b! f
.default_trigger = "default-on", | }$ j7 x% [4 m% S; M6 w
},% d* A! S* \5 w% H ]5 B R
};
5 Z& J- f# J& D0 s+ R* b6 v, a1 K' t# f3 |
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {' f0 D) Z: s3 T, ]' s
.leds = da850_evm_tl_leds, E( d& G, |0 r5 m2 _# w
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),4 q/ M- D# }9 x3 c
};
7 n' ~; c1 ?2 [( `7 s8 ^- S2 i* A
1 p% ?* \7 a6 pstatic void led_dev_release(struct device *dev)7 I. q7 q6 Z, l3 p
{
0 j; C! Q" V f4 x};
( v! C% U# [3 J* H+ p% D% k- Y- S- D$ H" B! ^8 p. ?8 P
static struct platform_device da850_evm_tl_leds_device = {
3 A ~2 z6 Z7 p1 h' B; Z .name = "leds-gpio",5 c6 f2 l1 v8 s6 s
.id = 1,$ h" Y' @; E/ ?) \( S
.dev = {
- X8 s6 \4 U- e8 C, N$ B .platform_data = &da850_evm_tl_leds_pdata,
% X& ]8 T6 ^$ h! U! u3 A .release = led_dev_release,
" y1 T! Z8 \1 {" v5 u }
3 `3 Y3 f4 v+ c};
1 R, L6 c4 ?% `6 k- K* B! F& j' u5 s% C \% e6 K
static int __init led_platform_init(void)8 y8 `+ c. r: ^- Y
{% T p D# {$ A) @$ ]1 H8 m5 B
int ret;
* \! Z: w- o7 v+ D) g#if 0* x. l+ t' k. |) i
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);- [/ W1 v9 p5 p
if (ret)
& R9 A y3 k# |* b pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
" @0 A, P# F/ L4 x& M( z% j "%d\n", ret);
* H$ C! x; T+ @9 h' I9 v" M#endif, l4 ^) H' R% F. t# K$ Q
ret = platform_device_register(&da850_evm_tl_leds_device);( @4 t$ X. h7 U' l4 t( {& a
if (ret)
% u0 ] r) H: g: K" Z pr_warning("Could not register som GPIO expander LEDS");
) w; V5 J- B, J) M3 m J else
' {/ |9 f2 D3 G& ?9 }" } printk(KERN_INFO "LED register sucessful!\n");
$ J$ Q# F% |# E8 e3 ^* I/ f7 v1 S6 F7 g
return ret;. X9 d4 Z* B6 a( q/ h: K% H# {
}
- O- L) w0 d) J8 A, E+ R2 `& Q) g7 s- ~) m4 i" P9 ~3 p
static void __exit led_platform_exit(void)
! K: r/ L+ C7 W. s{
5 R; V0 R+ U) z: M6 i platform_device_unregister(&da850_evm_tl_leds_device);
/ W+ ]* k) G4 t7 y! C3 s9 {1 b7 `% b8 G. k
printk(KERN_INFO "LED unregister!\n");
+ G8 t1 n9 U5 r" t5 j}9 p; o& k" f3 ], a0 `- z
, A3 G- A2 X4 B p4 ?$ a# U# I. P! _module_init(led_platform_init);0 H! m6 L! k. `, ]' Y
module_exit(led_platform_exit);* {" i( G6 m# q
: j: g. f3 j' p9 j9 Z
MODULE_DESCRIPTION("Led platform driver");" r- {' q2 ^& E- A! A/ W
MODULE_AUTHOR("Tronlong");
- ^6 W% o6 W$ E4 e) _9 H4 A$ {MODULE_LICENSE("GPL");9 _( H6 ?$ Z& G0 v4 P! o
; ~1 }* ]. {% n8 h k% b
|
|