intel_lspcon.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. *
  24. */
  25. #include <drm/drm_edid.h>
  26. #include <drm/drm_atomic_helper.h>
  27. #include <drm/drm_dp_dual_mode_helper.h>
  28. #include "intel_drv.h"
  29. enum drm_lspcon_mode lspcon_get_current_mode(struct intel_lspcon *lspcon)
  30. {
  31. enum drm_lspcon_mode current_mode = DRM_LSPCON_MODE_INVALID;
  32. struct i2c_adapter *adapter = &lspcon->aux->ddc;
  33. if (drm_lspcon_get_mode(adapter, &current_mode))
  34. DRM_ERROR("Error reading LSPCON mode\n");
  35. else
  36. DRM_DEBUG_KMS("Current LSPCON mode %s\n",
  37. current_mode == DRM_LSPCON_MODE_PCON ? "PCON" : "LS");
  38. return current_mode;
  39. }
  40. static int lspcon_change_mode(struct intel_lspcon *lspcon,
  41. enum drm_lspcon_mode mode, bool force)
  42. {
  43. int err;
  44. enum drm_lspcon_mode current_mode;
  45. struct i2c_adapter *adapter = &lspcon->aux->ddc;
  46. err = drm_lspcon_get_mode(adapter, &current_mode);
  47. if (err) {
  48. DRM_ERROR("Error reading LSPCON mode\n");
  49. return err;
  50. }
  51. if (current_mode == mode) {
  52. DRM_DEBUG_KMS("Current mode = desired LSPCON mode\n");
  53. return 0;
  54. }
  55. err = drm_lspcon_set_mode(adapter, mode);
  56. if (err < 0) {
  57. DRM_ERROR("LSPCON mode change failed\n");
  58. return err;
  59. }
  60. lspcon->mode = mode;
  61. DRM_DEBUG_KMS("LSPCON mode changed done\n");
  62. return 0;
  63. }
  64. static bool lspcon_probe(struct intel_lspcon *lspcon)
  65. {
  66. enum drm_dp_dual_mode_type adaptor_type;
  67. struct i2c_adapter *adapter = &lspcon->aux->ddc;
  68. /* Lets probe the adaptor and check its type */
  69. adaptor_type = drm_dp_dual_mode_detect(adapter);
  70. if (adaptor_type != DRM_DP_DUAL_MODE_LSPCON) {
  71. DRM_DEBUG_KMS("No LSPCON detected, found %s\n",
  72. drm_dp_get_dual_mode_type_name(adaptor_type));
  73. return false;
  74. }
  75. /* Yay ... got a LSPCON device */
  76. DRM_DEBUG_KMS("LSPCON detected\n");
  77. lspcon->mode = lspcon_get_current_mode(lspcon);
  78. lspcon->active = true;
  79. return true;
  80. }
  81. bool lspcon_init(struct intel_digital_port *intel_dig_port)
  82. {
  83. struct intel_dp *dp = &intel_dig_port->dp;
  84. struct intel_lspcon *lspcon = &intel_dig_port->lspcon;
  85. struct drm_device *dev = intel_dig_port->base.base.dev;
  86. struct drm_i915_private *dev_priv = to_i915(dev);
  87. if (!IS_GEN9(dev_priv)) {
  88. DRM_ERROR("LSPCON is supported on GEN9 only\n");
  89. return false;
  90. }
  91. lspcon->active = false;
  92. lspcon->mode = DRM_LSPCON_MODE_INVALID;
  93. lspcon->aux = &dp->aux;
  94. if (!lspcon_probe(lspcon)) {
  95. DRM_ERROR("Failed to probe lspcon\n");
  96. return false;
  97. }
  98. /*
  99. * In the SW state machine, lets Put LSPCON in PCON mode only.
  100. * In this way, it will work with both HDMI 1.4 sinks as well as HDMI
  101. * 2.0 sinks.
  102. */
  103. if (lspcon->active && lspcon->mode != DRM_LSPCON_MODE_PCON) {
  104. if (lspcon_change_mode(lspcon, DRM_LSPCON_MODE_PCON,
  105. true) < 0) {
  106. DRM_ERROR("LSPCON mode change to PCON failed\n");
  107. return false;
  108. }
  109. }
  110. DRM_DEBUG_KMS("Success: LSPCON init\n");
  111. return true;
  112. }