aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/nouveau/nouveau_dp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/nouveau/nouveau_dp.c')
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_dp.c963
1 files changed, 531 insertions, 432 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_dp.c b/drivers/gpu/drm/nouveau/nouveau_dp.c
index 7beb82a0315d..de5efe71fefd 100644
--- a/drivers/gpu/drm/nouveau/nouveau_dp.c
+++ b/drivers/gpu/drm/nouveau/nouveau_dp.c
@@ -28,418 +28,619 @@
28#include "nouveau_i2c.h" 28#include "nouveau_i2c.h"
29#include "nouveau_connector.h" 29#include "nouveau_connector.h"
30#include "nouveau_encoder.h" 30#include "nouveau_encoder.h"
31#include "nouveau_crtc.h"
32
33/******************************************************************************
34 * aux channel util functions
35 *****************************************************************************/
36#define AUX_DBG(fmt, args...) do { \
37 if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_AUXCH) { \
38 NV_PRINTK(KERN_DEBUG, dev, "AUXCH(%d): " fmt, ch, ##args); \
39 } \
40} while (0)
41#define AUX_ERR(fmt, args...) NV_ERROR(dev, "AUXCH(%d): " fmt, ch, ##args)
42
43static void
44auxch_fini(struct drm_device *dev, int ch)
45{
46 nv_mask(dev, 0x00e4e4 + (ch * 0x50), 0x00310000, 0x00000000);
47}
31 48
32static int 49static int
33auxch_rd(struct drm_encoder *encoder, int address, uint8_t *buf, int size) 50auxch_init(struct drm_device *dev, int ch)
34{ 51{
35 struct drm_device *dev = encoder->dev; 52 const u32 unksel = 1; /* nfi which to use, or if it matters.. */
36 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 53 const u32 ureq = unksel ? 0x00100000 : 0x00200000;
37 struct nouveau_i2c_chan *auxch; 54 const u32 urep = unksel ? 0x01000000 : 0x02000000;
38 int ret; 55 u32 ctrl, timeout;
39 56
40 auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); 57 /* wait up to 1ms for any previous transaction to be done... */
41 if (!auxch) 58 timeout = 1000;
42 return -ENODEV; 59 do {
43 60 ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50));
44 ret = nouveau_dp_auxch(auxch, 9, address, buf, size); 61 udelay(1);
45 if (ret) 62 if (!timeout--) {
46 return ret; 63 AUX_ERR("begin idle timeout 0x%08x", ctrl);
64 return -EBUSY;
65 }
66 } while (ctrl & 0x03010000);
67
68 /* set some magic, and wait up to 1ms for it to appear */
69 nv_mask(dev, 0x00e4e4 + (ch * 0x50), 0x00300000, ureq);
70 timeout = 1000;
71 do {
72 ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50));
73 udelay(1);
74 if (!timeout--) {
75 AUX_ERR("magic wait 0x%08x\n", ctrl);
76 auxch_fini(dev, ch);
77 return -EBUSY;
78 }
79 } while ((ctrl & 0x03000000) != urep);
47 80
48 return 0; 81 return 0;
49} 82}
50 83
51static int 84static int
52auxch_wr(struct drm_encoder *encoder, int address, uint8_t *buf, int size) 85auxch_tx(struct drm_device *dev, int ch, u8 type, u32 addr, u8 *data, u8 size)
53{ 86{
54 struct drm_device *dev = encoder->dev; 87 u32 ctrl, stat, timeout, retries;
55 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 88 u32 xbuf[4] = {};
56 struct nouveau_i2c_chan *auxch; 89 int ret, i;
57 int ret;
58 90
59 auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); 91 AUX_DBG("%d: 0x%08x %d\n", type, addr, size);
60 if (!auxch)
61 return -ENODEV;
62 92
63 ret = nouveau_dp_auxch(auxch, 8, address, buf, size); 93 ret = auxch_init(dev, ch);
64 return ret; 94 if (ret)
65} 95 goto out;
66 96
67static int 97 stat = nv_rd32(dev, 0x00e4e8 + (ch * 0x50));
68nouveau_dp_lane_count_set(struct drm_encoder *encoder, uint8_t cmd) 98 if (!(stat & 0x10000000)) {
69{ 99 AUX_DBG("sink not detected\n");
70 struct drm_device *dev = encoder->dev; 100 ret = -ENXIO;
71 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 101 goto out;
72 uint32_t tmp; 102 }
73 int or = nv_encoder->or, link = !(nv_encoder->dcb->sorconf.link & 1);
74
75 tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
76 tmp &= ~(NV50_SOR_DP_CTRL_ENHANCED_FRAME_ENABLED |
77 NV50_SOR_DP_CTRL_LANE_MASK);
78 tmp |= ((1 << (cmd & DP_LANE_COUNT_MASK)) - 1) << 16;
79 if (cmd & DP_LANE_COUNT_ENHANCED_FRAME_EN)
80 tmp |= NV50_SOR_DP_CTRL_ENHANCED_FRAME_ENABLED;
81 nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp);
82
83 return auxch_wr(encoder, DP_LANE_COUNT_SET, &cmd, 1);
84}
85 103
86static int 104 if (!(type & 1)) {
87nouveau_dp_link_bw_set(struct drm_encoder *encoder, uint8_t cmd) 105 memcpy(xbuf, data, size);
88{ 106 for (i = 0; i < 16; i += 4) {
89 struct drm_device *dev = encoder->dev; 107 AUX_DBG("wr 0x%08x\n", xbuf[i / 4]);
90 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 108 nv_wr32(dev, 0x00e4c0 + (ch * 0x50) + i, xbuf[i / 4]);
91 uint32_t tmp; 109 }
92 int reg = 0x614300 + (nv_encoder->or * 0x800); 110 }
93 111
94 tmp = nv_rd32(dev, reg); 112 ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50));
95 tmp &= 0xfff3ffff; 113 ctrl &= ~0x0001f0ff;
96 if (cmd == DP_LINK_BW_2_7) 114 ctrl |= type << 12;
97 tmp |= 0x00040000; 115 ctrl |= size - 1;
98 nv_wr32(dev, reg, tmp); 116 nv_wr32(dev, 0x00e4e0 + (ch * 0x50), addr);
117
118 /* retry transaction a number of times on failure... */
119 ret = -EREMOTEIO;
120 for (retries = 0; retries < 32; retries++) {
121 /* reset, and delay a while if this is a retry */
122 nv_wr32(dev, 0x00e4e4 + (ch * 0x50), 0x80000000 | ctrl);
123 nv_wr32(dev, 0x00e4e4 + (ch * 0x50), 0x00000000 | ctrl);
124 if (retries)
125 udelay(400);
126
127 /* transaction request, wait up to 1ms for it to complete */
128 nv_wr32(dev, 0x00e4e4 + (ch * 0x50), 0x00010000 | ctrl);
129
130 timeout = 1000;
131 do {
132 ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50));
133 udelay(1);
134 if (!timeout--) {
135 AUX_ERR("tx req timeout 0x%08x\n", ctrl);
136 goto out;
137 }
138 } while (ctrl & 0x00010000);
99 139
100 return auxch_wr(encoder, DP_LINK_BW_SET, &cmd, 1); 140 /* read status, and check if transaction completed ok */
101} 141 stat = nv_mask(dev, 0x00e4e8 + (ch * 0x50), 0, 0);
142 if (!(stat & 0x000f0f00)) {
143 ret = 0;
144 break;
145 }
102 146
103static int 147 AUX_DBG("%02d 0x%08x 0x%08x\n", retries, ctrl, stat);
104nouveau_dp_link_train_set(struct drm_encoder *encoder, int pattern) 148 }
105{
106 struct drm_device *dev = encoder->dev;
107 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
108 uint32_t tmp;
109 uint8_t cmd;
110 int or = nv_encoder->or, link = !(nv_encoder->dcb->sorconf.link & 1);
111 int ret;
112 149
113 tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); 150 if (type & 1) {
114 tmp &= ~NV50_SOR_DP_CTRL_TRAINING_PATTERN; 151 for (i = 0; i < 16; i += 4) {
115 tmp |= (pattern << 24); 152 xbuf[i / 4] = nv_rd32(dev, 0x00e4d0 + (ch * 0x50) + i);
116 nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp); 153 AUX_DBG("rd 0x%08x\n", xbuf[i / 4]);
154 }
155 memcpy(data, xbuf, size);
156 }
117 157
118 ret = auxch_rd(encoder, DP_TRAINING_PATTERN_SET, &cmd, 1); 158out:
119 if (ret) 159 auxch_fini(dev, ch);
120 return ret; 160 return ret;
121 cmd &= ~DP_TRAINING_PATTERN_MASK;
122 cmd |= (pattern & DP_TRAINING_PATTERN_MASK);
123 return auxch_wr(encoder, DP_TRAINING_PATTERN_SET, &cmd, 1);
124} 161}
125 162
126static int 163static u32
127nouveau_dp_max_voltage_swing(struct drm_encoder *encoder) 164dp_link_bw_get(struct drm_device *dev, int or, int link)
128{ 165{
129 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 166 u32 ctrl = nv_rd32(dev, 0x614300 + (or * 0x800));
130 struct drm_device *dev = encoder->dev; 167 if (!(ctrl & 0x000c0000))
131 struct bit_displayport_encoder_table_entry *dpse; 168 return 162000;
132 struct bit_displayport_encoder_table *dpe; 169 return 270000;
133 int i, dpe_headerlen, max_vs = 0; 170}
134
135 dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen);
136 if (!dpe)
137 return false;
138 dpse = (void *)((char *)dpe + dpe_headerlen);
139 171
140 for (i = 0; i < dpe_headerlen; i++, dpse++) { 172static int
141 if (dpse->vs_level > max_vs) 173dp_lane_count_get(struct drm_device *dev, int or, int link)
142 max_vs = dpse->vs_level; 174{
175 u32 ctrl = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
176 switch (ctrl & 0x000f0000) {
177 case 0x00010000: return 1;
178 case 0x00030000: return 2;
179 default:
180 return 4;
143 } 181 }
144
145 return max_vs;
146} 182}
147 183
148static int 184void
149nouveau_dp_max_pre_emphasis(struct drm_encoder *encoder, int vs) 185nouveau_dp_tu_update(struct drm_device *dev, int or, int link, u32 clk, u32 bpp)
150{ 186{
151 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 187 const u32 symbol = 100000;
152 struct drm_device *dev = encoder->dev; 188 int bestTU = 0, bestVTUi = 0, bestVTUf = 0, bestVTUa = 0;
153 struct bit_displayport_encoder_table_entry *dpse; 189 int TU, VTUi, VTUf, VTUa;
154 struct bit_displayport_encoder_table *dpe; 190 u64 link_data_rate, link_ratio, unk;
155 int i, dpe_headerlen, max_pre = 0; 191 u32 best_diff = 64 * symbol;
192 u32 link_nr, link_bw, r;
193
194 /* calculate packed data rate for each lane */
195 link_nr = dp_lane_count_get(dev, or, link);
196 link_data_rate = (clk * bpp / 8) / link_nr;
197
198 /* calculate ratio of packed data rate to link symbol rate */
199 link_bw = dp_link_bw_get(dev, or, link);
200 link_ratio = link_data_rate * symbol;
201 r = do_div(link_ratio, link_bw);
202
203 for (TU = 64; TU >= 32; TU--) {
204 /* calculate average number of valid symbols in each TU */
205 u32 tu_valid = link_ratio * TU;
206 u32 calc, diff;
207
208 /* find a hw representation for the fraction.. */
209 VTUi = tu_valid / symbol;
210 calc = VTUi * symbol;
211 diff = tu_valid - calc;
212 if (diff) {
213 if (diff >= (symbol / 2)) {
214 VTUf = symbol / (symbol - diff);
215 if (symbol - (VTUf * diff))
216 VTUf++;
217
218 if (VTUf <= 15) {
219 VTUa = 1;
220 calc += symbol - (symbol / VTUf);
221 } else {
222 VTUa = 0;
223 VTUf = 1;
224 calc += symbol;
225 }
226 } else {
227 VTUa = 0;
228 VTUf = min((int)(symbol / diff), 15);
229 calc += symbol / VTUf;
230 }
156 231
157 dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 232 diff = calc - tu_valid;
158 if (!dpe) 233 } else {
159 return false; 234 /* no remainder, but the hw doesn't like the fractional
160 dpse = (void *)((char *)dpe + dpe_headerlen); 235 * part to be zero. decrement the integer part and
236 * have the fraction add a whole symbol back
237 */
238 VTUa = 0;
239 VTUf = 1;
240 VTUi--;
241 }
161 242
162 for (i = 0; i < dpe_headerlen; i++, dpse++) { 243 if (diff < best_diff) {
163 if (dpse->vs_level != vs) 244 best_diff = diff;
164 continue; 245 bestTU = TU;
246 bestVTUa = VTUa;
247 bestVTUf = VTUf;
248 bestVTUi = VTUi;
249 if (diff == 0)
250 break;
251 }
252 }
165 253
166 if (dpse->pre_level > max_pre) 254 if (!bestTU) {
167 max_pre = dpse->pre_level; 255 NV_ERROR(dev, "DP: unable to find suitable config\n");
256 return;
168 } 257 }
169 258
170 return max_pre; 259 /* XXX close to vbios numbers, but not right */
260 unk = (symbol - link_ratio) * bestTU;
261 unk *= link_ratio;
262 r = do_div(unk, symbol);
263 r = do_div(unk, symbol);
264 unk += 6;
265
266 nv_mask(dev, NV50_SOR_DP_CTRL(or, link), 0x000001fc, bestTU << 2);
267 nv_mask(dev, NV50_SOR_DP_SCFG(or, link), 0x010f7f3f, bestVTUa << 24 |
268 bestVTUf << 16 |
269 bestVTUi << 8 |
270 unk);
171} 271}
172 272
173static bool 273u8 *
174nouveau_dp_link_train_adjust(struct drm_encoder *encoder, uint8_t *config) 274nouveau_dp_bios_data(struct drm_device *dev, struct dcb_entry *dcb, u8 **entry)
175{ 275{
176 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 276 struct drm_nouveau_private *dev_priv = dev->dev_private;
177 struct drm_device *dev = encoder->dev; 277 struct nvbios *bios = &dev_priv->vbios;
178 struct bit_displayport_encoder_table *dpe; 278 struct bit_entry d;
179 int ret, i, dpe_headerlen, vs = 0, pre = 0; 279 u8 *table;
180 uint8_t request[2]; 280 int i;
181 281
182 dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 282 if (bit_table(dev, 'd', &d)) {
183 if (!dpe) 283 NV_ERROR(dev, "BIT 'd' table not found\n");
184 return false; 284 return NULL;
185 285 }
186 ret = auxch_rd(encoder, DP_ADJUST_REQUEST_LANE0_1, request, 2);
187 if (ret)
188 return false;
189
190 NV_DEBUG_KMS(dev, "\t\tadjust 0x%02x 0x%02x\n", request[0], request[1]);
191
192 /* Keep all lanes at the same level.. */
193 for (i = 0; i < nv_encoder->dp.link_nr; i++) {
194 int lane_req = (request[i >> 1] >> ((i & 1) << 2)) & 0xf;
195 int lane_vs = lane_req & 3;
196 int lane_pre = (lane_req >> 2) & 3;
197 286
198 if (lane_vs > vs) 287 if (d.version != 1) {
199 vs = lane_vs; 288 NV_ERROR(dev, "BIT 'd' table version %d unknown\n", d.version);
200 if (lane_pre > pre) 289 return NULL;
201 pre = lane_pre;
202 } 290 }
203 291
204 if (vs >= nouveau_dp_max_voltage_swing(encoder)) { 292 table = ROMPTR(bios, d.data[0]);
205 vs = nouveau_dp_max_voltage_swing(encoder); 293 if (!table) {
206 vs |= 4; 294 NV_ERROR(dev, "displayport table pointer invalid\n");
295 return NULL;
207 } 296 }
208 297
209 if (pre >= nouveau_dp_max_pre_emphasis(encoder, vs & 3)) { 298 switch (table[0]) {
210 pre = nouveau_dp_max_pre_emphasis(encoder, vs & 3); 299 case 0x20:
211 pre |= 4; 300 case 0x21:
301 case 0x30:
302 break;
303 default:
304 NV_ERROR(dev, "displayport table 0x%02x unknown\n", table[0]);
305 return NULL;
212 } 306 }
213 307
214 /* Update the configuration for all lanes.. */ 308 for (i = 0; i < table[3]; i++) {
215 for (i = 0; i < nv_encoder->dp.link_nr; i++) 309 *entry = ROMPTR(bios, table[table[1] + (i * table[2])]);
216 config[i] = (pre << 3) | vs; 310 if (*entry && bios_encoder_match(dcb, ROM32((*entry)[0])))
311 return table;
312 }
217 313
218 return true; 314 NV_ERROR(dev, "displayport encoder table not found\n");
315 return NULL;
219} 316}
220 317
221static bool 318/******************************************************************************
222nouveau_dp_link_train_commit(struct drm_encoder *encoder, uint8_t *config) 319 * link training
223{ 320 *****************************************************************************/
224 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 321struct dp_state {
225 struct drm_device *dev = encoder->dev; 322 struct dcb_entry *dcb;
226 struct bit_displayport_encoder_table_entry *dpse; 323 u8 *table;
227 struct bit_displayport_encoder_table *dpe; 324 u8 *entry;
228 int or = nv_encoder->or, link = !(nv_encoder->dcb->sorconf.link & 1); 325 int auxch;
229 int dpe_headerlen, ret, i; 326 int crtc;
327 int or;
328 int link;
329 u8 *dpcd;
330 int link_nr;
331 u32 link_bw;
332 u8 stat[6];
333 u8 conf[4];
334};
230 335
231 NV_DEBUG_KMS(dev, "\t\tconfig 0x%02x 0x%02x 0x%02x 0x%02x\n", 336static void
232 config[0], config[1], config[2], config[3]); 337dp_set_link_config(struct drm_device *dev, struct dp_state *dp)
338{
339 struct drm_nouveau_private *dev_priv = dev->dev_private;
340 int or = dp->or, link = dp->link;
341 u8 *entry, sink[2];
342 u32 dp_ctrl;
343 u16 script;
344
345 NV_DEBUG_KMS(dev, "%d lanes at %d KB/s\n", dp->link_nr, dp->link_bw);
346
347 /* set selected link rate on source */
348 switch (dp->link_bw) {
349 case 270000:
350 nv_mask(dev, 0x614300 + (or * 0x800), 0x000c0000, 0x00040000);
351 sink[0] = DP_LINK_BW_2_7;
352 break;
353 default:
354 nv_mask(dev, 0x614300 + (or * 0x800), 0x000c0000, 0x00000000);
355 sink[0] = DP_LINK_BW_1_62;
356 break;
357 }
233 358
234 dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 359 /* offset +0x0a of each dp encoder table entry is a pointer to another
235 if (!dpe) 360 * table, that has (among other things) pointers to more scripts that
236 return false; 361 * need to be executed, this time depending on link speed.
237 dpse = (void *)((char *)dpe + dpe_headerlen); 362 */
363 entry = ROMPTR(&dev_priv->vbios, dp->entry[10]);
364 if (entry) {
365 if (dp->table[0] < 0x30) {
366 while (dp->link_bw < (ROM16(entry[0]) * 10))
367 entry += 4;
368 script = ROM16(entry[2]);
369 } else {
370 while (dp->link_bw < (entry[0] * 27000))
371 entry += 3;
372 script = ROM16(entry[1]);
373 }
238 374
239 for (i = 0; i < dpe->record_nr; i++, dpse++) { 375 nouveau_bios_run_init_table(dev, script, dp->dcb, dp->crtc);
240 if (dpse->vs_level == (config[0] & 3) &&
241 dpse->pre_level == ((config[0] >> 3) & 3))
242 break;
243 } 376 }
244 BUG_ON(i == dpe->record_nr); 377
245 378 /* configure lane count on the source */
246 for (i = 0; i < nv_encoder->dp.link_nr; i++) { 379 dp_ctrl = ((1 << dp->link_nr) - 1) << 16;
247 const int shift[4] = { 16, 8, 0, 24 }; 380 sink[1] = dp->link_nr;
248 uint32_t mask = 0xff << shift[i]; 381 if (dp->dpcd[2] & DP_ENHANCED_FRAME_CAP) {
249 uint32_t reg0, reg1, reg2; 382 dp_ctrl |= 0x00004000;
250 383 sink[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
251 reg0 = nv_rd32(dev, NV50_SOR_DP_UNK118(or, link)) & ~mask;
252 reg0 |= (dpse->reg0 << shift[i]);
253 reg1 = nv_rd32(dev, NV50_SOR_DP_UNK120(or, link)) & ~mask;
254 reg1 |= (dpse->reg1 << shift[i]);
255 reg2 = nv_rd32(dev, NV50_SOR_DP_UNK130(or, link)) & 0xffff00ff;
256 reg2 |= (dpse->reg2 << 8);
257 nv_wr32(dev, NV50_SOR_DP_UNK118(or, link), reg0);
258 nv_wr32(dev, NV50_SOR_DP_UNK120(or, link), reg1);
259 nv_wr32(dev, NV50_SOR_DP_UNK130(or, link), reg2);
260 } 384 }
261 385
262 ret = auxch_wr(encoder, DP_TRAINING_LANE0_SET, config, 4); 386 nv_mask(dev, NV50_SOR_DP_CTRL(or, link), 0x001f4000, dp_ctrl);
263 if (ret)
264 return false;
265 387
266 return true; 388 /* inform the sink of the new configuration */
389 auxch_tx(dev, dp->auxch, 8, DP_LINK_BW_SET, sink, 2);
267} 390}
268 391
269bool 392static void
270nouveau_dp_link_train(struct drm_encoder *encoder) 393dp_set_training_pattern(struct drm_device *dev, struct dp_state *dp, u8 tp)
271{ 394{
272 struct drm_device *dev = encoder->dev; 395 u8 sink_tp;
273 struct drm_nouveau_private *dev_priv = dev->dev_private;
274 struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio;
275 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
276 struct nouveau_connector *nv_connector;
277 struct bit_displayport_encoder_table *dpe;
278 int dpe_headerlen;
279 uint8_t config[4], status[3];
280 bool cr_done, cr_max_vs, eq_done, hpd_state;
281 int ret = 0, i, tries, voltage;
282 396
283 NV_DEBUG_KMS(dev, "link training!!\n"); 397 NV_DEBUG_KMS(dev, "training pattern %d\n", tp);
284 398
285 nv_connector = nouveau_encoder_connector_get(nv_encoder); 399 nv_mask(dev, NV50_SOR_DP_CTRL(dp->or, dp->link), 0x0f000000, tp << 24);
286 if (!nv_connector)
287 return false;
288 400
289 dpe = nouveau_bios_dp_table(dev, nv_encoder->dcb, &dpe_headerlen); 401 auxch_tx(dev, dp->auxch, 9, DP_TRAINING_PATTERN_SET, &sink_tp, 1);
290 if (!dpe) { 402 sink_tp &= ~DP_TRAINING_PATTERN_MASK;
291 NV_ERROR(dev, "SOR-%d: no DP encoder table!\n", nv_encoder->or); 403 sink_tp |= tp;
292 return false; 404 auxch_tx(dev, dp->auxch, 8, DP_TRAINING_PATTERN_SET, &sink_tp, 1);
293 } 405}
294 406
295 /* disable hotplug detect, this flips around on some panels during 407static const u8 nv50_lane_map[] = { 16, 8, 0, 24 };
296 * link training. 408static const u8 nvaf_lane_map[] = { 24, 16, 8, 0 };
297 */ 409
298 hpd_state = pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, false); 410static int
411dp_link_train_commit(struct drm_device *dev, struct dp_state *dp)
412{
413 struct drm_nouveau_private *dev_priv = dev->dev_private;
414 u32 mask = 0, drv = 0, pre = 0, unk = 0;
415 const u8 *shifts;
416 int link = dp->link;
417 int or = dp->or;
418 int i;
419
420 if (dev_priv->chipset != 0xaf)
421 shifts = nv50_lane_map;
422 else
423 shifts = nvaf_lane_map;
424
425 for (i = 0; i < dp->link_nr; i++) {
426 u8 *conf = dp->entry + dp->table[4];
427 u8 lane = (dp->stat[4 + (i >> 1)] >> ((i & 1) * 4)) & 0xf;
428 u8 lpre = (lane & 0x0c) >> 2;
429 u8 lvsw = (lane & 0x03) >> 0;
430
431 mask |= 0xff << shifts[i];
432 unk |= 1 << (shifts[i] >> 3);
433
434 dp->conf[i] = (lpre << 3) | lvsw;
435 if (lvsw == DP_TRAIN_VOLTAGE_SWING_1200)
436 dp->conf[i] |= DP_TRAIN_MAX_SWING_REACHED;
437 if (lpre == DP_TRAIN_PRE_EMPHASIS_9_5)
438 dp->conf[i] |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
439
440 NV_DEBUG_KMS(dev, "config lane %d %02x\n", i, dp->conf[i]);
441
442 if (dp->table[0] < 0x30) {
443 u8 *last = conf + (dp->entry[4] * dp->table[5]);
444 while (lvsw != conf[0] || lpre != conf[1]) {
445 conf += dp->table[5];
446 if (conf >= last)
447 return -EINVAL;
448 }
449
450 conf += 2;
451 } else {
452 /* no lookup table anymore, set entries for each
453 * combination of voltage swing and pre-emphasis
454 * level allowed by the DP spec.
455 */
456 switch (lvsw) {
457 case 0: lpre += 0; break;
458 case 1: lpre += 4; break;
459 case 2: lpre += 7; break;
460 case 3: lpre += 9; break;
461 }
462
463 conf = conf + (lpre * dp->table[5]);
464 conf++;
465 }
299 466
300 if (dpe->script0) { 467 drv |= conf[0] << shifts[i];
301 NV_DEBUG_KMS(dev, "SOR-%d: running DP script 0\n", nv_encoder->or); 468 pre |= conf[1] << shifts[i];
302 nouveau_bios_run_init_table(dev, le16_to_cpu(dpe->script0), 469 unk = (unk & ~0x0000ff00) | (conf[2] << 8);
303 nv_encoder->dcb);
304 } 470 }
305 471
306train: 472 nv_mask(dev, NV50_SOR_DP_UNK118(or, link), mask, drv);
307 cr_done = eq_done = false; 473 nv_mask(dev, NV50_SOR_DP_UNK120(or, link), mask, pre);
474 nv_mask(dev, NV50_SOR_DP_UNK130(or, link), 0x0000ff0f, unk);
308 475
309 /* set link configuration */ 476 return auxch_tx(dev, dp->auxch, 8, DP_TRAINING_LANE0_SET, dp->conf, 4);
310 NV_DEBUG_KMS(dev, "\tbegin train: bw %d, lanes %d\n", 477}
311 nv_encoder->dp.link_bw, nv_encoder->dp.link_nr);
312 478
313 ret = nouveau_dp_link_bw_set(encoder, nv_encoder->dp.link_bw); 479static int
314 if (ret) 480dp_link_train_update(struct drm_device *dev, struct dp_state *dp, u32 delay)
315 return false; 481{
482 int ret;
316 483
317 config[0] = nv_encoder->dp.link_nr; 484 udelay(delay);
318 if (nv_encoder->dp.dpcd_version >= 0x11 &&
319 nv_encoder->dp.enhanced_frame)
320 config[0] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
321 485
322 ret = nouveau_dp_lane_count_set(encoder, config[0]); 486 ret = auxch_tx(dev, dp->auxch, 9, DP_LANE0_1_STATUS, dp->stat, 6);
323 if (ret) 487 if (ret)
324 return false; 488 return ret;
325 489
326 /* clock recovery */ 490 NV_DEBUG_KMS(dev, "status %02x %02x %02x %02x %02x %02x\n",
327 NV_DEBUG_KMS(dev, "\tbegin cr\n"); 491 dp->stat[0], dp->stat[1], dp->stat[2], dp->stat[3],
328 ret = nouveau_dp_link_train_set(encoder, DP_TRAINING_PATTERN_1); 492 dp->stat[4], dp->stat[5]);
329 if (ret) 493 return 0;
330 goto stop; 494}
331 495
332 tries = 0; 496static int
333 voltage = -1; 497dp_link_train_cr(struct drm_device *dev, struct dp_state *dp)
334 memset(config, 0x00, sizeof(config)); 498{
335 for (;;) { 499 bool cr_done = false, abort = false;
336 if (!nouveau_dp_link_train_commit(encoder, config)) 500 int voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
337 break; 501 int tries = 0, i;
338 502
339 udelay(100); 503 dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_1);
340 504
341 ret = auxch_rd(encoder, DP_LANE0_1_STATUS, status, 2); 505 do {
342 if (ret) 506 if (dp_link_train_commit(dev, dp) ||
507 dp_link_train_update(dev, dp, 100))
343 break; 508 break;
344 NV_DEBUG_KMS(dev, "\t\tstatus: 0x%02x 0x%02x\n",
345 status[0], status[1]);
346 509
347 cr_done = true; 510 cr_done = true;
348 cr_max_vs = false; 511 for (i = 0; i < dp->link_nr; i++) {
349 for (i = 0; i < nv_encoder->dp.link_nr; i++) { 512 u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf;
350 int lane = (status[i >> 1] >> ((i & 1) * 4)) & 0xf;
351
352 if (!(lane & DP_LANE_CR_DONE)) { 513 if (!(lane & DP_LANE_CR_DONE)) {
353 cr_done = false; 514 cr_done = false;
354 if (config[i] & DP_TRAIN_MAX_PRE_EMPHASIS_REACHED) 515 if (dp->conf[i] & DP_TRAIN_MAX_SWING_REACHED)
355 cr_max_vs = true; 516 abort = true;
356 break; 517 break;
357 } 518 }
358 } 519 }
359 520
360 if ((config[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) { 521 if ((dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) {
361 voltage = config[0] & DP_TRAIN_VOLTAGE_SWING_MASK; 522 voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
362 tries = 0; 523 tries = 0;
363 } 524 }
525 } while (!cr_done && !abort && ++tries < 5);
364 526
365 if (cr_done || cr_max_vs || (++tries == 5)) 527 return cr_done ? 0 : -1;
366 break; 528}
367
368 if (!nouveau_dp_link_train_adjust(encoder, config))
369 break;
370 }
371
372 if (!cr_done)
373 goto stop;
374 529
375 /* channel equalisation */ 530static int
376 NV_DEBUG_KMS(dev, "\tbegin eq\n"); 531dp_link_train_eq(struct drm_device *dev, struct dp_state *dp)
377 ret = nouveau_dp_link_train_set(encoder, DP_TRAINING_PATTERN_2); 532{
378 if (ret) 533 bool eq_done, cr_done = true;
379 goto stop; 534 int tries = 0, i;
380 535
381 for (tries = 0; tries <= 5; tries++) { 536 dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_2);
382 udelay(400);
383 537
384 ret = auxch_rd(encoder, DP_LANE0_1_STATUS, status, 3); 538 do {
385 if (ret) 539 if (dp_link_train_update(dev, dp, 400))
386 break; 540 break;
387 NV_DEBUG_KMS(dev, "\t\tstatus: 0x%02x 0x%02x\n",
388 status[0], status[1]);
389 541
390 eq_done = true; 542 eq_done = !!(dp->stat[2] & DP_INTERLANE_ALIGN_DONE);
391 if (!(status[2] & DP_INTERLANE_ALIGN_DONE)) 543 for (i = 0; i < dp->link_nr && eq_done; i++) {
392 eq_done = false; 544 u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf;
393 545 if (!(lane & DP_LANE_CR_DONE))
394 for (i = 0; eq_done && i < nv_encoder->dp.link_nr; i++) {
395 int lane = (status[i >> 1] >> ((i & 1) * 4)) & 0xf;
396
397 if (!(lane & DP_LANE_CR_DONE)) {
398 cr_done = false; 546 cr_done = false;
399 break;
400 }
401
402 if (!(lane & DP_LANE_CHANNEL_EQ_DONE) || 547 if (!(lane & DP_LANE_CHANNEL_EQ_DONE) ||
403 !(lane & DP_LANE_SYMBOL_LOCKED)) { 548 !(lane & DP_LANE_SYMBOL_LOCKED))
404 eq_done = false; 549 eq_done = false;
405 break;
406 }
407 } 550 }
408 551
409 if (eq_done || !cr_done) 552 if (dp_link_train_commit(dev, dp))
410 break; 553 break;
554 } while (!eq_done && cr_done && ++tries <= 5);
411 555
412 if (!nouveau_dp_link_train_adjust(encoder, config) || 556 return eq_done ? 0 : -1;
413 !nouveau_dp_link_train_commit(encoder, config)) 557}
414 break;
415 }
416 558
417stop: 559bool
418 /* end link training */ 560nouveau_dp_link_train(struct drm_encoder *encoder, u32 datarate)
419 ret = nouveau_dp_link_train_set(encoder, DP_TRAINING_PATTERN_DISABLE); 561{
420 if (ret) 562 struct drm_nouveau_private *dev_priv = encoder->dev->dev_private;
563 struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio;
564 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
565 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
566 struct nouveau_connector *nv_connector =
567 nouveau_encoder_connector_get(nv_encoder);
568 struct drm_device *dev = encoder->dev;
569 struct nouveau_i2c_chan *auxch;
570 const u32 bw_list[] = { 270000, 162000, 0 };
571 const u32 *link_bw = bw_list;
572 struct dp_state dp;
573
574 auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
575 if (!auxch)
421 return false; 576 return false;
422 577
423 /* retry at a lower setting, if possible */ 578 dp.table = nouveau_dp_bios_data(dev, nv_encoder->dcb, &dp.entry);
424 if (!ret && !(eq_done && cr_done)) { 579 if (!dp.table)
425 NV_DEBUG_KMS(dev, "\twe failed\n"); 580 return -EINVAL;
426 if (nv_encoder->dp.link_bw != DP_LINK_BW_1_62) { 581
427 NV_DEBUG_KMS(dev, "retry link training at low rate\n"); 582 dp.dcb = nv_encoder->dcb;
428 nv_encoder->dp.link_bw = DP_LINK_BW_1_62; 583 dp.crtc = nv_crtc->index;
429 goto train; 584 dp.auxch = auxch->rd;
430 } 585 dp.or = nv_encoder->or;
586 dp.link = !(nv_encoder->dcb->sorconf.link & 1);
587 dp.dpcd = nv_encoder->dp.dpcd;
588
589 /* some sinks toggle hotplug in response to some of the actions
590 * we take during link training (DP_SET_POWER is one), we need
591 * to ignore them for the moment to avoid races.
592 */
593 pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, false);
594
595 /* enable down-spreading, if possible */
596 if (dp.table[1] >= 16) {
597 u16 script = ROM16(dp.entry[14]);
598 if (nv_encoder->dp.dpcd[3] & 1)
599 script = ROM16(dp.entry[12]);
600
601 nouveau_bios_run_init_table(dev, script, dp.dcb, dp.crtc);
431 } 602 }
432 603
433 if (dpe->script1) { 604 /* execute pre-train script from vbios */
434 NV_DEBUG_KMS(dev, "SOR-%d: running DP script 1\n", nv_encoder->or); 605 nouveau_bios_run_init_table(dev, ROM16(dp.entry[6]), dp.dcb, dp.crtc);
435 nouveau_bios_run_init_table(dev, le16_to_cpu(dpe->script1), 606
436 nv_encoder->dcb); 607 /* start off at highest link rate supported by encoder and display */
608 while (*link_bw > nv_encoder->dp.link_bw)
609 link_bw++;
610
611 while (link_bw[0]) {
612 /* find minimum required lane count at this link rate */
613 dp.link_nr = nv_encoder->dp.link_nr;
614 while ((dp.link_nr >> 1) * link_bw[0] > datarate)
615 dp.link_nr >>= 1;
616
617 /* drop link rate to minimum with this lane count */
618 while ((link_bw[1] * dp.link_nr) > datarate)
619 link_bw++;
620 dp.link_bw = link_bw[0];
621
622 /* program selected link configuration */
623 dp_set_link_config(dev, &dp);
624
625 /* attempt to train the link at this configuration */
626 memset(dp.stat, 0x00, sizeof(dp.stat));
627 if (!dp_link_train_cr(dev, &dp) &&
628 !dp_link_train_eq(dev, &dp))
629 break;
630
631 /* retry at lower rate */
632 link_bw++;
437 } 633 }
438 634
439 /* re-enable hotplug detect */ 635 /* finish link training */
440 pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, hpd_state); 636 dp_set_training_pattern(dev, &dp, DP_TRAINING_PATTERN_DISABLE);
441 637
442 return eq_done; 638 /* execute post-train script from vbios */
639 nouveau_bios_run_init_table(dev, ROM16(dp.entry[8]), dp.dcb, dp.crtc);
640
641 /* re-enable hotplug detect */
642 pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, true);
643 return true;
443} 644}
444 645
445bool 646bool
@@ -447,31 +648,34 @@ nouveau_dp_detect(struct drm_encoder *encoder)
447{ 648{
448 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 649 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
449 struct drm_device *dev = encoder->dev; 650 struct drm_device *dev = encoder->dev;
450 uint8_t dpcd[4]; 651 struct nouveau_i2c_chan *auxch;
652 u8 *dpcd = nv_encoder->dp.dpcd;
451 int ret; 653 int ret;
452 654
453 ret = auxch_rd(encoder, 0x0000, dpcd, 4); 655 auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
454 if (ret) 656 if (!auxch)
455 return false; 657 return false;
456 658
457 NV_DEBUG_KMS(dev, "encoder: link_bw %d, link_nr %d\n" 659 ret = auxch_tx(dev, auxch->rd, 9, DP_DPCD_REV, dpcd, 8);
458 "display: link_bw %d, link_nr %d version 0x%02x\n", 660 if (ret)
459 nv_encoder->dcb->dpconf.link_bw, 661 return false;
460 nv_encoder->dcb->dpconf.link_nr,
461 dpcd[1], dpcd[2] & 0x0f, dpcd[0]);
462 662
463 nv_encoder->dp.dpcd_version = dpcd[0]; 663 nv_encoder->dp.link_bw = 27000 * dpcd[1];
664 nv_encoder->dp.link_nr = dpcd[2] & DP_MAX_LANE_COUNT_MASK;
464 665
465 nv_encoder->dp.link_bw = dpcd[1]; 666 NV_DEBUG_KMS(dev, "display: %dx%d dpcd 0x%02x\n",
466 if (nv_encoder->dp.link_bw != DP_LINK_BW_1_62 && 667 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw, dpcd[0]);
467 !nv_encoder->dcb->dpconf.link_bw) 668 NV_DEBUG_KMS(dev, "encoder: %dx%d\n",
468 nv_encoder->dp.link_bw = DP_LINK_BW_1_62; 669 nv_encoder->dcb->dpconf.link_nr,
670 nv_encoder->dcb->dpconf.link_bw);
469 671
470 nv_encoder->dp.link_nr = dpcd[2] & DP_MAX_LANE_COUNT_MASK; 672 if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr)
471 if (nv_encoder->dp.link_nr > nv_encoder->dcb->dpconf.link_nr)
472 nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr; 673 nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr;
674 if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw)
675 nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw;
473 676
474 nv_encoder->dp.enhanced_frame = (dpcd[2] & DP_ENHANCED_FRAME_CAP); 677 NV_DEBUG_KMS(dev, "maximum: %dx%d\n",
678 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw);
475 679
476 return true; 680 return true;
477} 681}
@@ -480,105 +684,13 @@ int
480nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr, 684nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr,
481 uint8_t *data, int data_nr) 685 uint8_t *data, int data_nr)
482{ 686{
483 struct drm_device *dev = auxch->dev; 687 return auxch_tx(auxch->dev, auxch->rd, cmd, addr, data, data_nr);
484 uint32_t tmp, ctrl, stat = 0, data32[4] = {};
485 int ret = 0, i, index = auxch->rd;
486
487 NV_DEBUG_KMS(dev, "ch %d cmd %d addr 0x%x len %d\n", index, cmd, addr, data_nr);
488
489 tmp = nv_rd32(dev, NV50_AUXCH_CTRL(auxch->rd));
490 nv_wr32(dev, NV50_AUXCH_CTRL(auxch->rd), tmp | 0x00100000);
491 tmp = nv_rd32(dev, NV50_AUXCH_CTRL(auxch->rd));
492 if (!(tmp & 0x01000000)) {
493 NV_ERROR(dev, "expected bit 24 == 1, got 0x%08x\n", tmp);
494 ret = -EIO;
495 goto out;
496 }
497
498 for (i = 0; i < 3; i++) {
499 tmp = nv_rd32(dev, NV50_AUXCH_STAT(auxch->rd));
500 if (tmp & NV50_AUXCH_STAT_STATE_READY)
501 break;
502 udelay(100);
503 }
504
505 if (i == 3) {
506 ret = -EBUSY;
507 goto out;
508 }
509
510 if (!(cmd & 1)) {
511 memcpy(data32, data, data_nr);
512 for (i = 0; i < 4; i++) {
513 NV_DEBUG_KMS(dev, "wr %d: 0x%08x\n", i, data32[i]);
514 nv_wr32(dev, NV50_AUXCH_DATA_OUT(index, i), data32[i]);
515 }
516 }
517
518 nv_wr32(dev, NV50_AUXCH_ADDR(index), addr);
519 ctrl = nv_rd32(dev, NV50_AUXCH_CTRL(index));
520 ctrl &= ~(NV50_AUXCH_CTRL_CMD | NV50_AUXCH_CTRL_LEN);
521 ctrl |= (cmd << NV50_AUXCH_CTRL_CMD_SHIFT);
522 ctrl |= ((data_nr - 1) << NV50_AUXCH_CTRL_LEN_SHIFT);
523
524 for (i = 0; i < 16; i++) {
525 nv_wr32(dev, NV50_AUXCH_CTRL(index), ctrl | 0x80000000);
526 nv_wr32(dev, NV50_AUXCH_CTRL(index), ctrl);
527 nv_wr32(dev, NV50_AUXCH_CTRL(index), ctrl | 0x00010000);
528 if (!nv_wait(dev, NV50_AUXCH_CTRL(index),
529 0x00010000, 0x00000000)) {
530 NV_ERROR(dev, "expected bit 16 == 0, got 0x%08x\n",
531 nv_rd32(dev, NV50_AUXCH_CTRL(index)));
532 ret = -EBUSY;
533 goto out;
534 }
535
536 udelay(400);
537
538 stat = nv_rd32(dev, NV50_AUXCH_STAT(index));
539 if ((stat & NV50_AUXCH_STAT_REPLY_AUX) !=
540 NV50_AUXCH_STAT_REPLY_AUX_DEFER)
541 break;
542 }
543
544 if (i == 16) {
545 NV_ERROR(dev, "auxch DEFER too many times, bailing\n");
546 ret = -EREMOTEIO;
547 goto out;
548 }
549
550 if (cmd & 1) {
551 if ((stat & NV50_AUXCH_STAT_COUNT) != data_nr) {
552 ret = -EREMOTEIO;
553 goto out;
554 }
555
556 for (i = 0; i < 4; i++) {
557 data32[i] = nv_rd32(dev, NV50_AUXCH_DATA_IN(index, i));
558 NV_DEBUG_KMS(dev, "rd %d: 0x%08x\n", i, data32[i]);
559 }
560 memcpy(data, data32, data_nr);
561 }
562
563out:
564 tmp = nv_rd32(dev, NV50_AUXCH_CTRL(auxch->rd));
565 nv_wr32(dev, NV50_AUXCH_CTRL(auxch->rd), tmp & ~0x00100000);
566 tmp = nv_rd32(dev, NV50_AUXCH_CTRL(auxch->rd));
567 if (tmp & 0x01000000) {
568 NV_ERROR(dev, "expected bit 24 == 0, got 0x%08x\n", tmp);
569 ret = -EIO;
570 }
571
572 udelay(400);
573
574 return ret ? ret : (stat & NV50_AUXCH_STAT_REPLY);
575} 688}
576 689
577static int 690static int
578nouveau_dp_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) 691nouveau_dp_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
579{ 692{
580 struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adap; 693 struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adap;
581 struct drm_device *dev = auxch->dev;
582 struct i2c_msg *msg = msgs; 694 struct i2c_msg *msg = msgs;
583 int ret, mcnt = num; 695 int ret, mcnt = num;
584 696
@@ -602,19 +714,6 @@ nouveau_dp_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
602 if (ret < 0) 714 if (ret < 0)
603 return ret; 715 return ret;
604 716
605 switch (ret & NV50_AUXCH_STAT_REPLY_I2C) {
606 case NV50_AUXCH_STAT_REPLY_I2C_ACK:
607 break;
608 case NV50_AUXCH_STAT_REPLY_I2C_NACK:
609 return -EREMOTEIO;
610 case NV50_AUXCH_STAT_REPLY_I2C_DEFER:
611 udelay(100);
612 continue;
613 default:
614 NV_ERROR(dev, "bad auxch reply: 0x%08x\n", ret);
615 return -EREMOTEIO;
616 }
617
618 ptr += cnt; 717 ptr += cnt;
619 remaining -= cnt; 718 remaining -= cnt;
620 } 719 }