|
|
求大神给下面的程序做注解,请稍详细些,谢谢。. w: Y: G4 w4 v: U; l
#include <linux/init.h>* Q( ?$ z7 @6 x0 c; H3 Y m
#include <linux/module.h>
! T9 `2 P1 [1 j$ p3 m#include <linux/kernel.h>
' x6 y) V' A, b8 ]#include <linux/types.h>7 A w8 T' t1 V' K: y( l
#include <linux/gpio.h>
9 d& h6 d8 N/ b4 X4 M& @#include <linux/leds.h>- D. }5 s. k+ x5 ^& V9 g9 F& S
#include <linux/platform_device.h>/ k; z+ i( U1 b
9 A* H, W' d6 `8 s; I [#include <asm/mach-types.h>, Q. p8 U" A" n5 R6 E/ F3 J- v$ r
#include <asm/mach/arch.h># |* o1 K5 N. H3 V9 v
#include <mach/da8xx.h>% H' u( d/ l/ s ~. ]! S$ S, w( s
#include <mach/mux.h>4 b" C' k, m9 D6 `/ E2 v' M/ {
{0 S9 W/ ~& Y, S- e
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
8 s5 T2 N% l/ F9 c% A#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)3 ?$ t) J( {7 d9 ]% d! O- \2 Y
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1), @! r4 O: o5 l7 C
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)) G/ E- y2 L& a+ c
" n) L' H4 w J! B) P! b/ |/* assign the tl som board LED-GPIOs*/
" n% M5 g/ H) X) ~% {static const short da850_evm_tl_user_led_pins[] = {6 @9 l7 |) G( n
/* These pins are definition at <mach/mux.h> file */
" Y ^$ b( w9 `" O- q DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
5 l1 u. \" G* N9 q -17 ^: c+ Y- _( L
};' z3 D8 Z- F0 t5 ]3 }# ^
8 n& s R+ F3 N7 W# b; Gstatic struct gpio_led da850_evm_tl_leds[] = {
8 z7 V ^4 c$ I$ f6 D {/ b0 {+ F6 A$ f- @0 }- V
.active_low = 0,
7 m3 H* E z' \" @ .gpio = DA850_USER_LED0,
0 Y9 F, u9 j2 M$ j/ ^5 x .name = "user_led0",
) K' O3 r, N6 h0 A o3 ~; p1 s8 { .default_trigger = "default-on",
2 L% A0 A. ~! U! ]5 r },& [0 Q/ c3 l" e$ \* l. p
{2 J5 p( N9 O: {& N% f6 D
.active_low = 0,
9 u& c/ m' S. t- L0 f .gpio = DA850_USER_LED1,
5 j' X4 o0 {; ^" a2 X( ^; \9 _* b .name = "user_led1",/ Q R' P' e9 G: H8 \
.default_trigger = "default-on",8 d4 _0 u$ ?, q% O6 ]. ? ^
},
( w( i, r2 [6 j& C+ S {
" O! \" F2 V8 V. v: s; i .active_low = 0,
% Y" u# ~' y V+ |, p+ w+ R .gpio = DA850_USER_LED2,
* N f' b0 M. l7 b .name = "user_led2",! @- `5 p2 D& v+ D' V
.default_trigger = "default-on",
7 r, D$ \- N5 ]9 i },
+ W" J% U8 y3 D& t( E+ k7 i7 O {
5 f5 F* A* a& [0 N .active_low = 0,$ i0 d' W [+ G# `# n; `- Z" b7 ^8 V( W
.gpio = DA850_USER_LED3,
3 h! L1 y8 z) @, }3 G .name = "user_led3",
$ k' B$ ?( s7 t3 W$ p .default_trigger = "default-on",* N9 m0 C5 m n; E9 `
},
+ d0 M1 ~: u) q0 Z6 s7 ~};
( M9 Z" C4 @, F2 n8 b; X
" V; C- R i% a2 D; q9 X+ Ostatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
1 t0 U7 I9 G+ X5 h. Q .leds = da850_evm_tl_leds,. `: m/ x: h6 W
.num_leds = ARRAY_SIZE(da850_evm_tl_leds), x" j0 g ~( H
};
4 v' N {, S5 G. L5 X% a2 @- H. b5 G. ]: g2 x
static void led_dev_release(struct device *dev)
3 b0 L* n3 ?) F$ x3 p" }{( S* `- Y7 e6 w, y; M0 k. j3 z
};
' I, o$ n1 Q/ ?* |8 m% F+ R! R, v! C3 j3 `5 D4 p
static struct platform_device da850_evm_tl_leds_device = {
! X' l, E! _, V$ R+ ] .name = "leds-gpio",0 U6 i4 ?; h; F+ x. W: k A7 t. o
.id = 1,
* L, C: C$ P4 E .dev = {
. x8 H; }" x% ]8 K8 y4 _' A .platform_data = &da850_evm_tl_leds_pdata,
- i0 { m' _" i8 R0 P7 C .release = led_dev_release,, _! q7 _2 B9 M; {3 O
}9 T( S8 Z, E' f& }0 m5 O, M
};% N: [ \% a$ }& Z8 H. o
3 |# I: g# r& r! m/ @static int __init led_platform_init(void)
; x* P% N. J2 _2 N; a, w! l( t6 I{4 a5 O) z! B/ s7 Z( o5 H
int ret;6 _" ^7 U4 u0 g2 J0 D) w& [* Q1 i% Y
#if 0
* G- y1 G2 w- v( ^% J ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
5 | [) \* d" O7 I, d6 C if (ret)
4 B% g# t9 ~, Y7 Q" s1 `3 C! q pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
0 O4 _, c( o/ ~: t N+ r' I8 @% H$ q6 f "%d\n", ret);
2 O% A9 N6 ^% G) `% I#endif
& _1 c! e- {/ Y8 d ret = platform_device_register(&da850_evm_tl_leds_device);
: r% D5 K% a" k* I8 `( } if (ret)# ~1 x" p+ H# i X8 F) r: u; M- a" A
pr_warning("Could not register som GPIO expander LEDS");
, ~" c7 z' [# K8 H, E V else( P* z6 E( Z+ R
printk(KERN_INFO "LED register sucessful!\n");% Z$ R. K" h I4 l
) b- S/ p6 H* `
return ret;5 F- y5 D6 K6 I
}
, V4 F+ D! R' B0 v" @ D; K
% j$ `0 w3 h( l: Y8 Vstatic void __exit led_platform_exit(void)$ X9 f3 T, i; c7 s+ A
{
) ?9 T0 _: h: G$ M# b platform_device_unregister(&da850_evm_tl_leds_device);. p8 q8 m5 X, t7 H# x% j/ [
" A0 g5 I. p. X& o U1 F5 ` printk(KERN_INFO "LED unregister!\n");
/ X4 f2 X& U/ S7 Z7 k, Q1 d( w7 F}
4 M3 T7 k" }/ Y; M9 y0 k s: q: R8 ]( z8 Y( \ |- f
module_init(led_platform_init);* b6 i0 ~2 y* F2 L
module_exit(led_platform_exit);7 f3 `6 X `- d4 O7 N6 y9 d" x
; q1 N. A& R6 J& N% r8 j! i) qMODULE_DESCRIPTION("Led platform driver");
4 E- G( S3 V6 IMODULE_AUTHOR("Tronlong");
* l( F+ a, j' e) o$ |0 HMODULE_LICENSE("GPL");$ P6 M. O2 d" A9 `& K
7 D* v# r1 k. f3 m- W$ g3 u, p# M3 m |
|