|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
3 X) X# Z8 q! W( v5 J#include <linux/init.h>
7 _8 { A' S0 f$ I' m# J4 N5 U* x8 l4 P#include <linux/module.h>5 j2 o+ {% }2 p: b# |
#include <linux/kernel.h>
; U6 M- v* X) w/ _0 `#include <linux/types.h>
! _& G' Y9 v0 Y/ U$ h4 g9 h#include <linux/gpio.h>% f) U7 R7 L5 h7 L8 u
#include <linux/leds.h>
& I* n& F( g8 S8 e( T6 M, ^#include <linux/platform_device.h>2 q- ~* j5 A/ {. [
0 r ~9 [. _9 N, o- U0 r! `
#include <asm/mach-types.h>
% F& {' d5 L f6 z#include <asm/mach/arch.h>* k/ F8 d: k: Q! W E$ F
#include <mach/da8xx.h># f. G4 N; `# o8 `* h
#include <mach/mux.h>
% y Y, |& b7 r5 g% |$ G) f4 M ?' F
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
* ?" I6 l! M# `# j, L/ |#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)- i& z: p H& a! H7 K# R. x9 x
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)' n" `# ]! }9 h: ~# {/ q, H* H
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
r; v `7 U, I2 N
, `9 u3 w( G0 \* j4 S4 B/* assign the tl som board LED-GPIOs*/, u E6 J& i1 v8 |
static const short da850_evm_tl_user_led_pins[] = {$ |7 s5 |9 V- p) E* `; s0 f5 M2 P3 M
/* These pins are definition at <mach/mux.h> file */
1 J/ s5 N; C% k/ U8 s$ l DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,6 @( |) v4 j. t' j/ b# [
-1+ d3 K& X, _4 g
};+ h3 c1 Z7 A8 k7 S2 `1 q1 C
9 s( t$ F3 @2 D. c( h! {) Qstatic struct gpio_led da850_evm_tl_leds[] = {
. \3 I6 ?" C+ M8 `" [# s- f. |& ]1 g {' `8 B; M5 ?, K, c, B: N# h# a
.active_low = 0,
, P( K, g4 s0 }" K z8 r3 n' J .gpio = DA850_USER_LED0,: l: ]# Z4 P& q& H. C
.name = "user_led0",! V6 w) K* J9 n, [1 R
.default_trigger = "default-on",
: H; f8 e% u$ I5 W" V' P. O },
. _ ~, t) l% |! @+ U: ~ {
: \! r E& D4 U: t* ? .active_low = 0,
# ^) Y& h ?' O9 I* e .gpio = DA850_USER_LED1,
# M- d2 _: Q- C2 w! h4 K2 C .name = "user_led1",+ ^# q: }- y% c
.default_trigger = "default-on",$ Q% H% }% m0 s0 t8 u
},
: [6 P+ b3 A% F# t( Y/ P {
' W8 s% Z1 [! F: u .active_low = 0," h5 m: @! s$ ~
.gpio = DA850_USER_LED2,. e8 ?9 G H; U3 q7 A0 _0 U
.name = "user_led2",
i4 a4 j0 z; a7 \8 G6 { .default_trigger = "default-on",
: ]4 I# d9 w4 J) B ] },
6 R; o( j7 F6 P {2 h" ~) [4 R7 G4 |( F5 u2 h2 }$ \
.active_low = 0,
3 _2 @! h8 F+ V7 f, I .gpio = DA850_USER_LED3,
( F* Y; `! r; F- p0 v2 ] .name = "user_led3",0 H0 J, j. d9 r4 b
.default_trigger = "default-on",
* p/ v k/ S' \/ i },
7 G/ e6 f3 E G( t7 k( M# c* s};$ i. a# q' C/ I& G
# H1 s$ E' W h4 Q6 n- B! Xstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
+ K4 h4 R1 M: |' E .leds = da850_evm_tl_leds,
. ^# H: G8 C ~* ^9 B- D! a4 N4 m .num_leds = ARRAY_SIZE(da850_evm_tl_leds),' n; |+ P1 h. n9 s* _
};# W) s, R7 U4 a7 g1 i! h
# P3 H- a, H! W0 g3 W5 u2 O
static void led_dev_release(struct device *dev)9 v6 K! \3 X9 K9 q. K B! D+ U6 o. R+ i5 L
{3 a) C. O; e; j6 Q' C, J( m( n
};
" s. [9 M. D6 U! j0 g+ P
& d$ [% y" |$ f3 E8 h8 u, lstatic struct platform_device da850_evm_tl_leds_device = {6 s2 h2 u- K9 L$ b! ^. p, X
.name = "leds-gpio",* D5 \+ S0 D1 q* G2 k
.id = 1,
5 q, w5 l; v. s4 d/ r3 z; w& ~6 o .dev = {9 A) `- M* Q5 D9 `+ f
.platform_data = &da850_evm_tl_leds_pdata,
% i8 i% ^; n/ Q/ y .release = led_dev_release,
8 s: b/ r) e0 o M0 z }5 A" h" b' ?: M. s7 K4 f
};
; W5 ~( C+ L8 H4 Y( A$ N9 i. w' Q" I! o
, S1 w! V# V: }2 P2 l4 {7 hstatic int __init led_platform_init(void)
* ?" [! W( I, f1 Q{
, r0 E! Z' H# h- o% V7 v int ret;6 |) ]0 e6 a* G, a! F1 m) D; q- Q
#if 0( d7 `; B$ |2 |$ n
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);) F7 C6 n! d- v% k
if (ret). C' M( [& l- @' `# L
pr_warning("da850_evm_tl_leds_init : User LED mux failed :", h4 P% k& f* j" ?$ O
"%d\n", ret);
' O) d$ f6 z2 N% v0 v, ]/ G#endif
& P5 v: Y) a) `8 P2 H- F Q ret = platform_device_register(&da850_evm_tl_leds_device);
% q: ^% R4 D( K# Y if (ret)8 b# o$ n8 B2 F1 f
pr_warning("Could not register som GPIO expander LEDS");
% d( M/ r0 M" Z6 a& j0 s else. f7 e! u0 r$ {9 B
printk(KERN_INFO "LED register sucessful!\n");$ X. p; q0 G, V. {
+ f# d: m7 e* R7 w return ret;
' H& t8 w& E- T" |: a3 ^}2 G/ X- v; A K+ e/ H p% @. v: R
! I# H. F* ^& s; z1 {' B, Z
static void __exit led_platform_exit(void)
' S# C6 t5 X8 x! C8 d- ]{
' ]1 Q. G H# `7 f( A) i platform_device_unregister(&da850_evm_tl_leds_device);
: j( v x5 s" F0 V: C, \$ o+ Z7 Z6 ^0 v( ~& g$ y( S, E5 A# N
printk(KERN_INFO "LED unregister!\n");) r: A7 v, d2 A/ B" ~
}
p; E1 j3 i1 {- X2 W% E
( o1 n& X! s5 kmodule_init(led_platform_init);
( X) G/ m0 k. \5 w$ Z0 K, Pmodule_exit(led_platform_exit);' e# S5 Q8 g, x
! s6 j+ b5 `; Q, m/ M$ ?7 L
MODULE_DESCRIPTION("Led platform driver");' l# c) O! X6 ^5 H
MODULE_AUTHOR("Tronlong");- R, G: p+ P! w- X, l( f
MODULE_LICENSE("GPL");) X9 W; m- B8 z" _ M3 @
. a+ O% A& m5 B1 C( ~( ?" c |
|