2009-12-14 22:20:22 +00:00
|
|
|
/*
|
2011-06-06 07:16:30 +00:00
|
|
|
* PCI interface driver for DW SPI Core
|
2009-12-14 22:20:22 +00:00
|
|
|
*
|
2014-08-29 09:41:43 +00:00
|
|
|
* Copyright (c) 2009, 2014 Intel Corporation.
|
2009-12-14 22:20:22 +00: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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-12-14 22:20:22 +00:00
|
|
|
#include <linux/spi/spi.h>
|
2011-07-03 19:44:29 +00:00
|
|
|
#include <linux/module.h>
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2011-06-06 07:16:30 +00:00
|
|
|
#include "spi-dw.h"
|
2011-02-28 19:47:12 +00:00
|
|
|
|
2009-12-14 22:20:22 +00:00
|
|
|
#define DRIVER_NAME "dw_spi_pci"
|
|
|
|
|
|
|
|
struct dw_spi_pci {
|
2010-12-24 05:59:11 +00:00
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct dw_spi dws;
|
2009-12-14 22:20:22 +00:00
|
|
|
};
|
|
|
|
|
2014-08-29 09:41:42 +00:00
|
|
|
struct spi_pci_desc {
|
|
|
|
int (*setup)(struct dw_spi *);
|
2015-01-07 15:15:00 +00:00
|
|
|
u16 num_cs;
|
|
|
|
u16 bus_num;
|
2014-08-29 09:41:42 +00:00
|
|
|
};
|
|
|
|
|
2015-01-07 15:15:00 +00:00
|
|
|
static struct spi_pci_desc spi_pci_mid_desc_1 = {
|
2014-08-29 09:41:42 +00:00
|
|
|
.setup = dw_spi_mid_init,
|
2015-02-23 15:55:54 +00:00
|
|
|
.num_cs = 5,
|
2015-01-07 15:15:00 +00:00
|
|
|
.bus_num = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_pci_desc spi_pci_mid_desc_2 = {
|
|
|
|
.setup = dw_spi_mid_init,
|
2015-02-23 15:55:54 +00:00
|
|
|
.num_cs = 2,
|
2015-01-07 15:15:00 +00:00
|
|
|
.bus_num = 1,
|
2014-08-29 09:41:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
|
|
|
struct dw_spi_pci *dwpci;
|
|
|
|
struct dw_spi *dws;
|
2014-08-29 09:41:42 +00:00
|
|
|
struct spi_pci_desc *desc = (struct spi_pci_desc *)ent->driver_data;
|
2009-12-14 22:20:22 +00:00
|
|
|
int pci_bar = 0;
|
|
|
|
int ret;
|
|
|
|
|
2013-12-30 18:30:44 +00:00
|
|
|
ret = pcim_enable_device(pdev);
|
2009-12-14 22:20:22 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-01-06 07:21:33 +00:00
|
|
|
dwpci = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_pci),
|
|
|
|
GFP_KERNEL);
|
2013-12-30 18:30:44 +00:00
|
|
|
if (!dwpci)
|
|
|
|
return -ENOMEM;
|
2009-12-14 22:20:22 +00: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 09:41:40 +00:00
|
|
|
ret = pcim_iomap_regions(pdev, 1 << pci_bar, pci_name(pdev));
|
2009-12-14 22:20:22 +00:00
|
|
|
if (ret)
|
2013-12-30 18:30:44 +00:00
|
|
|
return ret;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2014-08-27 13:21:12 +00:00
|
|
|
dws->regs = pcim_iomap_table(pdev)[pci_bar];
|
|
|
|
|
2009-12-14 22:20:22 +00:00
|
|
|
dws->irq = pdev->irq;
|
2010-12-24 05:59:11 +00:00
|
|
|
|
|
|
|
/*
|
2014-08-29 09:41:42 +00:00
|
|
|
* Specific handling for paltforms, like dma setup,
|
2010-12-24 05:59:11 +00:00
|
|
|
* clock rate, FIFO depth.
|
|
|
|
*/
|
2015-01-07 15:15:00 +00:00
|
|
|
if (desc) {
|
2015-01-22 15:59:34 +00:00
|
|
|
dws->num_cs = desc->num_cs;
|
|
|
|
dws->bus_num = desc->bus_num;
|
|
|
|
|
2015-01-07 15:15:00 +00:00
|
|
|
if (desc->setup) {
|
|
|
|
ret = desc->setup(dws);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return -ENODEV;
|
2010-12-24 05:59:11 +00:00
|
|
|
}
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2013-12-30 18:30:44 +00:00
|
|
|
ret = dw_spi_add_host(&pdev->dev, dws);
|
2009-12-14 22:20:22 +00:00
|
|
|
if (ret)
|
2013-12-30 18:30:44 +00:00
|
|
|
return ret;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
|
|
|
/* PCI hook and SPI hook use the same drv data */
|
|
|
|
pci_set_drvdata(pdev, dwpci);
|
|
|
|
|
2014-08-29 09:41:39 +00:00
|
|
|
dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
|
|
|
|
pdev->vendor, pdev->device);
|
|
|
|
|
2013-12-30 18:30:44 +00:00
|
|
|
return 0;
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-07 16:57:14 +00:00
|
|
|
static void spi_pci_remove(struct pci_dev *pdev)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
|
|
|
struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
|
|
|
|
|
2010-01-20 20:49:45 +00:00
|
|
|
dw_spi_remove_host(&dwpci->dws);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 09:41:41 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int spi_suspend(struct device *dev)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2014-08-29 09:41:41 +00:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
2009-12-14 22:20:22 +00:00
|
|
|
struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
|
|
|
|
|
2014-08-29 09:41:41 +00:00
|
|
|
return dw_spi_suspend_host(&dwpci->dws);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 09:41:41 +00:00
|
|
|
static int spi_resume(struct device *dev)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2014-08-29 09:41:41 +00:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
2009-12-14 22:20:22 +00:00
|
|
|
struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
|
|
|
|
|
|
|
|
return dw_spi_resume_host(&dwpci->dws);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-08-29 09:41:41 +00:00
|
|
|
static SIMPLE_DEV_PM_OPS(dw_spi_pm_ops, spi_suspend, spi_resume);
|
|
|
|
|
2013-12-02 23:25:19 +00:00
|
|
|
static const struct pci_device_id pci_ids[] = {
|
2010-12-24 05:59:11 +00:00
|
|
|
/* Intel MID platform SPI controller 0 */
|
2015-01-07 15:15:00 +00: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-14 22:20:22 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_driver dw_spi_driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.id_table = pci_ids,
|
|
|
|
.probe = spi_pci_probe,
|
2012-12-07 16:57:14 +00:00
|
|
|
.remove = spi_pci_remove,
|
2014-08-29 09:41:41 +00:00
|
|
|
.driver = {
|
|
|
|
.pm = &dw_spi_pm_ops,
|
|
|
|
},
|
2009-12-14 22:20:22 +00:00
|
|
|
};
|
|
|
|
|
2012-04-04 14:29:32 +00:00
|
|
|
module_pci_driver(dw_spi_driver);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
|
|
|
|
MODULE_LICENSE("GPL v2");
|