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