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: 106118 Delivered-To: patches@linaro.org Received: by 10.140.91.2 with SMTP id y2csp2092629qgd; Wed, 21 Jun 2017 12:21:52 -0700 (PDT) X-Received: by 10.25.17.169 with SMTP id 41mr11180440lfr.129.1498072912673; Wed, 21 Jun 2017 12:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498072912; cv=none; d=google.com; s=arc-20160816; b=uJ16h92Jk5tXVayD/cprTwyncSbO97eKrhe5Pl4IcwS6SzDwtJ6I1szLkfhqcwzO0M FS+potTJ0COExQHXWDHgDFfChek4GThcVI/rRYX9xJfmKwMZjsTXdcN2A+/+CtljRzCE nd0Vd4prldPyWN5GjAPnE8acukKu7sj+Tyq7Rs1xrhFPnXAjpAuN5SgY6knXdqw2tZ6P cLqiuEn4XSNaS+AAfmJMgvlB4v0orGD8FieEuKy10qgGQRWtLR8aJyag5pLnx/IcqVPb 5xCQqjabHNbdVh+G7RUxx/V/dnTCqSPCSzbVJ4e4vNTnZ6ELRFWpeVWVN6+PmjHg7S+E SiSw== 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=QCVzUUSyFMYIjzPdmvE3ollrHFMCZblrrm/7PLOSfB4=; b=a4xUso8852clKqyvCT9jLY4eZ9kGyuDC8+tDulOTxKTfBc6TDEtkcJF+ST5SHQvs1D n6yQ8JoYGf6KfYDZNNtf7k5hggcmMPcREy53RPqkP2iYvLj/6ITRCq/CF34D4+k+iEJS YfV9bM3mw8m778EyamnkcYNCAv5UOHH7YHwwjBAeqWpoiQ/ZlpQ0bx9hJAggIcSgLNSd bXP5jhZaMGzHNKKv5MSl3GzWAyntLY3ZvCilKbVofo2aOvXXNbgqejPpLBlayKW6cC8A 9PguDEFQ0L0XQiGf9U2wgJWzSFRxYO7NHv/0T/Vdsy38lrj8ppTNMb62+obC8R8pU2Wv h+bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=WrLfgvzO; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::231 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-x231.google.com (mail-lf0-x231.google.com. [2a00:1450:4010:c07::231]) by mx.google.com with ESMTPS id q4si9072028lff.291.2017.06.21.12.21.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jun 2017 12:21:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::231 as permitted sender) client-ip=2a00:1450:4010:c07::231; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=WrLfgvzO; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::231 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-x231.google.com with SMTP id p189so102984460lfe.2 for ; Wed, 21 Jun 2017 12:21:52 -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=KcAATOqjS7SoJq/U75D/HaNQO/dUxz8aU+f6PLY2VMHeYuXeztFKSrwWnidBGLc1nd p4eBRwQui0/aRsgkuCIJxHAtPnWm5EIKz8MK+GF4OWS+1TSdUSGvh7/DC+41FYLSJO/D aw46p/WuHNuHcovEJlVpcg/PV6Z/dzJUiA5j0c3h9N6pRlBjp+2OO35TdM9rF6NwdMKn eeEZKptUoz97EYn1wdPBjeB+5pVfBMmVJh+4qdtUgHuzHz+GNtPWnUB5n2c2rBd592mi wZqyMiTosmK1DOnrMGdx0zpVVbEDACSFqEO3hlo42w7gUSUbDi4oPSOVJAFQcBlpUDqD VPnA== X-Gm-Message-State: AKS2vOwvu30K0Kp/0bDPcWZkVfGJvVCgKOo160/dNrlcHLocUvI48zXP HONvv78YJnTORXDDXSo= X-Received: by 10.46.71.195 with SMTP id u186mr10471288lja.16.1498072912347; Wed, 21 Jun 2017 12:21:52 -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 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> 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(-) -- 2.7.4 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);