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