Lines Matching refs:tu
73 struct tahvo_usb *tu = dev_get_drvdata(device); in vbus_state_show() local
74 return sprintf(buf, "%s\n", tu->vbus_state ? "on" : "off"); in vbus_state_show()
78 static void check_vbus_state(struct tahvo_usb *tu) in check_vbus_state() argument
80 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in check_vbus_state()
85 switch (tu->phy.otg->state) { in check_vbus_state()
88 if (tu->phy.otg->gadget) in check_vbus_state()
89 usb_gadget_vbus_connect(tu->phy.otg->gadget); in check_vbus_state()
90 tu->phy.otg->state = OTG_STATE_B_PERIPHERAL; in check_vbus_state()
91 usb_phy_set_event(&tu->phy, USB_EVENT_ENUMERATED); in check_vbus_state()
98 tu->phy.otg->state = OTG_STATE_A_HOST; in check_vbus_state()
103 dev_info(&tu->pt_dev->dev, "USB cable connected\n"); in check_vbus_state()
105 switch (tu->phy.otg->state) { in check_vbus_state()
107 if (tu->phy.otg->gadget) in check_vbus_state()
108 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in check_vbus_state()
109 tu->phy.otg->state = OTG_STATE_B_IDLE; in check_vbus_state()
110 usb_phy_set_event(&tu->phy, USB_EVENT_NONE); in check_vbus_state()
113 tu->phy.otg->state = OTG_STATE_A_IDLE; in check_vbus_state()
118 dev_info(&tu->pt_dev->dev, "USB cable disconnected\n"); in check_vbus_state()
121 prev_state = tu->vbus_state; in check_vbus_state()
122 tu->vbus_state = reg & TAHVO_STAT_VBUS; in check_vbus_state()
123 if (prev_state != tu->vbus_state) { in check_vbus_state()
124 extcon_set_cable_state_(tu->extcon, EXTCON_USB, tu->vbus_state); in check_vbus_state()
125 sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state"); in check_vbus_state()
129 static void tahvo_usb_become_host(struct tahvo_usb *tu) in tahvo_usb_become_host() argument
131 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_become_host()
133 extcon_set_cable_state_(tu->extcon, EXTCON_USB_HOST, true); in tahvo_usb_become_host()
138 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_become_host()
140 check_vbus_state(tu); in tahvo_usb_become_host()
143 static void tahvo_usb_stop_host(struct tahvo_usb *tu) in tahvo_usb_stop_host() argument
145 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_stop_host()
148 static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) in tahvo_usb_become_peripheral() argument
150 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_become_peripheral()
152 extcon_set_cable_state_(tu->extcon, EXTCON_USB_HOST, false); in tahvo_usb_become_peripheral()
157 tu->phy.otg->state = OTG_STATE_B_IDLE; in tahvo_usb_become_peripheral()
159 check_vbus_state(tu); in tahvo_usb_become_peripheral()
162 static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu) in tahvo_usb_stop_peripheral() argument
164 if (tu->phy.otg->gadget) in tahvo_usb_stop_peripheral()
165 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in tahvo_usb_stop_peripheral()
166 tu->phy.otg->state = OTG_STATE_B_IDLE; in tahvo_usb_stop_peripheral()
169 static void tahvo_usb_power_off(struct tahvo_usb *tu) in tahvo_usb_power_off() argument
171 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_power_off()
174 if (tu->phy.otg->gadget) in tahvo_usb_power_off()
175 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in tahvo_usb_power_off()
179 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_power_off()
184 struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, phy); in tahvo_usb_set_suspend() local
185 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_set_suspend()
188 dev_dbg(&tu->pt_dev->dev, "%s\n", __func__); in tahvo_usb_set_suspend()
202 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_host() local
205 dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, host); in tahvo_usb_set_host()
207 mutex_lock(&tu->serialize); in tahvo_usb_set_host()
210 if (tu->tahvo_mode == TAHVO_MODE_HOST) in tahvo_usb_set_host()
211 tahvo_usb_power_off(tu); in tahvo_usb_set_host()
213 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
217 if (tu->tahvo_mode == TAHVO_MODE_HOST) { in tahvo_usb_set_host()
219 tahvo_usb_become_host(tu); in tahvo_usb_set_host()
224 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
232 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_peripheral() local
235 dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, gadget); in tahvo_usb_set_peripheral()
237 mutex_lock(&tu->serialize); in tahvo_usb_set_peripheral()
240 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
241 tahvo_usb_power_off(tu); in tahvo_usb_set_peripheral()
242 tu->phy.otg->gadget = NULL; in tahvo_usb_set_peripheral()
243 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
247 tu->phy.otg->gadget = gadget; in tahvo_usb_set_peripheral()
248 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
249 tahvo_usb_become_peripheral(tu); in tahvo_usb_set_peripheral()
251 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
258 struct tahvo_usb *tu = _tu; in tahvo_usb_vbus_interrupt() local
260 mutex_lock(&tu->serialize); in tahvo_usb_vbus_interrupt()
261 check_vbus_state(tu); in tahvo_usb_vbus_interrupt()
262 mutex_unlock(&tu->serialize); in tahvo_usb_vbus_interrupt()
270 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_show() local
272 switch (tu->tahvo_mode) { in otg_mode_show()
286 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_store() local
289 mutex_lock(&tu->serialize); in otg_mode_store()
291 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in otg_mode_store()
292 tahvo_usb_stop_peripheral(tu); in otg_mode_store()
293 tu->tahvo_mode = TAHVO_MODE_HOST; in otg_mode_store()
294 if (tu->phy.otg->host) { in otg_mode_store()
296 tahvo_usb_become_host(tu); in otg_mode_store()
299 tahvo_usb_power_off(tu); in otg_mode_store()
303 if (tu->tahvo_mode == TAHVO_MODE_HOST) in otg_mode_store()
304 tahvo_usb_stop_host(tu); in otg_mode_store()
305 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in otg_mode_store()
306 if (tu->phy.otg->gadget) { in otg_mode_store()
308 tahvo_usb_become_peripheral(tu); in otg_mode_store()
311 tahvo_usb_power_off(tu); in otg_mode_store()
317 mutex_unlock(&tu->serialize); in otg_mode_store()
336 struct tahvo_usb *tu; in tahvo_usb_probe() local
339 tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); in tahvo_usb_probe()
340 if (!tu) in tahvo_usb_probe()
343 tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), in tahvo_usb_probe()
345 if (!tu->phy.otg) in tahvo_usb_probe()
348 tu->pt_dev = pdev; in tahvo_usb_probe()
352 tu->tahvo_mode = TAHVO_MODE_HOST; in tahvo_usb_probe()
354 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in tahvo_usb_probe()
357 mutex_init(&tu->serialize); in tahvo_usb_probe()
359 tu->ick = devm_clk_get(&pdev->dev, "usb_l4_ick"); in tahvo_usb_probe()
360 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
361 clk_enable(tu->ick); in tahvo_usb_probe()
366 tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS; in tahvo_usb_probe()
368 tu->extcon = devm_extcon_dev_allocate(&pdev->dev, tahvo_cable); in tahvo_usb_probe()
369 if (IS_ERR(tu->extcon)) { in tahvo_usb_probe()
374 ret = devm_extcon_dev_register(&pdev->dev, tu->extcon); in tahvo_usb_probe()
382 extcon_set_cable_state_(tu->extcon, EXTCON_USB_HOST, in tahvo_usb_probe()
383 tu->tahvo_mode == TAHVO_MODE_HOST); in tahvo_usb_probe()
384 extcon_set_cable_state_(tu->extcon, EXTCON_USB, tu->vbus_state); in tahvo_usb_probe()
387 tahvo_usb_power_off(tu); in tahvo_usb_probe()
388 tu->phy.dev = &pdev->dev; in tahvo_usb_probe()
389 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_probe()
390 tu->phy.label = DRIVER_NAME; in tahvo_usb_probe()
391 tu->phy.set_suspend = tahvo_usb_set_suspend; in tahvo_usb_probe()
393 tu->phy.otg->usb_phy = &tu->phy; in tahvo_usb_probe()
394 tu->phy.otg->set_host = tahvo_usb_set_host; in tahvo_usb_probe()
395 tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; in tahvo_usb_probe()
397 ret = usb_add_phy(&tu->phy, USB_PHY_TYPE_USB2); in tahvo_usb_probe()
404 dev_set_drvdata(&pdev->dev, tu); in tahvo_usb_probe()
406 tu->irq = platform_get_irq(pdev, 0); in tahvo_usb_probe()
407 ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt, in tahvo_usb_probe()
409 "tahvo-vbus", tu); in tahvo_usb_probe()
426 free_irq(tu->irq, tu); in tahvo_usb_probe()
428 usb_remove_phy(&tu->phy); in tahvo_usb_probe()
430 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
431 clk_disable(tu->ick); in tahvo_usb_probe()
438 struct tahvo_usb *tu = platform_get_drvdata(pdev); in tahvo_usb_remove() local
441 free_irq(tu->irq, tu); in tahvo_usb_remove()
442 usb_remove_phy(&tu->phy); in tahvo_usb_remove()
443 if (!IS_ERR(tu->ick)) in tahvo_usb_remove()
444 clk_disable(tu->ick); in tahvo_usb_remove()