]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/dma/dw/pci.c
313ba10c6224d6cff361806ec0be9bee88ac2c29
[linux.git] / drivers / dma / dw / pci.c
1 /*
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
18 static struct dw_dma_platform_data mrfld_pdata = {
19         .nr_channels = 8,
20         .is_private = true,
21         .is_memcpy = true,
22         .is_idma32 = true,
23         .chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
24         .chan_priority = CHAN_PRIORITY_ASCENDING,
25         .block_size = 131071,
26         .nr_masters = 1,
27         .data_width = {4},
28         .multi_block = {1, 1, 1, 1, 1, 1, 1, 1},
29 };
30
31 static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
32 {
33         const struct dw_dma_platform_data *pdata = (void *)pid->driver_data;
34         struct dw_dma_chip *chip;
35         int ret;
36
37         ret = pcim_enable_device(pdev);
38         if (ret)
39                 return ret;
40
41         ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
42         if (ret) {
43                 dev_err(&pdev->dev, "I/O memory remapping failed\n");
44                 return ret;
45         }
46
47         pci_set_master(pdev);
48         pci_try_set_mwi(pdev);
49
50         ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
51         if (ret)
52                 return ret;
53
54         ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
55         if (ret)
56                 return ret;
57
58         chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
59         if (!chip)
60                 return -ENOMEM;
61
62         chip->dev = &pdev->dev;
63         chip->id = pdev->devfn;
64         chip->regs = pcim_iomap_table(pdev)[0];
65         chip->irq = pdev->irq;
66         chip->pdata = pdata;
67
68         ret = dw_dma_probe(chip);
69         if (ret)
70                 return ret;
71
72         pci_set_drvdata(pdev, chip);
73
74         return 0;
75 }
76
77 static void dw_pci_remove(struct pci_dev *pdev)
78 {
79         struct dw_dma_chip *chip = pci_get_drvdata(pdev);
80         int ret;
81
82         ret = dw_dma_remove(chip);
83         if (ret)
84                 dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
85 }
86
87 #ifdef CONFIG_PM_SLEEP
88
89 static int dw_pci_suspend_late(struct device *dev)
90 {
91         struct pci_dev *pci = to_pci_dev(dev);
92         struct dw_dma_chip *chip = pci_get_drvdata(pci);
93
94         return dw_dma_disable(chip);
95 };
96
97 static int dw_pci_resume_early(struct device *dev)
98 {
99         struct pci_dev *pci = to_pci_dev(dev);
100         struct dw_dma_chip *chip = pci_get_drvdata(pci);
101
102         return dw_dma_enable(chip);
103 };
104
105 #endif /* CONFIG_PM_SLEEP */
106
107 static const struct dev_pm_ops dw_pci_dev_pm_ops = {
108         SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
109 };
110
111 static const struct pci_device_id dw_pci_id_table[] = {
112         /* Medfield (GPDMA) */
113         { PCI_VDEVICE(INTEL, 0x0827) },
114
115         /* BayTrail */
116         { PCI_VDEVICE(INTEL, 0x0f06) },
117         { PCI_VDEVICE(INTEL, 0x0f40) },
118
119         /* Merrifield iDMA 32-bit (GPDMA) */
120         { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&mrfld_pdata },
121
122         /* Braswell */
123         { PCI_VDEVICE(INTEL, 0x2286) },
124         { PCI_VDEVICE(INTEL, 0x22c0) },
125
126         /* Haswell */
127         { PCI_VDEVICE(INTEL, 0x9c60) },
128
129         /* Broadwell */
130         { PCI_VDEVICE(INTEL, 0x9ce0) },
131
132         { }
133 };
134 MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
135
136 static struct pci_driver dw_pci_driver = {
137         .name           = "dw_dmac_pci",
138         .id_table       = dw_pci_id_table,
139         .probe          = dw_pci_probe,
140         .remove         = dw_pci_remove,
141         .driver = {
142                 .pm     = &dw_pci_dev_pm_ops,
143         },
144 };
145
146 module_pci_driver(dw_pci_driver);
147
148 MODULE_LICENSE("GPL v2");
149 MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
150 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");