From patchwork Wed Aug 23 14:42:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 110849 Delivered-To: patches@linaro.org Received: by 10.37.128.210 with SMTP id c18csp7031408ybm; Wed, 23 Aug 2017 07:42:21 -0700 (PDT) X-Received: by 10.46.69.132 with SMTP id s126mr1158695lja.9.1503499341072; Wed, 23 Aug 2017 07:42:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503499341; cv=none; d=google.com; s=arc-20160816; b=s7RR6R/NAF77IwhpyyG+O8DjgYaewc37cDkrnaq5BX9RJSOt8Zy50t3ncb/hrK6V9s HpSqnhxF48eRZFZndEypXk6rkgZvc+EfDBAlEX2mbDzBlv/cDgpfVwGd325l3sy9PhQL NrE7ZuOctWD0YYKVtYvqcf2TI+8ismGU+OBub86D1cwbt9fhWgret9Y4IJDip/4Z/Xie FjLWB274keKlWftULSN3VmU21t/O5MZc+k8ckjIt4f3tU2K/1tlP8C0etPQzkbN8kBPC 9IQJG/knkmtqDAPW89A9vnikvhW70yOgrCAK5zz/Fquyw660MPfPIdP707ncAxFG2YX0 orvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=4/W6OZ+A4Rz4hctfwlJI6a5jCkwwM43qZi+T3IcWlFs=; b=nZkQQzTilAjJwP2iIvvZmzMlIl4T53KWN3PnpMn3ei4vFsfwAWK+gbajeO63bEAiwK r/CjvHkUQR625t7XdpQO5sKGaNHuIItestG3lpInBilXvv9M9fM3Y4bIsggAYWTiq+mb bvbGGLtt0ezWVHi4DV8eRVEQ2C8bkE7US8bMMw6Ufg++CdE+sJD2xscKcCnRx1DqOR2A kzPj48M9mKudIBnA2g5EnTp/LSuEFDPZ10CqYD/oYOHuaA52T5ZNnD1nPqWlQWtMZk0f 29jD7ymCu+Twxbwa1Hpgt4Yt9FhUh3Q8ggXNUUIIMy4fqKi3Gf0en7yGFItZ6vUK9nl8 Ag/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZP9/pZzS; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22d as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-lf0-x22d.google.com (mail-lf0-x22d.google.com. [2a00:1450:4010:c07::22d]) by mx.google.com with ESMTPS id r26si772957lje.50.2017.08.23.07.42.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 07:42:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22d as permitted sender) client-ip=2a00:1450:4010:c07::22d; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZP9/pZzS; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22d as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x22d.google.com with SMTP id l137so1426989lfg.3 for ; Wed, 23 Aug 2017 07:42:20 -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=4/W6OZ+A4Rz4hctfwlJI6a5jCkwwM43qZi+T3IcWlFs=; b=ZP9/pZzS1cSGSh0OxQT/y//rYdQFqMhJnodSRjERdabwOYiHF+l5+pIlecIH1rvGZ0 acN36gN9gjDpKNj9iz+AuGX3sYaDSRFCcePu2y6v0rWTMSrN3KMRKoJUiJxRU5532Iav Wbeqe4RLX+C94NB3ecq3D5/g7IxPN6PnbbHqs= 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=4/W6OZ+A4Rz4hctfwlJI6a5jCkwwM43qZi+T3IcWlFs=; b=qS8frXygNhvahcL+z2Lyjy5hjsgdVe02iAnBpZ/4Fcq7JSKu4odDcZyyEsyI4WKaL5 sQDp6OebVgWUAwz5Ai5C8E+kBxUtj5ntPvP7gkflA09SDbrnt8iL0CriuuanmQ2rZFHE K9Ksa1V2RAPKrKCN0hAj72a1y12Ce2zjAHBhkZ7uekLUnLRReFzJFeEy+xtc4WJvnn9w VgeGmL/n3A/fayfhiX2XlncBDNwTAFKnQqYU9zsPMmH/5MZeWdVMTGIHmW+IJOg+FQZY P/tKFN+QXOwKL6GoGrYxOONgiaVOxxzossr0B0YYdtOIZWMXAt+ndWwlFE23rrr9V1fn OEvA== X-Gm-Message-State: AHYfb5hMOLZ9G0NM5NEtyYM8ELCiJvbwVyc/F3n/B00vYY3mOvgyf3ms 8ES26WCzNQ8N6lQmi/8= X-Received: by 10.46.9.65 with SMTP id 62mr1166862ljj.177.1503499340683; Wed, 23 Aug 2017 07:42:20 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-67.NA.cust.bahnhof.se. [158.174.22.67]) by smtp.gmail.com with ESMTPSA id c89sm287593lfb.78.2017.08.23.07.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Aug 2017 07:42:20 -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 v2 3/9] PM / ACPI: Split code validating need for runtime resume in ->prepare() Date: Wed, 23 Aug 2017 16:42:03 +0200 Message-Id: <1503499329-28834-4-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503499329-28834-1-git-send-email-ulf.hansson@linaro.org> References: <1503499329-28834-1-git-send-email-ulf.hansson@linaro.org> 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 v2: - Updated return expression for acpi_dev_needs_resume(). --- drivers/acpi/device_pm.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) -- 2.7.4 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);