blob: 3db724eaa53c1e154cb550b52bb0e245b2eca2e4 [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>
Takashi Iwaie5f14242009-07-01 18:11:44 +020022#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040023#include <linux/module.h>
Takashi Iwaie5f14242009-07-01 18:11:44 +020024#include <sound/core.h>
Takashi Iwai1077a022012-12-19 16:39:18 +010025#include <sound/tlv.h>
Takashi Iwaie5f14242009-07-01 18:11:44 +020026#include "hda_codec.h"
27#include "hda_local.h"
Takashi Iwai128bc4b2012-05-07 17:42:31 +020028#include "hda_auto_parser.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020029#include "hda_jack.h"
Takashi Iwai1077a022012-12-19 16:39:18 +010030#include "hda_generic.h"
Takashi Iwaie5f14242009-07-01 18:11:44 +020031
32/*
33 */
34
35struct cs_spec {
Takashi Iwai1077a022012-12-19 16:39:18 +010036 struct hda_gen_spec gen;
Takashi Iwaie5f14242009-07-01 18:11:44 +020037
Takashi Iwaied208252009-07-07 09:04:26 +020038 unsigned int gpio_mask;
39 unsigned int gpio_dir;
40 unsigned int gpio_data;
Takashi Iwai6dfeb7032011-11-22 20:00:31 +010041 unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */
42 unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */
Takashi Iwaied208252009-07-07 09:04:26 +020043
Tim Howe56487c22011-07-22 16:41:00 -050044 /* CS421x */
45 unsigned int spdif_detect:1;
Takashi Iwai1077a022012-12-19 16:39:18 +010046 unsigned int spdif_present:1;
Tim Howe56487c22011-07-22 16:41:00 -050047 unsigned int sense_b:1;
48 hda_nid_t vendor_nid;
Takashi Iwai0c52db82013-11-08 13:03:57 +010049
50 /* for MBP SPDIF control */
51 int (*spdif_sw_put)(struct snd_kcontrol *kcontrol,
52 struct snd_ctl_elem_value *ucontrol);
Takashi Iwaie5f14242009-07-01 18:11:44 +020053};
54
Tim Howe56487c22011-07-22 16:41:00 -050055/* available models with CS420x */
Takashi Iwaia6bae202009-07-06 15:15:22 +020056enum {
Vince Weaver4e7d7c62010-09-22 17:31:37 -040057 CS420X_MBP53,
Takashi Iwaia6bae202009-07-06 15:15:22 +020058 CS420X_MBP55,
Rafael Avila de Espindola1a5ba2e2009-12-22 07:59:37 +010059 CS420X_IMAC27,
Takashi Iwaib35aabd2012-08-24 19:09:45 +020060 CS420X_GPIO_13,
61 CS420X_GPIO_23,
Takashi Iwaief596a52012-09-11 16:53:08 +020062 CS420X_MBP101,
Takashi Iwaiffe4d12b2012-11-23 08:34:13 +010063 CS420X_MBP81,
Takashi Iwai6ab982e2013-06-17 10:19:49 +020064 CS420X_MBA42,
Takashi Iwaia6bae202009-07-06 15:15:22 +020065 CS420X_AUTO,
Takashi Iwai03efce72012-09-13 09:56:57 +020066 /* aliases */
67 CS420X_IMAC27_122 = CS420X_GPIO_23,
68 CS420X_APPLE = CS420X_GPIO_13,
Takashi Iwaia6bae202009-07-06 15:15:22 +020069};
70
Tim Howe56487c22011-07-22 16:41:00 -050071/* CS421x boards */
72enum {
73 CS421X_CDB4210,
Takashi Iwaib35aabd2012-08-24 19:09:45 +020074 CS421X_SENSE_B,
Dylan Reid4af161072013-04-04 15:35:31 -070075 CS421X_STUMPY,
Tim Howe56487c22011-07-22 16:41:00 -050076};
77
Takashi Iwai40c20fa2009-07-06 13:00:57 +020078/* Vendor-specific processing widget */
79#define CS420X_VENDOR_NID 0x11
80#define CS_DIG_OUT1_PIN_NID 0x10
81#define CS_DIG_OUT2_PIN_NID 0x15
Daniel J Blueman16337e02012-11-04 13:19:03 +080082#define CS_DMIC1_PIN_NID 0x0e
83#define CS_DMIC2_PIN_NID 0x12
Takashi Iwai40c20fa2009-07-06 13:00:57 +020084
85/* coef indices */
86#define IDX_SPDIF_STAT 0x0000
87#define IDX_SPDIF_CTL 0x0001
88#define IDX_ADC_CFG 0x0002
89/* SZC bitmask, 4 modes below:
90 * 0 = immediate,
91 * 1 = digital immediate, analog zero-cross
92 * 2 = digtail & analog soft-ramp
93 * 3 = digital soft-ramp, analog zero-cross
94 */
95#define CS_COEF_ADC_SZC_MASK (3 << 0)
96#define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
97#define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
98/* PGA mode: 0 = differential, 1 = signle-ended */
99#define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
100#define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
101#define IDX_DAC_CFG 0x0003
102/* SZC bitmask, 4 modes below:
103 * 0 = Immediate
104 * 1 = zero-cross
105 * 2 = soft-ramp
106 * 3 = soft-ramp on zero-cross
107 */
108#define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
109#define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
110#define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
111
112#define IDX_BEEP_CFG 0x0004
113/* 0x0008 - test reg key */
114/* 0x0009 - 0x0014 -> 12 test regs */
115/* 0x0015 - visibility reg */
116
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200117/* Cirrus Logic CS4208 */
118#define CS4208_VENDOR_NID 0x24
119
Tim Howe56487c22011-07-22 16:41:00 -0500120/*
121 * Cirrus Logic CS4210
122 *
123 * 1 DAC => HP(sense) / Speakers,
124 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
125 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
126*/
127#define CS4210_DAC_NID 0x02
128#define CS4210_ADC_NID 0x03
David Henningsson5660ffd2012-01-02 12:40:17 +0100129#define CS4210_VENDOR_NID 0x0B
Tim Howe56487c22011-07-22 16:41:00 -0500130#define CS421X_DMIC_PIN_NID 0x09 /* Port E */
131#define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
132
133#define CS421X_IDX_DEV_CFG 0x01
134#define CS421X_IDX_ADC_CFG 0x02
135#define CS421X_IDX_DAC_CFG 0x03
136#define CS421X_IDX_SPK_CTL 0x04
137
138#define SPDIF_EVENT 0x04
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200139
David Henningsson5660ffd2012-01-02 12:40:17 +0100140/* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */
141#define CS4213_VENDOR_NID 0x09
142
143
Takashi Iwai277a57c2009-07-08 12:42:08 +0200144static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200145{
Tim Howe56487c22011-07-22 16:41:00 -0500146 struct cs_spec *spec = codec->spec;
147 snd_hda_codec_write(codec, spec->vendor_nid, 0,
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200148 AC_VERB_SET_COEF_INDEX, idx);
Tim Howe56487c22011-07-22 16:41:00 -0500149 return snd_hda_codec_read(codec, spec->vendor_nid, 0,
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200150 AC_VERB_GET_PROC_COEF, 0);
151}
152
Takashi Iwai277a57c2009-07-08 12:42:08 +0200153static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
154 unsigned int coef)
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200155{
Tim Howe56487c22011-07-22 16:41:00 -0500156 struct cs_spec *spec = codec->spec;
157 snd_hda_codec_write(codec, spec->vendor_nid, 0,
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200158 AC_VERB_SET_COEF_INDEX, idx);
Tim Howe56487c22011-07-22 16:41:00 -0500159 snd_hda_codec_write(codec, spec->vendor_nid, 0,
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200160 AC_VERB_SET_PROC_COEF, coef);
161}
162
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200163/*
164 * auto-mute and auto-mic switching
Tim Howe56487c22011-07-22 16:41:00 -0500165 * CS421x auto-output redirecting
166 * HP/SPK/SPDIF
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200167 */
168
Takashi Iwai1077a022012-12-19 16:39:18 +0100169static void cs_automute(struct hda_codec *codec)
Takashi Iwaie5f14242009-07-01 18:11:44 +0200170{
171 struct cs_spec *spec = codec->spec;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200172
Takashi Iwai1077a022012-12-19 16:39:18 +0100173 /* mute HPs if spdif jack (SENSE_B) is present */
174 spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b);
Tim Howe56487c22011-07-22 16:41:00 -0500175
Takashi Iwai1077a022012-12-19 16:39:18 +0100176 snd_hda_gen_update_outputs(codec);
Tim Howe56487c22011-07-22 16:41:00 -0500177
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200178 if (spec->gpio_eapd_hp || spec->gpio_eapd_speaker) {
Takashi Iwai039eb752013-03-18 16:55:49 +0100179 spec->gpio_data = spec->gen.hp_jack_present ?
Takashi Iwai6dfeb7032011-11-22 20:00:31 +0100180 spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
Stelian Pop3a385162009-07-30 14:44:27 +0200181 snd_hda_codec_write(codec, 0x01, 0,
Takashi Iwai039eb752013-03-18 16:55:49 +0100182 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Stelian Pop3a385162009-07-30 14:44:27 +0200183 }
Takashi Iwaie5f14242009-07-01 18:11:44 +0200184}
185
Takashi Iwai1077a022012-12-19 16:39:18 +0100186static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie5f14242009-07-01 18:11:44 +0200187{
Takashi Iwai1077a022012-12-19 16:39:18 +0100188 unsigned int val;
189 val = snd_hda_codec_get_pincfg(codec, nid);
190 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200191}
192
Takashi Iwai1077a022012-12-19 16:39:18 +0100193static void init_input_coef(struct hda_codec *codec)
Takashi Iwaie5f14242009-07-01 18:11:44 +0200194{
195 struct cs_spec *spec = codec->spec;
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200196 unsigned int coef;
Takashi Iwaie5f14242009-07-01 18:11:44 +0200197
David Henningsson5660ffd2012-01-02 12:40:17 +0100198 /* CS420x has multiple ADC, CS421x has single ADC */
199 if (spec->vendor_nid == CS420X_VENDOR_NID) {
Daniel J Blueman16337e02012-11-04 13:19:03 +0800200 coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG);
Tim Howe56487c22011-07-22 16:41:00 -0500201 if (is_active_pin(codec, CS_DMIC2_PIN_NID))
Daniel J Blueman16337e02012-11-04 13:19:03 +0800202 coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */
Tim Howe56487c22011-07-22 16:41:00 -0500203 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
Daniel J Blueman16337e02012-11-04 13:19:03 +0800204 coef |= 1 << 3; /* DMIC1 2 chan on, GPIO0 off
Tim Howe56487c22011-07-22 16:41:00 -0500205 * No effect if SPDIF_OUT2 is
206 * selected in IDX_SPDIF_CTL.
207 */
Daniel J Blueman16337e02012-11-04 13:19:03 +0800208
209 cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef);
Tim Howe56487c22011-07-22 16:41:00 -0500210 }
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200211}
212
Takashi Iwaic42d4782011-05-02 11:36:09 +0200213static const struct hda_verb cs_coef_init_verbs[] = {
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200214 {0x11, AC_VERB_SET_PROC_STATE, 1},
215 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
216 {0x11, AC_VERB_SET_PROC_COEF,
217 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
218 | 0x0040 /* Mute DACs on FIFO error */
219 | 0x1000 /* Enable DACs High Pass Filter */
220 | 0x0400 /* Disable Coefficient Auto increment */
221 )},
Takashi Iwai829e87e2012-11-23 08:25:25 +0100222 /* ADC1/2 - Digital and Analog Soft Ramp */
223 {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
224 {0x11, AC_VERB_SET_PROC_COEF, 0x000a},
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200225 /* Beep */
Alexander Stein5a83b4b2012-11-01 13:42:37 +0100226 {0x11, AC_VERB_SET_COEF_INDEX, IDX_BEEP_CFG},
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200227 {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */
228
229 {} /* terminator */
230};
231
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200232static const struct hda_verb cs4208_coef_init_verbs[] = {
233 {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
234 {0x24, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
235 {0x24, AC_VERB_SET_COEF_INDEX, 0x0033},
236 {0x24, AC_VERB_SET_PROC_COEF, 0x0001}, /* A1 ICS */
237 {0x24, AC_VERB_SET_COEF_INDEX, 0x0034},
238 {0x24, AC_VERB_SET_PROC_COEF, 0x1C01}, /* A1 Enable, A Thresh = 300mV */
239 {} /* terminator */
240};
241
Brian Austina769cbc2010-09-07 14:36:22 -0500242/* Errata: CS4207 rev C0/C1/C2 Silicon
243 *
244 * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
245 *
246 * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
247 * may be excessive (up to an additional 200 μA), which is most easily
248 * observed while the part is being held in reset (RESET# active low).
249 *
250 * Root Cause: At initial powerup of the device, the logic that drives
251 * the clock and write enable to the S/PDIF SRC RAMs is not properly
252 * initialized.
253 * Certain random patterns will cause a steady leakage current in those
254 * RAM cells. The issue will resolve once the SRCs are used (turned on).
255 *
256 * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
257 * blocks, which will alleviate the issue.
258 */
259
Takashi Iwaic42d4782011-05-02 11:36:09 +0200260static const struct hda_verb cs_errata_init_verbs[] = {
Brian Austina769cbc2010-09-07 14:36:22 -0500261 {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
262 {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
263
264 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
265 {0x11, AC_VERB_SET_PROC_COEF, 0x9999},
266 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
267 {0x11, AC_VERB_SET_PROC_COEF, 0xa412},
268 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
269 {0x11, AC_VERB_SET_PROC_COEF, 0x0009},
270
271 {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */
272 {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */
273
274 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
275 {0x11, AC_VERB_SET_PROC_COEF, 0x2412},
276 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
277 {0x11, AC_VERB_SET_PROC_COEF, 0x0000},
278 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
279 {0x11, AC_VERB_SET_PROC_COEF, 0x0008},
280 {0x11, AC_VERB_SET_PROC_STATE, 0x00},
281
Takashi Iwai38c07642011-03-03 14:54:19 +0100282#if 0 /* Don't to set to D3 as we are in power-up sequence */
Brian Austina769cbc2010-09-07 14:36:22 -0500283 {0x07, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Rx: D3 */
284 {0x08, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Tx: D3 */
285 /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */
Takashi Iwai38c07642011-03-03 14:54:19 +0100286#endif
Brian Austina769cbc2010-09-07 14:36:22 -0500287
288 {} /* terminator */
289};
290
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200291/* SPDIF setup */
Takashi Iwai1077a022012-12-19 16:39:18 +0100292static void init_digital_coef(struct hda_codec *codec)
Takashi Iwai40c20fa2009-07-06 13:00:57 +0200293{
294 unsigned int coef;
295
296 coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
297 coef |= 0x0008; /* Replace with mute on error */
298 if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID))
299 coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
300 * SPDIF_OUT2 is shared with GPIO1 and
301 * DMIC_SDA2.
302 */
303 cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200304}
305
306static int cs_init(struct hda_codec *codec)
307{
308 struct cs_spec *spec = codec->spec;
309
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200310 if (spec->vendor_nid == CS420X_VENDOR_NID) {
311 /* init_verb sequence for C0/C1/C2 errata*/
312 snd_hda_sequence_write(codec, cs_errata_init_verbs);
313 snd_hda_sequence_write(codec, cs_coef_init_verbs);
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200314 } else if (spec->vendor_nid == CS4208_VENDOR_NID) {
315 snd_hda_sequence_write(codec, cs4208_coef_init_verbs);
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200316 }
Takashi Iwaied208252009-07-07 09:04:26 +0200317
Takashi Iwai1077a022012-12-19 16:39:18 +0100318 snd_hda_gen_init(codec);
Takashi Iwai98415ea2012-11-23 08:26:58 +0100319
Takashi Iwaied208252009-07-07 09:04:26 +0200320 if (spec->gpio_mask) {
321 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
322 spec->gpio_mask);
323 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
324 spec->gpio_dir);
325 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
326 spec->gpio_data);
327 }
328
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200329 if (spec->vendor_nid == CS420X_VENDOR_NID) {
330 init_input_coef(codec);
331 init_digital_coef(codec);
332 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200333
Takashi Iwaie5f14242009-07-01 18:11:44 +0200334 return 0;
335}
336
Takashi Iwai0c52db82013-11-08 13:03:57 +0100337static int cs_build_controls(struct hda_codec *codec)
338{
339 int err;
340
341 err = snd_hda_gen_build_controls(codec);
342 if (err < 0)
343 return err;
344 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
345 return 0;
346}
347
Takashi Iwai1077a022012-12-19 16:39:18 +0100348#define cs_free snd_hda_gen_free
Takashi Iwaie5f14242009-07-01 18:11:44 +0200349
Takashi Iwaic42d4782011-05-02 11:36:09 +0200350static const struct hda_codec_ops cs_patch_ops = {
Takashi Iwai0c52db82013-11-08 13:03:57 +0100351 .build_controls = cs_build_controls,
Takashi Iwai1077a022012-12-19 16:39:18 +0100352 .build_pcms = snd_hda_gen_build_pcms,
Takashi Iwaie5f14242009-07-01 18:11:44 +0200353 .init = cs_init,
354 .free = cs_free,
David Henningsson5c2e4e02012-10-08 15:44:15 +0200355 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwaie5f14242009-07-01 18:11:44 +0200356};
357
358static int cs_parse_auto_config(struct hda_codec *codec)
359{
360 struct cs_spec *spec = codec->spec;
361 int err;
362
Takashi Iwai1077a022012-12-19 16:39:18 +0100363 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200364 if (err < 0)
365 return err;
Takashi Iwaied208252009-07-07 09:04:26 +0200366
Takashi Iwai1077a022012-12-19 16:39:18 +0100367 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
Takashi Iwaied208252009-07-07 09:04:26 +0200368 if (err < 0)
369 return err;
Takashi Iwai1077a022012-12-19 16:39:18 +0100370
Takashi Iwaie5f14242009-07-01 18:11:44 +0200371 return 0;
372}
373
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200374static const struct hda_model_fixup cs420x_models[] = {
375 { .id = CS420X_MBP53, .name = "mbp53" },
376 { .id = CS420X_MBP55, .name = "mbp55" },
377 { .id = CS420X_IMAC27, .name = "imac27" },
378 { .id = CS420X_IMAC27_122, .name = "imac27_122" },
379 { .id = CS420X_APPLE, .name = "apple" },
Takashi Iwaief596a52012-09-11 16:53:08 +0200380 { .id = CS420X_MBP101, .name = "mbp101" },
Takashi Iwaiffe4d12b2012-11-23 08:34:13 +0100381 { .id = CS420X_MBP81, .name = "mbp81" },
Takashi Iwai6ab982e2013-06-17 10:19:49 +0200382 { .id = CS420X_MBA42, .name = "mba42" },
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200383 {}
Takashi Iwaia6bae202009-07-06 15:15:22 +0200384};
385
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200386static const struct snd_pci_quirk cs420x_fixup_tbl[] = {
Vince Weaver4e7d7c62010-09-22 17:31:37 -0400387 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53),
Edgar (gimli) Hucek87232dd2010-11-03 08:14:10 +0100388 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55),
Takashi Iwaia6bae202009-07-06 15:15:22 +0200389 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
Takashi Iwaif46119b2010-10-11 14:46:35 +0200390 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55),
Takashi Iwai6dfeb7032011-11-22 20:00:31 +0100391 /* this conflicts with too many other models */
392 /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/
Takashi Iwai6dfeb7032011-11-22 20:00:31 +0100393
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200394 /* codec SSID */
Takashi Iwaiffe4d12b2012-11-23 08:34:13 +0100395 SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81),
Jérémy Lal7e5bea12012-01-09 17:19:45 +0100396 SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122),
Takashi Iwaief596a52012-09-11 16:53:08 +0200397 SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101),
Takashi Iwai6ab982e2013-06-17 10:19:49 +0200398 SND_PCI_QUIRK(0x106b, 0x5b00, "MacBookAir 4,2", CS420X_MBA42),
Takashi Iwai6dfeb7032011-11-22 20:00:31 +0100399 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE),
Takashi Iwaia6bae202009-07-06 15:15:22 +0200400 {} /* terminator */
401};
402
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200403static const struct hda_pintbl mbp53_pincfgs[] = {
Vince Weaver4e7d7c62010-09-22 17:31:37 -0400404 { 0x09, 0x012b4050 },
405 { 0x0a, 0x90100141 },
406 { 0x0b, 0x90100140 },
407 { 0x0c, 0x018b3020 },
408 { 0x0d, 0x90a00110 },
409 { 0x0e, 0x400000f0 },
410 { 0x0f, 0x01cbe030 },
411 { 0x10, 0x014be060 },
412 { 0x12, 0x400000f0 },
413 { 0x15, 0x400000f0 },
414 {} /* terminator */
415};
416
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200417static const struct hda_pintbl mbp55_pincfgs[] = {
Takashi Iwaia6bae202009-07-06 15:15:22 +0200418 { 0x09, 0x012b4030 },
419 { 0x0a, 0x90100121 },
420 { 0x0b, 0x90100120 },
421 { 0x0c, 0x400000f0 },
422 { 0x0d, 0x90a00110 },
423 { 0x0e, 0x400000f0 },
424 { 0x0f, 0x400000f0 },
425 { 0x10, 0x014be040 },
426 { 0x12, 0x400000f0 },
427 { 0x15, 0x400000f0 },
428 {} /* terminator */
429};
430
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200431static const struct hda_pintbl imac27_pincfgs[] = {
Rafael Avila de Espindola1a5ba2e2009-12-22 07:59:37 +0100432 { 0x09, 0x012b4050 },
433 { 0x0a, 0x90100140 },
434 { 0x0b, 0x90100142 },
435 { 0x0c, 0x018b3020 },
436 { 0x0d, 0x90a00110 },
437 { 0x0e, 0x400000f0 },
438 { 0x0f, 0x01cbe030 },
439 { 0x10, 0x014be060 },
440 { 0x12, 0x01ab9070 },
441 { 0x15, 0x400000f0 },
442 {} /* terminator */
443};
444
Takashi Iwaief596a52012-09-11 16:53:08 +0200445static const struct hda_pintbl mbp101_pincfgs[] = {
446 { 0x0d, 0x40ab90f0 },
447 { 0x0e, 0x90a600f0 },
448 { 0x12, 0x50a600f0 },
449 {} /* terminator */
450};
451
Takashi Iwai6ab982e2013-06-17 10:19:49 +0200452static const struct hda_pintbl mba42_pincfgs[] = {
453 { 0x09, 0x012b4030 }, /* HP */
454 { 0x0a, 0x400000f0 },
455 { 0x0b, 0x90100120 }, /* speaker */
456 { 0x0c, 0x400000f0 },
457 { 0x0d, 0x90a00110 }, /* mic */
458 { 0x0e, 0x400000f0 },
459 { 0x0f, 0x400000f0 },
460 { 0x10, 0x400000f0 },
461 { 0x12, 0x400000f0 },
462 { 0x15, 0x400000f0 },
463 {} /* terminator */
464};
465
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200466static const struct hda_pintbl mba6_pincfgs[] = {
467 { 0x10, 0x032120f0 }, /* HP */
468 { 0x11, 0x500000f0 },
469 { 0x12, 0x90100010 }, /* Speaker */
470 { 0x13, 0x500000f0 },
471 { 0x14, 0x500000f0 },
472 { 0x15, 0x770000f0 },
473 { 0x16, 0x770000f0 },
474 { 0x17, 0x430000f0 },
475 { 0x18, 0x43ab9030 }, /* Mic */
476 { 0x19, 0x770000f0 },
477 { 0x1a, 0x770000f0 },
478 { 0x1b, 0x770000f0 },
479 { 0x1c, 0x90a00090 },
480 { 0x1d, 0x500000f0 },
481 { 0x1e, 0x500000f0 },
482 { 0x1f, 0x500000f0 },
483 { 0x20, 0x500000f0 },
484 { 0x21, 0x430000f0 },
485 { 0x22, 0x430000f0 },
486 {} /* terminator */
487};
488
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200489static void cs420x_fixup_gpio_13(struct hda_codec *codec,
490 const struct hda_fixup *fix, int action)
Takashi Iwaia6bae202009-07-06 15:15:22 +0200491{
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200492 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
493 struct cs_spec *spec = codec->spec;
494 spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */
495 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
496 spec->gpio_mask = spec->gpio_dir =
497 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
498 }
Takashi Iwaia6bae202009-07-06 15:15:22 +0200499}
500
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200501static void cs420x_fixup_gpio_23(struct hda_codec *codec,
502 const struct hda_fixup *fix, int action)
503{
504 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
505 struct cs_spec *spec = codec->spec;
506 spec->gpio_eapd_hp = 4; /* GPIO2 = headphones */
507 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
508 spec->gpio_mask = spec->gpio_dir =
509 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
510 }
511}
512
513static const struct hda_fixup cs420x_fixups[] = {
514 [CS420X_MBP53] = {
515 .type = HDA_FIXUP_PINS,
516 .v.pins = mbp53_pincfgs,
517 .chained = true,
518 .chain_id = CS420X_APPLE,
519 },
520 [CS420X_MBP55] = {
521 .type = HDA_FIXUP_PINS,
522 .v.pins = mbp55_pincfgs,
523 .chained = true,
524 .chain_id = CS420X_GPIO_13,
525 },
526 [CS420X_IMAC27] = {
527 .type = HDA_FIXUP_PINS,
528 .v.pins = imac27_pincfgs,
529 .chained = true,
530 .chain_id = CS420X_GPIO_13,
531 },
532 [CS420X_GPIO_13] = {
533 .type = HDA_FIXUP_FUNC,
534 .v.func = cs420x_fixup_gpio_13,
535 },
536 [CS420X_GPIO_23] = {
537 .type = HDA_FIXUP_FUNC,
538 .v.func = cs420x_fixup_gpio_23,
539 },
Takashi Iwaief596a52012-09-11 16:53:08 +0200540 [CS420X_MBP101] = {
541 .type = HDA_FIXUP_PINS,
542 .v.pins = mbp101_pincfgs,
543 .chained = true,
Takashi Iwaief596a52012-09-11 16:53:08 +0200544 .chain_id = CS420X_GPIO_13,
545 },
Takashi Iwaiffe4d12b2012-11-23 08:34:13 +0100546 [CS420X_MBP81] = {
547 .type = HDA_FIXUP_VERBS,
548 .v.verbs = (const struct hda_verb[]) {
549 /* internal mic ADC2: right only, single ended */
550 {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
551 {0x11, AC_VERB_SET_PROC_COEF, 0x102a},
552 {}
553 },
554 .chained = true,
555 .chain_id = CS420X_GPIO_13,
556 },
Takashi Iwai6ab982e2013-06-17 10:19:49 +0200557 [CS420X_MBA42] = {
558 .type = HDA_FIXUP_PINS,
559 .v.pins = mba42_pincfgs,
560 .chained = true,
561 .chain_id = CS420X_GPIO_13,
562 },
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200563};
564
Takashi Iwai1077a022012-12-19 16:39:18 +0100565static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid)
566{
567 struct cs_spec *spec;
568
569 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
570 if (!spec)
571 return NULL;
572 codec->spec = spec;
573 spec->vendor_nid = vendor_nid;
574 snd_hda_gen_spec_init(&spec->gen);
575
576 return spec;
577}
578
Takashi Iwaie5f14242009-07-01 18:11:44 +0200579static int patch_cs420x(struct hda_codec *codec)
580{
581 struct cs_spec *spec;
582 int err;
583
Takashi Iwai1077a022012-12-19 16:39:18 +0100584 spec = cs_alloc_spec(codec, CS420X_VENDOR_NID);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200585 if (!spec)
586 return -ENOMEM;
Tim Howe56487c22011-07-22 16:41:00 -0500587
Takashi Iwai6d3073e2013-03-15 14:23:32 +0100588 spec->gen.automute_hook = cs_automute;
589
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200590 snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl,
591 cs420x_fixups);
592 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200593
Takashi Iwaied208252009-07-07 09:04:26 +0200594 err = cs_parse_auto_config(codec);
Takashi Iwai21a4dc42009-07-06 12:55:46 +0200595 if (err < 0)
596 goto error;
597
Takashi Iwaie5f14242009-07-01 18:11:44 +0200598 codec->patch_ops = cs_patch_ops;
599
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200600 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
601
Takashi Iwaie5f14242009-07-01 18:11:44 +0200602 return 0;
603
604 error:
Takashi Iwaic5e0b6d2012-10-10 08:50:35 +0200605 cs_free(codec);
Takashi Iwaie5f14242009-07-01 18:11:44 +0200606 return err;
607}
608
Tim Howe56487c22011-07-22 16:41:00 -0500609/*
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200610 * CS4208 support:
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200611 * Its layout is no longer compatible with CS4206/CS4207
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200612 */
613enum {
Takashi Iwai885845d2013-11-08 12:50:31 +0100614 CS4208_MAC_AUTO,
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200615 CS4208_MBA6,
Takashi Iwai0c52db82013-11-08 13:03:57 +0100616 CS4208_MBP11,
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200617 CS4208_GPIO0,
618};
619
620static const struct hda_model_fixup cs4208_models[] = {
621 { .id = CS4208_GPIO0, .name = "gpio0" },
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200622 { .id = CS4208_MBA6, .name = "mba6" },
Takashi Iwai0c52db82013-11-08 13:03:57 +0100623 { .id = CS4208_MBP11, .name = "mbp11" },
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200624 {}
625};
626
627static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
Takashi Iwai885845d2013-11-08 12:50:31 +0100628 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS4208_MAC_AUTO),
629 {} /* terminator */
630};
631
632/* codec SSID matching */
633static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
Takashi Iwai0c52db82013-11-08 13:03:57 +0100634 SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200635 SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
636 SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6),
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200637 {} /* terminator */
638};
639
640static void cs4208_fixup_gpio0(struct hda_codec *codec,
641 const struct hda_fixup *fix, int action)
642{
643 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
644 struct cs_spec *spec = codec->spec;
645 spec->gpio_eapd_hp = 0;
646 spec->gpio_eapd_speaker = 1;
647 spec->gpio_mask = spec->gpio_dir =
648 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
649 }
650}
651
Takashi Iwai885845d2013-11-08 12:50:31 +0100652static const struct hda_fixup cs4208_fixups[];
653
654/* remap the fixup from codec SSID and apply it */
655static void cs4208_fixup_mac(struct hda_codec *codec,
656 const struct hda_fixup *fix, int action)
657{
658 if (action != HDA_FIXUP_ACT_PRE_PROBE)
659 return;
David Henningssonf5662e12014-07-22 14:09:34 +0200660
661 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
Takashi Iwai885845d2013-11-08 12:50:31 +0100662 snd_hda_pick_fixup(codec, NULL, cs4208_mac_fixup_tbl, cs4208_fixups);
David Henningssonf5662e12014-07-22 14:09:34 +0200663 if (codec->fixup_id == HDA_FIXUP_ID_NOT_SET)
Takashi Iwai885845d2013-11-08 12:50:31 +0100664 codec->fixup_id = CS4208_GPIO0; /* default fixup */
665 snd_hda_apply_fixup(codec, action);
666}
667
Takashi Iwai0c52db82013-11-08 13:03:57 +0100668static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_value *ucontrol)
670{
671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672 struct cs_spec *spec = codec->spec;
673 hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0];
674 int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0;
675
676 snd_hda_set_pin_ctl_cache(codec, pin, pinctl);
677 return spec->spdif_sw_put(kcontrol, ucontrol);
678}
679
680/* hook the SPDIF switch */
681static void cs4208_fixup_spdif_switch(struct hda_codec *codec,
682 const struct hda_fixup *fix, int action)
683{
684 if (action == HDA_FIXUP_ACT_BUILD) {
685 struct cs_spec *spec = codec->spec;
686 struct snd_kcontrol *kctl;
687
688 if (!spec->gen.autocfg.dig_out_pins[0])
689 return;
690 kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch");
691 if (!kctl)
692 return;
693 spec->spdif_sw_put = kctl->put;
694 kctl->put = cs4208_spdif_sw_put;
695 }
696}
697
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200698static const struct hda_fixup cs4208_fixups[] = {
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200699 [CS4208_MBA6] = {
700 .type = HDA_FIXUP_PINS,
701 .v.pins = mba6_pincfgs,
702 .chained = true,
703 .chain_id = CS4208_GPIO0,
704 },
Takashi Iwai0c52db82013-11-08 13:03:57 +0100705 [CS4208_MBP11] = {
706 .type = HDA_FIXUP_FUNC,
707 .v.func = cs4208_fixup_spdif_switch,
708 .chained = true,
709 .chain_id = CS4208_GPIO0,
710 },
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200711 [CS4208_GPIO0] = {
712 .type = HDA_FIXUP_FUNC,
713 .v.func = cs4208_fixup_gpio0,
714 },
Takashi Iwai885845d2013-11-08 12:50:31 +0100715 [CS4208_MAC_AUTO] = {
716 .type = HDA_FIXUP_FUNC,
717 .v.func = cs4208_fixup_mac,
718 },
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200719};
720
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200721/* correct the 0dB offset of input pins */
722static void cs4208_fix_amp_caps(struct hda_codec *codec, hda_nid_t adc)
723{
724 unsigned int caps;
725
726 caps = query_amp_caps(codec, adc, HDA_INPUT);
727 caps &= ~(AC_AMPCAP_OFFSET);
728 caps |= 0x02;
729 snd_hda_override_amp_caps(codec, adc, HDA_INPUT, caps);
730}
731
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200732static int patch_cs4208(struct hda_codec *codec)
733{
734 struct cs_spec *spec;
735 int err;
736
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200737 spec = cs_alloc_spec(codec, CS4208_VENDOR_NID);
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200738 if (!spec)
739 return -ENOMEM;
740
741 spec->gen.automute_hook = cs_automute;
Takashi Iwaia1114a82013-11-04 16:32:01 +0100742 /* exclude NID 0x10 (HP) from output volumes due to different steps */
743 spec->gen.out_vol_mask = 1ULL << 0x10;
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200744
745 snd_hda_pick_fixup(codec, cs4208_models, cs4208_fixup_tbl,
746 cs4208_fixups);
747 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
748
Ben Whittenb5bf0a92013-09-27 10:13:51 +0200749 snd_hda_override_wcaps(codec, 0x18,
750 get_wcaps(codec, 0x18) | AC_WCAP_STEREO);
751 cs4208_fix_amp_caps(codec, 0x18);
752 cs4208_fix_amp_caps(codec, 0x1b);
753 cs4208_fix_amp_caps(codec, 0x1c);
754
Takashi Iwaibe8cf442013-09-09 13:57:57 +0200755 err = cs_parse_auto_config(codec);
756 if (err < 0)
757 goto error;
758
759 codec->patch_ops = cs_patch_ops;
760
761 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
762
763 return 0;
764
765 error:
766 cs_free(codec);
767 return err;
768}
769
770/*
Tim Howe56487c22011-07-22 16:41:00 -0500771 * Cirrus Logic CS4210
772 *
773 * 1 DAC => HP(sense) / Speakers,
774 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
775 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
776*/
777
778/* CS4210 board names */
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200779static const struct hda_model_fixup cs421x_models[] = {
780 { .id = CS421X_CDB4210, .name = "cdb4210" },
Dylan Reid4af161072013-04-04 15:35:31 -0700781 { .id = CS421X_STUMPY, .name = "stumpy" },
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200782 {}
Tim Howe56487c22011-07-22 16:41:00 -0500783};
784
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200785static const struct snd_pci_quirk cs421x_fixup_tbl[] = {
Tim Howe56487c22011-07-22 16:41:00 -0500786 /* Test Intel board + CDB2410 */
787 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210),
788 {} /* terminator */
789};
790
791/* CS4210 board pinconfigs */
792/* Default CS4210 (CDB4210)*/
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200793static const struct hda_pintbl cdb4210_pincfgs[] = {
Tim Howe56487c22011-07-22 16:41:00 -0500794 { 0x05, 0x0321401f },
795 { 0x06, 0x90170010 },
796 { 0x07, 0x03813031 },
797 { 0x08, 0xb7a70037 },
798 { 0x09, 0xb7a6003e },
799 { 0x0a, 0x034510f0 },
800 {} /* terminator */
801};
802
Dylan Reid4af161072013-04-04 15:35:31 -0700803/* Stumpy ChromeBox */
804static const struct hda_pintbl stumpy_pincfgs[] = {
805 { 0x05, 0x022120f0 },
806 { 0x06, 0x901700f0 },
807 { 0x07, 0x02a120f0 },
808 { 0x08, 0x77a70037 },
809 { 0x09, 0x77a6003e },
810 { 0x0a, 0x434510f0 },
811 {} /* terminator */
812};
813
Takashi Iwaib35aabd2012-08-24 19:09:45 +0200814/* Setup GPIO/SENSE for each board (if used) */
815static void cs421x_fixup_sense_b(struct hda_codec *codec,
816 const struct hda_fixup *fix, int action)
817{
818 struct cs_spec *spec = codec->spec;
819 if (action == HDA_FIXUP_ACT_PRE_PROBE)
820 spec->sense_b = 1;
821}
822
823static const struct hda_fixup cs421x_fixups[] = {
824 [CS421X_CDB4210] = {
825 .type = HDA_FIXUP_PINS,
826 .v.pins = cdb4210_pincfgs,
827 .chained = true,
828 .chain_id = CS421X_SENSE_B,
829 },
830 [CS421X_SENSE_B] = {
831 .type = HDA_FIXUP_FUNC,
832 .v.func = cs421x_fixup_sense_b,
Dylan Reid4af161072013-04-04 15:35:31 -0700833 },
834 [CS421X_STUMPY] = {
835 .type = HDA_FIXUP_PINS,
836 .v.pins = stumpy_pincfgs,
837 },
Tim Howe56487c22011-07-22 16:41:00 -0500838};
839
840static const struct hda_verb cs421x_coef_init_verbs[] = {
841 {0x0B, AC_VERB_SET_PROC_STATE, 1},
842 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG},
843 /*
844 Disable Coefficient Index Auto-Increment(DAI)=1,
845 PDREF=0
846 */
847 {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 },
848
849 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG},
850 /* ADC SZCMode = Digital Soft Ramp */
851 {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 },
852
853 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG},
854 {0x0B, AC_VERB_SET_PROC_COEF,
855 (0x0002 /* DAC SZCMode = Digital Soft Ramp */
856 | 0x0004 /* Mute DAC on FIFO error */
857 | 0x0008 /* Enable DAC High Pass Filter */
858 )},
859 {} /* terminator */
860};
861
862/* Errata: CS4210 rev A1 Silicon
863 *
864 * http://www.cirrus.com/en/pubs/errata/
865 *
866 * Description:
867 * 1. Performance degredation is present in the ADC.
868 * 2. Speaker output is not completely muted upon HP detect.
869 * 3. Noise is present when clipping occurs on the amplified
870 * speaker outputs.
871 *
872 * Workaround:
873 * The following verb sequence written to the registers during
874 * initialization will correct the issues listed above.
875 */
876
877static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = {
878 {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
879
880 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006},
881 {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */
882
883 {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A},
884 {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */
885
886 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011},
887 {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */
888
889 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A},
890 {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */
891
892 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B},
893 {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */
894
895 {} /* terminator */
896};
897
898/* Speaker Amp Gain is controlled by the vendor widget's coef 4 */
899static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0);
900
901static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol,
902 struct snd_ctl_elem_info *uinfo)
903{
904 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
905 uinfo->count = 1;
906 uinfo->value.integer.min = 0;
907 uinfo->value.integer.max = 3;
908 return 0;
909}
910
911static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol,
912 struct snd_ctl_elem_value *ucontrol)
913{
914 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
915
916 ucontrol->value.integer.value[0] =
917 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003;
918 return 0;
919}
920
921static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol,
922 struct snd_ctl_elem_value *ucontrol)
923{
924 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
925
926 unsigned int vol = ucontrol->value.integer.value[0];
927 unsigned int coef =
928 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL);
929 unsigned int original_coef = coef;
930
931 coef &= ~0x0003;
932 coef |= (vol & 0x0003);
933 if (original_coef == coef)
934 return 0;
935 else {
936 cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef);
937 return 1;
938 }
939}
940
Takashi Iwai1077a022012-12-19 16:39:18 +0100941static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = {
Tim Howe56487c22011-07-22 16:41:00 -0500942
943 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
944 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
945 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
946 .name = "Speaker Boost Playback Volume",
947 .info = cs421x_boost_vol_info,
948 .get = cs421x_boost_vol_get,
949 .put = cs421x_boost_vol_put,
950 .tlv = { .p = cs421x_speaker_boost_db_scale },
951};
952
David Henningsson5660ffd2012-01-02 12:40:17 +0100953static void cs4210_pinmux_init(struct hda_codec *codec)
Tim Howe56487c22011-07-22 16:41:00 -0500954{
955 struct cs_spec *spec = codec->spec;
956 unsigned int def_conf, coef;
957
958 /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */
959 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
960
961 if (spec->gpio_mask)
962 coef |= 0x0008; /* B1,B2 are GPIOs */
963 else
964 coef &= ~0x0008;
965
966 if (spec->sense_b)
967 coef |= 0x0010; /* B2 is SENSE_B, not inverted */
968 else
969 coef &= ~0x0010;
970
971 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
972
973 if ((spec->gpio_mask || spec->sense_b) &&
974 is_active_pin(codec, CS421X_DMIC_PIN_NID)) {
975
976 /*
977 GPIO or SENSE_B forced - disconnect the DMIC pin.
978 */
979 def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID);
980 def_conf &= ~AC_DEFCFG_PORT_CONN;
981 def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT);
982 snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf);
983 }
984}
985
Takashi Iwai1077a022012-12-19 16:39:18 +0100986static void cs4210_spdif_automute(struct hda_codec *codec,
987 struct hda_jack_tbl *tbl)
Tim Howe56487c22011-07-22 16:41:00 -0500988{
989 struct cs_spec *spec = codec->spec;
Takashi Iwai1077a022012-12-19 16:39:18 +0100990 bool spdif_present = false;
991 hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0];
Tim Howe56487c22011-07-22 16:41:00 -0500992
Takashi Iwai1077a022012-12-19 16:39:18 +0100993 /* detect on spdif is specific to CS4210 */
994 if (!spec->spdif_detect ||
995 spec->vendor_nid != CS4210_VENDOR_NID)
996 return;
997
998 spdif_present = snd_hda_jack_detect(codec, spdif_pin);
999 if (spdif_present == spec->spdif_present)
1000 return;
1001
1002 spec->spdif_present = spdif_present;
1003 /* SPDIF TX on/off */
1004 if (spdif_present)
1005 snd_hda_set_pin_ctl(codec, spdif_pin,
1006 spdif_present ? PIN_OUT : 0);
1007
1008 cs_automute(codec);
1009}
1010
1011static void parse_cs421x_digital(struct hda_codec *codec)
1012{
1013 struct cs_spec *spec = codec->spec;
1014 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
1015 int i;
Tim Howe56487c22011-07-22 16:41:00 -05001016
1017 for (i = 0; i < cfg->dig_outs; i++) {
1018 hda_nid_t nid = cfg->dig_out_pins[i];
Tim Howe56487c22011-07-22 16:41:00 -05001019 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
Tim Howe56487c22011-07-22 16:41:00 -05001020 spec->spdif_detect = 1;
Takashi Iwai1077a022012-12-19 16:39:18 +01001021 snd_hda_jack_detect_enable_callback(codec, nid,
1022 SPDIF_EVENT,
1023 cs4210_spdif_automute);
Tim Howe56487c22011-07-22 16:41:00 -05001024 }
1025 }
1026}
1027
1028static int cs421x_init(struct hda_codec *codec)
1029{
1030 struct cs_spec *spec = codec->spec;
1031
David Henningsson5660ffd2012-01-02 12:40:17 +01001032 if (spec->vendor_nid == CS4210_VENDOR_NID) {
1033 snd_hda_sequence_write(codec, cs421x_coef_init_verbs);
1034 snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes);
1035 cs4210_pinmux_init(codec);
1036 }
Tim Howe56487c22011-07-22 16:41:00 -05001037
Takashi Iwai1077a022012-12-19 16:39:18 +01001038 snd_hda_gen_init(codec);
1039
Tim Howe56487c22011-07-22 16:41:00 -05001040 if (spec->gpio_mask) {
1041 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
1042 spec->gpio_mask);
1043 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
1044 spec->gpio_dir);
1045 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1046 spec->gpio_data);
1047 }
1048
Takashi Iwai1077a022012-12-19 16:39:18 +01001049 init_input_coef(codec);
1050
1051 cs4210_spdif_automute(codec, NULL);
Tim Howe56487c22011-07-22 16:41:00 -05001052
1053 return 0;
1054}
1055
Tim Howe56487c22011-07-22 16:41:00 -05001056static int cs421x_build_controls(struct hda_codec *codec)
1057{
Takashi Iwai01a61e12011-10-28 00:03:22 +02001058 struct cs_spec *spec = codec->spec;
Tim Howe56487c22011-07-22 16:41:00 -05001059 int err;
1060
Takashi Iwai1077a022012-12-19 16:39:18 +01001061 err = snd_hda_gen_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001062 if (err < 0)
1063 return err;
1064
Takashi Iwai1077a022012-12-19 16:39:18 +01001065 if (spec->gen.autocfg.speaker_outs &&
1066 spec->vendor_nid == CS4210_VENDOR_NID) {
1067 err = snd_hda_ctl_add(codec, 0,
1068 snd_ctl_new1(&cs421x_speaker_boost_ctl, codec));
1069 if (err < 0)
1070 return err;
1071 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02001072 return 0;
Tim Howe56487c22011-07-22 16:41:00 -05001073}
1074
Takashi Iwai1077a022012-12-19 16:39:18 +01001075static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
Tim Howe56487c22011-07-22 16:41:00 -05001076{
Takashi Iwai1077a022012-12-19 16:39:18 +01001077 unsigned int caps;
Tim Howe56487c22011-07-22 16:41:00 -05001078
Takashi Iwai1077a022012-12-19 16:39:18 +01001079 /* set the upper-limit for mixer amp to 0dB */
1080 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
1081 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
1082 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
1083 << AC_AMPCAP_NUM_STEPS_SHIFT;
1084 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
Tim Howe56487c22011-07-22 16:41:00 -05001085}
1086
1087static int cs421x_parse_auto_config(struct hda_codec *codec)
1088{
1089 struct cs_spec *spec = codec->spec;
Takashi Iwai1077a022012-12-19 16:39:18 +01001090 hda_nid_t dac = CS4210_DAC_NID;
Tim Howe56487c22011-07-22 16:41:00 -05001091 int err;
1092
Takashi Iwai1077a022012-12-19 16:39:18 +01001093 fix_volume_caps(codec, dac);
1094
1095 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
Tim Howe56487c22011-07-22 16:41:00 -05001096 if (err < 0)
1097 return err;
Takashi Iwai1077a022012-12-19 16:39:18 +01001098
1099 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
Tim Howe56487c22011-07-22 16:41:00 -05001100 if (err < 0)
1101 return err;
Takashi Iwai1077a022012-12-19 16:39:18 +01001102
1103 parse_cs421x_digital(codec);
Tim Howe56487c22011-07-22 16:41:00 -05001104 return 0;
1105}
1106
1107#ifdef CONFIG_PM
1108/*
1109 Manage PDREF, when transitioning to D3hot
1110 (DAC,ADC) -> D3, PDREF=1, AFG->D3
1111*/
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001112static int cs421x_suspend(struct hda_codec *codec)
Tim Howe56487c22011-07-22 16:41:00 -05001113{
David Henningsson5660ffd2012-01-02 12:40:17 +01001114 struct cs_spec *spec = codec->spec;
Tim Howe56487c22011-07-22 16:41:00 -05001115 unsigned int coef;
1116
1117 snd_hda_shutup_pins(codec);
1118
1119 snd_hda_codec_write(codec, CS4210_DAC_NID, 0,
1120 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1121 snd_hda_codec_write(codec, CS4210_ADC_NID, 0,
1122 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1123
David Henningsson5660ffd2012-01-02 12:40:17 +01001124 if (spec->vendor_nid == CS4210_VENDOR_NID) {
1125 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
1126 coef |= 0x0004; /* PDREF */
1127 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
1128 }
Tim Howe56487c22011-07-22 16:41:00 -05001129
1130 return 0;
1131}
1132#endif
1133
Daniel J Blueman00e17f72012-11-04 13:19:04 +08001134static const struct hda_codec_ops cs421x_patch_ops = {
Tim Howe56487c22011-07-22 16:41:00 -05001135 .build_controls = cs421x_build_controls,
Takashi Iwai1077a022012-12-19 16:39:18 +01001136 .build_pcms = snd_hda_gen_build_pcms,
Tim Howe56487c22011-07-22 16:41:00 -05001137 .init = cs421x_init,
1138 .free = cs_free,
David Henningsson5c2e4e02012-10-08 15:44:15 +02001139 .unsol_event = snd_hda_jack_unsol_event,
Tim Howe56487c22011-07-22 16:41:00 -05001140#ifdef CONFIG_PM
1141 .suspend = cs421x_suspend,
1142#endif
1143};
1144
David Henningsson5660ffd2012-01-02 12:40:17 +01001145static int patch_cs4210(struct hda_codec *codec)
Tim Howe56487c22011-07-22 16:41:00 -05001146{
1147 struct cs_spec *spec;
1148 int err;
1149
Takashi Iwai1077a022012-12-19 16:39:18 +01001150 spec = cs_alloc_spec(codec, CS4210_VENDOR_NID);
Tim Howe56487c22011-07-22 16:41:00 -05001151 if (!spec)
1152 return -ENOMEM;
Tim Howe56487c22011-07-22 16:41:00 -05001153
Takashi Iwai6d3073e2013-03-15 14:23:32 +01001154 spec->gen.automute_hook = cs_automute;
1155
Takashi Iwaib35aabd2012-08-24 19:09:45 +02001156 snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl,
1157 cs421x_fixups);
1158 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
Tim Howe56487c22011-07-22 16:41:00 -05001159
1160 /*
1161 Update the GPIO/DMIC/SENSE_B pinmux before the configuration
1162 is auto-parsed. If GPIO or SENSE_B is forced, DMIC input
1163 is disabled.
1164 */
David Henningsson5660ffd2012-01-02 12:40:17 +01001165 cs4210_pinmux_init(codec);
Tim Howe56487c22011-07-22 16:41:00 -05001166
1167 err = cs421x_parse_auto_config(codec);
1168 if (err < 0)
1169 goto error;
1170
David Henningsson5660ffd2012-01-02 12:40:17 +01001171 codec->patch_ops = cs421x_patch_ops;
Tim Howe56487c22011-07-22 16:41:00 -05001172
Takashi Iwaib35aabd2012-08-24 19:09:45 +02001173 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1174
Tim Howe56487c22011-07-22 16:41:00 -05001175 return 0;
1176
1177 error:
Takashi Iwaic5e0b6d2012-10-10 08:50:35 +02001178 cs_free(codec);
Tim Howe56487c22011-07-22 16:41:00 -05001179 return err;
1180}
1181
David Henningsson5660ffd2012-01-02 12:40:17 +01001182static int patch_cs4213(struct hda_codec *codec)
1183{
1184 struct cs_spec *spec;
1185 int err;
1186
Takashi Iwai1077a022012-12-19 16:39:18 +01001187 spec = cs_alloc_spec(codec, CS4213_VENDOR_NID);
David Henningsson5660ffd2012-01-02 12:40:17 +01001188 if (!spec)
1189 return -ENOMEM;
David Henningsson5660ffd2012-01-02 12:40:17 +01001190
1191 err = cs421x_parse_auto_config(codec);
1192 if (err < 0)
1193 goto error;
1194
1195 codec->patch_ops = cs421x_patch_ops;
1196 return 0;
1197
1198 error:
Takashi Iwaic5e0b6d2012-10-10 08:50:35 +02001199 cs_free(codec);
David Henningsson5660ffd2012-01-02 12:40:17 +01001200 return err;
1201}
1202
Takashi Iwaie5f14242009-07-01 18:11:44 +02001203
1204/*
1205 * patch entries
1206 */
Takashi Iwaic42d4782011-05-02 11:36:09 +02001207static const struct hda_codec_preset snd_hda_preset_cirrus[] = {
Takashi Iwaie5f14242009-07-01 18:11:44 +02001208 { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x },
1209 { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x },
Takashi Iwaibe8cf442013-09-09 13:57:57 +02001210 { .id = 0x10134208, .name = "CS4208", .patch = patch_cs4208 },
David Henningsson5660ffd2012-01-02 12:40:17 +01001211 { .id = 0x10134210, .name = "CS4210", .patch = patch_cs4210 },
1212 { .id = 0x10134213, .name = "CS4213", .patch = patch_cs4213 },
Takashi Iwaie5f14242009-07-01 18:11:44 +02001213 {} /* terminator */
1214};
1215
1216MODULE_ALIAS("snd-hda-codec-id:10134206");
1217MODULE_ALIAS("snd-hda-codec-id:10134207");
Takashi Iwaibe8cf442013-09-09 13:57:57 +02001218MODULE_ALIAS("snd-hda-codec-id:10134208");
Tim Howe56487c22011-07-22 16:41:00 -05001219MODULE_ALIAS("snd-hda-codec-id:10134210");
David Henningsson5660ffd2012-01-02 12:40:17 +01001220MODULE_ALIAS("snd-hda-codec-id:10134213");
Takashi Iwaie5f14242009-07-01 18:11:44 +02001221
1222MODULE_LICENSE("GPL");
1223MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1224
1225static struct hda_codec_preset_list cirrus_list = {
1226 .preset = snd_hda_preset_cirrus,
1227 .owner = THIS_MODULE,
1228};
1229
1230static int __init patch_cirrus_init(void)
1231{
1232 return snd_hda_add_codec_preset(&cirrus_list);
1233}
1234
1235static void __exit patch_cirrus_exit(void)
1236{
1237 snd_hda_delete_codec_preset(&cirrus_list);
1238}
1239
1240module_init(patch_cirrus_init)
1241module_exit(patch_cirrus_exit)