|
70 | 70 | #define INT_RX_CHANNEL_OVERFLOW BIT(2) |
71 | 71 | #define INT_TX_CHANNEL_UNDERRUN BIT(3) |
72 | 72 |
|
73 | | -#define INT_ENABLE_MASK (CONTROL_RX_DATA_INT | CONTROL_TX_DATA_INT | \ |
74 | | - CONTROL_RX_OVER_INT | CONTROL_TX_UNDER_INT) |
| 73 | +#define INT_ENABLE_MASK (CONTROL_RX_OVER_INT | CONTROL_TX_UNDER_INT) |
75 | 74 |
|
76 | 75 | #define REG_CONTROL (0x00) |
77 | 76 | #define REG_FRAME_SIZE (0x04) |
@@ -133,10 +132,15 @@ static inline void mchp_corespi_disable(struct mchp_corespi *spi) |
133 | 132 | mchp_corespi_write(spi, REG_CONTROL, control); |
134 | 133 | } |
135 | 134 |
|
136 | | -static inline void mchp_corespi_read_fifo(struct mchp_corespi *spi) |
| 135 | +static inline void mchp_corespi_read_fifo(struct mchp_corespi *spi, int fifo_max) |
137 | 136 | { |
138 | | - while (spi->rx_len >= spi->n_bytes && !(mchp_corespi_read(spi, REG_STATUS) & STATUS_RXFIFO_EMPTY)) { |
139 | | - u32 data = mchp_corespi_read(spi, REG_RX_DATA); |
| 137 | + for (int i = 0; i < fifo_max; i++) { |
| 138 | + u32 data; |
| 139 | + |
| 140 | + while (mchp_corespi_read(spi, REG_STATUS) & STATUS_RXFIFO_EMPTY) |
| 141 | + ; |
| 142 | + |
| 143 | + data = mchp_corespi_read(spi, REG_RX_DATA); |
140 | 144 |
|
141 | 145 | spi->rx_len -= spi->n_bytes; |
142 | 146 |
|
@@ -211,11 +215,10 @@ static inline void mchp_corespi_set_xfer_size(struct mchp_corespi *spi, int len) |
211 | 215 | mchp_corespi_write(spi, REG_FRAMESUP, len); |
212 | 216 | } |
213 | 217 |
|
214 | | -static inline void mchp_corespi_write_fifo(struct mchp_corespi *spi) |
| 218 | +static inline void mchp_corespi_write_fifo(struct mchp_corespi *spi, int fifo_max) |
215 | 219 | { |
216 | | - int fifo_max, i = 0; |
| 220 | + int i = 0; |
217 | 221 |
|
218 | | - fifo_max = DIV_ROUND_UP(min(spi->tx_len, FIFO_DEPTH), spi->n_bytes); |
219 | 222 | mchp_corespi_set_xfer_size(spi, fifo_max); |
220 | 223 |
|
221 | 224 | while ((i < fifo_max) && !(mchp_corespi_read(spi, REG_STATUS) & STATUS_TXFIFO_FULL)) { |
@@ -413,19 +416,6 @@ static irqreturn_t mchp_corespi_interrupt(int irq, void *dev_id) |
413 | 416 | if (intfield == 0) |
414 | 417 | return IRQ_NONE; |
415 | 418 |
|
416 | | - if (intfield & INT_TXDONE) |
417 | | - mchp_corespi_write(spi, REG_INT_CLEAR, INT_TXDONE); |
418 | | - |
419 | | - if (intfield & INT_RXRDY) { |
420 | | - mchp_corespi_write(spi, REG_INT_CLEAR, INT_RXRDY); |
421 | | - |
422 | | - if (spi->rx_len) |
423 | | - mchp_corespi_read_fifo(spi); |
424 | | - } |
425 | | - |
426 | | - if (!spi->rx_len && !spi->tx_len) |
427 | | - finalise = true; |
428 | | - |
429 | 419 | if (intfield & INT_RX_CHANNEL_OVERFLOW) { |
430 | 420 | mchp_corespi_write(spi, REG_INT_CLEAR, INT_RX_CHANNEL_OVERFLOW); |
431 | 421 | finalise = true; |
@@ -512,9 +502,14 @@ static int mchp_corespi_transfer_one(struct spi_controller *host, |
512 | 502 |
|
513 | 503 | mchp_corespi_write(spi, REG_SLAVE_SELECT, spi->pending_slave_select); |
514 | 504 |
|
515 | | - while (spi->tx_len) |
516 | | - mchp_corespi_write_fifo(spi); |
| 505 | + while (spi->tx_len) { |
| 506 | + int fifo_max = DIV_ROUND_UP(min(spi->tx_len, FIFO_DEPTH), spi->n_bytes); |
| 507 | + |
| 508 | + mchp_corespi_write_fifo(spi, fifo_max); |
| 509 | + mchp_corespi_read_fifo(spi, fifo_max); |
| 510 | + } |
517 | 511 |
|
| 512 | + spi_finalize_current_transfer(host); |
518 | 513 | return 1; |
519 | 514 | } |
520 | 515 |
|
|
0 commit comments