|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
! u+ n8 W& G6 K) E2 b#include <linux/init.h>
0 \6 S) C- U3 K3 i D#include <linux/module.h>
% f' E8 x: R1 }* K/ }0 ^& E#include <linux/kernel.h> ~0 ^* N* u0 J6 u8 h+ b2 ^
#include <linux/types.h>
: ]9 C( N9 C7 B' V# Y/ }5 i/ f4 Q#include <linux/gpio.h>
: ]. O7 u# P2 P. ]6 U4 h#include <linux/leds.h># u9 N- ]6 k, ^3 {6 w, \( a! ^5 S
#include <linux/platform_device.h>
. b% B, t& W& S, J, A+ e, D" l: x6 `( B5 p" |
#include <asm/mach-types.h>
# F, W5 l- X$ D( Y#include <asm/mach/arch.h>
, g# g+ U( x: j! f3 \#include <mach/da8xx.h>2 [4 W! h# o0 T5 c/ i! J+ r% g, d$ z
#include <mach/mux.h>: [3 E- {6 S# Q o( Z
5 m. ?! F3 k% x0 c7 }% f t
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
/ r8 S% y4 M# e" s. b#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)8 R: k4 i( J k: S3 y6 Q- I( r
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
/ }, ?: A2 [. [7 v# Y' J#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)- H0 d; `' R$ X" k1 M3 N3 y
- U9 s) W% N4 n7 ]- Q$ P/* assign the tl som board LED-GPIOs*/
% D! K! l) B+ O8 @static const short da850_evm_tl_user_led_pins[] = {3 B* K3 M' a4 A! i$ X5 P
/* These pins are definition at <mach/mux.h> file */
, o" U. w) t u! J: o6 q$ ^ DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
! x3 K6 y! G& v, p3 L F/ Z- o9 z -1
/ c- ?+ \" A: _};/ |9 n) Q& ^ {3 J5 @5 k
0 l* ^, F% l nstatic struct gpio_led da850_evm_tl_leds[] = {3 B4 K& i. G* p I: @
{* N8 o- M+ |* R
.active_low = 0,. r0 a; O8 F! `. R' ~
.gpio = DA850_USER_LED0,
: k( N6 B" C) a3 n3 N .name = "user_led0",& G& B2 ] e0 V) C+ ?6 @
.default_trigger = "default-on",
& a3 }' Q, C$ V: M1 e* } },: j% t/ c0 K3 p k2 z# j, D
{
; X, p/ |6 e* Y+ N .active_low = 0,! b0 P4 T% p6 S; @* U1 H$ @
.gpio = DA850_USER_LED1,$ U% {' \+ i: C3 A8 F
.name = "user_led1",
7 p& z/ B8 j. e( k; }1 N* \ .default_trigger = "default-on",! g9 ^7 A% r! V$ x' A7 y
},
' T$ U* a. {/ F {
3 w: s! P% y. D Y' Y .active_low = 0,
. v0 i. B2 @* b+ {1 v7 r7 O .gpio = DA850_USER_LED2,- A J( M: h' R' R- P$ Z
.name = "user_led2",
+ Q2 [& c, p, _ .default_trigger = "default-on",
6 s6 @; _% u- `* k0 x& q- z, a# u0 b },
, S5 c# S2 Q: w: I6 { {
" E" ?4 E0 ?2 |% c+ ]! s5 m" G .active_low = 0,8 R' Q% }) ?: |( }3 b9 C) h2 R
.gpio = DA850_USER_LED3,& {4 w* D, T) Y8 i' h
.name = "user_led3",
, s6 X* P5 e: Z5 X' E( @0 H .default_trigger = "default-on",( Z/ L; g( d& h) @ a4 @7 P2 O. c
}, N9 a7 K2 |/ W
};# l) W! R4 F$ R4 @
4 K2 v) x8 D, b3 U* @$ q, T' lstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
/ H6 w3 d% B4 N5 i$ a2 b8 W4 [ .leds = da850_evm_tl_leds,9 G2 }9 b6 P& R& g& K6 M
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),: E H- c1 Q9 d$ J% w
};( ~7 c p# h9 e0 v
8 c, t. _) P! g/ J6 s' U( g% astatic void led_dev_release(struct device *dev)
# q! Q* ? D7 R0 A6 B& E{! z4 o9 H# q& U
};+ J' |3 \: Z: J) M8 S* T P
& J! Z x3 ~$ G
static struct platform_device da850_evm_tl_leds_device = {; f, Y7 @$ x! f" G6 w* h' J
.name = "leds-gpio",
( P: w9 @. Y# B1 Q: B .id = 1,, F) \, q9 L y% F# k
.dev = {" S" n F( B9 ~- n% z
.platform_data = &da850_evm_tl_leds_pdata,
& u8 p+ k9 U; n* H$ e$ D9 |$ ~ .release = led_dev_release,2 g/ O1 S9 ~, n( E' X
}: n, G) |1 F# E- }
};
/ b. }% {4 P, V0 {% L% M; A/ {8 ~ N0 j( x2 ]
static int __init led_platform_init(void)
* V3 @9 b- N1 H* l. S% U& S{$ ~1 M6 M/ [% \5 q
int ret;
/ M- E& _8 p; g) g6 f9 ^; X: G; Z#if 02 u+ J, p& a- a+ s' Q5 H& g5 n
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
0 u+ r0 b5 l) w if (ret)7 w; h: S% [9 R# P2 Y/ `
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
& o* ]4 Z; i8 c' t) U "%d\n", ret);$ ~ D9 x4 P+ s; D8 y
#endif7 c- X! r/ s0 a* o: y5 S& ?0 p
ret = platform_device_register(&da850_evm_tl_leds_device);& i' j' [2 D. V3 k* ~; A: I
if (ret)" c% I* a+ b- N
pr_warning("Could not register som GPIO expander LEDS");
2 Q T* W) c" ^5 G8 a5 q( D6 T else' y; G+ O) z/ h6 v; V3 e
printk(KERN_INFO "LED register sucessful!\n");
& G1 Y+ K! C8 w2 \3 L
- t2 N/ |2 X7 r6 w- @6 M return ret;
7 I, T0 p' ^7 `8 v6 S* x9 J; r}/ K, j" Z( G- W) }8 h
$ k, v2 x1 `0 H. X- N% ^
static void __exit led_platform_exit(void)
: M% T* X% b& ~3 I{
: R6 [$ _$ R6 Y4 J; l platform_device_unregister(&da850_evm_tl_leds_device);
' t9 q' c7 {. B# }. [! ]7 s0 R0 J. ^$ q5 A2 a) U
printk(KERN_INFO "LED unregister!\n");1 o* v/ `9 W5 ?: J9 \. h2 g( Q
} A- C- ^* N/ j" C
# v( d4 _* b% i7 k! K l
module_init(led_platform_init);% ~2 A0 I) u, q
module_exit(led_platform_exit);
8 ~& s! n6 y4 D0 Y/ g
; @4 Z: a ]# j6 ?1 k7 _9 U' _MODULE_DESCRIPTION("Led platform driver");! g9 b" M4 _9 x- E% Q8 n; L
MODULE_AUTHOR("Tronlong");, j$ g6 ~( l- u/ K
MODULE_LICENSE("GPL");, C) |% A) l; l$ k" t
, M: t; h! L" K; `; i7 A |
|