2009-12-15 06:20:22 +08:00
|
|
|
/*
|
2011-06-06 15:16:30 +08:00
|
|
|
* PCI interface driver for DW SPI Core
|
2009-12-15 06:20:22 +08:00
|
|
|
*
|
2014-08-29 17:41:43 +08:00
|
|
|
* Copyright (c) 2009, 2014 Intel Corporation.
|
2009-12-15 06:20:22 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/pci.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-12-15 06:20:22 +08:00
|
|
|
#include <linux/spi/spi.h>
|
2011-07-04 03:44:29 +08:00
|
|
|
#include <linux/module.h>
|
2009-12-15 06:20:22 +08:00
|
|
|
|
2011-06-06 15:16:30 +08:00
|
|
|
#include "spi-dw.h"
|
2011-03-01 03:47:12 +08:00
|
|
|
|
2009-12-15 06:20:22 +08:00
|
|
|
#define DRIVER_NAME "dw_spi_pci"
|
|
|
|
|
|
|
|
struct dw_spi_pci {
|
2010-12-24 13:59:11 +08:00
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct dw_spi dws;
|
2009-12-15 06:20:22 +08:00
|
|
|
};
|
|
|
|
|
2014-08-29 17:41:42 +08:00
|
|
|
struct spi_pci_desc {
|
|
|
|
int (*setup)(struct dw_spi *);
|
2015-01-07 23:15:00 +08:00
|
|
|
u16 num_cs;
|
|
|
|
u16 bus_num;
|
2014-08-29 17:41:42 +08:00
|
|
|
};
|
|
|
|
|
2015-01-07 23:15:00 +08:00
|
|
|
static struct spi_pci_desc spi_pci_mid_desc_1 = {
|
2014-08-29 17:41:42 +08:00
|
|
|
.setup = dw_spi_mid_init,
|
2015-01-07 23:15:00 +08:00
|
|
|
.num_cs = 32,
|
|
|
|
.bus_num = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_pci_desc spi_pci_mid_desc_2 = {
|
|
|
|
.setup = dw_spi_mid_init,
|
|
|
|
.num_cs = 4,
|
|
|
|
.bus_num = 1,
|
2014-08-29 17:41:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
2009-12-15 06:20:22 +08:00
|
|
|
{
|
|
|
|
struct dw_spi_pci *dwpci;
|
|
|
|
struct dw_spi *dws;
|
2014-08-29 17:41:42 +08:00
|
|
|
struct spi_pci_desc *desc = (struct spi_pci_desc *)ent->driver_data;
|
2009-12-15 06:20:22 +08:00
|
|
|
int pci_bar = 0;
|
|
|
|
int ret;
|
|
|
|
|
2013-12-31 02:30:44 +08:00
|
|
|
ret = pcim_enable_device(pdev);
|
2009-12-15 06:20:22 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-01-06 15:21:33 +08:00
|
|
|
dwpci = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_pci),
|
|
|
|
GFP_KERNEL);
|
2013-12-31 02:30:44 +08:00
|
|
|
if (!dwpci)
|
|
|
|
return -ENOMEM;
|
2009-12-15 06:20:22 +08:00
|
|
|
|
|
|
|
dwpci->pdev = pdev;
|
|
|
|
dws = &dwpci->dws;
|
|
|
|
|
|
|
|
/* Get basic io resource and map it */
|
|
|
|
dws->paddr = pci_resource_start(pdev, pci_bar);
|
|
|
|
|
2014-08-29 17:41:40 +08:00
|
|
|
ret = pcim_iomap_regions(pdev, 1 << pci_bar, pci_name(pdev));
|
2009-12-15 06:20:22 +08:00
|
|
|
if (ret)
|
2013-12-31 02:30:44 +08:00
|
|
|
return ret;
|
2009-12-15 06:20:22 +08:00
|
|
|
|
2014-08-27 21:21:12 +08:00
|
|
|
dws->regs = pcim_iomap_table(pdev)[pci_bar];
|
|
|
|
|
2009-12-15 06:20:22 +08:00
|
|
|
dws->irq = pdev->irq;
|
2010-12-24 13:59:11 +08:00
|
|
|
|
|
|
|
/*
|
2014-08-29 17:41:42 +08:00
|
|
|
* Specific handling for paltforms, like dma setup,
|
2010-12-24 13:59:11 +08:00
|
|
|
* clock rate, FIFO depth.
|
|
|
|
*/
|
2015-01-07 23:15:00 +08:00
|
|
|
if (desc) {
|
|
|
|
if (desc->setup) {
|
|
|
|
ret = desc->setup(dws);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
dws->num_cs = desc->num_cs;
|
|
|
|
dws->bus_num = desc->bus_num;
|
|
|
|
} else {
|
|
|
|
return -ENODEV;
|
2010-12-24 13:59:11 +08:00
|
|
|
}
|
2009-12-15 06:20:22 +08:00
|
|
|
|
2013-12-31 02:30:44 +08:00
|
|
|
ret = dw_spi_add_host(&pdev->dev, dws);
|
2009-12-15 06:20:22 +08:00
|
|
|
if (ret)
|
2013-12-31 02:30:44 +08:00
|
|
|
return ret;
|
2009-12-15 06:20:22 +08:00
|
|
|
|
|
|
|
/* PCI hook and SPI hook use the same drv data */
|
|
|
|
pci_set_drvdata(pdev, dwpci);
|
|
|
|
|
2014-08-29 17:41:39 +08:00
|
|
|
dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
|
|
|
|
pdev->vendor, pdev->device);
|
|
|
|
|
2013-12-31 02:30:44 +08:00
|
|
|
return 0;
|
2009-12-15 06:20:22 +08:00
|
|
|
}
|
|
|
|
|
2012-12-08 00:57:14 +08:00
|
|
|
static void spi_pci_remove(struct pci_dev *pdev)
|
2009-12-15 06:20:22 +08:00
|
|
|
{
|
|
|
|
struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
|
|
|
|
|
2010-01-21 04:49:45 +08:00
|
|
|
dw_spi_remove_host(&dwpci->dws);
|
2009-12-15 06:20:22 +08:00
|
|
|
}
|
|
|
|
|
2014-08-29 17:41:41 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int spi_suspend(struct device *dev)
|
2009-12-15 06:20:22 +08:00
|
|
|
{
|
2014-08-29 17:41:41 +08:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
2009-12-15 06:20:22 +08:00
|
|
|
struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
|
|
|
|
|
2014-08-29 17:41:41 +08:00
|
|
|
return dw_spi_suspend_host(&dwpci->dws);
|
2009-12-15 06:20:22 +08:00
|
|
|
}
|
|
|
|
|
2014-08-29 17:41:41 +08:00
|
|
|
static int spi_resume(struct device *dev)
|
2009-12-15 06:20:22 +08:00
|
|
|
{
|
2014-08-29 17:41:41 +08:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
2009-12-15 06:20:22 +08:00
|
|
|
struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
|
|
|
|
|
|
|
|
return dw_spi_resume_host(&dwpci->dws);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-08-29 17:41:41 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(dw_spi_pm_ops, spi_suspend, spi_resume);
|
|
|
|
|
2013-12-03 07:25:19 +08:00
|
|
|
static const struct pci_device_id pci_ids[] = {
|
2010-12-24 13:59:11 +08:00
|
|
|
/* Intel MID platform SPI controller 0 */
|
2015-01-07 23:15:00 +08: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},
|
2009-12-15 06:20:22 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_driver dw_spi_driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.id_table = pci_ids,
|
|
|
|
.probe = spi_pci_probe,
|
2012-12-08 00:57:14 +08:00
|
|
|
.remove = spi_pci_remove,
|
2014-08-29 17:41:41 +08:00
|
|
|
.driver = {
|
|
|
|
.pm = &dw_spi_pm_ops,
|
|
|
|
},
|
2009-12-15 06:20:22 +08:00
|
|
|
};
|
|
|
|
|
2012-04-04 22:29:32 +08:00
|
|
|
module_pci_driver(dw_spi_driver);
|
2009-12-15 06:20:22 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
|
|
|
|
MODULE_LICENSE("GPL v2");
|