1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2019 SiFive, Inc
6 * Pragnesh Patel <pragnesh.patel@sifive.com>
13 #include <linux/delay.h>
16 #include <asm/arch/gpio.h>
17 #include <asm/arch/spl.h>
19 #define GEM_PHY_RESET SIFIVE_GENERIC_GPIO_NR(0, 12)
21 #define MODE_SELECT_REG 0x1000
22 #define MODE_SELECT_QSPI 0x6
23 #define MODE_SELECT_SD 0xb
24 #define MODE_SELECT_MASK GENMASK(3, 0)
26 int spl_board_init_f(void)
32 debug("FU540 SPL init failed: %d\n", ret);
37 * GEMGXL init VSC8541 PHY reset sequence;
38 * leave pull-down active for 2ms
41 ret = gpio_request(GEM_PHY_RESET, "gem_phy_reset");
43 debug("gem_phy_reset gpio request failed: %d\n", ret);
47 /* Set GPIO 12 (PHY NRESET) */
48 ret = gpio_direction_output(GEM_PHY_RESET, 1);
50 debug("gem_phy_reset gpio direction set failed: %d\n", ret);
56 /* Reset PHY again to enter unmanaged mode */
57 gpio_set_value(GEM_PHY_RESET, 0);
59 gpio_set_value(GEM_PHY_RESET, 1);
65 u32 spl_boot_device(void)
67 u32 mode_select = readl((void *)MODE_SELECT_REG);
68 u32 boot_device = mode_select & MODE_SELECT_MASK;
70 switch (boot_device) {
71 case MODE_SELECT_QSPI:
72 return BOOT_DEVICE_SPI;
74 return BOOT_DEVICE_MMC1;
76 debug("Unsupported boot device 0x%x but trying MMC1\n",
78 return BOOT_DEVICE_MMC1;
82 #ifdef CONFIG_SPL_LOAD_FIT
83 int board_fit_config_name_match(const char *name)
85 /* boot using first FIT config */