coda-gdi.c 3.7 KB

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