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