|
|
求大神给下面的程序做注解,请稍详细些,谢谢。
4 `% C& L( D: I/ ~* p#include <linux/init.h>
% x7 B7 u+ o; ^3 T#include <linux/module.h>
7 R8 O4 b4 |: B#include <linux/kernel.h>& |, ]3 S' s8 H R
#include <linux/types.h>
. D: j/ M( b* D* L( P% I#include <linux/gpio.h>
/ x3 a l: k' `/ f1 n& L#include <linux/leds.h>
0 w6 F' b( U2 `#include <linux/platform_device.h>
# n8 x' ~- H7 D+ ^) H- Q1 b* |" f; A9 s W
#include <asm/mach-types.h>2 y; V* T+ b8 G% s1 q5 I
#include <asm/mach/arch.h>$ h6 s; C1 p2 k
#include <mach/da8xx.h>) N* T$ U. g9 @2 W: @, h
#include <mach/mux.h>
J' S1 j' ]7 }$ C
' W7 D8 W: }1 S1 d#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)5 Z3 _& i1 E& |( p; r
#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)
6 L2 O& [3 @/ d z5 F' b. y#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)0 |1 _3 r& o4 y% L9 J# `$ h
#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)% P4 u z& ^# Z2 R
, O }7 `$ V0 V; U+ ^( |
/* assign the tl som board LED-GPIOs*// K- s8 y v ?" A a) N
static const short da850_evm_tl_user_led_pins[] = {
7 q _% b* U4 v# O. A /* These pins are definition at <mach/mux.h> file */+ S( _2 D7 U, o9 N$ j
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
, m' |* G5 D( }4 i8 I -1
( U5 P" [9 r( d7 t2 S" B$ H};
" _# W# i ?( l Q
/ A& q( u3 L/ N6 E4 J" C' R0 istatic struct gpio_led da850_evm_tl_leds[] = {
- N1 r: U6 V. K! M {$ a q5 [ C5 o* {
.active_low = 0,' w' i9 R0 a2 c7 m
.gpio = DA850_USER_LED0,) A- s5 r5 N# |' I6 _' C' S
.name = "user_led0",% L ?/ ^7 u" s: m
.default_trigger = "default-on",
4 Z( H# Z2 H# h },( k! q7 D. F9 R) P* C z
{$ k3 j/ Z9 Z3 B( N( G4 [& o g0 g5 E
.active_low = 0,8 B+ }/ U- B" K% y z8 L) Y) L1 Y$ h
.gpio = DA850_USER_LED1,
6 ^: V# S' E4 @1 n, \ .name = "user_led1",
) _: L7 s, P+ o G! S .default_trigger = "default-on",
* d6 f. r( `. } },1 o" O: c- q2 v
{
~/ w6 L( n) u8 ~# L .active_low = 0,* d6 q. ]& M& }5 E. |- z9 j! l
.gpio = DA850_USER_LED2,
2 h" F! I" j3 a8 K0 o. i7 l: A: { .name = "user_led2",
' R' m( |4 D; k, X+ a, ?/ j0 n .default_trigger = "default-on",
1 k; t. Z( A9 l },
" ]) {6 [1 M* E' y {" V1 V) F- _$ [# m2 o
.active_low = 0,
5 ]# f7 U1 I* q0 h! ^ .gpio = DA850_USER_LED3,4 }' f; v9 |+ O' k1 D( `/ b# l# B
.name = "user_led3",
. i% V# s: k+ U' i% Y- d' k) w2 V# h! T .default_trigger = "default-on",
4 c; U/ D+ c8 L* J3 s- Z6 O },6 c( t. _+ O& ?8 b; {! b+ o
};6 F# G5 v: c; l7 k' V, q
: E) j# I9 q: j$ ?2 B5 D
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {
" N# f+ D% X$ f .leds = da850_evm_tl_leds,! m' J2 H3 C" {& B$ O
.num_leds = ARRAY_SIZE(da850_evm_tl_leds),2 |+ L* }8 u$ I+ n+ B
};. t2 Q1 m4 r% q- z/ R# o! C
4 D3 u6 j r: q; @/ g4 c4 q7 Wstatic void led_dev_release(struct device *dev)1 ]& O! [+ {- [
{4 v* k4 C1 G$ V- ~0 O* M1 E: ~
};
I7 r8 t' b) W4 w& r/ r, @8 r4 X' l1 x' U. Z2 ?* [
static struct platform_device da850_evm_tl_leds_device = {' e9 H' \$ z. Q& R! v/ O
.name = "leds-gpio",* H0 c2 V# S9 @: [4 g- R0 g
.id = 1,7 C9 U& R: l% s; _6 b3 }
.dev = {
, Q5 G2 F5 K, `3 R8 p0 h .platform_data = &da850_evm_tl_leds_pdata,! o; D! G; `% _( u# \3 v
.release = led_dev_release,- F. y8 e" z! _
}" x3 O7 ^8 y9 r: g' Q$ t
};
+ T! Z* G$ B4 m$ W3 @0 T
, m' |% R8 W1 f% c M9 P3 K- Tstatic int __init led_platform_init(void)
z/ |+ K# ~6 ~{4 J3 l$ i. G2 b6 i
int ret;
- V( X" g0 i, K+ \8 N v#if 09 g/ ?" h4 v& n% e: ~1 Q; O
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);8 W& o+ G; B" @" O: |, e
if (ret)* Q, O3 S0 N, x7 u
pr_warning("da850_evm_tl_leds_init : User LED mux failed :"" r) D1 L, }- i0 J1 b
"%d\n", ret);- | D8 G$ }/ C2 b
#endif7 G2 {: J$ Q% `% c, O& Z
ret = platform_device_register(&da850_evm_tl_leds_device);
& G6 @. u- k: Y( q0 b if (ret)
9 R! Y" Z. P V1 ?9 @3 E pr_warning("Could not register som GPIO expander LEDS");
- J& `+ ~7 D( |+ {8 H0 k W! |, s5 X else8 T/ A9 _+ N0 [# v7 X# H. q7 L4 L
printk(KERN_INFO "LED register sucessful!\n");
; d# K; E1 J: b& i( N7 Z7 I
% L0 i( X0 k/ ]. j2 s) E return ret;
: }: ^% M( Q; _* e}
% N+ D+ m7 U& a
) D1 N+ `: K- [9 {7 u, zstatic void __exit led_platform_exit(void)% f! t. E1 s5 {, U* H; Y
{4 W" N& F4 [. j4 M" L4 L
platform_device_unregister(&da850_evm_tl_leds_device);9 \7 N4 K8 r j
- U% o: T, Y7 y3 R) m Z# M
printk(KERN_INFO "LED unregister!\n");. z( g6 @5 J4 ^4 d# q0 Z# F
}
/ @( |, S. L5 w4 k' E4 G
7 y) r" g+ S" k2 t0 y+ e+ @5 zmodule_init(led_platform_init);
* t( a, g" m. T7 @- ~module_exit(led_platform_exit);( I' @6 y/ K" S8 G0 d9 ^. H: Y
# V! u, } z. f! G
MODULE_DESCRIPTION("Led platform driver");; C* E5 S2 z3 ?$ i" A
MODULE_AUTHOR("Tronlong");
3 j& B( M6 k$ w* [3 e% {; Q2 O; KMODULE_LICENSE("GPL");# a5 [ f; x( M8 ~4 L' `( {
) u" y/ `! {/ P2 p+ i0 D
|
|