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"
26 int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev
*mtkdev
)
28 struct device_node
*node
;
29 struct platform_device
*pdev
;
31 struct mtk_vcodec_pm
*pm
;
34 pdev
= mtkdev
->plat_dev
;
36 memset(pm
, 0, sizeof(struct mtk_vcodec_pm
));
41 node
= of_parse_phandle(dev
->of_node
, "mediatek,larb", 0);
43 mtk_v4l2_err("no mediatek,larb found");
46 pdev
= of_find_device_by_node(node
);
49 mtk_v4l2_err("no mediatek,larb device found");
52 pm
->larbvenc
= &pdev
->dev
;
54 node
= of_parse_phandle(dev
->of_node
, "mediatek,larb", 1);
56 mtk_v4l2_err("no mediatek,larb found");
60 pdev
= of_find_device_by_node(node
);
63 mtk_v4l2_err("no mediatek,larb device found");
67 pm
->larbvenclt
= &pdev
->dev
;
68 pdev
= mtkdev
->plat_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
);
98 void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev
*mtkdev
)
103 void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm
*pm
)
107 ret
= clk_prepare_enable(pm
->venc_sel
);
109 mtk_v4l2_err("clk_prepare_enable fail %d", ret
);
111 ret
= clk_set_parent(pm
->venc_sel
, pm
->vencpll_d2
);
113 mtk_v4l2_err("clk_set_parent fail %d", ret
);
115 ret
= clk_prepare_enable(pm
->venc_lt_sel
);
117 mtk_v4l2_err("clk_prepare_enable fail %d", ret
);
119 ret
= clk_set_parent(pm
->venc_lt_sel
, pm
->univpll1_d2
);
121 mtk_v4l2_err("clk_set_parent fail %d", ret
);
123 ret
= mtk_smi_larb_get(pm
->larbvenc
);
125 mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret
);
127 ret
= mtk_smi_larb_get(pm
->larbvenclt
);
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
);