From patchwork Fri Jul 21 10:13:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 123782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp115908vqg; Fri, 21 Jul 2023 03:49:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlEgLW0PIYXChlfg49S1wXkIpdPURKjIHhlZ7DEnqX95iV1D+hPlojxfZGLAcn7LirQqfkez X-Received: by 2002:a05:6870:1cb:b0:1b7:27f7:da8d with SMTP id n11-20020a05687001cb00b001b727f7da8dmr1883565oad.38.1689936598431; Fri, 21 Jul 2023 03:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689936598; cv=none; d=google.com; s=arc-20160816; b=mRY+26jnRI7Tn2vD8UkPRtWnvbAUJIMAYtH4Cirdfc3QPAlNzfUqAWgaml5D/0aiFH o+xOR1FTj3P4KOq7fnwaP8vGkxAT4MIha5e70lLxM/k/4n9llvXkJb24re1rEi2y6dcF jkRexI+vR5D/2l4CPVkgy0Ke1/dp6d6ilT5Woq7T12wx00Exj5G7Zt4Bs/K4uozJFXxU 9ya0xwZVq/1bLOYliMNAISg6dmYQr4QbRh6KnRGQ8pdZ1uCjQ9bg/wf81+C0BkHEfg3i BWnUt77+KTAeEatzvWfDKNEvUoboWTp/UZgUHAt4IGmv8WM2GLVPuysA1tz6f2JU6hg+ Z7zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=31fs7T26pswe7Ec2s7KzLb33EdY+Zlh+1iKINwcUZUo=; fh=aZbD6vIoztiNqTfT9U0ALtDeO+En2lq/Pmnvw9tY2p0=; b=FawDSiFuSCKnZxmAIZMG0fEbtg67aZ0UFNDT4YUwOMx6V8X90OiemXTqgtdGoDZ60h KDMjNYaeYZz5+dj9RoyetCxXnakRTr3GohDGWlfWu2rHQZZITdWv+kG0Ami/TaMom6er 3Mz3B5wumTt+Gz0CXsJoFJrthTth1aTAKK90TGcjq0RNEtgL3dJPNSbpqZXCSf38HdY9 Aly4lvB2mJIu6QBLc3RgTAxLrZCi/eLfSibS64G9RMBBgkfq83Xr2KFyq1FGCK7nbmpx yIeRJ6fBFeXDsWIhQg1LRSb277s1haMkFSj8GS/bpvbvKlLUp/rv4RsKE0xYuOc1p4Ql 3yFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Thr1Emik; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a25-20020a056a001d1900b00668717a964fsi2724080pfx.33.2023.07.21.03.49.44; Fri, 21 Jul 2023 03:49:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Thr1Emik; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjGUKOo (ORCPT + 99 others); Fri, 21 Jul 2023 06:14:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230082AbjGUKOY (ORCPT ); Fri, 21 Jul 2023 06:14:24 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A46F198A; Fri, 21 Jul 2023 03:14:23 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-55b1238cab4so940161a12.2; Fri, 21 Jul 2023 03:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689934462; x=1690539262; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=31fs7T26pswe7Ec2s7KzLb33EdY+Zlh+1iKINwcUZUo=; b=Thr1Emikb6RRfEmHDbEm7Kd11mcNx7jJLBe5BKlIw8SZXr+P/QChxcr+xS7KMjk/hF 4d9hQs2ed2Htb3Er5U0AXKs04k/cEMuxeMSHXu3OA9ceATf5zG2c2gNEEv5pudcOj1Vs IanX6GvDhmtbVymalBEcinw/jQZG5Gm9R+OMom4SwFqCpWBRu5lXknNqfd1OZ9EQbGHU jaR8pHtznQDra9ozMrWyRuMwTFfgnHWfcRzm8VzplhyQfHJ4XM8Cx0DtGN4S9bpDJA5I rQHw2w2b3BiLyR2GL1XwHyHATLpgBr6ffFQcGnjfbci8XyMwf9SBX5Ac+gbqJKQc30cE pMWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689934462; x=1690539262; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=31fs7T26pswe7Ec2s7KzLb33EdY+Zlh+1iKINwcUZUo=; b=glp0UjI9nljwNVWCaMVE1+LwBTT1FIqNrnidKIefcODgovcGhCvnKbKBG8IQzCSPLW xwCEeCFWkaZ0o4oFZdStxVgn86nGI6sWc/7OsRGeIc2hWpB+eot0vy6K4Jq8HkmQhBcH 6MhxMRj/FFSrDHJ5TXiifEsOX01AfsyyXbai2mNC9L02idWf75xrcsdGQd5LOzdC3tt6 4JZCT7QCMBlcxI+LT34DDAHSJ3HudRlfHgOXSqGCbabkD9mw0oQg6b87CCtX7srSXo2x IXinKY8UQkAnl/tlZ5XBrFn9iLZEX36FvJfAdHiHjBcVWbYHhqnt1xpvvKtlewsc4XPy JMdw== X-Gm-Message-State: ABy/qLZV2kjQyxaroX+gFyYb+57/OjJgTA80Idc2Hijzf0E/mlfwtDrg xfixLrrOQw5I7My0aMf/Zc8= X-Received: by 2002:a05:6a20:96d5:b0:134:15df:b148 with SMTP id hq21-20020a056a2096d500b0013415dfb148mr1183293pzc.29.1689934462485; Fri, 21 Jul 2023 03:14:22 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e23e-6b0d-6c46-3684-497a-06ee.emome-ip6.hinet.net. [2001:b400:e23e:6b0d:6c46:3684:497a:6ee]) by smtp.gmail.com with ESMTPSA id y1-20020a170902b48100b001b86492d724sm3050719plr.223.2023.07.21.03.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 03:14:22 -0700 (PDT) From: Victor Shih To: ulf.hansson@linaro.org, adrian.hunter@intel.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, benchuanggli@gmail.com, HL.Liu@genesyslogic.com.tw, Greg.tu@genesyslogic.com.tw, takahiro.akashi@linaro.org, dlunev@chromium.org, Victor Shih Subject: [PATCH V9 04/23] mmc: core: Extend support for mmc regulators with a vqmmc2 Date: Fri, 21 Jul 2023 18:13:30 +0800 Message-Id: <20230721101349.12387-5-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721101349.12387-1-victorshihgli@gmail.com> References: <20230721101349.12387-1-victorshihgli@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772026958337058517 X-GMAIL-MSGID: 1772026958337058517 From: Ulf Hansson Updates in V4: - Moved the voltage defines into this patch. Update in previous version: To allow an additional external regulator to be controlled by an mmc host driver, let's add support for a vqmmc2 regulator to the mmc core. For an SD UHS-II interface the vqmmc2 regulator may correspond to the so called vdd2 supply, as described by the SD spec. Initially, only 1.8V is needed, hence limit the new helper function, mmc_regulator_set_vqmmc2() to this too. Note that, to allow for flexibility mmc host drivers need to manage the enable/disable of the vqmmc2 regulator themselves, while the regulator is looked up through the common mmc_regulator_get_supply(). Signed-off-by: Ulf Hansson --- drivers/mmc/core/regulator.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/mmc/core/regulator.c b/drivers/mmc/core/regulator.c index 005247a49e51..208c27cfa505 100644 --- a/drivers/mmc/core/regulator.c +++ b/drivers/mmc/core/regulator.c @@ -226,6 +226,33 @@ int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios) } EXPORT_SYMBOL_GPL(mmc_regulator_set_vqmmc); +/** + * mmc_regulator_set_vqmmc2 - Set vqmmc2 as per the ios->vqmmc2_voltage + * @mmc: The mmc host to regulate + * @ios: The io bus settings + * + * Sets a new voltage level for the vqmmc2 regulator, which may correspond to + * the vdd2 regulator for an SD UHS-II interface. This function is expected to + * be called by mmc host drivers. + * + * Returns a negative error code on failure, zero if the voltage level was + * changed successfully or a positive value if the level didn't need to change. + */ +int mmc_regulator_set_vqmmc2(struct mmc_host *mmc, struct mmc_ios *ios) +{ + if (IS_ERR(mmc->supply.vqmmc2)) + return -EINVAL; + + switch (ios->vqmmc2_voltage) { + case MMC_VQMMC2_VOLTAGE_180: + return mmc_regulator_set_voltage_if_supported( + mmc->supply.vqmmc2, 1700000, 1800000, 1950000); + default: + return -EINVAL; + } +} +EXPORT_SYMBOL_GPL(mmc_regulator_set_vqmmc2); + #else static inline int mmc_regulator_get_ocrmask(struct regulator *supply) @@ -252,6 +279,7 @@ int mmc_regulator_get_supply(struct mmc_host *mmc) mmc->supply.vmmc = devm_regulator_get_optional(dev, "vmmc"); mmc->supply.vqmmc = devm_regulator_get_optional(dev, "vqmmc"); + mmc->supply.vqmmc2 = devm_regulator_get_optional(dev, "vqmmc2"); if (IS_ERR(mmc->supply.vmmc)) { if (PTR_ERR(mmc->supply.vmmc) == -EPROBE_DEFER) @@ -271,6 +299,12 @@ int mmc_regulator_get_supply(struct mmc_host *mmc) dev_dbg(dev, "No vqmmc regulator found\n"); } + if (IS_ERR(mmc->supply.vqmmc2)) { + if (PTR_ERR(mmc->supply.vqmmc2) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_dbg(dev, "No vqmmc2 regulator found\n"); + } + return 0; } EXPORT_SYMBOL_GPL(mmc_regulator_get_supply); diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 2e3748e4f14d..6f1be9993e16 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -74,6 +74,9 @@ struct mmc_ios { #define MMC_SIGNAL_VOLTAGE_180 1 #define MMC_SIGNAL_VOLTAGE_120 2 + unsigned char vqmmc2_voltage; +#define MMC_VQMMC2_VOLTAGE_180 0 + unsigned char drv_type; /* driver type (A, B, C, D) */ #define MMC_SET_DRIVER_TYPE_B 0 @@ -343,6 +346,7 @@ struct mmc_pwrseq; struct mmc_supply { struct regulator *vmmc; /* Card power supply */ struct regulator *vqmmc; /* Optional Vccq supply */ + struct regulator *vqmmc2; /* Optional supply for phy */ }; struct mmc_ctx { @@ -628,6 +632,7 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc, struct regulator *supply, unsigned short vdd_bit); int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios); +int mmc_regulator_set_vqmmc2(struct mmc_host *mmc, struct mmc_ios *ios); #else static inline int mmc_regulator_set_ocr(struct mmc_host *mmc, struct regulator *supply, @@ -641,6 +646,12 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, { return -EINVAL; } + +static inline int mmc_regulator_set_vqmmc2(struct mmc_host *mmc, + struct mmc_ios *ios) +{ + return -EINVAL; +} #endif int mmc_regulator_get_supply(struct mmc_host *mmc);