Skip to content

Commit

Permalink
spi: pxa2xx: choose closest lower speed
Browse files Browse the repository at this point in the history
As per discussion [1] the best choice is to set closest speed which is not
going over the asked one.

Do the same approach for Intel Quark boards.

[1] http://www.spinics.net/lists/linux-spi/msg03389.html

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Andy Shevchenko authored and Mark Brown committed Oct 16, 2015
1 parent 289de55 commit 3ad4806
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/spi/spi-pxa2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
mul = (1 << 24) >> 1;

/* Calculate initial quot */
q1 = DIV_ROUND_CLOSEST(fref1, rate);
q1 = DIV_ROUND_UP(fref1, rate);

/* Scale q1 if it's too big */
if (q1 > 256) {
Expand All @@ -755,7 +755,7 @@ static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)

/* Case 2 */

q2 = DIV_ROUND_CLOSEST(fref2, rate);
q2 = DIV_ROUND_UP(fref2, rate);
r2 = abs(fref2 / q2 - rate);

/*
Expand All @@ -774,13 +774,13 @@ static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
mul = (1 << 24) * 2 / 5;
}

/* Check case 3 only If the divisor is big enough */
/* Check case 3 only if the divisor is big enough */
if (fref / rate >= 80) {
u64 fssp;
u32 m;

/* Calculate initial quot */
q1 = DIV_ROUND_CLOSEST(fref, rate);
q1 = DIV_ROUND_UP(fref, rate);
m = (1 << 24) / q1;

/* Get the remainder */
Expand Down

0 comments on commit 3ad4806

Please sign in to comment.