Commit | Line | Data |
---|---|---|
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> | |
e5f14248 | 22 | #include <linux/slab.h> |
da155d5b | 23 | #include <linux/module.h> |
e5f14248 | 24 | #include <sound/core.h> |
1077a024 | 25 | #include <sound/tlv.h> |
e5f14248 TI |
26 | #include "hda_codec.h" |
27 | #include "hda_local.h" | |
128bc4ba | 28 | #include "hda_auto_parser.h" |
1835a0f9 | 29 | #include "hda_jack.h" |
1077a024 | 30 | #include "hda_generic.h" |
e5f14248 TI |
31 | |
32 | /* | |
33 | */ | |
34 | ||
35 | struct cs_spec { | |
1077a024 | 36 | struct hda_gen_spec gen; |
e5f14248 | 37 | |
ed208255 TI |
38 | unsigned int gpio_mask; |
39 | unsigned int gpio_dir; | |
40 | unsigned int gpio_data; | |
6dfeb703 TI |
41 | unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */ |
42 | unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */ | |
ed208255 | 43 | |
56487c27 TH |
44 | /* CS421x */ |
45 | unsigned int spdif_detect:1; | |
1077a024 | 46 | unsigned int spdif_present:1; |
56487c27 TH |
47 | unsigned int sense_b:1; |
48 | hda_nid_t vendor_nid; | |
0c52db8c TI |
49 | |
50 | /* for MBP SPDIF control */ | |
51 | int (*spdif_sw_put)(struct snd_kcontrol *kcontrol, | |
52 | struct snd_ctl_elem_value *ucontrol); | |
e5f14248 TI |
53 | }; |
54 | ||
56487c27 | 55 | /* available models with CS420x */ |
a6bae205 | 56 | enum { |
4e7d7c60 | 57 | CS420X_MBP53, |
a6bae205 | 58 | CS420X_MBP55, |
1a5ba2e9 | 59 | CS420X_IMAC27, |
b35aabd7 TI |
60 | CS420X_GPIO_13, |
61 | CS420X_GPIO_23, | |
ef596a57 | 62 | CS420X_MBP101, |
ffe4d12b | 63 | CS420X_MBP81, |
6ab982e8 | 64 | CS420X_MBA42, |
a6bae205 | 65 | CS420X_AUTO, |
03efce75 TI |
66 | /* aliases */ |
67 | CS420X_IMAC27_122 = CS420X_GPIO_23, | |
68 | CS420X_APPLE = CS420X_GPIO_13, | |
a6bae205 TI |
69 | }; |
70 | ||
56487c27 TH |
71 | /* CS421x boards */ |
72 | enum { | |
73 | CS421X_CDB4210, | |
b35aabd7 | 74 | CS421X_SENSE_B, |
4af16107 | 75 | CS421X_STUMPY, |
56487c27 TH |
76 | }; |
77 | ||
40c20fa0 TI |
78 | /* 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 | |
16337e02 DB |
82 | #define CS_DMIC1_PIN_NID 0x0e |
83 | #define CS_DMIC2_PIN_NID 0x12 | |
40c20fa0 TI |
84 | |
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 | ||
b5bf0a92 BW |
117 | /* Cirrus Logic CS4208 */ |
118 | #define CS4208_VENDOR_NID 0x24 | |
119 | ||
56487c27 TH |
120 | /* |
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 | |
5660ffd0 | 129 | #define CS4210_VENDOR_NID 0x0B |
56487c27 TH |
130 | #define CS421X_DMIC_PIN_NID 0x09 /* Port E */ |
131 | #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */ | |
132 | ||
1077a024 TI |
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 | |
e5f14248 | 137 | |
1077a024 TI |
138 | /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */ |
139 | #define CS4213_VENDOR_NID 0x09 | |
e5f14248 | 140 | |
21a4dc43 | 141 | |
1077a024 | 142 | static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx) |
e5f14248 TI |
143 | { |
144 | struct cs_spec *spec = codec->spec; | |
1077a024 TI |
145 | snd_hda_codec_write(codec, spec->vendor_nid, 0, |
146 | AC_VERB_SET_COEF_INDEX, idx); | |
147 | return snd_hda_codec_read(codec, spec->vendor_nid, 0, | |
148 | AC_VERB_GET_PROC_COEF, 0); | |
e5f14248 TI |
149 | } |
150 | ||
1077a024 TI |
151 | static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx, |
152 | unsigned int coef) | |
e5f14248 TI |
153 | { |
154 | struct cs_spec *spec = codec->spec; | |
1077a024 TI |
155 | snd_hda_codec_write(codec, spec->vendor_nid, 0, |
156 | AC_VERB_SET_COEF_INDEX, idx); | |
157 | snd_hda_codec_write(codec, spec->vendor_nid, 0, | |
158 | AC_VERB_SET_PROC_COEF, coef); | |
e5f14248 TI |
159 | } |
160 | ||
21a4dc43 TI |
161 | /* |
162 | * auto-mute and auto-mic switching | |
56487c27 TH |
163 | * CS421x auto-output redirecting |
164 | * HP/SPK/SPDIF | |
21a4dc43 TI |
165 | */ |
166 | ||
1077a024 | 167 | static void cs_automute(struct hda_codec *codec) |
e5f14248 TI |
168 | { |
169 | struct cs_spec *spec = codec->spec; | |
e5f14248 | 170 | |
1077a024 TI |
171 | /* mute HPs if spdif jack (SENSE_B) is present */ |
172 | spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b); | |
56487c27 | 173 | |
1077a024 | 174 | snd_hda_gen_update_outputs(codec); |
78e2a928 | 175 | |
be8cf445 | 176 | if (spec->gpio_eapd_hp || spec->gpio_eapd_speaker) { |
1f7c6658 TI |
177 | if (spec->gen.automute_speaker) |
178 | spec->gpio_data = spec->gen.hp_jack_present ? | |
179 | spec->gpio_eapd_hp : spec->gpio_eapd_speaker; | |
180 | else | |
181 | spec->gpio_data = | |
182 | spec->gpio_eapd_hp | spec->gpio_eapd_speaker; | |
3a385167 | 183 | snd_hda_codec_write(codec, 0x01, 0, |
039eb753 | 184 | AC_VERB_SET_GPIO_DATA, spec->gpio_data); |
3a385167 | 185 | } |
e5f14248 TI |
186 | } |
187 | ||
1077a024 | 188 | static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid) |
e5f14248 | 189 | { |
1077a024 TI |
190 | unsigned int val; |
191 | val = snd_hda_codec_get_pincfg(codec, nid); | |
192 | return (get_defcfg_connect(val) != AC_JACK_PORT_NONE); | |
e5f14248 TI |
193 | } |
194 | ||
1077a024 | 195 | static void init_input_coef(struct hda_codec *codec) |
e5f14248 TI |
196 | { |
197 | struct cs_spec *spec = codec->spec; | |
40c20fa0 | 198 | unsigned int coef; |
e5f14248 | 199 | |
5660ffd0 DH |
200 | /* CS420x has multiple ADC, CS421x has single ADC */ |
201 | if (spec->vendor_nid == CS420X_VENDOR_NID) { | |
16337e02 | 202 | coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG); |
56487c27 | 203 | if (is_active_pin(codec, CS_DMIC2_PIN_NID)) |
16337e02 | 204 | coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */ |
56487c27 | 205 | if (is_active_pin(codec, CS_DMIC1_PIN_NID)) |
16337e02 | 206 | coef |= 1 << 3; /* DMIC1 2 chan on, GPIO0 off |
56487c27 TH |
207 | * No effect if SPDIF_OUT2 is |
208 | * selected in IDX_SPDIF_CTL. | |
209 | */ | |
16337e02 DB |
210 | |
211 | cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef); | |
56487c27 | 212 | } |
40c20fa0 TI |
213 | } |
214 | ||
c42d4782 | 215 | static const struct hda_verb cs_coef_init_verbs[] = { |
40c20fa0 TI |
216 | {0x11, AC_VERB_SET_PROC_STATE, 1}, |
217 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG}, | |
218 | {0x11, AC_VERB_SET_PROC_COEF, | |
219 | (0x002a /* DAC1/2/3 SZCMode Soft Ramp */ | |
220 | | 0x0040 /* Mute DACs on FIFO error */ | |
221 | | 0x1000 /* Enable DACs High Pass Filter */ | |
222 | | 0x0400 /* Disable Coefficient Auto increment */ | |
223 | )}, | |
829e87e0 TI |
224 | /* ADC1/2 - Digital and Analog Soft Ramp */ |
225 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG}, | |
226 | {0x11, AC_VERB_SET_PROC_COEF, 0x000a}, | |
40c20fa0 | 227 | /* Beep */ |
5a83b4b5 | 228 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_BEEP_CFG}, |
40c20fa0 TI |
229 | {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */ |
230 | ||
231 | {} /* terminator */ | |
232 | }; | |
233 | ||
b5bf0a92 BW |
234 | static const struct hda_verb cs4208_coef_init_verbs[] = { |
235 | {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */ | |
236 | {0x24, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */ | |
237 | {0x24, AC_VERB_SET_COEF_INDEX, 0x0033}, | |
238 | {0x24, AC_VERB_SET_PROC_COEF, 0x0001}, /* A1 ICS */ | |
239 | {0x24, AC_VERB_SET_COEF_INDEX, 0x0034}, | |
240 | {0x24, AC_VERB_SET_PROC_COEF, 0x1C01}, /* A1 Enable, A Thresh = 300mV */ | |
241 | {} /* terminator */ | |
242 | }; | |
243 | ||
a769cbcf BA |
244 | /* Errata: CS4207 rev C0/C1/C2 Silicon |
245 | * | |
246 | * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf | |
247 | * | |
248 | * 6. At high temperature (TA > +85°C), the digital supply current (IVD) | |
249 | * may be excessive (up to an additional 200 μA), which is most easily | |
250 | * observed while the part is being held in reset (RESET# active low). | |
251 | * | |
252 | * Root Cause: At initial powerup of the device, the logic that drives | |
253 | * the clock and write enable to the S/PDIF SRC RAMs is not properly | |
254 | * initialized. | |
255 | * Certain random patterns will cause a steady leakage current in those | |
256 | * RAM cells. The issue will resolve once the SRCs are used (turned on). | |
257 | * | |
258 | * Workaround: The following verb sequence briefly turns on the S/PDIF SRC | |
259 | * blocks, which will alleviate the issue. | |
260 | */ | |
261 | ||
c42d4782 | 262 | static const struct hda_verb cs_errata_init_verbs[] = { |
a769cbcf BA |
263 | {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */ |
264 | {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */ | |
265 | ||
266 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0008}, | |
267 | {0x11, AC_VERB_SET_PROC_COEF, 0x9999}, | |
268 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0017}, | |
269 | {0x11, AC_VERB_SET_PROC_COEF, 0xa412}, | |
270 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0001}, | |
271 | {0x11, AC_VERB_SET_PROC_COEF, 0x0009}, | |
272 | ||
273 | {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */ | |
274 | {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */ | |
275 | ||
276 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0017}, | |
277 | {0x11, AC_VERB_SET_PROC_COEF, 0x2412}, | |
278 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0008}, | |
279 | {0x11, AC_VERB_SET_PROC_COEF, 0x0000}, | |
280 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0001}, | |
281 | {0x11, AC_VERB_SET_PROC_COEF, 0x0008}, | |
282 | {0x11, AC_VERB_SET_PROC_STATE, 0x00}, | |
283 | ||
38c07641 | 284 | #if 0 /* Don't to set to D3 as we are in power-up sequence */ |
a769cbcf BA |
285 | {0x07, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Rx: D3 */ |
286 | {0x08, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Tx: D3 */ | |
287 | /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */ | |
38c07641 | 288 | #endif |
a769cbcf BA |
289 | |
290 | {} /* terminator */ | |
291 | }; | |
292 | ||
40c20fa0 | 293 | /* SPDIF setup */ |
1077a024 | 294 | static void init_digital_coef(struct hda_codec *codec) |
40c20fa0 TI |
295 | { |
296 | unsigned int coef; | |
297 | ||
298 | coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */ | |
299 | coef |= 0x0008; /* Replace with mute on error */ | |
300 | if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID)) | |
301 | coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2 | |
302 | * SPDIF_OUT2 is shared with GPIO1 and | |
303 | * DMIC_SDA2. | |
304 | */ | |
305 | cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef); | |
e5f14248 TI |
306 | } |
307 | ||
308 | static int cs_init(struct hda_codec *codec) | |
309 | { | |
310 | struct cs_spec *spec = codec->spec; | |
311 | ||
be8cf445 TI |
312 | if (spec->vendor_nid == CS420X_VENDOR_NID) { |
313 | /* init_verb sequence for C0/C1/C2 errata*/ | |
314 | snd_hda_sequence_write(codec, cs_errata_init_verbs); | |
315 | snd_hda_sequence_write(codec, cs_coef_init_verbs); | |
b5bf0a92 BW |
316 | } else if (spec->vendor_nid == CS4208_VENDOR_NID) { |
317 | snd_hda_sequence_write(codec, cs4208_coef_init_verbs); | |
be8cf445 | 318 | } |
ed208255 | 319 | |
1077a024 | 320 | snd_hda_gen_init(codec); |
98415eac | 321 | |
ed208255 TI |
322 | if (spec->gpio_mask) { |
323 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, | |
324 | spec->gpio_mask); | |
325 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, | |
326 | spec->gpio_dir); | |
327 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, | |
328 | spec->gpio_data); | |
329 | } | |
330 | ||
be8cf445 TI |
331 | if (spec->vendor_nid == CS420X_VENDOR_NID) { |
332 | init_input_coef(codec); | |
333 | init_digital_coef(codec); | |
334 | } | |
01a61e12 TI |
335 | |
336 | return 0; | |
e5f14248 TI |
337 | } |
338 | ||
0c52db8c TI |
339 | static int cs_build_controls(struct hda_codec *codec) |
340 | { | |
341 | int err; | |
342 | ||
343 | err = snd_hda_gen_build_controls(codec); | |
344 | if (err < 0) | |
345 | return err; | |
346 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD); | |
347 | return 0; | |
348 | } | |
349 | ||
1077a024 | 350 | #define cs_free snd_hda_gen_free |
e5f14248 | 351 | |
c42d4782 | 352 | static const struct hda_codec_ops cs_patch_ops = { |
0c52db8c | 353 | .build_controls = cs_build_controls, |
1077a024 | 354 | .build_pcms = snd_hda_gen_build_pcms, |
e5f14248 TI |
355 | .init = cs_init, |
356 | .free = cs_free, | |
5c2e4e0a | 357 | .unsol_event = snd_hda_jack_unsol_event, |
e5f14248 TI |
358 | }; |
359 | ||
360 | static int cs_parse_auto_config(struct hda_codec *codec) | |
361 | { | |
362 | struct cs_spec *spec = codec->spec; | |
363 | int err; | |
364 | ||
1077a024 | 365 | err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); |
ed208255 TI |
366 | if (err < 0) |
367 | return err; | |
368 | ||
1077a024 | 369 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); |
e5f14248 TI |
370 | if (err < 0) |
371 | return err; | |
1077a024 | 372 | |
e5f14248 TI |
373 | return 0; |
374 | } | |
375 | ||
b35aabd7 TI |
376 | static const struct hda_model_fixup cs420x_models[] = { |
377 | { .id = CS420X_MBP53, .name = "mbp53" }, | |
378 | { .id = CS420X_MBP55, .name = "mbp55" }, | |
379 | { .id = CS420X_IMAC27, .name = "imac27" }, | |
380 | { .id = CS420X_IMAC27_122, .name = "imac27_122" }, | |
381 | { .id = CS420X_APPLE, .name = "apple" }, | |
ef596a57 | 382 | { .id = CS420X_MBP101, .name = "mbp101" }, |
ffe4d12b | 383 | { .id = CS420X_MBP81, .name = "mbp81" }, |
6ab982e8 | 384 | { .id = CS420X_MBA42, .name = "mba42" }, |
b35aabd7 | 385 | {} |
a6bae205 TI |
386 | }; |
387 | ||
b35aabd7 | 388 | static const struct snd_pci_quirk cs420x_fixup_tbl[] = { |
4e7d7c60 | 389 | SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53), |
87232dd4 | 390 | SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55), |
a6bae205 | 391 | SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55), |
f46119b7 | 392 | SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55), |
6dfeb703 TI |
393 | /* this conflicts with too many other models */ |
394 | /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/ | |
6dfeb703 | 395 | |
b35aabd7 | 396 | /* codec SSID */ |
ffe4d12b | 397 | SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81), |
7e5bea19 | 398 | SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122), |
ef596a57 | 399 | SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101), |
2ddee91a | 400 | SND_PCI_QUIRK(0x106b, 0x5600, "MacBookAir 5,2", CS420X_MBP81), |
6ab982e8 | 401 | SND_PCI_QUIRK(0x106b, 0x5b00, "MacBookAir 4,2", CS420X_MBA42), |
6dfeb703 | 402 | SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE), |
a6bae205 TI |
403 | {} /* terminator */ |
404 | }; | |
405 | ||
b35aabd7 | 406 | static const struct hda_pintbl mbp53_pincfgs[] = { |
4e7d7c60 VW |
407 | { 0x09, 0x012b4050 }, |
408 | { 0x0a, 0x90100141 }, | |
409 | { 0x0b, 0x90100140 }, | |
410 | { 0x0c, 0x018b3020 }, | |
411 | { 0x0d, 0x90a00110 }, | |
412 | { 0x0e, 0x400000f0 }, | |
413 | { 0x0f, 0x01cbe030 }, | |
414 | { 0x10, 0x014be060 }, | |
415 | { 0x12, 0x400000f0 }, | |
416 | { 0x15, 0x400000f0 }, | |
417 | {} /* terminator */ | |
418 | }; | |
419 | ||
b35aabd7 | 420 | static const struct hda_pintbl mbp55_pincfgs[] = { |
a6bae205 TI |
421 | { 0x09, 0x012b4030 }, |
422 | { 0x0a, 0x90100121 }, | |
423 | { 0x0b, 0x90100120 }, | |
424 | { 0x0c, 0x400000f0 }, | |
425 | { 0x0d, 0x90a00110 }, | |
426 | { 0x0e, 0x400000f0 }, | |
427 | { 0x0f, 0x400000f0 }, | |
428 | { 0x10, 0x014be040 }, | |
429 | { 0x12, 0x400000f0 }, | |
430 | { 0x15, 0x400000f0 }, | |
431 | {} /* terminator */ | |
432 | }; | |
433 | ||
b35aabd7 | 434 | static const struct hda_pintbl imac27_pincfgs[] = { |
1a5ba2e9 RAE |
435 | { 0x09, 0x012b4050 }, |
436 | { 0x0a, 0x90100140 }, | |
437 | { 0x0b, 0x90100142 }, | |
438 | { 0x0c, 0x018b3020 }, | |
439 | { 0x0d, 0x90a00110 }, | |
440 | { 0x0e, 0x400000f0 }, | |
441 | { 0x0f, 0x01cbe030 }, | |
442 | { 0x10, 0x014be060 }, | |
443 | { 0x12, 0x01ab9070 }, | |
444 | { 0x15, 0x400000f0 }, | |
445 | {} /* terminator */ | |
446 | }; | |
447 | ||
ef596a57 TI |
448 | static const struct hda_pintbl mbp101_pincfgs[] = { |
449 | { 0x0d, 0x40ab90f0 }, | |
450 | { 0x0e, 0x90a600f0 }, | |
451 | { 0x12, 0x50a600f0 }, | |
452 | {} /* terminator */ | |
453 | }; | |
454 | ||
6ab982e8 TI |
455 | static const struct hda_pintbl mba42_pincfgs[] = { |
456 | { 0x09, 0x012b4030 }, /* HP */ | |
457 | { 0x0a, 0x400000f0 }, | |
458 | { 0x0b, 0x90100120 }, /* speaker */ | |
459 | { 0x0c, 0x400000f0 }, | |
460 | { 0x0d, 0x90a00110 }, /* mic */ | |
461 | { 0x0e, 0x400000f0 }, | |
462 | { 0x0f, 0x400000f0 }, | |
463 | { 0x10, 0x400000f0 }, | |
464 | { 0x12, 0x400000f0 }, | |
465 | { 0x15, 0x400000f0 }, | |
466 | {} /* terminator */ | |
467 | }; | |
468 | ||
b5bf0a92 BW |
469 | static const struct hda_pintbl mba6_pincfgs[] = { |
470 | { 0x10, 0x032120f0 }, /* HP */ | |
471 | { 0x11, 0x500000f0 }, | |
472 | { 0x12, 0x90100010 }, /* Speaker */ | |
473 | { 0x13, 0x500000f0 }, | |
474 | { 0x14, 0x500000f0 }, | |
475 | { 0x15, 0x770000f0 }, | |
476 | { 0x16, 0x770000f0 }, | |
477 | { 0x17, 0x430000f0 }, | |
478 | { 0x18, 0x43ab9030 }, /* Mic */ | |
479 | { 0x19, 0x770000f0 }, | |
480 | { 0x1a, 0x770000f0 }, | |
481 | { 0x1b, 0x770000f0 }, | |
482 | { 0x1c, 0x90a00090 }, | |
483 | { 0x1d, 0x500000f0 }, | |
484 | { 0x1e, 0x500000f0 }, | |
485 | { 0x1f, 0x500000f0 }, | |
486 | { 0x20, 0x500000f0 }, | |
487 | { 0x21, 0x430000f0 }, | |
488 | { 0x22, 0x430000f0 }, | |
489 | {} /* terminator */ | |
490 | }; | |
491 | ||
b35aabd7 TI |
492 | static void cs420x_fixup_gpio_13(struct hda_codec *codec, |
493 | const struct hda_fixup *fix, int action) | |
494 | { | |
495 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { | |
496 | struct cs_spec *spec = codec->spec; | |
497 | spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */ | |
498 | spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */ | |
499 | spec->gpio_mask = spec->gpio_dir = | |
500 | spec->gpio_eapd_hp | spec->gpio_eapd_speaker; | |
501 | } | |
502 | } | |
a6bae205 | 503 | |
b35aabd7 TI |
504 | static void cs420x_fixup_gpio_23(struct hda_codec *codec, |
505 | const struct hda_fixup *fix, int action) | |
a6bae205 | 506 | { |
b35aabd7 TI |
507 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
508 | struct cs_spec *spec = codec->spec; | |
509 | spec->gpio_eapd_hp = 4; /* GPIO2 = headphones */ | |
510 | spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */ | |
511 | spec->gpio_mask = spec->gpio_dir = | |
512 | spec->gpio_eapd_hp | spec->gpio_eapd_speaker; | |
513 | } | |
a6bae205 TI |
514 | } |
515 | ||
b35aabd7 TI |
516 | static const struct hda_fixup cs420x_fixups[] = { |
517 | [CS420X_MBP53] = { | |
518 | .type = HDA_FIXUP_PINS, | |
519 | .v.pins = mbp53_pincfgs, | |
520 | .chained = true, | |
521 | .chain_id = CS420X_APPLE, | |
522 | }, | |
523 | [CS420X_MBP55] = { | |
524 | .type = HDA_FIXUP_PINS, | |
525 | .v.pins = mbp55_pincfgs, | |
526 | .chained = true, | |
527 | .chain_id = CS420X_GPIO_13, | |
528 | }, | |
529 | [CS420X_IMAC27] = { | |
530 | .type = HDA_FIXUP_PINS, | |
531 | .v.pins = imac27_pincfgs, | |
532 | .chained = true, | |
533 | .chain_id = CS420X_GPIO_13, | |
534 | }, | |
535 | [CS420X_GPIO_13] = { | |
536 | .type = HDA_FIXUP_FUNC, | |
537 | .v.func = cs420x_fixup_gpio_13, | |
538 | }, | |
539 | [CS420X_GPIO_23] = { | |
540 | .type = HDA_FIXUP_FUNC, | |
541 | .v.func = cs420x_fixup_gpio_23, | |
542 | }, | |
ef596a57 TI |
543 | [CS420X_MBP101] = { |
544 | .type = HDA_FIXUP_PINS, | |
545 | .v.pins = mbp101_pincfgs, | |
546 | .chained = true, | |
ef596a57 TI |
547 | .chain_id = CS420X_GPIO_13, |
548 | }, | |
ffe4d12b TI |
549 | [CS420X_MBP81] = { |
550 | .type = HDA_FIXUP_VERBS, | |
551 | .v.verbs = (const struct hda_verb[]) { | |
552 | /* internal mic ADC2: right only, single ended */ | |
553 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG}, | |
554 | {0x11, AC_VERB_SET_PROC_COEF, 0x102a}, | |
555 | {} | |
556 | }, | |
557 | .chained = true, | |
558 | .chain_id = CS420X_GPIO_13, | |
559 | }, | |
6ab982e8 TI |
560 | [CS420X_MBA42] = { |
561 | .type = HDA_FIXUP_PINS, | |
562 | .v.pins = mba42_pincfgs, | |
563 | .chained = true, | |
564 | .chain_id = CS420X_GPIO_13, | |
565 | }, | |
b35aabd7 TI |
566 | }; |
567 | ||
1077a024 | 568 | static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid) |
e5f14248 TI |
569 | { |
570 | struct cs_spec *spec; | |
e5f14248 TI |
571 | |
572 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
573 | if (!spec) | |
1077a024 | 574 | return NULL; |
e5f14248 | 575 | codec->spec = spec; |
1077a024 | 576 | spec->vendor_nid = vendor_nid; |
3e19fec3 | 577 | codec->power_save_node = 1; |
1077a024 TI |
578 | snd_hda_gen_spec_init(&spec->gen); |
579 | ||
580 | return spec; | |
581 | } | |
582 | ||
583 | static int patch_cs420x(struct hda_codec *codec) | |
584 | { | |
585 | struct cs_spec *spec; | |
586 | int err; | |
e5f14248 | 587 | |
1077a024 TI |
588 | spec = cs_alloc_spec(codec, CS420X_VENDOR_NID); |
589 | if (!spec) | |
590 | return -ENOMEM; | |
56487c27 | 591 | |
225068ab | 592 | codec->patch_ops = cs_patch_ops; |
6d3073e1 | 593 | spec->gen.automute_hook = cs_automute; |
bad994f5 | 594 | codec->single_adc_amp = 1; |
6d3073e1 | 595 | |
b35aabd7 TI |
596 | snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl, |
597 | cs420x_fixups); | |
598 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); | |
e5f14248 | 599 | |
ed208255 | 600 | err = cs_parse_auto_config(codec); |
21a4dc43 TI |
601 | if (err < 0) |
602 | goto error; | |
603 | ||
b35aabd7 TI |
604 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
605 | ||
e5f14248 TI |
606 | return 0; |
607 | ||
608 | error: | |
c5e0b6db | 609 | cs_free(codec); |
e5f14248 TI |
610 | return err; |
611 | } | |
612 | ||
be8cf445 TI |
613 | /* |
614 | * CS4208 support: | |
b5bf0a92 | 615 | * Its layout is no longer compatible with CS4206/CS4207 |
be8cf445 TI |
616 | */ |
617 | enum { | |
885845d7 | 618 | CS4208_MAC_AUTO, |
b5bf0a92 | 619 | CS4208_MBA6, |
0c52db8c | 620 | CS4208_MBP11, |
2154cc0e | 621 | CS4208_MACMINI, |
be8cf445 TI |
622 | CS4208_GPIO0, |
623 | }; | |
624 | ||
625 | static const struct hda_model_fixup cs4208_models[] = { | |
626 | { .id = CS4208_GPIO0, .name = "gpio0" }, | |
b5bf0a92 | 627 | { .id = CS4208_MBA6, .name = "mba6" }, |
0c52db8c | 628 | { .id = CS4208_MBP11, .name = "mbp11" }, |
2154cc0e | 629 | { .id = CS4208_MACMINI, .name = "macmini" }, |
be8cf445 TI |
630 | {} |
631 | }; | |
632 | ||
633 | static const struct snd_pci_quirk cs4208_fixup_tbl[] = { | |
885845d7 TI |
634 | SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS4208_MAC_AUTO), |
635 | {} /* terminator */ | |
636 | }; | |
637 | ||
638 | /* codec SSID matching */ | |
639 | static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = { | |
0c52db8c | 640 | SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11), |
2154cc0e | 641 | SND_PCI_QUIRK(0x106b, 0x6c00, "MacMini 7,1", CS4208_MACMINI), |
b5bf0a92 BW |
642 | SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6), |
643 | SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6), | |
e8ff581f | 644 | SND_PCI_QUIRK(0x106b, 0x7b00, "MacBookPro 12,1", CS4208_MBP11), |
be8cf445 TI |
645 | {} /* terminator */ |
646 | }; | |
647 | ||
648 | static void cs4208_fixup_gpio0(struct hda_codec *codec, | |
649 | const struct hda_fixup *fix, int action) | |
650 | { | |
651 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { | |
652 | struct cs_spec *spec = codec->spec; | |
653 | spec->gpio_eapd_hp = 0; | |
654 | spec->gpio_eapd_speaker = 1; | |
655 | spec->gpio_mask = spec->gpio_dir = | |
656 | spec->gpio_eapd_hp | spec->gpio_eapd_speaker; | |
657 | } | |
658 | } | |
659 | ||
885845d7 TI |
660 | static const struct hda_fixup cs4208_fixups[]; |
661 | ||
662 | /* remap the fixup from codec SSID and apply it */ | |
663 | static void cs4208_fixup_mac(struct hda_codec *codec, | |
664 | const struct hda_fixup *fix, int action) | |
665 | { | |
666 | if (action != HDA_FIXUP_ACT_PRE_PROBE) | |
667 | return; | |
f5662e1c DH |
668 | |
669 | codec->fixup_id = HDA_FIXUP_ID_NOT_SET; | |
885845d7 | 670 | snd_hda_pick_fixup(codec, NULL, cs4208_mac_fixup_tbl, cs4208_fixups); |
f5662e1c | 671 | if (codec->fixup_id == HDA_FIXUP_ID_NOT_SET) |
885845d7 TI |
672 | codec->fixup_id = CS4208_GPIO0; /* default fixup */ |
673 | snd_hda_apply_fixup(codec, action); | |
674 | } | |
675 | ||
2154cc0e TI |
676 | /* MacMini 7,1 has the inverted jack detection */ |
677 | static void cs4208_fixup_macmini(struct hda_codec *codec, | |
678 | const struct hda_fixup *fix, int action) | |
679 | { | |
680 | static const struct hda_pintbl pincfgs[] = { | |
681 | { 0x18, 0x00ab9150 }, /* mic (audio-in) jack: disable detect */ | |
682 | { 0x21, 0x004be140 }, /* SPDIF: disable detect */ | |
683 | { } | |
684 | }; | |
685 | ||
686 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { | |
687 | /* HP pin (0x10) has an inverted detection */ | |
688 | codec->inv_jack_detect = 1; | |
689 | /* disable the bogus Mic and SPDIF jack detections */ | |
690 | snd_hda_apply_pincfgs(codec, pincfgs); | |
691 | } | |
692 | } | |
693 | ||
0c52db8c TI |
694 | static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol, |
695 | struct snd_ctl_elem_value *ucontrol) | |
696 | { | |
697 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
698 | struct cs_spec *spec = codec->spec; | |
699 | hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0]; | |
700 | int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0; | |
701 | ||
702 | snd_hda_set_pin_ctl_cache(codec, pin, pinctl); | |
703 | return spec->spdif_sw_put(kcontrol, ucontrol); | |
704 | } | |
705 | ||
706 | /* hook the SPDIF switch */ | |
707 | static void cs4208_fixup_spdif_switch(struct hda_codec *codec, | |
708 | const struct hda_fixup *fix, int action) | |
709 | { | |
710 | if (action == HDA_FIXUP_ACT_BUILD) { | |
711 | struct cs_spec *spec = codec->spec; | |
712 | struct snd_kcontrol *kctl; | |
713 | ||
714 | if (!spec->gen.autocfg.dig_out_pins[0]) | |
715 | return; | |
716 | kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch"); | |
717 | if (!kctl) | |
718 | return; | |
719 | spec->spdif_sw_put = kctl->put; | |
720 | kctl->put = cs4208_spdif_sw_put; | |
721 | } | |
722 | } | |
723 | ||
be8cf445 | 724 | static const struct hda_fixup cs4208_fixups[] = { |
b5bf0a92 BW |
725 | [CS4208_MBA6] = { |
726 | .type = HDA_FIXUP_PINS, | |
727 | .v.pins = mba6_pincfgs, | |
728 | .chained = true, | |
729 | .chain_id = CS4208_GPIO0, | |
730 | }, | |
0c52db8c TI |
731 | [CS4208_MBP11] = { |
732 | .type = HDA_FIXUP_FUNC, | |
733 | .v.func = cs4208_fixup_spdif_switch, | |
734 | .chained = true, | |
735 | .chain_id = CS4208_GPIO0, | |
736 | }, | |
2154cc0e TI |
737 | [CS4208_MACMINI] = { |
738 | .type = HDA_FIXUP_FUNC, | |
739 | .v.func = cs4208_fixup_macmini, | |
740 | .chained = true, | |
741 | .chain_id = CS4208_GPIO0, | |
742 | }, | |
be8cf445 TI |
743 | [CS4208_GPIO0] = { |
744 | .type = HDA_FIXUP_FUNC, | |
745 | .v.func = cs4208_fixup_gpio0, | |
746 | }, | |
885845d7 TI |
747 | [CS4208_MAC_AUTO] = { |
748 | .type = HDA_FIXUP_FUNC, | |
749 | .v.func = cs4208_fixup_mac, | |
750 | }, | |
be8cf445 TI |
751 | }; |
752 | ||
b5bf0a92 BW |
753 | /* correct the 0dB offset of input pins */ |
754 | static void cs4208_fix_amp_caps(struct hda_codec *codec, hda_nid_t adc) | |
755 | { | |
756 | unsigned int caps; | |
757 | ||
758 | caps = query_amp_caps(codec, adc, HDA_INPUT); | |
759 | caps &= ~(AC_AMPCAP_OFFSET); | |
760 | caps |= 0x02; | |
761 | snd_hda_override_amp_caps(codec, adc, HDA_INPUT, caps); | |
762 | } | |
763 | ||
be8cf445 TI |
764 | static int patch_cs4208(struct hda_codec *codec) |
765 | { | |
766 | struct cs_spec *spec; | |
767 | int err; | |
768 | ||
b5bf0a92 | 769 | spec = cs_alloc_spec(codec, CS4208_VENDOR_NID); |
be8cf445 TI |
770 | if (!spec) |
771 | return -ENOMEM; | |
772 | ||
225068ab | 773 | codec->patch_ops = cs_patch_ops; |
be8cf445 | 774 | spec->gen.automute_hook = cs_automute; |
a1114a8c TI |
775 | /* exclude NID 0x10 (HP) from output volumes due to different steps */ |
776 | spec->gen.out_vol_mask = 1ULL << 0x10; | |
be8cf445 TI |
777 | |
778 | snd_hda_pick_fixup(codec, cs4208_models, cs4208_fixup_tbl, | |
779 | cs4208_fixups); | |
780 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); | |
781 | ||
b5bf0a92 BW |
782 | snd_hda_override_wcaps(codec, 0x18, |
783 | get_wcaps(codec, 0x18) | AC_WCAP_STEREO); | |
784 | cs4208_fix_amp_caps(codec, 0x18); | |
785 | cs4208_fix_amp_caps(codec, 0x1b); | |
786 | cs4208_fix_amp_caps(codec, 0x1c); | |
787 | ||
be8cf445 TI |
788 | err = cs_parse_auto_config(codec); |
789 | if (err < 0) | |
790 | goto error; | |
791 | ||
be8cf445 TI |
792 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
793 | ||
794 | return 0; | |
795 | ||
796 | error: | |
797 | cs_free(codec); | |
798 | return err; | |
799 | } | |
800 | ||
56487c27 TH |
801 | /* |
802 | * Cirrus Logic CS4210 | |
803 | * | |
804 | * 1 DAC => HP(sense) / Speakers, | |
805 | * 1 ADC <= LineIn(sense) / MicIn / DMicIn, | |
806 | * 1 SPDIF OUT => SPDIF Trasmitter(sense) | |
807 | */ | |
808 | ||
809 | /* CS4210 board names */ | |
b35aabd7 TI |
810 | static const struct hda_model_fixup cs421x_models[] = { |
811 | { .id = CS421X_CDB4210, .name = "cdb4210" }, | |
4af16107 | 812 | { .id = CS421X_STUMPY, .name = "stumpy" }, |
b35aabd7 | 813 | {} |
56487c27 TH |
814 | }; |
815 | ||
b35aabd7 | 816 | static const struct snd_pci_quirk cs421x_fixup_tbl[] = { |
56487c27 TH |
817 | /* Test Intel board + CDB2410 */ |
818 | SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210), | |
819 | {} /* terminator */ | |
820 | }; | |
821 | ||
822 | /* CS4210 board pinconfigs */ | |
823 | /* Default CS4210 (CDB4210)*/ | |
b35aabd7 | 824 | static const struct hda_pintbl cdb4210_pincfgs[] = { |
56487c27 TH |
825 | { 0x05, 0x0321401f }, |
826 | { 0x06, 0x90170010 }, | |
827 | { 0x07, 0x03813031 }, | |
828 | { 0x08, 0xb7a70037 }, | |
829 | { 0x09, 0xb7a6003e }, | |
830 | { 0x0a, 0x034510f0 }, | |
831 | {} /* terminator */ | |
832 | }; | |
833 | ||
4af16107 DR |
834 | /* Stumpy ChromeBox */ |
835 | static const struct hda_pintbl stumpy_pincfgs[] = { | |
836 | { 0x05, 0x022120f0 }, | |
837 | { 0x06, 0x901700f0 }, | |
838 | { 0x07, 0x02a120f0 }, | |
839 | { 0x08, 0x77a70037 }, | |
840 | { 0x09, 0x77a6003e }, | |
841 | { 0x0a, 0x434510f0 }, | |
842 | {} /* terminator */ | |
843 | }; | |
844 | ||
b35aabd7 TI |
845 | /* Setup GPIO/SENSE for each board (if used) */ |
846 | static void cs421x_fixup_sense_b(struct hda_codec *codec, | |
847 | const struct hda_fixup *fix, int action) | |
848 | { | |
849 | struct cs_spec *spec = codec->spec; | |
850 | if (action == HDA_FIXUP_ACT_PRE_PROBE) | |
851 | spec->sense_b = 1; | |
852 | } | |
853 | ||
854 | static const struct hda_fixup cs421x_fixups[] = { | |
855 | [CS421X_CDB4210] = { | |
856 | .type = HDA_FIXUP_PINS, | |
857 | .v.pins = cdb4210_pincfgs, | |
858 | .chained = true, | |
859 | .chain_id = CS421X_SENSE_B, | |
860 | }, | |
861 | [CS421X_SENSE_B] = { | |
862 | .type = HDA_FIXUP_FUNC, | |
863 | .v.func = cs421x_fixup_sense_b, | |
4af16107 DR |
864 | }, |
865 | [CS421X_STUMPY] = { | |
866 | .type = HDA_FIXUP_PINS, | |
867 | .v.pins = stumpy_pincfgs, | |
868 | }, | |
56487c27 TH |
869 | }; |
870 | ||
871 | static const struct hda_verb cs421x_coef_init_verbs[] = { | |
872 | {0x0B, AC_VERB_SET_PROC_STATE, 1}, | |
873 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG}, | |
874 | /* | |
875 | Disable Coefficient Index Auto-Increment(DAI)=1, | |
876 | PDREF=0 | |
877 | */ | |
878 | {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 }, | |
879 | ||
880 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG}, | |
881 | /* ADC SZCMode = Digital Soft Ramp */ | |
882 | {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 }, | |
883 | ||
884 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG}, | |
885 | {0x0B, AC_VERB_SET_PROC_COEF, | |
886 | (0x0002 /* DAC SZCMode = Digital Soft Ramp */ | |
887 | | 0x0004 /* Mute DAC on FIFO error */ | |
888 | | 0x0008 /* Enable DAC High Pass Filter */ | |
889 | )}, | |
890 | {} /* terminator */ | |
891 | }; | |
892 | ||
893 | /* Errata: CS4210 rev A1 Silicon | |
894 | * | |
895 | * http://www.cirrus.com/en/pubs/errata/ | |
896 | * | |
897 | * Description: | |
898 | * 1. Performance degredation is present in the ADC. | |
899 | * 2. Speaker output is not completely muted upon HP detect. | |
900 | * 3. Noise is present when clipping occurs on the amplified | |
901 | * speaker outputs. | |
902 | * | |
903 | * Workaround: | |
904 | * The following verb sequence written to the registers during | |
905 | * initialization will correct the issues listed above. | |
906 | */ | |
907 | ||
908 | static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = { | |
909 | {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */ | |
910 | ||
911 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006}, | |
912 | {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */ | |
913 | ||
914 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A}, | |
915 | {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */ | |
916 | ||
917 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011}, | |
918 | {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */ | |
919 | ||
920 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A}, | |
921 | {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */ | |
922 | ||
923 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B}, | |
924 | {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */ | |
925 | ||
926 | {} /* terminator */ | |
927 | }; | |
928 | ||
929 | /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */ | |
930 | static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0); | |
931 | ||
932 | static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol, | |
933 | struct snd_ctl_elem_info *uinfo) | |
934 | { | |
935 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
936 | uinfo->count = 1; | |
937 | uinfo->value.integer.min = 0; | |
938 | uinfo->value.integer.max = 3; | |
939 | return 0; | |
940 | } | |
941 | ||
942 | static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol, | |
943 | struct snd_ctl_elem_value *ucontrol) | |
944 | { | |
945 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
946 | ||
947 | ucontrol->value.integer.value[0] = | |
948 | cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003; | |
949 | return 0; | |
950 | } | |
951 | ||
952 | static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol, | |
953 | struct snd_ctl_elem_value *ucontrol) | |
954 | { | |
955 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
956 | ||
957 | unsigned int vol = ucontrol->value.integer.value[0]; | |
958 | unsigned int coef = | |
959 | cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL); | |
960 | unsigned int original_coef = coef; | |
961 | ||
962 | coef &= ~0x0003; | |
963 | coef |= (vol & 0x0003); | |
964 | if (original_coef == coef) | |
965 | return 0; | |
966 | else { | |
967 | cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef); | |
968 | return 1; | |
969 | } | |
970 | } | |
971 | ||
1077a024 | 972 | static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = { |
56487c27 TH |
973 | |
974 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
975 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | | |
976 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), | |
977 | .name = "Speaker Boost Playback Volume", | |
978 | .info = cs421x_boost_vol_info, | |
979 | .get = cs421x_boost_vol_get, | |
980 | .put = cs421x_boost_vol_put, | |
981 | .tlv = { .p = cs421x_speaker_boost_db_scale }, | |
982 | }; | |
983 | ||
5660ffd0 | 984 | static void cs4210_pinmux_init(struct hda_codec *codec) |
56487c27 TH |
985 | { |
986 | struct cs_spec *spec = codec->spec; | |
987 | unsigned int def_conf, coef; | |
988 | ||
989 | /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */ | |
990 | coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG); | |
991 | ||
992 | if (spec->gpio_mask) | |
993 | coef |= 0x0008; /* B1,B2 are GPIOs */ | |
994 | else | |
995 | coef &= ~0x0008; | |
996 | ||
997 | if (spec->sense_b) | |
998 | coef |= 0x0010; /* B2 is SENSE_B, not inverted */ | |
999 | else | |
1000 | coef &= ~0x0010; | |
1001 | ||
1002 | cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef); | |
1003 | ||
1004 | if ((spec->gpio_mask || spec->sense_b) && | |
1005 | is_active_pin(codec, CS421X_DMIC_PIN_NID)) { | |
1006 | ||
1007 | /* | |
1008 | GPIO or SENSE_B forced - disconnect the DMIC pin. | |
1009 | */ | |
1010 | def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID); | |
1011 | def_conf &= ~AC_DEFCFG_PORT_CONN; | |
1012 | def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT); | |
1013 | snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf); | |
1014 | } | |
1015 | } | |
1016 | ||
1077a024 | 1017 | static void cs4210_spdif_automute(struct hda_codec *codec, |
1a4f69d5 | 1018 | struct hda_jack_callback *tbl) |
56487c27 TH |
1019 | { |
1020 | struct cs_spec *spec = codec->spec; | |
1077a024 TI |
1021 | bool spdif_present = false; |
1022 | hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0]; | |
1023 | ||
1024 | /* detect on spdif is specific to CS4210 */ | |
1025 | if (!spec->spdif_detect || | |
1026 | spec->vendor_nid != CS4210_VENDOR_NID) | |
1027 | return; | |
1028 | ||
1029 | spdif_present = snd_hda_jack_detect(codec, spdif_pin); | |
1030 | if (spdif_present == spec->spdif_present) | |
1031 | return; | |
1032 | ||
1033 | spec->spdif_present = spdif_present; | |
1034 | /* SPDIF TX on/off */ | |
44008f08 | 1035 | snd_hda_set_pin_ctl(codec, spdif_pin, spdif_present ? PIN_OUT : 0); |
56487c27 | 1036 | |
1077a024 TI |
1037 | cs_automute(codec); |
1038 | } | |
1039 | ||
1040 | static void parse_cs421x_digital(struct hda_codec *codec) | |
1041 | { | |
1042 | struct cs_spec *spec = codec->spec; | |
1043 | struct auto_pin_cfg *cfg = &spec->gen.autocfg; | |
1044 | int i; | |
56487c27 TH |
1045 | |
1046 | for (i = 0; i < cfg->dig_outs; i++) { | |
1047 | hda_nid_t nid = cfg->dig_out_pins[i]; | |
56487c27 | 1048 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { |
56487c27 | 1049 | spec->spdif_detect = 1; |
1077a024 | 1050 | snd_hda_jack_detect_enable_callback(codec, nid, |
1077a024 | 1051 | cs4210_spdif_automute); |
56487c27 TH |
1052 | } |
1053 | } | |
1054 | } | |
1055 | ||
1056 | static int cs421x_init(struct hda_codec *codec) | |
1057 | { | |
1058 | struct cs_spec *spec = codec->spec; | |
1059 | ||
5660ffd0 DH |
1060 | if (spec->vendor_nid == CS4210_VENDOR_NID) { |
1061 | snd_hda_sequence_write(codec, cs421x_coef_init_verbs); | |
1062 | snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes); | |
1063 | cs4210_pinmux_init(codec); | |
1064 | } | |
56487c27 | 1065 | |
1077a024 TI |
1066 | snd_hda_gen_init(codec); |
1067 | ||
56487c27 TH |
1068 | if (spec->gpio_mask) { |
1069 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, | |
1070 | spec->gpio_mask); | |
1071 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, | |
1072 | spec->gpio_dir); | |
1073 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, | |
1074 | spec->gpio_data); | |
1075 | } | |
1076 | ||
1077a024 | 1077 | init_input_coef(codec); |
56487c27 | 1078 | |
1077a024 | 1079 | cs4210_spdif_automute(codec, NULL); |
56487c27 TH |
1080 | |
1081 | return 0; | |
1082 | } | |
1083 | ||
1077a024 | 1084 | static int cs421x_build_controls(struct hda_codec *codec) |
56487c27 | 1085 | { |
56487c27 | 1086 | struct cs_spec *spec = codec->spec; |
56487c27 | 1087 | int err; |
56487c27 | 1088 | |
1077a024 | 1089 | err = snd_hda_gen_build_controls(codec); |
56487c27 TH |
1090 | if (err < 0) |
1091 | return err; | |
56487c27 | 1092 | |
1077a024 TI |
1093 | if (spec->gen.autocfg.speaker_outs && |
1094 | spec->vendor_nid == CS4210_VENDOR_NID) { | |
56487c27 | 1095 | err = snd_hda_ctl_add(codec, 0, |
1077a024 | 1096 | snd_ctl_new1(&cs421x_speaker_boost_ctl, codec)); |
56487c27 TH |
1097 | if (err < 0) |
1098 | return err; | |
1099 | } | |
01a61e12 | 1100 | return 0; |
56487c27 TH |
1101 | } |
1102 | ||
1077a024 | 1103 | static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) |
56487c27 | 1104 | { |
1077a024 | 1105 | unsigned int caps; |
56487c27 | 1106 | |
1077a024 TI |
1107 | /* set the upper-limit for mixer amp to 0dB */ |
1108 | caps = query_amp_caps(codec, dac, HDA_OUTPUT); | |
1109 | caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT); | |
1110 | caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f) | |
1111 | << AC_AMPCAP_NUM_STEPS_SHIFT; | |
1112 | snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps); | |
56487c27 TH |
1113 | } |
1114 | ||
1115 | static int cs421x_parse_auto_config(struct hda_codec *codec) | |
1116 | { | |
1117 | struct cs_spec *spec = codec->spec; | |
1077a024 | 1118 | hda_nid_t dac = CS4210_DAC_NID; |
56487c27 TH |
1119 | int err; |
1120 | ||
1077a024 TI |
1121 | fix_volume_caps(codec, dac); |
1122 | ||
1123 | err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); | |
56487c27 TH |
1124 | if (err < 0) |
1125 | return err; | |
1077a024 TI |
1126 | |
1127 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); | |
56487c27 TH |
1128 | if (err < 0) |
1129 | return err; | |
1077a024 TI |
1130 | |
1131 | parse_cs421x_digital(codec); | |
56487c27 TH |
1132 | return 0; |
1133 | } | |
1134 | ||
1135 | #ifdef CONFIG_PM | |
1136 | /* | |
1137 | Manage PDREF, when transitioning to D3hot | |
1138 | (DAC,ADC) -> D3, PDREF=1, AFG->D3 | |
1139 | */ | |
68cb2b55 | 1140 | static int cs421x_suspend(struct hda_codec *codec) |
56487c27 | 1141 | { |
5660ffd0 | 1142 | struct cs_spec *spec = codec->spec; |
56487c27 TH |
1143 | unsigned int coef; |
1144 | ||
1145 | snd_hda_shutup_pins(codec); | |
1146 | ||
1147 | snd_hda_codec_write(codec, CS4210_DAC_NID, 0, | |
1148 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
1149 | snd_hda_codec_write(codec, CS4210_ADC_NID, 0, | |
1150 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
1151 | ||
5660ffd0 DH |
1152 | if (spec->vendor_nid == CS4210_VENDOR_NID) { |
1153 | coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG); | |
1154 | coef |= 0x0004; /* PDREF */ | |
1155 | cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef); | |
1156 | } | |
56487c27 TH |
1157 | |
1158 | return 0; | |
1159 | } | |
1160 | #endif | |
1161 | ||
00e17f76 | 1162 | static const struct hda_codec_ops cs421x_patch_ops = { |
56487c27 | 1163 | .build_controls = cs421x_build_controls, |
1077a024 | 1164 | .build_pcms = snd_hda_gen_build_pcms, |
56487c27 TH |
1165 | .init = cs421x_init, |
1166 | .free = cs_free, | |
5c2e4e0a | 1167 | .unsol_event = snd_hda_jack_unsol_event, |
56487c27 TH |
1168 | #ifdef CONFIG_PM |
1169 | .suspend = cs421x_suspend, | |
1170 | #endif | |
1171 | }; | |
1172 | ||
5660ffd0 | 1173 | static int patch_cs4210(struct hda_codec *codec) |
56487c27 TH |
1174 | { |
1175 | struct cs_spec *spec; | |
1176 | int err; | |
1177 | ||
1077a024 | 1178 | spec = cs_alloc_spec(codec, CS4210_VENDOR_NID); |
56487c27 TH |
1179 | if (!spec) |
1180 | return -ENOMEM; | |
56487c27 | 1181 | |
225068ab | 1182 | codec->patch_ops = cs421x_patch_ops; |
6d3073e1 TI |
1183 | spec->gen.automute_hook = cs_automute; |
1184 | ||
b35aabd7 TI |
1185 | snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl, |
1186 | cs421x_fixups); | |
1187 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); | |
56487c27 TH |
1188 | |
1189 | /* | |
1190 | Update the GPIO/DMIC/SENSE_B pinmux before the configuration | |
1191 | is auto-parsed. If GPIO or SENSE_B is forced, DMIC input | |
1192 | is disabled. | |
1193 | */ | |
5660ffd0 | 1194 | cs4210_pinmux_init(codec); |
56487c27 TH |
1195 | |
1196 | err = cs421x_parse_auto_config(codec); | |
1197 | if (err < 0) | |
1198 | goto error; | |
1199 | ||
b35aabd7 TI |
1200 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
1201 | ||
5660ffd0 DH |
1202 | return 0; |
1203 | ||
1204 | error: | |
c5e0b6db | 1205 | cs_free(codec); |
5660ffd0 DH |
1206 | return err; |
1207 | } | |
1208 | ||
1209 | static int patch_cs4213(struct hda_codec *codec) | |
1210 | { | |
1211 | struct cs_spec *spec; | |
1212 | int err; | |
1213 | ||
1077a024 | 1214 | spec = cs_alloc_spec(codec, CS4213_VENDOR_NID); |
5660ffd0 DH |
1215 | if (!spec) |
1216 | return -ENOMEM; | |
5660ffd0 | 1217 | |
225068ab TI |
1218 | codec->patch_ops = cs421x_patch_ops; |
1219 | ||
5660ffd0 DH |
1220 | err = cs421x_parse_auto_config(codec); |
1221 | if (err < 0) | |
1222 | goto error; | |
56487c27 TH |
1223 | |
1224 | return 0; | |
1225 | ||
1226 | error: | |
c5e0b6db | 1227 | cs_free(codec); |
56487c27 TH |
1228 | return err; |
1229 | } | |
1230 | ||
e5f14248 TI |
1231 | |
1232 | /* | |
1233 | * patch entries | |
1234 | */ | |
b9a94a9c TI |
1235 | static const struct hda_device_id snd_hda_id_cirrus[] = { |
1236 | HDA_CODEC_ENTRY(0x10134206, "CS4206", patch_cs420x), | |
1237 | HDA_CODEC_ENTRY(0x10134207, "CS4207", patch_cs420x), | |
1238 | HDA_CODEC_ENTRY(0x10134208, "CS4208", patch_cs4208), | |
1239 | HDA_CODEC_ENTRY(0x10134210, "CS4210", patch_cs4210), | |
1240 | HDA_CODEC_ENTRY(0x10134213, "CS4213", patch_cs4213), | |
e5f14248 TI |
1241 | {} /* terminator */ |
1242 | }; | |
b9a94a9c | 1243 | MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_cirrus); |
e5f14248 TI |
1244 | |
1245 | MODULE_LICENSE("GPL"); | |
1246 | MODULE_DESCRIPTION("Cirrus Logic HD-audio codec"); | |
1247 | ||
d8a766a1 | 1248 | static struct hda_codec_driver cirrus_driver = { |
b9a94a9c | 1249 | .id = snd_hda_id_cirrus, |
e5f14248 TI |
1250 | }; |
1251 | ||
d8a766a1 | 1252 | module_hda_codec_driver(cirrus_driver); |