Skip to content

Commit bf64b66

Browse files
fancerbroonie
authored andcommitted
spi: dw: Add generic DW SSI status-check method
The DW SSI errors handling method can be generically implemented for all types of the transfers: IRQ, DMA and poll-based ones. It will be a function which checks the overflow/underflow error flags and resets the controller if any of them is set. In the framework of this commit we make use of the new method to detect the errors in the IRQ- and DMA-based SPI transfer execution procedures. Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru> Link: https://lore.kernel.org/r/20201007235511.4935-17-Sergey.Semin@baikalelectronics.ru Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent cf75bae commit bf64b66

3 files changed

Lines changed: 37 additions & 18 deletions

File tree

drivers/spi/spi-dw-core.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,48 @@ static void dw_reader(struct dw_spi *dws)
169169
}
170170
}
171171

172-
static void int_error_stop(struct dw_spi *dws, const char *msg)
172+
int dw_spi_check_status(struct dw_spi *dws, bool raw)
173173
{
174-
spi_reset_chip(dws);
174+
u32 irq_status;
175+
int ret = 0;
176+
177+
if (raw)
178+
irq_status = dw_readl(dws, DW_SPI_RISR);
179+
else
180+
irq_status = dw_readl(dws, DW_SPI_ISR);
181+
182+
if (irq_status & SPI_INT_RXOI) {
183+
dev_err(&dws->master->dev, "RX FIFO overflow detected\n");
184+
ret = -EIO;
185+
}
186+
187+
if (irq_status & SPI_INT_RXUI) {
188+
dev_err(&dws->master->dev, "RX FIFO underflow detected\n");
189+
ret = -EIO;
190+
}
175191

176-
dev_err(&dws->master->dev, "%s\n", msg);
177-
dws->master->cur_msg->status = -EIO;
178-
spi_finalize_current_transfer(dws->master);
192+
if (irq_status & SPI_INT_TXOI) {
193+
dev_err(&dws->master->dev, "TX FIFO overflow detected\n");
194+
ret = -EIO;
195+
}
196+
197+
/* Generically handle the erroneous situation */
198+
if (ret) {
199+
spi_reset_chip(dws);
200+
if (dws->master->cur_msg)
201+
dws->master->cur_msg->status = ret;
202+
}
203+
204+
return ret;
179205
}
206+
EXPORT_SYMBOL_GPL(dw_spi_check_status);
180207

181208
static irqreturn_t dw_spi_transfer_handler(struct dw_spi *dws)
182209
{
183210
u16 irq_status = dw_readl(dws, DW_SPI_ISR);
184211

185-
/* Error handling */
186-
if (irq_status & (SPI_INT_TXOI | SPI_INT_RXOI | SPI_INT_RXUI)) {
187-
dw_readl(dws, DW_SPI_ICR);
188-
int_error_stop(dws, "interrupt_transfer: fifo overrun/underrun");
212+
if (dw_spi_check_status(dws, false)) {
213+
spi_finalize_current_transfer(dws->master);
189214
return IRQ_HANDLED;
190215
}
191216

drivers/spi/spi-dw-dma.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,10 @@ static void dw_spi_dma_exit(struct dw_spi *dws)
176176

177177
static irqreturn_t dw_spi_dma_transfer_handler(struct dw_spi *dws)
178178
{
179-
u16 irq_status = dw_readl(dws, DW_SPI_ISR);
179+
dw_spi_check_status(dws, false);
180180

181-
if (!irq_status)
182-
return IRQ_NONE;
183-
184-
dw_readl(dws, DW_SPI_ICR);
185-
spi_reset_chip(dws);
186-
187-
dev_err(&dws->master->dev, "%s: FIFO overrun/underrun\n", __func__);
188-
dws->master->cur_msg->status = -EIO;
189181
complete(&dws->dma_completion);
182+
190183
return IRQ_HANDLED;
191184
}
192185

drivers/spi/spi-dw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static inline void spi_shutdown_chip(struct dw_spi *dws)
262262
extern void dw_spi_set_cs(struct spi_device *spi, bool enable);
263263
extern void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
264264
struct dw_spi_cfg *cfg);
265+
extern int dw_spi_check_status(struct dw_spi *dws, bool raw);
265266
extern int dw_spi_add_host(struct device *dev, struct dw_spi *dws);
266267
extern void dw_spi_remove_host(struct dw_spi *dws);
267268
extern int dw_spi_suspend_host(struct dw_spi *dws);

0 commit comments

Comments
 (0)