|
|
求大神给下面的程序做注解,请稍详细些,谢谢。. ~, q6 w K5 y/ D
#include <linux/init.h>
/ _2 I- I! b2 n/ A' E1 p2 z#include <linux/module.h>$ ~7 F" v# e3 B2 m5 _
#include <linux/kernel.h>: r: k1 e6 G1 h) k( U' B6 _
#include <linux/types.h>
( J7 k# m: a M8 a. r; w7 ?#include <linux/gpio.h>) ~9 B, i* j) b0 Y7 Y8 _, l
#include <linux/leds.h>
# r7 W/ l6 l8 {$ Y, v#include <linux/platform_device.h>
' I# X; M. _7 p3 Z; O u* U) _& x0 p5 O) J. K
#include <asm/mach-types.h>
% l) M8 f* U/ _8 `* J5 _, |#include <asm/mach/arch.h>% t% `1 X8 @- I
#include <mach/da8xx.h>
# w# S9 `& S" U, H; N#include <mach/mux.h>
4 I+ x: z3 G# Y
9 ~1 o/ U9 q. a4 W' j' I9 f; O4 t- D#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
+ u9 p( g, |; i$ n' |; a#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)" }! Y1 O8 R* X6 `" X
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)( k9 D& A0 K+ q, B( N
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)5 n3 t/ D* J$ Y% p* v/ \
4 e ?6 J2 I7 R; }1 i
/* assign the tl som board LED-GPIOs*/
8 L$ l8 |2 j1 \/ \' Ustatic const short da850_evm_tl_user_led_pins[] = {
( F {" i4 u4 K: p; J' q7 _3 D /* These pins are definition at <mach/mux.h> file */: K% j) G( g# Y# h( ~' j. f
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
6 O/ _6 `, e% R, |% S& g -1) e4 C. ?8 S3 i# k% H$ u
};) X( } E a/ Z
& E }' `! j- ?* r! ?. Y, Y8 Q
static struct gpio_led da850_evm_tl_leds[] = {
# c/ F# a# H6 d, {# f5 Z {; U( p# `: l7 q1 B, p! {
.active_low = 0, T+ f5 k! ~% s* u9 b
.gpio = DA850_USER_LED0,- l; v! ?( O( I" u* P7 B
.name = "user_led0",- v2 M! H9 W1 i4 ^) p1 o
.default_trigger = "default-on",, f2 @$ n3 Z6 b
},. i" s2 x4 Q7 c* |
{ o' p: X; b9 C9 G; U
.active_low = 0,6 k: ~; I/ q7 [/ }
.gpio = DA850_USER_LED1,3 r8 Y6 q+ g2 `& o) X* \6 o
.name = "user_led1",, l; J' m. f6 P* C) a' A4 R
.default_trigger = "default-on",4 s% o1 f6 }8 L$ q
},) ~& I( P/ e9 c
{
7 i- y% O* M7 P. {: @ .active_low = 0,* s( i }$ k8 e$ ~3 q
.gpio = DA850_USER_LED2,6 D* u5 w4 p( g2 [2 w- T
.name = "user_led2",
" H% }; v/ D2 V! h .default_trigger = "default-on",
( z4 y' I( [3 u( f4 I },
6 e$ r: f c8 l% |3 w, w* J/ J {2 c* y" _/ K* K: ]5 D2 q0 V& _
.active_low = 0,
2 W4 X3 t9 J) d/ @4 n5 F! A( s .gpio = DA850_USER_LED3,, d/ l+ Z7 [- L! _1 i+ x0 U
.name = "user_led3",! ?, [/ B* p3 P: _
.default_trigger = "default-on",/ p0 D% L8 J( n3 A0 x1 N
}, p4 ^$ s; f) L
};8 r: o, W; A7 B- i }0 Y) a0 G
5 }8 g0 f: m, [* qstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
; S, }% o5 [8 @* O .leds = da850_evm_tl_leds,
# e6 o( {% s' @* U) s& S .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
- ?. b" Z( |% n};. H# J9 V/ X: E1 s
3 V$ Z n) V5 C7 F; H, }; e( Xstatic void led_dev_release(struct device *dev). G8 D7 J8 Q5 Z- ]
{
+ ?4 j5 r; e+ e, E};' k6 R! u4 e, b! x) A
7 L) u/ o' G9 x+ x( d: Vstatic struct platform_device da850_evm_tl_leds_device = {
4 i" F8 m" A7 g .name = "leds-gpio",( ~7 w$ h3 v& d& |8 M
.id = 1,1 B G1 q( f! W( F; }3 l
.dev = {
' N" c# a5 C2 N .platform_data = &da850_evm_tl_leds_pdata,
) j9 \& {4 O/ c" y$ p .release = led_dev_release,
& h9 Y ]/ C1 Z2 Q }5 }0 y# W m. q, D6 w8 O( y5 f( F( c% j
};
; } [4 X0 G* J! f* k# i
; _& q; z; @/ i" W- f+ l) J1 N/ lstatic int __init led_platform_init(void)
9 g7 i; t+ h# f# a& Y{( I. W& B- j/ N0 D/ C
int ret;
. {- `5 ~& j4 p/ E; l( I#if 0# d: r6 a6 H$ k# W# {4 a
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);2 i/ ]! e) ^* l
if (ret) `, _7 H, v9 l$ B* t: o1 S6 q7 o8 z" j
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
8 Q8 q* Y. w( X "%d\n", ret);
3 n6 L9 s* @5 a4 H8 M/ h2 t#endif
, L6 @1 E/ G& o6 p) V ret = platform_device_register(&da850_evm_tl_leds_device);
2 X( b5 n" P5 k; q* ^& K8 V3 K: G if (ret), C: c ~+ n8 Z1 `& N" B2 H
pr_warning("Could not register som GPIO expander LEDS");
# O+ n6 M/ J$ u3 y1 I else
% e8 I5 E, d) e( W5 o printk(KERN_INFO "LED register sucessful!\n"); v$ R( @+ }" q; X" O/ s! G* D6 y7 Z
6 o" Z# S6 a* v1 Z2 Q return ret;* l! Z' u% l" S
}2 P* t# e+ M4 L3 Q4 k( p- o
0 A+ @( v0 N' B! o6 B0 _9 E% V: sstatic void __exit led_platform_exit(void)
# v d: `9 Q- t+ Y1 A# q0 A{$ q% J) a8 q8 J) a1 W
platform_device_unregister(&da850_evm_tl_leds_device);
! p3 `' q3 B2 d: J# d1 {3 n# b9 \1 c
. v( d: L& G9 `0 i7 @ printk(KERN_INFO "LED unregister!\n");4 F& K* k" ?/ p2 j v Y
}# ?" \/ t3 O; `! ?
+ W+ `1 e/ \( |6 h4 q4 x$ u/ U4 N' _8 M
module_init(led_platform_init);9 m4 f5 P) R3 c! V0 f& ]! S
module_exit(led_platform_exit);0 U/ }( Q! f1 E3 s% c1 L
+ f9 _$ E. r. X9 g( d8 z# h& k' P
MODULE_DESCRIPTION("Led platform driver");3 S( f3 g4 A: N" y% n S
MODULE_AUTHOR("Tronlong");
s' S6 Z1 F P. K2 y/ Y* w3 J- N+ YMODULE_LICENSE("GPL");
: R G" ~9 P4 H- H( e; ^! |
4 H1 _7 l$ [( g% O- ^ E |
|