intel_dp_aux_backlight.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright © 2015 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. */
  24. #include "intel_drv.h"
  25. static void set_aux_backlight_enable(struct intel_dp *intel_dp, bool enable)
  26. {
  27. uint8_t reg_val = 0;
  28. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_EDP_DISPLAY_CONTROL_REGISTER,
  29. &reg_val) < 0) {
  30. DRM_DEBUG_KMS("Failed to read DPCD register 0x%x\n",
  31. DP_EDP_DISPLAY_CONTROL_REGISTER);
  32. return;
  33. }
  34. if (enable)
  35. reg_val |= DP_EDP_BACKLIGHT_ENABLE;
  36. else
  37. reg_val &= ~(DP_EDP_BACKLIGHT_ENABLE);
  38. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_DISPLAY_CONTROL_REGISTER,
  39. reg_val) != 1) {
  40. DRM_DEBUG_KMS("Failed to %s aux backlight\n",
  41. enable ? "enable" : "disable");
  42. }
  43. }
  44. /*
  45. * Read the current backlight value from DPCD register(s) based
  46. * on if 8-bit(MSB) or 16-bit(MSB and LSB) values are supported
  47. */
  48. static uint32_t intel_dp_aux_get_backlight(struct intel_connector *connector)
  49. {
  50. struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
  51. uint8_t read_val[2] = { 0x0 };
  52. uint16_t level = 0;
  53. if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_BACKLIGHT_BRIGHTNESS_MSB,
  54. &read_val, sizeof(read_val)) < 0) {
  55. DRM_DEBUG_KMS("Failed to read DPCD register 0x%x\n",
  56. DP_EDP_BACKLIGHT_BRIGHTNESS_MSB);
  57. return 0;
  58. }
  59. level = read_val[0];
  60. if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_BRIGHTNESS_BYTE_COUNT)
  61. level = (read_val[0] << 8 | read_val[1]);
  62. return level;
  63. }
  64. /*
  65. * Sends the current backlight level over the aux channel, checking if its using
  66. * 8-bit or 16 bit value (MSB and LSB)
  67. */
  68. static void
  69. intel_dp_aux_set_backlight(struct intel_connector *connector, u32 level)
  70. {
  71. struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
  72. uint8_t vals[2] = { 0x0 };
  73. vals[0] = level;
  74. /* Write the MSB and/or LSB */
  75. if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_BRIGHTNESS_BYTE_COUNT) {
  76. vals[0] = (level & 0xFF00) >> 8;
  77. vals[1] = (level & 0xFF);
  78. }
  79. if (drm_dp_dpcd_write(&intel_dp->aux, DP_EDP_BACKLIGHT_BRIGHTNESS_MSB,
  80. vals, sizeof(vals)) < 0) {
  81. DRM_DEBUG_KMS("Failed to write aux backlight level\n");
  82. return;
  83. }
  84. }
  85. static void intel_dp_aux_enable_backlight(struct intel_connector *connector)
  86. {
  87. struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
  88. uint8_t dpcd_buf = 0;
  89. set_aux_backlight_enable(intel_dp, true);
  90. if ((drm_dp_dpcd_readb(&intel_dp->aux,
  91. DP_EDP_BACKLIGHT_MODE_SET_REGISTER, &dpcd_buf) == 1) &&
  92. ((dpcd_buf & DP_EDP_BACKLIGHT_CONTROL_MODE_MASK) ==
  93. DP_EDP_BACKLIGHT_CONTROL_MODE_PRESET))
  94. drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_BACKLIGHT_MODE_SET_REGISTER,
  95. (dpcd_buf | DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD));
  96. }
  97. static void intel_dp_aux_disable_backlight(struct intel_connector *connector)
  98. {
  99. set_aux_backlight_enable(enc_to_intel_dp(&connector->encoder->base), false);
  100. }
  101. static int intel_dp_aux_setup_backlight(struct intel_connector *connector,
  102. enum pipe pipe)
  103. {
  104. struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
  105. struct intel_panel *panel = &connector->panel;
  106. intel_dp_aux_enable_backlight(connector);
  107. if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_BRIGHTNESS_BYTE_COUNT)
  108. panel->backlight.max = 0xFFFF;
  109. else
  110. panel->backlight.max = 0xFF;
  111. panel->backlight.min = 0;
  112. panel->backlight.level = intel_dp_aux_get_backlight(connector);
  113. panel->backlight.enabled = panel->backlight.level != 0;
  114. return 0;
  115. }
  116. static bool
  117. intel_dp_aux_display_control_capable(struct intel_connector *connector)
  118. {
  119. struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
  120. /* Check the eDP Display control capabilities registers to determine if
  121. * the panel can support backlight control over the aux channel
  122. */
  123. if (intel_dp->edp_dpcd[1] & DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP &&
  124. (intel_dp->edp_dpcd[1] & DP_EDP_BACKLIGHT_AUX_ENABLE_CAP) &&
  125. !((intel_dp->edp_dpcd[1] & DP_EDP_BACKLIGHT_PIN_ENABLE_CAP) ||
  126. (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_BRIGHTNESS_PWM_PIN_CAP))) {
  127. DRM_DEBUG_KMS("AUX Backlight Control Supported!\n");
  128. return true;
  129. }
  130. return false;
  131. }
  132. int intel_dp_aux_init_backlight_funcs(struct intel_connector *intel_connector)
  133. {
  134. struct intel_panel *panel = &intel_connector->panel;
  135. if (!i915.enable_dpcd_backlight)
  136. return -ENODEV;
  137. if (!intel_dp_aux_display_control_capable(intel_connector))
  138. return -ENODEV;
  139. panel->backlight.setup = intel_dp_aux_setup_backlight;
  140. panel->backlight.enable = intel_dp_aux_enable_backlight;
  141. panel->backlight.disable = intel_dp_aux_disable_backlight;
  142. panel->backlight.set = intel_dp_aux_set_backlight;
  143. panel->backlight.get = intel_dp_aux_get_backlight;
  144. return 0;
  145. }