|
|
求大神给下面的程序做注解,请稍详细些,谢谢。) n1 B! S i9 f. `1 T
#include <linux/init.h>
) u6 Q8 b( s- J3 @% F4 m, Y#include <linux/module.h>" ~, {: @$ ]. k9 u# {! o7 \
#include <linux/kernel.h>
% y) d' O. G4 b" S#include <linux/types.h>
. @( g) S& S" U- B#include <linux/gpio.h>% s2 }' |/ l2 Y% ~8 B) v" |
#include <linux/leds.h>
: v* ]# }" m$ U* Z% z* l. `#include <linux/platform_device.h>
: T- d7 I% V6 b9 } d& ~3 K
, R) E/ I, Y/ C3 M% U#include <asm/mach-types.h>
8 d$ S' n; }; R @) X% P#include <asm/mach/arch.h>
; k7 X2 \5 m- A#include <mach/da8xx.h>! F _# `0 f k1 b! ^! p" G1 b* G
#include <mach/mux.h>/ b ~6 K$ M4 ] P2 v# I4 y
$ g& S$ p: c& v9 Y0 M
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
/ p) [1 F0 p- u. v: s#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
?' ]. c8 @1 e% s m) O h" k+ p#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)# o: ]1 N2 ^2 }+ s
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
) [7 C& `4 S0 G0 v0 X, a, U# j, P: |( G+ P" @
/* assign the tl som board LED-GPIOs*/
W8 s0 z5 T+ P/ _1 N2 Ystatic const short da850_evm_tl_user_led_pins[] = {
A7 T" ^; X1 Q' Q% p1 Q /* These pins are definition at <mach/mux.h> file */
: R; a, m) o2 S v7 O3 b DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,% o/ u; O S3 Q. W/ k- b
-1
' L) r- F4 d. }4 D5 N};! G3 }! C! _# M, w) ^5 c
" |2 J b9 d% I5 x5 I5 t# z6 b$ sstatic struct gpio_led da850_evm_tl_leds[] = {
/ G9 R' O! n: u* H$ o6 `" ] {
# {# S# D* {# B; F! y .active_low = 0,
) x& Q5 O- Q5 K9 c .gpio = DA850_USER_LED0,
; z2 T4 q( c _; V7 e .name = "user_led0",3 M7 D3 s3 J( K; q
.default_trigger = "default-on",
: `7 P) a4 j L! @! G( z% j# V },& p% G9 S" g j2 u( N0 D, g8 y
{6 P/ C" Q- [% j, W) q
.active_low = 0,8 ^8 l- b* _' P6 k. c. J$ b4 ]% J
.gpio = DA850_USER_LED1,) h, A! G% K4 Q% \- C/ [
.name = "user_led1",
9 a$ z: `' Y8 S3 n# U .default_trigger = "default-on",
$ R/ |3 @7 q) b: g# R1 S: H0 E },
" W4 j% n, v# `3 b! X8 q {( F, _, V$ K5 G3 H% I+ ^
.active_low = 0,
& T- @+ [. C1 e1 o .gpio = DA850_USER_LED2,
* s* @% d" }0 `$ c7 @% t .name = "user_led2",
* g/ W' u# }& Z, @ .default_trigger = "default-on",) a: V$ b0 P% @: B5 C5 p% _4 c' C4 \
},
' n& m9 y7 N0 V0 A# ^0 z2 X {
# V( }! ]5 N1 b3 h, [ .active_low = 0,
& z$ s* o5 T& r3 }8 s6 k .gpio = DA850_USER_LED3,
& x1 G/ S1 W8 O .name = "user_led3",' ?- C! ?; {/ j& R# Q
.default_trigger = "default-on",+ x. ~* P) G( Y
},: t7 q1 P% } f/ H+ S- d" N: C
};- S8 l* @/ D% `$ }* O% E) i( j
) M3 D# {. [0 l- ~, g+ H# Bstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {( @% F& `. J8 V6 b/ N( L
.leds = da850_evm_tl_leds,; S( Y" [2 R+ N( L4 Z
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),- D) @; i- K _) g
};- Q* w& I" }( a4 P3 N: e
* z3 v5 \3 H5 P Z6 i
static void led_dev_release(struct device *dev)
3 c( r i! _* I{
7 ?, I" t+ P" L6 ? o};
+ H0 Q. L9 H' \4 X! ?& a- U m* I: `% n" r
static struct platform_device da850_evm_tl_leds_device = {3 K" T3 S6 V2 v0 G. c5 ]3 _6 }* n% `
.name = "leds-gpio",
0 I5 `% ~% g, w5 c- q$ |! Q .id = 1,
4 ^1 z% o8 ?2 j/ `( M# U# i .dev = {
: k& S6 L% e8 a; I .platform_data = &da850_evm_tl_leds_pdata,
- \- }' D5 `6 O$ \8 ~) Z3 a* s .release = led_dev_release,! y# h7 V. T4 e; y
}
+ J6 ~2 {( `6 [! f) p};
2 V6 I/ _- N9 H- [, H% k4 ~ ` i/ T) q4 ?9 w4 \( g7 G
static int __init led_platform_init(void)
) a- e+ M: a- O6 g0 z! K& e1 V{
! o @; {, M5 ]: Z, g% B2 a4 y3 t int ret;
; Q2 f$ L. S; @2 C) s* `7 [#if 0( L9 j. z! T9 S6 |6 _$ S# v
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);' g9 G4 J4 N. x! p6 m/ E
if (ret)
4 \1 a1 D: g: Z8 @- P pr_warning("da850_evm_tl_leds_init : User LED mux failed :"6 F. _6 |: B& }; |+ e; T$ y
"%d\n", ret);
9 V% B) Q' E }$ y" q, b#endif" a# L0 a- |' R# [! Z
ret = platform_device_register(&da850_evm_tl_leds_device);
* \4 W9 f5 J0 S' ]/ D0 } if (ret); T4 W# a6 h+ Q
pr_warning("Could not register som GPIO expander LEDS");* t; Y4 t; M; A+ Z* g2 l7 b
else' d6 _1 G9 e# c0 O4 m! f& X
printk(KERN_INFO "LED register sucessful!\n");- \4 f5 [' L3 u$ b+ m6 Z7 _+ L* x
0 ?6 ]& H+ O' `% _% ^* v Y
return ret;9 V3 _* D" e2 }1 N3 v
}' F; b, h* W6 a& B# `
; B1 D; V5 f3 q% l, s( f
static void __exit led_platform_exit(void)
+ _0 M$ ~* |2 X( ^3 D0 @/ X' s{. D6 W- _! x0 [; H: K
platform_device_unregister(&da850_evm_tl_leds_device);; D: ? F$ m* q' p, x% m3 q
( @3 g- V2 m: ^: E$ w
printk(KERN_INFO "LED unregister!\n");
$ h3 `7 J5 X+ U: x( j}
- Q3 q* ], ?4 L0 r
2 M3 @& ]+ Z# D3 m- Wmodule_init(led_platform_init);, u- Q" Q: t% O* J. t) ]
module_exit(led_platform_exit);- T. U4 e4 }, x! p+ C
% Q$ f/ y4 x. C' a7 H& S5 i0 Y( T3 YMODULE_DESCRIPTION("Led platform driver");
9 M6 @- Z% T# y8 {: h$ D' ?MODULE_AUTHOR("Tronlong");1 D% u" }. H4 D6 n4 P
MODULE_LICENSE("GPL");
& K; A8 C4 @9 o z) U- C
, b$ C- \% T( E% C! D: M+ X: J |
|