diff mbox

[U-Boot,RFC] arm926ejs, at91: add common phy_reset function

Message ID 1384251676-3601-1-git-send-email-hs@denx.de
State Superseded, archived
Delegated to: Andreas Bießmann
Headers show

Commit Message

Heiko Schocher Nov. 12, 2013, 10:21 a.m. UTC
add common phy reset code into a common function.

Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Andreas Bießmann <andreas.devel@googlemail.com>
Cc: Bo Shen <voice.shen@atmel.com>
Cc: Jens Scharsig <esw@bus-elektronik.de>
Cc: Sergey Lapin <slapin@ossfans.org>
Cc: Stelian Pop <stelian@popies.net>
Cc: Albin Tonnerre <albin.tonnerre@free-electrons.com>
Cc: Eric Benard <eric@eukrea.com>
Cc: Markus Hubig <mhubig@imko.de>

---
Patch based on the spl patchset from Bo Shen (as I want to
collect this function in at91-common directory), see:
http://lists.denx.de/pipermail/u-boot/2013-November/166272.html
(reworked this against newest Kconfig Makefile changes ...
 @Bo: Do you plan an update for this patchset for the Kconfig changes?

Maybe my change in arch/arm/cpu/at91-common/Makefile
could be done better... Do we have a common define for
all this variants?

---
 arch/arm/cpu/Makefile                           |  1 +
 arch/arm/cpu/at91-common/Makefile               |  5 +++
 arch/arm/cpu/at91-common/phy.c                  | 48 +++++++++++++++++++++++++
 arch/arm/include/asm/arch-at91/at91_common.h    |  1 +
 board/BuS/vl_ma2sc/vl_ma2sc.c                   | 18 ++--------
 board/afeb9260/afeb9260.c                       | 18 +---------
 board/atmel/at91sam9260ek/at91sam9260ek.c       | 19 +---------
 board/atmel/at91sam9263ek/at91sam9263ek.c       | 19 ++--------
 board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c | 19 +---------
 board/bluewater/snapper9260/snapper9260.c       | 16 +--------
 board/calao/sbc35_a9g20/sbc35_a9g20.c           | 19 +---------
 board/eukrea/cpu9260/cpu9260.c                  | 18 +---------
 board/taskit/stamp9g20/stamp9g20.c              | 31 +---------------
 spl/Makefile                                    |  4 ---
 14 files changed, 66 insertions(+), 170 deletions(-)
 create mode 100644 arch/arm/cpu/at91-common/phy.c

Comments

Andreas Bießmann Nov. 12, 2013, 12:56 p.m. UTC | #1
Hello Heiko,

On 11/12/2013 11:21 AM, Heiko Schocher wrote:
> add common phy reset code into a common function.
> 
> Signed-off-by: Heiko Schocher <hs@denx.de>
> Cc: Andreas Bießmann <andreas.devel@googlemail.com>
> Cc: Bo Shen <voice.shen@atmel.com>
> Cc: Jens Scharsig <esw@bus-elektronik.de>
> Cc: Sergey Lapin <slapin@ossfans.org>
> Cc: Stelian Pop <stelian@popies.net>
> Cc: Albin Tonnerre <albin.tonnerre@free-electrons.com>
> Cc: Eric Benard <eric@eukrea.com>
> Cc: Markus Hubig <mhubig@imko.de>
> 
> ---
> Patch based on the spl patchset from Bo Shen (as I want to
> collect this function in at91-common directory), see:
> http://lists.denx.de/pipermail/u-boot/2013-November/166272.html
> (reworked this against newest Kconfig Makefile changes ...
>  @Bo: Do you plan an update for this patchset for the Kconfig changes?

@Bo: I'll review the patches also these days.

> 
> Maybe my change in arch/arm/cpu/at91-common/Makefile
> could be done better... Do we have a common define for
> all this variants?

I think not, but how about defining a new one?

> 
> ---
>  arch/arm/cpu/Makefile                           |  1 +
>  arch/arm/cpu/at91-common/Makefile               |  5 +++
>  arch/arm/cpu/at91-common/phy.c                  | 48 +++++++++++++++++++++++++
>  arch/arm/include/asm/arch-at91/at91_common.h    |  1 +
>  board/BuS/vl_ma2sc/vl_ma2sc.c                   | 18 ++--------
>  board/afeb9260/afeb9260.c                       | 18 +---------
>  board/atmel/at91sam9260ek/at91sam9260ek.c       | 19 +---------
>  board/atmel/at91sam9263ek/at91sam9263ek.c       | 19 ++--------
>  board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c | 19 +---------
>  board/bluewater/snapper9260/snapper9260.c       | 16 +--------
>  board/calao/sbc35_a9g20/sbc35_a9g20.c           | 19 +---------
>  board/eukrea/cpu9260/cpu9260.c                  | 18 +---------
>  board/taskit/stamp9g20/stamp9g20.c              | 31 +---------------
>  spl/Makefile                                    |  4 ---
>  14 files changed, 66 insertions(+), 170 deletions(-)
>  create mode 100644 arch/arm/cpu/at91-common/phy.c
> 
> diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
> index fd0da53..886347d 100644
> --- a/arch/arm/cpu/Makefile
> +++ b/arch/arm/cpu/Makefile
> @@ -1,2 +1,3 @@
>  obj-$(CONFIG_TEGRA) += $(SOC)-common/
>  obj-$(CONFIG_TEGRA) += tegra-common/
> +obj-$(CONFIG_AT91FAMILY) += at91-common/
> diff --git a/arch/arm/cpu/at91-common/Makefile b/arch/arm/cpu/at91-common/Makefile
> index 040b956..255c7b9 100644
> --- a/arch/arm/cpu/at91-common/Makefile
> +++ b/arch/arm/cpu/at91-common/Makefile
> @@ -8,5 +8,10 @@
>  # SPDX-License-Identifier:	GPL-2.0+
>  #
>  
> +obj-$(CONFIG_AT91SAM9260) += phy.o
> +obj-$(CONFIG_AT91SAM9G20) += phy.o
> +obj-$(CONFIG_AT91SAM9263) += phy.o
> +obj-$(CONFIG_AT91SAM9XE) += phy.o
> +obj-$(CONFIG_AT91SAM9M10G45) += phy.o

How about defining some CONFIG_AT91_WANTS_PHY_RESET or
CONFIG_AT91_WANTS_COMMON_PHY?

>  obj-$(CONFIG_SPL_BUILD) += mpddrc.o
>  obj-$(CONFIG_SPL_BUILD) += spl.o
> diff --git a/arch/arm/cpu/at91-common/phy.c b/arch/arm/cpu/at91-common/phy.c
> new file mode 100644
> index 0000000..4706635
> --- /dev/null
> +++ b/arch/arm/cpu/at91-common/phy.c
> @@ -0,0 +1,48 @@
> +/*
> + * (C) Copyright 2007-2008
> + * Stelian Pop <stelian@popies.net>
> + * Lead Tech Design <www.leadtechdesign.com>
> + *
> + * Copyright (C) 2013 DENX Software Engineering, hs@denx.de
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <asm/io.h>
> +#include <asm/sizes.h>
> +#include <asm/arch/at91_pmc.h>
> +#include <asm/arch/at91_rstc.h>
> +#include <watchdog.h>
> +
> +void at91_phy_reset(void)
> +{
> +	unsigned long erstl;
> +	unsigned long start = get_timer(0);
> +	unsigned long timeout = 1000; /* 1000ms */

I'd constify timeout, it could give a hint to the compiler and it
doesn't hurt here.

> +	at91_rstc_t *rstc = (at91_rstc_t *)ATMEL_BASE_RSTC;
> +
> +	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
> +
> +	/* Need to reset PHY -> 500ms reset */

As there where discussion about this trick here could you please add
some comments:

---8<---
Reset PHY by pulling the NRST line for 500ms to low. To do so disable
user reset for low level on NRST pin and poll the NRST level in reset
status register.
--->8---

> +	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0x0D) |
> +		AT91_RSTC_MR_URSTEN, &rstc->mr);
> +
> +	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
> +
> +	/* Wait for end of hardware reset */
> +	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) {
> +		/* avoid shutdown by watchdog */
> +		WATCHDOG_RESET();
> +		mdelay(10);
> +
> +		/* timeout for not getting stuck in an endless loop */
> +		if (get_timer(start) >= timeout) {
> +			puts("*** ERROR: Timeout waiting for PHY reset!\n");
> +			break;
> +		}
> +	};
> +
> +	/* Restore NRST value */
> +	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN, &rstc->mr);
> +}
> diff --git a/arch/arm/include/asm/arch-at91/at91_common.h b/arch/arm/include/asm/arch-at91/at91_common.h
> index 3ca4d5b..59e2f43 100644
> --- a/arch/arm/include/asm/arch-at91/at91_common.h
> +++ b/arch/arm/include/asm/arch-at91/at91_common.h
> @@ -26,5 +26,6 @@ void at91_plla_init(u32 pllar);
>  void at91_mck_init(u32 mckr);
>  void at91_pmc_init(void);
>  void mem_init(void);
> +void at91_phy_reset(void);
>  
>  #endif /* AT91_COMMON_H */

<snip>

> diff --git a/board/taskit/stamp9g20/stamp9g20.c b/board/taskit/stamp9g20/stamp9g20.c
> index 704a63b..27cdf77 100644
> --- a/board/taskit/stamp9g20/stamp9g20.c
> +++ b/board/taskit/stamp9g20/stamp9g20.c
> @@ -19,7 +19,6 @@
>  #include <asm/arch/at91sam9_smc.h>
>  #include <asm/arch/at91_common.h>
>  #include <asm/arch/at91_pmc.h>
> -#include <asm/arch/at91_rstc.h>
>  #include <asm/arch/gpio.h>
>  #include <watchdog.h>
>  
> @@ -67,8 +66,6 @@ static void stamp9G20_nand_hw_init(void)
>  static void stamp9G20_macb_hw_init(void)
>  {
>  	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
> -	struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
> -	unsigned long erstl;
>  
>  	/* Enable the PHY Chip via PA26 on the Stamp 2 Adaptor */
>  	at91_set_gpio_output(AT91_PIN_PA26, 0);
> @@ -91,33 +88,7 @@ static void stamp9G20_macb_hw_init(void)
>  		pin_to_mask(AT91_PIN_PA28),
>  		&pioa->pudr);
>  
> -	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
> -
> -	/* Need to reset PHY -> 500ms reset */
> -	writel(AT91_RSTC_KEY | (AT91_RSTC_MR_ERSTL(13) &
> -				~AT91_RSTC_MR_URSTEN), &rstc->mr);
> -	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
> -
> -	/* Wait for end of hardware reset */
> -	unsigned long start = get_timer(0);
> -	unsigned long timeout = 1000; /* 1000ms */
> -
> -	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) {
> -
> -		/* avoid shutdown by watchdog */
> -		WATCHDOG_RESET();
> -		mdelay(10);
> -
> -		/* timeout for not getting stuck in an endless loop */
> -		if (get_timer(start) >= timeout) {
> -			puts("*** ERROR: Timeout waiting for PHY reset!\n");
> -			break;

Your code looks like this one, you should add Markus Hubig to your
Copyright list.

> -		};
> -	};
> -
> -	/* Restore NRST value */
> -	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
> -		&rstc->mr);
> +	at91_phy_reset();
>  
>  	/* Re-enable pull-up */
>  	writel(pin_to_mask(AT91_PIN_PA14) |
> diff --git a/spl/Makefile b/spl/Makefile
> index 736c6ca..cbd3d27 100644
> --- a/spl/Makefile
> +++ b/spl/Makefile
> @@ -111,10 +111,6 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
>  LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
>  endif
>  
> -ifeq ($(SOC),at91)
> -LIBS-y += arch/$(ARCH)/cpu/at91-common/libat91-common.o
> -endif
> -

That should not be removed here.

Looks good to me. Hopefully some board maintainers send their tested-by ...

Best regards

Andreas Bießmann
Heiko Schocher Nov. 12, 2013, 1:50 p.m. UTC | #2
Hello Andreas,

Am 12.11.2013 13:56, schrieb Andreas Bießmann:
> Hello Heiko,
>
> On 11/12/2013 11:21 AM, Heiko Schocher wrote:
>> add common phy reset code into a common function.
>>
>> Signed-off-by: Heiko Schocher<hs@denx.de>
>> Cc: Andreas Bießmann<andreas.devel@googlemail.com>
>> Cc: Bo Shen<voice.shen@atmel.com>
>> Cc: Jens Scharsig<esw@bus-elektronik.de>
>> Cc: Sergey Lapin<slapin@ossfans.org>
>> Cc: Stelian Pop<stelian@popies.net>
>> Cc: Albin Tonnerre<albin.tonnerre@free-electrons.com>
>> Cc: Eric Benard<eric@eukrea.com>
>> Cc: Markus Hubig<mhubig@imko.de>
>>
>> ---
>> Patch based on the spl patchset from Bo Shen (as I want to
>> collect this function in at91-common directory), see:
>> http://lists.denx.de/pipermail/u-boot/2013-November/166272.html
>> (reworked this against newest Kconfig Makefile changes ...
>>   @Bo: Do you plan an update for this patchset for the Kconfig changes?
>
> @Bo: I'll review the patches also these days.

Perfect!

>> Maybe my change in arch/arm/cpu/at91-common/Makefile
>> could be done better... Do we have a common define for
>> all this variants?
>
> I think not, but how about defining a new one?

I am fine with this too...

>> ---
>>   arch/arm/cpu/Makefile                           |  1 +
>>   arch/arm/cpu/at91-common/Makefile               |  5 +++
>>   arch/arm/cpu/at91-common/phy.c                  | 48 +++++++++++++++++++++++++
>>   arch/arm/include/asm/arch-at91/at91_common.h    |  1 +
>>   board/BuS/vl_ma2sc/vl_ma2sc.c                   | 18 ++--------
>>   board/afeb9260/afeb9260.c                       | 18 +---------
>>   board/atmel/at91sam9260ek/at91sam9260ek.c       | 19 +---------
>>   board/atmel/at91sam9263ek/at91sam9263ek.c       | 19 ++--------
>>   board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c | 19 +---------
>>   board/bluewater/snapper9260/snapper9260.c       | 16 +--------
>>   board/calao/sbc35_a9g20/sbc35_a9g20.c           | 19 +---------
>>   board/eukrea/cpu9260/cpu9260.c                  | 18 +---------
>>   board/taskit/stamp9g20/stamp9g20.c              | 31 +---------------
>>   spl/Makefile                                    |  4 ---
>>   14 files changed, 66 insertions(+), 170 deletions(-)
>>   create mode 100644 arch/arm/cpu/at91-common/phy.c
>>
>> diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
>> index fd0da53..886347d 100644
>> --- a/arch/arm/cpu/Makefile
>> +++ b/arch/arm/cpu/Makefile
>> @@ -1,2 +1,3 @@
>>   obj-$(CONFIG_TEGRA) += $(SOC)-common/
>>   obj-$(CONFIG_TEGRA) += tegra-common/
>> +obj-$(CONFIG_AT91FAMILY) += at91-common/
>> diff --git a/arch/arm/cpu/at91-common/Makefile b/arch/arm/cpu/at91-common/Makefile
>> index 040b956..255c7b9 100644
>> --- a/arch/arm/cpu/at91-common/Makefile
>> +++ b/arch/arm/cpu/at91-common/Makefile
>> @@ -8,5 +8,10 @@
>>   # SPDX-License-Identifier:	GPL-2.0+
>>   #
>>
>> +obj-$(CONFIG_AT91SAM9260) += phy.o
>> +obj-$(CONFIG_AT91SAM9G20) += phy.o
>> +obj-$(CONFIG_AT91SAM9263) += phy.o
>> +obj-$(CONFIG_AT91SAM9XE) += phy.o
>> +obj-$(CONFIG_AT91SAM9M10G45) += phy.o
>
> How about defining some CONFIG_AT91_WANTS_PHY_RESET or
> CONFIG_AT91_WANTS_COMMON_PHY?

I vote for CONFIG_AT91_WANTS_COMMON_PHY

>>   obj-$(CONFIG_SPL_BUILD) += mpddrc.o
>>   obj-$(CONFIG_SPL_BUILD) += spl.o
>> diff --git a/arch/arm/cpu/at91-common/phy.c b/arch/arm/cpu/at91-common/phy.c
>> new file mode 100644
>> index 0000000..4706635
>> --- /dev/null
>> +++ b/arch/arm/cpu/at91-common/phy.c
>> @@ -0,0 +1,48 @@
>> +/*
>> + * (C) Copyright 2007-2008
>> + * Stelian Pop<stelian@popies.net>
>> + * Lead Tech Design<www.leadtechdesign.com>
>> + *
>> + * Copyright (C) 2013 DENX Software Engineering, hs@denx.de
>> + *
>> + * SPDX-License-Identifier:	GPL-2.0+
>> + */
>> +
>> +#include<common.h>
>> +#include<asm/io.h>
>> +#include<asm/sizes.h>
>> +#include<asm/arch/at91_pmc.h>
>> +#include<asm/arch/at91_rstc.h>
>> +#include<watchdog.h>
>> +
>> +void at91_phy_reset(void)
>> +{
>> +	unsigned long erstl;
>> +	unsigned long start = get_timer(0);
>> +	unsigned long timeout = 1000; /* 1000ms */
>
> I'd constify timeout, it could give a hint to the compiler and it
> doesn't hurt here.

Ok.

>> +	at91_rstc_t *rstc = (at91_rstc_t *)ATMEL_BASE_RSTC;
>> +
>> +	erstl = readl(&rstc->mr)&  AT91_RSTC_MR_ERSTL_MASK;
>> +
>> +	/* Need to reset PHY ->  500ms reset */
>
> As there where discussion about this trick here could you please add
> some comments:

Ok.

> ---8<---
> Reset PHY by pulling the NRST line for 500ms to low. To do so disable
> user reset for low level on NRST pin and poll the NRST level in reset
> status register.
> --->8---
>
>> +	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0x0D) |
>> +		AT91_RSTC_MR_URSTEN,&rstc->mr);
>> +
>> +	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST,&rstc->cr);
>> +
>> +	/* Wait for end of hardware reset */
>> +	while (!(readl(&rstc->sr)&  AT91_RSTC_SR_NRSTL)) {
>> +		/* avoid shutdown by watchdog */
>> +		WATCHDOG_RESET();
>> +		mdelay(10);
>> +
>> +		/* timeout for not getting stuck in an endless loop */
>> +		if (get_timer(start)>= timeout) {
>> +			puts("*** ERROR: Timeout waiting for PHY reset!\n");
>> +			break;
>> +		}
>> +	};
>> +
>> +	/* Restore NRST value */
>> +	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,&rstc->mr);
>> +}
>> diff --git a/arch/arm/include/asm/arch-at91/at91_common.h b/arch/arm/include/asm/arch-at91/at91_common.h
>> index 3ca4d5b..59e2f43 100644
>> --- a/arch/arm/include/asm/arch-at91/at91_common.h
>> +++ b/arch/arm/include/asm/arch-at91/at91_common.h
>> @@ -26,5 +26,6 @@ void at91_plla_init(u32 pllar);
>>   void at91_mck_init(u32 mckr);
>>   void at91_pmc_init(void);
>>   void mem_init(void);
>> +void at91_phy_reset(void);
>>
>>   #endif /* AT91_COMMON_H */
>
> <snip>
>
>> diff --git a/board/taskit/stamp9g20/stamp9g20.c b/board/taskit/stamp9g20/stamp9g20.c
>> index 704a63b..27cdf77 100644
>> --- a/board/taskit/stamp9g20/stamp9g20.c
>> +++ b/board/taskit/stamp9g20/stamp9g20.c
>> @@ -19,7 +19,6 @@
>>   #include<asm/arch/at91sam9_smc.h>
>>   #include<asm/arch/at91_common.h>
>>   #include<asm/arch/at91_pmc.h>
>> -#include<asm/arch/at91_rstc.h>
>>   #include<asm/arch/gpio.h>
>>   #include<watchdog.h>
>>
>> @@ -67,8 +66,6 @@ static void stamp9G20_nand_hw_init(void)
>>   static void stamp9G20_macb_hw_init(void)
>>   {
>>   	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
>> -	struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
>> -	unsigned long erstl;
>>
>>   	/* Enable the PHY Chip via PA26 on the Stamp 2 Adaptor */
>>   	at91_set_gpio_output(AT91_PIN_PA26, 0);
>> @@ -91,33 +88,7 @@ static void stamp9G20_macb_hw_init(void)
>>   		pin_to_mask(AT91_PIN_PA28),
>>   		&pioa->pudr);
>>
>> -	erstl = readl(&rstc->mr)&  AT91_RSTC_MR_ERSTL_MASK;
>> -
>> -	/* Need to reset PHY ->  500ms reset */
>> -	writel(AT91_RSTC_KEY | (AT91_RSTC_MR_ERSTL(13)&
>> -				~AT91_RSTC_MR_URSTEN),&rstc->mr);
>> -	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST,&rstc->cr);
>> -
>> -	/* Wait for end of hardware reset */
>> -	unsigned long start = get_timer(0);
>> -	unsigned long timeout = 1000; /* 1000ms */
>> -
>> -	while (!(readl(&rstc->sr)&  AT91_RSTC_SR_NRSTL)) {
>> -
>> -		/* avoid shutdown by watchdog */
>> -		WATCHDOG_RESET();
>> -		mdelay(10);
>> -
>> -		/* timeout for not getting stuck in an endless loop */
>> -		if (get_timer(start)>= timeout) {
>> -			puts("*** ERROR: Timeout waiting for PHY reset!\n");
>> -			break;
>
> Your code looks like this one, you should add Markus Hubig to your
> Copyright list.

Ok.

>> -		};
>> -	};
>> -
>> -	/* Restore NRST value */
>> -	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
>> -		&rstc->mr);
>> +	at91_phy_reset();
>>
>>   	/* Re-enable pull-up */
>>   	writel(pin_to_mask(AT91_PIN_PA14) |
>> diff --git a/spl/Makefile b/spl/Makefile
>> index 736c6ca..cbd3d27 100644
>> --- a/spl/Makefile
>> +++ b/spl/Makefile
>> @@ -111,10 +111,6 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
>>   LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
>>   endif
>>
>> -ifeq ($(SOC),at91)
>> -LIBS-y += arch/$(ARCH)/cpu/at91-common/libat91-common.o
>> -endif
>> -
>
> That should not be removed here.

See my change in arch/arm/cpu/Makefile

With this change, this in the spl/Makefile is not needed ...
I did this, because arch/arm/cpu/at91-common/ contains not only
spl code. But maybe this should be changed in the spl patchset
from bo?

> Looks good to me. Hopefully some board maintainers send their tested-by ...

I am too...

bye,
Heiko
Bo Shen Nov. 13, 2013, 1:35 a.m. UTC | #3
Hi Heiko,

On 11/12/2013 09:50 PM, Heiko Schocher wrote:
> Hello Andreas,
>
> Am 12.11.2013 13:56, schrieb Andreas Bießmann:
>> Hello Heiko,
>>
>> On 11/12/2013 11:21 AM, Heiko Schocher wrote:
>>> add common phy reset code into a common function.
>>>
>>> Signed-off-by: Heiko Schocher<hs@denx.de>
>>> Cc: Andreas Bießmann<andreas.devel@googlemail.com>
>>> Cc: Bo Shen<voice.shen@atmel.com>
>>> Cc: Jens Scharsig<esw@bus-elektronik.de>
>>> Cc: Sergey Lapin<slapin@ossfans.org>
>>> Cc: Stelian Pop<stelian@popies.net>
>>> Cc: Albin Tonnerre<albin.tonnerre@free-electrons.com>
>>> Cc: Eric Benard<eric@eukrea.com>
>>> Cc: Markus Hubig<mhubig@imko.de>
>>>
>>> ---
>>> Patch based on the spl patchset from Bo Shen (as I want to
>>> collect this function in at91-common directory), see:
>>> http://lists.denx.de/pipermail/u-boot/2013-November/166272.html
>>> (reworked this against newest Kconfig Makefile changes ...
>>>   @Bo: Do you plan an update for this patchset for the Kconfig changes?
>>
>> @Bo: I'll review the patches also these days.

After Andreas finish reviewing the code, I will update this patchset for 
the Kconfig changes if needed.

> Perfect!
>
>>> Maybe my change in arch/arm/cpu/at91-common/Makefile
>>> could be done better... Do we have a common define for
>>> all this variants?
>>
>> I think not, but how about defining a new one?
>
> I am fine with this too...
>
>>> ---
>>>   arch/arm/cpu/Makefile                           |  1 +
>>>   arch/arm/cpu/at91-common/Makefile               |  5 +++
>>>   arch/arm/cpu/at91-common/phy.c                  | 48
>>> +++++++++++++++++++++++++
>>>   arch/arm/include/asm/arch-at91/at91_common.h    |  1 +
>>>   board/BuS/vl_ma2sc/vl_ma2sc.c                   | 18 ++--------
>>>   board/afeb9260/afeb9260.c                       | 18 +---------
>>>   board/atmel/at91sam9260ek/at91sam9260ek.c       | 19 +---------
>>>   board/atmel/at91sam9263ek/at91sam9263ek.c       | 19 ++--------
>>>   board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c | 19 +---------
>>>   board/bluewater/snapper9260/snapper9260.c       | 16 +--------
>>>   board/calao/sbc35_a9g20/sbc35_a9g20.c           | 19 +---------
>>>   board/eukrea/cpu9260/cpu9260.c                  | 18 +---------
>>>   board/taskit/stamp9g20/stamp9g20.c              | 31 +---------------
>>>   spl/Makefile                                    |  4 ---
>>>   14 files changed, 66 insertions(+), 170 deletions(-)
>>>   create mode 100644 arch/arm/cpu/at91-common/phy.c
>>>
>>> diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
>>> index fd0da53..886347d 100644
>>> --- a/arch/arm/cpu/Makefile
>>> +++ b/arch/arm/cpu/Makefile
>>> @@ -1,2 +1,3 @@
>>>   obj-$(CONFIG_TEGRA) += $(SOC)-common/
>>>   obj-$(CONFIG_TEGRA) += tegra-common/
>>> +obj-$(CONFIG_AT91FAMILY) += at91-common/

<snip>

>>> diff --git a/spl/Makefile b/spl/Makefile
>>> index 736c6ca..cbd3d27 100644
>>> --- a/spl/Makefile
>>> +++ b/spl/Makefile
>>> @@ -111,10 +111,6 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
>>>   LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
>>>   endif
>>>
>>> -ifeq ($(SOC),at91)
>>> -LIBS-y += arch/$(ARCH)/cpu/at91-common/libat91-common.o
>>> -endif
>>> -
>>
>> That should not be removed here.
>
> See my change in arch/arm/cpu/Makefile
>
> With this change, this in the spl/Makefile is not needed ...
> I did this, because arch/arm/cpu/at91-common/ contains not only
> spl code. But maybe this should be changed in the spl patchset
> from bo?

I am not fully got your means. what should I change?

>> Looks good to me. Hopefully some board maintainers send their
>> tested-by ...
>
> I am too...
>
> bye,
> Heiko

Best Regards,
Bo Shen
Heiko Schocher Nov. 13, 2013, 5:04 a.m. UTC | #4
Hello Bo,

Am 13.11.2013 02:35, schrieb Bo Shen:
> Hi Heiko,
>
> On 11/12/2013 09:50 PM, Heiko Schocher wrote:
>> Hello Andreas,
>>
>> Am 12.11.2013 13:56, schrieb Andreas Bießmann:
>>> Hello Heiko,
>>>
>>> On 11/12/2013 11:21 AM, Heiko Schocher wrote:
>>>> add common phy reset code into a common function.
>>>>
>>>> Signed-off-by: Heiko Schocher<hs@denx.de>
>>>> Cc: Andreas Bießmann<andreas.devel@googlemail.com>
>>>> Cc: Bo Shen<voice.shen@atmel.com>
>>>> Cc: Jens Scharsig<esw@bus-elektronik.de>
>>>> Cc: Sergey Lapin<slapin@ossfans.org>
>>>> Cc: Stelian Pop<stelian@popies.net>
>>>> Cc: Albin Tonnerre<albin.tonnerre@free-electrons.com>
>>>> Cc: Eric Benard<eric@eukrea.com>
>>>> Cc: Markus Hubig<mhubig@imko.de>
>>>>
>>>> ---
>>>> Patch based on the spl patchset from Bo Shen (as I want to
>>>> collect this function in at91-common directory), see:
>>>> http://lists.denx.de/pipermail/u-boot/2013-November/166272.html
>>>> (reworked this against newest Kconfig Makefile changes ...
>>>> @Bo: Do you plan an update for this patchset for the Kconfig changes?
>>>
>>> @Bo: I'll review the patches also these days.
>
> After Andreas finish reviewing the code, I will update this patchset for the Kconfig changes if needed.

Great, so I wait for your update, before I sent my updated
patch, thanks!

>> Perfect!
>>
>>>> Maybe my change in arch/arm/cpu/at91-common/Makefile
>>>> could be done better... Do we have a common define for
>>>> all this variants?
>>>
>>> I think not, but how about defining a new one?
>>
>> I am fine with this too...
>>
>>>> ---
>>>> arch/arm/cpu/Makefile | 1 +
>>>> arch/arm/cpu/at91-common/Makefile | 5 +++
>>>> arch/arm/cpu/at91-common/phy.c | 48
>>>> +++++++++++++++++++++++++
>>>> arch/arm/include/asm/arch-at91/at91_common.h | 1 +
>>>> board/BuS/vl_ma2sc/vl_ma2sc.c | 18 ++--------
>>>> board/afeb9260/afeb9260.c | 18 +---------
>>>> board/atmel/at91sam9260ek/at91sam9260ek.c | 19 +---------
>>>> board/atmel/at91sam9263ek/at91sam9263ek.c | 19 ++--------
>>>> board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c | 19 +---------
>>>> board/bluewater/snapper9260/snapper9260.c | 16 +--------
>>>> board/calao/sbc35_a9g20/sbc35_a9g20.c | 19 +---------
>>>> board/eukrea/cpu9260/cpu9260.c | 18 +---------
>>>> board/taskit/stamp9g20/stamp9g20.c | 31 +---------------
>>>> spl/Makefile | 4 ---
>>>> 14 files changed, 66 insertions(+), 170 deletions(-)
>>>> create mode 100644 arch/arm/cpu/at91-common/phy.c
>>>>
>>>> diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
>>>> index fd0da53..886347d 100644
>>>> --- a/arch/arm/cpu/Makefile
>>>> +++ b/arch/arm/cpu/Makefile
>>>> @@ -1,2 +1,3 @@
>>>> obj-$(CONFIG_TEGRA) += $(SOC)-common/
>>>> obj-$(CONFIG_TEGRA) += tegra-common/
>>>> +obj-$(CONFIG_AT91FAMILY) += at91-common/
>
> <snip>
>
>>>> diff --git a/spl/Makefile b/spl/Makefile
>>>> index 736c6ca..cbd3d27 100644
>>>> --- a/spl/Makefile
>>>> +++ b/spl/Makefile
>>>> @@ -111,10 +111,6 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
>>>> LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
>>>> endif
>>>>
>>>> -ifeq ($(SOC),at91)
>>>> -LIBS-y += arch/$(ARCH)/cpu/at91-common/libat91-common.o
>>>> -endif
>>>> -
>>>
>>> That should not be removed here.
>>
>> See my change in arch/arm/cpu/Makefile
>>
>> With this change, this in the spl/Makefile is not needed ...
>> I did this, because arch/arm/cpu/at91-common/ contains not only
>> spl code. But maybe this should be changed in the spl patchset
>> from bo?
>
> I am not fully got your means. what should I change?

Could you add to your patchset the following change?

 >>>> diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
 >>>> index fd0da53..886347d 100644
 >>>> --- a/arch/arm/cpu/Makefile
 >>>> +++ b/arch/arm/cpu/Makefile
 >>>> @@ -1,2 +1,3 @@
 >>>> obj-$(CONFIG_TEGRA) += $(SOC)-common/
 >>>> obj-$(CONFIG_TEGRA) += tegra-common/
 >>>> +obj-$(CONFIG_AT91FAMILY) += at91-common/
 >>>> diff --git a/spl/Makefile b/spl/Makefile
 >>>> index 736c6ca..cbd3d27 100644
 >>>> --- a/spl/Makefile
 >>>> +++ b/spl/Makefile
 >>>> @@ -111,10 +111,6 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
 >>>> LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
 >>>> endif
 >>>>
 >>>> -ifeq ($(SOC),at91)
 >>>> -LIBS-y += arch/$(ARCH)/cpu/at91-common/libat91-common.o
 >>>> -endif
 >>>> -

bye,
Heiko
Bo Shen Nov. 13, 2013, 8:15 a.m. UTC | #5
Hi Heiko,

On 11/13/2013 01:04 PM, Heiko Schocher wrote:
> Hello Bo,
>
> Am 13.11.2013 02:35, schrieb Bo Shen:
>> Hi Heiko,
>>
>> On 11/12/2013 09:50 PM, Heiko Schocher wrote:
>>> Hello Andreas,
>>>
>>> Am 12.11.2013 13:56, schrieb Andreas Bießmann:
>>>> Hello Heiko,
>>>>
>>>> On 11/12/2013 11:21 AM, Heiko Schocher wrote:
>>>>> add common phy reset code into a common function.
>>>>>
>>>>> Signed-off-by: Heiko Schocher<hs@denx.de>
>>>>> Cc: Andreas Bießmann<andreas.devel@googlemail.com>
>>>>> Cc: Bo Shen<voice.shen@atmel.com>
>>>>> Cc: Jens Scharsig<esw@bus-elektronik.de>
>>>>> Cc: Sergey Lapin<slapin@ossfans.org>
>>>>> Cc: Stelian Pop<stelian@popies.net>
>>>>> Cc: Albin Tonnerre<albin.tonnerre@free-electrons.com>
>>>>> Cc: Eric Benard<eric@eukrea.com>
>>>>> Cc: Markus Hubig<mhubig@imko.de>
>>>>>
>>>>> ---
>>>>> Patch based on the spl patchset from Bo Shen (as I want to
>>>>> collect this function in at91-common directory), see:
>>>>> http://lists.denx.de/pipermail/u-boot/2013-November/166272.html
>>>>> (reworked this against newest Kconfig Makefile changes ...
>>>>> @Bo: Do you plan an update for this patchset for the Kconfig changes?
>>>>
>>>> @Bo: I'll review the patches also these days.
>>
>> After Andreas finish reviewing the code, I will update this patchset
>> for the Kconfig changes if needed.
>
> Great, so I wait for your update, before I sent my updated
> patch, thanks!
>
>>> Perfect!
>>>
>>>>> Maybe my change in arch/arm/cpu/at91-common/Makefile
>>>>> could be done better... Do we have a common define for
>>>>> all this variants?
>>>>
>>>> I think not, but how about defining a new one?
>>>
>>> I am fine with this too...
>>>
>>>>> ---
>>>>> arch/arm/cpu/Makefile | 1 +
>>>>> arch/arm/cpu/at91-common/Makefile | 5 +++
>>>>> arch/arm/cpu/at91-common/phy.c | 48
>>>>> +++++++++++++++++++++++++
>>>>> arch/arm/include/asm/arch-at91/at91_common.h | 1 +
>>>>> board/BuS/vl_ma2sc/vl_ma2sc.c | 18 ++--------
>>>>> board/afeb9260/afeb9260.c | 18 +---------
>>>>> board/atmel/at91sam9260ek/at91sam9260ek.c | 19 +---------
>>>>> board/atmel/at91sam9263ek/at91sam9263ek.c | 19 ++--------
>>>>> board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c | 19 +---------
>>>>> board/bluewater/snapper9260/snapper9260.c | 16 +--------
>>>>> board/calao/sbc35_a9g20/sbc35_a9g20.c | 19 +---------
>>>>> board/eukrea/cpu9260/cpu9260.c | 18 +---------
>>>>> board/taskit/stamp9g20/stamp9g20.c | 31 +---------------
>>>>> spl/Makefile | 4 ---
>>>>> 14 files changed, 66 insertions(+), 170 deletions(-)
>>>>> create mode 100644 arch/arm/cpu/at91-common/phy.c
>>>>>
>>>>> diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
>>>>> index fd0da53..886347d 100644
>>>>> --- a/arch/arm/cpu/Makefile
>>>>> +++ b/arch/arm/cpu/Makefile
>>>>> @@ -1,2 +1,3 @@
>>>>> obj-$(CONFIG_TEGRA) += $(SOC)-common/
>>>>> obj-$(CONFIG_TEGRA) += tegra-common/
>>>>> +obj-$(CONFIG_AT91FAMILY) += at91-common/
>>
>> <snip>
>>
>>>>> diff --git a/spl/Makefile b/spl/Makefile
>>>>> index 736c6ca..cbd3d27 100644
>>>>> --- a/spl/Makefile
>>>>> +++ b/spl/Makefile
>>>>> @@ -111,10 +111,6 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
>>>>> LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
>>>>> endif
>>>>>
>>>>> -ifeq ($(SOC),at91)
>>>>> -LIBS-y += arch/$(ARCH)/cpu/at91-common/libat91-common.o
>>>>> -endif
>>>>> -
>>>>
>>>> That should not be removed here.
>>>
>>> See my change in arch/arm/cpu/Makefile
>>>
>>> With this change, this in the spl/Makefile is not needed ...
>>> I did this, because arch/arm/cpu/at91-common/ contains not only
>>> spl code. But maybe this should be changed in the spl patchset
>>> from bo?
>>
>> I am not fully got your means. what should I change?
>
> Could you add to your patchset the following change?

OK. I will add this after reviewing.
Thanks.

>  >>>> diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
>  >>>> index fd0da53..886347d 100644
>  >>>> --- a/arch/arm/cpu/Makefile
>  >>>> +++ b/arch/arm/cpu/Makefile
>  >>>> @@ -1,2 +1,3 @@
>  >>>> obj-$(CONFIG_TEGRA) += $(SOC)-common/
>  >>>> obj-$(CONFIG_TEGRA) += tegra-common/
>  >>>> +obj-$(CONFIG_AT91FAMILY) += at91-common/
>  >>>> diff --git a/spl/Makefile b/spl/Makefile
>  >>>> index 736c6ca..cbd3d27 100644
>  >>>> --- a/spl/Makefile
>  >>>> +++ b/spl/Makefile
>  >>>> @@ -111,10 +111,6 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
>  >>>> LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
>  >>>> endif
>  >>>>
>  >>>> -ifeq ($(SOC),at91)
>  >>>> -LIBS-y += arch/$(ARCH)/cpu/at91-common/libat91-common.o
>  >>>> -endif
>  >>>> -
>
> bye,
> Heiko

Best Regards,
Bo Shen
diff mbox

Patch

diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
index fd0da53..886347d 100644
--- a/arch/arm/cpu/Makefile
+++ b/arch/arm/cpu/Makefile
@@ -1,2 +1,3 @@ 
 obj-$(CONFIG_TEGRA) += $(SOC)-common/
 obj-$(CONFIG_TEGRA) += tegra-common/
+obj-$(CONFIG_AT91FAMILY) += at91-common/
diff --git a/arch/arm/cpu/at91-common/Makefile b/arch/arm/cpu/at91-common/Makefile
index 040b956..255c7b9 100644
--- a/arch/arm/cpu/at91-common/Makefile
+++ b/arch/arm/cpu/at91-common/Makefile
@@ -8,5 +8,10 @@ 
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_AT91SAM9260) += phy.o
+obj-$(CONFIG_AT91SAM9G20) += phy.o
+obj-$(CONFIG_AT91SAM9263) += phy.o
+obj-$(CONFIG_AT91SAM9XE) += phy.o
+obj-$(CONFIG_AT91SAM9M10G45) += phy.o
 obj-$(CONFIG_SPL_BUILD) += mpddrc.o
 obj-$(CONFIG_SPL_BUILD) += spl.o
diff --git a/arch/arm/cpu/at91-common/phy.c b/arch/arm/cpu/at91-common/phy.c
new file mode 100644
index 0000000..4706635
--- /dev/null
+++ b/arch/arm/cpu/at91-common/phy.c
@@ -0,0 +1,48 @@ 
+/*
+ * (C) Copyright 2007-2008
+ * Stelian Pop <stelian@popies.net>
+ * Lead Tech Design <www.leadtechdesign.com>
+ *
+ * Copyright (C) 2013 DENX Software Engineering, hs@denx.de
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/sizes.h>
+#include <asm/arch/at91_pmc.h>
+#include <asm/arch/at91_rstc.h>
+#include <watchdog.h>
+
+void at91_phy_reset(void)
+{
+	unsigned long erstl;
+	unsigned long start = get_timer(0);
+	unsigned long timeout = 1000; /* 1000ms */
+	at91_rstc_t *rstc = (at91_rstc_t *)ATMEL_BASE_RSTC;
+
+	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
+
+	/* Need to reset PHY -> 500ms reset */
+	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0x0D) |
+		AT91_RSTC_MR_URSTEN, &rstc->mr);
+
+	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
+
+	/* Wait for end of hardware reset */
+	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) {
+		/* avoid shutdown by watchdog */
+		WATCHDOG_RESET();
+		mdelay(10);
+
+		/* timeout for not getting stuck in an endless loop */
+		if (get_timer(start) >= timeout) {
+			puts("*** ERROR: Timeout waiting for PHY reset!\n");
+			break;
+		}
+	};
+
+	/* Restore NRST value */
+	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN, &rstc->mr);
+}
diff --git a/arch/arm/include/asm/arch-at91/at91_common.h b/arch/arm/include/asm/arch-at91/at91_common.h
index 3ca4d5b..59e2f43 100644
--- a/arch/arm/include/asm/arch-at91/at91_common.h
+++ b/arch/arm/include/asm/arch-at91/at91_common.h
@@ -26,5 +26,6 @@  void at91_plla_init(u32 pllar);
 void at91_mck_init(u32 mckr);
 void at91_pmc_init(void);
 void mem_init(void);
+void at91_phy_reset(void);
 
 #endif /* AT91_COMMON_H */
diff --git a/board/BuS/vl_ma2sc/vl_ma2sc.c b/board/BuS/vl_ma2sc/vl_ma2sc.c
index e2ae6fd..412ff3b 100644
--- a/board/BuS/vl_ma2sc/vl_ma2sc.c
+++ b/board/BuS/vl_ma2sc/vl_ma2sc.c
@@ -16,7 +16,6 @@ 
 #include <asm/arch/at91sam9_smc.h>
 #include <asm/arch/at91_pmc.h>
 #include <asm/arch/at91_pio.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/at91sam9263.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/at91_common.h>
@@ -76,25 +75,12 @@  static void vl_ma2sc_nand_hw_init(void)
 #ifdef CONFIG_MACB
 static void vl_ma2sc_macb_hw_init(void)
 {
-	unsigned long	erstl;
 	at91_pmc_t	*pmc	= (at91_pmc_t *) ATMEL_BASE_PMC;
-	at91_rstc_t	*rstc	= (at91_rstc_t *) ATMEL_BASE_RSTC;
+
 	/* Enable clock */
 	writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
 
-	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-
-	/* Need to reset PHY -> 500ms reset */
-	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0x0D) |
-		AT91_RSTC_MR_URSTEN, &rstc->mr);
-
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-	/* Wait for end hardware reset */
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
-		;
-
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN, &rstc->mr);
+	at91_phy_reset();
 
 	at91_macb_hw_init();
 }
diff --git a/board/afeb9260/afeb9260.c b/board/afeb9260/afeb9260.c
index e1b1c10..ea9575d 100644
--- a/board/afeb9260/afeb9260.c
+++ b/board/afeb9260/afeb9260.c
@@ -13,7 +13,6 @@ 
 #include <asm/arch/at91sam9_smc.h>
 #include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
@@ -67,8 +66,6 @@  static void afeb9260_macb_hw_init(void)
 {
 	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
 	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
-	struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
-	unsigned long erstl;
 
 
 	/* Enable EMAC clock */
@@ -94,20 +91,7 @@  static void afeb9260_macb_hw_init(void)
 	       pin_to_mask(AT91_PIN_PA28),
 	       &pioa->pudr);
 
-	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-
-	/* Need to reset PHY -> 500ms reset */
-	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
-		AT91_RSTC_MR_URSTEN, &rstc->mr);
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-
-	/* Wait for end hardware reset */
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
-		;
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
-		&rstc->mr);
-
+	at91_phy_reset();
 
 	/* Re-enable pull-up */
 	writel(pin_to_mask(AT91_PIN_PA14) |
diff --git a/board/atmel/at91sam9260ek/at91sam9260ek.c b/board/atmel/at91sam9260ek/at91sam9260ek.c
index 263de49..7f14af1 100644
--- a/board/atmel/at91sam9260ek/at91sam9260ek.c
+++ b/board/atmel/at91sam9260ek/at91sam9260ek.c
@@ -12,7 +12,6 @@ 
 #include <asm/arch/at91sam9_smc.h>
 #include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
 #include <atmel_mci.h>
 
@@ -73,8 +72,6 @@  static void at91sam9260ek_macb_hw_init(void)
 {
 	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
 	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
-	struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
-	unsigned long erstl;
 
 	/* Enable EMAC clock */
 	writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
@@ -98,21 +95,7 @@  static void at91sam9260ek_macb_hw_init(void)
 		pin_to_mask(AT91_PIN_PA28),
 		&pioa->pudr);
 
-	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-
-	/* Need to reset PHY -> 500ms reset */
-	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
-		AT91_RSTC_MR_URSTEN, &rstc->mr);
-
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-
-	/* Wait for end hardware reset */
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
-		;
-
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
-		&rstc->mr);
+	at91_phy_reset();
 
 	/* Re-enable pull-up */
 	writel(pin_to_mask(AT91_PIN_PA14) |
diff --git a/board/atmel/at91sam9263ek/at91sam9263ek.c b/board/atmel/at91sam9263ek/at91sam9263ek.c
index 2e9246f..d42a173 100644
--- a/board/atmel/at91sam9263ek/at91sam9263ek.c
+++ b/board/atmel/at91sam9263ek/at91sam9263ek.c
@@ -12,7 +12,6 @@ 
 #include <asm/arch/at91sam9_smc.h>
 #include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/at91_matrix.h>
 #include <asm/arch/at91_pio.h>
 #include <asm/arch/clk.h>
@@ -82,10 +81,9 @@  static void at91sam9263ek_nand_hw_init(void)
 #ifdef CONFIG_MACB
 static void at91sam9263ek_macb_hw_init(void)
 {
-	unsigned long 	erstl;
 	at91_pmc_t	*pmc	= (at91_pmc_t *) ATMEL_BASE_PMC;
 	at91_pio_t	*pio	= (at91_pio_t *) ATMEL_BASE_PIO;
-	at91_rstc_t	*rstc	= (at91_rstc_t *) ATMEL_BASE_RSTC;
+
 	/* Enable clock */
 	writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
 
@@ -97,23 +95,10 @@  static void at91sam9263ek_macb_hw_init(void)
 	 *
 	 * PHY has internal pull-down
 	 */
-
 	writel(1 << 25, &pio->pioc.pudr);
 	writel((1 << 25) | (1 <<26), &pio->pioe.pudr);
 
-	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-
-	/* Need to reset PHY -> 500ms reset */
-	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0x0D) |
-		AT91_RSTC_MR_URSTEN, &rstc->mr);
-
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-	/* Wait for end hardware reset */
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
-		;
-
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN, &rstc->mr);
+	at91_phy_reset();
 
 	/* Re-enable pull-up */
 	writel(1 << 25, &pio->pioc.puer);
diff --git a/board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c b/board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c
index 6a071f6..b7e2efd 100644
--- a/board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c
+++ b/board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c
@@ -12,7 +12,6 @@ 
 #include <asm/arch/at91sam9_smc.h>
 #include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/clk.h>
 #include <lcd.h>
@@ -88,8 +87,6 @@  static void at91sam9m10g45ek_macb_hw_init(void)
 {
 	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
 	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
-	struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
-	unsigned long erstl;
 
 	/* Enable clock */
 	writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
@@ -107,21 +104,7 @@  static void at91sam9m10g45ek_macb_hw_init(void)
 	       pin_to_mask(AT91_PIN_PA13),
 	       &pioa->pudr);
 
-	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-
-	/* Need to reset PHY -> 500ms reset */
-	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
-		AT91_RSTC_MR_URSTEN, &rstc->mr);
-
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-
-	/* Wait for end hardware reset */
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
-		;
-
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
-		&rstc->mr);
+	at91_phy_reset();
 
 	/* Re-enable pull-up */
 	writel(pin_to_mask(AT91_PIN_PA15) |
diff --git a/board/bluewater/snapper9260/snapper9260.c b/board/bluewater/snapper9260/snapper9260.c
index 8a6919d..bfde129 100644
--- a/board/bluewater/snapper9260/snapper9260.c
+++ b/board/bluewater/snapper9260/snapper9260.c
@@ -14,7 +14,6 @@ 
 #include <asm/arch/at91sam9_smc.h>
 #include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
 #include <net.h>
 #include <netdev.h>
@@ -31,8 +30,6 @@  static void macb_hw_init(void)
 {
 	struct at91_pmc *pmc   = (struct at91_pmc  *)ATMEL_BASE_PMC;
 	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
-	struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
-	unsigned long erstl;
 
 	/* Enable clock */
 	writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
@@ -54,18 +51,7 @@  static void macb_hw_init(void)
 	/* Enable ethernet power */
 	pca953x_set_val(0x28, IO_EXP_ETH_POWER, 0);
 
-	/* Need to reset PHY -> 500ms reset */
-	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
-	       AT91_RSTC_MR_URSTEN, &rstc->mr);
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-
-	/* Wait for end hardware reset */
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
-		;
-
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN, &rstc->mr);
+	at91_phy_reset();
 
 	/* Bring the ethernet out of reset */
 	pca953x_set_val(0x28, IO_EXP_ETH_RESET, 1);
diff --git a/board/calao/sbc35_a9g20/sbc35_a9g20.c b/board/calao/sbc35_a9g20/sbc35_a9g20.c
index ecf261c..2074a93 100644
--- a/board/calao/sbc35_a9g20/sbc35_a9g20.c
+++ b/board/calao/sbc35_a9g20/sbc35_a9g20.c
@@ -15,7 +15,6 @@ 
 #include <asm/arch/at91sam9_smc.h>
 #include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
 
 #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
@@ -77,8 +76,6 @@  static void sbc35_a9g20_macb_hw_init(void)
 {
 	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
 	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
-	struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
-	unsigned long erstl;
 
 	/* Enable EMAC clock */
 	writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
@@ -102,21 +99,7 @@  static void sbc35_a9g20_macb_hw_init(void)
 	       pin_to_mask(AT91_PIN_PA28),
 	       &pioa->pudr);
 
-	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-
-	/* Need to reset PHY -> 500ms reset */
-	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
-		AT91_RSTC_MR_URSTEN, &rstc->mr);
-
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-
-	/* Wait for end hardware reset */
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
-		;
-
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
-		&rstc->mr);
+	at91_phy_reset();
 
 	/* Re-enable pull-up */
 	writel(pin_to_mask(AT91_PIN_PA14) |
diff --git a/board/eukrea/cpu9260/cpu9260.c b/board/eukrea/cpu9260/cpu9260.c
index 5e1524e..274f72d 100644
--- a/board/eukrea/cpu9260/cpu9260.c
+++ b/board/eukrea/cpu9260/cpu9260.c
@@ -17,7 +17,6 @@ 
 #include <asm/arch/at91_common.h>
 #include <asm/arch/at91_matrix.h>
 #include <asm/arch/at91_pmc.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/at91_pio.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/hardware.h>
@@ -89,29 +88,14 @@  static void cpu9260_nand_hw_init(void)
 #ifdef CONFIG_MACB
 static void cpu9260_macb_hw_init(void)
 {
-	unsigned long rstcmr;
 	at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
-	at91_rstc_t *rstc = (at91_rstc_t *) ATMEL_BASE_RSTC;
 
 	/* Enable clock */
 	writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
 
 	at91_set_pio_pullup(AT91_PIO_PORTA, 17, 1);
 
-	rstcmr = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-
-	/* Need to reset PHY -> 500ms reset */
-	writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0xD) |
-				AT91_RSTC_MR_URSTEN, &rstc->mr);
-
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-
-	/* Wait for end hardware reset */
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
-		;
-
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | rstcmr | AT91_RSTC_MR_URSTEN, &rstc->mr);
+	at91_phy_reset();
 
 	at91_macb_hw_init();
 }
diff --git a/board/taskit/stamp9g20/stamp9g20.c b/board/taskit/stamp9g20/stamp9g20.c
index 704a63b..27cdf77 100644
--- a/board/taskit/stamp9g20/stamp9g20.c
+++ b/board/taskit/stamp9g20/stamp9g20.c
@@ -19,7 +19,6 @@ 
 #include <asm/arch/at91sam9_smc.h>
 #include <asm/arch/at91_common.h>
 #include <asm/arch/at91_pmc.h>
-#include <asm/arch/at91_rstc.h>
 #include <asm/arch/gpio.h>
 #include <watchdog.h>
 
@@ -67,8 +66,6 @@  static void stamp9G20_nand_hw_init(void)
 static void stamp9G20_macb_hw_init(void)
 {
 	struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
-	struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
-	unsigned long erstl;
 
 	/* Enable the PHY Chip via PA26 on the Stamp 2 Adaptor */
 	at91_set_gpio_output(AT91_PIN_PA26, 0);
@@ -91,33 +88,7 @@  static void stamp9G20_macb_hw_init(void)
 		pin_to_mask(AT91_PIN_PA28),
 		&pioa->pudr);
 
-	erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
-
-	/* Need to reset PHY -> 500ms reset */
-	writel(AT91_RSTC_KEY | (AT91_RSTC_MR_ERSTL(13) &
-				~AT91_RSTC_MR_URSTEN), &rstc->mr);
-	writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
-
-	/* Wait for end of hardware reset */
-	unsigned long start = get_timer(0);
-	unsigned long timeout = 1000; /* 1000ms */
-
-	while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) {
-
-		/* avoid shutdown by watchdog */
-		WATCHDOG_RESET();
-		mdelay(10);
-
-		/* timeout for not getting stuck in an endless loop */
-		if (get_timer(start) >= timeout) {
-			puts("*** ERROR: Timeout waiting for PHY reset!\n");
-			break;
-		};
-	};
-
-	/* Restore NRST value */
-	writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
-		&rstc->mr);
+	at91_phy_reset();
 
 	/* Re-enable pull-up */
 	writel(pin_to_mask(AT91_PIN_PA14) |
diff --git a/spl/Makefile b/spl/Makefile
index 736c6ca..cbd3d27 100644
--- a/spl/Makefile
+++ b/spl/Makefile
@@ -111,10 +111,6 @@  ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
 endif
 
-ifeq ($(SOC),at91)
-LIBS-y += arch/$(ARCH)/cpu/at91-common/libat91-common.o
-endif
-
 # Add GCC lib
 ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
 PLATFORM_LIBGCC = $(SPLTREE)/arch/$(ARCH)/lib/libgcc.o