|
求大神给下面的程序做注解,请稍详细些,谢谢。
6 E5 L; q; M# m; ~#include <linux/init.h>
. {, F0 d! ^7 x0 p c1 z9 a% ]3 Z' H#include <linux/module.h>+ X! f8 v, }$ N
#include <linux/kernel.h>
( p( Q+ f* F& L2 }6 c/ I9 b#include <linux/types.h>, \! |9 p5 M( y. s- {, p
#include <linux/gpio.h>5 n; |$ a% f# q0 q
#include <linux/leds.h>
' S7 a; ^2 m6 ]3 P# n4 h/ _, e& o#include <linux/platform_device.h>
+ b9 R% N m0 ]+ w7 r8 A- s6 d$ [, ^: G' p3 g* b
#include <asm/mach-types.h>( @" Z7 l) X: f' \" k1 _6 m
#include <asm/mach/arch.h>
7 m6 r* y$ b9 W6 C/ N& \#include <mach/da8xx.h>
9 l2 {/ ~/ [# b1 e7 }) L* O7 g#include <mach/mux.h>
6 ]1 S' K2 ~5 m4 ~$ A- P# V
2 X( o" _1 k8 \9 u#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)/ V% o. y& j y) a$ t# v
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
, x0 W9 K6 T( L+ ?3 l#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
8 C$ Q8 d. ]# |. X( C# O6 C2 @#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)% [- K# @+ l1 h2 H& D, h* m3 X
' W$ U4 T. n7 P# f H U
/* assign the tl som board LED-GPIOs*/ J- I/ b4 D2 G, o1 t% t1 G4 t1 v
static const short da850_evm_tl_user_led_pins[] = {* r8 t( O+ I9 j: z1 x- r n y
/* These pins are definition at <mach/mux.h> file */' c9 h% P- Z6 U: T( f4 S
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,4 v: @- c J% e3 e! j: O5 ?
-1
" x7 w- g6 F5 F" z( k8 h M};8 [! I, J4 J. y+ I
- x* q8 I( }7 Q) A2 q6 p8 Z8 T3 h* Nstatic struct gpio_led da850_evm_tl_leds[] = {* W% M/ k5 ^' V
{
4 S7 U8 C' v0 E+ ~6 A' S1 o; w+ Q .active_low = 0,( m8 W2 r) k/ ?- z, F$ l% d' L5 ]
.gpio = DA850_USER_LED0,; \4 y9 s, O7 a1 G* @
.name = "user_led0",
! x7 @/ ~1 d6 r- r' z .default_trigger = "default-on",: Y2 H& t& d: T
},
& K7 P( l4 n& ^+ |& M% a {+ r3 Q" M6 M7 H0 x4 n8 G
.active_low = 0,. N K. H; g4 s) F4 c) e% W
.gpio = DA850_USER_LED1,
0 d+ U! J$ W, ]3 |$ X& {& m .name = "user_led1",; g+ L6 Y# p# q7 R5 q
.default_trigger = "default-on",0 n% ^+ ^! N! \5 H ?/ p8 h$ A
},# {8 f9 y9 D( c0 Z$ `% U' X) P8 M
{% Q9 a+ j0 s- k
.active_low = 0,
$ R7 @4 _2 G; g' }& N .gpio = DA850_USER_LED2,
* @- u# g4 i6 A) h5 ?) d/ e, Q .name = "user_led2",
3 b u0 r* C/ u! ?3 N .default_trigger = "default-on",
% A `0 r% V4 Y* {: u# u# a },, g/ w( G; s6 z( y/ }5 p% {/ \
{* ?* Q- o; s3 e) E) z! u0 f0 r
.active_low = 0,
/ ^% Q- }+ \# [; H4 S Y3 Y* A .gpio = DA850_USER_LED3,' ~/ ~# w( F/ O3 @% g: T! h8 o
.name = "user_led3",
$ a5 D5 c* P7 j/ P3 J+ ]0 _ .default_trigger = "default-on",
2 g6 U7 {8 f0 j6 e9 X2 i$ v. | },
. H" d- [ s0 ?- p};1 Z$ d) T4 C* r4 _1 p/ s& E
" g# Q/ ^1 y/ j! wstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {7 E' I: C9 j: O Y# q
.leds = da850_evm_tl_leds,; L3 P" O6 W" }/ R! n1 T/ m x
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
" R9 S% S# e2 A# I};
: L! K) G2 L* r- B7 @9 C+ V" q: T- Y
static void led_dev_release(struct device *dev)
' \' }7 @5 [' _9 x3 h; r+ r0 w{" Q0 i' }! d. J$ V0 g
};
7 Q) X1 [' F- K1 x8 m; J
- L" `$ X% o- I% K# \& Q4 i. @1 o, sstatic struct platform_device da850_evm_tl_leds_device = {
& L; s/ y3 \3 k4 p U1 ]2 O .name = "leds-gpio",2 p8 V$ c" g3 o
.id = 1," }1 A; x4 _; Z' q
.dev = {" i2 B" E$ c. ]3 C$ o' n4 X- G" M5 W
.platform_data = &da850_evm_tl_leds_pdata,
# i& i' ?' }. r0 _ .release = led_dev_release,8 n; @! F1 _0 m& j$ y: o; e" f
}0 ^( o* L% M8 u6 Y7 r
};
3 f& {6 J3 y! A, j0 ]7 ?. D- D4 `" ~2 N6 Y3 @
static int __init led_platform_init(void)
( N1 y& V1 n; Z{% Y, Z* o2 p e! O7 g6 N6 \
int ret;3 `3 P$ e6 a" A
#if 0+ h+ n) ^0 @% ~
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
1 }) i+ ^: t G9 S2 H if (ret)* u( V o' `0 G8 A' z6 { n
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
( F6 v+ [' d( H0 f "%d\n", ret);- ~" ^8 R7 u/ Q7 S8 Y
#endif
+ s5 t& U" p, w ret = platform_device_register(&da850_evm_tl_leds_device);
& w% f# w$ r; | if (ret)4 A1 T ^7 |2 ~4 n" e: E
pr_warning("Could not register som GPIO expander LEDS");
3 B5 g4 b: H2 G' h8 @: g' q else# V3 Y8 t ?7 Z) S
printk(KERN_INFO "LED register sucessful!\n");% z% ?- D# g- b* C; M5 G
2 E- I, p9 k1 G$ L* v5 k% n return ret;
7 \2 y. D' A7 e9 a: j6 z1 \# k}
) f5 p8 G3 O [
- Z! a* e! a# E/ c5 s C( f `static void __exit led_platform_exit(void), d3 d" ^; A5 ]
{
- d+ ^/ Y4 Z, o$ i. c- ?$ T, H* V0 [ platform_device_unregister(&da850_evm_tl_leds_device);0 L6 u/ ~2 v* {1 A3 m+ ~) |* {
8 e+ \8 ` y! x2 W6 @0 Y9 }! r, d printk(KERN_INFO "LED unregister!\n");# [; |: Z) C _ m D& f
}
2 v2 p! E3 ^4 D7 r" l3 e/ K
2 i- E( F& T+ Fmodule_init(led_platform_init);
. u# S: n0 x2 @module_exit(led_platform_exit);
* q0 @) S: m& ~: t4 w" ]; j* W2 c- B, p% M9 T
MODULE_DESCRIPTION("Led platform driver");
9 M S# ?% a" G7 d' i! W% ^) UMODULE_AUTHOR("Tronlong");- A* x! _- g0 O3 M+ V: ~5 e0 w
MODULE_LICENSE("GPL"); V {" u8 K" I3 z9 q2 w1 e- e
% |7 j0 B6 h$ I
|
|