Lines Matching refs:tu
72 struct tahvo_usb *tu = dev_get_drvdata(device); in vbus_state_show() local
73 return sprintf(buf, "%s\n", tu->vbus_state ? "on" : "off"); in vbus_state_show()
77 static void check_vbus_state(struct tahvo_usb *tu) in check_vbus_state() argument
79 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in check_vbus_state()
84 switch (tu->phy.otg->state) { in check_vbus_state()
87 if (tu->phy.otg->gadget) in check_vbus_state()
88 usb_gadget_vbus_connect(tu->phy.otg->gadget); in check_vbus_state()
89 tu->phy.otg->state = OTG_STATE_B_PERIPHERAL; in check_vbus_state()
90 usb_phy_set_event(&tu->phy, USB_EVENT_ENUMERATED); in check_vbus_state()
97 tu->phy.otg->state = OTG_STATE_A_HOST; in check_vbus_state()
102 dev_info(&tu->pt_dev->dev, "USB cable connected\n"); in check_vbus_state()
104 switch (tu->phy.otg->state) { in check_vbus_state()
106 if (tu->phy.otg->gadget) in check_vbus_state()
107 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in check_vbus_state()
108 tu->phy.otg->state = OTG_STATE_B_IDLE; in check_vbus_state()
109 usb_phy_set_event(&tu->phy, USB_EVENT_NONE); in check_vbus_state()
112 tu->phy.otg->state = OTG_STATE_A_IDLE; in check_vbus_state()
117 dev_info(&tu->pt_dev->dev, "USB cable disconnected\n"); in check_vbus_state()
120 prev_state = tu->vbus_state; in check_vbus_state()
121 tu->vbus_state = reg & TAHVO_STAT_VBUS; in check_vbus_state()
122 if (prev_state != tu->vbus_state) { in check_vbus_state()
123 extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state); in check_vbus_state()
124 sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state"); in check_vbus_state()
128 static void tahvo_usb_become_host(struct tahvo_usb *tu) in tahvo_usb_become_host() argument
130 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_become_host()
132 extcon_set_cable_state(&tu->extcon, "USB-HOST", true); in tahvo_usb_become_host()
137 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_become_host()
139 check_vbus_state(tu); in tahvo_usb_become_host()
142 static void tahvo_usb_stop_host(struct tahvo_usb *tu) in tahvo_usb_stop_host() argument
144 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_stop_host()
147 static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) in tahvo_usb_become_peripheral() argument
149 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_become_peripheral()
151 extcon_set_cable_state(&tu->extcon, "USB-HOST", false); in tahvo_usb_become_peripheral()
156 tu->phy.otg->state = OTG_STATE_B_IDLE; in tahvo_usb_become_peripheral()
158 check_vbus_state(tu); in tahvo_usb_become_peripheral()
161 static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu) in tahvo_usb_stop_peripheral() argument
163 if (tu->phy.otg->gadget) in tahvo_usb_stop_peripheral()
164 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in tahvo_usb_stop_peripheral()
165 tu->phy.otg->state = OTG_STATE_B_IDLE; in tahvo_usb_stop_peripheral()
168 static void tahvo_usb_power_off(struct tahvo_usb *tu) in tahvo_usb_power_off() argument
170 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_power_off()
173 if (tu->phy.otg->gadget) in tahvo_usb_power_off()
174 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in tahvo_usb_power_off()
178 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_power_off()
183 struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, phy); in tahvo_usb_set_suspend() local
184 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_set_suspend()
187 dev_dbg(&tu->pt_dev->dev, "%s\n", __func__); in tahvo_usb_set_suspend()
201 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_host() local
204 dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, host); in tahvo_usb_set_host()
206 mutex_lock(&tu->serialize); in tahvo_usb_set_host()
209 if (tu->tahvo_mode == TAHVO_MODE_HOST) in tahvo_usb_set_host()
210 tahvo_usb_power_off(tu); in tahvo_usb_set_host()
212 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
216 if (tu->tahvo_mode == TAHVO_MODE_HOST) { in tahvo_usb_set_host()
218 tahvo_usb_become_host(tu); in tahvo_usb_set_host()
223 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
231 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_peripheral() local
234 dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, gadget); in tahvo_usb_set_peripheral()
236 mutex_lock(&tu->serialize); in tahvo_usb_set_peripheral()
239 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
240 tahvo_usb_power_off(tu); in tahvo_usb_set_peripheral()
241 tu->phy.otg->gadget = NULL; in tahvo_usb_set_peripheral()
242 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
246 tu->phy.otg->gadget = gadget; in tahvo_usb_set_peripheral()
247 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
248 tahvo_usb_become_peripheral(tu); in tahvo_usb_set_peripheral()
250 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
257 struct tahvo_usb *tu = _tu; in tahvo_usb_vbus_interrupt() local
259 mutex_lock(&tu->serialize); in tahvo_usb_vbus_interrupt()
260 check_vbus_state(tu); in tahvo_usb_vbus_interrupt()
261 mutex_unlock(&tu->serialize); in tahvo_usb_vbus_interrupt()
269 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_show() local
271 switch (tu->tahvo_mode) { in otg_mode_show()
285 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_store() local
288 mutex_lock(&tu->serialize); in otg_mode_store()
290 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in otg_mode_store()
291 tahvo_usb_stop_peripheral(tu); in otg_mode_store()
292 tu->tahvo_mode = TAHVO_MODE_HOST; in otg_mode_store()
293 if (tu->phy.otg->host) { in otg_mode_store()
295 tahvo_usb_become_host(tu); in otg_mode_store()
298 tahvo_usb_power_off(tu); in otg_mode_store()
302 if (tu->tahvo_mode == TAHVO_MODE_HOST) in otg_mode_store()
303 tahvo_usb_stop_host(tu); in otg_mode_store()
304 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in otg_mode_store()
305 if (tu->phy.otg->gadget) { in otg_mode_store()
307 tahvo_usb_become_peripheral(tu); in otg_mode_store()
310 tahvo_usb_power_off(tu); in otg_mode_store()
316 mutex_unlock(&tu->serialize); in otg_mode_store()
335 struct tahvo_usb *tu; in tahvo_usb_probe() local
338 tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); in tahvo_usb_probe()
339 if (!tu) in tahvo_usb_probe()
342 tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), in tahvo_usb_probe()
344 if (!tu->phy.otg) in tahvo_usb_probe()
347 tu->pt_dev = pdev; in tahvo_usb_probe()
351 tu->tahvo_mode = TAHVO_MODE_HOST; in tahvo_usb_probe()
353 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in tahvo_usb_probe()
356 mutex_init(&tu->serialize); in tahvo_usb_probe()
358 tu->ick = devm_clk_get(&pdev->dev, "usb_l4_ick"); in tahvo_usb_probe()
359 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
360 clk_enable(tu->ick); in tahvo_usb_probe()
365 tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS; in tahvo_usb_probe()
367 tu->extcon.name = DRIVER_NAME; in tahvo_usb_probe()
368 tu->extcon.supported_cable = tahvo_cable; in tahvo_usb_probe()
369 tu->extcon.dev.parent = &pdev->dev; in tahvo_usb_probe()
371 ret = extcon_dev_register(&tu->extcon); in tahvo_usb_probe()
379 extcon_set_cable_state(&tu->extcon, "USB-HOST", in tahvo_usb_probe()
380 tu->tahvo_mode == TAHVO_MODE_HOST); in tahvo_usb_probe()
381 extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state); in tahvo_usb_probe()
384 tahvo_usb_power_off(tu); in tahvo_usb_probe()
385 tu->phy.dev = &pdev->dev; in tahvo_usb_probe()
386 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_probe()
387 tu->phy.label = DRIVER_NAME; in tahvo_usb_probe()
388 tu->phy.set_suspend = tahvo_usb_set_suspend; in tahvo_usb_probe()
390 tu->phy.otg->usb_phy = &tu->phy; in tahvo_usb_probe()
391 tu->phy.otg->set_host = tahvo_usb_set_host; in tahvo_usb_probe()
392 tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; in tahvo_usb_probe()
394 ret = usb_add_phy(&tu->phy, USB_PHY_TYPE_USB2); in tahvo_usb_probe()
401 dev_set_drvdata(&pdev->dev, tu); in tahvo_usb_probe()
403 tu->irq = platform_get_irq(pdev, 0); in tahvo_usb_probe()
404 ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt, in tahvo_usb_probe()
406 "tahvo-vbus", tu); in tahvo_usb_probe()
423 free_irq(tu->irq, tu); in tahvo_usb_probe()
425 usb_remove_phy(&tu->phy); in tahvo_usb_probe()
427 extcon_dev_unregister(&tu->extcon); in tahvo_usb_probe()
429 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
430 clk_disable(tu->ick); in tahvo_usb_probe()
437 struct tahvo_usb *tu = platform_get_drvdata(pdev); in tahvo_usb_remove() local
440 free_irq(tu->irq, tu); in tahvo_usb_remove()
441 usb_remove_phy(&tu->phy); in tahvo_usb_remove()
442 extcon_dev_unregister(&tu->extcon); in tahvo_usb_remove()
443 if (!IS_ERR(tu->ick)) in tahvo_usb_remove()
444 clk_disable(tu->ick); in tahvo_usb_remove()