|
|
求大神给下面的程序做注解,请稍详细些,谢谢。1 v" G4 J7 n: M+ s" S* f
#include <linux/init.h>; c$ J6 |( l0 T' q4 ^( Q& D# R
#include <linux/module.h>
( i4 @" f' }* c* M#include <linux/kernel.h>/ G) G: |( L+ g. B9 k" ]
#include <linux/types.h>5 y4 E3 h% ]' r0 {% V& B: y5 K3 @
#include <linux/gpio.h>
! b* L" E9 F" x1 F! d9 F1 p#include <linux/leds.h>
+ A, o& A' X0 n, G! F#include <linux/platform_device.h>
" I3 C" B5 B+ l" w) f# d! f2 L- Q4 q1 s$ e3 E8 Q) Y! Y
#include <asm/mach-types.h>( P$ C& k: Q3 R" | X
#include <asm/mach/arch.h>' N9 i2 z W& M- j5 m
#include <mach/da8xx.h>
2 u6 ~9 Z/ V0 [; ]( }/ p9 Z#include <mach/mux.h>5 I) K/ Y) r5 q8 B8 p: t% J
N5 }9 g! b9 b( A9 T9 ]/ w#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
4 S2 l' d. M+ A' }$ i0 T5 R# i#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
% [6 W1 x3 ~* z. L" A#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
# C+ q; j! t9 q#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
* f0 \' I6 B. N# i, |2 Z
! l. f8 c' ]2 S1 w4 L& o/* assign the tl som board LED-GPIOs*/# a; L6 k' F; p3 V! [
static const short da850_evm_tl_user_led_pins[] = {
& k+ f, }/ U* n( _6 b* i+ ? /* These pins are definition at <mach/mux.h> file */
/ L, `2 K F( a( @! X, V4 K DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,; Y( P* ?# F8 _$ S8 ~
-1. Y1 \1 S1 U. S5 p0 o
};
4 t% q$ f( @3 a( C4 F: ?$ ?
3 t) ]1 q2 `5 Q" o* m7 m6 Xstatic struct gpio_led da850_evm_tl_leds[] = {
9 P! a2 g7 E0 c6 v) Q {
" T+ o( [ f/ |) P2 R' \8 _ .active_low = 0,1 ~" |4 }) U% P) Q
.gpio = DA850_USER_LED0,
/ \" E' h. G/ r .name = "user_led0",* Z+ U! ~0 g: r/ f! H d5 @2 ?$ a
.default_trigger = "default-on",
% A3 i9 U8 M2 O2 v4 B) k },
* y" `' i2 b- {% O3 s: V8 A {9 H: o# V! y& O- V' e% l/ ?7 f" \
.active_low = 0,
& ^3 P- _6 [5 {! h: a: A .gpio = DA850_USER_LED1,
$ v5 ] x( v' T6 T, d/ ~$ E8 a' U .name = "user_led1",
. l+ S( s; h$ G1 s5 r .default_trigger = "default-on",
( v( B: a9 N: _6 e1 J },
/ u; _* n8 A8 x4 t {; g% z+ [1 x2 Z& r! J
.active_low = 0,1 d' ^5 ?0 w) \, e; h8 m1 X! |
.gpio = DA850_USER_LED2,0 @8 [+ a& ?+ U
.name = "user_led2",2 S1 s4 ?6 p' ?9 U0 _& n$ q5 P
.default_trigger = "default-on",7 Q N! ~7 g% n R! c+ J% C7 D
},
% H u! K. D6 O1 ?6 l {. I. K5 |( M, U
.active_low = 0,
" H% ?; |- z/ `8 p+ i* Y0 \: ]- { .gpio = DA850_USER_LED3,% E" `) n. q+ T. x7 j
.name = "user_led3",/ N, i% R/ G/ W( v( ~
.default_trigger = "default-on",
' G% I5 M% c+ f8 W3 j },
9 k9 `. k" f& L};
) P+ i' f/ e0 P( ^+ K4 [+ g3 {8 m, r+ b7 U, [8 A
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {+ @) F3 [' x7 ^. X2 V
.leds = da850_evm_tl_leds,. k2 i/ G# n$ T
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
% Q5 }% C0 D2 D9 V- y};% k4 R6 j' H c; G% D" }
( J8 u- y$ a2 xstatic void led_dev_release(struct device *dev)
4 F' i9 }# p9 B{
- S' h$ d5 A6 S- x};7 c: W" w& x) g. m4 Q5 E/ N/ o
4 L$ i7 v, _- h" _
static struct platform_device da850_evm_tl_leds_device = {+ b& s1 O4 C' C/ J
.name = "leds-gpio",
3 p Y5 b/ i, ` .id = 1,
! ^3 ?: M. H8 L7 R .dev = {5 j ]( s$ o; G0 J+ N2 {# y
.platform_data = &da850_evm_tl_leds_pdata,
, n, [7 ~8 Z2 K .release = led_dev_release,
! d8 e# h: g9 h }1 P' U" L- V- u2 B0 n6 B
};
7 j% D0 K( \( z+ ?$ M u
7 ]2 Y) a4 o: a! Xstatic int __init led_platform_init(void)
3 T: ?% }' K: \" _{8 f {1 N/ r! r0 d
int ret;
8 e2 k+ o7 K3 j9 j#if 02 i. p& W( |/ w* y, h1 @ N4 @
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins); C7 A% o& x+ S0 n: l% L
if (ret)0 z+ G; S, X r; c7 b; O
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"! W1 E/ t; z! K. e, U
"%d\n", ret);0 j) d" {* L+ }2 y4 r
#endif
" D; ~ h2 n, I8 W9 F; _' H ret = platform_device_register(&da850_evm_tl_leds_device);
3 T3 v% q( v. n3 Z" J if (ret)
0 l$ m& x5 [6 O$ C3 s3 ~1 v pr_warning("Could not register som GPIO expander LEDS");! u$ C1 j1 h9 P0 x
else5 e( E! m& Q& @/ h8 {; p% {
printk(KERN_INFO "LED register sucessful!\n");% a) [( j8 B5 Q
- x+ h8 X2 i# B: ^& V3 D# b return ret;
0 [" W, G+ f* r. L! x: \6 c}
: C- ^8 k& `+ f; @; q) B) {
6 l5 q* \% l! U' M: k) w5 Ystatic void __exit led_platform_exit(void)
: d5 j% q6 y6 p2 H{% ^2 f9 A. ]) j7 ]6 T0 s) F _
platform_device_unregister(&da850_evm_tl_leds_device);
6 X) [3 c* I" h P$ s' H& L6 p1 w. Y! e8 k! i% {$ G
printk(KERN_INFO "LED unregister!\n");
3 n& P- A" V7 x}/ p5 H' e6 i. @* m& i! I5 D
$ [* |. c6 ?3 a& p* V" _6 N4 I: Y
module_init(led_platform_init);
# ~# i+ J4 N( E- S( [module_exit(led_platform_exit);! X3 E8 V: b1 b+ }8 H1 s8 t Q% T! p
: _, \, ?# `! I4 C' J6 K1 L
MODULE_DESCRIPTION("Led platform driver");! S. |+ G! i) T3 k6 B) A
MODULE_AUTHOR("Tronlong");
; _3 v) {1 |8 h4 Z, UMODULE_LICENSE("GPL");
: I! ]- J5 ]2 i
% @8 @2 q1 y" j# Z |
|