From patchwork Sun Jul 16 02:36:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 9842611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A21A60393 for ; Sun, 16 Jul 2017 02:37:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BA00285B9 for ; Sun, 16 Jul 2017 02:37:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 507B9285C6; Sun, 16 Jul 2017 02:37:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A43E4285B9 for ; Sun, 16 Jul 2017 02:37:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751256AbdGPCgV (ORCPT ); Sat, 15 Jul 2017 22:36:21 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:33823 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751253AbdGPCgS (ORCPT ); Sat, 15 Jul 2017 22:36:18 -0400 Received: by mail-qt0-f195.google.com with SMTP id m54so14631846qtb.1; Sat, 15 Jul 2017 19:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NLHxgK4U8NEIaGEnegqBo/rK+TiI6ItCXebM3LdcXvE=; b=cYtbMJEmxCPlG0V1+65WRU+AXTqh7aWMspfyjpm+al03dga4h/A5q++stGFgH2UU9B q4hq3LLGX80UVvCTjia/HWEphnhPF5Gk0D7k5C5wbuBlNN5PKMF9SeVZD2XZKM+Zp8g3 7x8bA1/YA0njSiQqWsBw2hCbk4qOK+rEd80D9S5etk+L0n+5/6+TuWqcdKfX9p9Cobwj pdAm96+p13edVYZam/U05Q3i6KQ+6rLZlu+VtCbvs7vuTuDDK77c0M4b0yUQn1xluK51 q1jkRDI1eonQPNewD+QNzklvNL1gWagV3S+/oUpekQyOg66r62UPAQEGhdsqOE5xzZSn LL0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NLHxgK4U8NEIaGEnegqBo/rK+TiI6ItCXebM3LdcXvE=; b=c1BF+5Cv84WCrU3NVs700bTz/bfbfSQbeEj3WwkQExDpifEikXXgl88NCln1LhHJE8 4eZux0j7VTNHbs7AXt0dYwgzkKdv38uNGN4Gw+l1LOyBDMEKgTFNcZFjSP46Fp5NDNpq utxkV9twDZlBEd092fh3wpkIboVZVadA8w2euR6w6PBCtis5DfBuOXr3m5D6fOB5NudR gYDDabFqB9AAAIElNZ5e0xiwhw0r77Rr8tsta41+QhukZdTaTMGMiiSn9suKDppr7xnv KWteZL+UxtkADSNsEgXFBu8Z59D2u/eqo6anRE/k7cNzYwFmYaeH6/n1Tq55fOAZ/joC 554g== X-Gm-Message-State: AIVw112BgYbsVaQGlveW6SwlyaOK8fmjQNQZr5CJp2Bi7GImzFu2xEqp AJxj+UEpBXbVelQk6iA= X-Received: by 10.237.56.135 with SMTP id k7mr21026805qte.134.1500172577430; Sat, 15 Jul 2017 19:36:17 -0700 (PDT) Received: from fainelli-desktop.broadcom.com ([192.19.255.250]) by smtp.gmail.com with ESMTPSA id x40sm10856966qta.66.2017.07.15.19.36.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jul 2017 19:36:16 -0700 (PDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Cc: Florian Fainelli , "Rafael J. Wysocki" , Alexandre Belloni , "Rafael J. Wysocki" , Ulf Hansson , Daniel Lezcano , linux-pm , Thibaud Cornic , JB , Mason , Kevin Hilman , Pavel Machek , Linux ARM Subject: [PATCH 1/2] PM / suspend: Add platform_suspend_target_state() Date: Sat, 15 Jul 2017 19:36:09 -0700 Message-Id: <20170716023610.4658-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170716023610.4658-1-f.fainelli@gmail.com> References: <20170623010837.11199-1-f.fainelli@gmail.com> <20170716023610.4658-1-f.fainelli@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an optional platform_suspend_ops callback: target_state, and a helper function globally visible to get this called: platform_suspend_target_state(). This is useful for platform specific drivers that may need to take a slightly different suspend/resume path based on the system's suspend/resume state being entered. Although this callback is optional and documented as such, it requires a platform_suspend_ops::begin callback to be implemented in order to provide an accurate suspend/resume state within the driver that implements this platform_suspend_ops. An enumeration: platform_target_state is defined which currently defines the standard ACPI_S[1-4] states and can be extended with platform specific suspend states. Signed-off-by: Florian Fainelli --- include/linux/suspend.h | 25 +++++++++++++++++++++++++ kernel/power/suspend.c | 15 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 0b1cf32edfd7..6e6cc0778816 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -50,6 +50,16 @@ enum suspend_stat_step { SUSPEND_RESUME }; +enum platform_target_state { + PLATFORM_STATE_UNKNOWN = -1, + PLATFORM_STATE_WORKING = 0, + PLATFORM_STATE_ACPI_S1, + PLATFORM_STATE_ACPI_S2, + PLATFORM_STATE_ACPI_S3, + PLATFORM_STATE_ACPI_S4, + /* Add platform specific states here */ +}; + struct suspend_stats { int success; int fail; @@ -172,6 +182,15 @@ static inline void dpm_save_failed_step(enum suspend_stat_step step) * Called by the PM core if the suspending of devices fails. * This callback is optional and should only be implemented by platforms * which require special recovery actions in that situation. + * + * @target_state: Returns the suspend state the suspend_ops will be entering. + * Called by device drivers that need to know the platform specific suspend + * state the system is about to enter. + * This callback is optional and should only be implemented by platforms + * which require special handling of power management states within + * drivers. It does require @begin to be implemented to provide the suspend + * state. Return value is platform_suspend_ops specific, and may be a 1:1 + * mapping to suspend_state_t when relevant. */ struct platform_suspend_ops { int (*valid)(suspend_state_t state); @@ -184,6 +203,7 @@ struct platform_suspend_ops { bool (*suspend_again)(void); void (*end)(void); void (*recover)(void); + enum platform_target_state (*target_state)(void); }; struct platform_freeze_ops { @@ -202,6 +222,7 @@ struct platform_freeze_ops { */ extern void suspend_set_ops(const struct platform_suspend_ops *ops); extern int suspend_valid_only_mem(suspend_state_t state); +extern enum platform_target_state platform_suspend_target_state(void); extern unsigned int pm_suspend_global_flags; @@ -281,6 +302,10 @@ static inline bool pm_resume_via_firmware(void) { return false; } static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {} static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; } +static inline int platform_suspend_target_state(void) +{ + return PLATFORM_STATE_UNKNOWN; +} static inline bool idle_should_freeze(void) { return false; } static inline void __init pm_states_init(void) {} static inline void freeze_set_ops(const struct platform_freeze_ops *ops) {} diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index 3ecf275d7e44..cd1b62f23b0e 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -202,6 +202,21 @@ void suspend_set_ops(const struct platform_suspend_ops *ops) EXPORT_SYMBOL_GPL(suspend_set_ops); /** + * platform_suspend_target_state - Return the platform specific suspend state. + * a begin() callback is necessary in order to fill this information correctly + * for callers. + */ +enum platform_target_state platform_suspend_target_state(void) +{ + if (!suspend_ops || !suspend_ops->target_state || + (suspend_ops->target_state && !suspend_ops->begin)) + return -ENOTSUPP; + + return suspend_ops->target_state(); +} +EXPORT_SYMBOL_GPL(platform_suspend_target_state); + +/** * suspend_valid_only_mem - Generic memory-only valid callback. * * Platform drivers that implement mem suspend only and only need to check for