blob: 080bd78523c92c59351cd0ee32151f7849d1ee5d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Rix09c82bc2009-10-31 12:37:41 -05002/*
3 * Copyright (c) 2009 Wind River Systems, Inc.
4 * Tom Rix <Tom.Rix@windriver.com>
5 *
6 * This is file is based on
7 * repository git.gitorious.org/u-boot-omap3/mainline.git,
8 * branch omap3-dev-usb, file drivers/usb/host/omap3530_usb.c
9 *
10 * This is the unique part of its copyright :
11 *
12 * ------------------------------------------------------------------------
13 *
14 * Copyright (c) 2009 Texas Instruments
15 *
16 * ------------------------------------------------------------------------
Tom Rix09c82bc2009-10-31 12:37:41 -050017 */
18
Simon Glassbd7a59a2019-11-14 12:57:23 -070019#include <serial.h>
Lokesh Vutla37bce592013-05-30 02:54:30 +000020#include <asm/omap_common.h>
Tom Rix09c82bc2009-10-31 12:37:41 -050021#include <twl4030.h>
Steve Sakoman31367d12010-06-25 12:42:04 -070022#include <twl6030.h>
Tom Rix09c82bc2009-10-31 12:37:41 -050023#include "omap3.h"
24
25static int platform_needs_initialization = 1;
26
27struct musb_config musb_cfg = {
Ajay Kumar Gupta7e71dc72010-06-10 11:20:47 +053028 .regs = (struct musb_regs *)MENTOR_USB0_BASE,
29 .timeout = OMAP3_USB_TIMEOUT,
30 .musb_speed = 0,
Tom Rix09c82bc2009-10-31 12:37:41 -050031};
32
33/*
34 * OMAP3 USB OTG registers.
35 */
36struct omap3_otg_regs {
37 u32 revision;
38 u32 sysconfig;
39 u32 sysstatus;
40 u32 interfsel;
41 u32 simenable;
42 u32 forcestdby;
43};
44
45static struct omap3_otg_regs *otg;
46
47#define OMAP3_OTG_SYSCONFIG_SMART_STANDBY_MODE 0x2000
48#define OMAP3_OTG_SYSCONFIG_NO_STANDBY_MODE 0x1000
49#define OMAP3_OTG_SYSCONFIG_SMART_IDLE_MODE 0x0010
50#define OMAP3_OTG_SYSCONFIG_NO_IDLE_MODE 0x0008
51#define OMAP3_OTG_SYSCONFIG_ENABLEWAKEUP 0x0004
52#define OMAP3_OTG_SYSCONFIG_SOFTRESET 0x0002
53#define OMAP3_OTG_SYSCONFIG_AUTOIDLE 0x0001
54
55#define OMAP3_OTG_SYSSTATUS_RESETDONE 0x0001
56
Steve Sakoman31367d12010-06-25 12:42:04 -070057/* OMAP4430 has an internal PHY, use it */
Tom Rini8d4bfb82017-05-12 22:33:19 -040058#ifdef CONFIG_OMAP44XX
Steve Sakoman31367d12010-06-25 12:42:04 -070059#define OMAP3_OTG_INTERFSEL_OMAP 0x0000
60#else
Tom Rix09c82bc2009-10-31 12:37:41 -050061#define OMAP3_OTG_INTERFSEL_OMAP 0x0001
Steve Sakoman31367d12010-06-25 12:42:04 -070062#endif
Tom Rix09c82bc2009-10-31 12:37:41 -050063
64#define OMAP3_OTG_FORCESTDBY_STANDBY 0x0001
65
66
67#ifdef DEBUG_MUSB_OMAP3
68static void musb_db_otg_regs(void)
69{
70 u32 l;
71 l = readl(&otg->revision);
72 serial_printf("OTG_REVISION 0x%x\n", l);
73 l = readl(&otg->sysconfig);
74 serial_printf("OTG_SYSCONFIG 0x%x\n", l);
75 l = readl(&otg->sysstatus);
76 serial_printf("OTG_SYSSTATUS 0x%x\n", l);
77 l = readl(&otg->interfsel);
78 serial_printf("OTG_INTERFSEL 0x%x\n", l);
79 l = readl(&otg->forcestdby);
80 serial_printf("OTG_FORCESTDBY 0x%x\n", l);
81}
82#endif
83
84int musb_platform_init(void)
85{
86 int ret = -1;
87
88 if (platform_needs_initialization) {
89 u32 stdby;
90
Tom Rix8526c6f2009-10-31 12:37:46 -050091 /*
92 * OMAP3EVM uses ISP1504 phy and so
93 * twl4030 related init is not required.
94 */
95#ifdef CONFIG_TWL4030_USB
Tom Rix09c82bc2009-10-31 12:37:41 -050096 if (twl4030_usb_ulpi_init()) {
97 serial_printf("ERROR: %s Could not initialize PHY\n",
98 __PRETTY_FUNCTION__);
99 goto end;
100 }
Tom Rix8526c6f2009-10-31 12:37:46 -0500101#endif
Steve Sakoman31367d12010-06-25 12:42:04 -0700102
103#ifdef CONFIG_TWL6030_POWER
104 twl6030_usb_device_settings();
105#endif
106
Tom Rix09c82bc2009-10-31 12:37:41 -0500107 otg = (struct omap3_otg_regs *)OMAP3_OTG_BASE;
108
109 /* Set OTG to always be on */
110 writel(OMAP3_OTG_SYSCONFIG_NO_STANDBY_MODE |
111 OMAP3_OTG_SYSCONFIG_NO_IDLE_MODE, &otg->sysconfig);
112
113 /* Set the interface */
114 writel(OMAP3_OTG_INTERFSEL_OMAP, &otg->interfsel);
115
116 /* Clear force standby */
117 stdby = readl(&otg->forcestdby);
118 stdby &= ~OMAP3_OTG_FORCESTDBY_STANDBY;
119 writel(stdby, &otg->forcestdby);
120
Tom Rini38216ee2017-05-12 22:33:18 -0400121#ifdef CONFIG_TARGET_OMAP3_EVM
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +0530122 musb_cfg.extvbus = omap3_evm_need_extvbus();
123#endif
Steve Sakoman31367d12010-06-25 12:42:04 -0700124
Tom Rini8d4bfb82017-05-12 22:33:19 -0400125#ifdef CONFIG_OMAP44XX
Lokesh Vutla37bce592013-05-30 02:54:30 +0000126 u32 *usbotghs_control =
127 (u32 *)((*ctrl)->control_usbotghs_ctrl);
Steve Sakoman31367d12010-06-25 12:42:04 -0700128 *usbotghs_control = 0x15;
129#endif
Tom Rix09c82bc2009-10-31 12:37:41 -0500130 platform_needs_initialization = 0;
131 }
132
133 ret = platform_needs_initialization;
Sanjeev Premi3a761ff2009-12-24 14:20:41 +0530134
135#ifdef CONFIG_TWL4030_USB
Tom Rix09c82bc2009-10-31 12:37:41 -0500136end:
Sanjeev Premi3a761ff2009-12-24 14:20:41 +0530137#endif
Tom Rix09c82bc2009-10-31 12:37:41 -0500138 return ret;
139
140}
141
142void musb_platform_deinit(void)
143{
144 /* noop */
145}