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