Lines Matching +full:phy +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2005-2006 Nokia Corporation
18 #include <linux/extcon-provider.h>
27 #define DRIVER_NAME "tahvo-usb"
47 struct usb_phy phy; member
63 static ssize_t vbus_show(struct device *device, in vbus_show() argument
66 struct tahvo_usb *tu = dev_get_drvdata(device); in vbus_show()
67 return sprintf(buf, "%s\n", str_on_off(tu->vbus_state)); in vbus_show()
73 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in check_vbus_state()
78 switch (tu->phy.otg->state) { in check_vbus_state()
81 if (tu->phy.otg->gadget) in check_vbus_state()
82 usb_gadget_vbus_connect(tu->phy.otg->gadget); in check_vbus_state()
83 tu->phy.otg->state = OTG_STATE_B_PERIPHERAL; in check_vbus_state()
84 usb_phy_set_event(&tu->phy, USB_EVENT_ENUMERATED); in check_vbus_state()
91 tu->phy.otg->state = OTG_STATE_A_HOST; in check_vbus_state()
96 dev_info(&tu->pt_dev->dev, "USB cable connected\n"); in check_vbus_state()
98 switch (tu->phy.otg->state) { in check_vbus_state()
100 if (tu->phy.otg->gadget) in check_vbus_state()
101 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in check_vbus_state()
102 tu->phy.otg->state = OTG_STATE_B_IDLE; in check_vbus_state()
103 usb_phy_set_event(&tu->phy, USB_EVENT_NONE); in check_vbus_state()
106 tu->phy.otg->state = OTG_STATE_A_IDLE; in check_vbus_state()
111 dev_info(&tu->pt_dev->dev, "USB cable disconnected\n"); in check_vbus_state()
114 prev_state = tu->vbus_state; in check_vbus_state()
115 tu->vbus_state = reg & TAHVO_STAT_VBUS; in check_vbus_state()
116 if (prev_state != tu->vbus_state) { in check_vbus_state()
117 extcon_set_state_sync(tu->extcon, EXTCON_USB, tu->vbus_state); in check_vbus_state()
118 sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state"); in check_vbus_state()
124 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_become_host()
126 extcon_set_state_sync(tu->extcon, EXTCON_USB_HOST, true); in tahvo_usb_become_host()
131 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_become_host()
138 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_stop_host()
143 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_become_peripheral()
145 extcon_set_state_sync(tu->extcon, EXTCON_USB_HOST, false); in tahvo_usb_become_peripheral()
150 tu->phy.otg->state = OTG_STATE_B_IDLE; in tahvo_usb_become_peripheral()
157 if (tu->phy.otg->gadget) in tahvo_usb_stop_peripheral()
158 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in tahvo_usb_stop_peripheral()
159 tu->phy.otg->state = OTG_STATE_B_IDLE; in tahvo_usb_stop_peripheral()
164 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_power_off()
167 if (tu->phy.otg->gadget) in tahvo_usb_power_off()
168 usb_gadget_vbus_disconnect(tu->phy.otg->gadget); in tahvo_usb_power_off()
172 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_power_off()
177 struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, phy); in tahvo_usb_set_suspend()
178 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); in tahvo_usb_set_suspend()
181 dev_dbg(&tu->pt_dev->dev, "%s\n", __func__); in tahvo_usb_set_suspend()
195 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_host()
196 phy); in tahvo_usb_set_host()
198 mutex_lock(&tu->serialize); in tahvo_usb_set_host()
201 if (tu->tahvo_mode == TAHVO_MODE_HOST) in tahvo_usb_set_host()
203 otg->host = NULL; in tahvo_usb_set_host()
204 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
208 if (tu->tahvo_mode == TAHVO_MODE_HOST) { in tahvo_usb_set_host()
209 otg->host = NULL; in tahvo_usb_set_host()
213 otg->host = host; in tahvo_usb_set_host()
215 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
223 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_peripheral()
224 phy); in tahvo_usb_set_peripheral()
226 mutex_lock(&tu->serialize); in tahvo_usb_set_peripheral()
229 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
231 tu->phy.otg->gadget = NULL; in tahvo_usb_set_peripheral()
232 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
236 tu->phy.otg->gadget = gadget; in tahvo_usb_set_peripheral()
237 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
240 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
249 mutex_lock(&tu->serialize); in tahvo_usb_vbus_interrupt()
251 mutex_unlock(&tu->serialize); in tahvo_usb_vbus_interrupt()
256 static ssize_t otg_mode_show(struct device *device, in otg_mode_show() argument
259 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_show()
261 switch (tu->tahvo_mode) { in otg_mode_show()
268 return -EINVAL; in otg_mode_show()
271 static ssize_t otg_mode_store(struct device *device, in otg_mode_store() argument
275 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_store()
278 mutex_lock(&tu->serialize); in otg_mode_store()
280 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in otg_mode_store()
282 tu->tahvo_mode = TAHVO_MODE_HOST; in otg_mode_store()
283 if (tu->phy.otg->host) { in otg_mode_store()
284 dev_info(device, "HOST mode: host controller present\n"); in otg_mode_store()
287 dev_info(device, "HOST mode: no host controller, powering off\n"); in otg_mode_store()
292 if (tu->tahvo_mode == TAHVO_MODE_HOST) in otg_mode_store()
294 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in otg_mode_store()
295 if (tu->phy.otg->gadget) { in otg_mode_store()
296 dev_info(device, "PERIPHERAL mode: gadget driver present\n"); in otg_mode_store()
299 dev_info(device, "PERIPHERAL mode: no gadget driver, powering off\n"); in otg_mode_store()
304 r = -EINVAL; in otg_mode_store()
306 mutex_unlock(&tu->serialize); in otg_mode_store()
321 struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent); in tahvo_usb_probe()
325 tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); in tahvo_usb_probe()
327 return -ENOMEM; in tahvo_usb_probe()
329 tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), in tahvo_usb_probe()
331 if (!tu->phy.otg) in tahvo_usb_probe()
332 return -ENOMEM; in tahvo_usb_probe()
334 tu->pt_dev = pdev; in tahvo_usb_probe()
338 tu->tahvo_mode = TAHVO_MODE_HOST; in tahvo_usb_probe()
340 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in tahvo_usb_probe()
343 mutex_init(&tu->serialize); in tahvo_usb_probe()
345 tu->ick = devm_clk_get(&pdev->dev, "usb_l4_ick"); in tahvo_usb_probe()
346 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
347 clk_enable(tu->ick); in tahvo_usb_probe()
352 tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS; in tahvo_usb_probe()
354 tu->extcon = devm_extcon_dev_allocate(&pdev->dev, tahvo_cable); in tahvo_usb_probe()
355 if (IS_ERR(tu->extcon)) { in tahvo_usb_probe()
356 dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); in tahvo_usb_probe()
357 ret = PTR_ERR(tu->extcon); in tahvo_usb_probe()
361 ret = devm_extcon_dev_register(&pdev->dev, tu->extcon); in tahvo_usb_probe()
363 dev_err(&pdev->dev, "could not register extcon device: %d\n", in tahvo_usb_probe()
369 extcon_set_state_sync(tu->extcon, EXTCON_USB_HOST, in tahvo_usb_probe()
370 tu->tahvo_mode == TAHVO_MODE_HOST); in tahvo_usb_probe()
371 extcon_set_state_sync(tu->extcon, EXTCON_USB, tu->vbus_state); in tahvo_usb_probe()
375 tu->phy.dev = &pdev->dev; in tahvo_usb_probe()
376 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_probe()
377 tu->phy.label = DRIVER_NAME; in tahvo_usb_probe()
378 tu->phy.set_suspend = tahvo_usb_set_suspend; in tahvo_usb_probe()
380 tu->phy.otg->usb_phy = &tu->phy; in tahvo_usb_probe()
381 tu->phy.otg->set_host = tahvo_usb_set_host; in tahvo_usb_probe()
382 tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; in tahvo_usb_probe()
384 ret = usb_add_phy(&tu->phy, USB_PHY_TYPE_USB2); in tahvo_usb_probe()
386 dev_err(&pdev->dev, "cannot register USB transceiver: %d\n", in tahvo_usb_probe()
391 dev_set_drvdata(&pdev->dev, tu); in tahvo_usb_probe()
393 tu->irq = ret = platform_get_irq(pdev, 0); in tahvo_usb_probe()
396 ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt, in tahvo_usb_probe()
398 "tahvo-vbus", tu); in tahvo_usb_probe()
400 dev_err(&pdev->dev, "could not register tahvo-vbus irq: %d\n", in tahvo_usb_probe()
408 usb_remove_phy(&tu->phy); in tahvo_usb_probe()
410 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
411 clk_disable(tu->ick); in tahvo_usb_probe()
420 free_irq(tu->irq, tu); in tahvo_usb_remove()
421 usb_remove_phy(&tu->phy); in tahvo_usb_remove()
422 if (!IS_ERR(tu->ick)) in tahvo_usb_remove()
423 clk_disable(tu->ick); in tahvo_usb_remove()
430 .name = "tahvo-usb",