ddp_dither.c 5.2 KB

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