pci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 <[email protected]>
  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 = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  29. if (ret)
  30. return ret;
  31. data = devm_kmemdup(&pdev->dev, drv_data, sizeof(*drv_data), GFP_KERNEL);
  32. if (!data)
  33. return -ENOMEM;
  34. chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
  35. if (!chip)
  36. return -ENOMEM;
  37. chip->dev = &pdev->dev;
  38. chip->id = pdev->devfn;
  39. chip->regs = pcim_iomap_table(pdev)[0];
  40. chip->irq = pdev->irq;
  41. chip->pdata = data->pdata;
  42. data->chip = chip;
  43. ret = data->probe(chip);
  44. if (ret)
  45. return ret;
  46. dw_dma_acpi_controller_register(chip->dw);
  47. pci_set_drvdata(pdev, data);
  48. return 0;
  49. }
  50. static void dw_pci_remove(struct pci_dev *pdev)
  51. {
  52. struct dw_dma_chip_pdata *data = pci_get_drvdata(pdev);
  53. struct dw_dma_chip *chip = data->chip;
  54. int ret;
  55. dw_dma_acpi_controller_free(chip->dw);
  56. ret = data->remove(chip);
  57. if (ret)
  58. dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
  59. }
  60. #ifdef CONFIG_PM_SLEEP
  61. static int dw_pci_suspend_late(struct device *dev)
  62. {
  63. struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
  64. struct dw_dma_chip *chip = data->chip;
  65. return do_dw_dma_disable(chip);
  66. };
  67. static int dw_pci_resume_early(struct device *dev)
  68. {
  69. struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
  70. struct dw_dma_chip *chip = data->chip;
  71. return do_dw_dma_enable(chip);
  72. };
  73. #endif /* CONFIG_PM_SLEEP */
  74. static const struct dev_pm_ops dw_pci_dev_pm_ops = {
  75. SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
  76. };
  77. static const struct pci_device_id dw_pci_id_table[] = {
  78. /* Medfield (GPDMA) */
  79. { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_dma_chip_pdata },
  80. /* BayTrail */
  81. { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_dma_chip_pdata },
  82. { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_dma_chip_pdata },
  83. /* Merrifield */
  84. { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&idma32_chip_pdata },
  85. /* Braswell */
  86. { PCI_VDEVICE(INTEL, 0x2286), (kernel_ulong_t)&dw_dma_chip_pdata },
  87. { PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_dma_chip_pdata },
  88. /* Elkhart Lake iDMA 32-bit (PSE DMA) */
  89. { PCI_VDEVICE(INTEL, 0x4bb4), (kernel_ulong_t)&xbar_chip_pdata },
  90. { PCI_VDEVICE(INTEL, 0x4bb5), (kernel_ulong_t)&xbar_chip_pdata },
  91. { PCI_VDEVICE(INTEL, 0x4bb6), (kernel_ulong_t)&xbar_chip_pdata },
  92. /* Haswell */
  93. { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_dma_chip_pdata },
  94. /* Broadwell */
  95. { PCI_VDEVICE(INTEL, 0x9ce0), (kernel_ulong_t)&dw_dma_chip_pdata },
  96. { }
  97. };
  98. MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
  99. static struct pci_driver dw_pci_driver = {
  100. .name = "dw_dmac_pci",
  101. .id_table = dw_pci_id_table,
  102. .probe = dw_pci_probe,
  103. .remove = dw_pci_remove,
  104. .driver = {
  105. .pm = &dw_pci_dev_pm_ops,
  106. },
  107. };
  108. module_pci_driver(dw_pci_driver);
  109. MODULE_LICENSE("GPL v2");
  110. MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
  111. MODULE_AUTHOR("Andy Shevchenko <[email protected]>");