From: Michael Grzeschik <m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> To: broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org Cc: kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Subject: [PATCH v3] spi: bitbang: only toggle bitchanges Date: Mon, 13 Apr 2015 12:59:30 +0200 [thread overview] Message-ID: <1428922770-16955-1-git-send-email-m.grzeschik@pengutronix.de> (raw) In-Reply-To: <20150331202306.GX2869-GFdadSzt00ze9xe1eoZjHA@public.gmane.org> The current implementation of bitbang_txrx_be_cpha0 and bitbang_txrx_be_cpha1 always call setmosi. That runs into several unnecessary calls into the gpiolib when the level of the GPIO actually has not to be changed. This patch changes the routines to remember the last GPIO level and only calls setmosi if an change has to be made. This way it improves the transfer throughput. Signed-off-by: Michael Grzeschik <m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> --- v2: - added missing braces v3: - fixed initial value of oldbit - added !! to condition for bool comparison drivers/spi/spi-bitbang-txrx.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-bitbang-txrx.h b/drivers/spi/spi-bitbang-txrx.h index c616e41..58606bf 100644 --- a/drivers/spi/spi-bitbang-txrx.h +++ b/drivers/spi/spi-bitbang-txrx.h @@ -49,12 +49,17 @@ bitbang_txrx_be_cpha0(struct spi_device *spi, { /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ + bool oldbit = !(word & (1 << 31)); /* clock starts at inactive polarity */ for (word <<= (32 - bits); likely(bits); bits--) { /* setup MSB (to slave) on trailing edge */ - if ((flags & SPI_MASTER_NO_TX) == 0) - setmosi(spi, word & (1 << 31)); + if ((flags & SPI_MASTER_NO_TX) == 0) { + if (!!(word & (1 << 31)) != oldbit) { + setmosi(spi, word & (1 << 31)); + oldbit = word & (1 << 31); + } + } spidelay(nsecs); /* T(setup) */ setsck(spi, !cpol); @@ -76,13 +81,18 @@ bitbang_txrx_be_cpha1(struct spi_device *spi, { /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */ + bool oldbit = !(word & (1 << 31)); /* clock starts at inactive polarity */ for (word <<= (32 - bits); likely(bits); bits--) { /* setup MSB (to slave) on leading edge */ setsck(spi, !cpol); - if ((flags & SPI_MASTER_NO_TX) == 0) - setmosi(spi, word & (1 << 31)); + if ((flags & SPI_MASTER_NO_TX) == 0) { + if (!!(word & (1 << 31)) != oldbit) { + setmosi(spi, word & (1 << 31)); + oldbit = word & (1 << 31); + } + } spidelay(nsecs); /* T(setup) */ setsck(spi, cpol); -- 2.1.4 -- 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
WARNING: multiple messages have this Message-ID (diff)
From: m.grzeschik@pengutronix.de (Michael Grzeschik) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3] spi: bitbang: only toggle bitchanges Date: Mon, 13 Apr 2015 12:59:30 +0200 [thread overview] Message-ID: <1428922770-16955-1-git-send-email-m.grzeschik@pengutronix.de> (raw) In-Reply-To: <20150331202306.GX2869@sirena.org.uk> The current implementation of bitbang_txrx_be_cpha0 and bitbang_txrx_be_cpha1 always call setmosi. That runs into several unnecessary calls into the gpiolib when the level of the GPIO actually has not to be changed. This patch changes the routines to remember the last GPIO level and only calls setmosi if an change has to be made. This way it improves the transfer throughput. Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> --- v2: - added missing braces v3: - fixed initial value of oldbit - added !! to condition for bool comparison drivers/spi/spi-bitbang-txrx.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-bitbang-txrx.h b/drivers/spi/spi-bitbang-txrx.h index c616e41..58606bf 100644 --- a/drivers/spi/spi-bitbang-txrx.h +++ b/drivers/spi/spi-bitbang-txrx.h @@ -49,12 +49,17 @@ bitbang_txrx_be_cpha0(struct spi_device *spi, { /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ + bool oldbit = !(word & (1 << 31)); /* clock starts at inactive polarity */ for (word <<= (32 - bits); likely(bits); bits--) { /* setup MSB (to slave) on trailing edge */ - if ((flags & SPI_MASTER_NO_TX) == 0) - setmosi(spi, word & (1 << 31)); + if ((flags & SPI_MASTER_NO_TX) == 0) { + if (!!(word & (1 << 31)) != oldbit) { + setmosi(spi, word & (1 << 31)); + oldbit = word & (1 << 31); + } + } spidelay(nsecs); /* T(setup) */ setsck(spi, !cpol); @@ -76,13 +81,18 @@ bitbang_txrx_be_cpha1(struct spi_device *spi, { /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */ + bool oldbit = !(word & (1 << 31)); /* clock starts@inactive polarity */ for (word <<= (32 - bits); likely(bits); bits--) { /* setup MSB (to slave) on leading edge */ setsck(spi, !cpol); - if ((flags & SPI_MASTER_NO_TX) == 0) - setmosi(spi, word & (1 << 31)); + if ((flags & SPI_MASTER_NO_TX) == 0) { + if (!!(word & (1 << 31)) != oldbit) { + setmosi(spi, word & (1 << 31)); + oldbit = word & (1 << 31); + } + } spidelay(nsecs); /* T(setup) */ setsck(spi, cpol); -- 2.1.4
next prev parent reply other threads:[~2015-04-13 10:59 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-03-31 13:54 [PATCH] spi: bitbang: only toggle bitchanges Michael Grzeschik 2015-03-31 13:54 ` Michael Grzeschik [not found] ` <1427810089-14866-1-git-send-email-m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 2015-03-31 14:13 ` Mark Brown 2015-03-31 14:13 ` Mark Brown [not found] ` <20150331141321.GR2869-GFdadSzt00ze9xe1eoZjHA@public.gmane.org> 2015-03-31 14:35 ` [PATCH v2] " Michael Grzeschik 2015-03-31 14:35 ` Michael Grzeschik [not found] ` <1427812501-7194-1-git-send-email-m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 2015-03-31 16:21 ` Mark Brown 2015-03-31 16:21 ` Mark Brown 2015-03-31 18:59 ` Jonas Gorski 2015-03-31 18:59 ` Jonas Gorski [not found] ` <CAOiHx=k_NhSgzUDNPGXLUWN9r9bJ1rbsv3vLg_gFKpuinEqKmA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2015-03-31 20:13 ` Michael Grzeschik 2015-03-31 20:13 ` Michael Grzeschik [not found] ` <20150331201300.GB12253-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 2015-03-31 20:23 ` Mark Brown 2015-03-31 20:23 ` Mark Brown [not found] ` <20150331202306.GX2869-GFdadSzt00ze9xe1eoZjHA@public.gmane.org> 2015-04-13 10:59 ` Michael Grzeschik [this message] 2015-04-13 10:59 ` [PATCH v3] " Michael Grzeschik [not found] ` <1428922770-16955-1-git-send-email-m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 2015-04-18 12:09 ` Mark Brown 2015-04-18 12:09 ` Mark Brown [not found] ` <20150418120926.GL26185-GFdadSzt00ze9xe1eoZjHA@public.gmane.org> 2015-04-18 13:18 ` Marc Kleine-Budde 2015-04-18 13:18 ` Marc Kleine-Budde [not found] ` <db1d2b9a-730b-40a5-a4f6-091fd3fad0e7-2ueSQiBKiTY7tOexoI0I+QC/G2K4zDHf@public.gmane.org> 2015-04-18 17:16 ` Mark Brown 2015-04-18 17:16 ` Mark Brown
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=1428922770-16955-1-git-send-email-m.grzeschik@pengutronix.de \ --to=m.grzeschik-bicnvbalz9megne8c9+irq@public.gmane.org \ --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \ --cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \ --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \ --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.