|
|
求大神给下面的程序做注解,请稍详细些,谢谢。0 k4 x: K# }+ C0 x$ W3 j( G$ P
#include <linux/init.h>
. [( i8 m1 \+ ~1 X#include <linux/module.h>
+ p+ O$ P- j$ G0 ~#include <linux/kernel.h>: n/ ^! U* D f* e1 V6 d) h
#include <linux/types.h>- w% |' Q/ X) \. b2 q& k* O& I
#include <linux/gpio.h>
3 F- V3 t4 g# h# ~) y, | r#include <linux/leds.h>" m5 a6 x9 P. s1 j9 r
#include <linux/platform_device.h>* A6 e+ t0 d$ ~& Y. L% a' z
/ @, J+ w: I3 t( k, J: u#include <asm/mach-types.h>
5 I. b! A" ~ i8 i7 `- A$ m#include <asm/mach/arch.h>6 y' y. N% B8 J) L
#include <mach/da8xx.h>
x* a! g7 j1 \9 t( a& j+ E- q9 a#include <mach/mux.h>4 S- G9 s3 K: }# m/ R R2 X. I
. O( {$ ^- u [ ]% y#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
" C( u% z8 {$ a$ a: V8 D) C#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)9 s4 z3 R4 |7 [; U4 G
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
! c0 T% N5 B: e* _9 t! K#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)9 {6 k7 a b# C- R5 z
+ B! H- _7 C1 Z( L0 e
/* assign the tl som board LED-GPIOs*/9 e `5 p5 W3 r9 o& |
static const short da850_evm_tl_user_led_pins[] = {
. R6 I1 h9 m, `7 T- r /* These pins are definition at <mach/mux.h> file */; X! q% [" _9 d4 @0 `( c4 k
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
# O6 C& S" Y& O+ s -1$ d& V; W, p+ a7 s
};7 P4 O; k- M+ S; Z+ b
1 i: o N5 a) c+ X1 V) B0 M$ cstatic struct gpio_led da850_evm_tl_leds[] = {: `: }5 n" A+ V$ s, A
{8 K! T, S: |1 r; g
.active_low = 0,8 C( o; n; D7 X, }+ l; i9 |
.gpio = DA850_USER_LED0,! }1 v, R* |0 y0 S, R( e: D) {
.name = "user_led0",
5 w& U8 S; i8 d6 W% Q) X .default_trigger = "default-on",6 t3 T3 g. H3 e- B; R
},
( C) u c* o. J {
' {# L- a+ f# Y! J8 U( s+ P .active_low = 0,
* I( E# A$ Q5 ]1 t% ]& i" @ .gpio = DA850_USER_LED1,
0 j4 K" Z& U) B) D. S& z .name = "user_led1",
! M4 b2 `# o8 Z: w a .default_trigger = "default-on",
( _8 u7 A' \3 Y2 N! ?, \. x },
6 g) e# c1 p. s8 }# W+ X1 x' O- v {
, Y# S4 P5 }- o3 U0 B .active_low = 0,2 S% `: k4 ~% B" q. T
.gpio = DA850_USER_LED2,- B0 } l9 q. Z) s* T7 I- L
.name = "user_led2",. l3 F' F) Z) @+ _: F9 Q( l
.default_trigger = "default-on",2 k) ^; n& a t
},1 f8 u$ q7 |( v& B+ x6 t$ D
{0 o6 A; R8 C3 N$ v
.active_low = 0,5 F8 k3 D! E+ I \9 l x9 s( o
.gpio = DA850_USER_LED3,& D* a/ {$ ~! c+ Z2 ^ x8 a4 G/ i
.name = "user_led3",( |3 B5 `( M# F; {6 e
.default_trigger = "default-on",
% O( f* w4 x% n" j+ X/ @- @& u3 m },
) K5 I; w3 |! N& `4 X- ^+ P};8 i* E+ B3 R/ C4 a
7 m+ d# @! U" }$ i' @( ^/ o7 Tstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
& |; N0 s3 d0 `6 P6 ? .leds = da850_evm_tl_leds,( X6 ~* V8 f$ Q& N1 X5 N
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),; h! k6 h5 `$ N" ~3 N* y
};
6 y! c( B% `4 N5 L+ U' D% K& s
% A, r, d! d% M- i' n) `; a, Lstatic void led_dev_release(struct device *dev)1 r V4 g5 j( I. t7 d5 Q
{
. _ I& `& C- k6 m9 ]};
( R1 r) r2 c- ?% s! l/ P+ G9 [, X. n" e
static struct platform_device da850_evm_tl_leds_device = {% `! \6 d' k0 D$ f
.name = "leds-gpio",# |; }; {, M' `7 ~4 V" J
.id = 1,# Z9 o O3 O0 w! E' i' |/ ^3 P9 d
.dev = {9 {5 y! W3 G" S; }" T
.platform_data = &da850_evm_tl_leds_pdata,0 X# F- B* A0 z
.release = led_dev_release,
% V/ `8 y6 _1 J }' ^1 [0 [+ z. ]% A' H! P$ I2 Z3 ~
};; a. c7 n' F/ g
& |2 \2 P1 s- u4 H) K7 {, b
static int __init led_platform_init(void)
" o M, n- u1 r b" C{) ~, K; D0 ]& c' q8 E
int ret;
3 v7 F' a, L5 W$ K4 X, a: e0 n#if 0! q: {* i5 T0 ?0 }
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);% Z/ ~5 e$ s# q- N2 G# Y+ k
if (ret)
1 ^9 N4 V, ^( s2 Z- P; t7 _ pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
% Y& T- P# q9 a& e ^ "%d\n", ret);
4 o- ~% ?3 R! X# y#endif
, C6 e/ R d/ F2 j$ ^ ret = platform_device_register(&da850_evm_tl_leds_device);
* g; S7 j2 y/ F! |: r: m+ I1 U9 Y if (ret): y" ~: ^# z( F
pr_warning("Could not register som GPIO expander LEDS");. F% f$ {7 a, _
else6 x3 q' }! y0 \$ p/ l
printk(KERN_INFO "LED register sucessful!\n");
3 f* z; @( ~/ c. V
; e6 l$ o- ~( b; r1 K" t return ret;
/ U9 ^7 }! o i( d6 l$ d8 x4 {}; K& g+ L$ U4 z: f
1 f! @. R5 J- A5 G5 a6 X* d; J, }static void __exit led_platform_exit(void)
% f3 S p9 g* _$ r" B5 ^{
5 c: W) F5 b* G. {& Z# I7 }" ~- _ platform_device_unregister(&da850_evm_tl_leds_device);: T6 u' {3 A, q8 M& W
r1 z/ D/ D2 @1 D7 }
printk(KERN_INFO "LED unregister!\n");
# M( B6 N0 N) m+ Z/ N}: d- w) Z8 t1 q8 X6 c- H6 e
: b9 T" q. O- pmodule_init(led_platform_init);) C" N- {1 [+ k, U7 F8 M" ^: u
module_exit(led_platform_exit);
) {! F" }, a4 a) n% v
8 I, S/ f! c& T3 | ^MODULE_DESCRIPTION("Led platform driver");6 X8 Z4 h( L4 P- e; y m
MODULE_AUTHOR("Tronlong");
1 C* `: I' R1 y; x0 M! A* P7 v0 {MODULE_LICENSE("GPL");
' \6 m: ]5 c! D" C& S
2 F, r* L0 q/ a6 @. p: F; n/ B: i |
|