spi-pxa2xx-pci.c 2.9 KB

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