From: Gerhard Sittig <gsi-ynQEQJNshbs@public.gmane.org>
To: Michael Grzeschik <m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
linux-arm-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org
Subject: Re: [PATCH 2/3] spi: bitbang: add lsb first support
Date: Wed, 12 Mar 2014 22:29:41 +0100 [thread overview]
Message-ID: <20140312212941.GP3327@book.gsilab.sittig.org> (raw)
In-Reply-To: <1394637636-29042-3-git-send-email-m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
On Wed, Mar 12, 2014 at 16:20 +0100, Michael Grzeschik wrote:
>
> The bitbang spi driver currently only supports the MSB mode. This patch
> adds the possibility to clock the data in LSB mode.
>
> Signed-off-by: Michael Grzeschik <m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> ---
> drivers/spi/spi-bitbang-txrx.h | 98 +++++++++++++++++++++++++++++-------------
> drivers/spi/spi-bitbang.c | 3 +-
> 2 files changed, 71 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/spi/spi-bitbang-txrx.h b/drivers/spi/spi-bitbang-txrx.h
> index b6e348d..7f9c020 100644
> --- a/drivers/spi/spi-bitbang-txrx.h
> +++ b/drivers/spi/spi-bitbang-txrx.h
> @@ -49,22 +49,42 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,
> {
> /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */
>
> - /* 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));
> - spidelay(nsecs); /* T(setup) */
> -
> - setsck(spi, !cpol);
> - spidelay(nsecs);
> -
> - /* sample MSB (from slave) on leading edge */
> - if ((flags & SPI_MASTER_NO_RX) == 0)
> - word |= getmiso(spi);
> - setsck(spi, cpol);
> - word <<= 1;
> + if (spi->mode & SPI_LSB_FIRST) {
> + /* clock starts at inactive polarity */
> + for (; likely(bits); bits--) {
> +
> + /* setup MSB (to slave) on trailing edge */
> + if ((flags & SPI_MASTER_NO_TX) == 0)
> + setmosi(spi, word & 1);
> + spidelay(nsecs); /* T(setup) */
> +
> + setsck(spi, !cpol);
> + spidelay(nsecs);
> +
> + /* sample LSB (from slave) on leading edge */
> + if ((flags & SPI_MASTER_NO_RX) == 0)
> + word |= getmiso(spi);
> + setsck(spi, cpol);
> + word >>= 1;
> + }
> + } else {
> + /* 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));
> + spidelay(nsecs); /* T(setup) */
> +
> + setsck(spi, !cpol);
> + spidelay(nsecs);
> +
> + /* sample MSB (from slave) on leading edge */
> + if ((flags & SPI_MASTER_NO_RX) == 0)
> + word |= getmiso(spi);
> + setsck(spi, cpol);
> + word <<= 1;
> + }
> }
> return word;
> }
Would it be useful to not duplicate the transmission logic, but
instead to optionally "bit swap" the TX and RX data before and
after the common transmission logic? Just a though whether this
might help maintenance. There might even be existing and proven
code to bit swap integers?
virtually yours
Gerhard Sittig
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office-ynQEQJNshbs@public.gmane.org
--
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:[~2014-03-12 21:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-12 15:20 [PATCH 0/3] spi: bitbang fixes and passive serial driver Michael Grzeschik
[not found] ` <1394637636-29042-1-git-send-email-m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2014-03-12 15:20 ` [PATCH 1/3] spi: bitbang: fix shift for getmosi Michael Grzeschik
[not found] ` <1394637636-29042-2-git-send-email-m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2014-03-12 21:23 ` Gerhard Sittig
2014-03-12 21:37 ` Mark Brown
2014-03-12 15:20 ` [PATCH 2/3] spi: bitbang: add lsb first support Michael Grzeschik
[not found] ` <1394637636-29042-3-git-send-email-m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2014-03-12 21:29 ` Gerhard Sittig [this message]
[not found] ` <20140312212941.GP3327-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2014-03-12 21:35 ` Mark Brown
[not found] ` <20140312213544.GX28112-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-03-13 18:11 ` Gerhard Sittig
[not found] ` <20140313181107.GT3327-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2014-03-13 18:41 ` Mark Brown
2014-03-13 19:22 ` Geert Uytterhoeven
2014-03-12 15:20 ` [PATCH 3/3] spi: psdev: add passive serial driver Michael Grzeschik
2014-03-12 15:42 ` [PATCH 0/3] spi: bitbang fixes and " Michael Grzeschik
-- strict thread matches above, loose matches on Subject: below --
2014-03-12 15:53 Michael Grzeschik
[not found] ` <1394639617-26917-1-git-send-email-m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2014-03-12 15:53 ` [PATCH 2/3] spi: bitbang: add lsb first support Michael Grzeschik
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=20140312212941.GP3327@book.gsilab.sittig.org \
--to=gsi-ynqeqjnshbs@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=linux-arm-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@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).