Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp359738pxk; Thu, 3 Sep 2020 01:19:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxY/wD/e2f/XaUKSloUQPbXUMjDU0A/vApWxPArTuT/wTUxinqrsDl4lEELmb4jAo/bOkj X-Received: by 2002:a17:906:819:: with SMTP id e25mr973697ejd.95.1599121155047; Thu, 03 Sep 2020 01:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599121155; cv=none; d=google.com; s=arc-20160816; b=WjOeF0k6zRZC2JFaVBaNjXUCl8MSRMQgJ8x4W0pmR72WvAYFf6LlwOLIL+ZsNih7qO lkkJGDkOPlRAyeeclerspe9TEb5MnFnB7FY4J3LHQsnCD6Z1n8WKvlqf02YQrY8Hz5lo vh0IJrLWY202fe59aNCiG9ntCE1A9ZPh4djofT+GfqKt1+whCQYRWhDWPAo66bn8GRK7 Ko9I7Ooe2zKP/FNNJzAX8VchAshLXbzqTmkHrLPWADc92iXTqBrFzozgdM57j78tV+1D twEYF/WgXZIsKOeAeKomNHxkhvxGx4prQDrrOXzGA5qxofOPjWpAn8Yo103ltUNBetyV VWkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=uquALcs6uvBgjGqSJGht6GpD3BVvO/NlDf/UDe+OY7U=; b=s/vw0iff5eruiRBcm5vaw7l0rCQzxxXSuGWCCIbRGzNfkroJt1VReCNSHbHBGBaEpp vHIFr6ei2IL9x3yqfnulHfbUrSTvdBdhqhYwbr+xCRKiekVm1WvvZaZCIK85QJafh3nU kkIHHXTVp3wLtjU+5FJgZoJv1D2JKTHAlMl8h4R4thGjtvcUC72je130Uz4P2Bmri61J +F9q5yX3TGHP7EwXxoGmfJCzn91mGtk3TJn+Cd3oeCbCtRc5g3SmYA9qL8LmC15KM1Am UuIpmGjsidw9mJ2ktXDyDDuVgiu9QvzxAAFvPXflw91jMdwxS8NB/LSk9bjxVjnFam9T 0SDg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si1575876ejb.363.2020.09.03.01.18.52; Thu, 03 Sep 2020 01:19:15 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728697AbgICIQy (ORCPT + 99 others); Thu, 3 Sep 2020 04:16:54 -0400 Received: from mga11.intel.com ([192.55.52.93]:55066 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726268AbgICIPw (ORCPT ); Thu, 3 Sep 2020 04:15:52 -0400 IronPort-SDR: rI+AfeZJmpPuVy+DLZznknJ4NeF13cGaxn1VZGbyy373drL9gNYNcTQct0UaJAjHi2kSFqNUSG vChVspQuqNHA== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="155042682" X-IronPort-AV: E=Sophos;i="5.76,385,1592895600"; d="scan'208";a="155042682" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 01:15:43 -0700 IronPort-SDR: 81e430P+oAXdH2KRXA5YExJnmsxD424q4QQ5wHiDUiJGzEOLZXOLSzGtPLE/UtxoU81OhgIXjP 64ipYFdqhwXw== X-IronPort-AV: E=Sophos;i="5.76,385,1592895600"; d="scan'208";a="477963176" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 01:15:40 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 85E1820F67; Thu, 3 Sep 2020 11:15:38 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1kDkPO-0001cG-Km; Thu, 03 Sep 2020 11:15:50 +0300 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 v8 3/6] ACPI: Add a convenience function to tell a device is in low power state Date: Thu, 3 Sep 2020 11:15:47 +0300 Message-Id: <20200903081550.6012-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903081550.6012-1-sakari.ailus@linux.intel.com> References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a convenience function to tell whether a device is in low power 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 --- drivers/acpi/device_pm.c | 31 +++++++++++++++++++++++++++++++ include/linux/acpi.h | 5 +++++ 2 files changed, 36 insertions(+) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 94d91c67aeaeb..e3c488d4af0d4 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1344,4 +1344,35 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) return 1; } EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); + +/** + * acpi_dev_state_low_power - Check the current ACPI power state of a device. + * @dev: Physical device the ACPI power state of which to check + * + * On a system without ACPI, return false. On a system with ACPI, return true if + * the current ACPI power state of the device is not 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. + */ +bool acpi_dev_state_low_power(struct device *dev) +{ + struct acpi_device *adev = ACPI_COMPANION(dev); + int power_state; + int ret; + + if (!adev) + return false; + + ret = acpi_device_get_power(adev, &power_state); + if (ret) { + dev_dbg(dev, "Cannot obtain power state (%d)\n", ret); + return false; + } + + return power_state != ACPI_STATE_D0; +} +EXPORT_SYMBOL_GPL(acpi_dev_state_low_power); + #endif /* CONFIG_PM */ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 17e80e182802e..d76d851259a49 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -978,6 +978,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_low_power(struct device *dev); #else static inline int acpi_dev_runtime_suspend(struct device *dev) { return 0; } static inline int acpi_dev_runtime_resume(struct device *dev) { return 0; } @@ -987,6 +988,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) { return 0; } +static inline bool acpi_dev_state_low_power(struct device *dev) +{ + return false; +} #endif #if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP) -- 2.20.1