Commit 3672bb82 authored by Dafna Hirschfeld's avatar Dafna Hirschfeld Committed by Mark Brown

spi: mediatek: skip delays if they are 0

In the function 'mtk_spi_set_hw_cs_timing'
the 'setup', 'hold' and 'inactive' delays are configured.
In case those values are 0 it causes errors on mt8173:

cros-ec-i2c-tunnel 1100a000.spi:ec@0:i2c-tunnel0:
	Error transferring EC i2c message -71
cros-ec-spi spi0.0: EC failed to respond in time.

This patch fixes that issues by setting only the values
that are not 0.

Fixes: 04e6bb0d ("spi: modify set_cs_timing parameter")
Signed-off-by: default avatarDafna Hirschfeld <dafna.hirschfeld@collabora.com>
Link: https://lore.kernel.org/r/20211001152153.4604-1-dafna.hirschfeld@collabora.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 75e33c55
...@@ -233,36 +233,44 @@ static int mtk_spi_set_hw_cs_timing(struct spi_device *spi) ...@@ -233,36 +233,44 @@ static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
return delay; return delay;
inactive = (delay * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000)) / 1000; inactive = (delay * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000)) / 1000;
setup = setup ? setup : 1; if (hold || setup) {
hold = hold ? hold : 1; reg_val = readl(mdata->base + SPI_CFG0_REG);
inactive = inactive ? inactive : 1; if (mdata->dev_comp->enhance_timing) {
if (hold) {
reg_val = readl(mdata->base + SPI_CFG0_REG); hold = min_t(u32, hold, 0x10000);
if (mdata->dev_comp->enhance_timing) { reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
hold = min_t(u32, hold, 0x10000); reg_val |= (((hold - 1) & 0xffff)
setup = min_t(u32, setup, 0x10000); << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET); }
reg_val |= (((hold - 1) & 0xffff) if (setup) {
<< SPI_ADJUST_CFG0_CS_HOLD_OFFSET); setup = min_t(u32, setup, 0x10000);
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET); reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
reg_val |= (((setup - 1) & 0xffff) reg_val |= (((setup - 1) & 0xffff)
<< SPI_ADJUST_CFG0_CS_SETUP_OFFSET); << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
} else { }
hold = min_t(u32, hold, 0x100); } else {
setup = min_t(u32, setup, 0x100); if (hold) {
reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET); hold = min_t(u32, hold, 0x100);
reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET); reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET); reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
reg_val |= (((setup - 1) & 0xff) }
<< SPI_CFG0_CS_SETUP_OFFSET); if (setup) {
setup = min_t(u32, setup, 0x100);
reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
reg_val |= (((setup - 1) & 0xff)
<< SPI_CFG0_CS_SETUP_OFFSET);
}
}
writel(reg_val, mdata->base + SPI_CFG0_REG);
} }
writel(reg_val, mdata->base + SPI_CFG0_REG);
inactive = min_t(u32, inactive, 0x100); if (inactive) {
reg_val = readl(mdata->base + SPI_CFG1_REG); inactive = min_t(u32, inactive, 0x100);
reg_val &= ~SPI_CFG1_CS_IDLE_MASK; reg_val = readl(mdata->base + SPI_CFG1_REG);
reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET); reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
writel(reg_val, mdata->base + SPI_CFG1_REG); reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
writel(reg_val, mdata->base + SPI_CFG1_REG);
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment