Skip to contentSkip to conversation

mmc: sdhci-of-aspeed: Fixes for AST2600 eMMC

PATCH Superseded Andrew Jeffery 2 participants 13 messages Aug 30, 2019 – Sep 2, 2019

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover mmc: sdhci-of-aspeed: Fixes for AST2600 eMMC

Hello,

This series enables the eMMC onboard the AST2600 EVB. There's currently a limitation of running it at 52MHz, I'm still investigating that. Reads and writes are both functional.

The two critical patches (3/5 and 4/5) are on the linux-mmc list and can be found here:

https://patchwork.ozlabs.org/project/linux-aspeed/list/?series=128207&state=%2A&archive=both

Cheers,

Andrew

Andrew Jeffery (4):
mmc: sdhci-of-aspeed: Drop redundant assignment to host->clock
mmc: sdhci-of-aspeed: Uphold clocks-on post-condition of set_clock()
mmc: sdhci-of-aspeed: Allow max-frequency limitation of SDCLK
ARM: dts: ast2600-evb: eMMC configuration

Wei Yongjun (1):
mmc: sdhci-of-aspeed: Fix return value check in aspeed_sdc_probe()

 arch/arm/boot/dts/aspeed-ast2600-evb.dts |  8 ++++++-
 arch/arm/boot/dts/aspeed-g6.dtsi         |  4 ++--
 drivers/mmc/host/sdhci-of-aspeed.c       | 28 ++++++++++++++++--------
 3 files changed, 28 insertions(+), 12 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/5 mmc: sdhci-of-aspeed: Fix return value check in aspeed_sdc_probe()

From: Wei Yongjun <[email protected]>

In case of error, the function of_platform_device_create() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

(cherry picked from commit 7b7de08a14b59d45cc4720bfb21732063ccfc8f6)
---
 drivers/mmc/host/sdhci-of-aspeed.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci-of-aspeed.c +2 -2
index 8bb095ca2fa9..d5acb5afc50f 100644
@@ -261,9 +261,9 @@ static int aspeed_sdc_probe(struct platform_device *pdev)
 		struct platform_device *cpdev;
 
 		cpdev = of_platform_device_create(child, NULL, &pdev->dev);
-		if (IS_ERR(cpdev)) {
+		if (!cpdev) {
 			of_node_put(child);
-			ret = PTR_ERR(cpdev);
+			ret = -ENODEV;
 			goto err_clk;
 		}
 	}
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH linux dev-5.2 1/5] mmc: sdhci-of-aspeed: Fix return value check in aspeed_sdc_probe()

Quoted 7 lines · Andrew Jeffery

From: Wei Yongjun <[email protected]>

In case of error, the function of_platform_device_create() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

Quoted 5 lines
(cherry picked from commit 7b7de08a14b59d45cc4720bfb21732063ccfc8f6)
#3 lore raw

PATCH 2/5 mmc: sdhci-of-aspeed: Drop redundant assignment to host->clock

In reply to Andrew Jeffery

host->clock is already managed by sdhci_set_ios().

---
 drivers/mmc/host/sdhci-of-aspeed.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mmc/host/sdhci-of-aspeed.c +1 -4
index d5acb5afc50f..6ae81c8af431 100644
@@ -61,7 +61,7 @@ static void aspeed_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 	sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
 
 	if (clock == 0)
-		goto out;
+		return;
 
 	for (div = 1; div < 256; div *= 2) {
 		if ((host->max_clk / div) <= clock)
@@ -72,9 +72,6 @@ static void aspeed_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 	clk = div << SDHCI_DIVIDER_SHIFT;
 
 	sdhci_enable_clk(host, clk);
-
-out:
-	host->clock = clock;
 }
 
 static void aspeed_sdhci_set_bus_width(struct sdhci_host *host, int width)
Signature · 1 line
2.20.1
#5 lore raw

Re: [PATCH linux dev-5.2 2/5] mmc: sdhci-of-aspeed: Drop redundant assignment to host->clock

Quoted 11 lines · Joel Stanley
Quoted 5 lines · Andrew Jeffery

host->clock is already managed by sdhci_set_ios().

I assume this went upstream with a fixes tag?

I haven't sent it yet, was waiting for Adrian to review my v1 upstream before sending a v2 with this patch included.

Not sure it needs a fixes tag, but there's no reason it shouldn't have one either. It's just a code cleanup, it doesn't fix a bug.

Andrew

#6 lore raw

PATCH 3/5 mmc: sdhci-of-aspeed: Uphold clocks-on post-condition of set_clock()

In reply to Andrew Jeffery

The early-exit didn't seem to matter on the AST2500, but on the AST2600 the SD clock genuinely may not be running on entry to aspeed_sdhci_set_clock(). Remove the early exit to ensure we always run sdhci_enable_clk().

---
 drivers/mmc/host/sdhci-of-aspeed.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/mmc/host/sdhci-of-aspeed.c +0 -3
index 6ae81c8af431..0b75806ed69d 100644
@@ -55,9 +55,6 @@ static void aspeed_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 	int div;
 	u16 clk;
 
-	if (clock == host->clock)
-		return;
-
 	sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
 
 	if (clock == 0)
Signature · 1 line
2.20.1
maintainer Tested-by on v1 3/5
#7 lore raw

Re: [PATCH linux dev-5.2 3/5] mmc: sdhci-of-aspeed: Uphold clocks-on post-condition of set_clock()

Quoted 7 lines · Andrew Jeffery

The early-exit didn't seem to matter on the AST2500, but on the AST2600 the SD clock genuinely may not be running on entry to aspeed_sdhci_set_clock(). Remove the early exit to ensure we always run sdhci_enable_clk().

I don't quite understand what this was doing in the original patch. The fix is good though, I tested it.

Quoted 21 lines
---
 drivers/mmc/host/sdhci-of-aspeed.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/mmc/host/sdhci-of-aspeed.c +0 -4
index 6ae81c8af431..0b75806ed69d 100644
@@ -55,9 +55,6 @@ static void aspeed_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
        int div;
        u16 clk;
 
-       if (clock == host->clock)
-               return;
-
        sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
 
        if (clock == 0)
--

2.20.1

#8 lore raw

Re: [PATCH linux dev-5.2 3/5] mmc: sdhci-of-aspeed: Uphold clocks-on post-condition of set_clock()

Quoted 11 lines · Joel Stanley
Quoted 7 lines · Andrew Jeffery

The early-exit didn't seem to matter on the AST2500, but on the AST2600 the SD clock genuinely may not be running on entry to aspeed_sdhci_set_clock(). Remove the early exit to ensure we always run sdhci_enable_clk().

I don't quite understand what this was doing in the original patch. The fix is good though, I tested it.

What do you mean? You already had questions about it? Would have been nice to pipe up at the time if so :D

Quoted 2 lines

Thanks,

Andrew

#9 lore raw

PATCH 4/5 mmc: sdhci-of-aspeed: Allow max-frequency limitation of SDCLK

In reply to Andrew Jeffery

Add a get_max_clock() handler to sdhci-of-aspeed to report f_max as the maximum clock rate if it is set. This enables artificial limitation of the bus speed via max-frequency in the devicetree for e.g. the AST2600 evaluation board where I am seeing errors at 200MHz.

---
 drivers/mmc/host/sdhci-of-aspeed.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci-of-aspeed.c +18 -2
index 0b75806ed69d..8962f6664381 100644
@@ -52,16 +52,24 @@ static void aspeed_sdc_configure_8bit_mode(struct aspeed_sdc *sdc,
 
 static void aspeed_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 {
+	struct sdhci_pltfm_host *pltfm_host;
+	unsigned long parent;
 	int div;
 	u16 clk;
 
+	pltfm_host = sdhci_priv(host);
+	parent = clk_get_rate(pltfm_host->clk);
+
 	sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
 
 	if (clock == 0)
 		return;
 
+	if (WARN_ON(clock > host->max_clk))
+		clock = host->max_clk;
+
 	for (div = 1; div < 256; div *= 2) {
-		if ((host->max_clk / div) <= clock)
+		if ((parent / div) <= clock)
 			break;
 	}
 	div >>= 1;
@@ -71,6 +79,14 @@ static void aspeed_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 	sdhci_enable_clk(host, clk);
 }
 
+static unsigned int aspeed_sdhci_get_max_clock(struct sdhci_host *host)
+{
+	if (host->mmc->f_max)
+		return host->mmc->f_max;
+
+	return sdhci_pltfm_clk_get_max_clock(host);
+}
+
 static void aspeed_sdhci_set_bus_width(struct sdhci_host *host, int width)
 {
 	struct sdhci_pltfm_host *pltfm_priv;
@@ -97,7 +113,7 @@ static void aspeed_sdhci_set_bus_width(struct sdhci_host *host, int width)
 
 static const struct sdhci_ops aspeed_sdhci_ops = {
 	.set_clock = aspeed_sdhci_set_clock,
-	.get_max_clock = sdhci_pltfm_clk_get_max_clock,
+	.get_max_clock = aspeed_sdhci_get_max_clock,
 	.set_bus_width = aspeed_sdhci_set_bus_width,
 	.get_timeout_clock = sdhci_pltfm_clk_get_max_clock,
 	.reset = sdhci_reset,
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 4/5
#10 lore raw

Re: [PATCH linux dev-5.2 4/5] mmc: sdhci-of-aspeed: Allow max-frequency limitation of SDCLK

Quoted 7 lines · Andrew Jeffery

Add a get_max_clock() handler to sdhci-of-aspeed to report f_max as the maximum clock rate if it is set. This enables artificial limitation of the bus speed via max-frequency in the devicetree for e.g. the AST2600 evaluation board where I am seeing errors at 200MHz.

#11 lore raw

PATCH 5/5 ARM: dts: ast2600-evb: eMMC configuration

In reply to Andrew Jeffery

Enable the eMMC controller and limit it to 52MHz to avoid the host controller reporting error conditions.

---
 arch/arm/boot/dts/aspeed-ast2600-evb.dts | 8 +++++++-
 arch/arm/boot/dts/aspeed-g6.dtsi         | 4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)
arch/arm/boot/dts/aspeed-ast2600-evb.dts +7 -1
index 2cb92d2a1041..9613cff2ce3a 100644
@@ -39,8 +39,14 @@
 	phy-handle = <&ethphy1>;
 };
 
+&emmc_controller {
+	status = "okay";
+};
+
 &emmc {
-	status = "disabled";
+	non-removable;
+	bus-width = <4>;
+	max-frequency = <52000000>;
 };
 
 &fsim0 {
arch/arm/boot/dts/aspeed-g6.dtsi +2 -2
index d0507f797981..12569e502678 100644
@@ -235,7 +235,7 @@
 				};
 			};
 
-			emmc: sdc@1e750000 {
+			emmc_controller: sdc@1e750000 {
 				compatible = "aspeed,ast2600-sd-controller";
 				reg = <0x1e750000 0x100>;
 				#address-cells = <1>;
@@ -244,7 +244,7 @@
 				clocks = <&syscon ASPEED_CLK_GATE_EMMCCLK>;
 				status = "disabled";
 
-				sdhci@1e750100 {
+				emmc: sdhci@1e750100 {
 					compatible = "aspeed,ast2600-sdhci";
 					reg = <0x100 0x100>;
 					sdhci,auto-cmd12;
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 5/5
#12 lore raw

Re: [PATCH linux dev-5.2 5/5] ARM: dts: ast2600-evb: eMMC configuration

Quoted 5 lines · Andrew Jeffery

Enable the eMMC controller and limit it to 52MHz to avoid the host controller reporting error conditions.

Naming is hard :/

Quoted 50 lines
---
 arch/arm/boot/dts/aspeed-ast2600-evb.dts | 8 +++++++-
 arch/arm/boot/dts/aspeed-g6.dtsi         | 4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)
arch/arm/boot/dts/aspeed-ast2600-evb.dts +7 -1
index 2cb92d2a1041..9613cff2ce3a 100644
@@ -39,8 +39,14 @@
        phy-handle = <&ethphy1>;
 };
 
+&emmc_controller {
+       status = "okay";
+};
+
 &emmc {
-       status = "disabled";
+       non-removable;
+       bus-width = <4>;
+       max-frequency = <52000000>;
 };
 
 &fsim0 {
arch/arm/boot/dts/aspeed-g6.dtsi +2 -3
index d0507f797981..12569e502678 100644
@@ -235,7 +235,7 @@
                                };
                        };
 
-                       emmc: sdc@1e750000 {
+                       emmc_controller: sdc@1e750000 {
                                compatible = "aspeed,ast2600-sd-controller";
                                reg = <0x1e750000 0x100>;
                                #address-cells = <1>;
@@ -244,7 +244,7 @@
                                clocks = <&syscon ASPEED_CLK_GATE_EMMCCLK>;
                                status = "disabled";
 
-                               sdhci@1e750100 {
+                               emmc: sdhci@1e750100 {
                                        compatible = "aspeed,ast2600-sdhci";
                                        reg = <0x100 0x100>;
                                        sdhci,auto-cmd12;
--

2.20.1