Commit 04bb2a031cf95b34b7432dd47b318a932a895b4c

Authored by Marek Szyprowski
Committed by Grant Likely
1 parent 5c2818cdfa

spi/bitbang: add support for SPI_MASTER_NO_{TX, RX} modes

This patch adds a new flags argument to bitbang_txrx_be_cpha0 and
bitbang_txrx_be_cpha1 transfer functions. This enables support for
SPI_MASTER_NO_{TX,RX} transfer modes. The change should have no impact
on speed of the existing drivers. bitbank_txrx_* functions are usually
inlined into the drivers. When the argument is equal to constant zero,
the optimizer would be able to eliminate the dead code (flags checks)
easily. Tested on ARM and GCC 4.4.x and in all cases the checks were
eliminated in the inlined function.

Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

Showing 6 changed files with 24 additions and 20 deletions Side-by-side Diff

drivers/spi/spi_bitbang_txrx.h
... ... @@ -44,7 +44,7 @@
44 44  
45 45 static inline u32
46 46 bitbang_txrx_be_cpha0(struct spi_device *spi,
47   - unsigned nsecs, unsigned cpol,
  47 + unsigned nsecs, unsigned cpol, unsigned flags,
48 48 u32 word, u8 bits)
49 49 {
50 50 /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */
... ... @@ -53,7 +53,8 @@
53 53 for (word <<= (32 - bits); likely(bits); bits--) {
54 54  
55 55 /* setup MSB (to slave) on trailing edge */
56   - setmosi(spi, word & (1 << 31));
  56 + if ((flags & SPI_MASTER_NO_TX) == 0)
  57 + setmosi(spi, word & (1 << 31));
57 58 spidelay(nsecs); /* T(setup) */
58 59  
59 60 setsck(spi, !cpol);
... ... @@ -61,7 +62,8 @@
61 62  
62 63 /* sample MSB (from slave) on leading edge */
63 64 word <<= 1;
64   - word |= getmiso(spi);
  65 + if ((flags & SPI_MASTER_NO_RX) == 0)
  66 + word |= getmiso(spi);
65 67 setsck(spi, cpol);
66 68 }
67 69 return word;
... ... @@ -69,7 +71,7 @@
69 71  
70 72 static inline u32
71 73 bitbang_txrx_be_cpha1(struct spi_device *spi,
72   - unsigned nsecs, unsigned cpol,
  74 + unsigned nsecs, unsigned cpol, unsigned flags,
73 75 u32 word, u8 bits)
74 76 {
75 77 /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */
... ... @@ -79,7 +81,8 @@
79 81  
80 82 /* setup MSB (to slave) on leading edge */
81 83 setsck(spi, !cpol);
82   - setmosi(spi, word & (1 << 31));
  84 + if ((flags & SPI_MASTER_NO_TX) == 0)
  85 + setmosi(spi, word & (1 << 31));
83 86 spidelay(nsecs); /* T(setup) */
84 87  
85 88 setsck(spi, cpol);
... ... @@ -87,7 +90,8 @@
87 90  
88 91 /* sample MSB (from slave) on trailing edge */
89 92 word <<= 1;
90   - word |= getmiso(spi);
  93 + if ((flags & SPI_MASTER_NO_RX) == 0)
  94 + word |= getmiso(spi);
91 95 }
92 96 return word;
93 97 }
drivers/spi/spi_butterfly.c
... ... @@ -156,7 +156,7 @@
156 156 unsigned nsecs,
157 157 u32 word, u8 bits)
158 158 {
159   - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
  159 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
160 160 }
161 161  
162 162 /*----------------------------------------------------------------------*/
drivers/spi/spi_gpio.c
... ... @@ -146,25 +146,25 @@
146 146 static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi,
147 147 unsigned nsecs, u32 word, u8 bits)
148 148 {
149   - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
  149 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
150 150 }
151 151  
152 152 static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi,
153 153 unsigned nsecs, u32 word, u8 bits)
154 154 {
155   - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
  155 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
156 156 }
157 157  
158 158 static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi,
159 159 unsigned nsecs, u32 word, u8 bits)
160 160 {
161   - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
  161 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
162 162 }
163 163  
164 164 static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
165 165 unsigned nsecs, u32 word, u8 bits)
166 166 {
167   - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
  167 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
168 168 }
169 169  
170 170 /*----------------------------------------------------------------------*/
drivers/spi/spi_lm70llp.c
... ... @@ -191,7 +191,7 @@
191 191 */
192 192 static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
193 193 {
194   - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
  194 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
195 195 }
196 196  
197 197 static void spi_lm70llp_attach(struct parport *p)
drivers/spi/spi_s3c24xx_gpio.c
... ... @@ -64,25 +64,25 @@
64 64 static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi,
65 65 unsigned nsecs, u32 word, u8 bits)
66 66 {
67   - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
  67 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
68 68 }
69 69  
70 70 static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi,
71 71 unsigned nsecs, u32 word, u8 bits)
72 72 {
73   - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
  73 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
74 74 }
75 75  
76 76 static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi,
77 77 unsigned nsecs, u32 word, u8 bits)
78 78 {
79   - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
  79 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
80 80 }
81 81  
82 82 static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi,
83 83 unsigned nsecs, u32 word, u8 bits)
84 84 {
85   - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
  85 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
86 86 }
87 87  
88 88  
drivers/spi/spi_sh_sci.c
... ... @@ -83,25 +83,25 @@
83 83 static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi,
84 84 unsigned nsecs, u32 word, u8 bits)
85 85 {
86   - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
  86 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
87 87 }
88 88  
89 89 static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi,
90 90 unsigned nsecs, u32 word, u8 bits)
91 91 {
92   - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
  92 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
93 93 }
94 94  
95 95 static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi,
96 96 unsigned nsecs, u32 word, u8 bits)
97 97 {
98   - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
  98 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
99 99 }
100 100  
101 101 static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi,
102 102 unsigned nsecs, u32 word, u8 bits)
103 103 {
104   - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
  104 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
105 105 }
106 106  
107 107 static void sh_sci_spi_chipselect(struct spi_device *dev, int value)