blob: 46cdb5ad1f04085f0c06cac6370723595043221d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Thomas Abrahame142e9f2009-01-04 09:41:13 +05302/*
3 * TI's Davinci platform specific USB wrapper functions.
4 *
5 * Copyright (c) 2008 Texas Instruments
6 *
Thomas Abrahame142e9f2009-01-04 09:41:13 +05307 * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
8 */
9
10#include <common.h>
11#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020012#include "davinci.h"
Prathap Srinivas6e20e642010-01-11 15:36:46 +053013#include <asm/arch/hardware.h>
Thomas Abrahame142e9f2009-01-04 09:41:13 +053014
Heiko Schocher1fa892c2011-11-01 20:00:26 +000015#if !defined(CONFIG_DV_USBPHY_CTL)
16#define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN)
17#endif
18
Thomas Abrahame142e9f2009-01-04 09:41:13 +053019/* MUSB platform configuration */
20struct musb_config musb_cfg = {
Ajay Kumar Guptabbf4c012010-06-10 11:20:47 +053021 .regs = (struct musb_regs *)MENTOR_USB0_BASE,
22 .timeout = DAVINCI_USB_TIMEOUT,
23 .musb_speed = 0,
Thomas Abrahame142e9f2009-01-04 09:41:13 +053024};
25
26/* MUSB module register overlay */
27struct davinci_usb_regs *dregs;
28
29/*
30 * Enable the USB phy
31 */
32static u8 phy_on(void)
33{
34 u32 timeout;
Prathap Srinivas6e20e642010-01-11 15:36:46 +053035#ifdef DAVINCI_DM365EVM
36 u32 val;
37#endif
Thomas Abrahame142e9f2009-01-04 09:41:13 +053038 /* Wait until the USB phy is turned on */
Prathap Srinivas6e20e642010-01-11 15:36:46 +053039#ifdef DAVINCI_DM365EVM
40 writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
41 USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
42#else
Heiko Schocher1fa892c2011-11-01 20:00:26 +000043 writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR);
Prathap Srinivas6e20e642010-01-11 15:36:46 +053044#endif
Thomas Abrahame142e9f2009-01-04 09:41:13 +053045 timeout = musb_cfg.timeout;
Prathap Srinivas6e20e642010-01-11 15:36:46 +053046
47#ifdef DAVINCI_DM365EVM
48 /* Set the ownership of GIO33 to USB */
49 val = readl(PINMUX4);
50 val &= ~(PINMUX4_USBDRVBUS_BITCLEAR);
51 val |= PINMUX4_USBDRVBUS_BITSET;
52 writel(val, PINMUX4);
53#endif
Thomas Abrahame142e9f2009-01-04 09:41:13 +053054 while (timeout--)
55 if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
56 return 1;
57
58 /* USB phy was not turned on */
59 return 0;
60}
61
62/*
63 * Disable the USB phy
64 */
65static void phy_off(void)
66{
67 /* powerdown the on-chip PHY and its oscillator */
68 writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
69}
70
Heiko Schocher4ebe2082011-11-01 20:00:25 +000071void __enable_vbus(void)
72{
73 /*
74 * nothing to do, vbus is handled through the cpu.
75 * Define this function in board code, if it is
76 * different on your board.
77 */
78}
79void enable_vbus(void)
80 __attribute__((weak, alias("__enable_vbus")));
81
Thomas Abrahame142e9f2009-01-04 09:41:13 +053082/*
83 * This function performs Davinci platform specific initialization for usb0.
84 */
85int musb_platform_init(void)
86{
87 u32 revision;
88
89 /* enable USB VBUS */
90 enable_vbus();
Heiko Schocher4ebe2082011-11-01 20:00:25 +000091
Thomas Abrahame142e9f2009-01-04 09:41:13 +053092 /* start the on-chip USB phy and its pll */
93 if (!phy_on())
94 return -1;
95
96 /* reset the controller */
97 dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
98 writel(1, &dregs->ctrlr);
99 udelay(5000);
100
101 /* Returns zero if e.g. not clocked */
102 revision = readl(&dregs->version);
103 if (!revision)
104 return -1;
105
106 /* Disable all interrupts */
107 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
108 DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
109 return 0;
110}
111
112/*
113 * This function performs Davinci platform specific deinitialization for usb0.
114 */
115void musb_platform_deinit(void)
116{
117 /* Turn of the phy */
118 phy_off();
119
120 /* flush any interrupts */
121 writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
122 DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
123}