spi-pxa2xx-pci.c 5.2 KB

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