platform.c 32 KB

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