Skip to contentSkip to conversation

m68k: mcf5441x: add support for esdhc mmc controller

PATCH In review Angelo Dureghello 3 participants 9 messages May 18, 2020 – May 25, 2020

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

PATCH v6 1/4 m68k: mcf5441x: add support for esdhc mmc controller

Add support for sdhci-edshc mmc controller.

---
Changes for v3:
- removed volatile cast from clk.c
Changes for v4:
- comment style fix in m5441xsim.h
Changes for v5:
- fix compilation warnings from __clk_enable2 and __clk_disable2 Changes for v6:
none

---
 arch/m68k/coldfire/clk.c                    | 15 ++++++++++
 arch/m68k/coldfire/device.c                 | 33 +++++++++++++++++++--
 arch/m68k/coldfire/m5441x.c                 | 12 +++++++-
 arch/m68k/include/asm/m5441xsim.h           | 15 ++++++++++
 arch/m68k/include/asm/mcfclk.h              |  2 ++
 include/linux/platform_data/mmc-esdhc-mcf.h | 17 +++++++++++
 6 files changed, 91 insertions(+), 3 deletions(-)
 create mode 100644 include/linux/platform_data/mmc-esdhc-mcf.h
arch/m68k/coldfire/clk.c +15 -0
index 7bc666e482eb..75a057445472 100644
@@ -73,6 +73,21 @@ struct clk_ops clk_ops1 = {
 #endif /* MCFPM_PPMCR1 */
 #endif /* MCFPM_PPMCR0 */
 
+static void __clk_enable2(struct clk *clk)
+{
+	__raw_writel(__raw_readl(MCFSDHC_CLK) | (1 << clk->slot), MCFSDHC_CLK);
+}
+
+static void __clk_disable2(struct clk *clk)
+{
+	__raw_writel(__raw_readl(MCFSDHC_CLK) & ~(1 << clk->slot), MCFSDHC_CLK);
+}
+
+struct clk_ops clk_ops2 = {
+	.enable		= __clk_enable2,
+	.disable	= __clk_disable2,
+};
+
 struct clk *clk_get(struct device *dev, const char *id)
 {
 	const char *clk_name = dev ? dev_name(dev) : id ? id : NULL;
arch/m68k/coldfire/device.c +31 -2
index b4103b6bfdeb..9ef4ec0aea00 100644
@@ -22,6 +22,7 @@
 #include <asm/mcfqspi.h>
 #include <linux/platform_data/edma.h>
 #include <linux/platform_data/dma-mcf-edma.h>
+#include <linux/platform_data/mmc-esdhc-mcf.h>
 
 /*
  *	All current ColdFire parts contain from 2, 3, 4 or 10 UARTS.
@@ -551,9 +552,35 @@ static struct platform_device mcf_edma = {
 		.platform_data = &mcf_edma_data,
 	}
 };
-
 #endif /* IS_ENABLED(CONFIG_MCF_EDMA) */
 
+#if IS_ENABLED(CONFIG_MMC)
+static struct mcf_esdhc_platform_data mcf_esdhc_data = {
+	.max_bus_width = 4,
+	.cd_type = ESDHC_CD_NONE,
+};
+
+static struct resource mcf_esdhc_resources[] = {
+	{
+		.start = MCFSDHC_BASE,
+		.end = MCFSDHC_BASE + MCFSDHC_SIZE - 1,
+		.flags = IORESOURCE_MEM,
+	}, {
+		.start = MCF_IRQ_SDHC,
+		.end = MCF_IRQ_SDHC,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct platform_device mcf_esdhc = {
+	.name			= "sdhci-esdhc-mcf",
+	.id			= 0,
+	.num_resources		= ARRAY_SIZE(mcf_esdhc_resources),
+	.resource		= mcf_esdhc_resources,
+	.dev.platform_data	= &mcf_esdhc_data,
+};
+#endif /* IS_ENABLED(CONFIG_MMC) */
+
 static struct platform_device *mcf_devices[] __initdata = {
 	&mcf_uart,
 #if IS_ENABLED(CONFIG_FEC)
@@ -586,6 +613,9 @@ static struct platform_device *mcf_devices[] __initdata = {
 #if IS_ENABLED(CONFIG_MCF_EDMA)
 	&mcf_edma,
 #endif
+#if IS_ENABLED(CONFIG_MMC)
+	&mcf_esdhc,
+#endif
 };
 
 /*
@@ -614,4 +644,3 @@ static int __init mcf_init_devices(void)
 }
 
 arch_initcall(mcf_init_devices);
-
arch/m68k/coldfire/m5441x.c +11 -1
index 5bd24c9b865d..ffa02de1a3fb 100644
@@ -52,7 +52,7 @@ DEFINE_CLK(0, "mcfssi.0", 47, MCF_CLK);
 DEFINE_CLK(0, "pll.0", 48, MCF_CLK);
 DEFINE_CLK(0, "mcfrng.0", 49, MCF_CLK);
 DEFINE_CLK(0, "mcfssi.1", 50, MCF_CLK);
-DEFINE_CLK(0, "mcfsdhc.0", 51, MCF_CLK);
+DEFINE_CLK(0, "sdhci-esdhc-mcf.0", 51, MCF_CLK);
 DEFINE_CLK(0, "enet-fec.0", 53, MCF_CLK);
 DEFINE_CLK(0, "enet-fec.1", 54, MCF_CLK);
 DEFINE_CLK(0, "switch.0", 55, MCF_CLK);
@@ -74,6 +74,10 @@ DEFINE_CLK(1, "mcfpwm.0", 34, MCF_BUSCLK);
 DEFINE_CLK(1, "sys.0", 36, MCF_BUSCLK);
 DEFINE_CLK(1, "gpio.0", 37, MCF_BUSCLK);
 
+DEFINE_CLK(2, "ipg.0", 0, MCF_CLK);
+DEFINE_CLK(2, "ahb.0", 1, MCF_CLK);
+DEFINE_CLK(2, "per.0", 2, MCF_CLK);
+
 struct clk *mcf_clks[] = {
 	&__clk_0_2,
 	&__clk_0_8,
@@ -131,6 +135,11 @@ struct clk *mcf_clks[] = {
 	&__clk_1_34,
 	&__clk_1_36,
 	&__clk_1_37,
+
+	&__clk_2_0,
+	&__clk_2_1,
+	&__clk_2_2,
+
 	NULL,
 };
 
@@ -151,6 +160,7 @@ static struct clk * const enable_clks[] __initconst = {
 	&__clk_0_33, /* pit.1 */
 	&__clk_0_37, /* eport */
 	&__clk_0_48, /* pll */
+	&__clk_0_51, /* esdhc */
 
 	&__clk_1_36, /* CCM/reset module/Power management */
 	&__clk_1_37, /* gpio */
arch/m68k/include/asm/m5441xsim.h +15 -0
index 4892f314ff38..e091e36d3464 100644
@@ -278,6 +278,13 @@
 #define MCFGPIO_IRQ_VECBASE	(MCFINT_VECBASE - MCFGPIO_IRQ_MIN)
 #define MCFGPIO_PIN_MAX		87
 
+/*
+ * Phase Locked Loop (PLL)
+ */
+#define MCF_PLL_CR		0xFC0C0000
+#define MCF_PLL_DR		0xFC0C0004
+#define MCF_PLL_SR		0xFC0C0008
+
 /*
  *  DSPI module.
  */
@@ -298,5 +305,13 @@
 #define MCFEDMA_IRQ_INTR16	(MCFINT1_VECBASE + MCFEDMA_EDMA_INTR16)
 #define MCFEDMA_IRQ_INTR56	(MCFINT2_VECBASE + MCFEDMA_EDMA_INTR56)
 #define MCFEDMA_IRQ_ERR	(MCFINT0_VECBASE + MCFINT0_EDMA_ERR)
+/*
+ *  esdhc module.
+ */
+#define MCFSDHC_BASE		0xfc0cc000
+#define MCFSDHC_SIZE		256
+#define MCFINT2_SDHC		31
+#define MCF_IRQ_SDHC		(MCFINT2_VECBASE + MCFINT2_SDHC)
+#define MCFSDHC_CLK		(MCFSDHC_BASE + 0x2c)
 
 #endif /* m5441xsim_h */
arch/m68k/include/asm/mcfclk.h +2 -0
index 0aca504fae31..722627e06d66 100644
@@ -30,6 +30,8 @@ extern struct clk_ops clk_ops0;
 extern struct clk_ops clk_ops1;
 #endif /* MCFPM_PPMCR1 */
 
+extern struct clk_ops clk_ops2;
+
 #define DEFINE_CLK(clk_bank, clk_name, clk_slot, clk_rate) \
 static struct clk __clk_##clk_bank##_##clk_slot = { \
 	.name = clk_name, \
include/linux/platform_data/mmc-esdhc-mcf.h new file +17 -0
new file mode 100644
index 000000000000..85cb786a62fe
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_PLATFORM_DATA_MCF_ESDHC_H__
+#define __LINUX_PLATFORM_DATA_MCF_ESDHC_H__
+
+enum cd_types {
+	ESDHC_CD_NONE,		/* no CD, neither controller nor gpio */
+	ESDHC_CD_CONTROLLER,	/* mmc controller internal CD */
+	ESDHC_CD_PERMANENT,	/* no CD, card permanently wired to host */
+};
+
+struct mcf_esdhc_platform_data {
+	int max_bus_width;
+	int cd_type;
+};
+
+#endif /* __LINUX_PLATFORM_DATA_MCF_ESDHC_H__ */
Signature · 1 line
2.26.2
#1 lore raw

PATCH v6 2/4 mmc: sdhci: add quirks for be to le byte swapping

Some controller as the ColdFire eshdc may require an endianness byte swap, because DMA read endianness is not configurable.

Facilitate using the bounce buffer for this by adding ->copy_to_bounce_buffer().

---
Changes for v3:
- add post request callback
Changes for v4:
none
Changes for v5:
- remove useless comment before swapping bounce buffer
- rename pre_dma_transfer to copy_to_bounce_buffer Changes for v6:
- add more details in the commit message body
- add length parameter to copy_to_bounce_buffer()

---
 drivers/mmc/host/sdhci.c | 10 +++++++---
 drivers/mmc/host/sdhci.h |  3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci.c +7 -3
index 3f716466fcfd..99613f9891a3 100644
@@ -634,9 +634,13 @@ static int sdhci_pre_dma_transfer(struct sdhci_host *host,
 		}
 		if (mmc_get_dma_dir(data) == DMA_TO_DEVICE) {
 			/* Copy the data to the bounce buffer */
-			sg_copy_to_buffer(data->sg, data->sg_len,
-					  host->bounce_buffer,
-					  length);
+			if (host->ops->copy_to_bounce_buffer) {
+				host->ops->copy_to_bounce_buffer(host,
+								 data, length);
+			} else {
+				sg_copy_to_buffer(data->sg, data->sg_len,
+						  host->bounce_buffer, length);
+			}
 		}
 		/* Switch ownership to the DMA */
 		dma_sync_single_for_device(host->mmc->parent,
drivers/mmc/host/sdhci.h +3 -0
index 79dffbb731d3..1bf4f1d91951 100644
@@ -653,6 +653,9 @@ struct sdhci_ops {
 	void	(*voltage_switch)(struct sdhci_host *host);
 	void	(*adma_write_desc)(struct sdhci_host *host, void **desc,
 				   dma_addr_t addr, int len, unsigned int cmd);
+	void	(*copy_to_bounce_buffer)(struct sdhci_host *host,
+					 struct mmc_data *data,
+					 unsigned int length);
 	void	(*request_done)(struct sdhci_host *host,
 				struct mmc_request *mrq);
 };
Signature · 1 line
2.26.2
#2 lore raw

PATCH v6 3/4 mmc: host: add Coldfire esdhc support

In reply to Angelo Dureghello

This driver has been developed as a separate module starting from the similar sdhci-esdhc-imx.c.

Reasons for a separate sdchi-esdhc-mcf driver:

- m68K architecture does not support devicetrees, so modifying sdhci-of-esdhc.c that is devicetree-related adding platform data seems not appropriate,
- clock-related part, has to be implemented specifically for mcf5441x family (see esdhc_mcf_pltfm_set_clock()),
- this is a big endian cpu accessing a big endian controller, but about sdma, this controller does not support hw swap, which needs to be handled with specific code,
- some other minor differences but mainly to avoid risks on tweaking inside largely used imx driver. Adding just a small size ColdFire-specific driver, with benefits in a further less risky maintenance.

---
Changes for v3:
- fix write support
Changes for v4:
none
Changes for v5:
- better probe cleanup on errors
- test for bounce buffer to be allocated
- rename pre_dma_transfer to copy_to_bounce_buffer
- change swap to swap and copy to bounce buffer
- fix line alignments to pass checkpatch --strict Changes for v6:
- add length parameter to esdhc_mcf_copy_to_bounce_buffer()

---
 drivers/mmc/host/Kconfig           |  13 +
 drivers/mmc/host/Makefile          |   1 +
 drivers/mmc/host/sdhci-esdhc-mcf.c | 521 +++++++++++++++++++++++++++++
 3 files changed, 535 insertions(+)
 create mode 100644 drivers/mmc/host/sdhci-esdhc-mcf.c
drivers/mmc/host/Kconfig +13 -0
index 462b5352fea7..da793fc95203 100644
@@ -235,6 +235,19 @@ config MMC_SDHCI_CNS3XXX
 
 	  If unsure, say N.
 
+config MMC_SDHCI_ESDHC_MCF
+	tristate "SDHCI support for the Freescale eSDHC ColdFire controller"
+	depends on M5441x
+	depends on MMC_SDHCI_PLTFM
+	select MMC_SDHCI_IO_ACCESSORS
+	help
+	  This selects the Freescale eSDHC controller support for
+	  ColdFire mcf5441x devices.
+
+	  If you have a controller with this interface, say Y or M here.
+
+	  If unsure, say N.
+
 config MMC_SDHCI_ESDHC_IMX
 	tristate "SDHCI support for the Freescale eSDHC/uSDHC i.MX controller"
 	depends on ARCH_MXC
drivers/mmc/host/Makefile +1 -0
index b929ef941208..af2cdaadc4d3 100644
@@ -82,6 +82,7 @@ obj-$(CONFIG_MMC_REALTEK_USB)	+= rtsx_usb_sdmmc.o
 obj-$(CONFIG_MMC_SDHCI_PLTFM)		+= sdhci-pltfm.o
 obj-$(CONFIG_MMC_SDHCI_CADENCE)		+= sdhci-cadence.o
 obj-$(CONFIG_MMC_SDHCI_CNS3XXX)		+= sdhci-cns3xxx.o
+obj-$(CONFIG_MMC_SDHCI_ESDHC_MCF)       += sdhci-esdhc-mcf.o
 obj-$(CONFIG_MMC_SDHCI_ESDHC_IMX)	+= sdhci-esdhc-imx.o
 obj-$(CONFIG_MMC_SDHCI_DOVE)		+= sdhci-dove.o
 obj-$(CONFIG_MMC_SDHCI_TEGRA)		+= sdhci-tegra.o
drivers/mmc/host/sdhci-esdhc-mcf.c new file +521 -0

521 lines not on this page · raw message

Signature · 1 line
2.26.2
#3 lore raw

PATCH v6 4/4 MAINTAINERS: add myself to maintain M5441X mmc host driver

In reply to Angelo Dureghello

Since actively working on Freescale ColdFire M5441X, adding myself as a maintainer of this driver.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index ecc0749810b0..92aab798154f 100644
@@ -6713,6 +6713,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/crypto/fsl-sec4.txt
 F:	drivers/crypto/caam/
 
+FREESCALE COLDFIRE M5441X MMC DRIVER
+M:	Angelo Dureghello <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/mmc/host/sdhci-esdhc-mcf.c
+F:	include/linux/platform_data/mmc-esdhc-mcf.h
+
 FREESCALE DIU FRAMEBUFFER DRIVER
 M:	Timur Tabi <[email protected]>
 L:	[email protected]
Signature · 1 line
2.26.2
#4 lore raw
In reply to Angelo Dureghello
Quoted 5 lines · Angelo Dureghello

Add support for sdhci-edshc mmc controller.

This one and the rest of series, applied for next, thanks!

Kind regards
Uffe

Quoted 224 lines

---
Changes for v3:
- removed volatile cast from clk.c
Changes for v4:
- comment style fix in m5441xsim.h
Changes for v5:
- fix compilation warnings from __clk_enable2 and __clk_disable2 Changes for v6:
none

---
 arch/m68k/coldfire/clk.c                    | 15 ++++++++++
 arch/m68k/coldfire/device.c                 | 33 +++++++++++++++++++--
 arch/m68k/coldfire/m5441x.c                 | 12 +++++++-
 arch/m68k/include/asm/m5441xsim.h           | 15 ++++++++++
 arch/m68k/include/asm/mcfclk.h              |  2 ++
 include/linux/platform_data/mmc-esdhc-mcf.h | 17 +++++++++++
 6 files changed, 91 insertions(+), 3 deletions(-)
 create mode 100644 include/linux/platform_data/mmc-esdhc-mcf.h
arch/m68k/coldfire/clk.c +15 -0
index 7bc666e482eb..75a057445472 100644
@@ -73,6 +73,21 @@ struct clk_ops clk_ops1 = {
 #endif /* MCFPM_PPMCR1 */
 #endif /* MCFPM_PPMCR0 */
 
+static void __clk_enable2(struct clk *clk)
+{
+       __raw_writel(__raw_readl(MCFSDHC_CLK) | (1 << clk->slot), MCFSDHC_CLK);
+}
+
+static void __clk_disable2(struct clk *clk)
+{
+       __raw_writel(__raw_readl(MCFSDHC_CLK) & ~(1 << clk->slot), MCFSDHC_CLK);
+}
+
+struct clk_ops clk_ops2 = {
+       .enable         = __clk_enable2,
+       .disable        = __clk_disable2,
+};
+
 struct clk *clk_get(struct device *dev, const char *id)
 {
        const char *clk_name = dev ? dev_name(dev) : id ? id : NULL;
arch/m68k/coldfire/device.c +31 -2
index b4103b6bfdeb..9ef4ec0aea00 100644
@@ -22,6 +22,7 @@
 #include <asm/mcfqspi.h>
 #include <linux/platform_data/edma.h>
 #include <linux/platform_data/dma-mcf-edma.h>
+#include <linux/platform_data/mmc-esdhc-mcf.h>
 
 /*
  *     All current ColdFire parts contain from 2, 3, 4 or 10 UARTS.
@@ -551,9 +552,35 @@ static struct platform_device mcf_edma = {
                .platform_data = &mcf_edma_data,
        }
 };
-
 #endif /* IS_ENABLED(CONFIG_MCF_EDMA) */
 
+#if IS_ENABLED(CONFIG_MMC)
+static struct mcf_esdhc_platform_data mcf_esdhc_data = {
+       .max_bus_width = 4,
+       .cd_type = ESDHC_CD_NONE,
+};
+
+static struct resource mcf_esdhc_resources[] = {
+       {
+               .start = MCFSDHC_BASE,
+               .end = MCFSDHC_BASE + MCFSDHC_SIZE - 1,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MCF_IRQ_SDHC,
+               .end = MCF_IRQ_SDHC,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mcf_esdhc = {
+       .name                   = "sdhci-esdhc-mcf",
+       .id                     = 0,
+       .num_resources          = ARRAY_SIZE(mcf_esdhc_resources),
+       .resource               = mcf_esdhc_resources,
+       .dev.platform_data      = &mcf_esdhc_data,
+};
+#endif /* IS_ENABLED(CONFIG_MMC) */
+
 static struct platform_device *mcf_devices[] __initdata = {
        &mcf_uart,
 #if IS_ENABLED(CONFIG_FEC)
@@ -586,6 +613,9 @@ static struct platform_device *mcf_devices[] __initdata = {
 #if IS_ENABLED(CONFIG_MCF_EDMA)
        &mcf_edma,
 #endif
+#if IS_ENABLED(CONFIG_MMC)
+       &mcf_esdhc,
+#endif
 };
 
 /*
@@ -614,4 +644,3 @@ static int __init mcf_init_devices(void)
 }
 
 arch_initcall(mcf_init_devices);
-
arch/m68k/coldfire/m5441x.c +11 -1
index 5bd24c9b865d..ffa02de1a3fb 100644
@@ -52,7 +52,7 @@ DEFINE_CLK(0, "mcfssi.0", 47, MCF_CLK);
 DEFINE_CLK(0, "pll.0", 48, MCF_CLK);
 DEFINE_CLK(0, "mcfrng.0", 49, MCF_CLK);
 DEFINE_CLK(0, "mcfssi.1", 50, MCF_CLK);
-DEFINE_CLK(0, "mcfsdhc.0", 51, MCF_CLK);
+DEFINE_CLK(0, "sdhci-esdhc-mcf.0", 51, MCF_CLK);
 DEFINE_CLK(0, "enet-fec.0", 53, MCF_CLK);
 DEFINE_CLK(0, "enet-fec.1", 54, MCF_CLK);
 DEFINE_CLK(0, "switch.0", 55, MCF_CLK);
@@ -74,6 +74,10 @@ DEFINE_CLK(1, "mcfpwm.0", 34, MCF_BUSCLK);
 DEFINE_CLK(1, "sys.0", 36, MCF_BUSCLK);
 DEFINE_CLK(1, "gpio.0", 37, MCF_BUSCLK);
 
+DEFINE_CLK(2, "ipg.0", 0, MCF_CLK);
+DEFINE_CLK(2, "ahb.0", 1, MCF_CLK);
+DEFINE_CLK(2, "per.0", 2, MCF_CLK);
+
 struct clk *mcf_clks[] = {
        &__clk_0_2,
        &__clk_0_8,
@@ -131,6 +135,11 @@ struct clk *mcf_clks[] = {
        &__clk_1_34,
        &__clk_1_36,
        &__clk_1_37,
+
+       &__clk_2_0,
+       &__clk_2_1,
+       &__clk_2_2,
+
        NULL,
 };
 
@@ -151,6 +160,7 @@ static struct clk * const enable_clks[] __initconst = {
        &__clk_0_33, /* pit.1 */
        &__clk_0_37, /* eport */
        &__clk_0_48, /* pll */
+       &__clk_0_51, /* esdhc */
 
        &__clk_1_36, /* CCM/reset module/Power management */
        &__clk_1_37, /* gpio */
arch/m68k/include/asm/m5441xsim.h +15 -0
index 4892f314ff38..e091e36d3464 100644
@@ -278,6 +278,13 @@
 #define MCFGPIO_IRQ_VECBASE    (MCFINT_VECBASE - MCFGPIO_IRQ_MIN)
 #define MCFGPIO_PIN_MAX                87
 
+/*
+ * Phase Locked Loop (PLL)
+ */
+#define MCF_PLL_CR             0xFC0C0000
+#define MCF_PLL_DR             0xFC0C0004
+#define MCF_PLL_SR             0xFC0C0008
+
 /*
  *  DSPI module.
  */
@@ -298,5 +305,13 @@
 #define MCFEDMA_IRQ_INTR16     (MCFINT1_VECBASE + MCFEDMA_EDMA_INTR16)
 #define MCFEDMA_IRQ_INTR56     (MCFINT2_VECBASE + MCFEDMA_EDMA_INTR56)
 #define MCFEDMA_IRQ_ERR        (MCFINT0_VECBASE + MCFINT0_EDMA_ERR)
+/*
+ *  esdhc module.
+ */
+#define MCFSDHC_BASE           0xfc0cc000
+#define MCFSDHC_SIZE           256
+#define MCFINT2_SDHC           31
+#define MCF_IRQ_SDHC           (MCFINT2_VECBASE + MCFINT2_SDHC)
+#define MCFSDHC_CLK            (MCFSDHC_BASE + 0x2c)
 
 #endif /* m5441xsim_h */
arch/m68k/include/asm/mcfclk.h +2 -0
index 0aca504fae31..722627e06d66 100644
@@ -30,6 +30,8 @@ extern struct clk_ops clk_ops0;
 extern struct clk_ops clk_ops1;
 #endif /* MCFPM_PPMCR1 */
 
+extern struct clk_ops clk_ops2;
+
 #define DEFINE_CLK(clk_bank, clk_name, clk_slot, clk_rate) \
 static struct clk __clk_##clk_bank##_##clk_slot = { \
        .name = clk_name, \
include/linux/platform_data/mmc-esdhc-mcf.h new file +17 -1
new file mode 100644
index 000000000000..85cb786a62fe
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_PLATFORM_DATA_MCF_ESDHC_H__
+#define __LINUX_PLATFORM_DATA_MCF_ESDHC_H__
+
+enum cd_types {
+       ESDHC_CD_NONE,          /* no CD, neither controller nor gpio */
+       ESDHC_CD_CONTROLLER,    /* mmc controller internal CD */
+       ESDHC_CD_PERMANENT,     /* no CD, card permanently wired to host */
+};
+
+struct mcf_esdhc_platform_data {
+       int max_bus_width;
+       int cd_type;
+};
+
+#endif /* __LINUX_PLATFORM_DATA_MCF_ESDHC_H__ */
--

2.26.2

maintainer
#6 lore raw
In reply to Angelo Dureghello

Hi Angelo,

Have you seen this breakage being reported in linux-next?

    arch/m68k/coldfire/clk.c:78:60: error: 'MCFSDHC_CLK' undeclared (first
    use in this function); did you mean 'MCF_CLK'?
    arch/m68k/coldfire/clk.c:83:61: error: 'MCFSDHC_CLK' undeclared (first
    use in this function); did you mean 'MCF_CLK'?
    make[2]: *** [scripts/Makefile.build:272: arch/m68k/coldfire/clk.o] 
    Error 1
    make[1]: *** [Makefile:1736: arch/m68k/coldfire] Error 2
    make: *** [Makefile:185: __sub-make] Error 2

This is when compiling for pretty much anything other than an mcf5441x target.

Quoted 28 lines · Angelo Dureghello

Add support for sdhci-edshc mmc controller.

---
Changes for v3:
- removed volatile cast from clk.c
Changes for v4:
- comment style fix in m5441xsim.h
Changes for v5:
- fix compilation warnings from __clk_enable2 and __clk_disable2 Changes for v6:
none

---
  arch/m68k/coldfire/clk.c                    | 15 ++++++++++
  arch/m68k/coldfire/device.c                 | 33 +++++++++++++++++++--
  arch/m68k/coldfire/m5441x.c                 | 12 +++++++-
  arch/m68k/include/asm/m5441xsim.h           | 15 ++++++++++
  arch/m68k/include/asm/mcfclk.h              |  2 ++
  include/linux/platform_data/mmc-esdhc-mcf.h | 17 +++++++++++
  6 files changed, 91 insertions(+), 3 deletions(-)

create mode 100644 include/linux/platform_data/mmc-esdhc-mcf.h

arch/m68k/coldfire/clk.c +0 -0
index 7bc666e482eb..75a057445472 100644

arch/m68k/coldfire/clk.c struct clk_ops clk_ops1 = { · line 79

Quoted 7 lines
arch/m68k/coldfire/clk.c +4 -0
@@ -73,6 +73,21 @@ struct clk_ops clk_ops1 = {
  #endif /* MCFPM_PPMCR1 */
  #endif /* MCFPM_PPMCR0 */
 
+static void __clk_enable2(struct clk *clk)
+{
+	__raw_writel(__raw_readl(MCFSDHC_CLK) | (1 << clk->slot), MCFSDHC_CLK);
+}

MCFSDHC_CLK will not be defiend for anything other than mcf5441x targets.

This mechanism looks a little out of place here, given how specific it is to the sdhc hardware module of the 5441x. Can you move this to the m5441x specific code resolving this?

Regards
Greg

Quoted 190 lines
arch/m68k/coldfire/clk.c +10 -0
+static void __clk_disable2(struct clk *clk)
+{
+	__raw_writel(__raw_readl(MCFSDHC_CLK) & ~(1 << clk->slot), MCFSDHC_CLK);
+}
+
+struct clk_ops clk_ops2 = {
+	.enable		= __clk_enable2,
+	.disable	= __clk_disable2,
+};
+
  struct clk *clk_get(struct device *dev, const char *id)
  {
  	const char *clk_name = dev ? dev_name(dev) : id ? id : NULL;
arch/m68k/coldfire/device.c +31 -2
index b4103b6bfdeb..9ef4ec0aea00 100644
@@ -22,6 +22,7 @@
  #include <asm/mcfqspi.h>
  #include <linux/platform_data/edma.h>
  #include <linux/platform_data/dma-mcf-edma.h>
+#include <linux/platform_data/mmc-esdhc-mcf.h>
 
  /*
   *	All current ColdFire parts contain from 2, 3, 4 or 10 UARTS.
@@ -551,9 +552,35 @@ static struct platform_device mcf_edma = {
  		.platform_data = &mcf_edma_data,
  	}
  };
-
  #endif /* IS_ENABLED(CONFIG_MCF_EDMA) */
 
+#if IS_ENABLED(CONFIG_MMC)
+static struct mcf_esdhc_platform_data mcf_esdhc_data = {
+	.max_bus_width = 4,
+	.cd_type = ESDHC_CD_NONE,
+};
+
+static struct resource mcf_esdhc_resources[] = {
+	{
+		.start = MCFSDHC_BASE,
+		.end = MCFSDHC_BASE + MCFSDHC_SIZE - 1,
+		.flags = IORESOURCE_MEM,
+	}, {
+		.start = MCF_IRQ_SDHC,
+		.end = MCF_IRQ_SDHC,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct platform_device mcf_esdhc = {
+	.name			= "sdhci-esdhc-mcf",
+	.id			= 0,
+	.num_resources		= ARRAY_SIZE(mcf_esdhc_resources),
+	.resource		= mcf_esdhc_resources,
+	.dev.platform_data	= &mcf_esdhc_data,
+};
+#endif /* IS_ENABLED(CONFIG_MMC) */
+
  static struct platform_device *mcf_devices[] __initdata = {
  	&mcf_uart,
  #if IS_ENABLED(CONFIG_FEC)
@@ -586,6 +613,9 @@ static struct platform_device *mcf_devices[] __initdata = {
  #if IS_ENABLED(CONFIG_MCF_EDMA)
  	&mcf_edma,
  #endif
+#if IS_ENABLED(CONFIG_MMC)
+	&mcf_esdhc,
+#endif
  };
 
  /*
@@ -614,4 +644,3 @@ static int __init mcf_init_devices(void)
  }
 
  arch_initcall(mcf_init_devices);
-
arch/m68k/coldfire/m5441x.c +11 -1
index 5bd24c9b865d..ffa02de1a3fb 100644
@@ -52,7 +52,7 @@ DEFINE_CLK(0, "mcfssi.0", 47, MCF_CLK);
  DEFINE_CLK(0, "pll.0", 48, MCF_CLK);
  DEFINE_CLK(0, "mcfrng.0", 49, MCF_CLK);
  DEFINE_CLK(0, "mcfssi.1", 50, MCF_CLK);
-DEFINE_CLK(0, "mcfsdhc.0", 51, MCF_CLK);
+DEFINE_CLK(0, "sdhci-esdhc-mcf.0", 51, MCF_CLK);
  DEFINE_CLK(0, "enet-fec.0", 53, MCF_CLK);
  DEFINE_CLK(0, "enet-fec.1", 54, MCF_CLK);
  DEFINE_CLK(0, "switch.0", 55, MCF_CLK);
@@ -74,6 +74,10 @@ DEFINE_CLK(1, "mcfpwm.0", 34, MCF_BUSCLK);
  DEFINE_CLK(1, "sys.0", 36, MCF_BUSCLK);
  DEFINE_CLK(1, "gpio.0", 37, MCF_BUSCLK);
 
+DEFINE_CLK(2, "ipg.0", 0, MCF_CLK);
+DEFINE_CLK(2, "ahb.0", 1, MCF_CLK);
+DEFINE_CLK(2, "per.0", 2, MCF_CLK);
+
  struct clk *mcf_clks[] = {
  	&__clk_0_2,
  	&__clk_0_8,
@@ -131,6 +135,11 @@ struct clk *mcf_clks[] = {
  	&__clk_1_34,
  	&__clk_1_36,
  	&__clk_1_37,
+
+	&__clk_2_0,
+	&__clk_2_1,
+	&__clk_2_2,
+
  	NULL,
  };
 
@@ -151,6 +160,7 @@ static struct clk * const enable_clks[] __initconst = {
  	&__clk_0_33, /* pit.1 */
  	&__clk_0_37, /* eport */
  	&__clk_0_48, /* pll */
+	&__clk_0_51, /* esdhc */
 
  	&__clk_1_36, /* CCM/reset module/Power management */
  	&__clk_1_37, /* gpio */
arch/m68k/include/asm/m5441xsim.h +15 -0
index 4892f314ff38..e091e36d3464 100644
@@ -278,6 +278,13 @@
  #define MCFGPIO_IRQ_VECBASE	(MCFINT_VECBASE - MCFGPIO_IRQ_MIN)
  #define MCFGPIO_PIN_MAX		87
 
+/*
+ * Phase Locked Loop (PLL)
+ */
+#define MCF_PLL_CR		0xFC0C0000
+#define MCF_PLL_DR		0xFC0C0004
+#define MCF_PLL_SR		0xFC0C0008
+
  /*
   *  DSPI module.
   */
@@ -298,5 +305,13 @@
  #define MCFEDMA_IRQ_INTR16	(MCFINT1_VECBASE + MCFEDMA_EDMA_INTR16)
  #define MCFEDMA_IRQ_INTR56	(MCFINT2_VECBASE + MCFEDMA_EDMA_INTR56)
  #define MCFEDMA_IRQ_ERR	(MCFINT0_VECBASE + MCFINT0_EDMA_ERR)
+/*
+ *  esdhc module.
+ */
+#define MCFSDHC_BASE		0xfc0cc000
+#define MCFSDHC_SIZE		256
+#define MCFINT2_SDHC		31
+#define MCF_IRQ_SDHC		(MCFINT2_VECBASE + MCFINT2_SDHC)
+#define MCFSDHC_CLK		(MCFSDHC_BASE + 0x2c)
 
  #endif /* m5441xsim_h */
arch/m68k/include/asm/mcfclk.h +2 -0
index 0aca504fae31..722627e06d66 100644
@@ -30,6 +30,8 @@ extern struct clk_ops clk_ops0;
  extern struct clk_ops clk_ops1;
  #endif /* MCFPM_PPMCR1 */
 
+extern struct clk_ops clk_ops2;
+
  #define DEFINE_CLK(clk_bank, clk_name, clk_slot, clk_rate) \
  static struct clk __clk_##clk_bank##_##clk_slot = { \
  	.name = clk_name, \
include/linux/platform_data/mmc-esdhc-mcf.h new file +17 -0
new file mode 100644
index 000000000000..85cb786a62fe
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_PLATFORM_DATA_MCF_ESDHC_H__
+#define __LINUX_PLATFORM_DATA_MCF_ESDHC_H__
+
+enum cd_types {
+	ESDHC_CD_NONE,		/* no CD, neither controller nor gpio */
+	ESDHC_CD_CONTROLLER,	/* mmc controller internal CD */
+	ESDHC_CD_PERMANENT,	/* no CD, card permanently wired to host */
+};
+
+struct mcf_esdhc_platform_data {
+	int max_bus_width;
+	int cd_type;
+};
+
+#endif /* __LINUX_PLATFORM_DATA_MCF_ESDHC_H__ */
#7 lore raw

Hi Greg,

Quoted 20 lines · Greg Ungerer

Hi Angelo,

Have you seen this breakage being reported in linux-next?

     arch/m68k/coldfire/clk.c:78:60: error: 'MCFSDHC_CLK' undeclared (first
     use in this function); did you mean 'MCF_CLK'?
     arch/m68k/coldfire/clk.c:83:61: error: 'MCFSDHC_CLK' undeclared (first
     use in this function); did you mean 'MCF_CLK'?
     make[2]: *** [scripts/Makefile.build:272: arch/m68k/coldfire/clk.o]
     Error 1
     make[1]: *** [Makefile:1736: arch/m68k/coldfire] Error 2
     make: *** [Makefile:185: __sub-make] Error 2

This is when compiling for pretty much anything other than an mcf5441x target.

Quoted 6 lines

MCFSDHC_CLK will not be defiend for anything other than mcf5441x targets.

This mechanism looks a little out of place here, given how specific it is to the sdhc hardware module of the 5441x. Can you move this to the m5441x specific code resolving this?

i apologize. Couldn't catch that since building for this target. Fixing, re-testing and sending patch in short.

Quoted 5 lines

Regards
Greg

Regards,
Angelo

maintainer
#8 lore raw

Hi Angelo,

Quoted 25 lines · Angelo Dureghello

Hi Greg,

Quoted 22 lines · Greg Ungerer

Hi Angelo,

Have you seen this breakage being reported in linux-next?

      arch/m68k/coldfire/clk.c:78:60: error: 'MCFSDHC_CLK' undeclared (first
      use in this function); did you mean 'MCF_CLK'?
      arch/m68k/coldfire/clk.c:83:61: error: 'MCFSDHC_CLK' undeclared (first
      use in this function); did you mean 'MCF_CLK'?
      make[2]: *** [scripts/Makefile.build:272: arch/m68k/coldfire/clk.o]
      Error 1
      make[1]: *** [Makefile:1736: arch/m68k/coldfire] Error 2
      make: *** [Makefile:185: __sub-make] Error 2

This is when compiling for pretty much anything other than an mcf5441x target.

MCFSDHC_CLK will not be defiend for anything other than mcf5441x targets.

Quoted 7 lines
Quoted 4 lines

This mechanism looks a little out of place here, given how specific it is to the sdhc hardware module of the 5441x. Can you move this to the m5441x specific code resolving this?

i apologize. Couldn't catch that since building for this target. Fixing, re-testing and sending patch in short.

There is a bunch of default ColdFire target configurations in arch/m68k/configs/M* that you can test compile for. Gives you pretty good coverage across various ColdFire types.

Regards
Greg