Skip to content

Commit fdc5231

Browse files
committed
spi: Merge up fixes to help CI
Get the fixes into CI for development.
2 parents fe73245 + 0c331fd commit fdc5231

7 files changed

Lines changed: 78 additions & 85 deletions

File tree

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18703,7 +18703,6 @@ F: include/dt-bindings/clock/samsung,*.h
1870318703
F: include/linux/clk/samsung.h
1870418704

1870518705
SAMSUNG SPI DRIVERS
18706-
M: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
1870718706
M: Andi Shyti <andi.shyti@kernel.org>
1870818707
L: linux-spi@vger.kernel.org
1870918708
L: linux-samsung-soc@vger.kernel.org

drivers/spi/spi-cadence.c

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/gpio/consumer.h>
1313
#include <linux/interrupt.h>
1414
#include <linux/io.h>
15+
#include <linux/kernel.h>
1516
#include <linux/module.h>
1617
#include <linux/of_irq.h>
1718
#include <linux/of_address.h>
@@ -302,49 +303,43 @@ static int cdns_spi_setup_transfer(struct spi_device *spi,
302303
}
303304

304305
/**
305-
* cdns_spi_fill_tx_fifo - Fills the TX FIFO with as many bytes as possible
306+
* cdns_spi_process_fifo - Fills the TX FIFO, and drain the RX FIFO
306307
* @xspi: Pointer to the cdns_spi structure
308+
* @ntx: Number of bytes to pack into the TX FIFO
309+
* @nrx: Number of bytes to drain from the RX FIFO
307310
*/
308-
static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi)
311+
static void cdns_spi_process_fifo(struct cdns_spi *xspi, int ntx, int nrx)
309312
{
310-
unsigned long trans_cnt = 0;
313+
ntx = clamp(ntx, 0, xspi->tx_bytes);
314+
nrx = clamp(nrx, 0, xspi->rx_bytes);
311315

312-
while ((trans_cnt < xspi->tx_fifo_depth) &&
313-
(xspi->tx_bytes > 0)) {
316+
xspi->tx_bytes -= ntx;
317+
xspi->rx_bytes -= nrx;
314318

319+
while (ntx || nrx) {
315320
/* When xspi in busy condition, bytes may send failed,
316321
* then spi control did't work thoroughly, add one byte delay
317322
*/
318-
if (cdns_spi_read(xspi, CDNS_SPI_ISR) &
319-
CDNS_SPI_IXR_TXFULL)
323+
if (cdns_spi_read(xspi, CDNS_SPI_ISR) & CDNS_SPI_IXR_TXFULL)
320324
udelay(10);
321325

322-
if (xspi->txbuf)
323-
cdns_spi_write(xspi, CDNS_SPI_TXD, *xspi->txbuf++);
324-
else
325-
cdns_spi_write(xspi, CDNS_SPI_TXD, 0);
326+
if (ntx) {
327+
if (xspi->txbuf)
328+
cdns_spi_write(xspi, CDNS_SPI_TXD, *xspi->txbuf++);
329+
else
330+
cdns_spi_write(xspi, CDNS_SPI_TXD, 0);
326331

327-
xspi->tx_bytes--;
328-
trans_cnt++;
329-
}
330-
}
332+
ntx--;
333+
}
331334

332-
/**
333-
* cdns_spi_read_rx_fifo - Reads the RX FIFO with as many bytes as possible
334-
* @xspi: Pointer to the cdns_spi structure
335-
* @count: Read byte count
336-
*/
337-
static void cdns_spi_read_rx_fifo(struct cdns_spi *xspi, unsigned long count)
338-
{
339-
u8 data;
340-
341-
/* Read out the data from the RX FIFO */
342-
while (count > 0) {
343-
data = cdns_spi_read(xspi, CDNS_SPI_RXD);
344-
if (xspi->rxbuf)
345-
*xspi->rxbuf++ = data;
346-
xspi->rx_bytes--;
347-
count--;
335+
if (nrx) {
336+
u8 data = cdns_spi_read(xspi, CDNS_SPI_RXD);
337+
338+
if (xspi->rxbuf)
339+
*xspi->rxbuf++ = data;
340+
341+
nrx--;
342+
}
348343
}
349344
}
350345

@@ -382,33 +377,22 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
382377
spi_finalize_current_transfer(ctlr);
383378
status = IRQ_HANDLED;
384379
} else if (intr_status & CDNS_SPI_IXR_TXOW) {
385-
int trans_cnt = cdns_spi_read(xspi, CDNS_SPI_THLD);
380+
int threshold = cdns_spi_read(xspi, CDNS_SPI_THLD);
381+
int trans_cnt = xspi->rx_bytes - xspi->tx_bytes;
382+
383+
if (threshold > 1)
384+
trans_cnt -= threshold;
385+
386386
/* Set threshold to one if number of pending are
387387
* less than half fifo
388388
*/
389389
if (xspi->tx_bytes < xspi->tx_fifo_depth >> 1)
390390
cdns_spi_write(xspi, CDNS_SPI_THLD, 1);
391391

392-
while (trans_cnt) {
393-
cdns_spi_read_rx_fifo(xspi, 1);
394-
395-
if (xspi->tx_bytes) {
396-
if (xspi->txbuf)
397-
cdns_spi_write(xspi, CDNS_SPI_TXD,
398-
*xspi->txbuf++);
399-
else
400-
cdns_spi_write(xspi, CDNS_SPI_TXD, 0);
401-
xspi->tx_bytes--;
402-
}
403-
trans_cnt--;
404-
}
405-
if (!xspi->tx_bytes) {
406-
/* Fixed delay due to controller limitation with
407-
* RX_NEMPTY incorrect status
408-
* Xilinx AR:65885 contains more details
409-
*/
410-
udelay(10);
411-
cdns_spi_read_rx_fifo(xspi, xspi->rx_bytes);
392+
if (xspi->tx_bytes) {
393+
cdns_spi_process_fifo(xspi, trans_cnt, trans_cnt);
394+
} else {
395+
cdns_spi_process_fifo(xspi, 0, trans_cnt);
412396
cdns_spi_write(xspi, CDNS_SPI_IDR,
413397
CDNS_SPI_IXR_DEFAULT);
414398
spi_finalize_current_transfer(ctlr);
@@ -451,16 +435,17 @@ static int cdns_transfer_one(struct spi_controller *ctlr,
451435
xspi->tx_bytes = transfer->len;
452436
xspi->rx_bytes = transfer->len;
453437

454-
if (!spi_controller_is_slave(ctlr))
438+
if (!spi_controller_is_slave(ctlr)) {
455439
cdns_spi_setup_transfer(spi, transfer);
440+
} else {
441+
/* Set TX empty threshold to half of FIFO depth
442+
* only if TX bytes are more than half FIFO depth.
443+
*/
444+
if (xspi->tx_bytes > xspi->tx_fifo_depth)
445+
cdns_spi_write(xspi, CDNS_SPI_THLD, xspi->tx_fifo_depth >> 1);
446+
}
456447

457-
/* Set TX empty threshold to half of FIFO depth
458-
* only if TX bytes are more than half FIFO depth.
459-
*/
460-
if (xspi->tx_bytes > (xspi->tx_fifo_depth >> 1))
461-
cdns_spi_write(xspi, CDNS_SPI_THLD, xspi->tx_fifo_depth >> 1);
462-
463-
cdns_spi_fill_tx_fifo(xspi);
448+
cdns_spi_process_fifo(xspi, xspi->tx_fifo_depth, 0);
464449
spi_transfer_delay_exec(transfer);
465450

466451
cdns_spi_write(xspi, CDNS_SPI_IER, CDNS_SPI_IXR_DEFAULT);

drivers/spi/spi-dw-mmio.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,17 @@ static void dw_spi_elba_set_cs(struct spi_device *spi, bool enable)
264264
struct regmap *syscon = dwsmmio->priv;
265265
u8 cs;
266266

267-
cs = spi->chip_select;
267+
cs = spi_get_chipselect(spi, 0);
268268
if (cs < 2)
269-
dw_spi_elba_override_cs(syscon, spi->chip_select, enable);
269+
dw_spi_elba_override_cs(syscon, spi_get_chipselect(spi, 0), enable);
270270

271271
/*
272272
* The DW SPI controller needs a native CS bit selected to start
273273
* the serial engine.
274274
*/
275-
spi->chip_select = 0;
275+
spi_set_chipselect(spi, 0, 0);
276276
dw_spi_set_cs(spi, enable);
277-
spi->chip_select = cs;
277+
spi_get_chipselect(spi, cs);
278278
}
279279

280280
static int dw_spi_elba_init(struct platform_device *pdev,

drivers/spi/spi-fsl-lpspi.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,9 +916,14 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
916916
ret = fsl_lpspi_dma_init(&pdev->dev, fsl_lpspi, controller);
917917
if (ret == -EPROBE_DEFER)
918918
goto out_pm_get;
919-
920919
if (ret < 0)
921920
dev_err(&pdev->dev, "dma setup error %d, use pio\n", ret);
921+
else
922+
/*
923+
* disable LPSPI module IRQ when enable DMA mode successfully,
924+
* to prevent the unexpected LPSPI module IRQ events.
925+
*/
926+
disable_irq(irq);
922927

923928
ret = devm_spi_register_controller(&pdev->dev, controller);
924929
if (ret < 0) {

drivers/spi/spi-geni-qcom.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ static void spi_geni_set_cs(struct spi_device *slv, bool set_flag)
294294
mas->cs_flag = set_flag;
295295
/* set xfer_mode to FIFO to complete cs_done in isr */
296296
mas->cur_xfer_mode = GENI_SE_FIFO;
297+
geni_se_select_mode(se, mas->cur_xfer_mode);
298+
297299
reinit_completion(&mas->cs_done);
298300
if (set_flag)
299301
geni_se_setup_m_cmd(se, SPI_CS_ASSERT, 0);

drivers/spi/spi-mt65xx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,9 @@ static void mtk_spi_remove(struct platform_device *pdev)
12761276
struct mtk_spi *mdata = spi_master_get_devdata(master);
12771277
int ret;
12781278

1279+
if (mdata->use_spimem && !completion_done(&mdata->spimem_done))
1280+
complete(&mdata->spimem_done);
1281+
12791282
ret = pm_runtime_get_sync(&pdev->dev);
12801283
if (ret < 0) {
12811284
dev_warn(&pdev->dev, "Failed to resume hardware (%pe)\n", ERR_PTR(ret));

drivers/spi/spi-qup.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,23 +1028,8 @@ static int spi_qup_probe(struct platform_device *pdev)
10281028
return -ENXIO;
10291029
}
10301030

1031-
ret = clk_prepare_enable(cclk);
1032-
if (ret) {
1033-
dev_err(dev, "cannot enable core clock\n");
1034-
return ret;
1035-
}
1036-
1037-
ret = clk_prepare_enable(iclk);
1038-
if (ret) {
1039-
clk_disable_unprepare(cclk);
1040-
dev_err(dev, "cannot enable iface clock\n");
1041-
return ret;
1042-
}
1043-
10441031
master = spi_alloc_master(dev, sizeof(struct spi_qup));
10451032
if (!master) {
1046-
clk_disable_unprepare(cclk);
1047-
clk_disable_unprepare(iclk);
10481033
dev_err(dev, "cannot allocate master\n");
10491034
return -ENOMEM;
10501035
}
@@ -1092,6 +1077,19 @@ static int spi_qup_probe(struct platform_device *pdev)
10921077
spin_lock_init(&controller->lock);
10931078
init_completion(&controller->done);
10941079

1080+
ret = clk_prepare_enable(cclk);
1081+
if (ret) {
1082+
dev_err(dev, "cannot enable core clock\n");
1083+
goto error_dma;
1084+
}
1085+
1086+
ret = clk_prepare_enable(iclk);
1087+
if (ret) {
1088+
clk_disable_unprepare(cclk);
1089+
dev_err(dev, "cannot enable iface clock\n");
1090+
goto error_dma;
1091+
}
1092+
10951093
iomode = readl_relaxed(base + QUP_IO_M_MODES);
10961094

10971095
size = QUP_IO_M_OUTPUT_BLOCK_SIZE(iomode);
@@ -1121,7 +1119,7 @@ static int spi_qup_probe(struct platform_device *pdev)
11211119
ret = spi_qup_set_state(controller, QUP_STATE_RESET);
11221120
if (ret) {
11231121
dev_err(dev, "cannot set RESET state\n");
1124-
goto error_dma;
1122+
goto error_clk;
11251123
}
11261124

11271125
writel_relaxed(0, base + QUP_OPERATIONAL);
@@ -1145,7 +1143,7 @@ static int spi_qup_probe(struct platform_device *pdev)
11451143
ret = devm_request_irq(dev, irq, spi_qup_qup_irq,
11461144
IRQF_TRIGGER_HIGH, pdev->name, controller);
11471145
if (ret)
1148-
goto error_dma;
1146+
goto error_clk;
11491147

11501148
pm_runtime_set_autosuspend_delay(dev, MSEC_PER_SEC);
11511149
pm_runtime_use_autosuspend(dev);
@@ -1160,11 +1158,12 @@ static int spi_qup_probe(struct platform_device *pdev)
11601158

11611159
disable_pm:
11621160
pm_runtime_disable(&pdev->dev);
1161+
error_clk:
1162+
clk_disable_unprepare(cclk);
1163+
clk_disable_unprepare(iclk);
11631164
error_dma:
11641165
spi_qup_release_dma(master);
11651166
error:
1166-
clk_disable_unprepare(cclk);
1167-
clk_disable_unprepare(iclk);
11681167
spi_master_put(master);
11691168
return ret;
11701169
}

0 commit comments

Comments
 (0)