|
|
求大神给下面的程序做注解,请稍详细些,谢谢。6 k& X8 `/ v/ E
#include <linux/init.h>( N; B) J4 k9 M+ E6 g6 h3 v" m
#include <linux/module.h>
# D$ T; Y' ?3 Z- N6 t4 o. H#include <linux/kernel.h>
N0 ^( H& {0 Z) U#include <linux/types.h>
1 T+ ]+ M( Y% y+ g#include <linux/gpio.h>
: h# T0 L& {% {$ ?#include <linux/leds.h>
9 P8 M0 I, J' n- f2 n#include <linux/platform_device.h>% P' q2 {" Y- y( {! y& h) H
; t# U3 n# z# O G
#include <asm/mach-types.h>
; E# U: ?7 _$ N6 s" S# a. t#include <asm/mach/arch.h>0 G; u) O. M, v4 W
#include <mach/da8xx.h>
3 Z" h. [% {# _( q#include <mach/mux.h>
5 R {* k; ?& [' V& |$ y [( d
. P4 [3 O6 a- p#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)$ j4 v+ M0 x+ U9 o$ }
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)8 O$ E% z) t3 A, ^* M
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1), s+ |: A8 v- G9 C" R) U+ V
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)
: o1 P" q2 L5 J+ n- _5 f* b: J; L1 M6 _: c
/* assign the tl som board LED-GPIOs*/. Q# z7 H# o7 }9 ^
static const short da850_evm_tl_user_led_pins[] = {
3 w. S1 n/ A1 B/ ^- }2 T! _( X" C /* These pins are definition at <mach/mux.h> file */& q9 z, p* J) A
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
0 a1 K7 Y) H6 ]) ^, ` -1, F; `6 R% _1 }+ E3 z+ z" Q8 M
};) ^0 H" `! B( L4 h' ^3 b, ~! v
4 y. E$ J; _5 Y* dstatic struct gpio_led da850_evm_tl_leds[] = {
9 E7 S0 J( b* k4 F/ s3 j {
. F/ C. j+ v- v# H; I .active_low = 0,, x5 {0 a& W! Z! _. z
.gpio = DA850_USER_LED0,4 _& h4 M5 x! y, O
.name = "user_led0"," \4 W( v: S6 I# C
.default_trigger = "default-on",
l4 K9 h1 U9 F },
y& w& p* G' l C3 D* _( Z' E {
7 V# Y& l' {$ _6 C, p3 d .active_low = 0, e t$ \; h1 I, J
.gpio = DA850_USER_LED1,
1 i% p( X6 l2 D .name = "user_led1",
6 H5 R' z5 d$ V .default_trigger = "default-on",
" u! N9 q4 `. M( `4 C },% K3 i+ g4 \. O% e3 {9 K: C1 @5 L% l
{" Z5 k- B- b* H3 Z* Q! V
.active_low = 0,- p2 u) A- R9 g) r% t# ]
.gpio = DA850_USER_LED2,
. T+ A# r! _5 J, A/ i' |8 ?# O .name = "user_led2",5 k3 V s$ x0 v7 ~
.default_trigger = "default-on",
' b2 P. g5 B8 t) M },, ~$ Q! Z0 }. X0 V4 v! K% ?
{
* S4 l: o' z$ h! E R .active_low = 0,; i0 k) l4 e% y' h1 v, i
.gpio = DA850_USER_LED3,
" b5 F7 r5 M9 o! }% Z .name = "user_led3",3 X' J# @( ]% C0 s; r0 u/ d5 ?
.default_trigger = "default-on",
/ N+ S' e: _4 h; \7 F: } },! w/ j: Y& k2 v
};
) |5 o4 h% O1 ^# `4 n4 f, o; u) d. j& |. D& M% R7 R" z
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {6 Z( k+ B/ k& y" g, a
.leds = da850_evm_tl_leds,
: I- n. @6 L2 ? .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
! W" k5 f! g- y; K+ l3 e u};
5 [; q, D$ x. c/ w1 i3 o/ W" w# z2 S2 g% _
static void led_dev_release(struct device *dev)
9 H* ~' O; E& O{
2 A U+ l1 k. E& Y7 U};
# s0 `" o7 m, I1 t. ?9 V9 s1 \& c7 Z& C, @' g4 _3 V
static struct platform_device da850_evm_tl_leds_device = {6 P: {" P& h/ V, V2 M; ]
.name = "leds-gpio",
+ W* M4 y9 l3 u! s .id = 1,
7 ?1 S$ ^1 H* I .dev = {
2 Q, W- d3 [" k& p9 | .platform_data = &da850_evm_tl_leds_pdata,% R! q& V4 }8 c
.release = led_dev_release,; C5 x! |, _* C5 M4 {5 u) e2 `
}
7 l6 d) W2 P& w' _% D5 _1 E};
/ k6 {: ?9 s$ D$ ?/ i* H2 \7 F3 a5 A0 n: S) X: c' g8 m" V
static int __init led_platform_init(void)1 Z/ Z. n) l t( W+ j+ Q% F
{
# Q& U/ x% @4 C( x% v) H int ret;6 `) M9 f3 [0 s/ l8 u& q
#if 0; U9 V; o$ |- U& X
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);9 w: O. A$ j3 b3 e6 p
if (ret)% v( c$ t5 o% o {& \. H
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
% S. B+ P& c; `+ h f "%d\n", ret);
! b- y( S, d8 l" k; {# ]( K#endif
! ^1 g5 i, H' `! E( x! G( P; P$ r ret = platform_device_register(&da850_evm_tl_leds_device);
; |0 L* w- y2 o$ X3 C$ \ if (ret)$ s! E. ^3 `5 ?# S
pr_warning("Could not register som GPIO expander LEDS");1 V3 I$ c7 i" G' U" G# @
else
- V8 F' r; c3 G7 T- p printk(KERN_INFO "LED register sucessful!\n");
$ V6 c9 `( Q0 Q- j2 u& L o# U
: _* |* V5 f- P return ret;1 r( h0 W @; A; @3 E- O
}, e) X# J. a7 p" \! p) x
, `" S' U. w5 s- J4 Jstatic void __exit led_platform_exit(void)
5 N/ `& Q9 H- Q( ~% G& z) r{
, c1 m$ H5 J7 i! @ platform_device_unregister(&da850_evm_tl_leds_device);
' @" d- x: e, E4 l$ ^0 ^3 g4 U# V0 P6 N* b) Z7 a; ?( [' i
printk(KERN_INFO "LED unregister!\n");# c" i6 Q2 C0 o
}. F0 y, `5 X4 T2 Q+ Y0 e2 i
- k, x& F0 ], p1 E3 r
module_init(led_platform_init);
8 U/ z. g0 [( ]$ H0 o( V- o$ Bmodule_exit(led_platform_exit);
% F1 a$ |4 K8 X( O7 j
0 ]6 i: T( A4 i+ G( I! N. p( K1 OMODULE_DESCRIPTION("Led platform driver");. E" ^4 W/ i6 w
MODULE_AUTHOR("Tronlong");0 q) A" M# |) f) g. |% Y
MODULE_LICENSE("GPL");" T* f8 Z3 E {3 q8 @
( w3 ~7 b* Z( a. f+ A8 g% M& M
|
|