dpu_hw_util.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  13. #include "msm_drv.h"
  14. #include "dpu_kms.h"
  15. #include "dpu_hw_mdss.h"
  16. #include "dpu_hw_util.h"
  17. /* using a file static variables for debugfs access */
  18. static u32 dpu_hw_util_log_mask = DPU_DBG_MASK_NONE;
  19. /* DPU_SCALER_QSEED3 */
  20. #define QSEED3_HW_VERSION 0x00
  21. #define QSEED3_OP_MODE 0x04
  22. #define QSEED3_RGB2Y_COEFF 0x08
  23. #define QSEED3_PHASE_INIT 0x0C
  24. #define QSEED3_PHASE_STEP_Y_H 0x10
  25. #define QSEED3_PHASE_STEP_Y_V 0x14
  26. #define QSEED3_PHASE_STEP_UV_H 0x18
  27. #define QSEED3_PHASE_STEP_UV_V 0x1C
  28. #define QSEED3_PRELOAD 0x20
  29. #define QSEED3_DE_SHARPEN 0x24
  30. #define QSEED3_DE_SHARPEN_CTL 0x28
  31. #define QSEED3_DE_SHAPE_CTL 0x2C
  32. #define QSEED3_DE_THRESHOLD 0x30
  33. #define QSEED3_DE_ADJUST_DATA_0 0x34
  34. #define QSEED3_DE_ADJUST_DATA_1 0x38
  35. #define QSEED3_DE_ADJUST_DATA_2 0x3C
  36. #define QSEED3_SRC_SIZE_Y_RGB_A 0x40
  37. #define QSEED3_SRC_SIZE_UV 0x44
  38. #define QSEED3_DST_SIZE 0x48
  39. #define QSEED3_COEF_LUT_CTRL 0x4C
  40. #define QSEED3_COEF_LUT_SWAP_BIT 0
  41. #define QSEED3_COEF_LUT_DIR_BIT 1
  42. #define QSEED3_COEF_LUT_Y_CIR_BIT 2
  43. #define QSEED3_COEF_LUT_UV_CIR_BIT 3
  44. #define QSEED3_COEF_LUT_Y_SEP_BIT 4
  45. #define QSEED3_COEF_LUT_UV_SEP_BIT 5
  46. #define QSEED3_BUFFER_CTRL 0x50
  47. #define QSEED3_CLK_CTRL0 0x54
  48. #define QSEED3_CLK_CTRL1 0x58
  49. #define QSEED3_CLK_STATUS 0x5C
  50. #define QSEED3_PHASE_INIT_Y_H 0x90
  51. #define QSEED3_PHASE_INIT_Y_V 0x94
  52. #define QSEED3_PHASE_INIT_UV_H 0x98
  53. #define QSEED3_PHASE_INIT_UV_V 0x9C
  54. #define QSEED3_COEF_LUT 0x100
  55. #define QSEED3_FILTERS 5
  56. #define QSEED3_LUT_REGIONS 4
  57. #define QSEED3_CIRCULAR_LUTS 9
  58. #define QSEED3_SEPARABLE_LUTS 10
  59. #define QSEED3_LUT_SIZE 60
  60. #define QSEED3_ENABLE 2
  61. #define QSEED3_DIR_LUT_SIZE (200 * sizeof(u32))
  62. #define QSEED3_CIR_LUT_SIZE \
  63. (QSEED3_LUT_SIZE * QSEED3_CIRCULAR_LUTS * sizeof(u32))
  64. #define QSEED3_SEP_LUT_SIZE \
  65. (QSEED3_LUT_SIZE * QSEED3_SEPARABLE_LUTS * sizeof(u32))
  66. void dpu_reg_write(struct dpu_hw_blk_reg_map *c,
  67. u32 reg_off,
  68. u32 val,
  69. const char *name)
  70. {
  71. /* don't need to mutex protect this */
  72. if (c->log_mask & dpu_hw_util_log_mask)
  73. DPU_DEBUG_DRIVER("[%s:0x%X] <= 0x%X\n",
  74. name, c->blk_off + reg_off, val);
  75. writel_relaxed(val, c->base_off + c->blk_off + reg_off);
  76. }
  77. int dpu_reg_read(struct dpu_hw_blk_reg_map *c, u32 reg_off)
  78. {
  79. return readl_relaxed(c->base_off + c->blk_off + reg_off);
  80. }
  81. u32 *dpu_hw_util_get_log_mask_ptr(void)
  82. {
  83. return &dpu_hw_util_log_mask;
  84. }
  85. static void _dpu_hw_setup_scaler3_lut(struct dpu_hw_blk_reg_map *c,
  86. struct dpu_hw_scaler3_cfg *scaler3_cfg, u32 offset)
  87. {
  88. int i, j, filter;
  89. int config_lut = 0x0;
  90. unsigned long lut_flags;
  91. u32 lut_addr, lut_offset, lut_len;
  92. u32 *lut[QSEED3_FILTERS] = {NULL, NULL, NULL, NULL, NULL};
  93. static const uint32_t off_tbl[QSEED3_FILTERS][QSEED3_LUT_REGIONS][2] = {
  94. {{18, 0x000}, {12, 0x120}, {12, 0x1E0}, {8, 0x2A0} },
  95. {{6, 0x320}, {3, 0x3E0}, {3, 0x440}, {3, 0x4A0} },
  96. {{6, 0x500}, {3, 0x5c0}, {3, 0x620}, {3, 0x680} },
  97. {{6, 0x380}, {3, 0x410}, {3, 0x470}, {3, 0x4d0} },
  98. {{6, 0x560}, {3, 0x5f0}, {3, 0x650}, {3, 0x6b0} },
  99. };
  100. lut_flags = (unsigned long) scaler3_cfg->lut_flag;
  101. if (test_bit(QSEED3_COEF_LUT_DIR_BIT, &lut_flags) &&
  102. (scaler3_cfg->dir_len == QSEED3_DIR_LUT_SIZE)) {
  103. lut[0] = scaler3_cfg->dir_lut;
  104. config_lut = 1;
  105. }
  106. if (test_bit(QSEED3_COEF_LUT_Y_CIR_BIT, &lut_flags) &&
  107. (scaler3_cfg->y_rgb_cir_lut_idx < QSEED3_CIRCULAR_LUTS) &&
  108. (scaler3_cfg->cir_len == QSEED3_CIR_LUT_SIZE)) {
  109. lut[1] = scaler3_cfg->cir_lut +
  110. scaler3_cfg->y_rgb_cir_lut_idx * QSEED3_LUT_SIZE;
  111. config_lut = 1;
  112. }
  113. if (test_bit(QSEED3_COEF_LUT_UV_CIR_BIT, &lut_flags) &&
  114. (scaler3_cfg->uv_cir_lut_idx < QSEED3_CIRCULAR_LUTS) &&
  115. (scaler3_cfg->cir_len == QSEED3_CIR_LUT_SIZE)) {
  116. lut[2] = scaler3_cfg->cir_lut +
  117. scaler3_cfg->uv_cir_lut_idx * QSEED3_LUT_SIZE;
  118. config_lut = 1;
  119. }
  120. if (test_bit(QSEED3_COEF_LUT_Y_SEP_BIT, &lut_flags) &&
  121. (scaler3_cfg->y_rgb_sep_lut_idx < QSEED3_SEPARABLE_LUTS) &&
  122. (scaler3_cfg->sep_len == QSEED3_SEP_LUT_SIZE)) {
  123. lut[3] = scaler3_cfg->sep_lut +
  124. scaler3_cfg->y_rgb_sep_lut_idx * QSEED3_LUT_SIZE;
  125. config_lut = 1;
  126. }
  127. if (test_bit(QSEED3_COEF_LUT_UV_SEP_BIT, &lut_flags) &&
  128. (scaler3_cfg->uv_sep_lut_idx < QSEED3_SEPARABLE_LUTS) &&
  129. (scaler3_cfg->sep_len == QSEED3_SEP_LUT_SIZE)) {
  130. lut[4] = scaler3_cfg->sep_lut +
  131. scaler3_cfg->uv_sep_lut_idx * QSEED3_LUT_SIZE;
  132. config_lut = 1;
  133. }
  134. if (config_lut) {
  135. for (filter = 0; filter < QSEED3_FILTERS; filter++) {
  136. if (!lut[filter])
  137. continue;
  138. lut_offset = 0;
  139. for (i = 0; i < QSEED3_LUT_REGIONS; i++) {
  140. lut_addr = QSEED3_COEF_LUT + offset
  141. + off_tbl[filter][i][1];
  142. lut_len = off_tbl[filter][i][0] << 2;
  143. for (j = 0; j < lut_len; j++) {
  144. DPU_REG_WRITE(c,
  145. lut_addr,
  146. (lut[filter])[lut_offset++]);
  147. lut_addr += 4;
  148. }
  149. }
  150. }
  151. }
  152. if (test_bit(QSEED3_COEF_LUT_SWAP_BIT, &lut_flags))
  153. DPU_REG_WRITE(c, QSEED3_COEF_LUT_CTRL + offset, BIT(0));
  154. }
  155. static void _dpu_hw_setup_scaler3_de(struct dpu_hw_blk_reg_map *c,
  156. struct dpu_hw_scaler3_de_cfg *de_cfg, u32 offset)
  157. {
  158. u32 sharp_lvl, sharp_ctl, shape_ctl, de_thr;
  159. u32 adjust_a, adjust_b, adjust_c;
  160. if (!de_cfg->enable)
  161. return;
  162. sharp_lvl = (de_cfg->sharpen_level1 & 0x1FF) |
  163. ((de_cfg->sharpen_level2 & 0x1FF) << 16);
  164. sharp_ctl = ((de_cfg->limit & 0xF) << 9) |
  165. ((de_cfg->prec_shift & 0x7) << 13) |
  166. ((de_cfg->clip & 0x7) << 16);
  167. shape_ctl = (de_cfg->thr_quiet & 0xFF) |
  168. ((de_cfg->thr_dieout & 0x3FF) << 16);
  169. de_thr = (de_cfg->thr_low & 0x3FF) |
  170. ((de_cfg->thr_high & 0x3FF) << 16);
  171. adjust_a = (de_cfg->adjust_a[0] & 0x3FF) |
  172. ((de_cfg->adjust_a[1] & 0x3FF) << 10) |
  173. ((de_cfg->adjust_a[2] & 0x3FF) << 20);
  174. adjust_b = (de_cfg->adjust_b[0] & 0x3FF) |
  175. ((de_cfg->adjust_b[1] & 0x3FF) << 10) |
  176. ((de_cfg->adjust_b[2] & 0x3FF) << 20);
  177. adjust_c = (de_cfg->adjust_c[0] & 0x3FF) |
  178. ((de_cfg->adjust_c[1] & 0x3FF) << 10) |
  179. ((de_cfg->adjust_c[2] & 0x3FF) << 20);
  180. DPU_REG_WRITE(c, QSEED3_DE_SHARPEN + offset, sharp_lvl);
  181. DPU_REG_WRITE(c, QSEED3_DE_SHARPEN_CTL + offset, sharp_ctl);
  182. DPU_REG_WRITE(c, QSEED3_DE_SHAPE_CTL + offset, shape_ctl);
  183. DPU_REG_WRITE(c, QSEED3_DE_THRESHOLD + offset, de_thr);
  184. DPU_REG_WRITE(c, QSEED3_DE_ADJUST_DATA_0 + offset, adjust_a);
  185. DPU_REG_WRITE(c, QSEED3_DE_ADJUST_DATA_1 + offset, adjust_b);
  186. DPU_REG_WRITE(c, QSEED3_DE_ADJUST_DATA_2 + offset, adjust_c);
  187. }
  188. void dpu_hw_setup_scaler3(struct dpu_hw_blk_reg_map *c,
  189. struct dpu_hw_scaler3_cfg *scaler3_cfg,
  190. u32 scaler_offset, u32 scaler_version,
  191. const struct dpu_format *format)
  192. {
  193. u32 op_mode = 0;
  194. u32 phase_init, preload, src_y_rgb, src_uv, dst;
  195. if (!scaler3_cfg->enable)
  196. goto end;
  197. op_mode |= BIT(0);
  198. op_mode |= (scaler3_cfg->y_rgb_filter_cfg & 0x3) << 16;
  199. if (format && DPU_FORMAT_IS_YUV(format)) {
  200. op_mode |= BIT(12);
  201. op_mode |= (scaler3_cfg->uv_filter_cfg & 0x3) << 24;
  202. }
  203. op_mode |= (scaler3_cfg->blend_cfg & 1) << 31;
  204. op_mode |= (scaler3_cfg->dir_en) ? BIT(4) : 0;
  205. preload =
  206. ((scaler3_cfg->preload_x[0] & 0x7F) << 0) |
  207. ((scaler3_cfg->preload_y[0] & 0x7F) << 8) |
  208. ((scaler3_cfg->preload_x[1] & 0x7F) << 16) |
  209. ((scaler3_cfg->preload_y[1] & 0x7F) << 24);
  210. src_y_rgb = (scaler3_cfg->src_width[0] & 0x1FFFF) |
  211. ((scaler3_cfg->src_height[0] & 0x1FFFF) << 16);
  212. src_uv = (scaler3_cfg->src_width[1] & 0x1FFFF) |
  213. ((scaler3_cfg->src_height[1] & 0x1FFFF) << 16);
  214. dst = (scaler3_cfg->dst_width & 0x1FFFF) |
  215. ((scaler3_cfg->dst_height & 0x1FFFF) << 16);
  216. if (scaler3_cfg->de.enable) {
  217. _dpu_hw_setup_scaler3_de(c, &scaler3_cfg->de, scaler_offset);
  218. op_mode |= BIT(8);
  219. }
  220. if (scaler3_cfg->lut_flag)
  221. _dpu_hw_setup_scaler3_lut(c, scaler3_cfg,
  222. scaler_offset);
  223. if (scaler_version == 0x1002) {
  224. phase_init =
  225. ((scaler3_cfg->init_phase_x[0] & 0x3F) << 0) |
  226. ((scaler3_cfg->init_phase_y[0] & 0x3F) << 8) |
  227. ((scaler3_cfg->init_phase_x[1] & 0x3F) << 16) |
  228. ((scaler3_cfg->init_phase_y[1] & 0x3F) << 24);
  229. DPU_REG_WRITE(c, QSEED3_PHASE_INIT + scaler_offset, phase_init);
  230. } else {
  231. DPU_REG_WRITE(c, QSEED3_PHASE_INIT_Y_H + scaler_offset,
  232. scaler3_cfg->init_phase_x[0] & 0x1FFFFF);
  233. DPU_REG_WRITE(c, QSEED3_PHASE_INIT_Y_V + scaler_offset,
  234. scaler3_cfg->init_phase_y[0] & 0x1FFFFF);
  235. DPU_REG_WRITE(c, QSEED3_PHASE_INIT_UV_H + scaler_offset,
  236. scaler3_cfg->init_phase_x[1] & 0x1FFFFF);
  237. DPU_REG_WRITE(c, QSEED3_PHASE_INIT_UV_V + scaler_offset,
  238. scaler3_cfg->init_phase_y[1] & 0x1FFFFF);
  239. }
  240. DPU_REG_WRITE(c, QSEED3_PHASE_STEP_Y_H + scaler_offset,
  241. scaler3_cfg->phase_step_x[0] & 0xFFFFFF);
  242. DPU_REG_WRITE(c, QSEED3_PHASE_STEP_Y_V + scaler_offset,
  243. scaler3_cfg->phase_step_y[0] & 0xFFFFFF);
  244. DPU_REG_WRITE(c, QSEED3_PHASE_STEP_UV_H + scaler_offset,
  245. scaler3_cfg->phase_step_x[1] & 0xFFFFFF);
  246. DPU_REG_WRITE(c, QSEED3_PHASE_STEP_UV_V + scaler_offset,
  247. scaler3_cfg->phase_step_y[1] & 0xFFFFFF);
  248. DPU_REG_WRITE(c, QSEED3_PRELOAD + scaler_offset, preload);
  249. DPU_REG_WRITE(c, QSEED3_SRC_SIZE_Y_RGB_A + scaler_offset, src_y_rgb);
  250. DPU_REG_WRITE(c, QSEED3_SRC_SIZE_UV + scaler_offset, src_uv);
  251. DPU_REG_WRITE(c, QSEED3_DST_SIZE + scaler_offset, dst);
  252. end:
  253. if (format && !DPU_FORMAT_IS_DX(format))
  254. op_mode |= BIT(14);
  255. if (format && format->alpha_enable) {
  256. op_mode |= BIT(10);
  257. if (scaler_version == 0x1002)
  258. op_mode |= (scaler3_cfg->alpha_filter_cfg & 0x1) << 30;
  259. else
  260. op_mode |= (scaler3_cfg->alpha_filter_cfg & 0x3) << 29;
  261. }
  262. DPU_REG_WRITE(c, QSEED3_OP_MODE + scaler_offset, op_mode);
  263. }
  264. u32 dpu_hw_get_scaler3_ver(struct dpu_hw_blk_reg_map *c,
  265. u32 scaler_offset)
  266. {
  267. return DPU_REG_READ(c, QSEED3_HW_VERSION + scaler_offset);
  268. }
  269. void dpu_hw_csc_setup(struct dpu_hw_blk_reg_map *c,
  270. u32 csc_reg_off,
  271. struct dpu_csc_cfg *data, bool csc10)
  272. {
  273. static const u32 matrix_shift = 7;
  274. u32 clamp_shift = csc10 ? 16 : 8;
  275. u32 val;
  276. /* matrix coeff - convert S15.16 to S4.9 */
  277. val = ((data->csc_mv[0] >> matrix_shift) & 0x1FFF) |
  278. (((data->csc_mv[1] >> matrix_shift) & 0x1FFF) << 16);
  279. DPU_REG_WRITE(c, csc_reg_off, val);
  280. val = ((data->csc_mv[2] >> matrix_shift) & 0x1FFF) |
  281. (((data->csc_mv[3] >> matrix_shift) & 0x1FFF) << 16);
  282. DPU_REG_WRITE(c, csc_reg_off + 0x4, val);
  283. val = ((data->csc_mv[4] >> matrix_shift) & 0x1FFF) |
  284. (((data->csc_mv[5] >> matrix_shift) & 0x1FFF) << 16);
  285. DPU_REG_WRITE(c, csc_reg_off + 0x8, val);
  286. val = ((data->csc_mv[6] >> matrix_shift) & 0x1FFF) |
  287. (((data->csc_mv[7] >> matrix_shift) & 0x1FFF) << 16);
  288. DPU_REG_WRITE(c, csc_reg_off + 0xc, val);
  289. val = (data->csc_mv[8] >> matrix_shift) & 0x1FFF;
  290. DPU_REG_WRITE(c, csc_reg_off + 0x10, val);
  291. /* Pre clamp */
  292. val = (data->csc_pre_lv[0] << clamp_shift) | data->csc_pre_lv[1];
  293. DPU_REG_WRITE(c, csc_reg_off + 0x14, val);
  294. val = (data->csc_pre_lv[2] << clamp_shift) | data->csc_pre_lv[3];
  295. DPU_REG_WRITE(c, csc_reg_off + 0x18, val);
  296. val = (data->csc_pre_lv[4] << clamp_shift) | data->csc_pre_lv[5];
  297. DPU_REG_WRITE(c, csc_reg_off + 0x1c, val);
  298. /* Post clamp */
  299. val = (data->csc_post_lv[0] << clamp_shift) | data->csc_post_lv[1];
  300. DPU_REG_WRITE(c, csc_reg_off + 0x20, val);
  301. val = (data->csc_post_lv[2] << clamp_shift) | data->csc_post_lv[3];
  302. DPU_REG_WRITE(c, csc_reg_off + 0x24, val);
  303. val = (data->csc_post_lv[4] << clamp_shift) | data->csc_post_lv[5];
  304. DPU_REG_WRITE(c, csc_reg_off + 0x28, val);
  305. /* Pre-Bias */
  306. DPU_REG_WRITE(c, csc_reg_off + 0x2c, data->csc_pre_bv[0]);
  307. DPU_REG_WRITE(c, csc_reg_off + 0x30, data->csc_pre_bv[1]);
  308. DPU_REG_WRITE(c, csc_reg_off + 0x34, data->csc_pre_bv[2]);
  309. /* Post-Bias */
  310. DPU_REG_WRITE(c, csc_reg_off + 0x38, data->csc_post_bv[0]);
  311. DPU_REG_WRITE(c, csc_reg_off + 0x3c, data->csc_post_bv[1]);
  312. DPU_REG_WRITE(c, csc_reg_off + 0x40, data->csc_post_bv[2]);
  313. }