pci.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * PCI driver for the High Speed UART DMA
  3. *
  4. * Copyright (C) 2015 Intel Corporation
  5. * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  6. *
  7. * Partially based on the bits found in drivers/tty/serial/mfd.c.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/bitops.h>
  14. #include <linux/device.h>
  15. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include "hsu.h"
  18. #define HSU_PCI_DMASR 0x00
  19. #define HSU_PCI_DMAISR 0x04
  20. #define HSU_PCI_CHAN_OFFSET 0x100
  21. #define PCI_DEVICE_ID_INTEL_MFLD_HSU_DMA 0x081e
  22. #define PCI_DEVICE_ID_INTEL_MRFLD_HSU_DMA 0x1192
  23. static irqreturn_t hsu_pci_irq(int irq, void *dev)
  24. {
  25. struct hsu_dma_chip *chip = dev;
  26. u32 dmaisr;
  27. u32 status;
  28. unsigned short i;
  29. int ret = 0;
  30. int err;
  31. dmaisr = readl(chip->regs + HSU_PCI_DMAISR);
  32. for (i = 0; i < chip->hsu->nr_channels; i++) {
  33. if (dmaisr & 0x1) {
  34. err = hsu_dma_get_status(chip, i, &status);
  35. if (err > 0)
  36. ret |= 1;
  37. else if (err == 0)
  38. ret |= hsu_dma_do_irq(chip, i, status);
  39. }
  40. dmaisr >>= 1;
  41. }
  42. return IRQ_RETVAL(ret);
  43. }
  44. static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  45. {
  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 = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  59. if (ret)
  60. return ret;
  61. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  62. if (ret)
  63. return ret;
  64. chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
  65. if (!chip)
  66. return -ENOMEM;
  67. ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
  68. if (ret < 0)
  69. return ret;
  70. chip->dev = &pdev->dev;
  71. chip->regs = pcim_iomap_table(pdev)[0];
  72. chip->length = pci_resource_len(pdev, 0);
  73. chip->offset = HSU_PCI_CHAN_OFFSET;
  74. chip->irq = pci_irq_vector(pdev, 0);
  75. ret = hsu_dma_probe(chip);
  76. if (ret)
  77. return ret;
  78. ret = request_irq(chip->irq, hsu_pci_irq, 0, "hsu_dma_pci", chip);
  79. if (ret)
  80. goto err_register_irq;
  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. err_register_irq:
  94. hsu_dma_remove(chip);
  95. return ret;
  96. }
  97. static void hsu_pci_remove(struct pci_dev *pdev)
  98. {
  99. struct hsu_dma_chip *chip = pci_get_drvdata(pdev);
  100. free_irq(chip->irq, chip);
  101. hsu_dma_remove(chip);
  102. }
  103. static const struct pci_device_id hsu_pci_id_table[] = {
  104. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MFLD_HSU_DMA), 0 },
  105. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_MRFLD_HSU_DMA), 0 },
  106. { }
  107. };
  108. MODULE_DEVICE_TABLE(pci, hsu_pci_id_table);
  109. static struct pci_driver hsu_pci_driver = {
  110. .name = "hsu_dma_pci",
  111. .id_table = hsu_pci_id_table,
  112. .probe = hsu_pci_probe,
  113. .remove = hsu_pci_remove,
  114. };
  115. module_pci_driver(hsu_pci_driver);
  116. MODULE_LICENSE("GPL v2");
  117. MODULE_DESCRIPTION("High Speed UART DMA PCI driver");
  118. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");