|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
$ S+ F# o( _* e3 b D#include <linux/init.h>
- j5 Y+ G+ w! N* \1 J' |) t- d#include <linux/module.h>
0 e0 f7 c- S, l#include <linux/kernel.h>
, l% J' q- d+ Y# t% o#include <linux/types.h>4 ]1 ~( V$ ^ u; I
#include <linux/gpio.h>
1 Q3 z4 M' r. Y: {- V% J#include <linux/leds.h>" B$ g6 `: @) B: u
#include <linux/platform_device.h>/ s3 f- k) t$ l3 u
5 N6 ^+ ]7 n8 H( z
#include <asm/mach-types.h>' Z# Q8 I2 {, ?8 A& E+ _
#include <asm/mach/arch.h>
: q7 k4 e0 C% A' o, s$ [6 n& K, f5 C#include <mach/da8xx.h>
2 q$ [8 a& `* [#include <mach/mux.h>+ x5 c& j6 R" T; D" s! }
7 V: t0 Y8 m5 I1 @* S p$ x2 a#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
# ~% c0 L9 E2 {- o* {/ a) a* [% Q( }1 [#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
. R# a. j( w+ b: w( m* k#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
/ T% A% u' M7 @/ A- p. v+ Z7 s/ U# B#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
/ T( [3 }( F' y6 k; x* ?
1 c* J( o" x; R, b. @6 H7 R/* assign the tl som board LED-GPIOs*/
: ~) t: B, _( Fstatic const short da850_evm_tl_user_led_pins[] = {
5 q" m0 K, N6 r: M /* These pins are definition at <mach/mux.h> file */
8 [) [% M, b) F) L# o DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,& G* d$ u2 S: G' N
-1
4 W& w4 s( e5 ]8 f2 e+ n' a/ D7 N};
# k' m) j$ ]( N% N0 m6 A4 ?
) [% z- ^2 s3 q7 ?" zstatic struct gpio_led da850_evm_tl_leds[] = { J4 l: c9 D& L+ i7 [* _
{$ G# x3 k5 W- G8 U0 r1 m Q: U2 H
.active_low = 0,
! k+ [4 ~9 i( g: O; K .gpio = DA850_USER_LED0,& _! \0 g3 C5 C. ~1 B9 b8 v2 k4 C% T
.name = "user_led0",8 L# a& Z# [9 G0 u7 E6 Q' q
.default_trigger = "default-on",8 M6 |- O8 k: |. N5 @% S2 M
},
6 ?4 V: z( t5 d! \9 a8 c% _ {( N0 `+ F. l# l8 D8 C$ [. b
.active_low = 0,
; ?9 L4 S1 q/ q# K+ n .gpio = DA850_USER_LED1,
8 g$ j/ A: W3 Q6 F. U .name = "user_led1",
9 w A* _3 ?, P3 i: M& g .default_trigger = "default-on",
" f" M# J/ k% N3 u },
9 L& P3 V% B& J0 _' e0 P {
$ {' ~% G7 d% k7 u% ` .active_low = 0,
+ z' S( ~1 m+ f .gpio = DA850_USER_LED2,# n( c4 }) l( {8 N
.name = "user_led2",
3 h1 W, w: e; d. u. ]! \1 C v .default_trigger = "default-on",
9 a+ z% {, `1 r1 f4 w },
# U; T5 E1 g2 b# o7 c {9 d4 h8 r- y9 X3 m" Z
.active_low = 0,
; K. {8 P L* W8 I9 G A( P .gpio = DA850_USER_LED3,2 U0 D$ L' w# d/ P: G$ Q
.name = "user_led3",
& \( X% }& E4 b! Q X& a8 i .default_trigger = "default-on",) W, v0 w3 y" w6 r; g+ I1 w4 O
},
* E( a0 u2 ~' D6 Y" e0 }- Z};- B% J0 h I k' A3 J( F7 J0 Y1 c
2 o6 Q( x/ }5 Z6 Ostatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
. [1 e3 p/ `- @ .leds = da850_evm_tl_leds,4 o4 Q& N, \& n7 N9 `# O% I
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
' d D+ r, U; f/ ~};: R% I) @ W M( O! s- D5 j
( E% q% G$ f) H+ Y. g& D5 p
static void led_dev_release(struct device *dev)4 Q6 C, d7 r, V& ^2 O: C( n
{
( f( b! N( [2 y% y; c0 a};: l. o/ F7 \2 z7 W; ]! s# v$ h# V$ c
I+ f8 q" P. l! ^5 U) j+ }. c9 W* dstatic struct platform_device da850_evm_tl_leds_device = {) o4 z3 {9 ?8 S% \
.name = "leds-gpio",
T3 y- B% u# [/ M# j! N& ^ .id = 1,% V3 X* N9 u6 k) A7 C) f
.dev = {5 a$ r& ]$ J2 v& {6 a% A" G
.platform_data = &da850_evm_tl_leds_pdata,
6 H. |: w5 P4 ]( i1 c1 r .release = led_dev_release,9 k8 i' x4 O1 k0 ~ j/ ~
}
" Y; @' ~ b: J+ n* X# a};
p6 U, g* e' N+ N
% H5 L/ ]( a7 }, {" Lstatic int __init led_platform_init(void)8 D0 ?+ j, u7 C; ]
{
, A# C) B3 Z) D0 N9 ?, M5 y int ret;
4 J- O) |: e5 H. h#if 0* D" Q& U; g+ |# T
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);) L* h& T' L& ]( _
if (ret)
, Z/ ?4 p$ S9 V8 B% Y pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
0 o. t1 l. D. h "%d\n", ret);
% n! C9 @0 j: f#endif( ] v d* S8 u2 u% B* c
ret = platform_device_register(&da850_evm_tl_leds_device);
, u* c3 U' k% K b if (ret)' F# r! W) W b, W
pr_warning("Could not register som GPIO expander LEDS");
g% m+ b; n# F else8 H/ {" J8 b/ I8 V+ U8 G9 Y
printk(KERN_INFO "LED register sucessful!\n");
1 }! k' ^& O1 v
5 @8 ~$ x `- \ C. _9 w1 F0 F return ret;. o6 r* ^2 K6 R) ~/ o' a9 l+ I0 j
}. _* V9 M2 I9 n5 V8 t0 w
+ e0 _1 [8 M- }0 ` u
static void __exit led_platform_exit(void)- n3 o6 i. f+ z" R" \) J1 s3 F
{5 Y7 H% ?1 H9 m; {" u ?
platform_device_unregister(&da850_evm_tl_leds_device);0 s9 s7 _! B+ Y* `* U6 O: m
2 m6 B& R3 ?6 V2 w2 x1 C1 @4 F
printk(KERN_INFO "LED unregister!\n");
" i' b. }1 K2 m- B}
$ I( y8 ]8 h+ D, l$ ]3 A, C& t/ }8 C. u$ |4 M/ |
module_init(led_platform_init);
0 |: s3 ^3 O, i) {/ emodule_exit(led_platform_exit);
0 C' H0 ]. N, L4 \2 {$ O& B5 R3 _: a& u
MODULE_DESCRIPTION("Led platform driver");, u+ O0 _' F2 G, _8 v: K
MODULE_AUTHOR("Tronlong");% q8 R) a: y4 p
MODULE_LICENSE("GPL");- h! V- O4 i% E
W+ c, s; K; X. _$ O; N |
|