Matthew Hilder

iMX28 SPI max clock rate

Discussion created by Matthew Hilder on Apr 24, 2013
Latest reply on May 6, 2013 by GraceH

Hello,

 

linux-2.6.35.3\drivers\spi\spi_mxs.c tries to set the maximum clock rate using the lines

 

rate = 1000 * ss->speed_khz / ss->divider / hz;

__raw_writel(BF_SSP_TIMING_CLOCK_DIVIDE(ss->divider) |

             BF_SSP_TIMING_CLOCK_RATE(rate - 1),

             ss->regs + HW_SSP_TIMING);

 

However this should round up the calculated rate variable otherwise the clock is set beyond the rate requested, e.g.

ss->speed_khz = 24000

ss->divider = 2

hz = 7000000  (requesting max rate of 7MHz)

 

==> rate = 1  (rounded down from 1.7)

==> SPI clock = 24000000 / (2 * (1+0)) = 12000000, i.e. 12MHz

 

This can be fixed in many ways.  I did

if ((1000 * ss->speed_khz) > (rate * ss->divider * hz))

        rate++; /* round up */

 

 

Matt.

Outcomes