blob: 261ec15e1b0ad95c225abdc7bbe13666c8fe9118 [file] [log] [blame]
Tom Rini4549e782018-05-06 18:27:01 -04001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Patrick Delaunayf8598d92018-03-12 10:46:18 +01002/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunayf8598d92018-03-12 10:46:18 +01004 */
Patrick Delaunay873bf442020-11-06 19:01:59 +01005
6#define LOG_CATEGORY LOGC_BOARD
7
Patrice Chotard395f1292019-02-12 16:50:40 +01008#include <common.h>
9#include <adc.h>
Patrick Delaunay8e194772019-06-21 15:26:40 +020010#include <bootm.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020011#include <clk.h>
Patrick Delaunayd1a597f2019-07-30 19:16:44 +020012#include <config.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020013#include <dm.h>
Simon Glass3a7d5572019-08-01 09:46:42 -060014#include <env.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060015#include <env_internal.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060016#include <fdt_support.h>
Patrick Delaunayc31000c2019-03-29 15:42:23 +010017#include <g_dnl.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020018#include <generic-phy.h>
Simon Glassdb41d652019-12-28 10:45:07 -070019#include <hang.h>
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +010020#include <i2c.h>
Simon Glass52559322019-11-14 12:57:46 -070021#include <init.h>
Patrick Delaunayd461f102019-02-12 11:44:41 +010022#include <led.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060023#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -070024#include <malloc.h>
Patrick Delaunayd461f102019-02-12 11:44:41 +010025#include <misc.h>
Patrick Delaunaye81f8d12019-07-02 13:26:07 +020026#include <mtd_node.h>
Simon Glass90526e92020-05-10 11:39:56 -060027#include <net.h>
Patrick Delaunay53e3d522019-08-01 11:29:03 +020028#include <netdev.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020029#include <phy.h>
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +020030#include <remoteproc.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020031#include <reset.h>
Patrick Delaunay45459742019-02-27 17:01:24 +010032#include <syscon.h>
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +010033#include <usb.h>
Patrick Delaunaydd281082019-07-30 19:16:39 +020034#include <watchdog.h>
Simon Glass401d1c42020-10-30 21:38:53 -060035#include <asm/global_data.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020036#include <asm/io.h>
Patrick Delaunay842ebb52019-02-27 17:01:18 +010037#include <asm/gpio.h>
Patrick Delaunay45459742019-02-27 17:01:24 +010038#include <asm/arch/stm32.h>
Patrice Chotard7f90cd62019-05-02 18:36:01 +020039#include <asm/arch/sys_proto.h>
Patrick Delaunaye81f8d12019-07-02 13:26:07 +020040#include <jffs2/load_kernel.h>
Simon Glasscd93d622020-05-10 11:40:13 -060041#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060042#include <linux/delay.h>
Simon Glass61b29b82020-02-03 07:36:15 -070043#include <linux/err.h>
Patrick Delaunay5ef642c2020-04-22 14:29:16 +020044#include <linux/iopoll.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020045#include <power/regulator.h>
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +010046#include <usb/dwc2_udc.h>
Patrick Delaunayf8598d92018-03-12 10:46:18 +010047
Patrick Delaunay03fb0382020-06-29 10:34:06 +020048#include "../../st/common/stusb160x.h"
49
Patrick Delaunay45459742019-02-27 17:01:24 +010050/* SYSCFG registers */
51#define SYSCFG_BOOTR 0x00
52#define SYSCFG_PMCSETR 0x04
53#define SYSCFG_IOCTRLSETR 0x18
54#define SYSCFG_ICNR 0x1C
55#define SYSCFG_CMPCR 0x20
56#define SYSCFG_CMPENSETR 0x24
57#define SYSCFG_PMCCLRR 0x44
58
59#define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0)
60#define SYSCFG_BOOTR_BOOTPD_SHIFT 4
61
62#define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0)
63#define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1)
64#define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2)
65#define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3)
66#define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4)
67
68#define SYSCFG_CMPCR_SW_CTRL BIT(1)
69#define SYSCFG_CMPCR_READY BIT(8)
70
71#define SYSCFG_CMPENSETR_MPU_EN BIT(0)
72
73#define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16)
74#define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17)
75
76#define SYSCFG_PMCSETR_ETH_SELMII BIT(20)
77
78#define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21)
Christophe Roullieredacf262019-05-17 15:08:43 +020079#define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0
80#define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21)
81#define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23)
Patrick Delaunay45459742019-02-27 17:01:24 +010082
Patrick Delaunayf8598d92018-03-12 10:46:18 +010083/*
84 * Get a global data pointer
85 */
86DECLARE_GLOBAL_DATA_PTR;
87
Patrice Chotard28c064e2019-04-30 18:09:38 +020088#define USB_LOW_THRESHOLD_UV 200000
Patrice Chotard395f1292019-02-12 16:50:40 +010089#define USB_WARNING_LOW_THRESHOLD_UV 660000
90#define USB_START_LOW_THRESHOLD_UV 1230000
Patrice Chotard28c064e2019-04-30 18:09:38 +020091#define USB_START_HIGH_THRESHOLD_UV 2150000
Patrice Chotard395f1292019-02-12 16:50:40 +010092
Patrick Delaunayd1a4b092020-05-25 12:19:46 +020093int board_early_init_f(void)
94{
95 /* nothing to do, only used in SPL */
96 return 0;
97}
98
Patrick Delaunayd461f102019-02-12 11:44:41 +010099int checkboard(void)
100{
101 int ret;
102 char *mode;
103 u32 otp;
104 struct udevice *dev;
105 const char *fdt_compat;
106 int fdt_compat_len;
107
Patrick Delaunay43df0a12020-03-18 09:22:49 +0100108 if (IS_ENABLED(CONFIG_TFABOOT))
Patrick Delaunayd461f102019-02-12 11:44:41 +0100109 mode = "trusted";
110 else
111 mode = "basic";
112
Patrick Delaunayd461f102019-02-12 11:44:41 +0100113 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
114 &fdt_compat_len);
Patrick Delaunay873bf442020-11-06 19:01:59 +0100115
116 log_info("Board: stm32mp1 in %s mode (%s)\n", mode,
117 fdt_compat && fdt_compat_len ? fdt_compat : "");
Patrick Delaunayd461f102019-02-12 11:44:41 +0100118
Patrick Delaunay888dc682020-03-24 09:05:00 +0100119 /* display the STMicroelectronics board identification */
Patrick Delaunay61f6d462020-02-12 19:37:42 +0100120 if (CONFIG_IS_ENABLED(CMD_STBOARD)) {
121 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700122 DM_DRIVER_GET(stm32mp_bsec),
Patrick Delaunay61f6d462020-02-12 19:37:42 +0100123 &dev);
124 if (!ret)
125 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
126 &otp, sizeof(otp));
127 if (ret > 0 && otp)
Patrick Delaunay873bf442020-11-06 19:01:59 +0100128 log_info("Board: MB%04x Var%d.%d Rev.%c-%02d\n",
129 otp >> 16,
130 (otp >> 12) & 0xF,
131 (otp >> 4) & 0xF,
132 ((otp >> 8) & 0xF) - 1 + 'A',
133 otp & 0xF);
Patrick Delaunayd461f102019-02-12 11:44:41 +0100134 }
135
136 return 0;
137}
138
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100139static void board_key_check(void)
140{
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100141 ofnode node;
142 struct gpio_desc gpio;
143 enum forced_boot_mode boot_mode = BOOT_NORMAL;
144
Patrick Delaunay00bac2a2020-07-31 16:31:42 +0200145 if (!IS_ENABLED(CONFIG_FASTBOOT) && !IS_ENABLED(CONFIG_CMD_STM32PROG))
146 return;
147
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100148 node = ofnode_path("/config");
149 if (!ofnode_valid(node)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100150 log_debug("no /config node?\n");
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100151 return;
152 }
Patrick Delaunay00bac2a2020-07-31 16:31:42 +0200153 if (IS_ENABLED(CONFIG_FASTBOOT)) {
154 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
155 &gpio, GPIOD_IS_IN)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100156 log_debug("could not find a /config/st,fastboot-gpios\n");
Patrick Delaunay00bac2a2020-07-31 16:31:42 +0200157 } else {
158 if (dm_gpio_get_value(&gpio)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100159 log_notice("Fastboot key pressed, ");
Patrick Delaunay00bac2a2020-07-31 16:31:42 +0200160 boot_mode = BOOT_FASTBOOT;
161 }
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100162
Patrick Delaunay00bac2a2020-07-31 16:31:42 +0200163 dm_gpio_free(NULL, &gpio);
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100164 }
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100165 }
Patrick Delaunay00bac2a2020-07-31 16:31:42 +0200166 if (IS_ENABLED(CONFIG_CMD_STM32PROG)) {
167 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
168 &gpio, GPIOD_IS_IN)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100169 log_debug("could not find a /config/st,stm32prog-gpios\n");
Patrick Delaunay00bac2a2020-07-31 16:31:42 +0200170 } else {
171 if (dm_gpio_get_value(&gpio)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100172 log_notice("STM32Programmer key pressed, ");
Patrick Delaunay00bac2a2020-07-31 16:31:42 +0200173 boot_mode = BOOT_STM32PROG;
174 }
175 dm_gpio_free(NULL, &gpio);
176 }
177 }
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100178 if (boot_mode != BOOT_NORMAL) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100179 log_notice("entering download mode...\n");
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100180 clrsetbits_le32(TAMP_BOOT_CONTEXT,
181 TAMP_BOOT_FORCED_MASK,
182 boot_mode);
183 }
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100184}
185
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100186int g_dnl_board_usb_cable_connected(void)
Patrice Chotard4c834b92018-08-10 17:12:14 +0200187{
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100188 struct udevice *dwc2_udc_otg;
Patrice Chotard4c834b92018-08-10 17:12:14 +0200189 int ret;
190
Patrick Delaunay6a8713b2020-07-31 16:31:43 +0200191 if (!IS_ENABLED(CONFIG_USB_GADGET_DWC2_OTG))
192 return -ENODEV;
193
Patrick Delaunay03fb0382020-06-29 10:34:06 +0200194 /* if typec stusb160x is present, means DK1 or DK2 board */
195 ret = stusb160x_cable_connected();
196 if (ret >= 0)
197 return ret;
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +0100198
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100199 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
Simon Glass65e25be2020-12-28 20:34:56 -0700200 DM_DRIVER_GET(dwc2_udc_otg),
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100201 &dwc2_udc_otg);
Patrick Delaunay873bf442020-11-06 19:01:59 +0100202 if (ret) {
203 log_debug("dwc2_udc_otg init failed\n");
204 return ret;
205 }
Patrice Chotard4c834b92018-08-10 17:12:14 +0200206
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100207 return dwc2_udc_B_session_valid(dwc2_udc_otg);
Patrice Chotard4c834b92018-08-10 17:12:14 +0200208}
Patrick Delaunayfb90fcf2019-09-13 15:24:17 +0200209
Patrick Delaunay6a8713b2020-07-31 16:31:43 +0200210#ifdef CONFIG_USB_GADGET_DOWNLOAD
Patrick Delaunayfb90fcf2019-09-13 15:24:17 +0200211#define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
212#define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
213
214int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
215{
Patrick Delaunay6a8713b2020-07-31 16:31:43 +0200216 if (IS_ENABLED(CONFIG_DFU_OVER_USB) &&
217 !strcmp(name, "usb_dnl_dfu"))
Patrick Delaunayfb90fcf2019-09-13 15:24:17 +0200218 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
Patrick Delaunay6a8713b2020-07-31 16:31:43 +0200219 else if (IS_ENABLED(CONFIG_FASTBOOT) &&
220 !strcmp(name, "usb_dnl_fastboot"))
Patrick Delaunayfb90fcf2019-09-13 15:24:17 +0200221 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
222 &dev->idProduct);
223 else
224 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
225
226 return 0;
227}
Patrick Delaunay6a8713b2020-07-31 16:31:43 +0200228#endif /* CONFIG_USB_GADGET_DOWNLOAD */
Patrice Chotard4c834b92018-08-10 17:12:14 +0200229
Patrice Chotard395f1292019-02-12 16:50:40 +0100230static int get_led(struct udevice **dev, char *led_string)
231{
232 char *led_name;
233 int ret;
234
235 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
236 if (!led_name) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100237 log_debug("could not find %s config string\n", led_string);
Patrice Chotard395f1292019-02-12 16:50:40 +0100238 return -ENOENT;
239 }
240 ret = led_get_by_label(led_name, dev);
241 if (ret) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100242 log_debug("get=%d\n", ret);
Patrice Chotard395f1292019-02-12 16:50:40 +0100243 return ret;
244 }
245
246 return 0;
247}
248
249static int setup_led(enum led_state_t cmd)
250{
251 struct udevice *dev;
252 int ret;
253
Patrick Delaunay0c952952020-04-22 14:29:12 +0200254 if (!CONFIG_IS_ENABLED(LED))
255 return 0;
256
Patrice Chotard395f1292019-02-12 16:50:40 +0100257 ret = get_led(&dev, "u-boot,boot-led");
258 if (ret)
259 return ret;
260
261 ret = led_set_state(dev, cmd);
262 return ret;
263}
Patrick Delaunaydd281082019-07-30 19:16:39 +0200264
265static void __maybe_unused led_error_blink(u32 nb_blink)
266{
Patrick Delaunaydd281082019-07-30 19:16:39 +0200267 int ret;
268 struct udevice *led;
269 u32 i;
Patrick Delaunaydd281082019-07-30 19:16:39 +0200270
271 if (!nb_blink)
272 return;
273
Patrick Delaunay0c952952020-04-22 14:29:12 +0200274 if (CONFIG_IS_ENABLED(LED)) {
275 ret = get_led(&led, "u-boot,error-led");
276 if (!ret) {
277 /* make u-boot,error-led blinking */
278 /* if U32_MAX and 125ms interval, for 17.02 years */
279 for (i = 0; i < 2 * nb_blink; i++) {
280 led_set_state(led, LEDST_TOGGLE);
281 mdelay(125);
282 WATCHDOG_RESET();
283 }
284 led_set_state(led, LEDST_ON);
Patrick Delaunaydd281082019-07-30 19:16:39 +0200285 }
286 }
Patrick Delaunaydd281082019-07-30 19:16:39 +0200287
288 /* infinite: the boot process must be stopped */
289 if (nb_blink == U32_MAX)
290 hang();
291}
Patrice Chotard395f1292019-02-12 16:50:40 +0100292
Patrice Chotard42082bc2020-10-16 09:28:59 +0200293static int adc_measurement(ofnode node, int adc_count, int *min_uV, int *max_uV)
Patrice Chotard395f1292019-02-12 16:50:40 +0100294{
295 struct ofnode_phandle_args adc_args;
296 struct udevice *adc;
Patrice Chotard395f1292019-02-12 16:50:40 +0100297 unsigned int raw;
Patrice Chotard42082bc2020-10-16 09:28:59 +0200298 int ret, uV;
299 int i;
Patrice Chotard395f1292019-02-12 16:50:40 +0100300
301 for (i = 0; i < adc_count; i++) {
302 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
303 "#io-channel-cells", 0, i,
304 &adc_args)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100305 log_debug("can't find /config/st,adc_usb_pd\n");
Patrice Chotard395f1292019-02-12 16:50:40 +0100306 return 0;
307 }
308
309 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
310 &adc);
311
312 if (ret) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100313 log_err("Can't get adc device(%d)\n", ret);
Patrice Chotard395f1292019-02-12 16:50:40 +0100314 return ret;
315 }
316
317 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
318 &raw);
319 if (ret) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100320 log_err("single shot failed for %s[%d]!\n",
321 adc->name, adc_args.args[0]);
Patrice Chotard395f1292019-02-12 16:50:40 +0100322 return ret;
323 }
324 /* Convert to uV */
325 if (!adc_raw_to_uV(adc, raw, &uV)) {
Patrice Chotard42082bc2020-10-16 09:28:59 +0200326 if (uV > *max_uV)
327 *max_uV = uV;
328 if (uV < *min_uV)
329 *min_uV = uV;
Patrick Delaunay873bf442020-11-06 19:01:59 +0100330 log_debug("%s[%02d] = %u, %d uV\n",
331 adc->name, adc_args.args[0], raw, uV);
Patrice Chotard395f1292019-02-12 16:50:40 +0100332 } else {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100333 log_err("Can't get uV value for %s[%d]\n",
334 adc->name, adc_args.args[0]);
Patrice Chotard395f1292019-02-12 16:50:40 +0100335 }
336 }
337
Patrice Chotard42082bc2020-10-16 09:28:59 +0200338 return 0;
339}
340
341static int board_check_usb_power(void)
342{
343 ofnode node;
344 int max_uV = 0;
345 int min_uV = USB_START_HIGH_THRESHOLD_UV;
346 int adc_count, ret;
347 u32 nb_blink;
348 u8 i;
349
Patrick Delaunay2214d5e2021-04-06 09:57:54 +0200350 if (!IS_ENABLED(CONFIG_ADC))
351 return -ENODEV;
352
Patrice Chotard42082bc2020-10-16 09:28:59 +0200353 node = ofnode_path("/config");
354 if (!ofnode_valid(node)) {
355 log_debug("no /config node?\n");
356 return -ENOENT;
357 }
358
Patrice Chotard395f1292019-02-12 16:50:40 +0100359 /*
Patrice Chotard42082bc2020-10-16 09:28:59 +0200360 * Retrieve the ADC channels devices and get measurement
361 * for each of them
Patrice Chotard395f1292019-02-12 16:50:40 +0100362 */
Patrice Chotard42082bc2020-10-16 09:28:59 +0200363 adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
364 "#io-channel-cells", 0);
365 if (adc_count < 0) {
366 if (adc_count == -ENOENT)
367 return 0;
368
369 log_err("Can't find adc channel (%d)\n", adc_count);
370
371 return adc_count;
372 }
373
374 /* perform maximum of 2 ADC measurements to detect power supply current */
375 for (i = 0; i < 2; i++) {
Patrick Delaunay2214d5e2021-04-06 09:57:54 +0200376 ret = adc_measurement(node, adc_count, &min_uV, &max_uV);
Patrice Chotard42082bc2020-10-16 09:28:59 +0200377 if (ret)
378 return ret;
379
380 /*
381 * If highest value is inside 1.23 Volts and 2.10 Volts, that means
382 * board is plugged on an USB-C 3A power supply and boot process can
383 * continue.
384 */
385 if (max_uV > USB_START_LOW_THRESHOLD_UV &&
386 max_uV <= USB_START_HIGH_THRESHOLD_UV &&
387 min_uV <= USB_LOW_THRESHOLD_UV)
388 return 0;
389
390 if (i == 0) {
391 log_err("Previous ADC measurements was not the one expected, retry in 20ms\n");
392 mdelay(20); /* equal to max tPDDebounce duration (min 10ms - max 20ms) */
393 }
394 }
Patrice Chotard395f1292019-02-12 16:50:40 +0100395
Patrick Delaunay873bf442020-11-06 19:01:59 +0100396 log_notice("****************************************************\n");
Patrice Chotard28c064e2019-04-30 18:09:38 +0200397 /*
398 * If highest and lowest value are either both below
399 * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
400 * means USB TYPE-C is in unattached mode, this is an issue, make
401 * u-boot,error-led blinking and stop boot process.
402 */
403 if ((max_uV > USB_LOW_THRESHOLD_UV &&
404 min_uV > USB_LOW_THRESHOLD_UV) ||
405 (max_uV <= USB_LOW_THRESHOLD_UV &&
406 min_uV <= USB_LOW_THRESHOLD_UV)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100407 log_notice("* ERROR USB TYPE-C connection in unattached mode *\n");
408 log_notice("* Check that USB TYPE-C cable is correctly plugged *\n");
Patrice Chotard28c064e2019-04-30 18:09:38 +0200409 /* with 125ms interval, led will blink for 17.02 years ....*/
410 nb_blink = U32_MAX;
411 }
412
413 if (max_uV > USB_LOW_THRESHOLD_UV &&
414 max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
415 min_uV <= USB_LOW_THRESHOLD_UV) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100416 log_notice("* WARNING 500mA power supply detected *\n");
Patrice Chotard395f1292019-02-12 16:50:40 +0100417 nb_blink = 2;
Patrice Chotard28c064e2019-04-30 18:09:38 +0200418 }
419
420 if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
421 max_uV <= USB_START_LOW_THRESHOLD_UV &&
422 min_uV <= USB_LOW_THRESHOLD_UV) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100423 log_notice("* WARNING 1.5A power supply detected *\n");
Patrice Chotard395f1292019-02-12 16:50:40 +0100424 nb_blink = 3;
425 }
426
Patrice Chotard28c064e2019-04-30 18:09:38 +0200427 /*
428 * If highest value is above 2.15 Volts that means that the USB TypeC
429 * supplies more than 3 Amp, this is not compliant with TypeC specification
430 */
431 if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100432 log_notice("* USB TYPE-C charger not compliant with *\n");
433 log_notice("* specification *\n");
434 log_notice("****************************************************\n\n");
Patrice Chotard28c064e2019-04-30 18:09:38 +0200435 /* with 125ms interval, led will blink for 17.02 years ....*/
436 nb_blink = U32_MAX;
437 } else {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100438 log_notice("* Current too low, use a 3A power supply! *\n");
439 log_notice("****************************************************\n\n");
Patrice Chotard28c064e2019-04-30 18:09:38 +0200440 }
Patrice Chotard395f1292019-02-12 16:50:40 +0100441
Patrick Delaunaydd281082019-07-30 19:16:39 +0200442 led_error_blink(nb_blink);
Patrice Chotard395f1292019-02-12 16:50:40 +0100443
444 return 0;
445}
446
Patrick Delaunay45459742019-02-27 17:01:24 +0100447static void sysconf_init(void)
448{
Patrick Delaunay45459742019-02-27 17:01:24 +0100449 u8 *syscfg;
Patrick Delaunay45459742019-02-27 17:01:24 +0100450 struct udevice *pwr_dev;
451 struct udevice *pwr_reg;
452 struct udevice *dev;
Patrick Delaunay45459742019-02-27 17:01:24 +0100453 u32 otp = 0;
Patrick Delaunay5ef642c2020-04-22 14:29:16 +0200454 int ret;
455 u32 bootr, val;
Patrick Delaunay45459742019-02-27 17:01:24 +0100456
457 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
458
459 /* interconnect update : select master using the port 1 */
460 /* LTDC = AXI_M9 */
461 /* GPU = AXI_M8 */
462 /* today information is hardcoded in U-Boot */
463 writel(BIT(9), syscfg + SYSCFG_ICNR);
464
465 /* disable Pull-Down for boot pin connected to VDD */
466 bootr = readl(syscfg + SYSCFG_BOOTR);
467 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
468 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
469 writel(bootr, syscfg + SYSCFG_BOOTR);
470
Patrick Delaunay45459742019-02-27 17:01:24 +0100471 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
472 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
473 * The customer will have to disable this for low frequencies
474 * or if AFMUX is selected but the function not used, typically for
475 * TRACE. Otherwise, impact on power consumption.
476 *
477 * WARNING:
478 * enabling High Speed mode while VDD>2.7V
479 * with the OTP product_below_2v5 (OTP 18, BIT 13)
480 * erroneously set to 1 can damage the IC!
481 * => U-Boot set the register only if VDD < 2.7V (in DT)
482 * but this value need to be consistent with board design
483 */
Patrick Delaunay5e959ab2019-07-30 19:16:42 +0200484 ret = uclass_get_device_by_driver(UCLASS_PMIC,
Simon Glass65e25be2020-12-28 20:34:56 -0700485 DM_DRIVER_GET(stm32mp_pwr_pmic),
Patrick Delaunay5e959ab2019-07-30 19:16:42 +0200486 &pwr_dev);
Patrick Delaunay3434bbe2020-07-31 16:31:45 +0200487 if (!ret && IS_ENABLED(CONFIG_DM_REGULATOR)) {
Patrick Delaunay45459742019-02-27 17:01:24 +0100488 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700489 DM_DRIVER_GET(stm32mp_bsec),
Patrick Delaunay45459742019-02-27 17:01:24 +0100490 &dev);
491 if (ret) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100492 log_err("Can't find stm32mp_bsec driver\n");
Patrick Delaunay45459742019-02-27 17:01:24 +0100493 return;
494 }
495
496 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
Patrick Delaunayff6618e2019-08-02 13:08:06 +0200497 if (ret > 0)
Patrick Delaunay45459742019-02-27 17:01:24 +0100498 otp = otp & BIT(13);
499
Patrick Delaunay5e959ab2019-07-30 19:16:42 +0200500 /* get VDD = vdd-supply */
501 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
Patrick Delaunay45459742019-02-27 17:01:24 +0100502 &pwr_reg);
503
504 /* check if VDD is Low Voltage */
505 if (!ret) {
506 if (regulator_get_value(pwr_reg) < 2700000) {
507 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
508 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
509 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
510 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
511 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
512 syscfg + SYSCFG_IOCTRLSETR);
513
514 if (!otp)
Patrick Delaunay873bf442020-11-06 19:01:59 +0100515 log_err("product_below_2v5=0: HSLVEN protected by HW\n");
Patrick Delaunay45459742019-02-27 17:01:24 +0100516 } else {
517 if (otp)
Patrick Delaunay873bf442020-11-06 19:01:59 +0100518 log_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
Patrick Delaunay45459742019-02-27 17:01:24 +0100519 }
520 } else {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100521 log_debug("VDD unknown");
Patrick Delaunay45459742019-02-27 17:01:24 +0100522 }
523 }
Patrick Delaunay45459742019-02-27 17:01:24 +0100524
525 /* activate automatic I/O compensation
526 * warning: need to ensure CSI enabled and ready in clock driver
527 */
528 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
529
Patrick Delaunay5ef642c2020-04-22 14:29:16 +0200530 /* poll until ready (1s timeout) */
531 ret = readl_poll_timeout(syscfg + SYSCFG_CMPCR, val,
532 val & SYSCFG_CMPCR_READY,
533 1000000);
534 if (ret) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100535 log_err("SYSCFG: I/O compensation failed, timeout.\n");
Patrick Delaunay5ef642c2020-04-22 14:29:16 +0200536 led_error_blink(10);
537 }
538
Patrick Delaunay45459742019-02-27 17:01:24 +0100539 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
Patrick Delaunay45459742019-02-27 17:01:24 +0100540}
541
Patrick Delaunayd573e462019-07-30 19:16:38 +0200542/* Fix to make I2C1 usable on DK2 for touchscreen usage in kernel */
543static int dk2_i2c1_fix(void)
544{
545 ofnode node;
546 struct gpio_desc hdmi, audio;
547 int ret = 0;
548
Patrick Delaunaye817c8e2020-07-31 16:31:47 +0200549 if (!IS_ENABLED(CONFIG_DM_REGULATOR))
550 return -ENODEV;
551
Patrick Delaunayd573e462019-07-30 19:16:38 +0200552 node = ofnode_path("/soc/i2c@40012000/hdmi-transmitter@39");
553 if (!ofnode_valid(node)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100554 log_debug("no hdmi-transmitter@39 ?\n");
Patrick Delaunayd573e462019-07-30 19:16:38 +0200555 return -ENOENT;
556 }
557
558 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
559 &hdmi, GPIOD_IS_OUT)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100560 log_debug("could not find reset-gpios\n");
Patrick Delaunayd573e462019-07-30 19:16:38 +0200561 return -ENOENT;
562 }
563
564 node = ofnode_path("/soc/i2c@40012000/cs42l51@4a");
565 if (!ofnode_valid(node)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100566 log_debug("no cs42l51@4a ?\n");
Patrick Delaunayd573e462019-07-30 19:16:38 +0200567 return -ENOENT;
568 }
569
570 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
571 &audio, GPIOD_IS_OUT)) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100572 log_debug("could not find reset-gpios\n");
Patrick Delaunayd573e462019-07-30 19:16:38 +0200573 return -ENOENT;
574 }
575
576 /* before power up, insure that HDMI and AUDIO IC is under reset */
577 ret = dm_gpio_set_value(&hdmi, 1);
578 if (ret) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100579 log_err("can't set_value for hdmi_nrst gpio");
Patrick Delaunayd573e462019-07-30 19:16:38 +0200580 goto error;
581 }
582 ret = dm_gpio_set_value(&audio, 1);
583 if (ret) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100584 log_err("can't set_value for audio_nrst gpio");
Patrick Delaunayd573e462019-07-30 19:16:38 +0200585 goto error;
586 }
587
588 /* power-up audio IC */
589 regulator_autoset_by_name("v1v8_audio", NULL);
590
591 /* power-up HDMI IC */
592 regulator_autoset_by_name("v1v2_hdmi", NULL);
593 regulator_autoset_by_name("v3v3_hdmi", NULL);
594
595error:
596 return ret;
597}
598
599static bool board_is_dk2(void)
600{
Patrick Delaunay84625482020-01-13 15:17:42 +0100601 if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
Patrick Delaunayd573e462019-07-30 19:16:38 +0200602 of_machine_is_compatible("st,stm32mp157c-dk2"))
603 return true;
604
605 return false;
606}
Patrick Delaunayd573e462019-07-30 19:16:38 +0200607
Patrick Delaunay055065a2020-04-22 14:29:13 +0200608static bool board_is_ev1(void)
609{
610 if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
611 (of_machine_is_compatible("st,stm32mp157a-ev1") ||
612 of_machine_is_compatible("st,stm32mp157c-ev1") ||
613 of_machine_is_compatible("st,stm32mp157d-ev1") ||
614 of_machine_is_compatible("st,stm32mp157f-ev1")))
615 return true;
616
617 return false;
618}
619
620/* touchscreen driver: only used for pincontrol configuration */
621static const struct udevice_id goodix_ids[] = {
622 { .compatible = "goodix,gt9147", },
623 { }
624};
625
626U_BOOT_DRIVER(goodix) = {
627 .name = "goodix",
628 .id = UCLASS_NOP,
629 .of_match = goodix_ids,
630};
631
632static void board_ev1_init(void)
633{
634 struct udevice *dev;
635
636 /* configure IRQ line on EV1 for touchscreen before LCD reset */
Simon Glass65e25be2020-12-28 20:34:56 -0700637 uclass_get_device_by_driver(UCLASS_NOP, DM_DRIVER_GET(goodix), &dev);
Patrick Delaunay055065a2020-04-22 14:29:13 +0200638}
639
Patrick Delaunayf8598d92018-03-12 10:46:18 +0100640/* board dependent setup after realloc */
641int board_init(void)
642{
643 /* address of boot parameters */
644 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
645
Patrick Delaunay29e4ce32020-06-04 14:30:24 +0200646 if (CONFIG_IS_ENABLED(DM_GPIO_HOG))
647 gpio_hog_probe_all();
Patrice Chotard8b4afe82019-03-11 11:13:17 +0100648
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100649 board_key_check();
650
Patrick Delaunay055065a2020-04-22 14:29:13 +0200651 if (board_is_ev1())
652 board_ev1_init();
653
Patrick Delaunayd573e462019-07-30 19:16:38 +0200654 if (board_is_dk2())
655 dk2_i2c1_fix();
656
Patrick Delaunaye817c8e2020-07-31 16:31:47 +0200657 if (IS_ENABLED(CONFIG_DM_REGULATOR))
658 regulators_enable_boot_on(_DEBUG);
Patrick Delaunayf59ad452019-07-05 17:20:09 +0200659
Patrick Delaunay3434bbe2020-07-31 16:31:45 +0200660 if (!IS_ENABLED(CONFIG_TFABOOT))
661 sysconf_init();
Patrick Delaunay45459742019-02-27 17:01:24 +0100662
Patrick Delaunay71ba2cb2020-04-10 19:14:01 +0200663 if (CONFIG_IS_ENABLED(LED))
Patrick Delaunay1f5118b2018-07-27 16:37:08 +0200664 led_default_state();
665
Patrick Delaunay0c952952020-04-22 14:29:12 +0200666 setup_led(LEDST_ON);
667
Patrick Delaunayf8598d92018-03-12 10:46:18 +0100668 return 0;
669}
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100670
671int board_late_init(void)
672{
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100673 const void *fdt_compat;
674 int fdt_compat_len;
Patrick Delaunay8b8b3d62019-07-30 19:16:37 +0200675 int ret;
676 u32 otp;
677 struct udevice *dev;
678 char buf[10];
Patrick Delaunay72b09982020-07-31 16:31:48 +0200679 char dtb_name[256];
680 int buf_len;
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100681
Patrick Delaunay72b09982020-07-31 16:31:48 +0200682 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
683 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
684 &fdt_compat_len);
685 if (fdt_compat && fdt_compat_len) {
686 if (strncmp(fdt_compat, "st,", 3) != 0) {
687 env_set("board_name", fdt_compat);
688 } else {
689 env_set("board_name", fdt_compat + 3);
Patrick Delaunay99f67432020-04-22 14:29:14 +0200690
Patrick Delaunay72b09982020-07-31 16:31:48 +0200691 buf_len = sizeof(dtb_name);
692 strncpy(dtb_name, fdt_compat + 3, buf_len);
693 buf_len -= strlen(fdt_compat + 3);
694 strncat(dtb_name, ".dtb", buf_len);
695 env_set("fdtfile", dtb_name);
696 }
697 }
698 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700699 DM_DRIVER_GET(stm32mp_bsec),
Patrick Delaunay72b09982020-07-31 16:31:48 +0200700 &dev);
Patrick Delaunay99f67432020-04-22 14:29:14 +0200701
Patrick Delaunay72b09982020-07-31 16:31:48 +0200702 if (!ret)
703 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
704 &otp, sizeof(otp));
705 if (ret > 0 && otp) {
706 snprintf(buf, sizeof(buf), "0x%04x", otp >> 16);
707 env_set("board_id", buf);
708
709 snprintf(buf, sizeof(buf), "0x%04x",
710 ((otp >> 8) & 0xF) - 1 + 0xA);
711 env_set("board_rev", buf);
Patrick Delaunay99f67432020-04-22 14:29:14 +0200712 }
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100713 }
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100714
Patrice Chotard395f1292019-02-12 16:50:40 +0100715 /* for DK1/DK2 boards */
716 board_check_usb_power();
717
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100718 return 0;
719}
Patrice Chotard395f1292019-02-12 16:50:40 +0100720
721void board_quiesce_devices(void)
722{
723 setup_led(LEDST_OFF);
724}
Patrice Chotard87471642019-05-02 18:07:14 +0200725
Patrick Delaunay53e3d522019-08-01 11:29:03 +0200726/* eth init function : weak called in eqos driver */
727int board_interface_eth_init(struct udevice *dev,
728 phy_interface_t interface_type)
Christophe Roullieredacf262019-05-17 15:08:43 +0200729{
730 u8 *syscfg;
731 u32 value;
Patrick Delaunay53e3d522019-08-01 11:29:03 +0200732 bool eth_clk_sel_reg = false;
733 bool eth_ref_clk_sel_reg = false;
734
735 /* Gigabit Ethernet 125MHz clock selection. */
736 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
737
738 /* Ethernet 50Mhz RMII clock selection */
739 eth_ref_clk_sel_reg =
740 dev_read_bool(dev, "st,eth_ref_clk_sel");
Christophe Roullieredacf262019-05-17 15:08:43 +0200741
742 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
743
744 if (!syscfg)
745 return -ENODEV;
746
747 switch (interface_type) {
748 case PHY_INTERFACE_MODE_MII:
749 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
750 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
Patrick Delaunay873bf442020-11-06 19:01:59 +0100751 log_debug("PHY_INTERFACE_MODE_MII\n");
Christophe Roullieredacf262019-05-17 15:08:43 +0200752 break;
753 case PHY_INTERFACE_MODE_GMII:
754 if (eth_clk_sel_reg)
755 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
756 SYSCFG_PMCSETR_ETH_CLK_SEL;
757 else
758 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
Patrick Delaunay873bf442020-11-06 19:01:59 +0100759 log_debug("PHY_INTERFACE_MODE_GMII\n");
Christophe Roullieredacf262019-05-17 15:08:43 +0200760 break;
761 case PHY_INTERFACE_MODE_RMII:
762 if (eth_ref_clk_sel_reg)
763 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
764 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
765 else
766 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
Patrick Delaunay873bf442020-11-06 19:01:59 +0100767 log_debug("PHY_INTERFACE_MODE_RMII\n");
Christophe Roullieredacf262019-05-17 15:08:43 +0200768 break;
769 case PHY_INTERFACE_MODE_RGMII:
770 case PHY_INTERFACE_MODE_RGMII_ID:
771 case PHY_INTERFACE_MODE_RGMII_RXID:
772 case PHY_INTERFACE_MODE_RGMII_TXID:
773 if (eth_clk_sel_reg)
774 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
775 SYSCFG_PMCSETR_ETH_CLK_SEL;
776 else
777 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
Patrick Delaunay873bf442020-11-06 19:01:59 +0100778 log_debug("PHY_INTERFACE_MODE_RGMII\n");
Christophe Roullieredacf262019-05-17 15:08:43 +0200779 break;
780 default:
Patrick Delaunay873bf442020-11-06 19:01:59 +0100781 log_debug("Do not manage %d interface\n",
782 interface_type);
Christophe Roullieredacf262019-05-17 15:08:43 +0200783 /* Do not manage others interfaces */
784 return -EINVAL;
785 }
786
787 /* clear and set ETH configuration bits */
788 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
789 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
790 syscfg + SYSCFG_PMCCLRR);
791 writel(value, syscfg + SYSCFG_PMCSETR);
792
793 return 0;
794}
795
Patrice Chotard8f24b1a2019-05-02 18:28:05 +0200796enum env_location env_get_location(enum env_operation op, int prio)
797{
798 u32 bootmode = get_bootmode();
799
800 if (prio)
801 return ENVL_UNKNOWN;
802
803 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
Patrick Delaunaya9addca2020-06-15 11:18:22 +0200804 case BOOT_FLASH_SD:
805 case BOOT_FLASH_EMMC:
Patrick Delaunayebfd5922020-07-31 16:31:49 +0200806 if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
807 return ENVL_MMC;
808 else if (CONFIG_IS_ENABLED(ENV_IS_IN_EXT4))
809 return ENVL_EXT4;
810 else
811 return ENVL_NOWHERE;
812
Patrice Chotard8f24b1a2019-05-02 18:28:05 +0200813 case BOOT_FLASH_NAND:
Patrick Delaunayb664a742020-03-18 09:22:52 +0100814 case BOOT_FLASH_SPINAND:
Patrick Delaunayebfd5922020-07-31 16:31:49 +0200815 if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI))
816 return ENVL_UBI;
817 else
818 return ENVL_NOWHERE;
819
Patrice Chotarde5c38fd2019-05-09 14:25:36 +0200820 case BOOT_FLASH_NOR:
Patrick Delaunayebfd5922020-07-31 16:31:49 +0200821 if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
822 return ENVL_SPI_FLASH;
823 else
824 return ENVL_NOWHERE;
825
Patrice Chotard8f24b1a2019-05-02 18:28:05 +0200826 default:
827 return ENVL_NOWHERE;
828 }
829}
830
Patrice Chotard7f90cd62019-05-02 18:36:01 +0200831const char *env_ext4_get_intf(void)
832{
833 u32 bootmode = get_bootmode();
834
835 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
836 case BOOT_FLASH_SD:
837 case BOOT_FLASH_EMMC:
838 return "mmc";
839 default:
840 return "";
841 }
842}
843
844const char *env_ext4_get_dev_part(void)
845{
Manuel Reis81d4c4e2020-11-25 10:16:20 +0000846 static char *const env_dev_part =
847#ifdef CONFIG_ENV_EXT4_DEVICE_AND_PART
848 CONFIG_ENV_EXT4_DEVICE_AND_PART;
849#else
850 "";
851#endif
Patrice Chotard7f90cd62019-05-02 18:36:01 +0200852 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
Manuel Reis81d4c4e2020-11-25 10:16:20 +0000853
854 if (strlen(env_dev_part) > 0)
855 return env_dev_part;
856
Patrice Chotard7f90cd62019-05-02 18:36:01 +0200857 u32 bootmode = get_bootmode();
858
859 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
860}
Manuel Reis81d4c4e2020-11-25 10:16:20 +0000861
Patrick Delaunaya9addca2020-06-15 11:18:22 +0200862int mmc_get_env_dev(void)
863{
Patrick Delaunay9f971932021-03-01 13:17:56 +0100864 u32 bootmode;
Patrick Delaunaya9addca2020-06-15 11:18:22 +0200865
Patrick Delaunay9f971932021-03-01 13:17:56 +0100866 if (CONFIG_SYS_MMC_ENV_DEV >= 0)
867 return CONFIG_SYS_MMC_ENV_DEV;
868
869 bootmode = get_bootmode();
870
871 /* use boot instance to select the correct mmc device identifier */
Patrick Delaunaya9addca2020-06-15 11:18:22 +0200872 return (bootmode & TAMP_BOOT_INSTANCE_MASK) - 1;
873}
Patrick Delaunaya9addca2020-06-15 11:18:22 +0200874
Patrick Delaunaye81f8d12019-07-02 13:26:07 +0200875#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900876int ft_board_setup(void *blob, struct bd_info *bd)
Patrick Delaunaye81f8d12019-07-02 13:26:07 +0200877{
Patrick Delaunayd0a3c4f2020-07-29 13:24:52 +0200878 static const struct node_info nodes[] = {
Patrick Delaunaye81f8d12019-07-02 13:26:07 +0200879 { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
Patrick Delaunayb664a742020-03-18 09:22:52 +0100880 { "st,stm32f469-qspi", MTD_DEV_TYPE_SPINAND},
Patrick Delaunaye81f8d12019-07-02 13:26:07 +0200881 { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
Christophe Kerello300669a2020-07-31 09:53:42 +0200882 { "st,stm32mp1-fmc2-nfc", MTD_DEV_TYPE_NAND, },
Patrick Delaunaye81f8d12019-07-02 13:26:07 +0200883 };
Patrick Delaunay29e5c022020-10-15 14:52:30 +0200884 char *boot_device;
Patrick Delaunay06f624f2020-07-31 16:31:50 +0200885
Patrick Delaunay29e5c022020-10-15 14:52:30 +0200886 /* Check the boot-source and don't update MTD for serial or usb boot */
887 boot_device = env_get("boot_device");
888 if (!boot_device ||
889 (strcmp(boot_device, "serial") && strcmp(boot_device, "usb")))
890 if (IS_ENABLED(CONFIG_FDT_FIXUP_PARTITIONS))
891 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
Patrick Delaunaye81f8d12019-07-02 13:26:07 +0200892
893 return 0;
894}
895#endif
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +0200896
897static void board_copro_image_process(ulong fw_image, size_t fw_size)
898{
899 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
900
901 if (!rproc_is_initialized())
902 if (rproc_init()) {
Patrick Delaunay873bf442020-11-06 19:01:59 +0100903 log_err("Remote Processor %d initialization failed\n",
904 id);
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +0200905 return;
906 }
907
908 ret = rproc_load(id, fw_image, fw_size);
Patrick Delaunay873bf442020-11-06 19:01:59 +0100909 log_err("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
910 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +0200911
Fabien Dessenne790d5b32019-10-30 14:38:32 +0100912 if (!ret)
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +0200913 rproc_start(id);
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +0200914}
915
916U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);