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