|
|
求大神给下面的程序做注解,请稍详细些,谢谢。; c' e; M# \' _8 A. B
#include <linux/init.h>" o8 T3 P/ h6 v# }+ S
#include <linux/module.h>
- ^; O$ V/ \# d: D6 X2 X#include <linux/kernel.h>
& J: k" }) x0 g) F* a#include <linux/types.h>
: i2 Y+ y; I) F/ @3 }# } o% b* U#include <linux/gpio.h>8 U" n$ c' V/ @8 n, S9 g
#include <linux/leds.h>
0 G6 @0 e& P5 F1 `( x, a8 T: V3 ]#include <linux/platform_device.h>" t4 x! n: u' H
. \, A$ j4 O) ?, @+ u#include <asm/mach-types.h>
2 v" ^: {( c x; D7 C) Z#include <asm/mach/arch.h>* B R1 f: {" x! e9 U# `: y
#include <mach/da8xx.h>
. U+ m& \( V( L) Q#include <mach/mux.h>6 V- m) Z* S" R+ Z, Q9 g$ a4 Q
/ S9 a; l2 ]5 x1 m+ B/ b
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
* ~7 v+ t8 c1 b5 L$ X7 \3 D! J#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)0 x1 C5 i9 h2 [
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1), g9 r! G x6 {) O) Z& L, U' \
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)4 w3 @7 L; c, w/ W3 j
' ^# L, g" R7 R( ], e/* assign the tl som board LED-GPIOs*/: P3 m' T. l. `) T4 I
static const short da850_evm_tl_user_led_pins[] = {
5 Q) m" H: G% r0 \, w0 D /* These pins are definition at <mach/mux.h> file */( R: T; j7 K6 ~) [+ e
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
7 I+ q( M8 U/ A -17 F) d+ D: s$ t4 o6 I+ ~$ g
};% f! B1 V& o0 ]) ?! S! E! n
' A# X1 C v- o4 o# lstatic struct gpio_led da850_evm_tl_leds[] = {
) ^4 x# d- d* h" d0 G2 E {
# U% l2 c; ? O! Y .active_low = 0,4 B' ^, w+ c! U' O u
.gpio = DA850_USER_LED0, ^% ^5 C {& |; ^* e
.name = "user_led0",, M' K1 Y% K, S, ?$ o
.default_trigger = "default-on",
# u, q$ t7 O8 @7 t; A },8 K- H& ?2 ~, |+ P, z: ]5 m
{
6 ^) Y! Q* [' h: R2 n8 e3 q .active_low = 0,
( g7 N( D' X5 [ ]- u/ j .gpio = DA850_USER_LED1,; o; P& B, a9 o& G1 k0 X
.name = "user_led1",
8 J* J; G1 f E% ?% z. D .default_trigger = "default-on",
" q# k* @4 r! v6 Y7 }( f },! l# q* }- ]1 x# A3 {/ I% w0 I2 g
{
1 S: ^9 L( I* y/ o .active_low = 0,
; O/ ]: a7 ?3 J/ x .gpio = DA850_USER_LED2,1 ?5 ^; B& ~$ c: e" J, g; y! q
.name = "user_led2",/ a) ^" f; G8 O, w! M- ~* v( a
.default_trigger = "default-on",+ l& \, M) f" U4 ?& W
},
! q' w! G j& y3 j) T {
1 d- N5 V! S( i. f! x4 H0 @ .active_low = 0,3 X! U5 X. \0 }( F( Z. {9 [
.gpio = DA850_USER_LED3,
" D5 R! a9 U, B .name = "user_led3",
; W; w2 ~1 G4 Y: f# f. Y: s .default_trigger = "default-on",7 g; A! W3 V( S. M& H% O$ L
},) g, S/ L9 D o/ { U' H9 r) J) R
};
7 i6 B" D1 ]0 U T3 q8 v2 c! B
( p1 E, j, V v5 O9 ^/ X) |static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
- ` w! t6 j. W0 s3 x8 D .leds = da850_evm_tl_leds,! z% h2 }9 m+ r' E' g2 p
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),% i# C3 \. `7 q5 {$ u, U+ Q
};
) c* O* b1 E1 t: E2 `9 a+ ?3 M" t e* R
static void led_dev_release(struct device *dev)
7 L1 d0 J4 X" O" Y a8 _! m{) _$ \" {) f& w
};: K7 p; b5 M+ ]% W0 e$ u
& @0 ?7 P- n1 y# l$ k
static struct platform_device da850_evm_tl_leds_device = {
6 }# ~5 J+ i Y( Z .name = "leds-gpio",
3 C4 T4 w: H) M/ i8 u .id = 1,$ F" U$ q( Z; K: b; c
.dev = {7 v# Z3 |, u7 L$ a! L) b
.platform_data = &da850_evm_tl_leds_pdata,
7 f% k2 n# J8 Q0 j' v% V8 ~ .release = led_dev_release,
- V) N- e p U6 H$ x9 O }4 [8 @8 ~4 b( q$ O
};
' l& J" E6 t7 b! k& o( M# b% x: j
static int __init led_platform_init(void)4 Q2 D/ V9 @4 m, U; [
{# }. _- r& ~. ~3 W
int ret;
l- P6 l# i2 g' U#if 0
$ ?- ?3 p, r; C8 l% ?. L& f ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);9 g% R) O# C8 ^) \
if (ret)
7 Q9 @3 t, n1 w+ W. _ pr_warning("da850_evm_tl_leds_init : User LED mux failed :"! b2 A/ @" Q' ?+ B" F
"%d\n", ret);7 ]2 A+ V: e; m( E
#endif2 e# ^9 a m% a7 k8 ~
ret = platform_device_register(&da850_evm_tl_leds_device);
( P7 {$ y5 b2 A- S2 F9 t if (ret)& n# u7 ?- Q( J
pr_warning("Could not register som GPIO expander LEDS");8 {! \, m; T2 M, ?% c) M
else* p9 L( Q4 o0 ?; s
printk(KERN_INFO "LED register sucessful!\n");
- U, p- f! _# G& r4 y
. o4 B5 y4 W! J9 ?9 V' V/ Y0 i4 q return ret;
7 D# p9 w% C/ o; f- w6 x}6 }* A2 u" c$ X6 G1 h* D
# W8 G; [% U" M9 Lstatic void __exit led_platform_exit(void)
& x8 D7 X8 M) x& h/ ?{
8 M" }) n& Q1 s5 [, J* G& p# |, y6 c platform_device_unregister(&da850_evm_tl_leds_device);4 j+ a; b6 q' p& S3 [! x2 H
6 }. d- J" ^8 `) G* |7 l% C printk(KERN_INFO "LED unregister!\n");
8 |- x; q5 f( B; z+ p# f}$ q; u. m# W3 G' P4 M1 F
3 f$ ^2 M3 B7 v2 Umodule_init(led_platform_init);; d( ^/ f: z4 e$ g: e5 X3 H, p% ?
module_exit(led_platform_exit);
, C' R, t2 E; A, Y% P; {/ e
) w$ M- [; G* l% K% KMODULE_DESCRIPTION("Led platform driver");
% D4 E4 g/ f" n/ L1 }% JMODULE_AUTHOR("Tronlong");
9 _& w, `: k- U, g7 i0 T% h! `% dMODULE_LICENSE("GPL");( E7 }# ?, Q" Q1 \1 x; ?
# ]: q6 X8 Y' G! s
|
|