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 dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, host); in tahvo_usb_set_host()
199 mutex_lock(&tu->serialize); in tahvo_usb_set_host()
202 if (tu->tahvo_mode == TAHVO_MODE_HOST) in tahvo_usb_set_host()
204 otg->host = NULL; in tahvo_usb_set_host()
205 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
209 if (tu->tahvo_mode == TAHVO_MODE_HOST) { in tahvo_usb_set_host()
210 otg->host = NULL; in tahvo_usb_set_host()
214 otg->host = host; in tahvo_usb_set_host()
216 mutex_unlock(&tu->serialize); in tahvo_usb_set_host()
224 struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, in tahvo_usb_set_peripheral()
225 phy); in tahvo_usb_set_peripheral()
227 dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, gadget); in tahvo_usb_set_peripheral()
229 mutex_lock(&tu->serialize); in tahvo_usb_set_peripheral()
232 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
234 tu->phy.otg->gadget = NULL; in tahvo_usb_set_peripheral()
235 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
239 tu->phy.otg->gadget = gadget; in tahvo_usb_set_peripheral()
240 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in tahvo_usb_set_peripheral()
243 mutex_unlock(&tu->serialize); in tahvo_usb_set_peripheral()
252 mutex_lock(&tu->serialize); in tahvo_usb_vbus_interrupt()
254 mutex_unlock(&tu->serialize); in tahvo_usb_vbus_interrupt()
259 static ssize_t otg_mode_show(struct device *device, in otg_mode_show() argument
262 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_show()
264 switch (tu->tahvo_mode) { in otg_mode_show()
271 return -EINVAL; in otg_mode_show()
274 static ssize_t otg_mode_store(struct device *device, in otg_mode_store() argument
278 struct tahvo_usb *tu = dev_get_drvdata(device); in otg_mode_store()
281 mutex_lock(&tu->serialize); in otg_mode_store()
283 if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) in otg_mode_store()
285 tu->tahvo_mode = TAHVO_MODE_HOST; in otg_mode_store()
286 if (tu->phy.otg->host) { in otg_mode_store()
287 dev_info(device, "HOST mode: host controller present\n"); in otg_mode_store()
290 dev_info(device, "HOST mode: no host controller, powering off\n"); in otg_mode_store()
295 if (tu->tahvo_mode == TAHVO_MODE_HOST) in otg_mode_store()
297 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in otg_mode_store()
298 if (tu->phy.otg->gadget) { in otg_mode_store()
299 dev_info(device, "PERIPHERAL mode: gadget driver present\n"); in otg_mode_store()
302 dev_info(device, "PERIPHERAL mode: no gadget driver, powering off\n"); in otg_mode_store()
307 r = -EINVAL; in otg_mode_store()
309 mutex_unlock(&tu->serialize); in otg_mode_store()
324 struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent); in tahvo_usb_probe()
328 tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); in tahvo_usb_probe()
330 return -ENOMEM; in tahvo_usb_probe()
332 tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), in tahvo_usb_probe()
334 if (!tu->phy.otg) in tahvo_usb_probe()
335 return -ENOMEM; in tahvo_usb_probe()
337 tu->pt_dev = pdev; in tahvo_usb_probe()
341 tu->tahvo_mode = TAHVO_MODE_HOST; in tahvo_usb_probe()
343 tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; in tahvo_usb_probe()
346 mutex_init(&tu->serialize); in tahvo_usb_probe()
348 tu->ick = devm_clk_get(&pdev->dev, "usb_l4_ick"); in tahvo_usb_probe()
349 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
350 clk_enable(tu->ick); in tahvo_usb_probe()
355 tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS; in tahvo_usb_probe()
357 tu->extcon = devm_extcon_dev_allocate(&pdev->dev, tahvo_cable); in tahvo_usb_probe()
358 if (IS_ERR(tu->extcon)) { in tahvo_usb_probe()
359 dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); in tahvo_usb_probe()
360 ret = PTR_ERR(tu->extcon); in tahvo_usb_probe()
364 ret = devm_extcon_dev_register(&pdev->dev, tu->extcon); in tahvo_usb_probe()
366 dev_err(&pdev->dev, "could not register extcon device: %d\n", in tahvo_usb_probe()
372 extcon_set_state_sync(tu->extcon, EXTCON_USB_HOST, in tahvo_usb_probe()
373 tu->tahvo_mode == TAHVO_MODE_HOST); in tahvo_usb_probe()
374 extcon_set_state_sync(tu->extcon, EXTCON_USB, tu->vbus_state); in tahvo_usb_probe()
378 tu->phy.dev = &pdev->dev; in tahvo_usb_probe()
379 tu->phy.otg->state = OTG_STATE_UNDEFINED; in tahvo_usb_probe()
380 tu->phy.label = DRIVER_NAME; in tahvo_usb_probe()
381 tu->phy.set_suspend = tahvo_usb_set_suspend; in tahvo_usb_probe()
383 tu->phy.otg->usb_phy = &tu->phy; in tahvo_usb_probe()
384 tu->phy.otg->set_host = tahvo_usb_set_host; in tahvo_usb_probe()
385 tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; in tahvo_usb_probe()
387 ret = usb_add_phy(&tu->phy, USB_PHY_TYPE_USB2); in tahvo_usb_probe()
389 dev_err(&pdev->dev, "cannot register USB transceiver: %d\n", in tahvo_usb_probe()
394 dev_set_drvdata(&pdev->dev, tu); in tahvo_usb_probe()
396 tu->irq = platform_get_irq(pdev, 0); in tahvo_usb_probe()
397 ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt, in tahvo_usb_probe()
399 "tahvo-vbus", tu); in tahvo_usb_probe()
401 dev_err(&pdev->dev, "could not register tahvo-vbus irq: %d\n", in tahvo_usb_probe()
409 usb_remove_phy(&tu->phy); in tahvo_usb_probe()
411 if (!IS_ERR(tu->ick)) in tahvo_usb_probe()
412 clk_disable(tu->ick); in tahvo_usb_probe()
421 free_irq(tu->irq, tu); in tahvo_usb_remove()
422 usb_remove_phy(&tu->phy); in tahvo_usb_remove()
423 if (!IS_ERR(tu->ick)) in tahvo_usb_remove()
424 clk_disable(tu->ick); in tahvo_usb_remove()
433 .name = "tahvo-usb",