|
|
求大神给下面的程序做注解,请稍详细些,谢谢。5 _, |6 h- t3 o; |
#include <linux/init.h>9 a6 M( e" V- E# e
#include <linux/module.h>% E, j3 e5 p6 z
#include <linux/kernel.h>8 V. a9 z) q9 _6 J: y
#include <linux/types.h>" q) f9 H7 k. m" f
#include <linux/gpio.h>
) Y& S: K: Z `0 T#include <linux/leds.h>
9 z. W) y# L m5 ~. T#include <linux/platform_device.h>1 U/ {# i2 }7 u0 {4 q! X: N
# s9 a y- g/ r: ]" _8 ?% n/ m
#include <asm/mach-types.h>
^5 `$ |! Q/ n0 N* u1 p% ^: `#include <asm/mach/arch.h>7 @2 i/ |4 @% N* {8 W# o K2 w+ J
#include <mach/da8xx.h>, _& q5 D8 X, W5 q/ P& z# K
#include <mach/mux.h>
; S2 d- a# t5 L7 |3 I6 E( m8 `7 w( b. S$ S" Q5 }
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)6 l% W: ]) u6 L+ ^3 j; L, [
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)- \9 ]& \: }$ A0 D m; h0 h
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)% J) p' R8 ^# V* c1 S
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2). O! b9 X1 k3 c
% m0 L( A: y! V1 H/* assign the tl som board LED-GPIOs*/
! ^$ q9 `3 ], C2 wstatic const short da850_evm_tl_user_led_pins[] = {% B# J# x; Z- K
/* These pins are definition at <mach/mux.h> file */6 {# N) n! c' e
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
# e8 { n; n+ f0 E) ?; E; ^ -1$ t$ U1 _7 X& }; T' k3 P9 V0 N. m8 y$ z
};2 b, P% B1 ^" Z5 R; y8 o
& _& X G" {" l" n1 x- P
static struct gpio_led da850_evm_tl_leds[] = {: E% Y* h- _& f6 Y$ V7 k, H( j3 p ?
{
9 h5 y0 X! u, X3 a9 S; \ .active_low = 0,7 O* \; T7 J* G1 J
.gpio = DA850_USER_LED0,1 p% e2 m; [3 d# E$ G) u6 q
.name = "user_led0",
5 K$ m& t: K1 T3 l2 k .default_trigger = "default-on",( A+ y0 {+ Q% ?1 x% B
},
- a g \2 F8 K" V# w. H5 @ {
' Y! ^8 N- |" U4 q/ d& k) Z: x .active_low = 0,
9 R E G' x; B& ~ .gpio = DA850_USER_LED1,6 E9 s3 ~# k" N0 w. X+ |+ l1 p
.name = "user_led1",
! x* G0 [- O; V0 y& B .default_trigger = "default-on",
[/ h/ J' u& D/ U' e& g0 b },
6 g3 j+ U; u- V! _2 F7 L5 X0 q% [ {
/ E0 P9 M6 f) N+ v .active_low = 0,
, z; B: m, N9 z4 ^: R .gpio = DA850_USER_LED2,
; o( M6 ]/ n0 \6 e7 z( a .name = "user_led2",( {( ~0 E. A9 z+ C* J" ~
.default_trigger = "default-on",
% M! c& T6 h) Q2 u5 s },
. b, C. L6 H2 P6 O! V4 ]) ` {! b& {+ |0 ~1 X' B' \
.active_low = 0,
) ?# d# W( T7 t1 A .gpio = DA850_USER_LED3,
7 p0 [1 V" g0 m, L .name = "user_led3",
3 o' R4 j) r' |1 N0 n+ | .default_trigger = "default-on",, O d7 n# d0 g) e) x
},: R) W" l5 G+ y$ n
};# Y2 y: w0 r4 p; {% X
; e: r) c" `6 o$ F0 F- T |static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {# U4 d, Y$ z6 b- O4 M/ G8 F& s3 r2 O
.leds = da850_evm_tl_leds,- X, O5 v, l$ g, _1 ~( ?7 v
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
1 q0 x& E0 k2 F, h7 Y% m% d% @};' a7 Z" x7 @5 {% X/ q; }9 m
2 v$ q9 O0 Z6 ]2 h+ @$ F* S6 Y
static void led_dev_release(struct device *dev)
/ u6 j5 Y6 J8 E- i* x. T5 ?{
^+ J5 B+ r# k. u};
y4 u y: k3 T: A) t" H: y" ?% m% r) e1 ~2 w
static struct platform_device da850_evm_tl_leds_device = {) l$ J' g0 W- ~$ _: x8 u" B
.name = "leds-gpio",/ K3 N# g4 ]. w5 G1 s) v4 K) H3 @5 p" ]
.id = 1,
$ a6 r3 Z g/ V% L8 \6 j& O .dev = {# }. z. m5 t" e" N
.platform_data = &da850_evm_tl_leds_pdata,8 {0 _) U- w( g" x& l
.release = led_dev_release,
+ Q! G9 h- r) ]) d0 I3 B }
6 C M5 U: z2 A5 D s};) D/ y! `; R& b+ b* m4 P
0 {/ a7 n1 f/ ^1 P |static int __init led_platform_init(void)
# i: r; {) j! J0 K3 |{+ r' K0 V T1 B9 }# J9 p
int ret;" y1 q8 L: O" {
#if 0
, h; I" {' p" T/ H: ~( B ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);* |7 ^& k2 w7 |: i
if (ret)/ w/ S* I' l! f: ]
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
0 W, d; d- ~0 f7 { "%d\n", ret);3 {9 T/ Y( \3 D: x5 R% }0 V
#endif
$ v; N7 C, z/ R6 B# [8 p ret = platform_device_register(&da850_evm_tl_leds_device);
% R. |! H9 N0 q* M( R, e if (ret)3 Z. T+ n2 v. k5 o2 n m
pr_warning("Could not register som GPIO expander LEDS");
2 ~8 y2 ~ O- b/ N( G' A else
8 g% U' @2 y" \( }% ]7 e/ d4 M" L printk(KERN_INFO "LED register sucessful!\n");
1 |6 U( z/ e9 z; g k8 F5 ^9 f+ h/ R, y' L8 R" t
return ret;/ ^& o! ] `( }
}' J& J9 e: ]% U+ M! y) H
; L& O/ X% E. l8 l6 ]static void __exit led_platform_exit(void)
2 ]3 R% O+ t8 }# W! ~9 E$ A' Q{
: b3 M0 p( x: ` platform_device_unregister(&da850_evm_tl_leds_device);
4 m- B# Q4 c- ]0 o8 I
, h! i. z4 w0 o: z# B5 ]- j printk(KERN_INFO "LED unregister!\n");
% ~. i% d: P1 Y" \# `8 ?}
: g; W* f0 p* x7 ~; o1 `, C. p5 v! s9 p3 T% c; v6 `% T
module_init(led_platform_init);$ M" M! }+ v+ ~
module_exit(led_platform_exit);
' x6 @. H* _' x$ g2 ?4 J1 A+ p" q% h
MODULE_DESCRIPTION("Led platform driver");: M( P. O" D' i+ E- E( o5 \
MODULE_AUTHOR("Tronlong");
, ]" h( E4 G- q- X" N+ M; |MODULE_LICENSE("GPL");
. c4 q0 t+ \, I
6 I& c7 d3 ^# T A* ~' N; ` |
|