2018-12-14 15:16:49 +00:00
|
|
|
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Microsemi Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <image.h>
|
2019-11-14 19:57:46 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-12-14 15:16:49 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/addrspace.h>
|
|
|
|
#include <asm/types.h>
|
|
|
|
#include <spi.h>
|
2019-01-02 08:52:26 +00:00
|
|
|
#include <led.h>
|
2019-01-17 16:07:14 +00:00
|
|
|
#include <wait_bit.h>
|
2019-04-24 09:27:58 +00:00
|
|
|
#include <miiphy.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2018-12-14 15:16:49 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2018-12-20 08:56:05 +00:00
|
|
|
enum {
|
|
|
|
BOARD_TYPE_PCB120 = 0xAABBCC00,
|
|
|
|
BOARD_TYPE_PCB123,
|
|
|
|
};
|
2018-12-14 15:16:49 +00:00
|
|
|
|
2019-01-17 16:07:14 +00:00
|
|
|
void mscc_switch_reset(bool enter)
|
|
|
|
{
|
|
|
|
/* Nasty workaround to avoid GPIO19 (DDR!) being reset */
|
|
|
|
mscc_gpio_set_alternate(19, 2);
|
|
|
|
|
|
|
|
debug("applying SwC reset\n");
|
|
|
|
|
|
|
|
writel(ICPU_RESET_CORE_RST_PROTECT, BASE_CFG + ICPU_RESET);
|
|
|
|
writel(PERF_SOFT_RST_SOFT_CHIP_RST, BASE_DEVCPU_GCB + PERF_SOFT_RST);
|
|
|
|
|
|
|
|
if (wait_for_bit_le32(BASE_DEVCPU_GCB + PERF_SOFT_RST,
|
|
|
|
PERF_SOFT_RST_SOFT_CHIP_RST, false, 5000, false))
|
|
|
|
pr_err("Tiemout while waiting for switch reset\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset GPIO19 mode back as regular GPIO, output, high (DDR
|
|
|
|
* not reset) (Order is important)
|
|
|
|
*/
|
|
|
|
setbits_le32(BASE_DEVCPU_GCB + PERF_GPIO_OE, BIT(19));
|
|
|
|
writel(BIT(19), BASE_DEVCPU_GCB + PERF_GPIO_OUT_SET);
|
|
|
|
mscc_gpio_set_alternate(19, 0);
|
|
|
|
}
|
|
|
|
|
2019-04-24 09:27:58 +00:00
|
|
|
int board_phy_config(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
if (gd->board_type == BOARD_TYPE_PCB123)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
phy_write(phydev, 0, 31, 0x10);
|
|
|
|
phy_write(phydev, 0, 18, 0x80F0);
|
|
|
|
while (phy_read(phydev, 0, 18) & 0x8000)
|
|
|
|
;
|
|
|
|
phy_write(phydev, 0, 31, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-14 15:16:49 +00:00
|
|
|
void board_debug_uart_init(void)
|
|
|
|
{
|
|
|
|
/* too early for the pinctrl driver, so configure the UART pins here */
|
2018-12-20 08:56:05 +00:00
|
|
|
mscc_gpio_set_alternate(6, 1);
|
|
|
|
mscc_gpio_set_alternate(7, 1);
|
2018-12-14 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int board_early_init_r(void)
|
|
|
|
{
|
|
|
|
/* Prepare SPI controller to be used in master mode */
|
|
|
|
writel(0, BASE_CFG + ICPU_SW_MODE);
|
|
|
|
clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
|
|
|
|
ICPU_GENERAL_CTRL_IF_SI_OWNER_M,
|
|
|
|
ICPU_GENERAL_CTRL_IF_SI_OWNER(2));
|
|
|
|
|
|
|
|
/* Address of boot parameters */
|
|
|
|
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE;
|
2019-01-02 08:52:26 +00:00
|
|
|
|
2018-12-14 15:16:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-12-20 08:56:05 +00:00
|
|
|
|
|
|
|
static void do_board_detect(void)
|
|
|
|
{
|
|
|
|
u16 dummy = 0;
|
|
|
|
|
|
|
|
/* Enable MIIM */
|
|
|
|
mscc_gpio_set_alternate(14, 1);
|
|
|
|
mscc_gpio_set_alternate(15, 1);
|
|
|
|
if (mscc_phy_rd(1, 0, 0, &dummy) == 0)
|
|
|
|
gd->board_type = BOARD_TYPE_PCB120;
|
|
|
|
else
|
|
|
|
gd->board_type = BOARD_TYPE_PCB123;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_MULTI_DTB_FIT)
|
|
|
|
int board_fit_config_name_match(const char *name)
|
|
|
|
{
|
|
|
|
if (gd->board_type == BOARD_TYPE_PCB120 &&
|
|
|
|
strcmp(name, "ocelot_pcb120") == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (gd->board_type == BOARD_TYPE_PCB123 &&
|
|
|
|
strcmp(name, "ocelot_pcb123") == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_DTB_RESELECT)
|
|
|
|
int embedded_dtb_select(void)
|
|
|
|
{
|
|
|
|
do_board_detect();
|
|
|
|
fdtdec_setup();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|