reset.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:56k
源码类别:

DVD

开发平台:

C/C++

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *         Copyright (c) 2002 by Sunplus Technology Co., Ltd.             *
  4.  *                                                                        *
  5.  *  This software is copyrighted by and is the property of Sunplus        *
  6.  *  Technology Co., Ltd. All rights are reserved by Sunplus Technology    *
  7.  *  Co., Ltd. This software may only be used in accordance with the       *
  8.  *  corresponding license agreement. Any unauthorized use, duplication,   *
  9.  *  distribution, or disclosure of this software is expressly forbidden.  *
  10.  *                                                                        *
  11.  *  This Copyright notice MUST not be removed or modified without prior   *
  12.  *  written consent of Sunplus Technology Co., Ltd.                       *
  13.  *                                                                        *
  14.  *  Sunplus Technology Co., Ltd. reserves the right to modify this        *
  15.  *  software without notice.                                              *
  16.  *                                                                        *
  17.  *  Sunplus Technology Co., Ltd.                                          *
  18.  *  19, Innovation First Road, Science-Based Industrial Park,             *
  19.  *  Hsin-Chu, Taiwan, R.O.C.                                              *
  20.  **************************************************************************/
  21. /*--------------------------------------------------------------------------
  22. |  File Name   :  reset.c
  23. |
  24. |  Description :   .... reset system
  25. |                 when system need reset,it will goto the file.
  26. |
  27. |
  28. |  Version    :  0.1  
  29. |  
  30. |  Rev    Date              Author(s)      Status & Comments
  31. |-----------------------------------------------------------------------------------------
  32. |  0.1  2004/2/7            Terry          Add DVD Preview function and re-structure code
  33. |  0.1  2004/12/31          caoh           Add Comments
  34. |-----------------------------------------------------------------------------------------*/
  35. #include "config.h"
  36. #include "regmap.h"
  37. #include "global.h"
  38. #include "syscfg.h"
  39. #include "sysclk.h"
  40. #include "load.h"
  41. #include "macro.h"
  42. #include "dma.h"
  43. #include "memcfg.h"
  44. #include "stc.h"
  45. #include "func.h"
  46. #include "cpu.h"
  47. #include "intdef.h"
  48. #include "gpio.h"
  49. #include "uart.h"
  50. #include "uartfifo.h"
  51. #include "viddec.h"
  52. #include "kernel.h"
  53. #include "supfunc.h"
  54. #include "hwif.h"
  55. #include "framebuf.h"   //Jeff 20010717
  56. #include "task.h"
  57. #include "audio.h"
  58. #include "lbaif.h"
  59. #include "cs8403a.h"    //kenny
  60. #include "dvdpe.h"
  61. #include "preview.h"
  62. #include "tvif.h"
  63. #include "test.h"
  64. #include "sio.h"
  65. #include "emuio.h"
  66. #include "user_init.h"
  67. //#define SHOW_SYSTEM_CLOCK
  68. //#ifdef   DVDRELEASE
  69. #ifndef SDRAM_BUS_32BITS
  70. #ifndef SDRAM_16Mb_Mode//terry,2003/11/18 02:04PM
  71. #define  UART0_SHARE_WITH_UART1
  72. #endif
  73. #endif
  74. //#endif
  75. #ifdef QSI_SHOW_ERR_RATE   
  76.     #undef  UART0_SHARE_WITH_UART1
  77. #endif          
  78. #include "reset.h"
  79. #if defined(PT2322)||defined(PT2320)
  80. #include "audctrl.h"
  81. #endif
  82. #ifdef TAS3001_AMP    //
  83. #include "ti3001.h"
  84. #endif
  85. #ifdef TAS5026_AMP    //
  86. #include "ti5026.h"
  87. #endif
  88. #ifndef EMULATION
  89. //#define SETUP_DAC
  90. #endif
  91. #ifndef DVDRELEASE
  92. //#define RESET_DBG 1
  93. //#define DRAM_TEST 1
  94. //#define TASK_GBG  1//??
  95. #endif
  96. #define DRAM_TEST_16MB
  97. //#define DRAM_TEST_64MB
  98. #ifdef  RESET_DBG   /* alan 02-05-24 */
  99. //#define MONE_CHKSUM
  100. #define MONE_CONFIG
  101. #define reset_status_puts(s)        io_write_wait(s)
  102. #define reset_status_puts_direct(s) io_write(s)
  103. #endif
  104. #ifndef reset_status_puts
  105. #define reset_status_puts(s)        ((void)(s))
  106. #endif
  107. #ifndef reset_status_puts_direct
  108. #define reset_status_puts_direct(s) ((void)(s))
  109. #endif
  110. #ifdef CS8403_ENABLE
  111. //extern void init_cs8403a__(void);
  112. #include "cs8403a.c"
  113. #endif
  114. //
  115. // SPHE8202 tuning
  116. //
  117. #ifdef  SPHE8202
  118. #if 0
  119. #undef  F121_5
  120. #undef  F114_75
  121. #undef  F108
  122. #undef  F94_5
  123. #undef  F81
  124. //#define F81
  125. //#define F108
  126. #define F114_75
  127. //#define F121_5
  128. //#define F128_25
  129. //#define F135
  130. #endif
  131. #endif
  132. #ifdef  SPHE8202
  133. #define ROM_SDRAM_SHARE_BUS
  134. //#define SUPPORT_USB
  135. #endif
  136. #ifdef  SUPPORT_USB
  137. #define USB_CONFIG_PLL
  138. #define CLK54_USE_USBPLL
  139. #endif
  140. #include "sbar.inc"
  141. //
  142. // EPROM_WAIT_STATE
  143. // *NOTE* ROM access time will be n+1 cycles.
  144. //
  145. //  value   cycle   108 94.5    81  67.5    54
  146. //  --------------- ------------------------------- -----
  147. //  3   4   36.8    42.33   48  59.2    74
  148. //  4   5   46  52.91   60  74  92.5
  149. //  5   6   55.2    63.49   72  88.8    111
  150. //  6   7   64.4    74.07   84  103.6   129.5
  151. //  7   8   73.6    84.66   96  118.4   148
  152. //  8   9   82.8    95.24   108 133.2   166.5
  153. //  9   10  92.6    105.82  123.5
  154. //  10  11  101.9   116.40  135.8
  155. //  11  12  111.1   126.98  148.1
  156. //  12  13  120.37  137.57  160.49
  157. //  13  14  129.63  148.15  172.84
  158. //  14  15  138.89  158.73  185.19
  159. //  15  16  148.18  169.31  197.53
  160. //
  161. #define ROM_TACC_DEFAULT    85
  162. #define SYSCLK_CYCLE    ((unsigned)(1.0E9/SYSCLK))      // in ns unit
  163. #define ROM0_TACC       ROM_TACC_DEFAULT
  164. #define ROM1_TACC       ROM_TACC_DEFAULT
  165. #define ROM2_TACC       ROM_TACC_DEFAULT
  166. #define ROM3_TACC       ROM_TACC_DEFAULT
  167. #define ROM0_WAITST     (SYSCLK_CYCLE/ROM0_TACC)
  168. #define ROM1_WAITST     (SYSCLK_CYCLE/ROM1_TACC)
  169. #define ROM2_WAITST     (SYSCLK_CYCLE/ROM2_TACC)
  170. #define ROM3_WAITST     (SYSCLK_CYCLE/ROM3_TACC)
  171. /*
  172. #ifdef BBK_DVD//zhoayanhua add 2003-11-24 14:24
  173. //ircmd_video.c
  174. extern void tv_init_output(void);
  175. #endif
  176. */
  177. extern void dac_setup();
  178. extern void reset_iop();
  179. extern void reset_vfd(void);
  180. // sysmain.c
  181. extern void LoadModual(UINT16 iModuleIndex);
  182. // crt0.S
  183. extern void set_sdram_timing_low(void);
  184. extern void set_sdram_timing(void);
  185. // current file
  186. UINT32 rom_checksum(void);
  187. int reset_change_sysclk(void);
  188. int reset_change_sysclk_27M(void);
  189. int change_system_clock(int);
  190. /**************************************************************************
  191.  *  Function Name: reset_system                                           *
  192.  *  Purposes:                                                             *
  193.  *   1. setup register file pointer (regs0 / s6)                          *
  194.  *   2. reset/enable hardware modules                                     *
  195.  *   3. setup watchdog/scrambling                                         *
  196.  *   4. setup rom1/2/3 bases                                              *
  197.  *   5. setup ROM/FLASH interface                                         *
  198.  *   6. setup system-bus arbitrator                                       *
  199.  *   7. reset audio                                                       *
  200.  *  Descriptions:                                                         *
  201.  *    reset following subsystems to a known state                         *
  202.  *  Arguments:  None                                                      *
  203.  *  Returns: None                                                         *
  204.  *  See also: None                                                        *
  205.  **************************************************************************/
  206. void
  207. reset_system(void)
  208. {
  209.     // setup register file pointer (regs0 / s6)
  210.     InitRegFile();
  211.     regs0->emulation    = 0;        // disable emulation functions
  212.     regs0->reset        = 0x0000;   //
  213. #ifdef SPHE1000
  214.     regs0->reset2       |= 0x2080;   // (boot-strap / tdm / cddsp)
  215. #else
  216.     regs0->reset2       = 0x3080;   // (boot-strap / tdm / cddsp)
  217. #endif
  218.     regs0->clken0       = 0xff7f;   // (grfx)
  219.     regs0->clken1       = 0xffff;   // ()
  220.     regs0->gclken0      = 0xffff;
  221.     regs0->gclken1      = 0xffff;
  222.     // [15:13] atg
  223.     // [7:6] dtg
  224.     // [1:0] watchdog
  225.     regs0->lbc_watchdog   = 0x03;     // disable watchdog/tog
  226.     // setup rom1/2/3 bases
  227. #ifdef SPHE1000 //MIKEY 2004.05.25
  228.     regs0->rom1_base      = 0x00800000 >> 16;       // rom1 m*64k-base  8MB
  229.     regs0->rom2_base      = 0x01000000 >> 16;       // rom2 n*64k-base 16MB
  230.     regs0->rom3_base      = 0x02000000 >> 16;       // rom3 n*64k-base 32MB
  231. #else
  232.     regs0->rom1_base      = 32;       // rom1 m*64k-base
  233.     regs0->rom2_base      = 32;       // rom2 n*64k-base
  234.     regs0->rom3_base      = 32;       // rom2 n*64k-base
  235. #endif
  236. #define VPP_CONFIG1_URGE_EN     (1<<4)//terry,2->4
  237. #define VPP_CONFIG1_URGE_DIS    (0<<4)
  238. #define VPP_CONFIG1_MB45        0       // 720
  239. #define VPP_CONFIG1_MB64        1       // 1024
  240. #define VPP_CONFIG1_MB22        2       // 352
  241. #define VPP_CONFIG1_MB30        3       // 480
  242. #if 1
  243.     regs0->mc_mbwidth       = 45;
  244.     regs0->vpp_config1  = VPP_CONFIG1_URGE_DIS|VPP_CONFIG1_MB45;
  245. #else
  246.     regs0->mc_mbwidth       = 64;
  247.     regs0->vpp_config1  = VPP_CONFIG1_URGE_DIS|VPP_CONFIG1_MB64;
  248. #endif
  249.     vpp_zoom_max    = VPP_ZOOM_MAX;
  250.     //
  251.     // setup ROM/FLASH interface
  252.     regs0->rom_config = 0xf000;     // always no pre-fetch
  253. #if 0
  254. #ifdef ROM_SDRAM_SHARE_BUS
  255.     regs0->rom_config = 0xf000;     // no pre-fetch
  256. #else
  257.     regs0->rom_config = 0xf00f;     // with pre-fetch
  258. #endif
  259. #endif
  260.     {
  261.         unsigned u;
  262.         u = (ROM0_TACC/SYSCLK_CYCLE) | ((ROM1_TACC/SYSCLK_CYCLE)<<8);
  263.         regs0->wait_cyc1_0 = u;
  264.         u = (ROM2_TACC/SYSCLK_CYCLE) | ((ROM3_TACC/SYSCLK_CYCLE)<<8);
  265.         regs0->wait_cyc3_2 = u;
  266.     }
  267.     //
  268.     // setup system-bus arbitrator
  269.     {
  270.         unsigned i;
  271.         for (i=0;i<sizeof(sbar_prr)/sizeof(sbar_prr[0]);i++)
  272.             regs0->sbar_prr[i] = sbar_prr[i];
  273.     }
  274. #ifndef NO_AUDIO_DSP
  275.     // audio
  276.     regs0->aud_reset = 1;
  277.     regs0->aud_reset = 0;
  278. #endif
  279. }
  280. #ifdef  MONE_CHKSUM
  281. /**************************************************************************
  282.  *  Function Name: rom_checksum                                           *
  283.  *  Purposes:                                                             *
  284.  *    At present, the funtion don't used                                  *
  285.  *  Descriptions:                                                         *
  286.  *    calculate rom check-sum (of first 512kbyte)                         *
  287.  *  Arguments:  None                                                      *
  288.  *  Returns: None                                                         *
  289.  *  See also: None                                                        *
  290.  **************************************************************************/
  291. UINT32
  292. rom_checksum(void)
  293. {
  294.     int i;
  295.     UINT32 chksum=0;
  296.     UINT32 *p = (UINT32 *)(ROM_BASE_CACHED);
  297.     for (i=0;i<(512*1024/4); i++)
  298.     {
  299.         chksum += *p++;
  300.     }
  301.     return chksum;
  302. }
  303. #endif
  304. #ifdef BOOT_LOAD//terry,2005/1/30 09:21PM
  305. #include "rommap_romb.h"
  306. /**************************************************************************
  307.  *  Function Name: rom_checksum                                           *
  308.  *  Purposes:                                                             *
  309.  *    At present, the funtion don't used                                  *
  310.  *  Descriptions:                                                         *
  311.  *    calculate rom check-sum (of first 512kbyte)                         *
  312.  *  Arguments:  None                                                      *
  313.  *  Returns: None                                                         *
  314.  *  See also: None                                                        *
  315.  **************************************************************************/
  316. UINT32 rom_checksum_per_kbyte(int st,int end)
  317. {
  318.     int i;
  319.     UINT32 chksum=0;    
  320.     UINT32 *p1;
  321.     UINT32 *q= (UINT32 *)(ROM_BASE_UNCACHED+ORG_BOOT_ROM_CHK_SUM);
  322.     
  323.     for (i=st;i<end; i++)
  324.     {
  325.         p1=(UINT32 *)( ROM_BASE_UNCACHED+(i*1024) );
  326.         //printf("-%x: %x-n",p1,*p1 );
  327.         chksum += *p1;
  328.         // delay_1ms(1000);
  329.     }
  330.     
  331.     //printf("nn == chksum:%x q:%x==nn\n",chksum,*q);
  332.     
  333.     if(*q==chksum) return 1;//goto boot rom
  334.     else return 0;
  335. }
  336. #endif
  337. /**************************************************************************
  338.  *  Function Name: init_timer                                             *
  339.  *  Purposes:                                                             *
  340.  *   1. setup STC 90kHz                                                   *
  341.  *   2. setup RTC 100Hz                                                   *
  342.  *   3. setup regs0->timer0_ctrl                                          *
  343.  *   4. setup timer2                                                      *
  344.  *   5. setup timer3                                                      *
  345.  *  Descriptions:                                                         *
  346.  *    reset following subsystems to a known state                         *
  347.  *  Arguments:  None                                                      *
  348.  *  Returns: None                                                         *
  349.  *  See also: None                                                        *
  350.  **************************************************************************/
  351. void    init_timer(void)
  352. {
  353.   // setup STC 90kHz
  354. #if defined(SPHE8202) || defined(SPHE1000)
  355.   regs0->stc_divisor    = (1<<15) | (150-1);
  356. #else
  357.   regs0->stc_divisor    = STC_DIVISOR;
  358. #endif
  359.   // setup RTC 100Hz
  360.   regs0->rtc_divisor    = 900-1;
  361. //terry,2004/2/17 06:08PM
  362. //if defined "SHOW_STANDBY_TIMER",timer0 would be used.suqiaoli modified 2004-2-26
  363. #if (defined(DVDRELEASE)|| !defined(TASK_GBG))&&!defined(SHOW_STANDBY_TIMER)
  364.   regs0->timer0_ctrl    = TIMER_CONFIG_STOP;
  365. #else
  366. #ifdef DVD_SERVO
  367. #ifdef EMU_MODE
  368.   regs0->timer0_ctrl    = TIMER_CONFIG_1ms;
  369. #else
  370.   regs0->timer0_ctrl    = TIMER_CONFIG_10ms;
  371. #endif
  372. #else
  373.   regs0->timer0_ctrl    = TIMER_CONFIG_4ms;
  374. #endif
  375. #endif
  376.   regs0->timer1_ctrl    = TIMER_CONFIG_STOP;
  377. #if 1
  378.   regs0->timer2_reload  = 0x4;
  379.   regs0->timer2_divisor = 0xffff;
  380.   regs0->timer2_ctrl    = 0;                // stop: this timer is used in performance meter
  381. #endif
  382. #ifdef SPHE1000
  383. #define TIMER3_PERIOD   0.01       // in second
  384. #define TIMER3_PRES     (SYSCLK/1000000)
  385. #else
  386. #define TIMER3_PERIOD   0.002       // in second
  387. #define TIMER3_PRES     2000
  388. #endif
  389.   regs0->timer3_reload  = (unsigned)((TIMER3_PERIOD*SYSCLK)/TIMER3_PRES) - 1;
  390.   regs0->timer3_divisor = TIMER3_PRES-1;
  391.   regs0->timer3_ctrl    = 3;                // go and reload
  392. }
  393. #ifdef DVD_SERVO
  394. void ServoDecInit(void);
  395. void ResetInterfaceProc(void);
  396. #endif
  397. #ifndef DVDRELEASE
  398. #define SUPPORT_UART0_INTR
  399. //#define SUPPORT_UART1_INTR
  400. #define write_stamp(n)  (regs0->stamp = (n))
  401. #endif
  402. #ifndef write_stamp
  403. #define write_stamp(n)  ((void)0)
  404. #endif
  405. enum    {
  406.     STAMP_RESET_START           = 0x01,
  407.     STAMP_RESET_SYSTEM,
  408.     STAMP_CHANGE_SYSCLK,
  409.     STAMP_LOAD_MODULE_OTHER,
  410.     STAMP_LOAD_MODULE_CDROM,
  411.     STAMP_DISABLE_VIDEO,
  412.     STAMP_ENABLE_INTR_0,
  413.     STAMP_RESET_WATCHDOG,
  414.     STAMP_LOAD_MODULE_MPEG,
  415.     STAMP_LOAD_MODULE_AP,
  416.     STAMP_LOAD_MODULE_AP2,
  417.     STAMP_LOAD_MODULE_FREE,
  418.     STAMP_RESET_OSD,
  419.     STAMP_CONFIG_MEMORY,
  420.     STAMP_ENABLE_INTR_1,
  421.     STAMP_RESET_FINISHED,
  422. };
  423. //
  424. // FUNCTION
  425. // reset_all
  426. //
  427. // DESCRIPTION
  428. // reset all, including some interface.
  429. //
  430. // *DISABLE INTR
  431. // *REGF + ROMIF setup
  432. // *EMUIO/UART setup (interrupt not yet enabled)
  433. // *APLL setup (before GPIO for correct XCK)
  434. // *GPIO setup
  435. // *SDRAM size setup
  436. // *TIMER setup
  437. // *SDRAM memory mapping configuration
  438. // *VIDDEC
  439. // *SUP
  440. // *MULTI-TASK
  441. // *ENABLE INTR
  442. // *IOP
  443. // *IR      (iop)
  444. // *VFD     (iop)
  445. // *TV-encoder  (iop)
  446. // *DAC     (iop)
  447. //
  448. //
  449. /**************************************************************************
  450.  *  Function Name: reset_all_enter                                        *
  451.  *  Purposes:                                                             *
  452.  *   1. disable CPU-level intr_enable                                     *
  453.  *   2. disable watchdog                                                  *
  454.  *   3. write stamp Start                                                 *
  455.  *  Descriptions:                                                         *
  456.  *    reset Start                                                         *
  457.  *  Arguments:  None                                                      *
  458.  *  Returns: None                                                         *
  459.  *  See also: None                                                        *
  460.  **************************************************************************/
  461. static void
  462. reset_all_enter(void)
  463. {
  464.     // disable CPU-level intr_enable
  465.     cpu_intr_disable();
  466.     // disable watchdog, we are about to reset all sub-systems
  467.     watchdog_onoff(0);
  468. #ifdef  UART0_SHARE_WITH_UART1
  469.     sft_uart0_share_uart1_pins();
  470. #endif
  471. #ifdef  UART_SWAP //axel swap uart0 and uar1 2004/10/29
  472.     sft_uart_swap();
  473. #endif
  474.     write_stamp(STAMP_RESET_START);
  475. }
  476. /**************************************************************************
  477.  *  Function Name: reset_all_exit                                         *
  478.  *  Purposes:                                                             *
  479.  *   1. report fpga/sdram/rom/anchors                                     *
  480.  *   2. test sdram                                                        *
  481.  *   3. write stamp finished                                              *
  482.  *  Descriptions:                                                         *
  483.  *      reset Finished                                                    *
  484.  *  Arguments:  None                                                      *
  485.  *  Returns: None                                                         *
  486.  *  See also: None                                                        *
  487.  **************************************************************************/
  488. static void
  489. reset_all_exit()
  490. {
  491.     //
  492.     // report/testing
  493.     //
  494. #ifndef DVDRELEASE
  495. //    report_fpga_status();
  496. //    report_sdram_parameter();
  497. //    report_rom_parameter();
  498. //    report_anchors();
  499. #endif
  500. #ifdef  DRAM_TEST
  501. #include "tstsdram.c"//4-3-30 21:40
  502.     test_sdram();
  503. #endif
  504.     //
  505.     // finished
  506.     //
  507.     write_stamp(STAMP_RESET_FINISHED);
  508.     if (check_chipinfo(4)==0) return -1;
  509. }
  510. /**************************************************************************
  511.  *  Function Name: reset_all_enable_intr_only_uart                        *
  512.  *  Purposes:                                                             *
  513.  *   1. reset interrupt flags                                             *
  514.  *   2. INTERRUPT for bootstrap is initialized                            *
  515.  *   3. enable CPU-level intr_mask (IP2/IP3)                              *
  516.  *   4. enable CPU-level intr_enable                                      *
  517.  *  Descriptions:                                                         *
  518.  *      Currently only UART is enabled during bootstrap (if required).    *
  519.  *  Arguments:  None                                                      *
  520.  *  Returns: None                                                         *
  521.  *  See also: None                                                        *
  522.  **************************************************************************/
  523. static void
  524. reset_all_enable_intr_only_uart()
  525. {
  526.     //
  527.     // reset interrupt flags
  528.     regs0->intr_flag        = -1;
  529.     regs0->intr1_flag       = -1;
  530.     //
  531.     // INTERRUPT for bootstrap is initialized here.
  532.     // Currently only UART is enabled during bootstrap (if required).
  533.     //
  534.     regs0->intr_mask = 0
  535. #ifdef  SUPPORT_UART0_INTR
  536.         | INTR_UART0_INT
  537. #endif
  538. #ifdef  SUPPORT_UART1_INTR
  539.         | INTR_UART1_INT
  540. #endif
  541.         ;
  542.     regs0->intr1_mask = 0
  543.         ;
  544.     cpu_set_intr_mask((1<<2)|(1<<3));       // enable CPU-level intr_mask (IP2/IP3)
  545.     cpu_intr_enable();                      // enable CPU-level intr_enable
  546. }
  547. /**************************************************************************
  548.  *  Function Name: reset_all_enable_intr_all                              *
  549.  *  Purposes:                                                             *
  550.  *   1. reset intr_flag (bitwise-clear-upon-write-1)                      *
  551.  *   2. reset intr_mask                                                   *
  552.  *  Descriptions:                                                         *
  553.  *      enable normal interrupt processing                                *
  554.  *  Arguments:  None                                                      *
  555.  *  Returns: None                                                         *
  556.  *  See also: None                                                        *
  557.  **************************************************************************/
  558. static void
  559. reset_all_enable_intr_all(void)
  560. {
  561.     //
  562.     // reset intr_flag (bitwise-clear-upon-write-1)
  563.     regs0->intr_flag        = -1;
  564.     regs0->intr1_flag       = -1;
  565. #ifndef DVDRELEASE
  566.     regs0->sdctrl_int       = 0;
  567.     regs0->sdctrl_int_mask  = 0x80; // sdram over-range
  568. #endif
  569.     // reset intr_mask
  570.     regs0->intr_mask  = 0
  571.         | INTR_FIELD_END | INTR_FIELD_START | INTR_PIC_END
  572.         | INTR_RI_WATCHDOG
  573.         | INTR_DECERR
  574.         | INTR_TIMER0
  575.         | INTR_TIMER1
  576. #if defined(SPHE1000) && defined(SUPPORT_USB)
  577.         | INTR_USB
  578. #endif
  579. #ifdef  SUPPORT_UART0_INTR
  580.         | INTR_UART0_INT
  581. #endif
  582. #ifdef  SUPPORT_UART1_INTR
  583.         | INTR_UART1_INT
  584. #endif
  585. #ifdef SUPPORT_UART_UPGRADE
  586.         | INTR_UART1_INT // for performing flash upgrading via UART
  587. #endif
  588. #ifdef SUPPORT_UART_COMMAND //kenny support uart to communicate with external MCU
  589.         | INTR_UART1_INT // for uart command
  590. #endif
  591. #ifdef DVD_SERVO
  592.         | INTR_H_PIO_INT
  593. #endif
  594. #ifdef STB_2_0
  595.         | INTR_RISC_INT3
  596. #endif
  597. #ifdef DVD_SERVO
  598.         | INTR_SRV_INT3
  599.         | INTR_SRV_INT2
  600.         | INTR_SRV_INT1
  601.         | INTR_SRV_INT0
  602. #endif
  603.             ;
  604.   regs0->intr1_mask  = 0
  605.         | INTR1_LSWITCH_INTR_FLAG   // lswitch watchdog
  606. #ifdef DVD_SERVO
  607.         | INTR1_TIMER3B             // timer for servo use
  608. #endif
  609.         | INTR1_TIMERW              // timer of watchdog
  610. #ifndef DVDRELEASE
  611. #ifdef ENABLE_SDRAM_OV_RANGE_INTR
  612.         | INTR1_SD                  // sdram-controller out-of-range
  613. #endif
  614. #endif
  615. #ifdef SPHE8202
  616.         | INTR1_USB                 // USB
  617. #endif
  618. #if 0
  619.         // not-used
  620.         | INTR1_TIMER2A
  621.         | INTR1_TIMER2B
  622.         | INTR1_TIMER3A
  623. #endif
  624.             ;
  625. }
  626. #ifdef CS4360  //huziqin 2004-2-26
  627. #define CS4360_ADDR   0x20
  628. /*
  629. mode control 1:
  630. addr 01h
  631. AMUTE  7
  632. DIF  4-6
  633. DEM 2-3
  634. FM  0-1
  635. mode control 2:
  636. addr 0ch
  637. SZC  6-7
  638. CPEN 5
  639. PDN  4
  640. POPG 3
  641. FREEZE  2
  642. MCLKDIV  1
  643. SNGLVOL  0
  644. */
  645. /**************************************************************************
  646.  *  Function Name: config_cs4360                                          *
  647.  *  Purposes:                                                             *
  648.  *     cofig cs4360 mode                                                  *
  649.  *  Descriptions:                                                         *
  650.  *     config_cs4360                                                      *
  651.  *  Arguments:                                                            * 
  652.  *    mode control 1:                                                     * 
  653.  *    addr 01h                                                            * 
  654.  *    AMUTE  7                                                            * 
  655.  *    DIF  4-6                                                            * 
  656.  *    DEM 2-3                                                             * 
  657.  *    FM  0-1                                                             * 
  658.  *                                                                        * 
  659.  *    mode control 2:                                                     * 
  660.  *    addr 0ch                                                            * 
  661.  *    SZC  6-7                                                            * 
  662.  *    CPEN 5                                                              * 
  663.  *    PDN  4                                                              * 
  664.  *    POPG 3                                                              * 
  665.  *    FREEZE  2                                                           * 
  666.  *    MCLKDIV  1                                                          * 
  667.  *    SNGLVOL  0                                                          * 
  668.  *  Returns: None                                                         *
  669.  *  See also: None                                                        *
  670.  **************************************************************************/
  671. void config_cs4360(void)
  672. {
  673.     BYTE data;
  674.     int res;
  675.     /*mode ctrl 2*/
  676.     data = 0xa8;
  677.     res = WriteToI2c(CS4360_ADDR, 0x0c, &data, 1);
  678.     /*mode ctrl 1*/
  679.     data = 0x90;
  680.     res = WriteToI2c(CS4360_ADDR, 0x01, &data, 1);
  681.     //printf("config 4360 res == %dn ",res);
  682. }
  683. #endif //cs4360
  684. /**************************************************************************
  685.  *  Function Name: reset_tvdac                                            *
  686.  *  Purposes:                                                             *
  687.  *   1. disable video dac                                                 *
  688.  *   2. enable osd                                                        *
  689.  *   3. enable tv-encoder                                                 *
  690.  *  Descriptions:                                                         *
  691.  *      reset TV dac                                                      *
  692.  *  Arguments:  None                                                      *
  693.  *  Returns: None                                                         *
  694.  *  See also: None                                                        *
  695.  **************************************************************************/
  696. static inline void
  697. reset_tvdac(void)
  698. {
  699. #if 0
  700.     regs0->tv_mode[5] = 0x60bf;
  701.     regs0->tv_mode[5] = 0x003f;
  702.     delay_1ms(1000);
  703. #endif
  704.     //
  705.     regs0->vpp_bg_y     = 0x00;
  706.     regs0->vpp_bg_cb_cr = 0x8080;
  707.     regs0->dis_x_size = 0;
  708.     regs0->dis_y_size = 0;
  709.     // enable osd
  710.     regs0->osd_mode[0]  = 0x8000;
  711.     regs0->osd_tv_std   = 0;
  712.     // enable tv-encoder
  713.     regs0->tv_mode[0]   = 0x0400;
  714.     regs0->tv_mode[2]   = 0x0000;
  715.     regs0->tv_mode[5]   &= ~0x6080;     // enable tv-encoder
  716.     regs0->tv_mode[5]   &= ~0x003f;     // enable DAC
  717. #ifdef  SPHE8202
  718.     regs0->tv_dac[0]    = (6<<6) | (6<<3) | (0<<0);
  719.     regs0->tv_dac[1]    = (6<<6) | (6<<3) | (6<<0);
  720. #endif
  721. }
  722. /**************************************************************************
  723.  *  Function Name: reset_vpp_par                                          *
  724.  *  Purposes:                                                             *
  725.  *      change vpp_par_mode                                               *
  726.  *  Descriptions:                                                         *
  727.  *      VPP Pixel Aspect Ratio                                            *
  728.  *  Arguments:  None                                                      *
  729.  *  Returns: None                                                         *
  730.  *  See also: None                                                        *
  731.  **************************************************************************/
  732. void reset_vpp_par()
  733. {
  734.     int flag=0;
  735. #ifdef PAR_MP_FORCE_SQUARE
  736.     flag |= VPP_PAR_MP_FORCE_SQUARE;
  737. #endif
  738. #ifdef PAR_MP4_FORCE_SQUARE
  739.     flag |= VPP_PAR_MP4_FORCE_SQUARE;
  740. #endif
  741. #ifdef PAR_MP4_GUESS_43TV
  742.     flag |= VPP_PAR_MP4_GUESS_43TV;
  743. #endif
  744. #ifdef PAR_MP4_REVERSE_169TV
  745.     flag |= VPP_PAR_MP4_REVERSE_169TV;
  746. #endif
  747.     setup_vpp_par_mode(flag);
  748. }
  749. #if defined(DVB1000_NON_OS) && defined(SUPPORT_USB)
  750. void reset_usb()
  751. {
  752. UINT32 *iptr;
  753. iptr = (UINT32*)0xbc030004;
  754. *iptr = 0x1;  //??
  755. iptr = (UINT32*) 0xbc030020;
  756. *iptr = 0x1c020000;
  757. delay_1ms(1);
  758. iptr = (UINT32*)0xbc020014;
  759. *iptr = 0x27777;
  760. iptr = (UINT32*)0xbc030004;
  761. *iptr = 0x0;
  762. }
  763. #endif //#if defined(DVB1000_NON_OS) && defined(SUPPORT_USB)
  764. #ifdef  SPHE8202 //nono
  765. UINT16 gpGPIOini;
  766. #endif
  767. /**************************************************************************
  768.  *  Function Name: reset_all                                              *
  769.  *  Purposes:                                                             *
  770.  *   1. DISABLE INTR                                                      *
  771.  *   2. REGF + ROMIF setup                                                *
  772.  *   3. EMUIO/UART setup (interrupt not yet enabled)                      *
  773.  *   4. APLL setup (before GPIO for correct XCK)                          *
  774.  *   5. GPIO setup                                                        *
  775.  *   6. SDRAM size setup                                                  *
  776.  *   7. TIMER setup                                                       *
  777.  *   8. SDRAM memory mapping configuration                                *
  778.  *   9. VIDDEC                                                            *
  779.  *   10. SUP                                                              *
  780.  *   11. MULTI-TASK                                                       *
  781.  *   12. ENABLE INTR                                                      *
  782.  *   13. IOP include IR 、VFD、TV-encoder、DAC                            *
  783.  *  Descriptions:                                                         *
  784.  *      reset all, including some interface.                              *
  785.  *  Arguments:  None                                                      *
  786.  *  Returns: None                                                         *
  787.  *  See also: None                                                        *
  788.  **************************************************************************/
  789. void reset_all(void)
  790. {
  791.     #ifdef  SPHE8202            // longson 2004.02.16
  792.     regs0->sft_cfg4 = 0x6073;   // disable  SC1_OUT and TRAY_OUT
  793.     regs0->gpio_oe[0] = 0x0c;   // enable GPIO[2] and GPIO[3] output
  794.     #endif
  795.     //
  796.     // at this time only reset.c/crt0.S/lexra.S/sysmain.c are assumed to
  797.     // be in memory
  798.     //
  799.     //
  800.     // load code to sdram if required
  801.     //
  802. #ifdef SPHE1000
  803. #if defined(LOAD_OTHER) || defined(ROM_SDRAM_SHARE_BUS)
  804.     LoadModual(MODUAL_OTHER);           write_stamp(STAMP_LOAD_MODULE_OTHER);
  805. #endif
  806.     msg_init();
  807. #endif
  808.     //
  809.     // prolog
  810.     reset_all_enter();
  811.     //
  812.     // reset basic system (again)
  813.     reset_system();
  814.     write_stamp(STAMP_RESET_SYSTEM);
  815.     #ifndef START_NO_VPP_DELAY //linrc add for nintaus 2004-7-12 19:51
  816.     reset_tvdac();
  817.     #endif
  818. #ifdef POWER_ON_VIDEO_DAC_OFF
  819.     tv_dacoff( (0x01<<0)|(0x01<<1)|(0x01<<2)|(0x01<<3)|(0x01<<4)|(0x01<<5) );
  820. #endif//POWER_ON_VIDEO_DAC_OFF
  821.     //
  822.     // change system clock from 108MHz to required frequency
  823. #ifndef USE_DEFAULT_CLOCK //2004/10/21 wjzhang , sphe1000B(stb-dvd): use default clock
  824. #ifdef SPHE1000
  825.     {
  826.       UINT32 CFG_board_config = regs0->hw_cfg;
  827.       if (CFG_board_config == 9) regs0->sft_cfg2 |= (3<<14);
  828.       reset_change_sysclk();              write_stamp(STAMP_CHANGE_SYSCLK);
  829.       if (CFG_board_config == 9) regs0->sft_cfg2 &= ~(3<<14);
  830.     }
  831. #else
  832.     reset_change_sysclk();              write_stamp(STAMP_CHANGE_SYSCLK);
  833. #endif
  834. #endif
  835.     //
  836.     // load code to sdram if required
  837.     //
  838. #ifndef SPHE1000
  839. #if defined(LOAD_OTHER) || defined(ROM_SDRAM_SHARE_BUS)
  840.     LoadModual(MODUAL_OTHER);           write_stamp(STAMP_LOAD_MODULE_OTHER);
  841. #endif
  842. #endif
  843. #ifdef TCL_STANDBY
  844.     regs0->sft_cfg1 &= ~(0x1 << 3);//gpio 3 enable
  845.     regs0->gpio_master[ 3/16 ] |= 0x1 << (3%16);//gpio 3 for mips
  846.     regs0->gpio_oe[ 3/16 ] |= 0x1 << (3%16);//output
  847.     regs0->gpio_out[3/16 ] |= (0x1 << (3%16));
  848.     //delay_1ms(500);
  849.     regs0->gpio_master[ 2/16 ] |= 0x1 << (2%16);//gpio 2 for mips
  850.     regs0->gpio_oe[ 2/16 ] &= ~(0x1 << (2%16));//input
  851.     //delay_1ms(500);
  852. #endif
  853.     LoadModual(MODUAL_AP);              write_stamp(STAMP_LOAD_MODULE_AP);
  854.     LoadModual(MODUAL_FREE);            write_stamp(STAMP_LOAD_MODULE_FREE);
  855.     LoadModual(MODUAL_CDROM);           write_stamp(STAMP_LOAD_MODULE_CDROM);
  856.     //
  857.     // at this time all essential code is decompressed and loaded.
  858.     // OTHER/AP/FREE/CDROM code are loaded
  859.     //
  860.     //
  861.     // blank display
  862.     disable_video();
  863.     write_stamp(STAMP_DISABLE_VIDEO);
  864. #ifdef SUPPORT_AUDIO_RESET
  865.     GpioResetAudio();
  866. #endif
  867.     //720 generate DAC clock first, Jeff 20020712
  868. #ifndef DVD728
  869.     // setup audio clockgen (to correct format and XCK)
  870.     hwsetup_audio_clkgen_init();
  871. #endif
  872. #ifdef  SUPPORT_EPP
  873.     // reset emuio fifo
  874.     reset_io();
  875. #endif
  876. #ifdef  SPHE8202
  877. //    UART0_set_baudrate(BAUDCC(115200, 135000000));
  878. //    UART0_set_baudrate(BAUDCC(115200, 128250000));
  879. //    UART0_set_baudrate(BAUDCC(115200, 121500000));
  880. //    UART0_set_baudrate(BAUDCC(115200, 114750000));
  881. //    UART0_set_baudrate(BAUDCC(115200, 108000000));
  882. #endif
  883. #ifdef SUPPORT_UART_COMMAND //kenny support uart to communicate with external MCU
  884.     reset_uart();
  885. #endif
  886. #if defined(DVDRELEASE) && !defined(SPHE1000)
  887.     #if defined(QSI_SHOW_ERR_RATE)
  888.         UART0_set_baudrate(BAUDCC(115200, 121500000));
  889.         psprintf(linebuf,"------------Release UART------------n");         
  890.         UART0_puts(linebuf);
  891.     #elif defined(UART_WITHOUT_DEBUG_MODE)//axel 2004/10/19 for the communication with external MCU
  892.         UART0_set_baudrate(BAUDCC(9600, 121500000));
  893.         //psprintf(linebuf,"------------Release UART------------n");         
  894.         //UART0_puts(linebuf);
  895.     #else
  896.     extern void sft_hvsync();//4-4-6 0:43
  897.     //sft_hvsync(1);
  898.     sft_hvsync();       //freyman 2004-2-27 12:01
  899. #endif
  900. #endif
  901. #ifdef UART_SWAP //axel swap uart0 and uar1 2004/10/29
  902. UART1_set_baudrate(BAUDCC(115200, 121500000));                   
  903. psprintf(linebuf,"------------Release UART------------n");    
  904. UART1_puts(linebuf);                                           
  905. #endif
  906. #if 0
  907.     regs0->sft_cfg2 |= 1<<15;
  908.     UART0_set_baudrate(BAUDCC(115200, 121500000));
  909.     UART1_set_baudrate(BAUDCC(115200, 121500000));
  910.     UART0_puts("enable UART0n");
  911.     UART1_puts("enable UART1n");
  912. #endif
  913.     //
  914.     // Enable UART interrupt here (to enable emuio access)
  915.     reset_all_enable_intr_only_uart();  write_stamp(STAMP_ENABLE_INTR_0);
  916. #if defined(SPHE8202)//nono
  917.     #ifdef MP_BOARD_256_PIN_NON_SHARE
  918.     gpGPIOini = 0xff;
  919.     #else
  920.     gpGPIOini = 0;
  921.     #endif
  922. #endif//SPHE8202
  923.     //
  924.     // hardware initialization
  925. #ifdef SPHE1000
  926.     reset_gpio_1000();
  927. #else
  928.     reset_gpio();         // setup GPIO directions
  929. #endif
  930. #if 0//def SUPPORT_UART_COMMAND    //inform external MCU Power is ok and releas vfd and ir
  931.     Inform_MCUOK();
  932. #endif
  933. #ifdef SYS_TEST_REG_00
  934.     sys_test_reg_00=0x7;
  935. #endif
  936. #ifdef SUPPORT_POWER_STB //jinping for power standby 2002-7-6 17:56
  937.     POWER_STB_SET( STANDBY ); // power on;
  938. #endif
  939. #ifdef SUPPORT_AMP // for SVA DVD solution
  940.     AMP_MUTE_SET(1);  // tripth amp. high mute; mute amp.
  941.     amp_onoff_flag = 0;//default is 0. 0:amp off,out to TV; 1:amp on, out to amp
  942. #endif
  943.     //
  944.     // Load other code modules
  945.     LoadModual(MODUAL_MPEG);            write_stamp(STAMP_LOAD_MODULE_MPEG);
  946.     LoadModual(MODUAL_AP2);             write_stamp(STAMP_LOAD_MODULE_AP2);
  947.     //
  948.     // setup framebuffer/memory initial configuration
  949.     enable_portable_bonding(0);
  950.     #ifdef PORTABLE_DVD//jhuang 2003/12/3
  951.         memory_config_saved = IOP_CONFIG_PDVD;
  952.         is_iop_ready();
  953.     #endif
  954.     memory_config_saved = 0xff;
  955.     config_memory(MEMORY_DVD_NTSC);
  956.     write_stamp(STAMP_CONFIG_MEMORY);
  957.     //
  958.     // setup timer
  959.     init_timer();
  960.     //
  961.     // initialize audio/video/sup decoder
  962.     // init_audio();  //terry mark it on 2002/2/24 02:40PM ,avoid A/D to be turned on at startup
  963.     init_video_decoder();
  964.     init_sup();
  965.     pe_init();
  966.     //
  967.     // Abort previous decoding tasks
  968.     MacroAbort();
  969.     //
  970.     // Reset interrupt routines
  971.     // atapi: (not used now)
  972.     // task: task-switching
  973.     reset_atapi_intr();
  974. #ifndef DVDRELEASE
  975.     reset_task();
  976. #endif
  977.     //
  978.     // Reset watchdog
  979.     watchdog_renew(0xffff);     // n*16/90k, first time we set to maximum (about 12-second)
  980.     watchdog_onoff(1);
  981.     write_stamp(STAMP_RESET_WATCHDOG);
  982.     //
  983.     // Enable all used interrupts
  984.     reset_all_enable_intr_all();            write_stamp(STAMP_ENABLE_INTR_1);
  985.     //
  986.     // Initialize OSD (before enable TV-encoder)
  987.     reset_osd();                            write_stamp(STAMP_RESET_OSD);
  988.     //
  989.     // basic service on
  990.     // interrupt has been on
  991.     //
  992.     //
  993.     //  IOP     IOP     IOP     IOP     IOP     IOP
  994.     //
  995.     // setup iop
  996.     reset_status_puts("setup iop.n");
  997.     reset_iop();
  998.     // iop service #1
  999.     reset_status_puts("setup ir inf.n");
  1000.     reset_ir();
  1001.     // iop service #2
  1002. #if defined(SUPPORT_VFD)&&defined(SUPPORT_VFD_PANEL) //lijd 2004-12-4 11:39
  1003.     reset_status_puts("setup vfd inf.n");
  1004.     reset_vfd();
  1005. #endif
  1006. #if defined(GPIO_KEY_LIGHT)
  1007.     init_keylight_io();
  1008. #endif
  1009.     // iop service #3 (if 721/725)
  1010.     reset_status_puts("setup tv inf.n");
  1011. #ifdef DVD728
  1012.     #define NO_SYNC_ON_G
  1013.     
  1014.     #ifdef NO_SYNC_ON_G
  1015.     setup_sync_on_G(0);     // support SCART TV, no sync signal on G channel
  1016.     #endif
  1017.     setup_display(0,1);     // FIX: this is for osd/tv-encoder to keep coherent.
  1018. //    delay_1ms(200); //terry,2003/8/11 11:44AM
  1019.     /*
  1020.     #ifdef BBK_DVD//zhaoyanhua add 2003-11-24 14:23
  1021.         tv_init_output();
  1022.     #endif
  1023.     */
  1024. #else
  1025.     tv_setup();
  1026. #endif
  1027. #ifdef DIGITAL_VIDEO_OUT
  1028. #ifdef SPHE8202
  1029. #ifdef MP_BOARD_256_PIN_NON_SHARE
  1030. #ifdef CCIR656_TYPE1
  1031. regs0->sdc_data_cnt[6][0] |= (0x0e);//Disable ROM_A20(Pin225),ROM_A21(Pin226),ROM_A22(Pin227) as GPIO92,93,94
  1032. regs0->sdc_data_cnt[6][0] |= (0x1 <<4);  //CCIR656 ENABLE on Pin225~233
  1033. #elif defined(CCIR656_TYPE2) 
  1034. regs0->sft_cfg7 |= (0x1 << 4);    //rbhung Only for TEST
  1035. regs0->sft_cfg3 &= ~(0x1 << 5);   //Disable AUD4 as GPIO50 for TV_CLK ,pin 193
  1036. #endif
  1037. #endif //MP_BOARD_256_PIN_NON_SHARE
  1038. #else //8210
  1039. regs0->sft_cfg6 |= (0x1 << 14); //CCIR656 ENABLE
  1040. regs0->sft_cfg3 |= (0x7 << 9);  //CCIR SYNC FROM PIN185,186
  1041. regs0->sft_cfg2 &= ~(0xf << 5);     //UART1 SELECT
  1042. //regs0->osd_tv_out |=(0x1 << 1);   //CbCr SWAP
  1043. regs0->osd_tv_out |=(0x1 << 3); //CCIR EDGE SELECT
  1044. //regs0->sft_cfg2 |= (0x7 << 9);    //TV_LCD RGB ENABLE
  1045. //regs0->ri_misc_b0 |= (0x3<<11);   //VIDEO CLK SELECT
  1046. #endif
  1047. #endif
  1048.   // iop service #4
  1049. #ifdef  SETUP_DAC
  1050.     reset_status_puts("setup dac.n");
  1051.     dac_setup();
  1052. #endif
  1053.     // iop service #5
  1054. #if defined(PT2322)||defined(PT2320)
  1055.     reset_status_puts("setup pt2322.n");
  1056.     init_pt_audio();
  1057. #endif
  1058. #if defined(TAS3001_AMP)||defined(NO_AMP_ONLY_TUNER)     //use TI 3001  amplifier  2-8-22 12:58
  1059.     {
  1060.   //    extern int AudioIOControl(UINT16 wCode, BYTE cType, UINT16 wParam); //kenny mark it
  1061.    //    AudioIOControl(2, 15, 0);  //set 720 pcm volume 2==VOLUME,15=max volume
  1062.         regs0->gpio_sel |= GPIOSEL_10_GPIOS;   //use gpio22,23 communicate with MCU// jason 2-11-4 19:05
  1063.         regs0->gpio_out[23/16]&=(~(3<<(22%16)));
  1064.         regs0->gpio_oe[23/16] |=(3<<(22%16));
  1065.     #ifndef NO_AMP_ONLY_TUNER
  1066.        tas3001_reset();
  1067. #endif
  1068.     }
  1069. #endif
  1070. #if defined(TAS5026_AMP)     //use TI 3001  amplifier  2-8-22 12:58
  1071.     {
  1072.   //    extern int AudioIOControl(UINT16 wCode, BYTE cType, UINT16 wParam); //kenny mark it
  1073.    //    AudioIOControl(2, 15, 0);  //set 720 pcm volume 2==VOLUME,15=max volume
  1074.        tas5026_reset();
  1075.     }
  1076. #endif
  1077.     // setup dsp port
  1078.     {
  1079.         int i;
  1080.         for (i=0;i<16;i++) regs0->dsp24_port[i] = 0; //Jeff 20011029
  1081.     }
  1082. #ifdef  SETUP_UART1
  1083.     // enable UART1
  1084.     {
  1085.         UINT32 u;
  1086.         // setup baudrate
  1087.         UART1_set_baudrate(UART_BAUD_57600);
  1088.         // change pinmux
  1089.         u = regs0->sft_cfg2;
  1090.         u = (u & ~(0x0f<<5)) | (0x09<<5);
  1091.         regs0->sft_cfg2 = u;
  1092.         while (1) UART1_puts("test uart #1n");
  1093.     }
  1094. #endif
  1095. /*
  1096.     // servo testing code
  1097. #ifdef DVD_SERVO
  1098. #ifndef SOFT_ATAPI //DVD_SERVO
  1099.     ServoDecInit(); // barry add for init servo
  1100.     ResetInterfaceProc();
  1101. #endif
  1102.     regs0->emu_cfg[16] = 0x00;              // ROM-pattern disable
  1103.     regs0->rf_servo_band_en = 0x00;         //
  1104. #endif
  1105. */
  1106. #ifdef VOLUME_RECODE        //gerry add it before init audio,2004-7-6 9:36
  1107.     volume_init();
  1108. #endif//VOLUME_RECODE
  1109.     //
  1110.     // initialize audio, put it here to avoid CS4334 noise
  1111.     AUDIF_Init_Audio();//2004AUDDRV init_audio();
  1112.     //
  1113.     // ???
  1114. #ifdef CS8403_ENABLE
  1115.    #ifdef SPHE8202
  1116.    init_cs8403a__();
  1117.    #else
  1118.     regs0->gpio_master[55 / 16] |= (0x1 << (55 % 16));  //pin155, GPIO[55]
  1119.     regs0->gpio_oe[55 / 16] |= (0x1 << (55 % 16));
  1120.     regs0->gpio_out[55 / 16] |= (0x1 << (55 % 16));
  1121.     init_cs8403a__();
  1122.    #endif
  1123. #endif
  1124. #ifdef PCM1742 //Jeff 20030917
  1125.     dac_turn_on();
  1126. #endif
  1127. #ifdef CS4360 //huziqin
  1128.     //printf("config 4360n");
  1129.     config_cs4360();
  1130. #endif
  1131.     // VPP Pixel Aspect Ratio
  1132.     reset_vpp_par();
  1133.     //
  1134.     // postlog
  1135. #ifdef PMP_MCU810        ////////add to wirte IR head H/L and keycode --yangli   2004-11-11
  1136.       
  1137.        SendIRIDPowerKeyToMCU();       
  1138. #endif 
  1139. #ifdef PMP_Video_Onlycvbs    ///yangli 2004-11-29.add to pmp video out only cvbs
  1140.     tv_dacoff(TV_DAC_B|TV_DAC_C|TV_DAC_D|TV_DAC_E|TV_DAC_F);//only cvb is on
  1141.  #endif
  1142. #ifdef IC_8202E
  1143. regs0->tv_mode[4] = 0x1000;    // turn off 54Mhz upsampling
  1144. regs0->g21_reserved[4] = 0x0; // turn off 108Mhz upsampling
  1145. tv_setup_TV8202E(1); // setup TV kernel for 9992
  1146. #else
  1147. tv_setup_TV8202E(0);
  1148. #endif // IC_8202E
  1149. #ifdef SPHE1000
  1150. #ifdef HE1001_TUNER //yarco 20041202
  1151. regs0->sft_cfg3 &= 0xffcf; //disable ATAPI
  1152. regs0->sft_cfg2 = (regs0->sft_cfg2 & 0xfff1) | 0x06; //select TS interface
  1153. #endif
  1154. #endif
  1155.     reset_all_exit();
  1156.     #if defined(DVB1000_NON_OS) && defined(SUPPORT_USB)
  1157.     reset_usb();
  1158.     #endif
  1159. }
  1160. /**************************************************************************
  1161.  *  Function Name: reset_set_uart0_baudrate                               *
  1162.  *  Purposes:                                                             *
  1163.  *      reset baudrate of uart0                                           *
  1164.  *  Descriptions:                                                         *
  1165.  *      there are 9 type baudrate of uart0                                *
  1166.  *  Arguments:  None                                                      *
  1167.  *  Returns: 0                                                            *
  1168.  *  See also: None                                                        *
  1169.  **************************************************************************/
  1170. static  inline  void    reset_set_uart0_baudrate(void)
  1171. {
  1172. #if     defined(F135)
  1173.     UART0_set_baudrate(BAUDCC(115200, 135000000));
  1174. #elif   defined(F128_25)
  1175.     UART0_set_baudrate(BAUDCC(115200, 128250000));
  1176. #elif   defined(F121_5)
  1177.     UART0_set_baudrate(BAUDCC(115200, 121500000));
  1178. #elif   defined(F114_75)
  1179.     UART0_set_baudrate(BAUDCC(115200, 114750000));
  1180. #elif   defined(F108)
  1181.     UART0_set_baudrate(BAUDCC(115200, 108000000));
  1182. #elif   defined(F101_25)
  1183.     UART0_set_baudrate(BAUDCC(115200, 101250000));
  1184. #elif   defined(F94_5)
  1185.     UART0_set_baudrate(BAUDCC(115200,  94500000));
  1186. #elif   defined(F87_75)
  1187.     UART0_set_baudrate(BAUDCC(115200,  87750000));
  1188. #elif   defined(F81)
  1189.     UART0_set_baudrate(BAUDCC(115200,  81000000));
  1190. #endif
  1191. }
  1192. /**************************************************************************
  1193.  *  Function Name: reset_change_sysclk                                    *
  1194.  *  Purposes:                                                             *
  1195.  *      change system clock                                               *
  1196.  *  Descriptions:                                                         *
  1197.  *       there are 19 type of system clock                                *
  1198.  *  Arguments:  None                                                      *
  1199.  *  Returns: 0                                                            *
  1200.  *  See also: None                                                        *
  1201.  **************************************************************************/
  1202. int
  1203. reset_change_sysclk(void)
  1204. {
  1205. #if     defined(F168_75) //wrwu, 2005-01-21, for over-clock
  1206.     change_system_clock(25);
  1207. #elif     defined(F162)
  1208.     change_system_clock(24);
  1209. #elif     defined(F155_25)
  1210.     change_system_clock(23);
  1211. #elif     defined(F148_5)
  1212.     change_system_clock(22);
  1213. #elif     defined(F141_75)
  1214.     change_system_clock(21);
  1215. #elif     defined(F135)
  1216.     change_system_clock(20);
  1217. #elif   defined(F128_25)
  1218.     change_system_clock(19);
  1219. #elif   defined(F121_5)
  1220.     change_system_clock(18);
  1221. #elif   defined(F114_75)
  1222.     change_system_clock(17);
  1223. #elif   defined(F108)
  1224.     change_system_clock(16);
  1225. #elif   defined(F101_25)
  1226.     change_system_clock(15);
  1227. #elif   defined(F94_5)
  1228.     change_system_clock(14);
  1229. #elif   defined(F87_75)
  1230.     change_system_clock(13);
  1231. #elif   defined(F81)
  1232.     change_system_clock(12);
  1233. #elif   defined(F74_25)
  1234.     change_system_clock(11);
  1235. #elif   defined(F67_5)
  1236.     change_system_clock(10);
  1237. #elif   defined(F60_75)
  1238.     change_system_clock(9);
  1239. #elif   defined(F54)
  1240.     change_system_clock(8);
  1241. #elif   defined(F47_25)
  1242.     change_system_clock(7);
  1243. #elif   defined(F40_5)
  1244.     change_system_clock(6);
  1245. #elif   defined(F33_75)
  1246.     change_system_clock(5);
  1247. #elif   defined(F27)
  1248.     change_system_clock(4);
  1249. #elif   defined(F13_5)
  1250.     change_system_clock(2);
  1251. #elif   defined(F6_75)
  1252.     change_system_clock(1);
  1253. #endif
  1254.     //reset_set_uart0_baudrate();
  1255.     return 0;
  1256. }
  1257. /**************************************************************************
  1258.  *  Function Name: reset_change_sysclk_27M                                *
  1259.  *  Purposes:                                                             *
  1260.  *      change system clock to 27M                                        *
  1261.  *  Descriptions:                                                         *
  1262.  *      change system clock                                               *
  1263.  *  Arguments:  None                                                      *
  1264.  *  Returns: 0                                                            *
  1265.  *  See also: None                                                        *
  1266.  **************************************************************************/
  1267. int
  1268. reset_change_sysclk_27M(void)
  1269. {
  1270.     change_system_clock(4);    UART0_set_baudrate(BAUDCC(115200, 27000000));
  1271. //  change_system_clock(10);    UART0_set_baudrate(BAUDCC(115200, 67500000));
  1272.     return 0;
  1273. }
  1274. #ifdef  SUPPORT_USB
  1275. /**************************************************************************
  1276.  *  Function Name: set_usbpll_reg                                         *
  1277.  *  Purposes:                                                             *
  1278.  *      setup regs0->sft_cfg9                                             *
  1279.  *  Descriptions:                                                         *
  1280.  *      setup USB clock                                                     *
  1281.  *  Arguments:  None                                                      *
  1282.  *  Returns: None                                                         *
  1283.  *  See also: None                                                        *
  1284.  **************************************************************************/
  1285. static inline void set_usbpll_reg(unsigned s, unsigned ns)
  1286. {
  1287. #ifdef SPHE1000
  1288.     unsigned cfg7;
  1289.     cfg7 = regs0->sft_cfg7;
  1290.     regs0->sft_cfg7 = (cfg7 & ~0xfff) | ((ns<<6)|(s));
  1291. #else
  1292.     unsigned cfg9;
  1293.     cfg9 = regs0->sft_cfg9;
  1294.     regs0->sft_cfg9 = (cfg9 & ~0xfff) | ((ns<<6)|(s));
  1295. #endif
  1296. }
  1297. #endif
  1298. //
  1299. // SYSTEM CLOCK
  1300. //
  1301. #ifdef SPHE1000
  1302. #define LX_F256
  1303. static inline void set_lx4189_overclock()
  1304. {
  1305. // change lx4189 sysclk->270Mhz
  1306. volatile UINT32 *ptr=(volatile UINT32*)0xbc010ce0;
  1307. BYTE NR=0, NF=0;
  1308. BYTE OD=0;
  1309. #if defined(LX_F251)
  1310. NR=5; NF=93;
  1311. #elif defined(LX_F253)
  1312. NR=5; NF=94;
  1313. #elif defined(LX_F256)
  1314. NR=2; NF=38;
  1315. #elif defined(LX_F263)
  1316. NR=2; NF=39;
  1317. #elif defined(LX_F270)
  1318. NR=2; NF=40;
  1319. #elif defined(LX_F276)
  1320. NR=2; NF=41;
  1321. #elif defined(LX_F283)
  1322. NR=2; NF=42;
  1323. #elif defined(LX_F290)
  1324. NR=2; NF=43;
  1325. #elif defined(LX_F297)
  1326. NR=2; NF=44;
  1327. #elif defined(LX_F303)
  1328. NR=2; NF=45;
  1329. #elif defined(LX_F310)
  1330. NR=2; NF=46;
  1331. #else // F270
  1332. NR=2; NF=40;
  1333. #endif
  1334. regs0->pllc_cfg = (OD<<14)|((NR-2)<<9)|(NF-2);
  1335. *ptr = 1;
  1336. delay_1us(500);
  1337. }
  1338. #endif // SPHE1000
  1339. /**************************************************************************
  1340.  *  Function Name: set_syspll_reg                                         *
  1341.  *  Purposes:                                                             *
  1342.  *     setup regs0->sysclk_div_sel and regs0->sysclk_sel                  *
  1343.  *  Descriptions:                                                         *
  1344.  *      setup system clock                                                *
  1345.  *  Arguments:  None                                                      *
  1346.  *  Returns: None                                                         *
  1347.  *  See also: None                                                        *
  1348.  **************************************************************************/
  1349. static inline void set_syspll_reg(unsigned a, unsigned b)
  1350. {
  1351.     int i;
  1352. #ifdef SPHE1000
  1353.     regs0->sysclk_div_sel= 0x0404;       // slow it down
  1354.     regs0->sysclk_sel=((a)|(10<<4));
  1355.     for (i=0;i<1000 && (regs0->sysclk_sel&((1<<8)|(1<<11)|(1<<12))); i++) ;
  1356.     regs0->sysclk_div_sel= ((b)|(0<<8));
  1357.   #if 0
  1358. set_lx4189_overclock();
  1359.   #endif
  1360. #else
  1361.     regs0->sysclk_div_sel= 4;       // slow it down
  1362.     regs0->sysclk_sel=a;
  1363.     for (i=0;i<1000 && (regs0->sysclk_sel&((1<<11)|(1<<12))); i++) ;
  1364. #ifdef  CLK54_USE_USBPLL
  1365.     b |= (2<<6);        // CLK54 select USB OSCx2
  1366.     //b |= (3<<6);        // CLK54 select USB OSC
  1367. #endif
  1368.     regs0->sysclk_div_sel= b;
  1369. #endif
  1370. }
  1371. /**************************************************************************
  1372.  *  Function Name: reset_delayX                                           *
  1373.  *  Purposes: delay time                                                  *
  1374.  *  Descriptions: delay time                                              *
  1375.  *  Arguments:  None                                                      *
  1376.  *  Returns: None                                                         *
  1377.  *  See also: None                                                        *
  1378.  **************************************************************************/
  1379. static void reset_delayX(int n)
  1380. {
  1381.     while (n-->0) {
  1382.         asm volatile ("nop");
  1383.     }
  1384. }
  1385. #define     CLKUV(u,v)  (((u)<<4)|(v))
  1386. #define     CLKUV_U(uv)  ((uv)>>4)
  1387. #define     CLKUV_V(uv)  ((uv)&0x0f)
  1388. static  const   UINT8   sysclk_table[26] = //wrwu, 2005-01-21, for over-clock
  1389. {
  1390.     CLKUV(1,0),     // 00: -----
  1391.     CLKUV(1,4),     // 01: 0.25x      6.75
  1392.     CLKUV(1,3),     // 02: 0.50x     13.5
  1393.     CLKUV(9,3),     // 03: 0.75x     20.25
  1394.     CLKUV(1,2),     // 04: 1.00x     27
  1395.     CLKUV(5,2),     // 05: 1.25x     33.75
  1396.     CLKUV(9,2),     // 06: 1.50x     40.5
  1397.     CLKUV(13,2),    // 07: 1.75x     47.25
  1398.     CLKUV(1,1),     // 08: 2.00x     54
  1399.     CLKUV(3,2),     // 09: 2.25x     60.75
  1400.     CLKUV(5,1),     // 10: 2.50x     67.5
  1401.     CLKUV(7,1),     // 11: 2.75x     74.25
  1402.     CLKUV(9,1),     // 12: 3.00x     81
  1403.     CLKUV(11,1),    // 13: 3.25x     87.75
  1404.     CLKUV(13,1),    // 14: 3.50x     94.5
  1405.     CLKUV(0,1),     // 15: 3.75x    101.25
  1406.     CLKUV(1,0),     // 16: 4.00x    108         xx
  1407.     CLKUV(2,1),     // 17: 4.25x    114.75
  1408.     CLKUV(3,1),     // 18: 4.50x    121.50
  1409.     CLKUV(4,0),     // 19: 4.75x    128.25      xx
  1410.     CLKUV(5,0),     // 20: 5.00x    135
  1411.     CLKUV(6,0),     // 21: 5.25x    141.75
  1412.     CLKUV(7,0),     // 22: 5.50x    148.5
  1413.     CLKUV(8,0),     // 23: 5.75x    155.25
  1414.     CLKUV(9,0),     // 24: 6.00x    162
  1415.     CLKUV(10,0),    // 25: 6.25x    168.75
  1416. #if 0
  1417.     CLKUV(11,0),    // 26: 6.50x    175.5
  1418.     CLKUV(12,0),    // 27: 6.75x    181.25
  1419.     CLKUV(13,0),    // 28: 7.00x    189
  1420. #endif
  1421. };
  1422. static  const   UINT8   baudrate_table[26] = { //wrwu, 2005-01-21, for over-clock
  1423.     BAUDCC(115200,6750000*0),
  1424.     BAUDCC(115200,6750000*1),
  1425.     BAUDCC(115200,6750000*2),
  1426.     BAUDCC(115200,6750000*3),
  1427.     BAUDCC(115200,6750000*4),
  1428.     BAUDCC(115200,6750000*5),
  1429.     BAUDCC(115200,6750000*6),
  1430.     BAUDCC(115200,6750000*7),
  1431.     BAUDCC(115200,6750000*8),
  1432.     BAUDCC(115200,6750000*9),
  1433.     BAUDCC(115200,6750000*10),
  1434.     BAUDCC(115200,6750000*11),
  1435.     BAUDCC(115200,6750000*12),
  1436.     BAUDCC(115200,6750000*13),
  1437.     BAUDCC(115200,6750000*14),
  1438.     BAUDCC(115200,6750000*15),
  1439.     BAUDCC(115200,6750000*16),
  1440.     BAUDCC(115200,6750000*17),
  1441.     BAUDCC(115200,6750000*18),
  1442.     BAUDCC(115200,6750000*19),
  1443.     BAUDCC(115200,6750000*20),
  1444.     BAUDCC(115200,6750000*21),
  1445.     BAUDCC(115200,6750000*22),
  1446.     BAUDCC(115200,6750000*23),
  1447.     BAUDCC(115200,6750000*24),
  1448.     BAUDCC(115200,6750000*25)
  1449. };
  1450. #ifdef SHOW_SYSTEM_CLOCK//nono 4-4-6 0:29
  1451. int get_sysclk;
  1452. #endif//SHOW_SYSTEM_CLOCK
  1453. /**************************************************************************
  1454.  *  Function Name: change_system_clock                                    *
  1455.  *  Purposes:                                                             *
  1456.  *   1. disable interrupt                                                 *
  1457.  *   2. get idx                                                           *
  1458.  *   3. set syspll                                                        *
  1459.  *   4. set sdram-timing                                                  *
  1460.  *   5. restore interrupt setting                                         *
  1461.  *  Descriptions:                                                         *
  1462.  *      change system clock                                               *
  1463.  *  Arguments:  None                                                      *
  1464.  *  Returns: 0                                                            *
  1465.  *  See also: None                                                        *
  1466.  **************************************************************************/
  1467. int
  1468. change_system_clock(int uvidx)
  1469. {
  1470.     unsigned uv, u, v, IEc;
  1471. #ifdef SHOW_SYSTEM_CLOCK//nono 4-4-6 0:29
  1472.     //get get_sysclk;print on cus_menu
  1473.     get_sysclk = uvidx;
  1474. #endif//#ifdef SHOW_SYSTEM_CLOCK
  1475.     // disable interrupt
  1476.     IEc = cpu_intr_disable();
  1477.     //
  1478.     reset_delayX(100);
  1479.     // get idx
  1480.     uv = sysclk_table[uvidx];
  1481.     u = CLKUV_U(uv);
  1482.     v = CLKUV_V(uv);
  1483. #if defined(BOOT_HALF) || defined(IC_8202E)
  1484.     if (v!=0) v--;
  1485. #endif
  1486.     // set syspll
  1487.     set_syspll_reg(u,v);
  1488. #ifdef  SUPPORT_USB
  1489.     //set_usbpll_reg(0x12,0x1b);        // 96mhz/48mhz
  1490.     //set_usbpll_reg(0x1b,0x1b);          // 54mhz/27mhz
  1491.     //regs0->sft_cfg7 |= (0xf<<8);        // clk27 select clk54/2
  1492.     //regs0->sft_cfg7 |= (3<<12);       // output clk54 to pin 65
  1493. #endif
  1494.     // set sdram-timing
  1495.     if (uvidx<10)
  1496.         set_sdram_timing_low();
  1497.     else
  1498.         set_sdram_timing();
  1499.     // restore interrupt setting
  1500.     cpu_intr_config(IEc);
  1501. #if !defined(SPHE8202) && !defined(SPHE1000)
  1502.     // initialize stc-divisor
  1503.     regs0->stc_divisor    = uvidx*75-1;
  1504.     UART0_set_baudrate(baudrate_table[uvidx]);
  1505. #endif
  1506.     return 0;
  1507. }
  1508. /**************************************************************************
  1509.  *  Function Name: slowdown_test                                          *
  1510.  *  Purposes:                                                             *
  1511.  *  Descriptions:                                                         *
  1512.  *  Arguments:  None                                                      *
  1513.  *  Returns: None                                                         *
  1514.  *  See also: None                                                        *
  1515.  **************************************************************************/
  1516. #if 0
  1517. void
  1518. slowdown_test(void)
  1519. {
  1520.     reset_change_sysclk_27M();
  1521.     UART0_set_baudrate(BAUDCC(115200, 27000000));
  1522.     delay_1ms(200);
  1523.     reset_change_sysclk();
  1524.     UART0_set_baudrate(BAUDCC(115200, 121500000));
  1525. }
  1526. #endif