diff options
author | Atsushi Nemoto <anemo@mba.ocn.ne.jp> | 2009-09-03 09:59:01 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2009-12-02 18:58:32 -0500 |
commit | dbf763a2f1c117cfe45bbbd2c874a150f0e0900b (patch) | |
tree | 175d8b9c1848a0923150ef1bc4ef003a9a032d2c /drivers | |
parent | 56f3f55cf9b604b924353ab6fcdac5fee5637ae3 (diff) |
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>
Diffstat (limited to 'drivers')
-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) |