|
|
求大神给下面的程序做注解,请稍详细些,谢谢。; ~7 M; i9 Z2 r! S3 c2 W: A( F
#include <linux/init.h>% Z% h5 m2 ^: m& s& }7 l/ o
#include <linux/module.h>9 }, n9 |+ K, H- B: j6 v0 ]
#include <linux/kernel.h>; a6 d5 \5 w0 ^$ F) @6 [
#include <linux/types.h>2 h, Y$ j6 J% K) E# E8 g# O V
#include <linux/gpio.h>
- q9 U: q4 I* I7 ^9 G1 Y#include <linux/leds.h> G4 j# ^% e% K2 N! B. z
#include <linux/platform_device.h>
& t+ g, C- u$ R8 Q0 Y+ ~& b5 Q3 ~& W5 F$ d
#include <asm/mach-types.h>
: D0 P$ L6 K- N" b8 z7 B#include <asm/mach/arch.h>
3 J0 H) A# h( t1 P% M. W' I$ @, Y#include <mach/da8xx.h>
' ?. m, @( x8 D# y! B#include <mach/mux.h>$ I0 B+ P2 }( Y- w
4 G* |2 L2 g$ Y% g' G) w' m+ t
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)8 K! d" `' ~/ Q$ x
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
% L% P2 R% w; N5 b#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
4 k" F2 n) N' f& o#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)5 E t& \1 {: V5 y+ ~! K
5 `6 j, L! H9 c% D* ?9 Z- w/* assign the tl som board LED-GPIOs*/
4 T, ^! [: e. @* j' kstatic const short da850_evm_tl_user_led_pins[] = {
' R0 p" O5 U6 B6 I3 a /* These pins are definition at <mach/mux.h> file */1 _7 C+ @ H# u) U- Q
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
' q6 p8 M7 P: {: e -1
; t& V7 F) J8 ?' M2 W; u7 u' W};
2 ]: P# L, E7 f' `1 H0 Z0 X/ D! ^* Y
static struct gpio_led da850_evm_tl_leds[] = {
- x. w& F$ M9 x* @4 O, E( N) F {6 [' a2 p: T$ s S
.active_low = 0,
+ c. s4 o& \! \) G. i M .gpio = DA850_USER_LED0,/ W: x0 d( ?* V
.name = "user_led0",/ ~, Y5 N9 T8 J: x5 M0 C( f4 j
.default_trigger = "default-on",
, n0 ~7 Z: Q" A; \, t. Z: `' N },
5 t1 _: W/ {5 l {* L1 @2 c ]2 T) }( N
.active_low = 0,' B0 e/ V+ u5 d
.gpio = DA850_USER_LED1,
7 J7 Y7 y l) a% e3 `, z7 z( A .name = "user_led1",0 U, s* R9 T/ M3 L/ K* G! P' U
.default_trigger = "default-on",
2 V; F7 J# ^+ v% ? I },
5 w% Y, X) t$ _; I {+ i. I F. K! O; h P5 r2 o* @ W& C
.active_low = 0,
; h, G! ]% }+ T# k1 c6 [1 H3 k; O .gpio = DA850_USER_LED2,
* H4 @- e3 D% ?' r# ^0 N* K .name = "user_led2",
4 b9 n6 }5 W( Y .default_trigger = "default-on",
, b; K, D: c8 B' y8 [+ \2 P }, H1 e. Q/ ]; Q2 E+ @
{
, D% p$ H% e4 ^" \' `' s .active_low = 0,
% H. F* d6 q% z0 M1 i; O .gpio = DA850_USER_LED3,8 W4 L& N" c6 y3 V" n8 L: [. `
.name = "user_led3",
2 k. J8 F Q4 M* [4 U/ h7 @ .default_trigger = "default-on",. }$ \, d: J+ [0 V v$ Q! f) C
},3 T" c d4 b4 Q( [% `7 B0 C; w
};
! ^) \1 t y. a3 `4 K! B: }1 v) j/ a& j& x$ r2 }
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
) T2 M! o% c) J% ~8 }7 f9 H .leds = da850_evm_tl_leds,2 z4 A; U+ r y& S- S
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
. M$ ?" F7 Q8 D2 J' p/ q! s S};7 a: b" |+ z% t
/ T$ c$ C$ }4 H& p# }/ h. ^. p2 [( ]static void led_dev_release(struct device *dev)
0 w: z$ I$ F# b1 F7 y. X& t{4 ?0 |, N& \/ R0 D( _# `
}; A" m H; H1 V+ W: A3 J% @. C
/ R& z, C# H% ~static struct platform_device da850_evm_tl_leds_device = {
3 T3 A2 T! b! T! D- w .name = "leds-gpio",5 f [. K& I! r1 r' \. ~' x/ l
.id = 1,
; r/ H& U: ^* U3 I .dev = {
( g* N/ {* a) n$ o, u6 } .platform_data = &da850_evm_tl_leds_pdata,3 g' G% s8 K! @* |1 q6 Q" Z
.release = led_dev_release,
8 U. ]2 J6 S6 L/ Q: E1 C }
& _; }, W- c! x" X};8 E4 z& u- D) d+ X- X' e# I
( Z9 t' v. Y3 {6 k) Q! M, F0 d
static int __init led_platform_init(void)- l, Q+ ~/ b6 \) a) K
{& c( Z- g' M( U* i
int ret;
: V& R* y- z+ q4 J* A- }, V b#if 0
0 m Z: Z; G. U7 p$ K( T ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
8 Z" @7 i- C4 [4 X$ C) e* x if (ret)5 \( N6 B4 C. v5 k7 \. n
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
: i6 N; F8 X/ A; y; e "%d\n", ret);3 a/ b- T: e7 o
#endif
0 J* Q9 A- I( [7 \( S9 ^' x; ~4 Z2 B ret = platform_device_register(&da850_evm_tl_leds_device);0 G8 V& y% `+ [* q
if (ret)3 ~/ @( N, n3 z" |
pr_warning("Could not register som GPIO expander LEDS");
& a% x; g6 \1 w else+ G/ w7 K4 L1 s$ ^7 g* x$ Y
printk(KERN_INFO "LED register sucessful!\n");
0 E7 ~# |7 K. P, |6 {; \$ q' a+ Z, Y" a! K+ j V
return ret;
: r) b8 d7 } _7 |) ?: Q! b& t}
7 q8 V9 ^+ [" f3 P& y, v( ?1 `
4 i, I% ~3 }0 \: {9 istatic void __exit led_platform_exit(void)
% Q- h- v0 U1 G# U& c( w* N{
) g1 d/ L* Y, @3 c+ m platform_device_unregister(&da850_evm_tl_leds_device);
- q" G! ^: T5 Z: N% r
* j E+ l, d- @% k* R7 G printk(KERN_INFO "LED unregister!\n");
. N0 G) s% J5 c}
7 p" Z5 d+ q, M l1 c# e' b- i$ W
5 z7 v; k Q! e( n) t$ L# R7 Gmodule_init(led_platform_init);9 |' G: N' x& j5 {- n5 Q
module_exit(led_platform_exit);/ c% A7 A. p3 M5 ^6 s. F: f+ K2 P
- q- \5 [% c( b* w3 _" @5 P- l* T
MODULE_DESCRIPTION("Led platform driver");
. U+ c5 c: [) |* [MODULE_AUTHOR("Tronlong");
[4 f) z( P9 @MODULE_LICENSE("GPL");, O" a3 s4 a2 ]3 ]( U! G
$ ~( Q. Q$ c \, a2 b, B |
|