|
|
求大神给下面的程序做注解,请稍详细些,谢谢。1 b. t- Q6 Q+ h9 v/ u+ f4 v8 M
#include <linux/init.h>& p& V1 g m _5 J* F+ K
#include <linux/module.h>
: d) Y' r8 C2 @# H( E#include <linux/kernel.h>5 M: V# g' V9 m S: K3 G
#include <linux/types.h> U1 N, m! U: O3 [* ?
#include <linux/gpio.h>' {: G& t U: {* f2 i# [* }
#include <linux/leds.h>5 \" p( T/ }& `: W
#include <linux/platform_device.h>8 y A9 T* B( r r% V9 J
1 | J# s1 F& R% l( v9 ~& p# O; C, M) l
#include <asm/mach-types.h>
% b9 r; D, K& M0 p* V#include <asm/mach/arch.h>( T+ V" @+ p7 z% d* L
#include <mach/da8xx.h>& l1 N& g9 h. f, a2 X
#include <mach/mux.h>
2 c( O: L( ]6 o2 [3 z- a
! S H! N) c' a2 H#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)) G8 g/ v. I: m) h
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)& O# ^& O- [0 N, l
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
$ H8 C7 A* n) D* L n/ h9 v) t#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
; D. l' o: r' \+ J1 Z' y
0 A5 c- a' k' _- L* ?' Q4 ~4 Y/* assign the tl som board LED-GPIOs*/1 M7 G' t7 W8 f$ j4 m. M
static const short da850_evm_tl_user_led_pins[] = {* {& R) d7 ~- ]! B) n0 l5 _
/* These pins are definition at <mach/mux.h> file */* [9 T/ K. H7 o1 b5 P% [8 E" ?" s) i; p
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
! n/ ?, w) u6 o }4 Q/ g' |7 j, ~1 k -16 d. U2 \* e1 }- l$ d5 R
};. T! N% `. E- x6 H! k. v
# X- {4 Z1 h U% A3 B% Vstatic struct gpio_led da850_evm_tl_leds[] = {1 {! z+ i4 k* L$ H1 M) l( A2 @- T
{$ ^" Y* Q9 @' H' X7 N1 q
.active_low = 0,: a6 r: j% a1 A* C2 V0 C' J+ A* J
.gpio = DA850_USER_LED0,! u: v0 G: e# }. Y$ x" X
.name = "user_led0",
6 u( X4 g8 o, e6 K! D, j .default_trigger = "default-on",
8 G! U2 r8 M3 M( O },
; D* D7 B% J0 |! v8 U2 g+ Y* F5 g0 T$ c {4 H' J7 f" M8 O+ m0 \# C/ ^' ?
.active_low = 0,- B8 u+ v+ D2 U* |/ a& Q
.gpio = DA850_USER_LED1,
$ A. i! g! q, b |" _6 D" M .name = "user_led1",) K2 g0 A4 p, N2 Q
.default_trigger = "default-on",
6 E. G6 G% d: _0 D* b },
, r. l4 i/ T! I" s3 { {
7 J4 f2 \, S/ b; _; |& ]. O .active_low = 0,
* ]4 j5 U0 k* k( P .gpio = DA850_USER_LED2,: d3 j' r2 @& }& N U
.name = "user_led2",
# Q% V8 ^- V- K, T .default_trigger = "default-on",
; l( l/ C' K3 ?2 A! X/ g b },. m( Y8 |) v; n# I% I8 m2 R
{/ i& B8 H* A) u6 [+ D$ I: s3 K& v
.active_low = 0, G* J. v; Z: j) m
.gpio = DA850_USER_LED3,
) A5 d4 P. X' P .name = "user_led3",
) ]- Z! b& J; A- p3 ]' o& i, J" s .default_trigger = "default-on",
9 B6 L: D7 J, m; \ },
0 U( }) R+ L* x# c2 P$ N# b}; S$ g( j" \9 O7 K) [
% C: G1 y! r4 G- E/ T
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
- O! b L, q) D .leds = da850_evm_tl_leds,
( Z4 S }9 y- ~# V( t$ G .num_leds = ARRAY_SIZE(da850_evm_tl_leds),. S% P9 C" o, Q
};$ i1 N3 `: j2 f9 N4 t1 Q4 l2 w
# r4 d; m! ^% o$ n' ]' b# Kstatic void led_dev_release(struct device *dev)
1 E; e9 }$ j: \; h3 o5 @$ m9 B{
6 {( N0 A- \4 c};1 V! Z# c, W% Q( r
; P+ n3 O, c+ ]9 ostatic struct platform_device da850_evm_tl_leds_device = {+ E, |4 }+ }" ?" V
.name = "leds-gpio",
# l3 X T/ V# T \' H. |! {' n .id = 1,2 D# W, W. z3 o' _* w0 j
.dev = {0 s1 J2 h' p: d+ F- {) ^0 U
.platform_data = &da850_evm_tl_leds_pdata,
1 n: N2 x. c$ H+ Y ~; `7 X7 \ .release = led_dev_release,
# @1 C+ e# ?; w, Y }
. Z! t$ `: }, D- k8 U* x};
4 S6 B& ^; G: s# b v g2 j) r8 Y3 K n- Z) E8 k! @0 E& T
static int __init led_platform_init(void)- q8 O8 r; K0 e2 |% i( `0 ?
{0 M4 x/ ~. ~+ W/ r. l6 E
int ret;
. r- |6 B9 G- @: I#if 01 w! ?' v- @/ c R# E$ ]
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);
! N* D, j% d0 r4 H. o: U# i, p3 p if (ret)
0 C: L! A6 e$ |. g; k$ E pr_warning("da850_evm_tl_leds_init : User LED mux failed :"% M0 Q8 f1 L" W: C4 k
"%d\n", ret);
/ @, s: r" X( B0 e" \#endif U9 l# r) k# Q! U9 C# r1 a/ M9 a
ret = platform_device_register(&da850_evm_tl_leds_device);
8 i: |* d0 H; j) {. v- o; Y if (ret)9 @% [ ^$ k3 s% I
pr_warning("Could not register som GPIO expander LEDS");4 _2 a# }$ c% j6 O2 P1 M
else! ~( R/ C# {; s. z$ T7 U
printk(KERN_INFO "LED register sucessful!\n");
/ j3 z$ v, s$ H. K
- ~$ i# O. z& p, u$ l$ v return ret;
R* o' v# M$ N h6 V: @6 }& @: S}
+ ?1 Q5 v% L% A) A6 ^* Z# t
7 Z2 [7 _7 S# _% h4 \. ^static void __exit led_platform_exit(void)
( R7 X1 p% D: I, g! d0 T: g1 M' @{
, t; ]. b# x; x6 M( l$ i platform_device_unregister(&da850_evm_tl_leds_device);; C- X- n8 |) L2 y r$ z7 O9 T
$ \( m5 V5 ]6 y% o- m/ {8 J
printk(KERN_INFO "LED unregister!\n");
- z# l0 D* {0 I& t}
N+ a: f5 _; y( w, @* |, u- R9 F
* @( S5 }4 K! i8 t8 Qmodule_init(led_platform_init);
t w: h& e- @8 b. D8 j/ O; w) v' omodule_exit(led_platform_exit);
3 B( c+ W( g3 p* L4 D% d2 s
+ l- A7 y5 s0 u2 W0 ^* x0 h# kMODULE_DESCRIPTION("Led platform driver");& U- c/ r( `# R5 K$ c+ Z
MODULE_AUTHOR("Tronlong");
! N: D q* d& ~" Z+ I9 BMODULE_LICENSE("GPL");5 `; r" G/ ?& `1 `; C( R; C6 O
# i6 H$ }; ]% S/ K$ \! Y |
|