SPI: spi_txx9: Fix bit rate calculation

TXx9 SPI bit rate is calculated by:
fBR = (spi-baseclk) / (n + 1)
Fix calculation of min_speed_hz, max_speed_hz and n.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by Atsushi Nemoto and committed by Ralf Baechle dbf763a2 56f3f55c

Changed files
+6 -7
drivers
+6 -7
drivers/spi/spi_txx9.c
··· 29 29 30 30 31 31 #define SPI_FIFO_SIZE 4 32 + #define SPI_MAX_DIVIDER 0xff /* Max. value for SPCR1.SER */ 33 + #define SPI_MIN_DIVIDER 1 /* Min. value for SPCR1.SER */ 32 34 33 35 #define TXx9_SPMCR 0x00 34 36 #define TXx9_SPCR0 0x04 ··· 195 193 196 194 if (prev_speed_hz != speed_hz 197 195 || prev_bits_per_word != bits_per_word) { 198 - u32 n = (c->baseclk + speed_hz - 1) / speed_hz; 199 - if (n < 1) 200 - n = 1; 201 - else if (n > 0xff) 202 - n = 0xff; 196 + int n = DIV_ROUND_UP(c->baseclk, speed_hz) - 1; 197 + n = clamp(n, SPI_MIN_DIVIDER, SPI_MAX_DIVIDER); 203 198 /* enter config mode */ 204 199 txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, 205 200 TXx9_SPMCR); ··· 369 370 goto exit; 370 371 } 371 372 c->baseclk = clk_get_rate(c->clk); 372 - c->min_speed_hz = (c->baseclk + 0xff - 1) / 0xff; 373 - c->max_speed_hz = c->baseclk; 373 + c->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1); 374 + c->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1); 374 375 375 376 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 376 377 if (!res)