Lines Matching +full:usb +full:- +full:hub
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for onboard USB hubs
23 #include <linux/usb.h>
24 #include <linux/usb/hcd.h>
25 #include <linux/usb/onboard_hub.h>
32 * hub requires more than the currently supported supplies, add a new one here.
65 static int onboard_hub_power_on(struct onboard_hub *hub) in onboard_hub_power_on() argument
69 err = regulator_bulk_enable(hub->pdata->num_supplies, hub->supplies); in onboard_hub_power_on()
71 dev_err(hub->dev, "failed to enable supplies: %d\n", err); in onboard_hub_power_on()
75 fsleep(hub->pdata->reset_us); in onboard_hub_power_on()
76 gpiod_set_value_cansleep(hub->reset_gpio, 0); in onboard_hub_power_on()
78 hub->is_powered_on = true; in onboard_hub_power_on()
83 static int onboard_hub_power_off(struct onboard_hub *hub) in onboard_hub_power_off() argument
87 gpiod_set_value_cansleep(hub->reset_gpio, 1); in onboard_hub_power_off()
89 err = regulator_bulk_disable(hub->pdata->num_supplies, hub->supplies); in onboard_hub_power_off()
91 dev_err(hub->dev, "failed to disable supplies: %d\n", err); in onboard_hub_power_off()
95 hub->is_powered_on = false; in onboard_hub_power_off()
102 struct onboard_hub *hub = dev_get_drvdata(dev); in onboard_hub_suspend() local
106 if (hub->always_powered_in_suspend) in onboard_hub_suspend()
109 mutex_lock(&hub->lock); in onboard_hub_suspend()
111 list_for_each_entry(node, &hub->udev_list, list) { in onboard_hub_suspend()
112 if (!device_may_wakeup(node->udev->bus->controller)) in onboard_hub_suspend()
115 if (usb_wakeup_enabled_descendants(node->udev)) { in onboard_hub_suspend()
121 mutex_unlock(&hub->lock); in onboard_hub_suspend()
126 return onboard_hub_power_off(hub); in onboard_hub_suspend()
131 struct onboard_hub *hub = dev_get_drvdata(dev); in onboard_hub_resume() local
133 if (hub->is_powered_on) in onboard_hub_resume()
136 return onboard_hub_power_on(hub); in onboard_hub_resume()
141 snprintf(buf, size, "usb_dev.%s", dev_name(&udev->dev)); in get_udev_link_name()
144 static int onboard_hub_add_usbdev(struct onboard_hub *hub, struct usb_device *udev) in onboard_hub_add_usbdev() argument
150 mutex_lock(&hub->lock); in onboard_hub_add_usbdev()
152 if (hub->going_away) { in onboard_hub_add_usbdev()
153 err = -EINVAL; in onboard_hub_add_usbdev()
159 err = -ENOMEM; in onboard_hub_add_usbdev()
163 node->udev = udev; in onboard_hub_add_usbdev()
165 list_add(&node->list, &hub->udev_list); in onboard_hub_add_usbdev()
167 mutex_unlock(&hub->lock); in onboard_hub_add_usbdev()
170 WARN_ON(sysfs_create_link(&hub->dev->kobj, &udev->dev.kobj, link_name)); in onboard_hub_add_usbdev()
175 mutex_unlock(&hub->lock); in onboard_hub_add_usbdev()
180 static void onboard_hub_remove_usbdev(struct onboard_hub *hub, const struct usb_device *udev) in onboard_hub_remove_usbdev() argument
186 sysfs_remove_link(&hub->dev->kobj, link_name); in onboard_hub_remove_usbdev()
188 mutex_lock(&hub->lock); in onboard_hub_remove_usbdev()
190 list_for_each_entry(node, &hub->udev_list, list) { in onboard_hub_remove_usbdev()
191 if (node->udev == udev) { in onboard_hub_remove_usbdev()
192 list_del(&node->list); in onboard_hub_remove_usbdev()
198 mutex_unlock(&hub->lock); in onboard_hub_remove_usbdev()
204 const struct onboard_hub *hub = dev_get_drvdata(dev); in always_powered_in_suspend_show() local
206 return sysfs_emit(buf, "%d\n", hub->always_powered_in_suspend); in always_powered_in_suspend_show()
212 struct onboard_hub *hub = dev_get_drvdata(dev); in always_powered_in_suspend_store() local
220 hub->always_powered_in_suspend = val; in always_powered_in_suspend_store()
238 pr_err("Failed to attach USB driver: %d\n", err); in onboard_hub_attach_usb_driver()
244 struct device *dev = &pdev->dev; in onboard_hub_probe()
245 struct onboard_hub *hub; in onboard_hub_probe() local
249 hub = devm_kzalloc(dev, sizeof(*hub), GFP_KERNEL); in onboard_hub_probe()
250 if (!hub) in onboard_hub_probe()
251 return -ENOMEM; in onboard_hub_probe()
253 of_id = of_match_device(onboard_hub_match, &pdev->dev); in onboard_hub_probe()
255 return -ENODEV; in onboard_hub_probe()
257 hub->pdata = of_id->data; in onboard_hub_probe()
258 if (!hub->pdata) in onboard_hub_probe()
259 return -EINVAL; in onboard_hub_probe()
261 if (hub->pdata->num_supplies > MAX_SUPPLIES) in onboard_hub_probe()
262 return dev_err_probe(dev, -EINVAL, "max %zu supplies supported!\n", in onboard_hub_probe()
265 for (i = 0; i < hub->pdata->num_supplies; i++) in onboard_hub_probe()
266 hub->supplies[i].supply = supply_names[i]; in onboard_hub_probe()
268 err = devm_regulator_bulk_get(dev, hub->pdata->num_supplies, hub->supplies); in onboard_hub_probe()
274 hub->reset_gpio = devm_gpiod_get_optional(dev, "reset", in onboard_hub_probe()
276 if (IS_ERR(hub->reset_gpio)) in onboard_hub_probe()
277 return dev_err_probe(dev, PTR_ERR(hub->reset_gpio), "failed to get reset GPIO\n"); in onboard_hub_probe()
279 hub->dev = dev; in onboard_hub_probe()
280 mutex_init(&hub->lock); in onboard_hub_probe()
281 INIT_LIST_HEAD(&hub->udev_list); in onboard_hub_probe()
283 dev_set_drvdata(dev, hub); in onboard_hub_probe()
285 err = onboard_hub_power_on(hub); in onboard_hub_probe()
290 * The USB driver might have been detached from the USB devices by in onboard_hub_probe()
292 * make sure to re-attach it if needed. in onboard_hub_probe()
294 * This needs to be done deferred to avoid self-deadlocks on systems in onboard_hub_probe()
304 struct onboard_hub *hub = dev_get_drvdata(&pdev->dev); in onboard_hub_remove() local
308 hub->going_away = true; in onboard_hub_remove()
310 mutex_lock(&hub->lock); in onboard_hub_remove()
312 /* unbind the USB devices to avoid dangling references to this device */ in onboard_hub_remove()
313 while (!list_empty(&hub->udev_list)) { in onboard_hub_remove()
314 node = list_first_entry(&hub->udev_list, struct usbdev_node, list); in onboard_hub_remove()
315 udev = node->udev; in onboard_hub_remove()
319 * which acquires hub->lock. We must release the lock first. in onboard_hub_remove()
321 get_device(&udev->dev); in onboard_hub_remove()
322 mutex_unlock(&hub->lock); in onboard_hub_remove()
323 device_release_driver(&udev->dev); in onboard_hub_remove()
324 put_device(&udev->dev); in onboard_hub_remove()
325 mutex_lock(&hub->lock); in onboard_hub_remove()
328 mutex_unlock(&hub->lock); in onboard_hub_remove()
330 onboard_hub_power_off(hub); in onboard_hub_remove()
344 .name = "onboard-usb-hub",
351 /************************** USB driver **************************/
361 * Returns the onboard_hub platform device that is associated with the USB
368 struct onboard_hub *hub; in _find_onboard_hub() local
370 pdev = of_find_device_by_node(dev->of_node); in _find_onboard_hub()
372 np = of_parse_phandle(dev->of_node, "peer-hub", 0); in _find_onboard_hub()
374 dev_err(dev, "failed to find device node for peer hub\n"); in _find_onboard_hub()
375 return ERR_PTR(-EINVAL); in _find_onboard_hub()
382 return ERR_PTR(-ENODEV); in _find_onboard_hub()
385 hub = dev_get_drvdata(&pdev->dev); in _find_onboard_hub()
386 put_device(&pdev->dev); in _find_onboard_hub()
389 * The presence of drvdata ('hub') indicates that the platform driver in _find_onboard_hub()
395 if (!hub) in _find_onboard_hub()
396 return ERR_PTR(-EPROBE_DEFER); in _find_onboard_hub()
398 return hub; in _find_onboard_hub()
403 struct device *dev = &udev->dev; in onboard_hub_usbdev_probe()
404 struct onboard_hub *hub; in onboard_hub_usbdev_probe() local
408 if (!dev->of_node) in onboard_hub_usbdev_probe()
409 return -ENODEV; in onboard_hub_usbdev_probe()
411 hub = _find_onboard_hub(dev); in onboard_hub_usbdev_probe()
412 if (IS_ERR(hub)) in onboard_hub_usbdev_probe()
413 return PTR_ERR(hub); in onboard_hub_usbdev_probe()
415 dev_set_drvdata(dev, hub); in onboard_hub_usbdev_probe()
417 err = onboard_hub_add_usbdev(hub, udev); in onboard_hub_usbdev_probe()
426 struct onboard_hub *hub = dev_get_drvdata(&udev->dev); in onboard_hub_usbdev_disconnect() local
428 onboard_hub_remove_usbdev(hub, udev); in onboard_hub_usbdev_disconnect()
434 { USB_DEVICE(VENDOR_ID_GENESYS, 0x0608) }, /* Genesys Logic GL850G USB 2.0 */
435 { USB_DEVICE(VENDOR_ID_GENESYS, 0x0610) }, /* Genesys Logic GL852G USB 2.0 */
436 { USB_DEVICE(VENDOR_ID_GENESYS, 0x0620) }, /* Genesys Logic GL3523 USB 3.1 */
437 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2412) }, /* USB2412 USB 2.0 */
438 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2514) }, /* USB2514B USB 2.0 */
439 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2517) }, /* USB2517 USB 2.0 */
440 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2744) }, /* USB5744 USB 2.0 */
441 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x5744) }, /* USB5744 USB 3.0 */
442 { USB_DEVICE(VENDOR_ID_REALTEK, 0x0411) }, /* RTS5411 USB 3.1 */
443 { USB_DEVICE(VENDOR_ID_REALTEK, 0x5411) }, /* RTS5411 USB 2.1 */
444 { USB_DEVICE(VENDOR_ID_REALTEK, 0x0414) }, /* RTS5414 USB 3.2 */
445 { USB_DEVICE(VENDOR_ID_REALTEK, 0x5414) }, /* RTS5414 USB 2.1 */
452 MODULE_DEVICE_TABLE(usb, onboard_hub_id_table);
455 .name = "onboard-usb-hub",
489 MODULE_DESCRIPTION("Driver for discrete onboard USB hubs");