|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
& t! p* Y/ }! O3 ~$ U$ A+ }#include <linux/init.h>
# H4 [( l8 w- V( t# T' S; {$ y# k#include <linux/module.h>1 U6 C: N3 V0 l
#include <linux/kernel.h>: p9 M7 O b* t+ n6 [
#include <linux/types.h>
6 b3 ~$ B' A. |) ^2 ]: g2 [6 K" {#include <linux/gpio.h>) g$ Q# m) a7 `' v' p
#include <linux/leds.h>5 {0 [/ ~' a* [ U4 q
#include <linux/platform_device.h>
; i9 t3 o2 u, F3 l9 V4 k( r
- c4 T2 u1 J4 K1 ?#include <asm/mach-types.h>9 d! s! [% p2 O* f; U
#include <asm/mach/arch.h>
$ C3 U% b2 B$ q7 Q#include <mach/da8xx.h>
# h, W* r1 e/ _. T#include <mach/mux.h>
$ o2 `" c$ G: k: S; ?
; K1 z/ s2 G% N. S& J4 U+ V#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
! S6 L2 T; |6 y; b* R) B( _( R3 u% F#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)- y+ [/ s6 _9 Q, j; Z6 k
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
& P# u( s* W) H% b+ i [8 U$ |#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)6 o% Z4 P3 K3 {: ^7 a5 ]
|, R0 u: T9 g. K, x( ]7 s8 x/ k/* assign the tl som board LED-GPIOs*/
* z4 b/ [ p. Y7 [; w3 \+ hstatic const short da850_evm_tl_user_led_pins[] = {
2 L, U- X9 G* M1 C F6 x- a& ~ /* These pins are definition at <mach/mux.h> file */
# O' C6 Y, h4 Z3 i. w( o DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,5 y( A9 Z( Z5 D. [1 U% J: s
-1
+ I6 f2 ^% Z! N* i% M. M( h' `};' w: Q) Z$ z) A6 h1 y, \& _
B ^& B: c, U+ L9 Ostatic struct gpio_led da850_evm_tl_leds[] = {: _ I# A4 r8 ~7 k
{
* Q/ u5 I( }6 T# y- p! g .active_low = 0,
" m2 e/ P/ j& n) v .gpio = DA850_USER_LED0,6 E G: N' H' x: H! \
.name = "user_led0",& P( c0 Q' J' t1 a2 n; n6 Y
.default_trigger = "default-on",+ A6 H- ]9 B c% s3 P& h/ w
},
. j s; C; ]# W7 h( x# S2 y; M {
0 i8 @6 C$ R; p3 d+ ^ .active_low = 0,
4 b# k) d- Z" x+ b .gpio = DA850_USER_LED1,4 H& Z3 d: [5 o" ~. {+ O3 m5 h
.name = "user_led1",
0 f3 h) h$ [6 x, I2 ]6 ?3 \- Q. \5 ~ .default_trigger = "default-on",
9 p( J( D9 C- G2 p) s' W },
4 ~# r) Z; W5 T9 [) u1 _; U {
/ G9 ?- Y& G9 o" [1 { .active_low = 0,4 C& F8 `9 R- ]9 F) D3 n$ @, _* S. v6 ~
.gpio = DA850_USER_LED2,
9 P: [- _3 W$ h( ] .name = "user_led2",- \4 _- ~3 N2 D
.default_trigger = "default-on",
9 N7 i& x% ^& ^9 s },
/ C ^) L3 A9 s* g$ `8 e {8 U# [- G& i& e$ u' A% r: Z* C
.active_low = 0,7 o3 a5 v* n% Y6 n" `' D
.gpio = DA850_USER_LED3,2 ?% B. b' n, I* K7 S# z% r
.name = "user_led3",
# k. s# Q; Y! V) Q8 c# t .default_trigger = "default-on",
% \% }- N5 F D, _( ~) N },' }. O! [. A# i) l, O7 e# @# ]! `; p
};( ]# W( A. i: j
; `9 L1 B$ {& u0 Sstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
4 v: y, E; @& Y5 i7 V$ U; P .leds = da850_evm_tl_leds,/ I# f& `' a4 e$ n0 Y( i+ |: V
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),2 o$ z9 R% n* p) L
};
- J( N& B1 _8 F" M: D) h1 C$ z
, P( S( ^. f! Y) Q4 @static void led_dev_release(struct device *dev)
0 w- I( c& V, d) D0 J{. [, z; _& V& O5 ^, Y- B& Y
};8 X6 ] x& ?" Z' a* H
7 v2 n1 E$ ~2 Q) ^! _* G" \
static struct platform_device da850_evm_tl_leds_device = {
1 g+ E1 d7 W4 G9 N/ e0 D( f .name = "leds-gpio",
" {5 l+ b/ r/ _7 n3 f: _- O .id = 1,
$ z8 x0 ^+ w0 J9 x' s6 p .dev = {9 U* @ A* p. t. r; p( V# I
.platform_data = &da850_evm_tl_leds_pdata,
9 F( o6 F- x3 d9 `7 f& l; y. a' o .release = led_dev_release,
4 x3 H( ~/ Y- O( o6 _" O }& ~$ m+ ~: {6 R" ]+ _5 x5 ~2 ?
};
d+ V/ r3 ]& v4 [# `
: e3 w: u/ o/ h* a3 T* y/ ~1 \static int __init led_platform_init(void)# J. \2 U1 R; E; _8 z
{ ^- C+ N1 s& N7 s$ X; j% {- I( A7 q
int ret;# n4 A3 l/ K ^' k
#if 0. |2 K: B* _# Y! T1 i6 K
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
0 H: P: v: F$ K- V+ N: z' R if (ret)7 s; B( n& E: V( n# Y( T
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
8 D$ x2 w* W# W/ n2 h# Z. h "%d\n", ret);+ n3 E# {* T3 K
#endif
& U/ z2 T% Z& j$ v- l ret = platform_device_register(&da850_evm_tl_leds_device);
* a/ j! Z; k6 @ if (ret)6 z/ l/ b4 R9 R
pr_warning("Could not register som GPIO expander LEDS");
( t3 y" f' t# Y% @: [ else
% z" F: U$ E. f. n* i5 N printk(KERN_INFO "LED register sucessful!\n");
3 R3 ^* _4 E# J9 F( P5 s' m# D `. g+ e/ l
return ret;
, ?8 T/ r* I! L+ n: p/ Z}. ^* ~/ ~! b- F1 O* c. R
" P9 j5 C! x/ v- h9 J S
static void __exit led_platform_exit(void)
) N! Q3 b) D( _0 Q; d{
( ^% k+ c' D1 j/ D platform_device_unregister(&da850_evm_tl_leds_device);
* d' F; }/ N. M6 Q( a+ d0 c- ^, A- k! e2 \% i4 \8 L3 ^$ X
printk(KERN_INFO "LED unregister!\n");% N. J, d! R" z' [% q$ h& G
}/ X0 ?* r1 t+ f, {% x. T
2 g- n) M) H K3 S& A) F5 Wmodule_init(led_platform_init);
$ h% Q4 z. q P- G/ |7 o6 amodule_exit(led_platform_exit);
" O; Q* i. y' ?9 @" W0 t
N! Q, Q1 E( ^: A+ G9 z* JMODULE_DESCRIPTION("Led platform driver");& F/ R$ _8 X; O; l
MODULE_AUTHOR("Tronlong");' u; O) S& ]5 D/ G
MODULE_LICENSE("GPL");; ?2 Z7 N& B' P+ T. n
* o7 c, n$ n( ? _
|
|