2 * CE4100's SPI device is more or less the same one as found on PXA
4 * Copyright (C) 2016, Intel Corporation
6 #include <linux/clk-provider.h>
7 #include <linux/module.h>
8 #include <linux/of_device.h>
10 #include <linux/platform_device.h>
11 #include <linux/spi/pxa2xx_spi.h>
13 #include <linux/dmaengine.h>
14 #include <linux/platform_data/dma-dw.h>
29 enum pxa_ssp_type type;
32 unsigned long max_clk_rate;
34 /* DMA channel request parameters */
35 bool (*dma_filter)(struct dma_chan *chan, void *param);
39 int (*setup)(struct pci_dev *pdev, struct pxa_spi_info *c);
42 static struct dw_dma_slave byt_tx_param = { .dst_id = 0 };
43 static struct dw_dma_slave byt_rx_param = { .src_id = 1 };
45 static struct dw_dma_slave bsw0_tx_param = { .dst_id = 0 };
46 static struct dw_dma_slave bsw0_rx_param = { .src_id = 1 };
47 static struct dw_dma_slave bsw1_tx_param = { .dst_id = 6 };
48 static struct dw_dma_slave bsw1_rx_param = { .src_id = 7 };
49 static struct dw_dma_slave bsw2_tx_param = { .dst_id = 8 };
50 static struct dw_dma_slave bsw2_rx_param = { .src_id = 9 };
52 static struct dw_dma_slave lpt1_tx_param = { .dst_id = 0 };
53 static struct dw_dma_slave lpt1_rx_param = { .src_id = 1 };
54 static struct dw_dma_slave lpt0_tx_param = { .dst_id = 2 };
55 static struct dw_dma_slave lpt0_rx_param = { .src_id = 3 };
57 static bool lpss_dma_filter(struct dma_chan *chan, void *param)
59 struct dw_dma_slave *dws = param;
61 if (dws->dma_dev != chan->device->dev)
68 static int lpss_spi_setup(struct pci_dev *dev, struct pxa_spi_info *c)
70 struct pci_dev *dma_dev;
72 c->num_chipselect = 1;
73 c->max_clk_rate = 50000000;
75 dma_dev = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
78 struct dw_dma_slave *slave = c->tx_param;
80 slave->dma_dev = &dma_dev->dev;
86 struct dw_dma_slave *slave = c->rx_param;
88 slave->dma_dev = &dma_dev->dev;
93 c->dma_filter = lpss_dma_filter;
97 static int mrfld_spi_setup(struct pci_dev *dev, struct pxa_spi_info *c)
99 switch (PCI_FUNC(dev->devfn)) {
102 c->num_chipselect = 1;
106 c->num_chipselect = 4;
110 c->num_chipselect = 1;
118 static struct pxa_spi_info spi_info_configs[] = {
122 .num_chipselect = -1,
123 .max_clk_rate = 3686400,
126 .type = LPSS_BYT_SSP,
128 .setup = lpss_spi_setup,
129 .tx_param = &byt_tx_param,
130 .rx_param = &byt_rx_param,
133 .type = LPSS_BSW_SSP,
135 .setup = lpss_spi_setup,
136 .tx_param = &bsw0_tx_param,
137 .rx_param = &bsw0_rx_param,
140 .type = LPSS_BSW_SSP,
142 .setup = lpss_spi_setup,
143 .tx_param = &bsw1_tx_param,
144 .rx_param = &bsw1_rx_param,
147 .type = LPSS_BSW_SSP,
149 .setup = lpss_spi_setup,
150 .tx_param = &bsw2_tx_param,
151 .rx_param = &bsw2_rx_param,
155 .max_clk_rate = 25000000,
156 .setup = mrfld_spi_setup,
158 [PORT_QUARK_X1000] = {
159 .type = QUARK_X1000_SSP,
162 .max_clk_rate = 50000000,
165 .type = LPSS_LPT_SSP,
167 .setup = lpss_spi_setup,
168 .tx_param = &lpt0_tx_param,
169 .rx_param = &lpt0_rx_param,
172 .type = LPSS_LPT_SSP,
174 .setup = lpss_spi_setup,
175 .tx_param = &lpt1_tx_param,
176 .rx_param = &lpt1_rx_param,
180 static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
181 const struct pci_device_id *ent)
183 struct platform_device_info pi;
185 struct platform_device *pdev;
186 struct pxa2xx_spi_master spi_pdata;
187 struct ssp_device *ssp;
188 struct pxa_spi_info *c;
191 ret = pcim_enable_device(dev);
195 ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
199 c = &spi_info_configs[ent->driver_data];
201 ret = c->setup(dev, c);
206 memset(&spi_pdata, 0, sizeof(spi_pdata));
207 spi_pdata.num_chipselect = (c->num_chipselect > 0) ? c->num_chipselect : dev->devfn;
208 spi_pdata.dma_filter = c->dma_filter;
209 spi_pdata.tx_param = c->tx_param;
210 spi_pdata.rx_param = c->rx_param;
211 spi_pdata.enable_dma = c->rx_param && c->tx_param;
213 ssp = &spi_pdata.ssp;
214 ssp->phys_base = pci_resource_start(dev, 0);
215 ssp->mmio_base = pcim_iomap_table(dev)[0];
217 ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
220 snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
221 ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
223 if (IS_ERR(ssp->clk))
224 return PTR_ERR(ssp->clk);
226 memset(&pi, 0, sizeof(pi));
227 pi.fwnode = dev->dev.fwnode;
228 pi.parent = &dev->dev;
229 pi.name = "pxa2xx-spi";
230 pi.id = ssp->port_id;
231 pi.data = &spi_pdata;
232 pi.size_data = sizeof(spi_pdata);
234 pdev = platform_device_register_full(&pi);
236 clk_unregister(ssp->clk);
237 return PTR_ERR(pdev);
240 pci_set_drvdata(dev, pdev);
245 static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
247 struct platform_device *pdev = pci_get_drvdata(dev);
248 struct pxa2xx_spi_master *spi_pdata;
250 spi_pdata = dev_get_platdata(&pdev->dev);
252 platform_device_unregister(pdev);
253 clk_unregister(spi_pdata->ssp.clk);
256 static const struct pci_device_id pxa2xx_spi_pci_devices[] = {
257 { PCI_VDEVICE(INTEL, 0x0935), PORT_QUARK_X1000 },
258 { PCI_VDEVICE(INTEL, 0x0f0e), PORT_BYT },
259 { PCI_VDEVICE(INTEL, 0x1194), PORT_MRFLD },
260 { PCI_VDEVICE(INTEL, 0x228e), PORT_BSW0 },
261 { PCI_VDEVICE(INTEL, 0x2290), PORT_BSW1 },
262 { PCI_VDEVICE(INTEL, 0x22ac), PORT_BSW2 },
263 { PCI_VDEVICE(INTEL, 0x2e6a), PORT_CE4100 },
264 { PCI_VDEVICE(INTEL, 0x9ce5), PORT_LPT0 },
265 { PCI_VDEVICE(INTEL, 0x9ce6), PORT_LPT1 },
268 MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices);
270 static struct pci_driver pxa2xx_spi_pci_driver = {
271 .name = "pxa2xx_spi_pci",
272 .id_table = pxa2xx_spi_pci_devices,
273 .probe = pxa2xx_spi_pci_probe,
274 .remove = pxa2xx_spi_pci_remove,
277 module_pci_driver(pxa2xx_spi_pci_driver);
279 MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver");
280 MODULE_LICENSE("GPL v2");
281 MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");