From patchwork Thu Mar 15 09:29:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 10284145 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 7CC5960291 for ; Thu, 15 Mar 2018 09:31:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F44128972 for ; Thu, 15 Mar 2018 09:31:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73ED828977; Thu, 15 Mar 2018 09:31: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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 12AAC28972 for ; Thu, 15 Mar 2018 09:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751806AbeCOJbB (ORCPT ); Thu, 15 Mar 2018 05:31:01 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34205 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751738AbeCOJam (ORCPT ); Thu, 15 Mar 2018 05:30:42 -0400 Received: by mail-wm0-f68.google.com with SMTP id a20so22215151wmd.1 for ; Thu, 15 Mar 2018 02:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=boaJ70rDdGnxcniUrG2PsqsXZwMQh1pYFhh3bZ4D0Cc=; b=GTfUarzdQMsuLtjOw5mApIIhKkRmnAwJ+j/mbv9qkdAAsD+nML/0Awu5L+MLBQLSIH PVxjLYxK2MMDliExN5PnhihFege1tsttiW0g1pUzXzAJRHxxg4Wbe5ZpN9Ia2+rcOd0o AQuwyY2rLqBYu/dgpNeDkhgogR8z88v9YDnCw= 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=boaJ70rDdGnxcniUrG2PsqsXZwMQh1pYFhh3bZ4D0Cc=; b=NlP1Zw5tzLv5qYbcV3v2RWOc1Wo6LjMHEQ6EnGKhMb8EhC6pBzgfmvfmaQIK9D2FTH DRxjv0suh3AHeO3nhom7nl1xyYLdna5MFGfUI41kSwf5dR95hKvzPE2gEzTF9amBxcYH re5ZlSx0gnRLjwwqBT0ZooZaxWykNciKtF0SNgY4dfJYNVqgUuB4j74rhaIXimbJvKL8 JSdOnj/vA5Vs9KxbBEur6MvND9hFCZaaA8W4RUdUomC9y3R1P2yPhwlNS97k5bqbYith vb+i/BwY/SJ5jh25CILtcp/xDK0LwaXyn6HGuk7H4N2tpUy+KKw9VcAebp1QUiJRR6wa 7veQ== X-Gm-Message-State: AElRT7FFd3P/8Cs/hsDkb9Hsogt2G5HUh5/IkvRws6lZiFeHZyR9urCq yMehUIotCxLpZP5UPDncyh6lKA== X-Google-Smtp-Source: AG47ELt9+5GvEawcVKQzMsFmmulzlfYdWbOg+I4zXk4I7VsENQO672alW4qbozBKsAv3Xf2QSXxaAQ== X-Received: by 10.28.58.199 with SMTP id h190mr4070661wma.119.1521106240852; Thu, 15 Mar 2018 02:30:40 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([80.214.78.222]) by smtp.gmail.com with ESMTPSA id m71sm3603844wmd.6.2018.03.15.02.30.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Mar 2018 02:30:40 -0700 (PDT) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: mchehab@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, hans.verkuil@cisco.com Cc: linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Benjamin Gaignard Subject: [PATCH 2/2] cec: stm32: add suspend/resume functions Date: Thu, 15 Mar 2018 10:29:49 +0100 Message-Id: <20180315092949.9895-3-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180315092949.9895-1-benjamin.gaignard@st.com> References: <20180315092949.9895-1-benjamin.gaignard@st.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Benjamin Gaignard If wake up irq is defined in device-tree cec adapter could be used has wake up source. Signed-off-by: Benjamin Gaignard --- drivers/media/platform/stm32/stm32-cec.c | 44 +++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/stm32/stm32-cec.c b/drivers/media/platform/stm32/stm32-cec.c index 35cc2ffd6b96..68e18ee6655b 100644 --- a/drivers/media/platform/stm32/stm32-cec.c +++ b/drivers/media/platform/stm32/stm32-cec.c @@ -11,8 +11,11 @@ #include #include #include +#include #include +#include #include +#include #include #include @@ -243,7 +246,7 @@ static int stm32_cec_probe(struct platform_device *pdev) struct resource *res; struct stm32_cec *cec; void __iomem *mmio; - int ret; + int ret, wakeirq; cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL); if (!cec) @@ -274,6 +277,12 @@ static int stm32_cec_probe(struct platform_device *pdev) if (ret) return ret; + wakeirq = of_irq_get_byname(pdev->dev.of_node, "wakeup"); + if (wakeirq > 0) { + device_init_wakeup(&pdev->dev, true); + dev_pm_set_dedicated_wake_irq(&pdev->dev, wakeirq); + } + cec->clk_cec = devm_clk_get(&pdev->dev, "cec"); if (IS_ERR(cec->clk_cec)) { dev_err(&pdev->dev, "Cannot get cec clock\n"); @@ -312,12 +321,44 @@ static int stm32_cec_remove(struct platform_device *pdev) { struct stm32_cec *cec = platform_get_drvdata(pdev); + dev_pm_clear_wake_irq(&pdev->dev); + device_init_wakeup(&pdev->dev, false); + cec_unregister_adapter(cec->adap); pm_runtime_disable(&pdev->dev); return 0; } + +static int __maybe_unused stm32_cec_suspend(struct device *dev) +{ + struct stm32_cec *cec = dev_get_drvdata(dev); + + pm_runtime_force_suspend(dev); + + if (device_may_wakeup(dev)) + enable_irq_wake(cec->irq); + + pinctrl_pm_select_sleep_state(dev); + + return 0; +} + +static int __maybe_unused stm32_cec_resume(struct device *dev) +{ + struct stm32_cec *cec = dev_get_drvdata(dev); + + pinctrl_pm_select_default_state(dev); + + if (device_may_wakeup(dev)) + disable_irq_wake(cec->irq); + + pm_runtime_force_resume(dev); + + return 0; +} + static int __maybe_unused stm32_cec_runtime_suspend(struct device *dev) { struct stm32_cec *cec = dev_get_drvdata(dev); @@ -341,6 +382,7 @@ static int __maybe_unused stm32_cec_runtime_resume(struct device *dev) static const struct dev_pm_ops stm32_cec_pm_ops = { SET_RUNTIME_PM_OPS(stm32_cec_runtime_suspend, stm32_cec_runtime_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(stm32_cec_suspend, stm32_cec_resume) }; static const struct of_device_id stm32_cec_of_match[] = {