blob: d4da57f21258c1fe1456250708293711f2e2d356 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright 2009 Red Hat Inc.
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 shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
David Howells760285e2012-10-02 18:01:07 +010025#include <drm/drmP.h>
Linus Torvalds612a9aa2012-10-03 23:29:23 -070026#include <drm/drm_dp_helper.h>
Ben Skeggsb01f0602010-07-23 11:39:03 +100027
Ben Skeggs77145f12012-07-31 16:16:21 +100028#include "nouveau_drm.h"
Ben Skeggsb01f0602010-07-23 11:39:03 +100029#include "nouveau_connector.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100030#include "nouveau_encoder.h"
Ben Skeggs27a45982011-08-04 09:26:44 +100031#include "nouveau_crtc.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100032
Ben Skeggs6c8e4632012-11-15 18:56:02 +100033#include <core/class.h>
34
Ben Skeggs77145f12012-07-31 16:16:21 +100035#include <subdev/gpio.h>
36#include <subdev/i2c.h>
Ben Skeggs43720132011-07-20 15:50:14 +100037
Ben Skeggs27a45982011-08-04 09:26:44 +100038/******************************************************************************
39 * link training
40 *****************************************************************************/
41struct dp_state {
Ben Skeggs4196faa2012-07-10 14:36:38 +100042 struct nouveau_i2c_port *auxch;
Ben Skeggs6c8e4632012-11-15 18:56:02 +100043 struct nouveau_object *core;
Ben Skeggscb75d972012-07-11 10:44:20 +100044 struct dcb_output *dcb;
Ben Skeggs27a45982011-08-04 09:26:44 +100045 int crtc;
Ben Skeggs52e0d0e2011-08-04 14:31:28 +100046 u8 *dpcd;
Ben Skeggs27a45982011-08-04 09:26:44 +100047 int link_nr;
48 u32 link_bw;
49 u8 stat[6];
50 u8 conf[4];
51};
52
53static void
54dp_set_link_config(struct drm_device *dev, struct dp_state *dp)
Ben Skeggs6ee73862009-12-11 19:24:15 +100055{
Ben Skeggs77145f12012-07-31 16:16:21 +100056 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs6c8e4632012-11-15 18:56:02 +100057 struct dcb_output *dcb = dp->dcb;
58 const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
59 const u32 moff = (dp->crtc << 3) | (link << 2) | or;
Ben Skeggs8663bc72012-03-09 16:22:56 +100060 u8 sink[2];
Ben Skeggs6c8e4632012-11-15 18:56:02 +100061 u32 data;
Ben Skeggs6ee73862009-12-11 19:24:15 +100062
Ben Skeggs77145f12012-07-31 16:16:21 +100063 NV_DEBUG(drm, "%d lanes at %d KB/s\n", dp->link_nr, dp->link_bw);
Ben Skeggs6ee73862009-12-11 19:24:15 +100064
Ben Skeggs8663bc72012-03-09 16:22:56 +100065 /* set desired link configuration on the source */
Ben Skeggs6c8e4632012-11-15 18:56:02 +100066 data = ((dp->link_bw / 27000) << 8) | dp->link_nr;
67 if (dp->dpcd[2] & DP_ENHANCED_FRAME_CAP)
68 data |= NV94_DISP_SOR_DP_LNKCTL_FRAME_ENH;
69
70 nv_call(dp->core, NV94_DISP_SOR_DP_LNKCTL + moff, data);
Ben Skeggs27a45982011-08-04 09:26:44 +100071
Ben Skeggs28e2d122011-08-04 14:16:45 +100072 /* inform the sink of the new configuration */
Ben Skeggs8663bc72012-03-09 16:22:56 +100073 sink[0] = dp->link_bw / 27000;
74 sink[1] = dp->link_nr;
75 if (dp->dpcd[2] & DP_ENHANCED_FRAME_CAP)
76 sink[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
77
Ben Skeggs77145f12012-07-31 16:16:21 +100078 nv_wraux(dp->auxch, DP_LINK_BW_SET, sink, 2);
Ben Skeggs27a45982011-08-04 09:26:44 +100079}
80
81static void
Ben Skeggs8663bc72012-03-09 16:22:56 +100082dp_set_training_pattern(struct drm_device *dev, struct dp_state *dp, u8 pattern)
Ben Skeggs27a45982011-08-04 09:26:44 +100083{
Ben Skeggs77145f12012-07-31 16:16:21 +100084 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs6c8e4632012-11-15 18:56:02 +100085 struct dcb_output *dcb = dp->dcb;
86 const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
87 const u32 moff = (dp->crtc << 3) | (link << 2) | or;
Ben Skeggs5b3eb952011-08-05 15:56:53 +100088 u8 sink_tp;
89
Ben Skeggs77145f12012-07-31 16:16:21 +100090 NV_DEBUG(drm, "training pattern %d\n", pattern);
Ben Skeggs5b3eb952011-08-05 15:56:53 +100091
Ben Skeggs6c8e4632012-11-15 18:56:02 +100092 nv_call(dp->core, NV94_DISP_SOR_DP_TRAIN + moff, pattern);
Ben Skeggs5b3eb952011-08-05 15:56:53 +100093
Ben Skeggs77145f12012-07-31 16:16:21 +100094 nv_rdaux(dp->auxch, DP_TRAINING_PATTERN_SET, &sink_tp, 1);
Ben Skeggs5b3eb952011-08-05 15:56:53 +100095 sink_tp &= ~DP_TRAINING_PATTERN_MASK;
Ben Skeggs8663bc72012-03-09 16:22:56 +100096 sink_tp |= pattern;
Ben Skeggs77145f12012-07-31 16:16:21 +100097 nv_wraux(dp->auxch, DP_TRAINING_PATTERN_SET, &sink_tp, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +100098}
99
100static int
Ben Skeggs27a45982011-08-04 09:26:44 +1000101dp_link_train_commit(struct drm_device *dev, struct dp_state *dp)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000102{
Ben Skeggs77145f12012-07-31 16:16:21 +1000103 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs6c8e4632012-11-15 18:56:02 +1000104 struct dcb_output *dcb = dp->dcb;
105 const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
106 const u32 moff = (dp->crtc << 3) | (link << 2) | or;
Ben Skeggs27a45982011-08-04 09:26:44 +1000107 int i;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000108
Ben Skeggs27a45982011-08-04 09:26:44 +1000109 for (i = 0; i < dp->link_nr; i++) {
Ben Skeggsc16a3a32011-08-05 14:47:28 +1000110 u8 lane = (dp->stat[4 + (i >> 1)] >> ((i & 1) * 4)) & 0xf;
111 u8 lpre = (lane & 0x0c) >> 2;
112 u8 lvsw = (lane & 0x03) >> 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000113
Ben Skeggsc16a3a32011-08-05 14:47:28 +1000114 dp->conf[i] = (lpre << 3) | lvsw;
115 if (lvsw == DP_TRAIN_VOLTAGE_SWING_1200)
Ben Skeggs27a45982011-08-04 09:26:44 +1000116 dp->conf[i] |= DP_TRAIN_MAX_SWING_REACHED;
Xi Wang44ab8cc2012-02-03 11:13:55 -0500117 if ((lpre << 3) == DP_TRAIN_PRE_EMPHASIS_9_5)
Ben Skeggs27a45982011-08-04 09:26:44 +1000118 dp->conf[i] |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
119
Ben Skeggs77145f12012-07-31 16:16:21 +1000120 NV_DEBUG(drm, "config lane %d %02x\n", i, dp->conf[i]);
Ben Skeggs6c8e4632012-11-15 18:56:02 +1000121
122 nv_call(dp->core, NV94_DISP_SOR_DP_DRVCTL(i) + moff, (lvsw << 8) | lpre);
Ben Skeggs27a45982011-08-04 09:26:44 +1000123 }
124
Ben Skeggs77145f12012-07-31 16:16:21 +1000125 return nv_wraux(dp->auxch, DP_TRAINING_LANE0_SET, dp->conf, 4);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000126}
127
128static int
Ben Skeggs27a45982011-08-04 09:26:44 +1000129dp_link_train_update(struct drm_device *dev, struct dp_state *dp, u32 delay)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000130{
Ben Skeggs77145f12012-07-31 16:16:21 +1000131 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000132 int ret;
133
Ben Skeggs27a45982011-08-04 09:26:44 +1000134 udelay(delay);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000135
Ben Skeggs77145f12012-07-31 16:16:21 +1000136 ret = nv_rdaux(dp->auxch, DP_LANE0_1_STATUS, dp->stat, 6);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000137 if (ret)
138 return ret;
Ben Skeggs27a45982011-08-04 09:26:44 +1000139
Dave Airlie268d2832012-10-03 13:26:15 +1000140 NV_DEBUG(drm, "status %*ph\n", 6, dp->stat);
Ben Skeggs27a45982011-08-04 09:26:44 +1000141 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000142}
143
144static int
Ben Skeggs27a45982011-08-04 09:26:44 +1000145dp_link_train_cr(struct drm_device *dev, struct dp_state *dp)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000146{
Ben Skeggs27a45982011-08-04 09:26:44 +1000147 bool cr_done = false, abort = false;
148 int voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
149 int tries = 0, i;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000150
Ben Skeggs27a45982011-08-04 09:26:44 +1000151 dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000152
Ben Skeggs27a45982011-08-04 09:26:44 +1000153 do {
154 if (dp_link_train_commit(dev, dp) ||
155 dp_link_train_update(dev, dp, 100))
Ben Skeggs6ee73862009-12-11 19:24:15 +1000156 break;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000157
Ben Skeggs27a45982011-08-04 09:26:44 +1000158 cr_done = true;
159 for (i = 0; i < dp->link_nr; i++) {
160 u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf;
161 if (!(lane & DP_LANE_CR_DONE)) {
162 cr_done = false;
163 if (dp->conf[i] & DP_TRAIN_MAX_SWING_REACHED)
164 abort = true;
165 break;
166 }
167 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000168
Ben Skeggs27a45982011-08-04 09:26:44 +1000169 if ((dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) {
170 voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
171 tries = 0;
172 }
173 } while (!cr_done && !abort && ++tries < 5);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000174
Ben Skeggs27a45982011-08-04 09:26:44 +1000175 return cr_done ? 0 : -1;
176}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000177
Ben Skeggs27a45982011-08-04 09:26:44 +1000178static int
179dp_link_train_eq(struct drm_device *dev, struct dp_state *dp)
180{
181 bool eq_done, cr_done = true;
182 int tries = 0, i;
183
184 dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_2);
185
186 do {
187 if (dp_link_train_update(dev, dp, 400))
188 break;
189
190 eq_done = !!(dp->stat[2] & DP_INTERLANE_ALIGN_DONE);
191 for (i = 0; i < dp->link_nr && eq_done; i++) {
192 u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf;
193 if (!(lane & DP_LANE_CR_DONE))
194 cr_done = false;
195 if (!(lane & DP_LANE_CHANNEL_EQ_DONE) ||
196 !(lane & DP_LANE_SYMBOL_LOCKED))
197 eq_done = false;
198 }
199
200 if (dp_link_train_commit(dev, dp))
201 break;
202 } while (!eq_done && cr_done && ++tries <= 5);
203
204 return eq_done ? 0 : -1;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000205}
206
Ben Skeggs8c1dcb62012-03-09 15:22:19 +1000207static void
Ben Skeggs8f2abc22012-11-15 18:58:01 +1000208dp_link_train_init(struct drm_device *dev, struct dp_state *dp, bool spread)
Ben Skeggs8c1dcb62012-03-09 15:22:19 +1000209{
Ben Skeggs8f2abc22012-11-15 18:58:01 +1000210 struct dcb_output *dcb = dp->dcb;
211 const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
212 const u32 moff = (dp->crtc << 3) | (link << 2) | or;
Ben Skeggs8c1dcb62012-03-09 15:22:19 +1000213
Ben Skeggs8f2abc22012-11-15 18:58:01 +1000214 nv_call(dp->core, NV94_DISP_SOR_DP_TRAIN + moff, (spread ?
215 NV94_DISP_SOR_DP_TRAIN_INIT_SPREAD_ON :
216 NV94_DISP_SOR_DP_TRAIN_INIT_SPREAD_OFF) |
217 NV94_DISP_SOR_DP_TRAIN_OP_INIT);
Ben Skeggs8c1dcb62012-03-09 15:22:19 +1000218}
219
220static void
221dp_link_train_fini(struct drm_device *dev, struct dp_state *dp)
222{
Ben Skeggs8f2abc22012-11-15 18:58:01 +1000223 struct dcb_output *dcb = dp->dcb;
224 const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
225 const u32 moff = (dp->crtc << 3) | (link << 2) | or;
Ben Skeggs8c1dcb62012-03-09 15:22:19 +1000226
Ben Skeggs8f2abc22012-11-15 18:58:01 +1000227 nv_call(dp->core, NV94_DISP_SOR_DP_TRAIN + moff,
228 NV94_DISP_SOR_DP_TRAIN_OP_FINI);
Ben Skeggs8c1dcb62012-03-09 15:22:19 +1000229}
230
Marcin Slusarz5b8a43a2012-08-19 23:00:00 +0200231static bool
Ben Skeggs8663bc72012-03-09 16:22:56 +1000232nouveau_dp_link_train(struct drm_encoder *encoder, u32 datarate,
Ben Skeggs6c8e4632012-11-15 18:56:02 +1000233 struct nouveau_object *core)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000234{
Ben Skeggs6ee73862009-12-11 19:24:15 +1000235 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggs27a45982011-08-04 09:26:44 +1000236 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
237 struct nouveau_connector *nv_connector =
238 nouveau_encoder_connector_get(nv_encoder);
239 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000240 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +1000241 struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
Ben Skeggs27a45982011-08-04 09:26:44 +1000242 const u32 bw_list[] = { 270000, 162000, 0 };
243 const u32 *link_bw = bw_list;
244 struct dp_state dp;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000245
Ben Skeggs5ed50202013-02-11 20:15:03 +1000246 dp.auxch = nv_encoder->i2c;
Ben Skeggs4196faa2012-07-10 14:36:38 +1000247 if (!dp.auxch)
Ben Skeggsb01f0602010-07-23 11:39:03 +1000248 return false;
249
Ben Skeggs6c8e4632012-11-15 18:56:02 +1000250 dp.core = core;
Ben Skeggs27a45982011-08-04 09:26:44 +1000251 dp.dcb = nv_encoder->dcb;
252 dp.crtc = nv_crtc->index;
Ben Skeggs52e0d0e2011-08-04 14:31:28 +1000253 dp.dpcd = nv_encoder->dp.dpcd;
Ben Skeggs27a45982011-08-04 09:26:44 +1000254
Ben Skeggs6860dc82012-03-12 11:16:55 +1000255 /* adjust required bandwidth for 8B/10B coding overhead */
256 datarate = (datarate / 8) * 10;
257
Ben Skeggs27a45982011-08-04 09:26:44 +1000258 /* some sinks toggle hotplug in response to some of the actions
259 * we take during link training (DP_SET_POWER is one), we need
260 * to ignore them for the moment to avoid races.
Ben Skeggsb01f0602010-07-23 11:39:03 +1000261 */
Ben Skeggs4f476432013-02-03 12:56:16 +1000262 nouveau_event_put(gpio->events, nv_connector->hpd.line,
263 &nv_connector->hpd_func);
Ben Skeggsb01f0602010-07-23 11:39:03 +1000264
Ben Skeggs8f2abc22012-11-15 18:58:01 +1000265 /* enable down-spreading and execute pre-train script from vbios */
266 dp_link_train_init(dev, &dp, nv_encoder->dp.dpcd[3] & 1);
Ben Skeggs27a45982011-08-04 09:26:44 +1000267
268 /* start off at highest link rate supported by encoder and display */
Ben Skeggs75a1fcc2011-08-04 09:55:44 +1000269 while (*link_bw > nv_encoder->dp.link_bw)
Ben Skeggs27a45982011-08-04 09:26:44 +1000270 link_bw++;
271
272 while (link_bw[0]) {
273 /* find minimum required lane count at this link rate */
274 dp.link_nr = nv_encoder->dp.link_nr;
275 while ((dp.link_nr >> 1) * link_bw[0] > datarate)
276 dp.link_nr >>= 1;
277
278 /* drop link rate to minimum with this lane count */
279 while ((link_bw[1] * dp.link_nr) > datarate)
280 link_bw++;
281 dp.link_bw = link_bw[0];
282
283 /* program selected link configuration */
284 dp_set_link_config(dev, &dp);
285
286 /* attempt to train the link at this configuration */
287 memset(dp.stat, 0x00, sizeof(dp.stat));
288 if (!dp_link_train_cr(dev, &dp) &&
289 !dp_link_train_eq(dev, &dp))
290 break;
291
292 /* retry at lower rate */
293 link_bw++;
Ben Skeggsea4718d2010-07-06 11:00:42 +1000294 }
295
Ben Skeggs27a45982011-08-04 09:26:44 +1000296 /* finish link training */
297 dp_set_training_pattern(dev, &dp, DP_TRAINING_PATTERN_DISABLE);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000298
Ben Skeggs27a45982011-08-04 09:26:44 +1000299 /* execute post-train script from vbios */
Ben Skeggs8c1dcb62012-03-09 15:22:19 +1000300 dp_link_train_fini(dev, &dp);
Ben Skeggsea4718d2010-07-06 11:00:42 +1000301
Ben Skeggsb01f0602010-07-23 11:39:03 +1000302 /* re-enable hotplug detect */
Ben Skeggs4f476432013-02-03 12:56:16 +1000303 nouveau_event_get(gpio->events, nv_connector->hpd.line,
304 &nv_connector->hpd_func);
Ben Skeggs27a45982011-08-04 09:26:44 +1000305 return true;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000306}
307
Ben Skeggsf14d9a42012-03-11 01:20:54 +1000308void
309nouveau_dp_dpms(struct drm_encoder *encoder, int mode, u32 datarate,
Ben Skeggs6c8e4632012-11-15 18:56:02 +1000310 struct nouveau_object *core)
Ben Skeggsf14d9a42012-03-11 01:20:54 +1000311{
312 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggs4196faa2012-07-10 14:36:38 +1000313 struct nouveau_i2c_port *auxch;
Ben Skeggsf14d9a42012-03-11 01:20:54 +1000314 u8 status;
315
Ben Skeggs5ed50202013-02-11 20:15:03 +1000316 auxch = nv_encoder->i2c;
Ben Skeggsf14d9a42012-03-11 01:20:54 +1000317 if (!auxch)
318 return;
319
320 if (mode == DRM_MODE_DPMS_ON)
321 status = DP_SET_POWER_D0;
322 else
323 status = DP_SET_POWER_D3;
324
Ben Skeggs77145f12012-07-31 16:16:21 +1000325 nv_wraux(auxch, DP_SET_POWER, &status, 1);
Ben Skeggsf14d9a42012-03-11 01:20:54 +1000326
327 if (mode == DRM_MODE_DPMS_ON)
Ben Skeggs6c8e4632012-11-15 18:56:02 +1000328 nouveau_dp_link_train(encoder, datarate, core);
Ben Skeggsf14d9a42012-03-11 01:20:54 +1000329}
330
Adam Jackson6225ee02012-05-14 16:05:49 -0400331static void
Ben Skeggs4196faa2012-07-10 14:36:38 +1000332nouveau_dp_probe_oui(struct drm_device *dev, struct nouveau_i2c_port *auxch,
Adam Jackson6225ee02012-05-14 16:05:49 -0400333 u8 *dpcd)
334{
Ben Skeggs77145f12012-07-31 16:16:21 +1000335 struct nouveau_drm *drm = nouveau_drm(dev);
Adam Jackson6225ee02012-05-14 16:05:49 -0400336 u8 buf[3];
337
338 if (!(dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
339 return;
340
Ben Skeggs77145f12012-07-31 16:16:21 +1000341 if (!nv_rdaux(auxch, DP_SINK_OUI, buf, 3))
342 NV_DEBUG(drm, "Sink OUI: %02hx%02hx%02hx\n",
Adam Jackson6225ee02012-05-14 16:05:49 -0400343 buf[0], buf[1], buf[2]);
344
Ben Skeggs77145f12012-07-31 16:16:21 +1000345 if (!nv_rdaux(auxch, DP_BRANCH_OUI, buf, 3))
346 NV_DEBUG(drm, "Branch OUI: %02hx%02hx%02hx\n",
Adam Jackson6225ee02012-05-14 16:05:49 -0400347 buf[0], buf[1], buf[2]);
348
349}
350
Ben Skeggs6ee73862009-12-11 19:24:15 +1000351bool
352nouveau_dp_detect(struct drm_encoder *encoder)
353{
354 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
355 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000356 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs4196faa2012-07-10 14:36:38 +1000357 struct nouveau_i2c_port *auxch;
Ben Skeggs52e0d0e2011-08-04 14:31:28 +1000358 u8 *dpcd = nv_encoder->dp.dpcd;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000359 int ret;
360
Ben Skeggs5ed50202013-02-11 20:15:03 +1000361 auxch = nv_encoder->i2c;
Ben Skeggs52e0d0e2011-08-04 14:31:28 +1000362 if (!auxch)
363 return false;
364
Ben Skeggs77145f12012-07-31 16:16:21 +1000365 ret = nv_rdaux(auxch, DP_DPCD_REV, dpcd, 8);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000366 if (ret)
367 return false;
368
Ben Skeggs75a1fcc2011-08-04 09:55:44 +1000369 nv_encoder->dp.link_bw = 27000 * dpcd[1];
Ben Skeggs85341f22010-09-28 10:03:57 +1000370 nv_encoder->dp.link_nr = dpcd[2] & DP_MAX_LANE_COUNT_MASK;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000371
Ben Skeggs77145f12012-07-31 16:16:21 +1000372 NV_DEBUG(drm, "display: %dx%d dpcd 0x%02x\n",
Ben Skeggs75a1fcc2011-08-04 09:55:44 +1000373 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw, dpcd[0]);
Ben Skeggs77145f12012-07-31 16:16:21 +1000374 NV_DEBUG(drm, "encoder: %dx%d\n",
Ben Skeggs75a1fcc2011-08-04 09:55:44 +1000375 nv_encoder->dcb->dpconf.link_nr,
376 nv_encoder->dcb->dpconf.link_bw);
377
378 if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr)
379 nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr;
380 if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw)
381 nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw;
382
Ben Skeggs77145f12012-07-31 16:16:21 +1000383 NV_DEBUG(drm, "maximum: %dx%d\n",
Ben Skeggs75a1fcc2011-08-04 09:55:44 +1000384 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw);
Ben Skeggsfe224bb2010-09-27 08:29:33 +1000385
Adam Jackson6225ee02012-05-14 16:05:49 -0400386 nouveau_dp_probe_oui(dev, auxch, dpcd);
387
Ben Skeggs6ee73862009-12-11 19:24:15 +1000388 return true;
389}