f8e9b44
From patchwork Mon Jan  8 15:44:19 2018
f8e9b44
Content-Type: text/plain; charset="utf-8"
f8e9b44
MIME-Version: 1.0
f8e9b44
Content-Transfer-Encoding: 7bit
f8e9b44
Subject: [v2] mmc: sdhci_f_sdh30: add ACPI support
f8e9b44
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
f8e9b44
X-Patchwork-Id: 10149775
f8e9b44
Message-Id: <20180108154419.2821-1-ard.biesheuvel@linaro.org>
f8e9b44
To: linux-mmc@vger.kernel.org
f8e9b44
Cc: adrian.hunter@intel.com, ulf.hansson@linaro.org,
f8e9b44
 Ard Biesheuvel <ard.biesheuvel@linaro.org>
f8e9b44
Date: Mon,  8 Jan 2018 15:44:19 +0000
f8e9b44
f8e9b44
The Fujitsu SDH30 SDHCI controller may be described as a SCX0002 ACPI
f8e9b44
device on ACPI platforms incorporating the Socionext SynQuacer SoC.
f8e9b44
f8e9b44
Given that mmc_of_parse() has already been made ACPI/DT agnostic,
f8e9b44
making the SDH30 driver ACPI capable is actually rather simple:
f8e9b44
all we need to do is make the call to sdhci_get_of_property() [which
f8e9b44
does not set any properties we care about] and the clock handling
f8e9b44
dependent on whether we are dealing with a DT device, and exposing
f8e9b44
the ACPI id via the platform_driver struct and the module metadata.
f8e9b44
f8e9b44
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
f8e9b44
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
f8e9b44
---
f8e9b44
v2: make OF optional now that ACPI is supported
f8e9b44
    drop dev_of_node() check when disabling the clocks - those routines
f8e9b44
    tolerate NULL pointers so there's no need
f8e9b44
f8e9b44
 drivers/mmc/host/Kconfig         |  2 +-
f8e9b44
 drivers/mmc/host/sdhci_f_sdh30.c | 52 +++++++++++++-------
f8e9b44
 2 files changed, 35 insertions(+), 19 deletions(-)
f8e9b44
f8e9b44
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
f8e9b44
index 567028c9219a..07ed947ed10b 100644
f8e9b44
--- a/drivers/mmc/host/Kconfig
f8e9b44
+++ b/drivers/mmc/host/Kconfig
f8e9b44
@@ -320,7 +320,7 @@ config MMC_SDHCI_BCM_KONA
f8e9b44
 config MMC_SDHCI_F_SDH30
f8e9b44
 	tristate "SDHCI support for Fujitsu Semiconductor F_SDH30"
f8e9b44
 	depends on MMC_SDHCI_PLTFM
f8e9b44
-	depends on OF
f8e9b44
+	depends on OF || ACPI
f8e9b44
 	help
f8e9b44
 	  This selects the Secure Digital Host Controller Interface (SDHCI)
f8e9b44
 	  Needed by some Fujitsu SoC for MMC / SD / SDIO support.
f8e9b44
diff --git a/drivers/mmc/host/sdhci_f_sdh30.c b/drivers/mmc/host/sdhci_f_sdh30.c
f8e9b44
index 04ca0d33a521..485f7591fae4 100644
f8e9b44
--- a/drivers/mmc/host/sdhci_f_sdh30.c
f8e9b44
+++ b/drivers/mmc/host/sdhci_f_sdh30.c
f8e9b44
@@ -10,9 +10,11 @@
f8e9b44
  * the Free Software Foundation, version 2 of the License.
f8e9b44
  */
f8e9b44
 
f8e9b44
+#include <linux/acpi.h>
f8e9b44
 #include <linux/err.h>
f8e9b44
 #include <linux/delay.h>
f8e9b44
 #include <linux/module.h>
f8e9b44
+#include <linux/of.h>
f8e9b44
 #include <linux/property.h>
f8e9b44
 #include <linux/clk.h>
f8e9b44
 
f8e9b44
@@ -146,7 +148,6 @@ static int sdhci_f_sdh30_probe(struct platform_device *pdev)
f8e9b44
 
f8e9b44
 	platform_set_drvdata(pdev, host);
f8e9b44
 
f8e9b44
-	sdhci_get_of_property(pdev);
f8e9b44
 	host->hw_name = "f_sdh30";
f8e9b44
 	host->ops = &sdhci_f_sdh30_ops;
f8e9b44
 	host->irq = irq;
f8e9b44
@@ -158,25 +159,29 @@ static int sdhci_f_sdh30_probe(struct platform_device *pdev)
f8e9b44
 		goto err;
f8e9b44
 	}
f8e9b44
 
f8e9b44
-	priv->clk_iface = devm_clk_get(&pdev->dev, "iface");
f8e9b44
-	if (IS_ERR(priv->clk_iface)) {
f8e9b44
-		ret = PTR_ERR(priv->clk_iface);
f8e9b44
-		goto err;
f8e9b44
-	}
f8e9b44
+	if (dev_of_node(dev)) {
f8e9b44
+		sdhci_get_of_property(pdev);
f8e9b44
 
f8e9b44
-	ret = clk_prepare_enable(priv->clk_iface);
f8e9b44
-	if (ret)
f8e9b44
-		goto err;
f8e9b44
+		priv->clk_iface = devm_clk_get(&pdev->dev, "iface");
f8e9b44
+		if (IS_ERR(priv->clk_iface)) {
f8e9b44
+			ret = PTR_ERR(priv->clk_iface);
f8e9b44
+			goto err;
f8e9b44
+		}
f8e9b44
 
f8e9b44
-	priv->clk = devm_clk_get(&pdev->dev, "core");
f8e9b44
-	if (IS_ERR(priv->clk)) {
f8e9b44
-		ret = PTR_ERR(priv->clk);
f8e9b44
-		goto err_clk;
f8e9b44
-	}
f8e9b44
+		ret = clk_prepare_enable(priv->clk_iface);
f8e9b44
+		if (ret)
f8e9b44
+			goto err;
f8e9b44
 
f8e9b44
-	ret = clk_prepare_enable(priv->clk);
f8e9b44
-	if (ret)
f8e9b44
-		goto err_clk;
f8e9b44
+		priv->clk = devm_clk_get(&pdev->dev, "core");
f8e9b44
+		if (IS_ERR(priv->clk)) {
f8e9b44
+			ret = PTR_ERR(priv->clk);
f8e9b44
+			goto err_clk;
f8e9b44
+		}
f8e9b44
+
f8e9b44
+		ret = clk_prepare_enable(priv->clk);
f8e9b44
+		if (ret)
f8e9b44
+			goto err_clk;
f8e9b44
+	}
f8e9b44
 
f8e9b44
 	/* init vendor specific regs */
f8e9b44
 	ctrl = sdhci_readw(host, F_SDH30_AHB_CONFIG);
f8e9b44
@@ -226,16 +231,27 @@ static int sdhci_f_sdh30_remove(struct platform_device *pdev)
f8e9b44
 	return 0;
f8e9b44
 }
f8e9b44
 
f8e9b44
+#ifdef CONFIG_OF
f8e9b44
 static const struct of_device_id f_sdh30_dt_ids[] = {
f8e9b44
 	{ .compatible = "fujitsu,mb86s70-sdhci-3.0" },
f8e9b44
 	{ /* sentinel */ }
f8e9b44
 };
f8e9b44
 MODULE_DEVICE_TABLE(of, f_sdh30_dt_ids);
f8e9b44
+#endif
f8e9b44
+
f8e9b44
+#ifdef CONFIG_ACPI
f8e9b44
+static const struct acpi_device_id f_sdh30_acpi_ids[] = {
f8e9b44
+	{ "SCX0002" },
f8e9b44
+	{ /* sentinel */ }
f8e9b44
+};
f8e9b44
+MODULE_DEVICE_TABLE(acpi, f_sdh30_acpi_ids);
f8e9b44
+#endif
f8e9b44
 
f8e9b44
 static struct platform_driver sdhci_f_sdh30_driver = {
f8e9b44
 	.driver = {
f8e9b44
 		.name = "f_sdh30",
f8e9b44
-		.of_match_table = f_sdh30_dt_ids,
f8e9b44
+		.of_match_table = of_match_ptr(f_sdh30_dt_ids),
f8e9b44
+		.acpi_match_table = ACPI_PTR(f_sdh30_acpi_ids),
f8e9b44
 		.pm	= &sdhci_pltfm_pmops,
f8e9b44
 	},
f8e9b44
 	.probe	= sdhci_f_sdh30_probe,