From ed56ccbab329f9a07ac264782cc98faf0e8f2b54 Mon Sep 17 00:00:00 2001 From: mmel <mmel@FreeBSD.org> Date: Sun, 18 Aug 2019 08:54:10 +0000 Subject: [PATCH] Enhance support of extres in dwmmc driver. Handle all clocks, regulators and resets defined by dwmmc bindings. MFC after: 2 weeks --- sys/dev/mmc/host/dwmmc.c | 60 +++++++++++++++++++++++++++++++++--- sys/dev/mmc/host/dwmmc_var.h | 5 +++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/sys/dev/mmc/host/dwmmc.c b/sys/dev/mmc/host/dwmmc.c index 57db0e4fc789..ea426df71268 100644 --- a/sys/dev/mmc/host/dwmmc.c +++ b/sys/dev/mmc/host/dwmmc.c @@ -454,8 +454,45 @@ parse_fdt(struct dwmmc_softc *sc) } #ifdef EXT_RESOURCES + + /* IP block reset is optional */ + error = hwreset_get_by_ofw_name(sc->dev, 0, "reset", &sc->hwreset); + if (error != 0 && error != ENOENT) { + device_printf(sc->dev, "Cannot get reset\n"); + goto fail; + } + + /* vmmc regulator is optional */ + error = regulator_get_by_ofw_property(sc->dev, 0, "vmmc-supply", + &sc->vmmc); + if (error != 0 && error != ENOENT) { + device_printf(sc->dev, "Cannot get regulator 'vmmc-supply'\n"); + goto fail; + } + + /* vqmmc regulator is optional */ + error = regulator_get_by_ofw_property(sc->dev, 0, "vqmmc-supply", + &sc->vqmmc); + if (error != 0 && error != ENOENT) { + device_printf(sc->dev, "Cannot get regulator 'vqmmc-supply'\n"); + goto fail; + } + + /* Assert reset first */ + if (sc->hwreset != NULL) { + error = hwreset_assert(sc->hwreset); + if (error != 0) { + device_printf(sc->dev, "Cannot assert reset\n"); + goto fail; + } + } + /* BIU (Bus Interface Unit clock) is optional */ error = clk_get_by_ofw_name(sc->dev, 0, "biu", &sc->biu); + if (error != 0 && error != ENOENT) { + device_printf(sc->dev, "Cannot get 'biu' clock\n"); + goto fail; + } if (sc->biu) { error = clk_enable(sc->biu); if (error != 0) { @@ -469,20 +506,33 @@ parse_fdt(struct dwmmc_softc *sc) * if no clock-frequency property is given */ error = clk_get_by_ofw_name(sc->dev, 0, "ciu", &sc->ciu); + if (error != 0 && error != ENOENT) { + device_printf(sc->dev, "Cannot get 'ciu'clock\n"); + goto fail; + } if (sc->ciu) { - error = clk_enable(sc->ciu); - if (error != 0) { - device_printf(sc->dev, "cannot enable ciu clock\n"); - goto fail; - } if (bus_hz != 0) { error = clk_set_freq(sc->ciu, bus_hz, 0); if (error != 0) device_printf(sc->dev, "cannot set ciu clock to %u\n", bus_hz); } + error = clk_enable(sc->ciu); + if (error != 0) { + device_printf(sc->dev, "cannot enable ciu clock\n"); + goto fail; + } clk_get_freq(sc->ciu, &sc->bus_hz); } + + /* Take dwmmc out of reset */ + if (sc->hwreset != NULL) { + error = hwreset_deassert(sc->hwreset); + if (error != 0) { + device_printf(sc->dev, "Cannot deassert reset\n"); + goto fail; + } + } #endif /* EXT_RESOURCES */ if (sc->bus_hz == 0) { diff --git a/sys/dev/mmc/host/dwmmc_var.h b/sys/dev/mmc/host/dwmmc_var.h index 1aac3880e464..ae4f547a88bd 100644 --- a/sys/dev/mmc/host/dwmmc_var.h +++ b/sys/dev/mmc/host/dwmmc_var.h @@ -35,6 +35,8 @@ #ifdef EXT_RESOURCES #include <dev/extres/clk/clk.h> +#include <dev/extres/hwreset/hwreset.h> +#include <dev/extres/regulator/regulator.h> #endif enum { @@ -83,6 +85,9 @@ struct dwmmc_softc { #ifdef EXT_RESOURCES clk_t biu; clk_t ciu; + hwreset_t hwreset; + regulator_t vmmc; + regulator_t vqmmc; #endif };