|
|
求大神给下面的程序做注解,请稍详细些,谢谢。* p+ ~2 ~1 l! w* {
#include <linux/init.h>
( _7 H' p2 e. s1 T" G- i1 D# W- m#include <linux/module.h>6 p/ H5 P8 w, |- Y- V
#include <linux/kernel.h>: K5 p. T# |" j* s0 _/ K/ B: K; o
#include <linux/types.h>
" j& p* V, g6 v% b! I#include <linux/gpio.h>& b" ~! [# }) p, {% |" o. R. o
#include <linux/leds.h>8 _" J3 J. d# Z5 L+ O. o7 u
#include <linux/platform_device.h>
/ @/ b/ D2 k5 S0 V+ l9 z. V3 R$ a2 n& E/ Q" `3 [. u# w0 h8 [
#include <asm/mach-types.h>
/ x& y* _1 i1 Q#include <asm/mach/arch.h>
) I" z/ `/ g; E7 h% s% b, n- o2 @#include <mach/da8xx.h>
5 x' ~0 u, ~8 y1 Q! s#include <mach/mux.h>
' }1 {, @ H6 a/ L* x" u
8 U, d' s. k& |6 y4 d! u$ k#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)" V; \. \$ e6 F# c# ?! e3 ~
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
J3 f" P5 q7 a$ ?# L. |#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)7 a+ c" z& `( W# B$ f7 l4 Z
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2); k# @0 |& p, g. F; S9 ~
7 v4 B. U4 z, L P) \# X4 d1 o
/* assign the tl som board LED-GPIOs*/" n$ Z5 W2 D4 {3 h% n
static const short da850_evm_tl_user_led_pins[] = {1 Q4 r8 r# t& w2 t1 r/ v) X) y
/* These pins are definition at <mach/mux.h> file */
" a1 w5 j4 Y: d5 J9 Y" S DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
0 e. w9 O! b' g -1# i! Z1 M2 u* q% k8 e
};8 i9 N0 Y5 b$ h0 ?7 }5 s
7 J% W- J% n1 T/ @9 r
static struct gpio_led da850_evm_tl_leds[] = {
5 \2 L( E. {. {6 \/ d* A {
0 j* f( N9 @; F5 N* s0 L: u .active_low = 0,
+ x+ h Z; |+ `" z V4 [" V, c! Q .gpio = DA850_USER_LED0,0 P# P( k7 W x2 m6 \) E: x6 y
.name = "user_led0"," F5 ]* b: d( R3 x0 t- x4 k; [9 ]% o
.default_trigger = "default-on",
7 t& @7 D5 A* x4 P },
& C; Y- o! |& _ r {6 w& p/ O7 E/ u' h
.active_low = 0,
( h9 W, y/ m( P2 L0 \- H! L .gpio = DA850_USER_LED1,
; R' l5 [6 [+ ?( ? .name = "user_led1",
- U# s1 b$ q1 x9 B# w2 ^+ Y# W5 O5 K .default_trigger = "default-on",8 `; k' w9 K4 i4 ^9 p* `/ q
},
8 G3 D" ~! D) u {, ?+ g+ t3 g; e7 }2 a
.active_low = 0,, v# a [1 u5 O# l) U
.gpio = DA850_USER_LED2,
! J% C! A5 O, t. X3 i1 w7 Y .name = "user_led2",1 @9 ]+ f: m* t% o1 N
.default_trigger = "default-on",
* C( \; i. x- v3 a2 H },
/ O. J, o2 D ~+ E( S, g {2 u! d T1 {. C% A; d
.active_low = 0, \- l* r, m& T2 {. r8 D Z
.gpio = DA850_USER_LED3,
5 N( B+ [1 Q* `) Z .name = "user_led3",
. s/ P2 P4 `8 t1 p9 p5 u .default_trigger = "default-on",% Z) X' o1 E! i+ S7 B+ X
},% [7 `* v. u1 b2 n, }6 N
};
6 j( X! ^( E$ H- T
5 A. z6 s4 H: W! D( k4 Y+ pstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
" \; o) O; m2 T .leds = da850_evm_tl_leds,% i% ~0 y8 v: }& ^, ]
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),: A9 J9 g9 d6 a. Z2 ]0 Q
}; V, F# r: U+ I# K2 g/ l
) J! A' T% R0 o" D
static void led_dev_release(struct device *dev)/ e/ `1 ?0 O; b% H7 V5 L! Y2 a
{) v5 x% [3 N% W8 D- ~! R$ Y
};, p- W, D' d( E" R" ]
1 c( e. b" }' ~& A! }* n
static struct platform_device da850_evm_tl_leds_device = {
$ k# B: y! f* ~# { .name = "leds-gpio",% g% G" H/ S4 y7 W+ F
.id = 1,
% A+ w: Q* ^* t: ? .dev = {2 X, f: t0 k7 N
.platform_data = &da850_evm_tl_leds_pdata,; Y+ w3 j, A0 r" @
.release = led_dev_release,
' _6 Y2 D8 U) ^+ |0 o. S) ]8 ^ }
( `% F4 h& ?+ \3 P6 R& i# U3 D};! y5 t$ F% U. X$ q4 d, Y5 `
/ l$ `6 v8 U$ R2 s
static int __init led_platform_init(void): m- D9 k, D) O8 n" K
{
& D: v# v. I7 r. A6 u1 R9 E int ret;% G, ?9 h+ N& T# b8 }: k1 r# `
#if 0
, K' |/ d3 ^- _% P ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
. E ~7 u8 U) O0 r' ?# A1 ?% H5 {" ] if (ret); l% H- O J; q L
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
3 l! w! ]% \- Q0 P1 p "%d\n", ret);
4 c- }" }9 i: }! ]$ P#endif
& D( `$ k/ K& @" v- M ret = platform_device_register(&da850_evm_tl_leds_device);+ e- ^" z: ^. L4 b$ ?- o
if (ret)6 h! L' K4 ^* L& P$ D8 a9 q* ~
pr_warning("Could not register som GPIO expander LEDS");2 g1 p7 J* c' K2 b8 s
else
1 y# T$ g8 [6 Z8 U( e: U" j% U printk(KERN_INFO "LED register sucessful!\n");6 F8 k [- X% d8 `, e ?- C+ ~
3 N; A( H6 w* z1 v6 W( Z5 }6 N& q return ret;4 @" f H; M% F+ t
}
/ C. M+ R3 S' W" J2 Z5 }% N4 t# J: t6 x
static void __exit led_platform_exit(void)) z& Q. B9 l5 x4 m8 Q* ?% R
{
+ o$ C7 I1 @' h" E' W platform_device_unregister(&da850_evm_tl_leds_device);( z7 e4 {3 z ]! q+ a) L2 e3 h
1 Z3 U1 Y" P6 |( b printk(KERN_INFO "LED unregister!\n");
: T+ p! l2 [, G$ w F: e}0 _4 g* f' T, F: R& X, f, j
1 Q- q4 q/ Z5 A- T) i
module_init(led_platform_init);" }4 A$ P- R. x0 B' L8 o K
module_exit(led_platform_exit);- r# U% K2 J4 b0 r1 J3 I8 G
* o+ A, Z& j$ E8 u- X0 }4 ^5 j
MODULE_DESCRIPTION("Led platform driver");" y4 L! V! r% A; J! p- D
MODULE_AUTHOR("Tronlong");& o7 k. E, L: \
MODULE_LICENSE("GPL");
( \* T4 {* T2 H! w% {1 N6 _# ^; B. n+ C6 R$ R
|
|