summaryrefslogtreecommitdiff
path: root/src/cpu/samsung/exynos5250/usb.c
blob: 5084707e36b27dfc6a927f311b09a43679f6a590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2012 Samsung Electronics
 * Copyright 2013 Google Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <console/console.h>
#include <device/device.h>
#include <arch/io.h>
#include <delay.h>
#include "gpio.h"
#include "power.h"
#include "cpu.h"
#include "usb.h"
#include "chip.h"

/* Enable VBUS */
static int usb_vbus_init(int vbus_gpio)
{
	/* Enable VBUS power switch */
	gpio_direction_output(GPIO_X11, 1);
	/* VBUS turn ON time */
	mdelay(3);

	return 0;
}

/* Setup the EHCI host controller. */

static void setup_usb_phy(struct usb_phy *usb, int hsic_gpio)
{
	unsigned int hostphy_ctrl0;

	power_enable_usb_phy();

	/* Setting up host and device simultaneously */
	hostphy_ctrl0 = readl(&usb->usbphyctrl0);
	hostphy_ctrl0 &= ~(HOST_CTRL0_FSEL_MASK | HOST_CTRL0_COMMONON_N |
			   /* HOST Phy setting */
			   HOST_CTRL0_PHYSWRST |
			   HOST_CTRL0_PHYSWRSTALL |
			   HOST_CTRL0_SIDDQ |
			   HOST_CTRL0_FORCESUSPEND |
			   HOST_CTRL0_FORCESLEEP);
	hostphy_ctrl0 |= (	/* Setting up the ref freq */
				 CLK_24MHZ << 16 |
				 /* HOST Phy setting */
				 HOST_CTRL0_LINKSWRST |
				 HOST_CTRL0_UTMISWRST);
	writel(hostphy_ctrl0, &usb->usbphyctrl0);
	udelay(10);
	clrbits_le32(&usb->usbphyctrl0,
		     HOST_CTRL0_LINKSWRST | HOST_CTRL0_UTMISWRST);
	udelay(20);

	/* EHCI Ctrl setting */
	setbits_le32(&usb->ehcictrl,
		     EHCICTRL_ENAINCRXALIGN |
		     EHCICTRL_ENAINCR4 |
		     EHCICTRL_ENAINCR8 | EHCICTRL_ENAINCR16);

	/* HSIC USB Hub initialization. */
	// FIXME board specific?
	gpio_direction_output(hsic_gpio, 0);
	udelay(100);
	gpio_direction_output(hsic_gpio, 1);
	udelay(5000);

	clrbits_le32(&usb->hsicphyctrl1,
		     HOST_CTRL0_SIDDQ |
		     HOST_CTRL0_FORCESLEEP |
		     HOST_CTRL0_FORCESUSPEND);
	setbits_le32(&usb->hsicphyctrl1, HOST_CTRL0_PHYSWRST);
	udelay(10);
	clrbits_le32(&usb->hsicphyctrl1, HOST_CTRL0_PHYSWRST);

	/* At this point we need to wait for 50ms before talking to
	 * the USB controller (PHY clock and power setup time)
	 * By the time we are actually in the payload, these 50ms
	 * will have passed.
	 */
}

void usb_init(device_t dev)
{
	struct usb_phy *usb;
	struct cpu_samsung_exynos5250_config *conf = dev->chip_info;

	usb_vbus_init(conf->usb_vbus_gpio);
	usb = (struct usb_phy *) samsung_get_base_usb_phy();
	setup_usb_phy(usb, conf->usb_hsic_gpio);
}