Commit 87bf5ab8 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Grant Likely

spi/fsl-espi: Make sure pm is within 2..32

The reference manual says that pm has to stay within 2 and 32. So the
lowest frequency is 32 and DIV16 set, the highest is 2 and DIV16 unset.
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarGrant Likely <grant.likely@secretlab.ca>
parent 35faa55c
...@@ -182,16 +182,18 @@ static int fsl_espi_setup_transfer(struct spi_device *spi, ...@@ -182,16 +182,18 @@ static int fsl_espi_setup_transfer(struct spi_device *spi,
cs->hw_mode |= CSMODE_DIV16; cs->hw_mode |= CSMODE_DIV16;
pm = DIV_ROUND_UP(mpc8xxx_spi->spibrg, hz * 16 * 4); pm = DIV_ROUND_UP(mpc8xxx_spi->spibrg, hz * 16 * 4);
WARN_ONCE(pm > 16, "%s: Requested speed is too low: %d Hz. " WARN_ONCE(pm > 33, "%s: Requested speed is too low: %d Hz. "
"Will use %d Hz instead.\n", dev_name(&spi->dev), "Will use %d Hz instead.\n", dev_name(&spi->dev),
hz, mpc8xxx_spi->spibrg / 1024); hz, mpc8xxx_spi->spibrg / (4 * 16 * (32 + 1)));
if (pm > 16) if (pm > 33)
pm = 16; pm = 33;
} else { } else {
pm = DIV_ROUND_UP(mpc8xxx_spi->spibrg, hz * 4); pm = DIV_ROUND_UP(mpc8xxx_spi->spibrg, hz * 4);
} }
if (pm) if (pm)
pm--; pm--;
if (pm < 2)
pm = 2;
cs->hw_mode |= CSMODE_PM(pm); cs->hw_mode |= CSMODE_PM(pm);
......
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