2009-12-15 05:20:22 +07:00
|
|
|
/*
|
2011-06-06 14:16:30 +07:00
|
|
|
* Designware SPI core controller driver (refer pxa2xx_spi.c)
|
2009-12-15 05:20:22 +07:00
|
|
|
*
|
|
|
|
* Copyright (c) 2009, Intel Corporation.
|
|
|
|
*
|
|
|
|
* 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/dma-mapping.h>
|
|
|
|
#include <linux/interrupt.h>
|
2011-07-04 02:44:29 +07:00
|
|
|
#include <linux/module.h>
|
2009-12-15 05:20:22 +07:00
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/delay.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>
|
2014-01-31 17:07:47 +07:00
|
|
|
#include <linux/gpio.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
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Slave spi_dev related */
|
|
|
|
struct chip_data {
|
|
|
|
u8 tmode; /* TR/TO/RO/EEPROM */
|
|
|
|
u8 type; /* SPI/SSP/MicroWire */
|
|
|
|
|
|
|
|
u8 poll_mode; /* 1 means use poll mode */
|
|
|
|
|
|
|
|
u16 clk_div; /* baud rate divider */
|
|
|
|
u32 speed_hz; /* baud rate */
|
|
|
|
void (*cs_control)(u32 command);
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
#define SPI_REGS_BUFSIZE 1024
|
2014-09-12 19:11:56 +07:00
|
|
|
static ssize_t dw_spi_show_regs(struct file *file, char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2014-09-12 19:11:56 +07:00
|
|
|
struct dw_spi *dws = file->private_data;
|
2009-12-15 05:20:22 +07:00
|
|
|
char *buf;
|
|
|
|
u32 len = 0;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
buf = kzalloc(SPI_REGS_BUFSIZE, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2014-09-12 19:11:56 +07:00
|
|
|
"%s registers:\n", dev_name(&dws->master->dev));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
|
|
|
"=================================\n");
|
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"CTRL0: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL0));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"CTRL1: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL1));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"SSIENR: \t0x%08x\n", dw_readl(dws, DW_SPI_SSIENR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"SER: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SER));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"BAUDR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_BAUDR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"TXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_TXFLTR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"RXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_RXFLTR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"TXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_TXFLR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"RXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_RXFLR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"SR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"IMR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_IMR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"ISR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_ISR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"DMACR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_DMACR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"DMATDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMATDLR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
2011-09-21 01:06:17 +07:00
|
|
|
"DMARDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMARDLR));
|
2009-12-15 05:20:22 +07:00
|
|
|
len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
|
|
|
|
"=================================\n");
|
|
|
|
|
2014-09-12 19:11:56 +07:00
|
|
|
ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
|
2009-12-15 05:20:22 +07:00
|
|
|
kfree(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-09-12 19:11:56 +07:00
|
|
|
static const struct file_operations dw_spi_regs_ops = {
|
2009-12-15 05:20:22 +07:00
|
|
|
.owner = THIS_MODULE,
|
2012-04-06 04:25:11 +07:00
|
|
|
.open = simple_open,
|
2014-09-12 19:11:56 +07:00
|
|
|
.read = dw_spi_show_regs,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 23:52:59 +07:00
|
|
|
.llseek = default_llseek,
|
2009-12-15 05:20:22 +07:00
|
|
|
};
|
|
|
|
|
2014-09-12 19:11:56 +07:00
|
|
|
static int dw_spi_debugfs_init(struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2017-01-06 16:35:13 +07:00
|
|
|
char name[32];
|
2016-12-22 16:18:12 +07:00
|
|
|
|
2017-01-06 16:35:13 +07:00
|
|
|
snprintf(name, 32, "dw_spi%d", dws->master->bus_num);
|
2016-12-22 16:18:12 +07:00
|
|
|
dws->debugfs = debugfs_create_dir(name, NULL);
|
2009-12-15 05:20:22 +07:00
|
|
|
if (!dws->debugfs)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
debugfs_create_file("registers", S_IFREG | S_IRUGO,
|
2014-09-12 19:11:56 +07:00
|
|
|
dws->debugfs, (void *)dws, &dw_spi_regs_ops);
|
2009-12-15 05:20:22 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-12 19:11:56 +07:00
|
|
|
static void dw_spi_debugfs_remove(struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2014-09-02 09:49:24 +07:00
|
|
|
debugfs_remove_recursive(dws->debugfs);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2014-09-12 19:11:56 +07:00
|
|
|
static inline int dw_spi_debugfs_init(struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2010-01-21 18:40:49 +07:00
|
|
|
return 0;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
2014-09-12 19:11:56 +07:00
|
|
|
static inline void dw_spi_debugfs_remove(struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DEBUG_FS */
|
|
|
|
|
2015-03-02 19:58:57 +07:00
|
|
|
static void dw_spi_set_cs(struct spi_device *spi, bool enable)
|
|
|
|
{
|
2018-02-01 22:17:29 +07:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
|
2015-03-02 19:58:57 +07:00
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
|
|
|
|
|
|
|
/* Chip select logic is inverted from spi_set_cs() */
|
2015-03-26 01:26:26 +07:00
|
|
|
if (chip && chip->cs_control)
|
2015-03-02 19:58:57 +07:00
|
|
|
chip->cs_control(!enable);
|
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
dw_writel(dws, DW_SPI_SER, BIT(spi->chip_select));
|
|
|
|
}
|
|
|
|
|
2011-03-30 22:09:54 +07:00
|
|
|
/* Return the max entries we can fill into tx fifo */
|
|
|
|
static inline u32 tx_max(struct dw_spi *dws)
|
|
|
|
{
|
|
|
|
u32 tx_left, tx_room, rxtx_gap;
|
|
|
|
|
|
|
|
tx_left = (dws->tx_end - dws->tx) / dws->n_bytes;
|
2015-03-13 02:19:31 +07:00
|
|
|
tx_room = dws->fifo_len - dw_readl(dws, DW_SPI_TXFLR);
|
2011-03-30 22:09:54 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Another concern is about the tx/rx mismatch, we
|
|
|
|
* though to use (dws->fifo_len - rxflr - txflr) as
|
|
|
|
* one maximum value for tx, but it doesn't cover the
|
|
|
|
* data which is out of tx/rx fifo and inside the
|
|
|
|
* shift registers. So a control from sw point of
|
|
|
|
* view is taken.
|
|
|
|
*/
|
|
|
|
rxtx_gap = ((dws->rx_end - dws->rx) - (dws->tx_end - dws->tx))
|
|
|
|
/ dws->n_bytes;
|
|
|
|
|
|
|
|
return min3(tx_left, tx_room, (u32) (dws->fifo_len - rxtx_gap));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the max entries we should read out of rx fifo */
|
|
|
|
static inline u32 rx_max(struct dw_spi *dws)
|
|
|
|
{
|
|
|
|
u32 rx_left = (dws->rx_end - dws->rx) / dws->n_bytes;
|
|
|
|
|
2015-03-13 02:19:31 +07:00
|
|
|
return min_t(u32, rx_left, dw_readl(dws, DW_SPI_RXFLR));
|
2011-03-30 22:09:54 +07:00
|
|
|
}
|
|
|
|
|
2011-03-30 22:09:55 +07:00
|
|
|
static void dw_writer(struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2011-03-30 22:09:54 +07:00
|
|
|
u32 max = tx_max(dws);
|
2011-03-30 22:09:52 +07:00
|
|
|
u16 txw = 0;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2011-03-30 22:09:54 +07:00
|
|
|
while (max--) {
|
|
|
|
/* Set the tx word if the transfer's original "tx" is not null */
|
|
|
|
if (dws->tx_end - dws->len) {
|
|
|
|
if (dws->n_bytes == 1)
|
|
|
|
txw = *(u8 *)(dws->tx);
|
|
|
|
else
|
|
|
|
txw = *(u16 *)(dws->tx);
|
|
|
|
}
|
2015-08-19 03:21:53 +07:00
|
|
|
dw_write_io_reg(dws, DW_SPI_DR, txw);
|
2011-03-30 22:09:54 +07:00
|
|
|
dws->tx += dws->n_bytes;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-30 22:09:55 +07:00
|
|
|
static void dw_reader(struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2011-03-30 22:09:54 +07:00
|
|
|
u32 max = rx_max(dws);
|
2011-03-30 22:09:52 +07:00
|
|
|
u16 rxw;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2011-03-30 22:09:54 +07:00
|
|
|
while (max--) {
|
2015-08-19 03:21:53 +07:00
|
|
|
rxw = dw_read_io_reg(dws, DW_SPI_DR);
|
2011-03-30 22:09:52 +07:00
|
|
|
/* Care rx only if the transfer's original "rx" is not null */
|
|
|
|
if (dws->rx_end - dws->len) {
|
|
|
|
if (dws->n_bytes == 1)
|
|
|
|
*(u8 *)(dws->rx) = rxw;
|
|
|
|
else
|
|
|
|
*(u16 *)(dws->rx) = rxw;
|
|
|
|
}
|
|
|
|
dws->rx += dws->n_bytes;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void int_error_stop(struct dw_spi *dws, const char *msg)
|
|
|
|
{
|
2015-03-02 19:58:55 +07:00
|
|
|
spi_reset_chip(dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
dev_err(&dws->master->dev, "%s\n", msg);
|
2015-03-02 19:58:57 +07:00
|
|
|
dws->master->cur_msg->status = -EIO;
|
|
|
|
spi_finalize_current_transfer(dws->master);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t interrupt_transfer(struct dw_spi *dws)
|
|
|
|
{
|
2015-03-13 02:19:31 +07:00
|
|
|
u16 irq_status = dw_readl(dws, DW_SPI_ISR);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
/* Error handling */
|
|
|
|
if (irq_status & (SPI_INT_TXOI | SPI_INT_RXOI | SPI_INT_RXUI)) {
|
2015-03-13 02:19:31 +07:00
|
|
|
dw_readl(dws, DW_SPI_ICR);
|
2011-03-30 22:09:55 +07:00
|
|
|
int_error_stop(dws, "interrupt_transfer: fifo overrun/underrun");
|
2009-12-15 05:20:22 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2011-03-30 22:09:55 +07:00
|
|
|
dw_reader(dws);
|
|
|
|
if (dws->rx_end == dws->rx) {
|
|
|
|
spi_mask_intr(dws, SPI_INT_TXEI);
|
2015-03-02 19:58:57 +07:00
|
|
|
spi_finalize_current_transfer(dws->master);
|
2011-03-30 22:09:55 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2010-01-21 03:49:45 +07:00
|
|
|
if (irq_status & SPI_INT_TXEI) {
|
|
|
|
spi_mask_intr(dws, SPI_INT_TXEI);
|
2011-03-30 22:09:55 +07:00
|
|
|
dw_writer(dws);
|
|
|
|
/* Enable TX irq always, it will be disabled when RX finished */
|
|
|
|
spi_umask_intr(dws, SPI_INT_TXEI);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t dw_spi_irq(int irq, void *dev_id)
|
|
|
|
{
|
2018-02-01 22:17:29 +07:00
|
|
|
struct spi_controller *master = dev_id;
|
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(master);
|
2015-03-13 02:19:31 +07:00
|
|
|
u16 irq_status = dw_readl(dws, DW_SPI_ISR) & 0x3f;
|
2010-09-07 14:27:27 +07:00
|
|
|
|
|
|
|
if (!irq_status)
|
|
|
|
return IRQ_NONE;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-03-02 19:58:57 +07:00
|
|
|
if (!master->cur_msg) {
|
2009-12-15 05:20:22 +07:00
|
|
|
spi_mask_intr(dws, SPI_INT_TXEI);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dws->transfer_handler(dws);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called inside pump_transfers() */
|
2015-03-02 19:58:57 +07:00
|
|
|
static int poll_transfer(struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2011-03-30 22:09:54 +07:00
|
|
|
do {
|
|
|
|
dw_writer(dws);
|
2011-03-30 22:09:52 +07:00
|
|
|
dw_reader(dws);
|
2011-03-30 22:09:54 +07:00
|
|
|
cpu_relax();
|
|
|
|
} while (dws->rx_end > dws->rx);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-03-02 19:58:57 +07:00
|
|
|
return 0;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
2018-02-01 22:17:29 +07:00
|
|
|
static int dw_spi_transfer_one(struct spi_controller *master,
|
2015-03-02 19:58:57 +07:00
|
|
|
struct spi_device *spi, struct spi_transfer *transfer)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2018-02-01 22:17:29 +07:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(master);
|
2015-03-02 19:58:57 +07:00
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
2009-12-15 05:20:22 +07:00
|
|
|
u8 imask = 0;
|
2015-02-24 18:32:11 +07:00
|
|
|
u16 txlevel = 0;
|
2015-10-15 03:12:18 +07:00
|
|
|
u32 cr0;
|
2015-03-09 21:48:46 +07:00
|
|
|
int ret;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-03-09 21:48:49 +07:00
|
|
|
dws->dma_mapped = 0;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
dws->tx = (void *)transfer->tx_buf;
|
|
|
|
dws->tx_end = dws->tx + transfer->len;
|
|
|
|
dws->rx = transfer->rx_buf;
|
|
|
|
dws->rx_end = dws->rx + transfer->len;
|
2015-03-02 19:58:57 +07:00
|
|
|
dws->len = transfer->len;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-03-02 19:58:56 +07:00
|
|
|
spi_enable_chip(dws, 0);
|
|
|
|
|
2009-12-15 05:20:22 +07:00
|
|
|
/* Handle per transfer options for bpw and speed */
|
2016-09-04 07:04:49 +07:00
|
|
|
if (transfer->speed_hz != dws->current_freq) {
|
|
|
|
if (transfer->speed_hz != chip->speed_hz) {
|
|
|
|
/* clk_div doesn't support odd number */
|
2016-09-07 22:45:30 +07:00
|
|
|
chip->clk_div = (DIV_ROUND_UP(dws->max_freq, transfer->speed_hz) + 1) & 0xfffe;
|
2016-09-04 07:04:49 +07:00
|
|
|
chip->speed_hz = transfer->speed_hz;
|
|
|
|
}
|
|
|
|
dws->current_freq = transfer->speed_hz;
|
2015-09-15 20:26:23 +07:00
|
|
|
spi_set_clk(dws, chip->clk_div);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
2015-09-15 20:26:23 +07:00
|
|
|
if (transfer->bits_per_word == 8) {
|
|
|
|
dws->n_bytes = 1;
|
|
|
|
dws->dma_width = 1;
|
|
|
|
} else if (transfer->bits_per_word == 16) {
|
|
|
|
dws->n_bytes = 2;
|
|
|
|
dws->dma_width = 2;
|
2015-10-15 03:12:20 +07:00
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
2015-10-15 03:12:18 +07:00
|
|
|
/* Default SPI mode is SCPOL = 0, SCPH = 0 */
|
2015-09-15 20:26:23 +07:00
|
|
|
cr0 = (transfer->bits_per_word - 1)
|
|
|
|
| (chip->type << SPI_FRF_OFFSET)
|
|
|
|
| (spi->mode << SPI_MODE_OFFSET)
|
|
|
|
| (chip->tmode << SPI_TMOD_OFFSET);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2010-01-21 18:40:52 +07:00
|
|
|
/*
|
|
|
|
* Adjust transfer mode if necessary. Requires platform dependent
|
|
|
|
* chipselect mechanism.
|
|
|
|
*/
|
2015-03-02 19:58:57 +07:00
|
|
|
if (chip->cs_control) {
|
2010-01-21 18:40:52 +07:00
|
|
|
if (dws->rx && dws->tx)
|
2010-09-07 14:52:06 +07:00
|
|
|
chip->tmode = SPI_TMOD_TR;
|
2010-01-21 18:40:52 +07:00
|
|
|
else if (dws->rx)
|
2010-09-07 14:52:06 +07:00
|
|
|
chip->tmode = SPI_TMOD_RO;
|
2010-01-21 18:40:52 +07:00
|
|
|
else
|
2010-09-07 14:52:06 +07:00
|
|
|
chip->tmode = SPI_TMOD_TO;
|
2010-01-21 18:40:52 +07:00
|
|
|
|
2010-09-07 14:52:06 +07:00
|
|
|
cr0 &= ~SPI_TMOD_MASK;
|
2010-01-21 18:40:52 +07:00
|
|
|
cr0 |= (chip->tmode << SPI_TMOD_OFFSET);
|
|
|
|
}
|
|
|
|
|
2015-03-13 02:19:31 +07:00
|
|
|
dw_writel(dws, DW_SPI_CTRL0, cr0);
|
2015-03-02 19:58:56 +07:00
|
|
|
|
2009-12-15 05:20:22 +07:00
|
|
|
/* Check if current transfer is a DMA transaction */
|
2015-03-09 21:48:49 +07:00
|
|
|
if (master->can_dma && master->can_dma(master, spi, transfer))
|
|
|
|
dws->dma_mapped = master->cur_msg_mapped;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-03-02 19:58:56 +07:00
|
|
|
/* For poll mode just disable all interrupts */
|
|
|
|
spi_mask_intr(dws, 0xff);
|
|
|
|
|
2010-01-21 03:49:45 +07:00
|
|
|
/*
|
|
|
|
* Interrupt mode
|
|
|
|
* we only need set the TXEI IRQ, as TX/RX always happen syncronizely
|
|
|
|
*/
|
2015-03-09 21:48:46 +07:00
|
|
|
if (dws->dma_mapped) {
|
2015-03-09 21:48:49 +07:00
|
|
|
ret = dws->dma_ops->dma_setup(dws, transfer);
|
2015-03-09 21:48:46 +07:00
|
|
|
if (ret < 0) {
|
|
|
|
spi_enable_chip(dws, 1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else if (!chip->poll_mode) {
|
2015-02-24 18:32:11 +07:00
|
|
|
txlevel = min_t(u16, dws->fifo_len / 2, dws->len / dws->n_bytes);
|
2015-03-13 02:19:31 +07:00
|
|
|
dw_writel(dws, DW_SPI_TXFLTR, txlevel);
|
2010-01-21 03:49:45 +07:00
|
|
|
|
2015-03-02 19:58:56 +07:00
|
|
|
/* Set the interrupt mask */
|
2014-09-02 09:49:24 +07:00
|
|
|
imask |= SPI_INT_TXEI | SPI_INT_TXOI |
|
|
|
|
SPI_INT_RXUI | SPI_INT_RXOI;
|
2015-03-02 19:58:56 +07:00
|
|
|
spi_umask_intr(dws, imask);
|
|
|
|
|
2009-12-15 05:20:22 +07:00
|
|
|
dws->transfer_handler = interrupt_transfer;
|
|
|
|
}
|
|
|
|
|
2015-03-02 19:58:56 +07:00
|
|
|
spi_enable_chip(dws, 1);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-03-09 21:48:46 +07:00
|
|
|
if (dws->dma_mapped) {
|
2015-03-09 21:48:49 +07:00
|
|
|
ret = dws->dma_ops->dma_transfer(dws, transfer);
|
2015-03-09 21:48:46 +07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
if (chip->poll_mode)
|
2015-03-02 19:58:57 +07:00
|
|
|
return poll_transfer(dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-03-02 19:58:57 +07:00
|
|
|
return 1;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
2018-02-01 22:17:29 +07:00
|
|
|
static void dw_spi_handle_err(struct spi_controller *master,
|
2014-01-31 17:07:44 +07:00
|
|
|
struct spi_message *msg)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2018-02-01 22:17:29 +07:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(master);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2015-03-09 21:48:48 +07:00
|
|
|
if (dws->dma_mapped)
|
|
|
|
dws->dma_ops->dma_stop(dws);
|
|
|
|
|
2015-03-02 19:58:57 +07:00
|
|
|
spi_reset_chip(dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This may be called twice for each spi dev */
|
|
|
|
static int dw_spi_setup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct dw_spi_chip *chip_info = NULL;
|
|
|
|
struct chip_data *chip;
|
2014-01-31 17:07:47 +07:00
|
|
|
int ret;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
/* Only alloc on first setup */
|
|
|
|
chip = spi_get_ctldata(spi);
|
|
|
|
if (!chip) {
|
2014-08-31 11:47:06 +07:00
|
|
|
chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
|
2009-12-15 05:20:22 +07:00
|
|
|
if (!chip)
|
|
|
|
return -ENOMEM;
|
2013-12-31 01:30:46 +07:00
|
|
|
spi_set_ctldata(spi, chip);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol drivers may change the chip settings, so...
|
|
|
|
* if chip_info exists, use it
|
|
|
|
*/
|
|
|
|
chip_info = spi->controller_data;
|
|
|
|
|
|
|
|
/* chip_info doesn't always exist */
|
|
|
|
if (chip_info) {
|
|
|
|
if (chip_info->cs_control)
|
|
|
|
chip->cs_control = chip_info->cs_control;
|
|
|
|
|
|
|
|
chip->poll_mode = chip_info->poll_mode;
|
|
|
|
chip->type = chip_info->type;
|
|
|
|
}
|
|
|
|
|
2015-12-23 18:05:39 +07:00
|
|
|
chip->tmode = SPI_TMOD_TR;
|
2014-09-19 00:08:56 +07:00
|
|
|
|
2014-01-31 17:07:47 +07:00
|
|
|
if (gpio_is_valid(spi->cs_gpio)) {
|
|
|
|
ret = gpio_direction_output(spi->cs_gpio,
|
|
|
|
!(spi->mode & SPI_CS_HIGH));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-15 05:20:22 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-31 11:47:06 +07:00
|
|
|
static void dw_spi_cleanup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
|
|
|
|
|
|
|
kfree(chip);
|
|
|
|
spi_set_ctldata(spi, NULL);
|
|
|
|
}
|
|
|
|
|
2009-12-15 05:20:22 +07:00
|
|
|
/* Restart the controller, disable all interrupts, clean rx fifo */
|
2015-01-07 21:56:55 +07:00
|
|
|
static void spi_hw_init(struct device *dev, struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2015-03-02 19:58:55 +07:00
|
|
|
spi_reset_chip(dws);
|
2010-01-21 09:41:10 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to detect the FIFO depth if not set by interface driver,
|
|
|
|
* the depth could be from 2 to 256 from HW spec
|
|
|
|
*/
|
|
|
|
if (!dws->fifo_len) {
|
|
|
|
u32 fifo;
|
2014-09-02 09:49:24 +07:00
|
|
|
|
2015-02-25 16:39:36 +07:00
|
|
|
for (fifo = 1; fifo < 256; fifo++) {
|
2015-03-13 02:19:31 +07:00
|
|
|
dw_writel(dws, DW_SPI_TXFLTR, fifo);
|
|
|
|
if (fifo != dw_readl(dws, DW_SPI_TXFLTR))
|
2010-01-21 09:41:10 +07:00
|
|
|
break;
|
|
|
|
}
|
2015-03-13 02:19:31 +07:00
|
|
|
dw_writel(dws, DW_SPI_TXFLTR, 0);
|
2010-01-21 09:41:10 +07:00
|
|
|
|
2015-02-25 16:39:36 +07:00
|
|
|
dws->fifo_len = (fifo == 1) ? 0 : fifo;
|
2015-01-07 21:56:55 +07:00
|
|
|
dev_dbg(dev, "Detected FIFO size: %u bytes\n", dws->fifo_len);
|
2010-01-21 09:41:10 +07:00
|
|
|
}
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
2013-12-31 01:30:44 +07:00
|
|
|
int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2018-02-01 22:17:29 +07:00
|
|
|
struct spi_controller *master;
|
2009-12-15 05:20:22 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
BUG_ON(dws == NULL);
|
|
|
|
|
2013-12-31 01:30:44 +07:00
|
|
|
master = spi_alloc_master(dev, 0);
|
|
|
|
if (!master)
|
|
|
|
return -ENOMEM;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
dws->master = master;
|
|
|
|
dws->type = SSI_MOTO_SPI;
|
|
|
|
dws->dma_inited = 0;
|
2015-10-27 22:48:16 +07:00
|
|
|
dws->dma_addr = (dma_addr_t)(dws->paddr + DW_SPI_DR);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2017-01-06 16:35:13 +07:00
|
|
|
ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED, dev_name(dev),
|
|
|
|
master);
|
2009-12-15 05:20:22 +07:00
|
|
|
if (ret < 0) {
|
2015-10-15 03:12:17 +07:00
|
|
|
dev_err(dev, "can not get IRQ\n");
|
2009-12-15 05:20:22 +07:00
|
|
|
goto err_free_master;
|
|
|
|
}
|
|
|
|
|
2014-09-19 00:08:56 +07:00
|
|
|
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
|
2013-05-22 09:36:35 +07:00
|
|
|
master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
|
2009-12-15 05:20:22 +07:00
|
|
|
master->bus_num = dws->bus_num;
|
|
|
|
master->num_chipselect = dws->num_cs;
|
|
|
|
master->setup = dw_spi_setup;
|
2014-08-31 11:47:06 +07:00
|
|
|
master->cleanup = dw_spi_cleanup;
|
2015-03-02 19:58:57 +07:00
|
|
|
master->set_cs = dw_spi_set_cs;
|
|
|
|
master->transfer_one = dw_spi_transfer_one;
|
|
|
|
master->handle_err = dw_spi_handle_err;
|
2014-02-20 20:37:56 +07:00
|
|
|
master->max_speed_hz = dws->max_freq;
|
2014-10-09 01:51:34 +07:00
|
|
|
master->dev.of_node = dev->of_node;
|
2016-10-10 21:25:25 +07:00
|
|
|
master->flags = SPI_MASTER_GPIO_SS;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
/* Basic HW init */
|
2015-01-07 21:56:55 +07:00
|
|
|
spi_hw_init(dev, dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2010-12-24 12:59:11 +07:00
|
|
|
if (dws->dma_ops && dws->dma_ops->dma_init) {
|
|
|
|
ret = dws->dma_ops->dma_init(dws);
|
|
|
|
if (ret) {
|
2015-01-07 21:56:54 +07:00
|
|
|
dev_warn(dev, "DMA init failed\n");
|
2010-12-24 12:59:11 +07:00
|
|
|
dws->dma_inited = 0;
|
2015-03-09 21:48:49 +07:00
|
|
|
} else {
|
|
|
|
master->can_dma = dws->dma_ops->can_dma;
|
2010-12-24 12:59:11 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 22:17:29 +07:00
|
|
|
spi_controller_set_devdata(master, dws);
|
|
|
|
ret = devm_spi_register_controller(dev, master);
|
2009-12-15 05:20:22 +07:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&master->dev, "problem registering spi master\n");
|
2014-01-31 17:07:44 +07:00
|
|
|
goto err_dma_exit;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
|
|
|
|
2014-09-12 19:11:56 +07:00
|
|
|
dw_spi_debugfs_init(dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
return 0;
|
|
|
|
|
2014-01-31 17:07:44 +07:00
|
|
|
err_dma_exit:
|
2010-12-24 12:59:11 +07:00
|
|
|
if (dws->dma_ops && dws->dma_ops->dma_exit)
|
|
|
|
dws->dma_ops->dma_exit(dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
spi_enable_chip(dws, 0);
|
2015-10-20 16:11:40 +07:00
|
|
|
free_irq(dws->irq, master);
|
2009-12-15 05:20:22 +07:00
|
|
|
err_free_master:
|
2018-02-01 22:17:29 +07:00
|
|
|
spi_controller_put(master);
|
2009-12-15 05:20:22 +07:00
|
|
|
return ret;
|
|
|
|
}
|
2010-12-24 12:59:10 +07:00
|
|
|
EXPORT_SYMBOL_GPL(dw_spi_add_host);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2012-12-07 23:57:14 +07:00
|
|
|
void dw_spi_remove_host(struct dw_spi *dws)
|
2009-12-15 05:20:22 +07:00
|
|
|
{
|
2014-09-12 19:11:56 +07:00
|
|
|
dw_spi_debugfs_remove(dws);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2010-12-24 12:59:11 +07:00
|
|
|
if (dws->dma_ops && dws->dma_ops->dma_exit)
|
|
|
|
dws->dma_ops->dma_exit(dws);
|
2015-10-15 03:12:23 +07:00
|
|
|
|
|
|
|
spi_shutdown_chip(dws);
|
2015-10-20 16:11:40 +07:00
|
|
|
|
|
|
|
free_irq(dws->irq, dws->master);
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
2010-12-24 12:59:10 +07:00
|
|
|
EXPORT_SYMBOL_GPL(dw_spi_remove_host);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
int dw_spi_suspend_host(struct dw_spi *dws)
|
|
|
|
{
|
2015-10-15 03:12:23 +07:00
|
|
|
int ret;
|
2009-12-15 05:20:22 +07:00
|
|
|
|
2018-02-01 22:17:29 +07:00
|
|
|
ret = spi_controller_suspend(dws->master);
|
2009-12-15 05:20:22 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-10-15 03:12:23 +07:00
|
|
|
|
|
|
|
spi_shutdown_chip(dws);
|
|
|
|
return 0;
|
2009-12-15 05:20:22 +07:00
|
|
|
}
|
2010-12-24 12:59:10 +07:00
|
|
|
EXPORT_SYMBOL_GPL(dw_spi_suspend_host);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
int dw_spi_resume_host(struct dw_spi *dws)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2015-01-07 21:56:55 +07:00
|
|
|
spi_hw_init(&dws->master->dev, dws);
|
2018-02-01 22:17:29 +07:00
|
|
|
ret = spi_controller_resume(dws->master);
|
2009-12-15 05:20:22 +07:00
|
|
|
if (ret)
|
|
|
|
dev_err(&dws->master->dev, "fail to start queue (%d)\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-12-24 12:59:10 +07:00
|
|
|
EXPORT_SYMBOL_GPL(dw_spi_resume_host);
|
2009-12-15 05:20:22 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Driver for DesignWare SPI controller core");
|
|
|
|
MODULE_LICENSE("GPL v2");
|