Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 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> |
Paul Gortmaker | d7614de | 2011-07-03 15:44:29 -0400 | [diff] [blame] | 8 | #include <linux/module.h> |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 9 | #include <linux/spi/pxa2xx_spi.h> |
| 10 | |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 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, |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 48 | const struct pci_device_id *ent) |
| 49 | { |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 50 | struct platform_device_info pi; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 51 | int ret; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 52 | struct platform_device *pdev; |
Sebastian Andrzej Siewior | 0f3e1d2 | 2011-02-03 00:31:21 +0530 | [diff] [blame] | 53 | struct pxa2xx_spi_master spi_pdata; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 54 | struct ssp_device *ssp; |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 55 | struct pxa_spi_info *c; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 56 | |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 57 | ret = pcim_enable_device(dev); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 58 | if (ret) |
| 59 | return ret; |
| 60 | |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 61 | ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI"); |
Mika Westerberg | c134634 | 2013-03-05 12:05:16 +0200 | [diff] [blame] | 62 | if (ret) |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 63 | return ret; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 64 | |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 65 | c = &spi_info_configs[ent->driver_data]; |
| 66 | |
Sebastian Andrzej Siewior | 0f3e1d2 | 2011-02-03 00:31:21 +0530 | [diff] [blame] | 67 | memset(&spi_pdata, 0, sizeof(spi_pdata)); |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 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; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 75 | |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 76 | ssp = &spi_pdata.ssp; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 77 | ssp->phys_base = pci_resource_start(dev, 0); |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 78 | ssp->mmio_base = pcim_iomap_table(dev)[0]; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 79 | if (!ssp->mmio_base) { |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 80 | dev_err(&dev->dev, "failed to ioremap() registers\n"); |
| 81 | return -EIO; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 82 | } |
| 83 | ssp->irq = dev->irq; |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 84 | ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn; |
| 85 | ssp->type = c->type; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 86 | |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 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); |
| 93 | |
| 94 | pdev = platform_device_register_full(&pi); |
Wei Yongjun | d77b538 | 2013-02-22 10:52:35 +0800 | [diff] [blame] | 95 | if (IS_ERR(pdev)) |
| 96 | return PTR_ERR(pdev); |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 97 | |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 98 | pci_set_drvdata(dev, pdev); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 99 | |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 100 | return 0; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 103 | static void pxa2xx_spi_pci_remove(struct pci_dev *dev) |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 104 | { |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 105 | struct platform_device *pdev = pci_get_drvdata(dev); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 106 | |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 107 | platform_device_unregister(pdev); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 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 }, |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 113 | { }, |
| 114 | }; |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 115 | MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 116 | |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 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, |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 122 | }; |
| 123 | |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 124 | module_pci_driver(pxa2xx_spi_pci_driver); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 125 | |
Chew, Chiau Ee | d6ba32d | 2014-04-18 00:26:06 +0800 | [diff] [blame^] | 126 | MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver"); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 127 | MODULE_LICENSE("GPL v2"); |
| 128 | MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>"); |