|
|
求大神给下面的程序做注解,请稍详细些,谢谢。3 w7 k9 q* V; `( g9 A, ]
#include <linux/init.h>
& M+ H" x& h5 c" U1 } q#include <linux/module.h>/ E" E. n5 F& b, c4 Z% w, a
#include <linux/kernel.h>
) ]" z/ \2 E6 m4 |' y9 t" p#include <linux/types.h>
) \7 r. j+ ?0 O- S#include <linux/gpio.h>$ G+ t6 r9 i2 @
#include <linux/leds.h>5 b- S- D |, l/ Y% d# Z3 _
#include <linux/platform_device.h># T& i+ S- I3 V& F# k! x2 [
3 B. d' @7 t1 u; f
#include <asm/mach-types.h>
e4 c- H0 l* d* a/ F& p i#include <asm/mach/arch.h>
0 W" Z2 U* s7 {. o7 P#include <mach/da8xx.h>
, Y T7 q" s- D/ C#include <mach/mux.h>$ g& p9 k* w o9 q. v, q
1 V( d4 \; z0 ~: O8 J4 K$ S#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
9 _9 j! B# W9 K9 K4 Y7 k#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
+ |/ ?; I, G9 R#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
+ j6 W2 A. z# }9 {6 s1 ~9 o#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)) Q6 k7 O h/ f; ]; p
- Q8 e8 n' i1 K/* assign the tl som board LED-GPIOs*/- n D5 | S/ |% x# c+ p; Y* G
static const short da850_evm_tl_user_led_pins[] = {
; r- d' F; F9 s, Z% m/ d; F /* These pins are definition at <mach/mux.h> file */
# }; ?- s" c' n+ x/ D DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,, N/ f! o. i6 j6 p6 ^/ j
-1) R2 B5 ~" k( k8 x d0 U3 }4 S
};7 h- Q& M, ~ f% C
1 f, G; O3 J+ ^% w! ?, x
static struct gpio_led da850_evm_tl_leds[] = {
% O$ h7 A( c, Q; i4 T/ ] {) R/ h; B5 P; w, `+ @* m6 _5 P
.active_low = 0,
$ O+ E5 k) H( N .gpio = DA850_USER_LED0,% S8 k: o4 b4 K* u' {% U' Q3 ]2 d
.name = "user_led0",
3 F- W4 b8 \2 V7 B .default_trigger = "default-on",
. I" L4 e8 h! P; Y },
; I t2 x$ ~/ K5 ]8 @) ]9 f7 ` {
6 A( [5 X1 H S# v6 Z; o% I3 F u .active_low = 0,
3 C. j" a# }# X& }6 c5 M3 B .gpio = DA850_USER_LED1,
& w) A. B2 r, s$ ] l+ B) Q* C .name = "user_led1",
3 A9 q# x8 f% N1 T5 W3 n .default_trigger = "default-on",' V3 T4 S2 @, I+ K6 x" v
},# o7 s9 `: u2 N2 G3 n* t9 b
{3 _$ Y+ ` @' o; p) o
.active_low = 0,
. q; G/ n' Y6 a .gpio = DA850_USER_LED2,* [' L2 `* L) N! F) B! w/ i4 \) X8 r
.name = "user_led2",) b" U- g4 ?5 i: j6 K* ~
.default_trigger = "default-on"," ]" Y3 U2 D5 X1 n
},5 W- {7 i4 K. L4 w
{% P/ R6 D( ]+ u5 f2 e
.active_low = 0,/ N9 a5 ^. \# U" }; w6 H: f( J4 v
.gpio = DA850_USER_LED3,1 ~7 m' Z( p0 a# z
.name = "user_led3",
' u! R, X: i# O' F .default_trigger = "default-on",
3 ~9 ~1 t" ^% |2 o },! m& w1 |& m% f$ ] |
};" I0 u$ W" ?5 P& }
% d' l5 y% f8 q! J5 Sstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
& e$ X5 X$ }' ]3 ~/ o9 }- s% K+ B .leds = da850_evm_tl_leds,
1 ~% H8 b6 l. S .num_leds = ARRAY_SIZE(da850_evm_tl_leds),- Q* R* z! W! n) x' J+ U$ _ {; w0 p
};
2 z2 U7 G' i1 ~8 \) t8 ]6 M+ {5 v& U8 d2 w! |) d! L. W
static void led_dev_release(struct device *dev)
! `- r& _1 W) _( n{
a3 Z s4 l* l" K- Y! w};, c; x) F7 u. C- I; D" f
& F' |. Q. O' G
static struct platform_device da850_evm_tl_leds_device = {
" T0 o( ?7 v( N! S% V .name = "leds-gpio",8 R+ c, h7 Z0 ?$ P! ^6 X2 L
.id = 1,
& Q3 A: k! p# n: F+ H, i .dev = {+ A" t d9 U! ~4 T* g3 ~) q0 ~
.platform_data = &da850_evm_tl_leds_pdata,
4 w7 i: K2 w: h .release = led_dev_release,! O# I1 ~% V- o2 M2 M# Z
}7 u7 R4 Z" G* V6 q- k
};1 m9 |* v3 x# \0 I+ X' a# T8 t
) k& t% V A# b6 b: p
static int __init led_platform_init(void)4 {" ] \$ Y+ ]
{/ D& v# u. h' x ]( a
int ret;0 P8 ]# X0 x+ _. X* q. ]9 s
#if 0
; D4 A z* ~! O% c$ T+ A t% g2 W" l ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
P" M) ]) i7 l* j7 ]7 v if (ret)
- g1 a q. c; T$ v- j: {, X5 O, _4 w pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
9 x0 D4 w. [6 F2 S2 U "%d\n", ret);
) a' R2 D* ?- G1 V#endif- v5 i; h8 ]5 b& j* p1 @- X
ret = platform_device_register(&da850_evm_tl_leds_device);
0 s* [. s/ W* z3 L' Y: N# w V% M$ R if (ret)! [- ?# N; s6 Z3 y, J1 K _6 j
pr_warning("Could not register som GPIO expander LEDS");' A5 V6 F9 }8 L) ` @
else
( O" ?/ J; B# h- J printk(KERN_INFO "LED register sucessful!\n");
& c, ^1 b( \# R. N
3 I$ _$ V2 f! Q4 {/ i2 A7 ? return ret;
2 j3 F% y/ f1 O* j}
5 \+ U4 X7 U/ J% ?6 s
) n& w+ L" U2 L8 j5 |4 lstatic void __exit led_platform_exit(void)
4 K- |2 ?$ U5 [# d7 D; w, l) @{
1 |; n6 l% Z" f) N( e$ S2 w platform_device_unregister(&da850_evm_tl_leds_device);0 {, j( I% w6 j# s0 z. J1 G2 n" m
- X! e ~' V0 Y+ T printk(KERN_INFO "LED unregister!\n");6 E, v+ Q' F/ Z6 O% k
}2 W: W4 m* y/ L1 a
$ M* \ |1 h! k- Z* d) umodule_init(led_platform_init);2 r6 K9 J7 b3 d0 [, X0 h* A' o/ K) t) e
module_exit(led_platform_exit);! D$ T0 |4 p+ r- |6 R9 X- V! F
6 p) X; N# J3 |) q& }
MODULE_DESCRIPTION("Led platform driver");& L: ]- y0 n* s. ?2 T! Z/ _: j" T
MODULE_AUTHOR("Tronlong");
0 {- B, j* J' b0 O, ?, H* a9 AMODULE_LICENSE("GPL");) l& }" O" \- o$ Z% b
5 A* x7 q7 N6 z9 t, g9 z& l3 v6 m
|
|