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