2 * Copyright © 2016 Intel Corporation
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:
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
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.
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"
30 static struct intel_dp *lspcon_to_intel_dp(struct intel_lspcon *lspcon)
32 struct intel_digital_port *dig_port =
33 container_of(lspcon, struct intel_digital_port, lspcon);
38 static enum drm_lspcon_mode lspcon_get_current_mode(struct intel_lspcon *lspcon)
40 enum drm_lspcon_mode current_mode = DRM_LSPCON_MODE_INVALID;
41 struct i2c_adapter *adapter = &lspcon_to_intel_dp(lspcon)->aux.ddc;
43 if (drm_lspcon_get_mode(adapter, ¤t_mode))
44 DRM_ERROR("Error reading LSPCON mode\n");
46 DRM_DEBUG_KMS("Current LSPCON mode %s\n",
47 current_mode == DRM_LSPCON_MODE_PCON ? "PCON" : "LS");
51 static int lspcon_change_mode(struct intel_lspcon *lspcon,
52 enum drm_lspcon_mode mode, bool force)
55 enum drm_lspcon_mode current_mode;
56 struct i2c_adapter *adapter = &lspcon_to_intel_dp(lspcon)->aux.ddc;
58 err = drm_lspcon_get_mode(adapter, ¤t_mode);
60 DRM_ERROR("Error reading LSPCON mode\n");
64 if (current_mode == mode) {
65 DRM_DEBUG_KMS("Current mode = desired LSPCON mode\n");
69 err = drm_lspcon_set_mode(adapter, mode);
71 DRM_ERROR("LSPCON mode change failed\n");
76 DRM_DEBUG_KMS("LSPCON mode changed done\n");
80 static bool lspcon_probe(struct intel_lspcon *lspcon)
82 enum drm_dp_dual_mode_type adaptor_type;
83 struct i2c_adapter *adapter = &lspcon_to_intel_dp(lspcon)->aux.ddc;
85 /* Lets probe the adaptor and check its type */
86 adaptor_type = drm_dp_dual_mode_detect(adapter);
87 if (adaptor_type != DRM_DP_DUAL_MODE_LSPCON) {
88 DRM_DEBUG_KMS("No LSPCON detected, found %s\n",
89 drm_dp_get_dual_mode_type_name(adaptor_type));
93 /* Yay ... got a LSPCON device */
94 DRM_DEBUG_KMS("LSPCON detected\n");
95 lspcon->mode = lspcon_get_current_mode(lspcon);
96 lspcon->active = true;
100 static void lspcon_resume_in_pcon_wa(struct intel_lspcon *lspcon)
102 struct intel_dp *intel_dp = lspcon_to_intel_dp(lspcon);
103 unsigned long start = jiffies;
105 if (!lspcon->desc_valid)
109 struct intel_dp_desc desc;
112 * The w/a only applies in PCON mode and we don't expect any
115 if (!__intel_dp_read_desc(intel_dp, &desc))
118 if (!memcmp(&intel_dp->desc, &desc, sizeof(desc))) {
119 DRM_DEBUG_KMS("LSPCON recovering in PCON mode after %u ms\n",
120 jiffies_to_msecs(jiffies - start));
124 if (time_after(jiffies, start + msecs_to_jiffies(1000)))
127 usleep_range(10000, 15000);
130 DRM_DEBUG_KMS("LSPCON DP descriptor mismatch after resume\n");
133 void lspcon_resume(struct intel_lspcon *lspcon)
135 lspcon_resume_in_pcon_wa(lspcon);
137 if (lspcon_change_mode(lspcon, DRM_LSPCON_MODE_PCON, true))
138 DRM_ERROR("LSPCON resume failed\n");
140 DRM_DEBUG_KMS("LSPCON resume success\n");
143 bool lspcon_init(struct intel_digital_port *intel_dig_port)
145 struct intel_dp *dp = &intel_dig_port->dp;
146 struct intel_lspcon *lspcon = &intel_dig_port->lspcon;
147 struct drm_device *dev = intel_dig_port->base.base.dev;
148 struct drm_i915_private *dev_priv = to_i915(dev);
150 if (!IS_GEN9(dev_priv)) {
151 DRM_ERROR("LSPCON is supported on GEN9 only\n");
155 lspcon->active = false;
156 lspcon->mode = DRM_LSPCON_MODE_INVALID;
158 if (!lspcon_probe(lspcon)) {
159 DRM_ERROR("Failed to probe lspcon\n");
164 * In the SW state machine, lets Put LSPCON in PCON mode only.
165 * In this way, it will work with both HDMI 1.4 sinks as well as HDMI
168 if (lspcon->active && lspcon->mode != DRM_LSPCON_MODE_PCON) {
169 if (lspcon_change_mode(lspcon, DRM_LSPCON_MODE_PCON,
171 DRM_ERROR("LSPCON mode change to PCON failed\n");
176 if (!intel_dp_read_dpcd(dp)) {
177 DRM_ERROR("LSPCON DPCD read failed\n");
181 lspcon->desc_valid = intel_dp_read_desc(dp);
183 DRM_DEBUG_KMS("Success: LSPCON init\n");