|
|
求大神给下面的程序做注解,请稍详细些,谢谢。8 W8 K. m4 C" }7 p4 p& _9 O( W
#include <linux/init.h>/ m& j7 @6 O* }; Y
#include <linux/module.h>" a# x/ q1 ~6 z6 i, r
#include <linux/kernel.h>
( @6 D& J- B5 G/ ^- }#include <linux/types.h>
" s, p& C3 S8 m8 W; R#include <linux/gpio.h>3 t/ U, v* H! }
#include <linux/leds.h>/ u1 p, v3 E `
#include <linux/platform_device.h>
$ i$ G! S& t5 r& l; `, ]+ H+ Q5 R6 |3 `9 x! Z- w6 h! L# z
#include <asm/mach-types.h>8 o3 I" W) E: }3 r* ]) i0 y4 h
#include <asm/mach/arch.h>
9 C2 Y. K- X1 y7 J4 @; D' r#include <mach/da8xx.h>
9 _( u+ D/ d, A' z0 b3 r) E+ u% G#include <mach/mux.h>+ f" U6 g6 F8 l* m% X; _; s1 ~' I
/ K) E* |; X2 i#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
' p5 f3 r( Z' f#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
& z0 f3 G U( N5 c, Q7 }4 _2 y#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)/ v5 H- L( k# w0 }# w
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
% p* z* [; x A+ R% e# f
- L( k* r( v9 f' p: J. p5 C/* assign the tl som board LED-GPIOs*/, Z: A7 j4 r9 D, w6 e
static const short da850_evm_tl_user_led_pins[] = {4 |" _1 i1 y0 i
/* These pins are definition at <mach/mux.h> file */9 ~& ^' Y3 ]+ U1 v
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,7 d( z! R2 H+ N5 d9 u6 X
-1 n' o4 d' f4 j& p
};
+ O1 O% |7 n: \# |% B
& M1 T! U c/ k8 }! bstatic struct gpio_led da850_evm_tl_leds[] = {" ~8 `! A" r3 g6 l3 Z* Y: }) Y3 v b
{/ z& o4 a. l9 H' o% k, Y' |
.active_low = 0,& x0 ~' ]: X6 C$ }0 ]
.gpio = DA850_USER_LED0,; z' T6 M& E4 ]" ?
.name = "user_led0",
7 l/ ^, z* w G+ G+ x% K; J, q .default_trigger = "default-on",
5 a# n1 `& y- k6 s" } },% I2 j. N3 F6 N& ?) W6 X
{
1 Z7 m: q* o- ~7 P5 U- D$ q9 F .active_low = 0,) X* t; x) \& H- O" K+ b
.gpio = DA850_USER_LED1,
6 w/ _# |7 }' \7 B# ^7 s .name = "user_led1",: r$ E2 p ?* h& K$ G* e: O
.default_trigger = "default-on",
! B0 ^. j& C1 A5 \ },
. h/ }9 o4 A! W% | {
4 K; _$ a( e6 {1 Q" \; L2 t. g# b .active_low = 0,; p+ O# Y9 N) K7 h3 i7 C. g
.gpio = DA850_USER_LED2,, v+ \/ X- {" o: f
.name = "user_led2",
C/ t3 R/ X; s! s* B .default_trigger = "default-on",
8 V; o( H+ S3 y* R* }6 u },
# p& [ D" R! u! b5 b/ k8 L {! m. E4 @ |2 _2 m" R6 N; G" l. U( ]; R
.active_low = 0,
A# s$ A$ ~8 i2 x8 j! n .gpio = DA850_USER_LED3,
5 Q4 Z5 x, R/ f, |3 \% k: ` .name = "user_led3"," ]7 @: K" ~9 ]2 G, g# C' A
.default_trigger = "default-on",& K; e! j, M8 H8 K. _4 s$ C5 Z
},, ]) _: j0 g! | w- ^5 v
};- }& b" ]8 s( R& z+ ]3 }! m% _
9 Q' \3 p2 ~* H* ?, c; J6 A
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {- K& U) Y9 ~2 l' J# c4 s3 x
.leds = da850_evm_tl_leds,
# v1 v0 B) ]" `, k/ O( N .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
: z( z5 W3 \* ^};
6 L E/ P! f, |5 ^% P6 F
! R6 W: K {! \0 z4 w2 ?- Fstatic void led_dev_release(struct device *dev)
& Y4 z3 b0 g$ T* ~% n) \1 G{
2 p! |* }0 y) H( H4 t4 ]# n1 u};) a9 |" }! D/ R! w3 k7 r
$ v+ P3 _: F9 t
static struct platform_device da850_evm_tl_leds_device = {5 {5 v K! G' W4 } w o
.name = "leds-gpio",2 i# B. G, J e- U% x; x- R- w
.id = 1,
$ q! k5 x6 f/ t- B# X( n# l .dev = {
. E+ S2 f8 c& P .platform_data = &da850_evm_tl_leds_pdata,
$ p% t* H. I( f/ E+ ^8 H4 S .release = led_dev_release,( O$ I. ^2 M4 {) z# I( d
}
( p5 z9 t* f5 g};
$ l9 B* J- g3 {% S4 c3 L* w$ G9 \* C' N3 v7 I2 |; ]
static int __init led_platform_init(void)) e# G5 w( D+ h2 w! V. M% P
{
! B7 y2 O0 g! m: X/ T/ H int ret;8 ]8 S' ?1 a2 r' ?. T1 H# F. \
#if 0
2 w* |7 i7 j+ r7 k ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);5 u C+ |) Q: G8 Q' M
if (ret)
& U: w9 x* g* z5 d+ s7 h pr_warning("da850_evm_tl_leds_init : User LED mux failed :"1 F. W& H% b& p, d* D; n, f# X
"%d\n", ret);
3 M6 ]4 {4 I9 ?& ~! s4 _; t3 m- H#endif% z# N, N. U5 T- Q# F
ret = platform_device_register(&da850_evm_tl_leds_device);6 S" w' m6 p1 F/ \2 x# `/ y
if (ret)1 g+ N2 M$ h. g* t# W" m# M7 x
pr_warning("Could not register som GPIO expander LEDS");
7 ~% P, H5 Q" S* V, Z) T. X else
( Z2 {1 I: @$ I4 j printk(KERN_INFO "LED register sucessful!\n");6 ?8 p+ t* p% Z2 Q3 e5 L0 I
4 {2 H& j- [! s p# h return ret;
9 G" [: v8 j0 h: H$ z) ~: w}: p2 l3 t* R# P4 `% J0 n3 a
& n0 y) j; G6 O3 b7 \! X* Astatic void __exit led_platform_exit(void)9 g: f. T( T% [
{8 ^ {* n* N$ B2 K5 J
platform_device_unregister(&da850_evm_tl_leds_device);
. l h( f9 a- [2 I1 p# x* ~8 k5 \1 n% h
printk(KERN_INFO "LED unregister!\n");
: }8 v( D: x& S5 x1 ^, C8 \9 u}
- k. I/ @' Q& [* F- p
, M2 q3 V1 e2 r9 G% wmodule_init(led_platform_init);7 p) t" m4 I; w2 L
module_exit(led_platform_exit);
" v' ]% X) W1 c3 ]% o+ S4 ^; i V/ { Q& r
MODULE_DESCRIPTION("Led platform driver");
; ]; w$ B1 w% {8 cMODULE_AUTHOR("Tronlong");4 P" h5 d; H! Z5 V
MODULE_LICENSE("GPL");
! J+ Z* N' O- ]2 K4 j3 g
3 @4 X/ _0 J5 J |
|