platform.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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) 2015. 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. #include <debug.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <video.h>
  35. #include <dev/uart.h>
  36. #include <arch/arm.h>
  37. #include <arch/arm/mmu.h>
  38. #include <arch/ops.h>
  39. #include <target/board.h>
  40. #include <platform/mt_reg_base.h>
  41. #include <platform/mt_disp_drv.h>
  42. #include <platform/disp_drv.h>
  43. #include <platform/boot_mode.h>
  44. #include <platform/mt_logo.h>
  45. #include <platform/partition.h>
  46. #include <env.h>
  47. #include <platform/mt_gpio.h>
  48. #include <platform/mt_pmic.h>
  49. #include <platform/mt_pmic_dlpt.h>
  50. #include <platform/mt_pmic_wrap_init.h>
  51. #include <platform/mt_i2c.h>
  52. #include <platform/mtk_key.h>
  53. #include <platform/mtk_smi.h>
  54. #include <platform/mt_rtc.h>
  55. #include <platform/mt_leds.h>
  56. #include <platform/pmif.h>
  57. #include <platform/spmi.h>
  58. #include <platform/upmu_common.h>
  59. #ifdef CFG_MTK_WDT_COMMON
  60. #include <mtk_wdt.h>
  61. #else
  62. #include <platform/mtk_wdt.h>
  63. #endif
  64. #include <platform/disp_drv_platform.h>
  65. #include <platform/verified_boot.h>
  66. #include <platform/sec_devinfo.h>
  67. #include <platform/mtk_pcie.h>
  68. #include <plinfo.h> // for plinfo_get_brom_header_block_size()
  69. #include <libfdt.h>
  70. #include <mt_gic.h> // for platform_init_interrupts()
  71. #include <mt_boot.h> // for bldr_load_dtb()
  72. #include <mtk_dcm.h> // for mt_dcm_init()
  73. #include <fpga_boot_argument.h>
  74. #include <profiling.h>
  75. #include <assert.h>
  76. #include <platform/mt_gpt.h> // for get_timer()
  77. #include <sec_export.h>
  78. #include "memory_layout.h"
  79. #include "load_vfy_boot.h"
  80. #include <fdt_op.h>
  81. #include <verified_boot_common.h>
  82. #include <platform/mtk_charger_intf.h>
  83. #include <rsc.h>
  84. #include <blockheader.h>
  85. #ifdef MTK_SMC_ID_MGMT
  86. #include "mtk_secure_api.h"
  87. #endif
  88. #include "mtk_dcm.h" //for mt_dcm_init()
  89. #ifdef MTK_EMMC_SUPPORT
  90. #include "mmc_rpmb.h"
  91. #endif
  92. #define DEVAPC_TURN_ON 1
  93. #define APUSYS_APC_TURN_ON 1
  94. #if defined(MTK_VPU_SUPPORT)
  95. #include <platform/mt_vpu.h>
  96. #endif
  97. #ifdef MTK_AB_OTA_UPDATER
  98. #include "bootctrl.h"
  99. #endif
  100. #if defined(MTK_SECURITY_SW_SUPPORT)
  101. #include "oemkey.h"
  102. #endif
  103. #if (defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT))
  104. #include "ufs_aio_interface.h"
  105. #include "ufs_aio_rpmb.h"
  106. #endif
  107. #ifdef MTK_CHARGER_NEW_ARCH
  108. #include <mtk_charger.h>
  109. #include <mtk_battery.h>
  110. #endif
  111. #include "show_animation_common.h"
  112. #ifdef MTK_MT6360_PMIC_SUPPORT
  113. #include <platform/mt6360_pmic.h>
  114. #endif /* MTK_MT6360_PMIC_SUPPORT */
  115. #ifdef MTK_MT6360_LDO_SUPPORT
  116. #include <platform/mt6360_ldo.h>
  117. #endif /* MTK_MT6360_LDO_SUPPORT */
  118. #ifdef MTK_SECURITY_SW_SUPPORT
  119. extern u8 g_oemkey[OEM_PUBK_SZ];
  120. #endif
  121. #ifdef LK_DL_CHECK
  122. /*block if check dl fail*/
  123. #undef LK_DL_CHECK_BLOCK_LEVEL
  124. #endif
  125. extern void platform_early_init_timer();
  126. extern void jump_da(u32 addr, u32 arg1, u32 arg2);
  127. extern int i2c_hw_init(void);
  128. extern int mboot_common_load_logo(unsigned long logo_addr, char* filename);
  129. extern int sec_func_init(u64 pl_start_addr);
  130. extern int sec_usbdl_enabled (void);
  131. extern unsigned int crypto_hw_engine_disable(void);
  132. extern void mtk_wdt_disable(void);
  133. extern void platform_deinit_interrupts(void);
  134. extern int mmc_get_dl_info(void);
  135. extern int mmc_legacy_init(int);
  136. extern void platform_clear_all_on_mux(void);
  137. extern unsigned int crypto_hw_engine_disable(void);
  138. #ifdef MTK_AEE_PLATFORM_DEBUG_SUPPORT
  139. extern void latch_lastbus_init(void);
  140. #endif
  141. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  142. extern kal_bool is_low_battery(kal_int32 val);
  143. extern int hw_charging_get_charger_type(void);
  144. #endif
  145. #ifdef MTK_LK_REGISTER_WDT
  146. extern void lk_register_wdt_callback(void);
  147. #endif
  148. void platform_uninit(void);
  149. void config_shared_SRAM_size(void);
  150. extern int dev_info_nr_cpu(void);
  151. extern void mt_pll_turn_off(void);
  152. extern void mt_clk_post_init(void);
  153. struct mmu_initial_mapping mmu_initial_mappings[] = {
  154. {
  155. .phys = (uint64_t)0,
  156. .virt = (uint32_t)0,
  157. .size = 0x40000000,
  158. .flags = MMU_MEMORY_TYPE_STRONGLY_ORDERED | MMU_MEMORY_AP_P_RW_U_NA,
  159. .name = "mcusys"
  160. },
  161. {
  162. .phys = (uint64_t)MEMBASE,
  163. .virt = (uint32_t)MEMBASE,
  164. .size = ROUNDUP(MEMSIZE, SECTION_SIZE),
  165. .flags = MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  166. .name = "ram"
  167. },
  168. {
  169. .phys = (uint64_t)SCRATCH_ADDR,
  170. .virt = (uint32_t)SCRATCH_ADDR,
  171. .size = SCRATCH_SIZE,
  172. .flags = MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  173. .name = "download"
  174. },
  175. /* null entry to terminate the list */
  176. { 0 }
  177. };
  178. BOOT_ARGUMENT *g_boot_arg;
  179. BOOT_ARGUMENT boot_addr;
  180. int g_nr_bank;
  181. BI_DRAM bi_dram[MAX_NR_BANK];
  182. unsigned int g_fb_base;
  183. unsigned int g_fb_size;
  184. static int g_dram_init_ret;
  185. static unsigned int bootarg_addr;
  186. static unsigned int bootarg_size;
  187. extern unsigned int logo_lk_t;
  188. extern unsigned int boot_time;
  189. int dram_init(void)
  190. {
  191. unsigned int i;
  192. struct boot_tag *tags;
  193. /* Get parameters from pre-loader. Get as early as possible
  194. * The address of BOOT_ARGUMENT_LOCATION will be used by Linux later
  195. * So copy the parameters from BOOT_ARGUMENT_LOCATION to LK's memory region
  196. */
  197. g_boot_arg = &boot_addr;
  198. bootarg_addr = (unsigned int)((unsigned int *)BOOT_ARGUMENT_LOCATION);
  199. bootarg_size = 0;
  200. fpga_set_boot_argument((BOOT_ARGUMENT*)bootarg_addr);
  201. if (*(unsigned int *)BOOT_ARGUMENT_LOCATION == BOOT_ARGUMENT_MAGIC) {
  202. memcpy(g_boot_arg, (void*)BOOT_ARGUMENT_LOCATION, sizeof(BOOT_ARGUMENT));
  203. bootarg_size = sizeof(BOOT_ARGUMENT);
  204. } else {
  205. g_boot_arg->maggic_number = BOOT_ARGUMENT_MAGIC;
  206. for (tags = (void *)BOOT_ARGUMENT_LOCATION; tags->hdr.size; tags = boot_tag_next(tags)) {
  207. switch (tags->hdr.tag) {
  208. case BOOT_TAG_BOOT_REASON:
  209. g_boot_arg->boot_reason = tags->u.boot_reason.boot_reason;
  210. break;
  211. case BOOT_TAG_BOOT_MODE:
  212. g_boot_arg->boot_mode = tags->u.boot_mode.boot_mode;
  213. break;
  214. case BOOT_TAG_META_COM:
  215. g_boot_arg->meta_com_type = tags->u.meta_com.meta_com_type;
  216. g_boot_arg->meta_com_id = tags->u.meta_com.meta_com_id;
  217. g_boot_arg->meta_uart_port = tags->u.meta_com.meta_uart_port;
  218. g_boot_arg->meta_log_disable = tags->u.meta_com.meta_log_disable;
  219. g_boot_arg->fast_meta_gpio = tags->u.meta_com.fast_meta_gpio;
  220. break;
  221. case BOOT_TAG_LOG_COM:
  222. g_boot_arg->log_port = tags->u.log_com.log_port;
  223. g_boot_arg->log_baudrate = tags->u.log_com.log_baudrate;
  224. g_boot_arg->log_enable = tags->u.log_com.log_enable;
  225. g_boot_arg->log_dynamic_switch = tags->u.log_com.log_dynamic_switch;
  226. break;
  227. case BOOT_TAG_MEM:
  228. g_boot_arg->dram_rank_num = tags->u.mem.dram_rank_num;
  229. for (i = 0; i < tags->u.mem.dram_rank_num; i++) {
  230. g_boot_arg->dram_rank_size[i] = tags->u.mem.dram_rank_size[i];
  231. }
  232. g_boot_arg->mblock_info = tags->u.mem.mblock_info;
  233. g_boot_arg->orig_dram_info = tags->u.mem.orig_dram_info;
  234. g_boot_arg->lca_reserved_mem = tags->u.mem.lca_reserved_mem;
  235. g_boot_arg->tee_reserved_mem = tags->u.mem.tee_reserved_mem;
  236. break;
  237. case BOOT_TAG_MD_INFO:
  238. for (i = 0; i < 4; i++) {
  239. g_boot_arg->md_type[i] = tags->u.md_info.md_type[i];
  240. }
  241. break;
  242. case BOOT_TAG_BOOT_TIME:
  243. g_boot_arg->boot_time = tags->u.boot_time.boot_time;
  244. break;
  245. case BOOT_TAG_DA_INFO:
  246. memcpy(&g_boot_arg->da_info, &tags->u.da_info.da_info, sizeof(da_info_t));
  247. break;
  248. case BOOT_TAG_SEC_INFO:
  249. memcpy(&g_boot_arg->sec_limit, &tags->u.sec_info.sec_limit, sizeof(SEC_LIMIT));
  250. break;
  251. case BOOT_TAG_PART_NUM:
  252. g_boot_arg->part_num = tags->u.part_num.part_num;
  253. break;
  254. case BOOT_TAG_PART_INFO:
  255. g_boot_arg->part_info = tags->u.part_info.part_info; /* only copy the pointer but the contains*/
  256. break;
  257. case BOOT_TAG_EFLAG:
  258. g_boot_arg->e_flag = tags->u.eflag.e_flag;
  259. break;
  260. case BOOT_TAG_DDR_RESERVE:
  261. g_boot_arg->ddr_reserve_enable = tags->u.ddr_reserve.ddr_reserve_enable;
  262. g_boot_arg->ddr_reserve_success = tags->u.ddr_reserve.ddr_reserve_success;
  263. g_boot_arg->ddr_reserve_ready = tags->u.ddr_reserve.ddr_reserve_ready;
  264. break;
  265. case BOOT_TAG_DRAM_BUF:
  266. g_boot_arg->dram_buf_size = tags->u.dram_buf.dram_buf_size;
  267. break;
  268. case BOOT_TAG_SRAM_INFO:
  269. g_boot_arg->non_secure_sram_addr = tags->u.sram_info.non_secure_sram_addr;
  270. g_boot_arg->non_secure_sram_size = tags->u.sram_info.non_secure_sram_size;
  271. break;
  272. case BOOT_TAG_PLAT_DBG_INFO:
  273. g_boot_arg->plat_dbg_info_max = tags->u.plat_dbg_info.info_max;
  274. if (g_boot_arg->plat_dbg_info_max > INFO_TYPE_MAX)
  275. g_boot_arg->plat_dbg_info_max = INFO_TYPE_MAX;
  276. for (i = 0; i < g_boot_arg->plat_dbg_info_max; i++) {
  277. g_boot_arg->plat_dbg_info[i].key = tags->u.plat_dbg_info.info[i].key;
  278. g_boot_arg->plat_dbg_info[i].base = tags->u.plat_dbg_info.info[i].base;
  279. g_boot_arg->plat_dbg_info[i].size = tags->u.plat_dbg_info.info[i].size;
  280. }
  281. break;
  282. case BOOT_TAG_PTP:
  283. memcpy(&g_boot_arg->ptp_volt_info, &tags->u.ptp_volt.ptp_volt_info, sizeof(ptp_info_t));
  284. break;
  285. case BOOT_TAG_EMI_INFO:
  286. memcpy(&(g_boot_arg->emi_info), &(tags->u.emi_info), sizeof(emi_info_t));
  287. break;
  288. case BOOT_TAG_IMGVER_INFO:
  289. g_boot_arg->pl_imgver_status = tags->u.imgver_info.pl_imgver_status;
  290. break;
  291. case BOOT_TAG_MAX_CPUS:
  292. g_boot_arg->max_cpus = tags->u.max_cpus.max_cpus;
  293. break;
  294. case BOOT_TAG_BAT_INFO:
  295. g_boot_arg->boot_voltage = tags->u.bat_info.boot_voltage;
  296. g_boot_arg->shutdown_time= tags->u.bat_info.shutdown_time;
  297. break;
  298. case BOOT_TAG_RAM_CONSOLE_INFO:
  299. g_boot_arg->ram_console_sram_addr = tags->u.ram_console_info.sram_addr;
  300. g_boot_arg->ram_console_sram_size = tags->u.ram_console_info.sram_size;
  301. g_boot_arg->ram_console_def_type = tags->u.ram_console_info.def_type;
  302. g_boot_arg->ram_console_memory_info_offset = tags->u.ram_console_info.memory_info_offset;
  303. break;
  304. case BOOT_TAG_CHR_INFO:
  305. g_boot_arg->charger_type = tags->u.chr_info.charger_type;
  306. break;
  307. #if WITH_GZ_MD_SHAREMEM
  308. case BOOT_TAG_GZ_PARAM:
  309. g_boot_arg->gz_md_shm_pa = tags->u.gz_param.modemMteeShareMemPA;
  310. g_boot_arg->gz_md_shm_sz = tags->u.gz_param.modemMteeShareMemSize;
  311. break;
  312. #endif
  313. case BOOT_TAG_SOC_ID:
  314. memcpy(g_boot_arg->socid, tags->u.socid.id, SOC_ID_LEN);
  315. break;
  316. default:
  317. break;
  318. }
  319. bootarg_size += tags->hdr.size;
  320. }
  321. }
  322. fpga_copy_boot_argument(g_boot_arg);
  323. g_nr_bank = g_boot_arg->dram_rank_num;
  324. if (g_nr_bank == 0 || g_nr_bank > MAX_NR_BANK) {
  325. g_dram_init_ret = -1;
  326. //dprintf(CRITICAL, "[LK ERROR] DRAM bank number is not correct!!!");
  327. //while (1) ;
  328. return -1;
  329. }
  330. return 0;
  331. }
  332. unsigned int platform_get_bootarg_addr(void)
  333. {
  334. return bootarg_addr;
  335. }
  336. unsigned int platform_get_bootarg_size(void)
  337. {
  338. return bootarg_size;
  339. }
  340. /*******************************************************
  341. * Routine: memory_size
  342. * Description: return DRAM size to LCM driver
  343. ******************************************************/
  344. u32 ddr_enable_4gb(void)
  345. {
  346. u32 status;
  347. #define INFRA_MISC (INFRACFG_AO_BASE + 0x0F00)
  348. #define INFRA_4GB_EN (1 << 13)
  349. #define PERI_MISC (PERICFG_BASE + 0x0208)
  350. #define PERI_4GB_EN (1 << 15)
  351. status = ((DRV_Reg32(INFRA_MISC) & INFRA_4GB_EN) && (DRV_Reg32(PERI_MISC) & PERI_4GB_EN)) ? 1 : 0;
  352. dprintf(CRITICAL, "%s() status=%u\n", __func__, status);
  353. return status;
  354. }
  355. u64 physical_memory_size(void)
  356. {
  357. int i;
  358. unsigned long long size = 0;
  359. for (i = 0; i < (int)(g_boot_arg->orig_dram_info.rank_num); i++) {
  360. size += g_boot_arg->orig_dram_info.rank_info[i].size;
  361. }
  362. return size;
  363. }
  364. u32 memory_size(void)
  365. {
  366. unsigned long long size = physical_memory_size();
  367. while (((unsigned long long)DRAM_PHY_ADDR + size) > 0x100000000ULL) {
  368. size -= (unsigned long long)(1024*1024*1024);
  369. }
  370. return (unsigned int)size;
  371. }
  372. void sw_env()
  373. {
  374. #ifdef LK_DL_CHECK
  375. #if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  376. int dl_status = 0;
  377. dl_status = mmc_get_dl_info();
  378. dprintf(INFO, "mt65xx_sw_env--dl_status: %d\n", dl_status);
  379. if (dl_status != 0) {
  380. video_printf("=> TOOL DL image Fail!\n");
  381. dprintf(CRITICAL, "TOOL DL image Fail\n");
  382. #ifdef LK_DL_CHECK_BLOCK_LEVEL
  383. dprintf(CRITICAL, "uboot is blocking by dl info\n");
  384. while (1) ;
  385. #endif
  386. }
  387. #endif
  388. #endif
  389. #ifndef MACH_FPGA_NO_DISPLAY
  390. #ifndef USER_BUILD
  391. switch (g_boot_mode) {
  392. case META_BOOT:
  393. video_printf(" => META MODE\n");
  394. break;
  395. case FACTORY_BOOT:
  396. video_printf(" => FACTORY MODE\n");
  397. break;
  398. case RECOVERY_BOOT:
  399. video_printf(" => RECOVERY MODE\n");
  400. break;
  401. case SW_REBOOT:
  402. //video_printf(" => SW RESET\n");
  403. break;
  404. case NORMAL_BOOT:
  405. //if(g_boot_arg->boot_reason != BR_RTC && get_env("hibboot") != NULL && atoi(get_env("hibboot")) == 1)
  406. if (get_env("hibboot") != NULL && atoi(get_env("hibboot")) == 1)
  407. video_printf(" => HIBERNATION BOOT\n");
  408. else
  409. video_printf(" => NORMAL BOOT\n");
  410. break;
  411. case ADVMETA_BOOT:
  412. video_printf(" => ADVANCED META MODE\n");
  413. break;
  414. case ATE_FACTORY_BOOT:
  415. video_printf(" => ATE FACTORY MODE\n");
  416. break;
  417. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  418. case KERNEL_POWER_OFF_CHARGING_BOOT:
  419. video_printf(" => POWER OFF CHARGING MODE\n");
  420. break;
  421. case LOW_POWER_OFF_CHARGING_BOOT:
  422. video_printf(" => LOW POWER OFF CHARGING MODE\n");
  423. break;
  424. #endif
  425. case ALARM_BOOT:
  426. video_printf(" => ALARM BOOT\n");
  427. break;
  428. case FASTBOOT:
  429. video_printf(" => FASTBOOT mode...\n");
  430. break;
  431. default:
  432. video_printf(" => UNKNOWN BOOT\n");
  433. }
  434. return;
  435. #endif
  436. #ifdef USER_BUILD
  437. /* it's ok to display META MODE since it already verfied by preloader */
  438. if (g_boot_mode == META_BOOT)
  439. video_printf(" => META MODE\n");
  440. if (g_boot_mode == FASTBOOT)
  441. video_printf(" => FASTBOOT mode...\n");
  442. return;
  443. #endif
  444. #endif /* MACH_FPGA_NO_DISPLAY */
  445. }
  446. extern uint64_t ld_tt_l1[4];
  447. void platform_init_mmu(void)
  448. {
  449. /* configure available RAM banks */
  450. dram_init();
  451. /* Long-descriptor translation with lpae enable */
  452. arm_mmu_lpae_init();
  453. struct mmu_initial_mapping *m = mmu_initial_mappings;
  454. for (uint i = 0; i < countof(mmu_initial_mappings); i++, m++) {
  455. arch_mmu_map(m->phys, m->virt, m->flags, m->size);
  456. }
  457. arch_enable_mmu(); //enable mmu after setup page table to avoid cpu prefetch which may bring on emi violation
  458. }
  459. /******************************************************************************
  460. ******************************************************************************/
  461. #define GPIO_BANK (GPIO_BASE + 0x6F0)
  462. #define TRAP_UFS_FIRST (0x3U << 17) /* [18:17] 0: UFS, 1: eMMC, 2: SF */
  463. void init_storage(void)
  464. {
  465. PROFILING_START("NAND/EMMC/UFS init");
  466. #if (defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT))
  467. #ifdef MACH_FPGA
  468. #if defined(MTK_UFS_SUPPORT)
  469. if (ufs_lk_init())
  470. #endif
  471. #if defined(MTK_EMMC_SUPPORT)
  472. mmc_legacy_init(1);
  473. #else
  474. dprintf(CRITICAL, "[LK ERROR] eMMC not support!!!\n");
  475. #endif
  476. #else
  477. if ((DRV_Reg32(GPIO_BANK) & TRAP_UFS_FIRST) == 0)
  478. ufs_lk_init();
  479. else {
  480. mmc_legacy_init(1);
  481. cmdline_append("androidboot.fstab_suffix=emmc");
  482. }
  483. #endif
  484. #else
  485. #ifndef MACH_FPGA
  486. nand_init();
  487. nand_driver_test();
  488. #endif // MACH_FPGA
  489. #endif // MTK_EMMC_SUPPORT || MTK_UFS_SUPPORT
  490. #if (defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT))
  491. init_rpmb_sharemem();
  492. #endif
  493. #if defined(MTK_UFS_SUPPORT)
  494. if ((DRV_Reg32(GPIO_BANK) & TRAP_UFS_FIRST) == 0) {
  495. if (ufs_clr_write_protect())
  496. dprintf(CRITICAL, "[LK ERROR] UFS clear write protect fail!!!\n");
  497. }
  498. #endif
  499. PROFILING_END(); /* NAND/EMMC/UFS init */
  500. }
  501. /******************************************************************************
  502. ******************************************************************************/
  503. void platform_early_init(void)
  504. {
  505. PROFILING_START("platform_early_init");
  506. #ifdef MTK_LK_REGISTER_WDT
  507. lk_register_wdt_callback();
  508. #endif
  509. /* initialize the uart */
  510. uart_init_early();
  511. PROFILING_START("Devinfo Init");
  512. #ifdef MTK_MT22_MODE
  513. devinfo_init_mode(MTK_MT22_MODE);
  514. #endif
  515. init_devinfo_data();
  516. dprintf(CRITICAL, "[LK] segment = 0x%x\n", (get_devinfo_with_index(30) & 0xFF));
  517. dprintf(CRITICAL, "[LK] spare4 = 0x%x\n", get_devinfo_with_index(7));
  518. PROFILING_END();
  519. platform_init_interrupts();
  520. platform_early_init_timer();
  521. #if !defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  522. mt_gpio_set_default();
  523. #endif // !defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  524. dprintf(SPEW, "bootarg_addr: 0x%x, bootarg_size: 0x%x\n", platform_get_bootarg_addr(), platform_get_bootarg_size());
  525. if (g_dram_init_ret < 0) {
  526. dprintf(CRITICAL, "[LK ERROR] DRAM bank number is not correct!!!\n");
  527. while (1) ;
  528. }
  529. //i2c_v1_init();
  530. PROFILING_START("WDT Init");
  531. mtk_wdt_init();
  532. PROFILING_END();
  533. //i2c init
  534. i2c_hw_init();
  535. #ifdef MACH_FPGA
  536. mtk_timer_init(); // GPT4 will be initialized at PL after
  537. mtk_wdt_disable(); // WDT will be triggered when uncompressing linux image on FPGA
  538. #endif
  539. PROFILING_START("pmif spmi init");
  540. pmif_spmi_init(SPMI_MASTER_0);
  541. PROFILING_END();
  542. pwrap_init_lk();
  543. #if !defined(MACH_FPGA) && !defined(NO_PMIC)
  544. PROFILING_START("pmic_init");
  545. pmic_init();
  546. PROFILING_END();
  547. #endif // !defined(MACH_FPGA) && !defined(NO_PMIC)
  548. PROFILING_END(); /* platform_early_init */
  549. #ifdef MTK_MT6360_PMIC_SUPPORT
  550. PROFILING_START("mt6360_pmic");
  551. mt6360_pmic_i2c_probe();
  552. PROFILING_END();
  553. #endif /* MTK_MT6360_PMIC_SUPPORT */
  554. #ifdef MTK_MT6360_LDO_SUPPORT
  555. PROFILING_START("mt6360_ldo");
  556. mt6360_ldo_i2c_probe();
  557. PROFILING_END();
  558. #endif /* MTK_MT6360_LDO_SUPPORT */
  559. }
  560. extern void mt65xx_bat_init(void);
  561. extern bool mtk_bat_allow_backlight_enable(void);
  562. #if defined (MTK_KERNEL_POWER_OFF_CHARGING)
  563. int kernel_charging_boot(void)
  564. {
  565. if ((g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) && upmu_is_chr_det() == KAL_TRUE) {
  566. dprintf(INFO,"[%s] Kernel Power Off Charging with Charger/Usb \n", __func__);
  567. return 1;
  568. } else if ((g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) && upmu_is_chr_det() == KAL_FALSE) {
  569. dprintf(INFO,"[%s] Kernel Power Off Charging without Charger/Usb \n", __func__);
  570. return -1;
  571. } else
  572. return 0;
  573. }
  574. #endif
  575. static void lk_vb_init(void)
  576. {
  577. #ifdef MTK_SECURITY_SW_SUPPORT
  578. u64 pl_start_addr = HEADER_BLOCK_SIZE_COMBO;
  579. #ifdef MTK_VER_SIMPLE_TEST
  580. u32 ret = 0;
  581. ret = sec_mtk_internal_ver_test(MTK_VER_SIMPLE_TEST);
  582. if (ret)
  583. assert(0);
  584. #endif
  585. #ifdef MTK_OTP_FRAMEWORK_V2
  586. enable_anti_rollback_v2_framework();
  587. #endif
  588. PROFILING_START("Security init");
  589. /* initialize security library */
  590. sec_func_init(pl_start_addr);
  591. seclib_set_oemkey(g_oemkey, OEM_PUBK_SZ);
  592. PROFILING_END();
  593. #endif
  594. }
  595. static void lk_vb_vfy_logo(void)
  596. {
  597. #ifdef MTK_SECURITY_SW_SUPPORT
  598. /* bypass logo vfy in fast meta mode */
  599. if(g_boot_mode == META_BOOT)
  600. return;
  601. PROFILING_START("logo verify");
  602. /*Verify logo before use it*/
  603. if (0 != img_auth_stor("logo", "logo", 0x0))
  604. assert(0);
  605. PROFILING_END();
  606. #endif
  607. }
  608. extern unsigned int mfg_clear_dfd(void);
  609. void platform_init(void)
  610. {
  611. bool backlight_on = false;
  612. int logo_size;
  613. PROFILING_START("platform_init");
  614. dprintf(CRITICAL, "platform_init()\n");
  615. init_storage();
  616. lk_vb_init();
  617. #ifdef MTK_AB_OTA_UPDATER
  618. /* get A/B system parameter before load dtb from boot image */
  619. get_AB_OTA_param();
  620. #endif
  621. /*
  622. * RSC initialize. It must be done before load device tree.
  623. * rsc_init will ectract DTBO index, which will be used in device
  624. * tree overlay, from PARA partition
  625. */
  626. rsc_init();
  627. /* The device tree should be loaded as early as possible. */
  628. load_device_tree();
  629. /* check doe settings to see if wdt needs to be disabled */
  630. PROFILING_START("mtk_wdt_doe_setup");
  631. mtk_wdt_doe_setup();
  632. PROFILING_END();
  633. #if defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  634. mt_gpio_set_default();
  635. #endif // defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  636. extern void dummy_ap_entry(void)__attribute__((weak)); /* This is empty function for normal load */
  637. if (dummy_ap_entry)
  638. dummy_ap_entry();
  639. #ifndef MACH_FPGA
  640. PROFILING_START("led init");
  641. leds_init();
  642. PROFILING_END();
  643. #endif // MACH_FPGA
  644. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  645. if ((g_boot_arg->boot_reason == BR_USB) && (upmu_is_chr_det() == KAL_FALSE)) {
  646. dprintf(INFO, "[%s] Unplugged Charger/Usb between Pre-loader and Uboot in Kernel Charging Mode, Power Off \n", __func__);
  647. mt_power_off();
  648. }
  649. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  650. PROFILING_START("ENV init");
  651. env_init();
  652. print_env();
  653. PROFILING_END();
  654. /* initialize the frame buffet information */
  655. g_fb_size = mt_disp_get_vram_size();
  656. g_fb_base = mblock_reserve_ext(&g_boot_arg->mblock_info, g_fb_size, 0x10000, 0x80000000, 1, "framebuffer");
  657. if (!g_fb_base) {
  658. dprintf(CRITICAL, "reserve framebuffer failed\n");
  659. }
  660. dprintf(CRITICAL, "FB base = 0x%x, FB size = 0x%x (%d)\n", g_fb_base, g_fb_size, g_fb_size);
  661. #ifndef MACH_FPGA
  662. #ifdef MTK_SMI_SUPPORT
  663. /* write SMI non on-the-fly register before DISP init */
  664. smi_apply_register_setting();
  665. #endif
  666. #endif
  667. #ifndef MACH_FPGA_NO_DISPLAY
  668. PROFILING_START("disp init");
  669. mt_disp_init((void *)g_fb_base);
  670. PROFILING_END();
  671. PROFILING_START("vedio init");
  672. drv_video_init();
  673. PROFILING_END();
  674. #endif /* MACH_FPGA_NO_DISPLAY */
  675. /*for kpd pmic mode setting*/
  676. set_kpd_pmic_mode();
  677. #ifndef MACH_FPGA
  678. PROFILING_START("boot mode select");
  679. #if !defined(NO_BOOT_MODE_SEL)
  680. boot_mode_select();
  681. #endif
  682. #ifdef CFG_MTK_WDT_COMMON
  683. PROFILING_START("wdt_check_exception");
  684. wdt_check_exception();
  685. PROFILING_END();
  686. #endif //CFG_MTK_WDT_COMMON
  687. #ifdef MTK_USB2JTAG_SUPPORT
  688. if (g_boot_mode != FASTBOOT) {
  689. extern void usb2jtag_init(void);
  690. usb2jtag_init();
  691. }
  692. #endif
  693. #ifdef MTK_AEE_PLATFORM_DEBUG_SUPPORT
  694. /* init lastbus: MUST call after kedump (in boot_mode_select) */
  695. latch_lastbus_init();
  696. #endif
  697. PROFILING_END(); /* boot mode select */
  698. #endif /*MACH_FPGA */
  699. lk_vb_vfy_logo();
  700. #ifndef MACH_FPGA_NO_DISPLAY
  701. /* fast meta mode */
  702. if(g_boot_mode != META_BOOT){
  703. PROFILING_START("load_logo");
  704. logo_size = mboot_common_load_logo((unsigned long)mt_get_logo_db_addr_pa(), "logo");
  705. assert(logo_size <= LK_LOGO_MAX_SIZE);
  706. PROFILING_END();
  707. } else
  708. /* Indicate logo lib that logo partition is not loaded */
  709. enable_logo(0);
  710. #endif // MACH_FPGA_NO_DISPLAY
  711. #if !defined(NO_BAT_INIT)
  712. #ifdef MTK_CHARGER_NEW_ARCH
  713. PROFILING_START("charger init");
  714. mtk_charger_init();
  715. PROFILING_END(); /* charger init */
  716. PROFILING_START("DLPT init");
  717. pmic_dlpt_init();
  718. PROFILING_END(); /* dlpt init */
  719. PROFILING_START("check sw_ocv");
  720. check_sw_ocv();
  721. PROFILING_END(); /* battery check sw_ocv */
  722. #ifdef MTK_HIGH_FRAME_RATE_FOR_DLPT
  723. /* move here for sw wk to avoid display current glitch */
  724. PROFILING_START("charger start");
  725. mtk_charger_start();
  726. PROFILING_END(); /* charger start */
  727. PROFILING_START(" DLPT get imix");
  728. get_dlpt_imix_r();
  729. PROFILING_END(); /* DLPT get imix */
  730. #endif
  731. #endif
  732. #endif
  733. /*Show download logo & message on screen */
  734. if (g_boot_arg->boot_mode == DOWNLOAD_BOOT) {
  735. dprintf(CRITICAL, "[LK] boot mode is DOWNLOAD_BOOT\n");
  736. #ifndef MACH_FPGA_NO_DISPLAY
  737. PROFILING_START("show logo");
  738. mt_disp_show_boot_logo();
  739. PROFILING_END();
  740. #endif
  741. video_printf(" => Downloading...\n");
  742. dprintf(CRITICAL, "enable backlight after show bootlogo! \n");
  743. #ifndef MACH_FPGA
  744. PROFILING_START("backlight");
  745. mt65xx_backlight_on();
  746. PROFILING_END();
  747. #endif
  748. #ifndef MACH_FPGA_NO_DISPLAY
  749. /* pwm need display sof */
  750. PROFILING_START("disp update");
  751. mt_disp_update_no_logo(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  752. PROFILING_END();
  753. #endif
  754. logo_lk_t = ((unsigned int)get_timer(boot_time));
  755. PROFILING_START("disable wdt, l2, cache, mmu");
  756. mtk_wdt_disable(); //Disable wdt before jump to DA
  757. platform_uninit();
  758. #ifdef HAVE_CACHE_PL310
  759. l2_disable();
  760. #endif
  761. arch_disable_cache(UCACHE);
  762. arch_disable_mmu();
  763. #ifdef ENABLE_L2_SHARING
  764. config_shared_SRAM_size();
  765. #endif
  766. PROFILING_END();
  767. jump_da(g_boot_arg->da_info.addr, g_boot_arg->da_info.arg1, g_boot_arg->da_info.arg2);
  768. }
  769. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  770. else if (g_boot_mode != META_BOOT &&
  771. g_boot_mode != ALARM_BOOT &&
  772. g_boot_mode != FASTBOOT &&
  773. g_boot_mode != KERNEL_POWER_OFF_CHARGING_BOOT &&
  774. g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT &&
  775. mtk_bat_allow_backlight_enable()) {
  776. #ifndef MACH_FPGA_NO_DISPLAY
  777. PROFILING_START("show logo");
  778. mt_disp_show_boot_logo();
  779. PROFILING_END();
  780. #endif // MACH_FPGA_NO_DISPLAY
  781. #ifndef MACH_FPGA
  782. PROFILING_START("backlight");
  783. mt65xx_backlight_on();
  784. PROFILING_END(); /* backlight */
  785. #endif
  786. #ifndef MACH_FPGA_NO_DISPLAY
  787. /* pwm need display sof */
  788. PROFILING_START("disp update");
  789. mt_disp_update_no_logo(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  790. PROFILING_END();
  791. #endif
  792. backlight_on = true;
  793. dprintf(INFO, "backlight enabled before battery init\n");
  794. logo_lk_t = ((unsigned int)get_timer(boot_time));
  795. }
  796. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  797. #ifndef MACH_FPGA
  798. PROFILING_START("mt_clk_post_init");
  799. mt_clk_post_init();
  800. PROFILING_END(); /* mt_clk_post_init */
  801. #if !defined(NO_PLL_TURN_OFF)
  802. PROFILING_START("mt_pll_turn_off");
  803. mt_pll_turn_off();
  804. PROFILING_END(); /* mt_pll_turn_off */
  805. #endif // !defined(NO_PLL_TURN_OFF)
  806. #if !defined(NO_DCM)
  807. PROFILING_START("mt_dcm_init");
  808. if (mt_dcm_init())
  809. dprintf(CRITICAL, "mt_dcm_init fail\n");
  810. PROFILING_END(); /* mt_dcm_init */
  811. #endif // !defined(NO_DCM)
  812. #if !defined(NO_BAT_INIT)
  813. #ifdef MTK_CHARGER_NEW_ARCH
  814. #ifndef MTK_HIGH_FRAME_RATE_FOR_DLPT
  815. PROFILING_START("charger start");
  816. mtk_charger_start();
  817. PROFILING_END(); /* charger start */
  818. PROFILING_START(" DLPT get imix");
  819. get_dlpt_imix_r();
  820. PROFILING_END(); /* DLPT get imix */
  821. #endif
  822. #else
  823. PROFILING_START("mt65xx_bat_init");
  824. mt65xx_bat_init();
  825. PROFILING_END(); /* mt65xx_bat_init */
  826. #endif // MTK_CHARGER_NEW_ARCH
  827. #endif // !defined(NO_BAT_INIT)
  828. #endif // MACH_FPGA
  829. #ifndef CFG_POWER_CHARGING
  830. PROFILING_START("RTC boot check Init");
  831. /* NOTE: if define CFG_POWER_CHARGING, will rtc_boot_check() in mt65xx_bat_init() */
  832. rtc_boot_check(false);
  833. PROFILING_END();
  834. #endif // CFG_POWER_CHARGING
  835. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  836. if (kernel_charging_boot() == 1) {
  837. PROFILING_START("show logo");
  838. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  839. CHARGER_TYPE CHR_Type_num = CHARGER_UNKNOWN;
  840. CHR_Type_num = hw_charging_get_charger_type();
  841. if ((g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) ||
  842. ((CHR_Type_num != STANDARD_HOST) && (CHR_Type_num != NONSTANDARD_CHARGER))) {
  843. #endif // MTK_BATLOWV_NO_PANEL_ON_EARLY
  844. mt_disp_power(TRUE);
  845. #ifndef MACH_FPGA_NO_DISPLAY
  846. mt_disp_show_low_battery();
  847. #endif
  848. mt65xx_leds_brightness_set(6, 110);
  849. #ifndef MACH_FPGA_NO_DISPLAY
  850. /* pwm need display sof */
  851. PROFILING_START("display update");
  852. mt_disp_update_no_logo(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  853. PROFILING_END();
  854. #endif
  855. backlight_on = true;
  856. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  857. }
  858. #endif
  859. PROFILING_END();
  860. }
  861. #else // MTK_KERNEL_POWER_OFF_CHARGING
  862. /* fast meta mode */
  863. if(g_boot_mode != META_BOOT)
  864. if (g_boot_mode != ALARM_BOOT && (g_boot_mode != FASTBOOT) && !backlight_on) {
  865. #ifndef MACH_FPGA_NO_DISPLAY
  866. PROFILING_START("show logo");
  867. mt_disp_show_boot_logo();
  868. PROFILING_END(); /* show logo */
  869. #endif
  870. }
  871. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  872. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  873. if (!is_low_battery(0)) {
  874. #endif
  875. /*
  876. * Update LCM with framebuffer before
  877. * turning on backlight to avoid LCM noise if there is
  878. * no any logo showed on screen before.
  879. */
  880. if (!backlight_on) {
  881. logo_lk_t = ((unsigned int)get_timer(boot_time));
  882. #ifndef MACH_FPGA_NO_DISPLAY
  883. PROFILING_START("display update");
  884. mt_disp_update_no_logo(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  885. PROFILING_END();
  886. #endif
  887. #ifndef MACH_FPGA
  888. PROFILING_START("backlight");
  889. mt65xx_backlight_on();
  890. PROFILING_END(); /* backlight */
  891. #endif
  892. }
  893. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  894. }
  895. #endif
  896. #ifndef MACH_FPGA
  897. PROFILING_START("sw_env");
  898. sw_env();
  899. PROFILING_END();
  900. #endif
  901. PROFILING_START("pcie init");
  902. mtk_pcie_init();
  903. PROFILING_END();
  904. // check and clear gpu dfd
  905. mfg_clear_dfd();
  906. PROFILING_END(); /* platform_init */
  907. }
  908. void platform_uninit(void)
  909. {
  910. #ifndef MACH_FPGA
  911. leds_deinit();
  912. platform_clear_all_on_mux();
  913. #endif
  914. platform_deinit_interrupts();
  915. return;
  916. }
  917. #ifdef ENABLE_L2_SHARING
  918. #define ADDR_CA7L_CACHE_CONFIG_MP(x) (CA7MCUCFG_BASE + 0x200 * x)
  919. #define L2C_SIZE_CFG_OFFSET 8
  920. #define L2C_SHARE_EN_OFFSET 12
  921. /* 4'b1111: 2048KB(not support)
  922. * 4'b0111: 1024KB(not support)
  923. * 4'b0011: 512KB
  924. * 4'b0001: 256KB
  925. * 4'b0000: 128KB (not support)
  926. */
  927. int is_l2_need_config(void)
  928. {
  929. volatile unsigned int cache_cfg, addr;
  930. addr = ADDR_CA7L_CACHE_CONFIG_MP(0);
  931. cache_cfg = DRV_Reg32(addr);
  932. cache_cfg = cache_cfg >> L2C_SIZE_CFG_OFFSET;
  933. /* only read 256KB need to be config.*/
  934. if ((cache_cfg &(0x7)) == 0x1) {
  935. return 1;
  936. }
  937. return 0;
  938. }
  939. void cluster_l2_share_enable(int cluster)
  940. {
  941. volatile unsigned int cache_cfg, addr;
  942. addr = ADDR_CA7L_CACHE_CONFIG_MP(cluster);
  943. /* set L2C size to 256KB */
  944. cache_cfg = DRV_Reg32(addr);
  945. cache_cfg &= (~0x7) << L2C_SIZE_CFG_OFFSET;
  946. cache_cfg |= 0x1 << L2C_SIZE_CFG_OFFSET;
  947. /* enable L2C_share_en. Sram only for other to use*/
  948. cache_cfg |= (0x1 << L2C_SHARE_EN_OFFSET);
  949. DRV_WriteReg32(addr, cache_cfg);
  950. }
  951. void cluster_l2_share_disable(int cluster)
  952. {
  953. volatile unsigned int cache_cfg, addr;
  954. addr = ADDR_CA7L_CACHE_CONFIG_MP(cluster);
  955. /* set L2C size to 512KB */
  956. cache_cfg = DRV_Reg32(addr);
  957. cache_cfg &= (~0x7) << L2C_SIZE_CFG_OFFSET;
  958. cache_cfg |= 0x3 << L2C_SIZE_CFG_OFFSET;
  959. DRV_WriteReg32(addr, cache_cfg);
  960. /* disable L2C_share_en. Sram only for cpu to use*/
  961. cache_cfg &= ~(0x1 << L2C_SHARE_EN_OFFSET);
  962. DRV_WriteReg32(addr, cache_cfg);
  963. }
  964. /* config L2 cache and sram to its size */
  965. void config_L2_size(void)
  966. {
  967. int cluster;
  968. if (is_l2_need_config()) {
  969. /*
  970. * Becuase mcu config is protected.
  971. * only can write in secutity mode
  972. */
  973. if (dev_info_nr_cpu() == 6) {
  974. cluster_l2_share_disable(0);
  975. cluster_l2_share_enable(1);
  976. }
  977. else {
  978. for (cluster = 0; cluster < 2; cluster++) {
  979. cluster_l2_share_disable(cluster);
  980. }
  981. }
  982. }
  983. }
  984. /* config SRAM back from L2 cache for DA relocation */
  985. void config_shared_SRAM_size(void)
  986. {
  987. int cluster;
  988. if (is_l2_need_config()) {
  989. /*
  990. * Becuase mcu config is protected.
  991. * only can write in secutity mode
  992. */
  993. for (cluster = 0; cluster < 2; cluster++) {
  994. cluster_l2_share_enable(cluster);
  995. }
  996. }
  997. }
  998. #endif
  999. void platform_sec_post_init(void)
  1000. {
  1001. unsigned int ret = 0;
  1002. ret = crypto_hw_engine_disable();
  1003. if (ret) {
  1004. dprintf(CRITICAL, "[SEC] crypto engine HW disable fail\n");
  1005. }
  1006. /* Lock Device APC in LK */
  1007. dprintf(CRITICAL, "[DEVAPC] sec_post_init\n");
  1008. #if APUSYS_APC_TURN_ON
  1009. mt_secure_call(MTK_SIP_BL_APUSYS_CONTROL_AARCH32, 0, 0, 0, 0);
  1010. #endif
  1011. #if DEVAPC_TURN_ON
  1012. dprintf(CRITICAL, "[DEVAPC] platform_sec_post_init - SMC call to ATF from LK\n");
  1013. #ifdef MTK_SMC_ID_MGMT
  1014. mt_secure_call(MTK_SIP_LK_DAPC_INIT, 0, 0, 0, 0);
  1015. #else
  1016. mt_secure_call(0x82000101, 0, 0, 0);
  1017. #endif
  1018. #endif
  1019. #if defined(MTK_TINYSYS_SCP_SUPPORT) || defined(MTK_AUDIODSP_SUPPORT)
  1020. tinysys_set_devapc_domain();
  1021. #endif
  1022. }
  1023. u32 get_devinfo_with_index(u32 index)
  1024. {
  1025. return internal_get_devinfo_with_index(index);
  1026. }
  1027. int platform_skip_hibernation(void)
  1028. {
  1029. switch (g_boot_arg->boot_reason) {
  1030. #if 0 // let schedule power on to go hiberantion bootup process
  1031. case BR_RTC:
  1032. #endif
  1033. case BR_WDT:
  1034. case BR_WDT_BY_PASS_PWK:
  1035. case BR_WDT_SW:
  1036. case BR_WDT_HW:
  1037. return 1;
  1038. }
  1039. return 0;
  1040. }
  1041. int is_meta_log_disable(void)
  1042. {
  1043. return g_boot_arg->meta_log_disable;
  1044. }