blob: 05d6ff2b69e8b1fc91a5670953a6a6ca0f990b0e [file] [log] [blame]
Stelian Popfefb6c12008-01-30 21:15:54 +00001/*
2 * (C) Copyright 2006
Stelian Pop567fb852008-05-08 22:52:09 +02003 * DENX Software Engineering <mk@denx.de>
Stelian Popfefb6c12008-01-30 21:15:54 +00004 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stelian Popfefb6c12008-01-30 21:15:54 +00006 */
7
8#include <common.h>
9
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020010#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
Stelian Popfefb6c12008-01-30 21:15:54 +000011
Reinhard Meyer86592f62010-11-07 13:26:14 +010012#include <asm/io.h>
Stelian Popfefb6c12008-01-30 21:15:54 +000013#include <asm/arch/hardware.h>
Stelian Pop983c1db2008-03-26 20:52:32 +010014#include <asm/arch/at91_pmc.h>
Jean-Christophe PLAGNIOL-VILLARDdc39ae92009-04-16 21:30:44 +020015#include <asm/arch/clk.h>
Stelian Popfefb6c12008-01-30 21:15:54 +000016
17int usb_cpu_init(void)
18{
Reinhard Meyer372f2782010-11-03 15:47:20 +010019 at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
Stelian Pop3e0cda02008-11-09 00:14:46 +010020
21#if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
RONETIX - Ilko Ilievfaa14ba2009-06-05 16:54:31 +020022 defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20) || \
Bo Shend9bef0a2013-10-21 16:13:59 +080023 defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9N12)
Stelian Pop3e0cda02008-11-09 00:14:46 +010024 /* Enable PLLB */
Matthias Fuchs0701f732010-03-25 14:30:13 +010025 writel(get_pllb_init(), &pmc->pllbr);
26 while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != AT91_PMC_LOCKB)
Stelian Pop3e0cda02008-11-09 00:14:46 +010027 ;
Bo Shend9bef0a2013-10-21 16:13:59 +080028#ifdef CONFIG_AT91SAM9N12
29 writel(AT91_PMC_USBS_USB_PLLB | AT91_PMC_USB_DIV_2, &pmc->usb);
30#endif
Richard Genoudbcfc8972012-11-29 23:18:32 +000031#elif defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
Bo Shene5e8bb02013-05-12 22:40:53 +000032 defined(CONFIG_AT91SAM9X5) || defined(CONFIG_SAMA5D3)
Sergey Matyukevich64203c72010-06-09 23:09:06 +040033 /* Enable UPLL */
34 writel(readl(&pmc->uckr) | AT91_PMC_UPLLEN | AT91_PMC_BIASEN,
35 &pmc->uckr);
36 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU)
37 ;
38
39 /* Select PLLA as input clock of OHCI */
40 writel(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10, &pmc->usb);
Stelian Pop3e0cda02008-11-09 00:14:46 +010041#endif
42
Stelian Popfefb6c12008-01-30 21:15:54 +000043 /* Enable USB host clock. */
Bo Shene5e8bb02013-05-12 22:40:53 +000044#ifdef CONFIG_SAMA5D3
45 writel(1 << (ATMEL_ID_UHP - 32), &pmc->pcer1);
46#else
Reinhard Meyer372f2782010-11-03 15:47:20 +010047 writel(1 << ATMEL_ID_UHP, &pmc->pcer);
Bo Shene5e8bb02013-05-12 22:40:53 +000048#endif
49
Bo Shen158947d2013-04-17 00:09:51 +000050#if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
Reinhard Meyer372f2782010-11-03 15:47:20 +010051 writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scer);
Stelian Popd99a8ff2008-05-08 20:52:22 +020052#else
Reinhard Meyer372f2782010-11-03 15:47:20 +010053 writel(ATMEL_PMC_UHP, &pmc->scer);
Stelian Popd99a8ff2008-05-08 20:52:22 +020054#endif
Stelian Popfefb6c12008-01-30 21:15:54 +000055
56 return 0;
57}
58
59int usb_cpu_stop(void)
60{
Reinhard Meyer372f2782010-11-03 15:47:20 +010061 at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
Matthias Fuchs0701f732010-03-25 14:30:13 +010062
Stelian Popfefb6c12008-01-30 21:15:54 +000063 /* Disable USB host clock. */
Bo Shene5e8bb02013-05-12 22:40:53 +000064#ifdef CONFIG_SAMA5D3
65 writel(1 << (ATMEL_ID_UHP - 32), &pmc->pcdr1);
66#else
Reinhard Meyer372f2782010-11-03 15:47:20 +010067 writel(1 << ATMEL_ID_UHP, &pmc->pcdr);
Bo Shene5e8bb02013-05-12 22:40:53 +000068#endif
69
Bo Shen158947d2013-04-17 00:09:51 +000070#if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
Reinhard Meyer372f2782010-11-03 15:47:20 +010071 writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scdr);
Stelian Popd99a8ff2008-05-08 20:52:22 +020072#else
Reinhard Meyer372f2782010-11-03 15:47:20 +010073 writel(ATMEL_PMC_UHP, &pmc->scdr);
Stelian Popd99a8ff2008-05-08 20:52:22 +020074#endif
Stelian Pop3e0cda02008-11-09 00:14:46 +010075
76#if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
Bo Shend9bef0a2013-10-21 16:13:59 +080077 defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20) || \
78 defined(CONFIG_AT91SAM9N12)
79#ifdef CONFIG_AT91SAM9N12
80 writel(0, &pmc->usb);
81#endif
Stelian Pop3e0cda02008-11-09 00:14:46 +010082 /* Disable PLLB */
Matthias Fuchs0701f732010-03-25 14:30:13 +010083 writel(0, &pmc->pllbr);
84 while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != 0)
Stelian Pop3e0cda02008-11-09 00:14:46 +010085 ;
Richard Genoudbcfc8972012-11-29 23:18:32 +000086#elif defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
Bo Shene5e8bb02013-05-12 22:40:53 +000087 defined(CONFIG_AT91SAM9X5) || defined(CONFIG_SAMA5D3)
Sergey Matyukevich64203c72010-06-09 23:09:06 +040088 /* Disable UPLL */
89 writel(readl(&pmc->uckr) & (~AT91_PMC_UPLLEN), &pmc->uckr);
90 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU)
91 ;
Stelian Pop3e0cda02008-11-09 00:14:46 +010092#endif
93
Stelian Popfefb6c12008-01-30 21:15:54 +000094 return 0;
95}
96
97int usb_cpu_init_fail(void)
98{
99 return usb_cpu_stop();
100}
101
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200102#endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) */