1 /* 2 * (C) Copyright 2006 3 * DENX Software Engineering <mk@denx.de> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 10 #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) 11 12 #include <asm/io.h> 13 #include <asm/arch/hardware.h> 14 #include <asm/arch/at91_pmc.h> 15 #include <asm/arch/clk.h> 16 17 int usb_cpu_init(void) 18 { 19 at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC; 20 21 #ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB 22 /* Enable PLLB */ 23 writel(get_pllb_init(), &pmc->pllbr); 24 while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != AT91_PMC_LOCKB) 25 ; 26 #ifdef CONFIG_AT91SAM9N12 27 writel(AT91_PMC_USBS_USB_PLLB | AT91_PMC_USB_DIV_2, &pmc->usb); 28 #endif 29 #elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL) 30 /* Enable UPLL */ 31 writel(readl(&pmc->uckr) | AT91_PMC_UPLLEN | AT91_PMC_BIASEN, 32 &pmc->uckr); 33 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) 34 ; 35 36 /* Select PLLA as input clock of OHCI */ 37 writel(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10, &pmc->usb); 38 #endif 39 40 at91_periph_clk_enable(ATMEL_ID_UHP); 41 42 at91_system_clk_enable(ATMEL_PMC_UHP); 43 #if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10) 44 at91_system_clk_enable(AT91_PMC_HCK0); 45 #endif 46 47 return 0; 48 } 49 50 int usb_cpu_stop(void) 51 { 52 at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC; 53 54 at91_periph_clk_disable(ATMEL_ID_UHP); 55 56 at91_system_clk_disable(ATMEL_PMC_UHP); 57 #if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10) 58 at91_system_clk_disable(AT91_PMC_HCK0); 59 #endif 60 61 #ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB 62 #ifdef CONFIG_AT91SAM9N12 63 writel(0, &pmc->usb); 64 #endif 65 /* Disable PLLB */ 66 writel(0, &pmc->pllbr); 67 while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != 0) 68 ; 69 #elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL) 70 /* Disable UPLL */ 71 writel(readl(&pmc->uckr) & (~AT91_PMC_UPLLEN), &pmc->uckr); 72 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) 73 ; 74 #endif 75 76 return 0; 77 } 78 79 int usb_cpu_init_fail(void) 80 { 81 return usb_cpu_stop(); 82 } 83 84 #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) */ 85