Skip to content

Commit ba785ed

Browse files
committed
i9300: USB support
1 parent b121afc commit ba785ed

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

board/samsung/i9300/i9300.c

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
*
55
* SPDX-License-Identifier: GPL-2.0+
66
*/
7-
87
#include <common.h>
98
#include <asm/gpio.h>
109
#include <asm/arch/gpio.h>
10+
#include <extcon.h>
11+
#include <power/max77686_pmic.h>
12+
#include <power/max77693_muic.h>
13+
#include <power/pmic.h>
14+
#include <power/regulator.h>
15+
#include <usb.h>
16+
#include <usb/dwc2_udc.h>
1117

1218
DECLARE_GLOBAL_DATA_PTR;
1319

@@ -25,6 +31,108 @@ static void board_gpio_init(void)
2531
gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE);
2632
}
2733

34+
static int i9300_phy_control(int on)
35+
{
36+
int ret;
37+
int type;
38+
struct udevice *vuotg;
39+
struct udevice *safeout;
40+
struct udevice *extcon;
41+
struct udevice *pmic;
42+
43+
ret = regulator_get_by_platname("VUOTG_3.0V", &vuotg);
44+
if (ret) {
45+
pr_err("Failed to get VUOTG_3.0V: %d\n", ret);
46+
return -1;
47+
}
48+
49+
ret = regulator_get_by_platname("ESAFEOUT1", &safeout);
50+
if (ret) {
51+
pr_err("Failed to get ESAFEOUT1: %d\n", ret);
52+
return -1;
53+
}
54+
55+
ret = extcon_get("muic-max77693", &extcon);
56+
if (ret) {
57+
pr_err("Failed to get max77693 extcon: %d\n", ret);
58+
return -1;
59+
}
60+
61+
ret = pmic_get("max77693_muic@25", &pmic);
62+
if (ret) {
63+
pr_err("Failed to get MUIC PMIC: %d!\n", ret);
64+
return -1;
65+
}
66+
67+
pr_info("Waiting 10 seconds for USB to be inserted...\n");
68+
int i = 0;
69+
do {
70+
extcon_get_cable_id(extcon, &type);
71+
if (type & EXTCON_TYPE_USB)
72+
break;
73+
mdelay(1000);
74+
} while (i++ < 10);
75+
76+
if (!(type & EXTCON_TYPE_USB)) {
77+
pr_info("No USB cable detected, aborting!\n");
78+
return -1;
79+
}
80+
81+
if (on) {
82+
ret = regulator_set_mode(vuotg, OPMODE_ON);
83+
if (ret) {
84+
pr_err("Failed to set VUOTG_3.0V to ON: %d\n", ret);
85+
return -1;
86+
}
87+
88+
ret = regulator_set_enable(safeout, true);
89+
if (ret) {
90+
pr_err("Failed to enable ESAFEOUT1: %d\n", ret);
91+
return -1;
92+
}
93+
94+
/* set MUIC path to USB */
95+
ret = pmic_reg_write(pmic, MAX77693_MUIC_CONTROL1,
96+
MAX77693_MUIC_CTRL1_DN1DP2);
97+
if (ret) {
98+
pr_err("Failed to set MUIC path to USB: %d\n", ret);
99+
return -1;
100+
}
101+
} else {
102+
ret = regulator_set_mode(vuotg, OPMODE_LPM);
103+
if (ret) {
104+
pr_err("Failed to set VUOTG_3.0V to LPM: %d\n", ret);
105+
return -1;
106+
}
107+
108+
/* set MUIC path to UART */
109+
ret = pmic_reg_write(pmic, MAX77693_MUIC_CONTROL1,
110+
MAX77693_MUIC_CTRL1_UT1UR2);
111+
if (ret) {
112+
pr_err("Failed to set MUIC path to UART: %d\n", ret);
113+
return -1;
114+
}
115+
116+
}
117+
118+
119+
return 0;
120+
}
121+
122+
struct dwc2_plat_otg_data exynos4_otg_data = {
123+
.phy_control = i9300_phy_control,
124+
.regs_phy = EXYNOS4X12_USBPHY_BASE,
125+
.regs_otg = EXYNOS4X12_USBOTG_BASE,
126+
.usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL,
127+
.usb_flags = PHY0_SLEEP,
128+
};
129+
130+
int board_usb_init(int index, enum usb_init_type init)
131+
{
132+
pr_info("Board usb init! %d %d\n", index, init);
133+
return dwc2_udc_probe(&exynos4_otg_data);
134+
}
135+
28136
int exynos_init(void)
29137
{
30138
board_gpio_init();

0 commit comments

Comments
 (0)