/*
* Copyright (c) 2016 MediaTek Inc.
* Author: PC Chen <pc.chen@mediatek.com>
* Tiffany Lin <tiffany.lin@mediatek.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <media/v4l2-event.h>
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>
#include <soc/mediatek/smi.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
#include "venc_drv_if.h"
#define MTK_VENC_MIN_W 160U
#define MTK_VENC_MIN_H 128U
#define MTK_VENC_MAX_W 1920U
#define MTK_VENC_MAX_H 1088U
#define DFT_CFG_WIDTH MTK_VENC_MIN_W
#define DFT_CFG_HEIGHT MTK_VENC_MIN_H
#define MTK_MAX_CTRLS_HINT 20
#define OUT_FMT_IDX 0
#define CAP_FMT_IDX 4
static void mtk_venc_worker(struct work_struct *work);
static struct mtk_video_fmt mtk_video_formats[] = {
{
.fourcc = V4L2_PIX_FMT_NV12M,
.type = MTK_FMT_FRAME,
.num_planes = 2,
},
{
.fourcc = V4L2_PIX_FMT_NV21M,
.type = MTK_FMT_FRAME,
.num_planes = 2,
},
{
.fourcc = V4L2_PIX_FMT_YUV420M,
.type = MTK_FMT_FRAME,
.num_planes = 3,
},
{
.fourcc = V4L2_PIX_FMT_YVU420M,
.type = MTK_FMT_FRAME,
.num_planes = 3,
},
{
.fourcc = V4L2_PIX_FMT_H264,
.type = MTK_FMT_ENC,
.num_planes = 1,
},
{
.fourcc = V4L2_PIX_FMT_VP8,
.type = MTK_FMT_ENC,
.num_planes = 1,
},
};
#define NUM_FORMATS ARRAY_SIZE(mtk_video_formats)
static const struct mtk_codec_framesizes mtk_venc_framesizes[] = {
{
.fourcc = V4L2_PIX_FMT_H264,
.stepwise = { MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16 },
},
{
.fourcc = V4L2_PIX_FMT_VP8,
.stepwise = { MTK_VENC_MIN_W, MTK_VENC_MAX_W, 16,
MTK_VENC_MIN_H, MTK_VENC_MAX_H, 16 },
},
};
#define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_venc_framesizes)
static int vidioc_venc_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct mtk_vcodec_ctx *ctx = ctrl_to_ctx(ctrl);
struct mtk_enc_params *p = &ctx->enc_params;
int ret =<