|
|
求大神给下面的程序做注解,请稍详细些,谢谢。) w, c0 D! m8 N( \% H3 w$ r
#include <linux/init.h>, ?" k+ K/ {( h0 ?6 \
#include <linux/module.h>6 t+ z1 U8 w" D2 T+ W
#include <linux/kernel.h>, Z/ v& p2 m0 b& s
#include <linux/types.h>
$ [3 P6 G9 J$ i+ L' z! a#include <linux/gpio.h>- F3 Y6 v% G: p ]1 i$ B
#include <linux/leds.h>4 [' @: d. G% h: p3 D$ r- X
#include <linux/platform_device.h>: D B0 ?& O: _' l f
5 G/ p& H* ?& O/ u#include <asm/mach-types.h>
/ [+ G1 U4 S6 v9 w! d5 j#include <asm/mach/arch.h>
2 k3 v% h' m" Q9 j; R9 o#include <mach/da8xx.h>
. }7 a X( t+ H, w5 r* |) M. c#include <mach/mux.h>
6 Z8 L& e% Y5 `% V1 ^
% K% Z2 {( D2 g& Q+ \#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)6 n% i L9 A4 g g1 }
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
& n3 y! U$ M" K4 ^ C& r#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)2 X* t; O! u* l
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)8 {1 S" T/ u- M4 U& b
1 k7 a/ P; p0 X, \2 }
/* assign the tl som board LED-GPIOs*/
7 K, h" _. X" { G6 M* g6 Z! i+ rstatic const short da850_evm_tl_user_led_pins[] = {
# h- Q$ A& w a* Q0 y# I2 X /* These pins are definition at <mach/mux.h> file */
4 A; m/ M+ f) Y" i4 b8 K DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
4 d& {2 B0 i1 P4 | -1, U5 Z6 o& R: C8 H/ l
};
$ U4 K( C: t( o4 f
+ q4 ~9 C" A6 R5 X: }" c# |, H' Astatic struct gpio_led da850_evm_tl_leds[] = {
( \+ i& Z W) I; Q {1 f) T4 r1 m! } T" S7 c! ]
.active_low = 0,
6 z/ c$ o) p" g% D7 y .gpio = DA850_USER_LED0,
. @0 n" \; C& V) D .name = "user_led0",' d1 t {# L7 h( J0 x
.default_trigger = "default-on",
# W/ ~2 e4 T, J },( E- b& I0 N* p+ _0 E( ?
{
* ^, v+ a! O5 y- g .active_low = 0,* V( P/ b! n$ C! _- B j/ R8 l
.gpio = DA850_USER_LED1,
6 w2 a; {% {. \& w .name = "user_led1",
7 s( y4 t5 D+ r6 ~7 q( V( ^- _3 u) t8 n .default_trigger = "default-on",$ \ v g% p4 E3 t" }! e
},: L8 l7 `1 ]- B. Q$ P# Z- u
{
6 E$ n1 |, M8 a3 r& R0 s .active_low = 0,0 _* Q2 Y4 y8 f' H# v1 r& W
.gpio = DA850_USER_LED2,
+ y% Y0 o2 H4 g i! a .name = "user_led2",3 f1 A1 d' i7 T0 z' _5 o4 T
.default_trigger = "default-on",
: b" v$ V* y& p }, c3 l9 X& W( ^( ?! u
{3 a5 w) H7 |: C/ [! i
.active_low = 0,/ q& l8 C8 X3 D2 c9 a
.gpio = DA850_USER_LED3,2 b T- m: c' ?: ?
.name = "user_led3",* Q5 c I: c+ G% X
.default_trigger = "default-on",5 m0 L0 Y& o A- _: J
},1 f; T D* V1 c" B2 V+ R H+ a
};
4 E) v/ Y% Z0 B% h V* M
9 Y9 y# v' [- W' b7 Sstatic struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
, Y2 ]$ k: K& @ r/ _; Y( L& b1 G. l .leds = da850_evm_tl_leds,/ v6 a/ O7 t G1 ?. R
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),
: u, e2 V v5 ]5 F};
$ j2 H9 E8 |( [9 K9 k! ?
! U H$ j* n8 z$ l- z$ vstatic void led_dev_release(struct device *dev)# ?' t$ p/ f1 i: A; Q
{+ Z7 n$ F. s7 S# e6 n; M
};
. L f8 z. V1 D9 b& w3 @$ r! P c4 b1 f/ |+ X& F
static struct platform_device da850_evm_tl_leds_device = {
0 ]; W0 _4 }+ `$ l# ^$ p .name = "leds-gpio",0 p6 X7 k% |! V8 {
.id = 1,8 l- B( c" N# F( E; E
.dev = {
. [7 ^/ X7 o1 B/ ?: E .platform_data = &da850_evm_tl_leds_pdata,
! g/ Y9 t! O8 r7 @6 j6 t# E .release = led_dev_release,! `4 A/ t9 d, c! L: `1 ]( b* r6 D
}* a' V& N6 H# W" I1 |
};
4 W a$ T# \) B! h. t! \8 V; e5 W4 W5 w7 R( J# L- ?
static int __init led_platform_init(void)
$ a! n: c X% N* V7 U& R% d{* t t" ?2 x) A' I
int ret; P1 {0 o. g% L/ Y* e2 L$ `
#if 0
! V1 E. u/ p" x% r! D, W ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);/ P$ {5 _0 w- `/ \( O
if (ret)
! Q0 J- U% X& T. H& X pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
; p8 Y% `2 Z9 d# M, Y "%d\n", ret);9 T+ \7 |5 }+ c# A
#endif8 {8 |2 E: m" f! B/ g7 t& H3 D
ret = platform_device_register(&da850_evm_tl_leds_device);
* P2 y7 z, |+ T5 ?# t( N# w if (ret)- H( f0 V; e" S( M) |0 [# N
pr_warning("Could not register som GPIO expander LEDS");0 K2 p# R$ U1 f' z
else
2 n7 N: h0 h1 X- C& s printk(KERN_INFO "LED register sucessful!\n");
% y" p0 G0 W3 K6 |" q6 D. S: s
, a6 m3 j2 P9 h return ret;
\; ?9 b/ t& I% i2 V8 P}, n9 L F" L% p' i
1 W8 B; J6 J( Q4 Z) o: R6 T. `, bstatic void __exit led_platform_exit(void)
2 r+ ?/ T0 y& U4 |$ m8 U% ?{- B9 D/ ]- @ H& H- b7 B5 ^" ~6 e
platform_device_unregister(&da850_evm_tl_leds_device);" ^* w0 Y2 d* W/ |( @! u) @8 t, v
8 E/ U8 u# j& m5 m9 S+ n printk(KERN_INFO "LED unregister!\n");
6 F/ c$ h( ~% ^& D0 @. }0 P1 d}1 R2 X: G6 ]% s6 f! |4 z
3 s) A1 `' R* _' n
module_init(led_platform_init);
' j4 U6 E% p4 }$ \1 |; B5 G- Bmodule_exit(led_platform_exit);) t' W2 q0 s6 y* c1 ?$ O- g
% J( X! f% g" R5 x* d6 JMODULE_DESCRIPTION("Led platform driver");
" W1 V4 ^1 p5 b* e8 i5 `MODULE_AUTHOR("Tronlong");
! F% g% @) m6 _ ?3 OMODULE_LICENSE("GPL");
1 h+ c2 s( \5 t" M
# X, w, U9 N. t |
|