-
Notifications
You must be signed in to change notification settings - Fork 2
/
tpmain.c.orig
389 lines (325 loc) · 10.3 KB
/
tpmain.c.orig
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#include <time.h>
#include <sys/mman.h>
#include <pthread.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include "hi_stb_api.h"
#include "fyf_com.h"
#include "hi_unf_tuner.h"
//#include <unistd.h>
//#include <stdio.h>
//#include <sys/types.h>
//#include <sys/stat.h>
//#include <string.h>
#define POWERUP_IR 0x6d927f80
#define POWERUP_KEY 3
HI_U32 g_standy_flag = 0xff;
#define REG_SYS_BASE 0x101e0000
#define REG_USB_RESET 0x80
#define SET_ETH_RESET (1<<15)
#define SET_USB_PHY_RESET (1<<16)
#define SET_USB_CTRL_RESET (1<<17)
#define REG_USB_CLK_EN 0x24
#define REG_USB_CLK_DIS 0x28
#define SET_USB_CLK (1<<20)
#define SET_ETH_CLK (1<<12)
void Hi_Pmoc_USB_ETH_CTL(int low_pwr)
{
int reg;
void *sysctl_map;
int fd=open("/dev/mem",O_RDWR|O_SYNC,00777);
sysctl_map = mmap(NULL,0x4000,PROT_READ|PROT_WRITE,MAP_SHARED,fd,REG_SYS_BASE);
if (sysctl_map == MAP_FAILED)
{
printf(" mmap failed.\n");
return ;
}
/*Set GPIO_05 Reuse*/
reg = *(volatile unsigned int*)(0x1c + sysctl_map);
reg |= (0x70000);
*(volatile unsigned int*)(0x1c + sysctl_map) = reg;
msync(sysctl_map, 0x4000, MS_ASYNC);
if(low_pwr)
{
/************* Disable USB start ****************/
/*Rmmod USB Driver*/
printf("77777777777\n");
system("rmmod ohci_hcd");
system("rmmod ehci_hcd");
/*reset USB PHY & controller*/
reg = *(volatile unsigned int*)(REG_USB_RESET + sysctl_map);
reg |= (SET_USB_PHY_RESET | SET_USB_CTRL_RESET);
*(volatile unsigned int*)(REG_USB_RESET + sysctl_map) = reg;
msync(sysctl_map, 0x4000, MS_ASYNC);
/*Disable USB CLK*/
reg = *(volatile unsigned int*)(REG_USB_CLK_DIS + sysctl_map);
reg |= (SET_USB_CLK);
*(volatile unsigned int*)(REG_USB_CLK_DIS + sysctl_map) = reg;
msync(sysctl_map, 0x4000, MS_ASYNC);
/************ Disable USB end *******************/
/************ Disable ETH Power start ****************/
/*Disable ETH CLK*/
reg = *(volatile unsigned int*)(0x40 + sysctl_map);
reg |= (1<<26);
*(volatile unsigned int*)(0x40 + sysctl_map) = reg;
msync(sysctl_map, 0x4000, MS_ASYNC);
/************ Disable ETH Power end ****************/
}
else
{
/************** Enable USB start ****************/
/*Enable USB CLK*/
reg = *(volatile unsigned int*)(REG_USB_CLK_EN + sysctl_map);
reg |= (SET_USB_CLK);
*(volatile unsigned int*)(REG_USB_CLK_EN + sysctl_map) = reg;
msync(sysctl_map, 0x4000, MS_ASYNC);
//udelay(100);
usleep(100);
/*Enable USB PHY*/
reg = *(volatile unsigned int*)(REG_USB_RESET + sysctl_map);
reg &= ~(SET_USB_PHY_RESET);
*(volatile unsigned int*)(REG_USB_RESET + sysctl_map) = reg;
msync(sysctl_map, 0x4000, MS_ASYNC);
//udelay(100);
usleep(100);
/*Enable USB controller*/
reg = *(volatile unsigned int*)(REG_USB_RESET + sysctl_map);
reg &= ~(SET_USB_CTRL_RESET);
*(volatile unsigned int*)(REG_USB_RESET + sysctl_map) = reg;
msync(sysctl_map, 0x4000, MS_ASYNC);
//udelay(100);
usleep(100);
/*Insmod USB driver*/
system("insmod /kmod/ehci-hcd.ko");
system("insmod /kmod/ohci-hcd.ko");
/************** Enable USB end *******************/
/************ Enable ETH Power start ****************/
/*Disable ETH CLK*/
reg = *(volatile unsigned int*)(0x40 + sysctl_map);
reg &= ~(1<<26);
*(volatile unsigned int*)(0x40 + sysctl_map) = reg;
msync(sysctl_map, 0x4000, MS_ASYNC);
/************ Enable ETH Power end ****************/
}
if ( munmap( sysctl_map, 0x4000) < 0 )
{
printf("munmap failed");
exit(1);
}
close(fd);
return ;
}
HI_S32 HISDK_Init()
{
HI_S32 s32Ret;
/* 初始化输出设备 */
s32Ret = HI_UNF_VO_Init();
if (HI_SUCCESS != s32Ret)
{
printf("ErrorCode:%08x LINE %d\n", s32Ret, __LINE__);
return s32Ret;
}
s32Ret = HI_UNF_GPIO_Write_Bit(14,1);
if (HI_SUCCESS != s32Ret)
{
printf("(%d):HI_UNF_GPIO_Open Error,ret=0x%x\n", __LINE__, s32Ret);
}
s32Ret |= HI_UNF_SND_Init();
if (HI_SUCCESS != s32Ret)
{
printf("ErrorCode:%08x LINE %d\n", s32Ret, __LINE__);
return s32Ret;
}
s32Ret |= HI_UNF_DISP_Init();
if (HI_SUCCESS != s32Ret)
{
printf("ErrorCode:%08x LINE %d\n", s32Ret, __LINE__);
return s32Ret;
}
s32Ret |= HI_UNF_AVPLAY_Init();
if (HI_SUCCESS != s32Ret)
{
printf("ErrorCode:%08x LINE %d\n", s32Ret, __LINE__);
return s32Ret;
}
HI_UNF_TUNER_ATTR_S stTunerAttr;
if (HI_SUCCESS != HI_UNF_TUNER_Init())
{
printf("\n +++ HI_UNF_TUNER_Init failed +++\n");
}
if (HI_SUCCESS != HI_UNF_TUNER_Open(0))
{
printf("\n +++ HI_UNF_TUNER_Open failed +++\n");
}
HI_UNF_TUNER_GetDeftAttr(0 , &stTunerAttr);
#ifdef _NEWLAND_DEMO_
stTunerAttr.enTunerDevType = HI_UNF_TUNER_DEV_TYPE_TMX70600;
if(HI_TUNER_CheckValid_I2cAddr(0,0xc6) != HI_SUCCESS)
{
HI_TUNER_CheckValid_I2cAddr(0,0xc0);
FYF_API_tuner_set_dev_addr(0);
printf("detect tuner devaddr is 0xc0 \n");
}
else
{
FYF_API_tuner_set_dev_addr(1);
printf("detect tuner devaddr is 0xc6 \n");
}
#endif
HI_UNF_TUNER_SetAttr(0 , &stTunerAttr);
s32Ret = HI_UNF_PMOC_Open();
if (HI_SUCCESS != s32Ret)
{
printf("(%d):HI_UNF_PMOC_Open Error,ret=0x%x\n", __LINE__, s32Ret);
}
/*
s32Ret = OSDGAL_Init();
if (s32Ret != HI_SUCCESS)
{
printf("OSDGAL_Init fail\n");
}
*/
return s32Ret;
}
int main(int argc, char *argv[])
{
HI_S32 ret,s32Ret;
HI_UNF_PMOC_STANDBY_MODE_S stStandbyMode;
FYF_E2P_IOCTL_PARAM_s fyf_e2p_ioctl_param;
BU08 time[2];
#ifdef _HAISI_DEMO_
printf("************************************HAISI DEMO***************************\n");
#else
printf("************************************NEWLAND DEMO***************************\n");
#endif
#ifdef FLASH_8M
printf("************************************8M FLASH***************************\n");
#else
printf("************************************16M FLASH***************************\n");
#endif
#ifdef BOX_ENCRYPT_E2PROM
printf("************************************ENCRYPT EEPROM***************************\n");
#else
printf("************************************NORMAL EEPROM***************************\n");
#endif
if( argc == 2 )
{
g_standy_flag = atoi(argv[1]);
}
s32Ret = HI_UNF_GPIO_Open();
if (HI_SUCCESS != s32Ret)
{
printf("(%d):HI_UNF_GPIO_Open Error,ret=0x%x\n", __LINE__, s32Ret);
}
s32Ret = HI_UNF_GPIO_DirSet_Bit(14,HI_FALSE);
if (HI_SUCCESS != s32Ret)
{
printf("(%d):HI_UNF_GPIO_DirSet_Bit Error,ret=0x%x\n", __LINE__, s32Ret);
}
HISDK_Init();
TP_Led_Init();
TP_KEY_Init();
TP_IR_Init();
FYF_API_dev_register();
//进入低功耗状态
if( 0xfe == g_standy_flag)
{
HI_UNF_PMOC_WKUP_S sAttr;
HI_UNF_PMOC_MODE_E enUnfSystemMode;
HI_U32 u32WakeupStatus;
APP_Com_API_ShowLED(" ");
HI_UNF_LED_SetFlashPin(HI_UNF_KEYLED_LIGHT_1);
fyf_e2p_ioctl_param.buffer = (PU08)time;
fyf_e2p_ioctl_param.bufferSize = sizeof(time);
//FYF_API_e2p_ioctl (FYF_E2P_IOCTL_READ_EX, 513, (BU32)&fyf_e2p_ioctl_param);
FYF_API_e2p_ioctl (FYF_E2P_IOCTL_READ_EX, 32, (BU32)&fyf_e2p_ioctl_param);
printf("power down ...........\n");
sAttr.u32IrPowerKey = POWERUP_IR;
sAttr.u32KeypadPowerKey = POWERUP_KEY;
//设置唤醒方式
ret = HI_UNF_PMOC_SetWakeUpAttr(&sAttr);
if( HI_SUCCESS != ret)
{
printf("HI_UNF_PMOC_SetWakeUpAttr %08x\n",ret);
}
//进入睡眠模式
printf("sleeping......\n");
printf("time = %d %d\n", time[0], time[1]);
#if 0
stStandbyMode.u32Mode = 2;
stStandbyMode.u32DispCode = 9009;
stStandbyMode.stTimeInfo.u32Hour = time[0]%24;//tv.tv_sec /3600;
stStandbyMode.stTimeInfo.u32Minute = time[1]%60;//(tv.tv_sec %3600)/60;
stStandbyMode.stTimeInfo.u32Second = 30;//(tv.tv_sec %3600)%60;
s32Ret = HI_UNF_PMOC_SetStandbyDispMode(&stStandbyMode);
if (HI_SUCCESS != s32Ret)
{
printf("(%d): HI_UNF_PMOC_SetStandbyDispMode Error,ret=0x%x\n", __LINE__, s32Ret);
return HI_FAILURE;
}
#endif
#if 1
system("echo 2000 > /proc/sys/vm/min_free_kbytes");
system("ifconfig eth0 down");
system("ifconfig eth1 down");
system("echo 0x0 0x1 0x0 0x190 > /proc/x5net/client_iface/phy_write");
system("echo 0x1 0x3 0x0 0x190 > /proc/x5net/client_iface/phy_write");
system("echo 0x0 0x1 0x0 0x800 > /proc/x5net/client_iface/phy_write");
system("echo 0x1 0x3 0x0 0x800 > /proc/x5net/client_iface/phy_write");
system("rmmod hi_eth.ko");
Hi_Pmoc_USB_ETH_CTL(1);
#endif
ret = HI_UNF_PMOC_SwitchSystemMode(HI_UNF_PMOC_MODE_SLEEP, &u32WakeupStatus);
if (HI_SUCCESS != ret)
{
printf("HI_UNF_PMOC_SwitchSystemMode,ret=0x%x\n", ret);
return HI_FAILURE;
}
HI_UNF_LED_SetFlashPin(HI_UNF_KEYLED_LIGHT_NONE);
#if 1
Hi_Pmoc_USB_ETH_CTL(0);
system("insmod /kmod/hi_eth.ko");
system("ifconfig eth0 up");
system("ifconfig eth1 up");
system("echo 0x0 0x1 0x0 0x1000 >/proc/x5net/client_iface/phy_write");
system("echo 0x1 0x1 0x0 0x1000 >/proc/x5net/client_iface/phy_write");
#endif
printf("power up ........... by %d\n",u32WakeupStatus);
}
#if 1 //added by mabel for opening sound
s32Ret |= HI_UNF_GPIO_Write_Bit(14,0);
if (HI_SUCCESS != s32Ret)
{
printf("(%d):HI_UNF_GPIO_Write_Bit Error,ret=0x%x\n", __LINE__, s32Ret);
}
usleep(50000);
#endif
HI_ETH_Open(0);
APP_Com_API_ShowLED("0000");
FYF_API_OSD_Init();
FYF_API_os_register();
FYF_API_sys_register();
FYF_API_demux_init();
#ifdef ENABLE_PVR
FYF_API_PVR_Init();
#endif
FYF_API_av_register();
#ifndef NO_CA
FYF_API_SMC_Init();
FYF_API_CA_Init();
FYF_API_DESCR_init();
#endif
FYF_API_mfs_init();
FYF_API_sql_init();
FYF_API_tuner_init();
//Ipanel_DLRegionId();
FYF_API_createGUIThread();
while (1)
{
// printf("main task is sleeping\n");
FYF_API_thread_sleep(2148573);
}
return 0;
}
//chenmeibao