spi-dw-pci.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 dw_spi_pci {
  23. struct pci_dev *pdev;
  24. struct dw_spi dws;
  25. };
  26. struct spi_pci_desc {
  27. int (*setup)(struct dw_spi *);
  28. };
  29. static struct spi_pci_desc spi_pci_mid_desc = {
  30. .setup = dw_spi_mid_init,
  31. };
  32. static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  33. {
  34. struct dw_spi_pci *dwpci;
  35. struct dw_spi *dws;
  36. struct spi_pci_desc *desc = (struct spi_pci_desc *)ent->driver_data;
  37. int pci_bar = 0;
  38. int ret;
  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 << pci_bar, pci_name(pdev));
  51. if (ret)
  52. return ret;
  53. dws->regs = pcim_iomap_table(pdev)[pci_bar];
  54. dws->bus_num = 0;
  55. dws->num_cs = 4;
  56. dws->irq = pdev->irq;
  57. /*
  58. * Specific handling for paltforms, like dma setup,
  59. * clock rate, FIFO depth.
  60. */
  61. if (desc && desc->setup) {
  62. ret = desc->setup(dws);
  63. if (ret)
  64. return ret;
  65. }
  66. ret = dw_spi_add_host(&pdev->dev, dws);
  67. if (ret)
  68. return ret;
  69. /* PCI hook and SPI hook use the same drv data */
  70. pci_set_drvdata(pdev, dwpci);
  71. dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
  72. pdev->vendor, pdev->device);
  73. return 0;
  74. }
  75. static void spi_pci_remove(struct pci_dev *pdev)
  76. {
  77. struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
  78. dw_spi_remove_host(&dwpci->dws);
  79. }
  80. #ifdef CONFIG_PM_SLEEP
  81. static int spi_suspend(struct device *dev)
  82. {
  83. struct pci_dev *pdev = to_pci_dev(dev);
  84. struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
  85. return dw_spi_suspend_host(&dwpci->dws);
  86. }
  87. static int spi_resume(struct device *dev)
  88. {
  89. struct pci_dev *pdev = to_pci_dev(dev);
  90. struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
  91. return dw_spi_resume_host(&dwpci->dws);
  92. }
  93. #endif
  94. static SIMPLE_DEV_PM_OPS(dw_spi_pm_ops, spi_suspend, spi_resume);
  95. static const struct pci_device_id pci_ids[] = {
  96. /* Intel MID platform SPI controller 0 */
  97. { PCI_VDEVICE(INTEL, 0x0800), (kernel_ulong_t)&spi_pci_mid_desc},
  98. {},
  99. };
  100. static struct pci_driver dw_spi_driver = {
  101. .name = DRIVER_NAME,
  102. .id_table = pci_ids,
  103. .probe = spi_pci_probe,
  104. .remove = spi_pci_remove,
  105. .driver = {
  106. .pm = &dw_spi_pm_ops,
  107. },
  108. };
  109. module_pci_driver(dw_spi_driver);
  110. MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
  111. MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
  112. MODULE_LICENSE("GPL v2");