pci.c 2.9 KB

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