Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 <subdev/bios.h> |
| 26 | #include <subdev/bios/dcb.h> |
| 27 | #include <subdev/bios/dp.h> |
| 28 | #include <subdev/bios/init.h> |
| 29 | #include <subdev/i2c.h> |
| 30 | |
| 31 | #include <engine/disp.h> |
| 32 | |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 33 | #include <core/class.h> |
| 34 | |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 35 | #include "dport.h" |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 36 | #include "outpdp.h" |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 37 | |
| 38 | /****************************************************************************** |
| 39 | * link training |
| 40 | *****************************************************************************/ |
| 41 | struct dp_state { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 42 | struct nvkm_output_dp *outp; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 43 | int link_nr; |
| 44 | u32 link_bw; |
| 45 | u8 stat[6]; |
| 46 | u8 conf[4]; |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 47 | bool pc2; |
| 48 | u8 pc2stat; |
| 49 | u8 pc2conf[2]; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | static int |
| 53 | dp_set_link_config(struct dp_state *dp) |
| 54 | { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 55 | struct nvkm_output_dp_impl *impl = (void *)nv_oclass(dp->outp); |
| 56 | struct nvkm_output_dp *outp = dp->outp; |
| 57 | struct nouveau_disp *disp = nouveau_disp(outp); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 58 | struct nouveau_bios *bios = nouveau_bios(disp); |
| 59 | struct nvbios_init init = { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 60 | .subdev = nv_subdev(disp), |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 61 | .bios = bios, |
| 62 | .offset = 0x0000, |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 63 | .outp = &outp->base.info, |
| 64 | .crtc = -1, |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 65 | .execute = 1, |
| 66 | }; |
| 67 | u32 lnkcmp; |
| 68 | u8 sink[2]; |
Ben Skeggs | 8df1d0c | 2013-11-04 13:40:36 +1000 | [diff] [blame] | 69 | int ret; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 70 | |
| 71 | DBG("%d lanes at %d KB/s\n", dp->link_nr, dp->link_bw); |
| 72 | |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 73 | /* set desired link configuration on the source */ |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 74 | if ((lnkcmp = dp->outp->info.lnkcmp)) { |
| 75 | if (outp->version < 0x30) { |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 76 | while ((dp->link_bw / 10) < nv_ro16(bios, lnkcmp)) |
| 77 | lnkcmp += 4; |
| 78 | init.offset = nv_ro16(bios, lnkcmp + 2); |
| 79 | } else { |
| 80 | while ((dp->link_bw / 27000) < nv_ro08(bios, lnkcmp)) |
| 81 | lnkcmp += 3; |
| 82 | init.offset = nv_ro16(bios, lnkcmp + 1); |
| 83 | } |
| 84 | |
| 85 | nvbios_exec(&init); |
| 86 | } |
| 87 | |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 88 | ret = impl->lnk_ctl(outp, dp->link_nr, dp->link_bw / 27000, |
| 89 | outp->dpcd[DPCD_RC02] & |
| 90 | DPCD_RC02_ENHANCED_FRAME_CAP); |
Ben Skeggs | 8df1d0c | 2013-11-04 13:40:36 +1000 | [diff] [blame] | 91 | if (ret) { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 92 | if (ret < 0) |
| 93 | ERR("lnk_ctl failed with %d\n", ret); |
Ben Skeggs | 8df1d0c | 2013-11-04 13:40:36 +1000 | [diff] [blame] | 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | /* set desired link configuration on the sink */ |
| 98 | sink[0] = dp->link_bw / 27000; |
| 99 | sink[1] = dp->link_nr; |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 100 | if (outp->dpcd[DPCD_RC02] & DPCD_RC02_ENHANCED_FRAME_CAP) |
Ben Skeggs | 8df1d0c | 2013-11-04 13:40:36 +1000 | [diff] [blame] | 101 | sink[1] |= DPCD_LC01_ENHANCED_FRAME_EN; |
| 102 | |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 103 | return nv_wraux(outp->base.edid, DPCD_LC00, sink, 2); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static void |
| 107 | dp_set_training_pattern(struct dp_state *dp, u8 pattern) |
| 108 | { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 109 | struct nvkm_output_dp_impl *impl = (void *)nv_oclass(dp->outp); |
| 110 | struct nvkm_output_dp *outp = dp->outp; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 111 | u8 sink_tp; |
| 112 | |
| 113 | DBG("training pattern %d\n", pattern); |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 114 | impl->pattern(outp, pattern); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 115 | |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 116 | nv_rdaux(outp->base.edid, DPCD_LC02, &sink_tp, 1); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 117 | sink_tp &= ~DPCD_LC02_TRAINING_PATTERN_SET; |
| 118 | sink_tp |= pattern; |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 119 | nv_wraux(outp->base.edid, DPCD_LC02, &sink_tp, 1); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static int |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 123 | dp_link_train_commit(struct dp_state *dp, bool pc) |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 124 | { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 125 | struct nvkm_output_dp_impl *impl = (void *)nv_oclass(dp->outp); |
| 126 | struct nvkm_output_dp *outp = dp->outp; |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 127 | int ret, i; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 128 | |
| 129 | for (i = 0; i < dp->link_nr; i++) { |
| 130 | u8 lane = (dp->stat[4 + (i >> 1)] >> ((i & 1) * 4)) & 0xf; |
| 131 | u8 lpre = (lane & 0x0c) >> 2; |
| 132 | u8 lvsw = (lane & 0x03) >> 0; |
| 133 | |
| 134 | dp->conf[i] = (lpre << 3) | lvsw; |
| 135 | if (lvsw == 3) |
| 136 | dp->conf[i] |= DPCD_LC03_MAX_SWING_REACHED; |
| 137 | if (lpre == 3) |
| 138 | dp->conf[i] |= DPCD_LC03_MAX_PRE_EMPHASIS_REACHED; |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 139 | dp->pc2conf[i >> 1] |= 4 << ((i & 1) * 4); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 140 | |
| 141 | DBG("config lane %d %02x\n", i, dp->conf[i]); |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 142 | impl->drv_ctl(outp, i, lvsw, lpre, 0); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 145 | ret = nv_wraux(outp->base.edid, DPCD_LC03(0), dp->conf, 4); |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 146 | if (ret) |
| 147 | return ret; |
| 148 | |
| 149 | if (pc) { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 150 | ret = nv_wraux(outp->base.edid, DPCD_LC0F, dp->pc2conf, 2); |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 151 | if (ret) |
| 152 | return ret; |
| 153 | } |
| 154 | |
| 155 | return 0; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static int |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 159 | dp_link_train_update(struct dp_state *dp, bool pc, u32 delay) |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 160 | { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 161 | struct nvkm_output_dp *outp = dp->outp; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 162 | int ret; |
| 163 | |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 164 | if (outp->dpcd[DPCD_RC0E_AUX_RD_INTERVAL]) |
| 165 | mdelay(outp->dpcd[DPCD_RC0E_AUX_RD_INTERVAL] * 4); |
Ben Skeggs | fb7c2a7 | 2014-05-15 21:50:07 +1000 | [diff] [blame] | 166 | else |
| 167 | udelay(delay); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 168 | |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 169 | ret = nv_rdaux(outp->base.edid, DPCD_LS02, dp->stat, 6); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 170 | if (ret) |
| 171 | return ret; |
| 172 | |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 173 | if (pc) { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 174 | ret = nv_rdaux(outp->base.edid, DPCD_LS0C, &dp->pc2stat, 1); |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 175 | if (ret) |
| 176 | dp->pc2stat = 0x00; |
| 177 | DBG("status %6ph pc2 %02x\n", dp->stat, dp->pc2stat); |
| 178 | } else { |
| 179 | DBG("status %6ph\n", dp->stat); |
| 180 | } |
| 181 | |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static int |
| 186 | dp_link_train_cr(struct dp_state *dp) |
| 187 | { |
| 188 | bool cr_done = false, abort = false; |
| 189 | int voltage = dp->conf[0] & DPCD_LC03_VOLTAGE_SWING_SET; |
| 190 | int tries = 0, i; |
| 191 | |
| 192 | dp_set_training_pattern(dp, 1); |
| 193 | |
| 194 | do { |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 195 | if (dp_link_train_commit(dp, false) || |
| 196 | dp_link_train_update(dp, false, 100)) |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 197 | break; |
| 198 | |
| 199 | cr_done = true; |
| 200 | for (i = 0; i < dp->link_nr; i++) { |
| 201 | u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf; |
| 202 | if (!(lane & DPCD_LS02_LANE0_CR_DONE)) { |
| 203 | cr_done = false; |
| 204 | if (dp->conf[i] & DPCD_LC03_MAX_SWING_REACHED) |
| 205 | abort = true; |
| 206 | break; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if ((dp->conf[0] & DPCD_LC03_VOLTAGE_SWING_SET) != voltage) { |
| 211 | voltage = dp->conf[0] & DPCD_LC03_VOLTAGE_SWING_SET; |
| 212 | tries = 0; |
| 213 | } |
| 214 | } while (!cr_done && !abort && ++tries < 5); |
| 215 | |
| 216 | return cr_done ? 0 : -1; |
| 217 | } |
| 218 | |
| 219 | static int |
| 220 | dp_link_train_eq(struct dp_state *dp) |
| 221 | { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 222 | struct nvkm_output_dp *outp = dp->outp; |
Ben Skeggs | c5bd028 | 2013-04-11 10:12:48 +1000 | [diff] [blame] | 223 | bool eq_done = false, cr_done = true; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 224 | int tries = 0, i; |
| 225 | |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 226 | if (outp->dpcd[2] & DPCD_RC02_TPS3_SUPPORTED) |
Ben Skeggs | 6e8e268 | 2014-05-15 22:00:06 +1000 | [diff] [blame] | 227 | dp_set_training_pattern(dp, 3); |
| 228 | else |
| 229 | dp_set_training_pattern(dp, 2); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 230 | |
| 231 | do { |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 232 | if (dp_link_train_update(dp, dp->pc2, 400)) |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 233 | break; |
| 234 | |
| 235 | eq_done = !!(dp->stat[2] & DPCD_LS04_INTERLANE_ALIGN_DONE); |
| 236 | for (i = 0; i < dp->link_nr && eq_done; i++) { |
| 237 | u8 lane = (dp->stat[i >> 1] >> ((i & 1) * 4)) & 0xf; |
| 238 | if (!(lane & DPCD_LS02_LANE0_CR_DONE)) |
| 239 | cr_done = false; |
| 240 | if (!(lane & DPCD_LS02_LANE0_CHANNEL_EQ_DONE) || |
| 241 | !(lane & DPCD_LS02_LANE0_SYMBOL_LOCKED)) |
| 242 | eq_done = false; |
| 243 | } |
| 244 | |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 245 | if (dp_link_train_commit(dp, dp->pc2)) |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 246 | break; |
| 247 | } while (!eq_done && cr_done && ++tries <= 5); |
| 248 | |
| 249 | return eq_done ? 0 : -1; |
| 250 | } |
| 251 | |
| 252 | static void |
| 253 | dp_link_train_init(struct dp_state *dp, bool spread) |
| 254 | { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 255 | struct nvkm_output_dp *outp = dp->outp; |
| 256 | struct nouveau_disp *disp = nouveau_disp(outp); |
| 257 | struct nouveau_bios *bios = nouveau_bios(disp); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 258 | struct nvbios_init init = { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 259 | .subdev = nv_subdev(disp), |
| 260 | .bios = bios, |
| 261 | .outp = &outp->base.info, |
| 262 | .crtc = -1, |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 263 | .execute = 1, |
| 264 | }; |
| 265 | |
| 266 | /* set desired spread */ |
| 267 | if (spread) |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 268 | init.offset = outp->info.script[2]; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 269 | else |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 270 | init.offset = outp->info.script[3]; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 271 | nvbios_exec(&init); |
| 272 | |
| 273 | /* pre-train script */ |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 274 | init.offset = outp->info.script[0]; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 275 | nvbios_exec(&init); |
| 276 | } |
| 277 | |
| 278 | static void |
| 279 | dp_link_train_fini(struct dp_state *dp) |
| 280 | { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 281 | struct nvkm_output_dp *outp = dp->outp; |
| 282 | struct nouveau_disp *disp = nouveau_disp(outp); |
| 283 | struct nouveau_bios *bios = nouveau_bios(disp); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 284 | struct nvbios_init init = { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 285 | .subdev = nv_subdev(disp), |
| 286 | .bios = bios, |
| 287 | .outp = &outp->base.info, |
| 288 | .crtc = -1, |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 289 | .execute = 1, |
| 290 | }; |
| 291 | |
| 292 | /* post-train script */ |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 293 | init.offset = outp->info.script[1], |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 294 | nvbios_exec(&init); |
| 295 | } |
| 296 | |
Ben Skeggs | 1f86ca1 | 2014-05-16 10:49:28 +1000 | [diff] [blame] | 297 | static const struct dp_rates { |
| 298 | u32 rate; |
| 299 | u8 bw; |
| 300 | u8 nr; |
| 301 | } nouveau_dp_rates[] = { |
| 302 | { 2160000, 0x14, 4 }, |
| 303 | { 1080000, 0x0a, 4 }, |
| 304 | { 1080000, 0x14, 2 }, |
| 305 | { 648000, 0x06, 4 }, |
| 306 | { 540000, 0x0a, 2 }, |
| 307 | { 540000, 0x14, 1 }, |
| 308 | { 324000, 0x06, 2 }, |
| 309 | { 270000, 0x0a, 1 }, |
| 310 | { 162000, 0x06, 1 }, |
| 311 | {} |
| 312 | }; |
| 313 | |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 314 | int |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 315 | nouveau_dp_train(struct nvkm_output_dp *outp, u32 datarate) |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 316 | { |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 317 | struct nouveau_disp *disp = nouveau_disp(outp); |
Ben Skeggs | 1f86ca1 | 2014-05-16 10:49:28 +1000 | [diff] [blame] | 318 | const struct dp_rates *cfg = nouveau_dp_rates; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 319 | struct dp_state _dp = { |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 320 | .outp = outp, |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 321 | }, *dp = &_dp; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 322 | int ret; |
| 323 | |
Ben Skeggs | fc243d7 | 2014-03-20 09:28:00 +1000 | [diff] [blame] | 324 | /* bring capabilities within encoder limits */ |
Ben Skeggs | 04e7e92 | 2014-05-15 22:20:40 +1000 | [diff] [blame] | 325 | if (nv_mclass(disp) < NVD0_DISP_CLASS) |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 326 | outp->dpcd[2] &= ~DPCD_RC02_TPS3_SUPPORTED; |
| 327 | if ((outp->dpcd[2] & 0x1f) > outp->base.info.dpconf.link_nr) { |
| 328 | outp->dpcd[2] &= ~DPCD_RC02_MAX_LANE_COUNT; |
| 329 | outp->dpcd[2] |= outp->base.info.dpconf.link_nr; |
Ben Skeggs | fc243d7 | 2014-03-20 09:28:00 +1000 | [diff] [blame] | 330 | } |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 331 | if (outp->dpcd[1] > outp->base.info.dpconf.link_bw) |
| 332 | outp->dpcd[1] = outp->base.info.dpconf.link_bw; |
| 333 | dp->pc2 = outp->dpcd[2] & DPCD_RC02_TPS3_SUPPORTED; |
Ben Skeggs | fc243d7 | 2014-03-20 09:28:00 +1000 | [diff] [blame] | 334 | |
Ben Skeggs | 1f86ca1 | 2014-05-16 10:49:28 +1000 | [diff] [blame] | 335 | /* restrict link config to the lowest required rate, if requested */ |
| 336 | if (datarate) { |
| 337 | datarate = (datarate / 8) * 10; /* 8B/10B coding overhead */ |
| 338 | while (cfg[1].rate >= datarate) |
| 339 | cfg++; |
| 340 | } |
| 341 | cfg--; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 342 | |
| 343 | /* enable down-spreading and execute pre-train script from vbios */ |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 344 | dp_link_train_init(dp, outp->dpcd[3] & 0x01); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 345 | |
Ben Skeggs | 1f86ca1 | 2014-05-16 10:49:28 +1000 | [diff] [blame] | 346 | while (ret = -EIO, (++cfg)->rate) { |
| 347 | /* select next configuration supported by encoder and sink */ |
Ben Skeggs | 3b52a1f | 2014-05-19 14:06:07 +1000 | [diff] [blame^] | 348 | while (cfg->nr > (outp->dpcd[2] & DPCD_RC02_MAX_LANE_COUNT) || |
| 349 | cfg->bw > (outp->dpcd[DPCD_RC01_MAX_LINK_RATE])) |
Ben Skeggs | 1f86ca1 | 2014-05-16 10:49:28 +1000 | [diff] [blame] | 350 | cfg++; |
| 351 | dp->link_bw = cfg->bw * 27000; |
| 352 | dp->link_nr = cfg->nr; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 353 | |
| 354 | /* program selected link configuration */ |
| 355 | ret = dp_set_link_config(dp); |
| 356 | if (ret == 0) { |
| 357 | /* attempt to train the link at this configuration */ |
| 358 | memset(dp->stat, 0x00, sizeof(dp->stat)); |
| 359 | if (!dp_link_train_cr(dp) && |
| 360 | !dp_link_train_eq(dp)) |
| 361 | break; |
| 362 | } else |
Ben Skeggs | 8df1d0c | 2013-11-04 13:40:36 +1000 | [diff] [blame] | 363 | if (ret) { |
| 364 | /* dp_set_link_config() handled training, or |
| 365 | * we failed to communicate with the sink. |
| 366 | */ |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 367 | break; |
| 368 | } |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /* finish link training */ |
| 372 | dp_set_training_pattern(dp, 0); |
Ben Skeggs | 687d8f6 | 2013-11-01 09:36:42 +1000 | [diff] [blame] | 373 | if (ret < 0) |
| 374 | ERR("link training failed\n"); |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 375 | |
| 376 | /* execute post-train script from vbios */ |
| 377 | dp_link_train_fini(dp); |
Ben Skeggs | 8df1d0c | 2013-11-04 13:40:36 +1000 | [diff] [blame] | 378 | return (ret < 0) ? false : true; |
Ben Skeggs | 0a0afd2 | 2013-02-18 23:17:53 -0500 | [diff] [blame] | 379 | } |