|
|
求大神给下面的程序做注解,请稍详细些,谢谢。) F8 x& [- s3 r' u8 y2 G& z
#include <linux/init.h>
) h; ]5 j2 J3 c* s#include <linux/module.h> o4 w- L! i. A/ L
#include <linux/kernel.h>! J9 E6 K8 v4 O: L. T& E& k) F# n
#include <linux/types.h>
! Q. j0 T9 A3 }#include <linux/gpio.h>
. Q* L9 q) F; e& u/ y#include <linux/leds.h>0 j/ w( H6 R9 ^" L1 F2 d/ w
#include <linux/platform_device.h>4 J8 Q# d2 C8 M7 k
0 L1 x% D+ C6 w# G+ O- O( f# W#include <asm/mach-types.h>9 [1 x* X e1 Q+ D1 Q" M) S
#include <asm/mach/arch.h>% G2 H, b, q/ [6 K7 S* [5 O) `
#include <mach/da8xx.h>& g* ~* `. [" D1 z7 G) e; c
#include <mach/mux.h>
0 K7 N, k/ X; }( z0 l( J# n7 \6 L8 z9 a% k) P! K0 t
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
, J. y. P' p- Y8 s5 r1 W#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
/ R" j7 X9 }& h+ b#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
& V! Y/ \/ i, Z) |#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)& H, v/ d/ D' L$ j$ I
1 C) @4 k! H& ^1 U; K6 B
/* assign the tl som board LED-GPIOs*/
" l/ s' B: Q# P! l, n0 Nstatic const short da850_evm_tl_user_led_pins[] = {
8 U( U/ P) Y4 h- {' y /* These pins are definition at <mach/mux.h> file */; d) n" M$ y! b, x" x2 s2 u/ ^; B9 h
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,) W# K# b: ^% e1 {) s0 w( g
-1; \6 i; |4 k$ {* M( M8 X
};6 d5 C$ @3 ^! q5 ?7 G3 f
- E$ P; W0 V+ h) P5 Z, }* b2 Jstatic struct gpio_led da850_evm_tl_leds[] = {
4 d, P! i3 s" G6 b {
0 |/ A2 h* h: K1 O9 K. c .active_low = 0,
- ^9 w4 n4 m' p# U& N c- y .gpio = DA850_USER_LED0,
, P( c' Y: y; B) O; N .name = "user_led0",
5 C2 d# ?# L ^! X* j2 S/ D( Q .default_trigger = "default-on",
( J* k J- C' [1 k1 f7 H },
/ ~) f# U. k7 V3 ~; Z, i. g# p {/ n K& b! T8 G8 ~4 V |! ^
.active_low = 0,% _, z/ ]7 H4 L7 d% [
.gpio = DA850_USER_LED1,
; |9 T3 d7 U! n4 a R& _ .name = "user_led1",3 p! I R5 B: `' l3 A9 b
.default_trigger = "default-on",$ }3 \- X& W) T
},
% ^3 X# e0 R3 i! b! m' V) { {
. q7 s% E# u5 P, j3 }: Z .active_low = 0,( q; N% `' P' I: D
.gpio = DA850_USER_LED2,
: S w. }9 N/ T! H! i .name = "user_led2",
2 D9 {3 n9 ]. {7 z$ N .default_trigger = "default-on",
0 q) Q8 b* L* q ]: h$ C },
9 ~0 y9 j. v1 V# g/ |4 D {, x" Y7 X# R3 M* {
.active_low = 0,
( S9 j: e$ r" o$ m' \9 W .gpio = DA850_USER_LED3,5 g4 n5 Y+ F$ E, Q% @" n; e" @
.name = "user_led3",7 j$ V9 r! N( r/ k' b
.default_trigger = "default-on",8 b# k" e- l/ L3 U
},2 S9 v0 y, m: }$ X5 C2 k7 t
};. J. q8 i8 x- _
4 J4 }4 q+ }8 ^. I' G, O+ t
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
7 A9 j2 x/ f7 i) @9 a2 c! f .leds = da850_evm_tl_leds,) n3 U& j5 B+ i* y, S L5 |) q4 O) g
.num_leds = ARRAY_SIZE(da850_evm_tl_leds)," c. o$ q5 W! ?& H% Q
};, ] U: C! q `. @. X
0 p) Q3 F) i' O+ e" v4 Q* e3 D, Jstatic void led_dev_release(struct device *dev)4 x) x Q" U8 M! u+ R5 U
{
: x' B% ~; H+ F4 R( ?; M4 ]& _4 D};& D7 s: |$ e* r4 {9 B- t! G+ N
- n. l( I- H5 a$ S8 U; xstatic struct platform_device da850_evm_tl_leds_device = {. {% D; M& y- w
.name = "leds-gpio",- I! d$ I9 n+ }6 F2 ^9 Q5 I
.id = 1,% r) L5 P. X: U
.dev = {
9 D8 v* L8 s2 A- [& i .platform_data = &da850_evm_tl_leds_pdata,$ z% f6 ?" j8 w3 h% l
.release = led_dev_release,( p6 a% T" |" m1 ]2 w$ V5 T1 L
}
/ _: E1 z6 w5 ~+ ^" n/ M};: {: f# F1 ~7 D2 U3 E: w1 I
2 \3 n) q; k) Mstatic int __init led_platform_init(void)
3 o- i3 G- X5 |5 r7 C# h# r9 L{% L* @! o1 `% s5 d; G- K) j2 ^
int ret;9 k0 \2 k8 x) t3 K
#if 0
" [. w0 [, v: R( u! e2 G+ d ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);. m3 Q1 Y0 l7 E* C j: N
if (ret)* }0 |; v9 S) _ ]/ p
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"* [4 D; H2 E2 D
"%d\n", ret);
) n8 S. O( {4 P( ^#endif
/ j7 a/ S2 ~. {- V* o, c: @ ret = platform_device_register(&da850_evm_tl_leds_device);% Q$ {: T# [, {) C0 |
if (ret)
* u0 r6 x1 r; ?6 k* F pr_warning("Could not register som GPIO expander LEDS");9 D7 b; G' L* e# `
else! r" s. j* Z& G0 r( p
printk(KERN_INFO "LED register sucessful!\n");+ S5 ~% W2 a' h
( k2 S+ I7 p6 m& R/ S1 i return ret;% }( v* l( h* p" i0 a& |
}( ^/ U& q- p4 {5 X9 p2 \1 Z- F
8 \0 Y' j* K6 q4 A
static void __exit led_platform_exit(void)4 S g( ?; I0 o: h4 H$ l4 M8 n
{
+ b i1 X- H* Q4 w! A' Q8 \ platform_device_unregister(&da850_evm_tl_leds_device);* q+ o* B( x" c! |* w
: X0 ^, x% K; W1 A- E
printk(KERN_INFO "LED unregister!\n");
; `! x; S4 U" \' t! J}8 ~1 q2 K B N* c; Z7 s8 O2 N
d- M0 \% G" O: X3 Q* w" L( Rmodule_init(led_platform_init);$ H" ^4 ~0 Q S% y7 d$ L/ H/ O- J
module_exit(led_platform_exit);) N5 o$ w4 `: p, t5 N
$ y" K2 X5 `8 C) i% _! l4 K
MODULE_DESCRIPTION("Led platform driver");
! h2 Q5 q& p; z2 N* rMODULE_AUTHOR("Tronlong");8 @' O1 f" r. {. j7 N
MODULE_LICENSE("GPL");
( ]6 D/ ]& u; J4 M: C) _# Z1 I, E& o }! z
|
|