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>
26 #define DRIVER_NAME "tahvo-usb"
46 struct usb_phy phy; member
62 static ssize_t vbus_show(struct device *device, in vbus_show() argument
65 struct tahvo_usb *tu = dev_get_drvdata(device); in vbus_show()
66 return sprintf(buf, "%s\n", tu->vbus_state ? "on" : "off"); in vbus_show()
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()
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()
137 tu->phy.otg->state = OTG_STATE_A_IDLE; in tahvo_usb_stop_host()
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()
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()
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()
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()
195 phy); in tahvo_usb_set_host()
197 mutex_lock(&tu->serialize); in tahvo_usb_set_host()
200 if (tu->tahvo_mode == TAHVO_MODE_HOST) in tahvo_usb_set_host()
202 otg->host = NULL; 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()
208 otg->host = NULL; in tahvo_usb_set_host()
212 otg->host = host; 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()
223 phy); in tahvo_usb_set_peripheral()
225 mutex_lock(&tu->serialize); in tahvo_usb_set_peripheral()
228 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) 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()
239 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
248 mutex_lock(&tu->serialize); in tahvo_usb_vbus_interrupt()
250 mutex_unlock(&tu->serialize); in tahvo_usb_vbus_interrupt()
255 static ssize_t otg_mode_show(struct device *device, in otg_mode_show() argument
258 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_show()
260 switch (tu->tahvo_mode) { in otg_mode_show()
267 return -EINVAL; in otg_mode_show()
270 static ssize_t otg_mode_store(struct device *device, in otg_mode_store() argument
274 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_store()
277 mutex_lock(&tu->serialize); in otg_mode_store()
279 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) 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()
283 dev_info(device, "HOST mode: host controller present\n"); in otg_mode_store()
286 dev_info(device, "HOST mode: no host controller, powering off\n"); in otg_mode_store()
291 if (tu->tahvo_mode == TAHVO_MODE_HOST) 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()
295 dev_info(device, "PERIPHERAL mode: gadget driver present\n"); in otg_mode_store()
298 dev_info(device, "PERIPHERAL mode: no gadget driver, powering off\n"); in otg_mode_store()
303 r = -EINVAL; in otg_mode_store()
305 mutex_unlock(&tu->serialize); in otg_mode_store()
320 struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent); in tahvo_usb_probe()
324 tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); in tahvo_usb_probe()
326 return -ENOMEM; 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()
331 return -ENOMEM; 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()
355 dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); 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()
362 dev_err(&pdev->dev, "could not register extcon device: %d\n", 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()
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()
385 dev_err(&pdev->dev, "cannot register USB transceiver: %d\n", 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()
399 dev_err(&pdev->dev, "could not register tahvo-vbus irq: %d\n", 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()
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()
429 .name = "tahvo-usb",