Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Universal Interface for Intel High Definition Audio Codec |
| 3 | * |
| 4 | * HD audio interface patch for SigmaTel STAC92xx |
| 5 | * |
| 6 | * Copyright (c) 2005 Embedded Alley Solutions, Inc. |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 7 | * Matt Porter <mporter@embeddedalley.com> |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 8 | * |
| 9 | * Based on patch_cmedia.c and patch_realtek.c |
| 10 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> |
| 11 | * |
| 12 | * This driver is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This driver is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <sound/driver.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <sound/core.h> |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 33 | #include <sound/asoundef.h> |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 34 | #include "hda_codec.h" |
| 35 | #include "hda_local.h" |
| 36 | |
Matt | 4e55096 | 2005-07-04 17:51:39 +0200 | [diff] [blame] | 37 | #define NUM_CONTROL_ALLOC 32 |
| 38 | #define STAC_HP_EVENT 0x37 |
| 39 | #define STAC_UNSOL_ENABLE (AC_USRSP_EN | STAC_HP_EVENT) |
| 40 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 41 | #define STAC_REF 0 |
| 42 | #define STAC_D945GTP3 1 |
| 43 | #define STAC_D945GTP5 2 |
Sam Revitch | 62fe78e | 2006-05-10 15:09:17 +0200 | [diff] [blame] | 44 | #define STAC_MACMINI 3 |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 45 | #define STAC_D965_2112 4 |
| 46 | #define STAC_D965_284B 5 |
| 47 | #define STAC_922X_MODELS 6 /* number of 922x models */ |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 48 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 49 | struct sigmatel_spec { |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 50 | struct snd_kcontrol_new *mixers[4]; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 51 | unsigned int num_mixers; |
| 52 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 53 | int board_config; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 54 | unsigned int surr_switch: 1; |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 55 | unsigned int line_switch: 1; |
| 56 | unsigned int mic_switch: 1; |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 57 | unsigned int alt_switch: 1; |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 58 | unsigned int hp_detect: 1; |
Sam Revitch | 62fe78e | 2006-05-10 15:09:17 +0200 | [diff] [blame] | 59 | unsigned int gpio_mute: 1; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 60 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 61 | /* playback */ |
| 62 | struct hda_multi_out multiout; |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 63 | hda_nid_t dac_nids[5]; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 64 | |
| 65 | /* capture */ |
| 66 | hda_nid_t *adc_nids; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 67 | unsigned int num_adcs; |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 68 | hda_nid_t *mux_nids; |
| 69 | unsigned int num_muxes; |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 70 | hda_nid_t dig_in_nid; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 71 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 72 | /* pin widgets */ |
| 73 | hda_nid_t *pin_nids; |
| 74 | unsigned int num_pins; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 75 | unsigned int *pin_configs; |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 76 | unsigned int *bios_pin_configs; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 77 | |
| 78 | /* codec specific stuff */ |
| 79 | struct hda_verb *init; |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 80 | struct snd_kcontrol_new *mixer; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 81 | |
| 82 | /* capture source */ |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 83 | struct hda_input_mux *input_mux; |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 84 | unsigned int cur_mux[3]; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 85 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 86 | /* i/o switches */ |
| 87 | unsigned int io_switch[2]; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 88 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 89 | struct hda_pcm pcm_rec[2]; /* PCM information */ |
| 90 | |
| 91 | /* dynamic controls and input_mux */ |
| 92 | struct auto_pin_cfg autocfg; |
| 93 | unsigned int num_kctl_alloc, num_kctl_used; |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 94 | struct snd_kcontrol_new *kctl_alloc; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 95 | struct hda_input_mux private_imux; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static hda_nid_t stac9200_adc_nids[1] = { |
| 99 | 0x03, |
| 100 | }; |
| 101 | |
| 102 | static hda_nid_t stac9200_mux_nids[1] = { |
| 103 | 0x0c, |
| 104 | }; |
| 105 | |
| 106 | static hda_nid_t stac9200_dac_nids[1] = { |
| 107 | 0x02, |
| 108 | }; |
| 109 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 110 | static hda_nid_t stac922x_adc_nids[2] = { |
| 111 | 0x06, 0x07, |
| 112 | }; |
| 113 | |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 114 | static hda_nid_t stac9227_adc_nids[2] = { |
| 115 | 0x07, 0x08, |
| 116 | }; |
| 117 | |
| 118 | #if 0 |
| 119 | static hda_nid_t d965_2112_dac_nids[3] = { |
| 120 | 0x02, 0x03, 0x05, |
| 121 | }; |
| 122 | #endif |
| 123 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 124 | static hda_nid_t stac922x_mux_nids[2] = { |
| 125 | 0x12, 0x13, |
| 126 | }; |
| 127 | |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 128 | static hda_nid_t stac9227_mux_nids[2] = { |
| 129 | 0x15, 0x16, |
| 130 | }; |
| 131 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 132 | static hda_nid_t stac927x_adc_nids[3] = { |
| 133 | 0x07, 0x08, 0x09 |
| 134 | }; |
| 135 | |
| 136 | static hda_nid_t stac927x_mux_nids[3] = { |
| 137 | 0x15, 0x16, 0x17 |
| 138 | }; |
| 139 | |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 140 | static hda_nid_t stac9205_adc_nids[2] = { |
| 141 | 0x12, 0x13 |
| 142 | }; |
| 143 | |
| 144 | static hda_nid_t stac9205_mux_nids[2] = { |
| 145 | 0x19, 0x1a |
| 146 | }; |
| 147 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 148 | static hda_nid_t stac9200_pin_nids[8] = { |
| 149 | 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | static hda_nid_t stac922x_pin_nids[10] = { |
| 153 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, |
| 154 | 0x0f, 0x10, 0x11, 0x15, 0x1b, |
| 155 | }; |
| 156 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 157 | static hda_nid_t stac927x_pin_nids[14] = { |
| 158 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, |
| 159 | 0x0f, 0x10, 0x11, 0x12, 0x13, |
| 160 | 0x14, 0x21, 0x22, 0x23, |
| 161 | }; |
| 162 | |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 163 | static hda_nid_t stac9205_pin_nids[12] = { |
| 164 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, |
| 165 | 0x0f, 0x14, 0x16, 0x17, 0x18, |
| 166 | 0x21, 0x22, |
| 167 | |
| 168 | }; |
| 169 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 170 | static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 171 | { |
| 172 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 173 | struct sigmatel_spec *spec = codec->spec; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 174 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 177 | static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 178 | { |
| 179 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 180 | struct sigmatel_spec *spec = codec->spec; |
| 181 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 182 | |
| 183 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 184 | return 0; |
| 185 | } |
| 186 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 187 | static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 188 | { |
| 189 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 190 | struct sigmatel_spec *spec = codec->spec; |
| 191 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 192 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 193 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 194 | spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]); |
| 195 | } |
| 196 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 197 | static struct hda_verb stac9200_core_init[] = { |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 198 | /* set dac0mux for dac converter */ |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 199 | { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00}, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 200 | {} |
| 201 | }; |
| 202 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 203 | static struct hda_verb stac922x_core_init[] = { |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 204 | /* set master volume and direct control */ |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 205 | { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 206 | {} |
| 207 | }; |
| 208 | |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 209 | static struct hda_verb stac9227_core_init[] = { |
| 210 | /* set master volume and direct control */ |
| 211 | { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, |
| 212 | /* unmute node 0x1b */ |
| 213 | { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, |
| 214 | {} |
| 215 | }; |
| 216 | |
| 217 | static struct hda_verb d965_2112_core_init[] = { |
| 218 | /* set master volume and direct control */ |
| 219 | { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, |
| 220 | /* unmute node 0x1b */ |
| 221 | { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, |
| 222 | /* select node 0x03 as DAC */ |
| 223 | { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01}, |
| 224 | {} |
| 225 | }; |
| 226 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 227 | static struct hda_verb stac927x_core_init[] = { |
| 228 | /* set master volume and direct control */ |
| 229 | { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, |
| 230 | {} |
| 231 | }; |
| 232 | |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 233 | static struct hda_verb stac9205_core_init[] = { |
| 234 | /* set master volume and direct control */ |
| 235 | { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, |
| 236 | {} |
| 237 | }; |
| 238 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 239 | static struct snd_kcontrol_new stac9200_mixer[] = { |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 240 | HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT), |
| 241 | HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT), |
| 242 | { |
| 243 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 244 | .name = "Input Source", |
| 245 | .count = 1, |
| 246 | .info = stac92xx_mux_enum_info, |
| 247 | .get = stac92xx_mux_enum_get, |
| 248 | .put = stac92xx_mux_enum_put, |
| 249 | }, |
| 250 | HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT), |
| 251 | HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT), |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 252 | HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT), |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 253 | { } /* end */ |
| 254 | }; |
| 255 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 256 | /* This needs to be generated dynamically based on sequence */ |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 257 | static struct snd_kcontrol_new stac922x_mixer[] = { |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 258 | { |
| 259 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 260 | .name = "Input Source", |
| 261 | .count = 1, |
| 262 | .info = stac92xx_mux_enum_info, |
| 263 | .get = stac92xx_mux_enum_get, |
| 264 | .put = stac92xx_mux_enum_put, |
| 265 | }, |
| 266 | HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT), |
Takashi Iwai | 0fd1708 | 2006-01-13 18:46:21 +0100 | [diff] [blame] | 267 | HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT), |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 268 | HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT), |
| 269 | { } /* end */ |
| 270 | }; |
| 271 | |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 272 | /* This needs to be generated dynamically based on sequence */ |
| 273 | static struct snd_kcontrol_new stac9227_mixer[] = { |
| 274 | { |
| 275 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 276 | .name = "Input Source", |
| 277 | .count = 1, |
| 278 | .info = stac92xx_mux_enum_info, |
| 279 | .get = stac92xx_mux_enum_get, |
| 280 | .put = stac92xx_mux_enum_put, |
| 281 | }, |
| 282 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), |
| 283 | HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT), |
| 284 | { } /* end */ |
| 285 | }; |
| 286 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 287 | static snd_kcontrol_new_t stac927x_mixer[] = { |
| 288 | { |
| 289 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 290 | .name = "Input Source", |
| 291 | .count = 1, |
| 292 | .info = stac92xx_mux_enum_info, |
| 293 | .get = stac92xx_mux_enum_get, |
| 294 | .put = stac92xx_mux_enum_put, |
| 295 | }, |
| 296 | HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT), |
| 297 | HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT), |
| 298 | HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT), |
| 299 | { } /* end */ |
| 300 | }; |
| 301 | |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 302 | static snd_kcontrol_new_t stac9205_mixer[] = { |
| 303 | { |
| 304 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 305 | .name = "Input Source", |
| 306 | .count = 1, |
| 307 | .info = stac92xx_mux_enum_info, |
| 308 | .get = stac92xx_mux_enum_get, |
| 309 | .put = stac92xx_mux_enum_put, |
| 310 | }, |
| 311 | HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT), |
| 312 | HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT), |
| 313 | HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT), |
| 314 | { } /* end */ |
| 315 | }; |
| 316 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 317 | static int stac92xx_build_controls(struct hda_codec *codec) |
| 318 | { |
| 319 | struct sigmatel_spec *spec = codec->spec; |
| 320 | int err; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 321 | int i; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 322 | |
| 323 | err = snd_hda_add_new_ctls(codec, spec->mixer); |
| 324 | if (err < 0) |
| 325 | return err; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 326 | |
| 327 | for (i = 0; i < spec->num_mixers; i++) { |
| 328 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 329 | if (err < 0) |
| 330 | return err; |
| 331 | } |
| 332 | |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 333 | if (spec->multiout.dig_out_nid) { |
| 334 | err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); |
| 335 | if (err < 0) |
| 336 | return err; |
| 337 | } |
| 338 | if (spec->dig_in_nid) { |
| 339 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 340 | if (err < 0) |
| 341 | return err; |
| 342 | } |
| 343 | return 0; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 346 | static unsigned int ref9200_pin_configs[8] = { |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 347 | 0x01c47010, 0x01447010, 0x0221401f, 0x01114010, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 348 | 0x02a19020, 0x01a19021, 0x90100140, 0x01813122, |
| 349 | }; |
| 350 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 351 | static unsigned int *stac9200_brd_tbl[] = { |
| 352 | ref9200_pin_configs, |
| 353 | }; |
| 354 | |
| 355 | static struct hda_board_config stac9200_cfg_tbl[] = { |
| 356 | { .modelname = "ref", |
| 357 | .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 358 | .pci_subdevice = 0x2668, /* DFI LanParty */ |
| 359 | .config = STAC_REF }, |
| 360 | {} /* terminator */ |
| 361 | }; |
| 362 | |
| 363 | static unsigned int ref922x_pin_configs[10] = { |
| 364 | 0x01014010, 0x01016011, 0x01012012, 0x0221401f, |
| 365 | 0x01813122, 0x01011014, 0x01441030, 0x01c41030, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 366 | 0x40000100, 0x40000100, |
| 367 | }; |
| 368 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 369 | static unsigned int d945gtp3_pin_configs[10] = { |
Matt Porter | 869264c | 2006-01-25 19:20:50 +0100 | [diff] [blame] | 370 | 0x0221401f, 0x01a19022, 0x01813021, 0x01014010, |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 371 | 0x40000100, 0x40000100, 0x40000100, 0x40000100, |
| 372 | 0x02a19120, 0x40000100, |
| 373 | }; |
| 374 | |
| 375 | static unsigned int d945gtp5_pin_configs[10] = { |
Matt Porter | 869264c | 2006-01-25 19:20:50 +0100 | [diff] [blame] | 376 | 0x0221401f, 0x01011012, 0x01813024, 0x01014010, |
| 377 | 0x01a19021, 0x01016011, 0x01452130, 0x40000100, |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 378 | 0x02a19320, 0x40000100, |
| 379 | }; |
| 380 | |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 381 | static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = { |
| 382 | [STAC_REF] = ref922x_pin_configs, |
| 383 | [STAC_D945GTP3] = d945gtp3_pin_configs, |
| 384 | [STAC_D945GTP5] = d945gtp5_pin_configs, |
Linus Torvalds | 7c3dec0 | 2006-07-10 22:21:43 -0700 | [diff] [blame] | 385 | [STAC_MACMINI] = d945gtp5_pin_configs, |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | static struct hda_board_config stac922x_cfg_tbl[] = { |
| 389 | { .modelname = "ref", |
| 390 | .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 391 | .pci_subdevice = 0x2668, /* DFI LanParty */ |
| 392 | .config = STAC_REF }, /* SigmaTel reference board */ |
Tobin Davis | 948a4db | 2006-08-22 19:43:46 +0200 | [diff] [blame] | 393 | /* Intel 945G based systems */ |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 394 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 395 | .pci_subdevice = 0x0101, |
| 396 | .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */ |
| 397 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
Takashi Iwai | 353b9e6 | 2006-02-16 18:16:17 +0100 | [diff] [blame] | 398 | .pci_subdevice = 0x0202, |
Tobin Davis | 948a4db | 2006-08-22 19:43:46 +0200 | [diff] [blame] | 399 | .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack */ |
Takashi Iwai | 353b9e6 | 2006-02-16 18:16:17 +0100 | [diff] [blame] | 400 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
Tobin Davis | 948a4db | 2006-08-22 19:43:46 +0200 | [diff] [blame] | 401 | .pci_subdevice = 0x0606, |
| 402 | .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */ |
Takashi Iwai | 353b9e6 | 2006-02-16 18:16:17 +0100 | [diff] [blame] | 403 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
Tobin Davis | 948a4db | 2006-08-22 19:43:46 +0200 | [diff] [blame] | 404 | .pci_subdevice = 0x0601, |
| 405 | .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */ |
| 406 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 407 | .pci_subdevice = 0x0111, |
| 408 | .config = STAC_D945GTP3 }, /* Intel D945GZP - 3 Stack */ |
| 409 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 410 | .pci_subdevice = 0x1115, |
| 411 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ |
| 412 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 413 | .pci_subdevice = 0x1116, |
| 414 | .config = STAC_D945GTP3 }, /* Intel D945GBO - 3 Stack */ |
| 415 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 416 | .pci_subdevice = 0x1117, |
| 417 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ |
| 418 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 419 | .pci_subdevice = 0x1118, |
| 420 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ |
| 421 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 422 | .pci_subdevice = 0x1119, |
| 423 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ |
| 424 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 425 | .pci_subdevice = 0x8826, |
| 426 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ |
| 427 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 428 | .pci_subdevice = 0x5049, |
| 429 | .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */ |
| 430 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 431 | .pci_subdevice = 0x5055, |
| 432 | .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */ |
| 433 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 434 | .pci_subdevice = 0x5048, |
| 435 | .config = STAC_D945GTP3 }, /* Intel D945GPB - 3 Stack */ |
| 436 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 437 | .pci_subdevice = 0x0110, |
| 438 | .config = STAC_D945GTP3 }, /* Intel D945GLR - 3 Stack */ |
| 439 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 440 | .pci_subdevice = 0x0404, |
| 441 | .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */ |
| 442 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 443 | .pci_subdevice = 0x0303, |
| 444 | .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */ |
| 445 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 446 | .pci_subdevice = 0x0013, |
| 447 | .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */ |
Matt Porter | d62c40e | 2006-01-23 15:26:27 +0100 | [diff] [blame] | 448 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 449 | .pci_subdevice = 0x0417, |
| 450 | .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */ |
Tobin Davis | 948a4db | 2006-08-22 19:43:46 +0200 | [diff] [blame] | 451 | /* Intel 945P based systems */ |
| 452 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 453 | .pci_subdevice = 0x0b0b, |
| 454 | .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack */ |
| 455 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 456 | .pci_subdevice = 0x0112, |
| 457 | .config = STAC_D945GTP3 }, /* Intel D945PLN - 3 Stack */ |
| 458 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 459 | .pci_subdevice = 0x0d0d, |
| 460 | .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */ |
| 461 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 462 | .pci_subdevice = 0x0909, |
| 463 | .config = STAC_D945GTP3 }, /* Intel D945PAW - 3 Stack */ |
| 464 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 465 | .pci_subdevice = 0x0505, |
| 466 | .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */ |
| 467 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 468 | .pci_subdevice = 0x0707, |
| 469 | .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */ |
| 470 | /* other systems */ |
Sam Revitch | 62fe78e | 2006-05-10 15:09:17 +0200 | [diff] [blame] | 471 | { .pci_subvendor = 0x8384, |
| 472 | .pci_subdevice = 0x7680, |
| 473 | .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */ |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 474 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 475 | .pci_subdevice = 0x2112, |
| 476 | .config = STAC_D965_2112 }, |
| 477 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 478 | .pci_subdevice = 0x284b, |
| 479 | .config = STAC_D965_284B }, |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 480 | {} /* terminator */ |
| 481 | }; |
| 482 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 483 | static unsigned int ref927x_pin_configs[14] = { |
| 484 | 0x01813122, 0x01a19021, 0x01014010, 0x01016011, |
| 485 | 0x01012012, 0x01011014, 0x40000100, 0x40000100, |
| 486 | 0x40000100, 0x40000100, 0x40000100, 0x01441030, |
| 487 | 0x01c41030, 0x40000100, |
| 488 | }; |
| 489 | |
Tobin Davis | 81d3dbd | 2006-08-22 19:44:45 +0200 | [diff] [blame] | 490 | static unsigned int d965_2112_pin_configs[14] = { |
| 491 | 0x0221401f, 0x02a19120, 0x40000100, 0x01014011, |
| 492 | 0x01a19021, 0x01813024, 0x40000100, 0x40000100, |
| 493 | 0x40000100, 0x40000100, 0x40000100, 0x40000100, |
| 494 | 0x40000100, 0x40000100 |
| 495 | }; |
| 496 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 497 | static unsigned int *stac927x_brd_tbl[] = { |
Tobin Davis | 81d3dbd | 2006-08-22 19:44:45 +0200 | [diff] [blame] | 498 | [STAC_REF] = ref927x_pin_configs, |
| 499 | [STAC_D965_2112] = d965_2112_pin_configs, |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 500 | }; |
| 501 | |
| 502 | static struct hda_board_config stac927x_cfg_tbl[] = { |
| 503 | { .modelname = "ref", |
| 504 | .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 505 | .pci_subdevice = 0x2668, /* DFI LanParty */ |
| 506 | .config = STAC_REF }, /* SigmaTel reference board */ |
Tobin Davis | 81d3dbd | 2006-08-22 19:44:45 +0200 | [diff] [blame] | 507 | /* SigmaTel 9227 reference board */ |
| 508 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 509 | .pci_subdevice = 0x284b, |
| 510 | .config = STAC_D965_284B }, |
| 511 | /* Intel 946 based systems */ |
| 512 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 513 | .pci_subdevice = 0x3d01, |
| 514 | .config = STAC_D965_2112 }, /* D946 configuration */ |
| 515 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 516 | .pci_subdevice = 0xa301, |
| 517 | .config = STAC_D965_2112 }, /* Intel D946GZT - 3 stack */ |
| 518 | /* 965 based systems */ |
| 519 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 520 | .pci_subdevice = 0x2116, |
| 521 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 522 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 523 | .pci_subdevice = 0x2115, |
| 524 | .config = STAC_D965_2112 }, /* Intel DQ965WC - 3 Stack */ |
| 525 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 526 | .pci_subdevice = 0x2114, |
| 527 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 528 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 529 | .pci_subdevice = 0x2113, |
| 530 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 531 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 532 | .pci_subdevice = 0x2112, |
| 533 | .config = STAC_D965_2112 }, /* Intel DG965MS - 3 Stack */ |
| 534 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 535 | .pci_subdevice = 0x2111, |
| 536 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 537 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 538 | .pci_subdevice = 0x2110, |
| 539 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 540 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 541 | .pci_subdevice = 0x2009, |
| 542 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 543 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 544 | .pci_subdevice = 0x2008, |
| 545 | .config = STAC_D965_2112 }, /* Intel DQ965GF - 3 Stack */ |
| 546 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 547 | .pci_subdevice = 0x2007, |
| 548 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 549 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 550 | .pci_subdevice = 0x2006, |
| 551 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 552 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 553 | .pci_subdevice = 0x2005, |
| 554 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 555 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 556 | .pci_subdevice = 0x2004, |
| 557 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 558 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 559 | .pci_subdevice = 0x2003, |
| 560 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 561 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 562 | .pci_subdevice = 0x2002, |
| 563 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ |
| 564 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 565 | .pci_subdevice = 0x2001, |
| 566 | .config = STAC_D965_2112 }, /* Intel DQ965GF - 3 Stackg */ |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 567 | {} /* terminator */ |
| 568 | }; |
| 569 | |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 570 | static unsigned int ref9205_pin_configs[12] = { |
| 571 | 0x40000100, 0x40000100, 0x01016011, 0x01014010, |
| 572 | 0x01813122, 0x01a19021, 0x40000100, 0x40000100, |
| 573 | 0x40000100, 0x40000100, 0x01441030, 0x01c41030 |
| 574 | }; |
| 575 | |
| 576 | static unsigned int *stac9205_brd_tbl[] = { |
| 577 | ref9205_pin_configs, |
| 578 | }; |
| 579 | |
| 580 | static struct hda_board_config stac9205_cfg_tbl[] = { |
| 581 | { .modelname = "ref", |
| 582 | .pci_subvendor = PCI_VENDOR_ID_INTEL, |
| 583 | .pci_subdevice = 0x2668, /* DFI LanParty */ |
| 584 | .config = STAC_REF }, /* SigmaTel reference board */ |
| 585 | {} /* terminator */ |
| 586 | }; |
| 587 | |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 588 | static int stac92xx_save_bios_config_regs(struct hda_codec *codec) |
| 589 | { |
| 590 | int i; |
| 591 | struct sigmatel_spec *spec = codec->spec; |
| 592 | |
| 593 | if (! spec->bios_pin_configs) { |
| 594 | spec->bios_pin_configs = kcalloc(spec->num_pins, |
| 595 | sizeof(*spec->bios_pin_configs), GFP_KERNEL); |
| 596 | if (! spec->bios_pin_configs) |
| 597 | return -ENOMEM; |
| 598 | } |
| 599 | |
| 600 | for (i = 0; i < spec->num_pins; i++) { |
| 601 | hda_nid_t nid = spec->pin_nids[i]; |
| 602 | unsigned int pin_cfg; |
| 603 | |
| 604 | pin_cfg = snd_hda_codec_read(codec, nid, 0, |
| 605 | AC_VERB_GET_CONFIG_DEFAULT, 0x00); |
| 606 | snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n", |
| 607 | nid, pin_cfg); |
| 608 | spec->bios_pin_configs[i] = pin_cfg; |
| 609 | } |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 614 | static void stac92xx_set_config_regs(struct hda_codec *codec) |
| 615 | { |
| 616 | int i; |
| 617 | struct sigmatel_spec *spec = codec->spec; |
| 618 | unsigned int pin_cfg; |
| 619 | |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 620 | if (! spec->pin_nids || ! spec->pin_configs) |
| 621 | return; |
| 622 | |
| 623 | for (i = 0; i < spec->num_pins; i++) { |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 624 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, |
| 625 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_0, |
| 626 | spec->pin_configs[i] & 0x000000ff); |
| 627 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, |
| 628 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, |
| 629 | (spec->pin_configs[i] & 0x0000ff00) >> 8); |
| 630 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, |
| 631 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, |
| 632 | (spec->pin_configs[i] & 0x00ff0000) >> 16); |
| 633 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, |
| 634 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, |
| 635 | spec->pin_configs[i] >> 24); |
| 636 | pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0, |
| 637 | AC_VERB_GET_CONFIG_DEFAULT, |
| 638 | 0x00); |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 639 | snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg); |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 640 | } |
| 641 | } |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 642 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 643 | /* |
| 644 | * Analog playback callbacks |
| 645 | */ |
| 646 | static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 647 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 648 | struct snd_pcm_substream *substream) |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 649 | { |
| 650 | struct sigmatel_spec *spec = codec->spec; |
| 651 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); |
| 652 | } |
| 653 | |
| 654 | static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 655 | struct hda_codec *codec, |
| 656 | unsigned int stream_tag, |
| 657 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 658 | struct snd_pcm_substream *substream) |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 659 | { |
| 660 | struct sigmatel_spec *spec = codec->spec; |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 661 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream); |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 665 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 666 | struct snd_pcm_substream *substream) |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 667 | { |
| 668 | struct sigmatel_spec *spec = codec->spec; |
| 669 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 670 | } |
| 671 | |
| 672 | /* |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 673 | * Digital playback callbacks |
| 674 | */ |
| 675 | static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 676 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 677 | struct snd_pcm_substream *substream) |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 678 | { |
| 679 | struct sigmatel_spec *spec = codec->spec; |
| 680 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 681 | } |
| 682 | |
| 683 | static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 684 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 685 | struct snd_pcm_substream *substream) |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 686 | { |
| 687 | struct sigmatel_spec *spec = codec->spec; |
| 688 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 689 | } |
| 690 | |
| 691 | |
| 692 | /* |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 693 | * Analog capture callbacks |
| 694 | */ |
| 695 | static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 696 | struct hda_codec *codec, |
| 697 | unsigned int stream_tag, |
| 698 | unsigned int format, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 699 | struct snd_pcm_substream *substream) |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 700 | { |
| 701 | struct sigmatel_spec *spec = codec->spec; |
| 702 | |
| 703 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 704 | stream_tag, 0, format); |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 709 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 710 | struct snd_pcm_substream *substream) |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 711 | { |
| 712 | struct sigmatel_spec *spec = codec->spec; |
| 713 | |
| 714 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); |
| 715 | return 0; |
| 716 | } |
| 717 | |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 718 | static struct hda_pcm_stream stac92xx_pcm_digital_playback = { |
| 719 | .substreams = 1, |
| 720 | .channels_min = 2, |
| 721 | .channels_max = 2, |
| 722 | /* NID is set in stac92xx_build_pcms */ |
| 723 | .ops = { |
| 724 | .open = stac92xx_dig_playback_pcm_open, |
| 725 | .close = stac92xx_dig_playback_pcm_close |
| 726 | }, |
| 727 | }; |
| 728 | |
| 729 | static struct hda_pcm_stream stac92xx_pcm_digital_capture = { |
| 730 | .substreams = 1, |
| 731 | .channels_min = 2, |
| 732 | .channels_max = 2, |
| 733 | /* NID is set in stac92xx_build_pcms */ |
| 734 | }; |
| 735 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 736 | static struct hda_pcm_stream stac92xx_pcm_analog_playback = { |
| 737 | .substreams = 1, |
| 738 | .channels_min = 2, |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 739 | .channels_max = 8, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 740 | .nid = 0x02, /* NID to query formats and rates */ |
| 741 | .ops = { |
| 742 | .open = stac92xx_playback_pcm_open, |
| 743 | .prepare = stac92xx_playback_pcm_prepare, |
| 744 | .cleanup = stac92xx_playback_pcm_cleanup |
| 745 | }, |
| 746 | }; |
| 747 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 748 | static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = { |
| 749 | .substreams = 1, |
| 750 | .channels_min = 2, |
| 751 | .channels_max = 2, |
| 752 | .nid = 0x06, /* NID to query formats and rates */ |
| 753 | .ops = { |
| 754 | .open = stac92xx_playback_pcm_open, |
| 755 | .prepare = stac92xx_playback_pcm_prepare, |
| 756 | .cleanup = stac92xx_playback_pcm_cleanup |
| 757 | }, |
| 758 | }; |
| 759 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 760 | static struct hda_pcm_stream stac92xx_pcm_analog_capture = { |
| 761 | .substreams = 2, |
| 762 | .channels_min = 2, |
| 763 | .channels_max = 2, |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 764 | /* NID is set in stac92xx_build_pcms */ |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 765 | .ops = { |
| 766 | .prepare = stac92xx_capture_pcm_prepare, |
| 767 | .cleanup = stac92xx_capture_pcm_cleanup |
| 768 | }, |
| 769 | }; |
| 770 | |
| 771 | static int stac92xx_build_pcms(struct hda_codec *codec) |
| 772 | { |
| 773 | struct sigmatel_spec *spec = codec->spec; |
| 774 | struct hda_pcm *info = spec->pcm_rec; |
| 775 | |
| 776 | codec->num_pcms = 1; |
| 777 | codec->pcm_info = info; |
| 778 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 779 | info->name = "STAC92xx Analog"; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 780 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 781 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture; |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 782 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 783 | |
| 784 | if (spec->alt_switch) { |
| 785 | codec->num_pcms++; |
| 786 | info++; |
| 787 | info->name = "STAC92xx Analog Alt"; |
| 788 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback; |
| 789 | } |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 790 | |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 791 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
| 792 | codec->num_pcms++; |
| 793 | info++; |
| 794 | info->name = "STAC92xx Digital"; |
| 795 | if (spec->multiout.dig_out_nid) { |
| 796 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback; |
| 797 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
| 798 | } |
| 799 | if (spec->dig_in_nid) { |
| 800 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture; |
| 801 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
| 802 | } |
| 803 | } |
| 804 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 805 | return 0; |
| 806 | } |
| 807 | |
Takashi Iwai | c960a03 | 2006-03-23 17:06:28 +0100 | [diff] [blame] | 808 | static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid) |
| 809 | { |
| 810 | unsigned int pincap = snd_hda_param_read(codec, nid, |
| 811 | AC_PAR_PIN_CAP); |
| 812 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
| 813 | if (pincap & AC_PINCAP_VREF_100) |
| 814 | return AC_PINCTL_VREF_100; |
| 815 | if (pincap & AC_PINCAP_VREF_80) |
| 816 | return AC_PINCTL_VREF_80; |
| 817 | if (pincap & AC_PINCAP_VREF_50) |
| 818 | return AC_PINCTL_VREF_50; |
| 819 | if (pincap & AC_PINCAP_VREF_GRD) |
| 820 | return AC_PINCTL_VREF_GRD; |
| 821 | return 0; |
| 822 | } |
| 823 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 824 | static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) |
| 825 | |
| 826 | { |
| 827 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); |
| 828 | } |
| 829 | |
| 830 | static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
| 831 | { |
| 832 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 833 | uinfo->count = 1; |
| 834 | uinfo->value.integer.min = 0; |
| 835 | uinfo->value.integer.max = 1; |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 840 | { |
| 841 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 842 | struct sigmatel_spec *spec = codec->spec; |
| 843 | int io_idx = kcontrol-> private_value & 0xff; |
| 844 | |
| 845 | ucontrol->value.integer.value[0] = spec->io_switch[io_idx]; |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 850 | { |
| 851 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 852 | struct sigmatel_spec *spec = codec->spec; |
| 853 | hda_nid_t nid = kcontrol->private_value >> 8; |
| 854 | int io_idx = kcontrol-> private_value & 0xff; |
| 855 | unsigned short val = ucontrol->value.integer.value[0]; |
| 856 | |
| 857 | spec->io_switch[io_idx] = val; |
| 858 | |
| 859 | if (val) |
| 860 | stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN); |
Takashi Iwai | c960a03 | 2006-03-23 17:06:28 +0100 | [diff] [blame] | 861 | else { |
| 862 | unsigned int pinctl = AC_PINCTL_IN_EN; |
| 863 | if (io_idx) /* set VREF for mic */ |
| 864 | pinctl |= stac92xx_get_vref(codec, nid); |
| 865 | stac92xx_auto_set_pinctl(codec, nid, pinctl); |
| 866 | } |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 867 | return 1; |
| 868 | } |
| 869 | |
| 870 | #define STAC_CODEC_IO_SWITCH(xname, xpval) \ |
| 871 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 872 | .name = xname, \ |
| 873 | .index = 0, \ |
| 874 | .info = stac92xx_io_switch_info, \ |
| 875 | .get = stac92xx_io_switch_get, \ |
| 876 | .put = stac92xx_io_switch_put, \ |
| 877 | .private_value = xpval, \ |
| 878 | } |
| 879 | |
| 880 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 881 | enum { |
| 882 | STAC_CTL_WIDGET_VOL, |
| 883 | STAC_CTL_WIDGET_MUTE, |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 884 | STAC_CTL_WIDGET_IO_SWITCH, |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 885 | }; |
| 886 | |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 887 | static struct snd_kcontrol_new stac92xx_control_templates[] = { |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 888 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 889 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 890 | STAC_CODEC_IO_SWITCH(NULL, 0), |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 891 | }; |
| 892 | |
| 893 | /* add dynamic controls */ |
| 894 | static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val) |
| 895 | { |
Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 896 | struct snd_kcontrol_new *knew; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 897 | |
| 898 | if (spec->num_kctl_used >= spec->num_kctl_alloc) { |
| 899 | int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC; |
| 900 | |
| 901 | knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */ |
| 902 | if (! knew) |
| 903 | return -ENOMEM; |
| 904 | if (spec->kctl_alloc) { |
| 905 | memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc); |
| 906 | kfree(spec->kctl_alloc); |
| 907 | } |
| 908 | spec->kctl_alloc = knew; |
| 909 | spec->num_kctl_alloc = num; |
| 910 | } |
| 911 | |
| 912 | knew = &spec->kctl_alloc[spec->num_kctl_used]; |
| 913 | *knew = stac92xx_control_templates[type]; |
Takashi Iwai | 82fe0c5 | 2005-06-30 10:54:33 +0200 | [diff] [blame] | 914 | knew->name = kstrdup(name, GFP_KERNEL); |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 915 | if (! knew->name) |
| 916 | return -ENOMEM; |
| 917 | knew->private_value = val; |
| 918 | spec->num_kctl_used++; |
| 919 | return 0; |
| 920 | } |
| 921 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 922 | /* flag inputs as additional dynamic lineouts */ |
| 923 | static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg) |
| 924 | { |
| 925 | struct sigmatel_spec *spec = codec->spec; |
| 926 | |
| 927 | switch (cfg->line_outs) { |
| 928 | case 3: |
| 929 | /* add line-in as side */ |
| 930 | if (cfg->input_pins[AUTO_PIN_LINE]) { |
| 931 | cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE]; |
| 932 | spec->line_switch = 1; |
| 933 | cfg->line_outs++; |
| 934 | } |
| 935 | break; |
| 936 | case 2: |
| 937 | /* add line-in as clfe and mic as side */ |
| 938 | if (cfg->input_pins[AUTO_PIN_LINE]) { |
| 939 | cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE]; |
| 940 | spec->line_switch = 1; |
| 941 | cfg->line_outs++; |
| 942 | } |
| 943 | if (cfg->input_pins[AUTO_PIN_MIC]) { |
| 944 | cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC]; |
| 945 | spec->mic_switch = 1; |
| 946 | cfg->line_outs++; |
| 947 | } |
| 948 | break; |
| 949 | case 1: |
| 950 | /* add line-in as surr and mic as clfe */ |
| 951 | if (cfg->input_pins[AUTO_PIN_LINE]) { |
| 952 | cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE]; |
| 953 | spec->line_switch = 1; |
| 954 | cfg->line_outs++; |
| 955 | } |
| 956 | if (cfg->input_pins[AUTO_PIN_MIC]) { |
| 957 | cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC]; |
| 958 | spec->mic_switch = 1; |
| 959 | cfg->line_outs++; |
| 960 | } |
| 961 | break; |
| 962 | } |
| 963 | |
| 964 | return 0; |
| 965 | } |
| 966 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 967 | /* |
| 968 | * XXX The line_out pin widget connection list may not be set to the |
| 969 | * desired DAC nid. This is the case on 927x where ports A and B can |
| 970 | * be routed to several DACs. |
| 971 | * |
| 972 | * This requires an analysis of the line-out/hp pin configuration |
| 973 | * to provide a best fit for pin/DAC configurations that are routable. |
| 974 | * For now, 927x DAC4 is not supported and 927x DAC1 output to ports |
| 975 | * A and B is not supported. |
| 976 | */ |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 977 | /* fill in the dac_nids table from the parsed pin configuration */ |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 978 | static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, |
| 979 | const struct auto_pin_cfg *cfg) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 980 | { |
| 981 | struct sigmatel_spec *spec = codec->spec; |
| 982 | hda_nid_t nid; |
| 983 | int i; |
| 984 | |
| 985 | /* check the pins hardwired to audio widget */ |
| 986 | for (i = 0; i < cfg->line_outs; i++) { |
| 987 | nid = cfg->line_out_pins[i]; |
| 988 | spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0, |
| 989 | AC_VERB_GET_CONNECT_LIST, 0) & 0xff; |
| 990 | } |
| 991 | |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 992 | spec->multiout.num_dacs = cfg->line_outs; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | /* add playback controls from the parsed DAC table */ |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 998 | static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, |
| 999 | const struct auto_pin_cfg *cfg) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1000 | { |
| 1001 | char name[32]; |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 1002 | static const char *chname[4] = { |
| 1003 | "Front", "Surround", NULL /*CLFE*/, "Side" |
| 1004 | }; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1005 | hda_nid_t nid; |
| 1006 | int i, err; |
| 1007 | |
| 1008 | for (i = 0; i < cfg->line_outs; i++) { |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 1009 | if (!spec->multiout.dac_nids[i]) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1010 | continue; |
| 1011 | |
| 1012 | nid = spec->multiout.dac_nids[i]; |
| 1013 | |
| 1014 | if (i == 2) { |
| 1015 | /* Center/LFE */ |
| 1016 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume", |
| 1017 | HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0) |
| 1018 | return err; |
| 1019 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume", |
| 1020 | HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0) |
| 1021 | return err; |
| 1022 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch", |
| 1023 | HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0) |
| 1024 | return err; |
| 1025 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch", |
| 1026 | HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0) |
| 1027 | return err; |
| 1028 | } else { |
| 1029 | sprintf(name, "%s Playback Volume", chname[i]); |
| 1030 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name, |
| 1031 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) |
| 1032 | return err; |
| 1033 | sprintf(name, "%s Playback Switch", chname[i]); |
| 1034 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name, |
| 1035 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) |
| 1036 | return err; |
| 1037 | } |
| 1038 | } |
| 1039 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 1040 | if (spec->line_switch) |
| 1041 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0) |
| 1042 | return err; |
| 1043 | |
| 1044 | if (spec->mic_switch) |
| 1045 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0) |
| 1046 | return err; |
| 1047 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1048 | return 0; |
| 1049 | } |
| 1050 | |
| 1051 | /* add playback controls for HP output */ |
| 1052 | static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg) |
| 1053 | { |
| 1054 | struct sigmatel_spec *spec = codec->spec; |
| 1055 | hda_nid_t pin = cfg->hp_pin; |
| 1056 | hda_nid_t nid; |
| 1057 | int i, err; |
Matt | 4e55096 | 2005-07-04 17:51:39 +0200 | [diff] [blame] | 1058 | unsigned int wid_caps; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1059 | |
| 1060 | if (! pin) |
| 1061 | return 0; |
| 1062 | |
Takashi Iwai | 54d1740 | 2005-11-21 16:33:22 +0100 | [diff] [blame] | 1063 | wid_caps = get_wcaps(codec, pin); |
Takashi Iwai | 505cb34 | 2006-03-27 12:51:52 +0200 | [diff] [blame] | 1064 | if (wid_caps & AC_WCAP_UNSOL_CAP) |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1065 | spec->hp_detect = 1; |
Matt | 4e55096 | 2005-07-04 17:51:39 +0200 | [diff] [blame] | 1066 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1067 | nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff; |
| 1068 | for (i = 0; i < cfg->line_outs; i++) { |
| 1069 | if (! spec->multiout.dac_nids[i]) |
| 1070 | continue; |
| 1071 | if (spec->multiout.dac_nids[i] == nid) |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | spec->multiout.hp_nid = nid; |
| 1076 | |
| 1077 | /* control HP volume/switch on the output mixer amp */ |
| 1078 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume", |
| 1079 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) |
| 1080 | return err; |
| 1081 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch", |
| 1082 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) |
| 1083 | return err; |
| 1084 | |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
| 1088 | /* create playback/capture controls for input pins */ |
| 1089 | static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) |
| 1090 | { |
| 1091 | struct sigmatel_spec *spec = codec->spec; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1092 | struct hda_input_mux *imux = &spec->private_imux; |
| 1093 | hda_nid_t con_lst[HDA_MAX_NUM_INPUTS]; |
| 1094 | int i, j, k; |
| 1095 | |
| 1096 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 1097 | int index = -1; |
| 1098 | if (cfg->input_pins[i]) { |
Takashi Iwai | 4a471b7 | 2005-12-07 13:56:29 +0100 | [diff] [blame] | 1099 | imux->items[imux->num_items].label = auto_pin_cfg_labels[i]; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1100 | |
| 1101 | for (j=0; j<spec->num_muxes; j++) { |
| 1102 | int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS); |
| 1103 | for (k=0; k<num_cons; k++) |
| 1104 | if (con_lst[k] == cfg->input_pins[i]) { |
| 1105 | index = k; |
| 1106 | break; |
| 1107 | } |
| 1108 | if (index >= 0) |
| 1109 | break; |
| 1110 | } |
| 1111 | imux->items[imux->num_items].index = index; |
| 1112 | imux->num_items++; |
| 1113 | } |
| 1114 | } |
| 1115 | |
Sam Revitch | 62fe78e | 2006-05-10 15:09:17 +0200 | [diff] [blame] | 1116 | if (imux->num_items == 1) { |
| 1117 | /* |
| 1118 | * Set the current input for the muxes. |
| 1119 | * The STAC9221 has two input muxes with identical source |
| 1120 | * NID lists. Hopefully this won't get confused. |
| 1121 | */ |
| 1122 | for (i = 0; i < spec->num_muxes; i++) { |
| 1123 | snd_hda_codec_write(codec, spec->mux_nids[i], 0, |
| 1124 | AC_VERB_SET_CONNECT_SEL, |
| 1125 | imux->items[0].index); |
| 1126 | } |
| 1127 | } |
| 1128 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1129 | return 0; |
| 1130 | } |
| 1131 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1132 | static void stac92xx_auto_init_multi_out(struct hda_codec *codec) |
| 1133 | { |
| 1134 | struct sigmatel_spec *spec = codec->spec; |
| 1135 | int i; |
| 1136 | |
| 1137 | for (i = 0; i < spec->autocfg.line_outs; i++) { |
| 1138 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 1139 | stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN); |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | static void stac92xx_auto_init_hp_out(struct hda_codec *codec) |
| 1144 | { |
| 1145 | struct sigmatel_spec *spec = codec->spec; |
| 1146 | hda_nid_t pin; |
| 1147 | |
| 1148 | pin = spec->autocfg.hp_pin; |
| 1149 | if (pin) /* connect to front */ |
| 1150 | stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN); |
| 1151 | } |
| 1152 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1153 | static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1154 | { |
| 1155 | struct sigmatel_spec *spec = codec->spec; |
| 1156 | int err; |
| 1157 | |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 1158 | if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1159 | return err; |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1160 | if (! spec->autocfg.line_outs) |
Matt Porter | 869264c | 2006-01-25 19:20:50 +0100 | [diff] [blame] | 1161 | return 0; /* can't find valid pin config */ |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 1162 | |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 1163 | if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0) |
| 1164 | return err; |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 1165 | if (spec->multiout.num_dacs == 0) |
| 1166 | if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0) |
| 1167 | return err; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1168 | |
| 1169 | if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 || |
| 1170 | (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 || |
| 1171 | (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0) |
| 1172 | return err; |
| 1173 | |
| 1174 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 1175 | if (spec->multiout.max_channels > 2) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1176 | spec->surr_switch = 1; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1177 | |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1178 | if (spec->autocfg.dig_out_pin) |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1179 | spec->multiout.dig_out_nid = dig_out; |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1180 | if (spec->autocfg.dig_in_pin) |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1181 | spec->dig_in_nid = dig_in; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1182 | |
| 1183 | if (spec->kctl_alloc) |
| 1184 | spec->mixers[spec->num_mixers++] = spec->kctl_alloc; |
| 1185 | |
| 1186 | spec->input_mux = &spec->private_imux; |
| 1187 | |
| 1188 | return 1; |
| 1189 | } |
| 1190 | |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1191 | /* add playback controls for HP output */ |
| 1192 | static int stac9200_auto_create_hp_ctls(struct hda_codec *codec, |
| 1193 | struct auto_pin_cfg *cfg) |
| 1194 | { |
| 1195 | struct sigmatel_spec *spec = codec->spec; |
| 1196 | hda_nid_t pin = cfg->hp_pin; |
| 1197 | unsigned int wid_caps; |
| 1198 | |
| 1199 | if (! pin) |
| 1200 | return 0; |
| 1201 | |
| 1202 | wid_caps = get_wcaps(codec, pin); |
Takashi Iwai | 505cb34 | 2006-03-27 12:51:52 +0200 | [diff] [blame] | 1203 | if (wid_caps & AC_WCAP_UNSOL_CAP) |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1204 | spec->hp_detect = 1; |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1205 | |
| 1206 | return 0; |
| 1207 | } |
| 1208 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1209 | static int stac9200_parse_auto_config(struct hda_codec *codec) |
| 1210 | { |
| 1211 | struct sigmatel_spec *spec = codec->spec; |
| 1212 | int err; |
| 1213 | |
Kailang Yang | df694da | 2005-12-05 19:42:22 +0100 | [diff] [blame] | 1214 | if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1215 | return err; |
| 1216 | |
| 1217 | if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0) |
| 1218 | return err; |
| 1219 | |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1220 | if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0) |
| 1221 | return err; |
| 1222 | |
| 1223 | if (spec->autocfg.dig_out_pin) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1224 | spec->multiout.dig_out_nid = 0x05; |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1225 | if (spec->autocfg.dig_in_pin) |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1226 | spec->dig_in_nid = 0x04; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1227 | |
| 1228 | if (spec->kctl_alloc) |
| 1229 | spec->mixers[spec->num_mixers++] = spec->kctl_alloc; |
| 1230 | |
| 1231 | spec->input_mux = &spec->private_imux; |
| 1232 | |
| 1233 | return 1; |
| 1234 | } |
| 1235 | |
Sam Revitch | 62fe78e | 2006-05-10 15:09:17 +0200 | [diff] [blame] | 1236 | /* |
| 1237 | * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a |
| 1238 | * funky external mute control using GPIO pins. |
| 1239 | */ |
| 1240 | |
| 1241 | static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted) |
| 1242 | { |
| 1243 | unsigned int gpiostate, gpiomask, gpiodir; |
| 1244 | |
| 1245 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, |
| 1246 | AC_VERB_GET_GPIO_DATA, 0); |
| 1247 | |
| 1248 | if (!muted) |
| 1249 | gpiostate |= (1 << pin); |
| 1250 | else |
| 1251 | gpiostate &= ~(1 << pin); |
| 1252 | |
| 1253 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, |
| 1254 | AC_VERB_GET_GPIO_MASK, 0); |
| 1255 | gpiomask |= (1 << pin); |
| 1256 | |
| 1257 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, |
| 1258 | AC_VERB_GET_GPIO_DIRECTION, 0); |
| 1259 | gpiodir |= (1 << pin); |
| 1260 | |
| 1261 | /* AppleHDA seems to do this -- WTF is this verb?? */ |
| 1262 | snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0); |
| 1263 | |
| 1264 | snd_hda_codec_write(codec, codec->afg, 0, |
| 1265 | AC_VERB_SET_GPIO_MASK, gpiomask); |
| 1266 | snd_hda_codec_write(codec, codec->afg, 0, |
| 1267 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); |
| 1268 | |
| 1269 | msleep(1); |
| 1270 | |
| 1271 | snd_hda_codec_write(codec, codec->afg, 0, |
| 1272 | AC_VERB_SET_GPIO_DATA, gpiostate); |
| 1273 | } |
| 1274 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1275 | static int stac92xx_init(struct hda_codec *codec) |
| 1276 | { |
| 1277 | struct sigmatel_spec *spec = codec->spec; |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1278 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1279 | int i; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1280 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1281 | snd_hda_sequence_write(codec, spec->init); |
| 1282 | |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1283 | /* set up pins */ |
| 1284 | if (spec->hp_detect) { |
Takashi Iwai | 505cb34 | 2006-03-27 12:51:52 +0200 | [diff] [blame] | 1285 | /* Enable unsolicited responses on the HP widget */ |
| 1286 | snd_hda_codec_write(codec, cfg->hp_pin, 0, |
| 1287 | AC_VERB_SET_UNSOLICITED_ENABLE, |
| 1288 | STAC_UNSOL_ENABLE); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1289 | /* fake event to set up pins */ |
| 1290 | codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); |
Tobin Davis | 68a6abd | 2006-08-21 19:02:10 +0200 | [diff] [blame] | 1291 | /* enable the headphones by default. If/when unsol_event detection works, this will be ignored */ |
| 1292 | stac92xx_auto_init_hp_out(codec); |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1293 | } else { |
| 1294 | stac92xx_auto_init_multi_out(codec); |
| 1295 | stac92xx_auto_init_hp_out(codec); |
| 1296 | } |
| 1297 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
Takashi Iwai | c960a03 | 2006-03-23 17:06:28 +0100 | [diff] [blame] | 1298 | hda_nid_t nid = cfg->input_pins[i]; |
| 1299 | if (nid) { |
| 1300 | unsigned int pinctl = AC_PINCTL_IN_EN; |
| 1301 | if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) |
| 1302 | pinctl |= stac92xx_get_vref(codec, nid); |
| 1303 | stac92xx_auto_set_pinctl(codec, nid, pinctl); |
| 1304 | } |
Takashi Iwai | 82bc955 | 2006-03-21 11:24:42 +0100 | [diff] [blame] | 1305 | } |
| 1306 | if (cfg->dig_out_pin) |
| 1307 | stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin, |
| 1308 | AC_PINCTL_OUT_EN); |
| 1309 | if (cfg->dig_in_pin) |
| 1310 | stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin, |
| 1311 | AC_PINCTL_IN_EN); |
| 1312 | |
Sam Revitch | 62fe78e | 2006-05-10 15:09:17 +0200 | [diff] [blame] | 1313 | if (spec->gpio_mute) { |
| 1314 | stac922x_gpio_mute(codec, 0, 0); |
| 1315 | stac922x_gpio_mute(codec, 1, 0); |
| 1316 | } |
| 1317 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1318 | return 0; |
| 1319 | } |
| 1320 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1321 | static void stac92xx_free(struct hda_codec *codec) |
| 1322 | { |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1323 | struct sigmatel_spec *spec = codec->spec; |
| 1324 | int i; |
| 1325 | |
| 1326 | if (! spec) |
| 1327 | return; |
| 1328 | |
| 1329 | if (spec->kctl_alloc) { |
| 1330 | for (i = 0; i < spec->num_kctl_used; i++) |
| 1331 | kfree(spec->kctl_alloc[i].name); |
| 1332 | kfree(spec->kctl_alloc); |
| 1333 | } |
| 1334 | |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1335 | if (spec->bios_pin_configs) |
| 1336 | kfree(spec->bios_pin_configs); |
| 1337 | |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1338 | kfree(spec); |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
Matt | 4e55096 | 2005-07-04 17:51:39 +0200 | [diff] [blame] | 1341 | static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid, |
| 1342 | unsigned int flag) |
| 1343 | { |
| 1344 | unsigned int pin_ctl = snd_hda_codec_read(codec, nid, |
| 1345 | 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); |
| 1346 | snd_hda_codec_write(codec, nid, 0, |
| 1347 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1348 | pin_ctl | flag); |
| 1349 | } |
| 1350 | |
| 1351 | static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, |
| 1352 | unsigned int flag) |
| 1353 | { |
| 1354 | unsigned int pin_ctl = snd_hda_codec_read(codec, nid, |
| 1355 | 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); |
| 1356 | snd_hda_codec_write(codec, nid, 0, |
| 1357 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1358 | pin_ctl & ~flag); |
| 1359 | } |
| 1360 | |
| 1361 | static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res) |
| 1362 | { |
| 1363 | struct sigmatel_spec *spec = codec->spec; |
| 1364 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1365 | int i, presence; |
| 1366 | |
| 1367 | if ((res >> 26) != STAC_HP_EVENT) |
| 1368 | return; |
| 1369 | |
| 1370 | presence = snd_hda_codec_read(codec, cfg->hp_pin, 0, |
| 1371 | AC_VERB_GET_PIN_SENSE, 0x00) >> 31; |
| 1372 | |
| 1373 | if (presence) { |
| 1374 | /* disable lineouts, enable hp */ |
| 1375 | for (i = 0; i < cfg->line_outs; i++) |
| 1376 | stac92xx_reset_pinctl(codec, cfg->line_out_pins[i], |
| 1377 | AC_PINCTL_OUT_EN); |
| 1378 | stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN); |
| 1379 | } else { |
| 1380 | /* enable lineouts, disable hp */ |
| 1381 | for (i = 0; i < cfg->line_outs; i++) |
| 1382 | stac92xx_set_pinctl(codec, cfg->line_out_pins[i], |
| 1383 | AC_PINCTL_OUT_EN); |
| 1384 | stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN); |
| 1385 | } |
| 1386 | } |
| 1387 | |
Matt | ff6fdc3 | 2005-06-27 15:06:52 +0200 | [diff] [blame] | 1388 | #ifdef CONFIG_PM |
| 1389 | static int stac92xx_resume(struct hda_codec *codec) |
| 1390 | { |
| 1391 | struct sigmatel_spec *spec = codec->spec; |
| 1392 | int i; |
| 1393 | |
| 1394 | stac92xx_init(codec); |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1395 | stac92xx_set_config_regs(codec); |
Matt | ff6fdc3 | 2005-06-27 15:06:52 +0200 | [diff] [blame] | 1396 | for (i = 0; i < spec->num_mixers; i++) |
| 1397 | snd_hda_resume_ctls(codec, spec->mixers[i]); |
| 1398 | if (spec->multiout.dig_out_nid) |
| 1399 | snd_hda_resume_spdif_out(codec); |
| 1400 | if (spec->dig_in_nid) |
| 1401 | snd_hda_resume_spdif_in(codec); |
| 1402 | |
| 1403 | return 0; |
| 1404 | } |
| 1405 | #endif |
| 1406 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1407 | static struct hda_codec_ops stac92xx_patch_ops = { |
| 1408 | .build_controls = stac92xx_build_controls, |
| 1409 | .build_pcms = stac92xx_build_pcms, |
| 1410 | .init = stac92xx_init, |
| 1411 | .free = stac92xx_free, |
Matt | 4e55096 | 2005-07-04 17:51:39 +0200 | [diff] [blame] | 1412 | .unsol_event = stac92xx_unsol_event, |
Matt | ff6fdc3 | 2005-06-27 15:06:52 +0200 | [diff] [blame] | 1413 | #ifdef CONFIG_PM |
| 1414 | .resume = stac92xx_resume, |
| 1415 | #endif |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1416 | }; |
| 1417 | |
| 1418 | static int patch_stac9200(struct hda_codec *codec) |
| 1419 | { |
| 1420 | struct sigmatel_spec *spec; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1421 | int err; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1422 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 1423 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1424 | if (spec == NULL) |
| 1425 | return -ENOMEM; |
| 1426 | |
| 1427 | codec->spec = spec; |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1428 | spec->num_pins = 8; |
| 1429 | spec->pin_nids = stac9200_pin_nids; |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 1430 | spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl); |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1431 | if (spec->board_config < 0) { |
| 1432 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n"); |
| 1433 | err = stac92xx_save_bios_config_regs(codec); |
| 1434 | if (err < 0) { |
| 1435 | stac92xx_free(codec); |
| 1436 | return err; |
| 1437 | } |
| 1438 | spec->pin_configs = spec->bios_pin_configs; |
| 1439 | } else { |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 1440 | spec->pin_configs = stac9200_brd_tbl[spec->board_config]; |
| 1441 | stac92xx_set_config_regs(codec); |
| 1442 | } |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1443 | |
| 1444 | spec->multiout.max_channels = 2; |
| 1445 | spec->multiout.num_dacs = 1; |
| 1446 | spec->multiout.dac_nids = stac9200_dac_nids; |
| 1447 | spec->adc_nids = stac9200_adc_nids; |
| 1448 | spec->mux_nids = stac9200_mux_nids; |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 1449 | spec->num_muxes = 1; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1450 | |
| 1451 | spec->init = stac9200_core_init; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1452 | spec->mixer = stac9200_mixer; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1453 | |
| 1454 | err = stac9200_parse_auto_config(codec); |
| 1455 | if (err < 0) { |
| 1456 | stac92xx_free(codec); |
| 1457 | return err; |
| 1458 | } |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1459 | |
| 1460 | codec->patch_ops = stac92xx_patch_ops; |
| 1461 | |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
| 1465 | static int patch_stac922x(struct hda_codec *codec) |
| 1466 | { |
| 1467 | struct sigmatel_spec *spec; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1468 | int err; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1469 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 1470 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1471 | if (spec == NULL) |
| 1472 | return -ENOMEM; |
| 1473 | |
| 1474 | codec->spec = spec; |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1475 | spec->num_pins = 10; |
| 1476 | spec->pin_nids = stac922x_pin_nids; |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 1477 | spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl); |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1478 | if (spec->board_config < 0) { |
| 1479 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, " |
| 1480 | "using BIOS defaults\n"); |
| 1481 | err = stac92xx_save_bios_config_regs(codec); |
| 1482 | if (err < 0) { |
| 1483 | stac92xx_free(codec); |
| 1484 | return err; |
| 1485 | } |
| 1486 | spec->pin_configs = spec->bios_pin_configs; |
| 1487 | } else if (stac922x_brd_tbl[spec->board_config] != NULL) { |
Matt Porter | 403d194 | 2005-11-29 15:00:51 +0100 | [diff] [blame] | 1488 | spec->pin_configs = stac922x_brd_tbl[spec->board_config]; |
| 1489 | stac92xx_set_config_regs(codec); |
| 1490 | } |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1491 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1492 | spec->adc_nids = stac922x_adc_nids; |
| 1493 | spec->mux_nids = stac922x_mux_nids; |
Matt | dabbed6 | 2005-06-14 10:19:34 +0200 | [diff] [blame] | 1494 | spec->num_muxes = 2; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1495 | |
| 1496 | spec->init = stac922x_core_init; |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1497 | spec->mixer = stac922x_mixer; |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1498 | |
| 1499 | spec->multiout.dac_nids = spec->dac_nids; |
Takashi Iwai | 19039bd | 2006-06-28 15:52:16 +0200 | [diff] [blame] | 1500 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1501 | err = stac92xx_parse_auto_config(codec, 0x08, 0x09); |
| 1502 | if (err < 0) { |
| 1503 | stac92xx_free(codec); |
| 1504 | return err; |
| 1505 | } |
| 1506 | |
Sam Revitch | 62fe78e | 2006-05-10 15:09:17 +0200 | [diff] [blame] | 1507 | if (spec->board_config == STAC_MACMINI) |
| 1508 | spec->gpio_mute = 1; |
| 1509 | |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1510 | codec->patch_ops = stac92xx_patch_ops; |
| 1511 | |
| 1512 | return 0; |
| 1513 | } |
| 1514 | |
| 1515 | static int patch_stac927x(struct hda_codec *codec) |
| 1516 | { |
| 1517 | struct sigmatel_spec *spec; |
| 1518 | int err; |
| 1519 | |
| 1520 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1521 | if (spec == NULL) |
| 1522 | return -ENOMEM; |
| 1523 | |
| 1524 | codec->spec = spec; |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1525 | spec->num_pins = 14; |
| 1526 | spec->pin_nids = stac927x_pin_nids; |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1527 | spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl); |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1528 | if (spec->board_config < 0) { |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1529 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n"); |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1530 | err = stac92xx_save_bios_config_regs(codec); |
| 1531 | if (err < 0) { |
| 1532 | stac92xx_free(codec); |
| 1533 | return err; |
| 1534 | } |
| 1535 | spec->pin_configs = spec->bios_pin_configs; |
| 1536 | } else if (stac927x_brd_tbl[spec->board_config] != NULL) { |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1537 | spec->pin_configs = stac927x_brd_tbl[spec->board_config]; |
| 1538 | stac92xx_set_config_regs(codec); |
| 1539 | } |
| 1540 | |
Tobin Davis | 81d3dbd | 2006-08-22 19:44:45 +0200 | [diff] [blame] | 1541 | switch (spec->board_config) { |
| 1542 | case STAC_D965_2112: |
| 1543 | spec->adc_nids = stac927x_adc_nids; |
| 1544 | spec->mux_nids = stac927x_mux_nids; |
| 1545 | spec->num_muxes = 3; |
| 1546 | spec->init = d965_2112_core_init; |
| 1547 | spec->mixer = stac9227_mixer; |
| 1548 | break; |
| 1549 | case STAC_D965_284B: |
| 1550 | spec->adc_nids = stac9227_adc_nids; |
| 1551 | spec->mux_nids = stac9227_mux_nids; |
| 1552 | spec->num_muxes = 2; |
| 1553 | spec->init = stac9227_core_init; |
| 1554 | spec->mixer = stac9227_mixer; |
| 1555 | break; |
| 1556 | default: |
| 1557 | spec->adc_nids = stac927x_adc_nids; |
| 1558 | spec->mux_nids = stac927x_mux_nids; |
| 1559 | spec->num_muxes = 3; |
| 1560 | spec->init = stac927x_core_init; |
| 1561 | spec->mixer = stac927x_mixer; |
| 1562 | } |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1563 | |
| 1564 | spec->multiout.dac_nids = spec->dac_nids; |
| 1565 | |
| 1566 | err = stac92xx_parse_auto_config(codec, 0x1e, 0x20); |
Matt | c7d4b2f | 2005-06-27 14:59:41 +0200 | [diff] [blame] | 1567 | if (err < 0) { |
| 1568 | stac92xx_free(codec); |
| 1569 | return err; |
| 1570 | } |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1571 | |
| 1572 | codec->patch_ops = stac92xx_patch_ops; |
| 1573 | |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 1577 | static int patch_stac9205(struct hda_codec *codec) |
| 1578 | { |
| 1579 | struct sigmatel_spec *spec; |
| 1580 | int err; |
| 1581 | |
| 1582 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1583 | if (spec == NULL) |
| 1584 | return -ENOMEM; |
| 1585 | |
| 1586 | codec->spec = spec; |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1587 | spec->num_pins = 14; |
| 1588 | spec->pin_nids = stac9205_pin_nids; |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 1589 | spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl); |
Richard Fish | 11b44bb | 2006-08-23 18:31:34 +0200 | [diff] [blame^] | 1590 | if (spec->board_config < 0) { |
| 1591 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n"); |
| 1592 | err = stac92xx_save_bios_config_regs(codec); |
| 1593 | if (err < 0) { |
| 1594 | stac92xx_free(codec); |
| 1595 | return err; |
| 1596 | } |
| 1597 | spec->pin_configs = spec->bios_pin_configs; |
| 1598 | } else { |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 1599 | spec->pin_configs = stac9205_brd_tbl[spec->board_config]; |
| 1600 | stac92xx_set_config_regs(codec); |
| 1601 | } |
| 1602 | |
| 1603 | spec->adc_nids = stac9205_adc_nids; |
| 1604 | spec->mux_nids = stac9205_mux_nids; |
| 1605 | spec->num_muxes = 3; |
| 1606 | |
| 1607 | spec->init = stac9205_core_init; |
| 1608 | spec->mixer = stac9205_mixer; |
| 1609 | |
| 1610 | spec->multiout.dac_nids = spec->dac_nids; |
| 1611 | |
| 1612 | err = stac92xx_parse_auto_config(codec, 0x1f, 0x20); |
| 1613 | if (err < 0) { |
| 1614 | stac92xx_free(codec); |
| 1615 | return err; |
| 1616 | } |
| 1617 | |
| 1618 | codec->patch_ops = stac92xx_patch_ops; |
| 1619 | |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1623 | /* |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1624 | * STAC9872 hack |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1625 | */ |
| 1626 | |
Guillaume Munch | 99ccc56 | 2006-08-16 19:35:12 +0200 | [diff] [blame] | 1627 | /* static config for Sony VAIO FE550G and Sony VAIO AR */ |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1628 | static hda_nid_t vaio_dacs[] = { 0x2 }; |
| 1629 | #define VAIO_HP_DAC 0x5 |
| 1630 | static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ }; |
| 1631 | static hda_nid_t vaio_mux_nids[] = { 0x15 }; |
| 1632 | |
| 1633 | static struct hda_input_mux vaio_mux = { |
| 1634 | .num_items = 2, |
| 1635 | .items = { |
Takashi Iwai | d773781 | 2006-04-25 13:05:43 +0200 | [diff] [blame] | 1636 | /* { "HP", 0x0 }, */ |
| 1637 | { "Line", 0x1 }, |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1638 | { "Mic", 0x2 }, |
| 1639 | { "PCM", 0x3 }, |
| 1640 | } |
| 1641 | }; |
| 1642 | |
| 1643 | static struct hda_verb vaio_init[] = { |
| 1644 | {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */ |
| 1645 | {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */ |
| 1646 | {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */ |
| 1647 | {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */ |
| 1648 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */ |
| 1649 | {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */ |
| 1650 | {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */ |
| 1651 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */ |
| 1652 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */ |
| 1653 | {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */ |
| 1654 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */ |
| 1655 | {} |
| 1656 | }; |
| 1657 | |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1658 | static struct hda_verb vaio_ar_init[] = { |
| 1659 | {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */ |
| 1660 | {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */ |
| 1661 | {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */ |
| 1662 | {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */ |
| 1663 | /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */ |
| 1664 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */ |
| 1665 | {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */ |
| 1666 | {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */ |
| 1667 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */ |
| 1668 | /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */ |
| 1669 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */ |
| 1670 | {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */ |
| 1671 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */ |
| 1672 | {} |
| 1673 | }; |
| 1674 | |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1675 | /* bind volumes of both NID 0x02 and 0x05 */ |
| 1676 | static int vaio_master_vol_put(struct snd_kcontrol *kcontrol, |
| 1677 | struct snd_ctl_elem_value *ucontrol) |
| 1678 | { |
| 1679 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1680 | long *valp = ucontrol->value.integer.value; |
| 1681 | int change; |
| 1682 | |
| 1683 | change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0, |
| 1684 | 0x7f, valp[0] & 0x7f); |
| 1685 | change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0, |
| 1686 | 0x7f, valp[1] & 0x7f); |
| 1687 | snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0, |
| 1688 | 0x7f, valp[0] & 0x7f); |
| 1689 | snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0, |
| 1690 | 0x7f, valp[1] & 0x7f); |
| 1691 | return change; |
| 1692 | } |
| 1693 | |
| 1694 | /* bind volumes of both NID 0x02 and 0x05 */ |
| 1695 | static int vaio_master_sw_put(struct snd_kcontrol *kcontrol, |
| 1696 | struct snd_ctl_elem_value *ucontrol) |
| 1697 | { |
| 1698 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1699 | long *valp = ucontrol->value.integer.value; |
| 1700 | int change; |
| 1701 | |
| 1702 | change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0, |
Takashi Iwai | a9393d7 | 2006-05-03 11:59:03 +0200 | [diff] [blame] | 1703 | 0x80, (valp[0] ? 0 : 0x80)); |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1704 | change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0, |
Takashi Iwai | a9393d7 | 2006-05-03 11:59:03 +0200 | [diff] [blame] | 1705 | 0x80, (valp[1] ? 0 : 0x80)); |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1706 | snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0, |
Takashi Iwai | a9393d7 | 2006-05-03 11:59:03 +0200 | [diff] [blame] | 1707 | 0x80, (valp[0] ? 0 : 0x80)); |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1708 | snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0, |
Takashi Iwai | a9393d7 | 2006-05-03 11:59:03 +0200 | [diff] [blame] | 1709 | 0x80, (valp[1] ? 0 : 0x80)); |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1710 | return change; |
| 1711 | } |
| 1712 | |
| 1713 | static struct snd_kcontrol_new vaio_mixer[] = { |
| 1714 | { |
| 1715 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1716 | .name = "Master Playback Volume", |
| 1717 | .info = snd_hda_mixer_amp_volume_info, |
| 1718 | .get = snd_hda_mixer_amp_volume_get, |
| 1719 | .put = vaio_master_vol_put, |
Takashi Iwai | c256652 | 2006-08-17 18:21:36 +0200 | [diff] [blame] | 1720 | .tlv = { .c = snd_hda_mixer_amp_tlv }, |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1721 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), |
| 1722 | }, |
| 1723 | { |
| 1724 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1725 | .name = "Master Playback Switch", |
| 1726 | .info = snd_hda_mixer_amp_switch_info, |
| 1727 | .get = snd_hda_mixer_amp_switch_get, |
| 1728 | .put = vaio_master_sw_put, |
| 1729 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), |
| 1730 | }, |
| 1731 | /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */ |
| 1732 | HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), |
| 1733 | HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), |
| 1734 | { |
| 1735 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1736 | .name = "Capture Source", |
| 1737 | .count = 1, |
| 1738 | .info = stac92xx_mux_enum_info, |
| 1739 | .get = stac92xx_mux_enum_get, |
| 1740 | .put = stac92xx_mux_enum_put, |
| 1741 | }, |
| 1742 | {} |
| 1743 | }; |
| 1744 | |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1745 | static struct snd_kcontrol_new vaio_ar_mixer[] = { |
| 1746 | { |
| 1747 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1748 | .name = "Master Playback Volume", |
| 1749 | .info = snd_hda_mixer_amp_volume_info, |
| 1750 | .get = snd_hda_mixer_amp_volume_get, |
| 1751 | .put = vaio_master_vol_put, |
| 1752 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), |
| 1753 | }, |
| 1754 | { |
| 1755 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1756 | .name = "Master Playback Switch", |
| 1757 | .info = snd_hda_mixer_amp_switch_info, |
| 1758 | .get = snd_hda_mixer_amp_switch_get, |
| 1759 | .put = vaio_master_sw_put, |
| 1760 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), |
| 1761 | }, |
| 1762 | /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */ |
| 1763 | HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), |
| 1764 | HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), |
| 1765 | /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT), |
| 1766 | HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/ |
| 1767 | { |
| 1768 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1769 | .name = "Capture Source", |
| 1770 | .count = 1, |
| 1771 | .info = stac92xx_mux_enum_info, |
| 1772 | .get = stac92xx_mux_enum_get, |
| 1773 | .put = stac92xx_mux_enum_put, |
| 1774 | }, |
| 1775 | {} |
| 1776 | }; |
| 1777 | |
| 1778 | static struct hda_codec_ops stac9872_patch_ops = { |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1779 | .build_controls = stac92xx_build_controls, |
| 1780 | .build_pcms = stac92xx_build_pcms, |
| 1781 | .init = stac92xx_init, |
| 1782 | .free = stac92xx_free, |
| 1783 | #ifdef CONFIG_PM |
| 1784 | .resume = stac92xx_resume, |
| 1785 | #endif |
| 1786 | }; |
| 1787 | |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1788 | enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */ |
| 1789 | CXD9872RD_VAIO, |
| 1790 | /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */ |
| 1791 | STAC9872AK_VAIO, |
| 1792 | /* Unknown. id=0x83847661 and subsys=0x104D1200. */ |
| 1793 | STAC9872K_VAIO, |
| 1794 | /* AR Series. id=0x83847664 and subsys=104D1300 */ |
| 1795 | CXD9872AKD_VAIO |
| 1796 | }; |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1797 | |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1798 | static struct hda_board_config stac9872_cfg_tbl[] = { |
| 1799 | { .modelname = "vaio", .config = CXD9872RD_VAIO }, |
| 1800 | { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO }, |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1801 | { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6, |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1802 | .config = CXD9872RD_VAIO }, |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1803 | { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef, |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1804 | .config = CXD9872RD_VAIO }, |
Guillaume Munch | 99ccc56 | 2006-08-16 19:35:12 +0200 | [diff] [blame] | 1805 | { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd, |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1806 | .config = CXD9872AKD_VAIO }, |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1807 | {} |
| 1808 | }; |
| 1809 | |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1810 | static int patch_stac9872(struct hda_codec *codec) |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1811 | { |
| 1812 | struct sigmatel_spec *spec; |
| 1813 | int board_config; |
| 1814 | |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1815 | board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl); |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1816 | if (board_config < 0) |
| 1817 | /* unknown config, let generic-parser do its job... */ |
| 1818 | return snd_hda_parse_generic_codec(codec); |
| 1819 | |
| 1820 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 1821 | if (spec == NULL) |
| 1822 | return -ENOMEM; |
| 1823 | |
| 1824 | codec->spec = spec; |
| 1825 | switch (board_config) { |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1826 | case CXD9872RD_VAIO: |
| 1827 | case STAC9872AK_VAIO: |
| 1828 | case STAC9872K_VAIO: |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1829 | spec->mixer = vaio_mixer; |
| 1830 | spec->init = vaio_init; |
| 1831 | spec->multiout.max_channels = 2; |
| 1832 | spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs); |
| 1833 | spec->multiout.dac_nids = vaio_dacs; |
| 1834 | spec->multiout.hp_nid = VAIO_HP_DAC; |
| 1835 | spec->num_adcs = ARRAY_SIZE(vaio_adcs); |
| 1836 | spec->adc_nids = vaio_adcs; |
| 1837 | spec->input_mux = &vaio_mux; |
| 1838 | spec->mux_nids = vaio_mux_nids; |
| 1839 | break; |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1840 | |
| 1841 | case CXD9872AKD_VAIO: |
| 1842 | spec->mixer = vaio_ar_mixer; |
| 1843 | spec->init = vaio_ar_init; |
| 1844 | spec->multiout.max_channels = 2; |
| 1845 | spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs); |
| 1846 | spec->multiout.dac_nids = vaio_dacs; |
| 1847 | spec->multiout.hp_nid = VAIO_HP_DAC; |
| 1848 | spec->num_adcs = ARRAY_SIZE(vaio_adcs); |
| 1849 | spec->adc_nids = vaio_adcs; |
| 1850 | spec->input_mux = &vaio_mux; |
| 1851 | spec->mux_nids = vaio_mux_nids; |
| 1852 | break; |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1855 | codec->patch_ops = stac9872_patch_ops; |
Takashi Iwai | db064e5 | 2006-03-16 16:04:58 +0100 | [diff] [blame] | 1856 | return 0; |
| 1857 | } |
| 1858 | |
| 1859 | |
| 1860 | /* |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1861 | * patch entries |
| 1862 | */ |
| 1863 | struct hda_codec_preset snd_hda_preset_sigmatel[] = { |
| 1864 | { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 }, |
| 1865 | { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x }, |
| 1866 | { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x }, |
| 1867 | { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x }, |
| 1868 | { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x }, |
| 1869 | { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x }, |
| 1870 | { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x }, |
Matt Porter | 22a27c7 | 2006-07-06 18:49:10 +0200 | [diff] [blame] | 1871 | { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x }, |
| 1872 | { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x }, |
| 1873 | { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x }, |
| 1874 | { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x }, |
| 1875 | { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x }, |
| 1876 | { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x }, |
Matt Porter | 3cc08dc | 2006-01-23 15:27:49 +0100 | [diff] [blame] | 1877 | { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x }, |
| 1878 | { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x }, |
| 1879 | { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x }, |
| 1880 | { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x }, |
| 1881 | { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x }, |
| 1882 | { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x }, |
| 1883 | { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x }, |
| 1884 | { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x }, |
| 1885 | { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x }, |
| 1886 | { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x }, |
Guillaume Munch | 6d85906 | 2006-08-22 17:15:47 +0200 | [diff] [blame] | 1887 | /* The following does not take into account .id=0x83847661 when subsys = |
| 1888 | * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are |
| 1889 | * currently not fully supported. |
| 1890 | */ |
| 1891 | { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 }, |
| 1892 | { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 }, |
| 1893 | { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 }, |
Matt Porter | f3302a5 | 2006-07-31 12:49:34 +0200 | [diff] [blame] | 1894 | { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 }, |
| 1895 | { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 }, |
| 1896 | { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 }, |
| 1897 | { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 }, |
| 1898 | { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 }, |
| 1899 | { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 }, |
| 1900 | { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 }, |
| 1901 | { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 }, |
Matt | 2f2f425 | 2005-04-13 14:45:30 +0200 | [diff] [blame] | 1902 | {} /* terminator */ |
| 1903 | }; |