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
);
48 mtk_v4l2_err("no mediatek,larb device found");
51 pm
->larbvenc
= &pdev
->dev
;
53 node
= of_parse_phandle(dev
->of_node
, "mediatek,larb", 1);
55 mtk_v4l2_err("no mediatek,larb found");
59 pdev
= of_find_device_by_node(node
);
61 mtk_v4l2_err("no mediatek,larb device found");
65 pm
->larbvenclt
= &pdev
->dev
;
66 pdev
= mtkdev
->plat_dev
;
69 pm
->vencpll_d2
= devm_clk_get(&pdev
->dev
, "venc_sel_src");
70 if (IS_ERR(pm
->vencpll_d2
)) {
71 mtk_v4l2_err("devm_clk_get vencpll_d2 fail");
72 ret
= PTR_ERR(pm
->vencpll_d2
);
75 pm
->venc_sel
= devm_clk_get(&pdev
->dev
, "venc_sel");
76 if (IS_ERR(pm
->venc_sel
)) {
77 mtk_v4l2_err("devm_clk_get venc_sel fail");
78 ret
= PTR_ERR(pm
->venc_sel
);
81 pm
->univpll1_d2
= devm_clk_get(&pdev
->dev
, "venc_lt_sel_src");
82 if (IS_ERR(pm
->univpll1_d2
)) {
83 mtk_v4l2_err("devm_clk_get univpll1_d2 fail");
84 ret
= PTR_ERR(pm
->univpll1_d2
);
87 pm
->venc_lt_sel
= devm_clk_get(&pdev
->dev
, "venc_lt_sel");
88 if (IS_ERR(pm
->venc_lt_sel
)) {
89 mtk_v4l2_err("devm_clk_get venc_lt_sel fail");
90 ret
= PTR_ERR(pm
->venc_lt_sel
);
96 void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev
*mtkdev
)
101 void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm
*pm
)
105 ret
= clk_prepare_enable(pm
->venc_sel
);
107 mtk_v4l2_err("clk_prepare_enable fail %d", ret
);
109 ret
= clk_set_parent(pm
->venc_sel
, pm
->vencpll_d2
);
111 mtk_v4l2_err("clk_set_parent fail %d", ret
);
113 ret
= clk_prepare_enable(pm
->venc_lt_sel
);
115 mtk_v4l2_err("clk_prepare_enable fail %d", ret
);
117 ret
= clk_set_parent(pm
->venc_lt_sel
, pm
->univpll1_d2
);
119 mtk_v4l2_err("clk_set_parent fail %d", ret
);
121 ret
= mtk_smi_larb_get(pm
->larbvenc
);
123 mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret
);
125 ret
= mtk_smi_larb_get(pm
->larbvenclt
);
127 mtk_v4l2_err("mtk_smi_larb_get larb4 fail %d", ret
);
131 void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm
*pm
)
133 mtk_smi_larb_put(pm
->larbvenc
);
134 mtk_smi_larb_put(pm
->larbvenclt
);
135 clk_disable_unprepare(pm
->venc_lt_sel
);
136 clk_disable_unprepare(pm
->venc_sel
);