spi-dw-pci.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * PCI interface driver for DW SPI Core
  3. *
  4. * Copyright (c) 2009, 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. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #include <linux/interrupt.h>
  20. #include <linux/pci.h>
  21. #include <linux/slab.h>
  22. #include <linux/spi/spi.h>
  23. #include <linux/module.h>
  24. #include "spi-dw.h"
  25. #define DRIVER_NAME "dw_spi_pci"
  26. struct dw_spi_pci {
  27. struct pci_dev *pdev;
  28. struct dw_spi dws;
  29. };
  30. static int spi_pci_probe(struct pci_dev *pdev,
  31. const struct pci_device_id *ent)
  32. {
  33. struct dw_spi_pci *dwpci;
  34. struct dw_spi *dws;
  35. int pci_bar = 0;
  36. int ret;
  37. dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
  38. pdev->vendor, pdev->device);
  39. ret = pcim_enable_device(pdev);
  40. if (ret)
  41. return ret;
  42. dwpci = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_pci),
  43. GFP_KERNEL);
  44. if (!dwpci)
  45. return -ENOMEM;
  46. dwpci->pdev = pdev;
  47. dws = &dwpci->dws;
  48. /* Get basic io resource and map it */
  49. dws->paddr = pci_resource_start(pdev, pci_bar);
  50. ret = pcim_iomap_regions(pdev, 1, dev_name(&pdev->dev));
  51. if (ret)
  52. return ret;
  53. dws->bus_num = 0;
  54. dws->num_cs = 4;
  55. dws->irq = pdev->irq;
  56. /*
  57. * Specific handling for Intel MID paltforms, like dma setup,
  58. * clock rate, FIFO depth.
  59. */
  60. if (pdev->device == 0x0800) {
  61. ret = dw_spi_mid_init(dws);
  62. if (ret)
  63. return ret;
  64. }
  65. ret = dw_spi_add_host(&pdev->dev, dws);
  66. if (ret)
  67. return ret;
  68. /* PCI hook and SPI hook use the same drv data */
  69. pci_set_drvdata(pdev, dwpci);
  70. return 0;
  71. }
  72. static void spi_pci_remove(struct pci_dev *pdev)
  73. {
  74. struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
  75. dw_spi_remove_host(&dwpci->dws);
  76. }
  77. #ifdef CONFIG_PM
  78. static int spi_suspend(struct pci_dev *pdev, pm_message_t state)
  79. {
  80. struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
  81. int ret;
  82. ret = dw_spi_suspend_host(&dwpci->dws);
  83. if (ret)
  84. return ret;
  85. pci_save_state(pdev);
  86. pci_disable_device(pdev);
  87. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  88. return ret;
  89. }
  90. static int spi_resume(struct pci_dev *pdev)
  91. {
  92. struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
  93. int ret;
  94. pci_set_power_state(pdev, PCI_D0);
  95. pci_restore_state(pdev);
  96. ret = pci_enable_device(pdev);
  97. if (ret)
  98. return ret;
  99. return dw_spi_resume_host(&dwpci->dws);
  100. }
  101. #else
  102. #define spi_suspend NULL
  103. #define spi_resume NULL
  104. #endif
  105. static const struct pci_device_id pci_ids[] = {
  106. /* Intel MID platform SPI controller 0 */
  107. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
  108. {},
  109. };
  110. static struct pci_driver dw_spi_driver = {
  111. .name = DRIVER_NAME,
  112. .id_table = pci_ids,
  113. .probe = spi_pci_probe,
  114. .remove = spi_pci_remove,
  115. .suspend = spi_suspend,
  116. .resume = spi_resume,
  117. };
  118. module_pci_driver(dw_spi_driver);
  119. MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
  120. MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
  121. MODULE_LICENSE("GPL v2");