spi-pxa2xx-pci.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * CE4100's SPI device is more or less the same one as found on PXA
  3. *
  4. * Copyright (C) 2016, Intel Corporation
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/module.h>
  8. #include <linux/of_device.h>
  9. #include <linux/pci.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/spi/pxa2xx_spi.h>
  12. #include <linux/dmaengine.h>
  13. #include <linux/platform_data/dma-dw.h>
  14. enum {
  15. PORT_QUARK_X1000,
  16. PORT_BYT,
  17. PORT_MRFLD,
  18. PORT_BSW0,
  19. PORT_BSW1,
  20. PORT_BSW2,
  21. PORT_CE4100,
  22. PORT_LPT,
  23. };
  24. struct pxa_spi_info {
  25. enum pxa_ssp_type type;
  26. int port_id;
  27. int num_chipselect;
  28. unsigned long max_clk_rate;
  29. /* DMA channel request parameters */
  30. bool (*dma_filter)(struct dma_chan *chan, void *param);
  31. void *tx_param;
  32. void *rx_param;
  33. int (*setup)(struct pci_dev *pdev, struct pxa_spi_info *c);
  34. };
  35. static struct dw_dma_slave byt_tx_param = { .dst_id = 0 };
  36. static struct dw_dma_slave byt_rx_param = { .src_id = 1 };
  37. static struct dw_dma_slave bsw0_tx_param = { .dst_id = 0 };
  38. static struct dw_dma_slave bsw0_rx_param = { .src_id = 1 };
  39. static struct dw_dma_slave bsw1_tx_param = { .dst_id = 6 };
  40. static struct dw_dma_slave bsw1_rx_param = { .src_id = 7 };
  41. static struct dw_dma_slave bsw2_tx_param = { .dst_id = 8 };
  42. static struct dw_dma_slave bsw2_rx_param = { .src_id = 9 };
  43. static struct dw_dma_slave lpt_tx_param = { .dst_id = 0 };
  44. static struct dw_dma_slave lpt_rx_param = { .src_id = 1 };
  45. static bool lpss_dma_filter(struct dma_chan *chan, void *param)
  46. {
  47. struct dw_dma_slave *dws = param;
  48. if (dws->dma_dev != chan->device->dev)
  49. return false;
  50. chan->private = dws;
  51. return true;
  52. }
  53. static int lpss_spi_setup(struct pci_dev *dev, struct pxa_spi_info *c)
  54. {
  55. struct pci_dev *dma_dev;
  56. c->num_chipselect = 1;
  57. c->max_clk_rate = 50000000;
  58. dma_dev = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
  59. if (c->tx_param) {
  60. struct dw_dma_slave *slave = c->tx_param;
  61. slave->dma_dev = &dma_dev->dev;
  62. slave->m_master = 0;
  63. slave->p_master = 1;
  64. }
  65. if (c->rx_param) {
  66. struct dw_dma_slave *slave = c->rx_param;
  67. slave->dma_dev = &dma_dev->dev;
  68. slave->m_master = 0;
  69. slave->p_master = 1;
  70. }
  71. c->dma_filter = lpss_dma_filter;
  72. return 0;
  73. }
  74. static int mrfld_spi_setup(struct pci_dev *dev, struct pxa_spi_info *c)
  75. {
  76. switch (PCI_FUNC(dev->devfn)) {
  77. case 0:
  78. c->port_id = 3;
  79. c->num_chipselect = 1;
  80. break;
  81. case 1:
  82. c->port_id = 5;
  83. c->num_chipselect = 4;
  84. break;
  85. case 2:
  86. c->port_id = 6;
  87. c->num_chipselect = 1;
  88. break;
  89. default:
  90. return -ENODEV;
  91. }
  92. return 0;
  93. }
  94. static struct pxa_spi_info spi_info_configs[] = {
  95. [PORT_CE4100] = {
  96. .type = PXA25x_SSP,
  97. .port_id = -1,
  98. .num_chipselect = -1,
  99. .max_clk_rate = 3686400,
  100. },
  101. [PORT_BYT] = {
  102. .type = LPSS_BYT_SSP,
  103. .port_id = 0,
  104. .setup = lpss_spi_setup,
  105. .tx_param = &byt_tx_param,
  106. .rx_param = &byt_rx_param,
  107. },
  108. [PORT_BSW0] = {
  109. .type = LPSS_BSW_SSP,
  110. .port_id = 0,
  111. .setup = lpss_spi_setup,
  112. .tx_param = &bsw0_tx_param,
  113. .rx_param = &bsw0_rx_param,
  114. },
  115. [PORT_BSW1] = {
  116. .type = LPSS_BSW_SSP,
  117. .port_id = 1,
  118. .setup = lpss_spi_setup,
  119. .tx_param = &bsw1_tx_param,
  120. .rx_param = &bsw1_rx_param,
  121. },
  122. [PORT_BSW2] = {
  123. .type = LPSS_BSW_SSP,
  124. .port_id = 2,
  125. .setup = lpss_spi_setup,
  126. .tx_param = &bsw2_tx_param,
  127. .rx_param = &bsw2_rx_param,
  128. },
  129. [PORT_MRFLD] = {
  130. .type = PXA27x_SSP,
  131. .max_clk_rate = 25000000,
  132. .setup = mrfld_spi_setup,
  133. },
  134. [PORT_QUARK_X1000] = {
  135. .type = QUARK_X1000_SSP,
  136. .port_id = -1,
  137. .num_chipselect = 1,
  138. .max_clk_rate = 50000000,
  139. },
  140. [PORT_LPT] = {
  141. .type = LPSS_LPT_SSP,
  142. .port_id = 0,
  143. .setup = lpss_spi_setup,
  144. .tx_param = &lpt_tx_param,
  145. .rx_param = &lpt_rx_param,
  146. },
  147. };
  148. static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
  149. const struct pci_device_id *ent)
  150. {
  151. struct platform_device_info pi;
  152. int ret;
  153. struct platform_device *pdev;
  154. struct pxa2xx_spi_master spi_pdata;
  155. struct ssp_device *ssp;
  156. struct pxa_spi_info *c;
  157. char buf[40];
  158. ret = pcim_enable_device(dev);
  159. if (ret)
  160. return ret;
  161. ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
  162. if (ret)
  163. return ret;
  164. c = &spi_info_configs[ent->driver_data];
  165. if (c->setup) {
  166. ret = c->setup(dev, c);
  167. if (ret)
  168. return ret;
  169. }
  170. memset(&spi_pdata, 0, sizeof(spi_pdata));
  171. spi_pdata.num_chipselect = (c->num_chipselect > 0) ? c->num_chipselect : dev->devfn;
  172. spi_pdata.dma_filter = c->dma_filter;
  173. spi_pdata.tx_param = c->tx_param;
  174. spi_pdata.rx_param = c->rx_param;
  175. spi_pdata.enable_dma = c->rx_param && c->tx_param;
  176. ssp = &spi_pdata.ssp;
  177. ssp->phys_base = pci_resource_start(dev, 0);
  178. ssp->mmio_base = pcim_iomap_table(dev)[0];
  179. ssp->irq = dev->irq;
  180. ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
  181. ssp->type = c->type;
  182. snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
  183. ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
  184. c->max_clk_rate);
  185. if (IS_ERR(ssp->clk))
  186. return PTR_ERR(ssp->clk);
  187. memset(&pi, 0, sizeof(pi));
  188. pi.fwnode = dev->dev.fwnode;
  189. pi.parent = &dev->dev;
  190. pi.name = "pxa2xx-spi";
  191. pi.id = ssp->port_id;
  192. pi.data = &spi_pdata;
  193. pi.size_data = sizeof(spi_pdata);
  194. pdev = platform_device_register_full(&pi);
  195. if (IS_ERR(pdev)) {
  196. clk_unregister(ssp->clk);
  197. return PTR_ERR(pdev);
  198. }
  199. pci_set_drvdata(dev, pdev);
  200. return 0;
  201. }
  202. static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
  203. {
  204. struct platform_device *pdev = pci_get_drvdata(dev);
  205. struct pxa2xx_spi_master *spi_pdata;
  206. spi_pdata = dev_get_platdata(&pdev->dev);
  207. platform_device_unregister(pdev);
  208. clk_unregister(spi_pdata->ssp.clk);
  209. }
  210. static const struct pci_device_id pxa2xx_spi_pci_devices[] = {
  211. { PCI_VDEVICE(INTEL, 0x0935), PORT_QUARK_X1000 },
  212. { PCI_VDEVICE(INTEL, 0x0f0e), PORT_BYT },
  213. { PCI_VDEVICE(INTEL, 0x1194), PORT_MRFLD },
  214. { PCI_VDEVICE(INTEL, 0x228e), PORT_BSW0 },
  215. { PCI_VDEVICE(INTEL, 0x2290), PORT_BSW1 },
  216. { PCI_VDEVICE(INTEL, 0x22ac), PORT_BSW2 },
  217. { PCI_VDEVICE(INTEL, 0x2e6a), PORT_CE4100 },
  218. { PCI_VDEVICE(INTEL, 0x9ce6), PORT_LPT },
  219. { },
  220. };
  221. MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices);
  222. static struct pci_driver pxa2xx_spi_pci_driver = {
  223. .name = "pxa2xx_spi_pci",
  224. .id_table = pxa2xx_spi_pci_devices,
  225. .probe = pxa2xx_spi_pci_probe,
  226. .remove = pxa2xx_spi_pci_remove,
  227. };
  228. module_pci_driver(pxa2xx_spi_pci_driver);
  229. MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver");
  230. MODULE_LICENSE("GPL v2");
  231. MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");