|
|
求大神给下面的程序做注解,请稍详细些,谢谢。) O: x, q6 |/ U
#include <linux/init.h>- Z' M6 X% F a( A; V" ~* E
#include <linux/module.h>
" s' t/ b+ s3 `#include <linux/kernel.h>
' d& y! w; F4 ^1 l# g& ?' O2 Z#include <linux/types.h>
1 S9 f0 \% v; ]; i) r. P#include <linux/gpio.h>( d4 |6 ]$ a9 ]" D7 Q. z
#include <linux/leds.h>
! i3 s8 a2 @# }% h#include <linux/platform_device.h>
/ j( I8 O6 S4 N' t) o, o% e! S2 \/ {8 \9 _/ u, c
#include <asm/mach-types.h>4 M0 m; ~6 d6 v2 a! H
#include <asm/mach/arch.h>! Z6 ]7 m" C6 m4 [! y
#include <mach/da8xx.h>
" b( X6 \; z8 r7 `: a& X+ Q#include <mach/mux.h>$ {' X% l+ E! o7 C5 C m* Z, X
. O0 r, d9 j1 H2 t( V9 e1 L/ S, j4 T#define DA850_USER_LED0 GPIO_TO_PIN(0, 0): g* J( S- e# ~5 \+ Q5 D
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)% r9 S# b' N/ s4 I6 M7 K z
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)5 U* H* }/ e& ^) K6 L; \* W' t
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
/ V5 v" i, g. I4 J' u
# y5 v/ j( \0 \0 A/* assign the tl som board LED-GPIOs*/
- w$ k6 M& W. L) Y7 b3 v% pstatic const short da850_evm_tl_user_led_pins[] = {2 {0 m9 i- U: l7 B! J1 h. z
/* These pins are definition at <mach/mux.h> file */
" [, k6 r+ W8 x6 E* U DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,! \! s' N* m2 B) z/ w' x9 [
-1
) f6 c! |: ?5 n6 Q3 c! O N; I! ^};7 k5 g) N& i; r e9 g3 D% A
V# S6 W+ `% vstatic struct gpio_led da850_evm_tl_leds[] = {
$ i ^3 c, y) C( M* |% u {" s8 F$ h8 s) R# x2 I& y# v1 [. R
.active_low = 0,2 y* H& ^8 G3 D3 Q' X; l
.gpio = DA850_USER_LED0,7 A4 {4 B' M% s1 E
.name = "user_led0",
3 b# C3 w& L* } B( V .default_trigger = "default-on",1 y" p @$ } A% J; P/ f
},8 _; i. Q. ]" q/ L, g- e8 H6 G( S
{
( o. z9 _9 f1 I6 m( s .active_low = 0, O0 ^: w8 D0 l
.gpio = DA850_USER_LED1,
4 I3 | X' a4 s( W& \ .name = "user_led1",1 q v2 e! A! d ]6 v2 |" U x0 Y
.default_trigger = "default-on",
! ~- C2 ]% v8 G ]% ^) E, U },
$ }/ n/ X [ C" O/ ~) S, R {
& ~2 q; Z6 y; j1 }$ ^ .active_low = 0,% B" K9 i& w# v6 \' [. Y
.gpio = DA850_USER_LED2,
' E/ g( u& `5 Z! w' y# K6 m; M .name = "user_led2",& S/ H2 v* ~+ D5 L3 K9 g6 G
.default_trigger = "default-on",
: A, Y: @1 \+ b* o+ t },
' T8 E- ~0 @4 ^5 k {
6 e; @! s6 }9 {# {3 @, T, B .active_low = 0,
0 x7 Z8 h7 o3 `2 r" R% z9 x$ Q .gpio = DA850_USER_LED3,7 B4 V4 L/ S) j7 y/ j) X
.name = "user_led3",) m. r/ q8 _3 w1 N D, P
.default_trigger = "default-on",
) q+ v5 P4 H L9 d6 P6 C% C5 o },
2 s/ V1 A7 [. Y" E};- P6 H& X. g2 @- Y
( Q+ x" I7 F4 u
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
/ z9 o4 n8 K! {: U .leds = da850_evm_tl_leds,
! t6 I% T9 K' ? .num_leds = ARRAY_SIZE(da850_evm_tl_leds),( L% c" B8 c5 j3 b
};
* f# _: [4 h. a+ J) F3 ~5 p4 ?4 d1 J
6 ~+ G! f) u+ p/ Mstatic void led_dev_release(struct device *dev)
+ m) t0 e2 [8 O0 J" g9 n9 }7 p{
+ K% \, d& x8 U- [: e; ]" M};
; l' h/ D1 W' i! _. X% W' [1 h+ G. R
6 o6 |- k; p4 u$ zstatic struct platform_device da850_evm_tl_leds_device = {2 P+ G7 `9 K. `* n$ h7 ?* M
.name = "leds-gpio",
% U% n1 w7 s. q, }$ X6 L( G .id = 1,
. h( }3 S$ K( ^$ _9 @& N. H .dev = {
, v! ]7 q B: _! _ .platform_data = &da850_evm_tl_leds_pdata,6 a& [# r0 x8 ~& R
.release = led_dev_release,1 y& ?& p- `" E- l7 ~
}/ @$ u2 S7 K$ e# V% P" F
};
+ F& i @% Z7 Q" ^" V I! P& y
: g- V( j/ B( W6 B% t3 gstatic int __init led_platform_init(void)9 Z4 G; S" U/ h+ o& }
{8 W; V1 j1 y& \4 ?1 U
int ret;- z* O: d# h$ c+ u# _8 G
#if 06 X5 `) `5 C, v( J6 l- q z% J1 r: h
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
$ x9 [! U% {2 d if (ret)( W& a5 i1 m3 o& U0 {
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"9 o% a% Z1 [/ q1 h
"%d\n", ret);
2 {# z/ h0 a. V$ g. r#endif; m' p) a" E! |& ]9 }0 |
ret = platform_device_register(&da850_evm_tl_leds_device);
6 f; M5 | I* I! W) m if (ret)
: U0 U' R) W, \6 p pr_warning("Could not register som GPIO expander LEDS");
- U0 z+ t1 z( T4 E6 p( x y else
3 C1 b* Z6 z& H# x, x printk(KERN_INFO "LED register sucessful!\n");
- }/ L" A9 w a9 y& z1 L# w
# e6 Z+ D+ M" y! S0 \ return ret;/ g9 x9 k7 [, L' l. L
}, j* @, |* a& q" u; }6 v
) o; V; W- a3 @1 U$ f5 A) f1 I% G3 x
static void __exit led_platform_exit(void)2 ~9 b5 O, F F
{
) O0 F" w4 G* j7 O) |# d# B& v platform_device_unregister(&da850_evm_tl_leds_device);9 |: \& a6 s) a' F1 `+ E
X0 S( m8 Y; s$ M2 L2 H2 ?
printk(KERN_INFO "LED unregister!\n");' A: g. y5 J" O3 @) N8 P
}
+ h6 K/ ^2 v: B0 ^2 m) `( j; X
# _8 p( |) I! }9 Smodule_init(led_platform_init);
' R$ A" |: d0 g( e, Jmodule_exit(led_platform_exit);
7 M. A& M6 M! \ A M5 U; \( j1 W* o9 ^% N4 t' l- W3 Q# g
MODULE_DESCRIPTION("Led platform driver");/ D' `. s0 r7 Z& i0 I
MODULE_AUTHOR("Tronlong");% H- B$ c& i* @8 @
MODULE_LICENSE("GPL");
( }- j( V: A1 g2 I+ L) ?3 U7 r, ~* |
|
|