mtk_mdp_regs.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2015-2016 MediaTek Inc.
  3. * Author: Houlong Wei <houlong.wei@mediatek.com>
  4. * Ming Hsiu Tsai <minghsiu.tsai@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/platform_device.h>
  16. #include "mtk_mdp_core.h"
  17. #include "mtk_mdp_regs.h"
  18. #define MDP_COLORFMT_PACK(VIDEO, PLANE, COPLANE, HF, VF, BITS, GROUP, SWAP, ID)\
  19. (((VIDEO) << 27) | ((PLANE) << 24) | ((COPLANE) << 22) |\
  20. ((HF) << 20) | ((VF) << 18) | ((BITS) << 8) | ((GROUP) << 6) |\
  21. ((SWAP) << 5) | ((ID) << 0))
  22. enum MDP_COLOR_ENUM {
  23. MDP_COLOR_UNKNOWN = 0,
  24. MDP_COLOR_NV12 = MDP_COLORFMT_PACK(0, 2, 1, 1, 1, 8, 1, 0, 12),
  25. MDP_COLOR_I420 = MDP_COLORFMT_PACK(0, 3, 0, 1, 1, 8, 1, 0, 8),
  26. MDP_COLOR_YV12 = MDP_COLORFMT_PACK(0, 3, 0, 1, 1, 8, 1, 1, 8),
  27. /* Mediatek proprietary format */
  28. MDP_COLOR_420_MT21 = MDP_COLORFMT_PACK(5, 2, 1, 1, 1, 256, 1, 0, 12),
  29. };
  30. static int32_t mtk_mdp_map_color_format(int v4l2_format)
  31. {
  32. switch (v4l2_format) {
  33. case V4L2_PIX_FMT_NV12M:
  34. case V4L2_PIX_FMT_NV12:
  35. return MDP_COLOR_NV12;
  36. case V4L2_PIX_FMT_MT21C:
  37. return MDP_COLOR_420_MT21;
  38. case V4L2_PIX_FMT_YUV420M:
  39. case V4L2_PIX_FMT_YUV420:
  40. return MDP_COLOR_I420;
  41. case V4L2_PIX_FMT_YVU420:
  42. return MDP_COLOR_YV12;
  43. }
  44. mtk_mdp_err("Unknown format 0x%x", v4l2_format);
  45. return MDP_COLOR_UNKNOWN;
  46. }
  47. void mtk_mdp_hw_set_input_addr(struct mtk_mdp_ctx *ctx,
  48. struct mtk_mdp_addr *addr)
  49. {
  50. struct mdp_buffer *src_buf = &ctx->vpu.vsi->src_buffer;
  51. int i;
  52. for (i = 0; i < ARRAY_SIZE(addr->addr); i++)
  53. src_buf->addr_mva[i] = (uint64_t)addr->addr[i];
  54. }
  55. void mtk_mdp_hw_set_output_addr(struct mtk_mdp_ctx *ctx,
  56. struct mtk_mdp_addr *addr)
  57. {
  58. struct mdp_buffer *dst_buf = &ctx->vpu.vsi->dst_buffer;
  59. int i;
  60. for (i = 0; i < ARRAY_SIZE(addr->addr); i++)
  61. dst_buf->addr_mva[i] = (uint64_t)addr->addr[i];
  62. }
  63. void mtk_mdp_hw_set_in_size(struct mtk_mdp_ctx *ctx)
  64. {
  65. struct mtk_mdp_frame *frame = &ctx->s_frame;
  66. struct mdp_config *config = &ctx->vpu.vsi->src_config;
  67. /* Set input pixel offset */
  68. config->crop_x = frame->crop.left;
  69. config->crop_y = frame->crop.top;
  70. /* Set input cropped size */
  71. config->crop_w = frame->crop.width;
  72. config->crop_h = frame->crop.height;
  73. /* Set input original size */
  74. config->x = 0;
  75. config->y = 0;
  76. config->w = frame->width;
  77. config->h = frame->height;
  78. }
  79. void mtk_mdp_hw_set_in_image_format(struct mtk_mdp_ctx *ctx)
  80. {
  81. unsigned int i;
  82. struct mtk_mdp_frame *frame = &ctx->s_frame;
  83. struct mdp_config *config = &ctx->vpu.vsi->src_config;
  84. struct mdp_buffer *src_buf = &ctx->vpu.vsi->src_buffer;
  85. src_buf->plane_num = frame->fmt->num_comp;
  86. config->format = mtk_mdp_map_color_format(frame->fmt->pixelformat);
  87. config->w_stride = 0; /* MDP will calculate it by color format. */
  88. config->h_stride = 0; /* MDP will calculate it by color format. */
  89. for (i = 0; i < src_buf->plane_num; i++)
  90. src_buf->plane_size[i] = frame->payload[i];
  91. }
  92. void mtk_mdp_hw_set_out_size(struct mtk_mdp_ctx *ctx)
  93. {
  94. struct mtk_mdp_frame *frame = &ctx->d_frame;
  95. struct mdp_config *config = &ctx->vpu.vsi->dst_config;
  96. config->crop_x = frame->crop.left;
  97. config->crop_y = frame->crop.top;
  98. config->crop_w = frame->crop.width;
  99. config->crop_h = frame->crop.height;
  100. config->x = 0;
  101. config->y = 0;
  102. config->w = frame->width;
  103. config->h = frame->height;
  104. }
  105. void mtk_mdp_hw_set_out_image_format(struct mtk_mdp_ctx *ctx)
  106. {
  107. unsigned int i;
  108. struct mtk_mdp_frame *frame = &ctx->d_frame;
  109. struct mdp_config *config = &ctx->vpu.vsi->dst_config;
  110. struct mdp_buffer *dst_buf = &ctx->vpu.vsi->dst_buffer;
  111. dst_buf->plane_num = frame->fmt->num_comp;
  112. config->format = mtk_mdp_map_color_format(frame->fmt->pixelformat);
  113. config->w_stride = 0; /* MDP will calculate it by color format. */
  114. config->h_stride = 0; /* MDP will calculate it by color format. */
  115. for (i = 0; i < dst_buf->plane_num; i++)
  116. dst_buf->plane_size[i] = frame->payload[i];
  117. }
  118. void mtk_mdp_hw_set_rotation(struct mtk_mdp_ctx *ctx)
  119. {
  120. struct mdp_config_misc *misc = &ctx->vpu.vsi->misc;
  121. misc->orientation = ctx->ctrls.rotate->val;
  122. misc->hflip = ctx->ctrls.hflip->val;
  123. misc->vflip = ctx->ctrls.vflip->val;
  124. }
  125. void mtk_mdp_hw_set_global_alpha(struct mtk_mdp_ctx *ctx)
  126. {
  127. struct mdp_config_misc *misc = &ctx->vpu.vsi->misc;
  128. misc->alpha = ctx->ctrls.global_alpha->val;
  129. }