blob: a7648fc452be64f80867636f4214c7b7fa4f9e55 [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"
Thomas Abraham99a33072009-01-04 09:41:13 +053027
28/* MUSB platform configuration */
29struct musb_config musb_cfg = {
30 (struct musb_regs *)MENTOR_USB0_BASE,
31 DAVINCI_USB_TIMEOUT,
32 0
33};
34
35/* MUSB module register overlay */
36struct davinci_usb_regs *dregs;
37
38/*
39 * Enable the USB phy
40 */
41static u8 phy_on(void)
42{
43 u32 timeout;
44
45 /* Wait until the USB phy is turned on */
46 writel(USBPHY_SESNDEN | USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
47 timeout = musb_cfg.timeout;
48 while (timeout--)
49 if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
50 return 1;
51
52 /* USB phy was not turned on */
53 return 0;
54}
55
56/*
57 * Disable the USB phy
58 */
59static void phy_off(void)
60{
61 /* powerdown the on-chip PHY and its oscillator */
62 writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
63}
64
65/*
66 * This function performs Davinci platform specific initialization for usb0.
67 */
68int musb_platform_init(void)
69{
70 u32 revision;
71
72 /* enable USB VBUS */
73 enable_vbus();
74
75 /* start the on-chip USB phy and its pll */
76 if (!phy_on())
77 return -1;
78
79 /* reset the controller */
80 dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
81 writel(1, &dregs->ctrlr);
82 udelay(5000);
83
84 /* Returns zero if e.g. not clocked */
85 revision = readl(&dregs->version);
86 if (!revision)
87 return -1;
88
89 /* Disable all interrupts */
90 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
91 DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
92 return 0;
93}
94
95/*
96 * This function performs Davinci platform specific deinitialization for usb0.
97 */
98void musb_platform_deinit(void)
99{
100 /* Turn of the phy */
101 phy_off();
102
103 /* flush any interrupts */
104 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
105 DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
106}