| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * HD audio interface patch for Conexant HDA audio codec | 
 | 3 |  * | 
 | 4 |  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> | 
 | 5 |  * 		      Takashi Iwai <tiwai@suse.de> | 
 | 6 |  * 		      Tobin Davis  <tdavis@dsl-only.net> | 
 | 7 |  * | 
 | 8 |  *  This driver is free software; you can redistribute it and/or modify | 
 | 9 |  *  it under the terms of the GNU General Public License as published by | 
 | 10 |  *  the Free Software Foundation; either version 2 of the License, or | 
 | 11 |  *  (at your option) any later version. | 
 | 12 |  * | 
 | 13 |  *  This driver is distributed in the hope that it will be useful, | 
 | 14 |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 15 |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 16 |  *  GNU General Public License for more details. | 
 | 17 |  * | 
 | 18 |  *  You should have received a copy of the GNU General Public License | 
 | 19 |  *  along with this program; if not, write to the Free Software | 
 | 20 |  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
 | 21 |  */ | 
 | 22 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 23 | #include <linux/init.h> | 
 | 24 | #include <linux/delay.h> | 
 | 25 | #include <linux/slab.h> | 
 | 26 | #include <linux/pci.h> | 
| Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 27 | #include <linux/module.h> | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 28 | #include <sound/core.h> | 
| Ulrich Dangel | bc7a166 | 2009-01-02 19:30:13 +0100 | [diff] [blame] | 29 | #include <sound/jack.h> | 
 | 30 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 31 | #include "hda_codec.h" | 
 | 32 | #include "hda_local.h" | 
| Einar Rünkaru | c0f8faf | 2009-12-16 22:41:36 +0200 | [diff] [blame] | 33 | #include "hda_beep.h" | 
| Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 34 | #include "hda_jack.h" | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 35 |  | 
 | 36 | #define CXT_PIN_DIR_IN              0x00 | 
 | 37 | #define CXT_PIN_DIR_OUT             0x01 | 
 | 38 | #define CXT_PIN_DIR_INOUT           0x02 | 
 | 39 | #define CXT_PIN_DIR_IN_NOMICBIAS    0x03 | 
 | 40 | #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 | 
 | 41 |  | 
 | 42 | #define CONEXANT_HP_EVENT	0x37 | 
 | 43 | #define CONEXANT_MIC_EVENT	0x38 | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 44 | #define CONEXANT_LINE_EVENT	0x39 | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 45 |  | 
| Ulrich Dangel | bc7a166 | 2009-01-02 19:30:13 +0100 | [diff] [blame] | 46 | /* Conexant 5051 specific */ | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 47 |  | 
| Takashi Iwai | ecda0cf | 2010-01-24 11:14:36 +0100 | [diff] [blame] | 48 | #define CXT5051_SPDIF_OUT	0x12 | 
| Ulrich Dangel | bc7a166 | 2009-01-02 19:30:13 +0100 | [diff] [blame] | 49 | #define CXT5051_PORTB_EVENT	0x38 | 
 | 50 | #define CXT5051_PORTC_EVENT	0x39 | 
 | 51 |  | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 52 | #define AUTO_MIC_PORTB		(1 << 1) | 
 | 53 | #define AUTO_MIC_PORTC		(1 << 2) | 
| Ulrich Dangel | bc7a166 | 2009-01-02 19:30:13 +0100 | [diff] [blame] | 54 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 55 | struct pin_dac_pair { | 
 | 56 | 	hda_nid_t pin; | 
 | 57 | 	hda_nid_t dac; | 
 | 58 | 	int type; | 
 | 59 | }; | 
 | 60 |  | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 61 | struct imux_info { | 
 | 62 | 	hda_nid_t pin;		/* input pin NID */ | 
 | 63 | 	hda_nid_t adc;		/* connected ADC NID */	 | 
 | 64 | 	hda_nid_t boost;	/* optional boost volume NID */ | 
 | 65 | 	int index;		/* corresponding to autocfg.input */ | 
 | 66 | }; | 
 | 67 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 68 | struct conexant_spec { | 
 | 69 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 70 | 	const struct snd_kcontrol_new *mixers[5]; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 71 | 	int num_mixers; | 
| Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 72 | 	hda_nid_t vmaster_nid; | 
| Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 73 | 	struct hda_vmaster_mute_hook vmaster_mute; | 
| Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 74 | 	bool vmaster_mute_led; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 75 |  | 
 | 76 | 	const struct hda_verb *init_verbs[5];	/* initialization verbs | 
 | 77 | 						 * don't forget NULL | 
 | 78 | 						 * termination! | 
 | 79 | 						 */ | 
 | 80 | 	unsigned int num_init_verbs; | 
 | 81 |  | 
 | 82 | 	/* playback */ | 
 | 83 | 	struct hda_multi_out multiout;	/* playback set-up | 
 | 84 | 					 * max_channels, dacs must be set | 
 | 85 | 					 * dig_out_nid and hp_nid are optional | 
 | 86 | 					 */ | 
 | 87 | 	unsigned int cur_eapd; | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 88 | 	unsigned int hp_present; | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 89 | 	unsigned int line_present; | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 90 | 	unsigned int auto_mic; | 
| Takashi Iwai | f6100bb | 2011-05-13 18:26:39 +0200 | [diff] [blame] | 91 | 	int auto_mic_ext;		/* imux_pins[] index for ext mic */ | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 92 | 	int auto_mic_dock;		/* imux_pins[] index for dock mic */ | 
 | 93 | 	int auto_mic_int;		/* imux_pins[] index for int mic */ | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 94 | 	unsigned int need_dac_fix; | 
| Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 95 | 	hda_nid_t slave_dig_outs[2]; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 96 |  | 
 | 97 | 	/* capture */ | 
 | 98 | 	unsigned int num_adc_nids; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 99 | 	const hda_nid_t *adc_nids; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 100 | 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */ | 
 | 101 |  | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 102 | 	unsigned int cur_adc_idx; | 
 | 103 | 	hda_nid_t cur_adc; | 
 | 104 | 	unsigned int cur_adc_stream_tag; | 
 | 105 | 	unsigned int cur_adc_format; | 
 | 106 |  | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 107 | 	const struct hda_pcm_stream *capture_stream; | 
 | 108 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 109 | 	/* capture source */ | 
 | 110 | 	const struct hda_input_mux *input_mux; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 111 | 	const hda_nid_t *capsrc_nids; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 112 | 	unsigned int cur_mux[3]; | 
 | 113 |  | 
 | 114 | 	/* channel model */ | 
 | 115 | 	const struct hda_channel_mode *channel_mode; | 
 | 116 | 	int num_channel_mode; | 
 | 117 |  | 
 | 118 | 	/* PCM information */ | 
 | 119 | 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */ | 
 | 120 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 121 | 	unsigned int spdif_route; | 
 | 122 |  | 
 | 123 | 	/* dynamic controls, init_verbs and input_mux */ | 
 | 124 | 	struct auto_pin_cfg autocfg; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 125 | 	struct hda_input_mux private_imux; | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 126 | 	struct imux_info imux_info[HDA_MAX_NUM_INPUTS]; | 
| Takashi Iwai | 22ce5f7 | 2011-05-15 12:19:29 +0200 | [diff] [blame] | 127 | 	hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; | 
| Takashi Iwai | 41923e4 | 2007-10-22 17:20:10 +0200 | [diff] [blame] | 128 | 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 129 | 	struct pin_dac_pair dac_info[8]; | 
 | 130 | 	int dac_info_filled; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 131 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 132 | 	unsigned int port_d_mode; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 133 | 	unsigned int auto_mute:1;	/* used in auto-parser */ | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 134 | 	unsigned int detect_line:1;	/* Line-out detection enabled */ | 
 | 135 | 	unsigned int automute_lines:1;	/* automute line-out as well */ | 
 | 136 | 	unsigned int automute_hp_lo:1;	/* both HP and LO available */ | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 137 | 	unsigned int dell_automute:1; | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 138 | 	unsigned int dell_vostro:1; | 
 | 139 | 	unsigned int ideapad:1; | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 140 | 	unsigned int thinkpad:1; | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 141 | 	unsigned int hp_laptop:1; | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 142 | 	unsigned int asus:1; | 
| Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 143 | 	unsigned int pin_eapd_ctrls:1; | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 144 | 	unsigned int fixup_stereo_dmic:1; | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 145 |  | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 146 | 	unsigned int adc_switching:1; | 
 | 147 |  | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 148 | 	unsigned int ext_mic_present; | 
 | 149 | 	unsigned int recording; | 
 | 150 | 	void (*capture_prepare)(struct hda_codec *codec); | 
 | 151 | 	void (*capture_cleanup)(struct hda_codec *codec); | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 152 |  | 
 | 153 | 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) | 
 | 154 | 	 * through the microphone jack. | 
 | 155 | 	 * When the user enables this through a mixer switch, both internal and | 
 | 156 | 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode, | 
 | 157 | 	 * we also allow the bias to be configured through a separate mixer | 
 | 158 | 	 * control. */ | 
 | 159 | 	unsigned int dc_enable; | 
 | 160 | 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ | 
 | 161 | 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 162 |  | 
 | 163 | 	unsigned int beep_amp; | 
| Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 164 |  | 
 | 165 | 	/* extra EAPD pins */ | 
 | 166 | 	unsigned int num_eapds; | 
 | 167 | 	hda_nid_t eapds[4]; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 168 | }; | 
 | 169 |  | 
 | 170 | static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, | 
 | 171 | 				      struct hda_codec *codec, | 
 | 172 | 				      struct snd_pcm_substream *substream) | 
 | 173 | { | 
 | 174 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 175 | 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | 
 | 176 | 					     hinfo); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 177 | } | 
 | 178 |  | 
 | 179 | static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | 
 | 180 | 					 struct hda_codec *codec, | 
 | 181 | 					 unsigned int stream_tag, | 
 | 182 | 					 unsigned int format, | 
 | 183 | 					 struct snd_pcm_substream *substream) | 
 | 184 | { | 
 | 185 | 	struct conexant_spec *spec = codec->spec; | 
 | 186 | 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | 
 | 187 | 						stream_tag, | 
 | 188 | 						format, substream); | 
 | 189 | } | 
 | 190 |  | 
 | 191 | static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | 
 | 192 | 					 struct hda_codec *codec, | 
 | 193 | 					 struct snd_pcm_substream *substream) | 
 | 194 | { | 
 | 195 | 	struct conexant_spec *spec = codec->spec; | 
 | 196 | 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | 
 | 197 | } | 
 | 198 |  | 
 | 199 | /* | 
 | 200 |  * Digital out | 
 | 201 |  */ | 
 | 202 | static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | 
 | 203 | 					  struct hda_codec *codec, | 
 | 204 | 					  struct snd_pcm_substream *substream) | 
 | 205 | { | 
 | 206 | 	struct conexant_spec *spec = codec->spec; | 
 | 207 | 	return snd_hda_multi_out_dig_open(codec, &spec->multiout); | 
 | 208 | } | 
 | 209 |  | 
 | 210 | static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | 
 | 211 | 					 struct hda_codec *codec, | 
 | 212 | 					 struct snd_pcm_substream *substream) | 
 | 213 | { | 
 | 214 | 	struct conexant_spec *spec = codec->spec; | 
 | 215 | 	return snd_hda_multi_out_dig_close(codec, &spec->multiout); | 
 | 216 | } | 
 | 217 |  | 
| Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 218 | static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | 
 | 219 | 					 struct hda_codec *codec, | 
 | 220 | 					 unsigned int stream_tag, | 
 | 221 | 					 unsigned int format, | 
 | 222 | 					 struct snd_pcm_substream *substream) | 
 | 223 | { | 
 | 224 | 	struct conexant_spec *spec = codec->spec; | 
 | 225 | 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, | 
 | 226 | 					     stream_tag, | 
 | 227 | 					     format, substream); | 
 | 228 | } | 
 | 229 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 230 | /* | 
 | 231 |  * Analog capture | 
 | 232 |  */ | 
 | 233 | static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | 
 | 234 | 				      struct hda_codec *codec, | 
 | 235 | 				      unsigned int stream_tag, | 
 | 236 | 				      unsigned int format, | 
 | 237 | 				      struct snd_pcm_substream *substream) | 
 | 238 | { | 
 | 239 | 	struct conexant_spec *spec = codec->spec; | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 240 | 	if (spec->capture_prepare) | 
 | 241 | 		spec->capture_prepare(codec); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 242 | 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | 
 | 243 | 				   stream_tag, 0, format); | 
 | 244 | 	return 0; | 
 | 245 | } | 
 | 246 |  | 
 | 247 | static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | 
 | 248 | 				      struct hda_codec *codec, | 
 | 249 | 				      struct snd_pcm_substream *substream) | 
 | 250 | { | 
 | 251 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 252 | 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 253 | 	if (spec->capture_cleanup) | 
 | 254 | 		spec->capture_cleanup(codec); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 255 | 	return 0; | 
 | 256 | } | 
 | 257 |  | 
 | 258 |  | 
 | 259 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 260 | static const struct hda_pcm_stream conexant_pcm_analog_playback = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 261 | 	.substreams = 1, | 
 | 262 | 	.channels_min = 2, | 
 | 263 | 	.channels_max = 2, | 
 | 264 | 	.nid = 0, /* fill later */ | 
 | 265 | 	.ops = { | 
 | 266 | 		.open = conexant_playback_pcm_open, | 
 | 267 | 		.prepare = conexant_playback_pcm_prepare, | 
 | 268 | 		.cleanup = conexant_playback_pcm_cleanup | 
 | 269 | 	}, | 
 | 270 | }; | 
 | 271 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 272 | static const struct hda_pcm_stream conexant_pcm_analog_capture = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 273 | 	.substreams = 1, | 
 | 274 | 	.channels_min = 2, | 
 | 275 | 	.channels_max = 2, | 
 | 276 | 	.nid = 0, /* fill later */ | 
 | 277 | 	.ops = { | 
 | 278 | 		.prepare = conexant_capture_pcm_prepare, | 
 | 279 | 		.cleanup = conexant_capture_pcm_cleanup | 
 | 280 | 	}, | 
 | 281 | }; | 
 | 282 |  | 
 | 283 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 284 | static const struct hda_pcm_stream conexant_pcm_digital_playback = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 285 | 	.substreams = 1, | 
 | 286 | 	.channels_min = 2, | 
 | 287 | 	.channels_max = 2, | 
 | 288 | 	.nid = 0, /* fill later */ | 
 | 289 | 	.ops = { | 
 | 290 | 		.open = conexant_dig_playback_pcm_open, | 
| Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 291 | 		.close = conexant_dig_playback_pcm_close, | 
 | 292 | 		.prepare = conexant_dig_playback_pcm_prepare | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 293 | 	}, | 
 | 294 | }; | 
 | 295 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 296 | static const struct hda_pcm_stream conexant_pcm_digital_capture = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 297 | 	.substreams = 1, | 
 | 298 | 	.channels_min = 2, | 
 | 299 | 	.channels_max = 2, | 
 | 300 | 	/* NID is set in alc_build_pcms */ | 
 | 301 | }; | 
 | 302 |  | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 303 | static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | 
 | 304 | 				      struct hda_codec *codec, | 
 | 305 | 				      unsigned int stream_tag, | 
 | 306 | 				      unsigned int format, | 
 | 307 | 				      struct snd_pcm_substream *substream) | 
 | 308 | { | 
 | 309 | 	struct conexant_spec *spec = codec->spec; | 
 | 310 | 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; | 
 | 311 | 	spec->cur_adc_stream_tag = stream_tag; | 
 | 312 | 	spec->cur_adc_format = format; | 
 | 313 | 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | 
 | 314 | 	return 0; | 
 | 315 | } | 
 | 316 |  | 
 | 317 | static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | 
 | 318 | 				      struct hda_codec *codec, | 
 | 319 | 				      struct snd_pcm_substream *substream) | 
 | 320 | { | 
 | 321 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 322 | 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc); | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 323 | 	spec->cur_adc = 0; | 
 | 324 | 	return 0; | 
 | 325 | } | 
 | 326 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 327 | static const struct hda_pcm_stream cx5051_pcm_analog_capture = { | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 328 | 	.substreams = 1, | 
 | 329 | 	.channels_min = 2, | 
 | 330 | 	.channels_max = 2, | 
 | 331 | 	.nid = 0, /* fill later */ | 
 | 332 | 	.ops = { | 
 | 333 | 		.prepare = cx5051_capture_pcm_prepare, | 
 | 334 | 		.cleanup = cx5051_capture_pcm_cleanup | 
 | 335 | 	}, | 
 | 336 | }; | 
 | 337 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 338 | static int conexant_build_pcms(struct hda_codec *codec) | 
 | 339 | { | 
 | 340 | 	struct conexant_spec *spec = codec->spec; | 
 | 341 | 	struct hda_pcm *info = spec->pcm_rec; | 
 | 342 |  | 
 | 343 | 	codec->num_pcms = 1; | 
 | 344 | 	codec->pcm_info = info; | 
 | 345 |  | 
 | 346 | 	info->name = "CONEXANT Analog"; | 
 | 347 | 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; | 
 | 348 | 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | 
 | 349 | 		spec->multiout.max_channels; | 
 | 350 | 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | 
 | 351 | 		spec->multiout.dac_nids[0]; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 352 | 	if (spec->capture_stream) | 
 | 353 | 		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; | 
 | 354 | 	else { | 
 | 355 | 		if (codec->vendor_id == 0x14f15051) | 
 | 356 | 			info->stream[SNDRV_PCM_STREAM_CAPTURE] = | 
 | 357 | 				cx5051_pcm_analog_capture; | 
 | 358 | 		else { | 
 | 359 | 			info->stream[SNDRV_PCM_STREAM_CAPTURE] = | 
 | 360 | 				conexant_pcm_analog_capture; | 
 | 361 | 			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | 
 | 362 | 				spec->num_adc_nids; | 
 | 363 | 		} | 
 | 364 | 	} | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 365 | 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | 
 | 366 |  | 
 | 367 | 	if (spec->multiout.dig_out_nid) { | 
 | 368 | 		info++; | 
 | 369 | 		codec->num_pcms++; | 
 | 370 | 		info->name = "Conexant Digital"; | 
| Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 371 | 		info->pcm_type = HDA_PCM_TYPE_SPDIF; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 372 | 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | 
 | 373 | 			conexant_pcm_digital_playback; | 
 | 374 | 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | 
 | 375 | 			spec->multiout.dig_out_nid; | 
 | 376 | 		if (spec->dig_in_nid) { | 
 | 377 | 			info->stream[SNDRV_PCM_STREAM_CAPTURE] = | 
 | 378 | 				conexant_pcm_digital_capture; | 
 | 379 | 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | 
 | 380 | 				spec->dig_in_nid; | 
 | 381 | 		} | 
| Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 382 | 		if (spec->slave_dig_outs[0]) | 
 | 383 | 			codec->slave_dig_outs = spec->slave_dig_outs; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 384 | 	} | 
 | 385 |  | 
 | 386 | 	return 0; | 
 | 387 | } | 
 | 388 |  | 
 | 389 | static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, | 
 | 390 | 	       			  struct snd_ctl_elem_info *uinfo) | 
 | 391 | { | 
 | 392 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 393 | 	struct conexant_spec *spec = codec->spec; | 
 | 394 |  | 
 | 395 | 	return snd_hda_input_mux_info(spec->input_mux, uinfo); | 
 | 396 | } | 
 | 397 |  | 
 | 398 | static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, | 
 | 399 | 				 struct snd_ctl_elem_value *ucontrol) | 
 | 400 | { | 
 | 401 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 402 | 	struct conexant_spec *spec = codec->spec; | 
 | 403 | 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | 
 | 404 |  | 
 | 405 | 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | 
 | 406 | 	return 0; | 
 | 407 | } | 
 | 408 |  | 
 | 409 | static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, | 
 | 410 | 				 struct snd_ctl_elem_value *ucontrol) | 
 | 411 | { | 
 | 412 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 413 | 	struct conexant_spec *spec = codec->spec; | 
 | 414 | 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | 
 | 415 |  | 
 | 416 | 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | 
 | 417 | 				     spec->capsrc_nids[adc_idx], | 
 | 418 | 				     &spec->cur_mux[adc_idx]); | 
 | 419 | } | 
 | 420 |  | 
| Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 421 | static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, | 
 | 422 | 			       unsigned int power_state) | 
 | 423 | { | 
 | 424 | 	if (power_state == AC_PWRST_D3) | 
 | 425 | 		msleep(100); | 
 | 426 | 	snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, | 
 | 427 | 			    power_state); | 
 | 428 | 	/* partial workaround for "azx_get_response timeout" */ | 
 | 429 | 	if (power_state == AC_PWRST_D0) | 
 | 430 | 		msleep(10); | 
 | 431 | 	snd_hda_codec_set_power_to_all(codec, fg, power_state, true); | 
 | 432 | } | 
 | 433 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 434 | static int conexant_init(struct hda_codec *codec) | 
 | 435 | { | 
 | 436 | 	struct conexant_spec *spec = codec->spec; | 
 | 437 | 	int i; | 
 | 438 |  | 
 | 439 | 	for (i = 0; i < spec->num_init_verbs; i++) | 
 | 440 | 		snd_hda_sequence_write(codec, spec->init_verbs[i]); | 
 | 441 | 	return 0; | 
 | 442 | } | 
 | 443 |  | 
 | 444 | static void conexant_free(struct hda_codec *codec) | 
 | 445 | { | 
| Einar Rünkaru | c0f8faf | 2009-12-16 22:41:36 +0200 | [diff] [blame] | 446 | 	snd_hda_detach_beep_device(codec); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 447 | 	kfree(codec->spec); | 
 | 448 | } | 
 | 449 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 450 | static const struct snd_kcontrol_new cxt_capture_mixers[] = { | 
| Takashi Iwai | b880c74 | 2009-03-10 14:41:05 +0100 | [diff] [blame] | 451 | 	{ | 
 | 452 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 453 | 		.name = "Capture Source", | 
 | 454 | 		.info = conexant_mux_enum_info, | 
 | 455 | 		.get = conexant_mux_enum_get, | 
 | 456 | 		.put = conexant_mux_enum_put | 
 | 457 | 	}, | 
 | 458 | 	{} | 
 | 459 | }; | 
 | 460 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 461 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | 
 | 462 | /* additional beep mixers; the actual parameters are overwritten at build */ | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 463 | static const struct snd_kcontrol_new cxt_beep_mixer[] = { | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 464 | 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), | 
 | 465 | 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), | 
 | 466 | 	{ } /* end */ | 
 | 467 | }; | 
 | 468 | #endif | 
 | 469 |  | 
| Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 470 | static const char * const slave_pfxs[] = { | 
 | 471 | 	"Headphone", "Speaker", "Front", "Surround", "CLFE", | 
| Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 472 | 	NULL | 
 | 473 | }; | 
 | 474 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 475 | static int conexant_build_controls(struct hda_codec *codec) | 
 | 476 | { | 
 | 477 | 	struct conexant_spec *spec = codec->spec; | 
 | 478 | 	unsigned int i; | 
 | 479 | 	int err; | 
 | 480 |  | 
 | 481 | 	for (i = 0; i < spec->num_mixers; i++) { | 
 | 482 | 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | 
 | 483 | 		if (err < 0) | 
 | 484 | 			return err; | 
 | 485 | 	} | 
 | 486 | 	if (spec->multiout.dig_out_nid) { | 
 | 487 | 		err = snd_hda_create_spdif_out_ctls(codec, | 
| Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 488 | 						    spec->multiout.dig_out_nid, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 489 | 						    spec->multiout.dig_out_nid); | 
 | 490 | 		if (err < 0) | 
 | 491 | 			return err; | 
| Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 492 | 		err = snd_hda_create_spdif_share_sw(codec, | 
 | 493 | 						    &spec->multiout); | 
 | 494 | 		if (err < 0) | 
 | 495 | 			return err; | 
 | 496 | 		spec->multiout.share_spdif = 1; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 497 | 	}  | 
 | 498 | 	if (spec->dig_in_nid) { | 
 | 499 | 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); | 
 | 500 | 		if (err < 0) | 
 | 501 | 			return err; | 
 | 502 | 	} | 
| Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 503 |  | 
 | 504 | 	/* if we have no master control, let's create it */ | 
 | 505 | 	if (spec->vmaster_nid && | 
 | 506 | 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { | 
 | 507 | 		unsigned int vmaster_tlv[4]; | 
 | 508 | 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, | 
 | 509 | 					HDA_OUTPUT, vmaster_tlv); | 
 | 510 | 		err = snd_hda_add_vmaster(codec, "Master Playback Volume", | 
| Takashi Iwai | 9322ca5 | 2012-02-03 14:28:01 +0100 | [diff] [blame] | 511 | 					  vmaster_tlv, slave_pfxs, | 
 | 512 | 					  "Playback Volume"); | 
| Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 513 | 		if (err < 0) | 
 | 514 | 			return err; | 
 | 515 | 	} | 
 | 516 | 	if (spec->vmaster_nid && | 
 | 517 | 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { | 
| Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 518 | 		err = __snd_hda_add_vmaster(codec, "Master Playback Switch", | 
 | 519 | 					    NULL, slave_pfxs, | 
 | 520 | 					    "Playback Switch", true, | 
| Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 521 | 					    &spec->vmaster_mute.sw_kctl); | 
| Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 522 | 		if (err < 0) | 
 | 523 | 			return err; | 
 | 524 | 	} | 
 | 525 |  | 
| Takashi Iwai | b880c74 | 2009-03-10 14:41:05 +0100 | [diff] [blame] | 526 | 	if (spec->input_mux) { | 
 | 527 | 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); | 
 | 528 | 		if (err < 0) | 
 | 529 | 			return err; | 
 | 530 | 	} | 
 | 531 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 532 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | 
 | 533 | 	/* create beep controls if needed */ | 
 | 534 | 	if (spec->beep_amp) { | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 535 | 		const struct snd_kcontrol_new *knew; | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 536 | 		for (knew = cxt_beep_mixer; knew->name; knew++) { | 
 | 537 | 			struct snd_kcontrol *kctl; | 
 | 538 | 			kctl = snd_ctl_new1(knew, codec); | 
 | 539 | 			if (!kctl) | 
 | 540 | 				return -ENOMEM; | 
 | 541 | 			kctl->private_value = spec->beep_amp; | 
 | 542 | 			err = snd_hda_ctl_add(codec, 0, kctl); | 
 | 543 | 			if (err < 0) | 
 | 544 | 				return err; | 
 | 545 | 		} | 
 | 546 | 	} | 
 | 547 | #endif | 
 | 548 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 549 | 	return 0; | 
 | 550 | } | 
 | 551 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 552 | static const struct hda_codec_ops conexant_patch_ops = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 553 | 	.build_controls = conexant_build_controls, | 
 | 554 | 	.build_pcms = conexant_build_pcms, | 
 | 555 | 	.init = conexant_init, | 
 | 556 | 	.free = conexant_free, | 
| Takashi Iwai | 4d7fbdb | 2011-07-26 10:33:10 +0200 | [diff] [blame] | 557 | 	.set_power_state = conexant_set_power, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 558 | }; | 
 | 559 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 560 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | 
 | 561 | #define set_beep_amp(spec, nid, idx, dir) \ | 
 | 562 | 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) | 
 | 563 | #else | 
 | 564 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ | 
 | 565 | #endif | 
 | 566 |  | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 567 | static int patch_conexant_auto(struct hda_codec *codec); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 568 | /* | 
 | 569 |  * EAPD control | 
 | 570 |  * the private value = nid | (invert << 8) | 
 | 571 |  */ | 
 | 572 |  | 
| Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 573 | #define cxt_eapd_info		snd_ctl_boolean_mono_info | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 574 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 575 | static int cxt_eapd_get(struct snd_kcontrol *kcontrol, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 576 | 			     struct snd_ctl_elem_value *ucontrol) | 
 | 577 | { | 
 | 578 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 579 | 	struct conexant_spec *spec = codec->spec; | 
 | 580 | 	int invert = (kcontrol->private_value >> 8) & 1; | 
 | 581 | 	if (invert) | 
 | 582 | 		ucontrol->value.integer.value[0] = !spec->cur_eapd; | 
 | 583 | 	else | 
 | 584 | 		ucontrol->value.integer.value[0] = spec->cur_eapd; | 
 | 585 | 	return 0; | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 586 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 587 | } | 
 | 588 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 589 | static int cxt_eapd_put(struct snd_kcontrol *kcontrol, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 590 | 			     struct snd_ctl_elem_value *ucontrol) | 
 | 591 | { | 
 | 592 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 593 | 	struct conexant_spec *spec = codec->spec; | 
 | 594 | 	int invert = (kcontrol->private_value >> 8) & 1; | 
 | 595 | 	hda_nid_t nid = kcontrol->private_value & 0xff; | 
 | 596 | 	unsigned int eapd; | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 597 |  | 
| Takashi Iwai | 68ea7b2 | 2007-11-15 15:54:38 +0100 | [diff] [blame] | 598 | 	eapd = !!ucontrol->value.integer.value[0]; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 599 | 	if (invert) | 
 | 600 | 		eapd = !eapd; | 
| Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 601 | 	if (eapd == spec->cur_eapd) | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 602 | 		return 0; | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 603 | 	 | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 604 | 	spec->cur_eapd = eapd; | 
| Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 605 | 	snd_hda_codec_write_cache(codec, nid, | 
 | 606 | 				  0, AC_VERB_SET_EAPD_BTLENABLE, | 
 | 607 | 				  eapd ? 0x02 : 0x00); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 608 | 	return 1; | 
 | 609 | } | 
 | 610 |  | 
| Takashi Iwai | 86d72bd | 2006-11-28 11:33:10 +0100 | [diff] [blame] | 611 | /* controls for test mode */ | 
 | 612 | #ifdef CONFIG_SND_DEBUG | 
 | 613 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 614 | #define CXT_EAPD_SWITCH(xname, nid, mask) \ | 
 | 615 | 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \ | 
 | 616 | 	  .info = cxt_eapd_info, \ | 
 | 617 | 	  .get = cxt_eapd_get, \ | 
 | 618 | 	  .put = cxt_eapd_put, \ | 
 | 619 | 	  .private_value = nid | (mask<<16) } | 
 | 620 |  | 
 | 621 |  | 
 | 622 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 623 | static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, | 
 | 624 | 				 struct snd_ctl_elem_info *uinfo) | 
 | 625 | { | 
 | 626 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 627 | 	struct conexant_spec *spec = codec->spec; | 
 | 628 | 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, | 
 | 629 | 				    spec->num_channel_mode); | 
 | 630 | } | 
 | 631 |  | 
 | 632 | static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, | 
 | 633 | 				struct snd_ctl_elem_value *ucontrol) | 
 | 634 | { | 
 | 635 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 636 | 	struct conexant_spec *spec = codec->spec; | 
 | 637 | 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, | 
 | 638 | 				   spec->num_channel_mode, | 
 | 639 | 				   spec->multiout.max_channels); | 
 | 640 | } | 
 | 641 |  | 
 | 642 | static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, | 
 | 643 | 				struct snd_ctl_elem_value *ucontrol) | 
 | 644 | { | 
 | 645 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 646 | 	struct conexant_spec *spec = codec->spec; | 
 | 647 | 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, | 
 | 648 | 				      spec->num_channel_mode, | 
 | 649 | 				      &spec->multiout.max_channels); | 
 | 650 | 	if (err >= 0 && spec->need_dac_fix) | 
 | 651 | 		spec->multiout.num_dacs = spec->multiout.max_channels / 2; | 
 | 652 | 	return err; | 
 | 653 | } | 
 | 654 |  | 
 | 655 | #define CXT_PIN_MODE(xname, nid, dir) \ | 
 | 656 | 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \ | 
 | 657 | 	  .info = conexant_ch_mode_info, \ | 
 | 658 | 	  .get = conexant_ch_mode_get, \ | 
 | 659 | 	  .put = conexant_ch_mode_put, \ | 
 | 660 | 	  .private_value = nid | (dir<<16) } | 
 | 661 |  | 
| Takashi Iwai | 86d72bd | 2006-11-28 11:33:10 +0100 | [diff] [blame] | 662 | #endif /* CONFIG_SND_DEBUG */ | 
 | 663 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 664 | /* Conexant 5045 specific */ | 
 | 665 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 666 | static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; | 
 | 667 | static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; | 
 | 668 | static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; | 
| Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 669 | #define CXT5045_SPDIF_OUT	0x18 | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 670 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 671 | static const struct hda_channel_mode cxt5045_modes[1] = { | 
| Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 672 | 	{ 2, NULL }, | 
 | 673 | }; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 674 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 675 | static const struct hda_input_mux cxt5045_capture_source = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 676 | 	.num_items = 2, | 
 | 677 | 	.items = { | 
| Michael Karcher | 3edbbb9 | 2012-04-06 15:34:16 +0200 | [diff] [blame] | 678 | 		{ "Internal Mic", 0x1 }, | 
 | 679 | 		{ "Mic",          0x2 }, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 680 | 	} | 
 | 681 | }; | 
 | 682 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 683 | static const struct hda_input_mux cxt5045_capture_source_benq = { | 
| Michael Karcher | e6e03da | 2012-04-06 15:34:18 +0200 | [diff] [blame] | 684 | 	.num_items = 4, | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 685 | 	.items = { | 
| Michael Karcher | 3edbbb9 | 2012-04-06 15:34:16 +0200 | [diff] [blame] | 686 | 		{ "Internal Mic", 0x1 }, | 
 | 687 | 		{ "Mic",          0x2 }, | 
 | 688 | 		{ "Line",         0x3 }, | 
 | 689 | 		{ "Mixer",        0x0 }, | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 690 | 	} | 
 | 691 | }; | 
 | 692 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 693 | static const struct hda_input_mux cxt5045_capture_source_hp530 = { | 
| Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 694 | 	.num_items = 2, | 
 | 695 | 	.items = { | 
| Michael Karcher | 3edbbb9 | 2012-04-06 15:34:16 +0200 | [diff] [blame] | 696 | 		{ "Mic",          0x1 }, | 
 | 697 | 		{ "Internal Mic", 0x2 }, | 
| Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 698 | 	} | 
 | 699 | }; | 
 | 700 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 701 | /* turn on/off EAPD (+ mute HP) as a master switch */ | 
 | 702 | static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, | 
 | 703 | 				    struct snd_ctl_elem_value *ucontrol) | 
 | 704 | { | 
 | 705 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 706 | 	struct conexant_spec *spec = codec->spec; | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 707 | 	unsigned int bits; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 708 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 709 | 	if (!cxt_eapd_put(kcontrol, ucontrol)) | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 710 | 		return 0; | 
 | 711 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 712 | 	/* toggle internal speakers mute depending of presence of | 
 | 713 | 	 * the headphone jack | 
 | 714 | 	 */ | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 715 | 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; | 
 | 716 | 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, | 
 | 717 | 				 HDA_AMP_MUTE, bits); | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 718 |  | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 719 | 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; | 
 | 720 | 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, | 
 | 721 | 				 HDA_AMP_MUTE, bits); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 722 | 	return 1; | 
 | 723 | } | 
 | 724 |  | 
 | 725 | /* bind volumes of both NID 0x10 and 0x11 */ | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 726 | static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { | 
| Takashi Iwai | cca3b37 | 2007-08-10 17:12:15 +0200 | [diff] [blame] | 727 | 	.ops = &snd_hda_bind_vol, | 
 | 728 | 	.values = { | 
 | 729 | 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), | 
 | 730 | 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), | 
 | 731 | 		0 | 
 | 732 | 	}, | 
 | 733 | }; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 734 |  | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 735 | /* toggle input of built-in and mic jack appropriately */ | 
 | 736 | static void cxt5045_hp_automic(struct hda_codec *codec) | 
 | 737 | { | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 738 | 	static const struct hda_verb mic_jack_on[] = { | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 739 | 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | 
 | 740 | 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | 
 | 741 | 		{} | 
 | 742 | 	}; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 743 | 	static const struct hda_verb mic_jack_off[] = { | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 744 | 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | 
 | 745 | 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | 
 | 746 | 		{} | 
 | 747 | 	}; | 
 | 748 | 	unsigned int present; | 
 | 749 |  | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 750 | 	present = snd_hda_jack_detect(codec, 0x12); | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 751 | 	if (present) | 
 | 752 | 		snd_hda_sequence_write(codec, mic_jack_on); | 
 | 753 | 	else | 
 | 754 | 		snd_hda_sequence_write(codec, mic_jack_off); | 
 | 755 | } | 
 | 756 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 757 |  | 
 | 758 | /* mute internal speaker if HP is plugged */ | 
 | 759 | static void cxt5045_hp_automute(struct hda_codec *codec) | 
 | 760 | { | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 761 | 	struct conexant_spec *spec = codec->spec; | 
| Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 762 | 	unsigned int bits; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 763 |  | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 764 | 	spec->hp_present = snd_hda_jack_detect(codec, 0x11); | 
| Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 765 |  | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 766 | 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;  | 
 | 767 | 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, | 
 | 768 | 				 HDA_AMP_MUTE, bits); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 769 | } | 
 | 770 |  | 
 | 771 | /* unsolicited event for HP jack sensing */ | 
 | 772 | static void cxt5045_hp_unsol_event(struct hda_codec *codec, | 
 | 773 | 				   unsigned int res) | 
 | 774 | { | 
 | 775 | 	res >>= 26; | 
 | 776 | 	switch (res) { | 
 | 777 | 	case CONEXANT_HP_EVENT: | 
 | 778 | 		cxt5045_hp_automute(codec); | 
 | 779 | 		break; | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 780 | 	case CONEXANT_MIC_EVENT: | 
 | 781 | 		cxt5045_hp_automic(codec); | 
 | 782 | 		break; | 
 | 783 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 784 | 	} | 
 | 785 | } | 
 | 786 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 787 | static const struct snd_kcontrol_new cxt5045_mixers[] = { | 
| Michael Karcher | cbf2d28 | 2012-04-06 15:34:17 +0200 | [diff] [blame] | 788 | 	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), | 
 | 789 | 	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), | 
| Takashi Iwai | c8229c3 | 2007-10-19 08:06:21 +0200 | [diff] [blame] | 790 | 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), | 
 | 791 | 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 792 | 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), | 
 | 793 | 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), | 
| David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 794 | 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), | 
 | 795 | 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), | 
| Takashi Iwai | cca3b37 | 2007-08-10 17:12:15 +0200 | [diff] [blame] | 796 | 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 797 | 	{ | 
 | 798 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 799 | 		.name = "Master Playback Switch", | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 800 | 		.info = cxt_eapd_info, | 
 | 801 | 		.get = cxt_eapd_get, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 802 | 		.put = cxt5045_hp_master_sw_put, | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 803 | 		.private_value = 0x10, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 804 | 	}, | 
 | 805 |  | 
 | 806 | 	{} | 
 | 807 | }; | 
 | 808 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 809 | static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { | 
| Michael Karcher | 3edbbb9 | 2012-04-06 15:34:16 +0200 | [diff] [blame] | 810 | 	HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT), | 
 | 811 | 	HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT), | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 812 |  | 
 | 813 | 	{} | 
 | 814 | }; | 
 | 815 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 816 | static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { | 
| Michael Karcher | cbf2d28 | 2012-04-06 15:34:17 +0200 | [diff] [blame] | 817 | 	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), | 
 | 818 | 	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), | 
| Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 819 | 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), | 
 | 820 | 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 821 | 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), | 
 | 822 | 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), | 
| David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 823 | 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), | 
 | 824 | 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), | 
| Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 825 | 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), | 
 | 826 | 	{ | 
 | 827 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 828 | 		.name = "Master Playback Switch", | 
 | 829 | 		.info = cxt_eapd_info, | 
 | 830 | 		.get = cxt_eapd_get, | 
 | 831 | 		.put = cxt5045_hp_master_sw_put, | 
 | 832 | 		.private_value = 0x10, | 
 | 833 | 	}, | 
 | 834 |  | 
 | 835 | 	{} | 
 | 836 | }; | 
 | 837 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 838 | static const struct hda_verb cxt5045_init_verbs[] = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 839 | 	/* Line in, Mic */ | 
| Takashi Iwai | 4090dff | 2008-07-12 12:02:45 +0200 | [diff] [blame] | 840 | 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 841 | 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 842 | 	/* HP, Amp  */ | 
| Takashi Iwai | c8229c3 | 2007-10-19 08:06:21 +0200 | [diff] [blame] | 843 | 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 844 | 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, | 
 | 845 | 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 846 | 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, | 
 | 847 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 848 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 849 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | 
 | 850 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 851 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 852 | 	/* Record selector: Internal mic */ | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 853 | 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 854 | 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 855 | 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | 
 | 856 | 	/* SPDIF route: PCM */ | 
| Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 857 | 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 858 | 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 859 | 	/* EAPD */ | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 860 | 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 861 | 	{ } /* end */ | 
 | 862 | }; | 
 | 863 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 864 | static const struct hda_verb cxt5045_benq_init_verbs[] = { | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 865 | 	/* Internal Mic, Mic */ | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 866 | 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, | 
 | 867 | 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, | 
 | 868 | 	/* Line In,HP, Amp  */ | 
 | 869 | 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 870 | 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, | 
 | 871 | 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | 
 | 872 | 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, | 
 | 873 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 874 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 875 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | 
 | 876 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 877 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 878 | 	/* Record selector: Internal mic */ | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 879 | 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, | 
 | 880 | 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, | 
 | 881 | 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | 
 | 882 | 	/* SPDIF route: PCM */ | 
| Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 883 | 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 884 | 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 885 | 	/* EAPD */ | 
 | 886 | 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | 
 | 887 | 	{ } /* end */ | 
 | 888 | }; | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 889 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 890 | static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 891 | 	/* pin sensing on HP jack */ | 
 | 892 | 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | 
| Takashi Iwai | d3091fa | 2007-03-28 15:11:53 +0200 | [diff] [blame] | 893 | 	{ } /* end */ | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 894 | }; | 
 | 895 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 896 | static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 897 | 	/* pin sensing on HP jack */ | 
 | 898 | 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | 
| Takashi Iwai | d3091fa | 2007-03-28 15:11:53 +0200 | [diff] [blame] | 899 | 	{ } /* end */ | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 900 | }; | 
 | 901 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 902 | #ifdef CONFIG_SND_DEBUG | 
 | 903 | /* Test configuration for debugging, modelled after the ALC260 test | 
 | 904 |  * configuration. | 
 | 905 |  */ | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 906 | static const struct hda_input_mux cxt5045_test_capture_source = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 907 | 	.num_items = 5, | 
 | 908 | 	.items = { | 
 | 909 | 		{ "MIXER", 0x0 }, | 
 | 910 | 		{ "MIC1 pin", 0x1 }, | 
 | 911 | 		{ "LINE1 pin", 0x2 }, | 
 | 912 | 		{ "HP-OUT pin", 0x3 }, | 
 | 913 | 		{ "CD pin", 0x4 }, | 
 | 914 |         }, | 
 | 915 | }; | 
 | 916 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 917 | static const struct snd_kcontrol_new cxt5045_test_mixer[] = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 918 |  | 
 | 919 | 	/* Output controls */ | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 920 | 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), | 
 | 921 | 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), | 
| Michael Karcher | 250f327 | 2012-04-06 15:34:20 +0200 | [diff] [blame] | 922 | 	HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT), | 
 | 923 | 	HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT), | 
 | 924 | 	HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT), | 
 | 925 | 	HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 926 | 	 | 
 | 927 | 	/* Modes for retasking pin widgets */ | 
 | 928 | 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), | 
 | 929 | 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), | 
 | 930 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 931 | 	/* EAPD Switch Control */ | 
 | 932 | 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), | 
 | 933 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 934 | 	/* Loopback mixer controls */ | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 935 |  | 
| Michael Karcher | 250f327 | 2012-04-06 15:34:20 +0200 | [diff] [blame] | 936 | 	HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT), | 
 | 937 | 	HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT), | 
 | 938 | 	HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT), | 
 | 939 | 	HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT), | 
 | 940 | 	HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT), | 
 | 941 | 	HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT), | 
 | 942 | 	HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT), | 
 | 943 | 	HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT), | 
 | 944 | 	HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT), | 
 | 945 | 	HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 946 | 	{ | 
 | 947 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 948 | 		.name = "Input Source", | 
 | 949 | 		.info = conexant_mux_enum_info, | 
 | 950 | 		.get = conexant_mux_enum_get, | 
 | 951 | 		.put = conexant_mux_enum_put, | 
 | 952 | 	}, | 
| Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 953 | 	/* Audio input controls */ | 
| Michael Karcher | cbf2d28 | 2012-04-06 15:34:17 +0200 | [diff] [blame] | 954 | 	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT), | 
 | 955 | 	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 956 | 	{ } /* end */ | 
 | 957 | }; | 
 | 958 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 959 | static const struct hda_verb cxt5045_test_init_verbs[] = { | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 960 | 	/* Set connections */ | 
 | 961 | 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, | 
 | 962 | 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, | 
 | 963 | 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 964 | 	/* Enable retasking pins as output, initially without power amp */ | 
 | 965 | 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 966 | 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 967 |  | 
 | 968 | 	/* Disable digital (SPDIF) pins initially, but users can enable | 
 | 969 | 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb | 
 | 970 | 	 * payload also sets the generation to 0, output to be in "consumer" | 
 | 971 | 	 * PCM format, copyright asserted, no pre-emphasis and no validity | 
 | 972 | 	 * control. | 
 | 973 | 	 */ | 
| Takashi Iwai | cbef978 | 2008-02-22 18:36:46 +0100 | [diff] [blame] | 974 | 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 975 | 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 976 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 977 | 	/* Unmute retasking pin widget output buffers since the default | 
 | 978 | 	 * state appears to be output.  As the pin mode is changed by the | 
 | 979 | 	 * user the pin mode control will take care of enabling the pin's | 
 | 980 | 	 * input/output buffers as needed. | 
 | 981 | 	 */ | 
 | 982 | 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 983 | 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 984 |  | 
 | 985 | 	/* Mute capture amp left and right */ | 
 | 986 | 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 987 |  | 
 | 988 | 	/* Set ADC connection select to match default mixer setting (mic1 | 
 | 989 | 	 * pin) | 
 | 990 | 	 */ | 
| Michael Karcher | 250f327 | 2012-04-06 15:34:20 +0200 | [diff] [blame] | 991 | 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, | 
 | 992 | 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x01}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 993 |  | 
 | 994 | 	/* Mute all inputs to mixer widget (even unconnected ones) */ | 
| Michael Karcher | 250f327 | 2012-04-06 15:34:20 +0200 | [diff] [blame] | 995 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */ | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 996 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ | 
 | 997 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ | 
 | 998 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ | 
 | 999 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | 
 | 1000 |  | 
 | 1001 | 	{ } | 
 | 1002 | }; | 
 | 1003 | #endif | 
 | 1004 |  | 
 | 1005 |  | 
 | 1006 | /* initialize jack-sensing, too */ | 
 | 1007 | static int cxt5045_init(struct hda_codec *codec) | 
 | 1008 | { | 
 | 1009 | 	conexant_init(codec); | 
 | 1010 | 	cxt5045_hp_automute(codec); | 
 | 1011 | 	return 0; | 
 | 1012 | } | 
 | 1013 |  | 
 | 1014 |  | 
 | 1015 | enum { | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1016 | 	CXT5045_LAPTOP_HPSENSE, | 
 | 1017 | 	CXT5045_LAPTOP_MICSENSE, | 
 | 1018 | 	CXT5045_LAPTOP_HPMICSENSE, | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 1019 | 	CXT5045_BENQ, | 
| Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 1020 | 	CXT5045_LAPTOP_HP530, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1021 | #ifdef CONFIG_SND_DEBUG | 
 | 1022 | 	CXT5045_TEST, | 
 | 1023 | #endif | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1024 | 	CXT5045_AUTO, | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1025 | 	CXT5045_MODELS | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1026 | }; | 
 | 1027 |  | 
| Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1028 | static const char * const cxt5045_models[CXT5045_MODELS] = { | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1029 | 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense", | 
 | 1030 | 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense", | 
 | 1031 | 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense", | 
 | 1032 | 	[CXT5045_BENQ]			= "benq", | 
| Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 1033 | 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530", | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1034 | #ifdef CONFIG_SND_DEBUG | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1035 | 	[CXT5045_TEST]		= "test", | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1036 | #endif | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1037 | 	[CXT5045_AUTO]			= "auto", | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1038 | }; | 
 | 1039 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1040 | static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { | 
| Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 1041 | 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), | 
| Takashi Iwai | 6a9dccd | 2008-07-01 14:52:05 +0200 | [diff] [blame] | 1042 | 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 1043 | 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1044 | 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), | 
 | 1045 | 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), | 
| Takashi Iwai | 9e46415 | 2008-07-12 12:05:25 +0200 | [diff] [blame] | 1046 | 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", | 
 | 1047 | 		      CXT5045_LAPTOP_HPMICSENSE), | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1048 | 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), | 
 | 1049 | 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), | 
 | 1050 | 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), | 
| Takashi Iwai | dea0a50 | 2009-02-09 17:14:52 +0100 | [diff] [blame] | 1051 | 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", | 
 | 1052 | 			   CXT5045_LAPTOP_HPMICSENSE), | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1053 | 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1054 | 	{} | 
 | 1055 | }; | 
 | 1056 |  | 
 | 1057 | static int patch_cxt5045(struct hda_codec *codec) | 
 | 1058 | { | 
 | 1059 | 	struct conexant_spec *spec; | 
 | 1060 | 	int board_config; | 
 | 1061 |  | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1062 | 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, | 
 | 1063 | 						  cxt5045_models, | 
 | 1064 | 						  cxt5045_cfg_tbl); | 
 | 1065 | 	if (board_config < 0) | 
| Takashi Iwai | c82693d | 2011-06-28 14:17:17 +0200 | [diff] [blame] | 1066 | 		board_config = CXT5045_AUTO; /* model=auto as default */ | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1067 | 	if (board_config == CXT5045_AUTO) | 
 | 1068 | 		return patch_conexant_auto(codec); | 
 | 1069 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1070 | 	spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 
 | 1071 | 	if (!spec) | 
 | 1072 | 		return -ENOMEM; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1073 | 	codec->spec = spec; | 
| Michael Karcher | 4f32456 | 2012-04-06 15:34:15 +0200 | [diff] [blame] | 1074 | 	codec->single_adc_amp = 1; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1075 |  | 
 | 1076 | 	spec->multiout.max_channels = 2; | 
 | 1077 | 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); | 
 | 1078 | 	spec->multiout.dac_nids = cxt5045_dac_nids; | 
 | 1079 | 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; | 
 | 1080 | 	spec->num_adc_nids = 1; | 
 | 1081 | 	spec->adc_nids = cxt5045_adc_nids; | 
 | 1082 | 	spec->capsrc_nids = cxt5045_capsrc_nids; | 
 | 1083 | 	spec->input_mux = &cxt5045_capture_source; | 
 | 1084 | 	spec->num_mixers = 1; | 
 | 1085 | 	spec->mixers[0] = cxt5045_mixers; | 
 | 1086 | 	spec->num_init_verbs = 1; | 
 | 1087 | 	spec->init_verbs[0] = cxt5045_init_verbs; | 
 | 1088 | 	spec->spdif_route = 0; | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1089 | 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); | 
 | 1090 | 	spec->channel_mode = cxt5045_modes; | 
| Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 1091 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1092 | 	set_beep_amp(spec, 0x16, 0, 1); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1093 |  | 
 | 1094 | 	codec->patch_ops = conexant_patch_ops; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1095 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1096 | 	switch (board_config) { | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1097 | 	case CXT5045_LAPTOP_HPSENSE: | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1098 | 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1099 | 		spec->input_mux = &cxt5045_capture_source; | 
 | 1100 | 		spec->num_init_verbs = 2; | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1101 | 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | 
 | 1102 | 		spec->mixers[0] = cxt5045_mixers; | 
 | 1103 | 		codec->patch_ops.init = cxt5045_init; | 
 | 1104 | 		break; | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1105 | 	case CXT5045_LAPTOP_MICSENSE: | 
| Takashi Iwai | 86376df | 2008-07-12 12:04:05 +0200 | [diff] [blame] | 1106 | 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1107 | 		spec->input_mux = &cxt5045_capture_source; | 
 | 1108 | 		spec->num_init_verbs = 2; | 
 | 1109 | 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1110 | 		spec->mixers[0] = cxt5045_mixers; | 
 | 1111 | 		codec->patch_ops.init = cxt5045_init; | 
 | 1112 | 		break; | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1113 | 	default: | 
 | 1114 | 	case CXT5045_LAPTOP_HPMICSENSE: | 
 | 1115 | 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | 
 | 1116 | 		spec->input_mux = &cxt5045_capture_source; | 
 | 1117 | 		spec->num_init_verbs = 3; | 
 | 1118 | 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | 
 | 1119 | 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; | 
 | 1120 | 		spec->mixers[0] = cxt5045_mixers; | 
 | 1121 | 		codec->patch_ops.init = cxt5045_init; | 
 | 1122 | 		break; | 
| Jiang Zhe | 5218c89 | 2008-01-17 11:18:41 +0100 | [diff] [blame] | 1123 | 	case CXT5045_BENQ: | 
 | 1124 | 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | 
 | 1125 | 		spec->input_mux = &cxt5045_capture_source_benq; | 
 | 1126 | 		spec->num_init_verbs = 1; | 
 | 1127 | 		spec->init_verbs[0] = cxt5045_benq_init_verbs; | 
 | 1128 | 		spec->mixers[0] = cxt5045_mixers; | 
 | 1129 | 		spec->mixers[1] = cxt5045_benq_mixers; | 
 | 1130 | 		spec->num_mixers = 2; | 
 | 1131 | 		codec->patch_ops.init = cxt5045_init; | 
 | 1132 | 		break; | 
| Jiang zhe | 2de3c23 | 2008-03-06 11:09:09 +0100 | [diff] [blame] | 1133 | 	case CXT5045_LAPTOP_HP530: | 
 | 1134 | 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | 
 | 1135 | 		spec->input_mux = &cxt5045_capture_source_hp530; | 
 | 1136 | 		spec->num_init_verbs = 2; | 
 | 1137 | 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | 
 | 1138 | 		spec->mixers[0] = cxt5045_mixers_hp530; | 
 | 1139 | 		codec->patch_ops.init = cxt5045_init; | 
 | 1140 | 		break; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1141 | #ifdef CONFIG_SND_DEBUG | 
 | 1142 | 	case CXT5045_TEST: | 
 | 1143 | 		spec->input_mux = &cxt5045_test_capture_source; | 
 | 1144 | 		spec->mixers[0] = cxt5045_test_mixer; | 
 | 1145 | 		spec->init_verbs[0] = cxt5045_test_init_verbs; | 
| Marc Boucher | 15908c3 | 2008-01-22 15:15:59 +0100 | [diff] [blame] | 1146 | 		break; | 
 | 1147 | 		 | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1148 | #endif	 | 
 | 1149 | 	} | 
| Takashi Iwai | 48ecb7e | 2007-12-17 14:32:49 +0100 | [diff] [blame] | 1150 |  | 
| Takashi Iwai | 031005f | 2008-06-26 14:49:58 +0200 | [diff] [blame] | 1151 | 	switch (codec->subsystem_id >> 16) { | 
 | 1152 | 	case 0x103c: | 
| Daniel T Chen | 8f0f5ff | 2010-04-28 18:00:11 -0400 | [diff] [blame] | 1153 | 	case 0x1631: | 
| Daniel T Chen | 0b587fc | 2009-11-25 18:27:20 -0500 | [diff] [blame] | 1154 | 	case 0x1734: | 
| Daniel T Chen | 0ebf9e3 | 2010-05-10 21:50:04 +0200 | [diff] [blame] | 1155 | 	case 0x17aa: | 
 | 1156 | 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have | 
 | 1157 | 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to | 
 | 1158 | 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) | 
| Takashi Iwai | 031005f | 2008-06-26 14:49:58 +0200 | [diff] [blame] | 1159 | 		 */ | 
 | 1160 | 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, | 
 | 1161 | 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) | | 
 | 1162 | 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | | 
 | 1163 | 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | | 
 | 1164 | 					  (1 << AC_AMPCAP_MUTE_SHIFT)); | 
 | 1165 | 		break; | 
 | 1166 | 	} | 
| Takashi Iwai | 48ecb7e | 2007-12-17 14:32:49 +0100 | [diff] [blame] | 1167 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1168 | 	if (spec->beep_amp) | 
| Takashi Iwai | 184e91c | 2013-03-18 11:00:44 +0100 | [diff] [blame] | 1169 | 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp)); | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1170 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1171 | 	return 0; | 
 | 1172 | } | 
 | 1173 |  | 
 | 1174 |  | 
 | 1175 | /* Conexant 5047 specific */ | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1176 | #define CXT5047_SPDIF_OUT	0x11 | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1177 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1178 | static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ | 
 | 1179 | static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; | 
 | 1180 | static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1181 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1182 | static const struct hda_channel_mode cxt5047_modes[1] = { | 
| Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 1183 | 	{ 2, NULL }, | 
 | 1184 | }; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1185 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1186 | static const struct hda_input_mux cxt5047_toshiba_capture_source = { | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1187 | 	.num_items = 2, | 
 | 1188 | 	.items = { | 
 | 1189 | 		{ "ExtMic", 0x2 }, | 
 | 1190 | 		{ "Line-In", 0x1 }, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1191 | 	} | 
 | 1192 | }; | 
 | 1193 |  | 
 | 1194 | /* turn on/off EAPD (+ mute HP) as a master switch */ | 
 | 1195 | static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, | 
 | 1196 | 				    struct snd_ctl_elem_value *ucontrol) | 
 | 1197 | { | 
 | 1198 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 1199 | 	struct conexant_spec *spec = codec->spec; | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1200 | 	unsigned int bits; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1201 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1202 | 	if (!cxt_eapd_put(kcontrol, ucontrol)) | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1203 | 		return 0; | 
 | 1204 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1205 | 	/* toggle internal speakers mute depending of presence of | 
 | 1206 | 	 * the headphone jack | 
 | 1207 | 	 */ | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1208 | 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; | 
| Takashi Iwai | 3b7523f | 2009-03-12 16:45:01 +0100 | [diff] [blame] | 1209 | 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of | 
 | 1210 | 	 * pin widgets unlike other codecs.  In this case, we need to | 
 | 1211 | 	 * set index 0x01 for the volume from the mixer amp 0x19. | 
 | 1212 | 	 */ | 
| Gregorio Guidi | 5d75bc5 | 2009-03-12 16:41:51 +0100 | [diff] [blame] | 1213 | 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1214 | 				 HDA_AMP_MUTE, bits); | 
 | 1215 | 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; | 
 | 1216 | 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, | 
 | 1217 | 				 HDA_AMP_MUTE, bits); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1218 | 	return 1; | 
 | 1219 | } | 
 | 1220 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1221 | /* mute internal speaker if HP is plugged */ | 
 | 1222 | static void cxt5047_hp_automute(struct hda_codec *codec) | 
 | 1223 | { | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1224 | 	struct conexant_spec *spec = codec->spec; | 
| Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 1225 | 	unsigned int bits; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1226 |  | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1227 | 	spec->hp_present = snd_hda_jack_detect(codec, 0x13); | 
| Tobin Davis | dd87da1 | 2007-02-26 16:07:42 +0100 | [diff] [blame] | 1228 |  | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1229 | 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; | 
| Takashi Iwai | 3b7523f | 2009-03-12 16:45:01 +0100 | [diff] [blame] | 1230 | 	/* See the note in cxt5047_hp_master_sw_put */ | 
| Gregorio Guidi | 5d75bc5 | 2009-03-12 16:41:51 +0100 | [diff] [blame] | 1231 | 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 1232 | 				 HDA_AMP_MUTE, bits); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1233 | } | 
 | 1234 |  | 
 | 1235 | /* toggle input of built-in and mic jack appropriately */ | 
 | 1236 | static void cxt5047_hp_automic(struct hda_codec *codec) | 
 | 1237 | { | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1238 | 	static const struct hda_verb mic_jack_on[] = { | 
| Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1239 | 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | 
 | 1240 | 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1241 | 		{} | 
 | 1242 | 	}; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1243 | 	static const struct hda_verb mic_jack_off[] = { | 
| Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1244 | 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | 
 | 1245 | 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1246 | 		{} | 
 | 1247 | 	}; | 
 | 1248 | 	unsigned int present; | 
 | 1249 |  | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1250 | 	present = snd_hda_jack_detect(codec, 0x15); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1251 | 	if (present) | 
 | 1252 | 		snd_hda_sequence_write(codec, mic_jack_on); | 
 | 1253 | 	else | 
 | 1254 | 		snd_hda_sequence_write(codec, mic_jack_off); | 
 | 1255 | } | 
 | 1256 |  | 
 | 1257 | /* unsolicited event for HP jack sensing */ | 
 | 1258 | static void cxt5047_hp_unsol_event(struct hda_codec *codec, | 
 | 1259 | 				  unsigned int res) | 
 | 1260 | { | 
| Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1261 | 	switch (res >> 26) { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1262 | 	case CONEXANT_HP_EVENT: | 
 | 1263 | 		cxt5047_hp_automute(codec); | 
 | 1264 | 		break; | 
 | 1265 | 	case CONEXANT_MIC_EVENT: | 
 | 1266 | 		cxt5047_hp_automic(codec); | 
 | 1267 | 		break; | 
 | 1268 | 	} | 
 | 1269 | } | 
 | 1270 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1271 | static const struct snd_kcontrol_new cxt5047_base_mixers[] = { | 
| Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1272 | 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), | 
 | 1273 | 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), | 
| David Henningsson | 5f99f86 | 2011-01-04 15:24:24 +0100 | [diff] [blame] | 1274 | 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1275 | 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), | 
 | 1276 | 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | 
 | 1277 | 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | 
 | 1278 | 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1279 | 	{ | 
 | 1280 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 1281 | 		.name = "Master Playback Switch", | 
 | 1282 | 		.info = cxt_eapd_info, | 
 | 1283 | 		.get = cxt_eapd_get, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1284 | 		.put = cxt5047_hp_master_sw_put, | 
 | 1285 | 		.private_value = 0x13, | 
 | 1286 | 	}, | 
 | 1287 |  | 
 | 1288 | 	{} | 
 | 1289 | }; | 
 | 1290 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1291 | static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { | 
| Takashi Iwai | 3b7523f | 2009-03-12 16:45:01 +0100 | [diff] [blame] | 1292 | 	/* See the note in cxt5047_hp_master_sw_put */ | 
| Gregorio Guidi | 5d75bc5 | 2009-03-12 16:41:51 +0100 | [diff] [blame] | 1293 | 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), | 
| Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1294 | 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), | 
 | 1295 | 	{} | 
 | 1296 | }; | 
 | 1297 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1298 | static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1299 | 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1300 | 	{ } /* end */ | 
 | 1301 | }; | 
 | 1302 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1303 | static const struct hda_verb cxt5047_init_verbs[] = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1304 | 	/* Line in, Mic, Built-in Mic */ | 
 | 1305 | 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | 
 | 1306 | 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | 
 | 1307 | 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1308 | 	/* HP, Speaker  */ | 
| Tobin Davis | b7589ce | 2007-04-24 17:56:55 +0200 | [diff] [blame] | 1309 | 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, | 
| Takashi Iwai | 5b3a744 | 2009-03-10 15:10:55 +0100 | [diff] [blame] | 1310 | 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ | 
 | 1311 | 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ | 
| Tobin Davis | 7f29673 | 2007-03-12 11:39:01 +0100 | [diff] [blame] | 1312 | 	/* Record selector: Mic */ | 
 | 1313 | 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03}, | 
 | 1314 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, | 
 | 1315 | 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | 
 | 1316 | 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1317 | 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | 
 | 1318 | 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, | 
 | 1319 | 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | 
 | 1320 | 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1321 | 	/* SPDIF route: PCM */ | 
 | 1322 | 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1323 | 	/* Enable unsolicited events */ | 
 | 1324 | 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | 
 | 1325 | 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1326 | 	{ } /* end */ | 
 | 1327 | }; | 
 | 1328 |  | 
 | 1329 | /* configuration for Toshiba Laptops */ | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1330 | static const struct hda_verb cxt5047_toshiba_init_verbs[] = { | 
| Takashi Iwai | 3b62886 | 2009-03-10 14:53:54 +0100 | [diff] [blame] | 1331 | 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1332 | 	{} | 
 | 1333 | }; | 
 | 1334 |  | 
 | 1335 | /* Test configuration for debugging, modelled after the ALC260 test | 
 | 1336 |  * configuration. | 
 | 1337 |  */ | 
 | 1338 | #ifdef CONFIG_SND_DEBUG | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1339 | static const struct hda_input_mux cxt5047_test_capture_source = { | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1340 | 	.num_items = 4, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1341 | 	.items = { | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1342 | 		{ "LINE1 pin", 0x0 }, | 
 | 1343 | 		{ "MIC1 pin", 0x1 }, | 
 | 1344 | 		{ "MIC2 pin", 0x2 }, | 
 | 1345 | 		{ "CD pin", 0x3 }, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1346 |         }, | 
 | 1347 | }; | 
 | 1348 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1349 | static const struct snd_kcontrol_new cxt5047_test_mixer[] = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1350 |  | 
 | 1351 | 	/* Output only controls */ | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1352 | 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), | 
 | 1353 | 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), | 
 | 1354 | 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), | 
 | 1355 | 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1356 | 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), | 
 | 1357 | 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), | 
 | 1358 | 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), | 
 | 1359 | 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1360 | 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), | 
 | 1361 | 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), | 
 | 1362 | 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), | 
 | 1363 | 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1364 |  | 
 | 1365 | 	/* Modes for retasking pin widgets */ | 
 | 1366 | 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), | 
 | 1367 | 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), | 
 | 1368 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1369 | 	/* EAPD Switch Control */ | 
 | 1370 | 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), | 
 | 1371 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1372 | 	/* Loopback mixer controls */ | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1373 | 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), | 
 | 1374 | 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), | 
 | 1375 | 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), | 
 | 1376 | 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), | 
 | 1377 | 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), | 
 | 1378 | 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), | 
 | 1379 | 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), | 
 | 1380 | 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1381 |  | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1382 | 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), | 
 | 1383 | 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), | 
 | 1384 | 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), | 
 | 1385 | 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), | 
 | 1386 | 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), | 
 | 1387 | 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), | 
 | 1388 | 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), | 
 | 1389 | 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1390 | 	{ | 
 | 1391 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 1392 | 		.name = "Input Source", | 
 | 1393 | 		.info = conexant_mux_enum_info, | 
 | 1394 | 		.get = conexant_mux_enum_get, | 
 | 1395 | 		.put = conexant_mux_enum_put, | 
 | 1396 | 	}, | 
| Takashi Iwai | 854206b | 2009-11-30 18:22:04 +0100 | [diff] [blame] | 1397 | 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), | 
| Marc Boucher | 9f113e0 | 2008-01-22 15:18:08 +0100 | [diff] [blame] | 1398 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1399 | 	{ } /* end */ | 
 | 1400 | }; | 
 | 1401 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1402 | static const struct hda_verb cxt5047_test_init_verbs[] = { | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1403 | 	/* Enable retasking pins as output, initially without power amp */ | 
 | 1404 | 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 1405 | 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 1406 | 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 1407 |  | 
 | 1408 | 	/* Disable digital (SPDIF) pins initially, but users can enable | 
 | 1409 | 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb | 
 | 1410 | 	 * payload also sets the generation to 0, output to be in "consumer" | 
 | 1411 | 	 * PCM format, copyright asserted, no pre-emphasis and no validity | 
 | 1412 | 	 * control. | 
 | 1413 | 	 */ | 
 | 1414 | 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, | 
 | 1415 |  | 
 | 1416 | 	/* Ensure mic1, mic2, line1 pin widgets take input from the  | 
 | 1417 | 	 * OUT1 sum bus when acting as an output. | 
 | 1418 | 	 */ | 
 | 1419 | 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0}, | 
 | 1420 | 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0}, | 
 | 1421 |  | 
 | 1422 | 	/* Start with output sum widgets muted and their output gains at min */ | 
 | 1423 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 1424 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 1425 |  | 
 | 1426 | 	/* Unmute retasking pin widget output buffers since the default | 
 | 1427 | 	 * state appears to be output.  As the pin mode is changed by the | 
 | 1428 | 	 * user the pin mode control will take care of enabling the pin's | 
 | 1429 | 	 * input/output buffers as needed. | 
 | 1430 | 	 */ | 
 | 1431 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 1432 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 1433 | 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 1434 |  | 
 | 1435 | 	/* Mute capture amp left and right */ | 
 | 1436 | 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 1437 |  | 
 | 1438 | 	/* Set ADC connection select to match default mixer setting (mic1 | 
 | 1439 | 	 * pin) | 
 | 1440 | 	 */ | 
 | 1441 | 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, | 
 | 1442 |  | 
 | 1443 | 	/* Mute all inputs to mixer widget (even unconnected ones) */ | 
 | 1444 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ | 
 | 1445 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ | 
 | 1446 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ | 
 | 1447 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ | 
 | 1448 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | 
 | 1449 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ | 
 | 1450 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ | 
 | 1451 | 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ | 
 | 1452 |  | 
 | 1453 | 	{ } | 
 | 1454 | }; | 
 | 1455 | #endif | 
 | 1456 |  | 
 | 1457 |  | 
 | 1458 | /* initialize jack-sensing, too */ | 
 | 1459 | static int cxt5047_hp_init(struct hda_codec *codec) | 
 | 1460 | { | 
 | 1461 | 	conexant_init(codec); | 
 | 1462 | 	cxt5047_hp_automute(codec); | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1463 | 	return 0; | 
 | 1464 | } | 
 | 1465 |  | 
 | 1466 |  | 
 | 1467 | enum { | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1468 | 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */ | 
 | 1469 | 	CXT5047_LAPTOP_HP,	/* Some HP laptops */ | 
 | 1470 | 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */ | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1471 | #ifdef CONFIG_SND_DEBUG | 
 | 1472 | 	CXT5047_TEST, | 
 | 1473 | #endif | 
| Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1474 | 	CXT5047_AUTO, | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1475 | 	CXT5047_MODELS | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1476 | }; | 
 | 1477 |  | 
| Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1478 | static const char * const cxt5047_models[CXT5047_MODELS] = { | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1479 | 	[CXT5047_LAPTOP]	= "laptop", | 
 | 1480 | 	[CXT5047_LAPTOP_HP]	= "laptop-hp", | 
 | 1481 | 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd", | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1482 | #ifdef CONFIG_SND_DEBUG | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1483 | 	[CXT5047_TEST]		= "test", | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1484 | #endif | 
| Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1485 | 	[CXT5047_AUTO]		= "auto", | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1486 | }; | 
 | 1487 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1488 | static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { | 
| Takashi Iwai | ac3e374 | 2007-12-17 17:14:18 +0100 | [diff] [blame] | 1489 | 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), | 
| Takashi Iwai | dea0a50 | 2009-02-09 17:14:52 +0100 | [diff] [blame] | 1490 | 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", | 
 | 1491 | 			   CXT5047_LAPTOP), | 
| Takashi Iwai | f5fcc13 | 2006-11-24 17:07:44 +0100 | [diff] [blame] | 1492 | 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1493 | 	{} | 
 | 1494 | }; | 
 | 1495 |  | 
 | 1496 | static int patch_cxt5047(struct hda_codec *codec) | 
 | 1497 | { | 
 | 1498 | 	struct conexant_spec *spec; | 
 | 1499 | 	int board_config; | 
 | 1500 |  | 
| Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1501 | 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, | 
 | 1502 | 						  cxt5047_models, | 
 | 1503 | 						  cxt5047_cfg_tbl); | 
| Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1504 | 	if (board_config < 0) | 
| Takashi Iwai | c82693d | 2011-06-28 14:17:17 +0200 | [diff] [blame] | 1505 | 		board_config = CXT5047_AUTO; /* model=auto as default */ | 
| Takashi Iwai | fa5dadc | 2011-05-13 19:33:18 +0200 | [diff] [blame] | 1506 | 	if (board_config == CXT5047_AUTO) | 
 | 1507 | 		return patch_conexant_auto(codec); | 
 | 1508 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1509 | 	spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 
 | 1510 | 	if (!spec) | 
 | 1511 | 		return -ENOMEM; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1512 | 	codec->spec = spec; | 
| Takashi Iwai | 9421f95 | 2009-03-12 17:06:07 +0100 | [diff] [blame] | 1513 | 	codec->pin_amp_workaround = 1; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1514 |  | 
 | 1515 | 	spec->multiout.max_channels = 2; | 
 | 1516 | 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); | 
 | 1517 | 	spec->multiout.dac_nids = cxt5047_dac_nids; | 
 | 1518 | 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; | 
 | 1519 | 	spec->num_adc_nids = 1; | 
 | 1520 | 	spec->adc_nids = cxt5047_adc_nids; | 
 | 1521 | 	spec->capsrc_nids = cxt5047_capsrc_nids; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1522 | 	spec->num_mixers = 1; | 
| Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1523 | 	spec->mixers[0] = cxt5047_base_mixers; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1524 | 	spec->num_init_verbs = 1; | 
 | 1525 | 	spec->init_verbs[0] = cxt5047_init_verbs; | 
 | 1526 | 	spec->spdif_route = 0; | 
| Tobin Davis | 5cd5752 | 2006-11-20 17:42:09 +0100 | [diff] [blame] | 1527 | 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), | 
 | 1528 | 	spec->channel_mode = cxt5047_modes, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1529 |  | 
 | 1530 | 	codec->patch_ops = conexant_patch_ops; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1531 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1532 | 	switch (board_config) { | 
 | 1533 | 	case CXT5047_LAPTOP: | 
| Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1534 | 		spec->num_mixers = 2; | 
 | 1535 | 		spec->mixers[1] = cxt5047_hp_spk_mixers; | 
 | 1536 | 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1537 | 		break; | 
 | 1538 | 	case CXT5047_LAPTOP_HP: | 
| Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1539 | 		spec->num_mixers = 2; | 
 | 1540 | 		spec->mixers[1] = cxt5047_hp_only_mixers; | 
| Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1541 | 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1542 | 		codec->patch_ops.init = cxt5047_hp_init; | 
 | 1543 | 		break; | 
 | 1544 | 	case CXT5047_LAPTOP_EAPD: | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 1545 | 		spec->input_mux = &cxt5047_toshiba_capture_source; | 
| Takashi Iwai | df481e4 | 2009-03-10 15:35:35 +0100 | [diff] [blame] | 1546 | 		spec->num_mixers = 2; | 
 | 1547 | 		spec->mixers[1] = cxt5047_hp_spk_mixers; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1548 | 		spec->num_init_verbs = 2; | 
 | 1549 | 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs; | 
| Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1550 | 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1551 | 		break; | 
 | 1552 | #ifdef CONFIG_SND_DEBUG | 
 | 1553 | 	case CXT5047_TEST: | 
 | 1554 | 		spec->input_mux = &cxt5047_test_capture_source; | 
 | 1555 | 		spec->mixers[0] = cxt5047_test_mixer; | 
 | 1556 | 		spec->init_verbs[0] = cxt5047_test_init_verbs; | 
| Tobin Davis | fb3409e | 2007-05-17 09:40:47 +0200 | [diff] [blame] | 1557 | 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1558 | #endif	 | 
 | 1559 | 	} | 
| Takashi Iwai | dd5746a | 2009-03-10 14:30:40 +0100 | [diff] [blame] | 1560 | 	spec->vmaster_nid = 0x13; | 
| Daniel T Chen | 025f206 | 2010-03-21 18:34:43 -0400 | [diff] [blame] | 1561 |  | 
 | 1562 | 	switch (codec->subsystem_id >> 16) { | 
 | 1563 | 	case 0x103c: | 
 | 1564 | 		/* HP laptops have really bad sound over 0 dB on NID 0x10. | 
 | 1565 | 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps | 
 | 1566 | 		 * with 0 dB offset 0x17) | 
 | 1567 | 		 */ | 
 | 1568 | 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, | 
 | 1569 | 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) | | 
 | 1570 | 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | | 
 | 1571 | 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | | 
 | 1572 | 					  (1 << AC_AMPCAP_MUTE_SHIFT)); | 
 | 1573 | 		break; | 
 | 1574 | 	} | 
 | 1575 |  | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 1576 | 	return 0; | 
 | 1577 | } | 
 | 1578 |  | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1579 | /* Conexant 5051 specific */ | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1580 | static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; | 
 | 1581 | static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1582 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1583 | static const struct hda_channel_mode cxt5051_modes[1] = { | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1584 | 	{ 2, NULL }, | 
 | 1585 | }; | 
 | 1586 |  | 
 | 1587 | static void cxt5051_update_speaker(struct hda_codec *codec) | 
 | 1588 | { | 
 | 1589 | 	struct conexant_spec *spec = codec->spec; | 
 | 1590 | 	unsigned int pinctl; | 
| Takashi Iwai | 23d2df5 | 2010-01-24 11:19:27 +0100 | [diff] [blame] | 1591 | 	/* headphone pin */ | 
 | 1592 | 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; | 
 | 1593 | 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 1594 | 			    pinctl); | 
 | 1595 | 	/* speaker pin */ | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1596 | 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; | 
 | 1597 | 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 1598 | 			    pinctl); | 
| Justin P. Mattock | a80581d | 2012-02-11 05:55:58 -0800 | [diff] [blame] | 1599 | 	/* on ideapad there is an additional speaker (subwoofer) to mute */ | 
| Herton Ronaldo Krzesinski | f7154de | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1600 | 	if (spec->ideapad) | 
 | 1601 | 		snd_hda_codec_write(codec, 0x1b, 0, | 
 | 1602 | 				    AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 1603 | 				    pinctl); | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1604 | } | 
 | 1605 |  | 
 | 1606 | /* turn on/off EAPD (+ mute HP) as a master switch */ | 
 | 1607 | static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, | 
 | 1608 | 				    struct snd_ctl_elem_value *ucontrol) | 
 | 1609 | { | 
 | 1610 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 1611 |  | 
 | 1612 | 	if (!cxt_eapd_put(kcontrol, ucontrol)) | 
 | 1613 | 		return 0; | 
 | 1614 | 	cxt5051_update_speaker(codec); | 
 | 1615 | 	return 1; | 
 | 1616 | } | 
 | 1617 |  | 
 | 1618 | /* toggle input of built-in and mic jack appropriately */ | 
 | 1619 | static void cxt5051_portb_automic(struct hda_codec *codec) | 
 | 1620 | { | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1621 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1622 | 	unsigned int present; | 
 | 1623 |  | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1624 | 	if (!(spec->auto_mic & AUTO_MIC_PORTB)) | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1625 | 		return; | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1626 | 	present = snd_hda_jack_detect(codec, 0x17); | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1627 | 	snd_hda_codec_write(codec, 0x14, 0, | 
 | 1628 | 			    AC_VERB_SET_CONNECT_SEL, | 
 | 1629 | 			    present ? 0x01 : 0x00); | 
 | 1630 | } | 
 | 1631 |  | 
 | 1632 | /* switch the current ADC according to the jack state */ | 
 | 1633 | static void cxt5051_portc_automic(struct hda_codec *codec) | 
 | 1634 | { | 
 | 1635 | 	struct conexant_spec *spec = codec->spec; | 
 | 1636 | 	unsigned int present; | 
 | 1637 | 	hda_nid_t new_adc; | 
 | 1638 |  | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1639 | 	if (!(spec->auto_mic & AUTO_MIC_PORTC)) | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1640 | 		return; | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1641 | 	present = snd_hda_jack_detect(codec, 0x18); | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1642 | 	if (present) | 
 | 1643 | 		spec->cur_adc_idx = 1; | 
 | 1644 | 	else | 
 | 1645 | 		spec->cur_adc_idx = 0; | 
 | 1646 | 	new_adc = spec->adc_nids[spec->cur_adc_idx]; | 
 | 1647 | 	if (spec->cur_adc && spec->cur_adc != new_adc) { | 
 | 1648 | 		/* stream is running, let's swap the current ADC */ | 
| Takashi Iwai | f0cea79 | 2010-08-13 11:56:53 +0200 | [diff] [blame] | 1649 | 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1650 | 		spec->cur_adc = new_adc; | 
 | 1651 | 		snd_hda_codec_setup_stream(codec, new_adc, | 
 | 1652 | 					   spec->cur_adc_stream_tag, 0, | 
 | 1653 | 					   spec->cur_adc_format); | 
 | 1654 | 	} | 
 | 1655 | } | 
 | 1656 |  | 
 | 1657 | /* mute internal speaker if HP is plugged */ | 
 | 1658 | static void cxt5051_hp_automute(struct hda_codec *codec) | 
 | 1659 | { | 
 | 1660 | 	struct conexant_spec *spec = codec->spec; | 
 | 1661 |  | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1662 | 	spec->hp_present = snd_hda_jack_detect(codec, 0x16); | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1663 | 	cxt5051_update_speaker(codec); | 
 | 1664 | } | 
 | 1665 |  | 
 | 1666 | /* unsolicited event for HP jack sensing */ | 
 | 1667 | static void cxt5051_hp_unsol_event(struct hda_codec *codec, | 
 | 1668 | 				   unsigned int res) | 
 | 1669 | { | 
 | 1670 | 	switch (res >> 26) { | 
 | 1671 | 	case CONEXANT_HP_EVENT: | 
 | 1672 | 		cxt5051_hp_automute(codec); | 
 | 1673 | 		break; | 
 | 1674 | 	case CXT5051_PORTB_EVENT: | 
 | 1675 | 		cxt5051_portb_automic(codec); | 
 | 1676 | 		break; | 
 | 1677 | 	case CXT5051_PORTC_EVENT: | 
 | 1678 | 		cxt5051_portc_automic(codec); | 
 | 1679 | 		break; | 
 | 1680 | 	} | 
 | 1681 | } | 
 | 1682 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1683 | static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1684 | 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), | 
 | 1685 | 	{ | 
 | 1686 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 1687 | 		.name = "Master Playback Switch", | 
 | 1688 | 		.info = cxt_eapd_info, | 
 | 1689 | 		.get = cxt_eapd_get, | 
 | 1690 | 		.put = cxt5051_hp_master_sw_put, | 
 | 1691 | 		.private_value = 0x1a, | 
 | 1692 | 	}, | 
| Takashi Iwai | 2c7a3fb | 2010-01-24 10:47:02 +0100 | [diff] [blame] | 1693 | 	{} | 
 | 1694 | }; | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1695 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1696 | static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { | 
| Takashi Iwai | 2c7a3fb | 2010-01-24 10:47:02 +0100 | [diff] [blame] | 1697 | 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), | 
 | 1698 | 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), | 
| David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 1699 | 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), | 
 | 1700 | 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), | 
| Takashi Iwai | 2c7a3fb | 2010-01-24 10:47:02 +0100 | [diff] [blame] | 1701 | 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), | 
 | 1702 | 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1703 | 	{} | 
 | 1704 | }; | 
 | 1705 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1706 | static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1707 | 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), | 
 | 1708 | 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), | 
| David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 1709 | 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), | 
 | 1710 | 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1711 | 	{} | 
 | 1712 | }; | 
 | 1713 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1714 | static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { | 
| Takashi Iwai | 4e4ac60 | 2010-01-23 22:29:54 +0100 | [diff] [blame] | 1715 | 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), | 
 | 1716 | 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1717 | 	{} | 
 | 1718 | }; | 
 | 1719 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1720 | static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { | 
| Takashi Iwai | 5f6c3de | 2010-01-23 22:19:29 +0100 | [diff] [blame] | 1721 | 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), | 
 | 1722 | 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), | 
| Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1723 | 	{} | 
 | 1724 | }; | 
 | 1725 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1726 | static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1727 | 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), | 
 | 1728 | 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), | 
| David Henningsson | 8607f7c | 2010-12-20 14:43:54 +0100 | [diff] [blame] | 1729 | 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), | 
 | 1730 | 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1731 | 	{} | 
 | 1732 | }; | 
 | 1733 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1734 | static const struct hda_verb cxt5051_init_verbs[] = { | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1735 | 	/* Line in, Mic */ | 
 | 1736 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | 
 | 1737 | 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | 
 | 1738 | 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | 
 | 1739 | 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | 
 | 1740 | 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | 
 | 1741 | 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | 
 | 1742 | 	/* SPK  */ | 
 | 1743 | 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 1744 | 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | 
 | 1745 | 	/* HP, Amp  */ | 
 | 1746 | 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 1747 | 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, | 
 | 1748 | 	/* DAC1 */	 | 
 | 1749 | 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 1750 | 	/* Record selector: Internal mic */ | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1751 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, | 
 | 1752 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, | 
 | 1753 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, | 
 | 1754 | 	/* SPDIF route: PCM */ | 
| Pierre-Louis Bossart | 1965c44 | 2010-05-06 16:37:03 -0500 | [diff] [blame] | 1755 | 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1756 | 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 1757 | 	/* EAPD */ | 
 | 1758 | 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */  | 
 | 1759 | 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1760 | 	{ } /* end */ | 
 | 1761 | }; | 
 | 1762 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1763 | static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1764 | 	/* Line in, Mic */ | 
 | 1765 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | 
 | 1766 | 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | 
 | 1767 | 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, | 
 | 1768 | 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, | 
 | 1769 | 	/* SPK  */ | 
 | 1770 | 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 1771 | 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | 
 | 1772 | 	/* HP, Amp  */ | 
 | 1773 | 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 1774 | 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, | 
 | 1775 | 	/* DAC1 */ | 
 | 1776 | 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 1777 | 	/* Record selector: Internal mic */ | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1778 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, | 
 | 1779 | 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, | 
 | 1780 | 	/* SPDIF route: PCM */ | 
 | 1781 | 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 1782 | 	/* EAPD */ | 
 | 1783 | 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | 
 | 1784 | 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1785 | 	{ } /* end */ | 
 | 1786 | }; | 
 | 1787 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1788 | static const struct hda_verb cxt5051_f700_init_verbs[] = { | 
| Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1789 | 	/* Line in, Mic */ | 
| Takashi Iwai | 30ed7ed | 2010-01-28 17:11:45 +0100 | [diff] [blame] | 1790 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | 
| Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1791 | 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | 
 | 1792 | 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, | 
 | 1793 | 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, | 
 | 1794 | 	/* SPK  */ | 
 | 1795 | 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 1796 | 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | 
 | 1797 | 	/* HP, Amp  */ | 
 | 1798 | 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 1799 | 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, | 
 | 1800 | 	/* DAC1 */ | 
 | 1801 | 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 1802 | 	/* Record selector: Internal mic */ | 
| Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1803 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, | 
 | 1804 | 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, | 
 | 1805 | 	/* SPDIF route: PCM */ | 
 | 1806 | 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 1807 | 	/* EAPD */ | 
 | 1808 | 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | 
 | 1809 | 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, | 
| Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1810 | 	{ } /* end */ | 
 | 1811 | }; | 
 | 1812 |  | 
| Takashi Iwai | 6953e55 | 2010-01-24 11:00:27 +0100 | [diff] [blame] | 1813 | static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, | 
 | 1814 | 				 unsigned int event) | 
 | 1815 | { | 
 | 1816 | 	snd_hda_codec_write(codec, nid, 0, | 
 | 1817 | 			    AC_VERB_SET_UNSOLICITED_ENABLE, | 
 | 1818 | 			    AC_USRSP_EN | event); | 
| Takashi Iwai | 6953e55 | 2010-01-24 11:00:27 +0100 | [diff] [blame] | 1819 | } | 
 | 1820 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1821 | static const struct hda_verb cxt5051_ideapad_init_verbs[] = { | 
| Herton Ronaldo Krzesinski | f7154de | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1822 | 	/* Subwoofer */ | 
 | 1823 | 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 1824 | 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, | 
 | 1825 | 	{ } /* end */ | 
 | 1826 | }; | 
 | 1827 |  | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1828 | /* initialize jack-sensing, too */ | 
 | 1829 | static int cxt5051_init(struct hda_codec *codec) | 
 | 1830 | { | 
| Takashi Iwai | 6953e55 | 2010-01-24 11:00:27 +0100 | [diff] [blame] | 1831 | 	struct conexant_spec *spec = codec->spec; | 
 | 1832 |  | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1833 | 	conexant_init(codec); | 
| Takashi Iwai | 6953e55 | 2010-01-24 11:00:27 +0100 | [diff] [blame] | 1834 |  | 
 | 1835 | 	if (spec->auto_mic & AUTO_MIC_PORTB) | 
 | 1836 | 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); | 
 | 1837 | 	if (spec->auto_mic & AUTO_MIC_PORTC) | 
 | 1838 | 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); | 
 | 1839 |  | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1840 | 	if (codec->patch_ops.unsol_event) { | 
 | 1841 | 		cxt5051_hp_automute(codec); | 
 | 1842 | 		cxt5051_portb_automic(codec); | 
 | 1843 | 		cxt5051_portc_automic(codec); | 
 | 1844 | 	} | 
 | 1845 | 	return 0; | 
 | 1846 | } | 
 | 1847 |  | 
 | 1848 |  | 
 | 1849 | enum { | 
 | 1850 | 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */ | 
 | 1851 | 	CXT5051_HP,	/* no docking */ | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1852 | 	CXT5051_HP_DV6736,	/* HP without mic switch */ | 
| Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1853 | 	CXT5051_F700,       /* HP Compaq Presario F700 */ | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1854 | 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */ | 
| Herton Ronaldo Krzesinski | f7154de | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1855 | 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */ | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1856 | 	CXT5051_AUTO,		/* auto-parser */ | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1857 | 	CXT5051_MODELS | 
 | 1858 | }; | 
 | 1859 |  | 
| Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1860 | static const char *const cxt5051_models[CXT5051_MODELS] = { | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1861 | 	[CXT5051_LAPTOP]	= "laptop", | 
 | 1862 | 	[CXT5051_HP]		= "hp", | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1863 | 	[CXT5051_HP_DV6736]	= "hp-dv6736", | 
| Takashi Iwai | 5f6c3de | 2010-01-23 22:19:29 +0100 | [diff] [blame] | 1864 | 	[CXT5051_F700]          = "hp-700", | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1865 | 	[CXT5051_TOSHIBA]	= "toshiba", | 
| Herton Ronaldo Krzesinski | f7154de | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1866 | 	[CXT5051_IDEAPAD]	= "ideapad", | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1867 | 	[CXT5051_AUTO]		= "auto", | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1868 | }; | 
 | 1869 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1870 | static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1871 | 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), | 
| Tony Vroon | 1812e67 | 2009-05-27 21:00:41 +0100 | [diff] [blame] | 1872 | 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), | 
| Takashi Iwai | 5f6c3de | 2010-01-23 22:19:29 +0100 | [diff] [blame] | 1873 | 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1874 | 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1875 | 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", | 
 | 1876 | 		      CXT5051_LAPTOP), | 
 | 1877 | 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), | 
| Herton Ronaldo Krzesinski | f7154de | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1878 | 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1879 | 	{} | 
 | 1880 | }; | 
 | 1881 |  | 
 | 1882 | static int patch_cxt5051(struct hda_codec *codec) | 
 | 1883 | { | 
 | 1884 | 	struct conexant_spec *spec; | 
 | 1885 | 	int board_config; | 
 | 1886 |  | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1887 | 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, | 
 | 1888 | 						  cxt5051_models, | 
 | 1889 | 						  cxt5051_cfg_tbl); | 
 | 1890 | 	if (board_config < 0) | 
| Takashi Iwai | c82693d | 2011-06-28 14:17:17 +0200 | [diff] [blame] | 1891 | 		board_config = CXT5051_AUTO; /* model=auto as default */ | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 1892 | 	if (board_config == CXT5051_AUTO) | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1893 | 		return patch_conexant_auto(codec); | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 1894 |  | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1895 | 	spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 
 | 1896 | 	if (!spec) | 
 | 1897 | 		return -ENOMEM; | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1898 | 	codec->spec = spec; | 
| Takashi Iwai | 9421f95 | 2009-03-12 17:06:07 +0100 | [diff] [blame] | 1899 | 	codec->pin_amp_workaround = 1; | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1900 |  | 
 | 1901 | 	codec->patch_ops = conexant_patch_ops; | 
 | 1902 | 	codec->patch_ops.init = cxt5051_init; | 
 | 1903 |  | 
 | 1904 | 	spec->multiout.max_channels = 2; | 
 | 1905 | 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); | 
 | 1906 | 	spec->multiout.dac_nids = cxt5051_dac_nids; | 
 | 1907 | 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; | 
 | 1908 | 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ | 
 | 1909 | 	spec->adc_nids = cxt5051_adc_nids; | 
| Takashi Iwai | 2c7a3fb | 2010-01-24 10:47:02 +0100 | [diff] [blame] | 1910 | 	spec->num_mixers = 2; | 
 | 1911 | 	spec->mixers[0] = cxt5051_capture_mixers; | 
 | 1912 | 	spec->mixers[1] = cxt5051_playback_mixers; | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1913 | 	spec->num_init_verbs = 1; | 
 | 1914 | 	spec->init_verbs[0] = cxt5051_init_verbs; | 
 | 1915 | 	spec->spdif_route = 0; | 
 | 1916 | 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); | 
 | 1917 | 	spec->channel_mode = cxt5051_modes; | 
 | 1918 | 	spec->cur_adc = 0; | 
 | 1919 | 	spec->cur_adc_idx = 0; | 
 | 1920 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1921 | 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); | 
 | 1922 |  | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1923 | 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; | 
 | 1924 |  | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1925 | 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1926 | 	switch (board_config) { | 
 | 1927 | 	case CXT5051_HP: | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1928 | 		spec->mixers[0] = cxt5051_hp_mixers; | 
 | 1929 | 		break; | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1930 | 	case CXT5051_HP_DV6736: | 
 | 1931 | 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; | 
 | 1932 | 		spec->mixers[0] = cxt5051_hp_dv6736_mixers; | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1933 | 		spec->auto_mic = 0; | 
| Takashi Iwai | 79d7d53 | 2009-03-04 09:03:50 +0100 | [diff] [blame] | 1934 | 		break; | 
| Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1935 | 	case CXT5051_F700: | 
 | 1936 | 		spec->init_verbs[0] = cxt5051_f700_init_verbs; | 
 | 1937 | 		spec->mixers[0] = cxt5051_f700_mixers; | 
| Takashi Iwai | faddaa5 | 2010-01-23 22:31:36 +0100 | [diff] [blame] | 1938 | 		spec->auto_mic = 0; | 
 | 1939 | 		break; | 
 | 1940 | 	case CXT5051_TOSHIBA: | 
 | 1941 | 		spec->mixers[0] = cxt5051_toshiba_mixers; | 
 | 1942 | 		spec->auto_mic = AUTO_MIC_PORTB; | 
| Ken Prox | cd9d95a | 2010-01-08 09:01:47 +0100 | [diff] [blame] | 1943 | 		break; | 
| Herton Ronaldo Krzesinski | f7154de | 2010-06-17 14:15:06 -0300 | [diff] [blame] | 1944 | 	case CXT5051_IDEAPAD: | 
 | 1945 | 		spec->init_verbs[spec->num_init_verbs++] = | 
 | 1946 | 			cxt5051_ideapad_init_verbs; | 
 | 1947 | 		spec->ideapad = 1; | 
 | 1948 | 		break; | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1949 | 	} | 
 | 1950 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1951 | 	if (spec->beep_amp) | 
| Takashi Iwai | 184e91c | 2013-03-18 11:00:44 +0100 | [diff] [blame] | 1952 | 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp)); | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 1953 |  | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 1954 | 	return 0; | 
 | 1955 | } | 
 | 1956 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1957 | /* Conexant 5066 specific */ | 
 | 1958 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1959 | static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; | 
 | 1960 | static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; | 
 | 1961 | static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; | 
 | 1962 | static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1963 |  | 
| Daniel Drake | dbaccc0 | 2009-11-09 15:17:24 +0000 | [diff] [blame] | 1964 | /* OLPC's microphone port is DC coupled for use with external sensors, | 
 | 1965 |  * therefore we use a 50% mic bias in order to center the input signal with | 
 | 1966 |  * the DC input range of the codec. */ | 
 | 1967 | #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 | 
 | 1968 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 1969 | static const struct hda_channel_mode cxt5066_modes[1] = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1970 | 	{ 2, NULL }, | 
 | 1971 | }; | 
 | 1972 |  | 
| Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 1973 | #define HP_PRESENT_PORT_A	(1 << 0) | 
 | 1974 | #define HP_PRESENT_PORT_D	(1 << 1) | 
 | 1975 | #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A) | 
 | 1976 | #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D) | 
 | 1977 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1978 | static void cxt5066_update_speaker(struct hda_codec *codec) | 
 | 1979 | { | 
 | 1980 | 	struct conexant_spec *spec = codec->spec; | 
 | 1981 | 	unsigned int pinctl; | 
 | 1982 |  | 
| John Baboval | 3a25344 | 2010-12-02 11:21:31 -0500 | [diff] [blame] | 1983 | 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", | 
 | 1984 | 		    spec->hp_present, spec->cur_eapd); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1985 |  | 
 | 1986 | 	/* Port A (HP) */ | 
| Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 1987 | 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 1988 | 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 1989 | 			pinctl); | 
 | 1990 |  | 
 | 1991 | 	/* Port D (HP/LO) */ | 
| Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 1992 | 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0; | 
 | 1993 | 	if (spec->dell_automute || spec->thinkpad) { | 
 | 1994 | 		/* Mute if Port A is connected */ | 
 | 1995 | 		if (hp_port_a_present(spec)) | 
| John Baboval | 3a25344 | 2010-12-02 11:21:31 -0500 | [diff] [blame] | 1996 | 			pinctl = 0; | 
 | 1997 | 	} else { | 
| Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 1998 | 		/* Thinkpad/Dell doesn't give pin-D status */ | 
 | 1999 | 		if (!hp_port_d_present(spec)) | 
 | 2000 | 			pinctl = 0; | 
| John Baboval | 3a25344 | 2010-12-02 11:21:31 -0500 | [diff] [blame] | 2001 | 	} | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2002 | 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 2003 | 			pinctl); | 
 | 2004 |  | 
 | 2005 | 	/* CLASS_D AMP */ | 
 | 2006 | 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; | 
 | 2007 | 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 2008 | 			pinctl); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2009 | } | 
 | 2010 |  | 
 | 2011 | /* turn on/off EAPD (+ mute HP) as a master switch */ | 
 | 2012 | static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, | 
 | 2013 | 				    struct snd_ctl_elem_value *ucontrol) | 
 | 2014 | { | 
 | 2015 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 2016 |  | 
 | 2017 | 	if (!cxt_eapd_put(kcontrol, ucontrol)) | 
 | 2018 | 		return 0; | 
 | 2019 |  | 
 | 2020 | 	cxt5066_update_speaker(codec); | 
 | 2021 | 	return 1; | 
 | 2022 | } | 
 | 2023 |  | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2024 | static const struct hda_input_mux cxt5066_olpc_dc_bias = { | 
 | 2025 | 	.num_items = 3, | 
 | 2026 | 	.items = { | 
 | 2027 | 		{ "Off", PIN_IN }, | 
 | 2028 | 		{ "50%", PIN_VREF50 }, | 
 | 2029 | 		{ "80%", PIN_VREF80 }, | 
 | 2030 | 	}, | 
 | 2031 | }; | 
 | 2032 |  | 
 | 2033 | static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) | 
 | 2034 | { | 
 | 2035 | 	struct conexant_spec *spec = codec->spec; | 
 | 2036 | 	/* Even though port F is the DC input, the bias is controlled on port B. | 
 | 2037 | 	 * we also leave that port as an active input (but unselected) in DC mode | 
 | 2038 | 	 * just in case that is necessary to make the bias setting take effect. */ | 
 | 2039 | 	return snd_hda_codec_write_cache(codec, 0x1a, 0, | 
 | 2040 | 		AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 2041 | 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); | 
 | 2042 | } | 
 | 2043 |  | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2044 | /* OLPC defers mic widget control until when capture is started because the | 
 | 2045 |  * microphone LED comes on as soon as these settings are put in place. if we | 
 | 2046 |  * did this before recording, it would give the false indication that recording | 
 | 2047 |  * is happening when it is not. */ | 
 | 2048 | static void cxt5066_olpc_select_mic(struct hda_codec *codec) | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2049 | { | 
| Daniel Drake | dbaccc0 | 2009-11-09 15:17:24 +0000 | [diff] [blame] | 2050 | 	struct conexant_spec *spec = codec->spec; | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2051 | 	if (!spec->recording) | 
 | 2052 | 		return; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2053 |  | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2054 | 	if (spec->dc_enable) { | 
 | 2055 | 		/* in DC mode we ignore presence detection and just use the jack | 
 | 2056 | 		 * through our special DC port */ | 
 | 2057 | 		const struct hda_verb enable_dc_mode[] = { | 
 | 2058 | 			/* disble internal mic, port C */ | 
 | 2059 | 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2060 |  | 
 | 2061 | 			/* enable DC capture, port F */ | 
 | 2062 | 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | 
 | 2063 | 			{}, | 
 | 2064 | 		}; | 
 | 2065 |  | 
 | 2066 | 		snd_hda_sequence_write(codec, enable_dc_mode); | 
 | 2067 | 		/* port B input disabled (and bias set) through the following call */ | 
 | 2068 | 		cxt5066_set_olpc_dc_bias(codec); | 
 | 2069 | 		return; | 
 | 2070 | 	} | 
 | 2071 |  | 
 | 2072 | 	/* disable DC (port F) */ | 
 | 2073 | 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); | 
 | 2074 |  | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2075 | 	/* external mic, port B */ | 
 | 2076 | 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 2077 | 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2078 |  | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2079 | 	/* internal mic, port C */ | 
 | 2080 | 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 2081 | 		spec->ext_mic_present ? 0 : PIN_VREF80); | 
 | 2082 | } | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2083 |  | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2084 | /* toggle input of built-in and mic jack appropriately */ | 
 | 2085 | static void cxt5066_olpc_automic(struct hda_codec *codec) | 
 | 2086 | { | 
 | 2087 | 	struct conexant_spec *spec = codec->spec; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2088 | 	unsigned int present; | 
 | 2089 |  | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2090 | 	if (spec->dc_enable) /* don't do presence detection in DC mode */ | 
 | 2091 | 		return; | 
 | 2092 |  | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2093 | 	present = snd_hda_codec_read(codec, 0x1a, 0, | 
 | 2094 | 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | 
 | 2095 | 	if (present) | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2096 | 		snd_printdd("CXT5066: external microphone detected\n"); | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2097 | 	else | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2098 | 		snd_printdd("CXT5066: external microphone absent\n"); | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2099 |  | 
 | 2100 | 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, | 
 | 2101 | 		present ? 0 : 1); | 
 | 2102 | 	spec->ext_mic_present = !!present; | 
 | 2103 |  | 
 | 2104 | 	cxt5066_olpc_select_mic(codec); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2105 | } | 
 | 2106 |  | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2107 | /* toggle input of built-in digital mic and mic jack appropriately */ | 
 | 2108 | static void cxt5066_vostro_automic(struct hda_codec *codec) | 
 | 2109 | { | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2110 | 	unsigned int present; | 
 | 2111 |  | 
 | 2112 | 	struct hda_verb ext_mic_present[] = { | 
 | 2113 | 		/* enable external mic, port B */ | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2114 | 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2115 |  | 
 | 2116 | 		/* switch to external mic input */ | 
 | 2117 | 		{0x17, AC_VERB_SET_CONNECT_SEL, 0}, | 
 | 2118 | 		{0x14, AC_VERB_SET_CONNECT_SEL, 0}, | 
 | 2119 |  | 
 | 2120 | 		/* disable internal digital mic */ | 
 | 2121 | 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2122 | 		{} | 
 | 2123 | 	}; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2124 | 	static const struct hda_verb ext_mic_absent[] = { | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2125 | 		/* enable internal mic, port C */ | 
 | 2126 | 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | 
 | 2127 |  | 
 | 2128 | 		/* switch to internal mic input */ | 
 | 2129 | 		{0x14, AC_VERB_SET_CONNECT_SEL, 2}, | 
 | 2130 |  | 
 | 2131 | 		/* disable external mic, port B */ | 
 | 2132 | 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2133 | 		{} | 
 | 2134 | 	}; | 
 | 2135 |  | 
 | 2136 | 	present = snd_hda_jack_detect(codec, 0x1a); | 
 | 2137 | 	if (present) { | 
 | 2138 | 		snd_printdd("CXT5066: external microphone detected\n"); | 
 | 2139 | 		snd_hda_sequence_write(codec, ext_mic_present); | 
 | 2140 | 	} else { | 
 | 2141 | 		snd_printdd("CXT5066: external microphone absent\n"); | 
 | 2142 | 		snd_hda_sequence_write(codec, ext_mic_absent); | 
 | 2143 | 	} | 
 | 2144 | } | 
 | 2145 |  | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2146 | /* toggle input of built-in digital mic and mic jack appropriately */ | 
 | 2147 | static void cxt5066_ideapad_automic(struct hda_codec *codec) | 
 | 2148 | { | 
 | 2149 | 	unsigned int present; | 
 | 2150 |  | 
 | 2151 | 	struct hda_verb ext_mic_present[] = { | 
 | 2152 | 		{0x14, AC_VERB_SET_CONNECT_SEL, 0}, | 
 | 2153 | 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | 
 | 2154 | 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2155 | 		{} | 
 | 2156 | 	}; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2157 | 	static const struct hda_verb ext_mic_absent[] = { | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2158 | 		{0x14, AC_VERB_SET_CONNECT_SEL, 2}, | 
 | 2159 | 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | 
 | 2160 | 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2161 | 		{} | 
 | 2162 | 	}; | 
 | 2163 |  | 
 | 2164 | 	present = snd_hda_jack_detect(codec, 0x1b); | 
 | 2165 | 	if (present) { | 
 | 2166 | 		snd_printdd("CXT5066: external microphone detected\n"); | 
 | 2167 | 		snd_hda_sequence_write(codec, ext_mic_present); | 
 | 2168 | 	} else { | 
 | 2169 | 		snd_printdd("CXT5066: external microphone absent\n"); | 
 | 2170 | 		snd_hda_sequence_write(codec, ext_mic_absent); | 
 | 2171 | 	} | 
 | 2172 | } | 
 | 2173 |  | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2174 |  | 
 | 2175 | /* toggle input of built-in digital mic and mic jack appropriately */ | 
 | 2176 | static void cxt5066_asus_automic(struct hda_codec *codec) | 
 | 2177 | { | 
 | 2178 | 	unsigned int present; | 
 | 2179 |  | 
 | 2180 | 	present = snd_hda_jack_detect(codec, 0x1b); | 
 | 2181 | 	snd_printdd("CXT5066: external microphone present=%d\n", present); | 
 | 2182 | 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, | 
 | 2183 | 			    present ? 1 : 0); | 
 | 2184 | } | 
 | 2185 |  | 
 | 2186 |  | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2187 | /* toggle input of built-in digital mic and mic jack appropriately */ | 
 | 2188 | static void cxt5066_hp_laptop_automic(struct hda_codec *codec) | 
 | 2189 | { | 
 | 2190 | 	unsigned int present; | 
 | 2191 |  | 
 | 2192 | 	present = snd_hda_jack_detect(codec, 0x1b); | 
 | 2193 | 	snd_printdd("CXT5066: external microphone present=%d\n", present); | 
 | 2194 | 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, | 
 | 2195 | 			    present ? 1 : 3); | 
 | 2196 | } | 
 | 2197 |  | 
 | 2198 |  | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2199 | /* toggle input of built-in digital mic and mic jack appropriately | 
 | 2200 |    order is: external mic -> dock mic -> interal mic */ | 
 | 2201 | static void cxt5066_thinkpad_automic(struct hda_codec *codec) | 
 | 2202 | { | 
 | 2203 | 	unsigned int ext_present, dock_present; | 
 | 2204 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2205 | 	static const struct hda_verb ext_mic_present[] = { | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2206 | 		{0x14, AC_VERB_SET_CONNECT_SEL, 0}, | 
 | 2207 | 		{0x17, AC_VERB_SET_CONNECT_SEL, 1}, | 
 | 2208 | 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | 
 | 2209 | 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2210 | 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2211 | 		{} | 
 | 2212 | 	}; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2213 | 	static const struct hda_verb dock_mic_present[] = { | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2214 | 		{0x14, AC_VERB_SET_CONNECT_SEL, 0}, | 
 | 2215 | 		{0x17, AC_VERB_SET_CONNECT_SEL, 0}, | 
 | 2216 | 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | 
 | 2217 | 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2218 | 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2219 | 		{} | 
 | 2220 | 	}; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2221 | 	static const struct hda_verb ext_mic_absent[] = { | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2222 | 		{0x14, AC_VERB_SET_CONNECT_SEL, 2}, | 
 | 2223 | 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | 
 | 2224 | 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2225 | 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2226 | 		{} | 
 | 2227 | 	}; | 
 | 2228 |  | 
 | 2229 | 	ext_present = snd_hda_jack_detect(codec, 0x1b); | 
 | 2230 | 	dock_present = snd_hda_jack_detect(codec, 0x1a); | 
 | 2231 | 	if (ext_present) { | 
 | 2232 | 		snd_printdd("CXT5066: external microphone detected\n"); | 
 | 2233 | 		snd_hda_sequence_write(codec, ext_mic_present); | 
 | 2234 | 	} else if (dock_present) { | 
 | 2235 | 		snd_printdd("CXT5066: dock microphone detected\n"); | 
 | 2236 | 		snd_hda_sequence_write(codec, dock_mic_present); | 
 | 2237 | 	} else { | 
 | 2238 | 		snd_printdd("CXT5066: external microphone absent\n"); | 
 | 2239 | 		snd_hda_sequence_write(codec, ext_mic_absent); | 
 | 2240 | 	} | 
 | 2241 | } | 
 | 2242 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2243 | /* mute internal speaker if HP is plugged */ | 
 | 2244 | static void cxt5066_hp_automute(struct hda_codec *codec) | 
 | 2245 | { | 
 | 2246 | 	struct conexant_spec *spec = codec->spec; | 
 | 2247 | 	unsigned int portA, portD; | 
 | 2248 |  | 
 | 2249 | 	/* Port A */ | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2250 | 	portA = snd_hda_jack_detect(codec, 0x19); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2251 |  | 
 | 2252 | 	/* Port D */ | 
| Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2253 | 	portD = snd_hda_jack_detect(codec, 0x1c); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2254 |  | 
| Takashi Iwai | a3de8ab | 2010-12-03 12:29:14 +0100 | [diff] [blame] | 2255 | 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; | 
 | 2256 | 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2257 | 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", | 
 | 2258 | 		portA, portD, spec->hp_present); | 
 | 2259 | 	cxt5066_update_speaker(codec); | 
 | 2260 | } | 
 | 2261 |  | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2262 | /* Dispatch the right mic autoswitch function */ | 
 | 2263 | static void cxt5066_automic(struct hda_codec *codec) | 
 | 2264 | { | 
 | 2265 | 	struct conexant_spec *spec = codec->spec; | 
 | 2266 |  | 
 | 2267 | 	if (spec->dell_vostro) | 
 | 2268 | 		cxt5066_vostro_automic(codec); | 
 | 2269 | 	else if (spec->ideapad) | 
 | 2270 | 		cxt5066_ideapad_automic(codec); | 
 | 2271 | 	else if (spec->thinkpad) | 
 | 2272 | 		cxt5066_thinkpad_automic(codec); | 
 | 2273 | 	else if (spec->hp_laptop) | 
 | 2274 | 		cxt5066_hp_laptop_automic(codec); | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2275 | 	else if (spec->asus) | 
 | 2276 | 		cxt5066_asus_automic(codec); | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2277 | } | 
 | 2278 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2279 | /* unsolicited event for jack sensing */ | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2280 | static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2281 | { | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2282 | 	struct conexant_spec *spec = codec->spec; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2283 | 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); | 
 | 2284 | 	switch (res >> 26) { | 
 | 2285 | 	case CONEXANT_HP_EVENT: | 
 | 2286 | 		cxt5066_hp_automute(codec); | 
 | 2287 | 		break; | 
 | 2288 | 	case CONEXANT_MIC_EVENT: | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2289 | 		/* ignore mic events in DC mode; we're always using the jack */ | 
 | 2290 | 		if (!spec->dc_enable) | 
 | 2291 | 			cxt5066_olpc_automic(codec); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2292 | 		break; | 
 | 2293 | 	} | 
 | 2294 | } | 
 | 2295 |  | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2296 | /* unsolicited event for jack sensing */ | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2297 | static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2298 | { | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2299 | 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2300 | 	switch (res >> 26) { | 
 | 2301 | 	case CONEXANT_HP_EVENT: | 
 | 2302 | 		cxt5066_hp_automute(codec); | 
 | 2303 | 		break; | 
 | 2304 | 	case CONEXANT_MIC_EVENT: | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2305 | 		cxt5066_automic(codec); | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2306 | 		break; | 
 | 2307 | 	} | 
 | 2308 | } | 
 | 2309 |  | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2310 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2311 | static const struct hda_input_mux cxt5066_analog_mic_boost = { | 
 | 2312 | 	.num_items = 5, | 
 | 2313 | 	.items = { | 
 | 2314 | 		{ "0dB",  0 }, | 
 | 2315 | 		{ "10dB", 1 }, | 
 | 2316 | 		{ "20dB", 2 }, | 
 | 2317 | 		{ "30dB", 3 }, | 
 | 2318 | 		{ "40dB", 4 }, | 
 | 2319 | 	}, | 
 | 2320 | }; | 
 | 2321 |  | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2322 | static void cxt5066_set_mic_boost(struct hda_codec *codec) | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2323 | { | 
 | 2324 | 	struct conexant_spec *spec = codec->spec; | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2325 | 	snd_hda_codec_write_cache(codec, 0x17, 0, | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2326 | 		AC_VERB_SET_AMP_GAIN_MUTE, | 
 | 2327 | 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | | 
 | 2328 | 			cxt5066_analog_mic_boost.items[spec->mic_boost].index); | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2329 | 	if (spec->ideapad || spec->thinkpad) { | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2330 | 		/* adjust the internal mic as well...it is not through 0x17 */ | 
 | 2331 | 		snd_hda_codec_write_cache(codec, 0x23, 0, | 
 | 2332 | 			AC_VERB_SET_AMP_GAIN_MUTE, | 
 | 2333 | 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | | 
 | 2334 | 				cxt5066_analog_mic_boost. | 
 | 2335 | 					items[spec->mic_boost].index); | 
 | 2336 | 	} | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2337 | } | 
 | 2338 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2339 | static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, | 
 | 2340 | 					   struct snd_ctl_elem_info *uinfo) | 
 | 2341 | { | 
 | 2342 | 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); | 
 | 2343 | } | 
 | 2344 |  | 
 | 2345 | static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, | 
 | 2346 | 					  struct snd_ctl_elem_value *ucontrol) | 
 | 2347 | { | 
 | 2348 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2349 | 	struct conexant_spec *spec = codec->spec; | 
 | 2350 | 	ucontrol->value.enumerated.item[0] = spec->mic_boost; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2351 | 	return 0; | 
 | 2352 | } | 
 | 2353 |  | 
 | 2354 | static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, | 
 | 2355 | 					  struct snd_ctl_elem_value *ucontrol) | 
 | 2356 | { | 
 | 2357 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2358 | 	struct conexant_spec *spec = codec->spec; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2359 | 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; | 
 | 2360 | 	unsigned int idx; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2361 | 	idx = ucontrol->value.enumerated.item[0]; | 
 | 2362 | 	if (idx >= imux->num_items) | 
 | 2363 | 		idx = imux->num_items - 1; | 
 | 2364 |  | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2365 | 	spec->mic_boost = idx; | 
 | 2366 | 	if (!spec->dc_enable) | 
 | 2367 | 		cxt5066_set_mic_boost(codec); | 
 | 2368 | 	return 1; | 
 | 2369 | } | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2370 |  | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2371 | static void cxt5066_enable_dc(struct hda_codec *codec) | 
 | 2372 | { | 
 | 2373 | 	const struct hda_verb enable_dc_mode[] = { | 
 | 2374 | 		/* disable gain */ | 
 | 2375 | 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 2376 |  | 
 | 2377 | 		/* switch to DC input */ | 
 | 2378 | 		{0x17, AC_VERB_SET_CONNECT_SEL, 3}, | 
 | 2379 | 		{} | 
 | 2380 | 	}; | 
 | 2381 |  | 
 | 2382 | 	/* configure as input source */ | 
 | 2383 | 	snd_hda_sequence_write(codec, enable_dc_mode); | 
 | 2384 | 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */ | 
 | 2385 | } | 
 | 2386 |  | 
 | 2387 | static void cxt5066_disable_dc(struct hda_codec *codec) | 
 | 2388 | { | 
 | 2389 | 	/* reconfigure input source */ | 
 | 2390 | 	cxt5066_set_mic_boost(codec); | 
 | 2391 | 	/* automic also selects the right mic if we're recording */ | 
 | 2392 | 	cxt5066_olpc_automic(codec); | 
 | 2393 | } | 
 | 2394 |  | 
 | 2395 | static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, | 
 | 2396 | 			     struct snd_ctl_elem_value *ucontrol) | 
 | 2397 | { | 
 | 2398 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 2399 | 	struct conexant_spec *spec = codec->spec; | 
 | 2400 | 	ucontrol->value.integer.value[0] = spec->dc_enable; | 
 | 2401 | 	return 0; | 
 | 2402 | } | 
 | 2403 |  | 
 | 2404 | static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, | 
 | 2405 | 			     struct snd_ctl_elem_value *ucontrol) | 
 | 2406 | { | 
 | 2407 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 2408 | 	struct conexant_spec *spec = codec->spec; | 
 | 2409 | 	int dc_enable = !!ucontrol->value.integer.value[0]; | 
 | 2410 |  | 
 | 2411 | 	if (dc_enable == spec->dc_enable) | 
 | 2412 | 		return 0; | 
 | 2413 |  | 
 | 2414 | 	spec->dc_enable = dc_enable; | 
 | 2415 | 	if (dc_enable) | 
 | 2416 | 		cxt5066_enable_dc(codec); | 
 | 2417 | 	else | 
 | 2418 | 		cxt5066_disable_dc(codec); | 
 | 2419 |  | 
 | 2420 | 	return 1; | 
 | 2421 | } | 
 | 2422 |  | 
 | 2423 | static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, | 
 | 2424 | 					   struct snd_ctl_elem_info *uinfo) | 
 | 2425 | { | 
 | 2426 | 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); | 
 | 2427 | } | 
 | 2428 |  | 
 | 2429 | static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, | 
 | 2430 | 					  struct snd_ctl_elem_value *ucontrol) | 
 | 2431 | { | 
 | 2432 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 2433 | 	struct conexant_spec *spec = codec->spec; | 
 | 2434 | 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias; | 
 | 2435 | 	return 0; | 
 | 2436 | } | 
 | 2437 |  | 
 | 2438 | static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, | 
 | 2439 | 					  struct snd_ctl_elem_value *ucontrol) | 
 | 2440 | { | 
 | 2441 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 2442 | 	struct conexant_spec *spec = codec->spec; | 
 | 2443 | 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; | 
 | 2444 | 	unsigned int idx; | 
 | 2445 |  | 
 | 2446 | 	idx = ucontrol->value.enumerated.item[0]; | 
 | 2447 | 	if (idx >= imux->num_items) | 
 | 2448 | 		idx = imux->num_items - 1; | 
 | 2449 |  | 
 | 2450 | 	spec->dc_input_bias = idx; | 
 | 2451 | 	if (spec->dc_enable) | 
 | 2452 | 		cxt5066_set_olpc_dc_bias(codec); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2453 | 	return 1; | 
 | 2454 | } | 
 | 2455 |  | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2456 | static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) | 
 | 2457 | { | 
 | 2458 | 	struct conexant_spec *spec = codec->spec; | 
 | 2459 | 	/* mark as recording and configure the microphone widget so that the | 
 | 2460 | 	 * recording LED comes on. */ | 
 | 2461 | 	spec->recording = 1; | 
 | 2462 | 	cxt5066_olpc_select_mic(codec); | 
 | 2463 | } | 
 | 2464 |  | 
 | 2465 | static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) | 
 | 2466 | { | 
 | 2467 | 	struct conexant_spec *spec = codec->spec; | 
 | 2468 | 	const struct hda_verb disable_mics[] = { | 
 | 2469 | 		/* disable external mic, port B */ | 
 | 2470 | 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2471 |  | 
 | 2472 | 		/* disble internal mic, port C */ | 
 | 2473 | 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2474 |  | 
 | 2475 | 		/* disable DC capture, port F */ | 
 | 2476 | 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2477 | 		{}, | 
 | 2478 | 	}; | 
 | 2479 |  | 
 | 2480 | 	snd_hda_sequence_write(codec, disable_mics); | 
 | 2481 | 	spec->recording = 0; | 
 | 2482 | } | 
 | 2483 |  | 
| Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 2484 | static void conexant_check_dig_outs(struct hda_codec *codec, | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2485 | 				    const hda_nid_t *dig_pins, | 
| Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 2486 | 				    int num_pins) | 
 | 2487 | { | 
 | 2488 | 	struct conexant_spec *spec = codec->spec; | 
 | 2489 | 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; | 
 | 2490 | 	int i; | 
 | 2491 |  | 
 | 2492 | 	for (i = 0; i < num_pins; i++, dig_pins++) { | 
 | 2493 | 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); | 
 | 2494 | 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) | 
 | 2495 | 			continue; | 
 | 2496 | 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) | 
 | 2497 | 			continue; | 
 | 2498 | 		if (spec->slave_dig_outs[0]) | 
 | 2499 | 			nid_loc++; | 
 | 2500 | 		else | 
 | 2501 | 			nid_loc = spec->slave_dig_outs; | 
 | 2502 | 	} | 
 | 2503 | } | 
 | 2504 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2505 | static const struct hda_input_mux cxt5066_capture_source = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2506 | 	.num_items = 4, | 
 | 2507 | 	.items = { | 
 | 2508 | 		{ "Mic B", 0 }, | 
 | 2509 | 		{ "Mic C", 1 }, | 
 | 2510 | 		{ "Mic E", 2 }, | 
 | 2511 | 		{ "Mic F", 3 }, | 
 | 2512 | 	}, | 
 | 2513 | }; | 
 | 2514 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2515 | static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2516 | 	.ops = &snd_hda_bind_vol, | 
 | 2517 | 	.values = { | 
 | 2518 | 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), | 
 | 2519 | 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), | 
 | 2520 | 		0 | 
 | 2521 | 	}, | 
 | 2522 | }; | 
 | 2523 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2524 | static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2525 | 	.ops = &snd_hda_bind_sw, | 
 | 2526 | 	.values = { | 
 | 2527 | 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), | 
 | 2528 | 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), | 
 | 2529 | 		0 | 
 | 2530 | 	}, | 
 | 2531 | }; | 
 | 2532 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2533 | static const struct snd_kcontrol_new cxt5066_mixer_master[] = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2534 | 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), | 
 | 2535 | 	{} | 
 | 2536 | }; | 
 | 2537 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2538 | static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2539 | 	{ | 
 | 2540 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 2541 | 		.name = "Master Playback Volume", | 
 | 2542 | 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 
 | 2543 | 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ | | 
 | 2544 | 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, | 
| Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 2545 | 		.subdevice = HDA_SUBDEV_AMP_FLAG, | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2546 | 		.info = snd_hda_mixer_amp_volume_info, | 
 | 2547 | 		.get = snd_hda_mixer_amp_volume_get, | 
 | 2548 | 		.put = snd_hda_mixer_amp_volume_put, | 
 | 2549 | 		.tlv = { .c = snd_hda_mixer_amp_tlv }, | 
 | 2550 | 		/* offset by 28 volume steps to limit minimum gain to -46dB */ | 
 | 2551 | 		.private_value = | 
 | 2552 | 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), | 
 | 2553 | 	}, | 
 | 2554 | 	{} | 
 | 2555 | }; | 
 | 2556 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2557 | static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2558 | 	{ | 
 | 2559 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 2560 | 		.name = "DC Mode Enable Switch", | 
 | 2561 | 		.info = snd_ctl_boolean_mono_info, | 
 | 2562 | 		.get = cxt5066_olpc_dc_get, | 
 | 2563 | 		.put = cxt5066_olpc_dc_put, | 
 | 2564 | 	}, | 
 | 2565 | 	{ | 
 | 2566 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 2567 | 		.name = "DC Input Bias Enum", | 
 | 2568 | 		.info = cxt5066_olpc_dc_bias_enum_info, | 
 | 2569 | 		.get = cxt5066_olpc_dc_bias_enum_get, | 
 | 2570 | 		.put = cxt5066_olpc_dc_bias_enum_put, | 
 | 2571 | 	}, | 
 | 2572 | 	{} | 
 | 2573 | }; | 
 | 2574 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2575 | static const struct snd_kcontrol_new cxt5066_mixers[] = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2576 | 	{ | 
 | 2577 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 2578 | 		.name = "Master Playback Switch", | 
 | 2579 | 		.info = cxt_eapd_info, | 
 | 2580 | 		.get = cxt_eapd_get, | 
 | 2581 | 		.put = cxt5066_hp_master_sw_put, | 
 | 2582 | 		.private_value = 0x1d, | 
 | 2583 | 	}, | 
 | 2584 |  | 
 | 2585 | 	{ | 
 | 2586 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2587 | 		.name = "Analog Mic Boost Capture Enum", | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2588 | 		.info = cxt5066_mic_boost_mux_enum_info, | 
 | 2589 | 		.get = cxt5066_mic_boost_mux_enum_get, | 
 | 2590 | 		.put = cxt5066_mic_boost_mux_enum_put, | 
 | 2591 | 	}, | 
 | 2592 |  | 
 | 2593 | 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), | 
 | 2594 | 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), | 
 | 2595 | 	{} | 
 | 2596 | }; | 
 | 2597 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2598 | static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { | 
| Einar Rünkaru | 254bba6 | 2009-12-16 22:16:13 +0200 | [diff] [blame] | 2599 | 	{ | 
 | 2600 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 2601 | 		.name = "Internal Mic Boost Capture Enum", | 
| Einar Rünkaru | 254bba6 | 2009-12-16 22:16:13 +0200 | [diff] [blame] | 2602 | 		.info = cxt5066_mic_boost_mux_enum_info, | 
 | 2603 | 		.get = cxt5066_mic_boost_mux_enum_get, | 
 | 2604 | 		.put = cxt5066_mic_boost_mux_enum_put, | 
 | 2605 | 		.private_value = 0x23 | 0x100, | 
 | 2606 | 	}, | 
 | 2607 | 	{} | 
 | 2608 | }; | 
 | 2609 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2610 | static const struct hda_verb cxt5066_init_verbs[] = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2611 | 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ | 
 | 2612 | 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ | 
 | 2613 | 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ | 
 | 2614 | 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ | 
 | 2615 |  | 
 | 2616 | 	/* Speakers  */ | 
 | 2617 | 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2618 | 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2619 |  | 
 | 2620 | 	/* HP, Amp  */ | 
 | 2621 | 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 2622 | 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2623 |  | 
 | 2624 | 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 2625 | 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2626 |  | 
 | 2627 | 	/* DAC1 */ | 
 | 2628 | 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 2629 |  | 
 | 2630 | 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ | 
 | 2631 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, | 
 | 2632 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2633 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, | 
 | 2634 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2635 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | 
 | 2636 |  | 
 | 2637 | 	/* no digital microphone support yet */ | 
 | 2638 | 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2639 |  | 
 | 2640 | 	/* Audio input selector */ | 
 | 2641 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, | 
 | 2642 |  | 
 | 2643 | 	/* SPDIF route: PCM */ | 
 | 2644 | 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 2645 | 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 2646 |  | 
 | 2647 | 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2648 | 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2649 |  | 
 | 2650 | 	/* EAPD */ | 
 | 2651 | 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | 
 | 2652 |  | 
 | 2653 | 	/* not handling these yet */ | 
 | 2654 | 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | 
 | 2655 | 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | 
 | 2656 | 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | 
 | 2657 | 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | 
 | 2658 | 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | 
 | 2659 | 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | 
 | 2660 | 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | 
 | 2661 | 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | 
 | 2662 | 	{ } /* end */ | 
 | 2663 | }; | 
 | 2664 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2665 | static const struct hda_verb cxt5066_init_verbs_olpc[] = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2666 | 	/* Port A: headphones */ | 
 | 2667 | 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 2668 | 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2669 |  | 
 | 2670 | 	/* Port B: external microphone */ | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2671 | 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2672 |  | 
 | 2673 | 	/* Port C: internal microphone */ | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2674 | 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2675 |  | 
 | 2676 | 	/* Port D: unused */ | 
 | 2677 | 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2678 |  | 
 | 2679 | 	/* Port E: unused, but has primary EAPD */ | 
 | 2680 | 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2681 | 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | 
 | 2682 |  | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2683 | 	/* Port F: external DC input through microphone port */ | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2684 | 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2685 |  | 
 | 2686 | 	/* Port G: internal speakers */ | 
 | 2687 | 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2688 | 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2689 |  | 
 | 2690 | 	/* DAC1 */ | 
 | 2691 | 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 2692 |  | 
 | 2693 | 	/* DAC2: unused */ | 
 | 2694 | 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | 
 | 2695 |  | 
 | 2696 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, | 
 | 2697 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2698 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | 
 | 2699 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2700 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 2701 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2702 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | 
 | 2703 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2704 | 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 2705 | 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2706 | 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | 
 | 2707 | 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2708 |  | 
 | 2709 | 	/* Disable digital microphone port */ | 
 | 2710 | 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2711 |  | 
 | 2712 | 	/* Audio input selectors */ | 
 | 2713 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, | 
 | 2714 | 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, | 
 | 2715 |  | 
 | 2716 | 	/* Disable SPDIF */ | 
 | 2717 | 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2718 | 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2719 |  | 
 | 2720 | 	/* enable unsolicited events for Port A and B */ | 
 | 2721 | 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | 
 | 2722 | 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | 
 | 2723 | 	{ } /* end */ | 
 | 2724 | }; | 
 | 2725 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2726 | static const struct hda_verb cxt5066_init_verbs_vostro[] = { | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 2727 | 	/* Port A: headphones */ | 
 | 2728 | 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2729 | 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2730 |  | 
 | 2731 | 	/* Port B: external microphone */ | 
 | 2732 | 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2733 |  | 
 | 2734 | 	/* Port C: unused */ | 
 | 2735 | 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2736 |  | 
 | 2737 | 	/* Port D: unused */ | 
 | 2738 | 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2739 |  | 
 | 2740 | 	/* Port E: unused, but has primary EAPD */ | 
 | 2741 | 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2742 | 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | 
 | 2743 |  | 
 | 2744 | 	/* Port F: unused */ | 
 | 2745 | 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2746 |  | 
 | 2747 | 	/* Port G: internal speakers */ | 
 | 2748 | 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2749 | 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2750 |  | 
 | 2751 | 	/* DAC1 */ | 
 | 2752 | 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 2753 |  | 
 | 2754 | 	/* DAC2: unused */ | 
 | 2755 | 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | 
 | 2756 |  | 
 | 2757 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 2758 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2759 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | 
 | 2760 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2761 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 2762 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2763 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | 
 | 2764 | 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2765 | 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | 
 | 2766 | 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2767 | 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | 
 | 2768 | 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2769 |  | 
 | 2770 | 	/* Digital microphone port */ | 
 | 2771 | 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | 
 | 2772 |  | 
 | 2773 | 	/* Audio input selectors */ | 
 | 2774 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, | 
 | 2775 | 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, | 
 | 2776 |  | 
 | 2777 | 	/* Disable SPDIF */ | 
 | 2778 | 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2779 | 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2780 |  | 
 | 2781 | 	/* enable unsolicited events for Port A and B */ | 
 | 2782 | 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | 
 | 2783 | 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | 
 | 2784 | 	{ } /* end */ | 
 | 2785 | }; | 
 | 2786 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2787 | static const struct hda_verb cxt5066_init_verbs_ideapad[] = { | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2788 | 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ | 
 | 2789 | 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ | 
 | 2790 | 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ | 
 | 2791 | 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ | 
 | 2792 |  | 
 | 2793 | 	/* Speakers  */ | 
 | 2794 | 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2795 | 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2796 |  | 
 | 2797 | 	/* HP, Amp  */ | 
 | 2798 | 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 2799 | 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2800 |  | 
 | 2801 | 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | 
 | 2802 | 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2803 |  | 
 | 2804 | 	/* DAC1 */ | 
 | 2805 | 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 2806 |  | 
 | 2807 | 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ | 
 | 2808 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, | 
 | 2809 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2810 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, | 
 | 2811 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2812 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | 
 | 2813 | 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */ | 
 | 2814 |  | 
 | 2815 | 	/* Audio input selector */ | 
 | 2816 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, | 
 | 2817 | 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */ | 
 | 2818 |  | 
 | 2819 | 	/* SPDIF route: PCM */ | 
 | 2820 | 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 2821 | 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 2822 |  | 
 | 2823 | 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2824 | 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2825 |  | 
 | 2826 | 	/* internal microphone */ | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 2827 | 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2828 |  | 
 | 2829 | 	/* EAPD */ | 
 | 2830 | 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | 
 | 2831 |  | 
 | 2832 | 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | 
 | 2833 | 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | 
 | 2834 | 	{ } /* end */ | 
 | 2835 | }; | 
 | 2836 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2837 | static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2838 | 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ | 
 | 2839 | 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ | 
 | 2840 |  | 
 | 2841 | 	/* Port G: internal speakers  */ | 
 | 2842 | 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2843 | 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2844 |  | 
 | 2845 | 	/* Port A: HP, Amp  */ | 
 | 2846 | 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2847 | 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2848 |  | 
 | 2849 | 	/* Port B: Mic Dock */ | 
 | 2850 | 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2851 |  | 
 | 2852 | 	/* Port C: Mic */ | 
 | 2853 | 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2854 |  | 
 | 2855 | 	/* Port D: HP Dock, Amp */ | 
 | 2856 | 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | 
 | 2857 | 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | 
 | 2858 |  | 
 | 2859 | 	/* DAC1 */ | 
 | 2860 | 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | 
 | 2861 |  | 
 | 2862 | 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ | 
 | 2863 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, | 
 | 2864 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | 
 | 2865 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, | 
 | 2866 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | 
 | 2867 | 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | 
 | 2868 | 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */ | 
 | 2869 |  | 
 | 2870 | 	/* Audio input selector */ | 
 | 2871 | 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, | 
 | 2872 | 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */ | 
 | 2873 |  | 
 | 2874 | 	/* SPDIF route: PCM */ | 
 | 2875 | 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 2876 | 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 2877 |  | 
 | 2878 | 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2879 | 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2880 |  | 
 | 2881 | 	/* internal microphone */ | 
| David Henningsson | 28c4edb | 2010-12-20 14:24:29 +0100 | [diff] [blame] | 2882 | 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2883 |  | 
 | 2884 | 	/* EAPD */ | 
 | 2885 | 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | 
 | 2886 |  | 
 | 2887 | 	/* enable unsolicited events for Port A, B, C and D */ | 
 | 2888 | 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | 
 | 2889 | 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | 
 | 2890 | 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | 
 | 2891 | 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | 
 | 2892 | 	{ } /* end */ | 
 | 2893 | }; | 
 | 2894 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2895 | static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2896 | 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | 
 | 2897 | 	{ } /* end */ | 
 | 2898 | }; | 
 | 2899 |  | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2900 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2901 | static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2902 | 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, | 
 | 2903 | 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | 
 | 2904 | 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | 
 | 2905 | 	{ } /* end */ | 
 | 2906 | }; | 
 | 2907 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2908 | /* initialize jack-sensing, too */ | 
 | 2909 | static int cxt5066_init(struct hda_codec *codec) | 
 | 2910 | { | 
 | 2911 | 	snd_printdd("CXT5066: init\n"); | 
 | 2912 | 	conexant_init(codec); | 
 | 2913 | 	if (codec->patch_ops.unsol_event) { | 
 | 2914 | 		cxt5066_hp_automute(codec); | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 2915 | 		cxt5066_automic(codec); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2916 | 	} | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2917 | 	cxt5066_set_mic_boost(codec); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2918 | 	return 0; | 
 | 2919 | } | 
 | 2920 |  | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2921 | static int cxt5066_olpc_init(struct hda_codec *codec) | 
 | 2922 | { | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2923 | 	struct conexant_spec *spec = codec->spec; | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2924 | 	snd_printdd("CXT5066: init\n"); | 
 | 2925 | 	conexant_init(codec); | 
 | 2926 | 	cxt5066_hp_automute(codec); | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 2927 | 	if (!spec->dc_enable) { | 
 | 2928 | 		cxt5066_set_mic_boost(codec); | 
 | 2929 | 		cxt5066_olpc_automic(codec); | 
 | 2930 | 	} else { | 
 | 2931 | 		cxt5066_enable_dc(codec); | 
 | 2932 | 	} | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 2933 | 	return 0; | 
 | 2934 | } | 
 | 2935 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2936 | enum { | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2937 | 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */ | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2938 | 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */ | 
 | 2939 | 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */ | 
| David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 2940 | 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */ | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2941 | 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */ | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2942 | 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */ | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2943 | 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2944 | 	CXT5066_HP_LAPTOP,      /* HP Laptop */ | 
| Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 2945 | 	CXT5066_AUTO,		/* BIOS auto-parser */ | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2946 | 	CXT5066_MODELS | 
 | 2947 | }; | 
 | 2948 |  | 
| Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 2949 | static const char * const cxt5066_models[CXT5066_MODELS] = { | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2950 | 	[CXT5066_LAPTOP]	= "laptop", | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2951 | 	[CXT5066_DELL_LAPTOP]	= "dell-laptop", | 
 | 2952 | 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5", | 
| David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 2953 | 	[CXT5066_DELL_VOSTRO]	= "dell-vostro", | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 2954 | 	[CXT5066_IDEAPAD]	= "ideapad", | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 2955 | 	[CXT5066_THINKPAD]	= "thinkpad", | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2956 | 	[CXT5066_ASUS]		= "asus", | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2957 | 	[CXT5066_HP_LAPTOP]	= "hp-laptop", | 
| Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 2958 | 	[CXT5066_AUTO]		= "auto", | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2959 | }; | 
 | 2960 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 2961 | static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { | 
| David Henningsson | 9966db22 | 2011-06-21 21:01:52 +0200 | [diff] [blame] | 2962 | 	SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), | 
| Takashi Iwai | 00cd0bb | 2010-10-21 09:57:40 +0200 | [diff] [blame] | 2963 | 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), | 
| David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 2964 | 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), | 
| David Henningsson | 8a96b1e | 2010-12-09 07:17:27 +0100 | [diff] [blame] | 2965 | 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), | 
| Daniel T Chen | ca6cd85 | 2011-01-08 18:25:27 -0500 | [diff] [blame] | 2966 | 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), | 
| Anisse Astier | 231f50b | 2010-04-28 18:05:06 +0200 | [diff] [blame] | 2967 | 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), | 
| David Henningsson | ebbd224 | 2011-02-23 13:15:56 +0100 | [diff] [blame] | 2968 | 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), | 
 | 2969 | 	SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 2970 | 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), | 
| Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 2971 | 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2972 | 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), | 
| Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 2973 | 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), | 
| Anisse Astier | 2ca9cac | 2010-09-10 15:47:55 +0200 | [diff] [blame] | 2974 | 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), | 
| Daniel T Chen | c536668 | 2010-05-04 22:07:58 -0400 | [diff] [blame] | 2975 | 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), | 
| David Henningsson | 5637edb | 2010-09-17 10:58:03 +0200 | [diff] [blame] | 2976 | 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", | 
 | 2977 | 		      CXT5066_LAPTOP), | 
 | 2978 | 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), | 
| Takashi Iwai | 4d15564 | 2010-09-07 11:58:30 +0200 | [diff] [blame] | 2979 | 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), | 
| Manoj Iyer | ef61d4e | 2010-12-03 18:43:55 -0600 | [diff] [blame] | 2980 | 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), | 
| David Henningsson | 1959387 | 2011-01-27 10:28:46 +0100 | [diff] [blame] | 2981 | 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), | 
| David Henningsson | 29c5fbb | 2012-01-23 16:39:55 +0100 | [diff] [blame] | 2982 | 	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO), | 
| Daniel Suchy | ca201c0 | 2011-10-18 11:09:44 +0200 | [diff] [blame] | 2983 | 	SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), | 
| David Henningsson | 8401265 | 2011-03-31 09:36:19 +0200 | [diff] [blame] | 2984 | 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), | 
| David Henningsson | b2cb129 | 2011-04-05 07:55:24 +0200 | [diff] [blame] | 2985 | 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), | 
| David Henningsson | d2859fd | 2011-05-23 08:26:16 +0200 | [diff] [blame] | 2986 | 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 2987 | 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), | 
| Takashi Iwai | af4ccf4 | 2011-05-25 07:33:20 +0200 | [diff] [blame] | 2988 | 	SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), | 
| Daniel T Chen | 7ab1fc0 | 2011-06-10 10:14:01 -0400 | [diff] [blame] | 2989 | 	SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 2990 | 	{} | 
 | 2991 | }; | 
 | 2992 |  | 
 | 2993 | static int patch_cxt5066(struct hda_codec *codec) | 
 | 2994 | { | 
 | 2995 | 	struct conexant_spec *spec; | 
 | 2996 | 	int board_config; | 
 | 2997 |  | 
| Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 2998 | 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, | 
 | 2999 | 						  cxt5066_models, cxt5066_cfg_tbl); | 
| Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 3000 | 	if (board_config < 0) | 
| Takashi Iwai | c82693d | 2011-06-28 14:17:17 +0200 | [diff] [blame] | 3001 | 		board_config = CXT5066_AUTO; /* model=auto as default */ | 
| Takashi Iwai | fea4a4f | 2011-05-16 11:49:12 +0200 | [diff] [blame] | 3002 | 	if (board_config == CXT5066_AUTO) | 
 | 3003 | 		return patch_conexant_auto(codec); | 
 | 3004 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3005 | 	spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 
 | 3006 | 	if (!spec) | 
 | 3007 | 		return -ENOMEM; | 
 | 3008 | 	codec->spec = spec; | 
 | 3009 |  | 
 | 3010 | 	codec->patch_ops = conexant_patch_ops; | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 3011 | 	codec->patch_ops.init = conexant_init; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3012 |  | 
 | 3013 | 	spec->dell_automute = 0; | 
 | 3014 | 	spec->multiout.max_channels = 2; | 
 | 3015 | 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); | 
 | 3016 | 	spec->multiout.dac_nids = cxt5066_dac_nids; | 
| Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 3017 | 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, | 
 | 3018 | 	    ARRAY_SIZE(cxt5066_digout_pin_nids)); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3019 | 	spec->num_adc_nids = 1; | 
 | 3020 | 	spec->adc_nids = cxt5066_adc_nids; | 
 | 3021 | 	spec->capsrc_nids = cxt5066_capsrc_nids; | 
 | 3022 | 	spec->input_mux = &cxt5066_capture_source; | 
 | 3023 |  | 
 | 3024 | 	spec->port_d_mode = PIN_HP; | 
 | 3025 |  | 
 | 3026 | 	spec->num_init_verbs = 1; | 
 | 3027 | 	spec->init_verbs[0] = cxt5066_init_verbs; | 
 | 3028 | 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); | 
 | 3029 | 	spec->channel_mode = cxt5066_modes; | 
 | 3030 | 	spec->cur_adc = 0; | 
 | 3031 | 	spec->cur_adc_idx = 0; | 
 | 3032 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 3033 | 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); | 
 | 3034 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3035 | 	switch (board_config) { | 
 | 3036 | 	default: | 
 | 3037 | 	case CXT5066_LAPTOP: | 
 | 3038 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; | 
 | 3039 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixers; | 
 | 3040 | 		break; | 
 | 3041 | 	case CXT5066_DELL_LAPTOP: | 
 | 3042 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; | 
 | 3043 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixers; | 
 | 3044 |  | 
 | 3045 | 		spec->port_d_mode = PIN_OUT; | 
 | 3046 | 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; | 
 | 3047 | 		spec->num_init_verbs++; | 
 | 3048 | 		spec->dell_automute = 1; | 
 | 3049 | 		break; | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 3050 | 	case CXT5066_ASUS: | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 3051 | 	case CXT5066_HP_LAPTOP: | 
 | 3052 | 		codec->patch_ops.init = cxt5066_init; | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 3053 | 		codec->patch_ops.unsol_event = cxt5066_unsol_event; | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 3054 | 		spec->init_verbs[spec->num_init_verbs] = | 
 | 3055 | 			cxt5066_init_verbs_hp_laptop; | 
 | 3056 | 		spec->num_init_verbs++; | 
| David Henningsson | a1d6906 | 2011-01-21 13:33:28 +0100 | [diff] [blame] | 3057 | 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; | 
 | 3058 | 		spec->asus = board_config == CXT5066_ASUS; | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 3059 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; | 
 | 3060 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixers; | 
 | 3061 | 		/* no S/PDIF out */ | 
| Andy Robinson | f6a2491 | 2011-01-24 10:12:37 -0500 | [diff] [blame] | 3062 | 		if (board_config == CXT5066_HP_LAPTOP) | 
 | 3063 | 			spec->multiout.dig_out_nid = 0; | 
| David Henningsson | 048e78a | 2010-09-02 08:35:47 +0200 | [diff] [blame] | 3064 | 		/* input source automatically selected */ | 
 | 3065 | 		spec->input_mux = NULL; | 
 | 3066 | 		spec->port_d_mode = 0; | 
 | 3067 | 		spec->mic_boost = 3; /* default 30dB gain */ | 
 | 3068 | 		break; | 
 | 3069 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3070 | 	case CXT5066_OLPC_XO_1_5: | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 3071 | 		codec->patch_ops.init = cxt5066_olpc_init; | 
 | 3072 | 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3073 | 		spec->init_verbs[0] = cxt5066_init_verbs_olpc; | 
 | 3074 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 3075 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3076 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixers; | 
 | 3077 | 		spec->port_d_mode = 0; | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 3078 | 		spec->mic_boost = 3; /* default 30dB gain */ | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3079 |  | 
 | 3080 | 		/* no S/PDIF out */ | 
 | 3081 | 		spec->multiout.dig_out_nid = 0; | 
 | 3082 |  | 
 | 3083 | 		/* input source automatically selected */ | 
 | 3084 | 		spec->input_mux = NULL; | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 3085 |  | 
 | 3086 | 		/* our capture hooks which allow us to turn on the microphone LED | 
 | 3087 | 		 * at the right time */ | 
 | 3088 | 		spec->capture_prepare = cxt5066_olpc_capture_prepare; | 
 | 3089 | 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3090 | 		break; | 
| David Henningsson | 1feba3b | 2010-09-17 10:52:50 +0200 | [diff] [blame] | 3091 | 	case CXT5066_DELL_VOSTRO: | 
| Daniel Drake | 75f8991 | 2010-01-07 13:46:25 +0100 | [diff] [blame] | 3092 | 		codec->patch_ops.init = cxt5066_init; | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 3093 | 		codec->patch_ops.unsol_event = cxt5066_unsol_event; | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 3094 | 		spec->init_verbs[0] = cxt5066_init_verbs_vostro; | 
 | 3095 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; | 
 | 3096 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixers; | 
| Einar Rünkaru | 254bba6 | 2009-12-16 22:16:13 +0200 | [diff] [blame] | 3097 | 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 3098 | 		spec->port_d_mode = 0; | 
| Einar Rünkaru | 254bba6 | 2009-12-16 22:16:13 +0200 | [diff] [blame] | 3099 | 		spec->dell_vostro = 1; | 
| Daniel Drake | c4cfe66 | 2010-01-07 13:47:04 +0100 | [diff] [blame] | 3100 | 		spec->mic_boost = 3; /* default 30dB gain */ | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 3101 |  | 
 | 3102 | 		/* no S/PDIF out */ | 
 | 3103 | 		spec->multiout.dig_out_nid = 0; | 
 | 3104 |  | 
 | 3105 | 		/* input source automatically selected */ | 
 | 3106 | 		spec->input_mux = NULL; | 
 | 3107 | 		break; | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 3108 | 	case CXT5066_IDEAPAD: | 
 | 3109 | 		codec->patch_ops.init = cxt5066_init; | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 3110 | 		codec->patch_ops.unsol_event = cxt5066_unsol_event; | 
| Greg Alexander | cfd3d8d | 2010-02-13 02:02:25 -0500 | [diff] [blame] | 3111 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; | 
 | 3112 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixers; | 
 | 3113 | 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad; | 
 | 3114 | 		spec->port_d_mode = 0; | 
 | 3115 | 		spec->ideapad = 1; | 
 | 3116 | 		spec->mic_boost = 2;	/* default 20dB gain */ | 
 | 3117 |  | 
 | 3118 | 		/* no S/PDIF out */ | 
 | 3119 | 		spec->multiout.dig_out_nid = 0; | 
 | 3120 |  | 
 | 3121 | 		/* input source automatically selected */ | 
 | 3122 | 		spec->input_mux = NULL; | 
 | 3123 | 		break; | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 3124 | 	case CXT5066_THINKPAD: | 
 | 3125 | 		codec->patch_ops.init = cxt5066_init; | 
| David Henningsson | 02b6b5b | 2011-01-21 13:27:39 +0100 | [diff] [blame] | 3126 | 		codec->patch_ops.unsol_event = cxt5066_unsol_event; | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 3127 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; | 
 | 3128 | 		spec->mixers[spec->num_mixers++] = cxt5066_mixers; | 
 | 3129 | 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; | 
 | 3130 | 		spec->thinkpad = 1; | 
 | 3131 | 		spec->port_d_mode = PIN_OUT; | 
 | 3132 | 		spec->mic_boost = 2;	/* default 20dB gain */ | 
 | 3133 |  | 
 | 3134 | 		/* no S/PDIF out */ | 
 | 3135 | 		spec->multiout.dig_out_nid = 0; | 
 | 3136 |  | 
 | 3137 | 		/* input source automatically selected */ | 
 | 3138 | 		spec->input_mux = NULL; | 
 | 3139 | 		break; | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3140 | 	} | 
 | 3141 |  | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 3142 | 	if (spec->beep_amp) | 
| Takashi Iwai | 184e91c | 2013-03-18 11:00:44 +0100 | [diff] [blame] | 3143 | 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp)); | 
| Takashi Iwai | 3507e2a | 2010-07-08 18:39:00 +0200 | [diff] [blame] | 3144 |  | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 3145 | 	return 0; | 
 | 3146 | } | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 3147 |  | 
 | 3148 | /* | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3149 |  * Automatic parser for CX20641 & co | 
 | 3150 |  */ | 
 | 3151 |  | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3152 | static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | 
 | 3153 | 				       struct hda_codec *codec, | 
 | 3154 | 				       unsigned int stream_tag, | 
 | 3155 | 				       unsigned int format, | 
 | 3156 | 				       struct snd_pcm_substream *substream) | 
 | 3157 | { | 
 | 3158 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 3159 | 	hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3160 | 	if (spec->adc_switching) { | 
 | 3161 | 		spec->cur_adc = adc; | 
 | 3162 | 		spec->cur_adc_stream_tag = stream_tag; | 
 | 3163 | 		spec->cur_adc_format = format; | 
 | 3164 | 	} | 
 | 3165 | 	snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); | 
 | 3166 | 	return 0; | 
 | 3167 | } | 
 | 3168 |  | 
 | 3169 | static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | 
 | 3170 | 				       struct hda_codec *codec, | 
 | 3171 | 				       struct snd_pcm_substream *substream) | 
 | 3172 | { | 
 | 3173 | 	struct conexant_spec *spec = codec->spec; | 
 | 3174 | 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc); | 
 | 3175 | 	spec->cur_adc = 0; | 
 | 3176 | 	return 0; | 
 | 3177 | } | 
 | 3178 |  | 
 | 3179 | static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { | 
 | 3180 | 	.substreams = 1, | 
 | 3181 | 	.channels_min = 2, | 
 | 3182 | 	.channels_max = 2, | 
 | 3183 | 	.nid = 0, /* fill later */ | 
 | 3184 | 	.ops = { | 
 | 3185 | 		.prepare = cx_auto_capture_pcm_prepare, | 
 | 3186 | 		.cleanup = cx_auto_capture_pcm_cleanup | 
 | 3187 | 	}, | 
 | 3188 | }; | 
 | 3189 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 3190 | static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3191 |  | 
| Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 3192 | #define get_connection_index(codec, mux, nid)\ | 
 | 3193 | 	snd_hda_get_conn_index(codec, mux, nid, 0) | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3194 |  | 
 | 3195 | /* get an unassigned DAC from the given list. | 
 | 3196 |  * Return the nid if found and reduce the DAC list, or return zero if | 
 | 3197 |  * not found | 
 | 3198 |  */ | 
 | 3199 | static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, | 
 | 3200 | 				    hda_nid_t *dacs, int *num_dacs) | 
 | 3201 | { | 
 | 3202 | 	int i, nums = *num_dacs; | 
 | 3203 | 	hda_nid_t ret = 0; | 
 | 3204 |  | 
 | 3205 | 	for (i = 0; i < nums; i++) { | 
 | 3206 | 		if (get_connection_index(codec, pin, dacs[i]) >= 0) { | 
 | 3207 | 			ret = dacs[i]; | 
 | 3208 | 			break; | 
 | 3209 | 		} | 
 | 3210 | 	} | 
 | 3211 | 	if (!ret) | 
 | 3212 | 		return 0; | 
 | 3213 | 	if (--nums > 0) | 
 | 3214 | 		memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); | 
 | 3215 | 	*num_dacs = nums; | 
 | 3216 | 	return ret; | 
 | 3217 | } | 
 | 3218 |  | 
 | 3219 | #define MAX_AUTO_DACS	5 | 
 | 3220 |  | 
| Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 3221 | #define DAC_SLAVE_FLAG	0x8000	/* filled dac is a slave */ | 
 | 3222 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3223 | /* fill analog DAC list from the widget tree */ | 
 | 3224 | static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) | 
 | 3225 | { | 
 | 3226 | 	hda_nid_t nid, end_nid; | 
 | 3227 | 	int nums = 0; | 
 | 3228 |  | 
 | 3229 | 	end_nid = codec->start_nid + codec->num_nodes; | 
 | 3230 | 	for (nid = codec->start_nid; nid < end_nid; nid++) { | 
 | 3231 | 		unsigned int wcaps = get_wcaps(codec, nid); | 
 | 3232 | 		unsigned int type = get_wcaps_type(wcaps); | 
 | 3233 | 		if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { | 
 | 3234 | 			dacs[nums++] = nid; | 
 | 3235 | 			if (nums >= MAX_AUTO_DACS) | 
 | 3236 | 				break; | 
 | 3237 | 		} | 
 | 3238 | 	} | 
 | 3239 | 	return nums; | 
 | 3240 | } | 
 | 3241 |  | 
 | 3242 | /* fill pin_dac_pair list from the pin and dac list */ | 
 | 3243 | static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, | 
 | 3244 | 			      int num_pins, hda_nid_t *dacs, int *rest, | 
| David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3245 | 			      struct pin_dac_pair *filled, int nums,  | 
 | 3246 | 			      int type) | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3247 | { | 
| David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3248 | 	int i, start = nums; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3249 |  | 
| David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3250 | 	for (i = 0; i < num_pins; i++, nums++) { | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3251 | 		filled[nums].pin = pins[i]; | 
 | 3252 | 		filled[nums].type = type; | 
 | 3253 | 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); | 
| David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3254 | 		if (filled[nums].dac)  | 
 | 3255 | 			continue; | 
 | 3256 | 		if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { | 
 | 3257 | 			filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; | 
 | 3258 | 			continue; | 
 | 3259 | 		} | 
 | 3260 | 		if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { | 
| Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 3261 | 			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; | 
| David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3262 | 			continue; | 
 | 3263 | 		} | 
 | 3264 | 		snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3265 | 	} | 
 | 3266 | 	return nums; | 
 | 3267 | } | 
 | 3268 |  | 
 | 3269 | /* parse analog output paths */ | 
 | 3270 | static void cx_auto_parse_output(struct hda_codec *codec) | 
 | 3271 | { | 
 | 3272 | 	struct conexant_spec *spec = codec->spec; | 
 | 3273 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
 | 3274 | 	hda_nid_t dacs[MAX_AUTO_DACS]; | 
 | 3275 | 	int i, j, nums, rest; | 
 | 3276 |  | 
 | 3277 | 	rest = fill_cx_auto_dacs(codec, dacs); | 
 | 3278 | 	/* parse all analog output pins */ | 
 | 3279 | 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, | 
| David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 3280 | 			  dacs, &rest, spec->dac_info, 0, | 
 | 3281 | 			  AUTO_PIN_LINE_OUT); | 
 | 3282 | 	nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, | 
 | 3283 | 			  dacs, &rest, spec->dac_info, nums, | 
 | 3284 | 			  AUTO_PIN_HP_OUT); | 
 | 3285 | 	nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, | 
 | 3286 | 			  dacs, &rest, spec->dac_info, nums, | 
 | 3287 | 			  AUTO_PIN_SPEAKER_OUT); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3288 | 	spec->dac_info_filled = nums; | 
 | 3289 | 	/* fill multiout struct */ | 
 | 3290 | 	for (i = 0; i < nums; i++) { | 
 | 3291 | 		hda_nid_t dac = spec->dac_info[i].dac; | 
| Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 3292 | 		if (!dac || (dac & DAC_SLAVE_FLAG)) | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3293 | 			continue; | 
 | 3294 | 		switch (spec->dac_info[i].type) { | 
 | 3295 | 		case AUTO_PIN_LINE_OUT: | 
 | 3296 | 			spec->private_dac_nids[spec->multiout.num_dacs] = dac; | 
 | 3297 | 			spec->multiout.num_dacs++; | 
 | 3298 | 			break; | 
 | 3299 | 		case AUTO_PIN_HP_OUT: | 
 | 3300 | 		case AUTO_PIN_SPEAKER_OUT: | 
 | 3301 | 			if (!spec->multiout.hp_nid) { | 
 | 3302 | 				spec->multiout.hp_nid = dac; | 
 | 3303 | 				break; | 
 | 3304 | 			} | 
 | 3305 | 			for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) | 
 | 3306 | 				if (!spec->multiout.extra_out_nid[j]) { | 
 | 3307 | 					spec->multiout.extra_out_nid[j] = dac; | 
 | 3308 | 					break; | 
 | 3309 | 				} | 
 | 3310 | 			break; | 
 | 3311 | 		} | 
 | 3312 | 	} | 
 | 3313 | 	spec->multiout.dac_nids = spec->private_dac_nids; | 
| David Henningsson | 8972495 | 2011-02-16 21:34:04 +0100 | [diff] [blame] | 3314 | 	spec->multiout.max_channels = spec->multiout.num_dacs * 2; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3315 |  | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3316 | 	for (i = 0; i < cfg->hp_outs; i++) { | 
 | 3317 | 		if (is_jack_detectable(codec, cfg->hp_pins[i])) { | 
 | 3318 | 			spec->auto_mute = 1; | 
 | 3319 | 			break; | 
 | 3320 | 		} | 
 | 3321 | 	} | 
| Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3322 | 	if (spec->auto_mute && | 
 | 3323 | 	    cfg->line_out_pins[0] && | 
 | 3324 | 	    cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3325 | 	    cfg->line_out_pins[0] != cfg->hp_pins[0] && | 
 | 3326 | 	    cfg->line_out_pins[0] != cfg->speaker_pins[0]) { | 
 | 3327 | 		for (i = 0; i < cfg->line_outs; i++) { | 
 | 3328 | 			if (is_jack_detectable(codec, cfg->line_out_pins[i])) { | 
 | 3329 | 				spec->detect_line = 1; | 
 | 3330 | 				break; | 
 | 3331 | 			} | 
 | 3332 | 		} | 
 | 3333 | 		spec->automute_lines = spec->detect_line; | 
 | 3334 | 	} | 
 | 3335 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3336 | 	spec->vmaster_nid = spec->private_dac_nids[0]; | 
 | 3337 | } | 
 | 3338 |  | 
| Takashi Iwai | da33986 | 2011-05-13 16:24:15 +0200 | [diff] [blame] | 3339 | static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, | 
 | 3340 | 			      hda_nid_t *pins, bool on); | 
 | 3341 |  | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3342 | static void do_automute(struct hda_codec *codec, int num_pins, | 
 | 3343 | 			hda_nid_t *pins, bool on) | 
 | 3344 | { | 
| Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3345 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3346 | 	int i; | 
 | 3347 | 	for (i = 0; i < num_pins; i++) | 
 | 3348 | 		snd_hda_codec_write(codec, pins[i], 0, | 
 | 3349 | 				    AC_VERB_SET_PIN_WIDGET_CONTROL, | 
 | 3350 | 				    on ? PIN_OUT : 0); | 
| Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3351 | 	if (spec->pin_eapd_ctrls) | 
 | 3352 | 		cx_auto_turn_eapd(codec, num_pins, pins, on); | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3353 | } | 
 | 3354 |  | 
 | 3355 | static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) | 
 | 3356 | { | 
 | 3357 | 	int i, present = 0; | 
 | 3358 |  | 
 | 3359 | 	for (i = 0; i < num_pins; i++) { | 
 | 3360 | 		hda_nid_t nid = pins[i]; | 
 | 3361 | 		if (!nid || !is_jack_detectable(codec, nid)) | 
 | 3362 | 			break; | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3363 | 		present |= snd_hda_jack_detect(codec, nid); | 
 | 3364 | 	} | 
 | 3365 | 	return present; | 
 | 3366 | } | 
 | 3367 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3368 | /* auto-mute/unmute speaker and line outs according to headphone jack */ | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3369 | static void cx_auto_update_speakers(struct hda_codec *codec) | 
 | 3370 | { | 
 | 3371 | 	struct conexant_spec *spec = codec->spec; | 
 | 3372 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
| Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3373 | 	int on = 1; | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3374 |  | 
| Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3375 | 	/* turn on HP EAPD when HP jacks are present */ | 
| Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3376 | 	if (spec->pin_eapd_ctrls) { | 
 | 3377 | 		if (spec->auto_mute) | 
 | 3378 | 			on = spec->hp_present; | 
 | 3379 | 		cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); | 
 | 3380 | 	} | 
 | 3381 |  | 
| Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3382 | 	/* mute speakers in auto-mode if HP or LO jacks are plugged */ | 
 | 3383 | 	if (spec->auto_mute) | 
 | 3384 | 		on = !(spec->hp_present || | 
 | 3385 | 		       (spec->detect_line && spec->line_present)); | 
 | 3386 | 	do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3387 |  | 
 | 3388 | 	/* toggle line-out mutes if needed, too */ | 
 | 3389 | 	/* if LO is a copy of either HP or Speaker, don't need to handle it */ | 
 | 3390 | 	if (cfg->line_out_pins[0] == cfg->hp_pins[0] || | 
 | 3391 | 	    cfg->line_out_pins[0] == cfg->speaker_pins[0]) | 
 | 3392 | 		return; | 
| Takashi Iwai | e2df82f | 2011-05-24 11:49:12 +0200 | [diff] [blame] | 3393 | 	if (spec->auto_mute) { | 
 | 3394 | 		/* mute LO in auto-mode when HP jack is present */ | 
 | 3395 | 		if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || | 
 | 3396 | 		    spec->automute_lines) | 
 | 3397 | 			on = !spec->hp_present; | 
 | 3398 | 		else | 
 | 3399 | 			on = 1; | 
 | 3400 | 	} | 
 | 3401 | 	do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3402 | } | 
 | 3403 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3404 | static void cx_auto_hp_automute(struct hda_codec *codec) | 
 | 3405 | { | 
 | 3406 | 	struct conexant_spec *spec = codec->spec; | 
 | 3407 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3408 |  | 
 | 3409 | 	if (!spec->auto_mute) | 
 | 3410 | 		return; | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3411 | 	spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); | 
 | 3412 | 	cx_auto_update_speakers(codec); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3413 | } | 
 | 3414 |  | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3415 | static void cx_auto_line_automute(struct hda_codec *codec) | 
 | 3416 | { | 
 | 3417 | 	struct conexant_spec *spec = codec->spec; | 
 | 3418 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
 | 3419 |  | 
 | 3420 | 	if (!spec->auto_mute || !spec->detect_line) | 
 | 3421 | 		return; | 
 | 3422 | 	spec->line_present = detect_jacks(codec, cfg->line_outs, | 
 | 3423 | 					  cfg->line_out_pins); | 
 | 3424 | 	cx_auto_update_speakers(codec); | 
 | 3425 | } | 
 | 3426 |  | 
 | 3427 | static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, | 
 | 3428 | 				 struct snd_ctl_elem_info *uinfo) | 
 | 3429 | { | 
 | 3430 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 3431 | 	struct conexant_spec *spec = codec->spec; | 
 | 3432 | 	static const char * const texts2[] = { | 
 | 3433 | 		"Disabled", "Enabled" | 
 | 3434 | 	}; | 
 | 3435 | 	static const char * const texts3[] = { | 
| Takashi Iwai | e49a343 | 2012-03-01 18:14:41 +0100 | [diff] [blame] | 3436 | 		"Disabled", "Speaker Only", "Line Out+Speaker" | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3437 | 	}; | 
 | 3438 | 	const char * const *texts; | 
 | 3439 |  | 
 | 3440 | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | 
 | 3441 | 	uinfo->count = 1; | 
 | 3442 | 	if (spec->automute_hp_lo) { | 
 | 3443 | 		uinfo->value.enumerated.items = 3; | 
 | 3444 | 		texts = texts3; | 
 | 3445 | 	} else { | 
 | 3446 | 		uinfo->value.enumerated.items = 2; | 
 | 3447 | 		texts = texts2; | 
 | 3448 | 	} | 
 | 3449 | 	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | 
 | 3450 | 		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; | 
 | 3451 | 	strcpy(uinfo->value.enumerated.name, | 
 | 3452 | 	       texts[uinfo->value.enumerated.item]); | 
 | 3453 | 	return 0; | 
 | 3454 | } | 
 | 3455 |  | 
 | 3456 | static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, | 
 | 3457 | 				struct snd_ctl_elem_value *ucontrol) | 
 | 3458 | { | 
 | 3459 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 3460 | 	struct conexant_spec *spec = codec->spec; | 
 | 3461 | 	unsigned int val; | 
 | 3462 | 	if (!spec->auto_mute) | 
 | 3463 | 		val = 0; | 
 | 3464 | 	else if (!spec->automute_lines) | 
 | 3465 | 		val = 1; | 
 | 3466 | 	else | 
 | 3467 | 		val = 2; | 
 | 3468 | 	ucontrol->value.enumerated.item[0] = val; | 
 | 3469 | 	return 0; | 
 | 3470 | } | 
 | 3471 |  | 
 | 3472 | static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, | 
 | 3473 | 				struct snd_ctl_elem_value *ucontrol) | 
 | 3474 | { | 
 | 3475 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 3476 | 	struct conexant_spec *spec = codec->spec; | 
 | 3477 |  | 
 | 3478 | 	switch (ucontrol->value.enumerated.item[0]) { | 
 | 3479 | 	case 0: | 
 | 3480 | 		if (!spec->auto_mute) | 
 | 3481 | 			return 0; | 
 | 3482 | 		spec->auto_mute = 0; | 
 | 3483 | 		break; | 
 | 3484 | 	case 1: | 
 | 3485 | 		if (spec->auto_mute && !spec->automute_lines) | 
 | 3486 | 			return 0; | 
 | 3487 | 		spec->auto_mute = 1; | 
 | 3488 | 		spec->automute_lines = 0; | 
 | 3489 | 		break; | 
 | 3490 | 	case 2: | 
 | 3491 | 		if (!spec->automute_hp_lo) | 
 | 3492 | 			return -EINVAL; | 
 | 3493 | 		if (spec->auto_mute && spec->automute_lines) | 
 | 3494 | 			return 0; | 
 | 3495 | 		spec->auto_mute = 1; | 
 | 3496 | 		spec->automute_lines = 1; | 
 | 3497 | 		break; | 
 | 3498 | 	default: | 
 | 3499 | 		return -EINVAL; | 
 | 3500 | 	} | 
 | 3501 | 	cx_auto_update_speakers(codec); | 
 | 3502 | 	return 1; | 
 | 3503 | } | 
 | 3504 |  | 
 | 3505 | static const struct snd_kcontrol_new cx_automute_mode_enum[] = { | 
 | 3506 | 	{ | 
 | 3507 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 3508 | 		.name = "Auto-Mute Mode", | 
 | 3509 | 		.info = cx_automute_mode_info, | 
 | 3510 | 		.get = cx_automute_mode_get, | 
 | 3511 | 		.put = cx_automute_mode_put, | 
 | 3512 | 	}, | 
 | 3513 | 	{ } | 
 | 3514 | }; | 
 | 3515 |  | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3516 | static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, | 
 | 3517 | 				 struct snd_ctl_elem_info *uinfo) | 
 | 3518 | { | 
 | 3519 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 3520 | 	struct conexant_spec *spec = codec->spec; | 
 | 3521 |  | 
 | 3522 | 	return snd_hda_input_mux_info(&spec->private_imux, uinfo); | 
 | 3523 | } | 
 | 3524 |  | 
 | 3525 | static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, | 
 | 3526 | 				struct snd_ctl_elem_value *ucontrol) | 
 | 3527 | { | 
 | 3528 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 3529 | 	struct conexant_spec *spec = codec->spec; | 
 | 3530 |  | 
 | 3531 | 	ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; | 
 | 3532 | 	return 0; | 
 | 3533 | } | 
 | 3534 |  | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3535 | /* look for the route the given pin from mux and return the index; | 
 | 3536 |  * if do_select is set, actually select the route. | 
 | 3537 |  */ | 
 | 3538 | static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3539 | 				     hda_nid_t pin, hda_nid_t *srcp, | 
 | 3540 | 				     bool do_select, int depth) | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3541 | { | 
 | 3542 | 	hda_nid_t conn[HDA_MAX_NUM_INPUTS]; | 
 | 3543 | 	int i, nums; | 
 | 3544 |  | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3545 | 	switch (get_wcaps_type(get_wcaps(codec, mux))) { | 
 | 3546 | 	case AC_WID_AUD_IN: | 
 | 3547 | 	case AC_WID_AUD_SEL: | 
 | 3548 | 	case AC_WID_AUD_MIX: | 
 | 3549 | 		break; | 
 | 3550 | 	default: | 
 | 3551 | 		return -1; | 
 | 3552 | 	} | 
 | 3553 |  | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3554 | 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); | 
 | 3555 | 	for (i = 0; i < nums; i++) | 
 | 3556 | 		if (conn[i] == pin) { | 
 | 3557 | 			if (do_select) | 
 | 3558 | 				snd_hda_codec_write(codec, mux, 0, | 
 | 3559 | 						    AC_VERB_SET_CONNECT_SEL, i); | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3560 | 			if (srcp) | 
 | 3561 | 				*srcp = mux; | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3562 | 			return i; | 
 | 3563 | 		} | 
 | 3564 | 	depth++; | 
 | 3565 | 	if (depth == 2) | 
 | 3566 | 		return -1; | 
 | 3567 | 	for (i = 0; i < nums; i++) { | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3568 | 		int ret  = __select_input_connection(codec, conn[i], pin, srcp, | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3569 | 						     do_select, depth); | 
 | 3570 | 		if (ret >= 0) { | 
 | 3571 | 			if (do_select) | 
 | 3572 | 				snd_hda_codec_write(codec, mux, 0, | 
 | 3573 | 						    AC_VERB_SET_CONNECT_SEL, i); | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3574 | 			return i; | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3575 | 		} | 
 | 3576 | 	} | 
 | 3577 | 	return -1; | 
 | 3578 | } | 
 | 3579 |  | 
 | 3580 | static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, | 
 | 3581 | 				   hda_nid_t pin) | 
 | 3582 | { | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3583 | 	__select_input_connection(codec, mux, pin, NULL, true, 0); | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3584 | } | 
 | 3585 |  | 
 | 3586 | static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, | 
 | 3587 | 				hda_nid_t pin) | 
 | 3588 | { | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 3589 | 	return __select_input_connection(codec, mux, pin, NULL, false, 0); | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3590 | } | 
 | 3591 |  | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3592 | static int cx_auto_mux_enum_update(struct hda_codec *codec, | 
 | 3593 | 				   const struct hda_input_mux *imux, | 
 | 3594 | 				   unsigned int idx) | 
 | 3595 | { | 
 | 3596 | 	struct conexant_spec *spec = codec->spec; | 
 | 3597 | 	hda_nid_t adc; | 
| Takashi Iwai | 313d2c0 | 2011-05-23 20:27:02 +0200 | [diff] [blame] | 3598 | 	int changed = 1; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3599 |  | 
 | 3600 | 	if (!imux->num_items) | 
 | 3601 | 		return 0; | 
 | 3602 | 	if (idx >= imux->num_items) | 
 | 3603 | 		idx = imux->num_items - 1; | 
 | 3604 | 	if (spec->cur_mux[0] == idx) | 
| Takashi Iwai | 313d2c0 | 2011-05-23 20:27:02 +0200 | [diff] [blame] | 3605 | 		changed = 0; | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 3606 | 	adc = spec->imux_info[idx].adc; | 
 | 3607 | 	select_input_connection(codec, spec->imux_info[idx].adc, | 
 | 3608 | 				spec->imux_info[idx].pin); | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3609 | 	if (spec->cur_adc && spec->cur_adc != adc) { | 
 | 3610 | 		/* stream is running, let's swap the current ADC */ | 
 | 3611 | 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | 
 | 3612 | 		spec->cur_adc = adc; | 
 | 3613 | 		snd_hda_codec_setup_stream(codec, adc, | 
 | 3614 | 					   spec->cur_adc_stream_tag, 0, | 
 | 3615 | 					   spec->cur_adc_format); | 
 | 3616 | 	} | 
 | 3617 | 	spec->cur_mux[0] = idx; | 
| Takashi Iwai | 313d2c0 | 2011-05-23 20:27:02 +0200 | [diff] [blame] | 3618 | 	return changed; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3619 | } | 
 | 3620 |  | 
 | 3621 | static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, | 
 | 3622 | 				struct snd_ctl_elem_value *ucontrol) | 
 | 3623 | { | 
 | 3624 | 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
 | 3625 | 	struct conexant_spec *spec = codec->spec; | 
 | 3626 |  | 
 | 3627 | 	return cx_auto_mux_enum_update(codec, &spec->private_imux, | 
 | 3628 | 				       ucontrol->value.enumerated.item[0]); | 
 | 3629 | } | 
 | 3630 |  | 
 | 3631 | static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { | 
 | 3632 | 	{ | 
 | 3633 | 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
 | 3634 | 		.name = "Capture Source", | 
 | 3635 | 		.info = cx_auto_mux_enum_info, | 
 | 3636 | 		.get = cx_auto_mux_enum_get, | 
 | 3637 | 		.put = cx_auto_mux_enum_put | 
 | 3638 | 	}, | 
 | 3639 | 	{} | 
 | 3640 | }; | 
 | 3641 |  | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3642 | static bool select_automic(struct hda_codec *codec, int idx, bool detect) | 
 | 3643 | { | 
 | 3644 | 	struct conexant_spec *spec = codec->spec; | 
 | 3645 | 	if (idx < 0) | 
 | 3646 | 		return false; | 
 | 3647 | 	if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) | 
 | 3648 | 		return false; | 
 | 3649 | 	cx_auto_mux_enum_update(codec, &spec->private_imux, idx); | 
 | 3650 | 	return true; | 
 | 3651 | } | 
 | 3652 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3653 | /* automatic switch internal and external mic */ | 
 | 3654 | static void cx_auto_automic(struct hda_codec *codec) | 
 | 3655 | { | 
 | 3656 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3657 |  | 
 | 3658 | 	if (!spec->auto_mic) | 
 | 3659 | 		return; | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3660 | 	if (!select_automic(codec, spec->auto_mic_ext, true)) | 
 | 3661 | 		if (!select_automic(codec, spec->auto_mic_dock, true)) | 
 | 3662 | 			select_automic(codec, spec->auto_mic_int, false); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3663 | } | 
 | 3664 |  | 
 | 3665 | static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) | 
 | 3666 | { | 
| Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 3667 | 	switch (snd_hda_jack_get_action(codec, res >> 26)) { | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3668 | 	case CONEXANT_HP_EVENT: | 
 | 3669 | 		cx_auto_hp_automute(codec); | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3670 | 		break; | 
 | 3671 | 	case CONEXANT_LINE_EVENT: | 
 | 3672 | 		cx_auto_line_automute(codec); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3673 | 		break; | 
 | 3674 | 	case CONEXANT_MIC_EVENT: | 
 | 3675 | 		cx_auto_automic(codec); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3676 | 		break; | 
 | 3677 | 	} | 
| Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 3678 | 	snd_hda_jack_report_sync(codec); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3679 | } | 
 | 3680 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3681 | /* check whether the pin config is suitable for auto-mic switching; | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3682 |  * auto-mic is enabled only when one int-mic and one ext- and/or | 
 | 3683 |  * one dock-mic exist | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3684 |  */ | 
 | 3685 | static void cx_auto_check_auto_mic(struct hda_codec *codec) | 
 | 3686 | { | 
 | 3687 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3688 | 	int pset[INPUT_PIN_ATTR_NORMAL + 1]; | 
 | 3689 | 	int i; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3690 |  | 
| Takashi Iwai | 506a419 | 2011-05-23 20:07:15 +0200 | [diff] [blame] | 3691 | 	for (i = 0; i < ARRAY_SIZE(pset); i++) | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3692 | 		pset[i] = -1; | 
 | 3693 | 	for (i = 0; i < spec->private_imux.num_items; i++) { | 
 | 3694 | 		hda_nid_t pin = spec->imux_info[i].pin; | 
 | 3695 | 		unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); | 
| Takashi Iwai | b55fcb5 | 2011-05-17 12:57:46 +0200 | [diff] [blame] | 3696 | 		int type, attr; | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3697 | 		attr = snd_hda_get_input_pin_attr(def_conf); | 
 | 3698 | 		if (attr == INPUT_PIN_ATTR_UNUSED) | 
| Takashi Iwai | b55fcb5 | 2011-05-17 12:57:46 +0200 | [diff] [blame] | 3699 | 			return; /* invalid entry */ | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3700 | 		if (attr > INPUT_PIN_ATTR_NORMAL) | 
 | 3701 | 			attr = INPUT_PIN_ATTR_NORMAL; | 
 | 3702 | 		if (attr != INPUT_PIN_ATTR_INT && | 
 | 3703 | 		    !is_jack_detectable(codec, pin)) | 
| Takashi Iwai | b55fcb5 | 2011-05-17 12:57:46 +0200 | [diff] [blame] | 3704 | 			return; /* non-detectable pin */ | 
 | 3705 | 		type = get_defcfg_device(def_conf); | 
 | 3706 | 		if (type != AC_JACK_MIC_IN && | 
 | 3707 | 		    (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) | 
 | 3708 | 			return; /* no valid input type */ | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3709 | 		if (pset[attr] >= 0) | 
 | 3710 | 			return; /* already occupied */ | 
 | 3711 | 		pset[attr] = i; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3712 | 	} | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3713 | 	if (pset[INPUT_PIN_ATTR_INT] < 0 || | 
 | 3714 | 	    (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) | 
 | 3715 | 		return; /* no input to switch*/ | 
 | 3716 | 	spec->auto_mic = 1; | 
 | 3717 | 	spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; | 
 | 3718 | 	spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; | 
 | 3719 | 	spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3720 | } | 
 | 3721 |  | 
 | 3722 | static void cx_auto_parse_input(struct hda_codec *codec) | 
 | 3723 | { | 
 | 3724 | 	struct conexant_spec *spec = codec->spec; | 
 | 3725 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
 | 3726 | 	struct hda_input_mux *imux; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3727 | 	int i, j; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3728 |  | 
 | 3729 | 	imux = &spec->private_imux; | 
 | 3730 | 	for (i = 0; i < cfg->num_inputs; i++) { | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3731 | 		for (j = 0; j < spec->num_adc_nids; j++) { | 
 | 3732 | 			hda_nid_t adc = spec->adc_nids[j]; | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 3733 | 			int idx = get_input_connection(codec, adc, | 
 | 3734 | 						       cfg->inputs[i].pin); | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3735 | 			if (idx >= 0) { | 
 | 3736 | 				const char *label; | 
 | 3737 | 				label = hda_get_autocfg_input_label(codec, cfg, i); | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 3738 | 				spec->imux_info[imux->num_items].index = i; | 
 | 3739 | 				spec->imux_info[imux->num_items].boost = 0; | 
 | 3740 | 				spec->imux_info[imux->num_items].adc = adc; | 
 | 3741 | 				spec->imux_info[imux->num_items].pin = | 
| Takashi Iwai | f6100bb | 2011-05-13 18:26:39 +0200 | [diff] [blame] | 3742 | 					cfg->inputs[i].pin; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3743 | 				snd_hda_add_imux_item(imux, label, idx, NULL); | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3744 | 				break; | 
 | 3745 | 			} | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3746 | 		} | 
 | 3747 | 	} | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 3748 | 	if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3749 | 		cx_auto_check_auto_mic(codec); | 
| Takashi Iwai | 7675535 | 2011-08-24 10:53:10 +0200 | [diff] [blame] | 3750 | 	if (imux->num_items > 1) { | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3751 | 		for (i = 1; i < imux->num_items; i++) { | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 3752 | 			if (spec->imux_info[i].adc != spec->imux_info[0].adc) { | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 3753 | 				spec->adc_switching = 1; | 
 | 3754 | 				break; | 
 | 3755 | 			} | 
 | 3756 | 		} | 
 | 3757 | 	} | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3758 | } | 
 | 3759 |  | 
 | 3760 | /* get digital-input audio widget corresponding to the given pin */ | 
 | 3761 | static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) | 
 | 3762 | { | 
 | 3763 | 	hda_nid_t nid, end_nid; | 
 | 3764 |  | 
 | 3765 | 	end_nid = codec->start_nid + codec->num_nodes; | 
 | 3766 | 	for (nid = codec->start_nid; nid < end_nid; nid++) { | 
 | 3767 | 		unsigned int wcaps = get_wcaps(codec, nid); | 
 | 3768 | 		unsigned int type = get_wcaps_type(wcaps); | 
 | 3769 | 		if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { | 
 | 3770 | 			if (get_connection_index(codec, nid, pin) >= 0) | 
 | 3771 | 				return nid; | 
 | 3772 | 		} | 
 | 3773 | 	} | 
 | 3774 | 	return 0; | 
 | 3775 | } | 
 | 3776 |  | 
 | 3777 | static void cx_auto_parse_digital(struct hda_codec *codec) | 
 | 3778 | { | 
 | 3779 | 	struct conexant_spec *spec = codec->spec; | 
 | 3780 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
 | 3781 | 	hda_nid_t nid; | 
 | 3782 |  | 
 | 3783 | 	if (cfg->dig_outs && | 
 | 3784 | 	    snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) | 
 | 3785 | 		spec->multiout.dig_out_nid = nid; | 
 | 3786 | 	if (cfg->dig_in_pin) | 
 | 3787 | 		spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); | 
 | 3788 | } | 
 | 3789 |  | 
 | 3790 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | 
 | 3791 | static void cx_auto_parse_beep(struct hda_codec *codec) | 
 | 3792 | { | 
 | 3793 | 	struct conexant_spec *spec = codec->spec; | 
 | 3794 | 	hda_nid_t nid, end_nid; | 
 | 3795 |  | 
 | 3796 | 	end_nid = codec->start_nid + codec->num_nodes; | 
 | 3797 | 	for (nid = codec->start_nid; nid < end_nid; nid++) | 
 | 3798 | 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { | 
 | 3799 | 			set_beep_amp(spec, nid, 0, HDA_OUTPUT); | 
 | 3800 | 			break; | 
 | 3801 | 		} | 
 | 3802 | } | 
 | 3803 | #else | 
 | 3804 | #define cx_auto_parse_beep(codec) | 
 | 3805 | #endif | 
 | 3806 |  | 
| Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3807 | /* parse EAPDs */ | 
| Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3808 | static void cx_auto_parse_eapd(struct hda_codec *codec) | 
 | 3809 | { | 
 | 3810 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3811 | 	hda_nid_t nid, end_nid; | 
 | 3812 |  | 
 | 3813 | 	end_nid = codec->start_nid + codec->num_nodes; | 
 | 3814 | 	for (nid = codec->start_nid; nid < end_nid; nid++) { | 
 | 3815 | 		if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) | 
 | 3816 | 			continue; | 
 | 3817 | 		if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) | 
 | 3818 | 			continue; | 
| Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3819 | 		spec->eapds[spec->num_eapds++] = nid; | 
 | 3820 | 		if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) | 
 | 3821 | 			break; | 
 | 3822 | 	} | 
| Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3823 |  | 
 | 3824 | 	/* NOTE: below is a wild guess; if we have more than two EAPDs, | 
 | 3825 | 	 * it's a new chip, where EAPDs are supposed to be associated to | 
 | 3826 | 	 * pins, and we can control EAPD per pin. | 
 | 3827 | 	 * OTOH, if only one or two EAPDs are found, it's an old chip, | 
 | 3828 | 	 * thus it might control over all pins. | 
 | 3829 | 	 */ | 
 | 3830 | 	spec->pin_eapd_ctrls = spec->num_eapds > 2; | 
| Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3831 | } | 
 | 3832 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3833 | static int cx_auto_parse_auto_config(struct hda_codec *codec) | 
 | 3834 | { | 
 | 3835 | 	struct conexant_spec *spec = codec->spec; | 
 | 3836 | 	int err; | 
 | 3837 |  | 
 | 3838 | 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | 
 | 3839 | 	if (err < 0) | 
 | 3840 | 		return err; | 
 | 3841 |  | 
 | 3842 | 	cx_auto_parse_output(codec); | 
 | 3843 | 	cx_auto_parse_input(codec); | 
 | 3844 | 	cx_auto_parse_digital(codec); | 
 | 3845 | 	cx_auto_parse_beep(codec); | 
| Takashi Iwai | 1911059 | 2011-07-11 14:46:44 +0200 | [diff] [blame] | 3846 | 	cx_auto_parse_eapd(codec); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3847 | 	return 0; | 
 | 3848 | } | 
 | 3849 |  | 
| Takashi Iwai | da33986 | 2011-05-13 16:24:15 +0200 | [diff] [blame] | 3850 | static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, | 
 | 3851 | 			      hda_nid_t *pins, bool on) | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3852 | { | 
 | 3853 | 	int i; | 
 | 3854 | 	for (i = 0; i < num_pins; i++) { | 
 | 3855 | 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) | 
 | 3856 | 			snd_hda_codec_write(codec, pins[i], 0, | 
| Takashi Iwai | da33986 | 2011-05-13 16:24:15 +0200 | [diff] [blame] | 3857 | 					    AC_VERB_SET_EAPD_BTLENABLE, | 
 | 3858 | 					    on ? 0x02 : 0); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3859 | 	} | 
 | 3860 | } | 
 | 3861 |  | 
 | 3862 | static void select_connection(struct hda_codec *codec, hda_nid_t pin, | 
 | 3863 | 			      hda_nid_t src) | 
 | 3864 | { | 
 | 3865 | 	int idx = get_connection_index(codec, pin, src); | 
 | 3866 | 	if (idx >= 0) | 
 | 3867 | 		snd_hda_codec_write(codec, pin, 0, | 
 | 3868 | 				    AC_VERB_SET_CONNECT_SEL, idx); | 
 | 3869 | } | 
 | 3870 |  | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3871 | static void mute_outputs(struct hda_codec *codec, int num_nids, | 
 | 3872 | 			 const hda_nid_t *nids) | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3873 | { | 
| Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 3874 | 	int i, val; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3875 |  | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3876 | 	for (i = 0; i < num_nids; i++) { | 
 | 3877 | 		hda_nid_t nid = nids[i]; | 
 | 3878 | 		if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) | 
 | 3879 | 			continue; | 
| Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 3880 | 		if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) | 
 | 3881 | 			val = AMP_OUT_MUTE; | 
 | 3882 | 		else | 
 | 3883 | 			val = AMP_OUT_ZERO; | 
 | 3884 | 		snd_hda_codec_write(codec, nid, 0, | 
 | 3885 | 				    AC_VERB_SET_AMP_GAIN_MUTE, val); | 
 | 3886 | 	} | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3887 | } | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3888 |  | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3889 | static void enable_unsol_pins(struct hda_codec *codec, int num_pins, | 
| Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 3890 | 			      hda_nid_t *pins, unsigned int action) | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3891 | { | 
 | 3892 | 	int i; | 
 | 3893 | 	for (i = 0; i < num_pins; i++) | 
| Takashi Iwai | 3a93897 | 2011-10-28 01:16:55 +0200 | [diff] [blame] | 3894 | 		snd_hda_jack_detect_enable(codec, pins[i], action); | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3895 | } | 
 | 3896 |  | 
| Takashi Iwai | 07cafff | 2012-02-20 12:30:59 +0100 | [diff] [blame] | 3897 | static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) | 
 | 3898 | { | 
 | 3899 | 	int i; | 
 | 3900 | 	for (i = 0; i < nums; i++) | 
 | 3901 | 		if (list[i] == nid) | 
 | 3902 | 			return true; | 
 | 3903 | 	return false; | 
 | 3904 | } | 
 | 3905 |  | 
 | 3906 | /* is the given NID found in any of autocfg items? */ | 
 | 3907 | static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid) | 
 | 3908 | { | 
 | 3909 | 	int i; | 
 | 3910 |  | 
 | 3911 | 	if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) || | 
 | 3912 | 	    found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) || | 
 | 3913 | 	    found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) || | 
 | 3914 | 	    found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs)) | 
 | 3915 | 		return true; | 
 | 3916 | 	for (i = 0; i < cfg->num_inputs; i++) | 
 | 3917 | 		if (cfg->inputs[i].pin == nid) | 
 | 3918 | 			return true; | 
 | 3919 | 	if (cfg->dig_in_pin == nid) | 
 | 3920 | 		return true; | 
 | 3921 | 	return false; | 
 | 3922 | } | 
 | 3923 |  | 
 | 3924 | /* clear unsol-event tags on unused pins; Conexant codecs seem to leave | 
 | 3925 |  * invalid unsol tags by some reason | 
 | 3926 |  */ | 
 | 3927 | static void clear_unsol_on_unused_pins(struct hda_codec *codec) | 
 | 3928 | { | 
 | 3929 | 	struct conexant_spec *spec = codec->spec; | 
 | 3930 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
 | 3931 | 	int i; | 
 | 3932 |  | 
 | 3933 | 	for (i = 0; i < codec->init_pins.used; i++) { | 
 | 3934 | 		struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); | 
 | 3935 | 		if (!found_in_autocfg(cfg, pin->nid)) | 
 | 3936 | 			snd_hda_codec_write(codec, pin->nid, 0, | 
 | 3937 | 					    AC_VERB_SET_UNSOLICITED_ENABLE, 0); | 
 | 3938 | 	} | 
 | 3939 | } | 
 | 3940 |  | 
| Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 3941 | /* turn on/off EAPD according to Master switch */ | 
 | 3942 | static void cx_auto_vmaster_hook(void *private_data, int enabled) | 
 | 3943 | { | 
 | 3944 | 	struct hda_codec *codec = private_data; | 
 | 3945 | 	struct conexant_spec *spec = codec->spec; | 
 | 3946 |  | 
 | 3947 | 	if (enabled && spec->pin_eapd_ctrls) { | 
 | 3948 | 		cx_auto_update_speakers(codec); | 
 | 3949 | 		return; | 
 | 3950 | 	} | 
 | 3951 | 	cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); | 
 | 3952 | } | 
 | 3953 |  | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3954 | static void cx_auto_init_output(struct hda_codec *codec) | 
 | 3955 | { | 
 | 3956 | 	struct conexant_spec *spec = codec->spec; | 
 | 3957 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
 | 3958 | 	hda_nid_t nid; | 
 | 3959 | 	int i; | 
 | 3960 |  | 
 | 3961 | 	mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); | 
| Takashi Iwai | ca3649d | 2012-04-19 15:15:25 +0200 | [diff] [blame] | 3962 | 	for (i = 0; i < cfg->hp_outs; i++) { | 
 | 3963 | 		unsigned int val = PIN_OUT; | 
 | 3964 | 		if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & | 
 | 3965 | 		    AC_PINCAP_HP_DRV) | 
 | 3966 | 			val |= AC_PINCTL_HP_EN; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3967 | 		snd_hda_codec_write(codec, cfg->hp_pins[i], 0, | 
| Takashi Iwai | ca3649d | 2012-04-19 15:15:25 +0200 | [diff] [blame] | 3968 | 				    AC_VERB_SET_PIN_WIDGET_CONTROL, val); | 
 | 3969 | 	} | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 3970 | 	mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); | 
 | 3971 | 	mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); | 
 | 3972 | 	mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3973 | 	for (i = 0; i < spec->dac_info_filled; i++) { | 
 | 3974 | 		nid = spec->dac_info[i].dac; | 
 | 3975 | 		if (!nid) | 
 | 3976 | 			nid = spec->multiout.dac_nids[0]; | 
| Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 3977 | 		else if (nid & DAC_SLAVE_FLAG) | 
 | 3978 | 			nid &= ~DAC_SLAVE_FLAG; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 3979 | 		select_connection(codec, spec->dac_info[i].pin, nid); | 
 | 3980 | 	} | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 3981 | 	if (spec->auto_mute) { | 
 | 3982 | 		enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, | 
 | 3983 | 				  CONEXANT_HP_EVENT); | 
 | 3984 | 		spec->hp_present = detect_jacks(codec, cfg->hp_outs, | 
 | 3985 | 						cfg->hp_pins); | 
 | 3986 | 		if (spec->detect_line) { | 
 | 3987 | 			enable_unsol_pins(codec, cfg->line_outs, | 
 | 3988 | 					  cfg->line_out_pins, | 
 | 3989 | 					  CONEXANT_LINE_EVENT); | 
 | 3990 | 			spec->line_present = | 
 | 3991 | 				detect_jacks(codec, cfg->line_outs, | 
 | 3992 | 					     cfg->line_out_pins); | 
 | 3993 | 		} | 
 | 3994 | 	} | 
 | 3995 | 	cx_auto_update_speakers(codec); | 
| Takashi Iwai | 254f296 | 2011-10-14 15:22:34 +0200 | [diff] [blame] | 3996 | 	/* turn on all EAPDs if no individual EAPD control is available */ | 
 | 3997 | 	if (!spec->pin_eapd_ctrls) | 
 | 3998 | 		cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); | 
| Takashi Iwai | 07cafff | 2012-02-20 12:30:59 +0100 | [diff] [blame] | 3999 | 	clear_unsol_on_unused_pins(codec); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4000 | } | 
 | 4001 |  | 
 | 4002 | static void cx_auto_init_input(struct hda_codec *codec) | 
 | 4003 | { | 
 | 4004 | 	struct conexant_spec *spec = codec->spec; | 
 | 4005 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
| Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 4006 | 	int i, val; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4007 |  | 
| Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 4008 | 	for (i = 0; i < spec->num_adc_nids; i++) { | 
 | 4009 | 		hda_nid_t nid = spec->adc_nids[i]; | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4010 | 		if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) | 
 | 4011 | 			continue; | 
| Takashi Iwai | 0ad1b5b | 2011-05-13 16:43:12 +0200 | [diff] [blame] | 4012 | 		if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) | 
 | 4013 | 			val = AMP_IN_MUTE(0); | 
 | 4014 | 		else | 
 | 4015 | 			val = AMP_IN_UNMUTE(0); | 
 | 4016 | 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | 
 | 4017 | 				    val); | 
 | 4018 | 	} | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4019 |  | 
 | 4020 | 	for (i = 0; i < cfg->num_inputs; i++) { | 
 | 4021 | 		unsigned int type; | 
 | 4022 | 		if (cfg->inputs[i].type == AUTO_PIN_MIC) | 
 | 4023 | 			type = PIN_VREF80; | 
 | 4024 | 		else | 
 | 4025 | 			type = PIN_IN; | 
 | 4026 | 		snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, | 
 | 4027 | 				    AC_VERB_SET_PIN_WIDGET_CONTROL, type); | 
 | 4028 | 	} | 
 | 4029 |  | 
 | 4030 | 	if (spec->auto_mic) { | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 4031 | 		if (spec->auto_mic_ext >= 0) { | 
| Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 4032 | 			snd_hda_jack_detect_enable(codec, | 
 | 4033 | 				cfg->inputs[spec->auto_mic_ext].pin, | 
 | 4034 | 				CONEXANT_MIC_EVENT); | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 4035 | 		} | 
 | 4036 | 		if (spec->auto_mic_dock >= 0) { | 
| Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 4037 | 			snd_hda_jack_detect_enable(codec, | 
 | 4038 | 				cfg->inputs[spec->auto_mic_dock].pin, | 
 | 4039 | 				CONEXANT_MIC_EVENT); | 
| Takashi Iwai | 43c1b2e | 2011-05-17 10:35:15 +0200 | [diff] [blame] | 4040 | 		} | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4041 | 		cx_auto_automic(codec); | 
 | 4042 | 	} else { | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4043 | 		select_input_connection(codec, spec->imux_info[0].adc, | 
 | 4044 | 					spec->imux_info[0].pin); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4045 | 	} | 
 | 4046 | } | 
 | 4047 |  | 
 | 4048 | static void cx_auto_init_digital(struct hda_codec *codec) | 
 | 4049 | { | 
 | 4050 | 	struct conexant_spec *spec = codec->spec; | 
 | 4051 | 	struct auto_pin_cfg *cfg = &spec->autocfg; | 
 | 4052 |  | 
 | 4053 | 	if (spec->multiout.dig_out_nid) | 
 | 4054 | 		snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, | 
 | 4055 | 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | 
 | 4056 | 	if (spec->dig_in_nid) | 
 | 4057 | 		snd_hda_codec_write(codec, cfg->dig_in_pin, 0, | 
 | 4058 | 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); | 
 | 4059 | } | 
 | 4060 |  | 
 | 4061 | static int cx_auto_init(struct hda_codec *codec) | 
 | 4062 | { | 
| Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 4063 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4064 | 	/*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ | 
 | 4065 | 	cx_auto_init_output(codec); | 
 | 4066 | 	cx_auto_init_input(codec); | 
 | 4067 | 	cx_auto_init_digital(codec); | 
| Takashi Iwai | 01a61e1 | 2011-10-28 00:03:22 +0200 | [diff] [blame] | 4068 | 	snd_hda_jack_report_sync(codec); | 
| Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 4069 | 	snd_hda_sync_vmaster_hook(&spec->vmaster_mute); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4070 | 	return 0; | 
 | 4071 | } | 
 | 4072 |  | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4073 | static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4074 | 			      const char *dir, int cidx, | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4075 | 			      hda_nid_t nid, int hda_dir, int amp_idx, int chs) | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4076 | { | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4077 | 	static char name[44]; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4078 | 	static struct snd_kcontrol_new knew[] = { | 
 | 4079 | 		HDA_CODEC_VOLUME(name, 0, 0, 0), | 
 | 4080 | 		HDA_CODEC_MUTE(name, 0, 0, 0), | 
 | 4081 | 	}; | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 4082 | 	static const char * const sfx[2] = { "Volume", "Switch" }; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4083 | 	int i, err; | 
 | 4084 |  | 
 | 4085 | 	for (i = 0; i < 2; i++) { | 
 | 4086 | 		struct snd_kcontrol *kctl; | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4087 | 		knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx, | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4088 | 							    hda_dir); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4089 | 		knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; | 
 | 4090 | 		knew[i].index = cidx; | 
 | 4091 | 		snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); | 
 | 4092 | 		kctl = snd_ctl_new1(&knew[i], codec); | 
 | 4093 | 		if (!kctl) | 
 | 4094 | 			return -ENOMEM; | 
 | 4095 | 		err = snd_hda_ctl_add(codec, nid, kctl); | 
 | 4096 | 		if (err < 0) | 
 | 4097 | 			return err; | 
| Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 4098 | 		if (!(query_amp_caps(codec, nid, hda_dir) & | 
 | 4099 | 		      (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))) | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4100 | 			break; | 
 | 4101 | 	} | 
 | 4102 | 	return 0; | 
 | 4103 | } | 
 | 4104 |  | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4105 | #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir)		\ | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4106 | 	cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3) | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4107 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4108 | #define cx_auto_add_pb_volume(codec, nid, str, idx)			\ | 
 | 4109 | 	cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) | 
 | 4110 |  | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4111 | static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, | 
 | 4112 | 			     hda_nid_t pin, const char *name, int idx) | 
 | 4113 | { | 
 | 4114 | 	unsigned int caps; | 
| David Henningsson | 468c545 | 2011-08-25 13:16:02 +0200 | [diff] [blame] | 4115 | 	if (dac && !(dac & DAC_SLAVE_FLAG)) { | 
 | 4116 | 		caps = query_amp_caps(codec, dac, HDA_OUTPUT); | 
 | 4117 | 		if (caps & AC_AMPCAP_NUM_STEPS) | 
 | 4118 | 			return cx_auto_add_pb_volume(codec, dac, name, idx); | 
 | 4119 | 	} | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4120 | 	caps = query_amp_caps(codec, pin, HDA_OUTPUT); | 
 | 4121 | 	if (caps & AC_AMPCAP_NUM_STEPS) | 
 | 4122 | 		return cx_auto_add_pb_volume(codec, pin, name, idx); | 
 | 4123 | 	return 0; | 
 | 4124 | } | 
 | 4125 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4126 | static int cx_auto_build_output_controls(struct hda_codec *codec) | 
 | 4127 | { | 
 | 4128 | 	struct conexant_spec *spec = codec->spec; | 
 | 4129 | 	int i, err; | 
 | 4130 | 	int num_line = 0, num_hp = 0, num_spk = 0; | 
| Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 4131 | 	static const char * const texts[3] = { "Front", "Surround", "CLFE" }; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4132 |  | 
 | 4133 | 	if (spec->dac_info_filled == 1) | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4134 | 		return try_add_pb_volume(codec, spec->dac_info[0].dac, | 
 | 4135 | 					 spec->dac_info[0].pin, | 
 | 4136 | 					 "Master", 0); | 
 | 4137 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4138 | 	for (i = 0; i < spec->dac_info_filled; i++) { | 
 | 4139 | 		const char *label; | 
 | 4140 | 		int idx, type; | 
| Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 4141 | 		hda_nid_t dac = spec->dac_info[i].dac; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4142 | 		type = spec->dac_info[i].type; | 
 | 4143 | 		if (type == AUTO_PIN_LINE_OUT) | 
 | 4144 | 			type = spec->autocfg.line_out_type; | 
 | 4145 | 		switch (type) { | 
 | 4146 | 		case AUTO_PIN_LINE_OUT: | 
 | 4147 | 		default: | 
 | 4148 | 			label = texts[num_line++]; | 
 | 4149 | 			idx = 0; | 
 | 4150 | 			break; | 
 | 4151 | 		case AUTO_PIN_HP_OUT: | 
 | 4152 | 			label = "Headphone"; | 
 | 4153 | 			idx = num_hp++; | 
 | 4154 | 			break; | 
 | 4155 | 		case AUTO_PIN_SPEAKER_OUT: | 
 | 4156 | 			label = "Speaker"; | 
 | 4157 | 			idx = num_spk++; | 
 | 4158 | 			break; | 
 | 4159 | 		} | 
| Takashi Iwai | 1f015f5 | 2011-08-23 14:57:08 +0200 | [diff] [blame] | 4160 | 		err = try_add_pb_volume(codec, dac, | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4161 | 					spec->dac_info[i].pin, | 
 | 4162 | 					label, idx); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4163 | 		if (err < 0) | 
 | 4164 | 			return err; | 
 | 4165 | 	} | 
| Takashi Iwai | 03697e2 | 2011-05-17 09:53:31 +0200 | [diff] [blame] | 4166 |  | 
 | 4167 | 	if (spec->auto_mute) { | 
 | 4168 | 		err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); | 
 | 4169 | 		if (err < 0) | 
 | 4170 | 			return err; | 
 | 4171 | 	} | 
 | 4172 | 	 | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4173 | 	return 0; | 
 | 4174 | } | 
 | 4175 |  | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4176 | /* Returns zero if this is a normal stereo channel, and non-zero if it should | 
 | 4177 |    be split in two independent channels. | 
 | 4178 |    dest_label must be at least 44 characters. */ | 
 | 4179 | static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label, | 
 | 4180 | 				     char *dest_label, int nid) | 
 | 4181 | { | 
 | 4182 | 	struct conexant_spec *spec = codec->spec; | 
 | 4183 | 	int i; | 
 | 4184 |  | 
 | 4185 | 	if (!spec->fixup_stereo_dmic) | 
 | 4186 | 		return 0; | 
 | 4187 |  | 
 | 4188 | 	for (i = 0; i < AUTO_CFG_MAX_INS; i++) { | 
 | 4189 | 		int def_conf; | 
 | 4190 | 		if (spec->autocfg.inputs[i].pin != nid) | 
 | 4191 | 			continue; | 
 | 4192 |  | 
 | 4193 | 		if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC) | 
 | 4194 | 			return 0; | 
 | 4195 | 		def_conf = snd_hda_codec_get_pincfg(codec, nid); | 
 | 4196 | 		if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) | 
 | 4197 | 			return 0; | 
 | 4198 |  | 
 | 4199 | 		/* Finally found the inverted internal mic! */ | 
 | 4200 | 		snprintf(dest_label, 44, "Inverted %s", label); | 
 | 4201 | 		return 1; | 
 | 4202 | 	} | 
 | 4203 | 	return 0; | 
 | 4204 | } | 
 | 4205 |  | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4206 | static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, | 
 | 4207 | 				      const char *label, const char *pfx, | 
 | 4208 | 				      int cidx) | 
 | 4209 | { | 
 | 4210 | 	struct conexant_spec *spec = codec->spec; | 
 | 4211 | 	int i; | 
 | 4212 |  | 
 | 4213 | 	for (i = 0; i < spec->num_adc_nids; i++) { | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4214 | 		char rightch_label[44]; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4215 | 		hda_nid_t adc_nid = spec->adc_nids[i]; | 
| Takashi Iwai | 5c9887e | 2011-05-13 18:36:37 +0200 | [diff] [blame] | 4216 | 		int idx = get_input_connection(codec, adc_nid, nid); | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4217 | 		if (idx < 0) | 
 | 4218 | 			continue; | 
| Michael Karcher | 4f32456 | 2012-04-06 15:34:15 +0200 | [diff] [blame] | 4219 | 		if (codec->single_adc_amp) | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4220 | 			idx = 0; | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4221 |  | 
 | 4222 | 		if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { | 
 | 4223 | 			/* Make two independent kcontrols for left and right */ | 
 | 4224 | 			int err = cx_auto_add_volume_idx(codec, label, pfx, | 
 | 4225 | 						cidx, adc_nid, HDA_INPUT, idx, 1); | 
 | 4226 | 			if (err < 0) | 
 | 4227 | 				return err; | 
 | 4228 | 			return cx_auto_add_volume_idx(codec, rightch_label, pfx, | 
 | 4229 | 							cidx, adc_nid, HDA_INPUT, idx, 2); | 
 | 4230 | 		} | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4231 | 		return cx_auto_add_volume_idx(codec, label, pfx, | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4232 | 					      cidx, adc_nid, HDA_INPUT, idx, 3); | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4233 | 	} | 
 | 4234 | 	return 0; | 
 | 4235 | } | 
 | 4236 |  | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4237 | static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, | 
 | 4238 | 				    const char *label, int cidx) | 
 | 4239 | { | 
 | 4240 | 	struct conexant_spec *spec = codec->spec; | 
 | 4241 | 	hda_nid_t mux, nid; | 
| Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4242 | 	int i, con; | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4243 |  | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4244 | 	nid = spec->imux_info[idx].pin; | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4245 | 	if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { | 
 | 4246 | 		char rightch_label[44]; | 
 | 4247 | 		if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { | 
 | 4248 | 			int err = cx_auto_add_volume_idx(codec, label, " Boost", | 
 | 4249 | 							 cidx, nid, HDA_INPUT, 0, 1); | 
 | 4250 | 			if (err < 0) | 
 | 4251 | 				return err; | 
 | 4252 | 			return cx_auto_add_volume_idx(codec, rightch_label, " Boost", | 
 | 4253 | 						      cidx, nid, HDA_INPUT, 0, 2); | 
 | 4254 | 		} | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4255 | 		return cx_auto_add_volume(codec, label, " Boost", cidx, | 
 | 4256 | 					  nid, HDA_INPUT); | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4257 | 	} | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4258 | 	con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, | 
 | 4259 | 					&mux, false, 0); | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4260 | 	if (con < 0) | 
 | 4261 | 		return 0; | 
| Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4262 | 	for (i = 0; i < idx; i++) { | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4263 | 		if (spec->imux_info[i].boost == mux) | 
| Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4264 | 			return 0; /* already present */ | 
 | 4265 | 	} | 
 | 4266 |  | 
 | 4267 | 	if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4268 | 		spec->imux_info[idx].boost = mux; | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4269 | 		return cx_auto_add_volume(codec, label, " Boost", 0, | 
 | 4270 | 					  mux, HDA_OUTPUT); | 
| Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4271 | 	} | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4272 | 	return 0; | 
 | 4273 | } | 
 | 4274 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4275 | static int cx_auto_build_input_controls(struct hda_codec *codec) | 
 | 4276 | { | 
 | 4277 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4278 | 	struct hda_input_mux *imux = &spec->private_imux; | 
 | 4279 | 	const char *prev_label; | 
 | 4280 | 	int input_conn[HDA_MAX_NUM_INPUTS]; | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4281 | 	int i, j, err, cidx; | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4282 | 	int multi_connection; | 
 | 4283 |  | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4284 | 	if (!imux->num_items) | 
 | 4285 | 		return 0; | 
 | 4286 |  | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4287 | 	multi_connection = 0; | 
 | 4288 | 	for (i = 0; i < imux->num_items; i++) { | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4289 | 		cidx = get_input_connection(codec, spec->imux_info[i].adc, | 
 | 4290 | 					    spec->imux_info[i].pin); | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4291 | 		if (cidx < 0) | 
 | 4292 | 			continue; | 
 | 4293 | 		input_conn[i] = spec->imux_info[i].adc; | 
| Michael Karcher | 4f32456 | 2012-04-06 15:34:15 +0200 | [diff] [blame] | 4294 | 		if (!codec->single_adc_amp) | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4295 | 			input_conn[i] |= cidx << 8; | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4296 | 		if (i > 0 && input_conn[i] != input_conn[0]) | 
 | 4297 | 			multi_connection = 1; | 
 | 4298 | 	} | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4299 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4300 | 	prev_label = NULL; | 
 | 4301 | 	cidx = 0; | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4302 | 	for (i = 0; i < imux->num_items; i++) { | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4303 | 		hda_nid_t nid = spec->imux_info[i].pin; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4304 | 		const char *label; | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4305 |  | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4306 | 		label = hda_get_autocfg_input_label(codec, &spec->autocfg, | 
| Takashi Iwai | 47ad1f4 | 2011-05-17 09:15:55 +0200 | [diff] [blame] | 4307 | 						    spec->imux_info[i].index); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4308 | 		if (label == prev_label) | 
 | 4309 | 			cidx++; | 
 | 4310 | 		else | 
 | 4311 | 			cidx = 0; | 
 | 4312 | 		prev_label = label; | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4313 |  | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4314 | 		err = cx_auto_add_boost_volume(codec, i, label, cidx); | 
 | 4315 | 		if (err < 0) | 
 | 4316 | 			return err; | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4317 |  | 
| Takashi Iwai | cf27f29 | 2011-05-16 11:33:02 +0200 | [diff] [blame] | 4318 | 		if (!multi_connection) { | 
| Takashi Iwai | f975930 | 2011-05-16 11:45:15 +0200 | [diff] [blame] | 4319 | 			if (i > 0) | 
 | 4320 | 				continue; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4321 | 			err = cx_auto_add_capture_volume(codec, nid, | 
 | 4322 | 							 "Capture", "", cidx); | 
 | 4323 | 		} else { | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4324 | 			bool dup_found = false; | 
 | 4325 | 			for (j = 0; j < i; j++) { | 
 | 4326 | 				if (input_conn[j] == input_conn[i]) { | 
 | 4327 | 					dup_found = true; | 
 | 4328 | 					break; | 
 | 4329 | 				} | 
 | 4330 | 			} | 
 | 4331 | 			if (dup_found) | 
 | 4332 | 				continue; | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4333 | 			err = cx_auto_add_capture_volume(codec, nid, | 
 | 4334 | 							 label, " Capture", cidx); | 
| David Henningsson | 983345e | 2011-02-15 19:57:09 +0100 | [diff] [blame] | 4335 | 		} | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4336 | 		if (err < 0) | 
 | 4337 | 			return err; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4338 | 	} | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4339 |  | 
 | 4340 | 	if (spec->private_imux.num_items > 1 && !spec->auto_mic) { | 
 | 4341 | 		err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); | 
 | 4342 | 		if (err < 0) | 
 | 4343 | 			return err; | 
 | 4344 | 	} | 
 | 4345 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4346 | 	return 0; | 
 | 4347 | } | 
 | 4348 |  | 
 | 4349 | static int cx_auto_build_controls(struct hda_codec *codec) | 
 | 4350 | { | 
| Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 4351 | 	struct conexant_spec *spec = codec->spec; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4352 | 	int err; | 
 | 4353 |  | 
 | 4354 | 	err = cx_auto_build_output_controls(codec); | 
 | 4355 | 	if (err < 0) | 
 | 4356 | 		return err; | 
 | 4357 | 	err = cx_auto_build_input_controls(codec); | 
 | 4358 | 	if (err < 0) | 
 | 4359 | 		return err; | 
| Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 4360 | 	err = conexant_build_controls(codec); | 
 | 4361 | 	if (err < 0) | 
 | 4362 | 		return err; | 
 | 4363 | 	err = snd_hda_jack_add_kctls(codec, &spec->autocfg); | 
 | 4364 | 	if (err < 0) | 
 | 4365 | 		return err; | 
| Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 4366 | 	if (spec->vmaster_mute.sw_kctl) { | 
 | 4367 | 		spec->vmaster_mute.hook = cx_auto_vmaster_hook; | 
 | 4368 | 		err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, | 
 | 4369 | 					       spec->vmaster_mute_led); | 
| Takashi Iwai | d2f344b | 2012-03-12 16:59:58 +0100 | [diff] [blame] | 4370 | 		if (err < 0) | 
 | 4371 | 			return err; | 
| Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 4372 | 	} | 
| Takashi Iwai | 31ef225 | 2011-12-01 17:41:36 +0100 | [diff] [blame] | 4373 | 	return 0; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4374 | } | 
 | 4375 |  | 
| Takashi Iwai | 22ce5f7 | 2011-05-15 12:19:29 +0200 | [diff] [blame] | 4376 | static int cx_auto_search_adcs(struct hda_codec *codec) | 
 | 4377 | { | 
 | 4378 | 	struct conexant_spec *spec = codec->spec; | 
 | 4379 | 	hda_nid_t nid, end_nid; | 
 | 4380 |  | 
 | 4381 | 	end_nid = codec->start_nid + codec->num_nodes; | 
 | 4382 | 	for (nid = codec->start_nid; nid < end_nid; nid++) { | 
 | 4383 | 		unsigned int caps = get_wcaps(codec, nid); | 
 | 4384 | 		if (get_wcaps_type(caps) != AC_WID_AUD_IN) | 
 | 4385 | 			continue; | 
 | 4386 | 		if (caps & AC_WCAP_DIGITAL) | 
 | 4387 | 			continue; | 
 | 4388 | 		if (snd_BUG_ON(spec->num_adc_nids >= | 
 | 4389 | 			       ARRAY_SIZE(spec->private_adc_nids))) | 
 | 4390 | 			break; | 
 | 4391 | 		spec->private_adc_nids[spec->num_adc_nids++] = nid; | 
 | 4392 | 	} | 
 | 4393 | 	spec->adc_nids = spec->private_adc_nids; | 
 | 4394 | 	return 0; | 
 | 4395 | } | 
 | 4396 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 4397 | static const struct hda_codec_ops cx_auto_patch_ops = { | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4398 | 	.build_controls = cx_auto_build_controls, | 
 | 4399 | 	.build_pcms = conexant_build_pcms, | 
 | 4400 | 	.init = cx_auto_init, | 
 | 4401 | 	.free = conexant_free, | 
 | 4402 | 	.unsol_event = cx_auto_unsol_event, | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4403 | }; | 
 | 4404 |  | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4405 | /* | 
 | 4406 |  * pin fix-up | 
 | 4407 |  */ | 
 | 4408 | struct cxt_pincfg { | 
 | 4409 | 	hda_nid_t nid; | 
 | 4410 | 	u32 val; | 
 | 4411 | }; | 
 | 4412 |  | 
 | 4413 | static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) | 
 | 4414 | { | 
 | 4415 | 	for (; cfg->nid; cfg++) | 
 | 4416 | 		snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); | 
 | 4417 |  | 
 | 4418 | } | 
 | 4419 |  | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4420 | enum { | 
 | 4421 | 	CXT_PINCFG_LENOVO_X200, | 
 | 4422 | 	CXT_PINCFG_LENOVO_TP410, | 
 | 4423 | 	CXT_FIXUP_STEREO_DMIC | 
 | 4424 | }; | 
 | 4425 |  | 
 | 4426 | static void apply_fixup(struct hda_codec *codec, | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4427 | 			    const struct snd_pci_quirk *quirk, | 
 | 4428 | 			    const struct cxt_pincfg **table) | 
 | 4429 | { | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4430 | 	 struct conexant_spec *spec = codec->spec; | 
 | 4431 |  | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4432 | 	quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); | 
| David Henningsson | d3ecba4 | 2012-04-10 13:05:29 +0200 | [diff] [blame] | 4433 | 	if (!quirk) | 
 | 4434 | 		return; | 
 | 4435 | 	if (table[quirk->value]) { | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4436 | 		snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", | 
 | 4437 | 			    quirk->name); | 
 | 4438 | 		apply_pincfg(codec, table[quirk->value]); | 
 | 4439 | 	} | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4440 | 	if (quirk->value == CXT_FIXUP_STEREO_DMIC) { | 
 | 4441 | 		snd_printdd(KERN_INFO "hda_codec: applying internal mic workaround for %s\n", | 
 | 4442 | 			    quirk->name); | 
 | 4443 | 		spec->fixup_stereo_dmic = 1; | 
 | 4444 | 	} | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4445 | } | 
 | 4446 |  | 
| Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4447 | /* ThinkPad X200 & co with cxt5051 */ | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4448 | static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { | 
 | 4449 | 	{ 0x16, 0x042140ff }, /* HP (seq# overridden) */ | 
 | 4450 | 	{ 0x17, 0x21a11000 }, /* dock-mic */ | 
 | 4451 | 	{ 0x19, 0x2121103f }, /* dock-HP */ | 
| Takashi Iwai | 3e93f5e | 2012-02-28 21:49:55 +0100 | [diff] [blame] | 4452 | 	{ 0x1c, 0x21440100 }, /* dock SPDIF out */ | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4453 | 	{} | 
 | 4454 | }; | 
 | 4455 |  | 
| Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4456 | /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ | 
 | 4457 | static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = { | 
 | 4458 | 	{ 0x19, 0x042110ff }, /* HP (seq# overridden) */ | 
 | 4459 | 	{ 0x1a, 0x21a190f0 }, /* dock-mic */ | 
 | 4460 | 	{ 0x1c, 0x212140ff }, /* dock-HP */ | 
 | 4461 | 	{} | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4462 | }; | 
 | 4463 |  | 
| Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4464 | static const struct cxt_pincfg *cxt_pincfg_tbl[] = { | 
 | 4465 | 	[CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, | 
 | 4466 | 	[CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410, | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4467 | 	[CXT_FIXUP_STEREO_DMIC] = NULL, | 
| Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4468 | }; | 
 | 4469 |  | 
 | 4470 | static const struct snd_pci_quirk cxt5051_fixups[] = { | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4471 | 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), | 
 | 4472 | 	{} | 
 | 4473 | }; | 
 | 4474 |  | 
| Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4475 | static const struct snd_pci_quirk cxt5066_fixups[] = { | 
| Takashi Iwai | cdab1ea | 2012-12-12 12:10:01 +0100 | [diff] [blame] | 4476 | 	SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC), | 
| Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4477 | 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), | 
 | 4478 | 	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), | 
 | 4479 | 	SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), | 
 | 4480 | 	SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), | 
 | 4481 | 	SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4482 | 	SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), | 
| Felix Kaechele | 419f4df | 2012-09-26 01:20:44 +0200 | [diff] [blame] | 4483 | 	SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC), | 
| David Henningsson | 8194af4 | 2012-06-21 16:03:01 +0200 | [diff] [blame] | 4484 | 	SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC), | 
| Takashi Iwai | d70f363 | 2012-04-19 15:18:08 +0200 | [diff] [blame] | 4485 | 	{} | 
 | 4486 | }; | 
 | 4487 |  | 
| Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 4488 | /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches | 
 | 4489 |  * can be created (bko#42825) | 
 | 4490 |  */ | 
 | 4491 | static void add_cx5051_fake_mutes(struct hda_codec *codec) | 
 | 4492 | { | 
 | 4493 | 	static hda_nid_t out_nids[] = { | 
 | 4494 | 		0x10, 0x11, 0 | 
 | 4495 | 	}; | 
 | 4496 | 	hda_nid_t *p; | 
 | 4497 |  | 
 | 4498 | 	for (p = out_nids; *p; p++) | 
 | 4499 | 		snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, | 
 | 4500 | 					  AC_AMPCAP_MIN_MUTE | | 
 | 4501 | 					  query_amp_caps(codec, *p, HDA_OUTPUT)); | 
 | 4502 | } | 
 | 4503 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4504 | static int patch_conexant_auto(struct hda_codec *codec) | 
 | 4505 | { | 
 | 4506 | 	struct conexant_spec *spec; | 
 | 4507 | 	int err; | 
 | 4508 |  | 
| Takashi Iwai | 1f8458a | 2011-05-13 17:22:05 +0200 | [diff] [blame] | 4509 | 	printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", | 
 | 4510 | 	       codec->chip_name); | 
 | 4511 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4512 | 	spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 
 | 4513 | 	if (!spec) | 
 | 4514 | 		return -ENOMEM; | 
 | 4515 | 	codec->spec = spec; | 
| Takashi Iwai | e92d4b0 | 2011-08-24 16:22:21 +0200 | [diff] [blame] | 4516 |  | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4517 | 	switch (codec->vendor_id) { | 
 | 4518 | 	case 0x14f15045: | 
| Michael Karcher | 4f32456 | 2012-04-06 15:34:15 +0200 | [diff] [blame] | 4519 | 		codec->single_adc_amp = 1; | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4520 | 		break; | 
| Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 4521 | 	case 0x14f15051: | 
 | 4522 | 		add_cx5051_fake_mutes(codec); | 
| Michael Karcher | 51969d6 | 2012-04-06 15:34:19 +0200 | [diff] [blame] | 4523 | 		codec->pin_amp_workaround = 1; | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4524 | 		apply_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl); | 
| Takashi Iwai | 3868137 | 2012-02-27 15:00:58 +0100 | [diff] [blame] | 4525 | 		break; | 
| Michael Karcher | 51969d6 | 2012-04-06 15:34:19 +0200 | [diff] [blame] | 4526 | 	default: | 
 | 4527 | 		codec->pin_amp_workaround = 1; | 
| David Henningsson | cae4d9a | 2012-04-02 15:40:27 +0200 | [diff] [blame] | 4528 | 		apply_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl); | 
| Takashi Iwai | 6b45214 | 2011-10-14 15:26:20 +0200 | [diff] [blame] | 4529 | 	} | 
 | 4530 |  | 
| Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 4531 | 	/* Show mute-led control only on HP laptops | 
 | 4532 | 	 * This is a sort of white-list: on HP laptops, EAPD corresponds | 
 | 4533 | 	 * only to the mute-LED without actualy amp function.  Meanwhile, | 
 | 4534 | 	 * others may use EAPD really as an amp switch, so it might be | 
 | 4535 | 	 * not good to expose it blindly. | 
| Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 4536 | 	 */ | 
| Takashi Iwai | f29735c | 2012-03-13 07:55:10 +0100 | [diff] [blame] | 4537 | 	switch (codec->subsystem_id >> 16) { | 
 | 4538 | 	case 0x103c: | 
 | 4539 | 		spec->vmaster_mute_led = 1; | 
 | 4540 | 		break; | 
 | 4541 | 	} | 
| Takashi Iwai | 527c73b | 2012-03-12 12:38:51 +0100 | [diff] [blame] | 4542 |  | 
| Takashi Iwai | 22ce5f7 | 2011-05-15 12:19:29 +0200 | [diff] [blame] | 4543 | 	err = cx_auto_search_adcs(codec); | 
 | 4544 | 	if (err < 0) | 
 | 4545 | 		return err; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4546 | 	err = cx_auto_parse_auto_config(codec); | 
 | 4547 | 	if (err < 0) { | 
 | 4548 | 		kfree(codec->spec); | 
 | 4549 | 		codec->spec = NULL; | 
 | 4550 | 		return err; | 
 | 4551 | 	} | 
| Takashi Iwai | 6764bce | 2011-05-13 16:52:25 +0200 | [diff] [blame] | 4552 | 	spec->capture_stream = &cx_auto_pcm_analog_capture; | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4553 | 	codec->patch_ops = cx_auto_patch_ops; | 
 | 4554 | 	if (spec->beep_amp) | 
| Takashi Iwai | 184e91c | 2013-03-18 11:00:44 +0100 | [diff] [blame] | 4555 | 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp)); | 
| Takashi Iwai | 4f2864a | 2012-01-25 11:54:19 +0100 | [diff] [blame] | 4556 |  | 
 | 4557 | 	/* Some laptops with Conexant chips show stalls in S3 resume, | 
 | 4558 | 	 * which falls into the single-cmd mode. | 
 | 4559 | 	 * Better to make reset, then. | 
 | 4560 | 	 */ | 
 | 4561 | 	if (!codec->bus->sync_write) { | 
 | 4562 | 		snd_printd("hda_codec: " | 
 | 4563 | 			   "Enable sync_write for stable communication\n"); | 
 | 4564 | 		codec->bus->sync_write = 1; | 
 | 4565 | 		codec->bus->allow_bus_reset = 1; | 
 | 4566 | 	} | 
 | 4567 |  | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4568 | 	return 0; | 
 | 4569 | } | 
 | 4570 |  | 
 | 4571 | /* | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 4572 |  */ | 
 | 4573 |  | 
| Takashi Iwai | 34cbe3a | 2011-05-02 11:38:21 +0200 | [diff] [blame] | 4574 | static const struct hda_codec_preset snd_hda_preset_conexant[] = { | 
| Tobin Davis | 82f3004 | 2007-02-13 12:45:44 +0100 | [diff] [blame] | 4575 | 	{ .id = 0x14f15045, .name = "CX20549 (Venice)", | 
 | 4576 | 	  .patch = patch_cxt5045 }, | 
 | 4577 | 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)", | 
 | 4578 | 	  .patch = patch_cxt5047 }, | 
| Takashi Iwai | 461e2c7 | 2008-01-25 11:35:17 +0100 | [diff] [blame] | 4579 | 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)", | 
 | 4580 | 	  .patch = patch_cxt5051 }, | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 4581 | 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)", | 
 | 4582 | 	  .patch = patch_cxt5066 }, | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 4583 | 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", | 
 | 4584 | 	  .patch = patch_cxt5066 }, | 
| Takashi Iwai | 850eab9 | 2010-08-09 13:44:27 +0200 | [diff] [blame] | 4585 | 	{ .id = 0x14f15068, .name = "CX20584", | 
 | 4586 | 	  .patch = patch_cxt5066 }, | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 4587 | 	{ .id = 0x14f15069, .name = "CX20585", | 
 | 4588 | 	  .patch = patch_cxt5066 }, | 
| David Henningsson | f0ca89b | 2011-06-21 20:51:34 +0200 | [diff] [blame] | 4589 | 	{ .id = 0x14f1506c, .name = "CX20588", | 
 | 4590 | 	  .patch = patch_cxt5066 }, | 
| David Henningsson | 6da8b51 | 2011-02-08 07:16:06 +0100 | [diff] [blame] | 4591 | 	{ .id = 0x14f1506e, .name = "CX20590", | 
 | 4592 | 	  .patch = patch_cxt5066 }, | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4593 | 	{ .id = 0x14f15097, .name = "CX20631", | 
 | 4594 | 	  .patch = patch_conexant_auto }, | 
 | 4595 | 	{ .id = 0x14f15098, .name = "CX20632", | 
 | 4596 | 	  .patch = patch_conexant_auto }, | 
 | 4597 | 	{ .id = 0x14f150a1, .name = "CX20641", | 
 | 4598 | 	  .patch = patch_conexant_auto }, | 
 | 4599 | 	{ .id = 0x14f150a2, .name = "CX20642", | 
 | 4600 | 	  .patch = patch_conexant_auto }, | 
 | 4601 | 	{ .id = 0x14f150ab, .name = "CX20651", | 
 | 4602 | 	  .patch = patch_conexant_auto }, | 
 | 4603 | 	{ .id = 0x14f150ac, .name = "CX20652", | 
 | 4604 | 	  .patch = patch_conexant_auto }, | 
 | 4605 | 	{ .id = 0x14f150b8, .name = "CX20664", | 
 | 4606 | 	  .patch = patch_conexant_auto }, | 
 | 4607 | 	{ .id = 0x14f150b9, .name = "CX20665", | 
 | 4608 | 	  .patch = patch_conexant_auto }, | 
| Takashi Iwai | 1168045 | 2012-05-11 08:39:24 +0200 | [diff] [blame] | 4609 | 	{ .id = 0x14f1510f, .name = "CX20751/2", | 
 | 4610 | 	  .patch = patch_conexant_auto }, | 
 | 4611 | 	{ .id = 0x14f15110, .name = "CX20751/2", | 
 | 4612 | 	  .patch = patch_conexant_auto }, | 
 | 4613 | 	{ .id = 0x14f15111, .name = "CX20753/4", | 
 | 4614 | 	  .patch = patch_conexant_auto }, | 
| Takashi Iwai | a162811 | 2013-01-21 16:53:37 +0100 | [diff] [blame] | 4615 | 	{ .id = 0x14f15113, .name = "CX20755", | 
 | 4616 | 	  .patch = patch_conexant_auto }, | 
 | 4617 | 	{ .id = 0x14f15114, .name = "CX20756", | 
 | 4618 | 	  .patch = patch_conexant_auto }, | 
 | 4619 | 	{ .id = 0x14f15115, .name = "CX20757", | 
 | 4620 | 	  .patch = patch_conexant_auto }, | 
| Takashi Iwai | ffb88d5 | 2013-11-06 18:47:42 +0100 | [diff] [blame] | 4621 | 	{ .id = 0x14f151d7, .name = "CX20952", | 
 | 4622 | 	  .patch = patch_conexant_auto }, | 
| Tobin Davis | c9b443d | 2006-11-14 12:13:39 +0100 | [diff] [blame] | 4623 | 	{} /* terminator */ | 
 | 4624 | }; | 
| Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 4625 |  | 
 | 4626 | MODULE_ALIAS("snd-hda-codec-id:14f15045"); | 
 | 4627 | MODULE_ALIAS("snd-hda-codec-id:14f15047"); | 
 | 4628 | MODULE_ALIAS("snd-hda-codec-id:14f15051"); | 
| Daniel Drake | 0fb67e9 | 2009-07-16 14:46:57 +0100 | [diff] [blame] | 4629 | MODULE_ALIAS("snd-hda-codec-id:14f15066"); | 
| Einar Rünkaru | 95a618b | 2009-11-23 22:23:49 +0200 | [diff] [blame] | 4630 | MODULE_ALIAS("snd-hda-codec-id:14f15067"); | 
| Takashi Iwai | 850eab9 | 2010-08-09 13:44:27 +0200 | [diff] [blame] | 4631 | MODULE_ALIAS("snd-hda-codec-id:14f15068"); | 
| Jens Taprogge | 7b2bfdb | 2010-04-14 23:42:04 +0200 | [diff] [blame] | 4632 | MODULE_ALIAS("snd-hda-codec-id:14f15069"); | 
| David Henningsson | f0ca89b | 2011-06-21 20:51:34 +0200 | [diff] [blame] | 4633 | MODULE_ALIAS("snd-hda-codec-id:14f1506c"); | 
| David Henningsson | 6da8b51 | 2011-02-08 07:16:06 +0100 | [diff] [blame] | 4634 | MODULE_ALIAS("snd-hda-codec-id:14f1506e"); | 
| Takashi Iwai | f2e5731 | 2010-09-15 10:07:08 +0200 | [diff] [blame] | 4635 | MODULE_ALIAS("snd-hda-codec-id:14f15097"); | 
 | 4636 | MODULE_ALIAS("snd-hda-codec-id:14f15098"); | 
 | 4637 | MODULE_ALIAS("snd-hda-codec-id:14f150a1"); | 
 | 4638 | MODULE_ALIAS("snd-hda-codec-id:14f150a2"); | 
 | 4639 | MODULE_ALIAS("snd-hda-codec-id:14f150ab"); | 
 | 4640 | MODULE_ALIAS("snd-hda-codec-id:14f150ac"); | 
 | 4641 | MODULE_ALIAS("snd-hda-codec-id:14f150b8"); | 
 | 4642 | MODULE_ALIAS("snd-hda-codec-id:14f150b9"); | 
| Takashi Iwai | 1168045 | 2012-05-11 08:39:24 +0200 | [diff] [blame] | 4643 | MODULE_ALIAS("snd-hda-codec-id:14f1510f"); | 
 | 4644 | MODULE_ALIAS("snd-hda-codec-id:14f15110"); | 
 | 4645 | MODULE_ALIAS("snd-hda-codec-id:14f15111"); | 
| Takashi Iwai | a162811 | 2013-01-21 16:53:37 +0100 | [diff] [blame] | 4646 | MODULE_ALIAS("snd-hda-codec-id:14f15113"); | 
 | 4647 | MODULE_ALIAS("snd-hda-codec-id:14f15114"); | 
 | 4648 | MODULE_ALIAS("snd-hda-codec-id:14f15115"); | 
| Takashi Iwai | ffb88d5 | 2013-11-06 18:47:42 +0100 | [diff] [blame] | 4649 | MODULE_ALIAS("snd-hda-codec-id:14f151d7"); | 
| Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 4650 |  | 
 | 4651 | MODULE_LICENSE("GPL"); | 
 | 4652 | MODULE_DESCRIPTION("Conexant HD-audio codec"); | 
 | 4653 |  | 
 | 4654 | static struct hda_codec_preset_list conexant_list = { | 
 | 4655 | 	.preset = snd_hda_preset_conexant, | 
 | 4656 | 	.owner = THIS_MODULE, | 
 | 4657 | }; | 
 | 4658 |  | 
 | 4659 | static int __init patch_conexant_init(void) | 
 | 4660 | { | 
 | 4661 | 	return snd_hda_add_codec_preset(&conexant_list); | 
 | 4662 | } | 
 | 4663 |  | 
 | 4664 | static void __exit patch_conexant_exit(void) | 
 | 4665 | { | 
 | 4666 | 	snd_hda_delete_codec_preset(&conexant_list); | 
 | 4667 | } | 
 | 4668 |  | 
 | 4669 | module_init(patch_conexant_init) | 
 | 4670 | module_exit(patch_conexant_exit) |