| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * patch_hdmi.c - routines for HDMI/DisplayPort codecs |
|---|
| .. | .. |
|---|
| 13 | 14 | * |
|---|
| 14 | 15 | * Maintained by: |
|---|
| 15 | 16 | * Wu Fengguang <wfg@linux.intel.com> |
|---|
| 16 | | - * |
|---|
| 17 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 18 | | - * under the terms of the GNU General Public License as published by the Free |
|---|
| 19 | | - * Software Foundation; either version 2 of the License, or (at your option) |
|---|
| 20 | | - * any later version. |
|---|
| 21 | | - * |
|---|
| 22 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 23 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|---|
| 24 | | - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|---|
| 25 | | - * for more details. |
|---|
| 26 | | - * |
|---|
| 27 | | - * You should have received a copy of the GNU General Public License |
|---|
| 28 | | - * along with this program; if not, write to the Free Software Foundation, |
|---|
| 29 | | - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 30 | 17 | */ |
|---|
| 31 | 18 | |
|---|
| 32 | 19 | #include <linux/init.h> |
|---|
| 33 | 20 | #include <linux/delay.h> |
|---|
| 21 | +#include <linux/pci.h> |
|---|
| 34 | 22 | #include <linux/slab.h> |
|---|
| 35 | 23 | #include <linux/module.h> |
|---|
| 36 | 24 | #include <linux/pm_runtime.h> |
|---|
| .. | .. |
|---|
| 41 | 29 | #include <sound/hdaudio.h> |
|---|
| 42 | 30 | #include <sound/hda_i915.h> |
|---|
| 43 | 31 | #include <sound/hda_chmap.h> |
|---|
| 44 | | -#include "hda_codec.h" |
|---|
| 32 | +#include <sound/hda_codec.h> |
|---|
| 45 | 33 | #include "hda_local.h" |
|---|
| 46 | 34 | #include "hda_jack.h" |
|---|
| 35 | +#include "hda_controller.h" |
|---|
| 47 | 36 | |
|---|
| 48 | 37 | static bool static_hdmi_pcm; |
|---|
| 49 | 38 | module_param(static_hdmi_pcm, bool, 0644); |
|---|
| 50 | 39 | MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); |
|---|
| 51 | 40 | |
|---|
| 52 | | -#define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807) |
|---|
| 53 | | -#define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808) |
|---|
| 54 | | -#define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809) |
|---|
| 55 | | -#define is_broxton(codec) ((codec)->core.vendor_id == 0x8086280a) |
|---|
| 56 | | -#define is_kabylake(codec) ((codec)->core.vendor_id == 0x8086280b) |
|---|
| 57 | | -#define is_geminilake(codec) (((codec)->core.vendor_id == 0x8086280d) || \ |
|---|
| 58 | | - ((codec)->core.vendor_id == 0x80862800)) |
|---|
| 59 | | -#define is_cannonlake(codec) ((codec)->core.vendor_id == 0x8086280c) |
|---|
| 60 | | -#define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \ |
|---|
| 61 | | - || is_skylake(codec) || is_broxton(codec) \ |
|---|
| 62 | | - || is_kabylake(codec)) || is_geminilake(codec) \ |
|---|
| 63 | | - || is_cannonlake(codec) |
|---|
| 64 | | -#define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882) |
|---|
| 65 | | -#define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883) |
|---|
| 66 | | -#define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec)) |
|---|
| 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 | + |
|---|
| 45 | +static bool enable_silent_stream = |
|---|
| 46 | +IS_ENABLED(CONFIG_SND_HDA_INTEL_HDMI_SILENT_STREAM); |
|---|
| 47 | +module_param(enable_silent_stream, bool, 0644); |
|---|
| 48 | +MODULE_PARM_DESC(enable_silent_stream, "Enable Silent Stream for HDMI devices"); |
|---|
| 67 | 49 | |
|---|
| 68 | 50 | struct hdmi_spec_per_cvt { |
|---|
| 69 | 51 | hda_nid_t cvt_nid; |
|---|
| .. | .. |
|---|
| 96 | 78 | int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */ |
|---|
| 97 | 79 | int repoll_count; |
|---|
| 98 | 80 | bool setup; /* the stream has been set up by prepare callback */ |
|---|
| 81 | + bool silent_stream; |
|---|
| 99 | 82 | int channels; /* current number of channels */ |
|---|
| 100 | 83 | bool non_pcm; |
|---|
| 101 | 84 | bool chmap_set; /* channel-map override by ALSA API? */ |
|---|
| .. | .. |
|---|
| 108 | 91 | /* operations used by generic code that can be overridden by patches */ |
|---|
| 109 | 92 | struct hdmi_ops { |
|---|
| 110 | 93 | int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid, |
|---|
| 111 | | - unsigned char *buf, int *eld_size); |
|---|
| 94 | + int dev_id, unsigned char *buf, int *eld_size); |
|---|
| 112 | 95 | |
|---|
| 113 | 96 | void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid, |
|---|
| 97 | + int dev_id, |
|---|
| 114 | 98 | int ca, int active_channels, int conn_type); |
|---|
| 115 | 99 | |
|---|
| 116 | 100 | /* enable/disable HBR (HD passthrough) */ |
|---|
| 117 | | - int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr); |
|---|
| 101 | + int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, |
|---|
| 102 | + int dev_id, bool hbr); |
|---|
| 118 | 103 | |
|---|
| 119 | 104 | int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid, |
|---|
| 120 | | - hda_nid_t pin_nid, u32 stream_tag, int format); |
|---|
| 105 | + hda_nid_t pin_nid, int dev_id, u32 stream_tag, |
|---|
| 106 | + int format); |
|---|
| 121 | 107 | |
|---|
| 122 | 108 | void (*pin_cvt_fixup)(struct hda_codec *codec, |
|---|
| 123 | 109 | struct hdmi_spec_per_pin *per_pin, |
|---|
| .. | .. |
|---|
| 131 | 117 | }; |
|---|
| 132 | 118 | |
|---|
| 133 | 119 | struct hdmi_spec { |
|---|
| 120 | + struct hda_codec *codec; |
|---|
| 134 | 121 | int num_cvts; |
|---|
| 135 | 122 | struct snd_array cvts; /* struct hdmi_spec_per_cvt */ |
|---|
| 136 | 123 | hda_nid_t cvt_nids[4]; /* only for haswell fix */ |
|---|
| .. | .. |
|---|
| 155 | 142 | struct snd_array pins; /* struct hdmi_spec_per_pin */ |
|---|
| 156 | 143 | struct hdmi_pcm pcm_rec[16]; |
|---|
| 157 | 144 | struct mutex pcm_lock; |
|---|
| 145 | + struct mutex bind_lock; /* for audio component binding */ |
|---|
| 158 | 146 | /* pcm_bitmap means which pcms have been assigned to pins*/ |
|---|
| 159 | 147 | unsigned long pcm_bitmap; |
|---|
| 160 | 148 | int pcm_used; /* counter of pcm_rec[] */ |
|---|
| .. | .. |
|---|
| 169 | 157 | |
|---|
| 170 | 158 | bool dyn_pin_out; |
|---|
| 171 | 159 | bool dyn_pcm_assign; |
|---|
| 160 | + bool dyn_pcm_no_legacy; |
|---|
| 161 | + bool nv_dp_workaround; /* workaround DP audio infoframe for Nvidia */ |
|---|
| 162 | + |
|---|
| 163 | + bool intel_hsw_fixup; /* apply Intel platform-specific fixups */ |
|---|
| 172 | 164 | /* |
|---|
| 173 | 165 | * Non-generic VIA/NVIDIA specific |
|---|
| 174 | 166 | */ |
|---|
| 175 | 167 | struct hda_multi_out multiout; |
|---|
| 176 | 168 | struct hda_pcm_stream pcm_playback; |
|---|
| 177 | 169 | |
|---|
| 178 | | - /* i915/powerwell (Haswell+/Valleyview+) specific */ |
|---|
| 179 | | - bool use_acomp_notifier; /* use i915 eld_notify callback for hotplug */ |
|---|
| 170 | + bool use_acomp_notifier; /* use eld_notify callback for hotplug */ |
|---|
| 171 | + bool acomp_registered; /* audio component registered in this driver */ |
|---|
| 172 | + bool force_connect; /* force connectivity */ |
|---|
| 180 | 173 | struct drm_audio_component_audio_ops drm_audio_ops; |
|---|
| 174 | + int (*port2pin)(struct hda_codec *, int); /* reverse port/pin mapping */ |
|---|
| 181 | 175 | |
|---|
| 182 | 176 | struct hdac_chmap chmap; |
|---|
| 183 | 177 | hda_nid_t vendor_nid; |
|---|
| 178 | + const int *port_map; |
|---|
| 179 | + int port_num; |
|---|
| 180 | + bool send_silent_stream; /* Flag to enable silent stream feature */ |
|---|
| 184 | 181 | }; |
|---|
| 185 | 182 | |
|---|
| 186 | 183 | #ifdef CONFIG_SND_HDA_COMPONENT |
|---|
| .. | .. |
|---|
| 273 | 270 | if (get_pcm_rec(spec, pcm_idx)->stream == hinfo) |
|---|
| 274 | 271 | return pcm_idx; |
|---|
| 275 | 272 | |
|---|
| 276 | | - codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo); |
|---|
| 273 | + codec_warn(codec, "HDMI: hinfo %p not tied to a PCM\n", hinfo); |
|---|
| 277 | 274 | return -EINVAL; |
|---|
| 278 | 275 | } |
|---|
| 279 | 276 | |
|---|
| .. | .. |
|---|
| 291 | 288 | return pin_idx; |
|---|
| 292 | 289 | } |
|---|
| 293 | 290 | |
|---|
| 294 | | - codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo); |
|---|
| 291 | + codec_dbg(codec, "HDMI: hinfo %p (pcm %d) not registered\n", hinfo, |
|---|
| 292 | + hinfo_to_pcm_index(codec, hinfo)); |
|---|
| 295 | 293 | return -EINVAL; |
|---|
| 296 | 294 | } |
|---|
| 297 | 295 | |
|---|
| .. | .. |
|---|
| 389 | 387 | } |
|---|
| 390 | 388 | |
|---|
| 391 | 389 | static const struct snd_kcontrol_new eld_bytes_ctl = { |
|---|
| 392 | | - .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
|---|
| 390 | + .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE | |
|---|
| 391 | + SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK, |
|---|
| 393 | 392 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
|---|
| 394 | 393 | .name = "ELD", |
|---|
| 395 | 394 | .info = hdmi_eld_ctl_info, |
|---|
| .. | .. |
|---|
| 657 | 656 | return true; |
|---|
| 658 | 657 | } |
|---|
| 659 | 658 | |
|---|
| 659 | +static int hdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid, |
|---|
| 660 | + int dev_id, unsigned char *buf, int *eld_size) |
|---|
| 661 | +{ |
|---|
| 662 | + snd_hda_set_dev_select(codec, nid, dev_id); |
|---|
| 663 | + |
|---|
| 664 | + return snd_hdmi_get_eld(codec, nid, buf, eld_size); |
|---|
| 665 | +} |
|---|
| 666 | + |
|---|
| 660 | 667 | static void hdmi_pin_setup_infoframe(struct hda_codec *codec, |
|---|
| 661 | | - hda_nid_t pin_nid, |
|---|
| 668 | + hda_nid_t pin_nid, int dev_id, |
|---|
| 662 | 669 | int ca, int active_channels, |
|---|
| 663 | 670 | int conn_type) |
|---|
| 664 | 671 | { |
|---|
| 672 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 665 | 673 | union audio_infoframe ai; |
|---|
| 666 | 674 | |
|---|
| 667 | 675 | memset(&ai, 0, sizeof(ai)); |
|---|
| 668 | | - if (conn_type == 0) { /* HDMI */ |
|---|
| 676 | + if ((conn_type == 0) || /* HDMI */ |
|---|
| 677 | + /* Nvidia DisplayPort: Nvidia HW expects same layout as HDMI */ |
|---|
| 678 | + (conn_type == 1 && spec->nv_dp_workaround)) { |
|---|
| 669 | 679 | struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi; |
|---|
| 670 | 680 | |
|---|
| 671 | | - hdmi_ai->type = 0x84; |
|---|
| 672 | | - hdmi_ai->ver = 0x01; |
|---|
| 673 | | - hdmi_ai->len = 0x0a; |
|---|
| 681 | + if (conn_type == 0) { /* HDMI */ |
|---|
| 682 | + hdmi_ai->type = 0x84; |
|---|
| 683 | + hdmi_ai->ver = 0x01; |
|---|
| 684 | + hdmi_ai->len = 0x0a; |
|---|
| 685 | + } else {/* Nvidia DP */ |
|---|
| 686 | + hdmi_ai->type = 0x84; |
|---|
| 687 | + hdmi_ai->ver = 0x1b; |
|---|
| 688 | + hdmi_ai->len = 0x11 << 2; |
|---|
| 689 | + } |
|---|
| 674 | 690 | hdmi_ai->CC02_CT47 = active_channels - 1; |
|---|
| 675 | 691 | hdmi_ai->CA = ca; |
|---|
| 676 | 692 | hdmi_checksum_audio_infoframe(hdmi_ai); |
|---|
| .. | .. |
|---|
| 687 | 703 | pin_nid); |
|---|
| 688 | 704 | return; |
|---|
| 689 | 705 | } |
|---|
| 706 | + |
|---|
| 707 | + snd_hda_set_dev_select(codec, pin_nid, dev_id); |
|---|
| 690 | 708 | |
|---|
| 691 | 709 | /* |
|---|
| 692 | 710 | * sizeof(ai) is used instead of sizeof(*hdmi_ai) or |
|---|
| .. | .. |
|---|
| 713 | 731 | struct hdmi_spec *spec = codec->spec; |
|---|
| 714 | 732 | struct hdac_chmap *chmap = &spec->chmap; |
|---|
| 715 | 733 | hda_nid_t pin_nid = per_pin->pin_nid; |
|---|
| 734 | + int dev_id = per_pin->dev_id; |
|---|
| 716 | 735 | int channels = per_pin->channels; |
|---|
| 717 | 736 | int active_channels; |
|---|
| 718 | 737 | struct hdmi_eld *eld; |
|---|
| .. | .. |
|---|
| 720 | 739 | |
|---|
| 721 | 740 | if (!channels) |
|---|
| 722 | 741 | return; |
|---|
| 742 | + |
|---|
| 743 | + snd_hda_set_dev_select(codec, pin_nid, dev_id); |
|---|
| 723 | 744 | |
|---|
| 724 | 745 | /* some HW (e.g. HSW+) needs reprogramming the amp at each time */ |
|---|
| 725 | 746 | if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) |
|---|
| .. | .. |
|---|
| 746 | 767 | pin_nid, non_pcm, ca, channels, |
|---|
| 747 | 768 | per_pin->chmap, per_pin->chmap_set); |
|---|
| 748 | 769 | |
|---|
| 749 | | - spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels, |
|---|
| 750 | | - eld->info.conn_type); |
|---|
| 770 | + spec->ops.pin_setup_infoframe(codec, pin_nid, dev_id, |
|---|
| 771 | + ca, active_channels, eld->info.conn_type); |
|---|
| 751 | 772 | |
|---|
| 752 | 773 | per_pin->non_pcm = non_pcm; |
|---|
| 753 | 774 | } |
|---|
| .. | .. |
|---|
| 756 | 777 | * Unsolicited events |
|---|
| 757 | 778 | */ |
|---|
| 758 | 779 | |
|---|
| 759 | | -static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); |
|---|
| 780 | +static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); |
|---|
| 760 | 781 | |
|---|
| 761 | 782 | static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid, |
|---|
| 762 | 783 | int dev_id) |
|---|
| .. | .. |
|---|
| 767 | 788 | if (pin_idx < 0) |
|---|
| 768 | 789 | return; |
|---|
| 769 | 790 | mutex_lock(&spec->pcm_lock); |
|---|
| 770 | | - if (hdmi_present_sense(get_pin(spec, pin_idx), 1)) |
|---|
| 771 | | - snd_hda_jack_report_sync(codec); |
|---|
| 791 | + hdmi_present_sense(get_pin(spec, pin_idx), 1); |
|---|
| 772 | 792 | mutex_unlock(&spec->pcm_lock); |
|---|
| 773 | 793 | } |
|---|
| 774 | 794 | |
|---|
| 775 | 795 | static void jack_callback(struct hda_codec *codec, |
|---|
| 776 | 796 | struct hda_jack_callback *jack) |
|---|
| 777 | 797 | { |
|---|
| 778 | | - /* hda_jack don't support DP MST */ |
|---|
| 779 | | - check_presence_and_report(codec, jack->nid, 0); |
|---|
| 798 | + /* stop polling when notification is enabled */ |
|---|
| 799 | + if (codec_has_acomp(codec)) |
|---|
| 800 | + return; |
|---|
| 801 | + |
|---|
| 802 | + check_presence_and_report(codec, jack->nid, jack->dev_id); |
|---|
| 780 | 803 | } |
|---|
| 781 | 804 | |
|---|
| 782 | | -static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) |
|---|
| 805 | +static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res, |
|---|
| 806 | + struct hda_jack_tbl *jack) |
|---|
| 783 | 807 | { |
|---|
| 784 | | - int tag = res >> AC_UNSOL_RES_TAG_SHIFT; |
|---|
| 785 | | - struct hda_jack_tbl *jack; |
|---|
| 786 | | - int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT; |
|---|
| 787 | | - |
|---|
| 788 | | - /* |
|---|
| 789 | | - * assume DP MST uses dyn_pcm_assign and acomp and |
|---|
| 790 | | - * never comes here |
|---|
| 791 | | - * if DP MST supports unsol event, below code need |
|---|
| 792 | | - * consider dev_entry |
|---|
| 793 | | - */ |
|---|
| 794 | | - jack = snd_hda_jack_tbl_get_from_tag(codec, tag); |
|---|
| 795 | | - if (!jack) |
|---|
| 796 | | - return; |
|---|
| 797 | 808 | jack->jack_dirty = 1; |
|---|
| 798 | 809 | |
|---|
| 799 | 810 | codec_dbg(codec, |
|---|
| 800 | 811 | "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n", |
|---|
| 801 | | - codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA), |
|---|
| 812 | + codec->addr, jack->nid, jack->dev_id, !!(res & AC_UNSOL_RES_IA), |
|---|
| 802 | 813 | !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV)); |
|---|
| 803 | 814 | |
|---|
| 804 | | - /* hda_jack don't support DP MST */ |
|---|
| 805 | | - check_presence_and_report(codec, jack->nid, 0); |
|---|
| 815 | + check_presence_and_report(codec, jack->nid, jack->dev_id); |
|---|
| 806 | 816 | } |
|---|
| 807 | 817 | |
|---|
| 808 | 818 | static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) |
|---|
| .. | .. |
|---|
| 821 | 831 | cp_ready); |
|---|
| 822 | 832 | |
|---|
| 823 | 833 | /* TODO */ |
|---|
| 824 | | - if (cp_state) |
|---|
| 834 | + if (cp_state) { |
|---|
| 825 | 835 | ; |
|---|
| 826 | | - if (cp_ready) |
|---|
| 836 | + } |
|---|
| 837 | + if (cp_ready) { |
|---|
| 827 | 838 | ; |
|---|
| 839 | + } |
|---|
| 828 | 840 | } |
|---|
| 829 | 841 | |
|---|
| 830 | 842 | |
|---|
| .. | .. |
|---|
| 832 | 844 | { |
|---|
| 833 | 845 | int tag = res >> AC_UNSOL_RES_TAG_SHIFT; |
|---|
| 834 | 846 | int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; |
|---|
| 847 | + struct hda_jack_tbl *jack; |
|---|
| 835 | 848 | |
|---|
| 836 | | - if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) { |
|---|
| 849 | + if (codec_has_acomp(codec)) |
|---|
| 850 | + return; |
|---|
| 851 | + |
|---|
| 852 | + if (codec->dp_mst) { |
|---|
| 853 | + int dev_entry = |
|---|
| 854 | + (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT; |
|---|
| 855 | + |
|---|
| 856 | + jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry); |
|---|
| 857 | + } else { |
|---|
| 858 | + jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0); |
|---|
| 859 | + } |
|---|
| 860 | + |
|---|
| 861 | + if (!jack) { |
|---|
| 837 | 862 | codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag); |
|---|
| 838 | 863 | return; |
|---|
| 839 | 864 | } |
|---|
| 840 | 865 | |
|---|
| 841 | 866 | if (subtag == 0) |
|---|
| 842 | | - hdmi_intrinsic_event(codec, res); |
|---|
| 867 | + hdmi_intrinsic_event(codec, res, jack); |
|---|
| 843 | 868 | else |
|---|
| 844 | 869 | hdmi_non_intrinsic_event(codec, res); |
|---|
| 845 | 870 | } |
|---|
| .. | .. |
|---|
| 874 | 899 | ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7) |
|---|
| 875 | 900 | |
|---|
| 876 | 901 | static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid, |
|---|
| 877 | | - bool hbr) |
|---|
| 902 | + int dev_id, bool hbr) |
|---|
| 878 | 903 | { |
|---|
| 879 | 904 | int pinctl, new_pinctl; |
|---|
| 880 | 905 | |
|---|
| 881 | 906 | if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) { |
|---|
| 907 | + snd_hda_set_dev_select(codec, pin_nid, dev_id); |
|---|
| 882 | 908 | pinctl = snd_hda_codec_read(codec, pin_nid, 0, |
|---|
| 883 | 909 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
|---|
| 884 | 910 | |
|---|
| .. | .. |
|---|
| 908 | 934 | } |
|---|
| 909 | 935 | |
|---|
| 910 | 936 | static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, |
|---|
| 911 | | - hda_nid_t pin_nid, u32 stream_tag, int format) |
|---|
| 937 | + hda_nid_t pin_nid, int dev_id, |
|---|
| 938 | + u32 stream_tag, int format) |
|---|
| 912 | 939 | { |
|---|
| 913 | 940 | struct hdmi_spec *spec = codec->spec; |
|---|
| 914 | 941 | unsigned int param; |
|---|
| 915 | 942 | int err; |
|---|
| 916 | 943 | |
|---|
| 917 | | - err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format)); |
|---|
| 944 | + err = spec->ops.pin_hbr_setup(codec, pin_nid, dev_id, |
|---|
| 945 | + is_hbr_format(format)); |
|---|
| 918 | 946 | |
|---|
| 919 | 947 | if (err) { |
|---|
| 920 | 948 | codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n"); |
|---|
| 921 | 949 | return err; |
|---|
| 922 | 950 | } |
|---|
| 923 | 951 | |
|---|
| 924 | | - if (is_haswell_plus(codec)) { |
|---|
| 952 | + if (spec->intel_hsw_fixup) { |
|---|
| 925 | 953 | |
|---|
| 926 | 954 | /* |
|---|
| 927 | 955 | * on recent platforms IEC Coding Type is required for HBR |
|---|
| .. | .. |
|---|
| 963 | 991 | per_pin = NULL; |
|---|
| 964 | 992 | else |
|---|
| 965 | 993 | per_pin = get_pin(spec, pin_idx); |
|---|
| 994 | + |
|---|
| 995 | + if (per_pin && per_pin->silent_stream) { |
|---|
| 996 | + cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid); |
|---|
| 997 | + if (cvt_id) |
|---|
| 998 | + *cvt_id = cvt_idx; |
|---|
| 999 | + return 0; |
|---|
| 1000 | + } |
|---|
| 966 | 1001 | |
|---|
| 967 | 1002 | /* Dynamically assign converter to stream */ |
|---|
| 968 | 1003 | for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { |
|---|
| .. | .. |
|---|
| 1234 | 1269 | set_bit(pcm_idx, &spec->pcm_in_use); |
|---|
| 1235 | 1270 | per_pin = get_pin(spec, pin_idx); |
|---|
| 1236 | 1271 | per_pin->cvt_nid = per_cvt->cvt_nid; |
|---|
| 1272 | + per_pin->silent_stream = false; |
|---|
| 1237 | 1273 | hinfo->nid = per_cvt->cvt_nid; |
|---|
| 1274 | + |
|---|
| 1275 | + /* flip stripe flag for the assigned stream if supported */ |
|---|
| 1276 | + if (get_wcaps(codec, per_cvt->cvt_nid) & AC_WCAP_STRIPE) |
|---|
| 1277 | + azx_stream(get_azx_dev(substream))->stripe = 1; |
|---|
| 1238 | 1278 | |
|---|
| 1239 | 1279 | snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id); |
|---|
| 1240 | 1280 | snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, |
|---|
| .. | .. |
|---|
| 1288 | 1328 | struct hdmi_spec *spec = codec->spec; |
|---|
| 1289 | 1329 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
|---|
| 1290 | 1330 | hda_nid_t pin_nid = per_pin->pin_nid; |
|---|
| 1331 | + int dev_id = per_pin->dev_id; |
|---|
| 1332 | + int conns; |
|---|
| 1291 | 1333 | |
|---|
| 1292 | 1334 | if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { |
|---|
| 1293 | 1335 | codec_warn(codec, |
|---|
| .. | .. |
|---|
| 1296 | 1338 | return -EINVAL; |
|---|
| 1297 | 1339 | } |
|---|
| 1298 | 1340 | |
|---|
| 1341 | + snd_hda_set_dev_select(codec, pin_nid, dev_id); |
|---|
| 1342 | + |
|---|
| 1343 | + if (spec->intel_hsw_fixup) { |
|---|
| 1344 | + conns = spec->num_cvts; |
|---|
| 1345 | + memcpy(per_pin->mux_nids, spec->cvt_nids, |
|---|
| 1346 | + sizeof(hda_nid_t) * conns); |
|---|
| 1347 | + } else { |
|---|
| 1348 | + conns = snd_hda_get_raw_connections(codec, pin_nid, |
|---|
| 1349 | + per_pin->mux_nids, |
|---|
| 1350 | + HDA_MAX_CONNECTIONS); |
|---|
| 1351 | + } |
|---|
| 1352 | + |
|---|
| 1299 | 1353 | /* all the device entries on the same pin have the same conn list */ |
|---|
| 1300 | | - per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid, |
|---|
| 1301 | | - per_pin->mux_nids, |
|---|
| 1302 | | - HDA_MAX_CONNECTIONS); |
|---|
| 1354 | + per_pin->num_mux_nids = conns; |
|---|
| 1303 | 1355 | |
|---|
| 1304 | 1356 | return 0; |
|---|
| 1305 | 1357 | } |
|---|
| 1306 | 1358 | |
|---|
| 1307 | 1359 | static int hdmi_find_pcm_slot(struct hdmi_spec *spec, |
|---|
| 1308 | | - struct hdmi_spec_per_pin *per_pin) |
|---|
| 1360 | + struct hdmi_spec_per_pin *per_pin) |
|---|
| 1309 | 1361 | { |
|---|
| 1310 | 1362 | int i; |
|---|
| 1311 | 1363 | |
|---|
| 1312 | | - /* try the prefer PCM */ |
|---|
| 1313 | | - if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap)) |
|---|
| 1314 | | - return per_pin->pin_nid_idx; |
|---|
| 1364 | + /* on the new machines, try to assign the pcm slot dynamically, |
|---|
| 1365 | + * not use the preferred fixed map (legacy way) anymore. |
|---|
| 1366 | + */ |
|---|
| 1367 | + if (spec->dyn_pcm_no_legacy) |
|---|
| 1368 | + goto last_try; |
|---|
| 1315 | 1369 | |
|---|
| 1316 | | - /* have a second try; check the "reserved area" over num_pins */ |
|---|
| 1370 | + /* |
|---|
| 1371 | + * generic_hdmi_build_pcms() may allocate extra PCMs on some |
|---|
| 1372 | + * platforms (with maximum of 'num_nids + dev_num - 1') |
|---|
| 1373 | + * |
|---|
| 1374 | + * The per_pin of pin_nid_idx=n and dev_id=m prefers to get pcm-n |
|---|
| 1375 | + * if m==0. This guarantees that dynamic pcm assignments are compatible |
|---|
| 1376 | + * with the legacy static per_pin-pcm assignment that existed in the |
|---|
| 1377 | + * days before DP-MST. |
|---|
| 1378 | + * |
|---|
| 1379 | + * Intel DP-MST prefers this legacy behavior for compatibility, too. |
|---|
| 1380 | + * |
|---|
| 1381 | + * per_pin of m!=0 prefers to get pcm=(num_nids + (m - 1)). |
|---|
| 1382 | + */ |
|---|
| 1383 | + |
|---|
| 1384 | + if (per_pin->dev_id == 0 || spec->intel_hsw_fixup) { |
|---|
| 1385 | + if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap)) |
|---|
| 1386 | + return per_pin->pin_nid_idx; |
|---|
| 1387 | + } else { |
|---|
| 1388 | + i = spec->num_nids + (per_pin->dev_id - 1); |
|---|
| 1389 | + if (i < spec->pcm_used && !(test_bit(i, &spec->pcm_bitmap))) |
|---|
| 1390 | + return i; |
|---|
| 1391 | + } |
|---|
| 1392 | + |
|---|
| 1393 | + /* have a second try; check the area over num_nids */ |
|---|
| 1317 | 1394 | for (i = spec->num_nids; i < spec->pcm_used; i++) { |
|---|
| 1318 | 1395 | if (!test_bit(i, &spec->pcm_bitmap)) |
|---|
| 1319 | 1396 | return i; |
|---|
| 1320 | 1397 | } |
|---|
| 1321 | 1398 | |
|---|
| 1399 | + last_try: |
|---|
| 1322 | 1400 | /* the last try; check the empty slots in pins */ |
|---|
| 1323 | | - for (i = 0; i < spec->num_nids; i++) { |
|---|
| 1401 | + for (i = 0; i < spec->pcm_used; i++) { |
|---|
| 1324 | 1402 | if (!test_bit(i, &spec->pcm_bitmap)) |
|---|
| 1325 | 1403 | return i; |
|---|
| 1326 | 1404 | } |
|---|
| .. | .. |
|---|
| 1428 | 1506 | per_pin->channels = 0; |
|---|
| 1429 | 1507 | } |
|---|
| 1430 | 1508 | |
|---|
| 1509 | +static struct snd_jack *pin_idx_to_pcm_jack(struct hda_codec *codec, |
|---|
| 1510 | + struct hdmi_spec_per_pin *per_pin) |
|---|
| 1511 | +{ |
|---|
| 1512 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 1513 | + |
|---|
| 1514 | + if (per_pin->pcm_idx >= 0) |
|---|
| 1515 | + return spec->pcm_rec[per_pin->pcm_idx].jack; |
|---|
| 1516 | + else |
|---|
| 1517 | + return NULL; |
|---|
| 1518 | +} |
|---|
| 1519 | + |
|---|
| 1431 | 1520 | /* update per_pin ELD from the given new ELD; |
|---|
| 1432 | 1521 | * setup info frame and notification accordingly |
|---|
| 1522 | + * also notify ELD kctl and report jack status changes |
|---|
| 1433 | 1523 | */ |
|---|
| 1434 | 1524 | static void update_eld(struct hda_codec *codec, |
|---|
| 1435 | 1525 | struct hdmi_spec_per_pin *per_pin, |
|---|
| 1436 | | - struct hdmi_eld *eld) |
|---|
| 1526 | + struct hdmi_eld *eld, |
|---|
| 1527 | + int repoll) |
|---|
| 1437 | 1528 | { |
|---|
| 1438 | 1529 | struct hdmi_eld *pin_eld = &per_pin->sink_eld; |
|---|
| 1439 | 1530 | struct hdmi_spec *spec = codec->spec; |
|---|
| 1531 | + struct snd_jack *pcm_jack; |
|---|
| 1440 | 1532 | bool old_eld_valid = pin_eld->eld_valid; |
|---|
| 1441 | 1533 | bool eld_changed; |
|---|
| 1442 | | - int pcm_idx = -1; |
|---|
| 1534 | + int pcm_idx; |
|---|
| 1535 | + |
|---|
| 1536 | + if (eld->eld_valid) { |
|---|
| 1537 | + if (eld->eld_size <= 0 || |
|---|
| 1538 | + snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer, |
|---|
| 1539 | + eld->eld_size) < 0) { |
|---|
| 1540 | + eld->eld_valid = false; |
|---|
| 1541 | + if (repoll) { |
|---|
| 1542 | + schedule_delayed_work(&per_pin->work, |
|---|
| 1543 | + msecs_to_jiffies(300)); |
|---|
| 1544 | + return; |
|---|
| 1545 | + } |
|---|
| 1546 | + } |
|---|
| 1547 | + } |
|---|
| 1548 | + |
|---|
| 1549 | + if (!eld->eld_valid || eld->eld_size <= 0) { |
|---|
| 1550 | + eld->eld_valid = false; |
|---|
| 1551 | + eld->eld_size = 0; |
|---|
| 1552 | + } |
|---|
| 1443 | 1553 | |
|---|
| 1444 | 1554 | /* for monitor disconnection, save pcm_idx firstly */ |
|---|
| 1445 | 1555 | pcm_idx = per_pin->pcm_idx; |
|---|
| 1556 | + |
|---|
| 1557 | + /* |
|---|
| 1558 | + * pcm_idx >=0 before update_eld() means it is in monitor |
|---|
| 1559 | + * disconnected event. Jack must be fetched before update_eld(). |
|---|
| 1560 | + */ |
|---|
| 1561 | + pcm_jack = pin_idx_to_pcm_jack(codec, per_pin); |
|---|
| 1562 | + |
|---|
| 1446 | 1563 | if (spec->dyn_pcm_assign) { |
|---|
| 1447 | 1564 | if (eld->eld_valid) { |
|---|
| 1448 | 1565 | hdmi_attach_hda_pcm(spec, per_pin); |
|---|
| .. | .. |
|---|
| 1457 | 1574 | */ |
|---|
| 1458 | 1575 | if (pcm_idx == -1) |
|---|
| 1459 | 1576 | pcm_idx = per_pin->pcm_idx; |
|---|
| 1577 | + if (!pcm_jack) |
|---|
| 1578 | + pcm_jack = pin_idx_to_pcm_jack(codec, per_pin); |
|---|
| 1460 | 1579 | |
|---|
| 1461 | 1580 | if (eld->eld_valid) |
|---|
| 1462 | 1581 | snd_hdmi_show_eld(codec, &eld->info); |
|---|
| 1463 | 1582 | |
|---|
| 1464 | 1583 | eld_changed = (pin_eld->eld_valid != eld->eld_valid); |
|---|
| 1465 | | - if (eld->eld_valid && pin_eld->eld_valid) |
|---|
| 1584 | + eld_changed |= (pin_eld->monitor_present != eld->monitor_present); |
|---|
| 1585 | + if (!eld_changed && eld->eld_valid && pin_eld->eld_valid) |
|---|
| 1466 | 1586 | if (pin_eld->eld_size != eld->eld_size || |
|---|
| 1467 | 1587 | memcmp(pin_eld->eld_buffer, eld->eld_buffer, |
|---|
| 1468 | 1588 | eld->eld_size) != 0) |
|---|
| 1469 | 1589 | eld_changed = true; |
|---|
| 1470 | 1590 | |
|---|
| 1471 | | - pin_eld->monitor_present = eld->monitor_present; |
|---|
| 1472 | | - pin_eld->eld_valid = eld->eld_valid; |
|---|
| 1473 | | - pin_eld->eld_size = eld->eld_size; |
|---|
| 1474 | | - if (eld->eld_valid) |
|---|
| 1475 | | - memcpy(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size); |
|---|
| 1476 | | - pin_eld->info = eld->info; |
|---|
| 1591 | + if (eld_changed) { |
|---|
| 1592 | + pin_eld->monitor_present = eld->monitor_present; |
|---|
| 1593 | + pin_eld->eld_valid = eld->eld_valid; |
|---|
| 1594 | + pin_eld->eld_size = eld->eld_size; |
|---|
| 1595 | + if (eld->eld_valid) |
|---|
| 1596 | + memcpy(pin_eld->eld_buffer, eld->eld_buffer, |
|---|
| 1597 | + eld->eld_size); |
|---|
| 1598 | + pin_eld->info = eld->info; |
|---|
| 1599 | + } |
|---|
| 1477 | 1600 | |
|---|
| 1478 | 1601 | /* |
|---|
| 1479 | 1602 | * Re-setup pin and infoframe. This is needed e.g. when |
|---|
| .. | .. |
|---|
| 1491 | 1614 | SNDRV_CTL_EVENT_MASK_VALUE | |
|---|
| 1492 | 1615 | SNDRV_CTL_EVENT_MASK_INFO, |
|---|
| 1493 | 1616 | &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id); |
|---|
| 1617 | + |
|---|
| 1618 | + if (eld_changed && pcm_jack) |
|---|
| 1619 | + snd_jack_report(pcm_jack, |
|---|
| 1620 | + (eld->monitor_present && eld->eld_valid) ? |
|---|
| 1621 | + SND_JACK_AVOUT : 0); |
|---|
| 1494 | 1622 | } |
|---|
| 1495 | 1623 | |
|---|
| 1496 | 1624 | /* update ELD and jack state via HD-audio verbs */ |
|---|
| 1497 | | -static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin, |
|---|
| 1625 | +static void hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin, |
|---|
| 1498 | 1626 | int repoll) |
|---|
| 1499 | 1627 | { |
|---|
| 1500 | | - struct hda_jack_tbl *jack; |
|---|
| 1501 | 1628 | struct hda_codec *codec = per_pin->codec; |
|---|
| 1502 | 1629 | struct hdmi_spec *spec = codec->spec; |
|---|
| 1503 | 1630 | struct hdmi_eld *eld = &spec->temp_eld; |
|---|
| 1631 | + struct device *dev = hda_codec_dev(codec); |
|---|
| 1504 | 1632 | hda_nid_t pin_nid = per_pin->pin_nid; |
|---|
| 1633 | + int dev_id = per_pin->dev_id; |
|---|
| 1505 | 1634 | /* |
|---|
| 1506 | 1635 | * Always execute a GetPinSense verb here, even when called from |
|---|
| 1507 | 1636 | * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited |
|---|
| .. | .. |
|---|
| 1511 | 1640 | * the unsolicited response to avoid custom WARs. |
|---|
| 1512 | 1641 | */ |
|---|
| 1513 | 1642 | int present; |
|---|
| 1514 | | - bool ret; |
|---|
| 1515 | | - bool do_repoll = false; |
|---|
| 1643 | + int ret; |
|---|
| 1516 | 1644 | |
|---|
| 1517 | | - present = snd_hda_pin_sense(codec, pin_nid); |
|---|
| 1645 | +#ifdef CONFIG_PM |
|---|
| 1646 | + if (dev->power.runtime_status == RPM_SUSPENDING) |
|---|
| 1647 | + return; |
|---|
| 1648 | +#endif |
|---|
| 1649 | + |
|---|
| 1650 | + ret = snd_hda_power_up_pm(codec); |
|---|
| 1651 | + if (ret < 0 && pm_runtime_suspended(dev)) |
|---|
| 1652 | + goto out; |
|---|
| 1653 | + |
|---|
| 1654 | + present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id); |
|---|
| 1518 | 1655 | |
|---|
| 1519 | 1656 | mutex_lock(&per_pin->lock); |
|---|
| 1520 | 1657 | eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); |
|---|
| .. | .. |
|---|
| 1528 | 1665 | codec->addr, pin_nid, eld->monitor_present, eld->eld_valid); |
|---|
| 1529 | 1666 | |
|---|
| 1530 | 1667 | if (eld->eld_valid) { |
|---|
| 1531 | | - if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer, |
|---|
| 1532 | | - &eld->eld_size) < 0) |
|---|
| 1668 | + if (spec->ops.pin_get_eld(codec, pin_nid, dev_id, |
|---|
| 1669 | + eld->eld_buffer, &eld->eld_size) < 0) |
|---|
| 1533 | 1670 | eld->eld_valid = false; |
|---|
| 1534 | | - else { |
|---|
| 1535 | | - if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer, |
|---|
| 1536 | | - eld->eld_size) < 0) |
|---|
| 1537 | | - eld->eld_valid = false; |
|---|
| 1538 | | - } |
|---|
| 1539 | | - if (!eld->eld_valid && repoll) |
|---|
| 1540 | | - do_repoll = true; |
|---|
| 1541 | 1671 | } |
|---|
| 1542 | 1672 | |
|---|
| 1543 | | - if (do_repoll) |
|---|
| 1544 | | - schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300)); |
|---|
| 1545 | | - else |
|---|
| 1546 | | - update_eld(codec, per_pin, eld); |
|---|
| 1547 | | - |
|---|
| 1548 | | - ret = !repoll || !eld->monitor_present || eld->eld_valid; |
|---|
| 1549 | | - |
|---|
| 1550 | | - jack = snd_hda_jack_tbl_get(codec, pin_nid); |
|---|
| 1551 | | - if (jack) { |
|---|
| 1552 | | - jack->block_report = !ret; |
|---|
| 1553 | | - jack->pin_sense = (eld->monitor_present && eld->eld_valid) ? |
|---|
| 1554 | | - AC_PINSENSE_PRESENCE : 0; |
|---|
| 1555 | | - } |
|---|
| 1673 | + update_eld(codec, per_pin, eld, repoll); |
|---|
| 1556 | 1674 | mutex_unlock(&per_pin->lock); |
|---|
| 1557 | | - return ret; |
|---|
| 1675 | + out: |
|---|
| 1676 | + snd_hda_power_down_pm(codec); |
|---|
| 1558 | 1677 | } |
|---|
| 1559 | 1678 | |
|---|
| 1560 | | -static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec, |
|---|
| 1679 | +#define I915_SILENT_RATE 48000 |
|---|
| 1680 | +#define I915_SILENT_CHANNELS 2 |
|---|
| 1681 | +#define I915_SILENT_FORMAT SNDRV_PCM_FORMAT_S16_LE |
|---|
| 1682 | +#define I915_SILENT_FORMAT_BITS 16 |
|---|
| 1683 | +#define I915_SILENT_FMT_MASK 0xf |
|---|
| 1684 | + |
|---|
| 1685 | +static void silent_stream_enable(struct hda_codec *codec, |
|---|
| 1561 | 1686 | struct hdmi_spec_per_pin *per_pin) |
|---|
| 1562 | 1687 | { |
|---|
| 1563 | 1688 | struct hdmi_spec *spec = codec->spec; |
|---|
| 1564 | | - struct snd_jack *jack = NULL; |
|---|
| 1565 | | - struct hda_jack_tbl *jack_tbl; |
|---|
| 1689 | + struct hdmi_spec_per_cvt *per_cvt; |
|---|
| 1690 | + int cvt_idx, pin_idx, err; |
|---|
| 1691 | + unsigned int format; |
|---|
| 1566 | 1692 | |
|---|
| 1567 | | - /* if !dyn_pcm_assign, get jack from hda_jack_tbl |
|---|
| 1568 | | - * in !dyn_pcm_assign case, spec->pcm_rec[].jack is not |
|---|
| 1569 | | - * NULL even after snd_hda_jack_tbl_clear() is called to |
|---|
| 1570 | | - * free snd_jack. This may cause access invalid memory |
|---|
| 1571 | | - * when calling snd_jack_report |
|---|
| 1572 | | - */ |
|---|
| 1573 | | - if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign) |
|---|
| 1574 | | - jack = spec->pcm_rec[per_pin->pcm_idx].jack; |
|---|
| 1575 | | - else if (!spec->dyn_pcm_assign) { |
|---|
| 1576 | | - /* |
|---|
| 1577 | | - * jack tbl doesn't support DP MST |
|---|
| 1578 | | - * DP MST will use dyn_pcm_assign, |
|---|
| 1579 | | - * so DP MST will never come here |
|---|
| 1580 | | - */ |
|---|
| 1581 | | - jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid); |
|---|
| 1582 | | - if (jack_tbl) |
|---|
| 1583 | | - jack = jack_tbl->jack; |
|---|
| 1693 | + mutex_lock(&per_pin->lock); |
|---|
| 1694 | + |
|---|
| 1695 | + if (per_pin->setup) { |
|---|
| 1696 | + codec_dbg(codec, "hdmi: PCM already open, no silent stream\n"); |
|---|
| 1697 | + goto unlock_out; |
|---|
| 1584 | 1698 | } |
|---|
| 1585 | | - return jack; |
|---|
| 1699 | + |
|---|
| 1700 | + pin_idx = pin_id_to_pin_index(codec, per_pin->pin_nid, per_pin->dev_id); |
|---|
| 1701 | + err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx); |
|---|
| 1702 | + if (err) { |
|---|
| 1703 | + codec_err(codec, "hdmi: no free converter to enable silent mode\n"); |
|---|
| 1704 | + goto unlock_out; |
|---|
| 1705 | + } |
|---|
| 1706 | + |
|---|
| 1707 | + per_cvt = get_cvt(spec, cvt_idx); |
|---|
| 1708 | + per_cvt->assigned = 1; |
|---|
| 1709 | + per_pin->cvt_nid = per_cvt->cvt_nid; |
|---|
| 1710 | + per_pin->silent_stream = true; |
|---|
| 1711 | + |
|---|
| 1712 | + codec_dbg(codec, "hdmi: enabling silent stream pin-NID=0x%x cvt-NID=0x%x\n", |
|---|
| 1713 | + per_pin->pin_nid, per_cvt->cvt_nid); |
|---|
| 1714 | + |
|---|
| 1715 | + snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id); |
|---|
| 1716 | + snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, |
|---|
| 1717 | + AC_VERB_SET_CONNECT_SEL, |
|---|
| 1718 | + per_pin->mux_idx); |
|---|
| 1719 | + |
|---|
| 1720 | + /* configure unused pins to choose other converters */ |
|---|
| 1721 | + pin_cvt_fixup(codec, per_pin, 0); |
|---|
| 1722 | + |
|---|
| 1723 | + snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid, |
|---|
| 1724 | + per_pin->dev_id, I915_SILENT_RATE); |
|---|
| 1725 | + |
|---|
| 1726 | + /* trigger silent stream generation in hw */ |
|---|
| 1727 | + format = snd_hdac_calc_stream_format(I915_SILENT_RATE, I915_SILENT_CHANNELS, |
|---|
| 1728 | + I915_SILENT_FORMAT, I915_SILENT_FORMAT_BITS, 0); |
|---|
| 1729 | + snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, |
|---|
| 1730 | + I915_SILENT_FMT_MASK, I915_SILENT_FMT_MASK, format); |
|---|
| 1731 | + usleep_range(100, 200); |
|---|
| 1732 | + snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, I915_SILENT_FMT_MASK, 0, format); |
|---|
| 1733 | + |
|---|
| 1734 | + per_pin->channels = I915_SILENT_CHANNELS; |
|---|
| 1735 | + hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); |
|---|
| 1736 | + |
|---|
| 1737 | + unlock_out: |
|---|
| 1738 | + mutex_unlock(&per_pin->lock); |
|---|
| 1739 | +} |
|---|
| 1740 | + |
|---|
| 1741 | +static void silent_stream_disable(struct hda_codec *codec, |
|---|
| 1742 | + struct hdmi_spec_per_pin *per_pin) |
|---|
| 1743 | +{ |
|---|
| 1744 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 1745 | + struct hdmi_spec_per_cvt *per_cvt; |
|---|
| 1746 | + int cvt_idx; |
|---|
| 1747 | + |
|---|
| 1748 | + mutex_lock(&per_pin->lock); |
|---|
| 1749 | + if (!per_pin->silent_stream) |
|---|
| 1750 | + goto unlock_out; |
|---|
| 1751 | + |
|---|
| 1752 | + codec_dbg(codec, "HDMI: disable silent stream on pin-NID=0x%x cvt-NID=0x%x\n", |
|---|
| 1753 | + per_pin->pin_nid, per_pin->cvt_nid); |
|---|
| 1754 | + |
|---|
| 1755 | + cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid); |
|---|
| 1756 | + if (cvt_idx >= 0 && cvt_idx < spec->num_cvts) { |
|---|
| 1757 | + per_cvt = get_cvt(spec, cvt_idx); |
|---|
| 1758 | + per_cvt->assigned = 0; |
|---|
| 1759 | + } |
|---|
| 1760 | + |
|---|
| 1761 | + per_pin->cvt_nid = 0; |
|---|
| 1762 | + per_pin->silent_stream = false; |
|---|
| 1763 | + |
|---|
| 1764 | + unlock_out: |
|---|
| 1765 | + mutex_unlock(&per_pin->lock); |
|---|
| 1586 | 1766 | } |
|---|
| 1587 | 1767 | |
|---|
| 1588 | 1768 | /* update ELD and jack state via audio component */ |
|---|
| .. | .. |
|---|
| 1591 | 1771 | { |
|---|
| 1592 | 1772 | struct hdmi_spec *spec = codec->spec; |
|---|
| 1593 | 1773 | struct hdmi_eld *eld = &spec->temp_eld; |
|---|
| 1594 | | - struct snd_jack *jack = NULL; |
|---|
| 1595 | | - int size; |
|---|
| 1774 | + bool monitor_prev, monitor_next; |
|---|
| 1596 | 1775 | |
|---|
| 1597 | 1776 | mutex_lock(&per_pin->lock); |
|---|
| 1598 | 1777 | eld->monitor_present = false; |
|---|
| 1599 | | - size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, |
|---|
| 1778 | + monitor_prev = per_pin->sink_eld.monitor_present; |
|---|
| 1779 | + eld->eld_size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, |
|---|
| 1600 | 1780 | per_pin->dev_id, &eld->monitor_present, |
|---|
| 1601 | 1781 | eld->eld_buffer, ELD_MAX_SIZE); |
|---|
| 1602 | | - if (size > 0) { |
|---|
| 1603 | | - size = min(size, ELD_MAX_SIZE); |
|---|
| 1604 | | - if (snd_hdmi_parse_eld(codec, &eld->info, |
|---|
| 1605 | | - eld->eld_buffer, size) < 0) |
|---|
| 1606 | | - size = -EINVAL; |
|---|
| 1607 | | - } |
|---|
| 1608 | | - |
|---|
| 1609 | | - if (size > 0) { |
|---|
| 1610 | | - eld->eld_valid = true; |
|---|
| 1611 | | - eld->eld_size = size; |
|---|
| 1612 | | - } else { |
|---|
| 1613 | | - eld->eld_valid = false; |
|---|
| 1614 | | - eld->eld_size = 0; |
|---|
| 1615 | | - } |
|---|
| 1616 | | - |
|---|
| 1617 | | - /* pcm_idx >=0 before update_eld() means it is in monitor |
|---|
| 1618 | | - * disconnected event. Jack must be fetched before update_eld() |
|---|
| 1619 | | - */ |
|---|
| 1620 | | - jack = pin_idx_to_jack(codec, per_pin); |
|---|
| 1621 | | - update_eld(codec, per_pin, eld); |
|---|
| 1622 | | - if (jack == NULL) |
|---|
| 1623 | | - jack = pin_idx_to_jack(codec, per_pin); |
|---|
| 1624 | | - if (jack == NULL) |
|---|
| 1625 | | - goto unlock; |
|---|
| 1626 | | - snd_jack_report(jack, |
|---|
| 1627 | | - eld->monitor_present ? SND_JACK_AVOUT : 0); |
|---|
| 1628 | | - unlock: |
|---|
| 1782 | + eld->eld_valid = (eld->eld_size > 0); |
|---|
| 1783 | + update_eld(codec, per_pin, eld, 0); |
|---|
| 1784 | + monitor_next = per_pin->sink_eld.monitor_present; |
|---|
| 1629 | 1785 | mutex_unlock(&per_pin->lock); |
|---|
| 1630 | | -} |
|---|
| 1631 | 1786 | |
|---|
| 1632 | | -static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) |
|---|
| 1633 | | -{ |
|---|
| 1634 | | - struct hda_codec *codec = per_pin->codec; |
|---|
| 1635 | | - int ret; |
|---|
| 1787 | + /* |
|---|
| 1788 | + * Power-up will call hdmi_present_sense, so the PM calls |
|---|
| 1789 | + * have to be done without mutex held. |
|---|
| 1790 | + */ |
|---|
| 1636 | 1791 | |
|---|
| 1637 | | - /* no temporary power up/down needed for component notifier */ |
|---|
| 1638 | | - if (!codec_has_acomp(codec)) { |
|---|
| 1639 | | - ret = snd_hda_power_up_pm(codec); |
|---|
| 1640 | | - if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) { |
|---|
| 1641 | | - snd_hda_power_down_pm(codec); |
|---|
| 1642 | | - return false; |
|---|
| 1792 | + if (spec->send_silent_stream) { |
|---|
| 1793 | + int pm_ret; |
|---|
| 1794 | + |
|---|
| 1795 | + if (!monitor_prev && monitor_next) { |
|---|
| 1796 | + pm_ret = snd_hda_power_up_pm(codec); |
|---|
| 1797 | + if (pm_ret < 0) |
|---|
| 1798 | + codec_err(codec, |
|---|
| 1799 | + "Monitor plugged-in, Failed to power up codec ret=[%d]\n", |
|---|
| 1800 | + pm_ret); |
|---|
| 1801 | + silent_stream_enable(codec, per_pin); |
|---|
| 1802 | + } else if (monitor_prev && !monitor_next) { |
|---|
| 1803 | + silent_stream_disable(codec, per_pin); |
|---|
| 1804 | + pm_ret = snd_hda_power_down_pm(codec); |
|---|
| 1805 | + if (pm_ret < 0) |
|---|
| 1806 | + codec_err(codec, |
|---|
| 1807 | + "Monitor plugged-out, Failed to power down codec ret=[%d]\n", |
|---|
| 1808 | + pm_ret); |
|---|
| 1643 | 1809 | } |
|---|
| 1644 | 1810 | } |
|---|
| 1811 | +} |
|---|
| 1645 | 1812 | |
|---|
| 1646 | | - if (codec_has_acomp(codec)) { |
|---|
| 1647 | | - sync_eld_via_acomp(codec, per_pin); |
|---|
| 1648 | | - ret = false; /* don't call snd_hda_jack_report_sync() */ |
|---|
| 1649 | | - } else { |
|---|
| 1650 | | - ret = hdmi_present_sense_via_verbs(per_pin, repoll); |
|---|
| 1651 | | - } |
|---|
| 1813 | +static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) |
|---|
| 1814 | +{ |
|---|
| 1815 | + struct hda_codec *codec = per_pin->codec; |
|---|
| 1652 | 1816 | |
|---|
| 1653 | 1817 | if (!codec_has_acomp(codec)) |
|---|
| 1654 | | - snd_hda_power_down_pm(codec); |
|---|
| 1655 | | - |
|---|
| 1656 | | - return ret; |
|---|
| 1818 | + hdmi_present_sense_via_verbs(per_pin, repoll); |
|---|
| 1819 | + else |
|---|
| 1820 | + sync_eld_via_acomp(codec, per_pin); |
|---|
| 1657 | 1821 | } |
|---|
| 1658 | 1822 | |
|---|
| 1659 | 1823 | static void hdmi_repoll_eld(struct work_struct *work) |
|---|
| .. | .. |
|---|
| 1664 | 1828 | struct hdmi_spec *spec = codec->spec; |
|---|
| 1665 | 1829 | struct hda_jack_tbl *jack; |
|---|
| 1666 | 1830 | |
|---|
| 1667 | | - jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid); |
|---|
| 1831 | + jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid, |
|---|
| 1832 | + per_pin->dev_id); |
|---|
| 1668 | 1833 | if (jack) |
|---|
| 1669 | 1834 | jack->jack_dirty = 1; |
|---|
| 1670 | 1835 | |
|---|
| .. | .. |
|---|
| 1672 | 1837 | per_pin->repoll_count = 0; |
|---|
| 1673 | 1838 | |
|---|
| 1674 | 1839 | mutex_lock(&spec->pcm_lock); |
|---|
| 1675 | | - if (hdmi_present_sense(per_pin, per_pin->repoll_count)) |
|---|
| 1676 | | - snd_hda_jack_report_sync(per_pin->codec); |
|---|
| 1840 | + hdmi_present_sense(per_pin, per_pin->repoll_count); |
|---|
| 1677 | 1841 | mutex_unlock(&spec->pcm_lock); |
|---|
| 1678 | 1842 | } |
|---|
| 1679 | | - |
|---|
| 1680 | | -static void intel_haswell_fixup_connect_list(struct hda_codec *codec, |
|---|
| 1681 | | - hda_nid_t nid); |
|---|
| 1682 | 1843 | |
|---|
| 1683 | 1844 | static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) |
|---|
| 1684 | 1845 | { |
|---|
| .. | .. |
|---|
| 1698 | 1859 | * all device entries on the same pin |
|---|
| 1699 | 1860 | */ |
|---|
| 1700 | 1861 | config = snd_hda_codec_get_pincfg(codec, pin_nid); |
|---|
| 1701 | | - if (get_defcfg_connect(config) == AC_JACK_PORT_NONE) |
|---|
| 1862 | + if (get_defcfg_connect(config) == AC_JACK_PORT_NONE && |
|---|
| 1863 | + !spec->force_connect) |
|---|
| 1702 | 1864 | return 0; |
|---|
| 1703 | 1865 | |
|---|
| 1704 | 1866 | /* |
|---|
| 1705 | 1867 | * To simplify the implementation, malloc all |
|---|
| 1706 | 1868 | * the virtual pins in the initialization statically |
|---|
| 1707 | 1869 | */ |
|---|
| 1708 | | - if (is_haswell_plus(codec)) { |
|---|
| 1870 | + if (spec->intel_hsw_fixup) { |
|---|
| 1709 | 1871 | /* |
|---|
| 1710 | 1872 | * On Intel platforms, device entries number is |
|---|
| 1711 | 1873 | * changed dynamically. If there is a DP MST |
|---|
| .. | .. |
|---|
| 1754 | 1916 | per_pin->dev_id = i; |
|---|
| 1755 | 1917 | per_pin->non_pcm = false; |
|---|
| 1756 | 1918 | snd_hda_set_dev_select(codec, pin_nid, i); |
|---|
| 1757 | | - if (is_haswell_plus(codec)) |
|---|
| 1758 | | - intel_haswell_fixup_connect_list(codec, pin_nid); |
|---|
| 1759 | 1919 | err = hdmi_read_pin_conn(codec, pin_idx); |
|---|
| 1760 | 1920 | if (err < 0) |
|---|
| 1761 | 1921 | return err; |
|---|
| .. | .. |
|---|
| 1802 | 1962 | return 0; |
|---|
| 1803 | 1963 | } |
|---|
| 1804 | 1964 | |
|---|
| 1965 | +static const struct snd_pci_quirk force_connect_list[] = { |
|---|
| 1966 | + SND_PCI_QUIRK(0x103c, 0x870f, "HP", 1), |
|---|
| 1967 | + SND_PCI_QUIRK(0x103c, 0x871a, "HP", 1), |
|---|
| 1968 | + SND_PCI_QUIRK(0x103c, 0x8711, "HP", 1), |
|---|
| 1969 | + SND_PCI_QUIRK(0x103c, 0x8715, "HP", 1), |
|---|
| 1970 | + SND_PCI_QUIRK(0x1462, 0xec94, "MS-7C94", 1), |
|---|
| 1971 | + {} |
|---|
| 1972 | +}; |
|---|
| 1973 | + |
|---|
| 1805 | 1974 | static int hdmi_parse_codec(struct hda_codec *codec) |
|---|
| 1806 | 1975 | { |
|---|
| 1807 | | - hda_nid_t nid; |
|---|
| 1976 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 1977 | + hda_nid_t start_nid; |
|---|
| 1978 | + unsigned int caps; |
|---|
| 1808 | 1979 | int i, nodes; |
|---|
| 1980 | + const struct snd_pci_quirk *q; |
|---|
| 1809 | 1981 | |
|---|
| 1810 | | - nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid); |
|---|
| 1811 | | - if (!nid || nodes < 0) { |
|---|
| 1982 | + nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &start_nid); |
|---|
| 1983 | + if (!start_nid || nodes < 0) { |
|---|
| 1812 | 1984 | codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); |
|---|
| 1813 | 1985 | return -EINVAL; |
|---|
| 1814 | 1986 | } |
|---|
| 1815 | 1987 | |
|---|
| 1816 | | - for (i = 0; i < nodes; i++, nid++) { |
|---|
| 1817 | | - unsigned int caps; |
|---|
| 1818 | | - unsigned int type; |
|---|
| 1988 | + q = snd_pci_quirk_lookup(codec->bus->pci, force_connect_list); |
|---|
| 1989 | + |
|---|
| 1990 | + if (q && q->value) |
|---|
| 1991 | + spec->force_connect = true; |
|---|
| 1992 | + |
|---|
| 1993 | + /* |
|---|
| 1994 | + * hdmi_add_pin() assumes total amount of converters to |
|---|
| 1995 | + * be known, so first discover all converters |
|---|
| 1996 | + */ |
|---|
| 1997 | + for (i = 0; i < nodes; i++) { |
|---|
| 1998 | + hda_nid_t nid = start_nid + i; |
|---|
| 1819 | 1999 | |
|---|
| 1820 | 2000 | caps = get_wcaps(codec, nid); |
|---|
| 1821 | | - type = get_wcaps_type(caps); |
|---|
| 1822 | 2001 | |
|---|
| 1823 | 2002 | if (!(caps & AC_WCAP_DIGITAL)) |
|---|
| 1824 | 2003 | continue; |
|---|
| 1825 | 2004 | |
|---|
| 1826 | | - switch (type) { |
|---|
| 1827 | | - case AC_WID_AUD_OUT: |
|---|
| 2005 | + if (get_wcaps_type(caps) == AC_WID_AUD_OUT) |
|---|
| 1828 | 2006 | hdmi_add_cvt(codec, nid); |
|---|
| 1829 | | - break; |
|---|
| 1830 | | - case AC_WID_PIN: |
|---|
| 2007 | + } |
|---|
| 2008 | + |
|---|
| 2009 | + /* discover audio pins */ |
|---|
| 2010 | + for (i = 0; i < nodes; i++) { |
|---|
| 2011 | + hda_nid_t nid = start_nid + i; |
|---|
| 2012 | + |
|---|
| 2013 | + caps = get_wcaps(codec, nid); |
|---|
| 2014 | + |
|---|
| 2015 | + if (!(caps & AC_WCAP_DIGITAL)) |
|---|
| 2016 | + continue; |
|---|
| 2017 | + |
|---|
| 2018 | + if (get_wcaps_type(caps) == AC_WID_PIN) |
|---|
| 1831 | 2019 | hdmi_add_pin(codec, nid); |
|---|
| 1832 | | - break; |
|---|
| 1833 | | - } |
|---|
| 1834 | 2020 | } |
|---|
| 1835 | 2021 | |
|---|
| 1836 | 2022 | return 0; |
|---|
| .. | .. |
|---|
| 1871 | 2057 | struct hdmi_spec *spec = codec->spec; |
|---|
| 1872 | 2058 | int pin_idx; |
|---|
| 1873 | 2059 | struct hdmi_spec_per_pin *per_pin; |
|---|
| 1874 | | - hda_nid_t pin_nid; |
|---|
| 1875 | 2060 | struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| 1876 | 2061 | bool non_pcm; |
|---|
| 1877 | | - int pinctl; |
|---|
| 2062 | + int pinctl, stripe; |
|---|
| 1878 | 2063 | int err = 0; |
|---|
| 1879 | 2064 | |
|---|
| 1880 | 2065 | mutex_lock(&spec->pcm_lock); |
|---|
| .. | .. |
|---|
| 1895 | 2080 | goto unlock; |
|---|
| 1896 | 2081 | } |
|---|
| 1897 | 2082 | per_pin = get_pin(spec, pin_idx); |
|---|
| 1898 | | - pin_nid = per_pin->pin_nid; |
|---|
| 1899 | 2083 | |
|---|
| 1900 | 2084 | /* Verify pin:cvt selections to avoid silent audio after S3. |
|---|
| 1901 | 2085 | * After S3, the audio driver restores pin:cvt selections |
|---|
| .. | .. |
|---|
| 1910 | 2094 | /* Call sync_audio_rate to set the N/CTS/M manually if necessary */ |
|---|
| 1911 | 2095 | /* Todo: add DP1.2 MST audio support later */ |
|---|
| 1912 | 2096 | if (codec_has_acomp(codec)) |
|---|
| 1913 | | - snd_hdac_sync_audio_rate(&codec->core, pin_nid, per_pin->dev_id, |
|---|
| 1914 | | - runtime->rate); |
|---|
| 2097 | + snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid, |
|---|
| 2098 | + per_pin->dev_id, runtime->rate); |
|---|
| 1915 | 2099 | |
|---|
| 1916 | 2100 | non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); |
|---|
| 1917 | 2101 | mutex_lock(&per_pin->lock); |
|---|
| 1918 | 2102 | per_pin->channels = substream->runtime->channels; |
|---|
| 1919 | 2103 | per_pin->setup = true; |
|---|
| 1920 | 2104 | |
|---|
| 2105 | + if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) { |
|---|
| 2106 | + stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core, |
|---|
| 2107 | + substream); |
|---|
| 2108 | + snd_hda_codec_write(codec, cvt_nid, 0, |
|---|
| 2109 | + AC_VERB_SET_STRIPE_CONTROL, |
|---|
| 2110 | + stripe); |
|---|
| 2111 | + } |
|---|
| 2112 | + |
|---|
| 1921 | 2113 | hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); |
|---|
| 1922 | 2114 | mutex_unlock(&per_pin->lock); |
|---|
| 1923 | 2115 | if (spec->dyn_pin_out) { |
|---|
| 1924 | | - pinctl = snd_hda_codec_read(codec, pin_nid, 0, |
|---|
| 2116 | + snd_hda_set_dev_select(codec, per_pin->pin_nid, |
|---|
| 2117 | + per_pin->dev_id); |
|---|
| 2118 | + pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0, |
|---|
| 1925 | 2119 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
|---|
| 1926 | | - snd_hda_codec_write(codec, pin_nid, 0, |
|---|
| 2120 | + snd_hda_codec_write(codec, per_pin->pin_nid, 0, |
|---|
| 1927 | 2121 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
|---|
| 1928 | 2122 | pinctl | PIN_OUT); |
|---|
| 1929 | 2123 | } |
|---|
| 1930 | 2124 | |
|---|
| 1931 | 2125 | /* snd_hda_set_dev_select() has been called before */ |
|---|
| 1932 | | - err = spec->ops.setup_stream(codec, cvt_nid, pin_nid, |
|---|
| 1933 | | - stream_tag, format); |
|---|
| 2126 | + err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid, |
|---|
| 2127 | + per_pin->dev_id, stream_tag, format); |
|---|
| 1934 | 2128 | unlock: |
|---|
| 1935 | 2129 | mutex_unlock(&spec->pcm_lock); |
|---|
| 1936 | 2130 | return err; |
|---|
| .. | .. |
|---|
| 1968 | 2162 | goto unlock; |
|---|
| 1969 | 2163 | } |
|---|
| 1970 | 2164 | per_cvt = get_cvt(spec, cvt_idx); |
|---|
| 1971 | | - snd_BUG_ON(!per_cvt->assigned); |
|---|
| 1972 | 2165 | per_cvt->assigned = 0; |
|---|
| 1973 | 2166 | hinfo->nid = 0; |
|---|
| 2167 | + |
|---|
| 2168 | + azx_stream(get_azx_dev(substream))->stripe = 0; |
|---|
| 1974 | 2169 | |
|---|
| 1975 | 2170 | snd_hda_spdif_ctls_unassign(codec, pcm_idx); |
|---|
| 1976 | 2171 | clear_bit(pcm_idx, &spec->pcm_in_use); |
|---|
| .. | .. |
|---|
| 1985 | 2180 | per_pin = get_pin(spec, pin_idx); |
|---|
| 1986 | 2181 | |
|---|
| 1987 | 2182 | if (spec->dyn_pin_out) { |
|---|
| 2183 | + snd_hda_set_dev_select(codec, per_pin->pin_nid, |
|---|
| 2184 | + per_pin->dev_id); |
|---|
| 1988 | 2185 | pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0, |
|---|
| 1989 | 2186 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
|---|
| 1990 | 2187 | snd_hda_codec_write(codec, per_pin->pin_nid, 0, |
|---|
| .. | .. |
|---|
| 2016 | 2213 | |
|---|
| 2017 | 2214 | static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx) |
|---|
| 2018 | 2215 | { |
|---|
| 2019 | | - struct hda_codec *codec = container_of(hdac, struct hda_codec, core); |
|---|
| 2216 | + struct hda_codec *codec = hdac_to_hda_codec(hdac); |
|---|
| 2020 | 2217 | struct hdmi_spec *spec = codec->spec; |
|---|
| 2021 | 2218 | struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); |
|---|
| 2022 | 2219 | |
|---|
| .. | .. |
|---|
| 2029 | 2226 | static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx, |
|---|
| 2030 | 2227 | unsigned char *chmap) |
|---|
| 2031 | 2228 | { |
|---|
| 2032 | | - struct hda_codec *codec = container_of(hdac, struct hda_codec, core); |
|---|
| 2229 | + struct hda_codec *codec = hdac_to_hda_codec(hdac); |
|---|
| 2033 | 2230 | struct hdmi_spec *spec = codec->spec; |
|---|
| 2034 | 2231 | struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); |
|---|
| 2035 | 2232 | |
|---|
| .. | .. |
|---|
| 2043 | 2240 | static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx, |
|---|
| 2044 | 2241 | unsigned char *chmap, int prepared) |
|---|
| 2045 | 2242 | { |
|---|
| 2046 | | - struct hda_codec *codec = container_of(hdac, struct hda_codec, core); |
|---|
| 2243 | + struct hda_codec *codec = hdac_to_hda_codec(hdac); |
|---|
| 2047 | 2244 | struct hdmi_spec *spec = codec->spec; |
|---|
| 2048 | 2245 | struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); |
|---|
| 2049 | 2246 | |
|---|
| .. | .. |
|---|
| 2059 | 2256 | |
|---|
| 2060 | 2257 | static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx) |
|---|
| 2061 | 2258 | { |
|---|
| 2062 | | - struct hda_codec *codec = container_of(hdac, struct hda_codec, core); |
|---|
| 2259 | + struct hda_codec *codec = hdac_to_hda_codec(hdac); |
|---|
| 2063 | 2260 | struct hdmi_spec *spec = codec->spec; |
|---|
| 2064 | 2261 | struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); |
|---|
| 2065 | 2262 | |
|---|
| .. | .. |
|---|
| 2069 | 2266 | static int generic_hdmi_build_pcms(struct hda_codec *codec) |
|---|
| 2070 | 2267 | { |
|---|
| 2071 | 2268 | struct hdmi_spec *spec = codec->spec; |
|---|
| 2072 | | - int idx; |
|---|
| 2269 | + int idx, pcm_num; |
|---|
| 2073 | 2270 | |
|---|
| 2074 | 2271 | /* |
|---|
| 2075 | 2272 | * for non-mst mode, pcm number is the same as before |
|---|
| 2076 | | - * for DP MST mode, pcm number is (nid number + dev_num - 1) |
|---|
| 2077 | | - * dev_num is the device entry number in a pin |
|---|
| 2078 | | - * |
|---|
| 2273 | + * for DP MST mode without extra PCM, pcm number is same |
|---|
| 2274 | + * for DP MST mode with extra PCMs, pcm number is |
|---|
| 2275 | + * (nid number + dev_num - 1) |
|---|
| 2276 | + * dev_num is the device entry number in a pin |
|---|
| 2079 | 2277 | */ |
|---|
| 2080 | | - for (idx = 0; idx < spec->num_nids + spec->dev_num - 1; idx++) { |
|---|
| 2278 | + |
|---|
| 2279 | + if (spec->dyn_pcm_no_legacy && codec->mst_no_extra_pcms) |
|---|
| 2280 | + pcm_num = spec->num_cvts; |
|---|
| 2281 | + else if (codec->mst_no_extra_pcms) |
|---|
| 2282 | + pcm_num = spec->num_nids; |
|---|
| 2283 | + else |
|---|
| 2284 | + pcm_num = spec->num_nids + spec->dev_num - 1; |
|---|
| 2285 | + |
|---|
| 2286 | + codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num); |
|---|
| 2287 | + |
|---|
| 2288 | + for (idx = 0; idx < pcm_num; idx++) { |
|---|
| 2081 | 2289 | struct hda_pcm *info; |
|---|
| 2082 | 2290 | struct hda_pcm_stream *pstr; |
|---|
| 2083 | 2291 | |
|---|
| .. | .. |
|---|
| 2109 | 2317 | pcm->jack = NULL; |
|---|
| 2110 | 2318 | } |
|---|
| 2111 | 2319 | |
|---|
| 2112 | | -static int add_hdmi_jack_kctl(struct hda_codec *codec, |
|---|
| 2113 | | - struct hdmi_spec *spec, |
|---|
| 2114 | | - int pcm_idx, |
|---|
| 2115 | | - const char *name) |
|---|
| 2320 | +static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx) |
|---|
| 2116 | 2321 | { |
|---|
| 2322 | + char hdmi_str[32] = "HDMI/DP"; |
|---|
| 2323 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 2324 | + struct hdmi_spec_per_pin *per_pin = get_pin(spec, pcm_idx); |
|---|
| 2117 | 2325 | struct snd_jack *jack; |
|---|
| 2326 | + int pcmdev = get_pcm_rec(spec, pcm_idx)->device; |
|---|
| 2118 | 2327 | int err; |
|---|
| 2119 | 2328 | |
|---|
| 2120 | | - err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack, |
|---|
| 2329 | + if (pcmdev > 0) |
|---|
| 2330 | + sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev); |
|---|
| 2331 | + if (!spec->dyn_pcm_assign && |
|---|
| 2332 | + !is_jack_detectable(codec, per_pin->pin_nid)) |
|---|
| 2333 | + strncat(hdmi_str, " Phantom", |
|---|
| 2334 | + sizeof(hdmi_str) - strlen(hdmi_str) - 1); |
|---|
| 2335 | + |
|---|
| 2336 | + err = snd_jack_new(codec->card, hdmi_str, SND_JACK_AVOUT, &jack, |
|---|
| 2121 | 2337 | true, false); |
|---|
| 2122 | 2338 | if (err < 0) |
|---|
| 2123 | 2339 | return err; |
|---|
| .. | .. |
|---|
| 2125 | 2341 | spec->pcm_rec[pcm_idx].jack = jack; |
|---|
| 2126 | 2342 | jack->private_data = &spec->pcm_rec[pcm_idx]; |
|---|
| 2127 | 2343 | jack->private_free = free_hdmi_jack_priv; |
|---|
| 2128 | | - return 0; |
|---|
| 2129 | | -} |
|---|
| 2130 | | - |
|---|
| 2131 | | -static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx) |
|---|
| 2132 | | -{ |
|---|
| 2133 | | - char hdmi_str[32] = "HDMI/DP"; |
|---|
| 2134 | | - struct hdmi_spec *spec = codec->spec; |
|---|
| 2135 | | - struct hdmi_spec_per_pin *per_pin; |
|---|
| 2136 | | - struct hda_jack_tbl *jack; |
|---|
| 2137 | | - int pcmdev = get_pcm_rec(spec, pcm_idx)->device; |
|---|
| 2138 | | - bool phantom_jack; |
|---|
| 2139 | | - int ret; |
|---|
| 2140 | | - |
|---|
| 2141 | | - if (pcmdev > 0) |
|---|
| 2142 | | - sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev); |
|---|
| 2143 | | - |
|---|
| 2144 | | - if (spec->dyn_pcm_assign) |
|---|
| 2145 | | - return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str); |
|---|
| 2146 | | - |
|---|
| 2147 | | - /* for !dyn_pcm_assign, we still use hda_jack for compatibility */ |
|---|
| 2148 | | - /* if !dyn_pcm_assign, it must be non-MST mode. |
|---|
| 2149 | | - * This means pcms and pins are statically mapped. |
|---|
| 2150 | | - * And pcm_idx is pin_idx. |
|---|
| 2151 | | - */ |
|---|
| 2152 | | - per_pin = get_pin(spec, pcm_idx); |
|---|
| 2153 | | - phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid); |
|---|
| 2154 | | - if (phantom_jack) |
|---|
| 2155 | | - strncat(hdmi_str, " Phantom", |
|---|
| 2156 | | - sizeof(hdmi_str) - strlen(hdmi_str) - 1); |
|---|
| 2157 | | - ret = snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, |
|---|
| 2158 | | - phantom_jack); |
|---|
| 2159 | | - if (ret < 0) |
|---|
| 2160 | | - return ret; |
|---|
| 2161 | | - jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid); |
|---|
| 2162 | | - if (jack == NULL) |
|---|
| 2163 | | - return 0; |
|---|
| 2164 | | - /* assign jack->jack to pcm_rec[].jack to |
|---|
| 2165 | | - * align with dyn_pcm_assign mode |
|---|
| 2166 | | - */ |
|---|
| 2167 | | - spec->pcm_rec[pcm_idx].jack = jack->jack; |
|---|
| 2168 | 2344 | return 0; |
|---|
| 2169 | 2345 | } |
|---|
| 2170 | 2346 | |
|---|
| .. | .. |
|---|
| 2257 | 2433 | struct hdmi_spec *spec = codec->spec; |
|---|
| 2258 | 2434 | int pin_idx; |
|---|
| 2259 | 2435 | |
|---|
| 2436 | + mutex_lock(&spec->bind_lock); |
|---|
| 2260 | 2437 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
|---|
| 2261 | 2438 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
|---|
| 2262 | 2439 | hda_nid_t pin_nid = per_pin->pin_nid; |
|---|
| .. | .. |
|---|
| 2264 | 2441 | |
|---|
| 2265 | 2442 | snd_hda_set_dev_select(codec, pin_nid, dev_id); |
|---|
| 2266 | 2443 | hdmi_init_pin(codec, pin_nid); |
|---|
| 2267 | | - if (!codec_has_acomp(codec)) |
|---|
| 2268 | | - snd_hda_jack_detect_enable_callback(codec, pin_nid, |
|---|
| 2269 | | - codec->jackpoll_interval > 0 ? |
|---|
| 2270 | | - jack_callback : NULL); |
|---|
| 2444 | + if (codec_has_acomp(codec)) |
|---|
| 2445 | + continue; |
|---|
| 2446 | + snd_hda_jack_detect_enable_callback_mst(codec, pin_nid, dev_id, |
|---|
| 2447 | + jack_callback); |
|---|
| 2271 | 2448 | } |
|---|
| 2449 | + mutex_unlock(&spec->bind_lock); |
|---|
| 2272 | 2450 | return 0; |
|---|
| 2273 | 2451 | } |
|---|
| 2274 | 2452 | |
|---|
| .. | .. |
|---|
| 2301 | 2479 | struct hdmi_spec *spec = codec->spec; |
|---|
| 2302 | 2480 | int pin_idx, pcm_idx; |
|---|
| 2303 | 2481 | |
|---|
| 2304 | | - if (codec_has_acomp(codec)) { |
|---|
| 2482 | + if (spec->acomp_registered) { |
|---|
| 2483 | + snd_hdac_acomp_exit(&codec->bus->core); |
|---|
| 2484 | + } else if (codec_has_acomp(codec)) { |
|---|
| 2305 | 2485 | snd_hdac_acomp_register_notifier(&codec->bus->core, NULL); |
|---|
| 2306 | | - codec->relaxed_resume = 0; |
|---|
| 2307 | 2486 | } |
|---|
| 2487 | + codec->relaxed_resume = 0; |
|---|
| 2308 | 2488 | |
|---|
| 2309 | 2489 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
|---|
| 2310 | 2490 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
|---|
| .. | .. |
|---|
| 2344 | 2524 | int pin_idx; |
|---|
| 2345 | 2525 | |
|---|
| 2346 | 2526 | codec->patch_ops.init(codec); |
|---|
| 2347 | | - regcache_sync(codec->core.regmap); |
|---|
| 2527 | + snd_hda_regmap_sync(codec); |
|---|
| 2348 | 2528 | |
|---|
| 2349 | 2529 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
|---|
| 2350 | 2530 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
|---|
| .. | .. |
|---|
| 2367 | 2547 | }; |
|---|
| 2368 | 2548 | |
|---|
| 2369 | 2549 | static const struct hdmi_ops generic_standard_hdmi_ops = { |
|---|
| 2370 | | - .pin_get_eld = snd_hdmi_get_eld, |
|---|
| 2550 | + .pin_get_eld = hdmi_pin_get_eld, |
|---|
| 2371 | 2551 | .pin_setup_infoframe = hdmi_pin_setup_infoframe, |
|---|
| 2372 | 2552 | .pin_hbr_setup = hdmi_pin_hbr_setup, |
|---|
| 2373 | 2553 | .setup_stream = hdmi_setup_stream, |
|---|
| .. | .. |
|---|
| 2382 | 2562 | if (!spec) |
|---|
| 2383 | 2563 | return -ENOMEM; |
|---|
| 2384 | 2564 | |
|---|
| 2565 | + spec->codec = codec; |
|---|
| 2385 | 2566 | spec->ops = generic_standard_hdmi_ops; |
|---|
| 2386 | 2567 | spec->dev_num = 1; /* initialize to 1 */ |
|---|
| 2387 | 2568 | mutex_init(&spec->pcm_lock); |
|---|
| 2569 | + mutex_init(&spec->bind_lock); |
|---|
| 2388 | 2570 | snd_hdac_register_chmap_ops(&codec->core, &spec->chmap); |
|---|
| 2389 | 2571 | |
|---|
| 2390 | 2572 | spec->chmap.ops.get_chmap = hdmi_get_chmap; |
|---|
| 2391 | 2573 | spec->chmap.ops.set_chmap = hdmi_set_chmap; |
|---|
| 2392 | 2574 | spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached; |
|---|
| 2393 | | - spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc, |
|---|
| 2575 | + spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc; |
|---|
| 2394 | 2576 | |
|---|
| 2395 | 2577 | codec->spec = spec; |
|---|
| 2396 | 2578 | hdmi_array_init(spec, 4); |
|---|
| .. | .. |
|---|
| 2420 | 2602 | } |
|---|
| 2421 | 2603 | |
|---|
| 2422 | 2604 | /* |
|---|
| 2605 | + * generic audio component binding |
|---|
| 2606 | + */ |
|---|
| 2607 | + |
|---|
| 2608 | +/* turn on / off the unsol event jack detection dynamically */ |
|---|
| 2609 | +static void reprogram_jack_detect(struct hda_codec *codec, hda_nid_t nid, |
|---|
| 2610 | + int dev_id, bool use_acomp) |
|---|
| 2611 | +{ |
|---|
| 2612 | + struct hda_jack_tbl *tbl; |
|---|
| 2613 | + |
|---|
| 2614 | + tbl = snd_hda_jack_tbl_get_mst(codec, nid, dev_id); |
|---|
| 2615 | + if (tbl) { |
|---|
| 2616 | + /* clear unsol even if component notifier is used, or re-enable |
|---|
| 2617 | + * if notifier is cleared |
|---|
| 2618 | + */ |
|---|
| 2619 | + unsigned int val = use_acomp ? 0 : (AC_USRSP_EN | tbl->tag); |
|---|
| 2620 | + snd_hda_codec_write_cache(codec, nid, 0, |
|---|
| 2621 | + AC_VERB_SET_UNSOLICITED_ENABLE, val); |
|---|
| 2622 | + } |
|---|
| 2623 | +} |
|---|
| 2624 | + |
|---|
| 2625 | +/* set up / clear component notifier dynamically */ |
|---|
| 2626 | +static void generic_acomp_notifier_set(struct drm_audio_component *acomp, |
|---|
| 2627 | + bool use_acomp) |
|---|
| 2628 | +{ |
|---|
| 2629 | + struct hdmi_spec *spec; |
|---|
| 2630 | + int i; |
|---|
| 2631 | + |
|---|
| 2632 | + spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops); |
|---|
| 2633 | + mutex_lock(&spec->bind_lock); |
|---|
| 2634 | + spec->use_acomp_notifier = use_acomp; |
|---|
| 2635 | + spec->codec->relaxed_resume = use_acomp; |
|---|
| 2636 | + spec->codec->bus->keep_power = 0; |
|---|
| 2637 | + /* reprogram each jack detection logic depending on the notifier */ |
|---|
| 2638 | + for (i = 0; i < spec->num_pins; i++) |
|---|
| 2639 | + reprogram_jack_detect(spec->codec, |
|---|
| 2640 | + get_pin(spec, i)->pin_nid, |
|---|
| 2641 | + get_pin(spec, i)->dev_id, |
|---|
| 2642 | + use_acomp); |
|---|
| 2643 | + mutex_unlock(&spec->bind_lock); |
|---|
| 2644 | +} |
|---|
| 2645 | + |
|---|
| 2646 | +/* enable / disable the notifier via master bind / unbind */ |
|---|
| 2647 | +static int generic_acomp_master_bind(struct device *dev, |
|---|
| 2648 | + struct drm_audio_component *acomp) |
|---|
| 2649 | +{ |
|---|
| 2650 | + generic_acomp_notifier_set(acomp, true); |
|---|
| 2651 | + return 0; |
|---|
| 2652 | +} |
|---|
| 2653 | + |
|---|
| 2654 | +static void generic_acomp_master_unbind(struct device *dev, |
|---|
| 2655 | + struct drm_audio_component *acomp) |
|---|
| 2656 | +{ |
|---|
| 2657 | + generic_acomp_notifier_set(acomp, false); |
|---|
| 2658 | +} |
|---|
| 2659 | + |
|---|
| 2660 | +/* check whether both HD-audio and DRM PCI devices belong to the same bus */ |
|---|
| 2661 | +static int match_bound_vga(struct device *dev, int subtype, void *data) |
|---|
| 2662 | +{ |
|---|
| 2663 | + struct hdac_bus *bus = data; |
|---|
| 2664 | + struct pci_dev *pci, *master; |
|---|
| 2665 | + |
|---|
| 2666 | + if (!dev_is_pci(dev) || !dev_is_pci(bus->dev)) |
|---|
| 2667 | + return 0; |
|---|
| 2668 | + master = to_pci_dev(bus->dev); |
|---|
| 2669 | + pci = to_pci_dev(dev); |
|---|
| 2670 | + return master->bus == pci->bus; |
|---|
| 2671 | +} |
|---|
| 2672 | + |
|---|
| 2673 | +/* audio component notifier for AMD/Nvidia HDMI codecs */ |
|---|
| 2674 | +static void generic_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id) |
|---|
| 2675 | +{ |
|---|
| 2676 | + struct hda_codec *codec = audio_ptr; |
|---|
| 2677 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 2678 | + hda_nid_t pin_nid = spec->port2pin(codec, port); |
|---|
| 2679 | + |
|---|
| 2680 | + if (!pin_nid) |
|---|
| 2681 | + return; |
|---|
| 2682 | + if (get_wcaps_type(get_wcaps(codec, pin_nid)) != AC_WID_PIN) |
|---|
| 2683 | + return; |
|---|
| 2684 | + /* skip notification during system suspend (but not in runtime PM); |
|---|
| 2685 | + * the state will be updated at resume |
|---|
| 2686 | + */ |
|---|
| 2687 | + if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND) |
|---|
| 2688 | + return; |
|---|
| 2689 | + |
|---|
| 2690 | + check_presence_and_report(codec, pin_nid, dev_id); |
|---|
| 2691 | +} |
|---|
| 2692 | + |
|---|
| 2693 | +/* set up the private drm_audio_ops from the template */ |
|---|
| 2694 | +static void setup_drm_audio_ops(struct hda_codec *codec, |
|---|
| 2695 | + const struct drm_audio_component_audio_ops *ops) |
|---|
| 2696 | +{ |
|---|
| 2697 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 2698 | + |
|---|
| 2699 | + spec->drm_audio_ops.audio_ptr = codec; |
|---|
| 2700 | + /* intel_audio_codec_enable() or intel_audio_codec_disable() |
|---|
| 2701 | + * will call pin_eld_notify with using audio_ptr pointer |
|---|
| 2702 | + * We need make sure audio_ptr is really setup |
|---|
| 2703 | + */ |
|---|
| 2704 | + wmb(); |
|---|
| 2705 | + spec->drm_audio_ops.pin2port = ops->pin2port; |
|---|
| 2706 | + spec->drm_audio_ops.pin_eld_notify = ops->pin_eld_notify; |
|---|
| 2707 | + spec->drm_audio_ops.master_bind = ops->master_bind; |
|---|
| 2708 | + spec->drm_audio_ops.master_unbind = ops->master_unbind; |
|---|
| 2709 | +} |
|---|
| 2710 | + |
|---|
| 2711 | +/* initialize the generic HDMI audio component */ |
|---|
| 2712 | +static void generic_acomp_init(struct hda_codec *codec, |
|---|
| 2713 | + const struct drm_audio_component_audio_ops *ops, |
|---|
| 2714 | + int (*port2pin)(struct hda_codec *, int)) |
|---|
| 2715 | +{ |
|---|
| 2716 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 2717 | + |
|---|
| 2718 | + if (!enable_acomp) { |
|---|
| 2719 | + codec_info(codec, "audio component disabled by module option\n"); |
|---|
| 2720 | + return; |
|---|
| 2721 | + } |
|---|
| 2722 | + |
|---|
| 2723 | + spec->port2pin = port2pin; |
|---|
| 2724 | + setup_drm_audio_ops(codec, ops); |
|---|
| 2725 | + if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops, |
|---|
| 2726 | + match_bound_vga, 0)) { |
|---|
| 2727 | + spec->acomp_registered = true; |
|---|
| 2728 | + } |
|---|
| 2729 | +} |
|---|
| 2730 | + |
|---|
| 2731 | +/* |
|---|
| 2423 | 2732 | * Intel codec parsers and helpers |
|---|
| 2424 | 2733 | */ |
|---|
| 2425 | 2734 | |
|---|
| 2426 | | -static void intel_haswell_fixup_connect_list(struct hda_codec *codec, |
|---|
| 2427 | | - hda_nid_t nid) |
|---|
| 2428 | | -{ |
|---|
| 2429 | | - struct hdmi_spec *spec = codec->spec; |
|---|
| 2430 | | - hda_nid_t conns[4]; |
|---|
| 2431 | | - int nconns; |
|---|
| 2432 | | - |
|---|
| 2433 | | - nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns)); |
|---|
| 2434 | | - if (nconns == spec->num_cvts && |
|---|
| 2435 | | - !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t))) |
|---|
| 2436 | | - return; |
|---|
| 2437 | | - |
|---|
| 2438 | | - /* override pins connection list */ |
|---|
| 2439 | | - codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid); |
|---|
| 2440 | | - snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids); |
|---|
| 2441 | | -} |
|---|
| 2442 | | - |
|---|
| 2443 | | -#define INTEL_VENDOR_NID 0x08 |
|---|
| 2444 | | -#define INTEL_GLK_VENDOR_NID 0x0B |
|---|
| 2445 | | -#define INTEL_GET_VENDOR_VERB 0xf81 |
|---|
| 2446 | | -#define INTEL_SET_VENDOR_VERB 0x781 |
|---|
| 2447 | | -#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */ |
|---|
| 2448 | | -#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */ |
|---|
| 2735 | +#define INTEL_GET_VENDOR_VERB 0xf81 |
|---|
| 2736 | +#define INTEL_SET_VENDOR_VERB 0x781 |
|---|
| 2737 | +#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */ |
|---|
| 2738 | +#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */ |
|---|
| 2449 | 2739 | |
|---|
| 2450 | 2740 | static void intel_haswell_enable_all_pins(struct hda_codec *codec, |
|---|
| 2451 | 2741 | bool update_tree) |
|---|
| .. | .. |
|---|
| 2525 | 2815 | |
|---|
| 2526 | 2816 | static int intel_pin2port(void *audio_ptr, int pin_nid) |
|---|
| 2527 | 2817 | { |
|---|
| 2528 | | - int base_nid = intel_base_nid(audio_ptr); |
|---|
| 2818 | + struct hda_codec *codec = audio_ptr; |
|---|
| 2819 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 2820 | + int base_nid, i; |
|---|
| 2529 | 2821 | |
|---|
| 2530 | | - if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3)) |
|---|
| 2531 | | - return -1; |
|---|
| 2532 | | - return pin_nid - base_nid + 1; /* intel port is 1-based */ |
|---|
| 2822 | + if (!spec->port_num) { |
|---|
| 2823 | + base_nid = intel_base_nid(codec); |
|---|
| 2824 | + if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3)) |
|---|
| 2825 | + return -1; |
|---|
| 2826 | + return pin_nid - base_nid + 1; |
|---|
| 2827 | + } |
|---|
| 2828 | + |
|---|
| 2829 | + /* |
|---|
| 2830 | + * looking for the pin number in the mapping table and return |
|---|
| 2831 | + * the index which indicate the port number |
|---|
| 2832 | + */ |
|---|
| 2833 | + for (i = 0; i < spec->port_num; i++) { |
|---|
| 2834 | + if (pin_nid == spec->port_map[i]) |
|---|
| 2835 | + return i; |
|---|
| 2836 | + } |
|---|
| 2837 | + |
|---|
| 2838 | + codec_info(codec, "Can't find the HDMI/DP port for pin %d\n", pin_nid); |
|---|
| 2839 | + return -1; |
|---|
| 2840 | +} |
|---|
| 2841 | + |
|---|
| 2842 | +static int intel_port2pin(struct hda_codec *codec, int port) |
|---|
| 2843 | +{ |
|---|
| 2844 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 2845 | + |
|---|
| 2846 | + if (!spec->port_num) { |
|---|
| 2847 | + /* we assume only from port-B to port-D */ |
|---|
| 2848 | + if (port < 1 || port > 3) |
|---|
| 2849 | + return 0; |
|---|
| 2850 | + return port + intel_base_nid(codec) - 1; |
|---|
| 2851 | + } |
|---|
| 2852 | + |
|---|
| 2853 | + if (port < 0 || port >= spec->port_num) |
|---|
| 2854 | + return 0; |
|---|
| 2855 | + return spec->port_map[port]; |
|---|
| 2533 | 2856 | } |
|---|
| 2534 | 2857 | |
|---|
| 2535 | 2858 | static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe) |
|---|
| .. | .. |
|---|
| 2538 | 2861 | int pin_nid; |
|---|
| 2539 | 2862 | int dev_id = pipe; |
|---|
| 2540 | 2863 | |
|---|
| 2541 | | - /* we assume only from port-B to port-D */ |
|---|
| 2542 | | - if (port < 1 || port > 3) |
|---|
| 2864 | + pin_nid = intel_port2pin(codec, port); |
|---|
| 2865 | + if (!pin_nid) |
|---|
| 2543 | 2866 | return; |
|---|
| 2544 | | - |
|---|
| 2545 | | - pin_nid = port + intel_base_nid(codec) - 1; /* intel port is 1-based */ |
|---|
| 2546 | | - |
|---|
| 2547 | 2867 | /* skip notification during system suspend (but not in runtime PM); |
|---|
| 2548 | 2868 | * the state will be updated at resume |
|---|
| 2549 | 2869 | */ |
|---|
| 2550 | | - if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0) |
|---|
| 2551 | | - return; |
|---|
| 2552 | | - /* ditto during suspend/resume process itself */ |
|---|
| 2553 | | - if (snd_hdac_is_in_pm(&codec->core)) |
|---|
| 2870 | + if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND) |
|---|
| 2554 | 2871 | return; |
|---|
| 2555 | 2872 | |
|---|
| 2556 | 2873 | snd_hdac_i915_set_bclk(&codec->bus->core); |
|---|
| 2557 | 2874 | check_presence_and_report(codec, pin_nid, dev_id); |
|---|
| 2558 | 2875 | } |
|---|
| 2876 | + |
|---|
| 2877 | +static const struct drm_audio_component_audio_ops intel_audio_ops = { |
|---|
| 2878 | + .pin2port = intel_pin2port, |
|---|
| 2879 | + .pin_eld_notify = intel_pin_eld_notify, |
|---|
| 2880 | +}; |
|---|
| 2559 | 2881 | |
|---|
| 2560 | 2882 | /* register i915 component pin_eld_notify callback */ |
|---|
| 2561 | 2883 | static void register_i915_notifier(struct hda_codec *codec) |
|---|
| .. | .. |
|---|
| 2563 | 2885 | struct hdmi_spec *spec = codec->spec; |
|---|
| 2564 | 2886 | |
|---|
| 2565 | 2887 | spec->use_acomp_notifier = true; |
|---|
| 2566 | | - spec->drm_audio_ops.audio_ptr = codec; |
|---|
| 2567 | | - /* intel_audio_codec_enable() or intel_audio_codec_disable() |
|---|
| 2568 | | - * will call pin_eld_notify with using audio_ptr pointer |
|---|
| 2569 | | - * We need make sure audio_ptr is really setup |
|---|
| 2570 | | - */ |
|---|
| 2571 | | - wmb(); |
|---|
| 2572 | | - spec->drm_audio_ops.pin2port = intel_pin2port; |
|---|
| 2573 | | - spec->drm_audio_ops.pin_eld_notify = intel_pin_eld_notify; |
|---|
| 2888 | + spec->port2pin = intel_port2pin; |
|---|
| 2889 | + setup_drm_audio_ops(codec, &intel_audio_ops); |
|---|
| 2574 | 2890 | snd_hdac_acomp_register_notifier(&codec->bus->core, |
|---|
| 2575 | 2891 | &spec->drm_audio_ops); |
|---|
| 2576 | 2892 | /* no need for forcible resume for jack check thanks to notifier */ |
|---|
| .. | .. |
|---|
| 2579 | 2895 | |
|---|
| 2580 | 2896 | /* setup_stream ops override for HSW+ */ |
|---|
| 2581 | 2897 | static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, |
|---|
| 2582 | | - hda_nid_t pin_nid, u32 stream_tag, int format) |
|---|
| 2898 | + hda_nid_t pin_nid, int dev_id, u32 stream_tag, |
|---|
| 2899 | + int format) |
|---|
| 2583 | 2900 | { |
|---|
| 2584 | 2901 | haswell_verify_D0(codec, cvt_nid, pin_nid); |
|---|
| 2585 | | - return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); |
|---|
| 2902 | + return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id, |
|---|
| 2903 | + stream_tag, format); |
|---|
| 2586 | 2904 | } |
|---|
| 2587 | 2905 | |
|---|
| 2588 | 2906 | /* pin_cvt_fixup ops override for HSW+ and VLV+ */ |
|---|
| .. | .. |
|---|
| 2643 | 2961 | } |
|---|
| 2644 | 2962 | |
|---|
| 2645 | 2963 | /* Intel Haswell and onwards; audio component with eld notifier */ |
|---|
| 2646 | | -static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid) |
|---|
| 2964 | +static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid, |
|---|
| 2965 | + const int *port_map, int port_num) |
|---|
| 2647 | 2966 | { |
|---|
| 2648 | 2967 | struct hdmi_spec *spec; |
|---|
| 2649 | 2968 | int err; |
|---|
| .. | .. |
|---|
| 2655 | 2974 | codec->dp_mst = true; |
|---|
| 2656 | 2975 | spec->dyn_pcm_assign = true; |
|---|
| 2657 | 2976 | spec->vendor_nid = vendor_nid; |
|---|
| 2977 | + spec->port_map = port_map; |
|---|
| 2978 | + spec->port_num = port_num; |
|---|
| 2979 | + spec->intel_hsw_fixup = true; |
|---|
| 2658 | 2980 | |
|---|
| 2659 | 2981 | intel_haswell_enable_all_pins(codec, true); |
|---|
| 2660 | 2982 | intel_haswell_fixup_enable_dp12(codec); |
|---|
| 2661 | 2983 | |
|---|
| 2662 | | - /* For Haswell/Broadwell, the controller is also in the power well and |
|---|
| 2663 | | - * can cover the codec power request, and so need not set this flag. |
|---|
| 2664 | | - */ |
|---|
| 2665 | | - if (!is_haswell(codec) && !is_broadwell(codec)) |
|---|
| 2666 | | - codec->core.link_power_control = 1; |
|---|
| 2984 | + codec->display_power_control = 1; |
|---|
| 2667 | 2985 | |
|---|
| 2668 | 2986 | codec->patch_ops.set_power_state = haswell_set_power_state; |
|---|
| 2669 | 2987 | codec->depop_delay = 0; |
|---|
| .. | .. |
|---|
| 2672 | 2990 | spec->ops.setup_stream = i915_hsw_setup_stream; |
|---|
| 2673 | 2991 | spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup; |
|---|
| 2674 | 2992 | |
|---|
| 2993 | + /* |
|---|
| 2994 | + * Enable silent stream feature, if it is enabled via |
|---|
| 2995 | + * module param or Kconfig option |
|---|
| 2996 | + */ |
|---|
| 2997 | + if (enable_silent_stream) |
|---|
| 2998 | + spec->send_silent_stream = true; |
|---|
| 2999 | + |
|---|
| 2675 | 3000 | return parse_intel_hdmi(codec); |
|---|
| 2676 | 3001 | } |
|---|
| 2677 | 3002 | |
|---|
| 2678 | 3003 | static int patch_i915_hsw_hdmi(struct hda_codec *codec) |
|---|
| 2679 | 3004 | { |
|---|
| 2680 | | - return intel_hsw_common_init(codec, INTEL_VENDOR_NID); |
|---|
| 3005 | + return intel_hsw_common_init(codec, 0x08, NULL, 0); |
|---|
| 2681 | 3006 | } |
|---|
| 2682 | 3007 | |
|---|
| 2683 | 3008 | static int patch_i915_glk_hdmi(struct hda_codec *codec) |
|---|
| 2684 | 3009 | { |
|---|
| 2685 | | - return intel_hsw_common_init(codec, INTEL_GLK_VENDOR_NID); |
|---|
| 3010 | + return intel_hsw_common_init(codec, 0x0b, NULL, 0); |
|---|
| 3011 | +} |
|---|
| 3012 | + |
|---|
| 3013 | +static int patch_i915_icl_hdmi(struct hda_codec *codec) |
|---|
| 3014 | +{ |
|---|
| 3015 | + /* |
|---|
| 3016 | + * pin to port mapping table where the value indicate the pin number and |
|---|
| 3017 | + * the index indicate the port number. |
|---|
| 3018 | + */ |
|---|
| 3019 | + static const int map[] = {0x0, 0x4, 0x6, 0x8, 0xa, 0xb}; |
|---|
| 3020 | + |
|---|
| 3021 | + return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map)); |
|---|
| 3022 | +} |
|---|
| 3023 | + |
|---|
| 3024 | +static int patch_i915_tgl_hdmi(struct hda_codec *codec) |
|---|
| 3025 | +{ |
|---|
| 3026 | + /* |
|---|
| 3027 | + * pin to port mapping table where the value indicate the pin number and |
|---|
| 3028 | + * the index indicate the port number. |
|---|
| 3029 | + */ |
|---|
| 3030 | + static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}; |
|---|
| 3031 | + int ret; |
|---|
| 3032 | + |
|---|
| 3033 | + ret = intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map)); |
|---|
| 3034 | + if (!ret) { |
|---|
| 3035 | + struct hdmi_spec *spec = codec->spec; |
|---|
| 3036 | + |
|---|
| 3037 | + spec->dyn_pcm_no_legacy = true; |
|---|
| 3038 | + } |
|---|
| 3039 | + |
|---|
| 3040 | + return ret; |
|---|
| 2686 | 3041 | } |
|---|
| 2687 | 3042 | |
|---|
| 2688 | 3043 | /* Intel Baytrail and Braswell; with eld notifier */ |
|---|
| .. | .. |
|---|
| 2699 | 3054 | /* For Valleyview/Cherryview, only the display codec is in the display |
|---|
| 2700 | 3055 | * power well and can use link_power ops to request/release the power. |
|---|
| 2701 | 3056 | */ |
|---|
| 2702 | | - codec->core.link_power_control = 1; |
|---|
| 3057 | + codec->display_power_control = 1; |
|---|
| 2703 | 3058 | |
|---|
| 2704 | 3059 | codec->depop_delay = 0; |
|---|
| 2705 | 3060 | codec->auto_runtime_pm = 1; |
|---|
| .. | .. |
|---|
| 2790 | 3145 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) |
|---|
| 2791 | 3146 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
|---|
| 2792 | 3147 | AMP_OUT_UNMUTE); |
|---|
| 2793 | | - snd_hda_jack_detect_enable(codec, pin); |
|---|
| 3148 | + snd_hda_jack_detect_enable(codec, pin, per_pin->dev_id); |
|---|
| 2794 | 3149 | return 0; |
|---|
| 2795 | 3150 | } |
|---|
| 2796 | 3151 | |
|---|
| .. | .. |
|---|
| 2969 | 3324 | if (!spec) |
|---|
| 2970 | 3325 | return -ENOMEM; |
|---|
| 2971 | 3326 | |
|---|
| 3327 | + spec->codec = codec; |
|---|
| 2972 | 3328 | codec->spec = spec; |
|---|
| 2973 | 3329 | hdmi_array_init(spec, 1); |
|---|
| 2974 | 3330 | |
|---|
| .. | .. |
|---|
| 3180 | 3536 | spec->pcm_playback.rates = SUPPORTED_RATES; |
|---|
| 3181 | 3537 | spec->pcm_playback.maxbps = SUPPORTED_MAXBPS; |
|---|
| 3182 | 3538 | spec->pcm_playback.formats = SUPPORTED_FORMATS; |
|---|
| 3539 | + spec->nv_dp_workaround = true; |
|---|
| 3183 | 3540 | return 0; |
|---|
| 3184 | 3541 | } |
|---|
| 3185 | 3542 | |
|---|
| .. | .. |
|---|
| 3273 | 3630 | return 0; |
|---|
| 3274 | 3631 | } |
|---|
| 3275 | 3632 | |
|---|
| 3633 | +/* map from pin NID to port; port is 0-based */ |
|---|
| 3634 | +/* for Nvidia: assume widget NID starting from 4, with step 1 (4, 5, 6, ...) */ |
|---|
| 3635 | +static int nvhdmi_pin2port(void *audio_ptr, int pin_nid) |
|---|
| 3636 | +{ |
|---|
| 3637 | + return pin_nid - 4; |
|---|
| 3638 | +} |
|---|
| 3639 | + |
|---|
| 3640 | +/* reverse-map from port to pin NID: see above */ |
|---|
| 3641 | +static int nvhdmi_port2pin(struct hda_codec *codec, int port) |
|---|
| 3642 | +{ |
|---|
| 3643 | + return port + 4; |
|---|
| 3644 | +} |
|---|
| 3645 | + |
|---|
| 3646 | +static const struct drm_audio_component_audio_ops nvhdmi_audio_ops = { |
|---|
| 3647 | + .pin2port = nvhdmi_pin2port, |
|---|
| 3648 | + .pin_eld_notify = generic_acomp_pin_eld_notify, |
|---|
| 3649 | + .master_bind = generic_acomp_master_bind, |
|---|
| 3650 | + .master_unbind = generic_acomp_master_unbind, |
|---|
| 3651 | +}; |
|---|
| 3652 | + |
|---|
| 3276 | 3653 | static int patch_nvhdmi(struct hda_codec *codec) |
|---|
| 3654 | +{ |
|---|
| 3655 | + struct hdmi_spec *spec; |
|---|
| 3656 | + int err; |
|---|
| 3657 | + |
|---|
| 3658 | + err = alloc_generic_hdmi(codec); |
|---|
| 3659 | + if (err < 0) |
|---|
| 3660 | + return err; |
|---|
| 3661 | + codec->dp_mst = true; |
|---|
| 3662 | + |
|---|
| 3663 | + spec = codec->spec; |
|---|
| 3664 | + spec->dyn_pcm_assign = true; |
|---|
| 3665 | + |
|---|
| 3666 | + err = hdmi_parse_codec(codec); |
|---|
| 3667 | + if (err < 0) { |
|---|
| 3668 | + generic_spec_free(codec); |
|---|
| 3669 | + return err; |
|---|
| 3670 | + } |
|---|
| 3671 | + |
|---|
| 3672 | + generic_hdmi_init_per_pins(codec); |
|---|
| 3673 | + |
|---|
| 3674 | + spec->dyn_pin_out = true; |
|---|
| 3675 | + |
|---|
| 3676 | + spec->chmap.ops.chmap_cea_alloc_validate_get_type = |
|---|
| 3677 | + nvhdmi_chmap_cea_alloc_validate_get_type; |
|---|
| 3678 | + spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate; |
|---|
| 3679 | + spec->nv_dp_workaround = true; |
|---|
| 3680 | + |
|---|
| 3681 | + codec->link_down_at_suspend = 1; |
|---|
| 3682 | + |
|---|
| 3683 | + generic_acomp_init(codec, &nvhdmi_audio_ops, nvhdmi_port2pin); |
|---|
| 3684 | + |
|---|
| 3685 | + return 0; |
|---|
| 3686 | +} |
|---|
| 3687 | + |
|---|
| 3688 | +static int patch_nvhdmi_legacy(struct hda_codec *codec) |
|---|
| 3277 | 3689 | { |
|---|
| 3278 | 3690 | struct hdmi_spec *spec; |
|---|
| 3279 | 3691 | int err; |
|---|
| .. | .. |
|---|
| 3288 | 3700 | spec->chmap.ops.chmap_cea_alloc_validate_get_type = |
|---|
| 3289 | 3701 | nvhdmi_chmap_cea_alloc_validate_get_type; |
|---|
| 3290 | 3702 | spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate; |
|---|
| 3703 | + spec->nv_dp_workaround = true; |
|---|
| 3291 | 3704 | |
|---|
| 3292 | 3705 | codec->link_down_at_suspend = 1; |
|---|
| 3293 | 3706 | |
|---|
| .. | .. |
|---|
| 3455 | 3868 | if (err) |
|---|
| 3456 | 3869 | return err; |
|---|
| 3457 | 3870 | |
|---|
| 3871 | + codec->depop_delay = 10; |
|---|
| 3458 | 3872 | codec->patch_ops.build_pcms = tegra_hdmi_build_pcms; |
|---|
| 3459 | 3873 | spec = codec->spec; |
|---|
| 3460 | 3874 | spec->chmap.ops.chmap_cea_alloc_validate_get_type = |
|---|
| 3461 | 3875 | nvhdmi_chmap_cea_alloc_validate_get_type; |
|---|
| 3462 | 3876 | spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate; |
|---|
| 3877 | + spec->nv_dp_workaround = true; |
|---|
| 3463 | 3878 | |
|---|
| 3464 | 3879 | return 0; |
|---|
| 3465 | 3880 | } |
|---|
| .. | .. |
|---|
| 3512 | 3927 | #define ATI_HBR_ENABLE 0x10 |
|---|
| 3513 | 3928 | |
|---|
| 3514 | 3929 | static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid, |
|---|
| 3515 | | - unsigned char *buf, int *eld_size) |
|---|
| 3930 | + int dev_id, unsigned char *buf, int *eld_size) |
|---|
| 3516 | 3931 | { |
|---|
| 3932 | + WARN_ON(dev_id != 0); |
|---|
| 3517 | 3933 | /* call hda_eld.c ATI/AMD-specific function */ |
|---|
| 3518 | 3934 | return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size, |
|---|
| 3519 | 3935 | is_amdhdmi_rev3_or_later(codec)); |
|---|
| 3520 | 3936 | } |
|---|
| 3521 | 3937 | |
|---|
| 3522 | | -static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca, |
|---|
| 3938 | +static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, |
|---|
| 3939 | + hda_nid_t pin_nid, int dev_id, int ca, |
|---|
| 3523 | 3940 | int active_channels, int conn_type) |
|---|
| 3524 | 3941 | { |
|---|
| 3942 | + WARN_ON(dev_id != 0); |
|---|
| 3525 | 3943 | snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca); |
|---|
| 3526 | 3944 | } |
|---|
| 3527 | 3945 | |
|---|
| .. | .. |
|---|
| 3593 | 4011 | static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac, |
|---|
| 3594 | 4012 | hda_nid_t pin_nid, int hdmi_slot, int stream_channel) |
|---|
| 3595 | 4013 | { |
|---|
| 3596 | | - struct hda_codec *codec = container_of(hdac, struct hda_codec, core); |
|---|
| 4014 | + struct hda_codec *codec = hdac_to_hda_codec(hdac); |
|---|
| 3597 | 4015 | int verb; |
|---|
| 3598 | 4016 | int ati_channel_setup = 0; |
|---|
| 3599 | 4017 | |
|---|
| .. | .. |
|---|
| 3629 | 4047 | static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac, |
|---|
| 3630 | 4048 | hda_nid_t pin_nid, int asp_slot) |
|---|
| 3631 | 4049 | { |
|---|
| 3632 | | - struct hda_codec *codec = container_of(hdac, struct hda_codec, core); |
|---|
| 4050 | + struct hda_codec *codec = hdac_to_hda_codec(hdac); |
|---|
| 3633 | 4051 | bool was_odd = false; |
|---|
| 3634 | 4052 | int ati_asp_slot = asp_slot; |
|---|
| 3635 | 4053 | int verb; |
|---|
| .. | .. |
|---|
| 3712 | 4130 | } |
|---|
| 3713 | 4131 | |
|---|
| 3714 | 4132 | static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid, |
|---|
| 3715 | | - bool hbr) |
|---|
| 4133 | + int dev_id, bool hbr) |
|---|
| 3716 | 4134 | { |
|---|
| 3717 | 4135 | int hbr_ctl, hbr_ctl_new; |
|---|
| 4136 | + |
|---|
| 4137 | + WARN_ON(dev_id != 0); |
|---|
| 3718 | 4138 | |
|---|
| 3719 | 4139 | hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0); |
|---|
| 3720 | 4140 | if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) { |
|---|
| .. | .. |
|---|
| 3741 | 4161 | } |
|---|
| 3742 | 4162 | |
|---|
| 3743 | 4163 | static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, |
|---|
| 3744 | | - hda_nid_t pin_nid, u32 stream_tag, int format) |
|---|
| 4164 | + hda_nid_t pin_nid, int dev_id, |
|---|
| 4165 | + u32 stream_tag, int format) |
|---|
| 3745 | 4166 | { |
|---|
| 3746 | | - |
|---|
| 3747 | 4167 | if (is_amdhdmi_rev3_or_later(codec)) { |
|---|
| 3748 | 4168 | int ramp_rate = 180; /* default as per AMD spec */ |
|---|
| 3749 | 4169 | /* disable ramp-up/down for non-pcm as per AMD spec */ |
|---|
| .. | .. |
|---|
| 3753 | 4173 | snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate); |
|---|
| 3754 | 4174 | } |
|---|
| 3755 | 4175 | |
|---|
| 3756 | | - return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); |
|---|
| 4176 | + return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id, |
|---|
| 4177 | + stream_tag, format); |
|---|
| 3757 | 4178 | } |
|---|
| 3758 | 4179 | |
|---|
| 3759 | 4180 | |
|---|
| .. | .. |
|---|
| 3779 | 4200 | ATI_VERB_SET_MULTICHANNEL_MODE, |
|---|
| 3780 | 4201 | ATI_MULTICHANNEL_MODE_SINGLE); |
|---|
| 3781 | 4202 | } |
|---|
| 4203 | + codec->auto_runtime_pm = 1; |
|---|
| 3782 | 4204 | |
|---|
| 3783 | 4205 | return 0; |
|---|
| 3784 | 4206 | } |
|---|
| 4207 | + |
|---|
| 4208 | +/* map from pin NID to port; port is 0-based */ |
|---|
| 4209 | +/* for AMD: assume widget NID starting from 3, with step 2 (3, 5, 7, ...) */ |
|---|
| 4210 | +static int atihdmi_pin2port(void *audio_ptr, int pin_nid) |
|---|
| 4211 | +{ |
|---|
| 4212 | + return pin_nid / 2 - 1; |
|---|
| 4213 | +} |
|---|
| 4214 | + |
|---|
| 4215 | +/* reverse-map from port to pin NID: see above */ |
|---|
| 4216 | +static int atihdmi_port2pin(struct hda_codec *codec, int port) |
|---|
| 4217 | +{ |
|---|
| 4218 | + return port * 2 + 3; |
|---|
| 4219 | +} |
|---|
| 4220 | + |
|---|
| 4221 | +static const struct drm_audio_component_audio_ops atihdmi_audio_ops = { |
|---|
| 4222 | + .pin2port = atihdmi_pin2port, |
|---|
| 4223 | + .pin_eld_notify = generic_acomp_pin_eld_notify, |
|---|
| 4224 | + .master_bind = generic_acomp_master_bind, |
|---|
| 4225 | + .master_unbind = generic_acomp_master_unbind, |
|---|
| 4226 | +}; |
|---|
| 3785 | 4227 | |
|---|
| 3786 | 4228 | static int patch_atihdmi(struct hda_codec *codec) |
|---|
| 3787 | 4229 | { |
|---|
| .. | .. |
|---|
| 3831 | 4273 | */ |
|---|
| 3832 | 4274 | codec->link_down_at_suspend = 1; |
|---|
| 3833 | 4275 | |
|---|
| 4276 | + generic_acomp_init(codec, &atihdmi_audio_ops, atihdmi_port2pin); |
|---|
| 4277 | + |
|---|
| 3834 | 4278 | return 0; |
|---|
| 3835 | 4279 | } |
|---|
| 3836 | 4280 | |
|---|
| .. | .. |
|---|
| 3841 | 4285 | static int patch_via_hdmi(struct hda_codec *codec) |
|---|
| 3842 | 4286 | { |
|---|
| 3843 | 4287 | return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID); |
|---|
| 4288 | +} |
|---|
| 4289 | + |
|---|
| 4290 | +static int patch_gf_hdmi(struct hda_codec *codec) |
|---|
| 4291 | +{ |
|---|
| 4292 | + int err; |
|---|
| 4293 | + |
|---|
| 4294 | + err = patch_generic_hdmi(codec); |
|---|
| 4295 | + if (err) |
|---|
| 4296 | + return err; |
|---|
| 4297 | + |
|---|
| 4298 | + /* |
|---|
| 4299 | + * Glenfly GPUs have two codecs, stream switches from one codec to |
|---|
| 4300 | + * another, need to do actual clean-ups in codec_cleanup_stream |
|---|
| 4301 | + */ |
|---|
| 4302 | + codec->no_sticky_stream = 1; |
|---|
| 4303 | + return 0; |
|---|
| 3844 | 4304 | } |
|---|
| 3845 | 4305 | |
|---|
| 3846 | 4306 | /* |
|---|
| .. | .. |
|---|
| 3861 | 4321 | HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x), |
|---|
| 3862 | 4322 | HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x), |
|---|
| 3863 | 4323 | HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x), |
|---|
| 3864 | | -HDA_CODEC_ENTRY(0x10de0008, "GPU 08 HDMI/DP", patch_nvhdmi), |
|---|
| 3865 | | -HDA_CODEC_ENTRY(0x10de0009, "GPU 09 HDMI/DP", patch_nvhdmi), |
|---|
| 3866 | | -HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi), |
|---|
| 3867 | | -HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi), |
|---|
| 3868 | | -HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi), |
|---|
| 3869 | | -HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi), |
|---|
| 3870 | | -HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi), |
|---|
| 3871 | | -HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi), |
|---|
| 3872 | | -HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi), |
|---|
| 3873 | | -HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi), |
|---|
| 3874 | | -HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi), |
|---|
| 3875 | | -HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi), |
|---|
| 3876 | | -HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi), |
|---|
| 4324 | +HDA_CODEC_ENTRY(0x10de0008, "GPU 08 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4325 | +HDA_CODEC_ENTRY(0x10de0009, "GPU 09 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4326 | +HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4327 | +HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4328 | +HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi_legacy), |
|---|
| 4329 | +HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4330 | +HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4331 | +HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4332 | +HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4333 | +HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4334 | +HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4335 | +HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4336 | +HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 3877 | 4337 | /* 17 is known to be absent */ |
|---|
| 3878 | | -HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi), |
|---|
| 3879 | | -HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi), |
|---|
| 3880 | | -HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi), |
|---|
| 3881 | | -HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi), |
|---|
| 3882 | | -HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi), |
|---|
| 4338 | +HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4339 | +HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4340 | +HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4341 | +HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 4342 | +HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi_legacy), |
|---|
| 3883 | 4343 | HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi), |
|---|
| 3884 | 4344 | HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi), |
|---|
| 3885 | 4345 | HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi), |
|---|
| 3886 | 4346 | HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi), |
|---|
| 4347 | +HDA_CODEC_ENTRY(0x10de002d, "Tegra186 HDMI/DP0", patch_tegra_hdmi), |
|---|
| 4348 | +HDA_CODEC_ENTRY(0x10de002e, "Tegra186 HDMI/DP1", patch_tegra_hdmi), |
|---|
| 4349 | +HDA_CODEC_ENTRY(0x10de002f, "Tegra194 HDMI/DP2", patch_tegra_hdmi), |
|---|
| 4350 | +HDA_CODEC_ENTRY(0x10de0030, "Tegra194 HDMI/DP3", patch_tegra_hdmi), |
|---|
| 3887 | 4351 | HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi), |
|---|
| 3888 | 4352 | HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi), |
|---|
| 3889 | 4353 | HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi), |
|---|
| .. | .. |
|---|
| 3926 | 4390 | HDA_CODEC_ENTRY(0x10de009e, "GPU 9e HDMI/DP", patch_nvhdmi), |
|---|
| 3927 | 4391 | HDA_CODEC_ENTRY(0x10de009f, "GPU 9f HDMI/DP", patch_nvhdmi), |
|---|
| 3928 | 4392 | HDA_CODEC_ENTRY(0x10de00a0, "GPU a0 HDMI/DP", patch_nvhdmi), |
|---|
| 4393 | +HDA_CODEC_ENTRY(0x10de00a3, "GPU a3 HDMI/DP", patch_nvhdmi), |
|---|
| 4394 | +HDA_CODEC_ENTRY(0x10de00a4, "GPU a4 HDMI/DP", patch_nvhdmi), |
|---|
| 4395 | +HDA_CODEC_ENTRY(0x10de00a5, "GPU a5 HDMI/DP", patch_nvhdmi), |
|---|
| 4396 | +HDA_CODEC_ENTRY(0x10de00a6, "GPU a6 HDMI/DP", patch_nvhdmi), |
|---|
| 4397 | +HDA_CODEC_ENTRY(0x10de00a7, "GPU a7 HDMI/DP", patch_nvhdmi), |
|---|
| 3929 | 4398 | HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch), |
|---|
| 3930 | 4399 | HDA_CODEC_ENTRY(0x10de8067, "MCP67/68 HDMI", patch_nvhdmi_2ch), |
|---|
| 4400 | +HDA_CODEC_ENTRY(0x67663d82, "Arise 82 HDMI/DP", patch_gf_hdmi), |
|---|
| 4401 | +HDA_CODEC_ENTRY(0x67663d83, "Arise 83 HDMI/DP", patch_gf_hdmi), |
|---|
| 4402 | +HDA_CODEC_ENTRY(0x67663d84, "Arise 84 HDMI/DP", patch_gf_hdmi), |
|---|
| 4403 | +HDA_CODEC_ENTRY(0x67663d85, "Arise 85 HDMI/DP", patch_gf_hdmi), |
|---|
| 4404 | +HDA_CODEC_ENTRY(0x67663d86, "Arise 86 HDMI/DP", patch_gf_hdmi), |
|---|
| 4405 | +HDA_CODEC_ENTRY(0x67663d87, "Arise 87 HDMI/DP", patch_gf_hdmi), |
|---|
| 3931 | 4406 | HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi), |
|---|
| 3932 | 4407 | HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi), |
|---|
| 3933 | 4408 | HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi), |
|---|
| 3934 | 4409 | HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi), |
|---|
| 3935 | 4410 | HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi), |
|---|
| 4411 | +HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi), |
|---|
| 3936 | 4412 | HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi), |
|---|
| 3937 | 4413 | HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi), |
|---|
| 3938 | 4414 | HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi), |
|---|
| .. | .. |
|---|
| 3946 | 4422 | HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi), |
|---|
| 3947 | 4423 | HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi), |
|---|
| 3948 | 4424 | HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi), |
|---|
| 3949 | | -HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi), |
|---|
| 4425 | +HDA_CODEC_ENTRY(0x8086280f, "Icelake HDMI", patch_i915_icl_hdmi), |
|---|
| 4426 | +HDA_CODEC_ENTRY(0x80862812, "Tigerlake HDMI", patch_i915_tgl_hdmi), |
|---|
| 4427 | +HDA_CODEC_ENTRY(0x80862814, "DG1 HDMI", patch_i915_tgl_hdmi), |
|---|
| 4428 | +HDA_CODEC_ENTRY(0x80862815, "Alderlake HDMI", patch_i915_tgl_hdmi), |
|---|
| 4429 | +HDA_CODEC_ENTRY(0x80862816, "Rocketlake HDMI", patch_i915_tgl_hdmi), |
|---|
| 4430 | +HDA_CODEC_ENTRY(0x80862819, "DG2 HDMI", patch_i915_tgl_hdmi), |
|---|
| 4431 | +HDA_CODEC_ENTRY(0x8086281a, "Jasperlake HDMI", patch_i915_icl_hdmi), |
|---|
| 4432 | +HDA_CODEC_ENTRY(0x8086281b, "Elkhartlake HDMI", patch_i915_icl_hdmi), |
|---|
| 4433 | +HDA_CODEC_ENTRY(0x8086281c, "Alderlake-P HDMI", patch_i915_tgl_hdmi), |
|---|
| 3950 | 4434 | HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi), |
|---|
| 3951 | 4435 | HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi), |
|---|
| 3952 | 4436 | HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi), |
|---|