blob: f42d395098bcc5c03bcfb6aec2afe51c1050b70c [file] [log] [blame]
Marek Vasut5ff05292020-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 Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Marek Vasut5ff05292020-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 Glass4dcacfc2020-05-10 11:40:13 -060035#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060036#include <linux/delay.h>
Marek Vasut5ff05292020-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 Delaunayf2f25c32020-05-25 12:19:46 +020044#include "../../st/common/stpmic1.h"
Marek Vasut5ff05292020-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
Marek Vasut145a8762020-10-08 15:14:58 +020084#define KS_CCR 0x08
85#define KS_CCR_EEPROM BIT(9)
86#define KS_BE0 BIT(12)
87#define KS_BE1 BIT(13)
88
Marek Vasut5ff05292020-01-24 18:39:16 +010089int setup_mac_address(void)
90{
Marek Vasut5ff05292020-01-24 18:39:16 +010091 unsigned char enetaddr[6];
Marek Vasutb0a2a492020-07-31 01:34:50 +020092 bool skip_eth0 = false;
93 bool skip_eth1 = false;
Marek Vasut2ab7a2a2020-03-31 19:51:29 +020094 struct udevice *dev;
95 int off, ret;
Marek Vasut5ff05292020-01-24 18:39:16 +010096
97 ret = eth_env_get_enetaddr("ethaddr", enetaddr);
98 if (ret) /* ethaddr is already set */
Marek Vasutb0a2a492020-07-31 01:34:50 +020099 skip_eth0 = true;
100
101 off = fdt_path_offset(gd->fdt_blob, "ethernet1");
102 if (off < 0) {
103 /* ethernet1 is not present in the system */
104 skip_eth1 = true;
Marek Vasut145a8762020-10-08 15:14:58 +0200105 goto out_set_ethaddr;
106 }
107
108 ret = eth_env_get_enetaddr("eth1addr", enetaddr);
109 if (ret) {
110 /* eth1addr is already set */
111 skip_eth1 = true;
112 goto out_set_ethaddr;
113 }
114
115 ret = fdt_node_check_compatible(gd->fdt_blob, off, "micrel,ks8851-mll");
116 if (ret)
117 goto out_set_ethaddr;
118
119 /*
120 * KS8851 with EEPROM may use custom MAC from EEPROM, read
121 * out the KS8851 CCR register to determine whether EEPROM
122 * is present. If EEPROM is present, it must contain valid
123 * MAC address.
124 */
125 u32 reg, ccr;
126 reg = fdt_get_base_address(gd->fdt_blob, off);
127 if (!reg)
128 goto out_set_ethaddr;
129
130 writew(KS_BE0 | KS_BE1 | KS_CCR, reg + 2);
131 ccr = readw(reg);
132 if (ccr & KS_CCR_EEPROM) {
133 skip_eth1 = true;
134 goto out_set_ethaddr;
Marek Vasutb0a2a492020-07-31 01:34:50 +0200135 }
136
Marek Vasut145a8762020-10-08 15:14:58 +0200137out_set_ethaddr:
Marek Vasutb0a2a492020-07-31 01:34:50 +0200138 if (skip_eth0 && skip_eth1)
Marek Vasut5ff05292020-01-24 18:39:16 +0100139 return 0;
140
Marek Vasut2ab7a2a2020-03-31 19:51:29 +0200141 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
142 if (off < 0) {
143 printf("%s: No eeprom0 path offset\n", __func__);
144 return off;
Marek Vasut5ff05292020-01-24 18:39:16 +0100145 }
146
Marek Vasut2ab7a2a2020-03-31 19:51:29 +0200147 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
Marek Vasut5ff05292020-01-24 18:39:16 +0100148 if (ret) {
149 printf("Cannot find EEPROM!\n");
150 return ret;
151 }
152
153 ret = i2c_eeprom_read(dev, 0xfa, enetaddr, 0x6);
154 if (ret) {
155 printf("Error reading configuration EEPROM!\n");
156 return ret;
157 }
158
Marek Vasutb0a2a492020-07-31 01:34:50 +0200159 if (is_valid_ethaddr(enetaddr)) {
160 if (!skip_eth0)
161 eth_env_set_enetaddr("ethaddr", enetaddr);
162
163 enetaddr[5]++;
164 if (!skip_eth1)
165 eth_env_set_enetaddr("eth1addr", enetaddr);
166 }
Marek Vasut5ff05292020-01-24 18:39:16 +0100167
168 return 0;
169}
170
171int checkboard(void)
172{
173 char *mode;
174 const char *fdt_compat;
175 int fdt_compat_len;
176
Patrick Delaunay472407a2020-03-18 09:22:49 +0100177 if (IS_ENABLED(CONFIG_TFABOOT))
Marek Vasut5ff05292020-01-24 18:39:16 +0100178 mode = "trusted";
179 else
180 mode = "basic";
181
182 printf("Board: stm32mp1 in %s mode", mode);
183 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
184 &fdt_compat_len);
185 if (fdt_compat && fdt_compat_len)
186 printf(" (%s)", fdt_compat);
187 puts("\n");
188
189 return 0;
190}
191
Marek Vasut47b98ba2020-04-22 13:18:11 +0200192#ifdef CONFIG_BOARD_EARLY_INIT_F
193static u8 brdcode __section("data");
Marek Vasut39221b52020-04-22 13:18:14 +0200194static u8 ddr3code __section("data");
Marek Vasut47b98ba2020-04-22 13:18:11 +0200195static u8 somcode __section("data");
Patrick Delaunay08c891a2020-05-25 12:19:47 +0200196static u32 opp_voltage_mv __section(".data");
Marek Vasut47b98ba2020-04-22 13:18:11 +0200197
198static void board_get_coding_straps(void)
199{
200 struct gpio_desc gpio[4];
201 ofnode node;
202 int i, ret;
203
204 node = ofnode_path("/config");
205 if (!ofnode_valid(node)) {
206 printf("%s: no /config node?\n", __func__);
207 return;
208 }
209
210 brdcode = 0;
Marek Vasut39221b52020-04-22 13:18:14 +0200211 ddr3code = 0;
Marek Vasut47b98ba2020-04-22 13:18:11 +0200212 somcode = 0;
213
214 ret = gpio_request_list_by_name_nodev(node, "dh,som-coding-gpios",
215 gpio, ARRAY_SIZE(gpio),
216 GPIOD_IS_IN);
217 for (i = 0; i < ret; i++)
218 somcode |= !!dm_gpio_get_value(&(gpio[i])) << i;
219
Marek Vasut39221b52020-04-22 13:18:14 +0200220 ret = gpio_request_list_by_name_nodev(node, "dh,ddr3-coding-gpios",
221 gpio, ARRAY_SIZE(gpio),
222 GPIOD_IS_IN);
223 for (i = 0; i < ret; i++)
224 ddr3code |= !!dm_gpio_get_value(&(gpio[i])) << i;
225
Marek Vasut47b98ba2020-04-22 13:18:11 +0200226 ret = gpio_request_list_by_name_nodev(node, "dh,board-coding-gpios",
227 gpio, ARRAY_SIZE(gpio),
228 GPIOD_IS_IN);
229 for (i = 0; i < ret; i++)
230 brdcode |= !!dm_gpio_get_value(&(gpio[i])) << i;
231
Marek Vasut39221b52020-04-22 13:18:14 +0200232 printf("Code: SoM:rev=%d,ddr3=%d Board:rev=%d\n",
233 somcode, ddr3code, brdcode);
234}
235
236int board_stm32mp1_ddr_config_name_match(struct udevice *dev,
237 const char *name)
238{
Marek Vasut272198e2020-04-29 15:08:38 +0200239 if (ddr3code == 1 &&
240 !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x1gb-533mhz"))
241 return 0;
242
Marek Vasut39221b52020-04-22 13:18:14 +0200243 if (ddr3code == 2 &&
Marek Vasut272198e2020-04-29 15:08:38 +0200244 !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x2gb-533mhz"))
Marek Vasut39221b52020-04-22 13:18:14 +0200245 return 0;
246
247 if (ddr3code == 3 &&
Marek Vasut272198e2020-04-29 15:08:38 +0200248 !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x4gb-533mhz"))
Marek Vasut39221b52020-04-22 13:18:14 +0200249 return 0;
250
251 return -EINVAL;
Marek Vasut47b98ba2020-04-22 13:18:11 +0200252}
253
Patrick Delaunay08c891a2020-05-25 12:19:47 +0200254void board_vddcore_init(u32 voltage_mv)
255{
256 if (IS_ENABLED(CONFIG_SPL_BUILD))
257 opp_voltage_mv = voltage_mv;
258}
259
Marek Vasut47b98ba2020-04-22 13:18:11 +0200260int board_early_init_f(void)
261{
Patrick Delaunayf2f25c32020-05-25 12:19:46 +0200262 if (IS_ENABLED(CONFIG_SPL_BUILD))
Patrick Delaunay08c891a2020-05-25 12:19:47 +0200263 stpmic1_init(opp_voltage_mv);
Marek Vasut47b98ba2020-04-22 13:18:11 +0200264 board_get_coding_straps();
265
266 return 0;
267}
268
269#ifdef CONFIG_SPL_LOAD_FIT
270int board_fit_config_name_match(const char *name)
271{
Marek Vasut060cb122020-07-31 01:35:33 +0200272 const char *compat;
273 char test[128];
274
275 compat = fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
Marek Vasut47b98ba2020-04-22 13:18:11 +0200276
Marek Vasut060cb122020-07-31 01:35:33 +0200277 snprintf(test, sizeof(test), "%s_somrev%d_boardrev%d",
278 compat, somcode, brdcode);
Marek Vasut47b98ba2020-04-22 13:18:11 +0200279
280 if (!strcmp(name, test))
281 return 0;
282
283 return -EINVAL;
284}
285#endif
286#endif
287
Marek Vasut5ff05292020-01-24 18:39:16 +0100288static void board_key_check(void)
289{
290#if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
291 ofnode node;
292 struct gpio_desc gpio;
293 enum forced_boot_mode boot_mode = BOOT_NORMAL;
294
295 node = ofnode_path("/config");
296 if (!ofnode_valid(node)) {
297 debug("%s: no /config node?\n", __func__);
298 return;
299 }
300#ifdef CONFIG_FASTBOOT
301 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
302 &gpio, GPIOD_IS_IN)) {
303 debug("%s: could not find a /config/st,fastboot-gpios\n",
304 __func__);
305 } else {
306 if (dm_gpio_get_value(&gpio)) {
307 puts("Fastboot key pressed, ");
308 boot_mode = BOOT_FASTBOOT;
309 }
310
311 dm_gpio_free(NULL, &gpio);
312 }
313#endif
314#ifdef CONFIG_CMD_STM32PROG
315 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
316 &gpio, GPIOD_IS_IN)) {
317 debug("%s: could not find a /config/st,stm32prog-gpios\n",
318 __func__);
319 } else {
320 if (dm_gpio_get_value(&gpio)) {
321 puts("STM32Programmer key pressed, ");
322 boot_mode = BOOT_STM32PROG;
323 }
324 dm_gpio_free(NULL, &gpio);
325 }
326#endif
327
328 if (boot_mode != BOOT_NORMAL) {
329 puts("entering download mode...\n");
330 clrsetbits_le32(TAMP_BOOT_CONTEXT,
331 TAMP_BOOT_FORCED_MASK,
332 boot_mode);
333 }
334#endif
335}
336
337#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
338
339#include <usb/dwc2_udc.h>
340int g_dnl_board_usb_cable_connected(void)
341{
342 struct udevice *dwc2_udc_otg;
343 int ret;
344
345 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
346 DM_GET_DRIVER(dwc2_udc_otg),
347 &dwc2_udc_otg);
348 if (!ret)
349 debug("dwc2_udc_otg init failed\n");
350
351 return dwc2_udc_B_session_valid(dwc2_udc_otg);
352}
353
354#define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
355#define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
356
357int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
358{
359 if (!strcmp(name, "usb_dnl_dfu"))
360 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
361 else if (!strcmp(name, "usb_dnl_fastboot"))
362 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
363 &dev->idProduct);
364 else
365 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
366
367 return 0;
368}
369
370#endif /* CONFIG_USB_GADGET */
371
372#ifdef CONFIG_LED
373static int get_led(struct udevice **dev, char *led_string)
374{
375 char *led_name;
376 int ret;
377
378 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
379 if (!led_name) {
380 pr_debug("%s: could not find %s config string\n",
381 __func__, led_string);
382 return -ENOENT;
383 }
384 ret = led_get_by_label(led_name, dev);
385 if (ret) {
386 debug("%s: get=%d\n", __func__, ret);
387 return ret;
388 }
389
390 return 0;
391}
392
393static int setup_led(enum led_state_t cmd)
394{
395 struct udevice *dev;
396 int ret;
397
398 ret = get_led(&dev, "u-boot,boot-led");
399 if (ret)
400 return ret;
401
402 ret = led_set_state(dev, cmd);
403 return ret;
404}
405#endif
406
407static void __maybe_unused led_error_blink(u32 nb_blink)
408{
409#ifdef CONFIG_LED
410 int ret;
411 struct udevice *led;
412 u32 i;
413#endif
414
415 if (!nb_blink)
416 return;
417
418#ifdef CONFIG_LED
419 ret = get_led(&led, "u-boot,error-led");
420 if (!ret) {
421 /* make u-boot,error-led blinking */
422 /* if U32_MAX and 125ms interval, for 17.02 years */
423 for (i = 0; i < 2 * nb_blink; i++) {
424 led_set_state(led, LEDST_TOGGLE);
425 mdelay(125);
426 WATCHDOG_RESET();
427 }
428 }
429#endif
430
431 /* infinite: the boot process must be stopped */
432 if (nb_blink == U32_MAX)
433 hang();
434}
435
436static void sysconf_init(void)
437{
Patrick Delaunayf8fe21d2020-04-01 09:07:33 +0200438#ifndef CONFIG_TFABOOT
Marek Vasut5ff05292020-01-24 18:39:16 +0100439 u8 *syscfg;
440#ifdef CONFIG_DM_REGULATOR
441 struct udevice *pwr_dev;
442 struct udevice *pwr_reg;
443 struct udevice *dev;
444 int ret;
445 u32 otp = 0;
446#endif
447 u32 bootr;
448
449 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
450
451 /* interconnect update : select master using the port 1 */
452 /* LTDC = AXI_M9 */
453 /* GPU = AXI_M8 */
454 /* today information is hardcoded in U-Boot */
455 writel(BIT(9), syscfg + SYSCFG_ICNR);
456
457 /* disable Pull-Down for boot pin connected to VDD */
458 bootr = readl(syscfg + SYSCFG_BOOTR);
459 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
460 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
461 writel(bootr, syscfg + SYSCFG_BOOTR);
462
463#ifdef CONFIG_DM_REGULATOR
464 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
465 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
466 * The customer will have to disable this for low frequencies
467 * or if AFMUX is selected but the function not used, typically for
468 * TRACE. Otherwise, impact on power consumption.
469 *
470 * WARNING:
471 * enabling High Speed mode while VDD>2.7V
472 * with the OTP product_below_2v5 (OTP 18, BIT 13)
473 * erroneously set to 1 can damage the IC!
474 * => U-Boot set the register only if VDD < 2.7V (in DT)
475 * but this value need to be consistent with board design
476 */
477 ret = uclass_get_device_by_driver(UCLASS_PMIC,
478 DM_GET_DRIVER(stm32mp_pwr_pmic),
479 &pwr_dev);
480 if (!ret) {
481 ret = uclass_get_device_by_driver(UCLASS_MISC,
482 DM_GET_DRIVER(stm32mp_bsec),
483 &dev);
484 if (ret) {
485 pr_err("Can't find stm32mp_bsec driver\n");
486 return;
487 }
488
489 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
490 if (ret > 0)
491 otp = otp & BIT(13);
492
493 /* get VDD = vdd-supply */
494 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
495 &pwr_reg);
496
497 /* check if VDD is Low Voltage */
498 if (!ret) {
499 if (regulator_get_value(pwr_reg) < 2700000) {
500 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
501 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
502 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
503 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
504 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
505 syscfg + SYSCFG_IOCTRLSETR);
506
507 if (!otp)
508 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
509 } else {
510 if (otp)
511 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
512 }
513 } else {
514 debug("VDD unknown");
515 }
516 }
517#endif
518
519 /* activate automatic I/O compensation
520 * warning: need to ensure CSI enabled and ready in clock driver
521 */
522 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
523
524 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
525 ;
526 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
527#endif
528}
529
Marek Vasut0839ea92020-03-28 02:01:58 +0100530static void board_init_fmc2(void)
531{
532#define STM32_FMC2_BCR1 0x0
533#define STM32_FMC2_BTR1 0x4
534#define STM32_FMC2_BWTR1 0x104
535#define STM32_FMC2_BCR(x) ((x) * 0x8 + STM32_FMC2_BCR1)
536#define STM32_FMC2_BCRx_FMCEN BIT(31)
537#define STM32_FMC2_BCRx_WREN BIT(12)
538#define STM32_FMC2_BCRx_RSVD BIT(7)
539#define STM32_FMC2_BCRx_FACCEN BIT(6)
540#define STM32_FMC2_BCRx_MWID(n) ((n) << 4)
541#define STM32_FMC2_BCRx_MTYP(n) ((n) << 2)
542#define STM32_FMC2_BCRx_MUXEN BIT(1)
543#define STM32_FMC2_BCRx_MBKEN BIT(0)
544#define STM32_FMC2_BTR(x) ((x) * 0x8 + STM32_FMC2_BTR1)
545#define STM32_FMC2_BTRx_DATAHLD(n) ((n) << 30)
546#define STM32_FMC2_BTRx_BUSTURN(n) ((n) << 16)
547#define STM32_FMC2_BTRx_DATAST(n) ((n) << 8)
548#define STM32_FMC2_BTRx_ADDHLD(n) ((n) << 4)
549#define STM32_FMC2_BTRx_ADDSET(n) ((n) << 0)
550
551#define RCC_MP_AHB6RSTCLRR 0x218
552#define RCC_MP_AHB6RSTCLRR_FMCRST BIT(12)
553#define RCC_MP_AHB6ENSETR 0x19c
554#define RCC_MP_AHB6ENSETR_FMCEN BIT(12)
555
556 const u32 bcr = STM32_FMC2_BCRx_WREN |STM32_FMC2_BCRx_RSVD |
557 STM32_FMC2_BCRx_FACCEN | STM32_FMC2_BCRx_MWID(1) |
558 STM32_FMC2_BCRx_MTYP(2) | STM32_FMC2_BCRx_MUXEN |
559 STM32_FMC2_BCRx_MBKEN;
560 const u32 btr = STM32_FMC2_BTRx_DATAHLD(3) |
561 STM32_FMC2_BTRx_BUSTURN(2) |
562 STM32_FMC2_BTRx_DATAST(0x22) |
563 STM32_FMC2_BTRx_ADDHLD(2) |
564 STM32_FMC2_BTRx_ADDSET(2);
565
566 /* Set up FMC2 bus for KS8851-16MLL and X11 SRAM */
567 writel(RCC_MP_AHB6RSTCLRR_FMCRST, STM32_RCC_BASE + RCC_MP_AHB6RSTCLRR);
568 writel(RCC_MP_AHB6ENSETR_FMCEN, STM32_RCC_BASE + RCC_MP_AHB6ENSETR);
569
570 /* KS8851-16MLL -- Muxed mode */
571 writel(bcr, STM32_FMC2_BASE + STM32_FMC2_BCR(1));
572 writel(btr, STM32_FMC2_BASE + STM32_FMC2_BTR(1));
573 /* AS7C34098 SRAM on X11 -- Muxed mode */
574 writel(bcr, STM32_FMC2_BASE + STM32_FMC2_BCR(3));
575 writel(btr, STM32_FMC2_BASE + STM32_FMC2_BTR(3));
576
577 setbits_le32(STM32_FMC2_BASE + STM32_FMC2_BCR1, STM32_FMC2_BCRx_FMCEN);
578}
579
Marek Vasut5ff05292020-01-24 18:39:16 +0100580/* board dependent setup after realloc */
581int board_init(void)
582{
Marek Vasut5ff05292020-01-24 18:39:16 +0100583 /* address of boot parameters */
584 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
585
Patrick Delaunay48bd3c92020-07-02 15:20:47 +0200586 if (CONFIG_IS_ENABLED(DM_GPIO_HOG))
587 gpio_hog_probe_all();
Marek Vasut5ff05292020-01-24 18:39:16 +0100588
589 board_key_check();
590
591#ifdef CONFIG_DM_REGULATOR
592 regulators_enable_boot_on(_DEBUG);
593#endif
594
595 sysconf_init();
596
Marek Vasut0839ea92020-03-28 02:01:58 +0100597 board_init_fmc2();
598
Patrick Delaunay78f68f22020-04-10 19:14:01 +0200599 if (CONFIG_IS_ENABLED(LED))
Marek Vasut5ff05292020-01-24 18:39:16 +0100600 led_default_state();
601
602 return 0;
603}
604
605int board_late_init(void)
606{
607 char *boot_device;
608#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
609 const void *fdt_compat;
610 int fdt_compat_len;
611
612 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
613 &fdt_compat_len);
614 if (fdt_compat && fdt_compat_len) {
615 if (strncmp(fdt_compat, "st,", 3) != 0)
616 env_set("board_name", fdt_compat);
617 else
618 env_set("board_name", fdt_compat + 3);
619 }
620#endif
621
622 /* Check the boot-source to disable bootdelay */
623 boot_device = env_get("boot_device");
624 if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
625 env_set("bootdelay", "0");
626
Marek Vasut47b98ba2020-04-22 13:18:11 +0200627#ifdef CONFIG_BOARD_EARLY_INIT_F
628 env_set_ulong("dh_som_rev", somcode);
629 env_set_ulong("dh_board_rev", brdcode);
Marek Vasut39221b52020-04-22 13:18:14 +0200630 env_set_ulong("dh_ddr3_code", ddr3code);
Marek Vasut47b98ba2020-04-22 13:18:11 +0200631#endif
632
Marek Vasut5ff05292020-01-24 18:39:16 +0100633 return 0;
634}
635
636void board_quiesce_devices(void)
637{
638#ifdef CONFIG_LED
639 setup_led(LEDST_OFF);
640#endif
641}
642
643/* eth init function : weak called in eqos driver */
644int board_interface_eth_init(struct udevice *dev,
645 phy_interface_t interface_type)
646{
647 u8 *syscfg;
648 u32 value;
649 bool eth_clk_sel_reg = false;
650 bool eth_ref_clk_sel_reg = false;
651
652 /* Gigabit Ethernet 125MHz clock selection. */
653 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
654
655 /* Ethernet 50Mhz RMII clock selection */
656 eth_ref_clk_sel_reg =
657 dev_read_bool(dev, "st,eth_ref_clk_sel");
658
659 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
660
661 if (!syscfg)
662 return -ENODEV;
663
664 switch (interface_type) {
665 case PHY_INTERFACE_MODE_MII:
666 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
667 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
668 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
669 break;
670 case PHY_INTERFACE_MODE_GMII:
671 if (eth_clk_sel_reg)
672 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
673 SYSCFG_PMCSETR_ETH_CLK_SEL;
674 else
675 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
676 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
677 break;
678 case PHY_INTERFACE_MODE_RMII:
679 if (eth_ref_clk_sel_reg)
680 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
681 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
682 else
683 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
684 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
685 break;
686 case PHY_INTERFACE_MODE_RGMII:
687 case PHY_INTERFACE_MODE_RGMII_ID:
688 case PHY_INTERFACE_MODE_RGMII_RXID:
689 case PHY_INTERFACE_MODE_RGMII_TXID:
690 if (eth_clk_sel_reg)
691 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
692 SYSCFG_PMCSETR_ETH_CLK_SEL;
693 else
694 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
695 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
696 break;
697 default:
698 debug("%s: Do not manage %d interface\n",
699 __func__, interface_type);
700 /* Do not manage others interfaces */
701 return -EINVAL;
702 }
703
704 /* clear and set ETH configuration bits */
705 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
706 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
707 syscfg + SYSCFG_PMCCLRR);
708 writel(value, syscfg + SYSCFG_PMCSETR);
709
710 return 0;
711}
712
Marek Vasut5ff05292020-01-24 18:39:16 +0100713#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900714int ft_board_setup(void *blob, struct bd_info *bd)
Marek Vasut5ff05292020-01-24 18:39:16 +0100715{
716 return 0;
717}
718#endif
719
Marek Vasut5ff05292020-01-24 18:39:16 +0100720static void board_copro_image_process(ulong fw_image, size_t fw_size)
721{
722 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
723
724 if (!rproc_is_initialized())
725 if (rproc_init()) {
726 printf("Remote Processor %d initialization failed\n",
727 id);
728 return;
729 }
730
731 ret = rproc_load(id, fw_image, fw_size);
732 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
733 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
734
735 if (!ret) {
736 rproc_start(id);
737 env_set("copro_state", "booted");
738 }
739}
740
741U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);