spi-pxa2xx-pci.c 5.6 KB

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