2019-05-29 14:18:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-12-14 22:20:22 +00:00
|
|
|
/*
|
2011-06-06 07:16:30 +00:00
|
|
|
* Designware SPI core controller driver (refer pxa2xx_spi.c)
|
2009-12-14 22:20:22 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2009, Intel Corporation.
|
|
|
|
*/
|
|
|
|
|
2021-11-15 18:19:14 +00:00
|
|
|
#include <linux/bitfield.h>
|
2009-12-14 22:20:22 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/interrupt.h>
|
2011-07-03 19:44:29 +00:00
|
|
|
#include <linux/module.h>
|
2020-10-07 23:55:06 +00:00
|
|
|
#include <linux/preempt.h>
|
2009-12-14 22:20:22 +00: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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-12-14 22:20:22 +00:00
|
|
|
#include <linux/spi/spi.h>
|
2020-10-07 23:55:06 +00:00
|
|
|
#include <linux/spi/spi-mem.h>
|
|
|
|
#include <linux/string.h>
|
2020-08-24 20:30:05 +00:00
|
|
|
#include <linux/of.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
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#endif
|
|
|
|
|
2020-10-07 23:54:56 +00:00
|
|
|
/* Slave spi_device related */
|
2021-11-15 18:19:13 +00:00
|
|
|
struct dw_spi_chip_data {
|
2020-10-07 23:54:52 +00:00
|
|
|
u32 cr0;
|
2020-08-24 20:30:05 +00:00
|
|
|
u32 rx_sample_dly; /* RX sample delay */
|
2009-12-14 22:20:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
2020-05-29 13:12:04 +00:00
|
|
|
|
|
|
|
#define DW_SPI_DBGFS_REG(_name, _off) \
|
|
|
|
{ \
|
|
|
|
.name = _name, \
|
|
|
|
.offset = _off, \
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 13:12:04 +00:00
|
|
|
static const struct debugfs_reg32 dw_spi_dbgfs_regs[] = {
|
|
|
|
DW_SPI_DBGFS_REG("CTRLR0", DW_SPI_CTRLR0),
|
|
|
|
DW_SPI_DBGFS_REG("CTRLR1", DW_SPI_CTRLR1),
|
|
|
|
DW_SPI_DBGFS_REG("SSIENR", DW_SPI_SSIENR),
|
|
|
|
DW_SPI_DBGFS_REG("SER", DW_SPI_SER),
|
|
|
|
DW_SPI_DBGFS_REG("BAUDR", DW_SPI_BAUDR),
|
|
|
|
DW_SPI_DBGFS_REG("TXFTLR", DW_SPI_TXFTLR),
|
|
|
|
DW_SPI_DBGFS_REG("RXFTLR", DW_SPI_RXFTLR),
|
|
|
|
DW_SPI_DBGFS_REG("TXFLR", DW_SPI_TXFLR),
|
|
|
|
DW_SPI_DBGFS_REG("RXFLR", DW_SPI_RXFLR),
|
|
|
|
DW_SPI_DBGFS_REG("SR", DW_SPI_SR),
|
|
|
|
DW_SPI_DBGFS_REG("IMR", DW_SPI_IMR),
|
|
|
|
DW_SPI_DBGFS_REG("ISR", DW_SPI_ISR),
|
|
|
|
DW_SPI_DBGFS_REG("DMACR", DW_SPI_DMACR),
|
|
|
|
DW_SPI_DBGFS_REG("DMATDLR", DW_SPI_DMATDLR),
|
|
|
|
DW_SPI_DBGFS_REG("DMARDLR", DW_SPI_DMARDLR),
|
2020-08-24 20:30:05 +00:00
|
|
|
DW_SPI_DBGFS_REG("RX_SAMPLE_DLY", DW_SPI_RX_SAMPLE_DLY),
|
2009-12-14 22:20:22 +00:00
|
|
|
};
|
|
|
|
|
2023-05-20 22:40:25 +00:00
|
|
|
static void dw_spi_debugfs_init(struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2017-01-06 09:35:13 +00:00
|
|
|
char name[32];
|
2016-12-22 09:18:12 +00:00
|
|
|
|
2017-01-06 09:35:13 +00:00
|
|
|
snprintf(name, 32, "dw_spi%d", dws->master->bus_num);
|
2016-12-22 09:18:12 +00:00
|
|
|
dws->debugfs = debugfs_create_dir(name, NULL);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-05-29 13:12:04 +00:00
|
|
|
dws->regset.regs = dw_spi_dbgfs_regs;
|
|
|
|
dws->regset.nregs = ARRAY_SIZE(dw_spi_dbgfs_regs);
|
|
|
|
dws->regset.base = dws->regs;
|
|
|
|
debugfs_create_regset32("registers", 0400, dws->debugfs, &dws->regset);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2014-09-12 12:11:56 +00:00
|
|
|
static void dw_spi_debugfs_remove(struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2014-09-02 02:49:24 +00:00
|
|
|
debugfs_remove_recursive(dws->debugfs);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2023-05-20 22:40:25 +00:00
|
|
|
static inline void dw_spi_debugfs_init(struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-12 12:11:56 +00:00
|
|
|
static inline void dw_spi_debugfs_remove(struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DEBUG_FS */
|
|
|
|
|
2018-07-27 19:53:54 +00:00
|
|
|
void dw_spi_set_cs(struct spi_device *spi, bool enable)
|
2015-03-02 12:58:57 +00:00
|
|
|
{
|
2018-02-01 15:17:29 +00:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
|
2020-05-15 10:47:43 +00:00
|
|
|
bool cs_high = !!(spi->mode & SPI_CS_HIGH);
|
2015-03-02 12:58:57 +00:00
|
|
|
|
2020-05-15 10:47:43 +00:00
|
|
|
/*
|
|
|
|
* DW SPI controller demands any native CS being set in order to
|
|
|
|
* proceed with data transfer. So in order to activate the SPI
|
|
|
|
* communications we must set a corresponding bit in the Slave
|
|
|
|
* Enable register no matter whether the SPI core is configured to
|
|
|
|
* support active-high or active-low CS level.
|
|
|
|
*/
|
|
|
|
if (cs_high == enable)
|
2023-03-10 17:32:03 +00:00
|
|
|
dw_writel(dws, DW_SPI_SER, BIT(spi_get_chipselect(spi, 0)));
|
2020-10-07 23:55:03 +00:00
|
|
|
else
|
2018-10-11 11:20:07 +00:00
|
|
|
dw_writel(dws, DW_SPI_SER, 0);
|
2015-03-02 12:58:57 +00:00
|
|
|
}
|
2021-11-15 18:19:11 +00:00
|
|
|
EXPORT_SYMBOL_NS_GPL(dw_spi_set_cs, SPI_DW_CORE);
|
2015-03-02 12:58:57 +00:00
|
|
|
|
2011-03-30 15:09:54 +00:00
|
|
|
/* Return the max entries we can fill into tx fifo */
|
2021-11-15 18:19:13 +00:00
|
|
|
static inline u32 dw_spi_tx_max(struct dw_spi *dws)
|
2011-03-30 15:09:54 +00:00
|
|
|
{
|
2020-10-07 23:54:57 +00:00
|
|
|
u32 tx_room, rxtx_gap;
|
2011-03-30 15:09:54 +00:00
|
|
|
|
2015-03-12 19:19:31 +00:00
|
|
|
tx_room = dws->fifo_len - dw_readl(dws, DW_SPI_TXFLR);
|
2011-03-30 15:09:54 +00: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.
|
|
|
|
*/
|
2020-10-07 23:54:57 +00:00
|
|
|
rxtx_gap = dws->fifo_len - (dws->rx_len - dws->tx_len);
|
2011-03-30 15:09:54 +00:00
|
|
|
|
2020-10-07 23:54:57 +00:00
|
|
|
return min3((u32)dws->tx_len, tx_room, rxtx_gap);
|
2011-03-30 15:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the max entries we should read out of rx fifo */
|
2021-11-15 18:19:13 +00:00
|
|
|
static inline u32 dw_spi_rx_max(struct dw_spi *dws)
|
2011-03-30 15:09:54 +00:00
|
|
|
{
|
2020-10-07 23:54:57 +00:00
|
|
|
return min_t(u32, dws->rx_len, dw_readl(dws, DW_SPI_RXFLR));
|
2011-03-30 15:09:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 15:09:55 +00:00
|
|
|
static void dw_writer(struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
u32 max = dw_spi_tx_max(dws);
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
u32 txw = 0;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2011-03-30 15:09:54 +00:00
|
|
|
while (max--) {
|
2020-10-07 23:54:57 +00:00
|
|
|
if (dws->tx) {
|
2011-03-30 15:09:54 +00:00
|
|
|
if (dws->n_bytes == 1)
|
|
|
|
txw = *(u8 *)(dws->tx);
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
else if (dws->n_bytes == 2)
|
2011-03-30 15:09:54 +00:00
|
|
|
txw = *(u16 *)(dws->tx);
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
else
|
|
|
|
txw = *(u32 *)(dws->tx);
|
2020-10-07 23:54:57 +00:00
|
|
|
|
|
|
|
dws->tx += dws->n_bytes;
|
2011-03-30 15:09:54 +00:00
|
|
|
}
|
2015-08-18 20:21:53 +00:00
|
|
|
dw_write_io_reg(dws, DW_SPI_DR, txw);
|
2020-10-07 23:54:57 +00:00
|
|
|
--dws->tx_len;
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-30 15:09:55 +00:00
|
|
|
static void dw_reader(struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
u32 max = dw_spi_rx_max(dws);
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
u32 rxw;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2011-03-30 15:09:54 +00:00
|
|
|
while (max--) {
|
2015-08-18 20:21:53 +00:00
|
|
|
rxw = dw_read_io_reg(dws, DW_SPI_DR);
|
2020-10-07 23:54:57 +00:00
|
|
|
if (dws->rx) {
|
2011-03-30 15:09:52 +00:00
|
|
|
if (dws->n_bytes == 1)
|
|
|
|
*(u8 *)(dws->rx) = rxw;
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
else if (dws->n_bytes == 2)
|
2011-03-30 15:09:52 +00:00
|
|
|
*(u16 *)(dws->rx) = rxw;
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
else
|
|
|
|
*(u32 *)(dws->rx) = rxw;
|
2020-10-07 23:54:57 +00:00
|
|
|
|
|
|
|
dws->rx += dws->n_bytes;
|
2011-03-30 15:09:52 +00:00
|
|
|
}
|
2020-10-07 23:54:57 +00:00
|
|
|
--dws->rx_len;
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:55:05 +00:00
|
|
|
int dw_spi_check_status(struct dw_spi *dws, bool raw)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2020-10-07 23:55:05 +00:00
|
|
|
u32 irq_status;
|
|
|
|
int ret = 0;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-10-07 23:55:05 +00:00
|
|
|
if (raw)
|
|
|
|
irq_status = dw_readl(dws, DW_SPI_RISR);
|
|
|
|
else
|
|
|
|
irq_status = dw_readl(dws, DW_SPI_ISR);
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
if (irq_status & DW_SPI_INT_RXOI) {
|
2020-10-07 23:55:05 +00:00
|
|
|
dev_err(&dws->master->dev, "RX FIFO overflow detected\n");
|
|
|
|
ret = -EIO;
|
|
|
|
}
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
if (irq_status & DW_SPI_INT_RXUI) {
|
2020-10-07 23:55:05 +00:00
|
|
|
dev_err(&dws->master->dev, "RX FIFO underflow detected\n");
|
|
|
|
ret = -EIO;
|
|
|
|
}
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
if (irq_status & DW_SPI_INT_TXOI) {
|
2020-10-07 23:55:05 +00:00
|
|
|
dev_err(&dws->master->dev, "TX FIFO overflow detected\n");
|
|
|
|
ret = -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generically handle the erroneous situation */
|
|
|
|
if (ret) {
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_reset_chip(dws);
|
2020-10-07 23:55:05 +00:00
|
|
|
if (dws->master->cur_msg)
|
|
|
|
dws->master->cur_msg->status = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
2021-11-15 18:19:11 +00:00
|
|
|
EXPORT_SYMBOL_NS_GPL(dw_spi_check_status, SPI_DW_CORE);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-10-07 23:54:59 +00:00
|
|
|
static irqreturn_t dw_spi_transfer_handler(struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2015-03-12 19:19:31 +00:00
|
|
|
u16 irq_status = dw_readl(dws, DW_SPI_ISR);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-10-07 23:55:05 +00:00
|
|
|
if (dw_spi_check_status(dws, false)) {
|
|
|
|
spi_finalize_current_transfer(dws->master);
|
2009-12-14 22:20:22 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:54:58 +00:00
|
|
|
/*
|
|
|
|
* Read data from the Rx FIFO every time we've got a chance executing
|
|
|
|
* this method. If there is nothing left to receive, terminate the
|
|
|
|
* procedure. Otherwise adjust the Rx FIFO Threshold level if it's a
|
|
|
|
* final stage of the transfer. By doing so we'll get the next IRQ
|
|
|
|
* right when the leftover incoming data is received.
|
|
|
|
*/
|
2011-03-30 15:09:55 +00:00
|
|
|
dw_reader(dws);
|
2020-10-07 23:54:57 +00:00
|
|
|
if (!dws->rx_len) {
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_mask_intr(dws, 0xff);
|
2015-03-02 12:58:57 +00:00
|
|
|
spi_finalize_current_transfer(dws->master);
|
2020-10-07 23:54:58 +00:00
|
|
|
} else if (dws->rx_len <= dw_readl(dws, DW_SPI_RXFTLR)) {
|
|
|
|
dw_writel(dws, DW_SPI_RXFTLR, dws->rx_len - 1);
|
2011-03-30 15:09:55 +00:00
|
|
|
}
|
2020-10-07 23:54:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send data out if Tx FIFO Empty IRQ is received. The IRQ will be
|
|
|
|
* disabled after the data transmission is finished so not to
|
|
|
|
* have the TXE IRQ flood at the final stage of the transfer.
|
|
|
|
*/
|
2021-11-15 18:19:13 +00:00
|
|
|
if (irq_status & DW_SPI_INT_TXEI) {
|
2011-03-30 15:09:55 +00:00
|
|
|
dw_writer(dws);
|
2020-10-07 23:54:58 +00:00
|
|
|
if (!dws->tx_len)
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_mask_intr(dws, DW_SPI_INT_TXEI);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t dw_spi_irq(int irq, void *dev_id)
|
|
|
|
{
|
2018-02-01 15:17:29 +00:00
|
|
|
struct spi_controller *master = dev_id;
|
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(master);
|
2021-11-15 18:19:14 +00:00
|
|
|
u16 irq_status = dw_readl(dws, DW_SPI_ISR) & DW_SPI_INT_MASK;
|
2010-09-07 07:27:27 +00:00
|
|
|
|
|
|
|
if (!irq_status)
|
|
|
|
return IRQ_NONE;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2015-03-02 12:58:57 +00:00
|
|
|
if (!master->cur_msg) {
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_mask_intr(dws, 0xff);
|
2009-12-14 22:20:22 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dws->transfer_handler(dws);
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:54:52 +00:00
|
|
|
static u32 dw_spi_prepare_cr0(struct dw_spi *dws, struct spi_device *spi)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2020-10-07 23:54:52 +00:00
|
|
|
u32 cr0 = 0;
|
2020-05-05 13:06:13 +00:00
|
|
|
|
2021-11-15 18:19:16 +00:00
|
|
|
if (dw_spi_ip_is(dws, PSSI)) {
|
2020-10-07 23:54:51 +00:00
|
|
|
/* CTRLR0[ 5: 4] Frame Format */
|
2021-11-15 18:19:14 +00:00
|
|
|
cr0 |= FIELD_PREP(DW_PSSI_CTRLR0_FRF_MASK, DW_SPI_CTRLR0_FRF_MOTO_SPI);
|
2020-05-05 13:06:13 +00:00
|
|
|
|
2020-10-07 23:54:51 +00:00
|
|
|
/*
|
|
|
|
* SPI mode (SCPOL|SCPH)
|
|
|
|
* CTRLR0[ 6] Serial Clock Phase
|
|
|
|
* CTRLR0[ 7] Serial Clock Polarity
|
|
|
|
*/
|
2021-11-15 18:19:14 +00:00
|
|
|
if (spi->mode & SPI_CPOL)
|
|
|
|
cr0 |= DW_PSSI_CTRLR0_SCPOL;
|
|
|
|
if (spi->mode & SPI_CPHA)
|
|
|
|
cr0 |= DW_PSSI_CTRLR0_SCPHA;
|
2020-05-05 13:06:14 +00:00
|
|
|
|
2020-10-07 23:54:51 +00:00
|
|
|
/* CTRLR0[11] Shift Register Loop */
|
2021-11-15 18:19:14 +00:00
|
|
|
if (spi->mode & SPI_LOOP)
|
|
|
|
cr0 |= DW_PSSI_CTRLR0_SRL;
|
2020-10-07 23:54:51 +00:00
|
|
|
} else {
|
|
|
|
/* CTRLR0[ 7: 6] Frame Format */
|
2021-11-15 18:19:14 +00:00
|
|
|
cr0 |= FIELD_PREP(DW_HSSI_CTRLR0_FRF_MASK, DW_SPI_CTRLR0_FRF_MOTO_SPI);
|
2020-05-05 13:06:14 +00:00
|
|
|
|
2020-10-07 23:54:51 +00:00
|
|
|
/*
|
|
|
|
* SPI mode (SCPOL|SCPH)
|
|
|
|
* CTRLR0[ 8] Serial Clock Phase
|
|
|
|
* CTRLR0[ 9] Serial Clock Polarity
|
|
|
|
*/
|
2021-11-15 18:19:14 +00:00
|
|
|
if (spi->mode & SPI_CPOL)
|
|
|
|
cr0 |= DW_HSSI_CTRLR0_SCPOL;
|
|
|
|
if (spi->mode & SPI_CPHA)
|
|
|
|
cr0 |= DW_HSSI_CTRLR0_SCPHA;
|
2020-05-05 13:06:14 +00:00
|
|
|
|
2020-10-07 23:54:51 +00:00
|
|
|
/* CTRLR0[13] Shift Register Loop */
|
2021-11-15 18:19:14 +00:00
|
|
|
if (spi->mode & SPI_LOOP)
|
|
|
|
cr0 |= DW_HSSI_CTRLR0_SRL;
|
2020-05-05 13:06:14 +00:00
|
|
|
|
2022-07-13 04:22:22 +00:00
|
|
|
/* CTRLR0[31] MST */
|
|
|
|
if (dw_spi_ver_is_ge(dws, HSSI, 102A))
|
|
|
|
cr0 |= DW_HSSI_CTRLR0_MST;
|
2020-10-07 23:54:51 +00:00
|
|
|
}
|
2020-09-20 11:28:54 +00:00
|
|
|
|
2020-10-07 23:54:52 +00:00
|
|
|
return cr0;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:54:56 +00:00
|
|
|
void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
|
|
|
|
struct dw_spi_cfg *cfg)
|
2020-10-07 23:54:52 +00:00
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
struct dw_spi_chip_data *chip = spi_get_ctldata(spi);
|
2020-10-07 23:54:52 +00:00
|
|
|
u32 cr0 = chip->cr0;
|
2020-10-07 23:54:54 +00:00
|
|
|
u32 speed_hz;
|
|
|
|
u16 clk_div;
|
2020-10-07 23:54:52 +00:00
|
|
|
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
/* CTRLR0[ 4/3: 0] or CTRLR0[ 20: 16] Data Frame Size */
|
|
|
|
cr0 |= (cfg->dfs - 1) << dws->dfs_offset;
|
2020-10-07 23:54:52 +00:00
|
|
|
|
2021-11-15 18:19:16 +00:00
|
|
|
if (dw_spi_ip_is(dws, PSSI))
|
2020-10-07 23:54:52 +00:00
|
|
|
/* CTRLR0[ 9:8] Transfer Mode */
|
2021-11-15 18:19:14 +00:00
|
|
|
cr0 |= FIELD_PREP(DW_PSSI_CTRLR0_TMOD_MASK, cfg->tmode);
|
2020-10-07 23:54:52 +00:00
|
|
|
else
|
|
|
|
/* CTRLR0[11:10] Transfer Mode */
|
2021-11-15 18:19:14 +00:00
|
|
|
cr0 |= FIELD_PREP(DW_HSSI_CTRLR0_TMOD_MASK, cfg->tmode);
|
2020-10-07 23:54:52 +00:00
|
|
|
|
2020-10-07 23:54:51 +00:00
|
|
|
dw_writel(dws, DW_SPI_CTRLR0, cr0);
|
2020-10-07 23:54:53 +00:00
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
if (cfg->tmode == DW_SPI_CTRLR0_TMOD_EPROMREAD ||
|
|
|
|
cfg->tmode == DW_SPI_CTRLR0_TMOD_RO)
|
2020-10-07 23:54:56 +00:00
|
|
|
dw_writel(dws, DW_SPI_CTRLR1, cfg->ndf ? cfg->ndf - 1 : 0);
|
|
|
|
|
2020-10-07 23:54:54 +00:00
|
|
|
/* Note DW APB SSI clock divider doesn't support odd numbers */
|
2020-10-07 23:54:56 +00:00
|
|
|
clk_div = (DIV_ROUND_UP(dws->max_freq, cfg->freq) + 1) & 0xfffe;
|
2020-10-07 23:54:54 +00:00
|
|
|
speed_hz = dws->max_freq / clk_div;
|
|
|
|
|
|
|
|
if (dws->current_freq != speed_hz) {
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_set_clk(dws, clk_div);
|
2020-10-07 23:54:54 +00:00
|
|
|
dws->current_freq = speed_hz;
|
2020-10-07 23:54:53 +00:00
|
|
|
}
|
2020-10-07 23:54:55 +00:00
|
|
|
|
|
|
|
/* Update RX sample delay if required */
|
|
|
|
if (dws->cur_rx_sample_dly != chip->rx_sample_dly) {
|
|
|
|
dw_writel(dws, DW_SPI_RX_SAMPLE_DLY, chip->rx_sample_dly);
|
|
|
|
dws->cur_rx_sample_dly = chip->rx_sample_dly;
|
|
|
|
}
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
2021-11-15 18:19:11 +00:00
|
|
|
EXPORT_SYMBOL_NS_GPL(dw_spi_update_config, SPI_DW_CORE);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-10-07 23:54:59 +00:00
|
|
|
static void dw_spi_irq_setup(struct dw_spi *dws)
|
|
|
|
{
|
|
|
|
u16 level;
|
|
|
|
u8 imask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Originally Tx and Rx data lengths match. Rx FIFO Threshold level
|
|
|
|
* will be adjusted at the final stage of the IRQ-based SPI transfer
|
|
|
|
* execution so not to lose the leftover of the incoming data.
|
|
|
|
*/
|
2023-01-13 18:59:42 +00:00
|
|
|
level = min_t(unsigned int, dws->fifo_len / 2, dws->tx_len);
|
2020-10-07 23:54:59 +00:00
|
|
|
dw_writel(dws, DW_SPI_TXFTLR, level);
|
|
|
|
dw_writel(dws, DW_SPI_RXFTLR, level - 1);
|
|
|
|
|
2020-11-17 09:40:54 +00:00
|
|
|
dws->transfer_handler = dw_spi_transfer_handler;
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
imask = DW_SPI_INT_TXEI | DW_SPI_INT_TXOI |
|
|
|
|
DW_SPI_INT_RXUI | DW_SPI_INT_RXOI | DW_SPI_INT_RXFI;
|
|
|
|
dw_spi_umask_intr(dws, imask);
|
2020-10-07 23:54:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:55:08 +00:00
|
|
|
/*
|
|
|
|
* The iterative procedure of the poll-based transfer is simple: write as much
|
|
|
|
* as possible to the Tx FIFO, wait until the pending to receive data is ready
|
|
|
|
* to be read, read it from the Rx FIFO and check whether the performed
|
|
|
|
* procedure has been successful.
|
|
|
|
*
|
|
|
|
* Note this method the same way as the IRQ-based transfer won't work well for
|
|
|
|
* the SPI devices connected to the controller with native CS due to the
|
|
|
|
* automatic CS assertion/de-assertion.
|
|
|
|
*/
|
|
|
|
static int dw_spi_poll_transfer(struct dw_spi *dws,
|
|
|
|
struct spi_transfer *transfer)
|
|
|
|
{
|
|
|
|
struct spi_delay delay;
|
|
|
|
u16 nbits;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
delay.unit = SPI_DELAY_UNIT_SCK;
|
|
|
|
nbits = dws->n_bytes * BITS_PER_BYTE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
dw_writer(dws);
|
|
|
|
|
|
|
|
delay.value = nbits * (dws->rx_len - dws->tx_len);
|
|
|
|
spi_delay_exec(&delay, transfer);
|
|
|
|
|
|
|
|
dw_reader(dws);
|
|
|
|
|
|
|
|
ret = dw_spi_check_status(dws, true);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
} while (dws->rx_len);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:17:29 +00:00
|
|
|
static int dw_spi_transfer_one(struct spi_controller *master,
|
2021-11-15 18:19:13 +00:00
|
|
|
struct spi_device *spi,
|
|
|
|
struct spi_transfer *transfer)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2018-02-01 15:17:29 +00:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(master);
|
2020-10-07 23:54:56 +00:00
|
|
|
struct dw_spi_cfg cfg = {
|
2021-11-15 18:19:13 +00:00
|
|
|
.tmode = DW_SPI_CTRLR0_TMOD_TR,
|
2020-10-07 23:54:56 +00:00
|
|
|
.dfs = transfer->bits_per_word,
|
|
|
|
.freq = transfer->speed_hz,
|
|
|
|
};
|
2015-03-09 14:48:46 +00:00
|
|
|
int ret;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2015-03-09 14:48:49 +00:00
|
|
|
dws->dma_mapped = 0;
|
2023-05-12 10:47:45 +00:00
|
|
|
dws->n_bytes =
|
|
|
|
roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word,
|
|
|
|
BITS_PER_BYTE));
|
|
|
|
|
2009-12-14 22:20:22 +00:00
|
|
|
dws->tx = (void *)transfer->tx_buf;
|
2020-10-07 23:54:57 +00:00
|
|
|
dws->tx_len = transfer->len / dws->n_bytes;
|
2009-12-14 22:20:22 +00:00
|
|
|
dws->rx = transfer->rx_buf;
|
2020-10-07 23:54:57 +00:00
|
|
|
dws->rx_len = dws->tx_len;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-10-07 23:54:57 +00:00
|
|
|
/* Ensure the data above is visible for all CPUs */
|
2020-01-03 02:52:10 +00:00
|
|
|
smp_mb();
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 0);
|
2015-03-02 12:58:56 +00:00
|
|
|
|
2020-10-07 23:54:56 +00:00
|
|
|
dw_spi_update_config(dws, spi, &cfg);
|
2018-09-04 19:49:44 +00:00
|
|
|
|
2020-10-07 23:54:54 +00:00
|
|
|
transfer->effective_speed_hz = dws->current_freq;
|
2010-01-21 11:40:52 +00:00
|
|
|
|
2009-12-14 22:20:22 +00:00
|
|
|
/* Check if current transfer is a DMA transaction */
|
2015-03-09 14:48:49 +00:00
|
|
|
if (master->can_dma && master->can_dma(master, spi, transfer))
|
|
|
|
dws->dma_mapped = master->cur_msg_mapped;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2015-03-02 12:58:56 +00:00
|
|
|
/* For poll mode just disable all interrupts */
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_mask_intr(dws, 0xff);
|
2015-03-02 12:58:56 +00:00
|
|
|
|
2015-03-09 14:48:46 +00:00
|
|
|
if (dws->dma_mapped) {
|
2015-03-09 14:48:49 +00:00
|
|
|
ret = dws->dma_ops->dma_setup(dws, transfer);
|
2020-10-07 23:55:01 +00:00
|
|
|
if (ret)
|
2015-03-09 14:48:46 +00:00
|
|
|
return ret;
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 1);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-05-29 13:11:51 +00:00
|
|
|
if (dws->dma_mapped)
|
|
|
|
return dws->dma_ops->dma_transfer(dws, transfer);
|
2020-10-07 23:55:08 +00:00
|
|
|
else if (dws->irq == IRQ_NOTCONNECTED)
|
|
|
|
return dw_spi_poll_transfer(dws, transfer);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-10-07 23:55:00 +00:00
|
|
|
dw_spi_irq_setup(dws);
|
|
|
|
|
2015-03-02 12:58:57 +00:00
|
|
|
return 1;
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 15:17:29 +00:00
|
|
|
static void dw_spi_handle_err(struct spi_controller *master,
|
2021-11-15 18:19:13 +00:00
|
|
|
struct spi_message *msg)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2018-02-01 15:17:29 +00:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(master);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2015-03-09 14:48:48 +00:00
|
|
|
if (dws->dma_mapped)
|
|
|
|
dws->dma_ops->dma_stop(dws);
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_reset_chip(dws);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:55:06 +00:00
|
|
|
static int dw_spi_adjust_mem_op_size(struct spi_mem *mem, struct spi_mem_op *op)
|
|
|
|
{
|
|
|
|
if (op->data.dir == SPI_MEM_DATA_IN)
|
2021-11-15 18:19:13 +00:00
|
|
|
op->data.nbytes = clamp_val(op->data.nbytes, 0, DW_SPI_NDF_MASK + 1);
|
2020-10-07 23:55:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool dw_spi_supports_mem_op(struct spi_mem *mem,
|
|
|
|
const struct spi_mem_op *op)
|
|
|
|
{
|
|
|
|
if (op->data.buswidth > 1 || op->addr.buswidth > 1 ||
|
|
|
|
op->dummy.buswidth > 1 || op->cmd.buswidth > 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return spi_mem_default_supports_op(mem, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_spi_init_mem_buf(struct dw_spi *dws, const struct spi_mem_op *op)
|
|
|
|
{
|
|
|
|
unsigned int i, j, len;
|
|
|
|
u8 *out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the total length of the EEPROM command transfer and
|
|
|
|
* either use the pre-allocated buffer or create a temporary one.
|
|
|
|
*/
|
|
|
|
len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
|
|
|
|
if (op->data.dir == SPI_MEM_DATA_OUT)
|
|
|
|
len += op->data.nbytes;
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
if (len <= DW_SPI_BUF_SIZE) {
|
2020-10-07 23:55:06 +00:00
|
|
|
out = dws->buf;
|
|
|
|
} else {
|
|
|
|
out = kzalloc(len, GFP_KERNEL);
|
|
|
|
if (!out)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect the operation code, address and dummy bytes into the single
|
|
|
|
* buffer. If it's a transfer with data to be sent, also copy it into the
|
|
|
|
* single buffer in order to speed the data transmission up.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < op->cmd.nbytes; ++i)
|
2021-11-15 18:19:13 +00:00
|
|
|
out[i] = DW_SPI_GET_BYTE(op->cmd.opcode, op->cmd.nbytes - i - 1);
|
2020-10-07 23:55:06 +00:00
|
|
|
for (j = 0; j < op->addr.nbytes; ++i, ++j)
|
2021-11-15 18:19:13 +00:00
|
|
|
out[i] = DW_SPI_GET_BYTE(op->addr.val, op->addr.nbytes - j - 1);
|
2020-10-07 23:55:06 +00:00
|
|
|
for (j = 0; j < op->dummy.nbytes; ++i, ++j)
|
|
|
|
out[i] = 0x0;
|
|
|
|
|
|
|
|
if (op->data.dir == SPI_MEM_DATA_OUT)
|
|
|
|
memcpy(&out[i], op->data.buf.out, op->data.nbytes);
|
|
|
|
|
|
|
|
dws->n_bytes = 1;
|
|
|
|
dws->tx = out;
|
|
|
|
dws->tx_len = len;
|
|
|
|
if (op->data.dir == SPI_MEM_DATA_IN) {
|
|
|
|
dws->rx = op->data.buf.in;
|
|
|
|
dws->rx_len = op->data.nbytes;
|
|
|
|
} else {
|
|
|
|
dws->rx = NULL;
|
|
|
|
dws->rx_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dw_spi_free_mem_buf(struct dw_spi *dws)
|
|
|
|
{
|
|
|
|
if (dws->tx != dws->buf)
|
|
|
|
kfree(dws->tx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_spi_write_then_read(struct dw_spi *dws, struct spi_device *spi)
|
|
|
|
{
|
|
|
|
u32 room, entries, sts;
|
|
|
|
unsigned int len;
|
|
|
|
u8 *buf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At initial stage we just pre-fill the Tx FIFO in with no rush,
|
|
|
|
* since native CS hasn't been enabled yet and the automatic data
|
|
|
|
* transmission won't start til we do that.
|
|
|
|
*/
|
|
|
|
len = min(dws->fifo_len, dws->tx_len);
|
|
|
|
buf = dws->tx;
|
|
|
|
while (len--)
|
|
|
|
dw_write_io_reg(dws, DW_SPI_DR, *buf++);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* After setting any bit in the SER register the transmission will
|
|
|
|
* start automatically. We have to keep up with that procedure
|
|
|
|
* otherwise the CS de-assertion will happen whereupon the memory
|
|
|
|
* operation will be pre-terminated.
|
|
|
|
*/
|
|
|
|
len = dws->tx_len - ((void *)buf - dws->tx);
|
|
|
|
dw_spi_set_cs(spi, false);
|
|
|
|
while (len) {
|
|
|
|
entries = readl_relaxed(dws->regs + DW_SPI_TXFLR);
|
|
|
|
if (!entries) {
|
|
|
|
dev_err(&dws->master->dev, "CS de-assertion on Tx\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
room = min(dws->fifo_len - entries, len);
|
|
|
|
for (; room; --room, --len)
|
|
|
|
dw_write_io_reg(dws, DW_SPI_DR, *buf++);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data fetching will start automatically if the EEPROM-read mode is
|
|
|
|
* activated. We have to keep up with the incoming data pace to
|
|
|
|
* prevent the Rx FIFO overflow causing the inbound data loss.
|
|
|
|
*/
|
|
|
|
len = dws->rx_len;
|
|
|
|
buf = dws->rx;
|
|
|
|
while (len) {
|
|
|
|
entries = readl_relaxed(dws->regs + DW_SPI_RXFLR);
|
|
|
|
if (!entries) {
|
|
|
|
sts = readl_relaxed(dws->regs + DW_SPI_RISR);
|
2021-11-15 18:19:13 +00:00
|
|
|
if (sts & DW_SPI_INT_RXOI) {
|
2020-10-07 23:55:06 +00:00
|
|
|
dev_err(&dws->master->dev, "FIFO overflow on Rx\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
entries = min(entries, len);
|
|
|
|
for (; entries; --entries, --len)
|
|
|
|
*buf++ = dw_read_io_reg(dws, DW_SPI_DR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool dw_spi_ctlr_busy(struct dw_spi *dws)
|
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
return dw_readl(dws, DW_SPI_SR) & DW_SPI_SR_BUSY;
|
2020-10-07 23:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_spi_wait_mem_op_done(struct dw_spi *dws)
|
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
int retry = DW_SPI_WAIT_RETRIES;
|
2020-10-07 23:55:06 +00:00
|
|
|
struct spi_delay delay;
|
|
|
|
unsigned long ns, us;
|
|
|
|
u32 nents;
|
|
|
|
|
|
|
|
nents = dw_readl(dws, DW_SPI_TXFLR);
|
|
|
|
ns = NSEC_PER_SEC / dws->current_freq * nents;
|
|
|
|
ns *= dws->n_bytes * BITS_PER_BYTE;
|
|
|
|
if (ns <= NSEC_PER_USEC) {
|
|
|
|
delay.unit = SPI_DELAY_UNIT_NSECS;
|
|
|
|
delay.value = ns;
|
|
|
|
} else {
|
|
|
|
us = DIV_ROUND_UP(ns, NSEC_PER_USEC);
|
|
|
|
delay.unit = SPI_DELAY_UNIT_USECS;
|
|
|
|
delay.value = clamp_val(us, 0, USHRT_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (dw_spi_ctlr_busy(dws) && retry--)
|
|
|
|
spi_delay_exec(&delay, NULL);
|
|
|
|
|
|
|
|
if (retry < 0) {
|
|
|
|
dev_err(&dws->master->dev, "Mem op hanged up\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dw_spi_stop_mem_op(struct dw_spi *dws, struct spi_device *spi)
|
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 0);
|
2020-10-07 23:55:06 +00:00
|
|
|
dw_spi_set_cs(spi, true);
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 1);
|
2020-10-07 23:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The SPI memory operation implementation below is the best choice for the
|
|
|
|
* devices, which are selected by the native chip-select lane. It's
|
|
|
|
* specifically developed to workaround the problem with automatic chip-select
|
|
|
|
* lane toggle when there is no data in the Tx FIFO buffer. Luckily the current
|
|
|
|
* SPI-mem core calls exec_op() callback only if the GPIO-based CS is
|
|
|
|
* unavailable.
|
|
|
|
*/
|
|
|
|
static int dw_spi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op)
|
|
|
|
{
|
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(mem->spi->controller);
|
|
|
|
struct dw_spi_cfg cfg;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect the outbound data into a single buffer to speed the
|
|
|
|
* transmission up at least on the initial stage.
|
|
|
|
*/
|
|
|
|
ret = dw_spi_init_mem_buf(dws, op);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DW SPI EEPROM-read mode is required only for the SPI memory Data-IN
|
|
|
|
* operation. Transmit-only mode is suitable for the rest of them.
|
|
|
|
*/
|
|
|
|
cfg.dfs = 8;
|
2020-10-07 23:55:07 +00:00
|
|
|
cfg.freq = clamp(mem->spi->max_speed_hz, 0U, dws->max_mem_freq);
|
2020-10-07 23:55:06 +00:00
|
|
|
if (op->data.dir == SPI_MEM_DATA_IN) {
|
2021-11-15 18:19:13 +00:00
|
|
|
cfg.tmode = DW_SPI_CTRLR0_TMOD_EPROMREAD;
|
2020-10-07 23:55:06 +00:00
|
|
|
cfg.ndf = op->data.nbytes;
|
|
|
|
} else {
|
2021-11-15 18:19:13 +00:00
|
|
|
cfg.tmode = DW_SPI_CTRLR0_TMOD_TO;
|
2020-10-07 23:55:06 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 0);
|
2020-10-07 23:55:06 +00:00
|
|
|
|
|
|
|
dw_spi_update_config(dws, mem->spi, &cfg);
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_mask_intr(dws, 0xff);
|
2020-10-07 23:55:06 +00:00
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 1);
|
2020-10-07 23:55:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DW APB SSI controller has very nasty peculiarities. First originally
|
|
|
|
* (without any vendor-specific modifications) it doesn't provide a
|
|
|
|
* direct way to set and clear the native chip-select signal. Instead
|
|
|
|
* the controller asserts the CS lane if Tx FIFO isn't empty and a
|
|
|
|
* transmission is going on, and automatically de-asserts it back to
|
|
|
|
* the high level if the Tx FIFO doesn't have anything to be pushed
|
|
|
|
* out. Due to that a multi-tasking or heavy IRQs activity might be
|
|
|
|
* fatal, since the transfer procedure preemption may cause the Tx FIFO
|
|
|
|
* getting empty and sudden CS de-assertion, which in the middle of the
|
|
|
|
* transfer will most likely cause the data loss. Secondly the
|
|
|
|
* EEPROM-read or Read-only DW SPI transfer modes imply the incoming
|
|
|
|
* data being automatically pulled in into the Rx FIFO. So if the
|
|
|
|
* driver software is late in fetching the data from the FIFO before
|
|
|
|
* it's overflown, new incoming data will be lost. In order to make
|
|
|
|
* sure the executed memory operations are CS-atomic and to prevent the
|
|
|
|
* Rx FIFO overflow we have to disable the local interrupts so to block
|
|
|
|
* any preemption during the subsequent IO operations.
|
|
|
|
*
|
|
|
|
* Note. At some circumstances disabling IRQs may not help to prevent
|
|
|
|
* the problems described above. The CS de-assertion and Rx FIFO
|
|
|
|
* overflow may still happen due to the relatively slow system bus or
|
|
|
|
* CPU not working fast enough, so the write-then-read algo implemented
|
|
|
|
* here just won't keep up with the SPI bus data transfer. Such
|
|
|
|
* situation is highly platform specific and is supposed to be fixed by
|
|
|
|
* manually restricting the SPI bus frequency using the
|
|
|
|
* dws->max_mem_freq parameter.
|
|
|
|
*/
|
|
|
|
local_irq_save(flags);
|
|
|
|
preempt_disable();
|
|
|
|
|
|
|
|
ret = dw_spi_write_then_read(dws, mem->spi);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
preempt_enable();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the operation being finished and check the controller
|
|
|
|
* status only if there hasn't been any run-time error detected. In the
|
|
|
|
* former case it's just pointless. In the later one to prevent an
|
|
|
|
* additional error message printing since any hw error flag being set
|
|
|
|
* would be due to an error detected on the data transfer.
|
|
|
|
*/
|
|
|
|
if (!ret) {
|
|
|
|
ret = dw_spi_wait_mem_op_done(dws);
|
|
|
|
if (!ret)
|
|
|
|
ret = dw_spi_check_status(dws, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
dw_spi_stop_mem_op(dws, mem->spi);
|
|
|
|
|
|
|
|
dw_spi_free_mem_buf(dws);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the default memory operations if a glue layer hasn't specified
|
|
|
|
* custom ones. Direct mapping operations will be preserved anyway since DW SPI
|
|
|
|
* controller doesn't have an embedded dirmap interface. Note the memory
|
|
|
|
* operations implemented in this driver is the best choice only for the DW APB
|
|
|
|
* SSI controller with standard native CS functionality. If a hardware vendor
|
|
|
|
* has fixed the automatic CS assertion/de-assertion peculiarity, then it will
|
|
|
|
* be safer to use the normal SPI-messages-based transfers implementation.
|
|
|
|
*/
|
|
|
|
static void dw_spi_init_mem_ops(struct dw_spi *dws)
|
|
|
|
{
|
|
|
|
if (!dws->mem_ops.exec_op && !(dws->caps & DW_SPI_CAP_CS_OVERRIDE) &&
|
|
|
|
!dws->set_cs) {
|
|
|
|
dws->mem_ops.adjust_op_size = dw_spi_adjust_mem_op_size;
|
|
|
|
dws->mem_ops.supports_op = dw_spi_supports_mem_op;
|
|
|
|
dws->mem_ops.exec_op = dw_spi_exec_mem_op;
|
2020-10-07 23:55:07 +00:00
|
|
|
if (!dws->max_mem_freq)
|
|
|
|
dws->max_mem_freq = dws->max_freq;
|
2020-10-07 23:55:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-14 22:20:22 +00:00
|
|
|
/* This may be called twice for each spi dev */
|
|
|
|
static int dw_spi_setup(struct spi_device *spi)
|
|
|
|
{
|
2020-10-07 23:54:52 +00:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
|
2021-11-15 18:19:13 +00:00
|
|
|
struct dw_spi_chip_data *chip;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
|
|
|
/* Only alloc on first setup */
|
|
|
|
chip = spi_get_ctldata(spi);
|
|
|
|
if (!chip) {
|
2020-08-24 20:30:05 +00:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
|
|
|
|
u32 rx_sample_dly_ns;
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
2009-12-14 22:20:22 +00:00
|
|
|
if (!chip)
|
|
|
|
return -ENOMEM;
|
2013-12-30 18:30:46 +00:00
|
|
|
spi_set_ctldata(spi, chip);
|
2020-08-24 20:30:05 +00:00
|
|
|
/* Get specific / default rx-sample-delay */
|
|
|
|
if (device_property_read_u32(&spi->dev,
|
|
|
|
"rx-sample-delay-ns",
|
|
|
|
&rx_sample_dly_ns) != 0)
|
|
|
|
/* Use default controller value */
|
|
|
|
rx_sample_dly_ns = dws->def_rx_sample_dly_ns;
|
|
|
|
chip->rx_sample_dly = DIV_ROUND_CLOSEST(rx_sample_dly_ns,
|
|
|
|
NSEC_PER_SEC /
|
|
|
|
dws->max_freq);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:54:52 +00:00
|
|
|
/*
|
|
|
|
* Update CR0 data each time the setup callback is invoked since
|
|
|
|
* the device parameters could have been changed, for instance, by
|
|
|
|
* the MMC SPI driver or something else.
|
|
|
|
*/
|
|
|
|
chip->cr0 = dw_spi_prepare_cr0(dws, spi);
|
|
|
|
|
2009-12-14 22:20:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-31 04:47:06 +00:00
|
|
|
static void dw_spi_cleanup(struct spi_device *spi)
|
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
struct dw_spi_chip_data *chip = spi_get_ctldata(spi);
|
2014-08-31 04:47:06 +00:00
|
|
|
|
|
|
|
kfree(chip);
|
|
|
|
spi_set_ctldata(spi, NULL);
|
|
|
|
}
|
|
|
|
|
2009-12-14 22:20:22 +00:00
|
|
|
/* Restart the controller, disable all interrupts, clean rx fifo */
|
2021-11-15 18:19:13 +00:00
|
|
|
static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_reset_chip(dws);
|
2010-01-21 02:41:10 +00:00
|
|
|
|
2021-11-15 18:19:15 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the Synopsys component version if it hasn't been specified
|
|
|
|
* by the platform. CoreKit version ID is encoded as a 3-chars ASCII
|
|
|
|
* code enclosed with '*' (typical for the most of Synopsys IP-cores).
|
|
|
|
*/
|
|
|
|
if (!dws->ver) {
|
|
|
|
dws->ver = dw_readl(dws, DW_SPI_VERSION);
|
|
|
|
|
|
|
|
dev_dbg(dev, "Synopsys DWC%sSSI v%c.%c%c\n",
|
2021-11-15 18:19:16 +00:00
|
|
|
dw_spi_ip_is(dws, PSSI) ? " APB " : " ",
|
2021-11-15 18:19:15 +00:00
|
|
|
DW_SPI_GET_BYTE(dws->ver, 3), DW_SPI_GET_BYTE(dws->ver, 2),
|
|
|
|
DW_SPI_GET_BYTE(dws->ver, 1));
|
|
|
|
}
|
|
|
|
|
2010-01-21 02:41:10 +00: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 02:49:24 +00:00
|
|
|
|
2015-02-25 09:39:36 +00:00
|
|
|
for (fifo = 1; fifo < 256; fifo++) {
|
2020-05-05 13:06:12 +00:00
|
|
|
dw_writel(dws, DW_SPI_TXFTLR, fifo);
|
|
|
|
if (fifo != dw_readl(dws, DW_SPI_TXFTLR))
|
2010-01-21 02:41:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-05-05 13:06:12 +00:00
|
|
|
dw_writel(dws, DW_SPI_TXFTLR, 0);
|
2010-01-21 02:41:10 +00:00
|
|
|
|
2015-02-25 09:39:36 +00:00
|
|
|
dws->fifo_len = (fifo == 1) ? 0 : fifo;
|
2015-01-07 14:56:55 +00:00
|
|
|
dev_dbg(dev, "Detected FIFO size: %u bytes\n", dws->fifo_len);
|
2010-01-21 02:41:10 +00:00
|
|
|
}
|
2018-10-11 11:20:07 +00:00
|
|
|
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
/*
|
|
|
|
* Detect CTRLR0.DFS field size and offset by testing the lowest bits
|
|
|
|
* writability. Note DWC SSI controller also has the extended DFS, but
|
|
|
|
* with zero offset.
|
|
|
|
*/
|
2021-11-15 18:19:16 +00:00
|
|
|
if (dw_spi_ip_is(dws, PSSI)) {
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
u32 cr0, tmp = dw_readl(dws, DW_SPI_CTRLR0);
|
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 0);
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
dw_writel(dws, DW_SPI_CTRLR0, 0xffffffff);
|
|
|
|
cr0 = dw_readl(dws, DW_SPI_CTRLR0);
|
|
|
|
dw_writel(dws, DW_SPI_CTRLR0, tmp);
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 1);
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
if (!(cr0 & DW_PSSI_CTRLR0_DFS_MASK)) {
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
dws->caps |= DW_SPI_CAP_DFS32;
|
2021-11-15 18:19:14 +00:00
|
|
|
dws->dfs_offset = __bf_shf(DW_PSSI_CTRLR0_DFS32_MASK);
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
dev_dbg(dev, "Detected 32-bits max data frame size\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dws->caps |= DW_SPI_CAP_DFS32;
|
|
|
|
}
|
|
|
|
|
2018-10-11 11:20:07 +00:00
|
|
|
/* enable HW fixup for explicit CS deselect for Amazon's alpine chip */
|
2020-09-20 11:28:53 +00:00
|
|
|
if (dws->caps & DW_SPI_CAP_CS_OVERRIDE)
|
2018-10-11 11:20:07 +00:00
|
|
|
dw_writel(dws, DW_SPI_CS_OVERRIDE, 0xF);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 18:30:44 +00:00
|
|
|
int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2018-02-01 15:17:29 +00:00
|
|
|
struct spi_controller *master;
|
2009-12-14 22:20:22 +00:00
|
|
|
int ret;
|
|
|
|
|
2019-12-05 23:14:21 +00:00
|
|
|
if (!dws)
|
|
|
|
return -EINVAL;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2013-12-30 18:30:44 +00:00
|
|
|
master = spi_alloc_master(dev, 0);
|
|
|
|
if (!master)
|
|
|
|
return -ENOMEM;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2021-12-22 15:57:38 +00:00
|
|
|
device_set_node(&master->dev, dev_fwnode(dev));
|
|
|
|
|
2009-12-14 22:20:22 +00:00
|
|
|
dws->master = master;
|
2015-10-27 15:48:16 +00:00
|
|
|
dws->dma_addr = (dma_addr_t)(dws->paddr + DW_SPI_DR);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2018-07-17 14:23:10 +00:00
|
|
|
spi_controller_set_devdata(master, dws);
|
|
|
|
|
2020-09-20 11:28:50 +00:00
|
|
|
/* Basic HW init */
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_hw_init(dev, dws);
|
2020-09-20 11:28:50 +00:00
|
|
|
|
2017-01-06 09:35:13 +00:00
|
|
|
ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED, dev_name(dev),
|
|
|
|
master);
|
2020-10-07 23:55:08 +00:00
|
|
|
if (ret < 0 && ret != -ENOTCONN) {
|
2015-10-14 20:12:17 +00:00
|
|
|
dev_err(dev, "can not get IRQ\n");
|
2009-12-14 22:20:22 +00:00
|
|
|
goto err_free_master;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:55:06 +00:00
|
|
|
dw_spi_init_mem_ops(dws);
|
|
|
|
|
2019-01-07 15:51:56 +00:00
|
|
|
master->use_gpio_descriptors = true;
|
2014-09-18 17:08:56 +00:00
|
|
|
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
|
spi: dw: Add support for 32-bits max xfer size
The Synopsis DesignWare DW_apb_ssi specifications version 3.23 onward
define a 32-bits maximum transfer size synthesis parameter
(SSI_MAX_XFER_SIZE=32) in addition to the legacy 16-bits configuration
(SSI_MAX_XFER_SIZE=16) for SPI controllers. When SSI_MAX_XFER_SIZE=32,
the layout of the ctrlr0 register changes, moving the data frame format
field from bits [3..0] to bits [16..20], and the RX/TX FIFO word size
can be up to 32-bits.
To support this new format, introduce the DW SPI capability flag
DW_SPI_CAP_DFS32 to indicate that a controller is configured with
SSI_MAX_XFER_SIZE=32. Since SSI_MAX_XFER_SIZE is a controller synthesis
parameter not accessible through a register, the detection of this
parameter value is done in spi_hw_init() by writing and reading the
ctrlr0 register and testing the value of bits [3..0]. These bits are
ignored (unchanged) for SSI_MAX_XFER_SIZE=16, allowing the detection.
If a DFS32 capable SPI controller is detected, the new field dfs_offset
in struct dw_spi is set to SPI_DFS32_OFFSET (16).
dw_spi_update_config() is modified to set the data frame size field at
the correct position is the CTRLR0 register, as indicated by the
dfs_offset field of the dw_spi structure.
The DW_SPI_CAP_DFS32 flag is also unconditionally set for SPI slave
controllers, e.g. controllers that have the DW_SPI_CAP_DWC_SSI
capability flag set. However, for these ssi controllers, the dfs_offset
field is set to 0 as before (as per specifications).
Finally, for any controller with the DW_SPI_CAP_DFS32 capability flag
set, dw_spi_add_host() extends the value of bits_per_word_mask from
16-bits to 32-bits. dw_reader() and dw_writer() are also modified to
handle 32-bits iTX/RX FIFO words.
Suggested-by: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20201206011817.11700-3-damien.lemoal@wdc.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-12-06 01:18:16 +00:00
|
|
|
if (dws->caps & DW_SPI_CAP_DFS32)
|
|
|
|
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
|
|
|
|
else
|
|
|
|
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
|
2009-12-14 22:20:22 +00:00
|
|
|
master->bus_num = dws->bus_num;
|
|
|
|
master->num_chipselect = dws->num_cs;
|
|
|
|
master->setup = dw_spi_setup;
|
2014-08-31 04:47:06 +00:00
|
|
|
master->cleanup = dw_spi_cleanup;
|
2020-10-07 23:54:50 +00:00
|
|
|
if (dws->set_cs)
|
|
|
|
master->set_cs = dws->set_cs;
|
|
|
|
else
|
|
|
|
master->set_cs = dw_spi_set_cs;
|
2015-03-02 12:58:57 +00:00
|
|
|
master->transfer_one = dw_spi_transfer_one;
|
|
|
|
master->handle_err = dw_spi_handle_err;
|
2020-11-20 21:34:14 +00:00
|
|
|
if (dws->mem_ops.exec_op)
|
|
|
|
master->mem_ops = &dws->mem_ops;
|
2014-02-20 13:37:56 +00:00
|
|
|
master->max_speed_hz = dws->max_freq;
|
2023-07-10 15:49:30 +00:00
|
|
|
master->flags = SPI_CONTROLLER_GPIO_SS;
|
2019-09-18 08:04:35 +00:00
|
|
|
master->auto_runtime_pm = true;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-08-24 20:30:05 +00:00
|
|
|
/* Get default rx sample delay */
|
|
|
|
device_property_read_u32(dev, "rx-sample-delay-ns",
|
|
|
|
&dws->def_rx_sample_dly_ns);
|
|
|
|
|
2010-12-24 05:59:11 +00:00
|
|
|
if (dws->dma_ops && dws->dma_ops->dma_init) {
|
2020-05-06 15:30:24 +00:00
|
|
|
ret = dws->dma_ops->dma_init(dev, dws);
|
2022-06-24 21:06:23 +00:00
|
|
|
if (ret == -EPROBE_DEFER) {
|
|
|
|
goto err_free_irq;
|
|
|
|
} else if (ret) {
|
2015-01-07 14:56:54 +00:00
|
|
|
dev_warn(dev, "DMA init failed\n");
|
2015-03-09 14:48:49 +00:00
|
|
|
} else {
|
|
|
|
master->can_dma = dws->dma_ops->can_dma;
|
2020-05-29 13:11:57 +00:00
|
|
|
master->flags |= SPI_CONTROLLER_MUST_TX;
|
2010-12-24 05:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-25 12:25:01 +00:00
|
|
|
ret = spi_register_controller(master);
|
2009-12-14 22:20:22 +00:00
|
|
|
if (ret) {
|
2022-08-22 18:18:53 +00:00
|
|
|
dev_err_probe(dev, ret, "problem registering spi master\n");
|
2014-01-31 10:07:44 +00:00
|
|
|
goto err_dma_exit;
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
|
|
|
|
2014-09-12 12:11:56 +00:00
|
|
|
dw_spi_debugfs_init(dws);
|
2009-12-14 22:20:22 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-01-31 10:07:44 +00:00
|
|
|
err_dma_exit:
|
2010-12-24 05:59:11 +00:00
|
|
|
if (dws->dma_ops && dws->dma_ops->dma_exit)
|
|
|
|
dws->dma_ops->dma_exit(dws);
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_enable_chip(dws, 0);
|
2022-06-24 21:06:23 +00:00
|
|
|
err_free_irq:
|
2015-10-20 09:11:40 +00:00
|
|
|
free_irq(dws->irq, master);
|
2009-12-14 22:20:22 +00:00
|
|
|
err_free_master:
|
2018-02-01 15:17:29 +00:00
|
|
|
spi_controller_put(master);
|
2009-12-14 22:20:22 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2021-11-15 18:19:11 +00:00
|
|
|
EXPORT_SYMBOL_NS_GPL(dw_spi_add_host, SPI_DW_CORE);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2012-12-07 16:57:14 +00:00
|
|
|
void dw_spi_remove_host(struct dw_spi *dws)
|
2009-12-14 22:20:22 +00:00
|
|
|
{
|
2014-09-12 12:11:56 +00:00
|
|
|
dw_spi_debugfs_remove(dws);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2020-05-25 12:25:01 +00:00
|
|
|
spi_unregister_controller(dws->master);
|
|
|
|
|
2010-12-24 05:59:11 +00:00
|
|
|
if (dws->dma_ops && dws->dma_ops->dma_exit)
|
|
|
|
dws->dma_ops->dma_exit(dws);
|
2015-10-14 20:12:23 +00:00
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_shutdown_chip(dws);
|
2015-10-20 09:11:40 +00:00
|
|
|
|
|
|
|
free_irq(dws->irq, dws->master);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
2021-11-15 18:19:11 +00:00
|
|
|
EXPORT_SYMBOL_NS_GPL(dw_spi_remove_host, SPI_DW_CORE);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
|
|
|
int dw_spi_suspend_host(struct dw_spi *dws)
|
|
|
|
{
|
2015-10-14 20:12:23 +00:00
|
|
|
int ret;
|
2009-12-14 22:20:22 +00:00
|
|
|
|
2018-02-01 15:17:29 +00:00
|
|
|
ret = spi_controller_suspend(dws->master);
|
2009-12-14 22:20:22 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-10-14 20:12:23 +00:00
|
|
|
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_shutdown_chip(dws);
|
2015-10-14 20:12:23 +00:00
|
|
|
return 0;
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
2021-11-15 18:19:11 +00:00
|
|
|
EXPORT_SYMBOL_NS_GPL(dw_spi_suspend_host, SPI_DW_CORE);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
|
|
|
int dw_spi_resume_host(struct dw_spi *dws)
|
|
|
|
{
|
2021-11-15 18:19:13 +00:00
|
|
|
dw_spi_hw_init(&dws->master->dev, dws);
|
2018-09-05 08:51:57 +00:00
|
|
|
return spi_controller_resume(dws->master);
|
2009-12-14 22:20:22 +00:00
|
|
|
}
|
2021-11-15 18:19:11 +00:00
|
|
|
EXPORT_SYMBOL_NS_GPL(dw_spi_resume_host, SPI_DW_CORE);
|
2009-12-14 22:20:22 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Driver for DesignWare SPI controller core");
|
|
|
|
MODULE_LICENSE("GPL v2");
|