Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1c1
- < // SPDX-License-Identifier: GPL-2.0
- ---
- > /* SPDX-License-Identifier: GPL-2.0 */
- 3c3
- < * Rockchip Video Decoder driver
- ---
- > * Apple Video Decoder driver
- 5c5
- < * Copyright (C) 2019 Collabora, Ltd.
- ---
- > * Copyright The Asahi Linux Contributors
- 6a7,8
- > * Based on rkvdec driver by Collabora, Ltd.
- > * Copyright (C) 2019 Collabora, Ltd.
- 12,19d13
- < #include <linux/clk.h>
- < #include <linux/interrupt.h>
- < #include <linux/iommu.h>
- < #include <linux/module.h>
- < #include <linux/of.h>
- < #include <linux/of_device.h>
- < #include <linux/platform_device.h>
- < #include <linux/pm.h>
- 21,23c15
- < #include <linux/slab.h>
- < #include <linux/videodev2.h>
- < #include <linux/workqueue.h>
- ---
- >
- 26,27d17
- < #include <media/videobuf2-core.h>
- < #include <media/videobuf2-vmalloc.h>
- 29d18
- < #include "rkvdec-regs.h"
- 34,35c23
- < return fmt1 == fmt2 || fmt2 == RKVDEC_IMG_FMT_ANY ||
- < fmt1 == RKVDEC_IMG_FMT_ANY;
- ---
- > return fmt1 == fmt2 || fmt2 == AVD_IMG_FMT_ANY || fmt1 == AVD_IMG_FMT_ANY;
- 40c28
- < if (image_fmt == RKVDEC_IMG_FMT_ANY)
- ---
- > if (image_fmt == AVD_IMG_FMT_ANY)
- 84,85c72,75
- < pix_mp->plane_fmt[0].sizeimage +=
- < 128 * DIV_ROUND_UP(pix_mp->width, 16) * DIV_ROUND_UP(pix_mp->height, 16);
- ---
- > fill_rvra(&ctx->rvra, ctx->image_fmt, pix_mp->width, pix_mp->height);
- > pix_mp->plane_fmt[0].sizeimage += ctx->rvra.size;
- > if (ctx->coded_fmt_desc->ops->adjust_decoded_fmt)
- > ctx->coded_fmt_desc->ops->adjust_decoded_fmt(ctx, pix_mp);
- 99c89
- < static void rkvdec_reset_decoded_fmt(struct rkvdec_ctx *ctx) {
- ---
- > void rkvdec_reset_decoded_fmt(struct rkvdec_ctx *ctx) {
- 146c136
- < static const struct v4l2_ctrl_ops rkvdec_ctrl_ops = {
- ---
- > const struct v4l2_ctrl_ops rkvdec_ctrl_ops = {
- 173,175c163,165
- < .cfg.min = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
- < .cfg.max = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
- < .cfg.def = V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
- ---
- > .cfg.min = V4L2_STATELESS_HEVC_DECODE_MODE_SLICE_BASED,
- > .cfg.max = V4L2_STATELESS_HEVC_DECODE_MODE_SLICE_BASED,
- > .cfg.def = V4L2_STATELESS_HEVC_DECODE_MODE_SLICE_BASED,
- 179,181c169,171
- < .cfg.min = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
- < .cfg.def = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
- < .cfg.max = V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
- ---
- > .cfg.min = V4L2_STATELESS_HEVC_START_CODE_NONE,
- > .cfg.def = V4L2_STATELESS_HEVC_START_CODE_NONE,
- > .cfg.max = V4L2_STATELESS_HEVC_START_CODE_NONE,
- 204c194
- < .image_fmt = RKVDEC_IMG_FMT_420_8BIT,
- ---
- > .image_fmt = AVD_IMG_FMT_420_8BIT,
- 208c198
- < .image_fmt = RKVDEC_IMG_FMT_420_10BIT,
- ---
- > .image_fmt = AVD_IMG_FMT_420_10BIT,
- 221a212
- > .cfg.ops = &rkvdec_ctrl_ops,
- 226a218,223
- > .cfg.id = V4L2_CID_STATELESS_H264_PRED_WEIGHTS,
- > },
- > {
- > .cfg.id = V4L2_CID_STATELESS_H264_SLICE_PARAMS,
- > },
- > {
- 228,230c225,227
- < .cfg.min = V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED,
- < .cfg.max = V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED,
- < .cfg.def = V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED,
- ---
- > .cfg.min = V4L2_STATELESS_H264_DECODE_MODE_SLICE_BASED,
- > .cfg.max = V4L2_STATELESS_H264_DECODE_MODE_SLICE_BASED,
- > .cfg.def = V4L2_STATELESS_H264_DECODE_MODE_SLICE_BASED,
- 234,236c231,234
- < .cfg.min = V4L2_STATELESS_H264_START_CODE_ANNEX_B,
- < .cfg.def = V4L2_STATELESS_H264_START_CODE_ANNEX_B,
- < .cfg.max = V4L2_STATELESS_H264_START_CODE_ANNEX_B,
- ---
- > .cfg.min = V4L2_STATELESS_H264_START_CODE_NONE,
- > .cfg.max = V4L2_STATELESS_H264_START_CODE_NONE,
- > .cfg.def = V4L2_STATELESS_H264_START_CODE_NONE,
- > /* annex b is also possibly but a bit more painfull */
- 262c260
- < .image_fmt = RKVDEC_IMG_FMT_420_8BIT,
- ---
- > .image_fmt = AVD_IMG_FMT_420_8BIT,
- 265,266c263,264
- < .fourcc = V4L2_PIX_FMT_NV15,
- < .image_fmt = RKVDEC_IMG_FMT_420_10BIT,
- ---
- > .fourcc = V4L2_PIX_FMT_P010,
- > .image_fmt = AVD_IMG_FMT_420_10BIT,
- 270c268
- < .image_fmt = RKVDEC_IMG_FMT_422_8BIT,
- ---
- > .image_fmt = AVD_IMG_FMT_422_8BIT,
- 273,274c271,273
- < .fourcc = V4L2_PIX_FMT_NV20,
- < .image_fmt = RKVDEC_IMG_FMT_422_10BIT,
- ---
- > /* TODO: missing P210 */
- > .fourcc = V4L2_PIX_FMT_P010,
- > .image_fmt = AVD_IMG_FMT_422_10BIT,
- 301c300
- < .image_fmt = RKVDEC_IMG_FMT_420_8BIT,
- ---
- > .image_fmt = AVD_IMG_FMT_420_8BIT,
- 312c311
- < .step_width = 64,
- ---
- > .step_width = 16,
- 314c313
- < .max_height = 2304,
- ---
- > .max_height = 4096,
- 319a319
- > .subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF,
- 321c321
- < .capability = RKVDEC_CAPABILITY_HEVC,
- ---
- > .capability = AVD_CAPABILITY_HEVC,
- 330,331c330,331
- < .min_height = 48,
- < .max_height = 2560,
- ---
- > .min_height = 64,
- > .max_height = 4096,
- 339c339
- < .capability = RKVDEC_CAPABILITY_H264,
- ---
- > .capability = AVD_CAPABILITY_H264,
- 347c347
- < .step_width = 64,
- ---
- > .step_width = 16,
- 349,350c349,350
- < .max_height = 2304,
- < .step_height = 64,
- ---
- > .max_height = 4096,
- > .step_height = 16,
- 356c356
- < .capability = RKVDEC_CAPABILITY_VP9,
- ---
- > .capability = AVD_CAPABILITY_VP9,
- 360c360,361
- < return (ctx->dev->variant->capabilities & capability) == capability;
- ---
- > return capability == AVD_CAPABILITY_H264;
- > /* return (ctx->dev->variant->capabilities & capability) == capability; */
- 392c393
- < static void rkvdec_reset_coded_fmt(struct rkvdec_ctx *ctx) {
- ---
- > void rkvdec_reset_coded_fmt(struct rkvdec_ctx *ctx) {
- 402,403c403,406
- < if (ctx->coded_fmt_desc->ops->adjust_fmt)
- < ctx->coded_fmt_desc->ops->adjust_fmt(ctx, f);
- ---
- > f->fmt.pix_mp.num_planes = 1;
- > if (!f->fmt.pix_mp.plane_fmt[0].sizeimage)
- > f->fmt.pix_mp.plane_fmt[0].sizeimage =
- > f->fmt.pix_mp.width * f->fmt.pix_mp.height;
- 408c411
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 444c447
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 453c456,457
- < if (WARN_ON(!coded_desc))
- ---
- > if (WARN_ON(!coded_desc)) {
- > dev_err(ctx->dev->dev, "no coded desc!");
- 454a459
- > }
- 474c479
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 490,496c495,496
- < if (desc->ops->adjust_fmt) {
- < int ret;
- <
- < ret = desc->ops->adjust_fmt(ctx, f);
- < if (ret)
- < return ret;
- < }
- ---
- > if (!pix_mp->plane_fmt[0].sizeimage)
- > pix_mp->plane_fmt[0].sizeimage = pix_mp->width * f->fmt.pix_mp.height;
- 503c503
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 522c522
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 568c568
- < ctx->image_fmt = RKVDEC_IMG_FMT_ANY;
- ---
- > ctx->image_fmt = AVD_IMG_FMT_ANY;
- 586c586
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 594c594
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 602c602
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 615c615
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(file);
- ---
- > struct rkvdec_ctx *ctx = file_to_ctx(file);
- 626c626
- < static const struct v4l2_ioctl_ops rkvdec_ioctl_ops = {
- ---
- > const struct v4l2_ioctl_ops rkvdec_ioctl_ops = {
- 791c791
- < static const struct vb2_ops rkvdec_queue_ops = {
- ---
- > const struct vb2_ops rkvdec_queue_ops = {
- 801,819c801,802
- < static int rkvdec_request_validate(struct media_request *req) {
- < unsigned int count;
- <
- < count = vb2_request_buffer_cnt(req);
- < if (!count)
- < return -ENOENT;
- < else if (count > 1)
- < return -EINVAL;
- <
- < return vb2_request_validate(req);
- < }
- <
- < static const struct media_device_ops rkvdec_media_ops = {
- < .req_validate = rkvdec_request_validate,
- < .req_queue = v4l2_m2m_request_queue,
- < };
- <
- < static void rkvdec_job_finish_no_pm(struct rkvdec_ctx *ctx,
- < enum vb2_buffer_state result) {
- ---
- > void rkvdec_job_finish_no_pm(struct rkvdec_ctx *ctx,
- > enum vb2_buffer_state result) {
- 831,832c814
- < static void rkvdec_job_finish(struct rkvdec_ctx *ctx,
- < enum vb2_buffer_state result) {
- ---
- > void rkvdec_job_finish(struct rkvdec_ctx *ctx, enum vb2_buffer_state result) {
- 862,940d843
- < void rkvdec_quirks_disable_qos(struct rkvdec_ctx *ctx) {
- < struct rkvdec_dev *rkvdec = ctx->dev;
- < u32 reg;
- <
- < /* Set undocumented swreg_block_gating_e field */
- < reg = readl(rkvdec->regs + RKVDEC_REG_QOS_CTRL);
- < reg &= GENMASK(31, 16);
- < reg |= 0xEFFF;
- < writel(reg, rkvdec->regs + RKVDEC_REG_QOS_CTRL);
- < }
- <
- < static void rkvdec_device_run(void *priv) {
- < struct rkvdec_ctx *ctx = priv;
- < struct rkvdec_dev *rkvdec = ctx->dev;
- < const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc;
- < int ret;
- <
- < if (WARN_ON(!desc))
- < return;
- <
- < ret = pm_runtime_resume_and_get(rkvdec->dev);
- < if (ret < 0) {
- < rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
- < return;
- < }
- <
- < ret = desc->ops->run(ctx);
- < if (ret)
- < rkvdec_job_finish(ctx, VB2_BUF_STATE_ERROR);
- < }
- <
- < static const struct v4l2_m2m_ops rkvdec_m2m_ops = {
- < .device_run = rkvdec_device_run,
- < };
- <
- < static int rkvdec_queue_init(void *priv, struct vb2_queue *src_vq,
- < struct vb2_queue *dst_vq) {
- < struct rkvdec_ctx *ctx = priv;
- < struct rkvdec_dev *rkvdec = ctx->dev;
- < int ret;
- <
- < src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
- < src_vq->io_modes = VB2_MMAP | VB2_DMABUF;
- < src_vq->drv_priv = ctx;
- < src_vq->ops = &rkvdec_queue_ops;
- < 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 = &rkvdec->vdev_lock;
- < src_vq->dev = rkvdec->v4l2_dev.dev;
- < src_vq->supports_requests = true;
- < src_vq->requires_requests = true;
- <
- < ret = vb2_queue_init(src_vq);
- < if (ret)
- < return ret;
- <
- < dst_vq->bidirectional = true;
- < dst_vq->mem_ops = &vb2_dma_contig_memops;
- < dst_vq->dma_attrs = DMA_ATTR_ALLOC_SINGLE_PAGES | DMA_ATTR_NO_KERNEL_MAPPING;
- < dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
- < dst_vq->io_modes = VB2_MMAP | VB2_DMABUF;
- < dst_vq->drv_priv = ctx;
- < dst_vq->ops = &rkvdec_queue_ops;
- < dst_vq->buf_struct_size = sizeof(struct rkvdec_decoded_buffer);
- < dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
- < dst_vq->lock = &rkvdec->vdev_lock;
- < dst_vq->dev = rkvdec->v4l2_dev.dev;
- <
- < return vb2_queue_init(dst_vq);
- < }
- <
- 956c859
- < static int rkvdec_init_ctrls(struct rkvdec_ctx *ctx) {
- ---
- > int rkvdec_init_ctrls(struct rkvdec_ctx *ctx) {
- 985,1339d887
- <
- < static int rkvdec_open(struct file *filp) {
- < struct rkvdec_dev *rkvdec = video_drvdata(filp);
- < struct rkvdec_ctx *ctx;
- < int ret;
- <
- < ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
- < if (!ctx)
- < return -ENOMEM;
- <
- < ctx->dev = rkvdec;
- < rkvdec_reset_coded_fmt(ctx);
- < rkvdec_reset_decoded_fmt(ctx);
- < v4l2_fh_init(&ctx->fh, video_devdata(filp));
- <
- < ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(rkvdec->m2m_dev, ctx, rkvdec_queue_init);
- < if (IS_ERR(ctx->fh.m2m_ctx)) {
- < ret = PTR_ERR(ctx->fh.m2m_ctx);
- < goto err_free_ctx;
- < }
- <
- < ret = rkvdec_init_ctrls(ctx);
- < if (ret)
- < goto err_cleanup_m2m_ctx;
- <
- < v4l2_fh_add(&ctx->fh, filp);
- <
- < return 0;
- <
- < err_cleanup_m2m_ctx:
- < v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
- <
- < err_free_ctx:
- < kfree(ctx);
- < return ret;
- < }
- <
- < static int rkvdec_release(struct file *filp) {
- < struct rkvdec_ctx *ctx = file_to_rkvdec_ctx(filp);
- <
- < v4l2_fh_del(&ctx->fh, filp);
- < v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
- < v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
- < v4l2_fh_exit(&ctx->fh);
- < kfree(ctx);
- <
- < return 0;
- < }
- <
- < static const struct v4l2_file_operations rkvdec_fops = {
- < .owner = THIS_MODULE,
- < .open = rkvdec_open,
- < .release = rkvdec_release,
- < .poll = v4l2_m2m_fop_poll,
- < .unlocked_ioctl = video_ioctl2,
- < .mmap = v4l2_m2m_fop_mmap,
- < };
- <
- < static int rkvdec_v4l2_init(struct rkvdec_dev *rkvdec) {
- < int ret;
- <
- < ret = v4l2_device_register(rkvdec->dev, &rkvdec->v4l2_dev);
- < if (ret) {
- < dev_err(rkvdec->dev, "Failed to register V4L2 device\n");
- < return ret;
- < }
- <
- < rkvdec->m2m_dev = v4l2_m2m_init(&rkvdec_m2m_ops);
- < if (IS_ERR(rkvdec->m2m_dev)) {
- < v4l2_err(&rkvdec->v4l2_dev, "Failed to init mem2mem device\n");
- < ret = PTR_ERR(rkvdec->m2m_dev);
- < goto err_unregister_v4l2;
- < }
- <
- < rkvdec->mdev.dev = rkvdec->dev;
- < strscpy(rkvdec->mdev.model, "rkvdec", sizeof(rkvdec->mdev.model));
- < strscpy(rkvdec->mdev.bus_info, "platform:rkvdec",
- < sizeof(rkvdec->mdev.bus_info));
- < media_device_init(&rkvdec->mdev);
- < rkvdec->mdev.ops = &rkvdec_media_ops;
- < rkvdec->v4l2_dev.mdev = &rkvdec->mdev;
- <
- < rkvdec->vdev.lock = &rkvdec->vdev_lock;
- < rkvdec->vdev.v4l2_dev = &rkvdec->v4l2_dev;
- < rkvdec->vdev.fops = &rkvdec_fops;
- < rkvdec->vdev.release = video_device_release_empty;
- < rkvdec->vdev.vfl_dir = VFL_DIR_M2M;
- < rkvdec->vdev.device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
- < rkvdec->vdev.ioctl_ops = &rkvdec_ioctl_ops;
- < video_set_drvdata(&rkvdec->vdev, rkvdec);
- < strscpy(rkvdec->vdev.name, "rkvdec", sizeof(rkvdec->vdev.name));
- <
- < ret = video_register_device(&rkvdec->vdev, VFL_TYPE_VIDEO, -1);
- < if (ret) {
- < v4l2_err(&rkvdec->v4l2_dev, "Failed to register video device\n");
- < goto err_cleanup_mc;
- < }
- <
- < ret = v4l2_m2m_register_media_controller(rkvdec->m2m_dev, &rkvdec->vdev,
- < MEDIA_ENT_F_PROC_VIDEO_DECODER);
- < if (ret) {
- < v4l2_err(&rkvdec->v4l2_dev,
- < "Failed to initialize V4L2 M2M media controller\n");
- < goto err_unregister_vdev;
- < }
- <
- < ret = media_device_register(&rkvdec->mdev);
- < if (ret) {
- < v4l2_err(&rkvdec->v4l2_dev, "Failed to register media device\n");
- < goto err_unregister_mc;
- < }
- <
- < return 0;
- <
- < err_unregister_mc:
- < v4l2_m2m_unregister_media_controller(rkvdec->m2m_dev);
- <
- < err_unregister_vdev:
- < video_unregister_device(&rkvdec->vdev);
- <
- < err_cleanup_mc:
- < media_device_cleanup(&rkvdec->mdev);
- < v4l2_m2m_release(rkvdec->m2m_dev);
- <
- < err_unregister_v4l2:
- < v4l2_device_unregister(&rkvdec->v4l2_dev);
- < return ret;
- < }
- <
- < static void rkvdec_v4l2_cleanup(struct rkvdec_dev *rkvdec) {
- < media_device_unregister(&rkvdec->mdev);
- < v4l2_m2m_unregister_media_controller(rkvdec->m2m_dev);
- < video_unregister_device(&rkvdec->vdev);
- < media_device_cleanup(&rkvdec->mdev);
- < v4l2_m2m_release(rkvdec->m2m_dev);
- < v4l2_device_unregister(&rkvdec->v4l2_dev);
- < }
- <
- < static void rkvdec_iommu_restore(struct rkvdec_dev *rkvdec) {
- < if (rkvdec->empty_domain) {
- < /*
- < * To rewrite mapping into the attached IOMMU core, attach a new empty
- < * domain that will program an empty table, then detach it to restore the
- < * default domain and all cached mappings. This is safely done in this
- < * interrupt handler to make sure no memory get mapped through the IOMMU
- < * while the empty domain is attached.
- < */
- < iommu_attach_device(rkvdec->empty_domain, rkvdec->dev);
- < iommu_detach_device(rkvdec->empty_domain, rkvdec->dev);
- < }
- < }
- <
- < static irqreturn_t rkvdec_irq_handler(int irq, void *priv) {
- < struct rkvdec_dev *rkvdec = priv;
- < struct rkvdec_ctx *ctx = v4l2_m2m_get_curr_priv(rkvdec->m2m_dev);
- < enum vb2_buffer_state state;
- < u32 status;
- <
- < status = readl(rkvdec->regs + RKVDEC_REG_INTERRUPT);
- < writel(0, rkvdec->regs + RKVDEC_REG_INTERRUPT);
- <
- < if (status & RKVDEC_RDY_STA) {
- < state = VB2_BUF_STATE_DONE;
- < } else {
- < state = VB2_BUF_STATE_ERROR;
- < if (status & RKVDEC_SOFTRESET_RDY)
- < rkvdec_iommu_restore(rkvdec);
- < }
- <
- < if (cancel_delayed_work(&rkvdec->watchdog_work))
- < rkvdec_job_finish(ctx, state);
- <
- < return IRQ_HANDLED;
- < }
- <
- < static void rkvdec_watchdog_func(struct work_struct *work) {
- < struct rkvdec_dev *rkvdec;
- < struct rkvdec_ctx *ctx;
- <
- < rkvdec =
- < container_of(to_delayed_work(work), struct rkvdec_dev, watchdog_work);
- < ctx = v4l2_m2m_get_curr_priv(rkvdec->m2m_dev);
- < if (ctx) {
- < dev_err(rkvdec->dev, "Frame processing timed out!\n");
- < writel(RKVDEC_IRQ_DIS, rkvdec->regs + RKVDEC_REG_INTERRUPT);
- < writel(0, rkvdec->regs + RKVDEC_REG_SYSCTRL);
- < rkvdec_job_finish(ctx, VB2_BUF_STATE_ERROR);
- < }
- < }
- <
- < static const struct rkvdec_variant rk3288_rkvdec_variant = {
- < .num_regs = 68,
- < .capabilities = RKVDEC_CAPABILITY_HEVC,
- < };
- <
- < static const struct rkvdec_variant rk3328_rkvdec_variant = {
- < .num_regs = 109,
- < .capabilities =
- < RKVDEC_CAPABILITY_HEVC | RKVDEC_CAPABILITY_H264 | RKVDEC_CAPABILITY_VP9,
- < .quirks = RKVDEC_QUIRK_DISABLE_QOS,
- < };
- <
- < static const struct rkvdec_variant rk3399_rkvdec_variant = {
- < .num_regs = 78,
- < .capabilities =
- < RKVDEC_CAPABILITY_HEVC | RKVDEC_CAPABILITY_H264 | RKVDEC_CAPABILITY_VP9,
- < };
- <
- < static const struct of_device_id of_rkvdec_match[] = {
- < {
- < .compatible = "rockchip,rk3288-vdec",
- < .data = &rk3288_rkvdec_variant,
- < },
- < {
- < .compatible = "rockchip,rk3328-vdec",
- < .data = &rk3328_rkvdec_variant,
- < },
- < {
- < .compatible = "rockchip,rk3399-vdec",
- < .data = &rk3399_rkvdec_variant,
- < },
- < {/* sentinel */}};
- < MODULE_DEVICE_TABLE(of, of_rkvdec_match);
- <
- < static const char *const rkvdec_clk_names[] = {"axi", "ahb", "cabac", "core"};
- <
- < static int rkvdec_probe(struct platform_device *pdev) {
- < const struct rkvdec_variant *variant;
- < struct rkvdec_dev *rkvdec;
- < unsigned int i;
- < int ret, irq;
- <
- < variant = of_device_get_match_data(&pdev->dev);
- < if (!variant)
- < return -EINVAL;
- <
- < rkvdec = devm_kzalloc(&pdev->dev, sizeof(*rkvdec), GFP_KERNEL);
- < if (!rkvdec)
- < return -ENOMEM;
- <
- < platform_set_drvdata(pdev, rkvdec);
- < rkvdec->dev = &pdev->dev;
- < rkvdec->variant = variant;
- < mutex_init(&rkvdec->vdev_lock);
- < INIT_DELAYED_WORK(&rkvdec->watchdog_work, rkvdec_watchdog_func);
- <
- < rkvdec->clocks = devm_kcalloc(&pdev->dev, ARRAY_SIZE(rkvdec_clk_names),
- < sizeof(*rkvdec->clocks), GFP_KERNEL);
- < if (!rkvdec->clocks)
- < return -ENOMEM;
- <
- < for (i = 0; i < ARRAY_SIZE(rkvdec_clk_names); i++)
- < rkvdec->clocks[i].id = rkvdec_clk_names[i];
- <
- < ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(rkvdec_clk_names),
- < rkvdec->clocks);
- < if (ret)
- < return ret;
- <
- < rkvdec->regs = devm_platform_ioremap_resource(pdev, 0);
- < if (IS_ERR(rkvdec->regs))
- < return PTR_ERR(rkvdec->regs);
- <
- < ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
- < if (ret) {
- < dev_err(&pdev->dev, "Could not set DMA coherent mask.\n");
- < return ret;
- < }
- <
- < vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
- <
- < irq = platform_get_irq(pdev, 0);
- < if (irq <= 0)
- < return -ENXIO;
- <
- < ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, rkvdec_irq_handler,
- < IRQF_ONESHOT, dev_name(&pdev->dev), rkvdec);
- < if (ret) {
- < dev_err(&pdev->dev, "Could not request vdec IRQ\n");
- < return ret;
- < }
- <
- < pm_runtime_set_autosuspend_delay(&pdev->dev, 100);
- < pm_runtime_use_autosuspend(&pdev->dev);
- < pm_runtime_enable(&pdev->dev);
- <
- < ret = rkvdec_v4l2_init(rkvdec);
- < if (ret)
- < goto err_disable_runtime_pm;
- <
- < if (iommu_get_domain_for_dev(&pdev->dev)) {
- < rkvdec->empty_domain = iommu_paging_domain_alloc(rkvdec->dev);
- <
- < if (IS_ERR(rkvdec->empty_domain)) {
- < rkvdec->empty_domain = NULL;
- < dev_warn(rkvdec->dev, "cannot alloc new empty domain\n");
- < }
- < }
- <
- < return 0;
- <
- < err_disable_runtime_pm:
- < pm_runtime_dont_use_autosuspend(&pdev->dev);
- < pm_runtime_disable(&pdev->dev);
- < return ret;
- < }
- <
- < static void rkvdec_remove(struct platform_device *pdev) {
- < struct rkvdec_dev *rkvdec = platform_get_drvdata(pdev);
- <
- < cancel_delayed_work_sync(&rkvdec->watchdog_work);
- <
- < rkvdec_v4l2_cleanup(rkvdec);
- < pm_runtime_disable(&pdev->dev);
- < pm_runtime_dont_use_autosuspend(&pdev->dev);
- <
- < if (rkvdec->empty_domain)
- < iommu_domain_free(rkvdec->empty_domain);
- < }
- <
- < #ifdef CONFIG_PM
- < static int rkvdec_runtime_resume(struct device *dev) {
- < struct rkvdec_dev *rkvdec = dev_get_drvdata(dev);
- <
- < return clk_bulk_prepare_enable(ARRAY_SIZE(rkvdec_clk_names), rkvdec->clocks);
- < }
- <
- < static int rkvdec_runtime_suspend(struct device *dev) {
- < struct rkvdec_dev *rkvdec = dev_get_drvdata(dev);
- <
- < clk_bulk_disable_unprepare(ARRAY_SIZE(rkvdec_clk_names), rkvdec->clocks);
- < return 0;
- < }
- < #endif
- <
- < static const struct dev_pm_ops rkvdec_pm_ops = {
- < SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
- < SET_RUNTIME_PM_OPS(rkvdec_runtime_suspend, rkvdec_runtime_resume,
- < NULL)};
- <
- < static struct platform_driver rkvdec_driver = {
- < .probe = rkvdec_probe,
- < .remove = rkvdec_remove,
- < .driver =
- < {
- < .name = "rkvdec",
- < .of_match_table = of_rkvdec_match,
- < .pm = &rkvdec_pm_ops,
- < },
- < };
- < module_platform_driver(rkvdec_driver);
- <
- < MODULE_AUTHOR("Boris Brezillon <[email protected]>");
- < MODULE_DESCRIPTION("Rockchip Video Decoder driver");
- < MODULE_LICENSE("GPL v2");
Advertisement
Add Comment
Please, Sign In to add comment