platform.c 32 KB

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