2018-12-06 00:09:52 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
2019-06-12 17:39:06 +08:00
|
|
|
* Hantro VPU codec driver
|
2018-12-06 00:09:52 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Collabora, Ltd.
|
|
|
|
* Copyright 2018 Google LLC.
|
|
|
|
* Tomasz Figa <tfiga@chromium.org>
|
|
|
|
*
|
|
|
|
* Based on s5p-mfc driver by Samsung Electronics Co., Ltd.
|
|
|
|
* Copyright (C) 2011 Samsung Electronics Co., Ltd.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <media/v4l2-event.h>
|
|
|
|
#include <media/v4l2-mem2mem.h>
|
|
|
|
#include <media/videobuf2-core.h>
|
|
|
|
#include <media/videobuf2-vmalloc.h>
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
#include "hantro_v4l2.h"
|
|
|
|
#include "hantro.h"
|
|
|
|
#include "hantro_hw.h"
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
#define DRIVER_NAME "hantro-vpu"
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
int hantro_debug;
|
|
|
|
module_param_named(debug, hantro_debug, int, 0644);
|
2018-12-06 00:09:52 +08:00
|
|
|
MODULE_PARM_DESC(debug,
|
|
|
|
"Debug level - higher value produces more verbose messages");
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
void *hantro_get_ctrl(struct hantro_ctx *ctx, u32 id)
|
2019-05-29 01:02:29 +08:00
|
|
|
{
|
|
|
|
struct v4l2_ctrl *ctrl;
|
|
|
|
|
|
|
|
ctrl = v4l2_ctrl_find(&ctx->ctrl_handler, id);
|
|
|
|
return ctrl ? ctrl->p_cur.p : NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-04 02:17:09 +08:00
|
|
|
dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
|
2019-05-29 01:02:29 +08:00
|
|
|
{
|
2019-09-04 02:17:09 +08:00
|
|
|
struct vb2_queue *q = v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx);
|
2019-06-19 07:12:37 +08:00
|
|
|
struct vb2_buffer *buf;
|
2019-05-29 01:02:29 +08:00
|
|
|
|
2022-07-12 05:11:38 +08:00
|
|
|
buf = vb2_find_buffer(q, ts);
|
|
|
|
if (!buf)
|
2019-06-19 07:12:37 +08:00
|
|
|
return 0;
|
2019-12-05 22:24:43 +08:00
|
|
|
return hantro_get_dec_buf_addr(ctx, buf);
|
2019-05-29 01:02:29 +08:00
|
|
|
}
|
|
|
|
|
2022-03-31 17:16:28 +08:00
|
|
|
static const struct v4l2_event hantro_eos_event = {
|
|
|
|
.type = V4L2_EVENT_EOS
|
|
|
|
};
|
|
|
|
|
2021-04-28 14:27:55 +08:00
|
|
|
static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
|
|
|
|
struct hantro_ctx *ctx,
|
|
|
|
enum vb2_buffer_state result)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
|
|
|
struct vb2_v4l2_buffer *src, *dst;
|
|
|
|
|
2020-03-26 05:34:34 +08:00
|
|
|
src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
|
|
|
|
dst = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
if (WARN_ON(!src))
|
|
|
|
return;
|
|
|
|
if (WARN_ON(!dst))
|
|
|
|
return;
|
|
|
|
|
|
|
|
src->sequence = ctx->sequence_out++;
|
|
|
|
dst->sequence = ctx->sequence_cap++;
|
|
|
|
|
2022-03-31 17:16:28 +08:00
|
|
|
if (v4l2_m2m_is_last_draining_src_buf(ctx->fh.m2m_ctx, src)) {
|
|
|
|
dst->flags |= V4L2_BUF_FLAG_LAST;
|
|
|
|
v4l2_event_queue_fh(&ctx->fh, &hantro_eos_event);
|
|
|
|
v4l2_m2m_mark_stopped(ctx->fh.m2m_ctx);
|
|
|
|
}
|
|
|
|
|
2020-03-26 05:34:34 +08:00
|
|
|
v4l2_m2m_buf_done_and_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx,
|
|
|
|
result);
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:27:55 +08:00
|
|
|
static void hantro_job_finish(struct hantro_dev *vpu,
|
|
|
|
struct hantro_ctx *ctx,
|
|
|
|
enum vb2_buffer_state result)
|
|
|
|
{
|
|
|
|
pm_runtime_mark_last_busy(vpu->dev);
|
|
|
|
pm_runtime_put_autosuspend(vpu->dev);
|
|
|
|
|
|
|
|
clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
|
|
|
|
|
|
|
|
hantro_job_finish_no_pm(vpu, ctx, result);
|
|
|
|
}
|
|
|
|
|
2020-07-01 21:16:06 +08:00
|
|
|
void hantro_irq_done(struct hantro_dev *vpu,
|
2019-06-12 17:39:06 +08:00
|
|
|
enum vb2_buffer_state result)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_ctx *ctx =
|
2018-12-06 00:09:52 +08:00
|
|
|
v4l2_m2m_get_curr_priv(vpu->m2m_dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If cancel_delayed_work returns false
|
|
|
|
* the timeout expired. The watchdog is running,
|
|
|
|
* and will take care of finishing the job.
|
|
|
|
*/
|
2020-07-01 21:16:05 +08:00
|
|
|
if (cancel_delayed_work(&vpu->watchdog_work)) {
|
|
|
|
if (result == VB2_BUF_STATE_DONE && ctx->codec_ops->done)
|
|
|
|
ctx->codec_ops->done(ctx);
|
2020-07-01 21:16:06 +08:00
|
|
|
hantro_job_finish(vpu, ctx, result);
|
2020-07-01 21:16:05 +08:00
|
|
|
}
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
void hantro_watchdog(struct work_struct *work)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_dev *vpu;
|
|
|
|
struct hantro_ctx *ctx;
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
vpu = container_of(to_delayed_work(work),
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_dev, watchdog_work);
|
2018-12-06 00:09:52 +08:00
|
|
|
ctx = v4l2_m2m_get_curr_priv(vpu->m2m_dev);
|
|
|
|
if (ctx) {
|
|
|
|
vpu_err("frame processing timed out!\n");
|
|
|
|
ctx->codec_ops->reset(ctx);
|
2020-07-01 21:16:06 +08:00
|
|
|
hantro_job_finish(vpu, ctx, VB2_BUF_STATE_ERROR);
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 22:24:42 +08:00
|
|
|
void hantro_start_prepare_run(struct hantro_ctx *ctx)
|
2019-07-25 22:17:54 +08:00
|
|
|
{
|
|
|
|
struct vb2_v4l2_buffer *src_buf;
|
|
|
|
|
|
|
|
src_buf = hantro_get_src_buf(ctx);
|
|
|
|
v4l2_ctrl_request_setup(src_buf->vb2_buf.req_obj.req,
|
|
|
|
&ctx->ctrl_handler);
|
2019-12-05 22:24:43 +08:00
|
|
|
|
2021-11-30 02:26:29 +08:00
|
|
|
if (!ctx->is_encoder && !ctx->dev->variant->late_postproc) {
|
2020-07-01 21:16:07 +08:00
|
|
|
if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
|
|
|
|
hantro_postproc_enable(ctx);
|
|
|
|
else
|
|
|
|
hantro_postproc_disable(ctx);
|
|
|
|
}
|
2019-07-25 22:17:54 +08:00
|
|
|
}
|
|
|
|
|
2019-12-05 22:24:42 +08:00
|
|
|
void hantro_end_prepare_run(struct hantro_ctx *ctx)
|
2019-07-25 22:17:54 +08:00
|
|
|
{
|
|
|
|
struct vb2_v4l2_buffer *src_buf;
|
|
|
|
|
2021-11-30 02:26:29 +08:00
|
|
|
if (!ctx->is_encoder && ctx->dev->variant->late_postproc) {
|
|
|
|
if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
|
|
|
|
hantro_postproc_enable(ctx);
|
|
|
|
else
|
|
|
|
hantro_postproc_disable(ctx);
|
|
|
|
}
|
|
|
|
|
2019-07-25 22:17:54 +08:00
|
|
|
src_buf = hantro_get_src_buf(ctx);
|
|
|
|
v4l2_ctrl_request_complete(src_buf->vb2_buf.req_obj.req,
|
|
|
|
&ctx->ctrl_handler);
|
|
|
|
|
|
|
|
/* Kick the watchdog. */
|
|
|
|
schedule_delayed_work(&ctx->dev->watchdog_work,
|
|
|
|
msecs_to_jiffies(2000));
|
|
|
|
}
|
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
static void device_run(void *priv)
|
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_ctx *ctx = priv;
|
2019-08-17 00:01:29 +08:00
|
|
|
struct vb2_v4l2_buffer *src, *dst;
|
2018-12-06 00:09:52 +08:00
|
|
|
int ret;
|
|
|
|
|
2019-08-17 00:01:29 +08:00
|
|
|
src = hantro_get_src_buf(ctx);
|
|
|
|
dst = hantro_get_dst_buf(ctx);
|
|
|
|
|
2021-04-26 20:26:43 +08:00
|
|
|
ret = pm_runtime_resume_and_get(ctx->dev->dev);
|
|
|
|
if (ret < 0)
|
2021-04-28 14:27:55 +08:00
|
|
|
goto err_cancel_job;
|
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
|
|
|
|
if (ret)
|
|
|
|
goto err_cancel_job;
|
|
|
|
|
2019-08-17 00:01:29 +08:00
|
|
|
v4l2_m2m_buf_copy_metadata(src, dst, true);
|
|
|
|
|
2021-06-03 19:49:58 +08:00
|
|
|
if (ctx->codec_ops->run(ctx))
|
|
|
|
goto err_cancel_job;
|
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
err_cancel_job:
|
2021-04-28 14:27:55 +08:00
|
|
|
hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
|
|
|
|
2021-09-21 04:02:10 +08:00
|
|
|
static const struct v4l2_m2m_ops vpu_m2m_ops = {
|
2018-12-06 00:09:52 +08:00
|
|
|
.device_run = device_run,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2019-05-29 01:02:24 +08:00
|
|
|
queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_ctx *ctx = priv;
|
2018-12-06 00:09:52 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
|
|
|
|
src_vq->io_modes = VB2_MMAP | VB2_DMABUF;
|
|
|
|
src_vq->drv_priv = ctx;
|
2019-06-12 17:39:06 +08:00
|
|
|
src_vq->ops = &hantro_queue_ops;
|
2018-12-06 00:09:52 +08:00
|
|
|
src_vq->mem_ops = &vb2_dma_contig_memops;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver does mostly sequential access, so sacrifice TLB efficiency
|
|
|
|
* for faster allocation. Also, no CPU access on the source queue,
|
|
|
|
* so no kernel mapping needed.
|
|
|
|
*/
|
|
|
|
src_vq->dma_attrs = DMA_ATTR_ALLOC_SINGLE_PAGES |
|
|
|
|
DMA_ATTR_NO_KERNEL_MAPPING;
|
|
|
|
src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
|
|
|
|
src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
|
|
|
|
src_vq->lock = &ctx->dev->vpu_mutex;
|
|
|
|
src_vq->dev = ctx->dev->v4l2_dev.dev;
|
2019-05-29 01:02:22 +08:00
|
|
|
src_vq->supports_requests = true;
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
ret = vb2_queue_init(src_vq);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-01-07 17:34:54 +08:00
|
|
|
dst_vq->bidirectional = true;
|
|
|
|
dst_vq->mem_ops = &vb2_dma_contig_memops;
|
|
|
|
dst_vq->dma_attrs = DMA_ATTR_ALLOC_SINGLE_PAGES;
|
2018-12-06 00:09:52 +08:00
|
|
|
/*
|
2022-01-07 17:34:54 +08:00
|
|
|
* The Kernel needs access to the JPEG destination buffer for the
|
|
|
|
* JPEG encoder to fill in the JPEG headers.
|
2018-12-06 00:09:52 +08:00
|
|
|
*/
|
2022-01-07 17:34:54 +08:00
|
|
|
if (!ctx->is_encoder)
|
|
|
|
dst_vq->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
|
2019-05-29 01:02:27 +08:00
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
|
|
|
|
dst_vq->io_modes = VB2_MMAP | VB2_DMABUF;
|
|
|
|
dst_vq->drv_priv = ctx;
|
2019-06-12 17:39:06 +08:00
|
|
|
dst_vq->ops = &hantro_queue_ops;
|
2021-11-16 22:38:40 +08:00
|
|
|
dst_vq->buf_struct_size = sizeof(struct hantro_decoded_buffer);
|
2018-12-06 00:09:52 +08:00
|
|
|
dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
|
|
|
|
dst_vq->lock = &ctx->dev->vpu_mutex;
|
|
|
|
dst_vq->dev = ctx->dev->v4l2_dev.dev;
|
|
|
|
|
|
|
|
return vb2_queue_init(dst_vq);
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:36:35 +08:00
|
|
|
static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
|
|
|
|
{
|
2020-11-26 17:36:17 +08:00
|
|
|
if (ctrl->id == V4L2_CID_STATELESS_H264_SPS) {
|
2020-07-10 00:36:35 +08:00
|
|
|
const struct v4l2_ctrl_h264_sps *sps = ctrl->p_new.p_h264_sps;
|
|
|
|
|
|
|
|
if (sps->chroma_format_idc > 1)
|
|
|
|
/* Only 4:0:0 and 4:2:0 are supported */
|
|
|
|
return -EINVAL;
|
|
|
|
if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
|
|
|
|
/* Luma and chroma bit depth mismatch */
|
|
|
|
return -EINVAL;
|
|
|
|
if (sps->bit_depth_luma_minus8 != 0)
|
|
|
|
/* Only 8-bit is supported */
|
|
|
|
return -EINVAL;
|
2022-07-09 00:21:44 +08:00
|
|
|
} else if (ctrl->id == V4L2_CID_STATELESS_HEVC_SPS) {
|
2021-06-03 19:49:59 +08:00
|
|
|
const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
|
|
|
|
|
2022-08-30 00:21:57 +08:00
|
|
|
if (sps->bit_depth_luma_minus8 != 0 && sps->bit_depth_luma_minus8 != 2)
|
|
|
|
/* Only 8-bit and 10-bit are supported */
|
2022-07-19 05:41:23 +08:00
|
|
|
return -EINVAL;
|
2021-11-16 22:38:40 +08:00
|
|
|
} else if (ctrl->id == V4L2_CID_STATELESS_VP9_FRAME) {
|
|
|
|
const struct v4l2_ctrl_vp9_frame *dec_params = ctrl->p_new.p_vp9_frame;
|
|
|
|
|
|
|
|
/* We only support profile 0 */
|
|
|
|
if (dec_params->profile != 0)
|
|
|
|
return -EINVAL;
|
2023-05-03 16:34:32 +08:00
|
|
|
} else if (ctrl->id == V4L2_CID_STATELESS_AV1_SEQUENCE) {
|
|
|
|
const struct v4l2_ctrl_av1_sequence *sequence = ctrl->p_new.p_av1_sequence;
|
|
|
|
|
|
|
|
if (sequence->bit_depth != 8 && sequence->bit_depth != 10)
|
|
|
|
return -EINVAL;
|
2020-07-10 00:36:35 +08:00
|
|
|
}
|
2023-05-03 16:34:32 +08:00
|
|
|
|
2020-07-10 00:36:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_ctx *ctx;
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
ctx = container_of(ctrl->handler,
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_ctx, ctrl_handler);
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
|
|
|
|
|
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_JPEG_COMPRESSION_QUALITY:
|
|
|
|
ctx->jpeg_quality = ctrl->val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-07 02:29:00 +08:00
|
|
|
static int hantro_vp9_s_ctrl(struct v4l2_ctrl *ctrl)
|
|
|
|
{
|
|
|
|
struct hantro_ctx *ctx;
|
|
|
|
|
|
|
|
ctx = container_of(ctrl->handler,
|
|
|
|
struct hantro_ctx, ctrl_handler);
|
|
|
|
|
|
|
|
switch (ctrl->id) {
|
2023-02-20 18:48:49 +08:00
|
|
|
case V4L2_CID_STATELESS_VP9_FRAME: {
|
|
|
|
int bit_depth = ctrl->p_new.p_vp9_frame->bit_depth;
|
|
|
|
|
|
|
|
if (ctx->bit_depth == bit_depth)
|
|
|
|
return 0;
|
|
|
|
|
2023-05-03 16:34:38 +08:00
|
|
|
return hantro_reset_raw_fmt(ctx, bit_depth, HANTRO_AUTO_POSTPROC);
|
2023-02-20 18:48:49 +08:00
|
|
|
}
|
2022-07-07 02:29:00 +08:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:48:46 +08:00
|
|
|
static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
|
|
|
|
{
|
|
|
|
struct hantro_ctx *ctx;
|
|
|
|
|
|
|
|
ctx = container_of(ctrl->handler,
|
|
|
|
struct hantro_ctx, ctrl_handler);
|
|
|
|
|
|
|
|
switch (ctrl->id) {
|
2023-02-20 18:48:48 +08:00
|
|
|
case V4L2_CID_STATELESS_HEVC_SPS: {
|
|
|
|
const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
|
|
|
|
int bit_depth = sps->bit_depth_luma_minus8 + 8;
|
|
|
|
|
|
|
|
if (ctx->bit_depth == bit_depth)
|
|
|
|
return 0;
|
|
|
|
|
2023-05-03 16:34:38 +08:00
|
|
|
return hantro_reset_raw_fmt(ctx, bit_depth, HANTRO_AUTO_POSTPROC);
|
2023-02-20 18:48:48 +08:00
|
|
|
}
|
2023-02-20 18:48:46 +08:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-03 16:34:32 +08:00
|
|
|
static int hantro_av1_s_ctrl(struct v4l2_ctrl *ctrl)
|
|
|
|
{
|
|
|
|
struct hantro_ctx *ctx;
|
|
|
|
|
|
|
|
ctx = container_of(ctrl->handler,
|
|
|
|
struct hantro_ctx, ctrl_handler);
|
|
|
|
|
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_STATELESS_AV1_SEQUENCE:
|
|
|
|
{
|
|
|
|
int bit_depth = ctrl->p_new.p_av1_sequence->bit_depth;
|
2023-05-03 16:34:38 +08:00
|
|
|
bool need_postproc = HANTRO_AUTO_POSTPROC;
|
2023-05-03 16:34:32 +08:00
|
|
|
|
2023-05-03 16:34:38 +08:00
|
|
|
if (ctrl->p_new.p_av1_sequence->flags
|
|
|
|
& V4L2_AV1_SEQUENCE_FLAG_FILM_GRAIN_PARAMS_PRESENT)
|
|
|
|
need_postproc = HANTRO_FORCE_POSTPROC;
|
|
|
|
|
|
|
|
if (ctx->bit_depth == bit_depth &&
|
|
|
|
ctx->need_postproc == need_postproc)
|
2023-05-03 16:34:32 +08:00
|
|
|
return 0;
|
|
|
|
|
2023-05-03 16:34:38 +08:00
|
|
|
return hantro_reset_raw_fmt(ctx, bit_depth, need_postproc);
|
2023-05-03 16:34:32 +08:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
|
2020-07-10 00:36:35 +08:00
|
|
|
.try_ctrl = hantro_try_ctrl,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct v4l2_ctrl_ops hantro_jpeg_ctrl_ops = {
|
|
|
|
.s_ctrl = hantro_jpeg_s_ctrl,
|
2018-12-06 00:09:52 +08:00
|
|
|
};
|
|
|
|
|
2022-07-07 02:29:00 +08:00
|
|
|
static const struct v4l2_ctrl_ops hantro_vp9_ctrl_ops = {
|
|
|
|
.s_ctrl = hantro_vp9_s_ctrl,
|
|
|
|
};
|
|
|
|
|
2023-02-20 18:48:46 +08:00
|
|
|
static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
|
|
|
|
.try_ctrl = hantro_try_ctrl,
|
|
|
|
.s_ctrl = hantro_hevc_s_ctrl,
|
|
|
|
};
|
|
|
|
|
2023-05-03 16:34:32 +08:00
|
|
|
static const struct v4l2_ctrl_ops hantro_av1_ctrl_ops = {
|
|
|
|
.try_ctrl = hantro_try_ctrl,
|
|
|
|
.s_ctrl = hantro_av1_s_ctrl,
|
|
|
|
};
|
|
|
|
|
2022-01-07 17:34:53 +08:00
|
|
|
#define HANTRO_JPEG_ACTIVE_MARKERS (V4L2_JPEG_ACTIVE_MARKER_APP0 | \
|
|
|
|
V4L2_JPEG_ACTIVE_MARKER_COM | \
|
|
|
|
V4L2_JPEG_ACTIVE_MARKER_DQT | \
|
|
|
|
V4L2_JPEG_ACTIVE_MARKER_DHT)
|
|
|
|
|
2019-07-25 22:17:52 +08:00
|
|
|
static const struct hantro_ctrl controls[] = {
|
2019-05-29 01:02:28 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
.codec = HANTRO_JPEG_ENCODER,
|
2019-05-29 01:02:28 +08:00
|
|
|
.cfg = {
|
2019-07-25 22:17:51 +08:00
|
|
|
.id = V4L2_CID_JPEG_COMPRESSION_QUALITY,
|
2019-05-29 01:02:28 +08:00
|
|
|
.min = 5,
|
|
|
|
.max = 100,
|
|
|
|
.step = 1,
|
|
|
|
.def = 50,
|
2020-07-10 00:36:35 +08:00
|
|
|
.ops = &hantro_jpeg_ctrl_ops,
|
2019-05-29 01:02:28 +08:00
|
|
|
},
|
2022-01-07 17:34:53 +08:00
|
|
|
}, {
|
|
|
|
.codec = HANTRO_JPEG_ENCODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_JPEG_ACTIVE_MARKER,
|
|
|
|
.max = HANTRO_JPEG_ACTIVE_MARKERS,
|
|
|
|
.def = HANTRO_JPEG_ACTIVE_MARKERS,
|
|
|
|
/*
|
|
|
|
* Changing the set of active markers/segments also
|
|
|
|
* messes up the alignment of the JPEG header, which
|
|
|
|
* is needed to allow the hardware to write directly
|
|
|
|
* to the output buffer. Implementing this introduces
|
|
|
|
* a lot of complexity for little gain, as the markers
|
|
|
|
* enabled is already the minimum required set.
|
|
|
|
*/
|
|
|
|
.flags = V4L2_CTRL_FLAG_READ_ONLY,
|
|
|
|
},
|
2021-04-29 22:48:12 +08:00
|
|
|
}, {
|
|
|
|
.codec = HANTRO_MPEG2_DECODER,
|
|
|
|
.cfg = {
|
2021-04-29 22:48:18 +08:00
|
|
|
.id = V4L2_CID_STATELESS_MPEG2_SEQUENCE,
|
2021-04-29 22:48:12 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_MPEG2_DECODER,
|
|
|
|
.cfg = {
|
2021-04-29 22:48:18 +08:00
|
|
|
.id = V4L2_CID_STATELESS_MPEG2_PICTURE,
|
2021-04-29 22:48:12 +08:00
|
|
|
},
|
2019-05-29 01:02:29 +08:00
|
|
|
}, {
|
2019-06-12 17:39:06 +08:00
|
|
|
.codec = HANTRO_MPEG2_DECODER,
|
2019-05-29 01:02:29 +08:00
|
|
|
.cfg = {
|
2021-04-29 22:48:18 +08:00
|
|
|
.id = V4L2_CID_STATELESS_MPEG2_QUANTISATION,
|
2019-05-29 01:02:29 +08:00
|
|
|
},
|
2019-07-12 04:26:44 +08:00
|
|
|
}, {
|
|
|
|
.codec = HANTRO_VP8_DECODER,
|
|
|
|
.cfg = {
|
2021-03-04 22:07:55 +08:00
|
|
|
.id = V4L2_CID_STATELESS_VP8_FRAME,
|
2019-07-12 04:26:44 +08:00
|
|
|
},
|
2019-08-17 00:01:30 +08:00
|
|
|
}, {
|
|
|
|
.codec = HANTRO_H264_DECODER,
|
|
|
|
.cfg = {
|
2020-11-26 17:36:17 +08:00
|
|
|
.id = V4L2_CID_STATELESS_H264_DECODE_PARAMS,
|
2019-08-17 00:01:30 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_H264_DECODER,
|
|
|
|
.cfg = {
|
2020-11-26 17:36:17 +08:00
|
|
|
.id = V4L2_CID_STATELESS_H264_SPS,
|
2020-07-10 00:36:35 +08:00
|
|
|
.ops = &hantro_ctrl_ops,
|
2019-08-17 00:01:30 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_H264_DECODER,
|
|
|
|
.cfg = {
|
2020-11-26 17:36:17 +08:00
|
|
|
.id = V4L2_CID_STATELESS_H264_PPS,
|
2019-08-17 00:01:30 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_H264_DECODER,
|
|
|
|
.cfg = {
|
2020-11-26 17:36:17 +08:00
|
|
|
.id = V4L2_CID_STATELESS_H264_SCALING_MATRIX,
|
2019-08-17 00:01:30 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_H264_DECODER,
|
|
|
|
.cfg = {
|
2020-11-26 17:36:17 +08:00
|
|
|
.id = V4L2_CID_STATELESS_H264_DECODE_MODE,
|
|
|
|
.min = V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED,
|
|
|
|
.def = V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED,
|
|
|
|
.max = V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED,
|
2019-08-17 00:01:30 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_H264_DECODER,
|
|
|
|
.cfg = {
|
2020-11-26 17:36:17 +08:00
|
|
|
.id = V4L2_CID_STATELESS_H264_START_CODE,
|
|
|
|
.min = V4L2_STATELESS_H264_START_CODE_ANNEX_B,
|
|
|
|
.def = V4L2_STATELESS_H264_START_CODE_ANNEX_B,
|
|
|
|
.max = V4L2_STATELESS_H264_START_CODE_ANNEX_B,
|
2019-08-17 00:01:30 +08:00
|
|
|
},
|
2019-11-22 13:16:08 +08:00
|
|
|
}, {
|
|
|
|
.codec = HANTRO_H264_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_MPEG_VIDEO_H264_PROFILE,
|
|
|
|
.min = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE,
|
|
|
|
.max = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
|
|
|
|
.menu_skip_mask =
|
|
|
|
BIT(V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED),
|
|
|
|
.def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN,
|
|
|
|
}
|
2019-08-17 00:01:30 +08:00
|
|
|
}, {
|
2021-06-03 19:49:59 +08:00
|
|
|
.codec = HANTRO_HEVC_DECODER,
|
|
|
|
.cfg = {
|
2022-07-09 00:21:44 +08:00
|
|
|
.id = V4L2_CID_STATELESS_HEVC_DECODE_MODE,
|
|
|
|
.min = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
|
|
|
|
.max = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
|
|
|
|
.def = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
|
2021-06-03 19:49:59 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_HEVC_DECODER,
|
|
|
|
.cfg = {
|
2022-07-09 00:21:44 +08:00
|
|
|
.id = V4L2_CID_STATELESS_HEVC_START_CODE,
|
|
|
|
.min = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
|
|
|
|
.max = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
|
|
|
|
.def = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
|
2021-06-03 19:49:59 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_HEVC_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
|
|
|
|
.min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
|
|
|
|
.max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
|
|
|
|
.def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_HEVC_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
|
|
|
|
.min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
|
|
|
|
.max = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1,
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_HEVC_DECODER,
|
|
|
|
.cfg = {
|
2022-07-09 00:21:44 +08:00
|
|
|
.id = V4L2_CID_STATELESS_HEVC_SPS,
|
2023-02-20 18:48:46 +08:00
|
|
|
.ops = &hantro_hevc_ctrl_ops,
|
2021-06-03 19:49:59 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_HEVC_DECODER,
|
|
|
|
.cfg = {
|
2022-07-09 00:21:44 +08:00
|
|
|
.id = V4L2_CID_STATELESS_HEVC_PPS,
|
2021-06-03 19:49:59 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_HEVC_DECODER,
|
|
|
|
.cfg = {
|
2022-07-09 00:21:44 +08:00
|
|
|
.id = V4L2_CID_STATELESS_HEVC_DECODE_PARAMS,
|
2021-06-03 19:49:59 +08:00
|
|
|
},
|
2021-07-15 23:12:23 +08:00
|
|
|
}, {
|
|
|
|
.codec = HANTRO_HEVC_DECODER,
|
|
|
|
.cfg = {
|
2022-07-09 00:21:44 +08:00
|
|
|
.id = V4L2_CID_STATELESS_HEVC_SCALING_MATRIX,
|
2021-07-15 23:12:23 +08:00
|
|
|
},
|
2021-11-16 22:38:40 +08:00
|
|
|
}, {
|
|
|
|
.codec = HANTRO_VP9_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_STATELESS_VP9_FRAME,
|
2022-07-07 02:29:00 +08:00
|
|
|
.ops = &hantro_vp9_ctrl_ops,
|
2021-11-16 22:38:40 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_VP9_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_STATELESS_VP9_COMPRESSED_HDR,
|
|
|
|
},
|
2023-05-03 16:34:31 +08:00
|
|
|
}, {
|
|
|
|
.codec = HANTRO_AV1_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_STATELESS_AV1_FRAME,
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_AV1_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY,
|
|
|
|
.dims = { V4L2_AV1_MAX_TILE_COUNT },
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_AV1_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_STATELESS_AV1_SEQUENCE,
|
2023-05-03 16:34:32 +08:00
|
|
|
.ops = &hantro_av1_ctrl_ops,
|
2023-05-03 16:34:31 +08:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
.codec = HANTRO_AV1_DECODER,
|
|
|
|
.cfg = {
|
|
|
|
.id = V4L2_CID_STATELESS_AV1_FILM_GRAIN,
|
|
|
|
},
|
2019-05-29 01:02:28 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static int hantro_ctrls_setup(struct hantro_dev *vpu,
|
|
|
|
struct hantro_ctx *ctx,
|
|
|
|
int allowed_codecs)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
2019-05-29 01:02:28 +08:00
|
|
|
int i, num_ctrls = ARRAY_SIZE(controls);
|
|
|
|
|
|
|
|
v4l2_ctrl_handler_init(&ctx->ctrl_handler, num_ctrls);
|
|
|
|
|
|
|
|
for (i = 0; i < num_ctrls; i++) {
|
|
|
|
if (!(allowed_codecs & controls[i].codec))
|
|
|
|
continue;
|
|
|
|
|
2019-07-25 22:17:51 +08:00
|
|
|
v4l2_ctrl_new_custom(&ctx->ctrl_handler,
|
|
|
|
&controls[i].cfg, NULL);
|
2018-12-06 00:09:52 +08:00
|
|
|
if (ctx->ctrl_handler.error) {
|
2019-05-29 01:02:28 +08:00
|
|
|
vpu_err("Adding control (%d) failed %d\n",
|
2019-07-25 22:17:51 +08:00
|
|
|
controls[i].cfg.id,
|
2018-12-06 00:09:52 +08:00
|
|
|
ctx->ctrl_handler.error);
|
|
|
|
v4l2_ctrl_handler_free(&ctx->ctrl_handler);
|
|
|
|
return ctx->ctrl_handler.error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* V4L2 file operations.
|
|
|
|
*/
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static int hantro_open(struct file *filp)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_dev *vpu = video_drvdata(filp);
|
2018-12-06 00:09:52 +08:00
|
|
|
struct video_device *vdev = video_devdata(filp);
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_func *func = hantro_vdev_to_func(vdev);
|
|
|
|
struct hantro_ctx *ctx;
|
2019-05-29 01:02:28 +08:00
|
|
|
int allowed_codecs, ret;
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not need any extra locking here, because we operate only
|
|
|
|
* on local data here, except reading few fields from dev, which
|
|
|
|
* do not change through device's lifetime (which is guaranteed by
|
|
|
|
* reference on module from open()) and V4L2 internal objects (such
|
|
|
|
* as vdev and ctx->fh), which have proper locking done in respective
|
|
|
|
* helper functions used here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ctx->dev = vpu;
|
2019-05-29 01:02:27 +08:00
|
|
|
if (func->id == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
|
2019-06-12 17:39:06 +08:00
|
|
|
allowed_codecs = vpu->variant->codec & HANTRO_ENCODERS;
|
2020-07-01 21:16:04 +08:00
|
|
|
ctx->is_encoder = true;
|
2019-05-29 01:02:27 +08:00
|
|
|
} else if (func->id == MEDIA_ENT_F_PROC_VIDEO_DECODER) {
|
2019-06-12 17:39:06 +08:00
|
|
|
allowed_codecs = vpu->variant->codec & HANTRO_DECODERS;
|
2020-07-01 21:16:04 +08:00
|
|
|
ctx->is_encoder = false;
|
2019-05-29 01:02:27 +08:00
|
|
|
} else {
|
2019-09-05 18:25:54 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto err_ctx_free;
|
2019-05-29 01:02:27 +08:00
|
|
|
}
|
2019-09-05 18:25:54 +08:00
|
|
|
|
|
|
|
ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(vpu->m2m_dev, ctx, queue_init);
|
2018-12-06 00:09:52 +08:00
|
|
|
if (IS_ERR(ctx->fh.m2m_ctx)) {
|
|
|
|
ret = PTR_ERR(ctx->fh.m2m_ctx);
|
2019-09-05 18:25:54 +08:00
|
|
|
goto err_ctx_free;
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
v4l2_fh_init(&ctx->fh, vdev);
|
|
|
|
filp->private_data = &ctx->fh;
|
|
|
|
v4l2_fh_add(&ctx->fh);
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
hantro_reset_fmts(ctx);
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
ret = hantro_ctrls_setup(vpu, ctx, allowed_codecs);
|
2018-12-06 00:09:52 +08:00
|
|
|
if (ret) {
|
|
|
|
vpu_err("Failed to set up controls\n");
|
|
|
|
goto err_fh_free;
|
|
|
|
}
|
|
|
|
ctx->fh.ctrl_handler = &ctx->ctrl_handler;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_fh_free:
|
|
|
|
v4l2_fh_del(&ctx->fh);
|
|
|
|
v4l2_fh_exit(&ctx->fh);
|
2019-09-05 18:25:54 +08:00
|
|
|
err_ctx_free:
|
2018-12-06 00:09:52 +08:00
|
|
|
kfree(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static int hantro_release(struct file *filp)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_ctx *ctx =
|
|
|
|
container_of(filp->private_data, struct hantro_ctx, fh);
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* No need for extra locking because this was the last reference
|
|
|
|
* to this file.
|
|
|
|
*/
|
|
|
|
v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
|
|
|
|
v4l2_fh_del(&ctx->fh);
|
|
|
|
v4l2_fh_exit(&ctx->fh);
|
|
|
|
v4l2_ctrl_handler_free(&ctx->ctrl_handler);
|
|
|
|
kfree(ctx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static const struct v4l2_file_operations hantro_fops = {
|
2018-12-06 00:09:52 +08:00
|
|
|
.owner = THIS_MODULE,
|
2019-06-12 17:39:06 +08:00
|
|
|
.open = hantro_open,
|
|
|
|
.release = hantro_release,
|
2018-12-06 00:09:52 +08:00
|
|
|
.poll = v4l2_m2m_fop_poll,
|
|
|
|
.unlocked_ioctl = video_ioctl2,
|
|
|
|
.mmap = v4l2_m2m_fop_mmap,
|
|
|
|
};
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static const struct of_device_id of_hantro_match[] = {
|
|
|
|
#ifdef CONFIG_VIDEO_HANTRO_ROCKCHIP
|
2021-07-20 04:52:40 +08:00
|
|
|
{ .compatible = "rockchip,px30-vpu", .data = &px30_vpu_variant, },
|
2021-06-15 05:32:15 +08:00
|
|
|
{ .compatible = "rockchip,rk3036-vpu", .data = &rk3036_vpu_variant, },
|
2021-06-15 05:32:14 +08:00
|
|
|
{ .compatible = "rockchip,rk3066-vpu", .data = &rk3066_vpu_variant, },
|
2018-12-06 00:09:52 +08:00
|
|
|
{ .compatible = "rockchip,rk3288-vpu", .data = &rk3288_vpu_variant, },
|
2021-06-15 05:32:12 +08:00
|
|
|
{ .compatible = "rockchip,rk3328-vpu", .data = &rk3328_vpu_variant, },
|
|
|
|
{ .compatible = "rockchip,rk3399-vpu", .data = &rk3399_vpu_variant, },
|
2022-06-12 23:53:45 +08:00
|
|
|
{ .compatible = "rockchip,rk3568-vepu", .data = &rk3568_vepu_variant, },
|
2022-02-15 05:29:53 +08:00
|
|
|
{ .compatible = "rockchip,rk3568-vpu", .data = &rk3568_vpu_variant, },
|
2023-05-03 16:34:37 +08:00
|
|
|
{ .compatible = "rockchip,rk3588-av1-vpu", .data = &rk3588_vpu981_variant, },
|
2020-03-20 21:12:54 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_VIDEO_HANTRO_IMX8M
|
2022-01-26 01:11:27 +08:00
|
|
|
{ .compatible = "nxp,imx8mm-vpu-g1", .data = &imx8mm_vpu_g1_variant, },
|
2020-03-20 21:12:54 +08:00
|
|
|
{ .compatible = "nxp,imx8mq-vpu", .data = &imx8mq_vpu_variant, },
|
2022-01-26 01:11:23 +08:00
|
|
|
{ .compatible = "nxp,imx8mq-vpu-g1", .data = &imx8mq_vpu_g1_variant },
|
2021-06-03 19:50:04 +08:00
|
|
|
{ .compatible = "nxp,imx8mq-vpu-g2", .data = &imx8mq_vpu_g2_variant },
|
2021-04-01 22:43:35 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_VIDEO_HANTRO_SAMA5D4
|
|
|
|
{ .compatible = "microchip,sama5d4-vdec", .data = &sama5d4_vdec_variant, },
|
2021-11-30 02:26:32 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_VIDEO_HANTRO_SUNXI
|
|
|
|
{ .compatible = "allwinner,sun50i-h6-vpu-g2", .data = &sunxi_vpu_variant, },
|
2019-06-12 17:39:06 +08:00
|
|
|
#endif
|
2018-12-06 00:09:52 +08:00
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
2019-06-12 17:39:06 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, of_hantro_match);
|
|
|
|
|
|
|
|
static int hantro_register_entity(struct media_device *mdev,
|
|
|
|
struct media_entity *entity,
|
|
|
|
const char *entity_name,
|
|
|
|
struct media_pad *pads, int num_pads,
|
|
|
|
int function, struct video_device *vdev)
|
2019-05-29 01:02:21 +08:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
entity->obj_type = MEDIA_ENTITY_TYPE_BASE;
|
|
|
|
if (function == MEDIA_ENT_F_IO_V4L) {
|
|
|
|
entity->info.dev.major = VIDEO_MAJOR;
|
|
|
|
entity->info.dev.minor = vdev->minor;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = devm_kasprintf(mdev->dev, GFP_KERNEL, "%s-%s", vdev->name,
|
|
|
|
entity_name);
|
|
|
|
if (!name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
entity->name = name;
|
|
|
|
entity->function = function;
|
|
|
|
|
|
|
|
ret = media_entity_pads_init(entity, num_pads, pads);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = media_device_register_entity(mdev, entity);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static int hantro_attach_func(struct hantro_dev *vpu,
|
|
|
|
struct hantro_func *func)
|
2019-05-29 01:02:21 +08:00
|
|
|
{
|
|
|
|
struct media_device *mdev = &vpu->mdev;
|
|
|
|
struct media_link *link;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Create the three encoder entities with their pads */
|
|
|
|
func->source_pad.flags = MEDIA_PAD_FL_SOURCE;
|
2019-06-12 17:39:06 +08:00
|
|
|
ret = hantro_register_entity(mdev, &func->vdev.entity, "source",
|
|
|
|
&func->source_pad, 1, MEDIA_ENT_F_IO_V4L,
|
|
|
|
&func->vdev);
|
2019-05-29 01:02:21 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
func->proc_pads[0].flags = MEDIA_PAD_FL_SINK;
|
|
|
|
func->proc_pads[1].flags = MEDIA_PAD_FL_SOURCE;
|
2019-06-12 17:39:06 +08:00
|
|
|
ret = hantro_register_entity(mdev, &func->proc, "proc",
|
|
|
|
func->proc_pads, 2, func->id,
|
|
|
|
&func->vdev);
|
2019-05-29 01:02:21 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_rel_entity0;
|
|
|
|
|
|
|
|
func->sink_pad.flags = MEDIA_PAD_FL_SINK;
|
2019-06-12 17:39:06 +08:00
|
|
|
ret = hantro_register_entity(mdev, &func->sink, "sink",
|
|
|
|
&func->sink_pad, 1, MEDIA_ENT_F_IO_V4L,
|
|
|
|
&func->vdev);
|
2019-05-29 01:02:21 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_rel_entity1;
|
|
|
|
|
|
|
|
/* Connect the three entities */
|
2020-02-05 03:38:37 +08:00
|
|
|
ret = media_create_pad_link(&func->vdev.entity, 0, &func->proc, 0,
|
2019-05-29 01:02:21 +08:00
|
|
|
MEDIA_LNK_FL_IMMUTABLE |
|
|
|
|
MEDIA_LNK_FL_ENABLED);
|
|
|
|
if (ret)
|
|
|
|
goto err_rel_entity2;
|
|
|
|
|
2020-02-05 03:38:37 +08:00
|
|
|
ret = media_create_pad_link(&func->proc, 1, &func->sink, 0,
|
2019-05-29 01:02:21 +08:00
|
|
|
MEDIA_LNK_FL_IMMUTABLE |
|
|
|
|
MEDIA_LNK_FL_ENABLED);
|
|
|
|
if (ret)
|
|
|
|
goto err_rm_links0;
|
|
|
|
|
|
|
|
/* Create video interface */
|
|
|
|
func->intf_devnode = media_devnode_create(mdev, MEDIA_INTF_T_V4L_VIDEO,
|
|
|
|
0, VIDEO_MAJOR,
|
|
|
|
func->vdev.minor);
|
|
|
|
if (!func->intf_devnode) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_rm_links1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connect the two DMA engines to the interface */
|
|
|
|
link = media_create_intf_link(&func->vdev.entity,
|
|
|
|
&func->intf_devnode->intf,
|
|
|
|
MEDIA_LNK_FL_IMMUTABLE |
|
|
|
|
MEDIA_LNK_FL_ENABLED);
|
|
|
|
if (!link) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_rm_devnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
link = media_create_intf_link(&func->sink, &func->intf_devnode->intf,
|
|
|
|
MEDIA_LNK_FL_IMMUTABLE |
|
|
|
|
MEDIA_LNK_FL_ENABLED);
|
|
|
|
if (!link) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_rm_devnode;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_rm_devnode:
|
|
|
|
media_devnode_remove(func->intf_devnode);
|
|
|
|
|
|
|
|
err_rm_links1:
|
|
|
|
media_entity_remove_links(&func->sink);
|
|
|
|
|
|
|
|
err_rm_links0:
|
|
|
|
media_entity_remove_links(&func->proc);
|
|
|
|
media_entity_remove_links(&func->vdev.entity);
|
|
|
|
|
|
|
|
err_rel_entity2:
|
|
|
|
media_device_unregister_entity(&func->sink);
|
|
|
|
|
|
|
|
err_rel_entity1:
|
|
|
|
media_device_unregister_entity(&func->proc);
|
|
|
|
|
|
|
|
err_rel_entity0:
|
|
|
|
media_device_unregister_entity(&func->vdev.entity);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static void hantro_detach_func(struct hantro_func *func)
|
2019-05-29 01:02:21 +08:00
|
|
|
{
|
|
|
|
media_devnode_remove(func->intf_devnode);
|
|
|
|
media_entity_remove_links(&func->sink);
|
|
|
|
media_entity_remove_links(&func->proc);
|
|
|
|
media_entity_remove_links(&func->vdev.entity);
|
|
|
|
media_device_unregister_entity(&func->sink);
|
|
|
|
media_device_unregister_entity(&func->proc);
|
|
|
|
media_device_unregister_entity(&func->vdev.entity);
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
|
|
|
const struct of_device_id *match;
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_func *func;
|
2018-12-06 00:09:52 +08:00
|
|
|
struct video_device *vfd;
|
2019-05-29 01:02:21 +08:00
|
|
|
int ret;
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
match = of_match_node(of_hantro_match, vpu->dev->of_node);
|
2019-05-29 01:02:21 +08:00
|
|
|
func = devm_kzalloc(vpu->dev, sizeof(*func), GFP_KERNEL);
|
|
|
|
if (!func) {
|
2018-12-06 00:09:52 +08:00
|
|
|
v4l2_err(&vpu->v4l2_dev, "Failed to allocate video device\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-05-29 01:02:27 +08:00
|
|
|
func->id = funcid;
|
2019-05-29 01:02:21 +08:00
|
|
|
|
|
|
|
vfd = &func->vdev;
|
2019-06-12 17:39:06 +08:00
|
|
|
vfd->fops = &hantro_fops;
|
2019-05-29 01:02:21 +08:00
|
|
|
vfd->release = video_device_release_empty;
|
2018-12-06 00:09:52 +08:00
|
|
|
vfd->lock = &vpu->vpu_mutex;
|
|
|
|
vfd->v4l2_dev = &vpu->v4l2_dev;
|
|
|
|
vfd->vfl_dir = VFL_DIR_M2M;
|
|
|
|
vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
|
2019-06-12 17:39:06 +08:00
|
|
|
vfd->ioctl_ops = &hantro_ioctl_ops;
|
2019-05-29 01:02:27 +08:00
|
|
|
snprintf(vfd->name, sizeof(vfd->name), "%s-%s", match->compatible,
|
|
|
|
funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ? "enc" : "dec");
|
|
|
|
|
2022-03-31 17:16:28 +08:00
|
|
|
if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
|
2019-05-29 01:02:27 +08:00
|
|
|
vpu->encoder = func;
|
2022-03-31 17:16:28 +08:00
|
|
|
} else {
|
2019-05-29 01:02:27 +08:00
|
|
|
vpu->decoder = func;
|
2022-03-31 17:16:28 +08:00
|
|
|
v4l2_disable_ioctl(vfd, VIDIOC_TRY_ENCODER_CMD);
|
|
|
|
v4l2_disable_ioctl(vfd, VIDIOC_ENCODER_CMD);
|
|
|
|
}
|
2019-05-29 01:02:21 +08:00
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
video_set_drvdata(vfd, vpu);
|
|
|
|
|
2020-02-03 19:41:12 +08:00
|
|
|
ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
|
2018-12-06 00:09:52 +08:00
|
|
|
if (ret) {
|
|
|
|
v4l2_err(&vpu->v4l2_dev, "Failed to register video device\n");
|
2019-05-29 01:02:21 +08:00
|
|
|
return ret;
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
ret = hantro_attach_func(vpu, func);
|
2018-12-06 00:09:52 +08:00
|
|
|
if (ret) {
|
2019-05-29 01:02:21 +08:00
|
|
|
v4l2_err(&vpu->v4l2_dev,
|
|
|
|
"Failed to attach functionality to the media device\n");
|
|
|
|
goto err_unreg_dev;
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
2019-05-29 01:02:21 +08:00
|
|
|
|
2019-06-12 17:39:07 +08:00
|
|
|
v4l2_info(&vpu->v4l2_dev, "registered %s as /dev/video%d\n", vfd->name,
|
|
|
|
vfd->num);
|
2019-05-29 01:02:21 +08:00
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
return 0;
|
|
|
|
|
2019-05-29 01:02:21 +08:00
|
|
|
err_unreg_dev:
|
2018-12-06 00:09:52 +08:00
|
|
|
video_unregister_device(vfd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static int hantro_add_enc_func(struct hantro_dev *vpu)
|
2019-05-29 01:02:27 +08:00
|
|
|
{
|
|
|
|
if (!vpu->variant->enc_fmts)
|
|
|
|
return 0;
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
return hantro_add_func(vpu, MEDIA_ENT_F_PROC_VIDEO_ENCODER);
|
2019-05-29 01:02:27 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static int hantro_add_dec_func(struct hantro_dev *vpu)
|
2019-05-29 01:02:27 +08:00
|
|
|
{
|
|
|
|
if (!vpu->variant->dec_fmts)
|
|
|
|
return 0;
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
return hantro_add_func(vpu, MEDIA_ENT_F_PROC_VIDEO_DECODER);
|
2019-05-29 01:02:27 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static void hantro_remove_func(struct hantro_dev *vpu,
|
|
|
|
unsigned int funcid)
|
2019-05-29 01:02:21 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_func *func;
|
2019-05-29 01:02:27 +08:00
|
|
|
|
|
|
|
if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER)
|
|
|
|
func = vpu->encoder;
|
|
|
|
else
|
|
|
|
func = vpu->decoder;
|
2019-05-29 01:02:21 +08:00
|
|
|
|
|
|
|
if (!func)
|
|
|
|
return;
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
hantro_detach_func(func);
|
2019-05-29 01:02:21 +08:00
|
|
|
video_unregister_device(&func->vdev);
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static void hantro_remove_enc_func(struct hantro_dev *vpu)
|
2019-05-29 01:02:27 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
hantro_remove_func(vpu, MEDIA_ENT_F_PROC_VIDEO_ENCODER);
|
2019-05-29 01:02:27 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static void hantro_remove_dec_func(struct hantro_dev *vpu)
|
2019-05-29 01:02:27 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
hantro_remove_func(vpu, MEDIA_ENT_F_PROC_VIDEO_DECODER);
|
2019-05-29 01:02:27 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static const struct media_device_ops hantro_m2m_media_ops = {
|
2019-05-29 01:02:22 +08:00
|
|
|
.req_validate = vb2_request_validate,
|
|
|
|
.req_queue = v4l2_m2m_request_queue,
|
|
|
|
};
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static int hantro_probe(struct platform_device *pdev)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
|
|
|
const struct of_device_id *match;
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_dev *vpu;
|
2018-12-06 00:09:52 +08:00
|
|
|
struct resource *res;
|
2019-06-12 17:39:10 +08:00
|
|
|
int num_bases;
|
2018-12-06 00:09:52 +08:00
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
vpu = devm_kzalloc(&pdev->dev, sizeof(*vpu), GFP_KERNEL);
|
|
|
|
if (!vpu)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
vpu->dev = &pdev->dev;
|
|
|
|
vpu->pdev = pdev;
|
|
|
|
mutex_init(&vpu->vpu_mutex);
|
|
|
|
spin_lock_init(&vpu->irqlock);
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
match = of_match_node(of_hantro_match, pdev->dev.of_node);
|
2018-12-06 00:09:52 +08:00
|
|
|
vpu->variant = match->data;
|
|
|
|
|
2022-01-26 01:11:23 +08:00
|
|
|
/*
|
|
|
|
* Support for nxp,imx8mq-vpu is kept for backwards compatibility
|
|
|
|
* but it's deprecated. Please update your DTS file to use
|
|
|
|
* nxp,imx8mq-vpu-g1 or nxp,imx8mq-vpu-g2 instead.
|
|
|
|
*/
|
|
|
|
if (of_device_is_compatible(pdev->dev.of_node, "nxp,imx8mq-vpu"))
|
|
|
|
dev_warn(&pdev->dev, "%s compatible is deprecated\n",
|
|
|
|
match->compatible);
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
INIT_DELAYED_WORK(&vpu->watchdog_work, hantro_watchdog);
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2019-06-12 17:39:12 +08:00
|
|
|
vpu->clocks = devm_kcalloc(&pdev->dev, vpu->variant->num_clocks,
|
|
|
|
sizeof(*vpu->clocks), GFP_KERNEL);
|
|
|
|
if (!vpu->clocks)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2021-04-01 22:43:33 +08:00
|
|
|
if (vpu->variant->num_clocks > 1) {
|
|
|
|
for (i = 0; i < vpu->variant->num_clocks; i++)
|
|
|
|
vpu->clocks[i].id = vpu->variant->clk_names[i];
|
|
|
|
|
|
|
|
ret = devm_clk_bulk_get(&pdev->dev, vpu->variant->num_clocks,
|
|
|
|
vpu->clocks);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If the driver has a single clk, chances are there will be no
|
|
|
|
* actual name in the DT bindings.
|
|
|
|
*/
|
|
|
|
vpu->clocks[0].clk = devm_clk_get(&pdev->dev, NULL);
|
2021-05-21 00:02:49 +08:00
|
|
|
if (IS_ERR(vpu->clocks[0].clk))
|
|
|
|
return PTR_ERR(vpu->clocks[0].clk);
|
2021-04-01 22:43:33 +08:00
|
|
|
}
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2023-03-24 11:07:31 +08:00
|
|
|
vpu->resets = devm_reset_control_array_get_optional_exclusive(&pdev->dev);
|
2021-11-30 02:26:26 +08:00
|
|
|
if (IS_ERR(vpu->resets))
|
|
|
|
return PTR_ERR(vpu->resets);
|
|
|
|
|
2019-06-12 17:39:10 +08:00
|
|
|
num_bases = vpu->variant->num_regs ?: 1;
|
|
|
|
vpu->reg_bases = devm_kcalloc(&pdev->dev, num_bases,
|
|
|
|
sizeof(*vpu->reg_bases), GFP_KERNEL);
|
|
|
|
if (!vpu->reg_bases)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < num_bases; i++) {
|
|
|
|
res = vpu->variant->reg_names ?
|
|
|
|
platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM,
|
|
|
|
vpu->variant->reg_names[i]) :
|
|
|
|
platform_get_resource(vpu->pdev, IORESOURCE_MEM, 0);
|
|
|
|
vpu->reg_bases[i] = devm_ioremap_resource(vpu->dev, res);
|
|
|
|
if (IS_ERR(vpu->reg_bases[i]))
|
|
|
|
return PTR_ERR(vpu->reg_bases[i]);
|
|
|
|
}
|
|
|
|
vpu->enc_base = vpu->reg_bases[0] + vpu->variant->enc_offset;
|
|
|
|
vpu->dec_base = vpu->reg_bases[0] + vpu->variant->dec_offset;
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2021-11-16 22:38:39 +08:00
|
|
|
/**
|
|
|
|
* TODO: Eventually allow taking advantage of full 64-bit address space.
|
|
|
|
* Until then we assume the MSB portion of buffers' base addresses is
|
|
|
|
* always 0 due to this masking operation.
|
|
|
|
*/
|
2018-12-06 00:09:52 +08:00
|
|
|
ret = dma_set_coherent_mask(vpu->dev, DMA_BIT_MASK(32));
|
|
|
|
if (ret) {
|
|
|
|
dev_err(vpu->dev, "Could not set DMA coherent mask.\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2019-07-25 22:17:50 +08:00
|
|
|
vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2019-06-12 17:39:09 +08:00
|
|
|
for (i = 0; i < vpu->variant->num_irqs; i++) {
|
2021-04-01 22:43:33 +08:00
|
|
|
const char *irq_name;
|
2019-05-29 01:02:27 +08:00
|
|
|
int irq;
|
|
|
|
|
2019-06-12 17:39:09 +08:00
|
|
|
if (!vpu->variant->irqs[i].handler)
|
|
|
|
continue;
|
2018-12-06 00:09:52 +08:00
|
|
|
|
2021-08-06 03:04:16 +08:00
|
|
|
if (vpu->variant->num_irqs > 1) {
|
2021-04-01 22:43:33 +08:00
|
|
|
irq_name = vpu->variant->irqs[i].name;
|
|
|
|
irq = platform_get_irq_byname(vpu->pdev, irq_name);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If the driver has a single IRQ, chances are there
|
|
|
|
* will be no actual name in the DT bindings.
|
|
|
|
*/
|
|
|
|
irq_name = "default";
|
|
|
|
irq = platform_get_irq(vpu->pdev, 0);
|
|
|
|
}
|
2019-07-31 02:15:42 +08:00
|
|
|
if (irq <= 0)
|
2018-12-06 00:09:52 +08:00
|
|
|
return -ENXIO;
|
|
|
|
|
2019-06-12 17:39:09 +08:00
|
|
|
ret = devm_request_irq(vpu->dev, irq,
|
|
|
|
vpu->variant->irqs[i].handler, 0,
|
|
|
|
dev_name(vpu->dev), vpu);
|
2018-12-06 00:09:52 +08:00
|
|
|
if (ret) {
|
2019-06-12 17:39:09 +08:00
|
|
|
dev_err(vpu->dev, "Could not request %s IRQ.\n",
|
|
|
|
irq_name);
|
2018-12-06 00:09:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-20 04:52:34 +08:00
|
|
|
if (vpu->variant->init) {
|
|
|
|
ret = vpu->variant->init(vpu);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Failed to init VPU hardware\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pm_runtime_set_autosuspend_delay(vpu->dev, 100);
|
|
|
|
pm_runtime_use_autosuspend(vpu->dev);
|
|
|
|
pm_runtime_enable(vpu->dev);
|
|
|
|
|
2021-11-30 02:26:26 +08:00
|
|
|
ret = reset_control_deassert(vpu->resets);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Failed to deassert resets\n");
|
|
|
|
goto err_pm_disable;
|
|
|
|
}
|
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
ret = clk_bulk_prepare(vpu->variant->num_clocks, vpu->clocks);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Failed to prepare clocks\n");
|
2021-11-30 02:26:26 +08:00
|
|
|
goto err_rst_assert;
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = v4l2_device_register(&pdev->dev, &vpu->v4l2_dev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Failed to register v4l2 device\n");
|
|
|
|
goto err_clk_unprepare;
|
|
|
|
}
|
|
|
|
platform_set_drvdata(pdev, vpu);
|
|
|
|
|
|
|
|
vpu->m2m_dev = v4l2_m2m_init(&vpu_m2m_ops);
|
|
|
|
if (IS_ERR(vpu->m2m_dev)) {
|
|
|
|
v4l2_err(&vpu->v4l2_dev, "Failed to init mem2mem device\n");
|
|
|
|
ret = PTR_ERR(vpu->m2m_dev);
|
|
|
|
goto err_v4l2_unreg;
|
|
|
|
}
|
|
|
|
|
|
|
|
vpu->mdev.dev = vpu->dev;
|
2019-03-29 23:28:45 +08:00
|
|
|
strscpy(vpu->mdev.model, DRIVER_NAME, sizeof(vpu->mdev.model));
|
2018-12-06 00:09:52 +08:00
|
|
|
media_device_init(&vpu->mdev);
|
2019-06-12 17:39:06 +08:00
|
|
|
vpu->mdev.ops = &hantro_m2m_media_ops;
|
2018-12-06 00:09:52 +08:00
|
|
|
vpu->v4l2_dev.mdev = &vpu->mdev;
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
ret = hantro_add_enc_func(vpu);
|
2018-12-06 00:09:52 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Failed to register encoder\n");
|
|
|
|
goto err_m2m_rel;
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
ret = hantro_add_dec_func(vpu);
|
2019-05-29 01:02:27 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Failed to register decoder\n");
|
|
|
|
goto err_rm_enc_func;
|
|
|
|
}
|
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
ret = media_device_register(&vpu->mdev);
|
|
|
|
if (ret) {
|
|
|
|
v4l2_err(&vpu->v4l2_dev, "Failed to register mem2mem media device\n");
|
2019-05-29 01:02:27 +08:00
|
|
|
goto err_rm_dec_func;
|
2018-12-06 00:09:52 +08:00
|
|
|
}
|
2019-05-29 01:02:21 +08:00
|
|
|
|
2018-12-06 00:09:52 +08:00
|
|
|
return 0;
|
2019-05-29 01:02:21 +08:00
|
|
|
|
2019-05-29 01:02:27 +08:00
|
|
|
err_rm_dec_func:
|
2019-06-12 17:39:06 +08:00
|
|
|
hantro_remove_dec_func(vpu);
|
2019-05-29 01:02:21 +08:00
|
|
|
err_rm_enc_func:
|
2019-06-12 17:39:06 +08:00
|
|
|
hantro_remove_enc_func(vpu);
|
2018-12-06 00:09:52 +08:00
|
|
|
err_m2m_rel:
|
2019-04-25 15:12:31 +08:00
|
|
|
media_device_cleanup(&vpu->mdev);
|
2018-12-06 00:09:52 +08:00
|
|
|
v4l2_m2m_release(vpu->m2m_dev);
|
|
|
|
err_v4l2_unreg:
|
|
|
|
v4l2_device_unregister(&vpu->v4l2_dev);
|
|
|
|
err_clk_unprepare:
|
|
|
|
clk_bulk_unprepare(vpu->variant->num_clocks, vpu->clocks);
|
2021-11-30 02:26:26 +08:00
|
|
|
err_rst_assert:
|
|
|
|
reset_control_assert(vpu->resets);
|
2021-11-30 02:26:25 +08:00
|
|
|
err_pm_disable:
|
2019-04-25 15:12:28 +08:00
|
|
|
pm_runtime_dont_use_autosuspend(vpu->dev);
|
2018-12-06 00:09:52 +08:00
|
|
|
pm_runtime_disable(vpu->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-26 22:31:59 +08:00
|
|
|
static void hantro_remove(struct platform_device *pdev)
|
2018-12-06 00:09:52 +08:00
|
|
|
{
|
2019-06-12 17:39:06 +08:00
|
|
|
struct hantro_dev *vpu = platform_get_drvdata(pdev);
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
v4l2_info(&vpu->v4l2_dev, "Removing %s\n", pdev->name);
|
|
|
|
|
|
|
|
media_device_unregister(&vpu->mdev);
|
2019-06-12 17:39:06 +08:00
|
|
|
hantro_remove_dec_func(vpu);
|
|
|
|
hantro_remove_enc_func(vpu);
|
2019-04-25 15:12:31 +08:00
|
|
|
media_device_cleanup(&vpu->mdev);
|
|
|
|
v4l2_m2m_release(vpu->m2m_dev);
|
2018-12-06 00:09:52 +08:00
|
|
|
v4l2_device_unregister(&vpu->v4l2_dev);
|
|
|
|
clk_bulk_unprepare(vpu->variant->num_clocks, vpu->clocks);
|
2021-11-30 02:26:26 +08:00
|
|
|
reset_control_assert(vpu->resets);
|
2019-04-25 15:12:28 +08:00
|
|
|
pm_runtime_dont_use_autosuspend(vpu->dev);
|
2018-12-06 00:09:52 +08:00
|
|
|
pm_runtime_disable(vpu->dev);
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:39:08 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int hantro_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct hantro_dev *vpu = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
if (vpu->variant->runtime_resume)
|
|
|
|
return vpu->variant->runtime_resume(vpu);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static const struct dev_pm_ops hantro_pm_ops = {
|
2018-12-06 00:09:52 +08:00
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
|
|
|
|
pm_runtime_force_resume)
|
2019-06-12 17:39:08 +08:00
|
|
|
SET_RUNTIME_PM_OPS(NULL, hantro_runtime_resume, NULL)
|
2018-12-06 00:09:52 +08:00
|
|
|
};
|
|
|
|
|
2019-06-12 17:39:06 +08:00
|
|
|
static struct platform_driver hantro_driver = {
|
|
|
|
.probe = hantro_probe,
|
2023-03-26 22:31:59 +08:00
|
|
|
.remove_new = hantro_remove,
|
2018-12-06 00:09:52 +08:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
2019-06-12 17:39:06 +08:00
|
|
|
.of_match_table = of_match_ptr(of_hantro_match),
|
|
|
|
.pm = &hantro_pm_ops,
|
2018-12-06 00:09:52 +08:00
|
|
|
},
|
|
|
|
};
|
2019-06-12 17:39:06 +08:00
|
|
|
module_platform_driver(hantro_driver);
|
2018-12-06 00:09:52 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_AUTHOR("Alpha Lin <Alpha.Lin@Rock-Chips.com>");
|
|
|
|
MODULE_AUTHOR("Tomasz Figa <tfiga@chromium.org>");
|
|
|
|
MODULE_AUTHOR("Ezequiel Garcia <ezequiel@collabora.com>");
|
2019-06-12 17:39:06 +08:00
|
|
|
MODULE_DESCRIPTION("Hantro VPU codec driver");
|