blob: e82a43074fb9dd0f7857879ca097c1e95e3b239c [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>
Patrick Delaunay093f6e12019-10-14 09:28:09 +020019#include <memalign.h>
Patrick Delaunay92dc1022019-02-12 11:44:41 +010020#include <misc.h>
Patrick Delaunayde98cbf2019-07-02 13:26:07 +020021#include <mtd.h>
22#include <mtd_node.h>
Patrick Delaunaybff66f92019-08-01 11:29:03 +020023#include <netdev.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020024#include <phy.h>
Patrick Delaunayc17d7252019-08-02 15:07:20 +020025#include <remoteproc.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020026#include <reset.h>
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010027#include <syscon.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010028#include <usb.h>
Patrick Delaunayae0931d02019-07-30 19:16:39 +020029#include <watchdog.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020030#include <asm/io.h>
Patrick Delaunayf2a7b872019-02-27 17:01:18 +010031#include <asm/gpio.h>
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010032#include <asm/arch/stm32.h>
Patrice Chotarddad97bf2019-05-02 18:36:01 +020033#include <asm/arch/sys_proto.h>
Patrick Delaunayde98cbf2019-07-02 13:26:07 +020034#include <jffs2/load_kernel.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020035#include <power/regulator.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010036#include <usb/dwc2_udc.h>
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010037
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010038/* SYSCFG registers */
39#define SYSCFG_BOOTR 0x00
40#define SYSCFG_PMCSETR 0x04
41#define SYSCFG_IOCTRLSETR 0x18
42#define SYSCFG_ICNR 0x1C
43#define SYSCFG_CMPCR 0x20
44#define SYSCFG_CMPENSETR 0x24
45#define SYSCFG_PMCCLRR 0x44
46
47#define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0)
48#define SYSCFG_BOOTR_BOOTPD_SHIFT 4
49
50#define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0)
51#define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1)
52#define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2)
53#define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3)
54#define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4)
55
56#define SYSCFG_CMPCR_SW_CTRL BIT(1)
57#define SYSCFG_CMPCR_READY BIT(8)
58
59#define SYSCFG_CMPENSETR_MPU_EN BIT(0)
60
61#define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16)
62#define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17)
63
64#define SYSCFG_PMCSETR_ETH_SELMII BIT(20)
65
66#define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21)
Christophe Roullier69ac3f52019-05-17 15:08:43 +020067#define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0
68#define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21)
69#define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23)
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010070
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010071/*
72 * Get a global data pointer
73 */
74DECLARE_GLOBAL_DATA_PTR;
75
Patrice Chotardcded32f2019-04-30 18:09:38 +020076#define USB_LOW_THRESHOLD_UV 200000
Patrice Chotard879cde52019-02-12 16:50:40 +010077#define USB_WARNING_LOW_THRESHOLD_UV 660000
78#define USB_START_LOW_THRESHOLD_UV 1230000
Patrice Chotardcded32f2019-04-30 18:09:38 +020079#define USB_START_HIGH_THRESHOLD_UV 2150000
Patrice Chotard879cde52019-02-12 16:50:40 +010080
Patrick Delaunay92dc1022019-02-12 11:44:41 +010081int checkboard(void)
82{
83 int ret;
84 char *mode;
85 u32 otp;
86 struct udevice *dev;
87 const char *fdt_compat;
88 int fdt_compat_len;
89
Patrick Delaunayff215a42019-07-02 13:26:06 +020090 if (IS_ENABLED(CONFIG_STM32MP1_OPTEE))
91 mode = "trusted with OP-TEE";
92 else if (IS_ENABLED(CONFIG_STM32MP1_TRUSTED))
Patrick Delaunay92dc1022019-02-12 11:44:41 +010093 mode = "trusted";
94 else
95 mode = "basic";
96
97 printf("Board: stm32mp1 in %s mode", mode);
98 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
99 &fdt_compat_len);
100 if (fdt_compat && fdt_compat_len)
101 printf(" (%s)", fdt_compat);
102 puts("\n");
103
104 ret = uclass_get_device_by_driver(UCLASS_MISC,
105 DM_GET_DRIVER(stm32mp_bsec),
106 &dev);
107
108 if (!ret)
109 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
110 &otp, sizeof(otp));
Patrick Delaunaydcb89fd2019-08-02 13:08:05 +0200111 if (ret > 0 && otp) {
Patrick Delaunay92dc1022019-02-12 11:44:41 +0100112 printf("Board: MB%04x Var%d Rev.%c-%02d\n",
113 otp >> 16,
114 (otp >> 12) & 0xF,
115 ((otp >> 8) & 0xF) - 1 + 'A',
116 otp & 0xF);
117 }
118
119 return 0;
120}
121
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100122static void board_key_check(void)
123{
124#if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
125 ofnode node;
126 struct gpio_desc gpio;
127 enum forced_boot_mode boot_mode = BOOT_NORMAL;
128
129 node = ofnode_path("/config");
130 if (!ofnode_valid(node)) {
131 debug("%s: no /config node?\n", __func__);
132 return;
133 }
134#ifdef CONFIG_FASTBOOT
135 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
136 &gpio, GPIOD_IS_IN)) {
137 debug("%s: could not find a /config/st,fastboot-gpios\n",
138 __func__);
139 } else {
140 if (dm_gpio_get_value(&gpio)) {
141 puts("Fastboot key pressed, ");
142 boot_mode = BOOT_FASTBOOT;
143 }
144
145 dm_gpio_free(NULL, &gpio);
146 }
147#endif
148#ifdef CONFIG_CMD_STM32PROG
149 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
150 &gpio, GPIOD_IS_IN)) {
151 debug("%s: could not find a /config/st,stm32prog-gpios\n",
152 __func__);
153 } else {
154 if (dm_gpio_get_value(&gpio)) {
155 puts("STM32Programmer key pressed, ");
156 boot_mode = BOOT_STM32PROG;
157 }
158 dm_gpio_free(NULL, &gpio);
159 }
160#endif
161
162 if (boot_mode != BOOT_NORMAL) {
163 puts("entering download mode...\n");
164 clrsetbits_le32(TAMP_BOOT_CONTEXT,
165 TAMP_BOOT_FORCED_MASK,
166 boot_mode);
167 }
168#endif
169}
170
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100171#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
Patrice Chotard204079b2018-08-10 17:12:14 +0200172
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100173/* STMicroelectronics STUSB1600 Type-C controller */
174#define STUSB1600_CC_CONNECTION_STATUS 0x0E
175
176/* STUSB1600_CC_CONNECTION_STATUS bitfields */
177#define STUSB1600_CC_ATTACH BIT(0)
178
179static int stusb1600_init(struct udevice **dev_stusb1600)
180{
181 ofnode node;
182 struct udevice *dev, *bus;
183 int ret;
184 u32 chip_addr;
185
186 *dev_stusb1600 = NULL;
187
188 /* if node stusb1600 is present, means DK1 or DK2 board */
189 node = ofnode_by_compatible(ofnode_null(), "st,stusb1600");
190 if (!ofnode_valid(node))
191 return -ENODEV;
192
193 ret = ofnode_read_u32(node, "reg", &chip_addr);
194 if (ret)
195 return -EINVAL;
196
197 ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node),
198 &bus);
199 if (ret) {
200 printf("bus for stusb1600 not found\n");
201 return -ENODEV;
202 }
203
204 ret = dm_i2c_probe(bus, chip_addr, 0, &dev);
205 if (!ret)
206 *dev_stusb1600 = dev;
207
208 return ret;
209}
210
211static int stusb1600_cable_connected(struct udevice *dev)
212{
213 u8 status;
214
215 if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1))
216 return 0;
217
218 return status & STUSB1600_CC_ATTACH;
219}
220
221#include <usb/dwc2_udc.h>
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100222int g_dnl_board_usb_cable_connected(void)
Patrice Chotard204079b2018-08-10 17:12:14 +0200223{
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100224 struct udevice *stusb1600;
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100225 struct udevice *dwc2_udc_otg;
Patrice Chotard204079b2018-08-10 17:12:14 +0200226 int ret;
227
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100228 if (!stusb1600_init(&stusb1600))
229 return stusb1600_cable_connected(stusb1600);
230
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100231 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
232 DM_GET_DRIVER(dwc2_udc_otg),
233 &dwc2_udc_otg);
234 if (!ret)
235 debug("dwc2_udc_otg init failed\n");
Patrice Chotard204079b2018-08-10 17:12:14 +0200236
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100237 return dwc2_udc_B_session_valid(dwc2_udc_otg);
Patrice Chotard879cde52019-02-12 16:50:40 +0100238}
Patrick Delaunay0aafce62019-09-13 15:24:17 +0200239
240#define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
241#define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
242
243int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
244{
245 if (!strcmp(name, "usb_dnl_dfu"))
246 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
247 else if (!strcmp(name, "usb_dnl_fastboot"))
248 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
249 &dev->idProduct);
250 else
251 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
252
253 return 0;
254}
255
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100256#endif /* CONFIG_USB_GADGET */
Patrice Chotard879cde52019-02-12 16:50:40 +0100257
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200258#ifdef CONFIG_LED
Patrice Chotard879cde52019-02-12 16:50:40 +0100259static int get_led(struct udevice **dev, char *led_string)
260{
261 char *led_name;
262 int ret;
263
264 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
265 if (!led_name) {
266 pr_debug("%s: could not find %s config string\n",
267 __func__, led_string);
268 return -ENOENT;
269 }
270 ret = led_get_by_label(led_name, dev);
271 if (ret) {
272 debug("%s: get=%d\n", __func__, ret);
273 return ret;
274 }
275
276 return 0;
277}
278
279static int setup_led(enum led_state_t cmd)
280{
281 struct udevice *dev;
282 int ret;
283
284 ret = get_led(&dev, "u-boot,boot-led");
285 if (ret)
286 return ret;
287
288 ret = led_set_state(dev, cmd);
Patrice Chotard204079b2018-08-10 17:12:14 +0200289 return ret;
290}
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200291#endif
292
293static void __maybe_unused led_error_blink(u32 nb_blink)
294{
295#ifdef CONFIG_LED
296 int ret;
297 struct udevice *led;
298 u32 i;
299#endif
300
301 if (!nb_blink)
302 return;
303
304#ifdef CONFIG_LED
305 ret = get_led(&led, "u-boot,error-led");
306 if (!ret) {
307 /* make u-boot,error-led blinking */
308 /* if U32_MAX and 125ms interval, for 17.02 years */
309 for (i = 0; i < 2 * nb_blink; i++) {
310 led_set_state(led, LEDST_TOGGLE);
311 mdelay(125);
312 WATCHDOG_RESET();
313 }
314 }
315#endif
316
317 /* infinite: the boot process must be stopped */
318 if (nb_blink == U32_MAX)
319 hang();
320}
Patrice Chotard204079b2018-08-10 17:12:14 +0200321
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200322#ifdef CONFIG_ADC
Patrice Chotard879cde52019-02-12 16:50:40 +0100323static int board_check_usb_power(void)
324{
325 struct ofnode_phandle_args adc_args;
326 struct udevice *adc;
Patrice Chotard879cde52019-02-12 16:50:40 +0100327 ofnode node;
328 unsigned int raw;
329 int max_uV = 0;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200330 int min_uV = USB_START_HIGH_THRESHOLD_UV;
Patrice Chotard879cde52019-02-12 16:50:40 +0100331 int ret, uV, adc_count;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200332 u32 nb_blink;
333 u8 i;
Patrice Chotard879cde52019-02-12 16:50:40 +0100334 node = ofnode_path("/config");
335 if (!ofnode_valid(node)) {
336 debug("%s: no /config node?\n", __func__);
337 return -ENOENT;
338 }
339
340 /*
341 * Retrieve the ADC channels devices and get measurement
342 * for each of them
343 */
344 adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
345 "#io-channel-cells");
346 if (adc_count < 0) {
347 if (adc_count == -ENOENT)
348 return 0;
349
350 pr_err("%s: can't find adc channel (%d)\n", __func__,
351 adc_count);
352
353 return adc_count;
354 }
355
356 for (i = 0; i < adc_count; i++) {
357 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
358 "#io-channel-cells", 0, i,
359 &adc_args)) {
360 pr_debug("%s: can't find /config/st,adc_usb_pd\n",
361 __func__);
362 return 0;
363 }
364
365 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
366 &adc);
367
368 if (ret) {
369 pr_err("%s: Can't get adc device(%d)\n", __func__,
370 ret);
371 return ret;
372 }
373
374 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
375 &raw);
376 if (ret) {
377 pr_err("%s: single shot failed for %s[%d]!\n",
378 __func__, adc->name, adc_args.args[0]);
379 return ret;
380 }
381 /* Convert to uV */
382 if (!adc_raw_to_uV(adc, raw, &uV)) {
383 if (uV > max_uV)
384 max_uV = uV;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200385 if (uV < min_uV)
386 min_uV = uV;
Patrice Chotard879cde52019-02-12 16:50:40 +0100387 pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
388 adc->name, adc_args.args[0], raw, uV);
389 } else {
390 pr_err("%s: Can't get uV value for %s[%d]\n",
391 __func__, adc->name, adc_args.args[0]);
392 }
393 }
394
395 /*
396 * If highest value is inside 1.23 Volts and 2.10 Volts, that means
397 * board is plugged on an USB-C 3A power supply and boot process can
398 * continue.
399 */
400 if (max_uV > USB_START_LOW_THRESHOLD_UV &&
Patrice Chotardcded32f2019-04-30 18:09:38 +0200401 max_uV <= USB_START_HIGH_THRESHOLD_UV &&
402 min_uV <= USB_LOW_THRESHOLD_UV)
Patrice Chotard879cde52019-02-12 16:50:40 +0100403 return 0;
404
Patrice Chotardcded32f2019-04-30 18:09:38 +0200405 pr_err("****************************************************\n");
406
407 /*
408 * If highest and lowest value are either both below
409 * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
410 * means USB TYPE-C is in unattached mode, this is an issue, make
411 * u-boot,error-led blinking and stop boot process.
412 */
413 if ((max_uV > USB_LOW_THRESHOLD_UV &&
414 min_uV > USB_LOW_THRESHOLD_UV) ||
415 (max_uV <= USB_LOW_THRESHOLD_UV &&
416 min_uV <= USB_LOW_THRESHOLD_UV)) {
417 pr_err("* ERROR USB TYPE-C connection in unattached mode *\n");
418 pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
419 /* with 125ms interval, led will blink for 17.02 years ....*/
420 nb_blink = U32_MAX;
421 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100422
Patrice Chotardcded32f2019-04-30 18:09:38 +0200423 if (max_uV > USB_LOW_THRESHOLD_UV &&
424 max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
425 min_uV <= USB_LOW_THRESHOLD_UV) {
426 pr_err("* WARNING 500mA power supply detected *\n");
Patrice Chotard879cde52019-02-12 16:50:40 +0100427 nb_blink = 2;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200428 }
429
430 if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
431 max_uV <= USB_START_LOW_THRESHOLD_UV &&
432 min_uV <= USB_LOW_THRESHOLD_UV) {
433 pr_err("* WARNING 1.5mA power supply detected *\n");
Patrice Chotard879cde52019-02-12 16:50:40 +0100434 nb_blink = 3;
435 }
436
Patrice Chotardcded32f2019-04-30 18:09:38 +0200437 /*
438 * If highest value is above 2.15 Volts that means that the USB TypeC
439 * supplies more than 3 Amp, this is not compliant with TypeC specification
440 */
441 if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
442 pr_err("* USB TYPE-C charger not compliant with *\n");
443 pr_err("* specification *\n");
444 pr_err("****************************************************\n\n");
445 /* with 125ms interval, led will blink for 17.02 years ....*/
446 nb_blink = U32_MAX;
447 } else {
448 pr_err("* Current too low, use a 3A power supply! *\n");
449 pr_err("****************************************************\n\n");
450 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100451
Patrick Delaunayae0931d02019-07-30 19:16:39 +0200452 led_error_blink(nb_blink);
Patrice Chotard879cde52019-02-12 16:50:40 +0100453
454 return 0;
455}
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200456#endif /* CONFIG_ADC */
Patrice Chotard879cde52019-02-12 16:50:40 +0100457
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100458static void sysconf_init(void)
459{
460#ifndef CONFIG_STM32MP1_TRUSTED
461 u8 *syscfg;
462#ifdef CONFIG_DM_REGULATOR
463 struct udevice *pwr_dev;
464 struct udevice *pwr_reg;
465 struct udevice *dev;
466 int ret;
467 u32 otp = 0;
468#endif
469 u32 bootr;
470
471 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
472
473 /* interconnect update : select master using the port 1 */
474 /* LTDC = AXI_M9 */
475 /* GPU = AXI_M8 */
476 /* today information is hardcoded in U-Boot */
477 writel(BIT(9), syscfg + SYSCFG_ICNR);
478
479 /* disable Pull-Down for boot pin connected to VDD */
480 bootr = readl(syscfg + SYSCFG_BOOTR);
481 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
482 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
483 writel(bootr, syscfg + SYSCFG_BOOTR);
484
485#ifdef CONFIG_DM_REGULATOR
486 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
487 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
488 * The customer will have to disable this for low frequencies
489 * or if AFMUX is selected but the function not used, typically for
490 * TRACE. Otherwise, impact on power consumption.
491 *
492 * WARNING:
493 * enabling High Speed mode while VDD>2.7V
494 * with the OTP product_below_2v5 (OTP 18, BIT 13)
495 * erroneously set to 1 can damage the IC!
496 * => U-Boot set the register only if VDD < 2.7V (in DT)
497 * but this value need to be consistent with board design
498 */
Patrick Delaunay6b2baa02019-07-30 19:16:42 +0200499 ret = uclass_get_device_by_driver(UCLASS_PMIC,
500 DM_GET_DRIVER(stm32mp_pwr_pmic),
501 &pwr_dev);
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100502 if (!ret) {
503 ret = uclass_get_device_by_driver(UCLASS_MISC,
504 DM_GET_DRIVER(stm32mp_bsec),
505 &dev);
506 if (ret) {
507 pr_err("Can't find stm32mp_bsec driver\n");
508 return;
509 }
510
511 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
Patrick Delaunayceb82e32019-08-02 13:08:06 +0200512 if (ret > 0)
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100513 otp = otp & BIT(13);
514
Patrick Delaunay6b2baa02019-07-30 19:16:42 +0200515 /* get VDD = vdd-supply */
516 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100517 &pwr_reg);
518
519 /* check if VDD is Low Voltage */
520 if (!ret) {
521 if (regulator_get_value(pwr_reg) < 2700000) {
522 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
523 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
524 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
525 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
526 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
527 syscfg + SYSCFG_IOCTRLSETR);
528
529 if (!otp)
530 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
531 } else {
532 if (otp)
533 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
534 }
535 } else {
536 debug("VDD unknown");
537 }
538 }
539#endif
540
541 /* activate automatic I/O compensation
542 * warning: need to ensure CSI enabled and ready in clock driver
543 */
544 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
545
546 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
547 ;
548 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
549#endif
550}
551
Patrick Delaunay9f76fdf2019-07-30 19:16:38 +0200552#ifdef CONFIG_DM_REGULATOR
553/* Fix to make I2C1 usable on DK2 for touchscreen usage in kernel */
554static int dk2_i2c1_fix(void)
555{
556 ofnode node;
557 struct gpio_desc hdmi, audio;
558 int ret = 0;
559
560 node = ofnode_path("/soc/i2c@40012000/hdmi-transmitter@39");
561 if (!ofnode_valid(node)) {
562 pr_debug("%s: no hdmi-transmitter@39 ?\n", __func__);
563 return -ENOENT;
564 }
565
566 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
567 &hdmi, GPIOD_IS_OUT)) {
568 pr_debug("%s: could not find reset-gpios\n",
569 __func__);
570 return -ENOENT;
571 }
572
573 node = ofnode_path("/soc/i2c@40012000/cs42l51@4a");
574 if (!ofnode_valid(node)) {
575 pr_debug("%s: no cs42l51@4a ?\n", __func__);
576 return -ENOENT;
577 }
578
579 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
580 &audio, GPIOD_IS_OUT)) {
581 pr_debug("%s: could not find reset-gpios\n",
582 __func__);
583 return -ENOENT;
584 }
585
586 /* before power up, insure that HDMI and AUDIO IC is under reset */
587 ret = dm_gpio_set_value(&hdmi, 1);
588 if (ret) {
589 pr_err("%s: can't set_value for hdmi_nrst gpio", __func__);
590 goto error;
591 }
592 ret = dm_gpio_set_value(&audio, 1);
593 if (ret) {
594 pr_err("%s: can't set_value for audio_nrst gpio", __func__);
595 goto error;
596 }
597
598 /* power-up audio IC */
599 regulator_autoset_by_name("v1v8_audio", NULL);
600
601 /* power-up HDMI IC */
602 regulator_autoset_by_name("v1v2_hdmi", NULL);
603 regulator_autoset_by_name("v3v3_hdmi", NULL);
604
605error:
606 return ret;
607}
608
609static bool board_is_dk2(void)
610{
Patrick Delaunay310aa8a2020-01-13 15:17:42 +0100611 if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
Patrick Delaunay9f76fdf2019-07-30 19:16:38 +0200612 of_machine_is_compatible("st,stm32mp157c-dk2"))
613 return true;
614
615 return false;
616}
617#endif
618
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100619/* board dependent setup after realloc */
620int board_init(void)
621{
Patrice Chotard972723a2019-03-11 11:13:17 +0100622 struct udevice *dev;
623
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100624 /* address of boot parameters */
625 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
626
Patrice Chotard972723a2019-03-11 11:13:17 +0100627 /* probe all PINCTRL for hog */
628 for (uclass_first_device(UCLASS_PINCTRL, &dev);
629 dev;
630 uclass_next_device(&dev)) {
631 pr_debug("probe pincontrol = %s\n", dev->name);
632 }
633
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100634 board_key_check();
635
Patrick Delaunay6519e442019-07-05 17:20:09 +0200636#ifdef CONFIG_DM_REGULATOR
Patrick Delaunay9f76fdf2019-07-30 19:16:38 +0200637 if (board_is_dk2())
638 dk2_i2c1_fix();
639
Patrick Delaunay6519e442019-07-05 17:20:09 +0200640 regulators_enable_boot_on(_DEBUG);
641#endif
642
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100643 sysconf_init();
644
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200645 if (CONFIG_IS_ENABLED(CONFIG_LED))
Patrick Delaunay36e3d112018-07-27 16:37:08 +0200646 led_default_state();
647
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100648 return 0;
649}
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100650
651int board_late_init(void)
652{
Patrick Delaunayf2451262019-07-30 19:16:41 +0200653 char *boot_device;
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100654#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
655 const void *fdt_compat;
656 int fdt_compat_len;
Patrick Delaunaye8566ec2019-07-30 19:16:37 +0200657 int ret;
658 u32 otp;
659 struct udevice *dev;
660 char buf[10];
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100661
662 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
663 &fdt_compat_len);
664 if (fdt_compat && fdt_compat_len) {
665 if (strncmp(fdt_compat, "st,", 3) != 0)
666 env_set("board_name", fdt_compat);
667 else
668 env_set("board_name", fdt_compat + 3);
669 }
Patrick Delaunaye8566ec2019-07-30 19:16:37 +0200670 ret = uclass_get_device_by_driver(UCLASS_MISC,
671 DM_GET_DRIVER(stm32mp_bsec),
672 &dev);
673
674 if (!ret)
675 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
676 &otp, sizeof(otp));
677 if (!ret && otp) {
678 snprintf(buf, sizeof(buf), "0x%04x", otp >> 16);
679 env_set("board_id", buf);
680
681 snprintf(buf, sizeof(buf), "0x%04x",
682 ((otp >> 8) & 0xF) - 1 + 0xA);
683 env_set("board_rev", buf);
684 }
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100685#endif
686
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200687#ifdef CONFIG_ADC
Patrice Chotard879cde52019-02-12 16:50:40 +0100688 /* for DK1/DK2 boards */
689 board_check_usb_power();
Patrick Delaunayf6626e72019-07-30 19:16:43 +0200690#endif /* CONFIG_ADC */
Patrice Chotard879cde52019-02-12 16:50:40 +0100691
Patrick Delaunayf2451262019-07-30 19:16:41 +0200692 /* Check the boot-source to disable bootdelay */
693 boot_device = env_get("boot_device");
694 if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
695 env_set("bootdelay", "0");
696
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100697 return 0;
698}
Patrice Chotard879cde52019-02-12 16:50:40 +0100699
700void board_quiesce_devices(void)
701{
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200702#ifdef CONFIG_LED
Patrice Chotard879cde52019-02-12 16:50:40 +0100703 setup_led(LEDST_OFF);
Patrick Delaunay7a3e4422019-07-30 19:16:40 +0200704#endif
Patrice Chotard879cde52019-02-12 16:50:40 +0100705}
Patrice Chotard41443cf2019-05-02 18:07:14 +0200706
Patrick Delaunaybff66f92019-08-01 11:29:03 +0200707/* eth init function : weak called in eqos driver */
708int board_interface_eth_init(struct udevice *dev,
709 phy_interface_t interface_type)
Christophe Roullier69ac3f52019-05-17 15:08:43 +0200710{
711 u8 *syscfg;
712 u32 value;
Patrick Delaunaybff66f92019-08-01 11:29:03 +0200713 bool eth_clk_sel_reg = false;
714 bool eth_ref_clk_sel_reg = false;
715
716 /* Gigabit Ethernet 125MHz clock selection. */
717 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
718
719 /* Ethernet 50Mhz RMII clock selection */
720 eth_ref_clk_sel_reg =
721 dev_read_bool(dev, "st,eth_ref_clk_sel");
Christophe Roullier69ac3f52019-05-17 15:08:43 +0200722
723 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
724
725 if (!syscfg)
726 return -ENODEV;
727
728 switch (interface_type) {
729 case PHY_INTERFACE_MODE_MII:
730 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
731 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
732 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
733 break;
734 case PHY_INTERFACE_MODE_GMII:
735 if (eth_clk_sel_reg)
736 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
737 SYSCFG_PMCSETR_ETH_CLK_SEL;
738 else
739 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
740 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
741 break;
742 case PHY_INTERFACE_MODE_RMII:
743 if (eth_ref_clk_sel_reg)
744 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
745 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
746 else
747 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
748 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
749 break;
750 case PHY_INTERFACE_MODE_RGMII:
751 case PHY_INTERFACE_MODE_RGMII_ID:
752 case PHY_INTERFACE_MODE_RGMII_RXID:
753 case PHY_INTERFACE_MODE_RGMII_TXID:
754 if (eth_clk_sel_reg)
755 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
756 SYSCFG_PMCSETR_ETH_CLK_SEL;
757 else
758 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
759 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
760 break;
761 default:
762 debug("%s: Do not manage %d interface\n",
763 __func__, interface_type);
764 /* Do not manage others interfaces */
765 return -EINVAL;
766 }
767
768 /* clear and set ETH configuration bits */
769 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
770 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
771 syscfg + SYSCFG_PMCCLRR);
772 writel(value, syscfg + SYSCFG_PMCSETR);
773
774 return 0;
775}
776
Patrice Chotard34320372019-05-02 18:28:05 +0200777enum env_location env_get_location(enum env_operation op, int prio)
778{
779 u32 bootmode = get_bootmode();
780
781 if (prio)
782 return ENVL_UNKNOWN;
783
784 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
785#ifdef CONFIG_ENV_IS_IN_EXT4
786 case BOOT_FLASH_SD:
787 case BOOT_FLASH_EMMC:
788 return ENVL_EXT4;
789#endif
790#ifdef CONFIG_ENV_IS_IN_UBI
791 case BOOT_FLASH_NAND:
792 return ENVL_UBI;
793#endif
Patrice Chotard2c461ec2019-05-09 14:25:36 +0200794#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
795 case BOOT_FLASH_NOR:
796 return ENVL_SPI_FLASH;
797#endif
Patrice Chotard34320372019-05-02 18:28:05 +0200798 default:
799 return ENVL_NOWHERE;
800 }
801}
802
Patrice Chotarddad97bf2019-05-02 18:36:01 +0200803#if defined(CONFIG_ENV_IS_IN_EXT4)
804const char *env_ext4_get_intf(void)
805{
806 u32 bootmode = get_bootmode();
807
808 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
809 case BOOT_FLASH_SD:
810 case BOOT_FLASH_EMMC:
811 return "mmc";
812 default:
813 return "";
814 }
815}
816
817const char *env_ext4_get_dev_part(void)
818{
819 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
820 u32 bootmode = get_bootmode();
821
822 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
823}
824#endif
825
Patrice Chotard41443cf2019-05-02 18:07:14 +0200826#ifdef CONFIG_SYS_MTDPARTS_RUNTIME
827
828#define MTDPARTS_LEN 256
829#define MTDIDS_LEN 128
830
831/**
832 * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
833 * If we need to access it before the env is relocated, then we need
834 * to use our own stack buffer. gd->env_buf will be too small.
835 *
836 * @param buf temporary buffer pointer MTDPARTS_LEN long
837 * @return mtdparts variable string, NULL if not found
838 */
839static const char *env_get_mtdparts(const char *str, char *buf)
840{
841 if (gd->flags & GD_FLG_ENV_READY)
842 return env_get(str);
843 if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
844 return buf;
845
846 return NULL;
847}
848
849/**
850 * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
851 */
852static void board_get_mtdparts(const char *dev,
853 char *mtdids,
854 char *mtdparts)
855{
856 char env_name[32] = "mtdparts_";
857 char tmp_mtdparts[MTDPARTS_LEN];
858 const char *tmp;
859
860 /* name of env variable to read = mtdparts_<dev> */
861 strcat(env_name, dev);
862 tmp = env_get_mtdparts(env_name, tmp_mtdparts);
863 if (tmp) {
864 /* mtdids: "<dev>=<dev>, ...." */
865 if (mtdids[0] != '\0')
866 strcat(mtdids, ",");
867 strcat(mtdids, dev);
868 strcat(mtdids, "=");
869 strcat(mtdids, dev);
870
871 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
872 if (mtdparts[0] != '\0')
873 strncat(mtdparts, ";", MTDPARTS_LEN);
874 else
875 strcat(mtdparts, "mtdparts=");
876 strncat(mtdparts, dev, MTDPARTS_LEN);
877 strncat(mtdparts, ":", MTDPARTS_LEN);
878 strncat(mtdparts, tmp, MTDPARTS_LEN);
879 }
880}
881
882void board_mtdparts_default(const char **mtdids, const char **mtdparts)
883{
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200884 struct mtd_info *mtd;
Patrice Chotard41443cf2019-05-02 18:07:14 +0200885 struct udevice *dev;
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200886 static char parts[3 * MTDPARTS_LEN + 1];
Patrice Chotard41443cf2019-05-02 18:07:14 +0200887 static char ids[MTDIDS_LEN + 1];
888 static bool mtd_initialized;
889
890 if (mtd_initialized) {
891 *mtdids = ids;
892 *mtdparts = parts;
893 return;
894 }
895
896 memset(parts, 0, sizeof(parts));
897 memset(ids, 0, sizeof(ids));
898
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200899 /* probe all MTD devices */
900 for (uclass_first_device(UCLASS_MTD, &dev);
901 dev;
902 uclass_next_device(&dev)) {
903 pr_debug("mtd device = %s\n", dev->name);
904 }
905
906 mtd = get_mtd_device_nm("nand0");
907 if (!IS_ERR_OR_NULL(mtd)) {
Patrice Chotard41443cf2019-05-02 18:07:14 +0200908 board_get_mtdparts("nand0", ids, parts);
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200909 put_mtd_device(mtd);
910 }
911
912 mtd = get_mtd_device_nm("spi-nand0");
913 if (!IS_ERR_OR_NULL(mtd)) {
914 board_get_mtdparts("spi-nand0", ids, parts);
915 put_mtd_device(mtd);
916 }
Patrice Chotard41443cf2019-05-02 18:07:14 +0200917
918 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
919 board_get_mtdparts("nor0", ids, parts);
920
921 mtd_initialized = true;
922 *mtdids = ids;
923 *mtdparts = parts;
924 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
925}
926#endif
Patrick Delaunayde98cbf2019-07-02 13:26:07 +0200927
928#if defined(CONFIG_OF_BOARD_SETUP)
929int ft_board_setup(void *blob, bd_t *bd)
930{
931#ifdef CONFIG_FDT_FIXUP_PARTITIONS
932 struct node_info nodes[] = {
933 { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
934 { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
935 };
936 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
937#endif
938
939 return 0;
940}
941#endif
Patrick Delaunayc17d7252019-08-02 15:07:20 +0200942
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200943#ifdef CONFIG_SET_DFU_ALT_INFO
944#define DFU_ALT_BUF_LEN SZ_1K
945
946static void board_get_alt_info(const char *dev, char *buff)
947{
948 char var_name[32] = "dfu_alt_info_";
949 int ret;
950
951 ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
952
953 /* name of env variable to read = dfu_alt_info_<dev> */
954 strcat(var_name, dev);
955 ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
956 if (ret) {
957 if (buff[0] != '\0')
958 strcat(buff, "&");
959 strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
960 }
961}
962
963void set_dfu_alt_info(char *interface, char *devstr)
964{
965 struct udevice *dev;
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200966 struct mtd_info *mtd;
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200967
968 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
969
970 if (env_get("dfu_alt_info"))
971 return;
972
973 memset(buf, 0, sizeof(buf));
974
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200975 /* probe all MTD devices */
976 mtd_probe_devices();
977
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200978 board_get_alt_info("ram", buf);
979
980 if (!uclass_get_device(UCLASS_MMC, 0, &dev))
981 board_get_alt_info("mmc0", buf);
982
983 if (!uclass_get_device(UCLASS_MMC, 1, &dev))
984 board_get_alt_info("mmc1", buf);
985
986 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
987 board_get_alt_info("nor0", buf);
988
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200989 mtd = get_mtd_device_nm("nand0");
990 if (!IS_ERR_OR_NULL(mtd))
Patrick Delaunay093f6e12019-10-14 09:28:09 +0200991 board_get_alt_info("nand0", buf);
992
Patrick Delaunay11ad8cb2019-10-14 09:28:11 +0200993 mtd = get_mtd_device_nm("spi-nand0");
994 if (!IS_ERR_OR_NULL(mtd))
995 board_get_alt_info("spi-nand0", buf);
996
Patrick Delaunay8e5031b2019-10-14 09:28:12 +0200997#ifdef CONFIG_DFU_VIRT
998 strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
999
1000 if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
1001 strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
1002#endif
1003
Patrick Delaunay093f6e12019-10-14 09:28:09 +02001004 env_set("dfu_alt_info", buf);
1005 puts("DFU alt info setting: done\n");
1006}
Patrick Delaunay8e5031b2019-10-14 09:28:12 +02001007
1008#if CONFIG_IS_ENABLED(DFU_VIRT)
1009#include <dfu.h>
1010#include <power/stpmic1.h>
1011
1012int dfu_otp_read(u64 offset, u8 *buffer, long *size)
1013{
1014 struct udevice *dev;
1015 int ret;
1016
1017 ret = uclass_get_device_by_driver(UCLASS_MISC,
1018 DM_GET_DRIVER(stm32mp_bsec),
1019 &dev);
1020 if (ret)
1021 return ret;
1022
1023 ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
1024 if (ret >= 0) {
1025 *size = ret;
1026 ret = 0;
1027 }
1028
1029 return 0;
1030}
1031
1032int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
1033{
1034 int ret;
1035#ifdef CONFIG_PMIC_STPMIC1
1036 struct udevice *dev;
1037
1038 ret = uclass_get_device_by_driver(UCLASS_MISC,
1039 DM_GET_DRIVER(stpmic1_nvm),
1040 &dev);
1041 if (ret)
1042 return ret;
1043
1044 ret = misc_read(dev, 0xF8 + offset, buffer, *size);
1045 if (ret >= 0) {
1046 *size = ret;
1047 ret = 0;
1048 }
1049 if (ret == -EACCES) {
1050 *size = 0;
1051 ret = 0;
1052 }
1053#else
1054 pr_err("PMIC update not supported");
1055 ret = -EOPNOTSUPP;
1056#endif
1057
1058 return ret;
1059}
1060
1061int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
1062 void *buf, long *len)
1063{
1064 switch (dfu->data.virt.dev_num) {
1065 case 0x0:
1066 return dfu_otp_read(offset, buf, len);
1067 case 0x1:
1068 return dfu_pmic_read(offset, buf, len);
1069 }
1070 *len = 0;
1071 return 0;
1072}
1073
1074int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
1075{
1076 *size = SZ_1K;
1077
1078 return 0;
1079}
1080
1081#endif
1082
Patrick Delaunay093f6e12019-10-14 09:28:09 +02001083#endif
1084
Patrick Delaunayc17d7252019-08-02 15:07:20 +02001085static void board_copro_image_process(ulong fw_image, size_t fw_size)
1086{
1087 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
1088
1089 if (!rproc_is_initialized())
1090 if (rproc_init()) {
1091 printf("Remote Processor %d initialization failed\n",
1092 id);
1093 return;
1094 }
1095
1096 ret = rproc_load(id, fw_image, fw_size);
1097 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
1098 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
1099
Fabien Dessennead6cc942019-10-30 14:38:32 +01001100 if (!ret)
Patrick Delaunayc17d7252019-08-02 15:07:20 +02001101 rproc_start(id);
Patrick Delaunayc17d7252019-08-02 15:07:20 +02001102}
1103
1104U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);