OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / gpu / drm / nouveau / nouveau_dp.c
blob9b93b703ceabaacaf9a3ba1f7326e77d1fe6a773
1 /*
2 * Copyright 2009 Red Hat Inc.
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 shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs
25 #include "drmP.h"
27 #include "nouveau_drv.h"
28 #include "nouveau_i2c.h"
29 #include "nouveau_connector.h"
30 #include "nouveau_encoder.h"
31 #include "nouveau_crtc.h"
32 #include "nouveau_gpio.h"
34 /******************************************************************************
35 * aux channel util functions
36 *****************************************************************************/
37 #define AUX_DBG(fmt, args...) do { \
38 if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_AUXCH) { \
39 NV_PRINTK(KERN_DEBUG, dev, "AUXCH(%d): " fmt, ch, ##args); \
40 } \
41 } while (0)
42 #define AUX_ERR(fmt, args...) NV_ERROR(dev, "AUXCH(%d): " fmt, ch, ##args)
44 static void
45 auxch_fini(struct drm_device *dev, int ch)
47 nv_mask(dev, 0x00e4e4 + (ch * 0x50), 0x00310000, 0x00000000);
50 static int
51 auxch_init(struct drm_device *dev, int ch)
53 const u32 unksel = 1; /* nfi which to use, or if it matters.. */
54 const u32 ureq = unksel ? 0x00100000 : 0x00200000;
55 const u32 urep = unksel ? 0x01000000 : 0x02000000;
56 u32 ctrl, timeout;
58 /* wait up to 1ms for any previous transaction to be done... */
59 timeout = 1000;
60 do {
61 ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50));
62 udelay(1);
63 if (!timeout--) {
64 AUX_ERR("begin idle timeout 0x%08x", ctrl);
65 return -EBUSY;
67 } while (ctrl & 0x03010000);
69 /* set some magic, and wait up to 1ms for it to appear */
70 nv_mask(dev, 0x00e4e4 + (ch * 0x50), 0x00300000, ureq);
71 timeout = 1000;
72 do {
73 ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50));
74 udelay(1);
75 if (!timeout--) {
76 AUX_ERR("magic wait 0x%08x\n", ctrl);
77 auxch_fini(dev, ch);
78 return -EBUSY;
80 } while ((ctrl & 0x03000000) != urep);
82 return 0;
85 static int
86 auxch_tx(struct drm_device *dev, int ch, u8 type, u32 addr, u8 *data, u8 size)
88 u32 ctrl, stat, timeout, retries;
89 u32 xbuf[4] = {};
90 int ret, i;
92 AUX_DBG("%d: 0x%08x %d\n", type, addr, size);
94 ret = auxch_init(dev, ch);
95 if (ret)
96 goto out;
98 stat = nv_rd32(dev, 0x00e4e8 + (ch * 0x50));
99 if (!(stat & 0x10000000)) {
100 AUX_DBG("sink not detected\n");
101 ret = -ENXIO;
102 goto out;
105 if (!(type & 1)) {
106 memcpy(xbuf, data, size);
107 for (i = 0; i < 16; i += 4) {
108 AUX_DBG("wr 0x%08x\n", xbuf[i / 4]);
109 nv_wr32(dev, 0x00e4c0 + (ch * 0x50) + i, xbuf[i / 4]);
113 ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50));
114 ctrl &= ~0x0001f0ff;
115 ctrl |= type << 12;
116 ctrl |= size - 1;
117 nv_wr32(dev, 0x00e4e0 + (ch * 0x50), addr);
119 /* retry transaction a number of times on failure... */
120 ret = -EREMOTEIO;
121 for (retries = 0; retries < 32; retries++) {
122 /* reset, and delay a while if this is a retry */
123 nv_wr32(dev, 0x00e4e4 + (ch * 0x50), 0x80000000 | ctrl);
124 nv_wr32(dev, 0x00e4e4 + (ch * 0x50), 0x00000000 | ctrl);
125 if (retries)
126 udelay(400);
128 /* transaction request, wait up to 1ms for it to complete */
129 nv_wr32(dev, 0x00e4e4 + (ch * 0x50), 0x00010000 | ctrl);
131 timeout = 1000;
132 do {
133 ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50));
134 udelay(1);
135 if (!timeout--) {
136 AUX_ERR("tx req timeout 0x%08x\n", ctrl);
137 goto out;
139 } while (ctrl & 0x00010000);
141 /* read status, and check if transaction completed ok */
142 stat = nv_mask(dev, 0x00e4e8 + (ch * 0x50), 0, 0);
143 if (!(stat & 0x000f0f00)) {
144 ret = 0;
145 break;
148 AUX_DBG("%02d 0x%08x 0x%08x\n", retries, ctrl, stat);
151 if (type & 1) {
152 for (i = 0; i < 16; i += 4) {
153 xbuf[i / 4] = nv_rd32(dev, 0x00e4d0 + (ch * 0x50) + i);
154 AUX_DBG("rd 0x%08x\n", xbuf[i / 4]);
156 memcpy(data, xbuf, size);
159 out:
160 auxch_fini(dev, ch);
161 return ret;
164 static u32
165 dp_link_bw_get(struct drm_device *dev, int or, int link)
167 u32 ctrl = nv_rd32(dev, 0x614300 + (or * 0x800));
168 if (!(ctrl & 0x000c0000))
169 return 162000;
170 return 270000;
173 static int
174 dp_lane_count_get(struct drm_device *dev, int or, int link)
176 u32 ctrl = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
177 switch (ctrl & 0x000f0000) {
178 case 0x00010000: return 1;
179 case 0x00030000: return 2;
180 default:
181 return 4;
185 void
186 nouveau_dp_tu_update(struct drm_device *dev, int or, int link, u32 clk, u32 bpp)
188 const u32 symbol = 100000;
189 int bestTU = 0, bestVTUi = 0, bestVTUf = 0, bestVTUa = 0;
190 int TU, VTUi, VTUf, VTUa;
191 u64 link_data_rate, link_ratio, unk;
192 u32 best_diff = 64 * symbol;
193 u32 link_nr, link_bw, r;
195 /* calculate packed data rate for each lane */
196 link_nr = dp_lane_count_get(dev, or, link);
197 link_data_rate = (clk * bpp / 8) / link_nr;
199 /* calculate ratio of packed data rate to link symbol rate */
200 link_bw = dp_link_bw_get(dev, or, link);
201 link_ratio = link_data_rate * symbol;
202 r = do_div(link_ratio, link_bw);
204 for (TU = 64; TU >= 32; TU--) {
205 /* calculate average number of valid symbols in each TU */
206 u32 tu_valid = link_ratio * TU;
207 u32 calc, diff;
209 /* find a hw representation for the fraction.. */
210 VTUi = tu_valid / symbol;
211 calc = VTUi * symbol;
212 diff = tu_valid - calc;
213 if (diff) {
214 if (diff >= (symbol / 2)) {
215 VTUf = symbol / (symbol - diff);
216 if (symbol - (VTUf * diff))
217 VTUf++;
219 if (VTUf <= 15) {
220 VTUa = 1;
221 calc += symbol - (symbol / VTUf);
222 } else {
223 VTUa = 0;
224 VTUf = 1;
225 calc += symbol;
227 } else {
228 VTUa = 0;
229 VTUf = min((int)(symbol / diff), 15);
230 calc += symbol / VTUf;
233 diff = calc - tu_valid;
234 } else {
235 /* no remainder, but the hw doesn't like the fractional
236 * part to be zero. decrement the integer part and
237 * have the fraction add a whole symbol back
239 VTUa = 0;
240 VTUf = 1;
241 VTUi--;
244 if (diff < best_diff) {
245 best_diff = diff;
246 bestTU = TU;
247 bestVTUa = VTUa;
248 bestVTUf = VTUf;
249 bestVTUi = VTUi;
250 if (diff == 0)
251 break;
255 if (!bestTU) {
256 NV_ERROR(dev, "DP: unable to find suitable config\n");
257 return;
260 /* XXX close to vbios numbers, but not right */
261 unk = (symbol - link_ratio) * bestTU;
262 unk *= link_ratio;
263 r = do_div(unk, symbol);
264 r = do_div(unk, symbol);
265 unk += 6;
267 nv_mask(dev, NV50_SOR_DP_CTRL(or, link), 0x000001fc, bestTU << 2);
268 nv_mask(dev, NV50_SOR_DP_SCFG(or, link), 0x010f7f3f, bestVTUa << 24 |
269 bestVTUf << 16 |
270 bestVTUi << 8 |
271 unk);
274 u8 *
275 nouveau_dp_bios_data(struct drm_device *dev, struct dcb_entry *dcb, u8 **entry)
277 struct bit_entry d;
278 u8 *table;
279 int i;
281 if (bit_table(dev, 'd', &d)) {
282 NV_ERROR(dev, "BIT 'd' table not found\n");
283 return NULL;
286 if (d.version != 1) {
287 NV_ERROR(dev, "BIT 'd' table version %d unknown\n", d.version);
288 return NULL;
291 table = ROMPTR(dev, d.data[0]);
292 if (!table) {
293 NV_ERROR(dev, "displayport table pointer invalid\n");
294 return NULL;
297 switch (table[0]) {
298 case 0x20:
299 case 0x21:
300 case 0x30:
301 break;
302 default:
303 NV_ERROR(dev, "displayport table 0x%02x unknown\n", table[0]);
304 return NULL;
307 for (i = 0; i < table[3]; i++) {
308 *entry = ROMPTR(dev, table[table[1] + (i * table[2])]);
309 if (*entry && bios_encoder_match(dcb, ROM32((*entry)[0])))
310 return table;
313 NV_ERROR(dev, "displayport encoder table not found\n");
314 return NULL;
317 /******************************************************************************
318 * link training
319 *****************************************************************************/
320 struct dp_state {
321 struct dcb_entry *dcb;
322 u8 *table;
323 u8 *entry;
324 int auxch;
325 int crtc;
326 int or;
327 int link;
328 u8 *dpcd;
329 int link_nr;
330 u32 link_bw;
331 u8 stat[6];
332 u8 conf[4];
335 static void
336 dp_set_link_config(struct drm_device *dev, struct dp_state *dp)
338 int or = dp->or, link = dp->link;
339 u8 *entry, sink[2];
340 u32 dp_ctrl;
341 u16 script;
343 NV_DEBUG_KMS(dev, "%d lanes at %d KB/s\n", dp->link_nr, dp->link_bw);
345 /* set selected link rate on source */
346 switch (dp->link_bw) {
347 case 270000:
348 nv_mask(dev, 0x614300 + (or * 0x800), 0x000c0000, 0x00040000);
349 sink[0] = DP_LINK_BW_2_7;
350 break;
351 default:
352 nv_mask(dev, 0x614300 + (or * 0x800), 0x000c0000, 0x00000000);
353 sink[0] = DP_LINK_BW_1_62;
354 break;
357 /* offset +0x0a of each dp encoder table entry is a pointer to another
358 * table, that has (among other things) pointers to more scripts that
359 * need to be executed, this time depending on link speed.
361 entry = ROMPTR(dev, dp->entry[10]);
362 if (entry) {
363 if (dp->table[0] < 0x30) {
364 while (dp->link_bw < (ROM16(entry[0]) * 10))
365 entry += 4;
366 script = ROM16(entry[2]);
367 } else {
368 while (dp->link_bw < (entry[0] * 27000))
369 entry += 3;
370 script = ROM16(entry[1]);
373 nouveau_bios_run_init_table(dev, script, dp->dcb, dp->crtc);
376 /* configure lane count on the source */
377 dp_ctrl = ((1 << dp->link_nr) - 1) << 16;
378 sink[1] = dp->link_nr;
379 if (dp->dpcd[2] & DP_ENHANCED_FRAME_CAP) {
380 dp_ctrl |= 0x00004000;
381 sink[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
384 nv_mask(dev, NV50_SOR_DP_CTRL(or, link), 0x001f4000, dp_ctrl);
386 /* inform the sink of the new configuration */
387 auxch_tx(dev, dp->auxch, 8, DP_LINK_BW_SET, sink, 2);
390 static void
391 dp_set_training_pattern(struct drm_device *dev, struct dp_state *dp, u8 tp)
393 u8 sink_tp;
395 NV_DEBUG_KMS(dev, "training pattern %d\n", tp);
397 nv_mask(dev, NV50_SOR_DP_CTRL(dp->or, dp->link), 0x0f000000, tp << 24);
399 auxch_tx(dev, dp->auxch, 9, DP_TRAINING_PATTERN_SET, &sink_tp, 1);
400 sink_tp &= ~DP_TRAINING_PATTERN_MASK;
401 sink_tp |= tp;
402 auxch_tx(dev, dp->auxch, 8, DP_TRAINING_PATTERN_SET, &sink_tp, 1);
405 static const u8 nv50_lane_map[] = { 16, 8, 0, 24 };
406 static const u8 nvaf_lane_map[] = { 24, 16, 8, 0 };
408 static int
409 dp_link_train_commit(struct drm_device *dev, struct dp_state *dp)
411 struct drm_nouveau_private *dev_priv = dev->dev_private;
412 u32 mask = 0, drv = 0, pre = 0, unk = 0;
413 const u8 *shifts;
414 int link = dp->link;
415 int or = dp->or;
416 int i;
418 if (dev_priv->chipset != 0xaf)
419 shifts = nv50_lane_map;
420 else
421 shifts = nvaf_lane_map;
423 for (i = 0; i < dp->link_nr; i++) {
424 u8 *conf = dp->entry + dp->table[4];
425 u8 lane = (dp->stat[4 + (i >> 1)] >> ((i & 1) * 4)) & 0xf;
426 u8 lpre = (lane & 0x0c) >> 2;
427 u8 lvsw = (lane & 0x03) >> 0;
429 mask |= 0xff << shifts[i];
430 unk |= 1 << (shifts[i] >> 3);
432 dp->conf[i] = (lpre << 3) | lvsw;
433 if (lvsw == DP_TRAIN_VOLTAGE_SWING_1200)
434 dp->conf[i] |= DP_TRAIN_MAX_SWING_REACHED;
435 if (lpre == DP_TRAIN_PRE_EMPHASIS_9_5)
436 dp->conf[i] |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
438 NV_DEBUG_KMS(dev, "config lane %d %02x\n", i, dp->conf[i]);
440 if (dp->table[0] < 0x30) {
441 u8 *last = conf + (dp->entry[4] * dp->table[5]);
442 while (lvsw != conf[0] || lpre != conf[1]) {
443 conf += dp->table[5];
444 if (conf >= last)
445 return -EINVAL;
448 conf += 2;
449 } else {
450 /* no lookup table anymore, set entries for each
451 * combination of voltage swing and pre-emphasis
452 * level allowed by the DP spec.
454 switch (lvsw) {
455 case 0: lpre += 0; break;
456 case 1: lpre += 4; break;
457 case 2: lpre += 7; break;
458 case 3: lpre += 9; break;
461 conf = conf + (lpre * dp->table[5]);
462 conf++;
465 drv |= conf[0] << shifts[i];
466 pre |= conf[1] << shifts[i];
467 unk = (unk & ~0x0000ff00) | (conf[2] << 8);
470 nv_mask(dev, NV50_SOR_DP_UNK118(or, link), mask, drv);
471 nv_mask(dev, NV50_SOR_DP_UNK120(or, link), mask, pre);
472 nv_mask(dev, NV50_SOR_DP_UNK130(or, link), 0x0000ff0f, unk);
474 return auxch_tx(dev, dp->auxch, 8, DP_TRAINING_LANE0_SET, dp->conf, 4);
477 static int
478 dp_link_train_update(struct drm_device *dev, struct dp_state *dp, u32 delay)
480 int ret;
482 udelay(delay);
484 ret = auxch_tx(dev, dp->auxch, 9, DP_LANE0_1_STATUS, dp->stat, 6);
485 if (ret)
486 return ret;
488 NV_DEBUG_KMS(dev, "status %02x %02x %02x %02x %02x %02x\n",
489 dp->stat[0], dp->stat[1], dp->stat[2], dp->stat[3],
490 dp->stat[4], dp->stat[5]);
491 return 0;
494 static int
495 dp_link_train_cr(struct drm_device *dev, struct dp_state *dp)
497 bool cr_done = false, abort = false;
498 int voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
499 int tries = 0, i;
501 dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_1);
503 do {
504 if (dp_link_train_commit(dev, dp) ||
505 dp_link_train_update(dev, dp, 100))
506 break;
508 cr_done = true;
509 for (i = 0; i < dp->link_nr; i++) {
510 u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf;
511 if (!(lane & DP_LANE_CR_DONE)) {
512 cr_done = false;
513 if (dp->conf[i] & DP_TRAIN_MAX_SWING_REACHED)
514 abort = true;
515 break;
519 if ((dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) {
520 voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
521 tries = 0;
523 } while (!cr_done && !abort && ++tries < 5);
525 return cr_done ? 0 : -1;
528 static int
529 dp_link_train_eq(struct drm_device *dev, struct dp_state *dp)
531 bool eq_done, cr_done = true;
532 int tries = 0, i;
534 dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_2);
536 do {
537 if (dp_link_train_update(dev, dp, 400))
538 break;
540 eq_done = !!(dp->stat[2] & DP_INTERLANE_ALIGN_DONE);
541 for (i = 0; i < dp->link_nr && eq_done; i++) {
542 u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf;
543 if (!(lane & DP_LANE_CR_DONE))
544 cr_done = false;
545 if (!(lane & DP_LANE_CHANNEL_EQ_DONE) ||
546 !(lane & DP_LANE_SYMBOL_LOCKED))
547 eq_done = false;
550 if (dp_link_train_commit(dev, dp))
551 break;
552 } while (!eq_done && cr_done && ++tries <= 5);
554 return eq_done ? 0 : -1;
557 bool
558 nouveau_dp_link_train(struct drm_encoder *encoder, u32 datarate)
560 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
561 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
562 struct nouveau_connector *nv_connector =
563 nouveau_encoder_connector_get(nv_encoder);
564 struct drm_device *dev = encoder->dev;
565 struct nouveau_i2c_chan *auxch;
566 const u32 bw_list[] = { 270000, 162000, 0 };
567 const u32 *link_bw = bw_list;
568 struct dp_state dp;
570 auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
571 if (!auxch)
572 return false;
574 dp.table = nouveau_dp_bios_data(dev, nv_encoder->dcb, &dp.entry);
575 if (!dp.table)
576 return -EINVAL;
578 dp.dcb = nv_encoder->dcb;
579 dp.crtc = nv_crtc->index;
580 dp.auxch = auxch->drive;
581 dp.or = nv_encoder->or;
582 dp.link = !(nv_encoder->dcb->sorconf.link & 1);
583 dp.dpcd = nv_encoder->dp.dpcd;
585 /* some sinks toggle hotplug in response to some of the actions
586 * we take during link training (DP_SET_POWER is one), we need
587 * to ignore them for the moment to avoid races.
589 nouveau_gpio_irq(dev, 0, nv_connector->hpd, 0xff, false);
591 /* enable down-spreading, if possible */
592 if (dp.table[1] >= 16) {
593 u16 script = ROM16(dp.entry[14]);
594 if (nv_encoder->dp.dpcd[3] & 1)
595 script = ROM16(dp.entry[12]);
597 nouveau_bios_run_init_table(dev, script, dp.dcb, dp.crtc);
600 /* execute pre-train script from vbios */
601 nouveau_bios_run_init_table(dev, ROM16(dp.entry[6]), dp.dcb, dp.crtc);
603 /* start off at highest link rate supported by encoder and display */
604 while (*link_bw > nv_encoder->dp.link_bw)
605 link_bw++;
607 while (link_bw[0]) {
608 /* find minimum required lane count at this link rate */
609 dp.link_nr = nv_encoder->dp.link_nr;
610 while ((dp.link_nr >> 1) * link_bw[0] > datarate)
611 dp.link_nr >>= 1;
613 /* drop link rate to minimum with this lane count */
614 while ((link_bw[1] * dp.link_nr) > datarate)
615 link_bw++;
616 dp.link_bw = link_bw[0];
618 /* program selected link configuration */
619 dp_set_link_config(dev, &dp);
621 /* attempt to train the link at this configuration */
622 memset(dp.stat, 0x00, sizeof(dp.stat));
623 if (!dp_link_train_cr(dev, &dp) &&
624 !dp_link_train_eq(dev, &dp))
625 break;
627 /* retry at lower rate */
628 link_bw++;
631 /* finish link training */
632 dp_set_training_pattern(dev, &dp, DP_TRAINING_PATTERN_DISABLE);
634 /* execute post-train script from vbios */
635 nouveau_bios_run_init_table(dev, ROM16(dp.entry[8]), dp.dcb, dp.crtc);
637 /* re-enable hotplug detect */
638 nouveau_gpio_irq(dev, 0, nv_connector->hpd, 0xff, true);
639 return true;
642 bool
643 nouveau_dp_detect(struct drm_encoder *encoder)
645 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
646 struct drm_device *dev = encoder->dev;
647 struct nouveau_i2c_chan *auxch;
648 u8 *dpcd = nv_encoder->dp.dpcd;
649 int ret;
651 auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
652 if (!auxch)
653 return false;
655 ret = auxch_tx(dev, auxch->drive, 9, DP_DPCD_REV, dpcd, 8);
656 if (ret)
657 return false;
659 nv_encoder->dp.link_bw = 27000 * dpcd[1];
660 nv_encoder->dp.link_nr = dpcd[2] & DP_MAX_LANE_COUNT_MASK;
662 NV_DEBUG_KMS(dev, "display: %dx%d dpcd 0x%02x\n",
663 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw, dpcd[0]);
664 NV_DEBUG_KMS(dev, "encoder: %dx%d\n",
665 nv_encoder->dcb->dpconf.link_nr,
666 nv_encoder->dcb->dpconf.link_bw);
668 if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr)
669 nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr;
670 if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw)
671 nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw;
673 NV_DEBUG_KMS(dev, "maximum: %dx%d\n",
674 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw);
676 return true;
680 nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr,
681 uint8_t *data, int data_nr)
683 return auxch_tx(auxch->dev, auxch->drive, cmd, addr, data, data_nr);
686 static int
687 nouveau_dp_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
689 struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adap;
690 struct i2c_msg *msg = msgs;
691 int ret, mcnt = num;
693 while (mcnt--) {
694 u8 remaining = msg->len;
695 u8 *ptr = msg->buf;
697 while (remaining) {
698 u8 cnt = (remaining > 16) ? 16 : remaining;
699 u8 cmd;
701 if (msg->flags & I2C_M_RD)
702 cmd = AUX_I2C_READ;
703 else
704 cmd = AUX_I2C_WRITE;
706 if (mcnt || remaining > 16)
707 cmd |= AUX_I2C_MOT;
709 ret = nouveau_dp_auxch(auxch, cmd, msg->addr, ptr, cnt);
710 if (ret < 0)
711 return ret;
713 ptr += cnt;
714 remaining -= cnt;
717 msg++;
720 return num;
723 static u32
724 nouveau_dp_i2c_func(struct i2c_adapter *adap)
726 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
729 const struct i2c_algorithm nouveau_dp_i2c_algo = {
730 .master_xfer = nouveau_dp_i2c_xfer,
731 .functionality = nouveau_dp_i2c_func