dummy_ap.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. size_t r1 = 0;
  299. size_t r2 = 0;
  300. switch (md_id) {
  301. case MD_SYS1:
  302. /* step 8: trigger modem SW to run */
  303. #ifndef NO_UNGATE_MD
  304. lk_secure_ret = mt_secure_call_ret4(MTK_SIP_BL_CCCI_CONTROL_AARCH32,
  305. MD_POWER_CONFIG, MD_LK_BOOT_UP, 0, 0, &r1, &r2, 0);
  306. dprintf(CRITICAL, "lk_secure_ret=%d, HW code =0x%x, SW_version=0x%x\n",
  307. lk_secure_ret, r1, r2);
  308. #else
  309. dprintf(CRITICAL, "do not let MD1 go\n");
  310. #endif
  311. break;
  312. default:
  313. break;
  314. }
  315. }
  316. void md_wdt_irq_handler(unsigned int irq)
  317. {
  318. //spm_mtcmos_ctrl_audio(STA_POWER_DOWN);
  319. //dprintf(CRITICAL, "turn off audio.\n");
  320. #if defined(ENABLE_MD_RESET_SPM) || defined(ENABLE_MD_RESET_RGU)
  321. unsigned int reg_value = 0;
  322. unsigned int cnt = ccci_read32(TOPRGU_BASE, TOP_RGU_WDT_NONRST_REG);
  323. // update counter
  324. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_NONRST_REG, cnt + 1);
  325. // reset UART config
  326. md_uart_config(AP_ONLY, 0);
  327. dprintf(CRITICAL, "\n\n\n\nCurrent wdt cnt:%d\n", cnt + 1);
  328. if (irq == MT_MD_WDT1_IRQ_ID) {
  329. #ifdef ENABLE_MD_RESET_SPM
  330. dprintf(CRITICAL, "MD1 power off\n");
  331. spm_mtcmos_ctrl_md1(STA_POWER_DOWN);
  332. mdelay(5);
  333. config_md_boot_env(MD_SYS1, 0);
  334. #endif
  335. #ifdef ENABLE_MD_RESET_RGU
  336. dprintf(CRITICAL, "MD1 reset\n");
  337. bus_protection_en(0);
  338. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_SWSYSRST,
  339. (ccci_read32(TOPRGU_BASE, TOP_RGU_WDT_SWSYSRST) | UNLOCK_KEY) | MD1_SYS);
  340. mdelay(5);
  341. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_SWSYSRST,
  342. (ccci_read32(TOPRGU_BASE, TOP_RGU_WDT_SWSYSRST) | UNLOCK_KEY) & (~MD1_SYS));
  343. bus_protection_diable(0);
  344. #endif
  345. let_md_go(MD_SYS1);
  346. }
  347. #if 1
  348. dprintf(CRITICAL, "Config UART after MD WDT! %d\n", cnt+1);
  349. if ((img_load_flag&((1 << MD_SYS1) | (1 << MD_SYS3))) == ((1 << MD_SYS1) | (1 << MD_SYS3))) {
  350. md_uart_config(MD1_MD2, 0);
  351. } else if (img_load_flag & (1 << MD_SYS1)) {
  352. md_uart_config(MD1_ONLY, 0);
  353. } else if (img_load_flag & (1 << MD_SYS3)) {
  354. md_uart_config(MD2_ONLY, 0);
  355. }
  356. #endif
  357. #else
  358. md_uart_config(AP_ONLY, 0);
  359. dprintf(CRITICAL, "Get MD WDT irq, STA:%x!!\n", ccci_read32(MD_RGU_BASE, 0xC));
  360. #ifdef IGNORE_MD_WDT
  361. dprintf(CRITICAL, "ignore MD WDT\n");
  362. #else
  363. dprintf(CRITICAL, "whole system reboot\n");
  364. ccci_write32(TOPRGU_BASE, TOP_RGU_LATCH_CONTROL, 0x95000000);
  365. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_MODE, 0x22000004);
  366. ccci_write32(TOPRGU_BASE, TOP_RGU_WDT_SWRST, 0x1209);
  367. while (1);
  368. #endif
  369. #endif
  370. //spm_mtcmos_ctrl_audio(STA_POWER_ON);
  371. //dprintf(CRITICAL, "turn on audio.\n");
  372. }
  373. int dummy_ap_irq_helper(unsigned int irq)
  374. {
  375. switch (irq) {
  376. case MT_MD_WDT1_IRQ_ID:
  377. if (img_load_flag &(1 << MD_SYS1)) {
  378. #ifndef IGNORE_MD1_WDT
  379. md_wdt_irq_handler(MT_MD_WDT1_IRQ_ID);
  380. #else
  381. dprintf(CRITICAL, "ignore MD1 WDT\n");
  382. #endif
  383. }
  384. return 1;
  385. default:
  386. break;
  387. }
  388. return 0;
  389. }
  390. #define BRINGUP_BYPASS_BROM /* bypass brom */
  391. int bypass_md_boot_rom(void)
  392. {
  393. #ifdef BRINGUP_BYPASS_BROM
  394. // #define MDPERIMISC_BASE (0x20060000)
  395. /* Change boot slave jump address */
  396. // unlock to write boot slave jump address
  397. #if 0
  398. ccci_write32(MDPERIMISC_BASE, 0x110C, 0x5500);
  399. // write 0x0 to boot slave jump address
  400. ccci_write32(MDPERIMISC_BASE, 0x1104, 0x0);
  401. // update boot slave jump address
  402. ccci_write32(MDPERIMISC_BASE, 0x1108, 0x1);
  403. dprintf(CRITICAL, "enter bypass md brom\n");
  404. return 0;
  405. #endif
  406. #else
  407. return -1;
  408. #endif
  409. }
  410. #if 0//ndef CTP_ENV
  411. int md_brom_boot(int boot_mode)
  412. {
  413. int ret = -1;
  414. int i;
  415. config_md_boot_env(MD_SYS1, boot_mode);
  416. let_md_go(MD_SYS1);
  417. for (i = 0; i < 200; i++) {
  418. if ((ccci_read32(INFRA_SEC_BASE, MD_BROM_0) == 1) &&
  419. (ccci_read32(INFRA_SEC_BASE, MD_BROM_1) == 1) &&
  420. (ccci_read32(INFRA_SEC_BASE, MD_BROM_2) == 1) &&
  421. (ccci_read32(INFRA_SEC_BASE, MD_BROM_3) == 1)) {
  422. dprintf(CRITICAL, "BROM success!!\n");
  423. spm_mtcmos_ctrl_md1(STA_POWER_DOWN);
  424. //mdelay(5); no need
  425. ret = 0;
  426. break;
  427. }
  428. mdelay(10);
  429. }
  430. if (ret) {
  431. dprintf(CRITICAL, "BROM Failed: 0x%x, 0x%x, 0x%x, 0x%x\n",
  432. ccci_read32(INFRA_SEC_BASE, MD_BROM_0),
  433. ccci_read32(INFRA_SEC_BASE, MD_BROM_1),
  434. ccci_read32(INFRA_SEC_BASE, MD_BROM_2),
  435. ccci_read32(INFRA_SEC_BASE, MD_BROM_3));
  436. if (bypass_md_boot_rom() >= 0)
  437. let_md_go(MD_SYS1);
  438. }
  439. return ret;
  440. }
  441. #endif
  442. void dummy_ap_boot_up_md(int md_ld_flag)
  443. {
  444. int boot_mode = 0;
  445. int i = 0;
  446. int ret;
  447. img_load_flag = (unsigned int)md_ld_flag;
  448. // reinit UART, overwrite DWS setting
  449. md_uart_config(AP_ONLY, 0);
  450. // Disable AP WDT
  451. *(volatile unsigned int *)(TOPRGU_BASE) = 0x22000000;
  452. dprintf(CRITICAL, "Welcome to use dummy AP!\n");
  453. dprintf(CRITICAL, "load flag for dummy AP: %x\n", img_load_flag);
  454. #ifndef CTP_ENV
  455. if (img_load_flag == 0) {
  456. dprintf(CRITICAL, "no MD loaded for dummy AP\n");
  457. ret = get_md_err_from_lk_info(MD_SYS1);
  458. dprintf(CRITICAL, "hint for MD1 errno: %x, %s\n", ret, ld_md_errno_to_str(-ret));
  459. ret = get_md_err_from_lk_info(MD_SYS3);
  460. dprintf(CRITICAL, "hint for MD3 errno: %x, %s\n", ret, ld_md_errno_to_str(-ret));
  461. dprintf(CRITICAL, "stop.....\n");
  462. while (1);
  463. }
  464. if (img_load_flag & (1 << MD_SYS1)) {
  465. dprintf(CRITICAL, "MD1 loaded");
  466. ret = get_md_err_from_lk_info(MD_SYS1);
  467. if (ret < 0) {
  468. dprintf(CRITICAL, "MD1 load image has error, errno:%s", ld_md_errno_to_str(-ret));
  469. while (1);
  470. }
  471. }
  472. // 2, Check boot Mode
  473. // 3, MD WDT ISR init
  474. dprintf(CRITICAL, "Init MD WDT\n");
  475. md_wdt_init();
  476. #endif
  477. // 6. Switch UART
  478. dprintf(CRITICAL, "Switch UART!\n");
  479. md_uart_config(MD1_ONLY, boot_mode); // 4. Common setting for all MD
  480. dprintf(CRITICAL, "MD%d Enabled\n", i+1);
  481. md_common_setting();
  482. #if 0//ndef CTP_ENV
  483. ret = md_brom_boot(boot_mode);
  484. if ( ret == 0)
  485. #endif
  486. {
  487. config_md_boot_env(MD_SYS1, boot_mode);
  488. let_md_go(MD_SYS1);
  489. }
  490. #ifndef CTP_ENV
  491. dprintf(CRITICAL, "enter while(1), ^O^!!!!!!!!!\n");
  492. while (1);
  493. #endif
  494. }