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 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 11 | static int ce4100_spi_probe(struct pci_dev *dev, |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 12 | const struct pci_device_id *ent) |
| 13 | { |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 14 | struct platform_device_info pi; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 15 | int ret; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 16 | struct platform_device *pdev; |
Sebastian Andrzej Siewior | 0f3e1d2 | 2011-02-03 00:31:21 +0530 | [diff] [blame] | 17 | struct pxa2xx_spi_master spi_pdata; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 18 | struct ssp_device *ssp; |
| 19 | |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 20 | ret = pcim_enable_device(dev); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 21 | if (ret) |
| 22 | return ret; |
| 23 | |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 24 | ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI"); |
Mika Westerberg | c134634 | 2013-03-05 12:05:16 +0200 | [diff] [blame] | 25 | if (ret) |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 26 | return ret; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 27 | |
Sebastian Andrzej Siewior | 0f3e1d2 | 2011-02-03 00:31:21 +0530 | [diff] [blame] | 28 | memset(&spi_pdata, 0, sizeof(spi_pdata)); |
| 29 | spi_pdata.num_chipselect = dev->devfn; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 30 | |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 31 | ssp = &spi_pdata.ssp; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 32 | ssp->phys_base = pci_resource_start(dev, 0); |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 33 | ssp->mmio_base = pcim_iomap_table(dev)[0]; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 34 | if (!ssp->mmio_base) { |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 35 | dev_err(&dev->dev, "failed to ioremap() registers\n"); |
| 36 | return -EIO; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 37 | } |
| 38 | ssp->irq = dev->irq; |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 39 | ssp->port_id = dev->devfn; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 40 | ssp->type = PXA25x_SSP; |
| 41 | |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 42 | memset(&pi, 0, sizeof(pi)); |
| 43 | pi.parent = &dev->dev; |
| 44 | pi.name = "pxa2xx-spi"; |
| 45 | pi.id = ssp->port_id; |
| 46 | pi.data = &spi_pdata; |
| 47 | pi.size_data = sizeof(spi_pdata); |
| 48 | |
| 49 | pdev = platform_device_register_full(&pi); |
Wei Yongjun | d77b538 | 2013-02-22 10:52:35 +0800 | [diff] [blame] | 50 | if (IS_ERR(pdev)) |
| 51 | return PTR_ERR(pdev); |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 52 | |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 53 | pci_set_drvdata(dev, pdev); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 54 | |
Mika Westerberg | 0202775 | 2013-01-07 12:44:32 +0200 | [diff] [blame] | 55 | return 0; |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 58 | static void ce4100_spi_remove(struct pci_dev *dev) |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 59 | { |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 60 | struct platform_device *pdev = pci_get_drvdata(dev); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 61 | |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 62 | platform_device_unregister(pdev); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Axel Lin | e290cf2 | 2011-12-15 08:11:25 +0800 | [diff] [blame] | 65 | static DEFINE_PCI_DEVICE_TABLE(ce4100_spi_devices) = { |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 66 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) }, |
| 67 | { }, |
| 68 | }; |
| 69 | MODULE_DEVICE_TABLE(pci, ce4100_spi_devices); |
| 70 | |
| 71 | static struct pci_driver ce4100_spi_driver = { |
| 72 | .name = "ce4100_spi", |
| 73 | .id_table = ce4100_spi_devices, |
| 74 | .probe = ce4100_spi_probe, |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 75 | .remove = ce4100_spi_remove, |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
Axel Lin | 8ebb35f | 2012-04-04 22:29:32 +0800 | [diff] [blame] | 78 | module_pci_driver(ce4100_spi_driver); |
Sebastian Andrzej Siewior | d6ea3df | 2010-11-24 10:17:14 +0100 | [diff] [blame] | 79 | |
| 80 | MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver"); |
| 81 | MODULE_LICENSE("GPL v2"); |
| 82 | MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>"); |