aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-sh-msiof.c
diff options
context:
space:
mode:
authorBastian Hecht <hechtb@gmail.com>2012-12-12 06:54:48 -0500
committerGrant Likely <grant.likely@secretlab.ca>2013-02-05 07:26:58 -0500
commitcf9c86efecf9510e62388fd174cf607671c59fa3 (patch)
treee5ab65e1d3b2b3e3aba31cfe7262334820c7ecd2 /drivers/spi/spi-sh-msiof.c
parentaae7147dfc522062b3448f67f5517d32fbdab1fb (diff)
spi/sh-msiof: Add device tree parsing to driver
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+renesas@gmail.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/spi/spi-sh-msiof.c')
-rw-r--r--drivers/spi/spi-sh-msiof.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 96358d0eabb7..8b40d0884f8b 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -20,6 +20,7 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/of.h>
23#include <linux/platform_device.h> 24#include <linux/platform_device.h>
24#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
25 26
@@ -592,6 +593,37 @@ static u32 sh_msiof_spi_txrx_word(struct spi_device *spi, unsigned nsecs,
592 return 0; 593 return 0;
593} 594}
594 595
596#ifdef CONFIG_OF
597static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev)
598{
599 struct sh_msiof_spi_info *info;
600 struct device_node *np = dev->of_node;
601 u32 num_cs = 0;
602
603 info = devm_kzalloc(dev, sizeof(struct sh_msiof_spi_info), GFP_KERNEL);
604 if (!info) {
605 dev_err(dev, "failed to allocate setup data\n");
606 return NULL;
607 }
608
609 /* Parse the MSIOF properties */
610 of_property_read_u32(np, "num-cs", &num_cs);
611 of_property_read_u32(np, "renesas,tx-fifo-size",
612 &info->tx_fifo_override);
613 of_property_read_u32(np, "renesas,rx-fifo-size",
614 &info->rx_fifo_override);
615
616 info->num_chipselect = num_cs;
617
618 return info;
619}
620#else
621static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev)
622{
623 return NULL;
624}
625#endif
626
595static int sh_msiof_spi_probe(struct platform_device *pdev) 627static int sh_msiof_spi_probe(struct platform_device *pdev)
596{ 628{
597 struct resource *r; 629 struct resource *r;
@@ -610,7 +642,17 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
610 p = spi_master_get_devdata(master); 642 p = spi_master_get_devdata(master);
611 643
612 platform_set_drvdata(pdev, p); 644 platform_set_drvdata(pdev, p);
613 p->info = pdev->dev.platform_data; 645 if (pdev->dev.of_node)
646 p->info = sh_msiof_spi_parse_dt(&pdev->dev);
647 else
648 p->info = pdev->dev.platform_data;
649
650 if (!p->info) {
651 dev_err(&pdev->dev, "failed to obtain device info\n");
652 ret = -ENXIO;
653 goto err1;
654 }
655
614 init_completion(&p->done); 656 init_completion(&p->done);
615 657
616 p->clk = clk_get(&pdev->dev, NULL); 658 p->clk = clk_get(&pdev->dev, NULL);
@@ -715,6 +757,17 @@ static int sh_msiof_spi_runtime_nop(struct device *dev)
715 return 0; 757 return 0;
716} 758}
717 759
760#ifdef CONFIG_OF
761static const struct of_device_id sh_msiof_match[] = {
762 { .compatible = "renesas,sh-msiof", },
763 { .compatible = "renesas,sh-mobile-msiof", },
764 {},
765};
766MODULE_DEVICE_TABLE(of, sh_msiof_match);
767#else
768#define sh_msiof_match NULL
769#endif
770
718static struct dev_pm_ops sh_msiof_spi_dev_pm_ops = { 771static struct dev_pm_ops sh_msiof_spi_dev_pm_ops = {
719 .runtime_suspend = sh_msiof_spi_runtime_nop, 772 .runtime_suspend = sh_msiof_spi_runtime_nop,
720 .runtime_resume = sh_msiof_spi_runtime_nop, 773 .runtime_resume = sh_msiof_spi_runtime_nop,
@@ -727,6 +780,7 @@ static struct platform_driver sh_msiof_spi_drv = {
727 .name = "spi_sh_msiof", 780 .name = "spi_sh_msiof",
728 .owner = THIS_MODULE, 781 .owner = THIS_MODULE,
729 .pm = &sh_msiof_spi_dev_pm_ops, 782 .pm = &sh_msiof_spi_dev_pm_ops,
783 .of_match_table = sh_msiof_match,
730 }, 784 },
731}; 785};
732module_platform_driver(sh_msiof_spi_drv); 786module_platform_driver(sh_msiof_spi_drv);