blob: 39e30c3c7a9d4e810ee91151f3c878d093dcf6c9 [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
18static struct dw_dma_platform_data dw_pci_pdata = {
19 .is_private = 1,
20 .chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
21 .chan_priority = CHAN_PRIORITY_ASCENDING,
22};
23
24static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
25{
26 struct dw_dma_chip *chip;
27 struct dw_dma_platform_data *pdata = (void *)pid->driver_data;
28 int ret;
29
30 ret = pcim_enable_device(pdev);
31 if (ret)
32 return ret;
33
34 ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
35 if (ret) {
36 dev_err(&pdev->dev, "I/O memory remapping failed\n");
37 return ret;
38 }
39
40 pci_set_master(pdev);
41 pci_try_set_mwi(pdev);
42
43 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
44 if (ret)
45 return ret;
46
47 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
48 if (ret)
49 return ret;
50
51 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
52 if (!chip)
53 return -ENOMEM;
54
55 chip->dev = &pdev->dev;
56 chip->regs = pcim_iomap_table(pdev)[0];
57 chip->irq = pdev->irq;
58
59 ret = dw_dma_probe(chip, pdata);
60 if (ret)
61 return ret;
62
63 pci_set_drvdata(pdev, chip);
64
65 return 0;
66}
67
68static void dw_pci_remove(struct pci_dev *pdev)
69{
70 struct dw_dma_chip *chip = pci_get_drvdata(pdev);
71 int ret;
72
73 ret = dw_dma_remove(chip);
74 if (ret)
75 dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
76}
77
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +080078#ifdef CONFIG_PM_SLEEP
79
80static int dw_pci_suspend_late(struct device *dev)
81{
82 struct pci_dev *pci = to_pci_dev(dev);
83 struct dw_dma_chip *chip = pci_get_drvdata(pci);
84
85 return dw_dma_suspend(chip);
86};
87
88static int dw_pci_resume_early(struct device *dev)
89{
90 struct pci_dev *pci = to_pci_dev(dev);
91 struct dw_dma_chip *chip = pci_get_drvdata(pci);
92
93 return dw_dma_resume(chip);
94};
95
Andy Shevchenkoc31b6ae2014-04-15 16:18:42 +030096#endif /* CONFIG_PM_SLEEP */
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +080097
98static const struct dev_pm_ops dw_pci_dev_pm_ops = {
Andy Shevchenkoc31b6ae2014-04-15 16:18:42 +030099 SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800100};
101
Jingoo Han75878212014-05-09 14:59:36 +0900102static const struct pci_device_id dw_pci_id_table[] = {
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300103 /* Medfield */
104 { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_pci_pdata },
105 { PCI_VDEVICE(INTEL, 0x0830), (kernel_ulong_t)&dw_pci_pdata },
106
107 /* BayTrail */
108 { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_pci_pdata },
109 { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_pci_pdata },
Andy Shevchenko24066812014-02-06 13:26:55 +0200110
111 /* Haswell */
112 { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_pci_pdata },
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300113 { }
114};
115MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
116
117static struct pci_driver dw_pci_driver = {
118 .name = "dw_dmac_pci",
119 .id_table = dw_pci_id_table,
120 .probe = dw_pci_probe,
121 .remove = dw_pci_remove,
Chew, Chiau Ee4501fe62014-03-15 02:02:39 +0800122 .driver = {
123 .pm = &dw_pci_dev_pm_ops,
124 },
Andy Shevchenkofed42c12013-06-05 15:26:46 +0300125};
126
127module_pci_driver(dw_pci_driver);
128
129MODULE_LICENSE("GPL v2");
130MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
131MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");