pci.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * PCI driver for the High Speed UART DMA
  4. *
  5. * Copyright (C) 2015 Intel Corporation
  6. * Author: Andy Shevchenko <[email protected]>
  7. *
  8. * Partially based on the bits found in drivers/tty/serial/mfd.c.
  9. */
  10. #include <linux/bitops.h>
  11. #include <linux/device.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include "hsu.h"
  16. #define HSU_PCI_DMASR 0x00
  17. #define HSU_PCI_DMAISR 0x04
  18. #define HSU_PCI_CHAN_OFFSET 0x100
  19. #define PCI_DEVICE_ID_INTEL_MFLD_HSU_DMA 0x081e
  20. #define PCI_DEVICE_ID_INTEL_MRFLD_HSU_DMA 0x1192
  21. static irqreturn_t hsu_pci_irq(int irq, void *dev)
  22. {
  23. struct hsu_dma_chip *chip = dev;
  24. unsigned long dmaisr;
  25. unsigned short i;
  26. u32 status;
  27. int ret = 0;
  28. int err;
  29. dmaisr = readl(chip->regs + HSU_PCI_DMAISR);
  30. for_each_set_bit(i, &dmaisr, chip->hsu->nr_channels) {
  31. err = hsu_dma_get_status(chip, i, &status);
  32. if (err > 0)
  33. ret |= 1;
  34. else if (err == 0)
  35. ret |= hsu_dma_do_irq(chip, i, status);
  36. }
  37. return IRQ_RETVAL(ret);
  38. }
  39. static void hsu_pci_dma_remove(void *chip)
  40. {
  41. hsu_dma_remove(chip);
  42. }
  43. static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  44. {
  45. struct device *dev = &pdev->dev;
  46. struct hsu_dma_chip *chip;
  47. int ret;
  48. ret = pcim_enable_device(pdev);
  49. if (ret)
  50. return ret;
  51. ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
  52. if (ret) {
  53. dev_err(&pdev->dev, "I/O memory remapping failed\n");
  54. return ret;
  55. }
  56. pci_set_master(pdev);
  57. pci_try_set_mwi(pdev);
  58. ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  59. if (ret)
  60. return ret;
  61. chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
  62. if (!chip)
  63. return -ENOMEM;
  64. ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
  65. if (ret < 0)
  66. return ret;
  67. chip->dev = &pdev->dev;
  68. chip->regs = pcim_iomap_table(pdev)[0];
  69. chip->length = pci_resource_len(pdev, 0);
  70. chip->offset = HSU_PCI_CHAN_OFFSET;
  71. chip->irq = pci_irq_vector(pdev, 0);
  72. ret = hsu_dma_probe(chip);
  73. if (ret)
  74. return ret;
  75. ret = devm_add_action_or_reset(dev, hsu_pci_dma_remove, chip);
  76. if (ret)
  77. return ret;
  78. ret = devm_request_irq(dev, chip->irq, hsu_pci_irq, 0, "hsu_dma_pci", chip);
  79. if (ret)
  80. return ret;
  81. /*
  82. * On Intel Tangier B0 and Anniedale the interrupt line, disregarding
  83. * to have different numbers, is shared between HSU DMA and UART IPs.
  84. * Thus on such SoCs we are expecting that IRQ handler is called in
  85. * UART driver only. Instead of handling the spurious interrupt
  86. * from HSU DMA here and waste CPU time and delay HSU UART interrupt
  87. * handling, disable the interrupt entirely.
  88. */
  89. if (pdev->device == PCI_DEVICE_ID_INTEL_MRFLD_HSU_DMA)
  90. disable_irq_nosync(chip->irq);
  91. pci_set_drvdata(pdev, chip);
  92. return 0;
  93. }
  94. static const struct pci_device_id hsu_pci_id_table[] = {
  95. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MFLD_HSU_DMA), 0 },
  96. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MRFLD_HSU_DMA), 0 },
  97. { }
  98. };
  99. MODULE_DEVICE_TABLE(pci, hsu_pci_id_table);
  100. static struct pci_driver hsu_pci_driver = {
  101. .name = "hsu_dma_pci",
  102. .id_table = hsu_pci_id_table,
  103. .probe = hsu_pci_probe,
  104. };
  105. module_pci_driver(hsu_pci_driver);
  106. MODULE_LICENSE("GPL v2");
  107. MODULE_DESCRIPTION("High Speed UART DMA PCI driver");
  108. MODULE_AUTHOR("Andy Shevchenko <[email protected]>");