diff options
Diffstat (limited to 'drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c')
-rw-r--r-- | drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 180 |
1 files changed, 131 insertions, 49 deletions
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index 4d31f1ed113f..dcfa2c2d4def 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -21,11 +21,55 @@ #include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_intr.h" #include "mtk_vcodec_util.h" -#include "mtk_vpu.h" +#include "mtk_vcodec_fw.h" module_param(mtk_v4l2_dbg_level, int, S_IRUGO | S_IWUSR); module_param(mtk_vcodec_dbg, bool, S_IRUGO | S_IWUSR); +static const struct mtk_video_fmt mtk_video_formats_output_mt8173[] = { + { + .fourcc = V4L2_PIX_FMT_NV12M, + .type = MTK_FMT_FRAME, + .num_planes = 2, + }, + { + .fourcc = V4L2_PIX_FMT_NV21M, + .type = MTK_FMT_FRAME, + .num_planes = 2, + }, + { + .fourcc = V4L2_PIX_FMT_YUV420M, + .type = MTK_FMT_FRAME, + .num_planes = 3, + }, + { + .fourcc = V4L2_PIX_FMT_YVU420M, + .type = MTK_FMT_FRAME, + .num_planes = 3, + }, +}; + +static const struct mtk_video_fmt mtk_video_formats_capture_mt8173[] = { + { + .fourcc = V4L2_PIX_FMT_H264, + .type = MTK_FMT_ENC, + .num_planes = 1, + }, + { + .fourcc = V4L2_PIX_FMT_VP8, + .type = MTK_FMT_ENC, + .num_planes = 1, + }, +}; + +static const struct mtk_video_fmt mtk_video_formats_capture_mt8183[] = { + { + .fourcc = V4L2_PIX_FMT_H264, + .type = MTK_FMT_ENC, + .num_planes = 1, + }, +}; + /* Wake up context wait_queue */ static void wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason) { @@ -101,22 +145,6 @@ static irqreturn_t mtk_vcodec_enc_lt_irq_handler(int irq, void *priv) return IRQ_HANDLED; } -static void mtk_vcodec_enc_reset_handler(void *priv) -{ - struct mtk_vcodec_dev *dev = priv; - struct mtk_vcodec_ctx *ctx; - - mtk_v4l2_debug(0, "Watchdog timeout!!"); - - mutex_lock(&dev->dev_mutex); - list_for_each_entry(ctx, &dev->ctx_list, list) { - ctx->state = MTK_STATE_ABORT; - mtk_v4l2_debug(0, "[%d] Change to state MTK_STATE_ABORT", - ctx->id); - } - mutex_unlock(&dev->dev_mutex); -} - static int fops_vcodec_open(struct file *file) { struct mtk_vcodec_dev *dev = video_drvdata(file); @@ -159,10 +187,10 @@ static int fops_vcodec_open(struct file *file) if (v4l2_fh_is_singular(&ctx->fh)) { /* - * vpu_load_firmware checks if it was loaded already and + * load fireware to checks if it was loaded already and * does nothing in that case */ - ret = vpu_load_firmware(dev->vpu_plat_dev); + ret = mtk_vcodec_fw_load_firmware(dev->fw_handler); if (ret < 0) { /* * Return 0 if downloading firmware successfully, @@ -173,7 +201,7 @@ static int fops_vcodec_open(struct file *file) } dev->enc_capability = - vpu_get_venc_hw_capa(dev->vpu_plat_dev); + mtk_vcodec_fw_get_venc_capa(dev->fw_handler); mtk_v4l2_debug(0, "encoder capability %x", dev->enc_capability); } @@ -235,7 +263,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) struct mtk_vcodec_dev *dev; struct video_device *vfd_enc; struct resource *res; - int i, j, ret; + phandle rproc_phandle; + enum mtk_vcodec_fw_type fw_type; + int ret; dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) @@ -244,30 +274,43 @@ static int mtk_vcodec_probe(struct platform_device *pdev) INIT_LIST_HEAD(&dev->ctx_list); dev->plat_dev = pdev; - dev->vpu_plat_dev = vpu_get_plat_device(dev->plat_dev); - if (dev->vpu_plat_dev == NULL) { - mtk_v4l2_err("[VPU] vpu device in not ready"); - return -EPROBE_DEFER; + if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu", + &rproc_phandle)) { + fw_type = VPU; + } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp", + &rproc_phandle)) { + fw_type = SCP; + } else { + mtk_v4l2_err("Could not get venc IPI device"); + return -ENODEV; } + if (!pdev->dev.dma_parms) { + pdev->dev.dma_parms = devm_kzalloc(&pdev->dev, + sizeof(*pdev->dev.dma_parms), + GFP_KERNEL); + if (!pdev->dev.dma_parms) + return -ENOMEM; + } + dma_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32)); - vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_enc_reset_handler, - dev, VPU_RST_ENC); + dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, VPU_RST_ENC); + if (IS_ERR(dev->fw_handler)) + return PTR_ERR(dev->fw_handler); + dev->venc_pdata = of_device_get_match_data(&pdev->dev); ret = mtk_vcodec_init_enc_pm(dev); if (ret < 0) { dev_err(&pdev->dev, "Failed to get mt vcodec clock source!"); - return ret; + goto err_enc_pm; } - for (i = VENC_SYS, j = 0; i < NUM_MAX_VCODEC_REG_BASE; i++, j++) { - res = platform_get_resource(pdev, IORESOURCE_MEM, j); - dev->reg_base[i] = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR((__force void *)dev->reg_base[i])) { - ret = PTR_ERR((__force void *)dev->reg_base[i]); - goto err_res; - } - mtk_v4l2_debug(2, "reg[%d] base=0x%p", i, dev->reg_base[i]); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + dev->reg_base[VENC_SYS] = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR((__force void *)dev->reg_base[VENC_SYS])) { + ret = PTR_ERR((__force void *)dev->reg_base[VENC_SYS]); + goto err_res; } + mtk_v4l2_debug(2, "reg[%d] base=0x%p", i, dev->reg_base[VENC_SYS]); res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (res == NULL) { @@ -277,6 +320,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) } dev->enc_irq = platform_get_irq(pdev, 0); + irq_set_status_flags(dev->enc_irq, IRQ_NOAUTOEN); ret = devm_request_irq(&pdev->dev, dev->enc_irq, mtk_vcodec_enc_irq_handler, 0, pdev->name, dev); @@ -288,20 +332,30 @@ static int mtk_vcodec_probe(struct platform_device *pdev) goto err_res; } - dev->enc_lt_irq = platform_get_irq(pdev, 1); - ret = devm_request_irq(&pdev->dev, - dev->enc_lt_irq, mtk_vcodec_enc_lt_irq_handler, - 0, pdev->name, dev); - if (ret) { - dev_err(&pdev->dev, - "Failed to install dev->enc_lt_irq %d (%d)", - dev->enc_lt_irq, ret); - ret = -EINVAL; - goto err_res; + if (dev->venc_pdata->has_lt_irq) { + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + dev->reg_base[VENC_LT_SYS] = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR((__force void *)dev->reg_base[VENC_LT_SYS])) { + ret = PTR_ERR((__force void *)dev->reg_base[VENC_LT_SYS]); + goto err_res; + } + mtk_v4l2_debug(2, "reg[%d] base=0x%p", i, dev->reg_base[VENC_LT_SYS]); + + dev->enc_lt_irq = platform_get_irq(pdev, 1); + irq_set_status_flags(dev->enc_lt_irq, IRQ_NOAUTOEN); + ret = devm_request_irq(&pdev->dev, + dev->enc_lt_irq, + mtk_vcodec_enc_lt_irq_handler, + 0, pdev->name, dev); + if (ret) { + dev_err(&pdev->dev, + "Failed to install dev->enc_lt_irq %d (%d)", + dev->enc_lt_irq, ret); + ret = -EINVAL; + goto err_res; + } } - disable_irq(dev->enc_irq); - disable_irq(dev->enc_lt_irq); /* VENC_LT */ mutex_init(&dev->enc_mutex); mutex_init(&dev->dev_mutex); spin_lock_init(&dev->irqlock); @@ -377,11 +431,38 @@ err_enc_alloc: v4l2_device_unregister(&dev->v4l2_dev); err_res: mtk_vcodec_release_enc_pm(dev); +err_enc_pm: + mtk_vcodec_fw_release(dev->fw_handler); return ret; } +static const struct mtk_vcodec_enc_pdata mt8173_pdata = { + .chip = MTK_MT8173, + .has_lt_irq = true, + .capture_formats = mtk_video_formats_capture_mt8173, + .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8173), + .output_formats = mtk_video_formats_output_mt8173, + .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173), + .min_bitrate = 1, + .max_bitrate = 4000000, +}; + +static const struct mtk_vcodec_enc_pdata mt8183_pdata = { + .chip = MTK_MT8183, + .has_lt_irq = false, + .uses_ext = true, + .capture_formats = mtk_video_formats_capture_mt8183, + .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8183), + /* MT8183 supports the same output formats as MT8173 */ + .output_formats = mtk_video_formats_output_mt8173, + .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173), + .min_bitrate = 64, + .max_bitrate = 40000000, +}; + static const struct of_device_id mtk_vcodec_enc_match[] = { - {.compatible = "mediatek,mt8173-vcodec-enc",}, + {.compatible = "mediatek,mt8173-vcodec-enc", .data = &mt8173_pdata}, + {.compatible = "mediatek,mt8183-vcodec-enc", .data = &mt8183_pdata}, {}, }; MODULE_DEVICE_TABLE(of, mtk_vcodec_enc_match); @@ -401,6 +482,7 @@ static int mtk_vcodec_enc_remove(struct platform_device *pdev) v4l2_device_unregister(&dev->v4l2_dev); mtk_vcodec_release_enc_pm(dev); + mtk_vcodec_fw_release(dev->fw_handler); return 0; } |