dmaengine: at_hdmac: add missing kernel-doc style description
[linux-block.git] / drivers / dma / dw / pci.c
CommitLineData
b466a37f 1// SPDX-License-Identifier: GPL-2.0
fed42c19
AS
2/*
3 * PCI driver for the Synopsys DesignWare DMA Controller
4 *
5 * Copyright (C) 2013 Intel Corporation
6 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
fed42c19
AS
7 */
8
9#include <linux/module.h>
10#include <linux/pci.h>
11#include <linux/device.h>
12
13#include "internal.h"
14
fed42c19
AS
15static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
16{
ae923c91
AS
17 const struct dw_dma_chip_pdata *drv_data = (void *)pid->driver_data;
18 struct dw_dma_chip_pdata *data;
fed42c19 19 struct dw_dma_chip *chip;
fed42c19
AS
20 int ret;
21
22 ret = pcim_enable_device(pdev);
23 if (ret)
24 return ret;
25
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;
30 }
31
32 pci_set_master(pdev);
33 pci_try_set_mwi(pdev);
34
1365e117 35 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
fed42c19
AS
36 if (ret)
37 return ret;
38
a183ec70
AS
39 data = devm_kmemdup(&pdev->dev, drv_data, sizeof(*drv_data), GFP_KERNEL);
40 if (!data)
41 return -ENOMEM;
42
fed42c19
AS
43 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
44 if (!chip)
45 return -ENOMEM;
46
47 chip->dev = &pdev->dev;
08d62f58 48 chip->id = pdev->devfn;
fed42c19
AS
49 chip->regs = pcim_iomap_table(pdev)[0];
50 chip->irq = pdev->irq;
69da8be9 51 chip->pdata = data->pdata;
fed42c19 52
a183ec70
AS
53 data->chip = chip;
54
69da8be9 55 ret = data->probe(chip);
fed42c19
AS
56 if (ret)
57 return ret;
58
38e4fb66
AS
59 dw_dma_acpi_controller_register(chip->dw);
60
a183ec70 61 pci_set_drvdata(pdev, data);
fed42c19
AS
62
63 return 0;
64}
65
66static void dw_pci_remove(struct pci_dev *pdev)
67{
ae923c91 68 struct dw_dma_chip_pdata *data = pci_get_drvdata(pdev);
a183ec70 69 struct dw_dma_chip *chip = data->chip;
fed42c19
AS
70 int ret;
71
38e4fb66
AS
72 dw_dma_acpi_controller_free(chip->dw);
73
a183ec70 74 ret = data->remove(chip);
fed42c19
AS
75 if (ret)
76 dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
77}
78
4501fe61
CCE
79#ifdef CONFIG_PM_SLEEP
80
81static int dw_pci_suspend_late(struct device *dev)
82{
ae923c91 83 struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
a183ec70 84 struct dw_dma_chip *chip = data->chip;
4501fe61 85
69da8be9 86 return do_dw_dma_disable(chip);
4501fe61
CCE
87};
88
89static int dw_pci_resume_early(struct device *dev)
90{
ae923c91 91 struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
a183ec70 92 struct dw_dma_chip *chip = data->chip;
4501fe61 93
69da8be9 94 return do_dw_dma_enable(chip);
4501fe61
CCE
95};
96
c31b6ae1 97#endif /* CONFIG_PM_SLEEP */
4501fe61
CCE
98
99static const struct dev_pm_ops dw_pci_dev_pm_ops = {
c31b6ae1 100 SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
4501fe61
CCE
101};
102
7587821d 103static const struct pci_device_id dw_pci_id_table[] = {
ebb7fe21 104 /* Medfield (GPDMA) */
ae923c91 105 { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_dma_chip_pdata },
fed42c19
AS
106
107 /* BayTrail */
ae923c91
AS
108 { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_dma_chip_pdata },
109 { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_dma_chip_pdata },
24066813 110
69da8be9 111 /* Merrifield */
ae923c91 112 { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&idma32_chip_pdata },
f7c799e9 113
b279c492 114 /* Braswell */
ae923c91
AS
115 { PCI_VDEVICE(INTEL, 0x2286), (kernel_ulong_t)&dw_dma_chip_pdata },
116 { PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_dma_chip_pdata },
b279c492 117
b48b8bc4 118 /* Elkhart Lake iDMA 32-bit (PSE DMA) */
fe364a7d
AS
119 { PCI_VDEVICE(INTEL, 0x4bb4), (kernel_ulong_t)&xbar_chip_pdata },
120 { PCI_VDEVICE(INTEL, 0x4bb5), (kernel_ulong_t)&xbar_chip_pdata },
121 { PCI_VDEVICE(INTEL, 0x4bb6), (kernel_ulong_t)&xbar_chip_pdata },
9e5ab065 122
24066813 123 /* Haswell */
ae923c91 124 { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_dma_chip_pdata },
3efaf2a9
AS
125
126 /* Broadwell */
ae923c91 127 { PCI_VDEVICE(INTEL, 0x9ce0), (kernel_ulong_t)&dw_dma_chip_pdata },
3efaf2a9 128
fed42c19
AS
129 { }
130};
131MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
132
133static 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,
4501fe61
CCE
138 .driver = {
139 .pm = &dw_pci_dev_pm_ops,
140 },
fed42c19
AS
141};
142
143module_pci_driver(dw_pci_driver);
144
145MODULE_LICENSE("GPL v2");
146MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
147MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");