blob: 4ed2d8884964bfe00ebc75232848ffb6d0f15da2 [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>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010015#include <i2c.h>
Patrick Delaunay92dc1022019-02-12 11:44:41 +010016#include <led.h>
Patrick Delaunay093f6e12019-10-14 09:28:09 +020017#include <memalign.h>
Patrick Delaunay92dc1022019-02-12 11:44:41 +010018#include <misc.h>
Patrick Delaunayde98cbf2019-07-02 13:26:07 +020019#include <mtd.h>
20#include <mtd_node.h>
Patrick Delaunaybff66f92019-08-01 11:29:03 +020021#include <netdev.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020022#include <phy.h>
Patrick Delaunayc17d7252019-08-02 15:07:20 +020023#include <remoteproc.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020024#include <reset.h>
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010025#include <syscon.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010026#include <usb.h>
Patrick Delaunayae0931d02019-07-30 19:16:39 +020027#include <watchdog.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020028#include <asm/io.h>
Patrick Delaunayf2a7b872019-02-27 17:01:18 +010029#include <asm/gpio.h>
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010030#include <asm/arch/stm32.h>
Patrice Chotarddad97bf2019-05-02 18:36:01 +020031#include <asm/arch/sys_proto.h>
Patrick Delaunayde98cbf2019-07-02 13:26:07 +020032#include <jffs2/load_kernel.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020033#include <power/regulator.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010034#include <usb/dwc2_udc.h>
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010035
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010036/* SYSCFG registers */
37#define SYSCFG_BOOTR 0x00
38#define SYSCFG_PMCSETR 0x04
39#define SYSCFG_IOCTRLSETR 0x18
40#define SYSCFG_ICNR 0x1C
41#define SYSCFG_CMPCR 0x20
42#define SYSCFG_CMPENSETR 0x24
43#define SYSCFG_PMCCLRR 0x44
44
45#define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0)
46#define SYSCFG_BOOTR_BOOTPD_SHIFT 4
47
48#define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0)
49#define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1)
50#define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2)
51#define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3)
52#define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4)
53
54#define SYSCFG_CMPCR_SW_CTRL BIT(1)
55#define SYSCFG_CMPCR_READY BIT(8)
56
57#define SYSCFG_CMPENSETR_MPU_EN BIT(0)
58
59#define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16)
60#define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17)
61
62#define SYSCFG_PMCSETR_ETH_SELMII BIT(20)
63
64#define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21)
Christophe Roullier69ac3f52019-05-17 15:08:43 +020065#define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0
66#define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21)
67#define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23)
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010068
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010069/*
70 * Get a global data pointer
71 */
72DECLARE_GLOBAL_DATA_PTR;
73
Patrice Chotardcded32f2019-04-30 18:09:38 +020074#define USB_LOW_THRESHOLD_UV 200000
Patrice Chotard879cde52019-02-12 16:50:40 +010075#define USB_WARNING_LOW_THRESHOLD_UV 660000
76#define USB_START_LOW_THRESHOLD_UV 1230000
Patrice Chotardcded32f2019-04-30 18:09:38 +020077#define USB_START_HIGH_THRESHOLD_UV 2150000
Patrice Chotard879cde52019-02-12 16:50:40 +010078
Patrick Delaunay92dc1022019-02-12 11:44:41 +010079int checkboard(void)
80{
81 int ret;
82 char *mode;
83 u32 otp;
84 struct udevice *dev;
85 const char *fdt_compat;
86 int fdt_compat_len;
87
Patrick Delaunayff215a42019-07-02 13:26:06 +020088 if (IS_ENABLED(CONFIG_STM32MP1_OPTEE))
89 mode = "trusted with OP-TEE";
90 else if (IS_ENABLED(CONFIG_STM32MP1_TRUSTED))
Patrick Delaunay92dc1022019-02-12 11:44:41 +010091 mode = "trusted";
92 else
93 mode = "basic";
94
95 printf("Board: stm32mp1 in %s mode", mode);
96 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
97 &fdt_compat_len);
98 if (fdt_compat && fdt_compat_len)
99 printf(" (%s)", fdt_compat);
100 puts("\n");
101
102 ret = uclass_get_device_by_driver(UCLASS_MISC,
103 DM_GET_DRIVER(stm32mp_bsec),
104 &dev);
105
106 if (!ret)
107 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
108 &otp, sizeof(otp));
Patrick Delaunaydcb89fd2019-08-02 13:08:05 +0200109 if (ret > 0 && otp) {
Patrick Delaunay92dc1022019-02-12 11:44:41 +0100110 printf("Board: MB%04x Var%d Rev.%c-%02d\n",
111 otp >> 16,
112 (otp >> 12) & 0xF,
113 ((otp >> 8) & 0xF) - 1 + 'A',
114 otp & 0xF);
115 }
116
117 return 0;
118}
119
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100120static void board_key_check(void)
121{
122#if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
123 ofnode node;
124 struct gpio_desc gpio;
125 enum forced_boot_mode boot_mode = BOOT_NORMAL;
126
127 node = ofnode_path("/config");
128 if (!ofnode_valid(node)) {
129 debug("%s: no /config node?\n", __func__);
130 return;
131 }
132#ifdef CONFIG_FASTBOOT
133 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
134 &gpio, GPIOD_IS_IN)) {
135 debug("%s: could not find a /config/st,fastboot-gpios\n",
136 __func__);
137 } else {
138 if (dm_gpio_get_value(&gpio)) {
139 puts("Fastboot key pressed, ");
140 boot_mode = BOOT_FASTBOOT;
141 }
142
143 dm_gpio_free(NULL, &gpio);
144 }
145#endif
146#ifdef CONFIG_CMD_STM32PROG
147 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
148 &gpio, GPIOD_IS_IN)) {
149 debug("%s: could not find a /config/st,stm32prog-gpios\n",
150 __func__);
151 } else {
152 if (dm_gpio_get_value(&gpio)) {
153 puts("STM32Programmer key pressed, ");
154 boot_mode = BOOT_STM32PROG;
155 }
156 dm_gpio_free(NULL, &gpio);
157 }
158#endif
159
160 if (boot_mode != BOOT_NORMAL) {
161 puts("entering download mode...\n");
162 clrsetbits_le32(TAMP_BOOT_CONTEXT,
163 TAMP_BOOT_FORCED_MASK,
164 boot_mode);
165 }
166#endif
167}
168
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100169#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
Patrice Chotard204079b2018-08-10 17:12:14 +0200170
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100171/* STMicroelectronics STUSB1600 Type-C controller */
172#define STUSB1600_CC_CONNECTION_STATUS 0x0E
173
174/* STUSB1600_CC_CONNECTION_STATUS bitfields */
175#define STUSB1600_CC_ATTACH BIT(0)
176
177static int stusb1600_init(struct udevice **dev_stusb1600)
178{
179 ofnode node;
180 struct udevice *dev, *bus;
181 int ret;
182 u32 chip_addr;
183
184 *dev_stusb1600 = NULL;
185
186 /* if node stusb1600 is present, means DK1 or DK2 board */
187 node = ofnode_by_compatible(ofnode_null(), "st,stusb1600");
188 if (!ofnode_valid(node))
189 return -ENODEV;
190
191 ret = ofnode_read_u32(node, "reg", &chip_addr);
192 if (ret)
193 return -EINVAL;
194
195 ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node),
196 &bus);
197 if (ret) {
198 printf("bus for stusb1600 not found\n");
199 return -ENODEV;
200 }
201
202 ret = dm_i2c_probe(bus, chip_addr, 0, &dev);
203 if (!ret)
204 *dev_stusb1600 = dev;
205
206 return ret;
207}
208
209static int stusb1600_cable_connected(struct udevice *dev)
210{
211 u8 status;
212
213 if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1))
214 return 0;
215
216 return status & STUSB1600_CC_ATTACH;
217}
218
219#include <usb/dwc2_udc.h>
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100220int g_dnl_board_usb_cable_connected(void)
Patrice Chotard204079b2018-08-10 17:12:14 +0200221{
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100222 struct udevice *stusb1600;
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100223 struct udevice *dwc2_udc_otg;
Patrice Chotard204079b2018-08-10 17:12:14 +0200224 int ret;
225
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100226 if (!stusb1600_init(&stusb1600))
227 return stusb1600_cable_connected(stusb1600);
228
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100229 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
230 DM_GET_DRIVER(dwc2_udc_otg),
231 &dwc2_udc_otg);
232 if (!ret)
233 debug("dwc2_udc_otg init failed\n");
Patrice Chotard204079b2018-08-10 17:12:14 +0200234
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100235 return dwc2_udc_B_session_valid(dwc2_udc_otg);
Patrice Chotard879cde52019-02-12 16:50:40 +0100236}
Patrick Delaunay0aafce62019-09-13 15:24:17 +0200237
238#define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
239#define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
240
241int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
242{
243 if (!strcmp(name, "usb_dnl_dfu"))
244 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
245 else if (!strcmp(name, "usb_dnl_fastboot"))
246 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
247 &dev->idProduct);
248 else
249 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
250
251 return 0;
252}
253
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100254#endif /* CONFIG_USB_GADGET */
Patrice Chotard879cde52019-02-12 16:50:40 +0100255
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200256#ifdef CONFIG_LED
Patrice Chotard879cde52019-02-12 16:50:40 +0100257static int get_led(struct udevice **dev, char *led_string)
258{
259 char *led_name;
260 int ret;
261
262 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
263 if (!led_name) {
264 pr_debug("%s: could not find %s config string\n",
265 __func__, led_string);
266 return -ENOENT;
267 }
268 ret = led_get_by_label(led_name, dev);
269 if (ret) {
270 debug("%s: get=%d\n", __func__, ret);
271 return ret;
272 }
273
274 return 0;
275}
276
277static int setup_led(enum led_state_t cmd)
278{
279 struct udevice *dev;
280 int ret;
281
282 ret = get_led(&dev, "u-boot,boot-led");
283 if (ret)
284 return ret;
285
286 ret = led_set_state(dev, cmd);
Patrice Chotard204079b2018-08-10 17:12:14 +0200287 return ret;
288}
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200289#endif
290
291static void __maybe_unused led_error_blink(u32 nb_blink)
292{
293#ifdef CONFIG_LED
294 int ret;
295 struct udevice *led;
296 u32 i;
297#endif
298
299 if (!nb_blink)
300 return;
301
302#ifdef CONFIG_LED
303 ret = get_led(&led, "u-boot,error-led");
304 if (!ret) {
305 /* make u-boot,error-led blinking */
306 /* if U32_MAX and 125ms interval, for 17.02 years */
307 for (i = 0; i < 2 * nb_blink; i++) {
308 led_set_state(led, LEDST_TOGGLE);
309 mdelay(125);
310 WATCHDOG_RESET();
311 }
312 }
313#endif
314
315 /* infinite: the boot process must be stopped */
316 if (nb_blink == U32_MAX)
317 hang();
318}
Patrice Chotard204079b2018-08-10 17:12:14 +0200319
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200320#ifdef CONFIG_ADC
Patrice Chotard879cde52019-02-12 16:50:40 +0100321static int board_check_usb_power(void)
322{
323 struct ofnode_phandle_args adc_args;
324 struct udevice *adc;
Patrice Chotard879cde52019-02-12 16:50:40 +0100325 ofnode node;
326 unsigned int raw;
327 int max_uV = 0;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200328 int min_uV = USB_START_HIGH_THRESHOLD_UV;
Patrice Chotard879cde52019-02-12 16:50:40 +0100329 int ret, uV, adc_count;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200330 u32 nb_blink;
331 u8 i;
Patrice Chotard879cde52019-02-12 16:50:40 +0100332 node = ofnode_path("/config");
333 if (!ofnode_valid(node)) {
334 debug("%s: no /config node?\n", __func__);
335 return -ENOENT;
336 }
337
338 /*
339 * Retrieve the ADC channels devices and get measurement
340 * for each of them
341 */
342 adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
343 "#io-channel-cells");
344 if (adc_count < 0) {
345 if (adc_count == -ENOENT)
346 return 0;
347
348 pr_err("%s: can't find adc channel (%d)\n", __func__,
349 adc_count);
350
351 return adc_count;
352 }
353
354 for (i = 0; i < adc_count; i++) {
355 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
356 "#io-channel-cells", 0, i,
357 &adc_args)) {
358 pr_debug("%s: can't find /config/st,adc_usb_pd\n",
359 __func__);
360 return 0;
361 }
362
363 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
364 &adc);
365
366 if (ret) {
367 pr_err("%s: Can't get adc device(%d)\n", __func__,
368 ret);
369 return ret;
370 }
371
372 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
373 &raw);
374 if (ret) {
375 pr_err("%s: single shot failed for %s[%d]!\n",
376 __func__, adc->name, adc_args.args[0]);
377 return ret;
378 }
379 /* Convert to uV */
380 if (!adc_raw_to_uV(adc, raw, &uV)) {
381 if (uV > max_uV)
382 max_uV = uV;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200383 if (uV < min_uV)
384 min_uV = uV;
Patrice Chotard879cde52019-02-12 16:50:40 +0100385 pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
386 adc->name, adc_args.args[0], raw, uV);
387 } else {
388 pr_err("%s: Can't get uV value for %s[%d]\n",
389 __func__, adc->name, adc_args.args[0]);
390 }
391 }
392
393 /*
394 * If highest value is inside 1.23 Volts and 2.10 Volts, that means
395 * board is plugged on an USB-C 3A power supply and boot process can
396 * continue.
397 */
398 if (max_uV > USB_START_LOW_THRESHOLD_UV &&
Patrice Chotardcded32f2019-04-30 18:09:38 +0200399 max_uV <= USB_START_HIGH_THRESHOLD_UV &&
400 min_uV <= USB_LOW_THRESHOLD_UV)
Patrice Chotard879cde52019-02-12 16:50:40 +0100401 return 0;
402
Patrice Chotardcded32f2019-04-30 18:09:38 +0200403 pr_err("****************************************************\n");
404
405 /*
406 * If highest and lowest value are either both below
407 * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
408 * means USB TYPE-C is in unattached mode, this is an issue, make
409 * u-boot,error-led blinking and stop boot process.
410 */
411 if ((max_uV > USB_LOW_THRESHOLD_UV &&
412 min_uV > USB_LOW_THRESHOLD_UV) ||
413 (max_uV <= USB_LOW_THRESHOLD_UV &&
414 min_uV <= USB_LOW_THRESHOLD_UV)) {
415 pr_err("* ERROR USB TYPE-C connection in unattached mode *\n");
416 pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
417 /* with 125ms interval, led will blink for 17.02 years ....*/
418 nb_blink = U32_MAX;
419 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100420
Patrice Chotardcded32f2019-04-30 18:09:38 +0200421 if (max_uV > USB_LOW_THRESHOLD_UV &&
422 max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
423 min_uV <= USB_LOW_THRESHOLD_UV) {
424 pr_err("* WARNING 500mA power supply detected *\n");
Patrice Chotard879cde52019-02-12 16:50:40 +0100425 nb_blink = 2;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200426 }
427
428 if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
429 max_uV <= USB_START_LOW_THRESHOLD_UV &&
430 min_uV <= USB_LOW_THRESHOLD_UV) {
431 pr_err("* WARNING 1.5mA power supply detected *\n");
Patrice Chotard879cde52019-02-12 16:50:40 +0100432 nb_blink = 3;
433 }
434
Patrice Chotardcded32f2019-04-30 18:09:38 +0200435 /*
436 * If highest value is above 2.15 Volts that means that the USB TypeC
437 * supplies more than 3 Amp, this is not compliant with TypeC specification
438 */
439 if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
440 pr_err("* USB TYPE-C charger not compliant with *\n");
441 pr_err("* specification *\n");
442 pr_err("****************************************************\n\n");
443 /* with 125ms interval, led will blink for 17.02 years ....*/
444 nb_blink = U32_MAX;
445 } else {
446 pr_err("* Current too low, use a 3A power supply! *\n");
447 pr_err("****************************************************\n\n");
448 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100449
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200450 led_error_blink(nb_blink);
Patrice Chotard879cde52019-02-12 16:50:40 +0100451
452 return 0;
453}
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200454#endif /* CONFIG_ADC */
Patrice Chotard879cde52019-02-12 16:50:40 +0100455
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100456static void sysconf_init(void)
457{
458#ifndef CONFIG_STM32MP1_TRUSTED
459 u8 *syscfg;
460#ifdef CONFIG_DM_REGULATOR
461 struct udevice *pwr_dev;
462 struct udevice *pwr_reg;
463 struct udevice *dev;
464 int ret;
465 u32 otp = 0;
466#endif
467 u32 bootr;
468
469 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
470
471 /* interconnect update : select master using the port 1 */
472 /* LTDC = AXI_M9 */
473 /* GPU = AXI_M8 */
474 /* today information is hardcoded in U-Boot */
475 writel(BIT(9), syscfg + SYSCFG_ICNR);
476
477 /* disable Pull-Down for boot pin connected to VDD */
478 bootr = readl(syscfg + SYSCFG_BOOTR);
479 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
480 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
481 writel(bootr, syscfg + SYSCFG_BOOTR);
482
483#ifdef CONFIG_DM_REGULATOR
484 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
485 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
486 * The customer will have to disable this for low frequencies
487 * or if AFMUX is selected but the function not used, typically for
488 * TRACE. Otherwise, impact on power consumption.
489 *
490 * WARNING:
491 * enabling High Speed mode while VDD>2.7V
492 * with the OTP product_below_2v5 (OTP 18, BIT 13)
493 * erroneously set to 1 can damage the IC!
494 * => U-Boot set the register only if VDD < 2.7V (in DT)
495 * but this value need to be consistent with board design
496 */
Patrick Delaunay6b2baa02019-07-30 19:16:42 +0200497 ret = uclass_get_device_by_driver(UCLASS_PMIC,
498 DM_GET_DRIVER(stm32mp_pwr_pmic),
499 &pwr_dev);
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100500 if (!ret) {
501 ret = uclass_get_device_by_driver(UCLASS_MISC,
502 DM_GET_DRIVER(stm32mp_bsec),
503 &dev);
504 if (ret) {
505 pr_err("Can't find stm32mp_bsec driver\n");
506 return;
507 }
508
509 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
Patrick Delaunayceb82e32019-08-02 13:08:06 +0200510 if (ret > 0)
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100511 otp = otp & BIT(13);
512
Patrick Delaunay6b2baa02019-07-30 19:16:42 +0200513 /* get VDD = vdd-supply */
514 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100515 &pwr_reg);
516
517 /* check if VDD is Low Voltage */
518 if (!ret) {
519 if (regulator_get_value(pwr_reg) < 2700000) {
520 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
521 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
522 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
523 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
524 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
525 syscfg + SYSCFG_IOCTRLSETR);
526
527 if (!otp)
528 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
529 } else {
530 if (otp)
531 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
532 }
533 } else {
534 debug("VDD unknown");
535 }
536 }
537#endif
538
539 /* activate automatic I/O compensation
540 * warning: need to ensure CSI enabled and ready in clock driver
541 */
542 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
543
544 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
545 ;
546 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
547#endif
548}
549
Patrick Delaunay9f76fdf2019-07-30 19:16:38 +0200550#ifdef CONFIG_DM_REGULATOR
551/* Fix to make I2C1 usable on DK2 for touchscreen usage in kernel */
552static int dk2_i2c1_fix(void)
553{
554 ofnode node;
555 struct gpio_desc hdmi, audio;
556 int ret = 0;
557
558 node = ofnode_path("/soc/i2c@40012000/hdmi-transmitter@39");
559 if (!ofnode_valid(node)) {
560 pr_debug("%s: no hdmi-transmitter@39 ?\n", __func__);
561 return -ENOENT;
562 }
563
564 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
565 &hdmi, GPIOD_IS_OUT)) {
566 pr_debug("%s: could not find reset-gpios\n",
567 __func__);
568 return -ENOENT;
569 }
570
571 node = ofnode_path("/soc/i2c@40012000/cs42l51@4a");
572 if (!ofnode_valid(node)) {
573 pr_debug("%s: no cs42l51@4a ?\n", __func__);
574 return -ENOENT;
575 }
576
577 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
578 &audio, GPIOD_IS_OUT)) {
579 pr_debug("%s: could not find reset-gpios\n",
580 __func__);
581 return -ENOENT;
582 }
583
584 /* before power up, insure that HDMI and AUDIO IC is under reset */
585 ret = dm_gpio_set_value(&hdmi, 1);
586 if (ret) {
587 pr_err("%s: can't set_value for hdmi_nrst gpio", __func__);
588 goto error;
589 }
590 ret = dm_gpio_set_value(&audio, 1);
591 if (ret) {
592 pr_err("%s: can't set_value for audio_nrst gpio", __func__);
593 goto error;
594 }
595
596 /* power-up audio IC */
597 regulator_autoset_by_name("v1v8_audio", NULL);
598
599 /* power-up HDMI IC */
600 regulator_autoset_by_name("v1v2_hdmi", NULL);
601 regulator_autoset_by_name("v3v3_hdmi", NULL);
602
603error:
604 return ret;
605}
606
607static bool board_is_dk2(void)
608{
609 if (CONFIG_IS_ENABLED(TARGET_STM32MP157C_DK2) &&
610 of_machine_is_compatible("st,stm32mp157c-dk2"))
611 return true;
612
613 return false;
614}
615#endif
616
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100617/* board dependent setup after realloc */
618int board_init(void)
619{
Patrice Chotard972723a2019-03-11 11:13:17 +0100620 struct udevice *dev;
621
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100622 /* address of boot parameters */
623 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
624
Patrice Chotard972723a2019-03-11 11:13:17 +0100625 /* probe all PINCTRL for hog */
626 for (uclass_first_device(UCLASS_PINCTRL, &dev);
627 dev;
628 uclass_next_device(&dev)) {
629 pr_debug("probe pincontrol = %s\n", dev->name);
630 }
631
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100632 board_key_check();
633
Patrick Delaunay6519e442019-07-05 17:20:09 +0200634#ifdef CONFIG_DM_REGULATOR
Patrick Delaunay9f76fdf2019-07-30 19:16:38 +0200635 if (board_is_dk2())
636 dk2_i2c1_fix();
637
Patrick Delaunay6519e442019-07-05 17:20:09 +0200638 regulators_enable_boot_on(_DEBUG);
639#endif
640
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100641 sysconf_init();
642
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200643 if (CONFIG_IS_ENABLED(CONFIG_LED))
Patrick Delaunay36e3d112018-07-27 16:37:08 +0200644 led_default_state();
645
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100646 return 0;
647}
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100648
649int board_late_init(void)
650{
Patrick Delaunayf2451262019-07-30 19:16:41 +0200651 char *boot_device;
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100652#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
653 const void *fdt_compat;
654 int fdt_compat_len;
Patrick Delaunaye8566ec2019-07-30 19:16:37 +0200655 int ret;
656 u32 otp;
657 struct udevice *dev;
658 char buf[10];
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100659
660 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
661 &fdt_compat_len);
662 if (fdt_compat && fdt_compat_len) {
663 if (strncmp(fdt_compat, "st,", 3) != 0)
664 env_set("board_name", fdt_compat);
665 else
666 env_set("board_name", fdt_compat + 3);
667 }
Patrick Delaunaye8566ec2019-07-30 19:16:37 +0200668 ret = uclass_get_device_by_driver(UCLASS_MISC,
669 DM_GET_DRIVER(stm32mp_bsec),
670 &dev);
671
672 if (!ret)
673 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
674 &otp, sizeof(otp));
675 if (!ret && otp) {
676 snprintf(buf, sizeof(buf), "0x%04x", otp >> 16);
677 env_set("board_id", buf);
678
679 snprintf(buf, sizeof(buf), "0x%04x",
680 ((otp >> 8) & 0xF) - 1 + 0xA);
681 env_set("board_rev", buf);
682 }
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100683#endif
684
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200685#ifdef CONFIG_ADC
Patrice Chotard879cde52019-02-12 16:50:40 +0100686 /* for DK1/DK2 boards */
687 board_check_usb_power();
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200688#endif /* CONFIG_ADC */
Patrice Chotard879cde52019-02-12 16:50:40 +0100689
Patrick Delaunayf2451262019-07-30 19:16:41 +0200690 /* Check the boot-source to disable bootdelay */
691 boot_device = env_get("boot_device");
692 if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
693 env_set("bootdelay", "0");
694
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100695 return 0;
696}
Patrice Chotard879cde52019-02-12 16:50:40 +0100697
698void board_quiesce_devices(void)
699{
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200700#ifdef CONFIG_LED
Patrice Chotard879cde52019-02-12 16:50:40 +0100701 setup_led(LEDST_OFF);
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200702#endif
Patrice Chotard879cde52019-02-12 16:50:40 +0100703}
Patrice Chotard41443cf2019-05-02 18:07:14 +0200704
Patrick Delaunaybff66f92019-08-01 11:29:03 +0200705/* eth init function : weak called in eqos driver */
706int board_interface_eth_init(struct udevice *dev,
707 phy_interface_t interface_type)
Christophe Roullier69ac3f52019-05-17 15:08:43 +0200708{
709 u8 *syscfg;
710 u32 value;
Patrick Delaunaybff66f92019-08-01 11:29:03 +0200711 bool eth_clk_sel_reg = false;
712 bool eth_ref_clk_sel_reg = false;
713
714 /* Gigabit Ethernet 125MHz clock selection. */
715 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
716
717 /* Ethernet 50Mhz RMII clock selection */
718 eth_ref_clk_sel_reg =
719 dev_read_bool(dev, "st,eth_ref_clk_sel");
Christophe Roullier69ac3f52019-05-17 15:08:43 +0200720
721 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
722
723 if (!syscfg)
724 return -ENODEV;
725
726 switch (interface_type) {
727 case PHY_INTERFACE_MODE_MII:
728 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
729 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
730 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
731 break;
732 case PHY_INTERFACE_MODE_GMII:
733 if (eth_clk_sel_reg)
734 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
735 SYSCFG_PMCSETR_ETH_CLK_SEL;
736 else
737 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
738 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
739 break;
740 case PHY_INTERFACE_MODE_RMII:
741 if (eth_ref_clk_sel_reg)
742 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
743 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
744 else
745 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
746 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
747 break;
748 case PHY_INTERFACE_MODE_RGMII:
749 case PHY_INTERFACE_MODE_RGMII_ID:
750 case PHY_INTERFACE_MODE_RGMII_RXID:
751 case PHY_INTERFACE_MODE_RGMII_TXID:
752 if (eth_clk_sel_reg)
753 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
754 SYSCFG_PMCSETR_ETH_CLK_SEL;
755 else
756 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
757 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
758 break;
759 default:
760 debug("%s: Do not manage %d interface\n",
761 __func__, interface_type);
762 /* Do not manage others interfaces */
763 return -EINVAL;
764 }
765
766 /* clear and set ETH configuration bits */
767 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
768 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
769 syscfg + SYSCFG_PMCCLRR);
770 writel(value, syscfg + SYSCFG_PMCSETR);
771
772 return 0;
773}
774
Patrice Chotard34320372019-05-02 18:28:05 +0200775enum env_location env_get_location(enum env_operation op, int prio)
776{
777 u32 bootmode = get_bootmode();
778
779 if (prio)
780 return ENVL_UNKNOWN;
781
782 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
783#ifdef CONFIG_ENV_IS_IN_EXT4
784 case BOOT_FLASH_SD:
785 case BOOT_FLASH_EMMC:
786 return ENVL_EXT4;
787#endif
788#ifdef CONFIG_ENV_IS_IN_UBI
789 case BOOT_FLASH_NAND:
790 return ENVL_UBI;
791#endif
Patrice Chotard2c461ec2019-05-09 14:25:36 +0200792#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
793 case BOOT_FLASH_NOR:
794 return ENVL_SPI_FLASH;
795#endif
Patrice Chotard34320372019-05-02 18:28:05 +0200796 default:
797 return ENVL_NOWHERE;
798 }
799}
800
Patrice Chotarddad97bf2019-05-02 18:36:01 +0200801#if defined(CONFIG_ENV_IS_IN_EXT4)
802const char *env_ext4_get_intf(void)
803{
804 u32 bootmode = get_bootmode();
805
806 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
807 case BOOT_FLASH_SD:
808 case BOOT_FLASH_EMMC:
809 return "mmc";
810 default:
811 return "";
812 }
813}
814
815const char *env_ext4_get_dev_part(void)
816{
817 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
818 u32 bootmode = get_bootmode();
819
820 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
821}
822#endif
823
Patrice Chotard41443cf2019-05-02 18:07:14 +0200824#ifdef CONFIG_SYS_MTDPARTS_RUNTIME
825
826#define MTDPARTS_LEN 256
827#define MTDIDS_LEN 128
828
829/**
830 * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
831 * If we need to access it before the env is relocated, then we need
832 * to use our own stack buffer. gd->env_buf will be too small.
833 *
834 * @param buf temporary buffer pointer MTDPARTS_LEN long
835 * @return mtdparts variable string, NULL if not found
836 */
837static const char *env_get_mtdparts(const char *str, char *buf)
838{
839 if (gd->flags & GD_FLG_ENV_READY)
840 return env_get(str);
841 if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
842 return buf;
843
844 return NULL;
845}
846
847/**
848 * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
849 */
850static void board_get_mtdparts(const char *dev,
851 char *mtdids,
852 char *mtdparts)
853{
854 char env_name[32] = "mtdparts_";
855 char tmp_mtdparts[MTDPARTS_LEN];
856 const char *tmp;
857
858 /* name of env variable to read = mtdparts_<dev> */
859 strcat(env_name, dev);
860 tmp = env_get_mtdparts(env_name, tmp_mtdparts);
861 if (tmp) {
862 /* mtdids: "<dev>=<dev>, ...." */
863 if (mtdids[0] != '\0')
864 strcat(mtdids, ",");
865 strcat(mtdids, dev);
866 strcat(mtdids, "=");
867 strcat(mtdids, dev);
868
869 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
870 if (mtdparts[0] != '\0')
871 strncat(mtdparts, ";", MTDPARTS_LEN);
872 else
873 strcat(mtdparts, "mtdparts=");
874 strncat(mtdparts, dev, MTDPARTS_LEN);
875 strncat(mtdparts, ":", MTDPARTS_LEN);
876 strncat(mtdparts, tmp, MTDPARTS_LEN);
877 }
878}
879
880void board_mtdparts_default(const char **mtdids, const char **mtdparts)
881{
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200882 struct mtd_info *mtd;
Patrice Chotard41443cf2019-05-02 18:07:14 +0200883 struct udevice *dev;
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200884 static char parts[3 * MTDPARTS_LEN + 1];
Patrice Chotard41443cf2019-05-02 18:07:14 +0200885 static char ids[MTDIDS_LEN + 1];
886 static bool mtd_initialized;
887
888 if (mtd_initialized) {
889 *mtdids = ids;
890 *mtdparts = parts;
891 return;
892 }
893
894 memset(parts, 0, sizeof(parts));
895 memset(ids, 0, sizeof(ids));
896
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200897 /* probe all MTD devices */
898 for (uclass_first_device(UCLASS_MTD, &dev);
899 dev;
900 uclass_next_device(&dev)) {
901 pr_debug("mtd device = %s\n", dev->name);
902 }
903
904 mtd = get_mtd_device_nm("nand0");
905 if (!IS_ERR_OR_NULL(mtd)) {
Patrice Chotard41443cf2019-05-02 18:07:14 +0200906 board_get_mtdparts("nand0", ids, parts);
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200907 put_mtd_device(mtd);
908 }
909
910 mtd = get_mtd_device_nm("spi-nand0");
911 if (!IS_ERR_OR_NULL(mtd)) {
912 board_get_mtdparts("spi-nand0", ids, parts);
913 put_mtd_device(mtd);
914 }
Patrice Chotard41443cf2019-05-02 18:07:14 +0200915
916 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
917 board_get_mtdparts("nor0", ids, parts);
918
919 mtd_initialized = true;
920 *mtdids = ids;
921 *mtdparts = parts;
922 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
923}
924#endif
Patrick Delaunayde98cbf2019-07-02 13:26:07 +0200925
926#if defined(CONFIG_OF_BOARD_SETUP)
927int ft_board_setup(void *blob, bd_t *bd)
928{
929#ifdef CONFIG_FDT_FIXUP_PARTITIONS
930 struct node_info nodes[] = {
931 { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
932 { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
933 };
934 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
935#endif
936
937 return 0;
938}
939#endif
Patrick Delaunayc17d7252019-08-02 15:07:20 +0200940
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200941#ifdef CONFIG_SET_DFU_ALT_INFO
942#define DFU_ALT_BUF_LEN SZ_1K
943
944static void board_get_alt_info(const char *dev, char *buff)
945{
946 char var_name[32] = "dfu_alt_info_";
947 int ret;
948
949 ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
950
951 /* name of env variable to read = dfu_alt_info_<dev> */
952 strcat(var_name, dev);
953 ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
954 if (ret) {
955 if (buff[0] != '\0')
956 strcat(buff, "&");
957 strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
958 }
959}
960
961void set_dfu_alt_info(char *interface, char *devstr)
962{
963 struct udevice *dev;
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200964 struct mtd_info *mtd;
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200965
966 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
967
968 if (env_get("dfu_alt_info"))
969 return;
970
971 memset(buf, 0, sizeof(buf));
972
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200973 /* probe all MTD devices */
974 mtd_probe_devices();
975
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200976 board_get_alt_info("ram", buf);
977
978 if (!uclass_get_device(UCLASS_MMC, 0, &dev))
979 board_get_alt_info("mmc0", buf);
980
981 if (!uclass_get_device(UCLASS_MMC, 1, &dev))
982 board_get_alt_info("mmc1", buf);
983
984 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
985 board_get_alt_info("nor0", buf);
986
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200987 mtd = get_mtd_device_nm("nand0");
988 if (!IS_ERR_OR_NULL(mtd))
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200989 board_get_alt_info("nand0", buf);
990
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200991 mtd = get_mtd_device_nm("spi-nand0");
992 if (!IS_ERR_OR_NULL(mtd))
993 board_get_alt_info("spi-nand0", buf);
994
Patrick Delaunay8e5031b2019-10-14 09:28:12 +0200995#ifdef CONFIG_DFU_VIRT
996 strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
997
998 if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
999 strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
1000#endif
1001
Patrick Delaunay093f6e12019-10-14 09:28:09 +02001002 env_set("dfu_alt_info", buf);
1003 puts("DFU alt info setting: done\n");
1004}
Patrick Delaunay8e5031b2019-10-14 09:28:12 +02001005
1006#if CONFIG_IS_ENABLED(DFU_VIRT)
1007#include <dfu.h>
1008#include <power/stpmic1.h>
1009
1010int dfu_otp_read(u64 offset, u8 *buffer, long *size)
1011{
1012 struct udevice *dev;
1013 int ret;
1014
1015 ret = uclass_get_device_by_driver(UCLASS_MISC,
1016 DM_GET_DRIVER(stm32mp_bsec),
1017 &dev);
1018 if (ret)
1019 return ret;
1020
1021 ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
1022 if (ret >= 0) {
1023 *size = ret;
1024 ret = 0;
1025 }
1026
1027 return 0;
1028}
1029
1030int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
1031{
1032 int ret;
1033#ifdef CONFIG_PMIC_STPMIC1
1034 struct udevice *dev;
1035
1036 ret = uclass_get_device_by_driver(UCLASS_MISC,
1037 DM_GET_DRIVER(stpmic1_nvm),
1038 &dev);
1039 if (ret)
1040 return ret;
1041
1042 ret = misc_read(dev, 0xF8 + offset, buffer, *size);
1043 if (ret >= 0) {
1044 *size = ret;
1045 ret = 0;
1046 }
1047 if (ret == -EACCES) {
1048 *size = 0;
1049 ret = 0;
1050 }
1051#else
1052 pr_err("PMIC update not supported");
1053 ret = -EOPNOTSUPP;
1054#endif
1055
1056 return ret;
1057}
1058
1059int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
1060 void *buf, long *len)
1061{
1062 switch (dfu->data.virt.dev_num) {
1063 case 0x0:
1064 return dfu_otp_read(offset, buf, len);
1065 case 0x1:
1066 return dfu_pmic_read(offset, buf, len);
1067 }
1068 *len = 0;
1069 return 0;
1070}
1071
1072int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
1073{
1074 *size = SZ_1K;
1075
1076 return 0;
1077}
1078
1079#endif
1080
Patrick Delaunay093f6e12019-10-14 09:28:09 +02001081#endif
1082
Patrick Delaunayc17d7252019-08-02 15:07:20 +02001083static void board_copro_image_process(ulong fw_image, size_t fw_size)
1084{
1085 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
1086
1087 if (!rproc_is_initialized())
1088 if (rproc_init()) {
1089 printf("Remote Processor %d initialization failed\n",
1090 id);
1091 return;
1092 }
1093
1094 ret = rproc_load(id, fw_image, fw_size);
1095 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
1096 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
1097
1098 if (!ret) {
1099 rproc_start(id);
1100 env_set("copro_state", "booted");
1101 }
1102}
1103
1104U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);