venc_drv_if.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Author: Daniel Hsiao <daniel.hsiao@mediatek.com>
  4. * Jungchang Tsao <jungchang.tsao@mediatek.com>
  5. * Tiffany Lin <tiffany.lin@mediatek.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/interrupt.h>
  18. #include <linux/kernel.h>
  19. #include <linux/slab.h>
  20. #include "venc_drv_base.h"
  21. #include "venc_drv_if.h"
  22. #include "mtk_vcodec_enc.h"
  23. #include "mtk_vcodec_enc_pm.h"
  24. #include "mtk_vpu.h"
  25. const struct venc_common_if *get_h264_enc_comm_if(void);
  26. const struct venc_common_if *get_vp8_enc_comm_if(void);
  27. int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
  28. {
  29. int ret = 0;
  30. switch (fourcc) {
  31. case V4L2_PIX_FMT_VP8:
  32. ctx->enc_if = get_vp8_enc_comm_if();
  33. break;
  34. case V4L2_PIX_FMT_H264:
  35. ctx->enc_if = get_h264_enc_comm_if();
  36. break;
  37. default:
  38. return -EINVAL;
  39. }
  40. mtk_venc_lock(ctx);
  41. mtk_vcodec_enc_clock_on(&ctx->dev->pm);
  42. ret = ctx->enc_if->init(ctx, (unsigned long *)&ctx->drv_handle);
  43. mtk_vcodec_enc_clock_off(&ctx->dev->pm);
  44. mtk_venc_unlock(ctx);
  45. return ret;
  46. }
  47. int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
  48. enum venc_set_param_type type, struct venc_enc_param *in)
  49. {
  50. int ret = 0;
  51. mtk_venc_lock(ctx);
  52. mtk_vcodec_enc_clock_on(&ctx->dev->pm);
  53. ret = ctx->enc_if->set_param(ctx->drv_handle, type, in);
  54. mtk_vcodec_enc_clock_off(&ctx->dev->pm);
  55. mtk_venc_unlock(ctx);
  56. return ret;
  57. }
  58. int venc_if_encode(struct mtk_vcodec_ctx *ctx,
  59. enum venc_start_opt opt, struct venc_frm_buf *frm_buf,
  60. struct mtk_vcodec_mem *bs_buf,
  61. struct venc_done_result *result)
  62. {
  63. int ret = 0;
  64. unsigned long flags;
  65. mtk_venc_lock(ctx);
  66. spin_lock_irqsave(&ctx->dev->irqlock, flags);
  67. ctx->dev->curr_ctx = ctx;
  68. spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
  69. mtk_vcodec_enc_clock_on(&ctx->dev->pm);
  70. ret = ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf,
  71. bs_buf, result);
  72. mtk_vcodec_enc_clock_off(&ctx->dev->pm);
  73. spin_lock_irqsave(&ctx->dev->irqlock, flags);
  74. ctx->dev->curr_ctx = NULL;
  75. spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
  76. mtk_venc_unlock(ctx);
  77. return ret;
  78. }
  79. int venc_if_deinit(struct mtk_vcodec_ctx *ctx)
  80. {
  81. int ret = 0;
  82. if (ctx->drv_handle == 0)
  83. return 0;
  84. mtk_venc_lock(ctx);
  85. mtk_vcodec_enc_clock_on(&ctx->dev->pm);
  86. ret = ctx->enc_if->deinit(ctx->drv_handle);
  87. mtk_vcodec_enc_clock_off(&ctx->dev->pm);
  88. mtk_venc_unlock(ctx);
  89. ctx->drv_handle = 0;
  90. return ret;
  91. }