|
|
求大神给下面的程序做注解,请稍详细些,谢谢。) r, W" B5 X, F3 |$ t* o# E) [
#include <linux/init.h>
/ |3 q* S ?/ c6 S2 V4 K#include <linux/module.h>- M ?" L% ? g+ M4 |: m
#include <linux/kernel.h># q* W6 ~& q. `; N/ L: g1 P# |2 C
#include <linux/types.h>
/ q3 {* ~' t! o9 w9 b#include <linux/gpio.h>
& N' q; M+ Z' Q$ i5 W: v1 Q#include <linux/leds.h>
2 \+ `7 k; s M#include <linux/platform_device.h>
: D2 v7 y( v1 J4 i B* R- W3 m
) [1 x8 x( |7 s4 y8 E2 `#include <asm/mach-types.h>% x/ L X, i8 Z0 Y7 a
#include <asm/mach/arch.h>
6 S0 g" H5 i- D1 t9 r7 i+ `' `#include <mach/da8xx.h>
4 P& n. [( l& C6 A#include <mach/mux.h>
# D5 P1 e3 G, W6 i+ f6 B2 @* D9 ^5 W
% W% y: b8 t2 C+ a#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)/ h4 k8 ? s) L
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
5 |( e9 o* F2 W4 t" l/ r F#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
* V1 j5 }) `) Q9 ^- ^0 G#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)# p/ I2 l8 p" T) v8 A) Z
! k _% ~: b4 A$ N
/* assign the tl som board LED-GPIOs*/
: O4 p$ B6 g: ^static const short da850_evm_tl_user_led_pins[] = {' {) M8 X* ^* l$ F
/* These pins are definition at <mach/mux.h> file */1 e. D( q! I1 N' Z
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
7 o# T2 x0 o/ C1 E( o! N* ] -1$ y8 ]* z7 t4 d7 p2 z
};3 r( d- ~, J/ g9 t( m k8 T
2 \; @ j: S( e) b; O
static struct gpio_led da850_evm_tl_leds[] = {
2 `9 x$ D8 T/ Y Q2 G- v9 m {
6 h# U9 i, w: r m7 ~ a5 h7 W .active_low = 0,
; ~) p& Z" Z U) x# ^ .gpio = DA850_USER_LED0,4 O( a, w8 I; F5 J7 I7 K; M
.name = "user_led0",7 l, H5 L4 Y+ i8 J% \1 C
.default_trigger = "default-on",, `: ^" l( ?# A F. i( D! o
},0 o* C8 G' G: [
{6 X* h4 f2 Y4 Y- p
.active_low = 0,
% i0 i% p+ z' |3 y* }7 ^ .gpio = DA850_USER_LED1,' i$ G* [+ u5 x
.name = "user_led1",+ X3 Y* @3 H( O; C" H6 `) T
.default_trigger = "default-on",
" j$ D; M9 g3 ` },( O+ l e A. y8 _) d2 ^
{
7 Y' ]8 ~: o. @2 G$ \0 r' c/ M .active_low = 0,
) s" v9 D- m# U% `0 n .gpio = DA850_USER_LED2,
l- V! w6 r9 x .name = "user_led2",) W* l8 u' n8 z" d/ s6 W
.default_trigger = "default-on",
& L1 I7 e* f- \1 l' s( ~ },$ i. k' V5 I. B5 b! \+ i
{& T$ K* s G6 r; a9 J! G# [) ?
.active_low = 0,, r+ c. O& ?/ D) p3 k2 Z4 p
.gpio = DA850_USER_LED3,
- @& e6 K5 @7 F) o4 h: Q .name = "user_led3",9 T- e3 [ t( P% S% ]
.default_trigger = "default-on",7 E, f8 p4 y( `% ~7 a7 `* _/ H7 `0 h& K
},
m9 O" A9 ~" y" z3 N};
" G ` C% N) u/ c0 d! C5 H' O7 z$ X9 b& d
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
5 a. \) Y) I5 B .leds = da850_evm_tl_leds,/ k3 |: `; c. ~! d1 W
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
% s4 `6 w/ H( c+ E};$ C+ L4 ~- x" ]! L
$ b( u% a# c0 \static void led_dev_release(struct device *dev)
: @1 J$ y# m9 F- S* l% V{0 t/ }* V3 j8 k5 l
};
% M- h9 }/ j; x7 u
* z+ y+ V. ^0 z+ d9 C% Ustatic struct platform_device da850_evm_tl_leds_device = {
) N) U& m9 b' H4 U3 x- w- M5 K8 T3 { .name = "leds-gpio",
8 a% z/ i/ i& g" F .id = 1,: F6 F$ W' z+ g: p/ a0 ^. ]
.dev = {
4 v: c" p$ R; o .platform_data = &da850_evm_tl_leds_pdata,
/ [9 t9 Q6 G& l" @ .release = led_dev_release,! i. T# U: a! b7 |" u& U7 C
}" Z* t7 Z6 y9 a/ {
};( N. [: a, ?. Z ?2 t& o# u
% @! \% z1 }) P1 [static int __init led_platform_init(void)- I; H- R# G" H4 m
{
! S$ P% V+ W' Y' p w- A int ret;
6 W/ {6 V* _) I6 Q P6 q/ X+ h#if 0
/ ]( t9 Y+ P$ M J- X! b5 Q8 o ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
+ X8 f( B+ v- i _- h( k if (ret)
! i6 F: u9 K! P/ J5 Z" _$ ` pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
1 T( Z$ o8 T& Y# [ D- I "%d\n", ret);/ v, b. Q" C& C. ]$ t
#endif7 R) k& U; } e
ret = platform_device_register(&da850_evm_tl_leds_device);& k l0 l( f2 \" w5 @
if (ret)' o4 A3 J" S; n3 Z E: E* b' ~4 {
pr_warning("Could not register som GPIO expander LEDS");' B4 r8 o1 Y- j! T8 y4 B8 m
else3 K' d2 v% f9 a% V0 o6 x' S
printk(KERN_INFO "LED register sucessful!\n");/ Q; `$ f4 h$ G. b9 y/ m1 L# a9 j2 R6 R
9 y( h7 G- B' f return ret;
1 Q6 L {2 K5 ~- s3 S6 j}
7 \5 b# n r5 p5 B8 p2 b
8 Q4 a( u! ?% H. }( a9 P" kstatic void __exit led_platform_exit(void)8 B4 T5 u4 f1 a ]! q9 A f. A
{) l6 x" q+ n5 b% k
platform_device_unregister(&da850_evm_tl_leds_device);
: ^! c/ x+ j, Y# W
2 D. _$ b) ^( o3 P1 r) o; Z, j printk(KERN_INFO "LED unregister!\n");* U+ i3 j4 R0 v5 ^
}, x4 W2 s' J( U) C1 f
' L6 j9 V; D dmodule_init(led_platform_init);
* b. d. S. `5 b( Dmodule_exit(led_platform_exit);& ~' \9 ], J$ z
7 d$ m( J8 ^4 Q) _5 k2 b6 p! x
MODULE_DESCRIPTION("Led platform driver");
1 \! E# V, I8 Q& PMODULE_AUTHOR("Tronlong");
% h. y( @: L7 @4 n/ p; \MODULE_LICENSE("GPL");9 g2 V! v% Q; c0 h4 ^7 C6 d
1 H# a$ `3 E# r( w0 P* P |
|