ddp_dsc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2019. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #define LOG_TAG "DSC"
  32. #include "platform/ddp_reg.h"
  33. #include "platform/ddp_info.h"
  34. #include "platform/ddp_log.h"
  35. #include "platform/ddp_reg_dsc.h"
  36. #include "platform/disp_drv_platform.h"
  37. #include "platform/primary_display.h"
  38. int dsc_clock_on(DISP_MODULE_ENUM module, void *handle)
  39. {
  40. DDPDBG("%s clock_on\n", ddp_get_module_name(module));
  41. ddp_enable_module_clock(module);
  42. return 0;
  43. }
  44. int dsc_clock_off(DISP_MODULE_ENUM module, void *handle)
  45. {
  46. DDPDBG("%s clock_off\n", ddp_get_module_name(module));
  47. ddp_disable_module_clock(module);
  48. return 0;
  49. }
  50. int dsc_init(DISP_MODULE_ENUM module, void *handle)
  51. {
  52. return dsc_clock_on(module, handle);
  53. }
  54. int dsc_deinit(DISP_MODULE_ENUM module, void *handle)
  55. {
  56. return dsc_clock_off(module, handle);
  57. }
  58. int dsc_config(DISP_MODULE_ENUM module, disp_ddp_path_config *pConfig,
  59. void *handle)
  60. {
  61. unsigned long base = DISPSYS_DSC_BASE;
  62. unsigned int height = pConfig->dst_h, width = pConfig->dst_w;
  63. unsigned int init_delay_limit, init_delay_height;
  64. unsigned int pic_group_width_m1;
  65. unsigned int pic_height_m1, pic_height_ext_m1, pic_height_ext_num;
  66. unsigned int slice_group_width_m1;
  67. unsigned int pad_num;
  68. unsigned int val;
  69. LCM_DSI_PARAMS *dsi = &pConfig->dsi_config;
  70. LCM_DSC_CONFIG_PARAMS *params = &dsi->dsc_params;
  71. if (dsi->dsc_enable == 0) {
  72. DISP_REG_SET_FIELD(handle, CON_FLD_DSC_EN,
  73. base + DISP_REG_DSC_CON, 0x1);
  74. DISP_REG_SET_FIELD(handle, CON_FLD_DISP_DSC_RELAY,
  75. base + DISP_REG_DSC_CON, 0x1);
  76. DISP_REG_SET(handle, base + DISP_REG_DSC_PIC_H, height - 1);
  77. DISP_REG_SET(handle, base + DISP_REG_DSC_PIC_W, width);
  78. return 0;
  79. }
  80. if (params->pic_width != width || params->pic_height != height) {
  81. DDPERR("%s size mismatch...", __func__);
  82. return 1;
  83. }
  84. val = 0x10001;
  85. DISP_REG_SET(handle, base + DISP_REG_DSC_CON, val);
  86. /* DSC Empty flag always high */
  87. DISP_REG_SET_FIELD(handle, CON_FLD_DSC_EMPTY_FLAG_ALWAYS_HIGH,
  88. base + DISP_REG_DSC_CON, 0x1);
  89. /* DSC output buffer as FHD(plus) */
  90. DISP_REG_SET(handle, base + DISP_REG_DSC_OBUF, 0x800002C2);
  91. init_delay_limit =
  92. ((128 + (params->xmit_delay + 2) / 3) * 3 +
  93. params->slice_width - 1) / params->slice_width;
  94. init_delay_height =
  95. (init_delay_limit > 15) ? 15 : init_delay_limit;
  96. val = params->slice_mode + (init_delay_height << 8) + (1 << 16);
  97. DISP_REG_SET(handle, base + DISP_REG_DSC_MODE, val);
  98. pic_group_width_m1 = (width + 2) / 3 - 1;
  99. DISP_REG_SET(handle, base + DISP_REG_DSC_PIC_W,
  100. (pic_group_width_m1 << 16) + width);
  101. pic_height_m1 = height - 1;
  102. pic_height_ext_num = (height + params->slice_height - 1) /
  103. params->slice_height;
  104. pic_height_ext_m1 = pic_height_ext_num * params->slice_height - 1;
  105. DISP_REG_SET(handle, base + DISP_REG_DSC_PIC_H,
  106. (pic_height_ext_m1 << 16) + pic_height_m1);
  107. slice_group_width_m1 = (params->slice_width + 2) / 3 - 1;
  108. DISP_REG_SET(handle, base + DISP_REG_DSC_SLICE_W,
  109. (slice_group_width_m1 << 16) + params->slice_width);
  110. DISP_REG_SET(handle, base + DISP_REG_DSC_SLICE_H,
  111. ((params->slice_width % 3) << 30) +
  112. ((pic_height_ext_num - 1) << 16) + params->slice_height - 1);
  113. DISP_REG_SET(handle, base + DISP_REG_DSC_CHUNK_SIZE,
  114. params->chunk_size);
  115. DISP_REG_SET(handle, base + DISP_REG_DSC_BUF_SIZE,
  116. params->chunk_size * params->slice_height);
  117. pad_num = (params->chunk_size + 2) / 3 * 3 - params->chunk_size;
  118. DISP_REG_SET(handle, base + DISP_REG_DSC_PAD, pad_num);
  119. if (params->dsc_cfg)
  120. DISP_REG_SET(handle, base + DISP_REG_DSC_CFG, params->dsc_cfg);
  121. else
  122. DISP_REG_SET(handle, base + DISP_REG_DSC_CFG, 0x22);
  123. if ((params->ver & 0xf) == 2)
  124. DISP_REG_SET_FIELD(handle, DSC_FLD_VER,
  125. base + DISP_REG_DSC_SHADOW, 0x2); /* DSC V1.2 */
  126. else
  127. DISP_REG_SET_FIELD(handle, DSC_FLD_VER,
  128. base + DISP_REG_DSC_SHADOW, 0x1); /* DSC V1.1 */
  129. /* set PPS */
  130. val = params->dsc_line_buf_depth + (params->bit_per_channel << 4) +
  131. (params->bit_per_pixel << 8) + (params->rct_on << 18) +
  132. (params->bp_enable << 19);
  133. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS0, val);
  134. val = (params->xmit_delay) + (params->dec_delay << 16);
  135. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS1, val);
  136. val = (params->scale_value) + (params->increment_interval << 16);
  137. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS2, val);
  138. val = (params->decrement_interval) + (params->line_bpg_offset << 16);
  139. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS3, val);
  140. val = (params->nfl_bpg_offset) + (params->slice_bpg_offset << 16);
  141. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS4, val);
  142. val = (params->initial_offset) + (params->final_offset << 16);
  143. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS5, val);
  144. val = (params->flatness_minqp) + (params->flatness_maxqp << 8) +
  145. (params->rc_model_size << 16);
  146. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS6, val);
  147. val = (params->rc_edge_factor) + (params->rc_quant_incr_limit0 << 8) +
  148. (params->rc_quant_incr_limit1 << 16) +
  149. (params->rc_tgt_offset_hi << 24) +
  150. (params->rc_tgt_offset_lo << 28);
  151. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS7, val);
  152. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS8, 0x382a1c0e);
  153. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS9, 0x69625446);
  154. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS10, 0x7b797770);
  155. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS11, 0x7e7d);
  156. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS12, 0x800880);
  157. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS13, 0xf8c100a1);
  158. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS14, 0xe8e3f0e3);
  159. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS15, 0xe103e0e3);
  160. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS16, 0xd943e123);
  161. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS17, 0xd185d965);
  162. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS18, 0xd1a7d1a5);
  163. DISP_REG_SET(handle, base + DISP_REG_DSC_PPS19, 0xd1ed);
  164. return 0;
  165. }
  166. int dsc_dump(DISP_MODULE_ENUM module)
  167. {
  168. unsigned long base = DISPSYS_DSC_BASE;
  169. DDPDUMP("== START: DISP DSC REGS ==\n");
  170. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  171. 0x0, INREG32(base + 0x0),
  172. 0x4, INREG32(base + 0x4),
  173. 0x8, INREG32(base + 0x8),
  174. 0xC, INREG32(base + 0xC));
  175. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  176. 0x10, INREG32(base + 0x10),
  177. 0x18, INREG32(base + 0x18),
  178. 0x1C, INREG32(base + 0x1C));
  179. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  180. 0x20, INREG32(base + 0x20),
  181. 0x24, INREG32(base + 0x24),
  182. 0x28, INREG32(base + 0x28),
  183. 0x2C, INREG32(base + 0x2C));
  184. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  185. 0x30, INREG32(base + 0x30),
  186. 0x34, INREG32(base + 0x34),
  187. 0x38, INREG32(base + 0x38));
  188. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  189. 0x80, INREG32(base + 0x80),
  190. 0x84, INREG32(base + 0x84),
  191. 0x88, INREG32(base + 0x88),
  192. 0x8C, INREG32(base + 0x8C));
  193. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  194. 0x90, INREG32(base + 0x90),
  195. 0x94, INREG32(base + 0x94),
  196. 0x98, INREG32(base + 0x98),
  197. 0x9C, INREG32(base + 0x9C));
  198. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  199. 0xA0, INREG32(base + 0xA0),
  200. 0xA4, INREG32(base + 0xA4),
  201. 0xA8, INREG32(base + 0xA8),
  202. 0xAC, INREG32(base + 0xAC));
  203. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  204. 0xB0, INREG32(base + 0xB0),
  205. 0xB4, INREG32(base + 0xB4),
  206. 0xB8, INREG32(base + 0xB8),
  207. 0xBC, INREG32(base + 0xBC));
  208. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  209. 0xC0, INREG32(base + 0xC0),
  210. 0xC4, INREG32(base + 0xC4),
  211. 0xC8, INREG32(base + 0xC8),
  212. 0xCC, INREG32(base + 0xCC));
  213. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  214. 0x100, INREG32(base + 0x100),
  215. 0x104, INREG32(base + 0x104),
  216. 0x108, INREG32(base + 0x108),
  217. 0x10C, INREG32(base + 0x10C));
  218. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  219. 0x110, INREG32(base + 0x110),
  220. 0x114, INREG32(base + 0x114),
  221. 0x118, INREG32(base + 0x118),
  222. 0x11C, INREG32(base + 0x11C));
  223. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  224. 0x120, INREG32(base + 0x120),
  225. 0x124, INREG32(base + 0x124),
  226. 0x128, INREG32(base + 0x128),
  227. 0x12C, INREG32(base + 0x12C));
  228. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  229. 0x130, INREG32(base + 0x130),
  230. 0x134, INREG32(base + 0x134),
  231. 0x138, INREG32(base + 0x138),
  232. 0x13C, INREG32(base + 0x13C));
  233. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  234. 0x140, INREG32(base + 0x140),
  235. 0x144, INREG32(base + 0x144),
  236. 0x148, INREG32(base + 0x148),
  237. 0x14C, INREG32(base + 0x14C));
  238. DDPDUMP("0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x, 0x%04x=0x%08x\n",
  239. 0x150, INREG32(base + 0x150),
  240. 0x154, INREG32(base + 0x154),
  241. 0x158, INREG32(base + 0x158),
  242. 0x15C, INREG32(base + 0x15C));
  243. DDPDUMP("0x%04x=0x%08x\n", 0x200, INREG32(base + 0x200));
  244. return 0;
  245. }
  246. DDP_MODULE_DRIVER ddp_driver_dsc = {
  247. .init = dsc_init,
  248. .deinit = dsc_deinit,
  249. .config = dsc_config,
  250. .dump_info = dsc_dump,
  251. };