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_pack_aux(const u8 * src,int src_bytes)13 u32 intel_dp_pack_aux(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_unpack_aux(u32 src,u8 * dst,int dst_bytes)25 static void intel_dp_unpack_aux(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->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->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 =
180 to_i915(dig_port->base.base.dev);
181 enum phy phy = intel_port_to_phy(i915, dig_port->base.port);
182 u32 ret;
183
184 /*
185 * Max timeout values:
186 * SKL-GLK: 1.6ms
187 * ICL+: 4ms
188 */
189 ret = DP_AUX_CH_CTL_SEND_BUSY |
190 DP_AUX_CH_CTL_DONE |
191 DP_AUX_CH_CTL_INTERRUPT |
192 DP_AUX_CH_CTL_TIME_OUT_ERROR |
193 DP_AUX_CH_CTL_TIME_OUT_MAX |
194 DP_AUX_CH_CTL_RECEIVE_ERROR |
195 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
196 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(intel_dp_aux_fw_sync_len()) |
197 DP_AUX_CH_CTL_SYNC_PULSE_SKL(intel_dp_aux_sync_len());
198
199 if (intel_phy_is_tc(i915, phy) &&
200 dig_port->tc_mode == TC_PORT_TBT_ALT)
201 ret |= DP_AUX_CH_CTL_TBT_IO;
202
203 return ret;
204 }
205
206 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)207 intel_dp_aux_xfer(struct intel_dp *intel_dp,
208 const u8 *send, int send_bytes,
209 u8 *recv, int recv_size,
210 u32 aux_send_ctl_flags)
211 {
212 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
213 struct drm_i915_private *i915 =
214 to_i915(dig_port->base.base.dev);
215 struct intel_uncore *uncore = &i915->uncore;
216 enum phy phy = intel_port_to_phy(i915, dig_port->base.port);
217 bool is_tc_port = intel_phy_is_tc(i915, phy);
218 i915_reg_t ch_ctl, ch_data[5];
219 u32 aux_clock_divider;
220 enum intel_display_power_domain aux_domain;
221 intel_wakeref_t aux_wakeref;
222 intel_wakeref_t pps_wakeref;
223 int i, ret, recv_bytes;
224 int try, clock = 0;
225 u32 status;
226 bool vdd;
227
228 ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
229 for (i = 0; i < ARRAY_SIZE(ch_data); i++)
230 ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i);
231
232 if (is_tc_port)
233 intel_tc_port_lock(dig_port);
234
235 aux_domain = intel_aux_power_domain(dig_port);
236
237 aux_wakeref = intel_display_power_get(i915, aux_domain);
238 pps_wakeref = intel_pps_lock(intel_dp);
239
240 /*
241 * We will be called with VDD already enabled for dpcd/edid/oui reads.
242 * In such cases we want to leave VDD enabled and it's up to upper layers
243 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
244 * ourselves.
245 */
246 vdd = intel_pps_vdd_on_unlocked(intel_dp);
247
248 /*
249 * dp aux is extremely sensitive to irq latency, hence request the
250 * lowest possible wakeup latency and so prevent the cpu from going into
251 * deep sleep states.
252 */
253 cpu_latency_qos_update_request(&intel_dp->pm_qos, 0);
254
255 intel_pps_check_power_unlocked(intel_dp);
256
257 /* Try to wait for any previous AUX channel activity */
258 for (try = 0; try < 3; try++) {
259 status = intel_uncore_read_notrace(uncore, ch_ctl);
260 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
261 break;
262 msleep(1);
263 }
264 /* just trace the final value */
265 trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
266
267 if (try == 3) {
268 const u32 status = intel_uncore_read(uncore, ch_ctl);
269
270 if (status != intel_dp->aux_busy_last_status) {
271 drm_WARN(&i915->drm, 1,
272 "%s: not started (status 0x%08x)\n",
273 intel_dp->aux.name, status);
274 intel_dp->aux_busy_last_status = status;
275 }
276
277 ret = -EBUSY;
278 goto out;
279 }
280
281 /* Only 5 data registers! */
282 if (drm_WARN_ON(&i915->drm, send_bytes > 20 || recv_size > 20)) {
283 ret = -E2BIG;
284 goto out;
285 }
286
287 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
288 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
289 send_bytes,
290 aux_clock_divider);
291
292 send_ctl |= aux_send_ctl_flags;
293
294 /* Must try at least 3 times according to DP spec */
295 for (try = 0; try < 5; try++) {
296 /* Load the send data into the aux channel data registers */
297 for (i = 0; i < send_bytes; i += 4)
298 intel_uncore_write(uncore,
299 ch_data[i >> 2],
300 intel_dp_pack_aux(send + i,
301 send_bytes - i));
302
303 /* Send the command and wait for it to complete */
304 intel_uncore_write(uncore, ch_ctl, send_ctl);
305
306 status = intel_dp_aux_wait_done(intel_dp);
307
308 /* Clear done status and any errors */
309 intel_uncore_write(uncore,
310 ch_ctl,
311 status |
312 DP_AUX_CH_CTL_DONE |
313 DP_AUX_CH_CTL_TIME_OUT_ERROR |
314 DP_AUX_CH_CTL_RECEIVE_ERROR);
315
316 /*
317 * DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
318 * 400us delay required for errors and timeouts
319 * Timeout errors from the HW already meet this
320 * requirement so skip to next iteration
321 */
322 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
323 continue;
324
325 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
326 usleep_range(400, 500);
327 continue;
328 }
329 if (status & DP_AUX_CH_CTL_DONE)
330 goto done;
331 }
332 }
333
334 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
335 drm_err(&i915->drm, "%s: not done (status 0x%08x)\n",
336 intel_dp->aux.name, status);
337 ret = -EBUSY;
338 goto out;
339 }
340
341 done:
342 /*
343 * Check for timeout or receive error. Timeouts occur when the sink is
344 * not connected.
345 */
346 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
347 drm_err(&i915->drm, "%s: receive error (status 0x%08x)\n",
348 intel_dp->aux.name, status);
349 ret = -EIO;
350 goto out;
351 }
352
353 /*
354 * Timeouts occur when the device isn't connected, so they're "normal"
355 * -- don't fill the kernel log with these
356 */
357 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
358 drm_dbg_kms(&i915->drm, "%s: timeout (status 0x%08x)\n",
359 intel_dp->aux.name, status);
360 ret = -ETIMEDOUT;
361 goto out;
362 }
363
364 /* Unload any bytes sent back from the other side */
365 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
366 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
367
368 /*
369 * By BSpec: "Message sizes of 0 or >20 are not allowed."
370 * We have no idea of what happened so we return -EBUSY so
371 * drm layer takes care for the necessary retries.
372 */
373 if (recv_bytes == 0 || recv_bytes > 20) {
374 drm_dbg_kms(&i915->drm,
375 "%s: Forbidden recv_bytes = %d on aux transaction\n",
376 intel_dp->aux.name, recv_bytes);
377 ret = -EBUSY;
378 goto out;
379 }
380
381 if (recv_bytes > recv_size)
382 recv_bytes = recv_size;
383
384 for (i = 0; i < recv_bytes; i += 4)
385 intel_dp_unpack_aux(intel_uncore_read(uncore, ch_data[i >> 2]),
386 recv + i, recv_bytes - i);
387
388 ret = recv_bytes;
389 out:
390 cpu_latency_qos_update_request(&intel_dp->pm_qos, PM_QOS_DEFAULT_VALUE);
391
392 if (vdd)
393 intel_pps_vdd_off_unlocked(intel_dp, false);
394
395 intel_pps_unlock(intel_dp, pps_wakeref);
396 intel_display_power_put_async(i915, aux_domain, aux_wakeref);
397
398 if (is_tc_port)
399 intel_tc_port_unlock(dig_port);
400
401 return ret;
402 }
403
404 #define BARE_ADDRESS_SIZE 3
405 #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
406
407 static void
intel_dp_aux_header(u8 txbuf[HEADER_SIZE],const struct drm_dp_aux_msg * msg)408 intel_dp_aux_header(u8 txbuf[HEADER_SIZE],
409 const struct drm_dp_aux_msg *msg)
410 {
411 txbuf[0] = (msg->request << 4) | ((msg->address >> 16) & 0xf);
412 txbuf[1] = (msg->address >> 8) & 0xff;
413 txbuf[2] = msg->address & 0xff;
414 txbuf[3] = msg->size - 1;
415 }
416
intel_dp_aux_xfer_flags(const struct drm_dp_aux_msg * msg)417 static u32 intel_dp_aux_xfer_flags(const struct drm_dp_aux_msg *msg)
418 {
419 /*
420 * If we're trying to send the HDCP Aksv, we need to set a the Aksv
421 * select bit to inform the hardware to send the Aksv after our header
422 * since we can't access that data from software.
423 */
424 if ((msg->request & ~DP_AUX_I2C_MOT) == DP_AUX_NATIVE_WRITE &&
425 msg->address == DP_AUX_HDCP_AKSV)
426 return DP_AUX_CH_CTL_AUX_AKSV_SELECT;
427
428 return 0;
429 }
430
431 static ssize_t
intel_dp_aux_transfer(struct drm_dp_aux * aux,struct drm_dp_aux_msg * msg)432 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
433 {
434 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
435 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
436 u8 txbuf[20], rxbuf[20];
437 size_t txsize, rxsize;
438 u32 flags = intel_dp_aux_xfer_flags(msg);
439 int ret;
440
441 intel_dp_aux_header(txbuf, msg);
442
443 switch (msg->request & ~DP_AUX_I2C_MOT) {
444 case DP_AUX_NATIVE_WRITE:
445 case DP_AUX_I2C_WRITE:
446 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
447 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
448 rxsize = 2; /* 0 or 1 data bytes */
449
450 if (drm_WARN_ON(&i915->drm, txsize > 20))
451 return -E2BIG;
452
453 drm_WARN_ON(&i915->drm, !msg->buffer != !msg->size);
454
455 if (msg->buffer)
456 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
457
458 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
459 rxbuf, rxsize, flags);
460 if (ret > 0) {
461 msg->reply = rxbuf[0] >> 4;
462
463 if (ret > 1) {
464 /* Number of bytes written in a short write. */
465 ret = clamp_t(int, rxbuf[1], 0, msg->size);
466 } else {
467 /* Return payload size. */
468 ret = msg->size;
469 }
470 }
471 break;
472
473 case DP_AUX_NATIVE_READ:
474 case DP_AUX_I2C_READ:
475 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
476 rxsize = msg->size + 1;
477
478 if (drm_WARN_ON(&i915->drm, rxsize > 20))
479 return -E2BIG;
480
481 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
482 rxbuf, rxsize, flags);
483 if (ret > 0) {
484 msg->reply = rxbuf[0] >> 4;
485 /*
486 * Assume happy day, and copy the data. The caller is
487 * expected to check msg->reply before touching it.
488 *
489 * Return payload size.
490 */
491 ret--;
492 memcpy(msg->buffer, rxbuf + 1, ret);
493 }
494 break;
495
496 default:
497 ret = -EINVAL;
498 break;
499 }
500
501 return ret;
502 }
503
g4x_aux_ctl_reg(struct intel_dp * intel_dp)504 static i915_reg_t g4x_aux_ctl_reg(struct intel_dp *intel_dp)
505 {
506 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
507 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
508 enum aux_ch aux_ch = dig_port->aux_ch;
509
510 switch (aux_ch) {
511 case AUX_CH_B:
512 case AUX_CH_C:
513 case AUX_CH_D:
514 return DP_AUX_CH_CTL(aux_ch);
515 default:
516 MISSING_CASE(aux_ch);
517 return DP_AUX_CH_CTL(AUX_CH_B);
518 }
519 }
520
g4x_aux_data_reg(struct intel_dp * intel_dp,int index)521 static i915_reg_t g4x_aux_data_reg(struct intel_dp *intel_dp, int index)
522 {
523 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
524 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
525 enum aux_ch aux_ch = dig_port->aux_ch;
526
527 switch (aux_ch) {
528 case AUX_CH_B:
529 case AUX_CH_C:
530 case AUX_CH_D:
531 return DP_AUX_CH_DATA(aux_ch, index);
532 default:
533 MISSING_CASE(aux_ch);
534 return DP_AUX_CH_DATA(AUX_CH_B, index);
535 }
536 }
537
ilk_aux_ctl_reg(struct intel_dp * intel_dp)538 static i915_reg_t ilk_aux_ctl_reg(struct intel_dp *intel_dp)
539 {
540 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
541 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
542 enum aux_ch aux_ch = dig_port->aux_ch;
543
544 switch (aux_ch) {
545 case AUX_CH_A:
546 return DP_AUX_CH_CTL(aux_ch);
547 case AUX_CH_B:
548 case AUX_CH_C:
549 case AUX_CH_D:
550 return PCH_DP_AUX_CH_CTL(aux_ch);
551 default:
552 MISSING_CASE(aux_ch);
553 return DP_AUX_CH_CTL(AUX_CH_A);
554 }
555 }
556
ilk_aux_data_reg(struct intel_dp * intel_dp,int index)557 static i915_reg_t ilk_aux_data_reg(struct intel_dp *intel_dp, int index)
558 {
559 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
560 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
561 enum aux_ch aux_ch = dig_port->aux_ch;
562
563 switch (aux_ch) {
564 case AUX_CH_A:
565 return DP_AUX_CH_DATA(aux_ch, index);
566 case AUX_CH_B:
567 case AUX_CH_C:
568 case AUX_CH_D:
569 return PCH_DP_AUX_CH_DATA(aux_ch, index);
570 default:
571 MISSING_CASE(aux_ch);
572 return DP_AUX_CH_DATA(AUX_CH_A, index);
573 }
574 }
575
skl_aux_ctl_reg(struct intel_dp * intel_dp)576 static i915_reg_t skl_aux_ctl_reg(struct intel_dp *intel_dp)
577 {
578 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
579 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
580 enum aux_ch aux_ch = dig_port->aux_ch;
581
582 switch (aux_ch) {
583 case AUX_CH_A:
584 case AUX_CH_B:
585 case AUX_CH_C:
586 case AUX_CH_D:
587 case AUX_CH_E:
588 case AUX_CH_F:
589 return DP_AUX_CH_CTL(aux_ch);
590 default:
591 MISSING_CASE(aux_ch);
592 return DP_AUX_CH_CTL(AUX_CH_A);
593 }
594 }
595
skl_aux_data_reg(struct intel_dp * intel_dp,int index)596 static i915_reg_t skl_aux_data_reg(struct intel_dp *intel_dp, int index)
597 {
598 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
599 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
600 enum aux_ch aux_ch = dig_port->aux_ch;
601
602 switch (aux_ch) {
603 case AUX_CH_A:
604 case AUX_CH_B:
605 case AUX_CH_C:
606 case AUX_CH_D:
607 case AUX_CH_E:
608 case AUX_CH_F:
609 return DP_AUX_CH_DATA(aux_ch, index);
610 default:
611 MISSING_CASE(aux_ch);
612 return DP_AUX_CH_DATA(AUX_CH_A, index);
613 }
614 }
615
tgl_aux_ctl_reg(struct intel_dp * intel_dp)616 static i915_reg_t tgl_aux_ctl_reg(struct intel_dp *intel_dp)
617 {
618 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
619 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
620 enum aux_ch aux_ch = dig_port->aux_ch;
621
622 switch (aux_ch) {
623 case AUX_CH_A:
624 case AUX_CH_B:
625 case AUX_CH_C:
626 case AUX_CH_USBC1:
627 case AUX_CH_USBC2:
628 case AUX_CH_USBC3:
629 case AUX_CH_USBC4:
630 case AUX_CH_USBC5: /* aka AUX_CH_D_XELPD */
631 case AUX_CH_USBC6: /* aka AUX_CH_E_XELPD */
632 return DP_AUX_CH_CTL(aux_ch);
633 default:
634 MISSING_CASE(aux_ch);
635 return DP_AUX_CH_CTL(AUX_CH_A);
636 }
637 }
638
tgl_aux_data_reg(struct intel_dp * intel_dp,int index)639 static i915_reg_t tgl_aux_data_reg(struct intel_dp *intel_dp, int index)
640 {
641 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
642 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
643 enum aux_ch aux_ch = dig_port->aux_ch;
644
645 switch (aux_ch) {
646 case AUX_CH_A:
647 case AUX_CH_B:
648 case AUX_CH_C:
649 case AUX_CH_USBC1:
650 case AUX_CH_USBC2:
651 case AUX_CH_USBC3:
652 case AUX_CH_USBC4:
653 case AUX_CH_USBC5: /* aka AUX_CH_D_XELPD */
654 case AUX_CH_USBC6: /* aka AUX_CH_E_XELPD */
655 return DP_AUX_CH_DATA(aux_ch, index);
656 default:
657 MISSING_CASE(aux_ch);
658 return DP_AUX_CH_DATA(AUX_CH_A, index);
659 }
660 }
661
intel_dp_aux_fini(struct intel_dp * intel_dp)662 void intel_dp_aux_fini(struct intel_dp *intel_dp)
663 {
664 if (cpu_latency_qos_request_active(&intel_dp->pm_qos))
665 cpu_latency_qos_remove_request(&intel_dp->pm_qos);
666
667 kfree(intel_dp->aux.name);
668 }
669
intel_dp_aux_init(struct intel_dp * intel_dp)670 void intel_dp_aux_init(struct intel_dp *intel_dp)
671 {
672 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
673 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
674 struct intel_encoder *encoder = &dig_port->base;
675 enum aux_ch aux_ch = dig_port->aux_ch;
676
677 if (DISPLAY_VER(dev_priv) >= 12) {
678 intel_dp->aux_ch_ctl_reg = tgl_aux_ctl_reg;
679 intel_dp->aux_ch_data_reg = tgl_aux_data_reg;
680 } else if (DISPLAY_VER(dev_priv) >= 9) {
681 intel_dp->aux_ch_ctl_reg = skl_aux_ctl_reg;
682 intel_dp->aux_ch_data_reg = skl_aux_data_reg;
683 } else if (HAS_PCH_SPLIT(dev_priv)) {
684 intel_dp->aux_ch_ctl_reg = ilk_aux_ctl_reg;
685 intel_dp->aux_ch_data_reg = ilk_aux_data_reg;
686 } else {
687 intel_dp->aux_ch_ctl_reg = g4x_aux_ctl_reg;
688 intel_dp->aux_ch_data_reg = g4x_aux_data_reg;
689 }
690
691 if (DISPLAY_VER(dev_priv) >= 9)
692 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
693 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
694 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
695 else if (HAS_PCH_SPLIT(dev_priv))
696 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
697 else
698 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
699
700 if (DISPLAY_VER(dev_priv) >= 9)
701 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
702 else
703 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
704
705 intel_dp->aux.drm_dev = &dev_priv->drm;
706 drm_dp_aux_init(&intel_dp->aux);
707
708 /* Failure to allocate our preferred name is not critical */
709 if (DISPLAY_VER(dev_priv) >= 13 && aux_ch >= AUX_CH_D_XELPD)
710 intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX %c/%s",
711 aux_ch_name(aux_ch - AUX_CH_D_XELPD + AUX_CH_D),
712 encoder->base.name);
713 else if (DISPLAY_VER(dev_priv) >= 12 && aux_ch >= AUX_CH_USBC1)
714 intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX USBC%c/%s",
715 aux_ch - AUX_CH_USBC1 + '1',
716 encoder->base.name);
717 else
718 intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX %c/%s",
719 aux_ch_name(aux_ch),
720 encoder->base.name);
721
722 intel_dp->aux.transfer = intel_dp_aux_transfer;
723 cpu_latency_qos_add_request(&intel_dp->pm_qos, PM_QOS_DEFAULT_VALUE);
724 }
725