|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
5 c' V7 H- G! Y#include <linux/init.h>
5 p+ Y( I7 F7 F% D: P) M! B& [#include <linux/module.h>
1 D. r7 l6 u4 T1 W$ z#include <linux/kernel.h>
3 F/ G9 {! [$ L' {#include <linux/types.h>
, `* H: }6 ~% ^" U! D1 d1 C- F#include <linux/gpio.h>% L+ j) G- @4 o2 z* Z
#include <linux/leds.h>
8 N7 Q o7 k8 [#include <linux/platform_device.h>2 @ \# w: `+ c) t. c0 F
6 `, u2 d9 [ ^# `7 [+ q#include <asm/mach-types.h>8 i/ P1 W1 I$ {( |( N7 a% w
#include <asm/mach/arch.h>+ R# a$ Q0 L; j: H$ d
#include <mach/da8xx.h>% @0 q2 M4 X6 C2 O) k: s
#include <mach/mux.h>& V7 L4 G9 H% l: ^5 Z$ i4 x7 S/ F( j u
# N" h! E: N8 l3 u) i
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
* i, `2 f' S4 T0 _7 X#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)& v+ b e M# N# B& s. n6 T
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
' ^# O. O: T9 \# u" ?/ v _; n5 O#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
# y: m$ m- j) l) t* M' U @+ z% D! c: V, r9 l
/* assign the tl som board LED-GPIOs*/* C3 ~) Z4 w) h8 Q
static const short da850_evm_tl_user_led_pins[] = {
7 Y5 y9 H1 s4 x i( L0 D /* These pins are definition at <mach/mux.h> file */
+ E! r4 u$ ^- p DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
9 [4 F8 z# {' K+ K! t3 k% Y -1! F x6 b$ @8 A4 u. q- H5 P
};. Z6 B5 [. Q4 _5 }. N3 V/ R
. r( R4 n! e6 y+ M# m- H) a2 C7 Q
static struct gpio_led da850_evm_tl_leds[] = {
- q2 c# c1 n8 y {6 E, }2 W( h u- J1 n% n
.active_low = 0,
8 S! |6 |) o0 B* w& R& X t! o1 H! r( U( G .gpio = DA850_USER_LED0,( ?, ]% q. g0 N, W: V# u
.name = "user_led0",0 k: k% ^3 _$ o
.default_trigger = "default-on",
; y4 B4 _& J& S0 g# R7 k- O },5 i, f7 ?: _, i' F
{
3 G% N9 k) y9 q4 ^ .active_low = 0,
& W( R, a* [ T% m2 X .gpio = DA850_USER_LED1,
* w" g/ T+ l( E- D; L* N i2 o .name = "user_led1",3 R1 F$ M f' ^+ ^) n' l
.default_trigger = "default-on",
! m* i4 t# o: h9 x ~- @% |" m' |: L9 @ },
7 C# A' N$ U7 e {
d) {. A3 }! T1 p: G- k! E .active_low = 0,
0 w+ Y! D" [8 K; m7 R+ g R .gpio = DA850_USER_LED2,
+ E& H! a1 g! N) S S .name = "user_led2",- G) }: a" x' B0 z
.default_trigger = "default-on",- R4 O: B3 `+ s1 s4 M
},% x% ], A. H4 D9 T9 b, z
{3 T% z* W, Z) n, [7 E0 V
.active_low = 0,% j4 O6 _ ~, i. X9 c
.gpio = DA850_USER_LED3,
. X9 f- L! f1 u. q2 x8 q .name = "user_led3",, C; e! x' A" `; \# {7 u
.default_trigger = "default-on",
" d! n4 ?! M! [# C# f1 I9 q4 K9 _ },& n+ d$ Q V3 ^6 t7 S
};
: L6 c/ O7 Z& c- b2 A6 c
. a) I# \5 v- M% m# x/ ?* L" O: A; Wstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
' o* _1 P; ^: F .leds = da850_evm_tl_leds,2 j( p: D# e J3 ?# e/ u0 o
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),8 S# Q4 S' F7 Y/ T! X1 N4 @
};# ?( r+ T# W6 Z, j7 z1 S. A
0 r+ h) h9 z3 d' A* `0 {7 ~6 v, [static void led_dev_release(struct device *dev). [* b8 ~/ [* L/ Z" P8 u
{/ ^4 i9 ]! x3 F5 Z7 ^7 ]8 o( b' E
};" y R8 @( [, t) E, X" l% u% Z: z
- |9 ~" h/ o7 V6 A! A, T
static struct platform_device da850_evm_tl_leds_device = {
+ S; i3 U: x! ?, J .name = "leds-gpio",4 e# }1 m6 a4 U0 V+ B' ^+ \
.id = 1,& |- J/ h) N6 ~
.dev = {6 W0 {" T, n! v1 M* P/ e8 [
.platform_data = &da850_evm_tl_leds_pdata,) m2 x5 W. W% \: L( g
.release = led_dev_release,$ `9 d T) A# ]
}
) Q X7 X/ D% U};, R1 _! ~$ p5 @
$ K; J! C1 L+ U8 O7 N
static int __init led_platform_init(void)1 A; w- j; J$ D# i6 i& [0 n) g
{% p3 ?" z5 ]5 j8 p! p+ o
int ret;/ t, P5 k! M/ G+ H
#if 0
2 U# }* D4 A5 J- W! ]9 D' R; Q- W ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);. @- X# S b/ l, Z( f
if (ret)
" g: ?; |. }$ t0 D+ q pr_warning("da850_evm_tl_leds_init : User LED mux failed :"1 S/ X. j$ S& ~; N7 X
"%d\n", ret);& `* h3 s- f! ^1 ]
#endif
; z. v# E3 s. W ]% j' Y ret = platform_device_register(&da850_evm_tl_leds_device);
( t. N6 g; ~$ c, h8 @ if (ret)( j0 e% A1 W1 x: d' i: I
pr_warning("Could not register som GPIO expander LEDS");% e3 S4 [7 P' q, @) w0 X
else
7 u) Y6 U Q7 ]$ s& C& T( w# |0 d printk(KERN_INFO "LED register sucessful!\n");# U: u# |/ ^# N6 w
- E. c4 u% j8 j) U5 R return ret;/ p$ K w- i1 _
}3 [# ~+ M7 ?& [' o" [
& Y0 k% V7 `1 w) A8 p3 t
static void __exit led_platform_exit(void)
$ J. C( V0 O+ K9 |- ?0 u' S3 x: r. s{
% }- P. \1 N+ R' {3 S4 o2 X platform_device_unregister(&da850_evm_tl_leds_device);
8 S9 Y5 N; k+ }# Q; R+ a* R2 n, K+ Q0 y/ F3 `* [( |9 z: ^: B# m
printk(KERN_INFO "LED unregister!\n");2 { C7 r5 c# Q# W4 ~
}6 a5 m% `& [8 H; N9 |) e- n
9 y6 R# b# C. \- X. w8 Z: r" dmodule_init(led_platform_init);6 e3 x' p8 p' o
module_exit(led_platform_exit);& O O1 Y' }+ t; V$ g7 N4 ]6 a
, v4 a& `) H& E, S; H2 r; j
MODULE_DESCRIPTION("Led platform driver");, y" v6 E% S7 e, h2 o' L5 w
MODULE_AUTHOR("Tronlong");
+ k4 [% z' f6 m' _! nMODULE_LICENSE("GPL");2 b2 N9 D ` n5 ^
2 m2 h4 R2 S3 l- Y5 @4 w7 z# t5 Y
|
|