]> git.sur5r.net Git - u-boot/blob - drivers/usb/host/ohci-at91.c
Merge branch 'master' of git://git.denx.de/u-boot-nds32
[u-boot] / drivers / usb / host / ohci-at91.c
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 #if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
22     defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20) || \
23     defined(CONFIG_AT91SAM9261)
24         /* Enable PLLB */
25         writel(get_pllb_init(), &pmc->pllbr);
26         while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != AT91_PMC_LOCKB)
27                 ;
28 #elif defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
29         defined(CONFIG_AT91SAM9X5) || defined(CONFIG_SAMA5D3)
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 CONFIG_SAMA5D3
42         writel(1 << (ATMEL_ID_UHP - 32), &pmc->pcer1);
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 CONFIG_SAMA5D3
62         writel(1 << (ATMEL_ID_UHP - 32), &pmc->pcdr1);
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 #if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
74     defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20)
75         /* Disable PLLB */
76         writel(0, &pmc->pllbr);
77         while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != 0)
78                 ;
79 #elif defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
80         defined(CONFIG_AT91SAM9X5) || defined(CONFIG_SAMA5D3)
81         /* Disable UPLL */
82         writel(readl(&pmc->uckr) & (~AT91_PMC_UPLLEN), &pmc->uckr);
83         while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU)
84                 ;
85 #endif
86
87         return 0;
88 }
89
90 int usb_cpu_init_fail(void)
91 {
92         return usb_cpu_stop();
93 }
94
95 #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) */