From patchwork Tue Apr 16 09:30:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33E7F161F for ; Tue, 16 Apr 2019 09:59:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CDF92882E for ; Tue, 16 Apr 2019 09:59:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10101288DC; Tue, 16 Apr 2019 09:59:27 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY 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 7247C2892D for ; Tue, 16 Apr 2019 09:59:26 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=65mLxc9RvkGot5bPGTZMPuZEtZW0IXgwJwz6d6NqURI=; b=AkJjdvMnOjnnC1 XTuzWuuAIUwqHk8/xej5cqTSlW/knrWWBuvU48Or/CAZi7Fya5pDD8WZZU9bzA3zyFvtgeM6iWrmX 7bX85V1DfM5rGumwp4YiYRUHyDvZDRQ1VQxTzXL7o+SISu8w912c9UmpFoD+ZWPtAza4JKAM1NBUD DjaIZpHa/YCXGJPP0tVwkaJc4ISVS4eK7KRVoGcxGeocxe4ZKldfj+dx0PmZgbA6qvVWkBiBaPgrn Kddu54BFH3px1Ysf8Gmwp+AscwQ5zuGuTJuXNmPw05Py/uU9Jx8/EDZ6sNAex7ShaWavGYg7VEcNa Tdl5lvilp72l3tyCIuag==; 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 1hGKs9-0003ec-Mi; Tue, 16 Apr 2019 09:59:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdY-0004By-15 for linux-mediatek@bombadil.infradead.org; Tue, 16 Apr 2019 09:44:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SqSJf1qx+QuLCgAXmpSaiW9+NBfayUhxGOHTonm2zhc=; b=BiOxRySJxkcnoJ/FDnqZ+cjAW BtGvonSO7o1oPKIyKAdfa6mfqzr7wWiONJMREYasTUs5APXeZGveUePm2R1Yu193zP288PXwxc6HS CimK5fNVVA0MYX523FhK9qA1ap1AImgbCRbzCAREcp3gTYgQC8f4Adfi7knETFzF0I5sHOMMjXwpx l9UCe18dnowIxqG6u493HYlGCkxDyKbQCFsKLFdyrmdYOo2Rm50XSMBTOdrhvELXJjj6swEcaPayA T7F7YSHM0ki7rm0HGOI5aK/voEFXyvMVVVasOd2soixm9e5DfBNmLFrPiQnajAGNLtMeOiiNZWAHZ 4Q4tg6lwA==; Received: from mailgw02.mediatek.com ([216.200.240.185]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQI-0002lY-Cm for linux-mediatek@lists.infradead.org; Tue, 16 Apr 2019 09:30:40 +0000 X-UUID: fdf13d437a7142f388dcdddd390efd85-20190416 X-UUID: fdf13d437a7142f388dcdddd390efd85-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 995971912; Tue, 16 Apr 2019 01:30:20 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:19 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:17 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 03/15] [media] mtk-mipicsi: add pm function Date: Tue, 16 Apr 2019 17:30:03 +0800 Message-ID: <1555407015-18130-4-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 48967CEB63FF91E327FD0A2DCBA22904CA4C750A69FB2313E50D2B42E8D872CA2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_103038_730016_BA493C06 X-CRM114-Status: GOOD ( 17.53 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add PM function to enable/disable clk and larb. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index e26bebe17fe5..ec4f6b503b32 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -464,6 +464,85 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .set_bus_param = mtk_mipicsi_set_bus_param, }; +static int mtk_mipicsi_pm_suspend(struct device *dev) +{ + struct soc_camera_host *ici = to_soc_camera_host(dev); + struct mtk_mipicsi_dev *mipicsi = NULL; + int ret = 0; + int i = 0; + + mipicsi = container_of(ici, struct mtk_mipicsi_dev, soc_host); + if (mipicsi->soc_host.icd != NULL) { + struct v4l2_subdev *sd = + soc_camera_to_subdev(mipicsi->soc_host.icd); + + ret = v4l2_subdev_call(sd, core, s_power, 0); + if (ret == -ENOIOCTLCMD) + ret = 0; + } + + /* close digtal and analog clock */ + for (i = 0; i < mipicsi->clk_num; ++i) + clk_disable_unprepare(mipicsi->clk[i]); + + if (mipicsi->larb_pdev != NULL) + mtk_smi_larb_put(mipicsi->larb_pdev); + + return ret; +} + +static int mtk_mipicsi_suspend(struct device *dev) +{ + if (pm_runtime_suspended(dev)) + return 0; + + return mtk_mipicsi_pm_suspend(dev); +} + +static int mtk_mipicsi_pm_resume(struct device *dev) +{ + struct soc_camera_host *ici = to_soc_camera_host(dev); + struct mtk_mipicsi_dev *mipicsi = + container_of(ici, struct mtk_mipicsi_dev, soc_host); + int ret = 0; + int i = 0; + + if (mipicsi->soc_host.icd != NULL) { + struct v4l2_subdev *sd = + soc_camera_to_subdev(mipicsi->soc_host.icd); + + ret = v4l2_subdev_call(sd, core, s_power, 1); + if (ret == -ENOIOCTLCMD) + ret = 0; + } + + if (mipicsi->larb_pdev != NULL) { + ret = mtk_smi_larb_get(mipicsi->larb_pdev); + if (ret != 0) + return ret; + } + + /* enable digtal clock */ + for (i = 0; i < mipicsi->clk_num; ++i) + (void)clk_prepare_enable(mipicsi->clk[i]); + + return ret; +} + +static int mtk_mipicsi_resume(struct device *dev) +{ + if (pm_runtime_suspended(dev)) + return 0; + + return mtk_mipicsi_pm_resume(dev); +} + +static const struct dev_pm_ops mtk_mipicsi_pm = { + SET_SYSTEM_SLEEP_PM_OPS(mtk_mipicsi_suspend, mtk_mipicsi_resume) + SET_RUNTIME_PM_OPS(mtk_mipicsi_pm_suspend, + mtk_mipicsi_pm_resume, NULL) +}; + static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, int index) { @@ -756,6 +835,7 @@ static const struct of_device_id mtk_mipicsi_of_match[] = { static struct platform_driver mtk_mipicsi_driver = { .driver = { .name = MTK_MIPICSI_DRV_NAME, + .pm = &mtk_mipicsi_pm, .of_match_table = of_match_ptr(mtk_mipicsi_of_match), }, .probe = mtk_mipicsi_probe,