xref: /linux/drivers/gpu/drm/i915/display/intel_cx0_phy.c (revision 6a8bf59de3ef47ff51face6ea826395a1098baa0)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2023 Intel Corporation
4  */
5 
6 #include <linux/log2.h>
7 #include <linux/math64.h>
8 
9 #include <drm/drm_print.h>
10 
11 #include "intel_alpm.h"
12 #include "intel_cmtg.h"
13 #include "intel_cx0_phy.h"
14 #include "intel_cx0_phy_regs.h"
15 #include "intel_display_regs.h"
16 #include "intel_ddi.h"
17 #include "intel_ddi_buf_trans.h"
18 #include "intel_de.h"
19 #include "intel_display_types.h"
20 #include "intel_display_utils.h"
21 #include "intel_dp.h"
22 #include "intel_dpll.h"
23 #include "intel_hdmi.h"
24 #include "intel_lt_phy.h"
25 #include "intel_panel.h"
26 #include "intel_psr.h"
27 #include "intel_snps_hdmi_pll.h"
28 #include "intel_tc.h"
29 
30 #define for_each_cx0_lane_in_mask(__lane_mask, __lane) \
31 	for ((__lane) = 0; (__lane) < 2; (__lane)++) \
32 		for_each_if((__lane_mask) & BIT(__lane))
33 
34 #define INTEL_CX0_LANE0		BIT(0)
35 #define INTEL_CX0_LANE1		BIT(1)
36 #define INTEL_CX0_BOTH_LANES	(INTEL_CX0_LANE1 | INTEL_CX0_LANE0)
37 
38 bool intel_encoder_is_c10phy(struct intel_encoder *encoder)
39 {
40 	struct intel_display *display = to_intel_display(encoder);
41 	enum phy phy = intel_encoder_to_phy(encoder);
42 
43 	if (display->platform.pantherlake) {
44 		if (display->platform.pantherlake_wildcatlake)
45 			return phy <= PHY_B;
46 		else
47 			return phy == PHY_A;
48 	}
49 
50 	if ((display->platform.lunarlake || display->platform.meteorlake) && phy < PHY_C)
51 		return true;
52 
53 	return false;
54 }
55 
56 static int lane_mask_to_lane(u8 lane_mask)
57 {
58 	if (WARN_ON((lane_mask & ~INTEL_CX0_BOTH_LANES) ||
59 		    hweight8(lane_mask) != 1))
60 		return 0;
61 
62 	return ilog2(lane_mask);
63 }
64 
65 static u8 intel_cx0_get_owned_lane_mask(struct intel_encoder *encoder)
66 {
67 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
68 
69 	if (!intel_tc_port_in_dp_alt_mode(dig_port))
70 		return INTEL_CX0_BOTH_LANES;
71 
72 	/*
73 	 * In DP-alt with pin assignment D, only PHY lane 0 is owned
74 	 * by display and lane 1 is owned by USB.
75 	 */
76 	return intel_tc_port_max_lane_count(dig_port) > 2
77 		? INTEL_CX0_BOTH_LANES : INTEL_CX0_LANE0;
78 }
79 
80 static void
81 assert_dc_off(struct intel_display *display)
82 {
83 	bool enabled;
84 
85 	enabled = intel_display_power_is_enabled(display, POWER_DOMAIN_DC_OFF);
86 	drm_WARN_ON(display->drm, !enabled);
87 }
88 
89 static void intel_cx0_program_msgbus_timer(struct intel_encoder *encoder)
90 {
91 	struct intel_display *display = to_intel_display(encoder);
92 	int lane;
93 
94 	for_each_cx0_lane_in_mask(INTEL_CX0_BOTH_LANES, lane)
95 		intel_de_rmw(display,
96 			     XELPDP_PORT_MSGBUS_TIMER(display, encoder->port, lane),
97 			     XELPDP_PORT_MSGBUS_TIMER_VAL_MASK,
98 			     XELPDP_PORT_MSGBUS_TIMER_VAL);
99 }
100 
101 /*
102  * Prepare HW for CX0 phy transactions.
103  *
104  * It is required that PSR and DC5/6 are disabled before any CX0 message
105  * bus transaction is executed.
106  *
107  * We also do the msgbus timer programming here to ensure that the timer
108  * is already programmed before any access to the msgbus.
109  */
110 static struct ref_tracker *intel_cx0_phy_transaction_begin(struct intel_encoder *encoder)
111 {
112 	struct intel_display *display = to_intel_display(encoder);
113 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
114 	struct ref_tracker *wakeref;
115 
116 	intel_psr_pause(intel_dp);
117 	wakeref = intel_display_power_get(display, POWER_DOMAIN_DC_OFF);
118 	intel_cx0_program_msgbus_timer(encoder);
119 
120 	return wakeref;
121 }
122 
123 static void intel_cx0_phy_transaction_end(struct intel_encoder *encoder, struct ref_tracker *wakeref)
124 {
125 	struct intel_display *display = to_intel_display(encoder);
126 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
127 
128 	intel_psr_resume(intel_dp);
129 	intel_display_power_put(display, POWER_DOMAIN_DC_OFF, wakeref);
130 }
131 
132 void intel_cx0_clear_response_ready_flag(struct intel_encoder *encoder,
133 					 int lane)
134 {
135 	struct intel_display *display = to_intel_display(encoder);
136 
137 	intel_de_rmw(display,
138 		     XELPDP_PORT_P2M_MSGBUS_STATUS(display, encoder->port, lane),
139 		     0, XELPDP_PORT_P2M_RESPONSE_READY | XELPDP_PORT_P2M_ERROR_SET);
140 }
141 
142 void intel_cx0_bus_reset(struct intel_encoder *encoder, int lane)
143 {
144 	struct intel_display *display = to_intel_display(encoder);
145 	enum port port = encoder->port;
146 	enum phy phy = intel_encoder_to_phy(encoder);
147 
148 	intel_de_write(display, XELPDP_PORT_M2P_MSGBUS_CTL(display, port, lane),
149 		       XELPDP_PORT_M2P_TRANSACTION_RESET);
150 
151 	if (intel_de_wait_for_clear_ms(display, XELPDP_PORT_M2P_MSGBUS_CTL(display, port, lane),
152 				       XELPDP_PORT_M2P_TRANSACTION_RESET,
153 				       XELPDP_MSGBUS_TIMEOUT_MS)) {
154 		drm_err_once(display->drm,
155 			     "Failed to bring PHY %c to idle.\n",
156 			     phy_name(phy));
157 		return;
158 	}
159 
160 	intel_cx0_clear_response_ready_flag(encoder, lane);
161 }
162 
163 int intel_cx0_wait_for_ack(struct intel_encoder *encoder,
164 			   int command, int lane, u32 *val)
165 {
166 	struct intel_display *display = to_intel_display(encoder);
167 	enum port port = encoder->port;
168 	enum phy phy = intel_encoder_to_phy(encoder);
169 
170 	if (intel_de_wait_ms(display, XELPDP_PORT_P2M_MSGBUS_STATUS(display, port, lane),
171 			     XELPDP_PORT_P2M_RESPONSE_READY,
172 			     XELPDP_PORT_P2M_RESPONSE_READY,
173 			     XELPDP_MSGBUS_TIMEOUT_MS, val)) {
174 		drm_dbg_kms(display->drm,
175 			    "PHY %c Timeout waiting for message ACK. Status: 0x%x\n",
176 			    phy_name(phy), *val);
177 
178 		if (!(intel_de_read(display, XELPDP_PORT_MSGBUS_TIMER(display, port, lane)) &
179 		      XELPDP_PORT_MSGBUS_TIMER_TIMED_OUT))
180 			drm_dbg_kms(display->drm,
181 				    "PHY %c Hardware did not detect a timeout\n",
182 				    phy_name(phy));
183 
184 		intel_cx0_bus_reset(encoder, lane);
185 		return -ETIMEDOUT;
186 	}
187 
188 	if (*val & XELPDP_PORT_P2M_ERROR_SET) {
189 		drm_dbg_kms(display->drm,
190 			    "PHY %c Error occurred during %s command. Status: 0x%x\n",
191 			    phy_name(phy),
192 			    command == XELPDP_PORT_P2M_COMMAND_READ_ACK ? "read" : "write", *val);
193 		intel_cx0_bus_reset(encoder, lane);
194 		return -EINVAL;
195 	}
196 
197 	if (REG_FIELD_GET(XELPDP_PORT_P2M_COMMAND_TYPE_MASK, *val) != command) {
198 		drm_dbg_kms(display->drm,
199 			    "PHY %c Not a %s response. MSGBUS Status: 0x%x.\n",
200 			    phy_name(phy),
201 			    command == XELPDP_PORT_P2M_COMMAND_READ_ACK ? "read" : "write", *val);
202 		intel_cx0_bus_reset(encoder, lane);
203 		return -EINVAL;
204 	}
205 
206 	return 0;
207 }
208 
209 static int __intel_cx0_read_once(struct intel_encoder *encoder,
210 				 int lane, u16 addr)
211 {
212 	struct intel_display *display = to_intel_display(encoder);
213 	enum port port = encoder->port;
214 	enum phy phy = intel_encoder_to_phy(encoder);
215 	int ack;
216 	u32 val;
217 
218 	if (intel_de_wait_for_clear_ms(display, XELPDP_PORT_M2P_MSGBUS_CTL(display, port, lane),
219 				       XELPDP_PORT_M2P_TRANSACTION_PENDING,
220 				       XELPDP_MSGBUS_TIMEOUT_MS)) {
221 		drm_dbg_kms(display->drm,
222 			    "PHY %c Timeout waiting for previous transaction to complete. Reset the bus and retry.\n", phy_name(phy));
223 		intel_cx0_bus_reset(encoder, lane);
224 		return -ETIMEDOUT;
225 	}
226 
227 	intel_cx0_clear_response_ready_flag(encoder, lane);
228 
229 	intel_de_write(display, XELPDP_PORT_M2P_MSGBUS_CTL(display, port, lane),
230 		       XELPDP_PORT_M2P_TRANSACTION_PENDING |
231 		       XELPDP_PORT_M2P_COMMAND_READ |
232 		       XELPDP_PORT_M2P_ADDRESS(addr));
233 
234 	ack = intel_cx0_wait_for_ack(encoder, XELPDP_PORT_P2M_COMMAND_READ_ACK, lane, &val);
235 	if (ack < 0)
236 		return ack;
237 
238 	intel_cx0_clear_response_ready_flag(encoder, lane);
239 
240 	/*
241 	 * FIXME: Workaround to let HW to settle
242 	 * down and let the message bus to end up
243 	 * in a known state
244 	 */
245 	if (DISPLAY_VER(display) < 30)
246 		intel_cx0_bus_reset(encoder, lane);
247 
248 	return REG_FIELD_GET(XELPDP_PORT_P2M_DATA_MASK, val);
249 }
250 
251 static u8 __intel_cx0_read(struct intel_encoder *encoder,
252 			   int lane, u16 addr)
253 {
254 	struct intel_display *display = to_intel_display(encoder);
255 	enum phy phy = intel_encoder_to_phy(encoder);
256 	int i, status;
257 
258 	assert_dc_off(display);
259 
260 	/* 3 tries is assumed to be enough to read successfully */
261 	for (i = 0; i < 3; i++) {
262 		status = __intel_cx0_read_once(encoder, lane, addr);
263 
264 		if (status >= 0)
265 			return status;
266 	}
267 
268 	drm_err_once(display->drm,
269 		     "PHY %c Read %04x failed after %d retries.\n",
270 		     phy_name(phy), addr, i);
271 
272 	return 0;
273 }
274 
275 u8 intel_cx0_read(struct intel_encoder *encoder, u8 lane_mask, u16 addr)
276 {
277 	int lane = lane_mask_to_lane(lane_mask);
278 
279 	return __intel_cx0_read(encoder, lane, addr);
280 }
281 
282 static int __intel_cx0_write_once(struct intel_encoder *encoder,
283 				  int lane, u16 addr, u8 data, bool committed)
284 {
285 	struct intel_display *display = to_intel_display(encoder);
286 	enum port port = encoder->port;
287 	enum phy phy = intel_encoder_to_phy(encoder);
288 	int ack;
289 	u32 val;
290 
291 	if (intel_de_wait_for_clear_ms(display, XELPDP_PORT_M2P_MSGBUS_CTL(display, port, lane),
292 				       XELPDP_PORT_M2P_TRANSACTION_PENDING,
293 				       XELPDP_MSGBUS_TIMEOUT_MS)) {
294 		drm_dbg_kms(display->drm,
295 			    "PHY %c Timeout waiting for previous transaction to complete. Resetting the bus.\n", phy_name(phy));
296 		intel_cx0_bus_reset(encoder, lane);
297 		return -ETIMEDOUT;
298 	}
299 
300 	intel_cx0_clear_response_ready_flag(encoder, lane);
301 
302 	intel_de_write(display, XELPDP_PORT_M2P_MSGBUS_CTL(display, port, lane),
303 		       XELPDP_PORT_M2P_TRANSACTION_PENDING |
304 		       (committed ? XELPDP_PORT_M2P_COMMAND_WRITE_COMMITTED :
305 				    XELPDP_PORT_M2P_COMMAND_WRITE_UNCOMMITTED) |
306 		       XELPDP_PORT_M2P_DATA(data) |
307 		       XELPDP_PORT_M2P_ADDRESS(addr));
308 
309 	if (intel_de_wait_for_clear_ms(display, XELPDP_PORT_M2P_MSGBUS_CTL(display, port, lane),
310 				       XELPDP_PORT_M2P_TRANSACTION_PENDING,
311 				       XELPDP_MSGBUS_TIMEOUT_MS)) {
312 		drm_dbg_kms(display->drm,
313 			    "PHY %c Timeout waiting for write to complete. Resetting the bus.\n", phy_name(phy));
314 		intel_cx0_bus_reset(encoder, lane);
315 		return -ETIMEDOUT;
316 	}
317 
318 	if (committed) {
319 		ack = intel_cx0_wait_for_ack(encoder, XELPDP_PORT_P2M_COMMAND_WRITE_ACK, lane, &val);
320 		if (ack < 0)
321 			return ack;
322 	} else if ((intel_de_read(display, XELPDP_PORT_P2M_MSGBUS_STATUS(display, port, lane)) &
323 		    XELPDP_PORT_P2M_ERROR_SET)) {
324 		drm_dbg_kms(display->drm,
325 			    "PHY %c Error occurred during write command.\n", phy_name(phy));
326 		intel_cx0_bus_reset(encoder, lane);
327 		return -EINVAL;
328 	}
329 
330 	intel_cx0_clear_response_ready_flag(encoder, lane);
331 
332 	/*
333 	 * FIXME: Workaround to let HW to settle
334 	 * down and let the message bus to end up
335 	 * in a known state
336 	 */
337 	if (DISPLAY_VER(display) < 30)
338 		intel_cx0_bus_reset(encoder, lane);
339 
340 	return 0;
341 }
342 
343 static void __intel_cx0_write(struct intel_encoder *encoder,
344 			      int lane, u16 addr, u8 data, bool committed)
345 {
346 	struct intel_display *display = to_intel_display(encoder);
347 	enum phy phy = intel_encoder_to_phy(encoder);
348 	int i, status;
349 
350 	assert_dc_off(display);
351 
352 	/* 3 tries is assumed to be enough to write successfully */
353 	for (i = 0; i < 3; i++) {
354 		status = __intel_cx0_write_once(encoder, lane, addr, data, committed);
355 
356 		if (status == 0)
357 			return;
358 	}
359 
360 	drm_err_once(display->drm,
361 		     "PHY %c Write %04x failed after %d retries.\n", phy_name(phy), addr, i);
362 }
363 
364 void intel_cx0_write(struct intel_encoder *encoder,
365 		     u8 lane_mask, u16 addr, u8 data, bool committed)
366 {
367 	int lane;
368 
369 	for_each_cx0_lane_in_mask(lane_mask, lane)
370 		__intel_cx0_write(encoder, lane, addr, data, committed);
371 }
372 
373 static void intel_c20_sram_write(struct intel_encoder *encoder,
374 				 int lane, u16 addr, u16 data)
375 {
376 	struct intel_display *display = to_intel_display(encoder);
377 
378 	assert_dc_off(display);
379 
380 	intel_cx0_write(encoder, lane, PHY_C20_WR_ADDRESS_H, addr >> 8, 0);
381 	intel_cx0_write(encoder, lane, PHY_C20_WR_ADDRESS_L, addr & 0xff, 0);
382 
383 	intel_cx0_write(encoder, lane, PHY_C20_WR_DATA_H, data >> 8, 0);
384 	intel_cx0_write(encoder, lane, PHY_C20_WR_DATA_L, data & 0xff, 1);
385 }
386 
387 static u16 intel_c20_sram_read(struct intel_encoder *encoder,
388 			       int lane, u16 addr)
389 {
390 	struct intel_display *display = to_intel_display(encoder);
391 	u16 val;
392 
393 	assert_dc_off(display);
394 
395 	intel_cx0_write(encoder, lane, PHY_C20_RD_ADDRESS_H, addr >> 8, 0);
396 	intel_cx0_write(encoder, lane, PHY_C20_RD_ADDRESS_L, addr & 0xff, 1);
397 
398 	val = intel_cx0_read(encoder, lane, PHY_C20_RD_DATA_H);
399 	val <<= 8;
400 	val |= intel_cx0_read(encoder, lane, PHY_C20_RD_DATA_L);
401 
402 	return val;
403 }
404 
405 static void __intel_cx0_rmw(struct intel_encoder *encoder,
406 			    int lane, u16 addr, u8 clear, u8 set, bool committed)
407 {
408 	u8 old, val;
409 
410 	old = __intel_cx0_read(encoder, lane, addr);
411 	val = (old & ~clear) | set;
412 
413 	if (val != old)
414 		__intel_cx0_write(encoder, lane, addr, val, committed);
415 }
416 
417 void intel_cx0_rmw(struct intel_encoder *encoder,
418 		   u8 lane_mask, u16 addr, u8 clear, u8 set, bool committed)
419 {
420 	u8 lane;
421 
422 	for_each_cx0_lane_in_mask(lane_mask, lane)
423 		__intel_cx0_rmw(encoder, lane, addr, clear, set, committed);
424 }
425 
426 static u8 intel_c10_get_tx_vboost_lvl(const struct intel_crtc_state *crtc_state)
427 {
428 	if (intel_crtc_has_dp_encoder(crtc_state)) {
429 		if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP) &&
430 		    (crtc_state->port_clock == 540000 ||
431 		     crtc_state->port_clock == 810000))
432 			return 5;
433 		else
434 			return 4;
435 	} else {
436 		return 5;
437 	}
438 }
439 
440 static u8 intel_c10_get_tx_term_ctl(const struct intel_crtc_state *crtc_state)
441 {
442 	if (intel_crtc_has_dp_encoder(crtc_state)) {
443 		if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP) &&
444 		    (crtc_state->port_clock == 540000 ||
445 		     crtc_state->port_clock == 810000))
446 			return 5;
447 		else
448 			return 2;
449 	} else {
450 		return 6;
451 	}
452 }
453 
454 static void intel_c10_msgbus_access_begin(struct intel_encoder *encoder,
455 					  u8 lane_mask)
456 {
457 	if (!intel_encoder_is_c10phy(encoder))
458 		return;
459 
460 	intel_cx0_rmw(encoder, lane_mask, PHY_C10_VDR_CONTROL(1),
461 		      0, C10_VDR_CTRL_MSGBUS_ACCESS, MB_WRITE_COMMITTED);
462 }
463 
464 static void intel_c10_msgbus_access_commit(struct intel_encoder *encoder,
465 					   u8 lane_mask, bool master_lane)
466 {
467 	u8 val = C10_VDR_CTRL_UPDATE_CFG;
468 
469 	if (!intel_encoder_is_c10phy(encoder))
470 		return;
471 
472 	if (master_lane)
473 		val |= C10_VDR_CTRL_MASTER_LANE;
474 
475 	intel_cx0_rmw(encoder, lane_mask, PHY_C10_VDR_CONTROL(1),
476 		      0, val, MB_WRITE_COMMITTED);
477 }
478 
479 void intel_cx0_phy_set_signal_levels(struct intel_encoder *encoder,
480 				     const struct intel_crtc_state *crtc_state)
481 {
482 	struct intel_display *display = to_intel_display(encoder);
483 	const struct intel_ddi_buf_trans *trans;
484 	u8 owned_lane_mask;
485 	struct ref_tracker *wakeref;
486 	int n_entries, ln;
487 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
488 
489 	if (intel_tc_port_in_tbt_alt_mode(dig_port))
490 		return;
491 
492 	owned_lane_mask = intel_cx0_get_owned_lane_mask(encoder);
493 
494 	wakeref = intel_cx0_phy_transaction_begin(encoder);
495 
496 	trans = intel_ddi_buf_trans_get(encoder, crtc_state, &n_entries);
497 	if (drm_WARN_ON_ONCE(display->drm, !trans)) {
498 		intel_cx0_phy_transaction_end(encoder, wakeref);
499 		return;
500 	}
501 
502 	intel_c10_msgbus_access_begin(encoder, owned_lane_mask);
503 
504 	if (intel_encoder_is_c10phy(encoder)) {
505 		intel_cx0_rmw(encoder, owned_lane_mask, PHY_C10_VDR_CMN(3),
506 			      C10_CMN3_TXVBOOST_MASK,
507 			      C10_CMN3_TXVBOOST(intel_c10_get_tx_vboost_lvl(crtc_state)),
508 			      MB_WRITE_UNCOMMITTED);
509 		intel_cx0_rmw(encoder, owned_lane_mask, PHY_C10_VDR_TX(1),
510 			      C10_TX1_TERMCTL_MASK,
511 			      C10_TX1_TERMCTL(intel_c10_get_tx_term_ctl(crtc_state)),
512 			      MB_WRITE_COMMITTED);
513 	}
514 
515 	for (ln = 0; ln < crtc_state->lane_count; ln++) {
516 		int level = intel_ddi_level(encoder, crtc_state, ln);
517 		int lane = ln / 2;
518 		int tx = ln % 2;
519 		u8 lane_mask = lane == 0 ? INTEL_CX0_LANE0 : INTEL_CX0_LANE1;
520 
521 		if (!(lane_mask & owned_lane_mask))
522 			continue;
523 
524 		intel_cx0_rmw(encoder, lane_mask, PHY_CX0_VDROVRD_CTL(lane, tx, 0),
525 			      C10_PHY_OVRD_LEVEL_MASK,
526 			      C10_PHY_OVRD_LEVEL(trans->entries[level].snps.pre_cursor),
527 			      MB_WRITE_COMMITTED);
528 		intel_cx0_rmw(encoder, lane_mask, PHY_CX0_VDROVRD_CTL(lane, tx, 1),
529 			      C10_PHY_OVRD_LEVEL_MASK,
530 			      C10_PHY_OVRD_LEVEL(trans->entries[level].snps.vswing),
531 			      MB_WRITE_COMMITTED);
532 		intel_cx0_rmw(encoder, lane_mask, PHY_CX0_VDROVRD_CTL(lane, tx, 2),
533 			      C10_PHY_OVRD_LEVEL_MASK,
534 			      C10_PHY_OVRD_LEVEL(trans->entries[level].snps.post_cursor),
535 			      MB_WRITE_COMMITTED);
536 	}
537 
538 	/* Write Override enables in 0xD71 */
539 	intel_cx0_rmw(encoder, owned_lane_mask, PHY_C10_VDR_OVRD,
540 		      0, PHY_C10_VDR_OVRD_TX1 | PHY_C10_VDR_OVRD_TX2,
541 		      MB_WRITE_COMMITTED);
542 
543 	intel_c10_msgbus_access_commit(encoder, owned_lane_mask, false);
544 
545 	intel_cx0_phy_transaction_end(encoder, wakeref);
546 }
547 
548 /*
549  * Basic DP link rates with 38.4 MHz reference clock.
550  * Note: The tables below are with SSC. In non-ssc
551  * registers 0xC04 to 0xC08(pll[4] to pll[8]) will be
552  * programmed 0.
553  */
554 
555 static const struct intel_c10pll_state mtl_c10_dp_rbr = {
556 	.tx = 0x10,
557 	.cmn = 0x21,
558 	.pll[0] = 0xB4,
559 	.pll[1] = 0,
560 	.pll[2] = 0x30,
561 	.pll[3] = 0x1,
562 	.pll[4] = 0x26,
563 	.pll[5] = 0x0C,
564 	.pll[6] = 0x98,
565 	.pll[7] = 0x46,
566 	.pll[8] = 0x1,
567 	.pll[9] = 0x1,
568 	.pll[10] = 0,
569 	.pll[11] = 0,
570 	.pll[12] = 0xC0,
571 	.pll[13] = 0,
572 	.pll[14] = 0,
573 	.pll[15] = 0x2,
574 	.pll[16] = 0x84,
575 	.pll[17] = 0x4F,
576 	.pll[18] = 0xE5,
577 	.pll[19] = 0x23,
578 };
579 
580 static const struct intel_c10pll_state mtl_c10_edp_r216 = {
581 	.tx = 0x10,
582 	.cmn = 0x21,
583 	.pll[0] = 0x4,
584 	.pll[1] = 0,
585 	.pll[2] = 0xA2,
586 	.pll[3] = 0x1,
587 	.pll[4] = 0x33,
588 	.pll[5] = 0x10,
589 	.pll[6] = 0x75,
590 	.pll[7] = 0xB3,
591 	.pll[8] = 0x1,
592 	.pll[9] = 0x1,
593 	.pll[10] = 0,
594 	.pll[11] = 0,
595 	.pll[12] = 0,
596 	.pll[13] = 0,
597 	.pll[14] = 0,
598 	.pll[15] = 0x2,
599 	.pll[16] = 0x85,
600 	.pll[17] = 0x0F,
601 	.pll[18] = 0xE6,
602 	.pll[19] = 0x23,
603 };
604 
605 static const struct intel_c10pll_state mtl_c10_edp_r243 = {
606 	.tx = 0x10,
607 	.cmn = 0x21,
608 	.pll[0] = 0x34,
609 	.pll[1] = 0,
610 	.pll[2] = 0xDA,
611 	.pll[3] = 0x1,
612 	.pll[4] = 0x39,
613 	.pll[5] = 0x12,
614 	.pll[6] = 0xE3,
615 	.pll[7] = 0xE9,
616 	.pll[8] = 0x1,
617 	.pll[9] = 0x1,
618 	.pll[10] = 0,
619 	.pll[11] = 0,
620 	.pll[12] = 0x20,
621 	.pll[13] = 0,
622 	.pll[14] = 0,
623 	.pll[15] = 0x2,
624 	.pll[16] = 0x85,
625 	.pll[17] = 0x8F,
626 	.pll[18] = 0xE6,
627 	.pll[19] = 0x23,
628 };
629 
630 static const struct intel_c10pll_state mtl_c10_dp_hbr1 = {
631 	.tx = 0x10,
632 	.cmn = 0x21,
633 	.pll[0] = 0xF4,
634 	.pll[1] = 0,
635 	.pll[2] = 0xF8,
636 	.pll[3] = 0x0,
637 	.pll[4] = 0x20,
638 	.pll[5] = 0x0A,
639 	.pll[6] = 0x29,
640 	.pll[7] = 0x10,
641 	.pll[8] = 0x1,   /* Verify */
642 	.pll[9] = 0x1,
643 	.pll[10] = 0,
644 	.pll[11] = 0,
645 	.pll[12] = 0xA0,
646 	.pll[13] = 0,
647 	.pll[14] = 0,
648 	.pll[15] = 0x1,
649 	.pll[16] = 0x84,
650 	.pll[17] = 0x4F,
651 	.pll[18] = 0xE5,
652 	.pll[19] = 0x23,
653 };
654 
655 static const struct intel_c10pll_state mtl_c10_edp_r324 = {
656 	.tx = 0x10,
657 	.cmn = 0x21,
658 	.pll[0] = 0xB4,
659 	.pll[1] = 0,
660 	.pll[2] = 0x30,
661 	.pll[3] = 0x1,
662 	.pll[4] = 0x26,
663 	.pll[5] = 0x0C,
664 	.pll[6] = 0x98,
665 	.pll[7] = 0x46,
666 	.pll[8] = 0x1,
667 	.pll[9] = 0x1,
668 	.pll[10] = 0,
669 	.pll[11] = 0,
670 	.pll[12] = 0xC0,
671 	.pll[13] = 0,
672 	.pll[14] = 0,
673 	.pll[15] = 0x1,
674 	.pll[16] = 0x85,
675 	.pll[17] = 0x4F,
676 	.pll[18] = 0xE6,
677 	.pll[19] = 0x23,
678 };
679 
680 static const struct intel_c10pll_state mtl_c10_edp_r432 = {
681 	.tx = 0x10,
682 	.cmn = 0x21,
683 	.pll[0] = 0x4,
684 	.pll[1] = 0,
685 	.pll[2] = 0xA2,
686 	.pll[3] = 0x1,
687 	.pll[4] = 0x33,
688 	.pll[5] = 0x10,
689 	.pll[6] = 0x75,
690 	.pll[7] = 0xB3,
691 	.pll[8] = 0x1,
692 	.pll[9] = 0x1,
693 	.pll[10] = 0,
694 	.pll[11] = 0,
695 	.pll[12] = 0,
696 	.pll[13] = 0,
697 	.pll[14] = 0,
698 	.pll[15] = 0x1,
699 	.pll[16] = 0x85,
700 	.pll[17] = 0x0F,
701 	.pll[18] = 0xE6,
702 	.pll[19] = 0x23,
703 };
704 
705 static const struct intel_c10pll_state mtl_c10_dp_hbr2 = {
706 	.tx = 0x10,
707 	.cmn = 0x21,
708 	.pll[0] = 0xF4,
709 	.pll[1] = 0,
710 	.pll[2] = 0xF8,
711 	.pll[3] = 0,
712 	.pll[4] = 0x20,
713 	.pll[5] = 0x0A,
714 	.pll[6] = 0x29,
715 	.pll[7] = 0x10,
716 	.pll[8] = 0x1,
717 	.pll[9] = 0x1,
718 	.pll[10] = 0,
719 	.pll[11] = 0,
720 	.pll[12] = 0xA0,
721 	.pll[13] = 0,
722 	.pll[14] = 0,
723 	.pll[15] = 0,
724 	.pll[16] = 0x84,
725 	.pll[17] = 0x4F,
726 	.pll[18] = 0xE5,
727 	.pll[19] = 0x23,
728 };
729 
730 static const struct intel_c10pll_state mtl_c10_edp_r675 = {
731 	.tx = 0x10,
732 	.cmn = 0x21,
733 	.pll[0] = 0xB4,
734 	.pll[1] = 0,
735 	.pll[2] = 0x3E,
736 	.pll[3] = 0x1,
737 	.pll[4] = 0xA8,
738 	.pll[5] = 0x0C,
739 	.pll[6] = 0x33,
740 	.pll[7] = 0x54,
741 	.pll[8] = 0x1,
742 	.pll[9] = 0x1,
743 	.pll[10] = 0,
744 	.pll[11] = 0,
745 	.pll[12] = 0xC8,
746 	.pll[13] = 0,
747 	.pll[14] = 0,
748 	.pll[15] = 0,
749 	.pll[16] = 0x85,
750 	.pll[17] = 0x8F,
751 	.pll[18] = 0xE6,
752 	.pll[19] = 0x23,
753 };
754 
755 static const struct intel_c10pll_state mtl_c10_dp_hbr3 = {
756 	.tx = 0x10,
757 	.cmn = 0x21,
758 	.pll[0] = 0x34,
759 	.pll[1] = 0,
760 	.pll[2] = 0x84,
761 	.pll[3] = 0x1,
762 	.pll[4] = 0x30,
763 	.pll[5] = 0x0F,
764 	.pll[6] = 0x3D,
765 	.pll[7] = 0x98,
766 	.pll[8] = 0x1,
767 	.pll[9] = 0x1,
768 	.pll[10] = 0,
769 	.pll[11] = 0,
770 	.pll[12] = 0xF0,
771 	.pll[13] = 0,
772 	.pll[14] = 0,
773 	.pll[15] = 0,
774 	.pll[16] = 0x84,
775 	.pll[17] = 0x0F,
776 	.pll[18] = 0xE5,
777 	.pll[19] = 0x23,
778 };
779 
780 struct intel_cx0pll_params {
781 	const char *name;
782 	bool is_c10;
783 	bool is_hdmi;
784 	int clock_rate;
785 	union {
786 		const struct intel_c10pll_state *c10;
787 		const struct intel_c20pll_state *c20;
788 	};
789 };
790 
791 #define __C10PLL_PARAMS(__is_hdmi, __clock_rate, __state) { \
792 	.name = __stringify(__state), \
793 	.is_c10 = true, \
794 	.is_hdmi = __is_hdmi, \
795 	.clock_rate = __clock_rate, \
796 	.c10 = &__state, \
797 }
798 
799 #define __C20PLL_PARAMS(__is_hdmi, __clock_rate, __state)    { \
800 	.name = __stringify(__state), \
801 	.is_c10 = false, \
802 	.is_hdmi = __is_hdmi, \
803 	.clock_rate = __clock_rate, \
804 	.c20 = &__state, \
805 }
806 
807 #define C10PLL_HDMI_PARAMS(__clock_rate, __state)       __C10PLL_PARAMS(true, __clock_rate, __state)
808 #define C10PLL_DP_PARAMS(__clock_rate, __state)         __C10PLL_PARAMS(false, __clock_rate, __state)
809 
810 #define C20PLL_HDMI_PARAMS(__clock_rate, __state)       __C20PLL_PARAMS(true, __clock_rate, __state)
811 #define C20PLL_DP_PARAMS(__clock_rate, __state)         __C20PLL_PARAMS(false, __clock_rate, __state)
812 
813 static const struct intel_cx0pll_params mtl_c10_dp_tables[] = {
814 	C10PLL_DP_PARAMS(162000, mtl_c10_dp_rbr),
815 	C10PLL_DP_PARAMS(270000, mtl_c10_dp_hbr1),
816 	C10PLL_DP_PARAMS(540000, mtl_c10_dp_hbr2),
817 	C10PLL_DP_PARAMS(810000, mtl_c10_dp_hbr3),
818 	{}
819 };
820 
821 static const struct intel_cx0pll_params mtl_c10_edp_tables[] = {
822 	C10PLL_DP_PARAMS(162000, mtl_c10_dp_rbr),
823 	C10PLL_DP_PARAMS(216000, mtl_c10_edp_r216),
824 	C10PLL_DP_PARAMS(243000, mtl_c10_edp_r243),
825 	C10PLL_DP_PARAMS(270000, mtl_c10_dp_hbr1),
826 	C10PLL_DP_PARAMS(324000, mtl_c10_edp_r324),
827 	C10PLL_DP_PARAMS(432000, mtl_c10_edp_r432),
828 	C10PLL_DP_PARAMS(540000, mtl_c10_dp_hbr2),
829 	C10PLL_DP_PARAMS(675000, mtl_c10_edp_r675),
830 	C10PLL_DP_PARAMS(810000, mtl_c10_dp_hbr3),
831 	{}
832 };
833 
834 /* C20 basic DP 1.4 tables */
835 static const struct intel_c20pll_state mtl_c20_dp_rbr = {
836 	.tx = {	0xbe88, /* tx cfg0 */
837 		0x5800, /* tx cfg1 */
838 		0x0000, /* tx cfg2 */
839 		},
840 	.cmn = {0x0500, /* cmn cfg0*/
841 		0x0005, /* cmn cfg1 */
842 		0x0000, /* cmn cfg2 */
843 		0x0000, /* cmn cfg3 */
844 		},
845 	.mpllb = { 0x50a8,	/* mpllb cfg0 */
846 		0x2120,		/* mpllb cfg1 */
847 		0xcd9a,		/* mpllb cfg2 */
848 		0xbfc1,		/* mpllb cfg3 */
849 		0x5ab8,         /* mpllb cfg4 */
850 		0x4c34,         /* mpllb cfg5 */
851 		0x2000,		/* mpllb cfg6 */
852 		0x0001,		/* mpllb cfg7 */
853 		0x6000,		/* mpllb cfg8 */
854 		0x0000,		/* mpllb cfg9 */
855 		0x0000,		/* mpllb cfg10 */
856 		},
857 };
858 
859 static const struct intel_c20pll_state mtl_c20_dp_hbr1 = {
860 	.tx = {	0xbe88, /* tx cfg0 */
861 		0x4800, /* tx cfg1 */
862 		0x0000, /* tx cfg2 */
863 		},
864 	.cmn = {0x0500, /* cmn cfg0*/
865 		0x0005, /* cmn cfg1 */
866 		0x0000, /* cmn cfg2 */
867 		0x0000, /* cmn cfg3 */
868 		},
869 	.mpllb = { 0x308c,	/* mpllb cfg0 */
870 		0x2110,		/* mpllb cfg1 */
871 		0xcc9c,		/* mpllb cfg2 */
872 		0xbfc1,		/* mpllb cfg3 */
873 		0x4b9a,         /* mpllb cfg4 */
874 		0x3f81,         /* mpllb cfg5 */
875 		0x2000,		/* mpllb cfg6 */
876 		0x0001,		/* mpllb cfg7 */
877 		0x5000,		/* mpllb cfg8 */
878 		0x0000,		/* mpllb cfg9 */
879 		0x0000,		/* mpllb cfg10 */
880 		},
881 };
882 
883 static const struct intel_c20pll_state mtl_c20_dp_hbr2 = {
884 	.tx = {	0xbe88, /* tx cfg0 */
885 		0x4800, /* tx cfg1 */
886 		0x0000, /* tx cfg2 */
887 		},
888 	.cmn = {0x0500, /* cmn cfg0*/
889 		0x0005, /* cmn cfg1 */
890 		0x0000, /* cmn cfg2 */
891 		0x0000, /* cmn cfg3 */
892 		},
893 	.mpllb = { 0x108c,	/* mpllb cfg0 */
894 		0x2108,		/* mpllb cfg1 */
895 		0xcc9c,		/* mpllb cfg2 */
896 		0xbfc1,		/* mpllb cfg3 */
897 		0x4b9a,         /* mpllb cfg4 */
898 		0x3f81,         /* mpllb cfg5 */
899 		0x2000,		/* mpllb cfg6 */
900 		0x0001,		/* mpllb cfg7 */
901 		0x5000,		/* mpllb cfg8 */
902 		0x0000,		/* mpllb cfg9 */
903 		0x0000,		/* mpllb cfg10 */
904 		},
905 };
906 
907 static const struct intel_c20pll_state mtl_c20_dp_hbr3 = {
908 	.tx = {	0xbe88, /* tx cfg0 */
909 		0x4800, /* tx cfg1 */
910 		0x0000, /* tx cfg2 */
911 		},
912 	.cmn = {0x0500, /* cmn cfg0*/
913 		0x0005, /* cmn cfg1 */
914 		0x0000, /* cmn cfg2 */
915 		0x0000, /* cmn cfg3 */
916 		},
917 	.mpllb = { 0x10d2,	/* mpllb cfg0 */
918 		0x2108,		/* mpllb cfg1 */
919 		0x8d98,		/* mpllb cfg2 */
920 		0xbfc1,		/* mpllb cfg3 */
921 		0x7166,         /* mpllb cfg4 */
922 		0x5f42,         /* mpllb cfg5 */
923 		0x2000,		/* mpllb cfg6 */
924 		0x0001,		/* mpllb cfg7 */
925 		0x7800,		/* mpllb cfg8 */
926 		0x0000,		/* mpllb cfg9 */
927 		0x0000,		/* mpllb cfg10 */
928 		},
929 };
930 
931 /* C20 basic DP 2.0 tables */
932 static const struct intel_c20pll_state mtl_c20_dp_uhbr10 = {
933 	.tx = {	0xbe21, /* tx cfg0 */
934 		0xe800, /* tx cfg1 */
935 		0x0000, /* tx cfg2 */
936 		},
937 	.cmn = {0x0700, /* cmn cfg0*/
938 		0x0005, /* cmn cfg1 */
939 		0x0000, /* cmn cfg2 */
940 		0x0000, /* cmn cfg3 */
941 		},
942 	.mplla = { 0x3104,	/* mplla cfg0 */
943 		0xd105,		/* mplla cfg1 */
944 		0xc025,		/* mplla cfg2 */
945 		0xc025,		/* mplla cfg3 */
946 		0x8c00,		/* mplla cfg4 */
947 		0x759a,		/* mplla cfg5 */
948 		0x4000,		/* mplla cfg6 */
949 		0x0003,		/* mplla cfg7 */
950 		0x3555,		/* mplla cfg8 */
951 		0x0001,		/* mplla cfg9 */
952 		},
953 };
954 
955 static const struct intel_c20pll_state mtl_c20_dp_uhbr13_5 = {
956 	.tx = {	0xbea0, /* tx cfg0 */
957 		0x4800, /* tx cfg1 */
958 		0x0000, /* tx cfg2 */
959 		},
960 	.cmn = {0x0500, /* cmn cfg0*/
961 		0x0005, /* cmn cfg1 */
962 		0x0000, /* cmn cfg2 */
963 		0x0000, /* cmn cfg3 */
964 		},
965 	.mpllb = { 0x015f,	/* mpllb cfg0 */
966 		0x2205,		/* mpllb cfg1 */
967 		0x1b17,		/* mpllb cfg2 */
968 		0xffc1,		/* mpllb cfg3 */
969 		0xe100,		/* mpllb cfg4 */
970 		0xbd00,		/* mpllb cfg5 */
971 		0x2000,		/* mpllb cfg6 */
972 		0x0001,		/* mpllb cfg7 */
973 		0x4800,		/* mpllb cfg8 */
974 		0x0000,		/* mpllb cfg9 */
975 		0x0000,		/* mpllb cfg10 */
976 		},
977 };
978 
979 static const struct intel_c20pll_state mtl_c20_dp_uhbr20 = {
980 	.tx = {	0xbe20, /* tx cfg0 */
981 		0x4800, /* tx cfg1 */
982 		0x0000, /* tx cfg2 */
983 		},
984 	.cmn = {0x0500, /* cmn cfg0*/
985 		0x0005, /* cmn cfg1 */
986 		0x0000, /* cmn cfg2 */
987 		0x0000, /* cmn cfg3 */
988 		},
989 	.mplla = { 0x3104,	/* mplla cfg0 */
990 		0xd105,		/* mplla cfg1 */
991 		0x9217,		/* mplla cfg2 */
992 		0x9217,		/* mplla cfg3 */
993 		0x8c00,		/* mplla cfg4 */
994 		0x759a,		/* mplla cfg5 */
995 		0x4000,		/* mplla cfg6 */
996 		0x0003,		/* mplla cfg7 */
997 		0x3555,		/* mplla cfg8 */
998 		0x0001,		/* mplla cfg9 */
999 		},
1000 };
1001 
1002 static const struct intel_cx0pll_params mtl_c20_dp_tables[] = {
1003 	C20PLL_DP_PARAMS(162000, mtl_c20_dp_rbr),
1004 	C20PLL_DP_PARAMS(270000, mtl_c20_dp_hbr1),
1005 	C20PLL_DP_PARAMS(540000, mtl_c20_dp_hbr2),
1006 	C20PLL_DP_PARAMS(810000, mtl_c20_dp_hbr3),
1007 	C20PLL_DP_PARAMS(1000000, mtl_c20_dp_uhbr10),
1008 	C20PLL_DP_PARAMS(1350000, mtl_c20_dp_uhbr13_5),
1009 	C20PLL_DP_PARAMS(2000000, mtl_c20_dp_uhbr20),
1010 	{}
1011 };
1012 
1013 /*
1014  * eDP link rates with 38.4 MHz reference clock.
1015  */
1016 
1017 static const struct intel_c20pll_state xe2hpd_c20_edp_r216 = {
1018 	.tx = { 0xbe88,
1019 		0x4800,
1020 		0x0000,
1021 		},
1022 	.cmn = { 0x0500,
1023 		 0x0005,
1024 		 0x0000,
1025 		 0x0000,
1026 		},
1027 	.mpllb = { 0x50e1,
1028 		   0x2120,
1029 		   0x8e18,
1030 		   0xbfc1,
1031 		   0x9000,
1032 		   0x78f6,
1033 		   0x0000,
1034 		   0x0000,
1035 		   0x0000,
1036 		   0x0000,
1037 		   0x0000,
1038 		  },
1039 };
1040 
1041 static const struct intel_c20pll_state xe2hpd_c20_edp_r243 = {
1042 	.tx = { 0xbe88,
1043 		0x4800,
1044 		0x0000,
1045 		},
1046 	.cmn = { 0x0500,
1047 		 0x0005,
1048 		 0x0000,
1049 		 0x0000,
1050 		},
1051 	.mpllb = { 0x50fd,
1052 		   0x2120,
1053 		   0x8f18,
1054 		   0xbfc1,
1055 		   0xa200,
1056 		   0x8814,
1057 		   0x2000,
1058 		   0x0001,
1059 		   0x1000,
1060 		   0x0000,
1061 		   0x0000,
1062 		  },
1063 };
1064 
1065 static const struct intel_c20pll_state xe2hpd_c20_edp_r324 = {
1066 	.tx = { 0xbe88,
1067 		0x4800,
1068 		0x0000,
1069 		},
1070 	.cmn = { 0x0500,
1071 		 0x0005,
1072 		 0x0000,
1073 		 0x0000,
1074 		},
1075 	.mpllb = { 0x30a8,
1076 		   0x2110,
1077 		   0xcd9a,
1078 		   0xbfc1,
1079 		   0x6c00,
1080 		   0x5ab8,
1081 		   0x2000,
1082 		   0x0001,
1083 		   0x6000,
1084 		   0x0000,
1085 		   0x0000,
1086 		  },
1087 };
1088 
1089 static const struct intel_c20pll_state xe2hpd_c20_edp_r432 = {
1090 	.tx = { 0xbe88,
1091 		0x4800,
1092 		0x0000,
1093 		},
1094 	.cmn = { 0x0500,
1095 		 0x0005,
1096 		 0x0000,
1097 		 0x0000,
1098 		},
1099 	.mpllb = { 0x30e1,
1100 		   0x2110,
1101 		   0x8e18,
1102 		   0xbfc1,
1103 		   0x9000,
1104 		   0x78f6,
1105 		   0x0000,
1106 		   0x0000,
1107 		   0x0000,
1108 		   0x0000,
1109 		   0x0000,
1110 		  },
1111 };
1112 
1113 static const struct intel_c20pll_state xe2hpd_c20_edp_r675 = {
1114 	.tx = { 0xbe88,
1115 		0x4800,
1116 		0x0000,
1117 		},
1118 	.cmn = { 0x0500,
1119 		 0x0005,
1120 		 0x0000,
1121 		 0x0000,
1122 		},
1123 	.mpllb = { 0x10af,
1124 		   0x2108,
1125 		   0xce1a,
1126 		   0xbfc1,
1127 		   0x7080,
1128 		   0x5e80,
1129 		   0x2000,
1130 		   0x0001,
1131 		   0x6400,
1132 		   0x0000,
1133 		   0x0000,
1134 		  },
1135 };
1136 
1137 static const struct intel_cx0pll_params xe2hpd_c20_edp_tables[] = {
1138 	C20PLL_DP_PARAMS(162000, mtl_c20_dp_rbr),
1139 	C20PLL_DP_PARAMS(216000, xe2hpd_c20_edp_r216),
1140 	C20PLL_DP_PARAMS(243000, xe2hpd_c20_edp_r243),
1141 	C20PLL_DP_PARAMS(270000, mtl_c20_dp_hbr1),
1142 	C20PLL_DP_PARAMS(324000, xe2hpd_c20_edp_r324),
1143 	C20PLL_DP_PARAMS(432000, xe2hpd_c20_edp_r432),
1144 	C20PLL_DP_PARAMS(540000, mtl_c20_dp_hbr2),
1145 	C20PLL_DP_PARAMS(675000, xe2hpd_c20_edp_r675),
1146 	C20PLL_DP_PARAMS(810000, mtl_c20_dp_hbr3),
1147 	{}
1148 };
1149 
1150 static const struct intel_c20pll_state xe2hpd_c20_dp_uhbr13_5 = {
1151 	.tx = {	0xbea0, /* tx cfg0 */
1152 		0x4800, /* tx cfg1 */
1153 		0x0000, /* tx cfg2 */
1154 		},
1155 	.cmn = {0x0500, /* cmn cfg0*/
1156 		0x0005, /* cmn cfg1 */
1157 		0x0000, /* cmn cfg2 */
1158 		0x0000, /* cmn cfg3 */
1159 		},
1160 	.mpllb = { 0x015f,	/* mpllb cfg0 */
1161 		0x2205,		/* mpllb cfg1 */
1162 		0x1b17,		/* mpllb cfg2 */
1163 		0xffc1,		/* mpllb cfg3 */
1164 		0xbd00,		/* mpllb cfg4 */
1165 		0x9ec3,		/* mpllb cfg5 */
1166 		0x2000,		/* mpllb cfg6 */
1167 		0x0001,		/* mpllb cfg7 */
1168 		0x4800,		/* mpllb cfg8 */
1169 		0x0000,		/* mpllb cfg9 */
1170 		0x0000,		/* mpllb cfg10 */
1171 		},
1172 };
1173 
1174 static const struct intel_cx0pll_params xe2hpd_c20_dp_tables[] = {
1175 	C20PLL_DP_PARAMS(162000, mtl_c20_dp_rbr),
1176 	C20PLL_DP_PARAMS(270000, mtl_c20_dp_hbr1),
1177 	C20PLL_DP_PARAMS(540000, mtl_c20_dp_hbr2),
1178 	C20PLL_DP_PARAMS(810000, mtl_c20_dp_hbr3),
1179 	C20PLL_DP_PARAMS(1000000, mtl_c20_dp_uhbr10),
1180 	C20PLL_DP_PARAMS(1350000, xe2hpd_c20_dp_uhbr13_5),
1181 	{}
1182 };
1183 
1184 static const struct intel_cx0pll_params xe3lpd_c20_dp_edp_tables[] = {
1185 	C20PLL_DP_PARAMS(162000, mtl_c20_dp_rbr),
1186 	C20PLL_DP_PARAMS(216000, xe2hpd_c20_edp_r216),
1187 	C20PLL_DP_PARAMS(243000, xe2hpd_c20_edp_r243),
1188 	C20PLL_DP_PARAMS(270000, mtl_c20_dp_hbr1),
1189 	C20PLL_DP_PARAMS(324000, xe2hpd_c20_edp_r324),
1190 	C20PLL_DP_PARAMS(432000, xe2hpd_c20_edp_r432),
1191 	C20PLL_DP_PARAMS(540000, mtl_c20_dp_hbr2),
1192 	C20PLL_DP_PARAMS(675000, xe2hpd_c20_edp_r675),
1193 	C20PLL_DP_PARAMS(810000, mtl_c20_dp_hbr3),
1194 	C20PLL_DP_PARAMS(1000000, mtl_c20_dp_uhbr10),
1195 	C20PLL_DP_PARAMS(1350000, xe2hpd_c20_dp_uhbr13_5),
1196 	C20PLL_DP_PARAMS(2000000, mtl_c20_dp_uhbr20),
1197 	{}
1198 };
1199 
1200 /*
1201  * HDMI link rates with 38.4 MHz reference clock.
1202  */
1203 
1204 static const struct intel_c10pll_state mtl_c10_hdmi_25_2 = {
1205 	.tx = 0x10,
1206 	.cmn = 0x1,
1207 	.pll[0] = 0x4,
1208 	.pll[1] = 0,
1209 	.pll[2] = 0xB2,
1210 	.pll[3] = 0,
1211 	.pll[4] = 0,
1212 	.pll[5] = 0,
1213 	.pll[6] = 0,
1214 	.pll[7] = 0,
1215 	.pll[8] = 0x20,
1216 	.pll[9] = 0x1,
1217 	.pll[10] = 0,
1218 	.pll[11] = 0,
1219 	.pll[12] = 0,
1220 	.pll[13] = 0,
1221 	.pll[14] = 0,
1222 	.pll[15] = 0xD,
1223 	.pll[16] = 0x6,
1224 	.pll[17] = 0x8F,
1225 	.pll[18] = 0x84,
1226 	.pll[19] = 0x23,
1227 };
1228 
1229 static const struct intel_c10pll_state mtl_c10_hdmi_27_0 = {
1230 	.tx = 0x10,
1231 	.cmn = 0x1,
1232 	.pll[0] = 0x34,
1233 	.pll[1] = 0,
1234 	.pll[2] = 0xC0,
1235 	.pll[3] = 0,
1236 	.pll[4] = 0,
1237 	.pll[5] = 0,
1238 	.pll[6] = 0,
1239 	.pll[7] = 0,
1240 	.pll[8] = 0x20,
1241 	.pll[9] = 0x1,
1242 	.pll[10] = 0,
1243 	.pll[11] = 0,
1244 	.pll[12] = 0x80,
1245 	.pll[13] = 0,
1246 	.pll[14] = 0,
1247 	.pll[15] = 0xD,
1248 	.pll[16] = 0x6,
1249 	.pll[17] = 0xCF,
1250 	.pll[18] = 0x84,
1251 	.pll[19] = 0x23,
1252 };
1253 
1254 static const struct intel_c10pll_state mtl_c10_hdmi_74_25 = {
1255 	.tx = 0x10,
1256 	.cmn = 0x1,
1257 	.pll[0] = 0xF4,
1258 	.pll[1] = 0,
1259 	.pll[2] = 0x7A,
1260 	.pll[3] = 0,
1261 	.pll[4] = 0,
1262 	.pll[5] = 0,
1263 	.pll[6] = 0,
1264 	.pll[7] = 0,
1265 	.pll[8] = 0x20,
1266 	.pll[9] = 0x1,
1267 	.pll[10] = 0,
1268 	.pll[11] = 0,
1269 	.pll[12] = 0x58,
1270 	.pll[13] = 0,
1271 	.pll[14] = 0,
1272 	.pll[15] = 0xB,
1273 	.pll[16] = 0x6,
1274 	.pll[17] = 0xF,
1275 	.pll[18] = 0x85,
1276 	.pll[19] = 0x23,
1277 };
1278 
1279 static const struct intel_c10pll_state mtl_c10_hdmi_148_5 = {
1280 	.tx = 0x10,
1281 	.cmn = 0x1,
1282 	.pll[0] = 0xF4,
1283 	.pll[1] = 0,
1284 	.pll[2] = 0x7A,
1285 	.pll[3] = 0,
1286 	.pll[4] = 0,
1287 	.pll[5] = 0,
1288 	.pll[6] = 0,
1289 	.pll[7] = 0,
1290 	.pll[8] = 0x20,
1291 	.pll[9] = 0x1,
1292 	.pll[10] = 0,
1293 	.pll[11] = 0,
1294 	.pll[12] = 0x58,
1295 	.pll[13] = 0,
1296 	.pll[14] = 0,
1297 	.pll[15] = 0xA,
1298 	.pll[16] = 0x6,
1299 	.pll[17] = 0xF,
1300 	.pll[18] = 0x85,
1301 	.pll[19] = 0x23,
1302 };
1303 
1304 static const struct intel_c10pll_state mtl_c10_hdmi_594 = {
1305 	.tx = 0x10,
1306 	.cmn = 0x1,
1307 	.pll[0] = 0xF4,
1308 	.pll[1] = 0,
1309 	.pll[2] = 0x7A,
1310 	.pll[3] = 0,
1311 	.pll[4] = 0,
1312 	.pll[5] = 0,
1313 	.pll[6] = 0,
1314 	.pll[7] = 0,
1315 	.pll[8] = 0x20,
1316 	.pll[9] = 0x1,
1317 	.pll[10] = 0,
1318 	.pll[11] = 0,
1319 	.pll[12] = 0x58,
1320 	.pll[13] = 0,
1321 	.pll[14] = 0,
1322 	.pll[15] = 0x8,
1323 	.pll[16] = 0x6,
1324 	.pll[17] = 0xF,
1325 	.pll[18] = 0x85,
1326 	.pll[19] = 0x23,
1327 };
1328 
1329 /* Precomputed C10 HDMI PLL tables */
1330 static const struct intel_c10pll_state mtl_c10_hdmi_27027 = {
1331 	.tx = 0x10,
1332 	.cmn = 0x1,
1333 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xC0, .pll[3] = 0x00, .pll[4] = 0x00,
1334 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1335 	.pll[10] = 0xFF, .pll[11] = 0xCC, .pll[12] = 0x9C, .pll[13] = 0xCB, .pll[14] = 0xCC,
1336 	.pll[15] = 0x0D, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1337 };
1338 
1339 static const struct intel_c10pll_state mtl_c10_hdmi_28320 = {
1340 	.tx = 0x10,
1341 	.cmn = 0x1,
1342 	.pll[0] = 0x04, .pll[1] = 0x00, .pll[2] = 0xCC, .pll[3] = 0x00, .pll[4] = 0x00,
1343 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1344 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x00, .pll[13] = 0x00, .pll[14] = 0x00,
1345 	.pll[15] = 0x0D, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1346 };
1347 
1348 static const struct intel_c10pll_state mtl_c10_hdmi_30240 = {
1349 	.tx = 0x10,
1350 	.cmn = 0x1,
1351 	.pll[0] = 0x04, .pll[1] = 0x00, .pll[2] = 0xDC, .pll[3] = 0x00, .pll[4] = 0x00,
1352 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1353 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x00, .pll[13] = 0x00, .pll[14] = 0x00,
1354 	.pll[15] = 0x0D, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1355 };
1356 
1357 static const struct intel_c10pll_state mtl_c10_hdmi_31500 = {
1358 	.tx = 0x10,
1359 	.cmn = 0x1,
1360 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x62, .pll[3] = 0x00, .pll[4] = 0x00,
1361 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1362 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0xA0, .pll[13] = 0x00, .pll[14] = 0x00,
1363 	.pll[15] = 0x0C, .pll[16] = 0x09, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1364 };
1365 
1366 static const struct intel_c10pll_state mtl_c10_hdmi_36000 = {
1367 	.tx = 0x10,
1368 	.cmn = 0x1,
1369 	.pll[0] = 0xC4, .pll[1] = 0x00, .pll[2] = 0x76, .pll[3] = 0x00, .pll[4] = 0x00,
1370 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1371 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x00, .pll[13] = 0x00, .pll[14] = 0x00,
1372 	.pll[15] = 0x0C, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1373 };
1374 
1375 static const struct intel_c10pll_state mtl_c10_hdmi_40000 = {
1376 	.tx = 0x10,
1377 	.cmn = 0x1,
1378 	.pll[0] = 0xB4, .pll[1] = 0x00, .pll[2] = 0x86, .pll[3] = 0x00, .pll[4] = 0x00,
1379 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1380 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0x55, .pll[13] = 0x55, .pll[14] = 0x55,
1381 	.pll[15] = 0x0C, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1382 };
1383 
1384 static const struct intel_c10pll_state mtl_c10_hdmi_49500 = {
1385 	.tx = 0x10,
1386 	.cmn = 0x1,
1387 	.pll[0] = 0x74, .pll[1] = 0x00, .pll[2] = 0xAE, .pll[3] = 0x00, .pll[4] = 0x00,
1388 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1389 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x20, .pll[13] = 0x00, .pll[14] = 0x00,
1390 	.pll[15] = 0x0C, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1391 };
1392 
1393 static const struct intel_c10pll_state mtl_c10_hdmi_50000 = {
1394 	.tx = 0x10,
1395 	.cmn = 0x1,
1396 	.pll[0] = 0x74, .pll[1] = 0x00, .pll[2] = 0xB0, .pll[3] = 0x00, .pll[4] = 0x00,
1397 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1398 	.pll[10] = 0xFF, .pll[11] = 0xAA, .pll[12] = 0x2A, .pll[13] = 0xA9, .pll[14] = 0xAA,
1399 	.pll[15] = 0x0C, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1400 };
1401 
1402 static const struct intel_c10pll_state mtl_c10_hdmi_57284 = {
1403 	.tx = 0x10,
1404 	.cmn = 0x1,
1405 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xCE, .pll[3] = 0x00, .pll[4] = 0x00,
1406 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1407 	.pll[10] = 0xFF, .pll[11] = 0x77, .pll[12] = 0x57, .pll[13] = 0x77, .pll[14] = 0x77,
1408 	.pll[15] = 0x0C, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1409 };
1410 
1411 static const struct intel_c10pll_state mtl_c10_hdmi_58000 = {
1412 	.tx = 0x10,
1413 	.cmn = 0x1,
1414 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xD0, .pll[3] = 0x00, .pll[4] = 0x00,
1415 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1416 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0xD5, .pll[13] = 0x55, .pll[14] = 0x55,
1417 	.pll[15] = 0x0C, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1418 };
1419 
1420 static const struct intel_c10pll_state mtl_c10_hdmi_65000 = {
1421 	.tx = 0x10,
1422 	.cmn = 0x1,
1423 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x66, .pll[3] = 0x00, .pll[4] = 0x00,
1424 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1425 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0xB5, .pll[13] = 0x55, .pll[14] = 0x55,
1426 	.pll[15] = 0x0B, .pll[16] = 0x09, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1427 };
1428 
1429 static const struct intel_c10pll_state mtl_c10_hdmi_71000 = {
1430 	.tx = 0x10,
1431 	.cmn = 0x1,
1432 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x72, .pll[3] = 0x00, .pll[4] = 0x00,
1433 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1434 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0xF5, .pll[13] = 0x55, .pll[14] = 0x55,
1435 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1436 };
1437 
1438 static const struct intel_c10pll_state mtl_c10_hdmi_74176 = {
1439 	.tx = 0x10,
1440 	.cmn = 0x1,
1441 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x7A, .pll[3] = 0x00, .pll[4] = 0x00,
1442 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1443 	.pll[10] = 0xFF, .pll[11] = 0x44, .pll[12] = 0x44, .pll[13] = 0x44, .pll[14] = 0x44,
1444 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1445 };
1446 
1447 static const struct intel_c10pll_state mtl_c10_hdmi_75000 = {
1448 	.tx = 0x10,
1449 	.cmn = 0x1,
1450 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x7C, .pll[3] = 0x00, .pll[4] = 0x00,
1451 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1452 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x20, .pll[13] = 0x00, .pll[14] = 0x00,
1453 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1454 };
1455 
1456 static const struct intel_c10pll_state mtl_c10_hdmi_78750 = {
1457 	.tx = 0x10,
1458 	.cmn = 0x1,
1459 	.pll[0] = 0xB4, .pll[1] = 0x00, .pll[2] = 0x84, .pll[3] = 0x00, .pll[4] = 0x00,
1460 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1461 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x08, .pll[13] = 0x00, .pll[14] = 0x00,
1462 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1463 };
1464 
1465 static const struct intel_c10pll_state mtl_c10_hdmi_85500 = {
1466 	.tx = 0x10,
1467 	.cmn = 0x1,
1468 	.pll[0] = 0xB4, .pll[1] = 0x00, .pll[2] = 0x92, .pll[3] = 0x00, .pll[4] = 0x00,
1469 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1470 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x10, .pll[13] = 0x00, .pll[14] = 0x00,
1471 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1472 };
1473 
1474 static const struct intel_c10pll_state mtl_c10_hdmi_88750 = {
1475 	.tx = 0x10,
1476 	.cmn = 0x1,
1477 	.pll[0] = 0x74, .pll[1] = 0x00, .pll[2] = 0x98, .pll[3] = 0x00, .pll[4] = 0x00,
1478 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1479 	.pll[10] = 0xFF, .pll[11] = 0xAA, .pll[12] = 0x72, .pll[13] = 0xA9, .pll[14] = 0xAA,
1480 	.pll[15] = 0x0B, .pll[16] = 0x09, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1481 };
1482 
1483 static const struct intel_c10pll_state mtl_c10_hdmi_106500 = {
1484 	.tx = 0x10,
1485 	.cmn = 0x1,
1486 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xBC, .pll[3] = 0x00, .pll[4] = 0x00,
1487 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1488 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0xF0, .pll[13] = 0x00, .pll[14] = 0x00,
1489 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1490 };
1491 
1492 static const struct intel_c10pll_state mtl_c10_hdmi_108000 = {
1493 	.tx = 0x10,
1494 	.cmn = 0x1,
1495 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xC0, .pll[3] = 0x00, .pll[4] = 0x00,
1496 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1497 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x80, .pll[13] = 0x00, .pll[14] = 0x00,
1498 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1499 };
1500 
1501 static const struct intel_c10pll_state mtl_c10_hdmi_115500 = {
1502 	.tx = 0x10,
1503 	.cmn = 0x1,
1504 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xD0, .pll[3] = 0x00, .pll[4] = 0x00,
1505 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1506 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x50, .pll[13] = 0x00, .pll[14] = 0x00,
1507 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1508 };
1509 
1510 static const struct intel_c10pll_state mtl_c10_hdmi_119000 = {
1511 	.tx = 0x10,
1512 	.cmn = 0x1,
1513 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xD6, .pll[3] = 0x00, .pll[4] = 0x00,
1514 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1515 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0xF5, .pll[13] = 0x55, .pll[14] = 0x55,
1516 	.pll[15] = 0x0B, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1517 };
1518 
1519 static const struct intel_c10pll_state mtl_c10_hdmi_135000 = {
1520 	.tx = 0x10,
1521 	.cmn = 0x1,
1522 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x6C, .pll[3] = 0x00, .pll[4] = 0x00,
1523 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1524 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x50, .pll[13] = 0x00, .pll[14] = 0x00,
1525 	.pll[15] = 0x0A, .pll[16] = 0x09, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1526 };
1527 
1528 static const struct intel_c10pll_state mtl_c10_hdmi_138500 = {
1529 	.tx = 0x10,
1530 	.cmn = 0x1,
1531 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x70, .pll[3] = 0x00, .pll[4] = 0x00,
1532 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1533 	.pll[10] = 0xFF, .pll[11] = 0xAA, .pll[12] = 0x22, .pll[13] = 0xA9, .pll[14] = 0xAA,
1534 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1535 };
1536 
1537 static const struct intel_c10pll_state mtl_c10_hdmi_147160 = {
1538 	.tx = 0x10,
1539 	.cmn = 0x1,
1540 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x78, .pll[3] = 0x00, .pll[4] = 0x00,
1541 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1542 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0xA5, .pll[13] = 0x55, .pll[14] = 0x55,
1543 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1544 };
1545 
1546 static const struct intel_c10pll_state mtl_c10_hdmi_148352 = {
1547 	.tx = 0x10,
1548 	.cmn = 0x1,
1549 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x7A, .pll[3] = 0x00, .pll[4] = 0x00,
1550 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1551 	.pll[10] = 0xFF, .pll[11] = 0x44, .pll[12] = 0x44, .pll[13] = 0x44, .pll[14] = 0x44,
1552 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1553 };
1554 
1555 static const struct intel_c10pll_state mtl_c10_hdmi_154000 = {
1556 	.tx = 0x10,
1557 	.cmn = 0x1,
1558 	.pll[0] = 0xB4, .pll[1] = 0x00, .pll[2] = 0x80, .pll[3] = 0x00, .pll[4] = 0x00,
1559 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1560 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0x35, .pll[13] = 0x55, .pll[14] = 0x55,
1561 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1562 };
1563 
1564 static const struct intel_c10pll_state mtl_c10_hdmi_162000 = {
1565 	.tx = 0x10,
1566 	.cmn = 0x1,
1567 	.pll[0] = 0xB4, .pll[1] = 0x00, .pll[2] = 0x88, .pll[3] = 0x00, .pll[4] = 0x00,
1568 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1569 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x60, .pll[13] = 0x00, .pll[14] = 0x00,
1570 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1571 };
1572 
1573 static const struct intel_c10pll_state mtl_c10_hdmi_167000 = {
1574 	.tx = 0x10,
1575 	.cmn = 0x1,
1576 	.pll[0] = 0xB4, .pll[1] = 0x00, .pll[2] = 0x8C, .pll[3] = 0x00, .pll[4] = 0x00,
1577 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1578 	.pll[10] = 0xFF, .pll[11] = 0xAA, .pll[12] = 0xFA, .pll[13] = 0xA9, .pll[14] = 0xAA,
1579 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1580 };
1581 
1582 static const struct intel_c10pll_state mtl_c10_hdmi_197802 = {
1583 	.tx = 0x10,
1584 	.cmn = 0x1,
1585 	.pll[0] = 0x74, .pll[1] = 0x00, .pll[2] = 0xAE, .pll[3] = 0x00, .pll[4] = 0x00,
1586 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1587 	.pll[10] = 0xFF, .pll[11] = 0x99, .pll[12] = 0x05, .pll[13] = 0x98, .pll[14] = 0x99,
1588 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1589 };
1590 
1591 static const struct intel_c10pll_state mtl_c10_hdmi_198000 = {
1592 	.tx = 0x10,
1593 	.cmn = 0x1,
1594 	.pll[0] = 0x74, .pll[1] = 0x00, .pll[2] = 0xAE, .pll[3] = 0x00, .pll[4] = 0x00,
1595 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1596 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x20, .pll[13] = 0x00, .pll[14] = 0x00,
1597 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1598 };
1599 
1600 static const struct intel_c10pll_state mtl_c10_hdmi_209800 = {
1601 	.tx = 0x10,
1602 	.cmn = 0x1,
1603 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xBA, .pll[3] = 0x00, .pll[4] = 0x00,
1604 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1605 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0x45, .pll[13] = 0x55, .pll[14] = 0x55,
1606 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1607 };
1608 
1609 static const struct intel_c10pll_state mtl_c10_hdmi_241500 = {
1610 	.tx = 0x10,
1611 	.cmn = 0x1,
1612 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xDA, .pll[3] = 0x00, .pll[4] = 0x00,
1613 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1614 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0xC8, .pll[13] = 0x00, .pll[14] = 0x00,
1615 	.pll[15] = 0x0A, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1616 };
1617 
1618 static const struct intel_c10pll_state mtl_c10_hdmi_262750 = {
1619 	.tx = 0x10,
1620 	.cmn = 0x1,
1621 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x68, .pll[3] = 0x00, .pll[4] = 0x00,
1622 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1623 	.pll[10] = 0xFF, .pll[11] = 0xAA, .pll[12] = 0x6C, .pll[13] = 0xA9, .pll[14] = 0xAA,
1624 	.pll[15] = 0x09, .pll[16] = 0x09, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1625 };
1626 
1627 static const struct intel_c10pll_state mtl_c10_hdmi_268500 = {
1628 	.tx = 0x10,
1629 	.cmn = 0x1,
1630 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x6A, .pll[3] = 0x00, .pll[4] = 0x00,
1631 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1632 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0xEC, .pll[13] = 0x00, .pll[14] = 0x00,
1633 	.pll[15] = 0x09, .pll[16] = 0x09, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1634 };
1635 
1636 static const struct intel_c10pll_state mtl_c10_hdmi_296703 = {
1637 	.tx = 0x10,
1638 	.cmn = 0x1,
1639 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x7A, .pll[3] = 0x00, .pll[4] = 0x00,
1640 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1641 	.pll[10] = 0xFF, .pll[11] = 0x33, .pll[12] = 0x44, .pll[13] = 0x33, .pll[14] = 0x33,
1642 	.pll[15] = 0x09, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1643 };
1644 
1645 static const struct intel_c10pll_state mtl_c10_hdmi_297000 = {
1646 	.tx = 0x10,
1647 	.cmn = 0x1,
1648 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x7A, .pll[3] = 0x00, .pll[4] = 0x00,
1649 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1650 	.pll[10] = 0xFF, .pll[11] = 0x00, .pll[12] = 0x58, .pll[13] = 0x00, .pll[14] = 0x00,
1651 	.pll[15] = 0x09, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1652 };
1653 
1654 static const struct intel_c10pll_state mtl_c10_hdmi_319750 = {
1655 	.tx = 0x10,
1656 	.cmn = 0x1,
1657 	.pll[0] = 0xB4, .pll[1] = 0x00, .pll[2] = 0x86, .pll[3] = 0x00, .pll[4] = 0x00,
1658 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1659 	.pll[10] = 0xFF, .pll[11] = 0xAA, .pll[12] = 0x44, .pll[13] = 0xA9, .pll[14] = 0xAA,
1660 	.pll[15] = 0x09, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1661 };
1662 
1663 static const struct intel_c10pll_state mtl_c10_hdmi_497750 = {
1664 	.tx = 0x10,
1665 	.cmn = 0x1,
1666 	.pll[0] = 0x34, .pll[1] = 0x00, .pll[2] = 0xE2, .pll[3] = 0x00, .pll[4] = 0x00,
1667 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1668 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0x9F, .pll[13] = 0x55, .pll[14] = 0x55,
1669 	.pll[15] = 0x09, .pll[16] = 0x08, .pll[17] = 0xCF, .pll[18] = 0x84, .pll[19] = 0x23,
1670 };
1671 
1672 static const struct intel_c10pll_state mtl_c10_hdmi_592000 = {
1673 	.tx = 0x10,
1674 	.cmn = 0x1,
1675 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x7A, .pll[3] = 0x00, .pll[4] = 0x00,
1676 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1677 	.pll[10] = 0xFF, .pll[11] = 0x55, .pll[12] = 0x15, .pll[13] = 0x55, .pll[14] = 0x55,
1678 	.pll[15] = 0x08, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1679 };
1680 
1681 static const struct intel_c10pll_state mtl_c10_hdmi_593407 = {
1682 	.tx = 0x10,
1683 	.cmn = 0x1,
1684 	.pll[0] = 0xF4, .pll[1] = 0x00, .pll[2] = 0x7A, .pll[3] = 0x00, .pll[4] = 0x00,
1685 	.pll[5] = 0x00, .pll[6] = 0x00, .pll[7] = 0x00, .pll[8] = 0x20, .pll[9] = 0xFF,
1686 	.pll[10] = 0xFF, .pll[11] = 0x3B, .pll[12] = 0x44, .pll[13] = 0xBA, .pll[14] = 0xBB,
1687 	.pll[15] = 0x08, .pll[16] = 0x08, .pll[17] = 0x8F, .pll[18] = 0x84, .pll[19] = 0x23,
1688 };
1689 
1690 static const struct intel_cx0pll_params mtl_c10_hdmi_tables[] = {
1691 	C10PLL_HDMI_PARAMS(25200, mtl_c10_hdmi_25_2), /* Consolidated Table */
1692 	C10PLL_HDMI_PARAMS(27000, mtl_c10_hdmi_27_0), /* Consolidated Table */
1693 	C10PLL_HDMI_PARAMS(27027, mtl_c10_hdmi_27027),
1694 	C10PLL_HDMI_PARAMS(28320, mtl_c10_hdmi_28320),
1695 	C10PLL_HDMI_PARAMS(30240, mtl_c10_hdmi_30240),
1696 	C10PLL_HDMI_PARAMS(31500, mtl_c10_hdmi_31500),
1697 	C10PLL_HDMI_PARAMS(36000, mtl_c10_hdmi_36000),
1698 	C10PLL_HDMI_PARAMS(40000, mtl_c10_hdmi_40000),
1699 	C10PLL_HDMI_PARAMS(49500, mtl_c10_hdmi_49500),
1700 	C10PLL_HDMI_PARAMS(50000, mtl_c10_hdmi_50000),
1701 	C10PLL_HDMI_PARAMS(57284, mtl_c10_hdmi_57284),
1702 	C10PLL_HDMI_PARAMS(58000, mtl_c10_hdmi_58000),
1703 	C10PLL_HDMI_PARAMS(65000, mtl_c10_hdmi_65000),
1704 	C10PLL_HDMI_PARAMS(71000, mtl_c10_hdmi_71000),
1705 	C10PLL_HDMI_PARAMS(74176, mtl_c10_hdmi_74176),
1706 	C10PLL_HDMI_PARAMS(74250, mtl_c10_hdmi_74_25), /* Consolidated Table */
1707 	C10PLL_HDMI_PARAMS(75000, mtl_c10_hdmi_75000),
1708 	C10PLL_HDMI_PARAMS(78750, mtl_c10_hdmi_78750),
1709 	C10PLL_HDMI_PARAMS(85500, mtl_c10_hdmi_85500),
1710 	C10PLL_HDMI_PARAMS(88750, mtl_c10_hdmi_88750),
1711 	C10PLL_HDMI_PARAMS(106500, mtl_c10_hdmi_106500),
1712 	C10PLL_HDMI_PARAMS(108000, mtl_c10_hdmi_108000),
1713 	C10PLL_HDMI_PARAMS(115500, mtl_c10_hdmi_115500),
1714 	C10PLL_HDMI_PARAMS(119000, mtl_c10_hdmi_119000),
1715 	C10PLL_HDMI_PARAMS(135000, mtl_c10_hdmi_135000),
1716 	C10PLL_HDMI_PARAMS(138500, mtl_c10_hdmi_138500),
1717 	C10PLL_HDMI_PARAMS(147160, mtl_c10_hdmi_147160),
1718 	C10PLL_HDMI_PARAMS(148352, mtl_c10_hdmi_148352),
1719 	C10PLL_HDMI_PARAMS(148500, mtl_c10_hdmi_148_5), /* Consolidated Table */
1720 	C10PLL_HDMI_PARAMS(154000, mtl_c10_hdmi_154000),
1721 	C10PLL_HDMI_PARAMS(162000, mtl_c10_hdmi_162000),
1722 	C10PLL_HDMI_PARAMS(167000, mtl_c10_hdmi_167000),
1723 	C10PLL_HDMI_PARAMS(197802, mtl_c10_hdmi_197802),
1724 	C10PLL_HDMI_PARAMS(198000, mtl_c10_hdmi_198000),
1725 	C10PLL_HDMI_PARAMS(209800, mtl_c10_hdmi_209800),
1726 	C10PLL_HDMI_PARAMS(241500, mtl_c10_hdmi_241500),
1727 	C10PLL_HDMI_PARAMS(262750, mtl_c10_hdmi_262750),
1728 	C10PLL_HDMI_PARAMS(268500, mtl_c10_hdmi_268500),
1729 	C10PLL_HDMI_PARAMS(296703, mtl_c10_hdmi_296703),
1730 	C10PLL_HDMI_PARAMS(297000, mtl_c10_hdmi_297000),
1731 	C10PLL_HDMI_PARAMS(319750, mtl_c10_hdmi_319750),
1732 	C10PLL_HDMI_PARAMS(497750, mtl_c10_hdmi_497750),
1733 	C10PLL_HDMI_PARAMS(592000, mtl_c10_hdmi_592000),
1734 	C10PLL_HDMI_PARAMS(593407, mtl_c10_hdmi_593407),
1735 	C10PLL_HDMI_PARAMS(594000, mtl_c10_hdmi_594), /* Consolidated Table */
1736 	{}
1737 };
1738 
1739 static const struct intel_c20pll_state mtl_c20_hdmi_27_0 = {
1740 	.tx = {  0xbe88, /* tx cfg0 */
1741 		  0x9800, /* tx cfg1 */
1742 		  0x0000, /* tx cfg2 */
1743 		},
1744 	.cmn = { 0x0500, /* cmn cfg0*/
1745 		  0x0005, /* cmn cfg1 */
1746 		  0x0000, /* cmn cfg2 */
1747 		  0x0000, /* cmn cfg3 */
1748 		},
1749 	.mpllb = { 0xa0e0,	/* mpllb cfg0 */
1750 		   0x7d80,	/* mpllb cfg1 */
1751 		   0x0906,	/* mpllb cfg2 */
1752 		   0xbe40,	/* mpllb cfg3 */
1753 		   0x0000,	/* mpllb cfg4 */
1754 		   0x0000,	/* mpllb cfg5 */
1755 		   0x2200,	/* mpllb cfg6 */
1756 		   0x0001,	/* mpllb cfg7 */
1757 		   0x8000,	/* mpllb cfg8 */
1758 		   0x0000,	/* mpllb cfg9 */
1759 		   0x0001,	/* mpllb cfg10 */
1760 		},
1761 };
1762 
1763 static const struct intel_c20pll_state mtl_c20_hdmi_74_25 = {
1764 	.tx = {  0xbe88, /* tx cfg0 */
1765 		  0x9800, /* tx cfg1 */
1766 		  0x0000, /* tx cfg2 */
1767 		},
1768 	.cmn = { 0x0500, /* cmn cfg0*/
1769 		  0x0005, /* cmn cfg1 */
1770 		  0x0000, /* cmn cfg2 */
1771 		  0x0000, /* cmn cfg3 */
1772 		},
1773 	.mpllb = { 0x609a,	/* mpllb cfg0 */
1774 		   0x7d40,	/* mpllb cfg1 */
1775 		   0xca06,	/* mpllb cfg2 */
1776 		   0xbe40,	/* mpllb cfg3 */
1777 		   0x0000,	/* mpllb cfg4 */
1778 		   0x0000,	/* mpllb cfg5 */
1779 		   0x2200,	/* mpllb cfg6 */
1780 		   0x0001,	/* mpllb cfg7 */
1781 		   0x5800,	/* mpllb cfg8 */
1782 		   0x0000,	/* mpllb cfg9 */
1783 		   0x0001,	/* mpllb cfg10 */
1784 		},
1785 };
1786 
1787 static const struct intel_c20pll_state mtl_c20_hdmi_148_5 = {
1788 	.tx = {  0xbe88, /* tx cfg0 */
1789 		  0x9800, /* tx cfg1 */
1790 		  0x0000, /* tx cfg2 */
1791 		},
1792 	.cmn = { 0x0500, /* cmn cfg0*/
1793 		  0x0005, /* cmn cfg1 */
1794 		  0x0000, /* cmn cfg2 */
1795 		  0x0000, /* cmn cfg3 */
1796 		},
1797 	.mpllb = { 0x409a,	/* mpllb cfg0 */
1798 		   0x7d20,	/* mpllb cfg1 */
1799 		   0xca06,	/* mpllb cfg2 */
1800 		   0xbe40,	/* mpllb cfg3 */
1801 		   0x0000,	/* mpllb cfg4 */
1802 		   0x0000,	/* mpllb cfg5 */
1803 		   0x2200,	/* mpllb cfg6 */
1804 		   0x0001,	/* mpllb cfg7 */
1805 		   0x5800,	/* mpllb cfg8 */
1806 		   0x0000,	/* mpllb cfg9 */
1807 		   0x0001,	/* mpllb cfg10 */
1808 		},
1809 };
1810 
1811 static const struct intel_c20pll_state mtl_c20_hdmi_594 = {
1812 	.tx = {  0xbe88, /* tx cfg0 */
1813 		  0x9800, /* tx cfg1 */
1814 		  0x0000, /* tx cfg2 */
1815 		},
1816 	.cmn = { 0x0500, /* cmn cfg0*/
1817 		  0x0005, /* cmn cfg1 */
1818 		  0x0000, /* cmn cfg2 */
1819 		  0x0000, /* cmn cfg3 */
1820 		},
1821 	.mpllb = { 0x009a,	/* mpllb cfg0 */
1822 		   0x7d08,	/* mpllb cfg1 */
1823 		   0xca06,	/* mpllb cfg2 */
1824 		   0xbe40,	/* mpllb cfg3 */
1825 		   0x0000,	/* mpllb cfg4 */
1826 		   0x0000,	/* mpllb cfg5 */
1827 		   0x2200,	/* mpllb cfg6 */
1828 		   0x0001,	/* mpllb cfg7 */
1829 		   0x5800,	/* mpllb cfg8 */
1830 		   0x0000,	/* mpllb cfg9 */
1831 		   0x0001,	/* mpllb cfg10 */
1832 		},
1833 };
1834 
1835 static const struct intel_c20pll_state mtl_c20_hdmi_300 = {
1836 	.tx = {  0xbe98, /* tx cfg0 */
1837 		  0x8800, /* tx cfg1 */
1838 		  0x0000, /* tx cfg2 */
1839 		},
1840 	.cmn = { 0x0500, /* cmn cfg0*/
1841 		  0x0005, /* cmn cfg1 */
1842 		  0x0000, /* cmn cfg2 */
1843 		  0x0000, /* cmn cfg3 */
1844 		},
1845 	.mpllb = { 0x309c,	/* mpllb cfg0 */
1846 		   0x2110,	/* mpllb cfg1 */
1847 		   0xca06,	/* mpllb cfg2 */
1848 		   0xbe40,	/* mpllb cfg3 */
1849 		   0x0000,	/* mpllb cfg4 */
1850 		   0x0000,	/* mpllb cfg5 */
1851 		   0x2200,	/* mpllb cfg6 */
1852 		   0x0001,	/* mpllb cfg7 */
1853 		   0x2000,	/* mpllb cfg8 */
1854 		   0x0000,	/* mpllb cfg9 */
1855 		   0x0004,	/* mpllb cfg10 */
1856 		},
1857 };
1858 
1859 static const struct intel_c20pll_state mtl_c20_hdmi_600 = {
1860 	.tx = {  0xbe98, /* tx cfg0 */
1861 		  0x8800, /* tx cfg1 */
1862 		  0x0000, /* tx cfg2 */
1863 		},
1864 	.cmn = { 0x0500, /* cmn cfg0*/
1865 		  0x0005, /* cmn cfg1 */
1866 		  0x0000, /* cmn cfg2 */
1867 		  0x0000, /* cmn cfg3 */
1868 		},
1869 	.mpllb = { 0x109c,	/* mpllb cfg0 */
1870 		   0x2108,	/* mpllb cfg1 */
1871 		   0xca06,	/* mpllb cfg2 */
1872 		   0xbe40,	/* mpllb cfg3 */
1873 		   0x0000,	/* mpllb cfg4 */
1874 		   0x0000,	/* mpllb cfg5 */
1875 		   0x2200,	/* mpllb cfg6 */
1876 		   0x0001,	/* mpllb cfg7 */
1877 		   0x2000,	/* mpllb cfg8 */
1878 		   0x0000,	/* mpllb cfg9 */
1879 		   0x0004,	/* mpllb cfg10 */
1880 		},
1881 };
1882 
1883 static const struct intel_c20pll_state mtl_c20_hdmi_800 = {
1884 	.tx = {  0xbe98, /* tx cfg0 */
1885 		  0x8800, /* tx cfg1 */
1886 		  0x0000, /* tx cfg2 */
1887 		},
1888 	.cmn = { 0x0500, /* cmn cfg0*/
1889 		  0x0005, /* cmn cfg1 */
1890 		  0x0000, /* cmn cfg2 */
1891 		  0x0000, /* cmn cfg3 */
1892 		},
1893 	.mpllb = { 0x10d0,	/* mpllb cfg0 */
1894 		   0x2108,	/* mpllb cfg1 */
1895 		   0x4a06,	/* mpllb cfg2 */
1896 		   0xbe40,	/* mpllb cfg3 */
1897 		   0x0000,	/* mpllb cfg4 */
1898 		   0x0000,	/* mpllb cfg5 */
1899 		   0x2200,	/* mpllb cfg6 */
1900 		   0x0003,	/* mpllb cfg7 */
1901 		   0x2aaa,	/* mpllb cfg8 */
1902 		   0x0002,	/* mpllb cfg9 */
1903 		   0x0004,	/* mpllb cfg10 */
1904 		},
1905 };
1906 
1907 static const struct intel_c20pll_state mtl_c20_hdmi_1000 = {
1908 	.tx = {  0xbe98, /* tx cfg0 */
1909 		  0x8800, /* tx cfg1 */
1910 		  0x0000, /* tx cfg2 */
1911 		},
1912 	.cmn = { 0x0500, /* cmn cfg0*/
1913 		  0x0005, /* cmn cfg1 */
1914 		  0x0000, /* cmn cfg2 */
1915 		  0x0000, /* cmn cfg3 */
1916 		},
1917 	.mpllb = { 0x1104,	/* mpllb cfg0 */
1918 		   0x2108,	/* mpllb cfg1 */
1919 		   0x0a06,	/* mpllb cfg2 */
1920 		   0xbe40,	/* mpllb cfg3 */
1921 		   0x0000,	/* mpllb cfg4 */
1922 		   0x0000,	/* mpllb cfg5 */
1923 		   0x2200,	/* mpllb cfg6 */
1924 		   0x0003,	/* mpllb cfg7 */
1925 		   0x3555,	/* mpllb cfg8 */
1926 		   0x0001,	/* mpllb cfg9 */
1927 		   0x0004,	/* mpllb cfg10 */
1928 		},
1929 };
1930 
1931 static const struct intel_c20pll_state mtl_c20_hdmi_1200 = {
1932 	.tx = {  0xbe98, /* tx cfg0 */
1933 		  0x8800, /* tx cfg1 */
1934 		  0x0000, /* tx cfg2 */
1935 		},
1936 	.cmn = { 0x0500, /* cmn cfg0*/
1937 		  0x0005, /* cmn cfg1 */
1938 		  0x0000, /* cmn cfg2 */
1939 		  0x0000, /* cmn cfg3 */
1940 		},
1941 	.mpllb = { 0x1138,	/* mpllb cfg0 */
1942 		   0x2108,	/* mpllb cfg1 */
1943 		   0x5486,	/* mpllb cfg2 */
1944 		   0xfe40,	/* mpllb cfg3 */
1945 		   0x0000,	/* mpllb cfg4 */
1946 		   0x0000,	/* mpllb cfg5 */
1947 		   0x2200,	/* mpllb cfg6 */
1948 		   0x0001,	/* mpllb cfg7 */
1949 		   0x4000,	/* mpllb cfg8 */
1950 		   0x0000,	/* mpllb cfg9 */
1951 		   0x0004,	/* mpllb cfg10 */
1952 		},
1953 };
1954 
1955 static const struct intel_cx0pll_params mtl_c20_hdmi_tables[] = {
1956 	C20PLL_HDMI_PARAMS(27000, mtl_c20_hdmi_27_0),
1957 	C20PLL_HDMI_PARAMS(74250, mtl_c20_hdmi_74_25),
1958 	C20PLL_HDMI_PARAMS(148500, mtl_c20_hdmi_148_5),
1959 	C20PLL_HDMI_PARAMS(594000, mtl_c20_hdmi_594),
1960 	C20PLL_HDMI_PARAMS(300000, mtl_c20_hdmi_300),
1961 	C20PLL_HDMI_PARAMS(600000, mtl_c20_hdmi_600),
1962 	C20PLL_HDMI_PARAMS(800000, mtl_c20_hdmi_800),
1963 	C20PLL_HDMI_PARAMS(1000000, mtl_c20_hdmi_1000),
1964 	C20PLL_HDMI_PARAMS(1200000, mtl_c20_hdmi_1200),
1965 	{}
1966 };
1967 
1968 static const struct intel_cx0pll_params *
1969 intel_c10pll_tables_get(const struct intel_crtc_state *crtc_state,
1970 			struct intel_encoder *encoder)
1971 {
1972 	if (intel_crtc_has_dp_encoder(crtc_state)) {
1973 		if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
1974 			return mtl_c10_edp_tables;
1975 		else
1976 			return mtl_c10_dp_tables;
1977 	} else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
1978 		return mtl_c10_hdmi_tables;
1979 	}
1980 
1981 	MISSING_CASE(encoder->type);
1982 	return NULL;
1983 }
1984 
1985 static void intel_cx0pll_update_ssc(struct intel_encoder *encoder,
1986 				    struct intel_cx0pll_state *pll_state, bool is_dp)
1987 {
1988 	struct intel_display *display = to_intel_display(encoder);
1989 
1990 	if (is_dp) {
1991 		if (intel_panel_use_ssc(display)) {
1992 			struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1993 			pll_state->ssc_enabled =
1994 				(intel_dp->dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5);
1995 		}
1996 	}
1997 }
1998 
1999 #define C10_PLL_SSC_REG_START_IDX	4
2000 #define C10_PLL_SSC_REG_COUNT		5
2001 
2002 static bool intel_c10pll_ssc_enabled(const struct intel_c10pll_state *pll_state)
2003 {
2004 	return memchr_inv(&pll_state->pll[C10_PLL_SSC_REG_START_IDX],
2005 			  0, sizeof(pll_state->pll[0]) * C10_PLL_SSC_REG_COUNT);
2006 }
2007 
2008 static void intel_c10pll_update_pll(struct intel_encoder *encoder,
2009 				    struct intel_cx0pll_state *pll_state)
2010 {
2011 	struct intel_display *display = to_intel_display(encoder);
2012 	int i;
2013 
2014 	if (pll_state->ssc_enabled)
2015 		return;
2016 
2017 	drm_WARN_ON(display->drm, ARRAY_SIZE(pll_state->c10.pll) <
2018 				  C10_PLL_SSC_REG_START_IDX + C10_PLL_SSC_REG_COUNT);
2019 	for (i = C10_PLL_SSC_REG_START_IDX;
2020 	     i < C10_PLL_SSC_REG_START_IDX + C10_PLL_SSC_REG_COUNT;
2021 	     i++)
2022 		pll_state->c10.pll[i] = 0;
2023 }
2024 
2025 static bool c10pll_state_is_dp(const struct intel_c10pll_state *pll_state)
2026 {
2027 	return !REG_FIELD_GET8(C10_PLL15_HDMIDIV_MASK, pll_state->pll[15]);
2028 }
2029 
2030 static bool c20pll_state_is_dp(const struct intel_c20pll_state *pll_state)
2031 {
2032 	return pll_state->vdr.serdes_rate & PHY_C20_IS_DP;
2033 }
2034 
2035 static bool cx0pll_state_is_dp(const struct intel_cx0pll_state *pll_state)
2036 {
2037 	if (pll_state->use_c10)
2038 		return c10pll_state_is_dp(&pll_state->c10);
2039 
2040 	return c20pll_state_is_dp(&pll_state->c20);
2041 }
2042 
2043 static int intel_c10pll_calc_port_clock(const struct intel_c10pll_state *pll_state)
2044 {
2045 	unsigned int frac_quot = 0, frac_rem = 0, frac_den = 1;
2046 	unsigned int multiplier, tx_clk_div, hdmi_div, refclk = 38400;
2047 	int tmpclk = 0;
2048 
2049 	if (pll_state->pll[0] & C10_PLL0_FRACEN) {
2050 		frac_quot = pll_state->pll[12] << 8 | pll_state->pll[11];
2051 		frac_rem =  pll_state->pll[14] << 8 | pll_state->pll[13];
2052 		frac_den =  pll_state->pll[10] << 8 | pll_state->pll[9];
2053 	}
2054 
2055 	multiplier = (REG_FIELD_GET8(C10_PLL3_MULTIPLIERH_MASK, pll_state->pll[3]) << 8 |
2056 		      pll_state->pll[2]) / 2 + 16;
2057 
2058 	tx_clk_div = REG_FIELD_GET8(C10_PLL15_TXCLKDIV_MASK, pll_state->pll[15]);
2059 	hdmi_div = REG_FIELD_GET8(C10_PLL15_HDMIDIV_MASK, pll_state->pll[15]);
2060 
2061 	tmpclk = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, (multiplier << 16) + frac_quot) +
2062 				     DIV_ROUND_CLOSEST(refclk * frac_rem, frac_den),
2063 				     10 << (tx_clk_div + 16));
2064 	tmpclk *= (hdmi_div ? 2 : 1);
2065 
2066 	return tmpclk;
2067 }
2068 
2069 static bool intel_c20phy_use_mpllb(const struct intel_c20pll_state *state)
2070 {
2071 	return state->tx[0] & C20_PHY_USE_MPLLB;
2072 }
2073 
2074 static int intel_c20pll_calc_port_clock(const struct intel_c20pll_state *pll_state)
2075 {
2076 	unsigned int frac, frac_en, frac_quot, frac_rem, frac_den;
2077 	unsigned int multiplier, refclk = 38400;
2078 	unsigned int tx_clk_div;
2079 	unsigned int ref_clk_mpllb_div;
2080 	unsigned int fb_clk_div4_en;
2081 	unsigned int ref, vco;
2082 	unsigned int tx_rate_mult;
2083 	unsigned int tx_rate = REG_FIELD_GET(C20_PHY_TX_RATE, pll_state->tx[0]);
2084 
2085 	if (intel_c20phy_use_mpllb(pll_state)) {
2086 		tx_rate_mult = 1;
2087 		frac_en = REG_FIELD_GET(C20_MPLLB_FRACEN, pll_state->mpllb[6]);
2088 		frac_quot = pll_state->mpllb[8];
2089 		frac_rem =  pll_state->mpllb[9];
2090 		frac_den =  pll_state->mpllb[7];
2091 		multiplier = REG_FIELD_GET(C20_MULTIPLIER_MASK, pll_state->mpllb[0]);
2092 		tx_clk_div = REG_FIELD_GET(C20_MPLLB_TX_CLK_DIV_MASK, pll_state->mpllb[0]);
2093 		ref_clk_mpllb_div = REG_FIELD_GET(C20_REF_CLK_MPLLB_DIV_MASK, pll_state->mpllb[6]);
2094 		fb_clk_div4_en = 0;
2095 	} else {
2096 		tx_rate_mult = 2;
2097 		frac_en = REG_FIELD_GET(C20_MPLLA_FRACEN, pll_state->mplla[6]);
2098 		frac_quot = pll_state->mplla[8];
2099 		frac_rem =  pll_state->mplla[9];
2100 		frac_den =  pll_state->mplla[7];
2101 		multiplier = REG_FIELD_GET(C20_MULTIPLIER_MASK, pll_state->mplla[0]);
2102 		tx_clk_div = REG_FIELD_GET(C20_MPLLA_TX_CLK_DIV_MASK, pll_state->mplla[1]);
2103 		ref_clk_mpllb_div = REG_FIELD_GET(C20_REF_CLK_MPLLB_DIV_MASK, pll_state->mplla[6]);
2104 		fb_clk_div4_en = REG_FIELD_GET(C20_FB_CLK_DIV4_EN, pll_state->mplla[0]);
2105 	}
2106 
2107 	if (frac_en)
2108 		frac = frac_quot + DIV_ROUND_CLOSEST(frac_rem, frac_den);
2109 	else
2110 		frac = 0;
2111 
2112 	ref = DIV_ROUND_CLOSEST(refclk * (1 << (1 + fb_clk_div4_en)), 1 << ref_clk_mpllb_div);
2113 	vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(ref, (multiplier << (17 - 2)) + frac) >> 17, 10);
2114 
2115 	return vco << tx_rate_mult >> tx_clk_div >> tx_rate;
2116 }
2117 
2118 /*
2119  * TODO: Convert the following to align with intel_c20pll_find_table() and
2120  * intel_c20pll_calc_state_from_table().
2121  */
2122 static int intel_c10pll_calc_state_from_table(struct intel_encoder *encoder,
2123 					      const struct intel_cx0pll_params *tables,
2124 					      bool is_dp, int port_clock, int lane_count,
2125 					      struct intel_cx0pll_state *pll_state)
2126 {
2127 	struct intel_display *display = to_intel_display(encoder);
2128 	int i;
2129 
2130 	for (i = 0; tables[i].name; i++) {
2131 		int clock = intel_c10pll_calc_port_clock(tables[i].c10);
2132 
2133 		drm_WARN_ON(display->drm, !intel_dpll_clock_matches(clock, tables[i].clock_rate));
2134 		if (intel_dpll_clock_matches(port_clock, clock)) {
2135 			pll_state->c10 = *tables[i].c10;
2136 			intel_cx0pll_update_ssc(encoder, pll_state, is_dp);
2137 			intel_c10pll_update_pll(encoder, pll_state);
2138 
2139 			pll_state->use_c10 = true;
2140 			pll_state->lane_count = lane_count;
2141 
2142 			drm_WARN_ON(display->drm, is_dp != c10pll_state_is_dp(&pll_state->c10));
2143 
2144 			return 0;
2145 		}
2146 	}
2147 
2148 	return -EINVAL;
2149 }
2150 
2151 static int intel_c10pll_calc_state(const struct intel_crtc_state *crtc_state,
2152 				   struct intel_encoder *encoder,
2153 				   struct intel_dpll_hw_state *hw_state)
2154 {
2155 	struct intel_display *display = to_intel_display(encoder);
2156 	bool is_dp = intel_crtc_has_dp_encoder(crtc_state);
2157 	const struct intel_cx0pll_params *tables;
2158 	int err;
2159 
2160 	tables = intel_c10pll_tables_get(crtc_state, encoder);
2161 	if (!tables)
2162 		return -EINVAL;
2163 
2164 	err = intel_c10pll_calc_state_from_table(encoder, tables, is_dp,
2165 						 crtc_state->port_clock, crtc_state->lane_count,
2166 						 &hw_state->cx0pll);
2167 
2168 	if (err == 0 || !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
2169 		return err;
2170 
2171 	/* For HDMI PLLs try SNPS PHY algorithm, if there are no precomputed tables */
2172 	intel_snps_hdmi_pll_compute_c10pll(&hw_state->cx0pll.c10,
2173 					   crtc_state->port_clock);
2174 	intel_c10pll_update_pll(encoder, &hw_state->cx0pll);
2175 
2176 	hw_state->cx0pll.use_c10 = true;
2177 	hw_state->cx0pll.lane_count = crtc_state->lane_count;
2178 
2179 	drm_WARN_ON(display->drm, is_dp != c10pll_state_is_dp(&hw_state->cx0pll.c10));
2180 
2181 	return 0;
2182 }
2183 
2184 int intel_readout_lane_count(struct intel_encoder *encoder, int lane0, int lane1)
2185 {
2186 	struct intel_display *display = to_intel_display(encoder);
2187 	u8 enabled_tx_lane_count = 0;
2188 	int max_tx_lane_count = 4;
2189 	bool lane_reversal;
2190 	int tx_lane;
2191 
2192 	lane_reversal = intel_de_read(display, XELPDP_PORT_BUF_CTL1(display, encoder->port)) &
2193 			XELPDP_PORT_REVERSAL;
2194 
2195 	/*
2196 	 * TODO: also check inactive TX lanes in all PHY lanes owned by the
2197 	 * display. For now checking only those PHY lane(s) which are owned
2198 	 * based on the active TX lane count (i.e.
2199 	 *   1,2 active TX lanes -> PHY lane#0
2200 	 *   3,4 active TX lanes -> PHY lane#0 and PHY lane#1).
2201 	 *
2202 	 * In case of lane reversal for 1, 2 active TX lanes, only PHY
2203 	 * lane#1 is used. This is only possible in TypeC legacy mode or if
2204 	 * the port is connected to a non-TC PHY. In both of these cases both
2205 	 * PHY lane#0 and #1 are owned by display, so check all 4 TX lanes in
2206 	 * both PHY lanes in those cases.
2207 	 */
2208 	if (!lane_reversal)
2209 		max_tx_lane_count = DDI_PORT_WIDTH_GET(intel_de_read(display,
2210 								     DDI_BUF_CTL(encoder->port)));
2211 
2212 	if (!drm_WARN_ON(display->drm, max_tx_lane_count == 0))
2213 		max_tx_lane_count = round_up(max_tx_lane_count, 2);
2214 
2215 	for (tx_lane = 0; tx_lane < max_tx_lane_count; tx_lane++) {
2216 		u8 phy_lane_mask = tx_lane < 2 ? lane0 : lane1;
2217 		int tx = tx_lane % 2 + 1;
2218 		u8 val;
2219 
2220 		val = intel_cx0_read(encoder, phy_lane_mask, PHY_CX0_TX_CONTROL(tx, 2));
2221 		if (!(val & CONTROL2_DISABLE_SINGLE_TX))
2222 			enabled_tx_lane_count++;
2223 	}
2224 
2225 	return enabled_tx_lane_count;
2226 }
2227 
2228 static bool readout_ssc_state(struct intel_encoder *encoder, bool is_mpll_b)
2229 {
2230 	struct intel_display *display = to_intel_display(encoder);
2231 
2232 	return intel_de_read(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port)) &
2233 		(is_mpll_b ? XELPDP_SSC_ENABLE_PLLB : XELPDP_SSC_ENABLE_PLLA);
2234 }
2235 
2236 static void intel_c10pll_readout_hw_state(struct intel_encoder *encoder,
2237 					  struct intel_cx0pll_state *cx0pll_state)
2238 {
2239 	struct intel_c10pll_state *pll_state = &cx0pll_state->c10;
2240 	struct intel_display *display = to_intel_display(encoder);
2241 	enum phy phy = intel_encoder_to_phy(encoder);
2242 	u8 lane = INTEL_CX0_LANE0;
2243 	struct ref_tracker *wakeref;
2244 	int i;
2245 
2246 	cx0pll_state->use_c10 = true;
2247 
2248 	wakeref = intel_cx0_phy_transaction_begin(encoder);
2249 
2250 	/*
2251 	 * According to C10 VDR Register programming Sequence we need
2252 	 * to do this to read PHY internal registers from MsgBus.
2253 	 */
2254 	intel_c10_msgbus_access_begin(encoder, lane);
2255 
2256 	cx0pll_state->lane_count = intel_readout_lane_count(encoder, INTEL_CX0_LANE0,
2257 							    INTEL_CX0_LANE1);
2258 
2259 	for (i = 0; i < ARRAY_SIZE(pll_state->pll); i++)
2260 		pll_state->pll[i] = intel_cx0_read(encoder, lane, PHY_C10_VDR_PLL(i));
2261 
2262 	pll_state->cmn = intel_cx0_read(encoder, lane, PHY_C10_VDR_CMN(0));
2263 	pll_state->tx = intel_cx0_read(encoder, lane, PHY_C10_VDR_TX(0));
2264 
2265 	intel_cx0_phy_transaction_end(encoder, wakeref);
2266 
2267 	cx0pll_state->ssc_enabled = readout_ssc_state(encoder, true);
2268 
2269 	if (cx0pll_state->ssc_enabled != intel_c10pll_ssc_enabled(pll_state))
2270 		drm_dbg_kms(display->drm,
2271 			    "PHY %c: SSC state mismatch: port SSC is %s, PLL SSC is %s\n",
2272 			    phy_name(phy),
2273 			    str_enabled_disabled(cx0pll_state->ssc_enabled),
2274 			    str_enabled_disabled(intel_c10pll_ssc_enabled(pll_state)));
2275 }
2276 
2277 static void intel_c10_pll_program(struct intel_display *display,
2278 				  struct intel_encoder *encoder,
2279 				  const struct intel_c10pll_state *pll_state)
2280 {
2281 	int i;
2282 
2283 	intel_c10_msgbus_access_begin(encoder, INTEL_CX0_BOTH_LANES);
2284 
2285 	/* Program the pll values only for the master lane */
2286 	for (i = 0; i < ARRAY_SIZE(pll_state->pll); i++)
2287 		intel_cx0_write(encoder, INTEL_CX0_LANE0, PHY_C10_VDR_PLL(i),
2288 				pll_state->pll[i],
2289 				(i % 4) ? MB_WRITE_UNCOMMITTED : MB_WRITE_COMMITTED);
2290 
2291 	intel_cx0_write(encoder, INTEL_CX0_LANE0, PHY_C10_VDR_CMN(0), pll_state->cmn, MB_WRITE_COMMITTED);
2292 	intel_cx0_write(encoder, INTEL_CX0_LANE0, PHY_C10_VDR_TX(0), pll_state->tx, MB_WRITE_COMMITTED);
2293 
2294 	/* Custom width needs to be programmed to 0 for both the phy lanes */
2295 	intel_cx0_rmw(encoder, INTEL_CX0_BOTH_LANES, PHY_C10_VDR_CUSTOM_WIDTH,
2296 		      C10_VDR_CUSTOM_WIDTH_MASK, C10_VDR_CUSTOM_WIDTH_8_10,
2297 		      MB_WRITE_COMMITTED);
2298 
2299 	intel_c10_msgbus_access_commit(encoder, INTEL_CX0_LANE0, true);
2300 }
2301 
2302 static void intel_c10pll_dump_hw_state(struct drm_printer *p,
2303 				       const struct intel_c10pll_state *hw_state)
2304 {
2305 	bool fracen;
2306 	int i;
2307 	unsigned int frac_quot = 0, frac_rem = 0, frac_den = 1;
2308 	unsigned int multiplier, tx_clk_div;
2309 
2310 	fracen = hw_state->pll[0] & C10_PLL0_FRACEN;
2311 	drm_printf(p, "c10pll_hw_state: fracen: %s, ", str_yes_no(fracen));
2312 
2313 	if (fracen) {
2314 		frac_quot = hw_state->pll[12] << 8 | hw_state->pll[11];
2315 		frac_rem =  hw_state->pll[14] << 8 | hw_state->pll[13];
2316 		frac_den =  hw_state->pll[10] << 8 | hw_state->pll[9];
2317 		drm_printf(p, "quot: %u, rem: %u, den: %u,\n",
2318 			   frac_quot, frac_rem, frac_den);
2319 	}
2320 
2321 	multiplier = (REG_FIELD_GET8(C10_PLL3_MULTIPLIERH_MASK, hw_state->pll[3]) << 8 |
2322 		      hw_state->pll[2]) / 2 + 16;
2323 	tx_clk_div = REG_FIELD_GET8(C10_PLL15_TXCLKDIV_MASK, hw_state->pll[15]);
2324 	drm_printf(p,
2325 		   "multiplier: %u, tx_clk_div: %u.\n", multiplier, tx_clk_div);
2326 
2327 	drm_printf(p, "c10pll_rawhw_state:");
2328 	drm_printf(p, "tx: 0x%x, cmn: 0x%x\n", hw_state->tx, hw_state->cmn);
2329 
2330 	BUILD_BUG_ON(ARRAY_SIZE(hw_state->pll) % 4);
2331 	for (i = 0; i < ARRAY_SIZE(hw_state->pll); i = i + 4)
2332 		drm_printf(p,
2333 			   "pll[%d] = 0x%x, pll[%d] = 0x%x, pll[%d] = 0x%x, pll[%d] = 0x%x\n",
2334 			   i, hw_state->pll[i], i + 1, hw_state->pll[i + 1],
2335 			   i + 2, hw_state->pll[i + 2], i + 3, hw_state->pll[i + 3]);
2336 }
2337 
2338 /*
2339  * Some ARLs SoCs have the same drm PCI IDs, so need a helper to differentiate based
2340  * on the host bridge device ID to get the correct txx_mics value.
2341  */
2342 static bool is_arrowlake_s_by_host_bridge(void)
2343 {
2344 	struct pci_dev *pdev = NULL;
2345 	while ((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST << 8, pdev))) {
2346 		if (IS_ARROWLAKE_S_BY_HOST_BRIDGE_ID(pdev->device)) {
2347 			pci_dev_put(pdev);
2348 			return true;
2349 		}
2350 	}
2351 
2352 	return false;
2353 }
2354 
2355 static u16 intel_c20_hdmi_tmds_tx_cgf_1(struct intel_display *display)
2356 {
2357 	u16 tx_misc;
2358 	u16 tx_dcc_cal_dac_ctrl_range = 8;
2359 	u16 tx_term_ctrl = 2;
2360 
2361 	if (DISPLAY_VER(display) >= 20) {
2362 		tx_misc = 5;
2363 		tx_term_ctrl = 4;
2364 	} else if (display->platform.battlemage) {
2365 		tx_misc = 0;
2366 	} else if (display->platform.meteorlake_u ||
2367 		   is_arrowlake_s_by_host_bridge()) {
2368 		tx_misc = 3;
2369 	} else {
2370 		tx_misc = 7;
2371 	}
2372 
2373 	return (C20_PHY_TX_MISC(tx_misc) |
2374 		C20_PHY_TX_DCC_CAL_RANGE(tx_dcc_cal_dac_ctrl_range) |
2375 		C20_PHY_TX_DCC_BYPASS | C20_PHY_TX_TERM_CTL(tx_term_ctrl));
2376 }
2377 
2378 static int intel_c20_compute_hdmi_tmds_pll(struct intel_display *display,
2379 					   int port_clock,
2380 					   struct intel_c20pll_state *pll_state)
2381 {
2382 	u64 datarate;
2383 	u64 mpll_tx_clk_div;
2384 	u64 vco_freq_shift;
2385 	u64 vco_freq;
2386 	u64 multiplier;
2387 	u64 mpll_multiplier;
2388 	u64 mpll_fracn_quot;
2389 	u64 mpll_fracn_rem;
2390 	u8  mpllb_ana_freq_vco;
2391 	u8  mpll_div_multiplier;
2392 
2393 	if (port_clock < 25175 || port_clock > 600000)
2394 		return -EINVAL;
2395 
2396 	datarate = ((u64)port_clock * 1000) * 10;
2397 	mpll_tx_clk_div = ilog2(div64_u64((u64)CLOCK_9999MHZ, (u64)datarate));
2398 	vco_freq_shift = ilog2(div64_u64((u64)CLOCK_4999MHZ * (u64)256, (u64)datarate));
2399 	vco_freq = (datarate << vco_freq_shift) >> 8;
2400 	multiplier = div64_u64((vco_freq << 28), (REFCLK_38_4_MHZ >> 4));
2401 	mpll_multiplier = 2 * (multiplier >> 32);
2402 
2403 	mpll_fracn_quot = (multiplier >> 16) & 0xFFFF;
2404 	mpll_fracn_rem  = multiplier & 0xFFFF;
2405 
2406 	mpll_div_multiplier = min_t(u8, div64_u64((vco_freq * 16 + (datarate >> 1)),
2407 						  datarate), 255);
2408 
2409 	if (vco_freq <= DATARATE_3000000000)
2410 		mpllb_ana_freq_vco = MPLLB_ANA_FREQ_VCO_3;
2411 	else if (vco_freq <= DATARATE_3500000000)
2412 		mpllb_ana_freq_vco = MPLLB_ANA_FREQ_VCO_2;
2413 	else if (vco_freq <= DATARATE_4000000000)
2414 		mpllb_ana_freq_vco = MPLLB_ANA_FREQ_VCO_1;
2415 	else
2416 		mpllb_ana_freq_vco = MPLLB_ANA_FREQ_VCO_0;
2417 
2418 	pll_state->tx[0]	= 0xbe88;
2419 	pll_state->tx[1]	= intel_c20_hdmi_tmds_tx_cgf_1(display);
2420 	pll_state->tx[2]	= 0x0000;
2421 	pll_state->cmn[0]	= 0x0500;
2422 	pll_state->cmn[1]	= 0x0005;
2423 	pll_state->cmn[2]	= 0x0000;
2424 	pll_state->cmn[3]	= 0x0000;
2425 	pll_state->mpllb[0]	= (MPLL_TX_CLK_DIV(mpll_tx_clk_div) |
2426 				   MPLL_MULTIPLIER(mpll_multiplier));
2427 	pll_state->mpllb[1]	= (CAL_DAC_CODE(CAL_DAC_CODE_31) |
2428 				   WORD_CLK_DIV |
2429 				   MPLL_DIV_MULTIPLIER(mpll_div_multiplier));
2430 	pll_state->mpllb[2]	= (MPLLB_ANA_FREQ_VCO(mpllb_ana_freq_vco) |
2431 				   CP_PROP(CP_PROP_20) |
2432 				   CP_INT(CP_INT_6));
2433 	pll_state->mpllb[3]	= (V2I(V2I_2) |
2434 				   CP_PROP_GS(CP_PROP_GS_30) |
2435 				   CP_INT_GS(CP_INT_GS_28));
2436 	pll_state->mpllb[4]	= 0x0000;
2437 	pll_state->mpllb[5]	= 0x0000;
2438 	pll_state->mpllb[6]	= (C20_MPLLB_FRACEN | SSC_UP_SPREAD);
2439 	pll_state->mpllb[7]	= MPLL_FRACN_DEN;
2440 	pll_state->mpllb[8]	= mpll_fracn_quot;
2441 	pll_state->mpllb[9]	= mpll_fracn_rem;
2442 	pll_state->mpllb[10]	= HDMI_DIV(HDMI_DIV_1);
2443 
2444 	return 0;
2445 }
2446 
2447 static const struct intel_cx0pll_params *
2448 intel_c20_pll_tables_get(const struct intel_crtc_state *crtc_state,
2449 			 struct intel_encoder *encoder)
2450 {
2451 	struct intel_display *display = to_intel_display(crtc_state);
2452 
2453 	if (intel_crtc_has_dp_encoder(crtc_state)) {
2454 		if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) {
2455 			if (DISPLAY_RUNTIME_INFO(display)->edp_typec_support)
2456 				return xe3lpd_c20_dp_edp_tables;
2457 			if (DISPLAY_VERx100(display) == 1401)
2458 				return xe2hpd_c20_edp_tables;
2459 		}
2460 
2461 		if (DISPLAY_VER(display) >= 30)
2462 			return xe3lpd_c20_dp_edp_tables;
2463 		else if (DISPLAY_VERx100(display) == 1401)
2464 			return xe2hpd_c20_dp_tables;
2465 		else
2466 			return mtl_c20_dp_tables;
2467 
2468 	} else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
2469 		return mtl_c20_hdmi_tables;
2470 	}
2471 
2472 	MISSING_CASE(encoder->type);
2473 	return NULL;
2474 }
2475 
2476 static u8 intel_c20_get_dp_rate(u32 clock)
2477 {
2478 	switch (clock) {
2479 	case 162000: /* 1.62 Gbps DP1.4 */
2480 		return 0;
2481 	case 270000: /* 2.7 Gbps DP1.4 */
2482 		return 1;
2483 	case 540000: /* 5.4 Gbps DP 1.4 */
2484 		return 2;
2485 	case 810000: /* 8.1 Gbps DP1.4 */
2486 		return 3;
2487 	case 216000: /* 2.16 Gbps eDP */
2488 		return 4;
2489 	case 243000: /* 2.43 Gbps eDP */
2490 		return 5;
2491 	case 324000: /* 3.24 Gbps eDP */
2492 		return 6;
2493 	case 432000: /* 4.32 Gbps eDP */
2494 		return 7;
2495 	case 1000000: /* 10 Gbps DP2.0 */
2496 		return 8;
2497 	case 1350000: /* 13.5 Gbps DP2.0 */
2498 		return 9;
2499 	case 2000000: /* 20 Gbps DP2.0 */
2500 		return 10;
2501 	case 648000: /* 6.48 Gbps eDP*/
2502 		return 11;
2503 	case 675000: /* 6.75 Gbps eDP*/
2504 		return 12;
2505 	default:
2506 		MISSING_CASE(clock);
2507 		return 0;
2508 	}
2509 }
2510 
2511 static u8 intel_c20_get_hdmi_rate(u32 clock)
2512 {
2513 	if (clock >= 25175 && clock <= 600000)
2514 		return 0;
2515 
2516 	switch (clock) {
2517 	case 300000: /* 3 Gbps */
2518 	case 600000: /* 6 Gbps */
2519 	case 1200000: /* 12 Gbps */
2520 		return 1;
2521 	case 800000: /* 8 Gbps */
2522 		return 2;
2523 	case 1000000: /* 10 Gbps */
2524 		return 3;
2525 	default:
2526 		MISSING_CASE(clock);
2527 		return 0;
2528 	}
2529 }
2530 
2531 static bool is_dp2(u32 clock)
2532 {
2533 	/* DP2.0 clock rates */
2534 	if (clock == 1000000 || clock == 1350000 || clock  == 2000000)
2535 		return true;
2536 
2537 	return false;
2538 }
2539 
2540 static int intel_get_c20_custom_width(u32 clock, bool dp)
2541 {
2542 	if (dp && is_dp2(clock))
2543 		return 2;
2544 	else if (intel_hdmi_is_frl(clock))
2545 		return 1;
2546 	else
2547 		return 0;
2548 }
2549 
2550 static void intel_c20_calc_vdr_params(struct intel_c20pll_vdr_state *vdr, bool is_dp,
2551 				      int port_clock)
2552 {
2553 	vdr->custom_width = intel_get_c20_custom_width(port_clock, is_dp);
2554 
2555 	vdr->serdes_rate = 0;
2556 	vdr->hdmi_rate = 0;
2557 
2558 	if (is_dp) {
2559 		vdr->serdes_rate = PHY_C20_IS_DP |
2560 				   PHY_C20_DP_RATE(intel_c20_get_dp_rate(port_clock));
2561 	} else {
2562 		if (intel_hdmi_is_frl(port_clock))
2563 			vdr->serdes_rate = PHY_C20_IS_HDMI_FRL;
2564 
2565 		vdr->hdmi_rate = intel_c20_get_hdmi_rate(port_clock);
2566 	}
2567 }
2568 
2569 #define PHY_C20_SERDES_RATE_MASK	(PHY_C20_IS_DP | PHY_C20_DP_RATE_MASK | PHY_C20_IS_HDMI_FRL)
2570 
2571 static void intel_c20_readout_vdr_params(struct intel_encoder *encoder,
2572 					 struct intel_c20pll_vdr_state *vdr, bool *cntx)
2573 {
2574 	u8 serdes;
2575 
2576 	serdes = intel_cx0_read(encoder, INTEL_CX0_LANE0, PHY_C20_VDR_CUSTOM_SERDES_RATE);
2577 	*cntx = serdes & PHY_C20_CONTEXT_TOGGLE;
2578 
2579 	vdr->custom_width = intel_cx0_read(encoder, INTEL_CX0_LANE0, PHY_C20_VDR_CUSTOM_WIDTH) &
2580 			    PHY_C20_CUSTOM_WIDTH_MASK;
2581 
2582 	vdr->serdes_rate = serdes & PHY_C20_SERDES_RATE_MASK;
2583 	if (!(vdr->serdes_rate & PHY_C20_IS_DP))
2584 		vdr->hdmi_rate = intel_cx0_read(encoder, INTEL_CX0_LANE0, PHY_C20_VDR_HDMI_RATE) &
2585 				 PHY_C20_HDMI_RATE_MASK;
2586 	else
2587 		vdr->hdmi_rate = 0;
2588 }
2589 
2590 static void intel_c20_program_vdr_params(struct intel_encoder *encoder,
2591 					 const struct intel_c20pll_vdr_state *vdr,
2592 					 u8 owned_lane_mask)
2593 {
2594 	struct intel_display *display = to_intel_display(encoder);
2595 
2596 	drm_WARN_ON(display->drm, vdr->custom_width & ~PHY_C20_CUSTOM_WIDTH_MASK);
2597 	intel_cx0_rmw(encoder, owned_lane_mask, PHY_C20_VDR_CUSTOM_WIDTH,
2598 		      PHY_C20_CUSTOM_WIDTH_MASK, vdr->custom_width,
2599 		      MB_WRITE_COMMITTED);
2600 
2601 	drm_WARN_ON(display->drm, vdr->serdes_rate & ~PHY_C20_SERDES_RATE_MASK);
2602 	intel_cx0_rmw(encoder, owned_lane_mask, PHY_C20_VDR_CUSTOM_SERDES_RATE,
2603 		      PHY_C20_SERDES_RATE_MASK, vdr->serdes_rate,
2604 		      MB_WRITE_COMMITTED);
2605 
2606 	if (vdr->serdes_rate & PHY_C20_IS_DP)
2607 		return;
2608 
2609 	drm_WARN_ON(display->drm, vdr->hdmi_rate & ~PHY_C20_HDMI_RATE_MASK);
2610 	intel_cx0_rmw(encoder, INTEL_CX0_BOTH_LANES, PHY_C20_VDR_HDMI_RATE,
2611 		      PHY_C20_HDMI_RATE_MASK, vdr->hdmi_rate,
2612 		      MB_WRITE_COMMITTED);
2613 }
2614 
2615 static const struct intel_cx0pll_params *
2616 intel_c20_pll_find_table(const struct intel_crtc_state *crtc_state,
2617 			 struct intel_encoder *encoder)
2618 {
2619 	struct intel_display *display = to_intel_display(crtc_state);
2620 	const struct intel_cx0pll_params *tables;
2621 	int i;
2622 
2623 	tables = intel_c20_pll_tables_get(crtc_state, encoder);
2624 	if (!tables)
2625 		return NULL;
2626 
2627 	for (i = 0; tables[i].name; i++) {
2628 		int clock = intel_c20pll_calc_port_clock(tables[i].c20);
2629 
2630 		drm_WARN_ON(display->drm, !intel_dpll_clock_matches(clock, tables[i].clock_rate));
2631 		if (intel_dpll_clock_matches(crtc_state->port_clock, clock))
2632 			return &tables[i];
2633 	}
2634 
2635 	return NULL;
2636 }
2637 
2638 static int intel_c20pll_calc_state_from_table(const struct intel_crtc_state *crtc_state,
2639 					      struct intel_encoder *encoder,
2640 					      struct intel_cx0pll_state *pll_state)
2641 {
2642 	const struct intel_cx0pll_params *table;
2643 
2644 	table = intel_c20_pll_find_table(crtc_state, encoder);
2645 	if (!table)
2646 		return -EINVAL;
2647 
2648 	pll_state->c20 = *table->c20;
2649 
2650 	intel_cx0pll_update_ssc(encoder, pll_state, intel_crtc_has_dp_encoder(crtc_state));
2651 
2652 	return 0;
2653 }
2654 
2655 static int intel_c20pll_calc_state(const struct intel_crtc_state *crtc_state,
2656 				   struct intel_encoder *encoder,
2657 				   struct intel_dpll_hw_state *hw_state)
2658 {
2659 	struct intel_display *display = to_intel_display(encoder);
2660 	bool is_dp = intel_crtc_has_dp_encoder(crtc_state);
2661 	int err = -ENOENT;
2662 
2663 	hw_state->cx0pll.use_c10 = false;
2664 	hw_state->cx0pll.lane_count = crtc_state->lane_count;
2665 
2666 	/*
2667 	 * Try the ideal C20 HDMI tables before computing them, since the calculated
2668 	 * values, although correct, may not be optimal.
2669 	 */
2670 	if (err)
2671 		err = intel_c20pll_calc_state_from_table(crtc_state, encoder,
2672 							 &hw_state->cx0pll);
2673 
2674 	/* TODO: Update SSC state for HDMI as well */
2675 	if (!is_dp && err)
2676 		err = intel_c20_compute_hdmi_tmds_pll(display, crtc_state->port_clock,
2677 						      &hw_state->cx0pll.c20);
2678 
2679 	if (err)
2680 		return err;
2681 
2682 	intel_c20_calc_vdr_params(&hw_state->cx0pll.c20.vdr,
2683 				  is_dp, crtc_state->port_clock);
2684 
2685 	drm_WARN_ON(display->drm, is_dp != c20pll_state_is_dp(&hw_state->cx0pll.c20));
2686 
2687 	return 0;
2688 }
2689 
2690 int intel_cx0pll_calc_state(const struct intel_crtc_state *crtc_state,
2691 			    struct intel_encoder *encoder,
2692 			    struct intel_dpll_hw_state *hw_state)
2693 {
2694 	memset(hw_state, 0, sizeof(*hw_state));
2695 
2696 	if (intel_encoder_is_c10phy(encoder))
2697 		return intel_c10pll_calc_state(crtc_state, encoder, hw_state);
2698 	return intel_c20pll_calc_state(crtc_state, encoder, hw_state);
2699 }
2700 
2701 static void intel_c20pll_readout_hw_state(struct intel_encoder *encoder,
2702 					  struct intel_cx0pll_state *cx0pll_state)
2703 {
2704 	struct intel_c20pll_state *pll_state = &cx0pll_state->c20;
2705 	struct intel_display *display = to_intel_display(encoder);
2706 	bool cntx;
2707 	struct ref_tracker *wakeref;
2708 	int i;
2709 
2710 	cx0pll_state->use_c10 = false;
2711 
2712 	wakeref = intel_cx0_phy_transaction_begin(encoder);
2713 
2714 	cx0pll_state->lane_count = intel_readout_lane_count(encoder, INTEL_CX0_LANE0,
2715 							    INTEL_CX0_LANE1);
2716 
2717 	/* 1. Read VDR params and current context selection */
2718 	intel_c20_readout_vdr_params(encoder, &pll_state->vdr, &cntx);
2719 
2720 	/* Read Tx configuration */
2721 	for (i = 0; i < ARRAY_SIZE(pll_state->tx); i++) {
2722 		if (cntx)
2723 			pll_state->tx[i] = intel_c20_sram_read(encoder,
2724 							       INTEL_CX0_LANE0,
2725 							       PHY_C20_B_TX_CNTX_CFG(display, i));
2726 		else
2727 			pll_state->tx[i] = intel_c20_sram_read(encoder,
2728 							       INTEL_CX0_LANE0,
2729 							       PHY_C20_A_TX_CNTX_CFG(display, i));
2730 	}
2731 
2732 	/* Read common configuration */
2733 	for (i = 0; i < ARRAY_SIZE(pll_state->cmn); i++) {
2734 		if (cntx)
2735 			pll_state->cmn[i] = intel_c20_sram_read(encoder,
2736 								INTEL_CX0_LANE0,
2737 								PHY_C20_B_CMN_CNTX_CFG(display, i));
2738 		else
2739 			pll_state->cmn[i] = intel_c20_sram_read(encoder,
2740 								INTEL_CX0_LANE0,
2741 								PHY_C20_A_CMN_CNTX_CFG(display, i));
2742 	}
2743 
2744 	if (intel_c20phy_use_mpllb(pll_state)) {
2745 		/* MPLLB configuration */
2746 		for (i = 0; i < ARRAY_SIZE(pll_state->mpllb); i++) {
2747 			if (cntx)
2748 				pll_state->mpllb[i] = intel_c20_sram_read(encoder,
2749 									  INTEL_CX0_LANE0,
2750 									  PHY_C20_B_MPLLB_CNTX_CFG(display, i));
2751 			else
2752 				pll_state->mpllb[i] = intel_c20_sram_read(encoder,
2753 									  INTEL_CX0_LANE0,
2754 									  PHY_C20_A_MPLLB_CNTX_CFG(display, i));
2755 		}
2756 	} else {
2757 		/* MPLLA configuration */
2758 		for (i = 0; i < ARRAY_SIZE(pll_state->mplla); i++) {
2759 			if (cntx)
2760 				pll_state->mplla[i] = intel_c20_sram_read(encoder,
2761 									  INTEL_CX0_LANE0,
2762 									  PHY_C20_B_MPLLA_CNTX_CFG(display, i));
2763 			else
2764 				pll_state->mplla[i] = intel_c20_sram_read(encoder,
2765 									  INTEL_CX0_LANE0,
2766 									  PHY_C20_A_MPLLA_CNTX_CFG(display, i));
2767 		}
2768 	}
2769 
2770 	intel_cx0_phy_transaction_end(encoder, wakeref);
2771 
2772 	cx0pll_state->ssc_enabled = readout_ssc_state(encoder, intel_c20phy_use_mpllb(pll_state));
2773 }
2774 
2775 static void intel_c20pll_dump_hw_state(struct drm_printer *p,
2776 				       const struct intel_c20pll_state *hw_state)
2777 {
2778 	int i;
2779 
2780 	drm_printf(p, "c20pll_hw_state:\n");
2781 	drm_printf(p,
2782 		   "tx[0] = 0x%.4x, tx[1] = 0x%.4x, tx[2] = 0x%.4x\n",
2783 		   hw_state->tx[0], hw_state->tx[1], hw_state->tx[2]);
2784 	drm_printf(p,
2785 		   "cmn[0] = 0x%.4x, cmn[1] = 0x%.4x, cmn[2] = 0x%.4x, cmn[3] = 0x%.4x\n",
2786 		   hw_state->cmn[0], hw_state->cmn[1], hw_state->cmn[2], hw_state->cmn[3]);
2787 
2788 	if (intel_c20phy_use_mpllb(hw_state)) {
2789 		for (i = 0; i < ARRAY_SIZE(hw_state->mpllb); i++)
2790 			drm_printf(p, "mpllb[%d] = 0x%.4x\n", i, hw_state->mpllb[i]);
2791 	} else {
2792 		for (i = 0; i < ARRAY_SIZE(hw_state->mplla); i++)
2793 			drm_printf(p, "mplla[%d] = 0x%.4x\n", i, hw_state->mplla[i]);
2794 
2795 		/* For full coverage, also print the additional PLL B entry. */
2796 		BUILD_BUG_ON(ARRAY_SIZE(hw_state->mplla) + 1 != ARRAY_SIZE(hw_state->mpllb));
2797 		drm_printf(p, "mpllb[%d] = 0x%.4x\n", i, hw_state->mpllb[i]);
2798 	}
2799 
2800 	drm_printf(p,
2801 		   "vdr: custom width: 0x%02x, serdes rate: 0x%02x, hdmi rate: 0x%02x\n",
2802 		   hw_state->vdr.custom_width, hw_state->vdr.serdes_rate, hw_state->vdr.hdmi_rate);
2803 }
2804 
2805 void intel_cx0pll_dump_hw_state(struct drm_printer *p,
2806 				const struct intel_cx0pll_state *hw_state)
2807 {
2808 	drm_printf(p,
2809 		   "cx0pll_hw_state: lane_count: %d, ssc_enabled: %s, use_c10: %s, tbt_mode: %s\n",
2810 		   hw_state->lane_count, str_yes_no(hw_state->ssc_enabled),
2811 		   str_yes_no(hw_state->use_c10), str_yes_no(hw_state->tbt_mode));
2812 
2813 	if (hw_state->use_c10)
2814 		intel_c10pll_dump_hw_state(p, &hw_state->c10);
2815 	else
2816 		intel_c20pll_dump_hw_state(p, &hw_state->c20);
2817 }
2818 
2819 static bool intel_c20_protocol_switch_valid(struct intel_encoder *encoder)
2820 {
2821 	struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
2822 
2823 	/* banks should not be cleared for DPALT/USB4/TBT modes */
2824 	/* TODO: optimize re-calibration in legacy mode */
2825 	return intel_tc_port_in_legacy_mode(intel_dig_port);
2826 }
2827 
2828 static void intel_c20_pll_program(struct intel_display *display,
2829 				  struct intel_encoder *encoder,
2830 				  const struct intel_c20pll_state *pll_state)
2831 {
2832 	u8 owned_lane_mask = intel_cx0_get_owned_lane_mask(encoder);
2833 	bool cntx;
2834 	int i;
2835 
2836 	/* 1. Read current context selection */
2837 	cntx = intel_cx0_read(encoder, INTEL_CX0_LANE0, PHY_C20_VDR_CUSTOM_SERDES_RATE) &
2838 		PHY_C20_CONTEXT_TOGGLE;
2839 
2840 	/*
2841 	 * 2. If there is a protocol switch from HDMI to DP or vice versa, clear
2842 	 * the lane #0 MPLLB CAL_DONE_BANK DP2.0 10G and 20G rates enable MPLLA.
2843 	 * Protocol switch is only applicable for MPLLA
2844 	 */
2845 	if (intel_c20_protocol_switch_valid(encoder)) {
2846 		for (i = 0; i < 4; i++)
2847 			intel_c20_sram_write(encoder, INTEL_CX0_LANE0, RAWLANEAONX_DIG_TX_MPLLB_CAL_DONE_BANK(i), 0);
2848 		usleep_range(4000, 4100);
2849 	}
2850 
2851 	/* 3. Write SRAM configuration context. If A in use, write configuration to B context */
2852 	/* 3.1 Tx configuration */
2853 	for (i = 0; i < ARRAY_SIZE(pll_state->tx); i++) {
2854 		if (cntx)
2855 			intel_c20_sram_write(encoder, INTEL_CX0_LANE0,
2856 					     PHY_C20_A_TX_CNTX_CFG(display, i),
2857 					     pll_state->tx[i]);
2858 		else
2859 			intel_c20_sram_write(encoder, INTEL_CX0_LANE0,
2860 					     PHY_C20_B_TX_CNTX_CFG(display, i),
2861 					     pll_state->tx[i]);
2862 	}
2863 
2864 	/* 3.2 common configuration */
2865 	for (i = 0; i < ARRAY_SIZE(pll_state->cmn); i++) {
2866 		if (cntx)
2867 			intel_c20_sram_write(encoder, INTEL_CX0_LANE0,
2868 					     PHY_C20_A_CMN_CNTX_CFG(display, i),
2869 					     pll_state->cmn[i]);
2870 		else
2871 			intel_c20_sram_write(encoder, INTEL_CX0_LANE0,
2872 					     PHY_C20_B_CMN_CNTX_CFG(display, i),
2873 					     pll_state->cmn[i]);
2874 	}
2875 
2876 	/* 3.3 mpllb or mplla configuration */
2877 	if (intel_c20phy_use_mpllb(pll_state)) {
2878 		for (i = 0; i < ARRAY_SIZE(pll_state->mpllb); i++) {
2879 			if (cntx)
2880 				intel_c20_sram_write(encoder, INTEL_CX0_LANE0,
2881 						     PHY_C20_A_MPLLB_CNTX_CFG(display, i),
2882 						     pll_state->mpllb[i]);
2883 			else
2884 				intel_c20_sram_write(encoder, INTEL_CX0_LANE0,
2885 						     PHY_C20_B_MPLLB_CNTX_CFG(display, i),
2886 						     pll_state->mpllb[i]);
2887 		}
2888 	} else {
2889 		for (i = 0; i < ARRAY_SIZE(pll_state->mplla); i++) {
2890 			if (cntx)
2891 				intel_c20_sram_write(encoder, INTEL_CX0_LANE0,
2892 						     PHY_C20_A_MPLLA_CNTX_CFG(display, i),
2893 						     pll_state->mplla[i]);
2894 			else
2895 				intel_c20_sram_write(encoder, INTEL_CX0_LANE0,
2896 						     PHY_C20_B_MPLLA_CNTX_CFG(display, i),
2897 						     pll_state->mplla[i]);
2898 		}
2899 	}
2900 
2901 	/*
2902 	 * 4. Program custom width to match the link protocol.
2903 	 * 5. For DP or 6. For HDMI
2904 	 */
2905 	intel_c20_program_vdr_params(encoder, &pll_state->vdr, owned_lane_mask);
2906 
2907 	/*
2908 	 * 7. Write Vendor specific registers to toggle context setting to load
2909 	 * the updated programming toggle context bit
2910 	 */
2911 	intel_cx0_rmw(encoder, owned_lane_mask, PHY_C20_VDR_CUSTOM_SERDES_RATE,
2912 		      PHY_C20_CONTEXT_TOGGLE, cntx ? 0 : PHY_C20_CONTEXT_TOGGLE,
2913 		      MB_WRITE_COMMITTED);
2914 }
2915 
2916 static bool is_mplla_clock_rate(int clock)
2917 {
2918 	return intel_dpll_clock_matches(clock, 1000000) ||
2919 	       intel_dpll_clock_matches(clock, 2000000);
2920 }
2921 
2922 static void intel_program_port_clock_ctl(struct intel_encoder *encoder,
2923 					 const struct intel_cx0pll_state *pll_state,
2924 					 int port_clock,
2925 					 bool lane_reversal)
2926 {
2927 	struct intel_display *display = to_intel_display(encoder);
2928 	bool is_dp = cx0pll_state_is_dp(pll_state);
2929 	u32 val = 0;
2930 
2931 	intel_de_rmw(display, XELPDP_PORT_BUF_CTL1(display, encoder->port),
2932 		     XELPDP_PORT_REVERSAL,
2933 		     lane_reversal ? XELPDP_PORT_REVERSAL : 0);
2934 
2935 	if (lane_reversal)
2936 		val |= XELPDP_LANE1_PHY_CLOCK_SELECT;
2937 
2938 	val |= XELPDP_FORWARD_CLOCK_UNGATE;
2939 
2940 	if (!is_dp && intel_hdmi_is_frl(port_clock))
2941 		val |= XELPDP_DDI_CLOCK_SELECT_PREP(display, XELPDP_DDI_CLOCK_SELECT_DIV18CLK);
2942 	else
2943 		val |= XELPDP_DDI_CLOCK_SELECT_PREP(display, XELPDP_DDI_CLOCK_SELECT_MAXPCLK);
2944 
2945 	/* TODO: HDMI FRL */
2946 	/* DP2.0 10G and 20G rates enable MPLLA*/
2947 	if (is_mplla_clock_rate(port_clock))
2948 		val |= pll_state->ssc_enabled ? XELPDP_SSC_ENABLE_PLLA : 0;
2949 	else
2950 		val |= pll_state->ssc_enabled ? XELPDP_SSC_ENABLE_PLLB : 0;
2951 
2952 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
2953 		     XELPDP_LANE1_PHY_CLOCK_SELECT | XELPDP_FORWARD_CLOCK_UNGATE |
2954 		     XELPDP_DDI_CLOCK_SELECT_MASK(display) | XELPDP_SSC_ENABLE_PLLA |
2955 		     XELPDP_SSC_ENABLE_PLLB, val);
2956 }
2957 
2958 static u32 intel_cx0_get_powerdown_update(u8 lane_mask)
2959 {
2960 	u32 val = 0;
2961 	int lane = 0;
2962 
2963 	for_each_cx0_lane_in_mask(lane_mask, lane)
2964 		val |= XELPDP_LANE_POWERDOWN_UPDATE(lane);
2965 
2966 	return val;
2967 }
2968 
2969 static u32 intel_cx0_get_powerdown_state(u8 lane_mask, u8 state)
2970 {
2971 	u32 val = 0;
2972 	int lane = 0;
2973 
2974 	for_each_cx0_lane_in_mask(lane_mask, lane)
2975 		val |= XELPDP_LANE_POWERDOWN_NEW_STATE(lane, state);
2976 
2977 	return val;
2978 }
2979 
2980 void intel_cx0_powerdown_change_sequence(struct intel_encoder *encoder,
2981 					 u8 lane_mask, u8 state)
2982 {
2983 	struct intel_display *display = to_intel_display(encoder);
2984 	enum port port = encoder->port;
2985 	enum phy phy = intel_encoder_to_phy(encoder);
2986 	intel_reg_t buf_ctl2_reg = XELPDP_PORT_BUF_CTL2(display, port);
2987 	int lane;
2988 
2989 	intel_de_rmw(display, buf_ctl2_reg,
2990 		     intel_cx0_get_powerdown_state(INTEL_CX0_BOTH_LANES, XELPDP_LANE_POWERDOWN_NEW_STATE_MASK),
2991 		     intel_cx0_get_powerdown_state(lane_mask, state));
2992 
2993 	/* Wait for pending transactions.*/
2994 	for_each_cx0_lane_in_mask(lane_mask, lane)
2995 		if (intel_de_wait_for_clear_ms(display, XELPDP_PORT_M2P_MSGBUS_CTL(display, port, lane),
2996 					       XELPDP_PORT_M2P_TRANSACTION_PENDING,
2997 					       XELPDP_MSGBUS_TIMEOUT_MS)) {
2998 			drm_dbg_kms(display->drm,
2999 				    "PHY %c Timeout waiting for previous transaction to complete. Reset the bus.\n",
3000 				    phy_name(phy));
3001 			intel_cx0_bus_reset(encoder, lane);
3002 		}
3003 
3004 	intel_de_rmw(display, buf_ctl2_reg,
3005 		     intel_cx0_get_powerdown_update(INTEL_CX0_BOTH_LANES),
3006 		     intel_cx0_get_powerdown_update(lane_mask));
3007 
3008 	/* Update Timeout Value */
3009 	if (intel_de_wait_for_clear_ms(display, buf_ctl2_reg,
3010 				       intel_cx0_get_powerdown_update(lane_mask),
3011 				       XELPDP_PORT_POWERDOWN_UPDATE_TIMEOUT_MS))
3012 		drm_warn(display->drm,
3013 			 "PHY %c failed to change powerdown state\n",
3014 			 phy_name(phy));
3015 }
3016 
3017 void intel_cx0_setup_powerdown(struct intel_encoder *encoder)
3018 {
3019 	struct intel_display *display = to_intel_display(encoder);
3020 	enum port port = encoder->port;
3021 
3022 	intel_de_rmw(display, XELPDP_PORT_BUF_CTL2(display, port),
3023 		     XELPDP_POWER_STATE_READY_MASK,
3024 		     XELPDP_POWER_STATE_READY(XELPDP_P2_STATE_READY));
3025 	intel_de_rmw(display, XELPDP_PORT_BUF_CTL3(display, port),
3026 		     XELPDP_POWER_STATE_ACTIVE_MASK |
3027 		     XELPDP_PLL_LANE_STAGGERING_DELAY_MASK,
3028 		     XELPDP_POWER_STATE_ACTIVE(XELPDP_P0_STATE_ACTIVE) |
3029 		     XELPDP_PLL_LANE_STAGGERING_DELAY(0));
3030 }
3031 
3032 static u32 intel_cx0_get_pclk_refclk_request(u8 lane_mask)
3033 {
3034 	u32 val = 0;
3035 	int lane = 0;
3036 
3037 	for_each_cx0_lane_in_mask(lane_mask, lane)
3038 		val |= XELPDP_LANE_PCLK_REFCLK_REQUEST(lane);
3039 
3040 	return val;
3041 }
3042 
3043 static u32 intel_cx0_get_pclk_refclk_ack(u8 lane_mask)
3044 {
3045 	u32 val = 0;
3046 	int lane = 0;
3047 
3048 	for_each_cx0_lane_in_mask(lane_mask, lane)
3049 		val |= XELPDP_LANE_PCLK_REFCLK_ACK(lane);
3050 
3051 	return val;
3052 }
3053 
3054 static void intel_cx0_phy_lane_reset(struct intel_encoder *encoder,
3055 				     bool lane_reversal)
3056 {
3057 	struct intel_display *display = to_intel_display(encoder);
3058 	enum port port = encoder->port;
3059 	enum phy phy = intel_encoder_to_phy(encoder);
3060 	u8 owned_lane_mask = intel_cx0_get_owned_lane_mask(encoder);
3061 	u8 lane_mask = lane_reversal ? INTEL_CX0_LANE1 : INTEL_CX0_LANE0;
3062 	u32 lane_pipe_reset = owned_lane_mask == INTEL_CX0_BOTH_LANES
3063 				? XELPDP_LANE_PIPE_RESET(0) | XELPDP_LANE_PIPE_RESET(1)
3064 				: XELPDP_LANE_PIPE_RESET(0);
3065 	u32 lane_phy_current_status = owned_lane_mask == INTEL_CX0_BOTH_LANES
3066 					? (XELPDP_LANE_PHY_CURRENT_STATUS(0) |
3067 					   XELPDP_LANE_PHY_CURRENT_STATUS(1))
3068 					: XELPDP_LANE_PHY_CURRENT_STATUS(0);
3069 
3070 	if (intel_de_wait_for_set_us(display, XELPDP_PORT_BUF_CTL1(display, port),
3071 				     XELPDP_PORT_BUF_SOC_PHY_READY,
3072 				     XELPDP_PORT_BUF_SOC_READY_TIMEOUT_US))
3073 		drm_warn(display->drm,
3074 			 "PHY %c failed to bring out of SOC reset\n",
3075 			 phy_name(phy));
3076 
3077 	intel_de_rmw(display, XELPDP_PORT_BUF_CTL2(display, port), lane_pipe_reset,
3078 		     lane_pipe_reset);
3079 
3080 	if (intel_de_wait_for_set_us(display, XELPDP_PORT_BUF_CTL2(display, port),
3081 				     lane_phy_current_status,
3082 				     XELPDP_PORT_RESET_START_TIMEOUT_US))
3083 		drm_warn(display->drm,
3084 			 "PHY %c failed to bring out of lane reset\n",
3085 			 phy_name(phy));
3086 
3087 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, port),
3088 		     intel_cx0_get_pclk_refclk_request(owned_lane_mask),
3089 		     intel_cx0_get_pclk_refclk_request(lane_mask));
3090 
3091 	if (intel_de_wait_us(display, XELPDP_PORT_CLOCK_CTL(display, port),
3092 			     intel_cx0_get_pclk_refclk_ack(owned_lane_mask),
3093 			     intel_cx0_get_pclk_refclk_ack(lane_mask),
3094 			     XELPDP_REFCLK_ENABLE_TIMEOUT_US, NULL))
3095 		drm_warn(display->drm,
3096 			 "PHY %c failed to request refclk\n",
3097 			 phy_name(phy));
3098 
3099 	intel_cx0_powerdown_change_sequence(encoder, INTEL_CX0_BOTH_LANES,
3100 					    XELPDP_P2_STATE_RESET);
3101 	intel_cx0_setup_powerdown(encoder);
3102 
3103 	intel_de_rmw(display, XELPDP_PORT_BUF_CTL2(display, port), lane_pipe_reset, 0);
3104 
3105 	if (intel_de_wait_for_clear_ms(display, XELPDP_PORT_BUF_CTL2(display, port),
3106 				       lane_phy_current_status,
3107 				       XELPDP_PORT_RESET_END_TIMEOUT_MS))
3108 		drm_warn(display->drm,
3109 			 "PHY %c failed to bring out of lane reset\n",
3110 			 phy_name(phy));
3111 }
3112 
3113 static void intel_cx0_program_phy_lane(struct intel_encoder *encoder, int lane_count,
3114 				       bool lane_reversal)
3115 {
3116 	int i;
3117 	u8 disables;
3118 	bool dp_alt_mode = intel_tc_port_in_dp_alt_mode(enc_to_dig_port(encoder));
3119 	u8 owned_lane_mask = intel_cx0_get_owned_lane_mask(encoder);
3120 
3121 	intel_c10_msgbus_access_begin(encoder, owned_lane_mask);
3122 
3123 	if (lane_reversal)
3124 		disables = REG_GENMASK8(3, 0) >> lane_count;
3125 	else
3126 		disables = REG_GENMASK8(3, 0) << lane_count;
3127 
3128 	if (dp_alt_mode && lane_count == 1) {
3129 		disables &= ~REG_GENMASK8(1, 0);
3130 		disables |= REG_FIELD_PREP8(REG_GENMASK8(1, 0), 0x1);
3131 	}
3132 
3133 	for (i = 0; i < 4; i++) {
3134 		int tx = i % 2 + 1;
3135 		u8 lane_mask = i < 2 ? INTEL_CX0_LANE0 : INTEL_CX0_LANE1;
3136 
3137 		if (!(owned_lane_mask & lane_mask))
3138 			continue;
3139 
3140 		intel_cx0_rmw(encoder, lane_mask, PHY_CX0_TX_CONTROL(tx, 2),
3141 			      CONTROL2_DISABLE_SINGLE_TX,
3142 			      disables & BIT(i) ? CONTROL2_DISABLE_SINGLE_TX : 0,
3143 			      MB_WRITE_COMMITTED);
3144 	}
3145 
3146 	intel_c10_msgbus_access_commit(encoder, owned_lane_mask, false);
3147 }
3148 
3149 static u32 intel_cx0_get_pclk_pll_request(u8 lane_mask)
3150 {
3151 	u32 val = 0;
3152 	int lane = 0;
3153 
3154 	for_each_cx0_lane_in_mask(lane_mask, lane)
3155 		val |= XELPDP_LANE_PCLK_PLL_REQUEST(lane);
3156 
3157 	return val;
3158 }
3159 
3160 static u32 intel_cx0_get_pclk_pll_ack(u8 lane_mask)
3161 {
3162 	u32 val = 0;
3163 	int lane = 0;
3164 
3165 	for_each_cx0_lane_in_mask(lane_mask, lane)
3166 		val |= XELPDP_LANE_PCLK_PLL_ACK(lane);
3167 
3168 	return val;
3169 }
3170 
3171 static void intel_cx0pll_enable(struct intel_encoder *encoder,
3172 				const struct intel_cx0pll_state *pll_state)
3173 {
3174 	struct intel_display *display = to_intel_display(encoder);
3175 	enum phy phy = intel_encoder_to_phy(encoder);
3176 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3177 	bool lane_reversal = dig_port->lane_reversal;
3178 	u8 maxpclk_lane = lane_reversal ? INTEL_CX0_LANE1 :
3179 					  INTEL_CX0_LANE0;
3180 	struct ref_tracker *wakeref = intel_cx0_phy_transaction_begin(encoder);
3181 	int port_clock;
3182 
3183 	if (pll_state->use_c10)
3184 		port_clock = intel_c10pll_calc_port_clock(&pll_state->c10);
3185 	else
3186 		port_clock = intel_c20pll_calc_port_clock(&pll_state->c20);
3187 
3188 	/*
3189 	 * Lane reversal is never used in DP-alt mode, in that case the
3190 	 * corresponding lane swapping (based on the TypeC cable flip state
3191 	 * for instance) is handled automatically by the HW via a TCSS mux.
3192 	 */
3193 	drm_WARN_ON(display->drm, lane_reversal && intel_tc_port_in_dp_alt_mode(dig_port));
3194 
3195 	/*
3196 	 * 1. Program PORT_CLOCK_CTL REGISTER to configure
3197 	 * clock muxes, gating and SSC
3198 	 */
3199 	intel_program_port_clock_ctl(encoder, pll_state, port_clock, lane_reversal);
3200 
3201 	/* 2. Bring PHY out of reset. */
3202 	intel_cx0_phy_lane_reset(encoder, lane_reversal);
3203 
3204 	/*
3205 	 * 3. Change Phy power state to Ready.
3206 	 * TODO: For DP alt mode use only one lane.
3207 	 */
3208 	intel_cx0_powerdown_change_sequence(encoder, INTEL_CX0_BOTH_LANES,
3209 					    XELPDP_P2_STATE_READY);
3210 
3211 	/*
3212 	 * 4. Program PORT_MSGBUS_TIMER register's Message Bus Timer field to 0xA000.
3213 	 *    (This is done inside intel_cx0_phy_transaction_begin(), since we would need
3214 	 *    the right timer thresholds for readouts too.)
3215 	 */
3216 
3217 	/* 5. Program PHY internal PLL internal registers. */
3218 	if (intel_encoder_is_c10phy(encoder))
3219 		intel_c10_pll_program(display, encoder, &pll_state->c10);
3220 	else
3221 		intel_c20_pll_program(display, encoder, &pll_state->c20);
3222 
3223 	/*
3224 	 * 6. Program the enabled and disabled owned PHY lane
3225 	 * transmitters over message bus
3226 	 */
3227 	intel_cx0_program_phy_lane(encoder, pll_state->lane_count, lane_reversal);
3228 
3229 	/*
3230 	 * 7. Follow the Display Voltage Frequency Switching - Sequence
3231 	 * Before Frequency Change. We handle this step in bxt_set_cdclk().
3232 	 */
3233 
3234 	/*
3235 	 * 8. Program DDI_CLK_VALFREQ to match intended DDI
3236 	 * clock frequency.
3237 	 */
3238 	intel_de_write(display, DDI_CLK_VALFREQ(encoder->port),
3239 		       intel_ddi_link_symbol_clock(encoder, port_clock));
3240 
3241 	/*
3242 	 * 9. Set PORT_CLOCK_CTL register PCLK PLL Request
3243 	 * LN<Lane for maxPCLK> to "1" to enable PLL.
3244 	 */
3245 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3246 		     intel_cx0_get_pclk_pll_request(INTEL_CX0_BOTH_LANES),
3247 		     intel_cx0_get_pclk_pll_request(maxpclk_lane));
3248 
3249 	/* 10. Poll on PORT_CLOCK_CTL PCLK PLL Ack LN<Lane for maxPCLK> == "1". */
3250 	if (intel_de_wait_us(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3251 			     intel_cx0_get_pclk_pll_ack(INTEL_CX0_BOTH_LANES),
3252 			     intel_cx0_get_pclk_pll_ack(maxpclk_lane),
3253 			     XELPDP_PCLK_PLL_ENABLE_TIMEOUT_US, NULL))
3254 		drm_warn(display->drm, "Port %c PLL not locked\n",
3255 			 phy_name(phy));
3256 
3257 	/*
3258 	 * 11. Follow the Display Voltage Frequency Switching Sequence After
3259 	 * Frequency Change. We handle this step in bxt_set_cdclk().
3260 	 */
3261 
3262 	/*
3263 	 * 12. Toggle powerdown if HDMI is enabled on C10 PHY.
3264 	 *
3265 	 * Wa_13013502646:
3266 	 * Fixes: HDMI lane to lane skew violations on C10 display PHYs.
3267 	 * Workaround: Toggle powerdown value by setting first to P0 and then to P2, for both
3268 	 * PHY lanes.
3269 	 */
3270 	if (!cx0pll_state_is_dp(pll_state) && pll_state->use_c10) {
3271 		intel_cx0_powerdown_change_sequence(encoder, INTEL_CX0_BOTH_LANES,
3272 						    XELPDP_P0_STATE_ACTIVE);
3273 		intel_cx0_powerdown_change_sequence(encoder, INTEL_CX0_BOTH_LANES,
3274 						    XELPDP_P2_STATE_READY);
3275 	}
3276 
3277 	intel_cx0_phy_transaction_end(encoder, wakeref);
3278 }
3279 
3280 void intel_mtl_tbt_pll_calc_state(struct intel_dpll_hw_state *hw_state)
3281 {
3282 	memset(hw_state, 0, sizeof(*hw_state));
3283 
3284 	hw_state->cx0pll.tbt_mode = true;
3285 }
3286 
3287 bool intel_mtl_tbt_pll_readout_hw_state(struct intel_display *display,
3288 					struct intel_dpll *pll,
3289 					struct intel_dpll_hw_state *hw_state)
3290 {
3291 	memset(hw_state, 0, sizeof(*hw_state));
3292 
3293 	hw_state->cx0pll.tbt_mode = true;
3294 
3295 	return true;
3296 }
3297 
3298 int intel_mtl_tbt_calc_port_clock(struct intel_encoder *encoder)
3299 {
3300 	struct intel_display *display = to_intel_display(encoder);
3301 	u32 clock, val;
3302 
3303 	val = intel_de_read(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port));
3304 
3305 	clock = XELPDP_DDI_CLOCK_SELECT_GET(display, val);
3306 
3307 	drm_WARN_ON(display->drm, !(val & XELPDP_FORWARD_CLOCK_UNGATE));
3308 	drm_WARN_ON(display->drm, !(val & XELPDP_TBT_CLOCK_REQUEST));
3309 	drm_WARN_ON(display->drm, !(val & XELPDP_TBT_CLOCK_ACK));
3310 
3311 	switch (clock) {
3312 	case XELPDP_DDI_CLOCK_SELECT_TBT_162:
3313 		return 162000;
3314 	case XELPDP_DDI_CLOCK_SELECT_TBT_270:
3315 		return 270000;
3316 	case XELPDP_DDI_CLOCK_SELECT_TBT_540:
3317 		return 540000;
3318 	case XELPDP_DDI_CLOCK_SELECT_TBT_810:
3319 		return 810000;
3320 	case XELPDP_DDI_CLOCK_SELECT_TBT_312_5:
3321 		return 1000000;
3322 	case XELPDP_DDI_CLOCK_SELECT_TBT_625:
3323 		return 2000000;
3324 	default:
3325 		MISSING_CASE(clock);
3326 		return 162000;
3327 	}
3328 }
3329 
3330 static int intel_mtl_tbt_clock_select(struct intel_display *display,
3331 				      int clock)
3332 {
3333 	switch (clock) {
3334 	case 162000:
3335 		return XELPDP_DDI_CLOCK_SELECT_TBT_162;
3336 	case 270000:
3337 		return XELPDP_DDI_CLOCK_SELECT_TBT_270;
3338 	case 540000:
3339 		return XELPDP_DDI_CLOCK_SELECT_TBT_540;
3340 	case 810000:
3341 		return XELPDP_DDI_CLOCK_SELECT_TBT_810;
3342 	case 1000000:
3343 		if (DISPLAY_VER(display) < 30) {
3344 			drm_WARN_ON(display->drm, "UHBR10 not supported for the platform\n");
3345 			return XELPDP_DDI_CLOCK_SELECT_TBT_162;
3346 		}
3347 		return XELPDP_DDI_CLOCK_SELECT_TBT_312_5;
3348 	case 2000000:
3349 		if (DISPLAY_VER(display) < 30) {
3350 			drm_WARN_ON(display->drm, "UHBR20 not supported for the platform\n");
3351 			return XELPDP_DDI_CLOCK_SELECT_TBT_162;
3352 		}
3353 		return XELPDP_DDI_CLOCK_SELECT_TBT_625;
3354 	default:
3355 		MISSING_CASE(clock);
3356 		return XELPDP_DDI_CLOCK_SELECT_TBT_162;
3357 	}
3358 }
3359 
3360 void intel_mtl_tbt_pll_enable_clock(struct intel_encoder *encoder, int port_clock)
3361 {
3362 	struct intel_display *display = to_intel_display(encoder);
3363 	enum phy phy = intel_encoder_to_phy(encoder);
3364 	u32 val = 0;
3365 	u32 mask;
3366 
3367 	/*
3368 	 * 1. Program PORT_CLOCK_CTL REGISTER to configure
3369 	 * clock muxes, gating and SSC
3370 	 */
3371 
3372 	mask = XELPDP_DDI_CLOCK_SELECT_MASK(display);
3373 	val |= XELPDP_DDI_CLOCK_SELECT_PREP(display,
3374 					    intel_mtl_tbt_clock_select(display, port_clock));
3375 
3376 	mask |= XELPDP_FORWARD_CLOCK_UNGATE;
3377 	val |= XELPDP_FORWARD_CLOCK_UNGATE;
3378 
3379 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3380 		     mask, val);
3381 
3382 	/* 2. Read back PORT_CLOCK_CTL REGISTER */
3383 	val = intel_de_read(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port));
3384 
3385 	/*
3386 	 * 3. Follow the Display Voltage Frequency Switching - Sequence
3387 	 * Before Frequency Change. We handle this step in bxt_set_cdclk().
3388 	 */
3389 
3390 	/*
3391 	 * 4. Set PORT_CLOCK_CTL register TBT CLOCK Request to "1" to enable PLL.
3392 	 */
3393 	val |= XELPDP_TBT_CLOCK_REQUEST;
3394 	intel_de_write(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port), val);
3395 
3396 	/* 5. Poll on PORT_CLOCK_CTL TBT CLOCK Ack == "1". */
3397 	if (intel_de_wait_for_set_us(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3398 				     XELPDP_TBT_CLOCK_ACK, 100))
3399 		drm_warn(display->drm, "[ENCODER:%d:%s][%c] PHY PLL not locked\n",
3400 			 encoder->base.base.id, encoder->base.name, phy_name(phy));
3401 
3402 	/*
3403 	 * 6. Follow the Display Voltage Frequency Switching Sequence After
3404 	 * Frequency Change. We handle this step in bxt_set_cdclk().
3405 	 */
3406 
3407 	/*
3408 	 * 7. Program DDI_CLK_VALFREQ to match intended DDI
3409 	 * clock frequency.
3410 	 */
3411 	intel_de_write(display, DDI_CLK_VALFREQ(encoder->port),
3412 		       intel_ddi_link_symbol_clock(encoder, port_clock));
3413 }
3414 
3415 void intel_mtl_pll_enable(struct intel_encoder *encoder,
3416 			  struct intel_dpll *pll,
3417 			  const struct intel_dpll_hw_state *dpll_hw_state)
3418 {
3419 	intel_cx0pll_enable(encoder, &dpll_hw_state->cx0pll);
3420 }
3421 
3422 void intel_mtl_pll_enable_clock(struct intel_encoder *encoder,
3423 				const struct intel_crtc_state *crtc_state)
3424 {
3425 	struct intel_display *display = to_intel_display(encoder);
3426 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3427 
3428 	if (intel_tc_port_in_tbt_alt_mode(dig_port))
3429 		intel_mtl_tbt_pll_enable_clock(encoder, crtc_state->port_clock);
3430 
3431 	/*
3432 	 * CMTG can be enabled only when the transcoder and port are compatible
3433 	 * (transcoder A with port A, transcoder B with port B).
3434 	 */
3435 	if (HAS_LT_PHY(display) &&
3436 	    ((crtc_state->cpu_transcoder == TRANSCODER_A && encoder->port == PORT_A) ||
3437 	     (crtc_state->cpu_transcoder == TRANSCODER_B && encoder->port == PORT_B)))
3438 		intel_cmtg_set_clk_select(crtc_state);
3439 }
3440 
3441 /*
3442  * According to HAS we need to enable MAC Transmitting LFPS in the "PHY Common
3443  * Control 0" PIPE register in case of AUX Less ALPM is going to be used. This
3444  * function is doing that and is called by link retrain sequence.
3445  */
3446 void intel_lnl_mac_transmit_lfps(struct intel_encoder *encoder,
3447 				 const struct intel_crtc_state *crtc_state)
3448 {
3449 	struct intel_display *display = to_intel_display(encoder);
3450 	struct ref_tracker *wakeref;
3451 	int i;
3452 	u8 owned_lane_mask;
3453 
3454 	if (DISPLAY_VER(display) < 20 ||
3455 	    !intel_alpm_is_alpm_aux_less(enc_to_intel_dp(encoder), crtc_state))
3456 		return;
3457 
3458 	owned_lane_mask = intel_cx0_get_owned_lane_mask(encoder);
3459 
3460 	wakeref = intel_cx0_phy_transaction_begin(encoder);
3461 
3462 	intel_c10_msgbus_access_begin(encoder, owned_lane_mask);
3463 
3464 	for (i = 0; i < 4; i++) {
3465 		int tx = i % 2 + 1;
3466 		u8 lane_mask = i < 2 ? INTEL_CX0_LANE0 : INTEL_CX0_LANE1;
3467 
3468 		if (!(owned_lane_mask & lane_mask))
3469 			continue;
3470 
3471 		intel_cx0_rmw(encoder, lane_mask, PHY_CMN1_CONTROL(tx, 0),
3472 			      CONTROL0_MAC_TRANSMIT_LFPS,
3473 			      CONTROL0_MAC_TRANSMIT_LFPS, MB_WRITE_COMMITTED);
3474 	}
3475 
3476 	intel_cx0_phy_transaction_end(encoder, wakeref);
3477 }
3478 
3479 static u8 cx0_power_control_disable_val(struct intel_encoder *encoder)
3480 {
3481 	struct intel_display *display = to_intel_display(encoder);
3482 
3483 	if (intel_encoder_is_c10phy(encoder))
3484 		return XELPDP_P2PG_STATE_DISABLE;
3485 
3486 	if ((display->platform.battlemage && encoder->port == PORT_A) ||
3487 	    (DISPLAY_VER(display) >= 30 && encoder->type == INTEL_OUTPUT_EDP))
3488 		return XELPDP_P2PG_STATE_DISABLE;
3489 
3490 	return XELPDP_P4PG_STATE_DISABLE;
3491 }
3492 
3493 static void intel_cx0pll_disable(struct intel_encoder *encoder)
3494 {
3495 	struct intel_display *display = to_intel_display(encoder);
3496 	enum phy phy = intel_encoder_to_phy(encoder);
3497 	struct ref_tracker *wakeref = intel_cx0_phy_transaction_begin(encoder);
3498 
3499 	/* 1. Change owned PHY lane power to Disable state. */
3500 	intel_cx0_powerdown_change_sequence(encoder, INTEL_CX0_BOTH_LANES,
3501 					    cx0_power_control_disable_val(encoder));
3502 
3503 	/*
3504 	 * 2. Follow the Display Voltage Frequency Switching Sequence Before
3505 	 * Frequency Change. We handle this step in bxt_set_cdclk().
3506 	 */
3507 
3508 	/*
3509 	 * 3. Set PORT_CLOCK_CTL register PCLK PLL Request LN<Lane for maxPCLK>
3510 	 * to "0" to disable PLL.
3511 	 */
3512 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3513 		     intel_cx0_get_pclk_pll_request(INTEL_CX0_BOTH_LANES) |
3514 		     intel_cx0_get_pclk_refclk_request(INTEL_CX0_BOTH_LANES), 0);
3515 
3516 	/* 4. Program DDI_CLK_VALFREQ to 0. */
3517 	intel_de_write(display, DDI_CLK_VALFREQ(encoder->port), 0);
3518 
3519 	/*
3520 	 * 5. Poll on PORT_CLOCK_CTL PCLK PLL Ack LN<Lane for maxPCLK**> == "0".
3521 	 */
3522 	if (intel_de_wait_for_clear_us(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3523 				       intel_cx0_get_pclk_pll_ack(INTEL_CX0_BOTH_LANES) |
3524 				       intel_cx0_get_pclk_refclk_ack(INTEL_CX0_BOTH_LANES),
3525 				       XELPDP_PCLK_PLL_DISABLE_TIMEOUT_US))
3526 		drm_warn(display->drm, "Port %c PLL not unlocked\n",
3527 			 phy_name(phy));
3528 
3529 	/*
3530 	 * 6. Follow the Display Voltage Frequency Switching Sequence After
3531 	 * Frequency Change. We handle this step in bxt_set_cdclk().
3532 	 */
3533 
3534 	/* 7. Program PORT_CLOCK_CTL register to disable and gate clocks. */
3535 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3536 		     XELPDP_DDI_CLOCK_SELECT_MASK(display), 0);
3537 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3538 		     XELPDP_FORWARD_CLOCK_UNGATE, 0);
3539 
3540 	intel_cx0_phy_transaction_end(encoder, wakeref);
3541 }
3542 
3543 static bool intel_cx0_pll_is_enabled(struct intel_encoder *encoder)
3544 {
3545 	struct intel_display *display = to_intel_display(encoder);
3546 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3547 	u8 lane = dig_port->lane_reversal ? INTEL_CX0_LANE1 : INTEL_CX0_LANE0;
3548 
3549 	return intel_de_read(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port)) &
3550 			     intel_cx0_get_pclk_pll_request(lane);
3551 }
3552 
3553 void intel_mtl_tbt_pll_disable_clock(struct intel_encoder *encoder)
3554 {
3555 	struct intel_display *display = to_intel_display(encoder);
3556 	enum phy phy = intel_encoder_to_phy(encoder);
3557 
3558 	/*
3559 	 * 1. Follow the Display Voltage Frequency Switching Sequence Before
3560 	 * Frequency Change. We handle this step in bxt_set_cdclk().
3561 	 */
3562 
3563 	/*
3564 	 * 2. Set PORT_CLOCK_CTL register TBT CLOCK Request to "0" to disable PLL.
3565 	 */
3566 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3567 		     XELPDP_TBT_CLOCK_REQUEST, 0);
3568 
3569 	/* 3. Poll on PORT_CLOCK_CTL TBT CLOCK Ack == "0". */
3570 	if (intel_de_wait_for_clear_us(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3571 				       XELPDP_TBT_CLOCK_ACK, 10))
3572 		drm_warn(display->drm, "[ENCODER:%d:%s][%c] PHY PLL not unlocked\n",
3573 			 encoder->base.base.id, encoder->base.name, phy_name(phy));
3574 
3575 	/*
3576 	 * 4. Follow the Display Voltage Frequency Switching Sequence After
3577 	 * Frequency Change. We handle this step in bxt_set_cdclk().
3578 	 */
3579 
3580 	/*
3581 	 * 5. Program PORT CLOCK CTRL register to disable and gate clocks
3582 	 */
3583 	intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port),
3584 		     XELPDP_DDI_CLOCK_SELECT_MASK(display) |
3585 		     XELPDP_FORWARD_CLOCK_UNGATE, 0);
3586 
3587 	/* 6. Program DDI_CLK_VALFREQ to 0. */
3588 	intel_de_write(display, DDI_CLK_VALFREQ(encoder->port), 0);
3589 }
3590 
3591 void intel_mtl_pll_disable(struct intel_encoder *encoder)
3592 {
3593 	intel_cx0pll_disable(encoder);
3594 }
3595 
3596 void intel_mtl_pll_disable_clock(struct intel_encoder *encoder)
3597 {
3598 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3599 
3600 	if (intel_tc_port_in_tbt_alt_mode(dig_port))
3601 		intel_mtl_tbt_pll_disable_clock(encoder);
3602 }
3603 
3604 enum icl_port_dpll_id
3605 intel_mtl_port_pll_type(struct intel_encoder *encoder,
3606 			const struct intel_crtc_state *crtc_state)
3607 {
3608 	struct intel_display *display = to_intel_display(encoder);
3609 	u32 val, clock;
3610 
3611 	/*
3612 	 * TODO: Determine the PLL type from the SW state, once MTL PLL
3613 	 * handling is done via the standard shared DPLL framework.
3614 	 */
3615 	val = intel_de_read(display, XELPDP_PORT_CLOCK_CTL(display, encoder->port));
3616 	clock = XELPDP_DDI_CLOCK_SELECT_GET(display, val);
3617 
3618 	if (clock == XELPDP_DDI_CLOCK_SELECT_MAXPCLK ||
3619 	    clock == XELPDP_DDI_CLOCK_SELECT_DIV18CLK)
3620 		return ICL_PORT_DPLL_MG_PHY;
3621 	else
3622 		return ICL_PORT_DPLL_DEFAULT;
3623 }
3624 
3625 bool intel_cx0pll_readout_hw_state(struct intel_encoder *encoder,
3626 				   struct intel_cx0pll_state *pll_state)
3627 {
3628 	memset(pll_state, 0, sizeof(*pll_state));
3629 
3630 	if (!intel_cx0_pll_is_enabled(encoder))
3631 		return false;
3632 
3633 	if (intel_encoder_is_c10phy(encoder))
3634 		intel_c10pll_readout_hw_state(encoder, pll_state);
3635 	else
3636 		intel_c20pll_readout_hw_state(encoder, pll_state);
3637 
3638 	return true;
3639 }
3640 
3641 static bool mtl_compare_hw_state_c10(const struct intel_c10pll_state *a,
3642 				     const struct intel_c10pll_state *b)
3643 {
3644 	if (a->tx != b->tx)
3645 		return false;
3646 
3647 	if (a->cmn != b->cmn)
3648 		return false;
3649 
3650 	if (memcmp(&a->pll, &b->pll, sizeof(a->pll)) != 0)
3651 		return false;
3652 
3653 	return true;
3654 }
3655 
3656 static bool mtl_compare_hw_state_c20(const struct intel_c20pll_state *a,
3657 				     const struct intel_c20pll_state *b)
3658 {
3659 	if (memcmp(&a->tx, &b->tx, sizeof(a->tx)) != 0)
3660 		return false;
3661 
3662 	if (memcmp(&a->cmn, &b->cmn, sizeof(a->cmn)) != 0)
3663 		return false;
3664 
3665 	if (a->tx[0] & C20_PHY_USE_MPLLB) {
3666 		if (memcmp(&a->mpllb, &b->mpllb, sizeof(a->mpllb)) != 0)
3667 			return false;
3668 	} else {
3669 		if (memcmp(&a->mplla, &b->mplla, sizeof(a->mplla)) != 0)
3670 			return false;
3671 	}
3672 
3673 	return true;
3674 }
3675 
3676 bool intel_cx0pll_compare_hw_state(const struct intel_cx0pll_state *a,
3677 				   const struct intel_cx0pll_state *b)
3678 {
3679 	if (a->tbt_mode || b->tbt_mode)
3680 		return true;
3681 
3682 	if (a->use_c10 != b->use_c10)
3683 		return false;
3684 
3685 	if (a->use_c10)
3686 		return mtl_compare_hw_state_c10(&a->c10,
3687 						&b->c10);
3688 	else
3689 		return mtl_compare_hw_state_c20(&a->c20,
3690 						&b->c20);
3691 }
3692 
3693 int intel_cx0pll_calc_port_clock(struct intel_encoder *encoder,
3694 				 const struct intel_cx0pll_state *pll_state)
3695 {
3696 	if (intel_encoder_is_c10phy(encoder))
3697 		return intel_c10pll_calc_port_clock(&pll_state->c10);
3698 
3699 	return intel_c20pll_calc_port_clock(&pll_state->c20);
3700 }
3701 
3702 /*
3703  * WA 14022081154
3704  * The dedicated display PHYs reset to a power state that blocks S0ix, increasing idle
3705  * system power. After a system reset (cold boot, S3/4/5, warm reset) if a dedicated
3706  * PHY is not being brought up shortly, use these steps to move the PHY to the lowest
3707  * power state to save power. For PTL the workaround is needed only for port A. Port B
3708  * is not connected.
3709  *
3710  * 1. Follow the PLL Enable Sequence, using any valid frequency such as DP 1.62 GHz.
3711  *    This brings lanes out of reset and enables the PLL to allow powerdown to be moved
3712  *    to the Disable state.
3713  * 2. Follow PLL Disable Sequence. This moves powerdown to the Disable state and disables the PLL.
3714  */
3715 void intel_cx0_pll_power_save_wa(struct intel_display *display)
3716 {
3717 	struct intel_encoder *encoder;
3718 
3719 	if (DISPLAY_VER(display) != 30)
3720 		return;
3721 
3722 	for_each_intel_encoder(display->drm, encoder) {
3723 		struct intel_cx0pll_state pll_state = {};
3724 		int port_clock = 162000;
3725 		int lane_count = 4;
3726 
3727 		if (!intel_encoder_is_dig_port(encoder))
3728 			continue;
3729 
3730 		if (!intel_encoder_is_c10phy(encoder))
3731 			continue;
3732 
3733 		if (intel_cx0_pll_is_enabled(encoder))
3734 			continue;
3735 
3736 		if (intel_c10pll_calc_state_from_table(encoder,
3737 						       mtl_c10_edp_tables,
3738 						       true, port_clock, lane_count,
3739 						       &pll_state) < 0) {
3740 			drm_WARN_ON(display->drm,
3741 				    "Unable to calc C10 state from the tables\n");
3742 			continue;
3743 		}
3744 
3745 		drm_dbg_kms(display->drm,
3746 			    "[ENCODER:%d:%s] Applying power saving workaround on disabled PLL\n",
3747 			    encoder->base.base.id, encoder->base.name);
3748 
3749 		intel_cx0pll_enable(encoder, &pll_state);
3750 		intel_cx0pll_disable(encoder);
3751 	}
3752 }
3753 
3754 static void intel_c10pll_verify_clock(struct intel_display *display,
3755 				      int precomputed_clock,
3756 				      const char *pll_state_name,
3757 				      const struct intel_c10pll_state *pll_state,
3758 				      bool is_precomputed_state)
3759 {
3760 	struct drm_printer p;
3761 	int clock;
3762 
3763 	clock = intel_c10pll_calc_port_clock(pll_state);
3764 
3765 	if (intel_dpll_clock_matches(clock, precomputed_clock))
3766 		return;
3767 
3768 	drm_warn(display->drm,
3769 		 "PLL state %s (%s): clock difference too high: computed %d, pre-computed %d\n",
3770 		 pll_state_name,
3771 		 is_precomputed_state ? "precomputed" : "computed",
3772 		 clock, precomputed_clock);
3773 
3774 	if (!drm_debug_enabled(DRM_UT_KMS))
3775 		return;
3776 
3777 	p = drm_dbg_printer(display->drm, DRM_UT_KMS, NULL);
3778 
3779 	drm_printf(&p, "PLL state %s (%s):\n",
3780 		   pll_state_name,
3781 		   is_precomputed_state ? "precomputed" : "computed");
3782 	intel_c10pll_dump_hw_state(&p, pll_state);
3783 }
3784 
3785 static void intel_c10pll_verify_params(struct intel_display *display,
3786 				       const struct intel_cx0pll_params *pll_params)
3787 {
3788 	struct intel_c10pll_state pll_state;
3789 
3790 	intel_c10pll_verify_clock(display, pll_params->clock_rate, pll_params->name, pll_params->c10, true);
3791 
3792 	if (!pll_params->is_hdmi)
3793 		return;
3794 
3795 	intel_snps_hdmi_pll_compute_c10pll(&pll_state, pll_params->clock_rate);
3796 
3797 	intel_c10pll_verify_clock(display, pll_params->clock_rate, pll_params->name, &pll_state, false);
3798 }
3799 
3800 static void intel_c20pll_verify_clock(struct intel_display *display,
3801 				      int precomputed_clock,
3802 				      const char *pll_state_name,
3803 				      const struct intel_c20pll_state *pll_state,
3804 				      bool is_precomputed_state)
3805 {
3806 	struct drm_printer p;
3807 	int clock;
3808 
3809 	clock = intel_c20pll_calc_port_clock(pll_state);
3810 
3811 	if (intel_dpll_clock_matches(clock, precomputed_clock))
3812 		return;
3813 
3814 	drm_warn(display->drm,
3815 		 "PLL state %s (%s): clock difference too high: computed %d, pre-computed %d\n",
3816 		 pll_state_name,
3817 		 is_precomputed_state ? "precomputed" : "computed",
3818 		 clock, precomputed_clock);
3819 
3820 	if (!drm_debug_enabled(DRM_UT_KMS))
3821 		return;
3822 
3823 	p = drm_dbg_printer(display->drm, DRM_UT_KMS, NULL);
3824 
3825 	drm_printf(&p, "PLL state %s (%s):\n",
3826 		   pll_state_name,
3827 		   is_precomputed_state ? "precomputed" : "computed");
3828 	intel_c20pll_dump_hw_state(&p, pll_state);
3829 }
3830 
3831 static void intel_c20pll_verify_params(struct intel_display *display,
3832 				       const struct intel_cx0pll_params *pll_params)
3833 {
3834 	struct intel_c20pll_state pll_state;
3835 
3836 	intel_c20pll_verify_clock(display, pll_params->clock_rate, pll_params->name, pll_params->c20, true);
3837 
3838 	if (!pll_params->is_hdmi)
3839 		return;
3840 
3841 	if (intel_c20_compute_hdmi_tmds_pll(display, pll_params->clock_rate, &pll_state) != 0)
3842 		return;
3843 
3844 	intel_c20pll_verify_clock(display, pll_params->clock_rate, pll_params->name, &pll_state, false);
3845 }
3846 
3847 static void intel_cx0pll_verify_tables(struct intel_display *display,
3848 				       const struct intel_cx0pll_params *tables)
3849 {
3850 	int i;
3851 
3852 	for (i = 0; tables[i].name; i++) {
3853 		if (tables[i].is_c10)
3854 			intel_c10pll_verify_params(display, &tables[i]);
3855 		else
3856 			intel_c20pll_verify_params(display, &tables[i]);
3857 	}
3858 }
3859 
3860 void intel_cx0pll_verify_plls(struct intel_display *display)
3861 {
3862 	/* C10 */
3863 	intel_cx0pll_verify_tables(display, mtl_c10_edp_tables);
3864 	intel_cx0pll_verify_tables(display, mtl_c10_dp_tables);
3865 	intel_cx0pll_verify_tables(display, mtl_c10_hdmi_tables);
3866 
3867 	/* C20 */
3868 	intel_cx0pll_verify_tables(display, xe2hpd_c20_edp_tables);
3869 	intel_cx0pll_verify_tables(display, mtl_c20_dp_tables);
3870 	intel_cx0pll_verify_tables(display, xe2hpd_c20_dp_tables);
3871 	intel_cx0pll_verify_tables(display, xe3lpd_c20_dp_edp_tables);
3872 	intel_cx0pll_verify_tables(display, mtl_c20_hdmi_tables);
3873 }
3874