pci.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 dw_pci_pdata = {
  16. .is_private = 1,
  17. .chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
  18. .chan_priority = CHAN_PRIORITY_ASCENDING,
  19. };
  20. static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
  21. {
  22. struct dw_dma_chip *chip;
  23. struct dw_dma_platform_data *pdata = (void *)pid->driver_data;
  24. int ret;
  25. ret = pcim_enable_device(pdev);
  26. if (ret)
  27. return ret;
  28. ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
  29. if (ret) {
  30. dev_err(&pdev->dev, "I/O memory remapping failed\n");
  31. return ret;
  32. }
  33. pci_set_master(pdev);
  34. pci_try_set_mwi(pdev);
  35. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  36. if (ret)
  37. return ret;
  38. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  39. if (ret)
  40. return ret;
  41. chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
  42. if (!chip)
  43. return -ENOMEM;
  44. chip->dev = &pdev->dev;
  45. chip->regs = pcim_iomap_table(pdev)[0];
  46. chip->irq = pdev->irq;
  47. ret = dw_dma_probe(chip, pdata);
  48. if (ret)
  49. return ret;
  50. pci_set_drvdata(pdev, chip);
  51. return 0;
  52. }
  53. static void dw_pci_remove(struct pci_dev *pdev)
  54. {
  55. struct dw_dma_chip *chip = pci_get_drvdata(pdev);
  56. int ret;
  57. ret = dw_dma_remove(chip);
  58. if (ret)
  59. dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
  60. }
  61. #ifdef CONFIG_PM_SLEEP
  62. static int dw_pci_suspend_late(struct device *dev)
  63. {
  64. struct pci_dev *pci = to_pci_dev(dev);
  65. struct dw_dma_chip *chip = pci_get_drvdata(pci);
  66. return dw_dma_disable(chip);
  67. };
  68. static int dw_pci_resume_early(struct device *dev)
  69. {
  70. struct pci_dev *pci = to_pci_dev(dev);
  71. struct dw_dma_chip *chip = pci_get_drvdata(pci);
  72. return dw_dma_enable(chip);
  73. };
  74. #endif /* CONFIG_PM_SLEEP */
  75. static const struct dev_pm_ops dw_pci_dev_pm_ops = {
  76. SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
  77. };
  78. static const struct pci_device_id dw_pci_id_table[] = {
  79. /* Medfield */
  80. { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_pci_pdata },
  81. { PCI_VDEVICE(INTEL, 0x0830), (kernel_ulong_t)&dw_pci_pdata },
  82. /* BayTrail */
  83. { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_pci_pdata },
  84. { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_pci_pdata },
  85. /* Braswell */
  86. { PCI_VDEVICE(INTEL, 0x2286), (kernel_ulong_t)&dw_pci_pdata },
  87. { PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_pci_pdata },
  88. /* Haswell */
  89. { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_pci_pdata },
  90. { }
  91. };
  92. MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
  93. static struct pci_driver dw_pci_driver = {
  94. .name = "dw_dmac_pci",
  95. .id_table = dw_pci_id_table,
  96. .probe = dw_pci_probe,
  97. .remove = dw_pci_remove,
  98. .driver = {
  99. .pm = &dw_pci_dev_pm_ops,
  100. },
  101. };
  102. module_pci_driver(dw_pci_driver);
  103. MODULE_LICENSE("GPL v2");
  104. MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
  105. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");