Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: imx: set spi_bus_clk for mx21 and mx27

Introduce additional output parameter in spi_imx_clkdiv_1()
function to return result frequency and set it to spi_bus_clk.

This fixes division by zero bug, which occurred in
spi_imx_calculate_timeout() function.

Signed-off-by: Robert Baldyga <r.baldyga@hackerion.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Robert Baldyga and committed by
Mark Brown
32df9ff2 2dd33f9c

+9 -5
+9 -5
drivers/spi/spi-imx.c
··· 173 173 174 174 /* MX21, MX27 */ 175 175 static unsigned int spi_imx_clkdiv_1(unsigned int fin, 176 - unsigned int fspi, unsigned int max) 176 + unsigned int fspi, unsigned int max, unsigned int *fres) 177 177 { 178 178 int i; 179 179 180 180 for (i = 2; i < max; i++) 181 181 if (fspi * mxc_clkdivs[i] >= fin) 182 - return i; 182 + break; 183 183 184 - return max; 184 + *fres = fin / mxc_clkdivs[i]; 185 + return i; 185 186 } 186 187 187 188 /* MX1, MX31, MX35, MX51 CSPI */ ··· 590 589 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); 591 590 unsigned int reg = MX21_CSPICTRL_ENABLE | MX21_CSPICTRL_MASTER; 592 591 unsigned int max = is_imx27_cspi(spi_imx) ? 16 : 18; 592 + unsigned int clk; 593 593 594 - reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz, max) << 595 - MX21_CSPICTRL_DR_SHIFT; 594 + reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz, max, &clk) 595 + << MX21_CSPICTRL_DR_SHIFT; 596 + spi_imx->spi_bus_clk = clk; 597 + 596 598 reg |= config->bpw - 1; 597 599 598 600 if (spi->mode & SPI_CPHA)