|
|
求大神给下面的程序做注解,请稍详细些,谢谢。) S/ K7 Z1 f' t, N Z
#include <linux/init.h>) G8 M+ b! [* H5 o6 B! y
#include <linux/module.h>
9 x t( P* d0 r6 x/ ?1 U6 {#include <linux/kernel.h>
7 E! Q, [ N0 C#include <linux/types.h>
$ X4 l# Q* m X% w+ ^ |#include <linux/gpio.h>
6 M; }0 B1 d2 q+ l! A0 o1 @#include <linux/leds.h>
4 l% p, ~& z) I! z5 ~# K) x& O& i#include <linux/platform_device.h>! K4 N3 e% O4 h9 l
: v& @( H7 J# p% ?1 N9 F; n- m
#include <asm/mach-types.h>7 b4 H' F5 x( X
#include <asm/mach/arch.h>6 X6 ?5 ^0 g. l8 S9 W
#include <mach/da8xx.h>
5 J- p- `1 G8 ?. s9 I. s9 M) Y* {% o4 v3 M#include <mach/mux.h>( J1 g' w; D& @5 N3 I7 x3 j
( w$ P( v5 f# p, _" Y/ u, ]$ s#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)6 C" ]8 M* L) |( Y9 p2 r k0 v
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
* [+ r9 x& D! s* n. |. M#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)- ~) t; v# r4 w! ~/ ?
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)7 }& I& t/ V$ h0 G: D+ O% j: e
# e, @# R! J0 N! l6 T# n, X
/* assign the tl som board LED-GPIOs*/ @4 t: R' Z9 s$ w7 z5 ~; {. [
static const short da850_evm_tl_user_led_pins[] = {, ^2 Y" d9 L0 u9 v+ h% |
/* These pins are definition at <mach/mux.h> file */0 [- I' d: ^7 E( x! x
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,8 x. x3 U" j2 E( b. [3 j1 G
-1' M& z5 {, w) M, M
}; e5 Y; \% p) g/ s+ b
/ X/ O7 a0 b/ g' d& |/ r9 Vstatic struct gpio_led da850_evm_tl_leds[] = {
+ x! [% q; X! L i! ?4 R* c" J {4 N( I, y! v+ E- a5 w' \& P. N2 u
.active_low = 0,
$ i4 i" M1 d9 c& U( ^1 X1 O7 U .gpio = DA850_USER_LED0,4 w# g# Y% {/ Q8 U5 G
.name = "user_led0",
9 F7 b) X! K5 W/ o .default_trigger = "default-on",
4 C) q0 \5 s2 S! P" U },
& o$ n! s' e, w% \: H9 S. j! A {
# o. C( m u C3 c0 r3 k' N# { .active_low = 0,( h8 H! E! @/ ~
.gpio = DA850_USER_LED1,5 t( d9 u9 Z7 j$ o7 r; k
.name = "user_led1",, N0 L& w* j- U+ W& @' w$ ?
.default_trigger = "default-on",6 s( H- y" O, N& i( u h
},
# v, [& \2 F2 D+ G5 u( f8 O {
1 F0 r+ V9 |5 T7 C, V7 j; l3 o/ r( N .active_low = 0,: U) C; n# V, W7 j) i
.gpio = DA850_USER_LED2,
' G' l% z' O8 A .name = "user_led2",
8 x& G& Z! h. a. o4 L .default_trigger = "default-on",
. c) A5 y+ F0 l6 O% `3 o# t8 d },
1 F$ X+ A G, L! j d {
, k0 w3 C7 S& k- A1 `/ t; F .active_low = 0,& P* s. y' q- y5 G& o5 O9 ~
.gpio = DA850_USER_LED3,
9 C- l' b$ p ~) R .name = "user_led3",
3 n3 H' L! y6 X O1 | .default_trigger = "default-on",
N2 P6 z' l$ a' [" [ },9 P' I, B' V0 f: x' Y r/ P+ A
};
1 ~, j; h+ t- @6 t. |/ `+ b) e3 h/ t. j" A, {' I$ f! M
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {4 o* \9 G" Z$ q& l* ~3 J1 R' l
.leds = da850_evm_tl_leds,
# `8 A9 y9 E9 X) Y% H5 u% x, t .num_leds = ARRAY_SIZE(da850_evm_tl_leds),. g7 t8 {) |. W7 |
};
3 ?0 c" t7 c$ L. z$ ~+ f4 R7 I! C: k8 K6 e1 T5 n
static void led_dev_release(struct device *dev)3 \2 s/ P9 @2 p) D4 ^
{. |1 e6 f9 E# }8 g3 w2 }5 v
};/ o& n+ f! `( n) {
4 l9 F5 z o6 ostatic struct platform_device da850_evm_tl_leds_device = {" S% \8 i7 O- X$ w) U2 u# ?
.name = "leds-gpio",
) O9 H0 c9 ]- |, w2 {, K" D# N' X .id = 1,
! X7 `$ p' `$ D+ b .dev = {
, M+ K% q) m0 K8 v8 @) N .platform_data = &da850_evm_tl_leds_pdata,& r% |. i5 S4 y+ o9 I8 s0 A
.release = led_dev_release,- v5 s' g6 ?; _1 O; a( ~5 N; R" N' F
}5 M( w' m* `7 d3 Z& y
};% s3 ] I9 h9 G
3 `- g$ t( s/ z3 g) ^. estatic int __init led_platform_init(void)
/ {1 l( {' L7 ^& ?% K) _2 H" K' ?{
) H0 Z; I' [) n l# g int ret;
4 \% ^( ?5 K& F7 g8 a#if 0
& w- }$ z/ W: e7 Y' X5 R2 x' B ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
. f& C/ g! f& X$ z0 X$ c3 B2 n if (ret)
5 ^. O3 T: S. v. C8 n R0 H% {: O$ G' t pr_warning("da850_evm_tl_leds_init : User LED mux failed :"* {. Z, Q2 K' O
"%d\n", ret);
: t! D7 d: T: ] |9 e0 I, d#endif$ @7 w2 T2 c; A7 _: F
ret = platform_device_register(&da850_evm_tl_leds_device);
% J3 w4 k. {6 [* I1 h* X if (ret)
: \- d9 Y X+ o$ H2 a7 ~8 Y pr_warning("Could not register som GPIO expander LEDS");7 H' x, d# V0 R3 l" G
else, u" R$ U4 F3 X' i3 K2 Z& h" I
printk(KERN_INFO "LED register sucessful!\n"); J/ f, X0 c! o+ T
" x$ t. i1 ?$ p: Y# k2 U% B0 [7 @0 ?$ e return ret;- ^0 o/ ^& ?! Q3 R
}
' m. ^7 J: @8 `1 H
" @8 s, O) c9 m% Z. n- Zstatic void __exit led_platform_exit(void)3 d) \* ` Y* D9 h2 A4 G+ k! n
{
( I( M) {- C j2 w; M4 a platform_device_unregister(&da850_evm_tl_leds_device);" O2 L* W) [! Y; f0 x3 G
7 K- F. Y) a' w. D3 s, v printk(KERN_INFO "LED unregister!\n");' C3 f- c! d! _( c& g8 A1 S
}1 g2 ] r1 w7 @0 v
, `6 ~) N# r5 r, |" r+ p
module_init(led_platform_init);6 G, Z: R. m5 B! P
module_exit(led_platform_exit);6 d+ S* F" f: I7 c2 A! G
) g( }8 @* O% @- H+ AMODULE_DESCRIPTION("Led platform driver");$ H' @1 Y8 J2 Q7 A8 a9 ]0 X3 ^ `
MODULE_AUTHOR("Tronlong");1 p8 P" V T) n9 w" F
MODULE_LICENSE("GPL");
) y9 ?: e2 _2 c1 C# R8 D0 y! C' y: k/ {
|
|