Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8053207rwb; Tue, 13 Dec 2022 01:15:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6kzGdY85CE3NzW02kE3WkAjpIUFhLOXoMV00dsSeHfIriNRYE/05ZEEx8u8qOUOhdaXacz X-Received: by 2002:a05:6a00:21c2:b0:56b:baf3:ad8b with SMTP id t2-20020a056a0021c200b0056bbaf3ad8bmr23660931pfj.6.1670922911887; Tue, 13 Dec 2022 01:15:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670922911; cv=none; d=google.com; s=arc-20160816; b=cdQEsNhzNzTFEqdgW6dFy5pVNAIDvhqmBuXpeKaeW0EyPliYhXycot8F498rvuzHu7 Hh8QTnQ9u9s4wwtczs9m9FKYWcJ5UdMdpN39EEYAKIMGWtLd37+CTtGrP5au7s4mZgWk Vg1RganLnsG6c9R/IqecAcDPjtIbZtYZVZvlOyg+q94BNOSZtTuVwLMiqUBjfUe5kY9+ Tg0vvu4K0JhpVOUlWLTxeDh2K/WCaERK40e3HSNc+0S1N6hPBK8offSSjxIVzSzGGf50 4b2lIxHtbHwJOkRJuNwiocf9EAbx6LuxOsuWM2aKc/IWBZJWTX00LFy6hsNiUkQIDWi1 U01w== 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=e/VYYTH35eMukzyNpI36t8nzdr9tycZ4oeZLcYIOrT8=; b=mGVf4FNoWulTyC34m1kTBIbK8OADA6faZ12lNE5jhFpN/YgYkj46i5L+4SOG4UAjms s78dygEd8iTfaACCzQP85A001VY20Di4rleWeqawvfGSLqAY1E8gM4wQyQnd+hakvIRS AHOry0yVUU9rJvBKnhl9aspwVQwisJ8qZzjm9molj7Zaj3JWQ0hXtMB47DKEc6BXuuNZ XWX3KxnII6nrEBLOxfdNDFU56tyk+/PGZAq1ypMUubMXV5gGXKkzl1FDzNNNNxDzF2+7 gPmN1In1jaiSJJ6iEtlmZfR8BFIX3TR+PJr6B9hx+Sp4SDhYGl0ajSFxrvz+j5xrNrQx BsEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UQXvkCRy; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p14-20020a056a000b4e00b005776a379a5asi12914420pfo.167.2022.12.13.01.15.02; Tue, 13 Dec 2022 01:15:11 -0800 (PST) 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=20210112 header.b=UQXvkCRy; 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 S234861AbiLMJBh (ORCPT + 74 others); Tue, 13 Dec 2022 04:01:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234803AbiLMJBY (ORCPT ); Tue, 13 Dec 2022 04:01:24 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 720ECF01E; Tue, 13 Dec 2022 01:01:17 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id 82so10019096pgc.0; Tue, 13 Dec 2022 01:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=e/VYYTH35eMukzyNpI36t8nzdr9tycZ4oeZLcYIOrT8=; b=UQXvkCRykSmhhm2/6D0LbCPixYNY2zizGMDSgkX71YKlPOefvpf5wphXCXpwnqfJqe KgMI0l/cWlYJJmhaZjGMZgz9zzYsR1DP7HLNKxRgcDBI3e3Hrz8vR1e0ezMU4Uaaig+O UVGM+4l12hwO7xGrkTkF0Lhh66FC8sjH2XRxRVnuq2V/NFvsmDWv+ApATRGLRbMoXzoY HyYvbsDx/JK7pUWAHdy5Xy56mppQtRIf3Kok5/Ah1w1qgMd+Vc0bBpvDzfEBttFuW5+K COnTwp0wxcIgwldQEGnO1U9POjbJY3XOHLFl1kZXB8qMt2Ei44sKbwjO0GRdxTKDVtNk wnMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=e/VYYTH35eMukzyNpI36t8nzdr9tycZ4oeZLcYIOrT8=; b=F5uXb+AqDLxv+ItdOfP0B06AMFR0Nu2C8rc/+Z8Jv6GYiP1p6LtFlwKJC1QkOQmUtw j1sEwCLBPH3vdlVjgOtnP4IDXsSbW3G3+M3yJmVPCZwjNEinp2L0QxfNKClpwS67NA64 7AEEYlgNWVRAx6Ea6gcD057s0pY3hIs+seA5rcd09axlPCEBAelQ+dB0fEht68UMyjDl mo43ojKWprNjoQ+QypzruAG93cbmdVEJbxfJl/0FgiaOs2E+PaklNHv+84DfkYftxbNK Z1Lqchezv+Td6xKN1fBlZBIh1uYCxAkNWD4nNgmKxFgZnA68bPBU6ROs487S/VkRfYMG etyg== X-Gm-Message-State: ANoB5pmda1JQqRRALHXAktyi33q9Ew///5hCrt1A+4h44/iQow/l7oMH 1B+BgGxFz/8E/bO5mOwqOns= X-Received: by 2002:a62:4ece:0:b0:577:3126:704d with SMTP id c197-20020a624ece000000b005773126704dmr20021853pfb.17.1670922076920; Tue, 13 Dec 2022 01:01:16 -0800 (PST) Received: from localhost.localdomain (2001-b400-e2dc-5c03-264b-f684-a8c9-21ae.emome-ip6.hinet.net. [2001:b400:e2dc:5c03:264b:f684:a8c9:21ae]) by smtp.gmail.com with ESMTPSA id 81-20020a621954000000b0056b9ec7e2desm7141682pfz.125.2022.12.13.01.01.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 01:01:15 -0800 (PST) From: Victor Shih X-Google-Original-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 V6 04/24] mmc: core: Extend support for mmc regulators with a vqmmc2 Date: Tue, 13 Dec 2022 17:00:27 +0800 Message-Id: <20221213090047.3805-5-victor.shih@genesyslogic.com.tw> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221213090047.3805-1-victor.shih@genesyslogic.com.tw> References: <20221213090047.3805-1-victor.shih@genesyslogic.com.tw> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 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 609201a467ef..3c189682797c 100644 --- a/drivers/mmc/core/regulator.c +++ b/drivers/mmc/core/regulator.c @@ -223,6 +223,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) @@ -249,6 +276,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) @@ -268,6 +296,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 150d10d5e6f8..895bcf7f80b7 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -71,6 +71,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 @@ -321,6 +324,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 { @@ -600,6 +604,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, @@ -613,6 +618,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); -- 2.25.1