]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/dma/hsu/pci.c
Merge branch 'x86-cleanups-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / drivers / dma / hsu / pci.c
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
14 #include <linux/bitops.h>
15 #include <linux/device.h>
16 #include <linux/module.h>
17 #include <linux/pci.h>
18
19 #include "hsu.h"
20
21 #define HSU_PCI_DMASR           0x00
22 #define HSU_PCI_DMAISR          0x04
23
24 #define HSU_PCI_CHAN_OFFSET     0x100
25
26 static irqreturn_t hsu_pci_irq(int irq, void *dev)
27 {
28         struct hsu_dma_chip *chip = dev;
29         u32 dmaisr;
30         u32 status;
31         unsigned short i;
32         irqreturn_t ret = IRQ_NONE;
33         int err;
34
35         dmaisr = readl(chip->regs + HSU_PCI_DMAISR);
36         for (i = 0; i < chip->hsu->nr_channels; i++) {
37                 if (dmaisr & 0x1) {
38                         err = hsu_dma_get_status(chip, i, &status);
39                         if (err > 0)
40                                 ret |= IRQ_HANDLED;
41                         else if (err == 0)
42                                 ret |= hsu_dma_do_irq(chip, i, status);
43                 }
44                 dmaisr >>= 1;
45         }
46
47         return ret;
48 }
49
50 static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
51 {
52         struct hsu_dma_chip *chip;
53         int ret;
54
55         ret = pcim_enable_device(pdev);
56         if (ret)
57                 return ret;
58
59         ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
60         if (ret) {
61                 dev_err(&pdev->dev, "I/O memory remapping failed\n");
62                 return ret;
63         }
64
65         pci_set_master(pdev);
66         pci_try_set_mwi(pdev);
67
68         ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
69         if (ret)
70                 return ret;
71
72         ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
73         if (ret)
74                 return ret;
75
76         chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
77         if (!chip)
78                 return -ENOMEM;
79
80         chip->dev = &pdev->dev;
81         chip->regs = pcim_iomap_table(pdev)[0];
82         chip->length = pci_resource_len(pdev, 0);
83         chip->offset = HSU_PCI_CHAN_OFFSET;
84         chip->irq = pdev->irq;
85
86         pci_enable_msi(pdev);
87
88         ret = hsu_dma_probe(chip);
89         if (ret)
90                 return ret;
91
92         ret = request_irq(chip->irq, hsu_pci_irq, 0, "hsu_dma_pci", chip);
93         if (ret)
94                 goto err_register_irq;
95
96         pci_set_drvdata(pdev, chip);
97
98         return 0;
99
100 err_register_irq:
101         hsu_dma_remove(chip);
102         return ret;
103 }
104
105 static void hsu_pci_remove(struct pci_dev *pdev)
106 {
107         struct hsu_dma_chip *chip = pci_get_drvdata(pdev);
108
109         free_irq(chip->irq, chip);
110         hsu_dma_remove(chip);
111 }
112
113 static const struct pci_device_id hsu_pci_id_table[] = {
114         { PCI_VDEVICE(INTEL, 0x081e), 0 },
115         { PCI_VDEVICE(INTEL, 0x1192), 0 },
116         { }
117 };
118 MODULE_DEVICE_TABLE(pci, hsu_pci_id_table);
119
120 static struct pci_driver hsu_pci_driver = {
121         .name           = "hsu_dma_pci",
122         .id_table       = hsu_pci_id_table,
123         .probe          = hsu_pci_probe,
124         .remove         = hsu_pci_remove,
125 };
126
127 module_pci_driver(hsu_pci_driver);
128
129 MODULE_LICENSE("GPL v2");
130 MODULE_DESCRIPTION("High Speed UART DMA PCI driver");
131 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");