From patchwork Mon Jul 17 20:06:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 9846035 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 C874A60392 for ; Mon, 17 Jul 2017 20:06:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB4E1284E3 for ; Mon, 17 Jul 2017 20:06:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B006528505; Mon, 17 Jul 2017 20:06:35 +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=ham 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 45B3B284E3 for ; Mon, 17 Jul 2017 20:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751341AbdGQUGe (ORCPT ); Mon, 17 Jul 2017 16:06:34 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:35540 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751316AbdGQUGd (ORCPT ); Mon, 17 Jul 2017 16:06:33 -0400 Received: by mail-qk0-f193.google.com with SMTP id z22so24791qka.2; Mon, 17 Jul 2017 13:06:32 -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=X5bSzKtJ5nuaRaX9r2/jqRbhCajzP2XRB6SWGOEXg+s=; b=AU2p5mmaIKuCNd3R97YxSEgrIR99XFL8VPEeY1tHuuAtGWVrFLG5TsfvIlyr2tCnn+ w+eJvGX3vFHyDuBrsx91wOUc/qNhGHJ9tP1roN5/oauZBAal5Z4vHe66h9Vzz/6968HB U9ZVZviWDgP8LSww6tLW7anoM0ukuZ5WsitaD15hPXpc7VorcCxc/K5ofLloFCQmiBr0 ucmyEtvCN2hJ50fzk8W1d65J9YjBvP/y3MBfuH0gtOMZYwC173Z2vCp7u5LA3U/xuxJa g3BsbPlnVDSi5MdlAHiEVv0MR+SyVS895ov/rxtvxt5tcqcBDd3P92kTSZ6azSIFAosB 46/Q== 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=X5bSzKtJ5nuaRaX9r2/jqRbhCajzP2XRB6SWGOEXg+s=; b=nRF3mTPkxy0SWpaU8kVKDBllVYin9r1WSCxJkgoEmyoeainmJiZMl+mS/h+po6f851 eyCb58r0STje8UoXU2KnP59KRKZAXFuULoc7wlLomy30r0a13YwWgLSOiUf4uiD94I2H d/izFj4GCUXZKN2SfKgVlimZmumzYfK2SzwBugEaS2Ql7P3z+OsrbJGaogdtWtDnXTjE t1vIbPctm4SLEyaP+UabX27YR9H6Yny+vLSsmhyQKpX1s/viGcF7MG5m98q3lIEyJlrc 9mcz1AKB9cRX3kHbdlVSqWqmdobQ0dQtZPn/aJiJ2VilEGjzbt+ziEfwBm6ezxd8xYTp wmpQ== X-Gm-Message-State: AIVw110zO77qRSfAENA1e+wWEVgsiDkGw8RZvOxtSfsW+x7Fs6KgcKTr 9kaVlbVO5LUWaweW/dQ= X-Received: by 10.55.167.211 with SMTP id q202mr31219425qke.77.1500321992233; Mon, 17 Jul 2017 13:06:32 -0700 (PDT) Received: from fainelli-desktop.broadcom.com ([192.19.255.250]) by smtp.gmail.com with ESMTPSA id v17sm108526qtc.39.2017.07.17.13.06.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jul 2017 13:06:31 -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 v2] PM / suspend: Add suspend_target_state() Date: Mon, 17 Jul 2017 13:06:28 -0700 Message-Id: <20170717200628.7018-1-f.fainelli@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170716023610.4658-1-f.fainelli@gmail.com> References: <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 Have the core suspend/resume framework store the system-wide suspend state (suspend_state_t) we are about to enter, and expose it to drivers via suspend_target_state() in order to retrieve that. The state is assigned in suspend_devices_and_enter(). 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. Signed-off-by: Florian Fainelli --- Changes in v2: - rename platform_suspend_target_state() -> suspend_target_state() - directly export the suspend_state_t value and assign it in suspend_devices_and_enter() include/linux/suspend.h | 2 ++ kernel/power/suspend.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 0b1cf32edfd7..7b70e7d6a006 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -202,6 +202,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 suspend_state_t suspend_target_state(void); extern unsigned int pm_suspend_global_flags; @@ -281,6 +282,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 suspend_state_t 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 3ecf275d7e44..a296d6e25d52 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -47,6 +47,7 @@ const char *mem_sleep_states[PM_SUSPEND_MAX]; suspend_state_t mem_sleep_current = PM_SUSPEND_FREEZE; static suspend_state_t mem_sleep_default = PM_SUSPEND_MEM; +static suspend_state_t pm_suspend_target_state; unsigned int pm_suspend_global_flags; EXPORT_SYMBOL_GPL(pm_suspend_global_flags); @@ -202,6 +203,18 @@ void suspend_set_ops(const struct platform_suspend_ops *ops) EXPORT_SYMBOL_GPL(suspend_set_ops); /** + * suspend_target_state - Return the system wide suspend state. + * + * The pm_suspend_target_state becomes valid during + * suspend_devices_and_enter(). + */ +suspend_state_t suspend_target_state(void) +{ + return pm_suspend_target_state; +} +EXPORT_SYMBOL_GPL(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 @@ -456,6 +469,8 @@ int suspend_devices_and_enter(suspend_state_t state) if (!sleep_state_supported(state)) return -ENOSYS; + pm_suspend_target_state = state; + error = platform_suspend_begin(state); if (error) goto Close;