aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/spi/spi-dw-mmio.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index d25cc4037e23..e80f60ed6fdf 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -15,11 +15,13 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/spi/spi.h> 16#include <linux/spi/spi.h>
17#include <linux/scatterlist.h> 17#include <linux/scatterlist.h>
18#include <linux/mfd/syscon.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/of.h> 20#include <linux/of.h>
20#include <linux/of_gpio.h> 21#include <linux/of_gpio.h>
21#include <linux/of_platform.h> 22#include <linux/of_platform.h>
22#include <linux/property.h> 23#include <linux/property.h>
24#include <linux/regmap.h>
23 25
24#include "spi-dw.h" 26#include "spi-dw.h"
25 27
@@ -28,10 +30,90 @@
28struct dw_spi_mmio { 30struct dw_spi_mmio {
29 struct dw_spi dws; 31 struct dw_spi dws;
30 struct clk *clk; 32 struct clk *clk;
33 void *priv;
31}; 34};
32 35
36#define MSCC_CPU_SYSTEM_CTRL_GENERAL_CTRL 0x24
37#define OCELOT_IF_SI_OWNER_MASK GENMASK(5, 4)
38#define OCELOT_IF_SI_OWNER_OFFSET 4
39#define MSCC_IF_SI_OWNER_SISL 0
40#define MSCC_IF_SI_OWNER_SIBM 1
41#define MSCC_IF_SI_OWNER_SIMC 2
42
43#define MSCC_SPI_MST_SW_MODE 0x14
44#define MSCC_SPI_MST_SW_MODE_SW_PIN_CTRL_MODE BIT(13)
45#define MSCC_SPI_MST_SW_MODE_SW_SPI_CS(x) (x << 5)
46
47struct dw_spi_mscc {
48 struct regmap *syscon;
49 void __iomem *spi_mst;
50};
51
52/*
53 * The Designware SPI controller (referred to as master in the documentation)
54 * automatically deasserts chip select when the tx fifo is empty. The chip
55 * selects then needs to be either driven as GPIOs or, for the first 4 using the
56 * the SPI boot controller registers. the final chip select is an OR gate
57 * between the Designware SPI controller and the SPI boot controller.
58 */
59static void dw_spi_mscc_set_cs(struct spi_device *spi, bool enable)
60{
61 struct dw_spi *dws = spi_master_get_devdata(spi->master);
62 struct dw_spi_mmio *dwsmmio = container_of(dws, struct dw_spi_mmio, dws);
63 struct dw_spi_mscc *dwsmscc = dwsmmio->priv;
64 u32 cs = spi->chip_select;
65
66 if (cs < 4) {
67 u32 sw_mode = MSCC_SPI_MST_SW_MODE_SW_PIN_CTRL_MODE;
68
69 if (!enable)
70 sw_mode |= MSCC_SPI_MST_SW_MODE_SW_SPI_CS(BIT(cs));
71
72 writel(sw_mode, dwsmscc->spi_mst + MSCC_SPI_MST_SW_MODE);
73 }
74
75 dw_spi_set_cs(spi, enable);
76}
77
78static int dw_spi_mscc_init(struct platform_device *pdev,
79 struct dw_spi_mmio *dwsmmio)
80{
81 struct dw_spi_mscc *dwsmscc;
82 struct resource *res;
83
84 dwsmscc = devm_kzalloc(&pdev->dev, sizeof(*dwsmscc), GFP_KERNEL);
85 if (!dwsmscc)
86 return -ENOMEM;
87
88 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
89 dwsmscc->spi_mst = devm_ioremap_resource(&pdev->dev, res);
90 if (IS_ERR(dwsmscc->spi_mst)) {
91 dev_err(&pdev->dev, "SPI_MST region map failed\n");
92 return PTR_ERR(dwsmscc->spi_mst);
93 }
94
95 dwsmscc->syscon = syscon_regmap_lookup_by_compatible("mscc,ocelot-cpu-syscon");
96 if (IS_ERR(dwsmscc->syscon))
97 return PTR_ERR(dwsmscc->syscon);
98
99 /* Deassert all CS */
100 writel(0, dwsmscc->spi_mst + MSCC_SPI_MST_SW_MODE);
101
102 /* Select the owner of the SI interface */
103 regmap_update_bits(dwsmscc->syscon, MSCC_CPU_SYSTEM_CTRL_GENERAL_CTRL,
104 OCELOT_IF_SI_OWNER_MASK,
105 MSCC_IF_SI_OWNER_SIMC << OCELOT_IF_SI_OWNER_OFFSET);
106
107 dwsmmio->dws.set_cs = dw_spi_mscc_set_cs;
108 dwsmmio->priv = dwsmscc;
109
110 return 0;
111}
112
33static int dw_spi_mmio_probe(struct platform_device *pdev) 113static int dw_spi_mmio_probe(struct platform_device *pdev)
34{ 114{
115 int (*init_func)(struct platform_device *pdev,
116 struct dw_spi_mmio *dwsmmio);
35 struct dw_spi_mmio *dwsmmio; 117 struct dw_spi_mmio *dwsmmio;
36 struct dw_spi *dws; 118 struct dw_spi *dws;
37 struct resource *mem; 119 struct resource *mem;
@@ -99,6 +181,13 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
99 } 181 }
100 } 182 }
101 183
184 init_func = device_get_match_data(&pdev->dev);
185 if (init_func) {
186 ret = init_func(pdev, dwsmmio);
187 if (ret)
188 goto out;
189 }
190
102 ret = dw_spi_add_host(&pdev->dev, dws); 191 ret = dw_spi_add_host(&pdev->dev, dws);
103 if (ret) 192 if (ret)
104 goto out; 193 goto out;
@@ -123,6 +212,7 @@ static int dw_spi_mmio_remove(struct platform_device *pdev)
123 212
124static const struct of_device_id dw_spi_mmio_of_match[] = { 213static const struct of_device_id dw_spi_mmio_of_match[] = {
125 { .compatible = "snps,dw-apb-ssi", }, 214 { .compatible = "snps,dw-apb-ssi", },
215 { .compatible = "mscc,ocelot-spi", .data = dw_spi_mscc_init},
126 { /* end of table */} 216 { /* end of table */}
127}; 217};
128MODULE_DEVICE_TABLE(of, dw_spi_mmio_of_match); 218MODULE_DEVICE_TABLE(of, dw_spi_mmio_of_match);