blob: c9abe3cc6df193816f7f2e2cb4e69caf7b15cc80 [file] [log] [blame]
Marek Vasut19953732020-01-24 18:39:16 +01001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
4 */
5
6#include <common.h>
7#include <adc.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -06009#include <net.h>
Marek Vasut19953732020-01-24 18:39:16 +010010#include <asm/arch/stm32.h>
11#include <asm/arch/sys_proto.h>
12#include <asm/gpio.h>
13#include <asm/io.h>
14#include <bootm.h>
15#include <clk.h>
16#include <config.h>
17#include <dm.h>
18#include <dm/device.h>
19#include <dm/uclass.h>
20#include <env.h>
21#include <env_internal.h>
22#include <g_dnl.h>
23#include <generic-phy.h>
24#include <hang.h>
25#include <i2c.h>
26#include <i2c_eeprom.h>
27#include <init.h>
28#include <led.h>
29#include <memalign.h>
30#include <misc.h>
31#include <mtd.h>
32#include <mtd_node.h>
33#include <netdev.h>
34#include <phy.h>
Simon Glasscd93d622020-05-10 11:40:13 -060035#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060036#include <linux/delay.h>
Marek Vasut19953732020-01-24 18:39:16 +010037#include <power/regulator.h>
38#include <remoteproc.h>
39#include <reset.h>
40#include <syscon.h>
41#include <usb.h>
42#include <usb/dwc2_udc.h>
43#include <watchdog.h>
Patrick Delaunayd1a4b092020-05-25 12:19:46 +020044#include "../../st/common/stpmic1.h"
Marek Vasut19953732020-01-24 18:39:16 +010045
46/* SYSCFG registers */
47#define SYSCFG_BOOTR 0x00
48#define SYSCFG_PMCSETR 0x04
49#define SYSCFG_IOCTRLSETR 0x18
50#define SYSCFG_ICNR 0x1C
51#define SYSCFG_CMPCR 0x20
52#define SYSCFG_CMPENSETR 0x24
53#define SYSCFG_PMCCLRR 0x44
54
55#define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0)
56#define SYSCFG_BOOTR_BOOTPD_SHIFT 4
57
58#define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0)
59#define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1)
60#define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2)
61#define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3)
62#define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4)
63
64#define SYSCFG_CMPCR_SW_CTRL BIT(1)
65#define SYSCFG_CMPCR_READY BIT(8)
66
67#define SYSCFG_CMPENSETR_MPU_EN BIT(0)
68
69#define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16)
70#define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17)
71
72#define SYSCFG_PMCSETR_ETH_SELMII BIT(20)
73
74#define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21)
75#define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0
76#define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21)
77#define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23)
78
79/*
80 * Get a global data pointer
81 */
82DECLARE_GLOBAL_DATA_PTR;
83
84int setup_mac_address(void)
85{
Marek Vasut19953732020-01-24 18:39:16 +010086 unsigned char enetaddr[6];
Marek Vasut9ff770b2020-07-31 01:34:50 +020087 bool skip_eth0 = false;
88 bool skip_eth1 = false;
Marek Vasutf19312e2020-03-31 19:51:29 +020089 struct udevice *dev;
90 int off, ret;
Marek Vasut19953732020-01-24 18:39:16 +010091
92 ret = eth_env_get_enetaddr("ethaddr", enetaddr);
93 if (ret) /* ethaddr is already set */
Marek Vasut9ff770b2020-07-31 01:34:50 +020094 skip_eth0 = true;
95
96 off = fdt_path_offset(gd->fdt_blob, "ethernet1");
97 if (off < 0) {
98 /* ethernet1 is not present in the system */
99 skip_eth1 = true;
100 } else {
101 ret = eth_env_get_enetaddr("eth1addr", enetaddr);
102 if (ret) /* eth1addr is already set */
103 skip_eth1 = true;
104 }
105
106 if (skip_eth0 && skip_eth1)
Marek Vasut19953732020-01-24 18:39:16 +0100107 return 0;
108
Marek Vasutf19312e2020-03-31 19:51:29 +0200109 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
110 if (off < 0) {
111 printf("%s: No eeprom0 path offset\n", __func__);
112 return off;
Marek Vasut19953732020-01-24 18:39:16 +0100113 }
114
Marek Vasutf19312e2020-03-31 19:51:29 +0200115 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
Marek Vasut19953732020-01-24 18:39:16 +0100116 if (ret) {
117 printf("Cannot find EEPROM!\n");
118 return ret;
119 }
120
121 ret = i2c_eeprom_read(dev, 0xfa, enetaddr, 0x6);
122 if (ret) {
123 printf("Error reading configuration EEPROM!\n");
124 return ret;
125 }
126
Marek Vasut9ff770b2020-07-31 01:34:50 +0200127 if (is_valid_ethaddr(enetaddr)) {
128 if (!skip_eth0)
129 eth_env_set_enetaddr("ethaddr", enetaddr);
130
131 enetaddr[5]++;
132 if (!skip_eth1)
133 eth_env_set_enetaddr("eth1addr", enetaddr);
134 }
Marek Vasut19953732020-01-24 18:39:16 +0100135
136 return 0;
137}
138
139int checkboard(void)
140{
141 char *mode;
142 const char *fdt_compat;
143 int fdt_compat_len;
144
Patrick Delaunay43df0a12020-03-18 09:22:49 +0100145 if (IS_ENABLED(CONFIG_TFABOOT))
Marek Vasut19953732020-01-24 18:39:16 +0100146 mode = "trusted";
147 else
148 mode = "basic";
149
150 printf("Board: stm32mp1 in %s mode", mode);
151 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
152 &fdt_compat_len);
153 if (fdt_compat && fdt_compat_len)
154 printf(" (%s)", fdt_compat);
155 puts("\n");
156
157 return 0;
158}
159
Marek Vasut731fd502020-04-22 13:18:11 +0200160#ifdef CONFIG_BOARD_EARLY_INIT_F
161static u8 brdcode __section("data");
Marek Vasut2d683652020-04-22 13:18:14 +0200162static u8 ddr3code __section("data");
Marek Vasut731fd502020-04-22 13:18:11 +0200163static u8 somcode __section("data");
Patrick Delaunay2f238322020-05-25 12:19:47 +0200164static u32 opp_voltage_mv __section(".data");
Marek Vasut731fd502020-04-22 13:18:11 +0200165
166static void board_get_coding_straps(void)
167{
168 struct gpio_desc gpio[4];
169 ofnode node;
170 int i, ret;
171
172 node = ofnode_path("/config");
173 if (!ofnode_valid(node)) {
174 printf("%s: no /config node?\n", __func__);
175 return;
176 }
177
178 brdcode = 0;
Marek Vasut2d683652020-04-22 13:18:14 +0200179 ddr3code = 0;
Marek Vasut731fd502020-04-22 13:18:11 +0200180 somcode = 0;
181
182 ret = gpio_request_list_by_name_nodev(node, "dh,som-coding-gpios",
183 gpio, ARRAY_SIZE(gpio),
184 GPIOD_IS_IN);
185 for (i = 0; i < ret; i++)
186 somcode |= !!dm_gpio_get_value(&(gpio[i])) << i;
187
Marek Vasut2d683652020-04-22 13:18:14 +0200188 ret = gpio_request_list_by_name_nodev(node, "dh,ddr3-coding-gpios",
189 gpio, ARRAY_SIZE(gpio),
190 GPIOD_IS_IN);
191 for (i = 0; i < ret; i++)
192 ddr3code |= !!dm_gpio_get_value(&(gpio[i])) << i;
193
Marek Vasut731fd502020-04-22 13:18:11 +0200194 ret = gpio_request_list_by_name_nodev(node, "dh,board-coding-gpios",
195 gpio, ARRAY_SIZE(gpio),
196 GPIOD_IS_IN);
197 for (i = 0; i < ret; i++)
198 brdcode |= !!dm_gpio_get_value(&(gpio[i])) << i;
199
Marek Vasut2d683652020-04-22 13:18:14 +0200200 printf("Code: SoM:rev=%d,ddr3=%d Board:rev=%d\n",
201 somcode, ddr3code, brdcode);
202}
203
204int board_stm32mp1_ddr_config_name_match(struct udevice *dev,
205 const char *name)
206{
Marek Vasut92ca0f72020-04-29 15:08:38 +0200207 if (ddr3code == 1 &&
208 !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x1gb-533mhz"))
209 return 0;
210
Marek Vasut2d683652020-04-22 13:18:14 +0200211 if (ddr3code == 2 &&
Marek Vasut92ca0f72020-04-29 15:08:38 +0200212 !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x2gb-533mhz"))
Marek Vasut2d683652020-04-22 13:18:14 +0200213 return 0;
214
215 if (ddr3code == 3 &&
Marek Vasut92ca0f72020-04-29 15:08:38 +0200216 !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x4gb-533mhz"))
Marek Vasut2d683652020-04-22 13:18:14 +0200217 return 0;
218
219 return -EINVAL;
Marek Vasut731fd502020-04-22 13:18:11 +0200220}
221
Patrick Delaunay2f238322020-05-25 12:19:47 +0200222void board_vddcore_init(u32 voltage_mv)
223{
224 if (IS_ENABLED(CONFIG_SPL_BUILD))
225 opp_voltage_mv = voltage_mv;
226}
227
Marek Vasut731fd502020-04-22 13:18:11 +0200228int board_early_init_f(void)
229{
Patrick Delaunayd1a4b092020-05-25 12:19:46 +0200230 if (IS_ENABLED(CONFIG_SPL_BUILD))
Patrick Delaunay2f238322020-05-25 12:19:47 +0200231 stpmic1_init(opp_voltage_mv);
Marek Vasut731fd502020-04-22 13:18:11 +0200232 board_get_coding_straps();
233
234 return 0;
235}
236
237#ifdef CONFIG_SPL_LOAD_FIT
238int board_fit_config_name_match(const char *name)
239{
Marek Vasut49650c72020-07-31 01:35:33 +0200240 const char *compat;
241 char test[128];
Marek Vasut731fd502020-04-22 13:18:11 +0200242
Marek Vasut49650c72020-07-31 01:35:33 +0200243 compat = fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
244
245 snprintf(test, sizeof(test), "%s_somrev%d_boardrev%d",
246 compat, somcode, brdcode);
Marek Vasut731fd502020-04-22 13:18:11 +0200247
248 if (!strcmp(name, test))
249 return 0;
250
251 return -EINVAL;
252}
253#endif
254#endif
255
Marek Vasut19953732020-01-24 18:39:16 +0100256static void board_key_check(void)
257{
258#if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
259 ofnode node;
260 struct gpio_desc gpio;
261 enum forced_boot_mode boot_mode = BOOT_NORMAL;
262
263 node = ofnode_path("/config");
264 if (!ofnode_valid(node)) {
265 debug("%s: no /config node?\n", __func__);
266 return;
267 }
268#ifdef CONFIG_FASTBOOT
269 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
270 &gpio, GPIOD_IS_IN)) {
271 debug("%s: could not find a /config/st,fastboot-gpios\n",
272 __func__);
273 } else {
274 if (dm_gpio_get_value(&gpio)) {
275 puts("Fastboot key pressed, ");
276 boot_mode = BOOT_FASTBOOT;
277 }
278
279 dm_gpio_free(NULL, &gpio);
280 }
281#endif
282#ifdef CONFIG_CMD_STM32PROG
283 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
284 &gpio, GPIOD_IS_IN)) {
285 debug("%s: could not find a /config/st,stm32prog-gpios\n",
286 __func__);
287 } else {
288 if (dm_gpio_get_value(&gpio)) {
289 puts("STM32Programmer key pressed, ");
290 boot_mode = BOOT_STM32PROG;
291 }
292 dm_gpio_free(NULL, &gpio);
293 }
294#endif
295
296 if (boot_mode != BOOT_NORMAL) {
297 puts("entering download mode...\n");
298 clrsetbits_le32(TAMP_BOOT_CONTEXT,
299 TAMP_BOOT_FORCED_MASK,
300 boot_mode);
301 }
302#endif
303}
304
305#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
306
307#include <usb/dwc2_udc.h>
308int g_dnl_board_usb_cable_connected(void)
309{
310 struct udevice *dwc2_udc_otg;
311 int ret;
312
313 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
314 DM_GET_DRIVER(dwc2_udc_otg),
315 &dwc2_udc_otg);
316 if (!ret)
317 debug("dwc2_udc_otg init failed\n");
318
319 return dwc2_udc_B_session_valid(dwc2_udc_otg);
320}
321
322#define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
323#define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
324
325int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
326{
327 if (!strcmp(name, "usb_dnl_dfu"))
328 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
329 else if (!strcmp(name, "usb_dnl_fastboot"))
330 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
331 &dev->idProduct);
332 else
333 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
334
335 return 0;
336}
337
338#endif /* CONFIG_USB_GADGET */
339
340#ifdef CONFIG_LED
341static int get_led(struct udevice **dev, char *led_string)
342{
343 char *led_name;
344 int ret;
345
346 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
347 if (!led_name) {
348 pr_debug("%s: could not find %s config string\n",
349 __func__, led_string);
350 return -ENOENT;
351 }
352 ret = led_get_by_label(led_name, dev);
353 if (ret) {
354 debug("%s: get=%d\n", __func__, ret);
355 return ret;
356 }
357
358 return 0;
359}
360
361static int setup_led(enum led_state_t cmd)
362{
363 struct udevice *dev;
364 int ret;
365
366 ret = get_led(&dev, "u-boot,boot-led");
367 if (ret)
368 return ret;
369
370 ret = led_set_state(dev, cmd);
371 return ret;
372}
373#endif
374
375static void __maybe_unused led_error_blink(u32 nb_blink)
376{
377#ifdef CONFIG_LED
378 int ret;
379 struct udevice *led;
380 u32 i;
381#endif
382
383 if (!nb_blink)
384 return;
385
386#ifdef CONFIG_LED
387 ret = get_led(&led, "u-boot,error-led");
388 if (!ret) {
389 /* make u-boot,error-led blinking */
390 /* if U32_MAX and 125ms interval, for 17.02 years */
391 for (i = 0; i < 2 * nb_blink; i++) {
392 led_set_state(led, LEDST_TOGGLE);
393 mdelay(125);
394 WATCHDOG_RESET();
395 }
396 }
397#endif
398
399 /* infinite: the boot process must be stopped */
400 if (nb_blink == U32_MAX)
401 hang();
402}
403
404static void sysconf_init(void)
405{
Patrick Delaunay654706b2020-04-01 09:07:33 +0200406#ifndef CONFIG_TFABOOT
Marek Vasut19953732020-01-24 18:39:16 +0100407 u8 *syscfg;
408#ifdef CONFIG_DM_REGULATOR
409 struct udevice *pwr_dev;
410 struct udevice *pwr_reg;
411 struct udevice *dev;
412 int ret;
413 u32 otp = 0;
414#endif
415 u32 bootr;
416
417 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
418
419 /* interconnect update : select master using the port 1 */
420 /* LTDC = AXI_M9 */
421 /* GPU = AXI_M8 */
422 /* today information is hardcoded in U-Boot */
423 writel(BIT(9), syscfg + SYSCFG_ICNR);
424
425 /* disable Pull-Down for boot pin connected to VDD */
426 bootr = readl(syscfg + SYSCFG_BOOTR);
427 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
428 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
429 writel(bootr, syscfg + SYSCFG_BOOTR);
430
431#ifdef CONFIG_DM_REGULATOR
432 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
433 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
434 * The customer will have to disable this for low frequencies
435 * or if AFMUX is selected but the function not used, typically for
436 * TRACE. Otherwise, impact on power consumption.
437 *
438 * WARNING:
439 * enabling High Speed mode while VDD>2.7V
440 * with the OTP product_below_2v5 (OTP 18, BIT 13)
441 * erroneously set to 1 can damage the IC!
442 * => U-Boot set the register only if VDD < 2.7V (in DT)
443 * but this value need to be consistent with board design
444 */
445 ret = uclass_get_device_by_driver(UCLASS_PMIC,
446 DM_GET_DRIVER(stm32mp_pwr_pmic),
447 &pwr_dev);
448 if (!ret) {
449 ret = uclass_get_device_by_driver(UCLASS_MISC,
450 DM_GET_DRIVER(stm32mp_bsec),
451 &dev);
452 if (ret) {
453 pr_err("Can't find stm32mp_bsec driver\n");
454 return;
455 }
456
457 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
458 if (ret > 0)
459 otp = otp & BIT(13);
460
461 /* get VDD = vdd-supply */
462 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
463 &pwr_reg);
464
465 /* check if VDD is Low Voltage */
466 if (!ret) {
467 if (regulator_get_value(pwr_reg) < 2700000) {
468 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
469 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
470 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
471 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
472 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
473 syscfg + SYSCFG_IOCTRLSETR);
474
475 if (!otp)
476 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
477 } else {
478 if (otp)
479 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
480 }
481 } else {
482 debug("VDD unknown");
483 }
484 }
485#endif
486
487 /* activate automatic I/O compensation
488 * warning: need to ensure CSI enabled and ready in clock driver
489 */
490 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
491
492 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
493 ;
494 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
495#endif
496}
497
Marek Vasutde80a242020-03-28 02:01:58 +0100498static void board_init_fmc2(void)
499{
500#define STM32_FMC2_BCR1 0x0
501#define STM32_FMC2_BTR1 0x4
502#define STM32_FMC2_BWTR1 0x104
503#define STM32_FMC2_BCR(x) ((x) * 0x8 + STM32_FMC2_BCR1)
504#define STM32_FMC2_BCRx_FMCEN BIT(31)
505#define STM32_FMC2_BCRx_WREN BIT(12)
506#define STM32_FMC2_BCRx_RSVD BIT(7)
507#define STM32_FMC2_BCRx_FACCEN BIT(6)
508#define STM32_FMC2_BCRx_MWID(n) ((n) << 4)
509#define STM32_FMC2_BCRx_MTYP(n) ((n) << 2)
510#define STM32_FMC2_BCRx_MUXEN BIT(1)
511#define STM32_FMC2_BCRx_MBKEN BIT(0)
512#define STM32_FMC2_BTR(x) ((x) * 0x8 + STM32_FMC2_BTR1)
513#define STM32_FMC2_BTRx_DATAHLD(n) ((n) << 30)
514#define STM32_FMC2_BTRx_BUSTURN(n) ((n) << 16)
515#define STM32_FMC2_BTRx_DATAST(n) ((n) << 8)
516#define STM32_FMC2_BTRx_ADDHLD(n) ((n) << 4)
517#define STM32_FMC2_BTRx_ADDSET(n) ((n) << 0)
518
519#define RCC_MP_AHB6RSTCLRR 0x218
520#define RCC_MP_AHB6RSTCLRR_FMCRST BIT(12)
521#define RCC_MP_AHB6ENSETR 0x19c
522#define RCC_MP_AHB6ENSETR_FMCEN BIT(12)
523
524 const u32 bcr = STM32_FMC2_BCRx_WREN |STM32_FMC2_BCRx_RSVD |
525 STM32_FMC2_BCRx_FACCEN | STM32_FMC2_BCRx_MWID(1) |
526 STM32_FMC2_BCRx_MTYP(2) | STM32_FMC2_BCRx_MUXEN |
527 STM32_FMC2_BCRx_MBKEN;
528 const u32 btr = STM32_FMC2_BTRx_DATAHLD(3) |
529 STM32_FMC2_BTRx_BUSTURN(2) |
530 STM32_FMC2_BTRx_DATAST(0x22) |
531 STM32_FMC2_BTRx_ADDHLD(2) |
532 STM32_FMC2_BTRx_ADDSET(2);
533
534 /* Set up FMC2 bus for KS8851-16MLL and X11 SRAM */
535 writel(RCC_MP_AHB6RSTCLRR_FMCRST, STM32_RCC_BASE + RCC_MP_AHB6RSTCLRR);
536 writel(RCC_MP_AHB6ENSETR_FMCEN, STM32_RCC_BASE + RCC_MP_AHB6ENSETR);
537
538 /* KS8851-16MLL -- Muxed mode */
539 writel(bcr, STM32_FMC2_BASE + STM32_FMC2_BCR(1));
540 writel(btr, STM32_FMC2_BASE + STM32_FMC2_BTR(1));
541 /* AS7C34098 SRAM on X11 -- Muxed mode */
542 writel(bcr, STM32_FMC2_BASE + STM32_FMC2_BCR(3));
543 writel(btr, STM32_FMC2_BASE + STM32_FMC2_BTR(3));
544
545 setbits_le32(STM32_FMC2_BASE + STM32_FMC2_BCR1, STM32_FMC2_BCRx_FMCEN);
546}
547
Marek Vasut19953732020-01-24 18:39:16 +0100548/* board dependent setup after realloc */
549int board_init(void)
550{
Marek Vasut19953732020-01-24 18:39:16 +0100551 /* address of boot parameters */
552 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
553
Patrick Delaunay6826d0d2020-07-02 15:20:47 +0200554 if (CONFIG_IS_ENABLED(DM_GPIO_HOG))
555 gpio_hog_probe_all();
Marek Vasut19953732020-01-24 18:39:16 +0100556
557 board_key_check();
558
559#ifdef CONFIG_DM_REGULATOR
560 regulators_enable_boot_on(_DEBUG);
561#endif
562
563 sysconf_init();
564
Marek Vasutde80a242020-03-28 02:01:58 +0100565 board_init_fmc2();
566
Patrick Delaunay71ba2cb2020-04-10 19:14:01 +0200567 if (CONFIG_IS_ENABLED(LED))
Marek Vasut19953732020-01-24 18:39:16 +0100568 led_default_state();
569
570 return 0;
571}
572
573int board_late_init(void)
574{
575 char *boot_device;
576#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
577 const void *fdt_compat;
578 int fdt_compat_len;
579
580 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
581 &fdt_compat_len);
582 if (fdt_compat && fdt_compat_len) {
583 if (strncmp(fdt_compat, "st,", 3) != 0)
584 env_set("board_name", fdt_compat);
585 else
586 env_set("board_name", fdt_compat + 3);
587 }
588#endif
589
590 /* Check the boot-source to disable bootdelay */
591 boot_device = env_get("boot_device");
592 if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
593 env_set("bootdelay", "0");
594
Marek Vasut731fd502020-04-22 13:18:11 +0200595#ifdef CONFIG_BOARD_EARLY_INIT_F
596 env_set_ulong("dh_som_rev", somcode);
597 env_set_ulong("dh_board_rev", brdcode);
Marek Vasut2d683652020-04-22 13:18:14 +0200598 env_set_ulong("dh_ddr3_code", ddr3code);
Marek Vasut731fd502020-04-22 13:18:11 +0200599#endif
600
Marek Vasut19953732020-01-24 18:39:16 +0100601 return 0;
602}
603
604void board_quiesce_devices(void)
605{
606#ifdef CONFIG_LED
607 setup_led(LEDST_OFF);
608#endif
609}
610
611/* eth init function : weak called in eqos driver */
612int board_interface_eth_init(struct udevice *dev,
613 phy_interface_t interface_type)
614{
615 u8 *syscfg;
616 u32 value;
617 bool eth_clk_sel_reg = false;
618 bool eth_ref_clk_sel_reg = false;
619
620 /* Gigabit Ethernet 125MHz clock selection. */
621 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
622
623 /* Ethernet 50Mhz RMII clock selection */
624 eth_ref_clk_sel_reg =
625 dev_read_bool(dev, "st,eth_ref_clk_sel");
626
627 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
628
629 if (!syscfg)
630 return -ENODEV;
631
632 switch (interface_type) {
633 case PHY_INTERFACE_MODE_MII:
634 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
635 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
636 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
637 break;
638 case PHY_INTERFACE_MODE_GMII:
639 if (eth_clk_sel_reg)
640 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
641 SYSCFG_PMCSETR_ETH_CLK_SEL;
642 else
643 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
644 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
645 break;
646 case PHY_INTERFACE_MODE_RMII:
647 if (eth_ref_clk_sel_reg)
648 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
649 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
650 else
651 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
652 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
653 break;
654 case PHY_INTERFACE_MODE_RGMII:
655 case PHY_INTERFACE_MODE_RGMII_ID:
656 case PHY_INTERFACE_MODE_RGMII_RXID:
657 case PHY_INTERFACE_MODE_RGMII_TXID:
658 if (eth_clk_sel_reg)
659 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
660 SYSCFG_PMCSETR_ETH_CLK_SEL;
661 else
662 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
663 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
664 break;
665 default:
666 debug("%s: Do not manage %d interface\n",
667 __func__, interface_type);
668 /* Do not manage others interfaces */
669 return -EINVAL;
670 }
671
672 /* clear and set ETH configuration bits */
673 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
674 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
675 syscfg + SYSCFG_PMCCLRR);
676 writel(value, syscfg + SYSCFG_PMCSETR);
677
678 return 0;
679}
680
Marek Vasut19953732020-01-24 18:39:16 +0100681#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900682int ft_board_setup(void *blob, struct bd_info *bd)
Marek Vasut19953732020-01-24 18:39:16 +0100683{
684 return 0;
685}
686#endif
687
Marek Vasut19953732020-01-24 18:39:16 +0100688static void board_copro_image_process(ulong fw_image, size_t fw_size)
689{
690 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
691
692 if (!rproc_is_initialized())
693 if (rproc_init()) {
694 printf("Remote Processor %d initialization failed\n",
695 id);
696 return;
697 }
698
699 ret = rproc_load(id, fw_image, fw_size);
700 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
701 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
702
703 if (!ret) {
704 rproc_start(id);
705 env_set("copro_state", "booted");
706 }
707}
708
709U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);