~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/spi/spi_sh_msiof.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 *
10
10
 */
11
11
 
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>
 
20
#include <linux/io.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>
22
 
#include <linux/io.h>
23
 
#include <linux/err.h>
24
24
 
 
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>
28
28
 
29
29
#include <asm/unaligned.h>
30
30
 
67
67
#define STR_TEOF  (1 << 23)
68
68
#define STR_REOF  (1 << 7)
69
69
 
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)
71
71
{
72
72
        switch (reg_offs) {
73
73
        case TSCR:
79
79
}
80
80
 
81
81
static void sh_msiof_write(struct sh_msiof_spi_priv *p, int reg_offs,
82
 
                           unsigned long value)
 
82
                           u32 value)
83
83
{
84
84
        switch (reg_offs) {
85
85
        case TSCR:
93
93
}
94
94
 
95
95
static 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;
99
 
        unsigned long data;
 
98
        u32 mask = clr | set;
 
99
        u32 data;
100
100
        int k;
101
101
 
102
102
        data = sh_msiof_read(p, CTR);
166
166
}
167
167
 
168
168
static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p,
169
 
                                      int cpol, int cpha,
170
 
                                      int tx_hi_z, int lsb_first)
 
169
                                      u32 cpol, u32 cpha,
 
170
                                      u32 tx_hi_z, u32 lsb_first)
171
171
{
172
 
        unsigned long tmp;
 
172
        u32 tmp;
173
173
        int edge;
174
174
 
175
175
        /*
187
187
        tmp |= cpol << 30; /* TSCKIZ */
188
188
        tmp |= cpol << 28; /* RSCKIZ */
189
189
 
190
 
        edge = cpol ? cpha : !cpha;
 
190
        edge = cpol ^ !cpha;
191
191
 
192
192
        tmp |= edge << 27; /* TEDG */
193
193
        tmp |= edge << 26; /* REDG */
197
197
 
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,
200
 
                                       int bits, int words)
 
200
                                       u32 bits, u32 words)
201
201
{
202
 
        unsigned long dr2;
203
 
 
204
 
        dr2 = ((bits - 1) << 24) | ((words - 1) << 16);
 
202
        u32 dr2 = ((bits - 1) << 24) | ((words - 1) << 16);
205
203
 
206
204
        if (tx_buf)
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)
224
222
{
225
 
        const unsigned char *buf_8 = tx_buf;
 
223
        const u8 *buf_8 = tx_buf;
226
224
        int k;
227
225
 
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)
234
232
{
235
 
        const unsigned short *buf_16 = tx_buf;
 
233
        const u16 *buf_16 = tx_buf;
236
234
        int k;
237
235
 
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)
244
242
{
245
 
        const unsigned short *buf_16 = tx_buf;
 
243
        const u16 *buf_16 = tx_buf;
246
244
        int k;
247
245
 
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)
254
252
{
255
 
        const unsigned int *buf_32 = tx_buf;
 
253
        const u32 *buf_32 = tx_buf;
256
254
        int k;
257
255
 
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)
264
262
{
265
 
        const unsigned int *buf_32 = tx_buf;
 
263
        const u32 *buf_32 = tx_buf;
266
264
        int k;
267
265
 
268
266
        for (k = 0; k < words; k++)
269
267
                sh_msiof_write(p, TFDR, get_unaligned(&buf_32[k]) << fs);
270
268
}
271
269
 
 
270
static 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
 
 
280
static 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
 
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)
274
292
{
275
 
        unsigned char *buf_8 = rx_buf;
 
293
        u8 *buf_8 = rx_buf;
276
294
        int k;
277
295
 
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)
284
302
{
285
 
        unsigned short *buf_16 = rx_buf;
 
303
        u16 *buf_16 = rx_buf;
286
304
        int k;
287
305
 
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)
294
312
{
295
 
        unsigned short *buf_16 = rx_buf;
 
313
        u16 *buf_16 = rx_buf;
296
314
        int k;
297
315
 
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)
304
322
{
305
 
        unsigned int *buf_32 = rx_buf;
 
323
        u32 *buf_32 = rx_buf;
306
324
        int k;
307
325
 
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)
314
332
{
315
 
        unsigned int *buf_32 = rx_buf;
 
333
        u32 *buf_32 = rx_buf;
316
334
        int k;
317
335
 
318
336
        for (k = 0; k < words; k++)
319
337
                put_unaligned(sh_msiof_read(p, RFDR) >> fs, &buf_32[k]);
320
338
}
321
339
 
 
340
static 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
 
 
350
static 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
 
322
360
static int sh_msiof_spi_bits(struct spi_device *spi, struct spi_transfer *t)
323
361
{
324
362
        int bits;
325
363
 
326
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
367
        return bits;
329
368
}
330
369
 
334
373
        unsigned long hz;
335
374
 
336
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
378
        return hz;
339
379
}
340
380
 
468
508
        int bytes_done;
469
509
        int words;
470
510
        int n;
 
511
        bool swab;
471
512
 
472
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
522
        /* setup bytes per word and fifo read/write functions */
475
523
        if (bits <= 8) {
476
524
                bytes_per_word = 1;
487
535
                        rx_fifo = sh_msiof_spi_read_fifo_16u;
488
536
                else
489
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
549
        } else {
491
550
                bytes_per_word = 4;
492
551
                if ((unsigned long)t->tx_buf & 0x03)