huangcm
2025-09-01 53d8e046ac1bf2ebe94f671983e3d3be059df91a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * (C) Copyright 2007-2013
 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
 * Char <yanjianbo@allwinnertech.com>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
 * GNU General Public License for more details.
 */
 
#include <common.h>
#include <asm/arch/timer.h>
#include <sys_config.h>
#include <asm/arch/cpu.h>
#include <fdt_support.h>
#include <sys_config.h>
#include <asm-generic/gpio.h>
#include <sunxi_board.h>
 
struct timer_list TIMER0;
static int sprite_led_status;
static __u32 sprite_led_hd;
 
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
static void sprite_timer_func(void *p)
{
   gpio_write_one_pin_value(sprite_led_hd, sprite_led_status,
                "sprite_gpio0");
   sprite_led_status = (~sprite_led_status) & 0x01;
 
   //printf("sprite_time_func\n");
   del_timer(&TIMER0);
   add_timer(&TIMER0);
   return;
}
 
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
int sprite_led_init(void)
{
   user_gpio_set_t gpio_init;
   int ret   = 0;
   int delay = 0;
 
   sprite_led_status = 1;
 
   //正常工作时,灯闪烁的时间
   ret = script_parser_fetch("/soc/card_boot", "sprite_work_delay",
                 (void *)&delay, 0);
 
   if (!delay) {
       delay = 500;
   }
 
   pr_msg("try sprite_led_gpio config\n");
   memset(&gpio_init, 0, sizeof(user_gpio_set_t));
 
   //配置输出gpio口
   ret = fdt_get_one_gpio(FDT_PATH_CARD_BOOT, "sprite_gpio0", &gpio_init);
   if (!ret) {
       if (gpio_init.port) {
           sprite_led_hd = sunxi_gpio_request(&gpio_init, 1);
           if (!sprite_led_hd) {
               pr_err("reuqest gpio for led failed\n");
               return 1;
           }
 
           TIMER0.data     = (unsigned long)&TIMER0;
           TIMER0.expires  = delay;
           TIMER0.function = sprite_timer_func;
           //init_timer(&TIMER0);
           add_timer(&TIMER0);
 
           tick_printf("sprite_led_gpio start\n");
           return 0;
       }
   }
   return 0;
}
 
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
int sprite_led_exit(int status)
{
   //int ret;
   int delay;
   int nodeoffset;
 
   del_timer(&TIMER0);
 
   //出错的时候,led的闪烁加快
   if (status < 0) {
       delay      = 0;
       nodeoffset = fdt_path_offset(working_fdt, FDT_PATH_CARD_BOOT);
       if (nodeoffset > 0) {
           fdt_getprop_u32(working_fdt, nodeoffset,
                   "sprite_err_delay", (uint32_t *)&delay);
       }
       if (!delay) {
           delay = 100;
       }
       del_timer(&TIMER0);
       TIMER0.data     = (unsigned long)&TIMER0;
       TIMER0.expires  = delay;
       TIMER0.function = sprite_timer_func;
       //init_timer(&TIMER0);
       add_timer(&TIMER0);
   }
 
   return 0;
}