blob: ad6db1cc287e2f050d4b9ea15abc39e8466d105c [file] [log] [blame]
Andy Shevchenkob466a372019-01-07 13:07:41 +02001// SPDX-License-Identifier: GPL-2.0
Andy Shevchenkofed42c12013-06-05 15:26:46 +03002/*
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>
Andy Shevchenkofed42c12013-06-05 15:26:46 +03007 */
8
9#include <linux/module.h>
10#include <linux/pci.h>
11#include <linux/device.h>
12
13#include "internal.h"
14
Andy Shevchenko69da8be2019-01-07 13:07:38 +020015struct dw_dma_pci_data {
16 const struct dw_dma_platform_data *pdata;
17 int (*probe)(struct dw_dma_chip *chip);
Andy Shevchenkoa183ec72019-06-14 14:06:04 +030018 int (*remove)(struct dw_dma_chip *chip);
19 struct dw_dma_chip *chip;
Andy Shevchenko69da8be2019-01-07 13:07:38 +020020};
21
22static const struct dw_dma_pci_data dw_pci_data = {
23 .probe = dw_dma_probe,
Andy Shevchenkoa183ec72019-06-14 14:06:04 +030024 .remove = dw_dma_remove,
Andy Shevchenko69da8be2019-01-07 13:07:38 +020025};
26
27static const struct dw_dma_platform_data idma32_pdata = {
Andy Shevchenkof7c799e92017-01-17 13:57:32 +020028 .nr_channels = 8,
Andy Shevchenkof7c799e92017-01-17 13:57:32 +020029 .chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
30 .chan_priority = CHAN_PRIORITY_ASCENDING,
31 .block_size = 131071,
32 .nr_masters = 1,
33 .data_width = {4},
Andy Shevchenko87fe9ae2019-01-07 13:07:35 +020034 .multi_block = {1, 1, 1, 1, 1, 1, 1, 1},
Andy Shevchenkof7c799e92017-01-17 13:57:32 +020035};
36
Andy Shevchenko69da8be2019-01-07 13:07:38 +020037static const struct dw_dma_pci_data idma32_pci_data = {
38 .pdata = &idma32_pdata,
39 .probe = idma32_dma_probe,
Andy Shevchenkoa183ec72019-06-14 14:06:04 +030040 .remove = idma32_dma_remove,
Andy Shevchenko69da8be2019-01-07 13:07:38 +020041};
42
Andy Shevchenkofed42c12013-06-05 15:26:46 +030043static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
44{
Andy Shevchenkoa183ec72019-06-14 14:06:04 +030045 const struct dw_dma_pci_data *drv_data = (void *)pid->driver_data;
46 struct dw_dma_pci_data *data;
Andy Shevchenkofed42c12013-06-05 15:26:46 +030047 struct dw_dma_chip *chip;
Andy Shevchenkofed42c12013-06-05 15:26:46 +030048 int ret;
49
50 ret = pcim_enable_device(pdev);
51 if (ret)
52 return ret;
53
54 ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
55 if (ret) {
56 dev_err(&pdev->dev, "I/O memory remapping failed\n");
57 return ret;
58 }
59
60 pci_set_master(pdev);
61 pci_try_set_mwi(pdev);
62
63 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
64 if (ret)
65 return ret;
66
67 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
68 if (ret)
69 return ret;
70
Andy Shevchenkoa183ec72019-06-14 14:06:04 +030071 data = devm_kmemdup(&pdev->dev, drv_data, sizeof(*drv_data), GFP_KERNEL);
72 if (!data)
73 return -ENOMEM;
74
Andy Shevchenkofed42c12013-06-05 15:26:46 +030075 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
76 if (!chip)
77 return -ENOMEM;
78
79 chip->dev = &pdev->dev;
Andy Shevchenko08d62f52017-01-17 13:57:26 +020080 chip->id = pdev->devfn;
Andy Shevchenkofed42c12013-06-05 15:26:46 +030081 chip->regs = pcim_iomap_table(pdev)[0];
82 chip->irq = pdev->irq;
Andy Shevchenko69da8be2019-01-07 13:07:38 +020083 chip->pdata = data->pdata;
Andy Shevchenkofed42c12013-06-05 15:26:46 +030084
Andy Shevchenkoa183ec72019-06-14 14:06:04 +030085 data->chip = chip;
86
Andy Shevchenko69da8be2019-01-07 13:07:38 +020087 ret = data->probe(chip);
Andy Shevchenkofed42c12013-06-05 15:26:46 +030088 if (ret)
89 return ret;
90
Andy Shevchenkoa183ec72019-06-14 14:06:04 +030091 pci_set_drvdata(pdev, data);
Andy Shevchenkofed42c12013-06-05 15:26:46 +030092
93 return 0;
94}
95
96static void dw_pci_remove(struct pci_dev *pdev)
97{
Andy Shevchenkoa183ec72019-06-14 14:06:04 +030098 struct dw_dma_pci_data *data = pci_get_drvdata(pdev);
99 struct dw_dma_chip *chip = data->chip;
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300100 int ret;
101
Andy Shevchenkoa183ec72019-06-14 14:06:04 +0300102 ret = data->remove(chip);
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300103 if (ret)
104 dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
105}
106
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800107#ifdef CONFIG_PM_SLEEP
108
109static int dw_pci_suspend_late(struct device *dev)
110{
Andy Shevchenkoa183ec72019-06-14 14:06:04 +0300111 struct dw_dma_pci_data *data = dev_get_drvdata(dev);
112 struct dw_dma_chip *chip = data->chip;
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800113
Andy Shevchenko69da8be2019-01-07 13:07:38 +0200114 return do_dw_dma_disable(chip);
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800115};
116
117static int dw_pci_resume_early(struct device *dev)
118{
Andy Shevchenkoa183ec72019-06-14 14:06:04 +0300119 struct dw_dma_pci_data *data = dev_get_drvdata(dev);
120 struct dw_dma_chip *chip = data->chip;
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800121
Andy Shevchenko69da8be2019-01-07 13:07:38 +0200122 return do_dw_dma_enable(chip);
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800123};
124
Andy Shevchenkoc31b6ae2014-04-15 16:18:42 +0300125#endif /* CONFIG_PM_SLEEP */
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800126
127static const struct dev_pm_ops dw_pci_dev_pm_ops = {
Andy Shevchenkoc31b6ae2014-04-15 16:18:42 +0300128 SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800129};
130
Jingoo Han75878212014-05-09 14:59:36 +0900131static const struct pci_device_id dw_pci_id_table[] = {
Andy Shevchenkoebb7fe22017-01-02 17:26:21 +0200132 /* Medfield (GPDMA) */
Andy Shevchenko69da8be2019-01-07 13:07:38 +0200133 { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_pci_data },
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300134
135 /* BayTrail */
Andy Shevchenko69da8be2019-01-07 13:07:38 +0200136 { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_pci_data },
137 { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_pci_data },
Andy Shevchenko24066812014-02-06 13:26:55 +0200138
Andy Shevchenko69da8be2019-01-07 13:07:38 +0200139 /* Merrifield */
140 { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&idma32_pci_data },
Andy Shevchenkof7c799e92017-01-17 13:57:32 +0200141
Andy Shevchenkob279c492014-08-19 20:29:18 +0300142 /* Braswell */
Andy Shevchenko69da8be2019-01-07 13:07:38 +0200143 { PCI_VDEVICE(INTEL, 0x2286), (kernel_ulong_t)&dw_pci_data },
144 { PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_pci_data },
Andy Shevchenkob279c492014-08-19 20:29:18 +0300145
Jarkko Nikulab48b8bc2019-08-13 11:06:02 +0300146 /* Elkhart Lake iDMA 32-bit (PSE DMA) */
Andy Shevchenko9e5ab062019-06-21 16:19:14 +0300147 { PCI_VDEVICE(INTEL, 0x4bb4), (kernel_ulong_t)&idma32_pci_data },
148 { PCI_VDEVICE(INTEL, 0x4bb5), (kernel_ulong_t)&idma32_pci_data },
149 { PCI_VDEVICE(INTEL, 0x4bb6), (kernel_ulong_t)&idma32_pci_data },
150
Andy Shevchenko24066812014-02-06 13:26:55 +0200151 /* Haswell */
Andy Shevchenko69da8be2019-01-07 13:07:38 +0200152 { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_pci_data },
Andy Shevchenko3efaf2a2016-01-29 16:27:07 +0200153
154 /* Broadwell */
Andy Shevchenko69da8be2019-01-07 13:07:38 +0200155 { PCI_VDEVICE(INTEL, 0x9ce0), (kernel_ulong_t)&dw_pci_data },
Andy Shevchenko3efaf2a2016-01-29 16:27:07 +0200156
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300157 { }
158};
159MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
160
161static struct pci_driver dw_pci_driver = {
162 .name = "dw_dmac_pci",
163 .id_table = dw_pci_id_table,
164 .probe = dw_pci_probe,
165 .remove = dw_pci_remove,
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800166 .driver = {
167 .pm = &dw_pci_dev_pm_ops,
168 },
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300169};
170
171module_pci_driver(dw_pci_driver);
172
173MODULE_LICENSE("GPL v2");
174MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
175MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");