|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
0 U% a: l( t& Q#include <linux/init.h>8 a& g3 O3 b* \9 A9 }$ y0 H
#include <linux/module.h>
( X8 v( T+ i! ^# ~#include <linux/kernel.h>
" X6 f. E! t$ D; |% | Y6 k1 z#include <linux/types.h>
7 g" f. `4 Y( A- o* G6 ]#include <linux/gpio.h>' s* e- F+ w x$ ^
#include <linux/leds.h>" D B2 Z3 Y& ]: v9 f2 T
#include <linux/platform_device.h>
2 O* I( q+ V' h( i2 m, J" ]# j, i+ [& i- n
#include <asm/mach-types.h>
Z4 u) v* m. t#include <asm/mach/arch.h>
0 y& k6 p' R) X' M. V: X#include <mach/da8xx.h>
) X* Z3 U4 [- A! x#include <mach/mux.h>
; E4 P7 o: H2 p* O I! X% T/ O! I% c, C; i% j2 K" e
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)/ ^) z3 F7 D6 Q
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)7 O$ N- p$ v* t$ I4 i7 i8 J
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)( e9 ]2 N( ?) p5 }
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
# L1 P4 [3 }' V& }% v% J# w% l' }
; b" I% z& x: L( D/* assign the tl som board LED-GPIOs*/$ J- N! J" |. O2 O( a1 i
static const short da850_evm_tl_user_led_pins[] = {
3 N5 j* g. p( w7 P /* These pins are definition at <mach/mux.h> file */9 t/ w; ]2 t4 Q8 C
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
$ K( [5 F$ v5 e. k0 g% T -19 N: b9 j# }4 F" m0 ~4 p
};2 Q0 `# @5 ^2 I8 R+ ^! H2 Y( [
: ]# r5 j9 k5 G) U8 E9 {# k9 U! @static struct gpio_led da850_evm_tl_leds[] = {
: g9 e7 S/ T0 @ {
3 }4 g+ _7 Z# i3 k" b .active_low = 0,: ?6 i0 ]3 n$ v: Y+ l' _
.gpio = DA850_USER_LED0,
# C/ x6 F! D' L: H% u .name = "user_led0",3 E2 I7 B: V: h& D+ y
.default_trigger = "default-on",
; S9 W! C0 [+ s: F },# R. d# |& h0 L S- W$ J% B
{
* I! J( L0 ~$ | .active_low = 0,
7 f# b- h2 e* E& t .gpio = DA850_USER_LED1,: q# s5 m; J/ _
.name = "user_led1",6 c" O! {0 H8 J2 }/ ?4 K$ Q- a$ }( P/ {
.default_trigger = "default-on",
; I F7 A o0 q K0 s+ [% }# l }," l: o) m. M- k: _+ |
{* Z/ C! [/ N" P/ }
.active_low = 0,
; G, T2 C$ J4 P! Q8 N/ S .gpio = DA850_USER_LED2,
4 G) |2 x3 D4 G2 \& J: f5 S; z .name = "user_led2",
M- E, _7 r8 o6 N+ ]1 V; Y .default_trigger = "default-on",
2 o8 R. P X* Y# c# z }, Z L& b5 I" l$ z$ t; h
{
. Q$ G) O7 x0 p% B: p m .active_low = 0,, C; q% k! T2 c) v! U q1 v! \
.gpio = DA850_USER_LED3,
9 F* C1 {) G: E6 [ .name = "user_led3",
2 _1 h2 p4 f4 W0 t& i .default_trigger = "default-on",
, e- ~( s8 Z4 F. ?* u/ @ },' }2 t5 U4 B+ ]9 l
};
4 N, V% ?" F% Q+ Z& |7 G& } {) e/ O; q7 z4 X: R* d1 P
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
* c; s o' A/ R7 u .leds = da850_evm_tl_leds,
: N9 A/ k- d) v .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
7 t+ P6 h1 c* s) I};
7 p: ?, _( |( |: K: m) j7 T! ~/ s& ~6 R5 [7 P1 @9 C
static void led_dev_release(struct device *dev)% T/ Z" b, o, U0 P: c
{% e8 F% ?, M( J& U& Y
};
" S* O" r ^0 u; Z5 y% Q" V# p
6 q; j! A# L( e8 r( a9 w+ ostatic struct platform_device da850_evm_tl_leds_device = {7 g+ Y, W1 Z+ m6 s( ~# b
.name = "leds-gpio",' `% o9 E, N$ _$ U- i" \' j
.id = 1,3 o! q* s" w8 V) n9 B! W* e
.dev = {
; Z% ~ {/ T, @6 u! T2 f. M, y .platform_data = &da850_evm_tl_leds_pdata,. H$ V8 `7 g) ]3 Z. L& J1 D% Y$ t
.release = led_dev_release,1 d3 a, q1 Z6 A, S1 q
}) t+ E- b- J5 G( a4 e( o
};
* ]; E7 d3 M% ^5 Y6 F3 d c4 `; Y- Z# Q+ t1 `8 ~2 ^, ]" O
static int __init led_platform_init(void)3 t3 z! Z2 w, l1 [) j( b; k5 R$ _
{
, F% _$ F6 X+ |/ k, Q0 I% B int ret;! B0 k. q0 z2 C, [/ r: R) Z
#if 0
2 \1 g0 a$ q, l: M+ o5 } ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
2 m4 x( @; [0 }1 V% R5 r3 } if (ret)/ z2 K4 M4 B: a: {8 k3 u- q H0 V
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
; E4 V. k$ q2 r& _1 ]; ^ "%d\n", ret);
( N7 R. Z C, b- ?$ R% t7 a' Y: [#endif6 b6 w. X3 Z8 z
ret = platform_device_register(&da850_evm_tl_leds_device);
0 Y1 |! C: i0 G% D/ @% s5 o if (ret)( D- f3 A+ R9 h/ N
pr_warning("Could not register som GPIO expander LEDS");! H8 p' A2 A4 L$ k% I( r
else/ K+ C+ X& ~& P4 x" m$ o: k" Q) m! j
printk(KERN_INFO "LED register sucessful!\n");& u+ Y4 A) H9 v4 h9 l, w
5 m' L% }% }3 ~$ e; A# D# `
return ret;; t( M# y+ R. M9 c
}; d) v7 t0 H1 T) u8 q0 D0 {
& e) C9 e; i) B2 s) G/ |
static void __exit led_platform_exit(void)
3 E0 t4 g7 F y/ H% D, ?{9 N2 z: D4 r! ~/ ?7 V' e0 j* W' ~
platform_device_unregister(&da850_evm_tl_leds_device);
" z! |3 d: F% {$ A2 L0 K2 ^, Z0 r$ v, z: g( @ A5 t& I
printk(KERN_INFO "LED unregister!\n"); g& \0 ?: H- T& x* s" I* x: [
}
9 Z9 F5 ~3 r4 V9 a" b. {4 h
l) I% Z& s. } C0 f" F! ymodule_init(led_platform_init);
2 ?( \! V* A* ?- p( b) amodule_exit(led_platform_exit);! D& Y. b) s. i* u$ R/ ^5 q
. A7 v% H, V, ]# q
MODULE_DESCRIPTION("Led platform driver");* v% J6 z5 B$ G
MODULE_AUTHOR("Tronlong");- q. b6 d3 [$ Y9 u& o
MODULE_LICENSE("GPL");
1 x1 j9 @$ T' S: z4 L3 C" G, @' T7 Y6 D
" N( S! Z7 j' X S5 I |
|