From patchwork Wed Feb 10 23:07:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 380281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1264AC433E9 for ; Wed, 10 Feb 2021 23:11:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF12764ECF for ; Wed, 10 Feb 2021 23:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234110AbhBJXLh (ORCPT ); Wed, 10 Feb 2021 18:11:37 -0500 Received: from mga02.intel.com ([134.134.136.20]:19927 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234108AbhBJXKR (ORCPT ); Wed, 10 Feb 2021 18:10:17 -0500 IronPort-SDR: CmIN2xGZouXvzddgL28oF1cS0+UV01IyA6/l3TI1fxm0Oq+ZLdygbjgpZq0MLqs9yEsIDiixP8 nvN9NBtxp2sA== X-IronPort-AV: E=McAfee;i="6000,8403,9891"; a="169292253" X-IronPort-AV: E=Sophos;i="5.81,169,1610438400"; d="scan'208";a="169292253" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2021 15:08:06 -0800 IronPort-SDR: wYuWBzrMm/LZF0wpYljnmXbhsaCdcxr3HGMwRpkFk/w7lskGeIoiQRkrFOoiPnPz0mEcPycj60 bIfObtbmOTZQ== X-IronPort-AV: E=Sophos;i="5.81,169,1610438400"; d="scan'208";a="420701005" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2021 15:08:03 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 5923C207C2; Thu, 11 Feb 2021 01:08:01 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1l9yaX-0007tZ-0j; Thu, 11 Feb 2021 01:08:01 +0200 From: Sakari Ailus To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , rajmohan.mani@intel.com, Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , linux-media@vger.kernel.org Subject: [PATCH v11 4/7] ACPI: Add a convenience function to tell a device is in D0 state Date: Thu, 11 Feb 2021 01:07:57 +0200 Message-Id: <20210210230800.30291-5-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210210230800.30291-1-sakari.ailus@linux.intel.com> References: <20210210230800.30291-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add a convenience function to tell whether a device is in D0 state, primarily for use in drivers' probe or remove functions on busses where the custom is to power on the device for the duration of both. Returns false on non-ACPI systems. Suggested-by: Mika Westerberg Signed-off-by: Sakari Ailus Reviewed-by: Rafael J. Wysocki Reviewed-by: Tomasz Figa --- drivers/acpi/device_pm.c | 27 +++++++++++++++++++++++++++ include/linux/acpi.h | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 096153761ebc3..8be6daa9cb7dd 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1336,4 +1336,31 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) return 1; } EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); + +/** + * acpi_dev_state_d0 - Tell if the device is in D0 power state + * @dev: Physical device the ACPI power state of which to check + * + * On a system without ACPI, return true. On a system with ACPI, return true if + * the current ACPI power state of the device is D0, or false otherwise. + * + * Note that the power state of a device is not well-defined after it has been + * passed to acpi_device_set_power() and before that function returns, so it is + * not valid to ask for the ACPI power state of the device in that time frame. + * + * This function is intended to be used in a driver's probe or remove + * function. See Documentation/firmware-guide/acpi/low-power-probe.rst for + * more information. + */ +bool acpi_dev_state_d0(struct device *dev) +{ + struct acpi_device *adev = ACPI_COMPANION(dev); + + if (!adev) + return true; + + return adev->power.state == ACPI_STATE_D0; +} +EXPORT_SYMBOL_GPL(acpi_dev_state_d0); + #endif /* CONFIG_PM */ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index ea296289a94c8..4886692564453 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -992,6 +992,7 @@ int acpi_dev_resume(struct device *dev); int acpi_subsys_runtime_suspend(struct device *dev); int acpi_subsys_runtime_resume(struct device *dev); int acpi_dev_pm_attach(struct device *dev, bool power_on); +bool acpi_dev_state_d0(struct device *dev); #else static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; } static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; } @@ -999,6 +1000,11 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) { return 0; } + +static inline bool acpi_dev_state_d0(struct device *dev) +{ + return true; +} #endif #if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP)