blob: 1d4a54c9026db6e616d7ca11411cf0250003951e [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 */
Patrice Chotard395f1292019-02-12 16:50:40 +01005#include <common.h>
6#include <adc.h>
Patrick Delaunay8e194772019-06-21 15:26:40 +02007#include <bootm.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +02008#include <clk.h>
Patrick Delaunayd1a597f2019-07-30 19:16:44 +02009#include <config.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020010#include <dm.h>
Simon Glass3a7d5572019-08-01 09:46:42 -060011#include <env.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060012#include <env_internal.h>
Patrick Delaunayc31000c2019-03-29 15:42:23 +010013#include <g_dnl.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020014#include <generic-phy.h>
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +010015#include <i2c.h>
Simon Glass52559322019-11-14 12:57:46 -070016#include <init.h>
Patrick Delaunayd461f102019-02-12 11:44:41 +010017#include <led.h>
Patrick Delaunayf6031d62019-10-14 09:28:09 +020018#include <memalign.h>
Patrick Delaunayd461f102019-02-12 11:44:41 +010019#include <misc.h>
Patrick Delaunaye81f8d12019-07-02 13:26:07 +020020#include <mtd.h>
21#include <mtd_node.h>
Patrick Delaunay53e3d522019-08-01 11:29:03 +020022#include <netdev.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020023#include <phy.h>
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +020024#include <remoteproc.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020025#include <reset.h>
Patrick Delaunay45459742019-02-27 17:01:24 +010026#include <syscon.h>
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +010027#include <usb.h>
Patrick Delaunaydd281082019-07-30 19:16:39 +020028#include <watchdog.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020029#include <asm/io.h>
Patrick Delaunay842ebb52019-02-27 17:01:18 +010030#include <asm/gpio.h>
Patrick Delaunay45459742019-02-27 17:01:24 +010031#include <asm/arch/stm32.h>
Patrice Chotard7f90cd62019-05-02 18:36:01 +020032#include <asm/arch/sys_proto.h>
Patrick Delaunaye81f8d12019-07-02 13:26:07 +020033#include <jffs2/load_kernel.h>
Patrice Chotard4c834b92018-08-10 17:12:14 +020034#include <power/regulator.h>
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +010035#include <usb/dwc2_udc.h>
Patrick Delaunayf8598d92018-03-12 10:46:18 +010036
Patrick Delaunay45459742019-02-27 17:01:24 +010037/* SYSCFG registers */
38#define SYSCFG_BOOTR 0x00
39#define SYSCFG_PMCSETR 0x04
40#define SYSCFG_IOCTRLSETR 0x18
41#define SYSCFG_ICNR 0x1C
42#define SYSCFG_CMPCR 0x20
43#define SYSCFG_CMPENSETR 0x24
44#define SYSCFG_PMCCLRR 0x44
45
46#define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0)
47#define SYSCFG_BOOTR_BOOTPD_SHIFT 4
48
49#define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0)
50#define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1)
51#define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2)
52#define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3)
53#define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4)
54
55#define SYSCFG_CMPCR_SW_CTRL BIT(1)
56#define SYSCFG_CMPCR_READY BIT(8)
57
58#define SYSCFG_CMPENSETR_MPU_EN BIT(0)
59
60#define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16)
61#define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17)
62
63#define SYSCFG_PMCSETR_ETH_SELMII BIT(20)
64
65#define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21)
Christophe Roullieredacf262019-05-17 15:08:43 +020066#define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0
67#define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21)
68#define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23)
Patrick Delaunay45459742019-02-27 17:01:24 +010069
Patrick Delaunayf8598d92018-03-12 10:46:18 +010070/*
71 * Get a global data pointer
72 */
73DECLARE_GLOBAL_DATA_PTR;
74
Patrice Chotard28c064e2019-04-30 18:09:38 +020075#define USB_LOW_THRESHOLD_UV 200000
Patrice Chotard395f1292019-02-12 16:50:40 +010076#define USB_WARNING_LOW_THRESHOLD_UV 660000
77#define USB_START_LOW_THRESHOLD_UV 1230000
Patrice Chotard28c064e2019-04-30 18:09:38 +020078#define USB_START_HIGH_THRESHOLD_UV 2150000
Patrice Chotard395f1292019-02-12 16:50:40 +010079
Patrick Delaunayd461f102019-02-12 11:44:41 +010080int checkboard(void)
81{
82 int ret;
83 char *mode;
84 u32 otp;
85 struct udevice *dev;
86 const char *fdt_compat;
87 int fdt_compat_len;
88
Patrick Delaunay152c84b2019-07-02 13:26:06 +020089 if (IS_ENABLED(CONFIG_STM32MP1_OPTEE))
90 mode = "trusted with OP-TEE";
91 else if (IS_ENABLED(CONFIG_STM32MP1_TRUSTED))
Patrick Delaunayd461f102019-02-12 11:44:41 +010092 mode = "trusted";
93 else
94 mode = "basic";
95
96 printf("Board: stm32mp1 in %s mode", mode);
97 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
98 &fdt_compat_len);
99 if (fdt_compat && fdt_compat_len)
100 printf(" (%s)", fdt_compat);
101 puts("\n");
102
103 ret = uclass_get_device_by_driver(UCLASS_MISC,
104 DM_GET_DRIVER(stm32mp_bsec),
105 &dev);
106
107 if (!ret)
108 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
109 &otp, sizeof(otp));
Patrick Delaunay19efa392019-08-02 13:08:05 +0200110 if (ret > 0 && otp) {
Patrick Delaunayd461f102019-02-12 11:44:41 +0100111 printf("Board: MB%04x Var%d Rev.%c-%02d\n",
112 otp >> 16,
113 (otp >> 12) & 0xF,
114 ((otp >> 8) & 0xF) - 1 + 'A',
115 otp & 0xF);
116 }
117
118 return 0;
119}
120
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100121static void board_key_check(void)
122{
123#if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
124 ofnode node;
125 struct gpio_desc gpio;
126 enum forced_boot_mode boot_mode = BOOT_NORMAL;
127
128 node = ofnode_path("/config");
129 if (!ofnode_valid(node)) {
130 debug("%s: no /config node?\n", __func__);
131 return;
132 }
133#ifdef CONFIG_FASTBOOT
134 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
135 &gpio, GPIOD_IS_IN)) {
136 debug("%s: could not find a /config/st,fastboot-gpios\n",
137 __func__);
138 } else {
139 if (dm_gpio_get_value(&gpio)) {
140 puts("Fastboot key pressed, ");
141 boot_mode = BOOT_FASTBOOT;
142 }
143
144 dm_gpio_free(NULL, &gpio);
145 }
146#endif
147#ifdef CONFIG_CMD_STM32PROG
148 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
149 &gpio, GPIOD_IS_IN)) {
150 debug("%s: could not find a /config/st,stm32prog-gpios\n",
151 __func__);
152 } else {
153 if (dm_gpio_get_value(&gpio)) {
154 puts("STM32Programmer key pressed, ");
155 boot_mode = BOOT_STM32PROG;
156 }
157 dm_gpio_free(NULL, &gpio);
158 }
159#endif
160
161 if (boot_mode != BOOT_NORMAL) {
162 puts("entering download mode...\n");
163 clrsetbits_le32(TAMP_BOOT_CONTEXT,
164 TAMP_BOOT_FORCED_MASK,
165 boot_mode);
166 }
167#endif
168}
169
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100170#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
Patrice Chotard4c834b92018-08-10 17:12:14 +0200171
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +0100172/* STMicroelectronics STUSB1600 Type-C controller */
173#define STUSB1600_CC_CONNECTION_STATUS 0x0E
174
175/* STUSB1600_CC_CONNECTION_STATUS bitfields */
176#define STUSB1600_CC_ATTACH BIT(0)
177
178static int stusb1600_init(struct udevice **dev_stusb1600)
179{
180 ofnode node;
181 struct udevice *dev, *bus;
182 int ret;
183 u32 chip_addr;
184
185 *dev_stusb1600 = NULL;
186
187 /* if node stusb1600 is present, means DK1 or DK2 board */
188 node = ofnode_by_compatible(ofnode_null(), "st,stusb1600");
189 if (!ofnode_valid(node))
190 return -ENODEV;
191
192 ret = ofnode_read_u32(node, "reg", &chip_addr);
193 if (ret)
194 return -EINVAL;
195
196 ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node),
197 &bus);
198 if (ret) {
199 printf("bus for stusb1600 not found\n");
200 return -ENODEV;
201 }
202
203 ret = dm_i2c_probe(bus, chip_addr, 0, &dev);
204 if (!ret)
205 *dev_stusb1600 = dev;
206
207 return ret;
208}
209
210static int stusb1600_cable_connected(struct udevice *dev)
211{
212 u8 status;
213
214 if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1))
215 return 0;
216
217 return status & STUSB1600_CC_ATTACH;
218}
219
220#include <usb/dwc2_udc.h>
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100221int g_dnl_board_usb_cable_connected(void)
Patrice Chotard4c834b92018-08-10 17:12:14 +0200222{
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +0100223 struct udevice *stusb1600;
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100224 struct udevice *dwc2_udc_otg;
Patrice Chotard4c834b92018-08-10 17:12:14 +0200225 int ret;
226
Patrick Delaunay6fe7dd32019-03-29 15:42:24 +0100227 if (!stusb1600_init(&stusb1600))
228 return stusb1600_cable_connected(stusb1600);
229
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100230 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
231 DM_GET_DRIVER(dwc2_udc_otg),
232 &dwc2_udc_otg);
233 if (!ret)
234 debug("dwc2_udc_otg init failed\n");
Patrice Chotard4c834b92018-08-10 17:12:14 +0200235
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100236 return dwc2_udc_B_session_valid(dwc2_udc_otg);
Patrice Chotard4c834b92018-08-10 17:12:14 +0200237}
Patrick Delaunayfb90fcf2019-09-13 15:24:17 +0200238
239#define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
240#define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
241
242int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
243{
244 if (!strcmp(name, "usb_dnl_dfu"))
245 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
246 else if (!strcmp(name, "usb_dnl_fastboot"))
247 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
248 &dev->idProduct);
249 else
250 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
251
252 return 0;
253}
254
Patrick Delaunayc31000c2019-03-29 15:42:23 +0100255#endif /* CONFIG_USB_GADGET */
Patrice Chotard4c834b92018-08-10 17:12:14 +0200256
Patrick Delaunaydd281082019-07-30 19:16:39 +0200257#ifdef CONFIG_LED
Patrice Chotard395f1292019-02-12 16:50:40 +0100258static int get_led(struct udevice **dev, char *led_string)
259{
260 char *led_name;
261 int ret;
262
263 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
264 if (!led_name) {
265 pr_debug("%s: could not find %s config string\n",
266 __func__, led_string);
267 return -ENOENT;
268 }
269 ret = led_get_by_label(led_name, dev);
270 if (ret) {
271 debug("%s: get=%d\n", __func__, ret);
272 return ret;
273 }
274
275 return 0;
276}
277
278static int setup_led(enum led_state_t cmd)
279{
280 struct udevice *dev;
281 int ret;
282
283 ret = get_led(&dev, "u-boot,boot-led");
284 if (ret)
285 return ret;
286
287 ret = led_set_state(dev, cmd);
288 return ret;
289}
Patrick Delaunaydd281082019-07-30 19:16:39 +0200290#endif
291
292static void __maybe_unused led_error_blink(u32 nb_blink)
293{
294#ifdef CONFIG_LED
295 int ret;
296 struct udevice *led;
297 u32 i;
298#endif
299
300 if (!nb_blink)
301 return;
302
303#ifdef CONFIG_LED
304 ret = get_led(&led, "u-boot,error-led");
305 if (!ret) {
306 /* make u-boot,error-led blinking */
307 /* if U32_MAX and 125ms interval, for 17.02 years */
308 for (i = 0; i < 2 * nb_blink; i++) {
309 led_set_state(led, LEDST_TOGGLE);
310 mdelay(125);
311 WATCHDOG_RESET();
312 }
313 }
314#endif
315
316 /* infinite: the boot process must be stopped */
317 if (nb_blink == U32_MAX)
318 hang();
319}
Patrice Chotard395f1292019-02-12 16:50:40 +0100320
Patrick Delaunay41542472019-07-30 19:16:43 +0200321#ifdef CONFIG_ADC
Patrice Chotard395f1292019-02-12 16:50:40 +0100322static int board_check_usb_power(void)
323{
324 struct ofnode_phandle_args adc_args;
325 struct udevice *adc;
Patrice Chotard395f1292019-02-12 16:50:40 +0100326 ofnode node;
327 unsigned int raw;
328 int max_uV = 0;
Patrice Chotard28c064e2019-04-30 18:09:38 +0200329 int min_uV = USB_START_HIGH_THRESHOLD_UV;
Patrice Chotard395f1292019-02-12 16:50:40 +0100330 int ret, uV, adc_count;
Patrice Chotard28c064e2019-04-30 18:09:38 +0200331 u32 nb_blink;
332 u8 i;
Patrice Chotard395f1292019-02-12 16:50:40 +0100333 node = ofnode_path("/config");
334 if (!ofnode_valid(node)) {
335 debug("%s: no /config node?\n", __func__);
336 return -ENOENT;
337 }
338
339 /*
340 * Retrieve the ADC channels devices and get measurement
341 * for each of them
342 */
343 adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
344 "#io-channel-cells");
345 if (adc_count < 0) {
346 if (adc_count == -ENOENT)
347 return 0;
348
349 pr_err("%s: can't find adc channel (%d)\n", __func__,
350 adc_count);
351
352 return adc_count;
353 }
354
355 for (i = 0; i < adc_count; i++) {
356 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
357 "#io-channel-cells", 0, i,
358 &adc_args)) {
359 pr_debug("%s: can't find /config/st,adc_usb_pd\n",
360 __func__);
361 return 0;
362 }
363
364 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
365 &adc);
366
367 if (ret) {
368 pr_err("%s: Can't get adc device(%d)\n", __func__,
369 ret);
370 return ret;
371 }
372
373 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
374 &raw);
375 if (ret) {
376 pr_err("%s: single shot failed for %s[%d]!\n",
377 __func__, adc->name, adc_args.args[0]);
378 return ret;
379 }
380 /* Convert to uV */
381 if (!adc_raw_to_uV(adc, raw, &uV)) {
382 if (uV > max_uV)
383 max_uV = uV;
Patrice Chotard28c064e2019-04-30 18:09:38 +0200384 if (uV < min_uV)
385 min_uV = uV;
Patrice Chotard395f1292019-02-12 16:50:40 +0100386 pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
387 adc->name, adc_args.args[0], raw, uV);
388 } else {
389 pr_err("%s: Can't get uV value for %s[%d]\n",
390 __func__, adc->name, adc_args.args[0]);
391 }
392 }
393
394 /*
395 * If highest value is inside 1.23 Volts and 2.10 Volts, that means
396 * board is plugged on an USB-C 3A power supply and boot process can
397 * continue.
398 */
399 if (max_uV > USB_START_LOW_THRESHOLD_UV &&
Patrice Chotard28c064e2019-04-30 18:09:38 +0200400 max_uV <= USB_START_HIGH_THRESHOLD_UV &&
401 min_uV <= USB_LOW_THRESHOLD_UV)
Patrice Chotard395f1292019-02-12 16:50:40 +0100402 return 0;
403
Patrice Chotard28c064e2019-04-30 18:09:38 +0200404 pr_err("****************************************************\n");
Patrice Chotard395f1292019-02-12 16:50:40 +0100405
Patrice Chotard28c064e2019-04-30 18:09:38 +0200406 /*
407 * If highest and lowest value are either both below
408 * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
409 * means USB TYPE-C is in unattached mode, this is an issue, make
410 * u-boot,error-led blinking and stop boot process.
411 */
412 if ((max_uV > USB_LOW_THRESHOLD_UV &&
413 min_uV > USB_LOW_THRESHOLD_UV) ||
414 (max_uV <= USB_LOW_THRESHOLD_UV &&
415 min_uV <= USB_LOW_THRESHOLD_UV)) {
416 pr_err("* ERROR USB TYPE-C connection in unattached mode *\n");
417 pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
418 /* with 125ms interval, led will blink for 17.02 years ....*/
419 nb_blink = U32_MAX;
420 }
421
422 if (max_uV > USB_LOW_THRESHOLD_UV &&
423 max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
424 min_uV <= USB_LOW_THRESHOLD_UV) {
425 pr_err("* WARNING 500mA power supply detected *\n");
Patrice Chotard395f1292019-02-12 16:50:40 +0100426 nb_blink = 2;
Patrice Chotard28c064e2019-04-30 18:09:38 +0200427 }
428
429 if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
430 max_uV <= USB_START_LOW_THRESHOLD_UV &&
431 min_uV <= USB_LOW_THRESHOLD_UV) {
432 pr_err("* WARNING 1.5mA power supply detected *\n");
Patrice Chotard395f1292019-02-12 16:50:40 +0100433 nb_blink = 3;
434 }
435
Patrice Chotard28c064e2019-04-30 18:09:38 +0200436 /*
437 * If highest value is above 2.15 Volts that means that the USB TypeC
438 * supplies more than 3 Amp, this is not compliant with TypeC specification
439 */
440 if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
441 pr_err("* USB TYPE-C charger not compliant with *\n");
442 pr_err("* specification *\n");
443 pr_err("****************************************************\n\n");
444 /* with 125ms interval, led will blink for 17.02 years ....*/
445 nb_blink = U32_MAX;
446 } else {
447 pr_err("* Current too low, use a 3A power supply! *\n");
448 pr_err("****************************************************\n\n");
449 }
Patrice Chotard395f1292019-02-12 16:50:40 +0100450
Patrick Delaunaydd281082019-07-30 19:16:39 +0200451 led_error_blink(nb_blink);
Patrice Chotard395f1292019-02-12 16:50:40 +0100452
453 return 0;
454}
Patrick Delaunay41542472019-07-30 19:16:43 +0200455#endif /* CONFIG_ADC */
Patrice Chotard395f1292019-02-12 16:50:40 +0100456
Patrick Delaunay45459742019-02-27 17:01:24 +0100457static void sysconf_init(void)
458{
459#ifndef CONFIG_STM32MP1_TRUSTED
460 u8 *syscfg;
461#ifdef CONFIG_DM_REGULATOR
462 struct udevice *pwr_dev;
463 struct udevice *pwr_reg;
464 struct udevice *dev;
465 int ret;
466 u32 otp = 0;
467#endif
468 u32 bootr;
469
470 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
471
472 /* interconnect update : select master using the port 1 */
473 /* LTDC = AXI_M9 */
474 /* GPU = AXI_M8 */
475 /* today information is hardcoded in U-Boot */
476 writel(BIT(9), syscfg + SYSCFG_ICNR);
477
478 /* disable Pull-Down for boot pin connected to VDD */
479 bootr = readl(syscfg + SYSCFG_BOOTR);
480 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
481 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
482 writel(bootr, syscfg + SYSCFG_BOOTR);
483
484#ifdef CONFIG_DM_REGULATOR
485 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
486 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
487 * The customer will have to disable this for low frequencies
488 * or if AFMUX is selected but the function not used, typically for
489 * TRACE. Otherwise, impact on power consumption.
490 *
491 * WARNING:
492 * enabling High Speed mode while VDD>2.7V
493 * with the OTP product_below_2v5 (OTP 18, BIT 13)
494 * erroneously set to 1 can damage the IC!
495 * => U-Boot set the register only if VDD < 2.7V (in DT)
496 * but this value need to be consistent with board design
497 */
Patrick Delaunay5e959ab2019-07-30 19:16:42 +0200498 ret = uclass_get_device_by_driver(UCLASS_PMIC,
499 DM_GET_DRIVER(stm32mp_pwr_pmic),
500 &pwr_dev);
Patrick Delaunay45459742019-02-27 17:01:24 +0100501 if (!ret) {
502 ret = uclass_get_device_by_driver(UCLASS_MISC,
503 DM_GET_DRIVER(stm32mp_bsec),
504 &dev);
505 if (ret) {
506 pr_err("Can't find stm32mp_bsec driver\n");
507 return;
508 }
509
510 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
Patrick Delaunayff6618e2019-08-02 13:08:06 +0200511 if (ret > 0)
Patrick Delaunay45459742019-02-27 17:01:24 +0100512 otp = otp & BIT(13);
513
Patrick Delaunay5e959ab2019-07-30 19:16:42 +0200514 /* get VDD = vdd-supply */
515 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
Patrick Delaunay45459742019-02-27 17:01:24 +0100516 &pwr_reg);
517
518 /* check if VDD is Low Voltage */
519 if (!ret) {
520 if (regulator_get_value(pwr_reg) < 2700000) {
521 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
522 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
523 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
524 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
525 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
526 syscfg + SYSCFG_IOCTRLSETR);
527
528 if (!otp)
529 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
530 } else {
531 if (otp)
532 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
533 }
534 } else {
535 debug("VDD unknown");
536 }
537 }
538#endif
539
540 /* activate automatic I/O compensation
541 * warning: need to ensure CSI enabled and ready in clock driver
542 */
543 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
544
545 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
546 ;
547 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
548#endif
549}
550
Patrick Delaunayd573e462019-07-30 19:16:38 +0200551#ifdef CONFIG_DM_REGULATOR
552/* Fix to make I2C1 usable on DK2 for touchscreen usage in kernel */
553static int dk2_i2c1_fix(void)
554{
555 ofnode node;
556 struct gpio_desc hdmi, audio;
557 int ret = 0;
558
559 node = ofnode_path("/soc/i2c@40012000/hdmi-transmitter@39");
560 if (!ofnode_valid(node)) {
561 pr_debug("%s: no hdmi-transmitter@39 ?\n", __func__);
562 return -ENOENT;
563 }
564
565 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
566 &hdmi, GPIOD_IS_OUT)) {
567 pr_debug("%s: could not find reset-gpios\n",
568 __func__);
569 return -ENOENT;
570 }
571
572 node = ofnode_path("/soc/i2c@40012000/cs42l51@4a");
573 if (!ofnode_valid(node)) {
574 pr_debug("%s: no cs42l51@4a ?\n", __func__);
575 return -ENOENT;
576 }
577
578 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
579 &audio, GPIOD_IS_OUT)) {
580 pr_debug("%s: could not find reset-gpios\n",
581 __func__);
582 return -ENOENT;
583 }
584
585 /* before power up, insure that HDMI and AUDIO IC is under reset */
586 ret = dm_gpio_set_value(&hdmi, 1);
587 if (ret) {
588 pr_err("%s: can't set_value for hdmi_nrst gpio", __func__);
589 goto error;
590 }
591 ret = dm_gpio_set_value(&audio, 1);
592 if (ret) {
593 pr_err("%s: can't set_value for audio_nrst gpio", __func__);
594 goto error;
595 }
596
597 /* power-up audio IC */
598 regulator_autoset_by_name("v1v8_audio", NULL);
599
600 /* power-up HDMI IC */
601 regulator_autoset_by_name("v1v2_hdmi", NULL);
602 regulator_autoset_by_name("v3v3_hdmi", NULL);
603
604error:
605 return ret;
606}
607
608static bool board_is_dk2(void)
609{
610 if (CONFIG_IS_ENABLED(TARGET_STM32MP157C_DK2) &&
611 of_machine_is_compatible("st,stm32mp157c-dk2"))
612 return true;
613
614 return false;
615}
616#endif
617
Patrick Delaunayf8598d92018-03-12 10:46:18 +0100618/* board dependent setup after realloc */
619int board_init(void)
620{
Patrice Chotard8b4afe82019-03-11 11:13:17 +0100621 struct udevice *dev;
622
Patrick Delaunayf8598d92018-03-12 10:46:18 +0100623 /* address of boot parameters */
624 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
625
Patrice Chotard8b4afe82019-03-11 11:13:17 +0100626 /* probe all PINCTRL for hog */
627 for (uclass_first_device(UCLASS_PINCTRL, &dev);
628 dev;
629 uclass_next_device(&dev)) {
630 pr_debug("probe pincontrol = %s\n", dev->name);
631 }
632
Patrick Delaunay9a2ba282019-02-27 17:01:20 +0100633 board_key_check();
634
Patrick Delaunayf59ad452019-07-05 17:20:09 +0200635#ifdef CONFIG_DM_REGULATOR
Patrick Delaunayd573e462019-07-30 19:16:38 +0200636 if (board_is_dk2())
637 dk2_i2c1_fix();
638
Patrick Delaunayf59ad452019-07-05 17:20:09 +0200639 regulators_enable_boot_on(_DEBUG);
640#endif
641
Patrick Delaunay45459742019-02-27 17:01:24 +0100642 sysconf_init();
643
Patrick Delaunay4616ff42019-07-30 19:16:40 +0200644 if (CONFIG_IS_ENABLED(CONFIG_LED))
Patrick Delaunay1f5118b2018-07-27 16:37:08 +0200645 led_default_state();
646
Patrick Delaunayf8598d92018-03-12 10:46:18 +0100647 return 0;
648}
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100649
650int board_late_init(void)
651{
Patrick Delaunay55f9cd22019-07-30 19:16:41 +0200652 char *boot_device;
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100653#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
654 const void *fdt_compat;
655 int fdt_compat_len;
Patrick Delaunay8b8b3d62019-07-30 19:16:37 +0200656 int ret;
657 u32 otp;
658 struct udevice *dev;
659 char buf[10];
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100660
661 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
662 &fdt_compat_len);
663 if (fdt_compat && fdt_compat_len) {
664 if (strncmp(fdt_compat, "st,", 3) != 0)
665 env_set("board_name", fdt_compat);
666 else
667 env_set("board_name", fdt_compat + 3);
668 }
Patrick Delaunay8b8b3d62019-07-30 19:16:37 +0200669 ret = uclass_get_device_by_driver(UCLASS_MISC,
670 DM_GET_DRIVER(stm32mp_bsec),
671 &dev);
672
673 if (!ret)
674 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
675 &otp, sizeof(otp));
676 if (!ret && otp) {
677 snprintf(buf, sizeof(buf), "0x%04x", otp >> 16);
678 env_set("board_id", buf);
679
680 snprintf(buf, sizeof(buf), "0x%04x",
681 ((otp >> 8) & 0xF) - 1 + 0xA);
682 env_set("board_rev", buf);
683 }
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100684#endif
685
Patrick Delaunay41542472019-07-30 19:16:43 +0200686#ifdef CONFIG_ADC
Patrice Chotard395f1292019-02-12 16:50:40 +0100687 /* for DK1/DK2 boards */
688 board_check_usb_power();
Patrick Delaunay41542472019-07-30 19:16:43 +0200689#endif /* CONFIG_ADC */
Patrice Chotard395f1292019-02-12 16:50:40 +0100690
Patrick Delaunay55f9cd22019-07-30 19:16:41 +0200691 /* Check the boot-source to disable bootdelay */
692 boot_device = env_get("boot_device");
693 if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
694 env_set("bootdelay", "0");
695
Patrick Delaunayb4ae34b2019-02-27 17:01:11 +0100696 return 0;
697}
Patrice Chotard395f1292019-02-12 16:50:40 +0100698
699void board_quiesce_devices(void)
700{
Patrick Delaunay4616ff42019-07-30 19:16:40 +0200701#ifdef CONFIG_LED
Patrice Chotard395f1292019-02-12 16:50:40 +0100702 setup_led(LEDST_OFF);
Patrick Delaunay4616ff42019-07-30 19:16:40 +0200703#endif
Patrice Chotard395f1292019-02-12 16:50:40 +0100704}
Patrice Chotard87471642019-05-02 18:07:14 +0200705
Patrick Delaunay53e3d522019-08-01 11:29:03 +0200706/* eth init function : weak called in eqos driver */
707int board_interface_eth_init(struct udevice *dev,
708 phy_interface_t interface_type)
Christophe Roullieredacf262019-05-17 15:08:43 +0200709{
710 u8 *syscfg;
711 u32 value;
Patrick Delaunay53e3d522019-08-01 11:29:03 +0200712 bool eth_clk_sel_reg = false;
713 bool eth_ref_clk_sel_reg = false;
714
715 /* Gigabit Ethernet 125MHz clock selection. */
716 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
717
718 /* Ethernet 50Mhz RMII clock selection */
719 eth_ref_clk_sel_reg =
720 dev_read_bool(dev, "st,eth_ref_clk_sel");
Christophe Roullieredacf262019-05-17 15:08:43 +0200721
722 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
723
724 if (!syscfg)
725 return -ENODEV;
726
727 switch (interface_type) {
728 case PHY_INTERFACE_MODE_MII:
729 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
730 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
731 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
732 break;
733 case PHY_INTERFACE_MODE_GMII:
734 if (eth_clk_sel_reg)
735 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
736 SYSCFG_PMCSETR_ETH_CLK_SEL;
737 else
738 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
739 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
740 break;
741 case PHY_INTERFACE_MODE_RMII:
742 if (eth_ref_clk_sel_reg)
743 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
744 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
745 else
746 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
747 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
748 break;
749 case PHY_INTERFACE_MODE_RGMII:
750 case PHY_INTERFACE_MODE_RGMII_ID:
751 case PHY_INTERFACE_MODE_RGMII_RXID:
752 case PHY_INTERFACE_MODE_RGMII_TXID:
753 if (eth_clk_sel_reg)
754 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
755 SYSCFG_PMCSETR_ETH_CLK_SEL;
756 else
757 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
758 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
759 break;
760 default:
761 debug("%s: Do not manage %d interface\n",
762 __func__, interface_type);
763 /* Do not manage others interfaces */
764 return -EINVAL;
765 }
766
767 /* clear and set ETH configuration bits */
768 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
769 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
770 syscfg + SYSCFG_PMCCLRR);
771 writel(value, syscfg + SYSCFG_PMCSETR);
772
773 return 0;
774}
775
Patrice Chotard8f24b1a2019-05-02 18:28:05 +0200776enum env_location env_get_location(enum env_operation op, int prio)
777{
778 u32 bootmode = get_bootmode();
779
780 if (prio)
781 return ENVL_UNKNOWN;
782
783 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
784#ifdef CONFIG_ENV_IS_IN_EXT4
785 case BOOT_FLASH_SD:
786 case BOOT_FLASH_EMMC:
787 return ENVL_EXT4;
788#endif
789#ifdef CONFIG_ENV_IS_IN_UBI
790 case BOOT_FLASH_NAND:
791 return ENVL_UBI;
792#endif
Patrice Chotarde5c38fd2019-05-09 14:25:36 +0200793#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
794 case BOOT_FLASH_NOR:
795 return ENVL_SPI_FLASH;
796#endif
Patrice Chotard8f24b1a2019-05-02 18:28:05 +0200797 default:
798 return ENVL_NOWHERE;
799 }
800}
801
Patrice Chotard7f90cd62019-05-02 18:36:01 +0200802#if defined(CONFIG_ENV_IS_IN_EXT4)
803const char *env_ext4_get_intf(void)
804{
805 u32 bootmode = get_bootmode();
806
807 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
808 case BOOT_FLASH_SD:
809 case BOOT_FLASH_EMMC:
810 return "mmc";
811 default:
812 return "";
813 }
814}
815
816const char *env_ext4_get_dev_part(void)
817{
818 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
819 u32 bootmode = get_bootmode();
820
821 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
822}
823#endif
824
Patrice Chotard87471642019-05-02 18:07:14 +0200825#ifdef CONFIG_SYS_MTDPARTS_RUNTIME
826
827#define MTDPARTS_LEN 256
828#define MTDIDS_LEN 128
829
830/**
831 * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
832 * If we need to access it before the env is relocated, then we need
833 * to use our own stack buffer. gd->env_buf will be too small.
834 *
835 * @param buf temporary buffer pointer MTDPARTS_LEN long
836 * @return mtdparts variable string, NULL if not found
837 */
838static const char *env_get_mtdparts(const char *str, char *buf)
839{
840 if (gd->flags & GD_FLG_ENV_READY)
841 return env_get(str);
842 if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
843 return buf;
844
845 return NULL;
846}
847
848/**
849 * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
850 */
851static void board_get_mtdparts(const char *dev,
852 char *mtdids,
853 char *mtdparts)
854{
855 char env_name[32] = "mtdparts_";
856 char tmp_mtdparts[MTDPARTS_LEN];
857 const char *tmp;
858
859 /* name of env variable to read = mtdparts_<dev> */
860 strcat(env_name, dev);
861 tmp = env_get_mtdparts(env_name, tmp_mtdparts);
862 if (tmp) {
863 /* mtdids: "<dev>=<dev>, ...." */
864 if (mtdids[0] != '\0')
865 strcat(mtdids, ",");
866 strcat(mtdids, dev);
867 strcat(mtdids, "=");
868 strcat(mtdids, dev);
869
870 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
871 if (mtdparts[0] != '\0')
872 strncat(mtdparts, ";", MTDPARTS_LEN);
873 else
874 strcat(mtdparts, "mtdparts=");
875 strncat(mtdparts, dev, MTDPARTS_LEN);
876 strncat(mtdparts, ":", MTDPARTS_LEN);
877 strncat(mtdparts, tmp, MTDPARTS_LEN);
878 }
879}
880
881void board_mtdparts_default(const char **mtdids, const char **mtdparts)
882{
Patrick Delaunayfd399a12019-10-14 09:28:11 +0200883 struct mtd_info *mtd;
Patrice Chotard87471642019-05-02 18:07:14 +0200884 struct udevice *dev;
Patrick Delaunayfd399a12019-10-14 09:28:11 +0200885 static char parts[3 * MTDPARTS_LEN + 1];
Patrice Chotard87471642019-05-02 18:07:14 +0200886 static char ids[MTDIDS_LEN + 1];
887 static bool mtd_initialized;
888
889 if (mtd_initialized) {
890 *mtdids = ids;
891 *mtdparts = parts;
892 return;
893 }
894
895 memset(parts, 0, sizeof(parts));
896 memset(ids, 0, sizeof(ids));
897
Patrick Delaunayfd399a12019-10-14 09:28:11 +0200898 /* probe all MTD devices */
899 for (uclass_first_device(UCLASS_MTD, &dev);
900 dev;
901 uclass_next_device(&dev)) {
902 pr_debug("mtd device = %s\n", dev->name);
903 }
904
905 mtd = get_mtd_device_nm("nand0");
906 if (!IS_ERR_OR_NULL(mtd)) {
Patrice Chotard87471642019-05-02 18:07:14 +0200907 board_get_mtdparts("nand0", ids, parts);
Patrick Delaunayfd399a12019-10-14 09:28:11 +0200908 put_mtd_device(mtd);
909 }
910
911 mtd = get_mtd_device_nm("spi-nand0");
912 if (!IS_ERR_OR_NULL(mtd)) {
913 board_get_mtdparts("spi-nand0", ids, parts);
914 put_mtd_device(mtd);
915 }
Patrice Chotard87471642019-05-02 18:07:14 +0200916
917 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
918 board_get_mtdparts("nor0", ids, parts);
919
920 mtd_initialized = true;
921 *mtdids = ids;
922 *mtdparts = parts;
923 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
924}
925#endif
Patrick Delaunaye81f8d12019-07-02 13:26:07 +0200926
927#if defined(CONFIG_OF_BOARD_SETUP)
928int ft_board_setup(void *blob, bd_t *bd)
929{
930#ifdef CONFIG_FDT_FIXUP_PARTITIONS
931 struct node_info nodes[] = {
932 { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
933 { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
934 };
935 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
936#endif
937
938 return 0;
939}
940#endif
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +0200941
Patrick Delaunayf6031d62019-10-14 09:28:09 +0200942#ifdef CONFIG_SET_DFU_ALT_INFO
943#define DFU_ALT_BUF_LEN SZ_1K
944
945static void board_get_alt_info(const char *dev, char *buff)
946{
947 char var_name[32] = "dfu_alt_info_";
948 int ret;
949
950 ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
951
952 /* name of env variable to read = dfu_alt_info_<dev> */
953 strcat(var_name, dev);
954 ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
955 if (ret) {
956 if (buff[0] != '\0')
957 strcat(buff, "&");
958 strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
959 }
960}
961
962void set_dfu_alt_info(char *interface, char *devstr)
963{
964 struct udevice *dev;
Patrick Delaunayfd399a12019-10-14 09:28:11 +0200965 struct mtd_info *mtd;
Patrick Delaunayf6031d62019-10-14 09:28:09 +0200966
967 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
968
969 if (env_get("dfu_alt_info"))
970 return;
971
972 memset(buf, 0, sizeof(buf));
973
Patrick Delaunayfd399a12019-10-14 09:28:11 +0200974 /* probe all MTD devices */
975 mtd_probe_devices();
976
Patrick Delaunayf6031d62019-10-14 09:28:09 +0200977 board_get_alt_info("ram", buf);
978
979 if (!uclass_get_device(UCLASS_MMC, 0, &dev))
980 board_get_alt_info("mmc0", buf);
981
982 if (!uclass_get_device(UCLASS_MMC, 1, &dev))
983 board_get_alt_info("mmc1", buf);
984
985 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
986 board_get_alt_info("nor0", buf);
987
Patrick Delaunayfd399a12019-10-14 09:28:11 +0200988 mtd = get_mtd_device_nm("nand0");
989 if (!IS_ERR_OR_NULL(mtd))
Patrick Delaunayf6031d62019-10-14 09:28:09 +0200990 board_get_alt_info("nand0", buf);
991
Patrick Delaunayfd399a12019-10-14 09:28:11 +0200992 mtd = get_mtd_device_nm("spi-nand0");
993 if (!IS_ERR_OR_NULL(mtd))
994 board_get_alt_info("spi-nand0", buf);
995
Patrick Delaunayb4fee162019-10-14 09:28:12 +0200996#ifdef CONFIG_DFU_VIRT
997 strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
998
999 if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
1000 strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
1001#endif
1002
Patrick Delaunayf6031d62019-10-14 09:28:09 +02001003 env_set("dfu_alt_info", buf);
1004 puts("DFU alt info setting: done\n");
1005}
Patrick Delaunayb4fee162019-10-14 09:28:12 +02001006
1007#if CONFIG_IS_ENABLED(DFU_VIRT)
1008#include <dfu.h>
1009#include <power/stpmic1.h>
1010
1011int dfu_otp_read(u64 offset, u8 *buffer, long *size)
1012{
1013 struct udevice *dev;
1014 int ret;
1015
1016 ret = uclass_get_device_by_driver(UCLASS_MISC,
1017 DM_GET_DRIVER(stm32mp_bsec),
1018 &dev);
1019 if (ret)
1020 return ret;
1021
1022 ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
1023 if (ret >= 0) {
1024 *size = ret;
1025 ret = 0;
1026 }
1027
1028 return 0;
1029}
1030
1031int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
1032{
1033 int ret;
1034#ifdef CONFIG_PMIC_STPMIC1
1035 struct udevice *dev;
1036
1037 ret = uclass_get_device_by_driver(UCLASS_MISC,
1038 DM_GET_DRIVER(stpmic1_nvm),
1039 &dev);
1040 if (ret)
1041 return ret;
1042
1043 ret = misc_read(dev, 0xF8 + offset, buffer, *size);
1044 if (ret >= 0) {
1045 *size = ret;
1046 ret = 0;
1047 }
1048 if (ret == -EACCES) {
1049 *size = 0;
1050 ret = 0;
1051 }
1052#else
1053 pr_err("PMIC update not supported");
1054 ret = -EOPNOTSUPP;
1055#endif
1056
1057 return ret;
1058}
1059
1060int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
1061 void *buf, long *len)
1062{
1063 switch (dfu->data.virt.dev_num) {
1064 case 0x0:
1065 return dfu_otp_read(offset, buf, len);
1066 case 0x1:
1067 return dfu_pmic_read(offset, buf, len);
1068 }
1069 *len = 0;
1070 return 0;
1071}
1072
1073int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
1074{
1075 *size = SZ_1K;
1076
1077 return 0;
1078}
1079
1080#endif
1081
Patrick Delaunayf6031d62019-10-14 09:28:09 +02001082#endif
1083
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +02001084static void board_copro_image_process(ulong fw_image, size_t fw_size)
1085{
1086 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
1087
1088 if (!rproc_is_initialized())
1089 if (rproc_init()) {
1090 printf("Remote Processor %d initialization failed\n",
1091 id);
1092 return;
1093 }
1094
1095 ret = rproc_load(id, fw_image, fw_size);
1096 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
1097 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
1098
Fabien Dessenne790d5b32019-10-30 14:38:32 +01001099 if (!ret)
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +02001100 rproc_start(id);
Patrick Delaunaya68ae8d2019-08-02 15:07:20 +02001101}
1102
1103U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);