Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | #include "drmP.h" |
Ben Skeggs | b01f060 | 2010-07-23 11:39:03 +1000 | [diff] [blame] | 26 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 27 | #include "nouveau_drv.h" |
| 28 | #include "nouveau_i2c.h" |
Ben Skeggs | b01f060 | 2010-07-23 11:39:03 +1000 | [diff] [blame] | 29 | #include "nouveau_connector.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 30 | #include "nouveau_encoder.h" |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 31 | #include "nouveau_crtc.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 32 | |
Ben Skeggs | 4372013 | 2011-07-20 15:50:14 +1000 | [diff] [blame] | 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 | |
| 43 | static void |
| 44 | auxch_fini(struct drm_device *dev, int ch) |
| 45 | { |
| 46 | nv_mask(dev, 0x00e4e4 + (ch * 0x50), 0x00310000, 0x00000000); |
| 47 | } |
| 48 | |
| 49 | static int |
| 50 | auxch_init(struct drm_device *dev, int ch) |
| 51 | { |
| 52 | const u32 unksel = 1; /* nfi which to use, or if it matters.. */ |
| 53 | const u32 ureq = unksel ? 0x00100000 : 0x00200000; |
| 54 | const u32 urep = unksel ? 0x01000000 : 0x02000000; |
| 55 | u32 ctrl, timeout; |
| 56 | |
| 57 | /* wait up to 1ms for any previous transaction to be done... */ |
| 58 | timeout = 1000; |
| 59 | do { |
| 60 | ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50)); |
| 61 | udelay(1); |
| 62 | if (!timeout--) { |
| 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); |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int |
| 85 | auxch_tx(struct drm_device *dev, int ch, u8 type, u32 addr, u8 *data, u8 size) |
| 86 | { |
| 87 | u32 ctrl, stat, timeout, retries; |
| 88 | u32 xbuf[4] = {}; |
| 89 | int ret, i; |
| 90 | |
| 91 | AUX_DBG("%d: 0x%08x %d\n", type, addr, size); |
| 92 | |
| 93 | ret = auxch_init(dev, ch); |
| 94 | if (ret) |
| 95 | goto out; |
| 96 | |
| 97 | stat = nv_rd32(dev, 0x00e4e8 + (ch * 0x50)); |
| 98 | if (!(stat & 0x10000000)) { |
| 99 | AUX_DBG("sink not detected\n"); |
| 100 | ret = -ENXIO; |
| 101 | goto out; |
| 102 | } |
| 103 | |
| 104 | if (!(type & 1)) { |
| 105 | memcpy(xbuf, data, size); |
| 106 | for (i = 0; i < 16; i += 4) { |
| 107 | AUX_DBG("wr 0x%08x\n", xbuf[i / 4]); |
| 108 | nv_wr32(dev, 0x00e4c0 + (ch * 0x50) + i, xbuf[i / 4]); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | ctrl = nv_rd32(dev, 0x00e4e4 + (ch * 0x50)); |
| 113 | ctrl &= ~0x0001f0ff; |
| 114 | ctrl |= type << 12; |
| 115 | ctrl |= size - 1; |
| 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); |
| 139 | |
| 140 | /* read status, and check if transaction completed ok */ |
| 141 | stat = nv_mask(dev, 0x00e4e8 + (ch * 0x50), 0, 0); |
| 142 | if (!(stat & 0x000f0f00)) { |
| 143 | ret = 0; |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | AUX_DBG("%02d 0x%08x 0x%08x\n", retries, ctrl, stat); |
| 148 | } |
| 149 | |
| 150 | if (type & 1) { |
| 151 | for (i = 0; i < 16; i += 4) { |
| 152 | xbuf[i / 4] = nv_rd32(dev, 0x00e4d0 + (ch * 0x50) + i); |
| 153 | AUX_DBG("rd 0x%08x\n", xbuf[i / 4]); |
| 154 | } |
| 155 | memcpy(data, xbuf, size); |
| 156 | } |
| 157 | |
| 158 | out: |
| 159 | auxch_fini(dev, ch); |
| 160 | return ret; |
| 161 | } |
| 162 | |
Ben Skeggs | 46959b7 | 2011-07-01 15:51:49 +1000 | [diff] [blame] | 163 | static u32 |
| 164 | dp_link_bw_get(struct drm_device *dev, int or, int link) |
| 165 | { |
| 166 | u32 ctrl = nv_rd32(dev, 0x614300 + (or * 0x800)); |
| 167 | if (!(ctrl & 0x000c0000)) |
| 168 | return 162000; |
| 169 | return 270000; |
| 170 | } |
| 171 | |
| 172 | static int |
| 173 | dp_lane_count_get(struct drm_device *dev, int or, int link) |
| 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; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void |
| 185 | nouveau_dp_tu_update(struct drm_device *dev, int or, int link, u32 clk, u32 bpp) |
| 186 | { |
| 187 | const u32 symbol = 100000; |
| 188 | int bestTU = 0, bestVTUi = 0, bestVTUf = 0, bestVTUa = 0; |
| 189 | int TU, VTUi, VTUf, VTUa; |
| 190 | u64 link_data_rate, link_ratio, unk; |
| 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 | } |
| 231 | |
| 232 | diff = calc - tu_valid; |
| 233 | } else { |
| 234 | /* no remainder, but the hw doesn't like the fractional |
| 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 | } |
| 242 | |
| 243 | if (diff < best_diff) { |
| 244 | best_diff = diff; |
| 245 | bestTU = TU; |
| 246 | bestVTUa = VTUa; |
| 247 | bestVTUf = VTUf; |
| 248 | bestVTUi = VTUi; |
| 249 | if (diff == 0) |
| 250 | break; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | if (!bestTU) { |
| 255 | NV_ERROR(dev, "DP: unable to find suitable config\n"); |
| 256 | return; |
| 257 | } |
| 258 | |
| 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); |
| 271 | } |
| 272 | |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 273 | u8 * |
| 274 | nouveau_dp_bios_data(struct drm_device *dev, struct dcb_entry *dcb, u8 **entry) |
| 275 | { |
| 276 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 277 | struct nvbios *bios = &dev_priv->vbios; |
| 278 | struct bit_entry d; |
| 279 | u8 *table; |
| 280 | int i; |
| 281 | |
| 282 | if (bit_table(dev, 'd', &d)) { |
| 283 | NV_ERROR(dev, "BIT 'd' table not found\n"); |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | if (d.version != 1) { |
| 288 | NV_ERROR(dev, "BIT 'd' table version %d unknown\n", d.version); |
| 289 | return NULL; |
| 290 | } |
| 291 | |
| 292 | table = ROMPTR(bios, d.data[0]); |
| 293 | if (!table) { |
| 294 | NV_ERROR(dev, "displayport table pointer invalid\n"); |
| 295 | return NULL; |
| 296 | } |
| 297 | |
| 298 | switch (table[0]) { |
| 299 | case 0x20: |
| 300 | case 0x21: |
| 301 | break; |
| 302 | default: |
| 303 | NV_ERROR(dev, "displayport table 0x%02x unknown\n", table[0]); |
| 304 | return NULL; |
| 305 | } |
| 306 | |
| 307 | for (i = 0; i < table[3]; i++) { |
| 308 | *entry = ROMPTR(bios, table[table[1] + (i * table[2])]); |
| 309 | if (*entry && bios_encoder_match(dcb, ROM32((*entry)[0]))) |
| 310 | return table; |
| 311 | } |
| 312 | |
| 313 | NV_ERROR(dev, "displayport encoder table not found\n"); |
| 314 | return NULL; |
| 315 | } |
| 316 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 317 | /****************************************************************************** |
| 318 | * link training |
| 319 | *****************************************************************************/ |
| 320 | struct dp_state { |
| 321 | struct dcb_entry *dcb; |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 322 | u8 *table; |
| 323 | u8 *entry; |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 324 | int auxch; |
| 325 | int crtc; |
| 326 | int or; |
| 327 | int link; |
Ben Skeggs | 52e0d0e | 2011-08-04 14:31:28 +1000 | [diff] [blame] | 328 | u8 *dpcd; |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 329 | int link_nr; |
| 330 | u32 link_bw; |
| 331 | u8 stat[6]; |
| 332 | u8 conf[4]; |
| 333 | }; |
| 334 | |
| 335 | static void |
| 336 | dp_set_link_config(struct drm_device *dev, struct dp_state *dp) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 337 | { |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 338 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 339 | int or = dp->or, link = dp->link; |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 340 | u8 *entry, sink[2]; |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 341 | u32 dp_ctrl; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 342 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 343 | NV_DEBUG_KMS(dev, "%d lanes at %d KB/s\n", dp->link_nr, dp->link_bw); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 344 | |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 345 | /* set selected link rate on source */ |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 346 | switch (dp->link_bw) { |
| 347 | case 270000: |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 348 | nv_mask(dev, 0x614300 + (or * 0x800), 0x000c0000, 0x00040000); |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 349 | sink[0] = DP_LINK_BW_2_7; |
| 350 | break; |
| 351 | default: |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 352 | nv_mask(dev, 0x614300 + (or * 0x800), 0x000c0000, 0x00000000); |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 353 | sink[0] = DP_LINK_BW_1_62; |
| 354 | break; |
| 355 | } |
| 356 | |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 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. |
| 360 | */ |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 361 | entry = ROMPTR(&dev_priv->vbios, dp->entry[10]); |
| 362 | if (entry) { |
| 363 | while (dp->link_bw < (ROM16(entry[0]) * 10)) |
| 364 | entry += 4; |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 365 | |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 366 | nouveau_bios_run_init_table(dev, ROM16(entry[2]), dp->dcb, dp->crtc); |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /* configure lane count on the source */ |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 370 | dp_ctrl = ((1 << dp->link_nr) - 1) << 16; |
| 371 | sink[1] = dp->link_nr; |
Ben Skeggs | 52e0d0e | 2011-08-04 14:31:28 +1000 | [diff] [blame] | 372 | if (dp->dpcd[2] & DP_ENHANCED_FRAME_CAP) { |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 373 | dp_ctrl |= 0x00004000; |
| 374 | sink[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; |
| 375 | } |
| 376 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 377 | nv_mask(dev, NV50_SOR_DP_CTRL(or, link), 0x001f4000, dp_ctrl); |
| 378 | |
Ben Skeggs | 28e2d12 | 2011-08-04 14:16:45 +1000 | [diff] [blame] | 379 | /* inform the sink of the new configuration */ |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 380 | auxch_tx(dev, dp->auxch, 8, DP_LINK_BW_SET, sink, 2); |
| 381 | } |
| 382 | |
| 383 | static void |
| 384 | dp_set_training_pattern(struct drm_device *dev, struct dp_state *dp, u8 tp) |
| 385 | { |
Ben Skeggs | 5b3eb95 | 2011-08-05 15:56:53 +1000 | [diff] [blame] | 386 | u8 sink_tp; |
| 387 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 388 | NV_DEBUG_KMS(dev, "training pattern %d\n", tp); |
Ben Skeggs | 5b3eb95 | 2011-08-05 15:56:53 +1000 | [diff] [blame] | 389 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 390 | nv_mask(dev, NV50_SOR_DP_CTRL(dp->or, dp->link), 0x0f000000, tp << 24); |
Ben Skeggs | 5b3eb95 | 2011-08-05 15:56:53 +1000 | [diff] [blame] | 391 | |
| 392 | auxch_tx(dev, dp->auxch, 9, DP_TRAINING_PATTERN_SET, &sink_tp, 1); |
| 393 | sink_tp &= ~DP_TRAINING_PATTERN_MASK; |
| 394 | sink_tp |= tp; |
| 395 | auxch_tx(dev, dp->auxch, 8, DP_TRAINING_PATTERN_SET, &sink_tp, 1); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 396 | } |
| 397 | |
Ben Skeggs | 1b45dbe | 2011-08-05 11:09:21 +1000 | [diff] [blame] | 398 | static const u8 nv50_lane_map[] = { 16, 8, 0, 24 }; |
| 399 | static const u8 nvaf_lane_map[] = { 24, 16, 8, 0 }; |
| 400 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 401 | static int |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 402 | dp_link_train_commit(struct drm_device *dev, struct dp_state *dp) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 403 | { |
Ben Skeggs | 1b45dbe | 2011-08-05 11:09:21 +1000 | [diff] [blame] | 404 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 405 | u32 mask = 0, drv = 0, pre = 0, unk = 0; |
Ben Skeggs | 1b45dbe | 2011-08-05 11:09:21 +1000 | [diff] [blame] | 406 | const u8 *shifts; |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 407 | int link = dp->link; |
| 408 | int or = dp->or; |
| 409 | int i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 410 | |
Ben Skeggs | 1b45dbe | 2011-08-05 11:09:21 +1000 | [diff] [blame] | 411 | if (dev_priv->chipset != 0xaf) |
| 412 | shifts = nv50_lane_map; |
| 413 | else |
| 414 | shifts = nvaf_lane_map; |
| 415 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 416 | for (i = 0; i < dp->link_nr; i++) { |
| 417 | u8 lane = (dp->stat[4 + (i >> 1)] >> ((i & 1) * 4)) & 0xf; |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 418 | u8 *conf = dp->entry + dp->table[4]; |
| 419 | u8 *last = conf + (dp->entry[4] * dp->table[5]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 420 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 421 | while (conf < last) { |
| 422 | if ((lane & 3) == conf[0] && |
| 423 | (lane >> 2) == conf[1]) |
| 424 | break; |
| 425 | conf += 5; |
| 426 | } |
| 427 | |
| 428 | if (conf == last) |
| 429 | return -EINVAL; |
| 430 | |
| 431 | dp->conf[i] = (conf[1] << 3) | conf[0]; |
| 432 | if (conf[0] == DP_TRAIN_VOLTAGE_SWING_1200) |
| 433 | dp->conf[i] |= DP_TRAIN_MAX_SWING_REACHED; |
| 434 | if (conf[1] == DP_TRAIN_PRE_EMPHASIS_9_5) |
| 435 | dp->conf[i] |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED; |
| 436 | |
| 437 | NV_DEBUG_KMS(dev, "config lane %d %02x\n", i, dp->conf[i]); |
| 438 | |
| 439 | mask |= 0xff << shifts[i]; |
| 440 | drv |= conf[2] << shifts[i]; |
| 441 | pre |= conf[3] << shifts[i]; |
| 442 | unk = (unk & ~0x0000ff00) | (conf[4] << 8); |
| 443 | unk |= 1 << (shifts[i] >> 3); |
| 444 | } |
| 445 | |
| 446 | nv_mask(dev, NV50_SOR_DP_UNK118(or, link), mask, drv); |
| 447 | nv_mask(dev, NV50_SOR_DP_UNK120(or, link), mask, pre); |
| 448 | nv_mask(dev, NV50_SOR_DP_UNK130(or, link), 0x0000ff0f, unk); |
| 449 | |
| 450 | return auxch_tx(dev, dp->auxch, 8, DP_TRAINING_LANE0_SET, dp->conf, 4); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static int |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 454 | dp_link_train_update(struct drm_device *dev, struct dp_state *dp, u32 delay) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 455 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 456 | int ret; |
| 457 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 458 | udelay(delay); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 459 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 460 | ret = auxch_tx(dev, dp->auxch, 9, DP_LANE0_1_STATUS, dp->stat, 6); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 461 | if (ret) |
| 462 | return ret; |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 463 | |
| 464 | NV_DEBUG_KMS(dev, "status %02x %02x %02x %02x %02x %02x\n", |
| 465 | dp->stat[0], dp->stat[1], dp->stat[2], dp->stat[3], |
| 466 | dp->stat[4], dp->stat[5]); |
| 467 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | static int |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 471 | dp_link_train_cr(struct drm_device *dev, struct dp_state *dp) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 472 | { |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 473 | bool cr_done = false, abort = false; |
| 474 | int voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK; |
| 475 | int tries = 0, i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 476 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 477 | dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_1); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 478 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 479 | do { |
| 480 | if (dp_link_train_commit(dev, dp) || |
| 481 | dp_link_train_update(dev, dp, 100)) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 482 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 483 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 484 | cr_done = true; |
| 485 | for (i = 0; i < dp->link_nr; i++) { |
| 486 | u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf; |
| 487 | if (!(lane & DP_LANE_CR_DONE)) { |
| 488 | cr_done = false; |
| 489 | if (dp->conf[i] & DP_TRAIN_MAX_SWING_REACHED) |
| 490 | abort = true; |
| 491 | break; |
| 492 | } |
| 493 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 494 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 495 | if ((dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) { |
| 496 | voltage = dp->conf[0] & DP_TRAIN_VOLTAGE_SWING_MASK; |
| 497 | tries = 0; |
| 498 | } |
| 499 | } while (!cr_done && !abort && ++tries < 5); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 500 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 501 | return cr_done ? 0 : -1; |
| 502 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 503 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 504 | static int |
| 505 | dp_link_train_eq(struct drm_device *dev, struct dp_state *dp) |
| 506 | { |
| 507 | bool eq_done, cr_done = true; |
| 508 | int tries = 0, i; |
| 509 | |
| 510 | dp_set_training_pattern(dev, dp, DP_TRAINING_PATTERN_2); |
| 511 | |
| 512 | do { |
| 513 | if (dp_link_train_update(dev, dp, 400)) |
| 514 | break; |
| 515 | |
| 516 | eq_done = !!(dp->stat[2] & DP_INTERLANE_ALIGN_DONE); |
| 517 | for (i = 0; i < dp->link_nr && eq_done; i++) { |
| 518 | u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf; |
| 519 | if (!(lane & DP_LANE_CR_DONE)) |
| 520 | cr_done = false; |
| 521 | if (!(lane & DP_LANE_CHANNEL_EQ_DONE) || |
| 522 | !(lane & DP_LANE_SYMBOL_LOCKED)) |
| 523 | eq_done = false; |
| 524 | } |
| 525 | |
| 526 | if (dp_link_train_commit(dev, dp)) |
| 527 | break; |
| 528 | } while (!eq_done && cr_done && ++tries <= 5); |
| 529 | |
| 530 | return eq_done ? 0 : -1; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | bool |
Ben Skeggs | a002fec | 2011-08-04 11:04:47 +1000 | [diff] [blame] | 534 | nouveau_dp_link_train(struct drm_encoder *encoder, u32 datarate) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 535 | { |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 536 | struct drm_nouveau_private *dev_priv = encoder->dev->dev_private; |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 537 | struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 538 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 539 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 540 | struct nouveau_connector *nv_connector = |
| 541 | nouveau_encoder_connector_get(nv_encoder); |
| 542 | struct drm_device *dev = encoder->dev; |
| 543 | struct nouveau_i2c_chan *auxch; |
| 544 | const u32 bw_list[] = { 270000, 162000, 0 }; |
| 545 | const u32 *link_bw = bw_list; |
| 546 | struct dp_state dp; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 547 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 548 | auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); |
| 549 | if (!auxch) |
Ben Skeggs | b01f060 | 2010-07-23 11:39:03 +1000 | [diff] [blame] | 550 | return false; |
| 551 | |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 552 | dp.table = nouveau_dp_bios_data(dev, nv_encoder->dcb, &dp.entry); |
| 553 | if (!dp.table) |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 554 | return -EINVAL; |
Ben Skeggs | ea4718d | 2010-07-06 11:00:42 +1000 | [diff] [blame] | 555 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 556 | dp.dcb = nv_encoder->dcb; |
| 557 | dp.crtc = nv_crtc->index; |
| 558 | dp.auxch = auxch->rd; |
| 559 | dp.or = nv_encoder->or; |
| 560 | dp.link = !(nv_encoder->dcb->sorconf.link & 1); |
Ben Skeggs | 52e0d0e | 2011-08-04 14:31:28 +1000 | [diff] [blame] | 561 | dp.dpcd = nv_encoder->dp.dpcd; |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 562 | |
| 563 | /* some sinks toggle hotplug in response to some of the actions |
| 564 | * we take during link training (DP_SET_POWER is one), we need |
| 565 | * to ignore them for the moment to avoid races. |
Ben Skeggs | b01f060 | 2010-07-23 11:39:03 +1000 | [diff] [blame] | 566 | */ |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 567 | pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, false); |
Ben Skeggs | b01f060 | 2010-07-23 11:39:03 +1000 | [diff] [blame] | 568 | |
Ben Skeggs | 52e0d0e | 2011-08-04 14:31:28 +1000 | [diff] [blame] | 569 | /* enable down-spreading, if possible */ |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 570 | if (dp.table[1] >= 16) { |
| 571 | u16 script = ROM16(dp.entry[14]); |
Ben Skeggs | 52e0d0e | 2011-08-04 14:31:28 +1000 | [diff] [blame] | 572 | if (nv_encoder->dp.dpcd[3] & 1) |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 573 | script = ROM16(dp.entry[12]); |
Ben Skeggs | 52e0d0e | 2011-08-04 14:31:28 +1000 | [diff] [blame] | 574 | |
| 575 | nouveau_bios_run_init_table(dev, script, dp.dcb, dp.crtc); |
| 576 | } |
| 577 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 578 | /* execute pre-train script from vbios */ |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 579 | nouveau_bios_run_init_table(dev, ROM16(dp.entry[6]), dp.dcb, dp.crtc); |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 580 | |
| 581 | /* start off at highest link rate supported by encoder and display */ |
Ben Skeggs | 75a1fcc | 2011-08-04 09:55:44 +1000 | [diff] [blame] | 582 | while (*link_bw > nv_encoder->dp.link_bw) |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 583 | link_bw++; |
| 584 | |
| 585 | while (link_bw[0]) { |
| 586 | /* find minimum required lane count at this link rate */ |
| 587 | dp.link_nr = nv_encoder->dp.link_nr; |
| 588 | while ((dp.link_nr >> 1) * link_bw[0] > datarate) |
| 589 | dp.link_nr >>= 1; |
| 590 | |
| 591 | /* drop link rate to minimum with this lane count */ |
| 592 | while ((link_bw[1] * dp.link_nr) > datarate) |
| 593 | link_bw++; |
| 594 | dp.link_bw = link_bw[0]; |
| 595 | |
| 596 | /* program selected link configuration */ |
| 597 | dp_set_link_config(dev, &dp); |
| 598 | |
| 599 | /* attempt to train the link at this configuration */ |
| 600 | memset(dp.stat, 0x00, sizeof(dp.stat)); |
| 601 | if (!dp_link_train_cr(dev, &dp) && |
| 602 | !dp_link_train_eq(dev, &dp)) |
| 603 | break; |
| 604 | |
| 605 | /* retry at lower rate */ |
| 606 | link_bw++; |
Ben Skeggs | ea4718d | 2010-07-06 11:00:42 +1000 | [diff] [blame] | 607 | } |
| 608 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 609 | /* finish link training */ |
| 610 | dp_set_training_pattern(dev, &dp, DP_TRAINING_PATTERN_DISABLE); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 611 | |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 612 | /* execute post-train script from vbios */ |
Ben Skeggs | 5f1800b | 2011-08-05 14:07:04 +1000 | [diff] [blame^] | 613 | nouveau_bios_run_init_table(dev, ROM16(dp.entry[8]), dp.dcb, dp.crtc); |
Ben Skeggs | ea4718d | 2010-07-06 11:00:42 +1000 | [diff] [blame] | 614 | |
Ben Skeggs | b01f060 | 2010-07-23 11:39:03 +1000 | [diff] [blame] | 615 | /* re-enable hotplug detect */ |
Ben Skeggs | 27a4598 | 2011-08-04 09:26:44 +1000 | [diff] [blame] | 616 | pgpio->irq_enable(dev, nv_connector->dcb->gpio_tag, true); |
| 617 | return true; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | bool |
| 621 | nouveau_dp_detect(struct drm_encoder *encoder) |
| 622 | { |
| 623 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 624 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 52e0d0e | 2011-08-04 14:31:28 +1000 | [diff] [blame] | 625 | struct nouveau_i2c_chan *auxch; |
| 626 | u8 *dpcd = nv_encoder->dp.dpcd; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 627 | int ret; |
| 628 | |
Ben Skeggs | 52e0d0e | 2011-08-04 14:31:28 +1000 | [diff] [blame] | 629 | auxch = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); |
| 630 | if (!auxch) |
| 631 | return false; |
| 632 | |
| 633 | ret = auxch_tx(dev, auxch->rd, 9, DP_DPCD_REV, dpcd, 8); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 634 | if (ret) |
| 635 | return false; |
| 636 | |
Ben Skeggs | 75a1fcc | 2011-08-04 09:55:44 +1000 | [diff] [blame] | 637 | nv_encoder->dp.link_bw = 27000 * dpcd[1]; |
Ben Skeggs | 85341f2 | 2010-09-28 10:03:57 +1000 | [diff] [blame] | 638 | nv_encoder->dp.link_nr = dpcd[2] & DP_MAX_LANE_COUNT_MASK; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 639 | |
Ben Skeggs | 75a1fcc | 2011-08-04 09:55:44 +1000 | [diff] [blame] | 640 | NV_DEBUG_KMS(dev, "display: %dx%d dpcd 0x%02x\n", |
| 641 | nv_encoder->dp.link_nr, nv_encoder->dp.link_bw, dpcd[0]); |
| 642 | NV_DEBUG_KMS(dev, "encoder: %dx%d\n", |
| 643 | nv_encoder->dcb->dpconf.link_nr, |
| 644 | nv_encoder->dcb->dpconf.link_bw); |
| 645 | |
| 646 | if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr) |
| 647 | nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr; |
| 648 | if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw) |
| 649 | nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw; |
| 650 | |
| 651 | NV_DEBUG_KMS(dev, "maximum: %dx%d\n", |
| 652 | nv_encoder->dp.link_nr, nv_encoder->dp.link_bw); |
Ben Skeggs | fe224bb | 2010-09-27 08:29:33 +1000 | [diff] [blame] | 653 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 654 | return true; |
| 655 | } |
| 656 | |
| 657 | int |
| 658 | nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr, |
| 659 | uint8_t *data, int data_nr) |
| 660 | { |
Ben Skeggs | 4372013 | 2011-07-20 15:50:14 +1000 | [diff] [blame] | 661 | return auxch_tx(auxch->dev, auxch->rd, cmd, addr, data, data_nr); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 662 | } |
| 663 | |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 664 | static int |
| 665 | nouveau_dp_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 666 | { |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 667 | struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adap; |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 668 | struct i2c_msg *msg = msgs; |
| 669 | int ret, mcnt = num; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 670 | |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 671 | while (mcnt--) { |
| 672 | u8 remaining = msg->len; |
| 673 | u8 *ptr = msg->buf; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 674 | |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 675 | while (remaining) { |
| 676 | u8 cnt = (remaining > 16) ? 16 : remaining; |
| 677 | u8 cmd; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 678 | |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 679 | if (msg->flags & I2C_M_RD) |
| 680 | cmd = AUX_I2C_READ; |
| 681 | else |
| 682 | cmd = AUX_I2C_WRITE; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 683 | |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 684 | if (mcnt || remaining > 16) |
| 685 | cmd |= AUX_I2C_MOT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 686 | |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 687 | ret = nouveau_dp_auxch(auxch, cmd, msg->addr, ptr, cnt); |
| 688 | if (ret < 0) |
| 689 | return ret; |
| 690 | |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 691 | ptr += cnt; |
| 692 | remaining -= cnt; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 693 | } |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 694 | |
| 695 | msg++; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 696 | } |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 697 | |
| 698 | return num; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 699 | } |
| 700 | |
Ben Skeggs | c020c9a | 2010-07-29 21:01:45 +1000 | [diff] [blame] | 701 | static u32 |
| 702 | nouveau_dp_i2c_func(struct i2c_adapter *adap) |
| 703 | { |
| 704 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
| 705 | } |
| 706 | |
| 707 | const struct i2c_algorithm nouveau_dp_i2c_algo = { |
| 708 | .master_xfer = nouveau_dp_i2c_xfer, |
| 709 | .functionality = nouveau_dp_i2c_func |
| 710 | }; |