Skip to contentSkip to conversation

socfpga: Enable SD/MMC support

PATCH Superseded dinguyen at altera.com 2 participants 6 messages Oct 17, 2013

Subsystems (5)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

cover socfpga: Enable SD/MMC support

From: Dinh Nguyen <[email protected]>

Hi,

This patch series enables support for the Synopsys SD/MMC driver that is on the Altera SOCFPGA platform. The reason why this series has 4 patches is to implement Arnd's suggestion:

http://lists.infradead.org/pipermail/linux-arm-kernel/2013-October/204982.html

To summarize Arnd's suggestion:

1. Create a backend syscon driver to control the system manager.
2. Create a clock driver independent of the SOCFPGA clock driver that uses syscon as the low-level interface.
3. Make the sdmmc driver use the normal clock API and link its clock to the driver step 2 in the device tree.

The end approach is a bit different because I did not find the need for a syscon driver for the system manager. Since the system manager had already been iomap already in the SOCFPGA platform code, I just reused it in the new clock driver.

Patch 1/4: clk: socfpga: Add a clock driver for SOCFPGA's system manager This patch adds a clk-sysmgr driver that can be use by a common clock API to set system manager register bits needed by the SD/MMC driver. The SD/MMC driver can simply call a common clock API to set the required clock phase settings for the SD/MMC CIU.

Patch 2/4: arm: dts: Add a system manager compatible property This patch adds a DTS compatible entry for the new clk-sysmgr driver.

Patch 3/4: mmc: dw_mmc-socfpga: Clean up SOCFPGA platform specific functionality This patch cleans up dw_mmc-socpfga.c file from defines that are outside of the SD/MMC IP. It makes the common clock API call to set the SD/MMC clock phase settings in the system manager.

Patch 4/4: arm: dts: Add support for SD/MMC on SOCFPGA
This patch adds the necessary DTS bindings for the SOCFPGA specific extensions to the base Synopsys DW SD/MMC driver.

Thanks,
Dinh

Dinh Nguyen (4):
clk: socfpga: Add a clock driver for SOCFPGA's system manager
arm: dts: Add a system manager compatible property
mmc: dw_mmc-socfpga: Clean up SOCFPGA platform specific functionality
arm: dts: Add support for SD/MMC on SOCFPGA

 .../bindings/arm/altera/socfpga-system.txt         |   10 +++
 .../devicetree/bindings/mmc/socfpga-dw-mshc.txt    |   38 ++++++++
 arch/arm/boot/dts/socfpga.dtsi                     |   23 ++++-
 arch/arm/boot/dts/socfpga_cyclone5.dts             |   12 +++
 arch/arm/boot/dts/socfpga_vt.dts                   |   12 +++
 drivers/clk/socfpga/Makefile                       |    2 +-
 drivers/clk/socfpga/clk-ysmgr.c                   |   91 ++++++++++++++++++++
 drivers/mmc/host/dw_mmc-socfpga.c                  |   80 +++--------------
 8 files changed, 195 insertions(+), 73 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mmc/socfpga-dw-mshc.txt
 create mode 100644 drivers/clk/socfpga/clk-sysmgr.c

---
Cc: Pavel Machek <[email protected]>
CC: Arnd Bergmann <[email protected]>
Cc: Mike Turquette <[email protected]>
CC: Olof Johansson <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Pawel Moll <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Stephen Warren <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Chris Ball <[email protected]>
Cc: Jaehoon Chung <[email protected]>
Cc: Seungwon Jeon <[email protected]>
Cc: devicetree at vger.kernel.org
Cc: linux-mmc at vger.kernel.org
CC: linux-arm-kernel at lists.infradead.org

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/4 clk: socfpga: Add a clock driver for SOCFPGA's system manager

From: Dinh Nguyen <[email protected]>

The system manager is an IP block on the SOCFPGA platform. The system manager contains registers that control other IPs on the platform. One of them is the SD/MMC IP. The system manager contains a register that controls the clock phase of the SD/MMC CIU.

This patch adds a clock driver that the SD/MMC driver can use by calling the common clock API in order to set the appropriate register in the system manager.

Cc Pavel Machek <[email protected]>
CC Arnd Bergmann <[email protected]>
Cc Mike Turquette <[email protected]>
CC Olof Johansson <[email protected]>
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Chris Ball <[email protected]>
Cc Jaehoon Chung <[email protected]>
Cc Seungwon Jeon <[email protected]>
Cc devicetree at vger.kernel.org
Cc linux-mmc at vger.kernel.org
CC linux-arm-kernel at lists.infradead.org
---
 drivers/clk/socfpga/Makefile     |    2 +-
 drivers/clk/socfpga/clk-sysmgr.c |   91 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/socfpga/clk-sysmgr.c
drivers/clk/socfpga/Makefile +1 -1
index 0303c0b..cfceabc 100644
@@ -1 +1 @@
-obj-y += clk.o
+obj-y += clk.o clk-sysmgr.o
drivers/clk/socfpga/clk-sysmgr.c new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/4 arm: dts: Add a system manager compatible property

In reply to dinguyen at altera.com

From: Dinh Nguyen <[email protected]>

The "altr,sysmgr-sdmmc-sdr" compatible property is used for the SOCFPGA clk-sysmgr driver. This property represents the register inside the system manager that controls the clock phase of the SD/MMC driver.

Cc Pavel Machek <[email protected]>
CC Arnd Bergmann <[email protected]>
Cc Mike Turquette <[email protected]>
CC Olof Johansson <[email protected]>
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Chris Ball <[email protected]>
Cc Jaehoon Chung <[email protected]>
Cc Seungwon Jeon <[email protected]>
Cc devicetree at vger.kernel.org
Cc linux-mmc at vger.kernel.org
CC linux-arm-kernel at lists.infradead.org
---
 .../bindings/arm/altera/socfpga-system.txt         |   10 ++++++++++
 arch/arm/boot/dts/socfpga.dtsi                     |   12 ++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/arm/altera/socfpga-system.txt +10 -0
index f4d04a0..7a6c7ed 100644
@@ -5,9 +5,19 @@ Required properties:
 - reg : Should contain 1 register ranges(address and length)
 - cpu1-start-addr : CPU1 start address in hex.
 
+Optional properties:
+- compatible = "altr,sysmgr-sdmmc-sdr". This compatible property is used
+to represent the clock phase settings for the SD/MMC IP.
+
 Example:
 	 sysmgr at ffd08000 {
 		compatible = "altr,sys-mgr";
 		reg = <0xffd08000 0x1000>;
 		cpu1-start-addr = <0xffd080c4>;
+
+		sysmgr_sdr_mmc: sysmgr_sdr_mmc {
+			#clock-cells = <0>;
+			compatible = "altr,sysmgr-sdmmc-sdr";
+			reg = <0x108 1>;
+		};
 	};
arch/arm/boot/dts/socfpga.dtsi +10 -2
index e273fa9..0662d04 100644
@@ -521,8 +521,16 @@
 			};
 
 		sysmgr at ffd08000 {
-				compatible = "altr,sys-mgr";
-				reg = <0xffd08000 0x4000>;
+			#address-cells = <1>;
+			#size-cells = <1>;
+			compatible = "altr,sys-mgr";
+			reg = <0xffd08000 0x4000>;
+
+			sysmgr_sdr_mmc: sysmgr_sdr_mmc {
+				#clock-cells = <0>;
+				compatible = "altr,sysmgr-sdmmc-sdr";
+				reg = <0x108 1>;
 			};
+		};
 	};
 };
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/4 mmc: dw_mmc-socfpga: Clean up SOCFPGA platform specific functionality

In reply to dinguyen at altera.com

From: Dinh Nguyen <[email protected]>

The SDR timing registers for the SD/MMC IP block for SOCFPGA is located in the system manager. This system manager IP block is located outside of the SD IP block itself. We can use the normal clock API to set the SDR settings.

Also, there is no need for "altr,dw-mshc-ciu-div" as the driver can get the value of the CIU clock from the common clock API.

Cc Pavel Machek <[email protected]>
CC Arnd Bergmann <[email protected]>
Cc Mike Turquette <[email protected]>
CC Olof Johansson <[email protected]>
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Chris Ball <[email protected]>
Cc Jaehoon Chung <[email protected]>
Cc Seungwon Jeon <[email protected]>
Cc devicetree at vger.kernel.org
Cc linux-mmc at vger.kernel.org
CC linux-arm-kernel at lists.infradead.org
---
 drivers/mmc/host/dw_mmc-socfpga.c |   80 +++++--------------------------------
 1 file changed, 10 insertions(+), 70 deletions(-)
drivers/mmc/host/dw_mmc-socfpga.c +10 -70
index 14b5961..8b55929 100644
@@ -13,97 +13,37 @@
  * Taken from dw_mmc-exynos.c
  */
 #include <linux/clk.h>
-#include <linux/mfd/syscon.h>
 #include <linux/mmc/host.h>
 #include <linux/mmc/dw_mmc.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
-#include <linux/regmap.h>
 
 #include "dw_mmc.h"
 #include "dw_mmc-pltfm.h"
 
-#define SYSMGR_SDMMCGRP_CTRL_OFFSET		0x108
-#define DRV_CLK_PHASE_SHIFT_SEL_MASK	0x7
-#define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel)          \
-	((((smplsel) & 0x7) << 3) | (((drvsel) & 0x7) << 0))
-
-/* SOCFPGA implementation specific driver private data */
-struct dw_mci_socfpga_priv_data {
-	u8	ciu_div; /* card interface unit divisor */
-	u32	hs_timing; /* bitmask for CIU clock phase shift */
-	struct regmap   *sysreg; /* regmap for system manager register */
-};
-
-static int dw_mci_socfpga_priv_init(struct dw_mci *host)
-{
-	struct dw_mci_socfpga_priv_data *priv;
-
-	priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		dev_err(host->dev, "mem alloc failed for private data\n");
-		return -ENOMEM;
-	}
-
-	priv->sysreg = syscon_regmap_lookup_by_compatible("altr,sys-mgr");
-	if (IS_ERR(priv->sysreg)) {
-		dev_err(host->dev, "regmap for altr,sys-mgr lookup failed.\n");
-		return PTR_ERR(priv->sysreg);
-	}
-	host->priv = priv;
-
-	return 0;
-}
-
 static int dw_mci_socfpga_setup_clock(struct dw_mci *host)
 {
-	struct dw_mci_socfpga_priv_data *priv = host->priv;
-
-	clk_disable_unprepare(host->ciu_clk);
-	regmap_write(priv->sysreg, SYSMGR_SDMMCGRP_CTRL_OFFSET,
-		priv->hs_timing);
-	clk_prepare_enable(host->ciu_clk);
-
-	host->bus_hz /= (priv->ciu_div + 1);
+	struct clk *sysmgr_clk = devm_clk_get(host->dev, "sysmgr-sdr-mmc");
+
+	if (IS_ERR(sysmgr_clk))
+		dev_dbg(host->dev, "sysmgr-sdr-mmc not available\n");
+	else {
+		clk_disable_unprepare(host->ciu_clk);
+		clk_prepare_enable(sysmgr_clk);
+		clk_prepare_enable(host->ciu_clk);
+	}
 	return 0;
 }
 
 static void dw_mci_socfpga_prepare_command(struct dw_mci *host, u32 *cmdr)
 {
-	struct dw_mci_socfpga_priv_data *priv = host->priv;
-
-	if (priv->hs_timing & DRV_CLK_PHASE_SHIFT_SEL_MASK)
-		*cmdr |= SDMMC_CMD_USE_HOLD_REG;
-}
-
-static int dw_mci_socfpga_parse_dt(struct dw_mci *host)
-{
-	struct dw_mci_socfpga_priv_data *priv = host->priv;
-	struct device_node *np = host->dev->of_node;
-	u32 timing[2];
-	u32 div = 0;
-	int ret;
-
-	ret = of_property_read_u32(np, "altr,dw-mshc-ciu-div", &div);
-	if (ret)
-		dev_info(host->dev, "No dw-mshc-ciu-div specified, assuming 1");
-	priv->ciu_div = div;
-
-	ret = of_property_read_u32_array(np,
-			"altr,dw-mshc-sdr-timing", timing, 2);
-	if (ret)
-		return ret;
-
-	priv->hs_timing = SYSMGR_SDMMC_CTRL_SET(timing[0], timing[1]);
-	return 0;
+	*cmdr |= SDMMC_CMD_USE_HOLD_REG;
 }
 
 static const struct dw_mci_drv_data socfpga_drv_data = {
-	.init			= dw_mci_socfpga_priv_init,
 	.setup_clock		= dw_mci_socfpga_setup_clock,
 	.prepare_command	= dw_mci_socfpga_prepare_command,
-	.parse_dt		= dw_mci_socfpga_parse_dt,
 };
 
 static const struct of_device_id dw_mci_socfpga_match[] = {
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/4 arm: dts: Add support for SD/MMC on SOCFPGA

In reply to dinguyen at altera.com

From: Dinh Nguyen <[email protected]>

Add new bindings that support SD/MMC on Altera's SOCFPGA platform.

Cc Pavel Machek <[email protected]>
CC Arnd Bergmann <[email protected]>
CC Olof Johansson <[email protected]>
Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Chris Ball <[email protected]>
Cc Jaehoon Chung <[email protected]>
Cc Seungwon Jeon <[email protected]>
Cc devicetree at vger.kernel.org
Cc linux-mmc at vger.kernel.org
CC linux-arm-kernel at lists.infradead.org
---
 .../devicetree/bindings/mmc/socfpga-dw-mshc.txt    |   38 ++++++++++++++++++++
 arch/arm/boot/dts/socfpga.dtsi                     |   11 ++++++
 arch/arm/boot/dts/socfpga_cyclone5.dts             |   12 +++++++
 arch/arm/boot/dts/socfpga_vt.dts                   |   12 +++++++
 4 files changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/socfpga-dw-mshc.txt
Documentation/devicetree/bindings/mmc/socfpga-dw-mshc.txt new file +38 -0
new file mode 100644
index 0000000..246f296
@@ -0,0 +1,38 @@
+* Altera SOCFPGA specific extensions to the Synopsys Designware Mobile
+  Storage Host Controller
+
+The Synopsys designware mobile storage host controller is used to interface
+a SoC with storage medium such as eMMC or SD/MMC cards. This file documents
+differences between the core Synopsys dw mshc controller properties described
+by synopsys-dw-mshc.txt and the properties used by the SOCFPGA specific
+extensions to the Synopsys Designware Mobile Storage Host Controller.
+
+Required Properties:
+
+* compatible: should be
+        - "altr,socfpga-dw-mshc": for controllers with Altera SOCFPGA
+          specific extensions.
+
+* samsung,dw-mshc-sdr-timing: See exynos-dw-mshc.txt for more information about
+	this property.
+
+Example:
+        dwmmc0 at ff704000 {
+                compatible = "altr,socfpga-dw-mshc", "snps,dw-mshc";
+                reg = <0xff704000 0x1000>;
+                interrupts = <0 139 4>;
+                fifo-depth = <0x400>;
+                #address-cells = <1>;
+                #size-cells = <0>;
+                clocks = <&l4_mp_clk>, <&sdmmc_clk>, <&sysmgr_sdr_mmc>;
+                clock-names = "biu", "ciu", "sysmgr-sdr-mmc";
+                num-slots = <1>;
+                supports-highspeed;
+                broken-cd;
+                samsung,dw-mshc-sdr-timing = <3 0>;
+
+                slot at 0 {
+                        reg = <0>;
+                        bus-width = <4>;
+                };
+        };
arch/arm/boot/dts/socfpga.dtsi +11 -0
index 0662d04..cacec8d 100644
@@ -468,6 +468,17 @@
 			cache-level = <2>;
 		};
 
+		mmc: dwmmc0 at ff704000 {
+			compatible = "altr,socfpga-dw-mshc";
+			reg = <0xff704000 0x1000>;
+			interrupts = <0 139 4>;
+			fifo-depth = <0x400>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			clocks = <&l4_mp_clk>, <&sdmmc_clk>, <&sysmgr_sdr_mmc>;
+			clock-names = "biu", "ciu", "sysmgr-sdr-mmc";
+		};
+
 		/* Local timer */
 		timer at fffec600 {
 			compatible = "arm,cortex-a9-twd-timer";
arch/arm/boot/dts/socfpga_cyclone5.dts +12 -0
index 809769e..44db0e6 100644
@@ -48,6 +48,18 @@
 			};
 		};
 
+		dwmmc0 at ff704000 {
+			num-slots = <1>;
+			supports-highspeed;
+			broken-cd;
+			samsung,dw-mshc-sdr-timing = <3 0>;
+
+			slot at 0 {
+				reg = <0>;
+				bus-width = <4>;
+			};
+		};
+
 		ethernet at ff702000 {
 			phy-mode = "rgmii";
 			phy-addr = <0xffffffff>; /* probe for phy addr */
arch/arm/boot/dts/socfpga_vt.dts +12 -0
index d1ec0ca..25b2653 100644
@@ -41,6 +41,18 @@
 			};
 		};
 
+		dwmmc0 at ff704000 {
+			num-slots = <1>;
+			supports-highspeed;
+			broken-cd;
+			samsung,dw-mshc-sdr-timing = <3 0>;
+
+			slot at 0 {
+				reg = <0>;
+				bus-width = <4>;
+			};
+		};
+
 		ethernet at ff700000 {
 			phy-mode = "gmii";
 			status = "okay";
Signature · 1 line
1.7.9.5
#5 lore raw

cover socfpga: Enable SD/MMC support

In reply to dinguyen at altera.com

Hi!

Quoted 18 lines · dinguyen at altera.com

From: Dinh Nguyen <[email protected]>

Hi,

This patch series enables support for the Synopsys SD/MMC driver that is on the Altera SOCFPGA platform. The reason why this series has 4 patches is to implement Arnd's suggestion:

http://lists.infradead.org/pipermail/linux-arm-kernel/2013-October/204982.html

To summarize Arnd's suggestion:

1. Create a backend syscon driver to control the system manager.
2. Create a clock driver independent of the SOCFPGA clock driver that uses syscon as the low-level interface.
3. Make the sdmmc driver use the normal clock API and link its clock to the driver step 2 in the device tree.

Quoted 5 lines

The end approach is a bit different because I did not find the need for a syscon driver for the system manager. Since the system manager had already been iomap already in the SOCFPGA platform code, I just reused it in the new clock driver.

What about the usbgrp, pinmuxgrp, nandgrp, etc. ?
Those are all registers for different subsystems, that are located/controlled by the systemmgr.
With Arnd's approach they all could call that low-level interface, instead of having a special case for every IP core. Isn't that the whole idea behind syscon?

Regards,
Steffen

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |