|
|
求大神给下面的程序做注解,请稍详细些,谢谢。! J. u1 P0 J7 n( [5 a
#include <linux/init.h>
/ S% q) g, w/ S5 L4 A#include <linux/module.h>3 V% J$ o" A3 ?; p D! s, t% ?1 n
#include <linux/kernel.h>
8 g& p# a4 \+ w3 Z) k#include <linux/types.h>
- V) P$ A2 y2 U% l2 A! Z#include <linux/gpio.h>( |# F- a( u& ]/ @0 V4 @4 ~
#include <linux/leds.h>- |$ z9 f9 v; D& p3 C# w5 K% N
#include <linux/platform_device.h>% B1 B9 O4 C* k$ Q
% n' p% n; |1 e* p#include <asm/mach-types.h>
0 P/ h" y$ y: U8 c% H- Q& m- [#include <asm/mach/arch.h>
7 E- e; c! x. m#include <mach/da8xx.h>
) u0 T1 }' T4 F0 {0 f9 `#include <mach/mux.h>5 x8 q6 a& i5 \0 `0 x+ Q+ c+ y/ Q' H
4 n- O+ N- n9 q e! j6 }! h& b+ o
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0). X" u+ B, g) O* e# }
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5). `& s# I6 d) ^% F7 f+ k @' S
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1): y9 }; ~. R1 ^9 j
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2). y+ h* p: D7 i8 d$ z1 ^
* p: v; @' `1 g* b% Q- {$ K
/* assign the tl som board LED-GPIOs*/9 [/ r' ~ C ]( O" B4 V
static const short da850_evm_tl_user_led_pins[] = {$ D" q7 ?( W" ]- g0 |- \. f- |- b
/* These pins are definition at <mach/mux.h> file */& y3 Y) \* T- y' [8 b7 a
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
c% N3 B( o' z! I& E P -13 M9 P( r7 A, j! W4 z2 a- w$ D
};3 _2 s* c; |( x# ~/ a% n! Y/ p9 n
4 [6 D# ^) `, v# @0 G4 D; w
static struct gpio_led da850_evm_tl_leds[] = {+ g' D5 H9 Y$ T" y* d; ~8 _4 e
{; \4 @+ R$ g( H% b
.active_low = 0,
9 b1 V4 i4 V8 \) ^$ V .gpio = DA850_USER_LED0,
" |3 a9 P7 l# b- a& H1 M( u4 K7 } .name = "user_led0"," J6 q. U" M* e. e1 w
.default_trigger = "default-on",$ E! G0 ~9 @# I, ]2 ^% R" G: L
},9 B+ Q: J+ L1 m- }3 R$ }
{
# T3 {) L4 D" y .active_low = 0,
+ j$ }0 X2 [/ J( o6 W |1 T .gpio = DA850_USER_LED1,
8 l: L+ L% j3 D6 G2 I1 }( o2 a .name = "user_led1",/ ~' V3 j+ u8 d: t/ }2 O7 w+ y
.default_trigger = "default-on",
5 `; \) q: I2 G( E8 f+ J4 x },
X9 |+ X" s E/ b" J$ [% g* X {% H( Y m5 ?2 h# H
.active_low = 0,
7 X% i6 V; @. t: |7 @, f .gpio = DA850_USER_LED2,
) h2 c1 O3 g m- i/ W& H( Q .name = "user_led2",
% w1 ~" K: B1 s- W/ J .default_trigger = "default-on", O+ U7 t8 D! k! w6 Y& v
},
( T* n2 x1 H. G/ T& q# [8 g {- T+ F0 f! h% N7 m. L
.active_low = 0,
. W0 g$ J3 I$ \) U* K/ d .gpio = DA850_USER_LED3,
) j) H% |: V2 L0 F% J' Y .name = "user_led3",0 I8 R$ \! @' \ r6 R3 [+ _5 R
.default_trigger = "default-on",0 r/ b9 O g+ D! f1 _
},( j1 b2 l: E% t6 m- U& X" w
};
8 B9 B H W4 `, h: C0 p- A# x& Y3 j" s
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
* Y* ~" y. ?! d .leds = da850_evm_tl_leds,
+ }' J4 j+ D8 A2 h* P& t: l3 U* n9 _# M .num_leds = ARRAY_SIZE(da850_evm_tl_leds),* J5 ]3 @* [% |7 L; \& M+ R
};
( ^/ n8 M$ C1 P3 o* A
& d7 @/ h) t6 M- n0 k; q' n: jstatic void led_dev_release(struct device *dev)" a& c, H% L" Y$ U4 T
{
9 ^0 x" o7 f2 K P8 r& e};
& K5 @! t( z0 u* a5 h7 z- m; I: k* f( @# u: R' N
static struct platform_device da850_evm_tl_leds_device = {" s/ m# N+ h; a* `
.name = "leds-gpio",/ d! s) s* D0 S6 r& S& a
.id = 1,
- q" k; ^5 A0 y* s .dev = {
! c2 X$ c$ a0 Z0 X .platform_data = &da850_evm_tl_leds_pdata,
8 z0 E0 p4 R: k# G" w1 U .release = led_dev_release,7 Y. [. S2 o9 k, M
}
7 a! T! p8 L8 \ Q};
( M' @) `2 V* q+ p: |9 S' w4 b+ C. I- @$ t
static int __init led_platform_init(void)
- z, c, B( S( c' }1 J% Z{& M8 H# y& |& }2 w
int ret;# g2 Q8 n/ X6 b# m3 [
#if 0
# ^2 H6 R! ]5 l Y: F8 A! |9 D ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);( m- [5 ^( l' C( [. G- l/ f
if (ret)3 @* a9 l' _2 a: B4 W
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
5 ]7 c% s( G1 f v "%d\n", ret);
0 T1 d2 A3 r8 K; S" [9 O# v3 L#endif1 g+ G. t( N: Q$ V6 i. ?
ret = platform_device_register(&da850_evm_tl_leds_device);
7 P0 w1 F& H l if (ret)
; b1 T# }% `- N e pr_warning("Could not register som GPIO expander LEDS");
3 T F8 |- i4 t+ m% j8 `4 y else! \! L- |9 A) F" D! @* E: R5 s
printk(KERN_INFO "LED register sucessful!\n");$ b9 `: \1 z5 P2 @+ G8 Z
. _: Q% n2 m* { return ret;
# \# a; g m+ T7 c0 J% Q}1 a ~+ |$ p6 m1 m. F
9 o2 ~$ ]1 D$ ~: a# s; \static void __exit led_platform_exit(void)
* G5 R- D! o/ p0 u{
. Z6 l8 d6 G0 e% Z$ `4 B1 K R platform_device_unregister(&da850_evm_tl_leds_device);0 l4 `5 n$ Y3 p8 I
" m1 i% p- Q9 M: N# x* {
printk(KERN_INFO "LED unregister!\n");
# m; v/ M6 j0 |8 {+ J& n2 W}
# c' Z: x) l0 \# v: r
( i W8 e, Q' ~# z/ ? Nmodule_init(led_platform_init);
8 h& r. M* v) S2 gmodule_exit(led_platform_exit);& [# r2 J8 O7 A7 n
( Q/ u$ d8 v$ g1 z
MODULE_DESCRIPTION("Led platform driver");
3 b, N5 E0 x3 z5 _7 S7 g' I& z# cMODULE_AUTHOR("Tronlong");7 e0 h$ N( l+ P! J
MODULE_LICENSE("GPL");
/ x: I4 a z, C: f. X4 }- I* f6 V+ I. g1 A% m8 o
|
|