|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
3 Z: ^5 i8 Z. b- I% R#include <linux/init.h>
+ }! C X" c& z3 E% D+ ], g#include <linux/module.h>9 m6 c5 j! e+ D3 C. [' T' s
#include <linux/kernel.h>
@- M! S5 H+ \#include <linux/types.h>- {( s* T7 N8 f- X- C; Z
#include <linux/gpio.h>
& T" w) |, S+ s# o3 \8 x3 S( p#include <linux/leds.h>% d' s! o1 R) B @ O5 x
#include <linux/platform_device.h>( p' m& M: Z( g6 \* P
1 d7 X$ L& X8 o/ r, r2 m% M#include <asm/mach-types.h>1 s4 f8 ]1 H( ]. f5 Z1 B2 v
#include <asm/mach/arch.h>
" p& u5 p3 ]! a; j& }#include <mach/da8xx.h>! [( ^0 Z) _. m6 z( O) b# W
#include <mach/mux.h>1 k2 [9 ]% s( v
1 n+ d2 z5 H; @. v& f#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)9 L) b- h1 ]3 Q4 |
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
0 B2 q7 y ]' z, ]1 B8 K( O#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
9 k w+ v" ~; s" M, Z#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)8 b( o. ]% j( m- [
9 j6 f6 r0 j5 e: q: c
/* assign the tl som board LED-GPIOs*/
0 k0 x/ K4 t n+ m$ s W( B3 |6 h5 ?static const short da850_evm_tl_user_led_pins[] = {: u- L" R: C9 I; D
/* These pins are definition at <mach/mux.h> file */; f7 |: M7 V0 O2 Y8 {. b2 g: V
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
; u$ B" C6 h' H: k, A2 b) V -1' B# {( s+ _7 ]: W# I2 e
};
4 p, p3 c; W1 h: v+ B7 l- e6 \9 P( _ E( I5 w
static struct gpio_led da850_evm_tl_leds[] = {
1 t7 K0 w) y2 w {, e _# Z# h$ o7 ]/ _# o( y3 N
.active_low = 0,! f' f" b+ U9 X7 f- u
.gpio = DA850_USER_LED0,
3 z% N( S$ W. T .name = "user_led0",
) c" d$ F9 T" u! I8 g .default_trigger = "default-on",
2 F: c8 v8 O4 Q# j" Y8 N0 b! h+ p3 ^ },
1 `& j) o. c0 [8 t) I; c# c7 v- y {9 Y/ g% V3 j4 T( V, ]6 y/ }& p
.active_low = 0,
* i" v. e- ~% Y! E" I3 x# B' M .gpio = DA850_USER_LED1,# ^' Z T+ I0 r' v0 q
.name = "user_led1",; x7 L" W! ?3 s/ Q5 x$ n' n
.default_trigger = "default-on",% u! i" v4 y m$ y4 i
},
2 b& q. o! a9 u$ n, w4 |4 { {
! k) n; i6 _2 P, d2 t5 M" W .active_low = 0,
" e* N5 H: c x .gpio = DA850_USER_LED2,
d4 }5 m! Q6 a3 N% A8 { .name = "user_led2",; q& {0 v* i& }- H$ m5 h
.default_trigger = "default-on",, J' G! N; W9 g# [" `' A
},9 Q' B8 q2 ?+ r2 W8 u! @
{$ y( x4 G7 b1 p$ s- W
.active_low = 0,9 {; W$ O# C5 h. e
.gpio = DA850_USER_LED3,
( H# p; j U/ z9 h! [+ H$ Y .name = "user_led3",
2 U4 f! p% K( O k8 ^0 ^6 ? .default_trigger = "default-on",
! `; y! [8 K* m* x, M },& G% j2 c! T% r; }
};. b3 ^: o7 ^4 X) |9 z" t9 h8 w
: Z7 v3 }& X. |# _% j/ Dstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {3 g7 {8 A( }$ V# t
.leds = da850_evm_tl_leds,4 X6 [7 b4 H$ L5 X6 Q
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),- F9 U( I8 O0 ?. D$ i: b1 ~
};3 E7 L: Y+ M7 f3 O2 D0 s2 Y; l
$ N4 _; m6 f4 |( Istatic void led_dev_release(struct device *dev)
( w1 c* y5 W8 g- e4 W* i{
1 H9 O: x/ e# ~' Y" I};0 D. }$ N" d8 Y5 N* p4 ~" r* r" y# y
5 _1 Z' r( K$ T) t$ e$ U3 J2 }, W3 \
static struct platform_device da850_evm_tl_leds_device = {
, n% ]& D$ j; n- U* `/ j6 D7 | .name = "leds-gpio",5 L/ J4 l6 m' d- |3 p- A
.id = 1,- t9 [" o2 `0 `7 p: {5 M
.dev = {/ U& E4 q7 w: {% ~; U
.platform_data = &da850_evm_tl_leds_pdata,5 k4 F" \4 V* F7 G0 C& l/ o( T x
.release = led_dev_release,
$ j. R4 \3 q+ [0 x$ v3 J }* N- ^& t+ f4 \
};
% X! F+ y9 _+ f4 ]; u- d! }; O3 a/ \( H( I
static int __init led_platform_init(void)% j2 N; P3 X. M4 }1 T2 |
{
" E8 C) R' h- u+ ?* v L2 H int ret;5 Y8 H% H. _- t7 I( ]
#if 0
: P" y9 E( I# [" f3 x) L+ `1 ` ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
$ X( N' D8 q3 b if (ret)
! e" q0 f+ d" f. L pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
4 E, M4 G; q* [) t2 C$ D7 ~( X& | "%d\n", ret);
& i# f) d( f. B1 z#endif
- C; u# q# G- p+ p ret = platform_device_register(&da850_evm_tl_leds_device);: c$ ^# u* ]( V' b! R' A7 V
if (ret)
0 V% C/ k1 e, a' h) l/ w2 n pr_warning("Could not register som GPIO expander LEDS");: K" [( T# M9 _5 K0 ]8 [5 \
else
2 F( i6 x) f6 r- G6 `7 Y printk(KERN_INFO "LED register sucessful!\n");
! m+ L% ^5 m$ S6 E: R4 m5 N: v% Q( Z7 ~8 d8 G5 N7 Z8 [
return ret;
2 _0 @& l3 a. [! K& t# [7 m* I9 o. B% `}
" t9 _3 c) A& s* {
* g9 I! S$ ^& \/ Qstatic void __exit led_platform_exit(void); k7 T$ E6 C6 k8 H
{# P0 m5 G9 F3 O1 Q* R: C* T2 @! ^* z
platform_device_unregister(&da850_evm_tl_leds_device);; O. s$ I B$ l% V: n' k2 A
! w' M% n3 F1 V1 |; r* `' M
printk(KERN_INFO "LED unregister!\n");
- K+ w, ?, a ?& W" `. Q. P}3 z1 o$ B( k" w8 t8 j
/ U% }. A9 {, |% ], z9 xmodule_init(led_platform_init);* t: l6 O7 {# l! `
module_exit(led_platform_exit);
0 o4 [* Z0 W7 S P) L; s* q
/ z5 @6 H* F0 w k- f! _MODULE_DESCRIPTION("Led platform driver");7 E+ O6 g1 }! T5 Y) q
MODULE_AUTHOR("Tronlong");# o+ {9 E) E; j" ~4 n
MODULE_LICENSE("GPL");+ K; \8 |( P6 U t
7 p5 Y. w- t1 h' @0 w$ p |
|