[U-Boot] [PATCH v3 0/5] kirkwood spi_claim/release_bus support

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
Changes for v3: - moved mpp_read function functionality into mpp_conf function - fixed all calls to mpp_conf so that they are compliant with the newly necessary mpp_conf prototype
Valentin Longchamp (5): kirkwood: add save functionality kirkwood_mpp_conf function kirkwood: fix calls to kirkwood_mpp_conf 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 | 14 ++++- arch/arm/include/asm/arch-kirkwood/mpp.h | 2 +- arch/arm/include/asm/arch-kirkwood/spi.h | 11 ++++ board/LaCie/net2big_v2/net2big_v2.c | 2 +- board/LaCie/netspace_v2/netspace_v2.c | 2 +- board/Marvell/dreamplug/dreamplug.c | 2 +- board/Marvell/guruplug/guruplug.c | 2 +- board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c | 2 +- board/Marvell/openrd/openrd.c | 2 +- board/Marvell/rd6281a/rd6281a.c | 2 +- board/Marvell/sheevaplug/sheevaplug.c | 2 +- board/Seagate/dockstar/dockstar.c | 2 +- board/cloudengines/pogo_e02/pogo_e02.c | 2 +- board/d-link/dns325/dns325.c | 2 +- board/keymile/km_arm/km_arm.c | 6 +- board/raidsonic/ib62x0/ib62x0.c | 2 +- drivers/spi/kirkwood_spi.c | 64 +++++++++++++++++++---- 17 files changed, 93 insertions(+), 28 deletions(-)

If a second non NULL argument is given to the kirkwood_mpp_conf function, it will be used to store the current configuration of the MPP registers. mpp_save must be a preallocated table of the same size as mpp_list and it must be zero terminated as well.
A later call to kirkwood_mpp_conf function with this saved list as first (mpp_conf) argment will set the configuration back.
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 | 14 ++++++++++++-- arch/arm/include/asm/arch-kirkwood/mpp.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c index 3da6c98..158ea84 100644 --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c @@ -31,11 +31,11 @@ static u32 kirkwood_variant(void) #define MPP_CTRL(i) (KW_MPP_BASE + (i* 4)) #define MPP_NR_REGS (1 + MPP_MAX/8)
-void kirkwood_mpp_conf(u32 *mpp_list) +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save) { u32 mpp_ctrl[MPP_NR_REGS]; unsigned int variant_mask; - int i; + int i, save = 0;
variant_mask = kirkwood_variant(); if (!variant_mask) @@ -48,10 +48,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) } debug("\n");
+ if (mpp_save) + save = 1;
while (*mpp_list) { unsigned int num = MPP_NUM(*mpp_list); unsigned int sel = MPP_SEL(*mpp_list); + unsigned int sel_save; int shift;
if (num > MPP_MAX) { @@ -66,6 +69,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) }
shift = (num & 7) << 2; + + if (save) { + sel_save = (mpp_ctrl[num / 8] >> shift) & 0xf; + *mpp_save = num | (sel_save << 8) | variant_mask; + mpp_save++; + } + mpp_ctrl[num / 8] &= ~(0xf << shift); mpp_ctrl[num / 8] |= sel << shift;
diff --git a/arch/arm/include/asm/arch-kirkwood/mpp.h b/arch/arm/include/asm/arch-kirkwood/mpp.h index b3c090e..8e50ee7 100644 --- a/arch/arm/include/asm/arch-kirkwood/mpp.h +++ b/arch/arm/include/asm/arch-kirkwood/mpp.h @@ -312,6 +312,6 @@
#define MPP_MAX 49
-void kirkwood_mpp_conf(unsigned int *mpp_list); +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save);
#endif

Hi Valentin,
On Thu, May 31, 2012 at 04:17:52PM +0200, Valentin Longchamp wrote:
If a second non NULL argument is given to the kirkwood_mpp_conf function, it will be used to store the current configuration of the MPP registers. mpp_save must be a preallocated table of the same size as mpp_list and it must be zero terminated as well.
A later call to kirkwood_mpp_conf function with this saved list as first (mpp_conf) argment will set the configuration back.
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 | 14 ++++++++++++-- arch/arm/include/asm/arch-kirkwood/mpp.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c index 3da6c98..158ea84 100644 --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c @@ -31,11 +31,11 @@ static u32 kirkwood_variant(void) #define MPP_CTRL(i) (KW_MPP_BASE + (i* 4)) #define MPP_NR_REGS (1 + MPP_MAX/8)
-void kirkwood_mpp_conf(u32 *mpp_list) +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save) { u32 mpp_ctrl[MPP_NR_REGS]; unsigned int variant_mask;
- int i;
int i, save = 0;
variant_mask = kirkwood_variant(); if (!variant_mask)
@@ -48,10 +48,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) } debug("\n");
if (mpp_save)
save = 1;
while (*mpp_list) { unsigned int num = MPP_NUM(*mpp_list); unsigned int sel = MPP_SEL(*mpp_list);
unsigned int sel_save;
int shift;
if (num > MPP_MAX) {
@@ -66,6 +69,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) }
shift = (num & 7) << 2;
if (save) {
Why using new variable if it's only used in one place? Why not use this here:
if (mpp_save) {
Then we don't need save variable at all.
Luka

Hi Luka,
On 06/01/2012 01:02 AM, Luka Perkov wrote:
Hi Valentin,
On Thu, May 31, 2012 at 04:17:52PM +0200, Valentin Longchamp wrote:
If a second non NULL argument is given to the kirkwood_mpp_conf function, it will be used to store the current configuration of the MPP registers. mpp_save must be a preallocated table of the same size as mpp_list and it must be zero terminated as well.
A later call to kirkwood_mpp_conf function with this saved list as first (mpp_conf) argment will set the configuration back.
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 | 14 ++++++++++++-- arch/arm/include/asm/arch-kirkwood/mpp.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c index 3da6c98..158ea84 100644 --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c @@ -31,11 +31,11 @@ static u32 kirkwood_variant(void) #define MPP_CTRL(i) (KW_MPP_BASE + (i* 4)) #define MPP_NR_REGS (1 + MPP_MAX/8)
-void kirkwood_mpp_conf(u32 *mpp_list) +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save) { u32 mpp_ctrl[MPP_NR_REGS]; unsigned int variant_mask;
- int i;
int i, save = 0;
variant_mask = kirkwood_variant(); if (!variant_mask)
@@ -48,10 +48,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) } debug("\n");
if (mpp_save)
save = 1;
while (*mpp_list) { unsigned int num = MPP_NUM(*mpp_list); unsigned int sel = MPP_SEL(*mpp_list);
unsigned int sel_save;
int shift;
if (num > MPP_MAX) {
@@ -66,6 +69,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) }
shift = (num & 7) << 2;
if (save) {
Why using new variable if it's only used in one place? Why not use this here:
if (mpp_save) {
Then we don't need save variable at all.
Yeah you are right, I can directly test on mpp_save, since it should remain NULL during the whole while loop if NULL at the beginning.

-----Original Message----- From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com] Sent: 01 June 2012 12:33 To: uboot@lukaperkov.net Cc: Prafulla Wadaskar; Brunck, Holger; u-boot@lists.denx.de Subject: Re: [U-Boot] [PATCH v3 1/5] kirkwood: add save functionality kirkwood_mpp_conf function
Hi Luka,
On 06/01/2012 01:02 AM, Luka Perkov wrote:
Hi Valentin,
On Thu, May 31, 2012 at 04:17:52PM +0200, Valentin Longchamp wrote:
If a second non NULL argument is given to the kirkwood_mpp_conf function, it will be used to store the current configuration of the
MPP
registers. mpp_save must be a preallocated table of the same size
as
mpp_list and it must be zero terminated as well.
A later call to kirkwood_mpp_conf function with this saved list as
first
(mpp_conf) argment will set the configuration back.
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 | 14 ++++++++++++-- arch/arm/include/asm/arch-kirkwood/mpp.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c
index 3da6c98..158ea84 100644 --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c @@ -31,11 +31,11 @@ static u32 kirkwood_variant(void) #define MPP_CTRL(i) (KW_MPP_BASE + (i* 4)) #define MPP_NR_REGS (1 + MPP_MAX/8)
-void kirkwood_mpp_conf(u32 *mpp_list) +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save) { u32 mpp_ctrl[MPP_NR_REGS]; unsigned int variant_mask;
- int i;
int i, save = 0;
variant_mask = kirkwood_variant(); if (!variant_mask)
@@ -48,10 +48,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) } debug("\n");
if (mpp_save)
save = 1;
while (*mpp_list) { unsigned int num = MPP_NUM(*mpp_list); unsigned int sel = MPP_SEL(*mpp_list);
unsigned int sel_save;
int shift;
if (num > MPP_MAX) {
@@ -66,6 +69,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) }
shift = (num & 7) << 2;
if (save) {
Why using new variable if it's only used in one place? Why not use
this
here:
if (mpp_save) {
Then we don't need save variable at all.
Yeah you are right, I can directly test on mpp_save, since it should remain NULL during the whole while loop if NULL at the beginning.
Pls port v4 with this fix, rest of the patch series looks okay to me.
Regards.. Prafulla . . .

If a second non NULL argument is given to the kirkwood_mpp_conf function, it will be used to store the current configuration of the MPP registers. mpp_save must be a preallocated table of the same size as mpp_list and it must be zero terminated as well.
A later call to kirkwood_mpp_conf function with this saved list as first (mpp_conf) argment will set the configuration back.
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 | 10 +++++++++- arch/arm/include/asm/arch-kirkwood/mpp.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c index 3da6c98..03eb2de 100644 --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c @@ -31,7 +31,7 @@ static u32 kirkwood_variant(void) #define MPP_CTRL(i) (KW_MPP_BASE + (i* 4)) #define MPP_NR_REGS (1 + MPP_MAX/8)
-void kirkwood_mpp_conf(u32 *mpp_list) +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save) { u32 mpp_ctrl[MPP_NR_REGS]; unsigned int variant_mask; @@ -52,6 +52,7 @@ void kirkwood_mpp_conf(u32 *mpp_list) while (*mpp_list) { unsigned int num = MPP_NUM(*mpp_list); unsigned int sel = MPP_SEL(*mpp_list); + unsigned int sel_save; int shift;
if (num > MPP_MAX) { @@ -66,6 +67,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) }
shift = (num & 7) << 2; + + if (mpp_save) { + sel_save = (mpp_ctrl[num / 8] >> shift) & 0xf; + *mpp_save = num | (sel_save << 8) | variant_mask; + mpp_save++; + } + mpp_ctrl[num / 8] &= ~(0xf << shift); mpp_ctrl[num / 8] |= sel << shift;
diff --git a/arch/arm/include/asm/arch-kirkwood/mpp.h b/arch/arm/include/asm/arch-kirkwood/mpp.h index b3c090e..8e50ee7 100644 --- a/arch/arm/include/asm/arch-kirkwood/mpp.h +++ b/arch/arm/include/asm/arch-kirkwood/mpp.h @@ -312,6 +312,6 @@
#define MPP_MAX 49
-void kirkwood_mpp_conf(unsigned int *mpp_list); +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save);
#endif

-----Original Message----- From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com] Sent: 01 June 2012 14:33 Cc: u-boot@lists.denx.de; Valentin Longchamp; Holger Brunck; Prafulla Wadaskar Subject: [PATCH v4 1/5] kirkwood: add save functionality kirkwood_mpp_conf function
If a second non NULL argument is given to the kirkwood_mpp_conf function, it will be used to store the current configuration of the MPP registers. mpp_save must be a preallocated table of the same size as mpp_list and it must be zero terminated as well.
A later call to kirkwood_mpp_conf function with this saved list as first (mpp_conf) argment will set the configuration back.
Signed-off-by: Valentin Longchamp valentin.longchamp@keymile.com cc: Holger Brunck holger.brunck@keymile.com cc: Prafulla Wadaskar prafulla@marvell.com
Have you send just one file? I have received only one!! No Change log, pls send all files with V4 in the patch series.
Regards.. Prafulla . . .

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
Changes for v3: - moved mpp_read function functionality into mpp_conf function - fixed all calls to mpp_conf so that they are compliant with the newly necessary mpp_conf prototype
Changes for v4: - minor fix in the mpp_conf function
Valentin Longchamp (5): kirkwood: add save functionality kirkwood_mpp_conf function kirkwood: fix calls to kirkwood_mpp_conf 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 | 10 +++- arch/arm/include/asm/arch-kirkwood/mpp.h | 2 +- arch/arm/include/asm/arch-kirkwood/spi.h | 11 ++++ board/LaCie/net2big_v2/net2big_v2.c | 2 +- board/LaCie/netspace_v2/netspace_v2.c | 2 +- board/Marvell/dreamplug/dreamplug.c | 2 +- board/Marvell/guruplug/guruplug.c | 2 +- board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c | 2 +- board/Marvell/openrd/openrd.c | 2 +- board/Marvell/rd6281a/rd6281a.c | 2 +- board/Marvell/sheevaplug/sheevaplug.c | 2 +- board/Seagate/dockstar/dockstar.c | 2 +- board/cloudengines/pogo_e02/pogo_e02.c | 2 +- board/d-link/dns325/dns325.c | 2 +- board/keymile/km_arm/km_arm.c | 6 +- board/raidsonic/ib62x0/ib62x0.c | 2 +- drivers/spi/kirkwood_spi.c | 64 +++++++++++++++++++---- 17 files changed, 90 insertions(+), 27 deletions(-)

If a second non NULL argument is given to the kirkwood_mpp_conf function, it will be used to store the current configuration of the MPP registers. mpp_save must be a preallocated table of the same size as mpp_list and it must be zero terminated as well.
A later call to kirkwood_mpp_conf function with this saved list as first (mpp_conf) argment will set the configuration back.
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 | 10 +++++++++- arch/arm/include/asm/arch-kirkwood/mpp.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c index 3da6c98..03eb2de 100644 --- a/arch/arm/cpu/arm926ejs/kirkwood/mpp.c +++ b/arch/arm/cpu/arm926ejs/kirkwood/mpp.c @@ -31,7 +31,7 @@ static u32 kirkwood_variant(void) #define MPP_CTRL(i) (KW_MPP_BASE + (i* 4)) #define MPP_NR_REGS (1 + MPP_MAX/8)
-void kirkwood_mpp_conf(u32 *mpp_list) +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save) { u32 mpp_ctrl[MPP_NR_REGS]; unsigned int variant_mask; @@ -52,6 +52,7 @@ void kirkwood_mpp_conf(u32 *mpp_list) while (*mpp_list) { unsigned int num = MPP_NUM(*mpp_list); unsigned int sel = MPP_SEL(*mpp_list); + unsigned int sel_save; int shift;
if (num > MPP_MAX) { @@ -66,6 +67,13 @@ void kirkwood_mpp_conf(u32 *mpp_list) }
shift = (num & 7) << 2; + + if (mpp_save) { + sel_save = (mpp_ctrl[num / 8] >> shift) & 0xf; + *mpp_save = num | (sel_save << 8) | variant_mask; + mpp_save++; + } + mpp_ctrl[num / 8] &= ~(0xf << shift); mpp_ctrl[num / 8] |= sel << shift;
diff --git a/arch/arm/include/asm/arch-kirkwood/mpp.h b/arch/arm/include/asm/arch-kirkwood/mpp.h index b3c090e..8e50ee7 100644 --- a/arch/arm/include/asm/arch-kirkwood/mpp.h +++ b/arch/arm/include/asm/arch-kirkwood/mpp.h @@ -312,6 +312,6 @@
#define MPP_MAX 49
-void kirkwood_mpp_conf(unsigned int *mpp_list); +void kirkwood_mpp_conf(u32 *mpp_list, u32 *mpp_save);
#endif

With the new second save argument introduced by the previous patch, all the calls to the function had to be fixed.
Signed-off-by: Valentin Longchamp valentin.longchamp@keymile.com cc: Holger Brunck holger.brunck@keymile.com cc: Prafulla Wadaskar prafulla@marvell.com --- board/LaCie/net2big_v2/net2big_v2.c | 2 +- board/LaCie/netspace_v2/netspace_v2.c | 2 +- board/Marvell/dreamplug/dreamplug.c | 2 +- board/Marvell/guruplug/guruplug.c | 2 +- board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c | 2 +- board/Marvell/openrd/openrd.c | 2 +- board/Marvell/rd6281a/rd6281a.c | 2 +- board/Marvell/sheevaplug/sheevaplug.c | 2 +- board/Seagate/dockstar/dockstar.c | 2 +- board/cloudengines/pogo_e02/pogo_e02.c | 2 +- board/d-link/dns325/dns325.c | 2 +- board/keymile/km_arm/km_arm.c | 6 +++--- board/raidsonic/ib62x0/ib62x0.c | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/board/LaCie/net2big_v2/net2big_v2.c b/board/LaCie/net2big_v2/net2big_v2.c index d0b4adf..0f5e5a5 100644 --- a/board/LaCie/net2big_v2/net2big_v2.c +++ b/board/LaCie/net2big_v2/net2big_v2.c @@ -75,7 +75,7 @@ int board_early_init_f(void) 0 };
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL);
return 0; } diff --git a/board/LaCie/netspace_v2/netspace_v2.c b/board/LaCie/netspace_v2/netspace_v2.c index fbf020f..704005f 100644 --- a/board/LaCie/netspace_v2/netspace_v2.c +++ b/board/LaCie/netspace_v2/netspace_v2.c @@ -73,7 +73,7 @@ int board_early_init_f(void) MPP33_GPIO, /* Fan speed (bit 2) */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL);
return 0; } diff --git a/board/Marvell/dreamplug/dreamplug.c b/board/Marvell/dreamplug/dreamplug.c index 31b73c9..d6497aa 100644 --- a/board/Marvell/dreamplug/dreamplug.c +++ b/board/Marvell/dreamplug/dreamplug.c @@ -99,7 +99,7 @@ int board_early_init_f(void) MPP49_GPIO, /* Wifi AP LED */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/guruplug/guruplug.c b/board/Marvell/guruplug/guruplug.c index 057c558..f5c1c3c 100644 --- a/board/Marvell/guruplug/guruplug.c +++ b/board/Marvell/guruplug/guruplug.c @@ -96,7 +96,7 @@ int board_early_init_f(void) MPP49_GPIO, /* B_GLED */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c b/board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c index 4c41f3b..43852f6 100644 --- a/board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c +++ b/board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c @@ -98,7 +98,7 @@ int board_early_init_f(void) MPP49_GPIO, 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/openrd/openrd.c b/board/Marvell/openrd/openrd.c index 2a10e69..d48f05a 100644 --- a/board/Marvell/openrd/openrd.c +++ b/board/Marvell/openrd/openrd.c @@ -102,7 +102,7 @@ int board_early_init_f(void) 0 };
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/rd6281a/rd6281a.c b/board/Marvell/rd6281a/rd6281a.c index 9c768bf..1fd7677 100644 --- a/board/Marvell/rd6281a/rd6281a.c +++ b/board/Marvell/rd6281a/rd6281a.c @@ -97,7 +97,7 @@ int board_early_init_f(void) MPP49_GPIO, 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/sheevaplug/sheevaplug.c b/board/Marvell/sheevaplug/sheevaplug.c index 71e6793..688d308 100644 --- a/board/Marvell/sheevaplug/sheevaplug.c +++ b/board/Marvell/sheevaplug/sheevaplug.c @@ -96,7 +96,7 @@ int board_early_init_f(void) MPP49_GPIO, 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Seagate/dockstar/dockstar.c b/board/Seagate/dockstar/dockstar.c index 38473e5..fc88520 100644 --- a/board/Seagate/dockstar/dockstar.c +++ b/board/Seagate/dockstar/dockstar.c @@ -100,7 +100,7 @@ int board_early_init_f(void) MPP49_GPIO, 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/cloudengines/pogo_e02/pogo_e02.c b/board/cloudengines/pogo_e02/pogo_e02.c index ff3421d..bac9ce5 100644 --- a/board/cloudengines/pogo_e02/pogo_e02.c +++ b/board/cloudengines/pogo_e02/pogo_e02.c @@ -71,7 +71,7 @@ int board_early_init_f(void) MPP49_GPIO, /* LED orange */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/d-link/dns325/dns325.c b/board/d-link/dns325/dns325.c index 990d79f..11260fe 100644 --- a/board/d-link/dns325/dns325.c +++ b/board/d-link/dns325/dns325.c @@ -97,7 +97,7 @@ int board_early_init_f(void) MPP49_GPIO, /* thermal sensor */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL);
kw_gpio_set_blink(DNS325_GPIO_LED_POWER , 1);
diff --git a/board/keymile/km_arm/km_arm.c b/board/keymile/km_arm/km_arm.c index c6c9a71..ed12b5c 100644 --- a/board/keymile/km_arm/km_arm.c +++ b/board/keymile/km_arm/km_arm.c @@ -244,7 +244,7 @@ int board_early_init_f(void) { u32 tmp;
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL);
/* * The FLASH_GPIO_PIN switches between using a @@ -299,7 +299,7 @@ int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) kwmpp_config[2] = MPP2_NF_IO4; kwmpp_config[3] = MPP3_NF_IO5;
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); tmp = readl(KW_GPIO0_BASE); writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE); } else if ((strcmp(argv[1], "on") == 0)) { @@ -310,7 +310,7 @@ int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) kwmpp_config[2] = MPP2_SPI_SCK; kwmpp_config[3] = MPP3_SPI_MISO;
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); tmp = readl(KW_GPIO0_BASE); writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE); } else { diff --git a/board/raidsonic/ib62x0/ib62x0.c b/board/raidsonic/ib62x0/ib62x0.c index 65f2c2e..1164d6b 100644 --- a/board/raidsonic/ib62x0/ib62x0.c +++ b/board/raidsonic/ib62x0/ib62x0.c @@ -66,7 +66,7 @@ int board_early_init_f(void) MPP29_GPIO, /* USB Copy button */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }

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 | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c index db8ba8b..01e1d11 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,19 +68,18 @@ 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_conf(kwspi_mpp_config); + kirkwood_mpp_conf(kwspi_mpp_config, cs_spi_mpp_back);
return slave; }
void spi_free_slave(struct spi_slave *slave) { + kirkwood_mpp_conf(cs_spi_mpp_back, NULL); free(slave); }

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 | 36 ++++++++++++++++++++++++++++++ 2 files changed, 47 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 01e1d11..db4bb0a 100644 --- a/drivers/spi/kirkwood_spi.c +++ b/drivers/spi/kirkwood_spi.c @@ -83,13 +83,49 @@ 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; + + /* set new spi mpp and save current mpp config */ + kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup); + +#endif + return 0; }
void spi_release_bus(struct spi_slave *slave) { +#if defined(CONFIG_SYS_KW_SPI_MPP) + kirkwood_mpp_conf(spi_mpp_backup, NULL); +#endif }
#ifndef CONFIG_SPI_CS_IS_VALID

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 db4bb0a..f4523a3 100644 --- a/drivers/spi/kirkwood_spi.c +++ b/drivers/spi/kirkwood_spi.c @@ -87,6 +87,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) @@ -118,7 +123,11 @@ int spi_claim_bus(struct spi_slave *slave)
#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) @@ -126,6 +135,8 @@ void spi_release_bus(struct spi_slave *slave) #if defined(CONFIG_SYS_KW_SPI_MPP) kirkwood_mpp_conf(spi_mpp_backup, NULL); #endif + + board_spi_release_bus(slave); }
#ifndef CONFIG_SPI_CS_IS_VALID

-----Original Message----- From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com] Sent: 01 June 2012 17:01 To: Prafulla Wadaskar Cc: u-boot@lists.denx.de; Valentin Longchamp; Holger Brunck Subject: [PATCH v4 5/5] 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
Applied this entire patch series to u-boot-marvell.git master branch
Regards.. Prafulla . . .

Hi Prafulla,
On 06/05/2012 04:21 PM, Prafulla Wadaskar wrote:
-----Original Message----- From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com] Sent: 01 June 2012 17:01 To: Prafulla Wadaskar Cc: u-boot@lists.denx.de; Valentin Longchamp; Holger Brunck Subject: [PATCH v4 5/5] 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
Applied this entire patch series to u-boot-marvell.git master branch
Thank you for applying this patch series. I will now send you the third series as you discussed it with Holger (http://lists.denx.de/pipermail/u-boot/2012-May/125208.html), which contains the patches for the support of new boards and new features for Keymile boards.
Valentin

With the new second save argument introduced by the previous patch, all the calls to the function had to be fixed.
Signed-off-by: Valentin Longchamp valentin.longchamp@keymile.com cc: Holger Brunck holger.brunck@keymile.com cc: Prafulla Wadaskar prafulla@marvell.com --- board/LaCie/net2big_v2/net2big_v2.c | 2 +- board/LaCie/netspace_v2/netspace_v2.c | 2 +- board/Marvell/dreamplug/dreamplug.c | 2 +- board/Marvell/guruplug/guruplug.c | 2 +- board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c | 2 +- board/Marvell/openrd/openrd.c | 2 +- board/Marvell/rd6281a/rd6281a.c | 2 +- board/Marvell/sheevaplug/sheevaplug.c | 2 +- board/Seagate/dockstar/dockstar.c | 2 +- board/cloudengines/pogo_e02/pogo_e02.c | 2 +- board/d-link/dns325/dns325.c | 2 +- board/keymile/km_arm/km_arm.c | 6 +++--- board/raidsonic/ib62x0/ib62x0.c | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/board/LaCie/net2big_v2/net2big_v2.c b/board/LaCie/net2big_v2/net2big_v2.c index d0b4adf..0f5e5a5 100644 --- a/board/LaCie/net2big_v2/net2big_v2.c +++ b/board/LaCie/net2big_v2/net2big_v2.c @@ -75,7 +75,7 @@ int board_early_init_f(void) 0 };
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL);
return 0; } diff --git a/board/LaCie/netspace_v2/netspace_v2.c b/board/LaCie/netspace_v2/netspace_v2.c index fbf020f..704005f 100644 --- a/board/LaCie/netspace_v2/netspace_v2.c +++ b/board/LaCie/netspace_v2/netspace_v2.c @@ -73,7 +73,7 @@ int board_early_init_f(void) MPP33_GPIO, /* Fan speed (bit 2) */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL);
return 0; } diff --git a/board/Marvell/dreamplug/dreamplug.c b/board/Marvell/dreamplug/dreamplug.c index 31b73c9..d6497aa 100644 --- a/board/Marvell/dreamplug/dreamplug.c +++ b/board/Marvell/dreamplug/dreamplug.c @@ -99,7 +99,7 @@ int board_early_init_f(void) MPP49_GPIO, /* Wifi AP LED */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/guruplug/guruplug.c b/board/Marvell/guruplug/guruplug.c index 057c558..f5c1c3c 100644 --- a/board/Marvell/guruplug/guruplug.c +++ b/board/Marvell/guruplug/guruplug.c @@ -96,7 +96,7 @@ int board_early_init_f(void) MPP49_GPIO, /* B_GLED */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c b/board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c index 4c41f3b..43852f6 100644 --- a/board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c +++ b/board/Marvell/mv88f6281gtw_ge/mv88f6281gtw_ge.c @@ -98,7 +98,7 @@ int board_early_init_f(void) MPP49_GPIO, 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/openrd/openrd.c b/board/Marvell/openrd/openrd.c index 2a10e69..d48f05a 100644 --- a/board/Marvell/openrd/openrd.c +++ b/board/Marvell/openrd/openrd.c @@ -102,7 +102,7 @@ int board_early_init_f(void) 0 };
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/rd6281a/rd6281a.c b/board/Marvell/rd6281a/rd6281a.c index 9c768bf..1fd7677 100644 --- a/board/Marvell/rd6281a/rd6281a.c +++ b/board/Marvell/rd6281a/rd6281a.c @@ -97,7 +97,7 @@ int board_early_init_f(void) MPP49_GPIO, 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Marvell/sheevaplug/sheevaplug.c b/board/Marvell/sheevaplug/sheevaplug.c index 71e6793..688d308 100644 --- a/board/Marvell/sheevaplug/sheevaplug.c +++ b/board/Marvell/sheevaplug/sheevaplug.c @@ -96,7 +96,7 @@ int board_early_init_f(void) MPP49_GPIO, 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/Seagate/dockstar/dockstar.c b/board/Seagate/dockstar/dockstar.c index 38473e5..fc88520 100644 --- a/board/Seagate/dockstar/dockstar.c +++ b/board/Seagate/dockstar/dockstar.c @@ -100,7 +100,7 @@ int board_early_init_f(void) MPP49_GPIO, 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/cloudengines/pogo_e02/pogo_e02.c b/board/cloudengines/pogo_e02/pogo_e02.c index ff3421d..bac9ce5 100644 --- a/board/cloudengines/pogo_e02/pogo_e02.c +++ b/board/cloudengines/pogo_e02/pogo_e02.c @@ -71,7 +71,7 @@ int board_early_init_f(void) MPP49_GPIO, /* LED orange */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }
diff --git a/board/d-link/dns325/dns325.c b/board/d-link/dns325/dns325.c index 990d79f..11260fe 100644 --- a/board/d-link/dns325/dns325.c +++ b/board/d-link/dns325/dns325.c @@ -97,7 +97,7 @@ int board_early_init_f(void) MPP49_GPIO, /* thermal sensor */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL);
kw_gpio_set_blink(DNS325_GPIO_LED_POWER , 1);
diff --git a/board/keymile/km_arm/km_arm.c b/board/keymile/km_arm/km_arm.c index c6c9a71..ed12b5c 100644 --- a/board/keymile/km_arm/km_arm.c +++ b/board/keymile/km_arm/km_arm.c @@ -244,7 +244,7 @@ int board_early_init_f(void) { u32 tmp;
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL);
/* * The FLASH_GPIO_PIN switches between using a @@ -299,7 +299,7 @@ int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) kwmpp_config[2] = MPP2_NF_IO4; kwmpp_config[3] = MPP3_NF_IO5;
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); tmp = readl(KW_GPIO0_BASE); writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE); } else if ((strcmp(argv[1], "on") == 0)) { @@ -310,7 +310,7 @@ int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) kwmpp_config[2] = MPP2_SPI_SCK; kwmpp_config[3] = MPP3_SPI_MISO;
- kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); tmp = readl(KW_GPIO0_BASE); writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE); } else { diff --git a/board/raidsonic/ib62x0/ib62x0.c b/board/raidsonic/ib62x0/ib62x0.c index 65f2c2e..1164d6b 100644 --- a/board/raidsonic/ib62x0/ib62x0.c +++ b/board/raidsonic/ib62x0/ib62x0.c @@ -66,7 +66,7 @@ int board_early_init_f(void) MPP29_GPIO, /* USB Copy button */ 0 }; - kirkwood_mpp_conf(kwmpp_config); + kirkwood_mpp_conf(kwmpp_config, NULL); return 0; }

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 | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c index db8ba8b..01e1d11 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,19 +68,18 @@ 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_conf(kwspi_mpp_config); + kirkwood_mpp_conf(kwspi_mpp_config, cs_spi_mpp_back);
return slave; }
void spi_free_slave(struct spi_slave *slave) { + kirkwood_mpp_conf(cs_spi_mpp_back, NULL); free(slave); }

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 | 36 ++++++++++++++++++++++++++++++ 2 files changed, 47 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 01e1d11..db4bb0a 100644 --- a/drivers/spi/kirkwood_spi.c +++ b/drivers/spi/kirkwood_spi.c @@ -83,13 +83,49 @@ 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; + + /* set new spi mpp and save current mpp config */ + kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup); + +#endif + return 0; }
void spi_release_bus(struct spi_slave *slave) { +#if defined(CONFIG_SYS_KW_SPI_MPP) + kirkwood_mpp_conf(spi_mpp_backup, NULL); +#endif }
#ifndef CONFIG_SPI_CS_IS_VALID

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 db4bb0a..f4523a3 100644 --- a/drivers/spi/kirkwood_spi.c +++ b/drivers/spi/kirkwood_spi.c @@ -87,6 +87,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) @@ -118,7 +123,11 @@ int spi_claim_bus(struct spi_slave *slave)
#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) @@ -126,6 +135,8 @@ void spi_release_bus(struct spi_slave *slave) #if defined(CONFIG_SYS_KW_SPI_MPP) kirkwood_mpp_conf(spi_mpp_backup, NULL); #endif + + board_spi_release_bus(slave); }
#ifndef CONFIG_SPI_CS_IS_VALID
participants (3)
-
Luka Perkov
-
Prafulla Wadaskar
-
Valentin Longchamp