|
|
求大神给下面的程序做注解,请稍详细些,谢谢。* V/ u9 R7 u2 M0 j; c9 O
#include <linux/init.h>9 f# m. e/ _1 }+ G* Z( n8 I% s- e6 c
#include <linux/module.h>0 e5 z) T4 W4 O6 m) q
#include <linux/kernel.h>
. R# v, v0 [2 A" J2 X% H1 e( A/ \, ~#include <linux/types.h>
) O' X; A9 Y6 T7 Y7 x9 F#include <linux/gpio.h>- f3 j4 B6 X, t" G1 Z9 I
#include <linux/leds.h>) e3 ]# k9 @4 Y8 y! A0 @
#include <linux/platform_device.h>7 m, ?- ]6 `& ~! l
2 ^; i0 N5 N! @& ~/ W) ^#include <asm/mach-types.h>$ Q* z" K4 D+ y2 u/ ~1 K4 w
#include <asm/mach/arch.h>
8 d+ e$ S5 ~ i* E' {. r#include <mach/da8xx.h>; `+ }4 O& ~$ D/ h, s0 O
#include <mach/mux.h>
/ m3 ^, C1 h8 i3 ]8 @- O& x! o: J
, ^4 h( j8 D( @7 @- B# E" @; }) |! s#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)" m9 J+ A4 S5 ]# d3 Z3 I9 ?
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)7 j/ D+ O4 m z. r! B3 L! J
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
$ O9 o7 ?& m* u# Z# B) e#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
- A& j. D% q5 w+ i5 l/ b" r4 A8 R* ^
/* assign the tl som board LED-GPIOs*/1 C/ O" ~+ g" w9 {
static const short da850_evm_tl_user_led_pins[] = {% H( N; D) L5 q& }" N% Z" g
/* These pins are definition at <mach/mux.h> file */
$ D9 ^ @2 b% }; W! B6 k DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
; n$ |5 e5 C0 _! r3 T; j- p: e -1
5 A" i. h9 Y# R, Q$ k};4 I' {% M4 c) {% L$ N$ k9 G0 n
+ e; I' r: \9 E# F1 T2 U) |static struct gpio_led da850_evm_tl_leds[] = {1 s7 k" I' x3 Z* p# ]. c6 Z
{
& z/ P* y+ o4 F .active_low = 0,
) F0 r- S5 m/ O, Q0 w: [ .gpio = DA850_USER_LED0,
# I6 r) K* _; y .name = "user_led0",
' }' R# G8 X$ ^4 x .default_trigger = "default-on",+ b' A' W5 O7 S1 @8 Z
},
: g" d" H! ~# ? ?/ F$ W {/ \$ I9 I4 {8 _8 w3 s3 v* C; @
.active_low = 0,! q+ k9 W3 q( R+ O
.gpio = DA850_USER_LED1,
b: G) A. H" p- l3 F5 S& u .name = "user_led1",. H( i! B9 U& X4 C% ?" @
.default_trigger = "default-on",
. H. x G* E) o },
- M; @0 m; M3 C7 [) J {7 i9 Z! ]; Q* e8 S1 i
.active_low = 0,) s0 L4 B( R! Y( y$ Q& F7 _
.gpio = DA850_USER_LED2,: h' ?+ |, J' W$ S* V) ]
.name = "user_led2",+ j7 e: y+ u$ k% a( d v
.default_trigger = "default-on",
+ X- x# @; m1 ~* {& b" r6 M },# g! c/ k7 _$ G( T
{7 T; ?4 H' `/ w2 c" L9 n
.active_low = 0,
6 f f) E& b! A% H+ q .gpio = DA850_USER_LED3,
! S+ O R9 E0 s& i; l; z' H& \ .name = "user_led3",% R$ x! }1 @6 Z" D# `
.default_trigger = "default-on",9 N/ f, t, C* S8 a
},6 c0 ~, Y- T# Q- A l. s. Z
};$ N, ^2 Z* G: T- ^5 P, I! W3 R
: X2 X7 w& y* |1 E1 G0 X. [static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
3 C. p7 U: D* }5 e+ X .leds = da850_evm_tl_leds,* k* M. E$ L; ?. G- s e
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),# f/ A5 |! X3 y7 z" L
};
9 y8 u' Y; I7 F; H3 k9 ^; f
0 y( F) Q. P7 ~static void led_dev_release(struct device *dev)" D: w& D3 n0 S& @3 T1 h5 r3 A- i
{
5 W8 F; m& @. Z' z; X) @: ]! B};( Y, Q; @% g/ N' @. h4 I8 x& |
) E- O! U9 q' y3 F% b5 F6 g
static struct platform_device da850_evm_tl_leds_device = {
$ k1 N+ Y8 e$ r; x .name = "leds-gpio",! m2 o; y& I5 |8 x
.id = 1,0 h1 i8 {* [# a0 U- B
.dev = {
0 x* K0 r4 e; Y: w5 r .platform_data = &da850_evm_tl_leds_pdata,
3 O8 C4 v" q# h2 U% f* K+ Y4 S$ K .release = led_dev_release,
2 y0 B9 u9 U+ Z- |) J+ @' E }
8 o/ e5 \ I8 {$ t f3 g};
( S4 F! |. T& U* I4 r
" L0 t: k$ L# `8 R+ Pstatic int __init led_platform_init(void)
5 I9 M2 o/ k9 d0 ~{. ^6 {5 o2 t! f
int ret; D& w$ j1 h4 ` V
#if 0: c/ ]1 g$ C" d# C8 A6 B
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);! C( M* N/ l% f
if (ret)
% W4 _ J0 A4 q9 Q5 \: E6 y pr_warning("da850_evm_tl_leds_init : User LED mux failed :" l1 _" e: Y6 J: N0 w* N
"%d\n", ret);" a; g- n& y2 B( m7 a4 g
#endif% M- h( {9 o8 c( @
ret = platform_device_register(&da850_evm_tl_leds_device);
- t! n3 ]8 n0 x! _8 ^ if (ret)
4 g; v# z( S6 f' @8 P; C pr_warning("Could not register som GPIO expander LEDS");( z$ I1 X* d, N, Z) ^7 o" I
else
4 S2 Z8 N9 q* r* {9 F5 n) g# a6 e printk(KERN_INFO "LED register sucessful!\n");
4 z, g5 `4 \* g6 u' k
9 p- P" ^' Q2 V" J2 w @( K return ret;
7 O# @# d/ m8 J0 l z" B3 I$ K}
9 B* N) G3 t6 h3 Z k; Q$ J+ E/ @1 A4 c+ r) K& c! \7 L! V
static void __exit led_platform_exit(void)' j: c6 I3 N/ \5 \: R
{# f; E3 f/ I0 E
platform_device_unregister(&da850_evm_tl_leds_device);
* u( R, t. m* z4 y0 ~6 m& k: ~9 C9 f% a, q
printk(KERN_INFO "LED unregister!\n");5 a( u$ f$ C N# T
}
2 I0 e" B- f& e+ Q1 a2 f! M" C" r0 K4 y4 O4 x0 R4 e5 s
module_init(led_platform_init);
0 B6 `3 @ ]5 p( D& b7 T: f5 d5 zmodule_exit(led_platform_exit);
: Y3 A: }$ f0 C2 N* m5 A( d! k% r9 @ x, j6 \+ t+ O
MODULE_DESCRIPTION("Led platform driver");, { w) {, B* k
MODULE_AUTHOR("Tronlong");/ h0 T, M4 n& j4 I% T* \( H* @
MODULE_LICENSE("GPL");- O, Q& B/ u6 _' p' h& j
7 }0 C( k6 R8 T: g4 b: L
|
|