spi-pxa2xx-pci.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #include <linux/dmaengine.h>
  13. #include <linux/platform_data/dma-dw.h>
  14. enum {
  15. PORT_CE4100,
  16. PORT_BYT,
  17. PORT_BSW0,
  18. PORT_BSW1,
  19. PORT_BSW2,
  20. };
  21. struct pxa_spi_info {
  22. enum pxa_ssp_type type;
  23. int port_id;
  24. int num_chipselect;
  25. unsigned long max_clk_rate;
  26. /* DMA channel request parameters */
  27. void *tx_param;
  28. void *rx_param;
  29. };
  30. static struct dw_dma_slave byt_tx_param = { .dst_id = 0 };
  31. static struct dw_dma_slave byt_rx_param = { .src_id = 1 };
  32. static struct dw_dma_slave bsw0_tx_param = { .dst_id = 0 };
  33. static struct dw_dma_slave bsw0_rx_param = { .src_id = 1 };
  34. static struct dw_dma_slave bsw1_tx_param = { .dst_id = 6 };
  35. static struct dw_dma_slave bsw1_rx_param = { .src_id = 7 };
  36. static struct dw_dma_slave bsw2_tx_param = { .dst_id = 8 };
  37. static struct dw_dma_slave bsw2_rx_param = { .src_id = 9 };
  38. static bool lpss_dma_filter(struct dma_chan *chan, void *param)
  39. {
  40. struct dw_dma_slave *dws = param;
  41. if (dws->dma_dev != chan->device->dev)
  42. return false;
  43. chan->private = dws;
  44. return true;
  45. }
  46. static struct pxa_spi_info spi_info_configs[] = {
  47. [PORT_CE4100] = {
  48. .type = PXA25x_SSP,
  49. .port_id = -1,
  50. .num_chipselect = -1,
  51. .max_clk_rate = 3686400,
  52. },
  53. [PORT_BYT] = {
  54. .type = LPSS_SSP,
  55. .port_id = 0,
  56. .num_chipselect = 1,
  57. .max_clk_rate = 50000000,
  58. .tx_param = &byt_tx_param,
  59. .rx_param = &byt_rx_param,
  60. },
  61. [PORT_BSW0] = {
  62. .type = LPSS_SSP,
  63. .port_id = 0,
  64. .num_chipselect = 1,
  65. .max_clk_rate = 50000000,
  66. .tx_param = &bsw0_tx_param,
  67. .rx_param = &bsw0_rx_param,
  68. },
  69. [PORT_BSW1] = {
  70. .type = LPSS_SSP,
  71. .port_id = 1,
  72. .num_chipselect = 1,
  73. .max_clk_rate = 50000000,
  74. .tx_param = &bsw1_tx_param,
  75. .rx_param = &bsw1_rx_param,
  76. },
  77. [PORT_BSW2] = {
  78. .type = LPSS_SSP,
  79. .port_id = 2,
  80. .num_chipselect = 1,
  81. .max_clk_rate = 50000000,
  82. .tx_param = &bsw2_tx_param,
  83. .rx_param = &bsw2_rx_param,
  84. },
  85. };
  86. static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
  87. const struct pci_device_id *ent)
  88. {
  89. struct platform_device_info pi;
  90. int ret;
  91. struct platform_device *pdev;
  92. struct pxa2xx_spi_master spi_pdata;
  93. struct ssp_device *ssp;
  94. struct pxa_spi_info *c;
  95. char buf[40];
  96. struct pci_dev *dma_dev;
  97. ret = pcim_enable_device(dev);
  98. if (ret)
  99. return ret;
  100. ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
  101. if (ret)
  102. return ret;
  103. c = &spi_info_configs[ent->driver_data];
  104. memset(&spi_pdata, 0, sizeof(spi_pdata));
  105. spi_pdata.num_chipselect = (c->num_chipselect > 0) ?
  106. c->num_chipselect : dev->devfn;
  107. dma_dev = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
  108. if (c->tx_param) {
  109. struct dw_dma_slave *slave = c->tx_param;
  110. slave->dma_dev = &dma_dev->dev;
  111. slave->src_master = 1;
  112. slave->dst_master = 0;
  113. }
  114. if (c->rx_param) {
  115. struct dw_dma_slave *slave = c->rx_param;
  116. slave->dma_dev = &dma_dev->dev;
  117. slave->src_master = 1;
  118. slave->dst_master = 0;
  119. }
  120. spi_pdata.dma_filter = lpss_dma_filter;
  121. spi_pdata.tx_param = c->tx_param;
  122. spi_pdata.rx_param = c->rx_param;
  123. spi_pdata.enable_dma = c->rx_param && c->tx_param;
  124. ssp = &spi_pdata.ssp;
  125. ssp->phys_base = pci_resource_start(dev, 0);
  126. ssp->mmio_base = pcim_iomap_table(dev)[0];
  127. if (!ssp->mmio_base) {
  128. dev_err(&dev->dev, "failed to ioremap() registers\n");
  129. return -EIO;
  130. }
  131. ssp->irq = dev->irq;
  132. ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
  133. ssp->type = c->type;
  134. snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
  135. ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL,
  136. CLK_IS_ROOT, c->max_clk_rate);
  137. if (IS_ERR(ssp->clk))
  138. return PTR_ERR(ssp->clk);
  139. memset(&pi, 0, sizeof(pi));
  140. pi.parent = &dev->dev;
  141. pi.name = "pxa2xx-spi";
  142. pi.id = ssp->port_id;
  143. pi.data = &spi_pdata;
  144. pi.size_data = sizeof(spi_pdata);
  145. pdev = platform_device_register_full(&pi);
  146. if (IS_ERR(pdev)) {
  147. clk_unregister(ssp->clk);
  148. return PTR_ERR(pdev);
  149. }
  150. pci_set_drvdata(dev, pdev);
  151. return 0;
  152. }
  153. static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
  154. {
  155. struct platform_device *pdev = pci_get_drvdata(dev);
  156. struct pxa2xx_spi_master *spi_pdata;
  157. spi_pdata = dev_get_platdata(&pdev->dev);
  158. platform_device_unregister(pdev);
  159. clk_unregister(spi_pdata->ssp.clk);
  160. }
  161. static const struct pci_device_id pxa2xx_spi_pci_devices[] = {
  162. { PCI_VDEVICE(INTEL, 0x2e6a), PORT_CE4100 },
  163. { PCI_VDEVICE(INTEL, 0x0f0e), PORT_BYT },
  164. { PCI_VDEVICE(INTEL, 0x228e), PORT_BSW0 },
  165. { PCI_VDEVICE(INTEL, 0x2290), PORT_BSW1 },
  166. { PCI_VDEVICE(INTEL, 0x22ac), PORT_BSW2 },
  167. { },
  168. };
  169. MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices);
  170. static struct pci_driver pxa2xx_spi_pci_driver = {
  171. .name = "pxa2xx_spi_pci",
  172. .id_table = pxa2xx_spi_pci_devices,
  173. .probe = pxa2xx_spi_pci_probe,
  174. .remove = pxa2xx_spi_pci_remove,
  175. };
  176. module_pci_driver(pxa2xx_spi_pci_driver);
  177. MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver");
  178. MODULE_LICENSE("GPL v2");
  179. MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");