From patchwork Mon Feb 24 10:22:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 25184 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1A7002066C for ; Mon, 24 Feb 2014 10:22:55 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id o6sf5485743oag.2 for ; Mon, 24 Feb 2014 02:22:54 -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=3uZ2aK2d81ZvvsEwXvjbHBPwpO0RBxESE3vaIhge2yE=; b=ZBPkUqtlVR9niLkMSCd62gHhnuyc3dMZh/Tu2OGJRgZlaRX2g6cmb/+LLDI1waUwJQ OOseNlunXfQclOWuStxtR0vtALJ8u04kJMrNsojl1u4Ls3V2gReV44ggPYDQfXilk04n YamQVU+fZHbl6lFZy8ntqnZigvAxQeEQ/Pf0IKePRHzAIS9y5pWLEA8WReoMtw4Gv+1l Y3fcNJ4uiWjKMg0yEFQb6TNXyJFMVhSwaHPG4DxoUpXXdVbxGiGPovN16XjV3EprpYSU GceQd0DTbn78l/cyU8cZAUzxwNBvqrlWFu/zkrUMFuGkLlzqSLmWXoC1McolGn+jpZ+D 8S8A== X-Gm-Message-State: ALoCoQl4euJF5ktyY0/epOpgDC6J6EbXaTBhdrWPYqE5ikhlM51/R2qgKfjbJxIm8TDAYYqUktb+ X-Received: by 10.50.164.198 with SMTP id ys6mr9014706igb.2.1393237374628; Mon, 24 Feb 2014 02:22:54 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.28.162 with SMTP id 31ls1966399qgz.50.gmail; Mon, 24 Feb 2014 02:22:54 -0800 (PST) X-Received: by 10.221.55.199 with SMTP id vz7mr12078860vcb.40.1393237374482; Mon, 24 Feb 2014 02:22:54 -0800 (PST) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id uc1si5701405vcb.128.2014.02.24.02.22.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 02:22:54 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.174 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.174; Received: by mail-vc0-f174.google.com with SMTP id im17so5648523vcb.19 for ; Mon, 24 Feb 2014 02:22:54 -0800 (PST) X-Received: by 10.221.30.14 with SMTP id sa14mr11908388vcb.44.1393237374388; Mon, 24 Feb 2014 02:22:54 -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 u4csp50985vcz; Mon, 24 Feb 2014 02:22:53 -0800 (PST) X-Received: by 10.180.210.171 with SMTP id mv11mr13560873wic.44.1393237373269; Mon, 24 Feb 2014 02:22:53 -0800 (PST) Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com [74.125.82.47]) by mx.google.com with ESMTPS id ej1si5052865wid.37.2014.02.24.02.22.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 02:22:53 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.47 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=74.125.82.47; Received: by mail-wg0-f47.google.com with SMTP id k14so4501987wgh.14 for ; Mon, 24 Feb 2014 02:22:52 -0800 (PST) X-Received: by 10.180.75.202 with SMTP id e10mr13507848wiw.50.1393237372798; Mon, 24 Feb 2014 02:22:52 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id hy8sm40899086wjb.2.2014.02.24.02.22.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 02:22:51 -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 V2 1/8] PM / Runtime: Fetch runtime PM callbacks using a macro Date: Mon, 24 Feb 2014 11:22:48 +0100 Message-Id: <1393237368-15500-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.174 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 v2: Updated the macro to return a callback instead. Suggested by Josh Cartwright. --- drivers/base/power/runtime.c | 63 ++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 72e00e6..cc7d1ed 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -13,6 +13,27 @@ #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_resume(struct device *dev, int rpmflags); static int rpm_suspend(struct device *dev, int rpmflags); @@ -310,19 +331,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_CALLBACK(dev, runtime_idle); if (callback) retval = __rpm_callback(callback, dev); @@ -492,19 +501,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_CALLBACK(dev, runtime_suspend); retval = rpm_callback(callback, dev); if (retval) @@ -724,19 +721,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_CALLBACK(dev, runtime_resume); retval = rpm_callback(callback, dev); if (retval) {