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