spi: imx: mx51-ecspi: Fix low-speed CONFIGREG delay calculation
authorMarek Vasut <marex@denx.de>
Mon, 26 Jul 2021 10:01:02 +0000 (12:01 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 26 Jul 2021 17:57:14 +0000 (18:57 +0100)
commit53ca18acbe645656132fb5a329833db711067e54
treeb2488f96935811b5820d654fda66d9bfbc8e5881
parente09f2ab8eecc6dcbd7013a1303cbe56b00dc9fb0
spi: imx: mx51-ecspi: Fix low-speed CONFIGREG delay calculation

The spi_imx->spi_bus_clk may be uninitialized and thus also zero in
mx51_ecspi_prepare_message(), which would lead to division by zero
in kernel. Since bitbang .setup_transfer callback which initializes
the spi_imx->spi_bus_clk is called after bitbang prepare_message
callback, iterate over all the transfers in spi_message, find the
one with lowest bus frequency, and use that bus frequency for the
delay calculation.

Note that it is not possible to move this CONFIGREG delay back into
the .setup_transfer callback, because that is invoked too late, after
the GPIO chipselects were already configured.

Fixes: 135cbd378eab ("spi: imx: mx51-ecspi: Reinstate low-speed CONFIGREG delay")
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210726100102.5188-1-marex@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-imx.c