|
|
求大神给下面的程序做注解,请稍详细些,谢谢。; m8 c, J% I, `4 v/ J" n
#include <linux/init.h>
4 I3 h4 I% o8 M8 x3 ~7 K3 @, t#include <linux/module.h>
! x6 C' l$ O$ `$ S#include <linux/kernel.h>
; k" H% b0 ^, W6 k#include <linux/types.h>% t* Z6 Z3 w" D5 E) {
#include <linux/gpio.h> l: w% d& ]% S
#include <linux/leds.h>" g; C6 _7 R) Q
#include <linux/platform_device.h>6 f; ?% Z# ^. ` t' @
( l5 }# o; t4 L9 F/ r i; ]: e#include <asm/mach-types.h>
' B0 n2 ~) l' ^/ d( M5 _#include <asm/mach/arch.h>
! s0 r! E7 I- z P4 x w k#include <mach/da8xx.h>
4 R: |/ l# Z( I; F Z#include <mach/mux.h>
9 n" b" k; c# Q. \0 `
; l+ o ~2 B3 g! p N$ J#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
9 T Y0 [3 c# F#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
: Z) P5 \. y: I( T) ~ w#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
6 V. D9 X, q, f3 s) {7 _/ s#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)1 T3 L% c0 N7 E; t0 [7 d, ?) D, i
$ P& I+ }5 i" a8 C% n' M% u/* assign the tl som board LED-GPIOs*/& K! w7 M1 R: `7 W% t* i/ \1 e. N
static const short da850_evm_tl_user_led_pins[] = {
0 \& w" J) V* q- p3 O, r: l; Q6 S /* These pins are definition at <mach/mux.h> file */0 F1 A0 L1 ~8 o$ ]. h
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
% c+ \ R6 h! m; d: |4 U& M -1
9 O8 M9 x0 s' \: ^- r};3 o. @( L: ]) E% Z7 q* L
1 x* B$ _+ Z0 b4 n1 c: g" ?0 o {
static struct gpio_led da850_evm_tl_leds[] = {
' C' g3 V; m9 x, y0 c {
- w: X- Z( W6 Q1 p. s) D1 F .active_low = 0,; w. e+ N1 o2 Y! n% p2 I! i
.gpio = DA850_USER_LED0,
. t( k( y2 k9 T6 U1 W6 m .name = "user_led0",. F% {5 E7 v3 C) x ^
.default_trigger = "default-on",
; I9 a* J; z. {3 O+ B; E },+ b1 m( b; E( C% D% I( B
{
; v1 n3 I7 _9 y2 W0 m, D# g& X .active_low = 0,
1 Z% C. P, L+ f& f! t# Q/ _- S& b .gpio = DA850_USER_LED1,& X+ U; v- ]0 j2 m6 t; Z
.name = "user_led1",
5 O& A* }. ~% ? .default_trigger = "default-on",2 [, e1 s9 u6 n2 z) \1 r. r
},) z( @; y+ M0 p! h, O) p ]3 n
{$ R+ X ^5 n1 z4 i( e
.active_low = 0,+ i' d8 Y$ P/ u# B$ c$ \
.gpio = DA850_USER_LED2,4 I8 x( \& b) q G9 o
.name = "user_led2",
% O' X( p, J4 x6 i- m. b .default_trigger = "default-on",( q: r4 d1 F" S& f1 y1 B
},
8 Q2 [' s5 T$ e1 c/ R* R {4 K$ n' O( F; b$ ?& R
.active_low = 0,
" D. p+ X+ n- L o% ` .gpio = DA850_USER_LED3,
3 D- t$ L3 U* |; t .name = "user_led3",
, c3 n6 \6 J9 C5 r8 j. P, h .default_trigger = "default-on"," t+ B8 t2 f, Q: }: h. K& K
},
, F+ w& B% P6 _: m};$ d) c+ j; m8 G y5 H& D
x, u! R# x C3 l5 N; X- \3 d \2 Vstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {& E$ f# Y7 m& C- ~# ?
.leds = da850_evm_tl_leds,
7 O9 W O, \* A .num_leds = ARRAY_SIZE(da850_evm_tl_leds),5 Q4 {3 T& ?& [
};
6 {" x; ]! Y- f/ J# S+ V' s4 B0 H0 k: o' k F- S3 Z
static void led_dev_release(struct device *dev)
# y, A2 \/ u% u# i J5 A- ]{- |: b) e8 s( q1 a
};
/ A+ O5 c2 o8 T! q( [. u, V
0 z5 u* k1 }+ ^, Nstatic struct platform_device da850_evm_tl_leds_device = {
' o0 s/ `# \* H# o" \+ U' P .name = "leds-gpio",
( U0 E" d# R+ {# ^7 y6 p! R9 ^ .id = 1,$ Z3 b( K8 {; F4 Z
.dev = {
5 I. M5 L4 q% A, e/ s3 y .platform_data = &da850_evm_tl_leds_pdata,
2 k. b9 e& Q9 y0 P# I/ `$ ` .release = led_dev_release,% E, i& [3 }0 z! V7 B5 Q- J' s
}
' G, k0 ^* Z/ Y \& \};
7 y _9 V! v2 W7 Z' q! o" S, f0 N: S2 H* _6 ?4 i
static int __init led_platform_init(void)
/ B$ [ q4 s- _$ y- p5 b+ a{/ ` \- _# l+ ^+ O# y- V
int ret;; C. F. ?' j, \% j2 q
#if 0
: R; V. ]0 T Y" z1 V' R9 O8 C ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);) R" e) e, Q$ [
if (ret)
) i& }% v9 r" G: t pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
3 g) ~3 z" t$ H5 b+ P0 b "%d\n", ret);
" `) y. P: j z0 g' b7 m6 k2 R#endif
; ]( o7 ~- H, T: t, P E ret = platform_device_register(&da850_evm_tl_leds_device);3 ^. j1 w: w; x/ l! b4 [0 g
if (ret)! ~# ]4 p2 y4 y. y; ?& i
pr_warning("Could not register som GPIO expander LEDS");
. q+ R* Y! O( ^ else
& o8 e* q* H) K) U- }; J8 v printk(KERN_INFO "LED register sucessful!\n");
0 I6 x0 {5 B8 K/ T% k$ C5 y% D2 Z% v0 |5 Q, Z, {$ t! r; `: H
return ret;$ D- r7 n8 `* x0 k) r4 k) U
}+ k/ w7 h7 ~/ {
1 y2 B6 ~7 u* L- vstatic void __exit led_platform_exit(void)
. s6 `, ]4 K9 y' t/ [{
# U: m- }7 ? d, _/ b, ~8 E% ?) b platform_device_unregister(&da850_evm_tl_leds_device);
# H/ M& L" Z1 z4 ?: T0 n/ W8 A, e0 _& b; k2 O9 _7 s! T
printk(KERN_INFO "LED unregister!\n");* P$ T# X/ y! G; d+ R/ O
}
6 t$ j) H4 j, w: s) a* e1 j4 k( z0 m4 z* i6 r/ F
module_init(led_platform_init);
$ R, n/ ^2 E" j8 umodule_exit(led_platform_exit);5 G5 }. U, _4 h( A
7 H8 X+ ~: N& {7 n( Q+ x @MODULE_DESCRIPTION("Led platform driver");
6 f; e& O/ F# J. t( H" d4 Z) JMODULE_AUTHOR("Tronlong");! Z, }1 B7 c/ Y6 |) A% W- u
MODULE_LICENSE("GPL");
* j' }) i, \0 f" e b- b& _# ^( R) K8 ?3 X) z
|
|