|
|
求大神给下面的程序做注解,请稍详细些,谢谢。9 t4 }" r; C- ^. B5 L0 n3 |
#include <linux/init.h>
! g p9 n; ?6 ^+ k/ F#include <linux/module.h>+ i2 v: Z* C) P3 t/ W! d
#include <linux/kernel.h>
$ E( d' k5 x( v5 S% {7 a" l! k#include <linux/types.h>
! N0 w9 d" B: W. e% A! k#include <linux/gpio.h>
/ \, i# g8 X+ \# _4 b/ k0 g1 k1 E! E#include <linux/leds.h>
2 U `2 R+ z* ]0 h; A- ^#include <linux/platform_device.h>4 [2 Z/ J; w( w6 x
& w& {: ]0 X) @7 U; A
#include <asm/mach-types.h>
. t: ^# v# o" s#include <asm/mach/arch.h>5 U- w" \0 M6 t% C% x
#include <mach/da8xx.h>- K; m6 G/ f# f: y0 p! m
#include <mach/mux.h>
/ O! g& n, M1 k6 S) W( o" y& n! V: S7 a5 R- g1 L
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
5 `5 a6 i( V" |3 S3 w+ [9 [6 i#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)4 t4 Y" ]- r' o" i0 \" g
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
9 D5 @. c% Y' d#define DA850_USER_LED3 GPIO_TO_PIN(0, 2). @ f q5 `' @$ s- b+ ~$ Y
% h8 V3 }1 D- E i* S/* assign the tl som board LED-GPIOs*/
+ _2 g& a" i$ ^8 q; [; s7 Cstatic const short da850_evm_tl_user_led_pins[] = {
/ M. y6 q0 u- k/ ]0 ~ d5 k /* These pins are definition at <mach/mux.h> file */9 X) L1 ]- R# }( f* B
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
/ k! n2 I. v' v" ]9 s+ R -1' |% T, `* Z$ J6 u
};* f+ K5 ^! z/ b( o1 _& }
' N( w3 h& f- G4 S% c" F! `static struct gpio_led da850_evm_tl_leds[] = {0 z u1 ~" D; ` a" |- k/ u9 C
{5 n" O* h" ?6 W! T. g. d. `0 z
.active_low = 0,
/ v$ `' d, b( v .gpio = DA850_USER_LED0,
5 S0 r& R9 M0 Z2 r2 k f& y6 ] .name = "user_led0",
* B9 x4 j1 f* _2 Y% X. o .default_trigger = "default-on",
( ^4 r- G% G% E. {& [7 a },
- w" F0 L2 i: s \4 b1 T9 O) f {9 m% L4 ~$ Z! I% v
.active_low = 0,
% d# W- P# W O; Q .gpio = DA850_USER_LED1,4 s$ `, b' P) T9 U
.name = "user_led1",
/ R- v" k6 c% i( e2 W .default_trigger = "default-on",9 d# D$ Q+ }, H- C& y7 Q9 {3 t* K8 K
},
6 ~5 z, Z- j( K# @1 z) c; M {2 w) k8 h3 {; S" p# H9 p
.active_low = 0,6 j% H7 l ~3 a5 j: _6 `+ i
.gpio = DA850_USER_LED2,& s+ ~! b, ]' y7 M3 \; ~, x9 K
.name = "user_led2",
! q% p- O* M- ?) b" u" D .default_trigger = "default-on",( G) _4 k+ v0 \6 ]
},; Z+ o/ g2 Q9 ^" P2 B w/ L! f
{& Q# O: q8 g: y+ r2 R
.active_low = 0,8 n0 h; t3 K- B5 `5 C
.gpio = DA850_USER_LED3,
" [" n. F) g7 _$ h" ]" G .name = "user_led3",' ~# u, l. f4 m h( c( I. l
.default_trigger = "default-on",
7 j( U+ {, h: n+ K. Q },; p" N8 V- S1 L+ Q# `9 P: d
};
0 v( C" j$ P! V% U/ `$ u1 j& D. z, ?- U) N& E6 s" W" |' V
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {; x6 m: O+ R' _# q" w) f9 c4 W
.leds = da850_evm_tl_leds,3 f4 W( h9 y6 v1 F3 _
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
' H6 R7 d8 h4 q" U Q% g2 s};; l; X, t" I! t. f) O
6 G+ q/ ^! ^/ N, N5 A
static void led_dev_release(struct device *dev)6 q% i, g) n- U/ j& [8 `2 o/ s
{
& l5 G/ u: d& f' I4 Z9 j};/ W) K, }7 t; R/ h% {* ]3 A" S
4 G; n1 V0 z& m6 R0 P
static struct platform_device da850_evm_tl_leds_device = {
5 u2 B' K0 e, y& r* G) n# F& }5 g .name = "leds-gpio",
1 ~, ^- [4 J6 q8 G: @; c- v .id = 1,
6 s% F9 c# t9 Y* q$ @; i; v .dev = {" Z7 s6 o' R3 Q$ ~' G
.platform_data = &da850_evm_tl_leds_pdata, M' Q0 J' S/ ^4 o1 Q5 y
.release = led_dev_release,* |% A' h' Y4 y% h4 @
}
: z' \( x* W7 V' L, q2 p};
& P' y: q5 W8 o" a5 ?- w |& Q/ Q* E7 W
static int __init led_platform_init(void)
( V+ P3 L! E# f# _{- S9 u2 o2 m s' c
int ret;
0 }" [% v8 ~8 y4 {) z, @! q#if 03 T( d. v9 f$ T; A
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);7 q9 t' b+ n. L
if (ret)
) i9 I- b. E( Q. |# q& h+ C$ ^ pr_warning("da850_evm_tl_leds_init : User LED mux failed :"& n t; N I- W2 s. O# i w8 @
"%d\n", ret);
' @7 {' `% B$ ~2 V3 [- I#endif: N" ]9 O' B- U7 H2 m) f
ret = platform_device_register(&da850_evm_tl_leds_device);( F9 \* _+ l5 u) L" M3 E6 j. L( t
if (ret)
/ |/ X: V; l( _3 X; l# T8 \6 @ pr_warning("Could not register som GPIO expander LEDS");6 J9 T' |8 i/ i6 h0 t0 ]
else
6 p! p+ K' p; \5 W" r3 i printk(KERN_INFO "LED register sucessful!\n");
# X5 a- u6 q, z6 ~
0 }1 T+ o" z! m4 c' v4 C return ret;# [4 @9 R) V. H, b
}1 }# C2 M6 K; }. [" @& l
9 D2 s- n; q2 @* ^; o
static void __exit led_platform_exit(void)
- z; O; h( Q& R- I" Z) e. @{/ h4 M; c8 V% \
platform_device_unregister(&da850_evm_tl_leds_device);
+ Q* x) ^8 t& X4 X# S3 j* k3 s. R- V1 u
printk(KERN_INFO "LED unregister!\n");7 S" y I( T+ L j- A* I
}1 e/ P9 K+ Q+ K+ l5 Q% [6 H
) T- Z& ?& D% r: k7 emodule_init(led_platform_init);4 H* J! Y; c5 W2 J; {9 K4 @# s
module_exit(led_platform_exit);$ K N% x0 t( [% e5 Y5 c! w% X
* J0 [( G6 G" P0 T! [7 nMODULE_DESCRIPTION("Led platform driver");
# R- k/ s5 R: M5 O8 f5 _; d& ?MODULE_AUTHOR("Tronlong");* J/ y: j$ t! c( Q0 x7 m3 V
MODULE_LICENSE("GPL");' z9 T$ b0 \7 E5 @! t" g6 [
3 W% O0 W; K3 M |
|