From owner-svn-src-all@freebsd.org Wed Dec 11 18:41:14 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2EC241DDB51; Wed, 11 Dec 2019 18:41:14 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47Y5Np0SbJz4Tg2; Wed, 11 Dec 2019 18:41:14 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0AF92F783; Wed, 11 Dec 2019 18:41:14 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xBBIfDvi016003; Wed, 11 Dec 2019 18:41:13 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xBBIfDZY016000; Wed, 11 Dec 2019 18:41:13 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201912111841.xBBIfDZY016000@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Wed, 11 Dec 2019 18:41:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355625 - head/sys/dev/mmc/host X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/sys/dev/mmc/host X-SVN-Commit-Revision: 355625 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Dec 2019 18:41:14 -0000 Author: manu Date: Wed Dec 11 18:41:13 2019 New Revision: 355625 URL: https://svnweb.freebsd.org/changeset/base/355625 Log: dwmmc: Add a detach method This method will disable the regulators, clocks and assert the reset of the module. It will also detach it's children (the mmc device) and release it's resources. While here enable the regulators on attach as we need them to power up the sdcard or emmc. MFC after: 1 month Modified: head/sys/dev/mmc/host/dwmmc.c head/sys/dev/mmc/host/dwmmc_rockchip.c head/sys/dev/mmc/host/dwmmc_var.h Modified: head/sys/dev/mmc/host/dwmmc.c ============================================================================== --- head/sys/dev/mmc/host/dwmmc.c Wed Dec 11 18:39:05 2019 (r355624) +++ head/sys/dev/mmc/host/dwmmc.c Wed Dec 11 18:41:13 2019 (r355625) @@ -537,6 +537,22 @@ parse_fdt(struct dwmmc_softc *sc) clk_get_freq(sc->ciu, &sc->bus_hz); } + /* Enable regulators */ + if (sc->vmmc != NULL) { + error = regulator_enable(sc->vmmc); + if (error != 0) { + device_printf(sc->dev, "Cannot enable vmmc regulator\n"); + goto fail; + } + } + if (sc->vqmmc != NULL) { + error = regulator_enable(sc->vqmmc); + if (error != 0) { + device_printf(sc->dev, "Cannot enable vqmmc regulator\n"); + goto fail; + } + } + /* Take dwmmc out of reset */ if (sc->hwreset != NULL) { error = hwreset_deassert(sc->hwreset); @@ -661,8 +677,51 @@ dwmmc_attach(device_t dev) sc->host.caps |= MMC_CAP_HSPEED; sc->host.caps |= MMC_CAP_SIGNALING_330; - device_add_child(dev, "mmc", -1); + sc->child = device_add_child(dev, "mmc", -1); return (bus_generic_attach(dev)); +} + +int +dwmmc_detach(device_t dev) +{ + struct dwmmc_softc *sc; + int ret; + + sc = device_get_softc(dev); + + ret = bus_generic_detach(dev); + if (ret != 0) + return (ret); + + DWMMC_LOCK_DESTROY(sc); + if (sc->intr_cookie != NULL) { + ret = bus_teardown_intr(dev, sc->res[1], sc->intr_cookie); + if (ret != 0) + return (ret); + } + bus_release_resources(dev, dwmmc_spec, sc->res); + + if (sc->child) { + ret = device_delete_child(dev, sc->child); + if (ret != 0) + return (ret); + } + +#ifdef EXT_RESOURCES + if (sc->hwreset != NULL && hwreset_deassert(sc->hwreset) != 0) + device_printf(sc->dev, "cannot deassert reset\n"); + if (sc->biu != NULL && clk_disable(sc->biu) != 0) + device_printf(sc->dev, "cannot disable biu clock\n"); + if (sc->ciu != NULL && clk_disable(sc->ciu) != 0) + device_printf(sc->dev, "cannot disable ciu clock\n"); + + if (sc->vmmc && regulator_disable(sc->vmmc) != 0) + device_printf(sc->dev, "Cannot disable vmmc regulator\n"); + if (sc->vqmmc && regulator_disable(sc->vqmmc) != 0) + device_printf(sc->dev, "Cannot disable vqmmc regulator\n"); +#endif + + return (0); } static int Modified: head/sys/dev/mmc/host/dwmmc_rockchip.c ============================================================================== --- head/sys/dev/mmc/host/dwmmc_rockchip.c Wed Dec 11 18:39:05 2019 (r355624) +++ head/sys/dev/mmc/host/dwmmc_rockchip.c Wed Dec 11 18:41:13 2019 (r355625) @@ -133,6 +133,7 @@ static device_method_t rockchip_dwmmc_methods[] = { /* bus interface */ DEVMETHOD(device_probe, rockchip_dwmmc_probe), DEVMETHOD(device_attach, rockchip_dwmmc_attach), + DEVMETHOD(device_detach, dwmmc_detach), DEVMETHOD_END }; Modified: head/sys/dev/mmc/host/dwmmc_var.h ============================================================================== --- head/sys/dev/mmc/host/dwmmc_var.h Wed Dec 11 18:39:05 2019 (r355624) +++ head/sys/dev/mmc/host/dwmmc_var.h Wed Dec 11 18:41:13 2019 (r355625) @@ -61,6 +61,7 @@ struct dwmmc_softc { uint32_t use_pio; uint32_t pwren_inverted; u_int desc_count; + device_t child; int (*update_ios)(struct dwmmc_softc *sc, struct mmc_ios *ios); @@ -94,5 +95,6 @@ struct dwmmc_softc { DECLARE_CLASS(dwmmc_driver); int dwmmc_attach(device_t); +int dwmmc_detach(device_t); #endif