blob: 9e90d59087c8fd18c1be79e7fb4d4f801d5c83e9 [file] [log] [blame]
Stelian Popd1aea1c2008-01-30 21:15:54 +00001/*
2 * (C) Copyright 2006
Stelian Popf9e848b2008-05-08 22:52:09 +02003 * DENX Software Engineering <mk@denx.de>
Stelian Popd1aea1c2008-01-30 21:15:54 +00004 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stelian Popd1aea1c2008-01-30 21:15:54 +00006 */
7
8#include <common.h>
9
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020010#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
Stelian Popd1aea1c2008-01-30 21:15:54 +000011
Reinhard Meyerb06208c2010-11-07 13:26:14 +010012#include <asm/io.h>
Stelian Popd1aea1c2008-01-30 21:15:54 +000013#include <asm/arch/hardware.h>
Stelian Popd4bfbc52008-03-26 20:52:32 +010014#include <asm/arch/at91_pmc.h>
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020015#include <asm/arch/clk.h>
Stelian Popd1aea1c2008-01-30 21:15:54 +000016
17int usb_cpu_init(void)
18{
Reinhard Meyerda480402010-11-03 15:47:20 +010019 at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
Stelian Pope9fe2cf2008-11-09 00:14:46 +010020
21#if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
RONETIX - Ilko Iliev500cda82009-06-05 16:54:31 +020022 defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20) || \
23 defined(CONFIG_AT91SAM9261)
Stelian Pope9fe2cf2008-11-09 00:14:46 +010024 /* Enable PLLB */
Matthias Fuchs1e01b082010-03-25 14:30:13 +010025 writel(get_pllb_init(), &pmc->pllbr);
26 while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != AT91_PMC_LOCKB)
Stelian Pope9fe2cf2008-11-09 00:14:46 +010027 ;
Richard Genoudb762a9c2012-11-29 23:18:32 +000028#elif defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
Bo Shen72979a32013-05-12 22:40:53 +000029 defined(CONFIG_AT91SAM9X5) || defined(CONFIG_SAMA5D3)
Sergey Matyukevichd25010d2010-06-09 23:09:06 +040030 /* 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);
Stelian Pope9fe2cf2008-11-09 00:14:46 +010038#endif
39
Stelian Popd1aea1c2008-01-30 21:15:54 +000040 /* Enable USB host clock. */
Bo Shen72979a32013-05-12 22:40:53 +000041#ifdef CONFIG_SAMA5D3
42 writel(1 << (ATMEL_ID_UHP - 32), &pmc->pcer1);
43#else
Reinhard Meyerda480402010-11-03 15:47:20 +010044 writel(1 << ATMEL_ID_UHP, &pmc->pcer);
Bo Shen72979a32013-05-12 22:40:53 +000045#endif
46
Bo Shenbed082f2013-04-17 00:09:51 +000047#if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
Reinhard Meyerda480402010-11-03 15:47:20 +010048 writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scer);
Stelian Pop61e69d72008-05-08 20:52:22 +020049#else
Reinhard Meyerda480402010-11-03 15:47:20 +010050 writel(ATMEL_PMC_UHP, &pmc->scer);
Stelian Pop61e69d72008-05-08 20:52:22 +020051#endif
Stelian Popd1aea1c2008-01-30 21:15:54 +000052
53 return 0;
54}
55
56int usb_cpu_stop(void)
57{
Reinhard Meyerda480402010-11-03 15:47:20 +010058 at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
Matthias Fuchs1e01b082010-03-25 14:30:13 +010059
Stelian Popd1aea1c2008-01-30 21:15:54 +000060 /* Disable USB host clock. */
Bo Shen72979a32013-05-12 22:40:53 +000061#ifdef CONFIG_SAMA5D3
62 writel(1 << (ATMEL_ID_UHP - 32), &pmc->pcdr1);
63#else
Reinhard Meyerda480402010-11-03 15:47:20 +010064 writel(1 << ATMEL_ID_UHP, &pmc->pcdr);
Bo Shen72979a32013-05-12 22:40:53 +000065#endif
66
Bo Shenbed082f2013-04-17 00:09:51 +000067#if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
Reinhard Meyerda480402010-11-03 15:47:20 +010068 writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scdr);
Stelian Pop61e69d72008-05-08 20:52:22 +020069#else
Reinhard Meyerda480402010-11-03 15:47:20 +010070 writel(ATMEL_PMC_UHP, &pmc->scdr);
Stelian Pop61e69d72008-05-08 20:52:22 +020071#endif
Stelian Pope9fe2cf2008-11-09 00:14:46 +010072
73#if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
Nicolas Ferre4ef545e2009-03-22 14:48:16 +010074 defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20)
Stelian Pope9fe2cf2008-11-09 00:14:46 +010075 /* Disable PLLB */
Matthias Fuchs1e01b082010-03-25 14:30:13 +010076 writel(0, &pmc->pllbr);
77 while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != 0)
Stelian Pope9fe2cf2008-11-09 00:14:46 +010078 ;
Richard Genoudb762a9c2012-11-29 23:18:32 +000079#elif defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
Bo Shen72979a32013-05-12 22:40:53 +000080 defined(CONFIG_AT91SAM9X5) || defined(CONFIG_SAMA5D3)
Sergey Matyukevichd25010d2010-06-09 23:09:06 +040081 /* Disable UPLL */
82 writel(readl(&pmc->uckr) & (~AT91_PMC_UPLLEN), &pmc->uckr);
83 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU)
84 ;
Stelian Pope9fe2cf2008-11-09 00:14:46 +010085#endif
86
Stelian Popd1aea1c2008-01-30 21:15:54 +000087 return 0;
88}
89
90int usb_cpu_init_fail(void)
91{
92 return usb_cpu_stop();
93}
94
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095#endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) */