public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 0/4] kirkwood spi_claim/release_bus support
@ 2012-05-30 15:42 Valentin Longchamp
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function Valentin Longchamp
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Valentin Longchamp @ 2012-05-30 15:42 UTC (permalink / raw)
  To: u-boot

This series adds generic support for the spi_claim/release_bus functions for
the kirkwood processors.

The implementation was already discussed in another thread following my first
board specific submission of the patch.

The series adds two functions to the kirkwood mpp code to be able to temporarily
save and then restore the mpp configuration.

Changes for v2:
	- save MPP configuration with mpp_read function as dicussed on ML
	- moved CS pin MPP config to spi_setup_slave only
	- add backup fo CS pin in spi_setup_slave and reset in spi_free_slave

Valentin Longchamp (4):
  kirkwood: add kirkwood_mpp_read function
  kw_spi: backup and reset the MPP of the chosen CS pin
  kw_spi: support spi_claim/release_bus functions
  kw_spi: add weak functions board_spi_claim/release_bus

 arch/arm/cpu/arm926ejs/kirkwood/mpp.c    |   41 +++++++++++++++++++
 arch/arm/include/asm/arch-kirkwood/mpp.h |    1 +
 arch/arm/include/asm/arch-kirkwood/spi.h |   11 +++++
 drivers/spi/kirkwood_spi.c               |   65 +++++++++++++++++++++++++----
 4 files changed, 109 insertions(+), 9 deletions(-)

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

* [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
  2012-05-30 15:42 [U-Boot] [PATCH v2 0/4] kirkwood spi_claim/release_bus support Valentin Longchamp
@ 2012-05-30 15:42 ` Valentin Longchamp
  2012-05-31  8:30   ` Prafulla Wadaskar
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen CS pin Valentin Longchamp
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Valentin Longchamp @ 2012-05-30 15:42 UTC (permalink / raw)
  To: u-boot

This function can be used to save current mpp state of all mpp pins
given in the mpp_list argument by reading the mpp registers, in the
second mpp_saved argument.

A later call to kirkwood_mpp_conf function with this saved list will
reset the mpp configuration as it was when kirkwood_mpp_read was called.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
cc: Holger Brunck <holger.brunck@keymile.com>
cc: Prafulla Wadaskar <prafulla@marvell.com>
---
 arch/arm/cpu/arm926ejs/kirkwood/mpp.c    |   41 ++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-kirkwood/mpp.h |    1 +
 2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
index 3da6c98..9fb9aea 100644
--- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
+++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
@@ -80,3 +80,44 @@ void kirkwood_mpp_conf(u32 *mpp_list)
 	debug("\n");
 
 }
+
+void kirkwood_mpp_read(u32 *mpp_list, u32 *mpp_saved)
+{
+	u32 mpp_ctrl[MPP_NR_REGS];
+	unsigned int variant_mask;
+	int i;
+
+	variant_mask = kirkwood_variant();
+	if (!variant_mask)
+		return;
+
+	for (i = 0; i < MPP_NR_REGS; i++) {
+		mpp_ctrl[i] = readl(MPP_CTRL(i));
+		debug(" %08x", mpp_ctrl[i]);
+	}
+
+	while (*mpp_list) {
+		unsigned int num = MPP_NUM(*mpp_list);
+		unsigned int sel;
+		int shift;
+
+		if (num > MPP_MAX) {
+			debug("kirkwood_mpp_conf: invalid MPP "
+					"number (%u)\n", num);
+			continue;
+		}
+		if (!(*mpp_list & variant_mask)) {
+			debug("kirkwood_mpp_conf: requested MPP%u config "
+				"unavailable on this hardware\n", num);
+			continue;
+		}
+
+		shift = (num & 7) << 2;
+		sel = (mpp_ctrl[num / 8] >> shift) & 0xf;
+		*mpp_saved = num | (sel << 8) | variant_mask;
+
+		mpp_list++;
+		mpp_saved++;
+	}
+}
+
diff --git a/arch/arm/include/asm/arch-kirkwood/mpp.h b/arch/arm/include/asm/arch-kirkwood/mpp.h
index b3c090e..22a64b8 100644
--- a/arch/arm/include/asm/arch-kirkwood/mpp.h
+++ b/arch/arm/include/asm/arch-kirkwood/mpp.h
@@ -313,5 +313,6 @@
 #define MPP_MAX			49
 
 void kirkwood_mpp_conf(unsigned int *mpp_list);
+void kirkwood_mpp_read(u32 *mpp_list, u32 *mpp_saved);
 
 #endif
-- 
1.7.1

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

* [U-Boot] [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen CS pin
  2012-05-30 15:42 [U-Boot] [PATCH v2 0/4] kirkwood spi_claim/release_bus support Valentin Longchamp
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function Valentin Longchamp
@ 2012-05-30 15:42 ` Valentin Longchamp
  2012-05-31  8:36   ` Prafulla Wadaskar
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 3/4] kw_spi: support spi_claim/release_bus functions Valentin Longchamp
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 4/4] kw_spi: add weak functions board_spi_claim/release_bus Valentin Longchamp
  3 siblings, 1 reply; 13+ messages in thread
From: Valentin Longchamp @ 2012-05-30 15:42 UTC (permalink / raw)
  To: u-boot

This was not done before, and in the case of a shared pin (for MPP0
between NF_IO[2] and CSn) this could lead to problems.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
cc: Holger Brunck <holger.brunck@keymile.com>
cc: Prafulla Wadaskar <prafulla@marvell.com>
---
 drivers/spi/kirkwood_spi.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index db8ba8b..2fd89d2 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -34,16 +34,14 @@
 
 static struct kwspi_registers *spireg = (struct kwspi_registers *)KW_SPI_BASE;
 
+u32 cs_spi_mpp_back[2];
+
 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;
-	u32 kwspi_mpp_config[] = {
-		MPP0_GPIO,
-		MPP7_SPI_SCn,
-		0
-	};
+	u32 kwspi_mpp_config[] = { 0, 0 };
 
 	if (!spi_cs_is_valid(bus, cs))
 		return NULL;
@@ -70,12 +68,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 
 	/* program mpp registers to select  SPI_CSn */
 	if (cs) {
-		kwspi_mpp_config[0] = MPP0_GPIO;
-		kwspi_mpp_config[1] = MPP7_SPI_SCn;
+		kwspi_mpp_config[0] = MPP7_SPI_SCn;
 	} else {
 		kwspi_mpp_config[0] = MPP0_SPI_SCn;
-		kwspi_mpp_config[1] = MPP7_GPO;
 	}
+	kirkwood_mpp_read(kwspi_mpp_config, cs_spi_mpp_back);
 	kirkwood_mpp_conf(kwspi_mpp_config);
 
 	return slave;
@@ -83,6 +80,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 
 void spi_free_slave(struct spi_slave *slave)
 {
+	kirkwood_mpp_conf(cs_spi_mpp_back);
 	free(slave);
 }
 
-- 
1.7.1

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

* [U-Boot] [PATCH v2 3/4] kw_spi: support spi_claim/release_bus functions
  2012-05-30 15:42 [U-Boot] [PATCH v2 0/4] kirkwood spi_claim/release_bus support Valentin Longchamp
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function Valentin Longchamp
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen CS pin Valentin Longchamp
@ 2012-05-30 15:42 ` Valentin Longchamp
  2012-05-31  8:44   ` Prafulla Wadaskar
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 4/4] kw_spi: add weak functions board_spi_claim/release_bus Valentin Longchamp
  3 siblings, 1 reply; 13+ messages in thread
From: Valentin Longchamp @ 2012-05-30 15:42 UTC (permalink / raw)
  To: u-boot

These two function nows ensure that the MPP is configured correctly for
the SPI controller before any SPI access, and restore the initial
configuration when the access is over.

Since the used pins for the SPI controller can differ (2 possibilities
for each signal), the used pins are configured with CONFIG_SYS_KW_SPI_MPP.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
cc: Holger Brunck <holger.brunck@keymile.com>
cc: Prafulla Wadaskar <prafulla@marvell.com>
---
 arch/arm/include/asm/arch-kirkwood/spi.h |   11 ++++++++
 drivers/spi/kirkwood_spi.c               |   38 ++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/arch-kirkwood/spi.h b/arch/arm/include/asm/arch-kirkwood/spi.h
index 1d5043f..c79bed7 100644
--- a/arch/arm/include/asm/arch-kirkwood/spi.h
+++ b/arch/arm/include/asm/arch-kirkwood/spi.h
@@ -37,6 +37,17 @@ struct kwspi_registers {
 	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
+ * bit 0: selects pin for MOSI (MPP1 if 0, MPP6 if 1)
+ * bit 1: selects pin for SCK (MPP2 if 0, MPP10 if 1)
+ * bit 2: selects pin for MISO (MPP3 if 0, MPP11 if 1)
+ */
+#define MOSI_MPP6	(1 << 0)
+#define SCK_MPP10	(1 << 1)
+#define MISO_MPP11	(1 << 2)
+
 #define KWSPI_CLKPRESCL_MASK	0x1f
 #define KWSPI_CSN_ACT		1 /* Activates serial memory interface */
 #define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */
diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index 2fd89d2..a3e6b6e 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -84,13 +84,51 @@ void spi_free_slave(struct spi_slave *slave)
 	free(slave);
 }
 
+#if defined(CONFIG_SYS_KW_SPI_MPP)
+u32 spi_mpp_backup[4];
+#endif
+
 int spi_claim_bus(struct spi_slave *slave)
 {
+#if defined(CONFIG_SYS_KW_SPI_MPP)
+	u32 config;
+	u32 spi_mpp_config[4];
+
+	config = CONFIG_SYS_KW_SPI_MPP;
+
+	if (config & MOSI_MPP6)
+		spi_mpp_config[0] = MPP6_SPI_MOSI;
+	else
+		spi_mpp_config[0] = MPP1_SPI_MOSI;
+
+	if (config & SCK_MPP10)
+		spi_mpp_config[1] = MPP10_SPI_SCK;
+	else
+		spi_mpp_config[1] = MPP2_SPI_SCK;
+
+	if (config & MISO_MPP11)
+		spi_mpp_config[2] = MPP11_SPI_MISO;
+	else
+		spi_mpp_config[2] = MPP3_SPI_MISO;
+
+	spi_mpp_config[3] = 0;
+	spi_mpp_backup[3] = 0;
+
+	/* save current mpp configuration */
+	kirkwood_mpp_read(spi_mpp_config, spi_mpp_backup);
+
+	/* finally set chosen mpp spi configuration */
+	kirkwood_mpp_conf(spi_mpp_config);
+#endif
+
 	return 0;
 }
 
 void spi_release_bus(struct spi_slave *slave)
 {
+#if defined(CONFIG_SYS_KW_SPI_MPP)
+	kirkwood_mpp_conf(spi_mpp_backup);
+#endif
 }
 
 #ifndef CONFIG_SPI_CS_IS_VALID
-- 
1.7.1

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

* [U-Boot] [PATCH v2 4/4] kw_spi: add weak functions board_spi_claim/release_bus
  2012-05-30 15:42 [U-Boot] [PATCH v2 0/4] kirkwood spi_claim/release_bus support Valentin Longchamp
                   ` (2 preceding siblings ...)
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 3/4] kw_spi: support spi_claim/release_bus functions Valentin Longchamp
@ 2012-05-30 15:42 ` Valentin Longchamp
  2012-05-31  8:45   ` Prafulla Wadaskar
  3 siblings, 1 reply; 13+ messages in thread
From: Valentin Longchamp @ 2012-05-30 15:42 UTC (permalink / raw)
  To: u-boot

This allows a final, board specific, step in the claim/relase_bus
function for the SPI controller, which may be needed for some hardware
designs.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
cc: Holger Brunck <holger.brunck@keymile.com>
cc: Prafulla Wadaskar <prafulla@marvell.com>
---
 drivers/spi/kirkwood_spi.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index a3e6b6e..a0da527 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -88,6 +88,11 @@ void spi_free_slave(struct spi_slave *slave)
 u32 spi_mpp_backup[4];
 #endif
 
+__attribute__((weak)) int board_spi_claim_bus(struct spi_slave *slave)
+{
+	return 0;
+}
+
 int spi_claim_bus(struct spi_slave *slave)
 {
 #if defined(CONFIG_SYS_KW_SPI_MPP)
@@ -121,7 +126,11 @@ int spi_claim_bus(struct spi_slave *slave)
 	kirkwood_mpp_conf(spi_mpp_config);
 #endif
 
-	return 0;
+	return board_spi_claim_bus(slave);
+}
+
+__attribute__((weak)) void board_spi_release_bus(struct spi_slave *slave)
+{
 }
 
 void spi_release_bus(struct spi_slave *slave)
@@ -129,6 +138,8 @@ void spi_release_bus(struct spi_slave *slave)
 #if defined(CONFIG_SYS_KW_SPI_MPP)
 	kirkwood_mpp_conf(spi_mpp_backup);
 #endif
+
+	board_spi_release_bus(slave);
 }
 
 #ifndef CONFIG_SPI_CS_IS_VALID
-- 
1.7.1

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

* [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function Valentin Longchamp
@ 2012-05-31  8:30   ` Prafulla Wadaskar
  2012-05-31  8:43     ` Valentin Longchamp
  0 siblings, 1 reply; 13+ messages in thread
From: Prafulla Wadaskar @ 2012-05-31  8:30 UTC (permalink / raw)
  To: u-boot



> -----Original Message-----
> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
> Sent: 30 May 2012 21:12
> To: Prafulla Wadaskar
> Cc: Valentin Longchamp; holger.brunck at keymile.com; u-
> boot at lists.denx.de; Prafulla Wadaskar
> Subject: [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
> 
> This function can be used to save current mpp state of all mpp pins
> given in the mpp_list argument by reading the mpp registers, in the
> second mpp_saved argument.
> 
> A later call to kirkwood_mpp_conf function with this saved list will
> reset the mpp configuration as it was when kirkwood_mpp_read was
> called.
> 
> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> cc: Holger Brunck <holger.brunck@keymile.com>
> cc: Prafulla Wadaskar <prafulla@marvell.com>
> ---
>  arch/arm/cpu/arm926ejs/kirkwood/mpp.c    |   41
> ++++++++++++++++++++++++++++++
>  arch/arm/include/asm/arch-kirkwood/mpp.h |    1 +
>  2 files changed, 42 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
> b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
> index 3da6c98..9fb9aea 100644
> --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
> +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
> @@ -80,3 +80,44 @@ void kirkwood_mpp_conf(u32 *mpp_list)
>  	debug("\n");
> 
>  }
> +
> +void kirkwood_mpp_read(u32 *mpp_list, u32 *mpp_saved)
> +{
> +	u32 mpp_ctrl[MPP_NR_REGS];
> +	unsigned int variant_mask;
> +	int i;
> +
> +	variant_mask = kirkwood_variant();
> +	if (!variant_mask)
> +		return;
> +
> +	for (i = 0; i < MPP_NR_REGS; i++) {
> +		mpp_ctrl[i] = readl(MPP_CTRL(i));
> +		debug(" %08x", mpp_ctrl[i]);
> +	}
> +
> +	while (*mpp_list) {
> +		unsigned int num = MPP_NUM(*mpp_list);
> +		unsigned int sel;
> +		int shift;
> +
> +		if (num > MPP_MAX) {
> +			debug("kirkwood_mpp_conf: invalid MPP "
> +					"number (%u)\n", num);
> +			continue;
> +		}
> +		if (!(*mpp_list & variant_mask)) {
> +			debug("kirkwood_mpp_conf: requested MPP%u config "
> +				"unavailable on this hardware\n", num);
> +			continue;
> +		}
> +
> +		shift = (num & 7) << 2;
> +		sel = (mpp_ctrl[num / 8] >> shift) & 0xf;
> +		*mpp_saved = num | (sel << 8) | variant_mask;
> +
> +		mpp_list++;
> +		mpp_saved++;
> +	}
> +}
> +

Hi Valentin
There is code duplication, similar code it already there in function  kirkwood_mpp_conf(), to make it short you should use kirkwood_mpp_read function within kirkwood_mpp_conf

Regards..
Prafulla . . .

> diff --git a/arch/arm/include/asm/arch-kirkwood/mpp.h
> b/arch/arm/include/asm/arch-kirkwood/mpp.h
> index b3c090e..22a64b8 100644
> --- a/arch/arm/include/asm/arch-kirkwood/mpp.h
> +++ b/arch/arm/include/asm/arch-kirkwood/mpp.h
> @@ -313,5 +313,6 @@
>  #define MPP_MAX			49
> 
>  void kirkwood_mpp_conf(unsigned int *mpp_list);
> +void kirkwood_mpp_read(u32 *mpp_list, u32 *mpp_saved);
> 
>  #endif
> --
> 1.7.1

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

* [U-Boot] [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen CS pin
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen CS pin Valentin Longchamp
@ 2012-05-31  8:36   ` Prafulla Wadaskar
  2012-05-31  8:45     ` Valentin Longchamp
  0 siblings, 1 reply; 13+ messages in thread
From: Prafulla Wadaskar @ 2012-05-31  8:36 UTC (permalink / raw)
  To: u-boot



> -----Original Message-----
> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
> Sent: 30 May 2012 21:12
> To: Prafulla Wadaskar
> Cc: Valentin Longchamp; holger.brunck at keymile.com; u-
> boot at lists.denx.de; Prafulla Wadaskar
> Subject: [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen
> CS pin
> 
> This was not done before, and in the case of a shared pin (for MPP0
> between NF_IO[2] and CSn) this could lead to problems.
> 
> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> cc: Holger Brunck <holger.brunck@keymile.com>
> cc: Prafulla Wadaskar <prafulla@marvell.com>
> ---
>  drivers/spi/kirkwood_spi.c |   14 ++++++--------
>  1 files changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
> index db8ba8b..2fd89d2 100644
> --- a/drivers/spi/kirkwood_spi.c
> +++ b/drivers/spi/kirkwood_spi.c
> @@ -34,16 +34,14 @@
> 
>  static struct kwspi_registers *spireg = (struct kwspi_registers
> *)KW_SPI_BASE;
> 
> +u32 cs_spi_mpp_back[2];
> +
>  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;
> -	u32 kwspi_mpp_config[] = {
> -		MPP0_GPIO,
> -		MPP7_SPI_SCn,
> -		0
> -	};
> +	u32 kwspi_mpp_config[] = { 0, 0 };
> 
>  	if (!spi_cs_is_valid(bus, cs))
>  		return NULL;
> @@ -70,12 +68,11 @@ struct spi_slave *spi_setup_slave(unsigned int
> bus, unsigned int cs,
> 
>  	/* program mpp registers to select  SPI_CSn */
>  	if (cs) {
> -		kwspi_mpp_config[0] = MPP0_GPIO;
> -		kwspi_mpp_config[1] = MPP7_SPI_SCn;
> +		kwspi_mpp_config[0] = MPP7_SPI_SCn;
>  	} else {
>  		kwspi_mpp_config[0] = MPP0_SPI_SCn;
> -		kwspi_mpp_config[1] = MPP7_GPO;
>  	}
> +	kirkwood_mpp_read(kwspi_mpp_config, cs_spi_mpp_back);
>  	kirkwood_mpp_conf(kwspi_mpp_config);
> 
>  	return slave;
> @@ -83,6 +80,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
> unsigned int cs,
> 
>  void spi_free_slave(struct spi_slave *slave)
>  {
> +	kirkwood_mpp_conf(cs_spi_mpp_back);
>  	free(slave);
>  }
> 
> --

Acked-By: Prafulla Wadaskar <prafulla@maravell.com>
But as you said functionality need to be verified, I hope you have verified it on any of Kirkwood variant.

Regards..
Prafulla . . .

> 1.7.1

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

* [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
  2012-05-31  8:30   ` Prafulla Wadaskar
@ 2012-05-31  8:43     ` Valentin Longchamp
  2012-05-31  8:49       ` Prafulla Wadaskar
  0 siblings, 1 reply; 13+ messages in thread
From: Valentin Longchamp @ 2012-05-31  8:43 UTC (permalink / raw)
  To: u-boot

Hi Prafulla,

On 05/31/2012 10:30 AM, Prafulla Wadaskar wrote:
>> -----Original Message-----
>> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
>> Sent: 30 May 2012 21:12
>> To: Prafulla Wadaskar
>> Cc: Valentin Longchamp; holger.brunck at keymile.com; u-
>> boot at lists.denx.de; Prafulla Wadaskar
>> Subject: [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
>>
>> This function can be used to save current mpp state of all mpp pins
>> given in the mpp_list argument by reading the mpp registers, in the
>> second mpp_saved argument.
>>
>> A later call to kirkwood_mpp_conf function with this saved list will
>> reset the mpp configuration as it was when kirkwood_mpp_read was
>> called.
>>
>> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
>> cc: Holger Brunck <holger.brunck@keymile.com>
>> cc: Prafulla Wadaskar <prafulla@marvell.com>
>> ---
>>  arch/arm/cpu/arm926ejs/kirkwood/mpp.c    |   41
>> ++++++++++++++++++++++++++++++
>>  arch/arm/include/asm/arch-kirkwood/mpp.h |    1 +
>>  2 files changed, 42 insertions(+), 0 deletions(-)
>>
>> diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
>> b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
>> index 3da6c98..9fb9aea 100644
>> --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
>> +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
>> @@ -80,3 +80,44 @@ void kirkwood_mpp_conf(u32 *mpp_list)
>>  	debug("\n");
>>
>>  }
>> +
>> +void kirkwood_mpp_read(u32 *mpp_list, u32 *mpp_saved)
>> +{
>> +	u32 mpp_ctrl[MPP_NR_REGS];
>> +	unsigned int variant_mask;
>> +	int i;
>> +
>> +	variant_mask = kirkwood_variant();
>> +	if (!variant_mask)
>> +		return;
>> +
>> +	for (i = 0; i < MPP_NR_REGS; i++) {
>> +		mpp_ctrl[i] = readl(MPP_CTRL(i));
>> +		debug(" %08x", mpp_ctrl[i]);
>> +	}
>> +
>> +	while (*mpp_list) {
>> +		unsigned int num = MPP_NUM(*mpp_list);
>> +		unsigned int sel;
>> +		int shift;
>> +
>> +		if (num > MPP_MAX) {
>> +			debug("kirkwood_mpp_conf: invalid MPP "
>> +					"number (%u)\n", num);
>> +			continue;
>> +		}
>> +		if (!(*mpp_list & variant_mask)) {
>> +			debug("kirkwood_mpp_conf: requested MPP%u config "
>> +				"unavailable on this hardware\n", num);
>> +			continue;
>> +		}
>> +
>> +		shift = (num & 7) << 2;
>> +		sel = (mpp_ctrl[num / 8] >> shift) & 0xf;
>> +		*mpp_saved = num | (sel << 8) | variant_mask;
>> +
>> +		mpp_list++;
>> +		mpp_saved++;
>> +	}
>> +}
>> +
> 
> Hi Valentin
> There is code duplication, similar code it already there in function  kirkwood_mpp_conf(), to make it short you should use kirkwood_mpp_read function within kirkwood_mpp_conf
> 

Not sure I understand what you mean. You want me to implement the
kirkwood_mpp_read functionnality directly into kirkwood_mpp_conf ?

If this is so, it would mean that I would have to change kirkwood_mpp_conf "API"
to add the second argument (mpp_saved) and then I would have to fix all the
calls to this function. Is that what you mean ?

Val

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

* [U-Boot] [PATCH v2 3/4] kw_spi: support spi_claim/release_bus functions
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 3/4] kw_spi: support spi_claim/release_bus functions Valentin Longchamp
@ 2012-05-31  8:44   ` Prafulla Wadaskar
  0 siblings, 0 replies; 13+ messages in thread
From: Prafulla Wadaskar @ 2012-05-31  8:44 UTC (permalink / raw)
  To: u-boot



> -----Original Message-----
> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
> Sent: 30 May 2012 21:12
> To: Prafulla Wadaskar
> Cc: Valentin Longchamp; holger.brunck at keymile.com; u-
> boot at lists.denx.de; Prafulla Wadaskar
> Subject: [PATCH v2 3/4] kw_spi: support spi_claim/release_bus
> functions
> 
> These two function nows ensure that the MPP is configured correctly
> for
> the SPI controller before any SPI access, and restore the initial
> configuration when the access is over.
> 
> Since the used pins for the SPI controller can differ (2 possibilities
> for each signal), the used pins are configured with
> CONFIG_SYS_KW_SPI_MPP.
> 
> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> cc: Holger Brunck <holger.brunck@keymile.com>
> cc: Prafulla Wadaskar <prafulla@marvell.com>
> ---
>  arch/arm/include/asm/arch-kirkwood/spi.h |   11 ++++++++
>  drivers/spi/kirkwood_spi.c               |   38
> ++++++++++++++++++++++++++++++
>  2 files changed, 49 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/include/asm/arch-kirkwood/spi.h
> b/arch/arm/include/asm/arch-kirkwood/spi.h
> index 1d5043f..c79bed7 100644
> --- a/arch/arm/include/asm/arch-kirkwood/spi.h
> +++ b/arch/arm/include/asm/arch-kirkwood/spi.h
> @@ -37,6 +37,17 @@ struct kwspi_registers {
>  	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
> + * bit 0: selects pin for MOSI (MPP1 if 0, MPP6 if 1)
> + * bit 1: selects pin for SCK (MPP2 if 0, MPP10 if 1)
> + * bit 2: selects pin for MISO (MPP3 if 0, MPP11 if 1)
> + */
> +#define MOSI_MPP6	(1 << 0)
> +#define SCK_MPP10	(1 << 1)
> +#define MISO_MPP11	(1 << 2)
> +
>  #define KWSPI_CLKPRESCL_MASK	0x1f
>  #define KWSPI_CSN_ACT		1 /* Activates serial memory interface
> */
>  #define KWSPI_SMEMRDY		(1 << 1) /* SerMem Data xfer ready */
> diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
> index 2fd89d2..a3e6b6e 100644
> --- a/drivers/spi/kirkwood_spi.c
> +++ b/drivers/spi/kirkwood_spi.c
> @@ -84,13 +84,51 @@ void spi_free_slave(struct spi_slave *slave)
>  	free(slave);
>  }
> 
> +#if defined(CONFIG_SYS_KW_SPI_MPP)
> +u32 spi_mpp_backup[4];
> +#endif
> +
>  int spi_claim_bus(struct spi_slave *slave)
>  {
> +#if defined(CONFIG_SYS_KW_SPI_MPP)
> +	u32 config;
> +	u32 spi_mpp_config[4];
> +
> +	config = CONFIG_SYS_KW_SPI_MPP;
> +
> +	if (config & MOSI_MPP6)
> +		spi_mpp_config[0] = MPP6_SPI_MOSI;
> +	else
> +		spi_mpp_config[0] = MPP1_SPI_MOSI;
> +
> +	if (config & SCK_MPP10)
> +		spi_mpp_config[1] = MPP10_SPI_SCK;
> +	else
> +		spi_mpp_config[1] = MPP2_SPI_SCK;
> +
> +	if (config & MISO_MPP11)
> +		spi_mpp_config[2] = MPP11_SPI_MISO;
> +	else
> +		spi_mpp_config[2] = MPP3_SPI_MISO;
> +
> +	spi_mpp_config[3] = 0;
> +	spi_mpp_backup[3] = 0;
> +
> +	/* save current mpp configuration */
> +	kirkwood_mpp_read(spi_mpp_config, spi_mpp_backup);
> +
> +	/* finally set chosen mpp spi configuration */
> +	kirkwood_mpp_conf(spi_mpp_config);
> +#endif
> +
>  	return 0;
>  }
> 
>  void spi_release_bus(struct spi_slave *slave)
>  {
> +#if defined(CONFIG_SYS_KW_SPI_MPP)
> +	kirkwood_mpp_conf(spi_mpp_backup);
> +#endif
>  }
> 

Acked-By: Prafulla Wadaskar <Prafulla@marvell.com>
One more comment: do you think we should safeguard spi_claim_bus for repeatative calls, for ex. once bus is claimed, it should be reclaimed until we release it?

Regards...
Prafulla . . .

>  #ifndef CONFIG_SPI_CS_IS_VALID
> --
> 1.7.1

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

* [U-Boot] [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen CS pin
  2012-05-31  8:36   ` Prafulla Wadaskar
@ 2012-05-31  8:45     ` Valentin Longchamp
  0 siblings, 0 replies; 13+ messages in thread
From: Valentin Longchamp @ 2012-05-31  8:45 UTC (permalink / raw)
  To: u-boot

On 05/31/2012 10:36 AM, Prafulla Wadaskar wrote:
>> -----Original Message-----
>> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
>> Sent: 30 May 2012 21:12
>> To: Prafulla Wadaskar
>> Cc: Valentin Longchamp; holger.brunck at keymile.com; u-
>> boot at lists.denx.de; Prafulla Wadaskar
>> Subject: [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen
>> CS pin
>>
>> This was not done before, and in the case of a shared pin (for MPP0
>> between NF_IO[2] and CSn) this could lead to problems.
>>
>> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
>> cc: Holger Brunck <holger.brunck@keymile.com>
>> cc: Prafulla Wadaskar <prafulla@marvell.com>
>> ---
>>  drivers/spi/kirkwood_spi.c |   14 ++++++--------
>>  1 files changed, 6 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
>> index db8ba8b..2fd89d2 100644
>> --- a/drivers/spi/kirkwood_spi.c
>> +++ b/drivers/spi/kirkwood_spi.c
>> @@ -34,16 +34,14 @@
>>
>>  static struct kwspi_registers *spireg = (struct kwspi_registers
>> *)KW_SPI_BASE;
>>
>> +u32 cs_spi_mpp_back[2];
>> +
>>  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;
>> -	u32 kwspi_mpp_config[] = {
>> -		MPP0_GPIO,
>> -		MPP7_SPI_SCn,
>> -		0
>> -	};
>> +	u32 kwspi_mpp_config[] = { 0, 0 };
>>
>>  	if (!spi_cs_is_valid(bus, cs))
>>  		return NULL;
>> @@ -70,12 +68,11 @@ struct spi_slave *spi_setup_slave(unsigned int
>> bus, unsigned int cs,
>>
>>  	/* program mpp registers to select  SPI_CSn */
>>  	if (cs) {
>> -		kwspi_mpp_config[0] = MPP0_GPIO;
>> -		kwspi_mpp_config[1] = MPP7_SPI_SCn;
>> +		kwspi_mpp_config[0] = MPP7_SPI_SCn;
>>  	} else {
>>  		kwspi_mpp_config[0] = MPP0_SPI_SCn;
>> -		kwspi_mpp_config[1] = MPP7_GPO;
>>  	}
>> +	kirkwood_mpp_read(kwspi_mpp_config, cs_spi_mpp_back);
>>  	kirkwood_mpp_conf(kwspi_mpp_config);
>>
>>  	return slave;
>> @@ -83,6 +80,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
>> unsigned int cs,
>>
>>  void spi_free_slave(struct spi_slave *slave)
>>  {
>> +	kirkwood_mpp_conf(cs_spi_mpp_back);
>>  	free(slave);
>>  }
>>
>> --
> 
> Acked-By: Prafulla Wadaskar <prafulla@maravell.com>
> But as you said functionality need to be verified, I hope you have verified it on any of Kirkwood variant.
> 

Sure, it's always been tested successfully on our kirkwood boards.

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

* [U-Boot] [PATCH v2 4/4] kw_spi: add weak functions board_spi_claim/release_bus
  2012-05-30 15:42 ` [U-Boot] [PATCH v2 4/4] kw_spi: add weak functions board_spi_claim/release_bus Valentin Longchamp
@ 2012-05-31  8:45   ` Prafulla Wadaskar
  0 siblings, 0 replies; 13+ messages in thread
From: Prafulla Wadaskar @ 2012-05-31  8:45 UTC (permalink / raw)
  To: u-boot



> -----Original Message-----
> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
> Sent: 30 May 2012 21:12
> To: Prafulla Wadaskar
> Cc: Valentin Longchamp; holger.brunck at keymile.com; u-
> boot at lists.denx.de; Prafulla Wadaskar
> Subject: [PATCH v2 4/4] kw_spi: add weak functions
> board_spi_claim/release_bus
> 
> This allows a final, board specific, step in the claim/relase_bus
> function for the SPI controller, which may be needed for some hardware
> designs.
> 
> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> cc: Holger Brunck <holger.brunck@keymile.com>
> cc: Prafulla Wadaskar <prafulla@marvell.com>
> ---
>  drivers/spi/kirkwood_spi.c |   13 ++++++++++++-
>  1 files changed, 12 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
> index a3e6b6e..a0da527 100644
> --- a/drivers/spi/kirkwood_spi.c
> +++ b/drivers/spi/kirkwood_spi.c
> @@ -88,6 +88,11 @@ void spi_free_slave(struct spi_slave *slave)
>  u32 spi_mpp_backup[4];
>  #endif
> 
> +__attribute__((weak)) int board_spi_claim_bus(struct spi_slave
> *slave)
> +{
> +	return 0;
> +}
> +
>  int spi_claim_bus(struct spi_slave *slave)
>  {
>  #if defined(CONFIG_SYS_KW_SPI_MPP)
> @@ -121,7 +126,11 @@ int spi_claim_bus(struct spi_slave *slave)
>  	kirkwood_mpp_conf(spi_mpp_config);
>  #endif
> 
> -	return 0;
> +	return board_spi_claim_bus(slave);
> +}
> +
> +__attribute__((weak)) void board_spi_release_bus(struct spi_slave
> *slave)
> +{
>  }
> 
>  void spi_release_bus(struct spi_slave *slave)
> @@ -129,6 +138,8 @@ void spi_release_bus(struct spi_slave *slave)
>  #if defined(CONFIG_SYS_KW_SPI_MPP)
>  	kirkwood_mpp_conf(spi_mpp_backup);
>  #endif
> +
> +	board_spi_release_bus(slave);
>  }
> 
>  #ifndef CONFIG_SPI_CS_IS_VALID
> --
> 1.7.1

Acked-By: Prafulla Wadaskar <Prafulla@marvell.com>

Regards..
Prafulla . . .

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

* [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
  2012-05-31  8:43     ` Valentin Longchamp
@ 2012-05-31  8:49       ` Prafulla Wadaskar
  2012-05-31 14:04         ` Valentin Longchamp
  0 siblings, 1 reply; 13+ messages in thread
From: Prafulla Wadaskar @ 2012-05-31  8:49 UTC (permalink / raw)
  To: u-boot



> -----Original Message-----
> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
> Sent: 31 May 2012 14:14
> To: Prafulla Wadaskar
> Cc: holger.brunck at keymile.com; u-boot at lists.denx.de
> Subject: Re: [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
> 
> Hi Prafulla,
> 
> On 05/31/2012 10:30 AM, Prafulla Wadaskar wrote:
> >> -----Original Message-----
> >> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
> >> Sent: 30 May 2012 21:12
> >> To: Prafulla Wadaskar
> >> Cc: Valentin Longchamp; holger.brunck at keymile.com; u-
> >> boot at lists.denx.de; Prafulla Wadaskar
> >> Subject: [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
> >>
> >> This function can be used to save current mpp state of all mpp pins
> >> given in the mpp_list argument by reading the mpp registers, in the
> >> second mpp_saved argument.
> >>
> >> A later call to kirkwood_mpp_conf function with this saved list
> will
> >> reset the mpp configuration as it was when kirkwood_mpp_read was
> >> called.
> >>
> >> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> >> cc: Holger Brunck <holger.brunck@keymile.com>
> >> cc: Prafulla Wadaskar <prafulla@marvell.com>
> >> ---
> >>  arch/arm/cpu/arm926ejs/kirkwood/mpp.c    |   41
> >> ++++++++++++++++++++++++++++++
> >>  arch/arm/include/asm/arch-kirkwood/mpp.h |    1 +
> >>  2 files changed, 42 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
> >> b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
> >> index 3da6c98..9fb9aea 100644
> >> --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
> >> +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
> >> @@ -80,3 +80,44 @@ void kirkwood_mpp_conf(u32 *mpp_list)
> >>  	debug("\n");
> >>
> >>  }
> >> +
> >> +void kirkwood_mpp_read(u32 *mpp_list, u32 *mpp_saved)
> >> +{
> >> +	u32 mpp_ctrl[MPP_NR_REGS];
> >> +	unsigned int variant_mask;
> >> +	int i;
> >> +
> >> +	variant_mask = kirkwood_variant();
> >> +	if (!variant_mask)
> >> +		return;
> >> +
> >> +	for (i = 0; i < MPP_NR_REGS; i++) {
> >> +		mpp_ctrl[i] = readl(MPP_CTRL(i));
> >> +		debug(" %08x", mpp_ctrl[i]);
> >> +	}
> >> +
> >> +	while (*mpp_list) {
> >> +		unsigned int num = MPP_NUM(*mpp_list);
> >> +		unsigned int sel;
> >> +		int shift;
> >> +
> >> +		if (num > MPP_MAX) {
> >> +			debug("kirkwood_mpp_conf: invalid MPP "
> >> +					"number (%u)\n", num);
>> +			continue;
> >> +		}
> >> +		if (!(*mpp_list & variant_mask)) {
> >> +			debug("kirkwood_mpp_conf: requested MPP%u config "
> >> +				"unavailable on this hardware\n", num);
> >> +			continue;
> >> +		}
> >> +
> >> +		shift = (num & 7) << 2;
> >> +		sel = (mpp_ctrl[num / 8] >> shift) & 0xf;
> >> +		*mpp_saved = num | (sel << 8) | variant_mask;
> >> +
> >> +		mpp_list++;
> >> +		mpp_saved++;
> >> +	}
> >> +}
> >> +
> >
> > Hi Valentin
> > There is code duplication, similar code it already there in function
> kirkwood_mpp_conf(), to make it short you should use kirkwood_mpp_read
> function within kirkwood_mpp_conf
> >
> 
> Not sure I understand what you mean. You want me to implement the
> kirkwood_mpp_read functionnality directly into kirkwood_mpp_conf ?

Yes,

> 
> If this is so, it would mean that I would have to change
> kirkwood_mpp_conf "API"
> to add the second argument (mpp_saved) and then I would have to fix
> all the
> calls to this function. Is that what you mean ?

Yes, my objective here is - how good we can optimise the code.

I will not stretch it further, it's up to you.

Regards..
Prafulla . . .

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

* [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
  2012-05-31  8:49       ` Prafulla Wadaskar
@ 2012-05-31 14:04         ` Valentin Longchamp
  0 siblings, 0 replies; 13+ messages in thread
From: Valentin Longchamp @ 2012-05-31 14:04 UTC (permalink / raw)
  To: u-boot

On 05/31/2012 10:49 AM, Prafulla Wadaskar wrote:
> 
> 
>> -----Original Message-----
>> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
>> Sent: 31 May 2012 14:14
>> To: Prafulla Wadaskar
>> Cc: holger.brunck at keymile.com; u-boot at lists.denx.de
>> Subject: Re: [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
>>
>> Hi Prafulla,
>>
>> On 05/31/2012 10:30 AM, Prafulla Wadaskar wrote:
>>>> -----Original Message-----
>>>> From: Valentin Longchamp [mailto:valentin.longchamp at keymile.com]
>>>> Sent: 30 May 2012 21:12
>>>> To: Prafulla Wadaskar
>>>> Cc: Valentin Longchamp; holger.brunck at keymile.com; u-
>>>> boot at lists.denx.de; Prafulla Wadaskar
>>>> Subject: [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function
>>>>
>>>> This function can be used to save current mpp state of all mpp pins
>>>> given in the mpp_list argument by reading the mpp registers, in the
>>>> second mpp_saved argument.
>>>>
>>>> A later call to kirkwood_mpp_conf function with this saved list
>> will
>>>> reset the mpp configuration as it was when kirkwood_mpp_read was
>>>> called.
>>>>
>>>> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
>>>> cc: Holger Brunck <holger.brunck@keymile.com>
>>>> cc: Prafulla Wadaskar <prafulla@marvell.com>
>>>> ---
>>>>  arch/arm/cpu/arm926ejs/kirkwood/mpp.c    |   41
>>>> ++++++++++++++++++++++++++++++
>>>>  arch/arm/include/asm/arch-kirkwood/mpp.h |    1 +
>>>>  2 files changed, 42 insertions(+), 0 deletions(-)
>>>>
>>>> diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
>>>> b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
>>>> index 3da6c98..9fb9aea 100644
>>>> --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
>>>> +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
>>>> @@ -80,3 +80,44 @@ void kirkwood_mpp_conf(u32 *mpp_list)
>>>>  	debug("\n");
>>>>
>>>>  }
>>>> +
>>>> +void kirkwood_mpp_read(u32 *mpp_list, u32 *mpp_saved)
>>>> +{
>>>> +	u32 mpp_ctrl[MPP_NR_REGS];
>>>> +	unsigned int variant_mask;
>>>> +	int i;
>>>> +
>>>> +	variant_mask = kirkwood_variant();
>>>> +	if (!variant_mask)
>>>> +		return;
>>>> +
>>>> +	for (i = 0; i < MPP_NR_REGS; i++) {
>>>> +		mpp_ctrl[i] = readl(MPP_CTRL(i));
>>>> +		debug(" %08x", mpp_ctrl[i]);
>>>> +	}
>>>> +
>>>> +	while (*mpp_list) {
>>>> +		unsigned int num = MPP_NUM(*mpp_list);
>>>> +		unsigned int sel;
>>>> +		int shift;
>>>> +
>>>> +		if (num > MPP_MAX) {
>>>> +			debug("kirkwood_mpp_conf: invalid MPP "
>>>> +					"number (%u)\n", num);
>>> +			continue;
>>>> +		}
>>>> +		if (!(*mpp_list & variant_mask)) {
>>>> +			debug("kirkwood_mpp_conf: requested MPP%u config "
>>>> +				"unavailable on this hardware\n", num);
>>>> +			continue;
>>>> +		}
>>>> +
>>>> +		shift = (num & 7) << 2;
>>>> +		sel = (mpp_ctrl[num / 8] >> shift) & 0xf;
>>>> +		*mpp_saved = num | (sel << 8) | variant_mask;
>>>> +
>>>> +		mpp_list++;
>>>> +		mpp_saved++;
>>>> +	}
>>>> +}
>>>> +
>>>
>>> Hi Valentin
>>> There is code duplication, similar code it already there in function
>> kirkwood_mpp_conf(), to make it short you should use kirkwood_mpp_read
>> function within kirkwood_mpp_conf
>>>
>>
>> Not sure I understand what you mean. You want me to implement the
>> kirkwood_mpp_read functionnality directly into kirkwood_mpp_conf ?
> 
> Yes,
> 
>>
>> If this is so, it would mean that I would have to change
>> kirkwood_mpp_conf "API"
>> to add the second argument (mpp_saved) and then I would have to fix
>> all the
>> calls to this function. Is that what you mean ?
> 
> Yes, my objective here is - how good we can optimise the code.
> 
> I will not stretch it further, it's up to you.
> 

OK, I have done it. Sending v3 of the series in a few minutes.

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

end of thread, other threads:[~2012-05-31 14:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-30 15:42 [U-Boot] [PATCH v2 0/4] kirkwood spi_claim/release_bus support Valentin Longchamp
2012-05-30 15:42 ` [U-Boot] [PATCH v2 1/4] kirkwood: add kirkwood_mpp_read function Valentin Longchamp
2012-05-31  8:30   ` Prafulla Wadaskar
2012-05-31  8:43     ` Valentin Longchamp
2012-05-31  8:49       ` Prafulla Wadaskar
2012-05-31 14:04         ` Valentin Longchamp
2012-05-30 15:42 ` [U-Boot] [PATCH v2 2/4] kw_spi: backup and reset the MPP of the chosen CS pin Valentin Longchamp
2012-05-31  8:36   ` Prafulla Wadaskar
2012-05-31  8:45     ` Valentin Longchamp
2012-05-30 15:42 ` [U-Boot] [PATCH v2 3/4] kw_spi: support spi_claim/release_bus functions Valentin Longchamp
2012-05-31  8:44   ` Prafulla Wadaskar
2012-05-30 15:42 ` [U-Boot] [PATCH v2 4/4] kw_spi: add weak functions board_spi_claim/release_bus Valentin Longchamp
2012-05-31  8:45   ` Prafulla Wadaskar

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