|
|
求大神给下面的程序做注解,请稍详细些,谢谢。+ X1 |2 d3 a8 s
#include <linux/init.h>7 b) i( k$ t! ~; z9 r$ l
#include <linux/module.h>+ f* k% _ }$ H+ _ V e( A* x
#include <linux/kernel.h>* z* Z, e# F% Q6 @+ w( V5 V
#include <linux/types.h>
0 q f7 s# @- r, v* `4 p* g+ F5 Z. m#include <linux/gpio.h>
t. q8 |7 G( o* a; V#include <linux/leds.h>2 `5 g( B" o2 c6 F( Y9 _
#include <linux/platform_device.h>
7 h) ?: T8 G V- s( \
: `% `6 ^7 ~9 B1 t' Y#include <asm/mach-types.h>) t& F+ Y' v/ O# n
#include <asm/mach/arch.h>0 t: D, `) L1 U) x0 B
#include <mach/da8xx.h> {1 x3 W2 i- O9 H) u. B0 F) B
#include <mach/mux.h>
/ |/ r7 C- h" R& W& I3 Q/ L) B- @0 \9 ?3 L, N5 S) E
#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
7 W% R; W$ m8 Y T8 t W#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)4 K3 \& S% i7 i6 A* R
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1). E6 N/ `" Q5 Q& E
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
% f+ Y: s4 q6 D
+ Z& Z7 |2 ]: u% E3 o/* assign the tl som board LED-GPIOs*/0 a' k# Y& i4 W; |: P& i
static const short da850_evm_tl_user_led_pins[] = {
8 ]! O4 x Q; S/ T /* These pins are definition at <mach/mux.h> file */
, Q }, `+ R) \ DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
: { A2 u6 h2 l* Z+ n7 ` -16 Q& x" M |) S: k
};1 N: e9 r& D% ~0 Y
) c+ M/ t& Z/ s+ Y& N* j5 M; I
static struct gpio_led da850_evm_tl_leds[] = {
, E+ X5 n& ^$ R/ g% K3 E0 ?0 C4 ?1 ^4 o {
; F W* {( _8 T$ c+ p4 K .active_low = 0,% L8 n3 }2 T. m: T& l2 t
.gpio = DA850_USER_LED0,
0 ?( t1 Y9 I: L6 u- x* E+ B* I7 W .name = "user_led0",
' H2 E6 t! O; V) K .default_trigger = "default-on",
" z+ J# r7 H, E },+ a# t' s' s: H P- i
{9 K9 C0 P: X/ x$ ~' C9 ?/ d3 C0 H( s3 H) Y
.active_low = 0,0 C9 S, T! n d, w+ A
.gpio = DA850_USER_LED1,
) f+ |! Z0 [+ l! x$ J+ Z .name = "user_led1",- x+ s6 [& G! ^1 `
.default_trigger = "default-on",6 r8 ]8 K$ v8 x! O) ? J1 n9 e+ W% q
},
; [- V2 N7 M$ ~2 z: A* N* u {
# V X3 o" |* Z6 j1 p9 [( b7 J( C7 L .active_low = 0,
% C5 l0 e2 ~1 A% R1 ]# r( G7 b .gpio = DA850_USER_LED2,
+ ]8 f% [& z% w& \2 Q .name = "user_led2",+ G4 m. b4 M% Q, w2 w. y
.default_trigger = "default-on",# l* K, }7 f5 B4 S, Z- U
},
6 S$ h# [6 K3 A' c {9 Y8 n% D8 j- H
.active_low = 0,
3 V2 C' ^3 p0 C' V" v! L .gpio = DA850_USER_LED3,+ w& O* `! k& K: x
.name = "user_led3",: @- f F* N' R
.default_trigger = "default-on",
: v- Z. X) [4 s& f0 U% |0 C },
" j- T, V5 U, G5 _ P9 e};$ x- ]9 G/ C- \6 B& v m6 P
% D" J- y3 S) `% H
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {' ~$ ?( k* q$ v/ W- S" k5 J# v
.leds = da850_evm_tl_leds,
0 F& X X! M& x/ h .num_leds = ARRAY_SIZE(da850_evm_tl_leds),+ P: S3 {/ S& e+ h9 g* T6 \
};
3 \: ?0 P5 N3 F. N# a' v
5 e; v+ O& h+ g5 }% w1 kstatic void led_dev_release(struct device *dev)6 I6 D2 }! \$ r ?# `1 x
{
2 n3 U9 m+ A$ S6 o. Q* W$ K8 L5 [};
" y# T* ^0 D3 P& s, H/ [7 k$ Y; f: m5 @* d D& L& D
static struct platform_device da850_evm_tl_leds_device = {
/ O0 C# }9 h4 X% P) F .name = "leds-gpio",9 c# @" m1 R6 ?
.id = 1,3 X8 @ W; ]; t, ^- D
.dev = {
N: m4 A' [4 Z' e. l- X .platform_data = &da850_evm_tl_leds_pdata,7 q- I. {6 i& v7 e: g. j1 A$ u
.release = led_dev_release,
. b+ k- A5 v+ W; T8 ]9 V }
7 Y: i/ c3 w3 `( x, x! \* f};
3 A4 r+ i: Z) t! j5 m. G; }+ W n" V y
static int __init led_platform_init(void)
; v1 |( f1 [3 ]0 y{
& n4 A+ s7 l5 G2 k, I6 N7 x7 | int ret;+ l+ u$ J% ~9 T+ G
#if 0
, q' S; Q0 Z3 a: F! j0 E& G( | ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);0 E; Y2 U& v+ h2 M( W+ r+ R
if (ret)
8 H1 Y" C) z; z8 S: h) l6 h" Q* ] pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
d3 v! j L. n* B ~; S6 u) u "%d\n", ret);; V5 A/ B6 j8 N
#endif
& q& y1 r, _- ] _ ret = platform_device_register(&da850_evm_tl_leds_device);) w3 D5 J4 k$ b
if (ret)
8 a* z" h9 m2 C. Z8 y pr_warning("Could not register som GPIO expander LEDS");
4 q4 R% A/ _. J& { v, q: \3 M else: q" N4 n Q9 {5 l, T
printk(KERN_INFO "LED register sucessful!\n");
, p9 Q9 t7 ` W6 Y
4 { m4 Z) u' I return ret;0 V: A+ T8 H1 S
}* n! ?$ w4 @) t4 B* G6 i O
# d/ F. L" e0 e9 z, v C3 c2 ^9 D
static void __exit led_platform_exit(void)
. B3 V) {7 a6 P" z{2 b1 h: M+ O7 D$ l Q
platform_device_unregister(&da850_evm_tl_leds_device);, f: F( ~* E7 E9 F4 }/ d
% s) z$ b$ _" z& S; W
printk(KERN_INFO "LED unregister!\n");9 L1 p" q1 p) ?3 s" R) \5 ?
}
/ c( @* T* M, J3 v: d1 L* `
& D- V3 ^# o7 N# ]& j* B3 a1 Mmodule_init(led_platform_init);
, {- C4 v! k( h# L: mmodule_exit(led_platform_exit);
) q1 o+ s1 E+ k! r5 p$ F* \- U: |5 W
MODULE_DESCRIPTION("Led platform driver");
' t/ t: _8 @1 }/ `' p* lMODULE_AUTHOR("Tronlong");( B: \8 { W2 {( [9 ]
MODULE_LICENSE("GPL");
7 D6 l6 W$ C$ R/ Z3 `# ^! F4 O
7 h2 {( r, r' @7 j |
|