|
求大神给下面的程序做注解,请稍详细些,谢谢。
- ?& T; q/ o$ S#include <linux/init.h>
" d+ }. N# d" h& J6 h/ P: f#include <linux/module.h>
% E' r7 O! \6 S: I" |7 L#include <linux/kernel.h>
5 B) E: N# \) P: `+ q" D#include <linux/types.h>: O* h* i( Y7 s4 B" Z6 S5 `0 x
#include <linux/gpio.h>6 q+ g& p S" p8 z7 J: D; m9 d7 [
#include <linux/leds.h>
" y6 Z& v1 A( R' f7 g0 x#include <linux/platform_device.h>
- ~* |; ~8 U, S8 ~' T( r, w: a$ {$ X. B' `4 f0 T+ G
#include <asm/mach-types.h>/ G" X& E8 Z* Z( h
#include <asm/mach/arch.h>
% O3 Z, R' g0 y' T# f#include <mach/da8xx.h>
$ W( k" _! S! d' C#include <mach/mux.h>4 ]# w5 C- ^3 e" G/ U" }! y
S; g. \9 y0 N#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)0 V6 M- y6 |* o T$ _0 e" \
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)6 x) z8 t) \4 |2 ~) \
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)! l7 y9 Z& w: a/ r
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)/ i2 i4 J W: ?8 N
6 @6 C; E% n% A. p/* assign the tl som board LED-GPIOs*/9 C( }- \3 \3 k2 c& h. T0 b
static const short da850_evm_tl_user_led_pins[] = {
6 a8 S9 {- j9 ^! `! b8 G8 C /* These pins are definition at <mach/mux.h> file */( ]# n2 H( M7 l) }* j5 |
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
6 O, l" o3 U. U$ M( h2 ?- j -1. N' @( v) K5 q/ D% m% J$ \: G& `9 Z
};
# }0 v6 P) m# d# s+ @. x3 D3 d) ?4 z% c/ b
static struct gpio_led da850_evm_tl_leds[] = {# z+ B( r8 j" W2 Y
{
- a/ u' c( j8 O( G2 A1 T .active_low = 0,
, @0 f$ ~: Y3 ~0 w) y5 F( A1 i. ~. S: z .gpio = DA850_USER_LED0,
, ~- t0 _ x: M) Q" H% x& a: f .name = "user_led0",: ~- D1 d6 e2 X1 m+ P
.default_trigger = "default-on",4 W. `) |3 ^% q# y9 n
},0 e: D! N$ N& j1 Y0 `: c
{# d5 [4 _) R- r4 ~) Y& i% E$ ^$ ?
.active_low = 0,! ^8 e& V+ t, o8 F+ |
.gpio = DA850_USER_LED1,
! E! y) O5 x3 ?6 Q .name = "user_led1",
9 m, ]4 W6 m. D2 d .default_trigger = "default-on",
# p2 V, x7 E# D) q& Y$ A1 O },
4 V3 ^$ E2 m$ e4 _' l9 B+ b {
; V- T5 G+ O2 w0 E+ }) ^0 |+ V5 Q2 m .active_low = 0,1 {* R( x C/ [. n: t
.gpio = DA850_USER_LED2,
* O# d1 N( c& n6 X .name = "user_led2",
" ]0 \$ M* k# L9 L& c' J) F- U% H .default_trigger = "default-on",
* Y0 o+ h3 z( e }, N, c& N v3 e: {
{2 D F' m* S" o ^: }2 z% D; U
.active_low = 0,- d3 ^% d6 o9 p( a6 I4 }, J
.gpio = DA850_USER_LED3,
V: l" L l& h- L7 V3 ]5 a .name = "user_led3",6 ?% ~- q, L& X8 ~4 E& A
.default_trigger = "default-on",
* K3 h. A1 S6 I2 X },
4 f: ^2 V2 z8 g! P9 X+ y};- R0 j( s9 h5 l! M' P6 d n! a
8 n* L0 r0 T: C- K1 N3 }- G: ]
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {, U! C! P" P4 W6 m
.leds = da850_evm_tl_leds,7 D8 V1 v" ]" P7 M; {) T; B
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
! v7 J, k4 z" i$ q X- p};
- V# T4 }. F9 J: u2 ^2 @" ^- v: y- s8 G6 f$ q$ o2 j7 I F0 z
static void led_dev_release(struct device *dev)
! T* V. x- E0 d# |( G9 _{$ s6 T& i! @" b
};
4 a2 Z3 p" |% M+ M% O" @
, N! f" ?/ y2 q: f$ K2 T& Rstatic struct platform_device da850_evm_tl_leds_device = {
?3 I7 J0 M& b3 X: c4 j4 F .name = "leds-gpio",
7 s. T: @) r5 u9 ~1 f0 k0 w .id = 1,$ g8 K, P; p) ^2 f* {2 x- ]% ~3 g
.dev = {
8 I4 D. n& t1 s$ e$ p& q1 A .platform_data = &da850_evm_tl_leds_pdata,
" O* B5 H3 p6 p8 Y9 P6 M .release = led_dev_release,+ J( J5 _; y8 U2 _* j
}
/ e# d8 Z( q/ M5 S};
- f: D3 u4 f2 H7 p: a, i
. j# t4 v' a$ C1 v u& z$ }static int __init led_platform_init(void)$ z" A, v9 L$ S/ E. m( g# n6 h
{
+ m3 [7 K! j3 U int ret;
0 t. H) K8 Q6 u7 i; U* l#if 0
g8 t9 n; e# C9 ^8 q3 a5 {. a ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
% B6 |4 s( m2 G% P- x if (ret)! Q9 E( q+ i! z9 X* r
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
) }: ~1 C. w1 c. ^ "%d\n", ret);
[: `% b7 w* o1 }6 w/ g3 M% F3 \2 @#endif
/ }- X& r* e8 }5 M3 t ret = platform_device_register(&da850_evm_tl_leds_device);
/ S* J9 k" T- F1 L if (ret)
$ G! S' J( K. I& k4 [- c pr_warning("Could not register som GPIO expander LEDS");. ]) M$ T. }4 t+ N5 l R' ?' d
else
; y! j1 B- i- Q0 d' ` printk(KERN_INFO "LED register sucessful!\n");/ Y4 l% W) i: t6 A* ~" k$ P
0 B! @' M7 Y# |! z& e6 v! L( S0 b
return ret;
: z1 l/ p7 X, d( I( H}
% k6 x+ k0 Y: i3 D* s" Y m3 ~# M. {4 q/ W% |
static void __exit led_platform_exit(void)& Z. t/ [. B3 [. m
{
- I/ G9 f9 {* M8 P# F platform_device_unregister(&da850_evm_tl_leds_device);
) [. v, Z4 R4 j! e5 z! b5 E5 k6 h( A
printk(KERN_INFO "LED unregister!\n");
# }. n2 L0 o4 E9 i2 D9 T/ P+ R}2 i/ h0 ~: X" @' C" E8 y5 \
, ^7 v7 n) M }6 f: F; q; `' Y) j
module_init(led_platform_init);; d! I' u7 Y" l! g
module_exit(led_platform_exit);! r2 x% t& v2 u3 }4 X
( o' f* Z5 A) k+ ^4 P. n
MODULE_DESCRIPTION("Led platform driver");
$ j. h- C- ]. ?8 x5 VMODULE_AUTHOR("Tronlong");
8 b7 }* c$ N' D% ]" @) jMODULE_LICENSE("GPL");3 r4 g9 q/ @# S" s2 s M
) }, m7 t% O1 Q$ F6 \
|
|