|
|
求大神给下面的程序做注解,请稍详细些,谢谢。1 j7 }4 x, d+ T9 w. X) B" f
#include <linux/init.h>7 b! ]: G4 }4 J; c6 \3 Q1 k' z
#include <linux/module.h>/ s6 L7 r2 a, Z/ Q9 ?0 X1 L7 V
#include <linux/kernel.h>$ n, n; h) S, W
#include <linux/types.h>2 q6 {' v! v9 S# y% |$ F0 B' T
#include <linux/gpio.h>
" m) j% G$ ]( w+ G- z9 K8 H2 t- _; y#include <linux/leds.h>8 S# c; P- O, K! X
#include <linux/platform_device.h>
' x, a: P) y, T1 E! ^6 v T* B( Y( m
2 u' i# @! d% m6 X3 _6 p S, t#include <asm/mach-types.h>( w/ {- z& e" ?' f
#include <asm/mach/arch.h>3 X$ m: Q; B: L( a
#include <mach/da8xx.h>
O9 ?' n8 }3 r6 G" T#include <mach/mux.h>* u H! i- v8 Y; W5 E. S
5 v3 {: N0 g4 A4 P#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
9 p; @7 T8 \- C6 P#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
7 i& b- d: q( |+ Q* X#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)1 W: ^. ]! W% d
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)3 n' q6 g5 }& h" w
' X3 O8 T5 \9 r K) O
/* assign the tl som board LED-GPIOs*/1 @4 }) F0 O2 b4 |( q; P5 l
static const short da850_evm_tl_user_led_pins[] = {5 Z! D" ]+ \) S6 b
/* These pins are definition at <mach/mux.h> file */
) k/ ~, B( @' _; y4 v9 H DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,% x ^2 ?& Q% {- N# i* L
-1' j" W0 k" f0 E7 {! f2 y1 Y
};9 r4 \5 E: H- K; U- b* |
. B# I' ]7 e* c: U( e. T2 n3 X
static struct gpio_led da850_evm_tl_leds[] = {2 z0 }7 m9 D9 U w! p4 z0 s2 m. x
{
5 D+ u! t! B2 Y) v2 _5 Y' e .active_low = 0,2 [1 `$ S& Q6 M2 d' d6 {" g4 D" b
.gpio = DA850_USER_LED0,
/ r+ k m: z, q- v. C3 d .name = "user_led0",
4 @! \/ u) w* w1 P' y .default_trigger = "default-on",
0 K9 M- [+ H7 q0 s. ]! J4 K },- c* |# a$ z4 v* D& A/ J
{+ J4 b) P- G. k, b, ?7 n2 t) _7 C
.active_low = 0,5 a: `- a# ~; G$ B5 E
.gpio = DA850_USER_LED1,) ~& e# y+ [" G- k4 {
.name = "user_led1",
9 [6 _& z9 Z3 A .default_trigger = "default-on",7 t0 }6 e" U- ^
},
, A& ~6 K- T$ A/ w7 S* _ {
8 n0 T2 x% E0 F .active_low = 0,6 l* b# M% J& S9 }: f! Y
.gpio = DA850_USER_LED2,
/ r# c! `- l. A; y .name = "user_led2",
1 r5 l5 h; X' w2 h7 g .default_trigger = "default-on",
. M: ~; r& \, {: @ }, F, E, D0 r3 x
{# u: A6 g1 z. [) h. b
.active_low = 0,& j: r1 \% e$ j0 ?
.gpio = DA850_USER_LED3,
: @7 c# i2 x6 ^+ U .name = "user_led3",
& H# I& M( d- S* {, _7 m$ ` .default_trigger = "default-on",& } n9 W3 k; |# C5 E2 p. V
},# R, U" d9 Y% U0 d2 R0 F
};1 {& x2 R" N# [; r
5 }5 b# T6 x% `# R7 M
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
* x1 [6 F5 {0 r5 B' }' I6 X$ q .leds = da850_evm_tl_leds,5 X6 y' K' V8 h+ z9 e2 ^
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
+ f( b4 Q+ h: C ~! N};
9 k# G- h' Z) @$ |" n; v( i8 r) V9 c6 A9 r* C4 Z6 |- }# d& K# B
static void led_dev_release(struct device *dev)
; q% F" w8 ~4 _6 H2 g8 K{* v3 j! Z5 \) Z1 w
};
) v P5 }6 H5 @! L6 s7 e* h3 D% q; l, J# |5 { j* r
static struct platform_device da850_evm_tl_leds_device = {) i2 E2 d: z% d- O/ }
.name = "leds-gpio",- ?* R$ V$ v3 q2 k$ q$ u# `
.id = 1,! [: c. F/ X0 I+ f
.dev = {
3 V- L a1 q% S& ]: C .platform_data = &da850_evm_tl_leds_pdata,0 {, H: }/ g1 K4 I: S# |
.release = led_dev_release,
& X- A& }7 G1 D1 [ }! z7 ?$ n7 n- \+ g6 U }
};
M6 e) I7 \ w2 B& p, j
3 t4 F# \9 ^ E/ s( y; O) G" bstatic int __init led_platform_init(void)
) Z; {3 n$ G1 L) J{
# F7 ^& Q6 u7 N! Z int ret;- \0 { U3 y7 `- S/ Y
#if 0
0 |! |4 l: Y+ f$ ^8 ?, J ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
3 x' }: a5 z: }% u7 ` if (ret)
# m7 c- ?2 P/ @7 B. c0 g0 E pr_warning("da850_evm_tl_leds_init : User LED mux failed :"3 Z( _7 r1 m. A. e' s+ b+ d4 |
"%d\n", ret);
2 z w/ g0 w5 T* h) L9 [9 ?#endif$ y$ o7 U3 ^6 v8 @4 y4 @) A$ x
ret = platform_device_register(&da850_evm_tl_leds_device);
6 T1 P- a8 R* _! q+ C4 H if (ret)
4 E+ ~$ I3 u+ p* s2 A pr_warning("Could not register som GPIO expander LEDS");
( y. z4 k+ k1 x0 T: _. Y0 I else
% G5 T# X$ w; j' @$ |8 ~ printk(KERN_INFO "LED register sucessful!\n");
) [. ?/ `8 {- r, U+ c* X" U) H, p5 V* w& E* B. j/ ^) t* @
return ret;
! i7 S5 [. Y1 o6 \}
* Z4 O" x$ t9 u' A; r, |. y, W
/ \' j, S" o, S- fstatic void __exit led_platform_exit(void)
6 U: R8 p) k L; u, M{
- a$ u, L4 Z5 q3 _" d# f1 s platform_device_unregister(&da850_evm_tl_leds_device);5 ~, P, O2 d" ?! `. B8 p- _3 E
9 s2 g2 g' d0 }+ z) d! H7 P printk(KERN_INFO "LED unregister!\n");4 @5 i& k7 A0 `
}5 X2 r6 }0 I+ x
* d2 y3 U; y' k0 J3 Q2 Ymodule_init(led_platform_init);6 e1 r, D$ X/ z3 S; B6 q% M
module_exit(led_platform_exit);
1 J# h0 ^- w; y# ~) I" x2 ?( {& D* j; u& t- r& S. }. U
MODULE_DESCRIPTION("Led platform driver");
0 _* E8 C0 G% u a k3 {MODULE_AUTHOR("Tronlong");$ U* _- Z# D: r
MODULE_LICENSE("GPL");1 s4 x) b+ j4 H2 x9 V# f9 }& |! w
; e& W& ^( q3 \, ]
|
|