diff options
author | 2020-04-07 09:08:15 +0000 | |
---|---|---|
committer | 2020-04-07 09:08:15 +0000 | |
commit | 4c45b3543db7f12281098b3a5f0c32beff3c01d9 (patch) | |
tree | 310a347ac43fd97022c7f63a335898ad0c144685 | |
parent | Fix off-by-one in check for valid pin numbers and use the existing (diff) | |
download | wireguard-openbsd-4c45b3543db7f12281098b3a5f0c32beff3c01d9.tar.xz wireguard-openbsd-4c45b3543db7f12281098b3a5f0c32beff3c01d9.zip |
Implement support for "usb-nop-xceiv" PHYs.
ok jsg@
-rw-r--r-- | sys/dev/ofw/ofw_misc.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/sys/dev/ofw/ofw_misc.c b/sys/dev/ofw/ofw_misc.c index c212e6c39aa..84fc5dcb6a5 100644 --- a/sys/dev/ofw/ofw_misc.c +++ b/sys/dev/ofw/ofw_misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_misc.c,v 1.18 2020/03/22 14:56:24 kettenis Exp $ */ +/* $OpenBSD: ofw_misc.c,v 1.19 2020/04/07 09:08:15 kettenis Exp $ */ /* * Copyright (c) 2017 Mark Kettenis * @@ -22,7 +22,9 @@ #include <machine/bus.h> #include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_gpio.h> #include <dev/ofw/ofw_misc.h> +#include <dev/ofw/ofw_regulator.h> /* * Register maps. @@ -128,10 +130,40 @@ phy_register(struct phy_device *pd) } int +phy_usb_nop_enable(int node) +{ + uint32_t vcc_supply; + uint32_t *gpio; + int len; + + vcc_supply = OF_getpropint(node, "vcc-supply", 0); + if (vcc_supply) + regulator_enable(vcc_supply); + + len = OF_getproplen(node, "reset-gpios"); + if (len <= 0) + return 0; + + /* There should only be a single GPIO pin. */ + gpio = malloc(len, M_TEMP, M_WAITOK); + OF_getpropintarray(node, "reset-gpios", gpio, len); + + gpio_controller_config_pin(gpio, GPIO_CONFIG_OUTPUT); + gpio_controller_set_pin(gpio, 1); + delay(10000); + gpio_controller_set_pin(gpio, 0); + + free(gpio, M_TEMP, len); + + return 0; +} + +int phy_enable_cells(uint32_t *cells) { struct phy_device *pd; uint32_t phandle = cells[0]; + int node; LIST_FOREACH(pd, &phy_devices, pd_list) { if (pd->pd_phandle == phandle) @@ -141,7 +173,14 @@ phy_enable_cells(uint32_t *cells) if (pd && pd->pd_enable) return pd->pd_enable(pd->pd_cookie, &cells[1]); - return -1; + node = OF_getnodebyphandle(phandle); + if (node == 0) + return ENXIO; + + if (OF_is_compatible(node, "usb-nop-xceiv")) + return phy_usb_nop_enable(node); + + return ENXIO; } uint32_t * |