From patchwork Fri Jun 23 01:08:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 9805511 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 9BA6A60329 for ; Fri, 23 Jun 2017 01:09:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1D832846A for ; Fri, 23 Jun 2017 01:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 946D728512; Fri, 23 Jun 2017 01:09:25 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI 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 3B1BA2846A for ; Fri, 23 Jun 2017 01:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754070AbdFWBI5 (ORCPT ); Thu, 22 Jun 2017 21:08:57 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36627 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753785AbdFWBIz (ORCPT ); Thu, 22 Jun 2017 21:08:55 -0400 Received: by mail-wr0-f194.google.com with SMTP id 77so8710724wrb.3; Thu, 22 Jun 2017 18:08:54 -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=hMsZe6Q+JF0CkkGQFLfjJ1hx0CoZsOnUd32ZOzTNATQ=; b=bRN1q1YBshDNm73Kem5KRyPpEwN2vxOn96TmY0UoT2D1+loGMZT6pqjGfHfWjIMSSy nazoK1Qt21vrfkDOlzoEiPlEi81JD4F0IrayfIXqQdFpsvAHyyek8HzohXCRTrExKFo7 Cna1tUhy07EVO/vB7LbIshhSvFMBOAE7y88701kl4jHKOWXl4JqZamiOcufkThf3jNC+ iRrfXqWi8Vj+ThSFvfATNrSncX5bPnJWUDNwr/h5fVTaqaXWd2ZLS5ocwANgtuXlD8Hi I72KBodDcvwNpvm4VKxr/Nw4DoJIcsQQ9c6TtqCL3zLuK3hLMRnuw2opV2JYLXj22B1V VbYA== 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=hMsZe6Q+JF0CkkGQFLfjJ1hx0CoZsOnUd32ZOzTNATQ=; b=ZUo9pHlvU1fCgkrkrj0ua/h/naIf019EtU3CAo72J/djvJADx8Ppxnsa8za39xvaLO U25SlCm0LBfb5mnkIqUohc9da327TII5DwRNVS1xeL2ixVpLzleXUu7u/BBlwBKf4M7l 0ntTIkN2oPQc5f7L3KrI0l0KLFiFR+BB7bnaF6e9z8ypi/fcJoMSZYOg0/QAE333gzuW LjmAIO8jBNr32kOMcQ5C1B+o1D1/VZkKklGwvjfDZwH1EEYzRDAxEJQgCS18vAl6pZaq UlcoPsHE70BhJjT/H5mK1brMhIG3XytqLoRaT1eYK5EO/6E7+pphYwsD5tEilfZJ7a4s ueOw== X-Gm-Message-State: AKS2vOxfgSQq54f8zkwnbhZLiZPDIFnRFR1sESNZ4e1UDbnjASfIQHFy Ixw7bzjbgmIoXF9oSAY= X-Received: by 10.28.1.85 with SMTP id 82mr3587589wmb.88.1498180133652; Thu, 22 Jun 2017 18:08:53 -0700 (PDT) Received: from fainelli-desktop.broadcom.com ([192.19.255.250]) by smtp.gmail.com with ESMTPSA id 92sm4883893wrb.55.2017.06.22.18.08.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jun 2017 18:08:52 -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: [RFC 1/2] PM / suspend: Add platform_suspend_target_state() Date: Thu, 22 Jun 2017 18:08:36 -0700 Message-Id: <20170623010837.11199-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170623010837.11199-1-f.fainelli@gmail.com> References: <20170622085102.mpk7vxodpgxtrlfd@piout.net> <20170623010837.11199-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. Signed-off-by: Florian Fainelli --- include/linux/suspend.h | 12 ++++++++++++ kernel/power/suspend.c | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index d9718378a8be..d998a04a90a2 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -172,6 +172,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 +193,7 @@ struct platform_suspend_ops { bool (*suspend_again)(void); void (*end)(void); void (*recover)(void); + int (*target_state)(void); }; struct platform_freeze_ops { @@ -200,6 +210,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 int platform_suspend_target_state(void); extern unsigned int pm_suspend_global_flags; @@ -279,6 +290,7 @@ 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 -ENOSYS; } 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 15e6baef5c73..d31fe7a08f4a 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -177,6 +177,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. + */ +int 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