|
|
求大神给下面的程序做注解,请稍详细些,谢谢。4 p4 _" L$ m- t k
#include <linux/init.h>
, r8 o$ J' J% m$ g8 C; W6 g7 Y/ V#include <linux/module.h>6 d( b9 } ^0 p& i8 b, `
#include <linux/kernel.h>) ^, E$ n) w4 H
#include <linux/types.h>
0 D3 k' x: K- _' H3 u6 ?' R#include <linux/gpio.h>
& z* z: ? K9 g5 @#include <linux/leds.h>
) V: f" b" @! l5 ?) r; [/ N: L#include <linux/platform_device.h>0 o8 Y% f4 R% a4 U+ E
3 N7 `+ ^0 P: ^4 q/ S7 o/ d#include <asm/mach-types.h>
; G$ k# @9 X/ u( R% ?5 z#include <asm/mach/arch.h>
( v! z. a" {2 z8 Y! r#include <mach/da8xx.h>
, i/ w4 r. Y% ]/ [! _#include <mach/mux.h>
6 L' m1 n2 |- J7 J4 y' j* e) E2 q0 e1 K
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)0 h9 h7 ?4 d3 _& D
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
' r4 l# J3 ?; y+ l7 s' j* c& ~#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
. U+ P- V" } o9 z2 m#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)8 w) T( o1 n( R0 i9 g
5 z. U( m0 |, Y7 @8 O8 c8 Z H
/* assign the tl som board LED-GPIOs*/
; u E1 ]& k ~: u( S" Kstatic const short da850_evm_tl_user_led_pins[] = {, U, P, m" M. G! H# B9 }) m
/* These pins are definition at <mach/mux.h> file */0 a& w, V/ }2 z1 o( H+ ]; K
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,6 f4 x0 M" O: c( A8 \
-1
0 J; T" `( U; Z7 Y- W d" r};
) `% S1 T' |9 ?+ U3 |1 F0 w3 v8 R0 J9 Q b! y. L
static struct gpio_led da850_evm_tl_leds[] = {
# G' B( O/ X) H0 l {
d6 ?4 F* k! P z .active_low = 0,( S& Y `& n, A
.gpio = DA850_USER_LED0,
3 b4 j) }3 ]2 y$ `! z .name = "user_led0",
: b9 E4 Q% v* F6 O% V .default_trigger = "default-on",+ x/ q3 b8 J3 z. J* e
}," M: H# A. C* `7 r/ g. V
{
; |3 w% u# d, L/ f .active_low = 0,$ q7 ^4 r% P/ M6 a
.gpio = DA850_USER_LED1,
: g" W( g: I% K u, q/ J .name = "user_led1",& R5 |5 I3 u% g1 R. w& u$ O$ I- Y$ H
.default_trigger = "default-on",3 v5 ?9 M# K0 t' x
},/ n1 m: k; S' {" f) i
{+ _4 s4 `8 f6 S7 F! T R
.active_low = 0,3 ]- w1 r# D0 w8 B0 T
.gpio = DA850_USER_LED2,' s9 {3 M9 J F3 C: x
.name = "user_led2",
; X* j9 [3 S' N( D" I* D, Y2 T% N .default_trigger = "default-on",. T1 M- j( O2 w) E8 T
},3 f" y- Z6 h1 c' t
{
. S; L" F4 E7 X .active_low = 0,6 f: N1 |, \: P- S
.gpio = DA850_USER_LED3,
9 u: y, j. }+ [+ @% L' w .name = "user_led3",
0 U; L- K5 D o .default_trigger = "default-on",: u# ?" V9 O8 w
},
/ u$ o+ {7 \- p) J# i};/ q* [* \( I/ e' A3 k
8 [) `6 |- A+ M) I* r9 c Istatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
& l* U4 I6 o2 o) a .leds = da850_evm_tl_leds,
- M% `) z( u; G% B3 [ .num_leds = ARRAY_SIZE(da850_evm_tl_leds),* r- o: X! `4 L' p
};0 l c# n R( o& X9 n8 j
. b8 m% m3 _: {- \6 Z
static void led_dev_release(struct device *dev)
5 N) ?3 C6 s5 [+ Z1 }: p{- e0 O( O) R$ C6 O8 B
};
5 _6 N) x; Q0 c9 X L7 p
3 M. U1 U& g% e& Y# T, ystatic struct platform_device da850_evm_tl_leds_device = {6 H- C" Y3 l2 l# Y: n% _% R+ x' u
.name = "leds-gpio",
9 Y. j6 m+ I& O* _. v) \/ S' R .id = 1,
. a! V0 g, j9 |7 H .dev = {
! c0 C2 ` S1 @. D* ` .platform_data = &da850_evm_tl_leds_pdata,6 i8 Z1 `% f0 P
.release = led_dev_release,7 N" l; _+ @8 d3 V5 x1 R% u0 c, a
}$ Q- y( b Q) u) b8 [
};: D3 `& K0 M- g+ e
2 j# T2 G9 D( z9 d4 ~( w* M
static int __init led_platform_init(void)
, J6 t9 X0 q. ]1 T& [. h+ q! p{
% U' Y/ c/ o1 T3 k M" H. D int ret;; I+ I2 D* B. _5 h7 {6 G5 _
#if 0$ ^3 @9 O+ t2 k* @5 `7 X2 M
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);5 l9 N, S3 i, }$ G8 U8 f
if (ret)/ X. E% n9 ?' u, k2 q
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
0 N8 p, d& o! |2 j8 }+ a "%d\n", ret);1 C( s1 i$ i$ q/ n0 M7 r. F
#endif
" f' e. r9 j4 r* c* x ret = platform_device_register(&da850_evm_tl_leds_device);0 C8 |2 j, M2 s7 N3 `3 G _6 b
if (ret)6 q( Z! E- \% g2 X7 b; t
pr_warning("Could not register som GPIO expander LEDS");
( E- ]: Y. \; c9 g4 ] else, t- ~$ L7 S0 ~$ ?, x
printk(KERN_INFO "LED register sucessful!\n");
7 n) O' A0 g- Q& J8 k2 f2 G% L. y: f: C
return ret;/ @7 O7 Z3 f5 }2 i2 n; o
}6 ]/ |2 \6 p' s
1 l R5 Q% D% O! Estatic void __exit led_platform_exit(void)' ~0 g+ h( @/ B f- E
{& C/ N2 C, j6 q8 e7 m. r4 r- l# V
platform_device_unregister(&da850_evm_tl_leds_device);3 Q) _4 _: f" c1 `+ N& M2 D
( _8 T4 i1 j$ D1 _, P2 F
printk(KERN_INFO "LED unregister!\n");( q3 u# J# p3 H4 o, k
}
2 U4 B8 i1 o1 G" P+ S: t3 h$ L: W3 k5 `& ]% i% z
module_init(led_platform_init);
- h: A. V! i- N |module_exit(led_platform_exit);
) @6 v- H; g" _' P1 e8 q( a5 G) L7 U4 `5 A4 V4 f1 P$ d4 P. Z0 C, f* Z
MODULE_DESCRIPTION("Led platform driver");- n, A) N |; T1 y( D) G( m1 C
MODULE_AUTHOR("Tronlong");6 q7 I4 h& T- }2 p' i. e
MODULE_LICENSE("GPL");
* T }& l/ @. E: ]* ^7 v$ i- {4 L1 ?7 ^: Q
|
|