|
|
求大神给下面的程序做注解,请稍详细些,谢谢。1 }3 k( y& S/ E# E: ^
#include <linux/init.h>' o, t$ E! y+ x1 ]. d, o. H( x
#include <linux/module.h>; a) Q* ^! ]1 R
#include <linux/kernel.h>
7 ~" t3 ]/ F) I( H( C#include <linux/types.h>
- ~% R/ y" P1 F#include <linux/gpio.h>5 w8 ^& R. U3 l. l# \/ b
#include <linux/leds.h>
8 s$ M4 \7 Y! o8 s7 v2 N3 @#include <linux/platform_device.h># @9 _, C, H! u, |# q8 X& k
6 D6 I& {& |: g- g9 Y: }- I
#include <asm/mach-types.h>
% n I. Y" ^; i# i, P#include <asm/mach/arch.h># o: c- b' S( p# @- X
#include <mach/da8xx.h>2 J c. {' @# w5 Y' ^/ L l- e
#include <mach/mux.h>' B1 c4 D; M: s6 p# y# X
M; {: p7 R1 u- j
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)! d7 ?+ R3 c. X R$ \3 D" ~
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)! I2 y9 i3 I) N. S2 b
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
/ b$ a; D0 T2 N#define DA850_USER_LED3 GPIO_TO_PIN(0, 2); { ` ?3 Y* ]* ^* v. |
9 k4 K4 H/ I3 \8 s# G/* assign the tl som board LED-GPIOs*/
; i# y2 a2 S P* c$ J9 r" m0 Sstatic const short da850_evm_tl_user_led_pins[] = {& t( z; N4 P. F5 K
/* These pins are definition at <mach/mux.h> file */
% Q+ v( H9 H1 U$ L* D% o DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
6 c6 ~6 G' x( k& V. u4 i. j -1
8 L* L6 n! T7 u; ?};
- W* V8 j+ S' q. M
3 y2 e6 ?* y4 O' l7 Y; ystatic struct gpio_led da850_evm_tl_leds[] = {
9 a# W' I7 [; h4 d {
% g: Z2 K, X, Y9 ` .active_low = 0,. R4 x8 I& m3 h. P5 X' C
.gpio = DA850_USER_LED0,
. P3 A) S- `' C+ T: W- L. B .name = "user_led0",* f: f1 B( x1 C' v
.default_trigger = "default-on",
2 D5 y8 ~( T! w },: w1 p4 ]; v: o' N& X
{
4 O3 G r1 S$ M9 w9 q$ j .active_low = 0,* |6 P* D- x1 d# N
.gpio = DA850_USER_LED1,6 M1 J" F3 W3 Q# V% v
.name = "user_led1",
: S* b4 y) `: p* ]6 l: Z .default_trigger = "default-on",
' A8 K: Y2 g% e Q7 I0 O: F },
9 o/ R. |) N1 J* Y. w( N {) F; A1 |) ~% [9 {) }+ J1 m8 l
.active_low = 0,7 Q/ I& V" ~9 d; H
.gpio = DA850_USER_LED2,; u; r; O. V0 C, M
.name = "user_led2",
7 U* w6 x5 P7 `# {* u g .default_trigger = "default-on",
8 ^; ?: |0 S4 @' |, s5 D },9 S8 Y Y" T& M0 z
{+ u0 Z5 J, l+ p5 K3 S
.active_low = 0,
5 H# A* K, N% V/ t/ v .gpio = DA850_USER_LED3,3 J% S# d( s# W$ `
.name = "user_led3",
2 W4 ?2 {3 U8 h0 n: [9 W6 W4 \8 b .default_trigger = "default-on",
! H8 w! K- I+ g A },
7 Y2 L. y$ o) M/ Y9 x};
5 y; c. h* ]: |8 a( Q# `4 _8 G7 M3 Z" e: L# j5 m9 u
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
% Q; h1 T; S" G# W .leds = da850_evm_tl_leds,/ f k# u9 k. R, l; G8 D
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),! a& { e/ Z7 R
};) A" Q" u% S0 S' n+ I9 S+ P
: Q8 R) X) h }9 P' X3 y
static void led_dev_release(struct device *dev)% y* \+ P& }5 o
{
: N) f: F3 t8 v8 X3 Z0 e, d};5 l& ~' r: F6 L' ]0 [0 x; Y2 s+ g
3 ]6 t5 ?: M$ X! ~, C% G% ]; E
static struct platform_device da850_evm_tl_leds_device = {# s+ @9 O3 F k# V6 ]# Q
.name = "leds-gpio",' w5 O4 }. A8 j; W1 O
.id = 1,. L: B) V ^/ ~6 W8 @7 L+ N9 p8 Y
.dev = {
, ^9 f. F' _6 F/ P7 y# q( u @6 e* @ .platform_data = &da850_evm_tl_leds_pdata,$ G6 d( c/ m3 h8 _+ I. K
.release = led_dev_release,
3 O; l& _% T0 s `' J* e4 u } }! l. F; w, q6 b
};) _' g O! j/ l. z: d# T6 u& ?* f( x
8 G. `; J7 x8 _6 ~static int __init led_platform_init(void). u8 j+ k1 Q3 \4 G4 {" ], h. j! x
{) m* v. w9 J6 z# k5 l
int ret;
6 U+ E% W$ t% X3 y# q#if 0
6 }: ~& q1 u- e! y ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);* I& f6 O& X% P. R9 T4 b$ H3 f. b: T
if (ret)
5 T3 I, P: d# L. F) A pr_warning("da850_evm_tl_leds_init : User LED mux failed :"' N" I0 C2 s% r$ a* a% H
"%d\n", ret);
! g3 P* m# z5 f* y: K2 S3 q: j#endif" j2 ]7 ^% G5 j2 w! S
ret = platform_device_register(&da850_evm_tl_leds_device);0 E4 ?5 h8 D4 \
if (ret)
$ L! j% ^9 q. A6 L0 H, r3 @ A pr_warning("Could not register som GPIO expander LEDS");
* d! z! \' {! t" _: X0 c @# K3 k else
( j* y3 [" J: J printk(KERN_INFO "LED register sucessful!\n");
# I4 A8 k* r% P1 N+ W& b8 B" n. h, y3 P! e6 C5 G& n' J- B: d
return ret;& A5 @5 l5 V5 Y1 `( b
}# }6 `& ~/ N2 F8 [+ E8 N* h7 o/ d
# s% P5 @' i4 ~3 G. X" p
static void __exit led_platform_exit(void)% \. o, K4 O { f6 S0 W1 x/ k8 |! {7 N
{8 ]& j- Y! ^( \% u% D* P1 g
platform_device_unregister(&da850_evm_tl_leds_device);( M _3 i$ d. G, n
9 C3 |" [* D) @) D' a- b3 x
printk(KERN_INFO "LED unregister!\n");
. Y9 @9 S1 G7 n7 O}
* c# V4 H+ q$ ^6 s! R$ T7 F j# ]( T( }# ~% h- w, U( G5 P: K
module_init(led_platform_init);
6 ~4 a! O% \* H, b3 gmodule_exit(led_platform_exit);3 p8 J( b' B* t! Y
. E8 r( \ O# ?
MODULE_DESCRIPTION("Led platform driver");% q0 \3 P# f2 M$ E* g' E
MODULE_AUTHOR("Tronlong");8 D: T) _: H. |" C: ~. D- ~+ n1 S
MODULE_LICENSE("GPL");
) k, n3 B9 l) ]& @. Y+ ]- [
( j% B m9 k% B$ Y" j |
|