1 // SPDX-License-Identifier: GPL-2.0-only
3 * hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms
5 * Copyright (C) 2014-2015 Intel Corp
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 #include <linux/init.h>
14 #include <linux/delay.h>
15 #include <linux/module.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/hdmi.h>
18 #include <drm/drm_edid.h>
19 #include <sound/pcm_params.h>
20 #include <sound/jack.h>
21 #include <sound/soc.h>
22 #include <sound/hdaudio_ext.h>
23 #include <sound/hda_i915.h>
24 #include <sound/pcm_drm_eld.h>
25 #include <sound/hda_chmap.h>
26 #include "../../hda/local.h"
27 #include "hdac_hdmi.h"
31 #define AMP_OUT_MUTE 0xb080
32 #define AMP_OUT_UNMUTE 0xb000
33 #define PIN_OUT (AC_PINCTL_OUT_EN)
35 #define HDA_MAX_CONNECTIONS 32
37 #define HDA_MAX_CVTS 3
38 #define HDA_MAX_PORTS 3
40 #define ELD_MAX_SIZE 256
41 #define ELD_FIXED_BYTES 20
43 #define ELD_VER_CEA_861D 2
44 #define ELD_VER_PARTIAL 31
45 #define ELD_MAX_MNL 16
47 struct hdac_hdmi_cvt_params {
48 unsigned int channels_min;
49 unsigned int channels_max;
55 struct hdac_hdmi_cvt {
56 struct list_head head;
59 struct hdac_hdmi_cvt_params params;
62 /* Currently only spk_alloc, more to be added */
63 struct hdac_hdmi_parsed_eld {
67 struct hdac_hdmi_eld {
71 char eld_buffer[ELD_MAX_SIZE];
72 struct hdac_hdmi_parsed_eld info;
75 struct hdac_hdmi_pin {
76 struct list_head head;
79 struct hdac_hdmi_port *ports;
81 struct hdac_device *hdev;
84 struct hdac_hdmi_port {
85 struct list_head head;
87 struct hdac_hdmi_pin *pin;
89 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
90 struct hdac_hdmi_eld eld;
93 struct snd_soc_dapm_context *dapm;
94 const char *output_pin;
95 struct work_struct dapm_work;
98 struct hdac_hdmi_pcm {
99 struct list_head head;
101 struct list_head port_list;
102 struct hdac_hdmi_cvt *cvt;
103 struct snd_soc_jack *jack;
108 unsigned char chmap[8]; /* ALSA API channel-map */
111 struct snd_kcontrol *eld_ctl;
114 struct hdac_hdmi_dai_port_map {
116 struct hdac_hdmi_port *port;
117 struct hdac_hdmi_cvt *cvt;
120 struct hdac_hdmi_drv_data {
121 unsigned int vendor_nid;
124 struct hdac_hdmi_priv {
125 struct hdac_device *hdev;
126 struct snd_soc_component *component;
127 struct snd_card *card;
128 struct hdac_hdmi_dai_port_map dai_map[HDA_MAX_CVTS];
129 struct list_head pin_list;
130 struct list_head cvt_list;
131 struct list_head pcm_list;
135 struct mutex pin_mutex;
136 struct hdac_chmap chmap;
137 struct hdac_hdmi_drv_data *drv_data;
138 struct snd_soc_dai_driver *dai_drv;
141 #define hdev_to_hdmi_priv(_hdev) dev_get_drvdata(&(_hdev)->dev)
143 static struct hdac_hdmi_pcm *
144 hdac_hdmi_get_pcm_from_cvt(struct hdac_hdmi_priv *hdmi,
145 struct hdac_hdmi_cvt *cvt)
147 struct hdac_hdmi_pcm *pcm;
149 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
157 static void hdac_hdmi_jack_report(struct hdac_hdmi_pcm *pcm,
158 struct hdac_hdmi_port *port, bool is_connect)
160 struct hdac_device *hdev = port->pin->hdev;
162 port->is_connect = is_connect;
165 * Report Jack connect event when a device is connected
166 * for the first time where same PCM is attached to multiple
169 if (pcm->jack_event == 0) {
171 "jack report for pcm=%d\n",
173 snd_soc_jack_report(pcm->jack, SND_JACK_AVOUT,
179 * Report Jack disconnect event when a device is disconnected
180 * is the only last connected device when same PCM is attached
183 if (pcm->jack_event == 1)
184 snd_soc_jack_report(pcm->jack, 0, SND_JACK_AVOUT);
185 if (pcm->jack_event > 0)
190 static void hdac_hdmi_port_dapm_update(struct hdac_hdmi_port *port)
192 if (port->is_connect)
193 snd_soc_dapm_enable_pin(port->dapm, port->jack_pin);
195 snd_soc_dapm_disable_pin(port->dapm, port->jack_pin);
196 snd_soc_dapm_sync(port->dapm);
199 static void hdac_hdmi_jack_dapm_work(struct work_struct *work)
201 struct hdac_hdmi_port *port;
203 port = container_of(work, struct hdac_hdmi_port, dapm_work);
204 hdac_hdmi_port_dapm_update(port);
207 static void hdac_hdmi_jack_report_sync(struct hdac_hdmi_pcm *pcm,
208 struct hdac_hdmi_port *port, bool is_connect)
210 hdac_hdmi_jack_report(pcm, port, is_connect);
211 hdac_hdmi_port_dapm_update(port);
214 /* MST supported verbs */
216 * Get the no devices that can be connected to a port on the Pin widget.
218 static int hdac_hdmi_get_port_len(struct hdac_device *hdev, hda_nid_t nid)
221 unsigned int type, param;
223 caps = get_wcaps(hdev, nid);
224 type = get_wcaps_type(caps);
226 if (!(caps & AC_WCAP_DIGITAL) || (type != AC_WID_PIN))
229 param = snd_hdac_read_parm_uncached(hdev, nid, AC_PAR_DEVLIST_LEN);
233 return param & AC_DEV_LIST_LEN_MASK;
237 * Get the port entry select on the pin. Return the port entry
238 * id selected on the pin. Return 0 means the first port entry
239 * is selected or MST is not supported.
241 static int hdac_hdmi_port_select_get(struct hdac_device *hdev,
242 struct hdac_hdmi_port *port)
244 return snd_hdac_codec_read(hdev, port->pin->nid,
245 0, AC_VERB_GET_DEVICE_SEL, 0);
249 * Sets the selected port entry for the configuring Pin widget verb.
250 * returns error if port set is not equal to port get otherwise success
252 static int hdac_hdmi_port_select_set(struct hdac_device *hdev,
253 struct hdac_hdmi_port *port)
257 if (!port->pin->mst_capable)
260 /* AC_PAR_DEVLIST_LEN is 0 based. */
261 num_ports = hdac_hdmi_get_port_len(hdev, port->pin->nid);
265 * Device List Length is a 0 based integer value indicating the
266 * number of sink device that a MST Pin Widget can support.
268 if (num_ports + 1 < port->id)
271 snd_hdac_codec_write(hdev, port->pin->nid, 0,
272 AC_VERB_SET_DEVICE_SEL, port->id);
274 if (port->id != hdac_hdmi_port_select_get(hdev, port))
277 dev_dbg(&hdev->dev, "Selected the port=%d\n", port->id);
282 static struct hdac_hdmi_pcm *get_hdmi_pcm_from_id(struct hdac_hdmi_priv *hdmi,
285 struct hdac_hdmi_pcm *pcm;
287 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
288 if (pcm->pcm_id == pcm_idx)
295 static unsigned int sad_format(const u8 *sad)
297 return ((sad[0] >> 0x3) & 0x1f);
300 static unsigned int sad_sample_bits_lpcm(const u8 *sad)
305 static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
308 u64 formats = SNDRV_PCM_FMTBIT_S16;
310 const u8 *sad, *eld_buf = eld;
312 sad = drm_eld_sad(eld_buf);
314 goto format_constraint;
316 for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
317 if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
320 * the controller support 20 and 24 bits in 32 bit
321 * container so we set S32
323 if (sad_sample_bits_lpcm(sad) & 0x6)
324 formats |= SNDRV_PCM_FMTBIT_S32;
329 return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT,
335 hdac_hdmi_set_dip_index(struct hdac_device *hdev, hda_nid_t pin_nid,
336 int packet_index, int byte_index)
340 val = (packet_index << 5) | (byte_index & 0x1f);
341 snd_hdac_codec_write(hdev, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
344 struct dp_audio_infoframe {
347 u8 ver; /* 0x11 << 2 */
349 u8 CC02_CT47; /* match with HDMI infoframe from this on */
353 u8 LFEPBL01_LSV36_DM_INH7;
356 static int hdac_hdmi_setup_audio_infoframe(struct hdac_device *hdev,
357 struct hdac_hdmi_pcm *pcm, struct hdac_hdmi_port *port)
359 uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE];
360 struct hdmi_audio_infoframe frame;
361 struct hdac_hdmi_pin *pin = port->pin;
362 struct dp_audio_infoframe dp_ai;
363 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
364 struct hdac_hdmi_cvt *cvt = pcm->cvt;
372 ca = snd_hdac_channel_allocation(hdev, port->eld.info.spk_alloc,
373 pcm->channels, pcm->chmap_set, true, pcm->chmap);
375 channels = snd_hdac_get_active_channels(ca);
376 hdmi->chmap.ops.set_channel_count(hdev, cvt->nid, channels);
378 snd_hdac_setup_channel_mapping(&hdmi->chmap, pin->nid, false, ca,
379 pcm->channels, pcm->chmap, pcm->chmap_set);
381 eld_buf = port->eld.eld_buffer;
382 conn_type = drm_eld_get_conn_type(eld_buf);
385 case DRM_ELD_CONN_TYPE_HDMI:
386 hdmi_audio_infoframe_init(&frame);
388 frame.channels = channels;
389 frame.channel_allocation = ca;
391 ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
397 case DRM_ELD_CONN_TYPE_DP:
398 memset(&dp_ai, 0, sizeof(dp_ai));
401 dp_ai.ver = 0x11 << 2;
402 dp_ai.CC02_CT47 = channels - 1;
409 dev_err(&hdev->dev, "Invalid connection type: %d\n", conn_type);
413 /* stop infoframe transmission */
414 hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
415 snd_hdac_codec_write(hdev, pin->nid, 0,
416 AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE);
419 /* Fill infoframe. Index auto-incremented */
420 hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
421 if (conn_type == DRM_ELD_CONN_TYPE_HDMI) {
422 for (i = 0; i < sizeof(buffer); i++)
423 snd_hdac_codec_write(hdev, pin->nid, 0,
424 AC_VERB_SET_HDMI_DIP_DATA, buffer[i]);
426 for (i = 0; i < sizeof(dp_ai); i++)
427 snd_hdac_codec_write(hdev, pin->nid, 0,
428 AC_VERB_SET_HDMI_DIP_DATA, dip[i]);
431 /* Start infoframe */
432 hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
433 snd_hdac_codec_write(hdev, pin->nid, 0,
434 AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST);
439 static int hdac_hdmi_set_tdm_slot(struct snd_soc_dai *dai,
440 unsigned int tx_mask, unsigned int rx_mask,
441 int slots, int slot_width)
443 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
444 struct hdac_device *hdev = hdmi->hdev;
445 struct hdac_hdmi_dai_port_map *dai_map;
446 struct hdac_hdmi_pcm *pcm;
448 dev_dbg(&hdev->dev, "%s: strm_tag: %d\n", __func__, tx_mask);
450 dai_map = &hdmi->dai_map[dai->id];
452 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
455 pcm->stream_tag = (tx_mask << 4);
460 static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
461 struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
463 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
464 struct hdac_hdmi_dai_port_map *dai_map;
465 struct hdac_hdmi_pcm *pcm;
468 dai_map = &hdmi->dai_map[dai->id];
470 format = snd_hdac_calc_stream_format(params_rate(hparams),
471 params_channels(hparams), params_format(hparams),
472 dai->driver->playback.sig_bits, 0);
474 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
478 pcm->format = format;
479 pcm->channels = params_channels(hparams);
484 static int hdac_hdmi_query_port_connlist(struct hdac_device *hdev,
485 struct hdac_hdmi_pin *pin,
486 struct hdac_hdmi_port *port)
488 if (!(get_wcaps(hdev, pin->nid) & AC_WCAP_CONN_LIST)) {
490 "HDMI: pin %d wcaps %#x does not support connection list\n",
491 pin->nid, get_wcaps(hdev, pin->nid));
495 if (hdac_hdmi_port_select_set(hdev, port) < 0)
498 port->num_mux_nids = snd_hdac_get_connections(hdev, pin->nid,
499 port->mux_nids, HDA_MAX_CONNECTIONS);
500 if (port->num_mux_nids == 0)
502 "No connections found for pin:port %d:%d\n",
505 dev_dbg(&hdev->dev, "num_mux_nids %d for pin:port %d:%d\n",
506 port->num_mux_nids, pin->nid, port->id);
508 return port->num_mux_nids;
512 * Query pcm list and return port to which stream is routed.
514 * Also query connection list of the pin, to validate the cvt to port map.
516 * Same stream rendering to multiple ports simultaneously can be done
517 * possibly, but not supported for now in driver. So return the first port
520 static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt(
521 struct hdac_device *hdev,
522 struct hdac_hdmi_priv *hdmi,
523 struct hdac_hdmi_cvt *cvt)
525 struct hdac_hdmi_pcm *pcm;
526 struct hdac_hdmi_port *port;
529 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
530 if (pcm->cvt == cvt) {
531 if (list_empty(&pcm->port_list))
534 list_for_each_entry(port, &pcm->port_list, head) {
535 mutex_lock(&pcm->lock);
536 ret = hdac_hdmi_query_port_connlist(hdev,
538 mutex_unlock(&pcm->lock);
542 for (i = 0; i < port->num_mux_nids; i++) {
543 if (port->mux_nids[i] == cvt->nid &&
544 port->eld.monitor_present &&
556 * Go through all converters and ensure connection is set to
557 * the correct pin as set via kcontrols.
559 static void hdac_hdmi_verify_connect_sel_all_pins(struct hdac_device *hdev)
561 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
562 struct hdac_hdmi_port *port;
563 struct hdac_hdmi_cvt *cvt;
566 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
567 port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
568 if (port && port->pin) {
569 snd_hdac_codec_write(hdev, port->pin->nid, 0,
570 AC_VERB_SET_CONNECT_SEL, cvt_idx);
571 dev_dbg(&hdev->dev, "%s: %s set connect %d -> %d\n",
572 __func__, cvt->name, port->pin->nid, cvt_idx);
579 * This tries to get a valid pin and set the HW constraints based on the
580 * ELD. Even if a valid pin is not found return success so that device open
583 static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream,
584 struct snd_soc_dai *dai)
586 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
587 struct hdac_device *hdev = hdmi->hdev;
588 struct hdac_hdmi_dai_port_map *dai_map;
589 struct hdac_hdmi_cvt *cvt;
590 struct hdac_hdmi_port *port;
593 dai_map = &hdmi->dai_map[dai->id];
596 port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
599 * To make PA and other userland happy.
600 * userland scans devices so returning error does not help.
604 if ((!port->eld.monitor_present) ||
605 (!port->eld.eld_valid)) {
608 "Failed: present?:%d ELD valid?:%d pin:port: %d:%d\n",
609 port->eld.monitor_present, port->eld.eld_valid,
610 port->pin->nid, port->id);
615 dai_map->port = port;
617 ret = hdac_hdmi_eld_limit_formats(substream->runtime,
618 port->eld.eld_buffer);
622 return snd_pcm_hw_constraint_eld(substream->runtime,
623 port->eld.eld_buffer);
626 static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
627 struct snd_soc_dai *dai)
629 struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
630 struct hdac_hdmi_dai_port_map *dai_map;
631 struct hdac_hdmi_pcm *pcm;
633 dai_map = &hdmi->dai_map[dai->id];
635 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
638 mutex_lock(&pcm->lock);
639 pcm->chmap_set = false;
640 memset(pcm->chmap, 0, sizeof(pcm->chmap));
642 mutex_unlock(&pcm->lock);
646 dai_map->port = NULL;
650 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
653 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
656 chans = get_wcaps(hdev, cvt->nid);
657 chans = get_wcaps_channels(chans);
659 cvt->params.channels_min = 2;
661 cvt->params.channels_max = chans;
662 if (chans > hdmi->chmap.channels_max)
663 hdmi->chmap.channels_max = chans;
665 err = snd_hdac_query_supported_pcm(hdev, cvt->nid,
667 &cvt->params.formats,
668 &cvt->params.maxbps);
671 "Failed to query pcm params for nid %d: %d\n",
677 static int hdac_hdmi_fill_widget_info(struct device *dev,
678 struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id,
679 void *priv, const char *wname, const char *stream,
680 struct snd_kcontrol_new *wc, int numkc,
681 int (*event)(struct snd_soc_dapm_widget *,
682 struct snd_kcontrol *, int), unsigned short event_flags)
685 w->name = devm_kstrdup(dev, wname, GFP_KERNEL);
690 w->reg = SND_SOC_NOPM;
692 w->kcontrol_news = wc;
693 w->num_kcontrols = numkc;
696 w->event_flags = event_flags;
701 static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route,
702 const char *sink, const char *control, const char *src,
703 int (*handler)(struct snd_soc_dapm_widget *src,
704 struct snd_soc_dapm_widget *sink))
708 route->control = control;
709 route->connected = handler;
712 static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_device *hdev,
713 struct hdac_hdmi_port *port)
715 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
716 struct hdac_hdmi_pcm *pcm;
717 struct hdac_hdmi_port *p;
719 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
720 if (list_empty(&pcm->port_list))
723 list_for_each_entry(p, &pcm->port_list, head) {
724 if (p->id == port->id && port->pin == p->pin)
732 static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
733 hda_nid_t nid, unsigned int pwr_state)
738 if (get_wcaps(hdev, nid) & AC_WCAP_POWER) {
739 if (!snd_hdac_check_power_state(hdev, nid, pwr_state)) {
740 for (count = 0; count < 10; count++) {
741 snd_hdac_codec_read(hdev, nid, 0,
742 AC_VERB_SET_POWER_STATE,
744 state = snd_hdac_sync_power_state(hdev,
746 if (!(state & AC_PWRST_ERROR))
753 static void hdac_hdmi_set_amp(struct hdac_device *hdev,
754 hda_nid_t nid, int val)
756 if (get_wcaps(hdev, nid) & AC_WCAP_OUT_AMP)
757 snd_hdac_codec_write(hdev, nid, 0,
758 AC_VERB_SET_AMP_GAIN_MUTE, val);
762 static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w,
763 struct snd_kcontrol *kc, int event)
765 struct hdac_hdmi_port *port = w->priv;
766 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
767 struct hdac_hdmi_pcm *pcm;
769 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
770 __func__, w->name, event);
772 pcm = hdac_hdmi_get_pcm(hdev, port);
776 /* set the device if pin is mst_capable */
777 if (hdac_hdmi_port_select_set(hdev, port) < 0)
781 case SND_SOC_DAPM_PRE_PMU:
782 hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D0);
784 /* Enable out path for this pin widget */
785 snd_hdac_codec_write(hdev, port->pin->nid, 0,
786 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
788 hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_UNMUTE);
790 return hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
792 case SND_SOC_DAPM_POST_PMD:
793 hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_MUTE);
795 /* Disable out path for this pin widget */
796 snd_hdac_codec_write(hdev, port->pin->nid, 0,
797 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
799 hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D3);
807 static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w,
808 struct snd_kcontrol *kc, int event)
810 struct hdac_hdmi_cvt *cvt = w->priv;
811 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
812 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
813 struct hdac_hdmi_pcm *pcm;
815 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
816 __func__, w->name, event);
818 pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, cvt);
823 case SND_SOC_DAPM_PRE_PMU:
824 hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D0);
826 /* Enable transmission */
827 snd_hdac_codec_write(hdev, cvt->nid, 0,
828 AC_VERB_SET_DIGI_CONVERT_1, 1);
830 /* Category Code (CC) to zero */
831 snd_hdac_codec_write(hdev, cvt->nid, 0,
832 AC_VERB_SET_DIGI_CONVERT_2, 0);
834 snd_hdac_codec_write(hdev, cvt->nid, 0,
835 AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag);
836 snd_hdac_codec_write(hdev, cvt->nid, 0,
837 AC_VERB_SET_STREAM_FORMAT, pcm->format);
840 * The connection indices are shared by all converters and
841 * may interfere with each other. Ensure correct
842 * routing for all converters at stream start.
844 hdac_hdmi_verify_connect_sel_all_pins(hdev);
848 case SND_SOC_DAPM_POST_PMD:
849 snd_hdac_codec_write(hdev, cvt->nid, 0,
850 AC_VERB_SET_CHANNEL_STREAMID, 0);
851 snd_hdac_codec_write(hdev, cvt->nid, 0,
852 AC_VERB_SET_STREAM_FORMAT, 0);
854 hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D3);
862 static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w,
863 struct snd_kcontrol *kc, int event)
865 struct hdac_hdmi_port *port = w->priv;
866 struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
869 dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
870 __func__, w->name, event);
873 kc = w->kcontrols[0];
875 mux_idx = dapm_kcontrol_get_value(kc);
877 /* set the device if pin is mst_capable */
878 if (hdac_hdmi_port_select_set(hdev, port) < 0)
882 snd_hdac_codec_write(hdev, port->pin->nid, 0,
883 AC_VERB_SET_CONNECT_SEL, (mux_idx - 1));
890 * Based on user selection, map the PINs with the PCMs.
892 static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,
893 struct snd_ctl_elem_value *ucontrol)
896 struct hdac_hdmi_port *p, *p_next;
897 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
898 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
899 struct snd_soc_dapm_context *dapm = w->dapm;
900 struct hdac_hdmi_port *port = w->priv;
901 struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
902 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
903 struct hdac_hdmi_pcm *pcm;
904 const char *cvt_name = e->texts[ucontrol->value.enumerated.item[0]];
906 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
913 mutex_lock(&hdmi->pin_mutex);
914 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
915 if (list_empty(&pcm->port_list))
918 list_for_each_entry_safe(p, p_next, &pcm->port_list, head) {
919 if (p == port && p->id == port->id &&
920 p->pin == port->pin) {
921 hdac_hdmi_jack_report_sync(pcm, port, false);
928 * Jack status is not reported during device probe as the
929 * PCMs are not registered by then. So report it here.
931 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
932 if (!strcmp(cvt_name, pcm->cvt->name)) {
933 list_add_tail(&port->head, &pcm->port_list);
934 if (port->eld.monitor_present && port->eld.eld_valid) {
935 hdac_hdmi_jack_report_sync(pcm, port, true);
936 mutex_unlock(&hdmi->pin_mutex);
941 mutex_unlock(&hdmi->pin_mutex);
947 * Ideally the Mux inputs should be based on the num_muxs enumerated, but
948 * the display driver seem to be programming the connection list for the pin
951 * So programming all the possible inputs for the mux, the user has to take
952 * care of selecting the right one and leaving all other inputs selected to
955 static int hdac_hdmi_create_pin_port_muxs(struct hdac_device *hdev,
956 struct hdac_hdmi_port *port,
957 struct snd_soc_dapm_widget *widget,
958 const char *widget_name)
960 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
961 struct hdac_hdmi_pin *pin = port->pin;
962 struct snd_kcontrol_new *kc;
963 struct hdac_hdmi_cvt *cvt;
965 char kc_name[NAME_SIZE];
966 char mux_items[NAME_SIZE];
967 /* To hold inputs to the Pin mux */
968 char *items[HDA_MAX_CONNECTIONS];
970 int num_items = hdmi->num_cvt + 1;
972 kc = devm_kzalloc(&hdev->dev, sizeof(*kc), GFP_KERNEL);
976 se = devm_kzalloc(&hdev->dev, sizeof(*se), GFP_KERNEL);
980 snprintf(kc_name, NAME_SIZE, "Pin %d port %d Input",
982 kc->name = devm_kstrdup(&hdev->dev, kc_name, GFP_KERNEL);
986 kc->private_value = (long)se;
987 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
989 kc->info = snd_soc_info_enum_double;
990 kc->put = hdac_hdmi_set_pin_port_mux;
991 kc->get = snd_soc_dapm_get_enum_double;
993 se->reg = SND_SOC_NOPM;
995 /* enum texts: ["NONE", "cvt #", "cvt #", ...] */
996 se->items = num_items;
997 se->mask = roundup_pow_of_two(se->items) - 1;
999 sprintf(mux_items, "NONE");
1000 items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
1004 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1006 sprintf(mux_items, "cvt %d", cvt->nid);
1007 items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
1012 se->texts = devm_kmemdup(&hdev->dev, items,
1013 (num_items * sizeof(char *)), GFP_KERNEL);
1017 return hdac_hdmi_fill_widget_info(&hdev->dev, widget,
1018 snd_soc_dapm_mux, port, widget_name, NULL, kc, 1,
1019 hdac_hdmi_pin_mux_widget_event,
1020 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_REG);
1023 /* Add cvt <- input <- mux route map */
1024 static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_device *hdev,
1025 struct snd_soc_dapm_widget *widgets,
1026 struct snd_soc_dapm_route *route, int rindex)
1028 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1029 const struct snd_kcontrol_new *kc;
1030 struct soc_enum *se;
1031 int mux_index = hdmi->num_cvt + hdmi->num_ports;
1034 for (i = 0; i < hdmi->num_ports; i++) {
1035 kc = widgets[mux_index].kcontrol_news;
1036 se = (struct soc_enum *)kc->private_value;
1037 for (j = 0; j < hdmi->num_cvt; j++) {
1038 hdac_hdmi_fill_route(&route[rindex],
1039 widgets[mux_index].name,
1041 widgets[j].name, NULL);
1051 * Widgets are added in the below sequence
1052 * Converter widgets for num converters enumerated
1053 * Pin-port widgets for num ports for Pins enumerated
1054 * Pin-port mux widgets to represent connenction list of pin widget
1056 * For each port, one Mux and One output widget is added
1057 * Total widgets elements = num_cvt + (num_ports * 2);
1059 * Routes are added as below:
1060 * pin-port mux -> pin (based on num_ports)
1061 * cvt -> "Input sel control" -> pin-port_mux
1063 * Total route elements:
1064 * num_ports + (pin_muxes * num_cvt)
1066 static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm)
1068 struct snd_soc_dapm_widget *widgets;
1069 struct snd_soc_dapm_route *route;
1070 struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
1071 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1072 struct snd_soc_dai_driver *dai_drv = hdmi->dai_drv;
1073 char widget_name[NAME_SIZE];
1074 struct hdac_hdmi_cvt *cvt;
1075 struct hdac_hdmi_pin *pin;
1076 int ret, i = 0, num_routes = 0, j;
1078 if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list))
1081 widgets = devm_kzalloc(dapm->dev, (sizeof(*widgets) *
1082 ((2 * hdmi->num_ports) + hdmi->num_cvt)),
1088 /* DAPM widgets to represent each converter widget */
1089 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1090 sprintf(widget_name, "Converter %d", cvt->nid);
1091 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1092 snd_soc_dapm_aif_in, cvt,
1093 widget_name, dai_drv[i].playback.stream_name, NULL, 0,
1094 hdac_hdmi_cvt_output_widget_event,
1095 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
1101 list_for_each_entry(pin, &hdmi->pin_list, head) {
1102 for (j = 0; j < pin->num_ports; j++) {
1103 sprintf(widget_name, "hif%d-%d Output",
1104 pin->nid, pin->ports[j].id);
1105 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1106 snd_soc_dapm_output, &pin->ports[j],
1107 widget_name, NULL, NULL, 0,
1108 hdac_hdmi_pin_output_widget_event,
1109 SND_SOC_DAPM_PRE_PMU |
1110 SND_SOC_DAPM_POST_PMD);
1113 pin->ports[j].output_pin = widgets[i].name;
1118 /* DAPM widgets to represent the connection list to pin widget */
1119 list_for_each_entry(pin, &hdmi->pin_list, head) {
1120 for (j = 0; j < pin->num_ports; j++) {
1121 sprintf(widget_name, "Pin%d-Port%d Mux",
1122 pin->nid, pin->ports[j].id);
1123 ret = hdac_hdmi_create_pin_port_muxs(hdev,
1124 &pin->ports[j], &widgets[i],
1130 /* For cvt to pin_mux mapping */
1131 num_routes += hdmi->num_cvt;
1133 /* For pin_mux to pin mapping */
1138 route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes),
1144 /* Add pin <- NULL <- mux route map */
1145 list_for_each_entry(pin, &hdmi->pin_list, head) {
1146 for (j = 0; j < pin->num_ports; j++) {
1147 int sink_index = i + hdmi->num_cvt;
1148 int src_index = sink_index + pin->num_ports *
1151 hdac_hdmi_fill_route(&route[i],
1152 widgets[sink_index].name, NULL,
1153 widgets[src_index].name, NULL);
1158 hdac_hdmi_add_pinmux_cvt_route(hdev, widgets, route, i);
1160 snd_soc_dapm_new_controls(dapm, widgets,
1161 ((2 * hdmi->num_ports) + hdmi->num_cvt));
1163 snd_soc_dapm_add_routes(dapm, route, num_routes);
1164 snd_soc_dapm_new_widgets(dapm->card);
1170 static int hdac_hdmi_init_dai_map(struct hdac_device *hdev)
1172 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1173 struct hdac_hdmi_dai_port_map *dai_map;
1174 struct hdac_hdmi_cvt *cvt;
1177 if (list_empty(&hdmi->cvt_list))
1180 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1181 dai_map = &hdmi->dai_map[dai_id];
1182 dai_map->dai_id = dai_id;
1187 if (dai_id == HDA_MAX_CVTS) {
1188 dev_warn(&hdev->dev,
1189 "Max dais supported: %d\n", dai_id);
1197 static int hdac_hdmi_add_cvt(struct hdac_device *hdev, hda_nid_t nid)
1199 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1200 struct hdac_hdmi_cvt *cvt;
1201 char name[NAME_SIZE];
1203 cvt = devm_kzalloc(&hdev->dev, sizeof(*cvt), GFP_KERNEL);
1208 sprintf(name, "cvt %d", cvt->nid);
1209 cvt->name = devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
1213 list_add_tail(&cvt->head, &hdmi->cvt_list);
1216 return hdac_hdmi_query_cvt_params(hdev, cvt);
1219 static int hdac_hdmi_parse_eld(struct hdac_device *hdev,
1220 struct hdac_hdmi_port *port)
1222 unsigned int ver, mnl;
1224 ver = (port->eld.eld_buffer[DRM_ELD_VER] & DRM_ELD_VER_MASK)
1225 >> DRM_ELD_VER_SHIFT;
1227 if (ver != ELD_VER_CEA_861D && ver != ELD_VER_PARTIAL) {
1228 dev_err(&hdev->dev, "HDMI: Unknown ELD version %d\n", ver);
1232 mnl = (port->eld.eld_buffer[DRM_ELD_CEA_EDID_VER_MNL] &
1233 DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
1235 if (mnl > ELD_MAX_MNL) {
1236 dev_err(&hdev->dev, "HDMI: MNL Invalid %d\n", mnl);
1240 port->eld.info.spk_alloc = port->eld.eld_buffer[DRM_ELD_SPEAKER];
1245 static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin,
1246 struct hdac_hdmi_port *port)
1248 struct hdac_device *hdev = pin->hdev;
1249 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1250 struct hdac_hdmi_pcm *pcm;
1253 bool eld_valid, eld_changed;
1259 * In case of non MST pin, get_eld info API expectes port
1262 mutex_lock(&hdmi->pin_mutex);
1263 port->eld.monitor_present = false;
1265 if (pin->mst_capable)
1268 size = snd_hdac_acomp_get_eld(hdev, pin->nid, port_id,
1269 &port->eld.monitor_present,
1270 port->eld.eld_buffer,
1274 size = min(size, ELD_MAX_SIZE);
1275 if (hdac_hdmi_parse_eld(hdev, port) < 0)
1279 eld_valid = port->eld.eld_valid;
1282 port->eld.eld_valid = true;
1283 port->eld.eld_size = size;
1285 port->eld.eld_valid = false;
1286 port->eld.eld_size = 0;
1289 eld_changed = (eld_valid != port->eld.eld_valid);
1291 pcm = hdac_hdmi_get_pcm(hdev, port);
1293 if (!port->eld.monitor_present || !port->eld.eld_valid) {
1295 dev_err(&hdev->dev, "%s: disconnect for pin:port %d:%d\n",
1296 __func__, pin->nid, port->id);
1299 * PCMs are not registered during device probe, so don't
1300 * report jack here. It will be done in usermode mux
1304 hdac_hdmi_jack_report(pcm, port, false);
1305 schedule_work(&port->dapm_work);
1308 mutex_unlock(&hdmi->pin_mutex);
1312 if (port->eld.monitor_present && port->eld.eld_valid) {
1314 hdac_hdmi_jack_report(pcm, port, true);
1315 schedule_work(&port->dapm_work);
1318 print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1,
1319 port->eld.eld_buffer, port->eld.eld_size, false);
1322 mutex_unlock(&hdmi->pin_mutex);
1324 if (eld_changed && pcm)
1325 snd_ctl_notify(hdmi->card,
1326 SNDRV_CTL_EVENT_MASK_VALUE |
1327 SNDRV_CTL_EVENT_MASK_INFO,
1331 static int hdac_hdmi_add_ports(struct hdac_device *hdev,
1332 struct hdac_hdmi_pin *pin)
1334 struct hdac_hdmi_port *ports;
1335 int max_ports = HDA_MAX_PORTS;
1339 * FIXME: max_port may vary for each platform, so pass this as
1340 * as driver data or query from i915 interface when this API is
1344 ports = devm_kcalloc(&hdev->dev, max_ports, sizeof(*ports), GFP_KERNEL);
1348 for (i = 0; i < max_ports; i++) {
1351 INIT_WORK(&ports[i].dapm_work, hdac_hdmi_jack_dapm_work);
1354 pin->num_ports = max_ports;
1358 static int hdac_hdmi_add_pin(struct hdac_device *hdev, hda_nid_t nid)
1360 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1361 struct hdac_hdmi_pin *pin;
1364 pin = devm_kzalloc(&hdev->dev, sizeof(*pin), GFP_KERNEL);
1369 pin->mst_capable = false;
1371 ret = hdac_hdmi_add_ports(hdev, pin);
1375 list_add_tail(&pin->head, &hdmi->pin_list);
1377 hdmi->num_ports += pin->num_ports;
1382 #define INTEL_VENDOR_NID 0x08
1383 #define INTEL_GLK_VENDOR_NID 0x0b
1384 #define INTEL_GET_VENDOR_VERB 0xf81
1385 #define INTEL_SET_VENDOR_VERB 0x781
1386 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
1387 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
1389 static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdev)
1391 unsigned int vendor_param;
1392 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1393 unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
1395 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
1396 INTEL_GET_VENDOR_VERB, 0);
1397 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
1400 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
1401 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
1402 INTEL_SET_VENDOR_VERB, vendor_param);
1403 if (vendor_param == -1)
1407 static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdev)
1409 unsigned int vendor_param;
1410 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1411 unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
1413 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
1414 INTEL_GET_VENDOR_VERB, 0);
1415 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
1418 /* enable DP1.2 mode */
1419 vendor_param |= INTEL_EN_DP12;
1420 vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
1421 INTEL_SET_VENDOR_VERB, vendor_param);
1422 if (vendor_param == -1)
1427 static int hdac_hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
1428 struct snd_ctl_elem_info *uinfo)
1430 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
1431 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1432 struct hdac_hdmi_pcm *pcm;
1433 struct hdac_hdmi_port *port;
1434 struct hdac_hdmi_eld *eld;
1436 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1439 pcm = get_hdmi_pcm_from_id(hdmi, kcontrol->id.device);
1441 dev_dbg(component->dev, "%s: no pcm, device %d\n", __func__,
1442 kcontrol->id.device);
1446 if (list_empty(&pcm->port_list)) {
1447 dev_dbg(component->dev, "%s: empty port list, device %d\n",
1448 __func__, kcontrol->id.device);
1452 mutex_lock(&hdmi->pin_mutex);
1454 list_for_each_entry(port, &pcm->port_list, head) {
1457 if (eld->eld_valid) {
1458 uinfo->count = eld->eld_size;
1463 mutex_unlock(&hdmi->pin_mutex);
1468 static int hdac_hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
1469 struct snd_ctl_elem_value *ucontrol)
1471 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
1472 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1473 struct hdac_hdmi_pcm *pcm;
1474 struct hdac_hdmi_port *port;
1475 struct hdac_hdmi_eld *eld;
1477 memset(ucontrol->value.bytes.data, 0, sizeof(ucontrol->value.bytes.data));
1479 pcm = get_hdmi_pcm_from_id(hdmi, kcontrol->id.device);
1481 dev_dbg(component->dev, "%s: no pcm, device %d\n", __func__,
1482 kcontrol->id.device);
1486 if (list_empty(&pcm->port_list)) {
1487 dev_dbg(component->dev, "%s: empty port list, device %d\n",
1488 __func__, kcontrol->id.device);
1492 mutex_lock(&hdmi->pin_mutex);
1494 list_for_each_entry(port, &pcm->port_list, head) {
1497 if (!eld->eld_valid)
1500 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
1501 eld->eld_size > ELD_MAX_SIZE) {
1502 mutex_unlock(&hdmi->pin_mutex);
1504 dev_err(component->dev, "%s: buffer too small, device %d eld_size %d\n",
1505 __func__, kcontrol->id.device, eld->eld_size);
1510 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
1515 mutex_unlock(&hdmi->pin_mutex);
1520 static int hdac_hdmi_create_eld_ctl(struct snd_soc_component *component, struct hdac_hdmi_pcm *pcm)
1522 struct snd_kcontrol *kctl;
1523 struct snd_kcontrol_new hdmi_eld_ctl = {
1524 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1525 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1526 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1528 .info = hdac_hdmi_eld_ctl_info,
1529 .get = hdac_hdmi_eld_ctl_get,
1530 .device = pcm->pcm_id,
1533 /* add ELD ctl with the device number corresponding to the PCM stream */
1534 kctl = snd_ctl_new1(&hdmi_eld_ctl, component);
1538 pcm->eld_ctl = kctl;
1540 return snd_ctl_add(component->card->snd_card, kctl);
1543 static const struct snd_soc_dai_ops hdmi_dai_ops = {
1544 .startup = hdac_hdmi_pcm_open,
1545 .shutdown = hdac_hdmi_pcm_close,
1546 .hw_params = hdac_hdmi_set_hw_params,
1547 .set_tdm_slot = hdac_hdmi_set_tdm_slot,
1551 * Each converter can support a stream independently. So a dai is created
1552 * based on the number of converter queried.
1554 static int hdac_hdmi_create_dais(struct hdac_device *hdev,
1555 struct snd_soc_dai_driver **dais,
1556 struct hdac_hdmi_priv *hdmi, int num_dais)
1558 struct snd_soc_dai_driver *hdmi_dais;
1559 struct hdac_hdmi_cvt *cvt;
1560 char name[NAME_SIZE], dai_name[NAME_SIZE];
1563 unsigned int rate_max = 384000, rate_min = 8000;
1567 hdmi_dais = devm_kzalloc(&hdev->dev,
1568 (sizeof(*hdmi_dais) * num_dais),
1573 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1574 ret = snd_hdac_query_supported_pcm(hdev, cvt->nid,
1575 &rates, &formats, &bps);
1579 /* Filter out 44.1, 88.2 and 176.4Khz */
1580 rates &= ~(SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |
1581 SNDRV_PCM_RATE_176400);
1585 sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
1586 hdmi_dais[i].name = devm_kstrdup(&hdev->dev,
1587 dai_name, GFP_KERNEL);
1589 if (!hdmi_dais[i].name)
1592 snprintf(name, sizeof(name), "hifi%d", i+1);
1593 hdmi_dais[i].playback.stream_name =
1594 devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
1595 if (!hdmi_dais[i].playback.stream_name)
1599 * Set caps based on capability queried from the converter.
1600 * It will be constrained runtime based on ELD queried.
1602 hdmi_dais[i].playback.formats = formats;
1603 hdmi_dais[i].playback.rates = rates;
1604 hdmi_dais[i].playback.rate_max = rate_max;
1605 hdmi_dais[i].playback.rate_min = rate_min;
1606 hdmi_dais[i].playback.channels_min = 2;
1607 hdmi_dais[i].playback.channels_max = 2;
1608 hdmi_dais[i].playback.sig_bits = bps;
1609 hdmi_dais[i].ops = &hdmi_dai_ops;
1614 hdmi->dai_drv = hdmi_dais;
1620 * Parse all nodes and store the cvt/pin nids in array
1621 * Add one time initialization for pin and cvt widgets
1623 static int hdac_hdmi_parse_and_map_nid(struct hdac_device *hdev,
1624 struct snd_soc_dai_driver **dais, int *num_dais)
1628 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1631 hdac_hdmi_skl_enable_all_pins(hdev);
1632 hdac_hdmi_skl_enable_dp12(hdev);
1634 num_nodes = snd_hdac_get_sub_nodes(hdev, hdev->afg, &nid);
1635 if (!nid || num_nodes <= 0) {
1636 dev_warn(&hdev->dev, "HDMI: failed to get afg sub nodes\n");
1640 for (i = 0; i < num_nodes; i++, nid++) {
1644 caps = get_wcaps(hdev, nid);
1645 type = get_wcaps_type(caps);
1647 if (!(caps & AC_WCAP_DIGITAL))
1652 case AC_WID_AUD_OUT:
1653 ret = hdac_hdmi_add_cvt(hdev, nid);
1659 ret = hdac_hdmi_add_pin(hdev, nid);
1666 if (!hdmi->num_pin || !hdmi->num_cvt) {
1668 dev_err(&hdev->dev, "Bad pin/cvt setup in %s\n", __func__);
1672 ret = hdac_hdmi_create_dais(hdev, dais, hdmi, hdmi->num_cvt);
1674 dev_err(&hdev->dev, "Failed to create dais with err: %d\n",
1679 *num_dais = hdmi->num_cvt;
1680 ret = hdac_hdmi_init_dai_map(hdev);
1682 dev_err(&hdev->dev, "Failed to init DAI map with err: %d\n",
1687 static int hdac_hdmi_pin2port(void *aptr, int pin)
1689 return pin - 4; /* map NID 0x05 -> port #1 */
1692 static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe)
1694 struct hdac_device *hdev = aptr;
1695 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1696 struct hdac_hdmi_pin *pin;
1697 struct hdac_hdmi_port *hport = NULL;
1698 struct snd_soc_component *component = hdmi->component;
1701 /* Don't know how this mapping is derived */
1702 hda_nid_t pin_nid = port + 0x04;
1704 dev_dbg(&hdev->dev, "%s: for pin:%d port=%d\n", __func__,
1708 * skip notification during system suspend (but not in runtime PM);
1709 * the state will be updated at resume. Also since the ELD and
1710 * connection states are updated in anyway at the end of the resume,
1711 * we can skip it when received during PM process.
1713 if (snd_power_get_state(component->card->snd_card) !=
1717 if (atomic_read(&hdev->in_pm))
1720 list_for_each_entry(pin, &hdmi->pin_list, head) {
1721 if (pin->nid != pin_nid)
1724 /* In case of non MST pin, pipe is -1 */
1726 pin->mst_capable = false;
1727 /* if not MST, default is port[0] */
1728 hport = &pin->ports[0];
1730 for (i = 0; i < pin->num_ports; i++) {
1731 pin->mst_capable = true;
1732 if (pin->ports[i].id == pipe) {
1733 hport = &pin->ports[i];
1740 hdac_hdmi_present_sense(pin, hport);
1745 static struct drm_audio_component_audio_ops aops = {
1746 .pin2port = hdac_hdmi_pin2port,
1747 .pin_eld_notify = hdac_hdmi_eld_notify_cb,
1750 static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card,
1753 struct snd_soc_pcm_runtime *rtd;
1755 for_each_card_rtds(card, rtd) {
1756 if (rtd->pcm && (rtd->pcm->device == device))
1763 /* create jack pin kcontrols */
1764 static int create_fill_jack_kcontrols(struct snd_soc_card *card,
1765 struct hdac_device *hdev)
1767 struct hdac_hdmi_pin *pin;
1768 struct snd_kcontrol_new *kc;
1769 char kc_name[NAME_SIZE], xname[NAME_SIZE];
1772 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
1773 struct snd_soc_component *component = hdmi->component;
1775 kc = devm_kcalloc(component->dev, hdmi->num_ports,
1776 sizeof(*kc), GFP_KERNEL);
1781 list_for_each_entry(pin, &hdmi->pin_list, head) {
1782 for (j = 0; j < pin->num_ports; j++) {
1783 snprintf(xname, sizeof(xname), "hif%d-%d Jack",
1784 pin->nid, pin->ports[j].id);
1785 name = devm_kstrdup(component->dev, xname, GFP_KERNEL);
1788 snprintf(kc_name, sizeof(kc_name), "%s Switch", xname);
1789 kc[i].name = devm_kstrdup(component->dev, kc_name,
1794 kc[i].private_value = (unsigned long)name;
1795 kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1797 kc[i].info = snd_soc_dapm_info_pin_switch;
1798 kc[i].put = snd_soc_dapm_put_pin_switch;
1799 kc[i].get = snd_soc_dapm_get_pin_switch;
1804 return snd_soc_add_card_controls(card, kc, i);
1807 int hdac_hdmi_jack_port_init(struct snd_soc_component *component,
1808 struct snd_soc_dapm_context *dapm)
1810 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1811 struct hdac_device *hdev = hdmi->hdev;
1812 struct hdac_hdmi_pin *pin;
1813 struct snd_soc_dapm_widget *widgets;
1814 struct snd_soc_dapm_route *route;
1815 char w_name[NAME_SIZE];
1818 widgets = devm_kcalloc(dapm->dev, hdmi->num_ports,
1819 sizeof(*widgets), GFP_KERNEL);
1824 route = devm_kcalloc(dapm->dev, hdmi->num_ports,
1825 sizeof(*route), GFP_KERNEL);
1829 /* create Jack DAPM widget */
1830 list_for_each_entry(pin, &hdmi->pin_list, head) {
1831 for (j = 0; j < pin->num_ports; j++) {
1832 snprintf(w_name, sizeof(w_name), "hif%d-%d Jack",
1833 pin->nid, pin->ports[j].id);
1835 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
1836 snd_soc_dapm_spk, NULL,
1837 w_name, NULL, NULL, 0, NULL, 0);
1841 pin->ports[j].jack_pin = widgets[i].name;
1842 pin->ports[j].dapm = dapm;
1844 /* add to route from Jack widget to output */
1845 hdac_hdmi_fill_route(&route[i], pin->ports[j].jack_pin,
1846 NULL, pin->ports[j].output_pin, NULL);
1852 /* Add Route from Jack widget to the output widget */
1853 ret = snd_soc_dapm_new_controls(dapm, widgets, hdmi->num_ports);
1857 ret = snd_soc_dapm_add_routes(dapm, route, hdmi->num_ports);
1861 ret = snd_soc_dapm_new_widgets(dapm->card);
1865 /* Add Jack Pin switch Kcontrol */
1866 ret = create_fill_jack_kcontrols(dapm->card, hdev);
1871 /* default set the Jack Pin switch to OFF */
1872 list_for_each_entry(pin, &hdmi->pin_list, head) {
1873 for (j = 0; j < pin->num_ports; j++)
1874 snd_soc_dapm_disable_pin(pin->ports[j].dapm,
1875 pin->ports[j].jack_pin);
1880 EXPORT_SYMBOL_GPL(hdac_hdmi_jack_port_init);
1882 int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device,
1883 struct snd_soc_jack *jack)
1885 struct snd_soc_component *component = dai->component;
1886 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1887 struct hdac_device *hdev = hdmi->hdev;
1888 struct hdac_hdmi_pcm *pcm;
1889 struct snd_pcm *snd_pcm;
1893 * this is a new PCM device, create new pcm and
1894 * add to the pcm list
1896 pcm = devm_kzalloc(&hdev->dev, sizeof(*pcm), GFP_KERNEL);
1899 pcm->pcm_id = device;
1900 pcm->cvt = hdmi->dai_map[dai->id].cvt;
1901 pcm->jack_event = 0;
1903 mutex_init(&pcm->lock);
1904 INIT_LIST_HEAD(&pcm->port_list);
1905 snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device);
1907 err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap);
1910 "chmap control add failed with err: %d for pcm: %d\n",
1916 /* add control for ELD Bytes */
1917 err = hdac_hdmi_create_eld_ctl(component, pcm);
1920 "eld control add failed with err: %d for pcm: %d\n",
1925 list_add_tail(&pcm->head, &hdmi->pcm_list);
1929 EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init);
1931 static void hdac_hdmi_present_sense_all_pins(struct hdac_device *hdev,
1932 struct hdac_hdmi_priv *hdmi, bool detect_pin_caps)
1935 struct hdac_hdmi_pin *pin;
1937 list_for_each_entry(pin, &hdmi->pin_list, head) {
1938 if (detect_pin_caps) {
1940 if (hdac_hdmi_get_port_len(hdev, pin->nid) == 0)
1941 pin->mst_capable = false;
1943 pin->mst_capable = true;
1946 for (i = 0; i < pin->num_ports; i++) {
1947 if (!pin->mst_capable && i > 0)
1950 hdac_hdmi_present_sense(pin, &pin->ports[i]);
1955 static int hdmi_codec_probe(struct snd_soc_component *component)
1957 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
1958 struct hdac_device *hdev = hdmi->hdev;
1959 struct snd_soc_dapm_context *dapm =
1960 snd_soc_component_get_dapm(component);
1961 struct hdac_ext_link *hlink;
1964 hdmi->component = component;
1967 * hold the ref while we probe, also no need to drop the ref on
1968 * exit, we call pm_runtime_suspend() so that will do for us
1970 hlink = snd_hdac_ext_bus_get_hlink_by_name(hdev->bus, dev_name(&hdev->dev));
1972 dev_err(&hdev->dev, "hdac link not found\n");
1976 snd_hdac_ext_bus_link_get(hdev->bus, hlink);
1978 ret = create_fill_widget_route_map(dapm);
1982 aops.audio_ptr = hdev;
1983 ret = snd_hdac_acomp_register_notifier(hdev->bus, &aops);
1985 dev_err(&hdev->dev, "notifier register failed: err: %d\n", ret);
1989 hdac_hdmi_present_sense_all_pins(hdev, hdmi, true);
1990 /* Imp: Store the card pointer in hda_codec */
1991 hdmi->card = dapm->card->snd_card;
1994 * Setup a device_link between card device and HDMI codec device.
1995 * The card device is the consumer and the HDMI codec device is
1996 * the supplier. With this setting, we can make sure that the audio
1997 * domain in display power will be always turned on before operating
1998 * on the HDMI audio codec registers.
1999 * Let's use the flag DL_FLAG_AUTOREMOVE_CONSUMER. This can make
2000 * sure the device link is freed when the machine driver is removed.
2002 device_link_add(component->card->dev, &hdev->dev, DL_FLAG_RPM_ACTIVE |
2003 DL_FLAG_AUTOREMOVE_CONSUMER);
2005 * hdac_device core already sets the state to active and calls
2006 * get_noresume. So enable runtime and set the device to suspend.
2008 pm_runtime_enable(&hdev->dev);
2009 pm_runtime_put(&hdev->dev);
2010 pm_runtime_suspend(&hdev->dev);
2015 static void hdmi_codec_remove(struct snd_soc_component *component)
2017 struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
2018 struct hdac_device *hdev = hdmi->hdev;
2021 ret = snd_hdac_acomp_register_notifier(hdev->bus, NULL);
2023 dev_err(&hdev->dev, "notifier unregister failed: err: %d\n",
2026 pm_runtime_disable(&hdev->dev);
2029 #ifdef CONFIG_PM_SLEEP
2030 static int hdmi_codec_resume(struct device *dev)
2032 struct hdac_device *hdev = dev_to_hdac_dev(dev);
2033 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
2036 ret = pm_runtime_force_resume(dev);
2040 * As the ELD notify callback request is not entertained while the
2041 * device is in suspend state. Need to manually check detection of
2042 * all pins here. pin capablity change is not support, so use the
2043 * already set pin caps.
2045 * NOTE: this is safe to call even if the codec doesn't actually resume.
2046 * The pin check involves only with DRM audio component hooks, so it
2047 * works even if the HD-audio side is still dreaming peacefully.
2049 hdac_hdmi_present_sense_all_pins(hdev, hdmi, false);
2053 #define hdmi_codec_resume NULL
2056 static const struct snd_soc_component_driver hdmi_hda_codec = {
2057 .probe = hdmi_codec_probe,
2058 .remove = hdmi_codec_remove,
2059 .use_pmdown_time = 1,
2063 static void hdac_hdmi_get_chmap(struct hdac_device *hdev, int pcm_idx,
2064 unsigned char *chmap)
2066 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
2067 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
2069 memcpy(chmap, pcm->chmap, ARRAY_SIZE(pcm->chmap));
2072 static void hdac_hdmi_set_chmap(struct hdac_device *hdev, int pcm_idx,
2073 unsigned char *chmap, int prepared)
2075 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
2076 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
2077 struct hdac_hdmi_port *port;
2082 if (list_empty(&pcm->port_list))
2085 mutex_lock(&pcm->lock);
2086 pcm->chmap_set = true;
2087 memcpy(pcm->chmap, chmap, ARRAY_SIZE(pcm->chmap));
2088 list_for_each_entry(port, &pcm->port_list, head)
2090 hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
2091 mutex_unlock(&pcm->lock);
2094 static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdev, int pcm_idx)
2096 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
2097 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
2102 if (list_empty(&pcm->port_list))
2108 static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdev, int pcm_idx)
2110 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
2111 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
2112 struct hdac_hdmi_port *port;
2117 if (list_empty(&pcm->port_list))
2120 port = list_first_entry(&pcm->port_list, struct hdac_hdmi_port, head);
2122 if (!port || !port->eld.eld_valid)
2125 return port->eld.info.spk_alloc;
2128 static struct hdac_hdmi_drv_data intel_glk_drv_data = {
2129 .vendor_nid = INTEL_GLK_VENDOR_NID,
2132 static struct hdac_hdmi_drv_data intel_drv_data = {
2133 .vendor_nid = INTEL_VENDOR_NID,
2136 static int hdac_hdmi_dev_probe(struct hdac_device *hdev)
2138 struct hdac_hdmi_priv *hdmi_priv;
2139 struct snd_soc_dai_driver *hdmi_dais = NULL;
2140 struct hdac_ext_link *hlink;
2143 struct hdac_driver *hdrv = drv_to_hdac_driver(hdev->dev.driver);
2144 const struct hda_device_id *hdac_id = hdac_get_device_id(hdev, hdrv);
2146 /* hold the ref while we probe */
2147 hlink = snd_hdac_ext_bus_get_hlink_by_name(hdev->bus, dev_name(&hdev->dev));
2149 dev_err(&hdev->dev, "hdac link not found\n");
2153 snd_hdac_ext_bus_link_get(hdev->bus, hlink);
2155 hdmi_priv = devm_kzalloc(&hdev->dev, sizeof(*hdmi_priv), GFP_KERNEL);
2156 if (hdmi_priv == NULL)
2159 snd_hdac_register_chmap_ops(hdev, &hdmi_priv->chmap);
2160 hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap;
2161 hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap;
2162 hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
2163 hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
2164 hdmi_priv->hdev = hdev;
2169 if (hdac_id->driver_data)
2170 hdmi_priv->drv_data =
2171 (struct hdac_hdmi_drv_data *)hdac_id->driver_data;
2173 hdmi_priv->drv_data = &intel_drv_data;
2175 dev_set_drvdata(&hdev->dev, hdmi_priv);
2177 INIT_LIST_HEAD(&hdmi_priv->pin_list);
2178 INIT_LIST_HEAD(&hdmi_priv->cvt_list);
2179 INIT_LIST_HEAD(&hdmi_priv->pcm_list);
2180 mutex_init(&hdmi_priv->pin_mutex);
2183 * Turned off in the runtime_suspend during the first explicit
2184 * pm_runtime_suspend call.
2186 snd_hdac_display_power(hdev->bus, hdev->addr, true);
2188 ret = hdac_hdmi_parse_and_map_nid(hdev, &hdmi_dais, &num_dais);
2191 "Failed in parse and map nid with err: %d\n", ret);
2194 snd_hdac_refresh_widgets(hdev);
2196 /* ASoC specific initialization */
2197 ret = devm_snd_soc_register_component(&hdev->dev, &hdmi_hda_codec,
2198 hdmi_dais, num_dais);
2200 snd_hdac_ext_bus_link_put(hdev->bus, hlink);
2205 static void clear_dapm_works(struct hdac_device *hdev)
2207 struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
2208 struct hdac_hdmi_pin *pin;
2211 list_for_each_entry(pin, &hdmi->pin_list, head)
2212 for (i = 0; i < pin->num_ports; i++)
2213 cancel_work_sync(&pin->ports[i].dapm_work);
2216 static int hdac_hdmi_dev_remove(struct hdac_device *hdev)
2218 clear_dapm_works(hdev);
2219 snd_hdac_display_power(hdev->bus, hdev->addr, false);
2225 static int hdac_hdmi_runtime_suspend(struct device *dev)
2227 struct hdac_device *hdev = dev_to_hdac_dev(dev);
2228 struct hdac_bus *bus = hdev->bus;
2229 struct hdac_ext_link *hlink;
2231 dev_dbg(dev, "Enter: %s\n", __func__);
2233 /* controller may not have been initialized for the first time */
2239 * codec_read is preferred over codec_write to set the power state.
2240 * This way verb is send to set the power state and response
2241 * is received. So setting power state is ensured without using loop
2242 * to read the state.
2244 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
2247 hlink = snd_hdac_ext_bus_get_hlink_by_name(bus, dev_name(dev));
2249 dev_err(dev, "hdac link not found\n");
2253 snd_hdac_codec_link_down(hdev);
2254 snd_hdac_ext_bus_link_put(bus, hlink);
2256 snd_hdac_display_power(bus, hdev->addr, false);
2261 static int hdac_hdmi_runtime_resume(struct device *dev)
2263 struct hdac_device *hdev = dev_to_hdac_dev(dev);
2264 struct hdac_bus *bus = hdev->bus;
2265 struct hdac_ext_link *hlink;
2267 dev_dbg(dev, "Enter: %s\n", __func__);
2269 /* controller may not have been initialized for the first time */
2273 hlink = snd_hdac_ext_bus_get_hlink_by_name(bus, dev_name(dev));
2275 dev_err(dev, "hdac link not found\n");
2279 snd_hdac_ext_bus_link_get(bus, hlink);
2280 snd_hdac_codec_link_up(hdev);
2282 snd_hdac_display_power(bus, hdev->addr, true);
2284 hdac_hdmi_skl_enable_all_pins(hdev);
2285 hdac_hdmi_skl_enable_dp12(hdev);
2288 snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
2294 #define hdac_hdmi_runtime_suspend NULL
2295 #define hdac_hdmi_runtime_resume NULL
2298 static const struct dev_pm_ops hdac_hdmi_pm = {
2299 SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
2300 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, hdmi_codec_resume)
2303 static const struct hda_device_id hdmi_list[] = {
2304 HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
2305 HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0),
2306 HDA_CODEC_EXT_ENTRY(0x8086280b, 0x100000, "Kabylake HDMI", 0),
2307 HDA_CODEC_EXT_ENTRY(0x8086280c, 0x100000, "Cannonlake HDMI",
2308 &intel_glk_drv_data),
2309 HDA_CODEC_EXT_ENTRY(0x8086280d, 0x100000, "Geminilake HDMI",
2310 &intel_glk_drv_data),
2314 MODULE_DEVICE_TABLE(hdaudio, hdmi_list);
2316 static struct hdac_driver hdmi_driver = {
2318 .name = "HDMI HDA Codec",
2319 .pm = &hdac_hdmi_pm,
2321 .id_table = hdmi_list,
2322 .probe = hdac_hdmi_dev_probe,
2323 .remove = hdac_hdmi_dev_remove,
2326 static int __init hdmi_init(void)
2328 return snd_hda_ext_driver_register(&hdmi_driver);
2331 static void __exit hdmi_exit(void)
2333 snd_hda_ext_driver_unregister(&hdmi_driver);
2336 module_init(hdmi_init);
2337 module_exit(hdmi_exit);
2339 MODULE_LICENSE("GPL v2");
2340 MODULE_DESCRIPTION("HDMI HD codec");