summaryrefslogtreecommitdiffstats
path: root/drivers/usb/musb/am35x.c
blob: 2024940cdd83809cd86efba7326b17ce99c526cb (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
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * am35x.c - TI's AM35x platform specific usb wrapper functions.
 *
 * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
 *
 * Based on drivers/usb/musb/da8xx.c
 *
 * Copyright (c) 2010 Texas Instruments Incorporated
 *
 * 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; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <common.h>

#include "am35x.h"

/* MUSB platform configuration */
struct musb_config musb_cfg = {
	.regs		= (struct musb_regs *)AM35X_USB_OTG_CORE_BASE,
	.timeout	= AM35X_USB_OTG_TIMEOUT,
	.musb_speed	= 0,
};

/*
 * Enable the USB phy
 */
static u8 phy_on(void)
{
	u32 devconf2;
	u32 timeout;

	devconf2 = readl(&am35x_scm_general_regs->devconf2);

	devconf2 &= ~(DEVCONF2_RESET | DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN |
		      DEVCONF2_OTGMODE | DEVCONF2_REFFREQ |
		      DEVCONF2_PHY_GPIOMODE);
	devconf2 |= DEVCONF2_SESENDEN | DEVCONF2_VBDTCTEN | DEVCONF2_PHY_PLLON |
		    DEVCONF2_REFFREQ_13MHZ | DEVCONF2_DATPOL;

	writel(devconf2, &am35x_scm_general_regs->devconf2);

	/* wait until the USB phy is turned on */
	timeout = musb_cfg.timeout;
	while (timeout--)
		if (readl(&am35x_scm_general_regs->devconf2) & DEVCONF2_PHYCKGD)
			return 1;

	/* USB phy was not turned on */
	return 0;
}

/*
 * Disable the USB phy
 */
static void phy_off(void)
{
	u32 devconf2;

	/*
	 * Power down the on-chip PHY.
	 */
	devconf2 = readl(&am35x_scm_general_regs->devconf2);

	devconf2 &= ~DEVCONF2_PHY_PLLON;
	devconf2 |= DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN;
	writel(devconf2, &am35x_scm_general_regs->devconf2);
}

/*
 * This function performs platform specific initialization for usb0.
 */
int musb_platform_init(void)
{
	u32 revision;
	u32 sw_reset;

	/* global usb reset */
	sw_reset = readl(&am35x_scm_general_regs->ip_sw_reset);
	sw_reset |= (1 << 0);
	writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
	sw_reset &= ~(1 << 0);
	writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);

	/* reset the controller */
	writel(0x1, &am35x_usb_regs->control);
	udelay(5000);

	/* start the on-chip usb phy and its pll */
	if (phy_on() == 0)
		return -1;

	/* Returns zero if e.g. not clocked */
	revision = readl(&am35x_usb_regs->revision);
	if (revision == 0)
		return -1;

	return 0;
}

/*
 * This function performs platform specific deinitialization for usb0.
 */
void musb_platform_deinit(void)
{
	/* Turn off the phy */
	phy_off();
}
OpenPOWER on IntegriCloud