|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
7 g: y$ u5 m. `7 R7 o+ h#include <linux/init.h>
& R( T2 K0 d: U9 N6 R0 R. x#include <linux/module.h>
3 m X$ {+ j# g#include <linux/kernel.h>
. b# N# H$ H4 u7 O( f+ n8 E% u6 V#include <linux/types.h>6 F( ?5 Y( i$ u7 j7 g
#include <linux/gpio.h>" [9 D9 Z) f+ j9 u4 I
#include <linux/leds.h>
- o+ ]8 f; D# i, k9 V; h& j#include <linux/platform_device.h>( Z3 {0 V; u6 \+ F* h# J& }
" D, ^9 O% Z- t; }4 w& m#include <asm/mach-types.h>/ x2 X7 E: o$ L/ A- |
#include <asm/mach/arch.h>
( B1 m# G0 t' d#include <mach/da8xx.h>
3 b# E% t# n/ r( x#include <mach/mux.h>
$ w" M# `8 \7 A" u# \7 s9 E! f( D% f
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
$ m( `1 u% C7 G/ ?, n! Y#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)# [9 Y6 [+ H$ [3 M! k6 r$ l
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
% g# a7 w$ p; V. c2 D#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
- v1 X0 \" i; A6 n+ x9 Z1 W# i" K9 `, i2 V
/* assign the tl som board LED-GPIOs*/! m; v- C8 H4 ^; ]
static const short da850_evm_tl_user_led_pins[] = {$ b" x7 `0 L1 g0 f7 y4 n3 ]* k
/* These pins are definition at <mach/mux.h> file */- I- h& U# R/ \: T0 C
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,- \! {6 u0 s0 U; G. R' `$ q3 v4 R
-1
6 u- ]4 X) h& i# H% S& z1 q! @; p% D" Z4 D};
) P& u* f+ o* ~8 `. z% \6 @- M5 r5 W2 C" Q
static struct gpio_led da850_evm_tl_leds[] = {
- x! e1 z. @3 I4 M* Y! ~* e {
% A5 m3 O. }8 _+ \) x% G .active_low = 0,
2 C& U. x7 ^* L) \ .gpio = DA850_USER_LED0,3 f& ~8 A5 x" P1 f$ W4 v
.name = "user_led0", l1 c- T* C8 u( _
.default_trigger = "default-on",! S6 H" \1 G6 R* n V# w2 F
},
; O- a* f; `5 _$ i/ Y {; k0 k) ^ a# i8 w
.active_low = 0,# P& B8 r) I) i! @
.gpio = DA850_USER_LED1,6 J8 p8 l/ G( A% a7 G3 u
.name = "user_led1",
5 Q$ G: W5 S5 {& _( n' ~+ ] .default_trigger = "default-on",% d) B# s+ h- c0 v
},! q$ k8 V, f/ M4 l5 L8 T2 {1 d
{" B' X% O+ m: N" A1 U: I
.active_low = 0,0 u6 ~/ S. S# W( }3 p
.gpio = DA850_USER_LED2,- P' c/ Q/ R9 l' Y2 L
.name = "user_led2",
/ P+ x& b- }3 i9 Q* ^% C .default_trigger = "default-on",
# h8 J- \9 C+ q# s9 m; G/ ] },
9 n7 B# r% N3 L6 v% D {
$ _$ q: b% M& g4 ` .active_low = 0,
, @7 |( P+ F9 u" v9 m* Q& L3 W .gpio = DA850_USER_LED3,
1 [% o2 @/ }8 G, e% _ .name = "user_led3",
: N j/ y; ~& P# [ .default_trigger = "default-on",
# O! n+ O- L- m- i: L7 j4 h) F6 ` },6 ~( U4 X- H; K- M
};
0 m, ~: E0 x7 [: f9 J1 K9 q. y8 G6 G- L+ w& \6 C+ n. h: [/ e; j' f
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
' g1 n1 X, |+ w .leds = da850_evm_tl_leds,
. p* T4 O' y3 X( A& g3 Y; x: C1 _3 z .num_leds = ARRAY_SIZE(da850_evm_tl_leds),7 K8 r9 Y# @8 ]) U! c% B0 @1 Q
};
j5 M7 p' ~1 M0 X4 L# z- L8 ?4 T ?
static void led_dev_release(struct device *dev)
& }& _" ~ ~1 `; C) R{. c. u& V, j6 X3 J+ |1 |2 m
};6 U' \7 t- R% ?1 H. V
8 O, ^8 x, q) @
static struct platform_device da850_evm_tl_leds_device = {
+ Q8 {% d( [! O W* B: S( e, l .name = "leds-gpio",- r( d, f/ ~6 n- o
.id = 1, T; b/ e) O% y" e' v# p$ u& V2 P
.dev = {
/ G" J ]) C8 s7 ^2 L7 w .platform_data = &da850_evm_tl_leds_pdata,* x8 n* g/ p# H" B& m, g
.release = led_dev_release,
8 Q0 u3 x6 q* z. J8 r }3 o4 U j M6 n
};
# E1 V! g4 |2 q) O. G! E1 a
1 A$ Y! ^3 {: {1 x4 C7 {3 ~static int __init led_platform_init(void)4 G% q# Z& n' S1 Y
{' j: _! s- P, P+ _2 ^; c1 L
int ret;! ^4 b: Y$ e( U: A8 r
#if 0* }0 e& f1 Y5 v$ Y k1 Q: l* x7 ~5 s
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
3 g' e, _+ _( h. r: D if (ret)- S2 g& o# F9 J# ]) F
pr_warning("da850_evm_tl_leds_init : User LED mux failed :": B& B1 o8 M2 U
"%d\n", ret);
+ D7 L% K8 g5 F# i/ w1 }3 l#endif6 K8 A7 Z7 D& p$ ~0 ?
ret = platform_device_register(&da850_evm_tl_leds_device);
0 }+ E" \+ u$ ~* z% I if (ret)1 {; ?9 I! F# x# ~4 Z; N
pr_warning("Could not register som GPIO expander LEDS");
# f2 m2 ]& f/ n8 R else
4 t2 g4 b# z8 d) C! L1 ]7 m* ~ printk(KERN_INFO "LED register sucessful!\n");
3 R z: ~, C6 R/ h8 X D: ?& o
% h, n& k% ?5 F* O+ n0 J0 V return ret;
5 @+ @ n7 L4 l, W: P: N2 \}
2 \, I* V7 Z( u4 W! K+ ]* D6 v* a) p+ U% ^5 ?. l6 ^8 |: a
static void __exit led_platform_exit(void)7 d8 V" k8 Z3 h. C
{' g, T- m* r' D' d5 X3 u
platform_device_unregister(&da850_evm_tl_leds_device);
& v3 |8 S4 X& W2 V
! n" |/ Q4 I( z% K0 k printk(KERN_INFO "LED unregister!\n");
, q8 {5 k* J* X}
2 b; z. c' ], g" o2 x6 D% Q) x) e1 t3 M. r b
module_init(led_platform_init);
; i& Z# q( |' P% fmodule_exit(led_platform_exit);3 Y3 Y) b' r. m) y
& q3 x( N4 D/ `) T( y1 D
MODULE_DESCRIPTION("Led platform driver");
7 Z3 `9 R$ Z2 U& b" _6 I% |MODULE_AUTHOR("Tronlong");, ^. |$ S, ~9 P1 x$ T/ _. h( [/ Y6 d
MODULE_LICENSE("GPL");
% J/ X. e- Y2 z3 G* z$ `
) w7 O$ m4 ?* Q- j) u |
|