blob: 05058d3e330d8e2290cf5f40500b9263b66723a8 [file] [log] [blame]
Bo Shencc30b782012-06-27 21:58:20 +00001/*
2 * (C) Copyright 2012
3 * Atmel Semiconductor <www.atmel.com>
4 * Written-by: Bo Shen <voice.shen@atmel.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 * MA 02110-1301 USA
23 */
24
25#include <common.h>
26#include <watchdog.h>
27#include <usb.h>
28#include <asm/io.h>
29#include <asm/arch/hardware.h>
30#include <asm/arch/at91_pmc.h>
31#include <asm/arch/clk.h>
32
33#include "ehci.h"
Bo Shencc30b782012-06-27 21:58:20 +000034
35/* Enable UTMI PLL time out 500us
36 * 10 times as datasheet specified
37 */
38#define EN_UPLL_TIMEOUT 500UL
39
Lucas Stach676ae062012-09-26 00:14:35 +020040int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Bo Shencc30b782012-06-27 21:58:20 +000041{
42 at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
43 ulong start_time, tmp_time;
44
45 start_time = get_timer(0);
46 /* Enable UTMI PLL */
47 writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
Andreas Bießmann81f40342012-06-28 02:50:37 +000048 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
Bo Shencc30b782012-06-27 21:58:20 +000049 WATCHDOG_RESET();
50 tmp_time = get_timer(0);
51 if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
52 printf("ERROR: failed to enable UPLL\n");
53 return -1;
54 }
55 }
56
57 /* Enable USB Host clock */
58 writel(1 << ATMEL_ID_UHPHS, &pmc->pcer);
59
Lucas Stach676ae062012-09-26 00:14:35 +020060 *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI;
61 *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
62 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Bo Shencc30b782012-06-27 21:58:20 +000063
64 return 0;
65}
66
Lucas Stach676ae062012-09-26 00:14:35 +020067int ehci_hcd_stop(int index)
Bo Shencc30b782012-06-27 21:58:20 +000068{
69 at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
70 ulong start_time, tmp_time;
71
72 /* Disable USB Host Clock */
73 writel(1 << ATMEL_ID_UHPHS, &pmc->pcdr);
74
75 start_time = get_timer(0);
76 /* Disable UTMI PLL */
77 writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
Andreas Bießmann81f40342012-06-28 02:50:37 +000078 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
Bo Shencc30b782012-06-27 21:58:20 +000079 WATCHDOG_RESET();
80 tmp_time = get_timer(0);
81 if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
82 printf("ERROR: failed to stop UPLL\n");
83 return -1;
84 }
85 }
86
87 return 0;
88}