blob: 31ae179b211c5b2127e663eef08bf5f60db18fa4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Peng Fanf664c142015-08-13 10:55:34 +08002/*
3 * (C) Copyright 2009
4 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
Peng Fanf664c142015-08-13 10:55:34 +08005 */
6
7#ifndef _SYS_PROTO_H_
8#define _SYS_PROTO_H_
9
Jagan Tekie5f970b2017-02-24 15:45:12 +053010#include <asm/io.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020011#include <asm/mach-imx/regs-common.h>
Peng Fan415f8952020-05-01 22:08:34 +080012#include <asm/mach-imx/module_fuse.h>
Simon Glass1e268642020-05-10 11:39:55 -060013#include <linux/bitops.h>
Peng Fanf664c142015-08-13 10:55:34 +080014#include "../arch-imx/cpu.h"
15
Simon Glass1e268642020-05-10 11:39:55 -060016struct bd_info;
17
Peng Fanf664c142015-08-13 10:55:34 +080018#define soc_rev() (get_cpu_rev() & 0xFF)
19#define is_soc_rev(rev) (soc_rev() == rev)
20
21/* returns MXC_CPU_ value */
Peng Fan6e3a3802020-02-05 17:44:28 +080022#define cpu_type(rev) (((rev) >> 12) & 0x1ff)
Adrian Alonso1eec27c2015-09-02 13:54:12 -050023#define soc_type(rev) (((rev) >> 12) & 0xf0)
Peng Fanf664c142015-08-13 10:55:34 +080024/* both macros return/take MXC_CPU_ constants */
25#define get_cpu_type() (cpu_type(get_cpu_rev()))
Adrian Alonso1eec27c2015-09-02 13:54:12 -050026#define get_soc_type() (soc_type(get_cpu_rev()))
Peng Fanf664c142015-08-13 10:55:34 +080027#define is_cpu_type(cpu) (get_cpu_type() == cpu)
Adrian Alonso1eec27c2015-09-02 13:54:12 -050028#define is_soc_type(soc) (get_soc_type() == soc)
Peng Fanf664c142015-08-13 10:55:34 +080029
Peng Fan1e4e7622016-05-23 18:35:52 +080030#define is_mx6() (is_soc_type(MXC_SOC_MX6))
31#define is_mx7() (is_soc_type(MXC_SOC_MX7))
Peng Fan39945c12018-11-20 10:19:25 +000032#define is_imx8m() (is_soc_type(MXC_SOC_IMX8M))
Peng Fan36b65172018-10-18 14:28:16 +020033#define is_imx8() (is_soc_type(MXC_SOC_IMX8))
Peng Fanbbcd2c42022-07-26 16:40:39 +080034#define is_imx9() (is_soc_type(MXC_SOC_IMX9))
Giulio Benetti3d1a5732021-05-20 16:10:13 +020035#define is_imxrt() (is_soc_type(MXC_SOC_IMXRT))
Peng Fan1e4e7622016-05-23 18:35:52 +080036
Peng Fanf664c142015-08-13 10:55:34 +080037#define is_mx6dqp() (is_cpu_type(MXC_CPU_MX6QP) || is_cpu_type(MXC_CPU_MX6DP))
Peng Fan1e4e7622016-05-23 18:35:52 +080038#define is_mx6dq() (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D))
39#define is_mx6sdl() (is_cpu_type(MXC_CPU_MX6SOLO) || is_cpu_type(MXC_CPU_MX6DL))
Jagan Teki0d6d48b2016-10-08 18:00:11 +053040#define is_mx6dl() (is_cpu_type(MXC_CPU_MX6DL))
Peng Fan1e4e7622016-05-23 18:35:52 +080041#define is_mx6sx() (is_cpu_type(MXC_CPU_MX6SX))
42#define is_mx6sl() (is_cpu_type(MXC_CPU_MX6SL))
Jagan Teki0d6d48b2016-10-08 18:00:11 +053043#define is_mx6solo() (is_cpu_type(MXC_CPU_MX6SOLO))
Peng Fan1e4e7622016-05-23 18:35:52 +080044#define is_mx6ul() (is_cpu_type(MXC_CPU_MX6UL))
Peng Fanad69a062020-02-05 20:17:17 +080045#define is_mx6ull() (is_cpu_type(MXC_CPU_MX6ULL) || is_cpu_type(MXC_CPU_MX6ULZ))
Peng Fanc53d0c92019-08-08 09:55:52 +000046#define is_mx6ulz() (is_cpu_type(MXC_CPU_MX6ULZ))
Peng Fan4cfd7972016-12-11 19:24:20 +080047#define is_mx6sll() (is_cpu_type(MXC_CPU_MX6SLL))
Peng Fanf664c142015-08-13 10:55:34 +080048
Peng Fan98c57822017-02-22 16:21:46 +080049#define is_mx7ulp() (is_cpu_type(MXC_CPU_MX7ULP))
50
Peng Fan67815082020-02-05 17:34:54 +080051#define is_imx8mq() (is_cpu_type(MXC_CPU_IMX8MQ) || is_cpu_type(MXC_CPU_IMX8MD) || is_cpu_type(MXC_CPU_IMX8MQL))
52#define is_imx8md() (is_cpu_type(MXC_CPU_IMX8MD))
53#define is_imx8mql() (is_cpu_type(MXC_CPU_IMX8MQL))
Peng Fan3e1d1ea2019-08-26 08:11:46 +000054#define is_imx8qm() (is_cpu_type(MXC_CPU_IMX8QM))
Peng Fan5c2218a2021-08-07 16:00:31 +080055#define is_imx8ulp() (is_cpu_type(MXC_CPU_IMX8ULP))
Peng Fan2d22a992019-08-27 06:25:04 +000056#define is_imx8mm() (is_cpu_type(MXC_CPU_IMX8MM) || is_cpu_type(MXC_CPU_IMX8MML) ||\
57 is_cpu_type(MXC_CPU_IMX8MMD) || is_cpu_type(MXC_CPU_IMX8MMDL) || \
58 is_cpu_type(MXC_CPU_IMX8MMS) || is_cpu_type(MXC_CPU_IMX8MMSL))
59#define is_imx8mml() (is_cpu_type(MXC_CPU_IMX8MML))
60#define is_imx8mmd() (is_cpu_type(MXC_CPU_IMX8MMD))
61#define is_imx8mmdl() (is_cpu_type(MXC_CPU_IMX8MMDL))
62#define is_imx8mms() (is_cpu_type(MXC_CPU_IMX8MMS))
63#define is_imx8mmsl() (is_cpu_type(MXC_CPU_IMX8MMSL))
Peng Fan1a07d912020-02-05 17:39:27 +080064#define is_imx8mn() (is_cpu_type(MXC_CPU_IMX8MN) || is_cpu_type(MXC_CPU_IMX8MND) || \
65 is_cpu_type(MXC_CPU_IMX8MNS) || is_cpu_type(MXC_CPU_IMX8MNL) || \
Ye Li715180e2021-03-19 15:57:11 +080066 is_cpu_type(MXC_CPU_IMX8MNDL) || is_cpu_type(MXC_CPU_IMX8MNSL) || \
67 is_cpu_type(MXC_CPU_IMX8MNUD) || is_cpu_type(MXC_CPU_IMX8MNUS) || is_cpu_type(MXC_CPU_IMX8MNUQ))
Peng Fan1a07d912020-02-05 17:39:27 +080068#define is_imx8mnd() (is_cpu_type(MXC_CPU_IMX8MND))
69#define is_imx8mns() (is_cpu_type(MXC_CPU_IMX8MNS))
70#define is_imx8mnl() (is_cpu_type(MXC_CPU_IMX8MNL))
71#define is_imx8mndl() (is_cpu_type(MXC_CPU_IMX8MNDL))
72#define is_imx8mnsl() (is_cpu_type(MXC_CPU_IMX8MNSL))
Ye Li715180e2021-03-19 15:57:11 +080073#define is_imx8mnuq() (is_cpu_type(MXC_CPU_IMX8MNUQ))
74#define is_imx8mnud() (is_cpu_type(MXC_CPU_IMX8MNUD))
75#define is_imx8mnus() (is_cpu_type(MXC_CPU_IMX8MNUS))
Ye Lid2d754f2020-04-20 20:12:54 -070076#define is_imx8mp() (is_cpu_type(MXC_CPU_IMX8MP) || is_cpu_type(MXC_CPU_IMX8MPD) || \
Peng Fan4d54f5b2022-04-07 15:55:51 +080077 is_cpu_type(MXC_CPU_IMX8MPL) || is_cpu_type(MXC_CPU_IMX8MP6) || is_cpu_type(MXC_CPU_IMX8MPUL))
Ye Lid2d754f2020-04-20 20:12:54 -070078#define is_imx8mpd() (is_cpu_type(MXC_CPU_IMX8MPD))
79#define is_imx8mpl() (is_cpu_type(MXC_CPU_IMX8MPL))
Ye Lid2d754f2020-04-20 20:12:54 -070080#define is_imx8mp6() (is_cpu_type(MXC_CPU_IMX8MP6))
Peng Fan4d54f5b2022-04-07 15:55:51 +080081#define is_imx8mpul() (is_cpu_type(MXC_CPU_IMX8MPUL))
Peng Fan5d2f2062019-06-27 17:23:49 +080082
Peng Fan36b65172018-10-18 14:28:16 +020083#define is_imx8qxp() (is_cpu_type(MXC_CPU_IMX8QXP))
84
Peng Fanc3db3ad2023-04-28 12:08:32 +080085#define is_imx93() (is_cpu_type(MXC_CPU_IMX93) || is_cpu_type(MXC_CPU_IMX9331) || \
86 is_cpu_type(MXC_CPU_IMX9332) || is_cpu_type(MXC_CPU_IMX9351) || \
87 is_cpu_type(MXC_CPU_IMX9322) || is_cpu_type(MXC_CPU_IMX9321) || \
88 is_cpu_type(MXC_CPU_IMX9312) || is_cpu_type(MXC_CPU_IMX9311))
89#define is_imx9351() (is_cpu_type(MXC_CPU_IMX9351))
90#define is_imx9332() (is_cpu_type(MXC_CPU_IMX9332))
91#define is_imx9331() (is_cpu_type(MXC_CPU_IMX9331))
92#define is_imx9322() (is_cpu_type(MXC_CPU_IMX9322))
93#define is_imx9321() (is_cpu_type(MXC_CPU_IMX9321))
94#define is_imx9312() (is_cpu_type(MXC_CPU_IMX9312))
95#define is_imx9311() (is_cpu_type(MXC_CPU_IMX9311))
Peng Fanbbcd2c42022-07-26 16:40:39 +080096
Giulio Benetti3d1a5732021-05-20 16:10:13 +020097#define is_imxrt1020() (is_cpu_type(MXC_CPU_IMXRT1020))
98#define is_imxrt1050() (is_cpu_type(MXC_CPU_IMXRT1050))
99
Jagan Tekie5f970b2017-02-24 15:45:12 +0530100#ifdef CONFIG_MX6
Marek Vasut28c0b632020-08-05 15:34:04 +0200101#define IMX6_SRC_GPR10_BMODE BIT(28)
Marek Vasut6b17c852020-08-05 15:34:05 +0200102#define IMX6_SRC_GPR10_PERSIST_SECONDARY_BOOT BIT(30)
Jagan Tekie5f970b2017-02-24 15:45:12 +0530103
Jagan Teki32a71142017-02-24 15:45:14 +0530104#define IMX6_BMODE_MASK GENMASK(7, 0)
Harald Seiler808c5d62021-12-01 10:02:54 +0100105#define IMX6_BMODE_SHIFT 4
106#define IMX6_BMODE_EIM_MASK BIT(3)
107#define IMX6_BMODE_EIM_SHIFT 3
Jagan Teki32a71142017-02-24 15:45:14 +0530108#define IMX6_BMODE_SERIAL_ROM_MASK GENMASK(26, 24)
109#define IMX6_BMODE_SERIAL_ROM_SHIFT 24
110
111enum imx6_bmode_serial_rom {
112 IMX6_BMODE_ECSPI1,
113 IMX6_BMODE_ECSPI2,
114 IMX6_BMODE_ECSPI3,
115 IMX6_BMODE_ECSPI4,
116 IMX6_BMODE_ECSPI5,
117 IMX6_BMODE_I2C1,
118 IMX6_BMODE_I2C2,
119 IMX6_BMODE_I2C3,
120};
121
Harald Seiler808c5d62021-12-01 10:02:54 +0100122enum imx6_bmode_eim {
Jagan Teki32a71142017-02-24 15:45:14 +0530123 IMX6_BMODE_NOR,
Lukasz Majewski3234ef32019-01-03 23:50:51 +0100124 IMX6_BMODE_ONENAND,
Jagan Teki32a71142017-02-24 15:45:14 +0530125};
126
127enum imx6_bmode {
Harald Seiler808c5d62021-12-01 10:02:54 +0100128 IMX6_BMODE_EIM,
Stefan Agner53456f52017-08-15 17:49:42 -0700129#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
130 IMX6_BMODE_QSPI,
131 IMX6_BMODE_RESERVED,
132#else
133 IMX6_BMODE_RESERVED,
Jagan Teki32a71142017-02-24 15:45:14 +0530134 IMX6_BMODE_SATA,
Stefan Agner53456f52017-08-15 17:49:42 -0700135#endif
Jagan Teki32a71142017-02-24 15:45:14 +0530136 IMX6_BMODE_SERIAL_ROM,
137 IMX6_BMODE_SD,
138 IMX6_BMODE_ESD,
139 IMX6_BMODE_MMC,
140 IMX6_BMODE_EMMC,
Eran Matityahu5fa7ca62017-12-14 20:20:02 +0200141 IMX6_BMODE_NAND_MIN,
142 IMX6_BMODE_NAND_MAX = 0xf,
Jagan Teki32a71142017-02-24 15:45:14 +0530143};
144
Jagan Tekie5f970b2017-02-24 15:45:12 +0530145u32 imx6_src_get_boot_mode(void);
Breno Limaf22b1092017-08-24 10:00:16 -0300146void gpr_init(void);
147
Jagan Tekie5f970b2017-02-24 15:45:12 +0530148#endif /* CONFIG_MX6 */
149
Marek Vasut28c0b632020-08-05 15:34:04 +0200150#ifdef CONFIG_MX7
151#define IMX7_SRC_GPR10_BMODE BIT(28)
Marek Vasut6b17c852020-08-05 15:34:05 +0200152#define IMX7_SRC_GPR10_PERSIST_SECONDARY_BOOT BIT(30)
Marek Vasut28c0b632020-08-05 15:34:04 +0200153#endif
154
Igor Opaniukb65af982019-12-30 13:56:44 +0200155/* address translation table */
156struct rproc_att {
157 u32 da; /* device address (From Cortex M4 view) */
158 u32 sa; /* system bus address */
159 u32 size; /* size of reg range */
160};
161
Marek Vasutddc59352022-12-13 05:46:07 +0100162const struct rproc_att *imx_bootaux_get_hostmap(void);
163
Peng Fan36986792019-09-16 03:09:31 +0000164struct rom_api {
165 u16 ver;
166 u16 tag;
167 u32 reserved1;
168 u32 (*download_image)(u8 *dest, u32 offset, u32 size, u32 xor);
169 u32 (*query_boot_infor)(u32 info_type, u32 *info, u32 xor);
170};
171
172enum boot_dev_type_e {
173 BT_DEV_TYPE_SD = 1,
174 BT_DEV_TYPE_MMC = 2,
175 BT_DEV_TYPE_NAND = 3,
176 BT_DEV_TYPE_FLEXSPINOR = 4,
Marek Vasut31b3bc42022-03-25 18:59:28 +0100177 BT_DEV_TYPE_SPI_NOR = 6,
Peng Fan36986792019-09-16 03:09:31 +0000178
179 BT_DEV_TYPE_USB = 0xE,
180 BT_DEV_TYPE_MEM_DEV = 0xF,
181
182 BT_DEV_TYPE_INVALID = 0xFF
183};
184
Ye Li504514b2023-02-03 18:21:47 +0800185enum boot_stage_type {
186 BT_STAGE_PRIMARY = 0x6,
187 BT_STAGE_SECONDARY = 0x9,
188 BT_STAGE_RECOVERY = 0xa,
189 BT_STAGE_USB = 0x5,
190};
191
Peng Fan36986792019-09-16 03:09:31 +0000192#define QUERY_ROM_VER 1
193#define QUERY_BT_DEV 2
194#define QUERY_PAGE_SZ 3
195#define QUERY_IVT_OFF 4
196#define QUERY_BT_STAGE 5
197#define QUERY_IMG_OFF 6
198
199#define ROM_API_OKAY 0xF0
200
201extern struct rom_api *g_rom_api;
Peng Fan5de0fc02022-07-26 16:40:48 +0800202extern unsigned long rom_pointer[];
203
204ulong spl_romapi_raw_seekable_read(u32 offset, u32 size, void *buf);
205ulong spl_romapi_get_uboot_base(u32 image_offset, u32 rom_bt_dev);
Rasmus Villemoesae1a8482022-06-20 10:53:19 +0200206
207u32 rom_api_download_image(u8 *dest, u32 offset, u32 size);
208u32 rom_api_query_boot_infor(u32 info_type, u32 *info);
209
Peng Fan101ef622021-08-07 16:00:32 +0800210/* For i.MX ULP */
211#define BT0CFG_LPBOOT_MASK 0x1
212#define BT0CFG_DUALBOOT_MASK 0x2
213
214enum bt_mode {
215 LOW_POWER_BOOT, /* LP_BT = 1 */
216 DUAL_BOOT, /* LP_BT = 0, DUAL_BT = 1 */
217 SINGLE_BOOT /* LP_BT = 0, DUAL_BT = 0 */
218};
219
Peng Fanf664c142015-08-13 10:55:34 +0800220u32 get_nr_cpus(void);
221u32 get_cpu_rev(void);
222u32 get_cpu_speed_grade_hz(void);
223u32 get_cpu_temp_grade(int *minc, int *maxc);
224const char *get_imx_type(u32 imxtype);
225u32 imx_ddr_size(void);
226void sdelay(unsigned long);
227void set_chipselect_size(int const);
228
Adrian Alonsoee7c4ca2015-09-02 13:54:15 -0500229void init_aips(void);
230void init_src(void);
Bryan O'Donoghue0290ea02018-04-05 19:46:06 +0100231void init_snvs(void);
Fabio Estevam5f79d462017-11-23 10:55:33 -0200232void imx_wdog_disable_powerdown(void);
Adrian Alonsoee7c4ca2015-09-02 13:54:15 -0500233
Marcel Ziswilera45585b2020-10-22 11:21:40 +0300234void board_mem_get_layout(u64 *phys_sdram_1_start,
235 u64 *phys_sdram_1_size,
236 u64 *phys_sdram_2_start,
237 u64 *phys_sdram_2_size);
238
Ye Lic07ac742023-06-15 18:09:20 +0800239int arch_auxiliary_core_up(u32 core_id, ulong boot_private_data);
Igor Opaniukcbee9452019-12-03 14:04:47 +0200240int arch_auxiliary_core_check_up(u32 core_id);
241
Diego Dorta29f702e2017-09-21 15:10:03 -0300242int board_mmc_get_env_dev(int devno);
243
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200244int nxp_board_rev(void);
245char nxp_board_rev_string(void);
246
Peng Fanf664c142015-08-13 10:55:34 +0800247/*
248 * Initializes on-chip ethernet controllers.
249 * to override, implement board_eth_init()
250 */
Simon Glass1e268642020-05-10 11:39:55 -0600251int fecmxc_initialize(struct bd_info *bis);
Peng Fanf664c142015-08-13 10:55:34 +0800252u32 get_ahb_clk(void);
253u32 get_periph_clk(void);
254
Peng Fan5f8dbf52015-10-29 15:54:49 +0800255void lcdif_power_down(void);
256
Peng Fanf664c142015-08-13 10:55:34 +0800257int mxs_reset_block(struct mxs_register_32 *reg);
258int mxs_wait_mask_set(struct mxs_register_32 *reg, u32 mask, u32 timeout);
259int mxs_wait_mask_clr(struct mxs_register_32 *reg, u32 mask, u32 timeout);
Peng Fanaa3b9072018-01-10 13:20:23 +0800260
Peng Fan4de11282022-04-06 14:30:25 +0800261void board_late_mmc_env_init(void);
262
Peng Fanaa3b9072018-01-10 13:20:23 +0800263unsigned long call_imx_sip(unsigned long id, unsigned long reg0,
Ye Lie5e91092019-10-26 16:24:03 +0200264 unsigned long reg1, unsigned long reg2,
265 unsigned long reg3);
Peng Fana5060092019-04-12 07:54:50 +0000266unsigned long call_imx_sip_ret2(unsigned long id, unsigned long reg0,
267 unsigned long *reg1, unsigned long reg2,
268 unsigned long reg3);
Ye Li89e2f952020-05-03 22:41:19 +0800269
270void imx_get_mac_from_fuse(int dev_id, unsigned char *mac);
Sven Schwermer2645cfa2022-01-02 20:36:56 +0100271
272#if defined(CONFIG_MX6) || defined(CONFIG_MX7) || defined(CONFIG_MX7ULP)
273void enable_ca7_smp(void);
274#endif
275
Peng Fan20402062022-07-26 16:40:36 +0800276enum boot_device get_boot_device(void);
277
Peng Fanf664c142015-08-13 10:55:34 +0800278#endif