linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bastian Hecht <hechtb@gmail.com>
To: spi-devel-general@lists.sourceforge.net
Cc: linux-sh@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	Magnus Damm <magnus.damm@gmail.com>
Subject: [PATCH 3/4] spi: sh-msiof: Add device tree parsing to driver
Date: Wed,  7 Nov 2012 12:40:06 +0100	[thread overview]
Message-ID: <1352288407-20594-4-git-send-email-hechtb@gmail.com> (raw)
In-Reply-To: <1352288407-20594-1-git-send-email-hechtb@gmail.com>

This adds the capability to retrieve setup data from the device tree
node. The usage of platform data is still available.

Signed-off-by: Bastian Hecht <hechtb@gmail.com>
---
 drivers/spi/spi-sh-msiof.c |   54 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 96358d0..65cd19c 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -20,6 +20,7 @@
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 
@@ -592,6 +593,35 @@ static u32 sh_msiof_spi_txrx_word(struct spi_device *spi, unsigned nsecs,
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev)
+{
+	struct sh_msiof_spi_info *info;
+	struct device_node *np = dev->of_node;
+	u32 chipselect = 0;
+
+	info = devm_kzalloc(dev, sizeof(struct sh_msiof_spi_info), GFP_KERNEL);
+	if (!info) {
+		dev_err(dev, "failed to allocate setup data\n");
+		return NULL;
+	}
+
+	/* Parse the MSIOF properties */
+	of_property_read_u32(np, "chip-select", &chipselect);
+	of_property_read_u32(np, "tx_fifo_size", &info->tx_fifo_override);
+	of_property_read_u32(np, "rx_fifo_size", &info->rx_fifo_override);
+
+	info->num_chipselect = chipselect;
+
+	return info;
+}
+#else
+static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 static int sh_msiof_spi_probe(struct platform_device *pdev)
 {
 	struct resource	*r;
@@ -610,7 +640,17 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
 	p = spi_master_get_devdata(master);
 
 	platform_set_drvdata(pdev, p);
-	p->info = pdev->dev.platform_data;
+	if (pdev->dev.of_node)
+		p->info = sh_msiof_spi_parse_dt(&pdev->dev);
+	else
+		p->info = pdev->dev.platform_data;
+
+	if (!p->info) {
+		dev_err(&pdev->dev, "failed to obtain device info\n");
+		ret = -ENXIO;
+		goto err1;
+	}
+
 	init_completion(&p->done);
 
 	p->clk = clk_get(&pdev->dev, NULL);
@@ -715,6 +755,17 @@ static int sh_msiof_spi_runtime_nop(struct device *dev)
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id sh_msiof_match[] = {
+	{ .compatible = "renesas,sh-msiof", },
+	{ .compatible = "renesas,sh-mobile-msiof", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, sh_msiof_match);
+#else
+#define sh_msiof_match NULL
+#endif
+
 static struct dev_pm_ops sh_msiof_spi_dev_pm_ops = {
 	.runtime_suspend = sh_msiof_spi_runtime_nop,
 	.runtime_resume = sh_msiof_spi_runtime_nop,
@@ -727,6 +778,7 @@ static struct platform_driver sh_msiof_spi_drv = {
 		.name		= "spi_sh_msiof",
 		.owner		= THIS_MODULE,
 		.pm		= &sh_msiof_spi_dev_pm_ops,
+		.of_match_table = sh_msiof_match,
 	},
 };
 module_platform_driver(sh_msiof_spi_drv);
-- 
1.7.5.4


  parent reply	other threads:[~2012-11-07 11:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-07 11:40 [PATCH RESEND 0/4] spi: sh-msiof: Add DT support Bastian Hecht
2012-11-07 11:40 ` [PATCH 1/4] spi: sh-msiof: Remove unneeded clock name Bastian Hecht
2012-12-06 14:05   ` Grant Likely
2012-11-07 11:40 ` [PATCH 2/4] spi: Add SH Mobile series as dependency to MSIOF controller Bastian Hecht
2012-11-07 11:40 ` Bastian Hecht [this message]
2012-12-06 14:14   ` [PATCH 3/4] spi: sh-msiof: Add device tree parsing to driver Grant Likely
2012-11-07 11:40 ` [PATCH 4/4] devicetree: Add Renesas SH Mobile MSIOF spi controller binding doc Bastian Hecht
2012-12-06 14:08   ` Grant Likely
2012-12-06 14:13     ` Grant Likely
2012-12-12 11:26       ` Bastian Hecht
  -- strict thread matches above, loose matches on Subject: below --
2012-09-21 11:00 [PATCH 1/4] spi: sh-msiof: Remove unneeded clock name Bastian Hecht
     [not found] ` <1348225249-1294-1-git-send-email-hechtb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-09-21 11:00   ` [PATCH 3/4] spi: sh-msiof: Add device tree parsing to driver Bastian Hecht

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=1352288407-20594-4-git-send-email-hechtb@gmail.com \
    --to=hechtb@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=spi-devel-general@lists.sourceforge.net \
    /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).