1 From 04bb2a031cf95b34b7432dd47b318a932a895b4c Mon Sep 17 00:00:00 2001
2 From: Marek Szyprowski <m.szyprowski@samsung.com>
3 Date: Wed, 30 Jun 2010 14:27:32 -0600
4 Subject: [PATCH] spi/bitbang: add support for SPI_MASTER_NO_{TX, RX} modes
6 This patch adds a new flags argument to bitbang_txrx_be_cpha0 and
7 bitbang_txrx_be_cpha1 transfer functions. This enables support for
8 SPI_MASTER_NO_{TX,RX} transfer modes. The change should have no impact
9 on speed of the existing drivers. bitbank_txrx_* functions are usually
10 inlined into the drivers. When the argument is equal to constant zero,
11 the optimizer would be able to eliminate the dead code (flags checks)
12 easily. Tested on ARM and GCC 4.4.x and in all cases the checks were
13 eliminated in the inlined function.
15 Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com>
16 Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
17 Acked-by: David Brownell <dbrownell@users.sourceforge.net>
18 Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
20 drivers/spi/spi_bitbang_txrx.h | 16 ++++++++++------
21 drivers/spi/spi_butterfly.c | 2 +-
22 drivers/spi/spi_gpio.c | 8 ++++----
23 drivers/spi/spi_lm70llp.c | 2 +-
24 drivers/spi/spi_s3c24xx_gpio.c | 8 ++++----
25 drivers/spi/spi_sh_sci.c | 8 ++++----
26 6 files changed, 24 insertions(+), 20 deletions(-)
28 --- a/drivers/spi/spi_bitbang_txrx.h
29 +++ b/drivers/spi/spi_bitbang_txrx.h
33 bitbang_txrx_be_cpha0(struct spi_device *spi,
34 - unsigned nsecs, unsigned cpol,
35 + unsigned nsecs, unsigned cpol, unsigned flags,
38 /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */
39 @@ -53,7 +53,8 @@ bitbang_txrx_be_cpha0(struct spi_device
40 for (word <<= (32 - bits); likely(bits); bits--) {
42 /* setup MSB (to slave) on trailing edge */
43 - setmosi(spi, word & (1 << 31));
44 + if ((flags & SPI_MASTER_NO_TX) == 0)
45 + setmosi(spi, word & (1 << 31));
46 spidelay(nsecs); /* T(setup) */
49 @@ -61,7 +62,8 @@ bitbang_txrx_be_cpha0(struct spi_device
51 /* sample MSB (from slave) on leading edge */
53 - word |= getmiso(spi);
54 + if ((flags & SPI_MASTER_NO_RX) == 0)
55 + word |= getmiso(spi);
59 @@ -69,7 +71,7 @@ bitbang_txrx_be_cpha0(struct spi_device
62 bitbang_txrx_be_cpha1(struct spi_device *spi,
63 - unsigned nsecs, unsigned cpol,
64 + unsigned nsecs, unsigned cpol, unsigned flags,
67 /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */
68 @@ -79,7 +81,8 @@ bitbang_txrx_be_cpha1(struct spi_device
70 /* setup MSB (to slave) on leading edge */
72 - setmosi(spi, word & (1 << 31));
73 + if ((flags & SPI_MASTER_NO_TX) == 0)
74 + setmosi(spi, word & (1 << 31));
75 spidelay(nsecs); /* T(setup) */
78 @@ -87,7 +90,8 @@ bitbang_txrx_be_cpha1(struct spi_device
80 /* sample MSB (from slave) on trailing edge */
82 - word |= getmiso(spi);
83 + if ((flags & SPI_MASTER_NO_RX) == 0)
84 + word |= getmiso(spi);
88 --- a/drivers/spi/spi_butterfly.c
89 +++ b/drivers/spi/spi_butterfly.c
90 @@ -156,7 +156,7 @@ butterfly_txrx_word_mode0(struct spi_dev
94 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
95 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
98 /*----------------------------------------------------------------------*/
99 --- a/drivers/spi/spi_gpio.c
100 +++ b/drivers/spi/spi_gpio.c
101 @@ -157,25 +157,25 @@ static inline void spidelay(unsigned nse
102 static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi,
103 unsigned nsecs, u32 word, u8 bits)
105 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
106 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
109 static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi,
110 unsigned nsecs, u32 word, u8 bits)
112 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
113 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
116 static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi,
117 unsigned nsecs, u32 word, u8 bits)
119 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
120 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
123 static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
124 unsigned nsecs, u32 word, u8 bits)
126 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
127 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
130 /*----------------------------------------------------------------------*/
131 --- a/drivers/spi/spi_lm70llp.c
132 +++ b/drivers/spi/spi_lm70llp.c
133 @@ -191,7 +191,7 @@ static void lm70_chipselect(struct spi_d
135 static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
137 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
138 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
141 static void spi_lm70llp_attach(struct parport *p)
142 --- a/drivers/spi/spi_s3c24xx_gpio.c
143 +++ b/drivers/spi/spi_s3c24xx_gpio.c
144 @@ -64,25 +64,25 @@ static inline u32 getmiso(struct spi_dev
145 static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi,
146 unsigned nsecs, u32 word, u8 bits)
148 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
149 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
152 static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi,
153 unsigned nsecs, u32 word, u8 bits)
155 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
156 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
159 static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi,
160 unsigned nsecs, u32 word, u8 bits)
162 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
163 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
166 static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi,
167 unsigned nsecs, u32 word, u8 bits)
169 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
170 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
174 --- a/drivers/spi/spi_sh_sci.c
175 +++ b/drivers/spi/spi_sh_sci.c
176 @@ -83,25 +83,25 @@ static inline u32 getmiso(struct spi_dev
177 static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi,
178 unsigned nsecs, u32 word, u8 bits)
180 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
181 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
184 static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi,
185 unsigned nsecs, u32 word, u8 bits)
187 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
188 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
191 static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi,
192 unsigned nsecs, u32 word, u8 bits)
194 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
195 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
198 static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi,
199 unsigned nsecs, u32 word, u8 bits)
201 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
202 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
205 static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
206 --- a/drivers/spi/spi_gpio_old.c
207 +++ b/drivers/spi/spi_gpio_old.c
208 @@ -80,25 +80,25 @@ static inline void do_spidelay(struct sp
209 static u32 spi_gpio_txrx_mode0(struct spi_device *spi,
210 unsigned nsecs, u32 word, u8 bits)
212 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
213 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
216 static u32 spi_gpio_txrx_mode1(struct spi_device *spi,
217 unsigned nsecs, u32 word, u8 bits)
219 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
220 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
223 static u32 spi_gpio_txrx_mode2(struct spi_device *spi,
224 unsigned nsecs, u32 word, u8 bits)
226 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
227 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
230 static u32 spi_gpio_txrx_mode3(struct spi_device *spi,
231 unsigned nsecs, u32 word, u8 bits)
233 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
234 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
237 static void spi_gpio_chipselect(struct spi_device *dev, int on)