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/pm_runtime.h>
11 #include <linux/slab.h>
12 #include <linux/spi/spi.h>
13 #include <linux/module.h>
17 #define DRIVER_NAME "dw_spi_pci"
20 int (*setup)(struct dw_spi *);
26 static struct spi_pci_desc spi_pci_mid_desc_1 = {
27 .setup = dw_spi_mid_init,
32 static struct spi_pci_desc spi_pci_mid_desc_2 = {
33 .setup = dw_spi_mid_init,
38 static struct spi_pci_desc spi_pci_ehl_desc = {
41 .max_freq = 100000000,
44 static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47 struct spi_pci_desc *desc = (struct spi_pci_desc *)ent->driver_data;
51 ret = pcim_enable_device(pdev);
55 dws = devm_kzalloc(&pdev->dev, sizeof(*dws), GFP_KERNEL);
59 /* Get basic io resource and map it */
60 dws->paddr = pci_resource_start(pdev, pci_bar);
63 ret = pcim_iomap_regions(pdev, 1 << pci_bar, pci_name(pdev));
67 ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
71 dws->regs = pcim_iomap_table(pdev)[pci_bar];
72 dws->irq = pci_irq_vector(pdev, 0);
75 * Specific handling for platforms, like dma setup,
76 * clock rate, FIFO depth.
79 dws->num_cs = desc->num_cs;
80 dws->bus_num = desc->bus_num;
81 dws->max_freq = desc->max_freq;
84 ret = desc->setup(dws);
89 pci_free_irq_vectors(pdev);
93 ret = dw_spi_add_host(&pdev->dev, dws);
95 pci_free_irq_vectors(pdev);
99 /* PCI hook and SPI hook use the same drv data */
100 pci_set_drvdata(pdev, dws);
102 dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
103 pdev->vendor, pdev->device);
105 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000);
106 pm_runtime_use_autosuspend(&pdev->dev);
107 pm_runtime_put_autosuspend(&pdev->dev);
108 pm_runtime_allow(&pdev->dev);
113 static void spi_pci_remove(struct pci_dev *pdev)
115 struct dw_spi *dws = pci_get_drvdata(pdev);
117 pm_runtime_forbid(&pdev->dev);
118 pm_runtime_get_noresume(&pdev->dev);
120 dw_spi_remove_host(dws);
121 pci_free_irq_vectors(pdev);
124 #ifdef CONFIG_PM_SLEEP
125 static int spi_suspend(struct device *dev)
127 struct dw_spi *dws = dev_get_drvdata(dev);
129 return dw_spi_suspend_host(dws);
132 static int spi_resume(struct device *dev)
134 struct dw_spi *dws = dev_get_drvdata(dev);
136 return dw_spi_resume_host(dws);
140 static SIMPLE_DEV_PM_OPS(dw_spi_pm_ops, spi_suspend, spi_resume);
142 static const struct pci_device_id pci_ids[] = {
143 /* Intel MID platform SPI controller 0 */
145 * The access to the device 8086:0801 is disabled by HW, since it's
146 * exclusively used by SCU to communicate with MSIC.
148 /* Intel MID platform SPI controller 1 */
149 { PCI_VDEVICE(INTEL, 0x0800), (kernel_ulong_t)&spi_pci_mid_desc_1},
150 /* Intel MID platform SPI controller 2 */
151 { PCI_VDEVICE(INTEL, 0x0812), (kernel_ulong_t)&spi_pci_mid_desc_2},
152 /* Intel Elkhart Lake PSE SPI controllers */
153 { PCI_VDEVICE(INTEL, 0x4b84), (kernel_ulong_t)&spi_pci_ehl_desc},
154 { PCI_VDEVICE(INTEL, 0x4b85), (kernel_ulong_t)&spi_pci_ehl_desc},
155 { PCI_VDEVICE(INTEL, 0x4b86), (kernel_ulong_t)&spi_pci_ehl_desc},
156 { PCI_VDEVICE(INTEL, 0x4b87), (kernel_ulong_t)&spi_pci_ehl_desc},
159 MODULE_DEVICE_TABLE(pci, pci_ids);
161 static struct pci_driver dw_spi_driver = {
164 .probe = spi_pci_probe,
165 .remove = spi_pci_remove,
167 .pm = &dw_spi_pm_ops,
171 module_pci_driver(dw_spi_driver);
174 MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
175 MODULE_LICENSE("GPL v2");