Commit 31272a39 authored by Yunfei Dong's avatar Yunfei Dong Committed by Mauro Carvalho Chehab

media: mediatek: vcodec: separate struct mtk_vcodec_dev

Adding different dev struct for encoder and decoder, remove
'struct mtk_vcodec_dev'.
Signed-off-by: default avatarYunfei Dong <yunfei.dong@mediatek.com>
Reviewed-by: default avatarNicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
parent 01abf5fb
......@@ -17,6 +17,77 @@
#define MTK_VCODEC_MAX_PLANES 3
#define WAIT_INTR_TIMEOUT_MS 1000
/*
* enum mtk_q_type - Type of queue
*/
enum mtk_q_type {
MTK_Q_DATA_SRC = 0,
MTK_Q_DATA_DST = 1,
};
/*
* enum mtk_hw_reg_idx - MTK hw register base index
*/
enum mtk_hw_reg_idx {
VDEC_SYS,
VDEC_MISC,
VDEC_LD,
VDEC_TOP,
VDEC_CM,
VDEC_AD,
VDEC_AV,
VDEC_PP,
VDEC_HWD,
VDEC_HWQ,
VDEC_HWB,
VDEC_HWG,
NUM_MAX_VDEC_REG_BASE,
/* h264 encoder */
VENC_SYS = NUM_MAX_VDEC_REG_BASE,
/* vp8 encoder */
VENC_LT_SYS,
NUM_MAX_VCODEC_REG_BASE
};
/*
* struct mtk_vcodec_clk_info - Structure used to store clock name
*/
struct mtk_vcodec_clk_info {
const char *clk_name;
struct clk *vcodec_clk;
};
/*
* struct mtk_vcodec_clk - Structure used to store vcodec clock information
*/
struct mtk_vcodec_clk {
struct mtk_vcodec_clk_info *clk_info;
int clk_num;
};
/*
* struct mtk_vcodec_pm - Power management data structure
*/
struct mtk_vcodec_pm {
struct mtk_vcodec_clk vdec_clk;
struct mtk_vcodec_clk venc_clk;
struct device *dev;
};
/*
* enum mtk_vdec_hw_id - Hardware index used to separate
* different hardware
*/
enum mtk_vdec_hw_id {
MTK_VDEC_CORE,
MTK_VDEC_LAT0,
MTK_VDEC_LAT1,
MTK_VDEC_LAT_SOC,
MTK_VDEC_HW_MAX,
};
/**
* enum mtk_instance_state - The state of an MTK Vcodec instance.
* @MTK_STATE_FREE: default state when instance is created
......
......@@ -7,7 +7,8 @@
#include <linux/debugfs.h>
#include "mtk_vcodec_dbgfs.h"
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_util.h"
static void mtk_vdec_dbgfs_get_format_type(struct mtk_vcodec_dec_ctx *ctx, char *buf,
......@@ -72,7 +73,7 @@ static void mtk_vdec_dbgfs_get_help(char *buf, int *used, int total)
static ssize_t mtk_vdec_dbgfs_write(struct file *filp, const char __user *ubuf,
size_t count, loff_t *ppos)
{
struct mtk_vcodec_dev *vcodec_dev = filp->private_data;
struct mtk_vcodec_dec_dev *vcodec_dev = filp->private_data;
struct mtk_vcodec_dbgfs *dbgfs = &vcodec_dev->dbgfs;
mutex_lock(&dbgfs->dbgfs_lock);
......@@ -88,7 +89,7 @@ static ssize_t mtk_vdec_dbgfs_write(struct file *filp, const char __user *ubuf,
static ssize_t mtk_vdec_dbgfs_read(struct file *filp, char __user *ubuf,
size_t count, loff_t *ppos)
{
struct mtk_vcodec_dev *vcodec_dev = filp->private_data;
struct mtk_vcodec_dec_dev *vcodec_dev = filp->private_data;
struct mtk_vcodec_dbgfs *dbgfs = &vcodec_dev->dbgfs;
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
struct mtk_vcodec_dec_ctx *ctx;
......@@ -146,7 +147,7 @@ static const struct file_operations vdec_fops = {
void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx)
{
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
struct mtk_vcodec_dev *vcodec_dev = ctx->dev;
struct mtk_vcodec_dec_dev *vcodec_dev = ctx->dev;
dbgfs_inst = kzalloc(sizeof(*dbgfs_inst), GFP_KERNEL);
if (!dbgfs_inst)
......@@ -161,7 +162,7 @@ void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx)
}
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_create);
void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dec_dev *vcodec_dev, int ctx_id)
{
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
......@@ -176,14 +177,11 @@ void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
}
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_remove);
void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode)
static void mtk_vcodec_dbgfs_vdec_init(struct mtk_vcodec_dec_dev *vcodec_dev)
{
struct dentry *vcodec_root;
if (is_encode)
vcodec_dev->dbgfs.vcodec_root = debugfs_create_dir("vcodec-enc", NULL);
else
vcodec_dev->dbgfs.vcodec_root = debugfs_create_dir("vcodec-dec", NULL);
vcodec_dev->dbgfs.vcodec_root = debugfs_create_dir("vcodec-dec", NULL);
if (IS_ERR(vcodec_dev->dbgfs.vcodec_root))
dev_err(&vcodec_dev->plat_dev->dev, "create vcodec dir err:%ld\n",
PTR_ERR(vcodec_dev->dbgfs.vcodec_root));
......@@ -193,18 +191,39 @@ void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode)
debugfs_create_x32("mtk_vcodec_dbg", 0644, vcodec_root, &mtk_vcodec_dbg);
vcodec_dev->dbgfs.inst_count = 0;
if (is_encode)
return;
INIT_LIST_HEAD(&vcodec_dev->dbgfs.dbgfs_head);
debugfs_create_file("vdec", 0200, vcodec_root, vcodec_dev, &vdec_fops);
mutex_init(&vcodec_dev->dbgfs.dbgfs_lock);
}
static void mtk_vcodec_dbgfs_venc_init(struct mtk_vcodec_enc_dev *vcodec_dev)
{
struct dentry *vcodec_root;
vcodec_dev->dbgfs.vcodec_root = debugfs_create_dir("vcodec-enc", NULL);
if (IS_ERR(vcodec_dev->dbgfs.vcodec_root))
dev_err(&vcodec_dev->plat_dev->dev, "create venc dir err:%d\n",
IS_ERR(vcodec_dev->dbgfs.vcodec_root));
vcodec_root = vcodec_dev->dbgfs.vcodec_root;
debugfs_create_x32("mtk_v4l2_dbg_level", 0644, vcodec_root, &mtk_v4l2_dbg_level);
debugfs_create_x32("mtk_vcodec_dbg", 0644, vcodec_root, &mtk_vcodec_dbg);
vcodec_dev->dbgfs.inst_count = 0;
}
void mtk_vcodec_dbgfs_init(void *vcodec_dev, bool is_encode)
{
if (is_encode)
mtk_vcodec_dbgfs_venc_init(vcodec_dev);
else
mtk_vcodec_dbgfs_vdec_init(vcodec_dev);
}
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_init);
void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev)
void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dbgfs *dbgfs)
{
debugfs_remove_recursive(vcodec_dev->dbgfs.vcodec_root);
debugfs_remove_recursive(dbgfs->vcodec_root);
}
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_deinit);
......
......@@ -7,7 +7,7 @@
#ifndef __MTK_VCODEC_DBGFS_H__
#define __MTK_VCODEC_DBGFS_H__
struct mtk_vcodec_dev;
struct mtk_vcodec_dec_dev;
struct mtk_vcodec_dec_ctx;
/*
......@@ -51,23 +51,23 @@ struct mtk_vcodec_dbgfs {
#if defined(CONFIG_DEBUG_FS)
void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx);
void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id);
void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode);
void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev);
void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dec_dev *vcodec_dev, int ctx_id);
void mtk_vcodec_dbgfs_init(void *vcodec_dev, bool is_encode);
void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dbgfs *dbgfs);
#else
static inline void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx)
{
}
static inline void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
static inline void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dec_dev *vcodec_dev, int ctx_id)
{
}
static inline void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode)
static inline void mtk_vcodec_dbgfs_init(void *vcodec_dev, bool is_encode)
{
}
static inline void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev)
static inline void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dbgfs *dbgfs)
{
}
#endif
......
......@@ -9,7 +9,7 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
......@@ -890,7 +890,7 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q)
static void m2mops_vdec_device_run(void *priv)
{
struct mtk_vcodec_dec_ctx *ctx = priv;
struct mtk_vcodec_dev *dev = ctx->dev;
struct mtk_vcodec_dec_dev *dev = ctx->dev;
queue_work(dev->decode_workqueue, &ctx->decode_work);
}
......
......@@ -21,7 +21,6 @@
#include <media/videobuf2-dma-contig.h>
#include <media/v4l2-device.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_dec_hw.h"
#include "mtk_vcodec_dec_pm.h"
......@@ -29,7 +28,7 @@
#include "mtk_vcodec_util.h"
#include "mtk_vcodec_fw.h"
static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_dev *dev)
static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_dec_dev *dev)
{
switch (dev->vdec_pdata->hw_arch) {
case MTK_VDEC_PURE_SINGLE_CORE:
......@@ -42,7 +41,7 @@ static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vc
}
}
static bool mtk_vcodec_is_hw_active(struct mtk_vcodec_dev *dev)
static bool mtk_vcodec_is_hw_active(struct mtk_vcodec_dec_dev *dev)
{
u32 cg_status;
......@@ -56,7 +55,7 @@ static bool mtk_vcodec_is_hw_active(struct mtk_vcodec_dev *dev)
static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
{
struct mtk_vcodec_dev *dev = priv;
struct mtk_vcodec_dec_dev *dev = priv;
struct mtk_vcodec_dec_ctx *ctx;
unsigned int dec_done_status = 0;
void __iomem *vdec_misc_addr = dev->reg_base[VDEC_MISC] +
......@@ -88,7 +87,7 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
return IRQ_HANDLED;
}
static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev)
static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dec_dev *dev)
{
struct platform_device *pdev = dev->plat_dev;
int reg_num, i;
......@@ -160,7 +159,7 @@ static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev)
return 0;
}
static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dev *dev)
static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dec_dev *dev)
{
struct platform_device *pdev = dev->plat_dev;
int ret;
......@@ -197,7 +196,7 @@ static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dev *dev)
static int fops_vcodec_open(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
struct mtk_vcodec_dec_dev *dev = video_drvdata(file);
struct mtk_vcodec_dec_ctx *ctx = NULL;
int ret = 0, i, hw_count;
struct vb2_queue *src_vq;
......@@ -294,7 +293,7 @@ static int fops_vcodec_open(struct file *file)
static int fops_vcodec_release(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
struct mtk_vcodec_dec_dev *dev = video_drvdata(file);
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(file->private_data);
mtk_v4l2_vdec_dbg(0, ctx, "[%d] decoder", ctx->id);
......@@ -331,7 +330,7 @@ static const struct v4l2_file_operations mtk_vcodec_fops = {
static int mtk_vcodec_probe(struct platform_device *pdev)
{
struct mtk_vcodec_dev *dev;
struct mtk_vcodec_dec_dev *dev;
struct video_device *vfd_dec;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
......@@ -538,7 +537,7 @@ MODULE_DEVICE_TABLE(of, mtk_vcodec_match);
static void mtk_vcodec_dec_remove(struct platform_device *pdev)
{
struct mtk_vcodec_dev *dev = platform_get_drvdata(pdev);
struct mtk_vcodec_dec_dev *dev = platform_get_drvdata(pdev);
destroy_workqueue(dev->decode_workqueue);
......@@ -554,7 +553,7 @@ static void mtk_vcodec_dec_remove(struct platform_device *pdev)
if (dev->vfd_dec)
video_unregister_device(dev->vfd_dec);
mtk_vcodec_dbgfs_deinit(dev);
mtk_vcodec_dbgfs_deinit(&dev->dbgfs);
v4l2_device_unregister(&dev->v4l2_dev);
if (!dev->vdec_pdata->is_subdev_supported)
pm_runtime_disable(dev->pm.dev);
......
......@@ -8,9 +8,49 @@
#define _MTK_VCODEC_DEC_DRV_H_
#include "mtk_vcodec_cmn_drv.h"
#include "mtk_vcodec_dbgfs.h"
#include "mtk_vcodec_fw_priv.h"
#include "mtk_vcodec_util.h"
#include "vdec_msg_queue.h"
#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
#define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE)
#define IS_VDEC_INNER_RACING(capability) ((capability) & MTK_VCODEC_INNER_RACING)
/*
* struct mtk_vdec_format_types - Structure used to get supported
* format types according to decoder capability
*/
enum mtk_vdec_format_types {
MTK_VDEC_FORMAT_MM21 = 0x20,
MTK_VDEC_FORMAT_MT21C = 0x40,
MTK_VDEC_FORMAT_H264_SLICE = 0x100,
MTK_VDEC_FORMAT_VP8_FRAME = 0x200,
MTK_VDEC_FORMAT_VP9_FRAME = 0x400,
MTK_VDEC_FORMAT_AV1_FRAME = 0x800,
MTK_VDEC_FORMAT_HEVC_FRAME = 0x1000,
MTK_VCODEC_INNER_RACING = 0x20000,
};
/*
* enum mtk_vdec_hw_count - Supported hardware count
*/
enum mtk_vdec_hw_count {
MTK_VDEC_NO_HW = 0,
MTK_VDEC_ONE_CORE,
MTK_VDEC_ONE_LAT_ONE_CORE,
MTK_VDEC_MAX_HW_COUNT,
};
/*
* enum mtk_vdec_hw_arch - Used to separate different hardware architecture
*/
enum mtk_vdec_hw_arch {
MTK_VDEC_PURE_SINGLE_CORE,
MTK_VDEC_LAT_SINGLE_CORE,
};
/**
* struct vdec_pic_info - picture size information
* @pic_w: picture width
......@@ -33,24 +73,54 @@ struct vdec_pic_info {
unsigned int reserved;
};
/*
* enum mtk_vdec_hw_id - Hardware index used to separate
* different hardware
/**
* struct mtk_vcodec_dec_pdata - compatible data for each IC
* @init_vdec_params: init vdec params
* @ctrls_setup: init vcodec dec ctrls
* @worker: worker to start a decode job
* @flush_decoder: function that flushes the decoder
* @get_cap_buffer: get capture buffer from capture queue
* @cap_to_disp: put capture buffer to disp list for lat and core arch
* @vdec_vb2_ops: struct vb2_ops
*
* @vdec_formats: supported video decoder formats
* @num_formats: count of video decoder formats
* @default_out_fmt: default output buffer format
* @default_cap_fmt: default capture buffer format
*
* @hw_arch: hardware arch is used to separate pure_sin_core and lat_sin_core
*
* @is_subdev_supported: whether support parent-node architecture(subdev)
* @uses_stateless_api: whether the decoder uses the stateless API with requests
*/
enum mtk_vdec_hw_id {
MTK_VDEC_CORE,
MTK_VDEC_LAT0,
MTK_VDEC_LAT1,
MTK_VDEC_LAT_SOC,
MTK_VDEC_HW_MAX,
struct mtk_vcodec_dec_pdata {
void (*init_vdec_params)(struct mtk_vcodec_dec_ctx *ctx);
int (*ctrls_setup)(struct mtk_vcodec_dec_ctx *ctx);
void (*worker)(struct work_struct *work);
int (*flush_decoder)(struct mtk_vcodec_dec_ctx *ctx);
struct vdec_fb *(*get_cap_buffer)(struct mtk_vcodec_dec_ctx *ctx);
void (*cap_to_disp)(struct mtk_vcodec_dec_ctx *ctx, int error,
struct media_request *src_buf_req);
const struct vb2_ops *vdec_vb2_ops;
const struct mtk_video_fmt *vdec_formats;
const int *num_formats;
const struct mtk_video_fmt *default_out_fmt;
const struct mtk_video_fmt *default_cap_fmt;
enum mtk_vdec_hw_arch hw_arch;
bool is_subdev_supported;
bool uses_stateless_api;
};
/**
* struct mtk_vcodec_dec_ctx - Context (instance) private data.
*
* @type: type of decoder instance
* @dev: pointer to the mtk_vcodec_dev of the device
* @list: link to ctx_list of mtk_vcodec_dev
* @dev: pointer to the mtk_vcodec_dec_dev of the device
* @list: link to ctx_list of mtk_vcodec_dec_dev
*
* @fh: struct v4l2_fh
* @m2m_ctx: pointer to the v4l2_m2m_ctx of the context
......@@ -93,7 +163,7 @@ enum mtk_vdec_hw_id {
*/
struct mtk_vcodec_dec_ctx {
enum mtk_instance_type type;
struct mtk_vcodec_dev *dev;
struct mtk_vcodec_dec_dev *dev;
struct list_head list;
struct v4l2_fh fh;
......@@ -134,6 +204,86 @@ struct mtk_vcodec_dec_ctx {
struct vdec_msg_queue msg_queue;
};
/**
* struct mtk_vcodec_dec_dev - driver data
* @v4l2_dev: V4L2 device to register video devices for.
* @vfd_dec: Video device for decoder
* @mdev_dec: Media device for decoder
*
* @m2m_dev_dec: m2m device for decoder
* @plat_dev: platform device
* @ctx_list: list of struct mtk_vcodec_ctx
* @curr_ctx: The context that is waiting for codec hardware
*
* @reg_base: Mapped address of MTK Vcodec registers.
* @vdec_pdata: decoder IC-specific data
* @vdecsys_regmap: VDEC_SYS register space passed through syscon
*
* @fw_handler: used to communicate with the firmware.
* @id_counter: used to identify current opened instance
*
* @dec_mutex: decoder hardware lock
* @dev_mutex: video_device lock
* @decode_workqueue: decode work queue
*
* @irqlock: protect data access by irq handler and work thread
* @dec_irq: decoder irq resource
*
* @pm: power management control
* @dec_capability: used to identify decode capability, ex: 4k
*
* @core_workqueue: queue used for core hardware decode
*
* @subdev_dev: subdev hardware device
* @subdev_prob_done: check whether all used hw device is prob done
* @subdev_bitmap: used to record hardware is ready or not
*
* @dec_active_cnt: used to mark whether need to record register value
* @vdec_racing_info: record register value
* @dec_racing_info_mutex: mutex lock used for inner racing mode
* @dbgfs: debug log related information
*/
struct mtk_vcodec_dec_dev {
struct v4l2_device v4l2_dev;
struct video_device *vfd_dec;
struct media_device mdev_dec;
struct v4l2_m2m_dev *m2m_dev_dec;
struct platform_device *plat_dev;
struct list_head ctx_list;
struct mtk_vcodec_dec_ctx *curr_ctx;
void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
const struct mtk_vcodec_dec_pdata *vdec_pdata;
struct regmap *vdecsys_regmap;
struct mtk_vcodec_fw *fw_handler;
unsigned long id_counter;
/* decoder hardware mutex lock */
struct mutex dec_mutex[MTK_VDEC_HW_MAX];
struct mutex dev_mutex;
struct workqueue_struct *decode_workqueue;
spinlock_t irqlock;
int dec_irq;
struct mtk_vcodec_pm pm;
unsigned int dec_capability;
struct workqueue_struct *core_workqueue;
void *subdev_dev[MTK_VDEC_HW_MAX];
int (*subdev_prob_done)(struct mtk_vcodec_dec_dev *vdec_dev);
DECLARE_BITMAP(subdev_bitmap, MTK_VDEC_HW_MAX);
atomic_t dec_active_cnt;
u32 vdec_racing_info[132];
/* Protects access to vdec_racing_info data */
struct mutex dec_racing_info_mutex;
struct mtk_vcodec_dbgfs dbgfs;
};
static inline struct mtk_vcodec_dec_ctx *fh_to_dec_ctx(struct v4l2_fh *fh)
{
return container_of(fh, struct mtk_vcodec_dec_ctx, fh);
......
......@@ -12,7 +12,6 @@
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_dec_hw.h"
#include "mtk_vcodec_dec_pm.h"
......@@ -36,7 +35,7 @@ static const struct of_device_id mtk_vdec_hw_match[] = {
};
MODULE_DEVICE_TABLE(of, mtk_vdec_hw_match);
static int mtk_vdec_hw_prob_done(struct mtk_vcodec_dev *vdec_dev)
static int mtk_vdec_hw_prob_done(struct mtk_vcodec_dec_dev *vdec_dev)
{
struct platform_device *pdev = vdec_dev->plat_dev;
struct device_node *subdev_node;
......@@ -123,7 +122,7 @@ static int mtk_vdec_hw_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct mtk_vdec_hw_dev *subdev_dev;
struct mtk_vcodec_dev *main_dev;
struct mtk_vcodec_dec_dev *main_dev;
const struct of_device_id *of_id;
int hw_idx;
int ret;
......
......@@ -10,7 +10,7 @@
#include <linux/io.h>
#include <linux/platform_device.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec_drv.h"
#define VDEC_HW_ACTIVE_ADDR 0x0
#define VDEC_HW_ACTIVE_MASK BIT(4)
......@@ -46,7 +46,7 @@ enum mtk_vdec_hw_reg_idx {
*/
struct mtk_vdec_hw_dev {
struct platform_device *plat_dev;
struct mtk_vcodec_dev *main_dev;
struct mtk_vcodec_dec_dev *main_dev;
void __iomem *reg_base[VDEC_HW_MAX];
struct mtk_vcodec_dec_ctx *curr_ctx;
......
......@@ -106,7 +106,7 @@ static void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm)
clk_disable_unprepare(dec_clk->clk_info[i].vcodec_clk);
}
static void mtk_vcodec_dec_enable_irq(struct mtk_vcodec_dev *vdec_dev, int hw_idx)
static void mtk_vcodec_dec_enable_irq(struct mtk_vcodec_dec_dev *vdec_dev, int hw_idx)
{
struct mtk_vdec_hw_dev *subdev_dev;
......@@ -124,7 +124,7 @@ static void mtk_vcodec_dec_enable_irq(struct mtk_vcodec_dev *vdec_dev, int hw_id
}
}
static void mtk_vcodec_dec_disable_irq(struct mtk_vcodec_dev *vdec_dev, int hw_idx)
static void mtk_vcodec_dec_disable_irq(struct mtk_vcodec_dec_dev *vdec_dev, int hw_idx)
{
struct mtk_vdec_hw_dev *subdev_dev;
......@@ -170,7 +170,7 @@ static void mtk_vcodec_record_racing_info(struct mtk_vcodec_dec_ctx *ctx)
mutex_unlock(&ctx->dev->dec_racing_info_mutex);
}
static struct mtk_vcodec_pm *mtk_vcodec_dec_get_pm(struct mtk_vcodec_dev *vdec_dev,
static struct mtk_vcodec_pm *mtk_vcodec_dec_get_pm(struct mtk_vcodec_dec_dev *vdec_dev,
int hw_idx)
{
struct mtk_vdec_hw_dev *subdev_dev;
......@@ -190,7 +190,7 @@ static struct mtk_vcodec_pm *mtk_vcodec_dec_get_pm(struct mtk_vcodec_dev *vdec_d
return &vdec_dev->pm;
}
static void mtk_vcodec_dec_child_dev_on(struct mtk_vcodec_dev *vdec_dev,
static void mtk_vcodec_dec_child_dev_on(struct mtk_vcodec_dec_dev *vdec_dev,
int hw_idx)
{
struct mtk_vcodec_pm *pm;
......@@ -210,7 +210,7 @@ static void mtk_vcodec_dec_child_dev_on(struct mtk_vcodec_dev *vdec_dev,
}
}
static void mtk_vcodec_dec_child_dev_off(struct mtk_vcodec_dev *vdec_dev,
static void mtk_vcodec_dec_child_dev_off(struct mtk_vcodec_dec_dev *vdec_dev,
int hw_idx)
{
struct mtk_vcodec_pm *pm;
......
......@@ -7,7 +7,7 @@
#ifndef _MTK_VCODEC_DEC_PM_H_
#define _MTK_VCODEC_DEC_PM_H_
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec_drv.h"
int mtk_vcodec_init_dec_clk(struct platform_device *pdev, struct mtk_vcodec_pm *pm);
......
......@@ -4,7 +4,6 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
......@@ -279,7 +278,7 @@ static void mtk_vdec_worker(struct work_struct *work)
{
struct mtk_vcodec_dec_ctx *ctx =
container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
struct mtk_vcodec_dev *dev = ctx->dev;
struct mtk_vcodec_dec_dev *dev = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct mtk_vcodec_mem buf;
struct vdec_fb *pfb;
......
......@@ -6,7 +6,6 @@
#include <media/v4l2-mem2mem.h>
#include <linux/module.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
......@@ -288,7 +287,7 @@ static void mtk_vdec_worker(struct work_struct *work)
{
struct mtk_vcodec_dec_ctx *ctx =
container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
struct mtk_vcodec_dev *dev = ctx->dev;
struct mtk_vcodec_dec_dev *dev = ctx->dev;
struct vb2_v4l2_buffer *vb2_v4l2_src;
struct vb2_buffer *vb2_src;
struct mtk_vcodec_mem *bs_src;
......@@ -444,7 +443,7 @@ const struct media_device_ops mtk_vcodec_media_ops = {
static void mtk_vcodec_add_formats(unsigned int fourcc,
struct mtk_vcodec_dec_ctx *ctx)
{
struct mtk_vcodec_dev *dev = ctx->dev;
struct mtk_vcodec_dec_dev *dev = ctx->dev;
const struct mtk_vcodec_dec_pdata *pdata = dev->vdec_pdata;
int count_formats = *pdata->num_formats;
......
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2016 MediaTek Inc.
* Author: PC Chen <pc.chen@mediatek.com>
* Tiffany Lin <tiffany.lin@mediatek.com>
*/
#ifndef _MTK_VCODEC_DRV_H_
#define _MTK_VCODEC_DRV_H_
#include <linux/platform_device.h>
#include <linux/videodev2.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-core.h>
#include "mtk_vcodec_dbgfs.h"
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_util.h"
#include "vdec_msg_queue.h"
#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
#define MTK_V4L2_BENCHMARK 0
#define WAIT_INTR_TIMEOUT_MS 1000
#define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE)
#define IS_VDEC_INNER_RACING(capability) ((capability) & MTK_VCODEC_INNER_RACING)
/*
* enum mtk_hw_reg_idx - MTK hw register base index
*/
enum mtk_hw_reg_idx {
VDEC_SYS,
VDEC_MISC,
VDEC_LD,
VDEC_TOP,
VDEC_CM,
VDEC_AD,
VDEC_AV,
VDEC_PP,
VDEC_HWD,
VDEC_HWQ,
VDEC_HWB,
VDEC_HWG,
NUM_MAX_VDEC_REG_BASE,
/* h264 encoder */
VENC_SYS = NUM_MAX_VDEC_REG_BASE,
/* vp8 encoder */
VENC_LT_SYS,
NUM_MAX_VCODEC_REG_BASE
};
/*
* enum mtk_vdec_hw_count - Supported hardware count
*/
enum mtk_vdec_hw_count {
MTK_VDEC_NO_HW = 0,
MTK_VDEC_ONE_CORE,
MTK_VDEC_ONE_LAT_ONE_CORE,
MTK_VDEC_MAX_HW_COUNT,
};
/*
* enum mtk_q_type - Type of queue
*/
enum mtk_q_type {
MTK_Q_DATA_SRC = 0,
MTK_Q_DATA_DST = 1,
};
/*
* struct mtk_vcodec_clk_info - Structure used to store clock name
*/
struct mtk_vcodec_clk_info {
const char *clk_name;
struct clk *vcodec_clk;
};
/*
* struct mtk_vcodec_clk - Structure used to store vcodec clock information
*/
struct mtk_vcodec_clk {
struct mtk_vcodec_clk_info *clk_info;
int clk_num;
};
/*
* struct mtk_vcodec_pm - Power management data structure
*/
struct mtk_vcodec_pm {
struct mtk_vcodec_clk vdec_clk;
struct mtk_vcodec_clk venc_clk;
struct device *dev;
};
/*
* enum mtk_vdec_hw_arch - Used to separate different hardware architecture
*/
enum mtk_vdec_hw_arch {
MTK_VDEC_PURE_SINGLE_CORE,
MTK_VDEC_LAT_SINGLE_CORE,
};
/*
* struct mtk_vdec_format_types - Structure used to get supported
* format types according to decoder capability
*/
enum mtk_vdec_format_types {
MTK_VDEC_FORMAT_MM21 = 0x20,
MTK_VDEC_FORMAT_MT21C = 0x40,
MTK_VDEC_FORMAT_H264_SLICE = 0x100,
MTK_VDEC_FORMAT_VP8_FRAME = 0x200,
MTK_VDEC_FORMAT_VP9_FRAME = 0x400,
MTK_VDEC_FORMAT_AV1_FRAME = 0x800,
MTK_VDEC_FORMAT_HEVC_FRAME = 0x1000,
MTK_VCODEC_INNER_RACING = 0x20000,
};
/**
* struct mtk_vcodec_dec_pdata - compatible data for each IC
* @init_vdec_params: init vdec params
* @ctrls_setup: init vcodec dec ctrls
* @worker: worker to start a decode job
* @flush_decoder: function that flushes the decoder
* @get_cap_buffer: get capture buffer from capture queue
* @cap_to_disp: put capture buffer to disp list for lat and core arch
* @vdec_vb2_ops: struct vb2_ops
*
* @vdec_formats: supported video decoder formats
* @num_formats: count of video decoder formats
* @default_out_fmt: default output buffer format
* @default_cap_fmt: default capture buffer format
*
* @hw_arch: hardware arch is used to separate pure_sin_core and lat_sin_core
*
* @is_subdev_supported: whether support parent-node architecture(subdev)
* @uses_stateless_api: whether the decoder uses the stateless API with requests
*/
struct mtk_vcodec_dec_pdata {
void (*init_vdec_params)(struct mtk_vcodec_dec_ctx *ctx);
int (*ctrls_setup)(struct mtk_vcodec_dec_ctx *ctx);
void (*worker)(struct work_struct *work);
int (*flush_decoder)(struct mtk_vcodec_dec_ctx *ctx);
struct vdec_fb *(*get_cap_buffer)(struct mtk_vcodec_dec_ctx *ctx);
void (*cap_to_disp)(struct mtk_vcodec_dec_ctx *ctx, int error,
struct media_request *src_buf_req);
struct vb2_ops *vdec_vb2_ops;
const struct mtk_video_fmt *vdec_formats;
const int *num_formats;
const struct mtk_video_fmt *default_out_fmt;
const struct mtk_video_fmt *default_cap_fmt;
enum mtk_vdec_hw_arch hw_arch;
bool is_subdev_supported;
bool uses_stateless_api;
};
/**
* struct mtk_vcodec_enc_pdata - compatible data for each IC
*
* @uses_ext: whether the encoder uses the extended firmware messaging format
* @min_bitrate: minimum supported encoding bitrate
* @max_bitrate: maximum supported encoding bitrate
* @capture_formats: array of supported capture formats
* @num_capture_formats: number of entries in capture_formats
* @output_formats: array of supported output formats
* @num_output_formats: number of entries in output_formats
* @core_id: stand for h264 or vp8 encode index
* @uses_34bit: whether the encoder uses 34-bit iova
*/
struct mtk_vcodec_enc_pdata {
bool uses_ext;
unsigned long min_bitrate;
unsigned long max_bitrate;
const struct mtk_video_fmt *capture_formats;
size_t num_capture_formats;
const struct mtk_video_fmt *output_formats;
size_t num_output_formats;
int core_id;
bool uses_34bit;
};
#define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext)
#define MTK_ENC_IOVA_IS_34BIT(ctx) ((ctx)->dev->venc_pdata->uses_34bit)
/**
* struct mtk_vcodec_dev - driver data
* @v4l2_dev: V4L2 device to register video devices for.
* @vfd_dec: Video device for decoder
* @mdev_dec: Media device for decoder
* @vfd_enc: Video device for encoder.
*
* @m2m_dev_dec: m2m device for decoder
* @m2m_dev_enc: m2m device for encoder.
* @plat_dev: platform device
* @ctx_list: list of struct mtk_vcodec_dec_ctx
* @irqlock: protect data access by irq handler and work thread
* @curr_ctx: The context that is waiting for codec hardware
* @curr_enc_ctx: The encoder context that is waiting for codec hardware
*
* @reg_base: Mapped address of MTK Vcodec registers.
* @vdec_pdata: decoder IC-specific data
* @venc_pdata: encoder IC-specific data
* @vdecsys_regmap: VDEC_SYS register space passed through syscon
*
* @fw_handler: used to communicate with the firmware.
* @id_counter: used to identify current opened instance
*
* @decode_workqueue: decode work queue
* @encode_workqueue: encode work queue
*
* @dev_mutex: video_device lock
*
* @dec_irq: decoder irq resource
* @enc_irq: h264 encoder irq resource
*
* @dec_mutex: decoder hardware lock
* @enc_mutex: encoder hardware lock.
*
* @pm: power management control
* @dec_capability: used to identify decode capability, ex: 4k
* @enc_capability: used to identify encode capability
*
* @core_workqueue: queue used for core hardware decode
*
* @subdev_dev: subdev hardware device
* @subdev_prob_done: check whether all used hw device is prob done
* @subdev_bitmap: used to record hardware is ready or not
*
* @dec_active_cnt: used to mark whether need to record register value
* @vdec_racing_info: record register value
* @dec_racing_info_mutex: mutex lock used for inner racing mode
* @dbgfs: debug log related information
*/
struct mtk_vcodec_dev {
struct v4l2_device v4l2_dev;
struct video_device *vfd_dec;
struct media_device mdev_dec;
struct video_device *vfd_enc;
struct v4l2_m2m_dev *m2m_dev_dec;
struct v4l2_m2m_dev *m2m_dev_enc;
struct platform_device *plat_dev;
struct list_head ctx_list;
spinlock_t irqlock;
struct mtk_vcodec_dec_ctx *curr_ctx;
struct mtk_vcodec_enc_ctx *curr_enc_ctx;
void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
const struct mtk_vcodec_dec_pdata *vdec_pdata;
const struct mtk_vcodec_enc_pdata *venc_pdata;
struct regmap *vdecsys_regmap;
struct mtk_vcodec_fw *fw_handler;
unsigned long id_counter;
struct workqueue_struct *decode_workqueue;
struct workqueue_struct *encode_workqueue;
struct mutex dev_mutex;
int dec_irq;
int enc_irq;
/* decoder hardware mutex lock */
struct mutex dec_mutex[MTK_VDEC_HW_MAX];
struct mutex enc_mutex;
struct mtk_vcodec_pm pm;
unsigned int dec_capability;
unsigned int enc_capability;
struct workqueue_struct *core_workqueue;
void *subdev_dev[MTK_VDEC_HW_MAX];
int (*subdev_prob_done)(struct mtk_vcodec_dev *vdec_dev);
DECLARE_BITMAP(subdev_bitmap, MTK_VDEC_HW_MAX);
atomic_t dec_active_cnt;
u32 vdec_racing_info[132];
/* Protects access to vdec_racing_info data */
struct mutex dec_racing_info_mutex;
struct mtk_vcodec_dbgfs dbgfs;
};
#endif /* _MTK_VCODEC_DRV_H_ */
......@@ -10,7 +10,6 @@
#include <media/videobuf2-dma-contig.h>
#include <linux/pm_runtime.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
......@@ -1436,7 +1435,7 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,
int mtk_venc_unlock(struct mtk_vcodec_enc_ctx *ctx)
{
struct mtk_vcodec_dev *dev = ctx->dev;
struct mtk_vcodec_enc_dev *dev = ctx->dev;
mutex_unlock(&dev->enc_mutex);
return 0;
......@@ -1444,7 +1443,7 @@ int mtk_venc_unlock(struct mtk_vcodec_enc_ctx *ctx)
int mtk_venc_lock(struct mtk_vcodec_enc_ctx *ctx)
{
struct mtk_vcodec_dev *dev = ctx->dev;
struct mtk_vcodec_enc_dev *dev = ctx->dev;
mutex_lock(&dev->enc_mutex);
return 0;
......
......@@ -16,7 +16,6 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc.h"
#include "mtk_vcodec_enc_pm.h"
#include "mtk_vcodec_intr.h"
......@@ -85,14 +84,14 @@ static void clean_irq_status(unsigned int irq_status, void __iomem *addr)
}
static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)
{
struct mtk_vcodec_dev *dev = priv;
struct mtk_vcodec_enc_dev *dev = priv;
struct mtk_vcodec_enc_ctx *ctx;
unsigned long flags;
void __iomem *addr;
int core_id;
spin_lock_irqsave(&dev->irqlock, flags);
ctx = dev->curr_enc_ctx;
ctx = dev->curr_ctx;
spin_unlock_irqrestore(&dev->irqlock, flags);
core_id = dev->venc_pdata->core_id;
......@@ -116,7 +115,7 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)
static int fops_vcodec_open(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
struct mtk_vcodec_enc_dev *dev = video_drvdata(file);
struct mtk_vcodec_enc_ctx *ctx = NULL;
int ret = 0;
struct vb2_queue *src_vq;
......@@ -203,7 +202,7 @@ static int fops_vcodec_open(struct file *file)
static int fops_vcodec_release(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
struct mtk_vcodec_enc_dev *dev = video_drvdata(file);
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(file->private_data);
mtk_v4l2_venc_dbg(1, ctx, "[%d] encoder", ctx->id);
......@@ -232,7 +231,7 @@ static const struct v4l2_file_operations mtk_vcodec_fops = {
static int mtk_vcodec_probe(struct platform_device *pdev)
{
struct mtk_vcodec_dev *dev;
struct mtk_vcodec_enc_dev *dev;
struct video_device *vfd_enc;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
......@@ -454,7 +453,7 @@ MODULE_DEVICE_TABLE(of, mtk_vcodec_enc_match);
static void mtk_vcodec_enc_remove(struct platform_device *pdev)
{
struct mtk_vcodec_dev *dev = platform_get_drvdata(pdev);
struct mtk_vcodec_enc_dev *dev = platform_get_drvdata(pdev);
destroy_workqueue(dev->encode_workqueue);
if (dev->m2m_dev_enc)
......@@ -463,7 +462,7 @@ static void mtk_vcodec_enc_remove(struct platform_device *pdev)
if (dev->vfd_enc)
video_unregister_device(dev->vfd_enc);
mtk_vcodec_dbgfs_deinit(dev);
mtk_vcodec_dbgfs_deinit(&dev->dbgfs);
v4l2_device_unregister(&dev->v4l2_dev);
pm_runtime_disable(dev->pm.dev);
mtk_vcodec_fw_release(dev->fw_handler);
......
......@@ -8,7 +8,39 @@
#define _MTK_VCODEC_ENC_DRV_H_
#include "mtk_vcodec_cmn_drv.h"
#include "mtk_vcodec_dbgfs.h"
#include "mtk_vcodec_fw_priv.h"
#include "mtk_vcodec_util.h"
#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
#define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext)
#define MTK_ENC_IOVA_IS_34BIT(ctx) ((ctx)->dev->venc_pdata->uses_34bit)
/**
* struct mtk_vcodec_enc_pdata - compatible data for each IC
*
* @uses_ext: whether the encoder uses the extended firmware messaging format
* @min_bitrate: minimum supported encoding bitrate
* @max_bitrate: maximum supported encoding bitrate
* @capture_formats: array of supported capture formats
* @num_capture_formats: number of entries in capture_formats
* @output_formats: array of supported output formats
* @num_output_formats: number of entries in output_formats
* @core_id: stand for h264 or vp8 encode index
* @uses_34bit: whether the encoder uses 34-bit iova
*/
struct mtk_vcodec_enc_pdata {
bool uses_ext;
unsigned long min_bitrate;
unsigned long max_bitrate;
const struct mtk_video_fmt *capture_formats;
size_t num_capture_formats;
const struct mtk_video_fmt *output_formats;
size_t num_output_formats;
int core_id;
bool uses_34bit;
};
/*
* enum mtk_encode_param - General encoding parameters type
......@@ -61,8 +93,8 @@ struct mtk_enc_params {
* struct mtk_vcodec_enc_ctx - Context (instance) private data.
*
* @type: type of encoder instance
* @dev: pointer to the mtk_vcodec_dev of the device
* @list: link to ctx_list of mtk_vcodec_dev
* @dev: pointer to the mtk_vcodec_enc_dev of the device
* @list: link to ctx_list of mtk_vcodec_enc_dev
*
* @fh: struct v4l2_fh
* @m2m_ctx: pointer to the v4l2_m2m_ctx of the context
......@@ -94,7 +126,7 @@ struct mtk_enc_params {
*/
struct mtk_vcodec_enc_ctx {
enum mtk_instance_type type;
struct mtk_vcodec_dev *dev;
struct mtk_vcodec_enc_dev *dev;
struct list_head list;
struct v4l2_fh fh;
......@@ -126,6 +158,61 @@ struct mtk_vcodec_enc_ctx {
struct mutex q_mutex;
};
/**
* struct mtk_vcodec_enc_dev - driver data
* @v4l2_dev: V4L2 device to register video devices for.
* @vfd_enc: Video device for encoder.
*
* @m2m_dev_enc: m2m device for encoder.
* @plat_dev: platform device
* @ctx_list: list of struct mtk_vcodec_ctx
* @curr_ctx: The context that is waiting for codec hardware
*
* @reg_base: Mapped address of MTK Vcodec registers.
* @venc_pdata: encoder IC-specific data
*
* @fw_handler: used to communicate with the firmware.
* @id_counter: used to identify current opened instance
*
* @enc_mutex: encoder hardware lock.
* @dev_mutex: video_device lock
* @encode_workqueue: encode work queue
*
* @enc_irq: h264 encoder irq resource
* @irqlock: protect data access by irq handler and work thread
*
* @pm: power management control
* @enc_capability: used to identify encode capability
* @dbgfs: debug log related information
*/
struct mtk_vcodec_enc_dev {
struct v4l2_device v4l2_dev;
struct video_device *vfd_enc;
struct v4l2_m2m_dev *m2m_dev_enc;
struct platform_device *plat_dev;
struct list_head ctx_list;
struct mtk_vcodec_enc_ctx *curr_ctx;
void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
const struct mtk_vcodec_enc_pdata *venc_pdata;
struct mtk_vcodec_fw *fw_handler;
unsigned long id_counter;
/* encoder hardware mutex lock */
struct mutex enc_mutex;
struct mutex dev_mutex;
struct workqueue_struct *encode_workqueue;
int enc_irq;
spinlock_t irqlock;
struct mtk_vcodec_pm pm;
unsigned int enc_capability;
struct mtk_vcodec_dbgfs dbgfs;
};
static inline struct mtk_vcodec_enc_ctx *fh_to_enc_ctx(struct v4l2_fh *fh)
{
return container_of(fh, struct mtk_vcodec_enc_ctx, fh);
......
......@@ -8,10 +8,10 @@
#include <linux/of.h>
#include <linux/pm_runtime.h>
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_enc_pm.h"
#include "mtk_vcodec_util.h"
int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *mtkdev)
int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *mtkdev)
{
struct platform_device *pdev;
struct mtk_vcodec_pm *pm;
......
......@@ -7,9 +7,9 @@
#ifndef _MTK_VCODEC_ENC_PM_H_
#define _MTK_VCODEC_ENC_PM_H_
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc_drv.h"
int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *dev);
int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *dev);
void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm);
void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm);
......
// SPDX-License-Identifier: GPL-2.0
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_fw.h"
#include "mtk_vcodec_fw_priv.h"
#include "mtk_vcodec_util.h"
#include "mtk_vcodec_drv.h"
struct mtk_vcodec_fw *mtk_vcodec_fw_select(void *priv, enum mtk_vcodec_fw_type type,
enum mtk_vcodec_fw_use fw_use)
{
struct platform_device *plat_dev;
if (fw_use == ENCODER)
plat_dev = ((struct mtk_vcodec_enc_dev *)priv)->plat_dev;
else
plat_dev = ((struct mtk_vcodec_dec_dev *)priv)->plat_dev;
switch (type) {
case VPU:
return mtk_vcodec_fw_vpu_init(priv, fw_use);
case SCP:
return mtk_vcodec_fw_scp_init(priv, fw_use);
default:
pr_err(MTK_DBG_VCODEC_STR "Invalid vcodec fw type");
dev_err(&plat_dev->dev, "Invalid vcodec fw type");
return ERR_PTR(-EINVAL);
}
}
......
......@@ -8,7 +8,8 @@
#include "../vpu/mtk_vpu.h"
struct mtk_vcodec_dev;
struct mtk_vcodec_dec_dev;
struct mtk_vcodec_enc_dev;
enum mtk_vcodec_fw_type {
VPU,
......
......@@ -5,7 +5,8 @@
#include "mtk_vcodec_fw.h"
struct mtk_vcodec_dev;
struct mtk_vcodec_dec_dev;
struct mtk_vcodec_enc_dev;
struct mtk_vcodec_fw {
enum mtk_vcodec_fw_type type;
......
// SPDX-License-Identifier: GPL-2.0
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_fw_priv.h"
#include "mtk_vcodec_util.h"
#include "mtk_vcodec_drv.h"
static int mtk_vcodec_scp_load_firmware(struct mtk_vcodec_fw *fw)
{
......@@ -56,14 +56,25 @@ static const struct mtk_vcodec_fw_ops mtk_vcodec_rproc_msg = {
struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(void *priv, enum mtk_vcodec_fw_use fw_use)
{
struct mtk_vcodec_fw *fw;
struct mtk_vcodec_dev *dev = priv;
struct platform_device *plat_dev;
struct mtk_scp *scp;
plat_dev = dev->plat_dev;
if (fw_use == ENCODER) {
struct mtk_vcodec_enc_dev *enc_dev = priv;
plat_dev = enc_dev->plat_dev;
} else if (fw_use == DECODER) {
struct mtk_vcodec_dec_dev *dec_dev = priv;
plat_dev = dec_dev->plat_dev;
} else {
pr_err("Invalid fw_use %d (use a resonable fw id here)\n", fw_use);
return ERR_PTR(-EINVAL);
}
scp = scp_get(plat_dev);
if (!scp) {
dev_err(&dev->plat_dev->dev, "could not get vdec scp handle");
dev_err(&plat_dev->dev, "could not get vdec scp handle");
return ERR_PTR(-EPROBE_DEFER);
}
......
// SPDX-License-Identifier: GPL-2.0
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_fw_priv.h"
#include "mtk_vcodec_util.h"
#include "mtk_vcodec_drv.h"
static int mtk_vcodec_vpu_load_firmware(struct mtk_vcodec_fw *fw)
{
......@@ -53,7 +53,7 @@ static void mtk_vcodec_vpu_release(struct mtk_vcodec_fw *fw)
static void mtk_vcodec_vpu_reset_dec_handler(void *priv)
{
struct mtk_vcodec_dev *dev = priv;
struct mtk_vcodec_dec_dev *dev = priv;
struct mtk_vcodec_dec_ctx *ctx;
dev_err(&dev->plat_dev->dev, "Watchdog timeout!!");
......@@ -68,7 +68,7 @@ static void mtk_vcodec_vpu_reset_dec_handler(void *priv)
static void mtk_vcodec_vpu_reset_enc_handler(void *priv)
{
struct mtk_vcodec_dev *dev = priv;
struct mtk_vcodec_enc_dev *dev = priv;
struct mtk_vcodec_enc_ctx *ctx;
dev_err(&dev->plat_dev->dev, "Watchdog timeout!!");
......@@ -94,24 +94,28 @@ static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = {
struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(void *priv, enum mtk_vcodec_fw_use fw_use)
{
struct platform_device *fw_pdev;
struct mtk_vcodec_dev *dev = priv;
struct platform_device *plat_dev;
struct mtk_vcodec_fw *fw;
enum rst_id rst_id;
if (fw_use == ENCODER) {
struct mtk_vcodec_enc_dev *enc_dev = priv;
plat_dev = enc_dev->plat_dev;
rst_id = VPU_RST_ENC;
} else if (fw_use == DECODER) {
struct mtk_vcodec_dec_dev *dec_dev = priv;
plat_dev = dec_dev->plat_dev;
rst_id = VPU_RST_DEC;
} else {
pr_err("Invalid fw_use %d (use a resonable fw id here)\n", fw_use);
return ERR_PTR(-EINVAL);
}
plat_dev = dev->plat_dev;
fw_pdev = vpu_get_plat_device(plat_dev);
if (!fw_pdev) {
dev_err(&dev->plat_dev->dev, "firmware device is not ready");
dev_err(&plat_dev->dev, "firmware device is not ready");
return ERR_PTR(-EINVAL);
}
......
......@@ -7,9 +7,9 @@
#include <linux/errno.h>
#include <linux/wait.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
int mtk_vcodec_wait_for_done_ctx(void *priv, int command, unsigned int timeout_ms,
unsigned int hw_id)
......
......@@ -9,9 +9,9 @@
#include <linux/of.h>
#include <linux/regmap.h>
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_dec_hw.h"
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_util.h"
#if defined(CONFIG_DEBUG_FS)
int mtk_vcodec_dbg;
......@@ -34,7 +34,7 @@ EXPORT_SYMBOL(mtk_vcodec_get_reg_addr);
int mtk_vcodec_write_vdecsys(struct mtk_vcodec_dec_ctx *ctx, unsigned int reg,
unsigned int val)
{
struct mtk_vcodec_dev *dev = ctx->dev;
struct mtk_vcodec_dec_dev *dev = ctx->dev;
if (dev->vdecsys_regmap)
return regmap_write(dev->vdecsys_regmap, reg, val);
......@@ -89,7 +89,7 @@ void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem)
}
EXPORT_SYMBOL(mtk_vcodec_mem_free);
void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx)
void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dec_dev *dev, int hw_idx)
{
if (hw_idx >= MTK_VDEC_HW_MAX || hw_idx < 0 || !dev->subdev_dev[hw_idx]) {
dev_err(&dev->plat_dev->dev, "hw idx is out of range:%d", hw_idx);
......@@ -100,7 +100,7 @@ void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx)
}
EXPORT_SYMBOL(mtk_vcodec_get_hw_dev);
void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev,
struct mtk_vcodec_dec_ctx *ctx, int hw_idx)
{
unsigned long flags;
......@@ -122,7 +122,7 @@ void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
}
EXPORT_SYMBOL(mtk_vcodec_set_curr_ctx);
struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev,
unsigned int hw_idx)
{
unsigned long flags;
......
......@@ -26,7 +26,7 @@ struct mtk_vcodec_fb {
};
struct mtk_vcodec_dec_ctx;
struct mtk_vcodec_dev;
struct mtk_vcodec_dec_dev;
#undef pr_fmt
#define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__
......@@ -88,10 +88,10 @@ void __iomem *mtk_vcodec_get_reg_addr(void __iomem **reg_base, unsigned int reg_
int mtk_vcodec_write_vdecsys(struct mtk_vcodec_dec_ctx *ctx, unsigned int reg, unsigned int val);
int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem);
void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem);
void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev,
struct mtk_vcodec_dec_ctx *ctx, int hw_idx);
struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev,
unsigned int hw_idx);
void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx);
void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dec_dev *dev, int hw_idx);
#endif /* _MTK_VCODEC_UTIL_H_ */
......@@ -13,7 +13,7 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>
#include "../mtk_vcodec_drv.h"
#include "../mtk_vcodec_dec_drv.h"
#define NAL_NON_IDR_SLICE 0x01
#define NAL_IDR_SLICE 0x05
......
......@@ -540,7 +540,7 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
return 0;
}
static void vdec_h264_insert_startcode(struct mtk_vcodec_dev *vcodec_dev, unsigned char *buf,
static void vdec_h264_insert_startcode(struct mtk_vcodec_dec_dev *vcodec_dev, unsigned char *buf,
size_t *bs_size, struct mtk_h264_pps_param *pps)
{
struct device *dev = &vcodec_dev->plat_dev->dev;
......
......@@ -8,7 +8,6 @@
#ifndef _VDEC_DRV_IF_H_
#define _VDEC_DRV_IF_H_
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_util.h"
......
......@@ -8,8 +8,8 @@
#include <linux/interrupt.h>
#include <linux/kthread.h>
#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_dec_pm.h"
#include "mtk_vcodec_drv.h"
#include "vdec_msg_queue.h"
#define VDEC_MSG_QUEUE_TIMEOUT_MS 1500
......@@ -241,7 +241,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
container_of(work, struct vdec_msg_queue, core_work);
struct mtk_vcodec_dec_ctx *ctx =
container_of(msg_queue, struct mtk_vcodec_dec_ctx, msg_queue);
struct mtk_vcodec_dev *dev = ctx->dev;
struct mtk_vcodec_dec_dev *dev = ctx->dev;
struct vdec_lat_buf *lat_buf;
spin_lock(&msg_queue->core_ctx.ready_lock);
......
......@@ -18,7 +18,7 @@
struct vdec_lat_buf;
struct mtk_vcodec_dec_ctx;
struct mtk_vcodec_dev;
struct mtk_vcodec_dec_dev;
typedef int (*core_decode_cb_t)(struct vdec_lat_buf *lat_buf);
/**
......
......@@ -4,8 +4,7 @@
* Author: PC Chen <pc.chen@mediatek.com>
*/
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_util.h"
#include "mtk_vcodec_dec_drv.h"
#include "vdec_drv_if.h"
#include "vdec_ipi_msg.h"
#include "vdec_vpu_if.h"
......
......@@ -10,7 +10,7 @@
#include <linux/kernel.h>
#include <linux/slab.h>
#include "../mtk_vcodec_drv.h"
#include "../mtk_vcodec_enc_drv.h"
#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_intr.h"
#include "../mtk_vcodec_enc.h"
......
......@@ -9,7 +9,7 @@
#include <linux/kernel.h>
#include <linux/slab.h>
#include "../mtk_vcodec_drv.h"
#include "../mtk_vcodec_enc_drv.h"
#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_intr.h"
#include "../mtk_vcodec_enc.h"
......
......@@ -9,7 +9,7 @@
#ifndef _VENC_DRV_BASE_
#define _VENC_DRV_BASE_
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "venc_drv_if.h"
......
......@@ -65,7 +65,7 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
mtk_venc_lock(ctx);
spin_lock_irqsave(&ctx->dev->irqlock, flags);
ctx->dev->curr_enc_ctx = ctx;
ctx->dev->curr_ctx = ctx;
spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
mtk_vcodec_enc_clock_on(&ctx->dev->pm);
......@@ -74,7 +74,7 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
mtk_vcodec_enc_clock_off(&ctx->dev->pm);
spin_lock_irqsave(&ctx->dev->irqlock, flags);
ctx->dev->curr_enc_ctx = NULL;
ctx->dev->curr_ctx = NULL;
spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
mtk_venc_unlock(ctx);
......
......@@ -9,8 +9,7 @@
#ifndef _VENC_DRV_IF_H_
#define _VENC_DRV_IF_H_
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_util.h"
#include "mtk_vcodec_enc_drv.h"
/*
* enum venc_yuv_fmt - The type of input yuv format
......
......@@ -4,7 +4,7 @@
* Author: PoChun Lin <pochun.lin@mediatek.com>
*/
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_fw.h"
#include "venc_ipi_msg.h"
#include "venc_vpu_if.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment