platform.c 33 KB

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