diff --git a/sys/arm64/rockchip/rk3568_pcie.c b/sys/arm64/rockchip/rk3568_pcie.c --- a/sys/arm64/rockchip/rk3568_pcie.c +++ b/sys/arm64/rockchip/rk3568_pcie.c @@ -139,21 +139,43 @@ int err, count; bool status; + /* Assert PCIe reset */ + if (sc->reset_gpio != NULL) { + if (gpio_pin_setflags(sc->reset_gpio, GPIO_PIN_OUTPUT)) { + device_printf(dev, "Could not setup PCIe reset\n"); + return (ENXIO); + } + if (gpio_pin_set_active(sc->reset_gpio, true)) { + device_printf(dev, "Could not set PCIe reset\n"); + return (ENXIO); + } + } + /* Assert reset */ - if (hwreset_assert(sc->hwreset)) + if (hwreset_assert(sc->hwreset)) { device_printf(dev, "Could not assert reset\n"); + return (ENXIO); + } /* Powerup PCIe */ - if (regulator_enable(sc->regulator)) - device_printf(dev, "Cannot enable regulator\n"); + if (sc->regulator != NULL) { + if (regulator_enable(sc->regulator)) { + device_printf(dev, "Cannot enable regulator\n"); + return (ENXIO); + } + } /* Enable PHY */ - if (phy_enable(sc->phy)) + if (phy_enable(sc->phy)) { device_printf(dev, "Cannot enable phy\n"); + return (ENXIO); + } /* Deassert reset */ - if (hwreset_deassert(sc->hwreset)) + if (hwreset_deassert(sc->hwreset)) { device_printf(dev, "Could not deassert reset\n"); + return (ENXIO); + } /* Enable clocks */ if ((err = clk_enable(sc->aclk_mst))) { @@ -183,7 +205,7 @@ bus_write_4(sc->apb_res, PCIE_CLIENT_GENERAL_CON, (DEVICE_TYPE_MASK << 16) | DEVICE_TYPE_RC); - /* Assert reset PCIe */ + /* Deassert PCIe reset */ if ((err = gpio_pin_set_active(sc->reset_gpio, false))) device_printf(dev, "reset_gpio set failed\n"); @@ -193,9 +215,13 @@ (LINK_REQ_RST_GRT | LTSSM_ENABLE)); DELAY(100000); - /* Release reset */ - if ((err = gpio_pin_set_active(sc->reset_gpio, true))) - device_printf(dev, "reset_gpio release failed\n"); + /* Release PCIe reset */ + if (sc->reset_gpio != NULL) { + if (gpio_pin_set_active(sc->reset_gpio, true)) { + device_printf(dev, "Could not release PCIe reset"); + return (ENXIO); + } + } /* Wait for link up/stable */ for (count = 20; count; count--) { @@ -301,8 +327,9 @@ } /* Get regulator if present */ - if (regulator_get_by_ofw_property(dev, 0, "vpcie3v3-supply", - &sc->regulator)) { + error = regulator_get_by_ofw_property(dev, 0, "vpcie3v3-supply", + &sc->regulator); + if (error != 0 && error != ENOENT) { device_printf(dev, "Cannot get regulator\n"); goto fail; } @@ -314,14 +341,11 @@ } /* Get GPIO reset */ - if (OF_hasprop(sc->node, "reset-gpios")) { - if (gpio_pin_get_by_ofw_property(dev, sc->node, "reset-gpios", - &sc->reset_gpio)) { - device_printf(dev, "Cannot get reset-gpios\n"); - goto fail; - } - gpio_pin_setflags(sc->reset_gpio, GPIO_PIN_OUTPUT); - gpio_pin_set_active(sc->reset_gpio, true); + error = gpio_pin_get_by_ofw_property(dev, sc->node, "reset-gpios", + &sc->reset_gpio); + if (error != 0 && error != ENOENT) { + device_printf(dev, "Cannot get reset-gpios\n"); + goto fail; } /* Get clocks */