blob: 74bc18775658667617464aa865a7fb939161c438 [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>
10
Grant Likelyfd4a3192012-12-07 16:57:14 +000011static int ce4100_spi_probe(struct pci_dev *dev,
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010012 const struct pci_device_id *ent)
13{
Mika Westerberg02027752013-01-07 12:44:32 +020014 struct platform_device_info pi;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010015 int ret;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010016 struct platform_device *pdev;
Sebastian Andrzej Siewior0f3e1d22011-02-03 00:31:21 +053017 struct pxa2xx_spi_master spi_pdata;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010018 struct ssp_device *ssp;
19
Mika Westerberg02027752013-01-07 12:44:32 +020020 ret = pcim_enable_device(dev);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010021 if (ret)
22 return ret;
23
Mika Westerberg02027752013-01-07 12:44:32 +020024 ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
Mika Westerbergc1346342013-03-05 12:05:16 +020025 if (ret)
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010026 return ret;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010027
Sebastian Andrzej Siewior0f3e1d22011-02-03 00:31:21 +053028 memset(&spi_pdata, 0, sizeof(spi_pdata));
29 spi_pdata.num_chipselect = dev->devfn;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010030
Mika Westerberg851bacf2013-01-07 12:44:33 +020031 ssp = &spi_pdata.ssp;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010032 ssp->phys_base = pci_resource_start(dev, 0);
Mika Westerberg02027752013-01-07 12:44:32 +020033 ssp->mmio_base = pcim_iomap_table(dev)[0];
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010034 if (!ssp->mmio_base) {
Mika Westerberg02027752013-01-07 12:44:32 +020035 dev_err(&dev->dev, "failed to ioremap() registers\n");
36 return -EIO;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010037 }
38 ssp->irq = dev->irq;
Mika Westerberg02027752013-01-07 12:44:32 +020039 ssp->port_id = dev->devfn;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010040 ssp->type = PXA25x_SSP;
41
Mika Westerberg02027752013-01-07 12:44:32 +020042 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 Yongjund77b5382013-02-22 10:52:35 +080050 if (IS_ERR(pdev))
51 return PTR_ERR(pdev);
Mika Westerberg02027752013-01-07 12:44:32 +020052
Mika Westerberg851bacf2013-01-07 12:44:33 +020053 pci_set_drvdata(dev, pdev);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010054
Mika Westerberg02027752013-01-07 12:44:32 +020055 return 0;
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010056}
57
Grant Likelyfd4a3192012-12-07 16:57:14 +000058static void ce4100_spi_remove(struct pci_dev *dev)
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010059{
Mika Westerberg851bacf2013-01-07 12:44:33 +020060 struct platform_device *pdev = pci_get_drvdata(dev);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010061
Mika Westerberg851bacf2013-01-07 12:44:33 +020062 platform_device_unregister(pdev);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010063}
64
Axel Line290cf22011-12-15 08:11:25 +080065static DEFINE_PCI_DEVICE_TABLE(ce4100_spi_devices) = {
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010066 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) },
67 { },
68};
69MODULE_DEVICE_TABLE(pci, ce4100_spi_devices);
70
71static struct pci_driver ce4100_spi_driver = {
72 .name = "ce4100_spi",
73 .id_table = ce4100_spi_devices,
74 .probe = ce4100_spi_probe,
Grant Likelyfd4a3192012-12-07 16:57:14 +000075 .remove = ce4100_spi_remove,
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010076};
77
Axel Lin8ebb35f2012-04-04 22:29:32 +080078module_pci_driver(ce4100_spi_driver);
Sebastian Andrzej Siewiord6ea3df2010-11-24 10:17:14 +010079
80MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver");
81MODULE_LICENSE("GPL v2");
82MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");