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