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