Skip to content

Commit 7b6ae47

Browse files
committed
Merge tag 'spi-fix-v5.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi fixes from Mark Brown: "A collection of driver specific fixes, there was a bit of a kerfuffle with some last minute review on hte spi-cadence-quadspi division by zero change but otherwise nothing terribly remarkable here - important fixes if you have the hardware but nothing with too wide an impact" * tag 'spi-fix-v5.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: spi: spi-bcm2835: Fix deadlock spi: cadence: Correct initialisation of runtime PM again spi: cadence-quadspi: Disable Auto-HW polling spi: spi-cadence-quadspi: Fix division by zero warning spi: spi-cadence-quadspi: Revert "Fix division by zero warning" spi: spi-cadence-quadspi: Fix division by zero warning spi: mediatek: move devm_spi_register_master position spi: mediatek: fix fifo rx mode spi: atmel: Fix CS and initialization bug spi: stm32: fixes pm_runtime calls in probe/remove spi: imx: mx51-ecspi: Reinstate low-speed CONFIGREG delay spi: stm32h7: fix full duplex irq handler handling
2 parents 7c3d49b + c45c1e8 commit 7b6ae47

File tree

7 files changed

+90
-65
lines changed

7 files changed

+90
-65
lines changed

drivers/spi/spi-atmel.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,6 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
352352
}
353353

354354
mr = spi_readl(as, MR);
355-
if (spi->cs_gpiod)
356-
gpiod_set_value(spi->cs_gpiod, 1);
357355
} else {
358356
u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0;
359357
int i;
@@ -369,8 +367,6 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
369367

370368
mr = spi_readl(as, MR);
371369
mr = SPI_BFINS(PCS, ~(1 << chip_select), mr);
372-
if (spi->cs_gpiod)
373-
gpiod_set_value(spi->cs_gpiod, 1);
374370
spi_writel(as, MR, mr);
375371
}
376372

@@ -400,8 +396,6 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
400396

401397
if (!spi->cs_gpiod)
402398
spi_writel(as, CR, SPI_BIT(LASTXFER));
403-
else
404-
gpiod_set_value(spi->cs_gpiod, 0);
405399
}
406400

407401
static void atmel_spi_lock(struct atmel_spi *as) __acquires(&as->lock)
@@ -1483,7 +1477,8 @@ static int atmel_spi_probe(struct platform_device *pdev)
14831477
master->bus_num = pdev->id;
14841478
master->num_chipselect = 4;
14851479
master->setup = atmel_spi_setup;
1486-
master->flags = (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX);
1480+
master->flags = (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX |
1481+
SPI_MASTER_GPIO_SS);
14871482
master->transfer_one = atmel_spi_one_transfer;
14881483
master->set_cs = atmel_spi_set_cs;
14891484
master->cleanup = atmel_spi_cleanup;

drivers/spi/spi-bcm2835.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ MODULE_PARM_DESC(polling_limit_us,
8383
* struct bcm2835_spi - BCM2835 SPI controller
8484
* @regs: base address of register map
8585
* @clk: core clock, divided to calculate serial clock
86+
* @clk_hz: core clock cached speed
8687
* @irq: interrupt, signals TX FIFO empty or RX FIFO ¾ full
8788
* @tfr: SPI transfer currently processed
8889
* @ctlr: SPI controller reverse lookup
@@ -116,6 +117,7 @@ MODULE_PARM_DESC(polling_limit_us,
116117
struct bcm2835_spi {
117118
void __iomem *regs;
118119
struct clk *clk;
120+
unsigned long clk_hz;
119121
int irq;
120122
struct spi_transfer *tfr;
121123
struct spi_controller *ctlr;
@@ -1045,27 +1047,26 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr,
10451047
{
10461048
struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
10471049
struct bcm2835_spidev *slv = spi_get_ctldata(spi);
1048-
unsigned long spi_hz, clk_hz, cdiv;
1050+
unsigned long spi_hz, cdiv;
10491051
unsigned long hz_per_byte, byte_limit;
10501052
u32 cs = slv->prepare_cs;
10511053

10521054
/* set clock */
10531055
spi_hz = tfr->speed_hz;
1054-
clk_hz = clk_get_rate(bs->clk);
10551056

1056-
if (spi_hz >= clk_hz / 2) {
1057+
if (spi_hz >= bs->clk_hz / 2) {
10571058
cdiv = 2; /* clk_hz/2 is the fastest we can go */
10581059
} else if (spi_hz) {
10591060
/* CDIV must be a multiple of two */
1060-
cdiv = DIV_ROUND_UP(clk_hz, spi_hz);
1061+
cdiv = DIV_ROUND_UP(bs->clk_hz, spi_hz);
10611062
cdiv += (cdiv % 2);
10621063

10631064
if (cdiv >= 65536)
10641065
cdiv = 0; /* 0 is the slowest we can go */
10651066
} else {
10661067
cdiv = 0; /* 0 is the slowest we can go */
10671068
}
1068-
tfr->effective_speed_hz = cdiv ? (clk_hz / cdiv) : (clk_hz / 65536);
1069+
tfr->effective_speed_hz = cdiv ? (bs->clk_hz / cdiv) : (bs->clk_hz / 65536);
10691070
bcm2835_wr(bs, BCM2835_SPI_CLK, cdiv);
10701071

10711072
/* handle all the 3-wire mode */
@@ -1354,6 +1355,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
13541355
return bs->irq ? bs->irq : -ENODEV;
13551356

13561357
clk_prepare_enable(bs->clk);
1358+
bs->clk_hz = clk_get_rate(bs->clk);
13571359

13581360
err = bcm2835_dma_init(ctlr, &pdev->dev, bs);
13591361
if (err)

drivers/spi/spi-cadence-quadspi.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ static unsigned int cqspi_calc_dummy(const struct spi_mem_op *op, bool dtr)
309309
{
310310
unsigned int dummy_clk;
311311

312+
if (!op->dummy.nbytes)
313+
return 0;
314+
312315
dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
313316
if (dtr)
314317
dummy_clk /= 2;
@@ -797,19 +800,20 @@ static int cqspi_write_setup(struct cqspi_flash_pdata *f_pdata,
797800
reg = cqspi_calc_rdreg(f_pdata);
798801
writel(reg, reg_base + CQSPI_REG_RD_INSTR);
799802

800-
if (f_pdata->dtr) {
801-
/*
802-
* Some flashes like the cypress Semper flash expect a 4-byte
803-
* dummy address with the Read SR command in DTR mode, but this
804-
* controller does not support sending address with the Read SR
805-
* command. So, disable write completion polling on the
806-
* controller's side. spi-nor will take care of polling the
807-
* status register.
808-
*/
809-
reg = readl(reg_base + CQSPI_REG_WR_COMPLETION_CTRL);
810-
reg |= CQSPI_REG_WR_DISABLE_AUTO_POLL;
811-
writel(reg, reg_base + CQSPI_REG_WR_COMPLETION_CTRL);
812-
}
803+
/*
804+
* SPI NAND flashes require the address of the status register to be
805+
* passed in the Read SR command. Also, some SPI NOR flashes like the
806+
* cypress Semper flash expect a 4-byte dummy address in the Read SR
807+
* command in DTR mode.
808+
*
809+
* But this controller does not support address phase in the Read SR
810+
* command when doing auto-HW polling. So, disable write completion
811+
* polling on the controller's side. spinand and spi-nor will take
812+
* care of polling the status register.
813+
*/
814+
reg = readl(reg_base + CQSPI_REG_WR_COMPLETION_CTRL);
815+
reg |= CQSPI_REG_WR_DISABLE_AUTO_POLL;
816+
writel(reg, reg_base + CQSPI_REG_WR_COMPLETION_CTRL);
813817

814818
reg = readl(reg_base + CQSPI_REG_SIZE);
815819
reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK;

drivers/spi/spi-cadence.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ static int cdns_spi_probe(struct platform_device *pdev)
517517
goto clk_dis_apb;
518518
}
519519

520+
pm_runtime_use_autosuspend(&pdev->dev);
521+
pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
522+
pm_runtime_get_noresume(&pdev->dev);
523+
pm_runtime_set_active(&pdev->dev);
524+
pm_runtime_enable(&pdev->dev);
525+
520526
ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs);
521527
if (ret < 0)
522528
master->num_chipselect = CDNS_SPI_DEFAULT_NUM_CS;
@@ -531,11 +537,6 @@ static int cdns_spi_probe(struct platform_device *pdev)
531537
/* SPI controller initializations */
532538
cdns_spi_init_hw(xspi);
533539

534-
pm_runtime_set_active(&pdev->dev);
535-
pm_runtime_enable(&pdev->dev);
536-
pm_runtime_use_autosuspend(&pdev->dev);
537-
pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
538-
539540
irq = platform_get_irq(pdev, 0);
540541
if (irq <= 0) {
541542
ret = -ENXIO;
@@ -566,6 +567,9 @@ static int cdns_spi_probe(struct platform_device *pdev)
566567

567568
master->bits_per_word_mask = SPI_BPW_MASK(8);
568569

570+
pm_runtime_mark_last_busy(&pdev->dev);
571+
pm_runtime_put_autosuspend(&pdev->dev);
572+
569573
ret = spi_register_master(master);
570574
if (ret) {
571575
dev_err(&pdev->dev, "spi_register_master failed\n");

drivers/spi/spi-imx.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static int mx51_ecspi_prepare_message(struct spi_imx_data *spi_imx,
506506
{
507507
struct spi_device *spi = msg->spi;
508508
u32 ctrl = MX51_ECSPI_CTRL_ENABLE;
509-
u32 testreg;
509+
u32 testreg, delay;
510510
u32 cfg = readl(spi_imx->base + MX51_ECSPI_CONFIG);
511511

512512
/* set Master or Slave mode */
@@ -567,14 +567,31 @@ static int mx51_ecspi_prepare_message(struct spi_imx_data *spi_imx,
567567

568568
writel(cfg, spi_imx->base + MX51_ECSPI_CONFIG);
569569

570+
/*
571+
* Wait until the changes in the configuration register CONFIGREG
572+
* propagate into the hardware. It takes exactly one tick of the
573+
* SCLK clock, but we will wait two SCLK clock just to be sure. The
574+
* effect of the delay it takes for the hardware to apply changes
575+
* is noticable if the SCLK clock run very slow. In such a case, if
576+
* the polarity of SCLK should be inverted, the GPIO ChipSelect might
577+
* be asserted before the SCLK polarity changes, which would disrupt
578+
* the SPI communication as the device on the other end would consider
579+
* the change of SCLK polarity as a clock tick already.
580+
*/
581+
delay = (2 * 1000000) / spi_imx->spi_bus_clk;
582+
if (likely(delay < 10)) /* SCLK is faster than 100 kHz */
583+
udelay(delay);
584+
else /* SCLK is _very_ slow */
585+
usleep_range(delay, delay + 10);
586+
570587
return 0;
571588
}
572589

573590
static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
574591
struct spi_device *spi)
575592
{
576593
u32 ctrl = readl(spi_imx->base + MX51_ECSPI_CTRL);
577-
u32 clk, delay;
594+
u32 clk;
578595

579596
/* Clear BL field and set the right value */
580597
ctrl &= ~MX51_ECSPI_CTRL_BL_MASK;
@@ -596,23 +613,6 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
596613

597614
writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL);
598615

599-
/*
600-
* Wait until the changes in the configuration register CONFIGREG
601-
* propagate into the hardware. It takes exactly one tick of the
602-
* SCLK clock, but we will wait two SCLK clock just to be sure. The
603-
* effect of the delay it takes for the hardware to apply changes
604-
* is noticable if the SCLK clock run very slow. In such a case, if
605-
* the polarity of SCLK should be inverted, the GPIO ChipSelect might
606-
* be asserted before the SCLK polarity changes, which would disrupt
607-
* the SPI communication as the device on the other end would consider
608-
* the change of SCLK polarity as a clock tick already.
609-
*/
610-
delay = (2 * 1000000) / clk;
611-
if (likely(delay < 10)) /* SCLK is faster than 100 kHz */
612-
udelay(delay);
613-
else /* SCLK is _very_ slow */
614-
usleep_range(delay, delay + 10);
615-
616616
return 0;
617617
}
618618

drivers/spi/spi-mt65xx.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,23 @@ static int mtk_spi_fifo_transfer(struct spi_master *master,
427427
mtk_spi_setup_packet(master);
428428

429429
cnt = xfer->len / 4;
430-
iowrite32_rep(mdata->base + SPI_TX_DATA_REG, xfer->tx_buf, cnt);
430+
if (xfer->tx_buf)
431+
iowrite32_rep(mdata->base + SPI_TX_DATA_REG, xfer->tx_buf, cnt);
432+
433+
if (xfer->rx_buf)
434+
ioread32_rep(mdata->base + SPI_RX_DATA_REG, xfer->rx_buf, cnt);
431435

432436
remainder = xfer->len % 4;
433437
if (remainder > 0) {
434438
reg_val = 0;
435-
memcpy(&reg_val, xfer->tx_buf + (cnt * 4), remainder);
436-
writel(reg_val, mdata->base + SPI_TX_DATA_REG);
439+
if (xfer->tx_buf) {
440+
memcpy(&reg_val, xfer->tx_buf + (cnt * 4), remainder);
441+
writel(reg_val, mdata->base + SPI_TX_DATA_REG);
442+
}
443+
if (xfer->rx_buf) {
444+
reg_val = readl(mdata->base + SPI_RX_DATA_REG);
445+
memcpy(xfer->rx_buf + (cnt * 4), &reg_val, remainder);
446+
}
437447
}
438448

439449
mtk_spi_enable_transfer(master);
@@ -793,12 +803,6 @@ static int mtk_spi_probe(struct platform_device *pdev)
793803

794804
pm_runtime_enable(&pdev->dev);
795805

796-
ret = devm_spi_register_master(&pdev->dev, master);
797-
if (ret) {
798-
dev_err(&pdev->dev, "failed to register master (%d)\n", ret);
799-
goto err_disable_runtime_pm;
800-
}
801-
802806
if (mdata->dev_comp->need_pad_sel) {
803807
if (mdata->pad_num != master->num_chipselect) {
804808
dev_err(&pdev->dev,
@@ -838,6 +842,12 @@ static int mtk_spi_probe(struct platform_device *pdev)
838842
dev_notice(&pdev->dev, "SPI dma_set_mask(%d) failed, ret:%d\n",
839843
addr_bits, ret);
840844

845+
ret = devm_spi_register_master(&pdev->dev, master);
846+
if (ret) {
847+
dev_err(&pdev->dev, "failed to register master (%d)\n", ret);
848+
goto err_disable_runtime_pm;
849+
}
850+
841851
return 0;
842852

843853
err_disable_runtime_pm:

drivers/spi/spi-stm32.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -884,15 +884,18 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
884884
ier = readl_relaxed(spi->base + STM32H7_SPI_IER);
885885

886886
mask = ier;
887-
/* EOTIE is triggered on EOT, SUSP and TXC events. */
887+
/*
888+
* EOTIE enables irq from EOT, SUSP and TXC events. We need to set
889+
* SUSP to acknowledge it later. TXC is automatically cleared
890+
*/
891+
888892
mask |= STM32H7_SPI_SR_SUSP;
889893
/*
890-
* When TXTF is set, DXPIE and TXPIE are cleared. So in case of
891-
* Full-Duplex, need to poll RXP event to know if there are remaining
892-
* data, before disabling SPI.
894+
* DXPIE is set in Full-Duplex, one IT will be raised if TXP and RXP
895+
* are set. So in case of Full-Duplex, need to poll TXP and RXP event.
893896
*/
894-
if (spi->rx_buf && !spi->cur_usedma)
895-
mask |= STM32H7_SPI_SR_RXP;
897+
if ((spi->cur_comm == SPI_FULL_DUPLEX) && !spi->cur_usedma)
898+
mask |= STM32H7_SPI_SR_TXP | STM32H7_SPI_SR_RXP;
896899

897900
if (!(sr & mask)) {
898901
dev_warn(spi->dev, "spurious IT (sr=0x%08x, ier=0x%08x)\n",
@@ -1925,6 +1928,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
19251928
master->can_dma = stm32_spi_can_dma;
19261929

19271930
pm_runtime_set_active(&pdev->dev);
1931+
pm_runtime_get_noresume(&pdev->dev);
19281932
pm_runtime_enable(&pdev->dev);
19291933

19301934
ret = spi_register_master(master);
@@ -1940,6 +1944,8 @@ static int stm32_spi_probe(struct platform_device *pdev)
19401944

19411945
err_pm_disable:
19421946
pm_runtime_disable(&pdev->dev);
1947+
pm_runtime_put_noidle(&pdev->dev);
1948+
pm_runtime_set_suspended(&pdev->dev);
19431949
err_dma_release:
19441950
if (spi->dma_tx)
19451951
dma_release_channel(spi->dma_tx);
@@ -1956,17 +1962,21 @@ static int stm32_spi_remove(struct platform_device *pdev)
19561962
struct spi_master *master = platform_get_drvdata(pdev);
19571963
struct stm32_spi *spi = spi_master_get_devdata(master);
19581964

1965+
pm_runtime_get_sync(&pdev->dev);
1966+
19591967
spi_unregister_master(master);
19601968
spi->cfg->disable(spi);
19611969

1970+
pm_runtime_disable(&pdev->dev);
1971+
pm_runtime_put_noidle(&pdev->dev);
1972+
pm_runtime_set_suspended(&pdev->dev);
19621973
if (master->dma_tx)
19631974
dma_release_channel(master->dma_tx);
19641975
if (master->dma_rx)
19651976
dma_release_channel(master->dma_rx);
19661977

19671978
clk_disable_unprepare(spi->clk);
19681979

1969-
pm_runtime_disable(&pdev->dev);
19701980

19711981
pinctrl_pm_select_sleep_state(&pdev->dev);
19721982

0 commit comments

Comments
 (0)