|
|
求大神给下面的程序做注解,请稍详细些,谢谢。6 R s2 x% s8 F. Z- p+ |
#include <linux/init.h>
3 W* k S2 S W* q H- O% z$ ?#include <linux/module.h>
3 o6 m% e$ Z* @( f- \/ l#include <linux/kernel.h>( T2 Y+ G3 Z9 P! U d
#include <linux/types.h>) C/ U/ [, Z) `3 w [
#include <linux/gpio.h>
6 x5 K6 W7 [. ~' \. S' k& s" |9 t! R; ?#include <linux/leds.h>
( I( K+ G1 c. Q#include <linux/platform_device.h>
! I; ]4 V; D% z
0 f% y; q! F! F" ?( k#include <asm/mach-types.h>
9 m1 d+ U$ l' |3 X1 O, p/ t' D3 K N: U#include <asm/mach/arch.h>* \) @ P4 ]& g% A6 K
#include <mach/da8xx.h> I1 I8 j" v$ n* H
#include <mach/mux.h>
" U7 m4 |+ d6 n' W; _* k
: J2 {$ }" W+ x( A9 j#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
T5 ?% b) r& Q, i G#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)6 c1 }4 s/ z+ U" E1 M) x* u
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)7 s+ f% C7 O0 r' B
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
* n) U" I9 y" `- ?( U+ L* x2 d
0 w/ d$ g3 i8 w8 Y9 ~6 ?/* assign the tl som board LED-GPIOs*/
# E$ S: N u9 t. B- r# R& Astatic const short da850_evm_tl_user_led_pins[] = {
5 P4 \1 h5 N2 O, E: e1 P /* These pins are definition at <mach/mux.h> file */9 Q) `% \& j$ i- T
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,6 [5 N! t3 o( J- G$ r( g
-1# C) u8 ^3 ]4 u% N+ t
};$ L# g! h3 `) U6 n
: ]8 _: Z; [6 a: m
static struct gpio_led da850_evm_tl_leds[] = {
5 N: }: s: T" {% O0 F {. o8 _2 [$ Z- F1 I; I# x( ?
.active_low = 0,
* @2 y) E" \4 T .gpio = DA850_USER_LED0,
( `0 O9 N3 G M6 }( b/ G .name = "user_led0",
3 y, @6 A! a/ i& d/ I/ H+ i2 Q .default_trigger = "default-on",! ]1 }: Y; }# L3 v6 P
},# w- _# ?$ q9 P8 S
{( Y% ?' f& C; P, _
.active_low = 0,
( P% a8 j- t0 _3 u: m .gpio = DA850_USER_LED1,
9 o. f: I! `6 x .name = "user_led1",8 b. W* a+ o: H" y- \' S. c5 ~! u/ q
.default_trigger = "default-on",% _$ r3 x& h* Q* [7 m( Q2 n
},
3 V) m+ b: E$ s" L+ Z {
, u1 f8 b# t6 A .active_low = 0,* @: H7 _3 H6 z, ]! f2 ~ ?7 @
.gpio = DA850_USER_LED2,
! q9 X0 s# g2 M .name = "user_led2",
2 e- H% b3 ~2 { |# `8 ~5 n .default_trigger = "default-on",$ Q! r/ l q# J, v
},1 x2 {6 q( x5 W9 w( v
{
{9 J% ?* s. B+ t+ }# k .active_low = 0,! i( t4 \3 h2 m
.gpio = DA850_USER_LED3,: ]9 C! r3 C; B" m: L3 [
.name = "user_led3", `$ w. R! m6 g' x) l
.default_trigger = "default-on",2 r6 |5 G' s* j2 b' X
},) J6 ` d. ?: X9 R, a8 _
}; v7 v( m; J4 D0 ]+ Y5 P; u% s2 A
- w! H9 R L8 q5 J. q) F
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
# i) ?; e6 u4 h. D. H: J .leds = da850_evm_tl_leds,
; r( W2 M' |$ b( @9 a .num_leds = ARRAY_SIZE(da850_evm_tl_leds),. j. Z8 W* o# s" b# ^. C
};
, n1 o9 P0 d+ ]; r" q9 k2 d6 `7 q7 c/ } `2 f) y4 u
static void led_dev_release(struct device *dev)* A; B' E; Z5 J+ U- u/ O& N7 \
{
1 w: Z5 i9 I+ P- u$ f' V) q};
5 Z; z! D* e' Z; m7 ~
" E1 |* B W2 I! }0 c, _1 Fstatic struct platform_device da850_evm_tl_leds_device = {
9 b! e: M% l' b: H .name = "leds-gpio",5 z( W- j- C, `1 z
.id = 1,6 I* z, o1 ?2 _
.dev = {4 k, G5 t: V! d3 ^2 H
.platform_data = &da850_evm_tl_leds_pdata,4 L4 i( H- l, j* K4 m7 d- R4 V0 d
.release = led_dev_release,8 i. X+ z9 [& \5 ]/ i- Z* m
}
4 f$ i1 B/ ] I, _. y};! j9 z9 b! y) x, ?2 U" J
9 n! a, R$ Z8 I3 `2 _5 w; x
static int __init led_platform_init(void)
" s5 X( J r# [{' l# U1 R6 M! H$ m
int ret;
1 x4 E& J1 X; M: M4 B0 q' w#if 0
a; s0 }; ~: j+ ^9 n7 h ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
& n) e& ^% V* f if (ret)( N, d6 u1 F9 `, }( _2 \
pr_warning("da850_evm_tl_leds_init : User LED mux failed :" u. D: v+ {' i6 X- J T
"%d\n", ret);
& j: A7 _ V( L6 z#endif+ D% s+ Z. w, z4 U) S6 v& N" u; J
ret = platform_device_register(&da850_evm_tl_leds_device);
' @/ ~! @) x+ d: |% j j if (ret)
3 N: ~$ o! k5 j# F g. K6 U pr_warning("Could not register som GPIO expander LEDS");% s3 H7 t, t2 K
else
( f+ m. E+ c1 N& U" c printk(KERN_INFO "LED register sucessful!\n");9 K: c% F E, A
9 }9 u1 U/ n/ M, d& s& j" a return ret;
3 |3 y# Q; u9 \3 E" A}
9 w, x1 ^9 N2 G2 F' s0 ]; k* d; |$ x+ V3 I+ h$ M3 s2 [
static void __exit led_platform_exit(void). E( U9 F& L' X" z" a* c+ H6 c8 }
{
- e, }3 S: w1 c. t* H platform_device_unregister(&da850_evm_tl_leds_device);, k& v0 A9 S1 U4 T9 u4 k/ R( O
2 s7 D! V* t o: g7 g printk(KERN_INFO "LED unregister!\n");' C# G+ z8 k1 Q; c" a
}! f! e! w9 M4 }* Y1 k: \
& U! o# n C4 P" v( ~# i, gmodule_init(led_platform_init);
7 Q, ^1 @1 J1 U$ I& pmodule_exit(led_platform_exit);
5 F; f, Z) t0 {6 B! B& V8 s, m5 k" G* B) g0 A/ V/ |
MODULE_DESCRIPTION("Led platform driver");
7 C; Y& X- ]8 \, r2 gMODULE_AUTHOR("Tronlong");
( X+ i( X0 G2 I* _' M7 {4 f" MMODULE_LICENSE("GPL"); |# _3 N: ~& {" q6 ]) z
3 S5 B0 D7 \ P
|
|