linux/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
<<
>>
Prefs
   1/*
   2* Copyright (c) 2016 MediaTek Inc.
   3* Author: Tiffany Lin <tiffany.lin@mediatek.com>
   4*
   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.
   8*
   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.
  13*/
  14
  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>
  20
  21#include "mtk_vcodec_enc_pm.h"
  22#include "mtk_vcodec_util.h"
  23#include "mtk_vpu.h"
  24
  25
  26int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
  27{
  28        struct device_node *node;
  29        struct platform_device *pdev;
  30        struct device *dev;
  31        struct mtk_vcodec_pm *pm;
  32        int ret = 0;
  33
  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;
  40
  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;
  45        }
  46        pdev = of_find_device_by_node(node);
  47        if (!pdev) {
  48                mtk_v4l2_err("no mediatek,larb device found");
  49                return -1;
  50        }
  51        pm->larbvenc = &pdev->dev;
  52
  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;
  57        }
  58
  59        pdev = of_find_device_by_node(node);
  60        if (!pdev) {
  61                mtk_v4l2_err("no mediatek,larb device found");
  62                return -1;
  63        }
  64
  65        pm->larbvenclt = &pdev->dev;
  66        pdev = mtkdev->plat_dev;
  67        pm->dev = &pdev->dev;
  68
  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);
  73        }
  74
  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);
  79        }
  80
  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);
  85        }
  86
  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);
  91        }
  92
  93        return ret;
  94}
  95
  96void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *mtkdev)
  97{
  98}
  99
 100
 101void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
 102{
 103        int ret;
 104
 105        ret = clk_prepare_enable(pm->venc_sel);
 106        if (ret)
 107                mtk_v4l2_err("clk_prepare_enable fail %d", ret);
 108
 109        ret = clk_set_parent(pm->venc_sel, pm->vencpll_d2);
 110        if (ret)
 111                mtk_v4l2_err("clk_set_parent fail %d", ret);
 112
 113        ret = clk_prepare_enable(pm->venc_lt_sel);
 114        if (ret)
 115                mtk_v4l2_err("clk_prepare_enable fail %d", ret);
 116
 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);
 120
 121        ret = mtk_smi_larb_get(pm->larbvenc);
 122        if (ret)
 123                mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
 124
 125        ret = mtk_smi_larb_get(pm->larbvenclt);
 126        if (ret)
 127                mtk_v4l2_err("mtk_smi_larb_get larb4 fail %d", ret);
 128
 129}
 130
 131void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
 132{
 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);
 137}
 138