spi-dw-pci.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * PCI interface driver for DW SPI Core
  3. *
  4. * Copyright (c) 2009, 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. */
  15. #include <linux/interrupt.h>
  16. #include <linux/pci.h>
  17. #include <linux/slab.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/module.h>
  20. #include "spi-dw.h"
  21. #define DRIVER_NAME "dw_spi_pci"
  22. struct spi_pci_desc {
  23. int (*setup)(struct dw_spi *);
  24. u16 num_cs;
  25. u16 bus_num;
  26. };
  27. static struct spi_pci_desc spi_pci_mid_desc_1 = {
  28. .setup = dw_spi_mid_init,
  29. .num_cs = 5,
  30. .bus_num = 0,
  31. };
  32. static struct spi_pci_desc spi_pci_mid_desc_2 = {
  33. .setup = dw_spi_mid_init,
  34. .num_cs = 2,
  35. .bus_num = 1,
  36. };
  37. static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  38. {
  39. struct dw_spi *dws;
  40. struct spi_pci_desc *desc = (struct spi_pci_desc *)ent->driver_data;
  41. int pci_bar = 0;
  42. int ret;
  43. ret = pcim_enable_device(pdev);
  44. if (ret)
  45. return ret;
  46. dws = devm_kzalloc(&pdev->dev, sizeof(*dws), GFP_KERNEL);
  47. if (!dws)
  48. return -ENOMEM;
  49. /* Get basic io resource and map it */
  50. dws->paddr = pci_resource_start(pdev, pci_bar);
  51. ret = pcim_iomap_regions(pdev, 1 << pci_bar, pci_name(pdev));
  52. if (ret)
  53. return ret;
  54. dws->regs = pcim_iomap_table(pdev)[pci_bar];
  55. dws->irq = pdev->irq;
  56. /*
  57. * Specific handling for paltforms, like dma setup,
  58. * clock rate, FIFO depth.
  59. */
  60. if (desc) {
  61. dws->num_cs = desc->num_cs;
  62. dws->bus_num = desc->bus_num;
  63. if (desc->setup) {
  64. ret = desc->setup(dws);
  65. if (ret)
  66. return ret;
  67. }
  68. } else {
  69. return -ENODEV;
  70. }
  71. ret = dw_spi_add_host(&pdev->dev, dws);
  72. if (ret)
  73. return ret;
  74. /* PCI hook and SPI hook use the same drv data */
  75. pci_set_drvdata(pdev, dws);
  76. dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
  77. pdev->vendor, pdev->device);
  78. return 0;
  79. }
  80. static void spi_pci_remove(struct pci_dev *pdev)
  81. {
  82. struct dw_spi *dws = pci_get_drvdata(pdev);
  83. dw_spi_remove_host(dws);
  84. }
  85. #ifdef CONFIG_PM_SLEEP
  86. static int spi_suspend(struct device *dev)
  87. {
  88. struct pci_dev *pdev = to_pci_dev(dev);
  89. struct dw_spi *dws = pci_get_drvdata(pdev);
  90. return dw_spi_suspend_host(dws);
  91. }
  92. static int spi_resume(struct device *dev)
  93. {
  94. struct pci_dev *pdev = to_pci_dev(dev);
  95. struct dw_spi *dws = pci_get_drvdata(pdev);
  96. return dw_spi_resume_host(dws);
  97. }
  98. #endif
  99. static SIMPLE_DEV_PM_OPS(dw_spi_pm_ops, spi_suspend, spi_resume);
  100. static const struct pci_device_id pci_ids[] = {
  101. /* Intel MID platform SPI controller 0 */
  102. /*
  103. * The access to the device 8086:0801 is disabled by HW, since it's
  104. * exclusively used by SCU to communicate with MSIC.
  105. */
  106. /* Intel MID platform SPI controller 1 */
  107. { PCI_VDEVICE(INTEL, 0x0800), (kernel_ulong_t)&spi_pci_mid_desc_1},
  108. /* Intel MID platform SPI controller 2 */
  109. { PCI_VDEVICE(INTEL, 0x0812), (kernel_ulong_t)&spi_pci_mid_desc_2},
  110. {},
  111. };
  112. static struct pci_driver dw_spi_driver = {
  113. .name = DRIVER_NAME,
  114. .id_table = pci_ids,
  115. .probe = spi_pci_probe,
  116. .remove = spi_pci_remove,
  117. .driver = {
  118. .pm = &dw_spi_pm_ops,
  119. },
  120. };
  121. module_pci_driver(dw_spi_driver);
  122. MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
  123. MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
  124. MODULE_LICENSE("GPL v2");