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