Skip to content

Commit 3a4bf92

Browse files
Jon Linbroonie
authored andcommitted
spi: rockchip: Preset cs-high and clk polarity in setup progress
After power up, the cs and clock is in default status, and the cs-high and clock polarity dts property configuration will take no effect until the calling of rockchip_spi_config in the first transmission. So preset them to make sure a correct voltage before the first transmission coming. Signed-off-by: Jon Lin <jon.lin@rock-chips.com> Link: https://lore.kernel.org/r/20220216014028.8123-5-jon.lin@rock-chips.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 869f2c9 commit 3a4bf92

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

drivers/spi/spi-rockchip.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,29 @@ static bool rockchip_spi_can_dma(struct spi_controller *ctlr,
713713
return xfer->len / bytes_per_word >= rs->fifo_len;
714714
}
715715

716+
static int rockchip_spi_setup(struct spi_device *spi)
717+
{
718+
struct rockchip_spi *rs = spi_controller_get_devdata(spi->controller);
719+
u32 cr0;
720+
721+
pm_runtime_get_sync(rs->dev);
722+
723+
cr0 = readl_relaxed(rs->regs + ROCKCHIP_SPI_CTRLR0);
724+
725+
cr0 &= ~(0x3 << CR0_SCPH_OFFSET);
726+
cr0 |= ((spi->mode & 0x3) << CR0_SCPH_OFFSET);
727+
if (spi->mode & SPI_CS_HIGH && spi->chip_select <= 1)
728+
cr0 |= BIT(spi->chip_select) << CR0_SOI_OFFSET;
729+
else if (spi->chip_select <= 1)
730+
cr0 &= ~(BIT(spi->chip_select) << CR0_SOI_OFFSET);
731+
732+
writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0);
733+
734+
pm_runtime_put(rs->dev);
735+
736+
return 0;
737+
}
738+
716739
static int rockchip_spi_probe(struct platform_device *pdev)
717740
{
718741
int ret;
@@ -840,6 +863,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)
840863
ctlr->min_speed_hz = rs->freq / BAUDR_SCKDV_MAX;
841864
ctlr->max_speed_hz = min(rs->freq / BAUDR_SCKDV_MIN, MAX_SCLK_OUT);
842865

866+
ctlr->setup = rockchip_spi_setup;
843867
ctlr->set_cs = rockchip_spi_set_cs;
844868
ctlr->transfer_one = rockchip_spi_transfer_one;
845869
ctlr->max_transfer_size = rockchip_spi_max_transfer_size;

0 commit comments

Comments
 (0)