|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
& q) U0 y$ l6 E6 p#include <linux/init.h>+ U. c; y* R3 S- y! i
#include <linux/module.h>
* i0 a/ I7 {' W- ~; y) b#include <linux/kernel.h>
( ?& t0 F8 I; C) d#include <linux/types.h>
9 u1 J( z# {! t' v7 l# X: R1 j0 F#include <linux/gpio.h>
6 F/ [. M; n8 y4 h/ B: Z% E% H#include <linux/leds.h>. [% ~" ~% _ J; L( {- \
#include <linux/platform_device.h>4 u+ T5 G# {& }+ @
- f6 m2 X3 n, X' P5 r8 \6 l#include <asm/mach-types.h>
( H- U' Y/ Q5 l* ?0 l( ~7 r* @#include <asm/mach/arch.h>
" m& B* o% F. y+ E$ t, u# e2 p5 m#include <mach/da8xx.h>7 ?0 }8 C* Y! c: `8 p
#include <mach/mux.h>
1 t; H% z! |- h$ r: C- M" q D, n
) R# g; S6 X( A i* R& y$ c#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)* ^" i% W6 g6 a8 Z
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
) L f) J! ]/ \; _0 k8 t5 B#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
4 a) j6 z+ a% N) Y, v9 J% Y#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
7 u9 S9 d& E) Z$ C4 Q9 l" |0 Q# `& U* |6 u; Y5 d7 v1 Y
/* assign the tl som board LED-GPIOs*/3 u: C0 Z9 d& X6 \; q/ Y5 n5 k
static const short da850_evm_tl_user_led_pins[] = {
3 y& @/ ~* n8 N) Y( i: P /* These pins are definition at <mach/mux.h> file */
6 I4 ?0 e8 F8 A' R! {# G DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
, W" w* y3 J8 C+ k) v5 E: R$ f -1, h4 k5 }: ]+ N! F$ Q7 V/ I& j
};1 ^* z9 Z' e! q% }9 g/ O) o
1 l* J( q5 j8 P% h! Q( ~
static struct gpio_led da850_evm_tl_leds[] = {1 E5 c' H. J( a9 {* g0 x! B( ^
{4 w7 R# n; H/ j2 h3 V* q2 X, Z4 U6 X% n
.active_low = 0,4 k9 l2 ?& V, Y, h& {/ Z" Z! @1 K
.gpio = DA850_USER_LED0,
( R0 m3 E( L+ B/ w .name = "user_led0",
8 Z# G U& `2 b& h+ P. a! [, U .default_trigger = "default-on",
, ]/ W5 X* K x$ l7 f9 Z+ N },
1 x. E3 _4 B% p5 `0 J' W5 }7 a X {
2 V8 N1 P& u# k X N .active_low = 0,) K" O& B" l1 k) B" X( Q" \
.gpio = DA850_USER_LED1,$ q1 L, z6 k6 B4 {5 P% B9 r# R
.name = "user_led1",
/ r6 O& i7 e) `1 o$ ^8 L9 x .default_trigger = "default-on",1 a/ {0 N7 `% s' Q: N5 U
},
/ @$ \1 u4 K2 H& P {+ A+ r+ ?' O" M+ ^% u3 l
.active_low = 0,5 ]) Q8 }$ Q- j! ?% P
.gpio = DA850_USER_LED2,
7 B. U9 H: E. Z% B6 Y! A/ e .name = "user_led2",% V4 R j/ `1 T2 H
.default_trigger = "default-on",
+ k- D% |" {' t/ ]( [' J },
- X( ~8 T% x8 @. X) A {* a! d- b1 W& x: U- E5 b! [
.active_low = 0,
; t( r# p3 [0 h( d, S1 X k, ` .gpio = DA850_USER_LED3,
W% p$ }% f& k! e$ z6 g5 K# W! B7 J% D/ l .name = "user_led3",1 ]- h3 P/ U& [
.default_trigger = "default-on",
?4 H3 K; H3 u% N7 V },
( l2 \$ ~/ I: O};
; U8 i3 ], Z9 a2 _, T" H# s0 i4 X
! M) s8 _. J, j0 h% m3 Q0 l* @static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {) f; G4 Q0 J0 K! Y3 I8 n( A6 N
.leds = da850_evm_tl_leds,
. C% {2 l/ Y2 \ a) O .num_leds = ARRAY_SIZE(da850_evm_tl_leds),8 o, S9 T1 T0 U/ J0 `5 V
};
; ^" ]- w G+ u8 j* x2 W
/ A/ D# V! c* i' @! C6 {1 Istatic void led_dev_release(struct device *dev)
2 ]' n7 G2 F, a" ?{
( R& a: q( D, n; i0 Z* Y};" I$ q9 l! w# A) U1 |( Y
" H5 [ O& B& n7 \- Y; p# [static struct platform_device da850_evm_tl_leds_device = {
$ R/ O0 ]0 A* T. L .name = "leds-gpio",, l. K7 m& t+ \9 H) p9 \$ e
.id = 1,, ]1 f+ F+ W7 M! M7 e/ v* C
.dev = {& R$ v( g& d+ q' {, k
.platform_data = &da850_evm_tl_leds_pdata," e0 }" ]3 d2 o- l
.release = led_dev_release,
. S t8 N5 P0 o8 H; K* v% p. h }5 f0 b4 f. Z: K, B" c
};
' f$ g: {# A! s- v5 O9 z/ f
/ C# U) L- t* y3 {static int __init led_platform_init(void)
9 B# B9 o. \" F% ^{
0 G; m$ p/ m0 b0 i2 `. t int ret;
6 b6 ^' P$ E# h1 [* y5 n* j" w# }/ s#if 0
/ i7 a" u2 e! n ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);5 f% t$ t! C! S6 j' Y
if (ret)' W' l _2 b& c3 b% x3 ^! E; I
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"; V' ~" w8 r5 E2 ]' O* Y. O
"%d\n", ret);: K2 b- b# b. a8 O
#endif: F7 ~3 F! F2 X) X- Y- Y
ret = platform_device_register(&da850_evm_tl_leds_device);
% p! b4 U+ K7 K: B* n5 }) F6 u if (ret)( x% j6 D' n: ]: ~$ D1 P1 N
pr_warning("Could not register som GPIO expander LEDS");
9 y( r% j' r( g; \: O3 R else0 q3 n3 e F; ]. l* G* i6 F" ]; B, M
printk(KERN_INFO "LED register sucessful!\n");% |9 x% \0 ~% b/ i; h# ?5 g! Z
* G* B8 V0 {9 |4 i+ D# h return ret;
- C# F5 i- d, O; ]4 g2 z, K}
/ O0 g8 B& H$ ^5 y5 t7 M
# i, _ B' n* ustatic void __exit led_platform_exit(void)
d" \! g4 w: f' r3 l{
2 P$ i- i6 P- E: X" O platform_device_unregister(&da850_evm_tl_leds_device);6 w2 `" b$ t9 Q8 A: g# }% l
( Z8 p- B7 `* A5 U/ Y& G
printk(KERN_INFO "LED unregister!\n");$ A: m# O- q2 Y( f$ X r
}
, U% \: m$ g$ ]7 G
( c1 Z% F6 @1 E; g5 @module_init(led_platform_init);
* W3 L* R8 l& c: b+ l( Omodule_exit(led_platform_exit);
$ K2 O, F' G: B: B2 D% E+ w% e0 i3 b# @$ r& _" y: n- a
MODULE_DESCRIPTION("Led platform driver");1 H" |- a/ @: s- p0 B% I2 y
MODULE_AUTHOR("Tronlong");3 m8 e6 p, E4 U" l0 j6 [6 X& ]
MODULE_LICENSE("GPL");
3 e- _% {! Z# d& d5 l
! W5 t0 I# Q& a( L/ h C, A |
|