xref: /linux/sound/hda/codecs/hdmi/intelhdmi.c (revision 21ef2d065ad3f0cfbf2ae51260bf962a9fa2c643)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Intel HDMI codec support
4  */
5 
6 #include <linux/init.h>
7 #include <linux/slab.h>
8 #include <linux/module.h>
9 #include <sound/core.h>
10 #include <sound/hdaudio.h>
11 #include <sound/hda_i915.h>
12 #include <sound/hda_codec.h>
13 #include "hda_local.h"
14 #include "hdmi_local.h"
15 
16 static bool enable_silent_stream =
17 IS_ENABLED(CONFIG_SND_HDA_INTEL_HDMI_SILENT_STREAM);
18 module_param(enable_silent_stream, bool, 0644);
19 MODULE_PARM_DESC(enable_silent_stream, "Enable Silent Stream for HDMI devices");
20 
21 enum {
22 	MODEL_HSW,
23 	MODEL_GLK,
24 	MODEL_ICL,
25 	MODEL_TGL,
26 	MODEL_ADLP,
27 	MODEL_BYT,
28 	MODEL_CPT,
29 };
30 
31 #define INTEL_GET_VENDOR_VERB	0xf81
32 #define INTEL_SET_VENDOR_VERB	0x781
33 #define INTEL_EN_DP12		0x02	/* enable DP 1.2 features */
34 #define INTEL_EN_ALL_PIN_CVTS	0x01	/* enable 2nd & 3rd pins and convertors */
35 
36 static void intel_haswell_enable_all_pins(struct hda_codec *codec,
37 					  bool update_tree)
38 {
39 	unsigned int vendor_param;
40 	struct hdmi_spec *spec = codec->spec;
41 
42 	vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
43 				INTEL_GET_VENDOR_VERB, 0);
44 	if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
45 		return;
46 
47 	vendor_param |= INTEL_EN_ALL_PIN_CVTS;
48 	vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
49 				INTEL_SET_VENDOR_VERB, vendor_param);
50 	if (vendor_param == -1)
51 		return;
52 
53 	if (update_tree)
54 		snd_hda_codec_update_widgets(codec);
55 }
56 
57 static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
58 {
59 	unsigned int vendor_param;
60 	struct hdmi_spec *spec = codec->spec;
61 
62 	vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
63 				INTEL_GET_VENDOR_VERB, 0);
64 	if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
65 		return;
66 
67 	/* enable DP1.2 mode */
68 	vendor_param |= INTEL_EN_DP12;
69 	snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
70 	snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
71 				INTEL_SET_VENDOR_VERB, vendor_param);
72 }
73 
74 /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
75  * Otherwise you may get severe h/w communication errors.
76  */
77 static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
78 				unsigned int power_state)
79 {
80 	/* check codec->spec: it can be called before the probe gets called */
81 	if (codec->spec) {
82 		if (power_state == AC_PWRST_D0) {
83 			intel_haswell_enable_all_pins(codec, false);
84 			intel_haswell_fixup_enable_dp12(codec);
85 		}
86 	}
87 
88 	snd_hda_codec_write_sync(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
89 	snd_hda_codec_set_power_to_all(codec, fg, power_state);
90 }
91 
92 /* There is a fixed mapping between audio pin node and display port.
93  * on SNB, IVY, HSW, BSW, SKL, BXT, KBL:
94  * Pin Widget 5 - PORT B (port = 1 in i915 driver)
95  * Pin Widget 6 - PORT C (port = 2 in i915 driver)
96  * Pin Widget 7 - PORT D (port = 3 in i915 driver)
97  *
98  * on VLV, ILK:
99  * Pin Widget 4 - PORT B (port = 1 in i915 driver)
100  * Pin Widget 5 - PORT C (port = 2 in i915 driver)
101  * Pin Widget 6 - PORT D (port = 3 in i915 driver)
102  */
103 static int intel_base_nid(struct hda_codec *codec)
104 {
105 	switch (codec->core.vendor_id) {
106 	case 0x80860054: /* ILK */
107 	case 0x80862804: /* ILK */
108 	case 0x80862882: /* VLV */
109 		return 4;
110 	default:
111 		return 5;
112 	}
113 }
114 
115 static int intel_pin2port(void *audio_ptr, int pin_nid)
116 {
117 	struct hda_codec *codec = audio_ptr;
118 	struct hdmi_spec *spec = codec->spec;
119 	int base_nid, i;
120 
121 	if (!spec->port_num) {
122 		base_nid = intel_base_nid(codec);
123 		if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3))
124 			return -1;
125 		return pin_nid - base_nid + 1;
126 	}
127 
128 	/*
129 	 * looking for the pin number in the mapping table and return
130 	 * the index which indicate the port number
131 	 */
132 	for (i = 0; i < spec->port_num; i++) {
133 		if (pin_nid == spec->port_map[i])
134 			return i;
135 	}
136 
137 	codec_info(codec, "Can't find the HDMI/DP port for pin NID 0x%x\n", pin_nid);
138 	return -1;
139 }
140 
141 static int intel_port2pin(struct hda_codec *codec, int port)
142 {
143 	struct hdmi_spec *spec = codec->spec;
144 
145 	if (!spec->port_num) {
146 		/* we assume only from port-B to port-D */
147 		if (port < 1 || port > 3)
148 			return 0;
149 		return port + intel_base_nid(codec) - 1;
150 	}
151 
152 	if (port < 0 || port >= spec->port_num)
153 		return 0;
154 	return spec->port_map[port];
155 }
156 
157 static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
158 {
159 	struct hda_codec *codec = audio_ptr;
160 	int pin_nid;
161 	int dev_id = pipe;
162 
163 	pin_nid = intel_port2pin(codec, port);
164 	if (!pin_nid)
165 		return;
166 	/* skip notification during system suspend (but not in runtime PM);
167 	 * the state will be updated at resume
168 	 */
169 	if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
170 		return;
171 
172 	snd_hdac_i915_set_bclk(&codec->bus->core);
173 	snd_hda_hdmi_check_presence_and_report(codec, pin_nid, dev_id);
174 }
175 
176 static const struct drm_audio_component_audio_ops intel_audio_ops = {
177 	.pin2port = intel_pin2port,
178 	.pin_eld_notify = intel_pin_eld_notify,
179 };
180 
181 /* register i915 component pin_eld_notify callback */
182 static void register_i915_notifier(struct hda_codec *codec)
183 {
184 	struct hdmi_spec *spec = codec->spec;
185 
186 	spec->use_acomp_notifier = true;
187 	spec->port2pin = intel_port2pin;
188 	snd_hda_hdmi_setup_drm_audio_ops(codec, &intel_audio_ops);
189 	snd_hdac_acomp_register_notifier(&codec->bus->core,
190 					&spec->drm_audio_ops);
191 	/* no need for forcible resume for jack check thanks to notifier */
192 	codec->relaxed_resume = 1;
193 }
194 
195 #define I915_SILENT_RATE		48000
196 #define I915_SILENT_CHANNELS		2
197 #define I915_SILENT_FORMAT_BITS	16
198 #define I915_SILENT_FMT_MASK		0xf
199 
200 static void silent_stream_enable_i915(struct hda_codec *codec,
201 				      struct hdmi_spec_per_pin *per_pin)
202 {
203 	unsigned int format;
204 
205 	snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
206 				 per_pin->dev_id, I915_SILENT_RATE);
207 
208 	/* trigger silent stream generation in hw */
209 	format = snd_hdac_stream_format(I915_SILENT_CHANNELS, I915_SILENT_FORMAT_BITS,
210 					I915_SILENT_RATE);
211 	snd_hda_codec_setup_stream(codec, per_pin->cvt_nid,
212 				   I915_SILENT_FMT_MASK, I915_SILENT_FMT_MASK, format);
213 	usleep_range(100, 200);
214 	snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, I915_SILENT_FMT_MASK, 0, format);
215 
216 	per_pin->channels = I915_SILENT_CHANNELS;
217 	snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
218 }
219 
220 static void silent_stream_set_kae(struct hda_codec *codec,
221 				  struct hdmi_spec_per_pin *per_pin,
222 				  bool enable)
223 {
224 	unsigned int param;
225 
226 	codec_dbg(codec, "HDMI: KAE %d cvt-NID=0x%x\n", enable, per_pin->cvt_nid);
227 
228 	param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0);
229 	param = (param >> 16) & 0xff;
230 
231 	if (enable)
232 		param |= AC_DIG3_KAE;
233 	else
234 		param &= ~AC_DIG3_KAE;
235 
236 	snd_hda_codec_write(codec, per_pin->cvt_nid, 0, AC_VERB_SET_DIGI_CONVERT_3, param);
237 }
238 
239 static void i915_set_silent_stream(struct hda_codec *codec,
240 				   struct hdmi_spec_per_pin *per_pin,
241 				   bool enable)
242 {
243 	struct hdmi_spec *spec = codec->spec;
244 
245 	switch (spec->silent_stream_type) {
246 	case SILENT_STREAM_KAE:
247 		if (enable) {
248 			silent_stream_enable_i915(codec, per_pin);
249 			silent_stream_set_kae(codec, per_pin, true);
250 		} else {
251 			silent_stream_set_kae(codec, per_pin, false);
252 		}
253 		break;
254 	case SILENT_STREAM_I915:
255 		if (enable) {
256 			silent_stream_enable_i915(codec, per_pin);
257 			snd_hda_power_up_pm(codec);
258 		} else {
259 			/* release ref taken in silent_stream_enable() */
260 			snd_hda_power_down_pm(codec);
261 		}
262 		break;
263 	default:
264 		break;
265 	}
266 }
267 
268 static void haswell_verify_D0(struct hda_codec *codec,
269 			      hda_nid_t cvt_nid, hda_nid_t nid)
270 {
271 	int pwr;
272 
273 	/* For Haswell, the converter 1/2 may keep in D3 state after bootup,
274 	 * thus pins could only choose converter 0 for use. Make sure the
275 	 * converters are in correct power state
276 	 */
277 	if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
278 		snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
279 
280 	if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
281 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
282 				    AC_PWRST_D0);
283 		msleep(40);
284 		pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
285 		pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
286 		codec_dbg(codec, "Haswell HDMI audio: Power for NID 0x%x is now D%d\n", nid, pwr);
287 	}
288 }
289 
290 /* Assure the pin select the right convetor */
291 static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
292 			struct hdmi_spec_per_pin *per_pin)
293 {
294 	hda_nid_t pin_nid = per_pin->pin_nid;
295 	int mux_idx, curr;
296 
297 	mux_idx = per_pin->mux_idx;
298 	curr = snd_hda_codec_read(codec, pin_nid, 0,
299 					  AC_VERB_GET_CONNECT_SEL, 0);
300 	if (curr != mux_idx)
301 		snd_hda_codec_write_cache(codec, pin_nid, 0,
302 					    AC_VERB_SET_CONNECT_SEL,
303 					    mux_idx);
304 }
305 
306 /* get the mux index for the converter of the pins
307  * converter's mux index is the same for all pins on Intel platform
308  */
309 static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
310 			hda_nid_t cvt_nid)
311 {
312 	int i;
313 
314 	for (i = 0; i < spec->num_cvts; i++)
315 		if (spec->cvt_nids[i] == cvt_nid)
316 			return i;
317 	return -EINVAL;
318 }
319 
320 /* Intel HDMI workaround to fix audio routing issue:
321  * For some Intel display codecs, pins share the same connection list.
322  * So a conveter can be selected by multiple pins and playback on any of these
323  * pins will generate sound on the external display, because audio flows from
324  * the same converter to the display pipeline. Also muting one pin may make
325  * other pins have no sound output.
326  * So this function assures that an assigned converter for a pin is not selected
327  * by any other pins.
328  */
329 static void intel_not_share_assigned_cvt(struct hda_codec *codec,
330 					 hda_nid_t pin_nid,
331 					 int dev_id, int mux_idx)
332 {
333 	struct hdmi_spec *spec = codec->spec;
334 	hda_nid_t nid;
335 	int cvt_idx, curr;
336 	struct hdmi_spec_per_cvt *per_cvt;
337 	struct hdmi_spec_per_pin *per_pin;
338 	int pin_idx;
339 
340 	/* configure the pins connections */
341 	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
342 		int dev_id_saved;
343 		int dev_num;
344 
345 		per_pin = get_pin(spec, pin_idx);
346 		/*
347 		 * pin not connected to monitor
348 		 * no need to operate on it
349 		 */
350 		if (!per_pin->pcm)
351 			continue;
352 
353 		if ((per_pin->pin_nid == pin_nid) &&
354 			(per_pin->dev_id == dev_id))
355 			continue;
356 
357 		/*
358 		 * if per_pin->dev_id >= dev_num,
359 		 * snd_hda_get_dev_select() will fail,
360 		 * and the following operation is unpredictable.
361 		 * So skip this situation.
362 		 */
363 		dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
364 		if (per_pin->dev_id >= dev_num)
365 			continue;
366 
367 		nid = per_pin->pin_nid;
368 
369 		/*
370 		 * Calling this function should not impact
371 		 * on the device entry selection
372 		 * So let's save the dev id for each pin,
373 		 * and restore it when return
374 		 */
375 		dev_id_saved = snd_hda_get_dev_select(codec, nid);
376 		snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
377 		curr = snd_hda_codec_read(codec, nid, 0,
378 					  AC_VERB_GET_CONNECT_SEL, 0);
379 		if (curr != mux_idx) {
380 			snd_hda_set_dev_select(codec, nid, dev_id_saved);
381 			continue;
382 		}
383 
384 
385 		/* choose an unassigned converter. The conveters in the
386 		 * connection list are in the same order as in the codec.
387 		 */
388 		for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
389 			per_cvt = get_cvt(spec, cvt_idx);
390 			if (!per_cvt->assigned) {
391 				codec_dbg(codec,
392 					  "choose cvt %d for pin NID 0x%x\n",
393 					  cvt_idx, nid);
394 				snd_hda_codec_write_cache(codec, nid, 0,
395 					    AC_VERB_SET_CONNECT_SEL,
396 					    cvt_idx);
397 				break;
398 			}
399 		}
400 		snd_hda_set_dev_select(codec, nid, dev_id_saved);
401 	}
402 }
403 
404 /* A wrapper of intel_not_share_asigned_cvt() */
405 static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
406 			hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
407 {
408 	int mux_idx;
409 	struct hdmi_spec *spec = codec->spec;
410 
411 	/* On Intel platform, the mapping of converter nid to
412 	 * mux index of the pins are always the same.
413 	 * The pin nid may be 0, this means all pins will not
414 	 * share the converter.
415 	 */
416 	mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
417 	if (mux_idx >= 0)
418 		intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
419 }
420 
421 /*
422  * prepare ops override for HSW+
423  *
424  * Disable keep-alive before the converter format and audio infoframe are
425  * reprogrammed by the PCM prepare sequence. Changing the audio format (e.g.
426  * the channel count when switching to multichannel PCM) while a keep-alive
427  * stream is active is not safe, so release keep-alive here, early in the
428  * sequence. It is re-enabled once the new stream has been set up, in
429  * i915_hsw_setup_stream().
430  */
431 static void i915_hsw_prepare(struct hda_codec *codec,
432 			     struct hdmi_spec_per_pin *per_pin)
433 {
434 	struct hdmi_spec *spec = codec->spec;
435 
436 	if (spec->silent_stream_type == SILENT_STREAM_KAE && per_pin->silent_stream) {
437 		silent_stream_set_kae(codec, per_pin, false);
438 		/* wait for pending transfers in codec to clear */
439 		usleep_range(100, 200);
440 	}
441 }
442 
443 /* setup_stream ops override for HSW+ */
444 static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
445 				 hda_nid_t pin_nid, int dev_id, u32 stream_tag,
446 				 int format)
447 {
448 	struct hdmi_spec *spec = codec->spec;
449 	int pin_idx = pin_id_to_pin_index(codec, pin_nid, dev_id);
450 	struct hdmi_spec_per_pin *per_pin;
451 	int res;
452 
453 	if (pin_idx < 0)
454 		per_pin = NULL;
455 	else
456 		per_pin = get_pin(spec, pin_idx);
457 
458 	haswell_verify_D0(codec, cvt_nid, pin_nid);
459 
460 	res = snd_hda_hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
461 					stream_tag, format);
462 
463 	/*
464 	 * Keep-alive was disabled in i915_hsw_prepare(), re-enable it now.
465 	 * The pin lookup above resolves to the same per_pin that prepare
466 	 * used (pin_nid comes from that per_pin), so this stays balanced; a
467 	 * NULL per_pin only occurs on a lookup failure that also implies no
468 	 * active keep-alive stream to restore.
469 	 */
470 	if (spec->silent_stream_type == SILENT_STREAM_KAE && per_pin && per_pin->silent_stream) {
471 		usleep_range(100, 200);
472 		silent_stream_set_kae(codec, per_pin, true);
473 	}
474 
475 	return res;
476 }
477 
478 /* pin_cvt_fixup ops override for HSW+ and VLV+ */
479 static void i915_pin_cvt_fixup(struct hda_codec *codec,
480 			       struct hdmi_spec_per_pin *per_pin,
481 			       hda_nid_t cvt_nid)
482 {
483 	if (per_pin) {
484 		haswell_verify_D0(codec, per_pin->cvt_nid, per_pin->pin_nid);
485 		snd_hda_set_dev_select(codec, per_pin->pin_nid,
486 			       per_pin->dev_id);
487 		intel_verify_pin_cvt_connect(codec, per_pin);
488 		intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
489 				     per_pin->dev_id, per_pin->mux_idx);
490 	} else {
491 		intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
492 	}
493 }
494 
495 static int i915_hdmi_suspend(struct hda_codec *codec)
496 {
497 	struct hdmi_spec *spec = codec->spec;
498 	bool silent_streams = false;
499 	int pin_idx, res;
500 
501 	res = snd_hda_hdmi_generic_suspend(codec);
502 	if (spec->silent_stream_type != SILENT_STREAM_KAE)
503 		return res;
504 
505 	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
506 		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
507 
508 		if (per_pin->silent_stream) {
509 			silent_streams = true;
510 			break;
511 		}
512 	}
513 
514 	if (silent_streams) {
515 		/*
516 		 * stream-id should remain programmed when codec goes
517 		 * to runtime suspend
518 		 */
519 		codec->no_stream_clean_at_suspend = 1;
520 
521 		/*
522 		 * the system might go to S3, in which case keep-alive
523 		 * must be reprogrammed upon resume
524 		 */
525 		codec->forced_resume = 1;
526 
527 		codec_dbg(codec, "HDMI: KAE active at suspend\n");
528 	} else {
529 		codec->no_stream_clean_at_suspend = 0;
530 		codec->forced_resume = 0;
531 	}
532 
533 	return res;
534 }
535 
536 static int i915_hdmi_resume(struct hda_codec *codec)
537 {
538 	struct hdmi_spec *spec = codec->spec;
539 	int pin_idx, res;
540 
541 	res = snd_hda_hdmi_generic_resume(codec);
542 	if (spec->silent_stream_type != SILENT_STREAM_KAE)
543 		return res;
544 
545 	/* KAE not programmed at suspend, nothing to do here */
546 	if (!codec->no_stream_clean_at_suspend)
547 		return res;
548 
549 	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
550 		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
551 
552 		/*
553 		 * If system was in suspend with monitor connected,
554 		 * the codec setting may have been lost. Re-enable
555 		 * keep-alive.
556 		 */
557 		if (per_pin->silent_stream) {
558 			unsigned int param;
559 
560 			param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0,
561 						   AC_VERB_GET_CONV, 0);
562 			if (!param) {
563 				codec_dbg(codec, "HDMI: KAE: restore stream id\n");
564 				silent_stream_enable_i915(codec, per_pin);
565 			}
566 
567 			param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0,
568 						   AC_VERB_GET_DIGI_CONVERT_1, 0);
569 			if (!(param & (AC_DIG3_KAE << 16))) {
570 				codec_dbg(codec, "HDMI: KAE: restore DIG3_KAE\n");
571 				silent_stream_set_kae(codec, per_pin, true);
572 			}
573 		}
574 	}
575 
576 	return res;
577 }
578 
579 /* precondition and allocation for Intel codecs */
580 static int alloc_intel_hdmi(struct hda_codec *codec)
581 {
582 	/* requires i915 binding */
583 	if (!codec->bus->core.audio_component) {
584 		codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
585 		/* set probe_id here to prevent generic fallback binding */
586 		codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
587 		return -ENODEV;
588 	}
589 
590 	return snd_hda_hdmi_generic_alloc(codec);
591 }
592 
593 /* parse and post-process for Intel codecs */
594 static int parse_intel_hdmi(struct hda_codec *codec)
595 {
596 	int err, retries = 3;
597 
598 	do {
599 		err = snd_hda_hdmi_parse_codec(codec);
600 	} while (err < 0 && retries--);
601 
602 	if (err < 0)
603 		return err;
604 
605 	snd_hda_hdmi_generic_init_per_pins(codec);
606 	register_i915_notifier(codec);
607 	return 0;
608 }
609 
610 /* Intel Haswell and onwards; audio component with eld notifier */
611 static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
612 				 const int *port_map, int port_num, int dev_num,
613 				 bool send_silent_stream)
614 {
615 	struct hdmi_spec *spec;
616 
617 	spec = codec->spec;
618 	codec->dp_mst = true;
619 	spec->vendor_nid = vendor_nid;
620 	spec->port_map = port_map;
621 	spec->port_num = port_num;
622 	spec->intel_hsw_fixup = true;
623 	spec->dev_num = dev_num;
624 
625 	intel_haswell_enable_all_pins(codec, true);
626 	intel_haswell_fixup_enable_dp12(codec);
627 
628 	codec->display_power_control = 1;
629 
630 	codec->depop_delay = 0;
631 	codec->auto_runtime_pm = 1;
632 
633 	spec->ops.prepare = i915_hsw_prepare;
634 	spec->ops.setup_stream = i915_hsw_setup_stream;
635 	spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
636 	spec->ops.silent_stream = i915_set_silent_stream;
637 
638 	/*
639 	 * Enable silent stream feature, if it is enabled via
640 	 * module param or Kconfig option
641 	 */
642 	if (send_silent_stream)
643 		spec->silent_stream_type = SILENT_STREAM_I915;
644 
645 	return parse_intel_hdmi(codec);
646 }
647 
648 static int probe_i915_hsw_hdmi(struct hda_codec *codec)
649 {
650 	return intel_hsw_common_init(codec, 0x08, NULL, 0, 3,
651 				     enable_silent_stream);
652 }
653 
654 static int probe_i915_glk_hdmi(struct hda_codec *codec)
655 {
656 	/*
657 	 * Silent stream calls audio component .get_power() from
658 	 * .pin_eld_notify(). On GLK this will deadlock in i915 due
659 	 * to the audio vs. CDCLK workaround.
660 	 */
661 	return intel_hsw_common_init(codec, 0x0b, NULL, 0, 3, false);
662 }
663 
664 static int probe_i915_icl_hdmi(struct hda_codec *codec)
665 {
666 	/*
667 	 * pin to port mapping table where the value indicate the pin number and
668 	 * the index indicate the port number.
669 	 */
670 	static const int map[] = {0x0, 0x4, 0x6, 0x8, 0xa, 0xb};
671 
672 	return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 3,
673 				     enable_silent_stream);
674 }
675 
676 static int probe_i915_tgl_hdmi(struct hda_codec *codec)
677 {
678 	/*
679 	 * pin to port mapping table where the value indicate the pin number and
680 	 * the index indicate the port number.
681 	 */
682 	static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
683 
684 	return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 4,
685 				     enable_silent_stream);
686 }
687 
688 static int probe_i915_adlp_hdmi(struct hda_codec *codec)
689 {
690 	struct hdmi_spec *spec;
691 	int res;
692 
693 	res = probe_i915_tgl_hdmi(codec);
694 	if (!res) {
695 		spec = codec->spec;
696 
697 		if (spec->silent_stream_type)
698 			spec->silent_stream_type = SILENT_STREAM_KAE;
699 	}
700 
701 	return res;
702 }
703 
704 /* Intel Baytrail and Braswell; with eld notifier */
705 static int probe_i915_byt_hdmi(struct hda_codec *codec)
706 {
707 	struct hdmi_spec *spec;
708 
709 	spec = codec->spec;
710 
711 	/* For Valleyview/Cherryview, only the display codec is in the display
712 	 * power well and can use link_power ops to request/release the power.
713 	 */
714 	codec->display_power_control = 1;
715 
716 	codec->depop_delay = 0;
717 	codec->auto_runtime_pm = 1;
718 
719 	spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
720 
721 	return parse_intel_hdmi(codec);
722 }
723 
724 /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */
725 static int probe_i915_cpt_hdmi(struct hda_codec *codec)
726 {
727 	return parse_intel_hdmi(codec);
728 }
729 
730 /*
731  * common driver probe
732  */
733 static int intelhdmi_probe(struct hda_codec *codec, const struct hda_device_id *id)
734 {
735 	int err;
736 
737 	err = alloc_intel_hdmi(codec);
738 	if (err < 0)
739 		return err;
740 
741 	switch (id->driver_data) {
742 	case MODEL_HSW:
743 		err = probe_i915_hsw_hdmi(codec);
744 		break;
745 	case MODEL_GLK:
746 		err = probe_i915_glk_hdmi(codec);
747 		break;
748 	case MODEL_ICL:
749 		err = probe_i915_icl_hdmi(codec);
750 		break;
751 	case MODEL_TGL:
752 		err = probe_i915_tgl_hdmi(codec);
753 		break;
754 	case MODEL_ADLP:
755 		err = probe_i915_adlp_hdmi(codec);
756 		break;
757 	case MODEL_BYT:
758 		err = probe_i915_byt_hdmi(codec);
759 		break;
760 	case MODEL_CPT:
761 		err = probe_i915_cpt_hdmi(codec);
762 		break;
763 	default:
764 		err = -EINVAL;
765 		break;
766 	}
767 
768 	if (err < 0) {
769 		snd_hda_hdmi_generic_spec_free(codec);
770 		return err;
771 	}
772 
773 	return 0;
774 }
775 
776 static const struct hda_codec_ops intelhdmi_codec_ops = {
777 	.probe = intelhdmi_probe,
778 	.remove = snd_hda_hdmi_generic_remove,
779 	.init = snd_hda_hdmi_generic_init,
780 	.build_pcms = snd_hda_hdmi_generic_build_pcms,
781 	.build_controls = snd_hda_hdmi_generic_build_controls,
782 	.unsol_event = snd_hda_hdmi_generic_unsol_event,
783 	.suspend = i915_hdmi_suspend,
784 	.resume = i915_hdmi_resume,
785 	.set_power_state = haswell_set_power_state,
786 };
787 
788 /*
789  * driver entries
790  */
791 static const struct hda_device_id snd_hda_id_intelhdmi[] = {
792 	HDA_CODEC_ID_MODEL(0x80860054, "IbexPeak HDMI",		MODEL_CPT),
793 	HDA_CODEC_ID_MODEL(0x80862800, "Geminilake HDMI",	MODEL_GLK),
794 	HDA_CODEC_ID_MODEL(0x80862804, "IbexPeak HDMI",		MODEL_CPT),
795 	HDA_CODEC_ID_MODEL(0x80862805, "CougarPoint HDMI",	MODEL_CPT),
796 	HDA_CODEC_ID_MODEL(0x80862806, "PantherPoint HDMI",	MODEL_CPT),
797 	HDA_CODEC_ID_MODEL(0x80862807, "Haswell HDMI",		MODEL_HSW),
798 	HDA_CODEC_ID_MODEL(0x80862808, "Broadwell HDMI",	MODEL_HSW),
799 	HDA_CODEC_ID_MODEL(0x80862809, "Skylake HDMI",		MODEL_HSW),
800 	HDA_CODEC_ID_MODEL(0x8086280a, "Broxton HDMI",		MODEL_HSW),
801 	HDA_CODEC_ID_MODEL(0x8086280b, "Kabylake HDMI",		MODEL_HSW),
802 	HDA_CODEC_ID_MODEL(0x8086280c, "Cannonlake HDMI",	MODEL_GLK),
803 	HDA_CODEC_ID_MODEL(0x8086280d, "Geminilake HDMI",	MODEL_GLK),
804 	HDA_CODEC_ID_MODEL(0x8086280f, "Icelake HDMI",		MODEL_ICL),
805 	HDA_CODEC_ID_MODEL(0x80862812, "Tigerlake HDMI",	MODEL_TGL),
806 	HDA_CODEC_ID_MODEL(0x80862814, "DG1 HDMI",		MODEL_TGL),
807 	HDA_CODEC_ID_MODEL(0x80862815, "Alderlake HDMI",	MODEL_TGL),
808 	HDA_CODEC_ID_MODEL(0x80862816, "Rocketlake HDMI",	MODEL_TGL),
809 	HDA_CODEC_ID_MODEL(0x80862818, "Raptorlake HDMI",	MODEL_TGL),
810 	HDA_CODEC_ID_MODEL(0x80862819, "DG2 HDMI",		MODEL_TGL),
811 	HDA_CODEC_ID_MODEL(0x8086281a, "Jasperlake HDMI",	MODEL_ICL),
812 	HDA_CODEC_ID_MODEL(0x8086281b, "Elkhartlake HDMI",	MODEL_ICL),
813 	HDA_CODEC_ID_MODEL(0x8086281c, "Alderlake-P HDMI",	MODEL_ADLP),
814 	HDA_CODEC_ID_MODEL(0x8086281d, "Meteor Lake HDMI",	MODEL_ADLP),
815 	HDA_CODEC_ID_MODEL(0x8086281e, "Battlemage HDMI",	MODEL_ADLP),
816 	HDA_CODEC_ID_MODEL(0x8086281f, "Raptor Lake P HDMI",	MODEL_ADLP),
817 	HDA_CODEC_ID_MODEL(0x80862820, "Lunar Lake HDMI",	MODEL_ADLP),
818 	HDA_CODEC_ID_MODEL(0x80862822, "Panther Lake HDMI",	MODEL_ADLP),
819 	HDA_CODEC_ID_MODEL(0x80862823, "Wildcat Lake HDMI",	MODEL_ADLP),
820 	HDA_CODEC_ID_MODEL(0x80862824, "Nova Lake HDMI",	MODEL_ADLP),
821 	HDA_CODEC_ID_MODEL(0x80862882, "Valleyview2 HDMI",	MODEL_BYT),
822 	HDA_CODEC_ID_MODEL(0x80862883, "Braswell HDMI",		MODEL_BYT),
823 	{} /* terminator */
824 };
825 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_intelhdmi);
826 
827 MODULE_LICENSE("GPL");
828 MODULE_DESCRIPTION("Intel HDMI HD-audio codec");
829 MODULE_IMPORT_NS("SND_HDA_CODEC_HDMI");
830 
831 static struct hda_codec_driver intelhdmi_driver = {
832 	.id = snd_hda_id_intelhdmi,
833 	.ops = &intelhdmi_codec_ops,
834 };
835 
836 module_hda_codec_driver(intelhdmi_driver);
837