devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Add device tree support for sdhci-s3c driver
@ 2011-07-17  4:51 Thomas Abraham
  2011-07-17  4:51 ` [PATCH v2 1/2] mmc: sdhci-s3c: Keep a copy of platform data and use it Thomas Abraham
       [not found] ` <1310878275-1422-1-git-send-email-thomas.abraham-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Abraham @ 2011-07-17  4:51 UTC (permalink / raw)
  To: devicetree-discuss; +Cc: cjb, ben-linux, linux-mmc, linux-samsung-soc

This patchset adds basic device tree support for sdhci-s3c driver.
The changes included in this patchset are

A. A copy of the platform data is kept in the drivers private data and
   that copy is referenced for further access to platform data.
B. Some of the platform data elements are retrived from the device tree
   node. The device tree based probe support using a compatible string
   matching is also added.

Changes since v1:
* Obtain some of the platform data from device tree as suggsted by
  Grant Likely.

Thomas Abraham (2):
  mmc: sdhci-s3c: Keep a copy of platform data and use it.
  mmc: sdhci-s3c: add device tree probe support

Thomas Abraham (2):
  mmc: sdhci-s3c: Keep a copy of platform data and use it
  mmc: sdhci-s3c: add device tree probe support

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] mmc: sdhci-s3c: Keep a copy of platform data and use it
  2011-07-17  4:51 [PATCH v2 0/2] Add device tree support for sdhci-s3c driver Thomas Abraham
@ 2011-07-17  4:51 ` Thomas Abraham
       [not found] ` <1310878275-1422-1-git-send-email-thomas.abraham-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Abraham @ 2011-07-17  4:51 UTC (permalink / raw)
  To: devicetree-discuss; +Cc: cjb, ben-linux, linux-mmc, linux-samsung-soc

The platform data is copied into driver's private data and the copy is
used for all access to the platform data. This simpifies the addition
of device tree support for the sdhci-s3c driver.

While at it, a redundant mmc caps setting is removed and
MMC_CAP_8_BIT_DATA is enabled, if the bus width is 8-bits wide.

Signed-off-by: Thomas Abraham <thomas.abraham@linaro.org>
---
 drivers/mmc/host/sdhci-s3c.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 69e3ee3..bb159cc 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -43,7 +43,7 @@ struct sdhci_s3c {
 	struct sdhci_host	*host;
 	struct platform_device	*pdev;
 	struct resource		*ioarea;
-	struct s3c_sdhci_platdata *pdata;
+	struct s3c_sdhci_platdata pdata;
 	unsigned int		cur_clk;
 	int			ext_cd_irq;
 	int			ext_cd_gpio;
@@ -134,7 +134,7 @@ static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
 	 * Clock divider's step is different as 1 from that of host controller
 	 * when 'clk_type' is S3C_SDHCI_CLK_DIV_EXTERNAL.
 	 */
-	if (ourhost->pdata->clk_type) {
+	if (ourhost->pdata.clk_type) {
 		rate = clk_round_rate(clksrc, wanted);
 		return wanted - rate;
 	}
@@ -209,8 +209,8 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
 
 		ios.clock = clock;
 
-		if (ourhost->pdata->cfg_card)
-			(ourhost->pdata->cfg_card)(ourhost->pdev, host->ioaddr,
+		if (ourhost->pdata.cfg_card)
+			(ourhost->pdata.cfg_card)(ourhost->pdev, host->ioaddr,
 						   &ios, NULL);
 	}
 }
@@ -341,7 +341,7 @@ static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
 {
 	struct sdhci_s3c *sc = dev_id;
 	int status = gpio_get_value(sc->ext_cd_gpio);
-	if (sc->pdata->ext_cd_gpio_invert)
+	if (sc->pdata.ext_cd_gpio_invert)
 		status = !status;
 	sdhci_s3c_notify_change(sc->pdev, status);
 	return IRQ_HANDLED;
@@ -349,7 +349,7 @@ static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
 
 static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
 {
-	struct s3c_sdhci_platdata *pdata = sc->pdata;
+	struct s3c_sdhci_platdata *pdata = &sc->pdata;
 	struct device *dev = &sc->pdev->dev;
 
 	if (gpio_request(pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) {
@@ -375,14 +375,14 @@ static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
 
 static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
 {
-	struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
+	struct s3c_sdhci_platdata *pdata;
 	struct device *dev = &pdev->dev;
 	struct sdhci_host *host;
 	struct sdhci_s3c *sc;
 	struct resource *res;
 	int ret, irq, ptr, clks;
 
-	if (!pdata) {
+	if (!pdev->dev.platform_data) {
 		dev_err(dev, "no device data specified\n");
 		return -ENOENT;
 	}
@@ -407,9 +407,10 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
 
 	sc = sdhci_priv(host);
 
+	memcpy(&sc->pdata, pdev->dev.platform_data, sizeof(*pdata));
+	pdata = &sc->pdata;
 	sc->host = host;
 	sc->pdev = pdev;
-	sc->pdata = pdata;
 	sc->ext_cd_gpio = -1; /* invalid gpio number */
 
 	platform_set_drvdata(pdev, host);
@@ -509,6 +510,8 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
 	if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
 		host->mmc->caps = MMC_CAP_NONREMOVABLE;
 
+	if (pdata->max_width == 8)
+		host->mmc->caps |= MMC_CAP_8_BIT_DATA;
 	if (pdata->host_caps)
 		host->mmc->caps |= pdata->host_caps;
 
@@ -528,10 +531,6 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
 		sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
 	}
 
-	/* It supports additional host capabilities if needed */
-	if (pdata->host_caps)
-		host->mmc->caps |= pdata->host_caps;
-
 	ret = sdhci_add_host(host);
 	if (ret) {
 		dev_err(dev, "sdhci_add_host() failed\n");
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] mmc: sdhci-s3c: add device tree probe support
       [not found] ` <1310878275-1422-1-git-send-email-thomas.abraham-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-17  4:51   ` Thomas Abraham
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Abraham @ 2011-07-17  4:51 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ
  Cc: linux-mmc-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	cjb-2X9k7bc8m7Mdnm+yROfE0A, ben-linux-elnMNo+KYs3YtjvyW6yDsg

Add device tree probe support for sdhci-s3c driver. Few of the platform
data elements are parsed from the device tree node and their values are
copied into the platform data stored in the private data of the driver.

Signed-off-by: Thomas Abraham <thomas.abraham-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 .../devicetree/bindings/mmc/samsung-sdhci.txt      |   39 ++++++++++++++++++++
 drivers/mmc/host/sdhci-s3c.c                       |   37 +++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mmc/samsung-sdhci.txt

diff --git a/Documentation/devicetree/bindings/mmc/samsung-sdhci.txt b/Documentation/devicetree/bindings/mmc/samsung-sdhci.txt
new file mode 100644
index 0000000..19e10a5
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/samsung-sdhci.txt
@@ -0,0 +1,39 @@
+* Samsung's SDHCI controller
+
+The Samsung's SDHCI controller is used for interfacing with SD/MMC cards.
+
+Required properties:
+  - compatible : should be "samsung,s3c6410-sdhci"
+
+  - reg : physical base address of the controller and length of memory mapped
+    region.
+
+  - interrupts : interrupt number to the cpu.
+
+  - samsung,sdhci-cd-type: specifies the card detection method to be used.
+    The possible values for this property are
+      (a) 0, internal card detection (sdhci cd pad connected to card slot)
+      (b) 1, external card detection (using a external callback)
+      (c) 2, using a external gpio as card detect line.
+      (d) 3, card detection is not available or broken.
+      (e) 4, for cards that are permanently wired to host.
+
+Optional properties
+  - samsung,sdhci-bus-width: specifies the maximum width of the mmc bus. The
+    value of this property could be 1, 4 or 8. If this property is not
+    specified, the default bus width is selected as 1.
+
+  - samsung,sdhci-clkdiv-external: specifies that the sdhci controller does
+    not include a internal divider to divide the input clock. This property
+    should be used for exynos4 based platforms.
+
+Example:
+
+	sdhci@12530000 {
+		compatible = "samsung,s3c6410-sdhci";
+		reg = <0x12530000 0x1000>;
+		interrupts = <362>;
+		samsung,sdhci-bus-width = <4>;
+		samsung,sdhci-cd-type = <0>;
+		samsung,sdhci-clkdiv-external;
+	};
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index bb159cc..efa37d0 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -19,6 +19,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/of.h>
 
 #include <linux/mmc/host.h>
 
@@ -373,6 +374,28 @@ static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
 	}
 }
 
+#ifdef CONFIG_OF
+static void sdhci_s3c_parse_dt(struct device_node *node,
+				struct s3c_sdhci_platdata *pdata)
+{
+	/* if the bus-width property is not specified, assume width as 1 */
+	if (of_property_read_u32(node, "samsung,sdhci-bus-width",
+			&pdata->max_width))
+		pdata->max_width = 1;
+
+	of_property_read_u32(node, "samsung,sdhci-cd-type", &pdata->cd_type);
+	pdata->clk_type =
+		(of_get_property(node, "samsung,sdhci-clkdiv-external", NULL)) ?
+			S3C_SDHCI_CLK_DIV_EXTERNAL : S3C_SDHCI_CLK_DIV_INTERNAL;
+}
+#else
+static void sdhci_s3c_parse_dt(struct device_node *node,
+				struct s3c_sdhci_platdata *pdata)
+{
+	return;
+}
+#endif
+
 static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
 {
 	struct s3c_sdhci_platdata *pdata;
@@ -474,6 +497,9 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
 		goto err_req_regs;
 	}
 
+	if (pdev->dev.of_node)
+		sdhci_s3c_parse_dt(pdev->dev.of_node, pdata);
+
 	/* Ensure we have minimal gpio selected CMD/CLK/Detect */
 	if (pdata->cfg_gpio)
 		pdata->cfg_gpio(pdev, pdata->max_width);
@@ -628,6 +654,16 @@ static int sdhci_s3c_resume(struct platform_device *dev)
 #define sdhci_s3c_resume NULL
 #endif
 
+#ifdef CONFIG_OF
+static const struct of_device_id s3c_sdhci_match[] = {
+	{ .compatible = "samsung,s3c6410-sdhci", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, s3c_sdhci_match);
+#else
+#define s3c_sdhci_match NULL
+#endif
+
 static struct platform_driver sdhci_s3c_driver = {
 	.probe		= sdhci_s3c_probe,
 	.remove		= __devexit_p(sdhci_s3c_remove),
@@ -636,6 +672,7 @@ static struct platform_driver sdhci_s3c_driver = {
 	.driver		= {
 		.owner	= THIS_MODULE,
 		.name	= "s3c-sdhci",
+		.of_match_table	= s3c_sdhci_match,
 	},
 };
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-07-17  4:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-17  4:51 [PATCH v2 0/2] Add device tree support for sdhci-s3c driver Thomas Abraham
2011-07-17  4:51 ` [PATCH v2 1/2] mmc: sdhci-s3c: Keep a copy of platform data and use it Thomas Abraham
     [not found] ` <1310878275-1422-1-git-send-email-thomas.abraham-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-17  4:51   ` [PATCH v2 2/2] mmc: sdhci-s3c: add device tree probe support Thomas Abraham

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).