|
|
求大神给下面的程序做注解,请稍详细些,谢谢。: z0 j4 Y1 }, V" i$ O- p" V
#include <linux/init.h>
; W e: b8 L0 s$ s0 U#include <linux/module.h>4 D, M' e1 \ N$ W
#include <linux/kernel.h>
6 K7 ^( |4 E& f; a7 X+ v#include <linux/types.h>5 p3 X _' ] ~% w9 V" S
#include <linux/gpio.h>
+ L" B: L: z3 a P7 W( f#include <linux/leds.h>& v3 O( J* |/ q6 Y6 R
#include <linux/platform_device.h>0 J i* |& ]( o1 M
# p1 E' v3 l# _* _#include <asm/mach-types.h>
- u- Q/ t* l2 |#include <asm/mach/arch.h>% V0 X+ w' v1 h
#include <mach/da8xx.h>6 h9 d/ m7 w; q' o& B" L
#include <mach/mux.h>
; m B+ r( k7 N& Q# `6 f! C5 Q) x; D+ L, n: u, E) x" d
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
/ Q" f/ j; H3 V8 }#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)" y5 s: |# U! X, Q3 e1 U; e
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)+ a( n5 Q7 e1 g& u" [) k) t# H9 N/ s
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)" `+ Z4 r2 c0 j$ d9 S G
3 x. @+ A7 }) p: p- L. Y
/* assign the tl som board LED-GPIOs*/% q' O% e z2 L3 X; ~5 z2 R! v
static const short da850_evm_tl_user_led_pins[] = {+ R4 i3 e( ~( n( Q; n+ k; Z2 T
/* These pins are definition at <mach/mux.h> file */* c, M: O/ \ M$ T t
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,+ f) X0 m% Q3 e" [
-1( Y! c- p% n3 D0 a5 I& u
};
" W. b, `9 _" X8 P. ~3 S( Y
% p* [5 ^# U# b# }: ^) X% astatic struct gpio_led da850_evm_tl_leds[] = {% P) a) _8 T* b! N% N: B2 Y
{
, X# _4 j& [: s .active_low = 0,
" H* \; E9 V7 k0 l& h .gpio = DA850_USER_LED0, M2 i1 r& `) z+ R
.name = "user_led0",% N% o1 n. ]! ]5 ^7 D
.default_trigger = "default-on",5 `7 R8 M4 H. [
},$ r& i k- ^; ^
{7 F% P: ~3 Q, B0 M0 V! O
.active_low = 0,
" P" j* ]. E) J6 O .gpio = DA850_USER_LED1,% y& n1 z3 b* \. x
.name = "user_led1",! g8 I/ g: b+ ~
.default_trigger = "default-on",
# V( z! A4 {2 F# i },, J6 M/ M$ |# G3 [% W4 d
{; I# w1 ?* W3 E( G% j/ E' ~6 }
.active_low = 0,9 A/ y8 y& X: S/ E
.gpio = DA850_USER_LED2,
* M# }: f8 x9 T c/ _ .name = "user_led2",
) B! C8 P2 ~& b& B7 H+ K .default_trigger = "default-on",/ Q+ b0 y7 {2 C( [
},
- c# J+ X+ Y: B' c( U9 U- ?/ u% @ {
2 \( {# C. b( K% O( Q* Q .active_low = 0,
! _' O4 G+ K x5 k9 {6 y, P2 m6 W2 ^ .gpio = DA850_USER_LED3,' E Q& s8 N( U1 N. o
.name = "user_led3"," L. S+ n2 b0 O* I
.default_trigger = "default-on",, [9 V3 U; p8 B3 ?0 Y
},( @; ~; L3 w- d$ Y5 }, e
};1 l h- O C9 G* B G3 S/ x. e
$ s" V( r. l I0 |
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {1 ?& }! N: C3 M% V+ Z
.leds = da850_evm_tl_leds,5 q& s0 X* l# D3 c$ ], x
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
4 T9 Z3 T: U `: \ H};
1 \6 _; D o2 ~2 F w1 a$ [# h6 @" C* h
static void led_dev_release(struct device *dev)
1 y6 \1 H: t6 N5 k{
% F. U; ], J$ I q7 y6 s};$ p. y( f7 _% X" Q; I X! W$ e8 w
" ^$ w9 C, a6 c1 E4 [static struct platform_device da850_evm_tl_leds_device = {2 I" F5 j5 N; Y1 H0 j* X w
.name = "leds-gpio",
0 r$ f& q' Y9 s& Q0 @5 X% m+ Z .id = 1,
, W7 E% d: M( y: x0 O. y; b .dev = {- F6 G P& f T9 B
.platform_data = &da850_evm_tl_leds_pdata,: I) e1 ]+ G, @( N9 F! r0 y3 l$ S
.release = led_dev_release,
# m" m3 S- N) g9 s* x }
8 K/ e7 m' ^" w! p};
( F9 N) @# r$ A/ @6 l0 I/ d$ |3 ~) w$ Z8 `
static int __init led_platform_init(void)
) H3 u9 Z1 S/ t{+ `# B6 m& o# F0 m c) G9 Q4 X5 D; {
int ret;( k; e! x5 E, g! [/ F! r* `% V
#if 0# Z8 ?8 l' r- ^ U V
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);: y' x& L- t5 B+ H! l
if (ret)
3 i! N9 {# ?3 m2 y# i6 r pr_warning("da850_evm_tl_leds_init : User LED mux failed :"4 h) }2 c4 @* y; n4 E4 I9 j
"%d\n", ret);* v9 |$ [. Y7 C z. \! l
#endif i Z5 U% f' {: ^9 A9 l( r
ret = platform_device_register(&da850_evm_tl_leds_device);
) ~/ p- f5 G1 J K if (ret)# B3 C' `' |8 t4 I: ~
pr_warning("Could not register som GPIO expander LEDS");/ `- n) T. j9 E
else
9 ?1 U/ q* k+ `0 | printk(KERN_INFO "LED register sucessful!\n");5 G0 b: i, h/ W& p+ \3 Q2 `7 u
9 |6 k& G3 D- e! I
return ret;1 F& v4 {0 K8 T( X& f% G
}1 s" l3 N/ D; s% K- Z9 I
/ ?! Q' X. ]7 t2 [+ E0 F' A" Estatic void __exit led_platform_exit(void)
/ [% E" F( S! v{
; k h2 ~) T2 g1 r! ~8 a) ? platform_device_unregister(&da850_evm_tl_leds_device); | \; |7 Y6 w: C
/ w% e+ h0 R* A, T/ }6 X7 l1 S printk(KERN_INFO "LED unregister!\n");2 p/ p& |! v9 ?0 _
} ^3 b+ ^( @ F! e* [2 W0 [
" B6 I" Z+ B: o7 Q7 zmodule_init(led_platform_init);
# l' I# O3 m. O0 c; Bmodule_exit(led_platform_exit);
5 t% y9 m% P2 L! w' Q6 u' X0 ~- Q3 D
MODULE_DESCRIPTION("Led platform driver");! k7 x; R8 r7 g4 s" b
MODULE_AUTHOR("Tronlong");
$ `, e/ D) j- s f1 V& w' ^MODULE_LICENSE("GPL");
: l$ h: v8 }; F# q# w( ?3 [& b+ ^- Q* b
|
|