spi-pxa2xx-pci.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #include <linux/clk.h>
  11. #include <linux/clk-provider.h>
  12. enum {
  13. PORT_CE4100,
  14. PORT_BYT,
  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. unsigned long max_clk_rate;
  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. .max_clk_rate = 3686400,
  36. },
  37. [PORT_BYT] = {
  38. .type = LPSS_SSP,
  39. .port_id = 0,
  40. .num_chipselect = 1,
  41. .tx_slave_id = 0,
  42. .tx_chan_id = 0,
  43. .rx_slave_id = 1,
  44. .rx_chan_id = 1,
  45. .max_clk_rate = 50000000,
  46. },
  47. };
  48. static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
  49. const struct pci_device_id *ent)
  50. {
  51. struct platform_device_info pi;
  52. int ret;
  53. struct platform_device *pdev;
  54. struct pxa2xx_spi_master spi_pdata;
  55. struct ssp_device *ssp;
  56. struct pxa_spi_info *c;
  57. char buf[40];
  58. ret = pcim_enable_device(dev);
  59. if (ret)
  60. return ret;
  61. ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
  62. if (ret)
  63. return ret;
  64. c = &spi_info_configs[ent->driver_data];
  65. memset(&spi_pdata, 0, sizeof(spi_pdata));
  66. spi_pdata.num_chipselect = (c->num_chipselect > 0) ?
  67. c->num_chipselect : dev->devfn;
  68. spi_pdata.tx_slave_id = c->tx_slave_id;
  69. spi_pdata.tx_chan_id = c->tx_chan_id;
  70. spi_pdata.rx_slave_id = c->rx_slave_id;
  71. spi_pdata.rx_chan_id = c->rx_chan_id;
  72. spi_pdata.enable_dma = c->rx_slave_id >= 0 && c->tx_slave_id >= 0;
  73. ssp = &spi_pdata.ssp;
  74. ssp->phys_base = pci_resource_start(dev, 0);
  75. ssp->mmio_base = pcim_iomap_table(dev)[0];
  76. if (!ssp->mmio_base) {
  77. dev_err(&dev->dev, "failed to ioremap() registers\n");
  78. return -EIO;
  79. }
  80. ssp->irq = dev->irq;
  81. ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
  82. ssp->type = c->type;
  83. snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
  84. ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL,
  85. CLK_IS_ROOT, c->max_clk_rate);
  86. if (IS_ERR(ssp->clk))
  87. return PTR_ERR(ssp->clk);
  88. memset(&pi, 0, sizeof(pi));
  89. pi.parent = &dev->dev;
  90. pi.name = "pxa2xx-spi";
  91. pi.id = ssp->port_id;
  92. pi.data = &spi_pdata;
  93. pi.size_data = sizeof(spi_pdata);
  94. pdev = platform_device_register_full(&pi);
  95. if (IS_ERR(pdev)) {
  96. clk_unregister(ssp->clk);
  97. return PTR_ERR(pdev);
  98. }
  99. pci_set_drvdata(dev, pdev);
  100. return 0;
  101. }
  102. static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
  103. {
  104. struct platform_device *pdev = pci_get_drvdata(dev);
  105. struct pxa2xx_spi_master *spi_pdata;
  106. spi_pdata = dev_get_platdata(&pdev->dev);
  107. platform_device_unregister(pdev);
  108. clk_unregister(spi_pdata->ssp.clk);
  109. }
  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 },
  113. { },
  114. };
  115. MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices);
  116. static struct pci_driver pxa2xx_spi_pci_driver = {
  117. .name = "pxa2xx_spi_pci",
  118. .id_table = pxa2xx_spi_pci_devices,
  119. .probe = pxa2xx_spi_pci_probe,
  120. .remove = pxa2xx_spi_pci_remove,
  121. };
  122. module_pci_driver(pxa2xx_spi_pci_driver);
  123. MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver");
  124. MODULE_LICENSE("GPL v2");
  125. MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");