|
|
求大神给下面的程序做注解,请稍详细些,谢谢。) I9 r' h0 V% d
#include <linux/init.h>
1 N& M+ m( `' G$ b#include <linux/module.h>( }2 K4 f1 J, J2 K) E- Q
#include <linux/kernel.h>. d1 H$ I& W- l, v7 \2 }$ x
#include <linux/types.h>
, ^) u! x! C+ H#include <linux/gpio.h>$ J" {$ g3 e- n2 [4 G# }) ? \; {
#include <linux/leds.h>
; Q! S+ q% R& }1 q! O#include <linux/platform_device.h>
8 n7 P7 e: U- w+ o3 ]9 \% |, L2 n/ E1 Z7 f# h/ b
#include <asm/mach-types.h>6 u4 W/ M) i/ b% ~6 d2 s
#include <asm/mach/arch.h>: J5 }2 I9 V+ A& u
#include <mach/da8xx.h>
# n% `- E) o9 o o Y#include <mach/mux.h>* N# Q1 y( X/ B/ M, V
) j8 j5 t8 h! }/ S
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
/ c! L M6 s5 B, E% N# w#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
{2 x p) `" |#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
/ D4 u- |! E: n- }0 y5 W! e#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
: u( j* V/ Q% p
$ `0 F" w1 b* ]% U5 q f/* assign the tl som board LED-GPIOs*/! d3 E8 Z( A- Z9 l6 ]
static const short da850_evm_tl_user_led_pins[] = {
. I* T& X7 ?" U: W( ? V9 ]5 n /* These pins are definition at <mach/mux.h> file */* Y U. S7 M6 P' k8 P) c' [9 e
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
# g3 {5 |$ G& T0 ?0 C -1
0 x5 C+ U: Q2 F. `& A$ `2 q};. Z6 y# l, ]. U
. M* M+ u U4 H( w8 x4 P
static struct gpio_led da850_evm_tl_leds[] = {
3 G. Z$ _ a6 b8 a; P: l {( K! {. ?" `1 O0 z
.active_low = 0,
+ w+ ~* v5 u% p( O) J9 l* | .gpio = DA850_USER_LED0,) A9 u. e* d4 {, r
.name = "user_led0",5 N4 L: k6 _5 m9 i
.default_trigger = "default-on",
% L9 S W) A* u; X- ]% @7 D& J },
7 l y8 G+ z5 m2 {- X8 _ {& N+ J7 b% ~5 [
.active_low = 0,# c! X& y6 _2 X* @7 X8 D5 d( n1 T
.gpio = DA850_USER_LED1,/ U2 E+ `3 K( H) E! `
.name = "user_led1",7 z" _& S# t1 P
.default_trigger = "default-on",9 X6 E+ X1 `# B8 R; q& N( O, B" d! G; u
},
/ r% I- Z# v! x O6 T5 N" z {, n9 i# A$ ?( h: ]% F
.active_low = 0,
, f: \ B( ~, W! b+ Y& k* L; K% s- L .gpio = DA850_USER_LED2,
$ P& s' O; f5 V; y( C .name = "user_led2",
- n3 C6 k& R+ R" f# c .default_trigger = "default-on",% {: _/ K/ j- q% Y
},5 Y8 W# f& i8 n: q) g; D
{
5 ~ D8 [% Q; V .active_low = 0,4 O6 S3 X; w1 c
.gpio = DA850_USER_LED3,
+ y( C- H8 u1 Q: z. \ .name = "user_led3",& p, V. R% b: s" m0 h1 T
.default_trigger = "default-on",
9 w) }* A4 V4 D) D/ w" Z },; J. L8 P5 K% {: q) j4 ]2 Y
};
. s/ H! d/ s4 a- u( m
6 Q8 Z( h/ \# q1 fstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {: A7 d& v# w% Q2 H' m) t% L9 X
.leds = da850_evm_tl_leds,+ w& ]/ r; R5 G5 j7 F4 ]
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),# Y+ R4 r6 t! y0 G
};
* i/ e5 z) `) Z' P) x/ s
1 I& D: n+ V3 ~+ U+ ^4 K& qstatic void led_dev_release(struct device *dev)
4 [0 P0 S. |" }& u) v L5 ?* U{
# }, F! y* j4 S7 O- l: l};$ A0 N& M$ A, y# g3 p& c/ b
: |2 q6 C2 v3 `' u" r! Istatic struct platform_device da850_evm_tl_leds_device = {
; h. O7 R; u4 K' e- l3 s; K .name = "leds-gpio",' c9 s6 h# T; V! I9 U
.id = 1,
8 U! X1 [1 j4 K) q+ I .dev = {! \+ j8 P' J& Z. A f# j9 [1 \6 N
.platform_data = &da850_evm_tl_leds_pdata,) O8 p4 n# B7 |% J& C* J/ `2 K
.release = led_dev_release,8 a% i4 [, c' _4 P5 C
}+ q, G: y/ T! @$ z7 D9 k
};
) r" C* t. B6 \) J, B
9 l% X3 Q: J6 u& L9 ^3 M4 ^static int __init led_platform_init(void)( k" }6 k' q5 n) `& s/ @: y5 g
{
* O9 p$ i5 v, G/ R* U5 U" q# _+ ~ int ret;+ N" N# J! p/ s6 }% }
#if 00 `" L$ M* d0 S% \$ S
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
3 L" f% p P9 ]; h9 m3 k if (ret)$ L. [+ \& B0 L1 Z* C* }
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
$ i+ l( b6 D; W "%d\n", ret);
! A/ [2 ~5 g! X( O( Z1 Y, d#endif, G$ [1 L3 x/ n: K
ret = platform_device_register(&da850_evm_tl_leds_device);
# U' u$ a4 |; K8 H c if (ret)4 i8 @% C5 f4 Y( x) _: y
pr_warning("Could not register som GPIO expander LEDS");
0 P' b# N1 x7 k" B' z" W else
: c0 R, X! f0 Z4 J9 N printk(KERN_INFO "LED register sucessful!\n");
/ B, b4 B) `' m( P s, F; O% p3 S {$ w9 T7 k( u2 W, U$ [
return ret;
& d5 X7 u9 [" q2 \, z0 e}
9 C @6 v* O* P u/ z& J5 f5 f! ]" H7 n& |, v. h; S
static void __exit led_platform_exit(void)
# s5 y B A$ M7 o{
, W" b& H! ]" @* @/ E* h2 h platform_device_unregister(&da850_evm_tl_leds_device);: F w" D# X' h, m
- @" X& x: K! J* F$ L: v
printk(KERN_INFO "LED unregister!\n");4 _0 n8 R1 O5 z3 M" q
}5 C6 F* V9 w& z, `. P5 U( r
7 G% ], b% b! |! c: J
module_init(led_platform_init);
; S/ Q1 d1 i+ v+ P( T! k: Emodule_exit(led_platform_exit);2 l2 J2 l- W# i1 v/ s' b" N
+ V; b& v8 x( F2 aMODULE_DESCRIPTION("Led platform driver");9 K$ D9 c! P4 m. A0 w- N8 [" X/ D, `
MODULE_AUTHOR("Tronlong");6 Z. X6 K/ l0 z8 t- k7 `/ L
MODULE_LICENSE("GPL");
# y, Z4 Y, `8 }( d6 w' O/ h( a4 l
, L2 w) q M9 k |
|