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