|
|
求大神给下面的程序做注解,请稍详细些,谢谢。. f+ S5 w3 r5 K0 H- Q
#include <linux/init.h>
# l/ o1 G9 a2 L. S0 r/ F# ^#include <linux/module.h>
9 y+ x- ^. k q+ |( ^#include <linux/kernel.h>
$ n. I0 Z# E+ t8 b#include <linux/types.h>
0 r" E5 v; h! n7 x0 U* ~#include <linux/gpio.h>: Q% A5 p0 o5 Z
#include <linux/leds.h>
2 }; C3 m2 }2 P8 b8 X* O* b#include <linux/platform_device.h>) T* ]) f4 e8 R( L9 {' S* x; k% T
/ B( Q1 x S1 S- s/ J#include <asm/mach-types.h>. t) ^" \( `$ L3 e0 A& n( ]
#include <asm/mach/arch.h>4 ^- }$ W0 V0 u! c2 U( d
#include <mach/da8xx.h>
3 u2 y2 i. B0 s2 ^. K3 M#include <mach/mux.h>7 j( Y7 c- ~ ~* u" c
" T0 \8 v' y7 C+ V5 v
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
. o; x5 x$ H! s: \- Q#define DA850_USER_LED1 GPIO_TO_PIN(0, 5): [% Z6 q* y. P2 q, e$ s
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)7 p- K% J" i( w5 {
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
2 [0 N; |9 h8 x( B, I# W; D# I% B' u) @7 y
/* assign the tl som board LED-GPIOs*/+ _# B8 J" O3 p& ] n
static const short da850_evm_tl_user_led_pins[] = {
& h; x4 E1 m q4 y0 H /* These pins are definition at <mach/mux.h> file */6 }( R/ Q% b# u# n: {
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
$ l0 @! [% Q) \. R, ^4 n/ H2 l Z -1
) S, T/ w6 X/ K+ S ?};
* P, C1 {$ t( H/ k2 \' R6 B
) R; Q2 W1 x7 Wstatic struct gpio_led da850_evm_tl_leds[] = {
6 }0 {) m# |1 a" ~+ ^ {) K) W5 E' H8 g b' X6 t- J
.active_low = 0,1 Z( V! ?; E( a( V u7 u: e& [
.gpio = DA850_USER_LED0,8 A$ y, W) X% V4 Y& }( L
.name = "user_led0",
. ?, B! k/ E% y6 Y0 \* ~ o .default_trigger = "default-on",6 ~8 j1 ^; B0 d3 X
},
3 @5 y p! j( e: } {4 H* U0 ]9 M( T0 l+ F
.active_low = 0,5 R3 J& _; v( Y" y" q
.gpio = DA850_USER_LED1,3 @4 C7 |! ~' x& _4 ]
.name = "user_led1",
' k" B O6 _* j3 x4 J .default_trigger = "default-on"," M5 `# y+ Q, p( Z
},
g9 A2 {$ ^2 N( T. j3 r8 s3 `; o {$ S" Y$ t( A& _- D2 o
.active_low = 0,3 g/ Z- Y$ z- L; R
.gpio = DA850_USER_LED2,6 a# P- c( i( }8 H$ D0 z
.name = "user_led2",/ ]& @& e* U6 M8 k
.default_trigger = "default-on",% r# m' @' G2 v& [1 E) ?
},
3 }: A5 Q f+ m1 @ {
. e$ ?# t1 A; P .active_low = 0,+ k* t5 ]& j1 E2 `! G% ~# h+ I
.gpio = DA850_USER_LED3,* r( f8 O# o: b0 [0 Y
.name = "user_led3",
" Z O/ S4 _; q; s0 W" U .default_trigger = "default-on",% \ M0 l5 r' V1 V% U# B
},
+ B+ q' ~+ y3 f$ K- n* r1 V- D};
' a+ M+ x/ P- \+ y, Y# L" R& E2 R% D6 i1 ]- a
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {+ I% G$ _: m" w# K" d# {9 b4 P
.leds = da850_evm_tl_leds,4 y% A9 A& n6 s3 w
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
' s) |# t" d8 e6 t3 a$ U2 K% ^};
9 c/ ]: G' F. P& [ `( m6 q. @) ^0 n3 K# b, v8 x2 P
static void led_dev_release(struct device *dev), S/ h7 R4 [( y# ?
{
5 U; o+ i( k8 W# }- n};
+ x$ q H D9 Z% P, F( E& G) ~
4 H" H2 H" o# | ^& bstatic struct platform_device da850_evm_tl_leds_device = {; i A; w( m: Y: G
.name = "leds-gpio",
2 W! g8 f0 V$ O: _! W: q .id = 1,
2 D+ t; |+ k* h& p: Y/ ] .dev = {
, d0 }6 h+ ?! w9 Z. F' ]5 a .platform_data = &da850_evm_tl_leds_pdata,' y8 r& n+ v' w, |* c T- \) |
.release = led_dev_release,
6 I- H9 W& I8 E8 B! y }
) c& t, B5 f! J, K5 }};
7 J$ y. B# h+ t* m- d( m# c$ n% t' v @' Z b
static int __init led_platform_init(void)3 ~$ x3 Z9 f, n7 J! S3 i5 i, W! `
{. ` b, a+ q$ p
int ret;! q+ G: s! G% O4 U
#if 0
" B) y' g) f0 [, ] ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);; G. A, m/ V Y' F( K5 x
if (ret)6 k9 t3 n; a% Y7 E! D
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
) l/ i) d, B9 ^ "%d\n", ret);
2 V6 o) ~' u7 X& ]* q#endif9 a( h, G( A: C' |' d# K; b2 s
ret = platform_device_register(&da850_evm_tl_leds_device);' [7 \8 U, q( h6 E8 V
if (ret)$ v$ g4 F% W. p
pr_warning("Could not register som GPIO expander LEDS");
R! h4 F+ e+ e @! H3 ? else
; b9 {$ |$ P) [* n% A printk(KERN_INFO "LED register sucessful!\n"); x. L8 R" h% l7 G" g
8 |; O* T, d3 x9 c7 }
return ret;& u5 c% J* D3 I6 J8 p
}7 Z5 t4 K* h6 [2 J" P; R
, M# q! b/ F4 M0 r3 H- r
static void __exit led_platform_exit(void)
, F7 @( g5 Q) w7 J5 I{0 t7 }7 T9 x' n
platform_device_unregister(&da850_evm_tl_leds_device);
% ]2 w7 y r7 A, ]# z' [
8 ~0 m9 a7 g! o- z) } printk(KERN_INFO "LED unregister!\n");0 ?/ k! d8 C+ f2 t+ ~0 O4 g
}4 J- g) w+ z; e; u! l5 j# j0 e
9 ^& @9 U5 G$ u4 C
module_init(led_platform_init);
( C0 H8 G# V. u/ Pmodule_exit(led_platform_exit);, M5 I$ h$ ?' N
0 S2 }0 l& e3 `' f8 |( a4 j) Q
MODULE_DESCRIPTION("Led platform driver");: Q0 x V+ m* v, y
MODULE_AUTHOR("Tronlong");
; U7 p6 {. n1 R- K2 F( G# LMODULE_LICENSE("GPL");9 V N- x, O, @! i1 N6 @1 c/ F
* {4 h+ }) O; ~9 p6 W |
|