Skip to contentSkip to conversation

Enable SD/MMC on JZ4780 SoCs

PATCH In review Ezequiel Garcia 3 participants 19 messages Mar 28, 2018 – Apr 11, 2018

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

v4 cover Enable SD/MMC on JZ4780 SoCs

This patchset adds support for SD/MMC on JZ4780 based platforms, such as the MIPS Creator CI20 board.

Most of the work has been done by Alex, Paul and Zubair, while I've only prepared the upstream submission, cleaned some patches, and written some commit logs where needed.

All praises should go to them, all rants to me.

The series is based on v4.16-rc6.

Changes from v3:
* Replaced callbacks with if/else magic to handle the different register widths on versions of the SoC.

Changes from v2:
* Fix commit log in "mmc: dt-bindings: add MMC support to JZ4740 SoC"

Changes from v1:
* Reordered patches, fixes first, for easier backporting.
* Added Link and Fixes tags to patch "Fix race condition", for easier backporting.
* Enabled the DMA in the dtsi for jz4780, dropped it from the ci20 dts.
* Reworded config and help user visible text.
* Reworded commit logs, using imperative.
* Re-authored my patches, as Collabora is partially sponsoring them.

Alex Smith (3):
mmc: jz4740: Fix race condition in IRQ mask update
mmc: jz4740: Set clock rate to mmc->f_max rather than JZ_MMC_CLK_RATE
mmc: jz4740: Add support for the JZ4780

Ezequiel Garcia (10):
mmc: jz4780: Order headers alphabetically
mmc: jz4740: Use dev_get_platdata
mmc: jz4740: Introduce devicetree probe
mmc: dt-bindings: add MMC support to JZ4740 SoC
mmc: jz4740: Use dma_request_chan()
MIPS: dts: jz4780: Add DMA controller node to the devicetree
MIPS: dts: jz4780: Add MMC controller node to the devicetree
MIPS: dts: ci20: Enable MMC in the devicetree
MIPS: configs: ci20: Enable DMA and MMC support
MIPS: configs: ci20: Enable ext4

Paul Cercueil (1):
mmc: jz4740: Fix error exit path in driver's probe

Zubair Lutfullah Kakakhel (1):
mmc: jz4740: Reset the device requesting the interrupt

 Documentation/devicetree/bindings/mmc/jz4740.txt |  38 +++++
 arch/mips/boot/dts/ingenic/ci20.dts              |  34 ++++
 arch/mips/boot/dts/ingenic/jz4780.dtsi           |  52 ++++++
 arch/mips/configs/ci20_defconfig                 |   4 +
 drivers/mmc/host/Kconfig                         |   9 +-
 drivers/mmc/host/jz4740_mmc.c                    | 205 +++++++++++++++--------
 include/dt-bindings/dma/jz4780-dma.h             |  49 ++++++
 7 files changed, 321 insertions(+), 70 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mmc/jz4740.txt
 create mode 100644 include/dt-bindings/dma/jz4780-dma.h
Signature · 1 line
2.16.2
#1 lore raw

PATCH v4 1/15 mmc: jz4740: Fix race condition in IRQ mask update

From: Alex Smith <[email protected]>

A spinlock is held while updating the internal copy of the IRQ mask, but not while writing it to the actual IMASK register. After the lock is released, an IRQ can occur before the IMASK register is written. If handling this IRQ causes the mask to be changed, when the handler returns back to the middle of the first mask update, a stale value will be written to the mask register.

If this causes an IRQ to become unmasked that cannot have its status cleared by writing a 1 to it in the IREG register, e.g. the SDIO IRQ, then we can end up stuck with the same IRQ repeatedly being fired but not handled. Normally the MMC IRQ handler attempts to clear any unexpected IRQs by writing IREG, but for those that cannot be cleared in this way then the IRQ will just repeatedly fire.

This was resulting in lockups after a while of using Wi-Fi on the CI20 (GitHub issue #19).

Resolve by holding the spinlock until after the IMASK register has been updated.

Fixes 61bfbdb85687 ("MMC: Add support for the controller on JZ4740 SoCs.")
---
 drivers/mmc/host/jz4740_mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/jz4740_mmc.c +1 -1
index 712e08d9a45e..a0168e9e4fce 100644
@@ -362,9 +362,9 @@ static void jz4740_mmc_set_irq_enabled(struct jz4740_mmc_host *host,
 		host->irq_mask &= ~irq;
 	else
 		host->irq_mask |= irq;
-	spin_unlock_irqrestore(&host->lock, flags);
 
 	writew(host->irq_mask, host->base + JZ_REG_MMC_IMASK);
+	spin_unlock_irqrestore(&host->lock, flags);
 }
 
 static void jz4740_mmc_clock_enable(struct jz4740_mmc_host *host,
Signature · 1 line
2.16.2
#2 lore raw

PATCH v4 2/15 mmc: jz4740: Fix error exit path in driver's probe

In reply to Ezequiel Garcia

From: Paul Cercueil <[email protected]>

Currently, if jz4740_mmc_request_gpios() fails, the driver tries to release DMA resources. This is wrong because DMA is requested at a later stage.

[Ezequiel: cleanup commit message]
---
 drivers/mmc/host/jz4740_mmc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/mmc/host/jz4740_mmc.c +9 -8
index a0168e9e4fce..97727cd34fc1 100644
@@ -1006,7 +1006,7 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 
 	ret = jz4740_mmc_request_gpios(mmc, pdev);
 	if (ret)
-		goto err_release_dma;
+		goto err_free_host;
 
 	mmc->ops = &jz4740_mmc_ops;
 	mmc->f_min = JZ_MMC_CLK_RATE / 128;
@@ -1038,16 +1038,17 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 	jz4740_mmc_clock_disable(host);
 	timer_setup(&host->timeout_timer, jz4740_mmc_timeout, 0);
 
-	host->use_dma = true;
-	if (host->use_dma && jz4740_mmc_acquire_dma_channels(host) != 0)
-		host->use_dma = false;
+	ret = jz4740_mmc_acquire_dma_channels(host);
+	if (ret == -EPROBE_DEFER)
+		goto err_free_irq;
+	host->use_dma = !ret;
 
 	platform_set_drvdata(pdev, host);
 	ret = mmc_add_host(mmc);
 
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to add mmc host: %d\n", ret);
-		goto err_free_irq;
+		goto err_release_dma;
 	}
 	dev_info(&pdev->dev, "JZ SD/MMC card driver registered\n");
 
@@ -1057,13 +1058,13 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 
 	return 0;
 
+err_release_dma:
+	if (host->use_dma)
+		jz4740_mmc_release_dma_channels(host);
 err_free_irq:
 	free_irq(host->irq, host);
 err_free_gpios:
 	jz4740_mmc_free_gpios(pdev);
-err_release_dma:
-	if (host->use_dma)
-		jz4740_mmc_release_dma_channels(host);
 err_free_host:
 	mmc_free_host(mmc);
 
Signature · 1 line
2.16.2
#3 lore raw

PATCH v4 3/15 mmc: jz4780: Order headers alphabetically

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Just a minor cleanup to order the headers alphabetically. This helps prevent merge conflicts.

---
 drivers/mmc/host/jz4740_mmc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/mmc/host/jz4740_mmc.c +9 -9
index 97727cd34fc1..eb57f514a459 100644
@@ -13,24 +13,24 @@
  *
  */
 
-#include <linux/mmc/host.h>
-#include <linux/mmc/slot-gpio.h>
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
 #include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/irq.h>
-#include <linux/interrupt.h>
+#include <linux/mmc/host.h>
+#include <linux/mmc/slot-gpio.h>
 #include <linux/module.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
-#include <linux/delay.h>
 #include <linux/scatterlist.h>
-#include <linux/clk.h>
 
-#include <linux/bitops.h>
-#include <linux/gpio.h>
 #include <asm/cacheflush.h>
-#include <linux/dma-mapping.h>
-#include <linux/dmaengine.h>
 
 #include <asm/mach-jz4740/dma.h>
 #include <asm/mach-jz4740/jz4740_mmc.h>
Signature · 1 line
2.16.2
#4 lore raw

PATCH v4 4/15 mmc: jz4740: Use dev_get_platdata

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Instead of accessing the platform data pointer directly, use the dev_get_platdata() helper.

---
 drivers/mmc/host/jz4740_mmc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/host/jz4740_mmc.c +3 -3
index eb57f514a459..b11f65077ce7 100644
@@ -926,7 +926,7 @@ static int jz4740_mmc_request_gpio(struct device *dev, int gpio,
 static int jz4740_mmc_request_gpios(struct mmc_host *mmc,
 	struct platform_device *pdev)
 {
-	struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
+	struct jz4740_mmc_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	int ret = 0;
 
 	if (!pdata)
@@ -955,7 +955,7 @@ static int jz4740_mmc_request_gpios(struct mmc_host *mmc,
 
 static void jz4740_mmc_free_gpios(struct platform_device *pdev)
 {
-	struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
+	struct jz4740_mmc_platform_data *pdata = dev_get_platdata(&pdev->dev);
 
 	if (!pdata)
 		return;
@@ -971,7 +971,7 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 	struct jz4740_mmc_host *host;
 	struct jz4740_mmc_platform_data *pdata;
 
-	pdata = pdev->dev.platform_data;
+	pdata = dev_get_platdata(&pdev->dev);
 
 	mmc = mmc_alloc_host(sizeof(struct jz4740_mmc_host), &pdev->dev);
 	if (!mmc) {
Signature · 1 line
2.16.2
#5 lore raw

PATCH v4 5/15 mmc: jz4740: Reset the device requesting the interrupt

In reply to Ezequiel Garcia

From: Zubair Lutfullah Kakakhel <[email protected]>

In case a bootloader leaves the device in a bad state, requesting the interrupt before resetting results in a bad interrupt loop.

---
 drivers/mmc/host/jz4740_mmc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/jz4740_mmc.c +2 -1
index b11f65077ce7..9f316d953b30 100644
@@ -1027,6 +1027,8 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 	spin_lock_init(&host->lock);
 	host->irq_mask = 0xffff;
 
+	jz4740_mmc_reset(host);
+
 	ret = request_threaded_irq(host->irq, jz_mmc_irq, jz_mmc_irq_worker, 0,
 			dev_name(&pdev->dev), host);
 	if (ret) {
@@ -1034,7 +1036,6 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 		goto err_free_gpios;
 	}
 
-	jz4740_mmc_reset(host);
 	jz4740_mmc_clock_disable(host);
 	timer_setup(&host->timeout_timer, jz4740_mmc_timeout, 0);
 
Signature · 1 line
2.16.2
#6 lore raw

PATCH v4 6/15 mmc: jz4740: Introduce devicetree probe

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Add support to probe the device via devicetree, which will be used to support other SoCs such as the JZ4780.

Based on commits from the CI20 repo, by Paul Cercueil and Alex Smith. Binding document based on work by Zubair Lutfullah Kakakhel.

---
 drivers/mmc/host/jz4740_mmc.c | 51 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 41 insertions(+), 10 deletions(-)
drivers/mmc/host/jz4740_mmc.c +41 -10
index 9f316d953b30..03757cc55f52 100644
@@ -26,6 +26,7 @@
 #include <linux/mmc/host.h>
 #include <linux/mmc/slot-gpio.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/scatterlist.h>
@@ -107,6 +108,10 @@
 
 #define JZ_MMC_CLK_RATE 24000000
 
+enum jz4740_mmc_version {
+	JZ_MMC_JZ4740,
+};
+
 enum jz4740_mmc_state {
 	JZ4740_MMC_STATE_READ_RESPONSE,
 	JZ4740_MMC_STATE_TRANSFER_DATA,
@@ -125,6 +130,8 @@ struct jz4740_mmc_host {
 	struct jz4740_mmc_platform_data *pdata;
 	struct clk *clk;
 
+	enum jz4740_mmc_version version;
+
 	int irq;
 	int card_detect_irq;
 
@@ -857,7 +864,7 @@ static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 	switch (ios->power_mode) {
 	case MMC_POWER_UP:
 		jz4740_mmc_reset(host);
-		if (gpio_is_valid(host->pdata->gpio_power))
+		if (host->pdata && gpio_is_valid(host->pdata->gpio_power))
 			gpio_set_value(host->pdata->gpio_power,
 					!host->pdata->power_active_low);
 		host->cmdat |= JZ_MMC_CMDAT_INIT;
@@ -866,7 +873,7 @@ static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 	case MMC_POWER_ON:
 		break;
 	default:
-		if (gpio_is_valid(host->pdata->gpio_power))
+		if (host->pdata && gpio_is_valid(host->pdata->gpio_power))
 			gpio_set_value(host->pdata->gpio_power,
 					host->pdata->power_active_low);
 		clk_disable_unprepare(host->clk);
@@ -964,11 +971,18 @@ static void jz4740_mmc_free_gpios(struct platform_device *pdev)
 		gpio_free(pdata->gpio_power);
 }
 
+static const struct of_device_id jz4740_mmc_of_match[] = {
+	{ .compatible = "ingenic,jz4740-mmc", .data = (void *) JZ_MMC_JZ4740 },
+	{},
+};
+MODULE_DEVICE_TABLE(of, jz4740_mmc_of_match);
+
 static int jz4740_mmc_probe(struct platform_device* pdev)
 {
 	int ret;
 	struct mmc_host *mmc;
 	struct jz4740_mmc_host *host;
+	const struct of_device_id *match;
 	struct jz4740_mmc_platform_data *pdata;
 
 	pdata = dev_get_platdata(&pdev->dev);
@@ -982,6 +996,27 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 	host = mmc_priv(mmc);
 	host->pdata = pdata;
 
+	match = of_match_device(jz4740_mmc_of_match, &pdev->dev);
+	if (match) {
+		host->version = (enum jz4740_mmc_version)match->data;
+		ret = mmc_of_parse(mmc);
+		if (ret) {
+			if (ret != -EPROBE_DEFER)
+				dev_err(&pdev->dev,
+					"could not parse of data: %d\n", ret);
+			goto err_free_host;
+		}
+	} else {
+		/* JZ4740 should be the only one using legacy probe */
+		host->version = JZ_MMC_JZ4740;
+		mmc->caps |= MMC_CAP_SDIO_IRQ;
+		if (!(pdata && pdata->data_1bit))
+			mmc->caps |= MMC_CAP_4_BIT_DATA;
+		ret = jz4740_mmc_request_gpios(mmc, pdev);
+		if (ret)
+			goto err_free_host;
+	}
+
 	host->irq = platform_get_irq(pdev, 0);
 	if (host->irq < 0) {
 		ret = host->irq;
@@ -1004,16 +1039,11 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
 		goto err_free_host;
 	}
 
-	ret = jz4740_mmc_request_gpios(mmc, pdev);
-	if (ret)
-		goto err_free_host;
-
 	mmc->ops = &jz4740_mmc_ops;
-	mmc->f_min = JZ_MMC_CLK_RATE / 128;
-	mmc->f_max = JZ_MMC_CLK_RATE;
+	if (!mmc->f_max)
+		mmc->f_max = JZ_MMC_CLK_RATE;
+	mmc->f_min = mmc->f_max / 128;
 	mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
-	mmc->caps = (pdata && pdata->data_1bit) ? 0 : MMC_CAP_4_BIT_DATA;
-	mmc->caps |= MMC_CAP_SDIO_IRQ;
 
 	mmc->max_blk_size = (1 << 10) - 1;
 	mmc->max_blk_count = (1 << 15) - 1;
@@ -1118,6 +1148,7 @@ static struct platform_driver jz4740_mmc_driver = {
 	.remove = jz4740_mmc_remove,
 	.driver = {
 		.name = "jz4740-mmc",
+		.of_match_table = of_match_ptr(jz4740_mmc_of_match),
 		.pm = JZ4740_MMC_PM_OPS,
 	},
 };
Signature · 1 line
2.16.2
#7 lore raw

PATCH v4 7/15 mmc: dt-bindings: add MMC support to JZ4740 SoC

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Add the devicetree binding for JZ4740/JZ4780 SoC MMC/SD controller.

---
 Documentation/devicetree/bindings/mmc/jz4740.txt | 38 ++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/jz4740.txt
Documentation/devicetree/bindings/mmc/jz4740.txt new file +38 -0
new file mode 100644
index 000000000000..7cd8c432d7c8
@@ -0,0 +1,38 @@
+* Ingenic JZ47xx MMC controllers
+
+This file documents the device tree properties used for the MMC controller in
+Ingenic JZ4740/JZ4780 SoCs. These are in addition to the core MMC properties
+described in mmc.txt.
+
+Required properties:
+- compatible: Should be one of the following:
+  - "ingenic,jz4740-mmc" for the JZ4740
+  - "ingenic,jz4780-mmc" for the JZ4780
+- reg: Should contain the MMC controller registers location and length.
+- interrupts: Should contain the interrupt specifier of the MMC controller.
+- clocks: Clock for the MMC controller.
+
+Optional properties:
+- dmas: List of DMA specifiers with the controller specific format
+        as described in the generic DMA client binding. A tx and rx
+        specifier is required.
+- dma-names: RX and TX  DMA request names.
+        Should be "rx" and "tx", in that order.
+
+For additional details on DMA client bindings see ../dma/dma.txt.
+
+Example:
+
+mmc0: mmc@13450000 {
+	compatible = "ingenic,jz4780-mmc";
+	reg = <0x13450000 0x1000>;
+
+	interrupt-parent = <&intc>;
+	interrupts = <37>;
+
+	clocks = <&cgu JZ4780_CLK_MSC0>;
+	clock-names = "mmc";
+
+	dmas = <&dma JZ4780_DMA_MSC0_RX 0xffffffff>, <&dma JZ4780_DMA_MSC0_TX 0xffffffff>;
+	dma-names = "rx", "tx";
+};
Signature · 1 line
2.16.2
#8 lore raw

PATCH v4 8/15 mmc: jz4740: Set clock rate to mmc->f_max rather than JZ_MMC_CLK_RATE

In reply to Ezequiel Garcia

From: Alex Smith <[email protected]>

The maximum clock rate can be overridden by DT. The clock rate should be set to the DT-specified value rather than the constant JZ_MMC_CLK_RATE when this is done. If the maximum clock rate is not set by DT then mmc->f_max will be set to JZ_MMC_CLK_RATE.

---
 drivers/mmc/host/jz4740_mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/jz4740_mmc.c +1 -1
index 03757cc55f52..aa635b458d2c 100644
@@ -825,7 +825,7 @@ static int jz4740_mmc_set_clock_rate(struct jz4740_mmc_host *host, int rate)
 	int real_rate;
 
 	jz4740_mmc_clock_disable(host);
-	clk_set_rate(host->clk, JZ_MMC_CLK_RATE);
+	clk_set_rate(host->clk, host->mmc->f_max);
 
 	real_rate = clk_get_rate(host->clk);
 
Signature · 1 line
2.16.2
#9 lore raw

PATCH v4 9/15 mmc: jz4740: Add support for the JZ4780

In reply to Ezequiel Garcia

From: Alex Smith <[email protected]>

Add support for the JZ4780 MMC controller to the jz47xx_mmc driver. There are a few minor differences from the 4740 to the 4780 that need to be handled, but otherwise the controllers behave the same. The IREG and IMASK registers are expanded to 32 bits. Additionally, some error conditions are now reported in both STATUS and IREG. Writing IREG before reading STATUS causes the bits in STATUS to be cleared, so STATUS must be read first to ensure we see and report error conditions correctly.

---
 drivers/mmc/host/Kconfig      |  9 +++--
 drivers/mmc/host/jz4740_mmc.c | 86 +++++++++++++++++++++++++++++++++----------
 2 files changed, 72 insertions(+), 23 deletions(-)
drivers/mmc/host/Kconfig +5 -4
index 620c2d90a646..35a5a5ad65b9 100644
@@ -766,11 +766,12 @@ config MMC_SH_MMCIF
 
 
 config MMC_JZ4740
-	tristate "JZ4740 SD/Multimedia Card Interface support"
-	depends on MACH_JZ4740
+	tristate "Ingenic JZ47xx SD/Multimedia Card Interface support"
+	depends on MACH_JZ4740 || MACH_JZ4780
 	help
-	  This selects support for the SD/MMC controller on Ingenic JZ4740
-	  SoCs.
+	  This selects support for the SD/MMC controller on Ingenic
+	  JZ4740, JZ4750, JZ4770 and JZ4780 SoCs.
+
 	  If you have a board based on such a SoC and with a SD/MMC slot,
 	  say Y or M here.
 
drivers/mmc/host/jz4740_mmc.c +67 -19

197 lines not on this page · raw message

Signature · 1 line
2.16.2
#10 lore raw

PATCH v4 10/15 mmc: jz4740: Use dma_request_chan()

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Replace dma_request_channel() with dma_request_chan(), which also supports probing from the devicetree.

---
 drivers/mmc/host/jz4740_mmc.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/mmc/host/jz4740_mmc.c +7 -15
index 5d3efd59bda1..993386c9ea50 100644
@@ -213,31 +213,23 @@ static void jz4740_mmc_release_dma_channels(struct jz4740_mmc_host *host)
 
 static int jz4740_mmc_acquire_dma_channels(struct jz4740_mmc_host *host)
 {
-	dma_cap_mask_t mask;
-
-	dma_cap_zero(mask);
-	dma_cap_set(DMA_SLAVE, mask);
-
-	host->dma_tx = dma_request_channel(mask, NULL, host);
-	if (!host->dma_tx) {
+	host->dma_tx = dma_request_chan(mmc_dev(host->mmc), "tx");
+	if (IS_ERR(host->dma_tx)) {
 		dev_err(mmc_dev(host->mmc), "Failed to get dma_tx channel\n");
-		return -ENODEV;
+		return PTR_ERR(host->dma_tx);
 	}
 
-	host->dma_rx = dma_request_channel(mask, NULL, host);
-	if (!host->dma_rx) {
+	host->dma_rx = dma_request_chan(mmc_dev(host->mmc), "rx");
+	if (IS_ERR(host->dma_rx)) {
 		dev_err(mmc_dev(host->mmc), "Failed to get dma_rx channel\n");
-		goto free_master_write;
+		dma_release_channel(host->dma_tx);
+		return PTR_ERR(host->dma_rx);
 	}
 
 	/* Initialize DMA pre request cookie */
 	host->next_data.cookie = 1;
 
 	return 0;
-
-free_master_write:
-	dma_release_channel(host->dma_tx);
-	return -ENODEV;
 }
 
 static inline struct dma_chan *jz4740_mmc_get_dma_chan(struct jz4740_mmc_host *host,
Signature · 1 line
2.16.2
#11 lore raw

PATCH v4 11/15 MIPS: dts: jz4780: Add DMA controller node to the devicetree

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Add the devicetree node to support the DMA controller found in JZ480 SoCs.

---
 arch/mips/boot/dts/ingenic/jz4780.dtsi | 12 +++++++++
 include/dt-bindings/dma/jz4780-dma.h   | 49 ++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 include/dt-bindings/dma/jz4780-dma.h
arch/mips/boot/dts/ingenic/jz4780.dtsi +12 -0
index 9b5794667aee..15a9801430bd 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <dt-bindings/clock/jz4780-cgu.h>
+#include <dt-bindings/dma/jz4780-dma.h>
 
 / {
 	#address-cells = <1>;
@@ -241,6 +242,17 @@
 		status = "disabled";
 	};
 
+	dma: dma@13420000 {
+		compatible = "ingenic,jz4780-dma";
+		reg = <0x13420000 0x10000>;
+		#dma-cells = <2>;
+
+		interrupt-parent = <&intc>;
+		interrupts = <10>;
+
+		clocks = <&cgu JZ4780_CLK_PDMA>;
+	};
+
 	bch: bch@134d0000 {
 		compatible = "ingenic,jz4780-bch";
 		reg = <0x134d0000 0x10000>;
include/dt-bindings/dma/jz4780-dma.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.16.2
#12 lore raw

PATCH v4 12/15 MIPS: dts: jz4780: Add MMC controller node to the devicetree

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Add the devicetree node to support the MMC host controller available in JZ480 SoCs.

---
 arch/mips/boot/dts/ingenic/jz4780.dtsi | 40 ++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
arch/mips/boot/dts/ingenic/jz4780.dtsi +40 -0
index 15a9801430bd..b72e53bb7292 100644
@@ -253,6 +253,46 @@
 		clocks = <&cgu JZ4780_CLK_PDMA>;
 	};
 
+	mmc0: mmc@13450000 {
+		compatible = "ingenic,jz4780-mmc";
+		reg = <0x13450000 0x1000>;
+
+		interrupt-parent = <&intc>;
+		interrupts = <37>;
+
+		clocks = <&cgu JZ4780_CLK_MSC0>;
+		clock-names = "mmc";
+
+		cap-sd-highspeed;
+		cap-mmc-highspeed;
+		cap-sdio-irq;
+		dmas = <&dma JZ4780_DMA_MSC0_RX 0xffffffff>,
+		       <&dma JZ4780_DMA_MSC0_TX 0xffffffff>;
+		dma-names = "rx", "tx";
+
+		status = "disabled";
+	};
+
+	mmc1: mmc@13460000 {
+		compatible = "ingenic,jz4780-mmc";
+		reg = <0x13460000 0x1000>;
+
+		interrupt-parent = <&intc>;
+		interrupts = <36>;
+
+		clocks = <&cgu JZ4780_CLK_MSC1>;
+		clock-names = "mmc";
+
+		cap-sd-highspeed;
+		cap-mmc-highspeed;
+		cap-sdio-irq;
+		dmas = <&dma JZ4780_DMA_MSC1_RX 0xffffffff>,
+		       <&dma JZ4780_DMA_MSC1_TX 0xffffffff>;
+		dma-names = "rx", "tx";
+
+		status = "disabled";
+	};
+
 	bch: bch@134d0000 {
 		compatible = "ingenic,jz4780-bch";
 		reg = <0x134d0000 0x10000>;
Signature · 1 line
2.16.2
#13 lore raw

PATCH v4 13/15 MIPS: dts: ci20: Enable MMC in the devicetree

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Now that we have support for JZ480 SoCs in the MMC driver, let's enable it on the devicetree.

---
 arch/mips/boot/dts/ingenic/ci20.dts | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
arch/mips/boot/dts/ingenic/ci20.dts +34 -0
index a4cc52214dbd..0ab5f59a56dc 100644
@@ -36,6 +36,28 @@
 	clock-frequency = <48000000>;
 };
 
+&mmc0 {
+	status = "okay";
+
+	bus-width = <4>;
+	max-frequency = <50000000>;
+
+	pinctrl-names = "default";
+	pinctrl-0 = <&pins_mmc0>;
+
+	cd-gpios = <&gpf 20 GPIO_ACTIVE_LOW>;
+};
+
+&mmc1 {
+	status = "okay";
+
+	bus-width = <4>;
+	max-frequency = <50000000>;
+
+	pinctrl-names = "default";
+	pinctrl-0 = <&pins_mmc1>;
+};
+
 &uart0 {
 	status = "okay";
 
@@ -203,4 +225,16 @@
 		groups = "nemc-cs6";
 		bias-disable;
 	};
+
+	pins_mmc0: mmc0 {
+		function = "mmc0";
+		groups = "mmc0-1bit-e", "mmc0-4bit-e";
+		bias-disable;
+	};
+
+	pins_mmc1: mmc1 {
+		function = "mmc1";
+		groups = "mmc1-1bit-d", "mmc1-4bit-d";
+		bias-disable;
+	};
 };
Signature · 1 line
2.16.2
#14 lore raw

PATCH v4 14/15 MIPS: configs: ci20: Enable DMA and MMC support

In reply to Ezequiel Garcia

From: Ezequiel Garcia <[email protected]>

Enable the SD/MMC support, along with DMA engine support in the CI20 defconfig.

---
 arch/mips/configs/ci20_defconfig | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/configs/ci20_defconfig +3 -0
index b5f4ad8f2c45..f88b05fd3077 100644
@@ -104,8 +104,11 @@ CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_HID is not set
 # CONFIG_USB_SUPPORT is not set
 CONFIG_MMC=y
+CONFIG_MMC_JZ4740=y
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_JZ4740=y
+CONFIG_DMADEVICES=y
+CONFIG_DMA_JZ4780=y
 # CONFIG_IOMMU_SUPPORT is not set
 CONFIG_MEMORY=y
 # CONFIG_DNOTIFY is not set
Signature · 1 line
2.16.2
#15 lore raw

PATCH v4 15/15 MIPS: configs: ci20: Enable ext4

In reply to Ezequiel Garcia

Now that we have MMC support, enable ext2/3/4 support in the CI20 defconfig.

---
 arch/mips/configs/ci20_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/mips/configs/ci20_defconfig +1 -0
index f88b05fd3077..be23fd25eeaa 100644
@@ -111,6 +111,7 @@ CONFIG_DMADEVICES=y
 CONFIG_DMA_JZ4780=y
 # CONFIG_IOMMU_SUPPORT is not set
 CONFIG_MEMORY=y
+CONFIG_EXT4_FS=y
 # CONFIG_DNOTIFY is not set
 CONFIG_PROC_KCORE=y
 # CONFIG_PROC_PAGE_MONITOR is not set
Signature · 1 line
2.16.2
#17 lore raw

Re: [PATCH v4 15/15] MIPS: configs: ci20: Enable ext4

In reply to Ezequiel Garcia
Quoted 4 lines · Ezequiel Garcia

Now that we have MMC support, enable ext2/3/4 support in the CI20 defconfig.

Thanks, queued for 4.18!

Kind regards
Uffe

Quoted 19 lines
---
 arch/mips/configs/ci20_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/mips/configs/ci20_defconfig +1 -1
index f88b05fd3077..be23fd25eeaa 100644
@@ -111,6 +111,7 @@ CONFIG_DMADEVICES=y
 CONFIG_DMA_JZ4780=y
 # CONFIG_IOMMU_SUPPORT is not set
 CONFIG_MEMORY=y
+CONFIG_EXT4_FS=y
 # CONFIG_DNOTIFY is not set
 CONFIG_PROC_KCORE=y
 # CONFIG_PROC_PAGE_MONITOR is not set
--

2.16.2

#18 lore raw
In reply to Ezequiel Garcia
Quoted 10 lines · Ezequiel Garcia

This patchset adds support for SD/MMC on JZ4780 based platforms, such as the MIPS Creator CI20 board.

Most of the work has been done by Alex, Paul and Zubair, while I've only prepared the upstream submission, cleaned some patches, and written some commit logs where needed.

All praises should go to them, all rants to me.

The series is based on v4.16-rc6.

I have queued up this series for 4.18, with the following exceptions. *) Patch 1, which I applied as fix for 3.17.
**) Patch 15, deferred until James acks it.

Thanks and kind regards
Uffe

Quoted 56 lines

Changes from v3:
* Replaced callbacks with if/else magic to handle the different register widths on versions of the SoC.

Changes from v2:
* Fix commit log in "mmc: dt-bindings: add MMC support to JZ4740 SoC"

Changes from v1:
* Reordered patches, fixes first, for easier backporting.
* Added Link and Fixes tags to patch "Fix race condition", for easier backporting.
* Enabled the DMA in the dtsi for jz4780, dropped it from the ci20 dts.
* Reworded config and help user visible text.
* Reworded commit logs, using imperative.
* Re-authored my patches, as Collabora is partially sponsoring them.

Alex Smith (3):
mmc: jz4740: Fix race condition in IRQ mask update
mmc: jz4740: Set clock rate to mmc->f_max rather than JZ_MMC_CLK_RATE
mmc: jz4740: Add support for the JZ4780

Ezequiel Garcia (10):
mmc: jz4780: Order headers alphabetically
mmc: jz4740: Use dev_get_platdata
mmc: jz4740: Introduce devicetree probe
mmc: dt-bindings: add MMC support to JZ4740 SoC
mmc: jz4740: Use dma_request_chan()
MIPS: dts: jz4780: Add DMA controller node to the devicetree
MIPS: dts: jz4780: Add MMC controller node to the devicetree
MIPS: dts: ci20: Enable MMC in the devicetree
MIPS: configs: ci20: Enable DMA and MMC support
MIPS: configs: ci20: Enable ext4

Paul Cercueil (1):
mmc: jz4740: Fix error exit path in driver's probe

Zubair Lutfullah Kakakhel (1):
mmc: jz4740: Reset the device requesting the interrupt

 Documentation/devicetree/bindings/mmc/jz4740.txt |  38 +++++
 arch/mips/boot/dts/ingenic/ci20.dts              |  34 ++++
 arch/mips/boot/dts/ingenic/jz4780.dtsi           |  52 ++++++
 arch/mips/configs/ci20_defconfig                 |   4 +
 drivers/mmc/host/Kconfig                         |   9 +-
 drivers/mmc/host/jz4740_mmc.c                    | 205 +++++++++++++++--------
 include/dt-bindings/dma/jz4780-dma.h             |  49 ++++++
 7 files changed, 321 insertions(+), 70 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mmc/jz4740.txt
 create mode 100644 include/dt-bindings/dma/jz4780-dma.h

--
2.16.2