From patchwork Tue May 19 14:11:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6438161 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 89F99C0432 for ; Tue, 19 May 2015 14:13:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9233820254 for ; Tue, 19 May 2015 14:12:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AD722039D for ; Tue, 19 May 2015 14:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752989AbbESOMF (ORCPT ); Tue, 19 May 2015 10:12:05 -0400 Received: from mail-wg0-f53.google.com ([74.125.82.53]:36659 "EHLO mail-wg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932808AbbESOMD (ORCPT ); Tue, 19 May 2015 10:12:03 -0400 Received: by wgbgq6 with SMTP id gq6so19554860wgb.3; Tue, 19 May 2015 07:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=CHClGnredXgveE5fag7Tpgwk43M0te19guI9LdhfaW0=; b=XTpp1JdoRbAO5ABa89vKMIgkfX/NFdhBa7r3mDgjsUcozv2pSJ7TvOZoTQcsD4c4Kt BsBMACgwPCLj9JGMqxGfofMMQMVcVUlYUjhqlrh13N87+WcINKq8mrbklNihdl7iHTAC QaKo/alUd6NVlDa+Hfymx6Sb2wwSrOKblqUi+b55ZjwrZhXAjhNuukd2U7sFu/ZoGQTh +yQkAQZ5qaNhz7nmUAMGBNChE52UBDKFYpCIG9BEi4jKTvKxMaJdBihlw1BH6JwI3kTk NyZrwxrKpS9E4i5zP8TjpW9jJVgPmQ03M3qEouRmSDac/AZjvtCDkF1BxL00p5igZ06V HdLw== X-Received: by 10.180.85.72 with SMTP id f8mr31775432wiz.62.1432044721138; Tue, 19 May 2015 07:12:01 -0700 (PDT) Received: from cizrna.lan ([109.72.12.94]) by mx.google.com with ESMTPSA id gs7sm17564806wib.10.2015.05.19.07.11.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 May 2015 07:12:00 -0700 (PDT) From: Tomeu Vizoso To: linux-pm@vger.kernel.org Cc: Laurent Pinchart , Dmitry Torokhov , Alan Stern , Tomeu Vizoso , "Rafael J. Wysocki" , Len Brown , Pavel Machek , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] PM / sleep: Add power.direct_complete_default flag Date: Tue, 19 May 2015 16:11:15 +0200 Message-Id: <1432044679-10256-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1432044679-10256-1-git-send-email-tomeu.vizoso@collabora.com> References: <1432044679-10256-1-git-send-email-tomeu.vizoso@collabora.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a new per-device flag power.direct_complete_default that will instruct the PM core to let that device remain in runtime suspend when the system goes into a sleep power state, without it having to implement the prepare() callback. This is useful because otherwise it would be needed to get dozens of drivers to implement the prepare() callback even if they don't have a 1-to-1 relationship with a piece of HW. Signed-off-by: Tomeu Vizoso --- v3: * Have the flag be a more direct substitute for prepare() as suggested by Rafael * Inherit this flag from the parent device v2: * Fix wording as suggested by Kevin Hilman --- Documentation/power/runtime_pm.txt | 8 +++++++- drivers/base/power/main.c | 5 +++++ include/linux/pm.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt index e76dc0a..caf7b53 100644 --- a/Documentation/power/runtime_pm.txt +++ b/Documentation/power/runtime_pm.txt @@ -228,6 +228,12 @@ defined in include/linux/pm.h: unsigned int ignore_children; - if set, the value of child_count is ignored (but still updated) + bool direct_complete_default; + - if set, the device will be left runtime-suspended when the system + transitions to a sleep state, unless there's a .prepare() callback that + returns a non-positive value. This flag is inherited from the parent + device when a device is added to the PM core's list of active devices. + unsigned int disable_depth; - used for disabling the helper functions (they work normally if this is equal to zero); the initial value of it is 1 (i.e. runtime PM is @@ -669,7 +675,7 @@ system suspend and resume callbacks for all of those devices, except for the complete callback, which is then entirely responsible for handling the device as appropriate. This only applies to system suspend transitions that are not related to hibernation (see Documentation/power/devices.txt for more -information). +information). See also power.direct_complete_default. The PM core does its best to reduce the probability of race conditions between the runtime PM and system suspend/resume (and hibernation) callbacks by carrying diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 3d874ec..175ddec 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -128,6 +128,9 @@ void device_pm_add(struct device *dev) if (dev->parent && dev->parent->power.is_prepared) dev_warn(dev, "parent %s should not be sleeping\n", dev_name(dev->parent)); + if (dev->parent) + dev->power.direct_complete_default = + dev->parent->power.direct_complete_default; list_add_tail(&dev->power.entry, &dpm_list); mutex_unlock(&dpm_list_mtx); } @@ -1589,6 +1592,8 @@ static int device_prepare(struct device *dev, pm_message_t state) trace_device_pm_callback_start(dev, info, state.event); ret = callback(dev); trace_device_pm_callback_end(dev, ret); + } else if (dev->power.direct_complete_default) { + ret = 1; } device_unlock(dev); diff --git a/include/linux/pm.h b/include/linux/pm.h index 4890743..fcb3451 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -565,6 +565,7 @@ struct dev_pm_info { bool ignore_children:1; bool early_init:1; /* Owned by the PM core */ bool direct_complete:1; /* Owned by the PM core */ + bool direct_complete_default:1; /* Ditto */ spinlock_t lock; #ifdef CONFIG_PM_SLEEP struct list_head entry;