Linux 4.19.133
[linux/fpc-iii.git] / drivers / media / platform / mtk-vcodec / mtk_vcodec_enc_pm.c
blob7c025045ea904ff12279c98acc05eca5b55198bf
1 /*
2 * Copyright (c) 2016 MediaTek Inc.
3 * Author: Tiffany Lin <tiffany.lin@mediatek.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/clk.h>
16 #include <linux/of_address.h>
17 #include <linux/of_platform.h>
18 #include <linux/pm_runtime.h>
19 #include <soc/mediatek/smi.h>
21 #include "mtk_vcodec_enc_pm.h"
22 #include "mtk_vcodec_util.h"
23 #include "mtk_vpu.h"
26 int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
28 struct device_node *node;
29 struct platform_device *pdev;
30 struct device *dev;
31 struct mtk_vcodec_pm *pm;
32 int ret = 0;
34 pdev = mtkdev->plat_dev;
35 pm = &mtkdev->pm;
36 memset(pm, 0, sizeof(struct mtk_vcodec_pm));
37 pm->mtkdev = mtkdev;
38 pm->dev = &pdev->dev;
39 dev = &pdev->dev;
41 node = of_parse_phandle(dev->of_node, "mediatek,larb", 0);
42 if (!node) {
43 mtk_v4l2_err("no mediatek,larb found");
44 return -ENODEV;
46 pdev = of_find_device_by_node(node);
47 of_node_put(node);
48 if (!pdev) {
49 mtk_v4l2_err("no mediatek,larb device found");
50 return -ENODEV;
52 pm->larbvenc = &pdev->dev;
54 node = of_parse_phandle(dev->of_node, "mediatek,larb", 1);
55 if (!node) {
56 mtk_v4l2_err("no mediatek,larb found");
57 return -ENODEV;
60 pdev = of_find_device_by_node(node);
61 of_node_put(node);
62 if (!pdev) {
63 mtk_v4l2_err("no mediatek,larb device found");
64 return -ENODEV;
67 pm->larbvenclt = &pdev->dev;
68 pdev = mtkdev->plat_dev;
69 pm->dev = &pdev->dev;
71 pm->vencpll_d2 = devm_clk_get(&pdev->dev, "venc_sel_src");
72 if (IS_ERR(pm->vencpll_d2)) {
73 mtk_v4l2_err("devm_clk_get vencpll_d2 fail");
74 ret = PTR_ERR(pm->vencpll_d2);
77 pm->venc_sel = devm_clk_get(&pdev->dev, "venc_sel");
78 if (IS_ERR(pm->venc_sel)) {
79 mtk_v4l2_err("devm_clk_get venc_sel fail");
80 ret = PTR_ERR(pm->venc_sel);
83 pm->univpll1_d2 = devm_clk_get(&pdev->dev, "venc_lt_sel_src");
84 if (IS_ERR(pm->univpll1_d2)) {
85 mtk_v4l2_err("devm_clk_get univpll1_d2 fail");
86 ret = PTR_ERR(pm->univpll1_d2);
89 pm->venc_lt_sel = devm_clk_get(&pdev->dev, "venc_lt_sel");
90 if (IS_ERR(pm->venc_lt_sel)) {
91 mtk_v4l2_err("devm_clk_get venc_lt_sel fail");
92 ret = PTR_ERR(pm->venc_lt_sel);
95 return ret;
98 void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *mtkdev)
103 void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
105 int ret;
107 ret = clk_prepare_enable(pm->venc_sel);
108 if (ret)
109 mtk_v4l2_err("clk_prepare_enable fail %d", ret);
111 ret = clk_set_parent(pm->venc_sel, pm->vencpll_d2);
112 if (ret)
113 mtk_v4l2_err("clk_set_parent fail %d", ret);
115 ret = clk_prepare_enable(pm->venc_lt_sel);
116 if (ret)
117 mtk_v4l2_err("clk_prepare_enable fail %d", ret);
119 ret = clk_set_parent(pm->venc_lt_sel, pm->univpll1_d2);
120 if (ret)
121 mtk_v4l2_err("clk_set_parent fail %d", ret);
123 ret = mtk_smi_larb_get(pm->larbvenc);
124 if (ret)
125 mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
127 ret = mtk_smi_larb_get(pm->larbvenclt);
128 if (ret)
129 mtk_v4l2_err("mtk_smi_larb_get larb4 fail %d", ret);
133 void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
135 mtk_smi_larb_put(pm->larbvenc);
136 mtk_smi_larb_put(pm->larbvenclt);
137 clk_disable_unprepare(pm->venc_lt_sel);
138 clk_disable_unprepare(pm->venc_sel);