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