u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] mmc: sophgo: milkv_duo: Add SD card support for Milk-V Duo board
@ 2024-03-09 17:51 Kongyang Liu
  2024-03-09 17:51 ` [PATCH v2 1/3] mmc: cv1800b: Add sdhci driver support for cv1800b SoC Kongyang Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Kongyang Liu @ 2024-03-09 17:51 UTC (permalink / raw)
  To: u-boot
  Cc: Jaehoon Chung, Kever Yang, Leo, Marek Vasut, Oleksandr Suvorov,
	Paul Barker, Peng Fan, Peter Geis, Rick Chen, Stefan Roese,
	Tom Rini

This series add sdhci driver for cv1800b SoC and enable SD card support for
Sophgo Milk-V Duo board.

Changes in v2:
- Refactored and simplified some of the code.
- Sync device tree with ptaches from Linux kernel

Kongyang Liu (3):
  mmc: cv1800b: Add sdhci driver support for cv1800b SoC
  riscv: dts: sophgo: Add clk node and sdhci node
  configs: milkv_duo: Add SD card configs

 arch/riscv/dts/cv1800b-milkv-duo.dts |   8 ++
 arch/riscv/dts/cv1800b.dtsi          |   4 +
 arch/riscv/dts/cv18xx.dtsi           |  22 +++++
 configs/milkv_duo_defconfig          |  10 +++
 drivers/mmc/Kconfig                  |  13 +++
 drivers/mmc/Makefile                 |   1 +
 drivers/mmc/cv1800b_sdhci.c          | 116 +++++++++++++++++++++++++++
 7 files changed, 174 insertions(+)
 create mode 100644 drivers/mmc/cv1800b_sdhci.c

-- 
2.41.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/3] mmc: cv1800b: Add sdhci driver support for cv1800b SoC
  2024-03-09 17:51 [PATCH v2 0/3] mmc: sophgo: milkv_duo: Add SD card support for Milk-V Duo board Kongyang Liu
@ 2024-03-09 17:51 ` Kongyang Liu
  2024-03-12 10:03   ` Leo Liang
  2024-03-09 17:51 ` [PATCH v2 2/3] riscv: dts: sophgo: Add clk node and sdhci node Kongyang Liu
  2024-03-09 17:51 ` [PATCH v2 3/3] configs: milkv_duo: Add SD card configs Kongyang Liu
  2 siblings, 1 reply; 7+ messages in thread
From: Kongyang Liu @ 2024-03-09 17:51 UTC (permalink / raw)
  To: u-boot
  Cc: Jaehoon Chung, Kever Yang, Marek Vasut, Oleksandr Suvorov,
	Paul Barker, Peng Fan, Peter Geis, Stefan Roese, Tom Rini

Add sdhci driver for cv1800b SoC.

Signed-off-by: Kongyang Liu <seashell11234455@gmail.com>

---

Changes in v2:
- Refactored and simplified some of the code.

 drivers/mmc/Kconfig         |  13 ++++
 drivers/mmc/Makefile        |   1 +
 drivers/mmc/cv1800b_sdhci.c | 116 ++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 drivers/mmc/cv1800b_sdhci.c

diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index cef05790dd..f7fe6d1042 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -568,6 +568,19 @@ config MMC_SDHCI_CADENCE
 
 	  If unsure, say N.
 
+config MMC_SDHCI_CV1800B
+	bool "SDHCI support for the CV1800B SD/SDIO/eMMC controller"
+	depends on BLK && DM_MMC
+	depends on MMC_SDHCI
+	depends on OF_CONTROL
+	help
+	  This selects the CV1800B SD/SDIO/eMMC driver.
+
+	  If you have a controller with this interface,
+	  say Y here.
+
+	  If unsure, say N.
+
 config MMC_SDHCI_AM654
 	bool "SDHCI Controller on TI's Am654 devices"
 	depends on ARCH_K3
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index e9cf1fcc64..3374321e29 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -60,6 +60,7 @@ obj-$(CONFIG_MMC_SDHCI_ATMEL)		+= atmel_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_BCM2835)		+= bcm2835_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_BCMSTB)		+= bcmstb_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_CADENCE)		+= sdhci-cadence.o
+obj-$(CONFIG_MMC_SDHCI_CV1800B)		+= cv1800b_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_AM654)		+= am654_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_IPROC)		+= iproc_sdhci.o
 obj-$(CONFIG_MMC_SDHCI_KONA)		+= kona_sdhci.o
diff --git a/drivers/mmc/cv1800b_sdhci.c b/drivers/mmc/cv1800b_sdhci.c
new file mode 100644
index 0000000000..2275c53777
--- /dev/null
+++ b/drivers/mmc/cv1800b_sdhci.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
+ */
+
+#include <dm.h>
+#include <mmc.h>
+#include <sdhci.h>
+#include <linux/delay.h>
+
+#define SDHCI_PHY_TX_RX_DLY  0x240
+#define MMC_MAX_CLOCK        375000000
+#define TUNE_MAX_PHCODE      128
+
+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);
+}
+
+static void cv1800b_sdhci_reset(struct sdhci_host *host, u8 mask)
+{
+	sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET);
+	while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask)
+		udelay(10);
+}
+
+static int cv1800b_execute_tuning(struct mmc *mmc, u8 opcode)
+{
+	struct sdhci_host *host = dev_get_priv(mmc->dev);
+
+	u16 tap;
+
+	int current_size = 0;
+	int max_size = 0;
+	int max_window = 0;
+
+	for (tap = 0; tap < TUNE_MAX_PHCODE; tap++) {
+		cv1800b_set_tap_delay(host, tap);
+
+		if (mmc_send_tuning(host->mmc, opcode, NULL)) {
+			current_size = 0;
+		} else {
+			current_size++;
+			if (current_size > max_size) {
+				max_size = current_size;
+				max_window = tap;
+			}
+		}
+	}
+
+	cv1800b_sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
+
+	cv1800b_set_tap_delay(host, max_window - max_size / 2);
+
+	return 0;
+}
+
+const struct sdhci_ops cv1800b_sdhci_sd_ops = {
+	.platform_execute_tuning = cv1800b_execute_tuning,
+};
+
+static int cv1800b_sdhci_bind(struct udevice *dev)
+{
+	struct cv1800b_sdhci_plat *plat = dev_get_plat(dev);
+
+	return sdhci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
+static int cv1800b_sdhci_probe(struct udevice *dev)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct cv1800b_sdhci_plat *plat = dev_get_plat(dev);
+	struct sdhci_host *host = dev_get_priv(dev);
+	int ret;
+
+	host->name = dev->name;
+	host->ioaddr = devfdt_get_addr_ptr(dev);
+
+	upriv->mmc = &plat->mmc;
+	host->mmc = &plat->mmc;
+	host->mmc->priv = host;
+	host->mmc->dev = dev;
+	host->ops = &cv1800b_sdhci_sd_ops;
+	host->max_clk = MMC_MAX_CLOCK;
+
+	ret = mmc_of_parse(dev, &plat->cfg);
+	if (ret)
+		return ret;
+
+	ret = sdhci_setup_cfg(&plat->cfg, host, 0, 200000);
+	if (ret)
+		return ret;
+
+	return sdhci_probe(dev);
+}
+
+static const struct udevice_id cv1800b_sdhci_match[] = {
+	{ .compatible = "sophgo,cv1800b-dwcmshc" },
+	{ }
+};
+
+U_BOOT_DRIVER(cv1800b_sdhci) = {
+	.name = "sdhci-cv1800b",
+	.id = UCLASS_MMC,
+	.of_match = cv1800b_sdhci_match,
+	.bind = cv1800b_sdhci_bind,
+	.probe = cv1800b_sdhci_probe,
+	.priv_auto = sizeof(struct sdhci_host),
+	.plat_auto = sizeof(struct cv1800b_sdhci_plat),
+	.ops = &sdhci_ops,
+};
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/3] riscv: dts: sophgo: Add clk node and sdhci node
  2024-03-09 17:51 [PATCH v2 0/3] mmc: sophgo: milkv_duo: Add SD card support for Milk-V Duo board Kongyang Liu
  2024-03-09 17:51 ` [PATCH v2 1/3] mmc: cv1800b: Add sdhci driver support for cv1800b SoC Kongyang Liu
@ 2024-03-09 17:51 ` Kongyang Liu
  2024-03-12  9:27   ` Leo Liang
  2024-03-09 17:51 ` [PATCH v2 3/3] configs: milkv_duo: Add SD card configs Kongyang Liu
  2 siblings, 1 reply; 7+ messages in thread
From: Kongyang Liu @ 2024-03-09 17:51 UTC (permalink / raw)
  To: u-boot; +Cc: Leo, Rick Chen, Tom Rini

Add clk node and sdhci node for cv18xx SoCs according to patches from Linux
kernel.

clk: https://lore.kernel.org/all/IA1PR20MB4953F9AD6792013B54636F05BB4F2@IA1PR20MB4953.namprd20.prod.outlook.com/
sdhci: https://lore.kernel.org/all/20240217144826.3944-1-jszhang@kernel.org/

Signed-off-by: Kongyang Liu <seashell11234455@gmail.com>

---

Changes in v2:
- Sync device tree with ptaches from Linux kernel

 arch/riscv/dts/cv1800b-milkv-duo.dts |  8 ++++++++
 arch/riscv/dts/cv1800b.dtsi          |  4 ++++
 arch/riscv/dts/cv18xx.dtsi           | 22 ++++++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/arch/riscv/dts/cv1800b-milkv-duo.dts b/arch/riscv/dts/cv1800b-milkv-duo.dts
index 3af9e34b3b..94e64ddce8 100644
--- a/arch/riscv/dts/cv1800b-milkv-duo.dts
+++ b/arch/riscv/dts/cv1800b-milkv-duo.dts
@@ -33,6 +33,14 @@
 	clock-frequency = <25000000>;
 };
 
+&sdhci0 {
+	status = "okay";
+	bus-width = <4>;
+	no-1-8-v;
+	no-mmc;
+	no-sdio;
+};
+
 &uart0 {
 	status = "okay";
 };
diff --git a/arch/riscv/dts/cv1800b.dtsi b/arch/riscv/dts/cv1800b.dtsi
index 165e9e320a..baf641829e 100644
--- a/arch/riscv/dts/cv1800b.dtsi
+++ b/arch/riscv/dts/cv1800b.dtsi
@@ -16,3 +16,7 @@
 &clint {
 	compatible = "sophgo,cv1800b-clint", "thead,c900-clint";
 };
+
+&clk {
+	compatible = "sophgo,cv1800-clk";
+};
diff --git a/arch/riscv/dts/cv18xx.dtsi b/arch/riscv/dts/cv18xx.dtsi
index 2d6f4a4b1e..ec99c4deeb 100644
--- a/arch/riscv/dts/cv18xx.dtsi
+++ b/arch/riscv/dts/cv18xx.dtsi
@@ -45,6 +45,13 @@
 		#clock-cells = <0>;
 	};
 
+	sdhci_clk: sdhci-clock {
+		compatible = "fixed-clock";
+		clock-frequency = <375000000>;
+		clock-output-names = "sdhci_clk";
+		#clock-cells = <0>;
+	};
+
 	soc {
 		compatible = "simple-bus";
 		interrupt-parent = <&plic>;
@@ -53,6 +60,12 @@
 		dma-noncoherent;
 		ranges;
 
+		clk: clock-controller@3002000 {
+			reg = <0x03002000 0x1000>;
+			clocks = <&osc>;
+			#clock-cells = <1>;
+		};
+
 		gpio0: gpio@3020000 {
 			compatible = "snps,dw-apb-gpio";
 			reg = <0x3020000 0x1000>;
@@ -175,6 +188,15 @@
 			status = "disabled";
 		};
 
+		sdhci0: mmc@4310000 {
+			compatible = "sophgo,cv1800b-dwcmshc";
+			reg = <0x4310000 0x1000>;
+			interrupts = <36 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&sdhci_clk>;
+			clock-names = "core";
+			status = "disabled";
+		};
+
 		plic: interrupt-controller@70000000 {
 			reg = <0x70000000 0x4000000>;
 			interrupts-extended = <&cpu0_intc 11>, <&cpu0_intc 9>;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/3] configs: milkv_duo: Add SD card configs
  2024-03-09 17:51 [PATCH v2 0/3] mmc: sophgo: milkv_duo: Add SD card support for Milk-V Duo board Kongyang Liu
  2024-03-09 17:51 ` [PATCH v2 1/3] mmc: cv1800b: Add sdhci driver support for cv1800b SoC Kongyang Liu
  2024-03-09 17:51 ` [PATCH v2 2/3] riscv: dts: sophgo: Add clk node and sdhci node Kongyang Liu
@ 2024-03-09 17:51 ` Kongyang Liu
  2024-03-12 10:02   ` Leo Liang
  2 siblings, 1 reply; 7+ messages in thread
From: Kongyang Liu @ 2024-03-09 17:51 UTC (permalink / raw)
  To: u-boot; +Cc: Leo Yu-Chi Liang, Tom Rini

Add configs related to sdhci and mmc for Sophgo Milk-V Duo board

Signed-off-by: Kongyang Liu <seashell11234455@gmail.com>
---

(no changes since v1)

 configs/milkv_duo_defconfig | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/configs/milkv_duo_defconfig b/configs/milkv_duo_defconfig
index 548adf174c..e8413d7aa9 100644
--- a/configs/milkv_duo_defconfig
+++ b/configs/milkv_duo_defconfig
@@ -17,6 +17,16 @@ CONFIG_SYS_CBSIZE=512
 CONFIG_SYS_PBSIZE=544
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="milkv_duo# "
+CONFIG_CMD_MMC=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_FAT=y
+CONFIG_CMD_FS_GENERIC=y
 CONFIG_ENV_OVERWRITE=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_SYS_NS16550=y
 CONFIG_SYS_NS16550_MEM32=y
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/3] riscv: dts: sophgo: Add clk node and sdhci node
  2024-03-09 17:51 ` [PATCH v2 2/3] riscv: dts: sophgo: Add clk node and sdhci node Kongyang Liu
@ 2024-03-12  9:27   ` Leo Liang
  0 siblings, 0 replies; 7+ messages in thread
From: Leo Liang @ 2024-03-12  9:27 UTC (permalink / raw)
  To: Kongyang Liu; +Cc: u-boot, Rick Chen, Tom Rini

On Sun, Mar 10, 2024 at 01:51:56AM +0800, Kongyang Liu wrote:
> Add clk node and sdhci node for cv18xx SoCs according to patches from Linux
> kernel.
> 
> clk: https://lore.kernel.org/all/IA1PR20MB4953F9AD6792013B54636F05BB4F2@IA1PR20MB4953.namprd20.prod.outlook.com/
> sdhci: https://lore.kernel.org/all/20240217144826.3944-1-jszhang@kernel.org/
> 
> Signed-off-by: Kongyang Liu <seashell11234455@gmail.com>
> ---
> 
> Changes in v2:
> - Sync device tree with ptaches from Linux kernel
> 
>  arch/riscv/dts/cv1800b-milkv-duo.dts |  8 ++++++++
>  arch/riscv/dts/cv1800b.dtsi          |  4 ++++
>  arch/riscv/dts/cv18xx.dtsi           | 22 ++++++++++++++++++++++
>  3 files changed, 34 insertions(+)

Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/3] configs: milkv_duo: Add SD card configs
  2024-03-09 17:51 ` [PATCH v2 3/3] configs: milkv_duo: Add SD card configs Kongyang Liu
@ 2024-03-12 10:02   ` Leo Liang
  0 siblings, 0 replies; 7+ messages in thread
From: Leo Liang @ 2024-03-12 10:02 UTC (permalink / raw)
  To: Kongyang Liu; +Cc: u-boot, Tom Rini

On Sun, Mar 10, 2024 at 01:51:57AM +0800, Kongyang Liu wrote:
> Add configs related to sdhci and mmc for Sophgo Milk-V Duo board
> 
> Signed-off-by: Kongyang Liu <seashell11234455@gmail.com>
> ---
> 
> (no changes since v1)
> 
>  configs/milkv_duo_defconfig | 10 ++++++++++
>  1 file changed, 10 insertions(+)

Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/3] mmc: cv1800b: Add sdhci driver support for cv1800b SoC
  2024-03-09 17:51 ` [PATCH v2 1/3] mmc: cv1800b: Add sdhci driver support for cv1800b SoC Kongyang Liu
@ 2024-03-12 10:03   ` Leo Liang
  0 siblings, 0 replies; 7+ messages in thread
From: Leo Liang @ 2024-03-12 10:03 UTC (permalink / raw)
  To: Kongyang Liu
  Cc: u-boot, Jaehoon Chung, Kever Yang, Marek Vasut,
	Oleksandr Suvorov, Paul Barker, Peng Fan, Peter Geis,
	Stefan Roese, Tom Rini

On Sun, Mar 10, 2024 at 01:51:55AM +0800, Kongyang Liu wrote:
> Add sdhci driver for cv1800b SoC.
> 
> Signed-off-by: Kongyang Liu <seashell11234455@gmail.com>
> ---
> 
> Changes in v2:
> - Refactored and simplified some of the code.
> 
>  drivers/mmc/Kconfig         |  13 ++++
>  drivers/mmc/Makefile        |   1 +
>  drivers/mmc/cv1800b_sdhci.c | 116 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 130 insertions(+)
>  create mode 100644 drivers/mmc/cv1800b_sdhci.c

Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-12 10:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-09 17:51 [PATCH v2 0/3] mmc: sophgo: milkv_duo: Add SD card support for Milk-V Duo board Kongyang Liu
2024-03-09 17:51 ` [PATCH v2 1/3] mmc: cv1800b: Add sdhci driver support for cv1800b SoC Kongyang Liu
2024-03-12 10:03   ` Leo Liang
2024-03-09 17:51 ` [PATCH v2 2/3] riscv: dts: sophgo: Add clk node and sdhci node Kongyang Liu
2024-03-12  9:27   ` Leo Liang
2024-03-09 17:51 ` [PATCH v2 3/3] configs: milkv_duo: Add SD card configs Kongyang Liu
2024-03-12 10:02   ` Leo Liang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).