blob: 520ed1dd57804320859bbef42fa5e15f6a487213 [file] [log] [blame]
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +01001/*
2 * CE4100's SPI device is more or less the same one as found on PXA
3 *
4 */
5#include <linux/pci.h>
6#include <linux/platform_device.h>
7#include <linux/of_device.h>
Paul Gortmakerd7614de2011-07-03 15:44:29 -04008#include <linux/module.h>
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +01009#include <linux/spi/pxa2xx_spi.h>
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +080010#include <linux/clk-provider.h>
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010011
Mika Westerbergb729bf32014-08-19 20:29:19 +030012#include <linux/dmaengine.h>
13#include <linux/platform_data/dma-dw.h>
14
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +080015enum {
16 PORT_CE4100,
17 PORT_BYT,
Mika Westerberg39d36532014-08-19 20:29:21 +030018 PORT_BSW0,
19 PORT_BSW1,
20 PORT_BSW2,
Weike Chene5262d02014-11-26 02:35:10 -080021 PORT_QUARK_X1000,
Leif Liddycaba2482016-02-20 20:20:22 +010022 PORT_LPT,
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +080023};
24
25struct pxa_spi_info {
26 enum pxa_ssp_type type;
27 int port_id;
28 int num_chipselect;
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +080029 unsigned long max_clk_rate;
Mika Westerbergb729bf32014-08-19 20:29:19 +030030
31 /* DMA channel request parameters */
32 void *tx_param;
33 void *rx_param;
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +080034};
35
Mika Westerbergb729bf32014-08-19 20:29:19 +030036static struct dw_dma_slave byt_tx_param = { .dst_id = 0 };
37static struct dw_dma_slave byt_rx_param = { .src_id = 1 };
38
Mika Westerberg39d36532014-08-19 20:29:21 +030039static struct dw_dma_slave bsw0_tx_param = { .dst_id = 0 };
40static struct dw_dma_slave bsw0_rx_param = { .src_id = 1 };
41static struct dw_dma_slave bsw1_tx_param = { .dst_id = 6 };
42static struct dw_dma_slave bsw1_rx_param = { .src_id = 7 };
43static struct dw_dma_slave bsw2_tx_param = { .dst_id = 8 };
44static struct dw_dma_slave bsw2_rx_param = { .src_id = 9 };
45
Leif Liddycaba2482016-02-20 20:20:22 +010046static struct dw_dma_slave lpt_tx_param = { .dst_id = 0 };
47static struct dw_dma_slave lpt_rx_param = { .src_id = 1 };
48
Mika Westerbergb729bf32014-08-19 20:29:19 +030049static bool lpss_dma_filter(struct dma_chan *chan, void *param)
50{
51 struct dw_dma_slave *dws = param;
52
53 if (dws->dma_dev != chan->device->dev)
54 return false;
55
56 chan->private = dws;
57 return true;
58}
59
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +080060static struct pxa_spi_info spi_info_configs[] = {
61 [PORT_CE4100] = {
62 .type = PXA25x_SSP,
63 .port_id = -1,
64 .num_chipselect = -1,
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +080065 .max_clk_rate = 3686400,
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +080066 },
67 [PORT_BYT] = {
Jarkko Nikula03fbf482015-06-04 16:55:10 +030068 .type = LPSS_BYT_SSP,
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +080069 .port_id = 0,
70 .num_chipselect = 1,
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +080071 .max_clk_rate = 50000000,
Mika Westerbergb729bf32014-08-19 20:29:19 +030072 .tx_param = &byt_tx_param,
73 .rx_param = &byt_rx_param,
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +080074 },
Mika Westerberg39d36532014-08-19 20:29:21 +030075 [PORT_BSW0] = {
Jarkko Nikula03fbf482015-06-04 16:55:10 +030076 .type = LPSS_BYT_SSP,
Mika Westerberg39d36532014-08-19 20:29:21 +030077 .port_id = 0,
78 .num_chipselect = 1,
79 .max_clk_rate = 50000000,
80 .tx_param = &bsw0_tx_param,
81 .rx_param = &bsw0_rx_param,
82 },
83 [PORT_BSW1] = {
Jarkko Nikula03fbf482015-06-04 16:55:10 +030084 .type = LPSS_BYT_SSP,
Mika Westerberg39d36532014-08-19 20:29:21 +030085 .port_id = 1,
86 .num_chipselect = 1,
87 .max_clk_rate = 50000000,
88 .tx_param = &bsw1_tx_param,
89 .rx_param = &bsw1_rx_param,
90 },
91 [PORT_BSW2] = {
Jarkko Nikula03fbf482015-06-04 16:55:10 +030092 .type = LPSS_BYT_SSP,
Mika Westerberg39d36532014-08-19 20:29:21 +030093 .port_id = 2,
94 .num_chipselect = 1,
95 .max_clk_rate = 50000000,
96 .tx_param = &bsw2_tx_param,
97 .rx_param = &bsw2_rx_param,
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +080098 },
Weike Chene5262d02014-11-26 02:35:10 -080099 [PORT_QUARK_X1000] = {
100 .type = QUARK_X1000_SSP,
101 .port_id = -1,
102 .num_chipselect = 1,
103 .max_clk_rate = 50000000,
104 },
Leif Liddycaba2482016-02-20 20:20:22 +0100105 [PORT_LPT] = {
106 .type = LPSS_LPT_SSP,
107 .port_id = 0,
108 .num_chipselect = 1,
109 .max_clk_rate = 50000000,
110 .tx_param = &lpt_tx_param,
111 .rx_param = &lpt_rx_param,
112 },
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800113};
114
115static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100116 const struct pci_device_id *ent)
117{
Mika Westerberg02027752013-01-07 12:44:32 +0200118 struct platform_device_info pi;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100119 int ret;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100120 struct platform_device *pdev;
Sebastian Andrzej Siewior0f3e1d22011-02-03 00:31:21 +0530121 struct pxa2xx_spi_master spi_pdata;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100122 struct ssp_device *ssp;
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800123 struct pxa_spi_info *c;
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +0800124 char buf[40];
Mika Westerbergb729bf32014-08-19 20:29:19 +0300125 struct pci_dev *dma_dev;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100126
Mika Westerberg02027752013-01-07 12:44:32 +0200127 ret = pcim_enable_device(dev);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100128 if (ret)
129 return ret;
130
Mika Westerberg02027752013-01-07 12:44:32 +0200131 ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
Mika Westerbergc1346342013-03-05 12:05:16 +0200132 if (ret)
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100133 return ret;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100134
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800135 c = &spi_info_configs[ent->driver_data];
136
Sebastian Andrzej Siewior0f3e1d22011-02-03 00:31:21 +0530137 memset(&spi_pdata, 0, sizeof(spi_pdata));
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800138 spi_pdata.num_chipselect = (c->num_chipselect > 0) ?
139 c->num_chipselect : dev->devfn;
Mika Westerbergb729bf32014-08-19 20:29:19 +0300140
141 dma_dev = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
142
143 if (c->tx_param) {
144 struct dw_dma_slave *slave = c->tx_param;
145
146 slave->dma_dev = &dma_dev->dev;
147 slave->src_master = 1;
148 slave->dst_master = 0;
149 }
150
151 if (c->rx_param) {
152 struct dw_dma_slave *slave = c->rx_param;
153
154 slave->dma_dev = &dma_dev->dev;
155 slave->src_master = 1;
156 slave->dst_master = 0;
157 }
158
159 spi_pdata.dma_filter = lpss_dma_filter;
160 spi_pdata.tx_param = c->tx_param;
161 spi_pdata.rx_param = c->rx_param;
162 spi_pdata.enable_dma = c->rx_param && c->tx_param;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100163
Mika Westerberg851bacf2013-01-07 12:44:33 +0200164 ssp = &spi_pdata.ssp;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100165 ssp->phys_base = pci_resource_start(dev, 0);
Mika Westerberg02027752013-01-07 12:44:32 +0200166 ssp->mmio_base = pcim_iomap_table(dev)[0];
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100167 if (!ssp->mmio_base) {
Mika Westerberg02027752013-01-07 12:44:32 +0200168 dev_err(&dev->dev, "failed to ioremap() registers\n");
169 return -EIO;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100170 }
171 ssp->irq = dev->irq;
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800172 ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
173 ssp->type = c->type;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100174
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +0800175 snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
176 ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL,
177 CLK_IS_ROOT, c->max_clk_rate);
178 if (IS_ERR(ssp->clk))
179 return PTR_ERR(ssp->clk);
180
Mika Westerberg02027752013-01-07 12:44:32 +0200181 memset(&pi, 0, sizeof(pi));
182 pi.parent = &dev->dev;
183 pi.name = "pxa2xx-spi";
184 pi.id = ssp->port_id;
185 pi.data = &spi_pdata;
186 pi.size_data = sizeof(spi_pdata);
187
188 pdev = platform_device_register_full(&pi);
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +0800189 if (IS_ERR(pdev)) {
190 clk_unregister(ssp->clk);
Wei Yongjund77b5382013-02-22 10:52:35 +0800191 return PTR_ERR(pdev);
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +0800192 }
Mika Westerberg02027752013-01-07 12:44:32 +0200193
Mika Westerberg851bacf2013-01-07 12:44:33 +0200194 pci_set_drvdata(dev, pdev);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100195
Mika Westerberg02027752013-01-07 12:44:32 +0200196 return 0;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100197}
198
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800199static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100200{
Mika Westerberg851bacf2013-01-07 12:44:33 +0200201 struct platform_device *pdev = pci_get_drvdata(dev);
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +0800202 struct pxa2xx_spi_master *spi_pdata;
203
204 spi_pdata = dev_get_platdata(&pdev->dev);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100205
Mika Westerberg851bacf2013-01-07 12:44:33 +0200206 platform_device_unregister(pdev);
Chew, Chiau Eeafa93c92014-07-25 01:10:54 +0800207 clk_unregister(spi_pdata->ssp.clk);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100208}
209
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800210static const struct pci_device_id pxa2xx_spi_pci_devices[] = {
211 { PCI_VDEVICE(INTEL, 0x2e6a), PORT_CE4100 },
Weike Chene5262d02014-11-26 02:35:10 -0800212 { PCI_VDEVICE(INTEL, 0x0935), PORT_QUARK_X1000 },
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800213 { PCI_VDEVICE(INTEL, 0x0f0e), PORT_BYT },
Mika Westerberg39d36532014-08-19 20:29:21 +0300214 { PCI_VDEVICE(INTEL, 0x228e), PORT_BSW0 },
215 { PCI_VDEVICE(INTEL, 0x2290), PORT_BSW1 },
216 { PCI_VDEVICE(INTEL, 0x22ac), PORT_BSW2 },
Leif Liddycaba2482016-02-20 20:20:22 +0100217 { PCI_VDEVICE(INTEL, 0x9ce6), PORT_LPT },
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100218 { },
219};
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800220MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100221
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800222static struct pci_driver pxa2xx_spi_pci_driver = {
223 .name = "pxa2xx_spi_pci",
224 .id_table = pxa2xx_spi_pci_devices,
225 .probe = pxa2xx_spi_pci_probe,
226 .remove = pxa2xx_spi_pci_remove,
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100227};
228
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800229module_pci_driver(pxa2xx_spi_pci_driver);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100230
Chew, Chiau Eed6ba32d2014-04-18 00:26:06 +0800231MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver");
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +0100232MODULE_LICENSE("GPL v2");
233MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");