vdec_drv_if.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Author: PC Chen <pc.chen@mediatek.com>
  4. * 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. */
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel.h>
  17. #include <linux/slab.h>
  18. #include "vdec_drv_if.h"
  19. #include "mtk_vcodec_dec.h"
  20. #include "vdec_drv_base.h"
  21. #include "mtk_vcodec_dec_pm.h"
  22. #include "mtk_vpu.h"
  23. const struct vdec_common_if *get_h264_dec_comm_if(void);
  24. const struct vdec_common_if *get_vp8_dec_comm_if(void);
  25. const struct vdec_common_if *get_vp9_dec_comm_if(void);
  26. int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
  27. {
  28. int ret = 0;
  29. switch (fourcc) {
  30. case V4L2_PIX_FMT_H264:
  31. ctx->dec_if = get_h264_dec_comm_if();
  32. break;
  33. case V4L2_PIX_FMT_VP8:
  34. ctx->dec_if = get_vp8_dec_comm_if();
  35. break;
  36. case V4L2_PIX_FMT_VP9:
  37. ctx->dec_if = get_vp9_dec_comm_if();
  38. break;
  39. default:
  40. return -EINVAL;
  41. }
  42. mtk_vdec_lock(ctx);
  43. mtk_vcodec_dec_clock_on(&ctx->dev->pm);
  44. ret = ctx->dec_if->init(ctx, &ctx->drv_handle);
  45. mtk_vcodec_dec_clock_off(&ctx->dev->pm);
  46. mtk_vdec_unlock(ctx);
  47. return ret;
  48. }
  49. int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
  50. struct vdec_fb *fb, bool *res_chg)
  51. {
  52. int ret = 0;
  53. if (bs) {
  54. if ((bs->dma_addr & 63) != 0) {
  55. mtk_v4l2_err("bs dma_addr should 64 byte align");
  56. return -EINVAL;
  57. }
  58. }
  59. if (fb) {
  60. if (((fb->base_y.dma_addr & 511) != 0) ||
  61. ((fb->base_c.dma_addr & 511) != 0)) {
  62. mtk_v4l2_err("frame buffer dma_addr should 512 byte align");
  63. return -EINVAL;
  64. }
  65. }
  66. if (ctx->drv_handle == 0)
  67. return -EIO;
  68. mtk_vdec_lock(ctx);
  69. mtk_vcodec_set_curr_ctx(ctx->dev, ctx);
  70. mtk_vcodec_dec_clock_on(&ctx->dev->pm);
  71. enable_irq(ctx->dev->dec_irq);
  72. ret = ctx->dec_if->decode(ctx->drv_handle, bs, fb, res_chg);
  73. disable_irq(ctx->dev->dec_irq);
  74. mtk_vcodec_dec_clock_off(&ctx->dev->pm);
  75. mtk_vcodec_set_curr_ctx(ctx->dev, NULL);
  76. mtk_vdec_unlock(ctx);
  77. return ret;
  78. }
  79. int vdec_if_get_param(struct mtk_vcodec_ctx *ctx, enum vdec_get_param_type type,
  80. void *out)
  81. {
  82. int ret = 0;
  83. if (ctx->drv_handle == 0)
  84. return -EIO;
  85. mtk_vdec_lock(ctx);
  86. ret = ctx->dec_if->get_param(ctx->drv_handle, type, out);
  87. mtk_vdec_unlock(ctx);
  88. return ret;
  89. }
  90. void vdec_if_deinit(struct mtk_vcodec_ctx *ctx)
  91. {
  92. if (ctx->drv_handle == 0)
  93. return;
  94. mtk_vdec_lock(ctx);
  95. mtk_vcodec_dec_clock_on(&ctx->dev->pm);
  96. ctx->dec_if->deinit(ctx->drv_handle);
  97. mtk_vcodec_dec_clock_off(&ctx->dev->pm);
  98. mtk_vdec_unlock(ctx);
  99. ctx->drv_handle = 0;
  100. }