Commit 304d3436 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Mark Brown

spi: add flags parameter to txrx_word function pointers

Add the capability to specify the flag parameter used in
bitbang_txrx_be_cpha{0,1} through the txrx_word function pointers of
spi_bitbang data structure. That feature will be used to add spi-3wire
support to the spi-gpio controller
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5ba155a4
...@@ -176,7 +176,7 @@ static void ath79_spi_cleanup(struct spi_device *spi) ...@@ -176,7 +176,7 @@ static void ath79_spi_cleanup(struct spi_device *spi)
} }
static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned int nsecs, static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned int nsecs,
u32 word, u8 bits) u32 word, u8 bits, unsigned flags)
{ {
struct ath79_spi *sp = ath79_spidev_to_sp(spi); struct ath79_spi *sp = ath79_spidev_to_sp(spi);
u32 ioc = sp->ioc_base; u32 ioc = sp->ioc_base;
......
...@@ -49,22 +49,26 @@ ...@@ -49,22 +49,26 @@
struct spi_bitbang_cs { struct spi_bitbang_cs {
unsigned nsecs; /* (clock cycle time)/2 */ unsigned nsecs; /* (clock cycle time)/2 */
u32 (*txrx_word)(struct spi_device *spi, unsigned nsecs, u32 (*txrx_word)(struct spi_device *spi, unsigned nsecs,
u32 word, u8 bits); u32 word, u8 bits, unsigned flags);
unsigned (*txrx_bufs)(struct spi_device *, unsigned (*txrx_bufs)(struct spi_device *,
u32 (*txrx_word)( u32 (*txrx_word)(
struct spi_device *spi, struct spi_device *spi,
unsigned nsecs, unsigned nsecs,
u32 word, u8 bits), u32 word, u8 bits,
unsigned, struct spi_transfer *); unsigned flags),
unsigned, struct spi_transfer *,
unsigned);
}; };
static unsigned bitbang_txrx_8( static unsigned bitbang_txrx_8(
struct spi_device *spi, struct spi_device *spi,
u32 (*txrx_word)(struct spi_device *spi, u32 (*txrx_word)(struct spi_device *spi,
unsigned nsecs, unsigned nsecs,
u32 word, u8 bits), u32 word, u8 bits,
unsigned flags),
unsigned ns, unsigned ns,
struct spi_transfer *t struct spi_transfer *t,
unsigned flags
) { ) {
unsigned bits = t->bits_per_word; unsigned bits = t->bits_per_word;
unsigned count = t->len; unsigned count = t->len;
...@@ -76,7 +80,7 @@ static unsigned bitbang_txrx_8( ...@@ -76,7 +80,7 @@ static unsigned bitbang_txrx_8(
if (tx) if (tx)
word = *tx++; word = *tx++;
word = txrx_word(spi, ns, word, bits); word = txrx_word(spi, ns, word, bits, flags);
if (rx) if (rx)
*rx++ = word; *rx++ = word;
count -= 1; count -= 1;
...@@ -88,9 +92,11 @@ static unsigned bitbang_txrx_16( ...@@ -88,9 +92,11 @@ static unsigned bitbang_txrx_16(
struct spi_device *spi, struct spi_device *spi,
u32 (*txrx_word)(struct spi_device *spi, u32 (*txrx_word)(struct spi_device *spi,
unsigned nsecs, unsigned nsecs,
u32 word, u8 bits), u32 word, u8 bits,
unsigned flags),
unsigned ns, unsigned ns,
struct spi_transfer *t struct spi_transfer *t,
unsigned flags
) { ) {
unsigned bits = t->bits_per_word; unsigned bits = t->bits_per_word;
unsigned count = t->len; unsigned count = t->len;
...@@ -102,7 +108,7 @@ static unsigned bitbang_txrx_16( ...@@ -102,7 +108,7 @@ static unsigned bitbang_txrx_16(
if (tx) if (tx)
word = *tx++; word = *tx++;
word = txrx_word(spi, ns, word, bits); word = txrx_word(spi, ns, word, bits, flags);
if (rx) if (rx)
*rx++ = word; *rx++ = word;
count -= 2; count -= 2;
...@@ -114,9 +120,11 @@ static unsigned bitbang_txrx_32( ...@@ -114,9 +120,11 @@ static unsigned bitbang_txrx_32(
struct spi_device *spi, struct spi_device *spi,
u32 (*txrx_word)(struct spi_device *spi, u32 (*txrx_word)(struct spi_device *spi,
unsigned nsecs, unsigned nsecs,
u32 word, u8 bits), u32 word, u8 bits,
unsigned flags),
unsigned ns, unsigned ns,
struct spi_transfer *t struct spi_transfer *t,
unsigned flags
) { ) {
unsigned bits = t->bits_per_word; unsigned bits = t->bits_per_word;
unsigned count = t->len; unsigned count = t->len;
...@@ -128,7 +136,7 @@ static unsigned bitbang_txrx_32( ...@@ -128,7 +136,7 @@ static unsigned bitbang_txrx_32(
if (tx) if (tx)
word = *tx++; word = *tx++;
word = txrx_word(spi, ns, word, bits); word = txrx_word(spi, ns, word, bits, flags);
if (rx) if (rx)
*rx++ = word; *rx++ = word;
count -= 4; count -= 4;
...@@ -236,7 +244,7 @@ static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t) ...@@ -236,7 +244,7 @@ static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)
struct spi_bitbang_cs *cs = spi->controller_state; struct spi_bitbang_cs *cs = spi->controller_state;
unsigned nsecs = cs->nsecs; unsigned nsecs = cs->nsecs;
return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t); return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t, 0);
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
......
...@@ -144,9 +144,9 @@ static void butterfly_chipselect(struct spi_device *spi, int value) ...@@ -144,9 +144,9 @@ static void butterfly_chipselect(struct spi_device *spi, int value)
static u32 static u32
butterfly_txrx_word_mode0(struct spi_device *spi, unsigned nsecs, u32 word, butterfly_txrx_word_mode0(struct spi_device *spi, unsigned nsecs, u32 word,
u8 bits) u8 bits, unsigned flags)
{ {
return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
......
...@@ -149,27 +149,27 @@ static inline int getmiso(const struct spi_device *spi) ...@@ -149,27 +149,27 @@ static inline int getmiso(const struct spi_device *spi)
*/ */
static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits, unsigned flags)
{ {
return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
} }
static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits, unsigned flags)
{ {
return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits);
} }
static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits, unsigned flags)
{ {
return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits);
} }
static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits, unsigned flags)
{ {
return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits);
} }
/* /*
...@@ -183,30 +183,30 @@ static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, ...@@ -183,30 +183,30 @@ static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
*/ */
static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi, static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits, unsigned flags)
{ {
unsigned flags = spi->master->flags; flags = spi->master->flags;
return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
} }
static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi, static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits, unsigned flags)
{ {
unsigned flags = spi->master->flags; flags = spi->master->flags;
return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits);
} }
static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi, static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits, unsigned flags)
{ {
unsigned flags = spi->master->flags; flags = spi->master->flags;
return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits);
} }
static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits, unsigned flags)
{ {
unsigned flags = spi->master->flags; flags = spi->master->flags;
return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits);
} }
......
...@@ -188,9 +188,10 @@ static void lm70_chipselect(struct spi_device *spi, int value) ...@@ -188,9 +188,10 @@ static void lm70_chipselect(struct spi_device *spi, int value)
/* /*
* Our actual bitbanger routine. * Our actual bitbanger routine.
*/ */
static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits) static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits,
unsigned flags)
{ {
return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
} }
static void spi_lm70llp_attach(struct parport *p) static void spi_lm70llp_attach(struct parport *p)
......
...@@ -80,27 +80,31 @@ static inline u32 getmiso(struct spi_device *dev) ...@@ -80,27 +80,31 @@ static inline u32 getmiso(struct spi_device *dev)
#include "spi-bitbang-txrx.h" #include "spi-bitbang-txrx.h"
static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi, static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits,
unsigned flags)
{ {
return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
} }
static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi, static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits,
unsigned flags)
{ {
return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits);
} }
static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi, static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits,
unsigned flags)
{ {
return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits);
} }
static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi, static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi,
unsigned nsecs, u32 word, u8 bits) unsigned nsecs, u32 word, u8 bits,
unsigned flags)
{ {
return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits);
} }
static void sh_sci_spi_chipselect(struct spi_device *dev, int value) static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
......
...@@ -54,7 +54,7 @@ static inline void xtfpga_spi_wait_busy(struct xtfpga_spi *xspi) ...@@ -54,7 +54,7 @@ static inline void xtfpga_spi_wait_busy(struct xtfpga_spi *xspi)
} }
static u32 xtfpga_spi_txrx_word(struct spi_device *spi, unsigned nsecs, static u32 xtfpga_spi_txrx_word(struct spi_device *spi, unsigned nsecs,
u32 v, u8 bits) u32 v, u8 bits, unsigned flags)
{ {
struct xtfpga_spi *xspi = spi_master_get_devdata(spi->master); struct xtfpga_spi *xspi = spi_master_get_devdata(spi->master);
......
...@@ -30,7 +30,7 @@ struct spi_bitbang { ...@@ -30,7 +30,7 @@ struct spi_bitbang {
/* txrx_word[SPI_MODE_*]() just looks like a shift register */ /* txrx_word[SPI_MODE_*]() just looks like a shift register */
u32 (*txrx_word[4])(struct spi_device *spi, u32 (*txrx_word[4])(struct spi_device *spi,
unsigned nsecs, unsigned nsecs,
u32 word, u8 bits); u32 word, u8 bits, unsigned flags);
}; };
/* you can call these default bitbang->master methods from your custom /* you can call these default bitbang->master methods from your custom
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment