2019-05-29 21:18:02 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-12-15 05:20:22 +07:00
|
|
|
/*
|
2011-06-06 14:16:30 +07:00
|
|
|
* PCI interface driver for DW SPI Core
|
2009-12-15 05:20:22 +07:00
|
|
|
*
|
2014-08-29 16:41:43 +07:00
|
|
|
* Copyright (c) 2009, 2014 Intel Corporation.
|
2009-12-15 05:20:22 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/pci.h>
|
2019-10-18 20:21:30 +07:00
|
|
|
#include <linux/pm_runtime.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-12-15 05:20:22 +07:00
|
|
|
#include <linux/spi/spi.h>
|
2011-07-04 02:44:29 +07:00
|
|
|
#include <linux/module.h>
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2011-06-06 14:16:30 +07:00
|
|
|
#include "spi-dw.h"
|
2011-03-01 02:47:12 +07:00
|
|
|
|
2009-12-15 05:20:22 +07:00
|
|
|
#define DRIVER_NAME "dw_spi_pci"
|
|
|
|
|
2014-08-29 16:41:42 +07:00
|
|
|
struct spi_pci_desc {
|
|
|
|
int (*setup)(struct dw_spi *);
|
2015-01-07 22:15:00 +07:00
|
|
|
u16 num_cs;
|
|
|
|
u16 bus_num;
|
2019-08-12 17:13:44 +07:00
|
|
|
u32 max_freq;
|
2014-08-29 16:41:42 +07:00
|
|
|
};
|
|
|
|
|
2015-01-07 22:15:00 +07:00
|
|
|
static struct spi_pci_desc spi_pci_mid_desc_1 = {
|
2014-08-29 16:41:42 +07:00
|
|
|
.setup = dw_spi_mid_init,
|
2015-02-23 22:55:54 +07:00
|
|
|
.num_cs = 5,
|
2015-01-07 22:15:00 +07:00
|
|
|
.bus_num = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_pci_desc spi_pci_mid_desc_2 = {
|
|
|
|
.setup = dw_spi_mid_init,
|
2015-02-23 22:55:54 +07:00
|
|
|
.num_cs = 2,
|
2015-01-07 22:15:00 +07:00
|
|
|
.bus_num = 1,
|
2014-08-29 16:41:42 +07:00
|
|
|
};
|
|
|
|
|
2019-08-12 17:13:44 +07:00
|
|
|
static struct spi_pci_desc spi_pci_ehl_desc = {
|
2019-10-18 20:21:31 +07:00
|
|
|
.num_cs = 2,
|
2019-08-12 17:13:44 +07:00
|
|
|
.bus_num = -1,
|
|
|
|
.max_freq = 100000000,
|
|
|
|
};
|
|
|
|
|
2014-08-29 16:41:42 +07:00
|
|
|
static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
|
|
|
struct dw_spi *dws;
|
2014-08-29 16:41:42 +07:00
|
|
|
struct spi_pci_desc *desc = (struct spi_pci_desc *)ent->driver_data;
|
2009-12-15 05:20:22 +07:00
|
|
|
int pci_bar = 0;
|
|
|
|
int ret;
|
|
|
|
|
2013-12-31 01:30:44 +07:00
|
|
|
ret = pcim_enable_device(pdev);
|
2009-12-15 05:20:22 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-10-15 03:12:24 +07:00
|
|
|
dws = devm_kzalloc(&pdev->dev, sizeof(*dws), GFP_KERNEL);
|
|
|
|
if (!dws)
|
2013-12-31 01:30:44 +07:00
|
|
|
return -ENOMEM;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
/* Get basic io resource and map it */
|
|
|
|
dws->paddr = pci_resource_start(pdev, pci_bar);
|
2019-10-01 15:14:05 +07:00
|
|
|
pci_set_master(pdev);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2014-08-29 16:41:40 +07:00
|
|
|
ret = pcim_iomap_regions(pdev, 1 << pci_bar, pci_name(pdev));
|
2009-12-15 05:20:22 +07:00
|
|
|
if (ret)
|
2013-12-31 01:30:44 +07:00
|
|
|
return ret;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2019-10-01 15:14:05 +07:00
|
|
|
ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2014-08-27 20:21:12 +07:00
|
|
|
dws->regs = pcim_iomap_table(pdev)[pci_bar];
|
2019-10-01 15:14:05 +07:00
|
|
|
dws->irq = pci_irq_vector(pdev, 0);
|
2010-12-24 12:59:11 +07:00
|
|
|
|
|
|
|
/*
|
2016-05-11 01:59:58 +07:00
|
|
|
* Specific handling for platforms, like dma setup,
|
2010-12-24 12:59:11 +07:00
|
|
|
* clock rate, FIFO depth.
|
|
|
|
*/
|
2015-01-07 22:15:00 +07:00
|
|
|
if (desc) {
|
2015-01-22 22:59:34 +07:00
|
|
|
dws->num_cs = desc->num_cs;
|
|
|
|
dws->bus_num = desc->bus_num;
|
2019-08-12 17:13:44 +07:00
|
|
|
dws->max_freq = desc->max_freq;
|
2015-01-22 22:59:34 +07:00
|
|
|
|
2015-01-07 22:15:00 +07:00
|
|
|
if (desc->setup) {
|
|
|
|
ret = desc->setup(dws);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
2019-10-01 15:14:05 +07:00
|
|
|
pci_free_irq_vectors(pdev);
|
2015-01-07 22:15:00 +07:00
|
|
|
return -ENODEV;
|
2010-12-24 12:59:11 +07:00
|
|
|
}
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2013-12-31 01:30:44 +07:00
|
|
|
ret = dw_spi_add_host(&pdev->dev, dws);
|
2019-10-01 15:14:05 +07:00
|
|
|
if (ret) {
|
|
|
|
pci_free_irq_vectors(pdev);
|
2013-12-31 01:30:44 +07:00
|
|
|
return ret;
|
2019-10-01 15:14:05 +07:00
|
|
|
}
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
/* PCI hook and SPI hook use the same drv data */
|
2015-10-15 03:12:24 +07:00
|
|
|
pci_set_drvdata(pdev, dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2014-08-29 16:41:39 +07:00
|
|
|
dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
|
|
|
|
pdev->vendor, pdev->device);
|
|
|
|
|
2019-10-18 20:21:30 +07:00
|
|
|
pm_runtime_set_autosuspend_delay(&pdev->dev, 1000);
|
|
|
|
pm_runtime_use_autosuspend(&pdev->dev);
|
|
|
|
pm_runtime_put_autosuspend(&pdev->dev);
|
|
|
|
pm_runtime_allow(&pdev->dev);
|
|
|
|
|
2013-12-31 01:30:44 +07:00
|
|
|
return 0;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
2012-12-07 23:57:14 +07:00
|
|
|
static void spi_pci_remove(struct pci_dev *pdev)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2015-10-15 03:12:24 +07:00
|
|
|
struct dw_spi *dws = pci_get_drvdata(pdev);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2019-10-18 20:21:30 +07:00
|
|
|
pm_runtime_forbid(&pdev->dev);
|
|
|
|
pm_runtime_get_noresume(&pdev->dev);
|
|
|
|
|
2015-10-15 03:12:24 +07:00
|
|
|
dw_spi_remove_host(dws);
|
2019-10-01 15:14:05 +07:00
|
|
|
pci_free_irq_vectors(pdev);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
2014-08-29 16:41:41 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int spi_suspend(struct device *dev)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2019-07-24 19:23:31 +07:00
|
|
|
struct dw_spi *dws = dev_get_drvdata(dev);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-10-15 03:12:24 +07:00
|
|
|
return dw_spi_suspend_host(dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
2014-08-29 16:41:41 +07:00
|
|
|
static int spi_resume(struct device *dev)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2019-07-24 19:23:31 +07:00
|
|
|
struct dw_spi *dws = dev_get_drvdata(dev);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-10-15 03:12:24 +07:00
|
|
|
return dw_spi_resume_host(dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-08-29 16:41:41 +07:00
|
|
|
static SIMPLE_DEV_PM_OPS(dw_spi_pm_ops, spi_suspend, spi_resume);
|
|
|
|
|
2013-12-03 06:25:19 +07:00
|
|
|
static const struct pci_device_id pci_ids[] = {
|
2010-12-24 12:59:11 +07:00
|
|
|
/* Intel MID platform SPI controller 0 */
|
2015-01-07 22:15:00 +07:00
|
|
|
/*
|
|
|
|
* The access to the device 8086:0801 is disabled by HW, since it's
|
|
|
|
* exclusively used by SCU to communicate with MSIC.
|
|
|
|
*/
|
|
|
|
/* Intel MID platform SPI controller 1 */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x0800), (kernel_ulong_t)&spi_pci_mid_desc_1},
|
|
|
|
/* Intel MID platform SPI controller 2 */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x0812), (kernel_ulong_t)&spi_pci_mid_desc_2},
|
2019-08-12 17:13:44 +07:00
|
|
|
/* Intel Elkhart Lake PSE SPI controllers */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4b84), (kernel_ulong_t)&spi_pci_ehl_desc},
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4b85), (kernel_ulong_t)&spi_pci_ehl_desc},
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4b86), (kernel_ulong_t)&spi_pci_ehl_desc},
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4b87), (kernel_ulong_t)&spi_pci_ehl_desc},
|
2009-12-15 05:20:22 +07:00
|
|
|
{},
|
|
|
|
};
|
2019-08-29 19:50:00 +07:00
|
|
|
MODULE_DEVICE_TABLE(pci, pci_ids);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
static struct pci_driver dw_spi_driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.id_table = pci_ids,
|
|
|
|
.probe = spi_pci_probe,
|
2012-12-07 23:57:14 +07:00
|
|
|
.remove = spi_pci_remove,
|
2014-08-29 16:41:41 +07:00
|
|
|
.driver = {
|
|
|
|
.pm = &dw_spi_pm_ops,
|
|
|
|
},
|
2009-12-15 05:20:22 +07:00
|
|
|
};
|
|
|
|
|
2012-04-04 21:29:32 +07:00
|
|
|
module_pci_driver(dw_spi_driver);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
|
|
|
|
MODULE_LICENSE("GPL v2");
|