|
|
求大神给下面的程序做注解,请稍详细些,谢谢。8 N& y0 C$ d1 \& w* z, F
#include <linux/init.h>
$ Y0 Y0 Q/ P$ R+ ?- b#include <linux/module.h>
# V7 X" D$ H* Y/ z7 N#include <linux/kernel.h>
# q- q5 K1 Y# S5 }2 m t#include <linux/types.h>9 M9 ~ A. U. u# ^& O$ o- _" J0 U
#include <linux/gpio.h>/ B8 O' |. z! [6 y) Z0 Y
#include <linux/leds.h>
9 R+ E/ P* ^- B( H#include <linux/platform_device.h>9 S4 O2 ^5 \4 U6 {7 ?
/ p0 B) L4 s/ X#include <asm/mach-types.h>
; q5 M1 L/ j; b' [$ W#include <asm/mach/arch.h>
! ~0 [) q3 U9 L6 ~: [+ S+ V#include <mach/da8xx.h>) m' p$ [6 g( ?: C
#include <mach/mux.h>: `& q( S0 u" F7 w: f* C
+ \, [# s4 l' \4 j& W( @8 ^#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)0 X$ ]' T! }2 @0 [: [% {5 I2 w
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
- w! f8 H9 M4 @$ }#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
! v: X9 S, Y% V) ]. U9 }#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)8 R- q( K6 {* S, G$ Z* O
. N8 A, D$ z2 N# ^) f/ J/* assign the tl som board LED-GPIOs*/8 |9 Y7 a4 l+ f! }8 P# l
static const short da850_evm_tl_user_led_pins[] = {
3 w# N+ E6 A# Y) Q& t /* These pins are definition at <mach/mux.h> file */
1 A$ D# O' f. q! E0 N DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
5 s7 a( W6 [% t+ v# r+ V; m5 z5 f -1( q6 u& K; o" \2 H
};9 u7 W; ~) D$ P2 n7 ]+ t
6 M3 _; ?: \4 A/ F* N; s
static struct gpio_led da850_evm_tl_leds[] = {/ u9 U0 m. H- W6 ^4 M2 L3 l' T+ f7 n0 Y
{
% F( {' m: a5 d& ` .active_low = 0,7 n( `' Y6 n6 f' h1 O$ G
.gpio = DA850_USER_LED0,
* q8 f* Y: j/ Q1 L8 K9 @' ^! \ .name = "user_led0",
4 Z1 i& p: K! {4 R; [0 a$ I2 Y .default_trigger = "default-on",
/ d9 U( ]7 a' u },
7 a1 |, p* q) M( H* {$ Z9 Y8 J {6 Z3 i% {; F+ T- ~$ Z
.active_low = 0, |: }7 N$ F6 d# ?
.gpio = DA850_USER_LED1,; j! A$ F) W/ P2 P6 X) l* V
.name = "user_led1",
1 x/ p0 z( L. q$ \" @7 w1 A .default_trigger = "default-on",
/ C5 A, p# d) V; Y" w },
& y- J9 n3 s& g6 x! U {; X" I( t" `- a, r2 O% ?4 L( x
.active_low = 0,
+ k* `7 z* |$ b0 n( D7 V L .gpio = DA850_USER_LED2,
3 h2 b7 P( [3 {8 V; }5 l3 d .name = "user_led2",
/ L. _- Z2 E( |) r# z4 a .default_trigger = "default-on",
8 h3 h" |$ x2 o% ]( N },7 @, t) N7 g7 {$ n& ?' @
{
# l% }7 S& J( t A9 g/ ?" | .active_low = 0,
( t; ?/ u& P# g% p; P& ^% t- x .gpio = DA850_USER_LED3,
T# Y8 s3 ^- X .name = "user_led3",3 Y; L! n, _) Z' T8 T E
.default_trigger = "default-on",
! f) a- K0 N8 Y },3 T8 T4 ^2 H( M0 h' S& f
};
# K$ |! `5 G9 X
+ p( } M8 ?. I1 d, U1 mstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
' @- @4 @2 Z+ r7 ?% p .leds = da850_evm_tl_leds,
4 x# s- K, I2 M. l8 \% z5 @# \ .num_leds = ARRAY_SIZE(da850_evm_tl_leds),' v Y& ?, c! j
};
3 [! w- e: w/ i' d) q: m7 N8 }: U0 ]: p' Y& ?
static void led_dev_release(struct device *dev)
+ ?- q& b+ b# V4 l7 {{. D6 v U- o) J, Y- d/ y( R# r
};
3 @5 o+ [+ l: n1 Z$ g. y
H. A: M1 v( H" Z! z" Bstatic struct platform_device da850_evm_tl_leds_device = {# i- w" y7 p0 M% H
.name = "leds-gpio",
9 A: b. a/ D9 K9 j .id = 1,- F4 A+ {1 u) V0 q! Q4 J
.dev = {
6 Q8 @, f" S4 v .platform_data = &da850_evm_tl_leds_pdata,
3 d3 e- c) z& t1 h: j .release = led_dev_release,
; x; @' M3 T, l! J }5 P; i7 c3 B: w% {/ e
};
n7 V7 I, G/ R. n# g4 l; V- H
: @2 X) K- u. n8 ^2 D6 [6 V, rstatic int __init led_platform_init(void)% F1 P3 o& H7 c7 i0 E: Q
{
3 K( d* ]6 B# v5 N6 h$ k0 o int ret;' u+ J( k+ R) a) n, U# K, N2 N
#if 0 O" Q' g# V% e. b, K8 L
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
+ ]* r* a/ W2 e! n8 \ I if (ret), i3 P1 Y% c4 p
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
4 O( a: Q5 F7 _5 v) M1 P) b- Z) Q9 } "%d\n", ret);
# \# Z: O" I$ B H0 i' O8 n3 Z#endif% C4 @5 U% f' f# \/ a r; i
ret = platform_device_register(&da850_evm_tl_leds_device);5 X3 l( |; |, l- I! F: S( F
if (ret)! y0 {3 R! h0 `; |
pr_warning("Could not register som GPIO expander LEDS");9 u2 K2 e: l2 c% T
else1 B; x8 n1 J2 o N) o) T4 \
printk(KERN_INFO "LED register sucessful!\n");
+ T# G4 v' t) m h, q5 s% W
( d: r! y, s v; V$ X* U! ` return ret;
+ F) H9 f- f t9 K}# |: v; Q' r; F8 I# R0 h
1 _# v; C# H$ \" Q/ Gstatic void __exit led_platform_exit(void)* J q+ E6 f% X+ R: y8 k
{
% x i6 x* F% a3 |' E+ d platform_device_unregister(&da850_evm_tl_leds_device);
; O' x; I3 H9 P0 f9 p$ I& P
. v! U2 I" Y$ n. p- t! H2 G% I printk(KERN_INFO "LED unregister!\n");* v7 ?# V+ K, C2 Q$ @
}
b, M. y1 N6 K7 X# l% `6 a) y& Q3 b; I4 {; k
module_init(led_platform_init);+ Q6 Z' W/ K& f# \
module_exit(led_platform_exit);
2 X5 U' N# ?( o d
. x. s/ N$ @4 U8 ?MODULE_DESCRIPTION("Led platform driver");
' ?, C# ?1 t+ C2 }! D! u) nMODULE_AUTHOR("Tronlong"); n2 I4 p0 C8 l. B' y: b
MODULE_LICENSE("GPL");3 L {* z1 P9 J# I! D
7 U% P1 j8 u* @) @2 B( u/ h( C
|
|