pci.c 2.7 KB

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