From patchwork Wed Jun 21 19:21:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 9802771 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 37BE7601C0 for ; Wed, 21 Jun 2017 19:22:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2863428563 for ; Wed, 21 Jun 2017 19:22:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26E0E28396; Wed, 21 Jun 2017 19:22:31 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 623B628666 for ; Wed, 21 Jun 2017 19:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752040AbdFUTW0 (ORCPT ); Wed, 21 Jun 2017 15:22:26 -0400 Received: from mail-lf0-f50.google.com ([209.85.215.50]:34453 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751789AbdFUTVx (ORCPT ); Wed, 21 Jun 2017 15:21:53 -0400 Received: by mail-lf0-f50.google.com with SMTP id l13so43022291lfl.1 for ; Wed, 21 Jun 2017 12:21:53 -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=QCVzUUSyFMYIjzPdmvE3ollrHFMCZblrrm/7PLOSfB4=; b=WrLfgvzOQxvP87vRcIkGWskfv9c0t/XSUojcSmwNJEKQL3xR+NMWYGOVIgZPDx9/qC 0OrLg+JDjG1uURL+F1fEgpCsg0w/mY1JsEy5cl4QGMtlAmYMFudIpht+NE7o9qagR+nP Nk9USDuJS/uQr2NH3r0ibJG5Hg0NT3LvGoEP0= 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=QCVzUUSyFMYIjzPdmvE3ollrHFMCZblrrm/7PLOSfB4=; b=bWBlWdrg5XR+lbLJpAgpIEKf+7sg9pXdrslGIpvsgup8xdfqctSq/UkHWV2XB9UUmI pvtd9bHnSxECSzfosJc4muv6n5d0eQ03c/y2oJ9C6dY9wsQPJY0Yxr6VFZPV1mgZHjDN 5XjlOp4of7fl8SuupbdIKcKP463PCLOE33wF5sU//cSO00oUHyobNGufbwu/7dEoIHl3 oC8BdMiSwDKW9ZZqNJnm7oUMKcAEhYSP4Qkp07vD9y8uS6mQwxY/RGyrAmPbUjo3dKCi UIBWDuWgbQHqryqkeIY2ez0534SW5w5Omi82Zaosf5aR4GFuWIjftP4ieN49h22AsGIB 1OYQ== X-Gm-Message-State: AKS2vOwA0A/cMP/PFfJ+BGm44zNggBiPq9SrTC13k7Dbtv6yZR68Y1jv cbVnmE+3WE3Do4q56TOZCw== X-Received: by 10.46.71.195 with SMTP id u186mr10471288lja.16.1498072912347; Wed, 21 Jun 2017 12:21:52 -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 t24sm3920047ljd.1.2017.06.21.12.21.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 12:21:51 -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 , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Ulf Hansson Subject: [PATCH 4/9] PM / ACPI: Split code validating need for runtime resume in ->prepare() Date: Wed, 21 Jun 2017 21:21:23 +0200 Message-Id: <1498072888-14782-5-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498072888-14782-1-git-send-email-ulf.hansson@linaro.org> References: <1498072888-14782-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 --- 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 d38acbc..ee51e75 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -933,6 +933,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. @@ -940,26 +961,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);