blob: ea660429713dbdf7754e793e17c5d76c62487d17 [file] [log] [blame]
Takashi Iwaie5f14242009-07-01 18:11:44 +02001/*
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 Gortmakerda155d52011-07-15 12:38:28 -040025#include <linux/module.h>
Takashi Iwaie5f14242009-07-01 18:11:44 +020026#include <sound/core.h>
27#include "hda_codec.h"
28#include "hda_local.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020029#include "hda_jack.h"
Tim Howe56487c22011-07-22 16:41:00 -050030#include <sound/tlv.h>
Takashi Iwaie5f14242009-07-01 18:11:44 +020031
32/*
33 */
34
35struct cs_spec {
Takashi Iwaia6bae202009-07-06 15:15:22 +020036 int board_config;
Takashi Iwaie5f14242009-07-01 18:11:44 +020037 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 Iwaic42d4782011-05-02 11:36:09 +020057 const struct hda_bind_ctls *capture_bind[2];
Takashi Iwaie5f14242009-07-01 18:11:44 +020058
Takashi Iwaied208252009-07-07 09:04:26 +020059 unsigned int gpio_mask;
60 unsigned int gpio_dir;
61 unsigned int gpio_data;
Takashi Iwai6dfeb7032011-11-22 20:00:31 +010062 unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */
63 unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */
Takashi Iwaied208252009-07-07 09:04:26 +020064
Takashi Iwaie5f14242009-07-01 18:11:44 +020065 struct hda_pcm pcm_rec[2]; /* PCM information */
66
67 unsigned int hp_detect:1;
68 unsigned int mic_detect:1;
Tim Howe56487c22011-07-22 16:41:00 -050069 /* 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 Iwaie5f14242009-07-01 18:11:44 +020075};
76
Tim Howe56487c22011-07-22 16:41:00 -050077/* available models with CS420x */
Takashi Iwaia6bae202009-07-06 15:15:22 +020078enum {
Vince Weaver4e7d7c62010-09-22 17:31:37 -040079 CS420X_MBP53,
Takashi Iwaia6bae202009-07-06 15:15:22 +020080 CS420X_MBP55,
Rafael Avila de Espindola1a5ba2e2009-12-22 07:59:37 +010081 CS420X_IMAC27,
Takashi Iwai6dfeb7032011-11-22 20:00:31 +010082 CS420X_APPLE,
Takashi Iwaia6bae202009-07-06 15:15:22 +020083 CS420X_AUTO,
84 CS420X_MODELS
85};
86
Tim Howe56487c22011-07-22 16:41:00 -050087/* CS421x boards */
88enum {
89 CS421X_CDB4210,
90 CS421X_MODELS
91};
92
Takashi Iwai40c20fa2009-07-06 13:00:57 +020093/* Vendor-specific processing widget */
94#define CS420X_VENDOR_NID 0x11
95#define CS_DIG_OUT1_PIN_NID 0x10
96#define CS_DIG_OUT2_PIN_NID 0x15
97#define CS_DMIC1_PIN_NID 0x12
98#define CS_DMIC2_PIN_NID 0x0e
99
100/* coef indices */
101#define IDX_SPDIF_STAT 0x0000
102#define IDX_SPDIF_CTL 0x0001
103#define IDX_ADC_CFG 0x0002
104/* SZC bitmask, 4 modes below:
105 * 0 = immediate,
106 * 1 = digital immediate, analog zero-cross
107 * 2 = digtail & analog soft-ramp
108 * 3 = digital soft-ramp, analog zero-cross
109 */
110#define CS_COEF_ADC_SZC_MASK (3 << 0)
111#define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
112#define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
113/* PGA mode: 0 = differential, 1 = signle-ended */
114#define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
115#define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
116#define IDX_DAC_CFG 0x0003
117/* SZC bitmask, 4 modes below:
118 * 0 = Immediate
119 * 1 = zero-cross
120 * 2 = soft-ramp
121 * 3 = soft-ramp on zero-cross
122 */
123#define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
124#define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
125#define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
126
127#define IDX_BEEP_CFG 0x0004
128/* 0x0008 - test reg key */
129/* 0x0009 - 0x0014 -> 12 test regs */
130/* 0x0015 - visibility reg */
131
Tim Howe56487c22011-07-22 16:41:00 -0500132/*
133 * Cirrus Logic CS4210
134 *
135 * 1 DAC => HP(sense) / Speakers,
136 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
137 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
138*/
139#define CS4210_DAC_NID 0x02
140#define CS4210_ADC_NID 0x03
141#define CS421X_VENDOR_NID 0x0B
142#define CS421X_DMIC_PIN_NID 0x09 /* Port E */
143#define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
144
145#define CS421X_IDX_DEV_CFG 0x01
146#define CS421X_IDX_ADC_CFG 0x02
147#define CS421X_IDX_DAC_CFG 0x03
148#define CS421X_IDX_SPK_CTL 0x04
149
150#define SPDIF_EVENT 0x04
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200151
Takashi Iwai277a57c2009-07-08 12:42:08 +0200152static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200153{
Tim Howe56487c22011-07-22 16:41:00 -0500154 struct cs_spec *spec = codec->spec;
155 snd_hda_codec_write(codec, spec->vendor_nid, 0,
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200156 AC_VERB_SET_COEF_INDEX, idx);
Tim Howe56487c22011-07-22 16:41:00 -0500157 return snd_hda_codec_read(codec, spec->vendor_nid, 0,
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200158 AC_VERB_GET_PROC_COEF, 0);
159}
160
Takashi Iwai277a57c2009-07-08 12:42:08 +0200161static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
162 unsigned int coef)
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200163{
Tim Howe56487c22011-07-22 16:41:00 -0500164 struct cs_spec *spec = codec->spec;
165 snd_hda_codec_write(codec, spec->vendor_nid, 0,
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200166 AC_VERB_SET_COEF_INDEX, idx);
Tim Howe56487c22011-07-22 16:41:00 -0500167 snd_hda_codec_write(codec, spec->vendor_nid, 0,
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200168 AC_VERB_SET_PROC_COEF, coef);
169}
170
171
Takashi Iwaie5f14242009-07-01 18:11:44 +0200172#define HP_EVENT 1
173#define MIC_EVENT 2
174
175/*
176 * PCM callbacks
177 */
178static int cs_playback_pcm_open(struct hda_pcm_stream *hinfo,
179 struct hda_codec *codec,
180 struct snd_pcm_substream *substream)
181{
182 struct cs_spec *spec = codec->spec;
183 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
184 hinfo);
185}
186
187static int cs_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
189 unsigned int stream_tag,
190 unsigned int format,
191 struct snd_pcm_substream *substream)
192{
193 struct cs_spec *spec = codec->spec;
194 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
195 stream_tag, format, substream);
196}
197
198static int cs_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
199 struct hda_codec *codec,
200 struct snd_pcm_substream *substream)
201{
202 struct cs_spec *spec = codec->spec;
203 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
204}
205
206/*
207 * Digital out
208 */
209static int cs_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
210 struct hda_codec *codec,
211 struct snd_pcm_substream *substream)
212{
213 struct cs_spec *spec = codec->spec;
214 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
215}
216
217static int cs_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
218 struct hda_codec *codec,
219 struct snd_pcm_substream *substream)
220{
221 struct cs_spec *spec = codec->spec;
222 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
223}
224
225static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
226 struct hda_codec *codec,
227 unsigned int stream_tag,
228 unsigned int format,
229 struct snd_pcm_substream *substream)
230{
231 struct cs_spec *spec = codec->spec;
232 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
233 format, substream);
234}
235
236static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
237 struct hda_codec *codec,
238 struct snd_pcm_substream *substream)
239{
240 struct cs_spec *spec = codec->spec;
241 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
242}
243
Takashi Iwai05ee7962011-11-16 18:05:11 +0100244static void cs_update_input_select(struct hda_codec *codec)
245{
246 struct cs_spec *spec = codec->spec;
247 if (spec->cur_adc)
248 snd_hda_codec_write(codec, spec->cur_adc, 0,
249 AC_VERB_SET_CONNECT_SEL,
250 spec->adc_idx[spec->cur_input]);
251}
252
Takashi Iwaie5f14242009-07-01 18:11:44 +0200253/*
254 * Analog capture
255 */
256static int cs_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
257 struct hda_codec *codec,
258 unsigned int stream_tag,
259 unsigned int format,
260 struct snd_pcm_substream *substream)
261{
262 struct cs_spec *spec = codec->spec;
263 spec->cur_adc = spec->adc_nid[spec->cur_input];
264 spec->cur_adc_stream_tag = stream_tag;
265 spec->cur_adc_format = format;
Takashi Iwai05ee7962011-11-16 18:05:11 +0100266 cs_update_input_select(codec);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200267 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
268 return 0;
269}
270
271static int cs_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
272 struct hda_codec *codec,
273 struct snd_pcm_substream *substream)
274{
275 struct cs_spec *spec = codec->spec;
276 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
277 spec->cur_adc = 0;
278 return 0;
279}
280
281/*
282 */
Takashi Iwaic42d4782011-05-02 11:36:09 +0200283static const struct hda_pcm_stream cs_pcm_analog_playback = {
Takashi Iwaie5f14242009-07-01 18:11:44 +0200284 .substreams = 1,
285 .channels_min = 2,
286 .channels_max = 2,
287 .ops = {
288 .open = cs_playback_pcm_open,
289 .prepare = cs_playback_pcm_prepare,
290 .cleanup = cs_playback_pcm_cleanup
291 },
292};
293
Takashi Iwaic42d4782011-05-02 11:36:09 +0200294static const struct hda_pcm_stream cs_pcm_analog_capture = {
Takashi Iwaie5f14242009-07-01 18:11:44 +0200295 .substreams = 1,
296 .channels_min = 2,
297 .channels_max = 2,
298 .ops = {
299 .prepare = cs_capture_pcm_prepare,
300 .cleanup = cs_capture_pcm_cleanup
301 },
302};
303
Takashi Iwaic42d4782011-05-02 11:36:09 +0200304static const struct hda_pcm_stream cs_pcm_digital_playback = {
Takashi Iwaie5f14242009-07-01 18:11:44 +0200305 .substreams = 1,
306 .channels_min = 2,
307 .channels_max = 2,
308 .ops = {
309 .open = cs_dig_playback_pcm_open,
310 .close = cs_dig_playback_pcm_close,
311 .prepare = cs_dig_playback_pcm_prepare,
312 .cleanup = cs_dig_playback_pcm_cleanup
313 },
314};
315
Takashi Iwaic42d4782011-05-02 11:36:09 +0200316static const struct hda_pcm_stream cs_pcm_digital_capture = {
Takashi Iwaie5f14242009-07-01 18:11:44 +0200317 .substreams = 1,
318 .channels_min = 2,
319 .channels_max = 2,
320};
321
322static int cs_build_pcms(struct hda_codec *codec)
323{
324 struct cs_spec *spec = codec->spec;
325 struct hda_pcm *info = spec->pcm_rec;
326
327 codec->pcm_info = info;
328 codec->num_pcms = 0;
329
330 info->name = "Cirrus Analog";
331 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cs_pcm_analog_playback;
332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0];
333 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
334 spec->multiout.max_channels;
335 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200336 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
337 spec->adc_nid[spec->cur_input];
338 codec->num_pcms++;
339
340 if (!spec->multiout.dig_out_nid && !spec->dig_in)
341 return 0;
342
343 info++;
344 info->name = "Cirrus Digital";
345 info->pcm_type = spec->autocfg.dig_out_type[0];
346 if (!info->pcm_type)
347 info->pcm_type = HDA_PCM_TYPE_SPDIF;
348 if (spec->multiout.dig_out_nid) {
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
350 cs_pcm_digital_playback;
351 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
352 spec->multiout.dig_out_nid;
353 }
354 if (spec->dig_in) {
355 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
356 cs_pcm_digital_capture;
357 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
358 }
359 codec->num_pcms++;
360
361 return 0;
362}
363
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200364/*
365 * parse codec topology
366 */
367
Takashi Iwaie5f14242009-07-01 18:11:44 +0200368static hda_nid_t get_dac(struct hda_codec *codec, hda_nid_t pin)
369{
370 hda_nid_t dac;
371 if (!pin)
372 return 0;
373 if (snd_hda_get_connections(codec, pin, &dac, 1) != 1)
374 return 0;
375 return dac;
376}
377
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200378static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
379{
380 struct cs_spec *spec = codec->spec;
381 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic1e0bb92010-08-30 13:05:30 +0200382 hda_nid_t pin = cfg->inputs[idx].pin;
Takashi Iwai06dec222011-05-17 10:00:16 +0200383 unsigned int val;
384 if (!is_jack_detectable(codec, pin))
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200385 return 0;
386 val = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwai99ae28b2010-09-17 14:42:34 +0200387 return (snd_hda_get_input_pin_attr(val) != INPUT_PIN_ATTR_INT);
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200388}
389
390static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
391 unsigned int *idxp)
392{
Takashi Iwai1b004d02011-08-20 09:19:59 +0200393 int i, idx;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200394 hda_nid_t nid;
395
396 nid = codec->start_nid;
397 for (i = 0; i < codec->num_nodes; i++, nid++) {
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200398 unsigned int type;
Takashi Iwai1682c812011-05-17 10:02:27 +0200399 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200400 if (type != AC_WID_AUD_IN)
401 continue;
Takashi Iwai1b004d02011-08-20 09:19:59 +0200402 idx = snd_hda_get_conn_index(codec, nid, pin, false);
403 if (idx >= 0) {
404 *idxp = idx;
Takashi Iwai8d087c72011-06-28 12:45:47 +0200405 return nid;
Takashi Iwai1b004d02011-08-20 09:19:59 +0200406 }
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200407 }
408 return 0;
409}
410
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200411static int is_active_pin(struct hda_codec *codec, hda_nid_t nid)
412{
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200413 unsigned int val;
414 val = snd_hda_codec_get_pincfg(codec, nid);
415 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
416}
417
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200418static int parse_output(struct hda_codec *codec)
419{
420 struct cs_spec *spec = codec->spec;
421 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai277a57c2009-07-08 12:42:08 +0200422 int i, extra_nids;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200423 hda_nid_t dac;
424
425 for (i = 0; i < cfg->line_outs; i++) {
426 dac = get_dac(codec, cfg->line_out_pins[i]);
427 if (!dac)
428 break;
429 spec->dac_nid[i] = dac;
430 }
431 spec->multiout.num_dacs = i;
432 spec->multiout.dac_nids = spec->dac_nid;
433 spec->multiout.max_channels = i * 2;
434
435 /* add HP and speakers */
436 extra_nids = 0;
437 for (i = 0; i < cfg->hp_outs; i++) {
438 dac = get_dac(codec, cfg->hp_pins[i]);
439 if (!dac)
440 break;
441 if (!i)
442 spec->multiout.hp_nid = dac;
443 else
444 spec->multiout.extra_out_nid[extra_nids++] = dac;
445 }
446 for (i = 0; i < cfg->speaker_outs; i++) {
447 dac = get_dac(codec, cfg->speaker_pins[i]);
448 if (!dac)
449 break;
450 spec->multiout.extra_out_nid[extra_nids++] = dac;
451 }
452
453 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
454 cfg->speaker_outs = cfg->line_outs;
455 memcpy(cfg->speaker_pins, cfg->line_out_pins,
456 sizeof(cfg->speaker_pins));
457 cfg->line_outs = 0;
458 }
459
460 return 0;
461}
462
463static int parse_input(struct hda_codec *codec)
464{
465 struct cs_spec *spec = codec->spec;
466 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai277a57c2009-07-08 12:42:08 +0200467 int i;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200468
Takashi Iwaic1e0bb92010-08-30 13:05:30 +0200469 for (i = 0; i < cfg->num_inputs; i++) {
470 hda_nid_t pin = cfg->inputs[i].pin;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200471 spec->input_idx[spec->num_inputs] = i;
472 spec->capsrc_idx[i] = spec->num_inputs++;
473 spec->cur_input = i;
474 spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]);
475 }
476 if (!spec->num_inputs)
477 return 0;
478
479 /* check whether the automatic mic switch is available */
480 if (spec->num_inputs == 2 &&
Takashi Iwai86e29592010-09-09 14:50:17 +0200481 cfg->inputs[0].type == AUTO_PIN_MIC &&
482 cfg->inputs[1].type == AUTO_PIN_MIC) {
Takashi Iwaic1e0bb92010-08-30 13:05:30 +0200483 if (is_ext_mic(codec, cfg->inputs[0].pin)) {
484 if (!is_ext_mic(codec, cfg->inputs[1].pin)) {
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200485 spec->mic_detect = 1;
Takashi Iwaic1e0bb92010-08-30 13:05:30 +0200486 spec->automic_idx = 0;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200487 }
488 } else {
Takashi Iwaic1e0bb92010-08-30 13:05:30 +0200489 if (is_ext_mic(codec, cfg->inputs[1].pin)) {
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200490 spec->mic_detect = 1;
Takashi Iwaic1e0bb92010-08-30 13:05:30 +0200491 spec->automic_idx = 1;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200492 }
493 }
494 }
495 return 0;
496}
497
498
499static int parse_digital_output(struct hda_codec *codec)
500{
501 struct cs_spec *spec = codec->spec;
502 struct auto_pin_cfg *cfg = &spec->autocfg;
503 hda_nid_t nid;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200504
505 if (!cfg->dig_outs)
506 return 0;
507 if (snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) < 1)
508 return 0;
509 spec->multiout.dig_out_nid = nid;
510 spec->multiout.share_spdif = 1;
511 if (cfg->dig_outs > 1 &&
512 snd_hda_get_connections(codec, cfg->dig_out_pins[1], &nid, 1) > 0) {
513 spec->slave_dig_outs[0] = nid;
514 codec->slave_dig_outs = spec->slave_dig_outs;
515 }
516 return 0;
517}
518
519static int parse_digital_input(struct hda_codec *codec)
520{
521 struct cs_spec *spec = codec->spec;
522 struct auto_pin_cfg *cfg = &spec->autocfg;
523 int idx;
524
Takashi Iwai60e53882009-07-06 15:01:09 +0200525 if (cfg->dig_in_pin)
526 spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx);
527 return 0;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200528}
529
530/*
531 * create mixer controls
532 */
533
Takashi Iwaiea734962011-01-17 11:29:34 +0100534static const char * const dir_sfx[2] = { "Playback", "Capture" };
Takashi Iwaie5f14242009-07-01 18:11:44 +0200535
536static int add_mute(struct hda_codec *codec, const char *name, int index,
537 unsigned int pval, int dir, struct snd_kcontrol **kctlp)
538{
Takashi Iwaib4dabfc2009-07-07 09:05:07 +0200539 char tmp[44];
Takashi Iwaie5f14242009-07-01 18:11:44 +0200540 struct snd_kcontrol_new knew =
541 HDA_CODEC_MUTE_IDX(tmp, index, 0, 0, HDA_OUTPUT);
542 knew.private_value = pval;
543 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]);
544 *kctlp = snd_ctl_new1(&knew, codec);
Jaroslav Kysela9e3fd872009-12-08 17:45:25 +0100545 (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100546 return snd_hda_ctl_add(codec, 0, *kctlp);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200547}
548
549static int add_volume(struct hda_codec *codec, const char *name,
550 int index, unsigned int pval, int dir,
551 struct snd_kcontrol **kctlp)
552{
David Henningsson2e1210b2011-09-14 13:22:54 +0200553 char tmp[44];
Takashi Iwaie5f14242009-07-01 18:11:44 +0200554 struct snd_kcontrol_new knew =
555 HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT);
556 knew.private_value = pval;
557 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
558 *kctlp = snd_ctl_new1(&knew, codec);
Jaroslav Kysela9e3fd872009-12-08 17:45:25 +0100559 (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100560 return snd_hda_ctl_add(codec, 0, *kctlp);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200561}
562
563static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
564{
565 unsigned int caps;
566
567 /* set the upper-limit for mixer amp to 0dB */
568 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
569 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
570 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
571 << AC_AMPCAP_NUM_STEPS_SHIFT;
572 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
573}
574
575static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
576{
577 struct cs_spec *spec = codec->spec;
578 unsigned int tlv[4];
579 int err;
580
581 spec->vmaster_sw =
582 snd_ctl_make_virtual_master("Master Playback Switch", NULL);
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100583 err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200584 if (err < 0)
585 return err;
586
587 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
588 spec->vmaster_vol =
589 snd_ctl_make_virtual_master("Master Playback Volume", tlv);
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100590 err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200591 if (err < 0)
592 return err;
593 return 0;
594}
595
596static int add_output(struct hda_codec *codec, hda_nid_t dac, int idx,
597 int num_ctls, int type)
598{
599 struct cs_spec *spec = codec->spec;
600 const char *name;
601 int err, index;
602 struct snd_kcontrol *kctl;
Takashi Iwaic42d4782011-05-02 11:36:09 +0200603 static const char * const speakers[] = {
Takashi Iwaie5f14242009-07-01 18:11:44 +0200604 "Front Speaker", "Surround Speaker", "Bass Speaker"
605 };
Takashi Iwaic42d4782011-05-02 11:36:09 +0200606 static const char * const line_outs[] = {
Takashi Iwaie5f14242009-07-01 18:11:44 +0200607 "Front Line-Out", "Surround Line-Out", "Bass Line-Out"
608 };
609
610 fix_volume_caps(codec, dac);
611 if (!spec->vmaster_sw) {
612 err = add_vmaster(codec, dac);
613 if (err < 0)
614 return err;
615 }
616
617 index = 0;
618 switch (type) {
619 case AUTO_PIN_HP_OUT:
620 name = "Headphone";
621 index = idx;
622 break;
623 case AUTO_PIN_SPEAKER_OUT:
624 if (num_ctls > 1)
625 name = speakers[idx];
626 else
627 name = "Speaker";
628 break;
629 default:
630 if (num_ctls > 1)
631 name = line_outs[idx];
632 else
633 name = "Line-Out";
634 break;
635 }
636
637 err = add_mute(codec, name, index,
638 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
639 if (err < 0)
640 return err;
641 err = snd_ctl_add_slave(spec->vmaster_sw, kctl);
642 if (err < 0)
643 return err;
644
645 err = add_volume(codec, name, index,
646 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
647 if (err < 0)
648 return err;
649 err = snd_ctl_add_slave(spec->vmaster_vol, kctl);
650 if (err < 0)
651 return err;
652
653 return 0;
654}
655
656static int build_output(struct hda_codec *codec)
657{
658 struct cs_spec *spec = codec->spec;
659 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200660 int i, err;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200661
662 for (i = 0; i < cfg->line_outs; i++) {
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200663 err = add_output(codec, get_dac(codec, cfg->line_out_pins[i]),
664 i, cfg->line_outs, cfg->line_out_type);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200665 if (err < 0)
666 return err;
667 }
Takashi Iwaie5f14242009-07-01 18:11:44 +0200668 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200669 err = add_output(codec, get_dac(codec, cfg->hp_pins[i]),
670 i, cfg->hp_outs, AUTO_PIN_HP_OUT);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200671 if (err < 0)
672 return err;
673 }
674 for (i = 0; i < cfg->speaker_outs; i++) {
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200675 err = add_output(codec, get_dac(codec, cfg->speaker_pins[i]),
676 i, cfg->speaker_outs, AUTO_PIN_SPEAKER_OUT);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200677 if (err < 0)
678 return err;
679 }
Takashi Iwaie5f14242009-07-01 18:11:44 +0200680 return 0;
681}
682
683/*
684 */
685
Takashi Iwaic42d4782011-05-02 11:36:09 +0200686static const struct snd_kcontrol_new cs_capture_ctls[] = {
Takashi Iwaie5f14242009-07-01 18:11:44 +0200687 HDA_BIND_SW("Capture Switch", 0),
688 HDA_BIND_VOL("Capture Volume", 0),
689};
690
Takashi Iwaiea359292009-07-06 12:58:59 +0200691static int change_cur_input(struct hda_codec *codec, unsigned int idx,
692 int force)
Takashi Iwaie5f14242009-07-01 18:11:44 +0200693{
694 struct cs_spec *spec = codec->spec;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200695
Takashi Iwaiea359292009-07-06 12:58:59 +0200696 if (spec->cur_input == idx && !force)
Takashi Iwaie5f14242009-07-01 18:11:44 +0200697 return 0;
698 if (spec->cur_adc && spec->cur_adc != spec->adc_nid[idx]) {
699 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +0200700 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200701 spec->cur_adc = spec->adc_nid[idx];
702 snd_hda_codec_setup_stream(codec, spec->cur_adc,
703 spec->cur_adc_stream_tag, 0,
704 spec->cur_adc_format);
705 }
Takashi Iwaie5f14242009-07-01 18:11:44 +0200706 spec->cur_input = idx;
Takashi Iwai05ee7962011-11-16 18:05:11 +0100707 cs_update_input_select(codec);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200708 return 1;
709}
710
711static int cs_capture_source_info(struct snd_kcontrol *kcontrol,
712 struct snd_ctl_elem_info *uinfo)
713{
714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
715 struct cs_spec *spec = codec->spec;
Takashi Iwai10a20af2010-09-09 16:28:02 +0200716 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200717 unsigned int idx;
718
719 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
720 uinfo->count = 1;
721 uinfo->value.enumerated.items = spec->num_inputs;
722 if (uinfo->value.enumerated.item >= spec->num_inputs)
723 uinfo->value.enumerated.item = spec->num_inputs - 1;
724 idx = spec->input_idx[uinfo->value.enumerated.item];
Takashi Iwai201e06f2011-11-16 15:33:26 +0100725 snd_hda_get_pin_label(codec, cfg->inputs[idx].pin, cfg,
726 uinfo->value.enumerated.name,
727 sizeof(uinfo->value.enumerated.name), NULL);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200728 return 0;
729}
730
731static int cs_capture_source_get(struct snd_kcontrol *kcontrol,
732 struct snd_ctl_elem_value *ucontrol)
733{
734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
735 struct cs_spec *spec = codec->spec;
736 ucontrol->value.enumerated.item[0] = spec->capsrc_idx[spec->cur_input];
737 return 0;
738}
739
740static int cs_capture_source_put(struct snd_kcontrol *kcontrol,
741 struct snd_ctl_elem_value *ucontrol)
742{
743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744 struct cs_spec *spec = codec->spec;
745 unsigned int idx = ucontrol->value.enumerated.item[0];
746
747 if (idx >= spec->num_inputs)
748 return -EINVAL;
749 idx = spec->input_idx[idx];
Takashi Iwaiea359292009-07-06 12:58:59 +0200750 return change_cur_input(codec, idx, 0);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200751}
752
Takashi Iwaic42d4782011-05-02 11:36:09 +0200753static const struct snd_kcontrol_new cs_capture_source = {
Takashi Iwaie5f14242009-07-01 18:11:44 +0200754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
755 .name = "Capture Source",
756 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
757 .info = cs_capture_source_info,
758 .get = cs_capture_source_get,
759 .put = cs_capture_source_put,
760};
761
Takashi Iwaic42d4782011-05-02 11:36:09 +0200762static const struct hda_bind_ctls *make_bind_capture(struct hda_codec *codec,
Takashi Iwaie5f14242009-07-01 18:11:44 +0200763 struct hda_ctl_ops *ops)
764{
765 struct cs_spec *spec = codec->spec;
766 struct hda_bind_ctls *bind;
767 int i, n;
768
769 bind = kzalloc(sizeof(*bind) + sizeof(long) * (spec->num_inputs + 1),
770 GFP_KERNEL);
771 if (!bind)
772 return NULL;
773 bind->ops = ops;
774 n = 0;
775 for (i = 0; i < AUTO_PIN_LAST; i++) {
776 if (!spec->adc_nid[i])
777 continue;
778 bind->values[n++] =
779 HDA_COMPOSE_AMP_VAL(spec->adc_nid[i], 3,
780 spec->adc_idx[i], HDA_INPUT);
781 }
782 return bind;
783}
784
Takashi Iwai6a929342010-10-11 15:16:20 +0200785/* add a (input-boost) volume control to the given input pin */
786static int add_input_volume_control(struct hda_codec *codec,
787 struct auto_pin_cfg *cfg,
788 int item)
789{
790 hda_nid_t pin = cfg->inputs[item].pin;
791 u32 caps;
792 const char *label;
793 struct snd_kcontrol *kctl;
794
795 if (!(get_wcaps(codec, pin) & AC_WCAP_IN_AMP))
796 return 0;
797 caps = query_amp_caps(codec, pin, HDA_INPUT);
798 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
799 if (caps <= 1)
800 return 0;
801 label = hda_get_autocfg_input_label(codec, cfg, item);
802 return add_volume(codec, label, 0,
803 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT), 1, &kctl);
804}
805
Takashi Iwaie5f14242009-07-01 18:11:44 +0200806static int build_input(struct hda_codec *codec)
807{
808 struct cs_spec *spec = codec->spec;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200809 int i, err;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200810
Takashi Iwaie5f14242009-07-01 18:11:44 +0200811 if (!spec->num_inputs)
812 return 0;
813
Takashi Iwaie5f14242009-07-01 18:11:44 +0200814 /* make bind-capture */
815 spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw);
816 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
817 for (i = 0; i < 2; i++) {
818 struct snd_kcontrol *kctl;
Takashi Iwai21949f02009-12-23 08:31:59 +0100819 int n;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200820 if (!spec->capture_bind[i])
821 return -ENOMEM;
822 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
823 if (!kctl)
824 return -ENOMEM;
825 kctl->private_value = (long)spec->capture_bind[i];
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100826 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200827 if (err < 0)
828 return err;
Takashi Iwai21949f02009-12-23 08:31:59 +0100829 for (n = 0; n < AUTO_PIN_LAST; n++) {
830 if (!spec->adc_nid[n])
831 continue;
Brian J. Tarricone8dd34ab2010-05-02 17:32:10 -0700832 err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]);
Takashi Iwai21949f02009-12-23 08:31:59 +0100833 if (err < 0)
834 return err;
835 }
Takashi Iwaie5f14242009-07-01 18:11:44 +0200836 }
837
838 if (spec->num_inputs > 1 && !spec->mic_detect) {
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100839 err = snd_hda_ctl_add(codec, 0,
Takashi Iwaie5f14242009-07-01 18:11:44 +0200840 snd_ctl_new1(&cs_capture_source, codec));
841 if (err < 0)
842 return err;
843 }
844
Takashi Iwai6a929342010-10-11 15:16:20 +0200845 for (i = 0; i < spec->num_inputs; i++) {
846 err = add_input_volume_control(codec, &spec->autocfg, i);
847 if (err < 0)
848 return err;
849 }
850
Takashi Iwaie5f14242009-07-01 18:11:44 +0200851 return 0;
852}
853
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200854/*
855 */
856
Takashi Iwaie5f14242009-07-01 18:11:44 +0200857static int build_digital_output(struct hda_codec *codec)
858{
859 struct cs_spec *spec = codec->spec;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200860 int err;
861
Takashi Iwai63b24132009-07-09 11:45:59 +0200862 if (!spec->multiout.dig_out_nid)
863 return 0;
864
Stephen Warren74b654c2011-06-01 11:14:18 -0600865 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid,
866 spec->multiout.dig_out_nid);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200867 if (err < 0)
868 return err;
869 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
870 if (err < 0)
871 return err;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200872 return 0;
873}
874
875static int build_digital_input(struct hda_codec *codec)
876{
877 struct cs_spec *spec = codec->spec;
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200878 if (spec->dig_in)
879 return snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
880 return 0;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200881}
882
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200883/*
884 * auto-mute and auto-mic switching
Tim Howe56487c22011-07-22 16:41:00 -0500885 * CS421x auto-output redirecting
886 * HP/SPK/SPDIF
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200887 */
888
Takashi Iwaie5f14242009-07-01 18:11:44 +0200889static void cs_automute(struct hda_codec *codec)
890{
891 struct cs_spec *spec = codec->spec;
892 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai06dec222011-05-17 10:00:16 +0200893 unsigned int hp_present;
Tim Howe56487c22011-07-22 16:41:00 -0500894 unsigned int spdif_present;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200895 hda_nid_t nid;
896 int i;
897
Tim Howe56487c22011-07-22 16:41:00 -0500898 spdif_present = 0;
899 if (cfg->dig_outs) {
900 nid = cfg->dig_out_pins[0];
901 if (is_jack_detectable(codec, nid)) {
902 /*
903 TODO: SPDIF output redirect when SENSE_B is enabled.
904 Shared (SENSE_A) jack (e.g HP/mini-TOSLINK)
905 assumed.
906 */
907 if (snd_hda_jack_detect(codec, nid)
908 /* && spec->sense_b */)
909 spdif_present = 1;
910 }
911 }
912
Takashi Iwaie5f14242009-07-01 18:11:44 +0200913 hp_present = 0;
914 for (i = 0; i < cfg->hp_outs; i++) {
915 nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200916 if (!is_jack_detectable(codec, nid))
Takashi Iwaie5f14242009-07-01 18:11:44 +0200917 continue;
Wu Fengguang864f92b2009-11-18 12:38:02 +0800918 hp_present = snd_hda_jack_detect(codec, nid);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200919 if (hp_present)
920 break;
921 }
Tim Howe56487c22011-07-22 16:41:00 -0500922
923 /* mute speakers if spdif or hp jack is plugged in */
Takashi Iwaie5f14242009-07-01 18:11:44 +0200924 for (i = 0; i < cfg->speaker_outs; i++) {
David Henningsson78e2a922012-01-02 12:40:16 +0100925 int pin_ctl = hp_present ? 0 : PIN_OUT;
926 /* detect on spdif is specific to CS421x */
927 if (spdif_present && (spec->vendor_nid == CS421X_VENDOR_NID))
928 pin_ctl = 0;
929
Takashi Iwaie5f14242009-07-01 18:11:44 +0200930 nid = cfg->speaker_pins[i];
931 snd_hda_codec_write(codec, nid, 0,
David Henningsson78e2a922012-01-02 12:40:16 +0100932 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_ctl);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200933 }
Takashi Iwai6dfeb7032011-11-22 20:00:31 +0100934 if (spec->gpio_eapd_hp) {
935 unsigned int gpio = hp_present ?
936 spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
Stelian Pop3a385162009-07-30 14:44:27 +0200937 snd_hda_codec_write(codec, 0x01, 0,
938 AC_VERB_SET_GPIO_DATA, gpio);
939 }
Tim Howe56487c22011-07-22 16:41:00 -0500940
941 /* specific to CS421x */
942 if (spec->vendor_nid == CS421X_VENDOR_NID) {
943 /* mute HPs if spdif jack (SENSE_B) is present */
944 for (i = 0; i < cfg->hp_outs; i++) {
945 nid = cfg->hp_pins[i];
946 snd_hda_codec_write(codec, nid, 0,
947 AC_VERB_SET_PIN_WIDGET_CONTROL,
948 (spdif_present && spec->sense_b) ? 0 : PIN_HP);
949 }
950
951 /* SPDIF TX on/off */
952 if (cfg->dig_outs) {
953 nid = cfg->dig_out_pins[0];
954 snd_hda_codec_write(codec, nid, 0,
955 AC_VERB_SET_PIN_WIDGET_CONTROL,
956 spdif_present ? PIN_OUT : 0);
957
958 }
959 /* Update board GPIOs if neccessary ... */
960 }
Takashi Iwaie5f14242009-07-01 18:11:44 +0200961}
962
Tim Howe56487c22011-07-22 16:41:00 -0500963/*
964 * Auto-input redirect for CS421x
965 * Switch max 3 inputs of a single ADC (nid 3)
966*/
967
Takashi Iwaie5f14242009-07-01 18:11:44 +0200968static void cs_automic(struct hda_codec *codec)
969{
970 struct cs_spec *spec = codec->spec;
971 struct auto_pin_cfg *cfg = &spec->autocfg;
972 hda_nid_t nid;
Wu Fengguang864f92b2009-11-18 12:38:02 +0800973 unsigned int present;
Tim Howe56487c22011-07-22 16:41:00 -0500974
Takashi Iwaic1e0bb92010-08-30 13:05:30 +0200975 nid = cfg->inputs[spec->automic_idx].pin;
Wu Fengguang864f92b2009-11-18 12:38:02 +0800976 present = snd_hda_jack_detect(codec, nid);
Tim Howe56487c22011-07-22 16:41:00 -0500977
978 /* specific to CS421x, single ADC */
979 if (spec->vendor_nid == CS421X_VENDOR_NID) {
980 if (present) {
981 spec->last_input = spec->cur_input;
982 spec->cur_input = spec->automic_idx;
983 } else {
984 spec->cur_input = spec->last_input;
985 }
Takashi Iwai05ee7962011-11-16 18:05:11 +0100986 cs_update_input_select(codec);
Tim Howe56487c22011-07-22 16:41:00 -0500987 } else {
988 if (present)
989 change_cur_input(codec, spec->automic_idx, 0);
990 else
991 change_cur_input(codec, !spec->automic_idx, 0);
992 }
Takashi Iwaie5f14242009-07-01 18:11:44 +0200993}
994
995/*
996 */
997
998static void init_output(struct hda_codec *codec)
999{
1000 struct cs_spec *spec = codec->spec;
1001 struct auto_pin_cfg *cfg = &spec->autocfg;
1002 int i;
1003
1004 /* mute first */
1005 for (i = 0; i < spec->multiout.num_dacs; i++)
1006 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
1007 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
1008 if (spec->multiout.hp_nid)
1009 snd_hda_codec_write(codec, spec->multiout.hp_nid, 0,
1010 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
1011 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
1012 if (!spec->multiout.extra_out_nid[i])
1013 break;
1014 snd_hda_codec_write(codec, spec->multiout.extra_out_nid[i], 0,
1015 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
1016 }
1017
1018 /* set appropriate pin controls */
1019 for (i = 0; i < cfg->line_outs; i++)
1020 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
1021 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Tim Howe56487c22011-07-22 16:41:00 -05001022 /* HP */
Takashi Iwaie5f14242009-07-01 18:11:44 +02001023 for (i = 0; i < cfg->hp_outs; i++) {
1024 hda_nid_t nid = cfg->hp_pins[i];
1025 snd_hda_codec_write(codec, nid, 0,
1026 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
1027 if (!cfg->speaker_outs)
1028 continue;
Tim Howe56487c22011-07-22 16:41:00 -05001029 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001030 snd_hda_jack_detect_enable(codec, nid, HP_EVENT);
Takashi Iwaie5f14242009-07-01 18:11:44 +02001031 spec->hp_detect = 1;
1032 }
1033 }
Tim Howe56487c22011-07-22 16:41:00 -05001034
1035 /* Speaker */
Takashi Iwaie5f14242009-07-01 18:11:44 +02001036 for (i = 0; i < cfg->speaker_outs; i++)
1037 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
1038 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Tim Howe56487c22011-07-22 16:41:00 -05001039
1040 /* SPDIF is enabled on presence detect for CS421x */
1041 if (spec->hp_detect || spec->spdif_detect)
Takashi Iwaie5f14242009-07-01 18:11:44 +02001042 cs_automute(codec);
1043}
1044
1045static void init_input(struct hda_codec *codec)
1046{
1047 struct cs_spec *spec = codec->spec;
1048 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai40c20fa2009-07-06 13:00:57 +02001049 unsigned int coef;
Takashi Iwaie5f14242009-07-01 18:11:44 +02001050 int i;
1051
Takashi Iwaic1e0bb92010-08-30 13:05:30 +02001052 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwaie5f14242009-07-01 18:11:44 +02001053 unsigned int ctl;
Takashi Iwaic1e0bb92010-08-30 13:05:30 +02001054 hda_nid_t pin = cfg->inputs[i].pin;
1055 if (!spec->adc_nid[i])
Takashi Iwaie5f14242009-07-01 18:11:44 +02001056 continue;
1057 /* set appropriate pin control and mute first */
1058 ctl = PIN_IN;
Takashi Iwai86e29592010-09-09 14:50:17 +02001059 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwaie5f14242009-07-01 18:11:44 +02001060 unsigned int caps = snd_hda_query_pin_caps(codec, pin);
1061 caps >>= AC_PINCAP_VREF_SHIFT;
1062 if (caps & AC_PINCAP_VREF_80)
1063 ctl = PIN_VREF80;
1064 }
1065 snd_hda_codec_write(codec, pin, 0,
1066 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
1067 snd_hda_codec_write(codec, spec->adc_nid[i], 0,
1068 AC_VERB_SET_AMP_GAIN_MUTE,
1069 AMP_IN_MUTE(spec->adc_idx[i]));
1070 if (spec->mic_detect && spec->automic_idx == i)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001071 snd_hda_jack_detect_enable(codec, pin, MIC_EVENT);
Takashi Iwaie5f14242009-07-01 18:11:44 +02001072 }
Tim Howe56487c22011-07-22 16:41:00 -05001073 /* specific to CS421x */
1074 if (spec->vendor_nid == CS421X_VENDOR_NID) {
1075 if (spec->mic_detect)
1076 cs_automic(codec);
1077 else {
1078 spec->cur_adc = spec->adc_nid[spec->cur_input];
Takashi Iwai05ee7962011-11-16 18:05:11 +01001079 cs_update_input_select(codec);
Tim Howe56487c22011-07-22 16:41:00 -05001080 }
1081 } else {
1082 change_cur_input(codec, spec->cur_input, 1);
1083 if (spec->mic_detect)
1084 cs_automic(codec);
Takashi Iwai40c20fa2009-07-06 13:00:57 +02001085
Tim Howe56487c22011-07-22 16:41:00 -05001086 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);
1095 }
Takashi Iwai40c20fa2009-07-06 13:00:57 +02001096}
1097
Takashi Iwaic42d4782011-05-02 11:36:09 +02001098static const struct hda_verb cs_coef_init_verbs[] = {
Takashi Iwai40c20fa2009-07-06 13:00:57 +02001099 {0x11, AC_VERB_SET_PROC_STATE, 1},
1100 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
1101 {0x11, AC_VERB_SET_PROC_COEF,
1102 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
1103 | 0x0040 /* Mute DACs on FIFO error */
1104 | 0x1000 /* Enable DACs High Pass Filter */
1105 | 0x0400 /* Disable Coefficient Auto increment */
1106 )},
1107 /* Beep */
1108 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
1109 {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */
1110
1111 {} /* terminator */
1112};
1113
Brian Austina769cbc2010-09-07 14:36:22 -05001114/* Errata: CS4207 rev C0/C1/C2 Silicon
1115 *
1116 * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
1117 *
1118 * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
1119 * may be excessive (up to an additional 200 μA), which is most easily
1120 * observed while the part is being held in reset (RESET# active low).
1121 *
1122 * Root Cause: At initial powerup of the device, the logic that drives
1123 * the clock and write enable to the S/PDIF SRC RAMs is not properly
1124 * initialized.
1125 * Certain random patterns will cause a steady leakage current in those
1126 * RAM cells. The issue will resolve once the SRCs are used (turned on).
1127 *
1128 * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
1129 * blocks, which will alleviate the issue.
1130 */
1131
Takashi Iwaic42d4782011-05-02 11:36:09 +02001132static const struct hda_verb cs_errata_init_verbs[] = {
Brian Austina769cbc2010-09-07 14:36:22 -05001133 {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
1134 {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
1135
1136 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
1137 {0x11, AC_VERB_SET_PROC_COEF, 0x9999},
1138 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
1139 {0x11, AC_VERB_SET_PROC_COEF, 0xa412},
1140 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
1141 {0x11, AC_VERB_SET_PROC_COEF, 0x0009},
1142
1143 {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */
1144 {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */
1145
1146 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
1147 {0x11, AC_VERB_SET_PROC_COEF, 0x2412},
1148 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
1149 {0x11, AC_VERB_SET_PROC_COEF, 0x0000},
1150 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
1151 {0x11, AC_VERB_SET_PROC_COEF, 0x0008},
1152 {0x11, AC_VERB_SET_PROC_STATE, 0x00},
1153
Takashi Iwai38c07642011-03-03 14:54:19 +01001154#if 0 /* Don't to set to D3 as we are in power-up sequence */
Brian Austina769cbc2010-09-07 14:36:22 -05001155 {0x07, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Rx: D3 */
1156 {0x08, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Tx: D3 */
1157 /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */
Takashi Iwai38c07642011-03-03 14:54:19 +01001158#endif
Brian Austina769cbc2010-09-07 14:36:22 -05001159
1160 {} /* terminator */
1161};
1162
Takashi Iwai40c20fa2009-07-06 13:00:57 +02001163/* SPDIF setup */
1164static void init_digital(struct hda_codec *codec)
1165{
1166 unsigned int coef;
1167
1168 coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
1169 coef |= 0x0008; /* Replace with mute on error */
1170 if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID))
1171 coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
1172 * SPDIF_OUT2 is shared with GPIO1 and
1173 * DMIC_SDA2.
1174 */
1175 cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef);
Takashi Iwaie5f14242009-07-01 18:11:44 +02001176}
1177
1178static int cs_init(struct hda_codec *codec)
1179{
1180 struct cs_spec *spec = codec->spec;
1181
Brian Austina769cbc2010-09-07 14:36:22 -05001182 /* init_verb sequence for C0/C1/C2 errata*/
1183 snd_hda_sequence_write(codec, cs_errata_init_verbs);
1184
Takashi Iwai40c20fa2009-07-06 13:00:57 +02001185 snd_hda_sequence_write(codec, cs_coef_init_verbs);
Takashi Iwaied208252009-07-07 09:04:26 +02001186
1187 if (spec->gpio_mask) {
1188 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
1189 spec->gpio_mask);
1190 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
1191 spec->gpio_dir);
1192 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1193 spec->gpio_data);
1194 }
1195
Takashi Iwaie5f14242009-07-01 18:11:44 +02001196 init_output(codec);
1197 init_input(codec);
Takashi Iwai40c20fa2009-07-06 13:00:57 +02001198 init_digital(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001199 snd_hda_jack_report_sync(codec);
1200
Takashi Iwaie5f14242009-07-01 18:11:44 +02001201 return 0;
1202}
1203
1204static int cs_build_controls(struct hda_codec *codec)
1205{
Takashi Iwai01a61e12011-10-28 00:03:22 +02001206 struct cs_spec *spec = codec->spec;
Takashi Iwaie5f14242009-07-01 18:11:44 +02001207 int err;
1208
1209 err = build_output(codec);
1210 if (err < 0)
1211 return err;
1212 err = build_input(codec);
1213 if (err < 0)
1214 return err;
1215 err = build_digital_output(codec);
1216 if (err < 0)
1217 return err;
1218 err = build_digital_input(codec);
1219 if (err < 0)
1220 return err;
Takashi Iwai01a61e12011-10-28 00:03:22 +02001221 err = cs_init(codec);
1222 if (err < 0)
1223 return err;
1224
1225 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1226 if (err < 0)
1227 return err;
1228
1229 return 0;
Takashi Iwaie5f14242009-07-01 18:11:44 +02001230}
1231
1232static void cs_free(struct hda_codec *codec)
1233{
1234 struct cs_spec *spec = codec->spec;
1235 kfree(spec->capture_bind[0]);
1236 kfree(spec->capture_bind[1]);
1237 kfree(codec->spec);
1238}
1239
1240static void cs_unsol_event(struct hda_codec *codec, unsigned int res)
1241{
Takashi Iwai3a938972011-10-28 01:16:55 +02001242 switch (snd_hda_jack_get_action(codec, res >> 26)) {
Takashi Iwaie5f14242009-07-01 18:11:44 +02001243 case HP_EVENT:
1244 cs_automute(codec);
1245 break;
1246 case MIC_EVENT:
1247 cs_automic(codec);
1248 break;
1249 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02001250 snd_hda_jack_report_sync(codec);
Takashi Iwaie5f14242009-07-01 18:11:44 +02001251}
1252
Takashi Iwaic42d4782011-05-02 11:36:09 +02001253static const struct hda_codec_ops cs_patch_ops = {
Takashi Iwaie5f14242009-07-01 18:11:44 +02001254 .build_controls = cs_build_controls,
1255 .build_pcms = cs_build_pcms,
1256 .init = cs_init,
1257 .free = cs_free,
1258 .unsol_event = cs_unsol_event,
1259};
1260
1261static int cs_parse_auto_config(struct hda_codec *codec)
1262{
1263 struct cs_spec *spec = codec->spec;
1264 int err;
1265
1266 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1267 if (err < 0)
1268 return err;
Takashi Iwaied208252009-07-07 09:04:26 +02001269
1270 err = parse_output(codec);
1271 if (err < 0)
1272 return err;
1273 err = parse_input(codec);
1274 if (err < 0)
1275 return err;
1276 err = parse_digital_output(codec);
1277 if (err < 0)
1278 return err;
1279 err = parse_digital_input(codec);
1280 if (err < 0)
1281 return err;
Takashi Iwaie5f14242009-07-01 18:11:44 +02001282 return 0;
1283}
1284
Takashi Iwaiea734962011-01-17 11:29:34 +01001285static const char * const cs420x_models[CS420X_MODELS] = {
Vince Weaver4e7d7c62010-09-22 17:31:37 -04001286 [CS420X_MBP53] = "mbp53",
Takashi Iwaia6bae202009-07-06 15:15:22 +02001287 [CS420X_MBP55] = "mbp55",
Rafael Avila de Espindola1a5ba2e2009-12-22 07:59:37 +01001288 [CS420X_IMAC27] = "imac27",
Dan Carpenter92bb43e2011-11-24 14:48:24 +03001289 [CS420X_APPLE] = "apple",
Takashi Iwaia6bae202009-07-06 15:15:22 +02001290 [CS420X_AUTO] = "auto",
1291};
1292
1293
Takashi Iwaic42d4782011-05-02 11:36:09 +02001294static const struct snd_pci_quirk cs420x_cfg_tbl[] = {
Vince Weaver4e7d7c62010-09-22 17:31:37 -04001295 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53),
Edgar (gimli) Hucek87232dd2010-11-03 08:14:10 +01001296 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55),
Takashi Iwaia6bae202009-07-06 15:15:22 +02001297 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
Takashi Iwaif46119b2010-10-11 14:46:35 +02001298 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55),
Takashi Iwai6dfeb7032011-11-22 20:00:31 +01001299 /* this conflicts with too many other models */
1300 /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/
1301 {} /* terminator */
1302};
1303
1304static const struct snd_pci_quirk cs420x_codec_cfg_tbl[] = {
1305 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE),
Takashi Iwaia6bae202009-07-06 15:15:22 +02001306 {} /* terminator */
1307};
1308
1309struct cs_pincfg {
1310 hda_nid_t nid;
1311 u32 val;
1312};
1313
Takashi Iwaic42d4782011-05-02 11:36:09 +02001314static const struct cs_pincfg mbp53_pincfgs[] = {
Vince Weaver4e7d7c62010-09-22 17:31:37 -04001315 { 0x09, 0x012b4050 },
1316 { 0x0a, 0x90100141 },
1317 { 0x0b, 0x90100140 },
1318 { 0x0c, 0x018b3020 },
1319 { 0x0d, 0x90a00110 },
1320 { 0x0e, 0x400000f0 },
1321 { 0x0f, 0x01cbe030 },
1322 { 0x10, 0x014be060 },
1323 { 0x12, 0x400000f0 },
1324 { 0x15, 0x400000f0 },
1325 {} /* terminator */
1326};
1327
Takashi Iwaic42d4782011-05-02 11:36:09 +02001328static const struct cs_pincfg mbp55_pincfgs[] = {
Takashi Iwaia6bae202009-07-06 15:15:22 +02001329 { 0x09, 0x012b4030 },
1330 { 0x0a, 0x90100121 },
1331 { 0x0b, 0x90100120 },
1332 { 0x0c, 0x400000f0 },
1333 { 0x0d, 0x90a00110 },
1334 { 0x0e, 0x400000f0 },
1335 { 0x0f, 0x400000f0 },
1336 { 0x10, 0x014be040 },
1337 { 0x12, 0x400000f0 },
1338 { 0x15, 0x400000f0 },
1339 {} /* terminator */
1340};
1341
Takashi Iwaic42d4782011-05-02 11:36:09 +02001342static const struct cs_pincfg imac27_pincfgs[] = {
Rafael Avila de Espindola1a5ba2e2009-12-22 07:59:37 +01001343 { 0x09, 0x012b4050 },
1344 { 0x0a, 0x90100140 },
1345 { 0x0b, 0x90100142 },
1346 { 0x0c, 0x018b3020 },
1347 { 0x0d, 0x90a00110 },
1348 { 0x0e, 0x400000f0 },
1349 { 0x0f, 0x01cbe030 },
1350 { 0x10, 0x014be060 },
1351 { 0x12, 0x01ab9070 },
1352 { 0x15, 0x400000f0 },
1353 {} /* terminator */
1354};
1355
Takashi Iwaic42d4782011-05-02 11:36:09 +02001356static const struct cs_pincfg *cs_pincfgs[CS420X_MODELS] = {
Vince Weaver4e7d7c62010-09-22 17:31:37 -04001357 [CS420X_MBP53] = mbp53_pincfgs,
Takashi Iwaia6bae202009-07-06 15:15:22 +02001358 [CS420X_MBP55] = mbp55_pincfgs,
Rafael Avila de Espindola1a5ba2e2009-12-22 07:59:37 +01001359 [CS420X_IMAC27] = imac27_pincfgs,
Takashi Iwaia6bae202009-07-06 15:15:22 +02001360};
1361
Tim Howe56487c22011-07-22 16:41:00 -05001362static void fix_pincfg(struct hda_codec *codec, int model,
1363 const struct cs_pincfg **pin_configs)
Takashi Iwaia6bae202009-07-06 15:15:22 +02001364{
Tim Howe56487c22011-07-22 16:41:00 -05001365 const struct cs_pincfg *cfg = pin_configs[model];
Takashi Iwaia6bae202009-07-06 15:15:22 +02001366 if (!cfg)
1367 return;
1368 for (; cfg->nid; cfg++)
1369 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1370}
1371
Takashi Iwaie5f14242009-07-01 18:11:44 +02001372static int patch_cs420x(struct hda_codec *codec)
1373{
1374 struct cs_spec *spec;
1375 int err;
1376
1377 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1378 if (!spec)
1379 return -ENOMEM;
1380 codec->spec = spec;
1381
Tim Howe56487c22011-07-22 16:41:00 -05001382 spec->vendor_nid = CS420X_VENDOR_NID;
1383
Takashi Iwaia6bae202009-07-06 15:15:22 +02001384 spec->board_config =
1385 snd_hda_check_board_config(codec, CS420X_MODELS,
1386 cs420x_models, cs420x_cfg_tbl);
Takashi Iwai6dfeb7032011-11-22 20:00:31 +01001387 if (spec->board_config < 0)
1388 spec->board_config =
1389 snd_hda_check_board_codec_sid_config(codec,
1390 CS420X_MODELS, NULL, cs420x_codec_cfg_tbl);
Takashi Iwaia6bae202009-07-06 15:15:22 +02001391 if (spec->board_config >= 0)
Tim Howe56487c22011-07-22 16:41:00 -05001392 fix_pincfg(codec, spec->board_config, cs_pincfgs);
Takashi Iwaia6bae202009-07-06 15:15:22 +02001393
Takashi Iwaied208252009-07-07 09:04:26 +02001394 switch (spec->board_config) {
Rafael Avila de Espindola1a5ba2e2009-12-22 07:59:37 +01001395 case CS420X_IMAC27:
Vince Weaver4e7d7c62010-09-22 17:31:37 -04001396 case CS420X_MBP53:
Takashi Iwaied208252009-07-07 09:04:26 +02001397 case CS420X_MBP55:
Takashi Iwai6dfeb7032011-11-22 20:00:31 +01001398 case CS420X_APPLE:
1399 spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */
1400 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
1401 spec->gpio_mask = spec->gpio_dir =
1402 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
Takashi Iwaied208252009-07-07 09:04:26 +02001403 break;
1404 }
Takashi Iwaie5f14242009-07-01 18:11:44 +02001405
Takashi Iwaied208252009-07-07 09:04:26 +02001406 err = cs_parse_auto_config(codec);
Takashi Iwai21a4dc42009-07-06 12:55:46 +02001407 if (err < 0)
1408 goto error;
1409
Takashi Iwaie5f14242009-07-01 18:11:44 +02001410 codec->patch_ops = cs_patch_ops;
1411
1412 return 0;
1413
1414 error:
1415 kfree(codec->spec);
1416 codec->spec = NULL;
1417 return err;
1418}
1419
Tim Howe56487c22011-07-22 16:41:00 -05001420/*
1421 * Cirrus Logic CS4210
1422 *
1423 * 1 DAC => HP(sense) / Speakers,
1424 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
1425 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
1426*/
1427
1428/* CS4210 board names */
1429static const char *cs421x_models[CS421X_MODELS] = {
1430 [CS421X_CDB4210] = "cdb4210",
1431};
1432
1433static const struct snd_pci_quirk cs421x_cfg_tbl[] = {
1434 /* Test Intel board + CDB2410 */
1435 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210),
1436 {} /* terminator */
1437};
1438
1439/* CS4210 board pinconfigs */
1440/* Default CS4210 (CDB4210)*/
1441static const struct cs_pincfg cdb4210_pincfgs[] = {
1442 { 0x05, 0x0321401f },
1443 { 0x06, 0x90170010 },
1444 { 0x07, 0x03813031 },
1445 { 0x08, 0xb7a70037 },
1446 { 0x09, 0xb7a6003e },
1447 { 0x0a, 0x034510f0 },
1448 {} /* terminator */
1449};
1450
1451static const struct cs_pincfg *cs421x_pincfgs[CS421X_MODELS] = {
1452 [CS421X_CDB4210] = cdb4210_pincfgs,
1453};
1454
1455static const struct hda_verb cs421x_coef_init_verbs[] = {
1456 {0x0B, AC_VERB_SET_PROC_STATE, 1},
1457 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG},
1458 /*
1459 Disable Coefficient Index Auto-Increment(DAI)=1,
1460 PDREF=0
1461 */
1462 {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 },
1463
1464 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG},
1465 /* ADC SZCMode = Digital Soft Ramp */
1466 {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 },
1467
1468 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG},
1469 {0x0B, AC_VERB_SET_PROC_COEF,
1470 (0x0002 /* DAC SZCMode = Digital Soft Ramp */
1471 | 0x0004 /* Mute DAC on FIFO error */
1472 | 0x0008 /* Enable DAC High Pass Filter */
1473 )},
1474 {} /* terminator */
1475};
1476
1477/* Errata: CS4210 rev A1 Silicon
1478 *
1479 * http://www.cirrus.com/en/pubs/errata/
1480 *
1481 * Description:
1482 * 1. Performance degredation is present in the ADC.
1483 * 2. Speaker output is not completely muted upon HP detect.
1484 * 3. Noise is present when clipping occurs on the amplified
1485 * speaker outputs.
1486 *
1487 * Workaround:
1488 * The following verb sequence written to the registers during
1489 * initialization will correct the issues listed above.
1490 */
1491
1492static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = {
1493 {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
1494
1495 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006},
1496 {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */
1497
1498 {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A},
1499 {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */
1500
1501 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011},
1502 {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */
1503
1504 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A},
1505 {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */
1506
1507 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B},
1508 {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */
1509
1510 {} /* terminator */
1511};
1512
1513/* Speaker Amp Gain is controlled by the vendor widget's coef 4 */
1514static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0);
1515
1516static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol,
1517 struct snd_ctl_elem_info *uinfo)
1518{
1519 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1520 uinfo->count = 1;
1521 uinfo->value.integer.min = 0;
1522 uinfo->value.integer.max = 3;
1523 return 0;
1524}
1525
1526static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol,
1527 struct snd_ctl_elem_value *ucontrol)
1528{
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530
1531 ucontrol->value.integer.value[0] =
1532 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003;
1533 return 0;
1534}
1535
1536static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol,
1537 struct snd_ctl_elem_value *ucontrol)
1538{
1539 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1540
1541 unsigned int vol = ucontrol->value.integer.value[0];
1542 unsigned int coef =
1543 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL);
1544 unsigned int original_coef = coef;
1545
1546 coef &= ~0x0003;
1547 coef |= (vol & 0x0003);
1548 if (original_coef == coef)
1549 return 0;
1550 else {
1551 cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef);
1552 return 1;
1553 }
1554}
1555
1556static const struct snd_kcontrol_new cs421x_speaker_bost_ctl = {
1557
1558 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1559 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1560 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1561 .name = "Speaker Boost Playback Volume",
1562 .info = cs421x_boost_vol_info,
1563 .get = cs421x_boost_vol_get,
1564 .put = cs421x_boost_vol_put,
1565 .tlv = { .p = cs421x_speaker_boost_db_scale },
1566};
1567
1568static void cs421x_pinmux_init(struct hda_codec *codec)
1569{
1570 struct cs_spec *spec = codec->spec;
1571 unsigned int def_conf, coef;
1572
1573 /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */
1574 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
1575
1576 if (spec->gpio_mask)
1577 coef |= 0x0008; /* B1,B2 are GPIOs */
1578 else
1579 coef &= ~0x0008;
1580
1581 if (spec->sense_b)
1582 coef |= 0x0010; /* B2 is SENSE_B, not inverted */
1583 else
1584 coef &= ~0x0010;
1585
1586 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
1587
1588 if ((spec->gpio_mask || spec->sense_b) &&
1589 is_active_pin(codec, CS421X_DMIC_PIN_NID)) {
1590
1591 /*
1592 GPIO or SENSE_B forced - disconnect the DMIC pin.
1593 */
1594 def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID);
1595 def_conf &= ~AC_DEFCFG_PORT_CONN;
1596 def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT);
1597 snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf);
1598 }
1599}
1600
1601static void init_cs421x_digital(struct hda_codec *codec)
1602{
1603 struct cs_spec *spec = codec->spec;
1604 struct auto_pin_cfg *cfg = &spec->autocfg;
1605 int i;
1606
1607
1608 for (i = 0; i < cfg->dig_outs; i++) {
1609 hda_nid_t nid = cfg->dig_out_pins[i];
1610 if (!cfg->speaker_outs)
1611 continue;
1612 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001613 snd_hda_jack_detect_enable(codec, nid, SPDIF_EVENT);
Tim Howe56487c22011-07-22 16:41:00 -05001614 spec->spdif_detect = 1;
1615 }
1616 }
1617}
1618
1619static int cs421x_init(struct hda_codec *codec)
1620{
1621 struct cs_spec *spec = codec->spec;
1622
1623 snd_hda_sequence_write(codec, cs421x_coef_init_verbs);
1624 snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes);
1625
1626 cs421x_pinmux_init(codec);
1627
1628 if (spec->gpio_mask) {
1629 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
1630 spec->gpio_mask);
1631 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
1632 spec->gpio_dir);
1633 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1634 spec->gpio_data);
1635 }
1636
1637 init_output(codec);
1638 init_input(codec);
1639 init_cs421x_digital(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001640 snd_hda_jack_report_sync(codec);
Tim Howe56487c22011-07-22 16:41:00 -05001641
1642 return 0;
1643}
1644
1645/*
1646 * CS4210 Input MUX (1 ADC)
1647 */
1648static int cs421x_mux_enum_info(struct snd_kcontrol *kcontrol,
1649 struct snd_ctl_elem_info *uinfo)
1650{
1651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1652 struct cs_spec *spec = codec->spec;
1653
1654 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
1655}
1656
1657static int cs421x_mux_enum_get(struct snd_kcontrol *kcontrol,
1658 struct snd_ctl_elem_value *ucontrol)
1659{
1660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1661 struct cs_spec *spec = codec->spec;
1662
1663 ucontrol->value.enumerated.item[0] = spec->cur_input;
1664 return 0;
1665}
1666
1667static int cs421x_mux_enum_put(struct snd_kcontrol *kcontrol,
1668 struct snd_ctl_elem_value *ucontrol)
1669{
1670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1671 struct cs_spec *spec = codec->spec;
1672
1673 return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol,
1674 spec->adc_nid[0], &spec->cur_input);
1675
1676}
1677
1678static struct snd_kcontrol_new cs421x_capture_source = {
1679
1680 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1681 .name = "Capture Source",
1682 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1683 .info = cs421x_mux_enum_info,
1684 .get = cs421x_mux_enum_get,
1685 .put = cs421x_mux_enum_put,
1686};
1687
1688static int cs421x_add_input_volume_control(struct hda_codec *codec, int item)
1689{
1690 struct cs_spec *spec = codec->spec;
1691 struct auto_pin_cfg *cfg = &spec->autocfg;
1692 const struct hda_input_mux *imux = &spec->input_mux;
1693 hda_nid_t pin = cfg->inputs[item].pin;
1694 struct snd_kcontrol *kctl;
1695 u32 caps;
1696
1697 if (!(get_wcaps(codec, pin) & AC_WCAP_IN_AMP))
1698 return 0;
1699
1700 caps = query_amp_caps(codec, pin, HDA_INPUT);
1701 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1702 if (caps <= 1)
1703 return 0;
1704
1705 return add_volume(codec, imux->items[item].label, 0,
1706 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT), 1, &kctl);
1707}
1708
1709/* add a (input-boost) volume control to the given input pin */
1710static int build_cs421x_input(struct hda_codec *codec)
1711{
1712 struct cs_spec *spec = codec->spec;
1713 struct auto_pin_cfg *cfg = &spec->autocfg;
1714 struct hda_input_mux *imux = &spec->input_mux;
1715 int i, err, type_idx;
1716 const char *label;
1717
1718 if (!spec->num_inputs)
1719 return 0;
1720
1721 /* make bind-capture */
1722 spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw);
1723 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
1724 for (i = 0; i < 2; i++) {
1725 struct snd_kcontrol *kctl;
1726 int n;
1727 if (!spec->capture_bind[i])
1728 return -ENOMEM;
1729 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
1730 if (!kctl)
1731 return -ENOMEM;
1732 kctl->private_value = (long)spec->capture_bind[i];
1733 err = snd_hda_ctl_add(codec, 0, kctl);
1734 if (err < 0)
1735 return err;
1736 for (n = 0; n < AUTO_PIN_LAST; n++) {
1737 if (!spec->adc_nid[n])
1738 continue;
1739 err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]);
1740 if (err < 0)
1741 return err;
1742 }
1743 }
1744
1745 /* Add Input MUX Items + Capture Volume/Switch */
1746 for (i = 0; i < spec->num_inputs; i++) {
1747 label = hda_get_autocfg_input_label(codec, cfg, i);
1748 snd_hda_add_imux_item(imux, label, spec->adc_idx[i], &type_idx);
1749
1750 err = cs421x_add_input_volume_control(codec, i);
1751 if (err < 0)
1752 return err;
1753 }
1754
1755 /*
1756 Add 'Capture Source' Switch if
1757 * 2 inputs and no mic detec
1758 * 3 inputs
1759 */
1760 if ((spec->num_inputs == 2 && !spec->mic_detect) ||
1761 (spec->num_inputs == 3)) {
1762
1763 err = snd_hda_ctl_add(codec, spec->adc_nid[0],
1764 snd_ctl_new1(&cs421x_capture_source, codec));
1765 if (err < 0)
1766 return err;
1767 }
1768
1769 return 0;
1770}
1771
1772/* Single DAC (Mute/Gain) */
1773static int build_cs421x_output(struct hda_codec *codec)
1774{
1775 hda_nid_t dac = CS4210_DAC_NID;
1776 struct cs_spec *spec = codec->spec;
1777 struct auto_pin_cfg *cfg = &spec->autocfg;
1778 struct snd_kcontrol *kctl;
1779 int err;
David Henningsson40d03e62012-01-02 12:40:15 +01001780 char *name = "Master";
Tim Howe56487c22011-07-22 16:41:00 -05001781
1782 fix_volume_caps(codec, dac);
Tim Howe56487c22011-07-22 16:41:00 -05001783
1784 err = add_mute(codec, name, 0,
1785 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
1786 if (err < 0)
1787 return err;
Tim Howe56487c22011-07-22 16:41:00 -05001788
1789 err = add_volume(codec, name, 0,
1790 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
1791 if (err < 0)
1792 return err;
Tim Howe56487c22011-07-22 16:41:00 -05001793
1794 if (cfg->speaker_outs) {
1795 err = snd_hda_ctl_add(codec, 0,
1796 snd_ctl_new1(&cs421x_speaker_bost_ctl, codec));
1797 if (err < 0)
1798 return err;
1799 }
1800 return err;
1801}
1802
1803static int cs421x_build_controls(struct hda_codec *codec)
1804{
Takashi Iwai01a61e12011-10-28 00:03:22 +02001805 struct cs_spec *spec = codec->spec;
Tim Howe56487c22011-07-22 16:41:00 -05001806 int err;
1807
1808 err = build_cs421x_output(codec);
1809 if (err < 0)
1810 return err;
1811 err = build_cs421x_input(codec);
1812 if (err < 0)
1813 return err;
1814 err = build_digital_output(codec);
1815 if (err < 0)
1816 return err;
Takashi Iwai01a61e12011-10-28 00:03:22 +02001817 err = cs421x_init(codec);
1818 if (err < 0)
1819 return err;
1820
1821 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1822 if (err < 0)
1823 return err;
1824
1825 return 0;
Tim Howe56487c22011-07-22 16:41:00 -05001826}
1827
1828static void cs421x_unsol_event(struct hda_codec *codec, unsigned int res)
1829{
Takashi Iwai3a938972011-10-28 01:16:55 +02001830 switch (snd_hda_jack_get_action(codec, res >> 26)) {
Tim Howe56487c22011-07-22 16:41:00 -05001831 case HP_EVENT:
1832 case SPDIF_EVENT:
1833 cs_automute(codec);
1834 break;
1835
1836 case MIC_EVENT:
1837 cs_automic(codec);
1838 break;
1839 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02001840 snd_hda_jack_report_sync(codec);
Tim Howe56487c22011-07-22 16:41:00 -05001841}
1842
1843static int parse_cs421x_input(struct hda_codec *codec)
1844{
1845 struct cs_spec *spec = codec->spec;
1846 struct auto_pin_cfg *cfg = &spec->autocfg;
1847 int i;
1848
1849 for (i = 0; i < cfg->num_inputs; i++) {
1850 hda_nid_t pin = cfg->inputs[i].pin;
1851 spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]);
1852 spec->cur_input = spec->last_input = i;
1853 spec->num_inputs++;
1854
1855 /* check whether the automatic mic switch is available */
1856 if (is_ext_mic(codec, i) && cfg->num_inputs >= 2) {
1857 spec->mic_detect = 1;
1858 spec->automic_idx = i;
1859 }
1860 }
1861 return 0;
1862}
1863
1864static int cs421x_parse_auto_config(struct hda_codec *codec)
1865{
1866 struct cs_spec *spec = codec->spec;
1867 int err;
1868
1869 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1870 if (err < 0)
1871 return err;
1872 err = parse_output(codec);
1873 if (err < 0)
1874 return err;
1875 err = parse_cs421x_input(codec);
1876 if (err < 0)
1877 return err;
1878 err = parse_digital_output(codec);
1879 if (err < 0)
1880 return err;
1881 return 0;
1882}
1883
1884#ifdef CONFIG_PM
1885/*
1886 Manage PDREF, when transitioning to D3hot
1887 (DAC,ADC) -> D3, PDREF=1, AFG->D3
1888*/
1889static int cs421x_suspend(struct hda_codec *codec, pm_message_t state)
1890{
1891 unsigned int coef;
1892
1893 snd_hda_shutup_pins(codec);
1894
1895 snd_hda_codec_write(codec, CS4210_DAC_NID, 0,
1896 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1897 snd_hda_codec_write(codec, CS4210_ADC_NID, 0,
1898 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1899
1900 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
1901 coef |= 0x0004; /* PDREF */
1902 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
1903
1904 return 0;
1905}
1906#endif
1907
1908static struct hda_codec_ops cs4210_patch_ops = {
1909 .build_controls = cs421x_build_controls,
1910 .build_pcms = cs_build_pcms,
1911 .init = cs421x_init,
1912 .free = cs_free,
1913 .unsol_event = cs421x_unsol_event,
1914#ifdef CONFIG_PM
1915 .suspend = cs421x_suspend,
1916#endif
1917};
1918
1919static int patch_cs421x(struct hda_codec *codec)
1920{
1921 struct cs_spec *spec;
1922 int err;
1923
1924 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1925 if (!spec)
1926 return -ENOMEM;
1927 codec->spec = spec;
1928
1929 spec->vendor_nid = CS421X_VENDOR_NID;
1930
1931 spec->board_config =
1932 snd_hda_check_board_config(codec, CS421X_MODELS,
1933 cs421x_models, cs421x_cfg_tbl);
1934 if (spec->board_config >= 0)
1935 fix_pincfg(codec, spec->board_config, cs421x_pincfgs);
1936 /*
1937 Setup GPIO/SENSE for each board (if used)
1938 */
1939 switch (spec->board_config) {
1940 case CS421X_CDB4210:
1941 snd_printd("CS4210 board: %s\n",
1942 cs421x_models[spec->board_config]);
1943/* spec->gpio_mask = 3;
1944 spec->gpio_dir = 3;
1945 spec->gpio_data = 3;
1946*/
1947 spec->sense_b = 1;
1948
1949 break;
1950 }
1951
1952 /*
1953 Update the GPIO/DMIC/SENSE_B pinmux before the configuration
1954 is auto-parsed. If GPIO or SENSE_B is forced, DMIC input
1955 is disabled.
1956 */
1957 cs421x_pinmux_init(codec);
1958
1959 err = cs421x_parse_auto_config(codec);
1960 if (err < 0)
1961 goto error;
1962
1963 codec->patch_ops = cs4210_patch_ops;
1964
1965 return 0;
1966
1967 error:
1968 kfree(codec->spec);
1969 codec->spec = NULL;
1970 return err;
1971}
1972
Takashi Iwaie5f14242009-07-01 18:11:44 +02001973
1974/*
1975 * patch entries
1976 */
Takashi Iwaic42d4782011-05-02 11:36:09 +02001977static const struct hda_codec_preset snd_hda_preset_cirrus[] = {
Takashi Iwaie5f14242009-07-01 18:11:44 +02001978 { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x },
1979 { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x },
Tim Howe56487c22011-07-22 16:41:00 -05001980 { .id = 0x10134210, .name = "CS4210", .patch = patch_cs421x },
Takashi Iwaie5f14242009-07-01 18:11:44 +02001981 {} /* terminator */
1982};
1983
1984MODULE_ALIAS("snd-hda-codec-id:10134206");
1985MODULE_ALIAS("snd-hda-codec-id:10134207");
Tim Howe56487c22011-07-22 16:41:00 -05001986MODULE_ALIAS("snd-hda-codec-id:10134210");
Takashi Iwaie5f14242009-07-01 18:11:44 +02001987
1988MODULE_LICENSE("GPL");
1989MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1990
1991static struct hda_codec_preset_list cirrus_list = {
1992 .preset = snd_hda_preset_cirrus,
1993 .owner = THIS_MODULE,
1994};
1995
1996static int __init patch_cirrus_init(void)
1997{
1998 return snd_hda_add_codec_preset(&cirrus_list);
1999}
2000
2001static void __exit patch_cirrus_exit(void)
2002{
2003 snd_hda_delete_codec_preset(&cirrus_list);
2004}
2005
2006module_init(patch_cirrus_init)
2007module_exit(patch_cirrus_exit)