pci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PCI driver for the Synopsys DesignWare DMA Controller
  4. *
  5. * Copyright (C) 2013 Intel Corporation
  6. * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/pci.h>
  10. #include <linux/device.h>
  11. #include "internal.h"
  12. static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
  13. {
  14. const struct dw_dma_chip_pdata *drv_data = (void *)pid->driver_data;
  15. struct dw_dma_chip_pdata *data;
  16. struct dw_dma_chip *chip;
  17. int ret;
  18. ret = pcim_enable_device(pdev);
  19. if (ret)
  20. return ret;
  21. ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
  22. if (ret) {
  23. dev_err(&pdev->dev, "I/O memory remapping failed\n");
  24. return ret;
  25. }
  26. pci_set_master(pdev);
  27. pci_try_set_mwi(pdev);
  28. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  29. if (ret)
  30. return ret;
  31. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  32. if (ret)
  33. return ret;
  34. data = devm_kmemdup(&pdev->dev, drv_data, sizeof(*drv_data), GFP_KERNEL);
  35. if (!data)
  36. return -ENOMEM;
  37. chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
  38. if (!chip)
  39. return -ENOMEM;
  40. chip->dev = &pdev->dev;
  41. chip->id = pdev->devfn;
  42. chip->regs = pcim_iomap_table(pdev)[0];
  43. chip->irq = pdev->irq;
  44. chip->pdata = data->pdata;
  45. data->chip = chip;
  46. ret = data->probe(chip);
  47. if (ret)
  48. return ret;
  49. dw_dma_acpi_controller_register(chip->dw);
  50. pci_set_drvdata(pdev, data);
  51. return 0;
  52. }
  53. static void dw_pci_remove(struct pci_dev *pdev)
  54. {
  55. struct dw_dma_chip_pdata *data = pci_get_drvdata(pdev);
  56. struct dw_dma_chip *chip = data->chip;
  57. int ret;
  58. dw_dma_acpi_controller_free(chip->dw);
  59. ret = data->remove(chip);
  60. if (ret)
  61. dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
  62. }
  63. #ifdef CONFIG_PM_SLEEP
  64. static int dw_pci_suspend_late(struct device *dev)
  65. {
  66. struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
  67. struct dw_dma_chip *chip = data->chip;
  68. return do_dw_dma_disable(chip);
  69. };
  70. static int dw_pci_resume_early(struct device *dev)
  71. {
  72. struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
  73. struct dw_dma_chip *chip = data->chip;
  74. return do_dw_dma_enable(chip);
  75. };
  76. #endif /* CONFIG_PM_SLEEP */
  77. static const struct dev_pm_ops dw_pci_dev_pm_ops = {
  78. SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
  79. };
  80. static const struct pci_device_id dw_pci_id_table[] = {
  81. /* Medfield (GPDMA) */
  82. { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_dma_chip_pdata },
  83. /* BayTrail */
  84. { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_dma_chip_pdata },
  85. { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_dma_chip_pdata },
  86. /* Merrifield */
  87. { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&idma32_chip_pdata },
  88. /* Braswell */
  89. { PCI_VDEVICE(INTEL, 0x2286), (kernel_ulong_t)&dw_dma_chip_pdata },
  90. { PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_dma_chip_pdata },
  91. /* Elkhart Lake iDMA 32-bit (PSE DMA) */
  92. { PCI_VDEVICE(INTEL, 0x4bb4), (kernel_ulong_t)&idma32_chip_pdata },
  93. { PCI_VDEVICE(INTEL, 0x4bb5), (kernel_ulong_t)&idma32_chip_pdata },
  94. { PCI_VDEVICE(INTEL, 0x4bb6), (kernel_ulong_t)&idma32_chip_pdata },
  95. /* Haswell */
  96. { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_dma_chip_pdata },
  97. /* Broadwell */
  98. { PCI_VDEVICE(INTEL, 0x9ce0), (kernel_ulong_t)&dw_dma_chip_pdata },
  99. { }
  100. };
  101. MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
  102. static struct pci_driver dw_pci_driver = {
  103. .name = "dw_dmac_pci",
  104. .id_table = dw_pci_id_table,
  105. .probe = dw_pci_probe,
  106. .remove = dw_pci_remove,
  107. .driver = {
  108. .pm = &dw_pci_dev_pm_ops,
  109. },
  110. };
  111. module_pci_driver(dw_pci_driver);
  112. MODULE_LICENSE("GPL v2");
  113. MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
  114. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");