blob: 89e18a2ddad66c48b6d5e24fda05d9bcf8c2a284 [file] [log] [blame]
Fabrice Gasnierba1fa2a2022-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
10#include <common.h>
11#include <dm.h>
12#include <dm/device_compat.h>
13#include <power/regulator.h>
14
15struct onboard_hub {
16 struct udevice *vdd;
17};
18
19static int usb_onboard_hub_probe(struct udevice *dev)
20{
21 struct onboard_hub *hub = dev_get_priv(dev);
22 int ret;
23
24 ret = device_get_supply_regulator(dev, "vdd-supply", &hub->vdd);
25 if (ret) {
26 dev_err(dev, "can't get vdd-supply: %d\n", ret);
27 return ret;
28 }
29
30 ret = regulator_set_enable_if_allowed(hub->vdd, true);
31 if (ret)
32 dev_err(dev, "can't enable vdd-supply: %d\n", ret);
33
34 return ret;
35}
36
37static int usb_onboard_hub_remove(struct udevice *dev)
38{
39 struct onboard_hub *hub = dev_get_priv(dev);
40 int ret;
41
42 ret = regulator_set_enable_if_allowed(hub->vdd, false);
43 if (ret)
44 dev_err(dev, "can't disable vdd-supply: %d\n", ret);
45
46 return ret;
47}
48
49static const struct udevice_id usb_onboard_hub_ids[] = {
50 /* Use generic usbVID,PID dt-bindings (usb-device.yaml) */
51 { .compatible = "usb424,2514" }, /* USB2514B USB 2.0 */
52 { }
53};
54
55U_BOOT_DRIVER(usb_onboard_hub) = {
56 .name = "usb_onboard_hub",
57 .id = UCLASS_USB_HUB,
58 .probe = usb_onboard_hub_probe,
59 .remove = usb_onboard_hub_remove,
60 .of_match = usb_onboard_hub_ids,
61 .priv_auto = sizeof(struct onboard_hub),
62};