Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HD audio interface patch for Cirrus Logic CS420x chip |
| 3 | * |
| 4 | * Copyright (c) 2009 Takashi Iwai <tiwai@suse.de> |
| 5 | * |
| 6 | * This driver is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This driver is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/pci.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 26 | #include <sound/core.h> |
| 27 | #include "hda_codec.h" |
| 28 | #include "hda_local.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 29 | #include "hda_auto_parser.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 30 | #include "hda_jack.h" |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 31 | #include <sound/tlv.h> |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | */ |
| 35 | |
| 36 | struct cs_spec { |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 37 | struct hda_gen_spec gen; |
| 38 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 39 | struct auto_pin_cfg autocfg; |
| 40 | struct hda_multi_out multiout; |
| 41 | struct snd_kcontrol *vmaster_sw; |
| 42 | struct snd_kcontrol *vmaster_vol; |
| 43 | |
| 44 | hda_nid_t dac_nid[AUTO_CFG_MAX_OUTS]; |
| 45 | hda_nid_t slave_dig_outs[2]; |
| 46 | |
| 47 | unsigned int input_idx[AUTO_PIN_LAST]; |
| 48 | unsigned int capsrc_idx[AUTO_PIN_LAST]; |
| 49 | hda_nid_t adc_nid[AUTO_PIN_LAST]; |
| 50 | unsigned int adc_idx[AUTO_PIN_LAST]; |
| 51 | unsigned int num_inputs; |
| 52 | unsigned int cur_input; |
| 53 | unsigned int automic_idx; |
| 54 | hda_nid_t cur_adc; |
| 55 | unsigned int cur_adc_stream_tag; |
| 56 | unsigned int cur_adc_format; |
| 57 | hda_nid_t dig_in; |
| 58 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 59 | const struct hda_bind_ctls *capture_bind[2]; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 60 | |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 61 | unsigned int gpio_mask; |
| 62 | unsigned int gpio_dir; |
| 63 | unsigned int gpio_data; |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 64 | unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */ |
| 65 | unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */ |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 66 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 67 | struct hda_pcm pcm_rec[2]; /* PCM information */ |
| 68 | |
| 69 | unsigned int hp_detect:1; |
| 70 | unsigned int mic_detect:1; |
Takashi Iwai | f37bc7a | 2012-11-08 15:59:23 +0100 | [diff] [blame^] | 71 | unsigned int speaker_2_1:1; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 72 | /* CS421x */ |
| 73 | unsigned int spdif_detect:1; |
| 74 | unsigned int sense_b:1; |
| 75 | hda_nid_t vendor_nid; |
| 76 | struct hda_input_mux input_mux; |
| 77 | unsigned int last_input; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 80 | /* available models with CS420x */ |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 81 | enum { |
Vince Weaver | 4e7d7c6 | 2010-09-22 17:31:37 -0400 | [diff] [blame] | 82 | CS420X_MBP53, |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 83 | CS420X_MBP55, |
Rafael Avila de Espindola | 1a5ba2e | 2009-12-22 07:59:37 +0100 | [diff] [blame] | 84 | CS420X_IMAC27, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 85 | CS420X_GPIO_13, |
| 86 | CS420X_GPIO_23, |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 87 | CS420X_MBP101, |
| 88 | CS420X_MBP101_COEF, |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 89 | CS420X_AUTO, |
Takashi Iwai | 03efce7 | 2012-09-13 09:56:57 +0200 | [diff] [blame] | 90 | /* aliases */ |
| 91 | CS420X_IMAC27_122 = CS420X_GPIO_23, |
| 92 | CS420X_APPLE = CS420X_GPIO_13, |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 95 | /* CS421x boards */ |
| 96 | enum { |
| 97 | CS421X_CDB4210, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 98 | CS421X_SENSE_B, |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 99 | }; |
| 100 | |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 101 | /* Vendor-specific processing widget */ |
| 102 | #define CS420X_VENDOR_NID 0x11 |
| 103 | #define CS_DIG_OUT1_PIN_NID 0x10 |
| 104 | #define CS_DIG_OUT2_PIN_NID 0x15 |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 105 | #define CS_DMIC1_PIN_NID 0x0e |
| 106 | #define CS_DMIC2_PIN_NID 0x12 |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 107 | |
| 108 | /* coef indices */ |
| 109 | #define IDX_SPDIF_STAT 0x0000 |
| 110 | #define IDX_SPDIF_CTL 0x0001 |
| 111 | #define IDX_ADC_CFG 0x0002 |
| 112 | /* SZC bitmask, 4 modes below: |
| 113 | * 0 = immediate, |
| 114 | * 1 = digital immediate, analog zero-cross |
| 115 | * 2 = digtail & analog soft-ramp |
| 116 | * 3 = digital soft-ramp, analog zero-cross |
| 117 | */ |
| 118 | #define CS_COEF_ADC_SZC_MASK (3 << 0) |
| 119 | #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */ |
| 120 | #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */ |
| 121 | /* PGA mode: 0 = differential, 1 = signle-ended */ |
| 122 | #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */ |
| 123 | #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */ |
| 124 | #define IDX_DAC_CFG 0x0003 |
| 125 | /* SZC bitmask, 4 modes below: |
| 126 | * 0 = Immediate |
| 127 | * 1 = zero-cross |
| 128 | * 2 = soft-ramp |
| 129 | * 3 = soft-ramp on zero-cross |
| 130 | */ |
| 131 | #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */ |
| 132 | #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */ |
| 133 | #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */ |
| 134 | |
| 135 | #define IDX_BEEP_CFG 0x0004 |
| 136 | /* 0x0008 - test reg key */ |
| 137 | /* 0x0009 - 0x0014 -> 12 test regs */ |
| 138 | /* 0x0015 - visibility reg */ |
| 139 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 140 | /* |
| 141 | * Cirrus Logic CS4210 |
| 142 | * |
| 143 | * 1 DAC => HP(sense) / Speakers, |
| 144 | * 1 ADC <= LineIn(sense) / MicIn / DMicIn, |
| 145 | * 1 SPDIF OUT => SPDIF Trasmitter(sense) |
| 146 | */ |
| 147 | #define CS4210_DAC_NID 0x02 |
| 148 | #define CS4210_ADC_NID 0x03 |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 149 | #define CS4210_VENDOR_NID 0x0B |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 150 | #define CS421X_DMIC_PIN_NID 0x09 /* Port E */ |
| 151 | #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */ |
| 152 | |
| 153 | #define CS421X_IDX_DEV_CFG 0x01 |
| 154 | #define CS421X_IDX_ADC_CFG 0x02 |
| 155 | #define CS421X_IDX_DAC_CFG 0x03 |
| 156 | #define CS421X_IDX_SPK_CTL 0x04 |
| 157 | |
| 158 | #define SPDIF_EVENT 0x04 |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 159 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 160 | /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */ |
| 161 | #define CS4213_VENDOR_NID 0x09 |
| 162 | |
| 163 | |
Takashi Iwai | 277a57c | 2009-07-08 12:42:08 +0200 | [diff] [blame] | 164 | static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx) |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 165 | { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 166 | struct cs_spec *spec = codec->spec; |
| 167 | snd_hda_codec_write(codec, spec->vendor_nid, 0, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 168 | AC_VERB_SET_COEF_INDEX, idx); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 169 | return snd_hda_codec_read(codec, spec->vendor_nid, 0, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 170 | AC_VERB_GET_PROC_COEF, 0); |
| 171 | } |
| 172 | |
Takashi Iwai | 277a57c | 2009-07-08 12:42:08 +0200 | [diff] [blame] | 173 | static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx, |
| 174 | unsigned int coef) |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 175 | { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 176 | struct cs_spec *spec = codec->spec; |
| 177 | snd_hda_codec_write(codec, spec->vendor_nid, 0, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 178 | AC_VERB_SET_COEF_INDEX, idx); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 179 | snd_hda_codec_write(codec, spec->vendor_nid, 0, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 180 | AC_VERB_SET_PROC_COEF, coef); |
| 181 | } |
| 182 | |
| 183 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 184 | #define HP_EVENT 1 |
| 185 | #define MIC_EVENT 2 |
| 186 | |
| 187 | /* |
| 188 | * PCM callbacks |
| 189 | */ |
| 190 | static int cs_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 191 | struct hda_codec *codec, |
| 192 | struct snd_pcm_substream *substream) |
| 193 | { |
| 194 | struct cs_spec *spec = codec->spec; |
| 195 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 196 | hinfo); |
| 197 | } |
| 198 | |
| 199 | static int cs_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 200 | struct hda_codec *codec, |
| 201 | unsigned int stream_tag, |
| 202 | unsigned int format, |
| 203 | struct snd_pcm_substream *substream) |
| 204 | { |
| 205 | struct cs_spec *spec = codec->spec; |
| 206 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 207 | stream_tag, format, substream); |
| 208 | } |
| 209 | |
| 210 | static int cs_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 211 | struct hda_codec *codec, |
| 212 | struct snd_pcm_substream *substream) |
| 213 | { |
| 214 | struct cs_spec *spec = codec->spec; |
| 215 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * Digital out |
| 220 | */ |
| 221 | static int cs_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 222 | struct hda_codec *codec, |
| 223 | struct snd_pcm_substream *substream) |
| 224 | { |
| 225 | struct cs_spec *spec = codec->spec; |
| 226 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 227 | } |
| 228 | |
| 229 | static int cs_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 230 | struct hda_codec *codec, |
| 231 | struct snd_pcm_substream *substream) |
| 232 | { |
| 233 | struct cs_spec *spec = codec->spec; |
| 234 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 235 | } |
| 236 | |
| 237 | static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 238 | struct hda_codec *codec, |
| 239 | unsigned int stream_tag, |
| 240 | unsigned int format, |
| 241 | struct snd_pcm_substream *substream) |
| 242 | { |
| 243 | struct cs_spec *spec = codec->spec; |
| 244 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, |
| 245 | format, substream); |
| 246 | } |
| 247 | |
| 248 | static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 249 | struct hda_codec *codec, |
| 250 | struct snd_pcm_substream *substream) |
| 251 | { |
| 252 | struct cs_spec *spec = codec->spec; |
| 253 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
| 254 | } |
| 255 | |
Takashi Iwai | 05ee796 | 2011-11-16 18:05:11 +0100 | [diff] [blame] | 256 | static void cs_update_input_select(struct hda_codec *codec) |
| 257 | { |
| 258 | struct cs_spec *spec = codec->spec; |
| 259 | if (spec->cur_adc) |
| 260 | snd_hda_codec_write(codec, spec->cur_adc, 0, |
| 261 | AC_VERB_SET_CONNECT_SEL, |
| 262 | spec->adc_idx[spec->cur_input]); |
| 263 | } |
| 264 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 265 | /* |
| 266 | * Analog capture |
| 267 | */ |
| 268 | static int cs_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 269 | struct hda_codec *codec, |
| 270 | unsigned int stream_tag, |
| 271 | unsigned int format, |
| 272 | struct snd_pcm_substream *substream) |
| 273 | { |
| 274 | struct cs_spec *spec = codec->spec; |
| 275 | spec->cur_adc = spec->adc_nid[spec->cur_input]; |
| 276 | spec->cur_adc_stream_tag = stream_tag; |
| 277 | spec->cur_adc_format = format; |
Takashi Iwai | 05ee796 | 2011-11-16 18:05:11 +0100 | [diff] [blame] | 278 | cs_update_input_select(codec); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 279 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static int cs_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 284 | struct hda_codec *codec, |
| 285 | struct snd_pcm_substream *substream) |
| 286 | { |
| 287 | struct cs_spec *spec = codec->spec; |
| 288 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 289 | spec->cur_adc = 0; |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | */ |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 295 | static const struct hda_pcm_stream cs_pcm_analog_playback = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 296 | .substreams = 1, |
| 297 | .channels_min = 2, |
| 298 | .channels_max = 2, |
| 299 | .ops = { |
| 300 | .open = cs_playback_pcm_open, |
| 301 | .prepare = cs_playback_pcm_prepare, |
| 302 | .cleanup = cs_playback_pcm_cleanup |
| 303 | }, |
| 304 | }; |
| 305 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 306 | static const struct hda_pcm_stream cs_pcm_analog_capture = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 307 | .substreams = 1, |
| 308 | .channels_min = 2, |
| 309 | .channels_max = 2, |
| 310 | .ops = { |
| 311 | .prepare = cs_capture_pcm_prepare, |
| 312 | .cleanup = cs_capture_pcm_cleanup |
| 313 | }, |
| 314 | }; |
| 315 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 316 | static const struct hda_pcm_stream cs_pcm_digital_playback = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 317 | .substreams = 1, |
| 318 | .channels_min = 2, |
| 319 | .channels_max = 2, |
| 320 | .ops = { |
| 321 | .open = cs_dig_playback_pcm_open, |
| 322 | .close = cs_dig_playback_pcm_close, |
| 323 | .prepare = cs_dig_playback_pcm_prepare, |
| 324 | .cleanup = cs_dig_playback_pcm_cleanup |
| 325 | }, |
| 326 | }; |
| 327 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 328 | static const struct hda_pcm_stream cs_pcm_digital_capture = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 329 | .substreams = 1, |
| 330 | .channels_min = 2, |
| 331 | .channels_max = 2, |
| 332 | }; |
| 333 | |
| 334 | static int cs_build_pcms(struct hda_codec *codec) |
| 335 | { |
| 336 | struct cs_spec *spec = codec->spec; |
| 337 | struct hda_pcm *info = spec->pcm_rec; |
| 338 | |
| 339 | codec->pcm_info = info; |
| 340 | codec->num_pcms = 0; |
| 341 | |
| 342 | info->name = "Cirrus Analog"; |
| 343 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cs_pcm_analog_playback; |
| 344 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0]; |
| 345 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 346 | spec->multiout.max_channels; |
| 347 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 348 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 349 | spec->adc_nid[spec->cur_input]; |
| 350 | codec->num_pcms++; |
| 351 | |
| 352 | if (!spec->multiout.dig_out_nid && !spec->dig_in) |
| 353 | return 0; |
| 354 | |
| 355 | info++; |
| 356 | info->name = "Cirrus Digital"; |
| 357 | info->pcm_type = spec->autocfg.dig_out_type[0]; |
| 358 | if (!info->pcm_type) |
| 359 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
| 360 | if (spec->multiout.dig_out_nid) { |
| 361 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 362 | cs_pcm_digital_playback; |
| 363 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 364 | spec->multiout.dig_out_nid; |
| 365 | } |
| 366 | if (spec->dig_in) { |
| 367 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 368 | cs_pcm_digital_capture; |
| 369 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in; |
| 370 | } |
| 371 | codec->num_pcms++; |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 376 | /* |
| 377 | * parse codec topology |
| 378 | */ |
| 379 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 380 | static hda_nid_t get_dac(struct hda_codec *codec, hda_nid_t pin) |
| 381 | { |
| 382 | hda_nid_t dac; |
| 383 | if (!pin) |
| 384 | return 0; |
| 385 | if (snd_hda_get_connections(codec, pin, &dac, 1) != 1) |
| 386 | return 0; |
| 387 | return dac; |
| 388 | } |
| 389 | |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 390 | static int is_ext_mic(struct hda_codec *codec, unsigned int idx) |
| 391 | { |
| 392 | struct cs_spec *spec = codec->spec; |
| 393 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 394 | hda_nid_t pin = cfg->inputs[idx].pin; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 395 | unsigned int val; |
| 396 | if (!is_jack_detectable(codec, pin)) |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 397 | return 0; |
| 398 | val = snd_hda_codec_get_pincfg(codec, pin); |
Takashi Iwai | 99ae28b | 2010-09-17 14:42:34 +0200 | [diff] [blame] | 399 | return (snd_hda_get_input_pin_attr(val) != INPUT_PIN_ATTR_INT); |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin, |
| 403 | unsigned int *idxp) |
| 404 | { |
Takashi Iwai | 1b004d0 | 2011-08-20 09:19:59 +0200 | [diff] [blame] | 405 | int i, idx; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 406 | hda_nid_t nid; |
| 407 | |
| 408 | nid = codec->start_nid; |
| 409 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 410 | unsigned int type; |
Takashi Iwai | 1682c81 | 2011-05-17 10:02:27 +0200 | [diff] [blame] | 411 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 412 | if (type != AC_WID_AUD_IN) |
| 413 | continue; |
Takashi Iwai | 1b004d0 | 2011-08-20 09:19:59 +0200 | [diff] [blame] | 414 | idx = snd_hda_get_conn_index(codec, nid, pin, false); |
| 415 | if (idx >= 0) { |
| 416 | *idxp = idx; |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 417 | return nid; |
Takashi Iwai | 1b004d0 | 2011-08-20 09:19:59 +0200 | [diff] [blame] | 418 | } |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 419 | } |
| 420 | return 0; |
| 421 | } |
| 422 | |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 423 | static int is_active_pin(struct hda_codec *codec, hda_nid_t nid) |
| 424 | { |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 425 | unsigned int val; |
| 426 | val = snd_hda_codec_get_pincfg(codec, nid); |
| 427 | return (get_defcfg_connect(val) != AC_JACK_PORT_NONE); |
| 428 | } |
| 429 | |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 430 | static int parse_output(struct hda_codec *codec) |
| 431 | { |
| 432 | struct cs_spec *spec = codec->spec; |
| 433 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 277a57c | 2009-07-08 12:42:08 +0200 | [diff] [blame] | 434 | int i, extra_nids; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 435 | hda_nid_t dac; |
| 436 | |
| 437 | for (i = 0; i < cfg->line_outs; i++) { |
| 438 | dac = get_dac(codec, cfg->line_out_pins[i]); |
| 439 | if (!dac) |
| 440 | break; |
| 441 | spec->dac_nid[i] = dac; |
| 442 | } |
| 443 | spec->multiout.num_dacs = i; |
| 444 | spec->multiout.dac_nids = spec->dac_nid; |
| 445 | spec->multiout.max_channels = i * 2; |
| 446 | |
Takashi Iwai | f37bc7a | 2012-11-08 15:59:23 +0100 | [diff] [blame^] | 447 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && i == 2) |
| 448 | spec->speaker_2_1 = 1; /* assume 2.1 speakers */ |
| 449 | |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 450 | /* add HP and speakers */ |
| 451 | extra_nids = 0; |
| 452 | for (i = 0; i < cfg->hp_outs; i++) { |
| 453 | dac = get_dac(codec, cfg->hp_pins[i]); |
| 454 | if (!dac) |
| 455 | break; |
| 456 | if (!i) |
| 457 | spec->multiout.hp_nid = dac; |
| 458 | else |
| 459 | spec->multiout.extra_out_nid[extra_nids++] = dac; |
| 460 | } |
| 461 | for (i = 0; i < cfg->speaker_outs; i++) { |
| 462 | dac = get_dac(codec, cfg->speaker_pins[i]); |
| 463 | if (!dac) |
| 464 | break; |
| 465 | spec->multiout.extra_out_nid[extra_nids++] = dac; |
| 466 | } |
| 467 | |
| 468 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
| 469 | cfg->speaker_outs = cfg->line_outs; |
| 470 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 471 | sizeof(cfg->speaker_pins)); |
| 472 | cfg->line_outs = 0; |
| 473 | } |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | static int parse_input(struct hda_codec *codec) |
| 479 | { |
| 480 | struct cs_spec *spec = codec->spec; |
| 481 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 277a57c | 2009-07-08 12:42:08 +0200 | [diff] [blame] | 482 | int i; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 483 | |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 484 | for (i = 0; i < cfg->num_inputs; i++) { |
| 485 | hda_nid_t pin = cfg->inputs[i].pin; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 486 | spec->input_idx[spec->num_inputs] = i; |
| 487 | spec->capsrc_idx[i] = spec->num_inputs++; |
| 488 | spec->cur_input = i; |
| 489 | spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]); |
| 490 | } |
| 491 | if (!spec->num_inputs) |
| 492 | return 0; |
| 493 | |
| 494 | /* check whether the automatic mic switch is available */ |
| 495 | if (spec->num_inputs == 2 && |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 496 | cfg->inputs[0].type == AUTO_PIN_MIC && |
| 497 | cfg->inputs[1].type == AUTO_PIN_MIC) { |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 498 | if (is_ext_mic(codec, cfg->inputs[0].pin)) { |
| 499 | if (!is_ext_mic(codec, cfg->inputs[1].pin)) { |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 500 | spec->mic_detect = 1; |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 501 | spec->automic_idx = 0; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 502 | } |
| 503 | } else { |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 504 | if (is_ext_mic(codec, cfg->inputs[1].pin)) { |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 505 | spec->mic_detect = 1; |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 506 | spec->automic_idx = 1; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | } |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | |
| 514 | static int parse_digital_output(struct hda_codec *codec) |
| 515 | { |
| 516 | struct cs_spec *spec = codec->spec; |
| 517 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 518 | hda_nid_t nid; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 519 | |
| 520 | if (!cfg->dig_outs) |
| 521 | return 0; |
| 522 | if (snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) < 1) |
| 523 | return 0; |
| 524 | spec->multiout.dig_out_nid = nid; |
| 525 | spec->multiout.share_spdif = 1; |
| 526 | if (cfg->dig_outs > 1 && |
| 527 | snd_hda_get_connections(codec, cfg->dig_out_pins[1], &nid, 1) > 0) { |
| 528 | spec->slave_dig_outs[0] = nid; |
| 529 | codec->slave_dig_outs = spec->slave_dig_outs; |
| 530 | } |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static int parse_digital_input(struct hda_codec *codec) |
| 535 | { |
| 536 | struct cs_spec *spec = codec->spec; |
| 537 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 538 | int idx; |
| 539 | |
Takashi Iwai | 60e5388 | 2009-07-06 15:01:09 +0200 | [diff] [blame] | 540 | if (cfg->dig_in_pin) |
| 541 | spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx); |
| 542 | return 0; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /* |
| 546 | * create mixer controls |
| 547 | */ |
| 548 | |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 549 | static const char * const dir_sfx[2] = { "Playback", "Capture" }; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 550 | |
| 551 | static int add_mute(struct hda_codec *codec, const char *name, int index, |
| 552 | unsigned int pval, int dir, struct snd_kcontrol **kctlp) |
| 553 | { |
Takashi Iwai | b4dabfc | 2009-07-07 09:05:07 +0200 | [diff] [blame] | 554 | char tmp[44]; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 555 | struct snd_kcontrol_new knew = |
| 556 | HDA_CODEC_MUTE_IDX(tmp, index, 0, 0, HDA_OUTPUT); |
| 557 | knew.private_value = pval; |
| 558 | snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]); |
| 559 | *kctlp = snd_ctl_new1(&knew, codec); |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 560 | (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 561 | return snd_hda_ctl_add(codec, 0, *kctlp); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static int add_volume(struct hda_codec *codec, const char *name, |
| 565 | int index, unsigned int pval, int dir, |
| 566 | struct snd_kcontrol **kctlp) |
| 567 | { |
David Henningsson | 2e1210b | 2011-09-14 13:22:54 +0200 | [diff] [blame] | 568 | char tmp[44]; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 569 | struct snd_kcontrol_new knew = |
| 570 | HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT); |
| 571 | knew.private_value = pval; |
| 572 | snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]); |
| 573 | *kctlp = snd_ctl_new1(&knew, codec); |
Jaroslav Kysela | 9e3fd87 | 2009-12-08 17:45:25 +0100 | [diff] [blame] | 574 | (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG; |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 575 | return snd_hda_ctl_add(codec, 0, *kctlp); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) |
| 579 | { |
| 580 | unsigned int caps; |
| 581 | |
| 582 | /* set the upper-limit for mixer amp to 0dB */ |
| 583 | caps = query_amp_caps(codec, dac, HDA_OUTPUT); |
| 584 | caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT); |
| 585 | caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f) |
| 586 | << AC_AMPCAP_NUM_STEPS_SHIFT; |
| 587 | snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps); |
| 588 | } |
| 589 | |
| 590 | static int add_vmaster(struct hda_codec *codec, hda_nid_t dac) |
| 591 | { |
| 592 | struct cs_spec *spec = codec->spec; |
| 593 | unsigned int tlv[4]; |
| 594 | int err; |
| 595 | |
| 596 | spec->vmaster_sw = |
| 597 | snd_ctl_make_virtual_master("Master Playback Switch", NULL); |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 598 | err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 599 | if (err < 0) |
| 600 | return err; |
| 601 | |
| 602 | snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv); |
| 603 | spec->vmaster_vol = |
| 604 | snd_ctl_make_virtual_master("Master Playback Volume", tlv); |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 605 | err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 606 | if (err < 0) |
| 607 | return err; |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | static int add_output(struct hda_codec *codec, hda_nid_t dac, int idx, |
| 612 | int num_ctls, int type) |
| 613 | { |
| 614 | struct cs_spec *spec = codec->spec; |
| 615 | const char *name; |
| 616 | int err, index; |
| 617 | struct snd_kcontrol *kctl; |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 618 | static const char * const speakers[] = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 619 | "Front Speaker", "Surround Speaker", "Bass Speaker" |
| 620 | }; |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 621 | static const char * const line_outs[] = { |
Takashi Iwai | e49a343 | 2012-03-01 18:14:41 +0100 | [diff] [blame] | 622 | "Front Line Out", "Surround Line Out", "Bass Line Out" |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 623 | }; |
| 624 | |
| 625 | fix_volume_caps(codec, dac); |
| 626 | if (!spec->vmaster_sw) { |
| 627 | err = add_vmaster(codec, dac); |
| 628 | if (err < 0) |
| 629 | return err; |
| 630 | } |
| 631 | |
| 632 | index = 0; |
| 633 | switch (type) { |
| 634 | case AUTO_PIN_HP_OUT: |
| 635 | name = "Headphone"; |
| 636 | index = idx; |
| 637 | break; |
| 638 | case AUTO_PIN_SPEAKER_OUT: |
Takashi Iwai | f37bc7a | 2012-11-08 15:59:23 +0100 | [diff] [blame^] | 639 | if (spec->speaker_2_1) |
| 640 | name = idx ? "Bass Speaker" : "Speaker"; |
| 641 | else if (num_ctls > 1) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 642 | name = speakers[idx]; |
| 643 | else |
| 644 | name = "Speaker"; |
| 645 | break; |
| 646 | default: |
| 647 | if (num_ctls > 1) |
| 648 | name = line_outs[idx]; |
| 649 | else |
Takashi Iwai | e49a343 | 2012-03-01 18:14:41 +0100 | [diff] [blame] | 650 | name = "Line Out"; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 651 | break; |
| 652 | } |
| 653 | |
| 654 | err = add_mute(codec, name, index, |
| 655 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); |
| 656 | if (err < 0) |
| 657 | return err; |
| 658 | err = snd_ctl_add_slave(spec->vmaster_sw, kctl); |
| 659 | if (err < 0) |
| 660 | return err; |
| 661 | |
| 662 | err = add_volume(codec, name, index, |
| 663 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); |
| 664 | if (err < 0) |
| 665 | return err; |
| 666 | err = snd_ctl_add_slave(spec->vmaster_vol, kctl); |
| 667 | if (err < 0) |
| 668 | return err; |
| 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static int build_output(struct hda_codec *codec) |
| 674 | { |
| 675 | struct cs_spec *spec = codec->spec; |
| 676 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 677 | int i, err; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 678 | |
| 679 | for (i = 0; i < cfg->line_outs; i++) { |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 680 | err = add_output(codec, get_dac(codec, cfg->line_out_pins[i]), |
| 681 | i, cfg->line_outs, cfg->line_out_type); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 682 | if (err < 0) |
| 683 | return err; |
| 684 | } |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 685 | for (i = 0; i < cfg->hp_outs; i++) { |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 686 | err = add_output(codec, get_dac(codec, cfg->hp_pins[i]), |
| 687 | i, cfg->hp_outs, AUTO_PIN_HP_OUT); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 688 | if (err < 0) |
| 689 | return err; |
| 690 | } |
| 691 | for (i = 0; i < cfg->speaker_outs; i++) { |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 692 | err = add_output(codec, get_dac(codec, cfg->speaker_pins[i]), |
| 693 | i, cfg->speaker_outs, AUTO_PIN_SPEAKER_OUT); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 694 | if (err < 0) |
| 695 | return err; |
| 696 | } |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | */ |
| 702 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 703 | static const struct snd_kcontrol_new cs_capture_ctls[] = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 704 | HDA_BIND_SW("Capture Switch", 0), |
| 705 | HDA_BIND_VOL("Capture Volume", 0), |
| 706 | }; |
| 707 | |
Takashi Iwai | ea35929 | 2009-07-06 12:58:59 +0200 | [diff] [blame] | 708 | static int change_cur_input(struct hda_codec *codec, unsigned int idx, |
| 709 | int force) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 710 | { |
| 711 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 712 | |
Takashi Iwai | ea35929 | 2009-07-06 12:58:59 +0200 | [diff] [blame] | 713 | if (spec->cur_input == idx && !force) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 714 | return 0; |
| 715 | if (spec->cur_adc && spec->cur_adc != spec->adc_nid[idx]) { |
| 716 | /* stream is running, let's swap the current ADC */ |
Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 717 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 718 | spec->cur_adc = spec->adc_nid[idx]; |
| 719 | snd_hda_codec_setup_stream(codec, spec->cur_adc, |
| 720 | spec->cur_adc_stream_tag, 0, |
| 721 | spec->cur_adc_format); |
| 722 | } |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 723 | spec->cur_input = idx; |
Takashi Iwai | 05ee796 | 2011-11-16 18:05:11 +0100 | [diff] [blame] | 724 | cs_update_input_select(codec); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 725 | return 1; |
| 726 | } |
| 727 | |
| 728 | static int cs_capture_source_info(struct snd_kcontrol *kcontrol, |
| 729 | struct snd_ctl_elem_info *uinfo) |
| 730 | { |
| 731 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 732 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 733 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 734 | unsigned int idx; |
| 735 | |
| 736 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 737 | uinfo->count = 1; |
| 738 | uinfo->value.enumerated.items = spec->num_inputs; |
| 739 | if (uinfo->value.enumerated.item >= spec->num_inputs) |
| 740 | uinfo->value.enumerated.item = spec->num_inputs - 1; |
| 741 | idx = spec->input_idx[uinfo->value.enumerated.item]; |
Takashi Iwai | 201e06f | 2011-11-16 15:33:26 +0100 | [diff] [blame] | 742 | snd_hda_get_pin_label(codec, cfg->inputs[idx].pin, cfg, |
| 743 | uinfo->value.enumerated.name, |
| 744 | sizeof(uinfo->value.enumerated.name), NULL); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static int cs_capture_source_get(struct snd_kcontrol *kcontrol, |
| 749 | struct snd_ctl_elem_value *ucontrol) |
| 750 | { |
| 751 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 752 | struct cs_spec *spec = codec->spec; |
| 753 | ucontrol->value.enumerated.item[0] = spec->capsrc_idx[spec->cur_input]; |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | static int cs_capture_source_put(struct snd_kcontrol *kcontrol, |
| 758 | struct snd_ctl_elem_value *ucontrol) |
| 759 | { |
| 760 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 761 | struct cs_spec *spec = codec->spec; |
| 762 | unsigned int idx = ucontrol->value.enumerated.item[0]; |
| 763 | |
| 764 | if (idx >= spec->num_inputs) |
| 765 | return -EINVAL; |
| 766 | idx = spec->input_idx[idx]; |
Takashi Iwai | ea35929 | 2009-07-06 12:58:59 +0200 | [diff] [blame] | 767 | return change_cur_input(codec, idx, 0); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 768 | } |
| 769 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 770 | static const struct snd_kcontrol_new cs_capture_source = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 771 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 772 | .name = "Capture Source", |
| 773 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 774 | .info = cs_capture_source_info, |
| 775 | .get = cs_capture_source_get, |
| 776 | .put = cs_capture_source_put, |
| 777 | }; |
| 778 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 779 | static const struct hda_bind_ctls *make_bind_capture(struct hda_codec *codec, |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 780 | struct hda_ctl_ops *ops) |
| 781 | { |
| 782 | struct cs_spec *spec = codec->spec; |
| 783 | struct hda_bind_ctls *bind; |
| 784 | int i, n; |
| 785 | |
| 786 | bind = kzalloc(sizeof(*bind) + sizeof(long) * (spec->num_inputs + 1), |
| 787 | GFP_KERNEL); |
| 788 | if (!bind) |
| 789 | return NULL; |
| 790 | bind->ops = ops; |
| 791 | n = 0; |
| 792 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 793 | if (!spec->adc_nid[i]) |
| 794 | continue; |
| 795 | bind->values[n++] = |
| 796 | HDA_COMPOSE_AMP_VAL(spec->adc_nid[i], 3, |
| 797 | spec->adc_idx[i], HDA_INPUT); |
| 798 | } |
| 799 | return bind; |
| 800 | } |
| 801 | |
Takashi Iwai | 6a92934 | 2010-10-11 15:16:20 +0200 | [diff] [blame] | 802 | /* add a (input-boost) volume control to the given input pin */ |
| 803 | static int add_input_volume_control(struct hda_codec *codec, |
| 804 | struct auto_pin_cfg *cfg, |
| 805 | int item) |
| 806 | { |
| 807 | hda_nid_t pin = cfg->inputs[item].pin; |
| 808 | u32 caps; |
| 809 | const char *label; |
| 810 | struct snd_kcontrol *kctl; |
| 811 | |
| 812 | if (!(get_wcaps(codec, pin) & AC_WCAP_IN_AMP)) |
| 813 | return 0; |
| 814 | caps = query_amp_caps(codec, pin, HDA_INPUT); |
| 815 | caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; |
| 816 | if (caps <= 1) |
| 817 | return 0; |
| 818 | label = hda_get_autocfg_input_label(codec, cfg, item); |
| 819 | return add_volume(codec, label, 0, |
| 820 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT), 1, &kctl); |
| 821 | } |
| 822 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 823 | static int build_input(struct hda_codec *codec) |
| 824 | { |
| 825 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 826 | int i, err; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 827 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 828 | if (!spec->num_inputs) |
| 829 | return 0; |
| 830 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 831 | /* make bind-capture */ |
| 832 | spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw); |
| 833 | spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol); |
| 834 | for (i = 0; i < 2; i++) { |
| 835 | struct snd_kcontrol *kctl; |
Takashi Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 836 | int n; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 837 | if (!spec->capture_bind[i]) |
| 838 | return -ENOMEM; |
| 839 | kctl = snd_ctl_new1(&cs_capture_ctls[i], codec); |
| 840 | if (!kctl) |
| 841 | return -ENOMEM; |
| 842 | kctl->private_value = (long)spec->capture_bind[i]; |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 843 | err = snd_hda_ctl_add(codec, 0, kctl); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 844 | if (err < 0) |
| 845 | return err; |
Takashi Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 846 | for (n = 0; n < AUTO_PIN_LAST; n++) { |
| 847 | if (!spec->adc_nid[n]) |
| 848 | continue; |
Brian J. Tarricone | 8dd34ab | 2010-05-02 17:32:10 -0700 | [diff] [blame] | 849 | err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]); |
Takashi Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 850 | if (err < 0) |
| 851 | return err; |
| 852 | } |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | if (spec->num_inputs > 1 && !spec->mic_detect) { |
Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 856 | err = snd_hda_ctl_add(codec, 0, |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 857 | snd_ctl_new1(&cs_capture_source, codec)); |
| 858 | if (err < 0) |
| 859 | return err; |
| 860 | } |
| 861 | |
Takashi Iwai | 6a92934 | 2010-10-11 15:16:20 +0200 | [diff] [blame] | 862 | for (i = 0; i < spec->num_inputs; i++) { |
| 863 | err = add_input_volume_control(codec, &spec->autocfg, i); |
| 864 | if (err < 0) |
| 865 | return err; |
| 866 | } |
| 867 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 868 | return 0; |
| 869 | } |
| 870 | |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 871 | /* |
| 872 | */ |
| 873 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 874 | static int build_digital_output(struct hda_codec *codec) |
| 875 | { |
| 876 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 877 | int err; |
| 878 | |
Takashi Iwai | 63b2413 | 2009-07-09 11:45:59 +0200 | [diff] [blame] | 879 | if (!spec->multiout.dig_out_nid) |
| 880 | return 0; |
| 881 | |
Takashi Iwai | dcda580 | 2012-10-12 17:24:51 +0200 | [diff] [blame] | 882 | err = snd_hda_create_dig_out_ctls(codec, spec->multiout.dig_out_nid, |
| 883 | spec->multiout.dig_out_nid, |
| 884 | spec->pcm_rec[1].pcm_type); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 885 | if (err < 0) |
| 886 | return err; |
| 887 | err = snd_hda_create_spdif_share_sw(codec, &spec->multiout); |
| 888 | if (err < 0) |
| 889 | return err; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 890 | return 0; |
| 891 | } |
| 892 | |
| 893 | static int build_digital_input(struct hda_codec *codec) |
| 894 | { |
| 895 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 896 | if (spec->dig_in) |
| 897 | return snd_hda_create_spdif_in_ctls(codec, spec->dig_in); |
| 898 | return 0; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 899 | } |
| 900 | |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 901 | /* |
| 902 | * auto-mute and auto-mic switching |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 903 | * CS421x auto-output redirecting |
| 904 | * HP/SPK/SPDIF |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 905 | */ |
| 906 | |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 907 | static void cs_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 908 | { |
| 909 | struct cs_spec *spec = codec->spec; |
| 910 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 911 | unsigned int hp_present; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 912 | unsigned int spdif_present; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 913 | hda_nid_t nid; |
| 914 | int i; |
| 915 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 916 | spdif_present = 0; |
| 917 | if (cfg->dig_outs) { |
| 918 | nid = cfg->dig_out_pins[0]; |
| 919 | if (is_jack_detectable(codec, nid)) { |
| 920 | /* |
| 921 | TODO: SPDIF output redirect when SENSE_B is enabled. |
| 922 | Shared (SENSE_A) jack (e.g HP/mini-TOSLINK) |
| 923 | assumed. |
| 924 | */ |
| 925 | if (snd_hda_jack_detect(codec, nid) |
| 926 | /* && spec->sense_b */) |
| 927 | spdif_present = 1; |
| 928 | } |
| 929 | } |
| 930 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 931 | hp_present = 0; |
| 932 | for (i = 0; i < cfg->hp_outs; i++) { |
| 933 | nid = cfg->hp_pins[i]; |
Takashi Iwai | 06dec22 | 2011-05-17 10:00:16 +0200 | [diff] [blame] | 934 | if (!is_jack_detectable(codec, nid)) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 935 | continue; |
Wu Fengguang | 864f92b | 2009-11-18 12:38:02 +0800 | [diff] [blame] | 936 | hp_present = snd_hda_jack_detect(codec, nid); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 937 | if (hp_present) |
| 938 | break; |
| 939 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 940 | |
| 941 | /* mute speakers if spdif or hp jack is plugged in */ |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 942 | for (i = 0; i < cfg->speaker_outs; i++) { |
David Henningsson | 78e2a92 | 2012-01-02 12:40:16 +0100 | [diff] [blame] | 943 | int pin_ctl = hp_present ? 0 : PIN_OUT; |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 944 | /* detect on spdif is specific to CS4210 */ |
| 945 | if (spdif_present && (spec->vendor_nid == CS4210_VENDOR_NID)) |
David Henningsson | 78e2a92 | 2012-01-02 12:40:16 +0100 | [diff] [blame] | 946 | pin_ctl = 0; |
| 947 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 948 | nid = cfg->speaker_pins[i]; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 949 | snd_hda_set_pin_ctl(codec, nid, pin_ctl); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 950 | } |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 951 | if (spec->gpio_eapd_hp) { |
| 952 | unsigned int gpio = hp_present ? |
| 953 | spec->gpio_eapd_hp : spec->gpio_eapd_speaker; |
Stelian Pop | 3a38516 | 2009-07-30 14:44:27 +0200 | [diff] [blame] | 954 | snd_hda_codec_write(codec, 0x01, 0, |
| 955 | AC_VERB_SET_GPIO_DATA, gpio); |
| 956 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 957 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 958 | /* specific to CS4210 */ |
| 959 | if (spec->vendor_nid == CS4210_VENDOR_NID) { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 960 | /* mute HPs if spdif jack (SENSE_B) is present */ |
| 961 | for (i = 0; i < cfg->hp_outs; i++) { |
| 962 | nid = cfg->hp_pins[i]; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 963 | snd_hda_set_pin_ctl(codec, nid, |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 964 | (spdif_present && spec->sense_b) ? 0 : PIN_HP); |
| 965 | } |
| 966 | |
| 967 | /* SPDIF TX on/off */ |
| 968 | if (cfg->dig_outs) { |
| 969 | nid = cfg->dig_out_pins[0]; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 970 | snd_hda_set_pin_ctl(codec, nid, |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 971 | spdif_present ? PIN_OUT : 0); |
| 972 | |
| 973 | } |
| 974 | /* Update board GPIOs if neccessary ... */ |
| 975 | } |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 976 | } |
| 977 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 978 | /* |
| 979 | * Auto-input redirect for CS421x |
| 980 | * Switch max 3 inputs of a single ADC (nid 3) |
| 981 | */ |
| 982 | |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 983 | static void cs_automic(struct hda_codec *codec, struct hda_jack_tbl *tbl) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 984 | { |
| 985 | struct cs_spec *spec = codec->spec; |
| 986 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 987 | hda_nid_t nid; |
Wu Fengguang | 864f92b | 2009-11-18 12:38:02 +0800 | [diff] [blame] | 988 | unsigned int present; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 989 | |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 990 | nid = cfg->inputs[spec->automic_idx].pin; |
Wu Fengguang | 864f92b | 2009-11-18 12:38:02 +0800 | [diff] [blame] | 991 | present = snd_hda_jack_detect(codec, nid); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 992 | |
| 993 | /* specific to CS421x, single ADC */ |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 994 | if (spec->vendor_nid == CS420X_VENDOR_NID) { |
| 995 | if (present) |
| 996 | change_cur_input(codec, spec->automic_idx, 0); |
| 997 | else |
| 998 | change_cur_input(codec, !spec->automic_idx, 0); |
| 999 | } else { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1000 | if (present) { |
Dylan Reid | f70eecd | 2012-01-31 13:04:41 -0800 | [diff] [blame] | 1001 | if (spec->cur_input != spec->automic_idx) { |
| 1002 | spec->last_input = spec->cur_input; |
| 1003 | spec->cur_input = spec->automic_idx; |
| 1004 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1005 | } else { |
| 1006 | spec->cur_input = spec->last_input; |
| 1007 | } |
Takashi Iwai | 05ee796 | 2011-11-16 18:05:11 +0100 | [diff] [blame] | 1008 | cs_update_input_select(codec); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1009 | } |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /* |
| 1013 | */ |
| 1014 | |
| 1015 | static void init_output(struct hda_codec *codec) |
| 1016 | { |
| 1017 | struct cs_spec *spec = codec->spec; |
| 1018 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1019 | int i; |
| 1020 | |
| 1021 | /* mute first */ |
| 1022 | for (i = 0; i < spec->multiout.num_dacs; i++) |
| 1023 | snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0, |
| 1024 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); |
| 1025 | if (spec->multiout.hp_nid) |
| 1026 | snd_hda_codec_write(codec, spec->multiout.hp_nid, 0, |
| 1027 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); |
| 1028 | for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) { |
| 1029 | if (!spec->multiout.extra_out_nid[i]) |
| 1030 | break; |
| 1031 | snd_hda_codec_write(codec, spec->multiout.extra_out_nid[i], 0, |
| 1032 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); |
| 1033 | } |
| 1034 | |
| 1035 | /* set appropriate pin controls */ |
| 1036 | for (i = 0; i < cfg->line_outs; i++) |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 1037 | snd_hda_set_pin_ctl(codec, cfg->line_out_pins[i], PIN_OUT); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1038 | /* HP */ |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1039 | for (i = 0; i < cfg->hp_outs; i++) { |
| 1040 | hda_nid_t nid = cfg->hp_pins[i]; |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 1041 | snd_hda_set_pin_ctl(codec, nid, PIN_HP); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1042 | if (!cfg->speaker_outs) |
| 1043 | continue; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1044 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 1045 | snd_hda_jack_detect_enable_callback(codec, nid, HP_EVENT, cs_automute); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1046 | spec->hp_detect = 1; |
| 1047 | } |
| 1048 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1049 | |
| 1050 | /* Speaker */ |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1051 | for (i = 0; i < cfg->speaker_outs; i++) |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 1052 | snd_hda_set_pin_ctl(codec, cfg->speaker_pins[i], PIN_OUT); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1053 | |
| 1054 | /* SPDIF is enabled on presence detect for CS421x */ |
| 1055 | if (spec->hp_detect || spec->spdif_detect) |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 1056 | cs_automute(codec, NULL); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | static void init_input(struct hda_codec *codec) |
| 1060 | { |
| 1061 | struct cs_spec *spec = codec->spec; |
| 1062 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 1063 | unsigned int coef; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1064 | int i; |
| 1065 | |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 1066 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1067 | unsigned int ctl; |
Takashi Iwai | c1e0bb9 | 2010-08-30 13:05:30 +0200 | [diff] [blame] | 1068 | hda_nid_t pin = cfg->inputs[i].pin; |
| 1069 | if (!spec->adc_nid[i]) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1070 | continue; |
| 1071 | /* set appropriate pin control and mute first */ |
| 1072 | ctl = PIN_IN; |
Takashi Iwai | 4740860 | 2012-04-20 13:06:53 +0200 | [diff] [blame] | 1073 | if (cfg->inputs[i].type == AUTO_PIN_MIC) |
| 1074 | ctl |= snd_hda_get_default_vref(codec, pin); |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 1075 | snd_hda_set_pin_ctl(codec, pin, ctl); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1076 | snd_hda_codec_write(codec, spec->adc_nid[i], 0, |
| 1077 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 1078 | AMP_IN_MUTE(spec->adc_idx[i])); |
| 1079 | if (spec->mic_detect && spec->automic_idx == i) |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 1080 | snd_hda_jack_detect_enable_callback(codec, pin, MIC_EVENT, cs_automic); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1081 | } |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1082 | /* CS420x has multiple ADC, CS421x has single ADC */ |
| 1083 | if (spec->vendor_nid == CS420X_VENDOR_NID) { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1084 | change_cur_input(codec, spec->cur_input, 1); |
| 1085 | if (spec->mic_detect) |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 1086 | cs_automic(codec, NULL); |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 1087 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1088 | coef = 0x000a; /* ADC1/2 - Digital and Analog Soft Ramp */ |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 1089 | cs_vendor_coef_set(codec, IDX_ADC_CFG, coef); |
| 1090 | |
| 1091 | coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1092 | if (is_active_pin(codec, CS_DMIC2_PIN_NID)) |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 1093 | coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */ |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1094 | if (is_active_pin(codec, CS_DMIC1_PIN_NID)) |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 1095 | coef |= 1 << 3; /* DMIC1 2 chan on, GPIO0 off |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1096 | * No effect if SPDIF_OUT2 is |
| 1097 | * selected in IDX_SPDIF_CTL. |
| 1098 | */ |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 1099 | |
| 1100 | cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef); |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1101 | } else { |
| 1102 | if (spec->mic_detect) |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 1103 | cs_automic(codec, NULL); |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1104 | else { |
| 1105 | spec->cur_adc = spec->adc_nid[spec->cur_input]; |
| 1106 | cs_update_input_select(codec); |
| 1107 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1108 | } |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 1111 | static const struct hda_verb cs_coef_init_verbs[] = { |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 1112 | {0x11, AC_VERB_SET_PROC_STATE, 1}, |
| 1113 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG}, |
| 1114 | {0x11, AC_VERB_SET_PROC_COEF, |
| 1115 | (0x002a /* DAC1/2/3 SZCMode Soft Ramp */ |
| 1116 | | 0x0040 /* Mute DACs on FIFO error */ |
| 1117 | | 0x1000 /* Enable DACs High Pass Filter */ |
| 1118 | | 0x0400 /* Disable Coefficient Auto increment */ |
| 1119 | )}, |
| 1120 | /* Beep */ |
Alexander Stein | 5a83b4b | 2012-11-01 13:42:37 +0100 | [diff] [blame] | 1121 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_BEEP_CFG}, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 1122 | {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */ |
| 1123 | |
| 1124 | {} /* terminator */ |
| 1125 | }; |
| 1126 | |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 1127 | /* Errata: CS4207 rev C0/C1/C2 Silicon |
| 1128 | * |
| 1129 | * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf |
| 1130 | * |
| 1131 | * 6. At high temperature (TA > +85°C), the digital supply current (IVD) |
| 1132 | * may be excessive (up to an additional 200 μA), which is most easily |
| 1133 | * observed while the part is being held in reset (RESET# active low). |
| 1134 | * |
| 1135 | * Root Cause: At initial powerup of the device, the logic that drives |
| 1136 | * the clock and write enable to the S/PDIF SRC RAMs is not properly |
| 1137 | * initialized. |
| 1138 | * Certain random patterns will cause a steady leakage current in those |
| 1139 | * RAM cells. The issue will resolve once the SRCs are used (turned on). |
| 1140 | * |
| 1141 | * Workaround: The following verb sequence briefly turns on the S/PDIF SRC |
| 1142 | * blocks, which will alleviate the issue. |
| 1143 | */ |
| 1144 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 1145 | static const struct hda_verb cs_errata_init_verbs[] = { |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 1146 | {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */ |
| 1147 | {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */ |
| 1148 | |
| 1149 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0008}, |
| 1150 | {0x11, AC_VERB_SET_PROC_COEF, 0x9999}, |
| 1151 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0017}, |
| 1152 | {0x11, AC_VERB_SET_PROC_COEF, 0xa412}, |
| 1153 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0001}, |
| 1154 | {0x11, AC_VERB_SET_PROC_COEF, 0x0009}, |
| 1155 | |
| 1156 | {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */ |
| 1157 | {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */ |
| 1158 | |
| 1159 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0017}, |
| 1160 | {0x11, AC_VERB_SET_PROC_COEF, 0x2412}, |
| 1161 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0008}, |
| 1162 | {0x11, AC_VERB_SET_PROC_COEF, 0x0000}, |
| 1163 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0001}, |
| 1164 | {0x11, AC_VERB_SET_PROC_COEF, 0x0008}, |
| 1165 | {0x11, AC_VERB_SET_PROC_STATE, 0x00}, |
| 1166 | |
Takashi Iwai | 38c0764 | 2011-03-03 14:54:19 +0100 | [diff] [blame] | 1167 | #if 0 /* Don't to set to D3 as we are in power-up sequence */ |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 1168 | {0x07, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Rx: D3 */ |
| 1169 | {0x08, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Tx: D3 */ |
| 1170 | /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */ |
Takashi Iwai | 38c0764 | 2011-03-03 14:54:19 +0100 | [diff] [blame] | 1171 | #endif |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 1172 | |
| 1173 | {} /* terminator */ |
| 1174 | }; |
| 1175 | |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 1176 | static const struct hda_verb mbp101_init_verbs[] = { |
| 1177 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0002}, |
| 1178 | {0x11, AC_VERB_SET_PROC_COEF, 0x100a}, |
| 1179 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0004}, |
| 1180 | {0x11, AC_VERB_SET_PROC_COEF, 0x000f}, |
| 1181 | {} |
| 1182 | }; |
| 1183 | |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 1184 | /* SPDIF setup */ |
| 1185 | static void init_digital(struct hda_codec *codec) |
| 1186 | { |
| 1187 | unsigned int coef; |
| 1188 | |
| 1189 | coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */ |
| 1190 | coef |= 0x0008; /* Replace with mute on error */ |
| 1191 | if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID)) |
| 1192 | coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2 |
| 1193 | * SPDIF_OUT2 is shared with GPIO1 and |
| 1194 | * DMIC_SDA2. |
| 1195 | */ |
| 1196 | cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | static int cs_init(struct hda_codec *codec) |
| 1200 | { |
| 1201 | struct cs_spec *spec = codec->spec; |
| 1202 | |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 1203 | /* init_verb sequence for C0/C1/C2 errata*/ |
| 1204 | snd_hda_sequence_write(codec, cs_errata_init_verbs); |
| 1205 | |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 1206 | snd_hda_sequence_write(codec, cs_coef_init_verbs); |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 1207 | |
| 1208 | if (spec->gpio_mask) { |
| 1209 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, |
| 1210 | spec->gpio_mask); |
| 1211 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, |
| 1212 | spec->gpio_dir); |
| 1213 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, |
| 1214 | spec->gpio_data); |
| 1215 | } |
| 1216 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1217 | init_output(codec); |
| 1218 | init_input(codec); |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 1219 | init_digital(codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 1220 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1221 | return 0; |
| 1222 | } |
| 1223 | |
| 1224 | static int cs_build_controls(struct hda_codec *codec) |
| 1225 | { |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 1226 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1227 | int err; |
| 1228 | |
| 1229 | err = build_output(codec); |
| 1230 | if (err < 0) |
| 1231 | return err; |
| 1232 | err = build_input(codec); |
| 1233 | if (err < 0) |
| 1234 | return err; |
| 1235 | err = build_digital_output(codec); |
| 1236 | if (err < 0) |
| 1237 | return err; |
| 1238 | err = build_digital_input(codec); |
| 1239 | if (err < 0) |
| 1240 | return err; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 1241 | err = cs_init(codec); |
| 1242 | if (err < 0) |
| 1243 | return err; |
| 1244 | |
| 1245 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); |
| 1246 | if (err < 0) |
| 1247 | return err; |
| 1248 | |
| 1249 | return 0; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | static void cs_free(struct hda_codec *codec) |
| 1253 | { |
| 1254 | struct cs_spec *spec = codec->spec; |
| 1255 | kfree(spec->capture_bind[0]); |
| 1256 | kfree(spec->capture_bind[1]); |
Takashi Iwai | b2cbf3b | 2012-10-10 08:53:06 +0200 | [diff] [blame] | 1257 | snd_hda_gen_free(&spec->gen); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1258 | kfree(codec->spec); |
| 1259 | } |
| 1260 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 1261 | static const struct hda_codec_ops cs_patch_ops = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1262 | .build_controls = cs_build_controls, |
| 1263 | .build_pcms = cs_build_pcms, |
| 1264 | .init = cs_init, |
| 1265 | .free = cs_free, |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 1266 | .unsol_event = snd_hda_jack_unsol_event, |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1267 | }; |
| 1268 | |
| 1269 | static int cs_parse_auto_config(struct hda_codec *codec) |
| 1270 | { |
| 1271 | struct cs_spec *spec = codec->spec; |
| 1272 | int err; |
| 1273 | |
| 1274 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 1275 | if (err < 0) |
| 1276 | return err; |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 1277 | |
| 1278 | err = parse_output(codec); |
| 1279 | if (err < 0) |
| 1280 | return err; |
| 1281 | err = parse_input(codec); |
| 1282 | if (err < 0) |
| 1283 | return err; |
| 1284 | err = parse_digital_output(codec); |
| 1285 | if (err < 0) |
| 1286 | return err; |
| 1287 | err = parse_digital_input(codec); |
| 1288 | if (err < 0) |
| 1289 | return err; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1290 | return 0; |
| 1291 | } |
| 1292 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1293 | static const struct hda_model_fixup cs420x_models[] = { |
| 1294 | { .id = CS420X_MBP53, .name = "mbp53" }, |
| 1295 | { .id = CS420X_MBP55, .name = "mbp55" }, |
| 1296 | { .id = CS420X_IMAC27, .name = "imac27" }, |
| 1297 | { .id = CS420X_IMAC27_122, .name = "imac27_122" }, |
| 1298 | { .id = CS420X_APPLE, .name = "apple" }, |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 1299 | { .id = CS420X_MBP101, .name = "mbp101" }, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1300 | {} |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 1301 | }; |
| 1302 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1303 | static const struct snd_pci_quirk cs420x_fixup_tbl[] = { |
Vince Weaver | 4e7d7c6 | 2010-09-22 17:31:37 -0400 | [diff] [blame] | 1304 | SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53), |
Edgar (gimli) Hucek | 87232dd | 2010-11-03 08:14:10 +0100 | [diff] [blame] | 1305 | SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55), |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 1306 | SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55), |
Takashi Iwai | f46119b | 2010-10-11 14:46:35 +0200 | [diff] [blame] | 1307 | SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55), |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 1308 | /* this conflicts with too many other models */ |
| 1309 | /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/ |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 1310 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1311 | /* codec SSID */ |
Jérémy Lal | 7e5bea1 | 2012-01-09 17:19:45 +0100 | [diff] [blame] | 1312 | SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122), |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 1313 | SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101), |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 1314 | SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE), |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 1315 | {} /* terminator */ |
| 1316 | }; |
| 1317 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1318 | static const struct hda_pintbl mbp53_pincfgs[] = { |
Vince Weaver | 4e7d7c6 | 2010-09-22 17:31:37 -0400 | [diff] [blame] | 1319 | { 0x09, 0x012b4050 }, |
| 1320 | { 0x0a, 0x90100141 }, |
| 1321 | { 0x0b, 0x90100140 }, |
| 1322 | { 0x0c, 0x018b3020 }, |
| 1323 | { 0x0d, 0x90a00110 }, |
| 1324 | { 0x0e, 0x400000f0 }, |
| 1325 | { 0x0f, 0x01cbe030 }, |
| 1326 | { 0x10, 0x014be060 }, |
| 1327 | { 0x12, 0x400000f0 }, |
| 1328 | { 0x15, 0x400000f0 }, |
| 1329 | {} /* terminator */ |
| 1330 | }; |
| 1331 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1332 | static const struct hda_pintbl mbp55_pincfgs[] = { |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 1333 | { 0x09, 0x012b4030 }, |
| 1334 | { 0x0a, 0x90100121 }, |
| 1335 | { 0x0b, 0x90100120 }, |
| 1336 | { 0x0c, 0x400000f0 }, |
| 1337 | { 0x0d, 0x90a00110 }, |
| 1338 | { 0x0e, 0x400000f0 }, |
| 1339 | { 0x0f, 0x400000f0 }, |
| 1340 | { 0x10, 0x014be040 }, |
| 1341 | { 0x12, 0x400000f0 }, |
| 1342 | { 0x15, 0x400000f0 }, |
| 1343 | {} /* terminator */ |
| 1344 | }; |
| 1345 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1346 | static const struct hda_pintbl imac27_pincfgs[] = { |
Rafael Avila de Espindola | 1a5ba2e | 2009-12-22 07:59:37 +0100 | [diff] [blame] | 1347 | { 0x09, 0x012b4050 }, |
| 1348 | { 0x0a, 0x90100140 }, |
| 1349 | { 0x0b, 0x90100142 }, |
| 1350 | { 0x0c, 0x018b3020 }, |
| 1351 | { 0x0d, 0x90a00110 }, |
| 1352 | { 0x0e, 0x400000f0 }, |
| 1353 | { 0x0f, 0x01cbe030 }, |
| 1354 | { 0x10, 0x014be060 }, |
| 1355 | { 0x12, 0x01ab9070 }, |
| 1356 | { 0x15, 0x400000f0 }, |
| 1357 | {} /* terminator */ |
| 1358 | }; |
| 1359 | |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 1360 | static const struct hda_pintbl mbp101_pincfgs[] = { |
| 1361 | { 0x0d, 0x40ab90f0 }, |
| 1362 | { 0x0e, 0x90a600f0 }, |
| 1363 | { 0x12, 0x50a600f0 }, |
| 1364 | {} /* terminator */ |
| 1365 | }; |
| 1366 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1367 | static void cs420x_fixup_gpio_13(struct hda_codec *codec, |
| 1368 | const struct hda_fixup *fix, int action) |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 1369 | { |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1370 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
| 1371 | struct cs_spec *spec = codec->spec; |
| 1372 | spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */ |
| 1373 | spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */ |
| 1374 | spec->gpio_mask = spec->gpio_dir = |
| 1375 | spec->gpio_eapd_hp | spec->gpio_eapd_speaker; |
| 1376 | } |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 1377 | } |
| 1378 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1379 | static void cs420x_fixup_gpio_23(struct hda_codec *codec, |
| 1380 | const struct hda_fixup *fix, int action) |
| 1381 | { |
| 1382 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
| 1383 | struct cs_spec *spec = codec->spec; |
| 1384 | spec->gpio_eapd_hp = 4; /* GPIO2 = headphones */ |
| 1385 | spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */ |
| 1386 | spec->gpio_mask = spec->gpio_dir = |
| 1387 | spec->gpio_eapd_hp | spec->gpio_eapd_speaker; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | static const struct hda_fixup cs420x_fixups[] = { |
| 1392 | [CS420X_MBP53] = { |
| 1393 | .type = HDA_FIXUP_PINS, |
| 1394 | .v.pins = mbp53_pincfgs, |
| 1395 | .chained = true, |
| 1396 | .chain_id = CS420X_APPLE, |
| 1397 | }, |
| 1398 | [CS420X_MBP55] = { |
| 1399 | .type = HDA_FIXUP_PINS, |
| 1400 | .v.pins = mbp55_pincfgs, |
| 1401 | .chained = true, |
| 1402 | .chain_id = CS420X_GPIO_13, |
| 1403 | }, |
| 1404 | [CS420X_IMAC27] = { |
| 1405 | .type = HDA_FIXUP_PINS, |
| 1406 | .v.pins = imac27_pincfgs, |
| 1407 | .chained = true, |
| 1408 | .chain_id = CS420X_GPIO_13, |
| 1409 | }, |
| 1410 | [CS420X_GPIO_13] = { |
| 1411 | .type = HDA_FIXUP_FUNC, |
| 1412 | .v.func = cs420x_fixup_gpio_13, |
| 1413 | }, |
| 1414 | [CS420X_GPIO_23] = { |
| 1415 | .type = HDA_FIXUP_FUNC, |
| 1416 | .v.func = cs420x_fixup_gpio_23, |
| 1417 | }, |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 1418 | [CS420X_MBP101] = { |
| 1419 | .type = HDA_FIXUP_PINS, |
| 1420 | .v.pins = mbp101_pincfgs, |
| 1421 | .chained = true, |
| 1422 | .chain_id = CS420X_MBP101_COEF, |
| 1423 | }, |
| 1424 | [CS420X_MBP101_COEF] = { |
| 1425 | .type = HDA_FIXUP_VERBS, |
| 1426 | .v.verbs = mbp101_init_verbs, |
| 1427 | .chained = true, |
| 1428 | .chain_id = CS420X_GPIO_13, |
| 1429 | }, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1430 | }; |
| 1431 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1432 | static int patch_cs420x(struct hda_codec *codec) |
| 1433 | { |
| 1434 | struct cs_spec *spec; |
| 1435 | int err; |
| 1436 | |
| 1437 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1438 | if (!spec) |
| 1439 | return -ENOMEM; |
| 1440 | codec->spec = spec; |
Takashi Iwai | b2cbf3b | 2012-10-10 08:53:06 +0200 | [diff] [blame] | 1441 | snd_hda_gen_init(&spec->gen); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1442 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1443 | spec->vendor_nid = CS420X_VENDOR_NID; |
| 1444 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1445 | snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl, |
| 1446 | cs420x_fixups); |
| 1447 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1448 | |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 1449 | err = cs_parse_auto_config(codec); |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 1450 | if (err < 0) |
| 1451 | goto error; |
| 1452 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1453 | codec->patch_ops = cs_patch_ops; |
| 1454 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1455 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
| 1456 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1457 | return 0; |
| 1458 | |
| 1459 | error: |
Takashi Iwai | c5e0b6d | 2012-10-10 08:50:35 +0200 | [diff] [blame] | 1460 | cs_free(codec); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1461 | codec->spec = NULL; |
| 1462 | return err; |
| 1463 | } |
| 1464 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1465 | /* |
| 1466 | * Cirrus Logic CS4210 |
| 1467 | * |
| 1468 | * 1 DAC => HP(sense) / Speakers, |
| 1469 | * 1 ADC <= LineIn(sense) / MicIn / DMicIn, |
| 1470 | * 1 SPDIF OUT => SPDIF Trasmitter(sense) |
| 1471 | */ |
| 1472 | |
| 1473 | /* CS4210 board names */ |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1474 | static const struct hda_model_fixup cs421x_models[] = { |
| 1475 | { .id = CS421X_CDB4210, .name = "cdb4210" }, |
| 1476 | {} |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1477 | }; |
| 1478 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1479 | static const struct snd_pci_quirk cs421x_fixup_tbl[] = { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1480 | /* Test Intel board + CDB2410 */ |
| 1481 | SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210), |
| 1482 | {} /* terminator */ |
| 1483 | }; |
| 1484 | |
| 1485 | /* CS4210 board pinconfigs */ |
| 1486 | /* Default CS4210 (CDB4210)*/ |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1487 | static const struct hda_pintbl cdb4210_pincfgs[] = { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1488 | { 0x05, 0x0321401f }, |
| 1489 | { 0x06, 0x90170010 }, |
| 1490 | { 0x07, 0x03813031 }, |
| 1491 | { 0x08, 0xb7a70037 }, |
| 1492 | { 0x09, 0xb7a6003e }, |
| 1493 | { 0x0a, 0x034510f0 }, |
| 1494 | {} /* terminator */ |
| 1495 | }; |
| 1496 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1497 | /* Setup GPIO/SENSE for each board (if used) */ |
| 1498 | static void cs421x_fixup_sense_b(struct hda_codec *codec, |
| 1499 | const struct hda_fixup *fix, int action) |
| 1500 | { |
| 1501 | struct cs_spec *spec = codec->spec; |
| 1502 | if (action == HDA_FIXUP_ACT_PRE_PROBE) |
| 1503 | spec->sense_b = 1; |
| 1504 | } |
| 1505 | |
| 1506 | static const struct hda_fixup cs421x_fixups[] = { |
| 1507 | [CS421X_CDB4210] = { |
| 1508 | .type = HDA_FIXUP_PINS, |
| 1509 | .v.pins = cdb4210_pincfgs, |
| 1510 | .chained = true, |
| 1511 | .chain_id = CS421X_SENSE_B, |
| 1512 | }, |
| 1513 | [CS421X_SENSE_B] = { |
| 1514 | .type = HDA_FIXUP_FUNC, |
| 1515 | .v.func = cs421x_fixup_sense_b, |
| 1516 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1517 | }; |
| 1518 | |
| 1519 | static const struct hda_verb cs421x_coef_init_verbs[] = { |
| 1520 | {0x0B, AC_VERB_SET_PROC_STATE, 1}, |
| 1521 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG}, |
| 1522 | /* |
| 1523 | Disable Coefficient Index Auto-Increment(DAI)=1, |
| 1524 | PDREF=0 |
| 1525 | */ |
| 1526 | {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 }, |
| 1527 | |
| 1528 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG}, |
| 1529 | /* ADC SZCMode = Digital Soft Ramp */ |
| 1530 | {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 }, |
| 1531 | |
| 1532 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG}, |
| 1533 | {0x0B, AC_VERB_SET_PROC_COEF, |
| 1534 | (0x0002 /* DAC SZCMode = Digital Soft Ramp */ |
| 1535 | | 0x0004 /* Mute DAC on FIFO error */ |
| 1536 | | 0x0008 /* Enable DAC High Pass Filter */ |
| 1537 | )}, |
| 1538 | {} /* terminator */ |
| 1539 | }; |
| 1540 | |
| 1541 | /* Errata: CS4210 rev A1 Silicon |
| 1542 | * |
| 1543 | * http://www.cirrus.com/en/pubs/errata/ |
| 1544 | * |
| 1545 | * Description: |
| 1546 | * 1. Performance degredation is present in the ADC. |
| 1547 | * 2. Speaker output is not completely muted upon HP detect. |
| 1548 | * 3. Noise is present when clipping occurs on the amplified |
| 1549 | * speaker outputs. |
| 1550 | * |
| 1551 | * Workaround: |
| 1552 | * The following verb sequence written to the registers during |
| 1553 | * initialization will correct the issues listed above. |
| 1554 | */ |
| 1555 | |
| 1556 | static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = { |
| 1557 | {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */ |
| 1558 | |
| 1559 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006}, |
| 1560 | {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */ |
| 1561 | |
| 1562 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A}, |
| 1563 | {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */ |
| 1564 | |
| 1565 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011}, |
| 1566 | {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */ |
| 1567 | |
| 1568 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A}, |
| 1569 | {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */ |
| 1570 | |
| 1571 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B}, |
| 1572 | {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */ |
| 1573 | |
| 1574 | {} /* terminator */ |
| 1575 | }; |
| 1576 | |
| 1577 | /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */ |
| 1578 | static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0); |
| 1579 | |
| 1580 | static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol, |
| 1581 | struct snd_ctl_elem_info *uinfo) |
| 1582 | { |
| 1583 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1584 | uinfo->count = 1; |
| 1585 | uinfo->value.integer.min = 0; |
| 1586 | uinfo->value.integer.max = 3; |
| 1587 | return 0; |
| 1588 | } |
| 1589 | |
| 1590 | static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol, |
| 1591 | struct snd_ctl_elem_value *ucontrol) |
| 1592 | { |
| 1593 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1594 | |
| 1595 | ucontrol->value.integer.value[0] = |
| 1596 | cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003; |
| 1597 | return 0; |
| 1598 | } |
| 1599 | |
| 1600 | static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol, |
| 1601 | struct snd_ctl_elem_value *ucontrol) |
| 1602 | { |
| 1603 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1604 | |
| 1605 | unsigned int vol = ucontrol->value.integer.value[0]; |
| 1606 | unsigned int coef = |
| 1607 | cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL); |
| 1608 | unsigned int original_coef = coef; |
| 1609 | |
| 1610 | coef &= ~0x0003; |
| 1611 | coef |= (vol & 0x0003); |
| 1612 | if (original_coef == coef) |
| 1613 | return 0; |
| 1614 | else { |
| 1615 | cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef); |
| 1616 | return 1; |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | static const struct snd_kcontrol_new cs421x_speaker_bost_ctl = { |
| 1621 | |
| 1622 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1623 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1624 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
| 1625 | .name = "Speaker Boost Playback Volume", |
| 1626 | .info = cs421x_boost_vol_info, |
| 1627 | .get = cs421x_boost_vol_get, |
| 1628 | .put = cs421x_boost_vol_put, |
| 1629 | .tlv = { .p = cs421x_speaker_boost_db_scale }, |
| 1630 | }; |
| 1631 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1632 | static void cs4210_pinmux_init(struct hda_codec *codec) |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1633 | { |
| 1634 | struct cs_spec *spec = codec->spec; |
| 1635 | unsigned int def_conf, coef; |
| 1636 | |
| 1637 | /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */ |
| 1638 | coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG); |
| 1639 | |
| 1640 | if (spec->gpio_mask) |
| 1641 | coef |= 0x0008; /* B1,B2 are GPIOs */ |
| 1642 | else |
| 1643 | coef &= ~0x0008; |
| 1644 | |
| 1645 | if (spec->sense_b) |
| 1646 | coef |= 0x0010; /* B2 is SENSE_B, not inverted */ |
| 1647 | else |
| 1648 | coef &= ~0x0010; |
| 1649 | |
| 1650 | cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef); |
| 1651 | |
| 1652 | if ((spec->gpio_mask || spec->sense_b) && |
| 1653 | is_active_pin(codec, CS421X_DMIC_PIN_NID)) { |
| 1654 | |
| 1655 | /* |
| 1656 | GPIO or SENSE_B forced - disconnect the DMIC pin. |
| 1657 | */ |
| 1658 | def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID); |
| 1659 | def_conf &= ~AC_DEFCFG_PORT_CONN; |
| 1660 | def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT); |
| 1661 | snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf); |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | static void init_cs421x_digital(struct hda_codec *codec) |
| 1666 | { |
| 1667 | struct cs_spec *spec = codec->spec; |
| 1668 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1669 | int i; |
| 1670 | |
| 1671 | |
| 1672 | for (i = 0; i < cfg->dig_outs; i++) { |
| 1673 | hda_nid_t nid = cfg->dig_out_pins[i]; |
| 1674 | if (!cfg->speaker_outs) |
| 1675 | continue; |
| 1676 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 1677 | snd_hda_jack_detect_enable_callback(codec, nid, SPDIF_EVENT, cs_automute); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1678 | spec->spdif_detect = 1; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | static int cs421x_init(struct hda_codec *codec) |
| 1684 | { |
| 1685 | struct cs_spec *spec = codec->spec; |
| 1686 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1687 | if (spec->vendor_nid == CS4210_VENDOR_NID) { |
| 1688 | snd_hda_sequence_write(codec, cs421x_coef_init_verbs); |
| 1689 | snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes); |
| 1690 | cs4210_pinmux_init(codec); |
| 1691 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1692 | |
| 1693 | if (spec->gpio_mask) { |
| 1694 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, |
| 1695 | spec->gpio_mask); |
| 1696 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, |
| 1697 | spec->gpio_dir); |
| 1698 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, |
| 1699 | spec->gpio_data); |
| 1700 | } |
| 1701 | |
| 1702 | init_output(codec); |
| 1703 | init_input(codec); |
| 1704 | init_cs421x_digital(codec); |
| 1705 | |
| 1706 | return 0; |
| 1707 | } |
| 1708 | |
| 1709 | /* |
| 1710 | * CS4210 Input MUX (1 ADC) |
| 1711 | */ |
| 1712 | static int cs421x_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 1713 | struct snd_ctl_elem_info *uinfo) |
| 1714 | { |
| 1715 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1716 | struct cs_spec *spec = codec->spec; |
| 1717 | |
| 1718 | return snd_hda_input_mux_info(&spec->input_mux, uinfo); |
| 1719 | } |
| 1720 | |
| 1721 | static int cs421x_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 1722 | struct snd_ctl_elem_value *ucontrol) |
| 1723 | { |
| 1724 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1725 | struct cs_spec *spec = codec->spec; |
| 1726 | |
| 1727 | ucontrol->value.enumerated.item[0] = spec->cur_input; |
| 1728 | return 0; |
| 1729 | } |
| 1730 | |
| 1731 | static int cs421x_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 1732 | struct snd_ctl_elem_value *ucontrol) |
| 1733 | { |
| 1734 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1735 | struct cs_spec *spec = codec->spec; |
| 1736 | |
| 1737 | return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol, |
| 1738 | spec->adc_nid[0], &spec->cur_input); |
| 1739 | |
| 1740 | } |
| 1741 | |
Daniel J Blueman | 00e17f7 | 2012-11-04 13:19:04 +0800 | [diff] [blame] | 1742 | static const struct snd_kcontrol_new cs421x_capture_source = { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1743 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1744 | .name = "Capture Source", |
| 1745 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 1746 | .info = cs421x_mux_enum_info, |
| 1747 | .get = cs421x_mux_enum_get, |
| 1748 | .put = cs421x_mux_enum_put, |
| 1749 | }; |
| 1750 | |
| 1751 | static int cs421x_add_input_volume_control(struct hda_codec *codec, int item) |
| 1752 | { |
| 1753 | struct cs_spec *spec = codec->spec; |
| 1754 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1755 | const struct hda_input_mux *imux = &spec->input_mux; |
| 1756 | hda_nid_t pin = cfg->inputs[item].pin; |
| 1757 | struct snd_kcontrol *kctl; |
| 1758 | u32 caps; |
| 1759 | |
| 1760 | if (!(get_wcaps(codec, pin) & AC_WCAP_IN_AMP)) |
| 1761 | return 0; |
| 1762 | |
| 1763 | caps = query_amp_caps(codec, pin, HDA_INPUT); |
| 1764 | caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; |
| 1765 | if (caps <= 1) |
| 1766 | return 0; |
| 1767 | |
| 1768 | return add_volume(codec, imux->items[item].label, 0, |
| 1769 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT), 1, &kctl); |
| 1770 | } |
| 1771 | |
| 1772 | /* add a (input-boost) volume control to the given input pin */ |
| 1773 | static int build_cs421x_input(struct hda_codec *codec) |
| 1774 | { |
| 1775 | struct cs_spec *spec = codec->spec; |
| 1776 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1777 | struct hda_input_mux *imux = &spec->input_mux; |
| 1778 | int i, err, type_idx; |
| 1779 | const char *label; |
| 1780 | |
| 1781 | if (!spec->num_inputs) |
| 1782 | return 0; |
| 1783 | |
| 1784 | /* make bind-capture */ |
| 1785 | spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw); |
| 1786 | spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol); |
| 1787 | for (i = 0; i < 2; i++) { |
| 1788 | struct snd_kcontrol *kctl; |
| 1789 | int n; |
| 1790 | if (!spec->capture_bind[i]) |
| 1791 | return -ENOMEM; |
| 1792 | kctl = snd_ctl_new1(&cs_capture_ctls[i], codec); |
| 1793 | if (!kctl) |
| 1794 | return -ENOMEM; |
| 1795 | kctl->private_value = (long)spec->capture_bind[i]; |
| 1796 | err = snd_hda_ctl_add(codec, 0, kctl); |
| 1797 | if (err < 0) |
| 1798 | return err; |
| 1799 | for (n = 0; n < AUTO_PIN_LAST; n++) { |
| 1800 | if (!spec->adc_nid[n]) |
| 1801 | continue; |
| 1802 | err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]); |
| 1803 | if (err < 0) |
| 1804 | return err; |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | /* Add Input MUX Items + Capture Volume/Switch */ |
| 1809 | for (i = 0; i < spec->num_inputs; i++) { |
| 1810 | label = hda_get_autocfg_input_label(codec, cfg, i); |
| 1811 | snd_hda_add_imux_item(imux, label, spec->adc_idx[i], &type_idx); |
| 1812 | |
| 1813 | err = cs421x_add_input_volume_control(codec, i); |
| 1814 | if (err < 0) |
| 1815 | return err; |
| 1816 | } |
| 1817 | |
| 1818 | /* |
| 1819 | Add 'Capture Source' Switch if |
| 1820 | * 2 inputs and no mic detec |
| 1821 | * 3 inputs |
| 1822 | */ |
| 1823 | if ((spec->num_inputs == 2 && !spec->mic_detect) || |
| 1824 | (spec->num_inputs == 3)) { |
| 1825 | |
| 1826 | err = snd_hda_ctl_add(codec, spec->adc_nid[0], |
| 1827 | snd_ctl_new1(&cs421x_capture_source, codec)); |
| 1828 | if (err < 0) |
| 1829 | return err; |
| 1830 | } |
| 1831 | |
| 1832 | return 0; |
| 1833 | } |
| 1834 | |
| 1835 | /* Single DAC (Mute/Gain) */ |
| 1836 | static int build_cs421x_output(struct hda_codec *codec) |
| 1837 | { |
| 1838 | hda_nid_t dac = CS4210_DAC_NID; |
| 1839 | struct cs_spec *spec = codec->spec; |
| 1840 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1841 | struct snd_kcontrol *kctl; |
| 1842 | int err; |
David Henningsson | 40d03e6 | 2012-01-02 12:40:15 +0100 | [diff] [blame] | 1843 | char *name = "Master"; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1844 | |
| 1845 | fix_volume_caps(codec, dac); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1846 | |
| 1847 | err = add_mute(codec, name, 0, |
| 1848 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); |
| 1849 | if (err < 0) |
| 1850 | return err; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1851 | |
| 1852 | err = add_volume(codec, name, 0, |
| 1853 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); |
| 1854 | if (err < 0) |
| 1855 | return err; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1856 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1857 | if (cfg->speaker_outs && (spec->vendor_nid == CS4210_VENDOR_NID)) { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1858 | err = snd_hda_ctl_add(codec, 0, |
| 1859 | snd_ctl_new1(&cs421x_speaker_bost_ctl, codec)); |
| 1860 | if (err < 0) |
| 1861 | return err; |
| 1862 | } |
| 1863 | return err; |
| 1864 | } |
| 1865 | |
| 1866 | static int cs421x_build_controls(struct hda_codec *codec) |
| 1867 | { |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 1868 | struct cs_spec *spec = codec->spec; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1869 | int err; |
| 1870 | |
| 1871 | err = build_cs421x_output(codec); |
| 1872 | if (err < 0) |
| 1873 | return err; |
| 1874 | err = build_cs421x_input(codec); |
| 1875 | if (err < 0) |
| 1876 | return err; |
| 1877 | err = build_digital_output(codec); |
| 1878 | if (err < 0) |
| 1879 | return err; |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 1880 | err = cs421x_init(codec); |
| 1881 | if (err < 0) |
| 1882 | return err; |
| 1883 | |
| 1884 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); |
| 1885 | if (err < 0) |
| 1886 | return err; |
| 1887 | |
| 1888 | return 0; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1889 | } |
| 1890 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1891 | static int parse_cs421x_input(struct hda_codec *codec) |
| 1892 | { |
| 1893 | struct cs_spec *spec = codec->spec; |
| 1894 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1895 | int i; |
| 1896 | |
| 1897 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1898 | hda_nid_t pin = cfg->inputs[i].pin; |
| 1899 | spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]); |
| 1900 | spec->cur_input = spec->last_input = i; |
| 1901 | spec->num_inputs++; |
| 1902 | |
| 1903 | /* check whether the automatic mic switch is available */ |
| 1904 | if (is_ext_mic(codec, i) && cfg->num_inputs >= 2) { |
| 1905 | spec->mic_detect = 1; |
| 1906 | spec->automic_idx = i; |
| 1907 | } |
| 1908 | } |
| 1909 | return 0; |
| 1910 | } |
| 1911 | |
| 1912 | static int cs421x_parse_auto_config(struct hda_codec *codec) |
| 1913 | { |
| 1914 | struct cs_spec *spec = codec->spec; |
| 1915 | int err; |
| 1916 | |
| 1917 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 1918 | if (err < 0) |
| 1919 | return err; |
| 1920 | err = parse_output(codec); |
| 1921 | if (err < 0) |
| 1922 | return err; |
| 1923 | err = parse_cs421x_input(codec); |
| 1924 | if (err < 0) |
| 1925 | return err; |
| 1926 | err = parse_digital_output(codec); |
| 1927 | if (err < 0) |
| 1928 | return err; |
| 1929 | return 0; |
| 1930 | } |
| 1931 | |
| 1932 | #ifdef CONFIG_PM |
| 1933 | /* |
| 1934 | Manage PDREF, when transitioning to D3hot |
| 1935 | (DAC,ADC) -> D3, PDREF=1, AFG->D3 |
| 1936 | */ |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 1937 | static int cs421x_suspend(struct hda_codec *codec) |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1938 | { |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1939 | struct cs_spec *spec = codec->spec; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1940 | unsigned int coef; |
| 1941 | |
| 1942 | snd_hda_shutup_pins(codec); |
| 1943 | |
| 1944 | snd_hda_codec_write(codec, CS4210_DAC_NID, 0, |
| 1945 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 1946 | snd_hda_codec_write(codec, CS4210_ADC_NID, 0, |
| 1947 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 1948 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1949 | if (spec->vendor_nid == CS4210_VENDOR_NID) { |
| 1950 | coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG); |
| 1951 | coef |= 0x0004; /* PDREF */ |
| 1952 | cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef); |
| 1953 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1954 | |
| 1955 | return 0; |
| 1956 | } |
| 1957 | #endif |
| 1958 | |
Daniel J Blueman | 00e17f7 | 2012-11-04 13:19:04 +0800 | [diff] [blame] | 1959 | static const struct hda_codec_ops cs421x_patch_ops = { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1960 | .build_controls = cs421x_build_controls, |
| 1961 | .build_pcms = cs_build_pcms, |
| 1962 | .init = cs421x_init, |
| 1963 | .free = cs_free, |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 1964 | .unsol_event = snd_hda_jack_unsol_event, |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1965 | #ifdef CONFIG_PM |
| 1966 | .suspend = cs421x_suspend, |
| 1967 | #endif |
| 1968 | }; |
| 1969 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1970 | static int patch_cs4210(struct hda_codec *codec) |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1971 | { |
| 1972 | struct cs_spec *spec; |
| 1973 | int err; |
| 1974 | |
| 1975 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1976 | if (!spec) |
| 1977 | return -ENOMEM; |
| 1978 | codec->spec = spec; |
Takashi Iwai | b2cbf3b | 2012-10-10 08:53:06 +0200 | [diff] [blame] | 1979 | snd_hda_gen_init(&spec->gen); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1980 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1981 | spec->vendor_nid = CS4210_VENDOR_NID; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1982 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 1983 | snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl, |
| 1984 | cs421x_fixups); |
| 1985 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1986 | |
| 1987 | /* |
| 1988 | Update the GPIO/DMIC/SENSE_B pinmux before the configuration |
| 1989 | is auto-parsed. If GPIO or SENSE_B is forced, DMIC input |
| 1990 | is disabled. |
| 1991 | */ |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1992 | cs4210_pinmux_init(codec); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1993 | |
| 1994 | err = cs421x_parse_auto_config(codec); |
| 1995 | if (err < 0) |
| 1996 | goto error; |
| 1997 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1998 | codec->patch_ops = cs421x_patch_ops; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1999 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 2000 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
| 2001 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 2002 | return 0; |
| 2003 | |
| 2004 | error: |
Takashi Iwai | c5e0b6d | 2012-10-10 08:50:35 +0200 | [diff] [blame] | 2005 | cs_free(codec); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 2006 | codec->spec = NULL; |
| 2007 | return err; |
| 2008 | } |
| 2009 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 2010 | static int patch_cs4213(struct hda_codec *codec) |
| 2011 | { |
| 2012 | struct cs_spec *spec; |
| 2013 | int err; |
| 2014 | |
| 2015 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 2016 | if (!spec) |
| 2017 | return -ENOMEM; |
| 2018 | codec->spec = spec; |
Takashi Iwai | b2cbf3b | 2012-10-10 08:53:06 +0200 | [diff] [blame] | 2019 | snd_hda_gen_init(&spec->gen); |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 2020 | |
| 2021 | spec->vendor_nid = CS4213_VENDOR_NID; |
| 2022 | |
| 2023 | err = cs421x_parse_auto_config(codec); |
| 2024 | if (err < 0) |
| 2025 | goto error; |
| 2026 | |
| 2027 | codec->patch_ops = cs421x_patch_ops; |
| 2028 | return 0; |
| 2029 | |
| 2030 | error: |
Takashi Iwai | c5e0b6d | 2012-10-10 08:50:35 +0200 | [diff] [blame] | 2031 | cs_free(codec); |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 2032 | codec->spec = NULL; |
| 2033 | return err; |
| 2034 | } |
| 2035 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 2036 | |
| 2037 | /* |
| 2038 | * patch entries |
| 2039 | */ |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 2040 | static const struct hda_codec_preset snd_hda_preset_cirrus[] = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 2041 | { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x }, |
| 2042 | { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x }, |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 2043 | { .id = 0x10134210, .name = "CS4210", .patch = patch_cs4210 }, |
| 2044 | { .id = 0x10134213, .name = "CS4213", .patch = patch_cs4213 }, |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 2045 | {} /* terminator */ |
| 2046 | }; |
| 2047 | |
| 2048 | MODULE_ALIAS("snd-hda-codec-id:10134206"); |
| 2049 | MODULE_ALIAS("snd-hda-codec-id:10134207"); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 2050 | MODULE_ALIAS("snd-hda-codec-id:10134210"); |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 2051 | MODULE_ALIAS("snd-hda-codec-id:10134213"); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 2052 | |
| 2053 | MODULE_LICENSE("GPL"); |
| 2054 | MODULE_DESCRIPTION("Cirrus Logic HD-audio codec"); |
| 2055 | |
| 2056 | static struct hda_codec_preset_list cirrus_list = { |
| 2057 | .preset = snd_hda_preset_cirrus, |
| 2058 | .owner = THIS_MODULE, |
| 2059 | }; |
| 2060 | |
| 2061 | static int __init patch_cirrus_init(void) |
| 2062 | { |
| 2063 | return snd_hda_add_codec_preset(&cirrus_list); |
| 2064 | } |
| 2065 | |
| 2066 | static void __exit patch_cirrus_exit(void) |
| 2067 | { |
| 2068 | snd_hda_delete_codec_preset(&cirrus_list); |
| 2069 | } |
| 2070 | |
| 2071 | module_init(patch_cirrus_init) |
| 2072 | module_exit(patch_cirrus_exit) |