summaryrefslogtreecommitdiff
path: root/board/st/stm32mp1/stm32mp1.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/st/stm32mp1/stm32mp1.c')
-rw-r--r--board/st/stm32mp1/stm32mp1.c357
1 files changed, 78 insertions, 279 deletions
diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index 45068b1cd9..33cb7f6c4d 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -7,7 +7,6 @@
#include <bootm.h>
#include <clk.h>
#include <config.h>
-#include <dfu.h>
#include <dm.h>
#include <env.h>
#include <env_internal.h>
@@ -18,9 +17,7 @@
#include <init.h>
#include <led.h>
#include <malloc.h>
-#include <memalign.h>
#include <misc.h>
-#include <mtd.h>
#include <mtd_node.h>
#include <netdev.h>
#include <phy.h>
@@ -35,6 +32,7 @@
#include <asm/arch/sys_proto.h>
#include <jffs2/load_kernel.h>
#include <linux/err.h>
+#include <linux/iopoll.h>
#include <power/regulator.h>
#include <usb/dwc2_udc.h>
@@ -90,9 +88,7 @@ int checkboard(void)
const char *fdt_compat;
int fdt_compat_len;
- if (IS_ENABLED(CONFIG_STM32MP1_OPTEE))
- mode = "trusted with OP-TEE";
- else if (IS_ENABLED(TFABOOT))
+ if (IS_ENABLED(CONFIG_TFABOOT))
mode = "trusted";
else
mode = "basic";
@@ -260,7 +256,6 @@ int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
#endif /* CONFIG_USB_GADGET */
-#ifdef CONFIG_LED
static int get_led(struct udevice **dev, char *led_string)
{
char *led_name;
@@ -286,6 +281,9 @@ static int setup_led(enum led_state_t cmd)
struct udevice *dev;
int ret;
+ if (!CONFIG_IS_ENABLED(LED))
+ return 0;
+
ret = get_led(&dev, "u-boot,boot-led");
if (ret)
return ret;
@@ -293,31 +291,29 @@ static int setup_led(enum led_state_t cmd)
ret = led_set_state(dev, cmd);
return ret;
}
-#endif
static void __maybe_unused led_error_blink(u32 nb_blink)
{
-#ifdef CONFIG_LED
int ret;
struct udevice *led;
u32 i;
-#endif
if (!nb_blink)
return;
-#ifdef CONFIG_LED
- ret = get_led(&led, "u-boot,error-led");
- if (!ret) {
- /* make u-boot,error-led blinking */
- /* if U32_MAX and 125ms interval, for 17.02 years */
- for (i = 0; i < 2 * nb_blink; i++) {
- led_set_state(led, LEDST_TOGGLE);
- mdelay(125);
- WATCHDOG_RESET();
+ if (CONFIG_IS_ENABLED(LED)) {
+ ret = get_led(&led, "u-boot,error-led");
+ if (!ret) {
+ /* make u-boot,error-led blinking */
+ /* if U32_MAX and 125ms interval, for 17.02 years */
+ for (i = 0; i < 2 * nb_blink; i++) {
+ led_set_state(led, LEDST_TOGGLE);
+ mdelay(125);
+ WATCHDOG_RESET();
+ }
+ led_set_state(led, LEDST_ON);
}
}
-#endif
/* infinite: the boot process must be stopped */
if (nb_blink == U32_MAX)
@@ -435,7 +431,7 @@ static int board_check_usb_power(void)
if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
max_uV <= USB_START_LOW_THRESHOLD_UV &&
min_uV <= USB_LOW_THRESHOLD_UV) {
- pr_err("* WARNING 1.5mA power supply detected *\n");
+ pr_err("* WARNING 1.5A power supply detected *\n");
nb_blink = 3;
}
@@ -468,10 +464,10 @@ static void sysconf_init(void)
struct udevice *pwr_dev;
struct udevice *pwr_reg;
struct udevice *dev;
- int ret;
u32 otp = 0;
#endif
- u32 bootr;
+ int ret;
+ u32 bootr, val;
syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
@@ -548,8 +544,15 @@ static void sysconf_init(void)
*/
writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
- while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
- ;
+ /* poll until ready (1s timeout) */
+ ret = readl_poll_timeout(syscfg + SYSCFG_CMPCR, val,
+ val & SYSCFG_CMPCR_READY,
+ 1000000);
+ if (ret) {
+ pr_err("SYSCFG: I/O compensation failed, timeout.\n");
+ led_error_blink(10);
+ }
+
clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
#endif
}
@@ -621,6 +624,38 @@ static bool board_is_dk2(void)
}
#endif
+static bool board_is_ev1(void)
+{
+ if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
+ (of_machine_is_compatible("st,stm32mp157a-ev1") ||
+ of_machine_is_compatible("st,stm32mp157c-ev1") ||
+ of_machine_is_compatible("st,stm32mp157d-ev1") ||
+ of_machine_is_compatible("st,stm32mp157f-ev1")))
+ return true;
+
+ return false;
+}
+
+/* touchscreen driver: only used for pincontrol configuration */
+static const struct udevice_id goodix_ids[] = {
+ { .compatible = "goodix,gt9147", },
+ { }
+};
+
+U_BOOT_DRIVER(goodix) = {
+ .name = "goodix",
+ .id = UCLASS_NOP,
+ .of_match = goodix_ids,
+};
+
+static void board_ev1_init(void)
+{
+ struct udevice *dev;
+
+ /* configure IRQ line on EV1 for touchscreen before LCD reset */
+ uclass_get_device_by_driver(UCLASS_NOP, DM_GET_DRIVER(goodix), &dev);
+}
+
/* board dependent setup after realloc */
int board_init(void)
{
@@ -638,6 +673,9 @@ int board_init(void)
board_key_check();
+ if (board_is_ev1())
+ board_ev1_init();
+
#ifdef CONFIG_DM_REGULATOR
if (board_is_dk2())
dk2_i2c1_fix();
@@ -650,12 +688,13 @@ int board_init(void)
if (CONFIG_IS_ENABLED(LED))
led_default_state();
+ setup_led(LEDST_ON);
+
return 0;
}
int board_late_init(void)
{
- char *boot_device;
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
const void *fdt_compat;
int fdt_compat_len;
@@ -667,10 +706,19 @@ int board_late_init(void)
fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
&fdt_compat_len);
if (fdt_compat && fdt_compat_len) {
- if (strncmp(fdt_compat, "st,", 3) != 0)
+ if (strncmp(fdt_compat, "st,", 3) != 0) {
env_set("board_name", fdt_compat);
- else
+ } else {
+ char dtb_name[256];
+ int buf_len = sizeof(dtb_name);
+
env_set("board_name", fdt_compat + 3);
+
+ strncpy(dtb_name, fdt_compat + 3, buf_len);
+ buf_len -= strlen(fdt_compat + 3);
+ strncat(dtb_name, ".dtb", buf_len);
+ env_set("fdtfile", dtb_name);
+ }
}
ret = uclass_get_device_by_driver(UCLASS_MISC,
DM_GET_DRIVER(stm32mp_bsec),
@@ -694,19 +742,12 @@ int board_late_init(void)
board_check_usb_power();
#endif /* CONFIG_ADC */
- /* Check the boot-source to disable bootdelay */
- boot_device = env_get("boot_device");
- if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
- env_set("bootdelay", "0");
-
return 0;
}
void board_quiesce_devices(void)
{
-#ifdef CONFIG_LED
setup_led(LEDST_OFF);
-#endif
}
/* eth init function : weak called in eqos driver */
@@ -794,6 +835,7 @@ enum env_location env_get_location(enum env_operation op, int prio)
#endif
#ifdef CONFIG_ENV_IS_IN_UBI
case BOOT_FLASH_NAND:
+ case BOOT_FLASH_SPINAND:
return ENVL_UBI;
#endif
#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
@@ -828,114 +870,13 @@ const char *env_ext4_get_dev_part(void)
}
#endif
-#ifdef CONFIG_SYS_MTDPARTS_RUNTIME
-
-#define MTDPARTS_LEN 256
-#define MTDIDS_LEN 128
-
-/**
- * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
- * If we need to access it before the env is relocated, then we need
- * to use our own stack buffer. gd->env_buf will be too small.
- *
- * @param buf temporary buffer pointer MTDPARTS_LEN long
- * @return mtdparts variable string, NULL if not found
- */
-static const char *env_get_mtdparts(const char *str, char *buf)
-{
- if (gd->flags & GD_FLG_ENV_READY)
- return env_get(str);
- if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
- return buf;
-
- return NULL;
-}
-
-/**
- * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
- */
-static void board_get_mtdparts(const char *dev,
- char *mtdids,
- char *mtdparts)
-{
- char env_name[32] = "mtdparts_";
- char tmp_mtdparts[MTDPARTS_LEN];
- const char *tmp;
-
- /* name of env variable to read = mtdparts_<dev> */
- strcat(env_name, dev);
- tmp = env_get_mtdparts(env_name, tmp_mtdparts);
- if (tmp) {
- /* mtdids: "<dev>=<dev>, ...." */
- if (mtdids[0] != '\0')
- strcat(mtdids, ",");
- strcat(mtdids, dev);
- strcat(mtdids, "=");
- strcat(mtdids, dev);
-
- /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
- if (mtdparts[0] != '\0')
- strncat(mtdparts, ";", MTDPARTS_LEN);
- else
- strcat(mtdparts, "mtdparts=");
- strncat(mtdparts, dev, MTDPARTS_LEN);
- strncat(mtdparts, ":", MTDPARTS_LEN);
- strncat(mtdparts, tmp, MTDPARTS_LEN);
- }
-}
-
-void board_mtdparts_default(const char **mtdids, const char **mtdparts)
-{
- struct mtd_info *mtd;
- struct udevice *dev;
- static char parts[3 * MTDPARTS_LEN + 1];
- static char ids[MTDIDS_LEN + 1];
- static bool mtd_initialized;
-
- if (mtd_initialized) {
- *mtdids = ids;
- *mtdparts = parts;
- return;
- }
-
- memset(parts, 0, sizeof(parts));
- memset(ids, 0, sizeof(ids));
-
- /* probe all MTD devices */
- for (uclass_first_device(UCLASS_MTD, &dev);
- dev;
- uclass_next_device(&dev)) {
- pr_debug("mtd device = %s\n", dev->name);
- }
-
- mtd = get_mtd_device_nm("nand0");
- if (!IS_ERR_OR_NULL(mtd)) {
- board_get_mtdparts("nand0", ids, parts);
- put_mtd_device(mtd);
- }
-
- mtd = get_mtd_device_nm("spi-nand0");
- if (!IS_ERR_OR_NULL(mtd)) {
- board_get_mtdparts("spi-nand0", ids, parts);
- put_mtd_device(mtd);
- }
-
- if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
- board_get_mtdparts("nor0", ids, parts);
-
- mtd_initialized = true;
- *mtdids = ids;
- *mtdparts = parts;
- debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
-}
-#endif
-
#if defined(CONFIG_OF_BOARD_SETUP)
int ft_board_setup(void *blob, bd_t *bd)
{
#ifdef CONFIG_FDT_FIXUP_PARTITIONS
struct node_info nodes[] = {
{ "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
+ { "st,stm32f469-qspi", MTD_DEV_TYPE_SPINAND},
{ "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
};
fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
@@ -945,148 +886,6 @@ int ft_board_setup(void *blob, bd_t *bd)
}
#endif
-#ifdef CONFIG_SET_DFU_ALT_INFO
-#define DFU_ALT_BUF_LEN SZ_1K
-
-static void board_get_alt_info(const char *dev, char *buff)
-{
- char var_name[32] = "dfu_alt_info_";
- int ret;
-
- ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
-
- /* name of env variable to read = dfu_alt_info_<dev> */
- strcat(var_name, dev);
- ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
- if (ret) {
- if (buff[0] != '\0')
- strcat(buff, "&");
- strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
- }
-}
-
-void set_dfu_alt_info(char *interface, char *devstr)
-{
- struct udevice *dev;
- struct mtd_info *mtd;
-
- ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
-
- if (env_get("dfu_alt_info"))
- return;
-
- memset(buf, 0, sizeof(buf));
-
- /* probe all MTD devices */
- mtd_probe_devices();
-
- board_get_alt_info("ram", buf);
-
- if (!uclass_get_device(UCLASS_MMC, 0, &dev))
- board_get_alt_info("mmc0", buf);
-
- if (!uclass_get_device(UCLASS_MMC, 1, &dev))
- board_get_alt_info("mmc1", buf);
-
- if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
- board_get_alt_info("nor0", buf);
-
- mtd = get_mtd_device_nm("nand0");
- if (!IS_ERR_OR_NULL(mtd))
- board_get_alt_info("nand0", buf);
-
- mtd = get_mtd_device_nm("spi-nand0");
- if (!IS_ERR_OR_NULL(mtd))
- board_get_alt_info("spi-nand0", buf);
-
-#ifdef CONFIG_DFU_VIRT
- strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
-
- if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
- strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
-#endif
-
- env_set("dfu_alt_info", buf);
- puts("DFU alt info setting: done\n");
-}
-
-#if CONFIG_IS_ENABLED(DFU_VIRT)
-#include <dfu.h>
-#include <power/stpmic1.h>
-
-static int dfu_otp_read(u64 offset, u8 *buffer, long *size)
-{
- struct udevice *dev;
- int ret;
-
- ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
- &dev);
- if (ret)
- return ret;
-
- ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
- if (ret >= 0) {
- *size = ret;
- ret = 0;
- }
-
- return 0;
-}
-
-static int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
-{
- int ret;
-#ifdef CONFIG_PMIC_STPMIC1
- struct udevice *dev;
-
- ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
- &dev);
- if (ret)
- return ret;
-
- ret = misc_read(dev, 0xF8 + offset, buffer, *size);
- if (ret >= 0) {
- *size = ret;
- ret = 0;
- }
- if (ret == -EACCES) {
- *size = 0;
- ret = 0;
- }
-#else
- pr_err("PMIC update not supported");
- ret = -EOPNOTSUPP;
-#endif
-
- return ret;
-}
-
-int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
- void *buf, long *len)
-{
- switch (dfu->data.virt.dev_num) {
- case 0x0:
- return dfu_otp_read(offset, buf, len);
- case 0x1:
- return dfu_pmic_read(offset, buf, len);
- }
- *len = 0;
- return 0;
-}
-
-int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
-{
- *size = SZ_1K;
-
- return 0;
-}
-
-#endif
-
-#endif
-
static void board_copro_image_process(ulong fw_image, size_t fw_size)
{
int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */