|
|
求大神给下面的程序做注解,请稍详细些,谢谢。7 J$ Q" p* V# t, `( q; a6 W! |
#include <linux/init.h>7 k9 X- ~3 k* i
#include <linux/module.h>' o2 m: {2 q& I2 ]
#include <linux/kernel.h>! p; J- B# {: `6 y" P6 c! ]: P( A* m
#include <linux/types.h>6 |. @, _5 w+ R9 H
#include <linux/gpio.h>
7 b! M0 C! k" W; y* k! I& K#include <linux/leds.h> l3 F& Z: q9 |" V8 o7 R% ~8 Y; Z6 X
#include <linux/platform_device.h>
2 U, m" f' } C, ^* J
/ y/ p, @- G: F8 D$ M/ |#include <asm/mach-types.h>
4 V1 G8 |$ l3 O5 \8 J#include <asm/mach/arch.h>
! H$ e. X! ?0 B. _& m$ n- n#include <mach/da8xx.h>
0 |. g9 ]3 P4 `$ n#include <mach/mux.h>
, M0 X( K O1 f7 R$ Q4 r% K; t6 v9 [( ^3 I" A6 w; X2 n0 C
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)) M& r1 C0 K& l8 i- x6 B/ S
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
$ E, K @0 `+ l9 v#define DA850_USER_LED2 GPIO_TO_PIN(0, 1) \4 b6 g* u' d( w2 }( O
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)1 l$ H: Z- a0 x( @. t, W
0 A# { n5 ]9 @1 ?. R1 n2 p
/* assign the tl som board LED-GPIOs*/1 I- `8 ]* J& {0 }9 z
static const short da850_evm_tl_user_led_pins[] = {/ c. S! P) n# A
/* These pins are definition at <mach/mux.h> file */
+ b3 V" O9 l! |9 q DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
1 G0 ?# {1 q5 @3 i -1
! p% k7 I' @ l8 Z& j) O" W6 B};: l0 l2 r, H p
- `8 @, I, T! D' u* F8 Y
static struct gpio_led da850_evm_tl_leds[] = {/ |6 j- w' i4 O) z
{4 |2 W4 s3 D U) c
.active_low = 0,
1 j% m I3 I# o8 j7 y .gpio = DA850_USER_LED0,# f1 v5 n7 s( q/ r
.name = "user_led0",
5 r6 T4 ~0 j( f! B+ d- f .default_trigger = "default-on",
. L: s. f2 x( s0 R/ T! n7 w& R },: K" b1 T4 J( o6 A" y1 x3 t
{
- {0 b/ \' {) |! s8 g" E .active_low = 0,
5 f5 x% u( n; W; \ .gpio = DA850_USER_LED1,9 }; ^5 `! ^ I- n
.name = "user_led1",. ?( M9 J$ \' X; ^
.default_trigger = "default-on",8 E) w6 b$ t# _) l' D: M. E9 J: V2 Q
},
5 \* K, }9 z/ g3 Z {) A- D, G' L! {" g2 I
.active_low = 0,
! C* n Y) ]+ u/ y8 f .gpio = DA850_USER_LED2,
, _$ c$ m& o% S: d: a5 E- h, H .name = "user_led2",3 k/ \+ ~' u: U1 t: R
.default_trigger = "default-on",
z2 f( X( ?3 T# v+ O5 {$ L },4 v5 ]9 m( j9 [) @ u @8 a
{
0 E& ?4 }% v5 |4 g .active_low = 0,( K% ]6 q# \6 y' Q
.gpio = DA850_USER_LED3,
$ s+ N7 O. ]* S V' Z% ` .name = "user_led3",
- n/ H& y5 O3 T1 H. k+ c .default_trigger = "default-on",
* R: S/ W/ Y3 z, r/ S },- g! x, o, ?( M/ ^
};+ s' x+ R6 {% ]+ C+ I# R
7 \& {: L+ u# o. P4 h- ]static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
, I% D5 p" _4 F, d; Z5 w U .leds = da850_evm_tl_leds,
- L- A% k% e. a3 L3 ?: ]5 F6 J .num_leds = ARRAY_SIZE(da850_evm_tl_leds)," x3 T+ P1 m" i" S/ @9 A# A
};, U9 q2 y! H \/ Z$ c
, g* g4 E0 R2 J: y- e! G
static void led_dev_release(struct device *dev)5 p1 z/ O, Y, [9 F0 X. E& ^
{
" k5 z: m; e* K# a- h! d1 k};
+ [+ B9 z' M8 L( }& j/ ]+ g8 C
( Q! s0 q$ F, I9 |- ^static struct platform_device da850_evm_tl_leds_device = {
+ L* P( S% C" ]. U! H% y. G" ]# T .name = "leds-gpio",
8 d6 b' y' h1 g .id = 1,
! F( A( G4 V, D! y& \9 y4 I$ x .dev = {! E, {: {- c3 u
.platform_data = &da850_evm_tl_leds_pdata,
9 R1 S9 z- g0 r- Z3 B: { l/ L- A .release = led_dev_release,$ g% P* c* {2 T7 y! y+ N% } @* y; w w
}$ Q. d7 _, K" R- x2 `/ _- i
};
, t1 `. e4 C( c* m$ r
/ {) H5 G9 Q8 i/ Z- i, Mstatic int __init led_platform_init(void)2 D, l5 Q" S& c E) {/ O
{
1 R) K j$ k0 K% s; X int ret;
$ o4 ^) U: y7 s$ p ~/ S& q#if 03 i/ o% N9 [+ i* Q: k3 h
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);8 x, k1 ^, b- e, l" ]: G" j/ |: a
if (ret)
8 Q, r5 j% r; r4 Q1 {" i2 E% y; g$ \ pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
* E5 n* u p& J$ ?$ v "%d\n", ret);
: [$ G3 O/ Y# e' G2 e6 U#endif* B( |* ]: {) G; B& I$ J2 r
ret = platform_device_register(&da850_evm_tl_leds_device);
# Y: U% Z# @* B: n if (ret)+ n5 y( N8 d1 N) v9 Y& ]
pr_warning("Could not register som GPIO expander LEDS");( f, `7 w. S; Y+ g4 Q
else
1 O) N# @4 w2 G+ E5 P! r3 D$ y printk(KERN_INFO "LED register sucessful!\n");* E! A5 T/ i( y
9 Z, Y0 s c$ `2 O* ^ ^
return ret;. R& p; Z. S3 { X8 Z) R
}
( d0 w' N9 u. ]& |) g6 D- Q& H; b. @# a' h: I8 A4 p% F4 o
static void __exit led_platform_exit(void)
. {, Q& L; d- e{. U% b+ D2 H- L- F% I, W
platform_device_unregister(&da850_evm_tl_leds_device);
% v+ P& h7 p* y) I) `" m0 L- d! p, K/ l4 E8 k9 O* W
printk(KERN_INFO "LED unregister!\n");/ {$ z6 g7 q9 O B5 {
}
I' r1 u1 Z5 N% a3 o3 }/ T
, g' Q5 A" `3 `3 mmodule_init(led_platform_init);
# k+ Y4 [0 U5 cmodule_exit(led_platform_exit);
( v8 ]5 H% [9 R5 c
( I6 s; A! T4 N( ?$ [$ w' b) cMODULE_DESCRIPTION("Led platform driver");8 b& S- H6 B4 e$ @: q# `& d- e
MODULE_AUTHOR("Tronlong");
& Y5 X8 | J1 c Y# ]MODULE_LICENSE("GPL");5 w! Q) V( m+ t8 J+ s
6 n$ F$ d5 ?1 I! X( O/ L |
|