From patchwork Fri Mar 31 10:55:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 77736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp479114vqo; Fri, 31 Mar 2023 04:09:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ZYvq6jsJ03wXSNIKxtXI3w/9yLUBZEof8/J38KdozWsC4HZRSkgQthAEj73QFkqHKMAoUg X-Received: by 2002:a05:6a20:4a30:b0:df:4e86:9c99 with SMTP id fr48-20020a056a204a3000b000df4e869c99mr17680777pzb.55.1680260984461; Fri, 31 Mar 2023 04:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680260984; cv=none; d=google.com; s=arc-20160816; b=OfbYmC2tVDfyWAi3YIQ+xseMPr+WNUktcc7Pa3ZKQTqNq6XyL+4SaYE1rdZXDNMvzY 2ugZd0F7nr2LoyHDQVRDfEniWVrWo8JuViw5lUMWrCVwbh2sgG/SQdgXmsyMRnm3v2h4 tavGJ99uG8pl0UdDXUDd1adTkqthauiquhV0jypaKFcgT9J8kVOBFO85Z3MOdyWpx1By 01AN+0r2DqdMMHV5NvOXyTaKXGHdPLdDC/6P7hNPne4MLY9CYpa5xLhfaOiHAYyhXftL lGy7wy9oniPHzr+Z/iP2SmkdoBY8sSgbMzX8kgjO+Dkz9oDPVjQbndlR8OvMbj3h1Ei2 R7rA== 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=4nxZ6ysc0NWh8raehRAJJdNoEHZEjQQLqxHOoCPHHTo=; b=MXqVxspMOV3ZZPgAs9QxPTMcw0+oibvOQLnf9amHJh/IM0+VlLM8eA0K+TeyimxpwH o06lZKYcDHRvSOMEpaTyeKYo7dIkp4aGJOEVODiSSCrBYWparzgCk2jJC60wtc45ubYI rEcb4f/iGYZgmkfEyrWHlVYFFp/0RDzRHoKwV/CscFAQqXpnjfObz9pmuVkqJbq9kPTc A5iI+jUxvR6P52Udyu4ax+qV1a3ZExWXFnDo0e5xBnAd4RApuesotVAumGayLtAAOJs7 svpI5YcKC4nFBx+FSGFqBzICtaMKwN6wOPL9nZiGBqHGQO19COhuPXCi7dzSYAGBP2F9 S8aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="G/m/Ch+x"; 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 h124-20020a636c82000000b0050b51e62c19si2052976pgc.825.2023.03.31.04.09.32; Fri, 31 Mar 2023 04:09:44 -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=20210112 header.b="G/m/Ch+x"; 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 S231825AbjCaK44 (ORCPT + 99 others); Fri, 31 Mar 2023 06:56:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbjCaK41 (ORCPT ); Fri, 31 Mar 2023 06:56:27 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ADEA1D2FF; Fri, 31 Mar 2023 03:56:17 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id h12-20020a17090aea8c00b0023d1311fab3so22960318pjz.1; Fri, 31 Mar 2023 03:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680260177; 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=4nxZ6ysc0NWh8raehRAJJdNoEHZEjQQLqxHOoCPHHTo=; b=G/m/Ch+xFFuDeZPu8cxR+T17IjUad2Haj0sd6CNs/7OmVVTpO+X/h6HvDf6vDWKdza eY8NcGX6r1wUrTSinX6eugftnMxzCL/U7HtaAVJQsXfwiTumywnRxvrWqSIqtz5Nfc35 gHDKp2ivEWjMnzalHZSEgkjzf94NMzUShTxD4z9ev+d7OHShPKpEHTml30+hExruUchB 2uC5+1YcRdgd/Wx2TlEEfI9QcE3cC41j3EVrYmMis75ex6VmfwDRhhlqaCDdRIkXfjGL sFlSAmT3HT985w0R7GAOxYGFcUg2xj/NFZ/T/q8t6YrckwXVczsmHqw47NENfCmFjrLz a83A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680260177; 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=4nxZ6ysc0NWh8raehRAJJdNoEHZEjQQLqxHOoCPHHTo=; b=QU068WaWY5W3WrN/yDb85pI41HY4ESrw7DSJTI/wVWfWvPWi33CdQYnw54XMxMPhE4 0Wc78MXgd/fB1NAaLKYLMzUqFR3HcSmhIhHIzb9sZKyzR9GsYwoKeSkxgGoRJRSh9KbP eVphQbdiWvZasng5ihVRfnvsgdY+xatpHUKMMlRcDPK0UPU9Nv09TD/fQUR1vuBwZtyy hyr5oiWpodsqftiHmaL51945B+thNb4qEynBR9GmDWyOTt551hTEbnMUYBg09sauv/VI gtoZsVU4qQVZGgDpUuZ+wMhB60ImwvSHw0vIa4VZUoHMs8q1HRhSoExzDTP+Pm865Rq1 EisQ== X-Gm-Message-State: AAQBX9el3LV6jz70T4WlTDBdkAQ07IDrcfhVBsttdpyCQff8owaDXgan UO3DDznzJGQHaTau97r0MAs= X-Received: by 2002:a17:903:11c4:b0:1a1:a727:a7fd with SMTP id q4-20020a17090311c400b001a1a727a7fdmr30907595plh.29.1680260177019; Fri, 31 Mar 2023 03:56:17 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e25c-983f-c7ff-3efd-77d9-6c16.emome-ip6.hinet.net. [2001:b400:e25c:983f:c7ff:3efd:77d9:6c16]) by smtp.gmail.com with ESMTPSA id f19-20020a170902e99300b0019acd3151d0sm1287665plb.114.2023.03.31.03.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 03:56:16 -0700 (PDT) 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 V7 04/23] mmc: core: Extend support for mmc regulators with a vqmmc2 Date: Fri, 31 Mar 2023 18:55:27 +0800 Message-Id: <20230331105546.13607-5-victor.shih@genesyslogic.com.tw> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230331105546.13607-1-victor.shih@genesyslogic.com.tw> References: <20230331105546.13607-1-victor.shih@genesyslogic.com.tw> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1761881342395736458?= X-GMAIL-MSGID: =?utf-8?q?1761881342395736458?= 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 a27bb520bf9a..703f5ce9713c 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 @@ -324,6 +327,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 { @@ -605,6 +609,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, @@ -618,6 +623,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);