2021-05-27 13:52:13 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021 SiFive, Inc
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Pragnesh Patel <pragnesh.patel@sifive.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <init.h>
|
|
|
|
#include <spl.h>
|
|
|
|
#include <misc.h>
|
|
|
|
#include <log.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <asm/arch/gpio.h>
|
|
|
|
#include <asm/arch/spl.h>
|
|
|
|
|
|
|
|
#define GEM_PHY_RESET SIFIVE_GENERIC_GPIO_NR(0, 12)
|
|
|
|
|
|
|
|
#define MODE_SELECT_REG 0x1000
|
|
|
|
#define MODE_SELECT_SD 0xb
|
|
|
|
#define MODE_SELECT_MASK GENMASK(3, 0)
|
|
|
|
|
2021-07-08 01:08:20 +00:00
|
|
|
static inline int spl_reset_device_by_gpio(const char *label, int pin, int low_width)
|
2021-05-27 13:52:13 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2021-07-08 01:08:20 +00:00
|
|
|
ret = gpio_request(pin, label);
|
2021-05-27 13:52:13 +00:00
|
|
|
if (ret) {
|
2021-07-08 01:08:20 +00:00
|
|
|
debug("%s gpio request failed: %d\n", label, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gpio_direction_output(pin, 1);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s gpio direction set failed: %d\n", label, ret);
|
2021-05-27 13:52:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-08 01:08:20 +00:00
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
gpio_set_value(pin, 0);
|
|
|
|
udelay(low_width);
|
|
|
|
gpio_set_value(pin, 1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int spl_gemgxl_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
2021-05-27 13:52:13 +00:00
|
|
|
/*
|
|
|
|
* GEMGXL init VSC8541 PHY reset sequence;
|
|
|
|
* leave pull-down active for 2ms
|
|
|
|
*/
|
|
|
|
udelay(2000);
|
2021-07-08 01:08:20 +00:00
|
|
|
ret = spl_reset_device_by_gpio("gem_phy_reset", GEM_PHY_RESET, 1);
|
|
|
|
mdelay(15);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int spl_board_init_f(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = spl_soc_init();
|
2021-05-27 13:52:13 +00:00
|
|
|
if (ret) {
|
2021-07-08 01:08:20 +00:00
|
|
|
debug("HiFive Unmatched FU740 SPL init failed: %d\n", ret);
|
|
|
|
goto end;
|
2021-05-27 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 01:08:20 +00:00
|
|
|
ret = spl_gemgxl_init();
|
2021-05-27 13:52:13 +00:00
|
|
|
if (ret) {
|
2021-07-08 01:08:20 +00:00
|
|
|
debug("Gigabit ethernet PHY (VSC8541) init failed: %d\n", ret);
|
|
|
|
goto end;
|
2021-05-27 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 01:08:20 +00:00
|
|
|
end:
|
|
|
|
return ret;
|
2021-05-27 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 spl_boot_device(void)
|
|
|
|
{
|
|
|
|
u32 mode_select = readl((void *)MODE_SELECT_REG);
|
|
|
|
u32 boot_device = mode_select & MODE_SELECT_MASK;
|
|
|
|
|
|
|
|
switch (boot_device) {
|
|
|
|
case MODE_SELECT_SD:
|
|
|
|
return BOOT_DEVICE_MMC1;
|
|
|
|
default:
|
|
|
|
debug("Unsupported boot device 0x%x but trying MMC1\n",
|
|
|
|
boot_device);
|
|
|
|
return BOOT_DEVICE_MMC1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPL_LOAD_FIT
|
|
|
|
int board_fit_config_name_match(const char *name)
|
|
|
|
{
|
2021-07-20 06:26:08 +00:00
|
|
|
/* boot using first FIT config */
|
|
|
|
return 0;
|
2021-05-27 13:52:13 +00:00
|
|
|
}
|
|
|
|
#endif
|