|
|
求大神给下面的程序做注解,请稍详细些,谢谢。/ j# n: M$ a: T" G* B7 X
#include <linux/init.h>% n9 [/ P" z9 t3 T1 x
#include <linux/module.h>
2 k( C, k5 F, {7 Z& `% t' {#include <linux/kernel.h>, `- s5 W" k$ T3 _ `
#include <linux/types.h>
! q7 T2 f! _! q# z# h#include <linux/gpio.h>
. B( Z, H! j5 I#include <linux/leds.h>, V9 i: j% H% n- j. N* W! E8 {
#include <linux/platform_device.h>
3 I# n& _; k2 s' D9 u S' B. C" ~) y
#include <asm/mach-types.h>% ~9 q! ^9 ?- h1 B4 d- \
#include <asm/mach/arch.h>
9 ^+ h" \9 _* J#include <mach/da8xx.h>1 h6 ^& w1 @! f3 D
#include <mach/mux.h>
& R( [* m4 w# \
: U, `( ^8 j5 l5 \! ]0 Z0 _! }1 o#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
/ ~9 v- t. i' ^% C#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
3 W; C: P3 i7 m1 v/ @#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
3 C8 x. v) ]$ h" {" O# G" X+ Y3 z+ P: h#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)8 z) w+ X* \ C( l0 {0 Q
5 F: `8 M2 {5 u5 |5 I
/* assign the tl som board LED-GPIOs*/- Q, X/ T# q$ W) l' B4 R6 R8 O
static const short da850_evm_tl_user_led_pins[] = {
8 d5 L A& `+ v$ m+ ?; [7 _+ i* u) l /* These pins are definition at <mach/mux.h> file */0 k2 u2 T; z7 l' W1 i9 Z' g
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
" `& f2 s C' G# @$ h m -1% X, L0 _+ _- h- U' P$ r3 b6 r
};
. N6 T' B* D- C) U2 P' j7 l: ^+ [4 A- T* {" a! ?
static struct gpio_led da850_evm_tl_leds[] = {
+ q, Q C2 @. e8 x( r {
5 m# c0 ?% m9 j .active_low = 0,
) K% S- {7 G: \' Y$ s .gpio = DA850_USER_LED0,
2 u5 ^, j7 V+ L- Y .name = "user_led0",
& p: D; {* _. n6 P/ ?2 O .default_trigger = "default-on",, m7 k. c5 o1 T% o! p; ~- V+ A
},8 i; w9 M0 i% Q, a- `
{ Z" C7 L" L: K: e# k1 q
.active_low = 0,9 W' K" Z5 Y" z- H# H6 K
.gpio = DA850_USER_LED1,# L2 d$ E( F) S1 _
.name = "user_led1",& [' d: P! |! D" k8 w% ~' v, ]
.default_trigger = "default-on",. x0 u% i) W0 e
},6 W) Z+ a; ^( m; O5 J4 \
{
: A2 I3 s4 a' J! x+ p .active_low = 0,9 e' |. _; h! m& Y8 ]6 c" z
.gpio = DA850_USER_LED2,$ c5 c* ?: J$ \# I' J
.name = "user_led2",5 B2 x" [3 A1 O7 s
.default_trigger = "default-on",
) w C/ C! a; t* X9 o# F j: K },3 B) O& D: r3 H* K( R% X# P+ _
{5 n# Y; e7 s* ?. \) U
.active_low = 0,
( Y; ]: `- f) N9 C! J8 Q .gpio = DA850_USER_LED3,
9 v% U" ~4 q7 a+ s+ d: \, o .name = "user_led3",
- h5 t" h9 d/ D7 p3 a5 | .default_trigger = "default-on",
6 ?4 x& a4 C" h( G6 p( J },9 G' U- P" }9 N; Z; i. O4 k4 |! J
};
# }7 b/ l. U8 F4 |6 V
7 ~9 b' o0 }" R1 U$ estatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {- f* H( z4 u+ e" Z# y9 u* e
.leds = da850_evm_tl_leds,
- \. ~2 k, ?* ~: g+ }: n) P .num_leds = ARRAY_SIZE(da850_evm_tl_leds),7 O$ p) `, q2 a9 k6 u. i
};- L3 t( Q$ b% j. A @; \! R
r# Q+ T6 A/ b) [" y% K9 c
static void led_dev_release(struct device *dev)
+ J( r! J" _: X' G0 p# u{: ?1 e" R- a' K- Y# J. Z
};; E0 e: _: Y, a* K! ]5 ~
2 g; u: D3 f3 F
static struct platform_device da850_evm_tl_leds_device = {* u' I! A! k M9 G: ^8 {' ]
.name = "leds-gpio",1 i! c- o% K4 s$ u% \& m; r
.id = 1,
- f/ J6 W) T8 r3 l4 z# ?! E" R* F) { .dev = { h( H0 _5 p6 k b4 H- |" J6 {3 l
.platform_data = &da850_evm_tl_leds_pdata," Z! c5 A: \+ |
.release = led_dev_release,1 B7 x7 v P) L: l' k. q; P
}) V" [2 h! u8 l! ?6 r/ M2 i
};
- H. ^" e2 Q' v. N. w* X0 ]2 p3 M
. ]1 L M0 Z7 A% T: R# E: j7 ustatic int __init led_platform_init(void)3 b, |3 X( K$ n
{# ~0 M/ a* G9 s3 r% K5 ^4 [
int ret;
* T+ C I$ C( m( Y- h$ h# X#if 00 Z' O& d) m9 o: s
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);: a/ @$ O W* g s1 O) h$ d! |
if (ret)
/ Q( O& R! |: B; ^ pr_warning("da850_evm_tl_leds_init : User LED mux failed :"4 c p' U4 o/ I% z
"%d\n", ret);
7 {% X1 o& z+ r8 C. N#endif+ K0 f9 e$ p6 j# m5 Y; E: i, K& z2 R
ret = platform_device_register(&da850_evm_tl_leds_device);5 U! U, h2 H. |/ c; y
if (ret)
& p' U$ S0 g# ^4 Z4 b) e9 j pr_warning("Could not register som GPIO expander LEDS");
5 f. U+ G' k; V3 f& i+ l) k0 z( U) o else5 x& x$ E6 _; M! Z# `
printk(KERN_INFO "LED register sucessful!\n");
1 d/ {; c3 z# h( j% D G3 B5 v! o5 z$ [
return ret;
r4 T: T! B9 `6 G: J3 O, L6 v% m, y' g' c}
8 J+ Y8 m6 |- V* _9 G, {& O1 U5 q! ~& e/ h! b6 G4 e
static void __exit led_platform_exit(void)
; V+ h6 |" i( r4 ^. y+ U+ w L{5 i% p) Y6 R! O5 f1 a' R
platform_device_unregister(&da850_evm_tl_leds_device);
7 ?; [* q/ f: r0 K0 I, `
}# d# h3 L9 {% T% t. v4 e. b; _ printk(KERN_INFO "LED unregister!\n");
1 ~+ E) r+ M. D X% v% n, p7 B3 c: s}8 b6 f) @2 @* _7 Z3 `+ e/ a& e* o& \' A
, B, C1 M3 |8 Rmodule_init(led_platform_init);) `& v% Q9 p, M
module_exit(led_platform_exit);
% k0 F- | U4 n, S/ T U/ L/ F4 `& s- Z1 W+ l: \' E! J6 v
MODULE_DESCRIPTION("Led platform driver");
# I' V) y8 O5 ^' Z( c5 m) p1 gMODULE_AUTHOR("Tronlong");
* \% P! S. I6 g/ ~3 R8 {- rMODULE_LICENSE("GPL"); k) u q" @* j6 n" h
" Z M3 f) N/ K* q8 \/ k. F
|
|