|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
: P; E0 h, I; Y) K1 b }#include <linux/init.h>) @5 ]9 x c. s
#include <linux/module.h>
3 R8 N& j1 R0 G! n0 ?5 _#include <linux/kernel.h>
6 a: j0 ~ E8 G4 d, s) c' t' r#include <linux/types.h>2 R# Y8 }2 t3 |
#include <linux/gpio.h>3 a: u* S2 \; r. G' j
#include <linux/leds.h>
3 P4 ]" Z; ]" e7 Z9 y, R3 g#include <linux/platform_device.h>
. p4 q! m. g; N9 {4 ~, t0 X, P$ E6 l* ~
#include <asm/mach-types.h>
2 z$ E F/ ~2 H% \3 P" m' V1 R#include <asm/mach/arch.h>
5 V" ~+ J2 I( a; m& x! t, @1 \' t0 A#include <mach/da8xx.h>
: c# {8 y- a8 {2 G, j7 F#include <mach/mux.h>- n7 i" [" r3 ~. z v7 i k
1 n" w) y/ D% F0 b5 g# ?" `#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
' ^6 G0 o. q# k#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)' x" { O4 o# d- T5 u
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
2 I* R( E9 }% M/ d- P+ I#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
' o7 e5 z1 C& B: A/ _8 V2 I# x9 J: Z4 ^9 R+ o6 W' v
/* assign the tl som board LED-GPIOs*/, a3 [; c, ?+ N; d' k: l
static const short da850_evm_tl_user_led_pins[] = {
8 \( x- k* f: S1 K /* These pins are definition at <mach/mux.h> file */! I. R( _2 D! Y0 M: F/ S
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,* `2 O+ x/ e- E3 ~* ~: D
-1) q r- S: D. x# a3 L
};
7 F. s" q8 m3 A! F- ~5 s/ T
" h( _+ ] w& j( W( s% Dstatic struct gpio_led da850_evm_tl_leds[] = {
5 r" s ~: ]9 X- i' b. f0 M9 h {
; {0 H$ n4 n% P v .active_low = 0,: g# {5 r% q, c) g1 |$ B
.gpio = DA850_USER_LED0,
% W7 Z7 b2 j3 R4 [. V2 P9 z, { .name = "user_led0",- P/ a) y5 { p! s0 G6 ]
.default_trigger = "default-on",
_+ Q( X1 j% c6 M( v+ \ },! N) O6 y H7 n2 }. [
{
( A5 E, o) ^. r: \( s+ o! i .active_low = 0,& }5 W( v U" a" \
.gpio = DA850_USER_LED1,
: w4 j, Z3 u; Q9 ?& r .name = "user_led1",4 A M3 l. B, a# k2 C% \
.default_trigger = "default-on",8 E7 ?" R: u% G! `# ^* i
},
0 s! ~5 ^( M8 R# A {6 f4 Q$ r( E7 i' p g4 `
.active_low = 0,
! z/ `3 R* L! K, o- t .gpio = DA850_USER_LED2,
0 [- {# T, o, G6 p. b: ~5 m .name = "user_led2",
: N2 A. l l7 W0 p/ ~ .default_trigger = "default-on",
8 k" ^; Q# ^# E# I( M },3 W+ C5 h6 W0 j+ @
{
' {# c$ A8 A% ]9 s2 I .active_low = 0,
- E- H' K) F7 ?9 E) r/ Q- r& O1 n+ A .gpio = DA850_USER_LED3,
/ e% Q' C5 l# y- [8 W5 f$ Z( @2 c L9 | .name = "user_led3",8 s1 Q1 d9 ^! n2 T* B
.default_trigger = "default-on",
) h% G5 }- B% K2 B: e" l" I },! a2 D- Y1 n3 w1 O* H
};
6 k7 s3 H" {& U/ W6 r* M" R* e8 v
& ?) }% M) D. i" J" A* X0 x) z5 ystatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
, ]& n) g# i$ l; v .leds = da850_evm_tl_leds,
0 T% y' z2 T9 a" w j2 S& [ .num_leds = ARRAY_SIZE(da850_evm_tl_leds), [* L: X2 U: f
};
$ E, T' m3 }3 c+ X
7 r; g, F9 S" r( k9 F' A) U* G# Mstatic void led_dev_release(struct device *dev)
1 x4 ~1 t3 B$ x( `{
6 o! g- s% b% K- v) f0 J};
) E, H4 X/ A8 ^* } t9 H0 I) Z. @) F( s0 ~# t3 x1 w# d) J
static struct platform_device da850_evm_tl_leds_device = {/ l; E2 R7 i: ]6 s3 c
.name = "leds-gpio",
4 m+ P) d$ D2 n+ q .id = 1,7 Z. H- ^3 ]2 c' B; G @
.dev = {
" b( @4 m/ b( t* h3 g1 Z .platform_data = &da850_evm_tl_leds_pdata,1 m& M0 T+ {# I; V. B
.release = led_dev_release,/ N& X; Y0 @: V9 t" S
}" X* N& T2 U6 K1 c+ E
};4 N% T& ~0 ?0 u3 k
$ n9 R( c0 u) W: V, d# v5 A5 q% D3 @7 g
static int __init led_platform_init(void)* B+ N I& ]; B( J M0 `
{
0 E+ L# O/ x8 W, y1 K9 g. j int ret;
; Q1 G, ] L: y" m) Z% v6 y4 l- A) q#if 0* ~8 ^4 K8 @" S: y- m7 L
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);" J/ M, z* z. B0 X& F2 q
if (ret)( h [' Y& A, w: f' q
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"4 R1 m5 b" z' |+ t5 y+ }- L
"%d\n", ret);9 P& j' T9 c3 ]: i) u
#endif
1 ^) A3 Z; w9 Q4 |+ _2 k ret = platform_device_register(&da850_evm_tl_leds_device);
: E# q' d, W4 l& |/ R: R- V; D if (ret)+ x5 W+ e; y ]( x
pr_warning("Could not register som GPIO expander LEDS");2 g1 G( j% {$ C
else$ ]* r2 k2 I8 @6 j( U
printk(KERN_INFO "LED register sucessful!\n");
$ |3 K* U3 D: O' i5 R4 T
. |. ^; m3 p T7 l* g return ret;
* K# O/ l# @& f8 t9 E. ~: T}
) N( a2 q7 L) E1 a* Q, z0 c& j$ V' P: @$ q* `+ s1 J; Z/ l. h! E
static void __exit led_platform_exit(void)
4 `$ ^# h( b* D7 f9 F{
* d6 A/ s0 ], m+ {' V% Y0 T+ [+ p platform_device_unregister(&da850_evm_tl_leds_device);6 M% ^) H6 D+ G2 p$ R: a8 o
; M, ^9 w' K, ]3 i' U printk(KERN_INFO "LED unregister!\n");
( j$ |2 f. k3 u/ ^}
# O" m( i6 j8 N2 l
: J8 f7 M# _( ]$ w: F( gmodule_init(led_platform_init);! H7 }8 R l( T" x
module_exit(led_platform_exit);) E$ c; E R+ S% |. M l. f" K6 |
n# h2 M0 y1 A; J, W! R
MODULE_DESCRIPTION("Led platform driver");
" n( w% w; N3 k0 P& o1 mMODULE_AUTHOR("Tronlong");7 u. F) W3 ^( ^$ Y. A) B/ g: V6 H
MODULE_LICENSE("GPL");: Q# R- T( p/ w, @: M
7 K, O- x9 K$ m+ {5 C
|
|