|
求大神给下面的程序做注解,请稍详细些,谢谢。
2 a. T2 ?3 u3 X#include <linux/init.h>
% a% `, @! y" K8 ?$ @" r# H: Z! m#include <linux/module.h>4 g; I: Y( w0 @0 J! K: z
#include <linux/kernel.h>
, N* b# r4 k5 U$ A( x# v#include <linux/types.h>
9 g, M( x: `) {#include <linux/gpio.h>. r0 y$ E6 r. x# p8 K
#include <linux/leds.h>1 y: V @0 D2 J) A; {2 x" {
#include <linux/platform_device.h>
g z; w- x7 x- J% N8 J4 ]0 l1 u" a3 }! {5 \* d6 X! R/ [
#include <asm/mach-types.h>1 Q+ g% t, b, e0 f
#include <asm/mach/arch.h>
( Q* s n" I4 K/ ?) i7 u r#include <mach/da8xx.h>
9 u) E* \4 v+ v7 B#include <mach/mux.h>
7 c5 b t3 B( N/ X E3 s& n
9 t! u9 N$ a7 r6 ~. r5 N#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
5 V2 r) }4 H4 [' T& d0 A#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)& h m5 b* u7 G- `
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)1 e- J9 z, g( `% f8 a1 P0 U+ y
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)8 A4 A+ A( O1 |$ Z) t9 y7 ^7 v: I
, B: H1 {% M/ p) N5 Z
/* assign the tl som board LED-GPIOs*/
5 m% e/ v$ _3 \0 d0 Bstatic const short da850_evm_tl_user_led_pins[] = {- l4 M2 M* W. C) A
/* These pins are definition at <mach/mux.h> file */0 m1 G) R ^4 q0 ^7 _' H! F) x9 d% w) Y
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,. G: L! x# C7 h+ {/ S+ w
-1
# C. s) @; s* M- x. x# f};" ?9 J0 `. u' }4 D
% m4 z8 S; H5 Z8 r
static struct gpio_led da850_evm_tl_leds[] = {
6 H! P" w* \7 D( e0 l% s {
" d* H0 l0 w& d7 T# g; H .active_low = 0,+ f$ f8 y# ~5 n& k$ M2 [
.gpio = DA850_USER_LED0,
. T& G- z5 E5 n6 h. ?; q .name = "user_led0",! J7 X) i& O2 i$ ?5 j
.default_trigger = "default-on",/ h ^* `* u; k' @% H0 L5 F8 c, b
},0 l' G/ o! W# r0 c% B5 t
{
# W: _- c3 m" G) E9 R .active_low = 0,
# {- j' I n, H3 R/ P( _! e+ w .gpio = DA850_USER_LED1,
6 K5 t7 l, [ U; ` .name = "user_led1",
. ~ ^; D9 o8 r2 g2 J .default_trigger = "default-on",( k0 F' ?% p/ h9 j( d
}, `* u5 W4 O! j) i1 {& d( \
{/ N8 T0 T3 F' e6 ^
.active_low = 0,
/ x, `/ t$ m6 a" h2 K8 a& T .gpio = DA850_USER_LED2,
" E; q0 Q( Y( R4 M! [ .name = "user_led2",
* ?5 z0 Y, j4 l+ u7 S .default_trigger = "default-on",
- F$ b( R- o$ C6 _ },5 Z3 h, e, s* U6 |% n' N7 k) C: G
{
- v1 ]* X: _, _1 b! A' _ .active_low = 0,. D# }* k3 Q& i' Z6 E2 f) x
.gpio = DA850_USER_LED3,
6 R: H9 _* Y2 k8 a) V, e .name = "user_led3",% A9 q9 w! I/ B5 h G
.default_trigger = "default-on",4 @6 V2 I7 X) Y4 {1 m" K
},
! }& F5 Q9 y9 k! J k* l};
% [- n/ r) t+ s" Q2 P% t" [( F l) s8 }! g- Q9 p9 T$ U8 T8 g( d# z
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {6 ] P2 Y m6 y9 r! i$ \
.leds = da850_evm_tl_leds,
" O' H. i) o' F( W6 B; e .num_leds = ARRAY_SIZE(da850_evm_tl_leds),+ n$ }) C9 A }7 q; V f
};
2 r9 e& D) L0 |1 |- u' ^# U+ H6 @
( Q( G7 M" p7 Z, M w5 \6 J; F8 {- Rstatic void led_dev_release(struct device *dev)
& V6 C c1 ~- n0 u{
8 q9 y) ]! w) `* D5 e8 p% F, v" v};
; F' }5 N; q& L( m5 \! U8 `6 E! R. Y$ U5 \% l
static struct platform_device da850_evm_tl_leds_device = {
8 p: d. [$ m+ o& u- s" ~ .name = "leds-gpio",
8 D' y0 O* Z( |+ H' I1 A .id = 1,8 C1 x* s% a6 J$ c3 }7 b
.dev = {# b% O1 a3 A- N3 f0 y/ o
.platform_data = &da850_evm_tl_leds_pdata,
/ @" Y9 n9 d/ Y. S1 y0 x .release = led_dev_release,+ f# ?# @- b, F( V+ t
}
0 x6 L$ b N; |. F3 Z; q};) T4 N3 e0 t7 o! p
9 y% B- b2 ` L" p" t, g( {' x
static int __init led_platform_init(void)
0 N8 O/ F- L7 J9 g{
4 |3 W! P4 {& e: Y5 y) n8 |6 [ int ret;- M& z$ z; C; Y
#if 0" i/ {' I7 f# ^" W0 z* |8 d2 `
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);$ w, \5 j6 U% Y: b. L- M
if (ret)
- d4 o2 T- V( e: I( F0 v7 d+ d pr_warning("da850_evm_tl_leds_init : User LED mux failed :"$ S* N( L2 t* p
"%d\n", ret);$ q: I: y% t* T
#endif7 G$ D5 }: Y) m
ret = platform_device_register(&da850_evm_tl_leds_device);( s0 O/ r/ j) l3 P& I h- r$ q
if (ret)
! S3 Z& `3 s2 _% l# b3 S. H pr_warning("Could not register som GPIO expander LEDS");
8 T# y' s4 B, }7 ?' g9 k- i else6 z5 {$ q" X( Q6 C
printk(KERN_INFO "LED register sucessful!\n");( V: n+ p3 S; x% ?
6 Y* M% x4 x2 L+ J) G; j
return ret;
% d6 A7 H# q' d3 k: }# i}7 X q1 Y" G$ M( ?! {7 z
* p% `8 f. ~" f) U: p# l+ k+ `
static void __exit led_platform_exit(void)
/ T' \. y2 n" V{% P$ F8 `9 J9 o5 M
platform_device_unregister(&da850_evm_tl_leds_device);0 f' g$ Y! G1 B5 _2 J
' S, K1 s% K, E& Y) T
printk(KERN_INFO "LED unregister!\n");/ Z g) o( H/ n
}0 N9 A% O. ^# @4 U. i: K9 n
! t: M2 ]2 s3 k/ F
module_init(led_platform_init);+ }, f6 ]0 W4 \" W
module_exit(led_platform_exit);
! P" p( B! I- w% f/ O1 B
. E- `4 h* ~4 P# S6 @; `7 RMODULE_DESCRIPTION("Led platform driver");
# x8 v9 \; U' ~+ M4 W ?; X% QMODULE_AUTHOR("Tronlong");4 V9 Y0 r3 A% a" O, B
MODULE_LICENSE("GPL");1 T% k1 q; |! l
9 W" |' }+ x+ n6 N5 ]8 U3 l0 I* q |
|