Commit | Line | Data |
---|---|---|
d6ea3df0 SAS |
1 | /* |
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> | |
d7614de4 | 8 | #include <linux/module.h> |
d6ea3df0 SAS |
9 | #include <linux/spi/pxa2xx_spi.h> |
10 | ||
d6ba32d5 CCE |
11 | enum { |
12 | PORT_CE4100, | |
13 | PORT_BYT, | |
14 | }; | |
15 | ||
16 | struct pxa_spi_info { | |
17 | enum pxa_ssp_type type; | |
18 | int port_id; | |
19 | int num_chipselect; | |
20 | int tx_slave_id; | |
21 | int tx_chan_id; | |
22 | int rx_slave_id; | |
23 | int rx_chan_id; | |
24 | }; | |
25 | ||
26 | static struct pxa_spi_info spi_info_configs[] = { | |
27 | [PORT_CE4100] = { | |
28 | .type = PXA25x_SSP, | |
29 | .port_id = -1, | |
30 | .num_chipselect = -1, | |
31 | .tx_slave_id = -1, | |
32 | .tx_chan_id = -1, | |
33 | .rx_slave_id = -1, | |
34 | .rx_chan_id = -1, | |
35 | }, | |
36 | [PORT_BYT] = { | |
37 | .type = LPSS_SSP, | |
38 | .port_id = 0, | |
39 | .num_chipselect = 1, | |
40 | .tx_slave_id = 0, | |
41 | .tx_chan_id = 0, | |
42 | .rx_slave_id = 1, | |
43 | .rx_chan_id = 1, | |
44 | }, | |
45 | }; | |
46 | ||
47 | static int pxa2xx_spi_pci_probe(struct pci_dev *dev, | |
d6ea3df0 SAS |
48 | const struct pci_device_id *ent) |
49 | { | |
0202775b | 50 | struct platform_device_info pi; |
d6ea3df0 | 51 | int ret; |
d6ea3df0 | 52 | struct platform_device *pdev; |
0f3e1d27 | 53 | struct pxa2xx_spi_master spi_pdata; |
d6ea3df0 | 54 | struct ssp_device *ssp; |
d6ba32d5 | 55 | struct pxa_spi_info *c; |
d6ea3df0 | 56 | |
0202775b | 57 | ret = pcim_enable_device(dev); |
d6ea3df0 SAS |
58 | if (ret) |
59 | return ret; | |
60 | ||
0202775b | 61 | ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI"); |
c1346340 | 62 | if (ret) |
d6ea3df0 | 63 | return ret; |
d6ea3df0 | 64 | |
d6ba32d5 CCE |
65 | c = &spi_info_configs[ent->driver_data]; |
66 | ||
0f3e1d27 | 67 | memset(&spi_pdata, 0, sizeof(spi_pdata)); |
d6ba32d5 CCE |
68 | spi_pdata.num_chipselect = (c->num_chipselect > 0) ? |
69 | c->num_chipselect : dev->devfn; | |
70 | spi_pdata.tx_slave_id = c->tx_slave_id; | |
71 | spi_pdata.tx_chan_id = c->tx_chan_id; | |
72 | spi_pdata.rx_slave_id = c->rx_slave_id; | |
73 | spi_pdata.rx_chan_id = c->rx_chan_id; | |
74 | spi_pdata.enable_dma = c->rx_slave_id >= 0 && c->tx_slave_id >= 0; | |
d6ea3df0 | 75 | |
851bacf5 | 76 | ssp = &spi_pdata.ssp; |
d6ea3df0 | 77 | ssp->phys_base = pci_resource_start(dev, 0); |
0202775b | 78 | ssp->mmio_base = pcim_iomap_table(dev)[0]; |
d6ea3df0 | 79 | if (!ssp->mmio_base) { |
0202775b MW |
80 | dev_err(&dev->dev, "failed to ioremap() registers\n"); |
81 | return -EIO; | |
d6ea3df0 SAS |
82 | } |
83 | ssp->irq = dev->irq; | |
d6ba32d5 CCE |
84 | ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn; |
85 | ssp->type = c->type; | |
d6ea3df0 | 86 | |
0202775b MW |
87 | memset(&pi, 0, sizeof(pi)); |
88 | pi.parent = &dev->dev; | |
89 | pi.name = "pxa2xx-spi"; | |
90 | pi.id = ssp->port_id; | |
91 | pi.data = &spi_pdata; | |
92 | pi.size_data = sizeof(spi_pdata); | |
d6ea3df0 | 93 | |
0202775b | 94 | pdev = platform_device_register_full(&pi); |
d77b5382 WY |
95 | if (IS_ERR(pdev)) |
96 | return PTR_ERR(pdev); | |
d6ea3df0 | 97 | |
851bacf5 | 98 | pci_set_drvdata(dev, pdev); |
d6ea3df0 | 99 | |
0202775b | 100 | return 0; |
d6ea3df0 SAS |
101 | } |
102 | ||
d6ba32d5 | 103 | static void pxa2xx_spi_pci_remove(struct pci_dev *dev) |
d6ea3df0 | 104 | { |
851bacf5 | 105 | struct platform_device *pdev = pci_get_drvdata(dev); |
d6ea3df0 | 106 | |
851bacf5 | 107 | platform_device_unregister(pdev); |
d6ea3df0 SAS |
108 | } |
109 | ||
d6ba32d5 CCE |
110 | static const struct pci_device_id pxa2xx_spi_pci_devices[] = { |
111 | { PCI_VDEVICE(INTEL, 0x2e6a), PORT_CE4100 }, | |
112 | { PCI_VDEVICE(INTEL, 0x0f0e), PORT_BYT }, | |
d6ea3df0 SAS |
113 | { }, |
114 | }; | |
d6ba32d5 | 115 | MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices); |
d6ea3df0 | 116 | |
d6ba32d5 CCE |
117 | static struct pci_driver pxa2xx_spi_pci_driver = { |
118 | .name = "pxa2xx_spi_pci", | |
119 | .id_table = pxa2xx_spi_pci_devices, | |
120 | .probe = pxa2xx_spi_pci_probe, | |
121 | .remove = pxa2xx_spi_pci_remove, | |
d6ea3df0 SAS |
122 | }; |
123 | ||
d6ba32d5 | 124 | module_pci_driver(pxa2xx_spi_pci_driver); |
d6ea3df0 | 125 | |
d6ba32d5 | 126 | MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver"); |
d6ea3df0 SAS |
127 | MODULE_LICENSE("GPL v2"); |
128 | MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>"); |