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: 111222 Delivered-To: patches@linaro.org Received: by 10.140.95.112 with SMTP id h103csp1457535qge; Tue, 29 Aug 2017 07:57:07 -0700 (PDT) X-Received: by 10.25.1.214 with SMTP id 205mr169977lfb.68.1504018627681; Tue, 29 Aug 2017 07:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504018627; cv=none; d=google.com; s=arc-20160816; b=NsyoeQAK9ri9rPvyIsuXJMy9Z1ted4i5pQDaN+GQesqbvFmZn3hkkFmLYopBzZgKZZ DvwaXvqA/VC/DEp1YAcqRI9TYyTfrbuEwKfgRtHm3PJVw0YpnG41OAZ+fQUKI2H2ye/5 eRRrcBLLnYemBQ1FJCi0vlR18zj8V/POAglfMdGm0xKAjjhXo8Oeyws0b8uLoA6U2zl8 vDF/oEvQO6zUeoLNQUMLTI2/FSA++hRgAzJMpvwDEuGflTs+n03OPguEn+V1UylYyFGy BIti5tCcWZmlKmU+a3li0fAHTDxl6BU42OMF+ok4OXuUnYkrEAbU31W+1q0ECOgYyCTW rlCw== 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=Lg9EEQT3YuyzWd/JOg75Y85U4sVeV31PRz0DxI/aF3w=; b=Rq6XIIxY+yivRNSZLQLrTJrXvHzUOBBvJTFgkbFBvWg801SjI/09Mv9Ohp6Ni46xgE NDfpr7cMZCe/lFR6GZzbA/d/aZt0N8RxP1JSNlu8sNygxDb57wwopTHZITt9aWuPpNu+ HPobkcT4D1JEZSNm0SFJVqXqUou/se07RcZq6YRAj5KQwqQC1XY/6cgLQu4DC97H5jPs 3fPR4+ord435kGK4BdVXtmaLO+f68/wE/UCcqfAvkVFJ8dFv/uEkRMnLnlbZyU5KA8i9 XbGByQ2mTj7eMj+2mbATJUAz0gpEcRmqdMUloiV/eRLd3mRumkEmWdHKmGpHMw5MSaUq GFxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AJTTGHek; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22a 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-x22a.google.com (mail-lf0-x22a.google.com. [2a00:1450:4010:c07::22a]) by mx.google.com with ESMTPS id o15si1410121lfg.530.2017.08.29.07.57.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Aug 2017 07:57:07 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22a as permitted sender) client-ip=2a00:1450:4010:c07::22a; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AJTTGHek; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22a 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-x22a.google.com with SMTP id d202so14330830lfd.5 for ; Tue, 29 Aug 2017 07:57:07 -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=ct/QR2fYfxO6OJxKkKXhY7xNWSy8dFFbjKmkOu4lXHrsJK+BSLGfKvfM+Tnt6XtzJK Ej02WgNusby1Iy86Sn0t3GwMeUqT5Lnw/O1DFsXcakOL0CeBNzZePpXvulaRHe5qyH0h k6jaNNjRVNiNjXhzjMF8f3qr9AI5yyHdA+wUBMlxsnPSzbJh8hTkhVDeyWSsXZn/ohyQ nZBOlkUhDCbJi76xGKopxrmRg2JLHadtUl7rp6zLcBocgF2M7YxzUjRUV6Y4+wWZAe7M JIdepzx+9vL7Mi9VMlh0dUYLTnvUHTlUhAMnTykIxzIh+26MeLQOg2SFUXNjAroRv24u PVjA== X-Gm-Message-State: AHYfb5g+kTM2/MdNf8O6kozKUcLdxvd/dyJgP+ssJnSxr/vWvXa8TU53 ZmY0kw9r2F0e5XRczkI= X-Received: by 10.25.84.136 with SMTP id b8mr191048lfl.9.1504018627031; Tue, 29 Aug 2017 07:57:07 -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 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> 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(-) -- 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);