[U-Boot] [PATCH 0/4] 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.
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 | 39 +++------------------- drivers/usb/host/ohci-at91.c | 20 ++++-------- 8 files changed, 66 insertions(+), 63 deletions(-)

To avoid the duplicated code, add the UTMI PLL handle functions, and add PMC_USB init function too.
Signed-off-by: Wenyou Yang wenyou.yang@atmel.com ---
arch/arm/mach-at91/clock.c | 48 +++++++++++++++++++++++++++++++++ arch/arm/mach-at91/include/mach/clk.h | 3 +++ 2 files changed, 51 insertions(+)
diff --git a/arch/arm/mach-at91/clock.c b/arch/arm/mach-at91/clock.c index 823d218..b8f8d48 100644 --- a/arch/arm/mach-at91/clock.c +++ b/arch/arm/mach-at91/clock.c @@ -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); +} diff --git a/arch/arm/mach-at91/include/mach/clk.h b/arch/arm/mach-at91/include/mach/clk.h index bef4e1c..b2604ef 100644 --- a/arch/arm/mach-at91/include/mach/clk.h +++ b/arch/arm/mach-at91/include/mach/clk.h @@ -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__ */

Due to introducing the UTMI PLL enable function, use this function to reduce the duplicated code.
Signed-off-by: Wenyou Yang wenyou.yang@atmel.com ---
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(-)
diff --git a/arch/arm/mach-at91/armv7/sama5d2_devices.c b/arch/arm/mach-at91/armv7/sama5d2_devices.c index 88f8f2c..978eac2 100644 --- a/arch/arm/mach-at91/armv7/sama5d2_devices.c +++ b/arch/arm/mach-at91/armv7/sama5d2_devices.c @@ -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); } diff --git a/arch/arm/mach-at91/armv7/sama5d3_devices.c b/arch/arm/mach-at91/armv7/sama5d3_devices.c index 78ecfc8..64ac262 100644 --- a/arch/arm/mach-at91/armv7/sama5d3_devices.c +++ b/arch/arm/mach-at91/armv7/sama5d3_devices.c @@ -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); } diff --git a/arch/arm/mach-at91/armv7/sama5d4_devices.c b/arch/arm/mach-at91/armv7/sama5d4_devices.c index ce33cd4..ebb779e 100644 --- a/arch/arm/mach-at91/armv7/sama5d4_devices.c +++ b/arch/arm/mach-at91/armv7/sama5d4_devices.c @@ -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); }

Due to introducing the new UTMI PLL clock handle functions, use these function to reduce the duplicated code.
Signed-off-by: Wenyou Yang wenyou.yang@atmel.com ---
drivers/usb/host/ehci-atmel.c | 39 ++++----------------------------------- drivers/usb/host/ohci-at91.c | 20 +++++++------------- 2 files changed, 11 insertions(+), 48 deletions(-)
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c index a33fb49..a4e2da0 100644 --- a/drivers/usb/host/ehci-atmel.c +++ b/drivers/usb/host/ehci-atmel.c @@ -7,37 +7,17 @@ */
#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 +31,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; } diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index da85111..6ae6959 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c @@ -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;

Due to introducing the new UTMI PLL clock handle functions, use the functions to reduce the duplicated code.
Signed-off-by: Wenyou Yang wenyou.yang@atmel.com [PATCH 0/5] ARM: at91: improve peripheral and system clock handle functions ---
board/siemens/corvus/board.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/board/siemens/corvus/board.c b/board/siemens/corvus/board.c index 8729fe9..658e029 100644 --- a/board/siemens/corvus/board.c +++ b/board/siemens/corvus/board.c @@ -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);
participants (1)
-
Wenyou Yang