Linux Audio

Check our new training course

Loading...
v3.15
 
   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
  23#include <linux/init.h>
  24#include <linux/delay.h>
  25#include <linux/slab.h>
  26#include <linux/module.h>
  27#include <sound/core.h>
  28#include <sound/jack.h>
  29
  30#include "hda_codec.h"
  31#include "hda_local.h"
  32#include "hda_auto_parser.h"
  33#include "hda_beep.h"
  34#include "hda_jack.h"
  35#include "hda_generic.h"
  36
  37#undef ENABLE_CXT_STATIC_QUIRKS
  38
  39#define CXT_PIN_DIR_IN              0x00
  40#define CXT_PIN_DIR_OUT             0x01
  41#define CXT_PIN_DIR_INOUT           0x02
  42#define CXT_PIN_DIR_IN_NOMICBIAS    0x03
  43#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  44
  45#define CONEXANT_HP_EVENT	0x37
  46#define CONEXANT_MIC_EVENT	0x38
  47#define CONEXANT_LINE_EVENT	0x39
  48
  49/* Conexant 5051 specific */
  50
  51#define CXT5051_SPDIF_OUT	0x12
  52#define CXT5051_PORTB_EVENT	0x38
  53#define CXT5051_PORTC_EVENT	0x39
  54
  55#define AUTO_MIC_PORTB		(1 << 1)
  56#define AUTO_MIC_PORTC		(1 << 2)
  57
  58struct conexant_spec {
  59	struct hda_gen_spec gen;
  60
  61	unsigned int beep_amp;
  62
  63	/* extra EAPD pins */
  64	unsigned int num_eapds;
  65	hda_nid_t eapds[4];
  66	bool dynamic_eapd;
 
  67
  68	unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
  69
  70	/* OPLC XO specific */
  71	bool recording;
  72	bool dc_enable;
  73	unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
  74	struct nid_path *dc_mode_path;
  75
  76#ifdef ENABLE_CXT_STATIC_QUIRKS
  77	const struct snd_kcontrol_new *mixers[5];
  78	int num_mixers;
  79	hda_nid_t vmaster_nid;
  80
  81	const struct hda_verb *init_verbs[5];	/* initialization verbs
  82						 * don't forget NULL
  83						 * termination!
  84						 */
  85	unsigned int num_init_verbs;
  86
  87	/* playback */
  88	struct hda_multi_out multiout;	/* playback set-up
  89					 * max_channels, dacs must be set
  90					 * dig_out_nid and hp_nid are optional
  91					 */
  92	unsigned int cur_eapd;
  93	unsigned int hp_present;
  94	unsigned int line_present;
  95	unsigned int auto_mic;
  96
  97	/* capture */
  98	unsigned int num_adc_nids;
  99	const hda_nid_t *adc_nids;
 100	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
 101
 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
 107	const struct hda_pcm_stream *capture_stream;
 108
 109	/* capture source */
 110	const struct hda_input_mux *input_mux;
 111	const hda_nid_t *capsrc_nids;
 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
 121	unsigned int spdif_route;
 122
 123	unsigned int port_d_mode;
 124	unsigned int dell_automute:1;
 125	unsigned int dell_vostro:1;
 126	unsigned int ideapad:1;
 127	unsigned int thinkpad:1;
 128	unsigned int hp_laptop:1;
 129	unsigned int asus:1;
 130
 131	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
 132#endif /* ENABLE_CXT_STATIC_QUIRKS */
 133};
 134
 135
 136#ifdef CONFIG_SND_HDA_INPUT_BEEP
 137static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
 138				int idx, int dir)
 139{
 140	spec->gen.beep_nid = nid;
 141	spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
 142}
 143/* additional beep mixers; the actual parameters are overwritten at build */
 144static const struct snd_kcontrol_new cxt_beep_mixer[] = {
 145	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
 146	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
 147	{ } /* end */
 148};
 149
 150/* create beep controls if needed */
 151static int add_beep_ctls(struct hda_codec *codec)
 152{
 153	struct conexant_spec *spec = codec->spec;
 154	int err;
 155
 156	if (spec->beep_amp) {
 157		const struct snd_kcontrol_new *knew;
 158		for (knew = cxt_beep_mixer; knew->name; knew++) {
 159			struct snd_kcontrol *kctl;
 160			kctl = snd_ctl_new1(knew, codec);
 161			if (!kctl)
 162				return -ENOMEM;
 163			kctl->private_value = spec->beep_amp;
 164			err = snd_hda_ctl_add(codec, 0, kctl);
 165			if (err < 0)
 166				return err;
 167		}
 168	}
 169	return 0;
 170}
 171#else
 172#define set_beep_amp(spec, nid, idx, dir) /* NOP */
 173#define add_beep_ctls(codec)	0
 174#endif
 175
 176
 177#ifdef ENABLE_CXT_STATIC_QUIRKS
 178static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
 179				      struct hda_codec *codec,
 180				      struct snd_pcm_substream *substream)
 181{
 182	struct conexant_spec *spec = codec->spec;
 183	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
 184					     hinfo);
 185}
 186
 187static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
 188					 struct hda_codec *codec,
 189					 unsigned int stream_tag,
 190					 unsigned int format,
 191					 struct snd_pcm_substream *substream)
 192{
 193	struct conexant_spec *spec = codec->spec;
 194	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
 195						stream_tag,
 196						format, substream);
 197}
 198
 199static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
 200					 struct hda_codec *codec,
 201					 struct snd_pcm_substream *substream)
 202{
 203	struct conexant_spec *spec = codec->spec;
 204	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
 205}
 206
 207/*
 208 * Digital out
 209 */
 210static int conexant_dig_playback_pcm_open(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_open(codec, &spec->multiout);
 216}
 217
 218static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
 219					 struct hda_codec *codec,
 220					 struct snd_pcm_substream *substream)
 221{
 222	struct conexant_spec *spec = codec->spec;
 223	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
 224}
 225
 226static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
 227					 struct hda_codec *codec,
 228					 unsigned int stream_tag,
 229					 unsigned int format,
 230					 struct snd_pcm_substream *substream)
 231{
 232	struct conexant_spec *spec = codec->spec;
 233	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
 234					     stream_tag,
 235					     format, substream);
 236}
 237
 238/*
 239 * Analog capture
 240 */
 241static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
 242				      struct hda_codec *codec,
 243				      unsigned int stream_tag,
 244				      unsigned int format,
 245				      struct snd_pcm_substream *substream)
 246{
 247	struct conexant_spec *spec = codec->spec;
 248	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
 249				   stream_tag, 0, format);
 250	return 0;
 251}
 252
 253static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
 254				      struct hda_codec *codec,
 255				      struct snd_pcm_substream *substream)
 256{
 257	struct conexant_spec *spec = codec->spec;
 258	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
 259	return 0;
 260}
 261
 262
 263
 264static const struct hda_pcm_stream conexant_pcm_analog_playback = {
 265	.substreams = 1,
 266	.channels_min = 2,
 267	.channels_max = 2,
 268	.nid = 0, /* fill later */
 269	.ops = {
 270		.open = conexant_playback_pcm_open,
 271		.prepare = conexant_playback_pcm_prepare,
 272		.cleanup = conexant_playback_pcm_cleanup
 273	},
 274};
 275
 276static const struct hda_pcm_stream conexant_pcm_analog_capture = {
 277	.substreams = 1,
 278	.channels_min = 2,
 279	.channels_max = 2,
 280	.nid = 0, /* fill later */
 281	.ops = {
 282		.prepare = conexant_capture_pcm_prepare,
 283		.cleanup = conexant_capture_pcm_cleanup
 284	},
 285};
 286
 287
 288static const struct hda_pcm_stream conexant_pcm_digital_playback = {
 289	.substreams = 1,
 290	.channels_min = 2,
 291	.channels_max = 2,
 292	.nid = 0, /* fill later */
 293	.ops = {
 294		.open = conexant_dig_playback_pcm_open,
 295		.close = conexant_dig_playback_pcm_close,
 296		.prepare = conexant_dig_playback_pcm_prepare
 297	},
 298};
 299
 300static const struct hda_pcm_stream conexant_pcm_digital_capture = {
 301	.substreams = 1,
 302	.channels_min = 2,
 303	.channels_max = 2,
 304	/* NID is set in alc_build_pcms */
 305};
 306
 307static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
 308				      struct hda_codec *codec,
 309				      unsigned int stream_tag,
 310				      unsigned int format,
 311				      struct snd_pcm_substream *substream)
 312{
 313	struct conexant_spec *spec = codec->spec;
 314	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
 315	spec->cur_adc_stream_tag = stream_tag;
 316	spec->cur_adc_format = format;
 317	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
 318	return 0;
 319}
 320
 321static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
 322				      struct hda_codec *codec,
 323				      struct snd_pcm_substream *substream)
 324{
 325	struct conexant_spec *spec = codec->spec;
 326	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
 327	spec->cur_adc = 0;
 328	return 0;
 329}
 330
 331static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
 332	.substreams = 1,
 333	.channels_min = 2,
 334	.channels_max = 2,
 335	.nid = 0, /* fill later */
 336	.ops = {
 337		.prepare = cx5051_capture_pcm_prepare,
 338		.cleanup = cx5051_capture_pcm_cleanup
 339	},
 340};
 341
 342static int conexant_build_pcms(struct hda_codec *codec)
 343{
 344	struct conexant_spec *spec = codec->spec;
 345	struct hda_pcm *info = spec->pcm_rec;
 346
 347	codec->num_pcms = 1;
 348	codec->pcm_info = info;
 349
 350	info->name = "CONEXANT Analog";
 351	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
 352	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
 353		spec->multiout.max_channels;
 354	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
 355		spec->multiout.dac_nids[0];
 356	if (spec->capture_stream)
 357		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
 358	else {
 359		if (codec->vendor_id == 0x14f15051)
 360			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
 361				cx5051_pcm_analog_capture;
 362		else {
 363			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
 364				conexant_pcm_analog_capture;
 365			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
 366				spec->num_adc_nids;
 367		}
 368	}
 369	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
 370
 371	if (spec->multiout.dig_out_nid) {
 372		info++;
 373		codec->num_pcms++;
 374		info->name = "Conexant Digital";
 375		info->pcm_type = HDA_PCM_TYPE_SPDIF;
 376		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
 377			conexant_pcm_digital_playback;
 378		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
 379			spec->multiout.dig_out_nid;
 380		if (spec->dig_in_nid) {
 381			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
 382				conexant_pcm_digital_capture;
 383			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
 384				spec->dig_in_nid;
 385		}
 386	}
 387
 388	return 0;
 389}
 390
 391static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
 392	       			  struct snd_ctl_elem_info *uinfo)
 393{
 394	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 395	struct conexant_spec *spec = codec->spec;
 396
 397	return snd_hda_input_mux_info(spec->input_mux, uinfo);
 398}
 399
 400static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
 401				 struct snd_ctl_elem_value *ucontrol)
 402{
 403	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 404	struct conexant_spec *spec = codec->spec;
 405	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
 406
 407	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
 408	return 0;
 409}
 410
 411static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
 412				 struct snd_ctl_elem_value *ucontrol)
 413{
 414	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 415	struct conexant_spec *spec = codec->spec;
 416	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
 417
 418	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
 419				     spec->capsrc_nids[adc_idx],
 420				     &spec->cur_mux[adc_idx]);
 421}
 422
 423static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
 424			       unsigned int power_state)
 425{
 426	if (power_state == AC_PWRST_D3)
 427		msleep(100);
 428	snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
 429			    power_state);
 430	/* partial workaround for "azx_get_response timeout" */
 431	if (power_state == AC_PWRST_D0)
 432		msleep(10);
 433	snd_hda_codec_set_power_to_all(codec, fg, power_state);
 434}
 435
 436static int conexant_init(struct hda_codec *codec)
 437{
 438	struct conexant_spec *spec = codec->spec;
 439	int i;
 440
 441	for (i = 0; i < spec->num_init_verbs; i++)
 442		snd_hda_sequence_write(codec, spec->init_verbs[i]);
 
 
 
 
 
 
 443	return 0;
 444}
 445
 446static void conexant_free(struct hda_codec *codec)
 447{
 448	kfree(codec->spec);
 449}
 450
 451static const struct snd_kcontrol_new cxt_capture_mixers[] = {
 452	{
 453		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 454		.name = "Capture Source",
 455		.info = conexant_mux_enum_info,
 456		.get = conexant_mux_enum_get,
 457		.put = conexant_mux_enum_put
 458	},
 459	{}
 460};
 461
 462static const char * const slave_pfxs[] = {
 463	"Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
 464	NULL
 465};
 466
 467static int conexant_build_controls(struct hda_codec *codec)
 468{
 469	struct conexant_spec *spec = codec->spec;
 470	unsigned int i;
 471	int err;
 472
 473	for (i = 0; i < spec->num_mixers; i++) {
 474		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
 475		if (err < 0)
 476			return err;
 477	}
 478	if (spec->multiout.dig_out_nid) {
 479		err = snd_hda_create_spdif_out_ctls(codec,
 480						    spec->multiout.dig_out_nid,
 481						    spec->multiout.dig_out_nid);
 482		if (err < 0)
 483			return err;
 484		err = snd_hda_create_spdif_share_sw(codec,
 485						    &spec->multiout);
 486		if (err < 0)
 487			return err;
 488		spec->multiout.share_spdif = 1;
 489	} 
 490	if (spec->dig_in_nid) {
 491		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
 492		if (err < 0)
 493			return err;
 494	}
 495
 496	/* if we have no master control, let's create it */
 497	if (spec->vmaster_nid &&
 498	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
 499		unsigned int vmaster_tlv[4];
 500		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
 501					HDA_OUTPUT, vmaster_tlv);
 502		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
 503					  vmaster_tlv, slave_pfxs,
 504					  "Playback Volume");
 505		if (err < 0)
 506			return err;
 507	}
 508	if (spec->vmaster_nid &&
 509	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
 510		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
 511					  NULL, slave_pfxs,
 512					  "Playback Switch");
 513		if (err < 0)
 514			return err;
 515	}
 516
 517	if (spec->input_mux) {
 518		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
 519		if (err < 0)
 520			return err;
 521	}
 522
 523	err = add_beep_ctls(codec);
 524	if (err < 0)
 525		return err;
 526
 
 
 
 527	return 0;
 528}
 
 
 
 529
 530static const struct hda_codec_ops conexant_patch_ops = {
 531	.build_controls = conexant_build_controls,
 532	.build_pcms = conexant_build_pcms,
 533	.init = conexant_init,
 534	.free = conexant_free,
 535	.set_power_state = conexant_set_power,
 536};
 537
 538static int patch_conexant_auto(struct hda_codec *codec);
 539/*
 540 * EAPD control
 541 * the private value = nid | (invert << 8)
 542 */
 543
 544#define cxt_eapd_info		snd_ctl_boolean_mono_info
 545
 546static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
 547			     struct snd_ctl_elem_value *ucontrol)
 548{
 549	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 550	struct conexant_spec *spec = codec->spec;
 551	int invert = (kcontrol->private_value >> 8) & 1;
 552	if (invert)
 553		ucontrol->value.integer.value[0] = !spec->cur_eapd;
 554	else
 555		ucontrol->value.integer.value[0] = spec->cur_eapd;
 556	return 0;
 557
 558}
 559
 560static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
 561			     struct snd_ctl_elem_value *ucontrol)
 562{
 563	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 564	struct conexant_spec *spec = codec->spec;
 565	int invert = (kcontrol->private_value >> 8) & 1;
 566	hda_nid_t nid = kcontrol->private_value & 0xff;
 567	unsigned int eapd;
 568
 569	eapd = !!ucontrol->value.integer.value[0];
 570	if (invert)
 571		eapd = !eapd;
 572	if (eapd == spec->cur_eapd)
 573		return 0;
 574	
 575	spec->cur_eapd = eapd;
 576	snd_hda_codec_write_cache(codec, nid,
 577				  0, AC_VERB_SET_EAPD_BTLENABLE,
 578				  eapd ? 0x02 : 0x00);
 579	return 1;
 580}
 581
 582/* controls for test mode */
 583#ifdef CONFIG_SND_DEBUG
 584
 585#define CXT_EAPD_SWITCH(xname, nid, mask) \
 586	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
 587	  .info = cxt_eapd_info, \
 588	  .get = cxt_eapd_get, \
 589	  .put = cxt_eapd_put, \
 590	  .private_value = nid | (mask<<16) }
 591
 592
 593
 594static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
 595				 struct snd_ctl_elem_info *uinfo)
 596{
 597	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 598	struct conexant_spec *spec = codec->spec;
 599	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
 600				    spec->num_channel_mode);
 601}
 602
 603static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
 604				struct snd_ctl_elem_value *ucontrol)
 605{
 606	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 607	struct conexant_spec *spec = codec->spec;
 608	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
 609				   spec->num_channel_mode,
 610				   spec->multiout.max_channels);
 611}
 612
 613static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
 614				struct snd_ctl_elem_value *ucontrol)
 615{
 616	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 617	struct conexant_spec *spec = codec->spec;
 618	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
 619				      spec->num_channel_mode,
 620				      &spec->multiout.max_channels);
 621	return err;
 622}
 623
 624#define CXT_PIN_MODE(xname, nid, dir) \
 625	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
 626	  .info = conexant_ch_mode_info, \
 627	  .get = conexant_ch_mode_get, \
 628	  .put = conexant_ch_mode_put, \
 629	  .private_value = nid | (dir<<16) }
 630
 631#endif /* CONFIG_SND_DEBUG */
 632
 633/* Conexant 5045 specific */
 634
 635static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
 636static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
 637static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
 638#define CXT5045_SPDIF_OUT	0x18
 639
 640static const struct hda_channel_mode cxt5045_modes[1] = {
 641	{ 2, NULL },
 642};
 643
 644static const struct hda_input_mux cxt5045_capture_source = {
 645	.num_items = 2,
 646	.items = {
 647		{ "Internal Mic", 0x1 },
 648		{ "Mic",          0x2 },
 649	}
 650};
 651
 652static const struct hda_input_mux cxt5045_capture_source_benq = {
 653	.num_items = 4,
 654	.items = {
 655		{ "Internal Mic", 0x1 },
 656		{ "Mic",          0x2 },
 657		{ "Line",         0x3 },
 658		{ "Mixer",        0x0 },
 659	}
 660};
 661
 662/* turn on/off EAPD (+ mute HP) as a master switch */
 663static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
 664				    struct snd_ctl_elem_value *ucontrol)
 665{
 666	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 667	struct conexant_spec *spec = codec->spec;
 668	unsigned int bits;
 669
 670	if (!cxt_eapd_put(kcontrol, ucontrol))
 671		return 0;
 672
 673	/* toggle internal speakers mute depending of presence of
 674	 * the headphone jack
 675	 */
 676	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
 677	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
 678				 HDA_AMP_MUTE, bits);
 679
 680	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
 681	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
 682				 HDA_AMP_MUTE, bits);
 683	return 1;
 684}
 685
 686/* bind volumes of both NID 0x10 and 0x11 */
 687static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
 688	.ops = &snd_hda_bind_vol,
 689	.values = {
 690		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
 691		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
 692		0
 693	},
 694};
 695
 696/* toggle input of built-in and mic jack appropriately */
 697static void cxt5045_hp_automic(struct hda_codec *codec)
 698{
 699	static const struct hda_verb mic_jack_on[] = {
 700		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
 701		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
 702		{}
 703	};
 704	static const struct hda_verb mic_jack_off[] = {
 705		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
 706		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
 707		{}
 708	};
 709	unsigned int present;
 710
 711	present = snd_hda_jack_detect(codec, 0x12);
 712	if (present)
 713		snd_hda_sequence_write(codec, mic_jack_on);
 714	else
 715		snd_hda_sequence_write(codec, mic_jack_off);
 716}
 717
 718
 719/* mute internal speaker if HP is plugged */
 720static void cxt5045_hp_automute(struct hda_codec *codec)
 721{
 722	struct conexant_spec *spec = codec->spec;
 723	unsigned int bits;
 724
 725	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
 726
 727	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 
 728	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
 729				 HDA_AMP_MUTE, bits);
 730}
 731
 732/* unsolicited event for HP jack sensing */
 733static void cxt5045_hp_unsol_event(struct hda_codec *codec,
 734				   unsigned int res)
 735{
 736	res >>= 26;
 737	switch (res) {
 738	case CONEXANT_HP_EVENT:
 739		cxt5045_hp_automute(codec);
 740		break;
 741	case CONEXANT_MIC_EVENT:
 742		cxt5045_hp_automic(codec);
 743		break;
 744
 
 
 
 
 
 
 
 
 745	}
 746}
 747
 748static const struct snd_kcontrol_new cxt5045_mixers[] = {
 749	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
 750	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
 751	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
 752	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
 753	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
 754	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
 755	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
 756	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
 757	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
 758	{
 759		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 760		.name = "Master Playback Switch",
 761		.info = cxt_eapd_info,
 762		.get = cxt_eapd_get,
 763		.put = cxt5045_hp_master_sw_put,
 764		.private_value = 0x10,
 765	},
 766
 767	{}
 768};
 769
 770static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
 771	HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
 772	HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
 773
 774	{}
 775};
 776
 777static const struct hda_verb cxt5045_init_verbs[] = {
 778	/* Line in, Mic */
 779	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
 780	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
 781	/* HP, Amp  */
 782	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
 783	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
 784	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
 785	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
 786	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
 787	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
 788	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
 789	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
 790	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
 791	/* Record selector: Internal mic */
 792	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
 793	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
 794	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
 795	/* SPDIF route: PCM */
 796	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
 797	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
 798	/* EAPD */
 799	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 
 800	{ } /* end */
 801};
 802
 803static const struct hda_verb cxt5045_benq_init_verbs[] = {
 804	/* Internal Mic, Mic */
 805	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
 806	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
 807	/* Line In,HP, Amp  */
 808	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
 809	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
 810	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
 811	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
 812	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
 813	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
 814	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
 815	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
 816	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
 817	/* Record selector: Internal mic */
 818	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
 819	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
 820	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
 821	/* SPDIF route: PCM */
 822	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
 823	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
 824	/* EAPD */
 825	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
 826	{ } /* end */
 827};
 828
 829static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
 830	/* pin sensing on HP jack */
 831	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
 832	{ } /* end */
 833};
 834
 835static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
 836	/* pin sensing on HP jack */
 837	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
 838	{ } /* end */
 839};
 840
 841#ifdef CONFIG_SND_DEBUG
 842/* Test configuration for debugging, modelled after the ALC260 test
 843 * configuration.
 844 */
 845static const struct hda_input_mux cxt5045_test_capture_source = {
 846	.num_items = 5,
 847	.items = {
 848		{ "MIXER", 0x0 },
 849		{ "MIC1 pin", 0x1 },
 850		{ "LINE1 pin", 0x2 },
 851		{ "HP-OUT pin", 0x3 },
 852		{ "CD pin", 0x4 },
 853        },
 854};
 855
 856static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
 857
 858	/* Output controls */
 859	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
 860	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
 861	HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
 862	HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
 863	HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
 864	HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
 865	
 866	/* Modes for retasking pin widgets */
 867	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
 868	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
 869
 870	/* EAPD Switch Control */
 871	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
 872
 873	/* Loopback mixer controls */
 874
 875	HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
 876	HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
 877	HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
 878	HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
 879	HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
 880	HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
 881	HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
 882	HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
 883	HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
 884	HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
 885	{
 886		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 887		.name = "Input Source",
 888		.info = conexant_mux_enum_info,
 889		.get = conexant_mux_enum_get,
 890		.put = conexant_mux_enum_put,
 891	},
 892	/* Audio input controls */
 893	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
 894	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
 895	{ } /* end */
 896};
 897
 898static const struct hda_verb cxt5045_test_init_verbs[] = {
 899	/* Set connections */
 900	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
 901	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
 902	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
 903	/* Enable retasking pins as output, initially without power amp */
 904	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
 905	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
 906
 907	/* Disable digital (SPDIF) pins initially, but users can enable
 908	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
 909	 * payload also sets the generation to 0, output to be in "consumer"
 910	 * PCM format, copyright asserted, no pre-emphasis and no validity
 911	 * control.
 912	 */
 913	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
 914	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
 915
 916	/* Unmute retasking pin widget output buffers since the default
 917	 * state appears to be output.  As the pin mode is changed by the
 918	 * user the pin mode control will take care of enabling the pin's
 919	 * input/output buffers as needed.
 920	 */
 921	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
 922	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
 923
 924	/* Mute capture amp left and right */
 925	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
 926
 927	/* Set ADC connection select to match default mixer setting (mic1
 928	 * pin)
 929	 */
 930	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
 931	{0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
 932
 933	/* Mute all inputs to mixer widget (even unconnected ones) */
 934	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
 935	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
 936	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
 937	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
 938	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
 939
 940	{ }
 941};
 942#endif
 943
 944
 945/* initialize jack-sensing, too */
 946static int cxt5045_init(struct hda_codec *codec)
 947{
 948	conexant_init(codec);
 949	cxt5045_hp_automute(codec);
 950	return 0;
 951}
 952
 953
 954enum {
 955	CXT5045_LAPTOP_HPSENSE,
 956	CXT5045_LAPTOP_MICSENSE,
 957	CXT5045_LAPTOP_HPMICSENSE,
 958	CXT5045_BENQ,
 959#ifdef CONFIG_SND_DEBUG
 960	CXT5045_TEST,
 961#endif
 962	CXT5045_AUTO,
 963	CXT5045_MODELS
 964};
 965
 966static const char * const cxt5045_models[CXT5045_MODELS] = {
 967	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
 968	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
 969	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
 970	[CXT5045_BENQ]			= "benq",
 971#ifdef CONFIG_SND_DEBUG
 972	[CXT5045_TEST]		= "test",
 973#endif
 974	[CXT5045_AUTO]			= "auto",
 975};
 976
 977static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
 978	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
 979	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
 980	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
 981	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
 982		      CXT5045_LAPTOP_HPMICSENSE),
 983	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
 984	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
 985	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
 986	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
 987			   CXT5045_LAPTOP_HPMICSENSE),
 988	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
 989	{}
 990};
 991
 992static int patch_cxt5045(struct hda_codec *codec)
 993{
 994	struct conexant_spec *spec;
 995	int board_config;
 996
 997	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
 998						  cxt5045_models,
 999						  cxt5045_cfg_tbl);
1000	if (board_config < 0)
1001		board_config = CXT5045_AUTO; /* model=auto as default */
1002	if (board_config == CXT5045_AUTO)
1003		return patch_conexant_auto(codec);
1004
1005	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1006	if (!spec)
1007		return -ENOMEM;
1008	codec->spec = spec;
1009	codec->single_adc_amp = 1;
1010
1011	spec->multiout.max_channels = 2;
1012	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1013	spec->multiout.dac_nids = cxt5045_dac_nids;
1014	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1015	spec->num_adc_nids = 1;
1016	spec->adc_nids = cxt5045_adc_nids;
1017	spec->capsrc_nids = cxt5045_capsrc_nids;
1018	spec->input_mux = &cxt5045_capture_source;
1019	spec->num_mixers = 1;
1020	spec->mixers[0] = cxt5045_mixers;
1021	spec->num_init_verbs = 1;
1022	spec->init_verbs[0] = cxt5045_init_verbs;
1023	spec->spdif_route = 0;
1024	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1025	spec->channel_mode = cxt5045_modes;
1026
1027	set_beep_amp(spec, 0x16, 0, 1);
1028
1029	codec->patch_ops = conexant_patch_ops;
1030
1031	switch (board_config) {
1032	case CXT5045_LAPTOP_HPSENSE:
1033		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1034		spec->input_mux = &cxt5045_capture_source;
1035		spec->num_init_verbs = 2;
1036		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1037		spec->mixers[0] = cxt5045_mixers;
1038		codec->patch_ops.init = cxt5045_init;
1039		break;
1040	case CXT5045_LAPTOP_MICSENSE:
1041		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1042		spec->input_mux = &cxt5045_capture_source;
1043		spec->num_init_verbs = 2;
1044		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1045		spec->mixers[0] = cxt5045_mixers;
1046		codec->patch_ops.init = cxt5045_init;
1047		break;
1048	default:
1049	case CXT5045_LAPTOP_HPMICSENSE:
1050		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1051		spec->input_mux = &cxt5045_capture_source;
1052		spec->num_init_verbs = 3;
1053		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1054		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1055		spec->mixers[0] = cxt5045_mixers;
1056		codec->patch_ops.init = cxt5045_init;
1057		break;
1058	case CXT5045_BENQ:
1059		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1060		spec->input_mux = &cxt5045_capture_source_benq;
1061		spec->num_init_verbs = 1;
1062		spec->init_verbs[0] = cxt5045_benq_init_verbs;
1063		spec->mixers[0] = cxt5045_mixers;
1064		spec->mixers[1] = cxt5045_benq_mixers;
1065		spec->num_mixers = 2;
1066		codec->patch_ops.init = cxt5045_init;
1067		break;
1068#ifdef CONFIG_SND_DEBUG
1069	case CXT5045_TEST:
1070		spec->input_mux = &cxt5045_test_capture_source;
1071		spec->mixers[0] = cxt5045_test_mixer;
1072		spec->init_verbs[0] = cxt5045_test_init_verbs;
1073		break;
1074		
1075#endif	
1076	}
1077
1078	switch (codec->subsystem_id >> 16) {
1079	case 0x103c:
1080	case 0x1631:
1081	case 0x1734:
1082	case 0x17aa:
1083		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1084		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1085		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1086		 */
1087		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1088					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1089					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1090					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1091					  (1 << AC_AMPCAP_MUTE_SHIFT));
1092		break;
1093	}
1094
1095	if (spec->beep_amp)
1096		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
1097
1098	return 0;
1099}
1100
1101
1102/* Conexant 5047 specific */
1103#define CXT5047_SPDIF_OUT	0x11
1104
1105static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1106static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1107static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1108
1109static const struct hda_channel_mode cxt5047_modes[1] = {
1110	{ 2, NULL },
1111};
1112
1113static const struct hda_input_mux cxt5047_toshiba_capture_source = {
1114	.num_items = 2,
1115	.items = {
1116		{ "ExtMic", 0x2 },
1117		{ "Line-In", 0x1 },
1118	}
1119};
1120
1121/* turn on/off EAPD (+ mute HP) as a master switch */
1122static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1123				    struct snd_ctl_elem_value *ucontrol)
1124{
1125	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1126	struct conexant_spec *spec = codec->spec;
1127	unsigned int bits;
1128
1129	if (!cxt_eapd_put(kcontrol, ucontrol))
1130		return 0;
1131
1132	/* toggle internal speakers mute depending of presence of
1133	 * the headphone jack
1134	 */
1135	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1136	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1137	 * pin widgets unlike other codecs.  In this case, we need to
1138	 * set index 0x01 for the volume from the mixer amp 0x19.
1139	 */
1140	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1141				 HDA_AMP_MUTE, bits);
1142	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1143	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1144				 HDA_AMP_MUTE, bits);
1145	return 1;
1146}
1147
1148/* mute internal speaker if HP is plugged */
1149static void cxt5047_hp_automute(struct hda_codec *codec)
 
1150{
 
1151	struct conexant_spec *spec = codec->spec;
1152	unsigned int bits;
1153
1154	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1155
1156	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1157	/* See the note in cxt5047_hp_master_sw_put */
1158	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1159				 HDA_AMP_MUTE, bits);
1160}
1161
1162/* toggle input of built-in and mic jack appropriately */
1163static void cxt5047_hp_automic(struct hda_codec *codec)
1164{
1165	static const struct hda_verb mic_jack_on[] = {
1166		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1167		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1168		{}
1169	};
1170	static const struct hda_verb mic_jack_off[] = {
1171		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1172		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1173		{}
1174	};
1175	unsigned int present;
1176
1177	present = snd_hda_jack_detect(codec, 0x15);
1178	if (present)
1179		snd_hda_sequence_write(codec, mic_jack_on);
1180	else
1181		snd_hda_sequence_write(codec, mic_jack_off);
1182}
1183
1184/* unsolicited event for HP jack sensing */
1185static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1186				  unsigned int res)
1187{
1188	switch (res >> 26) {
1189	case CONEXANT_HP_EVENT:
1190		cxt5047_hp_automute(codec);
1191		break;
1192	case CONEXANT_MIC_EVENT:
1193		cxt5047_hp_automic(codec);
1194		break;
1195	}
1196}
1197
1198static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1199	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1200	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1201	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1202	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1203	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1204	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1205	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1206	{
1207		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1208		.name = "Master Playback Switch",
1209		.info = cxt_eapd_info,
1210		.get = cxt_eapd_get,
1211		.put = cxt5047_hp_master_sw_put,
1212		.private_value = 0x13,
1213	},
1214
1215	{}
1216};
1217
1218static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1219	/* See the note in cxt5047_hp_master_sw_put */
1220	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1221	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1222	{}
1223};
1224
1225static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1226	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1227	{ } /* end */
1228};
1229
1230static const struct hda_verb cxt5047_init_verbs[] = {
1231	/* Line in, Mic, Built-in Mic */
1232	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1233	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1234	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1235	/* HP, Speaker  */
1236	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1237	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1238	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1239	/* Record selector: Mic */
1240	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1241	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1242	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1243	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1244	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1245	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1246	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1247	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1248	/* SPDIF route: PCM */
1249	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1250	/* Enable unsolicited events */
1251	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1252	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1253	{ } /* end */
1254};
1255
1256/* configuration for Toshiba Laptops */
1257static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
1258	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1259	{}
1260};
1261
1262/* Test configuration for debugging, modelled after the ALC260 test
1263 * configuration.
1264 */
1265#ifdef CONFIG_SND_DEBUG
1266static const struct hda_input_mux cxt5047_test_capture_source = {
1267	.num_items = 4,
1268	.items = {
1269		{ "LINE1 pin", 0x0 },
1270		{ "MIC1 pin", 0x1 },
1271		{ "MIC2 pin", 0x2 },
1272		{ "CD pin", 0x3 },
1273        },
1274};
1275
1276static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1277
1278	/* Output only controls */
1279	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1280	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1281	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1282	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1283	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1284	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1285	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1286	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1287	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1288	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1289	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1290	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1291
1292	/* Modes for retasking pin widgets */
1293	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1294	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1295
1296	/* EAPD Switch Control */
1297	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1298
1299	/* Loopback mixer controls */
1300	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1301	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1302	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1303	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1304	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1305	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1306	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1307	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1308
1309	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1310	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1311	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1312	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1313	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1314	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1315	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1316	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1317	{
1318		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1319		.name = "Input Source",
1320		.info = conexant_mux_enum_info,
1321		.get = conexant_mux_enum_get,
1322		.put = conexant_mux_enum_put,
1323	},
1324	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1325
1326	{ } /* end */
1327};
1328
1329static const struct hda_verb cxt5047_test_init_verbs[] = {
1330	/* Enable retasking pins as output, initially without power amp */
1331	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1332	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1333	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1334
1335	/* Disable digital (SPDIF) pins initially, but users can enable
1336	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1337	 * payload also sets the generation to 0, output to be in "consumer"
1338	 * PCM format, copyright asserted, no pre-emphasis and no validity
1339	 * control.
1340	 */
1341	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1342
1343	/* Ensure mic1, mic2, line1 pin widgets take input from the 
1344	 * OUT1 sum bus when acting as an output.
1345	 */
1346	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1347	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1348
1349	/* Start with output sum widgets muted and their output gains at min */
1350	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1351	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1352
1353	/* Unmute retasking pin widget output buffers since the default
1354	 * state appears to be output.  As the pin mode is changed by the
1355	 * user the pin mode control will take care of enabling the pin's
1356	 * input/output buffers as needed.
1357	 */
1358	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1359	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1360	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1361
1362	/* Mute capture amp left and right */
1363	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1364
1365	/* Set ADC connection select to match default mixer setting (mic1
1366	 * pin)
1367	 */
1368	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1369
1370	/* Mute all inputs to mixer widget (even unconnected ones) */
1371	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1372	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1373	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1374	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1375	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1376	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1377	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1378	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1379
1380	{ }
1381};
1382#endif
1383
1384
1385/* initialize jack-sensing, too */
1386static int cxt5047_hp_init(struct hda_codec *codec)
1387{
1388	conexant_init(codec);
1389	cxt5047_hp_automute(codec);
1390	return 0;
1391}
1392
1393
1394enum {
1395	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1396	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1397	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1398#ifdef CONFIG_SND_DEBUG
1399	CXT5047_TEST,
1400#endif
1401	CXT5047_AUTO,
1402	CXT5047_MODELS
1403};
1404
1405static const char * const cxt5047_models[CXT5047_MODELS] = {
1406	[CXT5047_LAPTOP]	= "laptop",
1407	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1408	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1409#ifdef CONFIG_SND_DEBUG
1410	[CXT5047_TEST]		= "test",
1411#endif
1412	[CXT5047_AUTO]		= "auto",
1413};
1414
1415static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1416	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1417	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1418			   CXT5047_LAPTOP),
1419	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1420	{}
1421};
1422
1423static int patch_cxt5047(struct hda_codec *codec)
1424{
1425	struct conexant_spec *spec;
1426	int board_config;
1427
1428	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1429						  cxt5047_models,
1430						  cxt5047_cfg_tbl);
1431	if (board_config < 0)
1432		board_config = CXT5047_AUTO; /* model=auto as default */
1433	if (board_config == CXT5047_AUTO)
1434		return patch_conexant_auto(codec);
1435
1436	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1437	if (!spec)
1438		return -ENOMEM;
1439	codec->spec = spec;
1440	codec->pin_amp_workaround = 1;
1441
1442	spec->multiout.max_channels = 2;
1443	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1444	spec->multiout.dac_nids = cxt5047_dac_nids;
1445	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1446	spec->num_adc_nids = 1;
1447	spec->adc_nids = cxt5047_adc_nids;
1448	spec->capsrc_nids = cxt5047_capsrc_nids;
1449	spec->num_mixers = 1;
1450	spec->mixers[0] = cxt5047_base_mixers;
1451	spec->num_init_verbs = 1;
1452	spec->init_verbs[0] = cxt5047_init_verbs;
1453	spec->spdif_route = 0;
1454	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1455	spec->channel_mode = cxt5047_modes,
1456
1457	codec->patch_ops = conexant_patch_ops;
1458
1459	switch (board_config) {
1460	case CXT5047_LAPTOP:
1461		spec->num_mixers = 2;
1462		spec->mixers[1] = cxt5047_hp_spk_mixers;
1463		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1464		break;
1465	case CXT5047_LAPTOP_HP:
1466		spec->num_mixers = 2;
1467		spec->mixers[1] = cxt5047_hp_only_mixers;
1468		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1469		codec->patch_ops.init = cxt5047_hp_init;
1470		break;
1471	case CXT5047_LAPTOP_EAPD:
1472		spec->input_mux = &cxt5047_toshiba_capture_source;
1473		spec->num_mixers = 2;
1474		spec->mixers[1] = cxt5047_hp_spk_mixers;
1475		spec->num_init_verbs = 2;
1476		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1477		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1478		break;
1479#ifdef CONFIG_SND_DEBUG
1480	case CXT5047_TEST:
1481		spec->input_mux = &cxt5047_test_capture_source;
1482		spec->mixers[0] = cxt5047_test_mixer;
1483		spec->init_verbs[0] = cxt5047_test_init_verbs;
1484		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1485#endif	
1486	}
1487	spec->vmaster_nid = 0x13;
1488
1489	switch (codec->subsystem_id >> 16) {
1490	case 0x103c:
1491		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1492		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1493		 * with 0 dB offset 0x17)
1494		 */
1495		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1496					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1497					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1498					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1499					  (1 << AC_AMPCAP_MUTE_SHIFT));
1500		break;
1501	}
1502
 
 
 
1503	return 0;
1504}
1505
1506/* Conexant 5051 specific */
1507static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1508static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1509
1510static const struct hda_channel_mode cxt5051_modes[1] = {
1511	{ 2, NULL },
1512};
1513
1514static void cxt5051_update_speaker(struct hda_codec *codec)
1515{
1516	struct conexant_spec *spec = codec->spec;
1517	unsigned int pinctl;
1518	/* headphone pin */
1519	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1520	snd_hda_set_pin_ctl(codec, 0x16, pinctl);
1521	/* speaker pin */
1522	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1523	snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
1524	/* on ideapad there is an additional speaker (subwoofer) to mute */
1525	if (spec->ideapad)
1526		snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
1527}
1528
1529/* turn on/off EAPD (+ mute HP) as a master switch */
1530static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1531				    struct snd_ctl_elem_value *ucontrol)
1532{
1533	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1534
1535	if (!cxt_eapd_put(kcontrol, ucontrol))
1536		return 0;
1537	cxt5051_update_speaker(codec);
1538	return 1;
1539}
1540
1541/* toggle input of built-in and mic jack appropriately */
1542static void cxt5051_portb_automic(struct hda_codec *codec)
1543{
1544	struct conexant_spec *spec = codec->spec;
1545	unsigned int present;
1546
1547	if (!(spec->auto_mic & AUTO_MIC_PORTB))
1548		return;
1549	present = snd_hda_jack_detect(codec, 0x17);
1550	snd_hda_codec_write(codec, 0x14, 0,
1551			    AC_VERB_SET_CONNECT_SEL,
1552			    present ? 0x01 : 0x00);
1553}
1554
1555/* switch the current ADC according to the jack state */
1556static void cxt5051_portc_automic(struct hda_codec *codec)
1557{
1558	struct conexant_spec *spec = codec->spec;
1559	unsigned int present;
1560	hda_nid_t new_adc;
1561
1562	if (!(spec->auto_mic & AUTO_MIC_PORTC))
1563		return;
1564	present = snd_hda_jack_detect(codec, 0x18);
1565	if (present)
1566		spec->cur_adc_idx = 1;
1567	else
1568		spec->cur_adc_idx = 0;
1569	new_adc = spec->adc_nids[spec->cur_adc_idx];
1570	if (spec->cur_adc && spec->cur_adc != new_adc) {
1571		/* stream is running, let's swap the current ADC */
1572		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1573		spec->cur_adc = new_adc;
1574		snd_hda_codec_setup_stream(codec, new_adc,
1575					   spec->cur_adc_stream_tag, 0,
1576					   spec->cur_adc_format);
1577	}
1578}
1579
1580/* mute internal speaker if HP is plugged */
1581static void cxt5051_hp_automute(struct hda_codec *codec)
1582{
1583	struct conexant_spec *spec = codec->spec;
1584
1585	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1586	cxt5051_update_speaker(codec);
1587}
1588
1589/* unsolicited event for HP jack sensing */
1590static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1591				   unsigned int res)
1592{
1593	switch (res >> 26) {
1594	case CONEXANT_HP_EVENT:
1595		cxt5051_hp_automute(codec);
1596		break;
1597	case CXT5051_PORTB_EVENT:
1598		cxt5051_portb_automic(codec);
1599		break;
1600	case CXT5051_PORTC_EVENT:
1601		cxt5051_portc_automic(codec);
1602		break;
1603	}
1604}
1605
1606static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1607	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1608	{
1609		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1610		.name = "Master Playback Switch",
1611		.info = cxt_eapd_info,
1612		.get = cxt_eapd_get,
1613		.put = cxt5051_hp_master_sw_put,
1614		.private_value = 0x1a,
1615	},
1616	{}
1617};
1618
1619static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1620	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1621	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1622	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1623	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1624	HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1625	HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
1626	{}
1627};
1628
1629static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1630	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1631	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1632	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1633	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1634	{}
1635};
1636
1637static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1638	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1639	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1640	{}
1641};
1642
1643static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1644	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1645	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1646	{}
1647};
1648
1649static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1650	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1651	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1652	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1653	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1654	{}
1655};
1656
1657static const struct hda_verb cxt5051_init_verbs[] = {
1658	/* Line in, Mic */
1659	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1660	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1661	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1662	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1663	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1664	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1665	/* SPK  */
1666	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1667	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1668	/* HP, Amp  */
1669	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1670	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1671	/* DAC1 */	
1672	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1673	/* Record selector: Internal mic */
1674	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1675	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1676	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1677	/* SPDIF route: PCM */
1678	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1679	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1680	/* EAPD */
1681	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 
1682	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1683	{ } /* end */
1684};
1685
1686static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1687	/* Line in, Mic */
1688	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1689	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1690	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1691	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1692	/* SPK  */
1693	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1694	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1695	/* HP, Amp  */
1696	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1697	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1698	/* DAC1 */
1699	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1700	/* Record selector: Internal mic */
1701	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1702	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1703	/* SPDIF route: PCM */
1704	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1705	/* EAPD */
1706	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1707	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1708	{ } /* end */
1709};
1710
1711static const struct hda_verb cxt5051_f700_init_verbs[] = {
1712	/* Line in, Mic */
1713	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1714	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1715	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1716	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1717	/* SPK  */
1718	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1719	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1720	/* HP, Amp  */
1721	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1722	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1723	/* DAC1 */
1724	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1725	/* Record selector: Internal mic */
1726	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1727	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1728	/* SPDIF route: PCM */
1729	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1730	/* EAPD */
1731	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1732	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1733	{ } /* end */
1734};
1735
1736static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1737				 unsigned int event)
1738{
1739	snd_hda_codec_write(codec, nid, 0,
1740			    AC_VERB_SET_UNSOLICITED_ENABLE,
1741			    AC_USRSP_EN | event);
1742}
1743
1744static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1745	/* Subwoofer */
1746	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1747	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1748	{ } /* end */
1749};
1750
1751/* initialize jack-sensing, too */
1752static int cxt5051_init(struct hda_codec *codec)
1753{
1754	struct conexant_spec *spec = codec->spec;
1755
1756	conexant_init(codec);
1757
1758	if (spec->auto_mic & AUTO_MIC_PORTB)
1759		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1760	if (spec->auto_mic & AUTO_MIC_PORTC)
1761		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1762
1763	if (codec->patch_ops.unsol_event) {
1764		cxt5051_hp_automute(codec);
1765		cxt5051_portb_automic(codec);
1766		cxt5051_portc_automic(codec);
1767	}
1768	return 0;
1769}
1770
1771
1772enum {
1773	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1774	CXT5051_HP,	/* no docking */
1775	CXT5051_HP_DV6736,	/* HP without mic switch */
1776	CXT5051_F700,       /* HP Compaq Presario F700 */
1777	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1778	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
1779	CXT5051_AUTO,		/* auto-parser */
1780	CXT5051_MODELS
1781};
1782
1783static const char *const cxt5051_models[CXT5051_MODELS] = {
1784	[CXT5051_LAPTOP]	= "laptop",
1785	[CXT5051_HP]		= "hp",
1786	[CXT5051_HP_DV6736]	= "hp-dv6736",
1787	[CXT5051_F700]          = "hp-700",
1788	[CXT5051_TOSHIBA]	= "toshiba",
1789	[CXT5051_IDEAPAD]	= "ideapad",
1790	[CXT5051_AUTO]		= "auto",
1791};
1792
1793static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1794	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1795	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1796	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1797	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1798	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1799		      CXT5051_LAPTOP),
1800	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1801	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1802	{}
1803};
1804
1805static int patch_cxt5051(struct hda_codec *codec)
1806{
1807	struct conexant_spec *spec;
1808	int board_config;
1809
1810	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1811						  cxt5051_models,
1812						  cxt5051_cfg_tbl);
1813	if (board_config < 0)
1814		board_config = CXT5051_AUTO; /* model=auto as default */
1815	if (board_config == CXT5051_AUTO)
1816		return patch_conexant_auto(codec);
1817
1818	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1819	if (!spec)
1820		return -ENOMEM;
1821	codec->spec = spec;
1822	codec->pin_amp_workaround = 1;
1823
1824	codec->patch_ops = conexant_patch_ops;
1825	codec->patch_ops.init = cxt5051_init;
1826
1827	spec->multiout.max_channels = 2;
1828	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1829	spec->multiout.dac_nids = cxt5051_dac_nids;
1830	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1831	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1832	spec->adc_nids = cxt5051_adc_nids;
1833	spec->num_mixers = 2;
1834	spec->mixers[0] = cxt5051_capture_mixers;
1835	spec->mixers[1] = cxt5051_playback_mixers;
1836	spec->num_init_verbs = 1;
1837	spec->init_verbs[0] = cxt5051_init_verbs;
1838	spec->spdif_route = 0;
1839	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1840	spec->channel_mode = cxt5051_modes;
1841	spec->cur_adc = 0;
1842	spec->cur_adc_idx = 0;
1843
1844	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1845
1846	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1847
1848	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1849	switch (board_config) {
1850	case CXT5051_HP:
1851		spec->mixers[0] = cxt5051_hp_mixers;
1852		break;
1853	case CXT5051_HP_DV6736:
1854		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1855		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1856		spec->auto_mic = 0;
1857		break;
1858	case CXT5051_F700:
1859		spec->init_verbs[0] = cxt5051_f700_init_verbs;
1860		spec->mixers[0] = cxt5051_f700_mixers;
1861		spec->auto_mic = 0;
1862		break;
1863	case CXT5051_TOSHIBA:
1864		spec->mixers[0] = cxt5051_toshiba_mixers;
1865		spec->auto_mic = AUTO_MIC_PORTB;
1866		break;
1867	case CXT5051_IDEAPAD:
1868		spec->init_verbs[spec->num_init_verbs++] =
1869			cxt5051_ideapad_init_verbs;
1870		spec->ideapad = 1;
1871		break;
1872	}
1873
1874	if (spec->beep_amp)
1875		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
1876
1877	return 0;
1878}
1879
1880/* Conexant 5066 specific */
1881
1882static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1883static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1884static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1885static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
1886
1887static const struct hda_channel_mode cxt5066_modes[1] = {
1888	{ 2, NULL },
1889};
1890
1891#define HP_PRESENT_PORT_A	(1 << 0)
1892#define HP_PRESENT_PORT_D	(1 << 1)
1893#define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
1894#define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
1895
1896static void cxt5066_update_speaker(struct hda_codec *codec)
1897{
1898	struct conexant_spec *spec = codec->spec;
1899	unsigned int pinctl;
1900
1901	codec_dbg(codec,
1902		  "CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1903		    spec->hp_present, spec->cur_eapd);
1904
1905	/* Port A (HP) */
1906	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
1907	snd_hda_set_pin_ctl(codec, 0x19, pinctl);
1908
1909	/* Port D (HP/LO) */
1910	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1911	if (spec->dell_automute || spec->thinkpad) {
1912		/* Mute if Port A is connected */
1913		if (hp_port_a_present(spec))
1914			pinctl = 0;
1915	} else {
1916		/* Thinkpad/Dell doesn't give pin-D status */
1917		if (!hp_port_d_present(spec))
1918			pinctl = 0;
1919	}
1920	snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
1921
1922	/* CLASS_D AMP */
1923	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1924	snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
1925}
1926
1927/* turn on/off EAPD (+ mute HP) as a master switch */
1928static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1929				    struct snd_ctl_elem_value *ucontrol)
1930{
1931	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1932
1933	if (!cxt_eapd_put(kcontrol, ucontrol))
1934		return 0;
1935
1936	cxt5066_update_speaker(codec);
1937	return 1;
1938}
1939
1940/* toggle input of built-in digital mic and mic jack appropriately */
1941static void cxt5066_vostro_automic(struct hda_codec *codec)
1942{
1943	unsigned int present;
1944
1945	struct hda_verb ext_mic_present[] = {
1946		/* enable external mic, port B */
1947		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1948
1949		/* switch to external mic input */
1950		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
1951		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
1952
1953		/* disable internal digital mic */
1954		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1955		{}
1956	};
1957	static const struct hda_verb ext_mic_absent[] = {
1958		/* enable internal mic, port C */
1959		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1960
1961		/* switch to internal mic input */
1962		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
1963
1964		/* disable external mic, port B */
1965		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1966		{}
1967	};
1968
1969	present = snd_hda_jack_detect(codec, 0x1a);
1970	if (present) {
1971		codec_dbg(codec, "CXT5066: external microphone detected\n");
1972		snd_hda_sequence_write(codec, ext_mic_present);
1973	} else {
1974		codec_dbg(codec, "CXT5066: external microphone absent\n");
1975		snd_hda_sequence_write(codec, ext_mic_absent);
1976	}
1977}
1978
1979/* toggle input of built-in digital mic and mic jack appropriately */
1980static void cxt5066_ideapad_automic(struct hda_codec *codec)
1981{
1982	unsigned int present;
1983
1984	struct hda_verb ext_mic_present[] = {
1985		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
1986		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1987		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1988		{}
1989	};
1990	static const struct hda_verb ext_mic_absent[] = {
1991		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
1992		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1993		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1994		{}
1995	};
1996
1997	present = snd_hda_jack_detect(codec, 0x1b);
1998	if (present) {
1999		codec_dbg(codec, "CXT5066: external microphone detected\n");
2000		snd_hda_sequence_write(codec, ext_mic_present);
2001	} else {
2002		codec_dbg(codec, "CXT5066: external microphone absent\n");
2003		snd_hda_sequence_write(codec, ext_mic_absent);
2004	}
2005}
2006
2007
2008/* toggle input of built-in digital mic and mic jack appropriately */
2009static void cxt5066_asus_automic(struct hda_codec *codec)
2010{
2011	unsigned int present;
2012
2013	present = snd_hda_jack_detect(codec, 0x1b);
2014	codec_dbg(codec, "CXT5066: external microphone present=%d\n", present);
2015	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2016			    present ? 1 : 0);
2017}
2018
2019
2020/* toggle input of built-in digital mic and mic jack appropriately */
2021static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2022{
2023	unsigned int present;
2024
2025	present = snd_hda_jack_detect(codec, 0x1b);
2026	codec_dbg(codec, "CXT5066: external microphone present=%d\n", present);
2027	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2028			    present ? 1 : 3);
2029}
2030
2031
2032/* toggle input of built-in digital mic and mic jack appropriately
2033   order is: external mic -> dock mic -> interal mic */
2034static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2035{
2036	unsigned int ext_present, dock_present;
2037
2038	static const struct hda_verb ext_mic_present[] = {
2039		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2040		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
2041		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2042		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2043		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2044		{}
2045	};
2046	static const struct hda_verb dock_mic_present[] = {
2047		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2048		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
2049		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2050		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2051		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2052		{}
2053	};
2054	static const struct hda_verb ext_mic_absent[] = {
2055		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2056		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2057		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2058		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2059		{}
2060	};
2061
2062	ext_present = snd_hda_jack_detect(codec, 0x1b);
2063	dock_present = snd_hda_jack_detect(codec, 0x1a);
2064	if (ext_present) {
2065		codec_dbg(codec, "CXT5066: external microphone detected\n");
2066		snd_hda_sequence_write(codec, ext_mic_present);
2067	} else if (dock_present) {
2068		codec_dbg(codec, "CXT5066: dock microphone detected\n");
2069		snd_hda_sequence_write(codec, dock_mic_present);
2070	} else {
2071		codec_dbg(codec, "CXT5066: external microphone absent\n");
2072		snd_hda_sequence_write(codec, ext_mic_absent);
2073	}
2074}
2075
2076/* mute internal speaker if HP is plugged */
2077static void cxt5066_hp_automute(struct hda_codec *codec)
2078{
2079	struct conexant_spec *spec = codec->spec;
2080	unsigned int portA, portD;
2081
2082	/* Port A */
2083	portA = snd_hda_jack_detect(codec, 0x19);
2084
2085	/* Port D */
2086	portD = snd_hda_jack_detect(codec, 0x1c);
2087
2088	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2089	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2090	codec_dbg(codec, "CXT5066: hp automute portA=%x portD=%x present=%d\n",
2091		portA, portD, spec->hp_present);
2092	cxt5066_update_speaker(codec);
2093}
2094
2095/* Dispatch the right mic autoswitch function */
2096static void cxt5066_automic(struct hda_codec *codec)
2097{
2098	struct conexant_spec *spec = codec->spec;
 
 
 
2099
2100	if (spec->dell_vostro)
2101		cxt5066_vostro_automic(codec);
2102	else if (spec->ideapad)
2103		cxt5066_ideapad_automic(codec);
2104	else if (spec->thinkpad)
2105		cxt5066_thinkpad_automic(codec);
2106	else if (spec->hp_laptop)
2107		cxt5066_hp_laptop_automic(codec);
2108	else if (spec->asus)
2109		cxt5066_asus_automic(codec);
2110}
2111
2112/* unsolicited event for jack sensing */
2113static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2114{
2115	codec_dbg(codec, "CXT5066: unsol event %x (%x)\n", res, res >> 26);
2116	switch (res >> 26) {
2117	case CONEXANT_HP_EVENT:
2118		cxt5066_hp_automute(codec);
2119		break;
2120	case CONEXANT_MIC_EVENT:
2121		cxt5066_automic(codec);
2122		break;
2123	}
2124}
2125
2126
2127static const struct hda_input_mux cxt5066_analog_mic_boost = {
2128	.num_items = 5,
2129	.items = {
2130		{ "0dB",  0 },
2131		{ "10dB", 1 },
2132		{ "20dB", 2 },
2133		{ "30dB", 3 },
2134		{ "40dB", 4 },
2135	},
2136};
2137
2138static void cxt5066_set_mic_boost(struct hda_codec *codec)
2139{
2140	struct conexant_spec *spec = codec->spec;
2141	snd_hda_codec_write_cache(codec, 0x17, 0,
2142		AC_VERB_SET_AMP_GAIN_MUTE,
2143		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2144			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2145	if (spec->ideapad || spec->thinkpad) {
2146		/* adjust the internal mic as well...it is not through 0x17 */
2147		snd_hda_codec_write_cache(codec, 0x23, 0,
2148			AC_VERB_SET_AMP_GAIN_MUTE,
2149			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2150				cxt5066_analog_mic_boost.
2151					items[spec->mic_boost].index);
2152	}
2153}
2154
2155static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2156					   struct snd_ctl_elem_info *uinfo)
2157{
2158	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2159}
2160
2161static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2162					  struct snd_ctl_elem_value *ucontrol)
2163{
2164	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2165	struct conexant_spec *spec = codec->spec;
2166	ucontrol->value.enumerated.item[0] = spec->mic_boost;
2167	return 0;
2168}
2169
2170static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2171					  struct snd_ctl_elem_value *ucontrol)
2172{
2173	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2174	struct conexant_spec *spec = codec->spec;
2175	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2176	unsigned int idx;
2177	idx = ucontrol->value.enumerated.item[0];
2178	if (idx >= imux->num_items)
2179		idx = imux->num_items - 1;
2180
2181	spec->mic_boost = idx;
2182	cxt5066_set_mic_boost(codec);
2183	return 1;
2184}
2185
2186static void conexant_check_dig_outs(struct hda_codec *codec,
2187				    const hda_nid_t *dig_pins,
2188				    int num_pins)
2189{
2190	struct conexant_spec *spec = codec->spec;
2191	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2192	int i;
2193
2194	for (i = 0; i < num_pins; i++, dig_pins++) {
2195		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2196		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2197			continue;
2198		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2199			continue;
2200	}
2201}
2202
2203static const struct hda_input_mux cxt5066_capture_source = {
2204	.num_items = 4,
2205	.items = {
2206		{ "Mic B", 0 },
2207		{ "Mic C", 1 },
2208		{ "Mic E", 2 },
2209		{ "Mic F", 3 },
2210	},
2211};
2212
2213static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2214	.ops = &snd_hda_bind_vol,
2215	.values = {
2216		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2217		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2218		0
2219	},
2220};
2221
2222static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2223	.ops = &snd_hda_bind_sw,
2224	.values = {
2225		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2226		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2227		0
2228	},
2229};
2230
2231static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2232	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2233	{}
2234};
2235
2236static const struct snd_kcontrol_new cxt5066_mixers[] = {
2237	{
2238		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2239		.name = "Master Playback Switch",
2240		.info = cxt_eapd_info,
2241		.get = cxt_eapd_get,
2242		.put = cxt5066_hp_master_sw_put,
2243		.private_value = 0x1d,
2244	},
2245
2246	{
2247		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2248		.name = "Analog Mic Boost Capture Enum",
2249		.info = cxt5066_mic_boost_mux_enum_info,
2250		.get = cxt5066_mic_boost_mux_enum_get,
2251		.put = cxt5066_mic_boost_mux_enum_put,
2252	},
2253
2254	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2255	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2256	{}
2257};
2258
2259static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2260	{
2261		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2262		.name = "Internal Mic Boost Capture Enum",
2263		.info = cxt5066_mic_boost_mux_enum_info,
2264		.get = cxt5066_mic_boost_mux_enum_get,
2265		.put = cxt5066_mic_boost_mux_enum_put,
2266		.private_value = 0x23 | 0x100,
2267	},
2268	{}
2269};
2270
2271static const struct hda_verb cxt5066_init_verbs[] = {
2272	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2273	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2274	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2275	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2276
2277	/* Speakers  */
2278	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2279	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2280
2281	/* HP, Amp  */
2282	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2283	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2284
2285	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2286	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2287
2288	/* DAC1 */
2289	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290
2291	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2292	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2293	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2294	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2295	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2296	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2297
2298	/* no digital microphone support yet */
2299	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2300
2301	/* Audio input selector */
2302	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2303
2304	/* SPDIF route: PCM */
2305	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2306	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2307
2308	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2309	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2310
2311	/* EAPD */
2312	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2313
2314	/* not handling these yet */
2315	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2316	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2317	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2318	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2319	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2320	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2321	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2322	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2323	{ } /* end */
2324};
2325
2326static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2327	/* Port A: headphones */
2328	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2329	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2330
2331	/* Port B: external microphone */
2332	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2333
2334	/* Port C: unused */
2335	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2336
2337	/* Port D: unused */
2338	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2339
2340	/* Port E: unused, but has primary EAPD */
2341	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2342	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2343
2344	/* Port F: unused */
2345	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2346
2347	/* Port G: internal speakers */
2348	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2349	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2350
2351	/* DAC1 */
2352	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2353
2354	/* DAC2: unused */
2355	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2356
2357	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2358	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2359	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2360	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2361	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2362	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2363	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2364	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2365	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2366	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2367	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2368	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2369
2370	/* Digital microphone port */
2371	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2372
2373	/* Audio input selectors */
2374	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2375	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2376
2377	/* Disable SPDIF */
2378	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2379	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2380
2381	/* enable unsolicited events for Port A and B */
2382	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2383	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2384	{ } /* end */
2385};
2386
2387static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2388	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2389	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2390	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2391	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2392
2393	/* Speakers  */
2394	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2395	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2396
2397	/* HP, Amp  */
2398	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2399	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2400
2401	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2402	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2403
2404	/* DAC1 */
2405	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2406
2407	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2408	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2409	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2410	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2411	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2412	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2413	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2414
2415	/* Audio input selector */
2416	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2417	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2418
2419	/* SPDIF route: PCM */
2420	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2421	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2422
2423	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2424	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2425
2426	/* internal microphone */
2427	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2428
2429	/* EAPD */
2430	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2431
2432	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2433	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2434	{ } /* end */
2435};
2436
2437static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2438	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2439	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2440
2441	/* Port G: internal speakers  */
2442	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2443	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2444
2445	/* Port A: HP, Amp  */
2446	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2447	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2448
2449	/* Port B: Mic Dock */
2450	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2451
2452	/* Port C: Mic */
2453	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2454
2455	/* Port D: HP Dock, Amp */
2456	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2457	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2458
2459	/* DAC1 */
2460	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2461
2462	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2463	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2464	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2465	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2466	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2467	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2468	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2469
2470	/* Audio input selector */
2471	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2472	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2473
2474	/* SPDIF route: PCM */
2475	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2476	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2477
2478	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2479	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2480
2481	/* internal microphone */
2482	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2483
2484	/* EAPD */
2485	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2486
2487	/* enable unsolicited events for Port A, B, C and D */
2488	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2489	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2490	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2491	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2492	{ } /* end */
2493};
2494
2495static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2496	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2497	{ } /* end */
2498};
2499
2500
2501static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2502	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2503	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2504	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2505	{ } /* end */
2506};
2507
2508/* initialize jack-sensing, too */
2509static int cxt5066_init(struct hda_codec *codec)
2510{
2511	codec_dbg(codec, "CXT5066: init\n");
2512	conexant_init(codec);
2513	if (codec->patch_ops.unsol_event) {
2514		cxt5066_hp_automute(codec);
2515		cxt5066_automic(codec);
2516	}
2517	cxt5066_set_mic_boost(codec);
2518	return 0;
2519}
2520
2521enum {
2522	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
2523	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
2524	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
2525	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
2526	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
2527	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
2528	CXT5066_HP_LAPTOP,      /* HP Laptop */
2529	CXT5066_AUTO,		/* BIOS auto-parser */
2530	CXT5066_MODELS
2531};
2532
2533static const char * const cxt5066_models[CXT5066_MODELS] = {
2534	[CXT5066_LAPTOP]	= "laptop",
2535	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
2536	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
2537	[CXT5066_IDEAPAD]	= "ideapad",
2538	[CXT5066_THINKPAD]	= "thinkpad",
2539	[CXT5066_ASUS]		= "asus",
2540	[CXT5066_HP_LAPTOP]	= "hp-laptop",
2541	[CXT5066_AUTO]		= "auto",
2542};
2543
2544static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2545	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
2546	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
2547	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
2548	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
2549	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2550	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2551	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
2552	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
2553	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
2554	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
2555	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
2556	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2557		      CXT5066_LAPTOP),
2558	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
2559	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
2560	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
2561	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
2562	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
2563	{}
2564};
2565
2566static int patch_cxt5066(struct hda_codec *codec)
2567{
2568	struct conexant_spec *spec;
2569	int board_config;
2570
2571	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2572						  cxt5066_models, cxt5066_cfg_tbl);
2573	if (board_config < 0)
2574		board_config = CXT5066_AUTO; /* model=auto as default */
2575	if (board_config == CXT5066_AUTO)
2576		return patch_conexant_auto(codec);
2577
2578	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2579	if (!spec)
2580		return -ENOMEM;
2581	codec->spec = spec;
2582
2583	codec->patch_ops = conexant_patch_ops;
2584	codec->patch_ops.init = conexant_init;
2585
2586	spec->dell_automute = 0;
2587	spec->multiout.max_channels = 2;
2588	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2589	spec->multiout.dac_nids = cxt5066_dac_nids;
2590	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
2591	    ARRAY_SIZE(cxt5066_digout_pin_nids));
2592	spec->num_adc_nids = 1;
2593	spec->adc_nids = cxt5066_adc_nids;
2594	spec->capsrc_nids = cxt5066_capsrc_nids;
2595	spec->input_mux = &cxt5066_capture_source;
2596
2597	spec->port_d_mode = PIN_HP;
2598
2599	spec->num_init_verbs = 1;
2600	spec->init_verbs[0] = cxt5066_init_verbs;
2601	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2602	spec->channel_mode = cxt5066_modes;
2603	spec->cur_adc = 0;
2604	spec->cur_adc_idx = 0;
2605
2606	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2607
2608	switch (board_config) {
2609	default:
2610	case CXT5066_LAPTOP:
2611		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2612		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2613		break;
2614	case CXT5066_DELL_LAPTOP:
2615		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2616		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2617
2618		spec->port_d_mode = PIN_OUT;
2619		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2620		spec->num_init_verbs++;
2621		spec->dell_automute = 1;
2622		break;
2623	case CXT5066_ASUS:
2624	case CXT5066_HP_LAPTOP:
2625		codec->patch_ops.init = cxt5066_init;
2626		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2627		spec->init_verbs[spec->num_init_verbs] =
2628			cxt5066_init_verbs_hp_laptop;
2629		spec->num_init_verbs++;
2630		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
2631		spec->asus = board_config == CXT5066_ASUS;
2632		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2633		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2634		/* no S/PDIF out */
2635		if (board_config == CXT5066_HP_LAPTOP)
2636			spec->multiout.dig_out_nid = 0;
2637		/* input source automatically selected */
2638		spec->input_mux = NULL;
2639		spec->port_d_mode = 0;
2640		spec->mic_boost = 3; /* default 30dB gain */
2641		break;
2642
2643	case CXT5066_DELL_VOSTRO:
2644		codec->patch_ops.init = cxt5066_init;
2645		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2646		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2647		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2648		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2649		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
2650		spec->port_d_mode = 0;
2651		spec->dell_vostro = 1;
2652		spec->mic_boost = 3; /* default 30dB gain */
2653
2654		/* no S/PDIF out */
2655		spec->multiout.dig_out_nid = 0;
2656
2657		/* input source automatically selected */
2658		spec->input_mux = NULL;
2659		break;
2660	case CXT5066_IDEAPAD:
2661		codec->patch_ops.init = cxt5066_init;
2662		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2663		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2664		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2665		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
2666		spec->port_d_mode = 0;
2667		spec->ideapad = 1;
2668		spec->mic_boost = 2;	/* default 20dB gain */
2669
2670		/* no S/PDIF out */
2671		spec->multiout.dig_out_nid = 0;
2672
2673		/* input source automatically selected */
2674		spec->input_mux = NULL;
2675		break;
2676	case CXT5066_THINKPAD:
2677		codec->patch_ops.init = cxt5066_init;
2678		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2679		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2680		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2681		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
2682		spec->thinkpad = 1;
2683		spec->port_d_mode = PIN_OUT;
2684		spec->mic_boost = 2;	/* default 20dB gain */
2685
2686		/* no S/PDIF out */
2687		spec->multiout.dig_out_nid = 0;
2688
2689		/* input source automatically selected */
2690		spec->input_mux = NULL;
2691		break;
2692	}
2693
2694	if (spec->beep_amp)
2695		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
2696
2697	return 0;
2698}
2699
2700#endif /* ENABLE_CXT_STATIC_QUIRKS */
2701
2702
2703/*
2704 * Automatic parser for CX20641 & co
2705 */
2706
2707#ifdef CONFIG_SND_HDA_INPUT_BEEP
2708static void cx_auto_parse_beep(struct hda_codec *codec)
2709{
2710	struct conexant_spec *spec = codec->spec;
2711	hda_nid_t nid, end_nid;
2712
2713	end_nid = codec->start_nid + codec->num_nodes;
2714	for (nid = codec->start_nid; nid < end_nid; nid++)
2715		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
2716			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
2717			break;
2718		}
 
 
 
 
 
 
 
 
 
 
 
 
 
2719}
2720#else
2721#define cx_auto_parse_beep(codec)
2722#endif
2723
2724/* parse EAPDs */
2725static void cx_auto_parse_eapd(struct hda_codec *codec)
2726{
 
2727	struct conexant_spec *spec = codec->spec;
2728	hda_nid_t nid, end_nid;
2729
2730	end_nid = codec->start_nid + codec->num_nodes;
2731	for (nid = codec->start_nid; nid < end_nid; nid++) {
2732		if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
2733			continue;
2734		if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
2735			continue;
2736		spec->eapds[spec->num_eapds++] = nid;
2737		if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
2738			break;
2739	}
2740
2741	/* NOTE: below is a wild guess; if we have more than two EAPDs,
2742	 * it's a new chip, where EAPDs are supposed to be associated to
2743	 * pins, and we can control EAPD per pin.
2744	 * OTOH, if only one or two EAPDs are found, it's an old chip,
2745	 * thus it might control over all pins.
2746	 */
2747	if (spec->num_eapds > 2)
2748		spec->dynamic_eapd = 1;
2749}
2750
2751static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
2752			      hda_nid_t *pins, bool on)
2753{
2754	int i;
2755	for (i = 0; i < num_pins; i++) {
2756		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
2757			snd_hda_codec_write(codec, pins[i], 0,
2758					    AC_VERB_SET_EAPD_BTLENABLE,
2759					    on ? 0x02 : 0);
 
 
 
 
 
 
 
 
 
2760	}
2761}
2762
2763/* turn on/off EAPD according to Master switch */
2764static void cx_auto_vmaster_hook(void *private_data, int enabled)
2765{
2766	struct hda_codec *codec = private_data;
2767	struct conexant_spec *spec = codec->spec;
2768
2769	cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
2770}
2771
2772static int cx_auto_build_controls(struct hda_codec *codec)
2773{
2774	int err;
2775
2776	err = snd_hda_gen_build_controls(codec);
2777	if (err < 0)
2778		return err;
2779
2780	err = add_beep_ctls(codec);
2781	if (err < 0)
2782		return err;
2783
2784	return 0;
2785}
2786
2787static int cx_auto_init(struct hda_codec *codec)
 
2788{
2789	struct conexant_spec *spec = codec->spec;
2790	snd_hda_gen_init(codec);
2791	if (!spec->dynamic_eapd)
2792		cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
2793
2794	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
2795
2796	return 0;
2797}
2798
2799#define cx_auto_free	snd_hda_gen_free
2800
2801static const struct hda_codec_ops cx_auto_patch_ops = {
2802	.build_controls = cx_auto_build_controls,
2803	.build_pcms = snd_hda_gen_build_pcms,
2804	.init = cx_auto_init,
2805	.free = cx_auto_free,
2806	.unsol_event = snd_hda_jack_unsol_event,
2807#ifdef CONFIG_PM
 
2808	.check_power_status = snd_hda_gen_check_power_status,
2809#endif
2810};
2811
2812/*
2813 * pin fix-up
2814 */
2815enum {
2816	CXT_PINCFG_LENOVO_X200,
2817	CXT_PINCFG_LENOVO_TP410,
2818	CXT_PINCFG_LEMOTE_A1004,
2819	CXT_PINCFG_LEMOTE_A1205,
 
2820	CXT_FIXUP_STEREO_DMIC,
 
2821	CXT_FIXUP_INC_MIC_BOOST,
2822	CXT_FIXUP_HEADPHONE_MIC_PIN,
2823	CXT_FIXUP_HEADPHONE_MIC,
2824	CXT_FIXUP_GPIO1,
 
2825	CXT_FIXUP_THINKPAD_ACPI,
2826	CXT_FIXUP_OLPC_XO,
2827	CXT_FIXUP_CAP_MIX_AMP,
2828	CXT_FIXUP_TOSHIBA_P105,
2829	CXT_FIXUP_HP_530,
2830	CXT_FIXUP_CAP_MIX_AMP_5047,
 
 
 
 
 
 
 
 
 
2831};
2832
2833/* for hda_fixup_thinkpad_acpi() */
2834#include "thinkpad_helper.c"
2835
2836static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
2837				  const struct hda_fixup *fix, int action)
2838{
2839	struct conexant_spec *spec = codec->spec;
2840	spec->gen.inv_dmic_split = 1;
2841}
2842
2843static void cxt5066_increase_mic_boost(struct hda_codec *codec,
2844				   const struct hda_fixup *fix, int action)
2845{
2846	if (action != HDA_FIXUP_ACT_PRE_PROBE)
2847		return;
2848
2849	snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
2850				  (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
2851				  (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2852				  (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2853				  (0 << AC_AMPCAP_MUTE_SHIFT));
2854}
2855
2856static void cxt_update_headset_mode(struct hda_codec *codec)
2857{
2858	/* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
2859	int i;
2860	bool mic_mode = false;
2861	struct conexant_spec *spec = codec->spec;
2862	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
2863
2864	hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
2865
2866	for (i = 0; i < cfg->num_inputs; i++)
2867		if (cfg->inputs[i].pin == mux_pin) {
2868			mic_mode = !!cfg->inputs[i].is_headphone_mic;
2869			break;
2870		}
2871
2872	if (mic_mode) {
2873		snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
2874		spec->gen.hp_jack_present = false;
2875	} else {
2876		snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
2877		spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
2878	}
2879
2880	snd_hda_gen_update_outputs(codec);
2881}
2882
2883static void cxt_update_headset_mode_hook(struct hda_codec *codec,
2884					 struct snd_kcontrol *kcontrol,
2885					 struct snd_ctl_elem_value *ucontrol)
2886{
2887	cxt_update_headset_mode(codec);
2888}
2889
2890static void cxt_fixup_headphone_mic(struct hda_codec *codec,
2891				    const struct hda_fixup *fix, int action)
2892{
2893	struct conexant_spec *spec = codec->spec;
2894
2895	switch (action) {
2896	case HDA_FIXUP_ACT_PRE_PROBE:
2897		spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
 
2898		break;
2899	case HDA_FIXUP_ACT_PROBE:
 
2900		spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
2901		spec->gen.automute_hook = cxt_update_headset_mode;
2902		break;
2903	case HDA_FIXUP_ACT_INIT:
2904		cxt_update_headset_mode(codec);
2905		break;
2906	}
2907}
2908
 
 
 
 
 
 
 
 
 
 
 
 
2909/* OPLC XO 1.5 fixup */
2910
2911/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
2912 * through the microphone jack.
2913 * When the user enables this through a mixer switch, both internal and
2914 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
2915 * we also allow the bias to be configured through a separate mixer
2916 * control. */
2917
2918#define update_mic_pin(codec, nid, val)					\
2919	snd_hda_codec_update_cache(codec, nid, 0,			\
2920				   AC_VERB_SET_PIN_WIDGET_CONTROL, val)
2921
2922static const struct hda_input_mux olpc_xo_dc_bias = {
2923	.num_items = 3,
2924	.items = {
2925		{ "Off", PIN_IN },
2926		{ "50%", PIN_VREF50 },
2927		{ "80%", PIN_VREF80 },
2928	},
2929};
2930
2931static void olpc_xo_update_mic_boost(struct hda_codec *codec)
2932{
2933	struct conexant_spec *spec = codec->spec;
2934	int ch, val;
2935
2936	for (ch = 0; ch < 2; ch++) {
2937		val = AC_AMP_SET_OUTPUT |
2938			(ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
2939		if (!spec->dc_enable)
2940			val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
2941		snd_hda_codec_write(codec, 0x17, 0,
2942				    AC_VERB_SET_AMP_GAIN_MUTE, val);
2943	}
2944}
2945
2946static void olpc_xo_update_mic_pins(struct hda_codec *codec)
2947{
2948	struct conexant_spec *spec = codec->spec;
2949	int cur_input, val;
2950	struct nid_path *path;
2951
2952	cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
2953
2954	/* Set up mic pins for port-B, C and F dynamically as the recording
2955	 * LED is turned on/off by these pin controls
2956	 */
2957	if (!spec->dc_enable) {
2958		/* disable DC bias path and pin for port F */
2959		update_mic_pin(codec, 0x1e, 0);
2960		snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
2961
2962		/* update port B (ext mic) and C (int mic) */
2963		/* OLPC defers mic widget control until when capture is
2964		 * started because the microphone LED comes on as soon as
2965		 * these settings are put in place. if we did this before
2966		 * recording, it would give the false indication that
2967		 * recording is happening when it is not.
2968		 */
2969		update_mic_pin(codec, 0x1a, spec->recording ?
2970			       snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
2971		update_mic_pin(codec, 0x1b, spec->recording ?
2972			       snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
2973		/* enable normal mic path */
2974		path = snd_hda_get_path_from_idx(codec, cur_input);
2975		if (path)
2976			snd_hda_activate_path(codec, path, true, false);
2977	} else {
2978		/* disable normal mic path */
2979		path = snd_hda_get_path_from_idx(codec, cur_input);
2980		if (path)
2981			snd_hda_activate_path(codec, path, false, false);
2982
2983		/* Even though port F is the DC input, the bias is controlled
2984		 * on port B.  We also leave that port as an active input (but
2985		 * unselected) in DC mode just in case that is necessary to
2986		 * make the bias setting take effect.
2987		 */
2988		if (spec->recording)
2989			val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
2990		else
2991			val = 0;
2992		update_mic_pin(codec, 0x1a, val);
2993		update_mic_pin(codec, 0x1b, 0);
2994		/* enable DC bias path and pin */
2995		update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
2996		snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
2997	}
2998}
2999
3000/* mic_autoswitch hook */
3001static void olpc_xo_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
 
3002{
3003	struct conexant_spec *spec = codec->spec;
3004	int saved_cached_write = codec->cached_write;
3005
3006	codec->cached_write = 1;
3007	/* in DC mode, we don't handle automic */
3008	if (!spec->dc_enable)
3009		snd_hda_gen_mic_autoswitch(codec, jack);
3010	olpc_xo_update_mic_pins(codec);
3011	snd_hda_codec_flush_cache(codec);
3012	codec->cached_write = saved_cached_write;
3013	if (spec->dc_enable)
3014		olpc_xo_update_mic_boost(codec);
3015}
3016
3017/* pcm_capture hook */
3018static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
3019				 struct hda_codec *codec,
3020				 struct snd_pcm_substream *substream,
3021				 int action)
3022{
3023	struct conexant_spec *spec = codec->spec;
3024
3025	/* toggle spec->recording flag and update mic pins accordingly
3026	 * for turning on/off LED
3027	 */
3028	switch (action) {
3029	case HDA_GEN_PCM_ACT_PREPARE:
3030		spec->recording = 1;
3031		olpc_xo_update_mic_pins(codec);
3032		break;
3033	case HDA_GEN_PCM_ACT_CLEANUP:
3034		spec->recording = 0;
3035		olpc_xo_update_mic_pins(codec);
3036		break;
3037	}
3038}
3039
3040static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
3041			       struct snd_ctl_elem_value *ucontrol)
3042{
3043	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3044	struct conexant_spec *spec = codec->spec;
3045	ucontrol->value.integer.value[0] = spec->dc_enable;
3046	return 0;
3047}
3048
3049static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
3050			       struct snd_ctl_elem_value *ucontrol)
3051{
3052	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3053	struct conexant_spec *spec = codec->spec;
3054	int dc_enable = !!ucontrol->value.integer.value[0];
3055
3056	if (dc_enable == spec->dc_enable)
3057		return 0;
3058
3059	spec->dc_enable = dc_enable;
3060	olpc_xo_update_mic_pins(codec);
3061	olpc_xo_update_mic_boost(codec);
3062	return 1;
3063}
3064
3065static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
3066				    struct snd_ctl_elem_value *ucontrol)
3067{
3068	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3069	struct conexant_spec *spec = codec->spec;
3070	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
3071	return 0;
3072}
3073
3074static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
3075				     struct snd_ctl_elem_info *uinfo)
3076{
3077	return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
3078}
3079
3080static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
3081				    struct snd_ctl_elem_value *ucontrol)
3082{
3083	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3084	struct conexant_spec *spec = codec->spec;
3085	const struct hda_input_mux *imux = &olpc_xo_dc_bias;
3086	unsigned int idx;
3087
3088	idx = ucontrol->value.enumerated.item[0];
3089	if (idx >= imux->num_items)
3090		idx = imux->num_items - 1;
3091	if (spec->dc_input_bias == idx)
3092		return 0;
3093
3094	spec->dc_input_bias = idx;
3095	if (spec->dc_enable)
3096		olpc_xo_update_mic_pins(codec);
3097	return 1;
3098}
3099
3100static const struct snd_kcontrol_new olpc_xo_mixers[] = {
3101	{
3102		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3103		.name = "DC Mode Enable Switch",
3104		.info = snd_ctl_boolean_mono_info,
3105		.get = olpc_xo_dc_mode_get,
3106		.put = olpc_xo_dc_mode_put,
3107	},
3108	{
3109		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3110		.name = "DC Input Bias Enum",
3111		.info = olpc_xo_dc_bias_enum_info,
3112		.get = olpc_xo_dc_bias_enum_get,
3113		.put = olpc_xo_dc_bias_enum_put,
3114	},
3115	{}
3116};
3117
3118/* overriding mic boost put callback; update mic boost volume only when
3119 * DC mode is disabled
3120 */
3121static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
3122				 struct snd_ctl_elem_value *ucontrol)
3123{
3124	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3125	struct conexant_spec *spec = codec->spec;
3126	int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
3127	if (ret > 0 && spec->dc_enable)
3128		olpc_xo_update_mic_boost(codec);
3129	return ret;
3130}
3131
3132static void cxt_fixup_olpc_xo(struct hda_codec *codec,
3133				    const struct hda_fixup *fix, int action)
3134{
3135	struct conexant_spec *spec = codec->spec;
 
3136	int i;
3137
3138	if (action != HDA_FIXUP_ACT_PROBE)
3139		return;
3140
3141	spec->gen.mic_autoswitch_hook = olpc_xo_automic;
3142	spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
3143	spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
3144
3145	snd_hda_add_new_ctls(codec, olpc_xo_mixers);
3146
3147	/* OLPC's microphone port is DC coupled for use with external sensors,
3148	 * therefore we use a 50% mic bias in order to center the input signal
3149	 * with the DC input range of the codec.
3150	 */
3151	snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
3152
3153	/* override mic boost control */
3154	for (i = 0; i < spec->gen.kctls.used; i++) {
3155		struct snd_kcontrol_new *kctl =
3156			snd_array_elem(&spec->gen.kctls, i);
3157		if (!strcmp(kctl->name, "Mic Boost Volume")) {
3158			kctl->put = olpc_xo_mic_boost_put;
3159			break;
3160		}
3161	}
3162}
3163
 
 
 
 
 
 
 
 
 
 
 
 
3164/*
3165 * Fix max input level on mixer widget to 0dB
3166 * (originally it has 0x2b steps with 0dB offset 0x14)
3167 */
3168static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
3169				  const struct hda_fixup *fix, int action)
3170{
3171	snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
3172				  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
3173				  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3174				  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3175				  (1 << AC_AMPCAP_MUTE_SHIFT));
3176}
3177
3178/*
3179 * Fix max input level on mixer widget to 0dB
3180 * (originally it has 0x1e steps with 0 dB offset 0x17)
3181 */
3182static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
3183				  const struct hda_fixup *fix, int action)
3184{
3185	snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
3186				  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3187				  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3188				  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3189				  (1 << AC_AMPCAP_MUTE_SHIFT));
3190}
3191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3192/* ThinkPad X200 & co with cxt5051 */
3193static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
3194	{ 0x16, 0x042140ff }, /* HP (seq# overridden) */
3195	{ 0x17, 0x21a11000 }, /* dock-mic */
3196	{ 0x19, 0x2121103f }, /* dock-HP */
3197	{ 0x1c, 0x21440100 }, /* dock SPDIF out */
3198	{}
3199};
3200
3201/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
3202static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
3203	{ 0x19, 0x042110ff }, /* HP (seq# overridden) */
3204	{ 0x1a, 0x21a190f0 }, /* dock-mic */
3205	{ 0x1c, 0x212140ff }, /* dock-HP */
3206	{}
3207};
3208
3209/* Lemote A1004/A1205 with cxt5066 */
3210static const struct hda_pintbl cxt_pincfg_lemote[] = {
3211	{ 0x1a, 0x90a10020 }, /* Internal mic */
3212	{ 0x1b, 0x03a11020 }, /* External mic */
3213	{ 0x1d, 0x400101f0 }, /* Not used */
3214	{ 0x1e, 0x40a701f0 }, /* Not used */
3215	{ 0x20, 0x404501f0 }, /* Not used */
3216	{ 0x22, 0x404401f0 }, /* Not used */
3217	{ 0x23, 0x40a701f0 }, /* Not used */
3218	{}
3219};
3220
 
 
 
 
 
 
 
 
 
 
 
3221static const struct hda_fixup cxt_fixups[] = {
3222	[CXT_PINCFG_LENOVO_X200] = {
3223		.type = HDA_FIXUP_PINS,
3224		.v.pins = cxt_pincfg_lenovo_x200,
3225	},
3226	[CXT_PINCFG_LENOVO_TP410] = {
3227		.type = HDA_FIXUP_PINS,
3228		.v.pins = cxt_pincfg_lenovo_tp410,
3229		.chained = true,
3230		.chain_id = CXT_FIXUP_THINKPAD_ACPI,
3231	},
3232	[CXT_PINCFG_LEMOTE_A1004] = {
3233		.type = HDA_FIXUP_PINS,
3234		.chained = true,
3235		.chain_id = CXT_FIXUP_INC_MIC_BOOST,
3236		.v.pins = cxt_pincfg_lemote,
3237	},
3238	[CXT_PINCFG_LEMOTE_A1205] = {
3239		.type = HDA_FIXUP_PINS,
3240		.v.pins = cxt_pincfg_lemote,
3241	},
 
 
 
 
 
 
 
 
 
3242	[CXT_FIXUP_STEREO_DMIC] = {
3243		.type = HDA_FIXUP_FUNC,
3244		.v.func = cxt_fixup_stereo_dmic,
3245	},
 
 
 
 
 
 
 
 
3246	[CXT_FIXUP_INC_MIC_BOOST] = {
3247		.type = HDA_FIXUP_FUNC,
3248		.v.func = cxt5066_increase_mic_boost,
3249	},
3250	[CXT_FIXUP_HEADPHONE_MIC_PIN] = {
3251		.type = HDA_FIXUP_PINS,
3252		.chained = true,
3253		.chain_id = CXT_FIXUP_HEADPHONE_MIC,
3254		.v.pins = (const struct hda_pintbl[]) {
3255			{ 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
3256			{ }
3257		}
3258	},
3259	[CXT_FIXUP_HEADPHONE_MIC] = {
3260		.type = HDA_FIXUP_FUNC,
3261		.v.func = cxt_fixup_headphone_mic,
3262	},
3263	[CXT_FIXUP_GPIO1] = {
3264		.type = HDA_FIXUP_VERBS,
3265		.v.verbs = (const struct hda_verb[]) {
3266			{ 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
3267			{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
3268			{ 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
3269			{ }
3270		},
3271	},
 
 
 
 
 
 
3272	[CXT_FIXUP_THINKPAD_ACPI] = {
3273		.type = HDA_FIXUP_FUNC,
3274		.v.func = hda_fixup_thinkpad_acpi,
3275	},
3276	[CXT_FIXUP_OLPC_XO] = {
3277		.type = HDA_FIXUP_FUNC,
3278		.v.func = cxt_fixup_olpc_xo,
3279	},
3280	[CXT_FIXUP_CAP_MIX_AMP] = {
3281		.type = HDA_FIXUP_FUNC,
3282		.v.func = cxt_fixup_cap_mix_amp,
3283	},
3284	[CXT_FIXUP_TOSHIBA_P105] = {
3285		.type = HDA_FIXUP_PINS,
3286		.v.pins = (const struct hda_pintbl[]) {
3287			{ 0x10, 0x961701f0 }, /* speaker/hp */
3288			{ 0x12, 0x02a1901e }, /* ext mic */
3289			{ 0x14, 0x95a70110 }, /* int mic */
3290			{}
3291		},
3292	},
3293	[CXT_FIXUP_HP_530] = {
3294		.type = HDA_FIXUP_PINS,
3295		.v.pins = (const struct hda_pintbl[]) {
3296			{ 0x12, 0x90a60160 }, /* int mic */
3297			{}
3298		},
3299		.chained = true,
3300		.chain_id = CXT_FIXUP_CAP_MIX_AMP,
3301	},
3302	[CXT_FIXUP_CAP_MIX_AMP_5047] = {
3303		.type = HDA_FIXUP_FUNC,
3304		.v.func = cxt_fixup_cap_mix_amp_5047,
3305	},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3306};
3307
3308static const struct snd_pci_quirk cxt5045_fixups[] = {
3309	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
3310	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
3311	/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
3312	 * really bad sound over 0dB on NID 0x17.
3313	 */
3314	SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
3315	SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
3316	SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
3317	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
3318	{}
3319};
3320
3321static const struct hda_model_fixup cxt5045_fixup_models[] = {
3322	{ .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
3323	{ .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
3324	{ .id = CXT_FIXUP_HP_530, .name = "hp-530" },
3325	{}
3326};
3327
3328static const struct snd_pci_quirk cxt5047_fixups[] = {
3329	/* HP laptops have really bad sound over 0 dB on NID 0x10.
3330	 */
3331	SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
3332	{}
3333};
3334
3335static const struct hda_model_fixup cxt5047_fixup_models[] = {
3336	{ .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
3337	{}
3338};
3339
3340static const struct snd_pci_quirk cxt5051_fixups[] = {
 
3341	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
3342	{}
3343};
3344
3345static const struct hda_model_fixup cxt5051_fixup_models[] = {
3346	{ .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
3347	{}
3348};
3349
3350static const struct snd_pci_quirk cxt5066_fixups[] = {
3351	SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
3352	SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3353	SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
 
3354	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
3355	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3356	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
3357	SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
3358	SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
3359	SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
 
3360	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
3361	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
 
 
 
3362	SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
 
 
 
3363	SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
 
3364	SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
3365	SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
3366	SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
3367	SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
3368	{}
3369};
3370
3371static const struct hda_model_fixup cxt5066_fixup_models[] = {
3372	{ .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
3373	{ .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
3374	{ .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
3375	{ .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
3376	{ .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
3377	{ .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
 
3378	{ .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
 
 
 
 
 
 
 
3379	{}
3380};
3381
3382/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
3383 * can be created (bko#42825)
3384 */
3385static void add_cx5051_fake_mutes(struct hda_codec *codec)
3386{
3387	static hda_nid_t out_nids[] = {
 
3388		0x10, 0x11, 0
3389	};
3390	hda_nid_t *p;
3391
3392	for (p = out_nids; *p; p++)
3393		snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
3394					  AC_AMPCAP_MIN_MUTE |
3395					  query_amp_caps(codec, *p, HDA_OUTPUT));
 
3396}
3397
3398static int patch_conexant_auto(struct hda_codec *codec)
3399{
3400	struct conexant_spec *spec;
3401	int err;
3402
3403	codec_info(codec, "%s: BIOS auto-probing.\n", codec->chip_name);
3404
3405	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3406	if (!spec)
3407		return -ENOMEM;
3408	snd_hda_gen_spec_init(&spec->gen);
3409	codec->spec = spec;
 
 
 
 
 
 
 
 
 
 
3410
3411	cx_auto_parse_beep(codec);
3412	cx_auto_parse_eapd(codec);
3413	spec->gen.own_eapd_ctl = 1;
3414	if (spec->dynamic_eapd)
3415		spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
3416
3417	switch (codec->vendor_id) {
3418	case 0x14f15045:
3419		codec->single_adc_amp = 1;
3420		spec->gen.mixer_nid = 0x17;
3421		spec->gen.add_stereo_mix_input = 1;
3422		snd_hda_pick_fixup(codec, cxt5045_fixup_models,
3423				   cxt5045_fixups, cxt_fixups);
3424		break;
3425	case 0x14f15047:
3426		codec->pin_amp_workaround = 1;
3427		spec->gen.mixer_nid = 0x19;
3428		spec->gen.add_stereo_mix_input = 1;
3429		snd_hda_pick_fixup(codec, cxt5047_fixup_models,
3430				   cxt5047_fixups, cxt_fixups);
3431		break;
3432	case 0x14f15051:
3433		add_cx5051_fake_mutes(codec);
3434		codec->pin_amp_workaround = 1;
3435		snd_hda_pick_fixup(codec, cxt5051_fixup_models,
3436				   cxt5051_fixups, cxt_fixups);
3437		break;
 
 
 
 
 
 
 
 
 
 
3438	default:
3439		codec->pin_amp_workaround = 1;
3440		snd_hda_pick_fixup(codec, cxt5066_fixup_models,
3441				   cxt5066_fixups, cxt_fixups);
3442		break;
3443	}
3444
3445	/* Show mute-led control only on HP laptops
3446	 * This is a sort of white-list: on HP laptops, EAPD corresponds
3447	 * only to the mute-LED without actualy amp function.  Meanwhile,
3448	 * others may use EAPD really as an amp switch, so it might be
3449	 * not good to expose it blindly.
3450	 */
3451	switch (codec->subsystem_id >> 16) {
3452	case 0x103c:
3453		spec->gen.vmaster_mute_enum = 1;
3454		break;
3455	}
3456
3457	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3458
3459	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
3460				       spec->parse_flags);
3461	if (err < 0)
3462		goto error;
3463
3464	err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
3465	if (err < 0)
3466		goto error;
3467
3468	codec->patch_ops = cx_auto_patch_ops;
 
 
3469
3470	/* Some laptops with Conexant chips show stalls in S3 resume,
3471	 * which falls into the single-cmd mode.
3472	 * Better to make reset, then.
3473	 */
3474	if (!codec->bus->sync_write) {
3475		codec_info(codec,
3476			   "Enable sync_write for stable communication\n");
3477		codec->bus->sync_write = 1;
3478		codec->bus->allow_bus_reset = 1;
3479	}
3480
3481	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
3482
3483	return 0;
3484
3485 error:
3486	cx_auto_free(codec);
3487	return err;
3488}
3489
3490#ifndef ENABLE_CXT_STATIC_QUIRKS
3491#define patch_cxt5045	patch_conexant_auto
3492#define patch_cxt5047	patch_conexant_auto
3493#define patch_cxt5051	patch_conexant_auto
3494#define patch_cxt5066	patch_conexant_auto
3495#endif
3496
3497/*
3498 */
3499
3500static const struct hda_codec_preset snd_hda_preset_conexant[] = {
3501	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
3502	  .patch = patch_cxt5045 },
3503	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3504	  .patch = patch_cxt5047 },
3505	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3506	  .patch = patch_cxt5051 },
3507	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
3508	  .patch = patch_cxt5066 },
3509	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3510	  .patch = patch_cxt5066 },
3511	{ .id = 0x14f15068, .name = "CX20584",
3512	  .patch = patch_cxt5066 },
3513	{ .id = 0x14f15069, .name = "CX20585",
3514	  .patch = patch_cxt5066 },
3515	{ .id = 0x14f1506c, .name = "CX20588",
3516	  .patch = patch_cxt5066 },
3517	{ .id = 0x14f1506e, .name = "CX20590",
3518	  .patch = patch_cxt5066 },
3519	{ .id = 0x14f15097, .name = "CX20631",
3520	  .patch = patch_conexant_auto },
3521	{ .id = 0x14f15098, .name = "CX20632",
3522	  .patch = patch_conexant_auto },
3523	{ .id = 0x14f150a1, .name = "CX20641",
3524	  .patch = patch_conexant_auto },
3525	{ .id = 0x14f150a2, .name = "CX20642",
3526	  .patch = patch_conexant_auto },
3527	{ .id = 0x14f150ab, .name = "CX20651",
3528	  .patch = patch_conexant_auto },
3529	{ .id = 0x14f150ac, .name = "CX20652",
3530	  .patch = patch_conexant_auto },
3531	{ .id = 0x14f150b8, .name = "CX20664",
3532	  .patch = patch_conexant_auto },
3533	{ .id = 0x14f150b9, .name = "CX20665",
3534	  .patch = patch_conexant_auto },
3535	{ .id = 0x14f1510f, .name = "CX20751/2",
3536	  .patch = patch_conexant_auto },
3537	{ .id = 0x14f15110, .name = "CX20751/2",
3538	  .patch = patch_conexant_auto },
3539	{ .id = 0x14f15111, .name = "CX20753/4",
3540	  .patch = patch_conexant_auto },
3541	{ .id = 0x14f15113, .name = "CX20755",
3542	  .patch = patch_conexant_auto },
3543	{ .id = 0x14f15114, .name = "CX20756",
3544	  .patch = patch_conexant_auto },
3545	{ .id = 0x14f15115, .name = "CX20757",
3546	  .patch = patch_conexant_auto },
3547	{ .id = 0x14f151d7, .name = "CX20952",
3548	  .patch = patch_conexant_auto },
3549	{} /* terminator */
3550};
3551
3552MODULE_ALIAS("snd-hda-codec-id:14f15045");
3553MODULE_ALIAS("snd-hda-codec-id:14f15047");
3554MODULE_ALIAS("snd-hda-codec-id:14f15051");
3555MODULE_ALIAS("snd-hda-codec-id:14f15066");
3556MODULE_ALIAS("snd-hda-codec-id:14f15067");
3557MODULE_ALIAS("snd-hda-codec-id:14f15068");
3558MODULE_ALIAS("snd-hda-codec-id:14f15069");
3559MODULE_ALIAS("snd-hda-codec-id:14f1506c");
3560MODULE_ALIAS("snd-hda-codec-id:14f1506e");
3561MODULE_ALIAS("snd-hda-codec-id:14f15097");
3562MODULE_ALIAS("snd-hda-codec-id:14f15098");
3563MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3564MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3565MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3566MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3567MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3568MODULE_ALIAS("snd-hda-codec-id:14f150b9");
3569MODULE_ALIAS("snd-hda-codec-id:14f1510f");
3570MODULE_ALIAS("snd-hda-codec-id:14f15110");
3571MODULE_ALIAS("snd-hda-codec-id:14f15111");
3572MODULE_ALIAS("snd-hda-codec-id:14f15113");
3573MODULE_ALIAS("snd-hda-codec-id:14f15114");
3574MODULE_ALIAS("snd-hda-codec-id:14f15115");
3575MODULE_ALIAS("snd-hda-codec-id:14f151d7");
3576
3577MODULE_LICENSE("GPL");
3578MODULE_DESCRIPTION("Conexant HD-audio codec");
3579
3580static struct hda_codec_preset_list conexant_list = {
3581	.preset = snd_hda_preset_conexant,
3582	.owner = THIS_MODULE,
3583};
3584
3585static int __init patch_conexant_init(void)
3586{
3587	return snd_hda_add_codec_preset(&conexant_list);
3588}
3589
3590static void __exit patch_conexant_exit(void)
3591{
3592	snd_hda_delete_codec_preset(&conexant_list);
3593}
3594
3595module_init(patch_conexant_init)
3596module_exit(patch_conexant_exit)
v6.8
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*
   3 * HD audio interface patch for Conexant HDA audio codec
   4 *
   5 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
   6 * 		      Takashi Iwai <tiwai@suse.de>
   7 * 		      Tobin Davis  <tdavis@dsl-only.net>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   8 */
   9
  10#include <linux/init.h>
  11#include <linux/delay.h>
  12#include <linux/slab.h>
  13#include <linux/module.h>
  14#include <sound/core.h>
  15#include <sound/jack.h>
  16
  17#include <sound/hda_codec.h>
  18#include "hda_local.h"
  19#include "hda_auto_parser.h"
  20#include "hda_beep.h"
  21#include "hda_jack.h"
  22#include "hda_generic.h"
  23
  24enum {
  25	CX_HEADSET_NOPRESENT = 0,
  26	CX_HEADSET_PARTPRESENT,
  27	CX_HEADSET_ALLPRESENT,
  28};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  29
  30struct conexant_spec {
  31	struct hda_gen_spec gen;
  32
 
 
  33	/* extra EAPD pins */
  34	unsigned int num_eapds;
  35	hda_nid_t eapds[4];
  36	bool dynamic_eapd;
  37	hda_nid_t mute_led_eapd;
  38
  39	unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
  40
  41	/* OPLC XO specific */
  42	bool recording;
  43	bool dc_enable;
  44	unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
  45	struct nid_path *dc_mode_path;
  46
  47	int mute_led_polarity;
  48	unsigned int gpio_led;
  49	unsigned int gpio_mute_led_mask;
  50	unsigned int gpio_mic_led_mask;
  51	unsigned int headset_present_flag;
  52	bool is_cx8070_sn6140;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  53};
  54
  55
  56#ifdef CONFIG_SND_HDA_INPUT_BEEP
  57/* additional beep mixers; private_value will be overwritten */
 
 
 
 
 
 
  58static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  59	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  60	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
 
  61};
  62
  63static int set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
  64			int idx, int dir)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  65{
  66	struct snd_kcontrol_new *knew;
  67	unsigned int beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  68	int i;
  69
  70	spec->gen.beep_nid = nid;
  71	for (i = 0; i < ARRAY_SIZE(cxt_beep_mixer); i++) {
  72		knew = snd_hda_gen_add_kctl(&spec->gen, NULL,
  73					    &cxt_beep_mixer[i]);
  74		if (!knew)
  75			return -ENOMEM;
  76		knew->private_value = beep_amp;
  77	}
  78	return 0;
  79}
  80
  81static int cx_auto_parse_beep(struct hda_codec *codec)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  82{
  83	struct conexant_spec *spec = codec->spec;
  84	hda_nid_t nid;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  85
  86	for_each_hda_codec_node(nid, codec)
  87		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP)
  88			return set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  89	return 0;
  90}
  91#else
  92#define cx_auto_parse_beep(codec)	0
  93#endif
  94
 
 
 
 
 
 
 
 
 
  95/*
  96 * Automatic parser for CX20641 & co
 
  97 */
  98
  99/* parse EAPDs */
 100static void cx_auto_parse_eapd(struct hda_codec *codec)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 101{
 102	struct conexant_spec *spec = codec->spec;
 103	hda_nid_t nid;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 104
 105	for_each_hda_codec_node(nid, codec) {
 106		if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
 107			continue;
 108		if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
 109			continue;
 110		spec->eapds[spec->num_eapds++] = nid;
 111		if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
 112			break;
 113	}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 114
 115	/* NOTE: below is a wild guess; if we have more than two EAPDs,
 116	 * it's a new chip, where EAPDs are supposed to be associated to
 117	 * pins, and we can control EAPD per pin.
 118	 * OTOH, if only one or two EAPDs are found, it's an old chip,
 119	 * thus it might control over all pins.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 120	 */
 121	if (spec->num_eapds > 2)
 122		spec->dynamic_eapd = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 123}
 124
 125static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
 126			      const hda_nid_t *pins, bool on)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 127{
 128	int i;
 129	for (i = 0; i < num_pins; i++) {
 130		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
 131			snd_hda_codec_write(codec, pins[i], 0,
 132					    AC_VERB_SET_EAPD_BTLENABLE,
 133					    on ? 0x02 : 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 134	}
 
 
 
 
 
 135}
 136
 137/* turn on/off EAPD according to Master switch */
 138static void cx_auto_vmaster_hook(void *private_data, int enabled)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 139{
 140	struct hda_codec *codec = private_data;
 141	struct conexant_spec *spec = codec->spec;
 
 142
 143	cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 144}
 145
 146/* turn on/off EAPD according to Master switch (inversely!) for mute LED */
 147static int cx_auto_vmaster_mute_led(struct led_classdev *led_cdev,
 148				    enum led_brightness brightness)
 149{
 150	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
 151	struct conexant_spec *spec = codec->spec;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 152
 153	snd_hda_codec_write(codec, spec->mute_led_eapd, 0,
 154			    AC_VERB_SET_EAPD_BTLENABLE,
 155			    brightness ? 0x02 : 0x00);
 156	return 0;
 157}
 158
 159static void cxt_init_gpio_led(struct hda_codec *codec)
 
 
 
 
 
 
 
 
 160{
 161	struct conexant_spec *spec = codec->spec;
 162	unsigned int mask = spec->gpio_mute_led_mask | spec->gpio_mic_led_mask;
 
 
 
 
 
 
 
 
 
 
 163
 164	if (mask) {
 165		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
 166				    mask);
 167		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
 168				    mask);
 169		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
 170				    spec->gpio_led);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 171	}
 172}
 173
 174static void cx_fixup_headset_recog(struct hda_codec *codec)
 
 175{
 176	unsigned int mic_persent;
 
 
 
 
 177
 178	/* fix some headset type recognize fail issue, such as EDIFIER headset */
 179	/* set micbiasd output current comparator threshold from 66% to 55%. */
 180	snd_hda_codec_write(codec, 0x1c, 0, 0x320, 0x010);
 181	/* set OFF voltage for DFET from -1.2V to -0.8V, set headset micbias registor
 182	 * value adjustment trim from 2.2K ohms to 2.0K ohms.
 183	 */
 184	snd_hda_codec_write(codec, 0x1c, 0, 0x3b0, 0xe10);
 185	/* fix reboot headset type recognize fail issue */
 186	mic_persent = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0x0);
 187	if (mic_persent & AC_PINSENSE_PRESENCE)
 188		/* enable headset mic VREF */
 189		snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
 190	else
 191		/* disable headset mic VREF */
 192		snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 193}
 194
 195static int cx_auto_init(struct hda_codec *codec)
 
 196{
 197	struct conexant_spec *spec = codec->spec;
 198	snd_hda_gen_init(codec);
 199	if (!spec->dynamic_eapd)
 200		cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
 201
 202	cxt_init_gpio_led(codec);
 203	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 204
 205	if (spec->is_cx8070_sn6140)
 206		cx_fixup_headset_recog(codec);
 
 
 
 207
 
 
 
 
 
 
 208	return 0;
 209}
 210
 211static void cx_auto_shutdown(struct hda_codec *codec)
 
 212{
 
 213	struct conexant_spec *spec = codec->spec;
 
 
 
 
 
 214
 215	/* Turn the problematic codec into D3 to avoid spurious noises
 216	   from the internal speaker during (and after) reboot */
 217	cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false);
 218}
 219
 220static void cx_auto_free(struct hda_codec *codec)
 
 
 221{
 222	cx_auto_shutdown(codec);
 223	snd_hda_gen_free(codec);
 
 
 
 
 
 
 
 
 
 224}
 225
 226static void cx_process_headset_plugin(struct hda_codec *codec)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 227{
 228	unsigned int val;
 229	unsigned int count = 0;
 
 
 
 
 
 
 
 230
 231	/* Wait headset detect done. */
 232	do {
 233		val = snd_hda_codec_read(codec, 0x1c, 0, 0xca0, 0x0);
 234		if (val & 0x080) {
 235			codec_dbg(codec, "headset type detect done!\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 236			break;
 237		}
 238		msleep(20);
 239		count++;
 240	} while (count < 3);
 241	val = snd_hda_codec_read(codec, 0x1c, 0, 0xcb0, 0x0);
 242	if (val & 0x800) {
 243		codec_dbg(codec, "headset plugin, type is CTIA\n");
 244		snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
 245	} else if (val & 0x400) {
 246		codec_dbg(codec, "headset plugin, type is OMTP\n");
 247		snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
 248	} else {
 249		codec_dbg(codec, "headphone plugin\n");
 250	}
 251}
 
 
 
 252
 253static void cx_update_headset_mic_vref(struct hda_codec *codec, unsigned int res)
 
 254{
 255	unsigned int phone_present, mic_persent, phone_tag, mic_tag;
 256	struct conexant_spec *spec = codec->spec;
 
 
 
 
 
 
 
 
 
 
 
 
 257
 258	/* In cx8070 and sn6140, the node 16 can only be config to headphone or disabled,
 259	 * the node 19 can only be config to microphone or disabled.
 260	 * Check hp&mic tag to process headset pulgin&plugout.
 
 
 261	 */
 262	phone_tag = snd_hda_codec_read(codec, 0x16, 0, AC_VERB_GET_UNSOLICITED_RESPONSE, 0x0);
 263	mic_tag = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_UNSOLICITED_RESPONSE, 0x0);
 264	if ((phone_tag & (res >> AC_UNSOL_RES_TAG_SHIFT)) ||
 265	    (mic_tag & (res >> AC_UNSOL_RES_TAG_SHIFT))) {
 266		phone_present = snd_hda_codec_read(codec, 0x16, 0, AC_VERB_GET_PIN_SENSE, 0x0);
 267		if (!(phone_present & AC_PINSENSE_PRESENCE)) {/* headphone plugout */
 268			spec->headset_present_flag = CX_HEADSET_NOPRESENT;
 269			snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20);
 270			return;
 271		}
 272		if (spec->headset_present_flag == CX_HEADSET_NOPRESENT) {
 273			spec->headset_present_flag = CX_HEADSET_PARTPRESENT;
 274		} else if (spec->headset_present_flag == CX_HEADSET_PARTPRESENT) {
 275			mic_persent = snd_hda_codec_read(codec, 0x19, 0,
 276							 AC_VERB_GET_PIN_SENSE, 0x0);
 277			/* headset is present */
 278			if ((phone_present & AC_PINSENSE_PRESENCE) &&
 279			    (mic_persent & AC_PINSENSE_PRESENCE)) {
 280				cx_process_headset_plugin(codec);
 281				spec->headset_present_flag = CX_HEADSET_ALLPRESENT;
 282			}
 283		}
 284	}
 285}
 286
 287static void cx_jack_unsol_event(struct hda_codec *codec, unsigned int res)
 
 288{
 
 289	struct conexant_spec *spec = codec->spec;
 290
 291	if (spec->is_cx8070_sn6140)
 292		cx_update_headset_mic_vref(codec, res);
 
 
 
 
 
 
 
 
 
 
 
 
 293
 294	snd_hda_jack_unsol_event(codec, res);
 295}
 296
 297#ifdef CONFIG_PM
 298static int cx_auto_suspend(struct hda_codec *codec)
 299{
 300	cx_auto_shutdown(codec);
 
 
 
 
 
 
 301	return 0;
 302}
 303#endif
 
 304
 305static const struct hda_codec_ops cx_auto_patch_ops = {
 306	.build_controls = snd_hda_gen_build_controls,
 307	.build_pcms = snd_hda_gen_build_pcms,
 308	.init = cx_auto_init,
 309	.free = cx_auto_free,
 310	.unsol_event = cx_jack_unsol_event,
 311#ifdef CONFIG_PM
 312	.suspend = cx_auto_suspend,
 313	.check_power_status = snd_hda_gen_check_power_status,
 314#endif
 315};
 316
 317/*
 318 * pin fix-up
 319 */
 320enum {
 321	CXT_PINCFG_LENOVO_X200,
 322	CXT_PINCFG_LENOVO_TP410,
 323	CXT_PINCFG_LEMOTE_A1004,
 324	CXT_PINCFG_LEMOTE_A1205,
 325	CXT_PINCFG_COMPAQ_CQ60,
 326	CXT_FIXUP_STEREO_DMIC,
 327	CXT_PINCFG_LENOVO_NOTEBOOK,
 328	CXT_FIXUP_INC_MIC_BOOST,
 329	CXT_FIXUP_HEADPHONE_MIC_PIN,
 330	CXT_FIXUP_HEADPHONE_MIC,
 331	CXT_FIXUP_GPIO1,
 332	CXT_FIXUP_ASPIRE_DMIC,
 333	CXT_FIXUP_THINKPAD_ACPI,
 334	CXT_FIXUP_OLPC_XO,
 335	CXT_FIXUP_CAP_MIX_AMP,
 336	CXT_FIXUP_TOSHIBA_P105,
 337	CXT_FIXUP_HP_530,
 338	CXT_FIXUP_CAP_MIX_AMP_5047,
 339	CXT_FIXUP_MUTE_LED_EAPD,
 340	CXT_FIXUP_HP_DOCK,
 341	CXT_FIXUP_HP_SPECTRE,
 342	CXT_FIXUP_HP_GATE_MIC,
 343	CXT_FIXUP_MUTE_LED_GPIO,
 344	CXT_FIXUP_HP_ZBOOK_MUTE_LED,
 345	CXT_FIXUP_HEADSET_MIC,
 346	CXT_FIXUP_HP_MIC_NO_PRESENCE,
 347	CXT_PINCFG_SWS_JS201D,
 348};
 349
 350/* for hda_fixup_thinkpad_acpi() */
 351#include "thinkpad_helper.c"
 352
 353static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
 354				  const struct hda_fixup *fix, int action)
 355{
 356	struct conexant_spec *spec = codec->spec;
 357	spec->gen.inv_dmic_split = 1;
 358}
 359
 360static void cxt5066_increase_mic_boost(struct hda_codec *codec,
 361				   const struct hda_fixup *fix, int action)
 362{
 363	if (action != HDA_FIXUP_ACT_PRE_PROBE)
 364		return;
 365
 366	snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
 367				  (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
 368				  (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
 369				  (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
 370				  (0 << AC_AMPCAP_MUTE_SHIFT));
 371}
 372
 373static void cxt_update_headset_mode(struct hda_codec *codec)
 374{
 375	/* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
 376	int i;
 377	bool mic_mode = false;
 378	struct conexant_spec *spec = codec->spec;
 379	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
 380
 381	hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
 382
 383	for (i = 0; i < cfg->num_inputs; i++)
 384		if (cfg->inputs[i].pin == mux_pin) {
 385			mic_mode = !!cfg->inputs[i].is_headphone_mic;
 386			break;
 387		}
 388
 389	if (mic_mode) {
 390		snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
 391		spec->gen.hp_jack_present = false;
 392	} else {
 393		snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
 394		spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
 395	}
 396
 397	snd_hda_gen_update_outputs(codec);
 398}
 399
 400static void cxt_update_headset_mode_hook(struct hda_codec *codec,
 401					 struct snd_kcontrol *kcontrol,
 402					 struct snd_ctl_elem_value *ucontrol)
 403{
 404	cxt_update_headset_mode(codec);
 405}
 406
 407static void cxt_fixup_headphone_mic(struct hda_codec *codec,
 408				    const struct hda_fixup *fix, int action)
 409{
 410	struct conexant_spec *spec = codec->spec;
 411
 412	switch (action) {
 413	case HDA_FIXUP_ACT_PRE_PROBE:
 414		spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
 415		snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410);
 416		break;
 417	case HDA_FIXUP_ACT_PROBE:
 418		WARN_ON(spec->gen.cap_sync_hook);
 419		spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
 420		spec->gen.automute_hook = cxt_update_headset_mode;
 421		break;
 422	case HDA_FIXUP_ACT_INIT:
 423		cxt_update_headset_mode(codec);
 424		break;
 425	}
 426}
 427
 428static void cxt_fixup_headset_mic(struct hda_codec *codec,
 429				    const struct hda_fixup *fix, int action)
 430{
 431	struct conexant_spec *spec = codec->spec;
 432
 433	switch (action) {
 434	case HDA_FIXUP_ACT_PRE_PROBE:
 435		spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
 436		break;
 437	}
 438}
 439
 440/* OPLC XO 1.5 fixup */
 441
 442/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
 443 * through the microphone jack.
 444 * When the user enables this through a mixer switch, both internal and
 445 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
 446 * we also allow the bias to be configured through a separate mixer
 447 * control. */
 448
 449#define update_mic_pin(codec, nid, val)					\
 450	snd_hda_codec_write_cache(codec, nid, 0,			\
 451				   AC_VERB_SET_PIN_WIDGET_CONTROL, val)
 452
 453static const struct hda_input_mux olpc_xo_dc_bias = {
 454	.num_items = 3,
 455	.items = {
 456		{ "Off", PIN_IN },
 457		{ "50%", PIN_VREF50 },
 458		{ "80%", PIN_VREF80 },
 459	},
 460};
 461
 462static void olpc_xo_update_mic_boost(struct hda_codec *codec)
 463{
 464	struct conexant_spec *spec = codec->spec;
 465	int ch, val;
 466
 467	for (ch = 0; ch < 2; ch++) {
 468		val = AC_AMP_SET_OUTPUT |
 469			(ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
 470		if (!spec->dc_enable)
 471			val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
 472		snd_hda_codec_write(codec, 0x17, 0,
 473				    AC_VERB_SET_AMP_GAIN_MUTE, val);
 474	}
 475}
 476
 477static void olpc_xo_update_mic_pins(struct hda_codec *codec)
 478{
 479	struct conexant_spec *spec = codec->spec;
 480	int cur_input, val;
 481	struct nid_path *path;
 482
 483	cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
 484
 485	/* Set up mic pins for port-B, C and F dynamically as the recording
 486	 * LED is turned on/off by these pin controls
 487	 */
 488	if (!spec->dc_enable) {
 489		/* disable DC bias path and pin for port F */
 490		update_mic_pin(codec, 0x1e, 0);
 491		snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
 492
 493		/* update port B (ext mic) and C (int mic) */
 494		/* OLPC defers mic widget control until when capture is
 495		 * started because the microphone LED comes on as soon as
 496		 * these settings are put in place. if we did this before
 497		 * recording, it would give the false indication that
 498		 * recording is happening when it is not.
 499		 */
 500		update_mic_pin(codec, 0x1a, spec->recording ?
 501			       snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
 502		update_mic_pin(codec, 0x1b, spec->recording ?
 503			       snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
 504		/* enable normal mic path */
 505		path = snd_hda_get_path_from_idx(codec, cur_input);
 506		if (path)
 507			snd_hda_activate_path(codec, path, true, false);
 508	} else {
 509		/* disable normal mic path */
 510		path = snd_hda_get_path_from_idx(codec, cur_input);
 511		if (path)
 512			snd_hda_activate_path(codec, path, false, false);
 513
 514		/* Even though port F is the DC input, the bias is controlled
 515		 * on port B.  We also leave that port as an active input (but
 516		 * unselected) in DC mode just in case that is necessary to
 517		 * make the bias setting take effect.
 518		 */
 519		if (spec->recording)
 520			val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
 521		else
 522			val = 0;
 523		update_mic_pin(codec, 0x1a, val);
 524		update_mic_pin(codec, 0x1b, 0);
 525		/* enable DC bias path and pin */
 526		update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
 527		snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
 528	}
 529}
 530
 531/* mic_autoswitch hook */
 532static void olpc_xo_automic(struct hda_codec *codec,
 533			    struct hda_jack_callback *jack)
 534{
 535	struct conexant_spec *spec = codec->spec;
 
 536
 
 537	/* in DC mode, we don't handle automic */
 538	if (!spec->dc_enable)
 539		snd_hda_gen_mic_autoswitch(codec, jack);
 540	olpc_xo_update_mic_pins(codec);
 
 
 541	if (spec->dc_enable)
 542		olpc_xo_update_mic_boost(codec);
 543}
 544
 545/* pcm_capture hook */
 546static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
 547				 struct hda_codec *codec,
 548				 struct snd_pcm_substream *substream,
 549				 int action)
 550{
 551	struct conexant_spec *spec = codec->spec;
 552
 553	/* toggle spec->recording flag and update mic pins accordingly
 554	 * for turning on/off LED
 555	 */
 556	switch (action) {
 557	case HDA_GEN_PCM_ACT_PREPARE:
 558		spec->recording = 1;
 559		olpc_xo_update_mic_pins(codec);
 560		break;
 561	case HDA_GEN_PCM_ACT_CLEANUP:
 562		spec->recording = 0;
 563		olpc_xo_update_mic_pins(codec);
 564		break;
 565	}
 566}
 567
 568static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
 569			       struct snd_ctl_elem_value *ucontrol)
 570{
 571	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 572	struct conexant_spec *spec = codec->spec;
 573	ucontrol->value.integer.value[0] = spec->dc_enable;
 574	return 0;
 575}
 576
 577static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
 578			       struct snd_ctl_elem_value *ucontrol)
 579{
 580	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 581	struct conexant_spec *spec = codec->spec;
 582	int dc_enable = !!ucontrol->value.integer.value[0];
 583
 584	if (dc_enable == spec->dc_enable)
 585		return 0;
 586
 587	spec->dc_enable = dc_enable;
 588	olpc_xo_update_mic_pins(codec);
 589	olpc_xo_update_mic_boost(codec);
 590	return 1;
 591}
 592
 593static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
 594				    struct snd_ctl_elem_value *ucontrol)
 595{
 596	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 597	struct conexant_spec *spec = codec->spec;
 598	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
 599	return 0;
 600}
 601
 602static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
 603				     struct snd_ctl_elem_info *uinfo)
 604{
 605	return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
 606}
 607
 608static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
 609				    struct snd_ctl_elem_value *ucontrol)
 610{
 611	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 612	struct conexant_spec *spec = codec->spec;
 613	const struct hda_input_mux *imux = &olpc_xo_dc_bias;
 614	unsigned int idx;
 615
 616	idx = ucontrol->value.enumerated.item[0];
 617	if (idx >= imux->num_items)
 618		idx = imux->num_items - 1;
 619	if (spec->dc_input_bias == idx)
 620		return 0;
 621
 622	spec->dc_input_bias = idx;
 623	if (spec->dc_enable)
 624		olpc_xo_update_mic_pins(codec);
 625	return 1;
 626}
 627
 628static const struct snd_kcontrol_new olpc_xo_mixers[] = {
 629	{
 630		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 631		.name = "DC Mode Enable Switch",
 632		.info = snd_ctl_boolean_mono_info,
 633		.get = olpc_xo_dc_mode_get,
 634		.put = olpc_xo_dc_mode_put,
 635	},
 636	{
 637		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 638		.name = "DC Input Bias Enum",
 639		.info = olpc_xo_dc_bias_enum_info,
 640		.get = olpc_xo_dc_bias_enum_get,
 641		.put = olpc_xo_dc_bias_enum_put,
 642	},
 643	{}
 644};
 645
 646/* overriding mic boost put callback; update mic boost volume only when
 647 * DC mode is disabled
 648 */
 649static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
 650				 struct snd_ctl_elem_value *ucontrol)
 651{
 652	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 653	struct conexant_spec *spec = codec->spec;
 654	int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
 655	if (ret > 0 && spec->dc_enable)
 656		olpc_xo_update_mic_boost(codec);
 657	return ret;
 658}
 659
 660static void cxt_fixup_olpc_xo(struct hda_codec *codec,
 661				    const struct hda_fixup *fix, int action)
 662{
 663	struct conexant_spec *spec = codec->spec;
 664	struct snd_kcontrol_new *kctl;
 665	int i;
 666
 667	if (action != HDA_FIXUP_ACT_PROBE)
 668		return;
 669
 670	spec->gen.mic_autoswitch_hook = olpc_xo_automic;
 671	spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
 672	spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
 673
 674	snd_hda_add_new_ctls(codec, olpc_xo_mixers);
 675
 676	/* OLPC's microphone port is DC coupled for use with external sensors,
 677	 * therefore we use a 50% mic bias in order to center the input signal
 678	 * with the DC input range of the codec.
 679	 */
 680	snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
 681
 682	/* override mic boost control */
 683	snd_array_for_each(&spec->gen.kctls, i, kctl) {
 
 
 684		if (!strcmp(kctl->name, "Mic Boost Volume")) {
 685			kctl->put = olpc_xo_mic_boost_put;
 686			break;
 687		}
 688	}
 689}
 690
 691static void cxt_fixup_mute_led_eapd(struct hda_codec *codec,
 692				    const struct hda_fixup *fix, int action)
 693{
 694	struct conexant_spec *spec = codec->spec;
 695
 696	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
 697		spec->mute_led_eapd = 0x1b;
 698		spec->dynamic_eapd = true;
 699		snd_hda_gen_add_mute_led_cdev(codec, cx_auto_vmaster_mute_led);
 700	}
 701}
 702
 703/*
 704 * Fix max input level on mixer widget to 0dB
 705 * (originally it has 0x2b steps with 0dB offset 0x14)
 706 */
 707static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
 708				  const struct hda_fixup *fix, int action)
 709{
 710	snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
 711				  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
 712				  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
 713				  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
 714				  (1 << AC_AMPCAP_MUTE_SHIFT));
 715}
 716
 717/*
 718 * Fix max input level on mixer widget to 0dB
 719 * (originally it has 0x1e steps with 0 dB offset 0x17)
 720 */
 721static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
 722				  const struct hda_fixup *fix, int action)
 723{
 724	snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
 725				  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
 726				  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
 727				  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
 728				  (1 << AC_AMPCAP_MUTE_SHIFT));
 729}
 730
 731static void cxt_fixup_hp_gate_mic_jack(struct hda_codec *codec,
 732				       const struct hda_fixup *fix,
 733				       int action)
 734{
 735	/* the mic pin (0x19) doesn't give an unsolicited event;
 736	 * probe the mic pin together with the headphone pin (0x16)
 737	 */
 738	if (action == HDA_FIXUP_ACT_PROBE)
 739		snd_hda_jack_set_gating_jack(codec, 0x19, 0x16);
 740}
 741
 742/* update LED status via GPIO */
 743static void cxt_update_gpio_led(struct hda_codec *codec, unsigned int mask,
 744				bool led_on)
 745{
 746	struct conexant_spec *spec = codec->spec;
 747	unsigned int oldval = spec->gpio_led;
 748
 749	if (spec->mute_led_polarity)
 750		led_on = !led_on;
 751
 752	if (led_on)
 753		spec->gpio_led |= mask;
 754	else
 755		spec->gpio_led &= ~mask;
 756	codec_dbg(codec, "mask:%d enabled:%d gpio_led:%d\n",
 757			mask, led_on, spec->gpio_led);
 758	if (spec->gpio_led != oldval)
 759		snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
 760				    spec->gpio_led);
 761}
 762
 763/* turn on/off mute LED via GPIO per vmaster hook */
 764static int cxt_gpio_mute_update(struct led_classdev *led_cdev,
 765				enum led_brightness brightness)
 766{
 767	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
 768	struct conexant_spec *spec = codec->spec;
 769
 770	cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, brightness);
 771	return 0;
 772}
 773
 774/* turn on/off mic-mute LED via GPIO per capture hook */
 775static int cxt_gpio_micmute_update(struct led_classdev *led_cdev,
 776				   enum led_brightness brightness)
 777{
 778	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
 779	struct conexant_spec *spec = codec->spec;
 780
 781	cxt_update_gpio_led(codec, spec->gpio_mic_led_mask, brightness);
 782	return 0;
 783}
 784
 785static void cxt_setup_mute_led(struct hda_codec *codec,
 786			       unsigned int mute, unsigned int mic_mute)
 787{
 788	struct conexant_spec *spec = codec->spec;
 789
 790	spec->gpio_led = 0;
 791	spec->mute_led_polarity = 0;
 792	if (mute) {
 793		snd_hda_gen_add_mute_led_cdev(codec, cxt_gpio_mute_update);
 794		spec->gpio_mute_led_mask = mute;
 795	}
 796	if (mic_mute) {
 797		snd_hda_gen_add_micmute_led_cdev(codec, cxt_gpio_micmute_update);
 798		spec->gpio_mic_led_mask = mic_mute;
 799	}
 800}
 801
 802static void cxt_fixup_mute_led_gpio(struct hda_codec *codec,
 803				const struct hda_fixup *fix, int action)
 804{
 805	if (action == HDA_FIXUP_ACT_PRE_PROBE)
 806		cxt_setup_mute_led(codec, 0x01, 0x02);
 807}
 808
 809static void cxt_fixup_hp_zbook_mute_led(struct hda_codec *codec,
 810					const struct hda_fixup *fix, int action)
 811{
 812	if (action == HDA_FIXUP_ACT_PRE_PROBE)
 813		cxt_setup_mute_led(codec, 0x10, 0x20);
 814}
 815
 816/* ThinkPad X200 & co with cxt5051 */
 817static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
 818	{ 0x16, 0x042140ff }, /* HP (seq# overridden) */
 819	{ 0x17, 0x21a11000 }, /* dock-mic */
 820	{ 0x19, 0x2121103f }, /* dock-HP */
 821	{ 0x1c, 0x21440100 }, /* dock SPDIF out */
 822	{}
 823};
 824
 825/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
 826static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
 827	{ 0x19, 0x042110ff }, /* HP (seq# overridden) */
 828	{ 0x1a, 0x21a190f0 }, /* dock-mic */
 829	{ 0x1c, 0x212140ff }, /* dock-HP */
 830	{}
 831};
 832
 833/* Lemote A1004/A1205 with cxt5066 */
 834static const struct hda_pintbl cxt_pincfg_lemote[] = {
 835	{ 0x1a, 0x90a10020 }, /* Internal mic */
 836	{ 0x1b, 0x03a11020 }, /* External mic */
 837	{ 0x1d, 0x400101f0 }, /* Not used */
 838	{ 0x1e, 0x40a701f0 }, /* Not used */
 839	{ 0x20, 0x404501f0 }, /* Not used */
 840	{ 0x22, 0x404401f0 }, /* Not used */
 841	{ 0x23, 0x40a701f0 }, /* Not used */
 842	{}
 843};
 844
 845/* SuoWoSi/South-holding JS201D with sn6140 */
 846static const struct hda_pintbl cxt_pincfg_sws_js201d[] = {
 847	{ 0x16, 0x03211040 }, /* hp out */
 848	{ 0x17, 0x91170110 }, /* SPK/Class_D */
 849	{ 0x18, 0x95a70130 }, /* Internal mic */
 850	{ 0x19, 0x03a11020 }, /* Headset Mic */
 851	{ 0x1a, 0x40f001f0 }, /* Not used */
 852	{ 0x21, 0x40f001f0 }, /* Not used */
 853	{}
 854};
 855
 856static const struct hda_fixup cxt_fixups[] = {
 857	[CXT_PINCFG_LENOVO_X200] = {
 858		.type = HDA_FIXUP_PINS,
 859		.v.pins = cxt_pincfg_lenovo_x200,
 860	},
 861	[CXT_PINCFG_LENOVO_TP410] = {
 862		.type = HDA_FIXUP_PINS,
 863		.v.pins = cxt_pincfg_lenovo_tp410,
 864		.chained = true,
 865		.chain_id = CXT_FIXUP_THINKPAD_ACPI,
 866	},
 867	[CXT_PINCFG_LEMOTE_A1004] = {
 868		.type = HDA_FIXUP_PINS,
 869		.chained = true,
 870		.chain_id = CXT_FIXUP_INC_MIC_BOOST,
 871		.v.pins = cxt_pincfg_lemote,
 872	},
 873	[CXT_PINCFG_LEMOTE_A1205] = {
 874		.type = HDA_FIXUP_PINS,
 875		.v.pins = cxt_pincfg_lemote,
 876	},
 877	[CXT_PINCFG_COMPAQ_CQ60] = {
 878		.type = HDA_FIXUP_PINS,
 879		.v.pins = (const struct hda_pintbl[]) {
 880			/* 0x17 was falsely set up as a mic, it should 0x1d */
 881			{ 0x17, 0x400001f0 },
 882			{ 0x1d, 0x97a70120 },
 883			{ }
 884		}
 885	},
 886	[CXT_FIXUP_STEREO_DMIC] = {
 887		.type = HDA_FIXUP_FUNC,
 888		.v.func = cxt_fixup_stereo_dmic,
 889	},
 890	[CXT_PINCFG_LENOVO_NOTEBOOK] = {
 891		.type = HDA_FIXUP_PINS,
 892		.v.pins = (const struct hda_pintbl[]) {
 893			{ 0x1a, 0x05d71030 },
 894			{ }
 895		},
 896		.chain_id = CXT_FIXUP_STEREO_DMIC,
 897	},
 898	[CXT_FIXUP_INC_MIC_BOOST] = {
 899		.type = HDA_FIXUP_FUNC,
 900		.v.func = cxt5066_increase_mic_boost,
 901	},
 902	[CXT_FIXUP_HEADPHONE_MIC_PIN] = {
 903		.type = HDA_FIXUP_PINS,
 904		.chained = true,
 905		.chain_id = CXT_FIXUP_HEADPHONE_MIC,
 906		.v.pins = (const struct hda_pintbl[]) {
 907			{ 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
 908			{ }
 909		}
 910	},
 911	[CXT_FIXUP_HEADPHONE_MIC] = {
 912		.type = HDA_FIXUP_FUNC,
 913		.v.func = cxt_fixup_headphone_mic,
 914	},
 915	[CXT_FIXUP_GPIO1] = {
 916		.type = HDA_FIXUP_VERBS,
 917		.v.verbs = (const struct hda_verb[]) {
 918			{ 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
 919			{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
 920			{ 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
 921			{ }
 922		},
 923	},
 924	[CXT_FIXUP_ASPIRE_DMIC] = {
 925		.type = HDA_FIXUP_FUNC,
 926		.v.func = cxt_fixup_stereo_dmic,
 927		.chained = true,
 928		.chain_id = CXT_FIXUP_GPIO1,
 929	},
 930	[CXT_FIXUP_THINKPAD_ACPI] = {
 931		.type = HDA_FIXUP_FUNC,
 932		.v.func = hda_fixup_thinkpad_acpi,
 933	},
 934	[CXT_FIXUP_OLPC_XO] = {
 935		.type = HDA_FIXUP_FUNC,
 936		.v.func = cxt_fixup_olpc_xo,
 937	},
 938	[CXT_FIXUP_CAP_MIX_AMP] = {
 939		.type = HDA_FIXUP_FUNC,
 940		.v.func = cxt_fixup_cap_mix_amp,
 941	},
 942	[CXT_FIXUP_TOSHIBA_P105] = {
 943		.type = HDA_FIXUP_PINS,
 944		.v.pins = (const struct hda_pintbl[]) {
 945			{ 0x10, 0x961701f0 }, /* speaker/hp */
 946			{ 0x12, 0x02a1901e }, /* ext mic */
 947			{ 0x14, 0x95a70110 }, /* int mic */
 948			{}
 949		},
 950	},
 951	[CXT_FIXUP_HP_530] = {
 952		.type = HDA_FIXUP_PINS,
 953		.v.pins = (const struct hda_pintbl[]) {
 954			{ 0x12, 0x90a60160 }, /* int mic */
 955			{}
 956		},
 957		.chained = true,
 958		.chain_id = CXT_FIXUP_CAP_MIX_AMP,
 959	},
 960	[CXT_FIXUP_CAP_MIX_AMP_5047] = {
 961		.type = HDA_FIXUP_FUNC,
 962		.v.func = cxt_fixup_cap_mix_amp_5047,
 963	},
 964	[CXT_FIXUP_MUTE_LED_EAPD] = {
 965		.type = HDA_FIXUP_FUNC,
 966		.v.func = cxt_fixup_mute_led_eapd,
 967	},
 968	[CXT_FIXUP_HP_DOCK] = {
 969		.type = HDA_FIXUP_PINS,
 970		.v.pins = (const struct hda_pintbl[]) {
 971			{ 0x16, 0x21011020 }, /* line-out */
 972			{ 0x18, 0x2181103f }, /* line-in */
 973			{ }
 974		},
 975		.chained = true,
 976		.chain_id = CXT_FIXUP_MUTE_LED_GPIO,
 977	},
 978	[CXT_FIXUP_HP_SPECTRE] = {
 979		.type = HDA_FIXUP_PINS,
 980		.v.pins = (const struct hda_pintbl[]) {
 981			/* enable NID 0x1d for the speaker on top */
 982			{ 0x1d, 0x91170111 },
 983			{ }
 984		}
 985	},
 986	[CXT_FIXUP_HP_GATE_MIC] = {
 987		.type = HDA_FIXUP_FUNC,
 988		.v.func = cxt_fixup_hp_gate_mic_jack,
 989	},
 990	[CXT_FIXUP_MUTE_LED_GPIO] = {
 991		.type = HDA_FIXUP_FUNC,
 992		.v.func = cxt_fixup_mute_led_gpio,
 993	},
 994	[CXT_FIXUP_HP_ZBOOK_MUTE_LED] = {
 995		.type = HDA_FIXUP_FUNC,
 996		.v.func = cxt_fixup_hp_zbook_mute_led,
 997	},
 998	[CXT_FIXUP_HEADSET_MIC] = {
 999		.type = HDA_FIXUP_FUNC,
1000		.v.func = cxt_fixup_headset_mic,
1001	},
1002	[CXT_FIXUP_HP_MIC_NO_PRESENCE] = {
1003		.type = HDA_FIXUP_PINS,
1004		.v.pins = (const struct hda_pintbl[]) {
1005			{ 0x1a, 0x02a1113c },
1006			{ }
1007		},
1008		.chained = true,
1009		.chain_id = CXT_FIXUP_HEADSET_MIC,
1010	},
1011	[CXT_PINCFG_SWS_JS201D] = {
1012		.type = HDA_FIXUP_PINS,
1013		.v.pins = cxt_pincfg_sws_js201d,
1014	},
1015};
1016
1017static const struct snd_pci_quirk cxt5045_fixups[] = {
1018	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
1019	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
1020	/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1021	 * really bad sound over 0dB on NID 0x17.
1022	 */
1023	SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
1024	SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
1025	SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
1026	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
1027	{}
1028};
1029
1030static const struct hda_model_fixup cxt5045_fixup_models[] = {
1031	{ .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
1032	{ .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
1033	{ .id = CXT_FIXUP_HP_530, .name = "hp-530" },
1034	{}
1035};
1036
1037static const struct snd_pci_quirk cxt5047_fixups[] = {
1038	/* HP laptops have really bad sound over 0 dB on NID 0x10.
1039	 */
1040	SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
1041	{}
1042};
1043
1044static const struct hda_model_fixup cxt5047_fixup_models[] = {
1045	{ .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
1046	{}
1047};
1048
1049static const struct snd_pci_quirk cxt5051_fixups[] = {
1050	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq CQ60", CXT_PINCFG_COMPAQ_CQ60),
1051	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
1052	{}
1053};
1054
1055static const struct hda_model_fixup cxt5051_fixup_models[] = {
1056	{ .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
1057	{}
1058};
1059
1060static const struct snd_pci_quirk cxt5066_fixups[] = {
1061	SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
1062	SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC),
1063	SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC),
1064	SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK),
1065	SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK),
1066	SND_PCI_QUIRK(0x103c, 0x80FD, "HP ProBook 640 G2", CXT_FIXUP_HP_DOCK),
1067	SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC),
1068	SND_PCI_QUIRK(0x103c, 0x814f, "HP ZBook 15u G3", CXT_FIXUP_MUTE_LED_GPIO),
1069	SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE),
1070	SND_PCI_QUIRK(0x103c, 0x822e, "HP ProBook 440 G4", CXT_FIXUP_MUTE_LED_GPIO),
1071	SND_PCI_QUIRK(0x103c, 0x828c, "HP EliteBook 840 G4", CXT_FIXUP_HP_DOCK),
1072	SND_PCI_QUIRK(0x103c, 0x8299, "HP 800 G3 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1073	SND_PCI_QUIRK(0x103c, 0x829a, "HP 800 G3 DM", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1074	SND_PCI_QUIRK(0x103c, 0x82b4, "HP ProDesk 600 G3", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1075	SND_PCI_QUIRK(0x103c, 0x836e, "HP ProBook 455 G5", CXT_FIXUP_MUTE_LED_GPIO),
1076	SND_PCI_QUIRK(0x103c, 0x837f, "HP ProBook 470 G5", CXT_FIXUP_MUTE_LED_GPIO),
1077	SND_PCI_QUIRK(0x103c, 0x83b2, "HP EliteBook 840 G5", CXT_FIXUP_HP_DOCK),
1078	SND_PCI_QUIRK(0x103c, 0x83b3, "HP EliteBook 830 G5", CXT_FIXUP_HP_DOCK),
1079	SND_PCI_QUIRK(0x103c, 0x83d3, "HP ProBook 640 G4", CXT_FIXUP_HP_DOCK),
1080	SND_PCI_QUIRK(0x103c, 0x8402, "HP ProBook 645 G4", CXT_FIXUP_MUTE_LED_GPIO),
1081	SND_PCI_QUIRK(0x103c, 0x8427, "HP ZBook Studio G5", CXT_FIXUP_HP_ZBOOK_MUTE_LED),
1082	SND_PCI_QUIRK(0x103c, 0x844f, "HP ZBook Studio G5", CXT_FIXUP_HP_ZBOOK_MUTE_LED),
1083	SND_PCI_QUIRK(0x103c, 0x8455, "HP Z2 G4", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1084	SND_PCI_QUIRK(0x103c, 0x8456, "HP Z2 G4 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1085	SND_PCI_QUIRK(0x103c, 0x8457, "HP Z2 G4 mini", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1086	SND_PCI_QUIRK(0x103c, 0x8458, "HP Z2 G4 mini premium", CXT_FIXUP_HP_MIC_NO_PRESENCE),
1087	SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
1088	SND_PCI_QUIRK(0x14f1, 0x0265, "SWS JS201D", CXT_PINCFG_SWS_JS201D),
1089	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
1090	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
1091	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
1092	SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
1093	SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
1094	SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
1095	SND_PCI_QUIRK(0x17aa, 0x21d2, "Lenovo T420s", CXT_PINCFG_LENOVO_TP410),
1096	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
1097	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
1098	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo IdeaPad Z560", CXT_FIXUP_MUTE_LED_EAPD),
1099	SND_PCI_QUIRK(0x17aa, 0x3905, "Lenovo G50-30", CXT_FIXUP_STEREO_DMIC),
1100	SND_PCI_QUIRK(0x17aa, 0x390b, "Lenovo G50-80", CXT_FIXUP_STEREO_DMIC),
1101	SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
1102	/* NOTE: we'd need to extend the quirk for 17aa:3977 as the same
1103	 * PCI SSID is used on multiple Lenovo models
1104	 */
1105	SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
1106	SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo G50-70", CXT_FIXUP_STEREO_DMIC),
1107	SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
1108	SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
1109	SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
1110	SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
1111	{}
1112};
1113
1114static const struct hda_model_fixup cxt5066_fixup_models[] = {
1115	{ .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
1116	{ .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
1117	{ .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
1118	{ .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
1119	{ .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
1120	{ .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
1121	{ .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" },
1122	{ .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
1123	{ .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" },
1124	{ .id = CXT_FIXUP_HP_DOCK, .name = "hp-dock" },
1125	{ .id = CXT_FIXUP_MUTE_LED_GPIO, .name = "mute-led-gpio" },
1126	{ .id = CXT_FIXUP_HP_ZBOOK_MUTE_LED, .name = "hp-zbook-mute-led" },
1127	{ .id = CXT_FIXUP_HP_MIC_NO_PRESENCE, .name = "hp-mic-fix" },
1128	{ .id = CXT_PINCFG_LENOVO_NOTEBOOK, .name = "lenovo-20149" },
1129	{ .id = CXT_PINCFG_SWS_JS201D, .name = "sws-js201d" },
1130	{}
1131};
1132
1133/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
1134 * can be created (bko#42825)
1135 */
1136static void add_cx5051_fake_mutes(struct hda_codec *codec)
1137{
1138	struct conexant_spec *spec = codec->spec;
1139	static const hda_nid_t out_nids[] = {
1140		0x10, 0x11, 0
1141	};
1142	const hda_nid_t *p;
1143
1144	for (p = out_nids; *p; p++)
1145		snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
1146					  AC_AMPCAP_MIN_MUTE |
1147					  query_amp_caps(codec, *p, HDA_OUTPUT));
1148	spec->gen.dac_min_mute = true;
1149}
1150
1151static int patch_conexant_auto(struct hda_codec *codec)
1152{
1153	struct conexant_spec *spec;
1154	int err;
1155
1156	codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name);
1157
1158	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1159	if (!spec)
1160		return -ENOMEM;
1161	snd_hda_gen_spec_init(&spec->gen);
1162	codec->spec = spec;
1163	codec->patch_ops = cx_auto_patch_ops;
1164
1165	/* init cx8070/sn6140 flag and reset headset_present_flag */
1166	switch (codec->core.vendor_id) {
1167	case 0x14f11f86:
1168	case 0x14f11f87:
1169		spec->is_cx8070_sn6140 = true;
1170		spec->headset_present_flag = CX_HEADSET_NOPRESENT;
1171		break;
1172	}
1173
 
1174	cx_auto_parse_eapd(codec);
1175	spec->gen.own_eapd_ctl = 1;
 
 
1176
1177	switch (codec->core.vendor_id) {
1178	case 0x14f15045:
1179		codec->single_adc_amp = 1;
1180		spec->gen.mixer_nid = 0x17;
1181		spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1182		snd_hda_pick_fixup(codec, cxt5045_fixup_models,
1183				   cxt5045_fixups, cxt_fixups);
1184		break;
1185	case 0x14f15047:
1186		codec->pin_amp_workaround = 1;
1187		spec->gen.mixer_nid = 0x19;
1188		spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1189		snd_hda_pick_fixup(codec, cxt5047_fixup_models,
1190				   cxt5047_fixups, cxt_fixups);
1191		break;
1192	case 0x14f15051:
1193		add_cx5051_fake_mutes(codec);
1194		codec->pin_amp_workaround = 1;
1195		snd_hda_pick_fixup(codec, cxt5051_fixup_models,
1196				   cxt5051_fixups, cxt_fixups);
1197		break;
1198	case 0x14f15098:
1199		codec->pin_amp_workaround = 1;
1200		spec->gen.mixer_nid = 0x22;
1201		spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1202		snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1203				   cxt5066_fixups, cxt_fixups);
1204		break;
1205	case 0x14f150f2:
1206		codec->power_save_node = 1;
1207		fallthrough;
1208	default:
1209		codec->pin_amp_workaround = 1;
1210		snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1211				   cxt5066_fixups, cxt_fixups);
1212		break;
1213	}
1214
1215	if (!spec->gen.vmaster_mute.hook && spec->dynamic_eapd)
1216		spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
 
 
 
 
 
 
 
 
 
1217
1218	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1219
1220	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
1221				       spec->parse_flags);
1222	if (err < 0)
1223		goto error;
1224
1225	err = cx_auto_parse_beep(codec);
1226	if (err < 0)
1227		goto error;
1228
1229	err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1230	if (err < 0)
1231		goto error;
1232
1233	/* Some laptops with Conexant chips show stalls in S3 resume,
1234	 * which falls into the single-cmd mode.
1235	 * Better to make reset, then.
1236	 */
1237	if (!codec->bus->core.sync_write) {
1238		codec_info(codec,
1239			   "Enable sync_write for stable communication\n");
1240		codec->bus->core.sync_write = 1;
1241		codec->bus->allow_bus_reset = 1;
1242	}
1243
1244	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1245
1246	return 0;
1247
1248 error:
1249	cx_auto_free(codec);
1250	return err;
1251}
1252
 
 
 
 
 
 
 
1253/*
1254 */
1255
1256static const struct hda_device_id snd_hda_id_conexant[] = {
1257	HDA_CODEC_ENTRY(0x14f11f86, "CX8070", patch_conexant_auto),
1258	HDA_CODEC_ENTRY(0x14f11f87, "SN6140", patch_conexant_auto),
1259	HDA_CODEC_ENTRY(0x14f12008, "CX8200", patch_conexant_auto),
1260	HDA_CODEC_ENTRY(0x14f120d0, "CX11970", patch_conexant_auto),
1261	HDA_CODEC_ENTRY(0x14f120d1, "SN6180", patch_conexant_auto),
1262	HDA_CODEC_ENTRY(0x14f15045, "CX20549 (Venice)", patch_conexant_auto),
1263	HDA_CODEC_ENTRY(0x14f15047, "CX20551 (Waikiki)", patch_conexant_auto),
1264	HDA_CODEC_ENTRY(0x14f15051, "CX20561 (Hermosa)", patch_conexant_auto),
1265	HDA_CODEC_ENTRY(0x14f15066, "CX20582 (Pebble)", patch_conexant_auto),
1266	HDA_CODEC_ENTRY(0x14f15067, "CX20583 (Pebble HSF)", patch_conexant_auto),
1267	HDA_CODEC_ENTRY(0x14f15068, "CX20584", patch_conexant_auto),
1268	HDA_CODEC_ENTRY(0x14f15069, "CX20585", patch_conexant_auto),
1269	HDA_CODEC_ENTRY(0x14f1506c, "CX20588", patch_conexant_auto),
1270	HDA_CODEC_ENTRY(0x14f1506e, "CX20590", patch_conexant_auto),
1271	HDA_CODEC_ENTRY(0x14f15097, "CX20631", patch_conexant_auto),
1272	HDA_CODEC_ENTRY(0x14f15098, "CX20632", patch_conexant_auto),
1273	HDA_CODEC_ENTRY(0x14f150a1, "CX20641", patch_conexant_auto),
1274	HDA_CODEC_ENTRY(0x14f150a2, "CX20642", patch_conexant_auto),
1275	HDA_CODEC_ENTRY(0x14f150ab, "CX20651", patch_conexant_auto),
1276	HDA_CODEC_ENTRY(0x14f150ac, "CX20652", patch_conexant_auto),
1277	HDA_CODEC_ENTRY(0x14f150b8, "CX20664", patch_conexant_auto),
1278	HDA_CODEC_ENTRY(0x14f150b9, "CX20665", patch_conexant_auto),
1279	HDA_CODEC_ENTRY(0x14f150f1, "CX21722", patch_conexant_auto),
1280	HDA_CODEC_ENTRY(0x14f150f2, "CX20722", patch_conexant_auto),
1281	HDA_CODEC_ENTRY(0x14f150f3, "CX21724", patch_conexant_auto),
1282	HDA_CODEC_ENTRY(0x14f150f4, "CX20724", patch_conexant_auto),
1283	HDA_CODEC_ENTRY(0x14f1510f, "CX20751/2", patch_conexant_auto),
1284	HDA_CODEC_ENTRY(0x14f15110, "CX20751/2", patch_conexant_auto),
1285	HDA_CODEC_ENTRY(0x14f15111, "CX20753/4", patch_conexant_auto),
1286	HDA_CODEC_ENTRY(0x14f15113, "CX20755", patch_conexant_auto),
1287	HDA_CODEC_ENTRY(0x14f15114, "CX20756", patch_conexant_auto),
1288	HDA_CODEC_ENTRY(0x14f15115, "CX20757", patch_conexant_auto),
1289	HDA_CODEC_ENTRY(0x14f151d7, "CX20952", patch_conexant_auto),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1290	{} /* terminator */
1291};
1292MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_conexant);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1293
1294MODULE_LICENSE("GPL");
1295MODULE_DESCRIPTION("Conexant HD-audio codec");
1296
1297static struct hda_codec_driver conexant_driver = {
1298	.id = snd_hda_id_conexant,
 
1299};
1300
1301module_hda_codec_driver(conexant_driver);