|
|
求大神给下面的程序做注解,请稍详细些,谢谢。% }, k; p/ T7 Y5 v
#include <linux/init.h>
/ I3 f% _5 k( w2 S/ b#include <linux/module.h>
! {7 Q* u/ V1 k5 t a6 G8 f# @#include <linux/kernel.h>
2 Y! @) z& I- \#include <linux/types.h>
4 N9 Q( K2 u9 @#include <linux/gpio.h>/ j. U/ Y* Q% ^ d) x9 ?
#include <linux/leds.h>
! |! L3 L; X5 U ^, W; Y( ?( d#include <linux/platform_device.h>8 d0 h$ o6 m! e. o, P) M: o3 }
: f2 l' `% Z$ k
#include <asm/mach-types.h>
1 @- c$ S: |( f#include <asm/mach/arch.h>
& ~' d' n: x* {0 y#include <mach/da8xx.h>) A& e: _' i1 `8 x! o
#include <mach/mux.h>
: i$ r. m1 H& N- C( \2 ^- g
3 W! o# u6 f6 Q6 x#define DA850_USER_LED0 GPIO_TO_PIN(0, 0)
3 q9 ?% O# X5 ^3 @#define DA850_USER_LED1 GPIO_TO_PIN(0, 5)% c" B1 |# Q/ Q# J' U
#define DA850_USER_LED2 GPIO_TO_PIN(0, 1)
* J& l K8 P% t2 ^! ?3 M: @+ |#define DA850_USER_LED3 GPIO_TO_PIN(0, 2)5 w6 Y* K. a( c3 A% T/ _
* ]) O* c& P: o* m% o" j. G/* assign the tl som board LED-GPIOs*/; I. _: g! M1 a7 ]: q6 I( |
static const short da850_evm_tl_user_led_pins[] = {/ B, R2 X2 U& z( r5 Y, ~: M
/* These pins are definition at <mach/mux.h> file */ G* l- L4 x0 k5 [& R A" t Z
DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_5,
% D, y) R5 N; r: x" Q, S -16 |3 Z# J$ O/ {# I; E; y
};$ [0 [1 X: C/ y
" z5 T' F1 W, q1 h- X! @, ?" o( T
static struct gpio_led da850_evm_tl_leds[] = {6 t+ \, W+ P6 @9 E
{+ _8 ^% L0 @) I* Q/ J0 W3 c
.active_low = 0,! ^! |: e9 P- z4 M; C- S1 o
.gpio = DA850_USER_LED0,' D0 t1 u% @1 [, d( N
.name = "user_led0",7 j7 i0 f0 l3 d# X0 {. x
.default_trigger = "default-on",
. a9 w4 ^* b1 U },+ ?& V/ I4 _5 ^" K8 D2 q& z2 n
{
. S! L# G7 O7 N A5 j5 ?/ ? .active_low = 0,5 F( _" Y& ~( D7 r7 Y E
.gpio = DA850_USER_LED1,4 h9 }2 S* e2 D( p* T, y0 k" d0 L
.name = "user_led1",4 E0 k) y. L9 H& W- x
.default_trigger = "default-on",, w, d: E6 u" `
},1 _( n G0 z! U1 Z/ j0 q
{
0 H, z- I U( O3 l8 N .active_low = 0,
! H8 x/ D4 s4 e .gpio = DA850_USER_LED2,
, r$ a/ M! Q* X .name = "user_led2",
4 V0 u/ X* ]# N" W .default_trigger = "default-on",; z: _% F$ h0 C" b' n& a
},# U" V& Z0 T0 A
{& j# A& B1 s1 N2 I
.active_low = 0,2 A3 r$ d9 n' J/ {* e# Y
.gpio = DA850_USER_LED3,& a4 L5 J9 Y0 b( J; B
.name = "user_led3",
, _2 u' D) q7 R- p3 v .default_trigger = "default-on",
8 v# U9 [: U6 s) Y },
- S8 j! T: B7 v- r1 s2 R2 ?};
4 a5 q6 w9 R' _! M/ \3 E! l: g) y8 p& O5 N f/ e. A
static struct gpio_led_platform_data da850_evm_tl_leds_pdata = {3 J8 S0 w" O9 Q
.leds = da850_evm_tl_leds,
% [2 u' R" \: I% _ .num_leds = ARRAY_SIZE(da850_evm_tl_leds),* P+ C w, P8 W5 O7 P# K
};
3 {/ j9 O% y# @: t( [) Z/ l" [( w/ q. C* ~6 d% t/ b2 J
static void led_dev_release(struct device *dev)
5 z+ U/ n% }1 @; {( G8 S# G; u, g{! }9 r4 l& B; k3 r
};
' F. w, _2 ?( |( Q2 y, v Z+ M
, z+ u- ]( v5 s7 Ystatic struct platform_device da850_evm_tl_leds_device = {8 t; A) M* B. R: e
.name = "leds-gpio",# _7 M4 U: |4 i$ B+ m; D! C
.id = 1,
" L G3 ^! A/ M, n' @1 \ .dev = {2 M2 i2 j7 P( [ O: {
.platform_data = &da850_evm_tl_leds_pdata,) n( c7 H: O* B
.release = led_dev_release,
7 h1 b! `2 V( Q! M2 r- Y }
* n+ x4 d$ n$ A- }! y};
' P0 }* U H$ \, j- i. |) c- E3 ?. R
static int __init led_platform_init(void)
( x( `2 I+ s( F6 S" ?2 c+ L{2 C( U$ V% }% j( J
int ret;' X' @; f" H! I- Q9 y# z- l8 @7 a
#if 05 z$ v# B- ?& g0 M) o3 i2 x2 b- D
ret = davinci_cfg_reg_list(da850_evm_tl_user_led_pins);4 T+ \" Z% T/ T# i/ X
if (ret)
! S ?7 z f( Y! z! S1 J pr_warning("da850_evm_tl_leds_init : User LED mux failed :"
8 f4 Z# |( W3 z" b) h "%d\n", ret);
; L$ I& B0 f$ [; p' ]#endif
6 {, ]6 L6 f4 L- A ret = platform_device_register(&da850_evm_tl_leds_device);
8 c6 g- _) F. C' X7 t if (ret)
$ V' V/ S% v( u) V9 b; e pr_warning("Could not register som GPIO expander LEDS"); l' r2 k! \2 N) c+ z9 ]
else2 q3 K T. X0 Z* {" U2 |( t( }! R
printk(KERN_INFO "LED register sucessful!\n");
$ [' R% \5 z6 t1 o) v2 k
' e, ]& L$ q+ h; H0 N/ S: W return ret;
$ A, ~) N4 R' C6 ~, z0 V6 g* n}
& q" {- C0 }( ?* t
- t( v- R3 G8 a ]. M$ mstatic void __exit led_platform_exit(void)
$ q7 M* ~7 R4 I! k8 A{
8 f1 o! x* _7 ?0 a platform_device_unregister(&da850_evm_tl_leds_device);
B; P! N- \1 u8 `, {" R( V* t* v
5 ~( @& P6 J" u3 m# C4 y( \ printk(KERN_INFO "LED unregister!\n");
3 _8 D7 v2 J* N; v; v" k3 J}
" a6 B0 u h6 A- {8 G( c% R+ c( N* R9 C; K
module_init(led_platform_init);- \; S" o* J! m9 A: ]; N5 _$ Z
module_exit(led_platform_exit);/ z- f" c0 K. E# }) [
# k+ [2 e* t$ K7 J& Z6 J; pMODULE_DESCRIPTION("Led platform driver");5 i- q; s& d% i2 w' m
MODULE_AUTHOR("Tronlong");
0 Z" e( N" ?/ c, Q1 ~+ B7 C$ zMODULE_LICENSE("GPL");
! e7 Y& ?7 M0 ~2 ]
9 |7 M; L2 r$ R |
|