Input: xpad - add support for Xbox1 PDP Camo series gamepad
[linux/fpc-iii.git] / drivers / media / platform / mtk-vcodec / mtk_vcodec_enc_pm.c
blob3e73e9db781f426f5682cda940c8ab0499803319
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 -1;
46 pdev = of_find_device_by_node(node);
47 if (!pdev) {
48 mtk_v4l2_err("no mediatek,larb device found");
49 return -1;
51 pm->larbvenc = &pdev->dev;
53 node = of_parse_phandle(dev->of_node, "mediatek,larb", 1);
54 if (!node) {
55 mtk_v4l2_err("no mediatek,larb found");
56 return -1;
59 pdev = of_find_device_by_node(node);
60 if (!pdev) {
61 mtk_v4l2_err("no mediatek,larb device found");
62 return -1;
65 pm->larbvenclt = &pdev->dev;
66 pdev = mtkdev->plat_dev;
67 pm->dev = &pdev->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);
93 return ret;
96 void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *mtkdev)
101 void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
103 int ret;
105 ret = clk_prepare_enable(pm->venc_sel);
106 if (ret)
107 mtk_v4l2_err("clk_prepare_enable fail %d", ret);
109 ret = clk_set_parent(pm->venc_sel, pm->vencpll_d2);
110 if (ret)
111 mtk_v4l2_err("clk_set_parent fail %d", ret);
113 ret = clk_prepare_enable(pm->venc_lt_sel);
114 if (ret)
115 mtk_v4l2_err("clk_prepare_enable fail %d", ret);
117 ret = clk_set_parent(pm->venc_lt_sel, pm->univpll1_d2);
118 if (ret)
119 mtk_v4l2_err("clk_set_parent fail %d", ret);
121 ret = mtk_smi_larb_get(pm->larbvenc);
122 if (ret)
123 mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
125 ret = mtk_smi_larb_get(pm->larbvenclt);
126 if (ret)
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);