root/drivers/media/platform/mtk-vcodec/vdec_drv_if.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. vdec_if_init
  2. vdec_if_decode
  3. vdec_if_get_param
  4. vdec_if_deinit

   1 // SPDX-License-Identifier: GPL-2.0
   2 /*
   3  * Copyright (c) 2016 MediaTek Inc.
   4  * Author: PC Chen <pc.chen@mediatek.com>
   5  *         Tiffany Lin <tiffany.lin@mediatek.com>
   6  */
   7 
   8 #include <linux/interrupt.h>
   9 #include <linux/kernel.h>
  10 #include <linux/slab.h>
  11 
  12 #include "vdec_drv_if.h"
  13 #include "mtk_vcodec_dec.h"
  14 #include "vdec_drv_base.h"
  15 #include "mtk_vcodec_dec_pm.h"
  16 #include "mtk_vpu.h"
  17 
  18 int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
  19 {
  20         int ret = 0;
  21 
  22         switch (fourcc) {
  23         case V4L2_PIX_FMT_H264:
  24                 ctx->dec_if = &vdec_h264_if;
  25                 break;
  26         case V4L2_PIX_FMT_VP8:
  27                 ctx->dec_if = &vdec_vp8_if;
  28                 break;
  29         case V4L2_PIX_FMT_VP9:
  30                 ctx->dec_if = &vdec_vp9_if;
  31                 break;
  32         default:
  33                 return -EINVAL;
  34         }
  35 
  36         mtk_vdec_lock(ctx);
  37         mtk_vcodec_dec_clock_on(&ctx->dev->pm);
  38         ret = ctx->dec_if->init(ctx);
  39         mtk_vcodec_dec_clock_off(&ctx->dev->pm);
  40         mtk_vdec_unlock(ctx);
  41 
  42         return ret;
  43 }
  44 
  45 int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
  46                    struct vdec_fb *fb, bool *res_chg)
  47 {
  48         int ret = 0;
  49 
  50         if (bs) {
  51                 if ((bs->dma_addr & 63) != 0) {
  52                         mtk_v4l2_err("bs dma_addr should 64 byte align");
  53                         return -EINVAL;
  54                 }
  55         }
  56 
  57         if (fb) {
  58                 if (((fb->base_y.dma_addr & 511) != 0) ||
  59                     ((fb->base_c.dma_addr & 511) != 0)) {
  60                         mtk_v4l2_err("frame buffer dma_addr should 512 byte align");
  61                         return -EINVAL;
  62                 }
  63         }
  64 
  65         if (!ctx->drv_handle)
  66                 return -EIO;
  67 
  68         mtk_vdec_lock(ctx);
  69 
  70         mtk_vcodec_set_curr_ctx(ctx->dev, ctx);
  71         mtk_vcodec_dec_clock_on(&ctx->dev->pm);
  72         enable_irq(ctx->dev->dec_irq);
  73         ret = ctx->dec_if->decode(ctx->drv_handle, bs, fb, res_chg);
  74         disable_irq(ctx->dev->dec_irq);
  75         mtk_vcodec_dec_clock_off(&ctx->dev->pm);
  76         mtk_vcodec_set_curr_ctx(ctx->dev, NULL);
  77 
  78         mtk_vdec_unlock(ctx);
  79 
  80         return ret;
  81 }
  82 
  83 int vdec_if_get_param(struct mtk_vcodec_ctx *ctx, enum vdec_get_param_type type,
  84                       void *out)
  85 {
  86         int ret = 0;
  87 
  88         if (!ctx->drv_handle)
  89                 return -EIO;
  90 
  91         mtk_vdec_lock(ctx);
  92         ret = ctx->dec_if->get_param(ctx->drv_handle, type, out);
  93         mtk_vdec_unlock(ctx);
  94 
  95         return ret;
  96 }
  97 
  98 void vdec_if_deinit(struct mtk_vcodec_ctx *ctx)
  99 {
 100         if (!ctx->drv_handle)
 101                 return;
 102 
 103         mtk_vdec_lock(ctx);
 104         mtk_vcodec_dec_clock_on(&ctx->dev->pm);
 105         ctx->dec_if->deinit(ctx->drv_handle);
 106         mtk_vcodec_dec_clock_off(&ctx->dev->pm);
 107         mtk_vdec_unlock(ctx);
 108 
 109         ctx->drv_handle = NULL;
 110 }

/* [<][>][^][v][top][bottom][index][help] */