Patchwork [U-Boot,v5,5/8] SPI: add Dove support to Kirkwood SPI driver

login
register
mail settings
Submitter Sascha Silbe
Date June 25, 2013, 9:27 p.m.
Message ID <1372195668-25496-6-git-send-email-t-uboot@infra-silbe.de>
Download mbox | patch
Permalink /patch/254420/
State Rejected
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Comments

Sascha Silbe - June 25, 2013, 9:27 p.m.
The SPI support on Dove is very similar to that on Kirkwood (and
possibly orion5x as well). Instead of duplicating the code, we tweak
the Kirkwood driver so it works for Dove, too.

Signed-off-by: Sascha Silbe <t-uboot@infra-silbe.de>
---
 v4->v5: Modify Kirkwood driver rather than duplicating it.

 The patch description might do with slightly more detail, but I'd
 like some feedback on the approach first. The patch itself should be
 pretty self-explanatory.

 arch/arm/include/asm/arch-kirkwood/spi.h | 27 ------------------
 drivers/spi/kirkwood_spi.c               | 47 +++++++++++++++++++++++++++++---
 2 files changed, 43 insertions(+), 31 deletions(-)
Sebastian Hesselbarth - June 25, 2013, 10:45 p.m.
On 06/25/2013 11:27 PM, Sascha Silbe wrote:
> The SPI support on Dove is very similar to that on Kirkwood (and
> possibly orion5x as well). Instead of duplicating the code, we tweak
> the Kirkwood driver so it works for Dove, too.
>
> Signed-off-by: Sascha Silbe<t-uboot@infra-silbe.de>
> ---
>   v4->v5: Modify Kirkwood driver rather than duplicating it.
>
>   The patch description might do with slightly more detail, but I'd
>   like some feedback on the approach first. The patch itself should be
>   pretty self-explanatory.
>
>   arch/arm/include/asm/arch-kirkwood/spi.h | 27 ------------------
>   drivers/spi/kirkwood_spi.c               | 47 +++++++++++++++++++++++++++++---
>   2 files changed, 43 insertions(+), 31 deletions(-)
>
> diff --git a/arch/arm/include/asm/arch-kirkwood/spi.h b/arch/arm/include/asm/arch-kirkwood/spi.h
> index 113f258..4145f62 100644
> --- a/arch/arm/include/asm/arch-kirkwood/spi.h
> +++ b/arch/arm/include/asm/arch-kirkwood/spi.h
> @@ -27,16 +27,6 @@
>   #ifndef __KW_SPI_H__
>   #define __KW_SPI_H__
>
> -/* SPI Registers on kirkwood SOC */
> -struct kwspi_registers {
> -	u32 ctrl;	/* 0x10600 */
> -	u32 cfg;	/* 0x10604 */
> -	u32 dout;	/* 0x10608 */
> -	u32 din;	/* 0x1060c */
> -	u32 irq_cause;	/* 0x10610 */
> -	u32 irq_mask;	/* 0x10614 */
> -};
> -
>   /* They are used to define CONFIG_SYS_KW_SPI_MPP
>    * each of the below #defines selects which mpp is
>    * configured for each SPI signal in spi_claim_bus
> @@ -48,21 +38,4 @@ struct kwspi_registers {
>   #define SCK_MPP10	(1<<  1)
>   #define MISO_MPP11	(1<<  2)
>
> -#define KWSPI_CLKPRESCL_MASK	0x1f
> -#define KWSPI_CLKPRESCL_MIN	0x12
> -#define KWSPI_CSN_ACT		1 /* Activates serial memory interface */
> -#define KWSPI_SMEMRDY		(1<<  1) /* SerMem Data xfer ready */
> -#define KWSPI_IRQUNMASK		1 /* unmask SPI interrupt */
> -#define KWSPI_IRQMASK		0 /* mask SPI interrupt */
> -#define KWSPI_SMEMRDIRQ		1 /* SerMem data xfer ready irq */
> -#define KWSPI_XFERLEN_1BYTE	0
> -#define KWSPI_XFERLEN_2BYTE	(1<<  5)
> -#define KWSPI_XFERLEN_MASK	(1<<  5)
> -#define KWSPI_ADRLEN_1BYTE	0
> -#define KWSPI_ADRLEN_2BYTE	1<<  8
> -#define KWSPI_ADRLEN_3BYTE	2<<  8
> -#define KWSPI_ADRLEN_4BYTE	3<<  8
> -#define KWSPI_ADRLEN_MASK	3<<  8
> -#define KWSPI_TIMEOUT		10000
> -
>   #endif /* __KW_SPI_H__ */
> diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
> index caa91e3..4e4c814 100644
> --- a/drivers/spi/kirkwood_spi.c
> +++ b/drivers/spi/kirkwood_spi.c
> @@ -28,23 +28,58 @@
>   #include<malloc.h>
>   #include<spi.h>
>   #include<asm/io.h>
> -#include<asm/arch/kirkwood.h>
> -#include<asm/arch/spi.h>
> -#include<asm/arch/mpp.h>
> +#include<asm/arch/config.h>
>
> -static struct kwspi_registers *spireg = (struct kwspi_registers *)KW_SPI_BASE;
> +/* SPI Registers on Dove/Kirkwood SOC */
> +struct kwspi_registers {
> +	u32 ctrl;	/* 0x00 */
> +	u32 cfg;	/* 0x04 */
> +	u32 dout;	/* 0x08 */
> +	u32 din;	/* 0x0c */
> +	u32 irq_cause;	/* 0x10 */
> +	u32 irq_mask;	/* 0x14 */
> +};
>
> +#if defined(CONFIG_KIRKWOOD)
> +static struct kwspi_registers *spireg =
> +        (struct kwspi_registers *)KW_SPI_BASE;
> +#elif defined(CONFIG_DOVE)
> +static struct kwspi_registers *spireg =
> +        (struct kwspi_registers *)DOVE_SPI_BASE;
> +#endif
> +
> +#define KWSPI_CLKPRESCL_MASK	0x1f
> +#define KWSPI_CLKPRESCL_MIN	0x12

After I looked deeper in Dove FS SPI registers today, I can now say that
Dove SPI allows some more prescaler settings. Nothing critical, as
kirkwood_spi finds the closest spi clock rate less that requested
frequency. By not using the extended prescaler, you may end up with
spi clock running slower than possible but it will not break anything.

Sebastian
Wolfgang Denk - June 26, 2013, 2:11 p.m.
Dear Sascha Silbe,

In message <1372195668-25496-6-git-send-email-t-uboot@infra-silbe.de> you wrote:
> The SPI support on Dove is very similar to that on Kirkwood (and
> possibly orion5x as well). Instead of duplicating the code, we tweak
> the Kirkwood driver so it works for Dove, too.
> 
> Signed-off-by: Sascha Silbe <t-uboot@infra-silbe.de>

Not checkpatch clean: 2 errors, 2 warnings.  Please fix.


Best regards,

Wolfgang Denk
Jagannadha Sutradharudu Teki - Dec. 20, 2013, 7:05 p.m.
Hi Sascha Silbe,

On Wed, Jun 26, 2013 at 7:41 PM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Sascha Silbe,
>
> In message <1372195668-25496-6-git-send-email-t-uboot@infra-silbe.de> you wrote:
>> The SPI support on Dove is very similar to that on Kirkwood (and
>> possibly orion5x as well). Instead of duplicating the code, we tweak
>> the Kirkwood driver so it works for Dove, too.
>>
>> Signed-off-by: Sascha Silbe <t-uboot@infra-silbe.de>
>
> Not checkpatch clean: 2 errors, 2 warnings.  Please fix.

Any inputs on this.
Jagannadha Sutradharudu Teki - Jan. 8, 2014, 12:50 p.m.
On Sat, Dec 21, 2013 at 12:35 AM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
> Hi Sascha Silbe,
>
> On Wed, Jun 26, 2013 at 7:41 PM, Wolfgang Denk <wd@denx.de> wrote:
>> Dear Sascha Silbe,
>>
>> In message <1372195668-25496-6-git-send-email-t-uboot@infra-silbe.de> you wrote:
>>> The SPI support on Dove is very similar to that on Kirkwood (and
>>> possibly orion5x as well). Instead of duplicating the code, we tweak
>>> the Kirkwood driver so it works for Dove, too.
>>>
>>> Signed-off-by: Sascha Silbe <t-uboot@infra-silbe.de>
>>
>> Not checkpatch clean: 2 errors, 2 warnings.  Please fix.
>
> Any inputs on this.

Last ping!

Patch

diff --git a/arch/arm/include/asm/arch-kirkwood/spi.h b/arch/arm/include/asm/arch-kirkwood/spi.h
index 113f258..4145f62 100644
--- a/arch/arm/include/asm/arch-kirkwood/spi.h
+++ b/arch/arm/include/asm/arch-kirkwood/spi.h
@@ -27,16 +27,6 @@ 
 #ifndef __KW_SPI_H__
 #define __KW_SPI_H__
 
-/* SPI Registers on kirkwood SOC */
-struct kwspi_registers {
-	u32 ctrl;	/* 0x10600 */
-	u32 cfg;	/* 0x10604 */
-	u32 dout;	/* 0x10608 */
-	u32 din;	/* 0x1060c */
-	u32 irq_cause;	/* 0x10610 */
-	u32 irq_mask;	/* 0x10614 */
-};
-
 /* They are used to define CONFIG_SYS_KW_SPI_MPP
  * each of the below #defines selects which mpp is
  * configured for each SPI signal in spi_claim_bus
@@ -48,21 +38,4 @@  struct kwspi_registers {
 #define SCK_MPP10	(1 << 1)
 #define MISO_MPP11	(1 << 2)
 
-#define KWSPI_CLKPRESCL_MASK	0x1f
-#define KWSPI_CLKPRESCL_MIN	0x12
-#define KWSPI_CSN_ACT		1 /* Activates serial memory interface */
-#define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */
-#define KWSPI_IRQUNMASK		1 /* unmask SPI interrupt */
-#define KWSPI_IRQMASK		0 /* mask SPI interrupt */
-#define KWSPI_SMEMRDIRQ		1 /* SerMem data xfer ready irq */
-#define KWSPI_XFERLEN_1BYTE	0
-#define KWSPI_XFERLEN_2BYTE	(1 << 5)
-#define KWSPI_XFERLEN_MASK	(1 << 5)
-#define KWSPI_ADRLEN_1BYTE	0
-#define KWSPI_ADRLEN_2BYTE	1 << 8
-#define KWSPI_ADRLEN_3BYTE	2 << 8
-#define KWSPI_ADRLEN_4BYTE	3 << 8
-#define KWSPI_ADRLEN_MASK	3 << 8
-#define KWSPI_TIMEOUT		10000
-
 #endif /* __KW_SPI_H__ */
diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index caa91e3..4e4c814 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -28,23 +28,58 @@ 
 #include <malloc.h>
 #include <spi.h>
 #include <asm/io.h>
-#include <asm/arch/kirkwood.h>
-#include <asm/arch/spi.h>
-#include <asm/arch/mpp.h>
+#include <asm/arch/config.h>
 
-static struct kwspi_registers *spireg = (struct kwspi_registers *)KW_SPI_BASE;
+/* SPI Registers on Dove/Kirkwood SOC */
+struct kwspi_registers {
+	u32 ctrl;	/* 0x00 */
+	u32 cfg;	/* 0x04 */
+	u32 dout;	/* 0x08 */
+	u32 din;	/* 0x0c */
+	u32 irq_cause;	/* 0x10 */
+	u32 irq_mask;	/* 0x14 */
+};
 
+#if defined(CONFIG_KIRKWOOD)
+static struct kwspi_registers *spireg =
+        (struct kwspi_registers *)KW_SPI_BASE;
+#elif defined(CONFIG_DOVE)
+static struct kwspi_registers *spireg =
+        (struct kwspi_registers *)DOVE_SPI_BASE;
+#endif
+
+#define KWSPI_CLKPRESCL_MASK	0x1f
+#define KWSPI_CLKPRESCL_MIN	0x12
+#define KWSPI_CSN_ACT		1 /* Activates serial memory interface */
+#define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */
+#define KWSPI_IRQUNMASK		1 /* unmask SPI interrupt */
+#define KWSPI_IRQMASK		0 /* mask SPI interrupt */
+#define KWSPI_SMEMRDIRQ		1 /* SerMem data xfer ready irq */
+#define KWSPI_XFERLEN_1BYTE	0
+#define KWSPI_XFERLEN_2BYTE	(1 << 5)
+#define KWSPI_XFERLEN_MASK	(1 << 5)
+#define KWSPI_ADRLEN_1BYTE	0
+#define KWSPI_ADRLEN_2BYTE	(1 << 8)
+#define KWSPI_ADRLEN_3BYTE	(2 << 8)
+#define KWSPI_ADRLEN_4BYTE	(3 << 8)
+#define KWSPI_ADRLEN_MASK	(3 << 8)
+#define KWSPI_TIMEOUT		10000
+
+#if defined(CONFIG_KIRKWOOD)
 u32 cs_spi_mpp_back[2];
+#endif
 
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 				unsigned int max_hz, unsigned int mode)
 {
 	struct spi_slave *slave;
 	u32 data;
+#if defined(CONFIG_KIRKWOOD)
 	static const u32 kwspi_mpp_config[2][2] = {
 		{ MPP0_SPI_SCn, 0 }, /* if cs == 0 */
 		{ MPP7_SPI_SCn, 0 } /* if cs != 0 */
 	};
+#endif
 
 	if (!spi_cs_is_valid(bus, cs))
 		return NULL;
@@ -67,15 +102,19 @@  struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	writel(KWSPI_SMEMRDIRQ, &spireg->irq_cause);
 	writel(KWSPI_IRQMASK, &spireg->irq_mask);
 
+#if defined(CONFIG_KIRKWOOD)
 	/* program mpp registers to select  SPI_CSn */
 	kirkwood_mpp_conf(kwspi_mpp_config[cs ? 1 : 0], cs_spi_mpp_back);
+#endif
 
 	return slave;
 }
 
 void spi_free_slave(struct spi_slave *slave)
 {
+#if defined(CONFIG_KIRKWOOD)
 	kirkwood_mpp_conf(cs_spi_mpp_back, NULL);
+#endif
 	free(slave);
 }