|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
3 x! N3 ]) R8 G- V/ |% a' N#include <linux/init.h>6 u8 I6 S/ N+ o* |& M* r5 k
#include <linux/module.h>& [1 A$ b/ R H5 ]; G; D
#include <linux/kernel.h>
9 m* N! ^7 v$ q( Q# c0 {$ Y#include <linux/types.h>
/ ~$ S9 E" U) r, e/ n# w#include <linux/gpio.h>: s& {+ A5 Y1 O/ l1 L
#include <linux/leds.h>7 o. n3 r! S" A" [ q
#include <linux/platform_device.h>
+ f% H4 s+ @ d$ g a* W2 u0 x8 t* ^8 p& ^0 s
#include <asm/mach-types.h>
6 P& c5 A2 J8 A#include <asm/mach/arch.h>
7 s5 x. ]; @9 A#include <mach/da8xx.h>5 ?4 c! x2 W' E! r
#include <mach/mux.h>! B E9 K# [7 I7 N$ d: P
5 {! S- ~) u% g" Y5 x; x/ }+ O$ c% m
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)2 B, d1 t6 U: v5 w3 ?
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
: b2 l9 s' v' m; k4 c#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
G4 n: n' n4 W. t; i) |#define DA850_USER_LED3 GPIO_TO_PIN(0, 2): \: |" Z/ Q3 S+ p7 I
% t$ f+ t& _5 s6 M e
/* assign the tl som board LED-GPIOs*/# ?9 M: G C4 q" c. c
static const short da850_evm_tl_user_led_pins[] = {
* W2 F `5 Q& L7 Q" V8 e+ X" J0 y, b" ` /* These pins are definition at <mach/mux.h> file */4 T% V& v" R/ A2 G: j3 N; V+ \
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,1 I! {. W3 {& ^5 E9 `
-1
* |: i g k; t# t3 w};7 Z/ r" ]: ]* H* ~* w) v
! B/ _- } {2 p& a U
static struct gpio_led da850_evm_tl_leds[] = {% E1 j+ ~! `0 H) F( z2 N
{# I2 e( d: u4 ]6 A9 l. n% t
.active_low = 0,& P+ V0 _. ^3 \2 p& ?. d
.gpio = DA850_USER_LED0,
7 e/ I9 @; f |6 B7 ~) u# | .name = "user_led0",
& v3 }' l( l E; `2 D# f, Q .default_trigger = "default-on",
* O6 N+ F9 N) P6 y },
- m L9 o+ c. s! Y( J2 g1 n {2 X. `6 s$ Q' |0 M& d
.active_low = 0,
0 {+ B' R% X! D$ p4 W' u- H: E2 J6 d .gpio = DA850_USER_LED1,
/ }# W8 H+ i* C7 \ .name = "user_led1",, s5 s( S8 t0 _& C
.default_trigger = "default-on",
* z% e0 O! `9 }7 v9 {. l; {; r },
$ r5 p% R; Q {: w {
$ Q6 E6 b6 O; ]4 D .active_low = 0,
* `% p8 Q( H+ j Q( ~% \ .gpio = DA850_USER_LED2,
, n/ y z5 d0 y7 |8 Y/ C S .name = "user_led2",
: A+ v, y! R- j$ G: m9 k, H4 x .default_trigger = "default-on",
_" q! e7 n% u; k( V },: p8 Y' o& `1 {9 ?& _ j
{
. S: D* O: ?, o9 V9 D9 b" X .active_low = 0,
! ^& M/ V$ i1 [7 N' u% J+ g .gpio = DA850_USER_LED3,/ m0 G2 }* \" n/ z+ D0 G* Y
.name = "user_led3"," M) F3 e' I2 W7 k/ E0 m. W. f0 x
.default_trigger = "default-on",4 d- G& _ }/ n% `
},
; Z! E# F# @ S: K};
* S( I3 P2 m) y8 L6 o7 s! B; v" ^" y/ O- z
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {' M$ t, c: Z- u7 m
.leds = da850_evm_tl_leds,' Y9 d& n" y1 L/ M; t
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),5 P' W1 m" p, F" _) ^* K' G
};2 `' c; M' o6 b5 j5 I$ v7 S
: L! b9 ?4 n& ~& v9 b* X2 ~8 estatic void led_dev_release(struct device *dev)9 C4 W1 V2 R6 V
{
) [$ }. h. O$ h" l! [% p};: B4 P( C4 R1 p
/ H" C. I" c1 {5 Z( P7 b8 M0 W: J
static struct platform_device da850_evm_tl_leds_device = {
0 e* k ^: s6 g! K+ x o .name = "leds-gpio",
* p+ L. i3 a: H, c .id = 1,2 _* t) K6 z5 L" @; I% B
.dev = {
. Z( K8 r6 F8 Y2 T$ O" Y& N6 l .platform_data = &da850_evm_tl_leds_pdata,
* Q3 R3 q" m* R$ F8 l) N$ u .release = led_dev_release,
. O. C# o6 n7 X1 {2 g; i8 Q }* Q+ p" V R. ]
};
; `: h$ e4 ?9 ]$ F
8 c9 G7 I/ D7 ^% @% ~* jstatic int __init led_platform_init(void)
8 a' M( i6 Z. w; R, o+ r+ Z2 P{
6 D- b+ X% ^0 t% k6 W# U int ret;
; g# I( M$ V% B#if 0) E1 M" P3 s; i( K/ h7 e/ C1 x) I
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);1 O D' ]7 J6 m& X& F
if (ret)
$ N2 N9 B- N4 M# [$ l+ {4 {! ^& Q% J m pr_warning("da850_evm_tl_leds_init : User LED mux failed :"& O# t: [5 [) \$ H4 y8 b
"%d\n", ret);
( A+ e+ \4 K# _9 v$ e#endif" z' o: r: L) v3 r: ?6 m7 K
ret = platform_device_register(&da850_evm_tl_leds_device);
& X. c T# g! f& p. ]- O% K if (ret)2 s0 ^# R$ r2 n: j0 P
pr_warning("Could not register som GPIO expander LEDS");
) T1 v$ A3 |- B, M else8 B) l6 Z* l) T
printk(KERN_INFO "LED register sucessful!\n");
$ A; ^- _- f7 J2 K. s! P" |/ P7 j& C0 L2 q# {
return ret;- {, a; d+ v/ i3 a4 |) k
}) r% E3 T, e! z
* s, G# l$ O/ t2 s- |( k* x) ]static void __exit led_platform_exit(void). O7 c! A- b" c& z* K
{6 X4 N- J/ F* d _- Y$ L, ?; D! p
platform_device_unregister(&da850_evm_tl_leds_device);
3 f& b, }" [% a; j+ _+ C
$ t1 c0 ^9 X! C' A4 D+ t printk(KERN_INFO "LED unregister!\n");+ A9 U! W% @# Q, H1 m# q
}) H# \% W) v2 l* O
. d: X. T3 T. x) kmodule_init(led_platform_init);
9 v# b* g9 s8 m4 g$ Vmodule_exit(led_platform_exit);- A8 J ?: W+ z& B7 d% R0 n
" y) W. `( b% S ?
MODULE_DESCRIPTION("Led platform driver");9 a3 C% ~) d/ V: f5 W. |
MODULE_AUTHOR("Tronlong");' n' V2 ^% ]$ I& |, s* s/ a
MODULE_LICENSE("GPL");
0 ^/ Q+ ], M# H3 N( X, G l- a0 t
|
|