|
|
求大神给下面的程序做注解,请稍详细些,谢谢。1 ]+ e$ F: Q% x4 f; i% |
#include <linux/init.h>7 Y( O; j/ g+ F% d
#include <linux/module.h>
8 i0 _( k$ q' Z( q9 h; k* M#include <linux/kernel.h>: |7 W, A! b( \/ Q( `- H N
#include <linux/types.h>
8 c" a$ J% u$ U7 a) | ]( s* ^#include <linux/gpio.h>0 e; c* h6 c) w6 T+ \
#include <linux/leds.h>
! v6 Z% `7 a# L4 L' `: ?#include <linux/platform_device.h>
6 a2 B* _& a% J7 z) C
4 X! ^& g% `7 y#include <asm/mach-types.h>$ K8 w ^7 k3 g* U6 `* S! o
#include <asm/mach/arch.h>
2 X5 C" ^% h% B$ n, W$ [& u#include <mach/da8xx.h>- F ^' H, @' d7 n& [
#include <mach/mux.h>0 {: y4 z9 K5 @
^6 ^3 r+ p/ j; F* |8 i$ y& ~#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)+ H1 ^; p0 J. {# ]
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)5 r- m) L O' G, `9 N' Y7 g
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)4 z$ d! |8 g ? X, I, m$ q% w
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)' b5 n. i% o- R! m x" ^8 Y- T% I
* k2 {: I H# D5 v p; a7 ?( W K/* assign the tl som board LED-GPIOs*/9 h* }" G- R9 }6 H
static const short da850_evm_tl_user_led_pins[] = {3 j, X& q5 \$ Q8 T% J+ W
/* These pins are definition at <mach/mux.h> file */
& n2 [! {% |* X& D$ ^ DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
$ o) j; i1 p/ F/ { -1
6 k( v5 O, {- e) }1 U1 q( H$ t};
7 E( o+ G" z: H3 ^
# n+ G$ E9 c. k' }! nstatic struct gpio_led da850_evm_tl_leds[] = {6 \6 a' j; ^& P) y
{2 W( D G; R7 |$ I4 b* n- c
.active_low = 0,: q% F' k! F/ O: O! y5 c$ q
.gpio = DA850_USER_LED0," x, U; ?8 ~; E1 N/ @- }: Q
.name = "user_led0",
+ {* V& D' @3 a .default_trigger = "default-on",
8 n! k8 D5 S9 w+ P2 ~: K },
: q: m/ P6 ~9 W; S( G {
# _7 y! B+ F+ o .active_low = 0,. r j% b& L. \5 h5 a% L* m
.gpio = DA850_USER_LED1,( {9 n; j) ]1 H# N6 Z/ R
.name = "user_led1",- Y1 ?5 w3 S O6 `4 @: y4 S
.default_trigger = "default-on",. e6 e' c0 y: G- y: \& k
},
/ T! w: Y# z2 u, P {6 n3 V( E9 q4 k( B6 y* _
.active_low = 0,
$ i. R P" B$ [/ j4 W6 d .gpio = DA850_USER_LED2,! H b; t" d8 p) t: [+ U& \
.name = "user_led2",+ F G) c! ~1 C
.default_trigger = "default-on",
+ J" \9 Y W5 u1 M },
& Q" k, m0 g& b8 K* C {. z- `6 V7 J* C% l% K9 I; r
.active_low = 0,. ]) C5 A& {" a1 A: a' d; d( G
.gpio = DA850_USER_LED3,
1 a" p" X& B# `. H( U3 o1 \) U$ K .name = "user_led3",
/ o- X$ D+ {8 G .default_trigger = "default-on",
6 V0 y5 X- r5 \! f+ ? },5 G4 D8 `/ X+ v* R8 K
};
: T8 Q$ g0 L; R) H+ y p1 z' S. u' [% x6 b M. w# ~
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {$ U; V+ D- M7 B0 k6 y7 n7 k% X
.leds = da850_evm_tl_leds,
% J. T; D6 R3 S .num_leds = ARRAY_SIZE(da850_evm_tl_leds),
3 o. u9 k E3 D& k# j( q};
]2 Z6 x7 c, T: e- ^
, a ?0 y" D6 Z' Dstatic void led_dev_release(struct device *dev)
4 ]/ q$ H# Z2 [0 e6 d; e% a/ @{& `, f7 M H% `
};, u. F' Y7 i( m! g5 f8 d1 a1 Z
5 t$ a, Q3 D0 q( J/ E
static struct platform_device da850_evm_tl_leds_device = {
5 W0 C* D; z! ^0 W .name = "leds-gpio",
. E# y4 g- X( ~; h; r3 [ .id = 1,9 D# H/ U4 e4 W9 J ~9 ^* k2 n
.dev = {, p3 L, f% m% ^" I5 Q& v
.platform_data = &da850_evm_tl_leds_pdata,3 S% H8 I- v: a3 r' @, S" d
.release = led_dev_release,
" Y2 N: b! Q% ^' e/ S }
$ {6 o, \* j4 s( t};
* y+ r$ d# u7 E5 L( {
' e" o7 {& n4 V/ [( m4 ~- \static int __init led_platform_init(void)3 r- j( M) c+ E) C
{
0 `( c0 U. H- V int ret;
2 J, q( A1 m! r7 d#if 0 F) }2 d2 {$ V A
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);3 [- b/ f$ W! C, W+ H
if (ret)
+ B- _$ Z" J* m' V2 B1 u0 j5 k pr_warning("da850_evm_tl_leds_init : User LED mux failed :"9 V y4 u, K3 d7 Y q
"%d\n", ret);# t) x! |6 X9 t0 U' f+ L
#endif
# ]$ j1 ?/ F0 F- n# Q& t ret = platform_device_register(&da850_evm_tl_leds_device);, Y: c5 [7 \/ I/ _. H& ^
if (ret)
* Z! f. ?" W5 @8 d pr_warning("Could not register som GPIO expander LEDS");
) f" ^4 K8 O1 Q3 A# M0 C: l/ [ else9 Q3 z# {) n7 l
printk(KERN_INFO "LED register sucessful!\n");5 K; Z9 C' V8 k8 x z$ g* T6 a
/ K# N, n7 Z7 _/ c& J return ret;
& [7 @! `9 v9 t}" A% V5 A2 ?* f
8 y% P: Z8 k0 @$ W9 o- P4 c
static void __exit led_platform_exit(void)1 C" d5 d& A& c' G' Y
{: A4 ]- w2 S' l- t- ~/ i5 }
platform_device_unregister(&da850_evm_tl_leds_device);8 b4 o$ w2 I, i3 [
& d4 Z0 G; i! M5 U' |0 w
printk(KERN_INFO "LED unregister!\n");: Z$ L, |( o/ Y# n' S* Q+ n, [2 G
}5 V2 Q/ X2 h6 ^! q' _- @
3 l0 J w# S3 n5 R, E) e _module_init(led_platform_init);. H/ h, ]- {1 i+ f0 B$ ^5 U* Y
module_exit(led_platform_exit);
4 H; g6 C: o: @- u+ o4 {3 V
+ n7 [( h# ^3 j* G5 v. s, G) }MODULE_DESCRIPTION("Led platform driver");5 D$ A; n7 q9 Q" [! V6 u8 \
MODULE_AUTHOR("Tronlong");
/ g$ ^* Z9 U$ OMODULE_LICENSE("GPL");! Z- l) x! ~" ]7 ]
8 o1 n3 `# Z) w9 }7 P
|
|