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