static void flush(struct dw_spi *dws) { while (dw_readw(dws, sr) & SR_RF_NOT_EMPT) dw_readw(dws, dr); wait_till_not_busy(dws); }
static void flush(struct dw_spi *dws) { while (!(dw_readw(dws, SPIM_SR) & SR_RF_EMPT)) dw_readw(dws, SPIM_RXDR); wait_till_not_busy(dws); }
static int u8_reader(struct dw_spi *dws) { while ((dw_readw(dws, sr) & SR_RF_NOT_EMPT) && (dws->rx < dws->rx_end)) { *(u8 *)(dws->rx) = dw_readw(dws, dr); ++dws->rx; } wait_till_not_busy(dws); return dws->rx == dws->rx_end; }
static int null_reader(struct dw_spi *dws) { u8 n_bytes = dws->n_bytes; while ((dw_readw(dws, sr) & SR_RF_NOT_EMPT) && (dws->rx < dws->rx_end)) { dw_readw(dws, dr); dws->rx += n_bytes; } wait_till_not_busy(dws); return dws->rx == dws->rx_end; }
static int u16_reader(struct dw_spi *dws) { u16 temp; while ((dw_readw(dws, sr) & SR_RF_NOT_EMPT) && (dws->rx < dws->rx_end)) { temp = dw_readw(dws, dr); *(u16 *)(dws->rx) = temp; dws->rx += 2; } wait_till_not_busy(dws); return dws->rx == dws->rx_end; }
static void dw_reader(struct dw_spi *dws) { u32 max = rx_max(dws); u16 rxw; DBG_SPI("%dbyte rx:",dws->n_bytes); while (max--) { rxw = dw_readw(dws, SPIM_RXDR); /* Care rx only if the transfer's original "rx" is not null */ if (dws->rx_end - dws->len) { if (dws->n_bytes == 1) { *(u8 *)(dws->rx) = rxw; DBG_SPI("0x%02x,", *(u8 *)(dws->rx)); } else { *(u16 *)(dws->rx) = rxw; DBG_SPI("0x%02x,", *(u16 *)(dws->rx)); } } dws->rx += dws->n_bytes; } DBG_SPI("\n"); }
static int reader_all(struct dw_spi *dws) { while (!(dw_readw(dws, SPIM_SR) & SR_RF_EMPT) && (dws->rx < dws->rx_end)) { dw_reader(dws); wait_till_not_busy(dws); } return dws->rx == dws->rx_end; }
static void wait_till_not_busy(struct dw_spi *dws) { unsigned long end = jiffies + 1 + usecs_to_jiffies(1000); while (time_before(jiffies, end)) { if (!(dw_readw(dws, sr) & SR_BUSY)) return; } dev_err(&dws->master->dev, "DW SPI: Status keeps busy for 1000us after a read/write!\n"); }
static int u16_writer(struct dw_spi *dws) { if (!(dw_readw(dws, sr) & SR_TF_NOT_FULL) || (dws->tx == dws->tx_end)) return 0; dw_writew(dws, dr, *(u16 *)(dws->tx)); dws->tx += 2; wait_till_not_busy(dws); return 1; }
static int null_writer(struct dw_spi *dws) { u8 n_bytes = dws->n_bytes; if (!(dw_readw(dws, sr) & SR_TF_NOT_FULL) || (dws->tx == dws->tx_end)) return 0; dw_writew(dws, dr, 0); dws->tx += n_bytes; wait_till_not_busy(dws); return 1; }
static void wait_till_not_busy(struct dw_spi *dws) { unsigned long end = jiffies + 1 + usecs_to_jiffies(1000); //if spi was slave, it is SR_BUSY always. if(dws->cur_chip) { if(dws->cur_chip->slave_enable == 1) return; } while (time_before(jiffies, end)) { if (!(dw_readw(dws, SPIM_SR) & SR_BUSY)) return; } dev_err(&dws->master->dev, "DW SPI: Status keeps busy for 1000us after a read/write!\n"); }
static void dw_reader(struct dw_spi *dws) { u32 max = rx_max(dws); u16 rxw; while (max--) { rxw = dw_readw(dws, DW_SPI_DR); /* Care rx only if the transfer's original "rx" is not null */ if (dws->rx_end - dws->len) { if (dws->n_bytes == 1) *(u8 *)(dws->rx) = rxw; else *(u16 *)(dws->rx) = rxw; } dws->rx += dws->n_bytes; } }
/* Return the max entries we can fill into tx fifo */ static inline u32 tx_max(struct dw_spi *dws) { u32 tx_left, tx_room, rxtx_gap; tx_left = (dws->tx_end - dws->tx) / dws->n_bytes; tx_room = dws->fifo_len - dw_readw(dws, DW_SPI_TXFLR); /* * Another concern is about the tx/rx mismatch, we * though to use (dws->fifo_len - rxflr - txflr) as * one maximum value for tx, but it doesn't cover the * data which is out of tx/rx fifo and inside the * shift registers. So a control from sw point of * view is taken. */ rxtx_gap = ((dws->rx_end - dws->rx) - (dws->tx_end - dws->tx)) / dws->n_bytes; return min3(tx_left, tx_room, (u32) (dws->fifo_len - rxtx_gap)); }
/* Return the max entries we should read out of rx fifo */ static inline u32 rx_max(struct dw_spi *dws) { u32 rx_left = (dws->rx_end - dws->rx) / dws->n_bytes; return min(rx_left, (u32)dw_readw(dws, DW_SPI_RXFLR)); }