[brcm63xx] add support for 'MAGIC' bcm6348-based board
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-2.6.35 / 120-spi-bitbang-norxtx-support.patch
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
5
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.
14
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>
19 ---
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(-)
27
28 --- a/drivers/spi/spi_bitbang_txrx.h
29 +++ b/drivers/spi/spi_bitbang_txrx.h
30 @@ -44,7 +44,7 @@
31
32 static inline u32
33 bitbang_txrx_be_cpha0(struct spi_device *spi,
34 - unsigned nsecs, unsigned cpol,
35 + unsigned nsecs, unsigned cpol, unsigned flags,
36 u32 word, u8 bits)
37 {
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--) {
41
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) */
47
48 setsck(spi, !cpol);
49 @@ -61,7 +62,8 @@ bitbang_txrx_be_cpha0(struct spi_device
50
51 /* sample MSB (from slave) on leading edge */
52 word <<= 1;
53 - word |= getmiso(spi);
54 + if ((flags & SPI_MASTER_NO_RX) == 0)
55 + word |= getmiso(spi);
56 setsck(spi, cpol);
57 }
58 return word;
59 @@ -69,7 +71,7 @@ bitbang_txrx_be_cpha0(struct spi_device
60
61 static inline u32
62 bitbang_txrx_be_cpha1(struct spi_device *spi,
63 - unsigned nsecs, unsigned cpol,
64 + unsigned nsecs, unsigned cpol, unsigned flags,
65 u32 word, u8 bits)
66 {
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
69
70 /* setup MSB (to slave) on leading edge */
71 setsck(spi, !cpol);
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) */
76
77 setsck(spi, cpol);
78 @@ -87,7 +90,8 @@ bitbang_txrx_be_cpha1(struct spi_device
79
80 /* sample MSB (from slave) on trailing edge */
81 word <<= 1;
82 - word |= getmiso(spi);
83 + if ((flags & SPI_MASTER_NO_RX) == 0)
84 + word |= getmiso(spi);
85 }
86 return word;
87 }
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
91 unsigned nsecs,
92 u32 word, u8 bits)
93 {
94 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
95 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
96 }
97
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)
104 {
105 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
106 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
107 }
108
109 static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi,
110 unsigned nsecs, u32 word, u8 bits)
111 {
112 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
113 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
114 }
115
116 static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi,
117 unsigned nsecs, u32 word, u8 bits)
118 {
119 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
120 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
121 }
122
123 static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
124 unsigned nsecs, u32 word, u8 bits)
125 {
126 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
127 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
128 }
129
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
134 */
135 static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
136 {
137 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
138 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
139 }
140
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)
147 {
148 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
149 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
150 }
151
152 static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi,
153 unsigned nsecs, u32 word, u8 bits)
154 {
155 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
156 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
157 }
158
159 static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi,
160 unsigned nsecs, u32 word, u8 bits)
161 {
162 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
163 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
164 }
165
166 static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi,
167 unsigned nsecs, u32 word, u8 bits)
168 {
169 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
170 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
171 }
172
173
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)
179 {
180 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
181 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
182 }
183
184 static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi,
185 unsigned nsecs, u32 word, u8 bits)
186 {
187 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
188 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
189 }
190
191 static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi,
192 unsigned nsecs, u32 word, u8 bits)
193 {
194 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
195 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
196 }
197
198 static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi,
199 unsigned nsecs, u32 word, u8 bits)
200 {
201 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
202 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
203 }
204
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)
211 {
212 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
213 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
214 }
215
216 static u32 spi_gpio_txrx_mode1(struct spi_device *spi,
217 unsigned nsecs, u32 word, u8 bits)
218 {
219 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
220 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
221 }
222
223 static u32 spi_gpio_txrx_mode2(struct spi_device *spi,
224 unsigned nsecs, u32 word, u8 bits)
225 {
226 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
227 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
228 }
229
230 static u32 spi_gpio_txrx_mode3(struct spi_device *spi,
231 unsigned nsecs, u32 word, u8 bits)
232 {
233 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
234 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
235 }
236
237 static void spi_gpio_chipselect(struct spi_device *dev, int on)