Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * patch_hdmi.c - routines for HDMI/DisplayPort codecs |
| 4 | * |
| 5 | * Copyright(c) 2008-2010 Intel Corporation. All rights reserved. |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 6 | * Copyright (c) 2006 ATI Technologies Inc. |
| 7 | * Copyright (c) 2008 NVIDIA Corp. All rights reserved. |
| 8 | * Copyright (c) 2008 Wei Ni <wni@nvidia.com> |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 9 | * |
| 10 | * Authors: |
| 11 | * Wu Fengguang <wfg@linux.intel.com> |
| 12 | * |
| 13 | * Maintained by: |
| 14 | * Wu Fengguang <wfg@linux.intel.com> |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify it |
| 17 | * under the terms of the GNU General Public License as published by the Free |
| 18 | * Software Foundation; either version 2 of the License, or (at your option) |
| 19 | * any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, but |
| 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 24 | * for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software Foundation, |
| 28 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 29 | */ |
| 30 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 31 | #include <linux/init.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/slab.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 34 | #include <linux/module.h> |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 35 | #include <sound/core.h> |
David Henningsson | 07acecc | 2011-05-19 11:46:03 +0200 | [diff] [blame] | 36 | #include <sound/jack.h> |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 37 | #include <sound/asoundef.h> |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 38 | #include <sound/tlv.h> |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 39 | #include "hda_codec.h" |
| 40 | #include "hda_local.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 41 | #include "hda_jack.h" |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 42 | |
Takashi Iwai | 0ebaa24 | 2011-01-11 18:11:04 +0100 | [diff] [blame] | 43 | static bool static_hdmi_pcm; |
| 44 | module_param(static_hdmi_pcm, bool, 0644); |
| 45 | MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); |
| 46 | |
Mengdong Lin | fb87fa3 | 2013-09-04 16:36:57 -0400 | [diff] [blame] | 47 | #define is_haswell(codec) ((codec)->vendor_id == 0x80862807) |
| 48 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 49 | struct hdmi_spec_per_cvt { |
| 50 | hda_nid_t cvt_nid; |
| 51 | int assigned; |
| 52 | unsigned int channels_min; |
| 53 | unsigned int channels_max; |
| 54 | u32 rates; |
| 55 | u64 formats; |
| 56 | unsigned int maxbps; |
| 57 | }; |
| 58 | |
Takashi Iwai | 4eea309 | 2013-02-07 18:18:19 +0100 | [diff] [blame] | 59 | /* max. connections to a widget */ |
| 60 | #define HDA_MAX_CONNECTIONS 32 |
| 61 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 62 | struct hdmi_spec_per_pin { |
| 63 | hda_nid_t pin_nid; |
| 64 | int num_mux_nids; |
| 65 | hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 66 | hda_nid_t cvt_nid; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 67 | |
| 68 | struct hda_codec *codec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 69 | struct hdmi_eld sink_eld; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 70 | struct mutex lock; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 71 | struct delayed_work work; |
David Henningsson | 92c69e7 | 2013-02-19 16:11:26 +0100 | [diff] [blame] | 72 | struct snd_kcontrol *eld_ctl; |
Wu Fengguang | c6e8453 | 2011-11-18 16:59:32 -0600 | [diff] [blame] | 73 | int repoll_count; |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 74 | bool setup; /* the stream has been set up by prepare callback */ |
| 75 | int channels; /* current number of channels */ |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 76 | bool non_pcm; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 77 | bool chmap_set; /* channel-map override by ALSA API? */ |
| 78 | unsigned char chmap[8]; /* ALSA API channel-map */ |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 79 | char pcm_name[8]; /* filled in build_pcm callbacks */ |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 80 | #ifdef CONFIG_PROC_FS |
| 81 | struct snd_info_entry *proc_entry; |
| 82 | #endif |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 83 | }; |
| 84 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 85 | struct cea_channel_speaker_allocation; |
| 86 | |
| 87 | /* operations used by generic code that can be overridden by patches */ |
| 88 | struct hdmi_ops { |
| 89 | int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid, |
| 90 | unsigned char *buf, int *eld_size); |
| 91 | |
| 92 | /* get and set channel assigned to each HDMI ASP (audio sample packet) slot */ |
| 93 | int (*pin_get_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid, |
| 94 | int asp_slot); |
| 95 | int (*pin_set_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid, |
| 96 | int asp_slot, int channel); |
| 97 | |
| 98 | void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid, |
| 99 | int ca, int active_channels, int conn_type); |
| 100 | |
| 101 | /* enable/disable HBR (HD passthrough) */ |
| 102 | int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr); |
| 103 | |
| 104 | int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid, |
| 105 | hda_nid_t pin_nid, u32 stream_tag, int format); |
| 106 | |
| 107 | /* Helpers for producing the channel map TLVs. These can be overridden |
| 108 | * for devices that have non-standard mapping requirements. */ |
| 109 | int (*chmap_cea_alloc_validate_get_type)(struct cea_channel_speaker_allocation *cap, |
| 110 | int channels); |
| 111 | void (*cea_alloc_to_tlv_chmap)(struct cea_channel_speaker_allocation *cap, |
| 112 | unsigned int *chmap, int channels); |
| 113 | |
| 114 | /* check that the user-given chmap is supported */ |
| 115 | int (*chmap_validate)(int ca, int channels, unsigned char *chmap); |
| 116 | }; |
| 117 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 118 | struct hdmi_spec { |
| 119 | int num_cvts; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 120 | struct snd_array cvts; /* struct hdmi_spec_per_cvt */ |
| 121 | hda_nid_t cvt_nids[4]; /* only for haswell fix */ |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 122 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 123 | int num_pins; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 124 | struct snd_array pins; /* struct hdmi_spec_per_pin */ |
| 125 | struct snd_array pcm_rec; /* struct hda_pcm */ |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 126 | unsigned int channels_max; /* max over all cvts */ |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 127 | |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 128 | struct hdmi_eld temp_eld; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 129 | struct hdmi_ops ops; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 130 | /* |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 131 | * Non-generic ATI/NVIDIA specific |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 132 | */ |
| 133 | struct hda_multi_out multiout; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 134 | struct hda_pcm_stream pcm_playback; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | |
| 138 | struct hdmi_audio_infoframe { |
| 139 | u8 type; /* 0x84 */ |
| 140 | u8 ver; /* 0x01 */ |
| 141 | u8 len; /* 0x0a */ |
| 142 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 143 | u8 checksum; |
| 144 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 145 | u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */ |
| 146 | u8 SS01_SF24; |
| 147 | u8 CXT04; |
| 148 | u8 CA; |
| 149 | u8 LFEPBL01_LSV36_DM_INH7; |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | struct dp_audio_infoframe { |
| 153 | u8 type; /* 0x84 */ |
| 154 | u8 len; /* 0x1b */ |
| 155 | u8 ver; /* 0x11 << 2 */ |
| 156 | |
| 157 | u8 CC02_CT47; /* match with HDMI infoframe from this on */ |
| 158 | u8 SS01_SF24; |
| 159 | u8 CXT04; |
| 160 | u8 CA; |
| 161 | u8 LFEPBL01_LSV36_DM_INH7; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 162 | }; |
| 163 | |
Takashi Iwai | 2b203dbb | 2011-02-11 12:17:30 +0100 | [diff] [blame] | 164 | union audio_infoframe { |
| 165 | struct hdmi_audio_infoframe hdmi; |
| 166 | struct dp_audio_infoframe dp; |
| 167 | u8 bytes[0]; |
| 168 | }; |
| 169 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 170 | /* |
| 171 | * CEA speaker placement: |
| 172 | * |
| 173 | * FLH FCH FRH |
| 174 | * FLW FL FLC FC FRC FR FRW |
| 175 | * |
| 176 | * LFE |
| 177 | * TC |
| 178 | * |
| 179 | * RL RLC RC RRC RR |
| 180 | * |
| 181 | * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to |
| 182 | * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC. |
| 183 | */ |
| 184 | enum cea_speaker_placement { |
| 185 | FL = (1 << 0), /* Front Left */ |
| 186 | FC = (1 << 1), /* Front Center */ |
| 187 | FR = (1 << 2), /* Front Right */ |
| 188 | FLC = (1 << 3), /* Front Left Center */ |
| 189 | FRC = (1 << 4), /* Front Right Center */ |
| 190 | RL = (1 << 5), /* Rear Left */ |
| 191 | RC = (1 << 6), /* Rear Center */ |
| 192 | RR = (1 << 7), /* Rear Right */ |
| 193 | RLC = (1 << 8), /* Rear Left Center */ |
| 194 | RRC = (1 << 9), /* Rear Right Center */ |
| 195 | LFE = (1 << 10), /* Low Frequency Effect */ |
| 196 | FLW = (1 << 11), /* Front Left Wide */ |
| 197 | FRW = (1 << 12), /* Front Right Wide */ |
| 198 | FLH = (1 << 13), /* Front Left High */ |
| 199 | FCH = (1 << 14), /* Front Center High */ |
| 200 | FRH = (1 << 15), /* Front Right High */ |
| 201 | TC = (1 << 16), /* Top Center */ |
| 202 | }; |
| 203 | |
| 204 | /* |
| 205 | * ELD SA bits in the CEA Speaker Allocation data block |
| 206 | */ |
| 207 | static int eld_speaker_allocation_bits[] = { |
| 208 | [0] = FL | FR, |
| 209 | [1] = LFE, |
| 210 | [2] = FC, |
| 211 | [3] = RL | RR, |
| 212 | [4] = RC, |
| 213 | [5] = FLC | FRC, |
| 214 | [6] = RLC | RRC, |
| 215 | /* the following are not defined in ELD yet */ |
| 216 | [7] = FLW | FRW, |
| 217 | [8] = FLH | FRH, |
| 218 | [9] = TC, |
| 219 | [10] = FCH, |
| 220 | }; |
| 221 | |
| 222 | struct cea_channel_speaker_allocation { |
| 223 | int ca_index; |
| 224 | int speakers[8]; |
| 225 | |
| 226 | /* derived values, just for convenience */ |
| 227 | int channels; |
| 228 | int spk_mask; |
| 229 | }; |
| 230 | |
| 231 | /* |
| 232 | * ALSA sequence is: |
| 233 | * |
| 234 | * surround40 surround41 surround50 surround51 surround71 |
| 235 | * ch0 front left = = = = |
| 236 | * ch1 front right = = = = |
| 237 | * ch2 rear left = = = = |
| 238 | * ch3 rear right = = = = |
| 239 | * ch4 LFE center center center |
| 240 | * ch5 LFE LFE |
| 241 | * ch6 side left |
| 242 | * ch7 side right |
| 243 | * |
| 244 | * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR} |
| 245 | */ |
| 246 | static int hdmi_channel_mapping[0x32][8] = { |
| 247 | /* stereo */ |
| 248 | [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, |
| 249 | /* 2.1 */ |
| 250 | [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, |
| 251 | /* Dolby Surround */ |
| 252 | [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 }, |
| 253 | /* surround40 */ |
| 254 | [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 }, |
| 255 | /* 4ch */ |
| 256 | [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 }, |
| 257 | /* surround41 */ |
Jerry Zhou | 9396d31 | 2010-09-21 14:44:51 +0800 | [diff] [blame] | 258 | [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 }, |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 259 | /* surround50 */ |
| 260 | [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 }, |
| 261 | /* surround51 */ |
| 262 | [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 }, |
| 263 | /* 7.1 */ |
| 264 | [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 }, |
| 265 | }; |
| 266 | |
| 267 | /* |
| 268 | * This is an ordered list! |
| 269 | * |
| 270 | * The preceding ones have better chances to be selected by |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 271 | * hdmi_channel_allocation(). |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 272 | */ |
| 273 | static struct cea_channel_speaker_allocation channel_allocations[] = { |
| 274 | /* channel: 7 6 5 4 3 2 1 0 */ |
| 275 | { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } }, |
| 276 | /* 2.1 */ |
| 277 | { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } }, |
| 278 | /* Dolby Surround */ |
| 279 | { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } }, |
| 280 | /* surround40 */ |
| 281 | { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } }, |
| 282 | /* surround41 */ |
| 283 | { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } }, |
| 284 | /* surround50 */ |
| 285 | { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } }, |
| 286 | /* surround51 */ |
| 287 | { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } }, |
| 288 | /* 6.1 */ |
| 289 | { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } }, |
| 290 | /* surround71 */ |
| 291 | { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } }, |
| 292 | |
| 293 | { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } }, |
| 294 | { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } }, |
| 295 | { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } }, |
| 296 | { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } }, |
| 297 | { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } }, |
| 298 | { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } }, |
| 299 | { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } }, |
| 300 | { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } }, |
| 301 | { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } }, |
| 302 | { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } }, |
| 303 | { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } }, |
| 304 | { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } }, |
| 305 | { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } }, |
| 306 | { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } }, |
| 307 | { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } }, |
| 308 | { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } }, |
| 309 | { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } }, |
| 310 | { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } }, |
| 311 | { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } }, |
| 312 | { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } }, |
| 313 | { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } }, |
| 314 | { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } }, |
| 315 | { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } }, |
| 316 | { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } }, |
| 317 | { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } }, |
| 318 | { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } }, |
| 319 | { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } }, |
| 320 | { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } }, |
| 321 | { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } }, |
| 322 | { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } }, |
| 323 | { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } }, |
| 324 | { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } }, |
| 325 | { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } }, |
| 326 | { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } }, |
| 327 | { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } }, |
| 328 | { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } }, |
| 329 | { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } }, |
| 330 | { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } }, |
| 331 | { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } }, |
| 332 | { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } }, |
| 333 | { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } }, |
| 334 | }; |
| 335 | |
| 336 | |
| 337 | /* |
| 338 | * HDMI routines |
| 339 | */ |
| 340 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 341 | #define get_pin(spec, idx) \ |
| 342 | ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx)) |
| 343 | #define get_cvt(spec, idx) \ |
| 344 | ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx)) |
| 345 | #define get_pcm_rec(spec, idx) \ |
| 346 | ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx)) |
| 347 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 348 | static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 349 | { |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 350 | int pin_idx; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 351 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 352 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 353 | if (get_pin(spec, pin_idx)->pin_nid == pin_nid) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 354 | return pin_idx; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 355 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 356 | snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid); |
| 357 | return -EINVAL; |
| 358 | } |
| 359 | |
| 360 | static int hinfo_to_pin_index(struct hdmi_spec *spec, |
| 361 | struct hda_pcm_stream *hinfo) |
| 362 | { |
| 363 | int pin_idx; |
| 364 | |
| 365 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 366 | if (get_pcm_rec(spec, pin_idx)->stream == hinfo) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 367 | return pin_idx; |
| 368 | |
| 369 | snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo); |
| 370 | return -EINVAL; |
| 371 | } |
| 372 | |
| 373 | static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid) |
| 374 | { |
| 375 | int cvt_idx; |
| 376 | |
| 377 | for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 378 | if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 379 | return cvt_idx; |
| 380 | |
| 381 | snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 382 | return -EINVAL; |
| 383 | } |
| 384 | |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 385 | static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, |
| 386 | struct snd_ctl_elem_info *uinfo) |
| 387 | { |
| 388 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 389 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 390 | struct hdmi_spec_per_pin *per_pin; |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 391 | struct hdmi_eld *eld; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 392 | int pin_idx; |
| 393 | |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 394 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 395 | |
| 396 | pin_idx = kcontrol->private_value; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 397 | per_pin = get_pin(spec, pin_idx); |
| 398 | eld = &per_pin->sink_eld; |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 399 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 400 | mutex_lock(&per_pin->lock); |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 401 | uinfo->count = eld->eld_valid ? eld->eld_size : 0; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 402 | mutex_unlock(&per_pin->lock); |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, |
| 408 | struct snd_ctl_elem_value *ucontrol) |
| 409 | { |
| 410 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 411 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 412 | struct hdmi_spec_per_pin *per_pin; |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 413 | struct hdmi_eld *eld; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 414 | int pin_idx; |
| 415 | |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 416 | pin_idx = kcontrol->private_value; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 417 | per_pin = get_pin(spec, pin_idx); |
| 418 | eld = &per_pin->sink_eld; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 419 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 420 | mutex_lock(&per_pin->lock); |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 421 | if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) { |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 422 | mutex_unlock(&per_pin->lock); |
David Henningsson | 68e03de | 2013-02-19 16:11:23 +0100 | [diff] [blame] | 423 | snd_BUG(); |
| 424 | return -EINVAL; |
| 425 | } |
| 426 | |
| 427 | memset(ucontrol->value.bytes.data, 0, |
| 428 | ARRAY_SIZE(ucontrol->value.bytes.data)); |
| 429 | if (eld->eld_valid) |
| 430 | memcpy(ucontrol->value.bytes.data, eld->eld_buffer, |
| 431 | eld->eld_size); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 432 | mutex_unlock(&per_pin->lock); |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | static struct snd_kcontrol_new eld_bytes_ctl = { |
| 438 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 439 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 440 | .name = "ELD", |
| 441 | .info = hdmi_eld_ctl_info, |
| 442 | .get = hdmi_eld_ctl_get, |
| 443 | }; |
| 444 | |
| 445 | static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx, |
| 446 | int device) |
| 447 | { |
| 448 | struct snd_kcontrol *kctl; |
| 449 | struct hdmi_spec *spec = codec->spec; |
| 450 | int err; |
| 451 | |
| 452 | kctl = snd_ctl_new1(&eld_bytes_ctl, codec); |
| 453 | if (!kctl) |
| 454 | return -ENOMEM; |
| 455 | kctl->private_value = pin_idx; |
| 456 | kctl->id.device = device; |
| 457 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 458 | err = snd_hda_ctl_add(codec, get_pin(spec, pin_idx)->pin_nid, kctl); |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 459 | if (err < 0) |
| 460 | return err; |
| 461 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 462 | get_pin(spec, pin_idx)->eld_ctl = kctl; |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 463 | return 0; |
| 464 | } |
| 465 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 466 | #ifdef BE_PARANOID |
| 467 | static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, |
| 468 | int *packet_index, int *byte_index) |
| 469 | { |
| 470 | int val; |
| 471 | |
| 472 | val = snd_hda_codec_read(codec, pin_nid, 0, |
| 473 | AC_VERB_GET_HDMI_DIP_INDEX, 0); |
| 474 | |
| 475 | *packet_index = val >> 5; |
| 476 | *byte_index = val & 0x1f; |
| 477 | } |
| 478 | #endif |
| 479 | |
| 480 | static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, |
| 481 | int packet_index, int byte_index) |
| 482 | { |
| 483 | int val; |
| 484 | |
| 485 | val = (packet_index << 5) | (byte_index & 0x1f); |
| 486 | |
| 487 | snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); |
| 488 | } |
| 489 | |
| 490 | static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid, |
| 491 | unsigned char val) |
| 492 | { |
| 493 | snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); |
| 494 | } |
| 495 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 496 | static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 497 | { |
| 498 | /* Unmute */ |
| 499 | if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) |
| 500 | snd_hda_codec_write(codec, pin_nid, 0, |
| 501 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); |
Takashi Iwai | 6169b67 | 2012-12-14 10:22:35 +0100 | [diff] [blame] | 502 | /* Enable pin out: some machines with GM965 gets broken output when |
| 503 | * the pin is disabled or changed while using with HDMI |
| 504 | */ |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 505 | snd_hda_codec_write(codec, pin_nid, 0, |
Takashi Iwai | 6169b67 | 2012-12-14 10:22:35 +0100 | [diff] [blame] | 506 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 507 | } |
| 508 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 509 | static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 510 | { |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 511 | return 1 + snd_hda_codec_read(codec, cvt_nid, 0, |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 512 | AC_VERB_GET_CVT_CHAN_COUNT, 0); |
| 513 | } |
| 514 | |
| 515 | static void hdmi_set_channel_count(struct hda_codec *codec, |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 516 | hda_nid_t cvt_nid, int chs) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 517 | { |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 518 | if (chs != hdmi_get_channel_count(codec, cvt_nid)) |
| 519 | snd_hda_codec_write(codec, cvt_nid, 0, |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 520 | AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); |
| 521 | } |
| 522 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 523 | /* |
| 524 | * ELD proc files |
| 525 | */ |
| 526 | |
| 527 | #ifdef CONFIG_PROC_FS |
| 528 | static void print_eld_info(struct snd_info_entry *entry, |
| 529 | struct snd_info_buffer *buffer) |
| 530 | { |
| 531 | struct hdmi_spec_per_pin *per_pin = entry->private_data; |
| 532 | |
| 533 | mutex_lock(&per_pin->lock); |
| 534 | snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer); |
| 535 | mutex_unlock(&per_pin->lock); |
| 536 | } |
| 537 | |
| 538 | static void write_eld_info(struct snd_info_entry *entry, |
| 539 | struct snd_info_buffer *buffer) |
| 540 | { |
| 541 | struct hdmi_spec_per_pin *per_pin = entry->private_data; |
| 542 | |
| 543 | mutex_lock(&per_pin->lock); |
| 544 | snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer); |
| 545 | mutex_unlock(&per_pin->lock); |
| 546 | } |
| 547 | |
| 548 | static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) |
| 549 | { |
| 550 | char name[32]; |
| 551 | struct hda_codec *codec = per_pin->codec; |
| 552 | struct snd_info_entry *entry; |
| 553 | int err; |
| 554 | |
| 555 | snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); |
| 556 | err = snd_card_proc_new(codec->bus->card, name, &entry); |
| 557 | if (err < 0) |
| 558 | return err; |
| 559 | |
| 560 | snd_info_set_text_ops(entry, per_pin, print_eld_info); |
| 561 | entry->c.text.write = write_eld_info; |
| 562 | entry->mode |= S_IWUSR; |
| 563 | per_pin->proc_entry = entry; |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) |
| 569 | { |
| 570 | if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) { |
| 571 | snd_device_free(per_pin->codec->bus->card, per_pin->proc_entry); |
| 572 | per_pin->proc_entry = NULL; |
| 573 | } |
| 574 | } |
| 575 | #else |
Takashi Iwai | b55447a | 2013-10-21 16:31:45 +0200 | [diff] [blame] | 576 | static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin, |
| 577 | int index) |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 578 | { |
| 579 | return 0; |
| 580 | } |
Takashi Iwai | b55447a | 2013-10-21 16:31:45 +0200 | [diff] [blame] | 581 | static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin) |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 582 | { |
| 583 | } |
| 584 | #endif |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 585 | |
| 586 | /* |
| 587 | * Channel mapping routines |
| 588 | */ |
| 589 | |
| 590 | /* |
| 591 | * Compute derived values in channel_allocations[]. |
| 592 | */ |
| 593 | static void init_channel_allocations(void) |
| 594 | { |
| 595 | int i, j; |
| 596 | struct cea_channel_speaker_allocation *p; |
| 597 | |
| 598 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { |
| 599 | p = channel_allocations + i; |
| 600 | p->channels = 0; |
| 601 | p->spk_mask = 0; |
| 602 | for (j = 0; j < ARRAY_SIZE(p->speakers); j++) |
| 603 | if (p->speakers[j]) { |
| 604 | p->channels++; |
| 605 | p->spk_mask |= p->speakers[j]; |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
Wang Xingchao | 72357c7 | 2012-09-06 10:02:36 +0800 | [diff] [blame] | 610 | static int get_channel_allocation_order(int ca) |
| 611 | { |
| 612 | int i; |
| 613 | |
| 614 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { |
| 615 | if (channel_allocations[i].ca_index == ca) |
| 616 | break; |
| 617 | } |
| 618 | return i; |
| 619 | } |
| 620 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 621 | /* |
| 622 | * The transformation takes two steps: |
| 623 | * |
| 624 | * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask |
| 625 | * spk_mask => (channel_allocations[]) => ai->CA |
| 626 | * |
| 627 | * TODO: it could select the wrong CA from multiple candidates. |
| 628 | */ |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 629 | static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 630 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 631 | int i; |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 632 | int ca = 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 633 | int spk_mask = 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 634 | char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; |
| 635 | |
| 636 | /* |
| 637 | * CA defaults to 0 for basic stereo audio |
| 638 | */ |
| 639 | if (channels <= 2) |
| 640 | return 0; |
| 641 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 642 | /* |
| 643 | * expand ELD's speaker allocation mask |
| 644 | * |
| 645 | * ELD tells the speaker mask in a compact(paired) form, |
| 646 | * expand ELD's notions to match the ones used by Audio InfoFrame. |
| 647 | */ |
| 648 | for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 649 | if (eld->info.spk_alloc & (1 << i)) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 650 | spk_mask |= eld_speaker_allocation_bits[i]; |
| 651 | } |
| 652 | |
| 653 | /* search for the first working match in the CA table */ |
| 654 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { |
| 655 | if (channels == channel_allocations[i].channels && |
| 656 | (spk_mask & channel_allocations[i].spk_mask) == |
| 657 | channel_allocations[i].spk_mask) { |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 658 | ca = channel_allocations[i].ca_index; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 659 | break; |
| 660 | } |
| 661 | } |
| 662 | |
Anssi Hannula | 18e3918 | 2013-09-01 14:36:47 +0300 | [diff] [blame] | 663 | if (!ca) { |
| 664 | /* if there was no match, select the regular ALSA channel |
| 665 | * allocation with the matching number of channels */ |
| 666 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { |
| 667 | if (channels == channel_allocations[i].channels) { |
| 668 | ca = channel_allocations[i].ca_index; |
| 669 | break; |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 674 | snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf)); |
Wu Fengguang | 2abbf43 | 2010-03-08 10:45:38 +0800 | [diff] [blame] | 675 | snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n", |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 676 | ca, channels, buf); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 677 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 678 | return ca; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static void hdmi_debug_channel_mapping(struct hda_codec *codec, |
| 682 | hda_nid_t pin_nid) |
| 683 | { |
| 684 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 685 | struct hdmi_spec *spec = codec->spec; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 686 | int i; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 687 | int channel; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 688 | |
| 689 | for (i = 0; i < 8; i++) { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 690 | channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 691 | printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 692 | channel, i); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 693 | } |
| 694 | #endif |
| 695 | } |
| 696 | |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 697 | static void hdmi_std_setup_channel_mapping(struct hda_codec *codec, |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 698 | hda_nid_t pin_nid, |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 699 | bool non_pcm, |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 700 | int ca) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 701 | { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 702 | struct hdmi_spec *spec = codec->spec; |
Anssi Hannula | 90f2800 | 2013-10-05 02:25:39 +0300 | [diff] [blame] | 703 | struct cea_channel_speaker_allocation *ch_alloc; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 704 | int i; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 705 | int err; |
Wang Xingchao | 72357c7 | 2012-09-06 10:02:36 +0800 | [diff] [blame] | 706 | int order; |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 707 | int non_pcm_mapping[8]; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 708 | |
Wang Xingchao | 72357c7 | 2012-09-06 10:02:36 +0800 | [diff] [blame] | 709 | order = get_channel_allocation_order(ca); |
Anssi Hannula | 90f2800 | 2013-10-05 02:25:39 +0300 | [diff] [blame] | 710 | ch_alloc = &channel_allocations[order]; |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 711 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 712 | if (hdmi_channel_mapping[ca][1] == 0) { |
Anssi Hannula | 90f2800 | 2013-10-05 02:25:39 +0300 | [diff] [blame] | 713 | int hdmi_slot = 0; |
| 714 | /* fill actual channel mappings in ALSA channel (i) order */ |
| 715 | for (i = 0; i < ch_alloc->channels; i++) { |
| 716 | while (!ch_alloc->speakers[7 - hdmi_slot] && !WARN_ON(hdmi_slot >= 8)) |
| 717 | hdmi_slot++; /* skip zero slots */ |
| 718 | |
| 719 | hdmi_channel_mapping[ca][i] = (i << 4) | hdmi_slot++; |
| 720 | } |
| 721 | /* fill the rest of the slots with ALSA channel 0xf */ |
| 722 | for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) |
| 723 | if (!ch_alloc->speakers[7 - hdmi_slot]) |
| 724 | hdmi_channel_mapping[ca][i++] = (0xf << 4) | hdmi_slot; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 725 | } |
| 726 | |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 727 | if (non_pcm) { |
Anssi Hannula | 90f2800 | 2013-10-05 02:25:39 +0300 | [diff] [blame] | 728 | for (i = 0; i < ch_alloc->channels; i++) |
Anssi Hannula | 11f7c52 | 2013-10-05 02:25:41 +0300 | [diff] [blame] | 729 | non_pcm_mapping[i] = (i << 4) | i; |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 730 | for (; i < 8; i++) |
Anssi Hannula | 11f7c52 | 2013-10-05 02:25:41 +0300 | [diff] [blame] | 731 | non_pcm_mapping[i] = (0xf << 4) | i; |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 732 | } |
| 733 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 734 | for (i = 0; i < 8; i++) { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 735 | int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i]; |
| 736 | int hdmi_slot = slotsetup & 0x0f; |
| 737 | int channel = (slotsetup & 0xf0) >> 4; |
| 738 | err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 739 | if (err) { |
Wu Fengguang | 2abbf43 | 2010-03-08 10:45:38 +0800 | [diff] [blame] | 740 | snd_printdd(KERN_NOTICE |
| 741 | "HDMI: channel mapping failed\n"); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 742 | break; |
| 743 | } |
| 744 | } |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 745 | } |
| 746 | |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 747 | struct channel_map_table { |
| 748 | unsigned char map; /* ALSA API channel map position */ |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 749 | int spk_mask; /* speaker position bit mask */ |
| 750 | }; |
| 751 | |
| 752 | static struct channel_map_table map_tables[] = { |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 753 | { SNDRV_CHMAP_FL, FL }, |
| 754 | { SNDRV_CHMAP_FR, FR }, |
| 755 | { SNDRV_CHMAP_RL, RL }, |
| 756 | { SNDRV_CHMAP_RR, RR }, |
| 757 | { SNDRV_CHMAP_LFE, LFE }, |
| 758 | { SNDRV_CHMAP_FC, FC }, |
| 759 | { SNDRV_CHMAP_RLC, RLC }, |
| 760 | { SNDRV_CHMAP_RRC, RRC }, |
| 761 | { SNDRV_CHMAP_RC, RC }, |
| 762 | { SNDRV_CHMAP_FLC, FLC }, |
| 763 | { SNDRV_CHMAP_FRC, FRC }, |
| 764 | { SNDRV_CHMAP_FLH, FLH }, |
| 765 | { SNDRV_CHMAP_FRH, FRH }, |
| 766 | { SNDRV_CHMAP_FLW, FLW }, |
| 767 | { SNDRV_CHMAP_FRW, FRW }, |
| 768 | { SNDRV_CHMAP_TC, TC }, |
| 769 | { SNDRV_CHMAP_FCH, FCH }, |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 770 | {} /* terminator */ |
| 771 | }; |
| 772 | |
| 773 | /* from ALSA API channel position to speaker bit mask */ |
| 774 | static int to_spk_mask(unsigned char c) |
| 775 | { |
| 776 | struct channel_map_table *t = map_tables; |
| 777 | for (; t->map; t++) { |
| 778 | if (t->map == c) |
| 779 | return t->spk_mask; |
| 780 | } |
| 781 | return 0; |
| 782 | } |
| 783 | |
| 784 | /* from ALSA API channel position to CEA slot */ |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 785 | static int to_cea_slot(int ordered_ca, unsigned char pos) |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 786 | { |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 787 | int mask = to_spk_mask(pos); |
| 788 | int i; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 789 | |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 790 | if (mask) { |
| 791 | for (i = 0; i < 8; i++) { |
| 792 | if (channel_allocations[ordered_ca].speakers[7 - i] == mask) |
| 793 | return i; |
| 794 | } |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 795 | } |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 796 | |
| 797 | return -1; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | /* from speaker bit mask to ALSA API channel position */ |
| 801 | static int spk_to_chmap(int spk) |
| 802 | { |
| 803 | struct channel_map_table *t = map_tables; |
| 804 | for (; t->map; t++) { |
| 805 | if (t->spk_mask == spk) |
| 806 | return t->map; |
| 807 | } |
| 808 | return 0; |
| 809 | } |
| 810 | |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 811 | /* from CEA slot to ALSA API channel position */ |
| 812 | static int from_cea_slot(int ordered_ca, unsigned char slot) |
| 813 | { |
| 814 | int mask = channel_allocations[ordered_ca].speakers[7 - slot]; |
| 815 | |
| 816 | return spk_to_chmap(mask); |
| 817 | } |
| 818 | |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 819 | /* get the CA index corresponding to the given ALSA API channel map */ |
| 820 | static int hdmi_manual_channel_allocation(int chs, unsigned char *map) |
| 821 | { |
| 822 | int i, spks = 0, spk_mask = 0; |
| 823 | |
| 824 | for (i = 0; i < chs; i++) { |
| 825 | int mask = to_spk_mask(map[i]); |
| 826 | if (mask) { |
| 827 | spk_mask |= mask; |
| 828 | spks++; |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { |
| 833 | if ((chs == channel_allocations[i].channels || |
| 834 | spks == channel_allocations[i].channels) && |
| 835 | (spk_mask & channel_allocations[i].spk_mask) == |
| 836 | channel_allocations[i].spk_mask) |
| 837 | return channel_allocations[i].ca_index; |
| 838 | } |
| 839 | return -1; |
| 840 | } |
| 841 | |
| 842 | /* set up the channel slots for the given ALSA API channel map */ |
| 843 | static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec, |
| 844 | hda_nid_t pin_nid, |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 845 | int chs, unsigned char *map, |
| 846 | int ca) |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 847 | { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 848 | struct hdmi_spec *spec = codec->spec; |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 849 | int ordered_ca = get_channel_allocation_order(ca); |
Anssi Hannula | 11f7c52 | 2013-10-05 02:25:41 +0300 | [diff] [blame] | 850 | int alsa_pos, hdmi_slot; |
| 851 | int assignments[8] = {[0 ... 7] = 0xf}; |
| 852 | |
| 853 | for (alsa_pos = 0; alsa_pos < chs; alsa_pos++) { |
| 854 | |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 855 | hdmi_slot = to_cea_slot(ordered_ca, map[alsa_pos]); |
Anssi Hannula | 11f7c52 | 2013-10-05 02:25:41 +0300 | [diff] [blame] | 856 | |
| 857 | if (hdmi_slot < 0) |
| 858 | continue; /* unassigned channel */ |
| 859 | |
| 860 | assignments[hdmi_slot] = alsa_pos; |
| 861 | } |
| 862 | |
| 863 | for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 864 | int err; |
Anssi Hannula | 11f7c52 | 2013-10-05 02:25:41 +0300 | [diff] [blame] | 865 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 866 | err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, |
| 867 | assignments[hdmi_slot]); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 868 | if (err) |
| 869 | return -EINVAL; |
| 870 | } |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | /* store ALSA API channel map from the current default map */ |
| 875 | static void hdmi_setup_fake_chmap(unsigned char *map, int ca) |
| 876 | { |
| 877 | int i; |
Anssi Hannula | 56cac41 | 2013-10-05 02:25:38 +0300 | [diff] [blame] | 878 | int ordered_ca = get_channel_allocation_order(ca); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 879 | for (i = 0; i < 8; i++) { |
Anssi Hannula | 56cac41 | 2013-10-05 02:25:38 +0300 | [diff] [blame] | 880 | if (i < channel_allocations[ordered_ca].channels) |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 881 | map[i] = from_cea_slot(ordered_ca, hdmi_channel_mapping[ca][i] & 0x0f); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 882 | else |
| 883 | map[i] = 0; |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | static void hdmi_setup_channel_mapping(struct hda_codec *codec, |
| 888 | hda_nid_t pin_nid, bool non_pcm, int ca, |
Anssi Hannula | 2060873 | 2013-02-03 17:55:45 +0200 | [diff] [blame] | 889 | int channels, unsigned char *map, |
| 890 | bool chmap_set) |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 891 | { |
Anssi Hannula | 2060873 | 2013-02-03 17:55:45 +0200 | [diff] [blame] | 892 | if (!non_pcm && chmap_set) { |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 893 | hdmi_manual_setup_channel_mapping(codec, pin_nid, |
Anssi Hannula | a5b7d51 | 2013-10-05 02:25:42 +0300 | [diff] [blame] | 894 | channels, map, ca); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 895 | } else { |
| 896 | hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca); |
| 897 | hdmi_setup_fake_chmap(map, ca); |
| 898 | } |
Anssi Hannula | 980b249 | 2013-10-05 02:25:44 +0300 | [diff] [blame] | 899 | |
| 900 | hdmi_debug_channel_mapping(codec, pin_nid); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 901 | } |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 902 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 903 | static int hdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid, |
| 904 | int asp_slot, int channel) |
| 905 | { |
| 906 | return snd_hda_codec_write(codec, pin_nid, 0, |
| 907 | AC_VERB_SET_HDMI_CHAN_SLOT, |
| 908 | (channel << 4) | asp_slot); |
| 909 | } |
| 910 | |
| 911 | static int hdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid, |
| 912 | int asp_slot) |
| 913 | { |
| 914 | return (snd_hda_codec_read(codec, pin_nid, 0, |
| 915 | AC_VERB_GET_HDMI_CHAN_SLOT, |
| 916 | asp_slot) & 0xf0) >> 4; |
| 917 | } |
| 918 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 919 | /* |
| 920 | * Audio InfoFrame routines |
| 921 | */ |
| 922 | |
| 923 | /* |
| 924 | * Enable Audio InfoFrame Transmission |
| 925 | */ |
| 926 | static void hdmi_start_infoframe_trans(struct hda_codec *codec, |
| 927 | hda_nid_t pin_nid) |
| 928 | { |
| 929 | hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); |
| 930 | snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, |
| 931 | AC_DIPXMIT_BEST); |
| 932 | } |
| 933 | |
| 934 | /* |
| 935 | * Disable Audio InfoFrame Transmission |
| 936 | */ |
| 937 | static void hdmi_stop_infoframe_trans(struct hda_codec *codec, |
| 938 | hda_nid_t pin_nid) |
| 939 | { |
| 940 | hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); |
| 941 | snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, |
| 942 | AC_DIPXMIT_DISABLE); |
| 943 | } |
| 944 | |
| 945 | static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid) |
| 946 | { |
| 947 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 948 | int i; |
| 949 | int size; |
| 950 | |
| 951 | size = snd_hdmi_get_eld_size(codec, pin_nid); |
| 952 | printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size); |
| 953 | |
| 954 | for (i = 0; i < 8; i++) { |
| 955 | size = snd_hda_codec_read(codec, pin_nid, 0, |
| 956 | AC_VERB_GET_HDMI_DIP_SIZE, i); |
| 957 | printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size); |
| 958 | } |
| 959 | #endif |
| 960 | } |
| 961 | |
| 962 | static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid) |
| 963 | { |
| 964 | #ifdef BE_PARANOID |
| 965 | int i, j; |
| 966 | int size; |
| 967 | int pi, bi; |
| 968 | for (i = 0; i < 8; i++) { |
| 969 | size = snd_hda_codec_read(codec, pin_nid, 0, |
| 970 | AC_VERB_GET_HDMI_DIP_SIZE, i); |
| 971 | if (size == 0) |
| 972 | continue; |
| 973 | |
| 974 | hdmi_set_dip_index(codec, pin_nid, i, 0x0); |
| 975 | for (j = 1; j < 1000; j++) { |
| 976 | hdmi_write_dip_byte(codec, pin_nid, 0x0); |
| 977 | hdmi_get_dip_index(codec, pin_nid, &pi, &bi); |
| 978 | if (pi != i) |
| 979 | snd_printd(KERN_INFO "dip index %d: %d != %d\n", |
| 980 | bi, pi, i); |
| 981 | if (bi == 0) /* byte index wrapped around */ |
| 982 | break; |
| 983 | } |
| 984 | snd_printd(KERN_INFO |
| 985 | "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n", |
| 986 | i, size, j); |
| 987 | } |
| 988 | #endif |
| 989 | } |
| 990 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 991 | static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 992 | { |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 993 | u8 *bytes = (u8 *)hdmi_ai; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 994 | u8 sum = 0; |
| 995 | int i; |
| 996 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 997 | hdmi_ai->checksum = 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 998 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 999 | for (i = 0; i < sizeof(*hdmi_ai); i++) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1000 | sum += bytes[i]; |
| 1001 | |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 1002 | hdmi_ai->checksum = -sum; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | static void hdmi_fill_audio_infoframe(struct hda_codec *codec, |
| 1006 | hda_nid_t pin_nid, |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 1007 | u8 *dip, int size) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1008 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1009 | int i; |
| 1010 | |
| 1011 | hdmi_debug_dip_size(codec, pin_nid); |
| 1012 | hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */ |
| 1013 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1014 | hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 1015 | for (i = 0; i < size; i++) |
| 1016 | hdmi_write_dip_byte(codec, pin_nid, dip[i]); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid, |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 1020 | u8 *dip, int size) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1021 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1022 | u8 val; |
| 1023 | int i; |
| 1024 | |
| 1025 | if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0) |
| 1026 | != AC_DIPXMIT_BEST) |
| 1027 | return false; |
| 1028 | |
| 1029 | hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 1030 | for (i = 0; i < size; i++) { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1031 | val = snd_hda_codec_read(codec, pin_nid, 0, |
| 1032 | AC_VERB_GET_HDMI_DIP_DATA, 0); |
Wu Fengguang | 53d7d69 | 2010-09-21 14:25:49 +0800 | [diff] [blame] | 1033 | if (val != dip[i]) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1034 | return false; |
| 1035 | } |
| 1036 | |
| 1037 | return true; |
| 1038 | } |
| 1039 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1040 | static void hdmi_pin_setup_infoframe(struct hda_codec *codec, |
| 1041 | hda_nid_t pin_nid, |
| 1042 | int ca, int active_channels, |
| 1043 | int conn_type) |
| 1044 | { |
| 1045 | union audio_infoframe ai; |
| 1046 | |
| 1047 | if (conn_type == 0) { /* HDMI */ |
| 1048 | struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi; |
| 1049 | |
| 1050 | hdmi_ai->type = 0x84; |
| 1051 | hdmi_ai->ver = 0x01; |
| 1052 | hdmi_ai->len = 0x0a; |
| 1053 | hdmi_ai->CC02_CT47 = active_channels - 1; |
| 1054 | hdmi_ai->CA = ca; |
| 1055 | hdmi_checksum_audio_infoframe(hdmi_ai); |
| 1056 | } else if (conn_type == 1) { /* DisplayPort */ |
| 1057 | struct dp_audio_infoframe *dp_ai = &ai.dp; |
| 1058 | |
| 1059 | dp_ai->type = 0x84; |
| 1060 | dp_ai->len = 0x1b; |
| 1061 | dp_ai->ver = 0x11 << 2; |
| 1062 | dp_ai->CC02_CT47 = active_channels - 1; |
| 1063 | dp_ai->CA = ca; |
| 1064 | } else { |
| 1065 | snd_printd("HDMI: unknown connection type at pin %d\n", |
| 1066 | pin_nid); |
| 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | /* |
| 1071 | * sizeof(ai) is used instead of sizeof(*hdmi_ai) or |
| 1072 | * sizeof(*dp_ai) to avoid partial match/update problems when |
| 1073 | * the user switches between HDMI/DP monitors. |
| 1074 | */ |
| 1075 | if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes, |
| 1076 | sizeof(ai))) { |
| 1077 | snd_printdd("hdmi_pin_setup_infoframe: " |
| 1078 | "pin=%d channels=%d ca=0x%02x\n", |
| 1079 | pin_nid, |
| 1080 | active_channels, ca); |
| 1081 | hdmi_stop_infoframe_trans(codec, pin_nid); |
| 1082 | hdmi_fill_audio_infoframe(codec, pin_nid, |
| 1083 | ai.bytes, sizeof(ai)); |
| 1084 | hdmi_start_infoframe_trans(codec, pin_nid); |
| 1085 | } |
| 1086 | } |
| 1087 | |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1088 | static void hdmi_setup_audio_infoframe(struct hda_codec *codec, |
| 1089 | struct hdmi_spec_per_pin *per_pin, |
| 1090 | bool non_pcm) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1091 | { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1092 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1093 | hda_nid_t pin_nid = per_pin->pin_nid; |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1094 | int channels = per_pin->channels; |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 1095 | int active_channels; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1096 | struct hdmi_eld *eld; |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 1097 | int ca, ordered_ca; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1098 | |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1099 | if (!channels) |
| 1100 | return; |
| 1101 | |
Mengdong Lin | 58f7d28 | 2013-09-04 16:37:12 -0400 | [diff] [blame] | 1102 | if (is_haswell(codec)) |
| 1103 | snd_hda_codec_write(codec, pin_nid, 0, |
| 1104 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 1105 | AMP_OUT_UNMUTE); |
| 1106 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1107 | eld = &per_pin->sink_eld; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1108 | if (!eld->monitor_present) |
| 1109 | return; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1110 | |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1111 | if (!non_pcm && per_pin->chmap_set) |
| 1112 | ca = hdmi_manual_channel_allocation(channels, per_pin->chmap); |
| 1113 | else |
| 1114 | ca = hdmi_channel_allocation(eld, channels); |
| 1115 | if (ca < 0) |
| 1116 | ca = 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1117 | |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 1118 | ordered_ca = get_channel_allocation_order(ca); |
| 1119 | active_channels = channel_allocations[ordered_ca].channels; |
| 1120 | |
| 1121 | hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels); |
| 1122 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1123 | /* |
Anssi Hannula | 39edac7 | 2013-10-07 19:24:52 +0300 | [diff] [blame] | 1124 | * always configure channel mapping, it may have been changed by the |
| 1125 | * user in the meantime |
| 1126 | */ |
| 1127 | hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca, |
| 1128 | channels, per_pin->chmap, |
| 1129 | per_pin->chmap_set); |
| 1130 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1131 | spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels, |
| 1132 | eld->info.conn_type); |
Wang Xingchao | 433968d | 2012-09-06 10:02:37 +0800 | [diff] [blame] | 1133 | |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 1134 | per_pin->non_pcm = non_pcm; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1135 | } |
| 1136 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1137 | /* |
| 1138 | * Unsolicited events |
| 1139 | */ |
| 1140 | |
Wu Fengguang | c6e8453 | 2011-11-18 16:59:32 -0600 | [diff] [blame] | 1141 | static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); |
Takashi Iwai | 38faddb | 2010-07-28 14:21:55 +0200 | [diff] [blame] | 1142 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1143 | static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) |
| 1144 | { |
| 1145 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 1146 | int tag = res >> AC_UNSOL_RES_TAG_SHIFT; |
| 1147 | int pin_nid; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1148 | int pin_idx; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 1149 | struct hda_jack_tbl *jack; |
Mengdong Lin | 2e59e5a | 2013-08-26 21:35:49 -0400 | [diff] [blame] | 1150 | int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT; |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 1151 | |
| 1152 | jack = snd_hda_jack_tbl_get_from_tag(codec, tag); |
| 1153 | if (!jack) |
| 1154 | return; |
| 1155 | pin_nid = jack->nid; |
| 1156 | jack->jack_dirty = 1; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1157 | |
Fengguang Wu | fae3d88 | 2012-04-10 17:00:35 +0800 | [diff] [blame] | 1158 | _snd_printd(SND_PR_VERBOSE, |
Mengdong Lin | 2e59e5a | 2013-08-26 21:35:49 -0400 | [diff] [blame] | 1159 | "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n", |
| 1160 | codec->addr, pin_nid, dev_entry, !!(res & AC_UNSOL_RES_IA), |
Fengguang Wu | fae3d88 | 2012-04-10 17:00:35 +0800 | [diff] [blame] | 1161 | !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV)); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1162 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1163 | pin_idx = pin_nid_to_pin_index(spec, pin_nid); |
| 1164 | if (pin_idx < 0) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1165 | return; |
| 1166 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1167 | hdmi_present_sense(get_pin(spec, pin_idx), 1); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 1168 | snd_hda_jack_report_sync(codec); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) |
| 1172 | { |
| 1173 | int tag = res >> AC_UNSOL_RES_TAG_SHIFT; |
| 1174 | int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; |
| 1175 | int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); |
| 1176 | int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); |
| 1177 | |
| 1178 | printk(KERN_INFO |
Takashi Iwai | e9ea8e8 | 2012-06-21 11:41:05 +0200 | [diff] [blame] | 1179 | "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1180 | codec->addr, |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1181 | tag, |
| 1182 | subtag, |
| 1183 | cp_state, |
| 1184 | cp_ready); |
| 1185 | |
| 1186 | /* TODO */ |
| 1187 | if (cp_state) |
| 1188 | ; |
| 1189 | if (cp_ready) |
| 1190 | ; |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res) |
| 1195 | { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1196 | int tag = res >> AC_UNSOL_RES_TAG_SHIFT; |
| 1197 | int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; |
| 1198 | |
Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 1199 | if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) { |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1200 | snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag); |
| 1201 | return; |
| 1202 | } |
| 1203 | |
| 1204 | if (subtag == 0) |
| 1205 | hdmi_intrinsic_event(codec, res); |
| 1206 | else |
| 1207 | hdmi_non_intrinsic_event(codec, res); |
| 1208 | } |
| 1209 | |
Mengdong Lin | 58f7d28 | 2013-09-04 16:37:12 -0400 | [diff] [blame] | 1210 | static void haswell_verify_D0(struct hda_codec *codec, |
Wang Xingchao | 53b434f | 2013-06-18 10:41:53 +0800 | [diff] [blame] | 1211 | hda_nid_t cvt_nid, hda_nid_t nid) |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 1212 | { |
Mengdong Lin | 58f7d28 | 2013-09-04 16:37:12 -0400 | [diff] [blame] | 1213 | int pwr; |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 1214 | |
Wang Xingchao | 53b434f | 2013-06-18 10:41:53 +0800 | [diff] [blame] | 1215 | /* For Haswell, the converter 1/2 may keep in D3 state after bootup, |
| 1216 | * thus pins could only choose converter 0 for use. Make sure the |
| 1217 | * converters are in correct power state */ |
Takashi Iwai | fd678ca | 2013-06-18 16:28:36 +0200 | [diff] [blame] | 1218 | if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0)) |
Wang Xingchao | 53b434f | 2013-06-18 10:41:53 +0800 | [diff] [blame] | 1219 | snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 1220 | |
Takashi Iwai | fd678ca | 2013-06-18 16:28:36 +0200 | [diff] [blame] | 1221 | if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) { |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 1222 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, |
| 1223 | AC_PWRST_D0); |
| 1224 | msleep(40); |
| 1225 | pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0); |
| 1226 | pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT; |
| 1227 | snd_printd("Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr); |
| 1228 | } |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 1229 | } |
| 1230 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1231 | /* |
| 1232 | * Callbacks |
| 1233 | */ |
| 1234 | |
Takashi Iwai | 92f10b3 | 2010-08-03 14:21:00 +0200 | [diff] [blame] | 1235 | /* HBR should be Non-PCM, 8 channels */ |
| 1236 | #define is_hbr_format(format) \ |
| 1237 | ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7) |
| 1238 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1239 | static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid, |
| 1240 | bool hbr) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1241 | { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1242 | int pinctl, new_pinctl; |
David Henningsson | 83f26ad | 2013-04-10 12:26:07 +0200 | [diff] [blame] | 1243 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1244 | if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) { |
| 1245 | pinctl = snd_hda_codec_read(codec, pin_nid, 0, |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 1246 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 1247 | |
| 1248 | new_pinctl = pinctl & ~AC_PINCTL_EPT; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1249 | if (hbr) |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 1250 | new_pinctl |= AC_PINCTL_EPT_HBR; |
| 1251 | else |
| 1252 | new_pinctl |= AC_PINCTL_EPT_NATIVE; |
| 1253 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1254 | snd_printdd("hdmi_pin_hbr_setup: " |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 1255 | "NID=0x%x, %spinctl=0x%x\n", |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1256 | pin_nid, |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 1257 | pinctl == new_pinctl ? "" : "new-", |
| 1258 | new_pinctl); |
| 1259 | |
| 1260 | if (pinctl != new_pinctl) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1261 | snd_hda_codec_write(codec, pin_nid, 0, |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 1262 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1263 | new_pinctl); |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1264 | } else if (hbr) |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 1265 | return -EINVAL; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1266 | |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, |
| 1271 | hda_nid_t pin_nid, u32 stream_tag, int format) |
| 1272 | { |
| 1273 | struct hdmi_spec *spec = codec->spec; |
| 1274 | int err; |
| 1275 | |
| 1276 | if (is_haswell(codec)) |
| 1277 | haswell_verify_D0(codec, cvt_nid, pin_nid); |
| 1278 | |
| 1279 | err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format)); |
| 1280 | |
| 1281 | if (err) { |
| 1282 | snd_printdd("hdmi_setup_stream: HBR is not supported\n"); |
| 1283 | return err; |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 1284 | } |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1285 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1286 | snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format); |
Anssi Hannula | ea87d1c | 2010-08-03 13:28:58 +0300 | [diff] [blame] | 1287 | return 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1288 | } |
| 1289 | |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1290 | static int hdmi_choose_cvt(struct hda_codec *codec, |
| 1291 | int pin_idx, int *cvt_id, int *mux_id) |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1292 | { |
| 1293 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1294 | struct hdmi_spec_per_pin *per_pin; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1295 | struct hdmi_spec_per_cvt *per_cvt = NULL; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1296 | int cvt_idx, mux_idx = 0; |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1297 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1298 | per_pin = get_pin(spec, pin_idx); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1299 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1300 | /* Dynamically assign converter to stream */ |
| 1301 | for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1302 | per_cvt = get_cvt(spec, cvt_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1303 | |
| 1304 | /* Must not already be assigned */ |
| 1305 | if (per_cvt->assigned) |
| 1306 | continue; |
| 1307 | /* Must be in pin's mux's list of converters */ |
| 1308 | for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++) |
| 1309 | if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid) |
| 1310 | break; |
| 1311 | /* Not in mux list */ |
| 1312 | if (mux_idx == per_pin->num_mux_nids) |
| 1313 | continue; |
| 1314 | break; |
| 1315 | } |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1316 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1317 | /* No free converters */ |
| 1318 | if (cvt_idx == spec->num_cvts) |
| 1319 | return -ENODEV; |
| 1320 | |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1321 | if (cvt_id) |
| 1322 | *cvt_id = cvt_idx; |
| 1323 | if (mux_id) |
| 1324 | *mux_id = mux_idx; |
| 1325 | |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
| 1329 | static void haswell_config_cvts(struct hda_codec *codec, |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1330 | hda_nid_t pin_nid, int mux_idx) |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1331 | { |
| 1332 | struct hdmi_spec *spec = codec->spec; |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1333 | hda_nid_t nid, end_nid; |
| 1334 | int cvt_idx, curr; |
| 1335 | struct hdmi_spec_per_cvt *per_cvt; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1336 | |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1337 | /* configure all pins, including "no physical connection" ones */ |
| 1338 | end_nid = codec->start_nid + codec->num_nodes; |
| 1339 | for (nid = codec->start_nid; nid < end_nid; nid++) { |
| 1340 | unsigned int wid_caps = get_wcaps(codec, nid); |
| 1341 | unsigned int wid_type = get_wcaps_type(wid_caps); |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1342 | |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1343 | if (wid_type != AC_WID_PIN) |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1344 | continue; |
| 1345 | |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1346 | if (nid == pin_nid) |
| 1347 | continue; |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1348 | |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1349 | curr = snd_hda_codec_read(codec, nid, 0, |
| 1350 | AC_VERB_GET_CONNECT_SEL, 0); |
| 1351 | if (curr != mux_idx) |
| 1352 | continue; |
| 1353 | |
| 1354 | /* choose an unassigned converter. The conveters in the |
| 1355 | * connection list are in the same order as in the codec. |
| 1356 | */ |
| 1357 | for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { |
| 1358 | per_cvt = get_cvt(spec, cvt_idx); |
| 1359 | if (!per_cvt->assigned) { |
| 1360 | snd_printdd("choose cvt %d for pin nid %d\n", |
| 1361 | cvt_idx, nid); |
| 1362 | snd_hda_codec_write_cache(codec, nid, 0, |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1363 | AC_VERB_SET_CONNECT_SEL, |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1364 | cvt_idx); |
| 1365 | break; |
| 1366 | } |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | /* |
| 1372 | * HDA PCM callbacks |
| 1373 | */ |
| 1374 | static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, |
| 1375 | struct hda_codec *codec, |
| 1376 | struct snd_pcm_substream *substream) |
| 1377 | { |
| 1378 | struct hdmi_spec *spec = codec->spec; |
| 1379 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1380 | int pin_idx, cvt_idx, mux_idx = 0; |
| 1381 | struct hdmi_spec_per_pin *per_pin; |
| 1382 | struct hdmi_eld *eld; |
| 1383 | struct hdmi_spec_per_cvt *per_cvt = NULL; |
| 1384 | int err; |
| 1385 | |
| 1386 | /* Validate hinfo */ |
| 1387 | pin_idx = hinfo_to_pin_index(spec, hinfo); |
| 1388 | if (snd_BUG_ON(pin_idx < 0)) |
| 1389 | return -EINVAL; |
| 1390 | per_pin = get_pin(spec, pin_idx); |
| 1391 | eld = &per_pin->sink_eld; |
| 1392 | |
| 1393 | err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx); |
| 1394 | if (err < 0) |
| 1395 | return err; |
| 1396 | |
| 1397 | per_cvt = get_cvt(spec, cvt_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1398 | /* Claim converter */ |
| 1399 | per_cvt->assigned = 1; |
Anssi Hannula | 1df5a06 | 2013-10-05 02:25:40 +0300 | [diff] [blame] | 1400 | per_pin->cvt_nid = per_cvt->cvt_nid; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1401 | hinfo->nid = per_cvt->cvt_nid; |
| 1402 | |
Takashi Iwai | bddee96 | 2013-06-18 16:14:22 +0200 | [diff] [blame] | 1403 | snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1404 | AC_VERB_SET_CONNECT_SEL, |
| 1405 | mux_idx); |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1406 | |
| 1407 | /* configure unused pins to choose other converters */ |
Mengdong Lin | fb87fa3 | 2013-09-04 16:36:57 -0400 | [diff] [blame] | 1408 | if (is_haswell(codec)) |
Mengdong Lin | f82d7d1 | 2013-09-21 20:34:45 -0400 | [diff] [blame] | 1409 | haswell_config_cvts(codec, per_pin->pin_nid, mux_idx); |
Wang Xingchao | 7ef166b | 2013-06-18 21:42:14 +0800 | [diff] [blame] | 1410 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1411 | snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1412 | |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 1413 | /* Initially set the converter's capabilities */ |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1414 | hinfo->channels_min = per_cvt->channels_min; |
| 1415 | hinfo->channels_max = per_cvt->channels_max; |
| 1416 | hinfo->rates = per_cvt->rates; |
| 1417 | hinfo->formats = per_cvt->formats; |
| 1418 | hinfo->maxbps = per_cvt->maxbps; |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 1419 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1420 | /* Restrict capabilities by ELD if this isn't disabled */ |
Stephen Warren | c3d5210 | 2011-06-01 11:14:16 -0600 | [diff] [blame] | 1421 | if (!static_hdmi_pcm && eld->eld_valid) { |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 1422 | snd_hdmi_eld_update_pcm_info(&eld->info, hinfo); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1423 | if (hinfo->channels_min > hinfo->channels_max || |
Takashi Iwai | 2ad779b | 2013-02-01 14:01:27 +0100 | [diff] [blame] | 1424 | !hinfo->rates || !hinfo->formats) { |
| 1425 | per_cvt->assigned = 0; |
| 1426 | hinfo->nid = 0; |
| 1427 | snd_hda_spdif_ctls_unassign(codec, pin_idx); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1428 | return -ENODEV; |
Takashi Iwai | 2ad779b | 2013-02-01 14:01:27 +0100 | [diff] [blame] | 1429 | } |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1430 | } |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 1431 | |
| 1432 | /* Store the updated parameters */ |
Takashi Iwai | 639cef0 | 2011-01-14 10:30:46 +0100 | [diff] [blame] | 1433 | runtime->hw.channels_min = hinfo->channels_min; |
| 1434 | runtime->hw.channels_max = hinfo->channels_max; |
| 1435 | runtime->hw.formats = hinfo->formats; |
| 1436 | runtime->hw.rates = hinfo->rates; |
Takashi Iwai | 4fe2ca1 | 2011-01-14 10:33:26 +0100 | [diff] [blame] | 1437 | |
| 1438 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 1439 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
| 1442 | |
| 1443 | /* |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1444 | * HDA/HDMI auto parsing |
| 1445 | */ |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1446 | static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1447 | { |
| 1448 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1449 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1450 | hda_nid_t pin_nid = per_pin->pin_nid; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1451 | |
| 1452 | if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { |
| 1453 | snd_printk(KERN_WARNING |
| 1454 | "HDMI: pin %d wcaps %#x " |
| 1455 | "does not support connection list\n", |
| 1456 | pin_nid, get_wcaps(codec, pin_nid)); |
| 1457 | return -EINVAL; |
| 1458 | } |
| 1459 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1460 | per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid, |
| 1461 | per_pin->mux_nids, |
| 1462 | HDA_MAX_CONNECTIONS); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1463 | |
| 1464 | return 0; |
| 1465 | } |
| 1466 | |
Wu Fengguang | c6e8453 | 2011-11-18 16:59:32 -0600 | [diff] [blame] | 1467 | static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1468 | { |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1469 | struct hda_codec *codec = per_pin->codec; |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1470 | struct hdmi_spec *spec = codec->spec; |
| 1471 | struct hdmi_eld *eld = &spec->temp_eld; |
| 1472 | struct hdmi_eld *pin_eld = &per_pin->sink_eld; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1473 | hda_nid_t pin_nid = per_pin->pin_nid; |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 1474 | /* |
| 1475 | * Always execute a GetPinSense verb here, even when called from |
| 1476 | * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited |
| 1477 | * response's PD bit is not the real PD value, but indicates that |
| 1478 | * the real PD value changed. An older version of the HD-audio |
| 1479 | * specification worked this way. Hence, we just ignore the data in |
| 1480 | * the unsolicited response to avoid custom WARs. |
| 1481 | */ |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1482 | int present = snd_hda_pin_sense(codec, pin_nid); |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1483 | bool update_eld = false; |
| 1484 | bool eld_changed = false; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1485 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1486 | mutex_lock(&per_pin->lock); |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1487 | pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); |
| 1488 | if (pin_eld->monitor_present) |
| 1489 | eld->eld_valid = !!(present & AC_PINSENSE_ELDV); |
| 1490 | else |
| 1491 | eld->eld_valid = false; |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 1492 | |
Fengguang Wu | fae3d88 | 2012-04-10 17:00:35 +0800 | [diff] [blame] | 1493 | _snd_printd(SND_PR_VERBOSE, |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1494 | "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n", |
Mengdong Lin | 1025091 | 2013-03-28 05:21:28 -0400 | [diff] [blame] | 1495 | codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid); |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 1496 | |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1497 | if (eld->eld_valid) { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1498 | if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer, |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 1499 | &eld->eld_size) < 0) |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1500 | eld->eld_valid = false; |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 1501 | else { |
| 1502 | memset(&eld->info, 0, sizeof(struct parsed_hdmi_eld)); |
| 1503 | if (snd_hdmi_parse_eld(&eld->info, eld->eld_buffer, |
| 1504 | eld->eld_size) < 0) |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1505 | eld->eld_valid = false; |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 1506 | } |
| 1507 | |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1508 | if (eld->eld_valid) { |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 1509 | snd_hdmi_show_eld(&eld->info); |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1510 | update_eld = true; |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 1511 | } |
Wu Fengguang | c6e8453 | 2011-11-18 16:59:32 -0600 | [diff] [blame] | 1512 | else if (repoll) { |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1513 | queue_delayed_work(codec->bus->workq, |
| 1514 | &per_pin->work, |
| 1515 | msecs_to_jiffies(300)); |
Takashi Iwai | cbbaa60 | 2013-10-17 18:03:24 +0200 | [diff] [blame] | 1516 | goto unlock; |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1517 | } |
| 1518 | } |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1519 | |
David Henningsson | 92c69e7 | 2013-02-19 16:11:26 +0100 | [diff] [blame] | 1520 | if (pin_eld->eld_valid && !eld->eld_valid) { |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1521 | update_eld = true; |
David Henningsson | 92c69e7 | 2013-02-19 16:11:26 +0100 | [diff] [blame] | 1522 | eld_changed = true; |
| 1523 | } |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1524 | if (update_eld) { |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1525 | bool old_eld_valid = pin_eld->eld_valid; |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1526 | pin_eld->eld_valid = eld->eld_valid; |
David Henningsson | 92c69e7 | 2013-02-19 16:11:26 +0100 | [diff] [blame] | 1527 | eld_changed = pin_eld->eld_size != eld->eld_size || |
| 1528 | memcmp(pin_eld->eld_buffer, eld->eld_buffer, |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1529 | eld->eld_size) != 0; |
| 1530 | if (eld_changed) |
| 1531 | memcpy(pin_eld->eld_buffer, eld->eld_buffer, |
| 1532 | eld->eld_size); |
| 1533 | pin_eld->eld_size = eld->eld_size; |
| 1534 | pin_eld->info = eld->info; |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1535 | |
| 1536 | /* Haswell-specific workaround: re-setup when the transcoder is |
| 1537 | * changed during the stream playback |
| 1538 | */ |
Mengdong Lin | fb87fa3 | 2013-09-04 16:36:57 -0400 | [diff] [blame] | 1539 | if (is_haswell(codec) && |
Mengdong Lin | 58f7d28 | 2013-09-04 16:37:12 -0400 | [diff] [blame] | 1540 | eld->eld_valid && !old_eld_valid && per_pin->setup) |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1541 | hdmi_setup_audio_infoframe(codec, per_pin, |
| 1542 | per_pin->non_pcm); |
David Henningsson | 4bd038f | 2013-02-19 16:11:25 +0100 | [diff] [blame] | 1543 | } |
David Henningsson | 92c69e7 | 2013-02-19 16:11:26 +0100 | [diff] [blame] | 1544 | |
| 1545 | if (eld_changed) |
| 1546 | snd_ctl_notify(codec->bus->card, |
| 1547 | SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, |
| 1548 | &per_pin->eld_ctl->id); |
Takashi Iwai | cbbaa60 | 2013-10-17 18:03:24 +0200 | [diff] [blame] | 1549 | unlock: |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1550 | mutex_unlock(&per_pin->lock); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1551 | } |
| 1552 | |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1553 | static void hdmi_repoll_eld(struct work_struct *work) |
| 1554 | { |
| 1555 | struct hdmi_spec_per_pin *per_pin = |
| 1556 | container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work); |
| 1557 | |
Wu Fengguang | c6e8453 | 2011-11-18 16:59:32 -0600 | [diff] [blame] | 1558 | if (per_pin->repoll_count++ > 6) |
| 1559 | per_pin->repoll_count = 0; |
| 1560 | |
| 1561 | hdmi_present_sense(per_pin, per_pin->repoll_count); |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 1562 | } |
| 1563 | |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 1564 | static void intel_haswell_fixup_connect_list(struct hda_codec *codec, |
| 1565 | hda_nid_t nid); |
| 1566 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1567 | static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) |
| 1568 | { |
| 1569 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1570 | unsigned int caps, config; |
| 1571 | int pin_idx; |
| 1572 | struct hdmi_spec_per_pin *per_pin; |
David Henningsson | 07acecc | 2011-05-19 11:46:03 +0200 | [diff] [blame] | 1573 | int err; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1574 | |
Takashi Iwai | efc2f8de | 2012-11-21 14:27:37 +0100 | [diff] [blame] | 1575 | caps = snd_hda_query_pin_caps(codec, pin_nid); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1576 | if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) |
| 1577 | return 0; |
| 1578 | |
Takashi Iwai | efc2f8de | 2012-11-21 14:27:37 +0100 | [diff] [blame] | 1579 | config = snd_hda_codec_get_pincfg(codec, pin_nid); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1580 | if (get_defcfg_connect(config) == AC_JACK_PORT_NONE) |
| 1581 | return 0; |
| 1582 | |
Mengdong Lin | fb87fa3 | 2013-09-04 16:36:57 -0400 | [diff] [blame] | 1583 | if (is_haswell(codec)) |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 1584 | intel_haswell_fixup_connect_list(codec, pin_nid); |
| 1585 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1586 | pin_idx = spec->num_pins; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1587 | per_pin = snd_array_new(&spec->pins); |
| 1588 | if (!per_pin) |
| 1589 | return -ENOMEM; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1590 | |
| 1591 | per_pin->pin_nid = pin_nid; |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 1592 | per_pin->non_pcm = false; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1593 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1594 | err = hdmi_read_pin_conn(codec, pin_idx); |
| 1595 | if (err < 0) |
| 1596 | return err; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1597 | |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1598 | spec->num_pins++; |
| 1599 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1600 | return 0; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1601 | } |
| 1602 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1603 | static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1604 | { |
| 1605 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1606 | struct hdmi_spec_per_cvt *per_cvt; |
| 1607 | unsigned int chans; |
| 1608 | int err; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1609 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1610 | chans = get_wcaps(codec, cvt_nid); |
| 1611 | chans = get_wcaps_channels(chans); |
| 1612 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1613 | per_cvt = snd_array_new(&spec->cvts); |
| 1614 | if (!per_cvt) |
| 1615 | return -ENOMEM; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1616 | |
| 1617 | per_cvt->cvt_nid = cvt_nid; |
| 1618 | per_cvt->channels_min = 2; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1619 | if (chans <= 16) { |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1620 | per_cvt->channels_max = chans; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1621 | if (chans > spec->channels_max) |
| 1622 | spec->channels_max = chans; |
| 1623 | } |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1624 | |
| 1625 | err = snd_hda_query_supported_pcm(codec, cvt_nid, |
| 1626 | &per_cvt->rates, |
| 1627 | &per_cvt->formats, |
| 1628 | &per_cvt->maxbps); |
| 1629 | if (err < 0) |
| 1630 | return err; |
| 1631 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1632 | if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids)) |
| 1633 | spec->cvt_nids[spec->num_cvts] = cvt_nid; |
| 1634 | spec->num_cvts++; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1635 | |
| 1636 | return 0; |
| 1637 | } |
| 1638 | |
| 1639 | static int hdmi_parse_codec(struct hda_codec *codec) |
| 1640 | { |
| 1641 | hda_nid_t nid; |
| 1642 | int i, nodes; |
| 1643 | |
| 1644 | nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); |
| 1645 | if (!nid || nodes < 0) { |
| 1646 | snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n"); |
| 1647 | return -EINVAL; |
| 1648 | } |
| 1649 | |
| 1650 | for (i = 0; i < nodes; i++, nid++) { |
| 1651 | unsigned int caps; |
| 1652 | unsigned int type; |
| 1653 | |
Takashi Iwai | efc2f8de | 2012-11-21 14:27:37 +0100 | [diff] [blame] | 1654 | caps = get_wcaps(codec, nid); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1655 | type = get_wcaps_type(caps); |
| 1656 | |
| 1657 | if (!(caps & AC_WCAP_DIGITAL)) |
| 1658 | continue; |
| 1659 | |
| 1660 | switch (type) { |
| 1661 | case AC_WID_AUD_OUT: |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1662 | hdmi_add_cvt(codec, nid); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1663 | break; |
| 1664 | case AC_WID_PIN: |
Wu Fengguang | 3eaead5 | 2010-05-14 16:36:15 +0800 | [diff] [blame] | 1665 | hdmi_add_pin(codec, nid); |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1666 | break; |
| 1667 | } |
| 1668 | } |
| 1669 | |
David Henningsson | c9adeef | 2012-11-07 09:22:33 +0100 | [diff] [blame] | 1670 | #ifdef CONFIG_PM |
| 1671 | /* We're seeing some problems with unsolicited hot plug events on |
| 1672 | * PantherPoint after S3, if this is not enabled */ |
| 1673 | if (codec->vendor_id == 0x80862806) |
| 1674 | codec->bus->power_keep_link_on = 1; |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1675 | /* |
| 1676 | * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event |
| 1677 | * can be lost and presence sense verb will become inaccurate if the |
| 1678 | * HDA link is powered off at hot plug or hw initialization time. |
| 1679 | */ |
David Henningsson | c9adeef | 2012-11-07 09:22:33 +0100 | [diff] [blame] | 1680 | else if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) & |
Wu Fengguang | 079d88c | 2010-03-08 10:44:23 +0800 | [diff] [blame] | 1681 | AC_PWRST_EPSS)) |
| 1682 | codec->bus->power_keep_link_on = 1; |
| 1683 | #endif |
| 1684 | |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1688 | /* |
| 1689 | */ |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 1690 | static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) |
| 1691 | { |
| 1692 | struct hda_spdif_out *spdif; |
| 1693 | bool non_pcm; |
| 1694 | |
| 1695 | mutex_lock(&codec->spdif_mutex); |
| 1696 | spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid); |
| 1697 | non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO); |
| 1698 | mutex_unlock(&codec->spdif_mutex); |
| 1699 | return non_pcm; |
| 1700 | } |
| 1701 | |
| 1702 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1703 | /* |
| 1704 | * HDMI callbacks |
| 1705 | */ |
| 1706 | |
| 1707 | static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1708 | struct hda_codec *codec, |
| 1709 | unsigned int stream_tag, |
| 1710 | unsigned int format, |
| 1711 | struct snd_pcm_substream *substream) |
| 1712 | { |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1713 | hda_nid_t cvt_nid = hinfo->nid; |
| 1714 | struct hdmi_spec *spec = codec->spec; |
| 1715 | int pin_idx = hinfo_to_pin_index(spec, hinfo); |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1716 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
| 1717 | hda_nid_t pin_nid = per_pin->pin_nid; |
Takashi Iwai | 1a6003b | 2012-09-06 17:42:08 +0200 | [diff] [blame] | 1718 | bool non_pcm; |
| 1719 | |
| 1720 | non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1721 | mutex_lock(&per_pin->lock); |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1722 | per_pin->channels = substream->runtime->channels; |
| 1723 | per_pin->setup = true; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1724 | |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1725 | hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1726 | mutex_unlock(&per_pin->lock); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1727 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1728 | return spec->ops.setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1729 | } |
| 1730 | |
Takashi Iwai | 8dfaa57 | 2012-08-06 14:49:36 +0200 | [diff] [blame] | 1731 | static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1732 | struct hda_codec *codec, |
| 1733 | struct snd_pcm_substream *substream) |
| 1734 | { |
| 1735 | snd_hda_codec_cleanup_stream(codec, hinfo->nid); |
| 1736 | return 0; |
| 1737 | } |
| 1738 | |
Takashi Iwai | f2ad24f | 2012-07-26 18:08:14 +0200 | [diff] [blame] | 1739 | static int hdmi_pcm_close(struct hda_pcm_stream *hinfo, |
| 1740 | struct hda_codec *codec, |
| 1741 | struct snd_pcm_substream *substream) |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1742 | { |
| 1743 | struct hdmi_spec *spec = codec->spec; |
| 1744 | int cvt_idx, pin_idx; |
| 1745 | struct hdmi_spec_per_cvt *per_cvt; |
| 1746 | struct hdmi_spec_per_pin *per_pin; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1747 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1748 | if (hinfo->nid) { |
| 1749 | cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid); |
| 1750 | if (snd_BUG_ON(cvt_idx < 0)) |
| 1751 | return -EINVAL; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1752 | per_cvt = get_cvt(spec, cvt_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1753 | |
| 1754 | snd_BUG_ON(!per_cvt->assigned); |
| 1755 | per_cvt->assigned = 0; |
| 1756 | hinfo->nid = 0; |
| 1757 | |
| 1758 | pin_idx = hinfo_to_pin_index(spec, hinfo); |
| 1759 | if (snd_BUG_ON(pin_idx < 0)) |
| 1760 | return -EINVAL; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1761 | per_pin = get_pin(spec, pin_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1762 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1763 | snd_hda_spdif_ctls_unassign(codec, pin_idx); |
Takashi Iwai | cbbaa60 | 2013-10-17 18:03:24 +0200 | [diff] [blame] | 1764 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1765 | mutex_lock(&per_pin->lock); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1766 | per_pin->chmap_set = false; |
| 1767 | memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1768 | |
| 1769 | per_pin->setup = false; |
| 1770 | per_pin->channels = 0; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1771 | mutex_unlock(&per_pin->lock); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1772 | } |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1773 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1774 | return 0; |
| 1775 | } |
| 1776 | |
| 1777 | static const struct hda_pcm_ops generic_ops = { |
| 1778 | .open = hdmi_pcm_open, |
Takashi Iwai | f2ad24f | 2012-07-26 18:08:14 +0200 | [diff] [blame] | 1779 | .close = hdmi_pcm_close, |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1780 | .prepare = generic_hdmi_playback_pcm_prepare, |
Takashi Iwai | 8dfaa57 | 2012-08-06 14:49:36 +0200 | [diff] [blame] | 1781 | .cleanup = generic_hdmi_playback_pcm_cleanup, |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1782 | }; |
| 1783 | |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1784 | /* |
| 1785 | * ALSA API channel-map control callbacks |
| 1786 | */ |
| 1787 | static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol, |
| 1788 | struct snd_ctl_elem_info *uinfo) |
| 1789 | { |
| 1790 | struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); |
| 1791 | struct hda_codec *codec = info->private_data; |
| 1792 | struct hdmi_spec *spec = codec->spec; |
| 1793 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1794 | uinfo->count = spec->channels_max; |
| 1795 | uinfo->value.integer.min = 0; |
| 1796 | uinfo->value.integer.max = SNDRV_CHMAP_LAST; |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1800 | static int hdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap, |
| 1801 | int channels) |
| 1802 | { |
| 1803 | /* If the speaker allocation matches the channel count, it is OK.*/ |
| 1804 | if (cap->channels != channels) |
| 1805 | return -1; |
| 1806 | |
| 1807 | /* all channels are remappable freely */ |
| 1808 | return SNDRV_CTL_TLVT_CHMAP_VAR; |
| 1809 | } |
| 1810 | |
| 1811 | static void hdmi_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap, |
| 1812 | unsigned int *chmap, int channels) |
| 1813 | { |
| 1814 | int count = 0; |
| 1815 | int c; |
| 1816 | |
| 1817 | for (c = 7; c >= 0; c--) { |
| 1818 | int spk = cap->speakers[c]; |
| 1819 | if (!spk) |
| 1820 | continue; |
| 1821 | |
| 1822 | chmap[count++] = spk_to_chmap(spk); |
| 1823 | } |
| 1824 | |
| 1825 | WARN_ON(count != channels); |
| 1826 | } |
| 1827 | |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1828 | static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 1829 | unsigned int size, unsigned int __user *tlv) |
| 1830 | { |
| 1831 | struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); |
| 1832 | struct hda_codec *codec = info->private_data; |
| 1833 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1834 | unsigned int __user *dst; |
| 1835 | int chs, count = 0; |
| 1836 | |
| 1837 | if (size < 8) |
| 1838 | return -ENOMEM; |
| 1839 | if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv)) |
| 1840 | return -EFAULT; |
| 1841 | size -= 8; |
| 1842 | dst = tlv + 2; |
Takashi Iwai | 498dab3 | 2012-09-10 16:08:40 +0200 | [diff] [blame] | 1843 | for (chs = 2; chs <= spec->channels_max; chs++) { |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1844 | int i; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1845 | struct cea_channel_speaker_allocation *cap; |
| 1846 | cap = channel_allocations; |
| 1847 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) { |
| 1848 | int chs_bytes = chs * 4; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1849 | int type = spec->ops.chmap_cea_alloc_validate_get_type(cap, chs); |
| 1850 | unsigned int tlv_chmap[8]; |
| 1851 | |
| 1852 | if (type < 0) |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1853 | continue; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1854 | if (size < 8) |
| 1855 | return -ENOMEM; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1856 | if (put_user(type, dst) || |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1857 | put_user(chs_bytes, dst + 1)) |
| 1858 | return -EFAULT; |
| 1859 | dst += 2; |
| 1860 | size -= 8; |
| 1861 | count += 8; |
| 1862 | if (size < chs_bytes) |
| 1863 | return -ENOMEM; |
| 1864 | size -= chs_bytes; |
| 1865 | count += chs_bytes; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1866 | spec->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs); |
| 1867 | if (copy_to_user(dst, tlv_chmap, chs_bytes)) |
| 1868 | return -EFAULT; |
| 1869 | dst += chs; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1870 | } |
| 1871 | } |
| 1872 | if (put_user(count, tlv + 1)) |
| 1873 | return -EFAULT; |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
| 1877 | static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol, |
| 1878 | struct snd_ctl_elem_value *ucontrol) |
| 1879 | { |
| 1880 | struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); |
| 1881 | struct hda_codec *codec = info->private_data; |
| 1882 | struct hdmi_spec *spec = codec->spec; |
| 1883 | int pin_idx = kcontrol->private_value; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1884 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1885 | int i; |
| 1886 | |
| 1887 | for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++) |
| 1888 | ucontrol->value.integer.value[i] = per_pin->chmap[i]; |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
| 1892 | static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol, |
| 1893 | struct snd_ctl_elem_value *ucontrol) |
| 1894 | { |
| 1895 | struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); |
| 1896 | struct hda_codec *codec = info->private_data; |
| 1897 | struct hdmi_spec *spec = codec->spec; |
| 1898 | int pin_idx = kcontrol->private_value; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1899 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1900 | unsigned int ctl_idx; |
| 1901 | struct snd_pcm_substream *substream; |
| 1902 | unsigned char chmap[8]; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1903 | int i, err, ca, prepared = 0; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1904 | |
| 1905 | ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 1906 | substream = snd_pcm_chmap_substream(info, ctl_idx); |
| 1907 | if (!substream || !substream->runtime) |
Takashi Iwai | 6f54c36 | 2013-01-15 14:44:41 +0100 | [diff] [blame] | 1908 | return 0; /* just for avoiding error from alsactl restore */ |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1909 | switch (substream->runtime->status->state) { |
| 1910 | case SNDRV_PCM_STATE_OPEN: |
| 1911 | case SNDRV_PCM_STATE_SETUP: |
| 1912 | break; |
| 1913 | case SNDRV_PCM_STATE_PREPARED: |
| 1914 | prepared = 1; |
| 1915 | break; |
| 1916 | default: |
| 1917 | return -EBUSY; |
| 1918 | } |
| 1919 | memset(chmap, 0, sizeof(chmap)); |
| 1920 | for (i = 0; i < ARRAY_SIZE(chmap); i++) |
| 1921 | chmap[i] = ucontrol->value.integer.value[i]; |
| 1922 | if (!memcmp(chmap, per_pin->chmap, sizeof(chmap))) |
| 1923 | return 0; |
| 1924 | ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap); |
| 1925 | if (ca < 0) |
| 1926 | return -EINVAL; |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 1927 | if (spec->ops.chmap_validate) { |
| 1928 | err = spec->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap); |
| 1929 | if (err) |
| 1930 | return err; |
| 1931 | } |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1932 | mutex_lock(&per_pin->lock); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1933 | per_pin->chmap_set = true; |
| 1934 | memcpy(per_pin->chmap, chmap, sizeof(chmap)); |
| 1935 | if (prepared) |
Takashi Iwai | b054087 | 2013-09-02 12:33:02 +0200 | [diff] [blame] | 1936 | hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 1937 | mutex_unlock(&per_pin->lock); |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1938 | |
| 1939 | return 0; |
| 1940 | } |
| 1941 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1942 | static int generic_hdmi_build_pcms(struct hda_codec *codec) |
| 1943 | { |
| 1944 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1945 | int pin_idx; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1946 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1947 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
| 1948 | struct hda_pcm *info; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1949 | struct hda_pcm_stream *pstr; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1950 | struct hdmi_spec_per_pin *per_pin; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1951 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1952 | per_pin = get_pin(spec, pin_idx); |
| 1953 | sprintf(per_pin->pcm_name, "HDMI %d", pin_idx); |
| 1954 | info = snd_array_new(&spec->pcm_rec); |
| 1955 | if (!info) |
| 1956 | return -ENOMEM; |
| 1957 | info->name = per_pin->pcm_name; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1958 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 1959 | info->own_chmap = true; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1960 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1961 | pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1962 | pstr->substreams = 1; |
| 1963 | pstr->ops = generic_ops; |
| 1964 | /* other pstr fields are set in open */ |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1965 | } |
| 1966 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1967 | codec->num_pcms = spec->num_pins; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1968 | codec->pcm_info = spec->pcm_rec.list; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1969 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1970 | return 0; |
| 1971 | } |
| 1972 | |
David Henningsson | 0b6c49b | 2011-08-23 16:56:03 +0200 | [diff] [blame] | 1973 | static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx) |
| 1974 | { |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 1975 | char hdmi_str[32] = "HDMI/DP"; |
David Henningsson | 0b6c49b | 2011-08-23 16:56:03 +0200 | [diff] [blame] | 1976 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1977 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
| 1978 | int pcmdev = get_pcm_rec(spec, pin_idx)->device; |
David Henningsson | 0b6c49b | 2011-08-23 16:56:03 +0200 | [diff] [blame] | 1979 | |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 1980 | if (pcmdev > 0) |
| 1981 | sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev); |
David Henningsson | 30efd8d | 2013-02-22 10:16:28 +0100 | [diff] [blame] | 1982 | if (!is_jack_detectable(codec, per_pin->pin_nid)) |
| 1983 | strncat(hdmi_str, " Phantom", |
| 1984 | sizeof(hdmi_str) - strlen(hdmi_str) - 1); |
David Henningsson | 0b6c49b | 2011-08-23 16:56:03 +0200 | [diff] [blame] | 1985 | |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 1986 | return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0); |
David Henningsson | 0b6c49b | 2011-08-23 16:56:03 +0200 | [diff] [blame] | 1987 | } |
| 1988 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1989 | static int generic_hdmi_build_controls(struct hda_codec *codec) |
| 1990 | { |
| 1991 | struct hdmi_spec *spec = codec->spec; |
| 1992 | int err; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1993 | int pin_idx; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 1994 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 1995 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 1996 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
David Henningsson | 0b6c49b | 2011-08-23 16:56:03 +0200 | [diff] [blame] | 1997 | |
| 1998 | err = generic_hdmi_build_jack(codec, pin_idx); |
| 1999 | if (err < 0) |
| 2000 | return err; |
| 2001 | |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 2002 | err = snd_hda_create_dig_out_ctls(codec, |
| 2003 | per_pin->pin_nid, |
| 2004 | per_pin->mux_nids[0], |
| 2005 | HDA_PCM_TYPE_HDMI); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2006 | if (err < 0) |
| 2007 | return err; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2008 | snd_hda_spdif_ctls_unassign(codec, pin_idx); |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 2009 | |
| 2010 | /* add control for ELD Bytes */ |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2011 | err = hdmi_create_eld_ctl(codec, pin_idx, |
| 2012 | get_pcm_rec(spec, pin_idx)->device); |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 2013 | |
| 2014 | if (err < 0) |
| 2015 | return err; |
Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 2016 | |
Takashi Iwai | 82b1d73 | 2011-12-20 15:53:07 +0100 | [diff] [blame] | 2017 | hdmi_present_sense(per_pin, 0); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2018 | } |
| 2019 | |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 2020 | /* add channel maps */ |
| 2021 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
| 2022 | struct snd_pcm_chmap *chmap; |
| 2023 | struct snd_kcontrol *kctl; |
| 2024 | int i; |
Takashi Iwai | 2ca320e | 2013-08-22 09:55:36 +0200 | [diff] [blame] | 2025 | |
| 2026 | if (!codec->pcm_info[pin_idx].pcm) |
| 2027 | break; |
Takashi Iwai | d45e688 | 2012-07-31 11:36:00 +0200 | [diff] [blame] | 2028 | err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm, |
| 2029 | SNDRV_PCM_STREAM_PLAYBACK, |
| 2030 | NULL, 0, pin_idx, &chmap); |
| 2031 | if (err < 0) |
| 2032 | return err; |
| 2033 | /* override handlers */ |
| 2034 | chmap->private_data = codec; |
| 2035 | kctl = chmap->kctl; |
| 2036 | for (i = 0; i < kctl->count; i++) |
| 2037 | kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE; |
| 2038 | kctl->info = hdmi_chmap_ctl_info; |
| 2039 | kctl->get = hdmi_chmap_ctl_get; |
| 2040 | kctl->put = hdmi_chmap_ctl_put; |
| 2041 | kctl->tlv.c = hdmi_chmap_ctl_tlv; |
| 2042 | } |
| 2043 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2044 | return 0; |
| 2045 | } |
| 2046 | |
Takashi Iwai | 8b8d654 | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2047 | static int generic_hdmi_init_per_pins(struct hda_codec *codec) |
| 2048 | { |
| 2049 | struct hdmi_spec *spec = codec->spec; |
| 2050 | int pin_idx; |
| 2051 | |
| 2052 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2053 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Takashi Iwai | 8b8d654 | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2054 | |
| 2055 | per_pin->codec = codec; |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2056 | mutex_init(&per_pin->lock); |
Takashi Iwai | 8b8d654 | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2057 | INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2058 | eld_proc_new(per_pin, pin_idx); |
Takashi Iwai | 8b8d654 | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2059 | } |
| 2060 | return 0; |
| 2061 | } |
| 2062 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2063 | static int generic_hdmi_init(struct hda_codec *codec) |
| 2064 | { |
| 2065 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2066 | int pin_idx; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2067 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2068 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2069 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2070 | hda_nid_t pin_nid = per_pin->pin_nid; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2071 | |
| 2072 | hdmi_init_pin(codec, pin_nid); |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 2073 | snd_hda_jack_detect_enable(codec, pin_nid, pin_nid); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2074 | } |
| 2075 | return 0; |
| 2076 | } |
| 2077 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2078 | static void hdmi_array_init(struct hdmi_spec *spec, int nums) |
| 2079 | { |
| 2080 | snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums); |
| 2081 | snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums); |
| 2082 | snd_array_init(&spec->pcm_rec, sizeof(struct hda_pcm), nums); |
| 2083 | } |
| 2084 | |
| 2085 | static void hdmi_array_free(struct hdmi_spec *spec) |
| 2086 | { |
| 2087 | snd_array_free(&spec->pins); |
| 2088 | snd_array_free(&spec->cvts); |
| 2089 | snd_array_free(&spec->pcm_rec); |
| 2090 | } |
| 2091 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2092 | static void generic_hdmi_free(struct hda_codec *codec) |
| 2093 | { |
| 2094 | struct hdmi_spec *spec = codec->spec; |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2095 | int pin_idx; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2096 | |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2097 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2098 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2099 | |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 2100 | cancel_delayed_work(&per_pin->work); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 2101 | eld_proc_free(per_pin); |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2102 | } |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2103 | |
Wu Fengguang | 744626d | 2011-11-16 16:29:47 +0800 | [diff] [blame] | 2104 | flush_workqueue(codec->bus->workq); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2105 | hdmi_array_free(spec); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2106 | kfree(spec); |
| 2107 | } |
| 2108 | |
Wang Xingchao | 28cb72e | 2013-06-24 07:45:23 -0400 | [diff] [blame] | 2109 | #ifdef CONFIG_PM |
| 2110 | static int generic_hdmi_resume(struct hda_codec *codec) |
| 2111 | { |
| 2112 | struct hdmi_spec *spec = codec->spec; |
| 2113 | int pin_idx; |
| 2114 | |
| 2115 | generic_hdmi_init(codec); |
| 2116 | snd_hda_codec_resume_amp(codec); |
| 2117 | snd_hda_codec_resume_cache(codec); |
| 2118 | |
| 2119 | for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { |
| 2120 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); |
| 2121 | hdmi_present_sense(per_pin, 1); |
| 2122 | } |
| 2123 | return 0; |
| 2124 | } |
| 2125 | #endif |
| 2126 | |
Takashi Iwai | fb79e1e | 2011-05-02 12:17:41 +0200 | [diff] [blame] | 2127 | static const struct hda_codec_ops generic_hdmi_patch_ops = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2128 | .init = generic_hdmi_init, |
| 2129 | .free = generic_hdmi_free, |
| 2130 | .build_pcms = generic_hdmi_build_pcms, |
| 2131 | .build_controls = generic_hdmi_build_controls, |
| 2132 | .unsol_event = hdmi_unsol_event, |
Wang Xingchao | 28cb72e | 2013-06-24 07:45:23 -0400 | [diff] [blame] | 2133 | #ifdef CONFIG_PM |
| 2134 | .resume = generic_hdmi_resume, |
| 2135 | #endif |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2136 | }; |
| 2137 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 2138 | static const struct hdmi_ops generic_standard_hdmi_ops = { |
| 2139 | .pin_get_eld = snd_hdmi_get_eld, |
| 2140 | .pin_get_slot_channel = hdmi_pin_get_slot_channel, |
| 2141 | .pin_set_slot_channel = hdmi_pin_set_slot_channel, |
| 2142 | .pin_setup_infoframe = hdmi_pin_setup_infoframe, |
| 2143 | .pin_hbr_setup = hdmi_pin_hbr_setup, |
| 2144 | .setup_stream = hdmi_setup_stream, |
| 2145 | .chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type, |
| 2146 | .cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap, |
| 2147 | }; |
| 2148 | |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2149 | |
| 2150 | static void intel_haswell_fixup_connect_list(struct hda_codec *codec, |
| 2151 | hda_nid_t nid) |
Mengdong Lin | 6ffe168 | 2012-12-18 16:59:15 -0500 | [diff] [blame] | 2152 | { |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2153 | struct hdmi_spec *spec = codec->spec; |
| 2154 | hda_nid_t conns[4]; |
| 2155 | int nconns; |
Mengdong Lin | 6ffe168 | 2012-12-18 16:59:15 -0500 | [diff] [blame] | 2156 | |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2157 | nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns)); |
| 2158 | if (nconns == spec->num_cvts && |
| 2159 | !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t))) |
Mengdong Lin | 6ffe168 | 2012-12-18 16:59:15 -0500 | [diff] [blame] | 2160 | return; |
| 2161 | |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2162 | /* override pins connection list */ |
| 2163 | snd_printdd("hdmi: haswell: override pin connection 0x%x\n", nid); |
| 2164 | snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids); |
Mengdong Lin | 6ffe168 | 2012-12-18 16:59:15 -0500 | [diff] [blame] | 2165 | } |
| 2166 | |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2167 | #define INTEL_VENDOR_NID 0x08 |
| 2168 | #define INTEL_GET_VENDOR_VERB 0xf81 |
| 2169 | #define INTEL_SET_VENDOR_VERB 0x781 |
| 2170 | #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */ |
| 2171 | #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */ |
| 2172 | |
| 2173 | static void intel_haswell_enable_all_pins(struct hda_codec *codec, |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2174 | bool update_tree) |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2175 | { |
| 2176 | unsigned int vendor_param; |
| 2177 | |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2178 | vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0, |
| 2179 | INTEL_GET_VENDOR_VERB, 0); |
| 2180 | if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS) |
| 2181 | return; |
| 2182 | |
| 2183 | vendor_param |= INTEL_EN_ALL_PIN_CVTS; |
| 2184 | vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0, |
| 2185 | INTEL_SET_VENDOR_VERB, vendor_param); |
| 2186 | if (vendor_param == -1) |
| 2187 | return; |
| 2188 | |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2189 | if (update_tree) |
| 2190 | snd_hda_codec_update_widgets(codec); |
Mengdong Lin | 1611a9c | 2013-02-08 17:09:52 -0500 | [diff] [blame] | 2191 | } |
| 2192 | |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2193 | static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec) |
| 2194 | { |
| 2195 | unsigned int vendor_param; |
| 2196 | |
| 2197 | vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0, |
| 2198 | INTEL_GET_VENDOR_VERB, 0); |
| 2199 | if (vendor_param == -1 || vendor_param & INTEL_EN_DP12) |
| 2200 | return; |
| 2201 | |
| 2202 | /* enable DP1.2 mode */ |
| 2203 | vendor_param |= INTEL_EN_DP12; |
| 2204 | snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0, |
| 2205 | INTEL_SET_VENDOR_VERB, vendor_param); |
| 2206 | } |
| 2207 | |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2208 | /* Haswell needs to re-issue the vendor-specific verbs before turning to D0. |
| 2209 | * Otherwise you may get severe h/w communication errors. |
| 2210 | */ |
| 2211 | static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg, |
| 2212 | unsigned int power_state) |
| 2213 | { |
| 2214 | if (power_state == AC_PWRST_D0) { |
| 2215 | intel_haswell_enable_all_pins(codec, false); |
| 2216 | intel_haswell_fixup_enable_dp12(codec); |
| 2217 | } |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2218 | |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2219 | snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state); |
| 2220 | snd_hda_codec_set_power_to_all(codec, fg, power_state); |
| 2221 | } |
Mengdong Lin | 6ffe168 | 2012-12-18 16:59:15 -0500 | [diff] [blame] | 2222 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2223 | static int patch_generic_hdmi(struct hda_codec *codec) |
| 2224 | { |
| 2225 | struct hdmi_spec *spec; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2226 | |
| 2227 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 2228 | if (spec == NULL) |
| 2229 | return -ENOMEM; |
| 2230 | |
Anssi Hannula | 307229d | 2013-10-24 21:10:34 +0300 | [diff] [blame^] | 2231 | spec->ops = generic_standard_hdmi_ops; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2232 | codec->spec = spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2233 | hdmi_array_init(spec, 4); |
Mengdong Lin | 6ffe168 | 2012-12-18 16:59:15 -0500 | [diff] [blame] | 2234 | |
Mengdong Lin | fb87fa3 | 2013-09-04 16:36:57 -0400 | [diff] [blame] | 2235 | if (is_haswell(codec)) { |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2236 | intel_haswell_enable_all_pins(codec, true); |
Takashi Iwai | c88d4e8 | 2013-02-08 17:10:04 -0500 | [diff] [blame] | 2237 | intel_haswell_fixup_enable_dp12(codec); |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2238 | } |
Mengdong Lin | 6ffe168 | 2012-12-18 16:59:15 -0500 | [diff] [blame] | 2239 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2240 | if (hdmi_parse_codec(codec) < 0) { |
| 2241 | codec->spec = NULL; |
| 2242 | kfree(spec); |
| 2243 | return -EINVAL; |
| 2244 | } |
| 2245 | codec->patch_ops = generic_hdmi_patch_ops; |
Mengdong Lin | fb87fa3 | 2013-09-04 16:36:57 -0400 | [diff] [blame] | 2246 | if (is_haswell(codec)) { |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2247 | codec->patch_ops.set_power_state = haswell_set_power_state; |
Mengdong Lin | 5dc989b | 2013-08-26 21:35:41 -0400 | [diff] [blame] | 2248 | codec->dp_mst = true; |
| 2249 | } |
Takashi Iwai | 17df3f5 | 2013-05-08 08:09:34 +0200 | [diff] [blame] | 2250 | |
Takashi Iwai | 8b8d654 | 2012-06-20 16:32:22 +0200 | [diff] [blame] | 2251 | generic_hdmi_init_per_pins(codec); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2252 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2253 | init_channel_allocations(); |
| 2254 | |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
| 2258 | /* |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2259 | * Shared non-generic implementations |
| 2260 | */ |
| 2261 | |
| 2262 | static int simple_playback_build_pcms(struct hda_codec *codec) |
| 2263 | { |
| 2264 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2265 | struct hda_pcm *info; |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 2266 | unsigned int chans; |
| 2267 | struct hda_pcm_stream *pstr; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2268 | struct hdmi_spec_per_cvt *per_cvt; |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2269 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2270 | per_cvt = get_cvt(spec, 0); |
| 2271 | chans = get_wcaps(codec, per_cvt->cvt_nid); |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 2272 | chans = get_wcaps_channels(chans); |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2273 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2274 | info = snd_array_new(&spec->pcm_rec); |
| 2275 | if (!info) |
| 2276 | return -ENOMEM; |
| 2277 | info->name = get_pin(spec, 0)->pcm_name; |
| 2278 | sprintf(info->name, "HDMI 0"); |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 2279 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
| 2280 | pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; |
| 2281 | *pstr = spec->pcm_playback; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2282 | pstr->nid = per_cvt->cvt_nid; |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 2283 | if (pstr->channels_max <= 2 && chans && chans <= 16) |
| 2284 | pstr->channels_max = chans; |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2285 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2286 | codec->num_pcms = 1; |
| 2287 | codec->pcm_info = info; |
| 2288 | |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2289 | return 0; |
| 2290 | } |
| 2291 | |
Takashi Iwai | 4b6ace9 | 2012-06-15 11:53:32 +0200 | [diff] [blame] | 2292 | /* unsolicited event for jack sensing */ |
| 2293 | static void simple_hdmi_unsol_event(struct hda_codec *codec, |
| 2294 | unsigned int res) |
| 2295 | { |
Takashi Iwai | 9dd8cf1 | 2012-06-21 10:43:15 +0200 | [diff] [blame] | 2296 | snd_hda_jack_set_dirty_all(codec); |
Takashi Iwai | 4b6ace9 | 2012-06-15 11:53:32 +0200 | [diff] [blame] | 2297 | snd_hda_jack_report_sync(codec); |
| 2298 | } |
| 2299 | |
| 2300 | /* generic_hdmi_build_jack can be used for simple_hdmi, too, |
| 2301 | * as long as spec->pins[] is set correctly |
| 2302 | */ |
| 2303 | #define simple_hdmi_build_jack generic_hdmi_build_jack |
| 2304 | |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2305 | static int simple_playback_build_controls(struct hda_codec *codec) |
| 2306 | { |
| 2307 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2308 | struct hdmi_spec_per_cvt *per_cvt; |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2309 | int err; |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2310 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2311 | per_cvt = get_cvt(spec, 0); |
| 2312 | err = snd_hda_create_spdif_out_ctls(codec, per_cvt->cvt_nid, |
| 2313 | per_cvt->cvt_nid); |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 2314 | if (err < 0) |
| 2315 | return err; |
| 2316 | return simple_hdmi_build_jack(codec, 0); |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2317 | } |
| 2318 | |
Takashi Iwai | 4f0110c | 2012-06-15 12:45:43 +0200 | [diff] [blame] | 2319 | static int simple_playback_init(struct hda_codec *codec) |
| 2320 | { |
| 2321 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2322 | struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0); |
| 2323 | hda_nid_t pin = per_pin->pin_nid; |
Takashi Iwai | 4f0110c | 2012-06-15 12:45:43 +0200 | [diff] [blame] | 2324 | |
Takashi Iwai | 8ceb332 | 2012-06-21 08:23:27 +0200 | [diff] [blame] | 2325 | snd_hda_codec_write(codec, pin, 0, |
| 2326 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 2327 | /* some codecs require to unmute the pin */ |
| 2328 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) |
| 2329 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 2330 | AMP_OUT_UNMUTE); |
| 2331 | snd_hda_jack_detect_enable(codec, pin, pin); |
Takashi Iwai | 4f0110c | 2012-06-15 12:45:43 +0200 | [diff] [blame] | 2332 | return 0; |
| 2333 | } |
| 2334 | |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2335 | static void simple_playback_free(struct hda_codec *codec) |
| 2336 | { |
| 2337 | struct hdmi_spec *spec = codec->spec; |
| 2338 | |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2339 | hdmi_array_free(spec); |
Stephen Warren | 3aaf898 | 2011-06-01 11:14:19 -0600 | [diff] [blame] | 2340 | kfree(spec); |
| 2341 | } |
| 2342 | |
| 2343 | /* |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2344 | * Nvidia specific implementations |
| 2345 | */ |
| 2346 | |
| 2347 | #define Nv_VERB_SET_Channel_Allocation 0xF79 |
| 2348 | #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A |
| 2349 | #define Nv_VERB_SET_Audio_Protection_On 0xF98 |
| 2350 | #define Nv_VERB_SET_Audio_Protection_Off 0xF99 |
| 2351 | |
| 2352 | #define nvhdmi_master_con_nid_7x 0x04 |
| 2353 | #define nvhdmi_master_pin_nid_7x 0x05 |
| 2354 | |
Takashi Iwai | fb79e1e | 2011-05-02 12:17:41 +0200 | [diff] [blame] | 2355 | static const hda_nid_t nvhdmi_con_nids_7x[4] = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2356 | /*front, rear, clfe, rear_surr */ |
| 2357 | 0x6, 0x8, 0xa, 0xc, |
| 2358 | }; |
| 2359 | |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 2360 | static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = { |
| 2361 | /* set audio protect on */ |
| 2362 | { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1}, |
| 2363 | /* enable digital output on pin widget */ |
| 2364 | { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 2365 | {} /* terminator */ |
| 2366 | }; |
| 2367 | |
| 2368 | static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2369 | /* set audio protect on */ |
| 2370 | { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1}, |
| 2371 | /* enable digital output on pin widget */ |
| 2372 | { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 2373 | { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 2374 | { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 2375 | { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 2376 | { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, |
| 2377 | {} /* terminator */ |
| 2378 | }; |
| 2379 | |
| 2380 | #ifdef LIMITED_RATE_FMT_SUPPORT |
| 2381 | /* support only the safe format and rate */ |
| 2382 | #define SUPPORTED_RATES SNDRV_PCM_RATE_48000 |
| 2383 | #define SUPPORTED_MAXBPS 16 |
| 2384 | #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE |
| 2385 | #else |
| 2386 | /* support all rates and formats */ |
| 2387 | #define SUPPORTED_RATES \ |
| 2388 | (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\ |
| 2389 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\ |
| 2390 | SNDRV_PCM_RATE_192000) |
| 2391 | #define SUPPORTED_MAXBPS 24 |
| 2392 | #define SUPPORTED_FORMATS \ |
| 2393 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 2394 | #endif |
| 2395 | |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 2396 | static int nvhdmi_7x_init_2ch(struct hda_codec *codec) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2397 | { |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 2398 | snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch); |
| 2399 | return 0; |
| 2400 | } |
| 2401 | |
| 2402 | static int nvhdmi_7x_init_8ch(struct hda_codec *codec) |
| 2403 | { |
| 2404 | snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2405 | return 0; |
| 2406 | } |
| 2407 | |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 2408 | static unsigned int channels_2_6_8[] = { |
| 2409 | 2, 6, 8 |
| 2410 | }; |
| 2411 | |
| 2412 | static unsigned int channels_2_8[] = { |
| 2413 | 2, 8 |
| 2414 | }; |
| 2415 | |
| 2416 | static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = { |
| 2417 | .count = ARRAY_SIZE(channels_2_6_8), |
| 2418 | .list = channels_2_6_8, |
| 2419 | .mask = 0, |
| 2420 | }; |
| 2421 | |
| 2422 | static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = { |
| 2423 | .count = ARRAY_SIZE(channels_2_8), |
| 2424 | .list = channels_2_8, |
| 2425 | .mask = 0, |
| 2426 | }; |
| 2427 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2428 | static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 2429 | struct hda_codec *codec, |
| 2430 | struct snd_pcm_substream *substream) |
| 2431 | { |
| 2432 | struct hdmi_spec *spec = codec->spec; |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 2433 | struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL; |
| 2434 | |
| 2435 | switch (codec->preset->id) { |
| 2436 | case 0x10de0002: |
| 2437 | case 0x10de0003: |
| 2438 | case 0x10de0005: |
| 2439 | case 0x10de0006: |
| 2440 | hw_constraints_channels = &hw_constraints_2_8_channels; |
| 2441 | break; |
| 2442 | case 0x10de0007: |
| 2443 | hw_constraints_channels = &hw_constraints_2_6_8_channels; |
| 2444 | break; |
| 2445 | default: |
| 2446 | break; |
| 2447 | } |
| 2448 | |
| 2449 | if (hw_constraints_channels != NULL) { |
| 2450 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 2451 | SNDRV_PCM_HW_PARAM_CHANNELS, |
| 2452 | hw_constraints_channels); |
Takashi Iwai | ad09fc9 | 2011-01-14 09:42:27 +0100 | [diff] [blame] | 2453 | } else { |
| 2454 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 2455 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
Nitin Daga | 393004b | 2011-01-10 21:49:31 +0530 | [diff] [blame] | 2456 | } |
| 2457 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2458 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 2459 | } |
| 2460 | |
| 2461 | static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 2462 | struct hda_codec *codec, |
| 2463 | struct snd_pcm_substream *substream) |
| 2464 | { |
| 2465 | struct hdmi_spec *spec = codec->spec; |
| 2466 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 2467 | } |
| 2468 | |
| 2469 | static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 2470 | struct hda_codec *codec, |
| 2471 | unsigned int stream_tag, |
| 2472 | unsigned int format, |
| 2473 | struct snd_pcm_substream *substream) |
| 2474 | { |
| 2475 | struct hdmi_spec *spec = codec->spec; |
| 2476 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 2477 | stream_tag, format, substream); |
| 2478 | } |
| 2479 | |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2480 | static const struct hda_pcm_stream simple_pcm_playback = { |
| 2481 | .substreams = 1, |
| 2482 | .channels_min = 2, |
| 2483 | .channels_max = 2, |
| 2484 | .ops = { |
| 2485 | .open = simple_playback_pcm_open, |
| 2486 | .close = simple_playback_pcm_close, |
| 2487 | .prepare = simple_playback_pcm_prepare |
| 2488 | }, |
| 2489 | }; |
| 2490 | |
| 2491 | static const struct hda_codec_ops simple_hdmi_patch_ops = { |
| 2492 | .build_controls = simple_playback_build_controls, |
| 2493 | .build_pcms = simple_playback_build_pcms, |
| 2494 | .init = simple_playback_init, |
| 2495 | .free = simple_playback_free, |
Takashi Iwai | 250e41a | 2012-06-15 14:40:21 +0200 | [diff] [blame] | 2496 | .unsol_event = simple_hdmi_unsol_event, |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2497 | }; |
| 2498 | |
| 2499 | static int patch_simple_hdmi(struct hda_codec *codec, |
| 2500 | hda_nid_t cvt_nid, hda_nid_t pin_nid) |
| 2501 | { |
| 2502 | struct hdmi_spec *spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2503 | struct hdmi_spec_per_cvt *per_cvt; |
| 2504 | struct hdmi_spec_per_pin *per_pin; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2505 | |
| 2506 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 2507 | if (!spec) |
| 2508 | return -ENOMEM; |
| 2509 | |
| 2510 | codec->spec = spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2511 | hdmi_array_init(spec, 1); |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2512 | |
| 2513 | spec->multiout.num_dacs = 0; /* no analog */ |
| 2514 | spec->multiout.max_channels = 2; |
| 2515 | spec->multiout.dig_out_nid = cvt_nid; |
| 2516 | spec->num_cvts = 1; |
| 2517 | spec->num_pins = 1; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2518 | per_pin = snd_array_new(&spec->pins); |
| 2519 | per_cvt = snd_array_new(&spec->cvts); |
| 2520 | if (!per_pin || !per_cvt) { |
| 2521 | simple_playback_free(codec); |
| 2522 | return -ENOMEM; |
| 2523 | } |
| 2524 | per_cvt->cvt_nid = cvt_nid; |
| 2525 | per_pin->pin_nid = pin_nid; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2526 | spec->pcm_playback = simple_pcm_playback; |
| 2527 | |
| 2528 | codec->patch_ops = simple_hdmi_patch_ops; |
| 2529 | |
| 2530 | return 0; |
| 2531 | } |
| 2532 | |
Aaron Plattner | 1f34852 | 2011-04-06 17:19:04 -0700 | [diff] [blame] | 2533 | static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec, |
| 2534 | int channels) |
| 2535 | { |
| 2536 | unsigned int chanmask; |
| 2537 | int chan = channels ? (channels - 1) : 1; |
| 2538 | |
| 2539 | switch (channels) { |
| 2540 | default: |
| 2541 | case 0: |
| 2542 | case 2: |
| 2543 | chanmask = 0x00; |
| 2544 | break; |
| 2545 | case 4: |
| 2546 | chanmask = 0x08; |
| 2547 | break; |
| 2548 | case 6: |
| 2549 | chanmask = 0x0b; |
| 2550 | break; |
| 2551 | case 8: |
| 2552 | chanmask = 0x13; |
| 2553 | break; |
| 2554 | } |
| 2555 | |
| 2556 | /* Set the audio infoframe channel allocation and checksum fields. The |
| 2557 | * channel count is computed implicitly by the hardware. */ |
| 2558 | snd_hda_codec_write(codec, 0x1, 0, |
| 2559 | Nv_VERB_SET_Channel_Allocation, chanmask); |
| 2560 | |
| 2561 | snd_hda_codec_write(codec, 0x1, 0, |
| 2562 | Nv_VERB_SET_Info_Frame_Checksum, |
| 2563 | (0x71 - chan - chanmask)); |
| 2564 | } |
| 2565 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2566 | static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo, |
| 2567 | struct hda_codec *codec, |
| 2568 | struct snd_pcm_substream *substream) |
| 2569 | { |
| 2570 | struct hdmi_spec *spec = codec->spec; |
| 2571 | int i; |
| 2572 | |
| 2573 | snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, |
| 2574 | 0, AC_VERB_SET_CHANNEL_STREAMID, 0); |
| 2575 | for (i = 0; i < 4; i++) { |
| 2576 | /* set the stream id */ |
| 2577 | snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, |
| 2578 | AC_VERB_SET_CHANNEL_STREAMID, 0); |
| 2579 | /* set the stream format */ |
| 2580 | snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, |
| 2581 | AC_VERB_SET_STREAM_FORMAT, 0); |
| 2582 | } |
| 2583 | |
Aaron Plattner | 1f34852 | 2011-04-06 17:19:04 -0700 | [diff] [blame] | 2584 | /* The audio hardware sends a channel count of 0x7 (8ch) when all the |
| 2585 | * streams are disabled. */ |
| 2586 | nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8); |
| 2587 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2588 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 2589 | } |
| 2590 | |
| 2591 | static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 2592 | struct hda_codec *codec, |
| 2593 | unsigned int stream_tag, |
| 2594 | unsigned int format, |
| 2595 | struct snd_pcm_substream *substream) |
| 2596 | { |
| 2597 | int chs; |
Takashi Iwai | 112daa7 | 2011-11-02 21:40:06 +0100 | [diff] [blame] | 2598 | unsigned int dataDCC2, channel_id; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2599 | int i; |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2600 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | e3245cd | 2012-05-10 10:21:29 +0200 | [diff] [blame] | 2601 | struct hda_spdif_out *spdif; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2602 | struct hdmi_spec_per_cvt *per_cvt; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2603 | |
| 2604 | mutex_lock(&codec->spdif_mutex); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2605 | per_cvt = get_cvt(spec, 0); |
| 2606 | spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2607 | |
| 2608 | chs = substream->runtime->channels; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2609 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2610 | dataDCC2 = 0x2; |
| 2611 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2612 | /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2613 | if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2614 | snd_hda_codec_write(codec, |
| 2615 | nvhdmi_master_con_nid_7x, |
| 2616 | 0, |
| 2617 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2618 | spdif->ctls & ~AC_DIG1_ENABLE & 0xff); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2619 | |
| 2620 | /* set the stream id */ |
| 2621 | snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, |
| 2622 | AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0); |
| 2623 | |
| 2624 | /* set the stream format */ |
| 2625 | snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, |
| 2626 | AC_VERB_SET_STREAM_FORMAT, format); |
| 2627 | |
| 2628 | /* turn on again (if needed) */ |
| 2629 | /* enable and set the channel status audio/data flag */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2630 | if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2631 | snd_hda_codec_write(codec, |
| 2632 | nvhdmi_master_con_nid_7x, |
| 2633 | 0, |
| 2634 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2635 | spdif->ctls & 0xff); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2636 | snd_hda_codec_write(codec, |
| 2637 | nvhdmi_master_con_nid_7x, |
| 2638 | 0, |
| 2639 | AC_VERB_SET_DIGI_CONVERT_2, dataDCC2); |
| 2640 | } |
| 2641 | |
| 2642 | for (i = 0; i < 4; i++) { |
| 2643 | if (chs == 2) |
| 2644 | channel_id = 0; |
| 2645 | else |
| 2646 | channel_id = i * 2; |
| 2647 | |
| 2648 | /* turn off SPDIF once; |
| 2649 | *otherwise the IEC958 bits won't be updated |
| 2650 | */ |
| 2651 | if (codec->spdif_status_reset && |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2652 | (spdif->ctls & AC_DIG1_ENABLE)) |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2653 | snd_hda_codec_write(codec, |
| 2654 | nvhdmi_con_nids_7x[i], |
| 2655 | 0, |
| 2656 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2657 | spdif->ctls & ~AC_DIG1_ENABLE & 0xff); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2658 | /* set the stream id */ |
| 2659 | snd_hda_codec_write(codec, |
| 2660 | nvhdmi_con_nids_7x[i], |
| 2661 | 0, |
| 2662 | AC_VERB_SET_CHANNEL_STREAMID, |
| 2663 | (stream_tag << 4) | channel_id); |
| 2664 | /* set the stream format */ |
| 2665 | snd_hda_codec_write(codec, |
| 2666 | nvhdmi_con_nids_7x[i], |
| 2667 | 0, |
| 2668 | AC_VERB_SET_STREAM_FORMAT, |
| 2669 | format); |
| 2670 | /* turn on again (if needed) */ |
| 2671 | /* enable and set the channel status audio/data flag */ |
| 2672 | if (codec->spdif_status_reset && |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2673 | (spdif->ctls & AC_DIG1_ENABLE)) { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2674 | snd_hda_codec_write(codec, |
| 2675 | nvhdmi_con_nids_7x[i], |
| 2676 | 0, |
| 2677 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 2678 | spdif->ctls & 0xff); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2679 | snd_hda_codec_write(codec, |
| 2680 | nvhdmi_con_nids_7x[i], |
| 2681 | 0, |
| 2682 | AC_VERB_SET_DIGI_CONVERT_2, dataDCC2); |
| 2683 | } |
| 2684 | } |
| 2685 | |
Aaron Plattner | 1f34852 | 2011-04-06 17:19:04 -0700 | [diff] [blame] | 2686 | nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2687 | |
| 2688 | mutex_unlock(&codec->spdif_mutex); |
| 2689 | return 0; |
| 2690 | } |
| 2691 | |
Takashi Iwai | fb79e1e | 2011-05-02 12:17:41 +0200 | [diff] [blame] | 2692 | static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2693 | .substreams = 1, |
| 2694 | .channels_min = 2, |
| 2695 | .channels_max = 8, |
| 2696 | .nid = nvhdmi_master_con_nid_7x, |
| 2697 | .rates = SUPPORTED_RATES, |
| 2698 | .maxbps = SUPPORTED_MAXBPS, |
| 2699 | .formats = SUPPORTED_FORMATS, |
| 2700 | .ops = { |
| 2701 | .open = simple_playback_pcm_open, |
| 2702 | .close = nvhdmi_8ch_7x_pcm_close, |
| 2703 | .prepare = nvhdmi_8ch_7x_pcm_prepare |
| 2704 | }, |
| 2705 | }; |
| 2706 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2707 | static int patch_nvhdmi_2ch(struct hda_codec *codec) |
| 2708 | { |
| 2709 | struct hdmi_spec *spec; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2710 | int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x, |
| 2711 | nvhdmi_master_pin_nid_7x); |
| 2712 | if (err < 0) |
| 2713 | return err; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2714 | |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 2715 | codec->patch_ops.init = nvhdmi_7x_init_2ch; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2716 | /* override the PCM rates, etc, as the codec doesn't give full list */ |
| 2717 | spec = codec->spec; |
| 2718 | spec->pcm_playback.rates = SUPPORTED_RATES; |
| 2719 | spec->pcm_playback.maxbps = SUPPORTED_MAXBPS; |
| 2720 | spec->pcm_playback.formats = SUPPORTED_FORMATS; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2721 | return 0; |
| 2722 | } |
| 2723 | |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 2724 | static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec) |
| 2725 | { |
| 2726 | struct hdmi_spec *spec = codec->spec; |
| 2727 | int err = simple_playback_build_pcms(codec); |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2728 | if (!err) { |
| 2729 | struct hda_pcm *info = get_pcm_rec(spec, 0); |
| 2730 | info->own_chmap = true; |
| 2731 | } |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 2732 | return err; |
| 2733 | } |
| 2734 | |
| 2735 | static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec) |
| 2736 | { |
| 2737 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2738 | struct hda_pcm *info; |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 2739 | struct snd_pcm_chmap *chmap; |
| 2740 | int err; |
| 2741 | |
| 2742 | err = simple_playback_build_controls(codec); |
| 2743 | if (err < 0) |
| 2744 | return err; |
| 2745 | |
| 2746 | /* add channel maps */ |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2747 | info = get_pcm_rec(spec, 0); |
| 2748 | err = snd_pcm_add_chmap_ctls(info->pcm, |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 2749 | SNDRV_PCM_STREAM_PLAYBACK, |
| 2750 | snd_pcm_alt_chmaps, 8, 0, &chmap); |
| 2751 | if (err < 0) |
| 2752 | return err; |
| 2753 | switch (codec->preset->id) { |
| 2754 | case 0x10de0002: |
| 2755 | case 0x10de0003: |
| 2756 | case 0x10de0005: |
| 2757 | case 0x10de0006: |
| 2758 | chmap->channel_mask = (1U << 2) | (1U << 8); |
| 2759 | break; |
| 2760 | case 0x10de0007: |
| 2761 | chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8); |
| 2762 | } |
| 2763 | return 0; |
| 2764 | } |
| 2765 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2766 | static int patch_nvhdmi_8ch_7x(struct hda_codec *codec) |
| 2767 | { |
| 2768 | struct hdmi_spec *spec; |
| 2769 | int err = patch_nvhdmi_2ch(codec); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2770 | if (err < 0) |
| 2771 | return err; |
| 2772 | spec = codec->spec; |
| 2773 | spec->multiout.max_channels = 8; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2774 | spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x; |
Takashi Iwai | ceaa86b | 2012-06-15 14:38:31 +0200 | [diff] [blame] | 2775 | codec->patch_ops.init = nvhdmi_7x_init_8ch; |
Takashi Iwai | 53775b0 | 2012-08-01 12:17:41 +0200 | [diff] [blame] | 2776 | codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms; |
| 2777 | codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls; |
Aaron Plattner | 1f34852 | 2011-04-06 17:19:04 -0700 | [diff] [blame] | 2778 | |
| 2779 | /* Initialize the audio infoframe channel mask and checksum to something |
| 2780 | * valid */ |
| 2781 | nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8); |
| 2782 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2783 | return 0; |
| 2784 | } |
| 2785 | |
| 2786 | /* |
| 2787 | * ATI-specific implementations |
| 2788 | * |
| 2789 | * FIXME: we may omit the whole this and use the generic code once after |
| 2790 | * it's confirmed to work. |
| 2791 | */ |
| 2792 | |
| 2793 | #define ATIHDMI_CVT_NID 0x02 /* audio converter */ |
| 2794 | #define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */ |
| 2795 | |
| 2796 | static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 2797 | struct hda_codec *codec, |
| 2798 | unsigned int stream_tag, |
| 2799 | unsigned int format, |
| 2800 | struct snd_pcm_substream *substream) |
| 2801 | { |
| 2802 | struct hdmi_spec *spec = codec->spec; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2803 | struct hdmi_spec_per_cvt *per_cvt = get_cvt(spec, 0); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2804 | int chans = substream->runtime->channels; |
| 2805 | int i, err; |
| 2806 | |
| 2807 | err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format, |
| 2808 | substream); |
| 2809 | if (err < 0) |
| 2810 | return err; |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2811 | snd_hda_codec_write(codec, per_cvt->cvt_nid, 0, |
Stephen Warren | 384a48d | 2011-06-01 11:14:21 -0600 | [diff] [blame] | 2812 | AC_VERB_SET_CVT_CHAN_COUNT, chans - 1); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2813 | /* FIXME: XXX */ |
| 2814 | for (i = 0; i < chans; i++) { |
Takashi Iwai | bce0d2a | 2013-03-13 14:40:31 +0100 | [diff] [blame] | 2815 | snd_hda_codec_write(codec, per_cvt->cvt_nid, 0, |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2816 | AC_VERB_SET_HDMI_CHAN_SLOT, |
| 2817 | (i << 4) | i); |
| 2818 | } |
| 2819 | return 0; |
| 2820 | } |
| 2821 | |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2822 | static int patch_atihdmi(struct hda_codec *codec) |
| 2823 | { |
| 2824 | struct hdmi_spec *spec; |
Takashi Iwai | d0b1252 | 2012-06-15 14:34:42 +0200 | [diff] [blame] | 2825 | int err = patch_simple_hdmi(codec, ATIHDMI_CVT_NID, ATIHDMI_PIN_NID); |
| 2826 | if (err < 0) |
| 2827 | return err; |
| 2828 | spec = codec->spec; |
| 2829 | spec->pcm_playback.ops.prepare = atihdmi_playback_pcm_prepare; |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2830 | return 0; |
| 2831 | } |
| 2832 | |
Annie Liu | 3de5ff8 | 2012-06-08 19:18:42 +0800 | [diff] [blame] | 2833 | /* VIA HDMI Implementation */ |
| 2834 | #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */ |
| 2835 | #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */ |
| 2836 | |
Annie Liu | 3de5ff8 | 2012-06-08 19:18:42 +0800 | [diff] [blame] | 2837 | static int patch_via_hdmi(struct hda_codec *codec) |
| 2838 | { |
Takashi Iwai | 250e41a | 2012-06-15 14:40:21 +0200 | [diff] [blame] | 2839 | return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID); |
Annie Liu | 3de5ff8 | 2012-06-08 19:18:42 +0800 | [diff] [blame] | 2840 | } |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2841 | |
| 2842 | /* |
| 2843 | * patch entries |
| 2844 | */ |
Takashi Iwai | fb79e1e | 2011-05-02 12:17:41 +0200 | [diff] [blame] | 2845 | static const struct hda_codec_preset snd_hda_preset_hdmi[] = { |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2846 | { .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi }, |
| 2847 | { .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi }, |
| 2848 | { .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi }, |
Anssi Hannula | 36e9c13 | 2010-12-05 02:34:15 +0200 | [diff] [blame] | 2849 | { .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi }, |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2850 | { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi }, |
| 2851 | { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi }, |
| 2852 | { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi }, |
| 2853 | { .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, |
| 2854 | { .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, |
| 2855 | { .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, |
| 2856 | { .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, |
| 2857 | { .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x }, |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 2858 | { .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi }, |
| 2859 | { .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi }, |
| 2860 | { .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi }, |
| 2861 | { .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi }, |
| 2862 | { .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2863 | { .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2864 | { .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2865 | { .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2866 | { .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2867 | { .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2868 | { .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi }, |
Richard Samson | c8900a0 | 2011-03-03 12:46:13 +0100 | [diff] [blame] | 2869 | /* 17 is known to be absent */ |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 2870 | { .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2871 | { .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2872 | { .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi }, |
| 2873 | { .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi }, |
| 2874 | { .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi }, |
| 2875 | { .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2876 | { .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2877 | { .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2878 | { .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2879 | { .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi }, |
Aaron Plattner | 7ae48b5 | 2012-07-16 17:10:04 -0700 | [diff] [blame] | 2880 | { .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_generic_hdmi }, |
Aaron Plattner | d52392b | 2013-07-12 11:01:37 -0700 | [diff] [blame] | 2881 | { .id = 0x10de0060, .name = "GPU 60 HDMI/DP", .patch = patch_generic_hdmi }, |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2882 | { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch }, |
| 2883 | { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch }, |
Annie Liu | 3de5ff8 | 2012-06-08 19:18:42 +0800 | [diff] [blame] | 2884 | { .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, |
| 2885 | { .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, |
| 2886 | { .id = 0x11069f84, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi }, |
| 2887 | { .id = 0x11069f85, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi }, |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2888 | { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi }, |
| 2889 | { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi }, |
| 2890 | { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi }, |
| 2891 | { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi }, |
| 2892 | { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi }, |
| 2893 | { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi }, |
Wu Fengguang | 591e610 | 2011-05-20 15:35:43 +0800 | [diff] [blame] | 2894 | { .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi }, |
Wang Xingchao | 1c76684 | 2012-06-13 10:23:52 +0800 | [diff] [blame] | 2895 | { .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi }, |
Wu Fengguang | 6edc59e | 2012-02-23 15:07:44 +0800 | [diff] [blame] | 2896 | { .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi }, |
Mengdong Lin | cc1a95d | 2013-10-20 23:03:31 -0400 | [diff] [blame] | 2897 | { .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi }, |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2898 | { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi }, |
| 2899 | {} /* terminator */ |
| 2900 | }; |
| 2901 | |
| 2902 | MODULE_ALIAS("snd-hda-codec-id:1002793c"); |
| 2903 | MODULE_ALIAS("snd-hda-codec-id:10027919"); |
| 2904 | MODULE_ALIAS("snd-hda-codec-id:1002791a"); |
| 2905 | MODULE_ALIAS("snd-hda-codec-id:1002aa01"); |
| 2906 | MODULE_ALIAS("snd-hda-codec-id:10951390"); |
| 2907 | MODULE_ALIAS("snd-hda-codec-id:10951392"); |
| 2908 | MODULE_ALIAS("snd-hda-codec-id:10de0002"); |
| 2909 | MODULE_ALIAS("snd-hda-codec-id:10de0003"); |
| 2910 | MODULE_ALIAS("snd-hda-codec-id:10de0005"); |
| 2911 | MODULE_ALIAS("snd-hda-codec-id:10de0006"); |
| 2912 | MODULE_ALIAS("snd-hda-codec-id:10de0007"); |
| 2913 | MODULE_ALIAS("snd-hda-codec-id:10de000a"); |
| 2914 | MODULE_ALIAS("snd-hda-codec-id:10de000b"); |
| 2915 | MODULE_ALIAS("snd-hda-codec-id:10de000c"); |
| 2916 | MODULE_ALIAS("snd-hda-codec-id:10de000d"); |
| 2917 | MODULE_ALIAS("snd-hda-codec-id:10de0010"); |
| 2918 | MODULE_ALIAS("snd-hda-codec-id:10de0011"); |
| 2919 | MODULE_ALIAS("snd-hda-codec-id:10de0012"); |
| 2920 | MODULE_ALIAS("snd-hda-codec-id:10de0013"); |
| 2921 | MODULE_ALIAS("snd-hda-codec-id:10de0014"); |
Richard Samson | c8900a0 | 2011-03-03 12:46:13 +0100 | [diff] [blame] | 2922 | MODULE_ALIAS("snd-hda-codec-id:10de0015"); |
| 2923 | MODULE_ALIAS("snd-hda-codec-id:10de0016"); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2924 | MODULE_ALIAS("snd-hda-codec-id:10de0018"); |
| 2925 | MODULE_ALIAS("snd-hda-codec-id:10de0019"); |
| 2926 | MODULE_ALIAS("snd-hda-codec-id:10de001a"); |
| 2927 | MODULE_ALIAS("snd-hda-codec-id:10de001b"); |
| 2928 | MODULE_ALIAS("snd-hda-codec-id:10de001c"); |
| 2929 | MODULE_ALIAS("snd-hda-codec-id:10de0040"); |
| 2930 | MODULE_ALIAS("snd-hda-codec-id:10de0041"); |
| 2931 | MODULE_ALIAS("snd-hda-codec-id:10de0042"); |
| 2932 | MODULE_ALIAS("snd-hda-codec-id:10de0043"); |
| 2933 | MODULE_ALIAS("snd-hda-codec-id:10de0044"); |
Aaron Plattner | 7ae48b5 | 2012-07-16 17:10:04 -0700 | [diff] [blame] | 2934 | MODULE_ALIAS("snd-hda-codec-id:10de0051"); |
Aaron Plattner | d52392b | 2013-07-12 11:01:37 -0700 | [diff] [blame] | 2935 | MODULE_ALIAS("snd-hda-codec-id:10de0060"); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2936 | MODULE_ALIAS("snd-hda-codec-id:10de0067"); |
| 2937 | MODULE_ALIAS("snd-hda-codec-id:10de8001"); |
Annie Liu | 3de5ff8 | 2012-06-08 19:18:42 +0800 | [diff] [blame] | 2938 | MODULE_ALIAS("snd-hda-codec-id:11069f80"); |
| 2939 | MODULE_ALIAS("snd-hda-codec-id:11069f81"); |
| 2940 | MODULE_ALIAS("snd-hda-codec-id:11069f84"); |
| 2941 | MODULE_ALIAS("snd-hda-codec-id:11069f85"); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2942 | MODULE_ALIAS("snd-hda-codec-id:17e80047"); |
| 2943 | MODULE_ALIAS("snd-hda-codec-id:80860054"); |
| 2944 | MODULE_ALIAS("snd-hda-codec-id:80862801"); |
| 2945 | MODULE_ALIAS("snd-hda-codec-id:80862802"); |
| 2946 | MODULE_ALIAS("snd-hda-codec-id:80862803"); |
| 2947 | MODULE_ALIAS("snd-hda-codec-id:80862804"); |
| 2948 | MODULE_ALIAS("snd-hda-codec-id:80862805"); |
Wu Fengguang | 591e610 | 2011-05-20 15:35:43 +0800 | [diff] [blame] | 2949 | MODULE_ALIAS("snd-hda-codec-id:80862806"); |
Wang Xingchao | 1c76684 | 2012-06-13 10:23:52 +0800 | [diff] [blame] | 2950 | MODULE_ALIAS("snd-hda-codec-id:80862807"); |
Wu Fengguang | 6edc59e | 2012-02-23 15:07:44 +0800 | [diff] [blame] | 2951 | MODULE_ALIAS("snd-hda-codec-id:80862880"); |
Mengdong Lin | cc1a95d | 2013-10-20 23:03:31 -0400 | [diff] [blame] | 2952 | MODULE_ALIAS("snd-hda-codec-id:80862882"); |
Takashi Iwai | 84eb01b | 2010-09-07 12:27:25 +0200 | [diff] [blame] | 2953 | MODULE_ALIAS("snd-hda-codec-id:808629fb"); |
| 2954 | |
| 2955 | MODULE_LICENSE("GPL"); |
| 2956 | MODULE_DESCRIPTION("HDMI HD-audio codec"); |
| 2957 | MODULE_ALIAS("snd-hda-codec-intelhdmi"); |
| 2958 | MODULE_ALIAS("snd-hda-codec-nvhdmi"); |
| 2959 | MODULE_ALIAS("snd-hda-codec-atihdmi"); |
| 2960 | |
| 2961 | static struct hda_codec_preset_list intel_list = { |
| 2962 | .preset = snd_hda_preset_hdmi, |
| 2963 | .owner = THIS_MODULE, |
| 2964 | }; |
| 2965 | |
| 2966 | static int __init patch_hdmi_init(void) |
| 2967 | { |
| 2968 | return snd_hda_add_codec_preset(&intel_list); |
| 2969 | } |
| 2970 | |
| 2971 | static void __exit patch_hdmi_exit(void) |
| 2972 | { |
| 2973 | snd_hda_delete_codec_preset(&intel_list); |
| 2974 | } |
| 2975 | |
| 2976 | module_init(patch_hdmi_init) |
| 2977 | module_exit(patch_hdmi_exit) |