Lines Matching refs:tu
65 struct tahvo_usb *tu = dev_get_drvdata(device); in vbus_show() local
66 return sprintf(buf, "%s\n", tu->vbus_state ? "on" : "off"); in vbus_show()
70 static void check_vbus_state(struct tahvo_usb *tu) in check_vbus_state() argument
72 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in check_vbus_state()
77 switch (tu->phy.otg->state) { in check_vbus_state()
80 if (tu->phy.otg->gadget) in check_vbus_state()
81 usb_gadget_vbus_connect(tu->phy.otg->gadget); in check_vbus_state()
82 tu->phy.otg->state = OTG_STATE_B_PERIPHERAL; in check_vbus_state()
83 usb_phy_set_event(&tu->phy, USB_EVENT_ENUMERATED); in check_vbus_state()
90 tu->phy.otg->state = OTG_STATE_A_HOST; in check_vbus_state()
95 dev_info(&tu->pt_dev->dev, "USB cable connected\n"); in check_vbus_state()
97 switch (tu->phy.otg->state) { in check_vbus_state()
99 if (tu->phy.otg->gadget) in check_vbus_state()
100 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in check_vbus_state()
101 tu->phy.otg->state = OTG_STATE_B_IDLE; in check_vbus_state()
102 usb_phy_set_event(&tu->phy, USB_EVENT_NONE); in check_vbus_state()
105 tu->phy.otg->state = OTG_STATE_A_IDLE; in check_vbus_state()
110 dev_info(&tu->pt_dev->dev, "USB cable disconnected\n"); in check_vbus_state()
113 prev_state = tu->vbus_state; in check_vbus_state()
114 tu->vbus_state = reg & TAHVO_STAT_VBUS; in check_vbus_state()
115 if (prev_state != tu->vbus_state) { in check_vbus_state()
116 extcon_set_state_sync(tu->extcon, EXTCON_USB, tu->vbus_state); in check_vbus_state()
117 sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state"); in check_vbus_state()
121 static void tahvo_usb_become_host(struct tahvo_usb *tu) in tahvo_usb_become_host() argument
123 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_become_host()
125 extcon_set_state_sync(tu->extcon, EXTCON_USB_HOST, true); in tahvo_usb_become_host()
130 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_become_host()
132 check_vbus_state(tu); in tahvo_usb_become_host()
135 static void tahvo_usb_stop_host(struct tahvo_usb *tu) in tahvo_usb_stop_host() argument
137 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_stop_host()
140 static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) in tahvo_usb_become_peripheral() argument
142 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_become_peripheral()
144 extcon_set_state_sync(tu->extcon, EXTCON_USB_HOST, false); in tahvo_usb_become_peripheral()
149 tu->phy.otg->state = OTG_STATE_B_IDLE; in tahvo_usb_become_peripheral()
151 check_vbus_state(tu); in tahvo_usb_become_peripheral()
154 static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu) in tahvo_usb_stop_peripheral() argument
156 if (tu->phy.otg->gadget) in tahvo_usb_stop_peripheral()
157 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in tahvo_usb_stop_peripheral()
158 tu->phy.otg->state = OTG_STATE_B_IDLE; in tahvo_usb_stop_peripheral()
161 static void tahvo_usb_power_off(struct tahvo_usb *tu) in tahvo_usb_power_off() argument
163 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_power_off()
166 if (tu->phy.otg->gadget) in tahvo_usb_power_off()
167 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in tahvo_usb_power_off()
171 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_power_off()
176 struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, phy); in tahvo_usb_set_suspend() local
177 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_set_suspend()
180 dev_dbg(&tu->pt_dev->dev, "%s\n", __func__); in tahvo_usb_set_suspend()
194 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_host() local
197 mutex_lock(&tu->serialize); in tahvo_usb_set_host()
200 if (tu->tahvo_mode == TAHVO_MODE_HOST) in tahvo_usb_set_host()
201 tahvo_usb_power_off(tu); in tahvo_usb_set_host()
203 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
207 if (tu->tahvo_mode == TAHVO_MODE_HOST) { in tahvo_usb_set_host()
209 tahvo_usb_become_host(tu); in tahvo_usb_set_host()
214 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
222 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_peripheral() local
225 mutex_lock(&tu->serialize); in tahvo_usb_set_peripheral()
228 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
229 tahvo_usb_power_off(tu); in tahvo_usb_set_peripheral()
230 tu->phy.otg->gadget = NULL; in tahvo_usb_set_peripheral()
231 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
235 tu->phy.otg->gadget = gadget; in tahvo_usb_set_peripheral()
236 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
237 tahvo_usb_become_peripheral(tu); in tahvo_usb_set_peripheral()
239 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
246 struct tahvo_usb *tu = _tu; in tahvo_usb_vbus_interrupt() local
248 mutex_lock(&tu->serialize); in tahvo_usb_vbus_interrupt()
249 check_vbus_state(tu); in tahvo_usb_vbus_interrupt()
250 mutex_unlock(&tu->serialize); in tahvo_usb_vbus_interrupt()
258 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_show() local
260 switch (tu->tahvo_mode) { in otg_mode_show()
274 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_store() local
277 mutex_lock(&tu->serialize); in otg_mode_store()
279 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in otg_mode_store()
280 tahvo_usb_stop_peripheral(tu); in otg_mode_store()
281 tu->tahvo_mode = TAHVO_MODE_HOST; in otg_mode_store()
282 if (tu->phy.otg->host) { in otg_mode_store()
284 tahvo_usb_become_host(tu); in otg_mode_store()
287 tahvo_usb_power_off(tu); in otg_mode_store()
291 if (tu->tahvo_mode == TAHVO_MODE_HOST) in otg_mode_store()
292 tahvo_usb_stop_host(tu); in otg_mode_store()
293 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in otg_mode_store()
294 if (tu->phy.otg->gadget) { in otg_mode_store()
296 tahvo_usb_become_peripheral(tu); in otg_mode_store()
299 tahvo_usb_power_off(tu); in otg_mode_store()
305 mutex_unlock(&tu->serialize); in otg_mode_store()
321 struct tahvo_usb *tu; in tahvo_usb_probe() local
324 tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); in tahvo_usb_probe()
325 if (!tu) in tahvo_usb_probe()
328 tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), in tahvo_usb_probe()
330 if (!tu->phy.otg) in tahvo_usb_probe()
333 tu->pt_dev = pdev; in tahvo_usb_probe()
337 tu->tahvo_mode = TAHVO_MODE_HOST; in tahvo_usb_probe()
339 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in tahvo_usb_probe()
342 mutex_init(&tu->serialize); in tahvo_usb_probe()
344 tu->ick = devm_clk_get(&pdev->dev, "usb_l4_ick"); in tahvo_usb_probe()
345 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
346 clk_enable(tu->ick); in tahvo_usb_probe()
351 tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS; in tahvo_usb_probe()
353 tu->extcon = devm_extcon_dev_allocate(&pdev->dev, tahvo_cable); in tahvo_usb_probe()
354 if (IS_ERR(tu->extcon)) { in tahvo_usb_probe()
356 ret = PTR_ERR(tu->extcon); in tahvo_usb_probe()
360 ret = devm_extcon_dev_register(&pdev->dev, tu->extcon); in tahvo_usb_probe()
368 extcon_set_state_sync(tu->extcon, EXTCON_USB_HOST, in tahvo_usb_probe()
369 tu->tahvo_mode == TAHVO_MODE_HOST); in tahvo_usb_probe()
370 extcon_set_state_sync(tu->extcon, EXTCON_USB, tu->vbus_state); in tahvo_usb_probe()
373 tahvo_usb_power_off(tu); in tahvo_usb_probe()
374 tu->phy.dev = &pdev->dev; in tahvo_usb_probe()
375 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_probe()
376 tu->phy.label = DRIVER_NAME; in tahvo_usb_probe()
377 tu->phy.set_suspend = tahvo_usb_set_suspend; in tahvo_usb_probe()
379 tu->phy.otg->usb_phy = &tu->phy; in tahvo_usb_probe()
380 tu->phy.otg->set_host = tahvo_usb_set_host; in tahvo_usb_probe()
381 tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; in tahvo_usb_probe()
383 ret = usb_add_phy(&tu->phy, USB_PHY_TYPE_USB2); in tahvo_usb_probe()
390 dev_set_drvdata(&pdev->dev, tu); in tahvo_usb_probe()
392 tu->irq = ret = platform_get_irq(pdev, 0); in tahvo_usb_probe()
395 ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt, in tahvo_usb_probe()
397 "tahvo-vbus", tu); in tahvo_usb_probe()
407 usb_remove_phy(&tu->phy); in tahvo_usb_probe()
409 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
410 clk_disable(tu->ick); in tahvo_usb_probe()
417 struct tahvo_usb *tu = platform_get_drvdata(pdev); in tahvo_usb_remove() local
419 free_irq(tu->irq, tu); in tahvo_usb_remove()
420 usb_remove_phy(&tu->phy); in tahvo_usb_remove()
421 if (!IS_ERR(tu->ick)) in tahvo_usb_remove()
422 clk_disable(tu->ick); in tahvo_usb_remove()