ddp_dither.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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) 2015. 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. #include <debug.h>
  32. #include "ddp_reg.h"
  33. #include "ddp_path.h"
  34. #include "ddp_dither.h"
  35. #include <platform/disp_drv_platform.h>
  36. #define DITHER_REG(reg_base, index) ((reg_base) + 0x100 + (index) * 4)
  37. static void disp_dither_init(disp_dither_id_t id, int width, int height,
  38. unsigned int dither_bpp, void *cmdq)
  39. {
  40. unsigned long reg_base = DISPSYS_DITHER0_BASE;
  41. unsigned int enable;
  42. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 5) , 0x00000000, ~0);
  43. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 6) , 0x00003004, ~0);
  44. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 7) , 0x00000000, ~0);
  45. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 8) , 0x00000000, ~0);
  46. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 9) , 0x00000000, ~0);
  47. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 10) , 0x00000000, ~0);
  48. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 11) , 0x00000000, ~0);
  49. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 12) , 0x00000011, ~0);
  50. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 13) , 0x00000000, ~0);
  51. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 14) , 0x00000000, ~0);
  52. enable = 0x1;
  53. if (dither_bpp == 16) { /* 565 */
  54. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 15), 0x50500001, ~0);
  55. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 16), 0x50504040, ~0);
  56. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 0), 0x00000001, ~0);
  57. } else if (dither_bpp == 18) { /* 666 */
  58. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 15), 0x40400001, ~0);
  59. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 16), 0x40404040, ~0);
  60. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 0), 0x00000001, ~0);
  61. } else if (dither_bpp == 24) { /* 888 */
  62. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 15), 0x20200001, ~0);
  63. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 16), 0x20202020, ~0);
  64. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 0), 0x00000001, ~0);
  65. } else if (dither_bpp > 24) {
  66. dprintf(CRITICAL, "[DITHER] High depth LCM (bpp = %d), no dither\n", dither_bpp);
  67. enable = 1;
  68. } else {
  69. dprintf(CRITICAL, "[DITHER] invalid dither bpp = %d\n", dither_bpp);
  70. /* Bypass dither */
  71. DISP_REG_MASK(cmdq, DITHER_REG(reg_base, 0), 0x00000000, ~0);
  72. enable = 0;
  73. }
  74. DISP_REG_MASK(cmdq, DISP_REG_DITHER_EN, enable, 0x1);
  75. DISP_REG_MASK(cmdq, DISP_REG_DITHER_CFG, enable << 1, 1 << 1);
  76. DISP_REG_SET(cmdq, DISP_REG_DITHER_SIZE, (width << 16) | height);
  77. }
  78. static int disp_dither_config(DISP_MODULE_ENUM module, disp_ddp_path_config* pConfig, void* cmdq)
  79. {
  80. dprintf(CRITICAL, "config dither dirty = %d\n", pConfig->dst_dirty);
  81. if (pConfig->dst_dirty) {
  82. disp_dither_init(DISP_DITHER0, pConfig->dst_w, pConfig->dst_h,
  83. pConfig->lcm_bpp, cmdq);
  84. }
  85. return 0;
  86. }
  87. static int disp_dither_start(DISP_MODULE_ENUM module, void *handle)
  88. {
  89. #ifdef LK_BYPASS_SHADOW_REG
  90. DISP_REG_SET_FIELD(handle, FLD_DITHER_BYPASS_SHADOW,
  91. DISP_REG_DITHER_0, 0x1);
  92. DISP_REG_SET_FIELD(handle, FLD_DITHER_READ_WRK_REG,
  93. DISP_REG_DITHER_0, 0x1);
  94. #endif
  95. return 0;
  96. }
  97. static int disp_dither_bypass(DISP_MODULE_ENUM module, int bypass)
  98. {
  99. int relay = 0;
  100. if (bypass)
  101. relay = 1;
  102. DISP_REG_MASK(NULL, DISP_REG_DITHER_CFG, relay, 0x1);
  103. dprintf(CRITICAL, "disp_dither_bypass(bypass = %d)", bypass);
  104. return 0;
  105. }
  106. static int disp_dither_clock_on(DISP_MODULE_ENUM module,void * handle)
  107. {
  108. ddp_enable_module_clock(module);
  109. return 0;
  110. }
  111. static int disp_dither_clock_off(DISP_MODULE_ENUM module,void * handle)
  112. {
  113. ddp_disable_module_clock(module);
  114. return 0;
  115. }
  116. DDP_MODULE_DRIVER ddp_driver_dither = {
  117. .start = disp_dither_start,
  118. .config = disp_dither_config,
  119. .bypass = disp_dither_bypass,
  120. .init = disp_dither_clock_on,
  121. .deinit = disp_dither_clock_off,
  122. .power_on = disp_dither_clock_on,
  123. .power_off = disp_dither_clock_off,
  124. };