From patchwork Tue Jan 18 12:43:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jason X-Patchwork-Id: 12716292 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 3D914C433EF for ; Tue, 18 Jan 2022 12:44:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237302AbiARMoP (ORCPT ); Tue, 18 Jan 2022 07:44:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237441AbiARMoP (ORCPT ); Tue, 18 Jan 2022 07:44:15 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC5DC061574 for ; Tue, 18 Jan 2022 04:44:15 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id s61-20020a17090a69c300b001b4d0427ea2so1919959pjj.4 for ; Tue, 18 Jan 2022 04:44:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RwJodhK2/6cKagq8a9RdnpdmwWUwFSsHR4MCeVz1ADc=; b=aJCcFDtVQ/krYQpqnFZbgNHrAg3QlV51s45HtUtOgSZM6PUQfkHHw3xLepw1DR4mnq 1FcYcEFQSfLOtkwej3F1z3V7/zVk+OOATagRV3rxAknQO8PuO9zoWuIGEIsAwNnq91Qv YQGoMuQVqCpDABiOvfMTnaZ2oKLmQ29t1Q8Zop/dk9qiMexLazi7MiaLQ+NwVsmYC1Tg 5IfW62+fruN3rTYoCfNYEPVEIM8T2b1NMBkpQrPZJPv5u2J+SsKwNWTp4h+ulWfA2DBB E6wBd+jpD/j6e347lrDrb75hwGgMjTaQ6iMMxoYNg2ecbL9FX9YolYafRA96tf/3x92B WZdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RwJodhK2/6cKagq8a9RdnpdmwWUwFSsHR4MCeVz1ADc=; b=UKqhwPx7scxhcnDnuqBeFeC19vtvpx7e7SZmmAIYggYmUkGwboE39NHUKE8SDWYU7c KKZpmPgVZlhr8o/GrCYqIxf1e7aG7ozk5GsHTK+k34DWHJr48nCXYdy7v5uQLEGZ7EVQ sDF/gbX2kGbALdIScqa6SoclhwF3J/NIkMI2PmoERNtkShhhHP2ZDajKO1PlzPvfPgtR loEuYx5l7rawN62Dj5Vvh9woJe0uJRdbjmQ180uDMYyrYaJw3aaChB+vVMagyUjX2Clc HR2djKAnyliY5ml1MnBUIASZqv1Y3wqE+Z01ohb/RnIxHCBzvh7Jtsps7zjra0anlPg0 g4RA== X-Gm-Message-State: AOAM5320aEd6fmwftbcYyAWc76usy1/H7ONiK537LxKz7EbVKDrkHx8+ 3VdMeIFPbNwMWSCfynJA6Yg= X-Google-Smtp-Source: ABdhPJyZ/yDEoUqhOlpzvUNS9LpUmnU1bSpt+h37Y/uxPuVaxHB+XiYj6p2e3D/ZcuQXSX+NdwGbOA== X-Received: by 2002:a17:90a:ab02:: with SMTP id m2mr1565358pjq.198.1642509854809; Tue, 18 Jan 2022 04:44:14 -0800 (PST) Received: from jason-z170xgaming7.genesyslogic.com.tw (60-251-58-169.hinet-ip.hinet.net. [60.251.58.169]) by smtp.gmail.com with ESMTPSA id n10sm362005pfj.120.2022.01.18.04.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 04:44:14 -0800 (PST) From: Jason Lai To: ulf.hansson@linaro.org, takahiro.akashi@linaro.org, adrian.hunter@intel.com Cc: linux-mmc@vger.kernel.org, ben.chuang@genesyslogic.com.tw, greg.tu@genesyslogic.com.tw, jason.lai@genesyslogic.com.tw, otis.wu@genesyslogic.com.tw, Jason Lai Subject: [PATCH v2 4/7] mmc: core: Extend support for mmc regulators with a vqmmc2 Date: Tue, 18 Jan 2022 20:43:52 +0800 Message-Id: <20220118124355.167552-5-jasonlai.genesyslogic@gmail.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220118124355.167552-1-jasonlai.genesyslogic@gmail.com> References: <20220118124355.167552-1-jasonlai.genesyslogic@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 --- drivers/mmc/core/regulator.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 8 ++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/mmc/core/regulator.c b/drivers/mmc/core/regulator.c index 609201a46..3c1896827 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 91065ab7f..69f8c8a8f 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -303,6 +303,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 { @@ -580,6 +581,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, @@ -593,6 +595,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);