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