|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
& Y+ b; i* M+ \0 t- [2 l9 g#include <linux/init.h>
5 h5 R2 d8 \/ F- o#include <linux/module.h>5 J1 `# g2 I/ K
#include <linux/kernel.h>
7 J* Y7 \0 O6 h2 ~ P+ r#include <linux/types.h>
- \) d; t' T- S' S9 n#include <linux/gpio.h>' n, B8 E# C4 Z3 Y# h3 A
#include <linux/leds.h>
* G8 R2 O% L! y#include <linux/platform_device.h>
' {3 U' j8 ]+ Y% ~ i3 I7 ?) \3 ]9 Y/ w! U! ]8 x/ ?
#include <asm/mach-types.h>3 @' \# E9 c+ }' w4 O
#include <asm/mach/arch.h>
0 u' w! O% c4 H# H- \7 j* Y1 |#include <mach/da8xx.h># j# f& v) J* ?1 {5 R5 R
#include <mach/mux.h>+ ]1 Y' g& j* n) n" x8 _% \' `
/ _4 x8 C) j% }( i
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)5 x1 \6 t; c4 N, S* }
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)3 o) g, u& N4 l9 c
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
2 [1 S9 D2 E6 P3 `#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
6 J! C, z+ w0 E
+ p* R0 h! b* a0 `, M) t$ U- z/* assign the tl som board LED-GPIOs*/' Q0 |8 [; k$ H2 q/ h E
static const short da850_evm_tl_user_led_pins[] = {
* d) n; }4 K( P4 s! C" E: J /* These pins are definition at <mach/mux.h> file */. s# K" d5 c5 `6 a3 |% ?3 W
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,' e7 i5 r% a. Q3 d1 Y( B) A
-1- r, M: P0 U4 ^
};
' ?9 k: q0 ]* I: c \
. I" C/ W2 X* E6 ^" }* ^static struct gpio_led da850_evm_tl_leds[] = {
. U& ^0 z) A) ~. O" D+ @ {
3 p5 ]2 D% X0 a) W: Z5 r; N .active_low = 0,6 A, `, h1 r$ G2 }; `
.gpio = DA850_USER_LED0,1 s. I9 {% l2 ?# m( ~
.name = "user_led0",3 [/ s- `% j- e4 |. y
.default_trigger = "default-on",
; M& V( j/ ` ~ },2 g3 e( @, F$ z) \8 W" m
{
; k" h: G3 w( s# x2 |9 ~7 l' z .active_low = 0,
6 C7 P& W8 X \) Z' }/ t .gpio = DA850_USER_LED1,
: l( J: n+ ^( w5 n .name = "user_led1",$ E( D: S! t( M0 A9 e( \
.default_trigger = "default-on",+ c! Z. E& c2 a
}," t( U6 @2 Q0 S. P+ v
{
* y k$ U, t* ~ .active_low = 0,% e( P$ }* K) _) B" N
.gpio = DA850_USER_LED2,5 R/ N) {) B% J. M. x
.name = "user_led2",% \" T, d& n7 G# y. L( O
.default_trigger = "default-on",
9 c% ^7 s% Z! |& Z! l },
4 c0 |0 c0 X+ ^$ S7 B {4 h$ `- V( _8 S7 b f4 ]
.active_low = 0,
9 Y5 F5 N# S9 x3 m8 G5 T .gpio = DA850_USER_LED3,
1 n& R; j" T& m .name = "user_led3",8 J& D! D4 R5 Q+ b3 P
.default_trigger = "default-on",1 {* J" G" {$ K* y, Y% a: c, Z
},( w. s+ M6 l% O
};" [. ^, D8 s# s3 q. Z
8 D, V: H; H# |+ J6 Z5 Vstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
$ x- o1 d- O' Y9 e .leds = da850_evm_tl_leds,
1 m- R; Q* S" |7 N% h# @- f# [2 S .num_leds = ARRAY_SIZE(da850_evm_tl_leds),1 o; c& i! p0 g/ T' q! e
};# V& ] u. E* H ]+ J: Z
( `' z/ p% t1 W; I& P9 d8 [static void led_dev_release(struct device *dev). v- C1 u2 T! ]: K+ B0 h, ?
{
. ^1 G) z2 U! V$ Z z};
& C% b3 A6 v3 a8 Y5 j; z8 a6 L q& l+ \
static struct platform_device da850_evm_tl_leds_device = {& v( ^" _8 }1 U0 n
.name = "leds-gpio",! U' r) G- J H7 g3 K6 E
.id = 1,! B" |+ j# L. l2 Y
.dev = {2 E$ x( ?2 u r! u$ u# V
.platform_data = &da850_evm_tl_leds_pdata,
* t1 b. B2 B( x& l) Y .release = led_dev_release,
" E) G( o* [ J# @" ~ }
8 f' f8 v- R" `( w W};9 b" C4 m" f) Z1 H7 S
- o4 U+ S0 ]8 M4 K6 bstatic int __init led_platform_init(void)
a9 f7 x& C! W+ r9 R/ E{) n+ d$ q0 l' H* [: }
int ret;* t7 `% O$ z3 d+ J- K2 d
#if 0
( A. r" H5 ^7 x1 [6 ? ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
" I! y+ c6 P* y if (ret)
+ a" Q; V) F( J, }5 Q. V# I pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
- G4 h; Y! J3 J3 C& V "%d\n", ret);; R9 f& h3 p6 s9 y
#endif. q: T* y0 ~: ]: _ i
ret = platform_device_register(&da850_evm_tl_leds_device);
9 i" K9 N- t' q2 r* T if (ret) y; X S1 h% f5 {7 X
pr_warning("Could not register som GPIO expander LEDS");& B7 K& m: F" U* [. W+ C1 [" J0 ?
else
* L! G& i0 u' y7 g. v! a0 | printk(KERN_INFO "LED register sucessful!\n");
8 g! ^) A( F3 K0 s* _7 n v8 I
return ret;$ X& W: p. ]) k/ N5 {' s
}( d( i0 ~, k4 V& `, F. q
' N$ b& I0 B1 z. \8 W8 ~% ]static void __exit led_platform_exit(void)
9 }+ z1 o" W' E2 t9 Q{
0 C3 T: `& c, c+ |- _$ R" b1 M7 q platform_device_unregister(&da850_evm_tl_leds_device);, W8 a9 y% J/ h$ O9 R! N \* r
0 j5 q$ K4 l z
printk(KERN_INFO "LED unregister!\n");0 L. ^( M+ f$ C6 \8 K, k3 g
}
, ]# J# B' ]( `/ l" f# O# O
! o; b5 ~& L: Dmodule_init(led_platform_init);; C+ Y+ Z& ]( k
module_exit(led_platform_exit); e; a/ p7 W! ~% P$ Z
' ?& R6 ]* v" x5 W* WMODULE_DESCRIPTION("Led platform driver");
6 m r0 W, r: {" {MODULE_AUTHOR("Tronlong");
6 x# ~; D) V8 a( n. a- nMODULE_LICENSE("GPL");5 O$ H) P; @* j) h
$ I- X7 b5 \. n! m, Q |
|