Lines Matching +full:role +full:- +full:switch +full:- +full:default +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0
3 * dwc3-rtk.c - Realtek DWC3 Specific Glue layer
19 #include <linux/usb/role.h>
65 static void switch_usb2_role(struct dwc3_rtk *rtk, enum usb_role role) in switch_usb2_role() argument
70 reg = rtk->regs + WRAP_USB2_PHY_REG; in switch_usb2_role()
73 switch (role) { in switch_usb2_role()
80 default: in switch_usb2_role()
81 dev_dbg(rtk->dev, "%s: role=%d\n", __func__, role); in switch_usb2_role()
86 static void switch_dwc3_role(struct dwc3_rtk *rtk, enum usb_role role) in switch_dwc3_role() argument
88 if (!rtk->dwc->role_sw) in switch_dwc3_role()
91 usb_role_switch_set_role(rtk->dwc->role_sw, role); in switch_dwc3_role()
96 enum usb_role role; in dwc3_rtk_get_role() local
98 role = rtk->cur_role; in dwc3_rtk_get_role()
100 if (rtk->dwc && rtk->dwc->role_sw) in dwc3_rtk_get_role()
101 role = usb_role_switch_get_role(rtk->dwc->role_sw); in dwc3_rtk_get_role()
103 dev_dbg(rtk->dev, "%s not usb_role_switch role=%d\n", __func__, role); in dwc3_rtk_get_role()
105 return role; in dwc3_rtk_get_role()
108 static void dwc3_rtk_set_role(struct dwc3_rtk *rtk, enum usb_role role) in dwc3_rtk_set_role() argument
110 rtk->cur_role = role; in dwc3_rtk_set_role()
112 switch_dwc3_role(rtk, role); in dwc3_rtk_set_role()
114 switch_usb2_role(rtk, role); in dwc3_rtk_set_role()
118 static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role role) in dwc3_usb_role_switch_set() argument
122 dwc3_rtk_set_role(rtk, role); in dwc3_usb_role_switch_set()
138 dwc3_role_switch.name = dev_name(rtk->dev); in dwc3_rtk_setup_role_switch()
141 dwc3_role_switch.fwnode = dev_fwnode(rtk->dev); in dwc3_rtk_setup_role_switch()
144 rtk->role_switch = usb_role_switch_register(rtk->dev, &dwc3_role_switch); in dwc3_rtk_setup_role_switch()
145 if (IS_ERR(rtk->role_switch)) in dwc3_rtk_setup_role_switch()
146 return PTR_ERR(rtk->role_switch); in dwc3_rtk_setup_role_switch()
153 if (rtk->role_switch) in dwc3_rtk_remove_role_switch()
154 usb_role_switch_unregister(rtk->role_switch); in dwc3_rtk_remove_role_switch()
156 rtk->role_switch = NULL; in dwc3_rtk_remove_role_switch()
167 [USB_SPEED_LOW] = "low-speed",
168 [USB_SPEED_FULL] = "full-speed",
169 [USB_SPEED_HIGH] = "high-speed",
171 [USB_SPEED_SUPER] = "super-speed",
172 [USB_SPEED_SUPER_PLUS] = "super-speed-plus",
185 ret = of_property_read_string(dwc3_np, "maximum-speed", &maximum_speed); in __get_dwc3_maximum_speed()
196 struct device *dev = rtk->dev; in dwc3_rtk_init()
209 reg = rtk->regs + WRAP_CTR_REG; in dwc3_rtk_init()
212 dev_info(dev, "[bug fixed] 1295/1296 A00: add workaround to disable multiple request for D-Bus"); in dwc3_rtk_init()
216 reg = rtk->regs + WRAP_USB2_PHY_REG; in dwc3_rtk_init()
222 reg = rtk->regs + WRAP_USB2_PHY_UTMI_REG; in dwc3_rtk_init()
226 maximum_speed = __get_dwc3_maximum_speed(dev->of_node); in dwc3_rtk_init()
229 reg = rtk->regs + WRAP_USB_HMAC_CTR0_REG; in dwc3_rtk_init()
233 reg = rtk->regs + WRAP_CTR_REG; in dwc3_rtk_init()
237 reg = rtk->regs + WRAP_PHY_PIPE_REG; in dwc3_rtk_init()
241 reg = rtk->regs + WRAP_USB_HMAC_CTR0_REG; in dwc3_rtk_init()
245 reg = rtk->regs + WRAP_APHY_REG; in dwc3_rtk_init()
249 dev_dbg(rtk->dev, "%s: disable usb 3.0 phy\n", __func__); in dwc3_rtk_init()
253 reg = rtk->regs + WRAP_CTR_REG; in dwc3_rtk_init()
257 /* Set phy Dp/Dm initial state to host mode to avoid the Dp glitch */ in dwc3_rtk_init()
258 reg = rtk->regs + WRAP_USB2_PHY_REG; in dwc3_rtk_init()
262 if (rtk->pm_base) { in dwc3_rtk_init()
263 reg = rtk->pm_base + USB_DBUS_PWR_CTRL_REG; in dwc3_rtk_init()
273 struct device *dev = rtk->dev; in dwc3_rtk_probe_dwc3_core()
274 struct device_node *node = dev->of_node; in dwc3_rtk_probe_dwc3_core()
282 return -EINVAL; in dwc3_rtk_probe_dwc3_core()
294 ret = -ENODEV; in dwc3_rtk_probe_dwc3_core()
301 ret = -ENODEV; in dwc3_rtk_probe_dwc3_core()
305 dwc3_dev = &dwc3_pdev->dev; in dwc3_rtk_probe_dwc3_core()
306 rtk->dwc = platform_get_drvdata(dwc3_pdev); in dwc3_rtk_probe_dwc3_core()
307 if (!rtk->dwc) { in dwc3_rtk_probe_dwc3_core()
309 ret = -ENODEV; in dwc3_rtk_probe_dwc3_core()
314 if (dr_mode != rtk->dwc->dr_mode) { in dwc3_rtk_probe_dwc3_core()
316 dr_mode, rtk->dwc->dr_mode); in dwc3_rtk_probe_dwc3_core()
317 dr_mode = rtk->dwc->dr_mode; in dwc3_rtk_probe_dwc3_core()
320 switch (dr_mode) { in dwc3_rtk_probe_dwc3_core()
322 rtk->cur_role = USB_ROLE_DEVICE; in dwc3_rtk_probe_dwc3_core()
325 rtk->cur_role = USB_ROLE_HOST; in dwc3_rtk_probe_dwc3_core()
327 default: in dwc3_rtk_probe_dwc3_core()
328 dev_dbg(rtk->dev, "%s: dr_mode=%d\n", __func__, dr_mode); in dwc3_rtk_probe_dwc3_core()
332 if (device_property_read_bool(dwc3_dev, "usb-role-switch")) { in dwc3_rtk_probe_dwc3_core()
338 rtk->cur_role = dwc3_rtk_get_role(rtk); in dwc3_rtk_probe_dwc3_core()
341 switch_usb2_role(rtk, rtk->cur_role); in dwc3_rtk_probe_dwc3_core()
358 struct device *dev = &pdev->dev; in dwc3_rtk_probe()
364 return -ENOMEM; in dwc3_rtk_probe()
368 rtk->dev = dev; in dwc3_rtk_probe()
374 rtk->regs = regs; in dwc3_rtk_probe()
375 rtk->regs_size = resource_size(res); in dwc3_rtk_probe()
379 rtk->pm_base = devm_ioremap_resource(dev, res); in dwc3_rtk_probe()
380 if (IS_ERR(rtk->pm_base)) in dwc3_rtk_probe()
381 return PTR_ERR(rtk->pm_base); in dwc3_rtk_probe()
391 rtk->dwc = NULL; in dwc3_rtk_remove()
395 of_platform_depopulate(rtk->dev); in dwc3_rtk_remove()
402 of_platform_depopulate(rtk->dev); in dwc3_rtk_shutdown()
406 { .compatible = "realtek,rtd-dwc3" },
423 switch_usb2_role(rtk, rtk->cur_role); in dwc3_rtk_resume()
446 .name = "rtk-dwc3",
457 MODULE_ALIAS("platform:rtk-dwc3");