Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * patch_hdmi.c - routines for HDMI/DisplayPort codecs |
| 5 | * |
| 6 | * Copyright(c) 2008-2010 Intel Corporation. All rights reserved. |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 7 | * Copyright (c) 2006 ATI Technologies Inc. |
| 8 | * Copyright (c) 2008 NVIDIA Corp. All rights reserved. |
| 9 | * Copyright (c) 2008 Wei Ni <wni@nvidia.com> |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 10 | * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi> |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 11 | * |
| 12 | * Authors: |
| 13 | * Wu Fengguang <wfg@linux.intel.com> |
| 14 | * |
| 15 | * Maintained by: |
| 16 | * Wu Fengguang <wfg@linux.intel.com> |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 17 | */ |
| 18 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 19 | #include <linux/init.h> |
| 20 | #include <linux/delay.h> |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 21 | #include <linux/pci.h> |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 22 | #include <linux/slab.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 23 | #include <linux/module.h> |
Chris Wilson | aaa23f8 | 2018-06-27 07:25:32 +0100 | [diff] [blame] | 24 | #include <linux/pm_runtime.h> |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 25 | #include <sound/core.h> |
David Henningsson | 07acecc | 2011-05-19 11:46:03 +0200 | [diff] [blame] | 26 | #include <sound/jack.h> |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 27 | #include <sound/asoundef.h> |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 28 | #include <sound/tlv.h> |
David Henningsson | 25adc13 | 2015-08-19 10:48:58 +0200 | [diff] [blame] | 29 | #include <sound/hdaudio.h> |
| 30 | #include <sound/hda_i915.h> |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 31 | #include <sound/hda_chmap.h> |
Pierre-Louis Bossart | be57bff | 2018-08-22 15:24:57 -0500 | [diff] [blame] | 32 | #include <sound/hda_codec.h> |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 33 | #include "hda_local.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 34 | #include "hda_jack.h" |
Takashi Iwai | e38e486 | 2019-12-02 08:49:47 +0100 | [diff] [blame] | 35 | #include "hda_controller.h" |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 36 | |
Takashi Iwai | 0ebaa24 | 2011-01-11 18:11:04 +0100 | [diff] [blame] | 37 | static bool static_hdmi_pcm; |
| 38 | module_param(static_hdmi_pcm, bool, 0644); |
| 39 | MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); |
| 40 | |
Takashi Iwai | b392350 | 2020-04-15 18:25:23 +0200 | [diff] [blame] | 41 | static bool enable_acomp = true; |
| 42 | module_param(enable_acomp, bool, 0444); |
| 43 | MODULE_PARM_DESC(enable_acomp, "Enable audio component binding (default=yes)"); |
| 44 | |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 45 | static bool enable_silent_stream = |
| 46 | IS_ENABLED(CONFIG_SND_HDA_INTEL_HDMI_SILENT_STREAM); |
| 47 | module_param(enable_silent_stream, bool, 0644); |
| 48 | MODULE_PARM_DESC(enable_silent_stream, "Enable Silent Stream for HDMI devices"); |
| 49 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 50 | struct hdmi_spec_per_cvt { |
| 51 | hda_nid_t cvt_nid; |
| 52 | int assigned; |
| 53 | unsigned int channels_min; |
| 54 | unsigned int channels_max; |
| 55 | u32 rates; |
| 56 | u64 formats; |
| 57 | unsigned int maxbps; |
| 58 | }; |
| 59 | |
Takashi Iwai | 4eea309 | 2013-02-07 18:18:19 +0100 | [diff] [blame] | 60 | /* max. connections to a widget */ |
| 61 | #define HDA_MAX_CONNECTIONS 32 |
| 62 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 63 | struct hdmi_spec_per_pin { |
| 64 | hda_nid_t pin_nid; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 65 | int dev_id; |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 66 | /* pin idx, different device entries on the same pin use the same idx */ |
| 67 | int pin_nid_idx; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 68 | int num_mux_nids; |
| 69 | hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; |
Mengdong Lin | 2df6742 | 2014-03-20 13:01:06 +0800 | [diff] [blame] | 70 | int mux_idx; |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 71 | hda_nid_t cvt_nid; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 72 | |
| 73 | struct hda_codec *codec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 74 | struct hdmi_eld sink_eld; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 75 | struct mutex lock; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 76 | struct delayed_work work; |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 77 | struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/ |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 78 | int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */ |
Wu Fengguang | c6e8453 | 2011-11-18 16:59:32 -0600 | [diff] [blame] | 79 | int repoll_count; |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 80 | bool setup; /* the stream has been set up by prepare callback */ |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 81 | bool silent_stream; |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 82 | int channels; /* current number of channels */ |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 83 | bool non_pcm; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 84 | bool chmap_set; /* channel-map override by ALSA API? */ |
| 85 | unsigned char chmap[8]; /* ALSA API channel-map */ |
Jie Yang | cd6a650 | 2015-05-27 19:45:45 +0800 | [diff] [blame] | 86 | #ifdef CONFIG_SND_PROC_FS |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 87 | struct snd_info_entry *proc_entry; |
| 88 | #endif |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 89 | }; |
| 90 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 91 | /* operations used by generic code that can be overridden by patches */ |
| 92 | struct hdmi_ops { |
| 93 | int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 94 | int dev_id, unsigned char *buf, int *eld_size); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 95 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 96 | void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 97 | int dev_id, |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 98 | int ca, int active_channels, int conn_type); |
| 99 | |
| 100 | /* enable/disable HBR (HD passthrough) */ |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 101 | int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, |
| 102 | int dev_id, bool hbr); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 103 | |
| 104 | int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 105 | hda_nid_t pin_nid, int dev_id, u32 stream_tag, |
| 106 | int format); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 107 | |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 108 | void (*pin_cvt_fixup)(struct hda_codec *codec, |
| 109 | struct hdmi_spec_per_pin *per_pin, |
| 110 | hda_nid_t cvt_nid); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 111 | }; |
| 112 | |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 113 | struct hdmi_pcm { |
| 114 | struct hda_pcm *pcm; |
| 115 | struct snd_jack *jack; |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 116 | struct snd_kcontrol *eld_ctl; |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 117 | }; |
| 118 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 119 | struct hdmi_spec { |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 120 | struct hda_codec *codec; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 121 | int num_cvts; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 122 | struct snd_array cvts; /* struct hdmi_spec_per_cvt */ |
| 123 | hda_nid_t cvt_nids[4]; /* only for haswell fix */ |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 124 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 125 | /* |
| 126 | * num_pins is the number of virtual pins |
| 127 | * for example, there are 3 pins, and each pin |
| 128 | * has 4 device entries, then the num_pins is 12 |
| 129 | */ |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 130 | int num_pins; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 131 | /* |
| 132 | * num_nids is the number of real pins |
| 133 | * In the above example, num_nids is 3 |
| 134 | */ |
| 135 | int num_nids; |
| 136 | /* |
| 137 | * dev_num is the number of device entries |
| 138 | * on each pin. |
| 139 | * In the above example, dev_num is 4 |
| 140 | */ |
| 141 | int dev_num; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 142 | struct snd_array pins; /* struct hdmi_spec_per_pin */ |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 143 | struct hdmi_pcm pcm_rec[16]; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 144 | struct mutex pcm_lock; |
Takashi Iwai | 302d5a8 | 2019-10-29 21:41:20 +0100 | [diff] [blame] | 145 | struct mutex bind_lock; /* for audio component binding */ |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 146 | /* pcm_bitmap means which pcms have been assigned to pins*/ |
| 147 | unsigned long pcm_bitmap; |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 148 | int pcm_used; /* counter of pcm_rec[] */ |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 149 | /* bitmap shows whether the pcm is opened in user space |
| 150 | * bit 0 means the first playback PCM (PCM3); |
| 151 | * bit 1 means the second playback PCM, and so on. |
| 152 | */ |
| 153 | unsigned long pcm_in_use; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 154 | |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 155 | struct hdmi_eld temp_eld; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 156 | struct hdmi_ops ops; |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 157 | |
| 158 | bool dyn_pin_out; |
Libin Yang | 6590faa | 2015-12-16 13:42:41 +0800 | [diff] [blame] | 159 | bool dyn_pcm_assign; |
Takashi Iwai | cb45722 | 2019-11-11 20:09:37 +0100 | [diff] [blame] | 160 | bool intel_hsw_fixup; /* apply Intel platform-specific fixups */ |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 161 | /* |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 162 | * Non-generic VIA/NVIDIA specific |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 163 | */ |
| 164 | struct hda_multi_out multiout; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 165 | struct hda_pcm_stream pcm_playback; |
David Henningsson | 25adc13 | 2015-08-19 10:48:58 +0200 | [diff] [blame] | 166 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 167 | bool use_acomp_notifier; /* use eld_notify callback for hotplug */ |
| 168 | bool acomp_registered; /* audio component registered in this driver */ |
Kai-Heng Feng | cd72c31 | 2020-08-04 23:58:34 +0800 | [diff] [blame] | 169 | bool force_connect; /* force connectivity */ |
Takashi Iwai | ae891ab | 2018-07-11 15:17:22 +0200 | [diff] [blame] | 170 | struct drm_audio_component_audio_ops drm_audio_ops; |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 171 | int (*port2pin)(struct hda_codec *, int); /* reverse port/pin mapping */ |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 172 | |
| 173 | struct hdac_chmap chmap; |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 174 | hda_nid_t vendor_nid; |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 175 | const int *port_map; |
| 176 | int port_num; |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 177 | bool send_silent_stream; /* Flag to enable silent stream feature */ |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 178 | }; |
| 179 | |
Takashi Iwai | a57942b | 2018-07-11 16:23:16 +0200 | [diff] [blame] | 180 | #ifdef CONFIG_SND_HDA_COMPONENT |
Takashi Iwai | 691be97 | 2016-03-18 15:10:08 +0100 | [diff] [blame] | 181 | static inline bool codec_has_acomp(struct hda_codec *codec) |
| 182 | { |
| 183 | struct hdmi_spec *spec = codec->spec; |
| 184 | return spec->use_acomp_notifier; |
| 185 | } |
Takashi Iwai | f4e3040 | 2015-12-10 13:01:28 +0100 | [diff] [blame] | 186 | #else |
| 187 | #define codec_has_acomp(codec) false |
| 188 | #endif |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 189 | |
| 190 | struct hdmi_audio_infoframe { |
| 191 | u8 type; /* 0x84 */ |
| 192 | u8 ver; /* 0x01 */ |
| 193 | u8 len; /* 0x0a */ |
| 194 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 195 | u8 checksum; |
| 196 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 197 | u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */ |
| 198 | u8 SS01_SF24; |
| 199 | u8 CXT04; |
| 200 | u8 CA; |
| 201 | u8 LFEPBL01_LSV36_DM_INH7; |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | struct dp_audio_infoframe { |
| 205 | u8 type; /* 0x84 */ |
| 206 | u8 len; /* 0x1b */ |
| 207 | u8 ver; /* 0x11 << 2 */ |
| 208 | |
| 209 | u8 CC02_CT47; /* match with HDMI infoframe from this on */ |
| 210 | u8 SS01_SF24; |
| 211 | u8 CXT04; |
| 212 | u8 CA; |
| 213 | u8 LFEPBL01_LSV36_DM_INH7; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 214 | }; |
| 215 | |
Takashi Iwai | 2b203dbb | 2011-02-11 12:17:30 +0100 | [diff] [blame] | 216 | union audio_infoframe { |
| 217 | struct hdmi_audio_infoframe hdmi; |
| 218 | struct dp_audio_infoframe dp; |
| 219 | u8 bytes[0]; |
| 220 | }; |
| 221 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 222 | /* |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 223 | * HDMI routines |
| 224 | */ |
| 225 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 226 | #define get_pin(spec, idx) \ |
| 227 | ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx)) |
| 228 | #define get_cvt(spec, idx) \ |
| 229 | ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx)) |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 230 | /* obtain hdmi_pcm object assigned to idx */ |
| 231 | #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx]) |
| 232 | /* obtain hda_pcm object assigned to idx */ |
| 233 | #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm) |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 234 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 235 | static int pin_id_to_pin_index(struct hda_codec *codec, |
| 236 | hda_nid_t pin_nid, int dev_id) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 237 | { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 238 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 239 | int pin_idx; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 240 | struct hdmi_spec_per_pin *per_pin; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 241 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 242 | /* |
| 243 | * (dev_id == -1) means it is NON-MST pin |
| 244 | * return the first virtual pin on this port |
| 245 | */ |
| 246 | if (dev_id == -1) |
| 247 | dev_id = 0; |
| 248 | |
| 249 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
| 250 | per_pin = get_pin(spec, pin_idx); |
| 251 | if ((per_pin->pin_nid == pin_nid) && |
| 252 | (per_pin->dev_id == dev_id)) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 253 | return pin_idx; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 254 | } |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 255 | |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 256 | codec_warn(codec, "HDMI: pin NID 0x%x not registered\n", pin_nid); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 257 | return -EINVAL; |
| 258 | } |
| 259 | |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 260 | static int hinfo_to_pcm_index(struct hda_codec *codec, |
| 261 | struct hda_pcm_stream *hinfo) |
| 262 | { |
| 263 | struct hdmi_spec *spec = codec->spec; |
| 264 | int pcm_idx; |
| 265 | |
| 266 | for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) |
| 267 | if (get_pcm_rec(spec, pcm_idx)->stream == hinfo) |
| 268 | return pcm_idx; |
| 269 | |
Kai Vehmanen | 90670fd | 2020-07-03 18:38:18 +0300 | [diff] [blame] | 270 | codec_warn(codec, "HDMI: hinfo %p not tied to a PCM\n", hinfo); |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 271 | return -EINVAL; |
| 272 | } |
| 273 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 274 | static int hinfo_to_pin_index(struct hda_codec *codec, |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 275 | struct hda_pcm_stream *hinfo) |
| 276 | { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 277 | struct hdmi_spec *spec = codec->spec; |
Libin Yang | 6590faa | 2015-12-16 13:42:41 +0800 | [diff] [blame] | 278 | struct hdmi_spec_per_pin *per_pin; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 279 | int pin_idx; |
| 280 | |
Libin Yang | 6590faa | 2015-12-16 13:42:41 +0800 | [diff] [blame] | 281 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
| 282 | per_pin = get_pin(spec, pin_idx); |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 283 | if (per_pin->pcm && |
| 284 | per_pin->pcm->pcm->stream == hinfo) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 285 | return pin_idx; |
Libin Yang | 6590faa | 2015-12-16 13:42:41 +0800 | [diff] [blame] | 286 | } |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 287 | |
Kai Vehmanen | 90670fd | 2020-07-03 18:38:18 +0300 | [diff] [blame] | 288 | codec_dbg(codec, "HDMI: hinfo %p (pcm %d) not registered\n", hinfo, |
| 289 | hinfo_to_pcm_index(codec, hinfo)); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 290 | return -EINVAL; |
| 291 | } |
| 292 | |
Libin Yang | 022f344 | 2016-02-03 10:48:34 +0800 | [diff] [blame] | 293 | static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec, |
| 294 | int pcm_idx) |
| 295 | { |
| 296 | int i; |
| 297 | struct hdmi_spec_per_pin *per_pin; |
| 298 | |
| 299 | for (i = 0; i < spec->num_pins; i++) { |
| 300 | per_pin = get_pin(spec, i); |
| 301 | if (per_pin->pcm_idx == pcm_idx) |
| 302 | return per_pin; |
| 303 | } |
| 304 | return NULL; |
| 305 | } |
| 306 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 307 | static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 308 | { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 309 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 310 | int cvt_idx; |
| 311 | |
| 312 | for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 313 | if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 314 | return cvt_idx; |
| 315 | |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 316 | codec_warn(codec, "HDMI: cvt NID 0x%x not registered\n", cvt_nid); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 317 | return -EINVAL; |
| 318 | } |
| 319 | |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 320 | static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, |
| 321 | struct snd_ctl_elem_info *uinfo) |
| 322 | { |
| 323 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 324 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 325 | struct hdmi_spec_per_pin *per_pin; |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 326 | struct hdmi_eld *eld; |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 327 | int pcm_idx; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 328 | |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 329 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 330 | |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 331 | pcm_idx = kcontrol->private_value; |
| 332 | mutex_lock(&spec->pcm_lock); |
| 333 | per_pin = pcm_idx_to_pin(spec, pcm_idx); |
| 334 | if (!per_pin) { |
| 335 | /* no pin is bound to the pcm */ |
| 336 | uinfo->count = 0; |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 337 | goto unlock; |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 338 | } |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 339 | eld = &per_pin->sink_eld; |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 340 | uinfo->count = eld->eld_valid ? eld->eld_size : 0; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 341 | |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 342 | unlock: |
| 343 | mutex_unlock(&spec->pcm_lock); |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, |
| 348 | struct snd_ctl_elem_value *ucontrol) |
| 349 | { |
| 350 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 351 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 352 | struct hdmi_spec_per_pin *per_pin; |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 353 | struct hdmi_eld *eld; |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 354 | int pcm_idx; |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 355 | int err = 0; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 356 | |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 357 | pcm_idx = kcontrol->private_value; |
| 358 | mutex_lock(&spec->pcm_lock); |
| 359 | per_pin = pcm_idx_to_pin(spec, pcm_idx); |
| 360 | if (!per_pin) { |
| 361 | /* no pin is bound to the pcm */ |
| 362 | memset(ucontrol->value.bytes.data, 0, |
| 363 | ARRAY_SIZE(ucontrol->value.bytes.data)); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 364 | goto unlock; |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 365 | } |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 366 | |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 367 | eld = &per_pin->sink_eld; |
David Henningsson | 360a824 | 2016-02-05 09:05:41 +0100 | [diff] [blame] | 368 | if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) || |
| 369 | eld->eld_size > ELD_MAX_SIZE) { |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 370 | snd_BUG(); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 371 | err = -EINVAL; |
| 372 | goto unlock; |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | memset(ucontrol->value.bytes.data, 0, |
| 376 | ARRAY_SIZE(ucontrol->value.bytes.data)); |
| 377 | if (eld->eld_valid) |
| 378 | memcpy(ucontrol->value.bytes.data, eld->eld_buffer, |
| 379 | eld->eld_size); |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 380 | |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 381 | unlock: |
| 382 | mutex_unlock(&spec->pcm_lock); |
| 383 | return err; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 384 | } |
| 385 | |
Bhumika Goyal | f3b827e | 2017-02-20 00:18:09 +0530 | [diff] [blame] | 386 | static const struct snd_kcontrol_new eld_bytes_ctl = { |
Takashi Iwai | fbd3eb7 | 2020-01-04 09:35:56 +0100 | [diff] [blame] | 387 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE | |
| 388 | SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK, |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 389 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 390 | .name = "ELD", |
| 391 | .info = hdmi_eld_ctl_info, |
| 392 | .get = hdmi_eld_ctl_get, |
| 393 | }; |
| 394 | |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 395 | static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx, |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 396 | int device) |
| 397 | { |
| 398 | struct snd_kcontrol *kctl; |
| 399 | struct hdmi_spec *spec = codec->spec; |
| 400 | int err; |
| 401 | |
| 402 | kctl = snd_ctl_new1(&eld_bytes_ctl, codec); |
| 403 | if (!kctl) |
| 404 | return -ENOMEM; |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 405 | kctl->private_value = pcm_idx; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 406 | kctl->id.device = device; |
| 407 | |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 408 | /* no pin nid is associated with the kctl now |
| 409 | * tbd: associate pin nid to eld ctl later |
| 410 | */ |
| 411 | err = snd_hda_ctl_add(codec, 0, kctl); |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 412 | if (err < 0) |
| 413 | return err; |
| 414 | |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 415 | get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 419 | #ifdef BE_PARANOID |
| 420 | static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, |
| 421 | int *packet_index, int *byte_index) |
| 422 | { |
| 423 | int val; |
| 424 | |
| 425 | val = snd_hda_codec_read(codec, pin_nid, 0, |
| 426 | AC_VERB_GET_HDMI_DIP_INDEX, 0); |
| 427 | |
| 428 | *packet_index = val >> 5; |
| 429 | *byte_index = val & 0x1f; |
| 430 | } |
| 431 | #endif |
| 432 | |
| 433 | static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, |
| 434 | int packet_index, int byte_index) |
| 435 | { |
| 436 | int val; |
| 437 | |
| 438 | val = (packet_index << 5) | (byte_index & 0x1f); |
| 439 | |
| 440 | snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); |
| 441 | } |
| 442 | |
| 443 | static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid, |
| 444 | unsigned char val) |
| 445 | { |
| 446 | snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); |
| 447 | } |
| 448 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 449 | static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 450 | { |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 451 | struct hdmi_spec *spec = codec->spec; |
| 452 | int pin_out; |
| 453 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 454 | /* Unmute */ |
| 455 | if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) |
| 456 | snd_hda_codec_write(codec, pin_nid, 0, |
| 457 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 458 | |
| 459 | if (spec->dyn_pin_out) |
| 460 | /* Disable pin out until stream is active */ |
| 461 | pin_out = 0; |
| 462 | else |
| 463 | /* Enable pin out: some machines with GM965 gets broken output |
| 464 | * when the pin is disabled or changed while using with HDMI |
| 465 | */ |
| 466 | pin_out = PIN_OUT; |
| 467 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 468 | snd_hda_codec_write(codec, pin_nid, 0, |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 469 | AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 470 | } |
| 471 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 472 | /* |
| 473 | * ELD proc files |
| 474 | */ |
| 475 | |
Jie Yang | cd6a650 | 2015-05-27 19:45:45 +0800 | [diff] [blame] | 476 | #ifdef CONFIG_SND_PROC_FS |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 477 | static void print_eld_info(struct snd_info_entry *entry, |
| 478 | struct snd_info_buffer *buffer) |
| 479 | { |
| 480 | struct hdmi_spec_per_pin *per_pin = entry->private_data; |
| 481 | |
| 482 | mutex_lock(&per_pin->lock); |
| 483 | snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer); |
| 484 | mutex_unlock(&per_pin->lock); |
| 485 | } |
| 486 | |
| 487 | static void write_eld_info(struct snd_info_entry *entry, |
| 488 | struct snd_info_buffer *buffer) |
| 489 | { |
| 490 | struct hdmi_spec_per_pin *per_pin = entry->private_data; |
| 491 | |
| 492 | mutex_lock(&per_pin->lock); |
| 493 | snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer); |
| 494 | mutex_unlock(&per_pin->lock); |
| 495 | } |
| 496 | |
| 497 | static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) |
| 498 | { |
| 499 | char name[32]; |
| 500 | struct hda_codec *codec = per_pin->codec; |
| 501 | struct snd_info_entry *entry; |
| 502 | int err; |
| 503 | |
| 504 | snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); |
Takashi Iwai | 6efdd85 | 2015-02-27 16:09:22 +0100 | [diff] [blame] | 505 | err = snd_card_proc_new(codec->card, name, &entry); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 506 | if (err < 0) |
| 507 | return err; |
| 508 | |
| 509 | snd_info_set_text_ops(entry, per_pin, print_eld_info); |
| 510 | entry->c.text.write = write_eld_info; |
Joe Perches | 6a73cf4 | 2018-05-23 12:20:59 -0700 | [diff] [blame] | 511 | entry->mode |= 0200; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 512 | per_pin->proc_entry = entry; |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) |
| 518 | { |
Markus Elfring | 1947a11 | 2015-06-28 11:15:28 +0200 | [diff] [blame] | 519 | if (!per_pin->codec->bus->shutdown) { |
Takashi Iwai | c560a67 | 2015-04-22 18:26:38 +0200 | [diff] [blame] | 520 | snd_info_free_entry(per_pin->proc_entry); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 521 | per_pin->proc_entry = NULL; |
| 522 | } |
| 523 | } |
| 524 | #else |
Takashi Iwai | b55447a | 2013-10-21 16:31:45 +0200 | [diff] [blame] | 525 | static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin, |
| 526 | int index) |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 527 | { |
| 528 | return 0; |
| 529 | } |
Takashi Iwai | b55447a | 2013-10-21 16:31:45 +0200 | [diff] [blame] | 530 | static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin) |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 531 | { |
| 532 | } |
| 533 | #endif |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 534 | |
| 535 | /* |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 536 | * Audio InfoFrame routines |
| 537 | */ |
| 538 | |
| 539 | /* |
| 540 | * Enable Audio InfoFrame Transmission |
| 541 | */ |
| 542 | static void hdmi_start_infoframe_trans(struct hda_codec *codec, |
| 543 | hda_nid_t pin_nid) |
| 544 | { |
| 545 | hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); |
| 546 | snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, |
| 547 | AC_DIPXMIT_BEST); |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * Disable Audio InfoFrame Transmission |
| 552 | */ |
| 553 | static void hdmi_stop_infoframe_trans(struct hda_codec *codec, |
| 554 | hda_nid_t pin_nid) |
| 555 | { |
| 556 | hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); |
| 557 | snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, |
| 558 | AC_DIPXMIT_DISABLE); |
| 559 | } |
| 560 | |
| 561 | static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid) |
| 562 | { |
| 563 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 564 | int i; |
| 565 | int size; |
| 566 | |
| 567 | size = snd_hdmi_get_eld_size(codec, pin_nid); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 568 | codec_dbg(codec, "HDMI: ELD buf size is %d\n", size); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 569 | |
| 570 | for (i = 0; i < 8; i++) { |
| 571 | size = snd_hda_codec_read(codec, pin_nid, 0, |
| 572 | AC_VERB_GET_HDMI_DIP_SIZE, i); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 573 | codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 574 | } |
| 575 | #endif |
| 576 | } |
| 577 | |
| 578 | static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid) |
| 579 | { |
| 580 | #ifdef BE_PARANOID |
| 581 | int i, j; |
| 582 | int size; |
| 583 | int pi, bi; |
| 584 | for (i = 0; i < 8; i++) { |
| 585 | size = snd_hda_codec_read(codec, pin_nid, 0, |
| 586 | AC_VERB_GET_HDMI_DIP_SIZE, i); |
| 587 | if (size == 0) |
| 588 | continue; |
| 589 | |
| 590 | hdmi_set_dip_index(codec, pin_nid, i, 0x0); |
| 591 | for (j = 1; j < 1000; j++) { |
| 592 | hdmi_write_dip_byte(codec, pin_nid, 0x0); |
| 593 | hdmi_get_dip_index(codec, pin_nid, &pi, &bi); |
| 594 | if (pi != i) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 595 | codec_dbg(codec, "dip index %d: %d != %d\n", |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 596 | bi, pi, i); |
| 597 | if (bi == 0) /* byte index wrapped around */ |
| 598 | break; |
| 599 | } |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 600 | codec_dbg(codec, |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 601 | "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n", |
| 602 | i, size, j); |
| 603 | } |
| 604 | #endif |
| 605 | } |
| 606 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 607 | static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 608 | { |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 609 | u8 *bytes = (u8 *)hdmi_ai; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 610 | u8 sum = 0; |
| 611 | int i; |
| 612 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 613 | hdmi_ai->checksum = 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 614 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 615 | for (i = 0; i < sizeof(*hdmi_ai); i++) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 616 | sum += bytes[i]; |
| 617 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 618 | hdmi_ai->checksum = -sum; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static void hdmi_fill_audio_infoframe(struct hda_codec *codec, |
| 622 | hda_nid_t pin_nid, |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 623 | u8 *dip, int size) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 624 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 625 | int i; |
| 626 | |
| 627 | hdmi_debug_dip_size(codec, pin_nid); |
| 628 | hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */ |
| 629 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 630 | hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 631 | for (i = 0; i < size; i++) |
| 632 | hdmi_write_dip_byte(codec, pin_nid, dip[i]); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid, |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 636 | u8 *dip, int size) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 637 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 638 | u8 val; |
| 639 | int i; |
| 640 | |
Kai Vehmanen | 46c3bbd | 2020-12-11 15:16:13 +0200 | [diff] [blame] | 641 | hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 642 | if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0) |
| 643 | != AC_DIPXMIT_BEST) |
| 644 | return false; |
| 645 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 646 | for (i = 0; i < size; i++) { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 647 | val = snd_hda_codec_read(codec, pin_nid, 0, |
| 648 | AC_VERB_GET_HDMI_DIP_DATA, 0); |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 649 | if (val != dip[i]) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 650 | return false; |
| 651 | } |
| 652 | |
| 653 | return true; |
| 654 | } |
| 655 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 656 | static int hdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid, |
| 657 | int dev_id, unsigned char *buf, int *eld_size) |
| 658 | { |
| 659 | snd_hda_set_dev_select(codec, nid, dev_id); |
| 660 | |
| 661 | return snd_hdmi_get_eld(codec, nid, buf, eld_size); |
| 662 | } |
| 663 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 664 | static void hdmi_pin_setup_infoframe(struct hda_codec *codec, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 665 | hda_nid_t pin_nid, int dev_id, |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 666 | int ca, int active_channels, |
| 667 | int conn_type) |
| 668 | { |
| 669 | union audio_infoframe ai; |
| 670 | |
Mengdong Lin | caaf5ef | 2014-03-11 17:12:52 -0400 | [diff] [blame] | 671 | memset(&ai, 0, sizeof(ai)); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 672 | if (conn_type == 0) { /* HDMI */ |
| 673 | struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi; |
| 674 | |
| 675 | hdmi_ai->type = 0x84; |
| 676 | hdmi_ai->ver = 0x01; |
| 677 | hdmi_ai->len = 0x0a; |
| 678 | hdmi_ai->CC02_CT47 = active_channels - 1; |
| 679 | hdmi_ai->CA = ca; |
| 680 | hdmi_checksum_audio_infoframe(hdmi_ai); |
| 681 | } else if (conn_type == 1) { /* DisplayPort */ |
| 682 | struct dp_audio_infoframe *dp_ai = &ai.dp; |
| 683 | |
| 684 | dp_ai->type = 0x84; |
| 685 | dp_ai->len = 0x1b; |
| 686 | dp_ai->ver = 0x11 << 2; |
| 687 | dp_ai->CC02_CT47 = active_channels - 1; |
| 688 | dp_ai->CA = ca; |
| 689 | } else { |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 690 | codec_dbg(codec, "HDMI: unknown connection type at pin NID 0x%x\n", pin_nid); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 691 | return; |
| 692 | } |
| 693 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 694 | snd_hda_set_dev_select(codec, pin_nid, dev_id); |
| 695 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 696 | /* |
| 697 | * sizeof(ai) is used instead of sizeof(*hdmi_ai) or |
| 698 | * sizeof(*dp_ai) to avoid partial match/update problems when |
| 699 | * the user switches between HDMI/DP monitors. |
| 700 | */ |
| 701 | if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes, |
| 702 | sizeof(ai))) { |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 703 | codec_dbg(codec, "%s: pin NID=0x%x channels=%d ca=0x%02x\n", |
| 704 | __func__, pin_nid, active_channels, ca); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 705 | hdmi_stop_infoframe_trans(codec, pin_nid); |
| 706 | hdmi_fill_audio_infoframe(codec, pin_nid, |
| 707 | ai.bytes, sizeof(ai)); |
| 708 | hdmi_start_infoframe_trans(codec, pin_nid); |
| 709 | } |
| 710 | } |
| 711 | |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 712 | static void hdmi_setup_audio_infoframe(struct hda_codec *codec, |
| 713 | struct hdmi_spec_per_pin *per_pin, |
| 714 | bool non_pcm) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 715 | { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 716 | struct hdmi_spec *spec = codec->spec; |
Subhransu S. Prusty | 739ffee | 2016-03-04 19:59:49 +0530 | [diff] [blame] | 717 | struct hdac_chmap *chmap = &spec->chmap; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 718 | hda_nid_t pin_nid = per_pin->pin_nid; |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 719 | int dev_id = per_pin->dev_id; |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 720 | int channels = per_pin->channels; |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 721 | int active_channels; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 722 | struct hdmi_eld *eld; |
Subhransu S. Prusty | 828cb4e | 2016-03-04 19:59:50 +0530 | [diff] [blame] | 723 | int ca; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 724 | |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 725 | if (!channels) |
| 726 | return; |
| 727 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 728 | snd_hda_set_dev_select(codec, pin_nid, dev_id); |
| 729 | |
Takashi Iwai | 44bb6d0 | 2016-03-21 12:36:44 +0100 | [diff] [blame] | 730 | /* some HW (e.g. HSW+) needs reprogramming the amp at each time */ |
| 731 | if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) |
Mengdong Lin | 58f7d28 | 2013-09-04 16:37:12 -0400 | [diff] [blame] | 732 | snd_hda_codec_write(codec, pin_nid, 0, |
| 733 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 734 | AMP_OUT_UNMUTE); |
| 735 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 736 | eld = &per_pin->sink_eld; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 737 | |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 738 | ca = snd_hdac_channel_allocation(&codec->core, |
Subhransu S. Prusty | 828cb4e | 2016-03-04 19:59:50 +0530 | [diff] [blame] | 739 | eld->info.spk_alloc, channels, |
| 740 | per_pin->chmap_set, non_pcm, per_pin->chmap); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 741 | |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 742 | active_channels = snd_hdac_get_active_channels(ca); |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 743 | |
Subhransu S. Prusty | 739ffee | 2016-03-04 19:59:49 +0530 | [diff] [blame] | 744 | chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid, |
| 745 | active_channels); |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 746 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 747 | /* |
Anssi Hannula | 39edac7 | 2013-10-07 19:24:52 +0300 | [diff] [blame] | 748 | * always configure channel mapping, it may have been changed by the |
| 749 | * user in the meantime |
| 750 | */ |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 751 | snd_hdac_setup_channel_mapping(&spec->chmap, |
Subhransu S. Prusty | 828cb4e | 2016-03-04 19:59:50 +0530 | [diff] [blame] | 752 | pin_nid, non_pcm, ca, channels, |
| 753 | per_pin->chmap, per_pin->chmap_set); |
Anssi Hannula | 39edac7 | 2013-10-07 19:24:52 +0300 | [diff] [blame] | 754 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 755 | spec->ops.pin_setup_infoframe(codec, pin_nid, dev_id, |
| 756 | ca, active_channels, eld->info.conn_type); |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 757 | |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 758 | per_pin->non_pcm = non_pcm; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 759 | } |
| 760 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 761 | /* |
| 762 | * Unsolicited events |
| 763 | */ |
| 764 | |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 765 | static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); |
Takashi Iwai | 38faddb | 2010-07-28 14:21:55 +0200 | [diff] [blame] | 766 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 767 | static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid, |
| 768 | int dev_id) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 769 | { |
| 770 | struct hdmi_spec *spec = codec->spec; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 771 | int pin_idx = pin_id_to_pin_index(codec, nid, dev_id); |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 772 | |
David Henningsson | 20ce902 | 2013-12-04 10:19:41 +0800 | [diff] [blame] | 773 | if (pin_idx < 0) |
| 774 | return; |
Chris Wilson | aaa23f8 | 2018-06-27 07:25:32 +0100 | [diff] [blame] | 775 | mutex_lock(&spec->pcm_lock); |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 776 | hdmi_present_sense(get_pin(spec, pin_idx), 1); |
Chris Wilson | aaa23f8 | 2018-06-27 07:25:32 +0100 | [diff] [blame] | 777 | mutex_unlock(&spec->pcm_lock); |
David Henningsson | 20ce902 | 2013-12-04 10:19:41 +0800 | [diff] [blame] | 778 | } |
| 779 | |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 780 | static void jack_callback(struct hda_codec *codec, |
| 781 | struct hda_jack_callback *jack) |
| 782 | { |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 783 | /* stop polling when notification is enabled */ |
| 784 | if (codec_has_acomp(codec)) |
| 785 | return; |
| 786 | |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 787 | check_presence_and_report(codec, jack->nid, jack->dev_id); |
Takashi Iwai | 1a4f69d | 2014-09-11 15:22:46 +0200 | [diff] [blame] | 788 | } |
| 789 | |
Takashi Iwai | 165c094 | 2020-02-06 17:28:01 +0100 | [diff] [blame] | 790 | static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res, |
| 791 | struct hda_jack_tbl *jack) |
David Henningsson | 20ce902 | 2013-12-04 10:19:41 +0800 | [diff] [blame] | 792 | { |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 793 | jack->jack_dirty = 1; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 794 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 795 | codec_dbg(codec, |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 796 | "HDMI hot plug event: Codec=%d NID=0x%x Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n", |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 797 | codec->addr, jack->nid, jack->dev_id, !!(res & AC_UNSOL_RES_IA), |
Fengguang Wu | fae3d88 | 2012-04-10 17:00:35 +0800 | [diff] [blame] | 798 | !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV)); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 799 | |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 800 | check_presence_and_report(codec, jack->nid, jack->dev_id); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) |
| 804 | { |
| 805 | int tag = res >> AC_UNSOL_RES_TAG_SHIFT; |
| 806 | int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; |
| 807 | int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); |
| 808 | int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); |
| 809 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 810 | codec_info(codec, |
Takashi Iwai | e9ea8e8 | 2012-06-21 11:41:05 +0200 | [diff] [blame] | 811 | "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 812 | codec->addr, |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 813 | tag, |
| 814 | subtag, |
| 815 | cp_state, |
| 816 | cp_ready); |
| 817 | |
| 818 | /* TODO */ |
Pierre-Louis Bossart | 75663c0 | 2020-01-13 15:14:05 -0600 | [diff] [blame] | 819 | if (cp_state) { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 820 | ; |
Pierre-Louis Bossart | 75663c0 | 2020-01-13 15:14:05 -0600 | [diff] [blame] | 821 | } |
| 822 | if (cp_ready) { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 823 | ; |
Pierre-Louis Bossart | 75663c0 | 2020-01-13 15:14:05 -0600 | [diff] [blame] | 824 | } |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | |
| 828 | static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res) |
| 829 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 830 | int tag = res >> AC_UNSOL_RES_TAG_SHIFT; |
| 831 | int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 832 | struct hda_jack_tbl *jack; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 833 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 834 | if (codec_has_acomp(codec)) |
| 835 | return; |
| 836 | |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 837 | if (codec->dp_mst) { |
| 838 | int dev_entry = |
| 839 | (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT; |
| 840 | |
| 841 | jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry); |
| 842 | } else { |
| 843 | jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0); |
| 844 | } |
| 845 | |
| 846 | if (!jack) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 847 | codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 848 | return; |
| 849 | } |
| 850 | |
| 851 | if (subtag == 0) |
Takashi Iwai | 165c094 | 2020-02-06 17:28:01 +0100 | [diff] [blame] | 852 | hdmi_intrinsic_event(codec, res, jack); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 853 | else |
| 854 | hdmi_non_intrinsic_event(codec, res); |
| 855 | } |
| 856 | |
Mengdong Lin | 58f7d28 | 2013-09-04 16:37:12 -0400 | [diff] [blame] | 857 | static void haswell_verify_D0(struct hda_codec *codec, |
Wang Xingchao | 53b434f | 2013-06-18 10:41:53 +0800 | [diff] [blame] | 858 | hda_nid_t cvt_nid, hda_nid_t nid) |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 859 | { |
Mengdong Lin | 58f7d28 | 2013-09-04 16:37:12 -0400 | [diff] [blame] | 860 | int pwr; |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 861 | |
Wang Xingchao | 53b434f | 2013-06-18 10:41:53 +0800 | [diff] [blame] | 862 | /* For Haswell, the converter 1/2 may keep in D3 state after bootup, |
| 863 | * thus pins could only choose converter 0 for use. Make sure the |
| 864 | * converters are in correct power state */ |
Takashi Iwai | fd678ca | 2013-06-18 16:28:36 +0200 | [diff] [blame] | 865 | if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0)) |
Wang Xingchao | 53b434f | 2013-06-18 10:41:53 +0800 | [diff] [blame] | 866 | snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 867 | |
Takashi Iwai | fd678ca | 2013-06-18 16:28:36 +0200 | [diff] [blame] | 868 | if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) { |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 869 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, |
| 870 | AC_PWRST_D0); |
| 871 | msleep(40); |
| 872 | pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0); |
| 873 | pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT; |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 874 | codec_dbg(codec, "Haswell HDMI audio: Power for NID 0x%x is now D%d\n", nid, pwr); |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 875 | } |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 876 | } |
| 877 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 878 | /* |
| 879 | * Callbacks |
| 880 | */ |
| 881 | |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 882 | /* HBR should be Non-PCM, 8 channels */ |
| 883 | #define is_hbr_format(format) \ |
| 884 | ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7) |
| 885 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 886 | static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 887 | int dev_id, bool hbr) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 888 | { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 889 | int pinctl, new_pinctl; |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 890 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 891 | if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) { |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 892 | snd_hda_set_dev_select(codec, pin_nid, dev_id); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 893 | pinctl = snd_hda_codec_read(codec, pin_nid, 0, |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 894 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 895 | |
Anssi Hannula | 13122e6 | 2013-11-10 20:56:10 +0200 | [diff] [blame] | 896 | if (pinctl < 0) |
| 897 | return hbr ? -EINVAL : 0; |
| 898 | |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 899 | new_pinctl = pinctl & ~AC_PINCTL_EPT; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 900 | if (hbr) |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 901 | new_pinctl |= AC_PINCTL_EPT_HBR; |
| 902 | else |
| 903 | new_pinctl |= AC_PINCTL_EPT_NATIVE; |
| 904 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 905 | codec_dbg(codec, |
| 906 | "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n", |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 907 | pin_nid, |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 908 | pinctl == new_pinctl ? "" : "new-", |
| 909 | new_pinctl); |
| 910 | |
| 911 | if (pinctl != new_pinctl) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 912 | snd_hda_codec_write(codec, pin_nid, 0, |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 913 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 914 | new_pinctl); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 915 | } else if (hbr) |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 916 | return -EINVAL; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 922 | hda_nid_t pin_nid, int dev_id, |
| 923 | u32 stream_tag, int format) |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 924 | { |
| 925 | struct hdmi_spec *spec = codec->spec; |
Sriram Periyasamy | 5a5d718 | 2017-09-19 17:25:05 -0500 | [diff] [blame] | 926 | unsigned int param; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 927 | int err; |
| 928 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 929 | err = spec->ops.pin_hbr_setup(codec, pin_nid, dev_id, |
| 930 | is_hbr_format(format)); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 931 | |
| 932 | if (err) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 933 | codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n"); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 934 | return err; |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 935 | } |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 936 | |
Takashi Iwai | cb45722 | 2019-11-11 20:09:37 +0100 | [diff] [blame] | 937 | if (spec->intel_hsw_fixup) { |
Sriram Periyasamy | 5a5d718 | 2017-09-19 17:25:05 -0500 | [diff] [blame] | 938 | |
| 939 | /* |
| 940 | * on recent platforms IEC Coding Type is required for HBR |
| 941 | * support, read current Digital Converter settings and set |
| 942 | * ICT bitfield if needed. |
| 943 | */ |
| 944 | param = snd_hda_codec_read(codec, cvt_nid, 0, |
| 945 | AC_VERB_GET_DIGI_CONVERT_1, 0); |
| 946 | |
| 947 | param = (param >> 16) & ~(AC_DIG3_ICT); |
| 948 | |
| 949 | /* on recent platforms ICT mode is required for HBR support */ |
| 950 | if (is_hbr_format(format)) |
| 951 | param |= 0x1; |
| 952 | |
| 953 | snd_hda_codec_write(codec, cvt_nid, 0, |
| 954 | AC_VERB_SET_DIGI_CONVERT_3, param); |
| 955 | } |
| 956 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 957 | snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format); |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 958 | return 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 959 | } |
| 960 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 961 | /* Try to find an available converter |
| 962 | * If pin_idx is less then zero, just try to find an available converter. |
| 963 | * Otherwise, try to find an available converter and get the cvt mux index |
| 964 | * of the pin. |
| 965 | */ |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 966 | static int hdmi_choose_cvt(struct hda_codec *codec, |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 967 | int pin_idx, int *cvt_id) |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 968 | { |
| 969 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 970 | struct hdmi_spec_per_pin *per_pin; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 971 | struct hdmi_spec_per_cvt *per_cvt = NULL; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 972 | int cvt_idx, mux_idx = 0; |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 973 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 974 | /* pin_idx < 0 means no pin will be bound to the converter */ |
| 975 | if (pin_idx < 0) |
| 976 | per_pin = NULL; |
| 977 | else |
| 978 | per_pin = get_pin(spec, pin_idx); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 979 | |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 980 | if (per_pin && per_pin->silent_stream) { |
| 981 | cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid); |
| 982 | if (cvt_id) |
| 983 | *cvt_id = cvt_idx; |
| 984 | return 0; |
| 985 | } |
| 986 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 987 | /* Dynamically assign converter to stream */ |
| 988 | for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 989 | per_cvt = get_cvt(spec, cvt_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 990 | |
| 991 | /* Must not already be assigned */ |
| 992 | if (per_cvt->assigned) |
| 993 | continue; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 994 | if (per_pin == NULL) |
| 995 | break; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 996 | /* Must be in pin's mux's list of converters */ |
| 997 | for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++) |
| 998 | if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid) |
| 999 | break; |
| 1000 | /* Not in mux list */ |
| 1001 | if (mux_idx == per_pin->num_mux_nids) |
| 1002 | continue; |
| 1003 | break; |
| 1004 | } |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1005 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1006 | /* No free converters */ |
| 1007 | if (cvt_idx == spec->num_cvts) |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1008 | return -EBUSY; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1009 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1010 | if (per_pin != NULL) |
| 1011 | per_pin->mux_idx = mux_idx; |
Mengdong Lin | 2df6742 | 2014-03-20 13:01:06 +0800 | [diff] [blame] | 1012 | |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1013 | if (cvt_id) |
| 1014 | *cvt_id = cvt_idx; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
Mengdong Lin | 2df6742 | 2014-03-20 13:01:06 +0800 | [diff] [blame] | 1019 | /* Assure the pin select the right convetor */ |
| 1020 | static void intel_verify_pin_cvt_connect(struct hda_codec *codec, |
| 1021 | struct hdmi_spec_per_pin *per_pin) |
| 1022 | { |
| 1023 | hda_nid_t pin_nid = per_pin->pin_nid; |
| 1024 | int mux_idx, curr; |
| 1025 | |
| 1026 | mux_idx = per_pin->mux_idx; |
| 1027 | curr = snd_hda_codec_read(codec, pin_nid, 0, |
| 1028 | AC_VERB_GET_CONNECT_SEL, 0); |
| 1029 | if (curr != mux_idx) |
| 1030 | snd_hda_codec_write_cache(codec, pin_nid, 0, |
| 1031 | AC_VERB_SET_CONNECT_SEL, |
| 1032 | mux_idx); |
| 1033 | } |
| 1034 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1035 | /* get the mux index for the converter of the pins |
| 1036 | * converter's mux index is the same for all pins on Intel platform |
| 1037 | */ |
| 1038 | static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec, |
| 1039 | hda_nid_t cvt_nid) |
| 1040 | { |
| 1041 | int i; |
| 1042 | |
| 1043 | for (i = 0; i < spec->num_cvts; i++) |
| 1044 | if (spec->cvt_nids[i] == cvt_nid) |
| 1045 | return i; |
| 1046 | return -EINVAL; |
| 1047 | } |
| 1048 | |
Mengdong Lin | 300016b | 2013-11-04 01:13:13 -0500 | [diff] [blame] | 1049 | /* Intel HDMI workaround to fix audio routing issue: |
| 1050 | * For some Intel display codecs, pins share the same connection list. |
| 1051 | * So a conveter can be selected by multiple pins and playback on any of these |
| 1052 | * pins will generate sound on the external display, because audio flows from |
| 1053 | * the same converter to the display pipeline. Also muting one pin may make |
| 1054 | * other pins have no sound output. |
| 1055 | * So this function assures that an assigned converter for a pin is not selected |
| 1056 | * by any other pins. |
| 1057 | */ |
| 1058 | static void intel_not_share_assigned_cvt(struct hda_codec *codec, |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1059 | hda_nid_t pin_nid, |
| 1060 | int dev_id, int mux_idx) |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1061 | { |
| 1062 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 1063 | hda_nid_t nid; |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1064 | int cvt_idx, curr; |
| 1065 | struct hdmi_spec_per_cvt *per_cvt; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1066 | struct hdmi_spec_per_pin *per_pin; |
| 1067 | int pin_idx; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1068 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1069 | /* configure the pins connections */ |
| 1070 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
| 1071 | int dev_id_saved; |
| 1072 | int dev_num; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1073 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1074 | per_pin = get_pin(spec, pin_idx); |
| 1075 | /* |
| 1076 | * pin not connected to monitor |
| 1077 | * no need to operate on it |
| 1078 | */ |
| 1079 | if (!per_pin->pcm) |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1080 | continue; |
| 1081 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1082 | if ((per_pin->pin_nid == pin_nid) && |
| 1083 | (per_pin->dev_id == dev_id)) |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1084 | continue; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1085 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1086 | /* |
| 1087 | * if per_pin->dev_id >= dev_num, |
| 1088 | * snd_hda_get_dev_select() will fail, |
| 1089 | * and the following operation is unpredictable. |
| 1090 | * So skip this situation. |
| 1091 | */ |
| 1092 | dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1; |
| 1093 | if (per_pin->dev_id >= dev_num) |
| 1094 | continue; |
| 1095 | |
| 1096 | nid = per_pin->pin_nid; |
| 1097 | |
| 1098 | /* |
| 1099 | * Calling this function should not impact |
| 1100 | * on the device entry selection |
| 1101 | * So let's save the dev id for each pin, |
| 1102 | * and restore it when return |
| 1103 | */ |
| 1104 | dev_id_saved = snd_hda_get_dev_select(codec, nid); |
| 1105 | snd_hda_set_dev_select(codec, nid, per_pin->dev_id); |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1106 | curr = snd_hda_codec_read(codec, nid, 0, |
| 1107 | AC_VERB_GET_CONNECT_SEL, 0); |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1108 | if (curr != mux_idx) { |
| 1109 | snd_hda_set_dev_select(codec, nid, dev_id_saved); |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1110 | continue; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1111 | } |
| 1112 | |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1113 | |
| 1114 | /* choose an unassigned converter. The conveters in the |
| 1115 | * connection list are in the same order as in the codec. |
| 1116 | */ |
| 1117 | for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { |
| 1118 | per_cvt = get_cvt(spec, cvt_idx); |
| 1119 | if (!per_cvt->assigned) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1120 | codec_dbg(codec, |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 1121 | "choose cvt %d for pin NID 0x%x\n", |
| 1122 | cvt_idx, nid); |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1123 | snd_hda_codec_write_cache(codec, nid, 0, |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1124 | AC_VERB_SET_CONNECT_SEL, |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1125 | cvt_idx); |
| 1126 | break; |
| 1127 | } |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1128 | } |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1129 | snd_hda_set_dev_select(codec, nid, dev_id_saved); |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1133 | /* A wrapper of intel_not_share_asigned_cvt() */ |
| 1134 | static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec, |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1135 | hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid) |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1136 | { |
| 1137 | int mux_idx; |
| 1138 | struct hdmi_spec *spec = codec->spec; |
| 1139 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1140 | /* On Intel platform, the mapping of converter nid to |
| 1141 | * mux index of the pins are always the same. |
| 1142 | * The pin nid may be 0, this means all pins will not |
| 1143 | * share the converter. |
| 1144 | */ |
| 1145 | mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid); |
| 1146 | if (mux_idx >= 0) |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1147 | intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx); |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1148 | } |
| 1149 | |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 1150 | /* skeleton caller of pin_cvt_fixup ops */ |
| 1151 | static void pin_cvt_fixup(struct hda_codec *codec, |
| 1152 | struct hdmi_spec_per_pin *per_pin, |
| 1153 | hda_nid_t cvt_nid) |
| 1154 | { |
| 1155 | struct hdmi_spec *spec = codec->spec; |
| 1156 | |
| 1157 | if (spec->ops.pin_cvt_fixup) |
| 1158 | spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid); |
| 1159 | } |
| 1160 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1161 | /* called in hdmi_pcm_open when no pin is assigned to the PCM |
| 1162 | * in dyn_pcm_assign mode. |
| 1163 | */ |
| 1164 | static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo, |
| 1165 | struct hda_codec *codec, |
| 1166 | struct snd_pcm_substream *substream) |
| 1167 | { |
| 1168 | struct hdmi_spec *spec = codec->spec; |
| 1169 | struct snd_pcm_runtime *runtime = substream->runtime; |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1170 | int cvt_idx, pcm_idx; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1171 | struct hdmi_spec_per_cvt *per_cvt = NULL; |
| 1172 | int err; |
| 1173 | |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1174 | pcm_idx = hinfo_to_pcm_index(codec, hinfo); |
| 1175 | if (pcm_idx < 0) |
| 1176 | return -EINVAL; |
| 1177 | |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 1178 | err = hdmi_choose_cvt(codec, -1, &cvt_idx); |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1179 | if (err) |
| 1180 | return err; |
| 1181 | |
| 1182 | per_cvt = get_cvt(spec, cvt_idx); |
| 1183 | per_cvt->assigned = 1; |
| 1184 | hinfo->nid = per_cvt->cvt_nid; |
| 1185 | |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 1186 | pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid); |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1187 | |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1188 | set_bit(pcm_idx, &spec->pcm_in_use); |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1189 | /* todo: setup spdif ctls assign */ |
| 1190 | |
| 1191 | /* Initially set the converter's capabilities */ |
| 1192 | hinfo->channels_min = per_cvt->channels_min; |
| 1193 | hinfo->channels_max = per_cvt->channels_max; |
| 1194 | hinfo->rates = per_cvt->rates; |
| 1195 | hinfo->formats = per_cvt->formats; |
| 1196 | hinfo->maxbps = per_cvt->maxbps; |
| 1197 | |
| 1198 | /* Store the updated parameters */ |
| 1199 | runtime->hw.channels_min = hinfo->channels_min; |
| 1200 | runtime->hw.channels_max = hinfo->channels_max; |
| 1201 | runtime->hw.formats = hinfo->formats; |
| 1202 | runtime->hw.rates = hinfo->rates; |
| 1203 | |
| 1204 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 1205 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
| 1206 | return 0; |
| 1207 | } |
| 1208 | |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1209 | /* |
| 1210 | * HDA PCM callbacks |
| 1211 | */ |
| 1212 | static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, |
| 1213 | struct hda_codec *codec, |
| 1214 | struct snd_pcm_substream *substream) |
| 1215 | { |
| 1216 | struct hdmi_spec *spec = codec->spec; |
| 1217 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 1218 | int pin_idx, cvt_idx, pcm_idx; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1219 | struct hdmi_spec_per_pin *per_pin; |
| 1220 | struct hdmi_eld *eld; |
| 1221 | struct hdmi_spec_per_cvt *per_cvt = NULL; |
| 1222 | int err; |
| 1223 | |
| 1224 | /* Validate hinfo */ |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 1225 | pcm_idx = hinfo_to_pcm_index(codec, hinfo); |
| 1226 | if (pcm_idx < 0) |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1227 | return -EINVAL; |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 1228 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1229 | mutex_lock(&spec->pcm_lock); |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1230 | pin_idx = hinfo_to_pin_index(codec, hinfo); |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1231 | if (!spec->dyn_pcm_assign) { |
| 1232 | if (snd_BUG_ON(pin_idx < 0)) { |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 1233 | err = -EINVAL; |
| 1234 | goto unlock; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1235 | } |
| 1236 | } else { |
| 1237 | /* no pin is assigned to the PCM |
| 1238 | * PA need pcm open successfully when probe |
| 1239 | */ |
| 1240 | if (pin_idx < 0) { |
| 1241 | err = hdmi_pcm_open_no_pin(hinfo, codec, substream); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 1242 | goto unlock; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1243 | } |
| 1244 | } |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1245 | |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 1246 | err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 1247 | if (err < 0) |
| 1248 | goto unlock; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1249 | |
| 1250 | per_cvt = get_cvt(spec, cvt_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1251 | /* Claim converter */ |
| 1252 | per_cvt->assigned = 1; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1253 | |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1254 | set_bit(pcm_idx, &spec->pcm_in_use); |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1255 | per_pin = get_pin(spec, pin_idx); |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 1256 | per_pin->cvt_nid = per_cvt->cvt_nid; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1257 | hinfo->nid = per_cvt->cvt_nid; |
| 1258 | |
Takashi Iwai | e38e486 | 2019-12-02 08:49:47 +0100 | [diff] [blame] | 1259 | /* flip stripe flag for the assigned stream if supported */ |
| 1260 | if (get_wcaps(codec, per_cvt->cvt_nid) & AC_WCAP_STRIPE) |
| 1261 | azx_stream(get_azx_dev(substream))->stripe = 1; |
| 1262 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1263 | snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id); |
Takashi Iwai | bddee96 | 2013-06-18 16:14:22 +0200 | [diff] [blame] | 1264 | snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1265 | AC_VERB_SET_CONNECT_SEL, |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 1266 | per_pin->mux_idx); |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1267 | |
| 1268 | /* configure unused pins to choose other converters */ |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 1269 | pin_cvt_fixup(codec, per_pin, 0); |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1270 | |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 1271 | snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1272 | |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 1273 | /* Initially set the converter's capabilities */ |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1274 | hinfo->channels_min = per_cvt->channels_min; |
| 1275 | hinfo->channels_max = per_cvt->channels_max; |
| 1276 | hinfo->rates = per_cvt->rates; |
| 1277 | hinfo->formats = per_cvt->formats; |
| 1278 | hinfo->maxbps = per_cvt->maxbps; |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 1279 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 1280 | eld = &per_pin->sink_eld; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1281 | /* Restrict capabilities by ELD if this isn't disabled */ |
Stephen Warren | c3d5210 | 2011-06-01 11:14:16 -0600 | [diff] [blame] | 1282 | if (!static_hdmi_pcm && eld->eld_valid) { |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 1283 | snd_hdmi_eld_update_pcm_info(&eld->info, hinfo); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1284 | if (hinfo->channels_min > hinfo->channels_max || |
Takashi Iwai | 2ad779b | 2013-02-01 14:01:27 +0100 | [diff] [blame] | 1285 | !hinfo->rates || !hinfo->formats) { |
| 1286 | per_cvt->assigned = 0; |
| 1287 | hinfo->nid = 0; |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 1288 | snd_hda_spdif_ctls_unassign(codec, pcm_idx); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 1289 | err = -ENODEV; |
| 1290 | goto unlock; |
Takashi Iwai | 2ad779b | 2013-02-01 14:01:27 +0100 | [diff] [blame] | 1291 | } |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1292 | } |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 1293 | |
| 1294 | /* Store the updated parameters */ |
Takashi Iwai | 639cef0 | 2011-01-14 10:30:46 +0100 | [diff] [blame] | 1295 | runtime->hw.channels_min = hinfo->channels_min; |
| 1296 | runtime->hw.channels_max = hinfo->channels_max; |
| 1297 | runtime->hw.formats = hinfo->formats; |
| 1298 | runtime->hw.rates = hinfo->rates; |
Takashi Iwai | 4fe2ca1 | 2011-01-14 10:33:26 +0100 | [diff] [blame] | 1299 | |
| 1300 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 1301 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 1302 | unlock: |
| 1303 | mutex_unlock(&spec->pcm_lock); |
| 1304 | return err; |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /* |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1308 | * HDA/HDMI auto parsing |
| 1309 | */ |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1310 | static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1311 | { |
| 1312 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1313 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1314 | hda_nid_t pin_nid = per_pin->pin_nid; |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 1315 | int dev_id = per_pin->dev_id; |
Kai Vehmanen | ae25488 | 2019-11-27 18:12:40 +0200 | [diff] [blame] | 1316 | int conns; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1317 | |
| 1318 | if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1319 | codec_warn(codec, |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 1320 | "HDMI: pin NID 0x%x wcaps %#x does not support connection list\n", |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1321 | pin_nid, get_wcaps(codec, pin_nid)); |
| 1322 | return -EINVAL; |
| 1323 | } |
| 1324 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 1325 | snd_hda_set_dev_select(codec, pin_nid, dev_id); |
| 1326 | |
Kai Vehmanen | ae25488 | 2019-11-27 18:12:40 +0200 | [diff] [blame] | 1327 | if (spec->intel_hsw_fixup) { |
| 1328 | conns = spec->num_cvts; |
| 1329 | memcpy(per_pin->mux_nids, spec->cvt_nids, |
| 1330 | sizeof(hda_nid_t) * conns); |
| 1331 | } else { |
| 1332 | conns = snd_hda_get_raw_connections(codec, pin_nid, |
| 1333 | per_pin->mux_nids, |
| 1334 | HDA_MAX_CONNECTIONS); |
| 1335 | } |
| 1336 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1337 | /* all the device entries on the same pin have the same conn list */ |
Kai Vehmanen | ae25488 | 2019-11-27 18:12:40 +0200 | [diff] [blame] | 1338 | per_pin->num_mux_nids = conns; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1343 | static int hdmi_find_pcm_slot(struct hdmi_spec *spec, |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 1344 | struct hdmi_spec_per_pin *per_pin) |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1345 | { |
| 1346 | int i; |
| 1347 | |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 1348 | /* |
Kai Vehmanen | 0c0fe9e | 2019-11-29 16:37:55 +0200 | [diff] [blame] | 1349 | * generic_hdmi_build_pcms() may allocate extra PCMs on some |
| 1350 | * platforms (with maximum of 'num_nids + dev_num - 1') |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 1351 | * |
| 1352 | * The per_pin of pin_nid_idx=n and dev_id=m prefers to get pcm-n |
| 1353 | * if m==0. This guarantees that dynamic pcm assignments are compatible |
Kai Vehmanen | 0c0fe9e | 2019-11-29 16:37:55 +0200 | [diff] [blame] | 1354 | * with the legacy static per_pin-pcm assignment that existed in the |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 1355 | * days before DP-MST. |
| 1356 | * |
Takashi Iwai | 643a2cc | 2019-12-03 16:41:05 +0100 | [diff] [blame] | 1357 | * Intel DP-MST prefers this legacy behavior for compatibility, too. |
| 1358 | * |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 1359 | * per_pin of m!=0 prefers to get pcm=(num_nids + (m - 1)). |
| 1360 | */ |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1361 | |
Takashi Iwai | 643a2cc | 2019-12-03 16:41:05 +0100 | [diff] [blame] | 1362 | if (per_pin->dev_id == 0 || spec->intel_hsw_fixup) { |
Kai Vehmanen | 0c0fe9e | 2019-11-29 16:37:55 +0200 | [diff] [blame] | 1363 | if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap)) |
| 1364 | return per_pin->pin_nid_idx; |
| 1365 | } else { |
| 1366 | i = spec->num_nids + (per_pin->dev_id - 1); |
| 1367 | if (i < spec->pcm_used && !(test_bit(i, &spec->pcm_bitmap))) |
| 1368 | return i; |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /* have a second try; check the area over num_nids */ |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1372 | for (i = spec->num_nids; i < spec->pcm_used; i++) { |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1373 | if (!test_bit(i, &spec->pcm_bitmap)) |
| 1374 | return i; |
| 1375 | } |
| 1376 | |
| 1377 | /* the last try; check the empty slots in pins */ |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1378 | for (i = 0; i < spec->num_nids; i++) { |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1379 | if (!test_bit(i, &spec->pcm_bitmap)) |
| 1380 | return i; |
| 1381 | } |
| 1382 | return -EBUSY; |
| 1383 | } |
| 1384 | |
| 1385 | static void hdmi_attach_hda_pcm(struct hdmi_spec *spec, |
| 1386 | struct hdmi_spec_per_pin *per_pin) |
| 1387 | { |
| 1388 | int idx; |
| 1389 | |
| 1390 | /* pcm already be attached to the pin */ |
| 1391 | if (per_pin->pcm) |
| 1392 | return; |
| 1393 | idx = hdmi_find_pcm_slot(spec, per_pin); |
Libin Yang | d10a80d | 2016-03-01 15:18:26 +0800 | [diff] [blame] | 1394 | if (idx == -EBUSY) |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1395 | return; |
| 1396 | per_pin->pcm_idx = idx; |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 1397 | per_pin->pcm = get_hdmi_pcm(spec, idx); |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1398 | set_bit(idx, &spec->pcm_bitmap); |
| 1399 | } |
| 1400 | |
| 1401 | static void hdmi_detach_hda_pcm(struct hdmi_spec *spec, |
| 1402 | struct hdmi_spec_per_pin *per_pin) |
| 1403 | { |
| 1404 | int idx; |
| 1405 | |
| 1406 | /* pcm already be detached from the pin */ |
| 1407 | if (!per_pin->pcm) |
| 1408 | return; |
| 1409 | idx = per_pin->pcm_idx; |
| 1410 | per_pin->pcm_idx = -1; |
| 1411 | per_pin->pcm = NULL; |
| 1412 | if (idx >= 0 && idx < spec->pcm_used) |
| 1413 | clear_bit(idx, &spec->pcm_bitmap); |
| 1414 | } |
| 1415 | |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1416 | static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec, |
| 1417 | struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid) |
| 1418 | { |
| 1419 | int mux_idx; |
| 1420 | |
| 1421 | for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++) |
| 1422 | if (per_pin->mux_nids[mux_idx] == cvt_nid) |
| 1423 | break; |
| 1424 | return mux_idx; |
| 1425 | } |
| 1426 | |
| 1427 | static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid); |
| 1428 | |
| 1429 | static void hdmi_pcm_setup_pin(struct hdmi_spec *spec, |
| 1430 | struct hdmi_spec_per_pin *per_pin) |
| 1431 | { |
| 1432 | struct hda_codec *codec = per_pin->codec; |
| 1433 | struct hda_pcm *pcm; |
| 1434 | struct hda_pcm_stream *hinfo; |
| 1435 | struct snd_pcm_substream *substream; |
| 1436 | int mux_idx; |
| 1437 | bool non_pcm; |
| 1438 | |
| 1439 | if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used) |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 1440 | pcm = get_pcm_rec(spec, per_pin->pcm_idx); |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1441 | else |
| 1442 | return; |
Takashi Iwai | 8a7d600 | 2018-04-25 16:19:13 +0200 | [diff] [blame] | 1443 | if (!pcm->pcm) |
| 1444 | return; |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1445 | if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use)) |
| 1446 | return; |
| 1447 | |
| 1448 | /* hdmi audio only uses playback and one substream */ |
| 1449 | hinfo = pcm->stream; |
| 1450 | substream = pcm->pcm->streams[0].substream; |
| 1451 | |
| 1452 | per_pin->cvt_nid = hinfo->nid; |
| 1453 | |
| 1454 | mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid); |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1455 | if (mux_idx < per_pin->num_mux_nids) { |
| 1456 | snd_hda_set_dev_select(codec, per_pin->pin_nid, |
| 1457 | per_pin->dev_id); |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1458 | snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, |
| 1459 | AC_VERB_SET_CONNECT_SEL, |
| 1460 | mux_idx); |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1461 | } |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1462 | snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid); |
| 1463 | |
| 1464 | non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid); |
| 1465 | if (substream->runtime) |
| 1466 | per_pin->channels = substream->runtime->channels; |
| 1467 | per_pin->setup = true; |
| 1468 | per_pin->mux_idx = mux_idx; |
| 1469 | |
| 1470 | hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); |
| 1471 | } |
| 1472 | |
| 1473 | static void hdmi_pcm_reset_pin(struct hdmi_spec *spec, |
| 1474 | struct hdmi_spec_per_pin *per_pin) |
| 1475 | { |
| 1476 | if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used) |
| 1477 | snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx); |
| 1478 | |
| 1479 | per_pin->chmap_set = false; |
| 1480 | memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); |
| 1481 | |
| 1482 | per_pin->setup = false; |
| 1483 | per_pin->channels = 0; |
| 1484 | } |
| 1485 | |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1486 | static struct snd_jack *pin_idx_to_pcm_jack(struct hda_codec *codec, |
| 1487 | struct hdmi_spec_per_pin *per_pin) |
| 1488 | { |
| 1489 | struct hdmi_spec *spec = codec->spec; |
| 1490 | |
| 1491 | if (per_pin->pcm_idx >= 0) |
| 1492 | return spec->pcm_rec[per_pin->pcm_idx].jack; |
| 1493 | else |
| 1494 | return NULL; |
| 1495 | } |
| 1496 | |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1497 | /* update per_pin ELD from the given new ELD; |
| 1498 | * setup info frame and notification accordingly |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1499 | * also notify ELD kctl and report jack status changes |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1500 | */ |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1501 | static void update_eld(struct hda_codec *codec, |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1502 | struct hdmi_spec_per_pin *per_pin, |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1503 | struct hdmi_eld *eld, |
| 1504 | int repoll) |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1505 | { |
| 1506 | struct hdmi_eld *pin_eld = &per_pin->sink_eld; |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1507 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1508 | struct snd_jack *pcm_jack; |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1509 | bool old_eld_valid = pin_eld->eld_valid; |
| 1510 | bool eld_changed; |
Colin Ian King | f953e72 | 2019-09-05 16:48:26 +0100 | [diff] [blame] | 1511 | int pcm_idx; |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1512 | |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1513 | if (eld->eld_valid) { |
| 1514 | if (eld->eld_size <= 0 || |
| 1515 | snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer, |
| 1516 | eld->eld_size) < 0) { |
| 1517 | eld->eld_valid = false; |
| 1518 | if (repoll) { |
| 1519 | schedule_delayed_work(&per_pin->work, |
| 1520 | msecs_to_jiffies(300)); |
| 1521 | return; |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | if (!eld->eld_valid || eld->eld_size <= 0) { |
| 1527 | eld->eld_valid = false; |
| 1528 | eld->eld_size = 0; |
| 1529 | } |
| 1530 | |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 1531 | /* for monitor disconnection, save pcm_idx firstly */ |
| 1532 | pcm_idx = per_pin->pcm_idx; |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1533 | |
| 1534 | /* |
| 1535 | * pcm_idx >=0 before update_eld() means it is in monitor |
| 1536 | * disconnected event. Jack must be fetched before update_eld(). |
| 1537 | */ |
| 1538 | pcm_jack = pin_idx_to_pcm_jack(codec, per_pin); |
| 1539 | |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1540 | if (spec->dyn_pcm_assign) { |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1541 | if (eld->eld_valid) { |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1542 | hdmi_attach_hda_pcm(spec, per_pin); |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1543 | hdmi_pcm_setup_pin(spec, per_pin); |
| 1544 | } else { |
| 1545 | hdmi_pcm_reset_pin(spec, per_pin); |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1546 | hdmi_detach_hda_pcm(spec, per_pin); |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 1547 | } |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1548 | } |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 1549 | /* if pcm_idx == -1, it means this is in monitor connection event |
| 1550 | * we can get the correct pcm_idx now. |
| 1551 | */ |
| 1552 | if (pcm_idx == -1) |
| 1553 | pcm_idx = per_pin->pcm_idx; |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1554 | if (!pcm_jack) |
| 1555 | pcm_jack = pin_idx_to_pcm_jack(codec, per_pin); |
Libin Yang | a76056f | 2015-12-16 16:48:15 +0800 | [diff] [blame] | 1556 | |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1557 | if (eld->eld_valid) |
| 1558 | snd_hdmi_show_eld(codec, &eld->info); |
| 1559 | |
| 1560 | eld_changed = (pin_eld->eld_valid != eld->eld_valid); |
Takashi Iwai | 551626e | 2019-07-17 14:30:23 +0200 | [diff] [blame] | 1561 | eld_changed |= (pin_eld->monitor_present != eld->monitor_present); |
| 1562 | if (!eld_changed && eld->eld_valid && pin_eld->eld_valid) |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1563 | if (pin_eld->eld_size != eld->eld_size || |
| 1564 | memcmp(pin_eld->eld_buffer, eld->eld_buffer, |
| 1565 | eld->eld_size) != 0) |
| 1566 | eld_changed = true; |
| 1567 | |
Takashi Iwai | 551626e | 2019-07-17 14:30:23 +0200 | [diff] [blame] | 1568 | if (eld_changed) { |
| 1569 | pin_eld->monitor_present = eld->monitor_present; |
| 1570 | pin_eld->eld_valid = eld->eld_valid; |
| 1571 | pin_eld->eld_size = eld->eld_size; |
| 1572 | if (eld->eld_valid) |
| 1573 | memcpy(pin_eld->eld_buffer, eld->eld_buffer, |
| 1574 | eld->eld_size); |
| 1575 | pin_eld->info = eld->info; |
| 1576 | } |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1577 | |
| 1578 | /* |
| 1579 | * Re-setup pin and infoframe. This is needed e.g. when |
| 1580 | * - sink is first plugged-in |
| 1581 | * - transcoder can change during stream playback on Haswell |
| 1582 | * and this can make HW reset converter selection on a pin. |
| 1583 | */ |
| 1584 | if (eld->eld_valid && !old_eld_valid && per_pin->setup) { |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 1585 | pin_cvt_fixup(codec, per_pin, 0); |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1586 | hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); |
| 1587 | } |
| 1588 | |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 1589 | if (eld_changed && pcm_idx >= 0) |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1590 | snd_ctl_notify(codec->card, |
| 1591 | SNDRV_CTL_EVENT_MASK_VALUE | |
| 1592 | SNDRV_CTL_EVENT_MASK_INFO, |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 1593 | &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id); |
Takashi Iwai | e90247f | 2015-11-13 09:12:12 +0100 | [diff] [blame] | 1594 | |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1595 | if (eld_changed && pcm_jack) |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 1596 | snd_jack_report(pcm_jack, |
| 1597 | (eld->monitor_present && eld->eld_valid) ? |
| 1598 | SND_JACK_AVOUT : 0); |
| 1599 | } |
| 1600 | |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1601 | /* update ELD and jack state via HD-audio verbs */ |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 1602 | static void hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin, |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1603 | int repoll) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1604 | { |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1605 | struct hda_codec *codec = per_pin->codec; |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1606 | struct hdmi_spec *spec = codec->spec; |
| 1607 | struct hdmi_eld *eld = &spec->temp_eld; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1608 | hda_nid_t pin_nid = per_pin->pin_nid; |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 1609 | int dev_id = per_pin->dev_id; |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 1610 | /* |
| 1611 | * Always execute a GetPinSense verb here, even when called from |
| 1612 | * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited |
| 1613 | * response's PD bit is not the real PD value, but indicates that |
| 1614 | * the real PD value changed. An older version of the HD-audio |
| 1615 | * specification worked this way. Hence, we just ignore the data in |
| 1616 | * the unsolicited response to avoid custom WARs. |
| 1617 | */ |
David Henningsson | da4a7a3 | 2013-12-18 10:46:04 +0100 | [diff] [blame] | 1618 | int present; |
Takashi Iwai | ae47e2e | 2020-02-06 17:28:03 +0100 | [diff] [blame] | 1619 | int ret; |
| 1620 | |
| 1621 | ret = snd_hda_power_up_pm(codec); |
| 1622 | if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) |
| 1623 | goto out; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1624 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 1625 | present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id); |
David Henningsson | da4a7a3 | 2013-12-18 10:46:04 +0100 | [diff] [blame] | 1626 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1627 | mutex_lock(&per_pin->lock); |
Takashi Iwai | c44da62 | 2016-04-13 09:45:53 +0200 | [diff] [blame] | 1628 | eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); |
| 1629 | if (eld->monitor_present) |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1630 | eld->eld_valid = !!(present & AC_PINSENSE_ELDV); |
| 1631 | else |
| 1632 | eld->eld_valid = false; |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 1633 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1634 | codec_dbg(codec, |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 1635 | "HDMI status: Codec=%d NID=0x%x Presence_Detect=%d ELD_Valid=%d\n", |
Takashi Iwai | c44da62 | 2016-04-13 09:45:53 +0200 | [diff] [blame] | 1636 | codec->addr, pin_nid, eld->monitor_present, eld->eld_valid); |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 1637 | |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1638 | if (eld->eld_valid) { |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 1639 | if (spec->ops.pin_get_eld(codec, pin_nid, dev_id, |
| 1640 | eld->eld_buffer, &eld->eld_size) < 0) |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1641 | eld->eld_valid = false; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1642 | } |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1643 | |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1644 | update_eld(codec, per_pin, eld, repoll); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1645 | mutex_unlock(&per_pin->lock); |
Takashi Iwai | ae47e2e | 2020-02-06 17:28:03 +0100 | [diff] [blame] | 1646 | out: |
| 1647 | snd_hda_power_down_pm(codec); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1648 | } |
| 1649 | |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1650 | #define I915_SILENT_RATE 48000 |
| 1651 | #define I915_SILENT_CHANNELS 2 |
| 1652 | #define I915_SILENT_FORMAT SNDRV_PCM_FORMAT_S16_LE |
| 1653 | #define I915_SILENT_FORMAT_BITS 16 |
| 1654 | #define I915_SILENT_FMT_MASK 0xf |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1655 | |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1656 | static void silent_stream_enable(struct hda_codec *codec, |
| 1657 | struct hdmi_spec_per_pin *per_pin) |
| 1658 | { |
| 1659 | struct hdmi_spec *spec = codec->spec; |
| 1660 | struct hdmi_spec_per_cvt *per_cvt; |
| 1661 | int cvt_idx, pin_idx, err; |
| 1662 | unsigned int format; |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1663 | |
| 1664 | mutex_lock(&per_pin->lock); |
| 1665 | |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1666 | if (per_pin->setup) { |
| 1667 | codec_dbg(codec, "hdmi: PCM already open, no silent stream\n"); |
| 1668 | goto unlock_out; |
| 1669 | } |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1670 | |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1671 | pin_idx = pin_id_to_pin_index(codec, per_pin->pin_nid, per_pin->dev_id); |
| 1672 | err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx); |
| 1673 | if (err) { |
| 1674 | codec_err(codec, "hdmi: no free converter to enable silent mode\n"); |
| 1675 | goto unlock_out; |
| 1676 | } |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1677 | |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1678 | per_cvt = get_cvt(spec, cvt_idx); |
| 1679 | per_cvt->assigned = 1; |
| 1680 | per_pin->cvt_nid = per_cvt->cvt_nid; |
| 1681 | per_pin->silent_stream = true; |
| 1682 | |
| 1683 | codec_dbg(codec, "hdmi: enabling silent stream pin-NID=0x%x cvt-NID=0x%x\n", |
| 1684 | per_pin->pin_nid, per_cvt->cvt_nid); |
| 1685 | |
| 1686 | snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id); |
| 1687 | snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, |
| 1688 | AC_VERB_SET_CONNECT_SEL, |
| 1689 | per_pin->mux_idx); |
| 1690 | |
| 1691 | /* configure unused pins to choose other converters */ |
| 1692 | pin_cvt_fixup(codec, per_pin, 0); |
| 1693 | |
| 1694 | snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid, |
| 1695 | per_pin->dev_id, I915_SILENT_RATE); |
| 1696 | |
| 1697 | /* trigger silent stream generation in hw */ |
| 1698 | format = snd_hdac_calc_stream_format(I915_SILENT_RATE, I915_SILENT_CHANNELS, |
| 1699 | I915_SILENT_FORMAT, I915_SILENT_FORMAT_BITS, 0); |
| 1700 | snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, |
| 1701 | I915_SILENT_FMT_MASK, I915_SILENT_FMT_MASK, format); |
| 1702 | usleep_range(100, 200); |
| 1703 | snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, I915_SILENT_FMT_MASK, 0, format); |
| 1704 | |
| 1705 | per_pin->channels = I915_SILENT_CHANNELS; |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1706 | hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); |
| 1707 | |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1708 | unlock_out: |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1709 | mutex_unlock(&per_pin->lock); |
| 1710 | } |
| 1711 | |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1712 | static void silent_stream_disable(struct hda_codec *codec, |
| 1713 | struct hdmi_spec_per_pin *per_pin) |
| 1714 | { |
| 1715 | struct hdmi_spec *spec = codec->spec; |
| 1716 | struct hdmi_spec_per_cvt *per_cvt; |
| 1717 | int cvt_idx; |
| 1718 | |
| 1719 | mutex_lock(&per_pin->lock); |
| 1720 | if (!per_pin->silent_stream) |
| 1721 | goto unlock_out; |
| 1722 | |
| 1723 | codec_dbg(codec, "HDMI: disable silent stream on pin-NID=0x%x cvt-NID=0x%x\n", |
| 1724 | per_pin->pin_nid, per_pin->cvt_nid); |
| 1725 | |
| 1726 | cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid); |
| 1727 | if (cvt_idx >= 0 && cvt_idx < spec->num_cvts) { |
| 1728 | per_cvt = get_cvt(spec, cvt_idx); |
| 1729 | per_cvt->assigned = 0; |
| 1730 | } |
| 1731 | |
| 1732 | per_pin->cvt_nid = 0; |
| 1733 | per_pin->silent_stream = false; |
| 1734 | |
| 1735 | unlock_out: |
Takashi Iwai | 3d5c5fd | 2021-01-01 09:38:52 +0100 | [diff] [blame] | 1736 | mutex_unlock(&per_pin->lock); |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1737 | } |
| 1738 | |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1739 | /* update ELD and jack state via audio component */ |
| 1740 | static void sync_eld_via_acomp(struct hda_codec *codec, |
| 1741 | struct hdmi_spec_per_pin *per_pin) |
| 1742 | { |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1743 | struct hdmi_spec *spec = codec->spec; |
| 1744 | struct hdmi_eld *eld = &spec->temp_eld; |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1745 | bool monitor_prev, monitor_next; |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1746 | |
Takashi Iwai | e2dc7d7 | 2015-12-01 12:39:38 +0100 | [diff] [blame] | 1747 | mutex_lock(&per_pin->lock); |
Takashi Iwai | c64c143 | 2016-03-21 16:07:30 +0100 | [diff] [blame] | 1748 | eld->monitor_present = false; |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1749 | monitor_prev = per_pin->sink_eld.monitor_present; |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1750 | eld->eld_size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1751 | per_pin->dev_id, &eld->monitor_present, |
| 1752 | eld->eld_buffer, ELD_MAX_SIZE); |
Takashi Iwai | adf615a | 2020-02-06 17:28:04 +0100 | [diff] [blame] | 1753 | eld->eld_valid = (eld->eld_size > 0); |
| 1754 | update_eld(codec, per_pin, eld, 0); |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1755 | monitor_next = per_pin->sink_eld.monitor_present; |
Takashi Iwai | e2dc7d7 | 2015-12-01 12:39:38 +0100 | [diff] [blame] | 1756 | mutex_unlock(&per_pin->lock); |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1757 | |
| 1758 | /* |
| 1759 | * Power-up will call hdmi_present_sense, so the PM calls |
| 1760 | * have to be done without mutex held. |
| 1761 | */ |
| 1762 | |
| 1763 | if (spec->send_silent_stream) { |
| 1764 | int pm_ret; |
| 1765 | |
| 1766 | if (!monitor_prev && monitor_next) { |
| 1767 | pm_ret = snd_hda_power_up_pm(codec); |
| 1768 | if (pm_ret < 0) |
| 1769 | codec_err(codec, |
| 1770 | "Monitor plugged-in, Failed to power up codec ret=[%d]\n", |
| 1771 | pm_ret); |
| 1772 | silent_stream_enable(codec, per_pin); |
| 1773 | } else if (monitor_prev && !monitor_next) { |
Kai Vehmanen | b1a5039 | 2020-12-10 19:44:45 +0200 | [diff] [blame] | 1774 | silent_stream_disable(codec, per_pin); |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 1775 | pm_ret = snd_hda_power_down_pm(codec); |
| 1776 | if (pm_ret < 0) |
| 1777 | codec_err(codec, |
| 1778 | "Monitor plugged-out, Failed to power down codec ret=[%d]\n", |
| 1779 | pm_ret); |
| 1780 | } |
| 1781 | } |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1782 | } |
| 1783 | |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 1784 | static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1785 | { |
| 1786 | struct hda_codec *codec = per_pin->codec; |
| 1787 | |
Takashi Iwai | ae47e2e | 2020-02-06 17:28:03 +0100 | [diff] [blame] | 1788 | if (!codec_has_acomp(codec)) |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 1789 | hdmi_present_sense_via_verbs(per_pin, repoll); |
Takashi Iwai | ae47e2e | 2020-02-06 17:28:03 +0100 | [diff] [blame] | 1790 | else |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1791 | sync_eld_via_acomp(codec, per_pin); |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 1792 | } |
| 1793 | |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1794 | static void hdmi_repoll_eld(struct work_struct *work) |
| 1795 | { |
| 1796 | struct hdmi_spec_per_pin *per_pin = |
| 1797 | container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work); |
Chris Wilson | aaa23f8 | 2018-06-27 07:25:32 +0100 | [diff] [blame] | 1798 | struct hda_codec *codec = per_pin->codec; |
| 1799 | struct hdmi_spec *spec = codec->spec; |
Hui Wang | 8c2e672 | 2019-05-06 22:09:31 +0800 | [diff] [blame] | 1800 | struct hda_jack_tbl *jack; |
| 1801 | |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 1802 | jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid, |
| 1803 | per_pin->dev_id); |
Hui Wang | 8c2e672 | 2019-05-06 22:09:31 +0800 | [diff] [blame] | 1804 | if (jack) |
| 1805 | jack->jack_dirty = 1; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1806 | |
Wu Fengguang | c6e8453 | 2011-11-18 16:59:32 -0600 | [diff] [blame] | 1807 | if (per_pin->repoll_count++ > 6) |
| 1808 | per_pin->repoll_count = 0; |
| 1809 | |
Chris Wilson | aaa23f8 | 2018-06-27 07:25:32 +0100 | [diff] [blame] | 1810 | mutex_lock(&spec->pcm_lock); |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 1811 | hdmi_present_sense(per_pin, per_pin->repoll_count); |
Chris Wilson | aaa23f8 | 2018-06-27 07:25:32 +0100 | [diff] [blame] | 1812 | mutex_unlock(&spec->pcm_lock); |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1813 | } |
| 1814 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1815 | static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) |
| 1816 | { |
| 1817 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1818 | unsigned int caps, config; |
| 1819 | int pin_idx; |
| 1820 | struct hdmi_spec_per_pin *per_pin; |
David Henningsson | 07acecc | 2011-05-19 11:46:03 +0200 | [diff] [blame] | 1821 | int err; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1822 | int dev_num, i; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1823 | |
Takashi Iwai | efc2f8de | 2012-11-21 14:27:37 +0100 | [diff] [blame] | 1824 | caps = snd_hda_query_pin_caps(codec, pin_nid); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1825 | if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) |
| 1826 | return 0; |
| 1827 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1828 | /* |
| 1829 | * For DP MST audio, Configuration Default is the same for |
| 1830 | * all device entries on the same pin |
| 1831 | */ |
Takashi Iwai | efc2f8de | 2012-11-21 14:27:37 +0100 | [diff] [blame] | 1832 | config = snd_hda_codec_get_pincfg(codec, pin_nid); |
Kai-Heng Feng | cd72c31 | 2020-08-04 23:58:34 +0800 | [diff] [blame] | 1833 | if (get_defcfg_connect(config) == AC_JACK_PORT_NONE && |
| 1834 | !spec->force_connect) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1835 | return 0; |
| 1836 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1837 | /* |
| 1838 | * To simplify the implementation, malloc all |
| 1839 | * the virtual pins in the initialization statically |
| 1840 | */ |
Takashi Iwai | cb45722 | 2019-11-11 20:09:37 +0100 | [diff] [blame] | 1841 | if (spec->intel_hsw_fixup) { |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1842 | /* |
| 1843 | * On Intel platforms, device entries number is |
| 1844 | * changed dynamically. If there is a DP MST |
| 1845 | * hub connected, the device entries number is 3. |
| 1846 | * Otherwise, it is 1. |
| 1847 | * Here we manually set dev_num to 3, so that |
| 1848 | * we can initialize all the device entries when |
| 1849 | * bootup statically. |
| 1850 | */ |
| 1851 | dev_num = 3; |
| 1852 | spec->dev_num = 3; |
| 1853 | } else if (spec->dyn_pcm_assign && codec->dp_mst) { |
| 1854 | dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1; |
| 1855 | /* |
| 1856 | * spec->dev_num is the maxinum number of device entries |
| 1857 | * among all the pins |
| 1858 | */ |
| 1859 | spec->dev_num = (spec->dev_num > dev_num) ? |
| 1860 | spec->dev_num : dev_num; |
| 1861 | } else { |
| 1862 | /* |
| 1863 | * If the platform doesn't support DP MST, |
| 1864 | * manually set dev_num to 1. This means |
| 1865 | * the pin has only one device entry. |
| 1866 | */ |
| 1867 | dev_num = 1; |
| 1868 | spec->dev_num = 1; |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 1869 | } |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1870 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1871 | for (i = 0; i < dev_num; i++) { |
| 1872 | pin_idx = spec->num_pins; |
| 1873 | per_pin = snd_array_new(&spec->pins); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1874 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1875 | if (!per_pin) |
| 1876 | return -ENOMEM; |
| 1877 | |
| 1878 | if (spec->dyn_pcm_assign) { |
| 1879 | per_pin->pcm = NULL; |
| 1880 | per_pin->pcm_idx = -1; |
| 1881 | } else { |
| 1882 | per_pin->pcm = get_hdmi_pcm(spec, pin_idx); |
| 1883 | per_pin->pcm_idx = pin_idx; |
| 1884 | } |
| 1885 | per_pin->pin_nid = pin_nid; |
| 1886 | per_pin->pin_nid_idx = spec->num_nids; |
| 1887 | per_pin->dev_id = i; |
| 1888 | per_pin->non_pcm = false; |
| 1889 | snd_hda_set_dev_select(codec, pin_nid, i); |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 1890 | err = hdmi_read_pin_conn(codec, pin_idx); |
| 1891 | if (err < 0) |
| 1892 | return err; |
| 1893 | spec->num_pins++; |
| 1894 | } |
| 1895 | spec->num_nids++; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1896 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1897 | return 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1898 | } |
| 1899 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1900 | static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1901 | { |
| 1902 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1903 | struct hdmi_spec_per_cvt *per_cvt; |
| 1904 | unsigned int chans; |
| 1905 | int err; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1906 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1907 | chans = get_wcaps(codec, cvt_nid); |
| 1908 | chans = get_wcaps_channels(chans); |
| 1909 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1910 | per_cvt = snd_array_new(&spec->cvts); |
| 1911 | if (!per_cvt) |
| 1912 | return -ENOMEM; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1913 | |
| 1914 | per_cvt->cvt_nid = cvt_nid; |
| 1915 | per_cvt->channels_min = 2; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1916 | if (chans <= 16) { |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1917 | per_cvt->channels_max = chans; |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 1918 | if (chans > spec->chmap.channels_max) |
| 1919 | spec->chmap.channels_max = chans; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1920 | } |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1921 | |
| 1922 | err = snd_hda_query_supported_pcm(codec, cvt_nid, |
| 1923 | &per_cvt->rates, |
| 1924 | &per_cvt->formats, |
| 1925 | &per_cvt->maxbps); |
| 1926 | if (err < 0) |
| 1927 | return err; |
| 1928 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1929 | if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids)) |
| 1930 | spec->cvt_nids[spec->num_cvts] = cvt_nid; |
| 1931 | spec->num_cvts++; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1932 | |
| 1933 | return 0; |
| 1934 | } |
| 1935 | |
Kai-Heng Feng | cd72c31 | 2020-08-04 23:58:34 +0800 | [diff] [blame] | 1936 | static const struct snd_pci_quirk force_connect_list[] = { |
Kai-Heng Feng | d96f27c | 2020-08-11 17:53:34 +0800 | [diff] [blame] | 1937 | SND_PCI_QUIRK(0x103c, 0x870f, "HP", 1), |
Kai-Heng Feng | cd72c31 | 2020-08-04 23:58:34 +0800 | [diff] [blame] | 1938 | SND_PCI_QUIRK(0x103c, 0x871a, "HP", 1), |
| 1939 | {} |
| 1940 | }; |
| 1941 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1942 | static int hdmi_parse_codec(struct hda_codec *codec) |
| 1943 | { |
Kai-Heng Feng | cd72c31 | 2020-08-04 23:58:34 +0800 | [diff] [blame] | 1944 | struct hdmi_spec *spec = codec->spec; |
Kai Vehmanen | 5627503 | 2020-07-03 18:38:17 +0300 | [diff] [blame] | 1945 | hda_nid_t start_nid; |
| 1946 | unsigned int caps; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1947 | int i, nodes; |
Kai-Heng Feng | cd72c31 | 2020-08-04 23:58:34 +0800 | [diff] [blame] | 1948 | const struct snd_pci_quirk *q; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1949 | |
Kai Vehmanen | 5627503 | 2020-07-03 18:38:17 +0300 | [diff] [blame] | 1950 | nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &start_nid); |
| 1951 | if (!start_nid || nodes < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1952 | codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1953 | return -EINVAL; |
| 1954 | } |
| 1955 | |
Kai-Heng Feng | cd72c31 | 2020-08-04 23:58:34 +0800 | [diff] [blame] | 1956 | q = snd_pci_quirk_lookup(codec->bus->pci, force_connect_list); |
| 1957 | |
| 1958 | if (q && q->value) |
| 1959 | spec->force_connect = true; |
| 1960 | |
Kai Vehmanen | 5627503 | 2020-07-03 18:38:17 +0300 | [diff] [blame] | 1961 | /* |
| 1962 | * hdmi_add_pin() assumes total amount of converters to |
| 1963 | * be known, so first discover all converters |
| 1964 | */ |
| 1965 | for (i = 0; i < nodes; i++) { |
| 1966 | hda_nid_t nid = start_nid + i; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1967 | |
Takashi Iwai | efc2f8de | 2012-11-21 14:27:37 +0100 | [diff] [blame] | 1968 | caps = get_wcaps(codec, nid); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1969 | |
| 1970 | if (!(caps & AC_WCAP_DIGITAL)) |
| 1971 | continue; |
| 1972 | |
Kai Vehmanen | 5627503 | 2020-07-03 18:38:17 +0300 | [diff] [blame] | 1973 | if (get_wcaps_type(caps) == AC_WID_AUD_OUT) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1974 | hdmi_add_cvt(codec, nid); |
Kai Vehmanen | 5627503 | 2020-07-03 18:38:17 +0300 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | /* discover audio pins */ |
| 1978 | for (i = 0; i < nodes; i++) { |
| 1979 | hda_nid_t nid = start_nid + i; |
| 1980 | |
| 1981 | caps = get_wcaps(codec, nid); |
| 1982 | |
| 1983 | if (!(caps & AC_WCAP_DIGITAL)) |
| 1984 | continue; |
| 1985 | |
| 1986 | if (get_wcaps_type(caps) == AC_WID_PIN) |
Wu Fengguang | 3eaead5 | 2010-05-14 16:36:15 +0800 | [diff] [blame] | 1987 | hdmi_add_pin(codec, nid); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1988 | } |
| 1989 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1990 | return 0; |
| 1991 | } |
| 1992 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1993 | /* |
| 1994 | */ |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 1995 | static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) |
| 1996 | { |
| 1997 | struct hda_spdif_out *spdif; |
| 1998 | bool non_pcm; |
| 1999 | |
| 2000 | mutex_lock(&codec->spdif_mutex); |
| 2001 | spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid); |
Libin Yang | 960a581 | 2016-06-16 11:13:25 +0800 | [diff] [blame] | 2002 | /* Add sanity check to pass klockwork check. |
| 2003 | * This should never happen. |
| 2004 | */ |
Wu Bo | a2f64724 | 2020-04-26 21:17:22 +0800 | [diff] [blame] | 2005 | if (WARN_ON(spdif == NULL)) { |
| 2006 | mutex_unlock(&codec->spdif_mutex); |
Libin Yang | 960a581 | 2016-06-16 11:13:25 +0800 | [diff] [blame] | 2007 | return true; |
Wu Bo | a2f64724 | 2020-04-26 21:17:22 +0800 | [diff] [blame] | 2008 | } |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 2009 | non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO); |
| 2010 | mutex_unlock(&codec->spdif_mutex); |
| 2011 | return non_pcm; |
| 2012 | } |
| 2013 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2014 | /* |
| 2015 | * HDMI callbacks |
| 2016 | */ |
| 2017 | |
| 2018 | static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 2019 | struct hda_codec *codec, |
| 2020 | unsigned int stream_tag, |
| 2021 | unsigned int format, |
| 2022 | struct snd_pcm_substream *substream) |
| 2023 | { |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2024 | hda_nid_t cvt_nid = hinfo->nid; |
| 2025 | struct hdmi_spec *spec = codec->spec; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 2026 | int pin_idx; |
| 2027 | struct hdmi_spec_per_pin *per_pin; |
Libin Yang | ddd621f | 2015-09-02 14:11:40 +0800 | [diff] [blame] | 2028 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 2029 | bool non_pcm; |
Sameer Pujar | 053b055 | 2019-01-14 23:51:12 +0530 | [diff] [blame] | 2030 | int pinctl, stripe; |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 2031 | int err = 0; |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 2032 | |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 2033 | mutex_lock(&spec->pcm_lock); |
| 2034 | pin_idx = hinfo_to_pin_index(codec, hinfo); |
| 2035 | if (spec->dyn_pcm_assign && pin_idx < 0) { |
| 2036 | /* when dyn_pcm_assign and pcm is not bound to a pin |
| 2037 | * skip pin setup and return 0 to make audio playback |
| 2038 | * be ongoing |
| 2039 | */ |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 2040 | pin_cvt_fixup(codec, NULL, cvt_nid); |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 2041 | snd_hda_codec_setup_stream(codec, cvt_nid, |
| 2042 | stream_tag, 0, format); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 2043 | goto unlock; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | if (snd_BUG_ON(pin_idx < 0)) { |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 2047 | err = -EINVAL; |
| 2048 | goto unlock; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 2049 | } |
| 2050 | per_pin = get_pin(spec, pin_idx); |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 2051 | |
| 2052 | /* Verify pin:cvt selections to avoid silent audio after S3. |
| 2053 | * After S3, the audio driver restores pin:cvt selections |
| 2054 | * but this can happen before gfx is ready and such selection |
| 2055 | * is overlooked by HW. Thus multiple pins can share a same |
| 2056 | * default convertor and mute control will affect each other, |
| 2057 | * which can cause a resumed audio playback become silent |
| 2058 | * after S3. |
| 2059 | */ |
| 2060 | pin_cvt_fixup(codec, per_pin, 0); |
Mengdong Lin | 2df6742 | 2014-03-20 13:01:06 +0800 | [diff] [blame] | 2061 | |
Libin Yang | ddd621f | 2015-09-02 14:11:40 +0800 | [diff] [blame] | 2062 | /* Call sync_audio_rate to set the N/CTS/M manually if necessary */ |
| 2063 | /* Todo: add DP1.2 MST audio support later */ |
Takashi Iwai | 93a9ff1 | 2016-03-18 19:45:13 +0100 | [diff] [blame] | 2064 | if (codec_has_acomp(codec)) |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 2065 | snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid, |
| 2066 | per_pin->dev_id, runtime->rate); |
Libin Yang | ddd621f | 2015-09-02 14:11:40 +0800 | [diff] [blame] | 2067 | |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 2068 | non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2069 | mutex_lock(&per_pin->lock); |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 2070 | per_pin->channels = substream->runtime->channels; |
| 2071 | per_pin->setup = true; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2072 | |
Sameer Pujar | 053b055 | 2019-01-14 23:51:12 +0530 | [diff] [blame] | 2073 | if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) { |
| 2074 | stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core, |
| 2075 | substream); |
| 2076 | snd_hda_codec_write(codec, cvt_nid, 0, |
| 2077 | AC_VERB_SET_STRIPE_CONTROL, |
| 2078 | stripe); |
| 2079 | } |
| 2080 | |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 2081 | hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2082 | mutex_unlock(&per_pin->lock); |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 2083 | if (spec->dyn_pin_out) { |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 2084 | snd_hda_set_dev_select(codec, per_pin->pin_nid, |
| 2085 | per_pin->dev_id); |
| 2086 | pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0, |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 2087 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 2088 | snd_hda_codec_write(codec, per_pin->pin_nid, 0, |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 2089 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2090 | pinctl | PIN_OUT); |
| 2091 | } |
| 2092 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2093 | /* snd_hda_set_dev_select() has been called before */ |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 2094 | err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid, |
| 2095 | per_pin->dev_id, stream_tag, format); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 2096 | unlock: |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 2097 | mutex_unlock(&spec->pcm_lock); |
| 2098 | return err; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2099 | } |
| 2100 | |
Takashi Iwai | 8dfaa57 | 2012-08-06 14:49:36 +0200 | [diff] [blame] | 2101 | static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 2102 | struct hda_codec *codec, |
| 2103 | struct snd_pcm_substream *substream) |
| 2104 | { |
| 2105 | snd_hda_codec_cleanup_stream(codec, hinfo->nid); |
| 2106 | return 0; |
| 2107 | } |
| 2108 | |
Takashi Iwai | f2ad24f | 2012-07-26 18:08:14 +0200 | [diff] [blame] | 2109 | static int hdmi_pcm_close(struct hda_pcm_stream *hinfo, |
| 2110 | struct hda_codec *codec, |
| 2111 | struct snd_pcm_substream *substream) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2112 | { |
| 2113 | struct hdmi_spec *spec = codec->spec; |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 2114 | int cvt_idx, pin_idx, pcm_idx; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2115 | struct hdmi_spec_per_cvt *per_cvt; |
| 2116 | struct hdmi_spec_per_pin *per_pin; |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 2117 | int pinctl; |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 2118 | int err = 0; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2119 | |
Kai Vehmanen | ce1558c | 2020-10-13 18:26:28 +0300 | [diff] [blame] | 2120 | mutex_lock(&spec->pcm_lock); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2121 | if (hinfo->nid) { |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 2122 | pcm_idx = hinfo_to_pcm_index(codec, hinfo); |
Kai Vehmanen | ce1558c | 2020-10-13 18:26:28 +0300 | [diff] [blame] | 2123 | if (snd_BUG_ON(pcm_idx < 0)) { |
| 2124 | err = -EINVAL; |
| 2125 | goto unlock; |
| 2126 | } |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2127 | cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid); |
Kai Vehmanen | ce1558c | 2020-10-13 18:26:28 +0300 | [diff] [blame] | 2128 | if (snd_BUG_ON(cvt_idx < 0)) { |
| 2129 | err = -EINVAL; |
| 2130 | goto unlock; |
| 2131 | } |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2132 | per_cvt = get_cvt(spec, cvt_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2133 | per_cvt->assigned = 0; |
| 2134 | hinfo->nid = 0; |
| 2135 | |
Takashi Iwai | 6fd739c | 2019-12-14 18:52:17 +0100 | [diff] [blame] | 2136 | azx_stream(get_azx_dev(substream))->stripe = 0; |
| 2137 | |
Libin Yang | b09887f8 | 2016-01-29 13:53:27 +0800 | [diff] [blame] | 2138 | snd_hda_spdif_ctls_unassign(codec, pcm_idx); |
Libin Yang | ac98379 | 2015-12-16 16:48:16 +0800 | [diff] [blame] | 2139 | clear_bit(pcm_idx, &spec->pcm_in_use); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2140 | pin_idx = hinfo_to_pin_index(codec, hinfo); |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 2141 | if (spec->dyn_pcm_assign && pin_idx < 0) |
| 2142 | goto unlock; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 2143 | |
| 2144 | if (snd_BUG_ON(pin_idx < 0)) { |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 2145 | err = -EINVAL; |
| 2146 | goto unlock; |
Libin Yang | 42b2987 | 2015-12-16 13:42:42 +0800 | [diff] [blame] | 2147 | } |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2148 | per_pin = get_pin(spec, pin_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2149 | |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 2150 | if (spec->dyn_pin_out) { |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 2151 | snd_hda_set_dev_select(codec, per_pin->pin_nid, |
| 2152 | per_pin->dev_id); |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 2153 | pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0, |
| 2154 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 2155 | snd_hda_codec_write(codec, per_pin->pin_nid, 0, |
| 2156 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 2157 | pinctl & ~PIN_OUT); |
| 2158 | } |
| 2159 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2160 | mutex_lock(&per_pin->lock); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 2161 | per_pin->chmap_set = false; |
| 2162 | memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 2163 | |
| 2164 | per_pin->setup = false; |
| 2165 | per_pin->channels = 0; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2166 | mutex_unlock(&per_pin->lock); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2167 | } |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 2168 | |
Kai Vehmanen | ce1558c | 2020-10-13 18:26:28 +0300 | [diff] [blame] | 2169 | unlock: |
| 2170 | mutex_unlock(&spec->pcm_lock); |
| 2171 | |
Takashi Iwai | f69548f | 2018-07-12 23:06:51 +0200 | [diff] [blame] | 2172 | return err; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | static const struct hda_pcm_ops generic_ops = { |
| 2176 | .open = hdmi_pcm_open, |
Takashi Iwai | f2ad24f | 2012-07-26 18:08:14 +0200 | [diff] [blame] | 2177 | .close = hdmi_pcm_close, |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2178 | .prepare = generic_hdmi_playback_pcm_prepare, |
Takashi Iwai | 8dfaa57 | 2012-08-06 14:49:36 +0200 | [diff] [blame] | 2179 | .cleanup = generic_hdmi_playback_pcm_cleanup, |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2180 | }; |
| 2181 | |
Subhransu S. Prusty | 44fde3b | 2016-04-04 19:23:54 +0530 | [diff] [blame] | 2182 | static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx) |
| 2183 | { |
Kai-Heng Feng | 8c11827 | 2020-05-05 11:03:53 +0800 | [diff] [blame] | 2184 | struct hda_codec *codec = hdac_to_hda_codec(hdac); |
Subhransu S. Prusty | 44fde3b | 2016-04-04 19:23:54 +0530 | [diff] [blame] | 2185 | struct hdmi_spec *spec = codec->spec; |
| 2186 | struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); |
| 2187 | |
| 2188 | if (!per_pin) |
| 2189 | return 0; |
| 2190 | |
| 2191 | return per_pin->sink_eld.info.spk_alloc; |
| 2192 | } |
| 2193 | |
Subhransu S. Prusty | 9b3dc8a | 2016-03-04 19:59:47 +0530 | [diff] [blame] | 2194 | static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx, |
| 2195 | unsigned char *chmap) |
| 2196 | { |
Kai-Heng Feng | 8c11827 | 2020-05-05 11:03:53 +0800 | [diff] [blame] | 2197 | struct hda_codec *codec = hdac_to_hda_codec(hdac); |
Subhransu S. Prusty | 9b3dc8a | 2016-03-04 19:59:47 +0530 | [diff] [blame] | 2198 | struct hdmi_spec *spec = codec->spec; |
| 2199 | struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); |
| 2200 | |
| 2201 | /* chmap is already set to 0 in caller */ |
| 2202 | if (!per_pin) |
| 2203 | return; |
| 2204 | |
| 2205 | memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap)); |
| 2206 | } |
| 2207 | |
| 2208 | static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx, |
| 2209 | unsigned char *chmap, int prepared) |
| 2210 | { |
Kai-Heng Feng | 8c11827 | 2020-05-05 11:03:53 +0800 | [diff] [blame] | 2211 | struct hda_codec *codec = hdac_to_hda_codec(hdac); |
Subhransu S. Prusty | 9b3dc8a | 2016-03-04 19:59:47 +0530 | [diff] [blame] | 2212 | struct hdmi_spec *spec = codec->spec; |
| 2213 | struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); |
| 2214 | |
Libin Yang | ed0739b | 2016-04-18 09:16:28 +0800 | [diff] [blame] | 2215 | if (!per_pin) |
| 2216 | return; |
Subhransu S. Prusty | 9b3dc8a | 2016-03-04 19:59:47 +0530 | [diff] [blame] | 2217 | mutex_lock(&per_pin->lock); |
| 2218 | per_pin->chmap_set = true; |
| 2219 | memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap)); |
| 2220 | if (prepared) |
| 2221 | hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); |
| 2222 | mutex_unlock(&per_pin->lock); |
| 2223 | } |
| 2224 | |
| 2225 | static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx) |
| 2226 | { |
Kai-Heng Feng | 8c11827 | 2020-05-05 11:03:53 +0800 | [diff] [blame] | 2227 | struct hda_codec *codec = hdac_to_hda_codec(hdac); |
Subhransu S. Prusty | 9b3dc8a | 2016-03-04 19:59:47 +0530 | [diff] [blame] | 2228 | struct hdmi_spec *spec = codec->spec; |
| 2229 | struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); |
| 2230 | |
| 2231 | return per_pin ? true:false; |
| 2232 | } |
| 2233 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2234 | static int generic_hdmi_build_pcms(struct hda_codec *codec) |
| 2235 | { |
| 2236 | struct hdmi_spec *spec = codec->spec; |
Kai Vehmanen | 2a2edfb | 2019-10-29 15:40:09 +0200 | [diff] [blame] | 2237 | int idx, pcm_num; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2238 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2239 | /* |
| 2240 | * for non-mst mode, pcm number is the same as before |
Kai Vehmanen | 2a2edfb | 2019-10-29 15:40:09 +0200 | [diff] [blame] | 2241 | * for DP MST mode without extra PCM, pcm number is same |
| 2242 | * for DP MST mode with extra PCMs, pcm number is |
| 2243 | * (nid number + dev_num - 1) |
| 2244 | * dev_num is the device entry number in a pin |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2245 | */ |
Kai Vehmanen | 2a2edfb | 2019-10-29 15:40:09 +0200 | [diff] [blame] | 2246 | |
| 2247 | if (codec->mst_no_extra_pcms) |
| 2248 | pcm_num = spec->num_nids; |
| 2249 | else |
| 2250 | pcm_num = spec->num_nids + spec->dev_num - 1; |
| 2251 | |
| 2252 | codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num); |
| 2253 | |
| 2254 | for (idx = 0; idx < pcm_num; idx++) { |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2255 | struct hda_pcm *info; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2256 | struct hda_pcm_stream *pstr; |
| 2257 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2258 | info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2259 | if (!info) |
| 2260 | return -ENOMEM; |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 2261 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2262 | spec->pcm_rec[idx].pcm = info; |
Libin Yang | 2bf3c85 | 2015-12-16 13:42:43 +0800 | [diff] [blame] | 2263 | spec->pcm_used++; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2264 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 2265 | info->own_chmap = true; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2266 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2267 | pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2268 | pstr->substreams = 1; |
| 2269 | pstr->ops = generic_ops; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2270 | /* pcm number is less than 16 */ |
| 2271 | if (spec->pcm_used >= 16) |
| 2272 | break; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2273 | /* other pstr fields are set in open */ |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | return 0; |
| 2277 | } |
| 2278 | |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2279 | static void free_hdmi_jack_priv(struct snd_jack *jack) |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 2280 | { |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2281 | struct hdmi_pcm *pcm = jack->private_data; |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 2282 | |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2283 | pcm->jack = NULL; |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 2284 | } |
| 2285 | |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 2286 | static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx) |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 2287 | { |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 2288 | char hdmi_str[32] = "HDMI/DP"; |
| 2289 | struct hdmi_spec *spec = codec->spec; |
| 2290 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pcm_idx); |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 2291 | struct snd_jack *jack; |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 2292 | int pcmdev = get_pcm_rec(spec, pcm_idx)->device; |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 2293 | int err; |
| 2294 | |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 2295 | if (pcmdev > 0) |
| 2296 | sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev); |
| 2297 | if (!spec->dyn_pcm_assign && |
| 2298 | !is_jack_detectable(codec, per_pin->pin_nid)) |
| 2299 | strncat(hdmi_str, " Phantom", |
| 2300 | sizeof(hdmi_str) - strlen(hdmi_str) - 1); |
| 2301 | |
| 2302 | err = snd_jack_new(codec->card, hdmi_str, SND_JACK_AVOUT, &jack, |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 2303 | true, false); |
| 2304 | if (err < 0) |
| 2305 | return err; |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2306 | |
| 2307 | spec->pcm_rec[pcm_idx].jack = jack; |
| 2308 | jack->private_data = &spec->pcm_rec[pcm_idx]; |
| 2309 | jack->private_free = free_hdmi_jack_priv; |
Takashi Iwai | 788d441 | 2015-11-12 15:36:13 +0100 | [diff] [blame] | 2310 | return 0; |
| 2311 | } |
| 2312 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2313 | static int generic_hdmi_build_controls(struct hda_codec *codec) |
| 2314 | { |
| 2315 | struct hdmi_spec *spec = codec->spec; |
Wang YanQing | 1f7f51a | 2017-09-03 21:18:49 +0800 | [diff] [blame] | 2316 | int dev, err; |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2317 | int pin_idx, pcm_idx; |
| 2318 | |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2319 | for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { |
Takashi Iwai | 8a7d600 | 2018-04-25 16:19:13 +0200 | [diff] [blame] | 2320 | if (!get_pcm_rec(spec, pcm_idx)->pcm) { |
| 2321 | /* no PCM: mark this for skipping permanently */ |
| 2322 | set_bit(pcm_idx, &spec->pcm_bitmap); |
| 2323 | continue; |
| 2324 | } |
| 2325 | |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2326 | err = generic_hdmi_build_jack(codec, pcm_idx); |
| 2327 | if (err < 0) |
| 2328 | return err; |
Libin Yang | b09887f8 | 2016-01-29 13:53:27 +0800 | [diff] [blame] | 2329 | |
| 2330 | /* create the spdif for each pcm |
| 2331 | * pin will be bound when monitor is connected |
| 2332 | */ |
| 2333 | if (spec->dyn_pcm_assign) |
| 2334 | err = snd_hda_create_dig_out_ctls(codec, |
| 2335 | 0, spec->cvt_nids[0], |
| 2336 | HDA_PCM_TYPE_HDMI); |
| 2337 | else { |
| 2338 | struct hdmi_spec_per_pin *per_pin = |
| 2339 | get_pin(spec, pcm_idx); |
| 2340 | err = snd_hda_create_dig_out_ctls(codec, |
| 2341 | per_pin->pin_nid, |
| 2342 | per_pin->mux_nids[0], |
| 2343 | HDA_PCM_TYPE_HDMI); |
| 2344 | } |
| 2345 | if (err < 0) |
| 2346 | return err; |
| 2347 | snd_hda_spdif_ctls_unassign(codec, pcm_idx); |
Libin Yang | fb087ea | 2016-02-23 16:33:37 +0800 | [diff] [blame] | 2348 | |
Wang YanQing | 1f7f51a | 2017-09-03 21:18:49 +0800 | [diff] [blame] | 2349 | dev = get_pcm_rec(spec, pcm_idx)->device; |
| 2350 | if (dev != SNDRV_PCM_INVALID_DEVICE) { |
| 2351 | /* add control for ELD Bytes */ |
| 2352 | err = hdmi_create_eld_ctl(codec, pcm_idx, dev); |
| 2353 | if (err < 0) |
| 2354 | return err; |
| 2355 | } |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2356 | } |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2357 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2358 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2359 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Kai Vehmanen | ca76282 | 2020-04-28 15:38:36 +0300 | [diff] [blame] | 2360 | struct hdmi_eld *pin_eld = &per_pin->sink_eld; |
David Henningsson | 0b6c49b | 2011-08-23 16:56:03 +0200 | [diff] [blame] | 2361 | |
Kai Vehmanen | ca76282 | 2020-04-28 15:38:36 +0300 | [diff] [blame] | 2362 | pin_eld->eld_valid = false; |
Takashi Iwai | 82b1d73 | 2011-12-20 15:53:07 +0100 | [diff] [blame] | 2363 | hdmi_present_sense(per_pin, 0); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2364 | } |
| 2365 | |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 2366 | /* add channel maps */ |
Libin Yang | 022f344 | 2016-02-03 10:48:34 +0800 | [diff] [blame] | 2367 | for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { |
Takashi Iwai | bbbc7e8 | 2015-02-27 17:43:19 +0100 | [diff] [blame] | 2368 | struct hda_pcm *pcm; |
Takashi Iwai | 2ca320e | 2013-08-22 09:55:36 +0200 | [diff] [blame] | 2369 | |
Libin Yang | 022f344 | 2016-02-03 10:48:34 +0800 | [diff] [blame] | 2370 | pcm = get_pcm_rec(spec, pcm_idx); |
Takashi Iwai | bbbc7e8 | 2015-02-27 17:43:19 +0100 | [diff] [blame] | 2371 | if (!pcm || !pcm->pcm) |
Takashi Iwai | 2ca320e | 2013-08-22 09:55:36 +0200 | [diff] [blame] | 2372 | break; |
Subhransu S. Prusty | 2f6e8a8 | 2016-03-04 19:59:51 +0530 | [diff] [blame] | 2373 | err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 2374 | if (err < 0) |
| 2375 | return err; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 2376 | } |
| 2377 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2378 | return 0; |
| 2379 | } |
| 2380 | |
Takashi Iwai | 8b8d654b | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2381 | static int generic_hdmi_init_per_pins(struct hda_codec *codec) |
| 2382 | { |
| 2383 | struct hdmi_spec *spec = codec->spec; |
| 2384 | int pin_idx; |
| 2385 | |
| 2386 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2387 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Takashi Iwai | 8b8d654b | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2388 | |
| 2389 | per_pin->codec = codec; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2390 | mutex_init(&per_pin->lock); |
Takashi Iwai | 8b8d654b | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2391 | INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2392 | eld_proc_new(per_pin, pin_idx); |
Takashi Iwai | 8b8d654b | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2393 | } |
| 2394 | return 0; |
| 2395 | } |
| 2396 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2397 | static int generic_hdmi_init(struct hda_codec *codec) |
| 2398 | { |
| 2399 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2400 | int pin_idx; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2401 | |
Takashi Iwai | 302d5a8 | 2019-10-29 21:41:20 +0100 | [diff] [blame] | 2402 | mutex_lock(&spec->bind_lock); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2403 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2404 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2405 | hda_nid_t pin_nid = per_pin->pin_nid; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2406 | int dev_id = per_pin->dev_id; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2407 | |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2408 | snd_hda_set_dev_select(codec, pin_nid, dev_id); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2409 | hdmi_init_pin(codec, pin_nid); |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2410 | if (codec_has_acomp(codec)) |
| 2411 | continue; |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 2412 | snd_hda_jack_detect_enable_callback_mst(codec, pin_nid, dev_id, |
| 2413 | jack_callback); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2414 | } |
Takashi Iwai | 302d5a8 | 2019-10-29 21:41:20 +0100 | [diff] [blame] | 2415 | mutex_unlock(&spec->bind_lock); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2416 | return 0; |
| 2417 | } |
| 2418 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2419 | static void hdmi_array_init(struct hdmi_spec *spec, int nums) |
| 2420 | { |
| 2421 | snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums); |
| 2422 | snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | static void hdmi_array_free(struct hdmi_spec *spec) |
| 2426 | { |
| 2427 | snd_array_free(&spec->pins); |
| 2428 | snd_array_free(&spec->cvts); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2429 | } |
| 2430 | |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2431 | static void generic_spec_free(struct hda_codec *codec) |
| 2432 | { |
| 2433 | struct hdmi_spec *spec = codec->spec; |
| 2434 | |
| 2435 | if (spec) { |
| 2436 | hdmi_array_free(spec); |
| 2437 | kfree(spec); |
| 2438 | codec->spec = NULL; |
| 2439 | } |
| 2440 | codec->dp_mst = false; |
| 2441 | } |
| 2442 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2443 | static void generic_hdmi_free(struct hda_codec *codec) |
| 2444 | { |
| 2445 | struct hdmi_spec *spec = codec->spec; |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2446 | int pin_idx, pcm_idx; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2447 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2448 | if (spec->acomp_registered) { |
| 2449 | snd_hdac_acomp_exit(&codec->bus->core); |
| 2450 | } else if (codec_has_acomp(codec)) { |
Takashi Iwai | a57942b | 2018-07-11 16:23:16 +0200 | [diff] [blame] | 2451 | snd_hdac_acomp_register_notifier(&codec->bus->core, NULL); |
Takashi Iwai | 4914da2 | 2019-07-16 08:56:51 +0200 | [diff] [blame] | 2452 | } |
Takashi Iwai | 10a9594 | 2019-11-22 14:26:24 +0100 | [diff] [blame] | 2453 | codec->relaxed_resume = 0; |
David Henningsson | 25adc13 | 2015-08-19 10:48:58 +0200 | [diff] [blame] | 2454 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2455 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2456 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Takashi Iwai | 2f35c63 | 2015-02-27 22:43:26 +0100 | [diff] [blame] | 2457 | cancel_delayed_work_sync(&per_pin->work); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2458 | eld_proc_free(per_pin); |
Libin Yang | 25e4abb | 2016-01-12 11:13:27 +0800 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { |
| 2462 | if (spec->pcm_rec[pcm_idx].jack == NULL) |
| 2463 | continue; |
| 2464 | if (spec->dyn_pcm_assign) |
| 2465 | snd_device_free(codec->card, |
| 2466 | spec->pcm_rec[pcm_idx].jack); |
| 2467 | else |
| 2468 | spec->pcm_rec[pcm_idx].jack = NULL; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2469 | } |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2470 | |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2471 | generic_spec_free(codec); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2472 | } |
| 2473 | |
Wang Xingchao | 28cb72e | 2013-06-24 07:45:23 -0400 | [diff] [blame] | 2474 | #ifdef CONFIG_PM |
| 2475 | static int generic_hdmi_resume(struct hda_codec *codec) |
| 2476 | { |
| 2477 | struct hdmi_spec *spec = codec->spec; |
| 2478 | int pin_idx; |
| 2479 | |
Pierre Ossman | a283368 | 2014-06-18 21:48:09 +0200 | [diff] [blame] | 2480 | codec->patch_ops.init(codec); |
Takashi Iwai | 1a462be | 2020-01-09 10:01:04 +0100 | [diff] [blame] | 2481 | snd_hda_regmap_sync(codec); |
Wang Xingchao | 28cb72e | 2013-06-24 07:45:23 -0400 | [diff] [blame] | 2482 | |
| 2483 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
| 2484 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
| 2485 | hdmi_present_sense(per_pin, 1); |
| 2486 | } |
| 2487 | return 0; |
| 2488 | } |
| 2489 | #endif |
| 2490 | |
Takashi Iwai | fb79e1e | 2011-05-02 12:17:41 +0200 | [diff] [blame] | 2491 | static const struct hda_codec_ops generic_hdmi_patch_ops = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2492 | .init = generic_hdmi_init, |
| 2493 | .free = generic_hdmi_free, |
| 2494 | .build_pcms = generic_hdmi_build_pcms, |
| 2495 | .build_controls = generic_hdmi_build_controls, |
| 2496 | .unsol_event = hdmi_unsol_event, |
Wang Xingchao | 28cb72e | 2013-06-24 07:45:23 -0400 | [diff] [blame] | 2497 | #ifdef CONFIG_PM |
| 2498 | .resume = generic_hdmi_resume, |
| 2499 | #endif |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2500 | }; |
| 2501 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 2502 | static const struct hdmi_ops generic_standard_hdmi_ops = { |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 2503 | .pin_get_eld = hdmi_pin_get_eld, |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame] | 2504 | .pin_setup_infoframe = hdmi_pin_setup_infoframe, |
| 2505 | .pin_hbr_setup = hdmi_pin_hbr_setup, |
| 2506 | .setup_stream = hdmi_setup_stream, |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 2507 | }; |
| 2508 | |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2509 | /* allocate codec->spec and assign/initialize generic parser ops */ |
| 2510 | static int alloc_generic_hdmi(struct hda_codec *codec) |
| 2511 | { |
| 2512 | struct hdmi_spec *spec; |
| 2513 | |
| 2514 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 2515 | if (!spec) |
| 2516 | return -ENOMEM; |
| 2517 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2518 | spec->codec = codec; |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2519 | spec->ops = generic_standard_hdmi_ops; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2520 | spec->dev_num = 1; /* initialize to 1 */ |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2521 | mutex_init(&spec->pcm_lock); |
Takashi Iwai | 302d5a8 | 2019-10-29 21:41:20 +0100 | [diff] [blame] | 2522 | mutex_init(&spec->bind_lock); |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2523 | snd_hdac_register_chmap_ops(&codec->core, &spec->chmap); |
| 2524 | |
| 2525 | spec->chmap.ops.get_chmap = hdmi_get_chmap; |
| 2526 | spec->chmap.ops.set_chmap = hdmi_set_chmap; |
| 2527 | spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached; |
Julia Lawall | 46394db | 2020-10-11 11:19:33 +0200 | [diff] [blame] | 2528 | spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc; |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2529 | |
| 2530 | codec->spec = spec; |
| 2531 | hdmi_array_init(spec, 4); |
| 2532 | |
| 2533 | codec->patch_ops = generic_hdmi_patch_ops; |
| 2534 | |
| 2535 | return 0; |
| 2536 | } |
| 2537 | |
| 2538 | /* generic HDMI parser */ |
| 2539 | static int patch_generic_hdmi(struct hda_codec *codec) |
| 2540 | { |
| 2541 | int err; |
| 2542 | |
| 2543 | err = alloc_generic_hdmi(codec); |
| 2544 | if (err < 0) |
| 2545 | return err; |
| 2546 | |
| 2547 | err = hdmi_parse_codec(codec); |
| 2548 | if (err < 0) { |
| 2549 | generic_spec_free(codec); |
| 2550 | return err; |
| 2551 | } |
| 2552 | |
| 2553 | generic_hdmi_init_per_pins(codec); |
| 2554 | return 0; |
| 2555 | } |
| 2556 | |
| 2557 | /* |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2558 | * generic audio component binding |
| 2559 | */ |
| 2560 | |
| 2561 | /* turn on / off the unsol event jack detection dynamically */ |
| 2562 | static void reprogram_jack_detect(struct hda_codec *codec, hda_nid_t nid, |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 2563 | int dev_id, bool use_acomp) |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2564 | { |
| 2565 | struct hda_jack_tbl *tbl; |
| 2566 | |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 2567 | tbl = snd_hda_jack_tbl_get_mst(codec, nid, dev_id); |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2568 | if (tbl) { |
| 2569 | /* clear unsol even if component notifier is used, or re-enable |
| 2570 | * if notifier is cleared |
| 2571 | */ |
| 2572 | unsigned int val = use_acomp ? 0 : (AC_USRSP_EN | tbl->tag); |
| 2573 | snd_hda_codec_write_cache(codec, nid, 0, |
| 2574 | AC_VERB_SET_UNSOLICITED_ENABLE, val); |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2575 | } |
| 2576 | } |
| 2577 | |
| 2578 | /* set up / clear component notifier dynamically */ |
| 2579 | static void generic_acomp_notifier_set(struct drm_audio_component *acomp, |
| 2580 | bool use_acomp) |
| 2581 | { |
| 2582 | struct hdmi_spec *spec; |
| 2583 | int i; |
| 2584 | |
| 2585 | spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops); |
Takashi Iwai | 302d5a8 | 2019-10-29 21:41:20 +0100 | [diff] [blame] | 2586 | mutex_lock(&spec->bind_lock); |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2587 | spec->use_acomp_notifier = use_acomp; |
| 2588 | spec->codec->relaxed_resume = use_acomp; |
Takashi Iwai | c2c3657 | 2020-07-28 10:20:33 +0200 | [diff] [blame] | 2589 | spec->codec->bus->keep_power = 0; |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2590 | /* reprogram each jack detection logic depending on the notifier */ |
Takashi Iwai | db84540 | 2020-02-06 17:28:02 +0100 | [diff] [blame] | 2591 | for (i = 0; i < spec->num_pins; i++) |
| 2592 | reprogram_jack_detect(spec->codec, |
| 2593 | get_pin(spec, i)->pin_nid, |
| 2594 | get_pin(spec, i)->dev_id, |
| 2595 | use_acomp); |
Takashi Iwai | 302d5a8 | 2019-10-29 21:41:20 +0100 | [diff] [blame] | 2596 | mutex_unlock(&spec->bind_lock); |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | /* enable / disable the notifier via master bind / unbind */ |
| 2600 | static int generic_acomp_master_bind(struct device *dev, |
| 2601 | struct drm_audio_component *acomp) |
| 2602 | { |
| 2603 | generic_acomp_notifier_set(acomp, true); |
| 2604 | return 0; |
| 2605 | } |
| 2606 | |
| 2607 | static void generic_acomp_master_unbind(struct device *dev, |
| 2608 | struct drm_audio_component *acomp) |
| 2609 | { |
| 2610 | generic_acomp_notifier_set(acomp, false); |
| 2611 | } |
| 2612 | |
| 2613 | /* check whether both HD-audio and DRM PCI devices belong to the same bus */ |
| 2614 | static int match_bound_vga(struct device *dev, int subtype, void *data) |
| 2615 | { |
| 2616 | struct hdac_bus *bus = data; |
| 2617 | struct pci_dev *pci, *master; |
| 2618 | |
| 2619 | if (!dev_is_pci(dev) || !dev_is_pci(bus->dev)) |
| 2620 | return 0; |
| 2621 | master = to_pci_dev(bus->dev); |
| 2622 | pci = to_pci_dev(dev); |
| 2623 | return master->bus == pci->bus; |
| 2624 | } |
| 2625 | |
| 2626 | /* audio component notifier for AMD/Nvidia HDMI codecs */ |
| 2627 | static void generic_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id) |
| 2628 | { |
| 2629 | struct hda_codec *codec = audio_ptr; |
| 2630 | struct hdmi_spec *spec = codec->spec; |
| 2631 | hda_nid_t pin_nid = spec->port2pin(codec, port); |
| 2632 | |
| 2633 | if (!pin_nid) |
| 2634 | return; |
| 2635 | if (get_wcaps_type(get_wcaps(codec, pin_nid)) != AC_WID_PIN) |
| 2636 | return; |
| 2637 | /* skip notification during system suspend (but not in runtime PM); |
| 2638 | * the state will be updated at resume |
| 2639 | */ |
| 2640 | if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0) |
| 2641 | return; |
| 2642 | /* ditto during suspend/resume process itself */ |
| 2643 | if (snd_hdac_is_in_pm(&codec->core)) |
| 2644 | return; |
| 2645 | |
| 2646 | check_presence_and_report(codec, pin_nid, dev_id); |
| 2647 | } |
| 2648 | |
| 2649 | /* set up the private drm_audio_ops from the template */ |
| 2650 | static void setup_drm_audio_ops(struct hda_codec *codec, |
| 2651 | const struct drm_audio_component_audio_ops *ops) |
| 2652 | { |
| 2653 | struct hdmi_spec *spec = codec->spec; |
| 2654 | |
| 2655 | spec->drm_audio_ops.audio_ptr = codec; |
| 2656 | /* intel_audio_codec_enable() or intel_audio_codec_disable() |
| 2657 | * will call pin_eld_notify with using audio_ptr pointer |
| 2658 | * We need make sure audio_ptr is really setup |
| 2659 | */ |
| 2660 | wmb(); |
| 2661 | spec->drm_audio_ops.pin2port = ops->pin2port; |
| 2662 | spec->drm_audio_ops.pin_eld_notify = ops->pin_eld_notify; |
| 2663 | spec->drm_audio_ops.master_bind = ops->master_bind; |
| 2664 | spec->drm_audio_ops.master_unbind = ops->master_unbind; |
| 2665 | } |
| 2666 | |
| 2667 | /* initialize the generic HDMI audio component */ |
| 2668 | static void generic_acomp_init(struct hda_codec *codec, |
| 2669 | const struct drm_audio_component_audio_ops *ops, |
| 2670 | int (*port2pin)(struct hda_codec *, int)) |
| 2671 | { |
| 2672 | struct hdmi_spec *spec = codec->spec; |
| 2673 | |
Takashi Iwai | b392350 | 2020-04-15 18:25:23 +0200 | [diff] [blame] | 2674 | if (!enable_acomp) { |
| 2675 | codec_info(codec, "audio component disabled by module option\n"); |
| 2676 | return; |
| 2677 | } |
| 2678 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2679 | spec->port2pin = port2pin; |
| 2680 | setup_drm_audio_ops(codec, ops); |
| 2681 | if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops, |
Takashi Iwai | dd23e1d | 2019-08-27 16:37:50 +0200 | [diff] [blame] | 2682 | match_bound_vga, 0)) { |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2683 | spec->acomp_registered = true; |
Takashi Iwai | dd23e1d | 2019-08-27 16:37:50 +0200 | [diff] [blame] | 2684 | } |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | /* |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2688 | * Intel codec parsers and helpers |
| 2689 | */ |
| 2690 | |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2691 | #define INTEL_GET_VENDOR_VERB 0xf81 |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2692 | #define INTEL_SET_VENDOR_VERB 0x781 |
| 2693 | #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */ |
| 2694 | #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */ |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2695 | |
| 2696 | static void intel_haswell_enable_all_pins(struct hda_codec *codec, |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2697 | bool update_tree) |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2698 | { |
| 2699 | unsigned int vendor_param; |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2700 | struct hdmi_spec *spec = codec->spec; |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2701 | |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2702 | vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0, |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2703 | INTEL_GET_VENDOR_VERB, 0); |
| 2704 | if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS) |
| 2705 | return; |
| 2706 | |
| 2707 | vendor_param |= INTEL_EN_ALL_PIN_CVTS; |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2708 | vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0, |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2709 | INTEL_SET_VENDOR_VERB, vendor_param); |
| 2710 | if (vendor_param == -1) |
| 2711 | return; |
| 2712 | |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2713 | if (update_tree) |
| 2714 | snd_hda_codec_update_widgets(codec); |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2715 | } |
| 2716 | |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2717 | static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec) |
| 2718 | { |
| 2719 | unsigned int vendor_param; |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2720 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2721 | |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2722 | vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0, |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2723 | INTEL_GET_VENDOR_VERB, 0); |
| 2724 | if (vendor_param == -1 || vendor_param & INTEL_EN_DP12) |
| 2725 | return; |
| 2726 | |
| 2727 | /* enable DP1.2 mode */ |
| 2728 | vendor_param |= INTEL_EN_DP12; |
Takashi Iwai | a551d91 | 2015-02-26 12:34:49 +0100 | [diff] [blame] | 2729 | snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB); |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2730 | snd_hda_codec_write_cache(codec, spec->vendor_nid, 0, |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2731 | INTEL_SET_VENDOR_VERB, vendor_param); |
| 2732 | } |
| 2733 | |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2734 | /* Haswell needs to re-issue the vendor-specific verbs before turning to D0. |
| 2735 | * Otherwise you may get severe h/w communication errors. |
| 2736 | */ |
| 2737 | static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg, |
| 2738 | unsigned int power_state) |
| 2739 | { |
| 2740 | if (power_state == AC_PWRST_D0) { |
| 2741 | intel_haswell_enable_all_pins(codec, false); |
| 2742 | intel_haswell_fixup_enable_dp12(codec); |
| 2743 | } |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2744 | |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2745 | snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state); |
| 2746 | snd_hda_codec_set_power_to_all(codec, fg, power_state); |
| 2747 | } |
Mengdong Lin | 6ffe168 | 2012-12-18 16:59:15 -0500 | [diff] [blame] | 2748 | |
Takashi Iwai | a57942b | 2018-07-11 16:23:16 +0200 | [diff] [blame] | 2749 | /* There is a fixed mapping between audio pin node and display port. |
| 2750 | * on SNB, IVY, HSW, BSW, SKL, BXT, KBL: |
| 2751 | * Pin Widget 5 - PORT B (port = 1 in i915 driver) |
| 2752 | * Pin Widget 6 - PORT C (port = 2 in i915 driver) |
| 2753 | * Pin Widget 7 - PORT D (port = 3 in i915 driver) |
| 2754 | * |
| 2755 | * on VLV, ILK: |
| 2756 | * Pin Widget 4 - PORT B (port = 1 in i915 driver) |
| 2757 | * Pin Widget 5 - PORT C (port = 2 in i915 driver) |
| 2758 | * Pin Widget 6 - PORT D (port = 3 in i915 driver) |
| 2759 | */ |
| 2760 | static int intel_base_nid(struct hda_codec *codec) |
| 2761 | { |
| 2762 | switch (codec->core.vendor_id) { |
| 2763 | case 0x80860054: /* ILK */ |
| 2764 | case 0x80862804: /* ILK */ |
| 2765 | case 0x80862882: /* VLV */ |
| 2766 | return 4; |
| 2767 | default: |
| 2768 | return 5; |
| 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | static int intel_pin2port(void *audio_ptr, int pin_nid) |
| 2773 | { |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2774 | struct hda_codec *codec = audio_ptr; |
| 2775 | struct hdmi_spec *spec = codec->spec; |
| 2776 | int base_nid, i; |
Takashi Iwai | a57942b | 2018-07-11 16:23:16 +0200 | [diff] [blame] | 2777 | |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2778 | if (!spec->port_num) { |
| 2779 | base_nid = intel_base_nid(codec); |
| 2780 | if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3)) |
| 2781 | return -1; |
Kai Vehmanen | c8e3eb9 | 2019-11-15 14:44:48 +0200 | [diff] [blame] | 2782 | return pin_nid - base_nid + 1; |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | /* |
| 2786 | * looking for the pin number in the mapping table and return |
| 2787 | * the index which indicate the port number |
| 2788 | */ |
| 2789 | for (i = 0; i < spec->port_num; i++) { |
| 2790 | if (pin_nid == spec->port_map[i]) |
Kai Vehmanen | d577cf7 | 2019-11-15 14:44:47 +0200 | [diff] [blame] | 2791 | return i; |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2792 | } |
| 2793 | |
Kai Vehmanen | 13b1f8a | 2020-12-11 14:45:47 +0200 | [diff] [blame] | 2794 | codec_info(codec, "Can't find the HDMI/DP port for pin NID 0x%x\n", pin_nid); |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2795 | return -1; |
Takashi Iwai | a57942b | 2018-07-11 16:23:16 +0200 | [diff] [blame] | 2796 | } |
| 2797 | |
Takashi Iwai | 3140aaf | 2019-07-15 23:14:53 +0200 | [diff] [blame] | 2798 | static int intel_port2pin(struct hda_codec *codec, int port) |
| 2799 | { |
| 2800 | struct hdmi_spec *spec = codec->spec; |
| 2801 | |
| 2802 | if (!spec->port_num) { |
| 2803 | /* we assume only from port-B to port-D */ |
| 2804 | if (port < 1 || port > 3) |
| 2805 | return 0; |
Takashi Iwai | 3140aaf | 2019-07-15 23:14:53 +0200 | [diff] [blame] | 2806 | return port + intel_base_nid(codec) - 1; |
| 2807 | } |
| 2808 | |
Kai Vehmanen | d577cf7 | 2019-11-15 14:44:47 +0200 | [diff] [blame] | 2809 | if (port < 0 || port >= spec->port_num) |
Takashi Iwai | 3140aaf | 2019-07-15 23:14:53 +0200 | [diff] [blame] | 2810 | return 0; |
Kai Vehmanen | d577cf7 | 2019-11-15 14:44:47 +0200 | [diff] [blame] | 2811 | return spec->port_map[port]; |
Takashi Iwai | 3140aaf | 2019-07-15 23:14:53 +0200 | [diff] [blame] | 2812 | } |
| 2813 | |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 2814 | static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe) |
David Henningsson | 25adc13 | 2015-08-19 10:48:58 +0200 | [diff] [blame] | 2815 | { |
| 2816 | struct hda_codec *codec = audio_ptr; |
Takashi Iwai | 7ff652f | 2016-03-21 14:50:24 +0100 | [diff] [blame] | 2817 | int pin_nid; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2818 | int dev_id = pipe; |
David Henningsson | 25adc13 | 2015-08-19 10:48:58 +0200 | [diff] [blame] | 2819 | |
Takashi Iwai | 3140aaf | 2019-07-15 23:14:53 +0200 | [diff] [blame] | 2820 | pin_nid = intel_port2pin(codec, port); |
| 2821 | if (!pin_nid) |
Takashi Iwai | 4f8e4f3 | 2016-03-10 12:02:49 +0100 | [diff] [blame] | 2822 | return; |
Takashi Iwai | 8ae743e | 2015-11-27 14:23:00 +0100 | [diff] [blame] | 2823 | /* skip notification during system suspend (but not in runtime PM); |
| 2824 | * the state will be updated at resume |
| 2825 | */ |
| 2826 | if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0) |
| 2827 | return; |
Takashi Iwai | eb399d3 | 2015-11-27 14:53:35 +0100 | [diff] [blame] | 2828 | /* ditto during suspend/resume process itself */ |
Takashi Iwai | feb20fa | 2018-06-27 09:03:51 +0200 | [diff] [blame] | 2829 | if (snd_hdac_is_in_pm(&codec->core)) |
Takashi Iwai | eb399d3 | 2015-11-27 14:53:35 +0100 | [diff] [blame] | 2830 | return; |
Takashi Iwai | 8ae743e | 2015-11-27 14:23:00 +0100 | [diff] [blame] | 2831 | |
Takashi Iwai | bb03ed2 | 2016-04-21 16:39:17 +0200 | [diff] [blame] | 2832 | snd_hdac_i915_set_bclk(&codec->bus->core); |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2833 | check_presence_and_report(codec, pin_nid, dev_id); |
David Henningsson | 25adc13 | 2015-08-19 10:48:58 +0200 | [diff] [blame] | 2834 | } |
| 2835 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2836 | static const struct drm_audio_component_audio_ops intel_audio_ops = { |
| 2837 | .pin2port = intel_pin2port, |
| 2838 | .pin_eld_notify = intel_pin_eld_notify, |
| 2839 | }; |
| 2840 | |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2841 | /* register i915 component pin_eld_notify callback */ |
| 2842 | static void register_i915_notifier(struct hda_codec *codec) |
| 2843 | { |
| 2844 | struct hdmi_spec *spec = codec->spec; |
| 2845 | |
| 2846 | spec->use_acomp_notifier = true; |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 2847 | spec->port2pin = intel_port2pin; |
| 2848 | setup_drm_audio_ops(codec, &intel_audio_ops); |
Takashi Iwai | a57942b | 2018-07-11 16:23:16 +0200 | [diff] [blame] | 2849 | snd_hdac_acomp_register_notifier(&codec->bus->core, |
Takashi Iwai | 82887c0 | 2018-07-11 15:48:18 +0200 | [diff] [blame] | 2850 | &spec->drm_audio_ops); |
Takashi Iwai | 4914da2 | 2019-07-16 08:56:51 +0200 | [diff] [blame] | 2851 | /* no need for forcible resume for jack check thanks to notifier */ |
| 2852 | codec->relaxed_resume = 1; |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2853 | } |
| 2854 | |
Takashi Iwai | 2c1c9b8 | 2016-03-21 12:42:06 +0100 | [diff] [blame] | 2855 | /* setup_stream ops override for HSW+ */ |
| 2856 | static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 2857 | hda_nid_t pin_nid, int dev_id, u32 stream_tag, |
| 2858 | int format) |
Takashi Iwai | 2c1c9b8 | 2016-03-21 12:42:06 +0100 | [diff] [blame] | 2859 | { |
| 2860 | haswell_verify_D0(codec, cvt_nid, pin_nid); |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 2861 | return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id, |
| 2862 | stream_tag, format); |
Takashi Iwai | 2c1c9b8 | 2016-03-21 12:42:06 +0100 | [diff] [blame] | 2863 | } |
| 2864 | |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 2865 | /* pin_cvt_fixup ops override for HSW+ and VLV+ */ |
| 2866 | static void i915_pin_cvt_fixup(struct hda_codec *codec, |
| 2867 | struct hdmi_spec_per_pin *per_pin, |
| 2868 | hda_nid_t cvt_nid) |
| 2869 | { |
| 2870 | if (per_pin) { |
Kai Vehmanen | 858e0ad | 2020-08-26 20:03:06 +0300 | [diff] [blame] | 2871 | haswell_verify_D0(codec, per_pin->cvt_nid, per_pin->pin_nid); |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2872 | snd_hda_set_dev_select(codec, per_pin->pin_nid, |
| 2873 | per_pin->dev_id); |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 2874 | intel_verify_pin_cvt_connect(codec, per_pin); |
| 2875 | intel_not_share_assigned_cvt(codec, per_pin->pin_nid, |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2876 | per_pin->dev_id, per_pin->mux_idx); |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 2877 | } else { |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2878 | intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid); |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 2879 | } |
| 2880 | } |
| 2881 | |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 2882 | /* precondition and allocation for Intel codecs */ |
| 2883 | static int alloc_intel_hdmi(struct hda_codec *codec) |
| 2884 | { |
Takashi Iwai | f2dbe87 | 2019-08-13 17:11:28 +0200 | [diff] [blame] | 2885 | int err; |
| 2886 | |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 2887 | /* requires i915 binding */ |
| 2888 | if (!codec->bus->core.audio_component) { |
| 2889 | codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n"); |
Takashi Iwai | fdd49c5 | 2018-06-27 09:54:46 +0200 | [diff] [blame] | 2890 | /* set probe_id here to prevent generic fallback binding */ |
| 2891 | codec->probe_id = HDA_CODEC_ID_SKIP_PROBE; |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 2892 | return -ENODEV; |
| 2893 | } |
| 2894 | |
Takashi Iwai | f2dbe87 | 2019-08-13 17:11:28 +0200 | [diff] [blame] | 2895 | err = alloc_generic_hdmi(codec); |
| 2896 | if (err < 0) |
| 2897 | return err; |
| 2898 | /* no need to handle unsol events */ |
| 2899 | codec->patch_ops.unsol_event = NULL; |
| 2900 | return 0; |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | /* parse and post-process for Intel codecs */ |
| 2904 | static int parse_intel_hdmi(struct hda_codec *codec) |
| 2905 | { |
Kai Vehmanen | 2928fa0 | 2020-01-20 18:01:17 +0200 | [diff] [blame] | 2906 | int err, retries = 3; |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 2907 | |
Kai Vehmanen | 2928fa0 | 2020-01-20 18:01:17 +0200 | [diff] [blame] | 2908 | do { |
| 2909 | err = hdmi_parse_codec(codec); |
| 2910 | } while (err < 0 && retries--); |
| 2911 | |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 2912 | if (err < 0) { |
| 2913 | generic_spec_free(codec); |
| 2914 | return err; |
| 2915 | } |
| 2916 | |
| 2917 | generic_hdmi_init_per_pins(codec); |
| 2918 | register_i915_notifier(codec); |
| 2919 | return 0; |
| 2920 | } |
| 2921 | |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2922 | /* Intel Haswell and onwards; audio component with eld notifier */ |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2923 | static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid, |
| 2924 | const int *port_map, int port_num) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2925 | { |
| 2926 | struct hdmi_spec *spec; |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2927 | int err; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2928 | |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 2929 | err = alloc_intel_hdmi(codec); |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2930 | if (err < 0) |
| 2931 | return err; |
| 2932 | spec = codec->spec; |
Libin Yang | 9152085 | 2017-01-12 16:04:53 +0800 | [diff] [blame] | 2933 | codec->dp_mst = true; |
| 2934 | spec->dyn_pcm_assign = true; |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2935 | spec->vendor_nid = vendor_nid; |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2936 | spec->port_map = port_map; |
| 2937 | spec->port_num = port_num; |
Takashi Iwai | cb45722 | 2019-11-11 20:09:37 +0100 | [diff] [blame] | 2938 | spec->intel_hsw_fixup = true; |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2939 | |
| 2940 | intel_haswell_enable_all_pins(codec, true); |
| 2941 | intel_haswell_fixup_enable_dp12(codec); |
| 2942 | |
Takashi Iwai | 46594d3 | 2018-12-09 10:10:19 +0100 | [diff] [blame] | 2943 | codec->display_power_control = 1; |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2944 | |
| 2945 | codec->patch_ops.set_power_state = haswell_set_power_state; |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2946 | codec->depop_delay = 0; |
| 2947 | codec->auto_runtime_pm = 1; |
| 2948 | |
Takashi Iwai | 2c1c9b8 | 2016-03-21 12:42:06 +0100 | [diff] [blame] | 2949 | spec->ops.setup_stream = i915_hsw_setup_stream; |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 2950 | spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup; |
Takashi Iwai | 2c1c9b8 | 2016-03-21 12:42:06 +0100 | [diff] [blame] | 2951 | |
Harsha Priya | 951894c | 2020-07-06 13:53:17 -0700 | [diff] [blame] | 2952 | /* |
| 2953 | * Enable silent stream feature, if it is enabled via |
| 2954 | * module param or Kconfig option |
| 2955 | */ |
| 2956 | if (enable_silent_stream) |
| 2957 | spec->send_silent_stream = true; |
| 2958 | |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 2959 | return parse_intel_hdmi(codec); |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2960 | } |
| 2961 | |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2962 | static int patch_i915_hsw_hdmi(struct hda_codec *codec) |
| 2963 | { |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2964 | return intel_hsw_common_init(codec, 0x08, NULL, 0); |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | static int patch_i915_glk_hdmi(struct hda_codec *codec) |
| 2968 | { |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2969 | return intel_hsw_common_init(codec, 0x0b, NULL, 0); |
| 2970 | } |
| 2971 | |
| 2972 | static int patch_i915_icl_hdmi(struct hda_codec *codec) |
| 2973 | { |
| 2974 | /* |
| 2975 | * pin to port mapping table where the value indicate the pin number and |
Kai Vehmanen | d577cf7 | 2019-11-15 14:44:47 +0200 | [diff] [blame] | 2976 | * the index indicate the port number. |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2977 | */ |
Kai Vehmanen | d577cf7 | 2019-11-15 14:44:47 +0200 | [diff] [blame] | 2978 | static const int map[] = {0x0, 0x4, 0x6, 0x8, 0xa, 0xb}; |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 2979 | |
| 2980 | return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map)); |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 2981 | } |
| 2982 | |
Kai Vehmanen | 9a11ba7 | 2019-11-05 18:10:53 +0200 | [diff] [blame] | 2983 | static int patch_i915_tgl_hdmi(struct hda_codec *codec) |
| 2984 | { |
| 2985 | /* |
| 2986 | * pin to port mapping table where the value indicate the pin number and |
Kai Vehmanen | d577cf7 | 2019-11-15 14:44:47 +0200 | [diff] [blame] | 2987 | * the index indicate the port number. |
Kai Vehmanen | 9a11ba7 | 2019-11-05 18:10:53 +0200 | [diff] [blame] | 2988 | */ |
| 2989 | static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}; |
| 2990 | |
| 2991 | return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map)); |
| 2992 | } |
| 2993 | |
Takashi Iwai | 7ff652f | 2016-03-21 14:50:24 +0100 | [diff] [blame] | 2994 | /* Intel Baytrail and Braswell; with eld notifier */ |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 2995 | static int patch_i915_byt_hdmi(struct hda_codec *codec) |
| 2996 | { |
| 2997 | struct hdmi_spec *spec; |
| 2998 | int err; |
| 2999 | |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 3000 | err = alloc_intel_hdmi(codec); |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 3001 | if (err < 0) |
| 3002 | return err; |
| 3003 | spec = codec->spec; |
| 3004 | |
Mengdong Lin | 2bd1f73f | 2015-04-29 17:43:43 +0800 | [diff] [blame] | 3005 | /* For Valleyview/Cherryview, only the display codec is in the display |
| 3006 | * power well and can use link_power ops to request/release the power. |
Mengdong Lin | 2bd1f73f | 2015-04-29 17:43:43 +0800 | [diff] [blame] | 3007 | */ |
Takashi Iwai | 029d92c | 2018-12-08 17:31:49 +0100 | [diff] [blame] | 3008 | codec->display_power_control = 1; |
Mengdong Lin | 2bd1f73f | 2015-04-29 17:43:43 +0800 | [diff] [blame] | 3009 | |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 3010 | codec->depop_delay = 0; |
| 3011 | codec->auto_runtime_pm = 1; |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 3012 | |
Takashi Iwai | 4846a67 | 2016-03-21 12:56:46 +0100 | [diff] [blame] | 3013 | spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup; |
| 3014 | |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 3015 | return parse_intel_hdmi(codec); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3016 | } |
| 3017 | |
Takashi Iwai | 7ff652f | 2016-03-21 14:50:24 +0100 | [diff] [blame] | 3018 | /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */ |
Takashi Iwai | e85015a3 | 2016-03-21 13:56:19 +0100 | [diff] [blame] | 3019 | static int patch_i915_cpt_hdmi(struct hda_codec *codec) |
| 3020 | { |
Takashi Iwai | e85015a3 | 2016-03-21 13:56:19 +0100 | [diff] [blame] | 3021 | int err; |
| 3022 | |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 3023 | err = alloc_intel_hdmi(codec); |
Takashi Iwai | e85015a3 | 2016-03-21 13:56:19 +0100 | [diff] [blame] | 3024 | if (err < 0) |
| 3025 | return err; |
Takashi Iwai | 43f6c8d | 2017-06-28 14:18:29 +0200 | [diff] [blame] | 3026 | return parse_intel_hdmi(codec); |
Takashi Iwai | e85015a3 | 2016-03-21 13:56:19 +0100 | [diff] [blame] | 3027 | } |
| 3028 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3029 | /* |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3030 | * Shared non-generic implementations |
| 3031 | */ |
| 3032 | |
| 3033 | static int simple_playback_build_pcms(struct hda_codec *codec) |
| 3034 | { |
| 3035 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3036 | struct hda_pcm *info; |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 3037 | unsigned int chans; |
| 3038 | struct hda_pcm_stream *pstr; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3039 | struct hdmi_spec_per_cvt *per_cvt; |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3040 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3041 | per_cvt = get_cvt(spec, 0); |
| 3042 | chans = get_wcaps(codec, per_cvt->cvt_nid); |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 3043 | chans = get_wcaps_channels(chans); |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3044 | |
Takashi Iwai | bbbc7e8 | 2015-02-27 17:43:19 +0100 | [diff] [blame] | 3045 | info = snd_hda_codec_pcm_new(codec, "HDMI 0"); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3046 | if (!info) |
| 3047 | return -ENOMEM; |
Libin Yang | 2bea241 | 2016-01-12 11:13:26 +0800 | [diff] [blame] | 3048 | spec->pcm_rec[0].pcm = info; |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 3049 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
| 3050 | pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; |
| 3051 | *pstr = spec->pcm_playback; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3052 | pstr->nid = per_cvt->cvt_nid; |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 3053 | if (pstr->channels_max <= 2 && chans && chans <= 16) |
| 3054 | pstr->channels_max = chans; |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3055 | |
| 3056 | return 0; |
| 3057 | } |
| 3058 | |
Takashi Iwai | 4b6ace9 | 2012-06-15 11:53:32 +0200 | [diff] [blame] | 3059 | /* unsolicited event for jack sensing */ |
| 3060 | static void simple_hdmi_unsol_event(struct hda_codec *codec, |
| 3061 | unsigned int res) |
| 3062 | { |
Takashi Iwai | 9dd8cf1 | 2012-06-21 10:43:15 +0200 | [diff] [blame] | 3063 | snd_hda_jack_set_dirty_all(codec); |
Takashi Iwai | 4b6ace9 | 2012-06-15 11:53:32 +0200 | [diff] [blame] | 3064 | snd_hda_jack_report_sync(codec); |
| 3065 | } |
| 3066 | |
| 3067 | /* generic_hdmi_build_jack can be used for simple_hdmi, too, |
| 3068 | * as long as spec->pins[] is set correctly |
| 3069 | */ |
| 3070 | #define simple_hdmi_build_jack generic_hdmi_build_jack |
| 3071 | |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3072 | static int simple_playback_build_controls(struct hda_codec *codec) |
| 3073 | { |
| 3074 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3075 | struct hdmi_spec_per_cvt *per_cvt; |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3076 | int err; |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3077 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3078 | per_cvt = get_cvt(spec, 0); |
Anssi Hannula | c9a6338 | 2013-12-10 22:46:34 +0200 | [diff] [blame] | 3079 | err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid, |
| 3080 | per_cvt->cvt_nid, |
| 3081 | HDA_PCM_TYPE_HDMI); |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 3082 | if (err < 0) |
| 3083 | return err; |
| 3084 | return simple_hdmi_build_jack(codec, 0); |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3085 | } |
| 3086 | |
Takashi Iwai | 4f0110c | 2012-06-15 12:45:43 +0200 | [diff] [blame] | 3087 | static int simple_playback_init(struct hda_codec *codec) |
| 3088 | { |
| 3089 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3090 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0); |
| 3091 | hda_nid_t pin = per_pin->pin_nid; |
Takashi Iwai | 4f0110c | 2012-06-15 12:45:43 +0200 | [diff] [blame] | 3092 | |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 3093 | snd_hda_codec_write(codec, pin, 0, |
| 3094 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 3095 | /* some codecs require to unmute the pin */ |
| 3096 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) |
| 3097 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 3098 | AMP_OUT_UNMUTE); |
Nikhil Mahale | 5204a05 | 2019-11-19 14:17:08 +0530 | [diff] [blame] | 3099 | snd_hda_jack_detect_enable(codec, pin, per_pin->dev_id); |
Takashi Iwai | 4f0110c | 2012-06-15 12:45:43 +0200 | [diff] [blame] | 3100 | return 0; |
| 3101 | } |
| 3102 | |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3103 | static void simple_playback_free(struct hda_codec *codec) |
| 3104 | { |
| 3105 | struct hdmi_spec *spec = codec->spec; |
| 3106 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3107 | hdmi_array_free(spec); |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 3108 | kfree(spec); |
| 3109 | } |
| 3110 | |
| 3111 | /* |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3112 | * Nvidia specific implementations |
| 3113 | */ |
| 3114 | |
| 3115 | #define Nv_VERB_SET_Channel_Allocation 0xF79 |
| 3116 | #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A |
| 3117 | #define Nv_VERB_SET_Audio_Protection_On 0xF98 |
| 3118 | #define Nv_VERB_SET_Audio_Protection_Off 0xF99 |
| 3119 | |
| 3120 | #define nvhdmi_master_con_nid_7x 0x04 |
| 3121 | #define nvhdmi_master_pin_nid_7x 0x05 |
| 3122 | |
Takashi Iwai | fb79e1e | 2011-05-02 12:17:41 +0200 | [diff] [blame] | 3123 | static const hda_nid_t nvhdmi_con_nids_7x[4] = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3124 | /*front, rear, clfe, rear_surr */ |
| 3125 | 0x6, 0x8, 0xa, 0xc, |
| 3126 | }; |
| 3127 | |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 3128 | static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = { |
| 3129 | /* set audio protect on */ |
| 3130 | { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1}, |
| 3131 | /* enable digital output on pin widget */ |
| 3132 | { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 3133 | {} /* terminator */ |
| 3134 | }; |
| 3135 | |
| 3136 | static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3137 | /* set audio protect on */ |
| 3138 | { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1}, |
| 3139 | /* enable digital output on pin widget */ |
| 3140 | { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 3141 | { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 3142 | { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 3143 | { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 3144 | { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 3145 | {} /* terminator */ |
| 3146 | }; |
| 3147 | |
| 3148 | #ifdef LIMITED_RATE_FMT_SUPPORT |
| 3149 | /* support only the safe format and rate */ |
| 3150 | #define SUPPORTED_RATES SNDRV_PCM_RATE_48000 |
| 3151 | #define SUPPORTED_MAXBPS 16 |
| 3152 | #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE |
| 3153 | #else |
| 3154 | /* support all rates and formats */ |
| 3155 | #define SUPPORTED_RATES \ |
| 3156 | (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\ |
| 3157 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\ |
| 3158 | SNDRV_PCM_RATE_192000) |
| 3159 | #define SUPPORTED_MAXBPS 24 |
| 3160 | #define SUPPORTED_FORMATS \ |
| 3161 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 3162 | #endif |
| 3163 | |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 3164 | static int nvhdmi_7x_init_2ch(struct hda_codec *codec) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3165 | { |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 3166 | snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch); |
| 3167 | return 0; |
| 3168 | } |
| 3169 | |
| 3170 | static int nvhdmi_7x_init_8ch(struct hda_codec *codec) |
| 3171 | { |
| 3172 | snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3173 | return 0; |
| 3174 | } |
| 3175 | |
Takashi Iwai | 50c697adf | 2017-06-07 14:20:07 +0200 | [diff] [blame] | 3176 | static const unsigned int channels_2_6_8[] = { |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 3177 | 2, 6, 8 |
| 3178 | }; |
| 3179 | |
Takashi Iwai | 50c697adf | 2017-06-07 14:20:07 +0200 | [diff] [blame] | 3180 | static const unsigned int channels_2_8[] = { |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 3181 | 2, 8 |
| 3182 | }; |
| 3183 | |
Takashi Iwai | 50c697adf | 2017-06-07 14:20:07 +0200 | [diff] [blame] | 3184 | static const struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = { |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 3185 | .count = ARRAY_SIZE(channels_2_6_8), |
| 3186 | .list = channels_2_6_8, |
| 3187 | .mask = 0, |
| 3188 | }; |
| 3189 | |
Takashi Iwai | 50c697adf | 2017-06-07 14:20:07 +0200 | [diff] [blame] | 3190 | static const struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = { |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 3191 | .count = ARRAY_SIZE(channels_2_8), |
| 3192 | .list = channels_2_8, |
| 3193 | .mask = 0, |
| 3194 | }; |
| 3195 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3196 | static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 3197 | struct hda_codec *codec, |
| 3198 | struct snd_pcm_substream *substream) |
| 3199 | { |
| 3200 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | 50c697adf | 2017-06-07 14:20:07 +0200 | [diff] [blame] | 3201 | const struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL; |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 3202 | |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 3203 | switch (codec->preset->vendor_id) { |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 3204 | case 0x10de0002: |
| 3205 | case 0x10de0003: |
| 3206 | case 0x10de0005: |
| 3207 | case 0x10de0006: |
| 3208 | hw_constraints_channels = &hw_constraints_2_8_channels; |
| 3209 | break; |
| 3210 | case 0x10de0007: |
| 3211 | hw_constraints_channels = &hw_constraints_2_6_8_channels; |
| 3212 | break; |
| 3213 | default: |
| 3214 | break; |
| 3215 | } |
| 3216 | |
| 3217 | if (hw_constraints_channels != NULL) { |
| 3218 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 3219 | SNDRV_PCM_HW_PARAM_CHANNELS, |
| 3220 | hw_constraints_channels); |
Takashi Iwai | ad09fc9 | 2011-01-14 09:42:27 +0100 | [diff] [blame] | 3221 | } else { |
| 3222 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 3223 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 3224 | } |
| 3225 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3226 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 3227 | } |
| 3228 | |
| 3229 | static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 3230 | struct hda_codec *codec, |
| 3231 | struct snd_pcm_substream *substream) |
| 3232 | { |
| 3233 | struct hdmi_spec *spec = codec->spec; |
| 3234 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 3235 | } |
| 3236 | |
| 3237 | static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 3238 | struct hda_codec *codec, |
| 3239 | unsigned int stream_tag, |
| 3240 | unsigned int format, |
| 3241 | struct snd_pcm_substream *substream) |
| 3242 | { |
| 3243 | struct hdmi_spec *spec = codec->spec; |
| 3244 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 3245 | stream_tag, format, substream); |
| 3246 | } |
| 3247 | |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3248 | static const struct hda_pcm_stream simple_pcm_playback = { |
| 3249 | .substreams = 1, |
| 3250 | .channels_min = 2, |
| 3251 | .channels_max = 2, |
| 3252 | .ops = { |
| 3253 | .open = simple_playback_pcm_open, |
| 3254 | .close = simple_playback_pcm_close, |
| 3255 | .prepare = simple_playback_pcm_prepare |
| 3256 | }, |
| 3257 | }; |
| 3258 | |
| 3259 | static const struct hda_codec_ops simple_hdmi_patch_ops = { |
| 3260 | .build_controls = simple_playback_build_controls, |
| 3261 | .build_pcms = simple_playback_build_pcms, |
| 3262 | .init = simple_playback_init, |
| 3263 | .free = simple_playback_free, |
Takashi Iwai | 250e41a | 2012-06-15 14:40:21 +0200 | [diff] [blame] | 3264 | .unsol_event = simple_hdmi_unsol_event, |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3265 | }; |
| 3266 | |
| 3267 | static int patch_simple_hdmi(struct hda_codec *codec, |
| 3268 | hda_nid_t cvt_nid, hda_nid_t pin_nid) |
| 3269 | { |
| 3270 | struct hdmi_spec *spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3271 | struct hdmi_spec_per_cvt *per_cvt; |
| 3272 | struct hdmi_spec_per_pin *per_pin; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3273 | |
| 3274 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 3275 | if (!spec) |
| 3276 | return -ENOMEM; |
| 3277 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 3278 | spec->codec = codec; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3279 | codec->spec = spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3280 | hdmi_array_init(spec, 1); |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3281 | |
| 3282 | spec->multiout.num_dacs = 0; /* no analog */ |
| 3283 | spec->multiout.max_channels = 2; |
| 3284 | spec->multiout.dig_out_nid = cvt_nid; |
| 3285 | spec->num_cvts = 1; |
| 3286 | spec->num_pins = 1; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3287 | per_pin = snd_array_new(&spec->pins); |
| 3288 | per_cvt = snd_array_new(&spec->cvts); |
| 3289 | if (!per_pin || !per_cvt) { |
| 3290 | simple_playback_free(codec); |
| 3291 | return -ENOMEM; |
| 3292 | } |
| 3293 | per_cvt->cvt_nid = cvt_nid; |
| 3294 | per_pin->pin_nid = pin_nid; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3295 | spec->pcm_playback = simple_pcm_playback; |
| 3296 | |
| 3297 | codec->patch_ops = simple_hdmi_patch_ops; |
| 3298 | |
| 3299 | return 0; |
| 3300 | } |
| 3301 | |
Aaron Plattner | 1f34852 | 2011-04-06 17:19:04 -0700 | [diff] [blame] | 3302 | static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec, |
| 3303 | int channels) |
| 3304 | { |
| 3305 | unsigned int chanmask; |
| 3306 | int chan = channels ? (channels - 1) : 1; |
| 3307 | |
| 3308 | switch (channels) { |
| 3309 | default: |
| 3310 | case 0: |
| 3311 | case 2: |
| 3312 | chanmask = 0x00; |
| 3313 | break; |
| 3314 | case 4: |
| 3315 | chanmask = 0x08; |
| 3316 | break; |
| 3317 | case 6: |
| 3318 | chanmask = 0x0b; |
| 3319 | break; |
| 3320 | case 8: |
| 3321 | chanmask = 0x13; |
| 3322 | break; |
| 3323 | } |
| 3324 | |
| 3325 | /* Set the audio infoframe channel allocation and checksum fields. The |
| 3326 | * channel count is computed implicitly by the hardware. */ |
| 3327 | snd_hda_codec_write(codec, 0x1, 0, |
| 3328 | Nv_VERB_SET_Channel_Allocation, chanmask); |
| 3329 | |
| 3330 | snd_hda_codec_write(codec, 0x1, 0, |
| 3331 | Nv_VERB_SET_Info_Frame_Checksum, |
| 3332 | (0x71 - chan - chanmask)); |
| 3333 | } |
| 3334 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3335 | static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo, |
| 3336 | struct hda_codec *codec, |
| 3337 | struct snd_pcm_substream *substream) |
| 3338 | { |
| 3339 | struct hdmi_spec *spec = codec->spec; |
| 3340 | int i; |
| 3341 | |
| 3342 | snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, |
| 3343 | 0, AC_VERB_SET_CHANNEL_STREAMID, 0); |
| 3344 | for (i = 0; i < 4; i++) { |
| 3345 | /* set the stream id */ |
| 3346 | snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, |
| 3347 | AC_VERB_SET_CHANNEL_STREAMID, 0); |
| 3348 | /* set the stream format */ |
| 3349 | snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, |
| 3350 | AC_VERB_SET_STREAM_FORMAT, 0); |
| 3351 | } |
| 3352 | |
Aaron Plattner | 1f34852 | 2011-04-06 17:19:04 -0700 | [diff] [blame] | 3353 | /* The audio hardware sends a channel count of 0x7 (8ch) when all the |
| 3354 | * streams are disabled. */ |
| 3355 | nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8); |
| 3356 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3357 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 3358 | } |
| 3359 | |
| 3360 | static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 3361 | struct hda_codec *codec, |
| 3362 | unsigned int stream_tag, |
| 3363 | unsigned int format, |
| 3364 | struct snd_pcm_substream *substream) |
| 3365 | { |
| 3366 | int chs; |
Takashi Iwai | 112daa7 | 2011-11-02 21:40:06 +0100 | [diff] [blame] | 3367 | unsigned int dataDCC2, channel_id; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3368 | int i; |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3369 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 3370 | struct hda_spdif_out *spdif; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3371 | struct hdmi_spec_per_cvt *per_cvt; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3372 | |
| 3373 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3374 | per_cvt = get_cvt(spec, 0); |
| 3375 | spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3376 | |
| 3377 | chs = substream->runtime->channels; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3378 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3379 | dataDCC2 = 0x2; |
| 3380 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3381 | /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3382 | if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3383 | snd_hda_codec_write(codec, |
| 3384 | nvhdmi_master_con_nid_7x, |
| 3385 | 0, |
| 3386 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3387 | spdif->ctls & ~AC_DIG1_ENABLE & 0xff); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3388 | |
| 3389 | /* set the stream id */ |
| 3390 | snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, |
| 3391 | AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0); |
| 3392 | |
| 3393 | /* set the stream format */ |
| 3394 | snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, |
| 3395 | AC_VERB_SET_STREAM_FORMAT, format); |
| 3396 | |
| 3397 | /* turn on again (if needed) */ |
| 3398 | /* enable and set the channel status audio/data flag */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3399 | if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3400 | snd_hda_codec_write(codec, |
| 3401 | nvhdmi_master_con_nid_7x, |
| 3402 | 0, |
| 3403 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3404 | spdif->ctls & 0xff); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3405 | snd_hda_codec_write(codec, |
| 3406 | nvhdmi_master_con_nid_7x, |
| 3407 | 0, |
| 3408 | AC_VERB_SET_DIGI_CONVERT_2, dataDCC2); |
| 3409 | } |
| 3410 | |
| 3411 | for (i = 0; i < 4; i++) { |
| 3412 | if (chs == 2) |
| 3413 | channel_id = 0; |
| 3414 | else |
| 3415 | channel_id = i * 2; |
| 3416 | |
| 3417 | /* turn off SPDIF once; |
| 3418 | *otherwise the IEC958 bits won't be updated |
| 3419 | */ |
| 3420 | if (codec->spdif_status_reset && |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3421 | (spdif->ctls & AC_DIG1_ENABLE)) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3422 | snd_hda_codec_write(codec, |
| 3423 | nvhdmi_con_nids_7x[i], |
| 3424 | 0, |
| 3425 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3426 | spdif->ctls & ~AC_DIG1_ENABLE & 0xff); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3427 | /* set the stream id */ |
| 3428 | snd_hda_codec_write(codec, |
| 3429 | nvhdmi_con_nids_7x[i], |
| 3430 | 0, |
| 3431 | AC_VERB_SET_CHANNEL_STREAMID, |
| 3432 | (stream_tag << 4) | channel_id); |
| 3433 | /* set the stream format */ |
| 3434 | snd_hda_codec_write(codec, |
| 3435 | nvhdmi_con_nids_7x[i], |
| 3436 | 0, |
| 3437 | AC_VERB_SET_STREAM_FORMAT, |
| 3438 | format); |
| 3439 | /* turn on again (if needed) */ |
| 3440 | /* enable and set the channel status audio/data flag */ |
| 3441 | if (codec->spdif_status_reset && |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3442 | (spdif->ctls & AC_DIG1_ENABLE)) { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3443 | snd_hda_codec_write(codec, |
| 3444 | nvhdmi_con_nids_7x[i], |
| 3445 | 0, |
| 3446 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 3447 | spdif->ctls & 0xff); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3448 | snd_hda_codec_write(codec, |
| 3449 | nvhdmi_con_nids_7x[i], |
| 3450 | 0, |
| 3451 | AC_VERB_SET_DIGI_CONVERT_2, dataDCC2); |
| 3452 | } |
| 3453 | } |
| 3454 | |
Aaron Plattner | 1f34852 | 2011-04-06 17:19:04 -0700 | [diff] [blame] | 3455 | nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3456 | |
| 3457 | mutex_unlock(&codec->spdif_mutex); |
| 3458 | return 0; |
| 3459 | } |
| 3460 | |
Takashi Iwai | fb79e1e | 2011-05-02 12:17:41 +0200 | [diff] [blame] | 3461 | static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3462 | .substreams = 1, |
| 3463 | .channels_min = 2, |
| 3464 | .channels_max = 8, |
| 3465 | .nid = nvhdmi_master_con_nid_7x, |
| 3466 | .rates = SUPPORTED_RATES, |
| 3467 | .maxbps = SUPPORTED_MAXBPS, |
| 3468 | .formats = SUPPORTED_FORMATS, |
| 3469 | .ops = { |
| 3470 | .open = simple_playback_pcm_open, |
| 3471 | .close = nvhdmi_8ch_7x_pcm_close, |
| 3472 | .prepare = nvhdmi_8ch_7x_pcm_prepare |
| 3473 | }, |
| 3474 | }; |
| 3475 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3476 | static int patch_nvhdmi_2ch(struct hda_codec *codec) |
| 3477 | { |
| 3478 | struct hdmi_spec *spec; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3479 | int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x, |
| 3480 | nvhdmi_master_pin_nid_7x); |
| 3481 | if (err < 0) |
| 3482 | return err; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3483 | |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 3484 | codec->patch_ops.init = nvhdmi_7x_init_2ch; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3485 | /* override the PCM rates, etc, as the codec doesn't give full list */ |
| 3486 | spec = codec->spec; |
| 3487 | spec->pcm_playback.rates = SUPPORTED_RATES; |
| 3488 | spec->pcm_playback.maxbps = SUPPORTED_MAXBPS; |
| 3489 | spec->pcm_playback.formats = SUPPORTED_FORMATS; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3490 | return 0; |
| 3491 | } |
| 3492 | |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 3493 | static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec) |
| 3494 | { |
| 3495 | struct hdmi_spec *spec = codec->spec; |
| 3496 | int err = simple_playback_build_pcms(codec); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3497 | if (!err) { |
| 3498 | struct hda_pcm *info = get_pcm_rec(spec, 0); |
| 3499 | info->own_chmap = true; |
| 3500 | } |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 3501 | return err; |
| 3502 | } |
| 3503 | |
| 3504 | static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec) |
| 3505 | { |
| 3506 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3507 | struct hda_pcm *info; |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 3508 | struct snd_pcm_chmap *chmap; |
| 3509 | int err; |
| 3510 | |
| 3511 | err = simple_playback_build_controls(codec); |
| 3512 | if (err < 0) |
| 3513 | return err; |
| 3514 | |
| 3515 | /* add channel maps */ |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 3516 | info = get_pcm_rec(spec, 0); |
| 3517 | err = snd_pcm_add_chmap_ctls(info->pcm, |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 3518 | SNDRV_PCM_STREAM_PLAYBACK, |
| 3519 | snd_pcm_alt_chmaps, 8, 0, &chmap); |
| 3520 | if (err < 0) |
| 3521 | return err; |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 3522 | switch (codec->preset->vendor_id) { |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 3523 | case 0x10de0002: |
| 3524 | case 0x10de0003: |
| 3525 | case 0x10de0005: |
| 3526 | case 0x10de0006: |
| 3527 | chmap->channel_mask = (1U << 2) | (1U << 8); |
| 3528 | break; |
| 3529 | case 0x10de0007: |
| 3530 | chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8); |
| 3531 | } |
| 3532 | return 0; |
| 3533 | } |
| 3534 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3535 | static int patch_nvhdmi_8ch_7x(struct hda_codec *codec) |
| 3536 | { |
| 3537 | struct hdmi_spec *spec; |
| 3538 | int err = patch_nvhdmi_2ch(codec); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3539 | if (err < 0) |
| 3540 | return err; |
| 3541 | spec = codec->spec; |
| 3542 | spec->multiout.max_channels = 8; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 3543 | spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x; |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 3544 | codec->patch_ops.init = nvhdmi_7x_init_8ch; |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 3545 | codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms; |
| 3546 | codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls; |
Aaron Plattner | 1f34852 | 2011-04-06 17:19:04 -0700 | [diff] [blame] | 3547 | |
| 3548 | /* Initialize the audio infoframe channel mask and checksum to something |
| 3549 | * valid */ |
| 3550 | nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8); |
| 3551 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3552 | return 0; |
| 3553 | } |
| 3554 | |
| 3555 | /* |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3556 | * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on: |
| 3557 | * - 0x10de0015 |
| 3558 | * - 0x10de0040 |
| 3559 | */ |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 3560 | static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap, |
Subhransu S. Prusty | f302240 | 2016-03-04 19:59:48 +0530 | [diff] [blame] | 3561 | struct hdac_cea_channel_speaker_allocation *cap, int channels) |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3562 | { |
| 3563 | if (cap->ca_index == 0x00 && channels == 2) |
| 3564 | return SNDRV_CTL_TLVT_CHMAP_FIXED; |
| 3565 | |
Subhransu S. Prusty | 028cb68 | 2016-03-14 10:35:06 +0530 | [diff] [blame] | 3566 | /* If the speaker allocation matches the channel count, it is OK. */ |
| 3567 | if (cap->channels != channels) |
| 3568 | return -1; |
| 3569 | |
| 3570 | /* all channels are remappable freely */ |
| 3571 | return SNDRV_CTL_TLVT_CHMAP_VAR; |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3572 | } |
| 3573 | |
Subhransu S. Prusty | 828cb4e | 2016-03-04 19:59:50 +0530 | [diff] [blame] | 3574 | static int nvhdmi_chmap_validate(struct hdac_chmap *chmap, |
| 3575 | int ca, int chs, unsigned char *map) |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3576 | { |
| 3577 | if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR)) |
| 3578 | return -EINVAL; |
| 3579 | |
| 3580 | return 0; |
| 3581 | } |
| 3582 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 3583 | /* map from pin NID to port; port is 0-based */ |
| 3584 | /* for Nvidia: assume widget NID starting from 4, with step 1 (4, 5, 6, ...) */ |
| 3585 | static int nvhdmi_pin2port(void *audio_ptr, int pin_nid) |
| 3586 | { |
| 3587 | return pin_nid - 4; |
| 3588 | } |
| 3589 | |
| 3590 | /* reverse-map from port to pin NID: see above */ |
| 3591 | static int nvhdmi_port2pin(struct hda_codec *codec, int port) |
| 3592 | { |
| 3593 | return port + 4; |
| 3594 | } |
| 3595 | |
| 3596 | static const struct drm_audio_component_audio_ops nvhdmi_audio_ops = { |
| 3597 | .pin2port = nvhdmi_pin2port, |
| 3598 | .pin_eld_notify = generic_acomp_pin_eld_notify, |
| 3599 | .master_bind = generic_acomp_master_bind, |
| 3600 | .master_unbind = generic_acomp_master_unbind, |
| 3601 | }; |
| 3602 | |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3603 | static int patch_nvhdmi(struct hda_codec *codec) |
| 3604 | { |
| 3605 | struct hdmi_spec *spec; |
| 3606 | int err; |
| 3607 | |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 3608 | err = alloc_generic_hdmi(codec); |
| 3609 | if (err < 0) |
| 3610 | return err; |
| 3611 | codec->dp_mst = true; |
| 3612 | |
| 3613 | spec = codec->spec; |
| 3614 | spec->dyn_pcm_assign = true; |
| 3615 | |
| 3616 | err = hdmi_parse_codec(codec); |
| 3617 | if (err < 0) { |
| 3618 | generic_spec_free(codec); |
| 3619 | return err; |
| 3620 | } |
| 3621 | |
| 3622 | generic_hdmi_init_per_pins(codec); |
| 3623 | |
| 3624 | spec->dyn_pin_out = true; |
| 3625 | |
| 3626 | spec->chmap.ops.chmap_cea_alloc_validate_get_type = |
| 3627 | nvhdmi_chmap_cea_alloc_validate_get_type; |
| 3628 | spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate; |
| 3629 | |
| 3630 | codec->link_down_at_suspend = 1; |
| 3631 | |
| 3632 | generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin); |
| 3633 | |
| 3634 | return 0; |
| 3635 | } |
| 3636 | |
| 3637 | static int patch_nvhdmi_legacy(struct hda_codec *codec) |
| 3638 | { |
| 3639 | struct hdmi_spec *spec; |
| 3640 | int err; |
| 3641 | |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3642 | err = patch_generic_hdmi(codec); |
| 3643 | if (err) |
| 3644 | return err; |
| 3645 | |
| 3646 | spec = codec->spec; |
Stephen Warren | 75fae11 | 2014-01-30 11:52:16 -0700 | [diff] [blame] | 3647 | spec->dyn_pin_out = true; |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3648 | |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 3649 | spec->chmap.ops.chmap_cea_alloc_validate_get_type = |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3650 | nvhdmi_chmap_cea_alloc_validate_get_type; |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 3651 | spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate; |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3652 | |
Lukas Wunner | 94989e3 | 2019-10-17 17:04:11 +0200 | [diff] [blame] | 3653 | codec->link_down_at_suspend = 1; |
| 3654 | |
Anssi Hannula | 611885b | 2013-11-03 17:15:00 +0200 | [diff] [blame] | 3655 | return 0; |
| 3656 | } |
| 3657 | |
| 3658 | /* |
Thierry Reding | 26e9a96 | 2015-05-05 14:56:20 +0200 | [diff] [blame] | 3659 | * The HDA codec on NVIDIA Tegra contains two scratch registers that are |
| 3660 | * accessed using vendor-defined verbs. These registers can be used for |
| 3661 | * interoperability between the HDA and HDMI drivers. |
| 3662 | */ |
| 3663 | |
| 3664 | /* Audio Function Group node */ |
| 3665 | #define NVIDIA_AFG_NID 0x01 |
| 3666 | |
| 3667 | /* |
| 3668 | * The SCRATCH0 register is used to notify the HDMI codec of changes in audio |
| 3669 | * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to |
| 3670 | * be raised in the HDMI codec. The remainder of the bits is arbitrary. This |
| 3671 | * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an |
| 3672 | * additional bit (at position 30) to signal the validity of the format. |
| 3673 | * |
| 3674 | * | 31 | 30 | 29 16 | 15 0 | |
| 3675 | * +---------+-------+--------+--------+ |
| 3676 | * | TRIGGER | VALID | UNUSED | FORMAT | |
| 3677 | * +-----------------------------------| |
| 3678 | * |
| 3679 | * Note that for the trigger bit to take effect it needs to change value |
| 3680 | * (i.e. it needs to be toggled). |
| 3681 | */ |
| 3682 | #define NVIDIA_GET_SCRATCH0 0xfa6 |
| 3683 | #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7 |
| 3684 | #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8 |
| 3685 | #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9 |
| 3686 | #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa |
| 3687 | #define NVIDIA_SCRATCH_TRIGGER (1 << 7) |
| 3688 | #define NVIDIA_SCRATCH_VALID (1 << 6) |
| 3689 | |
| 3690 | #define NVIDIA_GET_SCRATCH1 0xfab |
| 3691 | #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac |
| 3692 | #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad |
| 3693 | #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae |
| 3694 | #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf |
| 3695 | |
| 3696 | /* |
| 3697 | * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0, |
| 3698 | * the format is invalidated so that the HDMI codec can be disabled. |
| 3699 | */ |
| 3700 | static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format) |
| 3701 | { |
| 3702 | unsigned int value; |
| 3703 | |
| 3704 | /* bits [31:30] contain the trigger and valid bits */ |
| 3705 | value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0, |
| 3706 | NVIDIA_GET_SCRATCH0, 0); |
| 3707 | value = (value >> 24) & 0xff; |
| 3708 | |
| 3709 | /* bits [15:0] are used to store the HDA format */ |
| 3710 | snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, |
| 3711 | NVIDIA_SET_SCRATCH0_BYTE0, |
| 3712 | (format >> 0) & 0xff); |
| 3713 | snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, |
| 3714 | NVIDIA_SET_SCRATCH0_BYTE1, |
| 3715 | (format >> 8) & 0xff); |
| 3716 | |
| 3717 | /* bits [16:24] are unused */ |
| 3718 | snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, |
| 3719 | NVIDIA_SET_SCRATCH0_BYTE2, 0); |
| 3720 | |
| 3721 | /* |
| 3722 | * Bit 30 signals that the data is valid and hence that HDMI audio can |
| 3723 | * be enabled. |
| 3724 | */ |
| 3725 | if (format == 0) |
| 3726 | value &= ~NVIDIA_SCRATCH_VALID; |
| 3727 | else |
| 3728 | value |= NVIDIA_SCRATCH_VALID; |
| 3729 | |
| 3730 | /* |
| 3731 | * Whenever the trigger bit is toggled, an interrupt is raised in the |
| 3732 | * HDMI codec. The HDMI driver will use that as trigger to update its |
| 3733 | * configuration. |
| 3734 | */ |
| 3735 | value ^= NVIDIA_SCRATCH_TRIGGER; |
| 3736 | |
| 3737 | snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, |
| 3738 | NVIDIA_SET_SCRATCH0_BYTE3, value); |
| 3739 | } |
| 3740 | |
| 3741 | static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 3742 | struct hda_codec *codec, |
| 3743 | unsigned int stream_tag, |
| 3744 | unsigned int format, |
| 3745 | struct snd_pcm_substream *substream) |
| 3746 | { |
| 3747 | int err; |
| 3748 | |
| 3749 | err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag, |
| 3750 | format, substream); |
| 3751 | if (err < 0) |
| 3752 | return err; |
| 3753 | |
| 3754 | /* notify the HDMI codec of the format change */ |
| 3755 | tegra_hdmi_set_format(codec, format); |
| 3756 | |
| 3757 | return 0; |
| 3758 | } |
| 3759 | |
| 3760 | static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 3761 | struct hda_codec *codec, |
| 3762 | struct snd_pcm_substream *substream) |
| 3763 | { |
| 3764 | /* invalidate the format in the HDMI codec */ |
| 3765 | tegra_hdmi_set_format(codec, 0); |
| 3766 | |
| 3767 | return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream); |
| 3768 | } |
| 3769 | |
| 3770 | static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type) |
| 3771 | { |
| 3772 | struct hdmi_spec *spec = codec->spec; |
| 3773 | unsigned int i; |
| 3774 | |
| 3775 | for (i = 0; i < spec->num_pins; i++) { |
| 3776 | struct hda_pcm *pcm = get_pcm_rec(spec, i); |
| 3777 | |
| 3778 | if (pcm->pcm_type == type) |
| 3779 | return pcm; |
| 3780 | } |
| 3781 | |
| 3782 | return NULL; |
| 3783 | } |
| 3784 | |
| 3785 | static int tegra_hdmi_build_pcms(struct hda_codec *codec) |
| 3786 | { |
| 3787 | struct hda_pcm_stream *stream; |
| 3788 | struct hda_pcm *pcm; |
| 3789 | int err; |
| 3790 | |
| 3791 | err = generic_hdmi_build_pcms(codec); |
| 3792 | if (err < 0) |
| 3793 | return err; |
| 3794 | |
| 3795 | pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI); |
| 3796 | if (!pcm) |
| 3797 | return -ENODEV; |
| 3798 | |
| 3799 | /* |
| 3800 | * Override ->prepare() and ->cleanup() operations to notify the HDMI |
| 3801 | * codec about format changes. |
| 3802 | */ |
| 3803 | stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK]; |
| 3804 | stream->ops.prepare = tegra_hdmi_pcm_prepare; |
| 3805 | stream->ops.cleanup = tegra_hdmi_pcm_cleanup; |
| 3806 | |
| 3807 | return 0; |
| 3808 | } |
| 3809 | |
| 3810 | static int patch_tegra_hdmi(struct hda_codec *codec) |
| 3811 | { |
Mohan Kumar | 216116e | 2020-08-25 10:54:14 +0530 | [diff] [blame] | 3812 | struct hdmi_spec *spec; |
Thierry Reding | 26e9a96 | 2015-05-05 14:56:20 +0200 | [diff] [blame] | 3813 | int err; |
| 3814 | |
| 3815 | err = patch_generic_hdmi(codec); |
| 3816 | if (err) |
| 3817 | return err; |
| 3818 | |
| 3819 | codec->patch_ops.build_pcms = tegra_hdmi_build_pcms; |
Mohan Kumar | 216116e | 2020-08-25 10:54:14 +0530 | [diff] [blame] | 3820 | spec = codec->spec; |
| 3821 | spec->chmap.ops.chmap_cea_alloc_validate_get_type = |
| 3822 | nvhdmi_chmap_cea_alloc_validate_get_type; |
| 3823 | spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate; |
Thierry Reding | 26e9a96 | 2015-05-05 14:56:20 +0200 | [diff] [blame] | 3824 | |
| 3825 | return 0; |
| 3826 | } |
| 3827 | |
| 3828 | /* |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3829 | * ATI/AMD-specific implementations |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3830 | */ |
| 3831 | |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3832 | #define is_amdhdmi_rev3_or_later(codec) \ |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 3833 | ((codec)->core.vendor_id == 0x1002aa01 && \ |
| 3834 | ((codec)->core.revision_id & 0xff00) >= 0x0300) |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3835 | #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 3836 | |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3837 | /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */ |
| 3838 | #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771 |
| 3839 | #define ATI_VERB_SET_DOWNMIX_INFO 0x772 |
| 3840 | #define ATI_VERB_SET_MULTICHANNEL_01 0x777 |
| 3841 | #define ATI_VERB_SET_MULTICHANNEL_23 0x778 |
| 3842 | #define ATI_VERB_SET_MULTICHANNEL_45 0x779 |
| 3843 | #define ATI_VERB_SET_MULTICHANNEL_67 0x77a |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 3844 | #define ATI_VERB_SET_HBR_CONTROL 0x77c |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3845 | #define ATI_VERB_SET_MULTICHANNEL_1 0x785 |
| 3846 | #define ATI_VERB_SET_MULTICHANNEL_3 0x786 |
| 3847 | #define ATI_VERB_SET_MULTICHANNEL_5 0x787 |
| 3848 | #define ATI_VERB_SET_MULTICHANNEL_7 0x788 |
| 3849 | #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789 |
| 3850 | #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71 |
| 3851 | #define ATI_VERB_GET_DOWNMIX_INFO 0xf72 |
| 3852 | #define ATI_VERB_GET_MULTICHANNEL_01 0xf77 |
| 3853 | #define ATI_VERB_GET_MULTICHANNEL_23 0xf78 |
| 3854 | #define ATI_VERB_GET_MULTICHANNEL_45 0xf79 |
| 3855 | #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 3856 | #define ATI_VERB_GET_HBR_CONTROL 0xf7c |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3857 | #define ATI_VERB_GET_MULTICHANNEL_1 0xf85 |
| 3858 | #define ATI_VERB_GET_MULTICHANNEL_3 0xf86 |
| 3859 | #define ATI_VERB_GET_MULTICHANNEL_5 0xf87 |
| 3860 | #define ATI_VERB_GET_MULTICHANNEL_7 0xf88 |
| 3861 | #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89 |
| 3862 | |
Anssi Hannula | 84d69e7 | 2013-10-24 21:10:38 +0300 | [diff] [blame] | 3863 | /* AMD specific HDA cvt verbs */ |
| 3864 | #define ATI_VERB_SET_RAMP_RATE 0x770 |
| 3865 | #define ATI_VERB_GET_RAMP_RATE 0xf70 |
| 3866 | |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3867 | #define ATI_OUT_ENABLE 0x1 |
| 3868 | |
| 3869 | #define ATI_MULTICHANNEL_MODE_PAIRED 0 |
| 3870 | #define ATI_MULTICHANNEL_MODE_SINGLE 1 |
| 3871 | |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 3872 | #define ATI_HBR_CAPABLE 0x01 |
| 3873 | #define ATI_HBR_ENABLE 0x10 |
| 3874 | |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 3875 | static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 3876 | int dev_id, unsigned char *buf, int *eld_size) |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 3877 | { |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 3878 | WARN_ON(dev_id != 0); |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 3879 | /* call hda_eld.c ATI/AMD-specific function */ |
| 3880 | return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size, |
| 3881 | is_amdhdmi_rev3_or_later(codec)); |
| 3882 | } |
| 3883 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 3884 | static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, |
| 3885 | hda_nid_t pin_nid, int dev_id, int ca, |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3886 | int active_channels, int conn_type) |
| 3887 | { |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 3888 | WARN_ON(dev_id != 0); |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3889 | snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca); |
| 3890 | } |
| 3891 | |
| 3892 | static int atihdmi_paired_swap_fc_lfe(int pos) |
| 3893 | { |
| 3894 | /* |
| 3895 | * ATI/AMD have automatic FC/LFE swap built-in |
| 3896 | * when in pairwise mapping mode. |
| 3897 | */ |
| 3898 | |
| 3899 | switch (pos) { |
| 3900 | /* see channel_allocations[].speakers[] */ |
| 3901 | case 2: return 3; |
| 3902 | case 3: return 2; |
| 3903 | default: break; |
| 3904 | } |
| 3905 | |
| 3906 | return pos; |
| 3907 | } |
| 3908 | |
Subhransu S. Prusty | 828cb4e | 2016-03-04 19:59:50 +0530 | [diff] [blame] | 3909 | static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap, |
| 3910 | int ca, int chs, unsigned char *map) |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3911 | { |
Subhransu S. Prusty | f302240 | 2016-03-04 19:59:48 +0530 | [diff] [blame] | 3912 | struct hdac_cea_channel_speaker_allocation *cap; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3913 | int i, j; |
| 3914 | |
| 3915 | /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */ |
| 3916 | |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 3917 | cap = snd_hdac_get_ch_alloc_from_ca(ca); |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3918 | for (i = 0; i < chs; ++i) { |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 3919 | int mask = snd_hdac_chmap_to_spk_mask(map[i]); |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3920 | bool ok = false; |
| 3921 | bool companion_ok = false; |
| 3922 | |
| 3923 | if (!mask) |
| 3924 | continue; |
| 3925 | |
| 3926 | for (j = 0 + i % 2; j < 8; j += 2) { |
| 3927 | int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j); |
| 3928 | if (cap->speakers[chan_idx] == mask) { |
| 3929 | /* channel is in a supported position */ |
| 3930 | ok = true; |
| 3931 | |
| 3932 | if (i % 2 == 0 && i + 1 < chs) { |
| 3933 | /* even channel, check the odd companion */ |
| 3934 | int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1); |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 3935 | int comp_mask_req = snd_hdac_chmap_to_spk_mask(map[i+1]); |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3936 | int comp_mask_act = cap->speakers[comp_chan_idx]; |
| 3937 | |
| 3938 | if (comp_mask_req == comp_mask_act) |
| 3939 | companion_ok = true; |
| 3940 | else |
| 3941 | return -EINVAL; |
| 3942 | } |
| 3943 | break; |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | if (!ok) |
| 3948 | return -EINVAL; |
| 3949 | |
| 3950 | if (companion_ok) |
| 3951 | i++; /* companion channel already checked */ |
| 3952 | } |
| 3953 | |
| 3954 | return 0; |
| 3955 | } |
| 3956 | |
Subhransu S. Prusty | 739ffee | 2016-03-04 19:59:49 +0530 | [diff] [blame] | 3957 | static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac, |
| 3958 | hda_nid_t pin_nid, int hdmi_slot, int stream_channel) |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3959 | { |
Kai-Heng Feng | 8c11827 | 2020-05-05 11:03:53 +0800 | [diff] [blame] | 3960 | struct hda_codec *codec = hdac_to_hda_codec(hdac); |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3961 | int verb; |
| 3962 | int ati_channel_setup = 0; |
| 3963 | |
| 3964 | if (hdmi_slot > 7) |
| 3965 | return -EINVAL; |
| 3966 | |
| 3967 | if (!has_amd_full_remap_support(codec)) { |
| 3968 | hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot); |
| 3969 | |
| 3970 | /* In case this is an odd slot but without stream channel, do not |
| 3971 | * disable the slot since the corresponding even slot could have a |
| 3972 | * channel. In case neither have a channel, the slot pair will be |
| 3973 | * disabled when this function is called for the even slot. */ |
| 3974 | if (hdmi_slot % 2 != 0 && stream_channel == 0xf) |
| 3975 | return 0; |
| 3976 | |
| 3977 | hdmi_slot -= hdmi_slot % 2; |
| 3978 | |
| 3979 | if (stream_channel != 0xf) |
| 3980 | stream_channel -= stream_channel % 2; |
| 3981 | } |
| 3982 | |
| 3983 | verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e; |
| 3984 | |
| 3985 | /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */ |
| 3986 | |
| 3987 | if (stream_channel != 0xf) |
| 3988 | ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE; |
| 3989 | |
| 3990 | return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup); |
| 3991 | } |
| 3992 | |
Subhransu S. Prusty | 739ffee | 2016-03-04 19:59:49 +0530 | [diff] [blame] | 3993 | static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac, |
| 3994 | hda_nid_t pin_nid, int asp_slot) |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3995 | { |
Kai-Heng Feng | 8c11827 | 2020-05-05 11:03:53 +0800 | [diff] [blame] | 3996 | struct hda_codec *codec = hdac_to_hda_codec(hdac); |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 3997 | bool was_odd = false; |
| 3998 | int ati_asp_slot = asp_slot; |
| 3999 | int verb; |
| 4000 | int ati_channel_setup; |
| 4001 | |
| 4002 | if (asp_slot > 7) |
| 4003 | return -EINVAL; |
| 4004 | |
| 4005 | if (!has_amd_full_remap_support(codec)) { |
| 4006 | ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot); |
| 4007 | if (ati_asp_slot % 2 != 0) { |
| 4008 | ati_asp_slot -= 1; |
| 4009 | was_odd = true; |
| 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e; |
| 4014 | |
| 4015 | ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0); |
| 4016 | |
| 4017 | if (!(ati_channel_setup & ATI_OUT_ENABLE)) |
| 4018 | return 0xf; |
| 4019 | |
| 4020 | return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd; |
| 4021 | } |
| 4022 | |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 4023 | static int atihdmi_paired_chmap_cea_alloc_validate_get_type( |
| 4024 | struct hdac_chmap *chmap, |
Subhransu S. Prusty | f302240 | 2016-03-04 19:59:48 +0530 | [diff] [blame] | 4025 | struct hdac_cea_channel_speaker_allocation *cap, |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 4026 | int channels) |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4027 | { |
| 4028 | int c; |
| 4029 | |
| 4030 | /* |
| 4031 | * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so |
| 4032 | * we need to take that into account (a single channel may take 2 |
| 4033 | * channel slots if we need to carry a silent channel next to it). |
| 4034 | * On Rev3+ AMD codecs this function is not used. |
| 4035 | */ |
| 4036 | int chanpairs = 0; |
| 4037 | |
| 4038 | /* We only produce even-numbered channel count TLVs */ |
| 4039 | if ((channels % 2) != 0) |
| 4040 | return -1; |
| 4041 | |
| 4042 | for (c = 0; c < 7; c += 2) { |
| 4043 | if (cap->speakers[c] || cap->speakers[c+1]) |
| 4044 | chanpairs++; |
| 4045 | } |
| 4046 | |
| 4047 | if (chanpairs * 2 != channels) |
| 4048 | return -1; |
| 4049 | |
| 4050 | return SNDRV_CTL_TLVT_CHMAP_PAIRED; |
| 4051 | } |
| 4052 | |
Subhransu S. Prusty | 828cb4e | 2016-03-04 19:59:50 +0530 | [diff] [blame] | 4053 | static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap, |
Subhransu S. Prusty | f302240 | 2016-03-04 19:59:48 +0530 | [diff] [blame] | 4054 | struct hdac_cea_channel_speaker_allocation *cap, |
| 4055 | unsigned int *chmap, int channels) |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4056 | { |
| 4057 | /* produce paired maps for pre-rev3 ATI/AMD codecs */ |
| 4058 | int count = 0; |
| 4059 | int c; |
| 4060 | |
| 4061 | for (c = 7; c >= 0; c--) { |
| 4062 | int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c); |
| 4063 | int spk = cap->speakers[chan]; |
| 4064 | if (!spk) { |
| 4065 | /* add N/A channel if the companion channel is occupied */ |
| 4066 | if (cap->speakers[chan + (chan % 2 ? -1 : 1)]) |
| 4067 | chmap[count++] = SNDRV_CHMAP_NA; |
| 4068 | |
| 4069 | continue; |
| 4070 | } |
| 4071 | |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 4072 | chmap[count++] = snd_hdac_spk_to_chmap(spk); |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | WARN_ON(count != channels); |
| 4076 | } |
| 4077 | |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 4078 | static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 4079 | int dev_id, bool hbr) |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 4080 | { |
| 4081 | int hbr_ctl, hbr_ctl_new; |
| 4082 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 4083 | WARN_ON(dev_id != 0); |
| 4084 | |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 4085 | hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0); |
Anssi Hannula | 13122e6 | 2013-11-10 20:56:10 +0200 | [diff] [blame] | 4086 | if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) { |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 4087 | if (hbr) |
| 4088 | hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE; |
| 4089 | else |
| 4090 | hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE; |
| 4091 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 4092 | codec_dbg(codec, |
| 4093 | "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n", |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 4094 | pin_nid, |
| 4095 | hbr_ctl == hbr_ctl_new ? "" : "new-", |
| 4096 | hbr_ctl_new); |
| 4097 | |
| 4098 | if (hbr_ctl != hbr_ctl_new) |
| 4099 | snd_hda_codec_write(codec, pin_nid, 0, |
| 4100 | ATI_VERB_SET_HBR_CONTROL, |
| 4101 | hbr_ctl_new); |
| 4102 | |
| 4103 | } else if (hbr) |
| 4104 | return -EINVAL; |
| 4105 | |
| 4106 | return 0; |
| 4107 | } |
| 4108 | |
Anssi Hannula | 84d69e7 | 2013-10-24 21:10:38 +0300 | [diff] [blame] | 4109 | static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 4110 | hda_nid_t pin_nid, int dev_id, |
| 4111 | u32 stream_tag, int format) |
Anssi Hannula | 84d69e7 | 2013-10-24 21:10:38 +0300 | [diff] [blame] | 4112 | { |
Anssi Hannula | 84d69e7 | 2013-10-24 21:10:38 +0300 | [diff] [blame] | 4113 | if (is_amdhdmi_rev3_or_later(codec)) { |
| 4114 | int ramp_rate = 180; /* default as per AMD spec */ |
| 4115 | /* disable ramp-up/down for non-pcm as per AMD spec */ |
| 4116 | if (format & AC_FMT_TYPE_NON_PCM) |
| 4117 | ramp_rate = 0; |
| 4118 | |
| 4119 | snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate); |
| 4120 | } |
| 4121 | |
Nikhil Mahale | 9c32fea | 2019-11-19 14:17:09 +0530 | [diff] [blame] | 4122 | return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id, |
| 4123 | stream_tag, format); |
Anssi Hannula | 84d69e7 | 2013-10-24 21:10:38 +0300 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4127 | static int atihdmi_init(struct hda_codec *codec) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4128 | { |
| 4129 | struct hdmi_spec *spec = codec->spec; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4130 | int pin_idx, err; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4131 | |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4132 | err = generic_hdmi_init(codec); |
| 4133 | |
| 4134 | if (err) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4135 | return err; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4136 | |
| 4137 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
| 4138 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
| 4139 | |
| 4140 | /* make sure downmix information in infoframe is zero */ |
| 4141 | snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0); |
| 4142 | |
| 4143 | /* enable channel-wise remap mode if supported */ |
| 4144 | if (has_amd_full_remap_support(codec)) |
| 4145 | snd_hda_codec_write(codec, per_pin->pin_nid, 0, |
| 4146 | ATI_VERB_SET_MULTICHANNEL_MODE, |
| 4147 | ATI_MULTICHANNEL_MODE_SINGLE); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4148 | } |
Alex Deucher | 8218df9 | 2019-11-22 16:43:53 -0500 | [diff] [blame] | 4149 | codec->auto_runtime_pm = 1; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4150 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4151 | return 0; |
| 4152 | } |
| 4153 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 4154 | /* map from pin NID to port; port is 0-based */ |
| 4155 | /* for AMD: assume widget NID starting from 3, with step 2 (3, 5, 7, ...) */ |
| 4156 | static int atihdmi_pin2port(void *audio_ptr, int pin_nid) |
| 4157 | { |
| 4158 | return pin_nid / 2 - 1; |
| 4159 | } |
| 4160 | |
| 4161 | /* reverse-map from port to pin NID: see above */ |
| 4162 | static int atihdmi_port2pin(struct hda_codec *codec, int port) |
| 4163 | { |
| 4164 | return port * 2 + 3; |
| 4165 | } |
| 4166 | |
| 4167 | static const struct drm_audio_component_audio_ops atihdmi_audio_ops = { |
| 4168 | .pin2port = atihdmi_pin2port, |
| 4169 | .pin_eld_notify = generic_acomp_pin_eld_notify, |
| 4170 | .master_bind = generic_acomp_master_bind, |
| 4171 | .master_unbind = generic_acomp_master_unbind, |
| 4172 | }; |
| 4173 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4174 | static int patch_atihdmi(struct hda_codec *codec) |
| 4175 | { |
| 4176 | struct hdmi_spec *spec; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4177 | struct hdmi_spec_per_cvt *per_cvt; |
| 4178 | int err, cvt_idx; |
| 4179 | |
| 4180 | err = patch_generic_hdmi(codec); |
| 4181 | |
| 4182 | if (err) |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 4183 | return err; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4184 | |
| 4185 | codec->patch_ops.init = atihdmi_init; |
| 4186 | |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 4187 | spec = codec->spec; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4188 | |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 4189 | spec->ops.pin_get_eld = atihdmi_pin_get_eld; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4190 | spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe; |
Anssi Hannula | 461cf6b | 2013-10-24 21:10:37 +0300 | [diff] [blame] | 4191 | spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup; |
Anssi Hannula | 84d69e7 | 2013-10-24 21:10:38 +0300 | [diff] [blame] | 4192 | spec->ops.setup_stream = atihdmi_setup_stream; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4193 | |
Takashi Iwai | 3966922 | 2016-05-11 14:56:12 +0200 | [diff] [blame] | 4194 | spec->chmap.ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel; |
| 4195 | spec->chmap.ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel; |
| 4196 | |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4197 | if (!has_amd_full_remap_support(codec)) { |
| 4198 | /* override to ATI/AMD-specific versions with pairwise mapping */ |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 4199 | spec->chmap.ops.chmap_cea_alloc_validate_get_type = |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4200 | atihdmi_paired_chmap_cea_alloc_validate_get_type; |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 4201 | spec->chmap.ops.cea_alloc_to_tlv_chmap = |
| 4202 | atihdmi_paired_cea_alloc_to_tlv_chmap; |
| 4203 | spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate; |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4204 | } |
| 4205 | |
| 4206 | /* ATI/AMD converters do not advertise all of their capabilities */ |
| 4207 | for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { |
| 4208 | per_cvt = get_cvt(spec, cvt_idx); |
| 4209 | per_cvt->channels_max = max(per_cvt->channels_max, 8u); |
| 4210 | per_cvt->rates |= SUPPORTED_RATES; |
| 4211 | per_cvt->formats |= SUPPORTED_FORMATS; |
| 4212 | per_cvt->maxbps = max(per_cvt->maxbps, 24u); |
| 4213 | } |
| 4214 | |
Subhransu S. Prusty | 67b90cb | 2016-03-04 19:59:46 +0530 | [diff] [blame] | 4215 | spec->chmap.channels_max = max(spec->chmap.channels_max, 8u); |
Anssi Hannula | 5a613584 | 2013-10-24 21:10:35 +0300 | [diff] [blame] | 4216 | |
Takashi Iwai | 57cb54e | 2018-06-21 13:33:53 +0200 | [diff] [blame] | 4217 | /* AMD GPUs have neither EPSS nor CLKSTOP bits, hence preventing |
| 4218 | * the link-down as is. Tell the core to allow it. |
| 4219 | */ |
| 4220 | codec->link_down_at_suspend = 1; |
| 4221 | |
Takashi Iwai | ade49db | 2018-07-11 18:05:52 +0200 | [diff] [blame] | 4222 | generic_acomp_init(codec, &atihdmi_audio_ops, atihdmi_port2pin); |
| 4223 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4224 | return 0; |
| 4225 | } |
| 4226 | |
Annie Liu | 3de5ff8 | 2012-06-08 19:18:42 +0800 | [diff] [blame] | 4227 | /* VIA HDMI Implementation */ |
| 4228 | #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */ |
| 4229 | #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */ |
| 4230 | |
Annie Liu | 3de5ff8 | 2012-06-08 19:18:42 +0800 | [diff] [blame] | 4231 | static int patch_via_hdmi(struct hda_codec *codec) |
| 4232 | { |
Takashi Iwai | 250e41a | 2012-06-15 14:40:21 +0200 | [diff] [blame] | 4233 | return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID); |
Annie Liu | 3de5ff8 | 2012-06-08 19:18:42 +0800 | [diff] [blame] | 4234 | } |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4235 | |
| 4236 | /* |
| 4237 | * patch entries |
| 4238 | */ |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4239 | static const struct hda_device_id snd_hda_id_hdmi[] = { |
| 4240 | HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi), |
| 4241 | HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi), |
| 4242 | HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi), |
| 4243 | HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi), |
| 4244 | HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi), |
| 4245 | HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi), |
| 4246 | HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4247 | HDA_CODEC_ENTRY(0x10de0001, "MCP73 HDMI", patch_nvhdmi_2ch), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4248 | HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x), |
| 4249 | HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4250 | HDA_CODEC_ENTRY(0x10de0004, "GPU 04 HDMI", patch_nvhdmi_8ch_7x), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4251 | HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x), |
| 4252 | HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x), |
| 4253 | HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x), |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 4254 | HDA_CODEC_ENTRY(0x10de0008, "GPU 08 HDMI/DP", patch_nvhdmi_legacy), |
| 4255 | HDA_CODEC_ENTRY(0x10de0009, "GPU 09 HDMI/DP", patch_nvhdmi_legacy), |
| 4256 | HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi_legacy), |
| 4257 | HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi_legacy), |
| 4258 | HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi_legacy), |
| 4259 | HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi_legacy), |
| 4260 | HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi_legacy), |
| 4261 | HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi_legacy), |
| 4262 | HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi_legacy), |
| 4263 | HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi_legacy), |
| 4264 | HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi_legacy), |
| 4265 | HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi_legacy), |
| 4266 | HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi_legacy), |
Richard Samson | c8900a0 | 2011-03-03 12:46:13 +0100 | [diff] [blame] | 4267 | /* 17 is known to be absent */ |
Nikhil Mahale | 5398e94 | 2019-11-19 14:17:10 +0530 | [diff] [blame] | 4268 | HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi_legacy), |
| 4269 | HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi_legacy), |
| 4270 | HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi_legacy), |
| 4271 | HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi_legacy), |
| 4272 | HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi_legacy), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4273 | HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi), |
| 4274 | HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi), |
| 4275 | HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi), |
| 4276 | HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi), |
Thierry Reding | 917bb90 | 2018-12-03 16:53:17 +0100 | [diff] [blame] | 4277 | HDA_CODEC_ENTRY(0x10de002d, "Tegra186 HDMI/DP0", patch_tegra_hdmi), |
| 4278 | HDA_CODEC_ENTRY(0x10de002e, "Tegra186 HDMI/DP1", patch_tegra_hdmi), |
| 4279 | HDA_CODEC_ENTRY(0x10de002f, "Tegra194 HDMI/DP2", patch_tegra_hdmi), |
| 4280 | HDA_CODEC_ENTRY(0x10de0030, "Tegra194 HDMI/DP3", patch_tegra_hdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4281 | HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi), |
| 4282 | HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi), |
| 4283 | HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi), |
| 4284 | HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi), |
| 4285 | HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4286 | HDA_CODEC_ENTRY(0x10de0045, "GPU 45 HDMI/DP", patch_nvhdmi), |
| 4287 | HDA_CODEC_ENTRY(0x10de0050, "GPU 50 HDMI/DP", patch_nvhdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4288 | HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4289 | HDA_CODEC_ENTRY(0x10de0052, "GPU 52 HDMI/DP", patch_nvhdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4290 | HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4291 | HDA_CODEC_ENTRY(0x10de0061, "GPU 61 HDMI/DP", patch_nvhdmi), |
| 4292 | HDA_CODEC_ENTRY(0x10de0062, "GPU 62 HDMI/DP", patch_nvhdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4293 | HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch), |
| 4294 | HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi), |
| 4295 | HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi), |
| 4296 | HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4297 | HDA_CODEC_ENTRY(0x10de0073, "GPU 73 HDMI/DP", patch_nvhdmi), |
| 4298 | HDA_CODEC_ENTRY(0x10de0074, "GPU 74 HDMI/DP", patch_nvhdmi), |
| 4299 | HDA_CODEC_ENTRY(0x10de0076, "GPU 76 HDMI/DP", patch_nvhdmi), |
| 4300 | HDA_CODEC_ENTRY(0x10de007b, "GPU 7b HDMI/DP", patch_nvhdmi), |
| 4301 | HDA_CODEC_ENTRY(0x10de007c, "GPU 7c HDMI/DP", patch_nvhdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4302 | HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4303 | HDA_CODEC_ENTRY(0x10de007e, "GPU 7e HDMI/DP", patch_nvhdmi), |
Hui Wang | af67716 | 2017-02-09 09:20:54 +0800 | [diff] [blame] | 4304 | HDA_CODEC_ENTRY(0x10de0080, "GPU 80 HDMI/DP", patch_nvhdmi), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4305 | HDA_CODEC_ENTRY(0x10de0081, "GPU 81 HDMI/DP", patch_nvhdmi), |
Aaron Plattner | 2d369c7 | 2016-03-13 13:58:57 -0700 | [diff] [blame] | 4306 | HDA_CODEC_ENTRY(0x10de0082, "GPU 82 HDMI/DP", patch_nvhdmi), |
Aaron Plattner | 3ec622f | 2016-01-28 14:07:38 -0800 | [diff] [blame] | 4307 | HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4308 | HDA_CODEC_ENTRY(0x10de0084, "GPU 84 HDMI/DP", patch_nvhdmi), |
| 4309 | HDA_CODEC_ENTRY(0x10de0090, "GPU 90 HDMI/DP", patch_nvhdmi), |
| 4310 | HDA_CODEC_ENTRY(0x10de0091, "GPU 91 HDMI/DP", patch_nvhdmi), |
| 4311 | HDA_CODEC_ENTRY(0x10de0092, "GPU 92 HDMI/DP", patch_nvhdmi), |
| 4312 | HDA_CODEC_ENTRY(0x10de0093, "GPU 93 HDMI/DP", patch_nvhdmi), |
| 4313 | HDA_CODEC_ENTRY(0x10de0094, "GPU 94 HDMI/DP", patch_nvhdmi), |
| 4314 | HDA_CODEC_ENTRY(0x10de0095, "GPU 95 HDMI/DP", patch_nvhdmi), |
| 4315 | HDA_CODEC_ENTRY(0x10de0097, "GPU 97 HDMI/DP", patch_nvhdmi), |
| 4316 | HDA_CODEC_ENTRY(0x10de0098, "GPU 98 HDMI/DP", patch_nvhdmi), |
| 4317 | HDA_CODEC_ENTRY(0x10de0099, "GPU 99 HDMI/DP", patch_nvhdmi), |
Aaron Plattner | adb36a82 | 2020-06-11 11:08:45 -0700 | [diff] [blame] | 4318 | HDA_CODEC_ENTRY(0x10de009a, "GPU 9a HDMI/DP", patch_nvhdmi), |
| 4319 | HDA_CODEC_ENTRY(0x10de009d, "GPU 9d HDMI/DP", patch_nvhdmi), |
| 4320 | HDA_CODEC_ENTRY(0x10de009e, "GPU 9e HDMI/DP", patch_nvhdmi), |
| 4321 | HDA_CODEC_ENTRY(0x10de009f, "GPU 9f HDMI/DP", patch_nvhdmi), |
| 4322 | HDA_CODEC_ENTRY(0x10de00a0, "GPU a0 HDMI/DP", patch_nvhdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4323 | HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch), |
Daniel Dadap | 74ec118 | 2017-07-13 19:27:39 -0500 | [diff] [blame] | 4324 | HDA_CODEC_ENTRY(0x10de8067, "MCP67/68 HDMI", patch_nvhdmi_2ch), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4325 | HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi), |
| 4326 | HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi), |
| 4327 | HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi), |
| 4328 | HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi), |
Takashi Iwai | 7ff652f | 2016-03-21 14:50:24 +0100 | [diff] [blame] | 4329 | HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi), |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 4330 | HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4331 | HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi), |
| 4332 | HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi), |
| 4333 | HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi), |
Takashi Iwai | 7ff652f | 2016-03-21 14:50:24 +0100 | [diff] [blame] | 4334 | HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_i915_cpt_hdmi), |
Takashi Iwai | e85015a3 | 2016-03-21 13:56:19 +0100 | [diff] [blame] | 4335 | HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_i915_cpt_hdmi), |
| 4336 | HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_i915_cpt_hdmi), |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 4337 | HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_i915_hsw_hdmi), |
| 4338 | HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_i915_hsw_hdmi), |
| 4339 | HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_i915_hsw_hdmi), |
| 4340 | HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi), |
| 4341 | HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi), |
Guneshwor Singh | 2b4584d | 2017-12-07 18:06:20 +0530 | [diff] [blame] | 4342 | HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi), |
Ander Conselvan De Oliveira | a87a4d2 | 2017-04-13 13:05:35 +0530 | [diff] [blame] | 4343 | HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi), |
Jaroslav Kysela | b0d8bc5 | 2019-03-13 17:09:23 +0100 | [diff] [blame] | 4344 | HDA_CODEC_ENTRY(0x8086280f, "Icelake HDMI", patch_i915_icl_hdmi), |
Kai Vehmanen | 9a11ba7 | 2019-11-05 18:10:53 +0200 | [diff] [blame] | 4345 | HDA_CODEC_ENTRY(0x80862812, "Tigerlake HDMI", patch_i915_tgl_hdmi), |
Kai Vehmanen | 69b08bd | 2020-09-21 17:17:38 +0300 | [diff] [blame] | 4346 | HDA_CODEC_ENTRY(0x80862814, "DG1 HDMI", patch_i915_tgl_hdmi), |
Kai Vehmanen | d78359b | 2020-11-16 16:19:55 +0200 | [diff] [blame] | 4347 | HDA_CODEC_ENTRY(0x80862815, "Alderlake HDMI", patch_i915_tgl_hdmi), |
Kai Vehmanen | 5e941fc | 2021-01-13 17:56:29 +0200 | [diff] [blame] | 4348 | HDA_CODEC_ENTRY(0x8086281c, "Alderlake-P HDMI", patch_i915_tgl_hdmi), |
Rander Wang | f804a32 | 2020-09-02 18:42:07 +0300 | [diff] [blame] | 4349 | HDA_CODEC_ENTRY(0x80862816, "Rocketlake HDMI", patch_i915_tgl_hdmi), |
Yong Zhi | 78be222 | 2020-01-31 14:40:03 -0600 | [diff] [blame] | 4350 | HDA_CODEC_ENTRY(0x8086281a, "Jasperlake HDMI", patch_i915_icl_hdmi), |
Libin Yang | d233c49 | 2020-04-09 13:58:17 -0500 | [diff] [blame] | 4351 | HDA_CODEC_ENTRY(0x8086281b, "Elkhartlake HDMI", patch_i915_icl_hdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4352 | HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi), |
Takashi Iwai | a686632 | 2016-03-21 12:18:33 +0100 | [diff] [blame] | 4353 | HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi), |
| 4354 | HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi), |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4355 | HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi), |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 4356 | /* special ID for generic HDMI */ |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4357 | HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi), |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4358 | {} /* terminator */ |
| 4359 | }; |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4360 | MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4361 | |
| 4362 | MODULE_LICENSE("GPL"); |
| 4363 | MODULE_DESCRIPTION("HDMI HD-audio codec"); |
| 4364 | MODULE_ALIAS("snd-hda-codec-intelhdmi"); |
| 4365 | MODULE_ALIAS("snd-hda-codec-nvhdmi"); |
| 4366 | MODULE_ALIAS("snd-hda-codec-atihdmi"); |
| 4367 | |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 4368 | static struct hda_codec_driver hdmi_driver = { |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 4369 | .id = snd_hda_id_hdmi, |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 4370 | }; |
| 4371 | |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 4372 | module_hda_codec_driver(hdmi_driver); |