From: Maxime Chevallier <maxime.chevallier-fqqU8Ppg2Jk@public.gmane.org>
To: Boris Brezillon
<boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>
Cc: "David Woodhouse" <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
"Brian Norris"
<computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"Boris Brezillon"
<boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
"Marek Vasut"
<marek.vasut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"Richard Weinberger" <richard-/L3Ra7n9ekc@public.gmane.org>,
"Cyrille Pitchen"
<cyrille.pitchen-yU5RGvR974pGWvitb5QawA@public.gmane.org>,
linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
"Mark Brown" <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Peter Pan"
<peterpansjtu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"Frieder Schrempf"
<frieder.schrempf-wPoT/lNZgHizQB+pC5nmwQ@public.gmane.org>,
"Vignesh R" <vigneshr-l0cyMroinI0@public.gmane.org>,
"Yogesh Gaur" <yogeshnarayan.gaur-3arQi8VN3Tc@public.gmane.org>,
"Rafał Miłecki" <rafal-g1n6cQUeyibVItvQsEIGlw@public.gmane.org>,
"Kamal Dasu" <kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"Sourav Poddar" <sourav.poddar-l0cyMroinI0@public.gmane.org>
Subject: Re: [RFC PATCH 1/6] spi: Extend the core to ease integration of SPI memory controllers
Date: Tue, 6 Feb 2018 10:43:30 +0100 [thread overview]
Message-ID: <20180206104330.35ffb946@smile-e5570> (raw)
In-Reply-To: <20180205232120.5851-2-boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>
Hi Boris,
> From: Boris Brezillon <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
>
> Some controllers are exposing high-level interfaces to access various
> kind of SPI memories. Unfortunately they do not fit in the current
> spi_controller model and usually have drivers placed in
> drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI
> memories in general.
>
> This is an attempt at defining a SPI memory interface which works for
> all kinds of SPI memories (NORs, NANDs, SRAMs).
>
> Signed-off-by: Boris Brezillon <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
> ---
> drivers/spi/spi.c | 423
> +++++++++++++++++++++++++++++++++++++++++++++++-
> include/linux/spi/spi.h | 226 ++++++++++++++++++++++++++ 2 files
> changed, 646 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index b33a727a0158..57bc540a0521 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -2057,6 +2057,24 @@ static int of_spi_register_master(struct
> spi_controller *ctlr) }
> #endif
>
[...]
> +int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
> +{
> + unsigned int tmpbufsize, xferpos = 0, totalxferlen = 0;
> + struct spi_controller *ctlr = mem->spi->controller;
> + struct spi_transfer xfers[4] = { };
> + struct spi_message msg;
> + u8 *tmpbuf;
> + int ret;
> +
> + if (!spi_mem_supports_op(mem, op))
> + return -ENOTSUPP;
> +
> + if (ctlr->mem_ops) {
> + if (ctlr->auto_runtime_pm) {
> + ret = pm_runtime_get_sync(ctlr->dev.parent);
> + if (ret < 0) {
> + dev_err(&ctlr->dev,
> + "Failed to power device:
> %d\n",
> + ret);
> + return ret;
> + }
> + }
> +
> + mutex_lock(&ctlr->bus_lock_mutex);
> + mutex_lock(&ctlr->io_mutex);
> + ret = ctlr->mem_ops->exec_op(mem, op);
As a user, what prevented me from using spi_flash_read is that it
bypasses the message queue. I have a setup that uses spi_async and I
have to make sure everything goes in the right order, so I ended up
using spi_write_then_read instead.
Is there a way to make so that the message that uses exec_op are issued
in the correct order regarding messages that are already queued ?
Maybe we could extend spi_message or spi_transfer to store all
this opcode/dummy/addr information, so that we would use the standard
interfaces spi_sync / spi_async, and make this mechanism of exec_op
transparent from the user ?
> + mutex_unlock(&ctlr->io_mutex);
> + mutex_unlock(&ctlr->bus_lock_mutex);
> +
> + if (ctlr->auto_runtime_pm)
> + pm_runtime_put(ctlr->dev.parent);
> +
> + /*
> + * Some controllers only optimize specific paths
> (typically the
> + * read path) and expect the core to use the regular
> SPI
> + * interface in these cases.
> + */
> + if (!ret || ret != -ENOTSUPP)
> + return ret;
> + }
> +
> + tmpbufsize = sizeof(op->cmd.opcode) + op->addr.nbytes +
> + op->dummy.nbytes;
> +
> + /*
> + * Allocate a buffer to transmit the CMD, ADDR cycles with
> kmalloc() so
> + * we're guaranteed that this buffer is DMA-able, as
> required by the
> + * SPI layer.
> + */
> + tmpbuf = kzalloc(tmpbufsize, GFP_KERNEL | GFP_DMA);
> + if (!tmpbuf)
> + return -ENOMEM;
> +
> + spi_message_init(&msg);
> +
> + tmpbuf[0] = op->cmd.opcode;
> + xfers[xferpos].tx_buf = tmpbuf;
> + xfers[xferpos].len = sizeof(op->cmd.opcode);
> + xfers[xferpos].tx_nbits = op->cmd.buswidth;
> + spi_message_add_tail(&xfers[xferpos], &msg);
> + xferpos++;
> + totalxferlen++;
> +
> + if (op->addr.nbytes) {
> + memcpy(tmpbuf + 1, op->addr.buf, op->addr.nbytes);
> + xfers[xferpos].tx_buf = tmpbuf + 1;
> + xfers[xferpos].len = op->addr.nbytes;
> + xfers[xferpos].tx_nbits = op->addr.buswidth;
> + spi_message_add_tail(&xfers[xferpos], &msg);
> + xferpos++;
> + totalxferlen += op->addr.nbytes;
> + }
> +
> + if (op->dummy.nbytes) {
> + memset(tmpbuf + op->addr.nbytes + 1, 0xff,
> op->dummy.nbytes);
> + xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
> + xfers[xferpos].len = op->dummy.nbytes;
> + xfers[xferpos].tx_nbits = op->dummy.buswidth;
> + spi_message_add_tail(&xfers[xferpos], &msg);
> + xferpos++;
> + totalxferlen += op->dummy.nbytes;
> + }
Can't we use just one xfer for all the opcode, addr and dummy bytes ?
> + if (op->data.nbytes) {
> + if (op->data.dir == SPI_MEM_DATA_IN) {
> + xfers[xferpos].rx_buf = op->data.buf.in;
> + xfers[xferpos].rx_nbits = op->data.buswidth;
> + } else {
> + xfers[xferpos].tx_buf = op->data.buf.out;
> + xfers[xferpos].tx_nbits = op->data.buswidth;
> + }
> +
> + xfers[xferpos].len = op->data.nbytes;
> + spi_message_add_tail(&xfers[xferpos], &msg);
> + xferpos++;
> + totalxferlen += op->data.nbytes;
> + }
> +
> + ret = spi_sync(mem->spi, &msg);
> +
> + kfree(tmpbuf);
> +
> + if (ret)
> + return ret;
> +
> + if (msg.actual_length != totalxferlen)
> + return -EIO;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(spi_mem_exec_op);
[...]
Thanks,
Maxime
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-02-06 9:43 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-05 23:21 [RFC PATCH 0/6] spi: Extend the framework to generically support memory devices Boris Brezillon
[not found] ` <20180205232120.5851-1-boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>
2018-02-05 23:21 ` [RFC PATCH 1/6] spi: Extend the core to ease integration of SPI memory controllers Boris Brezillon
[not found] ` <20180205232120.5851-2-boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>
2018-02-06 9:43 ` Maxime Chevallier [this message]
2018-02-06 10:25 ` Boris Brezillon
2018-02-06 12:06 ` Mark Brown
2018-02-09 12:52 ` Miquel Raynal
2018-02-11 16:00 ` Boris Brezillon
2018-02-12 11:50 ` Vignesh R
[not found] ` <40a44152-e62c-d57e-7646-7699301c29cc-l0cyMroinI0@public.gmane.org>
2018-02-12 12:28 ` Boris Brezillon
2018-02-28 7:51 ` Peter Pan
2018-02-28 12:25 ` Boris Brezillon
2018-03-04 21:15 ` Cyrille Pitchen
2018-03-05 9:00 ` Boris Brezillon
2018-03-05 13:01 ` Cyrille Pitchen
2018-03-05 13:47 ` Boris Brezillon
2018-03-08 14:07 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 2/6] spi: bcm-qspi: Implement the spi_mem interface Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 3/6] spi: bcm53xx: " Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 4/6] spi: ti-qspi: " Boris Brezillon
[not found] ` <20180205232120.5851-5-boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>
2018-02-11 15:17 ` Miquel Raynal
2018-02-11 17:18 ` Boris Brezillon
2018-02-12 7:54 ` Miquel Raynal
2018-02-12 11:43 ` Vignesh R
[not found] ` <6a9eaaaf-20a6-b332-03d0-9d16e24d0b3d-l0cyMroinI0@public.gmane.org>
2018-02-12 12:31 ` Boris Brezillon
2018-02-12 16:00 ` Vignesh R
[not found] ` <67e61203-a2e9-853c-6cda-7226499611c2-l0cyMroinI0@public.gmane.org>
2018-02-12 16:08 ` Boris Brezillon
2018-02-14 16:25 ` Vignesh R
[not found] ` <0944fefa-6ef8-a93a-dad6-660044b8ec8e-l0cyMroinI0@public.gmane.org>
2018-02-14 19:09 ` Boris Brezillon
2018-02-14 20:44 ` Schrempf Frieder
[not found] ` <561c779b-28b1-ac8a-6b27-46b5ac59344b-wPoT/lNZgHizQB+pC5nmwQ@public.gmane.org>
2018-02-14 21:00 ` Boris Brezillon
2018-02-15 16:38 ` Schrempf Frieder
2018-02-17 11:01 ` Vignesh R
[not found] ` <55878296-f1c9-434b-3c7e-e2f03f5824a9-l0cyMroinI0@public.gmane.org>
2018-02-17 21:52 ` Boris Brezillon
2018-02-16 10:25 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 5/6] mtd: spi-nor: Use the spi_mem_xx() API Boris Brezillon
[not found] ` <20180205232120.5851-6-boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>
2018-02-12 11:44 ` Vignesh R
[not found] ` <933bd372-8b75-183f-0b03-563cabbbcc68-l0cyMroinI0@public.gmane.org>
2018-02-12 12:32 ` Boris Brezillon
2018-06-11 6:25 ` Yogesh Narayan Gaur
2018-06-11 7:35 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 6/6] spi: Get rid of the spi_flash_read() API Boris Brezillon
[not found] ` <20180205232120.5851-7-boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>
2018-02-16 10:21 ` Vignesh R
[not found] ` <674d7b22-a3ac-e812-04db-aa0acb1671b0-l0cyMroinI0@public.gmane.org>
2018-02-16 10:24 ` Boris Brezillon
[not found] ` <20180219162510.GG32761@sirena.org.uk>
2018-03-04 21:40 ` [RFC PATCH 0/6] spi: Extend the framework to generically support memory devices Cyrille Pitchen
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=20180206104330.35ffb946@smile-e5570 \
--to=maxime.chevallier-fqqu8ppg2jk@public.gmane.org \
--cc=boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org \
--cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=cyrille.pitchen-yU5RGvR974pGWvitb5QawA@public.gmane.org \
--cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=frieder.schrempf-wPoT/lNZgHizQB+pC5nmwQ@public.gmane.org \
--cc=kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=marek.vasut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=peterpansjtu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=rafal-g1n6cQUeyibVItvQsEIGlw@public.gmane.org \
--cc=richard-/L3Ra7n9ekc@public.gmane.org \
--cc=sourav.poddar-l0cyMroinI0@public.gmane.org \
--cc=vigneshr-l0cyMroinI0@public.gmane.org \
--cc=yogeshnarayan.gaur-3arQi8VN3Tc@public.gmane.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).