2010-01-21 15:46:42 +01:00
|
|
|
/*
|
2011-06-06 09:16:30 +02:00
|
|
|
* Memory-mapped interface driver for DW SPI Core
|
2010-01-21 15:46:42 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2010, Octasic semiconductor.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
2011-01-11 13:43:52 +01:00
|
|
|
#include <linux/err.h>
|
2010-01-21 15:46:42 +01:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2010-01-21 15:46:42 +01:00
|
|
|
#include <linux/spi/spi.h>
|
2011-02-28 20:47:12 +01:00
|
|
|
#include <linux/scatterlist.h>
|
2011-07-03 21:44:29 +02:00
|
|
|
#include <linux/module.h>
|
2014-06-13 15:36:18 +02:00
|
|
|
#include <linux/of.h>
|
2014-01-31 11:07:47 +01:00
|
|
|
#include <linux/of_gpio.h>
|
2014-06-13 15:36:18 +02:00
|
|
|
#include <linux/of_platform.h>
|
2015-10-14 22:12:25 +02:00
|
|
|
#include <linux/property.h>
|
2011-02-28 20:47:12 +01:00
|
|
|
|
2011-06-06 09:16:30 +02:00
|
|
|
#include "spi-dw.h"
|
2010-01-21 15:46:42 +01:00
|
|
|
|
|
|
|
#define DRIVER_NAME "dw_spi_mmio"
|
|
|
|
|
|
|
|
struct dw_spi_mmio {
|
2010-01-21 17:55:42 +01:00
|
|
|
struct dw_spi dws;
|
|
|
|
struct clk *clk;
|
2010-01-21 15:46:42 +01:00
|
|
|
};
|
|
|
|
|
2012-12-07 17:57:14 +01:00
|
|
|
static int dw_spi_mmio_probe(struct platform_device *pdev)
|
2010-01-21 15:46:42 +01:00
|
|
|
{
|
|
|
|
struct dw_spi_mmio *dwsmmio;
|
|
|
|
struct dw_spi *dws;
|
2013-12-30 19:30:44 +01:00
|
|
|
struct resource *mem;
|
2010-01-21 15:46:42 +01:00
|
|
|
int ret;
|
2014-06-13 15:36:18 +02:00
|
|
|
int num_cs;
|
2010-01-21 15:46:42 +01:00
|
|
|
|
2013-12-30 19:30:44 +01:00
|
|
|
dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!dwsmmio)
|
|
|
|
return -ENOMEM;
|
2010-01-21 15:46:42 +01:00
|
|
|
|
|
|
|
dws = &dwsmmio->dws;
|
|
|
|
|
|
|
|
/* Get basic io resource and map it */
|
|
|
|
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-12-30 19:30:44 +01:00
|
|
|
dws->regs = devm_ioremap_resource(&pdev->dev, mem);
|
|
|
|
if (IS_ERR(dws->regs)) {
|
|
|
|
dev_err(&pdev->dev, "SPI region map failed\n");
|
|
|
|
return PTR_ERR(dws->regs);
|
2010-01-21 15:46:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dws->irq = platform_get_irq(pdev, 0);
|
|
|
|
if (dws->irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "no irq resource?\n");
|
2013-12-30 19:30:44 +01:00
|
|
|
return dws->irq; /* -ENXIO */
|
2010-01-21 15:46:42 +01:00
|
|
|
}
|
|
|
|
|
2013-12-30 19:30:44 +01:00
|
|
|
dwsmmio->clk = devm_clk_get(&pdev->dev, NULL);
|
|
|
|
if (IS_ERR(dwsmmio->clk))
|
|
|
|
return PTR_ERR(dwsmmio->clk);
|
2013-12-30 19:30:45 +01:00
|
|
|
ret = clk_prepare_enable(dwsmmio->clk);
|
2013-12-30 19:30:44 +01:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-01-21 15:46:42 +01:00
|
|
|
|
2014-01-26 09:14:32 +01:00
|
|
|
dws->bus_num = pdev->id;
|
2014-06-13 15:36:18 +02:00
|
|
|
|
2010-01-21 15:46:42 +01:00
|
|
|
dws->max_freq = clk_get_rate(dwsmmio->clk);
|
|
|
|
|
2015-10-14 22:12:25 +02:00
|
|
|
device_property_read_u32(&pdev->dev, "reg-io-width", &dws->reg_io_width);
|
2015-08-18 22:21:53 +02:00
|
|
|
|
2014-06-13 15:36:18 +02:00
|
|
|
num_cs = 4;
|
|
|
|
|
2015-10-14 22:12:25 +02:00
|
|
|
device_property_read_u32(&pdev->dev, "num-cs", &num_cs);
|
2014-06-13 15:36:18 +02:00
|
|
|
|
|
|
|
dws->num_cs = num_cs;
|
|
|
|
|
2014-01-31 11:07:47 +01:00
|
|
|
if (pdev->dev.of_node) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < dws->num_cs; i++) {
|
|
|
|
int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
|
|
|
|
"cs-gpios", i);
|
|
|
|
|
|
|
|
if (cs_gpio == -EPROBE_DEFER) {
|
|
|
|
ret = cs_gpio;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gpio_is_valid(cs_gpio)) {
|
|
|
|
ret = devm_gpio_request(&pdev->dev, cs_gpio,
|
|
|
|
dev_name(&pdev->dev));
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-30 19:30:44 +01:00
|
|
|
ret = dw_spi_add_host(&pdev->dev, dws);
|
2010-01-21 15:46:42 +01:00
|
|
|
if (ret)
|
2013-12-30 19:30:44 +01:00
|
|
|
goto out;
|
2010-01-21 15:46:42 +01:00
|
|
|
|
|
|
|
platform_set_drvdata(pdev, dwsmmio);
|
|
|
|
return 0;
|
|
|
|
|
2013-12-30 19:30:44 +01:00
|
|
|
out:
|
2013-12-30 19:30:45 +01:00
|
|
|
clk_disable_unprepare(dwsmmio->clk);
|
2010-01-21 15:46:42 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-07 17:57:14 +01:00
|
|
|
static int dw_spi_mmio_remove(struct platform_device *pdev)
|
2010-01-21 15:46:42 +01:00
|
|
|
{
|
|
|
|
struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
dw_spi_remove_host(&dwsmmio->dws);
|
2017-04-18 20:09:06 +02:00
|
|
|
clk_disable_unprepare(dwsmmio->clk);
|
2010-01-21 15:46:42 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-13 15:36:18 +02:00
|
|
|
static const struct of_device_id dw_spi_mmio_of_match[] = {
|
|
|
|
{ .compatible = "snps,dw-apb-ssi", },
|
|
|
|
{ /* end of table */}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, dw_spi_mmio_of_match);
|
|
|
|
|
2010-01-21 15:46:42 +01:00
|
|
|
static struct platform_driver dw_spi_mmio_driver = {
|
2011-10-05 19:29:49 +02:00
|
|
|
.probe = dw_spi_mmio_probe,
|
2012-12-07 17:57:14 +01:00
|
|
|
.remove = dw_spi_mmio_remove,
|
2010-01-21 15:46:42 +01:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
2014-06-13 15:36:18 +02:00
|
|
|
.of_match_table = dw_spi_mmio_of_match,
|
2010-01-21 15:46:42 +01:00
|
|
|
},
|
|
|
|
};
|
2011-10-05 19:29:49 +02:00
|
|
|
module_platform_driver(dw_spi_mmio_driver);
|
2010-01-21 15:46:42 +01:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>");
|
|
|
|
MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
|
|
|
|
MODULE_LICENSE("GPL v2");
|