pci.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
  66. if (ret < 0)
  67. return ret;
  68. chip->dev = &pdev->dev;
  69. chip->regs = pcim_iomap_table(pdev)[0];
  70. chip->length = pci_resource_len(pdev, 0);
  71. chip->offset = HSU_PCI_CHAN_OFFSET;
  72. chip->irq = pci_irq_vector(pdev, 0);
  73. ret = hsu_dma_probe(chip);
  74. if (ret)
  75. return ret;
  76. ret = request_irq(chip->irq, hsu_pci_irq, 0, "hsu_dma_pci", chip);
  77. if (ret)
  78. goto err_register_irq;
  79. pci_set_drvdata(pdev, chip);
  80. return 0;
  81. err_register_irq:
  82. hsu_dma_remove(chip);
  83. return ret;
  84. }
  85. static void hsu_pci_remove(struct pci_dev *pdev)
  86. {
  87. struct hsu_dma_chip *chip = pci_get_drvdata(pdev);
  88. free_irq(chip->irq, chip);
  89. hsu_dma_remove(chip);
  90. }
  91. static const struct pci_device_id hsu_pci_id_table[] = {
  92. { PCI_VDEVICE(INTEL, 0x081e), 0 },
  93. { PCI_VDEVICE(INTEL, 0x1192), 0 },
  94. { }
  95. };
  96. MODULE_DEVICE_TABLE(pci, hsu_pci_id_table);
  97. static struct pci_driver hsu_pci_driver = {
  98. .name = "hsu_dma_pci",
  99. .id_table = hsu_pci_id_table,
  100. .probe = hsu_pci_probe,
  101. .remove = hsu_pci_remove,
  102. };
  103. module_pci_driver(hsu_pci_driver);
  104. MODULE_LICENSE("GPL v2");
  105. MODULE_DESCRIPTION("High Speed UART DMA PCI driver");
  106. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");