2008-01-31 05:15:54 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2006
|
2008-05-09 04:52:09 +08:00
|
|
|
* DENX Software Engineering <mk@denx.de>
|
2008-01-31 05:15:54 +08:00
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2008-01-31 05:15:54 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
|
2008-01-31 05:15:54 +08:00
|
|
|
|
2010-11-07 20:26:14 +08:00
|
|
|
#include <asm/io.h>
|
2008-01-31 05:15:54 +08:00
|
|
|
#include <asm/arch/hardware.h>
|
2008-03-27 03:52:32 +08:00
|
|
|
#include <asm/arch/at91_pmc.h>
|
2009-04-17 03:30:44 +08:00
|
|
|
#include <asm/arch/clk.h>
|
2008-01-31 05:15:54 +08:00
|
|
|
|
|
|
|
int usb_cpu_init(void)
|
|
|
|
{
|
2010-11-03 22:47:20 +08:00
|
|
|
at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
|
2008-11-09 07:14:46 +08:00
|
|
|
|
2013-10-21 16:14:00 +08:00
|
|
|
#ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB
|
2008-11-09 07:14:46 +08:00
|
|
|
/* Enable PLLB */
|
2010-03-25 21:30:13 +08:00
|
|
|
writel(get_pllb_init(), &pmc->pllbr);
|
|
|
|
while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != AT91_PMC_LOCKB)
|
2008-11-09 07:14:46 +08:00
|
|
|
;
|
2013-10-21 16:13:59 +08:00
|
|
|
#ifdef CONFIG_AT91SAM9N12
|
|
|
|
writel(AT91_PMC_USBS_USB_PLLB | AT91_PMC_USB_DIV_2, &pmc->usb);
|
|
|
|
#endif
|
2013-10-21 16:14:00 +08:00
|
|
|
#elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
|
2010-06-10 03:09:06 +08:00
|
|
|
/* Enable UPLL */
|
|
|
|
writel(readl(&pmc->uckr) | AT91_PMC_UPLLEN | AT91_PMC_BIASEN,
|
|
|
|
&pmc->uckr);
|
|
|
|
while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Select PLLA as input clock of OHCI */
|
|
|
|
writel(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10, &pmc->usb);
|
2008-11-09 07:14:46 +08:00
|
|
|
#endif
|
|
|
|
|
2008-01-31 05:15:54 +08:00
|
|
|
/* Enable USB host clock. */
|
2014-08-06 17:24:56 +08:00
|
|
|
#ifdef CPU_HAS_PCR
|
|
|
|
at91_periph_clk_enable(ATMEL_ID_UHP);
|
2013-05-13 06:40:53 +08:00
|
|
|
#else
|
2010-11-03 22:47:20 +08:00
|
|
|
writel(1 << ATMEL_ID_UHP, &pmc->pcer);
|
2013-05-13 06:40:53 +08:00
|
|
|
#endif
|
|
|
|
|
2013-04-17 08:09:51 +08:00
|
|
|
#if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
|
2010-11-03 22:47:20 +08:00
|
|
|
writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scer);
|
2008-05-09 02:52:22 +08:00
|
|
|
#else
|
2010-11-03 22:47:20 +08:00
|
|
|
writel(ATMEL_PMC_UHP, &pmc->scer);
|
2008-05-09 02:52:22 +08:00
|
|
|
#endif
|
2008-01-31 05:15:54 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_cpu_stop(void)
|
|
|
|
{
|
2010-11-03 22:47:20 +08:00
|
|
|
at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
|
2010-03-25 21:30:13 +08:00
|
|
|
|
2008-01-31 05:15:54 +08:00
|
|
|
/* Disable USB host clock. */
|
2014-08-06 17:24:56 +08:00
|
|
|
#ifdef CPU_HAS_PCR
|
|
|
|
at91_periph_clk_disable(ATMEL_ID_UHP);
|
2013-05-13 06:40:53 +08:00
|
|
|
#else
|
2010-11-03 22:47:20 +08:00
|
|
|
writel(1 << ATMEL_ID_UHP, &pmc->pcdr);
|
2013-05-13 06:40:53 +08:00
|
|
|
#endif
|
|
|
|
|
2013-04-17 08:09:51 +08:00
|
|
|
#if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
|
2010-11-03 22:47:20 +08:00
|
|
|
writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scdr);
|
2008-05-09 02:52:22 +08:00
|
|
|
#else
|
2010-11-03 22:47:20 +08:00
|
|
|
writel(ATMEL_PMC_UHP, &pmc->scdr);
|
2008-05-09 02:52:22 +08:00
|
|
|
#endif
|
2008-11-09 07:14:46 +08:00
|
|
|
|
2013-10-21 16:14:00 +08:00
|
|
|
#ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB
|
2013-10-21 16:13:59 +08:00
|
|
|
#ifdef CONFIG_AT91SAM9N12
|
|
|
|
writel(0, &pmc->usb);
|
|
|
|
#endif
|
2008-11-09 07:14:46 +08:00
|
|
|
/* Disable PLLB */
|
2010-03-25 21:30:13 +08:00
|
|
|
writel(0, &pmc->pllbr);
|
|
|
|
while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != 0)
|
2008-11-09 07:14:46 +08:00
|
|
|
;
|
2013-10-21 16:14:00 +08:00
|
|
|
#elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
|
2010-06-10 03:09:06 +08:00
|
|
|
/* Disable UPLL */
|
|
|
|
writel(readl(&pmc->uckr) & (~AT91_PMC_UPLLEN), &pmc->uckr);
|
|
|
|
while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU)
|
|
|
|
;
|
2008-11-09 07:14:46 +08:00
|
|
|
#endif
|
|
|
|
|
2008-01-31 05:15:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_cpu_init_fail(void)
|
|
|
|
{
|
|
|
|
return usb_cpu_stop();
|
|
|
|
}
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) */
|