~ubuntu-branches/ubuntu/saucy/u-boot/saucy

« back to all changes in this revision

Viewing changes to drivers/spi/omap3_spi.c

  • Committer: Package Import Robot
  • Author(s): Clint Adams
  • Date: 2012-05-01 18:07:19 UTC
  • mfrom: (16.1.23 sid)
  • Revision ID: package-import@ubuntu.com-20120501180719-rjntk3287im4a0ns
Tags: 2012.04.01-1
* New upstream version.
  - Update mipsel-native-endianness.diff.
  - Update no-error-on-set-but-unused-variables.diff (partially merged).
  - Drop kirkwood_spi-irq_mask.diff (merged).
  - Drop kirkwood-disable-l2c.diff (merged).

Show diffs side-by-side

added added

removed removed

Lines of Context:
297
297
        return 0;
298
298
}
299
299
 
 
300
/*McSPI Transmit Receive Mode*/
 
301
int omap3_spi_txrx(struct spi_slave *slave,
 
302
                unsigned int len, const u8 *txp, u8 *rxp, unsigned long flags)
 
303
{
 
304
        struct omap3_spi_slave *ds = to_omap3_spi(slave);
 
305
        int timeout = SPI_WAIT_TIMEOUT;
 
306
        int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
 
307
        int irqstatus = readl(&ds->regs->irqstatus);
 
308
        int i=0;
 
309
 
 
310
        /*Enable SPI channel*/
 
311
        if (flags & SPI_XFER_BEGIN)
 
312
                writel(OMAP3_MCSPI_CHCTRL_EN,
 
313
                       &ds->regs->channel[ds->slave.cs].chctrl);
 
314
 
 
315
        /*set TRANSMIT-RECEIVE Mode*/
 
316
        chconf &= ~OMAP3_MCSPI_CHCONF_TRM_MASK;
 
317
        chconf |= OMAP3_MCSPI_CHCONF_FORCE;
 
318
        writel(chconf, &ds->regs->channel[ds->slave.cs].chconf);
 
319
 
 
320
        /*Shift in and out 1 byte at time*/
 
321
        for (i=0; i < len; i++){
 
322
                /* Write: wait for TX empty (TXS == 1)*/
 
323
                irqstatus |= (1<< (4*(ds->slave.bus)));
 
324
                while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
 
325
                         OMAP3_MCSPI_CHSTAT_TXS)) {
 
326
                        if (--timeout <= 0) {
 
327
                                printf("SPI TXS timed out, status=0x%08x\n",
 
328
                                       readl(&ds->regs->channel[ds->slave.cs].chstat));
 
329
                                return -1;
 
330
                        }
 
331
                }
 
332
                /* Write the data */
 
333
                writel(txp[i], &ds->regs->channel[ds->slave.cs].tx);
 
334
 
 
335
                /*Read: wait for RX containing data (RXS == 1)*/
 
336
                while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
 
337
                         OMAP3_MCSPI_CHSTAT_RXS)) {
 
338
                        if (--timeout <= 0) {
 
339
                                printf("SPI RXS timed out, status=0x%08x\n",
 
340
                                       readl(&ds->regs->channel[ds->slave.cs].chstat));
 
341
                                return -1;
 
342
                        }
 
343
                }
 
344
                /* Read the data */
 
345
                rxp[i] = readl(&ds->regs->channel[ds->slave.cs].rx);
 
346
        }
 
347
 
 
348
        /*if transfer must be terminated disable the channel*/
 
349
        if (flags & SPI_XFER_END) {
 
350
                chconf &= ~OMAP3_MCSPI_CHCONF_FORCE;
 
351
                writel(chconf, &ds->regs->channel[ds->slave.cs].chconf);
 
352
 
 
353
                writel(0, &ds->regs->channel[ds->slave.cs].chctrl);
 
354
        }
 
355
 
 
356
        return 0;
 
357
}
 
358
 
300
359
int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
301
360
             const void *dout, void *din, unsigned long flags)
302
361
{
329
388
                }
330
389
                ret = 0;
331
390
        } else {
332
 
                if (dout != NULL)
 
391
                if (dout != NULL && din != NULL)
 
392
                        ret = omap3_spi_txrx(slave, len, txp, rxp, flags);
 
393
                else if (dout != NULL)
333
394
                        ret = omap3_spi_write(slave, len, txp, flags);
334
 
 
335
 
                if (din != NULL)
 
395
                else if (din != NULL)
336
396
                        ret = omap3_spi_read(slave, len, rxp, flags);
337
397
        }
338
398
        return ret;