Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2638993rdb; Wed, 4 Oct 2023 07:17:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrErLxQ1y6mdf9wYN0yDZhIuewUVQh3+rghIsI9JrgV1R6vr1UM3CGz7MhfBLGBqnFl/Fl X-Received: by 2002:a17:902:d349:b0:1c5:e527:68b0 with SMTP id l9-20020a170902d34900b001c5e52768b0mr2445024plk.62.1696429067551; Wed, 04 Oct 2023 07:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696429067; cv=none; d=google.com; s=arc-20160816; b=tBxAEOpL4by+rGUeioz7KEh4VtDfGomHhT6kyEJuPLq3z9tCx0gMPNOB7MhxgRjpm0 v8rz4LUoojoSpR+Y9AbjLZo3oNywYA+D6CHHXMJ3ZoFN3RvBXUFkMcwJw6hQOlASU3PE 6CWUZJzuh9NBC+s36QCSDGLld6JBUr40GYnq0mU//8VcQ6VEnTXdZ6AoGpDNlA6odi4t 8JBqCbvN5ZS9mtY238MWln4jZD6+3s5WuZUaRLafSNM+eSzKHtfzpTgm2nINREeoFCpL TqMZYq1XdINqmCbaR5feZbIAeU96PXrpWB6jv6zetZPjagHeHDwM1FdiJ8Z0E3mmqFDV srXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=SkbWpdDlNPiVngrUfwn9Q3KUJG64A7lq4G4XSXJ8ny8=; fh=6ROhvpJrsh+iZGjEACun9ZXYVgb1LMu8Jj3+nzwGyNE=; b=XHLKPc7yjVergnp+UvvLngHbKECgiNb3//Qp/mk6RDmJh1kycnmtvCU3LL+NTbqsJf +kt1qj91v2c/bNXY9BWJFaXr9R3sKwKj2yjhSVnLj4jmzUXxlWv+RGGIdZuBwaQE4dI/ ZAMTX345mnogp7tj89lMJWGCk/IUmehOiIEIyRlYPW/nH6IVs7yyICIQYPQF0+4xMKD6 dxF8cCxTSCATIlFapx4RcLQ5uzQglkyVTftPNkK49FnIZWZeliB2PJzWUSD01yLwxS8S 4I75DsMvumk40oSb3JpUpraMxQjwTALe6SSynOI12uH3v9n8g7YQwkJfLzCFKCN7qI51 Qd3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernkonzept.com header.s=mx1 header.b=Ey6XFdVJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernkonzept.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y22-20020a17090264d600b001c3845d008csi3548148pli.424.2023.10.04.07.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 07:17:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernkonzept.com header.s=mx1 header.b=Ey6XFdVJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernkonzept.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C71A681AFD84; Wed, 4 Oct 2023 07:17:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242875AbjJDORe (ORCPT + 99 others); Wed, 4 Oct 2023 10:17:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242879AbjJDORb (ORCPT ); Wed, 4 Oct 2023 10:17:31 -0400 Received: from mx.kernkonzept.com (serv1.kernkonzept.com [IPv6:2a01:4f8:1c1c:b490::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81B0EAD; Wed, 4 Oct 2023 07:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: Reply-To:Content-ID:Content-Description; bh=SkbWpdDlNPiVngrUfwn9Q3KUJG64A7lq4G4XSXJ8ny8=; b=Ey6XFdVJPni7Vjj/dP2fzSll4K LnYLm7C3dDqJe9KaqyAl0gmltjHRWRt18tHoDEuCyhW8zSkW3g6rjcFUJBG98iSH9zAw2OXxtbTMh DV8QVszoYimRfe47hlguY7xk5ieDNBuXUz6dXRV2iB0+rCoIRDRtH0me/Qt0YSw5MtmBYMsbB0u+f s0yxshk2WgBQqCx7LCt0uV4TvX2ZYAjqc5DG5wL5nrelx3oX4n+3n01MINF5TwShj1gv9sEYsOTSk JSSDt36nQMsytbqhUnOHWg7t2B3wgvTLFoPsl5fR7KW7Y8T02llzbWCYxoG4ywuacKUQ2YMv++oSS J+Z5Cjqw==; Received: from [10.22.3.24] (helo=serv1.dd1.int.kernkonzept.com) by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) id 1qo2gk-0071hO-1E; Wed, 04 Oct 2023 16:17:22 +0200 From: Stephan Gerhold Date: Wed, 04 Oct 2023 16:17:17 +0200 Subject: [PATCH RFC 1/2] regulator: core: Disable unused regulators with unknown status MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231004-reg-smd-unused-v1-1-5d682493d555@kernkonzept.com> References: <20231004-reg-smd-unused-v1-0-5d682493d555@kernkonzept.com> In-Reply-To: <20231004-reg-smd-unused-v1-0-5d682493d555@kernkonzept.com> To: Mark Brown Cc: Liam Girdwood , Andy Gross , Bjorn Andersson , Konrad Dybcio , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Stephan Gerhold , Stephan Gerhold X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 04 Oct 2023 07:17:42 -0700 (PDT) Some regulator drivers do not provide a way to check if the regulator is currently enabled or not. That does not necessarily mean that the regulator is always-on. For example, the regulators managed by the RPM firmware on Qualcomm platforms can be either on or off during boot but the initial state is not known. To sync the state the regulator should get either explicitly enabled or explicitly disabled. Enabling all regulators unconditionally is not safe, because we might not know which voltages are safe. The devices supplied by those regulators might also require a special power-up sequence where the regulators are turned on in a certain order or with specific delay. Disabling all unused regulators is safer. If the regulator is already off it will just stay that way. If the regulator is on, disabling it explicitly allows the firmware to turn it off for reduced power consumption. The regulator core already has functionality for disabling unused regulators. However, at the moment it assumes that all regulators where the .is_enabled() callback fails are actually off. There is no way to return a special value for the "unknown" state to explicitly ask for disabling those regulators. Some drivers (e.g. qcom-rpmh-regulator.c) return -EINVAL for the case where the initial status is unknown. Use that return code to assume the initial status is unknown and try to explicitly disable the regulator in that case. Signed-off-by: Stephan Gerhold --- Instead of -EINVAL we could also use a different return code to indicate the initial status is unknown. Or maybe there is some other option that would be easier? This is working for me but I'm sending it as RFC to get more feedback. :) --- drivers/regulator/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 3137e40fcd3e..182e3727651a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -6207,8 +6207,13 @@ static int regulator_late_cleanup(struct device *dev, void *data) if (rdev->use_count) goto unlock; - /* If reading the status failed, assume that it's off. */ - if (_regulator_is_enabled(rdev) <= 0) + /* + * If reading the status failed, assume that it's off. + * If the current status is unknown (-EINVAL), assume that the + * regulator might be on and try to explicitly disable it. + */ + ret = _regulator_is_enabled(rdev); + if (ret <= 0 && ret != -EINVAL) goto unlock; if (have_full_constraints()) { -- 2.39.2