diff mbox

[08/11] spi-dw: Ensure fifo lenght is set.

Message ID 1308794413-11069-9-git-send-email-dirk.brandewie@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

dirk.brandewie@gmail.com June 23, 2011, 2 a.m. UTC
From: Dirk Brandewie <dirk.brandewie@gmail.com>

Bug on fifo_len not being set.  The fifo sizing routine does not work
since the txfltr register can not be written while the controller is
enabled. The max value of txfltr can be larger than the fifo.  The
register allows values upto 0x3f (63) the fifo depth on the Intel
SOC's if 40

Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
---
 drivers/spi/spi-dw.c |   18 ++----------------
 1 files changed, 2 insertions(+), 16 deletions(-)

Comments

Feng Tang June 23, 2011, 2:41 a.m. UTC | #1
On Thu, 23 Jun 2011 10:00:10 +0800
"dirk.brandewie@gmail.com" <dirk.brandewie@gmail.com> wrote:

> From: Dirk Brandewie <dirk.brandewie@gmail.com>
> 
> Bug on fifo_len not being set.  The fifo sizing routine does not work
> since the txfltr register can not be written while the controller is
> enabled. The max value of txfltr can be larger than the fifo.  The
> register allows values upto 0x3f (63) the fifo depth on the Intel
> SOC's if 40
> 
> Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
> ---
>  drivers/spi/spi-dw.c |   18 ++----------------
>  1 files changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
> index ad92826..cc38aa0 100644
> --- a/drivers/spi/spi-dw.c
> +++ b/drivers/spi/spi-dw.c
> @@ -776,25 +776,11 @@ static int destroy_queue(struct spi_dw *dws)
>  /* Restart the controller, disable all interrupts, clean rx fifo */
>  static void spi_dw_hw_init(struct spi_dw *dws)
>  {
> +	BUG_ON(!dws->fifo_len);
> +
>  	spi_dw_disable(dws);
>  	spi_dw_mask_intr(dws, 0xff);
>  	spi_dw_enable(dws);
> -
> -	/*
> -	 * Try to detect the FIFO depth if not set by interface
> driver,
> -	 * the depth could be from 2 to 256 from HW spec
> -	 */
> -	if (!dws->fifo_len) {
> -		u32 fifo;
> -		for (fifo = 2; fifo <= 257; fifo++) {
> -			dw_writew(dws, txfltr, fifo);
> -			if (fifo != dw_readw(dws, txfltr))
> -				break;
> -		}
> -
> -		dws->fifo_len = (fifo == 257) ? 0 : fifo;
> -		dw_writew(dws, txfltr, 0);
> -	}
>  }

This code is requested by other community developers, the FIFO
length is adjustable for the dw_spi core when deployed on
different platforms, for those who are not certain about the
FIFO len, they can use this code to probe the FIFO len.

So we need to keep it.

>  
>  int __devinit spi_dw_add_host(struct spi_dw *dws)

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
dirk.brandewie@gmail.com June 23, 2011, 3:01 a.m. UTC | #2
On 06/22/2011 07:41 PM, Feng Tang wrote:
>
>
> On Thu, 23 Jun 2011 10:00:10 +0800
> "dirk.brandewie@gmail.com"<dirk.brandewie@gmail.com>  wrote:
>
>> From: Dirk Brandewie<dirk.brandewie@gmail.com>
>>
>> Bug on fifo_len not being set.  The fifo sizing routine does not work
>> since the txfltr register can not be written while the controller is
>> enabled. The max value of txfltr can be larger than the fifo.  The
>> register allows values upto 0x3f (63) the fifo depth on the Intel
>> SOC's if 40
>>
>> Signed-off-by: Dirk Brandewie<dirk.brandewie@gmail.com>
>> ---
>>   drivers/spi/spi-dw.c |   18 ++----------------
>>   1 files changed, 2 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
>> index ad92826..cc38aa0 100644
>> --- a/drivers/spi/spi-dw.c
>> +++ b/drivers/spi/spi-dw.c
>> @@ -776,25 +776,11 @@ static int destroy_queue(struct spi_dw *dws)
>>   /* Restart the controller, disable all interrupts, clean rx fifo */
>>   static void spi_dw_hw_init(struct spi_dw *dws)
>>   {
>> +	BUG_ON(!dws->fifo_len);
>> +
>>   	spi_dw_disable(dws);
>>   	spi_dw_mask_intr(dws, 0xff);
>>   	spi_dw_enable(dws);
>> -
>> -	/*
>> -	 * Try to detect the FIFO depth if not set by interface
>> driver,
>> -	 * the depth could be from 2 to 256 from HW spec
>> -	 */
>> -	if (!dws->fifo_len) {
>> -		u32 fifo;
>> -		for (fifo = 2; fifo<= 257; fifo++) {
>> -			dw_writew(dws, txfltr, fifo);
>> -			if (fifo != dw_readw(dws, txfltr))
>> -				break;
>> -		}
>> -
>> -		dws->fifo_len = (fifo == 257) ? 0 : fifo;
>> -		dw_writew(dws, txfltr, 0);
>> -	}
>>   }
>
> This code is requested by other community developers, the FIFO
> length is adjustable for the dw_spi core when deployed on
> different platforms, for those who are not certain about the
> FIFO len, they can use this code to probe the FIFO len.
>
> So we need to keep it.
>

Then I have bad documentation because document I have says that you can NOt 
write to txfltr while the controller is enabled.  The sizing routine as it 
stands can't work for the implementation in Moorsetown and Medfield.

If there are other SOC's that are implementing different semantics for txfltr we 
will need to handle this differently and do some runtime detection of how the 
fifo should be sized.

Can you give ne a reference to the person that requiested the sizing code so I 
can follow-up
>>
>>   int __devinit spi_dw_add_host(struct spi_dw *dws)


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
Feng Tang June 23, 2011, 3:21 a.m. UTC | #3
On Thu, 23 Jun 2011 11:01:25 +0800
Dirk Brandewie <dirk.brandewie@gmail.com> wrote:


> >> -	/*
> >> -	 * Try to detect the FIFO depth if not set by interface
> >> driver,
> >> -	 * the depth could be from 2 to 256 from HW spec
> >> -	 */
> >> -	if (!dws->fifo_len) {
> >> -		u32 fifo;
> >> -		for (fifo = 2; fifo<= 257; fifo++) {
> >> -			dw_writew(dws, txfltr, fifo);
> >> -			if (fifo != dw_readw(dws, txfltr))
> >> -				break;
> >> -		}
> >> -
> >> -		dws->fifo_len = (fifo == 257) ? 0 : fifo;
> >> -		dw_writew(dws, txfltr, 0);
> >> -	}
> >>   }
> >
> > This code is requested by other community developers, the FIFO
> > length is adjustable for the dw_spi core when deployed on
> > different platforms, for those who are not certain about the
> > FIFO len, they can use this code to probe the FIFO len.
> >
> > So we need to keep it.
> >
> 
> Then I have bad documentation because document I have says that you
> can NOt write to txfltr while the controller is enabled.  The sizing
> routine as it stands can't work for the implementation in Moorsetown
> and Medfield.
> 
> If there are other SOC's that are implementing different semantics
> for txfltr we will need to handle this differently and do some
> runtime detection of how the fifo should be sized.
> 
> Can you give ne a reference to the person that requiested the sizing
> code so I can follow-up

Git-show c587b6fa0510

commit c587b6fa05106606053fc5e8e344f07cd34ace23
Author: Feng Tang <feng.tang@intel.com>
Date:   Thu Jan 21 10:41:10 2010 +0800

    spi/dw_spi: add a FIFO depth detection

    FIFO depth is configurable for each implementation of DW core,
    so add a depth detection for those interface drivers who don't set
    the fifo_len explicitly

    Signed-off-by: Feng Tang <feng.tang@intel.com>
    Acked-by: Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>
    Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

I added the code per request from Jean-Hugues Deschenes.

Recently Alek Du has tested this code on his Medfield platform.

Thanks,
Feng

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
Grant Likely June 23, 2011, 3:55 a.m. UTC | #4
On Wed, Jun 22, 2011 at 8:00 PM,  <dirk.brandewie@gmail.com> wrote:
> From: Dirk Brandewie <dirk.brandewie@gmail.com>
>
> Bug on fifo_len not being set.  The fifo sizing routine does not work
> since the txfltr register can not be written while the controller is
> enabled. The max value of txfltr can be larger than the fifo.  The
> register allows values upto 0x3f (63) the fifo depth on the Intel
> SOC's if 40
>
> Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
> ---
>  drivers/spi/spi-dw.c |   18 ++----------------
>  1 files changed, 2 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
> index ad92826..cc38aa0 100644
> --- a/drivers/spi/spi-dw.c
> +++ b/drivers/spi/spi-dw.c
> @@ -776,25 +776,11 @@ static int destroy_queue(struct spi_dw *dws)
>  /* Restart the controller, disable all interrupts, clean rx fifo */
>  static void spi_dw_hw_init(struct spi_dw *dws)
>  {
> +       BUG_ON(!dws->fifo_len);
> +

Ditto here.  BUG is too big a reaction.  Fail to initialize the
device, sure, and print a warning, but don't BUG.

g.

>        spi_dw_disable(dws);
>        spi_dw_mask_intr(dws, 0xff);
>        spi_dw_enable(dws);
> -
> -       /*
> -        * Try to detect the FIFO depth if not set by interface driver,
> -        * the depth could be from 2 to 256 from HW spec
> -        */
> -       if (!dws->fifo_len) {
> -               u32 fifo;
> -               for (fifo = 2; fifo <= 257; fifo++) {
> -                       dw_writew(dws, txfltr, fifo);
> -                       if (fifo != dw_readw(dws, txfltr))
> -                               break;
> -               }
> -
> -               dws->fifo_len = (fifo == 257) ? 0 : fifo;
> -               dw_writew(dws, txfltr, 0);
> -       }
>  }
>
>  int __devinit spi_dw_add_host(struct spi_dw *dws)
> --
> 1.7.3.4
>
>
> ------------------------------------------------------------------------------
> Simplify data backup and recovery for your virtual environment with vRanger.
> Installation's a snap, and flexible recovery options mean your data is safe,
> secure and there when you need it. Data protection magic?
> Nope - It's vRanger. Get your free trial download today.
> http://p.sf.net/sfu/quest-sfdev2dev
> _______________________________________________
> spi-devel-general mailing list
> spi-devel-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/spi-devel-general
>
dirk.brandewie@gmail.com June 23, 2011, 4:20 a.m. UTC | #5
On 06/22/2011 08:55 PM, Grant Likely wrote:
> On Wed, Jun 22, 2011 at 8:00 PM,<dirk.brandewie@gmail.com>  wrote:
>> From: Dirk Brandewie<dirk.brandewie@gmail.com>
>>
>> Bug on fifo_len not being set.  The fifo sizing routine does not work
>> since the txfltr register can not be written while the controller is
>> enabled. The max value of txfltr can be larger than the fifo.  The
>> register allows values upto 0x3f (63) the fifo depth on the Intel
>> SOC's if 40
>>
>> Signed-off-by: Dirk Brandewie<dirk.brandewie@gmail.com>
>> ---
>>   drivers/spi/spi-dw.c |   18 ++----------------
>>   1 files changed, 2 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
>> index ad92826..cc38aa0 100644
>> --- a/drivers/spi/spi-dw.c
>> +++ b/drivers/spi/spi-dw.c
>> @@ -776,25 +776,11 @@ static int destroy_queue(struct spi_dw *dws)
>>   /* Restart the controller, disable all interrupts, clean rx fifo */
>>   static void spi_dw_hw_init(struct spi_dw *dws)
>>   {
>> +       BUG_ON(!dws->fifo_len);
>> +
>
> Ditto here.  BUG is too big a reaction.  Fail to initialize the
> device, sure, and print a warning, but don't BUG.

Ack,  I was trying to make sure the bug got caught while I was working towards 
getting the rest of my changes in.

--Dirk


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
diff mbox

Patch

diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index ad92826..cc38aa0 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -776,25 +776,11 @@  static int destroy_queue(struct spi_dw *dws)
 /* Restart the controller, disable all interrupts, clean rx fifo */
 static void spi_dw_hw_init(struct spi_dw *dws)
 {
+	BUG_ON(!dws->fifo_len);
+
 	spi_dw_disable(dws);
 	spi_dw_mask_intr(dws, 0xff);
 	spi_dw_enable(dws);
-
-	/*
-	 * Try to detect the FIFO depth if not set by interface driver,
-	 * the depth could be from 2 to 256 from HW spec
-	 */
-	if (!dws->fifo_len) {
-		u32 fifo;
-		for (fifo = 2; fifo <= 257; fifo++) {
-			dw_writew(dws, txfltr, fifo);
-			if (fifo != dw_readw(dws, txfltr))
-				break;
-		}
-
-		dws->fifo_len = (fifo == 257) ? 0 : fifo;
-		dw_writew(dws, txfltr, 0);
-	}
 }
 
 int __devinit spi_dw_add_host(struct spi_dw *dws)