1 // SPDX-License-Identifier: GPL-2.0+
2 /*
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 * ------------------------------------------------------------------------
17 */
18
19 #include <asm/omap_common.h>
20 #include <twl4030.h>
21 #include <twl6030.h>
22 #include "omap3.h"
23
24 static int platform_needs_initialization = 1;
25
26 struct musb_config musb_cfg = {
27 .regs = (struct musb_regs *)MENTOR_USB0_BASE,
28 .timeout = OMAP3_USB_TIMEOUT,
29 .musb_speed = 0,
30 };
31
32 /*
33 * OMAP3 USB OTG registers.
34 */
35 struct omap3_otg_regs {
36 u32 revision;
37 u32 sysconfig;
38 u32 sysstatus;
39 u32 interfsel;
40 u32 simenable;
41 u32 forcestdby;
42 };
43
44 static struct omap3_otg_regs *otg;
45
46 #define OMAP3_OTG_SYSCONFIG_SMART_STANDBY_MODE 0x2000
47 #define OMAP3_OTG_SYSCONFIG_NO_STANDBY_MODE 0x1000
48 #define OMAP3_OTG_SYSCONFIG_SMART_IDLE_MODE 0x0010
49 #define OMAP3_OTG_SYSCONFIG_NO_IDLE_MODE 0x0008
50 #define OMAP3_OTG_SYSCONFIG_ENABLEWAKEUP 0x0004
51 #define OMAP3_OTG_SYSCONFIG_SOFTRESET 0x0002
52 #define OMAP3_OTG_SYSCONFIG_AUTOIDLE 0x0001
53
54 #define OMAP3_OTG_SYSSTATUS_RESETDONE 0x0001
55
56 /* OMAP4430 has an internal PHY, use it */
57 #ifdef CONFIG_OMAP44XX
58 #define OMAP3_OTG_INTERFSEL_OMAP 0x0000
59 #else
60 #define OMAP3_OTG_INTERFSEL_OMAP 0x0001
61 #endif
62
63 #define OMAP3_OTG_FORCESTDBY_STANDBY 0x0001
64
65
66 #ifdef DEBUG_MUSB_OMAP3
musb_db_otg_regs(void)67 static void musb_db_otg_regs(void)
68 {
69 u32 l;
70 l = readl(&otg->revision);
71 serial_printf("OTG_REVISION 0x%x\n", l);
72 l = readl(&otg->sysconfig);
73 serial_printf("OTG_SYSCONFIG 0x%x\n", l);
74 l = readl(&otg->sysstatus);
75 serial_printf("OTG_SYSSTATUS 0x%x\n", l);
76 l = readl(&otg->interfsel);
77 serial_printf("OTG_INTERFSEL 0x%x\n", l);
78 l = readl(&otg->forcestdby);
79 serial_printf("OTG_FORCESTDBY 0x%x\n", l);
80 }
81 #endif
82
musb_platform_init(void)83 int musb_platform_init(void)
84 {
85 int ret = -1;
86
87 if (platform_needs_initialization) {
88 u32 stdby;
89
90 /*
91 * OMAP3EVM uses ISP1504 phy and so
92 * twl4030 related init is not required.
93 */
94 #ifdef CONFIG_TWL4030_USB
95 if (twl4030_usb_ulpi_init()) {
96 serial_printf("ERROR: %s Could not initialize PHY\n",
97 __PRETTY_FUNCTION__);
98 goto end;
99 }
100 #endif
101
102 #ifdef CONFIG_TWL6030_POWER
103 twl6030_usb_device_settings();
104 #endif
105
106 otg = (struct omap3_otg_regs *)OMAP3_OTG_BASE;
107
108 /* Set OTG to always be on */
109 writel(OMAP3_OTG_SYSCONFIG_NO_STANDBY_MODE |
110 OMAP3_OTG_SYSCONFIG_NO_IDLE_MODE, &otg->sysconfig);
111
112 /* Set the interface */
113 writel(OMAP3_OTG_INTERFSEL_OMAP, &otg->interfsel);
114
115 /* Clear force standby */
116 stdby = readl(&otg->forcestdby);
117 stdby &= ~OMAP3_OTG_FORCESTDBY_STANDBY;
118 writel(stdby, &otg->forcestdby);
119
120 #ifdef CONFIG_TARGET_OMAP3_EVM
121 musb_cfg.extvbus = omap3_evm_need_extvbus();
122 #endif
123
124 #ifdef CONFIG_OMAP44XX
125 u32 *usbotghs_control =
126 (u32 *)((*ctrl)->control_usbotghs_ctrl);
127 *usbotghs_control = 0x15;
128 #endif
129 platform_needs_initialization = 0;
130 }
131
132 ret = platform_needs_initialization;
133
134 #ifdef CONFIG_TWL4030_USB
135 end:
136 #endif
137 return ret;
138
139 }
140
musb_platform_deinit(void)141 void musb_platform_deinit(void)
142 {
143 /* noop */
144 }
145