|
|
求大神给下面的程序做注解,请稍详细些,谢谢。8 R1 n# p- x1 t0 D) H
#include <linux/init.h>
% c: n" K# r% Q' M#include <linux/module.h>
) h& E6 ^7 p% Z: R$ i, l#include <linux/kernel.h>/ U! R8 |3 {/ m$ V" H
#include <linux/types.h>- }# H: S% C/ C# J- f
#include <linux/gpio.h>6 K& U) l9 l, k" |) o0 T. H9 X
#include <linux/leds.h>
. Q5 I g' I; h% }; }" c2 Y$ u) Q#include <linux/platform_device.h>
' _; u+ a" j6 n/ H* z, {9 P" c
# e0 ]1 a/ S$ z3 a' ?#include <asm/mach-types.h>
" G) o/ o6 `! @# V#include <asm/mach/arch.h>
7 A* r* A, Z! A0 a2 ]#include <mach/da8xx.h>
8 Y3 U w0 c. s3 k0 g#include <mach/mux.h>; n# C( l: f" J( y
( ^* L6 ? [0 l N2 }
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
( ?4 V. Y D* r( ~+ f#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
5 G% d5 B; `8 S; R; p0 P, ]#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)7 h3 \. @6 K* B4 s, d/ h
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
: I$ s0 \, ^& ^& c; `
& a+ L4 w: e0 n" z( m, R' V% K8 l/* assign the tl som board LED-GPIOs*/! S! x, F. S; D& e$ ]: f: p
static const short da850_evm_tl_user_led_pins[] = {
; l. \* v: h! S# B /* These pins are definition at <mach/mux.h> file */
6 `! {. e( o5 h; f% ]7 B DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,5 U! p" f0 L' S& x' n. V: U
-1
1 f/ ?5 V7 z4 R' E5 A% |};/ l3 m/ I! [+ [' G/ \, v
/ y' ~. w+ i/ w2 u8 `
static struct gpio_led da850_evm_tl_leds[] = {; m. t2 u3 U$ @
{
2 Y3 }3 H5 ?' w, Q .active_low = 0," e( P9 j$ }" |% x1 z) } V
.gpio = DA850_USER_LED0,
# n0 q0 {: C) K/ A8 N6 ?3 r8 _' b .name = "user_led0",0 j A6 r& S% ^ r- y* Z* O8 y7 R; L
.default_trigger = "default-on",7 P7 Q; T3 |* ]/ }
},
! W" Q* d( |. C+ S; c: ^ {& s" [: p; v- w# }- y
.active_low = 0,
! q% j0 i5 m$ W- t. _; F .gpio = DA850_USER_LED1,- j4 O8 B0 ?+ R9 P
.name = "user_led1",: W7 i! ?7 e* ^
.default_trigger = "default-on",/ ? A/ h- a& |3 G! T# Q, l
},, V8 ^+ e& G5 I3 q5 s7 u! N
{2 ^4 Z: h5 o/ d: h1 x4 g
.active_low = 0, B4 T5 z1 s( y9 r8 x8 \* w: H
.gpio = DA850_USER_LED2,
+ }5 b" N" I! U% U5 z6 Q .name = "user_led2",
$ u. i4 L6 i, y. Q) E6 P* d& Z .default_trigger = "default-on",7 R3 N% o" J+ b- H7 l$ w. a' S) r
},- {% s0 E! R4 d5 p! D' c3 F9 K4 T
{
0 _' u3 C7 ]0 b, g( c; ^ .active_low = 0,
2 ^0 C) r* x$ G .gpio = DA850_USER_LED3,
; j7 g2 i" K7 u G' \9 J .name = "user_led3",5 o3 \# {. r7 J
.default_trigger = "default-on",* s( @: f' ]1 Z" I1 I8 @, E1 L
},
9 z) h; E$ P) w};
5 A7 N% ~- z; }+ n1 ]2 c8 t: F$ ]' L9 k; f3 ]+ k' b
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {# V4 f2 ^' a1 i8 n9 e4 X6 _5 d
.leds = da850_evm_tl_leds,# z* h$ o) {/ L
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),7 C W2 F9 O( F! W2 ^9 I3 b6 d8 y
};
' W" S( N, w( v" E/ ~0 v Y& R: _* y6 G' Q( f$ L& X) f
static void led_dev_release(struct device *dev); Y6 s0 u6 Q. h% k% c% R- E
{
1 ^* h; X4 S6 H7 g" W( ~ {' C};
: b1 W: F: ^/ Y. }2 o8 }0 E, F+ {4 Q+ Y9 j A' |: A- ?
static struct platform_device da850_evm_tl_leds_device = {" K" ~8 {9 [; G
.name = "leds-gpio",
" T2 }+ r; `2 u# J+ M+ i& V .id = 1,
9 w L9 a* e9 A! r .dev = {
3 \! Y1 G. e$ B: f' o# v .platform_data = &da850_evm_tl_leds_pdata,
! J; r. f8 a( l .release = led_dev_release,
$ k( ~" [8 V R& K) E$ S% H }
. |' h4 E; m: y* n- P};
/ @' X+ `! \( j
7 N7 }: }0 Q7 D1 ostatic int __init led_platform_init(void)* z6 _! _- g8 s. S$ H4 @
{
' p' q1 h2 {/ r, k S$ ? int ret;
4 E1 S) ]# ^4 {& c#if 0
; G5 Y9 E7 u7 ~+ \, F; \# \ ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);' E' ~4 J5 W8 W9 g$ U
if (ret)2 f) B, f* N' K1 ]& R" q3 Y3 B3 g
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"5 g9 l1 s0 S% w/ A$ m
"%d\n", ret);
: \8 P. z5 o- m* @( r) w#endif! D/ ] C. H* I( z& P0 b! U8 o) H
ret = platform_device_register(&da850_evm_tl_leds_device);4 W! h, b2 P1 a% l4 h; o& @" c3 i
if (ret)
0 t9 m% K B# Z0 {) F- O pr_warning("Could not register som GPIO expander LEDS");; L: W# |; @( e& A6 D. H( |( z
else' K2 \6 }: g8 }% y
printk(KERN_INFO "LED register sucessful!\n");* R" q. r1 y, }
4 l" r6 d: i" X5 O* z4 \& R- b
return ret;% e: a5 y. Y; \+ R! Y! V6 A
}8 I+ l0 O5 l# x
( M% ^* C! g6 i% J+ w: e
static void __exit led_platform_exit(void)0 I0 P' B, P ]% a
{
- {0 k1 i9 K' ]4 l% ]7 u platform_device_unregister(&da850_evm_tl_leds_device);
: c7 h) \8 i. P' O8 q: Z
4 [+ \9 X4 O# |+ z9 |5 H$ t printk(KERN_INFO "LED unregister!\n");
: q4 W/ E$ |1 ]* S7 N2 ^}6 f. G. J* h3 Z7 C/ z
! k" d: s: n" a/ B1 ` X/ Wmodule_init(led_platform_init);8 x8 b) q9 i2 L x$ t' w
module_exit(led_platform_exit);2 p7 v) A" ?4 B9 ]6 B* y! _5 h& Z/ G5 {
, K" [$ {$ X$ D' F' o
MODULE_DESCRIPTION("Led platform driver");4 n( d' Q" w* Y3 ^) G3 \" A' |. ^
MODULE_AUTHOR("Tronlong");
' m% D y1 L5 E/ Z& p" a uMODULE_LICENSE("GPL");' W3 W2 w. S8 M' _3 f; S: b6 g
/ b* p% H1 z* A: t |
|