Lines Matching refs:hsotg
20 static void dwc2_ovr_init(struct dwc2_hsotg *hsotg) in dwc2_ovr_init() argument
25 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_ovr_init()
27 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_ovr_init()
30 if (hsotg->role_sw_default_mode == USB_DR_MODE_HOST) in dwc2_ovr_init()
32 else if (hsotg->role_sw_default_mode == USB_DR_MODE_PERIPHERAL) in dwc2_ovr_init()
34 dwc2_writel(hsotg, gotgctl, GOTGCTL); in dwc2_ovr_init()
36 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_ovr_init()
38 dwc2_force_mode(hsotg, (hsotg->dr_mode == USB_DR_MODE_HOST)); in dwc2_ovr_init()
41 static int dwc2_ovr_avalid(struct dwc2_hsotg *hsotg, bool valid) in dwc2_ovr_avalid() argument
43 u32 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_ovr_avalid()
58 dwc2_writel(hsotg, gotgctl, GOTGCTL); in dwc2_ovr_avalid()
63 static int dwc2_ovr_bvalid(struct dwc2_hsotg *hsotg, bool valid) in dwc2_ovr_bvalid() argument
65 u32 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_ovr_bvalid()
80 dwc2_writel(hsotg, gotgctl, GOTGCTL); in dwc2_ovr_bvalid()
87 struct dwc2_hsotg *hsotg = usb_role_switch_get_drvdata(sw); in dwc2_drd_role_sw_set() local
92 if ((role == USB_ROLE_DEVICE && hsotg->dr_mode == USB_DR_MODE_HOST) || in dwc2_drd_role_sw_set()
93 (role == USB_ROLE_HOST && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)) in dwc2_drd_role_sw_set()
99 if (role == USB_ROLE_NONE && hsotg->test_mode) { in dwc2_drd_role_sw_set()
100 dev_dbg(hsotg->dev, "Core is in test mode\n"); in dwc2_drd_role_sw_set()
112 if (!hsotg->ll_hw_enabled && hsotg->clk) { in dwc2_drd_role_sw_set()
113 int ret = clk_prepare_enable(hsotg->clk); in dwc2_drd_role_sw_set()
119 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_drd_role_sw_set()
123 if (hsotg->role_sw_default_mode == USB_DR_MODE_HOST) in dwc2_drd_role_sw_set()
125 else if (hsotg->role_sw_default_mode == USB_DR_MODE_PERIPHERAL) in dwc2_drd_role_sw_set()
130 already = dwc2_ovr_avalid(hsotg, true); in dwc2_drd_role_sw_set()
132 already = dwc2_ovr_bvalid(hsotg, true); in dwc2_drd_role_sw_set()
133 if (dwc2_is_device_enabled(hsotg)) { in dwc2_drd_role_sw_set()
135 dwc2_hsotg_core_connect(hsotg); in dwc2_drd_role_sw_set()
138 if (dwc2_is_device_mode(hsotg)) { in dwc2_drd_role_sw_set()
139 if (!dwc2_ovr_bvalid(hsotg, false)) in dwc2_drd_role_sw_set()
141 dwc2_hsotg_core_disconnect(hsotg); in dwc2_drd_role_sw_set()
143 dwc2_ovr_avalid(hsotg, false); in dwc2_drd_role_sw_set()
147 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_drd_role_sw_set()
149 if (!already && hsotg->dr_mode == USB_DR_MODE_OTG) in dwc2_drd_role_sw_set()
151 dwc2_force_mode(hsotg, role == USB_ROLE_HOST); in dwc2_drd_role_sw_set()
153 if (!hsotg->ll_hw_enabled && hsotg->clk) in dwc2_drd_role_sw_set()
154 clk_disable_unprepare(hsotg->clk); in dwc2_drd_role_sw_set()
156 dev_dbg(hsotg->dev, "%s-session valid\n", in dwc2_drd_role_sw_set()
163 int dwc2_drd_init(struct dwc2_hsotg *hsotg) in dwc2_drd_init() argument
169 if (!device_property_read_bool(hsotg->dev, "usb-role-switch")) in dwc2_drd_init()
172 hsotg->role_sw_default_mode = usb_get_role_switch_default_mode(hsotg->dev); in dwc2_drd_init()
173 role_sw_desc.driver_data = hsotg; in dwc2_drd_init()
174 role_sw_desc.fwnode = dev_fwnode(hsotg->dev); in dwc2_drd_init()
178 role_sw = usb_role_switch_register(hsotg->dev, &role_sw_desc); in dwc2_drd_init()
181 dev_err(hsotg->dev, in dwc2_drd_init()
186 hsotg->role_sw = role_sw; in dwc2_drd_init()
189 dwc2_ovr_init(hsotg); in dwc2_drd_init()
194 void dwc2_drd_suspend(struct dwc2_hsotg *hsotg) in dwc2_drd_suspend() argument
198 if (hsotg->role_sw && !hsotg->params.external_id_pin_ctl) { in dwc2_drd_suspend()
199 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_drd_suspend()
201 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_drd_suspend()
202 gintsts = dwc2_readl(hsotg, GINTSTS); in dwc2_drd_suspend()
203 dwc2_writel(hsotg, gintsts | GINTSTS_CONIDSTSCHNG, GINTSTS); in dwc2_drd_suspend()
207 void dwc2_drd_resume(struct dwc2_hsotg *hsotg) in dwc2_drd_resume() argument
212 if (hsotg->role_sw) { in dwc2_drd_resume()
214 role = usb_role_switch_get_role(hsotg->role_sw); in dwc2_drd_resume()
217 if (hsotg->role_sw_default_mode == USB_DR_MODE_HOST) in dwc2_drd_resume()
219 else if (hsotg->role_sw_default_mode == USB_DR_MODE_PERIPHERAL) in dwc2_drd_resume()
225 dwc2_ovr_avalid(hsotg, true); in dwc2_drd_resume()
227 dwc2_ovr_bvalid(hsotg, true); in dwc2_drd_resume()
229 dwc2_force_mode(hsotg, role == USB_ROLE_HOST); in dwc2_drd_resume()
231 dev_dbg(hsotg->dev, "resuming %s-session valid\n", in dwc2_drd_resume()
236 if (hsotg->role_sw && !hsotg->params.external_id_pin_ctl) { in dwc2_drd_resume()
237 gintsts = dwc2_readl(hsotg, GINTSTS); in dwc2_drd_resume()
238 dwc2_writel(hsotg, gintsts | GINTSTS_CONIDSTSCHNG, GINTSTS); in dwc2_drd_resume()
239 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_drd_resume()
241 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_drd_resume()
245 void dwc2_drd_exit(struct dwc2_hsotg *hsotg) in dwc2_drd_exit() argument
247 if (hsotg->role_sw) in dwc2_drd_exit()
248 usb_role_switch_unregister(hsotg->role_sw); in dwc2_drd_exit()