2018-05-03 03:18:28 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
//
|
|
|
|
// Freescale MXS SPI master driver
|
|
|
|
//
|
|
|
|
// Copyright 2012 DENX Software Engineering, GmbH.
|
|
|
|
// Copyright 2012 Freescale Semiconductor, Inc.
|
|
|
|
// Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Rework and transition to new API by:
|
|
|
|
// Marek Vasut <marex@denx.de>
|
|
|
|
//
|
|
|
|
// Based on previous attempt by:
|
|
|
|
// Fabio Estevam <fabio.estevam@freescale.com>
|
|
|
|
//
|
|
|
|
// Based on code from U-Boot bootloader by:
|
|
|
|
// Marek Vasut <marex@denx.de>
|
|
|
|
//
|
|
|
|
// Based on spi-stmp.c, which is:
|
|
|
|
// Author: Dmitry Pervushin <dimka@embeddedalley.com>
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/dmaengine.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/completion.h>
|
2020-03-17 17:24:57 +08:00
|
|
|
#include <linux/pinctrl/consumer.h>
|
2012-08-03 23:26:11 +08:00
|
|
|
#include <linux/regulator/consumer.h>
|
2017-09-27 23:39:22 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2012-08-03 23:26:11 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/stmp_device.h>
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <linux/spi/mxs-spi.h>
|
2019-01-29 21:48:17 +08:00
|
|
|
#include <trace/events/spi.h>
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
#define DRIVER_NAME "mxs-spi"
|
|
|
|
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
/* Use 10S timeout for very long transfers, it should suffice. */
|
|
|
|
#define SSP_TIMEOUT 10000
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2012-08-03 23:26:13 +08:00
|
|
|
#define SG_MAXLEN 0xff00
|
|
|
|
|
2013-10-02 04:14:50 +08:00
|
|
|
/*
|
|
|
|
* Flags for txrx functions. More efficient that using an argument register for
|
|
|
|
* each one.
|
|
|
|
*/
|
|
|
|
#define TXRX_WRITE (1<<0) /* This is a write */
|
|
|
|
#define TXRX_DEASSERT_CS (1<<1) /* De-assert CS at end of txrx */
|
|
|
|
|
2012-08-03 23:26:11 +08:00
|
|
|
struct mxs_spi {
|
|
|
|
struct mxs_ssp ssp;
|
2012-08-03 23:26:13 +08:00
|
|
|
struct completion c;
|
2013-10-02 04:15:47 +08:00
|
|
|
unsigned int sck; /* Rate requested (vs actual) */
|
2012-08-03 23:26:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int mxs_spi_setup_transfer(struct spi_device *dev,
|
2013-10-02 04:15:40 +08:00
|
|
|
const struct spi_transfer *t)
|
2012-08-03 23:26:11 +08:00
|
|
|
{
|
|
|
|
struct mxs_spi *spi = spi_master_get_devdata(dev->master);
|
|
|
|
struct mxs_ssp *ssp = &spi->ssp;
|
2013-10-02 04:15:40 +08:00
|
|
|
const unsigned int hz = min(dev->max_speed_hz, t->speed_hz);
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
if (hz == 0) {
|
2013-10-02 04:15:40 +08:00
|
|
|
dev_err(&dev->dev, "SPI clock rate of zero not allowed\n");
|
2012-08-03 23:26:11 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-10-02 04:15:47 +08:00
|
|
|
if (hz != spi->sck) {
|
|
|
|
mxs_ssp_set_clk_rate(ssp, hz);
|
|
|
|
/*
|
|
|
|
* Save requested rate, hz, rather than the actual rate,
|
2014-10-03 05:10:22 +08:00
|
|
|
* ssp->clk_rate. Otherwise we would set the rate every transfer
|
2013-10-02 04:15:47 +08:00
|
|
|
* when the actual rate is not quite the same as requested rate.
|
|
|
|
*/
|
|
|
|
spi->sck = hz;
|
|
|
|
/*
|
|
|
|
* Perhaps we should return an error if the actual clock is
|
|
|
|
* nowhere close to what was requested?
|
|
|
|
*/
|
|
|
|
}
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2013-10-02 04:14:25 +08:00
|
|
|
writel(BM_SSP_CTRL0_LOCK_CS,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
writel(BF_SSP_CTRL1_SSP_MODE(BV_SSP_CTRL1_SSP_MODE__SPI) |
|
2013-10-02 04:15:40 +08:00
|
|
|
BF_SSP_CTRL1_WORD_LENGTH(BV_SSP_CTRL1_WORD_LENGTH__EIGHT_BITS) |
|
|
|
|
((dev->mode & SPI_CPOL) ? BM_SSP_CTRL1_POLARITY : 0) |
|
|
|
|
((dev->mode & SPI_CPHA) ? BM_SSP_CTRL1_PHASE : 0),
|
|
|
|
ssp->base + HW_SSP_CTRL1(ssp));
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
writel(0x0, ssp->base + HW_SSP_CMD0);
|
|
|
|
writel(0x0, ssp->base + HW_SSP_CMD1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-02 04:15:54 +08:00
|
|
|
static u32 mxs_spi_cs_to_reg(unsigned cs)
|
2012-08-03 23:26:11 +08:00
|
|
|
{
|
2013-10-02 04:15:54 +08:00
|
|
|
u32 select = 0;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* i.MX28 Datasheet: 17.10.1: HW_SSP_CTRL0
|
|
|
|
*
|
|
|
|
* The bits BM_SSP_CTRL0_WAIT_FOR_CMD and BM_SSP_CTRL0_WAIT_FOR_IRQ
|
|
|
|
* in HW_SSP_CTRL0 register do have multiple usage, please refer to
|
|
|
|
* the datasheet for further details. In SPI mode, they are used to
|
|
|
|
* toggle the chip-select lines (nCS pins).
|
|
|
|
*/
|
|
|
|
if (cs & 1)
|
|
|
|
select |= BM_SSP_CTRL0_WAIT_FOR_CMD;
|
|
|
|
if (cs & 2)
|
|
|
|
select |= BM_SSP_CTRL0_WAIT_FOR_IRQ;
|
|
|
|
|
|
|
|
return select;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mxs_ssp_wait(struct mxs_spi *spi, int offset, int mask, bool set)
|
|
|
|
{
|
2012-09-04 10:40:18 +08:00
|
|
|
const unsigned long timeout = jiffies + msecs_to_jiffies(SSP_TIMEOUT);
|
2012-08-03 23:26:11 +08:00
|
|
|
struct mxs_ssp *ssp = &spi->ssp;
|
2013-10-02 04:15:54 +08:00
|
|
|
u32 reg;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2012-09-04 10:40:18 +08:00
|
|
|
do {
|
2012-08-03 23:26:11 +08:00
|
|
|
reg = readl_relaxed(ssp->base + offset);
|
|
|
|
|
2012-09-04 10:40:18 +08:00
|
|
|
if (!set)
|
|
|
|
reg = ~reg;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2012-09-04 10:40:18 +08:00
|
|
|
reg &= mask;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2012-09-04 10:40:18 +08:00
|
|
|
if (reg == mask)
|
|
|
|
return 0;
|
|
|
|
} while (time_before(jiffies, timeout));
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2012-09-04 10:40:18 +08:00
|
|
|
return -ETIMEDOUT;
|
2012-08-03 23:26:11 +08:00
|
|
|
}
|
|
|
|
|
2012-08-03 23:26:13 +08:00
|
|
|
static void mxs_ssp_dma_irq_callback(void *param)
|
|
|
|
{
|
|
|
|
struct mxs_spi *spi = param;
|
2014-09-02 10:50:48 +08:00
|
|
|
|
2012-08-03 23:26:13 +08:00
|
|
|
complete(&spi->c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t mxs_ssp_irq_handler(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct mxs_ssp *ssp = dev_id;
|
2014-09-02 10:50:48 +08:00
|
|
|
|
2012-08-03 23:26:13 +08:00
|
|
|
dev_err(ssp->dev, "%s[%i] CTRL1=%08x STATUS=%08x\n",
|
|
|
|
__func__, __LINE__,
|
|
|
|
readl(ssp->base + HW_SSP_CTRL1(ssp)),
|
|
|
|
readl(ssp->base + HW_SSP_STATUS(ssp)));
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-10-02 04:15:04 +08:00
|
|
|
static int mxs_spi_txrx_dma(struct mxs_spi *spi,
|
2012-08-03 23:26:13 +08:00
|
|
|
unsigned char *buf, int len,
|
2013-10-02 04:14:50 +08:00
|
|
|
unsigned int flags)
|
2012-08-03 23:26:13 +08:00
|
|
|
{
|
|
|
|
struct mxs_ssp *ssp = &spi->ssp;
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
struct dma_async_tx_descriptor *desc = NULL;
|
|
|
|
const bool vmalloced_buf = is_vmalloc_addr(buf);
|
|
|
|
const int desc_len = vmalloced_buf ? PAGE_SIZE : SG_MAXLEN;
|
|
|
|
const int sgs = DIV_ROUND_UP(len, desc_len);
|
2012-08-03 23:26:13 +08:00
|
|
|
int sg_count;
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
int min, ret;
|
2013-10-02 04:15:54 +08:00
|
|
|
u32 ctrl0;
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
struct page *vm_page;
|
|
|
|
struct {
|
2013-10-02 04:15:54 +08:00
|
|
|
u32 pio[4];
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
struct scatterlist sg;
|
|
|
|
} *dma_xfer;
|
|
|
|
|
|
|
|
if (!len)
|
2012-08-03 23:26:13 +08:00
|
|
|
return -EINVAL;
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
|
2014-09-02 10:50:48 +08:00
|
|
|
dma_xfer = kcalloc(sgs, sizeof(*dma_xfer), GFP_KERNEL);
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
if (!dma_xfer)
|
|
|
|
return -ENOMEM;
|
2012-08-03 23:26:13 +08:00
|
|
|
|
2013-11-15 06:32:02 +08:00
|
|
|
reinit_completion(&spi->c);
|
2012-08-03 23:26:13 +08:00
|
|
|
|
2013-10-02 04:15:04 +08:00
|
|
|
/* Chip select was already programmed into CTRL0 */
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
ctrl0 = readl(ssp->base + HW_SSP_CTRL0);
|
2013-10-02 04:14:57 +08:00
|
|
|
ctrl0 &= ~(BM_SSP_CTRL0_XFER_COUNT | BM_SSP_CTRL0_IGNORE_CRC |
|
|
|
|
BM_SSP_CTRL0_READ);
|
2013-10-02 04:15:04 +08:00
|
|
|
ctrl0 |= BM_SSP_CTRL0_DATA_XFER;
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
|
2013-10-02 04:14:50 +08:00
|
|
|
if (!(flags & TXRX_WRITE))
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
ctrl0 |= BM_SSP_CTRL0_READ;
|
2012-08-03 23:26:13 +08:00
|
|
|
|
|
|
|
/* Queue the DMA data transfer. */
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
for (sg_count = 0; sg_count < sgs; sg_count++) {
|
2013-10-02 04:14:50 +08:00
|
|
|
/* Prepare the transfer descriptor. */
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
min = min(len, desc_len);
|
|
|
|
|
2013-10-02 04:14:50 +08:00
|
|
|
/*
|
|
|
|
* De-assert CS on last segment if flag is set (i.e., no more
|
|
|
|
* transfers will follow)
|
|
|
|
*/
|
|
|
|
if ((sg_count + 1 == sgs) && (flags & TXRX_DEASSERT_CS))
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
ctrl0 |= BM_SSP_CTRL0_IGNORE_CRC;
|
|
|
|
|
2012-12-26 13:48:51 +08:00
|
|
|
if (ssp->devid == IMX23_SSP) {
|
|
|
|
ctrl0 &= ~BM_SSP_CTRL0_XFER_COUNT;
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
ctrl0 |= min;
|
2012-12-26 13:48:51 +08:00
|
|
|
}
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
|
|
|
|
dma_xfer[sg_count].pio[0] = ctrl0;
|
|
|
|
dma_xfer[sg_count].pio[3] = min;
|
|
|
|
|
|
|
|
if (vmalloced_buf) {
|
|
|
|
vm_page = vmalloc_to_page(buf);
|
|
|
|
if (!vm_page) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_vmalloc;
|
|
|
|
}
|
2014-11-17 17:14:32 +08:00
|
|
|
|
|
|
|
sg_init_table(&dma_xfer[sg_count].sg, 1);
|
|
|
|
sg_set_page(&dma_xfer[sg_count].sg, vm_page,
|
|
|
|
min, offset_in_page(buf));
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
} else {
|
2014-11-17 17:14:32 +08:00
|
|
|
sg_init_one(&dma_xfer[sg_count].sg, buf, min);
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = dma_map_sg(ssp->dev, &dma_xfer[sg_count].sg, 1,
|
2013-10-02 04:14:50 +08:00
|
|
|
(flags & TXRX_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
|
|
|
|
len -= min;
|
|
|
|
buf += min;
|
|
|
|
|
|
|
|
/* Queue the PIO register write transfer. */
|
|
|
|
desc = dmaengine_prep_slave_sg(ssp->dmach,
|
|
|
|
(struct scatterlist *)dma_xfer[sg_count].pio,
|
|
|
|
(ssp->devid == IMX23_SSP) ? 1 : 4,
|
|
|
|
DMA_TRANS_NONE,
|
|
|
|
sg_count ? DMA_PREP_INTERRUPT : 0);
|
|
|
|
if (!desc) {
|
|
|
|
dev_err(ssp->dev,
|
|
|
|
"Failed to get PIO reg. write descriptor.\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_mapped;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc = dmaengine_prep_slave_sg(ssp->dmach,
|
|
|
|
&dma_xfer[sg_count].sg, 1,
|
2013-10-02 04:14:50 +08:00
|
|
|
(flags & TXRX_WRITE) ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM,
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
|
|
|
|
|
|
|
|
if (!desc) {
|
|
|
|
dev_err(ssp->dev,
|
|
|
|
"Failed to get DMA data write descriptor.\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_mapped;
|
|
|
|
}
|
2012-08-03 23:26:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The last descriptor must have this callback,
|
|
|
|
* to finish the DMA transaction.
|
|
|
|
*/
|
|
|
|
desc->callback = mxs_ssp_dma_irq_callback;
|
|
|
|
desc->callback_param = spi;
|
|
|
|
|
|
|
|
/* Start the transfer. */
|
|
|
|
dmaengine_submit(desc);
|
|
|
|
dma_async_issue_pending(ssp->dmach);
|
|
|
|
|
2015-02-05 22:47:06 +08:00
|
|
|
if (!wait_for_completion_timeout(&spi->c,
|
|
|
|
msecs_to_jiffies(SSP_TIMEOUT))) {
|
2012-08-03 23:26:13 +08:00
|
|
|
dev_err(ssp->dev, "DMA transfer timeout\n");
|
|
|
|
ret = -ETIMEDOUT;
|
2012-10-14 10:32:56 +08:00
|
|
|
dmaengine_terminate_all(ssp->dmach);
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
goto err_vmalloc;
|
2012-08-03 23:26:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
err_vmalloc:
|
|
|
|
while (--sg_count >= 0) {
|
|
|
|
err_mapped:
|
|
|
|
dma_unmap_sg(ssp->dev, &dma_xfer[sg_count].sg, 1,
|
2013-10-02 04:14:50 +08:00
|
|
|
(flags & TXRX_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
|
2012-08-03 23:26:13 +08:00
|
|
|
}
|
|
|
|
|
mxs/spi: Fix issues when doing long continuous transfer
When doing long continuous transfer, eg. from SPI flash via /dev/mtd,
the driver dies. This is caused by a bug in the DMA chaining. Rework
the DMA transfer code so that this issue does not happen any longer.
This involves proper allocation of correct amount of sg-list members.
Also, this means proper creation of DMA descriptors. There is actually an
important catch to this, the data transfer descriptors must be interleaved
with PIO register write descriptor, otherwise the transfer stalls. This
can be done in one descriptor, but due to the limitation of the DMA API,
it's not possible.
It turns out that in order for the SPI DMA to properly support
continuous transfers longer than 65280 bytes, there are some very
important parts that were left out from the documentation about about
the PIO transfer that is used.
Firstly, the XFER_SIZE register is not written with the whole length
of a transfer, but is written by each and every chained descriptor
with the length of the descriptors data buffer.
Next, unlike the demo code supplied by FSL, which only writes one PIO
word per descriptor, this does not apply if the descriptors are chained,
since the XFER_SIZE register must be written. Therefore, it is essential
to use four PIO words, CTRL0, CMD0, CMD1, XFER_SIZE. CMD0 and CMD1 are
written with zero, since they don't apply. The DMA programs the PIO words
in an incrementing order, so four PIO words.
Finally, unlike the demo code supplied by FSL, the SSP_CTRL0_IGNORE_CRC
must not be set during the whole transfer, but it must be set only on the
last descriptor in the chain.
Lastly, this code lends code from drivers/mtd/nand/omap2.c, which solves
trouble when the buffer supplied to the DMA transfer was vmalloc()'d. So
with this patch, it's safe to use /dev/mtdblockX interface again.
Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-09-04 10:40:15 +08:00
|
|
|
kfree(dma_xfer);
|
|
|
|
|
2012-08-03 23:26:13 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-02 04:15:04 +08:00
|
|
|
static int mxs_spi_txrx_pio(struct mxs_spi *spi,
|
2012-08-03 23:26:11 +08:00
|
|
|
unsigned char *buf, int len,
|
2013-10-02 04:14:50 +08:00
|
|
|
unsigned int flags)
|
2012-08-03 23:26:11 +08:00
|
|
|
{
|
|
|
|
struct mxs_ssp *ssp = &spi->ssp;
|
|
|
|
|
2013-10-02 04:14:39 +08:00
|
|
|
writel(BM_SSP_CTRL0_IGNORE_CRC,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
while (len--) {
|
2013-10-02 04:14:50 +08:00
|
|
|
if (len == 0 && (flags & TXRX_DEASSERT_CS))
|
2013-10-02 04:14:32 +08:00
|
|
|
writel(BM_SSP_CTRL0_IGNORE_CRC,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
if (ssp->devid == IMX23_SSP) {
|
|
|
|
writel(BM_SSP_CTRL0_XFER_COUNT,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
|
|
|
|
writel(1,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
|
|
|
|
} else {
|
|
|
|
writel(1, ssp->base + HW_SSP_XFER_SIZE);
|
|
|
|
}
|
|
|
|
|
2013-10-02 04:14:50 +08:00
|
|
|
if (flags & TXRX_WRITE)
|
2012-08-03 23:26:11 +08:00
|
|
|
writel(BM_SSP_CTRL0_READ,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
|
|
|
|
else
|
|
|
|
writel(BM_SSP_CTRL0_READ,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
|
|
|
|
|
|
|
|
writel(BM_SSP_CTRL0_RUN,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
|
|
|
|
|
|
|
|
if (mxs_ssp_wait(spi, HW_SSP_CTRL0, BM_SSP_CTRL0_RUN, 1))
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
2013-10-02 04:14:50 +08:00
|
|
|
if (flags & TXRX_WRITE)
|
2012-08-03 23:26:11 +08:00
|
|
|
writel(*buf, ssp->base + HW_SSP_DATA(ssp));
|
|
|
|
|
|
|
|
writel(BM_SSP_CTRL0_DATA_XFER,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
|
|
|
|
|
2013-10-02 04:14:50 +08:00
|
|
|
if (!(flags & TXRX_WRITE)) {
|
2012-08-03 23:26:11 +08:00
|
|
|
if (mxs_ssp_wait(spi, HW_SSP_STATUS(ssp),
|
|
|
|
BM_SSP_STATUS_FIFO_EMPTY, 0))
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
|
|
|
*buf = (readl(ssp->base + HW_SSP_DATA(ssp)) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mxs_ssp_wait(spi, HW_SSP_CTRL0, BM_SSP_CTRL0_RUN, 0))
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mxs_spi_transfer_one(struct spi_master *master,
|
|
|
|
struct spi_message *m)
|
|
|
|
{
|
|
|
|
struct mxs_spi *spi = spi_master_get_devdata(master);
|
|
|
|
struct mxs_ssp *ssp = &spi->ssp;
|
2014-02-05 17:47:59 +08:00
|
|
|
struct spi_transfer *t;
|
2013-10-02 04:14:50 +08:00
|
|
|
unsigned int flag;
|
2012-08-03 23:26:11 +08:00
|
|
|
int status = 0;
|
|
|
|
|
2013-10-02 04:15:04 +08:00
|
|
|
/* Program CS register bits here, it will be used for all transfers. */
|
|
|
|
writel(BM_SSP_CTRL0_WAIT_FOR_CMD | BM_SSP_CTRL0_WAIT_FOR_IRQ,
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
|
|
|
|
writel(mxs_spi_cs_to_reg(m->spi->chip_select),
|
|
|
|
ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2014-02-05 17:47:59 +08:00
|
|
|
list_for_each_entry(t, &m->transfers, transfer_list) {
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2019-01-29 21:48:17 +08:00
|
|
|
trace_spi_transfer_start(m, t);
|
|
|
|
|
2012-08-03 23:26:11 +08:00
|
|
|
status = mxs_spi_setup_transfer(m->spi, t);
|
|
|
|
if (status)
|
|
|
|
break;
|
|
|
|
|
2013-10-02 04:14:50 +08:00
|
|
|
/* De-assert on last transfer, inverted by cs_change flag */
|
|
|
|
flag = (&t->transfer_list == m->transfers.prev) ^ t->cs_change ?
|
|
|
|
TXRX_DEASSERT_CS : 0;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2012-08-03 23:26:13 +08:00
|
|
|
/*
|
|
|
|
* Small blocks can be transfered via PIO.
|
|
|
|
* Measured by empiric means:
|
|
|
|
*
|
|
|
|
* dd if=/dev/mtdblock0 of=/dev/null bs=1024k count=1
|
|
|
|
*
|
|
|
|
* DMA only: 2.164808 seconds, 473.0KB/s
|
|
|
|
* Combined: 1.676276 seconds, 610.9KB/s
|
|
|
|
*/
|
2012-09-04 10:40:17 +08:00
|
|
|
if (t->len < 32) {
|
2012-08-03 23:26:13 +08:00
|
|
|
writel(BM_SSP_CTRL1_DMA_ENABLE,
|
|
|
|
ssp->base + HW_SSP_CTRL1(ssp) +
|
|
|
|
STMP_OFFSET_REG_CLR);
|
|
|
|
|
|
|
|
if (t->tx_buf)
|
2013-10-02 04:15:04 +08:00
|
|
|
status = mxs_spi_txrx_pio(spi,
|
2012-08-03 23:26:13 +08:00
|
|
|
(void *)t->tx_buf,
|
2013-10-02 04:14:50 +08:00
|
|
|
t->len, flag | TXRX_WRITE);
|
2012-08-03 23:26:13 +08:00
|
|
|
if (t->rx_buf)
|
2013-10-02 04:15:04 +08:00
|
|
|
status = mxs_spi_txrx_pio(spi,
|
2012-08-03 23:26:13 +08:00
|
|
|
t->rx_buf, t->len,
|
2013-10-02 04:14:50 +08:00
|
|
|
flag);
|
2012-08-03 23:26:13 +08:00
|
|
|
} else {
|
|
|
|
writel(BM_SSP_CTRL1_DMA_ENABLE,
|
|
|
|
ssp->base + HW_SSP_CTRL1(ssp) +
|
|
|
|
STMP_OFFSET_REG_SET);
|
|
|
|
|
|
|
|
if (t->tx_buf)
|
2013-10-02 04:15:04 +08:00
|
|
|
status = mxs_spi_txrx_dma(spi,
|
2012-08-03 23:26:13 +08:00
|
|
|
(void *)t->tx_buf, t->len,
|
2013-10-02 04:14:50 +08:00
|
|
|
flag | TXRX_WRITE);
|
2012-08-03 23:26:13 +08:00
|
|
|
if (t->rx_buf)
|
2013-10-02 04:15:04 +08:00
|
|
|
status = mxs_spi_txrx_dma(spi,
|
2012-08-03 23:26:13 +08:00
|
|
|
t->rx_buf, t->len,
|
2013-10-02 04:14:50 +08:00
|
|
|
flag);
|
2012-08-03 23:26:13 +08:00
|
|
|
}
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2019-01-29 21:48:17 +08:00
|
|
|
trace_spi_transfer_stop(m, t);
|
|
|
|
|
2012-08-24 10:34:18 +08:00
|
|
|
if (status) {
|
|
|
|
stmp_reset_block(ssp->base);
|
2012-08-03 23:26:11 +08:00
|
|
|
break;
|
2012-08-24 10:34:18 +08:00
|
|
|
}
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2012-09-04 10:40:16 +08:00
|
|
|
m->actual_length += t->len;
|
2012-08-03 23:26:11 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 10:32:55 +08:00
|
|
|
m->status = status;
|
2012-08-03 23:26:11 +08:00
|
|
|
spi_finalize_current_message(master);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-09-27 23:39:22 +08:00
|
|
|
static int mxs_spi_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct spi_master *master = dev_get_drvdata(dev);
|
|
|
|
struct mxs_spi *spi = spi_master_get_devdata(master);
|
|
|
|
struct mxs_ssp *ssp = &spi->ssp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
clk_disable_unprepare(ssp->clk);
|
|
|
|
|
|
|
|
ret = pinctrl_pm_select_idle_state(dev);
|
|
|
|
if (ret) {
|
|
|
|
int ret2 = clk_prepare_enable(ssp->clk);
|
|
|
|
|
|
|
|
if (ret2)
|
|
|
|
dev_warn(dev, "Failed to reenable clock after failing pinctrl request (pinctrl: %d, clk: %d)\n",
|
|
|
|
ret, ret2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mxs_spi_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct spi_master *master = dev_get_drvdata(dev);
|
|
|
|
struct mxs_spi *spi = spi_master_get_devdata(master);
|
|
|
|
struct mxs_ssp *ssp = &spi->ssp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pinctrl_pm_select_default_state(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(ssp->clk);
|
|
|
|
if (ret)
|
|
|
|
pinctrl_pm_select_idle_state(dev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __maybe_unused mxs_spi_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct spi_master *master = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = spi_master_suspend(master);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!pm_runtime_suspended(dev))
|
|
|
|
return mxs_spi_runtime_suspend(dev);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __maybe_unused mxs_spi_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct spi_master *master = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!pm_runtime_suspended(dev))
|
|
|
|
ret = mxs_spi_runtime_resume(dev);
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = spi_master_resume(master);
|
|
|
|
if (ret < 0 && !pm_runtime_suspended(dev))
|
|
|
|
mxs_spi_runtime_suspend(dev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dev_pm_ops mxs_spi_pm = {
|
|
|
|
SET_RUNTIME_PM_OPS(mxs_spi_runtime_suspend,
|
|
|
|
mxs_spi_runtime_resume, NULL)
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(mxs_spi_suspend, mxs_spi_resume)
|
|
|
|
};
|
|
|
|
|
2012-08-03 23:26:11 +08:00
|
|
|
static const struct of_device_id mxs_spi_dt_ids[] = {
|
|
|
|
{ .compatible = "fsl,imx23-spi", .data = (void *) IMX23_SSP, },
|
|
|
|
{ .compatible = "fsl,imx28-spi", .data = (void *) IMX28_SSP, },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, mxs_spi_dt_ids);
|
|
|
|
|
2012-12-08 00:57:14 +08:00
|
|
|
static int mxs_spi_probe(struct platform_device *pdev)
|
2012-08-03 23:26:11 +08:00
|
|
|
{
|
|
|
|
const struct of_device_id *of_id =
|
|
|
|
of_match_device(mxs_spi_dt_ids, &pdev->dev);
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
struct spi_master *master;
|
|
|
|
struct mxs_spi *spi;
|
|
|
|
struct mxs_ssp *ssp;
|
|
|
|
struct clk *clk;
|
|
|
|
void __iomem *base;
|
2013-02-26 11:07:32 +08:00
|
|
|
int devid, clk_freq;
|
|
|
|
int ret = 0, irq_err;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2012-08-23 04:38:35 +08:00
|
|
|
/*
|
|
|
|
* Default clock speed for the SPI core. 160MHz seems to
|
|
|
|
* work reasonably well with most SPI flashes, so use this
|
|
|
|
* as a default. Override with "clock-frequency" DT prop.
|
|
|
|
*/
|
|
|
|
const int clk_freq_default = 160000000;
|
|
|
|
|
2012-08-03 23:26:13 +08:00
|
|
|
irq_err = platform_get_irq(pdev, 0);
|
2013-07-22 09:29:54 +08:00
|
|
|
if (irq_err < 0)
|
2014-02-14 11:19:21 +08:00
|
|
|
return irq_err;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2019-09-04 21:59:00 +08:00
|
|
|
base = devm_platform_ioremap_resource(pdev, 0);
|
2013-01-21 18:09:18 +08:00
|
|
|
if (IS_ERR(base))
|
|
|
|
return PTR_ERR(base);
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
clk = devm_clk_get(&pdev->dev, NULL);
|
|
|
|
if (IS_ERR(clk))
|
|
|
|
return PTR_ERR(clk);
|
|
|
|
|
2013-02-26 11:07:32 +08:00
|
|
|
devid = (enum mxs_ssp_id) of_id->data;
|
|
|
|
ret = of_property_read_u32(np, "clock-frequency",
|
|
|
|
&clk_freq);
|
|
|
|
if (ret)
|
2012-08-23 04:38:35 +08:00
|
|
|
clk_freq = clk_freq_default;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
master = spi_alloc_master(&pdev->dev, sizeof(*spi));
|
|
|
|
if (!master)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-09-27 23:39:22 +08:00
|
|
|
platform_set_drvdata(pdev, master);
|
|
|
|
|
2012-08-03 23:26:11 +08:00
|
|
|
master->transfer_one_message = mxs_spi_transfer_one;
|
2013-05-22 10:36:35 +08:00
|
|
|
master->bits_per_word_mask = SPI_BPW_MASK(8);
|
2012-08-03 23:26:11 +08:00
|
|
|
master->mode_bits = SPI_CPOL | SPI_CPHA;
|
|
|
|
master->num_chipselect = 3;
|
|
|
|
master->dev.of_node = np;
|
|
|
|
master->flags = SPI_MASTER_HALF_DUPLEX;
|
2017-09-27 23:39:22 +08:00
|
|
|
master->auto_runtime_pm = true;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
spi = spi_master_get_devdata(master);
|
|
|
|
ssp = &spi->ssp;
|
|
|
|
ssp->dev = &pdev->dev;
|
|
|
|
ssp->clk = clk;
|
|
|
|
ssp->base = base;
|
|
|
|
ssp->devid = devid;
|
2012-08-03 23:26:13 +08:00
|
|
|
|
2012-08-24 10:56:27 +08:00
|
|
|
init_completion(&spi->c);
|
|
|
|
|
2012-08-03 23:26:13 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev, irq_err, mxs_ssp_irq_handler, 0,
|
2014-11-11 03:25:24 +08:00
|
|
|
dev_name(&pdev->dev), ssp);
|
2012-08-03 23:26:13 +08:00
|
|
|
if (ret)
|
|
|
|
goto out_master_free;
|
|
|
|
|
2019-12-12 21:55:46 +08:00
|
|
|
ssp->dmach = dma_request_chan(&pdev->dev, "rx-tx");
|
|
|
|
if (IS_ERR(ssp->dmach)) {
|
2012-08-03 23:26:13 +08:00
|
|
|
dev_err(ssp->dev, "Failed to request DMA\n");
|
2019-12-12 21:55:46 +08:00
|
|
|
ret = PTR_ERR(ssp->dmach);
|
2012-08-03 23:26:13 +08:00
|
|
|
goto out_master_free;
|
|
|
|
}
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2017-09-27 23:39:22 +08:00
|
|
|
pm_runtime_enable(ssp->dev);
|
|
|
|
if (!pm_runtime_enabled(ssp->dev)) {
|
|
|
|
ret = mxs_spi_runtime_resume(ssp->dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(ssp->dev, "runtime resume failed\n");
|
|
|
|
goto out_dma_release;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pm_runtime_get_sync(ssp->dev);
|
|
|
|
if (ret < 0) {
|
2020-11-06 09:24:21 +08:00
|
|
|
pm_runtime_put_noidle(ssp->dev);
|
2017-09-27 23:39:22 +08:00
|
|
|
dev_err(ssp->dev, "runtime_get_sync failed\n");
|
|
|
|
goto out_pm_runtime_disable;
|
|
|
|
}
|
2013-07-10 11:16:28 +08:00
|
|
|
|
2012-08-23 04:38:35 +08:00
|
|
|
clk_set_rate(ssp->clk, clk_freq);
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2013-07-10 11:16:29 +08:00
|
|
|
ret = stmp_reset_block(ssp->base);
|
|
|
|
if (ret)
|
2017-09-27 23:39:22 +08:00
|
|
|
goto out_pm_runtime_put;
|
2012-08-03 23:26:11 +08:00
|
|
|
|
2013-09-24 12:32:56 +08:00
|
|
|
ret = devm_spi_register_master(&pdev->dev, master);
|
2012-08-03 23:26:11 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Cannot register SPI master, %d\n", ret);
|
2017-09-27 23:39:22 +08:00
|
|
|
goto out_pm_runtime_put;
|
2012-08-03 23:26:11 +08:00
|
|
|
}
|
|
|
|
|
2017-09-27 23:39:22 +08:00
|
|
|
pm_runtime_put(ssp->dev);
|
|
|
|
|
2012-08-03 23:26:11 +08:00
|
|
|
return 0;
|
|
|
|
|
2017-09-27 23:39:22 +08:00
|
|
|
out_pm_runtime_put:
|
|
|
|
pm_runtime_put(ssp->dev);
|
|
|
|
out_pm_runtime_disable:
|
|
|
|
pm_runtime_disable(ssp->dev);
|
2013-07-10 11:16:28 +08:00
|
|
|
out_dma_release:
|
2013-07-10 11:16:27 +08:00
|
|
|
dma_release_channel(ssp->dmach);
|
2012-08-03 23:26:13 +08:00
|
|
|
out_master_free:
|
2012-08-03 23:26:11 +08:00
|
|
|
spi_master_put(master);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-08 00:57:14 +08:00
|
|
|
static int mxs_spi_remove(struct platform_device *pdev)
|
2012-08-03 23:26:11 +08:00
|
|
|
{
|
|
|
|
struct spi_master *master;
|
|
|
|
struct mxs_spi *spi;
|
|
|
|
struct mxs_ssp *ssp;
|
|
|
|
|
2013-11-15 15:50:31 +08:00
|
|
|
master = platform_get_drvdata(pdev);
|
2012-08-03 23:26:11 +08:00
|
|
|
spi = spi_master_get_devdata(master);
|
|
|
|
ssp = &spi->ssp;
|
|
|
|
|
2017-09-27 23:39:22 +08:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
if (!pm_runtime_status_suspended(&pdev->dev))
|
|
|
|
mxs_spi_runtime_suspend(&pdev->dev);
|
|
|
|
|
2013-07-10 11:16:27 +08:00
|
|
|
dma_release_channel(ssp->dmach);
|
2012-08-03 23:26:11 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver mxs_spi_driver = {
|
|
|
|
.probe = mxs_spi_probe,
|
2012-12-08 00:57:14 +08:00
|
|
|
.remove = mxs_spi_remove,
|
2012-08-03 23:26:11 +08:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.of_match_table = mxs_spi_dt_ids,
|
2017-09-27 23:39:22 +08:00
|
|
|
.pm = &mxs_spi_pm,
|
2012-08-03 23:26:11 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(mxs_spi_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
|
|
|
|
MODULE_DESCRIPTION("MXS SPI master driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:mxs-spi");
|