xref: /openbmc/u-boot/drivers/usb/host/ohci-at91.c (revision 07b34278)
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 	/* Enable USB host clock. */
41 #ifdef CPU_HAS_PCR
42 	at91_periph_clk_enable(ATMEL_ID_UHP);
43 #else
44 	writel(1 << ATMEL_ID_UHP, &pmc->pcer);
45 #endif
46 
47 #if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
48 	writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scer);
49 #else
50 	writel(ATMEL_PMC_UHP, &pmc->scer);
51 #endif
52 
53 	return 0;
54 }
55 
56 int usb_cpu_stop(void)
57 {
58 	at91_pmc_t *pmc	= (at91_pmc_t *)ATMEL_BASE_PMC;
59 
60 	/* Disable USB host clock. */
61 #ifdef CPU_HAS_PCR
62 	at91_periph_clk_disable(ATMEL_ID_UHP);
63 #else
64 	writel(1 << ATMEL_ID_UHP, &pmc->pcdr);
65 #endif
66 
67 #if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
68 	writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scdr);
69 #else
70 	writel(ATMEL_PMC_UHP, &pmc->scdr);
71 #endif
72 
73 #ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB
74 #ifdef CONFIG_AT91SAM9N12
75 	writel(0, &pmc->usb);
76 #endif
77 	/* Disable PLLB */
78 	writel(0, &pmc->pllbr);
79 	while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != 0)
80 		;
81 #elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
82 	/* Disable UPLL */
83 	writel(readl(&pmc->uckr) & (~AT91_PMC_UPLLEN), &pmc->uckr);
84 	while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU)
85 		;
86 #endif
87 
88 	return 0;
89 }
90 
91 int usb_cpu_init_fail(void)
92 {
93 	return usb_cpu_stop();
94 }
95 
96 #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) */
97