Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CI: https://source.denx.de/u-boot/custodians/u-boot-riscv/-/pipelines/20596

- RISC-V: cmd: Add SBI implementation ID and extension ID
- Board: Rename spl_soc_init to spl_dram_init
- Board: milkv_duo: Add SPI NOR flash, Ethernet, Sysreset support
  • Loading branch information
trini committed May 2, 2024
2 parents 3132b79 + 19b762c commit 62825d4
Show file tree
Hide file tree
Showing 27 changed files with 591 additions and 14 deletions.
1 change: 1 addition & 0 deletions arch/riscv/cpu/andesv5/Kconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
config RISCV_NDS
bool
select ARCH_EARLY_INIT_R
select SYS_CACHE_SHIFT_6
imply CPU
imply CPU_RISCV
imply RISCV_TIMER if (RISCV_SMODE || SPL_RISCV_SMODE)
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/cpu/fu540/spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <dm.h>
#include <log.h>

int spl_soc_init(void)
int spl_dram_init(void)
{
int ret;
struct udevice *dev;
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/cpu/fu740/spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define CSR_U74_FEATURE_DISABLE 0x7c1

int spl_soc_init(void)
int spl_dram_init(void)
{
int ret;
struct udevice *dev;
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/cpu/jh7110/spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static bool check_ddr_size(phys_size_t size)
}
}

int spl_soc_init(void)
int spl_dram_init(void)
{
int ret;
struct udevice *dev;
Expand Down
18 changes: 18 additions & 0 deletions arch/riscv/dts/cv1800b-milkv-duo.dts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
};
};

&ethernet0 {
status = "okay";
phy-mode = "rmii";
};

&osc {
clock-frequency = <25000000>;
};
Expand All @@ -41,6 +46,19 @@
no-sdio;
};

&spif {
status = "okay";

spiflash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <75000000>;
spi-tx-bus-width = <4>;
spi-rx-bus-width = <4>;
m25p,fast-read;
};
};

&uart0 {
status = "okay";
};
40 changes: 40 additions & 0 deletions arch/riscv/dts/cv18xx.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@
#clock-cells = <0>;
};

eth_csrclk: eth-csrclk {
compatible = "fixed-clock";
clock-frequency = <250000000>;
clock-output-names = "eth_csrclk";
#clock-cells = <0x0>;
};

eth_ptpclk: eth-ptpclk {
compatible = "fixed-clock";
clock-frequency = <50000000>;
clock-output-names = "eth_ptpclk";
#clock-cells = <0x0>;
};

spif_clk: spi-flash-clock {
compatible = "fixed-clock";
clock-frequency = <300000000>;
clock-output-names = "spif_clk";
#clock-cells = <0>;
};

soc {
compatible = "simple-bus";
interrupt-parent = <&plic>;
Expand Down Expand Up @@ -138,6 +159,15 @@
};
};

ethernet0: ethernet@4070000 {
compatible = "sophgo,cv1800b-dwmac";
reg = <0x04070000 0x10000>;
interrupts = <31 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&eth_csrclk>, <&eth_ptpclk>;
clock-names = "stmmaceth", "ptp_ref";
status = "disabled";
};

uart0: serial@4140000 {
compatible = "snps,dw-apb-uart";
reg = <0x04140000 0x100>;
Expand Down Expand Up @@ -197,6 +227,16 @@
status = "disabled";
};

spif: spi-nor@10000000 {
compatible = "sophgo,cv1800b-spif";
reg = <0x10000000 0x10000000>;
#address-cells = <1>;
#size-cells = <0>;
clocks = <&spif_clk>;
interrupts = <95 IRQ_TYPE_LEVEL_HIGH>;
status = "disabled";
};

plic: interrupt-controller@70000000 {
reg = <0x70000000 0x4000000>;
interrupts-extended = <&cpu0_intc 11>, <&cpu0_intc 9>;
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/include/asm/arch-fu540/spl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#ifndef _SPL_SIFIVE_H
#define _SPL_SIFIVE_H

int spl_soc_init(void);
int spl_dram_init(void);

#endif /* _SPL_SIFIVE_H */
2 changes: 1 addition & 1 deletion arch/riscv/include/asm/arch-fu740/spl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#ifndef _SPL_SIFIVE_H
#define _SPL_SIFIVE_H

int spl_soc_init(void);
int spl_dram_init(void);

#endif /* _SPL_SIFIVE_H */
2 changes: 1 addition & 1 deletion arch/riscv/include/asm/arch-jh7110/spl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
#ifndef _SPL_STARFIVE_H
#define _SPL_STARFIVE_H

int spl_soc_init(void);
int spl_dram_init(void);

#endif /* _SPL_STARFIVE_H */
1 change: 1 addition & 0 deletions arch/riscv/include/asm/sbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum sbi_ext_id {
SBI_EXT_NACL = 0x4E41434C,
SBI_EXT_STA = 0x535441,
SBI_EXT_DBTR = 0x44425452,
SBI_EXT_SSE = 0x535345,
};

enum sbi_ext_base_fid {
Expand Down
4 changes: 2 additions & 2 deletions board/sifive/unleashed/spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ int spl_board_init_f(void)
{
int ret;

ret = spl_soc_init();
ret = spl_dram_init();
if (ret) {
debug("FU540 SPL init failed: %d\n", ret);
debug("FU540 DRAM init failed: %d\n", ret);
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions board/sifive/unmatched/spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ int spl_board_init_f(void)
{
int ret;

ret = spl_soc_init();
ret = spl_dram_init();
if (ret) {
debug("HiFive Unmatched FU740 SPL init failed: %d\n", ret);
debug("HiFive Unmatched FU740 DRAM init failed: %d\n", ret);
goto end;
}

Expand Down
3 changes: 2 additions & 1 deletion board/sophgo/milkv_duo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
#
# Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>

obj-y := board.o
obj-y += board.o
obj-$(CONFIG_NET) += ethernet.o
10 changes: 10 additions & 0 deletions board/sophgo/milkv_duo/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
* Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
*/

#include <dm/lists.h>

#include "ethernet.h"

int board_init(void)
{
if (IS_ENABLED(CONFIG_SYSRESET_CV1800B))
device_bind_driver(gd->dm_root, "cv1800b_sysreset", "sysreset", NULL);

if (IS_ENABLED(CONFIG_NET))
cv1800b_ephy_init();

return 0;
}
79 changes: 79 additions & 0 deletions board/sophgo/milkv_duo/ethernet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
*/

#include <linux/io.h>
#include <linux/bitops.h>
#include <linux/mii.h>

#define REG_EPHY_TOP_WRAP (u32 *)0x03009800
#define REG_EPHY_BASE (u32 *)0x03009000

#define REG_EPHY_CTL REG_EPHY_TOP_WRAP
#define REG_EPHY_APB_RW_SEL REG_EPHY_TOP_WRAP + 1

/* Page 0 register */
#define REG_PHY_ID1 REG_EPHY_BASE + MII_PHYSID1
#define REG_PHY_ID2 REG_EPHY_BASE + MII_PHYSID2
#define REG_PHY_PAGE_SEL REG_EPHY_BASE + 0x1f

/* Page 5 register */
#define REG_PD_EN_CTL REG_EPHY_BASE + 0x10

/* REG_EPHY_CTL */
#define REG_EPHY_SHUTDOWN BIT(0)
#define REG_EPHY_ANA_RST_N BIT(1)
#define REG_EPHY_DIG_RST_N BIT(2)
#define REG_EPHY_MAIN_RST_N BIT(3)

/* REG_PD_EN_CTL */
#define REG_EN_ETH_TXRT BIT(0)
#define REG_EN_ETH_CLK100M BIT(1)
#define REG_EN_ETH_CLK125M BIT(2)
#define REG_EN_ETH_PLL_LCKDET BIT(3)
#define REG_EN_ETH_RXADC BIT(4)
#define REG_EN_ETH_RXPGA BIT(5)
#define REG_EN_ETH_RXRT BIT(6)
#define REG_EN_ETH_TXCROSSOVER BIT(7)
#define REG_PD_ETH_PLL BIT(8)
#define REG_PD_ETH_TXDAC BIT(9)
#define REG_PD_ETH_TXDACBST BIT(10)
#define REG_PD_ETH_TXECHO BIT(11)
#define REG_PD_ETH_TXDRV_NMOS BIT(12)
#define REG_PD_ETH_TXLDO BIT(13)

void cv1800b_ephy_init(void)
{
u32 reg;
u32 phy_id = 1;

/* enable direct memory access for phy register */
writel(1, REG_EPHY_APB_RW_SEL);

reg = readl(REG_EPHY_CTL);
reg &= ~REG_EPHY_SHUTDOWN;
reg |= REG_EPHY_ANA_RST_N | REG_EPHY_DIG_RST_N | REG_EPHY_MAIN_RST_N;
writel(reg, REG_EPHY_CTL);

/* switch to page 5 */
writel(5 << 8, REG_PHY_PAGE_SEL);
reg = readl(REG_PD_EN_CTL);
reg &= ~(REG_PD_ETH_TXLDO | REG_PD_ETH_TXDRV_NMOS | REG_PD_ETH_TXDAC | REG_PD_ETH_PLL);
reg |= REG_EN_ETH_TXRT | REG_EN_ETH_CLK100M | REG_EN_ETH_CLK125M
| REG_EN_ETH_PLL_LCKDET | REG_EN_ETH_RXADC | REG_EN_ETH_RXPGA | REG_EN_ETH_RXRT;
writel(reg, REG_PD_EN_CTL);

/* switch to page 0 */
writel(0 << 8, REG_PHY_PAGE_SEL);
/*
* As the phy_id in the cv1800b PHY register is initialized to 0, it
* is necessary to manually initialize the phy_id to an arbitrary
* value so that it could corresponds to the generic PHY driver.
*/
writel(phy_id >> 16, REG_PHY_ID1);
writel(phy_id & 0xffff, REG_PHY_ID2);

/* switch to MDIO control */
writel(0, REG_EPHY_APB_RW_SEL);
}
11 changes: 11 additions & 0 deletions board/sophgo/milkv_duo/ethernet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
*/

#ifndef __CV1800B_ETHERNET_H
#define __CV1800B_ETHERNET_H

void cv1800b_ephy_init(void);

#endif
4 changes: 2 additions & 2 deletions board/starfive/visionfive2/spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ int spl_board_init_f(void)

jh7110_jtag_init();

ret = spl_soc_init();
ret = spl_dram_init();
if (ret) {
debug("JH7110 SPL init failed: %d\n", ret);
debug("JH7110 DRAM init failed: %d\n", ret);
return ret;
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/riscv/sbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ static struct sbi_imp implementations[] = {
{ 6, "Coffer" },
{ 7, "Xen Project" },
{ 8, "PolarFire Hart Software Services" },
{ 9, "coreboot" },
{ 10, "oreboot" },
};

static struct sbi_ext extensions[] = {
Expand All @@ -54,6 +56,7 @@ static struct sbi_ext extensions[] = {
{ SBI_EXT_NACL, "Nested Acceleration Extension" },
{ SBI_EXT_STA, "Steal-time Accounting Extension" },
{ SBI_EXT_DBTR, "Debug Trigger Extension" },
{ SBI_EXT_SSE, "Supervisor Software Events" },
};

static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc,
Expand Down
10 changes: 10 additions & 0 deletions configs/milkv_duo_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@ CONFIG_HUSH_PARSER=y
CONFIG_SYS_PROMPT="milkv_duo# "
CONFIG_CMD_MMC=y
CONFIG_CMD_PART=y
CONFIG_CMD_POWEROFF=y
CONFIG_CMD_DHCP=y
CONFIG_CMD_PXE=y
CONFIG_CMD_FAT=y
CONFIG_CMD_FS_GENERIC=y
CONFIG_ENV_OVERWRITE=y
CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_MMC=y
CONFIG_MMC_IO_VOLTAGE=y
CONFIG_MMC_UHS_SUPPORT=y
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_ADMA=y
CONFIG_MMC_SDHCI_CV1800B=y
CONFIG_ETH_DESIGNWARE=y
CONFIG_SYS_NS16550=y
CONFIG_SYS_NS16550_MEM32=y
CONFIG_SYSRESET=y
CONFIG_SYSRESET_CV1800B=y
CONFIG_SPI_FLASH_MACRONIX=y
CONFIG_SPI=y
CONFIG_CV1800B_SPIF=y
4 changes: 3 additions & 1 deletion drivers/mmc/cv1800b_sdhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
#define MMC_MAX_CLOCK 375000000
#define TUNE_MAX_PHCODE 128

#define PHY_TX_SRC_INVERT BIT(8)

struct cv1800b_sdhci_plat {
struct mmc_config cfg;
struct mmc mmc;
};

static void cv1800b_set_tap_delay(struct sdhci_host *host, u16 tap)
{
sdhci_writel(host, tap << 16, SDHCI_PHY_TX_RX_DLY);
sdhci_writel(host, PHY_TX_SRC_INVERT | tap << 16, SDHCI_PHY_TX_RX_DLY);
}

static void cv1800b_sdhci_reset(struct sdhci_host *host, u8 mask)
Expand Down
1 change: 1 addition & 0 deletions drivers/net/designware.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ static const struct udevice_id designware_eth_ids[] = {
{ .compatible = "amlogic,meson6-dwmac" },
{ .compatible = "st,stm32-dwmac" },
{ .compatible = "snps,arc-dwmac-3.70a" },
{ .compatible = "sophgo,cv1800b-dwmac" },
{ }
};

Expand Down
8 changes: 8 additions & 0 deletions drivers/spi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ config CF_SPI
Enable the ColdFire SPI driver. This driver can be used on
some m68k SoCs.

config CV1800B_SPIF
bool "Sophgo cv1800b SPI Flash Controller driver"
depends on SPI_MEM
help
Enable the Sophgo cv1800b SPI Flash Controller driver. This driver
can be used to access the SPI NOR flash on platforms embedding this
Sophgo cv1800b IP core.

config DAVINCI_SPI
bool "Davinci & Keystone SPI driver"
depends on ARCH_DAVINCI || ARCH_KEYSTONE
Expand Down

0 comments on commit 62825d4

Please sign in to comment.