]> bbs.cooldavid.org Git - net-next-2.6.git/blame - sound/pci/hda/patch_cirrus.c
ALSA: hda - Keep char arrays in input_mux items
[net-next-2.6.git] / sound / pci / hda / patch_cirrus.c
CommitLineData
e5f14248
TI
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>
25#include <sound/core.h>
26#include "hda_codec.h"
27#include "hda_local.h"
28
29/*
30 */
31
32struct cs_spec {
a6bae205 33 int board_config;
e5f14248
TI
34 struct auto_pin_cfg autocfg;
35 struct hda_multi_out multiout;
36 struct snd_kcontrol *vmaster_sw;
37 struct snd_kcontrol *vmaster_vol;
38
39 hda_nid_t dac_nid[AUTO_CFG_MAX_OUTS];
40 hda_nid_t slave_dig_outs[2];
41
42 unsigned int input_idx[AUTO_PIN_LAST];
43 unsigned int capsrc_idx[AUTO_PIN_LAST];
44 hda_nid_t adc_nid[AUTO_PIN_LAST];
45 unsigned int adc_idx[AUTO_PIN_LAST];
46 unsigned int num_inputs;
47 unsigned int cur_input;
48 unsigned int automic_idx;
49 hda_nid_t cur_adc;
50 unsigned int cur_adc_stream_tag;
51 unsigned int cur_adc_format;
52 hda_nid_t dig_in;
53
54 struct hda_bind_ctls *capture_bind[2];
55
ed208255
TI
56 unsigned int gpio_mask;
57 unsigned int gpio_dir;
58 unsigned int gpio_data;
59
e5f14248
TI
60 struct hda_pcm pcm_rec[2]; /* PCM information */
61
62 unsigned int hp_detect:1;
63 unsigned int mic_detect:1;
e5f14248
TI
64};
65
a6bae205
TI
66/* available models */
67enum {
68 CS420X_MBP55,
1a5ba2e9 69 CS420X_IMAC27,
a6bae205
TI
70 CS420X_AUTO,
71 CS420X_MODELS
72};
73
40c20fa0
TI
74/* Vendor-specific processing widget */
75#define CS420X_VENDOR_NID 0x11
76#define CS_DIG_OUT1_PIN_NID 0x10
77#define CS_DIG_OUT2_PIN_NID 0x15
78#define CS_DMIC1_PIN_NID 0x12
79#define CS_DMIC2_PIN_NID 0x0e
80
81/* coef indices */
82#define IDX_SPDIF_STAT 0x0000
83#define IDX_SPDIF_CTL 0x0001
84#define IDX_ADC_CFG 0x0002
85/* SZC bitmask, 4 modes below:
86 * 0 = immediate,
87 * 1 = digital immediate, analog zero-cross
88 * 2 = digtail & analog soft-ramp
89 * 3 = digital soft-ramp, analog zero-cross
90 */
91#define CS_COEF_ADC_SZC_MASK (3 << 0)
92#define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
93#define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
94/* PGA mode: 0 = differential, 1 = signle-ended */
95#define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
96#define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
97#define IDX_DAC_CFG 0x0003
98/* SZC bitmask, 4 modes below:
99 * 0 = Immediate
100 * 1 = zero-cross
101 * 2 = soft-ramp
102 * 3 = soft-ramp on zero-cross
103 */
104#define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
105#define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
106#define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
107
108#define IDX_BEEP_CFG 0x0004
109/* 0x0008 - test reg key */
110/* 0x0009 - 0x0014 -> 12 test regs */
111/* 0x0015 - visibility reg */
112
113
277a57c7 114static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
40c20fa0
TI
115{
116 snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
117 AC_VERB_SET_COEF_INDEX, idx);
118 return snd_hda_codec_read(codec, CS420X_VENDOR_NID, 0,
119 AC_VERB_GET_PROC_COEF, 0);
120}
121
277a57c7
TI
122static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
123 unsigned int coef)
40c20fa0
TI
124{
125 snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
126 AC_VERB_SET_COEF_INDEX, idx);
127 snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
128 AC_VERB_SET_PROC_COEF, coef);
129}
130
131
e5f14248
TI
132#define HP_EVENT 1
133#define MIC_EVENT 2
134
135/*
136 * PCM callbacks
137 */
138static int cs_playback_pcm_open(struct hda_pcm_stream *hinfo,
139 struct hda_codec *codec,
140 struct snd_pcm_substream *substream)
141{
142 struct cs_spec *spec = codec->spec;
143 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
144 hinfo);
145}
146
147static int cs_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
148 struct hda_codec *codec,
149 unsigned int stream_tag,
150 unsigned int format,
151 struct snd_pcm_substream *substream)
152{
153 struct cs_spec *spec = codec->spec;
154 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
155 stream_tag, format, substream);
156}
157
158static int cs_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 struct snd_pcm_substream *substream)
161{
162 struct cs_spec *spec = codec->spec;
163 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
164}
165
166/*
167 * Digital out
168 */
169static int cs_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
170 struct hda_codec *codec,
171 struct snd_pcm_substream *substream)
172{
173 struct cs_spec *spec = codec->spec;
174 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
175}
176
177static int cs_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
178 struct hda_codec *codec,
179 struct snd_pcm_substream *substream)
180{
181 struct cs_spec *spec = codec->spec;
182 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
183}
184
185static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
186 struct hda_codec *codec,
187 unsigned int stream_tag,
188 unsigned int format,
189 struct snd_pcm_substream *substream)
190{
191 struct cs_spec *spec = codec->spec;
192 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
193 format, substream);
194}
195
196static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
197 struct hda_codec *codec,
198 struct snd_pcm_substream *substream)
199{
200 struct cs_spec *spec = codec->spec;
201 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
202}
203
204/*
205 * Analog capture
206 */
207static int cs_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
208 struct hda_codec *codec,
209 unsigned int stream_tag,
210 unsigned int format,
211 struct snd_pcm_substream *substream)
212{
213 struct cs_spec *spec = codec->spec;
214 spec->cur_adc = spec->adc_nid[spec->cur_input];
215 spec->cur_adc_stream_tag = stream_tag;
216 spec->cur_adc_format = format;
217 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
218 return 0;
219}
220
221static int cs_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
222 struct hda_codec *codec,
223 struct snd_pcm_substream *substream)
224{
225 struct cs_spec *spec = codec->spec;
226 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
227 spec->cur_adc = 0;
228 return 0;
229}
230
231/*
232 */
233static struct hda_pcm_stream cs_pcm_analog_playback = {
234 .substreams = 1,
235 .channels_min = 2,
236 .channels_max = 2,
237 .ops = {
238 .open = cs_playback_pcm_open,
239 .prepare = cs_playback_pcm_prepare,
240 .cleanup = cs_playback_pcm_cleanup
241 },
242};
243
244static struct hda_pcm_stream cs_pcm_analog_capture = {
245 .substreams = 1,
246 .channels_min = 2,
247 .channels_max = 2,
248 .ops = {
249 .prepare = cs_capture_pcm_prepare,
250 .cleanup = cs_capture_pcm_cleanup
251 },
252};
253
254static struct hda_pcm_stream cs_pcm_digital_playback = {
255 .substreams = 1,
256 .channels_min = 2,
257 .channels_max = 2,
258 .ops = {
259 .open = cs_dig_playback_pcm_open,
260 .close = cs_dig_playback_pcm_close,
261 .prepare = cs_dig_playback_pcm_prepare,
262 .cleanup = cs_dig_playback_pcm_cleanup
263 },
264};
265
266static struct hda_pcm_stream cs_pcm_digital_capture = {
267 .substreams = 1,
268 .channels_min = 2,
269 .channels_max = 2,
270};
271
272static int cs_build_pcms(struct hda_codec *codec)
273{
274 struct cs_spec *spec = codec->spec;
275 struct hda_pcm *info = spec->pcm_rec;
276
277 codec->pcm_info = info;
278 codec->num_pcms = 0;
279
280 info->name = "Cirrus Analog";
281 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cs_pcm_analog_playback;
282 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0];
283 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
284 spec->multiout.max_channels;
285 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture;
e5f14248
TI
286 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
287 spec->adc_nid[spec->cur_input];
288 codec->num_pcms++;
289
290 if (!spec->multiout.dig_out_nid && !spec->dig_in)
291 return 0;
292
293 info++;
294 info->name = "Cirrus Digital";
295 info->pcm_type = spec->autocfg.dig_out_type[0];
296 if (!info->pcm_type)
297 info->pcm_type = HDA_PCM_TYPE_SPDIF;
298 if (spec->multiout.dig_out_nid) {
299 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
300 cs_pcm_digital_playback;
301 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
302 spec->multiout.dig_out_nid;
303 }
304 if (spec->dig_in) {
305 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
306 cs_pcm_digital_capture;
307 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
308 }
309 codec->num_pcms++;
310
311 return 0;
312}
313
21a4dc43
TI
314/*
315 * parse codec topology
316 */
317
e5f14248
TI
318static hda_nid_t get_dac(struct hda_codec *codec, hda_nid_t pin)
319{
320 hda_nid_t dac;
321 if (!pin)
322 return 0;
323 if (snd_hda_get_connections(codec, pin, &dac, 1) != 1)
324 return 0;
325 return dac;
326}
327
21a4dc43
TI
328static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
329{
330 struct cs_spec *spec = codec->spec;
331 struct auto_pin_cfg *cfg = &spec->autocfg;
c1e0bb92 332 hda_nid_t pin = cfg->inputs[idx].pin;
21a4dc43
TI
333 unsigned int val = snd_hda_query_pin_caps(codec, pin);
334 if (!(val & AC_PINCAP_PRES_DETECT))
335 return 0;
336 val = snd_hda_codec_get_pincfg(codec, pin);
337 return (get_defcfg_connect(val) == AC_JACK_PORT_COMPLEX);
338}
339
340static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
341 unsigned int *idxp)
342{
343 int i;
344 hda_nid_t nid;
345
346 nid = codec->start_nid;
347 for (i = 0; i < codec->num_nodes; i++, nid++) {
348 hda_nid_t pins[2];
349 unsigned int type;
350 int j, nums;
351 type = (get_wcaps(codec, nid) & AC_WCAP_TYPE)
352 >> AC_WCAP_TYPE_SHIFT;
353 if (type != AC_WID_AUD_IN)
354 continue;
355 nums = snd_hda_get_connections(codec, nid, pins,
356 ARRAY_SIZE(pins));
357 if (nums <= 0)
358 continue;
359 for (j = 0; j < nums; j++) {
360 if (pins[j] == pin) {
361 *idxp = j;
362 return nid;
363 }
364 }
365 }
366 return 0;
367}
368
40c20fa0
TI
369static int is_active_pin(struct hda_codec *codec, hda_nid_t nid)
370{
40c20fa0
TI
371 unsigned int val;
372 val = snd_hda_codec_get_pincfg(codec, nid);
373 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
374}
375
21a4dc43
TI
376static int parse_output(struct hda_codec *codec)
377{
378 struct cs_spec *spec = codec->spec;
379 struct auto_pin_cfg *cfg = &spec->autocfg;
277a57c7 380 int i, extra_nids;
21a4dc43
TI
381 hda_nid_t dac;
382
383 for (i = 0; i < cfg->line_outs; i++) {
384 dac = get_dac(codec, cfg->line_out_pins[i]);
385 if (!dac)
386 break;
387 spec->dac_nid[i] = dac;
388 }
389 spec->multiout.num_dacs = i;
390 spec->multiout.dac_nids = spec->dac_nid;
391 spec->multiout.max_channels = i * 2;
392
393 /* add HP and speakers */
394 extra_nids = 0;
395 for (i = 0; i < cfg->hp_outs; i++) {
396 dac = get_dac(codec, cfg->hp_pins[i]);
397 if (!dac)
398 break;
399 if (!i)
400 spec->multiout.hp_nid = dac;
401 else
402 spec->multiout.extra_out_nid[extra_nids++] = dac;
403 }
404 for (i = 0; i < cfg->speaker_outs; i++) {
405 dac = get_dac(codec, cfg->speaker_pins[i]);
406 if (!dac)
407 break;
408 spec->multiout.extra_out_nid[extra_nids++] = dac;
409 }
410
411 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
412 cfg->speaker_outs = cfg->line_outs;
413 memcpy(cfg->speaker_pins, cfg->line_out_pins,
414 sizeof(cfg->speaker_pins));
415 cfg->line_outs = 0;
416 }
417
418 return 0;
419}
420
421static int parse_input(struct hda_codec *codec)
422{
423 struct cs_spec *spec = codec->spec;
424 struct auto_pin_cfg *cfg = &spec->autocfg;
277a57c7 425 int i;
21a4dc43 426
c1e0bb92
TI
427 for (i = 0; i < cfg->num_inputs; i++) {
428 hda_nid_t pin = cfg->inputs[i].pin;
21a4dc43
TI
429 spec->input_idx[spec->num_inputs] = i;
430 spec->capsrc_idx[i] = spec->num_inputs++;
431 spec->cur_input = i;
432 spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]);
433 }
434 if (!spec->num_inputs)
435 return 0;
436
437 /* check whether the automatic mic switch is available */
438 if (spec->num_inputs == 2 &&
c1e0bb92
TI
439 cfg->inputs[0].type <= AUTO_PIN_FRONT_MIC &&
440 cfg->inputs[1].type == AUTO_PIN_FRONT_MIC) {
441 if (is_ext_mic(codec, cfg->inputs[0].pin)) {
442 if (!is_ext_mic(codec, cfg->inputs[1].pin)) {
21a4dc43 443 spec->mic_detect = 1;
c1e0bb92 444 spec->automic_idx = 0;
21a4dc43
TI
445 }
446 } else {
c1e0bb92 447 if (is_ext_mic(codec, cfg->inputs[1].pin)) {
21a4dc43 448 spec->mic_detect = 1;
c1e0bb92 449 spec->automic_idx = 1;
21a4dc43
TI
450 }
451 }
452 }
453 return 0;
454}
455
456
457static int parse_digital_output(struct hda_codec *codec)
458{
459 struct cs_spec *spec = codec->spec;
460 struct auto_pin_cfg *cfg = &spec->autocfg;
461 hda_nid_t nid;
21a4dc43
TI
462
463 if (!cfg->dig_outs)
464 return 0;
465 if (snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) < 1)
466 return 0;
467 spec->multiout.dig_out_nid = nid;
468 spec->multiout.share_spdif = 1;
469 if (cfg->dig_outs > 1 &&
470 snd_hda_get_connections(codec, cfg->dig_out_pins[1], &nid, 1) > 0) {
471 spec->slave_dig_outs[0] = nid;
472 codec->slave_dig_outs = spec->slave_dig_outs;
473 }
474 return 0;
475}
476
477static int parse_digital_input(struct hda_codec *codec)
478{
479 struct cs_spec *spec = codec->spec;
480 struct auto_pin_cfg *cfg = &spec->autocfg;
481 int idx;
482
60e53882
TI
483 if (cfg->dig_in_pin)
484 spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx);
485 return 0;
21a4dc43
TI
486}
487
488/*
489 * create mixer controls
490 */
491
e5f14248
TI
492static const char *dir_sfx[2] = { "Playback", "Capture" };
493
494static int add_mute(struct hda_codec *codec, const char *name, int index,
495 unsigned int pval, int dir, struct snd_kcontrol **kctlp)
496{
b4dabfc4 497 char tmp[44];
e5f14248
TI
498 struct snd_kcontrol_new knew =
499 HDA_CODEC_MUTE_IDX(tmp, index, 0, 0, HDA_OUTPUT);
500 knew.private_value = pval;
501 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]);
502 *kctlp = snd_ctl_new1(&knew, codec);
9e3fd871 503 (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
5e26dfd0 504 return snd_hda_ctl_add(codec, 0, *kctlp);
e5f14248
TI
505}
506
507static int add_volume(struct hda_codec *codec, const char *name,
508 int index, unsigned int pval, int dir,
509 struct snd_kcontrol **kctlp)
510{
511 char tmp[32];
512 struct snd_kcontrol_new knew =
513 HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT);
514 knew.private_value = pval;
515 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
516 *kctlp = snd_ctl_new1(&knew, codec);
9e3fd871 517 (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
5e26dfd0 518 return snd_hda_ctl_add(codec, 0, *kctlp);
e5f14248
TI
519}
520
521static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
522{
523 unsigned int caps;
524
525 /* set the upper-limit for mixer amp to 0dB */
526 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
527 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
528 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
529 << AC_AMPCAP_NUM_STEPS_SHIFT;
530 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
531}
532
533static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
534{
535 struct cs_spec *spec = codec->spec;
536 unsigned int tlv[4];
537 int err;
538
539 spec->vmaster_sw =
540 snd_ctl_make_virtual_master("Master Playback Switch", NULL);
3911a4c1 541 err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw);
e5f14248
TI
542 if (err < 0)
543 return err;
544
545 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
546 spec->vmaster_vol =
547 snd_ctl_make_virtual_master("Master Playback Volume", tlv);
3911a4c1 548 err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol);
e5f14248
TI
549 if (err < 0)
550 return err;
551 return 0;
552}
553
554static int add_output(struct hda_codec *codec, hda_nid_t dac, int idx,
555 int num_ctls, int type)
556{
557 struct cs_spec *spec = codec->spec;
558 const char *name;
559 int err, index;
560 struct snd_kcontrol *kctl;
561 static char *speakers[] = {
562 "Front Speaker", "Surround Speaker", "Bass Speaker"
563 };
564 static char *line_outs[] = {
565 "Front Line-Out", "Surround Line-Out", "Bass Line-Out"
566 };
567
568 fix_volume_caps(codec, dac);
569 if (!spec->vmaster_sw) {
570 err = add_vmaster(codec, dac);
571 if (err < 0)
572 return err;
573 }
574
575 index = 0;
576 switch (type) {
577 case AUTO_PIN_HP_OUT:
578 name = "Headphone";
579 index = idx;
580 break;
581 case AUTO_PIN_SPEAKER_OUT:
582 if (num_ctls > 1)
583 name = speakers[idx];
584 else
585 name = "Speaker";
586 break;
587 default:
588 if (num_ctls > 1)
589 name = line_outs[idx];
590 else
591 name = "Line-Out";
592 break;
593 }
594
595 err = add_mute(codec, name, index,
596 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
597 if (err < 0)
598 return err;
599 err = snd_ctl_add_slave(spec->vmaster_sw, kctl);
600 if (err < 0)
601 return err;
602
603 err = add_volume(codec, name, index,
604 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
605 if (err < 0)
606 return err;
607 err = snd_ctl_add_slave(spec->vmaster_vol, kctl);
608 if (err < 0)
609 return err;
610
611 return 0;
612}
613
614static int build_output(struct hda_codec *codec)
615{
616 struct cs_spec *spec = codec->spec;
617 struct auto_pin_cfg *cfg = &spec->autocfg;
21a4dc43 618 int i, err;
e5f14248
TI
619
620 for (i = 0; i < cfg->line_outs; i++) {
21a4dc43
TI
621 err = add_output(codec, get_dac(codec, cfg->line_out_pins[i]),
622 i, cfg->line_outs, cfg->line_out_type);
e5f14248
TI
623 if (err < 0)
624 return err;
625 }
e5f14248 626 for (i = 0; i < cfg->hp_outs; i++) {
21a4dc43
TI
627 err = add_output(codec, get_dac(codec, cfg->hp_pins[i]),
628 i, cfg->hp_outs, AUTO_PIN_HP_OUT);
e5f14248
TI
629 if (err < 0)
630 return err;
631 }
632 for (i = 0; i < cfg->speaker_outs; i++) {
21a4dc43
TI
633 err = add_output(codec, get_dac(codec, cfg->speaker_pins[i]),
634 i, cfg->speaker_outs, AUTO_PIN_SPEAKER_OUT);
e5f14248
TI
635 if (err < 0)
636 return err;
637 }
e5f14248
TI
638 return 0;
639}
640
641/*
642 */
643
644static struct snd_kcontrol_new cs_capture_ctls[] = {
645 HDA_BIND_SW("Capture Switch", 0),
646 HDA_BIND_VOL("Capture Volume", 0),
647};
648
ea35929b
TI
649static int change_cur_input(struct hda_codec *codec, unsigned int idx,
650 int force)
e5f14248
TI
651{
652 struct cs_spec *spec = codec->spec;
e5f14248 653
ea35929b 654 if (spec->cur_input == idx && !force)
e5f14248
TI
655 return 0;
656 if (spec->cur_adc && spec->cur_adc != spec->adc_nid[idx]) {
657 /* stream is running, let's swap the current ADC */
f0cea797 658 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
e5f14248
TI
659 spec->cur_adc = spec->adc_nid[idx];
660 snd_hda_codec_setup_stream(codec, spec->cur_adc,
661 spec->cur_adc_stream_tag, 0,
662 spec->cur_adc_format);
663 }
664 snd_hda_codec_write(codec, spec->cur_adc, 0,
665 AC_VERB_SET_CONNECT_SEL,
666 spec->adc_idx[idx]);
667 spec->cur_input = idx;
668 return 1;
669}
670
671static int cs_capture_source_info(struct snd_kcontrol *kcontrol,
672 struct snd_ctl_elem_info *uinfo)
673{
674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
675 struct cs_spec *spec = codec->spec;
676 unsigned int idx;
677
678 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
679 uinfo->count = 1;
680 uinfo->value.enumerated.items = spec->num_inputs;
681 if (uinfo->value.enumerated.item >= spec->num_inputs)
682 uinfo->value.enumerated.item = spec->num_inputs - 1;
683 idx = spec->input_idx[uinfo->value.enumerated.item];
684 strcpy(uinfo->value.enumerated.name, auto_pin_cfg_labels[idx]);
685 return 0;
686}
687
688static int cs_capture_source_get(struct snd_kcontrol *kcontrol,
689 struct snd_ctl_elem_value *ucontrol)
690{
691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
692 struct cs_spec *spec = codec->spec;
693 ucontrol->value.enumerated.item[0] = spec->capsrc_idx[spec->cur_input];
694 return 0;
695}
696
697static int cs_capture_source_put(struct snd_kcontrol *kcontrol,
698 struct snd_ctl_elem_value *ucontrol)
699{
700 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
701 struct cs_spec *spec = codec->spec;
702 unsigned int idx = ucontrol->value.enumerated.item[0];
703
704 if (idx >= spec->num_inputs)
705 return -EINVAL;
706 idx = spec->input_idx[idx];
ea35929b 707 return change_cur_input(codec, idx, 0);
e5f14248
TI
708}
709
710static struct snd_kcontrol_new cs_capture_source = {
711 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
712 .name = "Capture Source",
713 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
714 .info = cs_capture_source_info,
715 .get = cs_capture_source_get,
716 .put = cs_capture_source_put,
717};
718
e5f14248
TI
719static struct hda_bind_ctls *make_bind_capture(struct hda_codec *codec,
720 struct hda_ctl_ops *ops)
721{
722 struct cs_spec *spec = codec->spec;
723 struct hda_bind_ctls *bind;
724 int i, n;
725
726 bind = kzalloc(sizeof(*bind) + sizeof(long) * (spec->num_inputs + 1),
727 GFP_KERNEL);
728 if (!bind)
729 return NULL;
730 bind->ops = ops;
731 n = 0;
732 for (i = 0; i < AUTO_PIN_LAST; i++) {
733 if (!spec->adc_nid[i])
734 continue;
735 bind->values[n++] =
736 HDA_COMPOSE_AMP_VAL(spec->adc_nid[i], 3,
737 spec->adc_idx[i], HDA_INPUT);
738 }
739 return bind;
740}
741
742static int build_input(struct hda_codec *codec)
743{
744 struct cs_spec *spec = codec->spec;
21a4dc43 745 int i, err;
e5f14248 746
e5f14248
TI
747 if (!spec->num_inputs)
748 return 0;
749
e5f14248
TI
750 /* make bind-capture */
751 spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw);
752 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
753 for (i = 0; i < 2; i++) {
754 struct snd_kcontrol *kctl;
21949f00 755 int n;
e5f14248
TI
756 if (!spec->capture_bind[i])
757 return -ENOMEM;
758 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
759 if (!kctl)
760 return -ENOMEM;
761 kctl->private_value = (long)spec->capture_bind[i];
3911a4c1 762 err = snd_hda_ctl_add(codec, 0, kctl);
e5f14248
TI
763 if (err < 0)
764 return err;
21949f00
TI
765 for (n = 0; n < AUTO_PIN_LAST; n++) {
766 if (!spec->adc_nid[n])
767 continue;
8dd34ab1 768 err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]);
21949f00
TI
769 if (err < 0)
770 return err;
771 }
e5f14248
TI
772 }
773
774 if (spec->num_inputs > 1 && !spec->mic_detect) {
3911a4c1 775 err = snd_hda_ctl_add(codec, 0,
e5f14248
TI
776 snd_ctl_new1(&cs_capture_source, codec));
777 if (err < 0)
778 return err;
779 }
780
781 return 0;
782}
783
21a4dc43
TI
784/*
785 */
786
e5f14248
TI
787static int build_digital_output(struct hda_codec *codec)
788{
789 struct cs_spec *spec = codec->spec;
e5f14248
TI
790 int err;
791
63b2413b
TI
792 if (!spec->multiout.dig_out_nid)
793 return 0;
794
e5f14248
TI
795 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
796 if (err < 0)
797 return err;
798 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
799 if (err < 0)
800 return err;
e5f14248
TI
801 return 0;
802}
803
804static int build_digital_input(struct hda_codec *codec)
805{
806 struct cs_spec *spec = codec->spec;
21a4dc43
TI
807 if (spec->dig_in)
808 return snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
809 return 0;
e5f14248
TI
810}
811
21a4dc43
TI
812/*
813 * auto-mute and auto-mic switching
814 */
815
e5f14248
TI
816static void cs_automute(struct hda_codec *codec)
817{
818 struct cs_spec *spec = codec->spec;
819 struct auto_pin_cfg *cfg = &spec->autocfg;
864f92be 820 unsigned int caps, hp_present;
e5f14248
TI
821 hda_nid_t nid;
822 int i;
823
824 hp_present = 0;
825 for (i = 0; i < cfg->hp_outs; i++) {
826 nid = cfg->hp_pins[i];
827 caps = snd_hda_query_pin_caps(codec, nid);
828 if (!(caps & AC_PINCAP_PRES_DETECT))
829 continue;
864f92be 830 hp_present = snd_hda_jack_detect(codec, nid);
e5f14248
TI
831 if (hp_present)
832 break;
833 }
834 for (i = 0; i < cfg->speaker_outs; i++) {
835 nid = cfg->speaker_pins[i];
836 snd_hda_codec_write(codec, nid, 0,
837 AC_VERB_SET_PIN_WIDGET_CONTROL,
838 hp_present ? 0 : PIN_OUT);
839 }
1a5ba2e9
RAE
840 if (spec->board_config == CS420X_MBP55 ||
841 spec->board_config == CS420X_IMAC27) {
3a385167
SP
842 unsigned int gpio = hp_present ? 0x02 : 0x08;
843 snd_hda_codec_write(codec, 0x01, 0,
844 AC_VERB_SET_GPIO_DATA, gpio);
845 }
e5f14248
TI
846}
847
848static void cs_automic(struct hda_codec *codec)
849{
850 struct cs_spec *spec = codec->spec;
851 struct auto_pin_cfg *cfg = &spec->autocfg;
852 hda_nid_t nid;
864f92be 853 unsigned int present;
e5f14248 854
c1e0bb92 855 nid = cfg->inputs[spec->automic_idx].pin;
864f92be
WF
856 present = snd_hda_jack_detect(codec, nid);
857 if (present)
ea35929b 858 change_cur_input(codec, spec->automic_idx, 0);
c1e0bb92
TI
859 else
860 change_cur_input(codec, !spec->automic_idx, 0);
e5f14248
TI
861}
862
863/*
864 */
865
866static void init_output(struct hda_codec *codec)
867{
868 struct cs_spec *spec = codec->spec;
869 struct auto_pin_cfg *cfg = &spec->autocfg;
870 int i;
871
872 /* mute first */
873 for (i = 0; i < spec->multiout.num_dacs; i++)
874 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
875 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
876 if (spec->multiout.hp_nid)
877 snd_hda_codec_write(codec, spec->multiout.hp_nid, 0,
878 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
879 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
880 if (!spec->multiout.extra_out_nid[i])
881 break;
882 snd_hda_codec_write(codec, spec->multiout.extra_out_nid[i], 0,
883 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
884 }
885
886 /* set appropriate pin controls */
887 for (i = 0; i < cfg->line_outs; i++)
888 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
889 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
890 for (i = 0; i < cfg->hp_outs; i++) {
891 hda_nid_t nid = cfg->hp_pins[i];
892 snd_hda_codec_write(codec, nid, 0,
893 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
894 if (!cfg->speaker_outs)
895 continue;
896 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
897 snd_hda_codec_write(codec, nid, 0,
898 AC_VERB_SET_UNSOLICITED_ENABLE,
899 AC_USRSP_EN | HP_EVENT);
900 spec->hp_detect = 1;
901 }
902 }
903 for (i = 0; i < cfg->speaker_outs; i++)
904 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
905 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
906 if (spec->hp_detect)
907 cs_automute(codec);
908}
909
910static void init_input(struct hda_codec *codec)
911{
912 struct cs_spec *spec = codec->spec;
913 struct auto_pin_cfg *cfg = &spec->autocfg;
40c20fa0 914 unsigned int coef;
e5f14248
TI
915 int i;
916
c1e0bb92 917 for (i = 0; i < cfg->num_inputs; i++) {
e5f14248 918 unsigned int ctl;
c1e0bb92
TI
919 hda_nid_t pin = cfg->inputs[i].pin;
920 if (!spec->adc_nid[i])
e5f14248
TI
921 continue;
922 /* set appropriate pin control and mute first */
923 ctl = PIN_IN;
c1e0bb92 924 if (cfg->inputs[i].type <= AUTO_PIN_FRONT_MIC) {
e5f14248
TI
925 unsigned int caps = snd_hda_query_pin_caps(codec, pin);
926 caps >>= AC_PINCAP_VREF_SHIFT;
927 if (caps & AC_PINCAP_VREF_80)
928 ctl = PIN_VREF80;
929 }
930 snd_hda_codec_write(codec, pin, 0,
931 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
932 snd_hda_codec_write(codec, spec->adc_nid[i], 0,
933 AC_VERB_SET_AMP_GAIN_MUTE,
934 AMP_IN_MUTE(spec->adc_idx[i]));
935 if (spec->mic_detect && spec->automic_idx == i)
936 snd_hda_codec_write(codec, pin, 0,
937 AC_VERB_SET_UNSOLICITED_ENABLE,
938 AC_USRSP_EN | MIC_EVENT);
939 }
ea35929b 940 change_cur_input(codec, spec->cur_input, 1);
e5f14248
TI
941 if (spec->mic_detect)
942 cs_automic(codec);
40c20fa0
TI
943
944 coef = 0x000a; /* ADC1/2 - Digital and Analog Soft Ramp */
945 if (is_active_pin(codec, CS_DMIC2_PIN_NID))
946 coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */
947 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
948 coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0
b71a8eb0 949 * No effect if SPDIF_OUT2 is selected in
40c20fa0
TI
950 * IDX_SPDIF_CTL.
951 */
952 cs_vendor_coef_set(codec, IDX_ADC_CFG, coef);
953}
954
955static struct hda_verb cs_coef_init_verbs[] = {
956 {0x11, AC_VERB_SET_PROC_STATE, 1},
957 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
958 {0x11, AC_VERB_SET_PROC_COEF,
959 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
960 | 0x0040 /* Mute DACs on FIFO error */
961 | 0x1000 /* Enable DACs High Pass Filter */
962 | 0x0400 /* Disable Coefficient Auto increment */
963 )},
964 /* Beep */
965 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
966 {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */
967
968 {} /* terminator */
969};
970
a769cbcf
BA
971/* Errata: CS4207 rev C0/C1/C2 Silicon
972 *
973 * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
974 *
975 * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
976 * may be excessive (up to an additional 200 μA), which is most easily
977 * observed while the part is being held in reset (RESET# active low).
978 *
979 * Root Cause: At initial powerup of the device, the logic that drives
980 * the clock and write enable to the S/PDIF SRC RAMs is not properly
981 * initialized.
982 * Certain random patterns will cause a steady leakage current in those
983 * RAM cells. The issue will resolve once the SRCs are used (turned on).
984 *
985 * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
986 * blocks, which will alleviate the issue.
987 */
988
989static struct hda_verb cs_errata_init_verbs[] = {
990 {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
991 {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
992
993 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
994 {0x11, AC_VERB_SET_PROC_COEF, 0x9999},
995 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
996 {0x11, AC_VERB_SET_PROC_COEF, 0xa412},
997 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
998 {0x11, AC_VERB_SET_PROC_COEF, 0x0009},
999
1000 {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */
1001 {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */
1002
1003 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
1004 {0x11, AC_VERB_SET_PROC_COEF, 0x2412},
1005 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
1006 {0x11, AC_VERB_SET_PROC_COEF, 0x0000},
1007 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
1008 {0x11, AC_VERB_SET_PROC_COEF, 0x0008},
1009 {0x11, AC_VERB_SET_PROC_STATE, 0x00},
1010
1011 {0x07, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Rx: D3 */
1012 {0x08, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Tx: D3 */
1013 /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */
1014
1015 {} /* terminator */
1016};
1017
40c20fa0
TI
1018/* SPDIF setup */
1019static void init_digital(struct hda_codec *codec)
1020{
1021 unsigned int coef;
1022
1023 coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
1024 coef |= 0x0008; /* Replace with mute on error */
1025 if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID))
1026 coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
1027 * SPDIF_OUT2 is shared with GPIO1 and
1028 * DMIC_SDA2.
1029 */
1030 cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef);
e5f14248
TI
1031}
1032
1033static int cs_init(struct hda_codec *codec)
1034{
1035 struct cs_spec *spec = codec->spec;
1036
a769cbcf
BA
1037 /* init_verb sequence for C0/C1/C2 errata*/
1038 snd_hda_sequence_write(codec, cs_errata_init_verbs);
1039
40c20fa0 1040 snd_hda_sequence_write(codec, cs_coef_init_verbs);
ed208255
TI
1041
1042 if (spec->gpio_mask) {
1043 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
1044 spec->gpio_mask);
1045 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
1046 spec->gpio_dir);
1047 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1048 spec->gpio_data);
1049 }
1050
e5f14248
TI
1051 init_output(codec);
1052 init_input(codec);
40c20fa0 1053 init_digital(codec);
e5f14248
TI
1054 return 0;
1055}
1056
1057static int cs_build_controls(struct hda_codec *codec)
1058{
e5f14248
TI
1059 int err;
1060
1061 err = build_output(codec);
1062 if (err < 0)
1063 return err;
1064 err = build_input(codec);
1065 if (err < 0)
1066 return err;
1067 err = build_digital_output(codec);
1068 if (err < 0)
1069 return err;
1070 err = build_digital_input(codec);
1071 if (err < 0)
1072 return err;
e5f14248
TI
1073 return cs_init(codec);
1074}
1075
1076static void cs_free(struct hda_codec *codec)
1077{
1078 struct cs_spec *spec = codec->spec;
1079 kfree(spec->capture_bind[0]);
1080 kfree(spec->capture_bind[1]);
1081 kfree(codec->spec);
1082}
1083
1084static void cs_unsol_event(struct hda_codec *codec, unsigned int res)
1085{
1086 switch ((res >> 26) & 0x7f) {
1087 case HP_EVENT:
1088 cs_automute(codec);
1089 break;
1090 case MIC_EVENT:
1091 cs_automic(codec);
1092 break;
1093 }
1094}
1095
1096static struct hda_codec_ops cs_patch_ops = {
1097 .build_controls = cs_build_controls,
1098 .build_pcms = cs_build_pcms,
1099 .init = cs_init,
1100 .free = cs_free,
1101 .unsol_event = cs_unsol_event,
1102};
1103
1104static int cs_parse_auto_config(struct hda_codec *codec)
1105{
1106 struct cs_spec *spec = codec->spec;
1107 int err;
1108
1109 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
ed208255
TI
1110 if (err < 0)
1111 return err;
1112
1113 err = parse_output(codec);
1114 if (err < 0)
1115 return err;
1116 err = parse_input(codec);
1117 if (err < 0)
1118 return err;
1119 err = parse_digital_output(codec);
1120 if (err < 0)
1121 return err;
1122 err = parse_digital_input(codec);
e5f14248
TI
1123 if (err < 0)
1124 return err;
1125 return 0;
1126}
1127
a6bae205
TI
1128static const char *cs420x_models[CS420X_MODELS] = {
1129 [CS420X_MBP55] = "mbp55",
1a5ba2e9 1130 [CS420X_IMAC27] = "imac27",
a6bae205
TI
1131 [CS420X_AUTO] = "auto",
1132};
1133
1134
1135static struct snd_pci_quirk cs420x_cfg_tbl[] = {
1136 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
1a5ba2e9 1137 SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),
a6bae205
TI
1138 {} /* terminator */
1139};
1140
1141struct cs_pincfg {
1142 hda_nid_t nid;
1143 u32 val;
1144};
1145
1146static struct cs_pincfg mbp55_pincfgs[] = {
1147 { 0x09, 0x012b4030 },
1148 { 0x0a, 0x90100121 },
1149 { 0x0b, 0x90100120 },
1150 { 0x0c, 0x400000f0 },
1151 { 0x0d, 0x90a00110 },
1152 { 0x0e, 0x400000f0 },
1153 { 0x0f, 0x400000f0 },
1154 { 0x10, 0x014be040 },
1155 { 0x12, 0x400000f0 },
1156 { 0x15, 0x400000f0 },
1157 {} /* terminator */
1158};
1159
1a5ba2e9
RAE
1160static struct cs_pincfg imac27_pincfgs[] = {
1161 { 0x09, 0x012b4050 },
1162 { 0x0a, 0x90100140 },
1163 { 0x0b, 0x90100142 },
1164 { 0x0c, 0x018b3020 },
1165 { 0x0d, 0x90a00110 },
1166 { 0x0e, 0x400000f0 },
1167 { 0x0f, 0x01cbe030 },
1168 { 0x10, 0x014be060 },
1169 { 0x12, 0x01ab9070 },
1170 { 0x15, 0x400000f0 },
1171 {} /* terminator */
1172};
1173
a6bae205
TI
1174static struct cs_pincfg *cs_pincfgs[CS420X_MODELS] = {
1175 [CS420X_MBP55] = mbp55_pincfgs,
1a5ba2e9 1176 [CS420X_IMAC27] = imac27_pincfgs,
a6bae205
TI
1177};
1178
1179static void fix_pincfg(struct hda_codec *codec, int model)
1180{
1181 const struct cs_pincfg *cfg = cs_pincfgs[model];
1182 if (!cfg)
1183 return;
1184 for (; cfg->nid; cfg++)
1185 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1186}
1187
e5f14248
TI
1188
1189static int patch_cs420x(struct hda_codec *codec)
1190{
1191 struct cs_spec *spec;
1192 int err;
1193
1194 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1195 if (!spec)
1196 return -ENOMEM;
1197 codec->spec = spec;
1198
a6bae205
TI
1199 spec->board_config =
1200 snd_hda_check_board_config(codec, CS420X_MODELS,
1201 cs420x_models, cs420x_cfg_tbl);
1202 if (spec->board_config >= 0)
1203 fix_pincfg(codec, spec->board_config);
1204
ed208255 1205 switch (spec->board_config) {
1a5ba2e9 1206 case CS420X_IMAC27:
ed208255 1207 case CS420X_MBP55:
3a385167
SP
1208 /* GPIO1 = headphones */
1209 /* GPIO3 = speakers */
1210 spec->gpio_mask = 0x0a;
1211 spec->gpio_dir = 0x0a;
ed208255
TI
1212 break;
1213 }
e5f14248 1214
ed208255 1215 err = cs_parse_auto_config(codec);
21a4dc43
TI
1216 if (err < 0)
1217 goto error;
1218
e5f14248
TI
1219 codec->patch_ops = cs_patch_ops;
1220
1221 return 0;
1222
1223 error:
1224 kfree(codec->spec);
1225 codec->spec = NULL;
1226 return err;
1227}
1228
1229
1230/*
1231 * patch entries
1232 */
1233static struct hda_codec_preset snd_hda_preset_cirrus[] = {
1234 { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x },
1235 { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x },
1236 {} /* terminator */
1237};
1238
1239MODULE_ALIAS("snd-hda-codec-id:10134206");
1240MODULE_ALIAS("snd-hda-codec-id:10134207");
1241
1242MODULE_LICENSE("GPL");
1243MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1244
1245static struct hda_codec_preset_list cirrus_list = {
1246 .preset = snd_hda_preset_cirrus,
1247 .owner = THIS_MODULE,
1248};
1249
1250static int __init patch_cirrus_init(void)
1251{
1252 return snd_hda_add_codec_preset(&cirrus_list);
1253}
1254
1255static void __exit patch_cirrus_exit(void)
1256{
1257 snd_hda_delete_codec_preset(&cirrus_list);
1258}
1259
1260module_init(patch_cirrus_init)
1261module_exit(patch_cirrus_exit)