|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
: M [/ C6 f" Z8 Q0 v0 z#include <linux/init.h>
( S, K5 G* a/ e! F6 K) }#include <linux/module.h>
8 v, |3 O) O# i3 W# t& ^#include <linux/kernel.h>% Y, W5 f/ w9 G5 ?( D# P$ ~7 X% g
#include <linux/types.h>
! f; P& i% F3 I, t8 |( n#include <linux/gpio.h>1 W& c3 V: h" g+ P# b
#include <linux/leds.h>
1 R" b1 q A7 q+ U#include <linux/platform_device.h>; Y. ]: ~$ D2 R( {, s1 l7 a% l
/ G% H: N: G2 k6 b4 U
#include <asm/mach-types.h>
& A- F6 Y/ r% P- N, d* X#include <asm/mach/arch.h>
% d1 E s. M0 U#include <mach/da8xx.h>
$ X% J3 C! i6 ^% k6 v7 q" u) V#include <mach/mux.h>, m m6 s) u, ]6 f& J( E4 A9 L
7 z. n$ p- ^5 ^; o8 E" |
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
2 I5 @* U+ j5 @/ k& O6 T' V( ]#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
) X, j% x, |3 o! k5 b+ Y$ t' ]! _0 y% A#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
' `6 t* u, s Q# ~) g E0 k#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)2 f: I+ \! \' v- I: v% E/ |
3 b, c2 q u; f% f, [
/* assign the tl som board LED-GPIOs*/9 h9 G% M- V0 i) j' P+ f5 r
static const short da850_evm_tl_user_led_pins[] = {
* c0 ? z! N- I8 q: ]7 z /* These pins are definition at <mach/mux.h> file */
* ^ T( z' Z: B# t0 j e1 g DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
6 K7 j: u& r0 z' g -1
N9 S* y/ l1 z' k8 C- O};9 l% a( J+ o" W1 u2 }
8 n$ s! w# K3 [7 ostatic struct gpio_led da850_evm_tl_leds[] = {2 K: j. W' \6 V/ m$ v, x
{
* b6 ^# f7 s" t .active_low = 0,% V1 H* V' k' ?9 |
.gpio = DA850_USER_LED0,
( ^( Q: Q. x/ E: R- `" J .name = "user_led0",
5 L5 ^7 |- t2 S' p, @6 G1 { .default_trigger = "default-on",
$ s7 m: k, F' F5 x },
y8 e* c$ {% b; [. j4 _6 S8 _" w {- r' P4 ~! c8 k9 n+ g9 [+ |
.active_low = 0,/ P/ K' [$ y( J7 e! N4 q. x
.gpio = DA850_USER_LED1,
8 t4 J* x5 W% M% j2 m' g9 z .name = "user_led1",
3 u2 I: T X, u- U/ E .default_trigger = "default-on",8 K, `2 T! f/ W& O1 @1 g0 a
},1 o6 K; A" ]4 i6 H
{
3 G, ?! n+ I/ J1 b2 h .active_low = 0,
) u; ~7 | q! n% L1 O( H4 f8 s7 ^$ L .gpio = DA850_USER_LED2,3 y1 z8 w- x k' K, r
.name = "user_led2",. d+ P; `. I+ C5 q6 P) N6 }2 f
.default_trigger = "default-on",
3 q8 o0 }9 `3 m1 ~3 j$ V" o },
. Z+ y, W) E7 r: _$ C: i. Q( M* { {
) h$ y! v9 R- J2 Y/ Y .active_low = 0,
$ J) d1 \8 i* h .gpio = DA850_USER_LED3,
0 I, ?& Z- x9 J, q .name = "user_led3",
+ M3 x0 U8 O1 x- U7 |8 M .default_trigger = "default-on",, U% r$ Q: z! \7 j) t
},6 \/ p) {- h1 j5 p0 h, @! I
};0 S. c+ f2 D( J" Q0 `# X
; z4 X" O# _* S' s3 v
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
7 o' ?9 D& d7 c" Z4 O- y9 K .leds = da850_evm_tl_leds,
: K- |1 n: S/ I% T" G4 ] .num_leds = ARRAY_SIZE(da850_evm_tl_leds),. B# P6 Y% E# f0 z B F3 G
};
- G* Q$ ^/ s2 I/ }3 g) m1 k: J9 x- }
static void led_dev_release(struct device *dev)3 T6 t5 N) K2 y( x) o
{8 g8 {/ Z! l; J
};
/ F' J( ?9 l9 e2 L! D. O, I7 [4 b( Z. `( |; n- w1 u& k H% C( _
static struct platform_device da850_evm_tl_leds_device = {/ C9 ]# Y6 r2 p8 m$ \. k9 I
.name = "leds-gpio",! L/ z/ d( k% q+ A+ [6 Z" O
.id = 1,) y" j* e E& D5 e- K
.dev = {
# c3 W8 `* h/ J" | .platform_data = &da850_evm_tl_leds_pdata,
0 P$ `5 r# }" J+ S: \ .release = led_dev_release, n/ ?" R! E7 ^! ~
}
/ i6 |- K; u; e" }' V+ v};
3 [2 f1 L: u4 @, D
( I H9 t" g$ Istatic int __init led_platform_init(void)) c0 j* x A8 o# i5 Y3 z8 T, Q0 J' i
{$ g+ N) d5 x: c* E, P V! N$ Q
int ret;' o/ o$ B1 W* T- X
#if 08 |' S- O+ ~- u T' ^) i
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);8 w" ^& e, x5 a$ K; |
if (ret)
6 S M- K$ |% `& e pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
6 J, t. U8 U6 R "%d\n", ret);$ ]% E- J2 n9 n
#endif
& Y" u/ Y! i" w6 m' n ret = platform_device_register(&da850_evm_tl_leds_device);
2 M ?+ O& j+ |( B+ Z if (ret)
2 s. j$ L# R+ S pr_warning("Could not register som GPIO expander LEDS");
7 y1 P3 u8 v U else
5 @& D2 ^9 }/ U \0 o: D9 }; ^ printk(KERN_INFO "LED register sucessful!\n");
9 R# f' N1 c& c+ ?0 D
/ q/ {" Z+ H" X' e return ret;
, Q1 Z4 }$ f x8 L6 w) A4 U}* K2 {& f0 c$ C0 K1 y1 i
: |- }- I( V/ m' m% m; Gstatic void __exit led_platform_exit(void); c+ r5 U+ X; ^ U) a4 [
{
) u- i) L+ U5 R$ ?. Y. {* j platform_device_unregister(&da850_evm_tl_leds_device);# L( i2 R( r/ A$ z- h
% ]6 }* v! x$ r
printk(KERN_INFO "LED unregister!\n");
6 h% E4 m Z5 q" g: J* \& |, R}4 |0 N' j7 ^- E I/ k* r$ G0 T
6 R" ]" g: o. G( s, ~
module_init(led_platform_init);
H' I. Y. y1 ^ v3 Omodule_exit(led_platform_exit); Y/ q" q0 x2 ^; N5 _2 ^
; s6 |4 D4 U, y3 y7 L
MODULE_DESCRIPTION("Led platform driver");7 X) y* [, C8 C) Z; i
MODULE_AUTHOR("Tronlong");
9 o1 s4 p# F* u2 j) c# LMODULE_LICENSE("GPL");
$ l/ u" m3 z% c# P4 d" @# K$ |/ Z, E3 w" t
|
|