pci.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * PCI driver for the Synopsys DesignWare DMA Controller
  3. *
  4. * Copyright (C) 2013 Intel Corporation
  5. * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/pci.h>
  13. #include <linux/device.h>
  14. #include "internal.h"
  15. static struct dw_dma_platform_data mrfld_pdata = {
  16. .nr_channels = 8,
  17. .is_private = true,
  18. .is_memcpy = true,
  19. .is_idma32 = true,
  20. .chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
  21. .chan_priority = CHAN_PRIORITY_ASCENDING,
  22. .block_size = 131071,
  23. .nr_masters = 1,
  24. .data_width = {4},
  25. };
  26. static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
  27. {
  28. const struct dw_dma_platform_data *pdata = (void *)pid->driver_data;
  29. struct dw_dma_chip *chip;
  30. int ret;
  31. ret = pcim_enable_device(pdev);
  32. if (ret)
  33. return ret;
  34. ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
  35. if (ret) {
  36. dev_err(&pdev->dev, "I/O memory remapping failed\n");
  37. return ret;
  38. }
  39. pci_set_master(pdev);
  40. pci_try_set_mwi(pdev);
  41. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  42. if (ret)
  43. return ret;
  44. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  45. if (ret)
  46. return ret;
  47. chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
  48. if (!chip)
  49. return -ENOMEM;
  50. chip->dev = &pdev->dev;
  51. chip->id = pdev->devfn;
  52. chip->regs = pcim_iomap_table(pdev)[0];
  53. chip->irq = pdev->irq;
  54. chip->pdata = pdata;
  55. ret = dw_dma_probe(chip);
  56. if (ret)
  57. return ret;
  58. pci_set_drvdata(pdev, chip);
  59. return 0;
  60. }
  61. static void dw_pci_remove(struct pci_dev *pdev)
  62. {
  63. struct dw_dma_chip *chip = pci_get_drvdata(pdev);
  64. int ret;
  65. ret = dw_dma_remove(chip);
  66. if (ret)
  67. dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
  68. }
  69. #ifdef CONFIG_PM_SLEEP
  70. static int dw_pci_suspend_late(struct device *dev)
  71. {
  72. struct pci_dev *pci = to_pci_dev(dev);
  73. struct dw_dma_chip *chip = pci_get_drvdata(pci);
  74. return dw_dma_disable(chip);
  75. };
  76. static int dw_pci_resume_early(struct device *dev)
  77. {
  78. struct pci_dev *pci = to_pci_dev(dev);
  79. struct dw_dma_chip *chip = pci_get_drvdata(pci);
  80. return dw_dma_enable(chip);
  81. };
  82. #endif /* CONFIG_PM_SLEEP */
  83. static const struct dev_pm_ops dw_pci_dev_pm_ops = {
  84. SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
  85. };
  86. static const struct pci_device_id dw_pci_id_table[] = {
  87. /* Medfield (GPDMA) */
  88. { PCI_VDEVICE(INTEL, 0x0827) },
  89. /* BayTrail */
  90. { PCI_VDEVICE(INTEL, 0x0f06) },
  91. { PCI_VDEVICE(INTEL, 0x0f40) },
  92. /* Merrifield iDMA 32-bit (GPDMA) */
  93. { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&mrfld_pdata },
  94. /* Braswell */
  95. { PCI_VDEVICE(INTEL, 0x2286) },
  96. { PCI_VDEVICE(INTEL, 0x22c0) },
  97. /* Haswell */
  98. { PCI_VDEVICE(INTEL, 0x9c60) },
  99. /* Broadwell */
  100. { PCI_VDEVICE(INTEL, 0x9ce0) },
  101. { }
  102. };
  103. MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
  104. static struct pci_driver dw_pci_driver = {
  105. .name = "dw_dmac_pci",
  106. .id_table = dw_pci_id_table,
  107. .probe = dw_pci_probe,
  108. .remove = dw_pci_remove,
  109. .driver = {
  110. .pm = &dw_pci_dev_pm_ops,
  111. },
  112. };
  113. module_pci_driver(dw_pci_driver);
  114. MODULE_LICENSE("GPL v2");
  115. MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
  116. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");