Skip to content

Commit 5aca5f1

Browse files
lucaceresoliJon Lin
authored andcommitted
UPSTREAM: spi: rockchip: fix missing error on unsupported SPI_CS_HIGH
The hardware (except for the ROCKCHIP_SPI_VER2_TYPE2 version) does not support active-high native chip selects. However if such a CS is configured the core does not error as it normally should, because the 'ctlr->use_gpio_descriptors = true' line in rockchip_spi_probe() makes the core set SPI_CS_HIGH in ctlr->mode_bits. In such a case the spi-rockchip driver operates normally but produces an active-low chip select signal without notice. There is no provision in the current core code to handle this situation. Fix by adding a check in the ctlr->setup function (similarly to what spi-atmel.c does). This cannot be done reading the SPI_CS_HIGH but in ctlr->mode_bits because that bit gets always set by the core for master mode (see above). Fixes: eb1262e ("spi: spi-rockchip: use num-cs property and ctlr->enable_gpiods") Change-Id: I3e1065973cd5f3deac486bbc9a3bad230ace4971 Signed-off-by: Luca Ceresoli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Jon Lin <[email protected]> (cherry picked from commit d5d933f)
1 parent b3cb70b commit 5aca5f1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/spi/spi-rockchip.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ struct rockchip_spi {
199199
struct pinctrl_state *high_speed_state;
200200
bool slave_abort;
201201
bool cs_inactive; /* spi slave tansmition stop when cs inactive */
202+
bool cs_high_supported; /* native CS supports active-high polarity */
203+
202204
struct spi_transfer *xfer; /* Store xfer temporarily */
203205
spinlock_t lock; /* prevent I/O concurrent access */
204206
};
@@ -742,6 +744,11 @@ static int rockchip_spi_setup(struct spi_device *spi)
742744
struct rockchip_spi *rs = spi_controller_get_devdata(spi->controller);
743745
u32 cr0;
744746

747+
if (!spi->cs_gpiod && (spi->mode & SPI_CS_HIGH) && !rs->cs_high_supported) {
748+
dev_warn(&spi->dev, "setup: non GPIO CS can't be active-high\n");
749+
return -EINVAL;
750+
}
751+
745752
pm_runtime_get_sync(rs->dev);
746753

747754
cr0 = readl_relaxed(rs->regs + ROCKCHIP_SPI_CTRLR0);
@@ -933,6 +940,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)
933940

934941
switch (readl_relaxed(rs->regs + ROCKCHIP_SPI_VERSION)) {
935942
case ROCKCHIP_SPI_VER2_TYPE2:
943+
rs->cs_high_supported = true;
936944
ctlr->mode_bits |= SPI_CS_HIGH;
937945
if (ctlr->can_dma && slave_mode)
938946
rs->cs_inactive = true;

0 commit comments

Comments
 (0)