1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: Tiffany Lin <tiffany.lin@mediatek.com>
8 #include <linux/of_address.h>
9 #include <linux/of_platform.h>
10 #include <linux/pm_runtime.h>
11 #include <soc/mediatek/smi.h>
13 #include "mtk_vcodec_dec_pm.h"
14 #include "mtk_vcodec_util.h"
17 int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev
*mtkdev
)
19 struct device_node
*node
;
20 struct platform_device
*pdev
;
21 struct mtk_vcodec_pm
*pm
;
22 struct mtk_vcodec_clk
*dec_clk
;
23 struct mtk_vcodec_clk_info
*clk_info
;
26 pdev
= mtkdev
->plat_dev
;
29 dec_clk
= &pm
->vdec_clk
;
30 node
= of_parse_phandle(pdev
->dev
.of_node
, "mediatek,larb", 0);
32 mtk_v4l2_err("of_parse_phandle mediatek,larb fail!");
36 pdev
= of_find_device_by_node(node
);
41 pm
->larbvdec
= &pdev
->dev
;
42 pdev
= mtkdev
->plat_dev
;
46 of_property_count_strings(pdev
->dev
.of_node
, "clock-names");
47 if (dec_clk
->clk_num
> 0) {
48 dec_clk
->clk_info
= devm_kcalloc(&pdev
->dev
,
49 dec_clk
->clk_num
, sizeof(*clk_info
),
51 if (!dec_clk
->clk_info
)
54 mtk_v4l2_err("Failed to get vdec clock count");
58 for (i
= 0; i
< dec_clk
->clk_num
; i
++) {
59 clk_info
= &dec_clk
->clk_info
[i
];
60 ret
= of_property_read_string_index(pdev
->dev
.of_node
,
61 "clock-names", i
, &clk_info
->clk_name
);
63 mtk_v4l2_err("Failed to get clock name id = %d", i
);
66 clk_info
->vcodec_clk
= devm_clk_get(&pdev
->dev
,
68 if (IS_ERR(clk_info
->vcodec_clk
)) {
69 mtk_v4l2_err("devm_clk_get (%d)%s fail", i
,
71 return PTR_ERR(clk_info
->vcodec_clk
);
75 pm_runtime_enable(&pdev
->dev
);
80 void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev
*dev
)
82 pm_runtime_disable(dev
->pm
.dev
);
85 void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm
*pm
)
89 ret
= pm_runtime_get_sync(pm
->dev
);
91 mtk_v4l2_err("pm_runtime_get_sync fail %d", ret
);
94 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm
*pm
)
98 ret
= pm_runtime_put_sync(pm
->dev
);
100 mtk_v4l2_err("pm_runtime_put_sync fail %d", ret
);
103 void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm
*pm
)
105 struct mtk_vcodec_clk
*dec_clk
= &pm
->vdec_clk
;
108 for (i
= 0; i
< dec_clk
->clk_num
; i
++) {
109 ret
= clk_prepare_enable(dec_clk
->clk_info
[i
].vcodec_clk
);
111 mtk_v4l2_err("clk_prepare_enable %d %s fail %d", i
,
112 dec_clk
->clk_info
[i
].clk_name
, ret
);
117 ret
= mtk_smi_larb_get(pm
->larbvdec
);
119 mtk_v4l2_err("mtk_smi_larb_get larbvdec fail %d", ret
);
125 for (i
-= 1; i
>= 0; i
--)
126 clk_disable_unprepare(dec_clk
->clk_info
[i
].vcodec_clk
);
129 void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm
*pm
)
131 struct mtk_vcodec_clk
*dec_clk
= &pm
->vdec_clk
;
134 mtk_smi_larb_put(pm
->larbvdec
);
135 for (i
= dec_clk
->clk_num
- 1; i
>= 0; i
--)
136 clk_disable_unprepare(dec_clk
->clk_info
[i
].vcodec_clk
);