|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
4 \% B5 A Y7 d. u! U#include <linux/init.h>1 p/ U" P# Q: U( @3 `% P1 {+ o
#include <linux/module.h>
2 p, C$ d4 ^: e1 ?# }. m) F, a#include <linux/kernel.h>
3 s( ~+ c% L- t2 l' H7 o' D( w#include <linux/types.h>
. n' s& q& |. G+ L9 ?& K#include <linux/gpio.h>3 O2 v/ ~ w" z1 m7 q) e0 R
#include <linux/leds.h>
4 w! C" T3 N! ?2 E3 J. Y#include <linux/platform_device.h>
" I) m0 F5 ?/ @
- B8 H7 w5 y% o% b#include <asm/mach-types.h>
7 f1 l! h# V4 T; z& l#include <asm/mach/arch.h>
/ r$ z3 q, k. R) R5 a& o#include <mach/da8xx.h>
' l! c; v, g$ J( s& M- g#include <mach/mux.h>, d* n$ _9 x, r$ S7 O1 a
/ y0 Q* ?% O9 y& P) J* r/ r#define DA850_USER_LED0 GPIO_TO_PIN(0, 0), D7 N% R: p/ `8 n B0 u* j- q; |
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
7 T8 r W' W0 k' E) j# V3 u#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)* R P& q9 @* T4 l% m& }, V! K& I
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2). o a7 P: ~! ?/ x4 ~- ?
$ |+ `7 ]& A; }) L/* assign the tl som board LED-GPIOs*/
! }4 o; Q8 ? \5 v/ P" ystatic const short da850_evm_tl_user_led_pins[] = {# r* Y3 \* `; q8 e" ~7 q
/* These pins are definition at <mach/mux.h> file */
8 P" M7 t/ U. L. `, P DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,/ P) J9 p. {. S# C5 \, G, h
-1
4 `1 g) h& M2 p) d};& l# l9 |, S7 _$ I# q: ~, q- ?3 l' s
: {! y2 \% q. u( i! _" @static struct gpio_led da850_evm_tl_leds[] = {, w4 |4 c e6 R: g
{
6 y a4 o9 @: S& d( U .active_low = 0,
/ k& y5 h# u2 Y7 Y .gpio = DA850_USER_LED0,# i: h7 a/ n" v8 G
.name = "user_led0",6 D; }8 M z6 [: Q; [9 [
.default_trigger = "default-on",
+ d9 O$ ^) E4 y# ^/ y% p [ },
4 Q5 N# t+ Z# R# ^ z {
9 U! d. O3 h8 T$ W& ^1 r# n" T .active_low = 0,3 u& L7 ~2 f3 n
.gpio = DA850_USER_LED1,& F' B2 ^) g6 J$ k1 b K
.name = "user_led1",1 t9 |# k2 K' m2 W1 A7 w
.default_trigger = "default-on", F/ d8 j- e. a; F
},
! s1 H: h# R+ A4 `6 s. E {' s1 P7 E2 i' R; Y
.active_low = 0,
9 U8 b b8 W3 ]+ Q .gpio = DA850_USER_LED2,3 \6 r* u0 m: D
.name = "user_led2",
& Z1 n, U" m$ i! w .default_trigger = "default-on",
$ T+ i& {& W) r* K6 k9 c! h3 y },
2 b0 T" S, ^1 S: _2 Z {
# r [7 [" m* }6 l+ w .active_low = 0,
& K# B/ g+ b i( m. g .gpio = DA850_USER_LED3,
7 b' t; x) p/ r .name = "user_led3",
+ B0 N; A5 ~" I% s3 j .default_trigger = "default-on",3 m5 z" i4 ?: o3 p0 i$ U
},9 p$ K. h ~5 S6 K3 Q9 R
};1 _3 L8 @' s% j8 E5 O
. V; y2 b" Y H8 b, j: b h6 Ostatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {( l! N& c& y7 z0 t5 Y0 s
.leds = da850_evm_tl_leds,
6 s p) q1 c; S& q r) F( Z .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
) M/ K: ~, @6 @9 F+ N6 _};' _3 o* v% ^7 E# \
4 t' R/ p" l& H: V- ystatic void led_dev_release(struct device *dev)( X" U8 ^# s3 j. ~
{: A9 m; Z7 [8 u8 X
};
+ ?* I& x2 J2 }- L4 g3 g" G5 L: _3 A$ z6 l
static struct platform_device da850_evm_tl_leds_device = {
3 u/ O7 s, V; f" H. b .name = "leds-gpio",. p) k* Z j0 i% m. f
.id = 1,
( L* ?4 n" M$ \1 Q1 @. i .dev = {8 ] v# K3 x+ [. N6 }8 {! m! G
.platform_data = &da850_evm_tl_leds_pdata,8 D! \- b I4 q8 G
.release = led_dev_release,5 O8 g* F0 N- a) g
} b: m N; H; j
};% U. b$ [1 c, d1 |
, b: f( _! @9 x; }static int __init led_platform_init(void)1 K5 c: D% j; I7 G
{
# q' i# h# p3 p8 V6 x int ret;9 ~+ e: Y# i; u; O; z% d
#if 0- A4 f: h2 q0 P ~
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
+ V6 ?, G x y9 R' ^ if (ret)
4 @5 [: p7 t. d pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
# q) ` ?! q" S( u% w "%d\n", ret);
$ P. A9 |; x& P& ?2 n#endif5 W+ a6 R/ c4 d; J( y8 S+ D/ O, `
ret = platform_device_register(&da850_evm_tl_leds_device);8 e7 @/ W/ w& ^
if (ret)
* u, l4 D) `& X m0 _* u3 c' H; i pr_warning("Could not register som GPIO expander LEDS");! N* M( v$ a3 B
else" j; R% }& G6 m1 s7 h
printk(KERN_INFO "LED register sucessful!\n");
4 V( u/ `$ B$ I" g2 k; p$ g( e& D+ y. `$ ~ x+ v
return ret;* h. P$ Q! c( S W: |% k# o) c
} C$ r8 V5 V, O4 S d
( F6 r2 a7 e, F" @/ _( y' k- s
static void __exit led_platform_exit(void)
8 w! {) x5 @' g/ G! t{
1 J9 Q: A0 j. l+ C9 { platform_device_unregister(&da850_evm_tl_leds_device);3 }# t' p, E u
5 K/ i4 q8 n* `# T J
printk(KERN_INFO "LED unregister!\n");; m1 P( t+ _$ J& ^
}
5 B0 }# s3 c- V1 I8 K$ T" J" l( ?
4 w3 v; Y& {4 R: J$ dmodule_init(led_platform_init);9 I% `0 q& ~" f: r
module_exit(led_platform_exit);
" a4 P$ m8 s7 t: K' |
E0 @, o* d" V( m+ [5 [8 N. iMODULE_DESCRIPTION("Led platform driver");
/ Q# i% O4 Y! r: T% FMODULE_AUTHOR("Tronlong");# m* L( k3 p4 H; X- s! {+ F
MODULE_LICENSE("GPL");0 y2 S; q. Z3 {; t6 c' Y+ {4 N
0 Q* \9 ^% |6 A# n8 \# | |
|