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: 10284147 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 A285660386 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 A470228972 for ; Thu, 15 Mar 2018 09:31:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98FC728975; 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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C35C28974 for ; Thu, 15 Mar 2018 09:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NpXu2KvGZ6wxGoErXNkdMdqPaMOsdldvG5QA8TyhnAA=; b=Df0UleZ6aFzcaklfrjptyNSDWf uUKzAvXRFS63euxDG0HSTwyo9cMg65feLtL7RuctTAMWEwsNqc6BwdTuUBfZ1YXjq1jtjgfoKz6Di eQBSt+lqO2kmmYOwyRsa2PiVv6C9GJgWJvOhqKqqxYXh0beRaCUKs3tSyqmxxf2PWjdp7rbKlrE8W vlFOgaUO3AgbF4knq174Op5V7VbEza7DChDsR523+80hBV7aTZNahVjvTbNR4tkuaHmJrxaZ2pTGO yqtIOBrbnXaD8MXuULbDBy/C5a4IV8glhHJi9vgy+Vq8Zuz4h/gLdxBRZVbO6UiP7b1b/30z5V8ST 6jApRU3Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewPDs-00026Z-Ml; Thu, 15 Mar 2018 09:30:56 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewPDo-00023l-HW for linux-arm-kernel@lists.infradead.org; Thu, 15 Mar 2018 09:30:54 +0000 Received: by mail-wm0-x241.google.com with SMTP id s206so22228052wme.0 for ; Thu, 15 Mar 2018 02:30:42 -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=LZsbP2KKH013JiQXzCSF6VaagOePg3Ube3/2uihcAl0bJ23l3gPKa7cxSDqlcjKzdK /F/OxRbvffuDzIh0WdVmijoxAO9R1/py4VmMMDLCORw3NdpV0R2KcrITiSroRZzn1AQD CK6DsCA5Aa+rFwtBP17FOWJqcgxMZ8D/FQ5iOcQcYRgWGpQXQqt/dJXULPMdf1cDwsJq Vn8NThr2P7CxLa5RWsMGYNeZFw4UVB+q+Iju3otDDZ9YhfZ992e1rOdAGp4wczunNgDL 01+/GMSO7av18sNW2M2h8fSrS37lYL8Ct6fF1putCBcl2SWPMDmkMAK1F0/9kc4dlEan YQWw== X-Gm-Message-State: AElRT7GmNImMau6V6LhrI1MHjWAs9BzZnFBnbIHtnbmgc04NQzSowxUY jkBdJUbpqYBkxfWv5awv4udTkg== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180315_023052_733030_2084D139 X-CRM114-Status: GOOD ( 16.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benjamin Gaignard , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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[] = {