aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/spi/spi_sh_msiof.c127
-rw-r--r--drivers/spi/spidev.c12
2 files changed, 105 insertions, 34 deletions
diff --git a/drivers/spi/spi_sh_msiof.c b/drivers/spi/spi_sh_msiof.c
index 56f60c8ea0ab..da6e42ec856e 100644
--- a/drivers/spi/spi_sh_msiof.c
+++ b/drivers/spi/spi_sh_msiof.c
@@ -9,22 +9,22 @@
9 * 9 *
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/bitmap.h>
13#include <linux/init.h> 13#include <linux/clk.h>
14#include <linux/completion.h>
14#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/init.h>
15#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/io.h>
21#include <linux/kernel.h>
16#include <linux/platform_device.h> 22#include <linux/platform_device.h>
17#include <linux/completion.h>
18#include <linux/pm_runtime.h> 23#include <linux/pm_runtime.h>
19#include <linux/gpio.h>
20#include <linux/bitmap.h>
21#include <linux/clk.h>
22#include <linux/io.h>
23#include <linux/err.h>
24 24
25#include <linux/spi/sh_msiof.h>
25#include <linux/spi/spi.h> 26#include <linux/spi/spi.h>
26#include <linux/spi/spi_bitbang.h> 27#include <linux/spi/spi_bitbang.h>
27#include <linux/spi/sh_msiof.h>
28 28
29#include <asm/unaligned.h> 29#include <asm/unaligned.h>
30 30
@@ -67,7 +67,7 @@ struct sh_msiof_spi_priv {
67#define STR_TEOF (1 << 23) 67#define STR_TEOF (1 << 23)
68#define STR_REOF (1 << 7) 68#define STR_REOF (1 << 7)
69 69
70static unsigned long sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs) 70static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs)
71{ 71{
72 switch (reg_offs) { 72 switch (reg_offs) {
73 case TSCR: 73 case TSCR:
@@ -79,7 +79,7 @@ static unsigned long sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs)
79} 79}
80 80
81static void sh_msiof_write(struct sh_msiof_spi_priv *p, int reg_offs, 81static void sh_msiof_write(struct sh_msiof_spi_priv *p, int reg_offs,
82 unsigned long value) 82 u32 value)
83{ 83{
84 switch (reg_offs) { 84 switch (reg_offs) {
85 case TSCR: 85 case TSCR:
@@ -93,10 +93,10 @@ static void sh_msiof_write(struct sh_msiof_spi_priv *p, int reg_offs,
93} 93}
94 94
95static int sh_msiof_modify_ctr_wait(struct sh_msiof_spi_priv *p, 95static int sh_msiof_modify_ctr_wait(struct sh_msiof_spi_priv *p,
96 unsigned long clr, unsigned long set) 96 u32 clr, u32 set)
97{ 97{
98 unsigned long mask = clr | set; 98 u32 mask = clr | set;
99 unsigned long data; 99 u32 data;
100 int k; 100 int k;
101 101
102 data = sh_msiof_read(p, CTR); 102 data = sh_msiof_read(p, CTR);
@@ -166,10 +166,10 @@ static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
166} 166}
167 167
168static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, 168static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p,
169 int cpol, int cpha, 169 u32 cpol, u32 cpha,
170 int tx_hi_z, int lsb_first) 170 u32 tx_hi_z, u32 lsb_first)
171{ 171{
172 unsigned long tmp; 172 u32 tmp;
173 int edge; 173 int edge;
174 174
175 /* 175 /*
@@ -187,7 +187,7 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p,
187 tmp |= cpol << 30; /* TSCKIZ */ 187 tmp |= cpol << 30; /* TSCKIZ */
188 tmp |= cpol << 28; /* RSCKIZ */ 188 tmp |= cpol << 28; /* RSCKIZ */
189 189
190 edge = cpol ? cpha : !cpha; 190 edge = cpol ^ !cpha;
191 191
192 tmp |= edge << 27; /* TEDG */ 192 tmp |= edge << 27; /* TEDG */
193 tmp |= edge << 26; /* REDG */ 193 tmp |= edge << 26; /* REDG */
@@ -197,11 +197,9 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p,
197 197
198static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p, 198static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,
199 const void *tx_buf, void *rx_buf, 199 const void *tx_buf, void *rx_buf,
200 int bits, int words) 200 u32 bits, u32 words)
201{ 201{
202 unsigned long dr2; 202 u32 dr2 = ((bits - 1) << 24) | ((words - 1) << 16);
203
204 dr2 = ((bits - 1) << 24) | ((words - 1) << 16);
205 203
206 if (tx_buf) 204 if (tx_buf)
207 sh_msiof_write(p, TMDR2, dr2); 205 sh_msiof_write(p, TMDR2, dr2);
@@ -222,7 +220,7 @@ static void sh_msiof_reset_str(struct sh_msiof_spi_priv *p)
222static void sh_msiof_spi_write_fifo_8(struct sh_msiof_spi_priv *p, 220static void sh_msiof_spi_write_fifo_8(struct sh_msiof_spi_priv *p,
223 const void *tx_buf, int words, int fs) 221 const void *tx_buf, int words, int fs)
224{ 222{
225 const unsigned char *buf_8 = tx_buf; 223 const u8 *buf_8 = tx_buf;
226 int k; 224 int k;
227 225
228 for (k = 0; k < words; k++) 226 for (k = 0; k < words; k++)
@@ -232,7 +230,7 @@ static void sh_msiof_spi_write_fifo_8(struct sh_msiof_spi_priv *p,
232static void sh_msiof_spi_write_fifo_16(struct sh_msiof_spi_priv *p, 230static void sh_msiof_spi_write_fifo_16(struct sh_msiof_spi_priv *p,
233 const void *tx_buf, int words, int fs) 231 const void *tx_buf, int words, int fs)
234{ 232{
235 const unsigned short *buf_16 = tx_buf; 233 const u16 *buf_16 = tx_buf;
236 int k; 234 int k;
237 235
238 for (k = 0; k < words; k++) 236 for (k = 0; k < words; k++)
@@ -242,7 +240,7 @@ static void sh_msiof_spi_write_fifo_16(struct sh_msiof_spi_priv *p,
242static void sh_msiof_spi_write_fifo_16u(struct sh_msiof_spi_priv *p, 240static void sh_msiof_spi_write_fifo_16u(struct sh_msiof_spi_priv *p,
243 const void *tx_buf, int words, int fs) 241 const void *tx_buf, int words, int fs)
244{ 242{
245 const unsigned short *buf_16 = tx_buf; 243 const u16 *buf_16 = tx_buf;
246 int k; 244 int k;
247 245
248 for (k = 0; k < words; k++) 246 for (k = 0; k < words; k++)
@@ -252,7 +250,7 @@ static void sh_msiof_spi_write_fifo_16u(struct sh_msiof_spi_priv *p,
252static void sh_msiof_spi_write_fifo_32(struct sh_msiof_spi_priv *p, 250static void sh_msiof_spi_write_fifo_32(struct sh_msiof_spi_priv *p,
253 const void *tx_buf, int words, int fs) 251 const void *tx_buf, int words, int fs)
254{ 252{
255 const unsigned int *buf_32 = tx_buf; 253 const u32 *buf_32 = tx_buf;
256 int k; 254 int k;
257 255
258 for (k = 0; k < words; k++) 256 for (k = 0; k < words; k++)
@@ -262,17 +260,37 @@ static void sh_msiof_spi_write_fifo_32(struct sh_msiof_spi_priv *p,
262static void sh_msiof_spi_write_fifo_32u(struct sh_msiof_spi_priv *p, 260static void sh_msiof_spi_write_fifo_32u(struct sh_msiof_spi_priv *p,
263 const void *tx_buf, int words, int fs) 261 const void *tx_buf, int words, int fs)
264{ 262{
265 const unsigned int *buf_32 = tx_buf; 263 const u32 *buf_32 = tx_buf;
266 int k; 264 int k;
267 265
268 for (k = 0; k < words; k++) 266 for (k = 0; k < words; k++)
269 sh_msiof_write(p, TFDR, get_unaligned(&buf_32[k]) << fs); 267 sh_msiof_write(p, TFDR, get_unaligned(&buf_32[k]) << fs);
270} 268}
271 269
270static void sh_msiof_spi_write_fifo_s32(struct sh_msiof_spi_priv *p,
271 const void *tx_buf, int words, int fs)
272{
273 const u32 *buf_32 = tx_buf;
274 int k;
275
276 for (k = 0; k < words; k++)
277 sh_msiof_write(p, TFDR, swab32(buf_32[k] << fs));
278}
279
280static void sh_msiof_spi_write_fifo_s32u(struct sh_msiof_spi_priv *p,
281 const void *tx_buf, int words, int fs)
282{
283 const u32 *buf_32 = tx_buf;
284 int k;
285
286 for (k = 0; k < words; k++)
287 sh_msiof_write(p, TFDR, swab32(get_unaligned(&buf_32[k]) << fs));
288}
289
272static void sh_msiof_spi_read_fifo_8(struct sh_msiof_spi_priv *p, 290static void sh_msiof_spi_read_fifo_8(struct sh_msiof_spi_priv *p,
273 void *rx_buf, int words, int fs) 291 void *rx_buf, int words, int fs)
274{ 292{
275 unsigned char *buf_8 = rx_buf; 293 u8 *buf_8 = rx_buf;
276 int k; 294 int k;
277 295
278 for (k = 0; k < words; k++) 296 for (k = 0; k < words; k++)
@@ -282,7 +300,7 @@ static void sh_msiof_spi_read_fifo_8(struct sh_msiof_spi_priv *p,
282static void sh_msiof_spi_read_fifo_16(struct sh_msiof_spi_priv *p, 300static void sh_msiof_spi_read_fifo_16(struct sh_msiof_spi_priv *p,
283 void *rx_buf, int words, int fs) 301 void *rx_buf, int words, int fs)
284{ 302{
285 unsigned short *buf_16 = rx_buf; 303 u16 *buf_16 = rx_buf;
286 int k; 304 int k;
287 305
288 for (k = 0; k < words; k++) 306 for (k = 0; k < words; k++)
@@ -292,7 +310,7 @@ static void sh_msiof_spi_read_fifo_16(struct sh_msiof_spi_priv *p,
292static void sh_msiof_spi_read_fifo_16u(struct sh_msiof_spi_priv *p, 310static void sh_msiof_spi_read_fifo_16u(struct sh_msiof_spi_priv *p,
293 void *rx_buf, int words, int fs) 311 void *rx_buf, int words, int fs)
294{ 312{
295 unsigned short *buf_16 = rx_buf; 313 u16 *buf_16 = rx_buf;
296 int k; 314 int k;
297 315
298 for (k = 0; k < words; k++) 316 for (k = 0; k < words; k++)
@@ -302,7 +320,7 @@ static void sh_msiof_spi_read_fifo_16u(struct sh_msiof_spi_priv *p,
302static void sh_msiof_spi_read_fifo_32(struct sh_msiof_spi_priv *p, 320static void sh_msiof_spi_read_fifo_32(struct sh_msiof_spi_priv *p,
303 void *rx_buf, int words, int fs) 321 void *rx_buf, int words, int fs)
304{ 322{
305 unsigned int *buf_32 = rx_buf; 323 u32 *buf_32 = rx_buf;
306 int k; 324 int k;
307 325
308 for (k = 0; k < words; k++) 326 for (k = 0; k < words; k++)
@@ -312,19 +330,40 @@ static void sh_msiof_spi_read_fifo_32(struct sh_msiof_spi_priv *p,
312static void sh_msiof_spi_read_fifo_32u(struct sh_msiof_spi_priv *p, 330static void sh_msiof_spi_read_fifo_32u(struct sh_msiof_spi_priv *p,
313 void *rx_buf, int words, int fs) 331 void *rx_buf, int words, int fs)
314{ 332{
315 unsigned int *buf_32 = rx_buf; 333 u32 *buf_32 = rx_buf;
316 int k; 334 int k;
317 335
318 for (k = 0; k < words; k++) 336 for (k = 0; k < words; k++)
319 put_unaligned(sh_msiof_read(p, RFDR) >> fs, &buf_32[k]); 337 put_unaligned(sh_msiof_read(p, RFDR) >> fs, &buf_32[k]);
320} 338}
321 339
340static void sh_msiof_spi_read_fifo_s32(struct sh_msiof_spi_priv *p,
341 void *rx_buf, int words, int fs)
342{
343 u32 *buf_32 = rx_buf;
344 int k;
345
346 for (k = 0; k < words; k++)
347 buf_32[k] = swab32(sh_msiof_read(p, RFDR) >> fs);
348}
349
350static void sh_msiof_spi_read_fifo_s32u(struct sh_msiof_spi_priv *p,
351 void *rx_buf, int words, int fs)
352{
353 u32 *buf_32 = rx_buf;
354 int k;
355
356 for (k = 0; k < words; k++)
357 put_unaligned(swab32(sh_msiof_read(p, RFDR) >> fs), &buf_32[k]);
358}
359
322static int sh_msiof_spi_bits(struct spi_device *spi, struct spi_transfer *t) 360static int sh_msiof_spi_bits(struct spi_device *spi, struct spi_transfer *t)
323{ 361{
324 int bits; 362 int bits;
325 363
326 bits = t ? t->bits_per_word : 0; 364 bits = t ? t->bits_per_word : 0;
327 bits = bits ? bits : spi->bits_per_word; 365 if (!bits)
366 bits = spi->bits_per_word;
328 return bits; 367 return bits;
329} 368}
330 369
@@ -334,7 +373,8 @@ static unsigned long sh_msiof_spi_hz(struct spi_device *spi,
334 unsigned long hz; 373 unsigned long hz;
335 374
336 hz = t ? t->speed_hz : 0; 375 hz = t ? t->speed_hz : 0;
337 hz = hz ? hz : spi->max_speed_hz; 376 if (!hz)
377 hz = spi->max_speed_hz;
338 return hz; 378 return hz;
339} 379}
340 380
@@ -468,9 +508,17 @@ static int sh_msiof_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
468 int bytes_done; 508 int bytes_done;
469 int words; 509 int words;
470 int n; 510 int n;
511 bool swab;
471 512
472 bits = sh_msiof_spi_bits(spi, t); 513 bits = sh_msiof_spi_bits(spi, t);
473 514
515 if (bits <= 8 && t->len > 15 && !(t->len & 3)) {
516 bits = 32;
517 swab = true;
518 } else {
519 swab = false;
520 }
521
474 /* setup bytes per word and fifo read/write functions */ 522 /* setup bytes per word and fifo read/write functions */
475 if (bits <= 8) { 523 if (bits <= 8) {
476 bytes_per_word = 1; 524 bytes_per_word = 1;
@@ -487,6 +535,17 @@ static int sh_msiof_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
487 rx_fifo = sh_msiof_spi_read_fifo_16u; 535 rx_fifo = sh_msiof_spi_read_fifo_16u;
488 else 536 else
489 rx_fifo = sh_msiof_spi_read_fifo_16; 537 rx_fifo = sh_msiof_spi_read_fifo_16;
538 } else if (swab) {
539 bytes_per_word = 4;
540 if ((unsigned long)t->tx_buf & 0x03)
541 tx_fifo = sh_msiof_spi_write_fifo_s32u;
542 else
543 tx_fifo = sh_msiof_spi_write_fifo_s32;
544
545 if ((unsigned long)t->rx_buf & 0x03)
546 rx_fifo = sh_msiof_spi_read_fifo_s32u;
547 else
548 rx_fifo = sh_msiof_spi_read_fifo_s32;
490 } else { 549 } else {
491 bytes_per_word = 4; 550 bytes_per_word = 4;
492 if ((unsigned long)t->tx_buf & 0x03) 551 if ((unsigned long)t->tx_buf & 0x03)
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 603428213d21..d9fd86211365 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -30,6 +30,7 @@
30#include <linux/errno.h> 30#include <linux/errno.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/compat.h>
33 34
34#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
35#include <linux/spi/spidev.h> 36#include <linux/spi/spidev.h>
@@ -471,6 +472,16 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
471 return retval; 472 return retval;
472} 473}
473 474
475#ifdef CONFIG_COMPAT
476static long
477spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
478{
479 return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
480}
481#else
482#define spidev_compat_ioctl NULL
483#endif /* CONFIG_COMPAT */
484
474static int spidev_open(struct inode *inode, struct file *filp) 485static int spidev_open(struct inode *inode, struct file *filp)
475{ 486{
476 struct spidev_data *spidev; 487 struct spidev_data *spidev;
@@ -543,6 +554,7 @@ static const struct file_operations spidev_fops = {
543 .write = spidev_write, 554 .write = spidev_write,
544 .read = spidev_read, 555 .read = spidev_read,
545 .unlocked_ioctl = spidev_ioctl, 556 .unlocked_ioctl = spidev_ioctl,
557 .compat_ioctl = spidev_compat_ioctl,
546 .open = spidev_open, 558 .open = spidev_open,
547 .release = spidev_release, 559 .release = spidev_release,
548 .llseek = no_llseek, 560 .llseek = no_llseek,