blob: 359c635bf6aff8ddf77edfb29166e2f58a789efc [file] [log] [blame]
Thomas Abraham99a33072009-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-VILLARD8f6bcf42009-04-03 12:46:58 +020026#include "davinci.h"
Prathap Srinivase53a0f62010-01-11 15:36:46 +053027#include <asm/arch/hardware.h>
Thomas Abraham99a33072009-01-04 09:41:13 +053028
Heiko Schocher86c98ec2011-11-01 20:00:26 +000029#if !defined(CONFIG_DV_USBPHY_CTL)
30#define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN)
31#endif
32
Thomas Abraham99a33072009-01-04 09:41:13 +053033/* MUSB platform configuration */
34struct musb_config musb_cfg = {
Ajay Kumar Gupta7e71dc72010-06-10 11:20:47 +053035 .regs = (struct musb_regs *)MENTOR_USB0_BASE,
36 .timeout = DAVINCI_USB_TIMEOUT,
37 .musb_speed = 0,
Thomas Abraham99a33072009-01-04 09:41:13 +053038};
39
40/* MUSB module register overlay */
41struct davinci_usb_regs *dregs;
42
43/*
44 * Enable the USB phy
45 */
46static u8 phy_on(void)
47{
48 u32 timeout;
Prathap Srinivase53a0f62010-01-11 15:36:46 +053049#ifdef DAVINCI_DM365EVM
50 u32 val;
51#endif
Thomas Abraham99a33072009-01-04 09:41:13 +053052 /* Wait until the USB phy is turned on */
Prathap Srinivase53a0f62010-01-11 15:36:46 +053053#ifdef DAVINCI_DM365EVM
54 writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
55 USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
56#else
Heiko Schocher86c98ec2011-11-01 20:00:26 +000057 writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR);
Prathap Srinivase53a0f62010-01-11 15:36:46 +053058#endif
Thomas Abraham99a33072009-01-04 09:41:13 +053059 timeout = musb_cfg.timeout;
Prathap Srinivase53a0f62010-01-11 15:36:46 +053060
61#ifdef DAVINCI_DM365EVM
62 /* Set the ownership of GIO33 to USB */
63 val = readl(PINMUX4);
64 val &= ~(PINMUX4_USBDRVBUS_BITCLEAR);
65 val |= PINMUX4_USBDRVBUS_BITSET;
66 writel(val, PINMUX4);
67#endif
Thomas Abraham99a33072009-01-04 09:41:13 +053068 while (timeout--)
69 if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
70 return 1;
71
72 /* USB phy was not turned on */
73 return 0;
74}
75
76/*
77 * Disable the USB phy
78 */
79static void phy_off(void)
80{
81 /* powerdown the on-chip PHY and its oscillator */
82 writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
83}
84
Heiko Schocher662fb502011-11-01 20:00:25 +000085void __enable_vbus(void)
86{
87 /*
88 * nothing to do, vbus is handled through the cpu.
89 * Define this function in board code, if it is
90 * different on your board.
91 */
92}
93void enable_vbus(void)
94 __attribute__((weak, alias("__enable_vbus")));
95
Thomas Abraham99a33072009-01-04 09:41:13 +053096/*
97 * This function performs Davinci platform specific initialization for usb0.
98 */
99int musb_platform_init(void)
100{
101 u32 revision;
102
103 /* enable USB VBUS */
104 enable_vbus();
Heiko Schocher662fb502011-11-01 20:00:25 +0000105
Thomas Abraham99a33072009-01-04 09:41:13 +0530106 /* start the on-chip USB phy and its pll */
107 if (!phy_on())
108 return -1;
109
110 /* reset the controller */
111 dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
112 writel(1, &dregs->ctrlr);
113 udelay(5000);
114
115 /* Returns zero if e.g. not clocked */
116 revision = readl(&dregs->version);
117 if (!revision)
118 return -1;
119
120 /* Disable all interrupts */
121 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
122 DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
123 return 0;
124}
125
126/*
127 * This function performs Davinci platform specific deinitialization for usb0.
128 */
129void musb_platform_deinit(void)
130{
131 /* Turn of the phy */
132 phy_off();
133
134 /* flush any interrupts */
135 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
136 DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
137}