0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/module.h>
0010 #include <linux/pci.h>
0011 #include <linux/device.h>
0012
0013 #include "internal.h"
0014
0015 static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
0016 {
0017 const struct dw_dma_chip_pdata *drv_data = (void *)pid->driver_data;
0018 struct dw_dma_chip_pdata *data;
0019 struct dw_dma_chip *chip;
0020 int ret;
0021
0022 ret = pcim_enable_device(pdev);
0023 if (ret)
0024 return ret;
0025
0026 ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
0027 if (ret) {
0028 dev_err(&pdev->dev, "I/O memory remapping failed\n");
0029 return ret;
0030 }
0031
0032 pci_set_master(pdev);
0033 pci_try_set_mwi(pdev);
0034
0035 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
0036 if (ret)
0037 return ret;
0038
0039 data = devm_kmemdup(&pdev->dev, drv_data, sizeof(*drv_data), GFP_KERNEL);
0040 if (!data)
0041 return -ENOMEM;
0042
0043 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
0044 if (!chip)
0045 return -ENOMEM;
0046
0047 chip->dev = &pdev->dev;
0048 chip->id = pdev->devfn;
0049 chip->regs = pcim_iomap_table(pdev)[0];
0050 chip->irq = pdev->irq;
0051 chip->pdata = data->pdata;
0052
0053 data->chip = chip;
0054
0055 ret = data->probe(chip);
0056 if (ret)
0057 return ret;
0058
0059 dw_dma_acpi_controller_register(chip->dw);
0060
0061 pci_set_drvdata(pdev, data);
0062
0063 return 0;
0064 }
0065
0066 static void dw_pci_remove(struct pci_dev *pdev)
0067 {
0068 struct dw_dma_chip_pdata *data = pci_get_drvdata(pdev);
0069 struct dw_dma_chip *chip = data->chip;
0070 int ret;
0071
0072 dw_dma_acpi_controller_free(chip->dw);
0073
0074 ret = data->remove(chip);
0075 if (ret)
0076 dev_warn(&pdev->dev, "can't remove device properly: %d\n", ret);
0077 }
0078
0079 #ifdef CONFIG_PM_SLEEP
0080
0081 static int dw_pci_suspend_late(struct device *dev)
0082 {
0083 struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
0084 struct dw_dma_chip *chip = data->chip;
0085
0086 return do_dw_dma_disable(chip);
0087 };
0088
0089 static int dw_pci_resume_early(struct device *dev)
0090 {
0091 struct dw_dma_chip_pdata *data = dev_get_drvdata(dev);
0092 struct dw_dma_chip *chip = data->chip;
0093
0094 return do_dw_dma_enable(chip);
0095 };
0096
0097 #endif
0098
0099 static const struct dev_pm_ops dw_pci_dev_pm_ops = {
0100 SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_pci_suspend_late, dw_pci_resume_early)
0101 };
0102
0103 static const struct pci_device_id dw_pci_id_table[] = {
0104
0105 { PCI_VDEVICE(INTEL, 0x0827), (kernel_ulong_t)&dw_dma_chip_pdata },
0106
0107
0108 { PCI_VDEVICE(INTEL, 0x0f06), (kernel_ulong_t)&dw_dma_chip_pdata },
0109 { PCI_VDEVICE(INTEL, 0x0f40), (kernel_ulong_t)&dw_dma_chip_pdata },
0110
0111
0112 { PCI_VDEVICE(INTEL, 0x11a2), (kernel_ulong_t)&idma32_chip_pdata },
0113
0114
0115 { PCI_VDEVICE(INTEL, 0x2286), (kernel_ulong_t)&dw_dma_chip_pdata },
0116 { PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_dma_chip_pdata },
0117
0118
0119 { PCI_VDEVICE(INTEL, 0x4bb4), (kernel_ulong_t)&xbar_chip_pdata },
0120 { PCI_VDEVICE(INTEL, 0x4bb5), (kernel_ulong_t)&xbar_chip_pdata },
0121 { PCI_VDEVICE(INTEL, 0x4bb6), (kernel_ulong_t)&xbar_chip_pdata },
0122
0123
0124 { PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_dma_chip_pdata },
0125
0126
0127 { PCI_VDEVICE(INTEL, 0x9ce0), (kernel_ulong_t)&dw_dma_chip_pdata },
0128
0129 { }
0130 };
0131 MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
0132
0133 static struct pci_driver dw_pci_driver = {
0134 .name = "dw_dmac_pci",
0135 .id_table = dw_pci_id_table,
0136 .probe = dw_pci_probe,
0137 .remove = dw_pci_remove,
0138 .driver = {
0139 .pm = &dw_pci_dev_pm_ops,
0140 },
0141 };
0142
0143 module_pci_driver(dw_pci_driver);
0144
0145 MODULE_LICENSE("GPL v2");
0146 MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller PCI driver");
0147 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");