blob: c94a7623ff80361e463a72a8cb42ad5d5cdfd4d5 [file] [log] [blame]
Thomas Abrahame142e9f2009-01-04 09:41:13 +05301/*
2 * TI's Davinci platform specific USB wrapper functions.
3 *
4 * Copyright (c) 2008 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 * MA 02111-1307 USA
20 *
21 * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
22 */
23
24#include <common.h>
25#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020026#include "davinci.h"
Prathap Srinivas6e20e642010-01-11 15:36:46 +053027#include <asm/arch/hardware.h>
Thomas Abrahame142e9f2009-01-04 09:41:13 +053028
29/* MUSB platform configuration */
30struct musb_config musb_cfg = {
Ajay Kumar Guptabbf4c012010-06-10 11:20:47 +053031 .regs = (struct musb_regs *)MENTOR_USB0_BASE,
32 .timeout = DAVINCI_USB_TIMEOUT,
33 .musb_speed = 0,
Thomas Abrahame142e9f2009-01-04 09:41:13 +053034};
35
36/* MUSB module register overlay */
37struct davinci_usb_regs *dregs;
38
39/*
40 * Enable the USB phy
41 */
42static u8 phy_on(void)
43{
44 u32 timeout;
Prathap Srinivas6e20e642010-01-11 15:36:46 +053045#ifdef DAVINCI_DM365EVM
46 u32 val;
47#endif
Thomas Abrahame142e9f2009-01-04 09:41:13 +053048 /* Wait until the USB phy is turned on */
Prathap Srinivas6e20e642010-01-11 15:36:46 +053049#ifdef DAVINCI_DM365EVM
50 writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
51 USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
52#else
Thomas Abrahame142e9f2009-01-04 09:41:13 +053053 writel(USBPHY_SESNDEN | USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
Prathap Srinivas6e20e642010-01-11 15:36:46 +053054#endif
Thomas Abrahame142e9f2009-01-04 09:41:13 +053055 timeout = musb_cfg.timeout;
Prathap Srinivas6e20e642010-01-11 15:36:46 +053056
57#ifdef DAVINCI_DM365EVM
58 /* Set the ownership of GIO33 to USB */
59 val = readl(PINMUX4);
60 val &= ~(PINMUX4_USBDRVBUS_BITCLEAR);
61 val |= PINMUX4_USBDRVBUS_BITSET;
62 writel(val, PINMUX4);
63#endif
Thomas Abrahame142e9f2009-01-04 09:41:13 +053064 while (timeout--)
65 if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
66 return 1;
67
68 /* USB phy was not turned on */
69 return 0;
70}
71
72/*
73 * Disable the USB phy
74 */
75static void phy_off(void)
76{
77 /* powerdown the on-chip PHY and its oscillator */
78 writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
79}
80
Heiko Schocher4ebe2082011-11-01 20:00:25 +000081void __enable_vbus(void)
82{
83 /*
84 * nothing to do, vbus is handled through the cpu.
85 * Define this function in board code, if it is
86 * different on your board.
87 */
88}
89void enable_vbus(void)
90 __attribute__((weak, alias("__enable_vbus")));
91
Thomas Abrahame142e9f2009-01-04 09:41:13 +053092/*
93 * This function performs Davinci platform specific initialization for usb0.
94 */
95int musb_platform_init(void)
96{
97 u32 revision;
98
99 /* enable USB VBUS */
100 enable_vbus();
Heiko Schocher4ebe2082011-11-01 20:00:25 +0000101
Thomas Abrahame142e9f2009-01-04 09:41:13 +0530102 /* start the on-chip USB phy and its pll */
103 if (!phy_on())
104 return -1;
105
106 /* reset the controller */
107 dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
108 writel(1, &dregs->ctrlr);
109 udelay(5000);
110
111 /* Returns zero if e.g. not clocked */
112 revision = readl(&dregs->version);
113 if (!revision)
114 return -1;
115
116 /* Disable all interrupts */
117 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
118 DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
119 return 0;
120}
121
122/*
123 * This function performs Davinci platform specific deinitialization for usb0.
124 */
125void musb_platform_deinit(void)
126{
127 /* Turn of the phy */
128 phy_off();
129
130 /* flush any interrupts */
131 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
132 DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
133}