aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFranklin S Cooper Jr <fcooper@ti.com>2015-07-22 08:32:21 -0400
committerMark Brown <broonie@kernel.org>2015-07-24 12:35:48 -0400
commitbba732d86694f7217a41e83a2c1deb42ed9aa7fd (patch)
tree61e30c00d99ae293b546fc7226ea4c2fd1d6cc78
parentbc0195aad0daa2ad5b0d76cce22b167bc3435590 (diff)
spi: davinci: Set prescale value based on register value
Within davinci_spi_get_prescale() the prescale has two meanings. First one being the calculated prescale value and then at the end translates it to the prescale value that will be written to the SPI register. At first glance this can be confusing especially when comparing the minimum prescale value against what is seen in the TRM. To simplify things make it clear that the calculated prescale value will always be based on the value that will be written into the SPI register. Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-davinci.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 987afebea093..b4605c4158f4 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -255,7 +255,7 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value)
255 * This function calculates the prescale value that generates a clock rate 255 * This function calculates the prescale value that generates a clock rate
256 * less than or equal to the specified maximum. 256 * less than or equal to the specified maximum.
257 * 257 *
258 * Returns: calculated prescale - 1 for easy programming into SPI registers 258 * Returns: calculated prescale value for easy programming into SPI registers
259 * or negative error number if valid prescalar cannot be updated. 259 * or negative error number if valid prescalar cannot be updated.
260 */ 260 */
261static inline int davinci_spi_get_prescale(struct davinci_spi *dspi, 261static inline int davinci_spi_get_prescale(struct davinci_spi *dspi,
@@ -263,12 +263,13 @@ static inline int davinci_spi_get_prescale(struct davinci_spi *dspi,
263{ 263{
264 int ret; 264 int ret;
265 265
266 ret = DIV_ROUND_UP(clk_get_rate(dspi->clk), max_speed_hz); 266 /* Subtract 1 to match what will be programmed into SPI register. */
267 ret = DIV_ROUND_UP(clk_get_rate(dspi->clk), max_speed_hz) - 1;
267 268
268 if (ret < 1 || ret > 256) 269 if (ret < 0 || ret > 255)
269 return -EINVAL; 270 return -EINVAL;
270 271
271 return ret - 1; 272 return ret;
272} 273}
273 274
274/** 275/**