tidss_scale_coefs.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
  4. * Author: Jyri Sarha <jsarha@ti.com>
  5. */
  6. #include <linux/device.h>
  7. #include <linux/kernel.h>
  8. #include "tidss_scale_coefs.h"
  9. /*
  10. * These are interpolated with a custom python script from DSS5
  11. * (drivers/gpu/drm/omapdrm/dss/dispc_coef.c) coefficients.
  12. */
  13. static const struct tidss_scale_coefs coef5_m32 = {
  14. .c2 = { 28, 34, 40, 46, 52, 58, 64, 70, 0, 2, 4, 8, 12, 16, 20, 24, },
  15. .c1 = { 132, 138, 144, 150, 156, 162, 168, 174, 76, 84, 92, 98, 104, 110, 116, 124, },
  16. .c0 = { 192, 192, 192, 190, 188, 186, 184, 182, 180, },
  17. };
  18. static const struct tidss_scale_coefs coef5_m26 = {
  19. .c2 = { 24, 28, 32, 38, 44, 50, 56, 64, 0, 2, 4, 6, 8, 12, 16, 20, },
  20. .c1 = { 132, 138, 144, 152, 160, 166, 172, 178, 72, 80, 88, 94, 100, 108, 116, 124, },
  21. .c0 = { 200, 202, 204, 202, 200, 196, 192, 188, 184, },
  22. };
  23. static const struct tidss_scale_coefs coef5_m22 = {
  24. .c2 = { 16, 20, 24, 30, 36, 42, 48, 56, 0, 0, 0, 2, 4, 8, 12, 14, },
  25. .c1 = { 132, 140, 148, 156, 164, 172, 180, 186, 64, 72, 80, 88, 96, 104, 112, 122, },
  26. .c0 = { 216, 216, 216, 214, 212, 208, 204, 198, 192, },
  27. };
  28. static const struct tidss_scale_coefs coef5_m19 = {
  29. .c2 = { 12, 14, 16, 22, 28, 34, 40, 48, 0, 0, 0, 2, 4, 4, 4, 8, },
  30. .c1 = { 128, 140, 152, 160, 168, 176, 184, 192, 56, 64, 72, 82, 92, 100, 108, 118, },
  31. .c0 = { 232, 232, 232, 226, 220, 218, 216, 208, 200, },
  32. };
  33. static const struct tidss_scale_coefs coef5_m16 = {
  34. .c2 = { 0, 2, 4, 8, 12, 18, 24, 32, 0, 0, 0, -2, -4, -4, -4, -2, },
  35. .c1 = { 124, 138, 152, 164, 176, 186, 196, 206, 40, 48, 56, 68, 80, 90, 100, 112, },
  36. .c0 = { 264, 262, 260, 254, 248, 242, 236, 226, 216, },
  37. };
  38. static const struct tidss_scale_coefs coef5_m14 = {
  39. .c2 = { -8, -6, -4, -2, 0, 6, 12, 18, 0, -2, -4, -6, -8, -8, -8, -8, },
  40. .c1 = { 120, 134, 148, 164, 180, 194, 208, 220, 24, 32, 40, 52, 64, 78, 92, 106, },
  41. .c0 = { 288, 286, 284, 280, 276, 266, 256, 244, 232, },
  42. };
  43. static const struct tidss_scale_coefs coef5_m13 = {
  44. .c2 = { -12, -12, -12, -10, -8, -4, 0, 6, 0, -2, -4, -6, -8, -10, -12, -12, },
  45. .c1 = { 112, 130, 148, 164, 180, 196, 212, 228, 12, 22, 32, 44, 56, 70, 84, 98, },
  46. .c0 = { 312, 308, 304, 298, 292, 282, 272, 258, 244, },
  47. };
  48. static const struct tidss_scale_coefs coef5_m12 = {
  49. .c2 = { -16, -18, -20, -18, -16, -14, -12, -6, 0, -2, -4, -6, -8, -10, -12, -14, },
  50. .c1 = { 104, 124, 144, 164, 184, 202, 220, 238, 0, 10, 20, 30, 40, 56, 72, 88, },
  51. .c0 = { 336, 332, 328, 320, 312, 300, 288, 272, 256, },
  52. };
  53. static const struct tidss_scale_coefs coef5_m11 = {
  54. .c2 = { -20, -22, -24, -24, -24, -24, -24, -20, 0, -2, -4, -6, -8, -10, -12, -16, },
  55. .c1 = { 92, 114, 136, 158, 180, 204, 228, 250, -16, -8, 0, 12, 24, 38, 52, 72, },
  56. .c0 = { 368, 364, 360, 350, 340, 326, 312, 292, 272, },
  57. };
  58. static const struct tidss_scale_coefs coef5_m10 = {
  59. .c2 = { -16, -20, -24, -28, -32, -34, -36, -34, 0, 0, 0, -2, -4, -8, -12, -14, },
  60. .c1 = { 72, 96, 120, 148, 176, 204, 232, 260, -32, -26, -20, -10, 0, 16, 32, 52, },
  61. .c0 = { 400, 398, 396, 384, 372, 354, 336, 312, 288, },
  62. };
  63. static const struct tidss_scale_coefs coef5_m9 = {
  64. .c2 = { -12, -18, -24, -28, -32, -38, -44, -46, 0, 2, 4, 2, 0, -2, -4, -8, },
  65. .c1 = { 40, 68, 96, 128, 160, 196, 232, 268, -48, -46, -44, -36, -28, -14, 0, 20, },
  66. .c0 = { 456, 450, 444, 428, 412, 388, 364, 334, 304, },
  67. };
  68. static const struct tidss_scale_coefs coef5_m8 = {
  69. .c2 = { 0, -4, -8, -16, -24, -32, -40, -48, 0, 2, 4, 6, 8, 6, 4, 2, },
  70. .c1 = { 0, 28, 56, 94, 132, 176, 220, 266, -56, -60, -64, -62, -60, -50, -40, -20, },
  71. .c0 = { 512, 506, 500, 478, 456, 424, 392, 352, 312, },
  72. };
  73. static const struct tidss_scale_coefs coef3_m32 = {
  74. .c1 = { 108, 92, 76, 62, 48, 36, 24, 140, 256, 236, 216, 198, 180, 162, 144, 126, },
  75. .c0 = { 296, 294, 292, 288, 284, 278, 272, 136, 256, },
  76. };
  77. static const struct tidss_scale_coefs coef3_m26 = {
  78. .c1 = { 104, 90, 76, 60, 44, 32, 20, 138, 256, 236, 216, 198, 180, 160, 140, 122, },
  79. .c0 = { 304, 300, 296, 292, 288, 282, 276, 138, 256, },
  80. };
  81. static const struct tidss_scale_coefs coef3_m22 = {
  82. .c1 = { 100, 84, 68, 54, 40, 30, 20, 138, 256, 236, 216, 196, 176, 156, 136, 118, },
  83. .c0 = { 312, 310, 308, 302, 296, 286, 276, 138, 256, },
  84. };
  85. static const struct tidss_scale_coefs coef3_m19 = {
  86. .c1 = { 96, 80, 64, 50, 36, 26, 16, 136, 256, 236, 216, 194, 172, 152, 132, 114, },
  87. .c0 = { 320, 318, 316, 310, 304, 292, 280, 140, 256, },
  88. };
  89. static const struct tidss_scale_coefs coef3_m16 = {
  90. .c1 = { 88, 72, 56, 44, 32, 22, 12, 134, 256, 234, 212, 190, 168, 148, 128, 108, },
  91. .c0 = { 336, 332, 328, 320, 312, 300, 288, 144, 256, },
  92. };
  93. static const struct tidss_scale_coefs coef3_m14 = {
  94. .c1 = { 80, 64, 48, 36, 24, 16, 8, 132, 256, 232, 208, 186, 164, 142, 120, 100, },
  95. .c0 = { 352, 348, 344, 334, 324, 310, 296, 148, 256, },
  96. };
  97. static const struct tidss_scale_coefs coef3_m13 = {
  98. .c1 = { 72, 56, 40, 30, 20, 12, 4, 130, 256, 232, 208, 184, 160, 136, 112, 92, },
  99. .c0 = { 368, 364, 360, 346, 332, 316, 300, 150, 256, },
  100. };
  101. static const struct tidss_scale_coefs coef3_m12 = {
  102. .c1 = { 64, 50, 36, 26, 16, 10, 4, 130, 256, 230, 204, 178, 152, 128, 104, 84, },
  103. .c0 = { 384, 378, 372, 358, 344, 324, 304, 152, 256, },
  104. };
  105. static const struct tidss_scale_coefs coef3_m11 = {
  106. .c1 = { 56, 40, 24, 16, 8, 4, 0, 128, 256, 228, 200, 172, 144, 120, 96, 76, },
  107. .c0 = { 400, 396, 392, 376, 360, 336, 312, 156, 256, },
  108. };
  109. static const struct tidss_scale_coefs coef3_m10 = {
  110. .c1 = { 40, 26, 12, 6, 0, -2, -4, 126, 256, 226, 196, 166, 136, 110, 84, 62, },
  111. .c0 = { 432, 424, 416, 396, 376, 348, 320, 160, 256, },
  112. };
  113. static const struct tidss_scale_coefs coef3_m9 = {
  114. .c1 = { 24, 12, 0, -4, -8, -8, -8, 124, 256, 222, 188, 154, 120, 92, 64, 44, },
  115. .c0 = { 464, 456, 448, 424, 400, 366, 332, 166, 256, },
  116. };
  117. static const struct tidss_scale_coefs coef3_m8 = {
  118. .c1 = { 0, -8, -16, -16, -16, -12, -8, 124, 256, 214, 172, 134, 96, 66, 36, 18, },
  119. .c0 = { 512, 502, 492, 462, 432, 390, 348, 174, 256, },
  120. };
  121. const struct tidss_scale_coefs *tidss_get_scale_coefs(struct device *dev,
  122. u32 firinc,
  123. bool five_taps)
  124. {
  125. int i;
  126. int inc;
  127. static const struct {
  128. int mmin;
  129. int mmax;
  130. const struct tidss_scale_coefs *coef3;
  131. const struct tidss_scale_coefs *coef5;
  132. const char *name;
  133. } coefs[] = {
  134. { 27, 32, &coef3_m32, &coef5_m32, "M32" },
  135. { 23, 26, &coef3_m26, &coef5_m26, "M26" },
  136. { 20, 22, &coef3_m22, &coef5_m22, "M22" },
  137. { 17, 19, &coef3_m19, &coef5_m19, "M19" },
  138. { 15, 16, &coef3_m16, &coef5_m16, "M16" },
  139. { 14, 14, &coef3_m14, &coef5_m14, "M14" },
  140. { 13, 13, &coef3_m13, &coef5_m13, "M13" },
  141. { 12, 12, &coef3_m12, &coef5_m12, "M12" },
  142. { 11, 11, &coef3_m11, &coef5_m11, "M11" },
  143. { 10, 10, &coef3_m10, &coef5_m10, "M10" },
  144. { 9, 9, &coef3_m9, &coef5_m9, "M9" },
  145. { 4, 8, &coef3_m8, &coef5_m8, "M8" },
  146. /*
  147. * When upscaling more than two times, blockiness and outlines
  148. * around the image are observed when M8 tables are used. M11,
  149. * M16 and M19 tables are used to prevent this.
  150. */
  151. { 3, 3, &coef3_m11, &coef5_m11, "M11" },
  152. { 2, 2, &coef3_m16, &coef5_m16, "M16" },
  153. { 0, 1, &coef3_m19, &coef5_m19, "M19" },
  154. };
  155. /*
  156. * inc is result of 0x200000 * in_size / out_size. This dividing
  157. * by 0x40000 scales it down to 8 * in_size / out_size. After
  158. * division the actual scaling factor is 8/inc.
  159. */
  160. inc = firinc / 0x40000;
  161. for (i = 0; i < ARRAY_SIZE(coefs); ++i) {
  162. if (inc >= coefs[i].mmin && inc <= coefs[i].mmax) {
  163. if (five_taps)
  164. return coefs[i].coef5;
  165. else
  166. return coefs[i].coef3;
  167. }
  168. }
  169. dev_err(dev, "%s: Coefficients not found for firinc 0x%08x, inc %d\n",
  170. __func__, firinc, inc);
  171. return NULL;
  172. }