Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp491843ybt; Fri, 26 Jun 2020 04:37:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/7jI0ngSJ4utLdQkZHcyRlVcW8UYPyMaDa1szmXGqsIl/EAf7XDtSU/OUWF0wgoOOGUxF X-Received: by 2002:aa7:d845:: with SMTP id f5mr2811790eds.162.1593171427849; Fri, 26 Jun 2020 04:37:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593171427; cv=none; d=google.com; s=arc-20160816; b=imfQBPVvm/eM6+THuquNjQEyQZd0Z1G06W/sfJwc5WX1RVJf/z4pq6bNKCWk4G7bZX uKjVujSdlXGBRXEF4u7jlvoQCM+hOjp8H1C0klPJDcA4+F1aqj+dUQ6P1WSh5LbWWiPp 2/X9VtweOOhu5G9vO6PJkI3iff3V6rHIYg+kURdjJsdBd7R3/OtZai26ewf7OJUzx2l2 xi7pqSVqWpB6n1tKAMgTN9XQSpU+VHRs9DjHPCOEWLU7z0t1I4u/p6Crx9xcJiCQCXyG o3MeRPk6kCG7Z0yQBQj3RNUHy7/4MvN+ufWnGb21Ue10Ap/5rlyL24euG3YZ6RNVi4Ll t2xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=h4f9kZ/6QIDgPQOmaJgfHBpEZhUMMlkHHReXsKzMuiQ=; b=wkZPDlNBoUOe9xR9ibCFp39V5djdIJJcCP7c0PjoDyFFFhVO6Prxxj3N/ERQFPzFcI vGzz2H35GmV5iLC9Vb60zLZKhvowmcxbByW2bxY3hssfq968HX9ooirEyA2kUkMFRtkg EFHqZsKZCh4deuGd8SGIi3Xsy3mMkEr8v8A4WBWF/2MMFHlkGywRCvIHX42zPT98BeDm +lnB0Oj6Rl5ktuv9mdcBfIxhMrZNHZKjJVFzZFj8atyWRaLHTJOVR5VZHY783wWpyfPP mY+/1y/9abOvzS//y6lncEDgzXh2jLPCsCcmtvjGAPlkloaFSaj/Kn7rj9GOnp37n2/J 7awA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do15si25657172ejc.430.2020.06.26.04.36.44; Fri, 26 Jun 2020 04:37:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbgFZJcc (ORCPT + 99 others); Fri, 26 Jun 2020 05:32:32 -0400 Received: from relmlor1.renesas.com ([210.160.252.171]:59362 "EHLO relmlie5.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725768AbgFZJca (ORCPT ); Fri, 26 Jun 2020 05:32:30 -0400 X-IronPort-AV: E=Sophos;i="5.75,283,1589209200"; d="scan'208";a="50657262" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 26 Jun 2020 18:32:28 +0900 Received: from localhost.localdomain (unknown [10.166.252.89]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 58F57420331D; Fri, 26 Jun 2020 18:32:28 +0900 (JST) From: Yoshihiro Shimoda To: ulf.hansson@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, geert+renesas@glider.be, magnus.damm@gmail.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH/RFC v4 1/4] regulator: core: add prepare and resume_early Date: Fri, 26 Jun 2020 18:32:19 +0900 Message-Id: <1593163942-5087-2-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1593163942-5087-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1593163942-5087-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The regulator-fixed driver is possible to be off by firmware like PSCI while the system is suspended. If a consumer could get such a condition from regulator_is_enabled(), it's useful by consumers. The regulator subsystem already has regulator-state-(standby|mem|disk) sub-nodes and regulator-off-in-suspend property. However, suitable regulator_ops APIs didn't exist. So, add new regulator_ops APIs and prepare()/resume_early() in the regulator_pm_ops to set/clear the condition by new APIs before suspend() functions of consumers are called. Signed-off-by: Yoshihiro Shimoda --- drivers/regulator/core.c | 42 ++++++++++++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 6 ++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 03154f5..93eb2a3 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -5286,6 +5286,46 @@ void regulator_unregister(struct regulator_dev *rdev) EXPORT_SYMBOL_GPL(regulator_unregister); #ifdef CONFIG_SUSPEND +static int regulator_prepare(struct device *dev) +{ + struct regulator_dev *rdev = dev_to_rdev(dev); + suspend_state_t state = pm_suspend_target_state; + struct regulator_state *rstate; + int ret = 0; + + rstate = regulator_get_suspend_state(rdev, state); + if (rstate == NULL) + return 0; + + regulator_lock(rdev); + if (rstate->enabled == DISABLE_IN_SUSPEND && + rdev->desc->ops->set_prepare_disable) + ret = rdev->desc->ops->set_prepare_disable(rdev); + regulator_unlock(rdev); + + return ret; +} + +static int regulator_resume_early(struct device *dev) +{ + struct regulator_dev *rdev = dev_to_rdev(dev); + suspend_state_t state = pm_suspend_target_state; + struct regulator_state *rstate; + int ret = 0; + + rstate = regulator_get_suspend_state(rdev, state); + if (rstate == NULL) + return 0; + + regulator_lock(rdev); + if (rstate->enabled == DISABLE_IN_SUSPEND && + rdev->desc->ops->clear_resume_early_disable) + ret = rdev->desc->ops->clear_resume_early_disable(rdev); + regulator_unlock(rdev); + + return ret; +} + /** * regulator_suspend - prepare regulators for system wide suspend * @dev: ``&struct device`` pointer that is passed to _regulator_suspend() @@ -5336,6 +5376,8 @@ static int regulator_resume(struct device *dev) #ifdef CONFIG_PM static const struct dev_pm_ops __maybe_unused regulator_pm_ops = { + .prepare = regulator_prepare, + .resume_early = regulator_resume_early, .suspend = regulator_suspend, .resume = regulator_resume, }; diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 7eb9fea..299a504 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -115,6 +115,10 @@ enum regulator_status { * suspended. * @set_suspend_disable: Mark the regulator as disabled when the system is * suspended. + * @set_prepare_disable: Mark the regulator as disabled when the system is + * suspending. + * @clear_resume_early_disable: Unmark the regulator as disabled when + * the system is resuming. * @set_suspend_mode: Set the operating mode for the regulator when the * system is suspended. * @@ -195,6 +199,8 @@ struct regulator_ops { /* enable/disable regulator in suspend state */ int (*set_suspend_enable) (struct regulator_dev *); int (*set_suspend_disable) (struct regulator_dev *); + int (*set_prepare_disable) (struct regulator_dev *); + int (*clear_resume_early_disable) (struct regulator_dev *); /* set regulator suspend operating mode (defined in consumer.h) */ int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); -- 2.7.4