mdp_format.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "msm_drv.h"
  19. #include "mdp_kms.h"
  20. static struct csc_cfg csc_convert[CSC_MAX] = {
  21. [CSC_RGB2RGB] = {
  22. .type = CSC_RGB2RGB,
  23. .matrix = {
  24. 0x0200, 0x0000, 0x0000,
  25. 0x0000, 0x0200, 0x0000,
  26. 0x0000, 0x0000, 0x0200
  27. },
  28. .pre_bias = { 0x0, 0x0, 0x0 },
  29. .post_bias = { 0x0, 0x0, 0x0 },
  30. .pre_clamp = { 0x0, 0xff, 0x0, 0xff, 0x0, 0xff },
  31. .post_clamp = { 0x0, 0xff, 0x0, 0xff, 0x0, 0xff },
  32. },
  33. [CSC_YUV2RGB] = {
  34. .type = CSC_YUV2RGB,
  35. .matrix = {
  36. 0x0254, 0x0000, 0x0331,
  37. 0x0254, 0xff37, 0xfe60,
  38. 0x0254, 0x0409, 0x0000
  39. },
  40. .pre_bias = { 0xfff0, 0xff80, 0xff80 },
  41. .post_bias = { 0x00, 0x00, 0x00 },
  42. .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
  43. .post_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
  44. },
  45. [CSC_RGB2YUV] = {
  46. .type = CSC_RGB2YUV,
  47. .matrix = {
  48. 0x0083, 0x0102, 0x0032,
  49. 0x1fb5, 0x1f6c, 0x00e1,
  50. 0x00e1, 0x1f45, 0x1fdc
  51. },
  52. .pre_bias = { 0x00, 0x00, 0x00 },
  53. .post_bias = { 0x10, 0x80, 0x80 },
  54. .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
  55. .post_clamp = { 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0 },
  56. },
  57. [CSC_YUV2YUV] = {
  58. .type = CSC_YUV2YUV,
  59. .matrix = {
  60. 0x0200, 0x0000, 0x0000,
  61. 0x0000, 0x0200, 0x0000,
  62. 0x0000, 0x0000, 0x0200
  63. },
  64. .pre_bias = { 0x00, 0x00, 0x00 },
  65. .post_bias = { 0x00, 0x00, 0x00 },
  66. .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
  67. .post_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
  68. },
  69. };
  70. #define FMT(name, a, r, g, b, e0, e1, e2, e3, alpha, tight, c, cnt, fp, cs, yuv) { \
  71. .base = { .pixel_format = DRM_FORMAT_ ## name }, \
  72. .bpc_a = BPC ## a ## A, \
  73. .bpc_r = BPC ## r, \
  74. .bpc_g = BPC ## g, \
  75. .bpc_b = BPC ## b, \
  76. .unpack = { e0, e1, e2, e3 }, \
  77. .alpha_enable = alpha, \
  78. .unpack_tight = tight, \
  79. .cpp = c, \
  80. .unpack_count = cnt, \
  81. .fetch_type = fp, \
  82. .chroma_sample = cs, \
  83. .is_yuv = yuv, \
  84. }
  85. #define BPC0A 0
  86. /*
  87. * Note: Keep RGB formats 1st, followed by YUV formats to avoid breaking
  88. * mdp_get_rgb_formats()'s implementation.
  89. */
  90. static const struct mdp_format formats[] = {
  91. /* name a r g b e0 e1 e2 e3 alpha tight cpp cnt ... */
  92. FMT(ARGB8888, 8, 8, 8, 8, 1, 0, 2, 3, true, true, 4, 4,
  93. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  94. FMT(ABGR8888, 8, 8, 8, 8, 2, 0, 1, 3, true, true, 4, 4,
  95. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  96. FMT(RGBA8888, 8, 8, 8, 8, 3, 1, 0, 2, true, true, 4, 4,
  97. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  98. FMT(BGRA8888, 8, 8, 8, 8, 3, 2, 0, 1, true, true, 4, 4,
  99. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  100. FMT(XRGB8888, 8, 8, 8, 8, 1, 0, 2, 3, false, true, 4, 4,
  101. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  102. FMT(RGB888, 0, 8, 8, 8, 1, 0, 2, 0, false, true, 3, 3,
  103. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  104. FMT(BGR888, 0, 8, 8, 8, 2, 0, 1, 0, false, true, 3, 3,
  105. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  106. FMT(RGB565, 0, 5, 6, 5, 1, 0, 2, 0, false, true, 2, 3,
  107. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  108. FMT(BGR565, 0, 5, 6, 5, 2, 0, 1, 0, false, true, 2, 3,
  109. MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
  110. /* --- RGB formats above / YUV formats below this line --- */
  111. /* 2 plane YUV */
  112. FMT(NV12, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 2, 2,
  113. MDP_PLANE_PSEUDO_PLANAR, CHROMA_420, true),
  114. FMT(NV21, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 2, 2,
  115. MDP_PLANE_PSEUDO_PLANAR, CHROMA_420, true),
  116. FMT(NV16, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 2, 2,
  117. MDP_PLANE_PSEUDO_PLANAR, CHROMA_H2V1, true),
  118. FMT(NV61, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 2, 2,
  119. MDP_PLANE_PSEUDO_PLANAR, CHROMA_H2V1, true),
  120. /* 1 plane YUV */
  121. FMT(VYUY, 0, 8, 8, 8, 2, 0, 1, 0, false, true, 2, 4,
  122. MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
  123. FMT(UYVY, 0, 8, 8, 8, 1, 0, 2, 0, false, true, 2, 4,
  124. MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
  125. FMT(YUYV, 0, 8, 8, 8, 0, 1, 0, 2, false, true, 2, 4,
  126. MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
  127. FMT(YVYU, 0, 8, 8, 8, 0, 2, 0, 1, false, true, 2, 4,
  128. MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
  129. /* 3 plane YUV */
  130. FMT(YUV420, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 1, 1,
  131. MDP_PLANE_PLANAR, CHROMA_420, true),
  132. FMT(YVU420, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 1, 1,
  133. MDP_PLANE_PLANAR, CHROMA_420, true),
  134. };
  135. /*
  136. * Note:
  137. * @rgb_only must be set to true, when requesting
  138. * supported formats for RGB pipes.
  139. */
  140. uint32_t mdp_get_formats(uint32_t *pixel_formats, uint32_t max_formats,
  141. bool rgb_only)
  142. {
  143. uint32_t i;
  144. for (i = 0; i < ARRAY_SIZE(formats); i++) {
  145. const struct mdp_format *f = &formats[i];
  146. if (i == max_formats)
  147. break;
  148. if (rgb_only && MDP_FORMAT_IS_YUV(f))
  149. break;
  150. pixel_formats[i] = f->base.pixel_format;
  151. }
  152. return i;
  153. }
  154. const struct msm_format *mdp_get_format(struct msm_kms *kms, uint32_t format)
  155. {
  156. int i;
  157. for (i = 0; i < ARRAY_SIZE(formats); i++) {
  158. const struct mdp_format *f = &formats[i];
  159. if (f->base.pixel_format == format)
  160. return &f->base;
  161. }
  162. return NULL;
  163. }
  164. struct csc_cfg *mdp_get_default_csc_cfg(enum csc_type type)
  165. {
  166. if (unlikely(WARN_ON(type >= CSC_MAX)))
  167. return NULL;
  168. return &csc_convert[type];
  169. }