|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
0 N6 U$ J$ x, }* b6 t8 J6 B#include <linux/init.h>1 Y/ x& D( |, `- o/ N9 F, R
#include <linux/module.h>0 n( C7 n1 n! w% r
#include <linux/kernel.h>
" m& X8 t7 {5 l8 D) ]& ?#include <linux/types.h>
# F7 R' h! U1 ^9 a4 ]' Y. C#include <linux/gpio.h>4 Z0 w: Z) n% V/ V5 ?4 Y) W' U( l) B
#include <linux/leds.h>3 M: i6 m0 R- _% C' r1 I& p- o
#include <linux/platform_device.h>
9 D9 ^; h$ H( n2 j6 J! o: H! z& Y, V4 g* M; x0 {) J
#include <asm/mach-types.h>
& ]4 j& J1 j% S. n" Y( C* {#include <asm/mach/arch.h>% N$ l0 G9 j: k0 v
#include <mach/da8xx.h>: U, t0 M# @; C4 L2 P+ |4 I
#include <mach/mux.h>
7 O( i* y* q1 F) j# K9 ]; m) Q, `# t5 q% |; ]" R9 @3 S! V
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)1 _/ |; T- x# h# k4 u2 j4 H
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)" l! \) y3 O, O0 h: k, Q6 h
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
D; s/ B! c/ h! I#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)& e8 r' e+ s% ?
6 P! |2 o& k2 W4 S$ r
/* assign the tl som board LED-GPIOs*/% D4 j" n5 L& N9 C5 D: |- e
static const short da850_evm_tl_user_led_pins[] = {
* Y! J, ?' z2 T /* These pins are definition at <mach/mux.h> file */, w# ], u2 [+ i1 Z, K
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,- U% E/ b! J9 E) B9 n5 {
-1; E" o1 Y+ C/ \0 }( M
};
1 V1 X) ` L: l% H4 H4 E
# b! i5 b- X, v9 F) x. N! ]0 Astatic struct gpio_led da850_evm_tl_leds[] = {. }! }9 M& {. m) ]' Z
{
1 v! h) {4 {, _9 S- n .active_low = 0,
5 [/ q0 L& w- ]- m3 X .gpio = DA850_USER_LED0,
4 [6 P* C3 C: @; q) A .name = "user_led0",5 r9 j6 f1 I# t) W2 C
.default_trigger = "default-on",
1 o3 A9 r. U E) R7 ~" i5 L },4 ~. \. c( w8 a2 h" f
{4 {% J1 s7 v1 l6 U1 `( [& M. q
.active_low = 0,, m* G/ I: }$ R, Q, T
.gpio = DA850_USER_LED1,
0 A( P4 A, i. q4 ~" E8 P .name = "user_led1",3 j5 u+ v! U1 X2 E$ L
.default_trigger = "default-on",
" `/ e) E" V! [$ | },! x, k4 ^" p# E1 O, c% z3 r& h
{
8 H- X+ x1 q" W .active_low = 0,( e6 q" h9 r) d' j
.gpio = DA850_USER_LED2,: L) ~+ m9 x$ j# K/ S; W& a
.name = "user_led2",3 A- |3 \5 v2 ^8 U( h; _$ d+ r
.default_trigger = "default-on",! O: x8 h6 R! {" y1 A* @$ ~
},
. ^& P2 o6 o. N, T# c4 a {
' C3 `8 p3 ~0 X$ I .active_low = 0,
# N& }# ^ g% Y. s: F .gpio = DA850_USER_LED3,5 a0 Y( G8 Q$ x. Y1 E; H; D
.name = "user_led3",$ y9 O8 Z5 b0 L, K h" [9 u; ^
.default_trigger = "default-on",$ E; a9 I7 }$ _$ u! H) M3 O
},# W1 E: W d2 D2 y7 @$ ~' i& S0 d
};9 S4 H" P3 q; l, g. n0 V+ r
3 w9 a/ `+ R3 v* Y0 m3 mstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
% e a. U1 X4 P8 G8 J" f6 u .leds = da850_evm_tl_leds,1 ~4 n: ~( T2 u2 k- ?& n
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),9 Z* O! @. ^7 ^. k% ^0 h1 A( E5 p
};! L8 S" D' g: Q7 W9 p1 x
8 z4 B* L2 v/ U2 b3 kstatic void led_dev_release(struct device *dev)6 z( ]0 ^' `& o, @1 o
{, P, i! q5 o7 \: P
};
' z6 T9 R/ N2 d, j/ @ w" _8 w
# J# H& h( e' r3 ^' K \$ ~static struct platform_device da850_evm_tl_leds_device = {6 o( I1 o0 Z2 E6 }, z* @5 ^
.name = "leds-gpio"," ]0 f: q$ ^* v, x! n6 w
.id = 1,
1 s7 H) N4 l: ~: z, p( b; a# q' c .dev = {$ a& H0 L& x* R* U8 ~( |
.platform_data = &da850_evm_tl_leds_pdata,$ F; @9 V6 p/ J' G/ B g7 s) j
.release = led_dev_release,! h( s" g+ W8 v
}' J# B6 H6 K4 [- r: _8 {) n/ d+ F u
};
5 ?$ a7 e' T- i' @( h @3 C
5 q! S' ]0 G. N3 n+ K" c1 wstatic int __init led_platform_init(void)5 f9 H. `7 q' W3 {
{
$ r; E1 U9 c& X+ j4 } int ret;
, ^7 V; q" `% X# \9 Y5 _#if 0# H. W; [0 O* P Q
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
" q9 K7 `8 c4 ?9 L( ?7 e if (ret)& b( Q1 {+ f' X, W
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"; q! D# r! T! d) P& T
"%d\n", ret);( e$ }' z: q4 O: ]$ @/ U% S0 d: z
#endif
8 O% t X( I. |* X5 _7 g' K ret = platform_device_register(&da850_evm_tl_leds_device);' @1 a% i ~* H
if (ret)
) o- K% o# Q, q( n J, [' R0 _ pr_warning("Could not register som GPIO expander LEDS");
3 q" e/ S$ A3 x( D1 b else
8 n7 E6 j8 c1 o3 S1 c9 Y" z6 r% t printk(KERN_INFO "LED register sucessful!\n"); Q- ~$ P6 w* w: r
# U$ X) @7 T0 p8 \ D8 Q0 ]' S! z return ret;3 `! M+ @! M0 R- r) D1 c C4 F
}5 w& T/ ^) g# Z8 D- M
9 A9 x: K) r# h
static void __exit led_platform_exit(void)/ K3 ` R9 k% J/ C/ S1 I
{
7 x- |6 q s0 G7 l f' T) e platform_device_unregister(&da850_evm_tl_leds_device);
: ]( j* }# h) J) k1 ]- u2 f9 I# `8 d
! I! q& ?8 g! m( | printk(KERN_INFO "LED unregister!\n");# x9 o) r T7 O8 p
}
3 X' _' d" z# C8 p5 V/ i: U+ ?1 `% a( j, j. S+ _5 p, F
module_init(led_platform_init); N$ y7 {8 |' x" x9 {% S
module_exit(led_platform_exit);- ?# `8 M b( h# i2 {! f$ m
" L, z3 O! u+ n' f( f. F3 ZMODULE_DESCRIPTION("Led platform driver");
+ `/ Y5 n% U+ p9 D O4 sMODULE_AUTHOR("Tronlong");
5 w: P9 @, i/ n& n8 V6 [MODULE_LICENSE("GPL");
* r3 O5 M; F5 t+ i& i
0 G6 i. {& F/ S- t |
|