[PATCH] spi: Correct SPI clock frequency setting in spi_mpc8xxx

Grant Likely grant.likely at secretlab.ca
Wed Feb 17 02:32:11 EST 2010


[cc'd spi-devel-general, linuxppc-dev & Kumar Gala]

On Tue, Feb 16, 2010 at 7:12 AM, Ernst Schwab <eschwab at online.de> wrote:
> From: Ernst Schwab <eschwab at online.de>
>
> Correct SPI clock frequency division factor rounding, preventing clock rates
> higher than the maximum specified clock frequency being used.

For a patch like this, it helps to also cc the driver's specific
maintainer (Kumar) and to explicitly state your rational so that I
don't need to re-derive your calculations.  I'm more likely to merge a
brand new, if potentially broken, driver than to merge a change to an
existing driver that I don't know the impact of.

The change forces the division to always round up instead of down.
Please describe (for me now, and for people looking at the commit in
the future) the mathematical reason for the changes.

Thanks,
g.

>
> Signed-off-by: Ernst Schwab <eschwab at online.de>
> ---
> Tested on MPC8314.
>
> diff -up linux-2.6.33-rc8.orig/drivers/spi/spi_mpc8xxx.c linux-2.6.33-rc8/drivers/spi/spi_mpc8xxx.c
> --- linux-2.6.33-rc8.orig/drivers/spi/spi_mpc8xxx.c     2010-02-12 20:07:45.000000000 +0100
> +++ linux-2.6.33-rc8/drivers/spi/spi_mpc8xxx.c  2010-02-15 14:08:33.000000000 +0100
> @@ -365,7 +365,7 @@ int mpc8xxx_spi_setup_transfer(struct sp
>
>        if ((mpc8xxx_spi->spibrg / hz) > 64) {
>                cs->hw_mode |= SPMODE_DIV16;
> -               pm = mpc8xxx_spi->spibrg / (hz * 64);
> +               pm = (mpc8xxx_spi->spibrg - 1) / (hz * 64) + 1;
>
>                WARN_ONCE(pm > 16, "%s: Requested speed is too low: %d Hz. "
>                          "Will use %d Hz instead.\n", dev_name(&spi->dev),
> @@ -373,7 +373,7 @@ int mpc8xxx_spi_setup_transfer(struct sp
>                if (pm > 16)
>                        pm = 16;
>        } else
> -               pm = mpc8xxx_spi->spibrg / (hz * 4);
> +               pm = (mpc8xxx_spi->spibrg - 1) / (hz * 4) + 1;
>        if (pm)
>                pm--;
>
>
>
>
> --
>
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.


More information about the Linuxppc-dev mailing list