Skip to contentSkip to conversation

Add MMC/SD support for S700/S900

PATCH In review Amit Singh Tomar 3 participants 18 messages Nov 28, 2021 – Jan 18, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover Add MMC/SD support for S700/S900

Hi,

Sorry, it took me some time to come up with v4. For v3, all the comments are from MMC driver(patch 5/6), and tried to address in this series(v4) with changelog mentioned in the patch (5/6) itself.

--------------------------------------------------------
This series(v3) addresses review comments provided by Andre and Jaehoon. Earlier in MMC driver, we were *not* checking the command response errors(for instance, the CRC error) based on STATU register. This is now addressed in patch 5/6.

Also, MMC driver(patch 5/6) now has replaced the switch/case with if/else to correlate MMC_RSP_Rx bitmask values with register bits as suggested by Andre.

Apart from it, there are changes in patch 2/6 to fix weird assignments to div variable.

----------------------------------------------------------------------------------
Series(v2) has few important updates, while loading large files we found that MMC framework puts "0x1fffe00" into DMA Frame Length(DMA_FRAME_LEN 0x000C) but register itself is limited to 24 bits and hence it was failing. It is due to the wrong Block count(cfg->b_max) used in driver, that should be just 512. This is now fixed in patch 5/6.

Apart from it, as Andre pointed that we might be just overclocking the MMC/SD clock, and to confirm this we run following test:

$ md5sum clang
349eac46cbbe28f8e44da2dce07fa7b7  clang

U-Boot => ext4load mmc 0:2 0x0 clang
503316480 bytes read in 19516 ms (24.6 MiB/s)
U-Boot => md5sum 0x0 0x1e000000
md5 for 00000000 ... 1dffffff ==> d793bb51c4a1cf83c96d1980927461ff

Even though file gets loaded but md5sum doesn't match. This is now fixed in patch 2/6

U-Boot => ext4load mmc 0:2 0x0 clang
503316480 bytes read in 41524 ms (11.6 MiB/s)
U-Boot => md5sum 0x0 0x1e000000
md5 for 00000000 ... 1dffffff ==> 349eac46cbbe28f8e44da2dce07fa7b7

-----------------------------------------------------------------------------
At the moment on S700 based platforms, only way to load/boot the Kernel is from Ethernet, and with these patches one can now load/boot the Kernel from uSD card.

Patches(1/6 and 2/6) adds changes needed for MMC/SD clock. It introduces set/get callback routine and get/set MMC/SD clock rate based on device id.

Patch 4/6 adds MMC/SD node in U-boot specific dtsi file, which is used by MMC/SD driver to read controller base address later on.

Patch 5/6 adds driver for MMC/SD controller present on S700 SoC, and its based on Mainline Linux driver and DMA related bits is picked and simpilified from vendor source.

Final patch 6/6 enables the driver support along with MMC commands in Cubieboard7 config file.

Also, while at it just took the opportunity to synchronize the S700 SoC DT with Linux in patch 3/6.

This patch-set is tested on Cubieboard7-lite board with following results:

U-Boot 2021.01-rc1-04434-g6589149-dirty (Dec 13 2020 - 13:51:07 +0530) cubieboard7

DRAM:  1 GiB
PSCI:  v0.2
MMC:   mmc@e0210000: 0
In:    serial@e0126000
Out:   serial@e0126000
Err:   serial@e0126000
Net:   eth0: ethernet@e0220000
Hit any key to stop autoboot:  0

U-Boot =>
U-Boot =>
U-Boot =>
U-Boot => mmc info
Device: mmc@e0210000
Manufacturer ID: 3
OEM: 5344
Name: SC16G
Bus Speed: 50000000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 14.8 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
U-Boot => setenv bootargs console=ttyOWL3,115200n8 earlycon=owl,0xe0126000 init=/sbin/init root=/dev/mmcblk0p2 rw rootwait U-Boot => setenv kernel_addr_r 0x80000;setenv fdt_addr_r 0x10000000;
U-Boot => fatload mmc 0:1 ${kernel_addr_r} image ;fatload mmc 0:1 ${fdt_addr_r} s700-cubieboard7.dtb 27480576 bytes read in 1041 ms (25.2 MiB/s)
7056 bytes read in 2 ms (3.4 MiB/s)
U-Boot => booti $kernel_addr_r - $fdt_addr_r
## Flattened Device Tree blob at 10000000
Booting using the fdt blob at 0x10000000
Loading Device Tree to 000000003df56000, end 000000003df5ab8f ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 5.7.0-rc6-00022-g99f1c330923b-dirty (amit@amit-ThinkPad-X230) (gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701] (Linaro GCC 7.3-2018.05), GNU ld (GNU Binutils for Ubuntu) 2.26.1) #474 SMP PREEMPT Thu Aug 13 15:27:10 IST 2020
[    0.000000] Machine model: CubieBoard7
[    0.000000] earlycon: owl0 at MMIO 0x00000000e0126000 (options '')
[    0.000000] printk: bootconsole [owl0] enabled
[    0.000000] efi: UEFI not found.
[    0.000000] cma: Reserved 32 MiB at 0x000000003e000000

Amit Singh Tomar (6):
clk: actions: Introduce dummy get/set_rate callbacks
clk: actions: Add SD/MMC clocks
ARM: dts: sync Actions Semi S700 DT from Linux 5.10-rc7
ARM: dts: s700: add MMC/SD controller node
mmc: actions: add MMC driver for Actions OWL S700/S900
configs: Enable mmc support

 arch/arm/dts/s700-u-boot.dtsi                 |  10 +
 arch/arm/dts/s700.dtsi                        |  17 +-
 configs/cubieboard7_defconfig                 |   3 +
 drivers/clk/owl/clk_owl.c                     |  99 +++++
 drivers/mmc/Kconfig                           |   7 +
 drivers/mmc/Makefile                          |   1 +
 drivers/mmc/owl_mmc.c                         | 408 ++++++++++++++++++
 .../dt-bindings/power/owl-s700-powergate.h    |  19 +
 8 files changed, 563 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mmc/owl_mmc.c
 create mode 100644 include/dt-bindings/power/owl-s700-powergate.h
Signature · 1 line
2.27.0
#1 lore raw

PATCH v4 1/6 clk: actions: Introduce dummy get/set_rate callbacks

From: Amit Singh Tomar <[email protected]>

This commit introduces get/set_rate callbacks, these are dummy at the moment, and can be used to get/set clock for various devices based on the clk id.

---
Changes since v3:
* No changes.
Changes since v2:
* No changes.
Changes since previous version:
* Removed premature initialization to avoid compiler warnings.

---
 drivers/clk/owl/clk_owl.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/clk/owl/clk_owl.c +26 -0
index 96ab7fed1f37..f78e5fa3f08d 100644
@@ -128,6 +128,30 @@ int owl_clk_disable(struct clk *clk)
 	return 0;
 }
 
+static ulong owl_clk_get_rate(struct clk *clk)
+{
+	ulong rate;
+
+	switch (clk->id) {
+	default:
+		return -ENOENT;
+	}
+
+	return rate;
+}
+
+static ulong owl_clk_set_rate(struct clk *clk, ulong rate)
+{
+	ulong new_rate;
+
+	switch (clk->id) {
+	default:
+		return -ENOENT;
+	}
+
+	return new_rate;
+}
+
 static int owl_clk_probe(struct udevice *dev)
 {
 	struct owl_clk_priv *priv = dev_get_priv(dev);
@@ -145,6 +169,8 @@ static int owl_clk_probe(struct udevice *dev)
 static const struct clk_ops owl_clk_ops = {
 	.enable = owl_clk_enable,
 	.disable = owl_clk_disable,
+	.get_rate = owl_clk_get_rate,
+	.set_rate = owl_clk_set_rate,
 };
 
 static const struct udevice_id owl_clk_ids[] = {
Signature · 1 line
2.27.0
#4 lore raw

PATCH v4 2/6 clk: actions: Add SD/MMC clocks

In reply to Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This commit adds SD/MMC clocks, and provides .set/get_rate callbacks for SD/MMC device present on Actions OWL S700 SoCs.

---
Changes since v3:
* No change.
Changes since v2:
* Fixed the weird div assignment.
* Moved the clock bit for SD from header file to driver file.
* Removed "< 0" part while comparing unsigned.
Changes since previous version:
* Removed rate *= 2 as this just overclocks.
* Separated the divide by 128 bit from divider value.
* Provided the separate routine to get sd parent rate based on bit 9.
* Removed unnecessary initialization.

---
 drivers/clk/owl/clk_owl.c | 73 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
drivers/clk/owl/clk_owl.c +73 -0
index f78e5fa3f08d..678fdd5a4540 100644
@@ -20,6 +20,8 @@
 #include <linux/bitops.h>
 #include <linux/delay.h>
 
+#define CMU_DEVCLKEN0_SD0	BIT(22)
+
 void owl_clk_init(struct owl_clk_priv *priv)
 {
 	u32 bus_clk = 0, core_pll, dev_pll;
@@ -92,6 +94,9 @@ int owl_clk_enable(struct clk *clk)
 		setbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_ETH);
 		setbits_le32(priv->base + CMU_ETHERNETPLL, 5);
 		break;
+	case CLK_SD0:
+		setbits_le32(priv->base + CMU_DEVCLKEN0, CMU_DEVCLKEN0_SD0);
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -121,6 +126,9 @@ int owl_clk_disable(struct clk *clk)
 	case CLK_ETHERNET:
 		clrbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_ETH);
 		break;
+	case CLK_SD0:
+		clrbits_le32(priv->base + CMU_DEVCLKEN0, CMU_DEVCLKEN0_SD0);
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -128,11 +136,72 @@ int owl_clk_disable(struct clk *clk)
 	return 0;
 }
 
+static ulong get_sd_parent_rate(struct owl_clk_priv *priv, u32 dev_index)
+{
+	ulong rate;
+	u32 reg;
+
+	reg = readl(priv->base + (CMU_SD0CLK + dev_index * 0x4));
+	/* Clock output of DEV/NAND_PLL
+	 * Range: 48M ~ 756M
+	 * Frequency= PLLCLK * 6
+	 */
+	if (reg & 0x200)
+		rate = readl(priv->base + CMU_NANDPLL) & 0x7f;
+	else
+		rate = readl(priv->base + CMU_DEVPLL) & 0x7f;
+
+	rate *= 6000000;
+
+	return rate;
+}
+
+static ulong owl_get_sd_clk_rate(struct owl_clk_priv *priv, int sd_index)
+{
+	uint div, val;
+	ulong parent_rate = get_sd_parent_rate(priv, sd_index);
+
+	val = readl(priv->base + (CMU_SD0CLK + sd_index * 0x4));
+	div = (val & 0x1f) + 1;
+
+	return (parent_rate / div);
+}
+
+static ulong owl_set_sd_clk_rate(struct owl_clk_priv *priv, ulong rate,
+				 int sd_index)
+{
+	uint div, val;
+	ulong parent_rate = get_sd_parent_rate(priv, sd_index);
+
+	if (rate == 0)
+		return rate;
+
+	div = (parent_rate / rate);
+
+	val = readl(priv->base + (CMU_SD0CLK + sd_index * 0x4));
+	/* Bits 4..0 is used to program div value and bit 8 to enable
+	 * divide by 128 circuit
+	 */
+	val &= ~0x11f;
+	if (div >= 128) {
+		div = div / 128;
+		val |= 0x100; /* enable divide by 128 circuit */
+	}
+	val |= ((div - 1) & 0x1f);
+	writel(val, priv->base + (CMU_SD0CLK + sd_index * 0x4));
+
+	return owl_get_sd_clk_rate(priv, 0);
+}
+
 static ulong owl_clk_get_rate(struct clk *clk)
 {
+	struct owl_clk_priv *priv = dev_get_priv(clk->dev);
 	ulong rate;
 
 	switch (clk->id) {
+	case CLK_SD0:
+		rate = owl_get_sd_clk_rate(priv, 0);
+		break;
 	default:
 		return -ENOENT;
 	}
@@ -142,9 +211,13 @@ static ulong owl_clk_get_rate(struct clk *clk)
 
 static ulong owl_clk_set_rate(struct clk *clk, ulong rate)
 {
+	struct owl_clk_priv *priv = dev_get_priv(clk->dev);
 	ulong new_rate;
 
 	switch (clk->id) {
+	case CLK_SD0:
+		new_rate = owl_set_sd_clk_rate(priv, rate, 0);
+		break;
 	default:
 		return -ENOENT;
 	}
Signature · 1 line
2.27.0
#7 lore raw

PATCH v4 3/6 ARM: dts: sync Actions Semi S700 DT from Linux 5.10-rc7

In reply to Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This Synchronizes the Actions Semi S700 SoC DT changes from commit "0477e9288185" ("Linux 5.10-rc7").

---
Changes since previous versions
* No change.

---
 arch/arm/dts/s700.dtsi                        | 17 ++++++++++++++++-
 .../dt-bindings/power/owl-s700-powergate.h    | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 include/dt-bindings/power/owl-s700-powergate.h
arch/arm/dts/s700.dtsi +16 -1
index 2006ad5424fa..2c78caebf515 100644
@@ -5,6 +5,7 @@
 
 #include <dt-bindings/clock/actions,s700-cmu.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/power/owl-s700-powergate.h>
 #include <dt-bindings/reset/actions,s700-reset.h>
 
 / {
@@ -231,7 +232,7 @@
 
 		pinctrl: pinctrl@e01b0000 {
 			compatible = "actions,s700-pinctrl";
-			reg = <0x0 0xe01b0000 0x0 0x1000>;
+			reg = <0x0 0xe01b0000 0x0 0x100>;
 			clocks = <&cmu CLK_GPIO>;
 			gpio-controller;
 			gpio-ranges = <&pinctrl 0 0 136>;
@@ -244,5 +245,19 @@
 				     <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
 		};
+
+		dma: dma-controller@e0230000 {
+			compatible = "actions,s700-dma";
+			reg = <0x0 0xe0230000 0x0 0x1000>;
+			interrupts = <GIC_SPI 57 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 58 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 60 IRQ_TYPE_LEVEL_HIGH>;
+			#dma-cells = <1>;
+			dma-channels = <10>;
+			dma-requests = <44>;
+			clocks = <&cmu CLK_DMAC>;
+			power-domains = <&sps S700_PD_DMA>;
+		};
 	};
 };
include/dt-bindings/power/owl-s700-powergate.h new file +19 -0
new file mode 100644
index 000000000000..4cf1aefbf09c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Actions Semi S700 SPS
+ *
+ * Copyright (c) 2017 Andreas Färber
+ */
+#ifndef DT_BINDINGS_POWER_OWL_S700_POWERGATE_H
+#define DT_BINDINGS_POWER_OWL_S700_POWERGATE_H
+
+#define S700_PD_VDE	0
+#define S700_PD_VCE_SI	1
+#define S700_PD_USB2_1	2
+#define S700_PD_HDE	3
+#define S700_PD_DMA	4
+#define S700_PD_DS	5
+#define S700_PD_USB3	6
+#define S700_PD_USB2_0	7
+
+#endif
Signature · 1 line
2.27.0
#11 lore raw

PATCH v4 4/6 ARM: dts: s700: add MMC/SD controller node

In reply to Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This patch adds node for mmc/sd controller found on Action Semi OWL S700 SoC.

Since, upstream Linux binding has not been merged for S700 MMC/SD controller, Changes are put in u-boot specific dtsi file.

---
Changes since previous versions
* No change.

---
 arch/arm/dts/s700-u-boot.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/arm/dts/s700-u-boot.dtsi +10 -0
index 1b2768272c62..3c3396bccf11 100644
@@ -19,6 +19,16 @@
 			status = "okay";
                 };
 
+		mmc0: mmc@e0210000 {
+			compatible = "actions,s700-mmc", "actions,owl-mmc";
+			reg = <0x0 0xe0210000 0x0 0x4000>;
+			interrupts = <GIC_SPI 42 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&cmu CLK_SD0>;
+			dmas = <&dma 2>;
+			dma-names = "mmc";
+			bus-width = <4>;
+			status = "okay";
+		};
 	};
 };
 
Signature · 1 line
2.27.0
#16 lore raw

PATCH v4 6/6 configs: Enable mmc support

In reply to Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This commits enables mmc on the Actions Cubieboard7 board.

---
Changes since previous versions
* No change.

---
 configs/cubieboard7_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/cubieboard7_defconfig +3 -0
index 2937a54d1195..536b023a3eec 100644
@@ -16,3 +16,6 @@ CONFIG_PHY_REALTEK=y
 CONFIG_RTL8201F_PHY_S700_RMII_TIMINGS=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_ETH_DESIGNWARE_S700=y
+CONFIG_DM_MMC=y
+CONFIG_MMC_OWL=y
+CONFIG_CMD_MMC=y
Signature · 1 line
2.27.0
#14 lore raw

PATCH v4 5/6 mmc: actions: add MMC driver for Actions OWL S700/S900

In reply to Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This commit adds support for MMC controllers found on Actions OWL SoC platform(S700/S900).

---
Changes since v3:
* Re-based to latest master (2ad8d0cb950da)

There are some "dm: treewide" changes have been made since v3, for instance:

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

It is addressed in v4 for this MMC driver.

* Used setbits_le32( wherever possible.
* Properly write the OWL_REG_SD_BUF_SIZE register.
* Updated the mode handling as suggested by Ander:
mode = 0;
if (cmd->resp_type != MMC_RSP_NONE)
cmd_rsp_mask = OWL_SD_STATE_CLNR | OWL_SD_STATE_CRC7ER;

if (md->resp_type == MMC_RSP_R1) {
.... (always assign to "mode")
* Properly handled the unsupported SD clock rate.
* Wait for DMA transfer to complete before stoping the DMA.
Changes since v2:
* Progammed read/write delays as suggested by
Jaehoon, its more readable now.
* Updated commit message and source file to reflect
it supports S900 as well.
* Updated SD_DMA_CHANNEL macro to include channel offset.
* Checked the command response Error based on SDC STATU register bits.
* Replaced switch/case with if/else to correlate with MMC_RSP_Rx bitmask values, as suggested by Andre.
* Introduced clk_disable based on mmc->clk_disable flag.
* Guarded the clk_set_rate under if statment to avoid reprogramming the rate.
* Fetched the DRQ number from using args.args[0].
Changes since previous version
* Corrected block count to 512.
* Changed the command timeout value to 30ms.
* Used readl_poll_timeout.
* Read DMA parameters from DT instead of hardcoding it.
* Reduced number of arguments passed to own_dma_cofig.
* Removed debug leftover.
* Used mmc_of_parse().

---
 drivers/mmc/Kconfig   |   7 +
 drivers/mmc/Makefile  |   1 +
 drivers/mmc/owl_mmc.c | 408 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 416 insertions(+)
 create mode 100644 drivers/mmc/owl_mmc.c
drivers/mmc/Kconfig +7 -0
index e0927ce1c9bd..f04cc44e1973 100644
@@ -295,6 +295,13 @@ config MMC_MXC
 
 	  If unsure, say N.
 
+config MMC_OWL
+	bool "Actions OWL Multimedia Card Interface support"
+	depends on ARCH_OWL && DM_MMC && BLK
+	help
+	  This selects the OWL SD/MMC host controller found on board
+	  based on Actions S700/S900 SoC.
+
 config MMC_MXS
 	bool "Freescale MXS Multimedia Card Interface support"
 	depends on MX23 || MX28 || MX6 || MX7
drivers/mmc/Makefile +1 -0
index 7e819d2b3a25..17ebc04203ed 100644
@@ -39,6 +39,7 @@ obj-$(CONFIG_MMC_OMAP_HS)		+= omap_hsmmc.o
 obj-$(CONFIG_MMC_MXC)			+= mxcmmc.o
 obj-$(CONFIG_MMC_MXS)			+= mxsmmc.o
 obj-$(CONFIG_MMC_OCTEONTX)		+= octeontx_hsmmc.o
+obj-$(CONFIG_MMC_OWL)			+= owl_mmc.o
 obj-$(CONFIG_MMC_PCI)			+= pci_mmc.o
 obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
 obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
drivers/mmc/owl_mmc.c new file +408 -0

408 lines not on this page · raw message

Signature · 1 line
2.27.0
#8 lore raw

Re: [PATCH v4 3/6] ARM: dts: sync Actions Semi S700 DT from Linux 5.10-rc7

In reply to Amit Singh Tomar
Quoted 6 lines · Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This Synchronizes the Actions Semi S700 SoC DT changes from commit "0477e9288185" ("Linux 5.10-rc7").

Quoted 8 lines

---
Changes since previous versions
* No change.

---
 arch/arm/dts/s700.dtsi                        | 17 ++++++++++++++++-
 .../dt-bindings/power/owl-s700-powergate.h    | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 include/dt-bindings/power/owl-s700-powergate.h

That's a fairly old tag to sync to, can we please pick something newer (either latest release or latest rc)? Thanks!

Signature · 1 line
Tom
#9 lore raw

PATCH v4 3/6 ARM: dts: sync Actions Semi S700 DT from Linux v5.16-rc3

In reply to Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This Synchronizes the Actions Semi S700 SoC DT changes from commit "g58e1100fdc59" ("Linux v5.16-rc3").

---
 arch/arm/dts/s700.dtsi                        | 17 ++++++++++++++++-
 .../dt-bindings/power/owl-s700-powergate.h    | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 include/dt-bindings/power/owl-s700-powergate.h
arch/arm/dts/s700.dtsi +16 -1
index 2006ad5424fa..2c78caebf515 100644
@@ -5,6 +5,7 @@
 
 #include <dt-bindings/clock/actions,s700-cmu.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/power/owl-s700-powergate.h>
 #include <dt-bindings/reset/actions,s700-reset.h>
 
 / {
@@ -231,7 +232,7 @@
 
 		pinctrl: pinctrl@e01b0000 {
 			compatible = "actions,s700-pinctrl";
-			reg = <0x0 0xe01b0000 0x0 0x1000>;
+			reg = <0x0 0xe01b0000 0x0 0x100>;
 			clocks = <&cmu CLK_GPIO>;
 			gpio-controller;
 			gpio-ranges = <&pinctrl 0 0 136>;
@@ -244,5 +245,19 @@
 				     <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
 		};
+
+		dma: dma-controller@e0230000 {
+			compatible = "actions,s700-dma";
+			reg = <0x0 0xe0230000 0x0 0x1000>;
+			interrupts = <GIC_SPI 57 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 58 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 60 IRQ_TYPE_LEVEL_HIGH>;
+			#dma-cells = <1>;
+			dma-channels = <10>;
+			dma-requests = <44>;
+			clocks = <&cmu CLK_DMAC>;
+			power-domains = <&sps S700_PD_DMA>;
+		};
 	};
 };
include/dt-bindings/power/owl-s700-powergate.h new file +19 -0
new file mode 100644
index 000000000000..4cf1aefbf09c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Actions Semi S700 SPS
+ *
+ * Copyright (c) 2017 Andreas Färber
+ */
+#ifndef DT_BINDINGS_POWER_OWL_S700_POWERGATE_H
+#define DT_BINDINGS_POWER_OWL_S700_POWERGATE_H
+
+#define S700_PD_VDE	0
+#define S700_PD_VCE_SI	1
+#define S700_PD_USB2_1	2
+#define S700_PD_HDE	3
+#define S700_PD_DMA	4
+#define S700_PD_DS	5
+#define S700_PD_USB3	6
+#define S700_PD_USB2_0	7
+
+#endif
Signature · 1 line
2.27.0
#12 lore raw

Re: [PATCH v4 4/6] ARM: dts: s700: add MMC/SD controller node

In reply to Amit Singh Tomar
Quoted 9 lines · Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This patch adds node for mmc/sd controller found on Action Semi OWL S700 SoC.

Since, upstream Linux binding has not been merged for S700 MMC/SD controller, Changes are put in u-boot specific dtsi file.

This leads to:
arch/arm/dts/s700-cubieboard7.dtb: ERROR (phandle_references):
/soc/mmc@e0210000 : Reference to non-existent node or label "dma"

Please rebase on top of current next, thanks.

Signature · 1 line
Tom
Reviewed-by on v4 1/6
#2 lore raw

Re: [PATCH v4 1/6] clk: actions: Introduce dummy get/set_rate callbacks

In reply to Amit Singh Tomar
Quoted 24 lines · Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This commit introduces get/set_rate callbacks, these are dummy at the moment, and can be used to get/set clock for various devices based on the clk id.

---
Changes since v3:
* No changes.
Changes since v2:
* No changes.
Changes since previous version:
* Removed premature initialization to avoid compiler warnings.

---
  drivers/clk/owl/clk_owl.c | 26 ++++++++++++++++++++++++++
  1 file changed, 26 insertions(+)
drivers/clk/owl/clk_owl.c +0 -0
index 96ab7fed1f37..f78e5fa3f08d 100644

drivers/clk/owl/clk_owl.c int owl_clk_disable(struct clk *clk) · line 137

Quoted 10 lines
drivers/clk/owl/clk_owl.c +7 -0
@@ -128,6 +128,30 @@ int owl_clk_disable(struct clk *clk)
  	return 0;
  }
 
+static ulong owl_clk_get_rate(struct clk *clk)
+{
+	ulong rate;
+
+	switch (clk->id) {
+	default:
+		return -ENOENT;

-ENOSYS please

drivers/clk/owl/clk_owl.c int owl_clk_disable(struct clk *clk) · line 149

Quoted 12 lines
drivers/clk/owl/clk_owl.c +12 -0
+	}
+
+	return rate;
+}
+
+static ulong owl_clk_set_rate(struct clk *clk, ulong rate)
+{
+	ulong new_rate;
+
+	switch (clk->id) {
+	default:
+		return -ENOENT;

ditto

Quoted 10 lines
drivers/clk/owl/clk_owl.c +5 -0
+	}
+
+	return new_rate;
+}
+
  static int owl_clk_probe(struct udevice *dev)
  {
  	struct owl_clk_priv *priv = dev_get_priv(dev);

drivers/clk/owl/clk_owl.c static int owl_clk_probe(struct udevice *dev) · line 176

Quoted 8 lines
drivers/clk/owl/clk_owl.c +2 -0
@@ -145,6 +169,8 @@ static int owl_clk_probe(struct udevice *dev)
  static const struct clk_ops owl_clk_ops = {
  	.enable = owl_clk_enable,
  	.disable = owl_clk_disable,
+	.get_rate = owl_clk_get_rate,
+	.set_rate = owl_clk_set_rate,
  };
 
  static const struct udevice_id owl_clk_ids[] = {

With that fixed,

#5 lore raw

Re: [PATCH v4 2/6] clk: actions: Add SD/MMC clocks

In reply to Amit Singh Tomar
Quoted 29 lines · Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This commit adds SD/MMC clocks, and provides .set/get_rate callbacks for SD/MMC device present on Actions OWL S700 SoCs.

---
Changes since v3:
* No change.
Changes since v2:
* Fixed the weird div assignment.
* Moved the clock bit for SD from header file to driver file.
* Removed "< 0" part while comparing unsigned.
Changes since previous version:
* Removed rate *= 2 as this just overclocks.
* Separated the divide by 128 bit from divider value.
* Provided the separate routine to get sd parent rate based on bit 9.
* Removed unnecessary initialization.

---
  drivers/clk/owl/clk_owl.c | 73 +++++++++++++++++++++++++++++++++++++++
  1 file changed, 73 insertions(+)
drivers/clk/owl/clk_owl.c +0 -0
index f78e5fa3f08d..678fdd5a4540 100644

drivers/clk/owl/clk_owl.c line 23

Quoted 4 lines
drivers/clk/owl/clk_owl.c +1 -0
@@ -20,6 +20,8 @@
  #include <linux/bitops.h>
  #include <linux/delay.h>
 
+#define CMU_DEVCLKEN0_SD0	BIT(22)

Please define this in arch/arm/include/asm/arch-owl/regs_s[79]00.h like CMU_DEVCLKEN1_ETH.

Quoted 28 lines
drivers/clk/owl/clk_owl.c +7 -0
  void owl_clk_init(struct owl_clk_priv *priv)
  {
  	u32 bus_clk = 0, core_pll, dev_pll;
@@ -92,6 +94,9 @@ int owl_clk_enable(struct clk *clk)
  		setbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_ETH);
  		setbits_le32(priv->base + CMU_ETHERNETPLL, 5);
  		break;
+	case CLK_SD0:
+		setbits_le32(priv->base + CMU_DEVCLKEN0, CMU_DEVCLKEN0_SD0);
+		break;
  	default:
  		return -EINVAL;
  	}
@@ -121,6 +126,9 @@ int owl_clk_disable(struct clk *clk)
  	case CLK_ETHERNET:
  		clrbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_ETH);
  		break;
+	case CLK_SD0:
+		clrbits_le32(priv->base + CMU_DEVCLKEN0, CMU_DEVCLKEN0_SD0);
+		break;
  	default:
  		return -EINVAL;
  	}
@@ -128,11 +136,72 @@ int owl_clk_disable(struct clk *clk)
  	return 0;
  }
 
+static ulong get_sd_parent_rate(struct owl_clk_priv *priv, u32 dev_index)

drivers/clk/owl/clk_owl.c int owl_clk_disable(struct clk *clk) · line 149

Quoted 10 lines
drivers/clk/owl/clk_owl.c +10 -0
+{
+	ulong rate;
+	u32 reg;
+
+	reg = readl(priv->base + (CMU_SD0CLK + dev_index * 0x4));
+	/* Clock output of DEV/NAND_PLL
+	 * Range: 48M ~ 756M
+	 * Frequency= PLLCLK * 6
+	 */
+	if (reg & 0x200)

Please add a define for this bit

drivers/clk/owl/clk_owl.c int owl_clk_disable(struct clk *clk) · line 150

Quoted 1 line
drivers/clk/owl/clk_owl.c +1 -0
+		rate = readl(priv->base + CMU_NANDPLL) & 0x7f;

ditto for this mask

Quoted 5 lines
drivers/clk/owl/clk_owl.c +5 -0
+	else
+		rate = readl(priv->base + CMU_DEVPLL) & 0x7f;
+
+	rate *= 6000000;
+

drivers/clk/owl/clk_owl.c int owl_clk_disable(struct clk *clk) · line 165

Quoted 10 lines
drivers/clk/owl/clk_owl.c +10 -0
+	return rate;
+}
+
+static ulong owl_get_sd_clk_rate(struct owl_clk_priv *priv, int sd_index)
+{
+	uint div, val;
+	ulong parent_rate = get_sd_parent_rate(priv, sd_index);
+
+	val = readl(priv->base + (CMU_SD0CLK + sd_index * 0x4));
+	div = (val & 0x1f) + 1;

ditto

Quoted 4 lines
drivers/clk/owl/clk_owl.c +4 -0
+
+	return (parent_rate / div);
+}
+

drivers/clk/owl/clk_owl.c int owl_clk_disable(struct clk *clk) · line 179

Quoted 10 lines
drivers/clk/owl/clk_owl.c +10 -0
+static ulong owl_set_sd_clk_rate(struct owl_clk_priv *priv, ulong rate,
+				 int sd_index)
+{
+	uint div, val;
+	ulong parent_rate = get_sd_parent_rate(priv, sd_index);
+
+	if (rate == 0)
+		return rate;
+
+	div = (parent_rate / rate);

no parentheses needed here

drivers/clk/owl/clk_owl.c int owl_clk_disable(struct clk *clk) · line 184

Quoted 5 lines
drivers/clk/owl/clk_owl.c +5 -0
+
+	val = readl(priv->base + (CMU_SD0CLK + sd_index * 0x4));
+	/* Bits 4..0 is used to program div value and bit 8 to enable
+	 * divide by 128 circuit
+	 */

The comment is good, but please use defines. Additionally, we are not in the net subsystem, so it should be formatted like

	/*
	 * Bits 4..0 is used to program div value and bit 8 to enable
	 * divide by 128 circuit
	 */
Quoted 38 lines
drivers/clk/owl/clk_owl.c +19 -0
+	val &= ~0x11f;
+	if (div >= 128) {
+		div = div / 128;
+		val |= 0x100; /* enable divide by 128 circuit */
+	}
+	val |= ((div - 1) & 0x1f);
+	writel(val, priv->base + (CMU_SD0CLK + sd_index * 0x4));
+
+	return owl_get_sd_clk_rate(priv, 0);
+}
+
  static ulong owl_clk_get_rate(struct clk *clk)
  {
+	struct owl_clk_priv *priv = dev_get_priv(clk->dev);
  	ulong rate;
 
  	switch (clk->id) {
+	case CLK_SD0:
+		rate = owl_get_sd_clk_rate(priv, 0);
+		break;
  	default:
  		return -ENOENT;
  	}
@@ -142,9 +211,13 @@ static ulong owl_clk_get_rate(struct clk *clk)
 
  static ulong owl_clk_set_rate(struct clk *clk, ulong rate)
  {
+	struct owl_clk_priv *priv = dev_get_priv(clk->dev);
  	ulong new_rate;
 
  	switch (clk->id) {
+	case CLK_SD0:
+		new_rate = owl_set_sd_clk_rate(priv, rate, 0);
+		break;
  	default:
  		return -ENOENT;
  	}
#3 lore raw

Re: [PATCH v4 1/6] clk: actions: Introduce dummy get/set_rate callbacks

In reply to Amit Singh Tomar
Quoted 8 lines · Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This commit introduces get/set_rate callbacks, these are dummy at the moment, and can be used to get/set clock for various devices based on the clk id.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#13 lore raw

Re: [PATCH v4 4/6] ARM: dts: s700: add MMC/SD controller node

In reply to Amit Singh Tomar
Quoted 9 lines · Amit Singh Tomar

From: Amit Singh Tomar <[email protected]>

This patch adds node for mmc/sd controller found on Action Semi OWL S700 SoC.

Since, upstream Linux binding has not been merged for S700 MMC/SD controller, Changes are put in u-boot specific dtsi file.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom