Message ID | 20240816081922.282155-1-mailinglist1@johanneskirchmair.de |
---|---|
State | New |
Delegated to: | Marek Vasut |
Headers | show |
Series | usb: add reset pin handling to onboard-hub driver | expand |
Hi, On Fri, 16 Aug 2024 at 07:36, <mailinglist1@johanneskirchmair.de> wrote: > > From: Johannes Kirchmair <johannes.kirchmair@skidata.com> > > Some onboard-hub chips have external reset pins. This patch adds > handling of said pin to the onboard-hub driver. The naming for the > devicetree binding is done in the same way as in the Linux kernel to > ensure good compatibility between u-boot's and Linux's devicetrees. U-Boot's > > Signed-off-by: Johannes Kirchmair <johannes.kirchmair@skidata.com> > --- > common/usb_onboard_hub.c | 32 +++++++++++++++++++++++++++++++- > 1 file changed, 31 insertions(+), 1 deletion(-) > > diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c > index 68a04ac041..5b1bb79c55 100644 > --- a/common/usb_onboard_hub.c > +++ b/common/usb_onboard_hub.c > @@ -10,9 +10,11 @@ > #include <dm.h> > #include <dm/device_compat.h> > #include <power/regulator.h> > +#include <asm/gpio.h> > > struct onboard_hub { > struct udevice *vdd; > + struct gpio_desc reset_pin; > }; > > static int usb_onboard_hub_probe(struct udevice *dev) > @@ -27,8 +29,23 @@ static int usb_onboard_hub_probe(struct udevice *dev) > } > > ret = regulator_set_enable_if_allowed(hub->vdd, true); > - if (ret) > + if (ret) { > dev_err(dev, "can't enable vdd-supply: %d\n", ret); > + return ret; > + } > + > + ret = gpio_request_by_name(dev, "reset-gpios", 0, &hub->reset_pin, > + GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); > + if (ret && ret != -ENOENT) { > + dev_err(dev, "can't get reset-gpios 0: %d\n", ret); > + return ret; > + } > + > + if (hub->reset_pin.dev) { > + ret = dm_gpio_set_value(&hub->reset_pin, 0); > + if (ret) > + dev_err(dev, "failed setting reset-gpios to 0: %d\n", ret); > + } With the GPIOD_... flags above, this should already be done, so you don't need this code. > > return ret; > } > @@ -42,12 +59,25 @@ static int usb_onboard_hub_remove(struct udevice *dev) > if (ret) > dev_err(dev, "can't disable vdd-supply: %d\n", ret); > > + if (hub->reset_pin.dev) { > + ret = dm_gpio_set_value(&hub->reset_pin, 1); > + if (ret) > + dev_err(dev, "failed setting reset-gpios to 0: %d\n", ret); 1 Is this putting the device in reset? Could you add a comment as to why? > + } > + > + if (hub->reset_pin.dev) { > + ret = dm_gpio_free(dev, &hub->reset_pin); > + if (ret) > + dev_err(dev, "can't free reset-gpios: %d\n", ret); > + } > + > return ret; > } > > static const struct udevice_id usb_onboard_hub_ids[] = { > /* Use generic usbVID,PID dt-bindings (usb-device.yaml) */ > { .compatible = "usb424,2514" }, /* USB2514B USB 2.0 */ > + { .compatible = "usb4b4,6504" }, > { } > }; > > -- > 2.34.1 > Regards, Simon
diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c index 68a04ac041..5b1bb79c55 100644 --- a/common/usb_onboard_hub.c +++ b/common/usb_onboard_hub.c @@ -10,9 +10,11 @@ #include <dm.h> #include <dm/device_compat.h> #include <power/regulator.h> +#include <asm/gpio.h> struct onboard_hub { struct udevice *vdd; + struct gpio_desc reset_pin; }; static int usb_onboard_hub_probe(struct udevice *dev) @@ -27,8 +29,23 @@ static int usb_onboard_hub_probe(struct udevice *dev) } ret = regulator_set_enable_if_allowed(hub->vdd, true); - if (ret) + if (ret) { dev_err(dev, "can't enable vdd-supply: %d\n", ret); + return ret; + } + + ret = gpio_request_by_name(dev, "reset-gpios", 0, &hub->reset_pin, + GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); + if (ret && ret != -ENOENT) { + dev_err(dev, "can't get reset-gpios 0: %d\n", ret); + return ret; + } + + if (hub->reset_pin.dev) { + ret = dm_gpio_set_value(&hub->reset_pin, 0); + if (ret) + dev_err(dev, "failed setting reset-gpios to 0: %d\n", ret); + } return ret; } @@ -42,12 +59,25 @@ static int usb_onboard_hub_remove(struct udevice *dev) if (ret) dev_err(dev, "can't disable vdd-supply: %d\n", ret); + if (hub->reset_pin.dev) { + ret = dm_gpio_set_value(&hub->reset_pin, 1); + if (ret) + dev_err(dev, "failed setting reset-gpios to 0: %d\n", ret); + } + + if (hub->reset_pin.dev) { + ret = dm_gpio_free(dev, &hub->reset_pin); + if (ret) + dev_err(dev, "can't free reset-gpios: %d\n", ret); + } + return ret; } static const struct udevice_id usb_onboard_hub_ids[] = { /* Use generic usbVID,PID dt-bindings (usb-device.yaml) */ { .compatible = "usb424,2514" }, /* USB2514B USB 2.0 */ + { .compatible = "usb4b4,6504" }, { } };