intel_dsi_dcs_backlight.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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;
  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(struct intel_connector *connector, u32 level)
  56. {
  57. struct intel_encoder *encoder = connector->encoder;
  58. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  59. struct mipi_dsi_device *dsi_device;
  60. u8 data = level;
  61. enum port port;
  62. /* FIXME: Need to take care of 16 bit brightness level */
  63. for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
  64. dsi_device = intel_dsi->dsi_hosts[port]->device;
  65. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
  66. &data, sizeof(data));
  67. }
  68. }
  69. static void dcs_disable_backlight(struct intel_connector *connector)
  70. {
  71. struct intel_encoder *encoder = connector->encoder;
  72. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  73. struct mipi_dsi_device *dsi_device;
  74. enum port port;
  75. dcs_set_backlight(connector, 0);
  76. for_each_dsi_port(port, intel_dsi->dcs_cabc_ports) {
  77. u8 cabc = POWER_SAVE_OFF;
  78. dsi_device = intel_dsi->dsi_hosts[port]->device;
  79. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_POWER_SAVE,
  80. &cabc, sizeof(cabc));
  81. }
  82. for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
  83. u8 ctrl = 0;
  84. dsi_device = intel_dsi->dsi_hosts[port]->device;
  85. mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_CONTROL_DISPLAY,
  86. &ctrl, sizeof(ctrl));
  87. ctrl &= ~CONTROL_DISPLAY_BL;
  88. ctrl &= ~CONTROL_DISPLAY_DD;
  89. ctrl &= ~CONTROL_DISPLAY_BCTRL;
  90. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_CONTROL_DISPLAY,
  91. &ctrl, sizeof(ctrl));
  92. }
  93. }
  94. static void dcs_enable_backlight(struct intel_connector *connector)
  95. {
  96. struct intel_encoder *encoder = connector->encoder;
  97. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  98. struct intel_panel *panel = &connector->panel;
  99. struct mipi_dsi_device *dsi_device;
  100. enum port port;
  101. for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
  102. u8 ctrl = 0;
  103. dsi_device = intel_dsi->dsi_hosts[port]->device;
  104. mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_CONTROL_DISPLAY,
  105. &ctrl, sizeof(ctrl));
  106. ctrl |= CONTROL_DISPLAY_BL;
  107. ctrl |= CONTROL_DISPLAY_DD;
  108. ctrl |= CONTROL_DISPLAY_BCTRL;
  109. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_CONTROL_DISPLAY,
  110. &ctrl, sizeof(ctrl));
  111. }
  112. for_each_dsi_port(port, intel_dsi->dcs_cabc_ports) {
  113. u8 cabc = POWER_SAVE_MEDIUM;
  114. dsi_device = intel_dsi->dsi_hosts[port]->device;
  115. mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_POWER_SAVE,
  116. &cabc, sizeof(cabc));
  117. }
  118. dcs_set_backlight(connector, panel->backlight.level);
  119. }
  120. static int dcs_setup_backlight(struct intel_connector *connector,
  121. enum pipe unused)
  122. {
  123. struct intel_panel *panel = &connector->panel;
  124. panel->backlight.max = PANEL_PWM_MAX_VALUE;
  125. panel->backlight.level = PANEL_PWM_MAX_VALUE;
  126. return 0;
  127. }
  128. int intel_dsi_dcs_init_backlight_funcs(struct intel_connector *intel_connector)
  129. {
  130. struct drm_device *dev = intel_connector->base.dev;
  131. struct drm_i915_private *dev_priv = to_i915(dev);
  132. struct intel_encoder *encoder = intel_connector->encoder;
  133. struct intel_panel *panel = &intel_connector->panel;
  134. if (dev_priv->vbt.backlight.type != INTEL_BACKLIGHT_DSI_DCS)
  135. return -ENODEV;
  136. if (WARN_ON(encoder->type != INTEL_OUTPUT_DSI))
  137. return -EINVAL;
  138. panel->backlight.setup = dcs_setup_backlight;
  139. panel->backlight.enable = dcs_enable_backlight;
  140. panel->backlight.disable = dcs_disable_backlight;
  141. panel->backlight.set = dcs_set_backlight;
  142. panel->backlight.get = dcs_get_backlight;
  143. return 0;
  144. }