LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix mpc83xx spi prescale modulus calculate
@ 2008-06-20  9:38 Chen Gong
  2008-06-20  9:47 ` Li Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chen Gong @ 2008-06-20  9:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Chen Gong

Signed-off-by: Chen Gong <g.chen@freescale.com>
---
 drivers/spi/spi_mpc83xx.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c
index 6832da6..070c621 100644
--- a/drivers/spi/spi_mpc83xx.c
+++ b/drivers/spi/spi_mpc83xx.c
@@ -266,21 +266,24 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 
 	cs->hw_mode |= SPMODE_LEN(bits_per_word);
 
-	if ((mpc83xx_spi->spibrg / hz) >= 64) {
-		pm = mpc83xx_spi->spibrg / (hz * 64) - 1;
-		if (pm > 0x0f) {
-			dev_err(&spi->dev, "Requested speed is too "
-				"low: %d Hz. Will use %d Hz instead.\n",
-				hz, mpc83xx_spi->spibrg / 1024);
-			pm = 0x0f;
+	if ((mpc83xx_spi->spibrg / hz) > 64) {
+		pm = mpc83xx_spi->spibrg / (hz * 64);
+		if (pm > 16) {
+			cs->hw_mode |= SPMODE_DIV16;
+			pm /= 16;
+			if (pm > 16) {
+				dev_err(&spi->dev, "Requested speed is too "
+					"low: %d Hz. Will use %d Hz instead.\n",
+					hz, mpc83xx_spi->spibrg / 1024);
+				pm = 16;
+			}
 		}
-		cs->hw_mode |= SPMODE_PM(pm) | SPMODE_DIV16;
-	} else {
+	} else
 		pm = mpc83xx_spi->spibrg / (hz * 4);
-		if (pm)
-			pm--;
-		cs->hw_mode |= SPMODE_PM(pm);
-	}
+	if (pm)
+		pm--;
+
+	cs->hw_mode |= SPMODE_PM(pm);
 	regval =  mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode);
 	if (cs->hw_mode != regval) {
 		unsigned long flags;
-- 
1.5.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] fix mpc83xx spi prescale modulus calculate
  2008-06-20  9:38 [PATCH] fix mpc83xx spi prescale modulus calculate Chen Gong
@ 2008-06-20  9:47 ` Li Yang
  2008-06-20 12:28 ` Anton Vorontsov
  2008-06-20 13:12 ` Kumar Gala
  2 siblings, 0 replies; 4+ messages in thread
From: Li Yang @ 2008-06-20  9:47 UTC (permalink / raw)
  To: Chen Gong, linuxppc-dev

> -----Original Message-----
> From: linuxppc-dev-bounces+leoli=3Dfreescale.com@ozlabs.org=20
> [mailto:linuxppc-dev-bounces+leoli=3Dfreescale.com@ozlabs.org]=20
> On Behalf Of Chen Gong
> Sent: Friday, June 20, 2008 5:38 PM
> To: linuxppc-dev@ozlabs.org
> Cc: Chen Gong
> Subject: [PATCH] fix mpc83xx spi prescale modulus calculate
>=20
> Signed-off-by: Chen Gong <g.chen@freescale.com>

I think you should at least cc David Brownell and SPI mailling list.

- Leo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fix mpc83xx spi prescale modulus calculate
  2008-06-20  9:38 [PATCH] fix mpc83xx spi prescale modulus calculate Chen Gong
  2008-06-20  9:47 ` Li Yang
@ 2008-06-20 12:28 ` Anton Vorontsov
  2008-06-20 13:12 ` Kumar Gala
  2 siblings, 0 replies; 4+ messages in thread
From: Anton Vorontsov @ 2008-06-20 12:28 UTC (permalink / raw)
  To: Chen Gong; +Cc: linuxppc-dev

On Fri, Jun 20, 2008 at 05:38:17PM +0800, Chen Gong wrote:
> Signed-off-by: Chen Gong <g.chen@freescale.com>

The patch lacks any description. E.g. at which frequencies the current
math breaks, and why?

> ---
>  drivers/spi/spi_mpc83xx.c |   29 ++++++++++++++++-------------
>  1 files changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c
> index 6832da6..070c621 100644
> --- a/drivers/spi/spi_mpc83xx.c
> +++ b/drivers/spi/spi_mpc83xx.c
> @@ -266,21 +266,24 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
>  
>  	cs->hw_mode |= SPMODE_LEN(bits_per_word);
>  
> -	if ((mpc83xx_spi->spibrg / hz) >= 64) {
> -		pm = mpc83xx_spi->spibrg / (hz * 64) - 1;
> -		if (pm > 0x0f) {
> -			dev_err(&spi->dev, "Requested speed is too "
> -				"low: %d Hz. Will use %d Hz instead.\n",
> -				hz, mpc83xx_spi->spibrg / 1024);
> -			pm = 0x0f;
> +	if ((mpc83xx_spi->spibrg / hz) > 64) {
> +		pm = mpc83xx_spi->spibrg / (hz * 64);
> +		if (pm > 16) {

Suppose this didn't happen. So we calculated:
pm = mpc83xx_spi->spibrg / (hz * 64);
And we didn't set any hw flag.

> +			cs->hw_mode |= SPMODE_DIV16;
> +			pm /= 16;
> +			if (pm > 16) {
> +				dev_err(&spi->dev, "Requested speed is too "
> +					"low: %d Hz. Will use %d Hz instead.\n",
> +					hz, mpc83xx_spi->spibrg / 1024);
> +				pm = 16;
> +			}
>  		}
> -		cs->hw_mode |= SPMODE_PM(pm) | SPMODE_DIV16;
> -	} else {
> +	} else
>  		pm = mpc83xx_spi->spibrg / (hz * 4);

Now suppose this did happen. So we calculated:
pm = mpc83xx_spi->spibrg / (hz * 4);
And we didn't set any hw flag either.

So, we used two different formulas with the same hw flags.

Maybe I'm missing something, but this looks quite wrong.

> -		if (pm)
> -			pm--;
> -		cs->hw_mode |= SPMODE_PM(pm);
> -	}
> +	if (pm)
> +		pm--;
> +
> +	cs->hw_mode |= SPMODE_PM(pm);
>  	regval =  mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode);
>  	if (cs->hw_mode != regval) {
>  		unsigned long flags;
> -- 
> 1.5.4

-- 
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fix mpc83xx spi prescale modulus calculate
  2008-06-20  9:38 [PATCH] fix mpc83xx spi prescale modulus calculate Chen Gong
  2008-06-20  9:47 ` Li Yang
  2008-06-20 12:28 ` Anton Vorontsov
@ 2008-06-20 13:12 ` Kumar Gala
  2 siblings, 0 replies; 4+ messages in thread
From: Kumar Gala @ 2008-06-20 13:12 UTC (permalink / raw)
  To: Chen Gong; +Cc: linuxppc-dev


On Jun 20, 2008, at 4:38 AM, Chen Gong wrote:

> Signed-off-by: Chen Gong <g.chen@freescale.com>
> ---
> drivers/spi/spi_mpc83xx.c |   29 ++++++++++++++++-------------
> 1 files changed, 16 insertions(+), 13 deletions(-)
>

Please CC the SPI devel list.

- k

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-06-20 13:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-20  9:38 [PATCH] fix mpc83xx spi prescale modulus calculate Chen Gong
2008-06-20  9:47 ` Li Yang
2008-06-20 12:28 ` Anton Vorontsov
2008-06-20 13:12 ` Kumar Gala

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox