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