|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
; F4 |* d/ K. q8 w+ r3 S& g#include <linux/init.h>, x) P! N9 _) f: W; q0 I: d
#include <linux/module.h>
6 ]# d9 D+ O3 o) e. @+ p#include <linux/kernel.h>
; L, |; u3 g$ G7 f" W Q; t" r1 X8 t#include <linux/types.h>: D2 G$ }: X# f, s1 M$ K$ X* w
#include <linux/gpio.h>
8 S G+ k7 H8 p5 h6 b#include <linux/leds.h>' b! e4 u9 Q ~0 U. S7 n# C
#include <linux/platform_device.h>: x1 i/ q4 ~1 S8 N& L
, N) f, q5 \5 t. W
#include <asm/mach-types.h>
/ W5 O" P( p9 @2 A+ i#include <asm/mach/arch.h>2 L) r! p: U. m9 k# I
#include <mach/da8xx.h>
/ p# s/ L* n8 l! u#include <mach/mux.h>
2 z5 W# C; M* O0 W7 C( d
! w! M8 G* P% j k) ~' z) ]#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
. m8 }9 O% {2 N" J6 }: j#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)3 m, g% [) s: q) L$ F) `
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)% F3 |' V* d ]: }& w: o
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
/ Y3 g; ~6 t3 K: L
! v& i7 {' F: H/ ^9 C9 C/* assign the tl som board LED-GPIOs*/
0 l6 z$ t) o$ |static const short da850_evm_tl_user_led_pins[] = {
+ }1 j$ }/ Y x, [ /* These pins are definition at <mach/mux.h> file */" }1 A" e1 h+ X$ _
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,, j% r" x) I3 y* E
-1
' o* [. ?. k+ C8 R* V' I};. I1 V0 b1 b* s' X" T& a
3 k- O! u5 t+ }+ wstatic struct gpio_led da850_evm_tl_leds[] = {
$ ]! i0 T% G% ?) w1 x! b# ~ {
/ a6 x+ j) H+ R9 w0 j .active_low = 0,
# f7 d' k9 |% ] e .gpio = DA850_USER_LED0,
6 a4 t v: T) P9 f9 r# `3 P8 a .name = "user_led0",( T# F# u; ^$ w# C( ^$ Y
.default_trigger = "default-on",
" F" d4 [( i/ B! |+ m f },$ x: l* _4 S3 j: r; ]
{# ^8 S9 F! @( y) b6 f& A2 X
.active_low = 0,
- b; t4 x! T! `: |. E .gpio = DA850_USER_LED1,0 F" c; ^8 [. a3 }
.name = "user_led1",7 B' B3 L: S6 O
.default_trigger = "default-on",6 s& B. `/ v, G
},
7 r; C6 e5 k1 V9 @" A! a0 d4 | {
; W' S( \& B6 k$ @; h .active_low = 0,) x4 @7 V" Y' n7 {8 q" D
.gpio = DA850_USER_LED2,/ \) x* W) v' d5 [6 v
.name = "user_led2",
3 U+ E- T. E# ]7 ~# e; O A R# X: ` .default_trigger = "default-on",
. g( \, v5 _! p: J: D' x },
. l9 a3 q* t. z3 A% p, F1 E. [ {
/ u: f: ]+ p' r' ] .active_low = 0,
% m) K" g: u- w! G S( o% F .gpio = DA850_USER_LED3,
# h" Q* T$ s3 J8 L4 Y9 G7 j; q .name = "user_led3",9 c! ?: }/ m+ ]6 G4 q7 C
.default_trigger = "default-on",
. J( e2 s3 ^* Z },
3 B0 w; w# |0 S" N8 g};
, Y1 H$ N9 O& u0 s. l5 @
1 }4 `2 m) ~* D5 c/ g2 X: ?# A$ Mstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
) e/ f/ ]3 B& ^ .leds = da850_evm_tl_leds,1 c5 O' B. \! k2 p8 x
.num_leds = ARRAY_SIZE(da850_evm_tl_leds)," f8 A3 d6 R4 ]" z
};
& W1 h4 k/ s, {6 r: `- K' Q- q
( Z, i- n7 J$ C0 X: ^2 v5 nstatic void led_dev_release(struct device *dev)
Z; T1 r& X/ ]9 x5 ?1 X* o/ q) z{
7 k4 }, _- f! C};3 u1 n% n6 Y; Z
7 H7 ^) T8 J! m q: P1 Q" B
static struct platform_device da850_evm_tl_leds_device = {1 C3 o: m7 [( o
.name = "leds-gpio",3 K' G8 b0 \0 n( j. j( W) s
.id = 1,7 u/ x& T) n# K6 O# G9 Y) N- u+ P- `
.dev = {0 J1 v, b5 G- C. _
.platform_data = &da850_evm_tl_leds_pdata,
& O' C4 m+ ^& ? .release = led_dev_release,
) q2 P- l0 O( x }4 ^% w7 l3 |8 u6 b4 f7 [8 P
};, Z/ t9 V- K7 F* B9 r- }$ n9 g/ i
# m$ F7 A, l Z9 E" x: M( q
static int __init led_platform_init(void)
0 B$ P& c( E" ]6 \{# D0 S* W" O% @4 G
int ret;
6 F0 [% m: R5 n7 n' [; M* Y8 g% p#if 0
! z9 \9 V6 P% i" h5 B ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
8 A6 ^/ X3 m- X9 w* R/ u4 o5 j7 ` if (ret): H4 ~; l$ T' M5 f# D
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
. q* g" o1 A. ^! z4 h1 Z Q( \! c "%d\n", ret);
( C8 X5 n3 G# A6 Z#endif" M' ?5 V/ h/ z7 H* ~% p3 m
ret = platform_device_register(&da850_evm_tl_leds_device);8 ^6 Y6 Q& X4 x' x
if (ret)
: ^ R# S6 z% A( z' K pr_warning("Could not register som GPIO expander LEDS");5 B- G7 a% T( f$ [4 ]9 u7 Q
else
" M$ C6 A1 b! T& L$ U1 E printk(KERN_INFO "LED register sucessful!\n");& z& ~ k2 o0 {+ ~0 l3 g
- b+ `' K) m$ P, k
return ret;7 ]! |3 ?) q9 S2 X2 j3 |7 _
}6 |* X; P( X( W# J: }
; D) b% Q7 v8 _# [" V. V# P# i
static void __exit led_platform_exit(void)) ~/ G# r& ~5 g$ f; n
{
5 K; s0 z# m. G' U* N; n platform_device_unregister(&da850_evm_tl_leds_device);
1 B/ K- U0 u, h7 b5 V. _" V6 Y$ M& o) }3 Y4 n! U" B1 G$ o$ p9 \7 J
printk(KERN_INFO "LED unregister!\n");) R6 n! z, F ?. u4 x
}- k: y2 B* k A( k+ c" X2 G
" M; a& y# a3 m4 c* S
module_init(led_platform_init);, o$ @1 N: l; ?9 L% _; G% {
module_exit(led_platform_exit);
$ R7 D& f2 x# b3 n6 l& V+ G( O; X1 R: A! |) @! Q1 B
MODULE_DESCRIPTION("Led platform driver");
& c3 T5 P1 ^6 n/ C& oMODULE_AUTHOR("Tronlong");
! r7 Y! x# y: Y% l; gMODULE_LICENSE("GPL");/ v* ? o9 L5 E
) x1 `! ~4 B: x9 C$ | |
|