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