diff options
author | Thomas Koeller <thomas.koeller@baslerweb.com> | 2010-04-26 05:01:45 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-05-25 02:23:54 -0400 |
commit | 0c2a2ae32793e3500a15a449612485f5d17dd431 (patch) | |
tree | 36e31ce3b9f789d6ccc5c273d24a2f149f0e6d2b /drivers | |
parent | 41c4221ca6b9db8ea63d2c2323c0e7a8865eba6e (diff) |
spi/davinci: Fix clock prescale factor computation
Computation of the clock prescaler value returned bogus results if
the requested SPI clock was impossible to set. It now sets either
the maximum or minimum clock frequency, as appropriate.
Signed-off-by: Thomas Koeller <thomas.koeller@baslerweb.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/spi/davinci_spi.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index 95afb6b77395..b85090caf7cf 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c | |||
@@ -301,7 +301,7 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, | |||
301 | struct davinci_spi *davinci_spi; | 301 | struct davinci_spi *davinci_spi; |
302 | struct davinci_spi_platform_data *pdata; | 302 | struct davinci_spi_platform_data *pdata; |
303 | u8 bits_per_word = 0; | 303 | u8 bits_per_word = 0; |
304 | u32 hz = 0, prescale; | 304 | u32 hz = 0, prescale = 0, clkspeed; |
305 | 305 | ||
306 | davinci_spi = spi_master_get_devdata(spi->master); | 306 | davinci_spi = spi_master_get_devdata(spi->master); |
307 | pdata = davinci_spi->pdata; | 307 | pdata = davinci_spi->pdata; |
@@ -338,10 +338,16 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, | |||
338 | set_fmt_bits(davinci_spi->base, bits_per_word & 0x1f, | 338 | set_fmt_bits(davinci_spi->base, bits_per_word & 0x1f, |
339 | spi->chip_select); | 339 | spi->chip_select); |
340 | 340 | ||
341 | prescale = ((clk_get_rate(davinci_spi->clk) / hz) - 1) & 0xff; | 341 | clkspeed = clk_get_rate(davinci_spi->clk); |
342 | if (hz > clkspeed / 2) | ||
343 | prescale = 1 << 8; | ||
344 | if (hz < clkspeed / 256) | ||
345 | prescale = 255 << 8; | ||
346 | if (!prescale) | ||
347 | prescale = ((clkspeed / hz - 1) << 8) & 0x0000ff00; | ||
342 | 348 | ||
343 | clear_fmt_bits(davinci_spi->base, 0x0000ff00, spi->chip_select); | 349 | clear_fmt_bits(davinci_spi->base, 0x0000ff00, spi->chip_select); |
344 | set_fmt_bits(davinci_spi->base, prescale << 8, spi->chip_select); | 350 | set_fmt_bits(davinci_spi->base, prescale, spi->chip_select); |
345 | 351 | ||
346 | return 0; | 352 | return 0; |
347 | } | 353 | } |