Skip to content

Commit 3672bb8

Browse files
Dafna Hirschfeldbroonie
authored andcommitted
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: 04e6bb0 ("spi: modify set_cs_timing parameter") Signed-off-by: Dafna Hirschfeld <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 75e33c5 commit 3672bb8

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

drivers/spi/spi-mt65xx.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -233,36 +233,44 @@ static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
233233
return delay;
234234
inactive = (delay * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000)) / 1000;
235235

236-
setup = setup ? setup : 1;
237-
hold = hold ? hold : 1;
238-
inactive = inactive ? inactive : 1;
239-
240-
reg_val = readl(mdata->base + SPI_CFG0_REG);
241-
if (mdata->dev_comp->enhance_timing) {
242-
hold = min_t(u32, hold, 0x10000);
243-
setup = min_t(u32, setup, 0x10000);
244-
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
245-
reg_val |= (((hold - 1) & 0xffff)
246-
<< SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
247-
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
248-
reg_val |= (((setup - 1) & 0xffff)
249-
<< SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
250-
} else {
251-
hold = min_t(u32, hold, 0x100);
252-
setup = min_t(u32, setup, 0x100);
253-
reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
254-
reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
255-
reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
256-
reg_val |= (((setup - 1) & 0xff)
257-
<< SPI_CFG0_CS_SETUP_OFFSET);
236+
if (hold || setup) {
237+
reg_val = readl(mdata->base + SPI_CFG0_REG);
238+
if (mdata->dev_comp->enhance_timing) {
239+
if (hold) {
240+
hold = min_t(u32, hold, 0x10000);
241+
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
242+
reg_val |= (((hold - 1) & 0xffff)
243+
<< SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
244+
}
245+
if (setup) {
246+
setup = min_t(u32, setup, 0x10000);
247+
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
248+
reg_val |= (((setup - 1) & 0xffff)
249+
<< SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
250+
}
251+
} else {
252+
if (hold) {
253+
hold = min_t(u32, hold, 0x100);
254+
reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
255+
reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
256+
}
257+
if (setup) {
258+
setup = min_t(u32, setup, 0x100);
259+
reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
260+
reg_val |= (((setup - 1) & 0xff)
261+
<< SPI_CFG0_CS_SETUP_OFFSET);
262+
}
263+
}
264+
writel(reg_val, mdata->base + SPI_CFG0_REG);
258265
}
259-
writel(reg_val, mdata->base + SPI_CFG0_REG);
260266

261-
inactive = min_t(u32, inactive, 0x100);
262-
reg_val = readl(mdata->base + SPI_CFG1_REG);
263-
reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
264-
reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
265-
writel(reg_val, mdata->base + SPI_CFG1_REG);
267+
if (inactive) {
268+
inactive = min_t(u32, inactive, 0x100);
269+
reg_val = readl(mdata->base + SPI_CFG1_REG);
270+
reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
271+
reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
272+
writel(reg_val, mdata->base + SPI_CFG1_REG);
273+
}
266274

267275
return 0;
268276
}

0 commit comments

Comments
 (0)