aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/spi/spi-sh-msiof.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 181efd049d12..38d6b70e9be2 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -21,6 +21,7 @@
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/of.h>
24#include <linux/of_device.h>
24#include <linux/platform_device.h> 25#include <linux/platform_device.h>
25#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
26 27
@@ -30,11 +31,18 @@
30 31
31#include <asm/unaligned.h> 32#include <asm/unaligned.h>
32 33
34
35struct sh_msiof_chipdata {
36 u16 tx_fifo_size;
37 u16 rx_fifo_size;
38};
39
33struct sh_msiof_spi_priv { 40struct sh_msiof_spi_priv {
34 struct spi_bitbang bitbang; /* must be first for spi_bitbang.c */ 41 struct spi_bitbang bitbang; /* must be first for spi_bitbang.c */
35 void __iomem *mapbase; 42 void __iomem *mapbase;
36 struct clk *clk; 43 struct clk *clk;
37 struct platform_device *pdev; 44 struct platform_device *pdev;
45 const struct sh_msiof_chipdata *chipdata;
38 struct sh_msiof_spi_info *info; 46 struct sh_msiof_spi_info *info;
39 struct completion done; 47 struct completion done;
40 unsigned long flags; 48 unsigned long flags;
@@ -113,10 +121,6 @@ struct sh_msiof_spi_priv {
113#define STR_REOF 0x00000080 /* Frame Reception End */ 121#define STR_REOF 0x00000080 /* Frame Reception End */
114 122
115 123
116#define DEFAULT_TX_FIFO_SIZE 64
117#define DEFAULT_RX_FIFO_SIZE 64
118
119
120static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs) 124static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs)
121{ 125{
122 switch (reg_offs) { 126 switch (reg_offs) {
@@ -659,6 +663,18 @@ static u32 sh_msiof_spi_txrx_word(struct spi_device *spi, unsigned nsecs,
659 return 0; 663 return 0;
660} 664}
661 665
666static const struct sh_msiof_chipdata sh_data = {
667 .tx_fifo_size = 64,
668 .rx_fifo_size = 64,
669};
670
671static const struct of_device_id sh_msiof_match[] = {
672 { .compatible = "renesas,sh-msiof", .data = &sh_data },
673 { .compatible = "renesas,sh-mobile-msiof", .data = &sh_data },
674 {},
675};
676MODULE_DEVICE_TABLE(of, sh_msiof_match);
677
662#ifdef CONFIG_OF 678#ifdef CONFIG_OF
663static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev) 679static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev)
664{ 680{
@@ -694,6 +710,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
694{ 710{
695 struct resource *r; 711 struct resource *r;
696 struct spi_master *master; 712 struct spi_master *master;
713 const struct of_device_id *of_id;
697 struct sh_msiof_spi_priv *p; 714 struct sh_msiof_spi_priv *p;
698 int i; 715 int i;
699 int ret; 716 int ret;
@@ -707,10 +724,15 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
707 p = spi_master_get_devdata(master); 724 p = spi_master_get_devdata(master);
708 725
709 platform_set_drvdata(pdev, p); 726 platform_set_drvdata(pdev, p);
710 if (pdev->dev.of_node) 727
728 of_id = of_match_device(sh_msiof_match, &pdev->dev);
729 if (of_id) {
730 p->chipdata = of_id->data;
711 p->info = sh_msiof_spi_parse_dt(&pdev->dev); 731 p->info = sh_msiof_spi_parse_dt(&pdev->dev);
712 else 732 } else {
733 p->chipdata = (const void *)pdev->id_entry->driver_data;
713 p->info = dev_get_platdata(&pdev->dev); 734 p->info = dev_get_platdata(&pdev->dev);
735 }
714 736
715 if (!p->info) { 737 if (!p->info) {
716 dev_err(&pdev->dev, "failed to obtain device info\n"); 738 dev_err(&pdev->dev, "failed to obtain device info\n");
@@ -757,11 +779,9 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
757 p->pdev = pdev; 779 p->pdev = pdev;
758 pm_runtime_enable(&pdev->dev); 780 pm_runtime_enable(&pdev->dev);
759 781
760 /* The standard version of MSIOF use 64 word FIFOs */
761 p->tx_fifo_size = DEFAULT_TX_FIFO_SIZE;
762 p->rx_fifo_size = DEFAULT_RX_FIFO_SIZE;
763
764 /* Platform data may override FIFO sizes */ 782 /* Platform data may override FIFO sizes */
783 p->tx_fifo_size = p->chipdata->tx_fifo_size;
784 p->rx_fifo_size = p->chipdata->rx_fifo_size;
765 if (p->info->tx_fifo_override) 785 if (p->info->tx_fifo_override)
766 p->tx_fifo_size = p->info->tx_fifo_override; 786 p->tx_fifo_size = p->info->tx_fifo_override;
767 if (p->info->rx_fifo_override) 787 if (p->info->rx_fifo_override)
@@ -811,18 +831,16 @@ static int sh_msiof_spi_remove(struct platform_device *pdev)
811 return ret; 831 return ret;
812} 832}
813 833
814#ifdef CONFIG_OF 834static struct platform_device_id spi_driver_ids[] = {
815static const struct of_device_id sh_msiof_match[] = { 835 { "spi_sh_msiof", (kernel_ulong_t)&sh_data },
816 { .compatible = "renesas,sh-msiof", },
817 { .compatible = "renesas,sh-mobile-msiof", },
818 {}, 836 {},
819}; 837};
820MODULE_DEVICE_TABLE(of, sh_msiof_match); 838MODULE_DEVICE_TABLE(platform, spi_driver_ids);
821#endif
822 839
823static struct platform_driver sh_msiof_spi_drv = { 840static struct platform_driver sh_msiof_spi_drv = {
824 .probe = sh_msiof_spi_probe, 841 .probe = sh_msiof_spi_probe,
825 .remove = sh_msiof_spi_remove, 842 .remove = sh_msiof_spi_remove,
843 .id_table = spi_driver_ids,
826 .driver = { 844 .driver = {
827 .name = "spi_sh_msiof", 845 .name = "spi_sh_msiof",
828 .owner = THIS_MODULE, 846 .owner = THIS_MODULE,