platform.c 32 KB

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