Thread (58 messages) 58 messages, 7 authors, 2020-02-26

Re: [RFC 04/25] spi: gpio: Implement LSB First bitbang support

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2019-12-12 08:40:44
Also in: linux-leds, linux-spi, lkml

Hi Andreas,

On Thu, Dec 12, 2019 at 4:41 AM Andreas Färber [off-list ref] wrote:
Add support for slave DT property spi-lsb-first, i.e., SPI_LSB_FIRST mode.

Duplicate the inline helpers bitbang_txrx_be_cpha{0,1} as LE versions.
Make checkpatch.pl happy by changing "unsigned" to "unsigned int".

Conditionally call them from all the spi-gpio txrx_word callbacks.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Thanks for your patch!
quoted hunk ↗ jump to hunk
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -135,25 +135,37 @@ static inline int getmiso(const struct spi_device *spi)
 static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi,
                unsigned nsecs, u32 word, u8 bits, unsigned flags)
 {
-       return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
+       if (unlikely(spi->mode & SPI_LSB_FIRST))
+               return bitbang_txrx_le_cpha0(spi, nsecs, 0, flags, word, bits);
+       else
+               return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
 }
Duplicating all functions sounds a bit wasteful to me.

What about reverting the word first, and calling the normal functions?

    if (unlikely(spi->mode & SPI_LSB_FIRST)) {
            if (bits <= 8)
                    word = bitrev8(word) >> (bits - 8);
            else if (bits <= 16)
                    word = bitrev16(word) >> (bits - 16);
            else
                    word = bitrev32(word) >> (bits - 32);
    }
    return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help