Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HD audio interface patch for Cirrus Logic CS420x chip |
| 3 | * |
| 4 | * Copyright (c) 2009 Takashi Iwai <tiwai@suse.de> |
| 5 | * |
| 6 | * This driver is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This driver is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/init.h> |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 22 | #include <linux/slab.h> |
| 23 | #include <linux/pci.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 25 | #include <sound/core.h> |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 26 | #include <sound/tlv.h> |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 27 | #include "hda_codec.h" |
| 28 | #include "hda_local.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 29 | #include "hda_auto_parser.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 30 | #include "hda_jack.h" |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 31 | #include "hda_generic.h" |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | */ |
| 35 | |
| 36 | struct cs_spec { |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 37 | struct hda_gen_spec gen; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 38 | |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 39 | unsigned int gpio_mask; |
| 40 | unsigned int gpio_dir; |
| 41 | unsigned int gpio_data; |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 42 | unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */ |
| 43 | unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */ |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 44 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 45 | /* CS421x */ |
| 46 | unsigned int spdif_detect:1; |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 47 | unsigned int spdif_present:1; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 48 | unsigned int sense_b:1; |
| 49 | hda_nid_t vendor_nid; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 52 | /* available models with CS420x */ |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 53 | enum { |
Vince Weaver | 4e7d7c6 | 2010-09-22 17:31:37 -0400 | [diff] [blame] | 54 | CS420X_MBP53, |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 55 | CS420X_MBP55, |
Rafael Avila de Espindola | 1a5ba2e | 2009-12-22 07:59:37 +0100 | [diff] [blame] | 56 | CS420X_IMAC27, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 57 | CS420X_GPIO_13, |
| 58 | CS420X_GPIO_23, |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 59 | CS420X_MBP101, |
Takashi Iwai | ffe4d12b | 2012-11-23 08:34:13 +0100 | [diff] [blame] | 60 | CS420X_MBP81, |
Takashi Iwai | 6ab982e | 2013-06-17 10:19:49 +0200 | [diff] [blame] | 61 | CS420X_MBA42, |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 62 | CS420X_AUTO, |
Takashi Iwai | 03efce7 | 2012-09-13 09:56:57 +0200 | [diff] [blame] | 63 | /* aliases */ |
| 64 | CS420X_IMAC27_122 = CS420X_GPIO_23, |
| 65 | CS420X_APPLE = CS420X_GPIO_13, |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 68 | /* CS421x boards */ |
| 69 | enum { |
| 70 | CS421X_CDB4210, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 71 | CS421X_SENSE_B, |
Dylan Reid | 4af16107 | 2013-04-04 15:35:31 -0700 | [diff] [blame] | 72 | CS421X_STUMPY, |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 73 | }; |
| 74 | |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 75 | /* Vendor-specific processing widget */ |
| 76 | #define CS420X_VENDOR_NID 0x11 |
| 77 | #define CS_DIG_OUT1_PIN_NID 0x10 |
| 78 | #define CS_DIG_OUT2_PIN_NID 0x15 |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 79 | #define CS_DMIC1_PIN_NID 0x0e |
| 80 | #define CS_DMIC2_PIN_NID 0x12 |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 81 | |
| 82 | /* coef indices */ |
| 83 | #define IDX_SPDIF_STAT 0x0000 |
| 84 | #define IDX_SPDIF_CTL 0x0001 |
| 85 | #define IDX_ADC_CFG 0x0002 |
| 86 | /* SZC bitmask, 4 modes below: |
| 87 | * 0 = immediate, |
| 88 | * 1 = digital immediate, analog zero-cross |
| 89 | * 2 = digtail & analog soft-ramp |
| 90 | * 3 = digital soft-ramp, analog zero-cross |
| 91 | */ |
| 92 | #define CS_COEF_ADC_SZC_MASK (3 << 0) |
| 93 | #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */ |
| 94 | #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */ |
| 95 | /* PGA mode: 0 = differential, 1 = signle-ended */ |
| 96 | #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */ |
| 97 | #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */ |
| 98 | #define IDX_DAC_CFG 0x0003 |
| 99 | /* SZC bitmask, 4 modes below: |
| 100 | * 0 = Immediate |
| 101 | * 1 = zero-cross |
| 102 | * 2 = soft-ramp |
| 103 | * 3 = soft-ramp on zero-cross |
| 104 | */ |
| 105 | #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */ |
| 106 | #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */ |
| 107 | #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */ |
| 108 | |
| 109 | #define IDX_BEEP_CFG 0x0004 |
| 110 | /* 0x0008 - test reg key */ |
| 111 | /* 0x0009 - 0x0014 -> 12 test regs */ |
| 112 | /* 0x0015 - visibility reg */ |
| 113 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 114 | /* |
| 115 | * Cirrus Logic CS4210 |
| 116 | * |
| 117 | * 1 DAC => HP(sense) / Speakers, |
| 118 | * 1 ADC <= LineIn(sense) / MicIn / DMicIn, |
| 119 | * 1 SPDIF OUT => SPDIF Trasmitter(sense) |
| 120 | */ |
| 121 | #define CS4210_DAC_NID 0x02 |
| 122 | #define CS4210_ADC_NID 0x03 |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 123 | #define CS4210_VENDOR_NID 0x0B |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 124 | #define CS421X_DMIC_PIN_NID 0x09 /* Port E */ |
| 125 | #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */ |
| 126 | |
| 127 | #define CS421X_IDX_DEV_CFG 0x01 |
| 128 | #define CS421X_IDX_ADC_CFG 0x02 |
| 129 | #define CS421X_IDX_DAC_CFG 0x03 |
| 130 | #define CS421X_IDX_SPK_CTL 0x04 |
| 131 | |
| 132 | #define SPDIF_EVENT 0x04 |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 133 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 134 | /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */ |
| 135 | #define CS4213_VENDOR_NID 0x09 |
| 136 | |
| 137 | |
Takashi Iwai | 277a57c | 2009-07-08 12:42:08 +0200 | [diff] [blame] | 138 | static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx) |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 139 | { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 140 | struct cs_spec *spec = codec->spec; |
| 141 | snd_hda_codec_write(codec, spec->vendor_nid, 0, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 142 | AC_VERB_SET_COEF_INDEX, idx); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 143 | return snd_hda_codec_read(codec, spec->vendor_nid, 0, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 144 | AC_VERB_GET_PROC_COEF, 0); |
| 145 | } |
| 146 | |
Takashi Iwai | 277a57c | 2009-07-08 12:42:08 +0200 | [diff] [blame] | 147 | static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx, |
| 148 | unsigned int coef) |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 149 | { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 150 | struct cs_spec *spec = codec->spec; |
| 151 | snd_hda_codec_write(codec, spec->vendor_nid, 0, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 152 | AC_VERB_SET_COEF_INDEX, idx); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 153 | snd_hda_codec_write(codec, spec->vendor_nid, 0, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 154 | AC_VERB_SET_PROC_COEF, coef); |
| 155 | } |
| 156 | |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 157 | /* |
| 158 | * auto-mute and auto-mic switching |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 159 | * CS421x auto-output redirecting |
| 160 | * HP/SPK/SPDIF |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 161 | */ |
| 162 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 163 | static void cs_automute(struct hda_codec *codec) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 164 | { |
| 165 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 166 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 167 | /* mute HPs if spdif jack (SENSE_B) is present */ |
| 168 | spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 169 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 170 | snd_hda_gen_update_outputs(codec); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 171 | |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 172 | if (spec->gpio_eapd_hp) { |
Takashi Iwai | 039eb75 | 2013-03-18 16:55:49 +0100 | [diff] [blame] | 173 | spec->gpio_data = spec->gen.hp_jack_present ? |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 174 | spec->gpio_eapd_hp : spec->gpio_eapd_speaker; |
Stelian Pop | 3a38516 | 2009-07-30 14:44:27 +0200 | [diff] [blame] | 175 | snd_hda_codec_write(codec, 0x01, 0, |
Takashi Iwai | 039eb75 | 2013-03-18 16:55:49 +0100 | [diff] [blame] | 176 | AC_VERB_SET_GPIO_DATA, spec->gpio_data); |
Stelian Pop | 3a38516 | 2009-07-30 14:44:27 +0200 | [diff] [blame] | 177 | } |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 180 | static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 181 | { |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 182 | unsigned int val; |
| 183 | val = snd_hda_codec_get_pincfg(codec, nid); |
| 184 | return (get_defcfg_connect(val) != AC_JACK_PORT_NONE); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 187 | static void init_input_coef(struct hda_codec *codec) |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 188 | { |
| 189 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 190 | unsigned int coef; |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 191 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 192 | /* CS420x has multiple ADC, CS421x has single ADC */ |
| 193 | if (spec->vendor_nid == CS420X_VENDOR_NID) { |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 194 | coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 195 | if (is_active_pin(codec, CS_DMIC2_PIN_NID)) |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 196 | coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */ |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 197 | if (is_active_pin(codec, CS_DMIC1_PIN_NID)) |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 198 | coef |= 1 << 3; /* DMIC1 2 chan on, GPIO0 off |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 199 | * No effect if SPDIF_OUT2 is |
| 200 | * selected in IDX_SPDIF_CTL. |
| 201 | */ |
Daniel J Blueman | 16337e0 | 2012-11-04 13:19:03 +0800 | [diff] [blame] | 202 | |
| 203 | cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 204 | } |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 207 | static const struct hda_verb cs_coef_init_verbs[] = { |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 208 | {0x11, AC_VERB_SET_PROC_STATE, 1}, |
| 209 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG}, |
| 210 | {0x11, AC_VERB_SET_PROC_COEF, |
| 211 | (0x002a /* DAC1/2/3 SZCMode Soft Ramp */ |
| 212 | | 0x0040 /* Mute DACs on FIFO error */ |
| 213 | | 0x1000 /* Enable DACs High Pass Filter */ |
| 214 | | 0x0400 /* Disable Coefficient Auto increment */ |
| 215 | )}, |
Takashi Iwai | 829e87e | 2012-11-23 08:25:25 +0100 | [diff] [blame] | 216 | /* ADC1/2 - Digital and Analog Soft Ramp */ |
| 217 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG}, |
| 218 | {0x11, AC_VERB_SET_PROC_COEF, 0x000a}, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 219 | /* Beep */ |
Alexander Stein | 5a83b4b | 2012-11-01 13:42:37 +0100 | [diff] [blame] | 220 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_BEEP_CFG}, |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 221 | {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */ |
| 222 | |
| 223 | {} /* terminator */ |
| 224 | }; |
| 225 | |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 226 | /* Errata: CS4207 rev C0/C1/C2 Silicon |
| 227 | * |
| 228 | * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf |
| 229 | * |
| 230 | * 6. At high temperature (TA > +85°C), the digital supply current (IVD) |
| 231 | * may be excessive (up to an additional 200 μA), which is most easily |
| 232 | * observed while the part is being held in reset (RESET# active low). |
| 233 | * |
| 234 | * Root Cause: At initial powerup of the device, the logic that drives |
| 235 | * the clock and write enable to the S/PDIF SRC RAMs is not properly |
| 236 | * initialized. |
| 237 | * Certain random patterns will cause a steady leakage current in those |
| 238 | * RAM cells. The issue will resolve once the SRCs are used (turned on). |
| 239 | * |
| 240 | * Workaround: The following verb sequence briefly turns on the S/PDIF SRC |
| 241 | * blocks, which will alleviate the issue. |
| 242 | */ |
| 243 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 244 | static const struct hda_verb cs_errata_init_verbs[] = { |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 245 | {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */ |
| 246 | {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */ |
| 247 | |
| 248 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0008}, |
| 249 | {0x11, AC_VERB_SET_PROC_COEF, 0x9999}, |
| 250 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0017}, |
| 251 | {0x11, AC_VERB_SET_PROC_COEF, 0xa412}, |
| 252 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0001}, |
| 253 | {0x11, AC_VERB_SET_PROC_COEF, 0x0009}, |
| 254 | |
| 255 | {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */ |
| 256 | {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */ |
| 257 | |
| 258 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0017}, |
| 259 | {0x11, AC_VERB_SET_PROC_COEF, 0x2412}, |
| 260 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0008}, |
| 261 | {0x11, AC_VERB_SET_PROC_COEF, 0x0000}, |
| 262 | {0x11, AC_VERB_SET_COEF_INDEX, 0x0001}, |
| 263 | {0x11, AC_VERB_SET_PROC_COEF, 0x0008}, |
| 264 | {0x11, AC_VERB_SET_PROC_STATE, 0x00}, |
| 265 | |
Takashi Iwai | 38c0764 | 2011-03-03 14:54:19 +0100 | [diff] [blame] | 266 | #if 0 /* Don't to set to D3 as we are in power-up sequence */ |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 267 | {0x07, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Rx: D3 */ |
| 268 | {0x08, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Tx: D3 */ |
| 269 | /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */ |
Takashi Iwai | 38c0764 | 2011-03-03 14:54:19 +0100 | [diff] [blame] | 270 | #endif |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 271 | |
| 272 | {} /* terminator */ |
| 273 | }; |
| 274 | |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 275 | /* SPDIF setup */ |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 276 | static void init_digital_coef(struct hda_codec *codec) |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 277 | { |
| 278 | unsigned int coef; |
| 279 | |
| 280 | coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */ |
| 281 | coef |= 0x0008; /* Replace with mute on error */ |
| 282 | if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID)) |
| 283 | coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2 |
| 284 | * SPDIF_OUT2 is shared with GPIO1 and |
| 285 | * DMIC_SDA2. |
| 286 | */ |
| 287 | cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static int cs_init(struct hda_codec *codec) |
| 291 | { |
| 292 | struct cs_spec *spec = codec->spec; |
| 293 | |
Brian Austin | a769cbc | 2010-09-07 14:36:22 -0500 | [diff] [blame] | 294 | /* init_verb sequence for C0/C1/C2 errata*/ |
| 295 | snd_hda_sequence_write(codec, cs_errata_init_verbs); |
| 296 | |
Takashi Iwai | 40c20fa | 2009-07-06 13:00:57 +0200 | [diff] [blame] | 297 | snd_hda_sequence_write(codec, cs_coef_init_verbs); |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 298 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 299 | snd_hda_gen_init(codec); |
Takashi Iwai | 98415ea | 2012-11-23 08:26:58 +0100 | [diff] [blame] | 300 | |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 301 | if (spec->gpio_mask) { |
| 302 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, |
| 303 | spec->gpio_mask); |
| 304 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, |
| 305 | spec->gpio_dir); |
| 306 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, |
| 307 | spec->gpio_data); |
| 308 | } |
| 309 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 310 | init_input_coef(codec); |
| 311 | init_digital_coef(codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 312 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 316 | #define cs_free snd_hda_gen_free |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 317 | |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 318 | static const struct hda_codec_ops cs_patch_ops = { |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 319 | .build_controls = snd_hda_gen_build_controls, |
| 320 | .build_pcms = snd_hda_gen_build_pcms, |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 321 | .init = cs_init, |
| 322 | .free = cs_free, |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 323 | .unsol_event = snd_hda_jack_unsol_event, |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | static int cs_parse_auto_config(struct hda_codec *codec) |
| 327 | { |
| 328 | struct cs_spec *spec = codec->spec; |
| 329 | int err; |
| 330 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 331 | err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 332 | if (err < 0) |
| 333 | return err; |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 334 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 335 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 336 | if (err < 0) |
| 337 | return err; |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 338 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 339 | return 0; |
| 340 | } |
| 341 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 342 | static const struct hda_model_fixup cs420x_models[] = { |
| 343 | { .id = CS420X_MBP53, .name = "mbp53" }, |
| 344 | { .id = CS420X_MBP55, .name = "mbp55" }, |
| 345 | { .id = CS420X_IMAC27, .name = "imac27" }, |
| 346 | { .id = CS420X_IMAC27_122, .name = "imac27_122" }, |
| 347 | { .id = CS420X_APPLE, .name = "apple" }, |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 348 | { .id = CS420X_MBP101, .name = "mbp101" }, |
Takashi Iwai | ffe4d12b | 2012-11-23 08:34:13 +0100 | [diff] [blame] | 349 | { .id = CS420X_MBP81, .name = "mbp81" }, |
Takashi Iwai | 6ab982e | 2013-06-17 10:19:49 +0200 | [diff] [blame] | 350 | { .id = CS420X_MBA42, .name = "mba42" }, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 351 | {} |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 352 | }; |
| 353 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 354 | static const struct snd_pci_quirk cs420x_fixup_tbl[] = { |
Vince Weaver | 4e7d7c6 | 2010-09-22 17:31:37 -0400 | [diff] [blame] | 355 | SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53), |
Edgar (gimli) Hucek | 87232dd | 2010-11-03 08:14:10 +0100 | [diff] [blame] | 356 | SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55), |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 357 | SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55), |
Takashi Iwai | f46119b | 2010-10-11 14:46:35 +0200 | [diff] [blame] | 358 | SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55), |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 359 | /* this conflicts with too many other models */ |
| 360 | /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/ |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 361 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 362 | /* codec SSID */ |
Takashi Iwai | ffe4d12b | 2012-11-23 08:34:13 +0100 | [diff] [blame] | 363 | SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81), |
Jérémy Lal | 7e5bea1 | 2012-01-09 17:19:45 +0100 | [diff] [blame] | 364 | SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122), |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 365 | SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101), |
Takashi Iwai | 6ab982e | 2013-06-17 10:19:49 +0200 | [diff] [blame] | 366 | SND_PCI_QUIRK(0x106b, 0x5b00, "MacBookAir 4,2", CS420X_MBA42), |
Takashi Iwai | 6dfeb703 | 2011-11-22 20:00:31 +0100 | [diff] [blame] | 367 | SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE), |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 368 | {} /* terminator */ |
| 369 | }; |
| 370 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 371 | static const struct hda_pintbl mbp53_pincfgs[] = { |
Vince Weaver | 4e7d7c6 | 2010-09-22 17:31:37 -0400 | [diff] [blame] | 372 | { 0x09, 0x012b4050 }, |
| 373 | { 0x0a, 0x90100141 }, |
| 374 | { 0x0b, 0x90100140 }, |
| 375 | { 0x0c, 0x018b3020 }, |
| 376 | { 0x0d, 0x90a00110 }, |
| 377 | { 0x0e, 0x400000f0 }, |
| 378 | { 0x0f, 0x01cbe030 }, |
| 379 | { 0x10, 0x014be060 }, |
| 380 | { 0x12, 0x400000f0 }, |
| 381 | { 0x15, 0x400000f0 }, |
| 382 | {} /* terminator */ |
| 383 | }; |
| 384 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 385 | static const struct hda_pintbl mbp55_pincfgs[] = { |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 386 | { 0x09, 0x012b4030 }, |
| 387 | { 0x0a, 0x90100121 }, |
| 388 | { 0x0b, 0x90100120 }, |
| 389 | { 0x0c, 0x400000f0 }, |
| 390 | { 0x0d, 0x90a00110 }, |
| 391 | { 0x0e, 0x400000f0 }, |
| 392 | { 0x0f, 0x400000f0 }, |
| 393 | { 0x10, 0x014be040 }, |
| 394 | { 0x12, 0x400000f0 }, |
| 395 | { 0x15, 0x400000f0 }, |
| 396 | {} /* terminator */ |
| 397 | }; |
| 398 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 399 | static const struct hda_pintbl imac27_pincfgs[] = { |
Rafael Avila de Espindola | 1a5ba2e | 2009-12-22 07:59:37 +0100 | [diff] [blame] | 400 | { 0x09, 0x012b4050 }, |
| 401 | { 0x0a, 0x90100140 }, |
| 402 | { 0x0b, 0x90100142 }, |
| 403 | { 0x0c, 0x018b3020 }, |
| 404 | { 0x0d, 0x90a00110 }, |
| 405 | { 0x0e, 0x400000f0 }, |
| 406 | { 0x0f, 0x01cbe030 }, |
| 407 | { 0x10, 0x014be060 }, |
| 408 | { 0x12, 0x01ab9070 }, |
| 409 | { 0x15, 0x400000f0 }, |
| 410 | {} /* terminator */ |
| 411 | }; |
| 412 | |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 413 | static const struct hda_pintbl mbp101_pincfgs[] = { |
| 414 | { 0x0d, 0x40ab90f0 }, |
| 415 | { 0x0e, 0x90a600f0 }, |
| 416 | { 0x12, 0x50a600f0 }, |
| 417 | {} /* terminator */ |
| 418 | }; |
| 419 | |
Takashi Iwai | 6ab982e | 2013-06-17 10:19:49 +0200 | [diff] [blame] | 420 | static const struct hda_pintbl mba42_pincfgs[] = { |
| 421 | { 0x09, 0x012b4030 }, /* HP */ |
| 422 | { 0x0a, 0x400000f0 }, |
| 423 | { 0x0b, 0x90100120 }, /* speaker */ |
| 424 | { 0x0c, 0x400000f0 }, |
| 425 | { 0x0d, 0x90a00110 }, /* mic */ |
| 426 | { 0x0e, 0x400000f0 }, |
| 427 | { 0x0f, 0x400000f0 }, |
| 428 | { 0x10, 0x400000f0 }, |
| 429 | { 0x12, 0x400000f0 }, |
| 430 | { 0x15, 0x400000f0 }, |
| 431 | {} /* terminator */ |
| 432 | }; |
| 433 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 434 | static void cs420x_fixup_gpio_13(struct hda_codec *codec, |
| 435 | const struct hda_fixup *fix, int action) |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 436 | { |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 437 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
| 438 | struct cs_spec *spec = codec->spec; |
| 439 | spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */ |
| 440 | spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */ |
| 441 | spec->gpio_mask = spec->gpio_dir = |
| 442 | spec->gpio_eapd_hp | spec->gpio_eapd_speaker; |
| 443 | } |
Takashi Iwai | a6bae20 | 2009-07-06 15:15:22 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 446 | static void cs420x_fixup_gpio_23(struct hda_codec *codec, |
| 447 | const struct hda_fixup *fix, int action) |
| 448 | { |
| 449 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
| 450 | struct cs_spec *spec = codec->spec; |
| 451 | spec->gpio_eapd_hp = 4; /* GPIO2 = headphones */ |
| 452 | spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */ |
| 453 | spec->gpio_mask = spec->gpio_dir = |
| 454 | spec->gpio_eapd_hp | spec->gpio_eapd_speaker; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | static const struct hda_fixup cs420x_fixups[] = { |
| 459 | [CS420X_MBP53] = { |
| 460 | .type = HDA_FIXUP_PINS, |
| 461 | .v.pins = mbp53_pincfgs, |
| 462 | .chained = true, |
| 463 | .chain_id = CS420X_APPLE, |
| 464 | }, |
| 465 | [CS420X_MBP55] = { |
| 466 | .type = HDA_FIXUP_PINS, |
| 467 | .v.pins = mbp55_pincfgs, |
| 468 | .chained = true, |
| 469 | .chain_id = CS420X_GPIO_13, |
| 470 | }, |
| 471 | [CS420X_IMAC27] = { |
| 472 | .type = HDA_FIXUP_PINS, |
| 473 | .v.pins = imac27_pincfgs, |
| 474 | .chained = true, |
| 475 | .chain_id = CS420X_GPIO_13, |
| 476 | }, |
| 477 | [CS420X_GPIO_13] = { |
| 478 | .type = HDA_FIXUP_FUNC, |
| 479 | .v.func = cs420x_fixup_gpio_13, |
| 480 | }, |
| 481 | [CS420X_GPIO_23] = { |
| 482 | .type = HDA_FIXUP_FUNC, |
| 483 | .v.func = cs420x_fixup_gpio_23, |
| 484 | }, |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 485 | [CS420X_MBP101] = { |
| 486 | .type = HDA_FIXUP_PINS, |
| 487 | .v.pins = mbp101_pincfgs, |
| 488 | .chained = true, |
Takashi Iwai | ef596a5 | 2012-09-11 16:53:08 +0200 | [diff] [blame] | 489 | .chain_id = CS420X_GPIO_13, |
| 490 | }, |
Takashi Iwai | ffe4d12b | 2012-11-23 08:34:13 +0100 | [diff] [blame] | 491 | [CS420X_MBP81] = { |
| 492 | .type = HDA_FIXUP_VERBS, |
| 493 | .v.verbs = (const struct hda_verb[]) { |
| 494 | /* internal mic ADC2: right only, single ended */ |
| 495 | {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG}, |
| 496 | {0x11, AC_VERB_SET_PROC_COEF, 0x102a}, |
| 497 | {} |
| 498 | }, |
| 499 | .chained = true, |
| 500 | .chain_id = CS420X_GPIO_13, |
| 501 | }, |
Takashi Iwai | 6ab982e | 2013-06-17 10:19:49 +0200 | [diff] [blame] | 502 | [CS420X_MBA42] = { |
| 503 | .type = HDA_FIXUP_PINS, |
| 504 | .v.pins = mba42_pincfgs, |
| 505 | .chained = true, |
| 506 | .chain_id = CS420X_GPIO_13, |
| 507 | }, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 508 | }; |
| 509 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 510 | static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid) |
| 511 | { |
| 512 | struct cs_spec *spec; |
| 513 | |
| 514 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 515 | if (!spec) |
| 516 | return NULL; |
| 517 | codec->spec = spec; |
| 518 | spec->vendor_nid = vendor_nid; |
| 519 | snd_hda_gen_spec_init(&spec->gen); |
| 520 | |
| 521 | return spec; |
| 522 | } |
| 523 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 524 | static int patch_cs420x(struct hda_codec *codec) |
| 525 | { |
| 526 | struct cs_spec *spec; |
| 527 | int err; |
| 528 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 529 | spec = cs_alloc_spec(codec, CS420X_VENDOR_NID); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 530 | if (!spec) |
| 531 | return -ENOMEM; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 532 | |
Takashi Iwai | 6d3073e | 2013-03-15 14:23:32 +0100 | [diff] [blame] | 533 | spec->gen.automute_hook = cs_automute; |
| 534 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 535 | snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl, |
| 536 | cs420x_fixups); |
| 537 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 538 | |
Takashi Iwai | ed20825 | 2009-07-07 09:04:26 +0200 | [diff] [blame] | 539 | err = cs_parse_auto_config(codec); |
Takashi Iwai | 21a4dc4 | 2009-07-06 12:55:46 +0200 | [diff] [blame] | 540 | if (err < 0) |
| 541 | goto error; |
| 542 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 543 | codec->patch_ops = cs_patch_ops; |
| 544 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 545 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
| 546 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 547 | return 0; |
| 548 | |
| 549 | error: |
Takashi Iwai | c5e0b6d | 2012-10-10 08:50:35 +0200 | [diff] [blame] | 550 | cs_free(codec); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 551 | return err; |
| 552 | } |
| 553 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 554 | /* |
| 555 | * Cirrus Logic CS4210 |
| 556 | * |
| 557 | * 1 DAC => HP(sense) / Speakers, |
| 558 | * 1 ADC <= LineIn(sense) / MicIn / DMicIn, |
| 559 | * 1 SPDIF OUT => SPDIF Trasmitter(sense) |
| 560 | */ |
| 561 | |
| 562 | /* CS4210 board names */ |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 563 | static const struct hda_model_fixup cs421x_models[] = { |
| 564 | { .id = CS421X_CDB4210, .name = "cdb4210" }, |
Dylan Reid | 4af16107 | 2013-04-04 15:35:31 -0700 | [diff] [blame] | 565 | { .id = CS421X_STUMPY, .name = "stumpy" }, |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 566 | {} |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 567 | }; |
| 568 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 569 | static const struct snd_pci_quirk cs421x_fixup_tbl[] = { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 570 | /* Test Intel board + CDB2410 */ |
| 571 | SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210), |
| 572 | {} /* terminator */ |
| 573 | }; |
| 574 | |
| 575 | /* CS4210 board pinconfigs */ |
| 576 | /* Default CS4210 (CDB4210)*/ |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 577 | static const struct hda_pintbl cdb4210_pincfgs[] = { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 578 | { 0x05, 0x0321401f }, |
| 579 | { 0x06, 0x90170010 }, |
| 580 | { 0x07, 0x03813031 }, |
| 581 | { 0x08, 0xb7a70037 }, |
| 582 | { 0x09, 0xb7a6003e }, |
| 583 | { 0x0a, 0x034510f0 }, |
| 584 | {} /* terminator */ |
| 585 | }; |
| 586 | |
Dylan Reid | 4af16107 | 2013-04-04 15:35:31 -0700 | [diff] [blame] | 587 | /* Stumpy ChromeBox */ |
| 588 | static const struct hda_pintbl stumpy_pincfgs[] = { |
| 589 | { 0x05, 0x022120f0 }, |
| 590 | { 0x06, 0x901700f0 }, |
| 591 | { 0x07, 0x02a120f0 }, |
| 592 | { 0x08, 0x77a70037 }, |
| 593 | { 0x09, 0x77a6003e }, |
| 594 | { 0x0a, 0x434510f0 }, |
| 595 | {} /* terminator */ |
| 596 | }; |
| 597 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 598 | /* Setup GPIO/SENSE for each board (if used) */ |
| 599 | static void cs421x_fixup_sense_b(struct hda_codec *codec, |
| 600 | const struct hda_fixup *fix, int action) |
| 601 | { |
| 602 | struct cs_spec *spec = codec->spec; |
| 603 | if (action == HDA_FIXUP_ACT_PRE_PROBE) |
| 604 | spec->sense_b = 1; |
| 605 | } |
| 606 | |
| 607 | static const struct hda_fixup cs421x_fixups[] = { |
| 608 | [CS421X_CDB4210] = { |
| 609 | .type = HDA_FIXUP_PINS, |
| 610 | .v.pins = cdb4210_pincfgs, |
| 611 | .chained = true, |
| 612 | .chain_id = CS421X_SENSE_B, |
| 613 | }, |
| 614 | [CS421X_SENSE_B] = { |
| 615 | .type = HDA_FIXUP_FUNC, |
| 616 | .v.func = cs421x_fixup_sense_b, |
Dylan Reid | 4af16107 | 2013-04-04 15:35:31 -0700 | [diff] [blame] | 617 | }, |
| 618 | [CS421X_STUMPY] = { |
| 619 | .type = HDA_FIXUP_PINS, |
| 620 | .v.pins = stumpy_pincfgs, |
| 621 | }, |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 622 | }; |
| 623 | |
| 624 | static const struct hda_verb cs421x_coef_init_verbs[] = { |
| 625 | {0x0B, AC_VERB_SET_PROC_STATE, 1}, |
| 626 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG}, |
| 627 | /* |
| 628 | Disable Coefficient Index Auto-Increment(DAI)=1, |
| 629 | PDREF=0 |
| 630 | */ |
| 631 | {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 }, |
| 632 | |
| 633 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG}, |
| 634 | /* ADC SZCMode = Digital Soft Ramp */ |
| 635 | {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 }, |
| 636 | |
| 637 | {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG}, |
| 638 | {0x0B, AC_VERB_SET_PROC_COEF, |
| 639 | (0x0002 /* DAC SZCMode = Digital Soft Ramp */ |
| 640 | | 0x0004 /* Mute DAC on FIFO error */ |
| 641 | | 0x0008 /* Enable DAC High Pass Filter */ |
| 642 | )}, |
| 643 | {} /* terminator */ |
| 644 | }; |
| 645 | |
| 646 | /* Errata: CS4210 rev A1 Silicon |
| 647 | * |
| 648 | * http://www.cirrus.com/en/pubs/errata/ |
| 649 | * |
| 650 | * Description: |
| 651 | * 1. Performance degredation is present in the ADC. |
| 652 | * 2. Speaker output is not completely muted upon HP detect. |
| 653 | * 3. Noise is present when clipping occurs on the amplified |
| 654 | * speaker outputs. |
| 655 | * |
| 656 | * Workaround: |
| 657 | * The following verb sequence written to the registers during |
| 658 | * initialization will correct the issues listed above. |
| 659 | */ |
| 660 | |
| 661 | static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = { |
| 662 | {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */ |
| 663 | |
| 664 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006}, |
| 665 | {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */ |
| 666 | |
| 667 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A}, |
| 668 | {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */ |
| 669 | |
| 670 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011}, |
| 671 | {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */ |
| 672 | |
| 673 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A}, |
| 674 | {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */ |
| 675 | |
| 676 | {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B}, |
| 677 | {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */ |
| 678 | |
| 679 | {} /* terminator */ |
| 680 | }; |
| 681 | |
| 682 | /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */ |
| 683 | static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0); |
| 684 | |
| 685 | static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol, |
| 686 | struct snd_ctl_elem_info *uinfo) |
| 687 | { |
| 688 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 689 | uinfo->count = 1; |
| 690 | uinfo->value.integer.min = 0; |
| 691 | uinfo->value.integer.max = 3; |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol, |
| 696 | struct snd_ctl_elem_value *ucontrol) |
| 697 | { |
| 698 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 699 | |
| 700 | ucontrol->value.integer.value[0] = |
| 701 | cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003; |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol, |
| 706 | struct snd_ctl_elem_value *ucontrol) |
| 707 | { |
| 708 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 709 | |
| 710 | unsigned int vol = ucontrol->value.integer.value[0]; |
| 711 | unsigned int coef = |
| 712 | cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL); |
| 713 | unsigned int original_coef = coef; |
| 714 | |
| 715 | coef &= ~0x0003; |
| 716 | coef |= (vol & 0x0003); |
| 717 | if (original_coef == coef) |
| 718 | return 0; |
| 719 | else { |
| 720 | cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef); |
| 721 | return 1; |
| 722 | } |
| 723 | } |
| 724 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 725 | static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 726 | |
| 727 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 728 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 729 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
| 730 | .name = "Speaker Boost Playback Volume", |
| 731 | .info = cs421x_boost_vol_info, |
| 732 | .get = cs421x_boost_vol_get, |
| 733 | .put = cs421x_boost_vol_put, |
| 734 | .tlv = { .p = cs421x_speaker_boost_db_scale }, |
| 735 | }; |
| 736 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 737 | static void cs4210_pinmux_init(struct hda_codec *codec) |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 738 | { |
| 739 | struct cs_spec *spec = codec->spec; |
| 740 | unsigned int def_conf, coef; |
| 741 | |
| 742 | /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */ |
| 743 | coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG); |
| 744 | |
| 745 | if (spec->gpio_mask) |
| 746 | coef |= 0x0008; /* B1,B2 are GPIOs */ |
| 747 | else |
| 748 | coef &= ~0x0008; |
| 749 | |
| 750 | if (spec->sense_b) |
| 751 | coef |= 0x0010; /* B2 is SENSE_B, not inverted */ |
| 752 | else |
| 753 | coef &= ~0x0010; |
| 754 | |
| 755 | cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef); |
| 756 | |
| 757 | if ((spec->gpio_mask || spec->sense_b) && |
| 758 | is_active_pin(codec, CS421X_DMIC_PIN_NID)) { |
| 759 | |
| 760 | /* |
| 761 | GPIO or SENSE_B forced - disconnect the DMIC pin. |
| 762 | */ |
| 763 | def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID); |
| 764 | def_conf &= ~AC_DEFCFG_PORT_CONN; |
| 765 | def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT); |
| 766 | snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf); |
| 767 | } |
| 768 | } |
| 769 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 770 | static void cs4210_spdif_automute(struct hda_codec *codec, |
| 771 | struct hda_jack_tbl *tbl) |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 772 | { |
| 773 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 774 | bool spdif_present = false; |
| 775 | hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0]; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 776 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 777 | /* detect on spdif is specific to CS4210 */ |
| 778 | if (!spec->spdif_detect || |
| 779 | spec->vendor_nid != CS4210_VENDOR_NID) |
| 780 | return; |
| 781 | |
| 782 | spdif_present = snd_hda_jack_detect(codec, spdif_pin); |
| 783 | if (spdif_present == spec->spdif_present) |
| 784 | return; |
| 785 | |
| 786 | spec->spdif_present = spdif_present; |
| 787 | /* SPDIF TX on/off */ |
| 788 | if (spdif_present) |
| 789 | snd_hda_set_pin_ctl(codec, spdif_pin, |
| 790 | spdif_present ? PIN_OUT : 0); |
| 791 | |
| 792 | cs_automute(codec); |
| 793 | } |
| 794 | |
| 795 | static void parse_cs421x_digital(struct hda_codec *codec) |
| 796 | { |
| 797 | struct cs_spec *spec = codec->spec; |
| 798 | struct auto_pin_cfg *cfg = &spec->gen.autocfg; |
| 799 | int i; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 800 | |
| 801 | for (i = 0; i < cfg->dig_outs; i++) { |
| 802 | hda_nid_t nid = cfg->dig_out_pins[i]; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 803 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 804 | spec->spdif_detect = 1; |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 805 | snd_hda_jack_detect_enable_callback(codec, nid, |
| 806 | SPDIF_EVENT, |
| 807 | cs4210_spdif_automute); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | static int cs421x_init(struct hda_codec *codec) |
| 813 | { |
| 814 | struct cs_spec *spec = codec->spec; |
| 815 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 816 | if (spec->vendor_nid == CS4210_VENDOR_NID) { |
| 817 | snd_hda_sequence_write(codec, cs421x_coef_init_verbs); |
| 818 | snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes); |
| 819 | cs4210_pinmux_init(codec); |
| 820 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 821 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 822 | snd_hda_gen_init(codec); |
| 823 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 824 | if (spec->gpio_mask) { |
| 825 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, |
| 826 | spec->gpio_mask); |
| 827 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, |
| 828 | spec->gpio_dir); |
| 829 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, |
| 830 | spec->gpio_data); |
| 831 | } |
| 832 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 833 | init_input_coef(codec); |
| 834 | |
| 835 | cs4210_spdif_automute(codec, NULL); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 836 | |
| 837 | return 0; |
| 838 | } |
| 839 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 840 | static int cs421x_build_controls(struct hda_codec *codec) |
| 841 | { |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 842 | struct cs_spec *spec = codec->spec; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 843 | int err; |
| 844 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 845 | err = snd_hda_gen_build_controls(codec); |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 846 | if (err < 0) |
| 847 | return err; |
| 848 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 849 | if (spec->gen.autocfg.speaker_outs && |
| 850 | spec->vendor_nid == CS4210_VENDOR_NID) { |
| 851 | err = snd_hda_ctl_add(codec, 0, |
| 852 | snd_ctl_new1(&cs421x_speaker_boost_ctl, codec)); |
| 853 | if (err < 0) |
| 854 | return err; |
| 855 | } |
Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 856 | return 0; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 857 | } |
| 858 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 859 | static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 860 | { |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 861 | unsigned int caps; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 862 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 863 | /* set the upper-limit for mixer amp to 0dB */ |
| 864 | caps = query_amp_caps(codec, dac, HDA_OUTPUT); |
| 865 | caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT); |
| 866 | caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f) |
| 867 | << AC_AMPCAP_NUM_STEPS_SHIFT; |
| 868 | snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | static int cs421x_parse_auto_config(struct hda_codec *codec) |
| 872 | { |
| 873 | struct cs_spec *spec = codec->spec; |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 874 | hda_nid_t dac = CS4210_DAC_NID; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 875 | int err; |
| 876 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 877 | fix_volume_caps(codec, dac); |
| 878 | |
| 879 | err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 880 | if (err < 0) |
| 881 | return err; |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 882 | |
| 883 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 884 | if (err < 0) |
| 885 | return err; |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 886 | |
| 887 | parse_cs421x_digital(codec); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | #ifdef CONFIG_PM |
| 892 | /* |
| 893 | Manage PDREF, when transitioning to D3hot |
| 894 | (DAC,ADC) -> D3, PDREF=1, AFG->D3 |
| 895 | */ |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 896 | static int cs421x_suspend(struct hda_codec *codec) |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 897 | { |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 898 | struct cs_spec *spec = codec->spec; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 899 | unsigned int coef; |
| 900 | |
| 901 | snd_hda_shutup_pins(codec); |
| 902 | |
| 903 | snd_hda_codec_write(codec, CS4210_DAC_NID, 0, |
| 904 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 905 | snd_hda_codec_write(codec, CS4210_ADC_NID, 0, |
| 906 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 907 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 908 | if (spec->vendor_nid == CS4210_VENDOR_NID) { |
| 909 | coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG); |
| 910 | coef |= 0x0004; /* PDREF */ |
| 911 | cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef); |
| 912 | } |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | #endif |
| 917 | |
Daniel J Blueman | 00e17f7 | 2012-11-04 13:19:04 +0800 | [diff] [blame] | 918 | static const struct hda_codec_ops cs421x_patch_ops = { |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 919 | .build_controls = cs421x_build_controls, |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 920 | .build_pcms = snd_hda_gen_build_pcms, |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 921 | .init = cs421x_init, |
| 922 | .free = cs_free, |
David Henningsson | 5c2e4e0 | 2012-10-08 15:44:15 +0200 | [diff] [blame] | 923 | .unsol_event = snd_hda_jack_unsol_event, |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 924 | #ifdef CONFIG_PM |
| 925 | .suspend = cs421x_suspend, |
| 926 | #endif |
| 927 | }; |
| 928 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 929 | static int patch_cs4210(struct hda_codec *codec) |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 930 | { |
| 931 | struct cs_spec *spec; |
| 932 | int err; |
| 933 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 934 | spec = cs_alloc_spec(codec, CS4210_VENDOR_NID); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 935 | if (!spec) |
| 936 | return -ENOMEM; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 937 | |
Takashi Iwai | 6d3073e | 2013-03-15 14:23:32 +0100 | [diff] [blame] | 938 | spec->gen.automute_hook = cs_automute; |
| 939 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 940 | snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl, |
| 941 | cs421x_fixups); |
| 942 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 943 | |
| 944 | /* |
| 945 | Update the GPIO/DMIC/SENSE_B pinmux before the configuration |
| 946 | is auto-parsed. If GPIO or SENSE_B is forced, DMIC input |
| 947 | is disabled. |
| 948 | */ |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 949 | cs4210_pinmux_init(codec); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 950 | |
| 951 | err = cs421x_parse_auto_config(codec); |
| 952 | if (err < 0) |
| 953 | goto error; |
| 954 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 955 | codec->patch_ops = cs421x_patch_ops; |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 956 | |
Takashi Iwai | b35aabd | 2012-08-24 19:09:45 +0200 | [diff] [blame] | 957 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
| 958 | |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 959 | return 0; |
| 960 | |
| 961 | error: |
Takashi Iwai | c5e0b6d | 2012-10-10 08:50:35 +0200 | [diff] [blame] | 962 | cs_free(codec); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 963 | return err; |
| 964 | } |
| 965 | |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 966 | static int patch_cs4213(struct hda_codec *codec) |
| 967 | { |
| 968 | struct cs_spec *spec; |
| 969 | int err; |
| 970 | |
Takashi Iwai | 1077a02 | 2012-12-19 16:39:18 +0100 | [diff] [blame] | 971 | spec = cs_alloc_spec(codec, CS4213_VENDOR_NID); |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 972 | if (!spec) |
| 973 | return -ENOMEM; |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 974 | |
| 975 | err = cs421x_parse_auto_config(codec); |
| 976 | if (err < 0) |
| 977 | goto error; |
| 978 | |
| 979 | codec->patch_ops = cs421x_patch_ops; |
| 980 | return 0; |
| 981 | |
| 982 | error: |
Takashi Iwai | c5e0b6d | 2012-10-10 08:50:35 +0200 | [diff] [blame] | 983 | cs_free(codec); |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 984 | return err; |
| 985 | } |
| 986 | |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 987 | |
| 988 | /* |
| 989 | * patch entries |
| 990 | */ |
Takashi Iwai | c42d478 | 2011-05-02 11:36:09 +0200 | [diff] [blame] | 991 | static const struct hda_codec_preset snd_hda_preset_cirrus[] = { |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 992 | { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x }, |
| 993 | { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x }, |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 994 | { .id = 0x10134210, .name = "CS4210", .patch = patch_cs4210 }, |
| 995 | { .id = 0x10134213, .name = "CS4213", .patch = patch_cs4213 }, |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 996 | {} /* terminator */ |
| 997 | }; |
| 998 | |
| 999 | MODULE_ALIAS("snd-hda-codec-id:10134206"); |
| 1000 | MODULE_ALIAS("snd-hda-codec-id:10134207"); |
Tim Howe | 56487c2 | 2011-07-22 16:41:00 -0500 | [diff] [blame] | 1001 | MODULE_ALIAS("snd-hda-codec-id:10134210"); |
David Henningsson | 5660ffd | 2012-01-02 12:40:17 +0100 | [diff] [blame] | 1002 | MODULE_ALIAS("snd-hda-codec-id:10134213"); |
Takashi Iwai | e5f1424 | 2009-07-01 18:11:44 +0200 | [diff] [blame] | 1003 | |
| 1004 | MODULE_LICENSE("GPL"); |
| 1005 | MODULE_DESCRIPTION("Cirrus Logic HD-audio codec"); |
| 1006 | |
| 1007 | static struct hda_codec_preset_list cirrus_list = { |
| 1008 | .preset = snd_hda_preset_cirrus, |
| 1009 | .owner = THIS_MODULE, |
| 1010 | }; |
| 1011 | |
| 1012 | static int __init patch_cirrus_init(void) |
| 1013 | { |
| 1014 | return snd_hda_add_codec_preset(&cirrus_list); |
| 1015 | } |
| 1016 | |
| 1017 | static void __exit patch_cirrus_exit(void) |
| 1018 | { |
| 1019 | snd_hda_delete_codec_preset(&cirrus_list); |
| 1020 | } |
| 1021 | |
| 1022 | module_init(patch_cirrus_init) |
| 1023 | module_exit(patch_cirrus_exit) |