|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
0 `" l5 Q. n. t# R4 |#include <linux/init.h>1 H5 V) h% R. ?3 S; n
#include <linux/module.h>
& ~. R' U3 {9 v2 b5 _#include <linux/kernel.h>/ H) z) q5 R9 C5 ~% Q# Z
#include <linux/types.h>: Y- f$ H3 b |+ x' \; Z
#include <linux/gpio.h>6 Z+ P9 A( c, h. [
#include <linux/leds.h>
6 W; J) S5 W: M. U- Z#include <linux/platform_device.h>! U9 m- M$ S5 n
, J0 Q; c8 p2 L; V3 N: g- E
#include <asm/mach-types.h>
: H* I! s! N$ s6 V L#include <asm/mach/arch.h>
! o; X5 n# v( ]# L7 U#include <mach/da8xx.h>
% U$ F! {4 z, N# K) ~, a# m* t2 o#include <mach/mux.h>1 }' T, q; Y0 U1 s
1 y; q+ c: i8 @ |3 B# ~& Y#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
' S4 a8 S% H% W; a#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
6 ?5 P, X2 n4 i" n' m#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
9 \7 z8 P$ [+ M* ^7 F$ K( s#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)7 B J2 @' H% L
) s# }% q! ~5 V- b. L4 |/* assign the tl som board LED-GPIOs*/
; J) E4 I% l$ o! Q* ?6 dstatic const short da850_evm_tl_user_led_pins[] = {
! ~& b/ n% R9 m% h b /* These pins are definition at <mach/mux.h> file */2 s5 d+ J2 u& F. K! V5 R
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
! g& j$ K6 Q1 x3 b9 U! } -1/ F! {& x- g( ~& E3 C( d$ D. b
};% T7 N$ h4 m2 X# k% `4 X
) n) y) q! g4 K* O/ [ S6 S
static struct gpio_led da850_evm_tl_leds[] = {
( |3 I- p9 n, _2 J2 _ {% l {2 G, k6 v+ W
.active_low = 0,+ l5 K: X \8 [5 N
.gpio = DA850_USER_LED0,& `3 t4 u9 N& V
.name = "user_led0",
- \+ f; g- {7 S) m* R. h .default_trigger = "default-on",
& F/ Y9 m& u. f y },
9 ^" Z4 j) e w% Q2 _ {& s2 U) ^3 I4 ]( W* O" D
.active_low = 0,
\( x8 v+ G: [' H/ U& K .gpio = DA850_USER_LED1,1 e4 P' [5 j7 M5 G
.name = "user_led1",
* c1 R2 W' _# i$ g8 S! P .default_trigger = "default-on",
% t/ e! Z3 h( a" y4 m5 i, j! ~ },2 j0 u/ Q: n; } j) m- Q: K/ O
{+ w5 E- w8 q0 Q/ I0 u+ f
.active_low = 0,% _+ x+ J! k6 r P
.gpio = DA850_USER_LED2,
: G1 N+ B/ B$ t0 x- c .name = "user_led2",
% L4 z) ]- ]4 f5 Y8 \4 V .default_trigger = "default-on",$ f6 R$ o* c: x1 V! Y1 ~" w
},% R& i9 l6 Z1 N7 T
{' @) _* `( a! K+ o. R
.active_low = 0,
9 n% r7 z9 D8 M1 k* K .gpio = DA850_USER_LED3,
* E" i! W0 n# b2 w& _ .name = "user_led3",
: |, Z/ d9 D. P! y& E .default_trigger = "default-on",8 H% m2 v: H1 y* k. c
},( T7 J( E. w) F' \
};
8 x O) w9 q' ]: O. x+ R- r0 i" y+ @6 X
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {* u S2 d" j. Q' Z! H
.leds = da850_evm_tl_leds,2 S# ]* K( \8 q, V7 |6 k; C
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),; V/ M% o: k+ `. s
};
& w- h/ X( d7 y% D" `( t Y8 y
+ ]. @6 ?! N& p+ nstatic void led_dev_release(struct device *dev)
* b9 |( U0 G, K3 x* n$ S" s4 ~{" B+ Z- R7 X1 {2 K7 Z5 F# S( O
};
4 Z/ F! _8 C" m" m3 ^3 r/ g. a3 e, t) y$ @2 R
static struct platform_device da850_evm_tl_leds_device = {6 J+ j) f4 r" L2 |: v/ F- X. I
.name = "leds-gpio",) s8 h2 N* I4 e0 {
.id = 1,) e0 J% U) \& o
.dev = {9 N( s5 Q2 }- S) }9 V2 l
.platform_data = &da850_evm_tl_leds_pdata,
5 Z# M5 G' Y5 z0 G- w. m; d3 F .release = led_dev_release,
& q# g/ }3 e6 t2 _% t }8 F4 q$ R1 U% F L8 m; u( g% Q* n8 \
};- R7 W$ E) ?, T! X
, W' H$ p2 [# S/ D0 C+ d
static int __init led_platform_init(void)) o. o2 p1 J# I2 K: T
{( H$ H) P8 V3 Q- A, r
int ret;
3 W' E5 `! k" M2 `2 U' y4 G9 Q) u#if 09 k5 F; z. w& H5 K
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
) w( r) b! N/ V; ~$ w6 s7 ^( k if (ret)
9 ^" f; i7 c3 g {8 K pr_warning("da850_evm_tl_leds_init : User LED mux failed :"* T$ f8 t; a2 j5 Z( p/ N
"%d\n", ret);" N4 g& M& q0 G* V% [
#endif; @# B$ j- }& }/ k/ U, d! q
ret = platform_device_register(&da850_evm_tl_leds_device);
6 t S" q0 x4 g2 n; j if (ret)3 o# H& e& ]( [* A! h
pr_warning("Could not register som GPIO expander LEDS");
) _2 X7 A! N, m else6 q! A9 r' _/ ?4 S! [! u0 H8 j
printk(KERN_INFO "LED register sucessful!\n");5 ?0 L# \ F9 N4 j( ?
8 |6 M8 f7 n% y. z! O return ret;
+ }7 [1 O9 w5 Z+ b0 C}7 d% H, C! d( G, m
3 Z( V9 d6 I+ t# t/ @( Wstatic void __exit led_platform_exit(void)
" {/ y4 @7 e# c n{
+ E/ c* Y$ x2 f0 N5 {6 a1 c platform_device_unregister(&da850_evm_tl_leds_device);
8 q- n& G9 ]. d
/ C/ Y8 i) z! g$ ]9 S* z' i printk(KERN_INFO "LED unregister!\n");
: U0 T' T# h- Y}
" R9 t( `6 h# G5 d. U, q8 d3 M& }: L: d4 X% Y$ V0 R1 {3 o
module_init(led_platform_init);
- w1 L# k, p9 J' ?module_exit(led_platform_exit);: I* c9 V7 z- i& M# M# J
. c- r: h( c7 G4 m6 w, }! t9 cMODULE_DESCRIPTION("Led platform driver");
7 b- [ \7 L# f9 p& TMODULE_AUTHOR("Tronlong");* R$ \9 x9 @/ I/ `! F6 s
MODULE_LICENSE("GPL");
0 {0 k/ [* Q& k! T
# p% J1 }) q* h( N+ Y% c" P |
|