From patchwork Fri Aug 18 10:01:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 13357686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93E9BC7113C for ; Fri, 18 Aug 2023 10:04:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359624AbjHRKEY (ORCPT ); Fri, 18 Aug 2023 06:04:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359668AbjHRKEA (ORCPT ); Fri, 18 Aug 2023 06:04:00 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AC96422D; Fri, 18 Aug 2023 03:03:41 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-689f9576babso593795b3a.0; Fri, 18 Aug 2023 03:03:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692352961; x=1692957761; 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=a3IF5QFAnDOaVnC/uZs+WrxnLwpg6ClEv9l9+7GBX6k=; b=Xo1IoN20YaN7ynIhCLHqHMI/Tra1NIYKKsftkrnDrOqRMxCAmw+BFpDwFAbDCfMqLW 3+in21iI3hxluHY90Of8NCGkAO7ZyBfcGLYA5D0qLHG4/I/jDZCCpBzasd4bXbBz6OzO seC+nGdYtwO7SSri+e+SRLWXJ1EP4JYpSKNHRGiSwLoy5y1GNZo+qQ2BtNxir9FXKNMs EmBSqoMoWrZVN7j6AJpQ1Fg/fIDxRkc17wzcVzVqwh3DeEOnWr7mbwxDHCxTXu5NINw/ jqkXJcByjK8N3coyHgXg61+04/TxS16d17wd2+5yoNkKitXDSxalio5zXFdpbLdbWHP3 Dv8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692352961; x=1692957761; 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=a3IF5QFAnDOaVnC/uZs+WrxnLwpg6ClEv9l9+7GBX6k=; b=KxXuFMe66dt0a0Wy8G4qww+SBKhA2Qmbgi+O4otc6L3cmgrbk7IebTAghVO5nWnKoh XdqwFbwTfDiI4baF5T3M4Rlx5YCq3tUlevraKMnZRo/5/SnmAofcI9/J8pOo8nSC1Jcd FM5P55DcjhAbf2FDUZ1OLP99P8umF7l78xRbgT6A3NUktNqpNqr8VW8XSNP990GfwxJ6 GO2zw4a/ekj8e+R+pVCkZfdSrpRDQ10KKkmxnhk7P5uOlq0E56s22aR1UIwhNdWhRJBJ cvTxaool3k2Ov/iBF9EoxTD2MuUKlpWUX9qMPIPQEcj9dfDndlZPIhnFie069AiG1nd9 K7QA== X-Gm-Message-State: AOJu0YzjBC2tXf9GV3fm8Rl6G3Fe3+R0Ef38iy01QXhaUFl4rLsqdF6W vVeLkV1ePn+4cPzHvHeWvGKtN+2oLDI= X-Google-Smtp-Source: AGHT+IF6DvyH+VsLBvhu4VqyzzIW0oxrnPT34UXkuELiTEGqd0ER9k8hm7a0K38VVlrF7qLzXmFSbA== X-Received: by 2002:a05:6a00:1912:b0:668:99aa:3f17 with SMTP id y18-20020a056a00191200b0066899aa3f17mr2209678pfi.16.1692352961256; Fri, 18 Aug 2023 03:02:41 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e25c-55ec-ad14-f925-5202-a39b.emome-ip6.hinet.net. [2001:b400:e25c:55ec:ad14:f925:5202:a39b]) by smtp.gmail.com with ESMTPSA id n22-20020a62e516000000b006870ccfbb54sm1180649pff.196.2023.08.18.03.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 03:02:40 -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 V10 04/23] mmc: core: Extend support for mmc regulators with a vqmmc2 Date: Fri, 18 Aug 2023 18:01:58 +0800 Message-Id: <20230818100217.12725-5-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230818100217.12725-1-victorshihgli@gmail.com> References: <20230818100217.12725-1-victorshihgli@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: Ulf Hansson 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 --- Updates in V10: - Modify the commit message. Updates in V4: - Moved the voltage defines into this patch. --- 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 958c4da0954a..e786e6702932 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 @@ -325,6 +328,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 { @@ -606,6 +610,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, @@ -619,6 +624,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);