From patchwork Tue Apr 16 09:27:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902329 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 E96F6922 for ; Tue, 16 Apr 2019 09:29:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C31E5284C0 for ; Tue, 16 Apr 2019 09:29:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B782B288DA; Tue, 16 Apr 2019 09:29:29 +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 67E15284C0 for ; Tue, 16 Apr 2019 09:29:29 +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=YOJfcEChusspfj fjjbEDK+QTIJrV4FFz5vnMw/k7hstEtG6uxKQzk7x6G2nUZjbMGuqrYUD+9WlY4VpF7Xiir2xdgAs x2RGO8yrlQP0gtS3S62NXBDNNHI2jGhg8mRWum6MhrRTxTv2s/dqFKlIJyxcFhw7vMcDUa52aLdeb SiiLG3i/qxgJiuplx8m0L7h+mtz1shCcOvSXHkFkDRgno6YMLKG46Y868BPEkcx2iYTl6CK8GcSMe 1Ox0QQFHqm3ZRjCfJ66CQG4XowbcdIP6rfk6rWHAFxC0Y6OSz14jMhEsJ9uSphXXjOOenL5AJj3iz +HucWMPhlb874FxQbJXg==; 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 1hGKPA-0002iE-9H; Tue, 16 Apr 2019 09:29:28 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKNt-0001FJ-8c; Tue, 16 Apr 2019 09:28:13 +0000 X-UUID: c63ff9b3020245febbfb6b1fd1c3ca62-20190416 X-UUID: c63ff9b3020245febbfb6b1fd1c3ca62-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 232669426; Tue, 16 Apr 2019 01:28:02 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:28:01 -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:27:47 +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:27:47 +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:27:31 +0800 Message-ID: <1555406863-18069-4-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555406863-18069-1-git-send-email-stu.hsieh@mediatek.com> References: <1555406863-18069-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: F8A115F74A3FB00C08F721AA7D7A1D8E49C1960D65CAF6E8315D3D895B894B542000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_022809_887714_96A0C28B X-CRM114-Status: GOOD ( 13.07 ) 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, wsd_upstream@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,