|
|
求大神给下面的程序做注解,请稍详细些,谢谢。6 Y) }$ u0 t( l' t, w$ O
#include <linux/init.h>- H+ w* m, w4 S
#include <linux/module.h>
/ \1 Q, y- `2 f/ R5 ~$ R) N#include <linux/kernel.h>) f! a _' \0 p. h8 B# C8 ]
#include <linux/types.h>1 w1 Y/ z) P6 U! ]% o- d
#include <linux/gpio.h>
. x# C, ]3 n V% _7 [1 C3 ?#include <linux/leds.h># O& ]: o* R, _/ R
#include <linux/platform_device.h>% v& h! n2 E! l- m; t. v
v3 A" H2 U+ H- f( o
#include <asm/mach-types.h>+ s1 G7 _( F* T) X- S& R! p& I% e
#include <asm/mach/arch.h>/ c1 p! S8 x- O6 p# r
#include <mach/da8xx.h>' p8 n" x. D- R/ y2 j- X
#include <mach/mux.h>
0 h' o- j2 ?% F/ l+ U9 O b0 n: }
5 H1 h* T: \& _3 t9 E! Z0 E* N2 \9 r#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
9 Q; e- L4 @, I, K+ G#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
0 i; r1 A/ l/ f$ k, y* o) s#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
+ }+ {0 D9 H9 z& ]- Y#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)/ y% Z2 \0 }" B& z) i, p- F
- Z0 V2 k" k% V' M6 ^- C
/* assign the tl som board LED-GPIOs*/
; ~$ @% |- U/ r; o6 G9 m; j3 f% xstatic const short da850_evm_tl_user_led_pins[] = {
! E7 g A9 I0 W; q: r }9 X /* These pins are definition at <mach/mux.h> file */" P, C) T/ }+ x: `+ @# x) T) a
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,2 _ ~/ b9 b2 H$ [* o' T# s
-1
. E5 E' T6 X7 L};- k/ ^5 t) @2 B! Y, {4 X
) e. [1 r9 v& t% p9 `# pstatic struct gpio_led da850_evm_tl_leds[] = {" g+ ?" O* W5 u. W
{( ]' X$ e' k- G* y. E
.active_low = 0,
% D3 s# U k% @8 l2 \* L .gpio = DA850_USER_LED0,# V" ~/ _% x7 _( h7 i! z
.name = "user_led0",
+ z; T3 Z V8 S$ ?* e .default_trigger = "default-on",- N6 t1 i2 Q3 d; p8 B
},; i0 B* W6 a1 S
{
8 o! b& F& q) Y/ x .active_low = 0,' P5 C) O; R) q
.gpio = DA850_USER_LED1,% F" n7 n, i3 P' p' s1 w
.name = "user_led1",
; P2 i# V v# E7 k E .default_trigger = "default-on",
q( z6 S( H7 g, Q2 E& S% p },
4 S0 Z# s7 F. e0 U" D9 k) S {
& p8 Y; n; U$ O9 J- l- {9 W' z; `4 m .active_low = 0,
9 @& W# H) k* Z8 {0 _ .gpio = DA850_USER_LED2,& k7 r- M/ k* Z- e) y8 z
.name = "user_led2",
0 T3 I/ H) {$ c& W9 `+ g, O; ~ .default_trigger = "default-on",7 I+ l/ i- k7 o' |
},
6 w% P! V% R+ {4 S* G3 s3 ]$ H4 j {% C8 e3 U+ P; U* m) s
.active_low = 0,, I% K4 I) R- A: s. j+ D
.gpio = DA850_USER_LED3,
7 O7 m0 [* e! n .name = "user_led3",
9 [, E& T6 z! p* Z .default_trigger = "default-on",, _& K4 x8 D+ W4 D% Q4 o
},- r4 u6 ], X( m- z9 T% Y
};
6 l! s3 |+ h1 U" |2 d/ u' [* c3 @5 e) y
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
: R2 q r* B5 x0 ` .leds = da850_evm_tl_leds,, S0 b1 h6 _4 R3 T. g
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),! l O' i; u1 O$ @* U# @8 E
};
3 b6 w$ h! O; `" B/ H) U4 e% o& x- I6 m4 v I3 t. z- f9 @
static void led_dev_release(struct device *dev)
9 X8 Z2 M) g3 G& a( R; {{# S- {* m& ?$ ^: W- B" `! O- O
};
& z% I, D5 f4 g8 D1 M- a! h- _+ u1 f2 y0 r
static struct platform_device da850_evm_tl_leds_device = {- E+ N# a; C. [1 k. U
.name = "leds-gpio",
3 w. O6 q: q( y p- ?8 v .id = 1,
2 y9 p! Y0 Q' F0 L1 ^ .dev = {
/ h5 P& |/ @- ~) n* c% Q( u9 j .platform_data = &da850_evm_tl_leds_pdata,
8 U C# `' Y1 S' Q' D, r: M .release = led_dev_release,! G! t( @! l! \2 b2 w9 P/ ]
}- }% v( s. O( j2 w" f2 H
};% ^% H9 m, }$ e/ c
$ J$ l" Z o1 }static int __init led_platform_init(void). ?! v; J5 E/ c5 i# R
{
" M: t) {) ~3 \. l' r4 u2 e- ` int ret; c$ P6 A9 \0 U# U: m7 V
#if 0; B' K( u/ W) g( N d, o0 ~! O
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);0 V8 R. S P. {; b
if (ret)9 {, x% d& z% m K! F
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"* f6 H- l$ r2 O* J% C& h& L
"%d\n", ret);
! @, W- P8 ~+ `/ e0 k/ B3 U#endif l9 L6 V$ r8 ?7 U( D! j
ret = platform_device_register(&da850_evm_tl_leds_device);
9 x% r0 P6 v/ g; u( G4 I2 b+ R. j if (ret)! D! U, j2 r( |; X# e8 `& J- d
pr_warning("Could not register som GPIO expander LEDS");2 Y/ B5 ^- o' q
else
W2 v! i, G: L; d: k. s" e printk(KERN_INFO "LED register sucessful!\n");9 g: \( \# [5 ]% p. J0 A
/ B& [0 r+ y: \2 ?! j, @7 q5 Y
return ret;. N1 g3 v7 p ^$ j
}
. S, M! F( J) m" g+ F7 R: L2 a, ^& T8 l" p! ?: _% b
static void __exit led_platform_exit(void)
! F( Q6 k$ h) h( e{2 s% y8 J( ^* Q" {& l% _6 s
platform_device_unregister(&da850_evm_tl_leds_device);
6 K1 ~5 Z, I9 l; ^4 L0 H2 p7 G; ]9 c3 P/ y! `- v; s @3 } q
printk(KERN_INFO "LED unregister!\n");
6 D* H* o3 M/ e8 }: _" m$ m3 B}
! a! i1 s% Q7 A) h" c$ j
8 N2 }) F: Q. O/ @. F7 ]8 }module_init(led_platform_init);
+ a) L4 A, s% ~6 l6 @7 gmodule_exit(led_platform_exit);
* z$ }9 ?+ p* f2 o9 Q: V- m) p4 @( j% h0 V$ J F' a; L6 [
MODULE_DESCRIPTION("Led platform driver");
3 j3 ]$ T. z" sMODULE_AUTHOR("Tronlong");
7 U; y; W$ q) ]4 gMODULE_LICENSE("GPL");8 E/ k. Q: q2 n( E6 ? D7 S
' T# z7 Q+ t+ k3 a& _! p |
|