|
|
求大神给下面的程序做注解,请稍详细些,谢谢。7 E% u6 O6 W- @" X: W: c6 B) \
#include <linux/init.h> p% E% i7 T( K$ O8 G/ I
#include <linux/module.h>
, D6 u5 \# e9 a- `. Y#include <linux/kernel.h>- V3 w: d A/ H7 ]
#include <linux/types.h>/ |* ^6 w% k% H: I
#include <linux/gpio.h>8 Q. ~. [ V6 o4 U4 Z# a
#include <linux/leds.h>, E+ l/ C$ N+ y5 k8 L) [
#include <linux/platform_device.h>9 O- Y) a9 g* Q3 b" C
* S# Q: }3 r) a# O$ n#include <asm/mach-types.h>
' R9 J! T8 O8 b5 q& U#include <asm/mach/arch.h>
* q7 t o/ Q" J0 ^3 s#include <mach/da8xx.h> K2 _1 H; o/ w7 j x
#include <mach/mux.h>
; B' [) v5 ~# Y1 Z* E
$ v7 j1 c I6 J* h$ g#define DA850_USER_LED0 GPIO_TO_PIN(0, 0), l8 b/ f& Y: a% {1 @
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
9 L) @' I" c3 s: d! ^* _7 o$ \#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
% L8 F) a. n* O#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)- s9 ~/ Q6 U% Q) g. m. \7 W
; j; `3 K5 R5 t3 b9 r3 f+ s
/* assign the tl som board LED-GPIOs*/8 k% |# p' F9 V+ _+ X
static const short da850_evm_tl_user_led_pins[] = {
; f9 I# N5 d0 { /* These pins are definition at <mach/mux.h> file */
; ~) i4 Y" z4 M# X4 U/ L" y, Q DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
9 c0 C0 A$ I- i# E7 T: q -1( {$ T0 _" a3 L) z8 q
};. i4 I, W) \; F
: [! U) ^8 E$ x" f; b
static struct gpio_led da850_evm_tl_leds[] = {% ~" Q _6 Z7 p# X* y7 B- X
{
* |- Q: ^$ v0 h/ @( L0 I .active_low = 0,5 P! u' ]* j9 s" p1 x
.gpio = DA850_USER_LED0,3 e3 |* U# `+ S' {
.name = "user_led0",
7 X: I! r2 C1 e8 {7 N9 A$ ] .default_trigger = "default-on",7 L" o7 i. V6 `* ?) q! p
},; z. a; O4 D u% U# ]
{
0 ?' I U* q2 t9 d .active_low = 0,4 E+ @' N( m7 O* q2 { e z
.gpio = DA850_USER_LED1,
0 c+ ^ A6 W) p! T4 O9 H- ` .name = "user_led1",/ e& Q0 a5 [( ?1 _, g, ~
.default_trigger = "default-on",+ w5 z( K- U E* Y U
}, l2 p$ h$ f. y% X8 y
{# E: ~, O$ z+ E% `+ W+ h7 L
.active_low = 0,
4 g) j. S! }9 B4 J$ {8 D f d# u0 p .gpio = DA850_USER_LED2,
$ _8 H. N% r9 A. A! K& T .name = "user_led2",. e2 e2 }, r- ^, K
.default_trigger = "default-on",2 Q# g7 q4 i% t" w i
},3 G5 V$ Z: p- c2 x: l9 e- N+ r
{
* M9 L. |' B r! S .active_low = 0,
2 K, q0 x8 O1 @7 v .gpio = DA850_USER_LED3,; P$ W: I; K _; t/ O- \" b
.name = "user_led3",
# ^+ J# D! S- L- r/ _ .default_trigger = "default-on",
3 C/ S( e5 S8 b0 P$ ?8 M4 w, E },
% _% u5 J' F0 i K2 K};% \+ u9 G' c3 }! \7 Z& }/ l& V
# e$ d" l D7 h3 U! G7 x# W
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {' h5 ?9 v8 h# D8 o; k, ]; c; g8 W
.leds = da850_evm_tl_leds,
/ ~* a/ `( R3 c7 U3 u" k .num_leds = ARRAY_SIZE(da850_evm_tl_leds),, Z8 q9 q e& L
};
/ K; K3 |1 }/ F$ B) h! o7 l: u" I% j( [7 D r9 Q- G
static void led_dev_release(struct device *dev)- ?4 l G' k8 l0 e: w
{( I- ?" D4 ?" n- S0 o. z" Z
};' X2 D2 j6 f$ d
3 U; y, K0 H( v7 o4 Kstatic struct platform_device da850_evm_tl_leds_device = {
! k$ U- X4 j' x. U .name = "leds-gpio",
N j( j F3 H2 c7 U .id = 1,
; R% V/ n% K! n" \2 h, M( U& C/ v .dev = { F7 Z: h! j2 @0 t: G/ l
.platform_data = &da850_evm_tl_leds_pdata,3 X l& D& h5 g/ q! G2 \
.release = led_dev_release,: W& R( w- o6 m5 _" l
}1 A7 q9 z$ x0 ?* b( ?8 T/ L/ i
};
: }/ T6 Z% f6 m( ^6 W7 _. |. f& J/ B4 ^( S/ y1 y8 `
static int __init led_platform_init(void)
( W) P5 i) q! w: r7 w/ [{
* D; f) ?. {- m int ret;" T( d$ \: `8 g8 G
#if 07 v& U6 t. x. q, v- U
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
W) e& l/ W1 P! P: ] if (ret)& N( U$ h* X+ i- u. p
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"7 p4 I2 s# c. w$ N
"%d\n", ret);
2 V' A' M2 b# R#endif
$ K' p2 V/ g: `8 a ret = platform_device_register(&da850_evm_tl_leds_device);
5 V# ^" a4 M5 O$ j0 I7 h if (ret)" o* U- m1 w+ u: X7 l! |2 s
pr_warning("Could not register som GPIO expander LEDS");
9 g2 K6 s0 R2 g+ J else
( [3 l7 N9 I6 S$ S3 h- r printk(KERN_INFO "LED register sucessful!\n");
& j. F/ h$ f& P* w" l3 w/ M4 a; p' ]2 a& V3 H1 a4 O% e( O* y
return ret;, z$ Z0 F. X8 v( K d. F6 L
}' V( d0 F* s9 M9 [
$ ]1 W z, t# e& f- r
static void __exit led_platform_exit(void)6 l0 @! n9 S( E4 }& L3 w X
{
E' d& C9 n# y- \$ F! C o( ] platform_device_unregister(&da850_evm_tl_leds_device);
7 O* y5 D- g$ q* i: Z' t0 e" [
. y7 A& G, [ V6 q6 { y printk(KERN_INFO "LED unregister!\n");: w0 u& B" |+ A' C3 V( d# k& d
}
: |7 U; c8 n$ G b4 U
. H4 u4 Y5 L' p( X( cmodule_init(led_platform_init);
. u* q$ \* p, I& D7 l! N' vmodule_exit(led_platform_exit);
1 q, |; E$ }* I& j* \. Z% s% H) ?, D+ O% e5 o
MODULE_DESCRIPTION("Led platform driver");. v; _5 c5 ?; U3 d* t( c
MODULE_AUTHOR("Tronlong");
( I, p& l: b- T ]6 A( |/ x6 U1 G0 dMODULE_LICENSE("GPL");* L) I. v0 H, M5 b
. m* Y* J" d2 n% u0 N: r, [ |
|