From: Emil Renner Berthing <esmil@mailme.dk>
To: linux-spi@vger.kernel.org
Cc: Emil Renner Berthing <kernel@esmil.dk>,
Addy Ke <addy.ke@rock-chips.com>, Mark Brown <broonie@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 06/14] spi: rockchip: read transfer info directly
Date: Wed, 31 Oct 2018 11:57:03 +0100 [thread overview]
Message-ID: <20181031105711.19575-7-esmil@mailme.dk> (raw)
In-Reply-To: <20181031105711.19575-1-esmil@mailme.dk>
From: Emil Renner Berthing <kernel@esmil.dk>
Just read transfer info directly from the spi device
and transfer structures rather than storing it in
driver data first.
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---
drivers/spi/spi-rockchip.c | 70 +++++++++++++-------------------------
1 file changed, 24 insertions(+), 46 deletions(-)
diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index 5729e6071729..5edc51820d35 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -178,12 +178,8 @@ struct rockchip_spi {
/* max bus freq supported */
u32 max_freq;
- u16 mode;
- u8 tmode;
- u8 bpw;
u8 n_bytes;
u32 rsd_nsecs;
- unsigned len;
u32 speed;
const void *tx;
@@ -194,8 +190,6 @@ struct rockchip_spi {
bool cs_asserted[ROCKCHIP_SPI_MAX_CS_NUM];
bool use_dma;
- struct sg_table tx_sg;
- struct sg_table rx_sg;
struct rockchip_spi_dma_data dma_rx;
struct rockchip_spi_dma_data dma_tx;
};
@@ -282,17 +276,6 @@ static void rockchip_spi_set_cs(struct spi_device *spi, bool enable)
rs->cs_asserted[spi->chip_select] = cs_asserted;
}
-static int rockchip_spi_prepare_message(struct spi_master *master,
- struct spi_message *msg)
-{
- struct rockchip_spi *rs = spi_master_get_devdata(master);
- struct spi_device *spi = msg->spi;
-
- rs->mode = spi->mode;
-
- return 0;
-}
-
static void rockchip_spi_handle_err(struct spi_master *master,
struct spi_message *msg)
{
@@ -397,14 +380,15 @@ static void rockchip_spi_dma_txcb(void *data)
spi_finalize_current_transfer(rs->master);
}
-static int rockchip_spi_prepare_dma(struct rockchip_spi *rs)
+static int rockchip_spi_prepare_dma(struct rockchip_spi *rs,
+ struct spi_transfer *xfer)
{
struct dma_async_tx_descriptor *rxdesc, *txdesc;
atomic_set(&rs->state, 0);
rxdesc = NULL;
- if (rs->rx) {
+ if (xfer->rx_buf) {
struct dma_slave_config rxconf = {
.direction = DMA_DEV_TO_MEM,
.src_addr = rs->dma_rx.addr,
@@ -416,7 +400,7 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs)
rxdesc = dmaengine_prep_slave_sg(
rs->dma_rx.ch,
- rs->rx_sg.sgl, rs->rx_sg.nents,
+ xfer->rx_sg.sgl, xfer->rx_sg.nents,
DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
if (!rxdesc)
return -EINVAL;
@@ -426,7 +410,7 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs)
}
txdesc = NULL;
- if (rs->tx) {
+ if (xfer->tx_buf) {
struct dma_slave_config txconf = {
.direction = DMA_MEM_TO_DEV,
.dst_addr = rs->dma_tx.addr,
@@ -438,7 +422,7 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs)
txdesc = dmaengine_prep_slave_sg(
rs->dma_tx.ch,
- rs->tx_sg.sgl, rs->tx_sg.nents,
+ xfer->tx_sg.sgl, xfer->tx_sg.nents,
DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
if (!txdesc) {
if (rxdesc)
@@ -469,7 +453,8 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs)
return 1;
}
-static void rockchip_spi_config(struct rockchip_spi *rs)
+static void rockchip_spi_config(struct rockchip_spi *rs,
+ struct spi_device *spi, struct spi_transfer *xfer)
{
u32 div = 0;
u32 dmacr = 0;
@@ -481,13 +466,19 @@ static void rockchip_spi_config(struct rockchip_spi *rs)
| CR0_EM_BIG << CR0_EM_OFFSET;
cr0 |= (rs->n_bytes << CR0_DFS_OFFSET);
- cr0 |= ((rs->mode & 0x3) << CR0_SCPH_OFFSET);
- cr0 |= (rs->tmode << CR0_XFM_OFFSET);
+ cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET;
+
+ if (xfer->rx_buf && xfer->tx_buf)
+ cr0 |= CR0_XFM_TR << CR0_XFM_OFFSET;
+ else if (xfer->rx_buf)
+ cr0 |= CR0_XFM_RO << CR0_XFM_OFFSET;
+ else
+ cr0 |= CR0_XFM_TO << CR0_XFM_OFFSET;
if (rs->use_dma) {
- if (rs->tx)
+ if (xfer->tx_buf)
dmacr |= TF_DMA_EN;
- if (rs->rx)
+ if (xfer->rx_buf)
dmacr |= RF_DMA_EN;
}
@@ -521,11 +512,11 @@ static void rockchip_spi_config(struct rockchip_spi *rs)
writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0);
if (rs->n_bytes == 1)
- writel_relaxed(rs->len - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
+ writel_relaxed(xfer->len - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
else if (rs->n_bytes == 2)
- writel_relaxed((rs->len / 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
+ writel_relaxed((xfer->len / 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
else
- writel_relaxed((rs->len * 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
+ writel_relaxed((xfer->len * 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_TXFTLR);
writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
@@ -565,24 +556,12 @@ static int rockchip_spi_transfer_one(
}
rs->speed = xfer->speed_hz;
- rs->bpw = xfer->bits_per_word;
- rs->n_bytes = rs->bpw >> 3;
+ rs->n_bytes = xfer->bits_per_word >> 3;
rs->tx = xfer->tx_buf;
rs->tx_end = rs->tx + xfer->len;
rs->rx = xfer->rx_buf;
rs->rx_end = rs->rx + xfer->len;
- rs->len = xfer->len;
-
- rs->tx_sg = xfer->tx_sg;
- rs->rx_sg = xfer->rx_sg;
-
- if (rs->tx && rs->rx)
- rs->tmode = CR0_XFM_TR;
- else if (rs->tx)
- rs->tmode = CR0_XFM_TO;
- else if (rs->rx)
- rs->tmode = CR0_XFM_RO;
/* we need prepare dma before spi was enabled */
if (master->can_dma && master->can_dma(master, spi, xfer))
@@ -590,10 +569,10 @@ static int rockchip_spi_transfer_one(
else
rs->use_dma = false;
- rockchip_spi_config(rs);
+ rockchip_spi_config(rs, spi, xfer);
if (rs->use_dma)
- return rockchip_spi_prepare_dma(rs);
+ return rockchip_spi_prepare_dma(rs, xfer);
return rockchip_spi_pio_transfer(rs);
}
@@ -685,7 +664,6 @@ static int rockchip_spi_probe(struct platform_device *pdev)
master->bits_per_word_mask = SPI_BPW_MASK(16) | SPI_BPW_MASK(8);
master->set_cs = rockchip_spi_set_cs;
- master->prepare_message = rockchip_spi_prepare_message;
master->transfer_one = rockchip_spi_transfer_one;
master->max_transfer_size = rockchip_spi_max_transfer_size;
master->handle_err = rockchip_spi_handle_err;
--
2.19.1
next prev parent reply other threads:[~2018-10-31 10:58 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-31 10:56 [PATCH v1 00/14] Rockchip SPI cleanup and use interrupts Emil Renner Berthing
2018-10-31 10:56 ` [PATCH v1 01/14] spi: rockchip: make spi_enable_chip take bool Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: make spi_enable_chip take bool" to the spi tree Mark Brown
2018-10-31 10:56 ` [PATCH v1 02/14] spi: rockchip: use designated init for dma config Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: use designated init for dma config" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 03/14] spi: rockchip: always use SPI mode Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: always use SPI mode" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 04/14] spi: rockchip: use atomic_t state Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: use atomic_t state" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 05/14] spi: rockchip: disable spi on error Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: disable spi on error" to the spi tree Mark Brown
2018-10-31 10:57 ` Emil Renner Berthing [this message]
2018-11-05 12:06 ` Applied "spi: rockchip: read transfer info directly" " Mark Brown
2018-10-31 10:57 ` [PATCH v1 07/14] spi: rockchip: don't store dma channels twice Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: don't store dma channels twice" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 08/14] spi: rockchip: remove master pointer from dev data Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: remove master pointer from dev data" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 09/14] spi: rockchip: simplify use_dma logic Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: simplify use_dma logic" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 10/14] spi: rockchip: set min/max speed Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: set min/max speed" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 11/14] spi: rockchip: precompute rx sample delay Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: precompute rx sample delay" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 12/14] spi: rockchip: use irq rather than polling Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: use irq rather than polling" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 13/14] spi: rockchip: support 4bit words Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: support 4bit words" to the spi tree Mark Brown
2018-10-31 10:57 ` [PATCH v1 14/14] spi: rockchip: support lsb-first mode Emil Renner Berthing
2018-11-05 12:06 ` Applied "spi: rockchip: support lsb-first mode" to the spi tree Mark Brown
2018-10-31 11:20 ` [PATCH v1 00/14] Rockchip SPI cleanup and use interrupts Heiko Stübner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181031105711.19575-7-esmil@mailme.dk \
--to=esmil@mailme.dk \
--cc=addy.ke@rock-chips.com \
--cc=broonie@kernel.org \
--cc=heiko@sntech.de \
--cc=kernel@esmil.dk \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).