platform.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #include <debug.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <video.h>
  35. #include <dev/uart.h>
  36. #include <arch/arm.h>
  37. #include <arch/arm/mmu.h>
  38. #include <arch/ops.h>
  39. #include <target/board.h>
  40. #include <platform/mt_reg_base.h>
  41. #include <platform/mt_disp_drv.h>
  42. #include <platform/disp_drv.h>
  43. #include <platform/boot_mode.h>
  44. #include <platform/mt_logo.h>
  45. #include <platform/partition.h>
  46. #include <env.h>
  47. #include <platform/mt_gpio.h>
  48. #include <platform/mt_pmic.h>
  49. #include <platform/mt_pmic_dlpt.h>
  50. #include <platform/mt_pmic_wrap_init.h>
  51. #include <platform/mt_i2c.h>
  52. #include <platform/mtk_key.h>
  53. #include <platform/mtk_smi.h>
  54. #include <platform/mt_rtc.h>
  55. #include <platform/mt_leds.h>
  56. #include <platform/pmif.h>
  57. #include <platform/spmi.h>
  58. #include <platform/upmu_common.h>
  59. #ifdef CFG_MTK_WDT_COMMON
  60. #include <mtk_wdt.h>
  61. #else
  62. #include <platform/mtk_wdt.h>
  63. #endif
  64. #include <platform/disp_drv_platform.h>
  65. #include <platform/verified_boot.h>
  66. #include <platform/sec_devinfo.h>
  67. #include <plinfo.h> // for plinfo_get_brom_header_block_size()
  68. #include <libfdt.h>
  69. #include <mt_gic.h> // for platform_init_interrupts()
  70. #include <mt_boot.h> // for bldr_load_dtb()
  71. #include <mtk_dcm.h> // for mt_dcm_init()
  72. #include <fpga_boot_argument.h>
  73. #include <profiling.h>
  74. #include <assert.h>
  75. #include <platform/mt_gpt.h> // for get_timer()
  76. #include <sec_export.h>
  77. #include "memory_layout.h"
  78. #include "load_vfy_boot.h"
  79. #include <fdt_op.h>
  80. #include <verified_boot_common.h>
  81. #include <platform/mtk_charger_intf.h>
  82. #include <rsc.h>
  83. #ifdef MTK_SMC_ID_MGMT
  84. #include "mtk_secure_api.h"
  85. #endif
  86. #include "mtk_dcm.h" //for mt_dcm_init()
  87. #ifdef MTK_EMMC_SUPPORT
  88. #include "mmc_rpmb.h"
  89. #endif
  90. #define DEVAPC_TURN_ON 1
  91. #define APUSYS_APC_TURN_ON 1
  92. #if defined(MTK_VPU_SUPPORT)
  93. #include <platform/mt_vpu.h>
  94. #endif
  95. #ifdef MTK_AB_OTA_UPDATER
  96. #include "bootctrl.h"
  97. #endif
  98. #if defined(MTK_SECURITY_SW_SUPPORT)
  99. #include "oemkey.h"
  100. #endif
  101. #if (defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT))
  102. #include "ufs_aio_interface.h"
  103. #include "ufs_aio_rpmb.h"
  104. #endif
  105. #ifdef MTK_CHARGER_NEW_ARCH
  106. #include <mtk_charger.h>
  107. #include <mtk_battery.h>
  108. #endif
  109. #include "show_animation_common.h"
  110. #ifdef MTK_MT6360_PMIC_SUPPORT
  111. #include <platform/mt6360_pmic.h>
  112. #endif /* MTK_MT6360_PMIC_SUPPORT */
  113. #ifdef MTK_MT6360_LDO_SUPPORT
  114. #include <platform/mt6360_ldo.h>
  115. #endif /* MTK_MT6360_LDO_SUPPORT */
  116. #ifdef MTK_SECURITY_SW_SUPPORT
  117. extern u8 g_oemkey[OEM_PUBK_SZ];
  118. #endif
  119. #ifdef LK_DL_CHECK
  120. /*block if check dl fail*/
  121. #undef LK_DL_CHECK_BLOCK_LEVEL
  122. #endif
  123. extern void platform_early_init_timer();
  124. extern void jump_da(u32 addr, u32 arg1, u32 arg2);
  125. extern int i2c_hw_init(void);
  126. extern int mboot_common_load_logo(unsigned long logo_addr, char* filename);
  127. extern int sec_func_init(u64 pl_start_addr);
  128. extern int sec_usbdl_enabled (void);
  129. extern unsigned int crypto_hw_engine_disable(void);
  130. extern void mtk_wdt_disable(void);
  131. extern void platform_deinit_interrupts(void);
  132. extern int mmc_get_dl_info(void);
  133. extern int mmc_legacy_init(int);
  134. extern void platform_clear_all_on_mux(void);
  135. extern unsigned int crypto_hw_engine_disable(void);
  136. #ifdef MTK_AEE_PLATFORM_DEBUG_SUPPORT
  137. extern void latch_lastbus_init(void);
  138. #endif
  139. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  140. extern kal_bool is_low_battery(kal_int32 val);
  141. extern int hw_charging_get_charger_type(void);
  142. #endif
  143. #ifdef MTK_LK_REGISTER_WDT
  144. extern void lk_register_wdt_callback(void);
  145. #endif
  146. void platform_uninit(void);
  147. void config_shared_SRAM_size(void);
  148. extern int dev_info_nr_cpu(void);
  149. extern void mt_pll_turn_off(void);
  150. extern void mt_clk_post_init(void);
  151. struct mmu_initial_mapping mmu_initial_mappings[] = {
  152. {
  153. .phys = (uint64_t)0,
  154. .virt = (uint32_t)0,
  155. .size = 0x40000000,
  156. .flags = MMU_MEMORY_TYPE_STRONGLY_ORDERED | MMU_MEMORY_AP_P_RW_U_NA,
  157. .name = "mcusys"
  158. },
  159. {
  160. .phys = (uint64_t)MEMBASE,
  161. .virt = (uint32_t)MEMBASE,
  162. .size = ROUNDUP(MEMSIZE, SECTION_SIZE),
  163. .flags = MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  164. .name = "ram"
  165. },
  166. {
  167. .phys = (uint64_t)SCRATCH_ADDR,
  168. .virt = (uint32_t)SCRATCH_ADDR,
  169. .size = SCRATCH_SIZE,
  170. .flags = MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  171. .name = "download"
  172. },
  173. /* null entry to terminate the list */
  174. { 0 }
  175. };
  176. BOOT_ARGUMENT *g_boot_arg;
  177. BOOT_ARGUMENT boot_addr;
  178. int g_nr_bank;
  179. BI_DRAM bi_dram[MAX_NR_BANK];
  180. unsigned int g_fb_base;
  181. unsigned int g_fb_size;
  182. static int g_dram_init_ret;
  183. static unsigned int bootarg_addr;
  184. static unsigned int bootarg_size;
  185. extern unsigned int logo_lk_t;
  186. extern unsigned int boot_time;
  187. int dram_init(void)
  188. {
  189. unsigned int i;
  190. struct boot_tag *tags;
  191. /* Get parameters from pre-loader. Get as early as possible
  192. * The address of BOOT_ARGUMENT_LOCATION will be used by Linux later
  193. * So copy the parameters from BOOT_ARGUMENT_LOCATION to LK's memory region
  194. */
  195. g_boot_arg = &boot_addr;
  196. bootarg_addr = (unsigned int)((unsigned int *)BOOT_ARGUMENT_LOCATION);
  197. bootarg_size = 0;
  198. fpga_set_boot_argument((BOOT_ARGUMENT*)bootarg_addr);
  199. if (*(unsigned int *)BOOT_ARGUMENT_LOCATION == BOOT_ARGUMENT_MAGIC) {
  200. memcpy(g_boot_arg, (void*)BOOT_ARGUMENT_LOCATION, sizeof(BOOT_ARGUMENT));
  201. bootarg_size = sizeof(BOOT_ARGUMENT);
  202. } else {
  203. g_boot_arg->maggic_number = BOOT_ARGUMENT_MAGIC;
  204. for (tags = (void *)BOOT_ARGUMENT_LOCATION; tags->hdr.size; tags = boot_tag_next(tags)) {
  205. switch (tags->hdr.tag) {
  206. case BOOT_TAG_BOOT_REASON:
  207. g_boot_arg->boot_reason = tags->u.boot_reason.boot_reason;
  208. break;
  209. case BOOT_TAG_BOOT_MODE:
  210. g_boot_arg->boot_mode = tags->u.boot_mode.boot_mode;
  211. break;
  212. case BOOT_TAG_META_COM:
  213. g_boot_arg->meta_com_type = tags->u.meta_com.meta_com_type;
  214. g_boot_arg->meta_com_id = tags->u.meta_com.meta_com_id;
  215. g_boot_arg->meta_uart_port = tags->u.meta_com.meta_uart_port;
  216. g_boot_arg->meta_log_disable = tags->u.meta_com.meta_log_disable;
  217. g_boot_arg->fast_meta_gpio = tags->u.meta_com.fast_meta_gpio;
  218. break;
  219. case BOOT_TAG_APUSYS_INFO:
  220. g_boot_arg->g_apusys_status = tags->u.apusys_info.apusys_status;
  221. if(g_boot_arg->g_apusys_status == APUSYS_NORMAL)
  222. cmdline_append("apusys_status=normal");
  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 (1U << 11) /* bit 11 0: UFS, bit 11 1: eMMC */
  466. void init_storage(void)
  467. {
  468. PROFILING_START("NAND/EMMC/UFS init");
  469. #if (defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT))
  470. #ifdef MACH_FPGA
  471. #if 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. else {
  483. mmc_legacy_init(1);
  484. cmdline_append("androidboot.fstab_suffix=emmc");
  485. }
  486. #endif
  487. #else
  488. #ifndef MACH_FPGA
  489. nand_init();
  490. nand_driver_test();
  491. #endif // MACH_FPGA
  492. #endif // MTK_EMMC_SUPPORT || MTK_UFS_SUPPORT
  493. #if (defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT))
  494. init_rpmb_sharemem();
  495. #endif
  496. #if defined(MTK_UFS_SUPPORT)
  497. if ((DRV_Reg32(GPIO_BANK) & TRAP_UFS_FIRST) == 0) {
  498. if (ufs_clr_write_protect())
  499. dprintf(CRITICAL, "[LK ERROR] UFS clear write protect fail!!!\n");
  500. }
  501. #endif
  502. PROFILING_END(); /* NAND/EMMC/UFS init */
  503. }
  504. /******************************************************************************
  505. ******************************************************************************/
  506. void platform_early_init(void)
  507. {
  508. PROFILING_START("platform_early_init");
  509. #ifdef MTK_LK_REGISTER_WDT
  510. lk_register_wdt_callback();
  511. #endif
  512. /* initialize the uart */
  513. uart_init_early();
  514. PROFILING_START("Devinfo Init");
  515. #ifdef MTK_MT22_MODE
  516. devinfo_init_mode(MTK_MT22_MODE);
  517. #endif
  518. init_devinfo_data();
  519. dprintf(CRITICAL, "[LK] segment = 0x%x\n", (get_devinfo_with_index(30) & 0xFF));
  520. dprintf(CRITICAL, "[LK] spare4 = 0x%x\n", get_devinfo_with_index(7));
  521. PROFILING_END();
  522. platform_init_interrupts();
  523. platform_early_init_timer();
  524. #if !defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  525. mt_gpio_set_default();
  526. #endif // !defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  527. dprintf(SPEW, "bootarg_addr: 0x%x, bootarg_size: 0x%x\n", platform_get_bootarg_addr(), platform_get_bootarg_size());
  528. if (g_dram_init_ret < 0) {
  529. dprintf(CRITICAL, "[LK ERROR] DRAM bank number is not correct!!!\n");
  530. while (1) ;
  531. }
  532. //i2c_v1_init();
  533. PROFILING_START("WDT Init");
  534. mtk_wdt_init();
  535. PROFILING_END();
  536. //i2c init
  537. i2c_hw_init();
  538. #ifdef MACH_FPGA
  539. mtk_timer_init(); // GPT4 will be initialized at PL after
  540. mtk_wdt_disable(); // WDT will be triggered when uncompressing linux image on FPGA
  541. #endif
  542. PROFILING_START("pmif spmi init");
  543. pmif_spmi_init(SPMI_MASTER_0);
  544. PROFILING_END();
  545. pwrap_init_lk();
  546. #if !defined(MACH_FPGA) && !defined(NO_PMIC)
  547. PROFILING_START("pmic_init");
  548. pmic_init();
  549. PROFILING_END();
  550. #endif // !defined(MACH_FPGA) && !defined(NO_PMIC)
  551. PROFILING_END(); /* platform_early_init */
  552. #ifdef MTK_MT6360_PMIC_SUPPORT
  553. PROFILING_START("mt6360_pmic");
  554. mt6360_pmic_i2c_probe();
  555. PROFILING_END();
  556. #endif /* MTK_MT6360_PMIC_SUPPORT */
  557. #ifdef MTK_MT6360_LDO_SUPPORT
  558. PROFILING_START("mt6360_ldo");
  559. mt6360_ldo_i2c_probe();
  560. PROFILING_END();
  561. #endif /* MTK_MT6360_LDO_SUPPORT */
  562. }
  563. extern void mt65xx_bat_init(void);
  564. extern bool mtk_bat_allow_backlight_enable(void);
  565. #if defined (MTK_KERNEL_POWER_OFF_CHARGING)
  566. int kernel_charging_boot(void)
  567. {
  568. if ((g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) && upmu_is_chr_det() == KAL_TRUE) {
  569. dprintf(INFO,"[%s] Kernel Power Off Charging with Charger/Usb \n", __func__);
  570. return 1;
  571. } else if ((g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) && upmu_is_chr_det() == KAL_FALSE) {
  572. dprintf(INFO,"[%s] Kernel Power Off Charging without Charger/Usb \n", __func__);
  573. return -1;
  574. } else
  575. return 0;
  576. }
  577. #endif
  578. static void lk_vb_init(void)
  579. {
  580. #ifdef MTK_SECURITY_SW_SUPPORT
  581. u64 pl_start_addr = 0;
  582. #ifdef MTK_VER_SIMPLE_TEST
  583. u32 ret = 0;
  584. ret = sec_mtk_internal_ver_test(MTK_VER_SIMPLE_TEST);
  585. if (ret)
  586. assert(0);
  587. #endif
  588. #ifdef MTK_OTP_FRAMEWORK_V2
  589. enable_anti_rollback_v2_framework();
  590. #endif
  591. plinfo_get_brom_header_block_size(&pl_start_addr);
  592. PROFILING_START("Security init");
  593. /* initialize security library */
  594. sec_func_init(pl_start_addr);
  595. seclib_set_oemkey(g_oemkey, OEM_PUBK_SZ);
  596. PROFILING_END();
  597. #endif
  598. }
  599. static void lk_vb_vfy_logo(void)
  600. {
  601. #ifdef MTK_SECURITY_SW_SUPPORT
  602. /* bypass logo vfy in fast meta mode */
  603. if(g_boot_mode == META_BOOT)
  604. return;
  605. PROFILING_START("logo verify");
  606. /*Verify logo before use it*/
  607. if (0 != img_auth_stor("logo", "logo", 0x0))
  608. assert(0);
  609. PROFILING_END();
  610. #endif
  611. }
  612. extern unsigned int mfg_clear_dfd(void);
  613. void platform_init(void)
  614. {
  615. bool backlight_on = false;
  616. int logo_size;
  617. PROFILING_START("platform_init");
  618. dprintf(CRITICAL, "platform_init()\n");
  619. init_storage();
  620. lk_vb_init();
  621. #ifdef MTK_AB_OTA_UPDATER
  622. /* get A/B system parameter before load dtb from boot image */
  623. get_AB_OTA_param();
  624. #endif
  625. /*
  626. * RSC initialize. It must be done before load device tree.
  627. * rsc_init will ectract DTBO index, which will be used in device
  628. * tree overlay, from PARA partition
  629. */
  630. rsc_init();
  631. /* The device tree should be loaded as early as possible. */
  632. load_device_tree();
  633. /* check doe settings to see if wdt needs to be disabled */
  634. PROFILING_START("mtk_wdt_doe_setup");
  635. mtk_wdt_doe_setup();
  636. PROFILING_END();
  637. #if defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  638. mt_gpio_set_default();
  639. #endif // defined(USE_DTB_NO_DWS) && !defined(MACH_FPGA)
  640. extern void dummy_ap_entry(void)__attribute__((weak)); /* This is empty function for normal load */
  641. if (dummy_ap_entry)
  642. dummy_ap_entry();
  643. #ifndef MACH_FPGA
  644. PROFILING_START("led init");
  645. leds_init();
  646. PROFILING_END();
  647. #endif // MACH_FPGA
  648. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  649. if ((g_boot_arg->boot_reason == BR_USB) && (upmu_is_chr_det() == KAL_FALSE)) {
  650. dprintf(INFO, "[%s] Unplugged Charger/Usb between Pre-loader and Uboot in Kernel Charging Mode, Power Off \n", __func__);
  651. mt_power_off();
  652. }
  653. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  654. PROFILING_START("ENV init");
  655. env_init();
  656. print_env();
  657. PROFILING_END();
  658. /* initialize the frame buffet information */
  659. g_fb_size = mt_disp_get_vram_size();
  660. g_fb_base = mblock_reserve_ext(&g_boot_arg->mblock_info, g_fb_size, 0x10000, 0x80000000, 1, "framebuffer");
  661. if (!g_fb_base) {
  662. dprintf(CRITICAL, "reserve framebuffer failed\n");
  663. }
  664. dprintf(CRITICAL, "FB base = 0x%x, FB size = 0x%x (%d)\n", g_fb_base, g_fb_size, g_fb_size);
  665. #ifndef MACH_FPGA
  666. #ifdef MTK_SMI_SUPPORT
  667. /* write SMI non on-the-fly register before DISP init */
  668. smi_apply_register_setting();
  669. #endif
  670. #endif
  671. #ifndef MACH_FPGA_NO_DISPLAY
  672. PROFILING_START("disp init");
  673. mt_disp_init((void *)g_fb_base);
  674. PROFILING_END();
  675. PROFILING_START("vedio init");
  676. drv_video_init();
  677. PROFILING_END();
  678. #endif /* MACH_FPGA_NO_DISPLAY */
  679. /*for kpd pmic mode setting*/
  680. set_kpd_pmic_mode();
  681. #ifndef MACH_FPGA
  682. PROFILING_START("boot mode select");
  683. #if !defined(NO_BOOT_MODE_SEL)
  684. boot_mode_select();
  685. #endif
  686. #ifdef CFG_MTK_WDT_COMMON
  687. PROFILING_START("wdt_check_exception");
  688. wdt_check_exception();
  689. PROFILING_END();
  690. #endif //CFG_MTK_WDT_COMMON
  691. #ifdef MTK_USB2JTAG_SUPPORT
  692. if (g_boot_mode != FASTBOOT) {
  693. extern void usb2jtag_init(void);
  694. usb2jtag_init();
  695. }
  696. #endif
  697. #ifdef MTK_AEE_PLATFORM_DEBUG_SUPPORT
  698. /* init lastbus: MUST call after kedump (in boot_mode_select) */
  699. latch_lastbus_init();
  700. #endif
  701. PROFILING_END(); /* boot mode select */
  702. #endif /*MACH_FPGA */
  703. lk_vb_vfy_logo();
  704. #ifndef MACH_FPGA_NO_DISPLAY
  705. /* fast meta mode */
  706. if(g_boot_mode != META_BOOT){
  707. PROFILING_START("load_logo");
  708. logo_size = mboot_common_load_logo((unsigned long)mt_get_logo_db_addr_pa(), "logo");
  709. assert(logo_size <= LK_LOGO_MAX_SIZE);
  710. PROFILING_END();
  711. } else
  712. /* Indicate logo lib that logo partition is not loaded */
  713. enable_logo(0);
  714. #endif // MACH_FPGA_NO_DISPLAY
  715. #if !defined(NO_BAT_INIT)
  716. #ifdef MTK_CHARGER_NEW_ARCH
  717. PROFILING_START("charger init");
  718. mtk_charger_init();
  719. PROFILING_END(); /* charger init */
  720. PROFILING_START("DLPT init");
  721. pmic_dlpt_init();
  722. PROFILING_END(); /* dlpt init */
  723. PROFILING_START("check sw_ocv");
  724. check_sw_ocv();
  725. PROFILING_END(); /* battery check sw_ocv */
  726. #endif
  727. #endif
  728. /*Show download logo & message on screen */
  729. if (g_boot_arg->boot_mode == DOWNLOAD_BOOT) {
  730. dprintf(CRITICAL, "[LK] boot mode is DOWNLOAD_BOOT\n");
  731. #ifndef MACH_FPGA_NO_DISPLAY
  732. PROFILING_START("show logo");
  733. mt_disp_show_boot_logo();
  734. PROFILING_END();
  735. #endif
  736. video_printf(" => Downloading...\n");
  737. dprintf(CRITICAL, "enable backlight after show bootlogo! \n");
  738. #ifndef MACH_FPGA
  739. PROFILING_START("backlight");
  740. mt65xx_backlight_on();
  741. PROFILING_END();
  742. #endif
  743. #ifndef MACH_FPGA_NO_DISPLAY
  744. /* pwm need display sof */
  745. PROFILING_START("disp update");
  746. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  747. PROFILING_END();
  748. #endif
  749. logo_lk_t = ((unsigned int)get_timer(boot_time));
  750. PROFILING_START("disable wdt, l2, cache, mmu");
  751. mtk_wdt_disable(); //Disable wdt before jump to DA
  752. platform_uninit();
  753. #ifdef HAVE_CACHE_PL310
  754. l2_disable();
  755. #endif
  756. arch_disable_cache(UCACHE);
  757. arch_disable_mmu();
  758. #ifdef ENABLE_L2_SHARING
  759. config_shared_SRAM_size();
  760. #endif
  761. PROFILING_END();
  762. jump_da(g_boot_arg->da_info.addr, g_boot_arg->da_info.arg1, g_boot_arg->da_info.arg2);
  763. }
  764. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  765. else if (g_boot_mode != META_BOOT &&
  766. g_boot_mode != ALARM_BOOT &&
  767. g_boot_mode != FASTBOOT &&
  768. g_boot_mode != KERNEL_POWER_OFF_CHARGING_BOOT &&
  769. g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT &&
  770. mtk_bat_allow_backlight_enable()) {
  771. #ifndef MACH_FPGA_NO_DISPLAY
  772. PROFILING_START("show logo");
  773. mt_disp_show_boot_logo();
  774. PROFILING_END();
  775. #endif // MACH_FPGA_NO_DISPLAY
  776. #ifndef MACH_FPGA
  777. PROFILING_START("backlight");
  778. mt65xx_backlight_on();
  779. PROFILING_END(); /* backlight */
  780. #endif
  781. #ifndef MACH_FPGA_NO_DISPLAY
  782. /* pwm need display sof */
  783. PROFILING_START("disp update");
  784. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  785. PROFILING_END();
  786. #endif
  787. backlight_on = true;
  788. dprintf(INFO, "backlight enabled before battery init\n");
  789. logo_lk_t = ((unsigned int)get_timer(boot_time));
  790. }
  791. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  792. #ifndef MACH_FPGA
  793. PROFILING_START("mt_clk_post_init");
  794. mt_clk_post_init();
  795. PROFILING_END(); /* mt_clk_post_init */
  796. #if !defined(NO_PLL_TURN_OFF)
  797. PROFILING_START("mt_pll_turn_off");
  798. mt_pll_turn_off();
  799. PROFILING_END(); /* mt_pll_turn_off */
  800. #endif // !defined(NO_PLL_TURN_OFF)
  801. #if !defined(NO_DCM)
  802. PROFILING_START("mt_dcm_init");
  803. if (mt_dcm_init())
  804. dprintf(CRITICAL, "mt_dcm_init fail\n");
  805. PROFILING_END(); /* mt_dcm_init */
  806. #endif // !defined(NO_DCM)
  807. #if !defined(NO_BAT_INIT)
  808. #ifdef MTK_CHARGER_NEW_ARCH
  809. PROFILING_START("charger start");
  810. mtk_charger_start();
  811. PROFILING_END(); /* charger start */
  812. PROFILING_START(" DLPT get imix");
  813. get_dlpt_imix_r();
  814. PROFILING_END(); /* DLPT get imix */
  815. #else
  816. PROFILING_START("mt65xx_bat_init");
  817. mt65xx_bat_init();
  818. PROFILING_END(); /* mt65xx_bat_init */
  819. #endif // MTK_CHARGER_NEW_ARCH
  820. #endif // !defined(NO_BAT_INIT)
  821. #endif // MACH_FPGA
  822. #ifndef CFG_POWER_CHARGING
  823. PROFILING_START("RTC boot check Init");
  824. /* NOTE: if define CFG_POWER_CHARGING, will rtc_boot_check() in mt65xx_bat_init() */
  825. rtc_boot_check(false);
  826. PROFILING_END();
  827. #endif // CFG_POWER_CHARGING
  828. #ifdef MTK_KERNEL_POWER_OFF_CHARGING
  829. if (kernel_charging_boot() == 1) {
  830. PROFILING_START("show logo");
  831. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  832. CHARGER_TYPE CHR_Type_num = CHARGER_UNKNOWN;
  833. CHR_Type_num = hw_charging_get_charger_type();
  834. if ((g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) ||
  835. ((CHR_Type_num != STANDARD_HOST) && (CHR_Type_num != NONSTANDARD_CHARGER))) {
  836. #endif // MTK_BATLOWV_NO_PANEL_ON_EARLY
  837. mt_disp_power(TRUE);
  838. #ifndef MACH_FPGA_NO_DISPLAY
  839. mt_disp_show_low_battery();
  840. #endif
  841. mt65xx_leds_brightness_set(6, 110);
  842. #ifndef MACH_FPGA_NO_DISPLAY
  843. /* pwm need display sof */
  844. PROFILING_START("display update");
  845. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  846. PROFILING_END();
  847. #endif
  848. backlight_on = true;
  849. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  850. }
  851. #endif
  852. PROFILING_END();
  853. }
  854. #else // MTK_KERNEL_POWER_OFF_CHARGING
  855. /* fast meta mode */
  856. if(g_boot_mode != META_BOOT)
  857. if (g_boot_mode != ALARM_BOOT && (g_boot_mode != FASTBOOT) && !backlight_on) {
  858. #ifndef MACH_FPGA_NO_DISPLAY
  859. PROFILING_START("show logo");
  860. mt_disp_show_boot_logo();
  861. PROFILING_END(); /* show logo */
  862. #endif
  863. }
  864. #endif // MTK_KERNEL_POWER_OFF_CHARGING
  865. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  866. if (!is_low_battery(0)) {
  867. #endif
  868. /*
  869. * Update LCM with framebuffer before
  870. * turning on backlight to avoid LCM noise if there is
  871. * no any logo showed on screen before.
  872. */
  873. if (!backlight_on) {
  874. logo_lk_t = ((unsigned int)get_timer(boot_time));
  875. #ifndef MACH_FPGA_NO_DISPLAY
  876. PROFILING_START("display update");
  877. mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
  878. PROFILING_END();
  879. #endif
  880. #ifndef MACH_FPGA
  881. PROFILING_START("backlight");
  882. mt65xx_backlight_on();
  883. PROFILING_END(); /* backlight */
  884. #endif
  885. }
  886. #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY
  887. }
  888. #endif
  889. #ifndef MACH_FPGA
  890. PROFILING_START("sw_env");
  891. sw_env();
  892. PROFILING_END();
  893. #endif
  894. // check and clear gpu dfd
  895. mfg_clear_dfd();
  896. PROFILING_END(); /* platform_init */
  897. }
  898. void platform_uninit(void)
  899. {
  900. #ifndef MACH_FPGA
  901. leds_deinit();
  902. platform_clear_all_on_mux();
  903. #endif
  904. platform_deinit_interrupts();
  905. return;
  906. }
  907. #ifdef ENABLE_L2_SHARING
  908. #define ADDR_CA7L_CACHE_CONFIG_MP(x) (CA7MCUCFG_BASE + 0x200 * x)
  909. #define L2C_SIZE_CFG_OFFSET 8
  910. #define L2C_SHARE_EN_OFFSET 12
  911. /* 4'b1111: 2048KB(not support)
  912. * 4'b0111: 1024KB(not support)
  913. * 4'b0011: 512KB
  914. * 4'b0001: 256KB
  915. * 4'b0000: 128KB (not support)
  916. */
  917. int is_l2_need_config(void)
  918. {
  919. volatile unsigned int cache_cfg, addr;
  920. addr = ADDR_CA7L_CACHE_CONFIG_MP(0);
  921. cache_cfg = DRV_Reg32(addr);
  922. cache_cfg = cache_cfg >> L2C_SIZE_CFG_OFFSET;
  923. /* only read 256KB need to be config.*/
  924. if ((cache_cfg &(0x7)) == 0x1) {
  925. return 1;
  926. }
  927. return 0;
  928. }
  929. void cluster_l2_share_enable(int cluster)
  930. {
  931. volatile unsigned int cache_cfg, addr;
  932. addr = ADDR_CA7L_CACHE_CONFIG_MP(cluster);
  933. /* set L2C size to 256KB */
  934. cache_cfg = DRV_Reg32(addr);
  935. cache_cfg &= (~0x7) << L2C_SIZE_CFG_OFFSET;
  936. cache_cfg |= 0x1 << L2C_SIZE_CFG_OFFSET;
  937. /* enable L2C_share_en. Sram only for other to use*/
  938. cache_cfg |= (0x1 << L2C_SHARE_EN_OFFSET);
  939. DRV_WriteReg32(addr, cache_cfg);
  940. }
  941. void cluster_l2_share_disable(int cluster)
  942. {
  943. volatile unsigned int cache_cfg, addr;
  944. addr = ADDR_CA7L_CACHE_CONFIG_MP(cluster);
  945. /* set L2C size to 512KB */
  946. cache_cfg = DRV_Reg32(addr);
  947. cache_cfg &= (~0x7) << L2C_SIZE_CFG_OFFSET;
  948. cache_cfg |= 0x3 << L2C_SIZE_CFG_OFFSET;
  949. DRV_WriteReg32(addr, cache_cfg);
  950. /* disable L2C_share_en. Sram only for cpu to use*/
  951. cache_cfg &= ~(0x1 << L2C_SHARE_EN_OFFSET);
  952. DRV_WriteReg32(addr, cache_cfg);
  953. }
  954. /* config L2 cache and sram to its size */
  955. void config_L2_size(void)
  956. {
  957. int cluster;
  958. if (is_l2_need_config()) {
  959. /*
  960. * Becuase mcu config is protected.
  961. * only can write in secutity mode
  962. */
  963. if (dev_info_nr_cpu() == 6) {
  964. cluster_l2_share_disable(0);
  965. cluster_l2_share_enable(1);
  966. }
  967. else {
  968. for (cluster = 0; cluster < 2; cluster++) {
  969. cluster_l2_share_disable(cluster);
  970. }
  971. }
  972. }
  973. }
  974. /* config SRAM back from L2 cache for DA relocation */
  975. void config_shared_SRAM_size(void)
  976. {
  977. int cluster;
  978. if (is_l2_need_config()) {
  979. /*
  980. * Becuase mcu config is protected.
  981. * only can write in secutity mode
  982. */
  983. for (cluster = 0; cluster < 2; cluster++) {
  984. cluster_l2_share_enable(cluster);
  985. }
  986. }
  987. }
  988. #endif
  989. void platform_sec_post_init(void)
  990. {
  991. unsigned int ret = 0;
  992. ret = crypto_hw_engine_disable();
  993. if (ret) {
  994. dprintf(CRITICAL, "[SEC] crypto engine HW disable fail\n");
  995. }
  996. /* Lock Device APC in LK */
  997. dprintf(CRITICAL, "[DEVAPC] sec_post_init\n");
  998. #if APUSYS_APC_TURN_ON
  999. if (g_boot_arg->g_apusys_status == APUSYS_NORMAL) {
  1000. mt_secure_call(MTK_SIP_BL_APUSYS_CONTROL_AARCH32, 0, 0, 0, 0);
  1001. }
  1002. #endif
  1003. #if DEVAPC_TURN_ON
  1004. dprintf(CRITICAL, "[DEVAPC] platform_sec_post_init - SMC call to ATF from LK\n");
  1005. #ifdef MTK_SMC_ID_MGMT
  1006. mt_secure_call(MTK_SIP_LK_DAPC_INIT, 0, 0, 0, 0);
  1007. #else
  1008. mt_secure_call(0x82000101, 0, 0, 0);
  1009. #endif
  1010. #endif
  1011. #if defined(MTK_TINYSYS_SCP_SUPPORT) || defined(MTK_AUDIODSP_SUPPORT)
  1012. tinysys_set_devapc_domain();
  1013. #endif
  1014. }
  1015. u32 get_devinfo_with_index(u32 index)
  1016. {
  1017. return internal_get_devinfo_with_index(index);
  1018. }
  1019. int platform_skip_hibernation(void)
  1020. {
  1021. switch (g_boot_arg->boot_reason) {
  1022. #if 0 // let schedule power on to go hiberantion bootup process
  1023. case BR_RTC:
  1024. #endif
  1025. case BR_WDT:
  1026. case BR_WDT_BY_PASS_PWK:
  1027. case BR_WDT_SW:
  1028. case BR_WDT_HW:
  1029. return 1;
  1030. }
  1031. return 0;
  1032. }
  1033. int is_meta_log_disable(void)
  1034. {
  1035. return g_boot_arg->meta_log_disable;
  1036. }