blob: 279c7b77979987006010f518541fbdc242b9d86e [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>
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +01008#include <config.h>
Patrice Chotard204079b2018-08-10 17:12:14 +02009#include <clk.h>
10#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>
17#include <misc.h>
Patrick Delaunayde98cbf2019-07-02 13:26:07 +020018#include <mtd.h>
19#include <mtd_node.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020020#include <phy.h>
21#include <reset.h>
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010022#include <syscon.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010023#include <usb.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020024#include <asm/io.h>
Patrick Delaunayf2a7b872019-02-27 17:01:18 +010025#include <asm/gpio.h>
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010026#include <asm/arch/stm32.h>
Patrice Chotarddad97bf2019-05-02 18:36:01 +020027#include <asm/arch/sys_proto.h>
Patrick Delaunayde98cbf2019-07-02 13:26:07 +020028#include <jffs2/load_kernel.h>
Patrice Chotard204079b2018-08-10 17:12:14 +020029#include <power/regulator.h>
Patrick Delaunay7f3384d2019-03-29 15:42:24 +010030#include <usb/dwc2_udc.h>
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010031
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010032/* SYSCFG registers */
33#define SYSCFG_BOOTR 0x00
34#define SYSCFG_PMCSETR 0x04
35#define SYSCFG_IOCTRLSETR 0x18
36#define SYSCFG_ICNR 0x1C
37#define SYSCFG_CMPCR 0x20
38#define SYSCFG_CMPENSETR 0x24
39#define SYSCFG_PMCCLRR 0x44
40
41#define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0)
42#define SYSCFG_BOOTR_BOOTPD_SHIFT 4
43
44#define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0)
45#define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1)
46#define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2)
47#define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3)
48#define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4)
49
50#define SYSCFG_CMPCR_SW_CTRL BIT(1)
51#define SYSCFG_CMPCR_READY BIT(8)
52
53#define SYSCFG_CMPENSETR_MPU_EN BIT(0)
54
55#define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16)
56#define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17)
57
58#define SYSCFG_PMCSETR_ETH_SELMII BIT(20)
59
60#define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21)
Christophe Roullier69ac3f52019-05-17 15:08:43 +020061#define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0
62#define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21)
63#define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23)
Patrick Delaunay4ace1d12019-02-27 17:01:24 +010064
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010065/*
66 * Get a global data pointer
67 */
68DECLARE_GLOBAL_DATA_PTR;
69
Patrice Chotardcded32f2019-04-30 18:09:38 +020070#define USB_LOW_THRESHOLD_UV 200000
Patrice Chotard879cde52019-02-12 16:50:40 +010071#define USB_WARNING_LOW_THRESHOLD_UV 660000
72#define USB_START_LOW_THRESHOLD_UV 1230000
Patrice Chotardcded32f2019-04-30 18:09:38 +020073#define USB_START_HIGH_THRESHOLD_UV 2150000
Patrice Chotard879cde52019-02-12 16:50:40 +010074
Patrick Delaunay92dc1022019-02-12 11:44:41 +010075int checkboard(void)
76{
77 int ret;
78 char *mode;
79 u32 otp;
80 struct udevice *dev;
81 const char *fdt_compat;
82 int fdt_compat_len;
83
Patrick Delaunayff215a42019-07-02 13:26:06 +020084 if (IS_ENABLED(CONFIG_STM32MP1_OPTEE))
85 mode = "trusted with OP-TEE";
86 else if (IS_ENABLED(CONFIG_STM32MP1_TRUSTED))
Patrick Delaunay92dc1022019-02-12 11:44:41 +010087 mode = "trusted";
88 else
89 mode = "basic";
90
91 printf("Board: stm32mp1 in %s mode", mode);
92 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
93 &fdt_compat_len);
94 if (fdt_compat && fdt_compat_len)
95 printf(" (%s)", fdt_compat);
96 puts("\n");
97
98 ret = uclass_get_device_by_driver(UCLASS_MISC,
99 DM_GET_DRIVER(stm32mp_bsec),
100 &dev);
101
102 if (!ret)
103 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
104 &otp, sizeof(otp));
105 if (!ret && otp) {
106 printf("Board: MB%04x Var%d Rev.%c-%02d\n",
107 otp >> 16,
108 (otp >> 12) & 0xF,
109 ((otp >> 8) & 0xF) - 1 + 'A',
110 otp & 0xF);
111 }
112
113 return 0;
114}
115
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100116static void board_key_check(void)
117{
118#if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
119 ofnode node;
120 struct gpio_desc gpio;
121 enum forced_boot_mode boot_mode = BOOT_NORMAL;
122
123 node = ofnode_path("/config");
124 if (!ofnode_valid(node)) {
125 debug("%s: no /config node?\n", __func__);
126 return;
127 }
128#ifdef CONFIG_FASTBOOT
129 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
130 &gpio, GPIOD_IS_IN)) {
131 debug("%s: could not find a /config/st,fastboot-gpios\n",
132 __func__);
133 } else {
134 if (dm_gpio_get_value(&gpio)) {
135 puts("Fastboot key pressed, ");
136 boot_mode = BOOT_FASTBOOT;
137 }
138
139 dm_gpio_free(NULL, &gpio);
140 }
141#endif
142#ifdef CONFIG_CMD_STM32PROG
143 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
144 &gpio, GPIOD_IS_IN)) {
145 debug("%s: could not find a /config/st,stm32prog-gpios\n",
146 __func__);
147 } else {
148 if (dm_gpio_get_value(&gpio)) {
149 puts("STM32Programmer key pressed, ");
150 boot_mode = BOOT_STM32PROG;
151 }
152 dm_gpio_free(NULL, &gpio);
153 }
154#endif
155
156 if (boot_mode != BOOT_NORMAL) {
157 puts("entering download mode...\n");
158 clrsetbits_le32(TAMP_BOOT_CONTEXT,
159 TAMP_BOOT_FORCED_MASK,
160 boot_mode);
161 }
162#endif
163}
164
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100165#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
Patrice Chotard204079b2018-08-10 17:12:14 +0200166
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100167/* STMicroelectronics STUSB1600 Type-C controller */
168#define STUSB1600_CC_CONNECTION_STATUS 0x0E
169
170/* STUSB1600_CC_CONNECTION_STATUS bitfields */
171#define STUSB1600_CC_ATTACH BIT(0)
172
173static int stusb1600_init(struct udevice **dev_stusb1600)
174{
175 ofnode node;
176 struct udevice *dev, *bus;
177 int ret;
178 u32 chip_addr;
179
180 *dev_stusb1600 = NULL;
181
182 /* if node stusb1600 is present, means DK1 or DK2 board */
183 node = ofnode_by_compatible(ofnode_null(), "st,stusb1600");
184 if (!ofnode_valid(node))
185 return -ENODEV;
186
187 ret = ofnode_read_u32(node, "reg", &chip_addr);
188 if (ret)
189 return -EINVAL;
190
191 ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node),
192 &bus);
193 if (ret) {
194 printf("bus for stusb1600 not found\n");
195 return -ENODEV;
196 }
197
198 ret = dm_i2c_probe(bus, chip_addr, 0, &dev);
199 if (!ret)
200 *dev_stusb1600 = dev;
201
202 return ret;
203}
204
205static int stusb1600_cable_connected(struct udevice *dev)
206{
207 u8 status;
208
209 if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1))
210 return 0;
211
212 return status & STUSB1600_CC_ATTACH;
213}
214
215#include <usb/dwc2_udc.h>
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100216int g_dnl_board_usb_cable_connected(void)
Patrice Chotard204079b2018-08-10 17:12:14 +0200217{
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100218 struct udevice *stusb1600;
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100219 struct udevice *dwc2_udc_otg;
Patrice Chotard204079b2018-08-10 17:12:14 +0200220 int ret;
221
Patrick Delaunay7f3384d2019-03-29 15:42:24 +0100222 if (!stusb1600_init(&stusb1600))
223 return stusb1600_cable_connected(stusb1600);
224
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100225 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
226 DM_GET_DRIVER(dwc2_udc_otg),
227 &dwc2_udc_otg);
228 if (!ret)
229 debug("dwc2_udc_otg init failed\n");
Patrice Chotard204079b2018-08-10 17:12:14 +0200230
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100231 return dwc2_udc_B_session_valid(dwc2_udc_otg);
Patrice Chotard879cde52019-02-12 16:50:40 +0100232}
Patrick Delaunay58bc0cd2019-03-29 15:42:23 +0100233#endif /* CONFIG_USB_GADGET */
Patrice Chotard879cde52019-02-12 16:50:40 +0100234
235static int get_led(struct udevice **dev, char *led_string)
236{
237 char *led_name;
238 int ret;
239
240 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
241 if (!led_name) {
242 pr_debug("%s: could not find %s config string\n",
243 __func__, led_string);
244 return -ENOENT;
245 }
246 ret = led_get_by_label(led_name, dev);
247 if (ret) {
248 debug("%s: get=%d\n", __func__, ret);
249 return ret;
250 }
251
252 return 0;
253}
254
255static int setup_led(enum led_state_t cmd)
256{
257 struct udevice *dev;
258 int ret;
259
260 ret = get_led(&dev, "u-boot,boot-led");
261 if (ret)
262 return ret;
263
264 ret = led_set_state(dev, cmd);
Patrice Chotard204079b2018-08-10 17:12:14 +0200265 return ret;
266}
267
Patrice Chotard879cde52019-02-12 16:50:40 +0100268static int board_check_usb_power(void)
269{
270 struct ofnode_phandle_args adc_args;
271 struct udevice *adc;
272 struct udevice *led;
273 ofnode node;
274 unsigned int raw;
275 int max_uV = 0;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200276 int min_uV = USB_START_HIGH_THRESHOLD_UV;
Patrice Chotard879cde52019-02-12 16:50:40 +0100277 int ret, uV, adc_count;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200278 u32 nb_blink;
279 u8 i;
Patrice Chotard879cde52019-02-12 16:50:40 +0100280 node = ofnode_path("/config");
281 if (!ofnode_valid(node)) {
282 debug("%s: no /config node?\n", __func__);
283 return -ENOENT;
284 }
285
286 /*
287 * Retrieve the ADC channels devices and get measurement
288 * for each of them
289 */
290 adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
291 "#io-channel-cells");
292 if (adc_count < 0) {
293 if (adc_count == -ENOENT)
294 return 0;
295
296 pr_err("%s: can't find adc channel (%d)\n", __func__,
297 adc_count);
298
299 return adc_count;
300 }
301
302 for (i = 0; i < adc_count; i++) {
303 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
304 "#io-channel-cells", 0, i,
305 &adc_args)) {
306 pr_debug("%s: can't find /config/st,adc_usb_pd\n",
307 __func__);
308 return 0;
309 }
310
311 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
312 &adc);
313
314 if (ret) {
315 pr_err("%s: Can't get adc device(%d)\n", __func__,
316 ret);
317 return ret;
318 }
319
320 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
321 &raw);
322 if (ret) {
323 pr_err("%s: single shot failed for %s[%d]!\n",
324 __func__, adc->name, adc_args.args[0]);
325 return ret;
326 }
327 /* Convert to uV */
328 if (!adc_raw_to_uV(adc, raw, &uV)) {
329 if (uV > max_uV)
330 max_uV = uV;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200331 if (uV < min_uV)
332 min_uV = uV;
Patrice Chotard879cde52019-02-12 16:50:40 +0100333 pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
334 adc->name, adc_args.args[0], raw, uV);
335 } else {
336 pr_err("%s: Can't get uV value for %s[%d]\n",
337 __func__, adc->name, adc_args.args[0]);
338 }
339 }
340
341 /*
342 * If highest value is inside 1.23 Volts and 2.10 Volts, that means
343 * board is plugged on an USB-C 3A power supply and boot process can
344 * continue.
345 */
346 if (max_uV > USB_START_LOW_THRESHOLD_UV &&
Patrice Chotardcded32f2019-04-30 18:09:38 +0200347 max_uV <= USB_START_HIGH_THRESHOLD_UV &&
348 min_uV <= USB_LOW_THRESHOLD_UV)
Patrice Chotard879cde52019-02-12 16:50:40 +0100349 return 0;
350
Patrice Chotardcded32f2019-04-30 18:09:38 +0200351 pr_err("****************************************************\n");
352
353 /*
354 * If highest and lowest value are either both below
355 * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
356 * means USB TYPE-C is in unattached mode, this is an issue, make
357 * u-boot,error-led blinking and stop boot process.
358 */
359 if ((max_uV > USB_LOW_THRESHOLD_UV &&
360 min_uV > USB_LOW_THRESHOLD_UV) ||
361 (max_uV <= USB_LOW_THRESHOLD_UV &&
362 min_uV <= USB_LOW_THRESHOLD_UV)) {
363 pr_err("* ERROR USB TYPE-C connection in unattached mode *\n");
364 pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
365 /* with 125ms interval, led will blink for 17.02 years ....*/
366 nb_blink = U32_MAX;
367 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100368
Patrice Chotardcded32f2019-04-30 18:09:38 +0200369 if (max_uV > USB_LOW_THRESHOLD_UV &&
370 max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
371 min_uV <= USB_LOW_THRESHOLD_UV) {
372 pr_err("* WARNING 500mA power supply detected *\n");
Patrice Chotard879cde52019-02-12 16:50:40 +0100373 nb_blink = 2;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200374 }
375
376 if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
377 max_uV <= USB_START_LOW_THRESHOLD_UV &&
378 min_uV <= USB_LOW_THRESHOLD_UV) {
379 pr_err("* WARNING 1.5mA power supply detected *\n");
Patrice Chotard879cde52019-02-12 16:50:40 +0100380 nb_blink = 3;
381 }
382
Patrice Chotardcded32f2019-04-30 18:09:38 +0200383 /*
384 * If highest value is above 2.15 Volts that means that the USB TypeC
385 * supplies more than 3 Amp, this is not compliant with TypeC specification
386 */
387 if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
388 pr_err("* USB TYPE-C charger not compliant with *\n");
389 pr_err("* specification *\n");
390 pr_err("****************************************************\n\n");
391 /* with 125ms interval, led will blink for 17.02 years ....*/
392 nb_blink = U32_MAX;
393 } else {
394 pr_err("* Current too low, use a 3A power supply! *\n");
395 pr_err("****************************************************\n\n");
396 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100397
398 ret = get_led(&led, "u-boot,error-led");
Patrice Chotardcded32f2019-04-30 18:09:38 +0200399 if (ret) {
400 /* in unattached case, the boot process must be stopped */
401 if (nb_blink == U32_MAX)
402 hang();
Patrice Chotard879cde52019-02-12 16:50:40 +0100403 return ret;
Patrice Chotardcded32f2019-04-30 18:09:38 +0200404 }
Patrice Chotard879cde52019-02-12 16:50:40 +0100405
Patrice Chotardcded32f2019-04-30 18:09:38 +0200406 /* make u-boot,error-led blinking */
Patrice Chotard879cde52019-02-12 16:50:40 +0100407 for (i = 0; i < nb_blink * 2; i++) {
408 led_set_state(led, LEDST_TOGGLE);
409 mdelay(125);
410 }
411 led_set_state(led, LEDST_ON);
412
413 return 0;
414}
415
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100416static void sysconf_init(void)
417{
418#ifndef CONFIG_STM32MP1_TRUSTED
419 u8 *syscfg;
420#ifdef CONFIG_DM_REGULATOR
421 struct udevice *pwr_dev;
422 struct udevice *pwr_reg;
423 struct udevice *dev;
424 int ret;
425 u32 otp = 0;
426#endif
427 u32 bootr;
428
429 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
430
431 /* interconnect update : select master using the port 1 */
432 /* LTDC = AXI_M9 */
433 /* GPU = AXI_M8 */
434 /* today information is hardcoded in U-Boot */
435 writel(BIT(9), syscfg + SYSCFG_ICNR);
436
437 /* disable Pull-Down for boot pin connected to VDD */
438 bootr = readl(syscfg + SYSCFG_BOOTR);
439 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
440 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
441 writel(bootr, syscfg + SYSCFG_BOOTR);
442
443#ifdef CONFIG_DM_REGULATOR
444 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
445 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
446 * The customer will have to disable this for low frequencies
447 * or if AFMUX is selected but the function not used, typically for
448 * TRACE. Otherwise, impact on power consumption.
449 *
450 * WARNING:
451 * enabling High Speed mode while VDD>2.7V
452 * with the OTP product_below_2v5 (OTP 18, BIT 13)
453 * erroneously set to 1 can damage the IC!
454 * => U-Boot set the register only if VDD < 2.7V (in DT)
455 * but this value need to be consistent with board design
456 */
457 ret = syscon_get_by_driver_data(STM32MP_SYSCON_PWR, &pwr_dev);
458 if (!ret) {
459 ret = uclass_get_device_by_driver(UCLASS_MISC,
460 DM_GET_DRIVER(stm32mp_bsec),
461 &dev);
462 if (ret) {
463 pr_err("Can't find stm32mp_bsec driver\n");
464 return;
465 }
466
467 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
468 if (!ret)
469 otp = otp & BIT(13);
470
471 /* get VDD = pwr-supply */
472 ret = device_get_supply_regulator(pwr_dev, "pwr-supply",
473 &pwr_reg);
474
475 /* check if VDD is Low Voltage */
476 if (!ret) {
477 if (regulator_get_value(pwr_reg) < 2700000) {
478 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
479 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
480 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
481 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
482 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
483 syscfg + SYSCFG_IOCTRLSETR);
484
485 if (!otp)
486 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
487 } else {
488 if (otp)
489 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
490 }
491 } else {
492 debug("VDD unknown");
493 }
494 }
495#endif
496
497 /* activate automatic I/O compensation
498 * warning: need to ensure CSI enabled and ready in clock driver
499 */
500 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
501
502 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
503 ;
504 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
505#endif
506}
507
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100508/* board dependent setup after realloc */
509int board_init(void)
510{
Patrice Chotard972723a2019-03-11 11:13:17 +0100511 struct udevice *dev;
512
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100513 /* address of boot parameters */
514 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
515
Patrice Chotard972723a2019-03-11 11:13:17 +0100516 /* probe all PINCTRL for hog */
517 for (uclass_first_device(UCLASS_PINCTRL, &dev);
518 dev;
519 uclass_next_device(&dev)) {
520 pr_debug("probe pincontrol = %s\n", dev->name);
521 }
522
Patrick Delaunay008d3c32019-02-27 17:01:20 +0100523 board_key_check();
524
Patrick Delaunay6519e442019-07-05 17:20:09 +0200525#ifdef CONFIG_DM_REGULATOR
526 regulators_enable_boot_on(_DEBUG);
527#endif
528
Patrick Delaunay4ace1d12019-02-27 17:01:24 +0100529 sysconf_init();
530
Patrick Delaunay36e3d112018-07-27 16:37:08 +0200531 if (IS_ENABLED(CONFIG_LED))
532 led_default_state();
533
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100534 return 0;
535}
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100536
537int board_late_init(void)
538{
539#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
540 const void *fdt_compat;
541 int fdt_compat_len;
542
543 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
544 &fdt_compat_len);
545 if (fdt_compat && fdt_compat_len) {
546 if (strncmp(fdt_compat, "st,", 3) != 0)
547 env_set("board_name", fdt_compat);
548 else
549 env_set("board_name", fdt_compat + 3);
550 }
551#endif
552
Patrice Chotard879cde52019-02-12 16:50:40 +0100553 /* for DK1/DK2 boards */
554 board_check_usb_power();
555
Patrick Delaunayd70e3f82019-02-27 17:01:11 +0100556 return 0;
557}
Patrice Chotard879cde52019-02-12 16:50:40 +0100558
559void board_quiesce_devices(void)
560{
561 setup_led(LEDST_OFF);
562}
Patrice Chotard41443cf2019-05-02 18:07:14 +0200563
Christophe Roullier69ac3f52019-05-17 15:08:43 +0200564/* board interface eth init */
565/* this is a weak define that we are overriding */
566int board_interface_eth_init(phy_interface_t interface_type,
567 bool eth_clk_sel_reg, bool eth_ref_clk_sel_reg)
568{
569 u8 *syscfg;
570 u32 value;
571
572 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
573
574 if (!syscfg)
575 return -ENODEV;
576
577 switch (interface_type) {
578 case PHY_INTERFACE_MODE_MII:
579 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
580 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
581 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
582 break;
583 case PHY_INTERFACE_MODE_GMII:
584 if (eth_clk_sel_reg)
585 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
586 SYSCFG_PMCSETR_ETH_CLK_SEL;
587 else
588 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
589 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
590 break;
591 case PHY_INTERFACE_MODE_RMII:
592 if (eth_ref_clk_sel_reg)
593 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
594 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
595 else
596 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
597 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
598 break;
599 case PHY_INTERFACE_MODE_RGMII:
600 case PHY_INTERFACE_MODE_RGMII_ID:
601 case PHY_INTERFACE_MODE_RGMII_RXID:
602 case PHY_INTERFACE_MODE_RGMII_TXID:
603 if (eth_clk_sel_reg)
604 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
605 SYSCFG_PMCSETR_ETH_CLK_SEL;
606 else
607 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
608 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
609 break;
610 default:
611 debug("%s: Do not manage %d interface\n",
612 __func__, interface_type);
613 /* Do not manage others interfaces */
614 return -EINVAL;
615 }
616
617 /* clear and set ETH configuration bits */
618 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
619 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
620 syscfg + SYSCFG_PMCCLRR);
621 writel(value, syscfg + SYSCFG_PMCSETR);
622
623 return 0;
624}
625
Patrice Chotard34320372019-05-02 18:28:05 +0200626enum env_location env_get_location(enum env_operation op, int prio)
627{
628 u32 bootmode = get_bootmode();
629
630 if (prio)
631 return ENVL_UNKNOWN;
632
633 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
634#ifdef CONFIG_ENV_IS_IN_EXT4
635 case BOOT_FLASH_SD:
636 case BOOT_FLASH_EMMC:
637 return ENVL_EXT4;
638#endif
639#ifdef CONFIG_ENV_IS_IN_UBI
640 case BOOT_FLASH_NAND:
641 return ENVL_UBI;
642#endif
Patrice Chotard2c461ec2019-05-09 14:25:36 +0200643#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
644 case BOOT_FLASH_NOR:
645 return ENVL_SPI_FLASH;
646#endif
Patrice Chotard34320372019-05-02 18:28:05 +0200647 default:
648 return ENVL_NOWHERE;
649 }
650}
651
Patrice Chotarddad97bf2019-05-02 18:36:01 +0200652#if defined(CONFIG_ENV_IS_IN_EXT4)
653const char *env_ext4_get_intf(void)
654{
655 u32 bootmode = get_bootmode();
656
657 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
658 case BOOT_FLASH_SD:
659 case BOOT_FLASH_EMMC:
660 return "mmc";
661 default:
662 return "";
663 }
664}
665
666const char *env_ext4_get_dev_part(void)
667{
668 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
669 u32 bootmode = get_bootmode();
670
671 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
672}
673#endif
674
Patrice Chotard41443cf2019-05-02 18:07:14 +0200675#ifdef CONFIG_SYS_MTDPARTS_RUNTIME
676
677#define MTDPARTS_LEN 256
678#define MTDIDS_LEN 128
679
680/**
681 * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
682 * If we need to access it before the env is relocated, then we need
683 * to use our own stack buffer. gd->env_buf will be too small.
684 *
685 * @param buf temporary buffer pointer MTDPARTS_LEN long
686 * @return mtdparts variable string, NULL if not found
687 */
688static const char *env_get_mtdparts(const char *str, char *buf)
689{
690 if (gd->flags & GD_FLG_ENV_READY)
691 return env_get(str);
692 if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
693 return buf;
694
695 return NULL;
696}
697
698/**
699 * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
700 */
701static void board_get_mtdparts(const char *dev,
702 char *mtdids,
703 char *mtdparts)
704{
705 char env_name[32] = "mtdparts_";
706 char tmp_mtdparts[MTDPARTS_LEN];
707 const char *tmp;
708
709 /* name of env variable to read = mtdparts_<dev> */
710 strcat(env_name, dev);
711 tmp = env_get_mtdparts(env_name, tmp_mtdparts);
712 if (tmp) {
713 /* mtdids: "<dev>=<dev>, ...." */
714 if (mtdids[0] != '\0')
715 strcat(mtdids, ",");
716 strcat(mtdids, dev);
717 strcat(mtdids, "=");
718 strcat(mtdids, dev);
719
720 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
721 if (mtdparts[0] != '\0')
722 strncat(mtdparts, ";", MTDPARTS_LEN);
723 else
724 strcat(mtdparts, "mtdparts=");
725 strncat(mtdparts, dev, MTDPARTS_LEN);
726 strncat(mtdparts, ":", MTDPARTS_LEN);
727 strncat(mtdparts, tmp, MTDPARTS_LEN);
728 }
729}
730
731void board_mtdparts_default(const char **mtdids, const char **mtdparts)
732{
733 struct udevice *dev;
734 static char parts[2 * MTDPARTS_LEN + 1];
735 static char ids[MTDIDS_LEN + 1];
736 static bool mtd_initialized;
737
738 if (mtd_initialized) {
739 *mtdids = ids;
740 *mtdparts = parts;
741 return;
742 }
743
744 memset(parts, 0, sizeof(parts));
745 memset(ids, 0, sizeof(ids));
746
747 if (!uclass_get_device(UCLASS_MTD, 0, &dev))
748 board_get_mtdparts("nand0", ids, parts);
749
750 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
751 board_get_mtdparts("nor0", ids, parts);
752
753 mtd_initialized = true;
754 *mtdids = ids;
755 *mtdparts = parts;
756 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
757}
758#endif
Patrick Delaunayde98cbf2019-07-02 13:26:07 +0200759
760#if defined(CONFIG_OF_BOARD_SETUP)
761int ft_board_setup(void *blob, bd_t *bd)
762{
763#ifdef CONFIG_FDT_FIXUP_PARTITIONS
764 struct node_info nodes[] = {
765 { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
766 { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
767 };
768 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
769#endif
770
771 return 0;
772}
773#endif