xref: /openbmc/u-boot/drivers/usb/musb/omap3.c (revision ddf56bc7)
1 /*
2  * Copyright (c) 2009 Wind River Systems, Inc.
3  * Tom Rix <Tom.Rix@windriver.com>
4  *
5  * This is file is based on
6  * repository git.gitorious.org/u-boot-omap3/mainline.git,
7  * branch omap3-dev-usb, file drivers/usb/host/omap3530_usb.c
8  *
9  * This is the unique part of its copyright :
10  *
11  * ------------------------------------------------------------------------
12  *
13  * Copyright (c) 2009 Texas Instruments
14  *
15  * ------------------------------------------------------------------------
16  *
17  * SPDX-License-Identifier:	GPL-2.0+
18  */
19 
20 #include <asm/omap_common.h>
21 #include <twl4030.h>
22 #include <twl6030.h>
23 #include "omap3.h"
24 
25 static int platform_needs_initialization = 1;
26 
27 struct musb_config musb_cfg = {
28 	.regs		= (struct musb_regs *)MENTOR_USB0_BASE,
29 	.timeout	= OMAP3_USB_TIMEOUT,
30 	.musb_speed	= 0,
31 };
32 
33 /*
34  * OMAP3 USB OTG registers.
35  */
36 struct omap3_otg_regs {
37 	u32	revision;
38 	u32	sysconfig;
39 	u32	sysstatus;
40 	u32	interfsel;
41 	u32	simenable;
42 	u32	forcestdby;
43 };
44 
45 static 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 
57 /* OMAP4430 has an internal PHY, use it */
58 #ifdef CONFIG_OMAP4430
59 #define OMAP3_OTG_INTERFSEL_OMAP			0x0000
60 #else
61 #define OMAP3_OTG_INTERFSEL_OMAP			0x0001
62 #endif
63 
64 #define OMAP3_OTG_FORCESTDBY_STANDBY			0x0001
65 
66 
67 #ifdef DEBUG_MUSB_OMAP3
68 static 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 
84 int musb_platform_init(void)
85 {
86 	int ret = -1;
87 
88 	if (platform_needs_initialization) {
89 		u32 stdby;
90 
91 		/*
92 		 * OMAP3EVM uses ISP1504 phy and so
93 		 * twl4030 related init is not required.
94 		 */
95 #ifdef CONFIG_TWL4030_USB
96 		if (twl4030_usb_ulpi_init()) {
97 			serial_printf("ERROR: %s Could not initialize PHY\n",
98 				__PRETTY_FUNCTION__);
99 			goto end;
100 		}
101 #endif
102 
103 #ifdef CONFIG_TWL6030_POWER
104 		twl6030_usb_device_settings();
105 #endif
106 
107 		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 
121 #ifdef CONFIG_OMAP3_EVM
122 		musb_cfg.extvbus = omap3_evm_need_extvbus();
123 #endif
124 
125 #ifdef CONFIG_OMAP4430
126 		u32 *usbotghs_control =
127 			(u32 *)((*ctrl)->control_usbotghs_ctrl);
128 		*usbotghs_control = 0x15;
129 #endif
130 		platform_needs_initialization = 0;
131 	}
132 
133 	ret = platform_needs_initialization;
134 
135 #ifdef CONFIG_TWL4030_USB
136 end:
137 #endif
138 	return ret;
139 
140 }
141 
142 void musb_platform_deinit(void)
143 {
144 	/* noop */
145 }
146