From patchwork Tue Dec 13 09:00:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 32710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:8188:b0:89:790f:f786 with SMTP id m8csp3858158dye; Tue, 13 Dec 2022 01:04:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf738SILzzjSPwOIJSt2Ck9/pcFb9xqHneeYZElMWPdhOckYXFWdHNXuYCAPhZa111zUzTLW X-Received: by 2002:a17:902:9696:b0:189:cf92:6f5c with SMTP id n22-20020a170902969600b00189cf926f5cmr19711744plp.52.1670922286726; Tue, 13 Dec 2022 01:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670922286; cv=none; d=google.com; s=arc-20160816; b=atsM3WhWpKzR/aS0lfMLyAXEXi4tk+lm5NomCbGf/t65BnbwjxRHEFdiBNInmPEd5g //vr8bLmZuhDVLKE1GlRWhql461ag+r/fJ0LLQJnp4f7J2mBDmhYm21V+kCA0NJBcCRR EGTMEdntQo5/Svkw0Pz2SiHtmPZlMT9onX151azIzXeeZyveT+MtC6ggLYDmq1srXH8q B7VfenLsH01en2B79XUqUCEsVoLIJm+7kiW4ExT2S/0T4SjGRG1jI1g/ibfTIn/BE+Am UPZyKf64WuqEBPkWN0EYHbN1e2ewOmiOju1IitlCm79HBkvbriA+YR8xa2G62Tl4X5Zk BOrA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y188-20020a6364c5000000b004779a46d07csi12046689pgb.183.2022.12.13.01.04.34; Tue, 13 Dec 2022 01:04:46 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752089008026624748?= X-GMAIL-MSGID: =?utf-8?q?1752089008026624748?= 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);