1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2020-2021 Intel Corporation
4 */
5
6 #include "i915_drv.h"
7 #include "i915_trace.h"
8 #include "intel_display_types.h"
9 #include "intel_dp_aux.h"
10 #include "intel_pps.h"
11 #include "intel_tc.h"
12
intel_dp_aux_pack(const u8 * src,int src_bytes)13 static u32 intel_dp_aux_pack(const u8 *src, int src_bytes)
14 {
15 int i;
16 u32 v = 0;
17
18 if (src_bytes > 4)
19 src_bytes = 4;
20 for (i = 0; i < src_bytes; i++)
21 v |= ((u32)src[i]) << ((3 - i) * 8);
22 return v;
23 }
24
intel_dp_aux_unpack(u32 src,u8 * dst,int dst_bytes)25 static void intel_dp_aux_unpack(u32 src, u8 *dst, int dst_bytes)
26 {
27 int i;
28
29 if (dst_bytes > 4)
30 dst_bytes = 4;
31 for (i = 0; i < dst_bytes; i++)
32 dst[i] = src >> ((3 - i) * 8);
33 }
34
35 static u32
intel_dp_aux_wait_done(struct intel_dp * intel_dp)36 intel_dp_aux_wait_done(struct intel_dp *intel_dp)
37 {
38 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
39 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
40 const unsigned int timeout_ms = 10;
41 u32 status;
42 bool done;
43
44 #define C (((status = intel_uncore_read_notrace(&i915->uncore, ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
45 done = wait_event_timeout(i915->display.gmbus.wait_queue, C,
46 msecs_to_jiffies_timeout(timeout_ms));
47
48 /* just trace the final value */
49 trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
50
51 if (!done)
52 drm_err(&i915->drm,
53 "%s: did not complete or timeout within %ums (status 0x%08x)\n",
54 intel_dp->aux.name, timeout_ms, status);
55 #undef C
56
57 return status;
58 }
59
g4x_get_aux_clock_divider(struct intel_dp * intel_dp,int index)60 static u32 g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
61 {
62 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
63
64 if (index)
65 return 0;
66
67 /*
68 * The clock divider is based off the hrawclk, and would like to run at
69 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
70 */
71 return DIV_ROUND_CLOSEST(RUNTIME_INFO(dev_priv)->rawclk_freq, 2000);
72 }
73
ilk_get_aux_clock_divider(struct intel_dp * intel_dp,int index)74 static u32 ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
75 {
76 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
77 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
78 u32 freq;
79
80 if (index)
81 return 0;
82
83 /*
84 * The clock divider is based off the cdclk or PCH rawclk, and would
85 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
86 * divide by 2000 and use that
87 */
88 if (dig_port->aux_ch == AUX_CH_A)
89 freq = dev_priv->display.cdclk.hw.cdclk;
90 else
91 freq = RUNTIME_INFO(dev_priv)->rawclk_freq;
92 return DIV_ROUND_CLOSEST(freq, 2000);
93 }
94
hsw_get_aux_clock_divider(struct intel_dp * intel_dp,int index)95 static u32 hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
96 {
97 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
98 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
99
100 if (dig_port->aux_ch != AUX_CH_A && HAS_PCH_LPT_H(dev_priv)) {
101 /* Workaround for non-ULT HSW */
102 switch (index) {
103 case 0: return 63;
104 case 1: return 72;
105 default: return 0;
106 }
107 }
108
109 return ilk_get_aux_clock_divider(intel_dp, index);
110 }
111
skl_get_aux_clock_divider(struct intel_dp * intel_dp,int index)112 static u32 skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
113 {
114 /*
115 * SKL doesn't need us to program the AUX clock divider (Hardware will
116 * derive the clock from CDCLK automatically). We still implement the
117 * get_aux_clock_divider vfunc to plug-in into the existing code.
118 */
119 return index ? 0 : 1;
120 }
121
intel_dp_aux_sync_len(void)122 static int intel_dp_aux_sync_len(void)
123 {
124 int precharge = 16; /* 10-16 */
125 int preamble = 16;
126
127 return precharge + preamble;
128 }
129
intel_dp_aux_fw_sync_len(void)130 static int intel_dp_aux_fw_sync_len(void)
131 {
132 int precharge = 10; /* 10-16 */
133 int preamble = 8;
134
135 return precharge + preamble;
136 }
137
g4x_dp_aux_precharge_len(void)138 static int g4x_dp_aux_precharge_len(void)
139 {
140 int precharge_min = 10;
141 int preamble = 16;
142
143 /* HW wants the length of the extra precharge in 2us units */
144 return (intel_dp_aux_sync_len() -
145 precharge_min - preamble) / 2;
146 }
147
g4x_get_aux_send_ctl(struct intel_dp * intel_dp,int send_bytes,u32 aux_clock_divider)148 static u32 g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
149 int send_bytes,
150 u32 aux_clock_divider)
151 {
152 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
153 struct drm_i915_private *dev_priv =
154 to_i915(dig_port->base.base.dev);
155 u32 timeout;
156
157 /* Max timeout value on G4x-BDW: 1.6ms */
158 if (IS_BROADWELL(dev_priv))
159 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
160 else
161 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
162
163 return DP_AUX_CH_CTL_SEND_BUSY |
164 DP_AUX_CH_CTL_DONE |
165 DP_AUX_CH_CTL_INTERRUPT |
166 DP_AUX_CH_CTL_TIME_OUT_ERROR |
167 timeout |
168 DP_AUX_CH_CTL_RECEIVE_ERROR |
169 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
170 (g4x_dp_aux_precharge_len() << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
171 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
172 }
173
skl_get_aux_send_ctl(struct intel_dp * intel_dp,int send_bytes,u32 unused)174 static u32 skl_get_aux_send_ctl(struct intel_dp *intel_dp,
175 int send_bytes,
176 u32 unused)
177 {
178 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
179 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
180 u32 ret;
181
182 /*
183 * Max timeout values:
184 * SKL-GLK: 1.6ms
185 * ICL+: 4ms
186 */
187 ret = DP_AUX_CH_CTL_SEND_BUSY |
188 DP_AUX_CH_CTL_DONE |
189 DP_AUX_CH_CTL_INTERRUPT |
190 DP_AUX_CH_CTL_TIME_OUT_ERROR |
191 DP_AUX_CH_CTL_TIME_OUT_MAX |
192 DP_AUX_CH_CTL_RECEIVE_ERROR |
193 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
194 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(intel_dp_aux_fw_sync_len()) |
195 DP_AUX_CH_CTL_SYNC_PULSE_SKL(intel_dp_aux_sync_len());
196
197 if (intel_tc_port_in_tbt_alt_mode(dig_port))
198 ret |= DP_AUX_CH_CTL_TBT_IO;
199
200 /*
201 * Power request bit is already set during aux power well enable.
202 * Preserve the bit across aux transactions.
203 */
204 if (DISPLAY_VER(i915) >= 14)
205 ret |= XELPDP_DP_AUX_CH_CTL_POWER_REQUEST;
206
207 return ret;
208 }
209
210 static int
intel_dp_aux_xfer(struct intel_dp * intel_dp,const u8 * send,int send_bytes,u8 * recv,int recv_size,u32 aux_send_ctl_flags)211 intel_dp_aux_xfer(struct intel_dp *intel_dp,
212 const u8 *send, int send_bytes,
213 u8 *recv, int recv_size,
214 u32 aux_send_ctl_flags)
215 {
216 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
217 struct drm_i915_private *i915 =
218 to_i915(dig_port->base.base.dev);
219 struct intel_uncore *uncore = &i915->uncore;
220 enum phy phy = intel_port_to_phy(i915, dig_port->base.port);
221 bool is_tc_port = intel_phy_is_tc(i915, phy);
222 i915_reg_t ch_ctl, ch_data[5];
223 u32 aux_clock_divider;
224 enum intel_display_power_domain aux_domain;
225 intel_wakeref_t aux_wakeref;
226 intel_wakeref_t pps_wakeref;
227 int i, ret, recv_bytes;
228 int try, clock = 0;
229 u32 status;
230 bool vdd;
231
232 ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
233 for (i = 0; i < ARRAY_SIZE(ch_data); i++)
234 ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i);
235
236 if (is_tc_port)
237 intel_tc_port_lock(dig_port);
238
239 aux_domain = intel_aux_power_domain(dig_port);
240
241 aux_wakeref = intel_display_power_get(i915, aux_domain);
242 pps_wakeref = intel_pps_lock(intel_dp);
243
244 /*
245 * We will be called with VDD already enabled for dpcd/edid/oui reads.
246 * In such cases we want to leave VDD enabled and it's up to upper layers
247 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
248 * ourselves.
249 */
250 vdd = intel_pps_vdd_on_unlocked(intel_dp);
251
252 /*
253 * dp aux is extremely sensitive to irq latency, hence request the
254 * lowest possible wakeup latency and so prevent the cpu from going into
255 * deep sleep states.
256 */
257 cpu_latency_qos_update_request(&intel_dp->pm_qos, 0);
258
259 intel_pps_check_power_unlocked(intel_dp);
260
261 /* Try to wait for any previous AUX channel activity */
262 for (try = 0; try < 3; try++) {
263 status = intel_uncore_read_notrace(uncore, ch_ctl);
264 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
265 break;
266 msleep(1);
267 }
268 /* just trace the final value */
269 trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
270
271 if (try == 3) {
272 const u32 status = intel_uncore_read(uncore, ch_ctl);
273
274 if (status != intel_dp->aux_busy_last_status) {
275 drm_WARN(&i915->drm, 1,
276 "%s: not started (status 0x%08x)\n",
277 intel_dp->aux.name, status);
278 intel_dp->aux_busy_last_status = status;
279 }
280
281 ret = -EBUSY;
282 goto out;
283 }
284
285 /* Only 5 data registers! */
286 if (drm_WARN_ON(&i915->drm, send_bytes > 20 || recv_size > 20)) {
287 ret = -E2BIG;
288 goto out;
289 }
290
291 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
292 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
293 send_bytes,
294 aux_clock_divider);
295
296 send_ctl |= aux_send_ctl_flags;
297
298 /* Must try at least 3 times according to DP spec */
299 for (try = 0; try < 5; try++) {
300 /* Load the send data into the aux channel data registers */
301 for (i = 0; i < send_bytes; i += 4)
302 intel_uncore_write(uncore,
303 ch_data[i >> 2],
304 intel_dp_aux_pack(send + i,
305 send_bytes - i));
306
307 /* Send the command and wait for it to complete */
308 intel_uncore_write(uncore, ch_ctl, send_ctl);
309
310 status = intel_dp_aux_wait_done(intel_dp);
311
312 /* Clear done status and any errors */
313 intel_uncore_write(uncore,
314 ch_ctl,
315 status |
316 DP_AUX_CH_CTL_DONE |
317 DP_AUX_CH_CTL_TIME_OUT_ERROR |
318 DP_AUX_CH_CTL_RECEIVE_ERROR);
319
320 /*
321 * DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
322 * 400us delay required for errors and timeouts
323 * Timeout errors from the HW already meet this
324 * requirement so skip to next iteration
325 */
326 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
327 continue;
328
329 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
330 usleep_range(400, 500);
331 continue;
332 }
333 if (status & DP_AUX_CH_CTL_DONE)
334 goto done;
335 }
336 }
337
338 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
339 drm_err(&i915->drm, "%s: not done (status 0x%08x)\n",
340 intel_dp->aux.name, status);
341 ret = -EBUSY;
342 goto out;
343 }
344
345 done:
346 /*
347 * Check for timeout or receive error. Timeouts occur when the sink is
348 * not connected.
349 */
350 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
351 drm_err(&i915->drm, "%s: receive error (status 0x%08x)\n",
352 intel_dp->aux.name, status);
353 ret = -EIO;
354 goto out;
355 }
356
357 /*
358 * Timeouts occur when the device isn't connected, so they're "normal"
359 * -- don't fill the kernel log with these
360 */
361 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
362 drm_dbg_kms(&i915->drm, "%s: timeout (status 0x%08x)\n",
363 intel_dp->aux.name, status);
364 ret = -ETIMEDOUT;
365 goto out;
366 }
367
368 /* Unload any bytes sent back from the other side */
369 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
370 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
371
372 /*
373 * By BSpec: "Message sizes of 0 or >20 are not allowed."
374 * We have no idea of what happened so we return -EBUSY so
375 * drm layer takes care for the necessary retries.
376 */
377 if (recv_bytes == 0 || recv_bytes > 20) {
378 drm_dbg_kms(&i915->drm,
379 "%s: Forbidden recv_bytes = %d on aux transaction\n",
380 intel_dp->aux.name, recv_bytes);
381 ret = -EBUSY;
382 goto out;
383 }
384
385 if (recv_bytes > recv_size)
386 recv_bytes = recv_size;
387
388 for (i = 0; i < recv_bytes; i += 4)
389 intel_dp_aux_unpack(intel_uncore_read(uncore, ch_data[i >> 2]),
390 recv + i, recv_bytes - i);
391
392 ret = recv_bytes;
393 out:
394 cpu_latency_qos_update_request(&intel_dp->pm_qos, PM_QOS_DEFAULT_VALUE);
395
396 if (vdd)
397 intel_pps_vdd_off_unlocked(intel_dp, false);
398
399 intel_pps_unlock(intel_dp, pps_wakeref);
400 intel_display_power_put_async(i915, aux_domain, aux_wakeref);
401
402 if (is_tc_port)
403 intel_tc_port_unlock(dig_port);
404
405 return ret;
406 }
407
408 #define BARE_ADDRESS_SIZE 3
409 #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
410
411 static void
intel_dp_aux_header(u8 txbuf[HEADER_SIZE],const struct drm_dp_aux_msg * msg)412 intel_dp_aux_header(u8 txbuf[HEADER_SIZE],
413 const struct drm_dp_aux_msg *msg)
414 {
415 txbuf[0] = (msg->request << 4) | ((msg->address >> 16) & 0xf);
416 txbuf[1] = (msg->address >> 8) & 0xff;
417 txbuf[2] = msg->address & 0xff;
418 txbuf[3] = msg->size - 1;
419 }
420
intel_dp_aux_xfer_flags(const struct drm_dp_aux_msg * msg)421 static u32 intel_dp_aux_xfer_flags(const struct drm_dp_aux_msg *msg)
422 {
423 /*
424 * If we're trying to send the HDCP Aksv, we need to set a the Aksv
425 * select bit to inform the hardware to send the Aksv after our header
426 * since we can't access that data from software.
427 */
428 if ((msg->request & ~DP_AUX_I2C_MOT) == DP_AUX_NATIVE_WRITE &&
429 msg->address == DP_AUX_HDCP_AKSV)
430 return DP_AUX_CH_CTL_AUX_AKSV_SELECT;
431
432 return 0;
433 }
434
435 static ssize_t
intel_dp_aux_transfer(struct drm_dp_aux * aux,struct drm_dp_aux_msg * msg)436 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
437 {
438 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
439 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
440 u8 txbuf[20], rxbuf[20];
441 size_t txsize, rxsize;
442 u32 flags = intel_dp_aux_xfer_flags(msg);
443 int ret;
444
445 intel_dp_aux_header(txbuf, msg);
446
447 switch (msg->request & ~DP_AUX_I2C_MOT) {
448 case DP_AUX_NATIVE_WRITE:
449 case DP_AUX_I2C_WRITE:
450 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
451 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
452 rxsize = 2; /* 0 or 1 data bytes */
453
454 if (drm_WARN_ON(&i915->drm, txsize > 20))
455 return -E2BIG;
456
457 drm_WARN_ON(&i915->drm, !msg->buffer != !msg->size);
458
459 if (msg->buffer)
460 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
461
462 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
463 rxbuf, rxsize, flags);
464 if (ret > 0) {
465 msg->reply = rxbuf[0] >> 4;
466
467 if (ret > 1) {
468 /* Number of bytes written in a short write. */
469 ret = clamp_t(int, rxbuf[1], 0, msg->size);
470 } else {
471 /* Return payload size. */
472 ret = msg->size;
473 }
474 }
475 break;
476
477 case DP_AUX_NATIVE_READ:
478 case DP_AUX_I2C_READ:
479 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
480 rxsize = msg->size + 1;
481
482 if (drm_WARN_ON(&i915->drm, rxsize > 20))
483 return -E2BIG;
484
485 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
486 rxbuf, rxsize, flags);
487 if (ret > 0) {
488 msg->reply = rxbuf[0] >> 4;
489 /*
490 * Assume happy day, and copy the data. The caller is
491 * expected to check msg->reply before touching it.
492 *
493 * Return payload size.
494 */
495 ret--;
496 memcpy(msg->buffer, rxbuf + 1, ret);
497 }
498 break;
499
500 default:
501 ret = -EINVAL;
502 break;
503 }
504
505 return ret;
506 }
507
g4x_aux_ctl_reg(struct intel_dp * intel_dp)508 static i915_reg_t g4x_aux_ctl_reg(struct intel_dp *intel_dp)
509 {
510 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
511 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
512 enum aux_ch aux_ch = dig_port->aux_ch;
513
514 switch (aux_ch) {
515 case AUX_CH_B:
516 case AUX_CH_C:
517 case AUX_CH_D:
518 return DP_AUX_CH_CTL(aux_ch);
519 default:
520 MISSING_CASE(aux_ch);
521 return DP_AUX_CH_CTL(AUX_CH_B);
522 }
523 }
524
g4x_aux_data_reg(struct intel_dp * intel_dp,int index)525 static i915_reg_t g4x_aux_data_reg(struct intel_dp *intel_dp, int index)
526 {
527 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
528 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
529 enum aux_ch aux_ch = dig_port->aux_ch;
530
531 switch (aux_ch) {
532 case AUX_CH_B:
533 case AUX_CH_C:
534 case AUX_CH_D:
535 return DP_AUX_CH_DATA(aux_ch, index);
536 default:
537 MISSING_CASE(aux_ch);
538 return DP_AUX_CH_DATA(AUX_CH_B, index);
539 }
540 }
541
ilk_aux_ctl_reg(struct intel_dp * intel_dp)542 static i915_reg_t ilk_aux_ctl_reg(struct intel_dp *intel_dp)
543 {
544 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
545 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
546 enum aux_ch aux_ch = dig_port->aux_ch;
547
548 switch (aux_ch) {
549 case AUX_CH_A:
550 return DP_AUX_CH_CTL(aux_ch);
551 case AUX_CH_B:
552 case AUX_CH_C:
553 case AUX_CH_D:
554 return PCH_DP_AUX_CH_CTL(aux_ch);
555 default:
556 MISSING_CASE(aux_ch);
557 return DP_AUX_CH_CTL(AUX_CH_A);
558 }
559 }
560
ilk_aux_data_reg(struct intel_dp * intel_dp,int index)561 static i915_reg_t ilk_aux_data_reg(struct intel_dp *intel_dp, int index)
562 {
563 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
564 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
565 enum aux_ch aux_ch = dig_port->aux_ch;
566
567 switch (aux_ch) {
568 case AUX_CH_A:
569 return DP_AUX_CH_DATA(aux_ch, index);
570 case AUX_CH_B:
571 case AUX_CH_C:
572 case AUX_CH_D:
573 return PCH_DP_AUX_CH_DATA(aux_ch, index);
574 default:
575 MISSING_CASE(aux_ch);
576 return DP_AUX_CH_DATA(AUX_CH_A, index);
577 }
578 }
579
skl_aux_ctl_reg(struct intel_dp * intel_dp)580 static i915_reg_t skl_aux_ctl_reg(struct intel_dp *intel_dp)
581 {
582 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
583 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
584 enum aux_ch aux_ch = dig_port->aux_ch;
585
586 switch (aux_ch) {
587 case AUX_CH_A:
588 case AUX_CH_B:
589 case AUX_CH_C:
590 case AUX_CH_D:
591 case AUX_CH_E:
592 case AUX_CH_F:
593 return DP_AUX_CH_CTL(aux_ch);
594 default:
595 MISSING_CASE(aux_ch);
596 return DP_AUX_CH_CTL(AUX_CH_A);
597 }
598 }
599
skl_aux_data_reg(struct intel_dp * intel_dp,int index)600 static i915_reg_t skl_aux_data_reg(struct intel_dp *intel_dp, int index)
601 {
602 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
603 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
604 enum aux_ch aux_ch = dig_port->aux_ch;
605
606 switch (aux_ch) {
607 case AUX_CH_A:
608 case AUX_CH_B:
609 case AUX_CH_C:
610 case AUX_CH_D:
611 case AUX_CH_E:
612 case AUX_CH_F:
613 return DP_AUX_CH_DATA(aux_ch, index);
614 default:
615 MISSING_CASE(aux_ch);
616 return DP_AUX_CH_DATA(AUX_CH_A, index);
617 }
618 }
619
tgl_aux_ctl_reg(struct intel_dp * intel_dp)620 static i915_reg_t tgl_aux_ctl_reg(struct intel_dp *intel_dp)
621 {
622 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
623 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
624 enum aux_ch aux_ch = dig_port->aux_ch;
625
626 switch (aux_ch) {
627 case AUX_CH_A:
628 case AUX_CH_B:
629 case AUX_CH_C:
630 case AUX_CH_USBC1:
631 case AUX_CH_USBC2:
632 case AUX_CH_USBC3:
633 case AUX_CH_USBC4:
634 case AUX_CH_USBC5: /* aka AUX_CH_D_XELPD */
635 case AUX_CH_USBC6: /* aka AUX_CH_E_XELPD */
636 return DP_AUX_CH_CTL(aux_ch);
637 default:
638 MISSING_CASE(aux_ch);
639 return DP_AUX_CH_CTL(AUX_CH_A);
640 }
641 }
642
tgl_aux_data_reg(struct intel_dp * intel_dp,int index)643 static i915_reg_t tgl_aux_data_reg(struct intel_dp *intel_dp, int index)
644 {
645 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
646 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
647 enum aux_ch aux_ch = dig_port->aux_ch;
648
649 switch (aux_ch) {
650 case AUX_CH_A:
651 case AUX_CH_B:
652 case AUX_CH_C:
653 case AUX_CH_USBC1:
654 case AUX_CH_USBC2:
655 case AUX_CH_USBC3:
656 case AUX_CH_USBC4:
657 case AUX_CH_USBC5: /* aka AUX_CH_D_XELPD */
658 case AUX_CH_USBC6: /* aka AUX_CH_E_XELPD */
659 return DP_AUX_CH_DATA(aux_ch, index);
660 default:
661 MISSING_CASE(aux_ch);
662 return DP_AUX_CH_DATA(AUX_CH_A, index);
663 }
664 }
665
xelpdp_aux_ctl_reg(struct intel_dp * intel_dp)666 static i915_reg_t xelpdp_aux_ctl_reg(struct intel_dp *intel_dp)
667 {
668 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
669 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
670 enum aux_ch aux_ch = dig_port->aux_ch;
671
672 switch (aux_ch) {
673 case AUX_CH_A:
674 case AUX_CH_B:
675 case AUX_CH_USBC1:
676 case AUX_CH_USBC2:
677 case AUX_CH_USBC3:
678 case AUX_CH_USBC4:
679 return XELPDP_DP_AUX_CH_CTL(aux_ch);
680 default:
681 MISSING_CASE(aux_ch);
682 return XELPDP_DP_AUX_CH_CTL(AUX_CH_A);
683 }
684 }
685
xelpdp_aux_data_reg(struct intel_dp * intel_dp,int index)686 static i915_reg_t xelpdp_aux_data_reg(struct intel_dp *intel_dp, int index)
687 {
688 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
689 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
690 enum aux_ch aux_ch = dig_port->aux_ch;
691
692 switch (aux_ch) {
693 case AUX_CH_A:
694 case AUX_CH_B:
695 case AUX_CH_USBC1:
696 case AUX_CH_USBC2:
697 case AUX_CH_USBC3:
698 case AUX_CH_USBC4:
699 return XELPDP_DP_AUX_CH_DATA(aux_ch, index);
700 default:
701 MISSING_CASE(aux_ch);
702 return XELPDP_DP_AUX_CH_DATA(AUX_CH_A, index);
703 }
704 }
705
intel_dp_aux_fini(struct intel_dp * intel_dp)706 void intel_dp_aux_fini(struct intel_dp *intel_dp)
707 {
708 if (cpu_latency_qos_request_active(&intel_dp->pm_qos))
709 cpu_latency_qos_remove_request(&intel_dp->pm_qos);
710
711 kfree(intel_dp->aux.name);
712 }
713
intel_dp_aux_init(struct intel_dp * intel_dp)714 void intel_dp_aux_init(struct intel_dp *intel_dp)
715 {
716 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
717 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
718 struct intel_encoder *encoder = &dig_port->base;
719 enum aux_ch aux_ch = dig_port->aux_ch;
720
721 if (DISPLAY_VER(dev_priv) >= 14) {
722 intel_dp->aux_ch_ctl_reg = xelpdp_aux_ctl_reg;
723 intel_dp->aux_ch_data_reg = xelpdp_aux_data_reg;
724 } else if (DISPLAY_VER(dev_priv) >= 12) {
725 intel_dp->aux_ch_ctl_reg = tgl_aux_ctl_reg;
726 intel_dp->aux_ch_data_reg = tgl_aux_data_reg;
727 } else if (DISPLAY_VER(dev_priv) >= 9) {
728 intel_dp->aux_ch_ctl_reg = skl_aux_ctl_reg;
729 intel_dp->aux_ch_data_reg = skl_aux_data_reg;
730 } else if (HAS_PCH_SPLIT(dev_priv)) {
731 intel_dp->aux_ch_ctl_reg = ilk_aux_ctl_reg;
732 intel_dp->aux_ch_data_reg = ilk_aux_data_reg;
733 } else {
734 intel_dp->aux_ch_ctl_reg = g4x_aux_ctl_reg;
735 intel_dp->aux_ch_data_reg = g4x_aux_data_reg;
736 }
737
738 if (DISPLAY_VER(dev_priv) >= 9)
739 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
740 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
741 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
742 else if (HAS_PCH_SPLIT(dev_priv))
743 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
744 else
745 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
746
747 if (DISPLAY_VER(dev_priv) >= 9)
748 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
749 else
750 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
751
752 intel_dp->aux.drm_dev = &dev_priv->drm;
753 drm_dp_aux_init(&intel_dp->aux);
754
755 /* Failure to allocate our preferred name is not critical */
756 if (DISPLAY_VER(dev_priv) >= 13 && aux_ch >= AUX_CH_D_XELPD)
757 intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX %c/%s",
758 aux_ch_name(aux_ch - AUX_CH_D_XELPD + AUX_CH_D),
759 encoder->base.name);
760 else if (DISPLAY_VER(dev_priv) >= 12 && aux_ch >= AUX_CH_USBC1)
761 intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX USBC%c/%s",
762 aux_ch - AUX_CH_USBC1 + '1',
763 encoder->base.name);
764 else
765 intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX %c/%s",
766 aux_ch_name(aux_ch),
767 encoder->base.name);
768
769 intel_dp->aux.transfer = intel_dp_aux_transfer;
770 cpu_latency_qos_add_request(&intel_dp->pm_qos, PM_QOS_DEFAULT_VALUE);
771 }
772