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