pci.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. static irqreturn_t hsu_pci_irq(int irq, void *dev)
  22. {
  23. struct hsu_dma_chip *chip = dev;
  24. u32 dmaisr;
  25. u32 status;
  26. unsigned short i;
  27. int ret = 0;
  28. int err;
  29. dmaisr = readl(chip->regs + HSU_PCI_DMAISR);
  30. for (i = 0; i < chip->hsu->nr_channels; i++) {
  31. if (dmaisr & 0x1) {
  32. err = hsu_dma_get_status(chip, i, &status);
  33. if (err > 0)
  34. ret |= 1;
  35. else if (err == 0)
  36. ret |= hsu_dma_do_irq(chip, i, status);
  37. }
  38. dmaisr >>= 1;
  39. }
  40. return IRQ_RETVAL(ret);
  41. }
  42. static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  43. {
  44. struct hsu_dma_chip *chip;
  45. int ret;
  46. ret = pcim_enable_device(pdev);
  47. if (ret)
  48. return ret;
  49. ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
  50. if (ret) {
  51. dev_err(&pdev->dev, "I/O memory remapping failed\n");
  52. return ret;
  53. }
  54. pci_set_master(pdev);
  55. pci_try_set_mwi(pdev);
  56. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  57. if (ret)
  58. return ret;
  59. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  60. if (ret)
  61. return ret;
  62. chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
  63. if (!chip)
  64. return -ENOMEM;
  65. chip->dev = &pdev->dev;
  66. chip->regs = pcim_iomap_table(pdev)[0];
  67. chip->length = pci_resource_len(pdev, 0);
  68. chip->offset = HSU_PCI_CHAN_OFFSET;
  69. chip->irq = pdev->irq;
  70. pci_enable_msi(pdev);
  71. ret = hsu_dma_probe(chip);
  72. if (ret)
  73. return ret;
  74. ret = request_irq(chip->irq, hsu_pci_irq, 0, "hsu_dma_pci", chip);
  75. if (ret)
  76. goto err_register_irq;
  77. pci_set_drvdata(pdev, chip);
  78. return 0;
  79. err_register_irq:
  80. hsu_dma_remove(chip);
  81. return ret;
  82. }
  83. static void hsu_pci_remove(struct pci_dev *pdev)
  84. {
  85. struct hsu_dma_chip *chip = pci_get_drvdata(pdev);
  86. free_irq(chip->irq, chip);
  87. hsu_dma_remove(chip);
  88. }
  89. static const struct pci_device_id hsu_pci_id_table[] = {
  90. { PCI_VDEVICE(INTEL, 0x081e), 0 },
  91. { PCI_VDEVICE(INTEL, 0x1192), 0 },
  92. { }
  93. };
  94. MODULE_DEVICE_TABLE(pci, hsu_pci_id_table);
  95. static struct pci_driver hsu_pci_driver = {
  96. .name = "hsu_dma_pci",
  97. .id_table = hsu_pci_id_table,
  98. .probe = hsu_pci_probe,
  99. .remove = hsu_pci_remove,
  100. };
  101. module_pci_driver(hsu_pci_driver);
  102. MODULE_LICENSE("GPL v2");
  103. MODULE_DESCRIPTION("High Speed UART DMA PCI driver");
  104. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");