From owner-dev-commits-src-main@freebsd.org Wed Jun 2 08:05:10 2021 Return-Path: Delivered-To: dev-commits-src-main@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 B626D63D98B; Wed, 2 Jun 2021 08:05:10 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fw1m56h2Bz4YM1; Wed, 2 Jun 2021 08:05:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B84561326A; Wed, 2 Jun 2021 08:05:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1528590p073043; Wed, 2 Jun 2021 08:05:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 152859GX073042; Wed, 2 Jun 2021 08:05:09 GMT (envelope-from git) Date: Wed, 2 Jun 2021 08:05:09 GMT Message-Id: <202106020805.152859GX073042@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Marcin Wojtas Subject: git: c80e2ca57e0c - main - sdhci_xenon: improve the VCCQ voltage switch sequence MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mw X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c80e2ca57e0c1b3647b55471584c6d32214232ea Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2021 08:05:11 -0000 The branch main has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=c80e2ca57e0c1b3647b55471584c6d32214232ea commit c80e2ca57e0c1b3647b55471584c6d32214232ea Author: Marcin Wojtas AuthorDate: 2021-05-27 18:39:12 +0000 Commit: Marcin Wojtas CommitDate: 2021-06-02 07:55:20 +0000 sdhci_xenon: improve the VCCQ voltage switch sequence Improve the VCCQ voltage switch, so that to properly handle the SDHCI_HOST_CONTROL2 register signaling flags and along with manipulating the regulator. Reviewed by: manu Obtained from: Semihalf Sponsored by: Marvell Differential Revision: https://reviews.freebsd.org/D30564 MFC after: 2 weeks --- sys/dev/sdhci/sdhci_xenon.c | 84 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/sys/dev/sdhci/sdhci_xenon.c b/sys/dev/sdhci/sdhci_xenon.c index f92d02608abb..42f36b619b36 100644 --- a/sys/dev/sdhci/sdhci_xenon.c +++ b/sys/dev/sdhci/sdhci_xenon.c @@ -388,35 +388,87 @@ sdhci_xenon_switch_vccq(device_t brdev, device_t reqdev) { struct sdhci_xenon_softc *sc; struct sdhci_slot *slot; + uint16_t hostctrl2; int uvolt, err; + slot = device_get_ivars(reqdev); + + if (slot->version < SDHCI_SPEC_300) + return (0); + sc = device_get_softc(brdev); if (sc->mmc_helper.vqmmc_supply == NULL) return EOPNOTSUPP; - slot = device_get_ivars(reqdev); + err = 0; + + hostctrl2 = bus_read_2(sc->mem_res, SDHCI_HOST_CONTROL2); switch (slot->host.ios.vccq) { - case vccq_180: - uvolt = 1800000; - break; case vccq_330: + if (!(hostctrl2 & SDHCI_CTRL2_S18_ENABLE)) + return (0); + hostctrl2 &= ~SDHCI_CTRL2_S18_ENABLE; + bus_write_2(sc->mem_res, SDHCI_HOST_CONTROL2, hostctrl2); + uvolt = 3300000; - break; + err = regulator_set_voltage(sc->mmc_helper.vqmmc_supply, + uvolt, uvolt); + if (err != 0) { + device_printf(sc->dev, + "Cannot set vqmmc to %d<->%d\n", + uvolt, + uvolt); + return (err); + } + + /* + * According to the 'SD Host Controller Simplified + * Specification 4.20 the host driver should take more + * than 5ms for stable time of host voltage regulator + * from changing 1.8V Signaling Enable. + */ + DELAY(5000); + hostctrl2 = bus_read_2(sc->mem_res, SDHCI_HOST_CONTROL2); + if (!(hostctrl2 & SDHCI_CTRL2_S18_ENABLE)) + return (0); + return EAGAIN; + case vccq_180: + if (!(slot->host.caps & MMC_CAP_SIGNALING_180)) { + return EINVAL; + } + if (hostctrl2 & SDHCI_CTRL2_S18_ENABLE) + return (0); + hostctrl2 |= SDHCI_CTRL2_S18_ENABLE; + bus_write_2(sc->mem_res, SDHCI_HOST_CONTROL2, hostctrl2); + + uvolt = 1800000; + err = regulator_set_voltage(sc->mmc_helper.vqmmc_supply, + uvolt, uvolt); + if (err != 0) { + device_printf(sc->dev, + "Cannot set vqmmc to %d<->%d\n", + uvolt, + uvolt); + return (err); + } + + /* + * According to the 'SD Host Controller Simplified + * Specification 4.20 the host driver should take more + * than 5ms for stable time of host voltage regulator + * from changing 1.8V Signaling Enable. + */ + DELAY(5000); + hostctrl2 = bus_read_2(sc->mem_res, SDHCI_HOST_CONTROL2); + if (hostctrl2 & SDHCI_CTRL2_S18_ENABLE) + return (0); + return EAGAIN; default: + device_printf(brdev, + "Attempt to set unsupported signaling voltage\n"); return EINVAL; } - - err = regulator_set_voltage(sc->mmc_helper.vqmmc_supply, uvolt, uvolt); - if (err != 0) { - device_printf(sc->dev, - "Cannot set vqmmc to %d<->%d\n", - uvolt, - uvolt); - return (err); - } - - return (0); } static int