|
|
求大神给下面的程序做注解,请稍详细些,谢谢。' M {: y# y( E% |9 D* S
#include <linux/init.h>
7 h# V0 i0 S, X2 J" J8 H#include <linux/module.h> O2 F/ i8 |. V- Q
#include <linux/kernel.h>
8 J6 H9 S6 e) ]% @, v#include <linux/types.h>% E; |9 q! d2 l# j# G
#include <linux/gpio.h>' o# m7 v5 Y [& l" H" h& V
#include <linux/leds.h>
; I( R3 X- n! |& W* \: y#include <linux/platform_device.h>
0 K- }$ p% x% {& _) \
5 j# ?4 `! k4 |% d4 f1 c#include <asm/mach-types.h>
: q% ~; @' {7 x; f! R9 |#include <asm/mach/arch.h>
% H+ N1 ]' r/ K5 u* K7 R; B. X$ H#include <mach/da8xx.h>' d( v( Z' V* `
#include <mach/mux.h>. r) {2 i5 f( I0 k$ s2 a3 w
& {4 o/ ~) ?+ k) F
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
2 S& i2 K9 u; t8 s! ~5 k7 ^#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)! d2 p; I# Q# [
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
# n* ]: E7 c7 }# ?$ f( x" O5 R#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
( C; I4 C7 _' m. Q# k% }$ S k
0 q0 M$ h" ]" V# W; Y- k/* assign the tl som board LED-GPIOs*/
. W! z4 u. v0 d7 @static const short da850_evm_tl_user_led_pins[] = {
2 z7 K8 K) W6 ~( J q /* These pins are definition at <mach/mux.h> file *// Q0 f1 y& g3 ~4 H
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
4 D3 p. m; l2 [$ I( l; h# K' s -1" ]9 J0 X7 l( w$ w5 Z8 `
};
5 z% ^6 t7 {/ z# q8 ~ I6 C Q0 s) V2 Y( P1 b) i7 ^/ d
static struct gpio_led da850_evm_tl_leds[] = {
$ H; ?7 V( Z$ K$ n2 j) y {
( ]" e& T( c w .active_low = 0,9 o! a! i3 x* Y/ C" k5 ^+ z
.gpio = DA850_USER_LED0,1 y: l/ g, L1 I; M, e( x7 U9 y
.name = "user_led0",
e: s4 O5 k, ?: T s .default_trigger = "default-on",: z7 Y' m+ x" v! z' O8 A3 H; L
},
- b& W! Y; @$ C& x3 @2 ? {: c, c0 K t, n6 b
.active_low = 0,5 u U: y- e7 f- n" ?/ k8 Q; A/ W
.gpio = DA850_USER_LED1,
7 [; o0 Y+ q; B7 u h .name = "user_led1",; B! ]' f3 [# R0 h; ?7 L
.default_trigger = "default-on",
, D2 v6 I3 z4 k( p0 @ },% H5 l' N* H4 x5 h9 e
{, d2 `% ]& ~; B# U7 L: u
.active_low = 0,* K9 t; d1 _- B6 E9 X3 I) ^9 G/ ?
.gpio = DA850_USER_LED2,8 ~0 o8 m8 _6 p" ~3 I
.name = "user_led2",6 k; \4 m- h6 S) Q, j9 B$ @$ ?
.default_trigger = "default-on",# Z7 o$ U* T5 G. k) v/ T% z1 b! R: Q$ I
},
* I/ S: m1 J: A) O {6 x( |0 X. w% @% w/ ?6 G8 x
.active_low = 0,
( O* v$ Q. b% B- U+ c2 h. \, q .gpio = DA850_USER_LED3,% X7 S2 ^# R: G6 e
.name = "user_led3",
6 d9 k: x& C5 C# X: n+ Z .default_trigger = "default-on",( _' U# r- t$ Q2 S* ~- T7 Q* a
},; B2 G5 P( M: e F0 r
};
: U+ ]* [: o& I3 J+ n: j7 B7 T2 P( t4 k* H' x8 E7 ^
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
* H# t& l0 ^( d$ {" K8 z2 U .leds = da850_evm_tl_leds,
Q# e* T. w, i5 ^& A. x .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
5 [/ z8 v: i A: d5 O7 i};' n' J9 J e3 G4 i
7 {' Z% j' d& n2 O' `; Y# t4 _ E- m
static void led_dev_release(struct device *dev)1 O8 f" ` N# F. |% x/ z
{. D- B: f7 p0 C/ k# x9 Q/ L' N7 s
};+ {1 t. b" q' o4 D, P
" o1 T" N) U/ Z0 j+ x) l
static struct platform_device da850_evm_tl_leds_device = {5 p; f& C" P; T, f1 B
.name = "leds-gpio",
5 p$ L3 X% h% M1 E% D* w0 K# F .id = 1,- Q9 h. W5 f( [; Z5 Z: {
.dev = {
, H8 p+ Y& ~ d0 ?5 ` .platform_data = &da850_evm_tl_leds_pdata,
2 O) D6 k4 }1 _6 U! V2 I .release = led_dev_release,+ M' `2 E0 {' w1 O8 w
}
1 s: u; f: ?: b0 T# W4 c};; w' e/ x4 G9 r! ~) w" C% L/ x
0 M6 k7 G# P8 Mstatic int __init led_platform_init(void)# c5 E# Y2 i& m) f) t9 x
{
& Q3 @" b7 o: T8 J7 |+ C$ T& c int ret;
) f' A# \# T5 g#if 0
% ~6 v l3 }1 b3 z6 |& G1 T p9 t+ W ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
( s0 Y& N. A, J) W/ N, U if (ret)
/ Y/ o4 ^# u6 ~, a: ~9 l0 p' _6 p pr_warning("da850_evm_tl_leds_init : User LED mux failed :"7 u6 G# y& [' c8 S. r
"%d\n", ret);
- y% a6 q& I6 V; f/ Y: ~$ D% m' }1 D#endif
6 W9 J9 @! ? [7 Y% z4 K6 l ret = platform_device_register(&da850_evm_tl_leds_device);7 a5 w$ S! ~! s9 E3 e
if (ret)4 q6 Q+ O) u* w$ ~
pr_warning("Could not register som GPIO expander LEDS");
- V- Q$ m! B- |# ]# ~+ U# a& ~+ p% A else
$ R% f0 D/ W9 D5 G' w* N printk(KERN_INFO "LED register sucessful!\n");! V0 S! {' |* ~
Z7 h+ Q Q4 E# z2 q
return ret;1 o2 o5 p0 ]$ c/ L. O
}2 i8 z8 d9 X" ~+ ?1 M! b9 k
0 S' D) Y. F1 J/ W5 h/ Wstatic void __exit led_platform_exit(void) @# V% Y5 k7 D2 ]
{* m6 y( H* Q6 `) E0 p
platform_device_unregister(&da850_evm_tl_leds_device);! X& n0 c2 K7 ~5 x+ E
( c o0 M5 D& T( Q/ o printk(KERN_INFO "LED unregister!\n");0 z: }/ {$ L9 T+ f
}
3 O' @+ h1 |5 X
+ q5 W- H0 y( R7 s I8 Bmodule_init(led_platform_init);
) T; h0 x2 V5 U+ o' T. ^module_exit(led_platform_exit);
" C; C+ R0 r+ d, z. O4 B* w7 d
MODULE_DESCRIPTION("Led platform driver");
" y3 r# o/ X, ?& q4 G+ v* O, dMODULE_AUTHOR("Tronlong");; j( [! Q$ ]% ~# m' J5 {6 o
MODULE_LICENSE("GPL");) H# E' R# ^6 Y
F: e; h$ y% x3 v! {- W+ A% ] |
|