|
|
求大神给下面的程序做注解,请稍详细些,谢谢。0 ^8 A# T6 Y: ~' V
#include <linux/init.h>
, W7 K3 Q# y2 u, H& ~#include <linux/module.h>
j/ w+ Z% h" N; D3 v#include <linux/kernel.h>3 R! o" T6 s h9 C U u7 W
#include <linux/types.h>
- J: c8 Q9 h" W0 P- s v2 B: B4 N#include <linux/gpio.h>
4 }& p% S0 d& b#include <linux/leds.h> X9 u5 ^( j% @/ z9 z# z0 P b
#include <linux/platform_device.h>0 o( K0 j- H7 n* z. Z8 h% L/ N
' [; K, Y$ {4 J# C8 q! {( r
#include <asm/mach-types.h>
: w) m) ?- u: C3 C#include <asm/mach/arch.h>
8 g4 [* r2 H+ D( l2 H#include <mach/da8xx.h>1 h: X: G% U6 c: ]$ }& R: u8 A* e
#include <mach/mux.h>$ X9 D J4 H: g( ]$ o
2 S8 O) B3 K% @9 J+ _#define DA850_USER_LED0 GPIO_TO_PIN(0, 0). Y. O0 F' u, t: ]$ R7 v+ D" U
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)* o" c* x8 P! p- v, c
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)+ v7 ~4 j5 N! x& T- B" D0 D) h* n; [
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
6 G4 N8 e5 {8 |( z
" U$ l( C% Q2 W* A" s' u7 p/* assign the tl som board LED-GPIOs*/
* S# Z) i" X" I6 I Tstatic const short da850_evm_tl_user_led_pins[] = {+ K) L. R6 n! s4 n
/* These pins are definition at <mach/mux.h> file */- p; @, J7 v- c3 _0 X
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
! x/ s0 M( J0 v. v# o4 w -18 j! T- w& p8 J7 v$ C
};# m$ _' ]) ^. v7 c& `
3 E0 h0 }1 k/ K2 v$ k
static struct gpio_led da850_evm_tl_leds[] = {
* ]4 O A. I; ^1 a {
6 j! Y! s g5 }5 @: Q9 r .active_low = 0,! [& R d. O% d r0 I6 I
.gpio = DA850_USER_LED0," O7 r4 b4 g8 R, k3 S: ]
.name = "user_led0",6 \# [) Z& T6 t5 Q0 c$ {2 T1 A5 J
.default_trigger = "default-on",
% r9 U9 J& M4 Z- k) q; i1 X O },) e ~3 D6 ]) j# N, O) G+ _: w# ~% V
{
# y7 v+ p I# H0 X2 G .active_low = 0,
4 z4 w& J+ \! k4 e8 p u2 `4 I .gpio = DA850_USER_LED1,
9 @3 l! H" r4 J* V2 K3 m .name = "user_led1",
- }+ A/ |3 T( H( i .default_trigger = "default-on",7 f* w5 K5 ?4 N& q
},5 B9 u9 t! E& h8 x7 c
{2 m, ?- z4 F1 @
.active_low = 0,8 \1 A4 O0 D* p" E$ C* G, q; c, v
.gpio = DA850_USER_LED2,& E# g1 [ B# }" D: _
.name = "user_led2",' {& J8 b) }/ C U; J4 f
.default_trigger = "default-on",7 V; U; O8 X' G& i/ c7 G
},
) S! m+ `8 \/ d1 Y* l3 ? {
7 M6 {; C( }' Q) Z/ }! G# N .active_low = 0,
I/ v9 X w- N* O3 n% R .gpio = DA850_USER_LED3,
) q; e" a1 w& I: k .name = "user_led3",5 h; y: H$ A j1 N' M/ ?
.default_trigger = "default-on",
3 j6 a4 z6 k5 l+ E( @$ U },
) ]: C! g! H% i' Z};
* Y; C4 J5 t% ]; x) ]5 W, O& G& N* q
( d3 x, a6 g* o- d2 e3 lstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
3 Y8 E- \: m& z% s6 L3 { .leds = da850_evm_tl_leds,
- }: G' \! _) K4 u& u( h: ~ .num_leds = ARRAY_SIZE(da850_evm_tl_leds),5 I! Q E$ K, c/ b5 @% k7 j2 }
};
+ g5 W) B. P! p" Y8 N* _* _# r
5 c; E# y8 I( K8 m8 F- v- ystatic void led_dev_release(struct device *dev)
3 t. H, {5 G/ n; y$ ]{
/ ^, Q2 d) H% ~- f4 d};& \. u. r6 c9 R0 W3 M
+ H' `9 b' j% V; fstatic struct platform_device da850_evm_tl_leds_device = {! T* b7 m1 G; H5 H: M
.name = "leds-gpio",5 A7 _) K9 I9 Z A4 F# U* Z
.id = 1,* f. R5 n5 R2 q: b& r5 {/ o
.dev = {
2 u# T* O C6 I; r% A4 O- B .platform_data = &da850_evm_tl_leds_pdata,9 i7 B. a/ T7 p) |
.release = led_dev_release,
" \* s3 N! t) ^/ b" o }
7 g9 O% O4 z% S7 e! \};
9 y2 V& w6 G; A, I5 ~4 V
) ?7 u3 N1 F9 zstatic int __init led_platform_init(void)
% O" ~) K. n! C1 H, M{
3 D& v+ _) B0 b+ d5 a, o int ret;' Q1 K$ c ]6 N9 U
#if 0
' T& w, b8 S5 k" M' ~ ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);* `2 X5 X) S: ]
if (ret)
% I8 R9 A" E1 ` pr_warning("da850_evm_tl_leds_init : User LED mux failed :"' c, Q3 ?. j1 Q# `' ^7 a8 x6 W% S
"%d\n", ret);) f- F9 V$ f" l5 @1 Z* p
#endif) d7 T' ]4 ~ d" a$ O2 ]
ret = platform_device_register(&da850_evm_tl_leds_device);
+ b4 w& @! w1 o$ q2 E if (ret)0 V9 _% z$ Y0 A! W: n3 U" Q
pr_warning("Could not register som GPIO expander LEDS");
6 H7 ^* }" s5 ` else4 d9 T* X9 J; A+ |3 |; a. s
printk(KERN_INFO "LED register sucessful!\n");, @2 [- I) Z p/ J2 ?# z
$ d5 H" A9 d; D M% ? d, N
return ret;6 o6 f9 Z6 P* i" x( N
}
5 T2 p+ q6 _( x$ Q# e% Z! L+ i$ ~; `/ k0 o: ^/ D; E H& R
static void __exit led_platform_exit(void)
% k5 x) m2 q; Y( h! h- Q{2 K2 _5 d1 C8 U
platform_device_unregister(&da850_evm_tl_leds_device);4 B5 T% {6 K1 }9 p; b% p- p, @. y& F/ B' s
- J/ f6 |9 J7 J* D1 [0 G
printk(KERN_INFO "LED unregister!\n");
3 N7 L: m8 d% `: C+ Q! o. E% r}+ b4 T d, E; g `4 s. f2 ^
8 L' W2 J7 M* n! K0 v0 y+ }* U. l/ x
module_init(led_platform_init);0 l; c3 ?# R8 I5 R
module_exit(led_platform_exit);
9 R' v* L& e6 P& E. ?8 ~9 S
5 Q* f! g0 u! Z: e) @! D- u- xMODULE_DESCRIPTION("Led platform driver");: R: n y3 t5 n- g9 i
MODULE_AUTHOR("Tronlong");3 u; X+ N, Z1 R8 u9 H
MODULE_LICENSE("GPL");( G7 }! D! R! x( c1 Q* [8 [
( ~+ R' |1 r' y& Y8 T |
|