dummy_ap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2016. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. //#define CTP_ENV
  32. #ifndef CTP_ENV
  33. /* Note: Pleae enable DUMMY_AP option at rule.mk if hope to use this function */
  34. #include <platform/boot_mode.h>
  35. #include <debug.h>
  36. #include <dev/uart.h>
  37. #include <platform/mtk_key.h>
  38. #include <target/cust_key.h>
  39. #include <platform/mt_gpio.h>
  40. #include <sys/types.h>
  41. #include <debug.h>
  42. #include <err.h>
  43. #include <reg.h>
  44. #include <string.h>
  45. #include <platform/mt_typedefs.h>
  46. #include <platform/mt_reg_base.h>
  47. #include <platform/mt_irq.h>
  48. #include <platform/mt_pmic.h>
  49. #include <platform/timer.h>
  50. #include <sys/types.h>
  51. #include <arch/ops.h>
  52. #include <platform/mt_pmic.h>
  53. #include <platform/upmu_common.h>
  54. #include <platform/upmu_hw.h>
  55. #include <platform/spm.h>
  56. #include "plat_atf_sec_call.h"
  57. #else
  58. /*CTP environment*/
  59. #include <gpio.h>
  60. #include <barriers.h>
  61. #include <sync_write.h>
  62. #include <upmu_hw.h>
  63. #include <mt_spm_reg.h>
  64. #include <mt_spm_mtcmos.h>
  65. #include <efuse.h>
  66. #define dprintf(CRITICAL, fmt, args...) dbg_print("[MD]: "fmt, ##args)
  67. static void let_md_go(int md_id);
  68. static void config_md_boot_env(int md_id, int boot_mode);
  69. #endif /*CTP_ENV*/
  70. //------- feature option part ---------------------------------------
  71. //#define DEFAULT_META
  72. #define ENABLE_MD_RESET_SPM
  73. //#define ENABLE_MD_RESET_RGU
  74. //#define IGNORE_MD_WDT
  75. //#define IGNORE_MD1_WDT
  76. //#define IGNORE_MD2_WDT
  77. //#define NO_UNGATE_MD
  78. //------- enum and macro part ---------------------------------------
  79. enum {
  80. MD_SYS1 = 0,
  81. MD_SYS2,
  82. MD_SYS3,
  83. MD_SYS4,
  84. };
  85. enum {
  86. AP_ONLY = -1,
  87. MD1_ONLY = 0,
  88. MD2_ONLY,
  89. MD1_MD2,
  90. };
  91. #define ccci_write32(b, a, v) DRV_WriteReg32((b)+(a), (v))
  92. #define ccci_read32(b, a) DRV_Reg32((b)+(a))
  93. #define ccci_write16(b, a, v) DRV_WriteReg16((b)+(a), (v))
  94. #define ccci_read16(b, a) DRV_Reg16((b)+(a))
  95. #define ccci_write8(b, a, v) DRV_WriteReg8((b)+(a), (v))
  96. #define ccci_read8(b, a) DRV_Reg8((b)+(a))
  97. struct sram_cfg {
  98. unsigned int offset;
  99. unsigned int start_bit;
  100. unsigned int end_bit;
  101. };
  102. //------- IRQ ID part ---------------------------------------
  103. #define GIC_PRIVATE_SIGNALS (32)
  104. #define MT_MD_WDT1_IRQ_ID (78+GIC_PRIVATE_SIGNALS)
  105. //------- register part ---------------------------------------
  106. #define MD1_BUS_PROTECT_SET (0x10001B84)
  107. #define MD1_BUS_PROTECT_CLR (0x10001B88)
  108. #define MD1_BUS_PROTECT_STA (0x10001B90)
  109. #define MD1_BUS_PROTECT1_SET (0x100012A0)
  110. #define MD1_BUS_PROTECT1_CLR (0x100012A4)
  111. #define MD1_BUS_PROTECT1_STA (0x10001228)
  112. #define MD1_BUS_PROTECT2_SET (0x10001BB8)
  113. #define MD1_BUS_PROTECT2_CLR (0x10001BBC)
  114. #define MD1_BUS_PROTECT2_STA (0x10001BC4)
  115. #define PROTECTION_BITMASK ((0x1 << 10)|(0x1 << 21)|(0x1 << 29)) // bit 10,21,29
  116. #define PROTECTION1_BITMASK (0x1 << 7) // bit 7
  117. #define PROTECTION2_BITMASK ((0x1 << 6)|(0x1 << 7)) // bit 6,7
  118. #define MD1_BOOT_VECTOR_EN (0x20000024)
  119. #define MD1_META_FLAG (0x20000010)
  120. #define TOPRGU_BASE (0x10007000)
  121. #define TOP_RGU_WDT_MODE (0x0)
  122. #define TOP_RGU_WDT_SWRST (0x14)
  123. #define TOP_RGU_WDT_SWSYSRST (0x18)
  124. #define TOP_RGU_WDT_NONRST_REG (0x20)
  125. #define TOP_RGU_LATCH_CONTROL (0x44)
  126. #define MD1_SYS (1 << 7)
  127. #define UNLOCK_KEY (0x88000000)
  128. #define MD_USB_INTERRUPT_MUX 0x10000280
  129. /* MD RGU PCore
  130. #define BASE_ADDR_MDRSTCTL 0x200F0000
  131. #define MD_RGU_BASE (BASE_ADDR_MDRSTCTL + 0x100)
  132. #define WDT_MD_MODE (0x0)
  133. #define WDT_MD_MODE_KEY (0x55000030)
  134. */
  135. #define PLL_TYPE (volatile kal_uint32 *)
  136. // AP view
  137. #define BASE_MADDR_APMIXEDSYS (0x1000C000)
  138. #define BASE_MADDR_MDTOP_PLLMIXED (0x20140000)
  139. #define BASE_MADDR_MDTOP_CLKSW (0x20150000)
  140. #define UINT32P (volatile unsigned int *)
  141. #define SLEEP_BASE (0x10006000)
  142. #define POWERON_CONFIG_EN (UINT32P (SLEEP_BASE+0x0))
  143. #define SPM_POWER_ON_VAL1 (UINT32P (SLEEP_BASE+0x8))
  144. #define INFRACFG_AO_BASE (0x10001000)
  145. #define INFRA_TOPAXI_PROTECTEN_1_SET (0x2A8)
  146. #define INFRA_TOPAXI_PROTECTEN_1_CLR (0x2AC)
  147. #define INFRA_MISC2 (0xF0C)
  148. #define INFRA_SEC_BASE (0x1001a000)
  149. #define MD_BROM_0 (0x824)
  150. #define MD_BROM_1 (0x828)
  151. #define MD_BROM_2 (0x82C)
  152. #define MD_BROM_3 (0x830)
  153. //------- GPIO part ---------------------------------------
  154. #define GPIO_MAGIC (0x80000000)
  155. // -- UART
  156. #define NO_NEED_UART_CONFIG
  157. #ifndef NO_NEED_UART_CONFIG
  158. #define UART1_TX_GPIO_ID (GPIO95 | GPIO_MAGIC)
  159. #define UART1_RX_GPIO_ID (GPIO94 | GPIO_MAGIC)
  160. #define UART2_TX_GPIO_ID (GPIO149 | GPIO_MAGIC)
  161. #define UART2_RX_GPIO_ID (GPIO147 | GPIO_MAGIC)
  162. #define UART3_TX_GPIO_ID (GPIO37 | GPIO_MAGIC)
  163. #define UART3_RX_GPIO_ID (GPIO36 | GPIO_MAGIC)
  164. #define UART4_TX_GPIO_ID (GPIO50 | GPIO_MAGIC)
  165. #define UART4_RX_GPIO_ID (GPIO49 | GPIO_MAGIC)
  166. #endif
  167. //------- code part ---------------------------------------
  168. static unsigned int img_load_flag = 0;
  169. #ifndef CTP_ENV
  170. extern BOOT_ARGUMENT *g_boot_arg;
  171. extern char *ld_md_errno_to_str(int errno);
  172. static int meta_detection(void)
  173. {
  174. int boot_mode;
  175. #ifdef DEFAULT_META
  176. boot_mode = 1;
  177. return boot_mode;
  178. #endif
  179. boot_mode = 0;
  180. if (g_boot_arg->boot_mode != NORMAL_BOOT)
  181. boot_mode = 1;
  182. dprintf(CRITICAL, "Meta mode: %d, boot_mode: %d\n", boot_mode, g_boot_arg->boot_mode);
  183. return boot_mode;
  184. }
  185. void md_wdt_init(void)
  186. {
  187. if (img_load_flag & (1 << MD_SYS1)) {
  188. mt_irq_set_sens(MT_MD_WDT1_IRQ_ID, MT65xx_EDGE_SENSITIVE);
  189. mt_irq_set_polarity(MT_MD_WDT1_IRQ_ID, MT65xx_POLARITY_LOW);
  190. mt_irq_unmask(MT_MD_WDT1_IRQ_ID);
  191. }
  192. }
  193. #endif //#ifndef CTP_ENV
  194. void md_uart_config(int type_id, int boot_mode)
  195. {
  196. #ifndef NO_NEED_UART_CONFIG
  197. switch (type_id) {
  198. case AP_ONLY: // for AP only
  199. dprintf(CRITICAL, "md_uart_config:%d, UART1->AP_0, UART2->N/A, UART3->MD1_0, UART4->MD1\n", type_id);
  200. // same as dws initial setting
  201. mt_set_gpio_mode(UART1_TX_GPIO_ID, GPIO_MODE_01);
  202. mt_set_gpio_mode(UART1_RX_GPIO_ID, GPIO_MODE_01);
  203. mt_set_gpio_mode(UART3_TX_GPIO_ID, GPIO_MODE_04);
  204. mt_set_gpio_mode(UART3_RX_GPIO_ID, GPIO_MODE_04);
  205. break;
  206. case MD1_ONLY: // for AP & MD1
  207. case MD2_ONLY: // for AP & C2K
  208. case MD1_MD2: // for both MD1 and C2K
  209. if (boot_mode) {
  210. dprintf(CRITICAL, "md_uart_config:%d, UART3->MD1_0, UART1->AP_0, UART2->NA/A, UART4->MD1\n", type_id);
  211. mt_set_gpio_mode(UART1_TX_GPIO_ID, GPIO_MODE_01);
  212. mt_set_gpio_mode(UART1_RX_GPIO_ID, GPIO_MODE_01);
  213. mt_set_gpio_mode(UART3_TX_GPIO_ID, GPIO_MODE_04);
  214. mt_set_gpio_mode(UART3_RX_GPIO_ID, GPIO_MODE_04);
  215. }
  216. break;
  217. default:
  218. break;
  219. }
  220. #endif
  221. }
  222. void bus_protection_en(int md_id)
  223. {
  224. if (md_id == MD_SYS1) {
  225. /* enable protection for MD1 */
  226. dprintf(CRITICAL, "enable protection for md\n");
  227. DRV_WriteReg32(MD1_BUS_PROTECT_SET, PROTECTION_BITMASK);
  228. DRV_WriteReg32(MD1_BUS_PROTECT1_SET, PROTECTION1_BITMASK);
  229. DRV_WriteReg32(MD1_BUS_PROTECT2_SET, PROTECTION2_BITMASK);
  230. /* poll protection ready */
  231. dprintf(CRITICAL, "wait protection ....\n");
  232. while ((DRV_Reg32(MD1_BUS_PROTECT_STA)&PROTECTION_BITMASK) != PROTECTION_BITMASK) {
  233. dprintf(CRITICAL, "0x%x\n", DRV_Reg32(MD1_BUS_PROTECT_STA));
  234. }
  235. dprintf(CRITICAL, "wait protection1 ....\n");
  236. while ((DRV_Reg32(MD1_BUS_PROTECT1_STA)&PROTECTION1_BITMASK) != PROTECTION1_BITMASK) {
  237. dprintf(CRITICAL, "0x%x\n", DRV_Reg32(MD1_BUS_PROTECT1_STA));
  238. }
  239. dprintf(CRITICAL, "wait protection2 ....\n");
  240. while ((DRV_Reg32(MD1_BUS_PROTECT2_STA)&PROTECTION2_BITMASK) != PROTECTION2_BITMASK) {
  241. dprintf(CRITICAL, "0x%x\n", DRV_Reg32(MD1_BUS_PROTECT2_STA));
  242. }
  243. dprintf(CRITICAL, "protection enable done\n");
  244. return;
  245. }
  246. }
  247. void bus_protection_diable(int md_id)
  248. {
  249. if (md_id == MD_SYS1) {
  250. /* enable protection for MD1 */
  251. dprintf(CRITICAL, "disable protection for md\n");
  252. DRV_WriteReg32(MD1_BUS_PROTECT_CLR, PROTECTION_BITMASK);
  253. DRV_WriteReg32(MD1_BUS_PROTECT1_CLR, PROTECTION1_BITMASK);
  254. DRV_WriteReg32(MD1_BUS_PROTECT2_CLR, PROTECTION2_BITMASK);
  255. /* poll protection ready */
  256. dprintf(CRITICAL, "wait protection disable....\n");
  257. while ((DRV_Reg32(MD1_BUS_PROTECT_STA)&PROTECTION_BITMASK) != 0x00000000) {
  258. dprintf(CRITICAL, "0x%x\n", DRV_Reg32(MD1_BUS_PROTECT_STA));
  259. }
  260. dprintf(CRITICAL, "wait protection1 disable....\n");
  261. while ((DRV_Reg32(MD1_BUS_PROTECT1_STA)&PROTECTION1_BITMASK) != 0x00000000) {
  262. dprintf(CRITICAL, "0x%x\n", DRV_Reg32(MD1_BUS_PROTECT1_STA));
  263. }
  264. dprintf(CRITICAL, "wait protection2 disable....\n");
  265. while ((DRV_Reg32(MD1_BUS_PROTECT2_STA)&PROTECTION2_BITMASK) != 0x00000000) {
  266. dprintf(CRITICAL, "0x%x\n", DRV_Reg32(MD1_BUS_PROTECT2_STA));
  267. }
  268. dprintf(CRITICAL, "protection disable done\n");
  269. return;
  270. }
  271. }
  272. int md_common_setting()
  273. {
  274. unsigned int reg_value;
  275. // MD srcclkena setting: [7:4]=4'h0110, [3:0]=4'h1101
  276. reg_value = ccci_read32(INFRACFG_AO_BASE, INFRA_MISC2);
  277. reg_value &= ~(0xFF);
  278. reg_value |= 0x21;
  279. ccci_write32(INFRACFG_AO_BASE, INFRA_MISC2, reg_value);
  280. dprintf(CRITICAL, "MD srcclkena setting:0x%x\n", ccci_read32(INFRACFG_AO_BASE, INFRA_MISC2));
  281. return 0;
  282. }
  283. static void config_md_boot_env(int md_id, int boot_mode)
  284. {
  285. unsigned int reg_value;
  286. spm_write(POWERON_CONFIG_EN, 0x0B160001);
  287. reg_value = spm_read(SPM_POWER_ON_VAL1);
  288. reg_value |= (0x1 << 21);
  289. spm_write(SPM_POWER_ON_VAL1, reg_value);
  290. dprintf(CRITICAL, "md_srclkena done!\n");
  291. spm_mtcmos_ctrl_md1(STA_POWER_ON);
  292. dprintf(CRITICAL, "MD1 MTCMOS power on done!\n");
  293. bypass_md_boot_rom();
  294. }
  295. static void let_md_go(int md_id)
  296. {
  297. int lk_secure_ret;
  298. switch (md_id) {
  299. case MD_SYS1:
  300. /* step 8: trigger modem SW to run */
  301. #ifndef NO_UNGATE_MD
  302. /* default trigger md run*/
  303. lk_secure_ret = mt_secure_call_ret4(MTK_SIP_BL_CCCI_CONTROL_AARCH32,
  304. MD_POWER_CONFIG, MD_LK_BOOT_UP_FOR_UNGATE, 1, 0, 0, 0, 0);
  305. dprintf(CRITICAL, "lk_secure_ret=%d\n", lk_secure_ret);
  306. #else
  307. dprintf(CRITICAL, "do not let MD1 go\n");
  308. #endif
  309. break;
  310. default:
  311. break;
  312. }
  313. }
  314. void md_wdt_irq_handler(unsigned int irq)
  315. {
  316. //spm_mtcmos_ctrl_audio(STA_POWER_DOWN);
  317. //dprintf(CRITICAL, "turn off audio.\n");
  318. #if defined(ENABLE_MD_RESET_SPM) || defined(ENABLE_MD_RESET_RGU)
  319. unsigned int reg_value = 0;
  320. unsigned int cnt = ccci_read32(TOPRGU_BASE, TOP_RGU_WDT_NONRST_REG);
  321. // update counter
  322. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_NONRST_REG, cnt + 1);
  323. // reset UART config
  324. md_uart_config(AP_ONLY, 0);
  325. dprintf(CRITICAL, "\n\n\n\nCurrent wdt cnt:%d\n", cnt + 1);
  326. if (irq == MT_MD_WDT1_IRQ_ID) {
  327. #ifdef ENABLE_MD_RESET_SPM
  328. dprintf(CRITICAL, "MD1 power off\n");
  329. spm_mtcmos_ctrl_md1(STA_POWER_DOWN);
  330. mdelay(5);
  331. config_md_boot_env(MD_SYS1, 0);
  332. #endif
  333. #ifdef ENABLE_MD_RESET_RGU
  334. dprintf(CRITICAL, "MD1 reset\n");
  335. bus_protection_en(0);
  336. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_SWSYSRST,
  337. (ccci_read32(TOPRGU_BASE, TOP_RGU_WDT_SWSYSRST) | UNLOCK_KEY) | MD1_SYS);
  338. mdelay(5);
  339. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_SWSYSRST,
  340. (ccci_read32(TOPRGU_BASE, TOP_RGU_WDT_SWSYSRST) | UNLOCK_KEY) & (~MD1_SYS));
  341. bus_protection_diable(0);
  342. #endif
  343. let_md_go(MD_SYS1);
  344. }
  345. #if 1
  346. dprintf(CRITICAL, "Config UART after MD WDT! %d\n", cnt+1);
  347. if ((img_load_flag&((1 << MD_SYS1) | (1 << MD_SYS3))) == ((1 << MD_SYS1) | (1 << MD_SYS3))) {
  348. md_uart_config(MD1_MD2, 0);
  349. } else if (img_load_flag & (1 << MD_SYS1)) {
  350. md_uart_config(MD1_ONLY, 0);
  351. } else if (img_load_flag & (1 << MD_SYS3)) {
  352. md_uart_config(MD2_ONLY, 0);
  353. }
  354. #endif
  355. #else
  356. md_uart_config(AP_ONLY, 0);
  357. dprintf(CRITICAL, "Get MD WDT irq, STA:%x!!\n", ccci_read32(MD_RGU_BASE, 0xC));
  358. #ifdef IGNORE_MD_WDT
  359. dprintf(CRITICAL, "ignore MD WDT\n");
  360. #else
  361. dprintf(CRITICAL, "whole system reboot\n");
  362. ccci_write32(TOPRGU_BASE, TOP_RGU_LATCH_CONTROL, 0x95000000);
  363. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_MODE, 0x22000004);
  364. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_SWRST, 0x1209);
  365. while (1);
  366. #endif
  367. #endif
  368. //spm_mtcmos_ctrl_audio(STA_POWER_ON);
  369. //dprintf(CRITICAL, "turn on audio.\n");
  370. }
  371. int dummy_ap_irq_helper(unsigned int irq)
  372. {
  373. switch (irq) {
  374. case MT_MD_WDT1_IRQ_ID:
  375. if (img_load_flag &(1 << MD_SYS1)) {
  376. #ifndef IGNORE_MD1_WDT
  377. md_wdt_irq_handler(MT_MD_WDT1_IRQ_ID);
  378. #else
  379. dprintf(CRITICAL, "ignore MD1 WDT\n");
  380. #endif
  381. }
  382. return 1;
  383. default:
  384. break;
  385. }
  386. return 0;
  387. }
  388. #define BRINGUP_BYPASS_BROM 1
  389. int bypass_md_boot_rom(void)
  390. {
  391. unsigned int res_bypass = 0;
  392. res_bypass = mt_secure_call_ret4(MTK_SIP_BL_CCCI_CONTROL_AARCH32,
  393. MD_POWER_CONFIG, MD_LK_BYPASS_BROM, BRINGUP_BYPASS_BROM, 0, 0, 0, 0);
  394. if (res_bypass)
  395. dprintf(CRITICAL, "do bypass md brom\n");
  396. else
  397. dprintf(CRITICAL, "no bypass md brom,normal flow\n");
  398. return 0;
  399. }
  400. #if 0//ndef CTP_ENV
  401. int md_brom_boot(int boot_mode)
  402. {
  403. int ret = -1;
  404. int i;
  405. config_md_boot_env(MD_SYS1, boot_mode);
  406. let_md_go(MD_SYS1);
  407. for (i = 0; i < 200; i++) {
  408. if ((ccci_read32(INFRA_SEC_BASE, MD_BROM_0) == 1) &&
  409. (ccci_read32(INFRA_SEC_BASE, MD_BROM_1) == 1) &&
  410. (ccci_read32(INFRA_SEC_BASE, MD_BROM_2) == 1) &&
  411. (ccci_read32(INFRA_SEC_BASE, MD_BROM_3) == 1)) {
  412. dprintf(CRITICAL, "BROM success!!\n");
  413. spm_mtcmos_ctrl_md1(STA_POWER_DOWN);
  414. //mdelay(5); no need
  415. ret = 0;
  416. break;
  417. }
  418. mdelay(10);
  419. }
  420. if (ret) {
  421. dprintf(CRITICAL, "BROM Failed: 0x%x, 0x%x, 0x%x, 0x%x\n",
  422. ccci_read32(INFRA_SEC_BASE, MD_BROM_0),
  423. ccci_read32(INFRA_SEC_BASE, MD_BROM_1),
  424. ccci_read32(INFRA_SEC_BASE, MD_BROM_2),
  425. ccci_read32(INFRA_SEC_BASE, MD_BROM_3));
  426. if (bypass_md_boot_rom() >= 0)
  427. let_md_go(MD_SYS1);
  428. }
  429. return ret;
  430. }
  431. #endif
  432. void dummy_ap_boot_up_md(int md_ld_flag)
  433. {
  434. int boot_mode = 0;
  435. int i = 0;
  436. int ret;
  437. img_load_flag = (unsigned int)md_ld_flag;
  438. // reinit UART, overwrite DWS setting
  439. md_uart_config(AP_ONLY, 0);
  440. // Disable AP WDT
  441. *(volatile unsigned int *)(TOPRGU_BASE) = 0x22000000;
  442. dprintf(CRITICAL, "Welcome to use dummy AP!\n");
  443. dprintf(CRITICAL, "load flag for dummy AP: %x\n", img_load_flag);
  444. #ifndef CTP_ENV
  445. if (img_load_flag == 0) {
  446. dprintf(CRITICAL, "no MD loaded for dummy AP\n");
  447. ret = get_md_err_from_lk_info(MD_SYS1);
  448. dprintf(CRITICAL, "hint for MD1 errno: %x, %s\n", ret, ld_md_errno_to_str(-ret));
  449. ret = get_md_err_from_lk_info(MD_SYS3);
  450. dprintf(CRITICAL, "hint for MD3 errno: %x, %s\n", ret, ld_md_errno_to_str(-ret));
  451. dprintf(CRITICAL, "stop.....\n");
  452. while (1);
  453. }
  454. if (img_load_flag & (1 << MD_SYS1)) {
  455. dprintf(CRITICAL, "MD1 loaded");
  456. ret = get_md_err_from_lk_info(MD_SYS1);
  457. if (ret < 0) {
  458. dprintf(CRITICAL, "MD1 load image has error, errno:%s", ld_md_errno_to_str(-ret));
  459. while (1);
  460. }
  461. }
  462. // 2, Check boot Mode
  463. // 3, MD WDT ISR init
  464. dprintf(CRITICAL, "Init MD WDT\n");
  465. md_wdt_init();
  466. #endif
  467. // 6. Switch UART
  468. dprintf(CRITICAL, "Switch UART!\n");
  469. md_uart_config(MD1_ONLY, boot_mode); // 4. Common setting for all MD
  470. dprintf(CRITICAL, "MD%d Enabled\n", i+1);
  471. md_common_setting();
  472. #if 0//ndef CTP_ENV
  473. ret = md_brom_boot(boot_mode);
  474. if ( ret == 0)
  475. #endif
  476. {
  477. config_md_boot_env(MD_SYS1, boot_mode);
  478. let_md_go(MD_SYS1);
  479. }
  480. #ifndef CTP_ENV
  481. dprintf(CRITICAL, "enter while(1), ^O^!!!!!!!!!\n");
  482. while (1);
  483. #endif
  484. }