/* This function will check the SPIFLG register and handle any events that are detected there  */
static int davinci_spi_process_events(struct davinci_spi *dspi)
/* This function will check the SPIFLG register and handle any events that are detected there  */
static int davinci_spi_process_events(struct davinci_spi *dspi)
{
    u32 buf, status, errors = 0, spidat1;
    buf = readl(dspi->base + SPIBUF);
    if (dspi->rcount > 0 && !(buf & SPIBUF_RXEMPTY_MASK)) {
        dspi->get_rx(buf & 0xFFFF, dspi);
        dspi->rcount--;
    }
    status = readl(dspi->base + SPIFLG);
    if (unlikely(status & SPIFLG_ERROR_MASK)) {
        errors = status & SPIFLG_ERROR_MASK;
        goto out;
    }
    if (dspi->wcount > 0 && !(buf & SPIBUF_TXFULL_MASK)) {
        spidat1 = readl(dspi->base + SPIDAT1);
        dspi->wcount--;
        spidat1 &= ~0xFFFF;
        spidat1 |= 0xFFFF & dspi->get_tx(dspi);
        writel(spidat1, dspi->base + SPIDAT1);
    }
out:
    return errors;
}