From patchwork Tue Aug 29 14:56:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 9927595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AB8D4603B4 for ; Tue, 29 Aug 2017 14:57:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9604628979 for ; Tue, 29 Aug 2017 14:57:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AE0A28986; Tue, 29 Aug 2017 14:57:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D4C728980 for ; Tue, 29 Aug 2017 14:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754658AbdH2O5O (ORCPT ); Tue, 29 Aug 2017 10:57:14 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:36111 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754661AbdH2O5I (ORCPT ); Tue, 29 Aug 2017 10:57:08 -0400 Received: by mail-lf0-f44.google.com with SMTP id z12so14370090lfd.3 for ; Tue, 29 Aug 2017 07:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Lg9EEQT3YuyzWd/JOg75Y85U4sVeV31PRz0DxI/aF3w=; b=AJTTGHekrPYMkim+F9nNl6TaM1vVhP+VaGH0EV/+XkIXeGFZZ5kaw567JrdyVQNW3Y X9aL0t6bnXx+tLpf9vjSRh6NkkMhpuK98xF3rrgTg4y2CrpfKCmJ9ANwr7KFTYGWbOnT 7UzlVLL+nsELDhMNLztjatNIdrCDzFBBEvpvo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Lg9EEQT3YuyzWd/JOg75Y85U4sVeV31PRz0DxI/aF3w=; b=rzVA5ZNgRYHfqAZUC//3wH340DTa7k6vojvxClLtk63zlvTPds1xc5aIZPAlyEZHxl TbSLP58Y8zB0wHIl5zablfV68daJy0VOoXnWYWuoAuUhLOfV6kBVlTEjiFs2ld302jLq IxtQkbFzVLkEntW43KsbdFSnu5LuT3pPEUqOlTAjF87j4dX6j9psrYJjTwQFUu/iHjJ3 M8ZDgCMkgmsLY8AR3oDMMSNjhbo95O38aH+o2tEHoppbpVgBJct5wdLSXEUOW/Hultk3 GDVvbvz4YnOXLgcGONJJZCvizRRok0xI/eh9oeR57XGXBiDp63E0pPJLVK5DJZxyVtuw zlnA== X-Gm-Message-State: AHYfb5hI2BVtCE+eAb9hv5jMY3tHMg2Rc8n3XvU8n2fqtbKGAiuqCVUD Xi/yQPeHZr6X2mOv X-Received: by 10.25.84.136 with SMTP id b8mr191048lfl.9.1504018627031; Tue, 29 Aug 2017 07:57:07 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-67.NA.cust.bahnhof.se. [158.174.22.67]) by smtp.gmail.com with ESMTPSA id y23sm652454ljd.19.2017.08.29.07.57.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Aug 2017 07:57:06 -0700 (PDT) From: Ulf Hansson To: Wolfram Sang , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Cc: Kevin Hilman , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jisheng Zhang , John Stultz , Guodong Xu , Sumit Semwal , Haojian Zhuang , Johannes Stezenbach , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Ulf Hansson Subject: [PATCH v3 4/8] PM / ACPI: Split code validating need for runtime resume in ->prepare() Date: Tue, 29 Aug 2017 16:56:46 +0200 Message-Id: <1504018610-10822-5-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504018610-10822-1-git-send-email-ulf.hansson@linaro.org> References: <1504018610-10822-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the code dealing with validation of whether runtime resuming the device is needed during system suspend. In this way it becomes more clear for what circumstances ACPI is prevented from trying the direct_complete path. Signed-off-by: Ulf Hansson --- Changes in v3: - None. --- drivers/acpi/device_pm.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 632f214..5181057 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -989,6 +989,27 @@ int acpi_dev_resume_early(struct device *dev) } EXPORT_SYMBOL_GPL(acpi_dev_resume_early); +static bool acpi_dev_needs_resume(struct device *dev, struct acpi_device *adev) +{ + u32 sys_target = acpi_target_system_state(); + int ret, state; + + if (device_may_wakeup(dev) != !!adev->wakeup.prepare_count) + return true; + + if (sys_target == ACPI_STATE_S0) + return false; + + if (adev->power.flags.dsw_present) + return true; + + ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state); + if (ret) + return true; + + return state != adev->power.state; +} + /** * acpi_subsys_prepare - Prepare device for system transition to a sleep state. * @dev: Device to prepare. @@ -996,26 +1017,16 @@ EXPORT_SYMBOL_GPL(acpi_dev_resume_early); int acpi_subsys_prepare(struct device *dev) { struct acpi_device *adev = ACPI_COMPANION(dev); - u32 sys_target; - int ret, state; + int ret; ret = pm_generic_prepare(dev); if (ret < 0) return ret; - if (!adev || !pm_runtime_suspended(dev) - || device_may_wakeup(dev) != !!adev->wakeup.prepare_count) - return 0; - - sys_target = acpi_target_system_state(); - if (sys_target == ACPI_STATE_S0) - return 1; - - if (adev->power.flags.dsw_present) + if (!adev || !pm_runtime_suspended(dev)) return 0; - ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state); - return !ret && state == adev->power.state; + return !acpi_dev_needs_resume(dev, adev); } EXPORT_SYMBOL_GPL(acpi_subsys_prepare);