Skip to contentSkip to conversation

ARM: at91: add UTMI PLL handle functions

PATCH Superseded Wenyou Yang 2 participants 9 messages Dec 9, 2015 – Dec 10, 2015

Subsystems (6)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover ARM: at91: add UTMI PLL handle functions

To reduce the duplicated code, add UTMI PLL enable/disable functions, replace the UTMI PLL handle code with these functions.

It is based on the following patch set.
[PATCH v2 0/5] ARM: at91: improve peripheral and system clock handle functions

Changes in v2:
- remain asm/io.h include.

Wenyou Yang (4):
ARM: at91: clock: add UTMI PLL enable/disable function
ARM: at91: armv7: clean up UTMI PLL handle code
drivers: usb: atmel: clean up the UTMI PLL code
board: atmel: siemens: clean up UTMI PLL code

 arch/arm/mach-at91/armv7/sama5d2_devices.c |    5 +--
 arch/arm/mach-at91/armv7/sama5d3_devices.c |    5 +--
 arch/arm/mach-at91/armv7/sama5d4_devices.c |    5 +--
 arch/arm/mach-at91/clock.c                 |   48 ++++++++++++++++++++++++++++
 arch/arm/mach-at91/include/mach/clk.h      |    3 ++
 board/siemens/corvus/board.c               |    4 +--
 drivers/usb/host/ehci-atmel.c              |   38 +++-------------------
 drivers/usb/host/ohci-at91.c               |   20 ++++--------
 8 files changed, 66 insertions(+), 62 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/4 ARM: at91: clock: add UTMI PLL enable/disable function

To avoid the duplicated code, add the UTMI PLL handle functions, and add PMC_USB init function too.

---

Changes in v2: None

 arch/arm/mach-at91/clock.c            |   48 +++++++++++++++++++++++++++++++++
 arch/arm/mach-at91/include/mach/clk.h |    3 +++
 2 files changed, 51 insertions(+)
arch/arm/mach-at91/clock.c +48 -0
index 823d218..b8f8d48 100644
@@ -10,6 +10,8 @@
 #include <asm/arch/hardware.h>
 #include <asm/arch/at91_pmc.h>
 
+#define EN_UPLL_TIMEOUT		500
+
 void at91_periph_clk_enable(int id)
 {
 	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
@@ -70,3 +72,49 @@ void at91_system_clk_disable(int sys_clk)
 
 	writel(sys_clk, &pmc->scdr);
 }
+
+int at91_upll_clk_enable(void)
+{
+	struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
+	ulong start_time, tmp_time;
+
+	if ((readl(&pmc->uckr) & AT91_PMC_UPLLEN) == AT91_PMC_UPLLEN)
+		return 0;
+
+	start_time = get_timer(0);
+	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
+		tmp_time = get_timer(0);
+		if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
+			printf("ERROR: failed to enable UPLL\n");
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+int at91_upll_clk_disable(void)
+{
+	struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
+	ulong start_time, tmp_time;
+
+	start_time = get_timer(0);
+	writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
+	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
+		tmp_time = get_timer(0);
+		if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
+			printf("ERROR: failed to stop UPLL\n");
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+void at91_usb_clk_init(u32 value)
+{
+	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
+
+	writel(value, &pmc->usb);
+}
arch/arm/mach-at91/include/mach/clk.h +3 -0
index bef4e1c..b2604ef 100644
@@ -130,5 +130,8 @@ int at91_enable_periph_generated_clk(u32 id, u32 clk_source, u32 div);
 u32 at91_get_periph_generated_clk(u32 id);
 void at91_system_clk_enable(int sys_clk);
 void at91_system_clk_disable(int sys_clk);
+int at91_upll_clk_enable(void);
+int at91_upll_clk_disable(void);
+void at91_usb_clk_init(u32 value);
 
 #endif /* __ASM_ARM_ARCH_CLK_H__ */
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 1/4 ARM: at91: clock: add UTMI PLL enable/disable function

Hello Wenyou,

Am 09.12.2015 um 08:57 schrieb Wenyou Yang:

Quoted 11 lines

To avoid the duplicated code, add the UTMI PLL handle functions, and add PMC_USB init function too.

---

Changes in v2: None

  arch/arm/mach-at91/clock.c            |   48 +++++++++++++++++++++++++++++++++
  arch/arm/mach-at91/include/mach/clk.h |    3 +++
  2 files changed, 51 insertions(+)

Tested on the smartweb board, see log:
http://xeidos.ddns.net/buildbot/builders/smartweb_dfu/builds/29/steps/shell/logs/tbotlog

bye,
Heiko

Quoted 78 lines
arch/arm/mach-at91/clock.c +48 -0
index 823d218..b8f8d48 100644
@@ -10,6 +10,8 @@
  #include <asm/arch/hardware.h>
  #include <asm/arch/at91_pmc.h>
 
+#define EN_UPLL_TIMEOUT		500
+
  void at91_periph_clk_enable(int id)
  {
  	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
@@ -70,3 +72,49 @@ void at91_system_clk_disable(int sys_clk)
 
  	writel(sys_clk, &pmc->scdr);
  }
+
+int at91_upll_clk_enable(void)
+{
+	struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
+	ulong start_time, tmp_time;
+
+	if ((readl(&pmc->uckr) & AT91_PMC_UPLLEN) == AT91_PMC_UPLLEN)
+		return 0;
+
+	start_time = get_timer(0);
+	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
+		tmp_time = get_timer(0);
+		if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
+			printf("ERROR: failed to enable UPLL\n");
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+int at91_upll_clk_disable(void)
+{
+	struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
+	ulong start_time, tmp_time;
+
+	start_time = get_timer(0);
+	writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
+	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
+		tmp_time = get_timer(0);
+		if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
+			printf("ERROR: failed to stop UPLL\n");
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+void at91_usb_clk_init(u32 value)
+{
+	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
+
+	writel(value, &pmc->usb);
+}
arch/arm/mach-at91/include/mach/clk.h +3 -0
index bef4e1c..b2604ef 100644
@@ -130,5 +130,8 @@ int at91_enable_periph_generated_clk(u32 id, u32 clk_source, u32 div);
  u32 at91_get_periph_generated_clk(u32 id);
  void at91_system_clk_enable(int sys_clk);
  void at91_system_clk_disable(int sys_clk);
+int at91_upll_clk_enable(void);
+int at91_upll_clk_disable(void);
+void at91_usb_clk_init(u32 value);
 
  #endif /* __ASM_ARM_ARCH_CLK_H__ */
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#3 lore raw

PATCH v2 2/4 ARM: at91: armv7: clean up UTMI PLL handle code

In reply to Wenyou Yang

Due to introducing the UTMI PLL enable function, use this function to reduce the duplicated code.

---

Changes in v2: None

 arch/arm/mach-at91/armv7/sama5d2_devices.c |    5 +----
 arch/arm/mach-at91/armv7/sama5d3_devices.c |    5 +----
 arch/arm/mach-at91/armv7/sama5d4_devices.c |    5 +----
 3 files changed, 3 insertions(+), 12 deletions(-)
arch/arm/mach-at91/armv7/sama5d2_devices.c +1 -4
index 88f8f2c..978eac2 100644
@@ -7,7 +7,6 @@
 
 #include <common.h>
 #include <asm/io.h>
-#include <asm/arch/at91_pmc.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/sama5d2.h>
 
@@ -48,9 +47,7 @@ char *get_cpu_name()
 #ifdef CONFIG_USB_GADGET_ATMEL_USBA
 void at91_udp_hw_init(void)
 {
-	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
-
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	at91_upll_clk_enable();
 
 	at91_periph_clk_enable(ATMEL_ID_UDPHS);
 }
arch/arm/mach-at91/armv7/sama5d3_devices.c +1 -4
index 78ecfc8..64ac262 100644
@@ -8,7 +8,6 @@
 #include <common.h>
 #include <asm/arch/sama5d3.h>
 #include <asm/arch/at91_common.h>
-#include <asm/arch/at91_pmc.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/gpio.h>
 #include <asm/io.h>
@@ -208,10 +207,8 @@ void at91_lcd_hw_init(void)
 #ifdef CONFIG_USB_GADGET_ATMEL_USBA
 void at91_udp_hw_init(void)
 {
-	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
-
 	/* Enable UPLL clock */
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	at91_upll_clk_enable();
 	/* Enable UDPHS clock */
 	at91_periph_clk_enable(ATMEL_ID_UDPHS);
 }
arch/arm/mach-at91/armv7/sama5d4_devices.c +1 -4
index ce33cd4..ebb779e 100644
@@ -8,7 +8,6 @@
 #include <common.h>
 #include <asm/io.h>
 #include <asm/arch/at91_common.h>
-#include <asm/arch/at91_pmc.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/sama5_sfr.h>
 #include <asm/arch/sama5d4.h>
@@ -37,10 +36,8 @@ char *get_cpu_name()
 #ifdef CONFIG_USB_GADGET_ATMEL_USBA
 void at91_udp_hw_init(void)
 {
-	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
-
 	/* Enable UPLL clock */
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	at91_upll_clk_enable();
 	/* Enable UDPHS clock */
 	at91_periph_clk_enable(ATMEL_ID_UDPHS);
 }
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v2 2/4 ARM: at91: armv7: clean up UTMI PLL handle code

Hello Wenyou,

Am 09.12.2015 um 08:57 schrieb Wenyou Yang:

Quoted 4 lines

Due to introducing the UTMI PLL enable function, use this function to reduce the duplicated code.

Quoted 8 lines

---

Changes in v2: None

  arch/arm/mach-at91/armv7/sama5d2_devices.c |    5 +----
  arch/arm/mach-at91/armv7/sama5d3_devices.c |    5 +----
  arch/arm/mach-at91/armv7/sama5d4_devices.c |    5 +----
  3 files changed, 3 insertions(+), 12 deletions(-)

Tested on the smartweb board, see log:
http://xeidos.ddns.net/buildbot/builders/smartweb_dfu/builds/29/steps/shell/logs/tbotlog

bye,
Heiko

Quoted 73 lines
arch/arm/mach-at91/armv7/sama5d2_devices.c +1 -4
index 88f8f2c..978eac2 100644
@@ -7,7 +7,6 @@
 
  #include <common.h>
  #include <asm/io.h>
-#include <asm/arch/at91_pmc.h>
  #include <asm/arch/clk.h>
  #include <asm/arch/sama5d2.h>
 
@@ -48,9 +47,7 @@ char *get_cpu_name()
  #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  void at91_udp_hw_init(void)
  {
-	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
-
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	at91_upll_clk_enable();
 
  	at91_periph_clk_enable(ATMEL_ID_UDPHS);
  }
arch/arm/mach-at91/armv7/sama5d3_devices.c +1 -4
index 78ecfc8..64ac262 100644
@@ -8,7 +8,6 @@
  #include <common.h>
  #include <asm/arch/sama5d3.h>
  #include <asm/arch/at91_common.h>
-#include <asm/arch/at91_pmc.h>
  #include <asm/arch/clk.h>
  #include <asm/arch/gpio.h>
  #include <asm/io.h>
@@ -208,10 +207,8 @@ void at91_lcd_hw_init(void)
  #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  void at91_udp_hw_init(void)
  {
-	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
-
  	/* Enable UPLL clock */
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	at91_upll_clk_enable();
  	/* Enable UDPHS clock */
  	at91_periph_clk_enable(ATMEL_ID_UDPHS);
  }
arch/arm/mach-at91/armv7/sama5d4_devices.c +1 -4
index ce33cd4..ebb779e 100644
@@ -8,7 +8,6 @@
  #include <common.h>
  #include <asm/io.h>
  #include <asm/arch/at91_common.h>
-#include <asm/arch/at91_pmc.h>
  #include <asm/arch/clk.h>
  #include <asm/arch/sama5_sfr.h>
  #include <asm/arch/sama5d4.h>
@@ -37,10 +36,8 @@ char *get_cpu_name()
  #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  void at91_udp_hw_init(void)
  {
-	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
-
  	/* Enable UPLL clock */
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	at91_upll_clk_enable();
  	/* Enable UDPHS clock */
  	at91_periph_clk_enable(ATMEL_ID_UDPHS);
  }
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#5 lore raw

PATCH v2 3/4 drivers: usb: atmel: clean up the UTMI PLL code

In reply to Wenyou Yang

Due to introducing the new UTMI PLL clock handle functions, use these function to reduce the duplicated code.

---

Changes in v2:
- remain asm/io.h include.

 drivers/usb/host/ehci-atmel.c |   38 ++++----------------------------------
 drivers/usb/host/ohci-at91.c  |   20 +++++++-------------
 2 files changed, 11 insertions(+), 47 deletions(-)
drivers/usb/host/ehci-atmel.c +4 -34
index a33fb49..1d7d280 100644
@@ -7,37 +7,18 @@
  */
 
 #include <common.h>
-#include <watchdog.h>
 #include <usb.h>
 #include <asm/io.h>
-#include <asm/arch/hardware.h>
-#include <asm/arch/at91_pmc.h>
 #include <asm/arch/clk.h>
 
 #include "ehci.h"
 
-/* Enable UTMI PLL time out 500us
- * 10 times as datasheet specified
- */
-#define EN_UPLL_TIMEOUT	500UL
-
 int ehci_hcd_init(int index, enum usb_init_type init,
 		struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 {
-	at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
-	ulong start_time, tmp_time;
-
-	start_time = get_timer(0);
 	/* Enable UTMI PLL */
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
-	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
-		WATCHDOG_RESET();
-		tmp_time = get_timer(0);
-		if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
-			printf("ERROR: failed to enable UPLL\n");
-			return -1;
-		}
-	}
+	if (at91_upll_clk_enable())
+		return -1;
 
 	/* Enable USB Host clock */
 	at91_periph_clk_enable(ATMEL_ID_UHPHS);
@@ -51,23 +32,12 @@ int ehci_hcd_init(int index, enum usb_init_type init,
 
 int ehci_hcd_stop(int index)
 {
-	at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
-	ulong start_time, tmp_time;
-
 	/* Disable USB Host Clock */
 	at91_periph_clk_disable(ATMEL_ID_UHPHS);
 
-	start_time = get_timer(0);
 	/* Disable UTMI PLL */
-	writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
-	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
-		WATCHDOG_RESET();
-		tmp_time = get_timer(0);
-		if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
-			printf("ERROR: failed to stop UPLL\n");
-			return -1;
-		}
-	}
+	if (at91_upll_clk_disable())
+		return -1;
 
 	return 0;
 }
drivers/usb/host/ohci-at91.c +7 -13
index da85111..6ae6959 100644
@@ -24,17 +24,13 @@ int usb_cpu_init(void)
 	while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != AT91_PMC_LOCKB)
 		;
 #ifdef CONFIG_AT91SAM9N12
-	writel(AT91_PMC_USBS_USB_PLLB | AT91_PMC_USB_DIV_2, &pmc->usb);
+	at91_usb_clk_init(AT91_PMC_USBS_USB_PLLB | AT91_PMC_USB_DIV_2);
 #endif
 #elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
-	/* Enable UPLL */
-	writel(readl(&pmc->uckr) | AT91_PMC_UPLLEN | AT91_PMC_BIASEN,
-		&pmc->uckr);
-	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU)
-		;
+	if (at91_upll_clk_enable())
+		return -1;
 
-	/* Select PLLA as input clock of OHCI */
-	writel(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10, &pmc->usb);
+	at91_usb_clk_init(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10);
 #endif
 
 	at91_periph_clk_enable(ATMEL_ID_UHP);
@@ -60,17 +56,15 @@ int usb_cpu_stop(void)
 
 #ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB
 #ifdef CONFIG_AT91SAM9N12
-	writel(0, &pmc->usb);
+	at91_usb_clk_init(0);
 #endif
 	/* Disable PLLB */
 	writel(0, &pmc->pllbr);
 	while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != 0)
 		;
 #elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
-	/* Disable UPLL */
-	writel(readl(&pmc->uckr) & (~AT91_PMC_UPLLEN), &pmc->uckr);
-	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU)
-		;
+	if (at91_upll_clk_disable())
+		return -1;
 #endif
 
 	return 0;
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v2 3/4 drivers: usb: atmel: clean up the UTMI PLL code

Hello Wenyou,

Am 09.12.2015 um 08:57 schrieb Wenyou Yang:

Quoted 4 lines

Due to introducing the new UTMI PLL clock handle functions, use these function to reduce the duplicated code.

Quoted 8 lines

---

Changes in v2:
- remain asm/io.h include.

  drivers/usb/host/ehci-atmel.c |   38 ++++----------------------------------
  drivers/usb/host/ohci-at91.c  |   20 +++++++-------------
  2 files changed, 11 insertions(+), 47 deletions(-)

Tested on the smartweb board, see log:
http://xeidos.ddns.net/buildbot/builders/smartweb_dfu/builds/29/steps/shell/logs/tbotlog

bye,
Heiko

Quoted 119 lines
drivers/usb/host/ehci-atmel.c +4 -34
index a33fb49..1d7d280 100644
@@ -7,37 +7,18 @@
   */
 
  #include <common.h>
-#include <watchdog.h>
  #include <usb.h>
  #include <asm/io.h>
-#include <asm/arch/hardware.h>
-#include <asm/arch/at91_pmc.h>
  #include <asm/arch/clk.h>
 
  #include "ehci.h"
 
-/* Enable UTMI PLL time out 500us
- * 10 times as datasheet specified
- */
-#define EN_UPLL_TIMEOUT	500UL
-
  int ehci_hcd_init(int index, enum usb_init_type init,
  		struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  {
-	at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
-	ulong start_time, tmp_time;
-
-	start_time = get_timer(0);
  	/* Enable UTMI PLL */
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
-	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
-		WATCHDOG_RESET();
-		tmp_time = get_timer(0);
-		if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
-			printf("ERROR: failed to enable UPLL\n");
-			return -1;
-		}
-	}
+	if (at91_upll_clk_enable())
+		return -1;
 
  	/* Enable USB Host clock */
  	at91_periph_clk_enable(ATMEL_ID_UHPHS);
@@ -51,23 +32,12 @@ int ehci_hcd_init(int index, enum usb_init_type init,
 
  int ehci_hcd_stop(int index)
  {
-	at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
-	ulong start_time, tmp_time;
-
  	/* Disable USB Host Clock */
  	at91_periph_clk_disable(ATMEL_ID_UHPHS);
 
-	start_time = get_timer(0);
  	/* Disable UTMI PLL */
-	writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
-	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
-		WATCHDOG_RESET();
-		tmp_time = get_timer(0);
-		if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
-			printf("ERROR: failed to stop UPLL\n");
-			return -1;
-		}
-	}
+	if (at91_upll_clk_disable())
+		return -1;
 
  	return 0;
  }
drivers/usb/host/ohci-at91.c +7 -13
index da85111..6ae6959 100644
@@ -24,17 +24,13 @@ int usb_cpu_init(void)
  	while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != AT91_PMC_LOCKB)
  		;
  #ifdef CONFIG_AT91SAM9N12
-	writel(AT91_PMC_USBS_USB_PLLB | AT91_PMC_USB_DIV_2, &pmc->usb);
+	at91_usb_clk_init(AT91_PMC_USBS_USB_PLLB | AT91_PMC_USB_DIV_2);
  #endif
  #elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
-	/* Enable UPLL */
-	writel(readl(&pmc->uckr) | AT91_PMC_UPLLEN | AT91_PMC_BIASEN,
-		&pmc->uckr);
-	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU)
-		;
+	if (at91_upll_clk_enable())
+		return -1;
 
-	/* Select PLLA as input clock of OHCI */
-	writel(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10, &pmc->usb);
+	at91_usb_clk_init(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10);
  #endif
 
  	at91_periph_clk_enable(ATMEL_ID_UHP);
@@ -60,17 +56,15 @@ int usb_cpu_stop(void)
 
  #ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB
  #ifdef CONFIG_AT91SAM9N12
-	writel(0, &pmc->usb);
+	at91_usb_clk_init(0);
  #endif
  	/* Disable PLLB */
  	writel(0, &pmc->pllbr);
  	while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != 0)
  		;
  #elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
-	/* Disable UPLL */
-	writel(readl(&pmc->uckr) & (~AT91_PMC_UPLLEN), &pmc->uckr);
-	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU)
-		;
+	if (at91_upll_clk_disable())
+		return -1;
  #endif
 
  	return 0;
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#7 lore raw

PATCH v2 4/4 board: atmel: siemens: clean up UTMI PLL code

In reply to Wenyou Yang

Due to introducing the new UTMI PLL clock handle functions, use the functions to reduce the duplicated code.

---

Changes in v2: None

 board/siemens/corvus/board.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
board/siemens/corvus/board.c +1 -3
index 8729fe9..658e029 100644
@@ -207,10 +207,8 @@ int board_early_init_f(void)
 /* from ./arch/arm/mach-at91/armv7/sama5d3_devices.c */
 void at91_udp_hw_init(void)
 {
-	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
-
 	/* Enable UPLL clock */
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	at91_upll_clk_enable();
 
 	/* Enable UDPHS clock */
 	at91_periph_clk_enable(ATMEL_ID_UDPHS);
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v2 4/4 board: atmel: siemens: clean up UTMI PLL code

Hello Wenyou,

Am 09.12.2015 um 08:57 schrieb Wenyou Yang:

Quoted 10 lines

Due to introducing the new UTMI PLL clock handle functions, use the functions to reduce the duplicated code.

---

Changes in v2: None

  board/siemens/corvus/board.c |    4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

Tested on the smartweb board, see log:
http://xeidos.ddns.net/buildbot/builders/smartweb_dfu/builds/29/steps/shell/logs/tbotlog

bye,
Heiko

Quoted 18 lines
board/siemens/corvus/board.c +1 -3
index 8729fe9..658e029 100644
@@ -207,10 +207,8 @@ int board_early_init_f(void)
  /* from ./arch/arm/mach-at91/armv7/sama5d3_devices.c */
  void at91_udp_hw_init(void)
  {
-	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
-
  	/* Enable UPLL clock */
-	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	at91_upll_clk_enable();
 
  	/* Enable UDPHS clock */
  	at91_periph_clk_enable(ATMEL_ID_UDPHS);
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany