|
|
求大神给下面的程序做注解,请稍详细些,谢谢。+ X* n2 ~ ~& k* v; [
#include <linux/init.h>
3 H* z) s. X2 t* q# R8 w#include <linux/module.h> i) E" J2 y" W. `' I+ q
#include <linux/kernel.h>& T' j! a% q2 o O( M- m
#include <linux/types.h>
# E, p9 t1 ~6 J+ v0 K% L& ?8 A: r#include <linux/gpio.h>
) J: l% G' m9 L& c& d) _* }#include <linux/leds.h>- W6 j6 n) @. @! T! n, x6 @! A6 f
#include <linux/platform_device.h>
/ c$ f5 @ ^! G+ h5 G# B& H
) h3 r% S, x- R7 U. C W#include <asm/mach-types.h>
- z+ x7 Y& l# z# Y8 A2 C#include <asm/mach/arch.h>
/ P+ e8 m: u1 r% y) j" ~8 N2 t#include <mach/da8xx.h>( [) ^. z/ i5 Y' X4 U
#include <mach/mux.h>- A. [1 K8 ?2 r/ I% Y1 E
5 I4 X# T+ P' i! e6 K/ }4 K
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
: P/ H: S8 f9 @4 f6 n& Z#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)' T% @ B6 p1 Z! V! C
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
8 c& x2 Y4 O8 L2 j" ~#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)0 o& M# s+ K2 Q8 ~
3 y1 M0 b5 G2 [4 `3 p& T6 Z
/* assign the tl som board LED-GPIOs*/, M* z9 D- y, {, [) p/ Q0 V* ~
static const short da850_evm_tl_user_led_pins[] = {
6 r6 K: N* {( D$ c- s; a6 z) v /* These pins are definition at <mach/mux.h> file */4 s/ \0 e% X! i" [7 M1 e
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5, |3 d) X5 c" d# @
-1 H/ ]1 R% _3 l9 l
};
% I$ r' o' R' s3 O6 K- S7 f' T& }7 l% |
static struct gpio_led da850_evm_tl_leds[] = {, j5 K6 G; L6 O/ M$ y
{5 u( k) H; ~" S, j2 G7 ?
.active_low = 0,
6 ^5 ]; {! v' d1 g" ~4 S .gpio = DA850_USER_LED0,, e! P0 W& |" q
.name = "user_led0",6 K Q% b4 C/ n8 _/ _
.default_trigger = "default-on",% r4 f4 Z# l+ w: Z9 b
},
8 I# N) e/ ^& H1 m9 P* k {
4 |0 ~2 B6 N0 k: W7 S! R .active_low = 0,( T. b5 L" v: }) j0 d" i3 N
.gpio = DA850_USER_LED1,, f: u: r4 P. v2 q8 @, k
.name = "user_led1",( q4 e6 G z* o6 t% K
.default_trigger = "default-on",% @5 N. B/ S; x `4 n0 Q" F" Z4 d
},! ]' b) Y' ^! n) z5 i4 R' x& Z
{: ?- |# f) t8 V# }+ T+ k( v
.active_low = 0,
. D" E% H, F" t) |& { .gpio = DA850_USER_LED2," Z; D F( H8 }2 T3 ]7 o' y
.name = "user_led2",4 D2 A& a+ M5 r0 }2 o/ K$ L
.default_trigger = "default-on",' Q) M* I0 @- W/ K! v
}, b1 X$ {, G3 W/ ?* I
{
" B3 J. y+ L8 X% [2 t- f .active_low = 0,
/ a9 U1 f; E8 _ .gpio = DA850_USER_LED3,, I" e" U( _1 K( E w. n
.name = "user_led3", H3 O7 U5 a. _) S1 u' H+ G
.default_trigger = "default-on",
/ ~1 z4 O2 A6 `: M },
/ w& e- x/ L% x) q) R8 _};
5 [- B! ]7 H* b* g6 ]. \
! J& ?8 \0 v; m0 R0 Ostatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {2 \, J8 P5 X+ c7 A& [+ J
.leds = da850_evm_tl_leds,
, s. i- m' Y7 K0 D .num_leds = ARRAY_SIZE(da850_evm_tl_leds)," G0 Y" J$ v2 p0 C, ^3 M
};9 D2 g% O6 x0 H7 M8 Q
2 Q+ Y, ^! n/ l/ Rstatic void led_dev_release(struct device *dev)( g L) }: N* ^- c
{4 G" L! i0 ~7 \5 s4 c8 ~. {' g, S2 ?) N
};" A5 @' h& ^4 h: j8 @
k: J' |! m* j `+ c! c
static struct platform_device da850_evm_tl_leds_device = {2 Q, C3 Y9 t3 K. r; p; f" c
.name = "leds-gpio",
& {2 o7 V! B; K) o0 Y .id = 1,
1 Y9 X4 B: P3 u! F: R5 r+ ` .dev = {5 z, |/ {. i- c8 z
.platform_data = &da850_evm_tl_leds_pdata,
$ o- l- z9 |, x1 N, i3 P) M .release = led_dev_release,+ A9 g1 ]8 J: E. M& @( ]. F
}
3 P8 A0 K5 V/ O. r+ F, f};: }0 v$ k. r6 Y' p0 ?6 p
9 X% P- K, i" I6 _+ h7 b2 F" Y
static int __init led_platform_init(void)4 i; L- E/ x/ A# A6 q
{9 h; T Q5 g7 s& Z2 {) h
int ret;
( h) s8 F; ~. k4 Z$ j, r#if 0 k; }/ h, @% v6 ]- g0 `0 t, N
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
5 R) N' F7 W. V- I if (ret)
) s4 O0 u4 _1 p1 p pr_warning("da850_evm_tl_leds_init : User LED mux failed :") S- o+ j$ k4 p# { q, ?9 {
"%d\n", ret);
/ x& _2 V/ E; g+ {( C! Q#endif8 I+ ?( [! }, g' ~
ret = platform_device_register(&da850_evm_tl_leds_device);
4 t6 a( q; F4 O0 W1 d if (ret)+ q8 ~ f+ w* @# P) o
pr_warning("Could not register som GPIO expander LEDS");
& ?9 J4 |$ o/ o5 }. I8 r/ d" k0 q X else
! L- R; `' T5 S: n3 v7 c: s! B printk(KERN_INFO "LED register sucessful!\n");9 B5 B% m1 G8 |) e+ Y, }6 O
. N& {" p# {1 N5 y- b
return ret;5 B: w3 h" g }+ Y3 b/ p: m
}! m, w/ `3 c( c; W- T
7 |8 d T' {+ B8 Z0 ~static void __exit led_platform_exit(void)
3 o5 ~+ _) i9 x/ d2 e$ _{3 p, y) S6 a0 J
platform_device_unregister(&da850_evm_tl_leds_device);6 |' h. r; j; Q% m9 I9 l
/ |! b5 T5 D2 p: p4 Z, y
printk(KERN_INFO "LED unregister!\n");
, ]' `: S& d- d) {, R, q) H3 R+ Z}2 T4 {+ o; m9 c. G$ l7 l
" R* k) S+ y9 r; R0 a' Z8 D9 w2 lmodule_init(led_platform_init);) _" ]) c! w0 ?* | P8 p; j
module_exit(led_platform_exit);
' G( k+ W9 M3 t, w# Y+ y3 y8 z) X" }. w( y' s3 \
MODULE_DESCRIPTION("Led platform driver");1 }. J( v: r) v$ z, t! ?! g
MODULE_AUTHOR("Tronlong");
; a! w# ^8 Y- c) l1 WMODULE_LICENSE("GPL");+ S$ w/ ~- R8 n# M1 R2 c
. s4 h4 d5 y8 P: e |
|