blob: ca76579405d1f100eca989fa1e18d5da6bf18e20 [file] [log] [blame]
Tom Rini8b0c8a12018-05-06 18:27:01 -04001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +01002/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +01004 */
Patrice Chotard879cde52019-02-12 16:50:40 +01005#include <common.h>
6#include <adc.h>
Patrick Delaunay500401f2019-06-21 15:26:40 +02007#include <bootm.h>
Patrice Chotard204079b2018-08-10 17:12:14 +02008#include <clk.h>
Patrick Delaunay266bf102019-07-30 19:16:44 +02009#include <config.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020010#include <dm.h>
Simon Glassdb229612019-08-01 09:46:42 -060011#include <env.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060012#include <env_internal.h>
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +010013#include <g_dnl.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020014#include <generic-phy.h>
Simon Glassf11478f2019-12-28 10:45:07 -070015#include <hang.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010016#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070017#include <init.h>
Patrick Delaunay92dc1022019-02-12 11:44:41 +010018#include <led.h>
Simon Glass9bc15642020-02-03 07:36:16 -070019#include <malloc.h>
Patrick Delaunay093f6e12019-10-14 09:28:09 +020020#include <memalign.h>
Patrick Delaunay92dc1022019-02-12 11:44:41 +010021#include <misc.h>
Patrick Delaunayde98cbf2019-07-02 13:26:07 +020022#include <mtd.h>
23#include <mtd_node.h>
Patrick Delaunaybff66f92019-08-01 11:29:03 +020024#include <netdev.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020025#include <phy.h>
Patrick Delaunayc17d7252019-08-02 15:07:20 +020026#include <remoteproc.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020027#include <reset.h>
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010028#include <syscon.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010029#include <usb.h>
Patrick Delaunayae0931d02019-07-30 19:16:39 +020030#include <watchdog.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020031#include <asm/io.h>
Patrick Delaunayf2a7b872019-02-27 17:01:18 +010032#include <asm/gpio.h>
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010033#include <asm/arch/stm32.h>
Patrice Chotarddad97bf2019-05-02 18:36:01 +020034#include <asm/arch/sys_proto.h>
Patrick Delaunayde98cbf2019-07-02 13:26:07 +020035#include <jffs2/load_kernel.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070036#include <linux/err.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020037#include <power/regulator.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010038#include <usb/dwc2_udc.h>
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010039
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010040/* SYSCFG registers */
41#define SYSCFG_BOOTR 0x00
42#define SYSCFG_PMCSETR 0x04
43#define SYSCFG_IOCTRLSETR 0x18
44#define SYSCFG_ICNR 0x1C
45#define SYSCFG_CMPCR 0x20
46#define SYSCFG_CMPENSETR 0x24
47#define SYSCFG_PMCCLRR 0x44
48
49#define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0)
50#define SYSCFG_BOOTR_BOOTPD_SHIFT 4
51
52#define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0)
53#define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1)
54#define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2)
55#define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3)
56#define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4)
57
58#define SYSCFG_CMPCR_SW_CTRL BIT(1)
59#define SYSCFG_CMPCR_READY BIT(8)
60
61#define SYSCFG_CMPENSETR_MPU_EN BIT(0)
62
63#define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16)
64#define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17)
65
66#define SYSCFG_PMCSETR_ETH_SELMII BIT(20)
67
68#define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21)
Christophe Roullier69ac3f52019-05-17 15:08:43 +020069#define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0
70#define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21)
71#define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23)
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010072
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010073/*
74 * Get a global data pointer
75 */
76DECLARE_GLOBAL_DATA_PTR;
77
Patrice Chotardcded32f2019-04-30 18:09:38 +020078#define USB_LOW_THRESHOLD_UV 200000
Patrice Chotard879cde52019-02-12 16:50:40 +010079#define USB_WARNING_LOW_THRESHOLD_UV 660000
80#define USB_START_LOW_THRESHOLD_UV 1230000
Patrice Chotardcded32f2019-04-30 18:09:38 +020081#define USB_START_HIGH_THRESHOLD_UV 2150000
Patrice Chotard879cde52019-02-12 16:50:40 +010082
Patrick Delaunay92dc1022019-02-12 11:44:41 +010083int checkboard(void)
84{
85 int ret;
86 char *mode;
87 u32 otp;
88 struct udevice *dev;
89 const char *fdt_compat;
90 int fdt_compat_len;
91
Patrick Delaunayff215a42019-07-02 13:26:06 +020092 if (IS_ENABLED(CONFIG_STM32MP1_OPTEE))
93 mode = "trusted with OP-TEE";
94 else if (IS_ENABLED(CONFIG_STM32MP1_TRUSTED))
Patrick Delaunay92dc1022019-02-12 11:44:41 +010095 mode = "trusted";
96 else
97 mode = "basic";
98
99 printf("Board: stm32mp1 in %s mode", mode);
100 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
101 &fdt_compat_len);
102 if (fdt_compat && fdt_compat_len)
103 printf(" (%s)", fdt_compat);
104 puts("\n");
105
106 ret = uclass_get_device_by_driver(UCLASS_MISC,
107 DM_GET_DRIVER(stm32mp_bsec),
108 &dev);
109
110 if (!ret)
111 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
112 &otp, sizeof(otp));
Patrick Delaunaydcb89fd2019-08-02 13:08:05 +0200113 if (ret > 0 && otp) {
Patrick Delaunay92dc1022019-02-12 11:44:41 +0100114 printf("Board: MB%04x Var%d Rev.%c-%02d\n",
115 otp >> 16,
116 (otp >> 12) & 0xF,
117 ((otp >> 8) & 0xF) - 1 + 'A',
118 otp & 0xF);
119 }
120
121 return 0;
122}
123
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100124static void board_key_check(void)
125{
126#if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
127 ofnode node;
128 struct gpio_desc gpio;
129 enum forced_boot_mode boot_mode = BOOT_NORMAL;
130
131 node = ofnode_path("/config");
132 if (!ofnode_valid(node)) {
133 debug("%s: no /config node?\n", __func__);
134 return;
135 }
136#ifdef CONFIG_FASTBOOT
137 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
138 &gpio, GPIOD_IS_IN)) {
139 debug("%s: could not find a /config/st,fastboot-gpios\n",
140 __func__);
141 } else {
142 if (dm_gpio_get_value(&gpio)) {
143 puts("Fastboot key pressed, ");
144 boot_mode = BOOT_FASTBOOT;
145 }
146
147 dm_gpio_free(NULL, &gpio);
148 }
149#endif
150#ifdef CONFIG_CMD_STM32PROG
151 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
152 &gpio, GPIOD_IS_IN)) {
153 debug("%s: could not find a /config/st,stm32prog-gpios\n",
154 __func__);
155 } else {
156 if (dm_gpio_get_value(&gpio)) {
157 puts("STM32Programmer key pressed, ");
158 boot_mode = BOOT_STM32PROG;
159 }
160 dm_gpio_free(NULL, &gpio);
161 }
162#endif
163
164 if (boot_mode != BOOT_NORMAL) {
165 puts("entering download mode...\n");
166 clrsetbits_le32(TAMP_BOOT_CONTEXT,
167 TAMP_BOOT_FORCED_MASK,
168 boot_mode);
169 }
170#endif
171}
172
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100173#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
Patrice Chotard204079b2018-08-10 17:12:14 +0200174
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100175/* STMicroelectronics STUSB1600 Type-C controller */
176#define STUSB1600_CC_CONNECTION_STATUS 0x0E
177
178/* STUSB1600_CC_CONNECTION_STATUS bitfields */
179#define STUSB1600_CC_ATTACH BIT(0)
180
181static int stusb1600_init(struct udevice **dev_stusb1600)
182{
183 ofnode node;
184 struct udevice *dev, *bus;
185 int ret;
186 u32 chip_addr;
187
188 *dev_stusb1600 = NULL;
189
190 /* if node stusb1600 is present, means DK1 or DK2 board */
191 node = ofnode_by_compatible(ofnode_null(), "st,stusb1600");
192 if (!ofnode_valid(node))
193 return -ENODEV;
194
195 ret = ofnode_read_u32(node, "reg", &chip_addr);
196 if (ret)
197 return -EINVAL;
198
199 ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node),
200 &bus);
201 if (ret) {
202 printf("bus for stusb1600 not found\n");
203 return -ENODEV;
204 }
205
206 ret = dm_i2c_probe(bus, chip_addr, 0, &dev);
207 if (!ret)
208 *dev_stusb1600 = dev;
209
210 return ret;
211}
212
213static int stusb1600_cable_connected(struct udevice *dev)
214{
215 u8 status;
216
217 if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1))
218 return 0;
219
220 return status & STUSB1600_CC_ATTACH;
221}
222
223#include <usb/dwc2_udc.h>
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100224int g_dnl_board_usb_cable_connected(void)
Patrice Chotard204079b2018-08-10 17:12:14 +0200225{
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100226 struct udevice *stusb1600;
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100227 struct udevice *dwc2_udc_otg;
Patrice Chotard204079b2018-08-10 17:12:14 +0200228 int ret;
229
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100230 if (!stusb1600_init(&stusb1600))
231 return stusb1600_cable_connected(stusb1600);
232
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100233 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
234 DM_GET_DRIVER(dwc2_udc_otg),
235 &dwc2_udc_otg);
236 if (!ret)
237 debug("dwc2_udc_otg init failed\n");
Patrice Chotard204079b2018-08-10 17:12:14 +0200238
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100239 return dwc2_udc_B_session_valid(dwc2_udc_otg);
Patrice Chotard879cde52019-02-12 16:50:40 +0100240}
Patrick Delaunay0aafce62019-09-13 15:24:17 +0200241
242#define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
243#define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
244
245int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
246{
247 if (!strcmp(name, "usb_dnl_dfu"))
248 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
249 else if (!strcmp(name, "usb_dnl_fastboot"))
250 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
251 &dev->idProduct);
252 else
253 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
254
255 return 0;
256}
257
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100258#endif /* CONFIG_USB_GADGET */
Patrice Chotard879cde52019-02-12 16:50:40 +0100259
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200260#ifdef CONFIG_LED
Patrice Chotard879cde52019-02-12 16:50:40 +0100261static int get_led(struct udevice **dev, char *led_string)
262{
263 char *led_name;
264 int ret;
265
266 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
267 if (!led_name) {
268 pr_debug("%s: could not find %s config string\n",
269 __func__, led_string);
270 return -ENOENT;
271 }
272 ret = led_get_by_label(led_name, dev);
273 if (ret) {
274 debug("%s: get=%d\n", __func__, ret);
275 return ret;
276 }
277
278 return 0;
279}
280
281static int setup_led(enum led_state_t cmd)
282{
283 struct udevice *dev;
284 int ret;
285
286 ret = get_led(&dev, "u-boot,boot-led");
287 if (ret)
288 return ret;
289
290 ret = led_set_state(dev, cmd);
Patrice Chotard204079b2018-08-10 17:12:14 +0200291 return ret;
292}
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200293#endif
294
295static void __maybe_unused led_error_blink(u32 nb_blink)
296{
297#ifdef CONFIG_LED
298 int ret;
299 struct udevice *led;
300 u32 i;
301#endif
302
303 if (!nb_blink)
304 return;
305
306#ifdef CONFIG_LED
307 ret = get_led(&led, "u-boot,error-led");
308 if (!ret) {
309 /* make u-boot,error-led blinking */
310 /* if U32_MAX and 125ms interval, for 17.02 years */
311 for (i = 0; i < 2 * nb_blink; i++) {
312 led_set_state(led, LEDST_TOGGLE);
313 mdelay(125);
314 WATCHDOG_RESET();
315 }
316 }
317#endif
318
319 /* infinite: the boot process must be stopped */
320 if (nb_blink == U32_MAX)
321 hang();
322}
Patrice Chotard204079b2018-08-10 17:12:14 +0200323
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200324#ifdef CONFIG_ADC
Patrice Chotard879cde52019-02-12 16:50:40 +0100325static int board_check_usb_power(void)
326{
327 struct ofnode_phandle_args adc_args;
328 struct udevice *adc;
Patrice Chotard879cde52019-02-12 16:50:40 +0100329 ofnode node;
330 unsigned int raw;
331 int max_uV = 0;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200332 int min_uV = USB_START_HIGH_THRESHOLD_UV;
Patrice Chotard879cde52019-02-12 16:50:40 +0100333 int ret, uV, adc_count;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200334 u32 nb_blink;
335 u8 i;
Patrice Chotard879cde52019-02-12 16:50:40 +0100336 node = ofnode_path("/config");
337 if (!ofnode_valid(node)) {
338 debug("%s: no /config node?\n", __func__);
339 return -ENOENT;
340 }
341
342 /*
343 * Retrieve the ADC channels devices and get measurement
344 * for each of them
345 */
346 adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
347 "#io-channel-cells");
348 if (adc_count < 0) {
349 if (adc_count == -ENOENT)
350 return 0;
351
352 pr_err("%s: can't find adc channel (%d)\n", __func__,
353 adc_count);
354
355 return adc_count;
356 }
357
358 for (i = 0; i < adc_count; i++) {
359 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
360 "#io-channel-cells", 0, i,
361 &adc_args)) {
362 pr_debug("%s: can't find /config/st,adc_usb_pd\n",
363 __func__);
364 return 0;
365 }
366
367 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
368 &adc);
369
370 if (ret) {
371 pr_err("%s: Can't get adc device(%d)\n", __func__,
372 ret);
373 return ret;
374 }
375
376 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
377 &raw);
378 if (ret) {
379 pr_err("%s: single shot failed for %s[%d]!\n",
380 __func__, adc->name, adc_args.args[0]);
381 return ret;
382 }
383 /* Convert to uV */
384 if (!adc_raw_to_uV(adc, raw, &uV)) {
385 if (uV > max_uV)
386 max_uV = uV;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200387 if (uV < min_uV)
388 min_uV = uV;
Patrice Chotard879cde52019-02-12 16:50:40 +0100389 pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
390 adc->name, adc_args.args[0], raw, uV);
391 } else {
392 pr_err("%s: Can't get uV value for %s[%d]\n",
393 __func__, adc->name, adc_args.args[0]);
394 }
395 }
396
397 /*
398 * If highest value is inside 1.23 Volts and 2.10 Volts, that means
399 * board is plugged on an USB-C 3A power supply and boot process can
400 * continue.
401 */
402 if (max_uV > USB_START_LOW_THRESHOLD_UV &&
Patrice Chotardcded32f2019-04-30 18:09:38 +0200403 max_uV <= USB_START_HIGH_THRESHOLD_UV &&
404 min_uV <= USB_LOW_THRESHOLD_UV)
Patrice Chotard879cde52019-02-12 16:50:40 +0100405 return 0;
406
Patrice Chotardcded32f2019-04-30 18:09:38 +0200407 pr_err("****************************************************\n");
408
409 /*
410 * If highest and lowest value are either both below
411 * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
412 * means USB TYPE-C is in unattached mode, this is an issue, make
413 * u-boot,error-led blinking and stop boot process.
414 */
415 if ((max_uV > USB_LOW_THRESHOLD_UV &&
416 min_uV > USB_LOW_THRESHOLD_UV) ||
417 (max_uV <= USB_LOW_THRESHOLD_UV &&
418 min_uV <= USB_LOW_THRESHOLD_UV)) {
419 pr_err("* ERROR USB TYPE-C connection in unattached mode *\n");
420 pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
421 /* with 125ms interval, led will blink for 17.02 years ....*/
422 nb_blink = U32_MAX;
423 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100424
Patrice Chotardcded32f2019-04-30 18:09:38 +0200425 if (max_uV > USB_LOW_THRESHOLD_UV &&
426 max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
427 min_uV <= USB_LOW_THRESHOLD_UV) {
428 pr_err("* WARNING 500mA power supply detected *\n");
Patrice Chotard879cde52019-02-12 16:50:40 +0100429 nb_blink = 2;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200430 }
431
432 if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
433 max_uV <= USB_START_LOW_THRESHOLD_UV &&
434 min_uV <= USB_LOW_THRESHOLD_UV) {
435 pr_err("* WARNING 1.5mA power supply detected *\n");
Patrice Chotard879cde52019-02-12 16:50:40 +0100436 nb_blink = 3;
437 }
438
Patrice Chotardcded32f2019-04-30 18:09:38 +0200439 /*
440 * If highest value is above 2.15 Volts that means that the USB TypeC
441 * supplies more than 3 Amp, this is not compliant with TypeC specification
442 */
443 if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
444 pr_err("* USB TYPE-C charger not compliant with *\n");
445 pr_err("* specification *\n");
446 pr_err("****************************************************\n\n");
447 /* with 125ms interval, led will blink for 17.02 years ....*/
448 nb_blink = U32_MAX;
449 } else {
450 pr_err("* Current too low, use a 3A power supply! *\n");
451 pr_err("****************************************************\n\n");
452 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100453
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200454 led_error_blink(nb_blink);
Patrice Chotard879cde52019-02-12 16:50:40 +0100455
456 return 0;
457}
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200458#endif /* CONFIG_ADC */
Patrice Chotard879cde52019-02-12 16:50:40 +0100459
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100460static void sysconf_init(void)
461{
462#ifndef CONFIG_STM32MP1_TRUSTED
463 u8 *syscfg;
464#ifdef CONFIG_DM_REGULATOR
465 struct udevice *pwr_dev;
466 struct udevice *pwr_reg;
467 struct udevice *dev;
468 int ret;
469 u32 otp = 0;
470#endif
471 u32 bootr;
472
473 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
474
475 /* interconnect update : select master using the port 1 */
476 /* LTDC = AXI_M9 */
477 /* GPU = AXI_M8 */
478 /* today information is hardcoded in U-Boot */
479 writel(BIT(9), syscfg + SYSCFG_ICNR);
480
481 /* disable Pull-Down for boot pin connected to VDD */
482 bootr = readl(syscfg + SYSCFG_BOOTR);
483 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
484 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
485 writel(bootr, syscfg + SYSCFG_BOOTR);
486
487#ifdef CONFIG_DM_REGULATOR
488 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
489 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
490 * The customer will have to disable this for low frequencies
491 * or if AFMUX is selected but the function not used, typically for
492 * TRACE. Otherwise, impact on power consumption.
493 *
494 * WARNING:
495 * enabling High Speed mode while VDD>2.7V
496 * with the OTP product_below_2v5 (OTP 18, BIT 13)
497 * erroneously set to 1 can damage the IC!
498 * => U-Boot set the register only if VDD < 2.7V (in DT)
499 * but this value need to be consistent with board design
500 */
Patrick Delaunay6b2baa02019-07-30 19:16:42 +0200501 ret = uclass_get_device_by_driver(UCLASS_PMIC,
502 DM_GET_DRIVER(stm32mp_pwr_pmic),
503 &pwr_dev);
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100504 if (!ret) {
505 ret = uclass_get_device_by_driver(UCLASS_MISC,
506 DM_GET_DRIVER(stm32mp_bsec),
507 &dev);
508 if (ret) {
509 pr_err("Can't find stm32mp_bsec driver\n");
510 return;
511 }
512
513 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
Patrick Delaunayceb82e32019-08-02 13:08:06 +0200514 if (ret > 0)
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100515 otp = otp & BIT(13);
516
Patrick Delaunay6b2baa02019-07-30 19:16:42 +0200517 /* get VDD = vdd-supply */
518 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100519 &pwr_reg);
520
521 /* check if VDD is Low Voltage */
522 if (!ret) {
523 if (regulator_get_value(pwr_reg) < 2700000) {
524 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
525 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
526 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
527 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
528 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
529 syscfg + SYSCFG_IOCTRLSETR);
530
531 if (!otp)
532 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
533 } else {
534 if (otp)
535 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
536 }
537 } else {
538 debug("VDD unknown");
539 }
540 }
541#endif
542
543 /* activate automatic I/O compensation
544 * warning: need to ensure CSI enabled and ready in clock driver
545 */
546 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
547
548 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
549 ;
550 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
551#endif
552}
553
Patrick Delaunay9f76fdf2019-07-30 19:16:38 +0200554#ifdef CONFIG_DM_REGULATOR
555/* Fix to make I2C1 usable on DK2 for touchscreen usage in kernel */
556static int dk2_i2c1_fix(void)
557{
558 ofnode node;
559 struct gpio_desc hdmi, audio;
560 int ret = 0;
561
562 node = ofnode_path("/soc/i2c@40012000/hdmi-transmitter@39");
563 if (!ofnode_valid(node)) {
564 pr_debug("%s: no hdmi-transmitter@39 ?\n", __func__);
565 return -ENOENT;
566 }
567
568 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
569 &hdmi, GPIOD_IS_OUT)) {
570 pr_debug("%s: could not find reset-gpios\n",
571 __func__);
572 return -ENOENT;
573 }
574
575 node = ofnode_path("/soc/i2c@40012000/cs42l51@4a");
576 if (!ofnode_valid(node)) {
577 pr_debug("%s: no cs42l51@4a ?\n", __func__);
578 return -ENOENT;
579 }
580
581 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
582 &audio, GPIOD_IS_OUT)) {
583 pr_debug("%s: could not find reset-gpios\n",
584 __func__);
585 return -ENOENT;
586 }
587
588 /* before power up, insure that HDMI and AUDIO IC is under reset */
589 ret = dm_gpio_set_value(&hdmi, 1);
590 if (ret) {
591 pr_err("%s: can't set_value for hdmi_nrst gpio", __func__);
592 goto error;
593 }
594 ret = dm_gpio_set_value(&audio, 1);
595 if (ret) {
596 pr_err("%s: can't set_value for audio_nrst gpio", __func__);
597 goto error;
598 }
599
600 /* power-up audio IC */
601 regulator_autoset_by_name("v1v8_audio", NULL);
602
603 /* power-up HDMI IC */
604 regulator_autoset_by_name("v1v2_hdmi", NULL);
605 regulator_autoset_by_name("v3v3_hdmi", NULL);
606
607error:
608 return ret;
609}
610
611static bool board_is_dk2(void)
612{
Patrick Delaunay310aa8a2020-01-13 15:17:42 +0100613 if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
Patrick Delaunay9f76fdf2019-07-30 19:16:38 +0200614 of_machine_is_compatible("st,stm32mp157c-dk2"))
615 return true;
616
617 return false;
618}
619#endif
620
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100621/* board dependent setup after realloc */
622int board_init(void)
623{
Patrice Chotard972723a2019-03-11 11:13:17 +0100624 struct udevice *dev;
625
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100626 /* address of boot parameters */
627 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
628
Patrice Chotard972723a2019-03-11 11:13:17 +0100629 /* probe all PINCTRL for hog */
630 for (uclass_first_device(UCLASS_PINCTRL, &dev);
631 dev;
632 uclass_next_device(&dev)) {
633 pr_debug("probe pincontrol = %s\n", dev->name);
634 }
635
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100636 board_key_check();
637
Patrick Delaunay6519e442019-07-05 17:20:09 +0200638#ifdef CONFIG_DM_REGULATOR
Patrick Delaunay9f76fdf2019-07-30 19:16:38 +0200639 if (board_is_dk2())
640 dk2_i2c1_fix();
641
Patrick Delaunay6519e442019-07-05 17:20:09 +0200642 regulators_enable_boot_on(_DEBUG);
643#endif
644
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100645 sysconf_init();
646
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200647 if (CONFIG_IS_ENABLED(CONFIG_LED))
Patrick Delaunay36e3d112018-07-27 16:37:08 +0200648 led_default_state();
649
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100650 return 0;
651}
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100652
653int board_late_init(void)
654{
Patrick Delaunayf2451262019-07-30 19:16:41 +0200655 char *boot_device;
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100656#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
657 const void *fdt_compat;
658 int fdt_compat_len;
Patrick Delaunaye8566ec2019-07-30 19:16:37 +0200659 int ret;
660 u32 otp;
661 struct udevice *dev;
662 char buf[10];
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100663
664 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
665 &fdt_compat_len);
666 if (fdt_compat && fdt_compat_len) {
667 if (strncmp(fdt_compat, "st,", 3) != 0)
668 env_set("board_name", fdt_compat);
669 else
670 env_set("board_name", fdt_compat + 3);
671 }
Patrick Delaunaye8566ec2019-07-30 19:16:37 +0200672 ret = uclass_get_device_by_driver(UCLASS_MISC,
673 DM_GET_DRIVER(stm32mp_bsec),
674 &dev);
675
676 if (!ret)
677 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
678 &otp, sizeof(otp));
679 if (!ret && otp) {
680 snprintf(buf, sizeof(buf), "0x%04x", otp >> 16);
681 env_set("board_id", buf);
682
683 snprintf(buf, sizeof(buf), "0x%04x",
684 ((otp >> 8) & 0xF) - 1 + 0xA);
685 env_set("board_rev", buf);
686 }
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100687#endif
688
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200689#ifdef CONFIG_ADC
Patrice Chotard879cde52019-02-12 16:50:40 +0100690 /* for DK1/DK2 boards */
691 board_check_usb_power();
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200692#endif /* CONFIG_ADC */
Patrice Chotard879cde52019-02-12 16:50:40 +0100693
Patrick Delaunayf2451262019-07-30 19:16:41 +0200694 /* Check the boot-source to disable bootdelay */
695 boot_device = env_get("boot_device");
696 if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
697 env_set("bootdelay", "0");
698
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100699 return 0;
700}
Patrice Chotard879cde52019-02-12 16:50:40 +0100701
702void board_quiesce_devices(void)
703{
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200704#ifdef CONFIG_LED
Patrice Chotard879cde52019-02-12 16:50:40 +0100705 setup_led(LEDST_OFF);
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200706#endif
Patrice Chotard879cde52019-02-12 16:50:40 +0100707}
Patrice Chotard41443cf2019-05-02 18:07:14 +0200708
Patrick Delaunaybff66f92019-08-01 11:29:03 +0200709/* eth init function : weak called in eqos driver */
710int board_interface_eth_init(struct udevice *dev,
711 phy_interface_t interface_type)
Christophe Roullier69ac3f52019-05-17 15:08:43 +0200712{
713 u8 *syscfg;
714 u32 value;
Patrick Delaunaybff66f92019-08-01 11:29:03 +0200715 bool eth_clk_sel_reg = false;
716 bool eth_ref_clk_sel_reg = false;
717
718 /* Gigabit Ethernet 125MHz clock selection. */
719 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
720
721 /* Ethernet 50Mhz RMII clock selection */
722 eth_ref_clk_sel_reg =
723 dev_read_bool(dev, "st,eth_ref_clk_sel");
Christophe Roullier69ac3f52019-05-17 15:08:43 +0200724
725 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
726
727 if (!syscfg)
728 return -ENODEV;
729
730 switch (interface_type) {
731 case PHY_INTERFACE_MODE_MII:
732 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
733 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
734 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
735 break;
736 case PHY_INTERFACE_MODE_GMII:
737 if (eth_clk_sel_reg)
738 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
739 SYSCFG_PMCSETR_ETH_CLK_SEL;
740 else
741 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
742 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
743 break;
744 case PHY_INTERFACE_MODE_RMII:
745 if (eth_ref_clk_sel_reg)
746 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
747 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
748 else
749 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
750 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
751 break;
752 case PHY_INTERFACE_MODE_RGMII:
753 case PHY_INTERFACE_MODE_RGMII_ID:
754 case PHY_INTERFACE_MODE_RGMII_RXID:
755 case PHY_INTERFACE_MODE_RGMII_TXID:
756 if (eth_clk_sel_reg)
757 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
758 SYSCFG_PMCSETR_ETH_CLK_SEL;
759 else
760 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
761 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
762 break;
763 default:
764 debug("%s: Do not manage %d interface\n",
765 __func__, interface_type);
766 /* Do not manage others interfaces */
767 return -EINVAL;
768 }
769
770 /* clear and set ETH configuration bits */
771 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
772 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
773 syscfg + SYSCFG_PMCCLRR);
774 writel(value, syscfg + SYSCFG_PMCSETR);
775
776 return 0;
777}
778
Patrice Chotard34320372019-05-02 18:28:05 +0200779enum env_location env_get_location(enum env_operation op, int prio)
780{
781 u32 bootmode = get_bootmode();
782
783 if (prio)
784 return ENVL_UNKNOWN;
785
786 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
787#ifdef CONFIG_ENV_IS_IN_EXT4
788 case BOOT_FLASH_SD:
789 case BOOT_FLASH_EMMC:
790 return ENVL_EXT4;
791#endif
792#ifdef CONFIG_ENV_IS_IN_UBI
793 case BOOT_FLASH_NAND:
794 return ENVL_UBI;
795#endif
Patrice Chotard2c461ec2019-05-09 14:25:36 +0200796#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
797 case BOOT_FLASH_NOR:
798 return ENVL_SPI_FLASH;
799#endif
Patrice Chotard34320372019-05-02 18:28:05 +0200800 default:
801 return ENVL_NOWHERE;
802 }
803}
804
Patrice Chotarddad97bf2019-05-02 18:36:01 +0200805#if defined(CONFIG_ENV_IS_IN_EXT4)
806const char *env_ext4_get_intf(void)
807{
808 u32 bootmode = get_bootmode();
809
810 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
811 case BOOT_FLASH_SD:
812 case BOOT_FLASH_EMMC:
813 return "mmc";
814 default:
815 return "";
816 }
817}
818
819const char *env_ext4_get_dev_part(void)
820{
821 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
822 u32 bootmode = get_bootmode();
823
824 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
825}
826#endif
827
Patrice Chotard41443cf2019-05-02 18:07:14 +0200828#ifdef CONFIG_SYS_MTDPARTS_RUNTIME
829
830#define MTDPARTS_LEN 256
831#define MTDIDS_LEN 128
832
833/**
834 * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
835 * If we need to access it before the env is relocated, then we need
836 * to use our own stack buffer. gd->env_buf will be too small.
837 *
838 * @param buf temporary buffer pointer MTDPARTS_LEN long
839 * @return mtdparts variable string, NULL if not found
840 */
841static const char *env_get_mtdparts(const char *str, char *buf)
842{
843 if (gd->flags & GD_FLG_ENV_READY)
844 return env_get(str);
845 if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
846 return buf;
847
848 return NULL;
849}
850
851/**
852 * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
853 */
854static void board_get_mtdparts(const char *dev,
855 char *mtdids,
856 char *mtdparts)
857{
858 char env_name[32] = "mtdparts_";
859 char tmp_mtdparts[MTDPARTS_LEN];
860 const char *tmp;
861
862 /* name of env variable to read = mtdparts_<dev> */
863 strcat(env_name, dev);
864 tmp = env_get_mtdparts(env_name, tmp_mtdparts);
865 if (tmp) {
866 /* mtdids: "<dev>=<dev>, ...." */
867 if (mtdids[0] != '\0')
868 strcat(mtdids, ",");
869 strcat(mtdids, dev);
870 strcat(mtdids, "=");
871 strcat(mtdids, dev);
872
873 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
874 if (mtdparts[0] != '\0')
875 strncat(mtdparts, ";", MTDPARTS_LEN);
876 else
877 strcat(mtdparts, "mtdparts=");
878 strncat(mtdparts, dev, MTDPARTS_LEN);
879 strncat(mtdparts, ":", MTDPARTS_LEN);
880 strncat(mtdparts, tmp, MTDPARTS_LEN);
881 }
882}
883
884void board_mtdparts_default(const char **mtdids, const char **mtdparts)
885{
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200886 struct mtd_info *mtd;
Patrice Chotard41443cf2019-05-02 18:07:14 +0200887 struct udevice *dev;
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200888 static char parts[3 * MTDPARTS_LEN + 1];
Patrice Chotard41443cf2019-05-02 18:07:14 +0200889 static char ids[MTDIDS_LEN + 1];
890 static bool mtd_initialized;
891
892 if (mtd_initialized) {
893 *mtdids = ids;
894 *mtdparts = parts;
895 return;
896 }
897
898 memset(parts, 0, sizeof(parts));
899 memset(ids, 0, sizeof(ids));
900
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200901 /* probe all MTD devices */
902 for (uclass_first_device(UCLASS_MTD, &dev);
903 dev;
904 uclass_next_device(&dev)) {
905 pr_debug("mtd device = %s\n", dev->name);
906 }
907
908 mtd = get_mtd_device_nm("nand0");
909 if (!IS_ERR_OR_NULL(mtd)) {
Patrice Chotard41443cf2019-05-02 18:07:14 +0200910 board_get_mtdparts("nand0", ids, parts);
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200911 put_mtd_device(mtd);
912 }
913
914 mtd = get_mtd_device_nm("spi-nand0");
915 if (!IS_ERR_OR_NULL(mtd)) {
916 board_get_mtdparts("spi-nand0", ids, parts);
917 put_mtd_device(mtd);
918 }
Patrice Chotard41443cf2019-05-02 18:07:14 +0200919
920 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
921 board_get_mtdparts("nor0", ids, parts);
922
923 mtd_initialized = true;
924 *mtdids = ids;
925 *mtdparts = parts;
926 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
927}
928#endif
Patrick Delaunayde98cbf2019-07-02 13:26:07 +0200929
930#if defined(CONFIG_OF_BOARD_SETUP)
931int ft_board_setup(void *blob, bd_t *bd)
932{
933#ifdef CONFIG_FDT_FIXUP_PARTITIONS
934 struct node_info nodes[] = {
935 { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
936 { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
937 };
938 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
939#endif
940
941 return 0;
942}
943#endif
Patrick Delaunayc17d7252019-08-02 15:07:20 +0200944
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200945#ifdef CONFIG_SET_DFU_ALT_INFO
946#define DFU_ALT_BUF_LEN SZ_1K
947
948static void board_get_alt_info(const char *dev, char *buff)
949{
950 char var_name[32] = "dfu_alt_info_";
951 int ret;
952
953 ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
954
955 /* name of env variable to read = dfu_alt_info_<dev> */
956 strcat(var_name, dev);
957 ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
958 if (ret) {
959 if (buff[0] != '\0')
960 strcat(buff, "&");
961 strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
962 }
963}
964
965void set_dfu_alt_info(char *interface, char *devstr)
966{
967 struct udevice *dev;
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200968 struct mtd_info *mtd;
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200969
970 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
971
972 if (env_get("dfu_alt_info"))
973 return;
974
975 memset(buf, 0, sizeof(buf));
976
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200977 /* probe all MTD devices */
978 mtd_probe_devices();
979
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200980 board_get_alt_info("ram", buf);
981
982 if (!uclass_get_device(UCLASS_MMC, 0, &dev))
983 board_get_alt_info("mmc0", buf);
984
985 if (!uclass_get_device(UCLASS_MMC, 1, &dev))
986 board_get_alt_info("mmc1", buf);
987
988 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
989 board_get_alt_info("nor0", buf);
990
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200991 mtd = get_mtd_device_nm("nand0");
992 if (!IS_ERR_OR_NULL(mtd))
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200993 board_get_alt_info("nand0", buf);
994
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200995 mtd = get_mtd_device_nm("spi-nand0");
996 if (!IS_ERR_OR_NULL(mtd))
997 board_get_alt_info("spi-nand0", buf);
998
Patrick Delaunay8e5031b2019-10-14 09:28:12 +0200999#ifdef CONFIG_DFU_VIRT
1000 strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
1001
1002 if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
1003 strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
1004#endif
1005
Patrick Delaunay093f6e12019-10-14 09:28:09 +02001006 env_set("dfu_alt_info", buf);
1007 puts("DFU alt info setting: done\n");
1008}
Patrick Delaunay8e5031b2019-10-14 09:28:12 +02001009
1010#if CONFIG_IS_ENABLED(DFU_VIRT)
1011#include <dfu.h>
1012#include <power/stpmic1.h>
1013
1014int dfu_otp_read(u64 offset, u8 *buffer, long *size)
1015{
1016 struct udevice *dev;
1017 int ret;
1018
1019 ret = uclass_get_device_by_driver(UCLASS_MISC,
1020 DM_GET_DRIVER(stm32mp_bsec),
1021 &dev);
1022 if (ret)
1023 return ret;
1024
1025 ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
1026 if (ret >= 0) {
1027 *size = ret;
1028 ret = 0;
1029 }
1030
1031 return 0;
1032}
1033
1034int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
1035{
1036 int ret;
1037#ifdef CONFIG_PMIC_STPMIC1
1038 struct udevice *dev;
1039
1040 ret = uclass_get_device_by_driver(UCLASS_MISC,
1041 DM_GET_DRIVER(stpmic1_nvm),
1042 &dev);
1043 if (ret)
1044 return ret;
1045
1046 ret = misc_read(dev, 0xF8 + offset, buffer, *size);
1047 if (ret >= 0) {
1048 *size = ret;
1049 ret = 0;
1050 }
1051 if (ret == -EACCES) {
1052 *size = 0;
1053 ret = 0;
1054 }
1055#else
1056 pr_err("PMIC update not supported");
1057 ret = -EOPNOTSUPP;
1058#endif
1059
1060 return ret;
1061}
1062
1063int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
1064 void *buf, long *len)
1065{
1066 switch (dfu->data.virt.dev_num) {
1067 case 0x0:
1068 return dfu_otp_read(offset, buf, len);
1069 case 0x1:
1070 return dfu_pmic_read(offset, buf, len);
1071 }
1072 *len = 0;
1073 return 0;
1074}
1075
1076int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
1077{
1078 *size = SZ_1K;
1079
1080 return 0;
1081}
1082
1083#endif
1084
Patrick Delaunay093f6e12019-10-14 09:28:09 +02001085#endif
1086
Patrick Delaunayc17d7252019-08-02 15:07:20 +02001087static void board_copro_image_process(ulong fw_image, size_t fw_size)
1088{
1089 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
1090
1091 if (!rproc_is_initialized())
1092 if (rproc_init()) {
1093 printf("Remote Processor %d initialization failed\n",
1094 id);
1095 return;
1096 }
1097
1098 ret = rproc_load(id, fw_image, fw_size);
1099 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
1100 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
1101
Fabien Dessennead6cc942019-10-30 14:38:32 +01001102 if (!ret)
Patrick Delaunayc17d7252019-08-02 15:07:20 +02001103 rproc_start(id);
Patrick Delaunayc17d7252019-08-02 15:07:20 +02001104}
1105
1106U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);