From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS 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 4D341C2D0DB for ; Tue, 21 Jan 2020 16:07:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 21DFE217F4 for ; Tue, 21 Jan 2020 16:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579622857; bh=Etj8yij3CAucRbzdetwiiQnST9C69JEhxInBr2wcaEA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=atiAowQn9DZwVdktybSqTXYOFWn5wJ81ARcXDQMd4ci/jOAA13X5xL9Sxc09WXG3D 3eD6X3D+m5/HrmS5smBj7r/yBk6oa2VUdR0og8Zol6jCjfw9SM79eWgyxjiqnIGbyk TX9S/Gr2m//SfU7TZbuhzpscrZFMscVj04z9qLF8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729253AbgAUQHg (ORCPT ); Tue, 21 Jan 2020 11:07:36 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:37365 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726555AbgAUQHf (ORCPT ); Tue, 21 Jan 2020 11:07:35 -0500 Received: by mail-ot1-f68.google.com with SMTP id k14so3404148otn.4; Tue, 21 Jan 2020 08:07:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B8ych26z3AXNCbZFGLBZKaxG5qsV0F9LivF0I3NpuHM=; b=WVTvmDFyW1kXlKZxuLyScVltiuJKqzwh67rsphlEFWQqlERJQjV7iZ7xT8eLb1qYLV fFm1ywUaS9shlDjl6OdfZ94+z6xIdJfmUnZPKZ6l4YkkBuqwp5zOxQ3VvDPjLlU+rtbZ 2lC2pu1vf5ZnZ7/ocOfp2AmVHBbSt8lexqN4Bhq399t96Xn9cQ/ujaa7eO0LVL1lRKJ6 ikwwss4ZD4SBmHEJOMI2HrKeQR8c+QqSi1xsKitrWONfR945myR0I1z1Lx1LvepxHtKo tIS35O31FOsg1gffJy/jOhyvnmkhJvdbbXKCQaOqNmN4H9qHC4qjQaV3zQukzQRV8I9o Kxzw== X-Gm-Message-State: APjAAAUCFQeZX4b1s8VdDJVZ7vWTjXVwmNLh/MicDboUCSJFhKootdrC odHBe+Uyo719svBeTZbyBJgNakNaLkbWkshr+oetgQ== X-Google-Smtp-Source: APXvYqzW0Iot2FkUM+XXy/qsy+zxC0zxSVszNHm2yg6QZXRu2RVIGdcdFV3nOXiV1tovriJ1VgWYSagoFQaWuhmZW3w= X-Received: by 2002:a9d:7653:: with SMTP id o19mr3974233otl.118.1579622854894; Tue, 21 Jan 2020 08:07:34 -0800 (PST) MIME-Version: 1.0 References: <20200121134157.20396-1-sakari.ailus@linux.intel.com> <20200121134157.20396-3-sakari.ailus@linux.intel.com> In-Reply-To: <20200121134157.20396-3-sakari.ailus@linux.intel.com> From: "Rafael J. Wysocki" Date: Tue, 21 Jan 2020 17:07:23 +0100 Message-ID: Subject: Re: [PATCH v4 2/6] ACPI: Add a convenience function to tell a device is in low power state To: Sakari Ailus Cc: linux-i2c , Wolfram Sang , "Rafael J. Wysocki" , ACPI Devel Maling List , Bingbu Cao , linux-media@vger.kernel.org, Chiranjeevi Rapolu , Hyungwoo Yang , Bartosz Golaszewski , Arnd Bergmann , Linux Kernel Mailing List , Greg Kroah-Hartman , "Mani, Rajmohan" , Tomasz Figa Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 21, 2020 at 2:41 PM Sakari Ailus wrote: > > 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 5e4a8860a9c0c..d3174c6edf915 100644 > --- a/drivers/acpi/device_pm.c > +++ b/drivers/acpi/device_pm.c > @@ -1348,4 +1348,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 0f37a7d5fa774..aa666da311444 100644 > --- a/include/linux/acpi.h > +++ b/include/linux/acpi.h > @@ -926,6 +926,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; } > @@ -935,6 +936,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 >