Skip to contentSkip to conversation

board: riscv: add openpiton-riscv64 SoC support

PATCH RESEND Superseded Tianrui Wei 2 participants 3 messages Jun 29, 2021 1 message not in the archive

Subsystems (2)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH RESEND v7 1/2 board: riscv: add openpiton-riscv64 SoC support

This patch adds openpiton-riscv64 SOC support. In particular, this board supports a standard bootflow through zsbl->u-boot SPL-> opensbi->u-boot proper->Linux. There are separate defconfigs for building u-boot SPL and u-boot proper

- V6
. separate defconfigs for u-boot and SPL
. eliminate debug console output
. style updates
- V7
. update Kconfig for OpenPiton board
. SPL defconfig updates

---
 arch/riscv/Kconfig                          |   4 +
 arch/riscv/dts/Makefile                     |   1 +
 arch/riscv/dts/openpiton-riscv64.dts        | 153 ++++++++
 board/openpiton/riscv64/Kconfig             |  40 +++
 board/openpiton/riscv64/MAINTAINERS         |   8 +
 board/openpiton/riscv64/Makefile            |   5 +
 board/openpiton/riscv64/openpiton-riscv64.c |  33 ++
 configs/openpiton_riscv64_defconfig         |  76 ++++
 configs/openpiton_riscv64_spl_defconfig     |  87 +++++
 doc/board/index.rst                         |   1 +
 doc/board/openpiton/index.rst               |   9 +
 doc/board/openpiton/riscv64.rst             | 376 ++++++++++++++++++++
 include/configs/openpiton-riscv64.h         |  61 ++++
 13 files changed, 854 insertions(+)
 create mode 100644 arch/riscv/dts/openpiton-riscv64.dts
 create mode 100644 board/openpiton/riscv64/Kconfig
 create mode 100644 board/openpiton/riscv64/MAINTAINERS
 create mode 100644 board/openpiton/riscv64/Makefile
 create mode 100644 board/openpiton/riscv64/openpiton-riscv64.c
 create mode 100644 configs/openpiton_riscv64_defconfig
 create mode 100644 configs/openpiton_riscv64_spl_defconfig
 create mode 100644 doc/board/openpiton/index.rst
 create mode 100644 doc/board/openpiton/riscv64.rst
 create mode 100644 include/configs/openpiton-riscv64.h
arch/riscv/Kconfig +4 -0
index b3d7fd84ce..4b0c3dffa6 100644
@@ -26,6 +26,9 @@ config TARGET_SIFIVE_UNMATCHED
 config TARGET_SIPEED_MAIX
 	bool "Support Sipeed Maix Board"
 
+config TARGET_OPENPITON_RISCV64
+	bool "Support RISC-V cores on OpenPiton SoC"
+
 endchoice
 
 config SYS_ICACHE_OFF
@@ -60,6 +63,7 @@ source "board/emulation/qemu-riscv/Kconfig"
 source "board/microchip/mpfs_icicle/Kconfig"
 source "board/sifive/unleashed/Kconfig"
 source "board/sifive/unmatched/Kconfig"
+source "board/openpiton/riscv64/Kconfig"
 source "board/sipeed/maix/Kconfig"
 
 # platform-specific options below
arch/riscv/dts/Makefile +1 -0
index 7778874831..b6e9166767 100644
@@ -3,6 +3,7 @@
 dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
 dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-mpfs-icicle-kit.dtb
 dtb-$(CONFIG_TARGET_QEMU_VIRT) += qemu-virt.dtb
+dtb-$(CONFIG_TARGET_OPENPITON_RISCV64) += openpiton-riscv64.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNLEASHED) += hifive-unleashed-a00.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNMATCHED) += hifive-unmatched-a00.dtb
 dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
arch/riscv/dts/openpiton-riscv64.dts new file +153 -0

153 lines not on this page · raw message

board/openpiton/riscv64/Kconfig new file +40 -0
new file mode 100644
index 0000000000..193c890046
@@ -0,0 +1,40 @@
+if TARGET_OPENPITON_RISCV64
+
+config SYS_BOARD
+	default "riscv64"
+
+config SYS_VENDOR
+	default "openpiton"
+
+config SYS_CPU
+	default "generic"
+
+config SYS_CONFIG_NAME
+	default "openpiton-riscv64"
+
+config SYS_TEXT_BASE
+	default 0x81000000 if SPL
+	default 0x80000000 if !RISCV_SMODE
+	default 0x81000000 if RISCV_SMODE
+
+config SPL_TEXT_BASE
+	default 0x82000000
+
+config SPL_OPENSBI_LOAD_ADDR
+	default 0x80000000
+
+config BOARD_SPECIFIC_OPTIONS # dummy
+	def_bool y
+	select ARCH_EARLY_INIT_R
+	select SUPPORT_SPL
+	imply CPU_RISCV
+	imply RISCV_TIMER
+	imply SPL_SIFIVE_CLINT
+	imply CMD_CPU
+	imply SPL_CPU_SUPPORT
+	imply SPL_SMP
+	imply SPL_MMC
+	imply SMP
+	imply SPL_RISCV_MMODE
+
+endif
board/openpiton/riscv64/MAINTAINERS new file +8 -0
new file mode 100644
index 0000000000..f91c000c83
@@ -0,0 +1,8 @@
+Openpiton BOARD
+M:	Tianrui Wei<[email protected]>
+S:	Maintained
+F:	board/openpiton/riscv64/
+F:	include/configs/openpiton-riscv64.h
+F:	configs/openpiton_riscv64_defconfig
+F:	configs/openpiton_riscv64_spl_defconfig
+F:  drivers/mmc/piton_mmc.c
board/openpiton/riscv64/Makefile new file +5 -0
new file mode 100644
index 0000000000..3bffa75a9a
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2021 Tianrui Wei
+# Tianrui Wei <[email protected]>
+obj-y += openpiton-riscv64.o
board/openpiton/riscv64/openpiton-riscv64.c new file +33 -0
new file mode 100644
index 0000000000..f2282d1548
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 SiFive, Inc
+ * Copyright (c) 2021 Tianrui Wei
+ *
+ *
+ * Authors:
+ *   Pragnesh Patel <[email protected]>
+ *   Tianrui Wei <[email protected]>
+ */
+#include <common.h>
+#include <init.h>
+#include <configs/openpiton-riscv64.h>
+#include <dm.h>
+#include <spl.h>
+
+#ifdef CONFIG_SPL
+void board_boot_order(u32 *spl_boot_list)
+{
+	u8 i;
+	u32 boot_devices[] = {
+		BOOT_DEVICE_MMC1,
+	};
+
+	for (i = 0; i < ARRAY_SIZE(boot_devices); i++)
+		spl_boot_list[i] = boot_devices[i];
+}
+#endif
+
+int board_init(void)
+{
+		return 0;
+}
configs/openpiton_riscv64_defconfig new file +76 -0

76 lines not on this page · raw message

configs/openpiton_riscv64_spl_defconfig new file +87 -0

87 lines not on this page · raw message

doc/board/index.rst +1 -0
index a70d2de19d..6b1e246217 100644
@@ -18,6 +18,7 @@ Board-specific doc
    intel/index
    kontron/index
    microchip/index
+   openpiton/index
    rockchip/index
    sifive/index
    sipeed/index
doc/board/openpiton/index.rst new file +9 -0
new file mode 100644
index 0000000000..c469102c4b
@@ -0,0 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+OpenPiton
+=========
+
+.. toctree::
+   :maxdepth: 2
+
+   riscv64
doc/board/openpiton/riscv64.rst new file +376 -0

376 lines not on this page · raw message

include/configs/openpiton-riscv64.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.32.0
#2 lore raw

PATCH RESEND v7 2/2 mmc: openpiton: add piton_mmc driver

In reply to a message not in the archive

This commit adds support to piton_mmc driver for OpenPiton-riscv64 This driver has many things set as preconfigured because the hardware automatically configures most of the settings during startup.

- V6
. change type of address
. move declarations ahead
. loop style update
- V7
. dm updates
. fix indentations
. style fixes to improve readability
. add write support for mmc cards

---
 drivers/mmc/Kconfig     |   9 ++
 drivers/mmc/Makefile    |   1 +
 drivers/mmc/piton_mmc.c | 181 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 191 insertions(+)
 create mode 100644 drivers/mmc/piton_mmc.c
drivers/mmc/Kconfig +9 -0
index 8901456967..4948e194e7 100644
@@ -727,6 +727,15 @@ config MMC_SUNXI_HAS_MODE_SWITCH
 	bool
 	depends on MMC_SUNXI
 
+config MMC_PITON
+	bool "MMC support for OpenPiton SoC"
+	depends on DM_MMC && BLK
+	help
+	  This selects support for the SD host controller on OpenPiton SoC.
+	  Note that this SD controller directly exposes the contents of the
+	  SD card as memory mapped, so there is no manual configuration
+	  required
+
 config GENERIC_ATMEL_MCI
 	bool "Atmel Multimedia Card Interface support"
 	depends on DM_MMC && BLK && ARCH_AT91
drivers/mmc/Makefile +1 -0
index 89d6af3db3..d96ac90719 100644
@@ -72,6 +72,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON)		+= xenon_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_ZYNQ)		+= zynq_sdhci.o
 
 obj-$(CONFIG_MMC_SUNXI)			+= sunxi_mmc.o
+obj-$(CONFIG_MMC_PITON)			+= piton_mmc.o
 obj-$(CONFIG_MMC_UNIPHIER)		+= tmio-common.o uniphier-sd.o
 obj-$(CONFIG_RENESAS_SDHI)		+= tmio-common.o renesas-sdhi.o
 obj-$(CONFIG_MMC_BCM2835)		+= bcm2835_sdhost.o
drivers/mmc/piton_mmc.c new file +181 -0

181 lines not on this page · raw message

Signature · 1 line
2.32.0
#3 lore raw

Re: [RESEND PATCH v7 2/2] mmc: openpiton: add piton_mmc driver

Quoted 89 lines · Tianrui Wei

This commit adds support to piton_mmc driver for OpenPiton-riscv64 This driver has many things set as preconfigured because the hardware automatically configures most of the settings during startup.

- V6
. change type of address
. move declarations ahead
. loop style update
- V7
. dm updates
. fix indentations
. style fixes to improve readability
. add write support for mmc cards

---
 drivers/mmc/Kconfig     |   9 ++
 drivers/mmc/Makefile    |   1 +
 drivers/mmc/piton_mmc.c | 181 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 191 insertions(+)
 create mode 100644 drivers/mmc/piton_mmc.c
drivers/mmc/Kconfig +9 -0
index 8901456967..4948e194e7 100644
@@ -727,6 +727,15 @@ config MMC_SUNXI_HAS_MODE_SWITCH
 	bool
 	depends on MMC_SUNXI
 
+config MMC_PITON
+	bool "MMC support for OpenPiton SoC"
+	depends on DM_MMC && BLK
+	help
+	  This selects support for the SD host controller on OpenPiton SoC.
+	  Note that this SD controller directly exposes the contents of the
+	  SD card as memory mapped, so there is no manual configuration
+	  required
+
 config GENERIC_ATMEL_MCI
 	bool "Atmel Multimedia Card Interface support"
 	depends on DM_MMC && BLK && ARCH_AT91
drivers/mmc/Makefile +1 -0
index 89d6af3db3..d96ac90719 100644
@@ -72,6 +72,7 @@ obj-$(CONFIG_MMC_SDHCI_XENON)		+= xenon_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_ZYNQ)		+= zynq_sdhci.o
 
 obj-$(CONFIG_MMC_SUNXI)			+= sunxi_mmc.o
+obj-$(CONFIG_MMC_PITON)			+= piton_mmc.o
 obj-$(CONFIG_MMC_UNIPHIER)		+= tmio-common.o uniphier-sd.o
 obj-$(CONFIG_RENESAS_SDHI)		+= tmio-common.o renesas-sdhi.o
 obj-$(CONFIG_MMC_BCM2835)		+= bcm2835_sdhost.o
drivers/mmc/piton_mmc.c new file +28 -0
new file mode 100644
index 0000000000..8517ec8410
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2009 SAMSUNG Electronics
+ * Minkyu Kang <[email protected]>
+ * Jaehoon Chung <[email protected]>
+ * Portions Copyright 2011-2019 NVIDIA Corporation
+ * Portions Copyright 2021 Tianrui Wei
+ * This file is adapted from tegra_mmc.c
+ * Tianrui Wei <[email protected]>
+ */
+
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <div64.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/types.h>
+#include <linux/sizes.h>
+#include <log.h>
+#include <mmc.h>
+
+
+#define PITON_MMC_DUMMY_F_MAX 20000000
+#define PITON_MMC_DUMMY_F_MIN 10000000

drivers/mmc/piton_mmc.c line 38

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+#define PITON_MMC_DUMMY_CAPACITY SZ_4G << 3
+#define PITON_MMC_DUMMY_B_MAX SZ_4G
+
+struct piton_mmc_plat {
+	struct mmc_config cfg;
+	struct mmc mmc;
+};
+
+struct piton_mmc_priv {
+	void __iomem *piton_mmc_base_addr; /* peripheral id */

It's for piton. It can be used to base_addr from piton_mmc_base_addr.

drivers/mmc/piton_mmc.c line 45

Quoted 7 lines
drivers/mmc/piton_mmc.c new file +7 -0
+};
+
+/*
+ * see mmc_read_blocks to see how it is used.
+ * start block is hidden at cmd->arg
+ * also, initialize the block size at init
+ */

It seems that not need to describe this comment.

Quoted 17 lines
drivers/mmc/piton_mmc.c new file +17 -0
+static int piton_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
+							  struct mmc_data *data)
+{
+	/* check first if this is a pure command */
+	if (!data)
+		return 0;
+
+	struct piton_mmc_priv *priv = dev_get_priv(dev);
+	u32 *buff, *start_addr, *write_src;
+	size_t byte_cnt, start_block;
+
+	buff = (u32 *)data->dest;
+	write_src = (u32 *)data->src;
+	start_block = cmd->cmdarg;
+	start_addr = priv->piton_mmc_base_addr + start_block;
+
+	/* if there is a read */

drivers/mmc/piton_mmc.c line 72

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+	if (data->flags & MMC_DATA_READ) {
+		for (byte_cnt = data->blocks * data->blocksize; byte_cnt;
+				 byte_cnt -= sizeof(u32)) {
+			*buff++ = readl(start_addr++);
+		}
+	} else {
+		for (byte_cnt = data->blocks * data->blocksize; byte_cnt;
+				 byte_cnt -= sizeof(u32)) {
+			writel(*write_src++,start_addr++);
+		}

Can be reduced code.

for (byte_cnt = data->blocks * data->blocksize; byte_cnt; byte_cnt -= sizeof((u32)) {
	if (data->flags & MMC_DATA_READ)
		...
	else
		...
}
Quoted 38 lines
drivers/mmc/piton_mmc.c new file +38 -0
+
+	}
+
+	return 0;
+}
+
+static int piton_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+	struct piton_mmc_priv *priv = dev_get_priv(dev);
+	struct piton_mmc_plat *plat = dev_get_plat(dev);
+	struct mmc_config *cfg;
+	struct mmc *mmc;
+	/* fill in device description */
+	struct blk_desc *bdesc;
+
+	priv->piton_mmc_base_addr = (void *)dev_read_addr(dev);
+	cfg = &plat->cfg;
+	cfg->name = "PITON MMC";
+	cfg->host_caps = MMC_MODE_8BIT;
+	cfg->f_max = PITON_MMC_DUMMY_F_MAX;
+	cfg->f_min = PITON_MMC_DUMMY_F_MIN;
+	cfg->voltages = MMC_VDD_21_22;
+
+	mmc = &plat->mmc;
+	mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+	mmc->capacity_user = PITON_MMC_DUMMY_CAPACITY;
+	mmc->capacity_user *= mmc->read_bl_len;
+	mmc->capacity_boot = 0;
+	mmc->capacity_rpmb = 0;
+	for (int i = 0; i < 4; i++)
+		mmc->capacity_gp[i] = 0;
+	mmc->capacity = PITON_MMC_DUMMY_CAPACITY;
+	mmc->has_init = 1;
+
+	bdesc = mmc_get_blk_desc(mmc);
+	bdesc->lun = 0;
+	bdesc->hwpart = 0;
+	bdesc->type = 0;

drivers/mmc/piton_mmc.c line 120

Quoted 10 lines
drivers/mmc/piton_mmc.c new file +10 -0
+	bdesc->blksz = mmc->read_bl_len;
+	bdesc->log2blksz = LOG2(bdesc->blksz);
+	bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len);
+
+	return 0;
+}
+
+/* test if the micro sd card is present
+ * always return 1, which means present
+ */

Not need to add this comment.

drivers/mmc/piton_mmc.c line 131

Quoted 11 lines
drivers/mmc/piton_mmc.c new file +11 -0
+static int piton_mmc_getcd(struct udevice *dev)
+{
+	/*
+	 * always return 1
+	 */
+	return 1;
+}
+
+/* dummy function, piton_mmc don't need initialization
+ * in hw
+ */

Remove. Which function is dummy?

Quoted 51 lines
drivers/mmc/piton_mmc.c new file +50 -0
+static const struct dm_mmc_ops piton_mmc_ops = {
+	.send_cmd = piton_mmc_send_cmd,
+	.get_cd = piton_mmc_getcd,
+};
+
+static int piton_mmc_probe(struct udevice *dev)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct piton_mmc_plat *plat = dev_get_plat(dev);
+	struct mmc_config *cfg = &plat->cfg;
+
+	cfg->name = dev->name;
+	upriv->mmc = &plat->mmc;
+	upriv->mmc->has_init = 1;
+	upriv->mmc->capacity = PITON_MMC_DUMMY_CAPACITY;
+	upriv->mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+	return 0;
+}
+
+static int piton_mmc_bind(struct udevice *dev)
+{
+	struct piton_mmc_plat *plat = dev_get_plat(dev);
+	struct mmc_config *cfg = &plat->cfg;
+
+	cfg->name = dev->name;
+	cfg->host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT;
+	cfg->voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
+	cfg->f_min = PITON_MMC_DUMMY_F_MIN;
+	cfg->f_max = PITON_MMC_DUMMY_F_MAX;
+	cfg->b_max = MMC_MAX_BLOCK_LEN;
+
+	return mmc_bind(dev, &plat->mmc, cfg);
+}
+
+static const struct udevice_id piton_mmc_ids[] = {
+	{.compatible = "openpiton,piton-mmc"},
+	{/* sentinel */}
+};
+
+U_BOOT_DRIVER(piton_mmc_drv) = {
+	.name = "piton_mmc",
+	.id = UCLASS_MMC,
+	.of_match = piton_mmc_ids,
+	.of_to_plat = piton_mmc_ofdata_to_platdata,
+	.bind = piton_mmc_bind,
+	.probe = piton_mmc_probe,
+	.ops = &piton_mmc_ops,
+	.plat_auto = sizeof(struct piton_mmc_plat),
+	.priv_auto = sizeof(struct piton_mmc_priv),
+};