coda-gdi.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Coda multi-standard codec IP
  4. *
  5. * Copyright (C) 2014 Philipp Zabel, Pengutronix
  6. */
  7. #include <linux/bitops.h>
  8. #include "coda.h"
  9. #define XY2_INVERT BIT(7)
  10. #define XY2_ZERO BIT(6)
  11. #define XY2_TB_XOR BIT(5)
  12. #define XY2_XYSEL BIT(4)
  13. #define XY2_Y (1 << 4)
  14. #define XY2_X (0 << 4)
  15. #define XY2(luma_sel, luma_bit, chroma_sel, chroma_bit) \
  16. (((XY2_##luma_sel) | (luma_bit)) << 8 | \
  17. (XY2_##chroma_sel) | (chroma_bit))
  18. static const u16 xy2ca_zero_map[16] = {
  19. XY2(ZERO, 0, ZERO, 0),
  20. XY2(ZERO, 0, ZERO, 0),
  21. XY2(ZERO, 0, ZERO, 0),
  22. XY2(ZERO, 0, ZERO, 0),
  23. XY2(ZERO, 0, ZERO, 0),
  24. XY2(ZERO, 0, ZERO, 0),
  25. XY2(ZERO, 0, ZERO, 0),
  26. XY2(ZERO, 0, ZERO, 0),
  27. XY2(ZERO, 0, ZERO, 0),
  28. XY2(ZERO, 0, ZERO, 0),
  29. XY2(ZERO, 0, ZERO, 0),
  30. XY2(ZERO, 0, ZERO, 0),
  31. XY2(ZERO, 0, ZERO, 0),
  32. XY2(ZERO, 0, ZERO, 0),
  33. XY2(ZERO, 0, ZERO, 0),
  34. XY2(ZERO, 0, ZERO, 0),
  35. };
  36. static const u16 xy2ca_tiled_map[16] = {
  37. XY2(Y, 0, Y, 0),
  38. XY2(Y, 1, Y, 1),
  39. XY2(Y, 2, Y, 2),
  40. XY2(Y, 3, X, 3),
  41. XY2(X, 3, ZERO, 0),
  42. XY2(ZERO, 0, ZERO, 0),
  43. XY2(ZERO, 0, ZERO, 0),
  44. XY2(ZERO, 0, ZERO, 0),
  45. XY2(ZERO, 0, ZERO, 0),
  46. XY2(ZERO, 0, ZERO, 0),
  47. XY2(ZERO, 0, ZERO, 0),
  48. XY2(ZERO, 0, ZERO, 0),
  49. XY2(ZERO, 0, ZERO, 0),
  50. XY2(ZERO, 0, ZERO, 0),
  51. XY2(ZERO, 0, ZERO, 0),
  52. XY2(ZERO, 0, ZERO, 0),
  53. };
  54. /*
  55. * RA[15:0], CA[15:8] are hardwired to contain the 24-bit macroblock
  56. * start offset (macroblock size is 16x16 for luma, 16x8 for chroma).
  57. * Bits CA[4:0] are set using XY2CA above. BA[3:0] seems to be unused.
  58. */
  59. #define RBC_CA (0 << 4)
  60. #define RBC_BA (1 << 4)
  61. #define RBC_RA (2 << 4)
  62. #define RBC_ZERO (3 << 4)
  63. #define RBC(luma_sel, luma_bit, chroma_sel, chroma_bit) \
  64. (((RBC_##luma_sel) | (luma_bit)) << 6 | \
  65. (RBC_##chroma_sel) | (chroma_bit))
  66. static const u16 rbc2axi_tiled_map[32] = {
  67. RBC(ZERO, 0, ZERO, 0),
  68. RBC(ZERO, 0, ZERO, 0),
  69. RBC(ZERO, 0, ZERO, 0),
  70. RBC(CA, 0, CA, 0),
  71. RBC(CA, 1, CA, 1),
  72. RBC(CA, 2, CA, 2),
  73. RBC(CA, 3, CA, 3),
  74. RBC(CA, 4, CA, 8),
  75. RBC(CA, 8, CA, 9),
  76. RBC(CA, 9, CA, 10),
  77. RBC(CA, 10, CA, 11),
  78. RBC(CA, 11, CA, 12),
  79. RBC(CA, 12, CA, 13),
  80. RBC(CA, 13, CA, 14),
  81. RBC(CA, 14, CA, 15),
  82. RBC(CA, 15, RA, 0),
  83. RBC(RA, 0, RA, 1),
  84. RBC(RA, 1, RA, 2),
  85. RBC(RA, 2, RA, 3),
  86. RBC(RA, 3, RA, 4),
  87. RBC(RA, 4, RA, 5),
  88. RBC(RA, 5, RA, 6),
  89. RBC(RA, 6, RA, 7),
  90. RBC(RA, 7, RA, 8),
  91. RBC(RA, 8, RA, 9),
  92. RBC(RA, 9, RA, 10),
  93. RBC(RA, 10, RA, 11),
  94. RBC(RA, 11, RA, 12),
  95. RBC(RA, 12, RA, 13),
  96. RBC(RA, 13, RA, 14),
  97. RBC(RA, 14, RA, 15),
  98. RBC(RA, 15, ZERO, 0),
  99. };
  100. void coda_set_gdi_regs(struct coda_ctx *ctx)
  101. {
  102. struct coda_dev *dev = ctx->dev;
  103. const u16 *xy2ca_map;
  104. u32 xy2rbc_config;
  105. int i;
  106. switch (ctx->tiled_map_type) {
  107. case GDI_LINEAR_FRAME_MAP:
  108. default:
  109. xy2ca_map = xy2ca_zero_map;
  110. xy2rbc_config = 0;
  111. break;
  112. case GDI_TILED_FRAME_MB_RASTER_MAP:
  113. xy2ca_map = xy2ca_tiled_map;
  114. xy2rbc_config = CODA9_XY2RBC_TILED_MAP |
  115. CODA9_XY2RBC_CA_INC_HOR |
  116. (16 - 1) << 12 | (8 - 1) << 4;
  117. break;
  118. }
  119. for (i = 0; i < 16; i++)
  120. coda_write(dev, xy2ca_map[i],
  121. CODA9_GDI_XY2_CAS_0 + 4 * i);
  122. for (i = 0; i < 4; i++)
  123. coda_write(dev, XY2(ZERO, 0, ZERO, 0),
  124. CODA9_GDI_XY2_BA_0 + 4 * i);
  125. for (i = 0; i < 16; i++)
  126. coda_write(dev, XY2(ZERO, 0, ZERO, 0),
  127. CODA9_GDI_XY2_RAS_0 + 4 * i);
  128. coda_write(dev, xy2rbc_config, CODA9_GDI_XY2_RBC_CONFIG);
  129. if (xy2rbc_config) {
  130. for (i = 0; i < 32; i++)
  131. coda_write(dev, rbc2axi_tiled_map[i],
  132. CODA9_GDI_RBC2_AXI_0 + 4 * i);
  133. }
  134. }