diff options
-rw-r--r-- | drivers/spi/spi_txx9.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/drivers/spi/spi_txx9.c b/drivers/spi/spi_txx9.c index 96057de133ad..19f75627c3de 100644 --- a/drivers/spi/spi_txx9.c +++ b/drivers/spi/spi_txx9.c | |||
@@ -29,6 +29,8 @@ | |||
29 | 29 | ||
30 | 30 | ||
31 | #define SPI_FIFO_SIZE 4 | 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 | #define TXx9_SPMCR 0x00 | 35 | #define TXx9_SPMCR 0x00 |
34 | #define TXx9_SPCR0 0x04 | 36 | #define TXx9_SPCR0 0x04 |
@@ -193,11 +195,8 @@ static void txx9spi_work_one(struct txx9spi *c, struct spi_message *m) | |||
193 | 195 | ||
194 | if (prev_speed_hz != speed_hz | 196 | if (prev_speed_hz != speed_hz |
195 | || prev_bits_per_word != bits_per_word) { | 197 | || prev_bits_per_word != bits_per_word) { |
196 | u32 n = (c->baseclk + speed_hz - 1) / speed_hz; | 198 | int n = DIV_ROUND_UP(c->baseclk, speed_hz) - 1; |
197 | if (n < 1) | 199 | n = clamp(n, SPI_MIN_DIVIDER, SPI_MAX_DIVIDER); |
198 | n = 1; | ||
199 | else if (n > 0xff) | ||
200 | n = 0xff; | ||
201 | /* enter config mode */ | 200 | /* enter config mode */ |
202 | txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, | 201 | txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, |
203 | TXx9_SPMCR); | 202 | TXx9_SPMCR); |
@@ -370,8 +369,8 @@ static int __init txx9spi_probe(struct platform_device *dev) | |||
370 | goto exit; | 369 | goto exit; |
371 | } | 370 | } |
372 | c->baseclk = clk_get_rate(c->clk); | 371 | c->baseclk = clk_get_rate(c->clk); |
373 | c->min_speed_hz = (c->baseclk + 0xff - 1) / 0xff; | 372 | c->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1); |
374 | c->max_speed_hz = c->baseclk; | 373 | c->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1); |
375 | 374 | ||
376 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | 375 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
377 | if (!res) | 376 | if (!res) |