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