From patchwork Thu Feb 20 15:31:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 25058 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f71.google.com (mail-pb0-f71.google.com [209.85.160.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B65A6203C6 for ; Thu, 20 Feb 2014 15:31:33 +0000 (UTC) Received: by mail-pb0-f71.google.com with SMTP id jt11sf4889300pbb.6 for ; Thu, 20 Feb 2014 07:31:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=79wBWi40am5zGKYOKQcBnZoJYOYMYkU372AAir2aAg0=; b=Uy1oeA5c47E1HUpS/L+bwdtkwXHbsXZhi4Jlb6rGbLeb/CRQufztac96xJ9D9dbelw InhLLpXgcts61sWC1cKofznLCmw5IzqvlgiB8NqhGwOHLMc6wIvgvfQo7nTo0MrdNVzz uuZzmzk20VT7vC4Jvyiwx4ng1Lvow9DQWsRpdvUOCj1+L/I0lhj9aIny+wIAwJcOHpEb /LxL/J+V9dimx512SOUy/djAGq7aMvrI0/9vtNJ81CipGTG7nI++xHH7jZ9Cu8oQK9Qb YrBlpIj6I1XsuMAfIX/2jfFDmnwipCcDOnxQITwVAlFXe7UokHWqRnTFPZTvX8ncrwXz 5NmQ== X-Gm-Message-State: ALoCoQmBlQkNfFqC5HLRHKR/FJKPy7IZiHmMJk8Sgkfc2ndsyKkjlRhYg0YfCdiCihQ66VRMml+E X-Received: by 10.66.141.135 with SMTP id ro7mr970326pab.28.1392910292440; Thu, 20 Feb 2014 07:31:32 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.35.208 with SMTP id n74ls589795qgn.65.gmail; Thu, 20 Feb 2014 07:31:32 -0800 (PST) X-Received: by 10.220.99.72 with SMTP id t8mr1395445vcn.10.1392910292268; Thu, 20 Feb 2014 07:31:32 -0800 (PST) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id k2si1594533vcj.30.2014.02.20.07.31.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Feb 2014 07:31:32 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id jx11so1982671veb.38 for ; Thu, 20 Feb 2014 07:31:32 -0800 (PST) X-Received: by 10.52.61.168 with SMTP id q8mr1144831vdr.40.1392910292103; Thu, 20 Feb 2014 07:31:32 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp67148vcz; Thu, 20 Feb 2014 07:31:31 -0800 (PST) X-Received: by 10.194.188.80 with SMTP id fy16mr2691653wjc.30.1392910291178; Thu, 20 Feb 2014 07:31:31 -0800 (PST) Received: from mail-we0-f176.google.com (mail-we0-f176.google.com [74.125.82.176]) by mx.google.com with ESMTPS id j3si3840377wiz.14.2014.02.20.07.31.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Feb 2014 07:31:31 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.176 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=74.125.82.176; Received: by mail-we0-f176.google.com with SMTP id q58so1547597wes.7 for ; Thu, 20 Feb 2014 07:31:30 -0800 (PST) X-Received: by 10.180.98.71 with SMTP id eg7mr3052288wib.31.1392910290652; Thu, 20 Feb 2014 07:31:30 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id h9sm9719799wjz.16.2014.02.20.07.31.28 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Feb 2014 07:31:29 -0800 (PST) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Kevin Hilman , Alan Stern , Mark Brown , Russell King , Linus Walleij , Wolfram Sang , Alessandro Rubini , Ulf Hansson , Greg Kroah-Hartman Subject: [PATCH 1/8] PM / Runtime: Fetch runtime PM callbacks using a macro Date: Thu, 20 Feb 2014 16:31:13 +0100 Message-Id: <1392910280-12891-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1392910280-12891-1-git-send-email-ulf.hansson@linaro.org> References: <1392910280-12891-1-git-send-email-ulf.hansson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , While fetching the proper runtime PM callback, we walk the hierarchy of device's power domains, subsystems and drivers. This is common for rpm_suspend(), rpm_idle() and rpm_resume(). Let's clean up the code by using a macro that handles this. Cc: Kevin Hilman Cc: Alan Stern Cc: Greg Kroah-Hartman Cc: Mark Brown Cc: Russell King Cc: Linus Walleij Cc: Wolfram Sang Cc: Alessandro Rubini Signed-off-by: Ulf Hansson --- drivers/base/power/runtime.c | 59 ++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 72e00e6..dedbd64 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -13,6 +13,23 @@ #include #include "power.h" +#define RPM_GET_CALLBACK(dev, cb) \ +({ \ + if (dev->pm_domain) \ + callback = dev->pm_domain->ops.cb; \ + else if (dev->type && dev->type->pm) \ + callback = dev->type->pm->cb; \ + else if (dev->class && dev->class->pm) \ + callback = dev->class->pm->cb; \ + else if (dev->bus && dev->bus->pm) \ + callback = dev->bus->pm->cb; \ + else \ + callback = NULL; \ + \ + if (!callback && dev->driver && dev->driver->pm) \ + callback = dev->driver->pm->cb; \ +}) + static int rpm_resume(struct device *dev, int rpmflags); static int rpm_suspend(struct device *dev, int rpmflags); @@ -310,19 +327,7 @@ static int rpm_idle(struct device *dev, int rpmflags) dev->power.idle_notification = true; - if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_idle; - else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_idle; - else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_idle; - else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_idle; - else - callback = NULL; - - if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_idle; + RPM_GET_CALLBACK(dev, runtime_idle); if (callback) retval = __rpm_callback(callback, dev); @@ -492,19 +497,7 @@ static int rpm_suspend(struct device *dev, int rpmflags) __update_runtime_status(dev, RPM_SUSPENDING); - if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_suspend; - else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_suspend; - else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_suspend; - else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_suspend; - else - callback = NULL; - - if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_suspend; + RPM_GET_CALLBACK(dev, runtime_suspend); retval = rpm_callback(callback, dev); if (retval) @@ -724,19 +717,7 @@ static int rpm_resume(struct device *dev, int rpmflags) __update_runtime_status(dev, RPM_RESUMING); - if (dev->pm_domain) - callback = dev->pm_domain->ops.runtime_resume; - else if (dev->type && dev->type->pm) - callback = dev->type->pm->runtime_resume; - else if (dev->class && dev->class->pm) - callback = dev->class->pm->runtime_resume; - else if (dev->bus && dev->bus->pm) - callback = dev->bus->pm->runtime_resume; - else - callback = NULL; - - if (!callback && dev->driver && dev->driver->pm) - callback = dev->driver->pm->runtime_resume; + RPM_GET_CALLBACK(dev, runtime_resume); retval = rpm_callback(callback, dev); if (retval) {