From patchwork Fri Sep 15 09:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 140524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1158198vqi; Fri, 15 Sep 2023 09:10:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVXK7x8WZLENa9VNngtKFB+TXC5DIf3VrnFslmjI412xca8koXvlKEWjtrxu8xGV3mf7Lh X-Received: by 2002:a17:902:e80a:b0:1b3:d4d5:beb2 with SMTP id u10-20020a170902e80a00b001b3d4d5beb2mr2378130plg.9.1694794210850; Fri, 15 Sep 2023 09:10:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694794210; cv=none; d=google.com; s=arc-20160816; b=eVnDx+8luRicFmphILhrJAUOjmDE4j8tGU1YWvUCImT7c73F7+ruEUrRLfv3GYBMQq w3MN3NVs2kogM7la5/DcrfmvLT3i/MFQUhSgoNgjbKNTUmyN3lyvBBHQpR0CG76hEu8l Tn+Lk/vB4DNKAGWyC72WHcVgHK5zpFzKonPmpqgLl22nwi2UVbXDqmA+O7mU13AsBMNH DV6QYZtgY6QSvr+DVdVXdt5+Ejy+vtyKI96b6iS5u6E8z//G7w0IS+LTUVzc8N4gugHu eNjRVCElni5841TuTJqSCpLs5EdMZ7TaO6dRhi9HOyIh6Kgqoxp5r37twZFndYKiWj3h XWog== 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=8neypDPalnwcRyMDJSfFLCSaijYuZSqHnClQI/QiH6o=; fh=KOtNjZfRPCjQZphSIMptO02uH7FbEAONyvdGOPNH0yk=; b=s+Q9cha1BqftipdJ5jIPSWVyw3UIihM7r+ZHp0xdWqIQi4gcHAOVdgoWI/JhqmHTPW 0bBzqWWChMW5t43+Pvo0Vj87UqhYetCjaf20XgWpbBu2a1mAHfwfdYrLZ4LO1d9/0FsE DMiXtR4hFWbPp1nOkntD/q3i1yy8G3PR3Zo0j9PX0sV9M9MU5r1tRSaXTPbSqT83Q14W 912h8H1OZ1q7ErDwzd326/I3pagtq9RVnDupKhiZHX9q6GXI58PA3NOQXGnzULunCAvk PbjHKcdLfBCjq5VuHbdRbMmSp7myij9EIvLgjEij2l+XC5nwwQzIVF8ffOhshDx+uM+H G5ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Op0JztWV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id n10-20020a170902e54a00b001b89fd6bec4si3761395plf.144.2023.09.15.09.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:10:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Op0JztWV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 12153836FEA5; Fri, 15 Sep 2023 02:45:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233908AbjIOJok (ORCPT + 32 others); Fri, 15 Sep 2023 05:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233841AbjIOJoe (ORCPT ); Fri, 15 Sep 2023 05:44:34 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E3E3272C; Fri, 15 Sep 2023 02:44:09 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-274928c74b0so619033a91.3; Fri, 15 Sep 2023 02:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694771049; x=1695375849; darn=vger.kernel.org; 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=8neypDPalnwcRyMDJSfFLCSaijYuZSqHnClQI/QiH6o=; b=Op0JztWV9rkqedV2zz6LSU7FGEvVVDN7VOzIdAAoTUDJj9Bp0sC7zgXmLG7HLqlubc lJSQNoenY5BZExZsGAD1FZ5B8f4IlH3rQymloMgUmFn2L6uu2ms+U+f6A4WJEgoc8wlX LzpTyZSxbNffzs4V9PFbG6pHuYKzg4eMAG2qdjKcL87jVlpURJAfTvAege95861eerHP 5Hbm41Wrg9vhJsoKQcKUlZt2JpjPBgKkrcsRdRlFLQhEUKqXiHMkt6ZrayCDgJQpmuYr GSr8doQuRdD2G8bbNuJLlIuCffXnftFms5DcO6NW6JiJ2j2jslS5nredIkunq5TIt5j6 O7Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694771049; x=1695375849; 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=8neypDPalnwcRyMDJSfFLCSaijYuZSqHnClQI/QiH6o=; b=WLjh9PkdoR0pC12/ZYrFnch8VO4JS9ZTXvUEzzg1EAdGbApdKQkdgyjpwJIGzEyFC1 MUA2f+FMl2VW0UmUQ8Fc0dTsPt4hPVyL+nr3eiX9q9ZSWqLsXHZ4J195wmc/KoZYSHaq lqzQGGed/BnmLFS4Ew0FZ65puOeUgJeUF7e6rzoY1a+GDHmnI/J4OgPZ1tZiNzkNPgPP uvEoogQT1D1AF+wfzS5d2LMEr7TrJNksngUID6URuSMmOSwKdDWtHMZBrl35id0di/58 B705wfh7JBX7zieJ4l/63vn8orEPLO59QgLdqFkr5MclsXR27V1g6jUnHtBwSYOxY0dD owqw== X-Gm-Message-State: AOJu0YzM3xBvDmx0jcCi6sgpj5TYCEHSZiusvN3HtmMcu+eE00QldsCw cV30wrB3tBVLFIt6UlAqK8o= X-Received: by 2002:a17:90b:1490:b0:268:b682:23de with SMTP id js16-20020a17090b149000b00268b68223demr1001744pjb.28.1694771048757; Fri, 15 Sep 2023 02:44:08 -0700 (PDT) Received: from localhost.localdomain (2001-b400-e2a6-6d77-d32f-f490-6688-3d32.emome-ip6.hinet.net. [2001:b400:e2a6:6d77:d32f:f490:6688:3d32]) by smtp.gmail.com with ESMTPSA id x4-20020a17090a530400b0025023726fc4sm4432794pjh.26.2023.09.15.02.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 02:44:08 -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 V12 04/23] mmc: core: Extend support for mmc regulators with a vqmmc2 Date: Fri, 15 Sep 2023 17:43:32 +0800 Message-Id: <20230915094351.11120-5-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915094351.11120-1-victorshihgli@gmail.com> References: <20230915094351.11120-1-victorshihgli@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 15 Sep 2023 02:45:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777120534768075958 X-GMAIL-MSGID: 1777120534768075958 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 505b30935f48..5dbc4f23797a 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 @@ -331,6 +334,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 { @@ -612,6 +616,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, @@ -625,6 +630,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);