1 // SPDX-License-Identifier: GPL-2.0-only
3 * PCI interface driver for DW SPI Core
5 * Copyright (c) 2009, 2014 Intel Corporation.
8 #include <linux/interrupt.h>
10 #include <linux/slab.h>
11 #include <linux/spi/spi.h>
12 #include <linux/module.h>
16 #define DRIVER_NAME "dw_spi_pci"
19 int (*setup)(struct dw_spi *);
24 static struct spi_pci_desc spi_pci_mid_desc_1 = {
25 .setup = dw_spi_mid_init,
30 static struct spi_pci_desc spi_pci_mid_desc_2 = {
31 .setup = dw_spi_mid_init,
36 static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39 struct spi_pci_desc *desc = (struct spi_pci_desc *)ent->driver_data;
43 ret = pcim_enable_device(pdev);
47 dws = devm_kzalloc(&pdev->dev, sizeof(*dws), GFP_KERNEL);
51 /* Get basic io resource and map it */
52 dws->paddr = pci_resource_start(pdev, pci_bar);
54 ret = pcim_iomap_regions(pdev, 1 << pci_bar, pci_name(pdev));
58 dws->regs = pcim_iomap_table(pdev)[pci_bar];
62 * Specific handling for platforms, like dma setup,
63 * clock rate, FIFO depth.
66 dws->num_cs = desc->num_cs;
67 dws->bus_num = desc->bus_num;
70 ret = desc->setup(dws);
78 ret = dw_spi_add_host(&pdev->dev, dws);
82 /* PCI hook and SPI hook use the same drv data */
83 pci_set_drvdata(pdev, dws);
85 dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
86 pdev->vendor, pdev->device);
91 static void spi_pci_remove(struct pci_dev *pdev)
93 struct dw_spi *dws = pci_get_drvdata(pdev);
95 dw_spi_remove_host(dws);
98 #ifdef CONFIG_PM_SLEEP
99 static int spi_suspend(struct device *dev)
101 struct pci_dev *pdev = to_pci_dev(dev);
102 struct dw_spi *dws = pci_get_drvdata(pdev);
104 return dw_spi_suspend_host(dws);
107 static int spi_resume(struct device *dev)
109 struct pci_dev *pdev = to_pci_dev(dev);
110 struct dw_spi *dws = pci_get_drvdata(pdev);
112 return dw_spi_resume_host(dws);
116 static SIMPLE_DEV_PM_OPS(dw_spi_pm_ops, spi_suspend, spi_resume);
118 static const struct pci_device_id pci_ids[] = {
119 /* Intel MID platform SPI controller 0 */
121 * The access to the device 8086:0801 is disabled by HW, since it's
122 * exclusively used by SCU to communicate with MSIC.
124 /* Intel MID platform SPI controller 1 */
125 { PCI_VDEVICE(INTEL, 0x0800), (kernel_ulong_t)&spi_pci_mid_desc_1},
126 /* Intel MID platform SPI controller 2 */
127 { PCI_VDEVICE(INTEL, 0x0812), (kernel_ulong_t)&spi_pci_mid_desc_2},
131 static struct pci_driver dw_spi_driver = {
134 .probe = spi_pci_probe,
135 .remove = spi_pci_remove,
137 .pm = &dw_spi_pm_ops,
141 module_pci_driver(dw_spi_driver);
143 MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
144 MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
145 MODULE_LICENSE("GPL v2");