dummy_ap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. // Dummy AP
  2. #include <platform/boot_mode.h>
  3. #include <debug.h>
  4. #include <dev/uart.h>
  5. #include <platform/mtk_key.h>
  6. #include <target/cust_key.h>
  7. #include <platform/mt_gpio.h>
  8. // Feature on/off config
  9. //#define ENABLE_MD_RESET
  10. #define ENABLE_DUMMY_AP_FOR_MD1
  11. //#define ENABLE_DUMMY_AP_FOR_MD2
  12. #ifdef ENABLE_MD_RESET
  13. #include <platform/spm.h>
  14. #endif
  15. #define MAX_MD_NUM (2)
  16. #define MAX_IMG_NUM (8)
  17. #define PART_HEADER_MAGIC (0x58881688)
  18. #define BOOT_ARGS_ADDR (0x87F00000)
  19. #define IMG_HEADER_ADDR (0x87F00000+1024)
  20. typedef enum{
  21. DUMMY_AP_IMG = 0,
  22. MD1_IMG,
  23. MD1_RAM_DISK,
  24. MD2_IMG,
  25. MD2_RAM_DISK,
  26. MD_DSP
  27. }img_idx_t;
  28. typedef struct _map
  29. {
  30. char name[32];
  31. img_idx_t idx;
  32. }map_t;
  33. //typedef union
  34. //{
  35. // struct
  36. // {
  37. // unsigned int magic; /* partition magic */
  38. // unsigned int dsize; /* partition data size */
  39. // char name[32]; /* partition name */
  40. // unsigned int maddr; /* partition memory address */
  41. // } info;
  42. // unsigned char data[512];
  43. //} part_hdr_t;
  44. // Notice for MT6582
  45. // Update LK BOOT_ARGUMENT structure
  46. /*
  47. typedef struct {
  48. unsigned int magic_number;
  49. BOOTMODE boot_mode;
  50. unsigned int e_flag;
  51. unsigned int log_port;
  52. unsigned int log_baudrate;
  53. unsigned char log_enable;
  54. unsigned char part_num; //<<<-------
  55. unsigned char reserved[2]; //<<<-------
  56. unsigned int dram_rank_num;
  57. unsigned int dram_rank_size[4];
  58. unsigned int boot_reason;
  59. unsigned int meta_com_type;
  60. unsigned int meta_com_id;
  61. unsigned int boot_time;
  62. da_info_t da_info;
  63. SEC_LIMIT sec_limit;
  64. part_hdr_t *part_info; //<<<------
  65. } BOOT_ARGUMENT;
  66. */
  67. extern BOOT_ARGUMENT *g_boot_arg; //<<<-----
  68. //static BOOT_ARGUMENT *boot_args=BOOT_ARGS_ADDR;
  69. //static unsigned int *img_header_array = (unsigned int*)IMG_HEADER_ADDR;
  70. static unsigned int img_load_flag = 0;
  71. static part_hdr_t *img_info_start = NULL;
  72. static unsigned int img_addr_tbl[MAX_IMG_NUM];
  73. static unsigned int img_size_tbl[MAX_IMG_NUM];
  74. static map_t map_tbl[] =
  75. {
  76. {"DUMMY_AP", DUMMY_AP_IMG},
  77. {"MD_IMG", MD1_IMG},
  78. {"MD_RAM_DISK", MD1_RAM_DISK},
  79. {"MD_DSP", MD_DSP},
  80. {"MD2_IMG", MD2_IMG},
  81. {"MD2_RAM_DISK", MD2_RAM_DISK},
  82. };
  83. extern int mt_set_gpio_mode_chip(unsigned int pin, unsigned int mode);
  84. int parse_img_header(unsigned int *start_addr, unsigned int img_num) //<<<------
  85. {
  86. int i, j;
  87. int idx;
  88. if(start_addr == NULL) {
  89. printf("parse_img_header get invalid parameters!\n");
  90. return -1;
  91. }
  92. img_info_start = (part_hdr_t*)start_addr;
  93. for(i=0; i<img_num; i++) //<<<------
  94. {
  95. if(img_info_start[i].info.magic != PART_HEADER_MAGIC)
  96. continue;
  97. for(j=0; j<(sizeof(map_tbl)/sizeof(map_t)); j++)
  98. {
  99. if(strcmp(img_info_start[i].info.name, map_tbl[j].name) == 0) {
  100. idx = map_tbl[j].idx;
  101. img_addr_tbl[idx] = img_info_start[i].info.maddr;
  102. img_size_tbl[idx] = img_info_start[i].info.dsize;
  103. img_load_flag |= (1<<idx);
  104. printf("[%s] idx:%d, addr:0x%x, size:0x%x\n", map_tbl[j].name, idx, img_addr_tbl[idx], img_size_tbl[idx]);
  105. }
  106. }
  107. }
  108. return 0;
  109. }
  110. static int meta_detection(void)
  111. {
  112. int boot_mode = 0;
  113. // Put check bootmode code here
  114. if(g_boot_arg->boot_mode != NORMAL_BOOT)
  115. boot_mode = 1;
  116. printf("Meta mode: %d, boot_mode: %d-v1)\n", boot_mode, g_boot_arg->boot_mode);
  117. return boot_mode;
  118. }
  119. static void md_gpio_config(unsigned int boot_md_id)
  120. {
  121. switch(boot_md_id)
  122. {
  123. #ifdef ENABLE_DUMMY_AP_FOR_MD1
  124. case 0:
  125. //SIM1=> MD1 SIM1IF
  126. mt_set_gpio_mode(GPIO22,1);
  127. mt_set_gpio_mode(GPIO23,1);
  128. //SIM2=> MD1 SIM2IF
  129. mt_set_gpio_mode(GPIO24,1);
  130. mt_set_gpio_mode(GPIO25,1);
  131. break;
  132. #endif
  133. #ifdef ENABLE_DUMMY_AP_FOR_MD2
  134. case 1:
  135. //SIM1=> MD2 SIM1IF
  136. mt_set_gpio_mode(GPIO_SIM1_SCLK,2);
  137. mt_set_gpio_mode(GPIO_SIM1_SRST,2);
  138. mt_set_gpio_mode(GPIO_SIM1_SIO ,2);
  139. //SIM2=> MD2 SIM2IF
  140. mt_set_gpio_mode(GPIO_SIM2_SCLK,2);
  141. mt_set_gpio_mode(GPIO_SIM2_SRST,2);
  142. mt_set_gpio_mode(GPIO_SIM2_SIO ,2);
  143. break;
  144. #endif
  145. default:
  146. printf("@md_gpio_config, MD%d not enable!!!\n", boot_md_id+1);
  147. return;
  148. }
  149. }
  150. static void md_emi_remapping(unsigned int boot_md_id)
  151. {
  152. unsigned int md_img_start_addr = 0;
  153. unsigned int md_emi_remapping_addr = 0;
  154. switch(boot_md_id)
  155. {
  156. #ifdef ENABLE_DUMMY_AP_FOR_MD1
  157. case 0: // MD1
  158. md_img_start_addr = img_addr_tbl[MD1_IMG] - 0x80000000;
  159. md_emi_remapping_addr = 0x10001300; // MD1 BANK0_MAP0
  160. break;
  161. #endif
  162. #ifdef ENABLE_DUMMY_AP_FOR_MD2
  163. case 1: // MD2
  164. md_img_start_addr = img_addr_tbl[MD2_IMG] - 0x40000000;
  165. md_emi_remapping_addr = 0x10001310; // MD2 BANK0_MAP0
  166. break;
  167. #endif
  168. default:
  169. printf("@md_emi_remapping, MD%d not enable!!!\n", boot_md_id+1);
  170. return;
  171. }
  172. printf(" ---> Map 0x00000000 to %x for MD%d\n", md_img_start_addr, boot_md_id+1);
  173. // For MDx BANK0_MAP0
  174. *((volatile unsigned int*)md_emi_remapping_addr) = (((md_img_start_addr >> 24) | 1) & 0xFF) \
  175. + ((((md_img_start_addr + 0x02000000) >> 16) | 1<<8) & 0xFF00) \
  176. + ((((md_img_start_addr + 0x04000000) >> 8) | 1<<16) & 0xFF0000) \
  177. + ((((md_img_start_addr + 0x06000000) >> 0) | 1<<24) & 0xFF000000);
  178. // For MDx BANK0_MAP1
  179. *((volatile unsigned int*)(md_emi_remapping_addr + 0x4)) = ((((md_img_start_addr + 0x08000000) >> 24) | 1) & 0xFF) \
  180. + ((((md_img_start_addr + 0x0A000000) >> 16) | 1<<8) & 0xFF00) \
  181. + ((((md_img_start_addr + 0x0C000000) >> 8) | 1<<16) & 0xFF0000) \
  182. + ((((md_img_start_addr + 0x0E000000) >> 0) | 1<<24) & 0xFF000000);
  183. }
  184. static void md_power_up_mtcmos(unsigned int boot_md_id)
  185. {
  186. #if 0 // Chao ????????? Wait YP api ready
  187. volatile unsigned int loop = 10000;
  188. loop =10000;
  189. while(loop-->0);
  190. switch(boot_md_id)
  191. {
  192. case 0://MD 1
  193. #ifdef ENABLE_MD_RESET
  194. spm_mtcmos_ctrl_mdsys1(STA_POWER_ON);
  195. #endif
  196. break;
  197. case 1:// MD2
  198. break;
  199. }
  200. #endif
  201. }
  202. static void md_common_setting(int boot_md_id)
  203. {
  204. volatile unsigned int *md_wdt;
  205. unsigned int r_md_wdt = 0;
  206. switch(boot_md_id)
  207. {
  208. #ifdef ENABLE_DUMMY_AP_FOR_MD1
  209. case 0:
  210. // Put special setting here if needed
  211. //; ## Disable WDT
  212. //print "Disable MD1 WDT"
  213. md_wdt = (volatile unsigned int*)0x20050000;
  214. printf("Disable MD1 WDT\n");
  215. r_md_wdt = *md_wdt;
  216. r_md_wdt &= 0xFFFFFFFE;
  217. r_md_wdt |= 0x2200;
  218. mdelay(5);
  219. *md_wdt = r_md_wdt;
  220. //SRCLKEN_O1 = 1 for MD_VRF18. Requested by Terry.Chang.
  221. //Need to fix. Ask Terry for API. We shoudl just call SPM's API here.
  222. break;
  223. #endif
  224. #ifdef ENABLE_DUMMY_AP_FOR_MD2
  225. case 1:
  226. // Put special setting here if needed
  227. //; ## Disable WDT
  228. //print "Disable MD1 WDT"
  229. md_wdt = (volatile unsigned int*)0x30050000;
  230. printf("Disable MD2 WDT\n");
  231. r_md_wdt = *md_wdt;
  232. r_md_wdt &= 0xFFFFFFFE;
  233. r_md_wdt |= 0x2200;
  234. mdelay(5);
  235. *md_wdt = r_md_wdt;
  236. //SRCLKEN_O1 = 1 for MD_VRF18. Requested by Terry.Chang.
  237. //Need to fix. Ask Terry for API. We shoudl just call SPM's API here.
  238. *(volatile unsigned int *)(0x10006000) = 0x0B160001;
  239. *(volatile unsigned int *)(0x10006014) = (*(volatile unsigned int *)(0x10006014)) | (0x1 << 21);
  240. break;
  241. #endif
  242. default:
  243. printf("@md_common_setting, MD%d not enable!!!\n", boot_md_id+1);
  244. return;
  245. }
  246. }
  247. static void md_boot_up(unsigned int boot_md_id, unsigned int is_meta_mode)
  248. {
  249. unsigned int reg_value;
  250. switch(boot_md_id){
  251. #ifdef ENABLE_DUMMY_AP_FOR_MD1
  252. case 0:// For MD1
  253. if(is_meta_mode)
  254. {
  255. // Put META Register setting here
  256. *((volatile unsigned int*)0x20000010) |= 0x1; // Bit0, Meta mode flag, this need sync with MD init owner
  257. }
  258. // Set boot slave to let MD to run
  259. *((volatile unsigned int*)0x2019379C) = 0x3567C766; // Key Register
  260. *((volatile unsigned int*)0x20190000) = 0x0; // Vector Register
  261. *((volatile unsigned int*)0x20195488) = 0xA3B66175; // Slave En Register
  262. break;
  263. #endif
  264. #ifdef ENABLE_DUMMY_AP_FOR_MD2
  265. case 1:// For MD2
  266. printf("md_bootup: md2 set VTCXO_1 on,bit3=1\n");
  267. pmic_config_interface(0x0A02, 0x1, 0x1, 3); //bit:3: =>b1
  268. printf("md_bootup: md2 set SRCLK_EN_SEL on,bit(13,12)=(0,1)\n");
  269. pmic_config_interface(0x0A02, 0x1, 0x3, 12);//bit:13:12=>b01
  270. reg_value = *((volatile unsigned int*)0x10001F00);
  271. reg_value &= ~(0x1E000000);
  272. reg_value |= 0x12000000;
  273. *((volatile unsigned int*)0x10001F00) = reg_value;
  274. printf("md_bootup: md2 enable, set SRCLKEN infra_misc(0x1000_1F00), bit(28,27,26,25)=0x%x\n",(*((volatile unsigned int*)0x10001F00)&0x1E000000));
  275. reg_value = *((volatile unsigned int*)0x10001F08);
  276. reg_value &= ~(0x001F0078);
  277. reg_value |= 0x001B0048;
  278. *((volatile unsigned int*)0x10001F08) = reg_value;
  279. printf("md_bootup: md2 set PLL misc_config(0x1000_1F08), bit(20,19,18,17,16,6,5,4,3)=0x%x\n",(*((volatile unsigned int*)0x10001F08)&0x001F0078));
  280. mdelay(3);// sleep 3
  281. *((volatile unsigned int*)0x1000C004) = 0x00000101;
  282. printf("md_bootup: md2 set AP_PLL_CON1(0x1000C004)=0x%x\n",(*((volatile unsigned int*)0x1000C004)&0x00000101));
  283. mdelay(1);
  284. *((volatile unsigned int*)0x1000C004) = 0x00000103;
  285. printf("md_bootup: md2 set AP_PLL_CON1(0x1000C004)=0x%x\n",(*((volatile unsigned int*)0x1000C004)&0x00000103));
  286. if(is_meta_mode)
  287. {
  288. // Put META Register setting here
  289. *((volatile unsigned int*)0x30000010) |= 0x1; // Bit0, Meta mode flag, this need sync with MD init owner
  290. }
  291. // Set boot slave to let MD to run
  292. *((volatile unsigned int*)0x3019379C) = 0x3567C766; // Key Register
  293. *((volatile unsigned int*)0x30190000) = 0x0; // Vector Register
  294. *((volatile unsigned int*)0x30195488) = 0xA3B66175; // Slave En Register
  295. break;
  296. #endif
  297. default:
  298. printf("@md_boot_up, MD%d not enable!!!\n", boot_md_id+1);
  299. return;
  300. }
  301. }
  302. int md_jtag_config(int boot_md_id)
  303. {
  304. // Add Jtag setting here
  305. return 0;
  306. }
  307. int get_input(void)
  308. {
  309. return 0;
  310. }
  311. void apply_env_setting(int case_id)
  312. {
  313. printf("Apply case:%d setting for dummy AP!\n", case_id);
  314. }
  315. void md_uart_config(int md_id)
  316. {
  317. switch(md_id)
  318. {
  319. #ifdef ENABLE_DUMMY_AP_FOR_MD1
  320. case 0:
  321. // UART pin mux description
  322. // GPIOID--------M0--------M1--------M2--------M3--------M4--------M5--------M6--------M7
  323. // 8 URXD2 MD_URXD3
  324. // 65 MD_UTXD3
  325. // 67 MD_URXD3
  326. // 77 URXD1 URXD2 MD_URXD3
  327. // 78 UTXD1 UTXD2 MD_UTXD3
  328. // Switch AP UART to MD1 uart
  329. // Disable 65 and 67 for mode priority
  330. mt_set_gpio_mode(GPIO65, 0);
  331. mt_set_gpio_dir(GPIO65, GPIO_DIR_IN);
  332. mt_set_gpio_mode(GPIO67, 0);
  333. mt_set_gpio_dir(GPIO67, GPIO_DIR_IN);
  334. //RX
  335. mt_set_gpio_mode(GPIO77,5);
  336. mt_set_gpio_dir(GPIO77, GPIO_DIR_IN);
  337. mt_set_gpio_pull_enable(GPIO77, GPIO_PULL_ENABLE);
  338. mt_set_gpio_pull_select(GPIO77, GPIO_PULL_UP);
  339. //TX
  340. mt_set_gpio_mode(GPIO78,5);
  341. mt_set_gpio_dir(GPIO78, GPIO_DIR_OUT);
  342. break;
  343. #endif
  344. #ifdef ENABLE_DUMMY_AP_FOR_MD2
  345. case 1:
  346. printf("md_uart_config:%d,enable md2, disable AP & MD1 uart!\n", md_id);
  347. //disable AP uart
  348. //RX
  349. mt_set_gpio_mode(GPIO136,GPIO_MODE_GPIO);
  350. mt_set_gpio_dir(GPIO136, GPIO_DIR_IN);
  351. mt_set_gpio_pull_enable(GPIO136, GPIO_PULL_DISABLE);
  352. //TX
  353. mt_set_gpio_mode(GPIO137,GPIO_MODE_GPIO);
  354. mt_set_gpio_dir(GPIO137, GPIO_DIR_IN);
  355. mt_set_gpio_pull_enable(GPIO137, GPIO_PULL_DISABLE);
  356. //disable MD1 uart
  357. //RX
  358. mt_set_gpio_mode(GPIO144,GPIO_MODE_GPIO);
  359. mt_set_gpio_dir(GPIO144, GPIO_DIR_IN);
  360. mt_set_gpio_pull_enable(GPIO144, GPIO_PULL_DISABLE);
  361. //TX
  362. mt_set_gpio_mode(GPIO145,GPIO_MODE_GPIO);
  363. mt_set_gpio_dir(GPIO145, GPIO_DIR_IN);
  364. mt_set_gpio_pull_enable(GPIO15, GPIO_PULL_DISABLE);
  365. //enable MD2 uart
  366. //RX
  367. mt_set_gpio_mode(GPIO14,4);
  368. mt_set_gpio_dir(GPIO14, GPIO_DIR_IN);
  369. mt_set_gpio_pull_enable(GPIO14, GPIO_PULL_ENABLE);
  370. mt_set_gpio_pull_select(GPIO14, GPIO_PULL_UP);
  371. //TX
  372. mt_set_gpio_mode(GPIO15,4);
  373. mt_set_gpio_dir(GPIO15, GPIO_DIR_OUT);
  374. break;
  375. #endif
  376. default:
  377. printf("@md_uart_config, MD%d not enable!!!\n", md_id+1);
  378. return;
  379. }
  380. }
  381. static void let_md_go(int md_id)
  382. {
  383. unsigned int is_meta_mode = 0;
  384. // 1, Setup special GPIO request (RF/SIM/UART ... etc)
  385. printf("Step 1: Configure GPIO!\n");
  386. md_gpio_config(md_id);
  387. // 2, Configure EMI remapping setting
  388. printf("Step 2: Configure EMI remapping...\n");
  389. md_emi_remapping(md_id);
  390. // 3, Power up MD MTCMOS
  391. //printf("Step 3: Power up MD!\n");
  392. md_power_up_mtcmos(md_id);
  393. // 4, Configure DAP for ICE to connect to MD
  394. printf("Step 4: Configure DAP for ICE to connect to MD!\n");
  395. md_jtag_config(md_id);
  396. // 5, Check boot Mode
  397. is_meta_mode = meta_detection();
  398. printf("Step 5: Notify MD enter %s mode!\n", is_meta_mode ? "META" : "NORMAL");
  399. // 6, MD register setting
  400. printf("Step 6: MD Common setting!\n");
  401. md_common_setting(md_id);
  402. // 7, Boot up MD
  403. printf("Step 7: MD%d boot up with meta(%d)!\n", md_id+1, is_meta_mode);
  404. md_boot_up(md_id, is_meta_mode);
  405. printf("\nmd%d boot up done!\n", md_id + 1);
  406. printf("\nmd%d switch uart,then enter while(1)!\n", md_id + 1);
  407. md_uart_config(md_id);
  408. }
  409. void md_wdt_init(void);
  410. void dummy_ap_entry(void)
  411. {
  412. int md_check_tbl[] = {1<<MD1_IMG, 1<<MD2_IMG};
  413. int i=0;
  414. int get_val;
  415. volatile unsigned int count;
  416. volatile unsigned int count1;
  417. // Disable AP WDT
  418. *(volatile unsigned int *)(0x10007000) = 0x22000000;
  419. printf("Welcome to use dummy AP!\n");
  420. get_val = get_input();
  421. apply_env_setting(get_val);
  422. // 0, Parse header info
  423. printf("Parsing image info!\n");
  424. //parse_img_header(img_header_array); //<<<------
  425. parse_img_header((unsigned int*)g_boot_arg->part_info, (unsigned int)g_boot_arg->part_num);
  426. printf("Begin to configure MD run env!\n");
  427. for(i=0; i<MAX_MD_NUM; i++) {
  428. if(img_load_flag & md_check_tbl[i]) {
  429. printf("MD%d Enabled\n", i+1);
  430. let_md_go(i);
  431. }
  432. }
  433. printf("All dummy AP config done, enter while(1), ^0^!!!!!\n");
  434. while(1);
  435. md_wdt_init();
  436. #if 0
  437. count = 1;
  438. while(count--) {
  439. count1 = 0x80000000;
  440. while(count1--);
  441. }
  442. printf("Write MD WDT SWRST\n");
  443. *((volatile unsigned int *)0x2005001C) = 0x1209;
  444. count = 1;
  445. while(count--) {
  446. count1 = 0x08000000;
  447. while(count1--);
  448. }
  449. printf("Read back STA:%x!!\n", *((volatile unsigned int*)0x2005000C));
  450. #endif
  451. while(1);
  452. }
  453. // EXT functions
  454. #include <sys/types.h>
  455. #include <debug.h>
  456. #include <err.h>
  457. #include <reg.h>
  458. #include <platform/mt_typedefs.h>
  459. #include <platform/mt_reg_base.h>
  460. #include <platform/mt_irq.h>
  461. #include <sys/types.h>
  462. #define GIC_PRIVATE_SIGNALS (32)
  463. #define MT_MD_WDT1_IRQ_ID (184)
  464. #define TOPRGU_BASE (0x10007000)
  465. #define TOP_RGU_MODE_ADDR (TOPRGU_BASE+0x0)
  466. #define TOP_RGU_SW_WDT_ADDR (TOPRGU_BASE+0x14)
  467. #define TOP_RGU_COUNT_ADDR (TOPRGU_BASE+0x20)
  468. void md_wdt_irq_handler(unsigned int irq)
  469. {
  470. #ifdef ENABLE_MD_RESET
  471. if(irq==MT_MD_WDT1_IRQ_ID)
  472. {
  473. unsigned int cnt = *(volatile unsigned int *)(TOP_RGU_COUNT_ADDR);
  474. *(volatile unsigned int *)(TOP_RGU_COUNT_ADDR) = cnt+1;
  475. //disable MD1 uart
  476. //RX
  477. mt_set_gpio_mode(GPIO144,GPIO_MODE_GPIO);
  478. mt_set_gpio_dir(GPIO144, GPIO_DIR_IN);
  479. mt_set_gpio_pull_enable(GPIO144, GPIO_PULL_DISABLE);
  480. //TX
  481. mt_set_gpio_mode(GPIO145,GPIO_MODE_GPIO);
  482. mt_set_gpio_dir(GPIO145, GPIO_DIR_IN);
  483. mt_set_gpio_pull_enable(GPIO15, GPIO_PULL_DISABLE);
  484. //disable MD2 uart
  485. //RX
  486. mt_set_gpio_mode(GPIO14,GPIO_MODE_GPIO);
  487. mt_set_gpio_dir(GPIO14, GPIO_DIR_IN);
  488. mt_set_gpio_pull_enable(GPIO14, GPIO_PULL_DISABLE);
  489. //TX
  490. mt_set_gpio_mode(GPIO15,GPIO_MODE_GPIO);
  491. mt_set_gpio_dir(GPIO15, GPIO_DIR_IN);
  492. mt_set_gpio_pull_enable(GPIO15, GPIO_PULL_DISABLE);
  493. //enable AP uart
  494. //RX
  495. mt_set_gpio_mode(GPIO136,GPIO_MODE_GPIO);
  496. mt_set_gpio_dir(GPIO136, GPIO_DIR_IN);
  497. mt_set_gpio_pull_enable(GPIO136, GPIO_PULL_DISABLE);
  498. //TX
  499. mt_set_gpio_mode(GPIO137,GPIO_MODE_GPIO);
  500. mt_set_gpio_dir(GPIO137, GPIO_DIR_IN);
  501. mt_set_gpio_pull_enable(GPIO137, GPIO_PULL_DISABLE);
  502. //RX
  503. mt_set_gpio_mode(GPIO136,2);
  504. mt_set_gpio_dir(GPIO136, GPIO_DIR_IN);
  505. mt_set_gpio_pull_enable(GPIO136, GPIO_PULL_ENABLE);
  506. mt_set_gpio_pull_select(GPIO136, GPIO_PULL_UP);
  507. //TX
  508. mt_set_gpio_mode(GPIO137,2);
  509. mt_set_gpio_dir(GPIO137, GPIO_DIR_OUT);
  510. printf("MD1 power off\n");
  511. spm_mtcmos_ctrl_mdsys1(STA_POWER_DOWN);
  512. mdelay(5);
  513. let_md_go(0);
  514. }
  515. #else
  516. //printf("Get MD WDT irq, STA:%x!!\n", *((volatile unsigned int*)0x2005000C));
  517. *(volatile unsigned int *)(TOP_RGU_MODE_ADDR) = 0x22000000;
  518. *(volatile unsigned int *)(TOP_RGU_SW_WDT_ADDR) = 0x1209;
  519. while(1);
  520. #endif
  521. }
  522. void dummy_ap_irq_handler(unsigned int irq)
  523. {
  524. switch(irq){
  525. case MT_MD_WDT1_IRQ_ID:
  526. if(img_load_flag &(1<<MD1_IMG)) {
  527. md_wdt_irq_handler(MT_MD_WDT1_IRQ_ID);
  528. mt_irq_ack(MT_MD_WDT1_IRQ_ID);
  529. mt_irq_unmask(MT_MD_WDT1_IRQ_ID);
  530. }
  531. break;
  532. default:
  533. break;
  534. }
  535. }
  536. void md_wdt_init(void)
  537. {
  538. if(img_load_flag &(1<<MD1_IMG)) {
  539. mt_irq_set_sens(MT_MD_WDT1_IRQ_ID, MT65xx_EDGE_SENSITIVE);
  540. mt_irq_set_polarity(MT_MD_WDT1_IRQ_ID, MT65xx_POLARITY_LOW);
  541. mt_irq_unmask(MT_MD_WDT1_IRQ_ID);
  542. }
  543. }