linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mpc52xx_psc_spi: enlarge clock range
@ 2009-09-16 11:07 Dragos Carp
  2009-09-16 20:48 ` [spi-devel-general] " Wolfram Sang
       [not found] ` <20090916204853.GA21627-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Dragos Carp @ 2009-09-16 11:07 UTC (permalink / raw)
  To: David Brownell, spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

allow spi clock values bellow 78kbps down to ca. 300bps

Signed-off-by: Dragos Carp <dragos.carp-+ybMorV4k0dBDgjK7y7TUQ@public.gmane.org>
---
 mpc52xx_psc_spi.c |   26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)


[-- Attachment #2: mpc52xx_psc_spi.patch --]
[-- Type: text/plain, Size: 1833 bytes --]

diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 1b74d5c..b15882a 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -78,7 +78,8 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
 	struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
 	struct mpc52xx_psc __iomem *psc = mps->psc;
 	u32 sicr;
-	u16 ccr;
+	u32 ccr;
+	u32 bitclkdiv;
 
 	sicr = in_be32(&psc->sicr);
 
@@ -98,17 +99,16 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
 		sicr &= ~0x10000000;
 	out_be32(&psc->sicr, sicr);
 
-	/* Set clock frequency and bits per word
-	 * Because psc->ccr is defined as 16bit register instead of 32bit
-	 * just set the lower byte of BitClkDiv
-	 */
-	ccr = in_be16((u16 __iomem *)&psc->ccr);
-	ccr &= 0xFF00;
-	if (cs->speed_hz)
-		ccr |= (MCLK / cs->speed_hz - 1) & 0xFF;
-	else /* by default SPI Clk 1MHz */
-		ccr |= (MCLK / 1000000 - 1) & 0xFF;
-	out_be16((u16 __iomem *)&psc->ccr, ccr);
+	/* Set clock frequency */
+	bitclkdiv = MCLK / (cs->speed_hz ? cs->speed_hz : 1000000) - 1;
+	bitclkdiv &= 0xFFFF;
+	bitclkdiv |= (bitclkdiv & 0xFF) << 16;	/* byte swapped */
+	bitclkdiv &= 0x00FFFF00;
+	ccr = in_be32(&psc->ccr);
+	ccr &= 0xFF0000FF;
+	ccr |= bitclkdiv;
+	out_be32(&psc->ccr, ccr);
+	
 	mps->bits_per_word = cs->bits_per_word;
 
 	if (mps->cs_control)
@@ -333,7 +333,7 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
 	/* Configure 8bit codec mode as a SPI master and use EOF flags */
 	/* SICR_SIM_CODEC8|SICR_GENCLK|SICR_SPI|SICR_MSTR|SICR_USEEOF */
 	out_be32(&psc->sicr, 0x0180C800);
-	out_be16((u16 __iomem *)&psc->ccr, 0x070F); /* default SPI Clk 1MHz */
+	out_be32(&psc->ccr, 0x07130000); /* default SPI Clk 1MHz */
 
 	/* Set 2ms DTL delay */
 	out_8(&psc->ctur, 0x00);

[-- Attachment #3: Type: text/plain, Size: 401 bytes --]

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf

[-- Attachment #4: Type: text/plain, Size: 210 bytes --]

_______________________________________________
spi-devel-general mailing list
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/spi-devel-general

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

* Re: [spi-devel-general] [PATCH] mpc52xx_psc_spi: enlarge clock range
  2009-09-16 11:07 [PATCH] mpc52xx_psc_spi: enlarge clock range Dragos Carp
@ 2009-09-16 20:48 ` Wolfram Sang
       [not found] ` <20090916204853.GA21627-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2009-09-16 20:48 UTC (permalink / raw)
  To: Dragos Carp; +Cc: spi-devel-general, David Brownell, linuxppc-dev


[-- Attachment #1.1: Type: text/plain, Size: 2677 bytes --]

Hi,

adding powerpc-list and Grant to cc.

On Wed, Sep 16, 2009 at 01:07:50PM +0200, Dragos Carp wrote:
> allow spi clock values bellow 78kbps down to ca. 300bps

Looks like your patch converts the driver from mpc5200 to mpc5200b? If this is
really all which is needed, it should support both versions, I think.

Regards,

   Wolfram

> 
> Signed-off-by: Dragos Carp <dragos.carp@toptica.com>
> ---
>  mpc52xx_psc_spi.c |   26 +++++++++++++-------------
>  1 file changed, 13 insertions(+), 13 deletions(-)
> 

> diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
> index 1b74d5c..b15882a 100644
> --- a/drivers/spi/mpc52xx_psc_spi.c
> +++ b/drivers/spi/mpc52xx_psc_spi.c
> @@ -78,7 +78,8 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
>  	struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
>  	struct mpc52xx_psc __iomem *psc = mps->psc;
>  	u32 sicr;
> -	u16 ccr;
> +	u32 ccr;
> +	u32 bitclkdiv;
>  
>  	sicr = in_be32(&psc->sicr);
>  
> @@ -98,17 +99,16 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
>  		sicr &= ~0x10000000;
>  	out_be32(&psc->sicr, sicr);
>  
> -	/* Set clock frequency and bits per word
> -	 * Because psc->ccr is defined as 16bit register instead of 32bit
> -	 * just set the lower byte of BitClkDiv
> -	 */
> -	ccr = in_be16((u16 __iomem *)&psc->ccr);
> -	ccr &= 0xFF00;
> -	if (cs->speed_hz)
> -		ccr |= (MCLK / cs->speed_hz - 1) & 0xFF;
> -	else /* by default SPI Clk 1MHz */
> -		ccr |= (MCLK / 1000000 - 1) & 0xFF;
> -	out_be16((u16 __iomem *)&psc->ccr, ccr);
> +	/* Set clock frequency */
> +	bitclkdiv = MCLK / (cs->speed_hz ? cs->speed_hz : 1000000) - 1;
> +	bitclkdiv &= 0xFFFF;
> +	bitclkdiv |= (bitclkdiv & 0xFF) << 16;	/* byte swapped */
> +	bitclkdiv &= 0x00FFFF00;
> +	ccr = in_be32(&psc->ccr);
> +	ccr &= 0xFF0000FF;
> +	ccr |= bitclkdiv;
> +	out_be32(&psc->ccr, ccr);
> +	
>  	mps->bits_per_word = cs->bits_per_word;
>  
>  	if (mps->cs_control)
> @@ -333,7 +333,7 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
>  	/* Configure 8bit codec mode as a SPI master and use EOF flags */
>  	/* SICR_SIM_CODEC8|SICR_GENCLK|SICR_SPI|SICR_MSTR|SICR_USEEOF */
>  	out_be32(&psc->sicr, 0x0180C800);
> -	out_be16((u16 __iomem *)&psc->ccr, 0x070F); /* default SPI Clk 1MHz */
> +	out_be32(&psc->ccr, 0x07130000); /* default SPI Clk 1MHz */
>  
>  	/* Set 2ms DTL delay */
>  	out_8(&psc->ctur, 0x00);

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

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

* Re: [PATCH] mpc52xx_psc_spi: enlarge clock range
       [not found] ` <20090916204853.GA21627-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
@ 2009-09-17 14:04   ` Dragos Carp
  2009-09-17 14:13     ` [spi-devel-general] " Grant Likely
       [not found]     ` <4AB241FA.9090604-+ybMorV4k0dBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Dragos Carp @ 2009-09-17 14:04 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	David Brownell, linuxppc-dev-mnsaURCQ41sdnm+yROfE0A

Hi,

I wasn't aware that MPC5200 differ from MPC5200B in this regard. I also
couldn't find any MPC5200 user manual on Freescale's webpage.
Is there a #define that I can use to distinguish between the two
processor variants? Querying the PVR register is not a nice solution
because the chip-select activate function is called in some scenarios
quite often.

Regards,
Dragos


On 09/16/2009 10:48 PM, Wolfram Sang wrote:
> Hi,
>
> adding powerpc-list and Grant to cc.
>
> On Wed, Sep 16, 2009 at 01:07:50PM +0200, Dragos Carp wrote:
>   
>> allow spi clock values bellow 78kbps down to ca. 300bps
>>     
> Looks like your patch converts the driver from mpc5200 to mpc5200b? If this is
> really all which is needed, it should support both versions, I think.
>
> Regards,
>
>    Wolfram
>
>   
>> Signed-off-by: Dragos Carp <dragos.carp-+ybMorV4k0dBDgjK7y7TUQ@public.gmane.org>
>> ---
>>  mpc52xx_psc_spi.c |   26 +++++++++++++-------------
>>  1 file changed, 13 insertions(+), 13 deletions(-)
>>
>>     
>   
>> diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
>> index 1b74d5c..b15882a 100644
>> --- a/drivers/spi/mpc52xx_psc_spi.c
>> +++ b/drivers/spi/mpc52xx_psc_spi.c
>> @@ -78,7 +78,8 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
>>  	struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
>>  	struct mpc52xx_psc __iomem *psc = mps->psc;
>>  	u32 sicr;
>> -	u16 ccr;
>> +	u32 ccr;
>> +	u32 bitclkdiv;
>>  
>>  	sicr = in_be32(&psc->sicr);
>>  
>> @@ -98,17 +99,16 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
>>  		sicr &= ~0x10000000;
>>  	out_be32(&psc->sicr, sicr);
>>  
>> -	/* Set clock frequency and bits per word
>> -	 * Because psc->ccr is defined as 16bit register instead of 32bit
>> -	 * just set the lower byte of BitClkDiv
>> -	 */
>> -	ccr = in_be16((u16 __iomem *)&psc->ccr);
>> -	ccr &= 0xFF00;
>> -	if (cs->speed_hz)
>> -		ccr |= (MCLK / cs->speed_hz - 1) & 0xFF;
>> -	else /* by default SPI Clk 1MHz */
>> -		ccr |= (MCLK / 1000000 - 1) & 0xFF;
>> -	out_be16((u16 __iomem *)&psc->ccr, ccr);
>> +	/* Set clock frequency */
>> +	bitclkdiv = MCLK / (cs->speed_hz ? cs->speed_hz : 1000000) - 1;
>> +	bitclkdiv &= 0xFFFF;
>> +	bitclkdiv |= (bitclkdiv & 0xFF) << 16;	/* byte swapped */
>> +	bitclkdiv &= 0x00FFFF00;
>> +	ccr = in_be32(&psc->ccr);
>> +	ccr &= 0xFF0000FF;
>> +	ccr |= bitclkdiv;
>> +	out_be32(&psc->ccr, ccr);
>> +	
>>  	mps->bits_per_word = cs->bits_per_word;
>>  
>>  	if (mps->cs_control)
>> @@ -333,7 +333,7 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
>>  	/* Configure 8bit codec mode as a SPI master and use EOF flags */
>>  	/* SICR_SIM_CODEC8|SICR_GENCLK|SICR_SPI|SICR_MSTR|SICR_USEEOF */
>>  	out_be32(&psc->sicr, 0x0180C800);
>> -	out_be16((u16 __iomem *)&psc->ccr, 0x070F); /* default SPI Clk 1MHz */
>> +	out_be32(&psc->ccr, 0x07130000); /* default SPI Clk 1MHz */
>>  
>>  	/* Set 2ms DTL delay */
>>  	out_8(&psc->ctur, 0x00);
>>     
>   



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf

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

* Re: [spi-devel-general] [PATCH] mpc52xx_psc_spi: enlarge clock range
  2009-09-17 14:04   ` Dragos Carp
@ 2009-09-17 14:13     ` Grant Likely
       [not found]     ` <4AB241FA.9090604-+ybMorV4k0dBDgjK7y7TUQ@public.gmane.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Grant Likely @ 2009-09-17 14:13 UTC (permalink / raw)
  To: Dragos Carp; +Cc: spi-devel-general, David Brownell, linuxppc-dev

On Thu, Sep 17, 2009 at 8:04 AM, Dragos Carp <dragos.carp@toptica.com> wrote:
> Hi,
>
> I wasn't aware that MPC5200 differ from MPC5200B in this regard. I also
> couldn't find any MPC5200 user manual on Freescale's webpage.
> Is there a #define that I can use to distinguish between the two
> processor variants? Querying the PVR register is not a nice solution
> because the chip-select activate function is called in some scenarios
> quite often.

Use the compatible value.  That's what it is there for.  Only use the
extended register format if "fsl,mpc5200b-psc-spi" is present in the
compatible list.

g.

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

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

* Re: [PATCH] mpc52xx_psc_spi: enlarge clock range
       [not found]     ` <4AB241FA.9090604-+ybMorV4k0dBDgjK7y7TUQ@public.gmane.org>
@ 2009-09-17 14:13       ` Wolfram Sang
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2009-09-17 14:13 UTC (permalink / raw)
  To: Dragos Carp
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	David Brownell, linuxppc-dev-mnsaURCQ41sdnm+yROfE0A


[-- Attachment #1.1: Type: text/plain, Size: 1017 bytes --]

> I wasn't aware that MPC5200 differ from MPC5200B in this regard. I also
> couldn't find any MPC5200 user manual on Freescale's webpage.

Hmm, it was the first hit using a web search engine :)

http://www.freescale.com/files/microcontrollers/doc/user_guide/MPC5200UM.pdf?WT_TYPE=Users%20Guides&WT_VENDOR=FREESCALE&WT_FILE_FORMAT=pdf&WT_ASSET=Documentation

> Is there a #define that I can use to distinguish between the two
> processor variants? Querying the PVR register is not a nice solution

I think you should have two different functions for calculation, one for 5200
and one for 5200B. During init query the device tree for 'fsl,mpc5200-psc-spi'
or 'fsl,mpc5200b-psc-spi' and make the driver use the proper function.

(BTW I haven't checked for further differences between 5200 and 5200B; there
may be more)

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 401 bytes --]

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf

[-- Attachment #3: Type: text/plain, Size: 210 bytes --]

_______________________________________________
spi-devel-general mailing list
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/spi-devel-general

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

end of thread, other threads:[~2009-09-17 14:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-16 11:07 [PATCH] mpc52xx_psc_spi: enlarge clock range Dragos Carp
2009-09-16 20:48 ` [spi-devel-general] " Wolfram Sang
     [not found] ` <20090916204853.GA21627-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-09-17 14:04   ` Dragos Carp
2009-09-17 14:13     ` [spi-devel-general] " Grant Likely
     [not found]     ` <4AB241FA.9090604-+ybMorV4k0dBDgjK7y7TUQ@public.gmane.org>
2009-09-17 14:13       ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).