Skip to content

Commit 4039974

Browse files
committed
Merge tag 'spi-fix-v5.19-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi fixes from Mark Brown: "A bunch of driver specific fixes, plus a fix for spi-mem's status polling for devices that use GPIO chip selects and a DT bindings examples fix that helps with the validation work" * tag 'spi-fix-v5.19-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: spi: rockchip: Unmask IRQ at the final to avoid preemption spi: dt-bindings: Fix unevaluatedProperties warnings in examples spi: spi-mem: Fix spi_mem_poll_status() spi: cadence: Detect transmit FIFO depth spi: spi-cadence: Fix SPI CS gets toggling sporadically
2 parents bed0518 + 419bc8f commit 4039974

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

Documentation/devicetree/bindings/spi/microchip,mpfs-spi.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,5 @@ examples:
4747
clocks = <&clkcfg CLK_SPI0>;
4848
interrupt-parent = <&plic>;
4949
interrupts = <54>;
50-
spi-max-frequency = <25000000>;
5150
};
5251
...

Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ examples:
110110
pinctrl-names = "default";
111111
pinctrl-0 = <&qup_spi1_default>;
112112
interrupts = <GIC_SPI 602 IRQ_TYPE_LEVEL_HIGH>;
113-
spi-max-frequency = <50000000>;
114113
#address-cells = <1>;
115114
#size-cells = <0>;
116115
};

drivers/spi/spi-cadence.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#define CDNS_SPI_BAUD_DIV_SHIFT 3 /* Baud rate divisor shift in CR */
7070
#define CDNS_SPI_SS_SHIFT 10 /* Slave Select field shift in CR */
7171
#define CDNS_SPI_SS0 0x1 /* Slave Select zero */
72+
#define CDNS_SPI_NOSS 0x3C /* No Slave select */
7273

7374
/*
7475
* SPI Interrupt Registers bit Masks
@@ -92,9 +93,6 @@
9293
#define CDNS_SPI_ER_ENABLE 0x00000001 /* SPI Enable Bit Mask */
9394
#define CDNS_SPI_ER_DISABLE 0x0 /* SPI Disable Bit Mask */
9495

95-
/* SPI FIFO depth in bytes */
96-
#define CDNS_SPI_FIFO_DEPTH 128
97-
9896
/* Default number of chip select lines */
9997
#define CDNS_SPI_DEFAULT_NUM_CS 4
10098

@@ -110,6 +108,7 @@
110108
* @rx_bytes: Number of bytes requested
111109
* @dev_busy: Device busy flag
112110
* @is_decoded_cs: Flag for decoder property set or not
111+
* @tx_fifo_depth: Depth of the TX FIFO
113112
*/
114113
struct cdns_spi {
115114
void __iomem *regs;
@@ -123,6 +122,7 @@ struct cdns_spi {
123122
int rx_bytes;
124123
u8 dev_busy;
125124
u32 is_decoded_cs;
125+
unsigned int tx_fifo_depth;
126126
};
127127

128128
/* Macros for the SPI controller read/write */
@@ -304,7 +304,7 @@ static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi)
304304
{
305305
unsigned long trans_cnt = 0;
306306

307-
while ((trans_cnt < CDNS_SPI_FIFO_DEPTH) &&
307+
while ((trans_cnt < xspi->tx_fifo_depth) &&
308308
(xspi->tx_bytes > 0)) {
309309

310310
/* When xspi in busy condition, bytes may send failed,
@@ -450,19 +450,42 @@ static int cdns_prepare_transfer_hardware(struct spi_master *master)
450450
* @master: Pointer to the spi_master structure which provides
451451
* information about the controller.
452452
*
453-
* This function disables the SPI master controller.
453+
* This function disables the SPI master controller when no slave selected.
454454
*
455455
* Return: 0 always
456456
*/
457457
static int cdns_unprepare_transfer_hardware(struct spi_master *master)
458458
{
459459
struct cdns_spi *xspi = spi_master_get_devdata(master);
460+
u32 ctrl_reg;
460461

461-
cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
462+
/* Disable the SPI if slave is deselected */
463+
ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR);
464+
ctrl_reg = (ctrl_reg & CDNS_SPI_CR_SSCTRL) >> CDNS_SPI_SS_SHIFT;
465+
if (ctrl_reg == CDNS_SPI_NOSS)
466+
cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
462467

463468
return 0;
464469
}
465470

471+
/**
472+
* cdns_spi_detect_fifo_depth - Detect the FIFO depth of the hardware
473+
* @xspi: Pointer to the cdns_spi structure
474+
*
475+
* The depth of the TX FIFO is a synthesis configuration parameter of the SPI
476+
* IP. The FIFO threshold register is sized so that its maximum value can be the
477+
* FIFO size - 1. This is used to detect the size of the FIFO.
478+
*/
479+
static void cdns_spi_detect_fifo_depth(struct cdns_spi *xspi)
480+
{
481+
/* The MSBs will get truncated giving us the size of the FIFO */
482+
cdns_spi_write(xspi, CDNS_SPI_THLD, 0xffff);
483+
xspi->tx_fifo_depth = cdns_spi_read(xspi, CDNS_SPI_THLD) + 1;
484+
485+
/* Reset to default */
486+
cdns_spi_write(xspi, CDNS_SPI_THLD, 0x1);
487+
}
488+
466489
/**
467490
* cdns_spi_probe - Probe method for the SPI driver
468491
* @pdev: Pointer to the platform_device structure
@@ -535,6 +558,8 @@ static int cdns_spi_probe(struct platform_device *pdev)
535558
if (ret < 0)
536559
xspi->is_decoded_cs = 0;
537560

561+
cdns_spi_detect_fifo_depth(xspi);
562+
538563
/* SPI controller initializations */
539564
cdns_spi_init_hw(xspi);
540565

drivers/spi/spi-mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ int spi_mem_poll_status(struct spi_mem *mem,
808808
op->data.dir != SPI_MEM_DATA_IN)
809809
return -EINVAL;
810810

811-
if (ctlr->mem_ops && ctlr->mem_ops->poll_status) {
811+
if (ctlr->mem_ops && ctlr->mem_ops->poll_status && !mem->spi->cs_gpiod) {
812812
ret = spi_mem_access_start(mem);
813813
if (ret)
814814
return ret;

drivers/spi/spi-rockchip.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,18 @@ static int rockchip_spi_prepare_irq(struct rockchip_spi *rs,
381381
rs->tx_left = rs->tx ? xfer->len / rs->n_bytes : 0;
382382
rs->rx_left = xfer->len / rs->n_bytes;
383383

384-
if (rs->cs_inactive)
385-
writel_relaxed(INT_RF_FULL | INT_CS_INACTIVE, rs->regs + ROCKCHIP_SPI_IMR);
386-
else
387-
writel_relaxed(INT_RF_FULL, rs->regs + ROCKCHIP_SPI_IMR);
384+
writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR);
385+
388386
spi_enable_chip(rs, true);
389387

390388
if (rs->tx_left)
391389
rockchip_spi_pio_writer(rs);
392390

391+
if (rs->cs_inactive)
392+
writel_relaxed(INT_RF_FULL | INT_CS_INACTIVE, rs->regs + ROCKCHIP_SPI_IMR);
393+
else
394+
writel_relaxed(INT_RF_FULL, rs->regs + ROCKCHIP_SPI_IMR);
395+
393396
/* 1 means the transfer is in progress */
394397
return 1;
395398
}

0 commit comments

Comments
 (0)