From: Andrea Merello <andrea.merello@gmail.com>
To: ulf.hansson@linaro.org, mcoquelin.stm32@gmail.com,
alexandre.torgue@st.com
Cc: linux-mmc@vger.kernel.org, Andrea Merello <andrea.merello@gmail.com>
Subject: [PATCH 2/9] mmc: mmci: add support for not-amba, but still compatible, variants
Date: Tue, 8 Nov 2016 14:43:38 +0100 [thread overview]
Message-ID: <1478612625-23256-3-git-send-email-andrea.merello@gmail.com> (raw)
In-Reply-To: <1478612625-23256-1-git-send-email-andrea.merello@gmail.com>
The STM32F4xx family contain a SDIO IP that looks like a variant of
the PL180, however, inspite it's actually attached to a APB bus, it
cannot be handled by the AMBA bus code, because it lacks of the ID
registers that AMBA primecell IPs have.
This patch prepares for supporting the STM32 variant by letting the
driver register also as a platform driver, that can be matched from
the OF with specific "compatible" strings
Signed-off-by: Andrea Merello <andrea.merello@gmail.com>
---
drivers/mmc/host/Kconfig | 8 +-
drivers/mmc/host/mmci.c | 259 +++++++++++++++++++++++++++++++++++------------
2 files changed, 199 insertions(+), 68 deletions(-)
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 5cf7eba..0f51de3 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -5,12 +5,12 @@
comment "MMC/SD/SDIO Host Controller Drivers"
config MMC_ARMMMCI
- tristate "ARM AMBA Multimedia Card Interface support"
- depends on ARM_AMBA
+ tristate "ARM AMBA Multimedia Card Interface and compatible support"
help
This selects the ARM(R) AMBA(R) PrimeCell Multimedia Card
- Interface (PL180 and PL181) support. If you have an ARM(R)
- platform with a Multimedia Card slot, say Y or M here.
+ Interface (PL180, PL181 and compatible) support.
+ If you have an ARM(R) platform with a Multimedia Card slot,
+ say Y or M here.
If unsure, say N.
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index b826a3a..b1dfde3 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1,5 +1,6 @@
/*
- * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver
+ * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 and
+ * comaptible driver
*
* Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
* Copyright (C) 2010 ST-Ericsson SA
@@ -37,6 +38,8 @@
#include <linux/pm_runtime.h>
#include <linux/types.h>
#include <linux/pinctrl/consumer.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>
#include <asm/div64.h>
#include <asm/io.h>
@@ -105,7 +108,7 @@ struct variant_data {
bool reversed_irq_handling;
};
-static struct variant_data variant_arm = {
+static __maybe_unused struct variant_data variant_arm = {
.fifosize = 16 * 4,
.fifohalfsize = 8 * 4,
.datalength_bits = 16,
@@ -114,7 +117,7 @@ static struct variant_data variant_arm = {
.reversed_irq_handling = true,
};
-static struct variant_data variant_arm_extended_fifo = {
+static __maybe_unused struct variant_data variant_arm_extended_fifo = {
.fifosize = 128 * 4,
.fifohalfsize = 64 * 4,
.datalength_bits = 16,
@@ -122,7 +125,7 @@ static struct variant_data variant_arm_extended_fifo = {
.f_max = 100000000,
};
-static struct variant_data variant_arm_extended_fifo_hwfc = {
+static __maybe_unused struct variant_data variant_arm_extended_fifo_hwfc = {
.fifosize = 128 * 4,
.fifohalfsize = 64 * 4,
.clkreg_enable = MCI_ARM_HWFCEN,
@@ -131,7 +134,7 @@ static struct variant_data variant_arm_extended_fifo_hwfc = {
.f_max = 100000000,
};
-static struct variant_data variant_u300 = {
+static __maybe_unused struct variant_data variant_u300 = {
.fifosize = 16 * 4,
.fifohalfsize = 8 * 4,
.clkreg_enable = MCI_ST_U300_HWFCEN,
@@ -146,7 +149,7 @@ static struct variant_data variant_u300 = {
.pwrreg_nopower = true,
};
-static struct variant_data variant_nomadik = {
+static __maybe_unused struct variant_data variant_nomadik = {
.fifosize = 16 * 4,
.fifohalfsize = 8 * 4,
.clkreg = MCI_CLK_ENABLE,
@@ -162,7 +165,7 @@ static struct variant_data variant_nomadik = {
.pwrreg_nopower = true,
};
-static struct variant_data variant_ux500 = {
+static __maybe_unused struct variant_data variant_ux500 = {
.fifosize = 30 * 4,
.fifohalfsize = 8 * 4,
.clkreg = MCI_CLK_ENABLE,
@@ -181,7 +184,7 @@ static struct variant_data variant_ux500 = {
.pwrreg_nopower = true,
};
-static struct variant_data variant_ux500v2 = {
+static __maybe_unused struct variant_data variant_ux500v2 = {
.fifosize = 30 * 4,
.fifohalfsize = 8 * 4,
.clkreg = MCI_CLK_ENABLE,
@@ -202,7 +205,7 @@ static struct variant_data variant_ux500v2 = {
.pwrreg_nopower = true,
};
-static struct variant_data variant_qcom = {
+static __maybe_unused struct variant_data variant_qcom = {
.fifosize = 16 * 4,
.fifohalfsize = 8 * 4,
.clkreg = MCI_CLK_ENABLE,
@@ -1483,31 +1486,32 @@ static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
return 0;
}
-static int mmci_probe(struct amba_device *dev,
- const struct amba_id *id)
+static struct mmci_host *mmci_probe(struct device *dev,
+ struct variant_data *variant,
+ struct resource *res,
+ unsigned int irq0, unsigned int irq1)
{
- struct mmci_platform_data *plat = dev->dev.platform_data;
- struct device_node *np = dev->dev.of_node;
- struct variant_data *variant = id->data;
- struct mmci_host *host;
+ struct device_node *np = dev->of_node;
+ struct mmci_platform_data *plat = dev->platform_data;
struct mmc_host *mmc;
+ struct mmci_host *host;
int ret;
/* Must have platform data or Device Tree. */
if (!plat && !np) {
- dev_err(&dev->dev, "No plat data or DT found\n");
- return -EINVAL;
+ dev_err(dev, "No plat data or DT found\n");
+ return ERR_PTR(-EINVAL);
}
if (!plat) {
- plat = devm_kzalloc(&dev->dev, sizeof(*plat), GFP_KERNEL);
+ plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL);
if (!plat)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
}
- mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev);
+ mmc = mmc_alloc_host(sizeof(struct mmci_host), dev);
if (!mmc)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
ret = mmci_of_parse(np, mmc);
if (ret)
@@ -1516,12 +1520,7 @@ static int mmci_probe(struct amba_device *dev,
host = mmc_priv(mmc);
host->mmc = mmc;
- host->hw_designer = amba_manf(dev);
- host->hw_revision = amba_rev(dev);
- dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer);
- dev_dbg(mmc_dev(mmc), "revision = 0x%01x\n", host->hw_revision);
-
- host->clk = devm_clk_get(&dev->dev, NULL);
+ host->clk = devm_clk_get(dev, NULL);
if (IS_ERR(host->clk)) {
ret = PTR_ERR(host->clk);
goto host_free;
@@ -1553,8 +1552,8 @@ static int mmci_probe(struct amba_device *dev,
host->mclk);
}
- host->phybase = dev->res.start;
- host->base = devm_ioremap_resource(&dev->dev, &dev->res);
+ host->phybase = res->start;
+ host->base = devm_ioremap_resource(dev, res);
if (IS_ERR(host->base)) {
ret = PTR_ERR(host->base);
goto clk_disable;
@@ -1688,49 +1687,41 @@ static int mmci_probe(struct amba_device *dev,
}
}
- ret = devm_request_irq(&dev->dev, dev->irq[0], mmci_irq, IRQF_SHARED,
- DRIVER_NAME " (cmd)", host);
+ ret = devm_request_irq(dev, irq0, mmci_irq, IRQF_SHARED,
+ DRIVER_NAME " (cmd)", host);
if (ret)
goto clk_disable;
- if (!dev->irq[1])
+ if (!irq1) {
host->singleirq = true;
- else {
- ret = devm_request_irq(&dev->dev, dev->irq[1], mmci_pio_irq,
- IRQF_SHARED, DRIVER_NAME " (pio)", host);
+ } else {
+ ret = devm_request_irq(dev, irq1, mmci_pio_irq,
+ IRQF_SHARED, DRIVER_NAME " (pio)", host);
if (ret)
goto clk_disable;
}
writel(MCI_IRQENABLE, host->base + MMCIMASK0);
- amba_set_drvdata(dev, mmc);
-
- dev_info(&dev->dev, "%s: PL%03x manf %x rev%u at 0x%08llx irq %d,%d (pio)\n",
- mmc_hostname(mmc), amba_part(dev), amba_manf(dev),
- amba_rev(dev), (unsigned long long)dev->res.start,
- dev->irq[0], dev->irq[1]);
-
mmci_dma_setup(host);
- pm_runtime_set_autosuspend_delay(&dev->dev, 50);
- pm_runtime_use_autosuspend(&dev->dev);
+ pm_runtime_set_autosuspend_delay(dev, 50);
+ pm_runtime_use_autosuspend(dev);
mmc_add_host(mmc);
- pm_runtime_put(&dev->dev);
- return 0;
+ pm_runtime_put(dev);
+ return host;
clk_disable:
clk_disable_unprepare(host->clk);
host_free:
mmc_free_host(mmc);
- return ret;
+ return ERR_PTR(ret);
}
-static int mmci_remove(struct amba_device *dev)
+static int mmc_remove(struct mmc_host *mmc)
{
- struct mmc_host *mmc = amba_get_drvdata(dev);
if (mmc) {
struct mmci_host *host = mmc_priv(mmc);
@@ -1739,7 +1730,7 @@ static int mmci_remove(struct amba_device *dev)
* Undo pm_runtime_put() in probe. We use the _sync
* version here so that we can access the primecell.
*/
- pm_runtime_get_sync(&dev->dev);
+ pm_runtime_get_sync(mmc->parent);
mmc_remove_host(mmc);
@@ -1793,14 +1784,11 @@ static void mmci_restore(struct mmci_host *host)
spin_unlock_irqrestore(&host->lock, flags);
}
-static int mmci_runtime_suspend(struct device *dev)
+static int mmci_runtime_suspend(struct mmc_host *mmc)
{
- struct amba_device *adev = to_amba_device(dev);
- struct mmc_host *mmc = amba_get_drvdata(adev);
-
if (mmc) {
struct mmci_host *host = mmc_priv(mmc);
- pinctrl_pm_select_sleep_state(dev);
+ pinctrl_pm_select_sleep_state(mmc->parent);
mmci_save(host);
clk_disable_unprepare(host->clk);
}
@@ -1808,28 +1796,77 @@ static int mmci_runtime_suspend(struct device *dev)
return 0;
}
-static int mmci_runtime_resume(struct device *dev)
+static int mmci_runtime_resume(struct mmc_host *mmc)
{
- struct amba_device *adev = to_amba_device(dev);
- struct mmc_host *mmc = amba_get_drvdata(adev);
if (mmc) {
struct mmci_host *host = mmc_priv(mmc);
clk_prepare_enable(host->clk);
mmci_restore(host);
- pinctrl_pm_select_default_state(dev);
+ pinctrl_pm_select_default_state(mmc->parent);
}
return 0;
}
#endif
-static const struct dev_pm_ops mmci_dev_pm_ops = {
+#ifdef CONFIG_ARM_AMBA
+static int mmci_remove_amba(struct amba_device *dev)
+{
+ struct mmc_host *mmc = amba_get_drvdata(dev);
+
+ return mmc_remove(mmc);
+}
+
+static int mmci_runtime_resume_amba(struct device *dev)
+{
+ struct amba_device *adev = to_amba_device(dev);
+ struct mmc_host *mmc = amba_get_drvdata(adev);
+
+ return mmci_runtime_resume(mmc);
+}
+
+static int mmci_runtime_suspend_amba(struct device *dev)
+{
+ struct amba_device *adev = to_amba_device(dev);
+ struct mmc_host *mmc = amba_get_drvdata(adev);
+
+ return mmci_runtime_suspend(mmc);
+}
+
+static const struct dev_pm_ops mmci_dev_pm_ops_amba = {
SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
pm_runtime_force_resume)
- SET_RUNTIME_PM_OPS(mmci_runtime_suspend, mmci_runtime_resume, NULL)
+ SET_RUNTIME_PM_OPS(mmci_runtime_suspend_amba, mmci_runtime_resume_amba,
+ NULL)
};
+static int mmci_probe_amba(struct amba_device *dev, const struct amba_id *id)
+{
+ struct mmci_host *host;
+ struct variant_data *variant = id->data;
+
+ host = mmci_probe(&pdev->dev, variant, &dev->res,
+ dev->irq[0], dev->irq[1]);
+ if (IS_ERR(ret))
+ return PTR_ERR(host);
+
+ host->hw_designer = amba_manf(dev);
+ host->hw_revision = amba_rev(dev);
+ dev_dbg(mmc_dev(host->mmc), "designer ID = 0x%02x\n",
+ host->hw_designer);
+ dev_dbg(mmc_dev(host->mmc), "revision = 0x%01x\n", host->hw_revision);
+
+ amba_set_drvdata(dev, host->mmc);
+
+ dev_info(&dev->dev, "%s: PL%03x manf %x rev%u at 0x%08llx irq %d,%d (pio)\n",
+ mmc_hostname(host->mmc), amba_part(dev), amba_manf(dev),
+ amba_rev(dev), (unsigned long long)dev->res.start,
+ dev->irq[0], dev->irq[1]);
+
+ return 0;
+}
+
static struct amba_id mmci_ids[] = {
{
.id = 0x00041180,
@@ -1891,14 +1928,108 @@ MODULE_DEVICE_TABLE(amba, mmci_ids);
static struct amba_driver mmci_driver = {
.drv = {
.name = DRIVER_NAME,
- .pm = &mmci_dev_pm_ops,
+ .pm = &mmci_dev_pm_ops_amba,
},
- .probe = mmci_probe,
- .remove = mmci_remove,
+ .probe = mmci_probe_amba,
+ .remove = mmci_remove_amba,
.id_table = mmci_ids,
};
module_amba_driver(mmci_driver);
+#endif
+
+static const struct of_device_id mmci_pltfm_match[] = {
+ {},
+};
+
+static int mmci_probe_pltfm(struct platform_device *pdev)
+{
+ struct mmci_host *host;
+ struct variant_data *variant;
+ const struct of_device_id *match;
+ int irq0, irq1;
+ struct resource *res;
+
+ irq0 = platform_get_irq(pdev, 0);
+ if (irq0 < 0) {
+ dev_err(&pdev->dev, "Can't get IRQ");
+ return -EINVAL;
+ }
+
+ irq1 = platform_get_irq(pdev, 1);
+ /* optional. set to 0 to be compatible with original amba probe code */
+ if (irq1 < 0)
+ irq1 = 0;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(&pdev->dev, "Can't get MMIO range");
+ return -EINVAL;
+ }
+
+ match = of_match_device(mmci_pltfm_match, &pdev->dev);
+ if (!match) {
+ dev_err(&pdev->dev, "Can't get variant data\n");
+ return -EINVAL;
+ }
+ variant = (struct variant_data *)match->data;
+
+ host = mmci_probe(&pdev->dev, variant, res,
+ irq0, irq1);
+ if (IS_ERR(host))
+ return PTR_ERR(host);
+
+ platform_set_drvdata(pdev, host->mmc);
+ dev_info(&pdev->dev, "%s: PL81x compatible SDIO at 0x%08llx irq %d,%d (pio)\n",
+ mmc_hostname(host->mmc),
+ (unsigned long long)res->start, irq0, irq1);
+
+ return 0;
+}
+
+static int mmci_remove_pltfm(struct platform_device *pdev)
+{
+ struct mmc_host *mmc = platform_get_drvdata(pdev);
+
+ return mmc_remove(mmc);
+}
+
+static int mmci_runtime_resume_pltfm(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct mmc_host *mmc = platform_get_drvdata(pdev);
+
+ return mmci_runtime_resume(mmc);
+}
+
+static int mmci_runtime_suspend_pltfm(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct mmc_host *mmc = platform_get_drvdata(pdev);
+
+ return mmci_runtime_suspend(mmc);
+}
+
+MODULE_DEVICE_TABLE(of, mmci_pltfm_match);
+
+static const struct dev_pm_ops mmci_dev_pm_ops_pltfm = {
+ SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+ pm_runtime_force_resume)
+ SET_RUNTIME_PM_OPS(mmci_runtime_suspend_pltfm,
+ mmci_runtime_resume_pltfm, NULL)
+};
+
+static struct platform_driver mmci_pltfm_driver = {
+ .probe = mmci_probe_pltfm,
+ .remove = mmci_remove_pltfm,
+ .driver = {
+ .name = DRIVER_NAME,
+ .of_match_table = mmci_pltfm_match,
+ .pm = &mmci_dev_pm_ops_pltfm,
+ },
+};
+
+module_platform_driver(mmci_pltfm_driver);
module_param(fmax, uint, 0444);
--
2.7.4
next prev parent reply other threads:[~2016-11-08 13:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-08 13:43 [PATCH 0/9] mmc: mmci: add support for STM32 SD controller Andrea Merello
2016-11-08 13:43 ` [PATCH 1/9] mmc: mmci: don't pretend IP variants with only one IRQ to have two mask regs Andrea Merello
2016-11-08 13:43 ` Andrea Merello [this message]
2016-11-08 17:39 ` [PATCH 2/9] mmc: mmci: add support for not-amba, but still compatible, variants kbuild test robot
2016-11-08 17:41 ` kbuild test robot
2016-11-08 13:43 ` [PATCH 3/9] mmc: mmci: don't pretend all variants to have MCI_STARBITERR flag Andrea Merello
2016-11-08 13:43 ` [PATCH 4/9] mmc: mmci: add support for setting pad type via pinctrl Andrea Merello
2016-11-08 13:43 ` [PATCH 5/9] mmc: mmci: add STM32 variant Andrea Merello
2016-11-08 13:43 ` [PATCH 6/9] DT: stm32f429: add pin map for SDIO controller Andrea Merello
2016-11-10 10:51 ` Alexandre Torgue
2016-11-14 10:19 ` Andrea Merello
2016-11-08 13:43 ` [PATCH 7/9] DT: stm32f429: add node " Andrea Merello
2016-11-08 13:43 ` [PATCH 8/9] DT: stm32f469-disco: " Andrea Merello
2016-11-10 10:54 ` Alexandre Torgue
2016-11-14 10:36 ` Andrea Merello
2016-11-14 10:42 ` Alexandre Torgue
2016-11-08 13:43 ` [PATCH 9/9] Documentation: document mmci STM32 DT binding Andrea Merello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478612625-23256-3-git-send-email-andrea.merello@gmail.com \
--to=andrea.merello@gmail.com \
--cc=alexandre.torgue@st.com \
--cc=linux-mmc@vger.kernel.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=ulf.hansson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).