|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
4 K- U1 G1 s. _6 j8 c#include <linux/init.h>& ^$ R3 q* T" ]. F2 r% J: i/ P( [- ]7 q
#include <linux/module.h>( V& N" d6 p9 h. Z
#include <linux/kernel.h>
& X: ]& r& Z6 ]( v7 l# E. c. _#include <linux/types.h>
, G5 `7 w" i R#include <linux/gpio.h>
4 O' I5 P: D% S* }. u$ |4 W#include <linux/leds.h>5 {5 Z+ F" X# T- z* v: }( t, {
#include <linux/platform_device.h>
* ^$ l8 a+ z/ q
# o; A l5 F+ E% X1 [" |" U( D* d#include <asm/mach-types.h>
2 U2 b+ t: |. E/ l2 U#include <asm/mach/arch.h>2 e5 C- z! {/ D) g; M/ ^ W
#include <mach/da8xx.h>
; m9 B, b! j- W" U9 B( Q#include <mach/mux.h>" h) c# c7 r$ I5 n* x" @
$ c% ?# ~9 E% }$ e( N
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)7 c4 u% ]( K! f( d5 W! a
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)$ y4 [* g. ^3 M0 k3 u8 R
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
: ^+ s2 c# z4 N: B& w#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
. e" m. r. [& C- N, Y: I
' N: |( B6 R- P' I# q. h/* assign the tl som board LED-GPIOs*/% T& D9 [1 b- A: R: P
static const short da850_evm_tl_user_led_pins[] = {
! Z4 }6 o/ F/ {- {# A- [ /* These pins are definition at <mach/mux.h> file */3 _/ P K6 f. z' h; q& v( I
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
$ `1 z/ ~& L1 `# v0 J7 {) @ -1' H) I3 ]' F( d
};% n4 L, j- b1 l' z# Y
- J# x( ~$ p( h* }! C) L! C5 I: E
static struct gpio_led da850_evm_tl_leds[] = {( |8 y; b9 @7 k7 p2 v( J
{8 q: b8 _& k; d( X! M, r4 _
.active_low = 0,
- h7 S2 t. A: }, n4 \ .gpio = DA850_USER_LED0,9 E) S; \+ ^; L- \+ ~
.name = "user_led0",
5 Z! o7 } x' l$ t7 g& K4 b" C .default_trigger = "default-on",
6 c* `& r/ W5 e1 V; \# q7 p },
4 W# d8 g& Q( w: k ~ {
- L8 s5 N! H( i: R7 W .active_low = 0,
2 c8 `& d# [; @/ J3 Z$ G8 W C; A: f .gpio = DA850_USER_LED1,: W% K; y7 V1 L
.name = "user_led1",
$ H2 P, n: v: Y0 P" n# o .default_trigger = "default-on",
4 x% E0 g/ \1 d G3 k },
O! o, r8 U& D7 O9 u' \# ~ {$ [( m2 |) a. S/ t2 o" S% J: t
.active_low = 0,
2 S& B1 J! K; B' c( ?3 m) ~ .gpio = DA850_USER_LED2,
?% {- Z C, E$ H+ K: x( A- Y .name = "user_led2",
$ j$ e9 m+ K/ C; m$ Q .default_trigger = "default-on",
" q, T% U, b! p& o: h4 z$ F },8 j& d6 [8 \5 _* H& K2 @
{' b, ~ K- A( _) e% @3 P
.active_low = 0,
9 Y6 @) A6 E. |8 W Q3 V .gpio = DA850_USER_LED3," z: c' j/ n% |$ U1 z T
.name = "user_led3",
8 [9 r" C4 }# E7 {% _# w .default_trigger = "default-on",& d! A% F: ]7 Y$ _; r9 z4 N
}," s' p* V% l8 S0 i9 w1 c5 r
};2 d. }7 f) B( I( z" c' q( Z) [
+ z" z1 d4 | |4 H1 w2 q; `6 Pstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
$ ^& f) Q( a) y$ [ .leds = da850_evm_tl_leds,% _8 V* N' m+ s# M2 j P+ t
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),: x5 f! ]. y c6 J5 _' V( ?# ~- \
};: g5 A) [/ V/ _" X5 w
( e, ^2 _) O/ }
static void led_dev_release(struct device *dev); q) u; H$ a$ c# X" H
{" g: b0 i4 R& y( r0 \
};
1 L& X. W8 m) r4 P! Y2 A% A; H$ C% z5 W/ \$ O* t
static struct platform_device da850_evm_tl_leds_device = {
$ D" U7 H3 P' x$ u3 S .name = "leds-gpio",
6 ]3 z. m0 r) l+ U$ z8 q- \ .id = 1,3 ~! G, X# J Y
.dev = {
2 v% l6 x% C( k, |( y .platform_data = &da850_evm_tl_leds_pdata,
$ j4 ]6 e0 S, A& u; s: U! r .release = led_dev_release,8 g3 C1 Z, w9 R* w7 V- E
}+ g8 N2 k2 c- G7 X
};
6 f( e; L" o# G) V. x4 l* b
0 l: O1 B" }1 [: X, J+ Z/ `0 tstatic int __init led_platform_init(void)
8 n5 u! C; k5 r; U! Q{2 B( q# Q7 K7 b; R' R* l
int ret;
: f I: ?% t- l6 J#if 0, n% [2 k0 Z. ~: a3 o9 D$ B& P) N ^
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
/ _. O! _3 z# o8 }* x G* ] if (ret)' }/ u/ k5 M5 g% q4 E
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"6 p c/ y. K, T$ u% G& c
"%d\n", ret);1 T8 o7 [2 D0 L6 R
#endif
g$ G8 }( C- e- \6 A/ u ret = platform_device_register(&da850_evm_tl_leds_device);
9 _- r) s- Y" ~% t3 {: }, z( r if (ret)- r/ Q/ `4 V: A* R
pr_warning("Could not register som GPIO expander LEDS");% L) A! g1 n, i5 j0 W
else }. |+ T+ L5 X0 n5 G
printk(KERN_INFO "LED register sucessful!\n");
O5 N/ S" N: M
, ~% j5 n4 W2 { return ret;
' j6 @. X: S- `2 ~& _1 X' S) H}2 E' U2 d4 |" {
* F" B" k" A' E' D+ I3 A5 @
static void __exit led_platform_exit(void)& o! t" `% X# [& ], H! n* W. t5 F2 J
{
& F" M% M* q; ?+ {0 s; R. ? platform_device_unregister(&da850_evm_tl_leds_device);
. S2 Q1 ^1 O/ O0 q3 P% ~4 [' {* p/ b+ ~; u
printk(KERN_INFO "LED unregister!\n");
% y; r9 o7 D6 C8 c5 u}
1 }6 r1 ]0 n$ Y: g5 p3 A" ]" `
, i& S K9 D$ ^5 r/ Umodule_init(led_platform_init);# @5 p2 y8 b/ U
module_exit(led_platform_exit);$ g0 d2 y, T5 U! n2 L _9 A
( S4 H) w; N- l0 S, y+ ?
MODULE_DESCRIPTION("Led platform driver");
2 x) c- `5 q6 {/ c6 KMODULE_AUTHOR("Tronlong");
4 A) D. O, ?' B9 {; VMODULE_LICENSE("GPL");7 W3 a3 z4 f7 Q9 t1 U
/ h: U1 ~/ N9 K
|
|