| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016 MediaTek Inc. |
|---|
| 3 | 4 | * Author: PC Chen <pc.chen@mediatek.com> |
|---|
| 4 | 5 | * Tiffany Lin <tiffany.lin@mediatek.com> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | 6 | */ |
|---|
| 15 | 7 | |
|---|
| 16 | 8 | #include <linux/slab.h> |
|---|
| .. | .. |
|---|
| 28 | 20 | #include "mtk_vcodec_dec_pm.h" |
|---|
| 29 | 21 | #include "mtk_vcodec_intr.h" |
|---|
| 30 | 22 | #include "mtk_vcodec_util.h" |
|---|
| 31 | | -#include "mtk_vpu.h" |
|---|
| 23 | +#include "mtk_vcodec_fw.h" |
|---|
| 32 | 24 | |
|---|
| 33 | 25 | #define VDEC_HW_ACTIVE 0x10 |
|---|
| 34 | 26 | #define VDEC_IRQ_CFG 0x11 |
|---|
| .. | .. |
|---|
| 85 | 77 | return IRQ_HANDLED; |
|---|
| 86 | 78 | } |
|---|
| 87 | 79 | |
|---|
| 88 | | -static void mtk_vcodec_dec_reset_handler(void *priv) |
|---|
| 89 | | -{ |
|---|
| 90 | | - struct mtk_vcodec_dev *dev = priv; |
|---|
| 91 | | - struct mtk_vcodec_ctx *ctx; |
|---|
| 92 | | - |
|---|
| 93 | | - mtk_v4l2_err("Watchdog timeout!!"); |
|---|
| 94 | | - |
|---|
| 95 | | - mutex_lock(&dev->dev_mutex); |
|---|
| 96 | | - list_for_each_entry(ctx, &dev->ctx_list, list) { |
|---|
| 97 | | - ctx->state = MTK_STATE_ABORT; |
|---|
| 98 | | - mtk_v4l2_debug(0, "[%d] Change to state MTK_STATE_ERROR", |
|---|
| 99 | | - ctx->id); |
|---|
| 100 | | - } |
|---|
| 101 | | - mutex_unlock(&dev->dev_mutex); |
|---|
| 102 | | -} |
|---|
| 103 | | - |
|---|
| 104 | 80 | static int fops_vcodec_open(struct file *file) |
|---|
| 105 | 81 | { |
|---|
| 106 | 82 | struct mtk_vcodec_dev *dev = video_drvdata(file); |
|---|
| .. | .. |
|---|
| 145 | 121 | } |
|---|
| 146 | 122 | src_vq = v4l2_m2m_get_vq(ctx->m2m_ctx, |
|---|
| 147 | 123 | V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); |
|---|
| 148 | | - ctx->empty_flush_buf->vb.vb2_buf.vb2_queue = src_vq; |
|---|
| 124 | + ctx->empty_flush_buf->m2m_buf.vb.vb2_buf.vb2_queue = src_vq; |
|---|
| 149 | 125 | ctx->empty_flush_buf->lastframe = true; |
|---|
| 150 | 126 | mtk_vcodec_dec_set_default_params(ctx); |
|---|
| 151 | 127 | |
|---|
| 152 | 128 | if (v4l2_fh_is_singular(&ctx->fh)) { |
|---|
| 153 | | - mtk_vcodec_dec_pw_on(&dev->pm); |
|---|
| 129 | + ret = mtk_vcodec_dec_pw_on(&dev->pm); |
|---|
| 130 | + if (ret < 0) |
|---|
| 131 | + goto err_load_fw; |
|---|
| 154 | 132 | /* |
|---|
| 155 | | - * vpu_load_firmware checks if it was loaded already and |
|---|
| 156 | | - * does nothing in that case |
|---|
| 133 | + * Does nothing if firmware was already loaded. |
|---|
| 157 | 134 | */ |
|---|
| 158 | | - ret = vpu_load_firmware(dev->vpu_plat_dev); |
|---|
| 135 | + ret = mtk_vcodec_fw_load_firmware(dev->fw_handler); |
|---|
| 159 | 136 | if (ret < 0) { |
|---|
| 160 | 137 | /* |
|---|
| 161 | 138 | * Return 0 if downloading firmware successfully, |
|---|
| 162 | 139 | * otherwise it is failed |
|---|
| 163 | 140 | */ |
|---|
| 164 | | - mtk_v4l2_err("vpu_load_firmware failed!"); |
|---|
| 141 | + mtk_v4l2_err("failed to load firmware!"); |
|---|
| 165 | 142 | goto err_load_fw; |
|---|
| 166 | 143 | } |
|---|
| 167 | 144 | |
|---|
| 168 | 145 | dev->dec_capability = |
|---|
| 169 | | - vpu_get_vdec_hw_capa(dev->vpu_plat_dev); |
|---|
| 146 | + mtk_vcodec_fw_get_vdec_capa(dev->fw_handler); |
|---|
| 170 | 147 | mtk_v4l2_debug(0, "decoder capability %x", dev->dec_capability); |
|---|
| 171 | 148 | } |
|---|
| 172 | 149 | |
|---|
| .. | .. |
|---|
| 236 | 213 | struct mtk_vcodec_dev *dev; |
|---|
| 237 | 214 | struct video_device *vfd_dec; |
|---|
| 238 | 215 | struct resource *res; |
|---|
| 216 | + phandle rproc_phandle; |
|---|
| 217 | + enum mtk_vcodec_fw_type fw_type; |
|---|
| 239 | 218 | int i, ret; |
|---|
| 240 | 219 | |
|---|
| 241 | 220 | dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 245 | 224 | INIT_LIST_HEAD(&dev->ctx_list); |
|---|
| 246 | 225 | dev->plat_dev = pdev; |
|---|
| 247 | 226 | |
|---|
| 248 | | - dev->vpu_plat_dev = vpu_get_plat_device(dev->plat_dev); |
|---|
| 249 | | - if (dev->vpu_plat_dev == NULL) { |
|---|
| 250 | | - mtk_v4l2_err("[VPU] vpu device in not ready"); |
|---|
| 251 | | - return -EPROBE_DEFER; |
|---|
| 227 | + if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu", |
|---|
| 228 | + &rproc_phandle)) { |
|---|
| 229 | + fw_type = VPU; |
|---|
| 230 | + } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp", |
|---|
| 231 | + &rproc_phandle)) { |
|---|
| 232 | + fw_type = SCP; |
|---|
| 233 | + } else { |
|---|
| 234 | + mtk_v4l2_err("Could not get vdec IPI device"); |
|---|
| 235 | + return -ENODEV; |
|---|
| 252 | 236 | } |
|---|
| 237 | + if (!pdev->dev.dma_parms) { |
|---|
| 238 | + pdev->dev.dma_parms = devm_kzalloc(&pdev->dev, |
|---|
| 239 | + sizeof(*pdev->dev.dma_parms), |
|---|
| 240 | + GFP_KERNEL); |
|---|
| 241 | + if (!pdev->dev.dma_parms) |
|---|
| 242 | + return -ENOMEM; |
|---|
| 243 | + } |
|---|
| 244 | + dma_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 253 | 245 | |
|---|
| 254 | | - vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_dec_reset_handler, |
|---|
| 255 | | - dev, VPU_RST_DEC); |
|---|
| 246 | + dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, DECODER); |
|---|
| 247 | + if (IS_ERR(dev->fw_handler)) |
|---|
| 248 | + return PTR_ERR(dev->fw_handler); |
|---|
| 256 | 249 | |
|---|
| 257 | 250 | ret = mtk_vcodec_init_dec_pm(dev); |
|---|
| 258 | 251 | if (ret < 0) { |
|---|
| 259 | 252 | dev_err(&pdev->dev, "Failed to get mt vcodec clock source"); |
|---|
| 260 | | - return ret; |
|---|
| 253 | + goto err_dec_pm; |
|---|
| 261 | 254 | } |
|---|
| 262 | 255 | |
|---|
| 263 | 256 | for (i = 0; i < NUM_MAX_VDEC_REG_BASE; i++) { |
|---|
| 264 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, i); |
|---|
| 265 | | - if (res == NULL) { |
|---|
| 266 | | - dev_err(&pdev->dev, "get memory resource failed."); |
|---|
| 267 | | - ret = -ENXIO; |
|---|
| 268 | | - goto err_res; |
|---|
| 269 | | - } |
|---|
| 270 | | - dev->reg_base[i] = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 257 | + dev->reg_base[i] = devm_platform_ioremap_resource(pdev, i); |
|---|
| 271 | 258 | if (IS_ERR((__force void *)dev->reg_base[i])) { |
|---|
| 272 | 259 | ret = PTR_ERR((__force void *)dev->reg_base[i]); |
|---|
| 273 | 260 | goto err_res; |
|---|
| .. | .. |
|---|
| 283 | 270 | } |
|---|
| 284 | 271 | |
|---|
| 285 | 272 | dev->dec_irq = platform_get_irq(pdev, 0); |
|---|
| 273 | + irq_set_status_flags(dev->dec_irq, IRQ_NOAUTOEN); |
|---|
| 286 | 274 | ret = devm_request_irq(&pdev->dev, dev->dec_irq, |
|---|
| 287 | 275 | mtk_vcodec_dec_irq_handler, 0, pdev->name, dev); |
|---|
| 288 | 276 | if (ret) { |
|---|
| .. | .. |
|---|
| 292 | 280 | goto err_res; |
|---|
| 293 | 281 | } |
|---|
| 294 | 282 | |
|---|
| 295 | | - disable_irq(dev->dec_irq); |
|---|
| 296 | 283 | mutex_init(&dev->dec_mutex); |
|---|
| 297 | 284 | mutex_init(&dev->dev_mutex); |
|---|
| 298 | 285 | spin_lock_init(&dev->irqlock); |
|---|
| .. | .. |
|---|
| 345 | 332 | goto err_event_workq; |
|---|
| 346 | 333 | } |
|---|
| 347 | 334 | |
|---|
| 348 | | - ret = video_register_device(vfd_dec, VFL_TYPE_GRABBER, 0); |
|---|
| 335 | + ret = video_register_device(vfd_dec, VFL_TYPE_VIDEO, 0); |
|---|
| 349 | 336 | if (ret) { |
|---|
| 350 | 337 | mtk_v4l2_err("Failed to register video device"); |
|---|
| 351 | 338 | goto err_dec_reg; |
|---|
| .. | .. |
|---|
| 366 | 353 | v4l2_device_unregister(&dev->v4l2_dev); |
|---|
| 367 | 354 | err_res: |
|---|
| 368 | 355 | mtk_vcodec_release_dec_pm(dev); |
|---|
| 356 | +err_dec_pm: |
|---|
| 357 | + mtk_vcodec_fw_release(dev->fw_handler); |
|---|
| 369 | 358 | return ret; |
|---|
| 370 | 359 | } |
|---|
| 371 | 360 | |
|---|
| .. | .. |
|---|
| 390 | 379 | |
|---|
| 391 | 380 | v4l2_device_unregister(&dev->v4l2_dev); |
|---|
| 392 | 381 | mtk_vcodec_release_dec_pm(dev); |
|---|
| 382 | + mtk_vcodec_fw_release(dev->fw_handler); |
|---|
| 393 | 383 | return 0; |
|---|
| 394 | 384 | } |
|---|
| 395 | 385 | |
|---|