|
|
求大神给下面的程序做注解,请稍详细些,谢谢。9 J% R0 v/ \0 `4 @
#include <linux/init.h>
% k0 B8 ?6 a3 q( o- k#include <linux/module.h>5 `/ S3 \" X- @3 s& D! ^4 V( m
#include <linux/kernel.h>$ P9 q m, E( Q/ M
#include <linux/types.h>
0 |% c1 g% Q) \- D* j7 e" I5 l z#include <linux/gpio.h>0 w3 S+ Z( I# E% ^8 d' E5 F
#include <linux/leds.h>7 s! H% a" W/ Y( L4 C! w
#include <linux/platform_device.h>
& X7 ~% u7 I( g$ z% D" s5 S) v! ?
) K# f0 P( W- G" d, A#include <asm/mach-types.h>; {+ c! P. U: [. z: Q B
#include <asm/mach/arch.h>: ^1 }! x2 A/ _3 U/ x
#include <mach/da8xx.h>" N. V U# [* N6 B5 x3 ?! H" c3 F. `) b
#include <mach/mux.h>
# N% \0 N1 }, U) R2 R9 c8 }; G4 F/ h# N) [
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)2 H/ o: \$ V0 O0 `. h1 F7 W
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
+ Z1 p/ T9 V1 X% u: A, N8 _$ g#define DA850_USER_LED2 GPIO_TO_PIN(0, 1); s; T ?7 i3 r r0 Y( E
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)8 N0 u/ f g) t' B! e' S
3 K) Y5 s1 F% a% m8 g
/* assign the tl som board LED-GPIOs*/; Z5 T5 k1 {4 ?& g1 y" S2 u: E
static const short da850_evm_tl_user_led_pins[] = {
1 ^3 T- H( D' P. _ /* These pins are definition at <mach/mux.h> file */# |6 q( M* S3 C4 R- x8 d
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
% f1 p: ^; T& n/ f* ]7 z5 j7 A -1
2 q$ z$ c/ Z: [};
; N5 z2 K: p6 i, m
7 U9 m0 k' |4 v( x0 }& Pstatic struct gpio_led da850_evm_tl_leds[] = {
, D! Z/ f1 J# k( A- h0 f {
8 I5 B4 F' x9 N8 l1 V. { .active_low = 0,
+ f D: o }" D' ?. X .gpio = DA850_USER_LED0,
* q5 u7 s1 o8 r, Z$ k .name = "user_led0",
' l& u6 ?( n5 v7 m2 y .default_trigger = "default-on",' k: J; X7 p' o" n- w1 q2 ?
},
3 R$ k/ H& y8 B {
6 n4 R0 L2 Q! c! Q3 F8 f .active_low = 0,
$ l( a+ [% y. d4 W7 y- |8 ^; d) G .gpio = DA850_USER_LED1,$ m/ V9 n0 A# a' q
.name = "user_led1",
) w# d4 `* E5 l7 p# q. D! X .default_trigger = "default-on",. T2 e" o! c1 T6 a9 D
},
$ F' U# w, W0 k/ b9 C {& r( Z: f; [, S& q7 q2 I3 w/ a+ {7 V4 ~
.active_low = 0,
- J8 t+ H, z7 p0 a- A' K .gpio = DA850_USER_LED2,
2 V$ [8 ]. d; a) w% n .name = "user_led2",9 S" h- V% s y
.default_trigger = "default-on",
: }) ` u4 i% C: ]& k/ v; J9 a+ _ },
5 K" u* p7 K4 Z% i* k. K {
" X1 G" c6 @( l8 a5 G7 W .active_low = 0,( V/ g8 V* X) }/ C" G$ E+ H7 ?
.gpio = DA850_USER_LED3,
% g" h6 ` V1 k- u9 |( I .name = "user_led3",3 }6 d$ Z! d5 E1 l2 ]3 J. y
.default_trigger = "default-on",6 N0 ?& h. a3 G4 G4 U7 @5 ^
},
& y. K# E V+ V2 h/ w& d};8 R' Z6 h# W: B+ |5 n" J- P3 g' o
5 G: ?9 ?- l7 M: ?
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
+ G; V1 \5 f+ H' ~, B) Z, ?. Y h; Y .leds = da850_evm_tl_leds,* n. K7 J* O y' C' a# V# f* t
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),! e; i( K r# @9 O
}; G" f. v/ {7 v" n# U7 {
O! e. n' m" a' Q1 I4 c# `+ O. f
static void led_dev_release(struct device *dev)
. A) v3 N) e: q{
: ~7 O9 q' G; ^* h5 M};
# H V3 D- `1 Y4 {- L
# i0 O4 O# D6 B$ q8 w" wstatic struct platform_device da850_evm_tl_leds_device = {
5 v; v7 N. Y' a6 E- h- ], f .name = "leds-gpio",
" Y" q( u) m0 g' h- } .id = 1,- Y* H, E5 {$ I. V
.dev = {& m7 h% q. u+ h3 T( e8 l
.platform_data = &da850_evm_tl_leds_pdata,
, q0 w, H7 s4 w; L .release = led_dev_release,
* Y9 i* b" z. P$ k }- @ T% e/ K# s! X
};
. b! E! Y+ p5 p2 H) }
U8 K/ @1 W+ Y: s7 Q$ hstatic int __init led_platform_init(void). o7 Q6 X7 A! x
{
* F) E; R0 r+ V, x$ K3 b int ret;
8 o4 ~- H% g& c2 ~#if 0
( @3 X3 Q0 u" ?8 i3 t, c: n, H+ R ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);: a. R) A$ c! z: d' a$ _- h
if (ret)/ I) ?2 G( a/ Q
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"1 W' o) I3 ]1 y
"%d\n", ret);8 X" J4 Q% I1 B6 i5 ~+ Z! A
#endif
# ]/ X5 x- g4 d5 F% ?' q7 W# Z. E ret = platform_device_register(&da850_evm_tl_leds_device);- j+ b& }, D0 K0 a
if (ret)
' _, W! V' J! c: H: b) E: E pr_warning("Could not register som GPIO expander LEDS");
' X1 e6 \/ ?" g) H; I( V) F9 ?- g: Q else
7 p, J/ m( t/ @1 T; w! |, m* b1 f printk(KERN_INFO "LED register sucessful!\n");; T' Q# Z3 b5 a3 `% R! F& r
& D- @+ r, h; }/ h8 t
return ret;
1 g; Q! R6 T, u}
+ H" c' o5 B! O0 R6 d" Z% `6 O( ~1 ^0 ]1 y
static void __exit led_platform_exit(void)
) d6 ^9 W1 P7 s5 |" k; Q{
8 m l, o0 M* e( T/ N! a% i( y% z platform_device_unregister(&da850_evm_tl_leds_device);8 I X' G" B& D- r8 u) H. T7 ~9 M
0 D, n: b9 R( g& x5 m. k/ U printk(KERN_INFO "LED unregister!\n");' N% c( g8 N$ k$ f
}; f3 a: @2 M8 ]
) c0 `, G5 j8 `* _6 Q K- p3 |: T2 T
module_init(led_platform_init);
) S1 S/ k2 `3 }6 ymodule_exit(led_platform_exit);+ m) h5 N* O: H D: N
" V4 v: p$ p* [7 E5 e) ^" C
MODULE_DESCRIPTION("Led platform driver");$ E# f+ Q8 D. k5 s! [" Y
MODULE_AUTHOR("Tronlong");- Z4 ~+ P9 E/ d7 y
MODULE_LICENSE("GPL");
# w0 N( }; g% a! P! A; j* M
/ l) R2 c: x! h+ X6 V |
|