|
|
求大神给下面的程序做注解,请稍详细些,谢谢。6 E. d0 D% u/ C0 E0 w) m
#include <linux/init.h>6 h9 l' l; W* \* B1 V
#include <linux/module.h>+ P& s8 F2 |4 l) m
#include <linux/kernel.h>
# Q$ d( O* W( z#include <linux/types.h>
& ]) x& @# l/ G: a0 U#include <linux/gpio.h>
; H& a) F$ S7 K0 w# u5 |#include <linux/leds.h>9 g, G8 j( J; ?; e
#include <linux/platform_device.h>
, q( \, ]% `) v; Y
, V2 K6 n) H$ p7 q2 E#include <asm/mach-types.h>
) ?; w9 P# R3 s#include <asm/mach/arch.h>
* u; g' x" r3 j$ A: G0 R/ a k9 ^" `#include <mach/da8xx.h>' V5 [9 L0 w. U: u b( ]8 [0 Y( f
#include <mach/mux.h>
! ^: b1 S+ P. n4 w, m% l4 v: k3 F1 U2 w8 _& @
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
" f2 S, D' M. E g- N#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)% f2 W* n4 q& l7 `* l
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
7 k8 a# i' F# g5 p#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)# e& O# @; T/ T) P
5 u1 h9 Q" g: |8 `/* assign the tl som board LED-GPIOs*/& f! x$ c& \8 C1 o7 o
static const short da850_evm_tl_user_led_pins[] = {: ^/ P- l/ N* W# H
/* These pins are definition at <mach/mux.h> file */4 w" e G z* }* T6 m7 E
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,1 X: V# ]& J, s$ i6 u6 A( B y
-13 S! W+ ~4 K' P p
};' v, X* V6 _* O" t4 B- g! d
3 I( A+ K7 @* o+ Estatic struct gpio_led da850_evm_tl_leds[] = {
$ D' x6 j; s& X) n* j/ U, R O$ X5 b {2 V8 s. i5 p* S& l- q. G
.active_low = 0,- A3 i3 D2 T! p- X, i( S1 Z4 g# F
.gpio = DA850_USER_LED0,3 ?6 v1 a2 J5 m8 H7 G4 O
.name = "user_led0",/ O% o @4 Z; a" s
.default_trigger = "default-on",$ A/ Z `% k7 s' ^
},
3 B4 e4 Q. `& \ {; p' ^" U, W- e G9 M
.active_low = 0,+ O) H. H; g6 z6 j7 q3 s# I
.gpio = DA850_USER_LED1,4 Q. d/ K7 Q! x* {8 @+ m) U4 x
.name = "user_led1",
/ q2 A5 T: T2 U. {/ A .default_trigger = "default-on",0 f: Q R4 u- a# d& |9 W# q' D
},1 B( ]- l8 F8 Q# `( w
{
7 q4 m, w; c0 y .active_low = 0,
& W7 B( _) f5 r .gpio = DA850_USER_LED2,$ J( A7 S. B8 M d& U
.name = "user_led2",/ X3 h7 F5 ~9 y. A$ X
.default_trigger = "default-on",1 ?8 }2 {' v Z# _6 L# w6 C
},. l( ]! ~, q9 t2 L
{; n ?2 ^% V, m* O& C; D( S( H
.active_low = 0,5 f! H0 x3 h* ]2 q
.gpio = DA850_USER_LED3,
* u% u1 K+ W! b+ B# Y! E* o .name = "user_led3",
9 ]* E% i& w8 ~* s .default_trigger = "default-on",
0 q; A! d: D# ]2 @4 W },4 u9 j/ A( b; u. U
};
, r9 H( F: _) `: D% d6 y# F6 Z# w/ V6 {1 o: h, U I
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {3 t+ I2 E }/ s* S( I3 Z
.leds = da850_evm_tl_leds,# ?/ p! Z+ B( B( I$ R
.num_leds = ARRAY_SIZE(da850_evm_tl_leds), R/ L) K0 d) G" q/ O
};
+ R( c o+ b5 p" O8 o9 c
% X* U( G! z& S; bstatic void led_dev_release(struct device *dev)
1 m' n5 c8 s( i9 |* A{/ i4 \/ u) D9 R( [' J/ X
};. [5 I2 k9 z O1 T5 P
, u% T; Y7 w' j: gstatic struct platform_device da850_evm_tl_leds_device = {& s f1 [0 V6 B( d( ~5 \/ r
.name = "leds-gpio",) J/ d. M1 r) `/ R* j$ c) k& `; s
.id = 1,
M" L! K0 b$ d7 I4 L .dev = {
. g6 c* ^+ F$ L .platform_data = &da850_evm_tl_leds_pdata,
' T! M+ y5 H1 W' C1 g+ L .release = led_dev_release,- ^3 a3 _+ z% N
}$ t l5 d( {' X4 h! a
};2 M# s- e8 @8 [1 |
6 a: H! E$ r" X, H% g' estatic int __init led_platform_init(void)9 y% I! _3 X* [, r
{! X: a {! d) i; L+ I
int ret;- T8 R6 n! B( B
#if 0+ R0 A4 X9 A, P$ x1 g. U/ W
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);* X1 K1 ~ N. J' \- U
if (ret)
$ T7 I1 S% Z: p; ~ pr_warning("da850_evm_tl_leds_init : User LED mux failed :"4 k- v; [! p# ^
"%d\n", ret);+ R. j3 g: o) Q8 u+ S' U7 J7 k
#endif
( p: b- e, _7 ?7 O1 W ret = platform_device_register(&da850_evm_tl_leds_device);) m2 O2 j6 V9 \5 U5 o2 v3 _
if (ret)) P. D0 _" m8 ]" F# i5 @$ v
pr_warning("Could not register som GPIO expander LEDS");
3 n& k& [& _' A8 _( N { `: D7 v else9 W5 e4 k& ?3 n* W
printk(KERN_INFO "LED register sucessful!\n");( A( K. D5 |- k/ S2 i) k6 B
X. T' I/ Z5 m% b
return ret;" L- G' o6 D" ~+ T1 G# A* I
}% [8 {9 e1 g. S U$ V
! v- t4 h$ @4 u/ A6 m1 w4 kstatic void __exit led_platform_exit(void)% E. G, O: b, x7 K- v! F
{& \" S. `7 U' V1 C( K; Y3 u( p
platform_device_unregister(&da850_evm_tl_leds_device);
' o2 w* S* ]( z9 n4 V7 U3 |
7 g" A2 J! ?# a e printk(KERN_INFO "LED unregister!\n");
' i4 M2 K/ x) F( D}
- i9 \9 A6 B" n0 m% t. ^9 ?3 ?! n: c/ G) F1 b
module_init(led_platform_init);% b1 l- s. E, D. a
module_exit(led_platform_exit);/ t; |: b) ]/ p
9 | {, |2 J8 ` y! R# NMODULE_DESCRIPTION("Led platform driver");- Q7 w4 N& _( ^* A$ f4 ~
MODULE_AUTHOR("Tronlong");* b( a4 B$ Y+ [5 `& d X3 x
MODULE_LICENSE("GPL");
8 R* { I( v2 `7 F2 c {9 S' b& x
5 m" Q6 S5 i! U8 p. @$ e( W% ] |
|