|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
7 j. `- V$ W1 I9 w/ P#include <linux/init.h>! O% q' [& ^4 {- x) J" y' E/ e
#include <linux/module.h>
$ z* r/ o( ~1 L7 L& T#include <linux/kernel.h>
2 }( S; Y" n: e$ R s* ^9 O#include <linux/types.h>
, u" W/ [, n- F6 Y: M @) q: I#include <linux/gpio.h>
# A! |' W. q/ W; {3 a#include <linux/leds.h>
9 y; e2 d' o6 r#include <linux/platform_device.h>& \5 \: P8 U+ u }% T
k( m3 E* z; p, D- X#include <asm/mach-types.h>
) I9 X1 f/ _+ U; h( @/ P9 b$ c#include <asm/mach/arch.h>7 l2 H. }/ A' U' S% ?
#include <mach/da8xx.h>
0 t. X* N3 T! r# \! B#include <mach/mux.h> w' z7 k% H5 Y: b
' C5 s- f4 z7 {' r#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
" K2 ?& w# d# _#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
# z2 ]0 u/ N2 y9 U8 C0 y#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
# O& Y, K4 s. k* x% z6 J7 {& m7 p$ r#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
. Y E5 b8 K0 E1 a' s; [" g$ S7 u3 e1 \* c: o! f
/* assign the tl som board LED-GPIOs*/
3 }+ ?0 F( k6 q3 e; T, lstatic const short da850_evm_tl_user_led_pins[] = {
6 @1 _5 _1 ^3 H5 W0 b+ V+ \ /* These pins are definition at <mach/mux.h> file */
+ C3 E' c1 D8 j( c7 ]8 o# w$ q DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,' M* e2 ~8 s! O1 |+ |1 r
-1 I5 u- j4 f& q& @
}; B# C! t) G n; f8 i, ]& @( J3 G
# H* Y& G. t" A7 g( m
static struct gpio_led da850_evm_tl_leds[] = {* _- O7 ~' h$ W6 |4 C2 _
{
* ]( b8 d4 f5 H4 Y) { .active_low = 0,6 J# S5 l$ d! [" T) Q/ x" Y2 {
.gpio = DA850_USER_LED0,; w. C( ?+ @" j O
.name = "user_led0",* a* ~5 h# J" L8 a# W& D& K: k
.default_trigger = "default-on",
# B; D- c7 T- \ },
( O* L- z$ A8 i- K% g {0 z5 P W" z p) p) V
.active_low = 0,+ ]& j. W9 L) I9 l/ N/ X$ X
.gpio = DA850_USER_LED1,) n# T- x) Q$ [! E% k
.name = "user_led1",% F! ^5 W) {# d8 `2 a% {
.default_trigger = "default-on",
& x. y9 r6 z# ?, h. H },
S1 D, w; h. V0 N2 [ {
2 d2 H. J) J( p* k1 E1 r .active_low = 0,
' o4 y- }3 Q* W2 Q" | .gpio = DA850_USER_LED2,
, \) y/ O$ J# P( Y: _1 c0 R .name = "user_led2",
. I$ q- v* r, }2 D .default_trigger = "default-on",
4 J. z7 q: v% e4 {/ p) } },! r& F* L! u: I' |' B9 S/ m/ D
{
3 ~* w0 R( X: y .active_low = 0,
6 h5 I( V# P) Q/ S& v# k .gpio = DA850_USER_LED3,4 a7 x% f6 Y# ?: H* z g
.name = "user_led3",9 {0 d2 v U* \& i# [% c
.default_trigger = "default-on",7 O k. ^. X/ P& ~4 ^: n
},; v/ t- G! k2 }4 I
};
& C/ R$ C2 S8 W2 p. h9 e5 W/ `+ i E3 Z# R) X( `
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {4 O3 E9 a2 ], ?! t. a+ t' u
.leds = da850_evm_tl_leds,2 m! Q! \3 h6 w* b& _6 ~- F) a
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),# l3 T. j% d, w2 y3 |, s! g
};
& ^0 p( Y: L& R4 {8 a/ A8 u$ `; _' }, y! j- d* v; c; s, ^- L
static void led_dev_release(struct device *dev)
8 J1 r6 z2 E. I4 E{# z, d H& @; s, ?
};
- ?' [9 r& ]- k1 c% X9 K- l1 g4 {5 m) b9 N
static struct platform_device da850_evm_tl_leds_device = {
5 Y: Y4 P# B1 s! F: L. K+ _6 j .name = "leds-gpio",
' ~4 g1 D9 R0 h' `. X9 o) G/ c) T .id = 1,- J1 C) T, k3 L9 {
.dev = {
# n2 w6 e2 x- b7 N4 C z6 I .platform_data = &da850_evm_tl_leds_pdata,
9 q7 W% z Y6 [" [ .release = led_dev_release,, \5 H& d# Q: {* l
}
; v1 L; Y" Q' ?' v};6 {/ t; H9 [4 _" L
; D6 E9 W" \( o0 ^% E) O1 ?static int __init led_platform_init(void)- Z- x% }7 ?, l! @. q1 n
{1 z! S @7 U' t, q$ u# L+ M
int ret;" q2 J8 u9 h8 A4 g. C* ^; }& z: Z
#if 02 j) B6 _7 t1 N2 m& @$ R
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);8 A' F d) C( r. D8 |% y+ ]) M
if (ret)2 e% r* G( n% z" M, b& b5 k& W, {* T) D
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
. o" T, F4 a) ~8 b! C "%d\n", ret);: V1 T5 m" ^1 |! k
#endif! g5 g1 X, H+ M- h' E1 f% B# B
ret = platform_device_register(&da850_evm_tl_leds_device);" \; v A& e2 T7 `/ l# A8 @5 X0 f
if (ret)
8 _& G. l) ?5 k1 r8 E+ ~ pr_warning("Could not register som GPIO expander LEDS");
3 W2 U) n! L: `; d else
3 ^( L& [) t1 a5 n0 X; h% o3 K printk(KERN_INFO "LED register sucessful!\n");8 I, i$ g( p, t. G! A3 E. z
2 s3 M' G1 L2 g9 @; G) ?/ l$ G; n return ret;
9 X7 k% ]9 c' `: [& ]6 M}9 [4 N3 r0 R" S. O
$ m+ I( S" E+ vstatic void __exit led_platform_exit(void)
8 H# u; D! I6 X( K{
4 s! w z4 `+ U( q platform_device_unregister(&da850_evm_tl_leds_device);
$ v+ D6 A6 u5 y' s# ^& L2 A* _8 k& w9 T8 V
printk(KERN_INFO "LED unregister!\n");
& e6 v$ ~, O& O% f}! b. s2 C t' d6 l2 ?) {; e/ V
* H8 g4 R) y. J9 R& F9 P% o/ J
module_init(led_platform_init);4 B. A) |# R: _2 Q' o
module_exit(led_platform_exit);
5 k% [$ N* j3 |# A8 [8 B/ [8 x. k2 ~, w2 O+ N
MODULE_DESCRIPTION("Led platform driver");
1 H6 {" D7 K: \& Q# u1 kMODULE_AUTHOR("Tronlong");8 ^. h4 s. Z: A, [& Z# x4 k
MODULE_LICENSE("GPL");' M* m2 U( j* ]4 ~* h7 [
( y% |6 m7 t2 {7 }, r0 Y |
|