History

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.

Atsushi Nemoto committed 17 years ago

Commit dbf763a1 parent 56f3f551 file · +6 −7Browse files

Unified · Split

drivers/spi/spi_txx9.c+6−7
@@ -29,6 +29,8 @@ · 28 unmodified lines
2929
3030
3131 #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 */
3234
3335 #define TXx9_SPMCR 0x00
3436 #define TXx9_SPCR0 0x04
@@ -193,11 +195,8 @@ static void txx9spi_work_one(struct txx9spi *c, struct spi_message *m) · 158 unmodified lines
193195
194196 if (prev_speed_hz != speed_hz
195197 || prev_bits_per_word != bits_per_word) {
196− u32 n = (c->baseclk + speed_hz - 1) / speed_hz;
197− if (n < 1)
198− n = 1;
199− else if (n > 0xff)
200− n = 0xff;
198+ int n = DIV_ROUND_UP(c->baseclk, speed_hz) - 1;
199+ n = clamp(n, SPI_MIN_DIVIDER, SPI_MAX_DIVIDER);
201200 /* enter config mode */
202201 txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR,
203202 TXx9_SPMCR);
@@ -370,8 +369,8 @@ static int __init txx9spi_probe(struct platform_device *dev) · 166 unmodified lines
370369 goto exit;
371370 }
372371 c->baseclk = clk_get_rate(c->clk);
373− c->min_speed_hz = (c->baseclk + 0xff - 1) / 0xff;
374− c->max_speed_hz = c->baseclk;
372+ c->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1);
373+ c->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1);
375374
376375 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
377376 if (!res)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t