Andy Shevchenko | b466a37 | 2019-01-07 13:07:41 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 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> |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/pci.h> |
| 11 | #include <linux/device.h> |
| 12 | |
| 13 | #include "internal.h" |
| 14 | |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 15 | struct dw_dma_pci_data { |
| 16 | const struct dw_dma_platform_data *pdata; |
| 17 | int (*probe)(struct dw_dma_chip *chip); |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 18 | int (*remove)(struct dw_dma_chip *chip); |
| 19 | struct dw_dma_chip *chip; |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | static const struct dw_dma_pci_data dw_pci_data = { |
| 23 | .probe = dw_dma_probe, |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 24 | .remove = dw_dma_remove, |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | static const struct dw_dma_platform_data idma32_pdata = { |
Andy Shevchenko | f7c799e9 | 2017-01-17 13:57:32 +0200 | [diff] [blame] | 28 | .nr_channels = 8, |
Andy Shevchenko | f7c799e9 | 2017-01-17 13:57:32 +0200 | [diff] [blame] | 29 | .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 Shevchenko | 87fe9ae | 2019-01-07 13:07:35 +0200 | [diff] [blame] | 34 | .multi_block = {1, 1, 1, 1, 1, 1, 1, 1}, |
Andy Shevchenko | f7c799e9 | 2017-01-17 13:57:32 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 37 | static const struct dw_dma_pci_data idma32_pci_data = { |
| 38 | .pdata = &idma32_pdata, |
| 39 | .probe = idma32_dma_probe, |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 40 | .remove = idma32_dma_remove, |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 43 | static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 44 | { |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 45 | const struct dw_dma_pci_data *drv_data = (void *)pid->driver_data; |
| 46 | struct dw_dma_pci_data *data; |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 47 | struct dw_dma_chip *chip; |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 48 | 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 Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 71 | data = devm_kmemdup(&pdev->dev, drv_data, sizeof(*drv_data), GFP_KERNEL); |
| 72 | if (!data) |
| 73 | return -ENOMEM; |
| 74 | |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 75 | chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); |
| 76 | if (!chip) |
| 77 | return -ENOMEM; |
| 78 | |
| 79 | chip->dev = &pdev->dev; |
Andy Shevchenko | 08d62f5 | 2017-01-17 13:57:26 +0200 | [diff] [blame] | 80 | chip->id = pdev->devfn; |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 81 | chip->regs = pcim_iomap_table(pdev)[0]; |
| 82 | chip->irq = pdev->irq; |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 83 | chip->pdata = data->pdata; |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 84 | |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 85 | data->chip = chip; |
| 86 | |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 87 | ret = data->probe(chip); |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 88 | if (ret) |
| 89 | return ret; |
| 90 | |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 91 | pci_set_drvdata(pdev, data); |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static void dw_pci_remove(struct pci_dev *pdev) |
| 97 | { |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 98 | struct dw_dma_pci_data *data = pci_get_drvdata(pdev); |
| 99 | struct dw_dma_chip *chip = data->chip; |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 100 | int ret; |
| 101 | |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 102 | ret = data->remove(chip); |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 103 | if (ret) |
| 104 | dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret); |
| 105 | } |
| 106 | |
Chew, Chiau Ee | 4501fe6 | 2014-03-15 02:02:39 +0800 | [diff] [blame] | 107 | #ifdef CONFIG_PM_SLEEP |
| 108 | |
| 109 | static int dw_pci_suspend_late(struct device *dev) |
| 110 | { |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 111 | struct dw_dma_pci_data *data = dev_get_drvdata(dev); |
| 112 | struct dw_dma_chip *chip = data->chip; |
Chew, Chiau Ee | 4501fe6 | 2014-03-15 02:02:39 +0800 | [diff] [blame] | 113 | |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 114 | return do_dw_dma_disable(chip); |
Chew, Chiau Ee | 4501fe6 | 2014-03-15 02:02:39 +0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | static int dw_pci_resume_early(struct device *dev) |
| 118 | { |
Andy Shevchenko | a183ec7 | 2019-06-14 14:06:04 +0300 | [diff] [blame] | 119 | struct dw_dma_pci_data *data = dev_get_drvdata(dev); |
| 120 | struct dw_dma_chip *chip = data->chip; |
Chew, Chiau Ee | 4501fe6 | 2014-03-15 02:02:39 +0800 | [diff] [blame] | 121 | |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 122 | return do_dw_dma_enable(chip); |
Chew, Chiau Ee | 4501fe6 | 2014-03-15 02:02:39 +0800 | [diff] [blame] | 123 | }; |
| 124 | |
Andy Shevchenko | c31b6ae | 2014-04-15 16:18:42 +0300 | [diff] [blame] | 125 | #endif /* CONFIG_PM_SLEEP */ |
Chew, Chiau Ee | 4501fe6 | 2014-03-15 02:02:39 +0800 | [diff] [blame] | 126 | |
| 127 | static const struct dev_pm_ops dw_pci_dev_pm_ops = { |
Andy Shevchenko | c31b6ae | 2014-04-15 16:18:42 +0300 | [diff] [blame] | 128 | SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early) |
Chew, Chiau Ee | 4501fe6 | 2014-03-15 02:02:39 +0800 | [diff] [blame] | 129 | }; |
| 130 | |
Jingoo Han | 7587821 | 2014-05-09 14:59:36 +0900 | [diff] [blame] | 131 | static const struct pci_device_id dw_pci_id_table[] = { |
Andy Shevchenko | ebb7fe2 | 2017-01-02 17:26:21 +0200 | [diff] [blame] | 132 | /* Medfield (GPDMA) */ |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 133 | { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_pci_data }, |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 134 | |
| 135 | /* BayTrail */ |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 136 | { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_pci_data }, |
| 137 | { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_pci_data }, |
Andy Shevchenko | 2406681 | 2014-02-06 13:26:55 +0200 | [diff] [blame] | 138 | |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 139 | /* Merrifield */ |
| 140 | { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&idma32_pci_data }, |
Andy Shevchenko | f7c799e9 | 2017-01-17 13:57:32 +0200 | [diff] [blame] | 141 | |
Andy Shevchenko | b279c49 | 2014-08-19 20:29:18 +0300 | [diff] [blame] | 142 | /* Braswell */ |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 143 | { PCI_VDEVICE(INTEL, 0x2286), (kernel_ulong_t)&dw_pci_data }, |
| 144 | { PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_pci_data }, |
Andy Shevchenko | b279c49 | 2014-08-19 20:29:18 +0300 | [diff] [blame] | 145 | |
Jarkko Nikula | b48b8bc | 2019-08-13 11:06:02 +0300 | [diff] [blame^] | 146 | /* Elkhart Lake iDMA 32-bit (PSE DMA) */ |
Andy Shevchenko | 9e5ab06 | 2019-06-21 16:19:14 +0300 | [diff] [blame] | 147 | { 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 Shevchenko | 2406681 | 2014-02-06 13:26:55 +0200 | [diff] [blame] | 151 | /* Haswell */ |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 152 | { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_pci_data }, |
Andy Shevchenko | 3efaf2a | 2016-01-29 16:27:07 +0200 | [diff] [blame] | 153 | |
| 154 | /* Broadwell */ |
Andy Shevchenko | 69da8be | 2019-01-07 13:07:38 +0200 | [diff] [blame] | 155 | { PCI_VDEVICE(INTEL, 0x9ce0), (kernel_ulong_t)&dw_pci_data }, |
Andy Shevchenko | 3efaf2a | 2016-01-29 16:27:07 +0200 | [diff] [blame] | 156 | |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 157 | { } |
| 158 | }; |
| 159 | MODULE_DEVICE_TABLE(pci, dw_pci_id_table); |
| 160 | |
| 161 | static 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 Ee | 4501fe6 | 2014-03-15 02:02:39 +0800 | [diff] [blame] | 166 | .driver = { |
| 167 | .pm = &dw_pci_dev_pm_ops, |
| 168 | }, |
Andy Shevchenko | fed42c1 | 2013-06-05 15:26:46 +0300 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | module_pci_driver(dw_pci_driver); |
| 172 | |
| 173 | MODULE_LICENSE("GPL v2"); |
| 174 | MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver"); |
| 175 | MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>"); |