|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
_' g0 O4 L: f#include <linux/init.h>; j- N$ m4 \7 K7 d
#include <linux/module.h>6 y: @' Y/ ^- ^7 ?6 E% j
#include <linux/kernel.h>9 y$ M, o9 C4 v9 [. u
#include <linux/types.h>
! N3 f6 i( ~# ^8 K% N#include <linux/gpio.h>
: x3 S9 z5 u6 d' q% k Z# f Q#include <linux/leds.h>/ R: l& T- K9 b3 c3 S0 r, W2 _
#include <linux/platform_device.h>
+ K- g( ?* V' E; |
. X, o% T0 i' y# ~0 U+ o#include <asm/mach-types.h>
7 o! ?+ O0 H5 |; I#include <asm/mach/arch.h>0 o$ {+ w8 s& f; q
#include <mach/da8xx.h>
* G8 {3 K K- d/ ]. v/ h% E#include <mach/mux.h>
{5 F5 O# J6 Y3 h
& k% |8 ]( T! S$ I& S#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)! t; m; s0 g& j, V
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
p6 M! X2 g( F7 M2 O#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)5 q9 X, r t% V
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
! ?' o8 V9 `8 s4 Y* f5 N! C. o8 d" P( b1 \ O n
/* assign the tl som board LED-GPIOs*/
" A4 S. {+ S) istatic const short da850_evm_tl_user_led_pins[] = {
% T; l( X' h0 y( u9 M1 y- h /* These pins are definition at <mach/mux.h> file */2 v! ?" Z+ [6 C; l7 n& R
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
7 G' l D; r& {1 t) X, Q -1
i u6 o) v. A, C, m* M};
) B j) n1 H' j* m# B+ H0 G7 Q- Y2 q" d
static struct gpio_led da850_evm_tl_leds[] = {
/ b8 n2 d W+ L3 j {
/ {9 v" m) w% E, x .active_low = 0,
I5 M0 D8 i$ h# Q Y .gpio = DA850_USER_LED0,
. m, f8 T* @3 p" I' z! Q- k .name = "user_led0",
) z& p# ^2 q$ k' l3 S5 @8 J& E& h .default_trigger = "default-on",5 r- ~- a: w; k5 d
},
6 f/ u7 T0 H, R" ?5 C6 w# }7 {) w {0 y# F: _) x2 {& R6 d
.active_low = 0,/ e7 p2 { Q) R4 Z; k
.gpio = DA850_USER_LED1,
3 g: |) k( ~2 v6 C+ C .name = "user_led1",. X+ [9 W( L1 n
.default_trigger = "default-on",
8 s; ]9 x+ I8 m! r' r1 w' T },- {5 m9 j) l/ s! @9 o' D) M
{$ V2 i+ x8 E9 [
.active_low = 0,
i- _6 s7 X0 J# f3 }; W .gpio = DA850_USER_LED2,& B, m- }$ m4 R( \ n: U
.name = "user_led2",# I, V* E# x% u7 c% A, \
.default_trigger = "default-on",0 q) c7 E& T7 |5 M9 o* Y4 t! |
},
8 Y% o1 g7 E5 W- f- T: }1 | {
& d7 f; M- G: i: a0 y .active_low = 0,
* A" |! M4 F( S! l h .gpio = DA850_USER_LED3,
" W+ k5 Z) ]3 [ .name = "user_led3",8 X9 I$ S8 U' [) q5 V. j
.default_trigger = "default-on",
# D4 U+ A+ F5 T8 |, V+ b' e },+ y' ]. ?/ q9 X; Q" ]% i' _, R
};
" y1 f% f' ]6 v8 z
# l* g; ^& @$ R: n) Vstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
; v+ y* I1 U2 A" o+ I .leds = da850_evm_tl_leds,
5 ]7 m( s5 y( u .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
* ~( H% a z. `) U' f S% @};
- |% @3 y: a& V: ]! U! W. D2 \3 [( W+ }% x9 r/ s% b
static void led_dev_release(struct device *dev)
% h' ?$ W* Q( D s4 M1 l/ q{
: t& a& T0 ?% G W};. m$ _0 U- N4 h6 M1 s
" Y! _- P0 g8 o& K9 Q# q5 ustatic struct platform_device da850_evm_tl_leds_device = {( J7 v D+ T% G8 \2 y% x0 P
.name = "leds-gpio",; Z) p1 x% e& D+ l! R( L9 S
.id = 1,: x" ]* \$ |9 F. z3 @9 [4 ^
.dev = {
! t: C( g9 D" \5 V7 Q .platform_data = &da850_evm_tl_leds_pdata,
. b) X7 v1 h$ H4 j) q .release = led_dev_release,5 p: x1 L ?# G% D: `9 x8 b" M
}
6 P# B0 o& Z' ]2 E- O$ J- I};
5 t% P y9 g2 T5 s% |& t& W1 Y$ L" l4 a1 R) R
static int __init led_platform_init(void)$ N* d+ q: }+ l5 F
{( Y/ y- h6 ?0 T8 a! K
int ret; y Y( e! g$ V; S
#if 0
# A% d& |4 v2 D1 _0 B ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
# H) V3 w8 \. J8 ] if (ret)
/ d) K+ V7 l' d! j) X+ m" J pr_warning("da850_evm_tl_leds_init : User LED mux failed :"/ g) d2 T, g) e& a, d" ~3 G- i
"%d\n", ret);
: W( a) h5 e6 Y2 v+ }#endif
+ C& z) D# \2 X# w; U6 n3 e+ | ret = platform_device_register(&da850_evm_tl_leds_device);5 C4 `# q( S8 M4 e# p3 D @3 s( C
if (ret)
r5 B3 D, e! w% N1 Z pr_warning("Could not register som GPIO expander LEDS");1 ^3 i) |5 _8 c/ {$ ~+ A
else
0 o4 P" q# M; j0 }& T# [ printk(KERN_INFO "LED register sucessful!\n");4 `7 X' X$ ]) Q) r' _1 N
d1 J& ]% C9 t( I return ret;
: Q; s/ G% {7 v7 y8 q}
5 ~7 ]5 V2 o8 H7 L9 g
% f: d8 _ w7 P) }static void __exit led_platform_exit(void)
: [- ?/ |# Z2 ]3 l/ ^{: D8 e7 S4 H# |3 h7 Z- a& }
platform_device_unregister(&da850_evm_tl_leds_device);
" C3 c! p: I/ W6 W. ]
7 g; A% L. O3 i6 F printk(KERN_INFO "LED unregister!\n");
+ k3 D6 r6 z8 z# |# W5 A1 s}
6 Z# n J0 w$ B1 y/ e7 w, A+ g) e) f+ z* o) i8 [: m
module_init(led_platform_init);
8 a. p+ v& q e% M3 j0 q! M! kmodule_exit(led_platform_exit);2 {* i+ w% e# U" R' S8 k+ g" `
6 n* t; K# G5 a, s5 ?' x
MODULE_DESCRIPTION("Led platform driver");5 s3 d5 }, ?, u/ N& c
MODULE_AUTHOR("Tronlong");
8 j, w& ?4 J4 K; t* h- _9 [MODULE_LICENSE("GPL");
' i$ g) v/ d; \" h! z" _; V, H
& W: t2 Q, e- g; }$ z/ m8 `3 Q |
|