12
#include <linux/kernel.h>
12
#include <linux/bitmap.h>
13
#include <linux/clk.h>
14
#include <linux/completion.h>
15
#include <linux/delay.h>
16
#include <linux/err.h>
17
#include <linux/gpio.h>
13
18
#include <linux/init.h>
14
#include <linux/delay.h>
15
19
#include <linux/interrupt.h>
21
#include <linux/kernel.h>
16
22
#include <linux/platform_device.h>
17
#include <linux/completion.h>
18
23
#include <linux/pm_runtime.h>
19
#include <linux/gpio.h>
20
#include <linux/bitmap.h>
21
#include <linux/clk.h>
23
#include <linux/err.h>
25
#include <linux/spi/sh_msiof.h>
25
26
#include <linux/spi/spi.h>
26
27
#include <linux/spi/spi_bitbang.h>
27
#include <linux/spi/sh_msiof.h>
29
29
#include <asm/unaligned.h>
67
67
#define STR_TEOF (1 << 23)
68
68
#define STR_REOF (1 << 7)
70
static unsigned long sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs)
70
static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs)
72
72
switch (reg_offs) {
95
95
static int sh_msiof_modify_ctr_wait(struct sh_msiof_spi_priv *p,
96
unsigned long clr, unsigned long set)
98
unsigned long mask = clr | set;
102
102
data = sh_msiof_read(p, CTR);
168
168
static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p,
170
int tx_hi_z, int lsb_first)
170
u32 tx_hi_z, u32 lsb_first)
187
187
tmp |= cpol << 30; /* TSCKIZ */
188
188
tmp |= cpol << 28; /* RSCKIZ */
190
edge = cpol ? cpha : !cpha;
192
192
tmp |= edge << 27; /* TEDG */
193
193
tmp |= edge << 26; /* REDG */
198
198
static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,
199
199
const void *tx_buf, void *rx_buf,
204
dr2 = ((bits - 1) << 24) | ((words - 1) << 16);
202
u32 dr2 = ((bits - 1) << 24) | ((words - 1) << 16);
207
205
sh_msiof_write(p, TMDR2, dr2);
222
220
static void sh_msiof_spi_write_fifo_8(struct sh_msiof_spi_priv *p,
223
221
const void *tx_buf, int words, int fs)
225
const unsigned char *buf_8 = tx_buf;
223
const u8 *buf_8 = tx_buf;
228
226
for (k = 0; k < words; k++)
232
230
static void sh_msiof_spi_write_fifo_16(struct sh_msiof_spi_priv *p,
233
231
const void *tx_buf, int words, int fs)
235
const unsigned short *buf_16 = tx_buf;
233
const u16 *buf_16 = tx_buf;
238
236
for (k = 0; k < words; k++)
242
240
static void sh_msiof_spi_write_fifo_16u(struct sh_msiof_spi_priv *p,
243
241
const void *tx_buf, int words, int fs)
245
const unsigned short *buf_16 = tx_buf;
243
const u16 *buf_16 = tx_buf;
248
246
for (k = 0; k < words; k++)
252
250
static void sh_msiof_spi_write_fifo_32(struct sh_msiof_spi_priv *p,
253
251
const void *tx_buf, int words, int fs)
255
const unsigned int *buf_32 = tx_buf;
253
const u32 *buf_32 = tx_buf;
258
256
for (k = 0; k < words; k++)
262
260
static void sh_msiof_spi_write_fifo_32u(struct sh_msiof_spi_priv *p,
263
261
const void *tx_buf, int words, int fs)
265
const unsigned int *buf_32 = tx_buf;
263
const u32 *buf_32 = tx_buf;
268
266
for (k = 0; k < words; k++)
269
267
sh_msiof_write(p, TFDR, get_unaligned(&buf_32[k]) << fs);
270
static void sh_msiof_spi_write_fifo_s32(struct sh_msiof_spi_priv *p,
271
const void *tx_buf, int words, int fs)
273
const u32 *buf_32 = tx_buf;
276
for (k = 0; k < words; k++)
277
sh_msiof_write(p, TFDR, swab32(buf_32[k] << fs));
280
static void sh_msiof_spi_write_fifo_s32u(struct sh_msiof_spi_priv *p,
281
const void *tx_buf, int words, int fs)
283
const u32 *buf_32 = tx_buf;
286
for (k = 0; k < words; k++)
287
sh_msiof_write(p, TFDR, swab32(get_unaligned(&buf_32[k]) << fs));
272
290
static void sh_msiof_spi_read_fifo_8(struct sh_msiof_spi_priv *p,
273
291
void *rx_buf, int words, int fs)
275
unsigned char *buf_8 = rx_buf;
278
296
for (k = 0; k < words; k++)
282
300
static void sh_msiof_spi_read_fifo_16(struct sh_msiof_spi_priv *p,
283
301
void *rx_buf, int words, int fs)
285
unsigned short *buf_16 = rx_buf;
303
u16 *buf_16 = rx_buf;
288
306
for (k = 0; k < words; k++)
292
310
static void sh_msiof_spi_read_fifo_16u(struct sh_msiof_spi_priv *p,
293
311
void *rx_buf, int words, int fs)
295
unsigned short *buf_16 = rx_buf;
313
u16 *buf_16 = rx_buf;
298
316
for (k = 0; k < words; k++)
302
320
static void sh_msiof_spi_read_fifo_32(struct sh_msiof_spi_priv *p,
303
321
void *rx_buf, int words, int fs)
305
unsigned int *buf_32 = rx_buf;
323
u32 *buf_32 = rx_buf;
308
326
for (k = 0; k < words; k++)
312
330
static void sh_msiof_spi_read_fifo_32u(struct sh_msiof_spi_priv *p,
313
331
void *rx_buf, int words, int fs)
315
unsigned int *buf_32 = rx_buf;
333
u32 *buf_32 = rx_buf;
318
336
for (k = 0; k < words; k++)
319
337
put_unaligned(sh_msiof_read(p, RFDR) >> fs, &buf_32[k]);
340
static void sh_msiof_spi_read_fifo_s32(struct sh_msiof_spi_priv *p,
341
void *rx_buf, int words, int fs)
343
u32 *buf_32 = rx_buf;
346
for (k = 0; k < words; k++)
347
buf_32[k] = swab32(sh_msiof_read(p, RFDR) >> fs);
350
static void sh_msiof_spi_read_fifo_s32u(struct sh_msiof_spi_priv *p,
351
void *rx_buf, int words, int fs)
353
u32 *buf_32 = rx_buf;
356
for (k = 0; k < words; k++)
357
put_unaligned(swab32(sh_msiof_read(p, RFDR) >> fs), &buf_32[k]);
322
360
static int sh_msiof_spi_bits(struct spi_device *spi, struct spi_transfer *t)
326
364
bits = t ? t->bits_per_word : 0;
327
bits = bits ? bits : spi->bits_per_word;
366
bits = spi->bits_per_word;
487
535
rx_fifo = sh_msiof_spi_read_fifo_16u;
489
537
rx_fifo = sh_msiof_spi_read_fifo_16;
540
if ((unsigned long)t->tx_buf & 0x03)
541
tx_fifo = sh_msiof_spi_write_fifo_s32u;
543
tx_fifo = sh_msiof_spi_write_fifo_s32;
545
if ((unsigned long)t->rx_buf & 0x03)
546
rx_fifo = sh_msiof_spi_read_fifo_s32u;
548
rx_fifo = sh_msiof_spi_read_fifo_s32;
491
550
bytes_per_word = 4;
492
551
if ((unsigned long)t->tx_buf & 0x03)