|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
. Q9 [% x% L. A! Q0 \$ R' |, k+ j#include <linux/init.h>- a" I3 w( z0 n6 Z8 `* s" T- S
#include <linux/module.h>
# D3 R N. b# T#include <linux/kernel.h>
0 c3 H/ ~3 j m' `' @' T#include <linux/types.h>* b4 u8 T& v7 B" v0 a' z
#include <linux/gpio.h>
! K- z$ |. u: ~5 Z+ i1 f* b#include <linux/leds.h>
" i5 o+ ]8 L4 Z w6 {7 s#include <linux/platform_device.h>
7 r" S* o( Z- `% _6 w. j1 ~& n9 @) ]; R
#include <asm/mach-types.h>
( w# J6 n# `9 z) K#include <asm/mach/arch.h>) u8 B* `: b6 o% K+ Q+ O& n* }
#include <mach/da8xx.h>$ Y) d3 ^9 `) A) }
#include <mach/mux.h>2 h, M" x c7 P6 u* b3 q/ B
8 U/ g, a; C# x
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
- P* b- Z( _% W3 B* q#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)) Q/ |( p% `0 Z3 ~" ?8 \
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)3 _! G9 ~0 N& x/ A' U
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
7 ^# W) M' P/ O9 ]) ~$ O7 T# e+ \0 Z9 s% ?+ `1 @! v2 W7 ~; X' y! r: M
/* assign the tl som board LED-GPIOs*/
+ Y* @4 Z! x, j) [5 D) G8 @static const short da850_evm_tl_user_led_pins[] = {
6 L( v, X5 |% v) c /* These pins are definition at <mach/mux.h> file */
- V K/ D% P4 n8 @( l DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
: Q3 o+ m' W/ q0 I5 U) e -1: A' T; y& t3 ]& l+ i6 p- y$ v( k3 b
};" Z: Y! U' m$ Q# c* A) x
/ E, w; \5 N: c- D% M: H) P9 Xstatic struct gpio_led da850_evm_tl_leds[] = {; P5 y. K$ [& j1 i
{+ e! O; Q$ n# T. a. @
.active_low = 0,
% P& C$ `4 h; C .gpio = DA850_USER_LED0,& b: \$ M* r7 \! B! K
.name = "user_led0",
4 C1 F/ M% I' G( F2 l4 u# ` .default_trigger = "default-on",
0 k b$ _; V; | },/ [. O* M. ~. s0 F9 @- i
{( w* h* h) ~2 y1 K ^& F ~
.active_low = 0,
" L5 R: H1 r9 m .gpio = DA850_USER_LED1,
- n- d) \ B3 f .name = "user_led1",6 N0 J0 Y1 a. T: x; |
.default_trigger = "default-on",& \2 e4 A- w* A. i
},9 f" d; J' D* G w) [
{7 n* M7 d8 _+ y) @$ I
.active_low = 0,
& |* r+ D4 j6 J' m5 h .gpio = DA850_USER_LED2,
5 Q8 P& V. r% x# Z1 a( P @: y9 R .name = "user_led2",
# W" E8 J! |0 p8 F .default_trigger = "default-on",3 c) { K4 e7 X6 Z7 i1 {& \
},
' J; @* k1 ~2 c3 U {1 g8 l$ ^. ?- b8 V( r8 k8 x
.active_low = 0,
* a4 f( ~8 ]4 V A9 f' i; ^$ O$ j .gpio = DA850_USER_LED3,
' k; \5 l1 @$ t& U ?- z/ M .name = "user_led3",9 j3 x7 ]% x& q- H
.default_trigger = "default-on",
# l( _+ c) z' X2 | },* V+ B' a4 Q* a1 U. q5 C# f1 ^
};7 \* h) m3 Y% j/ D' |8 h0 \3 p
! Z" Z; y, @, t
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = { X5 v7 ?7 o% f; k. r `0 B0 r
.leds = da850_evm_tl_leds,
' ]9 u1 w N( P5 @4 E5 j" \ .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
3 T: x" M# Y3 F0 X& N3 R};
$ v9 N0 C+ R) q' @. f+ k
; X( J2 u$ I3 Q+ c: S2 astatic void led_dev_release(struct device *dev)
" l F/ r: W' q8 d{7 s; R7 w! w/ `, f
};
/ X" E- E6 ~2 @% X% m6 L5 r' w: Q
0 t% N2 J8 b% {* h* Z7 w* m- Z0 k Nstatic struct platform_device da850_evm_tl_leds_device = {
5 k7 J* [/ C* b5 m4 ?+ Z' s .name = "leds-gpio",
- l( \) u5 Y) V6 ?0 D8 d .id = 1,
4 Q/ _' S$ y& e- C: q .dev = {$ T' B, o( c' Z
.platform_data = &da850_evm_tl_leds_pdata,
; R4 j; r2 t$ N9 p% K .release = led_dev_release,9 M$ I9 N% m# a! C/ R9 a' t
}
6 \% J' o% v8 ^6 n};5 t" p- V# y7 t6 b" N
# ]! r9 \! K0 e2 r" c& _
static int __init led_platform_init(void)9 W& P* ^3 _1 ?) e& h
{1 `+ d! z7 D( J$ O
int ret;1 ~/ X( y6 S) @1 L; Y% j$ q, }: N
#if 07 d0 u# @ m E* r9 b
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
8 f: ~0 c: ^( F* Z if (ret)' Y+ r8 \- D+ ]* X k& h
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
5 i* v! Q0 T- J/ K, p$ \; K1 \ "%d\n", ret);
. B* ?+ @8 j) R' V#endif/ T% @% B0 r2 O& W6 H' A7 ^2 `
ret = platform_device_register(&da850_evm_tl_leds_device);
+ i# N; F7 ]. T if (ret)
/ k9 Z! V' ~4 Q$ k" W+ s Y pr_warning("Could not register som GPIO expander LEDS");
1 m3 ^0 A5 A* z else
; C) u! I' ~, [4 j7 z printk(KERN_INFO "LED register sucessful!\n");
T7 _9 h) V: H6 v5 S
5 m5 @5 \5 J+ E1 m& S9 A return ret;
: G. l% V( g' K" a) {, c6 T6 ]9 r}
7 c7 @- z% {; B6 \. i" c# A V% J4 }# _2 x
static void __exit led_platform_exit(void)
3 O# v5 m5 q8 q, g6 K{- j$ h0 `" a& n* t5 K* v
platform_device_unregister(&da850_evm_tl_leds_device);# W6 l' l! a5 q" E
: ~9 U0 P( i+ w4 ~' C. B: c9 K printk(KERN_INFO "LED unregister!\n");
) v) e* c* R* z: j1 N0 u7 r}
! ~/ p5 b' N/ S6 q( [$ J5 {# h! C# ?7 @7 N! g9 u' R
module_init(led_platform_init);/ \6 i! S6 x# a2 O- k
module_exit(led_platform_exit);
3 m! Y) @/ g; v' ?& w6 s( {9 D+ i- G8 o/ V4 x9 y' b
MODULE_DESCRIPTION("Led platform driver");5 W8 y2 M! K, y$ \# @' b
MODULE_AUTHOR("Tronlong");
0 J. o/ o4 p. i; @9 oMODULE_LICENSE("GPL");
. Y$ t$ G* J* ]( d: F3 P7 l
2 l+ E- G e' i2 ~; O& F |
|