diff mbox

[U-Boot,02/20] arm/km: use correct kw_gpio function for NAND/SPI switching

Message ID 1339063620-8890-3-git-send-email-valentin.longchamp@keymile.com
State Rejected
Delegated to: Prafulla Wadaskar
Headers show

Commit Message

Valentin Longchamp June 7, 2012, 10:06 a.m. UTC
This used to be done with registers direct access, which is not clear
and optimal.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
cc: Gerlando Falauto <gerlando.falauto@keymile.com>
cc: Prafulla Wadaskar <prafulla@marvell.com>
---
 board/keymile/km_arm/km_arm.c |   53 +++++++++++++++++++++-------------------
 include/configs/km/km_arm.h   |    1 +
 2 files changed, 29 insertions(+), 25 deletions(-)

Comments

Prafulla Wadaskar June 12, 2012, 4:39 a.m. UTC | #1
> -----Original Message-----
> From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com]
> Sent: 07 June 2012 15:37
> To: prafulla@mavell.com
> Cc: Valentin Longchamp; holger.brunck@keymile.com; u-
> boot@lists.denx.de; Gerlando Falauto; Prafulla Wadaskar
> Subject: [PATCH 02/20] arm/km: use correct kw_gpio function for
> NAND/SPI switching
> 
> This used to be done with registers direct access, which is not clear
> and optimal.
> 
> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
> cc: Gerlando Falauto <gerlando.falauto@keymile.com>
> cc: Prafulla Wadaskar <prafulla@marvell.com>
> ---
>  board/keymile/km_arm/km_arm.c |   53 +++++++++++++++++++++-----------
> --------
>  include/configs/km/km_arm.h   |    1 +
>  2 files changed, 29 insertions(+), 25 deletions(-)
> 
> diff --git a/board/keymile/km_arm/km_arm.c
> b/board/keymile/km_arm/km_arm.c
> index ed12b5c..e4ae1fb 100644
> --- a/board/keymile/km_arm/km_arm.c
> +++ b/board/keymile/km_arm/km_arm.c
> @@ -247,15 +247,12 @@ int board_early_init_f(void)
>  	kirkwood_mpp_conf(kwmpp_config, NULL);
> 
>  	/*
> -	 * The FLASH_GPIO_PIN switches between using a
> +	 * The KM_FLASH_GPIO_PIN switches between using a
>  	 * NAND or a SPI FLASH. Set this pin on start
>  	 * to NAND mode.
>  	 */
> -	tmp = readl(KW_GPIO0_BASE);
> -	writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
> -	tmp = readl(KW_GPIO0_BASE + 4);
> -	writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
> -
> +	kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
> +	kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
>  #if defined(CONFIG_SOFT_I2C)
>  	/* init the GPIO for I2C Bitbang driver */
>  	kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
> @@ -284,35 +281,41 @@ int board_init(void)
>  	return 0;
>  }
> 
> +int km_hw_spi_bus_claim(int on)
> +{
> +	int gpio_value = !on;
> +
> +	if (on) {
> +		kwmpp_config[0] = MPP0_SPI_SCn;
> +		kwmpp_config[1] = MPP1_SPI_MOSI;
> +		kwmpp_config[2] = MPP2_SPI_SCK;
> +		kwmpp_config[3] = MPP3_SPI_MISO;
> +	} else {
> +		kwmpp_config[0] = MPP0_NF_IO2;
> +		kwmpp_config[1] = MPP1_NF_IO3;
> +		kwmpp_config[2] = MPP2_NF_IO4;
> +		kwmpp_config[3] = MPP3_NF_IO5;
> +	}

NACK...

Regards..
Prafulla . . .
Holger Brunck June 12, 2012, 8:38 a.m. UTC | #2
On 06/12/2012 06:39 AM, Prafulla Wadaskar wrote:
> 
> 
>> -----Original Message-----
>> From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com]
>> Sent: 07 June 2012 15:37
>> To: prafulla@mavell.com
>> Cc: Valentin Longchamp; holger.brunck@keymile.com; u-
>> boot@lists.denx.de; Gerlando Falauto; Prafulla Wadaskar
>> Subject: [PATCH 02/20] arm/km: use correct kw_gpio function for
>> NAND/SPI switching
>>
>> This used to be done with registers direct access, which is not clear
>> and optimal.
>>
>> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
>> Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
>> cc: Gerlando Falauto <gerlando.falauto@keymile.com>
>> cc: Prafulla Wadaskar <prafulla@marvell.com>
>> ---
>>  board/keymile/km_arm/km_arm.c |   53 +++++++++++++++++++++-----------
>> --------
>>  include/configs/km/km_arm.h   |    1 +
>>  2 files changed, 29 insertions(+), 25 deletions(-)
>>
>> diff --git a/board/keymile/km_arm/km_arm.c
>> b/board/keymile/km_arm/km_arm.c
>> index ed12b5c..e4ae1fb 100644
>> --- a/board/keymile/km_arm/km_arm.c
>> +++ b/board/keymile/km_arm/km_arm.c
>> @@ -247,15 +247,12 @@ int board_early_init_f(void)
>>  	kirkwood_mpp_conf(kwmpp_config, NULL);
>>
>>  	/*
>> -	 * The FLASH_GPIO_PIN switches between using a
>> +	 * The KM_FLASH_GPIO_PIN switches between using a
>>  	 * NAND or a SPI FLASH. Set this pin on start
>>  	 * to NAND mode.
>>  	 */
>> -	tmp = readl(KW_GPIO0_BASE);
>> -	writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
>> -	tmp = readl(KW_GPIO0_BASE + 4);
>> -	writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
>> -
>> +	kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
>> +	kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
>>  #if defined(CONFIG_SOFT_I2C)
>>  	/* init the GPIO for I2C Bitbang driver */
>>  	kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
>> @@ -284,35 +281,41 @@ int board_init(void)
>>  	return 0;
>>  }
>>
>> +int km_hw_spi_bus_claim(int on)
>> +{
>> +	int gpio_value = !on;
>> +
>> +	if (on) {
>> +		kwmpp_config[0] = MPP0_SPI_SCn;
>> +		kwmpp_config[1] = MPP1_SPI_MOSI;
>> +		kwmpp_config[2] = MPP2_SPI_SCK;
>> +		kwmpp_config[3] = MPP3_SPI_MISO;
>> +	} else {
>> +		kwmpp_config[0] = MPP0_NF_IO2;
>> +		kwmpp_config[1] = MPP1_NF_IO3;
>> +		kwmpp_config[2] = MPP2_NF_IO4;
>> +		kwmpp_config[3] = MPP3_NF_IO5;
>> +	}
> 
> NACK...
> 

Could you please be a bit more verbose. Why do you NACK this? This code is only
related to our boards...

Regards
Holger
Prafulla Wadaskar June 12, 2012, 9:32 a.m. UTC | #3
> -----Original Message-----
> From: Holger Brunck [mailto:holger.brunck@keymile.com]
> Sent: 12 June 2012 14:08
> To: Prafulla Wadaskar
> Cc: Valentin Longchamp; prafulla@mavell.com; u-boot@lists.denx.de;
> Gerlando Falauto
> Subject: Re: [PATCH 02/20] arm/km: use correct kw_gpio function for
> NAND/SPI switching
> 
> On 06/12/2012 06:39 AM, Prafulla Wadaskar wrote:
> >
> >
> >> -----Original Message-----
> >> From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com]
> >> Sent: 07 June 2012 15:37
> >> To: prafulla@mavell.com
> >> Cc: Valentin Longchamp; holger.brunck@keymile.com; u-
> >> boot@lists.denx.de; Gerlando Falauto; Prafulla Wadaskar
> >> Subject: [PATCH 02/20] arm/km: use correct kw_gpio function for
> >> NAND/SPI switching
> >>
> >> This used to be done with registers direct access, which is not
> clear
> >> and optimal.
> >>
> >> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> >> Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
> >> cc: Gerlando Falauto <gerlando.falauto@keymile.com>
> >> cc: Prafulla Wadaskar <prafulla@marvell.com>
> >> ---
> >>  board/keymile/km_arm/km_arm.c |   53 +++++++++++++++++++++--------
> ---
> >> --------
> >>  include/configs/km/km_arm.h   |    1 +
> >>  2 files changed, 29 insertions(+), 25 deletions(-)
> >>
> >> diff --git a/board/keymile/km_arm/km_arm.c
> >> b/board/keymile/km_arm/km_arm.c
> >> index ed12b5c..e4ae1fb 100644
> >> --- a/board/keymile/km_arm/km_arm.c
> >> +++ b/board/keymile/km_arm/km_arm.c
> >> @@ -247,15 +247,12 @@ int board_early_init_f(void)
> >>  	kirkwood_mpp_conf(kwmpp_config, NULL);
> >>
> >>  	/*
> >> -	 * The FLASH_GPIO_PIN switches between using a
> >> +	 * The KM_FLASH_GPIO_PIN switches between using a
> >>  	 * NAND or a SPI FLASH. Set this pin on start
> >>  	 * to NAND mode.
> >>  	 */
> >> -	tmp = readl(KW_GPIO0_BASE);
> >> -	writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
> >> -	tmp = readl(KW_GPIO0_BASE + 4);
> >> -	writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
> >> -
> >> +	kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
> >> +	kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
> >>  #if defined(CONFIG_SOFT_I2C)
> >>  	/* init the GPIO for I2C Bitbang driver */
> >>  	kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
> >> @@ -284,35 +281,41 @@ int board_init(void)
> >>  	return 0;
> >>  }
> >>
> >> +int km_hw_spi_bus_claim(int on)
> >> +{
> >> +	int gpio_value = !on;
> >> +
> >> +	if (on) {
> >> +		kwmpp_config[0] = MPP0_SPI_SCn;
> >> +		kwmpp_config[1] = MPP1_SPI_MOSI;
> >> +		kwmpp_config[2] = MPP2_SPI_SCK;
> >> +		kwmpp_config[3] = MPP3_SPI_MISO;
> >> +	} else {
> >> +		kwmpp_config[0] = MPP0_NF_IO2;
> >> +		kwmpp_config[1] = MPP1_NF_IO3;
> >> +		kwmpp_config[2] = MPP2_NF_IO4;
> >> +		kwmpp_config[3] = MPP3_NF_IO5;
> >> +	}
> >
> > NACK...
> >
> 
> Could you please be a bit more verbose. Why do you NACK this? This
> code is only
> related to our boards...

Dear Holger
We have already patches for Kirkwood-spi in place that address this.
So we have to use this framework.

Ref: http://lists.denx.de/pipermail/u-boot/2012-June/125574.html

Regards..
Prafulla . . .
Holger Brunck June 12, 2012, 10:29 a.m. UTC | #4
On 06/12/2012 11:32 AM, Prafulla Wadaskar wrote:
> 
> 
>> -----Original Message-----
>> From: Holger Brunck [mailto:holger.brunck@keymile.com]
>> Sent: 12 June 2012 14:08
>> To: Prafulla Wadaskar
>> Cc: Valentin Longchamp; prafulla@mavell.com; u-boot@lists.denx.de;
>> Gerlando Falauto
>> Subject: Re: [PATCH 02/20] arm/km: use correct kw_gpio function for
>> NAND/SPI switching
>>
>> On 06/12/2012 06:39 AM, Prafulla Wadaskar wrote:
>>>
>>>
>>>> -----Original Message-----
>>>> From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com]
>>>> Sent: 07 June 2012 15:37
>>>> To: prafulla@mavell.com
>>>> Cc: Valentin Longchamp; holger.brunck@keymile.com; u-
>>>> boot@lists.denx.de; Gerlando Falauto; Prafulla Wadaskar
>>>> Subject: [PATCH 02/20] arm/km: use correct kw_gpio function for
>>>> NAND/SPI switching
>>>>
>>>> This used to be done with registers direct access, which is not
>> clear
>>>> and optimal.
>>>>
>>>> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
>>>> Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
>>>> cc: Gerlando Falauto <gerlando.falauto@keymile.com>
>>>> cc: Prafulla Wadaskar <prafulla@marvell.com>
>>>> ---
>>>>  board/keymile/km_arm/km_arm.c |   53 +++++++++++++++++++++--------
>> ---
>>>> --------
>>>>  include/configs/km/km_arm.h   |    1 +
>>>>  2 files changed, 29 insertions(+), 25 deletions(-)
>>>>
>>>> diff --git a/board/keymile/km_arm/km_arm.c
>>>> b/board/keymile/km_arm/km_arm.c
>>>> index ed12b5c..e4ae1fb 100644
>>>> --- a/board/keymile/km_arm/km_arm.c
>>>> +++ b/board/keymile/km_arm/km_arm.c
>>>> @@ -247,15 +247,12 @@ int board_early_init_f(void)
>>>>  	kirkwood_mpp_conf(kwmpp_config, NULL);
>>>>
>>>>  	/*
>>>> -	 * The FLASH_GPIO_PIN switches between using a
>>>> +	 * The KM_FLASH_GPIO_PIN switches between using a
>>>>  	 * NAND or a SPI FLASH. Set this pin on start
>>>>  	 * to NAND mode.
>>>>  	 */
>>>> -	tmp = readl(KW_GPIO0_BASE);
>>>> -	writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
>>>> -	tmp = readl(KW_GPIO0_BASE + 4);
>>>> -	writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
>>>> -
>>>> +	kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
>>>> +	kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
>>>>  #if defined(CONFIG_SOFT_I2C)
>>>>  	/* init the GPIO for I2C Bitbang driver */
>>>>  	kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
>>>> @@ -284,35 +281,41 @@ int board_init(void)
>>>>  	return 0;
>>>>  }
>>>>
>>>> +int km_hw_spi_bus_claim(int on)
>>>> +{
>>>> +	int gpio_value = !on;
>>>> +
>>>> +	if (on) {
>>>> +		kwmpp_config[0] = MPP0_SPI_SCn;
>>>> +		kwmpp_config[1] = MPP1_SPI_MOSI;
>>>> +		kwmpp_config[2] = MPP2_SPI_SCK;
>>>> +		kwmpp_config[3] = MPP3_SPI_MISO;
>>>> +	} else {
>>>> +		kwmpp_config[0] = MPP0_NF_IO2;
>>>> +		kwmpp_config[1] = MPP1_NF_IO3;
>>>> +		kwmpp_config[2] = MPP2_NF_IO4;
>>>> +		kwmpp_config[3] = MPP3_NF_IO5;
>>>> +	}
>>>
>>> NACK...
>>>
>>
>> Could you please be a bit more verbose. Why do you NACK this? This
>> code is only
>> related to our boards...
> 
> Dear Holger
> We have already patches for Kirkwood-spi in place that address this.
> So we have to use this framework.
> 
> Ref: http://lists.denx.de/pipermail/u-boot/2012-June/125574.html
> 

ok I see what you mean. We make use of it later on:
[PATCH 18/20] arm/km: implement weak function board_spi_clam_bus/release
I'll squash this one together with 02/20 then it is more clear.

Regards
Holger
Holger Brunck June 13, 2012, 12:16 p.m. UTC | #5
On 06/12/2012 12:29 PM, Holger Brunck wrote:
> On 06/12/2012 11:32 AM, Prafulla Wadaskar wrote:
>>
>>
>>> -----Original Message-----
>>> From: Holger Brunck [mailto:holger.brunck@keymile.com]
>>> Sent: 12 June 2012 14:08
>>> To: Prafulla Wadaskar
>>> Cc: Valentin Longchamp; prafulla@mavell.com; u-boot@lists.denx.de;
>>> Gerlando Falauto
>>> Subject: Re: [PATCH 02/20] arm/km: use correct kw_gpio function for
>>> NAND/SPI switching
>>>
>>> On 06/12/2012 06:39 AM, Prafulla Wadaskar wrote:
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Valentin Longchamp [mailto:valentin.longchamp@keymile.com]
>>>>> Sent: 07 June 2012 15:37
>>>>> To: prafulla@mavell.com
>>>>> Cc: Valentin Longchamp; holger.brunck@keymile.com; u-
>>>>> boot@lists.denx.de; Gerlando Falauto; Prafulla Wadaskar
>>>>> Subject: [PATCH 02/20] arm/km: use correct kw_gpio function for
>>>>> NAND/SPI switching
>>>>>
>>>>> This used to be done with registers direct access, which is not
>>> clear
>>>>> and optimal.
>>>>>
>>>>> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
>>>>> Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
>>>>> cc: Gerlando Falauto <gerlando.falauto@keymile.com>
>>>>> cc: Prafulla Wadaskar <prafulla@marvell.com>
>>>>> ---
>>>>>  board/keymile/km_arm/km_arm.c |   53 +++++++++++++++++++++--------
>>> ---
>>>>> --------
>>>>>  include/configs/km/km_arm.h   |    1 +
>>>>>  2 files changed, 29 insertions(+), 25 deletions(-)
>>>>>
>>>>> diff --git a/board/keymile/km_arm/km_arm.c
>>>>> b/board/keymile/km_arm/km_arm.c
>>>>> index ed12b5c..e4ae1fb 100644
>>>>> --- a/board/keymile/km_arm/km_arm.c
>>>>> +++ b/board/keymile/km_arm/km_arm.c
>>>>> @@ -247,15 +247,12 @@ int board_early_init_f(void)
>>>>>  	kirkwood_mpp_conf(kwmpp_config, NULL);
>>>>>
>>>>>  	/*
>>>>> -	 * The FLASH_GPIO_PIN switches between using a
>>>>> +	 * The KM_FLASH_GPIO_PIN switches between using a
>>>>>  	 * NAND or a SPI FLASH. Set this pin on start
>>>>>  	 * to NAND mode.
>>>>>  	 */
>>>>> -	tmp = readl(KW_GPIO0_BASE);
>>>>> -	writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
>>>>> -	tmp = readl(KW_GPIO0_BASE + 4);
>>>>> -	writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
>>>>> -
>>>>> +	kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
>>>>> +	kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
>>>>>  #if defined(CONFIG_SOFT_I2C)
>>>>>  	/* init the GPIO for I2C Bitbang driver */
>>>>>  	kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
>>>>> @@ -284,35 +281,41 @@ int board_init(void)
>>>>>  	return 0;
>>>>>  }
>>>>>
>>>>> +int km_hw_spi_bus_claim(int on)
>>>>> +{
>>>>> +	int gpio_value = !on;
>>>>> +
>>>>> +	if (on) {
>>>>> +		kwmpp_config[0] = MPP0_SPI_SCn;
>>>>> +		kwmpp_config[1] = MPP1_SPI_MOSI;
>>>>> +		kwmpp_config[2] = MPP2_SPI_SCK;
>>>>> +		kwmpp_config[3] = MPP3_SPI_MISO;
>>>>> +	} else {
>>>>> +		kwmpp_config[0] = MPP0_NF_IO2;
>>>>> +		kwmpp_config[1] = MPP1_NF_IO3;
>>>>> +		kwmpp_config[2] = MPP2_NF_IO4;
>>>>> +		kwmpp_config[3] = MPP3_NF_IO5;
>>>>> +	}
>>>>
>>>> NACK...
>>>>
>>>
>>> Could you please be a bit more verbose. Why do you NACK this? This
>>> code is only
>>> related to our boards...
>>
>> Dear Holger
>> We have already patches for Kirkwood-spi in place that address this.
>> So we have to use this framework.
>>
>> Ref: http://lists.denx.de/pipermail/u-boot/2012-June/125574.html
>>
> 
> ok I see what you mean. We make use of it later on:
> [PATCH 18/20] arm/km: implement weak function board_spi_clam_bus/release
> I'll squash this one together with 02/20 then it is more clear.
> 

ok  I'll send an update of the SPI feature update soon as a standalone patch.
I'll squash

[PATCH 01/20] arm/km: enable spi claim bus
[PATCH 02/20] arm/km: use correct kw_gpio function for NAND/SPI switching
[PATCH 18/20] arm/km: implement weak function board_spi_clam_bus/release
[PATCH 19/20] arm/km: remove spi toggle command

into it and then it is much more clear what the patch does.

Updates with your inputs of the remaining patches will also follow.

Regards
Holger
diff mbox

Patch

diff --git a/board/keymile/km_arm/km_arm.c b/board/keymile/km_arm/km_arm.c
index ed12b5c..e4ae1fb 100644
--- a/board/keymile/km_arm/km_arm.c
+++ b/board/keymile/km_arm/km_arm.c
@@ -247,15 +247,12 @@  int board_early_init_f(void)
 	kirkwood_mpp_conf(kwmpp_config, NULL);
 
 	/*
-	 * The FLASH_GPIO_PIN switches between using a
+	 * The KM_FLASH_GPIO_PIN switches between using a
 	 * NAND or a SPI FLASH. Set this pin on start
 	 * to NAND mode.
 	 */
-	tmp = readl(KW_GPIO0_BASE);
-	writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
-	tmp = readl(KW_GPIO0_BASE + 4);
-	writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
-
+	kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
+	kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
 #if defined(CONFIG_SOFT_I2C)
 	/* init the GPIO for I2C Bitbang driver */
 	kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
@@ -284,35 +281,41 @@  int board_init(void)
 	return 0;
 }
 
+int km_hw_spi_bus_claim(int on)
+{
+	int gpio_value = !on;
+
+	if (on) {
+		kwmpp_config[0] = MPP0_SPI_SCn;
+		kwmpp_config[1] = MPP1_SPI_MOSI;
+		kwmpp_config[2] = MPP2_SPI_SCK;
+		kwmpp_config[3] = MPP3_SPI_MISO;
+	} else {
+		kwmpp_config[0] = MPP0_NF_IO2;
+		kwmpp_config[1] = MPP1_NF_IO3;
+		kwmpp_config[2] = MPP2_NF_IO4;
+		kwmpp_config[3] = MPP3_NF_IO5;
+	}
+
+	/* Multi-Purpose Pins Functionality configuration */
+	kirkwood_mpp_conf(kwmpp_config, NULL);
+	kw_gpio_set_value(KM_FLASH_GPIO_PIN, gpio_value);
+
+	return 0;
+}
+
 #if defined(CONFIG_CMD_SF)
 int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	u32 tmp;
 	if (argc < 2)
 		return cmd_usage(cmdtp);
 
 	if ((strcmp(argv[1], "off") == 0)) {
 		printf("SPI FLASH disabled, NAND enabled\n");
-		/* Multi-Purpose Pins Functionality configuration */
-		kwmpp_config[0] = MPP0_NF_IO2;
-		kwmpp_config[1] = MPP1_NF_IO3;
-		kwmpp_config[2] = MPP2_NF_IO4;
-		kwmpp_config[3] = MPP3_NF_IO5;
-
-		kirkwood_mpp_conf(kwmpp_config, NULL);
-		tmp = readl(KW_GPIO0_BASE);
-		writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
+		km_hw_spi_bus_claim(0);
 	} else if ((strcmp(argv[1], "on") == 0)) {
 		printf("SPI FLASH enabled, NAND disabled\n");
-		/* Multi-Purpose Pins Functionality configuration */
-		kwmpp_config[0] = MPP0_SPI_SCn;
-		kwmpp_config[1] = MPP1_SPI_MOSI;
-		kwmpp_config[2] = MPP2_SPI_SCK;
-		kwmpp_config[3] = MPP3_SPI_MISO;
-
-		kirkwood_mpp_conf(kwmpp_config, NULL);
-		tmp = readl(KW_GPIO0_BASE);
-		writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE);
+		km_hw_spi_bus_claim(1);
 	} else {
 		return cmd_usage(cmdtp);
 	}
diff --git a/include/configs/km/km_arm.h b/include/configs/km/km_arm.h
index 056bf53..28b5021 100644
--- a/include/configs/km/km_arm.h
+++ b/include/configs/km/km_arm.h
@@ -231,6 +231,7 @@  int get_scl(void);
 #define CONFIG_SYS_KW_SPI_MPP	0x0
 
 #define FLASH_GPIO_PIN			0x00010000
+#define KM_FLASH_GPIO_PIN	16
 
 #define MTDIDS_DEFAULT		"nand0=orion_nand"
 /* test-only: partitioning needs some tuning, this is just for tests */