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