treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / dma / dw / pci.c
blobcf6e8ec4c0ff47c20e7420ae3c8f4f697bb32370
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * PCI driver for the Synopsys DesignWare DMA Controller
5 * Copyright (C) 2013 Intel Corporation
6 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
7 */
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/device.h>
13 #include "internal.h"
15 static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
17 const struct dw_dma_chip_pdata *drv_data = (void *)pid->driver_data;
18 struct dw_dma_chip_pdata *data;
19 struct dw_dma_chip *chip;
20 int ret;
22 ret = pcim_enable_device(pdev);
23 if (ret)
24 return ret;
26 ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
27 if (ret) {
28 dev_err(&pdev->dev, "I/O memory remapping failed\n");
29 return ret;
32 pci_set_master(pdev);
33 pci_try_set_mwi(pdev);
35 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
36 if (ret)
37 return ret;
39 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
40 if (ret)
41 return ret;
43 data = devm_kmemdup(&pdev->dev, drv_data, sizeof(*drv_data), GFP_KERNEL);
44 if (!data)
45 return -ENOMEM;
47 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
48 if (!chip)
49 return -ENOMEM;
51 chip->dev = &pdev->dev;
52 chip->id = pdev->devfn;
53 chip->regs = pcim_iomap_table(pdev)[0];
54 chip->irq = pdev->irq;
55 chip->pdata = data->pdata;
57 data->chip = chip;
59 ret = data->probe(chip);
60 if (ret)
61 return ret;
63 pci_set_drvdata(pdev, data);
65 return 0;
68 static void dw_pci_remove(struct pci_dev *pdev)
70 struct dw_dma_chip_pdata *data = pci_get_drvdata(pdev);
71 struct dw_dma_chip *chip = data->chip;
72 int ret;
74 ret = data->remove(chip);
75 if (ret)
76 dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
79 #ifdef CONFIG_PM_SLEEP
81 static int dw_pci_suspend_late(struct device *dev)
83 struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
84 struct dw_dma_chip *chip = data->chip;
86 return do_dw_dma_disable(chip);
89 static int dw_pci_resume_early(struct device *dev)
91 struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
92 struct dw_dma_chip *chip = data->chip;
94 return do_dw_dma_enable(chip);
97 #endif /* CONFIG_PM_SLEEP */
99 static const struct dev_pm_ops dw_pci_dev_pm_ops = {
100 SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
103 static const struct pci_device_id dw_pci_id_table[] = {
104 /* Medfield (GPDMA) */
105 { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_dma_chip_pdata },
107 /* BayTrail */
108 { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_dma_chip_pdata },
109 { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_dma_chip_pdata },
111 /* Merrifield */
112 { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&idma32_chip_pdata },
114 /* Braswell */
115 { PCI_VDEVICE(INTEL, 0x2286), (kernel_ulong_t)&dw_dma_chip_pdata },
116 { PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_dma_chip_pdata },
118 /* Elkhart Lake iDMA 32-bit (PSE DMA) */
119 { PCI_VDEVICE(INTEL, 0x4bb4), (kernel_ulong_t)&idma32_chip_pdata },
120 { PCI_VDEVICE(INTEL, 0x4bb5), (kernel_ulong_t)&idma32_chip_pdata },
121 { PCI_VDEVICE(INTEL, 0x4bb6), (kernel_ulong_t)&idma32_chip_pdata },
123 /* Haswell */
124 { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_dma_chip_pdata },
126 /* Broadwell */
127 { PCI_VDEVICE(INTEL, 0x9ce0), (kernel_ulong_t)&dw_dma_chip_pdata },
131 MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
133 static struct pci_driver dw_pci_driver = {
134 .name = "dw_dmac_pci",
135 .id_table = dw_pci_id_table,
136 .probe = dw_pci_probe,
137 .remove = dw_pci_remove,
138 .driver = {
139 .pm = &dw_pci_dev_pm_ops,
143 module_pci_driver(dw_pci_driver);
145 MODULE_LICENSE("GPL v2");
146 MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
147 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");