From patchwork Fri Feb 28 11:49:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 25528 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AC00A20543 for ; Fri, 28 Feb 2014 11:49:40 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id bj1sf1186387pad.7 for ; Fri, 28 Feb 2014 03:49:39 -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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=QM2T7Nd7Gx/S66xwVGBEvvWqKXyTrYhQKVMRtitLRPo=; b=ly6JtjgNg2O5nZKbtRwOmnICff3L+lYVIUKszcL/49Pikfn7JSFjdbtQevy/4NjjBt 7n/HBACRfcxXmtp0VEz4KuOizdoAnBWKuCZvbxYFgEMKxqS6t9Exg36t0A4yqQs90/cm 4FwCcxvvj/PntOUxN/yDiTQ/7L9fXaVOM19maPzJ0ykqESDx96ZWSgHFGXVzrTdyd/PF HMBaGN8crN3dq2TwBVzOyLeupk3WiOks2LPSrDJO2dUo2Um21ksxvHsMELY7LMWbRtCz d0XfcHgXouFocSCfRZLWsSzV8ZCSOZXx+NhV2BDv624KNaTK6Tb5ED1tdr1jbC8OyNXG 1VLw== X-Gm-Message-State: ALoCoQlcG6zDg/Sj/UOR6F1deRDl5EK22hoBYUiZmOlvMoP0MHgxUgt8kBd+sct3Q9K+ZlPXSSzi X-Received: by 10.68.201.134 with SMTP id ka6mr1031279pbc.4.1393588179387; Fri, 28 Feb 2014 03:49:39 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.230 with SMTP id c93ls1050632qgf.35.gmail; Fri, 28 Feb 2014 03:49:39 -0800 (PST) X-Received: by 10.220.11.141 with SMTP id t13mr2178583vct.30.1393588179261; Fri, 28 Feb 2014 03:49:39 -0800 (PST) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id eb8si504996vdb.47.2014.02.28.03.49.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Feb 2014 03:49:39 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id le5so595408vcb.30 for ; Fri, 28 Feb 2014 03:49:39 -0800 (PST) X-Received: by 10.58.86.230 with SMTP id s6mr2184627vez.16.1393588179152; Fri, 28 Feb 2014 03:49:39 -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.130.193 with SMTP id u1csp47986vcs; Fri, 28 Feb 2014 03:49:38 -0800 (PST) X-Received: by 10.152.206.4 with SMTP id lk4mr949284lac.65.1393588177441; Fri, 28 Feb 2014 03:49:37 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by mx.google.com with ESMTPS id pm4si3901769lbb.32.2014.02.28.03.49.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Feb 2014 03:49:37 -0800 (PST) Received-SPF: neutral (google.com: 209.85.217.181 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id c11so2592851lbj.40 for ; Fri, 28 Feb 2014 03:49:37 -0800 (PST) X-Received: by 10.152.235.3 with SMTP id ui3mr11118871lac.2.1393588176917; Fri, 28 Feb 2014 03:49:36 -0800 (PST) Received: from linaro-ulf.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id cu8sm3591568lbb.12.2014.02.28.03.49.34 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Feb 2014 03:49:35 -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 , Greg Kroah-Hartman , Mark Brown , Russell King , Linus Walleij , Wolfram Sang , Alessandro Rubini , Josh Cartwright , Ulf Hansson Subject: [PATCH V3 1/8] PM / Runtime: Fetch runtime PM callbacks using a macro Date: Fri, 28 Feb 2014 12:49:32 +0100 Message-Id: <1393588172-20640-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 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.220.171 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 --- Changes in v3: Added functions to return the callbacks, which will be the only users of the macro. According to comments from Alan Stern and Kevin Hilman. Changes in v2: Updated the macro to return a callback instead. Suggested by Josh Cartwright. --- drivers/base/power/runtime.c | 78 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 72e00e6..ac495b1 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -13,6 +13,42 @@ #include #include "power.h" +#define RPM_GET_CALLBACK(dev, cb) \ +({ \ + int (*__rpm_cb)(struct device *__d); \ + \ + if (dev->pm_domain) \ + __rpm_cb = dev->pm_domain->ops.cb; \ + else if (dev->type && dev->type->pm) \ + __rpm_cb = dev->type->pm->cb; \ + else if (dev->class && dev->class->pm) \ + __rpm_cb = dev->class->pm->cb; \ + else if (dev->bus && dev->bus->pm) \ + __rpm_cb = dev->bus->pm->cb; \ + else \ + __rpm_cb = NULL; \ + \ + if (!__rpm_cb && dev->driver && dev->driver->pm) \ + __rpm_cb = dev->driver->pm->cb; \ + \ + __rpm_cb; \ +}) + +static int (*rpm_get_suspend_cb(struct device *dev))(struct device *) +{ + return RPM_GET_CALLBACK(dev, runtime_suspend); +} + +static int (*rpm_get_resume_cb(struct device *dev))(struct device *) +{ + return RPM_GET_CALLBACK(dev, runtime_resume); +} + +static int (*rpm_get_idle_cb(struct device *dev))(struct device *) +{ + return RPM_GET_CALLBACK(dev, runtime_idle); +} + static int rpm_resume(struct device *dev, int rpmflags); static int rpm_suspend(struct device *dev, int rpmflags); @@ -310,19 +346,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; + callback = rpm_get_idle_cb(dev); if (callback) retval = __rpm_callback(callback, dev); @@ -492,19 +516,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; + callback = rpm_get_suspend_cb(dev); retval = rpm_callback(callback, dev); if (retval) @@ -724,19 +736,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; + callback = rpm_get_resume_cb(dev); retval = rpm_callback(callback, dev); if (retval) {