blob: 68a04ac0412b3d1ebe42d795f71fcdad637c5eab [file] [log] [blame]
Fabrice Gasniercd809b12022-12-12 11:44:35 +01001// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Driver for onboard USB hubs
4 *
5 * Copyright (C) 2022, STMicroelectronics - All Rights Reserved
6 *
7 * Mostly inspired by Linux kernel v6.1 onboard_usb_hub driver
8 */
9
Fabrice Gasniercd809b12022-12-12 11:44:35 +010010#include <dm.h>
11#include <dm/device_compat.h>
12#include <power/regulator.h>
13
14struct onboard_hub {
15 struct udevice *vdd;
16};
17
18static int usb_onboard_hub_probe(struct udevice *dev)
19{
20 struct onboard_hub *hub = dev_get_priv(dev);
21 int ret;
22
23 ret = device_get_supply_regulator(dev, "vdd-supply", &hub->vdd);
24 if (ret) {
25 dev_err(dev, "can't get vdd-supply: %d\n", ret);
26 return ret;
27 }
28
29 ret = regulator_set_enable_if_allowed(hub->vdd, true);
30 if (ret)
31 dev_err(dev, "can't enable vdd-supply: %d\n", ret);
32
33 return ret;
34}
35
36static int usb_onboard_hub_remove(struct udevice *dev)
37{
38 struct onboard_hub *hub = dev_get_priv(dev);
39 int ret;
40
41 ret = regulator_set_enable_if_allowed(hub->vdd, false);
42 if (ret)
43 dev_err(dev, "can't disable vdd-supply: %d\n", ret);
44
45 return ret;
46}
47
48static const struct udevice_id usb_onboard_hub_ids[] = {
49 /* Use generic usbVID,PID dt-bindings (usb-device.yaml) */
50 { .compatible = "usb424,2514" }, /* USB2514B USB 2.0 */
51 { }
52};
53
54U_BOOT_DRIVER(usb_onboard_hub) = {
55 .name = "usb_onboard_hub",
56 .id = UCLASS_USB_HUB,
57 .probe = usb_onboard_hub_probe,
58 .remove = usb_onboard_hub_remove,
59 .of_match = usb_onboard_hub_ids,
60 .priv_auto = sizeof(struct onboard_hub),
61};