2 * hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms
4 * Copyright (C) 2014-2015 Intel Corp
5 * Author: Samreen Nilofer <samreen.nilofer@intel.com>
6 * Subhransu S. Prusty <subhransu.s.prusty@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/module.h>
23 #include <linux/pm_runtime.h>
24 #include <linux/hdmi.h>
25 #include <drm/drm_edid.h>
26 #include <sound/pcm_params.h>
27 #include <sound/jack.h>
28 #include <sound/soc.h>
29 #include <sound/hdaudio_ext.h>
30 #include <sound/hda_i915.h>
31 #include <sound/pcm_drm_eld.h>
32 #include "../../hda/local.h"
33 #include "hdac_hdmi.h"
37 #define AMP_OUT_MUTE 0xb080
38 #define AMP_OUT_UNMUTE 0xb000
39 #define PIN_OUT (AC_PINCTL_OUT_EN)
41 #define HDA_MAX_CONNECTIONS 32
43 #define HDA_MAX_CVTS 3
45 #define ELD_MAX_SIZE 256
46 #define ELD_FIXED_BYTES 20
48 struct hdac_hdmi_cvt_params {
49 unsigned int channels_min;
50 unsigned int channels_max;
56 struct hdac_hdmi_cvt {
57 struct list_head head;
60 struct hdac_hdmi_cvt_params params;
63 struct hdac_hdmi_eld {
67 char eld_buffer[ELD_MAX_SIZE];
70 struct hdac_hdmi_pin {
71 struct list_head head;
74 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
75 struct hdac_hdmi_eld eld;
76 struct hdac_ext_device *edev;
78 struct delayed_work work;
81 struct hdac_hdmi_pcm {
82 struct list_head head;
84 struct hdac_hdmi_pin *pin;
85 struct hdac_hdmi_cvt *cvt;
86 struct snd_jack *jack;
89 struct hdac_hdmi_dai_pin_map {
91 struct hdac_hdmi_pin *pin;
92 struct hdac_hdmi_cvt *cvt;
95 struct hdac_hdmi_priv {
96 struct hdac_hdmi_dai_pin_map dai_map[HDA_MAX_CVTS];
97 struct list_head pin_list;
98 struct list_head cvt_list;
99 struct list_head pcm_list;
102 struct mutex pin_mutex;
105 static inline struct hdac_ext_device *to_hda_ext_device(struct device *dev)
107 struct hdac_device *hdac = dev_to_hdac_dev(dev);
109 return to_ehdac_device(hdac);
112 static unsigned int sad_format(const u8 *sad)
114 return ((sad[0] >> 0x3) & 0x1f);
117 static unsigned int sad_sample_bits_lpcm(const u8 *sad)
122 static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
125 u64 formats = SNDRV_PCM_FMTBIT_S16;
127 const u8 *sad, *eld_buf = eld;
129 sad = drm_eld_sad(eld_buf);
131 goto format_constraint;
133 for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
134 if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
137 * the controller support 20 and 24 bits in 32 bit
138 * container so we set S32
140 if (sad_sample_bits_lpcm(sad) & 0x6)
141 formats |= SNDRV_PCM_FMTBIT_S32;
146 return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT,
151 /* HDMI ELD routines */
152 static unsigned int hdac_hdmi_get_eld_data(struct hdac_device *codec,
153 hda_nid_t nid, int byte_index)
157 val = snd_hdac_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_ELDD,
160 dev_dbg(&codec->dev, "HDMI: ELD data byte %d: 0x%x\n",
166 static int hdac_hdmi_get_eld_size(struct hdac_device *codec, hda_nid_t nid)
168 return snd_hdac_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_SIZE,
173 * This function queries the ELD size and ELD data and fills in the buffer
176 static int hdac_hdmi_get_eld(struct hdac_device *codec, hda_nid_t nid,
177 unsigned char *buf, int *eld_size)
179 int i, size, ret = 0;
182 * ELD size is initialized to zero in caller function. If no errors and
183 * ELD is valid, actual eld_size is assigned.
186 size = hdac_hdmi_get_eld_size(codec, nid);
187 if (size < ELD_FIXED_BYTES || size > ELD_MAX_SIZE) {
188 dev_err(&codec->dev, "HDMI: invalid ELD buf size %d\n", size);
193 for (i = 0; i < size; i++) {
194 unsigned int val = hdac_hdmi_get_eld_data(codec, nid, i);
196 * Graphics driver might be writing to ELD buffer right now.
197 * Just abort. The caller will repoll after a while.
199 if (!(val & AC_ELDD_ELD_VALID)) {
201 "HDMI: invalid ELD data byte %d\n", i);
205 val &= AC_ELDD_ELD_DATA;
207 * The first byte cannot be zero. This can happen on some DVI
208 * connections. Some Intel chips may also need some 250ms delay
209 * to return non-zero ELD data, even when the graphics driver
210 * correctly writes ELD content before setting ELD_valid bit.
213 dev_err(&codec->dev, "HDMI: 0 ELD data\n");
225 static int hdac_hdmi_setup_stream(struct hdac_ext_device *hdac,
226 hda_nid_t cvt_nid, hda_nid_t pin_nid,
227 u32 stream_tag, int format)
231 dev_dbg(&hdac->hdac.dev, "cvt nid %d pnid %d stream %d format 0x%x\n",
232 cvt_nid, pin_nid, stream_tag, format);
234 val = (stream_tag << 4);
236 snd_hdac_codec_write(&hdac->hdac, cvt_nid, 0,
237 AC_VERB_SET_CHANNEL_STREAMID, val);
238 snd_hdac_codec_write(&hdac->hdac, cvt_nid, 0,
239 AC_VERB_SET_STREAM_FORMAT, format);
245 hdac_hdmi_set_dip_index(struct hdac_ext_device *hdac, hda_nid_t pin_nid,
246 int packet_index, int byte_index)
250 val = (packet_index << 5) | (byte_index & 0x1f);
252 snd_hdac_codec_write(&hdac->hdac, pin_nid, 0,
253 AC_VERB_SET_HDMI_DIP_INDEX, val);
256 struct dp_audio_infoframe {
259 u8 ver; /* 0x11 << 2 */
261 u8 CC02_CT47; /* match with HDMI infoframe from this on */
265 u8 LFEPBL01_LSV36_DM_INH7;
268 static int hdac_hdmi_setup_audio_infoframe(struct hdac_ext_device *hdac,
269 hda_nid_t cvt_nid, hda_nid_t pin_nid)
271 uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE];
272 struct hdmi_audio_infoframe frame;
273 struct dp_audio_infoframe dp_ai;
274 struct hdac_hdmi_priv *hdmi = hdac->private_data;
275 struct hdac_hdmi_pin *pin;
283 list_for_each_entry(pin, &hdmi->pin_list, head) {
284 if (pin->nid == pin_nid)
288 eld_buf = pin->eld.eld_buffer;
289 conn_type = drm_eld_get_conn_type(eld_buf);
291 /* setup channel count */
292 snd_hdac_codec_write(&hdac->hdac, cvt_nid, 0,
293 AC_VERB_SET_CVT_CHAN_COUNT, channels - 1);
296 case DRM_ELD_CONN_TYPE_HDMI:
297 hdmi_audio_infoframe_init(&frame);
299 /* Default stereo for now */
300 frame.channels = channels;
302 ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
308 case DRM_ELD_CONN_TYPE_DP:
309 memset(&dp_ai, 0, sizeof(dp_ai));
312 dp_ai.ver = 0x11 << 2;
313 dp_ai.CC02_CT47 = channels - 1;
320 dev_err(&hdac->hdac.dev, "Invalid connection type: %d\n",
325 /* stop infoframe transmission */
326 hdac_hdmi_set_dip_index(hdac, pin_nid, 0x0, 0x0);
327 snd_hdac_codec_write(&hdac->hdac, pin_nid, 0,
328 AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE);
331 /* Fill infoframe. Index auto-incremented */
332 hdac_hdmi_set_dip_index(hdac, pin_nid, 0x0, 0x0);
333 if (conn_type == DRM_ELD_CONN_TYPE_HDMI) {
334 for (i = 0; i < sizeof(buffer); i++)
335 snd_hdac_codec_write(&hdac->hdac, pin_nid, 0,
336 AC_VERB_SET_HDMI_DIP_DATA, buffer[i]);
338 for (i = 0; i < sizeof(dp_ai); i++)
339 snd_hdac_codec_write(&hdac->hdac, pin_nid, 0,
340 AC_VERB_SET_HDMI_DIP_DATA, dip[i]);
343 /* Start infoframe */
344 hdac_hdmi_set_dip_index(hdac, pin_nid, 0x0, 0x0);
345 snd_hdac_codec_write(&hdac->hdac, pin_nid, 0,
346 AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST);
351 static void hdac_hdmi_set_power_state(struct hdac_ext_device *edev,
352 struct hdac_hdmi_dai_pin_map *dai_map, unsigned int pwr_state)
354 /* Power up pin widget */
355 if (!snd_hdac_check_power_state(&edev->hdac, dai_map->pin->nid,
357 snd_hdac_codec_write(&edev->hdac, dai_map->pin->nid, 0,
358 AC_VERB_SET_POWER_STATE, pwr_state);
360 /* Power up converter */
361 if (!snd_hdac_check_power_state(&edev->hdac, dai_map->cvt->nid,
363 snd_hdac_codec_write(&edev->hdac, dai_map->cvt->nid, 0,
364 AC_VERB_SET_POWER_STATE, pwr_state);
367 static int hdac_hdmi_playback_prepare(struct snd_pcm_substream *substream,
368 struct snd_soc_dai *dai)
370 struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
371 struct hdac_hdmi_priv *hdmi = hdac->private_data;
372 struct hdac_hdmi_dai_pin_map *dai_map;
373 struct hdac_ext_dma_params *dd;
376 dai_map = &hdmi->dai_map[dai->id];
378 dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream);
379 dev_dbg(&hdac->hdac.dev, "stream tag from cpu dai %d format in cvt 0x%x\n",
380 dd->stream_tag, dd->format);
382 ret = hdac_hdmi_setup_audio_infoframe(hdac, dai_map->cvt->nid,
387 return hdac_hdmi_setup_stream(hdac, dai_map->cvt->nid,
388 dai_map->pin->nid, dd->stream_tag, dd->format);
391 static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
392 struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
394 struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
395 struct hdac_hdmi_priv *hdmi = hdac->private_data;
396 struct hdac_hdmi_dai_pin_map *dai_map;
397 struct hdac_hdmi_pin *pin;
398 struct hdac_ext_dma_params *dd;
400 dai_map = &hdmi->dai_map[dai->id];
406 if ((!pin->eld.monitor_present) || (!pin->eld.eld_valid)) {
407 dev_err(&hdac->hdac.dev, "device is not configured for this pin: %d\n",
412 dd = snd_soc_dai_get_dma_data(dai, substream);
414 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
419 dd->format = snd_hdac_calc_stream_format(params_rate(hparams),
420 params_channels(hparams), params_format(hparams),
423 snd_soc_dai_set_dma_data(dai, substream, (void *)dd);
428 static int hdac_hdmi_playback_cleanup(struct snd_pcm_substream *substream,
429 struct snd_soc_dai *dai)
431 struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai);
432 struct hdac_ext_dma_params *dd;
433 struct hdac_hdmi_priv *hdmi = edev->private_data;
434 struct hdac_hdmi_dai_pin_map *dai_map;
436 dai_map = &hdmi->dai_map[dai->id];
438 dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream);
441 snd_soc_dai_set_dma_data(dai, substream, NULL);
448 static void hdac_hdmi_enable_cvt(struct hdac_ext_device *edev,
449 struct hdac_hdmi_dai_pin_map *dai_map)
451 /* Enable transmission */
452 snd_hdac_codec_write(&edev->hdac, dai_map->cvt->nid, 0,
453 AC_VERB_SET_DIGI_CONVERT_1, 1);
455 /* Category Code (CC) to zero */
456 snd_hdac_codec_write(&edev->hdac, dai_map->cvt->nid, 0,
457 AC_VERB_SET_DIGI_CONVERT_2, 0);
460 static int hdac_hdmi_enable_pin(struct hdac_ext_device *hdac,
461 struct hdac_hdmi_dai_pin_map *dai_map)
464 struct hdac_hdmi_pin *pin = dai_map->pin;
466 for (mux_idx = 0; mux_idx < pin->num_mux_nids; mux_idx++) {
467 if (pin->mux_nids[mux_idx] == dai_map->cvt->nid) {
468 snd_hdac_codec_write(&hdac->hdac, pin->nid, 0,
469 AC_VERB_SET_CONNECT_SEL, mux_idx);
474 if (mux_idx == pin->num_mux_nids)
477 /* Enable out path for this pin widget */
478 snd_hdac_codec_write(&hdac->hdac, pin->nid, 0,
479 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
481 hdac_hdmi_set_power_state(hdac, dai_map, AC_PWRST_D0);
483 snd_hdac_codec_write(&hdac->hdac, pin->nid, 0,
484 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
489 static int hdac_hdmi_query_pin_connlist(struct hdac_ext_device *hdac,
490 struct hdac_hdmi_pin *pin)
492 if (!(get_wcaps(&hdac->hdac, pin->nid) & AC_WCAP_CONN_LIST)) {
493 dev_warn(&hdac->hdac.dev,
494 "HDMI: pin %d wcaps %#x does not support connection list\n",
495 pin->nid, get_wcaps(&hdac->hdac, pin->nid));
499 pin->num_mux_nids = snd_hdac_get_connections(&hdac->hdac, pin->nid,
500 pin->mux_nids, HDA_MAX_CONNECTIONS);
501 if (pin->num_mux_nids == 0)
502 dev_warn(&hdac->hdac.dev, "No connections found for pin: %d\n",
505 dev_dbg(&hdac->hdac.dev, "num_mux_nids %d for pin: %d\n",
506 pin->num_mux_nids, pin->nid);
508 return pin->num_mux_nids;
512 * Query pcm list and return pin widget to which stream is routed.
514 * Also query connection list of the pin, to validate the cvt to pin map.
516 * Same stream rendering to multiple pins simultaneously can be done
517 * possibly, but not supported for now in driver. So return the first pin
520 static struct hdac_hdmi_pin *hdac_hdmi_get_pin_from_cvt(
521 struct hdac_ext_device *edev,
522 struct hdac_hdmi_priv *hdmi,
523 struct hdac_hdmi_cvt *cvt)
525 struct hdac_hdmi_pcm *pcm;
526 struct hdac_hdmi_pin *pin = NULL;
529 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
530 if (pcm->cvt == cvt) {
537 ret = hdac_hdmi_query_pin_connlist(edev, pin);
541 for (i = 0; i < pin->num_mux_nids; i++) {
542 if (pin->mux_nids[i] == cvt->nid)
551 * This tries to get a valid pin and set the HW constraints based on the
552 * ELD. Even if a valid pin is not found return success so that device open
555 static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream,
556 struct snd_soc_dai *dai)
558 struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
559 struct hdac_hdmi_priv *hdmi = hdac->private_data;
560 struct hdac_hdmi_dai_pin_map *dai_map;
561 struct hdac_hdmi_cvt *cvt;
562 struct hdac_hdmi_pin *pin;
565 dai_map = &hdmi->dai_map[dai->id];
568 pin = hdac_hdmi_get_pin_from_cvt(hdac, hdmi, cvt);
571 * To make PA and other userland happy.
572 * userland scans devices so returning error does not help.
577 if ((!pin->eld.monitor_present) ||
578 (!pin->eld.eld_valid)) {
580 dev_warn(&hdac->hdac.dev,
581 "Failed: montior present? %d ELD valid?: %d for pin: %d\n",
582 pin->eld.monitor_present, pin->eld.eld_valid, pin->nid);
589 hdac_hdmi_enable_cvt(hdac, dai_map);
590 ret = hdac_hdmi_enable_pin(hdac, dai_map);
594 ret = hdac_hdmi_eld_limit_formats(substream->runtime,
595 pin->eld.eld_buffer);
599 return snd_pcm_hw_constraint_eld(substream->runtime,
600 pin->eld.eld_buffer);
603 static int hdac_hdmi_trigger(struct snd_pcm_substream *substream, int cmd,
604 struct snd_soc_dai *dai)
606 struct hdac_hdmi_dai_pin_map *dai_map;
607 struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
608 struct hdac_hdmi_priv *hdmi = hdac->private_data;
611 dai_map = &hdmi->dai_map[dai->id];
612 if (cmd == SNDRV_PCM_TRIGGER_RESUME) {
613 ret = hdac_hdmi_enable_pin(hdac, dai_map);
617 return hdac_hdmi_playback_prepare(substream, dai);
623 static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
624 struct snd_soc_dai *dai)
626 struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
627 struct hdac_hdmi_priv *hdmi = hdac->private_data;
628 struct hdac_hdmi_dai_pin_map *dai_map;
630 dai_map = &hdmi->dai_map[dai->id];
633 snd_hdac_codec_write(&hdac->hdac, dai_map->cvt->nid, 0,
634 AC_VERB_SET_CHANNEL_STREAMID, 0);
635 snd_hdac_codec_write(&hdac->hdac, dai_map->cvt->nid, 0,
636 AC_VERB_SET_STREAM_FORMAT, 0);
638 hdac_hdmi_set_power_state(hdac, dai_map, AC_PWRST_D3);
640 snd_hdac_codec_write(&hdac->hdac, dai_map->pin->nid, 0,
641 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
648 hdac_hdmi_query_cvt_params(struct hdac_device *hdac, struct hdac_hdmi_cvt *cvt)
652 /* Only stereo supported as of now */
653 cvt->params.channels_min = cvt->params.channels_max = 2;
655 err = snd_hdac_query_supported_pcm(hdac, cvt->nid,
657 &cvt->params.formats,
658 &cvt->params.maxbps);
661 "Failed to query pcm params for nid %d: %d\n",
667 static int hdac_hdmi_fill_widget_info(struct device *dev,
668 struct snd_soc_dapm_widget *w,
669 enum snd_soc_dapm_type id, void *priv,
670 const char *wname, const char *stream,
671 struct snd_kcontrol_new *wc, int numkc)
674 w->name = devm_kstrdup(dev, wname, GFP_KERNEL);
679 w->reg = SND_SOC_NOPM;
681 w->kcontrol_news = wc;
682 w->num_kcontrols = numkc;
688 static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route,
689 const char *sink, const char *control, const char *src,
690 int (*handler)(struct snd_soc_dapm_widget *src,
691 struct snd_soc_dapm_widget *sink))
695 route->control = control;
696 route->connected = handler;
699 static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_ext_device *edev,
700 struct hdac_hdmi_pin *pin)
702 struct hdac_hdmi_priv *hdmi = edev->private_data;
703 struct hdac_hdmi_pcm *pcm = NULL;
705 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
714 * Based on user selection, map the PINs with the PCMs.
716 static int hdac_hdmi_set_pin_mux(struct snd_kcontrol *kcontrol,
717 struct snd_ctl_elem_value *ucontrol)
720 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
721 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
722 struct snd_soc_dapm_context *dapm = w->dapm;
723 struct hdac_hdmi_pin *pin = w->priv;
724 struct hdac_ext_device *edev = to_hda_ext_device(dapm->dev);
725 struct hdac_hdmi_priv *hdmi = edev->private_data;
726 struct hdac_hdmi_pcm *pcm = NULL;
727 const char *cvt_name = e->texts[ucontrol->value.enumerated.item[0]];
729 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
733 mutex_lock(&hdmi->pin_mutex);
734 list_for_each_entry(pcm, &hdmi->pcm_list, head) {
739 * Jack status is not reported during device probe as the
740 * PCMs are not registered by then. So report it here.
742 if (!strcmp(cvt_name, pcm->cvt->name) && !pcm->pin) {
744 if (pin->eld.monitor_present && pin->eld.eld_valid) {
745 dev_dbg(&edev->hdac.dev,
746 "jack report for pcm=%d\n",
749 snd_jack_report(pcm->jack, SND_JACK_AVOUT);
751 mutex_unlock(&hdmi->pin_mutex);
755 mutex_unlock(&hdmi->pin_mutex);
761 * Ideally the Mux inputs should be based on the num_muxs enumerated, but
762 * the display driver seem to be programming the connection list for the pin
765 * So programming all the possible inputs for the mux, the user has to take
766 * care of selecting the right one and leaving all other inputs selected to
769 static int hdac_hdmi_create_pin_muxs(struct hdac_ext_device *edev,
770 struct hdac_hdmi_pin *pin,
771 struct snd_soc_dapm_widget *widget,
772 const char *widget_name)
774 struct hdac_hdmi_priv *hdmi = edev->private_data;
775 struct snd_kcontrol_new *kc;
776 struct hdac_hdmi_cvt *cvt;
778 char kc_name[NAME_SIZE];
779 char mux_items[NAME_SIZE];
780 /* To hold inputs to the Pin mux */
781 char *items[HDA_MAX_CONNECTIONS];
783 int num_items = hdmi->num_cvt + 1;
785 kc = devm_kzalloc(&edev->hdac.dev, sizeof(*kc), GFP_KERNEL);
789 se = devm_kzalloc(&edev->hdac.dev, sizeof(*se), GFP_KERNEL);
793 sprintf(kc_name, "Pin %d Input", pin->nid);
794 kc->name = devm_kstrdup(&edev->hdac.dev, kc_name, GFP_KERNEL);
798 kc->private_value = (long)se;
799 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
801 kc->info = snd_soc_info_enum_double;
802 kc->put = hdac_hdmi_set_pin_mux;
803 kc->get = snd_soc_dapm_get_enum_double;
805 se->reg = SND_SOC_NOPM;
807 /* enum texts: ["NONE", "cvt #", "cvt #", ...] */
808 se->items = num_items;
809 se->mask = roundup_pow_of_two(se->items) - 1;
811 sprintf(mux_items, "NONE");
812 items[i] = devm_kstrdup(&edev->hdac.dev, mux_items, GFP_KERNEL);
816 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
818 sprintf(mux_items, "cvt %d", cvt->nid);
819 items[i] = devm_kstrdup(&edev->hdac.dev, mux_items, GFP_KERNEL);
824 se->texts = devm_kmemdup(&edev->hdac.dev, items,
825 (num_items * sizeof(char *)), GFP_KERNEL);
829 return hdac_hdmi_fill_widget_info(&edev->hdac.dev, widget,
830 snd_soc_dapm_mux, pin, widget_name, NULL, kc, 1);
833 /* Add cvt <- input <- mux route map */
834 static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_ext_device *edev,
835 struct snd_soc_dapm_widget *widgets,
836 struct snd_soc_dapm_route *route, int rindex)
838 struct hdac_hdmi_priv *hdmi = edev->private_data;
839 const struct snd_kcontrol_new *kc;
841 int mux_index = hdmi->num_cvt + hdmi->num_pin;
844 for (i = 0; i < hdmi->num_pin; i++) {
845 kc = widgets[mux_index].kcontrol_news;
846 se = (struct soc_enum *)kc->private_value;
847 for (j = 0; j < hdmi->num_cvt; j++) {
848 hdac_hdmi_fill_route(&route[rindex],
849 widgets[mux_index].name,
851 widgets[j].name, NULL);
861 * Widgets are added in the below sequence
862 * Converter widgets for num converters enumerated
863 * Pin widgets for num pins enumerated
864 * Pin mux widgets to represent connenction list of pin widget
866 * Total widgets elements = num_cvt + num_pin + num_pin;
868 * Routes are added as below:
869 * pin mux -> pin (based on num_pins)
870 * cvt -> "Input sel control" -> pin_mux
872 * Total route elements:
873 * num_pins + (pin_muxes * num_cvt)
875 static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm)
877 struct snd_soc_dapm_widget *widgets;
878 struct snd_soc_dapm_route *route;
879 struct hdac_ext_device *edev = to_hda_ext_device(dapm->dev);
880 struct hdac_hdmi_priv *hdmi = edev->private_data;
881 struct snd_soc_dai_driver *dai_drv = dapm->component->dai_drv;
882 char widget_name[NAME_SIZE];
883 struct hdac_hdmi_cvt *cvt;
884 struct hdac_hdmi_pin *pin;
885 int ret, i = 0, num_routes = 0;
887 if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list))
890 widgets = devm_kzalloc(dapm->dev,
891 (sizeof(*widgets) * ((2 * hdmi->num_pin) + hdmi->num_cvt)),
897 /* DAPM widgets to represent each converter widget */
898 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
899 sprintf(widget_name, "Converter %d", cvt->nid);
900 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
901 snd_soc_dapm_aif_in, &cvt->nid,
902 widget_name, dai_drv[i].playback.stream_name, NULL, 0);
908 list_for_each_entry(pin, &hdmi->pin_list, head) {
909 sprintf(widget_name, "hif%d Output", pin->nid);
910 ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
911 snd_soc_dapm_output, &pin->nid,
912 widget_name, NULL, NULL, 0);
918 /* DAPM widgets to represent the connection list to pin widget */
919 list_for_each_entry(pin, &hdmi->pin_list, head) {
920 sprintf(widget_name, "Pin %d Mux", pin->nid);
921 ret = hdac_hdmi_create_pin_muxs(edev, pin, &widgets[i],
927 /* For cvt to pin_mux mapping */
928 num_routes += hdmi->num_cvt;
930 /* For pin_mux to pin mapping */
934 route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes),
940 /* Add pin <- NULL <- mux route map */
941 list_for_each_entry(pin, &hdmi->pin_list, head) {
942 int sink_index = i + hdmi->num_cvt;
943 int src_index = sink_index + hdmi->num_pin;
945 hdac_hdmi_fill_route(&route[i],
946 widgets[sink_index].name, NULL,
947 widgets[src_index].name, NULL);
952 hdac_hdmi_add_pinmux_cvt_route(edev, widgets, route, i);
954 snd_soc_dapm_new_controls(dapm, widgets,
955 ((2 * hdmi->num_pin) + hdmi->num_cvt));
957 snd_soc_dapm_add_routes(dapm, route, num_routes);
958 snd_soc_dapm_new_widgets(dapm->card);
964 static int hdac_hdmi_init_dai_map(struct hdac_ext_device *edev)
966 struct hdac_hdmi_priv *hdmi = edev->private_data;
967 struct hdac_hdmi_dai_pin_map *dai_map;
968 struct hdac_hdmi_cvt *cvt;
971 if (list_empty(&hdmi->cvt_list))
974 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
975 dai_map = &hdmi->dai_map[dai_id];
976 dai_map->dai_id = dai_id;
981 if (dai_id == HDA_MAX_CVTS) {
982 dev_warn(&edev->hdac.dev,
983 "Max dais supported: %d\n", dai_id);
991 static int hdac_hdmi_add_cvt(struct hdac_ext_device *edev, hda_nid_t nid)
993 struct hdac_hdmi_priv *hdmi = edev->private_data;
994 struct hdac_hdmi_cvt *cvt;
995 char name[NAME_SIZE];
997 cvt = kzalloc(sizeof(*cvt), GFP_KERNEL);
1002 sprintf(name, "cvt %d", cvt->nid);
1003 cvt->name = kstrdup(name, GFP_KERNEL);
1005 list_add_tail(&cvt->head, &hdmi->cvt_list);
1008 return hdac_hdmi_query_cvt_params(&edev->hdac, cvt);
1011 static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin, int repoll)
1013 struct hdac_ext_device *edev = pin->edev;
1014 struct hdac_hdmi_priv *hdmi = edev->private_data;
1015 struct hdac_hdmi_pcm *pcm;
1018 pin->repoll_count = repoll;
1020 pm_runtime_get_sync(&edev->hdac.dev);
1021 val = snd_hdac_codec_read(&edev->hdac, pin->nid, 0,
1022 AC_VERB_GET_PIN_SENSE, 0);
1024 dev_dbg(&edev->hdac.dev, "Pin sense val %x for pin: %d\n",
1028 mutex_lock(&hdmi->pin_mutex);
1029 pin->eld.monitor_present = !!(val & AC_PINSENSE_PRESENCE);
1030 pin->eld.eld_valid = !!(val & AC_PINSENSE_ELDV);
1032 pcm = hdac_hdmi_get_pcm(edev, pin);
1034 if (!pin->eld.monitor_present || !pin->eld.eld_valid) {
1036 dev_dbg(&edev->hdac.dev, "%s: disconnect for pin %d\n",
1037 __func__, pin->nid);
1040 * PCMs are not registered during device probe, so don't
1041 * report jack here. It will be done in usermode mux
1045 dev_dbg(&edev->hdac.dev,
1046 "jack report for pcm=%d\n", pcm->pcm_id);
1048 snd_jack_report(pcm->jack, 0);
1051 mutex_unlock(&hdmi->pin_mutex);
1052 goto put_hdac_device;
1055 if (pin->eld.monitor_present && pin->eld.eld_valid) {
1056 /* TODO: use i915 component for reading ELD later */
1057 if (hdac_hdmi_get_eld(&edev->hdac, pin->nid,
1058 pin->eld.eld_buffer,
1059 &pin->eld.eld_size) == 0) {
1062 dev_dbg(&edev->hdac.dev,
1063 "jack report for pcm=%d\n",
1066 snd_jack_report(pcm->jack, SND_JACK_AVOUT);
1069 print_hex_dump_bytes("ELD: ", DUMP_PREFIX_OFFSET,
1070 pin->eld.eld_buffer, pin->eld.eld_size);
1072 pin->eld.monitor_present = false;
1073 pin->eld.eld_valid = false;
1076 dev_dbg(&edev->hdac.dev,
1077 "jack report for pcm=%d\n",
1080 snd_jack_report(pcm->jack, 0);
1085 mutex_unlock(&hdmi->pin_mutex);
1088 * Sometimes the pin_sense may present invalid monitor
1089 * present and eld_valid. If ELD data is not valid, loop few
1090 * more times to get correct pin sense and valid ELD.
1092 if ((!pin->eld.monitor_present || !pin->eld.eld_valid) && repoll)
1093 schedule_delayed_work(&pin->work, msecs_to_jiffies(300));
1096 pm_runtime_put_sync(&edev->hdac.dev);
1099 static void hdac_hdmi_repoll_eld(struct work_struct *work)
1101 struct hdac_hdmi_pin *pin =
1102 container_of(to_delayed_work(work), struct hdac_hdmi_pin, work);
1104 /* picked from legacy HDA driver */
1105 if (pin->repoll_count++ > 6)
1106 pin->repoll_count = 0;
1108 hdac_hdmi_present_sense(pin, pin->repoll_count);
1111 static int hdac_hdmi_add_pin(struct hdac_ext_device *edev, hda_nid_t nid)
1113 struct hdac_hdmi_priv *hdmi = edev->private_data;
1114 struct hdac_hdmi_pin *pin;
1116 pin = kzalloc(sizeof(*pin), GFP_KERNEL);
1122 list_add_tail(&pin->head, &hdmi->pin_list);
1126 INIT_DELAYED_WORK(&pin->work, hdac_hdmi_repoll_eld);
1131 #define INTEL_VENDOR_NID 0x08
1132 #define INTEL_GET_VENDOR_VERB 0xf81
1133 #define INTEL_SET_VENDOR_VERB 0x781
1134 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
1135 #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
1137 static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdac)
1139 unsigned int vendor_param;
1141 vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0,
1142 INTEL_GET_VENDOR_VERB, 0);
1143 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
1146 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
1147 vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0,
1148 INTEL_SET_VENDOR_VERB, vendor_param);
1149 if (vendor_param == -1)
1153 static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdac)
1155 unsigned int vendor_param;
1157 vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0,
1158 INTEL_GET_VENDOR_VERB, 0);
1159 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
1162 /* enable DP1.2 mode */
1163 vendor_param |= INTEL_EN_DP12;
1164 vendor_param = snd_hdac_codec_read(hdac, INTEL_VENDOR_NID, 0,
1165 INTEL_SET_VENDOR_VERB, vendor_param);
1166 if (vendor_param == -1)
1171 static struct snd_soc_dai_ops hdmi_dai_ops = {
1172 .startup = hdac_hdmi_pcm_open,
1173 .shutdown = hdac_hdmi_pcm_close,
1174 .hw_params = hdac_hdmi_set_hw_params,
1175 .prepare = hdac_hdmi_playback_prepare,
1176 .trigger = hdac_hdmi_trigger,
1177 .hw_free = hdac_hdmi_playback_cleanup,
1181 * Each converter can support a stream independently. So a dai is created
1182 * based on the number of converter queried.
1184 static int hdac_hdmi_create_dais(struct hdac_device *hdac,
1185 struct snd_soc_dai_driver **dais,
1186 struct hdac_hdmi_priv *hdmi, int num_dais)
1188 struct snd_soc_dai_driver *hdmi_dais;
1189 struct hdac_hdmi_cvt *cvt;
1190 char name[NAME_SIZE], dai_name[NAME_SIZE];
1193 unsigned int rate_max = 384000, rate_min = 8000;
1197 hdmi_dais = devm_kzalloc(&hdac->dev,
1198 (sizeof(*hdmi_dais) * num_dais),
1203 list_for_each_entry(cvt, &hdmi->cvt_list, head) {
1204 ret = snd_hdac_query_supported_pcm(hdac, cvt->nid,
1205 &rates, &formats, &bps);
1209 sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
1210 hdmi_dais[i].name = devm_kstrdup(&hdac->dev,
1211 dai_name, GFP_KERNEL);
1213 if (!hdmi_dais[i].name)
1216 snprintf(name, sizeof(name), "hifi%d", i+1);
1217 hdmi_dais[i].playback.stream_name =
1218 devm_kstrdup(&hdac->dev, name, GFP_KERNEL);
1219 if (!hdmi_dais[i].playback.stream_name)
1223 * Set caps based on capability queried from the converter.
1224 * It will be constrained runtime based on ELD queried.
1226 hdmi_dais[i].playback.formats = formats;
1227 hdmi_dais[i].playback.rates = rates;
1228 hdmi_dais[i].playback.rate_max = rate_max;
1229 hdmi_dais[i].playback.rate_min = rate_min;
1230 hdmi_dais[i].playback.channels_min = 2;
1231 hdmi_dais[i].playback.channels_max = 2;
1232 hdmi_dais[i].ops = &hdmi_dai_ops;
1243 * Parse all nodes and store the cvt/pin nids in array
1244 * Add one time initialization for pin and cvt widgets
1246 static int hdac_hdmi_parse_and_map_nid(struct hdac_ext_device *edev,
1247 struct snd_soc_dai_driver **dais, int *num_dais)
1251 struct hdac_device *hdac = &edev->hdac;
1252 struct hdac_hdmi_priv *hdmi = edev->private_data;
1255 hdac_hdmi_skl_enable_all_pins(hdac);
1256 hdac_hdmi_skl_enable_dp12(hdac);
1258 num_nodes = snd_hdac_get_sub_nodes(hdac, hdac->afg, &nid);
1259 if (!nid || num_nodes <= 0) {
1260 dev_warn(&hdac->dev, "HDMI: failed to get afg sub nodes\n");
1264 hdac->num_nodes = num_nodes;
1265 hdac->start_nid = nid;
1267 for (i = 0; i < hdac->num_nodes; i++, nid++) {
1271 caps = get_wcaps(hdac, nid);
1272 type = get_wcaps_type(caps);
1274 if (!(caps & AC_WCAP_DIGITAL))
1279 case AC_WID_AUD_OUT:
1280 ret = hdac_hdmi_add_cvt(edev, nid);
1286 ret = hdac_hdmi_add_pin(edev, nid);
1293 hdac->end_nid = nid;
1295 if (!hdmi->num_pin || !hdmi->num_cvt)
1298 ret = hdac_hdmi_create_dais(hdac, dais, hdmi, hdmi->num_cvt);
1300 dev_err(&hdac->dev, "Failed to create dais with err: %d\n",
1305 *num_dais = hdmi->num_cvt;
1307 return hdac_hdmi_init_dai_map(edev);
1310 static void hdac_hdmi_eld_notify_cb(void *aptr, int port)
1312 struct hdac_ext_device *edev = aptr;
1313 struct hdac_hdmi_priv *hdmi = edev->private_data;
1314 struct hdac_hdmi_pin *pin;
1315 struct snd_soc_codec *codec = edev->scodec;
1317 /* Don't know how this mapping is derived */
1318 hda_nid_t pin_nid = port + 0x04;
1320 dev_dbg(&edev->hdac.dev, "%s: for pin: %d\n", __func__, pin_nid);
1323 * skip notification during system suspend (but not in runtime PM);
1324 * the state will be updated at resume. Also since the ELD and
1325 * connection states are updated in anyway at the end of the resume,
1326 * we can skip it when received during PM process.
1328 if (snd_power_get_state(codec->component.card->snd_card) !=
1332 if (atomic_read(&edev->hdac.in_pm))
1335 list_for_each_entry(pin, &hdmi->pin_list, head) {
1336 if (pin->nid == pin_nid)
1337 hdac_hdmi_present_sense(pin, 1);
1341 static struct i915_audio_component_audio_ops aops = {
1342 .pin_eld_notify = hdac_hdmi_eld_notify_cb,
1345 int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device)
1347 char jack_name[NAME_SIZE];
1348 struct snd_soc_codec *codec = dai->codec;
1349 struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
1350 struct snd_soc_dapm_context *dapm =
1351 snd_soc_component_get_dapm(&codec->component);
1352 struct hdac_hdmi_priv *hdmi = edev->private_data;
1353 struct hdac_hdmi_pcm *pcm;
1356 * this is a new PCM device, create new pcm and
1357 * add to the pcm list
1359 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
1362 pcm->pcm_id = device;
1363 pcm->cvt = hdmi->dai_map[dai->id].cvt;
1365 list_add_tail(&pcm->head, &hdmi->pcm_list);
1367 sprintf(jack_name, "HDMI/DP, pcm=%d Jack", device);
1369 return snd_jack_new(dapm->card->snd_card, jack_name,
1370 SND_JACK_AVOUT, &pcm->jack, true, false);
1372 EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init);
1374 static int hdmi_codec_probe(struct snd_soc_codec *codec)
1376 struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
1377 struct hdac_hdmi_priv *hdmi = edev->private_data;
1378 struct snd_soc_dapm_context *dapm =
1379 snd_soc_component_get_dapm(&codec->component);
1380 struct hdac_hdmi_pin *pin;
1383 edev->scodec = codec;
1385 ret = create_fill_widget_route_map(dapm);
1389 aops.audio_ptr = edev;
1390 ret = snd_hdac_i915_register_notifier(&aops);
1392 dev_err(&edev->hdac.dev, "notifier register failed: err: %d\n",
1397 list_for_each_entry(pin, &hdmi->pin_list, head)
1398 hdac_hdmi_present_sense(pin, 1);
1400 /* Imp: Store the card pointer in hda_codec */
1401 edev->card = dapm->card->snd_card;
1404 * hdac_device core already sets the state to active and calls
1405 * get_noresume. So enable runtime and set the device to suspend.
1407 pm_runtime_enable(&edev->hdac.dev);
1408 pm_runtime_put(&edev->hdac.dev);
1409 pm_runtime_suspend(&edev->hdac.dev);
1414 static int hdmi_codec_remove(struct snd_soc_codec *codec)
1416 struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec);
1418 pm_runtime_disable(&edev->hdac.dev);
1423 static int hdmi_codec_prepare(struct device *dev)
1425 struct hdac_ext_device *edev = to_hda_ext_device(dev);
1426 struct hdac_device *hdac = &edev->hdac;
1428 pm_runtime_get_sync(&edev->hdac.dev);
1432 * codec_read is preferred over codec_write to set the power state.
1433 * This way verb is send to set the power state and response
1434 * is received. So setting power state is ensured without using loop
1435 * to read the state.
1437 snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE,
1443 static void hdmi_codec_complete(struct device *dev)
1445 struct hdac_ext_device *edev = to_hda_ext_device(dev);
1446 struct hdac_hdmi_priv *hdmi = edev->private_data;
1447 struct hdac_hdmi_pin *pin;
1448 struct hdac_device *hdac = &edev->hdac;
1451 snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE,
1454 hdac_hdmi_skl_enable_all_pins(&edev->hdac);
1455 hdac_hdmi_skl_enable_dp12(&edev->hdac);
1458 * As the ELD notify callback request is not entertained while the
1459 * device is in suspend state. Need to manually check detection of
1462 list_for_each_entry(pin, &hdmi->pin_list, head)
1463 hdac_hdmi_present_sense(pin, 1);
1465 pm_runtime_put_sync(&edev->hdac.dev);
1468 #define hdmi_codec_prepare NULL
1469 #define hdmi_codec_complete NULL
1472 static struct snd_soc_codec_driver hdmi_hda_codec = {
1473 .probe = hdmi_codec_probe,
1474 .remove = hdmi_codec_remove,
1475 .idle_bias_off = true,
1478 static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev)
1480 struct hdac_device *codec = &edev->hdac;
1481 struct hdac_hdmi_priv *hdmi_priv;
1482 struct snd_soc_dai_driver *hdmi_dais = NULL;
1486 hdmi_priv = devm_kzalloc(&codec->dev, sizeof(*hdmi_priv), GFP_KERNEL);
1487 if (hdmi_priv == NULL)
1490 edev->private_data = hdmi_priv;
1492 dev_set_drvdata(&codec->dev, edev);
1494 INIT_LIST_HEAD(&hdmi_priv->pin_list);
1495 INIT_LIST_HEAD(&hdmi_priv->cvt_list);
1496 INIT_LIST_HEAD(&hdmi_priv->pcm_list);
1497 mutex_init(&hdmi_priv->pin_mutex);
1500 * Turned off in the runtime_suspend during the first explicit
1501 * pm_runtime_suspend call.
1503 ret = snd_hdac_display_power(edev->hdac.bus, true);
1505 dev_err(&edev->hdac.dev,
1506 "Cannot turn on display power on i915 err: %d\n",
1511 ret = hdac_hdmi_parse_and_map_nid(edev, &hdmi_dais, &num_dais);
1513 dev_err(&codec->dev,
1514 "Failed in parse and map nid with err: %d\n", ret);
1518 /* ASoC specific initialization */
1519 return snd_soc_register_codec(&codec->dev, &hdmi_hda_codec,
1520 hdmi_dais, num_dais);
1523 static int hdac_hdmi_dev_remove(struct hdac_ext_device *edev)
1525 struct hdac_hdmi_priv *hdmi = edev->private_data;
1526 struct hdac_hdmi_pin *pin, *pin_next;
1527 struct hdac_hdmi_cvt *cvt, *cvt_next;
1528 struct hdac_hdmi_pcm *pcm, *pcm_next;
1530 snd_soc_unregister_codec(&edev->hdac.dev);
1532 list_for_each_entry_safe(pcm, pcm_next, &hdmi->pcm_list, head) {
1535 list_del(&pcm->head);
1539 list_for_each_entry_safe(cvt, cvt_next, &hdmi->cvt_list, head) {
1540 list_del(&cvt->head);
1545 list_for_each_entry_safe(pin, pin_next, &hdmi->pin_list, head) {
1546 list_del(&pin->head);
1554 static int hdac_hdmi_runtime_suspend(struct device *dev)
1556 struct hdac_ext_device *edev = to_hda_ext_device(dev);
1557 struct hdac_device *hdac = &edev->hdac;
1558 struct hdac_bus *bus = hdac->bus;
1561 dev_dbg(dev, "Enter: %s\n", __func__);
1563 /* controller may not have been initialized for the first time */
1569 * codec_read is preferred over codec_write to set the power state.
1570 * This way verb is send to set the power state and response
1571 * is received. So setting power state is ensured without using loop
1572 * to read the state.
1574 snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE,
1576 err = snd_hdac_display_power(bus, false);
1578 dev_err(bus->dev, "Cannot turn on display power on i915\n");
1585 static int hdac_hdmi_runtime_resume(struct device *dev)
1587 struct hdac_ext_device *edev = to_hda_ext_device(dev);
1588 struct hdac_device *hdac = &edev->hdac;
1589 struct hdac_bus *bus = hdac->bus;
1592 dev_dbg(dev, "Enter: %s\n", __func__);
1594 /* controller may not have been initialized for the first time */
1598 err = snd_hdac_display_power(bus, true);
1600 dev_err(bus->dev, "Cannot turn on display power on i915\n");
1604 hdac_hdmi_skl_enable_all_pins(&edev->hdac);
1605 hdac_hdmi_skl_enable_dp12(&edev->hdac);
1608 snd_hdac_codec_read(hdac, hdac->afg, 0, AC_VERB_SET_POWER_STATE,
1614 #define hdac_hdmi_runtime_suspend NULL
1615 #define hdac_hdmi_runtime_resume NULL
1618 static const struct dev_pm_ops hdac_hdmi_pm = {
1619 SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
1620 .prepare = hdmi_codec_prepare,
1621 .complete = hdmi_codec_complete,
1624 static const struct hda_device_id hdmi_list[] = {
1625 HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
1626 HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0),
1630 MODULE_DEVICE_TABLE(hdaudio, hdmi_list);
1632 static struct hdac_ext_driver hdmi_driver = {
1635 .name = "HDMI HDA Codec",
1636 .pm = &hdac_hdmi_pm,
1638 .id_table = hdmi_list,
1640 .probe = hdac_hdmi_dev_probe,
1641 .remove = hdac_hdmi_dev_remove,
1644 static int __init hdmi_init(void)
1646 return snd_hda_ext_driver_register(&hdmi_driver);
1649 static void __exit hdmi_exit(void)
1651 snd_hda_ext_driver_unregister(&hdmi_driver);
1654 module_init(hdmi_init);
1655 module_exit(hdmi_exit);
1657 MODULE_LICENSE("GPL v2");
1658 MODULE_DESCRIPTION("HDMI HD codec");
1659 MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>");
1660 MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>");