Ignore:
Timestamp:
May 30, 2013, 5:16:33 PM (12 years ago)
Author:
bouyer
Message:

Use 128bits transfers at the SPI controller level when possible;
this speeds up the boot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/softs/tsar_boot/src/spi.c

    r388 r398  
    55 */
    66#include <spi.h>
     7
     8/**
     9 * \param   x: input value
     10 *
     11 * \return  byte-swapped value
     12 *
     13 * \brief   byte-swap a 32bit word
     14 */
     15static unsigned int bswap32(unsigned int x)
     16{
     17  unsigned int y;
     18  y =  (x & 0x000000ff) << 24;
     19  y |= (x & 0x0000ff00) <<  8;
     20  y |= (x & 0x00ff0000) >>  8;
     21  y |= (x & 0xff000000) >> 24;
     22  return y;
     23}
    724
    825/**
     
    6784}
    6885
     86void spi_get_data(struct spi_dev * spi, void *buf, unsigned int count)
     87{
     88    unsigned int *data = buf;
     89    unsigned char *data8;
     90    unsigned int spi_ctrl0, spi_ctrl;
     91    int i;
     92
     93    _spi_wait_if_busy(spi);
     94    /* switch to 128 bits words */
     95    spi_ctrl0 = ioread32(&spi->ctrl);
     96    spi_ctrl = (spi_ctrl0 & ~SPI_CTRL_CHAR_LEN_MASK) | 128;
     97    iowrite32(&spi->ctrl, spi_ctrl);
     98
     99    /* read data */
     100    for (i = 0; i + 3 < count / 4; i += 4) {
     101        iowrite32(&spi->rx_tx[0], 0xffffffff);
     102        iowrite32(&spi->rx_tx[1], 0xffffffff);
     103        iowrite32(&spi->rx_tx[2], 0xffffffff);
     104        iowrite32(&spi->rx_tx[3], 0xffffffff);
     105        iowrite32(&spi->ctrl,  spi_ctrl | SPI_CTRL_GO_BSY);
     106        _spi_wait_if_busy(spi);
     107        *data = bswap32(ioread32(&spi->rx_tx[3]));
     108        data++;
     109        *data = bswap32(ioread32(&spi->rx_tx[2]));
     110        data++;
     111        *data = bswap32(ioread32(&spi->rx_tx[1]));
     112        data++;
     113        *data = bswap32(ioread32(&spi->rx_tx[0]));
     114        data++;
     115    }
     116    /* switch back to original word size */
     117    iowrite32(&spi->ctrl, spi_ctrl0);
     118    /* read missing bits */
     119    data8 = (void *)data;
     120    i = i * 4;
     121    for (; i < count; i++) {
     122        iowrite32(&spi->rx_tx[0], 0xffffffff);
     123        iowrite32(&spi->ctrl,  spi_ctrl0 | SPI_CTRL_GO_BSY);
     124        _spi_wait_if_busy(spi);
     125        *data8 = spi_get_rx(spi, 0);
     126        data8++;
     127    }
     128    return;
     129}
     130
    69131void spi_ss_assert(struct spi_dev * spi, int index)
    70132{
Note: See TracChangeset for help on using the changeset viewer.