blob: 4c30fdd092b3b1e5b7e6050b7e7d1afee6c11e57 [file] [log] [blame]
Andy Shevchenkofed42c12013-06-05 15:26:46 +03001/*
2 * PCI driver for the Synopsys DesignWare DMA Controller
3 *
4 * Copyright (C) 2013 Intel Corporation
5 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/pci.h>
14#include <linux/device.h>
15
16#include "internal.h"
17
Andy Shevchenkofed42c12013-06-05 15:26:46 +030018static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
19{
20 struct dw_dma_chip *chip;
21 struct dw_dma_platform_data *pdata = (void *)pid->driver_data;
22 int ret;
23
24 ret = pcim_enable_device(pdev);
25 if (ret)
26 return ret;
27
28 ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
29 if (ret) {
30 dev_err(&pdev->dev, "I/O memory remapping failed\n");
31 return ret;
32 }
33
34 pci_set_master(pdev);
35 pci_try_set_mwi(pdev);
36
37 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
38 if (ret)
39 return ret;
40
41 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
42 if (ret)
43 return ret;
44
45 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
46 if (!chip)
47 return -ENOMEM;
48
49 chip->dev = &pdev->dev;
50 chip->regs = pcim_iomap_table(pdev)[0];
51 chip->irq = pdev->irq;
52
53 ret = dw_dma_probe(chip, pdata);
54 if (ret)
55 return ret;
56
57 pci_set_drvdata(pdev, chip);
58
59 return 0;
60}
61
62static void dw_pci_remove(struct pci_dev *pdev)
63{
64 struct dw_dma_chip *chip = pci_get_drvdata(pdev);
65 int ret;
66
67 ret = dw_dma_remove(chip);
68 if (ret)
69 dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
70}
71
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +080072#ifdef CONFIG_PM_SLEEP
73
74static int dw_pci_suspend_late(struct device *dev)
75{
76 struct pci_dev *pci = to_pci_dev(dev);
77 struct dw_dma_chip *chip = pci_get_drvdata(pci);
78
Andy Shevchenko2540f742014-09-23 17:18:13 +030079 return dw_dma_disable(chip);
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +080080};
81
82static int dw_pci_resume_early(struct device *dev)
83{
84 struct pci_dev *pci = to_pci_dev(dev);
85 struct dw_dma_chip *chip = pci_get_drvdata(pci);
86
Andy Shevchenko2540f742014-09-23 17:18:13 +030087 return dw_dma_enable(chip);
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +080088};
89
Andy Shevchenkoc31b6ae2014-04-15 16:18:42 +030090#endif /* CONFIG_PM_SLEEP */
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +080091
92static const struct dev_pm_ops dw_pci_dev_pm_ops = {
Andy Shevchenkoc31b6ae2014-04-15 16:18:42 +030093 SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +080094};
95
Jingoo Han75878212014-05-09 14:59:36 +090096static const struct pci_device_id dw_pci_id_table[] = {
Andy Shevchenkofed42c12013-06-05 15:26:46 +030097 /* Medfield */
Andy Shevchenko6dbd80a2015-09-28 18:57:05 +030098 { PCI_VDEVICE(INTEL, 0x0827) },
99 { PCI_VDEVICE(INTEL, 0x0830) },
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300100
101 /* BayTrail */
Andy Shevchenko6dbd80a2015-09-28 18:57:05 +0300102 { PCI_VDEVICE(INTEL, 0x0f06) },
103 { PCI_VDEVICE(INTEL, 0x0f40) },
Andy Shevchenko24066812014-02-06 13:26:55 +0200104
Andy Shevchenkob279c492014-08-19 20:29:18 +0300105 /* Braswell */
Andy Shevchenko6dbd80a2015-09-28 18:57:05 +0300106 { PCI_VDEVICE(INTEL, 0x2286) },
107 { PCI_VDEVICE(INTEL, 0x22c0) },
Andy Shevchenkob279c492014-08-19 20:29:18 +0300108
Andy Shevchenko24066812014-02-06 13:26:55 +0200109 /* Haswell */
Andy Shevchenko6dbd80a2015-09-28 18:57:05 +0300110 { PCI_VDEVICE(INTEL, 0x9c60) },
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300111 { }
112};
113MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
114
115static struct pci_driver dw_pci_driver = {
116 .name = "dw_dmac_pci",
117 .id_table = dw_pci_id_table,
118 .probe = dw_pci_probe,
119 .remove = dw_pci_remove,
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800120 .driver = {
121 .pm = &dw_pci_dev_pm_ops,
122 },
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300123};
124
125module_pci_driver(dw_pci_driver);
126
127MODULE_LICENSE("GPL v2");
128MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
129MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");