From patchwork Mon Oct 13 14:02:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 38660 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B8E342039B for ; Mon, 13 Oct 2014 14:02:35 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id a1sf4197028wgh.5 for ; Mon, 13 Oct 2014 07:02:34 -0700 (PDT) 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=SGmxfuiTs6K49V5ctcfenOYQIFl7xbmsViPs+r35qtc=; b=CW/TP+zYxLT2GkmkdvHo1Z3pFRDPJeFE7JprMQGtVmAWHmngJPgVENV++dveOT2Os+ Wa4/CdZTCUK87ijZeYnZ8M55ECXEjZsVsvRUwrUNDXT0MYoN8661eBEkfBaY/9h5vmWe ARp4yza8CWWA0afrRJuSW+lc/We8oFJJrlQktVsninb7L9++zjVIL5Rl7VBhIeIw1kfV bJhRG0CA5BPM7PuFtEb+lR7m6psrkRf27hJElCx+IVPHjj/uysZO4xdWtfcL5MVdNQu/ 3G7GMqxLh460BQ1tX+U8Ghb7wSBBQN4F7bXNyWHlXo7O4eTzat46lIuUt+RgKoltVFaT 81MQ== X-Gm-Message-State: ALoCoQlGgVdsE78MtRD+OyzjH3VeXmiiM3VKrPUOVBDe8Gdrihuu/qLuDZmLFzJnUGNiA+MeBoJ4 X-Received: by 10.112.168.225 with SMTP id zz1mr602012lbb.8.1413208954352; Mon, 13 Oct 2014 07:02:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.4 with SMTP id x4ls76269lag.42.gmail; Mon, 13 Oct 2014 07:02:34 -0700 (PDT) X-Received: by 10.112.52.165 with SMTP id u5mr3798859lbo.80.1413208954215; Mon, 13 Oct 2014 07:02:34 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com [209.85.215.48]) by mx.google.com with ESMTPS id zm10si22254012lbb.125.2014.10.13.07.02.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 07:02:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id gi9so6818209lab.35 for ; Mon, 13 Oct 2014 07:02:34 -0700 (PDT) X-Received: by 10.112.190.69 with SMTP id go5mr24044790lbc.32.1413208954038; Mon, 13 Oct 2014 07:02:34 -0700 (PDT) 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.112.84.229 with SMTP id c5csp220096lbz; Mon, 13 Oct 2014 07:02:33 -0700 (PDT) X-Received: by 10.180.74.197 with SMTP id w5mr978443wiv.7.1413208953462; Mon, 13 Oct 2014 07:02:33 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) by mx.google.com with ESMTPS id n9si12829312wic.14.2014.10.13.07.02.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 07:02:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.212.179 as permitted sender) client-ip=209.85.212.179; Received: by mail-wi0-f179.google.com with SMTP id d1so7524233wiv.12 for ; Mon, 13 Oct 2014 07:02:33 -0700 (PDT) X-Received: by 10.194.3.78 with SMTP id a14mr2932847wja.91.1413208953225; Mon, 13 Oct 2014 07:02:33 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id fq1sm1533474wib.12.2014.10.13.07.02.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Oct 2014 07:02:32 -0700 (PDT) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Geert Uytterhoeven , Kevin Hilman , Alan Stern , Greg Kroah-Hartman , Tomasz Figa , Simon Horman , Magnus Damm , Ben Dooks , Kukjin Kim , Philipp Zabel , Mark Brown , Wolfram Sang , Russell King , Dmitry Torokhov , Jack Dai , Jinkun Hong , Aaron Lu , Sylwester Nawrocki , Ulf Hansson Subject: [PATCH v3 2/9] PM / Domains: Enable genpd to support ->get|put() callbacks Date: Mon, 13 Oct 2014 16:02:03 +0200 Message-Id: <1413208930-26019-3-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1413208930-26019-1-git-send-email-ulf.hansson@linaro.org> References: <1413208930-26019-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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) 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: , To provide users control over whether the power should be maintained, implement the ->get|put() callbacks for genpd's PM domain. A usage count variable keeps track of the number of users. A positive value tells genpd to keep supplying power and also to power up if it's the first user. Do note, the above applies no matter of CONFIG_PM_RUNTIME. That's because we allows a PM domain to be initialized in power off state and thus we need a way to power it up. Once the usage count reaches zero, genpd tries to power off its PM domain. Although for !CONFIG_PM_RUNTIME we need to maintain the power once it's been enabled, since drivers can't use runtime PM to restore it dynamically. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 26 +++++++++++++++++++++++++- include/linux/pm_domain.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 40bc2f4..96fe72e 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -451,10 +451,12 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd) * (2) The domain is waiting for its master to power up. * (3) One of the domain's devices is being resumed right now. * (4) System suspend is in progress. + * (5) The usage_count > 0, since it tells us to stay powered. */ if (genpd->status == GPD_STATE_POWER_OFF || genpd->status == GPD_STATE_WAIT_MASTER - || genpd->resume_count > 0 || genpd->prepared_count > 0) + || genpd->resume_count > 0 || genpd->prepared_count > 0 + || atomic_read(&genpd->usage_count) > 0) return 0; if (atomic_read(&genpd->sd_count) > 0) @@ -1358,6 +1360,25 @@ EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweron); #endif /* CONFIG_PM_SLEEP */ +static int pm_genpd_get(struct dev_pm_domain *domain) +{ + struct generic_pm_domain *genpd = pd_to_genpd(domain); + + atomic_inc(&genpd->usage_count); + + return pm_genpd_poweron(genpd); +} + +static void pm_genpd_put(struct dev_pm_domain *domain) +{ + struct generic_pm_domain *genpd = pd_to_genpd(domain); + + if (!atomic_dec_and_test(&genpd->usage_count)) + return; + + genpd_queue_power_off_work(genpd); +} + static struct generic_pm_domain_data *__pm_genpd_alloc_dev_data(struct device *dev) { struct generic_pm_domain_data *gpd_data; @@ -1875,10 +1896,13 @@ void pm_genpd_init(struct generic_pm_domain *genpd, genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE; init_waitqueue_head(&genpd->status_wait_queue); genpd->poweroff_task = NULL; + atomic_set(&genpd->usage_count, 0); genpd->resume_count = 0; genpd->device_count = 0; genpd->max_off_time_ns = -1; genpd->max_off_time_changed = true; + genpd->domain.get = pm_genpd_get; + genpd->domain.put = pm_genpd_put; genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend; genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume; genpd->domain.ops.prepare = pm_genpd_prepare; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 8e2806f..7b3cba2 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -58,6 +58,7 @@ struct generic_pm_domain { enum gpd_status status; /* Current state of the domain */ wait_queue_head_t status_wait_queue; struct task_struct *poweroff_task; /* Powering off task */ + atomic_t usage_count; /* Number of users of the domain */ unsigned int resume_count; /* Number of devices being resumed */ unsigned int device_count; /* Number of devices */ unsigned int suspended_count; /* System suspend device counter */