|
|
求大神给下面的程序做注解,请稍详细些,谢谢。 H B! J& ?+ `7 \
#include <linux/init.h>
. \- L/ I3 t! t* W0 l#include <linux/module.h>& Q$ V* q; K# e- y
#include <linux/kernel.h>* y. D) x a3 l3 q6 P! y' R2 j9 Z
#include <linux/types.h>& N r* T5 Y. U1 u: G/ v
#include <linux/gpio.h>
* O* l0 M0 n) Q5 m* ?5 y3 W#include <linux/leds.h>
7 d( S# _. H7 z1 W+ w, }#include <linux/platform_device.h>
$ {+ g A% m2 L0 Z
4 D+ U) s: A% F# y( w) q% q+ J- V7 F6 P#include <asm/mach-types.h>
+ ]0 e4 v- Q9 l6 T, `0 d#include <asm/mach/arch.h> M: c! E& S% B; Q R
#include <mach/da8xx.h>; L& A# l6 w( h; w j+ F0 z
#include <mach/mux.h>
+ A0 J5 f8 Y' y6 u4 b8 U( g3 v2 G! F( r# |) b7 O" Y5 x9 _; F, v/ H5 t$ v' `
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)* p' W5 W D0 S [9 e# u0 U
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5); {4 y0 U. m* _" Q+ ~
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)6 z* @ V: R. R) L# p S+ `
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
3 j' F9 k7 K7 l4 r: D( {6 O! R! l2 j$ b- _' S* P
/* assign the tl som board LED-GPIOs*/* [" V0 u0 \* B( s4 l
static const short da850_evm_tl_user_led_pins[] = {
3 L0 f7 }0 M+ I1 T2 W /* These pins are definition at <mach/mux.h> file */) g V4 A' z9 x) h2 M9 I6 l
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
' o/ O0 m k3 i0 } c! Q3 z" V -1
. \5 h' S* r9 \# m0 ~: @};' f# P7 H; l& B: V, g' n
. A& R M7 [$ v# k3 K6 u5 ]; \! I' C& Z
static struct gpio_led da850_evm_tl_leds[] = {
9 Q0 }1 s$ j6 p& j7 w/ f2 F {
3 X$ ^5 ~- e5 Y .active_low = 0,
9 W, |$ a' R* g: c& E4 n" w .gpio = DA850_USER_LED0,, l5 K" g6 O; f* }
.name = "user_led0",6 p0 ?" T/ h7 n2 x8 G* G
.default_trigger = "default-on",
( e8 i& o6 f3 n7 W, B },
% ] @2 @" F, C2 d( J8 r2 c, g$ t$ t {/ T" m5 u1 C" Y- ]* U5 h
.active_low = 0," M1 ]6 S# Q- x( U" {& i
.gpio = DA850_USER_LED1,
1 i: S# ~1 t. K6 | .name = "user_led1",; |& M; O2 m; K6 T
.default_trigger = "default-on",/ Q* z6 Y8 R O8 x' E
},
' t8 w: I; m0 `6 X. j {
9 h5 n/ b9 I! r2 Q .active_low = 0,! L1 t9 Y$ E1 c7 e: b- A+ c8 ?3 S
.gpio = DA850_USER_LED2,4 E! u1 | c* m& D
.name = "user_led2",8 m3 A0 d8 }. E) M
.default_trigger = "default-on",& I. Z8 V" W$ Y5 U6 d
},
) |8 p6 z1 ]. {$ K {
# e% o: ^6 n* g& v4 F) e5 x3 ` .active_low = 0,
7 d x- b3 Q& N+ r' G, _ .gpio = DA850_USER_LED3,
/ S% {/ {7 {7 k8 z- f .name = "user_led3",
Y6 F# i2 v9 ]" A b7 Q9 O .default_trigger = "default-on", }: W9 z: W3 H, U# f4 R8 U
},
% i! I& @) m2 {" g" B};) X% m( K( h4 m2 v
# H% E6 m3 P8 a' w, ]6 ~+ s+ ~% @
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
7 c1 v' e( D! N1 T6 J .leds = da850_evm_tl_leds,
! d* s* ?/ @! M5 J2 a0 ^3 h .num_leds = ARRAY_SIZE(da850_evm_tl_leds),. }# O y% k! X) e7 Z" E3 O
};
, B. @& V3 p1 w8 j! B7 | E" A( P2 E- I" Y: L
static void led_dev_release(struct device *dev)
7 j6 s1 R8 i% S( x$ m{
6 f' n; E1 v7 B% L: f; V! t+ o};; {/ i, Z3 ?1 ]
) T5 w" H: Y0 _static struct platform_device da850_evm_tl_leds_device = {
/ I; f& c+ _7 } .name = "leds-gpio",
* G! x6 J9 c6 d9 Z! e0 ` r .id = 1,
) p5 `$ q2 H" R" c .dev = {" L' i9 }" B0 a9 i9 r
.platform_data = &da850_evm_tl_leds_pdata,
: t+ u- m, `8 d6 i2 h$ w! \1 c6 e .release = led_dev_release,+ W2 o! R4 a# ?) Q
}6 ~9 n o( |4 @6 j
};" e z4 z) ]. E6 N1 p+ d" }4 N# Q
) E# m- b* ?8 q+ e! L3 Rstatic int __init led_platform_init(void)
+ H9 I2 T/ \3 f{$ ]! `& [2 ~& ~9 Y4 t5 k
int ret;
; s. s8 @9 E0 C b% o#if 0
/ q3 i" p! H# _. \2 v6 t! q ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);' u+ Q- M) R6 H
if (ret)5 c7 U: j/ Z: ^0 m* q3 }
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
( u2 c$ ^( h* O7 {7 l5 ?" E3 [. y5 z/ W "%d\n", ret);
. b$ q* i8 D! ]#endif8 w1 g0 G/ b, ^& X f
ret = platform_device_register(&da850_evm_tl_leds_device);
$ \9 r' [2 N. ^3 I- W if (ret)
' ]% I2 M2 p3 x pr_warning("Could not register som GPIO expander LEDS");
6 ~4 c% K# Z8 R& \8 x else: r+ e+ g, h6 Y8 M! w1 z8 E
printk(KERN_INFO "LED register sucessful!\n");9 ?3 K2 F" [/ y
' z. {; X4 J* f return ret;- S6 Z( [8 C1 V
}3 u# }* g+ H* V! Z' S1 X. d! s
# ?1 C; B& {+ R O! Q7 M( s$ m5 c( r
static void __exit led_platform_exit(void)
q& q4 D3 I0 B( L) Y& d{
: _" V% L( e' G6 }& Z3 n p* \ platform_device_unregister(&da850_evm_tl_leds_device);
% A6 Q' c* }7 v6 T! F6 p( B: {6 g( r
printk(KERN_INFO "LED unregister!\n");
1 p6 ]0 O1 A$ X}5 G0 F7 `# f: B( E' j+ l
/ ?5 D. ?4 ^2 {( }% E- Qmodule_init(led_platform_init);
) Z6 s! M1 A; M0 a# t/ wmodule_exit(led_platform_exit);
* V7 a C4 _0 V, b3 b1 n0 W2 h8 [& [) s5 r. Q& m5 d" k3 l. O
MODULE_DESCRIPTION("Led platform driver");2 r; F% M/ R! f3 N9 F$ S
MODULE_AUTHOR("Tronlong");( F) z9 h" U% y) n1 h, S
MODULE_LICENSE("GPL");0 G- c4 c1 {4 K2 d
5 S4 f0 H, r N$ A |
|