|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
" z j* F' [2 w; D D: S( L#include <linux/init.h>: Y- ~/ H, ]0 x# U( {
#include <linux/module.h>
( O/ e5 k! _3 \/ I' m0 N#include <linux/kernel.h>; e* h: m/ d# v" `2 V* I
#include <linux/types.h>" I6 a/ a J; R+ r8 u) i, r
#include <linux/gpio.h>
5 K& t+ K: [7 i, l. `; P#include <linux/leds.h>
- @9 W1 ?# B' i4 ~#include <linux/platform_device.h>& Z3 {- e9 u" i, K7 V2 t% w
; a+ G: q1 W d5 B# A6 Q' x0 U) n#include <asm/mach-types.h>1 H4 R; X0 _- H. `9 ?% i" T
#include <asm/mach/arch.h>& y- r# u) E |& Q! h
#include <mach/da8xx.h>& C6 F; Y& z/ W$ m( F4 w# ~
#include <mach/mux.h>% a( j! D8 J8 Z- Y2 L
8 N. E# H1 ], O% I$ w0 r#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
1 y9 C: g. m: K% Z1 I/ G1 b#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
0 k( d0 ]$ N4 U7 F. q5 G#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
) k" w s0 p% f% s! F4 t5 a3 B#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)1 f1 }* R: K: H4 y
0 Z1 o. V# X- U/* assign the tl som board LED-GPIOs*/& G$ R' o; b, d/ o% G( f
static const short da850_evm_tl_user_led_pins[] = {) |3 D8 I6 G5 v5 t- I* h
/* These pins are definition at <mach/mux.h> file */
7 y, L2 J; q5 d/ k, s) a DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,9 i6 Q7 ]3 k+ n9 G0 q6 |
-1/ O. {! k% ~( N( u. A# m+ g
};
# ?9 U2 ]) _4 }. X3 l, O
1 n$ T" d6 w; ?: Y, y+ K8 R9 Fstatic struct gpio_led da850_evm_tl_leds[] = {) `9 ?4 ~ E7 U6 W0 Z5 `( o9 {! s
{
5 ]" ~ X, S8 g; ] .active_low = 0,4 B7 R5 t i5 Y* c* R
.gpio = DA850_USER_LED0,
9 d1 G; }8 I( U+ n3 j$ Q) N F .name = "user_led0",
4 I3 h1 p5 W/ w9 _/ o9 v3 q, m .default_trigger = "default-on",
; h4 W: W. a" `8 Y1 N$ C$ ]0 K },# w+ v4 Q0 `% f( S
{7 y8 L. ^0 d% [! f0 F8 \# l
.active_low = 0,7 m: V/ y$ E( P* Z% U$ i; A, ?" B
.gpio = DA850_USER_LED1,' o% r9 z0 u9 x) ^! k) r
.name = "user_led1",, o. H6 U$ r0 j0 m: Z% l
.default_trigger = "default-on",( F: y& u, ~. J' z W* D
},: l8 q# v' O- z: v: n2 M" E2 Y9 o
{/ C& u5 A9 y- E1 p7 v
.active_low = 0,0 L4 z+ T! f) w) X. k$ H3 ^
.gpio = DA850_USER_LED2, f8 T l$ \6 g6 n8 v: @ P* a3 [( G
.name = "user_led2",
$ K- O8 W/ \& ~8 I! x) q: A( d .default_trigger = "default-on",+ { }2 C [5 K5 D2 }
},
1 J/ T& _3 P$ M* q( K! t# P* A {, ]5 a7 @3 o. J1 z# [& M& b
.active_low = 0,, _2 d- H7 L$ d1 |; q7 L
.gpio = DA850_USER_LED3,
0 v3 y, A3 i3 ~; D: j/ b .name = "user_led3",. l' q5 s% v5 {7 ~7 R3 g; X: X
.default_trigger = "default-on",
/ k$ V3 p3 R9 I) Q; I* a/ g },0 d7 p( M+ t4 q; @9 K
};
0 x( r2 C: B) ` O. ^2 C5 R: u3 C* [- K& F& k2 H- Z$ P
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
3 h, d" Q$ s% @2 x. a/ @ .leds = da850_evm_tl_leds,$ k- K, f* g: K8 l
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),8 R8 `# B/ v2 {1 w: O8 |$ n+ r
};% J% ^! a- f% a3 Y. ~
5 ^. n, }: F4 ?static void led_dev_release(struct device *dev). @& i6 ^9 O: E3 W! }4 K# p
{; F$ `# `2 ~" }$ t% b$ U
};- q/ _1 n! R+ u F) d1 l
8 O& F" y5 d/ _- b; G
static struct platform_device da850_evm_tl_leds_device = {& F& E4 j& ?% Q0 r3 [6 v
.name = "leds-gpio",& c' f9 u* x% A$ t! V/ T2 Q
.id = 1,
1 c5 s# N# t9 A: Q x: g0 f% c .dev = {- _; O7 M8 G1 _. W) q) p
.platform_data = &da850_evm_tl_leds_pdata,
8 X8 L7 D9 B- w* m9 K7 W .release = led_dev_release,
* c* E8 A3 F9 B7 D' S, w }
5 O0 J5 W' Y. v$ G) d3 A};
& B/ ?) ~, ?* e. q" l. E/ Z) P7 u* K7 ]) ~ j
static int __init led_platform_init(void): Q" h+ N8 M. R9 {4 ]6 K
{
- M& [$ N0 h9 H& w f* C7 D int ret;
3 `* _! r3 ~1 F$ d9 E#if 0% B1 a( w, u1 l# f
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);( c" v' P- I& ^% d5 Y/ c
if (ret): T# Y2 n# Y; M
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
5 J4 s6 u0 ~' ^: o "%d\n", ret);
/ R+ ?( ^" U+ |) r+ [' v7 l#endif* a' {1 T6 t7 w* m8 ?
ret = platform_device_register(&da850_evm_tl_leds_device);9 V/ H) t! |8 G) v8 n. s
if (ret); {( N; ]' C! Q
pr_warning("Could not register som GPIO expander LEDS");
" X) [0 e% a: h" h2 B& G7 o else$ P7 T2 Z& J" I/ q" s# |
printk(KERN_INFO "LED register sucessful!\n");
5 p* a4 H9 ^' G7 q: F+ L# ]! [1 [3 q( ~, x5 ?6 X L
return ret;9 X" |$ x" S- _1 v
}
. p5 j4 C$ K8 \( t# R: P5 U# C$ {* k# r! z3 p
static void __exit led_platform_exit(void)2 O% u% `/ m: m9 S6 y% w
{% B1 c1 |/ p4 @; `
platform_device_unregister(&da850_evm_tl_leds_device);
. n' [8 e/ P# i) W9 o7 u
% b8 A8 |' c) Y% O8 Q% p printk(KERN_INFO "LED unregister!\n");: c6 e, L* S1 b) A9 H. o5 n$ k, _
}
Z5 \4 Y2 u3 h/ j c' p8 b0 ?( u+ t3 I0 Z4 r. V- e
module_init(led_platform_init); n J F1 m! A0 I- C* C h
module_exit(led_platform_exit);
; G L& |4 n" {( u! Z1 I4 }
9 I2 Q) c( R0 H& d7 D( D. }9 oMODULE_DESCRIPTION("Led platform driver");+ [+ X) K, r% r2 S/ n
MODULE_AUTHOR("Tronlong");6 ~; o+ `! s( s) z
MODULE_LICENSE("GPL");
9 b4 F5 d+ F' l/ m' T7 o. e; u
& }6 P" _$ p; y |
|