intel_dsi_dcs_backlight.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright © 2016 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
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Author: Deepak M <m.deepak at intel.com>
  24. */
  25. #include "intel_drv.h"
  26. #include "intel_dsi.h"
  27. #include "i915_drv.h"
  28. #include <video/mipi_display.h>
  29. #include <drm/drm_mipi_dsi.h>
  30. #define CONTROL_DISPLAY_BCTRL (1 << 5)
  31. #define CONTROL_DISPLAY_DD (1 << 3)
  32. #define CONTROL_DISPLAY_BL (1 << 2)
  33. #define POWER_SAVE_OFF (0 << 0)
  34. #define POWER_SAVE_LOW (1 << 0)
  35. #define POWER_SAVE_MEDIUM (2 << 0)
  36. #define POWER_SAVE_HIGH (3 << 0)
  37. #define POWER_SAVE_OUTDOOR_MODE (4 << 0)
  38. #define PANEL_PWM_MAX_VALUE 0xFF
  39. static u32 dcs_get_backlight(struct intel_connector *connector)
  40. {
  41. struct intel_encoder *encoder = connector->encoder;
  42. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  43. struct mipi_dsi_device *dsi_device;
  44. u8 data = 0;
  45. enum port port;
  46. /* FIXME: Need to take care of 16 bit brightness level */
  47. for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
  48. dsi_device = intel_dsi->dsi_hosts[port]->device;
  49. mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
  50. &data, sizeof(data));
  51. break;
  52. }
  53. return data;
  54. }
  55. static void dcs_set_backlight(const struct drm_connector_state *conn_state, u32 level)
  56. {
  57. struct intel_dsi *intel_dsi = enc_to_intel_dsi(conn_state->best_encoder);
  58. struct mipi_dsi_device *dsi_device;
  59. u8 data = level;
  60. enum port port;
  61. /* FIXME: Need to take care of 16 bit brightness level */
  62. for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
  63. dsi_device = intel_dsi->dsi_hosts[port]->device;
  64. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
  65. &data, sizeof(data));
  66. }
  67. }
  68. static void dcs_disable_backlight(const struct drm_connector_state *conn_state)
  69. {
  70. struct intel_dsi *intel_dsi = enc_to_intel_dsi(conn_state->best_encoder);
  71. struct mipi_dsi_device *dsi_device;
  72. enum port port;
  73. dcs_set_backlight(conn_state, 0);
  74. for_each_dsi_port(port, intel_dsi->dcs_cabc_ports) {
  75. u8 cabc = POWER_SAVE_OFF;
  76. dsi_device = intel_dsi->dsi_hosts[port]->device;
  77. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_POWER_SAVE,
  78. &cabc, sizeof(cabc));
  79. }
  80. for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
  81. u8 ctrl = 0;
  82. dsi_device = intel_dsi->dsi_hosts[port]->device;
  83. mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_CONTROL_DISPLAY,
  84. &ctrl, sizeof(ctrl));
  85. ctrl &= ~CONTROL_DISPLAY_BL;
  86. ctrl &= ~CONTROL_DISPLAY_DD;
  87. ctrl &= ~CONTROL_DISPLAY_BCTRL;
  88. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_CONTROL_DISPLAY,
  89. &ctrl, sizeof(ctrl));
  90. }
  91. }
  92. static void dcs_enable_backlight(const struct intel_crtc_state *crtc_state,
  93. const struct drm_connector_state *conn_state)
  94. {
  95. struct intel_dsi *intel_dsi = enc_to_intel_dsi(conn_state->best_encoder);
  96. struct intel_panel *panel = &to_intel_connector(conn_state->connector)->panel;
  97. struct mipi_dsi_device *dsi_device;
  98. enum port port;
  99. for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
  100. u8 ctrl = 0;
  101. dsi_device = intel_dsi->dsi_hosts[port]->device;
  102. mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_CONTROL_DISPLAY,
  103. &ctrl, sizeof(ctrl));
  104. ctrl |= CONTROL_DISPLAY_BL;
  105. ctrl |= CONTROL_DISPLAY_DD;
  106. ctrl |= CONTROL_DISPLAY_BCTRL;
  107. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_CONTROL_DISPLAY,
  108. &ctrl, sizeof(ctrl));
  109. }
  110. for_each_dsi_port(port, intel_dsi->dcs_cabc_ports) {
  111. u8 cabc = POWER_SAVE_MEDIUM;
  112. dsi_device = intel_dsi->dsi_hosts[port]->device;
  113. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_POWER_SAVE,
  114. &cabc, sizeof(cabc));
  115. }
  116. dcs_set_backlight(conn_state, panel->backlight.level);
  117. }
  118. static int dcs_setup_backlight(struct intel_connector *connector,
  119. enum pipe unused)
  120. {
  121. struct intel_panel *panel = &connector->panel;
  122. panel->backlight.max = PANEL_PWM_MAX_VALUE;
  123. panel->backlight.level = PANEL_PWM_MAX_VALUE;
  124. return 0;
  125. }
  126. int intel_dsi_dcs_init_backlight_funcs(struct intel_connector *intel_connector)
  127. {
  128. struct drm_device *dev = intel_connector->base.dev;
  129. struct drm_i915_private *dev_priv = to_i915(dev);
  130. struct intel_encoder *encoder = intel_connector->encoder;
  131. struct intel_panel *panel = &intel_connector->panel;
  132. if (dev_priv->vbt.backlight.type != INTEL_BACKLIGHT_DSI_DCS)
  133. return -ENODEV;
  134. if (WARN_ON(encoder->type != INTEL_OUTPUT_DSI))
  135. return -EINVAL;
  136. panel->backlight.setup = dcs_setup_backlight;
  137. panel->backlight.enable = dcs_enable_backlight;
  138. panel->backlight.disable = dcs_disable_backlight;
  139. panel->backlight.set = dcs_set_backlight;
  140. panel->backlight.get = dcs_get_backlight;
  141. return 0;
  142. }