aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/arm/pxa2xx-ac97-lib.c8
-rw-r--r--sound/core/compress_offload.c114
-rw-r--r--sound/drivers/aloop.c5
-rw-r--r--sound/drivers/vx/vx_core.c3
-rw-r--r--sound/pci/Kconfig1
-rw-r--r--sound/pci/ali5451/ali5451.c2
-rw-r--r--sound/pci/atiixp.c5
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c23
-rw-r--r--sound/pci/hda/Kconfig25
-rw-r--r--sound/pci/hda/ca0132_regs.h409
-rw-r--r--sound/pci/hda/hda_auto_parser.c129
-rw-r--r--sound/pci/hda/hda_auto_parser.h81
-rw-r--r--sound/pci/hda/hda_codec.c664
-rw-r--r--sound/pci/hda/hda_codec.h93
-rw-r--r--sound/pci/hda/hda_eld.c52
-rw-r--r--sound/pci/hda/hda_generic.c5290
-rw-r--r--sound/pci/hda/hda_generic.h303
-rw-r--r--sound/pci/hda/hda_hwdep.c87
-rw-r--r--sound/pci/hda/hda_intel.c154
-rw-r--r--sound/pci/hda/hda_jack.c9
-rw-r--r--sound/pci/hda/hda_local.h118
-rw-r--r--sound/pci/hda/hda_proc.c35
-rw-r--r--sound/pci/hda/patch_analog.c1418
-rw-r--r--sound/pci/hda/patch_ca0110.c490
-rw-r--r--sound/pci/hda/patch_ca0132.c4374
-rw-r--r--sound/pci/hda/patch_cirrus.c1292
-rw-r--r--sound/pci/hda/patch_cmedia.c166
-rw-r--r--sound/pci/hda/patch_conexant.c1378
-rw-r--r--sound/pci/hda/patch_hdmi.c227
-rw-r--r--sound/pci/hda/patch_realtek.c4349
-rw-r--r--sound/pci/hda/patch_sigmatel.c7429
-rw-r--r--sound/pci/hda/patch_via.c2630
-rw-r--r--sound/pci/ice1712/wm8766.c2
-rw-r--r--sound/pci/intel8x0.c10
-rw-r--r--sound/pci/maestro3.c10
-rw-r--r--sound/pci/nm256/nm256.c3
-rw-r--r--sound/pci/pcxhr/pcxhr_core.c3
-rw-r--r--sound/pci/rme32.c2
-rw-r--r--sound/pci/rme9652/hdsp.c462
-rw-r--r--sound/pci/via82xx.c2
-rw-r--r--sound/soc/atmel/Kconfig6
-rw-r--r--sound/soc/atmel/atmel-pcm-pdc.c4
-rw-r--r--sound/soc/atmel/atmel-pcm.c2
-rw-r--r--sound/soc/atmel/atmel-pcm.h6
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c14
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c6
-rw-r--r--sound/soc/codecs/Kconfig6
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/ak4642.c33
-rw-r--r--sound/soc/codecs/arizona.c264
-rw-r--r--sound/soc/codecs/arizona.h8
-rw-r--r--sound/soc/codecs/cs4271.c34
-rw-r--r--sound/soc/codecs/cs42l52.c4
-rw-r--r--sound/soc/codecs/da7213.c1599
-rw-r--r--sound/soc/codecs/da7213.h523
-rwxr-xr-x[-rw-r--r--]sound/soc/codecs/max98090.c2685
-rwxr-xr-xsound/soc/codecs/max98090.h1549
-rw-r--r--sound/soc/codecs/tlv320aic3x.c87
-rw-r--r--sound/soc/codecs/tlv320aic3x.h4
-rw-r--r--sound/soc/codecs/tlv320dac33.c16
-rw-r--r--sound/soc/codecs/twl4030.c85
-rw-r--r--sound/soc/codecs/twl6040.c62
-rw-r--r--sound/soc/codecs/wm2000.c66
-rw-r--r--sound/soc/codecs/wm2000.h3
-rw-r--r--sound/soc/codecs/wm2200.c62
-rw-r--r--sound/soc/codecs/wm5100.c13
-rw-r--r--sound/soc/codecs/wm5102.c159
-rw-r--r--sound/soc/codecs/wm5110.c94
-rw-r--r--sound/soc/codecs/wm8350.c10
-rw-r--r--sound/soc/codecs/wm8804.c3
-rw-r--r--sound/soc/codecs/wm8962.c37
-rw-r--r--sound/soc/codecs/wm8983.c41
-rw-r--r--sound/soc/codecs/wm8985.c43
-rw-r--r--sound/soc/codecs/wm8994.c10
-rw-r--r--sound/soc/codecs/wm_adsp.c525
-rw-r--r--sound/soc/codecs/wm_adsp.h18
-rw-r--r--sound/soc/codecs/wmfw.h15
-rw-r--r--sound/soc/davinci/davinci-evm.c6
-rw-r--r--sound/soc/davinci/davinci-mcasp.c2
-rw-r--r--sound/soc/dwc/designware_i2s.c4
-rw-r--r--sound/soc/fsl/imx-audmux.c2
-rw-r--r--sound/soc/generic/simple-card.c63
-rw-r--r--sound/soc/mxs/mxs-saif.c49
-rw-r--r--sound/soc/omap/Kconfig19
-rw-r--r--sound/soc/omap/Makefile4
-rw-r--r--sound/soc/omap/n810.c4
-rw-r--r--sound/soc/omap/omap-hdmi.c2
-rw-r--r--sound/soc/omap/omap-mcpdm.c4
-rw-r--r--sound/soc/omap/omap-pcm.c14
-rw-r--r--sound/soc/omap/omap-twl4030.c204
-rw-r--r--sound/soc/omap/omap3pandora.c8
-rw-r--r--sound/soc/omap/rx51.c8
-rw-r--r--sound/soc/omap/sdp3430.c278
-rw-r--r--sound/soc/omap/zoom2.c207
-rw-r--r--sound/soc/pxa/palm27x.c38
-rw-r--r--sound/soc/samsung/Kconfig6
-rw-r--r--sound/soc/samsung/dma.c3
-rw-r--r--sound/soc/samsung/dma.h1
-rw-r--r--sound/soc/samsung/i2s.c267
-rw-r--r--sound/soc/samsung/i2s.h7
-rw-r--r--sound/soc/samsung/s3c24xx-i2s.c2
-rw-r--r--sound/soc/samsung/smdk_wm8580.c7
-rw-r--r--sound/soc/samsung/smdk_wm8994.c30
-rw-r--r--sound/soc/sh/fsi.c242
-rw-r--r--sound/soc/soc-compress.c123
-rw-r--r--sound/soc/soc-core.c135
-rw-r--r--sound/soc/soc-dapm.c6
-rw-r--r--sound/soc/soc-pcm.c19
-rw-r--r--sound/soc/tegra/Kconfig19
-rw-r--r--sound/soc/tegra/Makefile4
-rw-r--r--sound/soc/tegra/tegra20_ac97.c480
-rw-r--r--sound/soc/tegra/tegra20_ac97.h95
-rw-r--r--sound/soc/tegra/tegra20_das.c13
-rw-r--r--sound/soc/tegra/tegra30_ahub.c4
-rw-r--r--sound/soc/tegra/tegra30_i2s.c4
-rw-r--r--sound/soc/tegra/tegra_asoc_utils.c53
-rw-r--r--sound/soc/tegra/tegra_asoc_utils.h1
-rw-r--r--sound/soc/tegra/tegra_wm9712.c176
-rw-r--r--sound/soc/ux500/mop500.c2
-rw-r--r--sound/usb/caiaq/device.c8
-rw-r--r--sound/usb/card.c2
-rw-r--r--sound/usb/mixer.c1
-rw-r--r--sound/usb/mixer_maps.c4
-rw-r--r--sound/usb/mixer_quirks.c72
-rw-r--r--sound/usb/pcm.c26
-rw-r--r--sound/usb/quirks-table.h73
-rw-r--r--sound/usb/quirks.c13
127 files changed, 24446 insertions, 18323 deletions
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c
index fff7753e35c1..e6f4633b8dd5 100644
--- a/sound/arm/pxa2xx-ac97-lib.c
+++ b/sound/arm/pxa2xx-ac97-lib.c
@@ -34,7 +34,7 @@ static struct clk *ac97_clk;
34static struct clk *ac97conf_clk; 34static struct clk *ac97conf_clk;
35static int reset_gpio; 35static int reset_gpio;
36 36
37extern void pxa27x_assert_ac97reset(int reset_gpio, int on); 37extern void pxa27x_configure_ac97reset(int reset_gpio, bool to_gpio);
38 38
39/* 39/*
40 * Beware PXA27x bugs: 40 * Beware PXA27x bugs:
@@ -140,10 +140,10 @@ static inline void pxa_ac97_warm_pxa27x(void)
140 gsr_bits = 0; 140 gsr_bits = 0;
141 141
142 /* warm reset broken on Bulverde, so manually keep AC97 reset high */ 142 /* warm reset broken on Bulverde, so manually keep AC97 reset high */
143 pxa27x_assert_ac97reset(reset_gpio, 1); 143 pxa27x_configure_ac97reset(reset_gpio, true);
144 udelay(10); 144 udelay(10);
145 GCR |= GCR_WARM_RST; 145 GCR |= GCR_WARM_RST;
146 pxa27x_assert_ac97reset(reset_gpio, 0); 146 pxa27x_configure_ac97reset(reset_gpio, false);
147 udelay(500); 147 udelay(500);
148} 148}
149 149
@@ -358,7 +358,7 @@ int pxa2xx_ac97_hw_probe(struct platform_device *dev)
358 __func__, ret); 358 __func__, ret);
359 goto err_conf; 359 goto err_conf;
360 } 360 }
361 pxa27x_assert_ac97reset(reset_gpio, 0); 361 pxa27x_configure_ac97reset(reset_gpio, false);
362 362
363 ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK"); 363 ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK");
364 if (IS_ERR(ac97conf_clk)) { 364 if (IS_ERR(ac97conf_clk)) {
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index ad11dc994792..c84abc886e90 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -144,16 +144,17 @@ static int snd_compr_free(struct inode *inode, struct file *f)
144 return 0; 144 return 0;
145} 145}
146 146
147static void snd_compr_update_tstamp(struct snd_compr_stream *stream, 147static int snd_compr_update_tstamp(struct snd_compr_stream *stream,
148 struct snd_compr_tstamp *tstamp) 148 struct snd_compr_tstamp *tstamp)
149{ 149{
150 if (!stream->ops->pointer) 150 if (!stream->ops->pointer)
151 return; 151 return -ENOTSUPP;
152 stream->ops->pointer(stream, tstamp); 152 stream->ops->pointer(stream, tstamp);
153 pr_debug("dsp consumed till %d total %d bytes\n", 153 pr_debug("dsp consumed till %d total %d bytes\n",
154 tstamp->byte_offset, tstamp->copied_total); 154 tstamp->byte_offset, tstamp->copied_total);
155 stream->runtime->hw_pointer = tstamp->byte_offset; 155 stream->runtime->hw_pointer = tstamp->byte_offset;
156 stream->runtime->total_bytes_transferred = tstamp->copied_total; 156 stream->runtime->total_bytes_transferred = tstamp->copied_total;
157 return 0;
157} 158}
158 159
159static size_t snd_compr_calc_avail(struct snd_compr_stream *stream, 160static size_t snd_compr_calc_avail(struct snd_compr_stream *stream,
@@ -161,7 +162,9 @@ static size_t snd_compr_calc_avail(struct snd_compr_stream *stream,
161{ 162{
162 long avail_calc; /*this needs to be signed variable */ 163 long avail_calc; /*this needs to be signed variable */
163 164
165 memset(avail, 0, sizeof(*avail));
164 snd_compr_update_tstamp(stream, &avail->tstamp); 166 snd_compr_update_tstamp(stream, &avail->tstamp);
167 /* Still need to return avail even if tstamp can't be filled in */
165 168
166 /* FIXME: This needs to be different for capture stream, 169 /* FIXME: This needs to be different for capture stream,
167 available is # of compressed data, for playback it's 170 available is # of compressed data, for playback it's
@@ -483,6 +486,8 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
483 if (retval) 486 if (retval)
484 goto out; 487 goto out;
485 stream->runtime->state = SNDRV_PCM_STATE_SETUP; 488 stream->runtime->state = SNDRV_PCM_STATE_SETUP;
489 stream->metadata_set = false;
490 stream->next_track = false;
486 } else { 491 } else {
487 return -EPERM; 492 return -EPERM;
488 } 493 }
@@ -514,14 +519,60 @@ out:
514 return retval; 519 return retval;
515} 520}
516 521
522static int
523snd_compr_get_metadata(struct snd_compr_stream *stream, unsigned long arg)
524{
525 struct snd_compr_metadata metadata;
526 int retval;
527
528 if (!stream->ops->get_metadata)
529 return -ENXIO;
530
531 if (copy_from_user(&metadata, (void __user *)arg, sizeof(metadata)))
532 return -EFAULT;
533
534 retval = stream->ops->get_metadata(stream, &metadata);
535 if (retval != 0)
536 return retval;
537
538 if (copy_to_user((void __user *)arg, &metadata, sizeof(metadata)))
539 return -EFAULT;
540
541 return 0;
542}
543
544static int
545snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg)
546{
547 struct snd_compr_metadata metadata;
548 int retval;
549
550 if (!stream->ops->set_metadata)
551 return -ENXIO;
552 /*
553 * we should allow parameter change only when stream has been
554 * opened not in other cases
555 */
556 if (copy_from_user(&metadata, (void __user *)arg, sizeof(metadata)))
557 return -EFAULT;
558
559 retval = stream->ops->set_metadata(stream, &metadata);
560 stream->metadata_set = true;
561
562 return retval;
563}
564
517static inline int 565static inline int
518snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg) 566snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg)
519{ 567{
520 struct snd_compr_tstamp tstamp; 568 struct snd_compr_tstamp tstamp = {0};
569 int ret;
521 570
522 snd_compr_update_tstamp(stream, &tstamp); 571 ret = snd_compr_update_tstamp(stream, &tstamp);
523 return copy_to_user((struct snd_compr_tstamp __user *)arg, 572 if (ret == 0)
524 &tstamp, sizeof(tstamp)) ? -EFAULT : 0; 573 ret = copy_to_user((struct snd_compr_tstamp __user *)arg,
574 &tstamp, sizeof(tstamp)) ? -EFAULT : 0;
575 return ret;
525} 576}
526 577
527static int snd_compr_pause(struct snd_compr_stream *stream) 578static int snd_compr_pause(struct snd_compr_stream *stream)
@@ -594,6 +645,44 @@ static int snd_compr_drain(struct snd_compr_stream *stream)
594 return retval; 645 return retval;
595} 646}
596 647
648static int snd_compr_next_track(struct snd_compr_stream *stream)
649{
650 int retval;
651
652 /* only a running stream can transition to next track */
653 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING)
654 return -EPERM;
655
656 /* you can signal next track isf this is intended to be a gapless stream
657 * and current track metadata is set
658 */
659 if (stream->metadata_set == false)
660 return -EPERM;
661
662 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_NEXT_TRACK);
663 if (retval != 0)
664 return retval;
665 stream->metadata_set = false;
666 stream->next_track = true;
667 return 0;
668}
669
670static int snd_compr_partial_drain(struct snd_compr_stream *stream)
671{
672 int retval;
673 if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
674 stream->runtime->state == SNDRV_PCM_STATE_SETUP)
675 return -EPERM;
676 /* stream can be drained only when next track has been signalled */
677 if (stream->next_track == false)
678 return -EPERM;
679
680 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN);
681
682 stream->next_track = false;
683 return retval;
684}
685
597static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 686static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
598{ 687{
599 struct snd_compr_file *data = f->private_data; 688 struct snd_compr_file *data = f->private_data;
@@ -623,6 +712,12 @@ static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
623 case _IOC_NR(SNDRV_COMPRESS_GET_PARAMS): 712 case _IOC_NR(SNDRV_COMPRESS_GET_PARAMS):
624 retval = snd_compr_get_params(stream, arg); 713 retval = snd_compr_get_params(stream, arg);
625 break; 714 break;
715 case _IOC_NR(SNDRV_COMPRESS_SET_METADATA):
716 retval = snd_compr_set_metadata(stream, arg);
717 break;
718 case _IOC_NR(SNDRV_COMPRESS_GET_METADATA):
719 retval = snd_compr_get_metadata(stream, arg);
720 break;
626 case _IOC_NR(SNDRV_COMPRESS_TSTAMP): 721 case _IOC_NR(SNDRV_COMPRESS_TSTAMP):
627 retval = snd_compr_tstamp(stream, arg); 722 retval = snd_compr_tstamp(stream, arg);
628 break; 723 break;
@@ -644,6 +739,13 @@ static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
644 case _IOC_NR(SNDRV_COMPRESS_DRAIN): 739 case _IOC_NR(SNDRV_COMPRESS_DRAIN):
645 retval = snd_compr_drain(stream); 740 retval = snd_compr_drain(stream);
646 break; 741 break;
742 case _IOC_NR(SNDRV_COMPRESS_PARTIAL_DRAIN):
743 retval = snd_compr_partial_drain(stream);
744 break;
745 case _IOC_NR(SNDRV_COMPRESS_NEXT_TRACK):
746 retval = snd_compr_next_track(stream);
747 break;
748
647 } 749 }
648 mutex_unlock(&stream->device->lock); 750 mutex_unlock(&stream->device->lock);
649 return retval; 751 return retval;
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index 3d822328d383..64d534710b51 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -286,12 +286,14 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd)
286 loopback_active_notify(dpcm); 286 loopback_active_notify(dpcm);
287 break; 287 break;
288 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 288 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
289 case SNDRV_PCM_TRIGGER_SUSPEND:
289 spin_lock(&cable->lock); 290 spin_lock(&cable->lock);
290 cable->pause |= stream; 291 cable->pause |= stream;
291 loopback_timer_stop(dpcm); 292 loopback_timer_stop(dpcm);
292 spin_unlock(&cable->lock); 293 spin_unlock(&cable->lock);
293 break; 294 break;
294 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 295 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
296 case SNDRV_PCM_TRIGGER_RESUME:
295 spin_lock(&cable->lock); 297 spin_lock(&cable->lock);
296 dpcm->last_jiffies = jiffies; 298 dpcm->last_jiffies = jiffies;
297 cable->pause &= ~stream; 299 cable->pause &= ~stream;
@@ -563,7 +565,8 @@ static snd_pcm_uframes_t loopback_pointer(struct snd_pcm_substream *substream)
563static struct snd_pcm_hardware loopback_pcm_hardware = 565static struct snd_pcm_hardware loopback_pcm_hardware =
564{ 566{
565 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP | 567 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP |
566 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), 568 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE |
569 SNDRV_PCM_INFO_RESUME),
567 .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | 570 .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
568 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE | 571 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |
569 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE), 572 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE),
diff --git a/sound/drivers/vx/vx_core.c b/sound/drivers/vx/vx_core.c
index de5055a3b0d0..c39961c11401 100644
--- a/sound/drivers/vx/vx_core.c
+++ b/sound/drivers/vx/vx_core.c
@@ -52,7 +52,6 @@ MODULE_LICENSE("GPL");
52int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int time) 52int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int time)
53{ 53{
54 unsigned long end_time = jiffies + (time * HZ + 999) / 1000; 54 unsigned long end_time = jiffies + (time * HZ + 999) / 1000;
55#ifdef CONFIG_SND_DEBUG
56 static char *reg_names[VX_REG_MAX] = { 55 static char *reg_names[VX_REG_MAX] = {
57 "ICR", "CVR", "ISR", "IVR", "RXH", "RXM", "RXL", 56 "ICR", "CVR", "ISR", "IVR", "RXH", "RXM", "RXL",
58 "DMA", "CDSP", "RFREQ", "RUER/V2", "DATA", "MEMIRQ", 57 "DMA", "CDSP", "RFREQ", "RUER/V2", "DATA", "MEMIRQ",
@@ -60,7 +59,7 @@ int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int t
60 "MIC3", "INTCSR", "CNTRL", "GPIOC", 59 "MIC3", "INTCSR", "CNTRL", "GPIOC",
61 "LOFREQ", "HIFREQ", "CSUER", "RUER" 60 "LOFREQ", "HIFREQ", "CSUER", "RUER"
62 }; 61 };
63#endif 62
64 do { 63 do {
65 if ((snd_vx_inb(chip, reg) & mask) == bit) 64 if ((snd_vx_inb(chip, reg) & mask) == bit)
66 return 0; 65 return 0;
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 947cfb4eb30c..fe6fa93a6262 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -678,6 +678,7 @@ config SND_LOLA
678 678
679config SND_LX6464ES 679config SND_LX6464ES
680 tristate "Digigram LX6464ES" 680 tristate "Digigram LX6464ES"
681 depends on HAS_IOPORT
681 select SND_PCM 682 select SND_PCM
682 help 683 help
683 Say Y here to include support for Digigram LX6464ES boards. 684 Say Y here to include support for Digigram LX6464ES boards.
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index 136a393b70ab..e760af9d1fb6 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -1435,7 +1435,7 @@ static snd_pcm_uframes_t snd_ali_pointer(struct snd_pcm_substream *substream)
1435 1435
1436 spin_lock(&codec->reg_lock); 1436 spin_lock(&codec->reg_lock);
1437 if (!pvoice->running) { 1437 if (!pvoice->running) {
1438 spin_unlock_irq(&codec->reg_lock); 1438 spin_unlock(&codec->reg_lock);
1439 return 0; 1439 return 0;
1440 } 1440 }
1441 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); 1441 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR));
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index a67743183aaf..6e78c6789858 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -567,8 +567,9 @@ static int ac97_probing_bugs(struct pci_dev *pci)
567 567
568 q = snd_pci_quirk_lookup(pci, atiixp_quirks); 568 q = snd_pci_quirk_lookup(pci, atiixp_quirks);
569 if (q) { 569 if (q) {
570 snd_printdd(KERN_INFO "Atiixp quirk for %s. " 570 snd_printdd(KERN_INFO
571 "Forcing codec %d\n", q->name, q->value); 571 "Atiixp quirk for %s. Forcing codec %d\n",
572 snd_pci_quirk_name(q), q->value);
572 return q->value; 573 return q->value;
573 } 574 }
574 /* this hardware doesn't need workarounds. Probe for codec */ 575 /* this hardware doesn't need workarounds. Probe for codec */
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index a4184bb27761..b46dc9b24dbd 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -650,6 +650,29 @@ static int snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
650 snd_dma_pci_data(chip->pci_dev), 650 snd_dma_pci_data(chip->pci_dev),
651 0x10000, 0x10000); 651 0x10000, 0x10000);
652 652
653 switch (VORTEX_PCM_TYPE(pcm)) {
654 case VORTEX_PCM_ADB:
655 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
656 snd_pcm_std_chmaps,
657 VORTEX_IS_QUAD(chip) ? 4 : 2,
658 0, NULL);
659 if (err < 0)
660 return err;
661 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_CAPTURE,
662 snd_pcm_std_chmaps, 2, 0, NULL);
663 if (err < 0)
664 return err;
665 break;
666#ifdef CHIP_AU8830
667 case VORTEX_PCM_A3D:
668 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
669 snd_pcm_std_chmaps, 1, 0, NULL);
670 if (err < 0)
671 return err;
672 break;
673#endif
674 };
675
653 if (VORTEX_PCM_TYPE(pcm) == VORTEX_PCM_SPDIF) { 676 if (VORTEX_PCM_TYPE(pcm) == VORTEX_PCM_SPDIF) {
654 for (i = 0; i < ARRAY_SIZE(snd_vortex_mixer_spdif); i++) { 677 for (i = 0; i < ARRAY_SIZE(snd_vortex_mixer_spdif); i++) {
655 kctl = snd_ctl_new1(&snd_vortex_mixer_spdif[i], chip); 678 kctl = snd_ctl_new1(&snd_vortex_mixer_spdif[i], chip);
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 6eeb8897624b..80a7d44bcf81 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -15,6 +15,9 @@ menuconfig SND_HDA_INTEL
15 15
16if SND_HDA_INTEL 16if SND_HDA_INTEL
17 17
18config SND_HDA_DSP_LOADER
19 bool
20
18config SND_HDA_PREALLOC_SIZE 21config SND_HDA_PREALLOC_SIZE
19 int "Pre-allocated buffer size for HD-audio driver" 22 int "Pre-allocated buffer size for HD-audio driver"
20 range 0 32768 23 range 0 32768
@@ -86,6 +89,7 @@ config SND_HDA_PATCH_LOADER
86config SND_HDA_CODEC_REALTEK 89config SND_HDA_CODEC_REALTEK
87 bool "Build Realtek HD-audio codec support" 90 bool "Build Realtek HD-audio codec support"
88 default y 91 default y
92 select SND_HDA_GENERIC
89 help 93 help
90 Say Y here to include Realtek HD-audio codec support in 94 Say Y here to include Realtek HD-audio codec support in
91 snd-hda-intel driver, such as ALC880. 95 snd-hda-intel driver, such as ALC880.
@@ -98,6 +102,7 @@ config SND_HDA_CODEC_REALTEK
98config SND_HDA_CODEC_ANALOG 102config SND_HDA_CODEC_ANALOG
99 bool "Build Analog Device HD-audio codec support" 103 bool "Build Analog Device HD-audio codec support"
100 default y 104 default y
105 select SND_HDA_GENERIC
101 help 106 help
102 Say Y here to include Analog Device HD-audio codec support in 107 Say Y here to include Analog Device HD-audio codec support in
103 snd-hda-intel driver, such as AD1986A. 108 snd-hda-intel driver, such as AD1986A.
@@ -110,6 +115,7 @@ config SND_HDA_CODEC_ANALOG
110config SND_HDA_CODEC_SIGMATEL 115config SND_HDA_CODEC_SIGMATEL
111 bool "Build IDT/Sigmatel HD-audio codec support" 116 bool "Build IDT/Sigmatel HD-audio codec support"
112 default y 117 default y
118 select SND_HDA_GENERIC
113 help 119 help
114 Say Y here to include IDT (Sigmatel) HD-audio codec support in 120 Say Y here to include IDT (Sigmatel) HD-audio codec support in
115 snd-hda-intel driver, such as STAC9200. 121 snd-hda-intel driver, such as STAC9200.
@@ -122,6 +128,7 @@ config SND_HDA_CODEC_SIGMATEL
122config SND_HDA_CODEC_VIA 128config SND_HDA_CODEC_VIA
123 bool "Build VIA HD-audio codec support" 129 bool "Build VIA HD-audio codec support"
124 default y 130 default y
131 select SND_HDA_GENERIC
125 help 132 help
126 Say Y here to include VIA HD-audio codec support in 133 Say Y here to include VIA HD-audio codec support in
127 snd-hda-intel driver, such as VT1708. 134 snd-hda-intel driver, such as VT1708.
@@ -147,8 +154,8 @@ config SND_HDA_CODEC_HDMI
147 154
148config SND_HDA_CODEC_CIRRUS 155config SND_HDA_CODEC_CIRRUS
149 bool "Build Cirrus Logic codec support" 156 bool "Build Cirrus Logic codec support"
150 depends on SND_HDA_INTEL
151 default y 157 default y
158 select SND_HDA_GENERIC
152 help 159 help
153 Say Y here to include Cirrus Logic codec support in 160 Say Y here to include Cirrus Logic codec support in
154 snd-hda-intel driver, such as CS4206. 161 snd-hda-intel driver, such as CS4206.
@@ -161,6 +168,7 @@ config SND_HDA_CODEC_CIRRUS
161config SND_HDA_CODEC_CONEXANT 168config SND_HDA_CODEC_CONEXANT
162 bool "Build Conexant HD-audio codec support" 169 bool "Build Conexant HD-audio codec support"
163 default y 170 default y
171 select SND_HDA_GENERIC
164 help 172 help
165 Say Y here to include Conexant HD-audio codec support in 173 Say Y here to include Conexant HD-audio codec support in
166 snd-hda-intel driver, such as CX20549. 174 snd-hda-intel driver, such as CX20549.
@@ -172,8 +180,8 @@ config SND_HDA_CODEC_CONEXANT
172 180
173config SND_HDA_CODEC_CA0110 181config SND_HDA_CODEC_CA0110
174 bool "Build Creative CA0110-IBG codec support" 182 bool "Build Creative CA0110-IBG codec support"
175 depends on SND_HDA_INTEL
176 default y 183 default y
184 select SND_HDA_GENERIC
177 help 185 help
178 Say Y here to include Creative CA0110-IBG codec support in 186 Say Y here to include Creative CA0110-IBG codec support in
179 snd-hda-intel driver, found on some Creative X-Fi cards. 187 snd-hda-intel driver, found on some Creative X-Fi cards.
@@ -185,7 +193,6 @@ config SND_HDA_CODEC_CA0110
185 193
186config SND_HDA_CODEC_CA0132 194config SND_HDA_CODEC_CA0132
187 bool "Build Creative CA0132 codec support" 195 bool "Build Creative CA0132 codec support"
188 depends on SND_HDA_INTEL
189 default y 196 default y
190 help 197 help
191 Say Y here to include Creative CA0132 codec support in 198 Say Y here to include Creative CA0132 codec support in
@@ -196,9 +203,21 @@ config SND_HDA_CODEC_CA0132
196 snd-hda-codec-ca0132. 203 snd-hda-codec-ca0132.
197 This module is automatically loaded at probing. 204 This module is automatically loaded at probing.
198 205
206config SND_HDA_CODEC_CA0132_DSP
207 bool "Support new DSP code for CA0132 codec"
208 depends on SND_HDA_CODEC_CA0132 && FW_LOADER
209 select SND_HDA_DSP_LOADER
210 help
211 Say Y here to enable the DSP for Creative CA0132 for extended
212 features like equalizer or echo cancellation.
213
214 Note that this option requires the external firmware file
215 (ctefx.bin).
216
199config SND_HDA_CODEC_CMEDIA 217config SND_HDA_CODEC_CMEDIA
200 bool "Build C-Media HD-audio codec support" 218 bool "Build C-Media HD-audio codec support"
201 default y 219 default y
220 select SND_HDA_GENERIC
202 help 221 help
203 Say Y here to include C-Media HD-audio codec support in 222 Say Y here to include C-Media HD-audio codec support in
204 snd-hda-intel driver, such as CMI9880. 223 snd-hda-intel driver, such as CMI9880.
diff --git a/sound/pci/hda/ca0132_regs.h b/sound/pci/hda/ca0132_regs.h
new file mode 100644
index 000000000000..07e760937d3c
--- /dev/null
+++ b/sound/pci/hda/ca0132_regs.h
@@ -0,0 +1,409 @@
1/*
2 * HD audio interface patch for Creative CA0132 chip.
3 * CA0132 registers defines.
4 *
5 * Copyright (c) 2011, Creative Technology Ltd.
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef __CA0132_REGS_H
23#define __CA0312_REGS_H
24
25#define DSP_CHIP_OFFSET 0x100000
26#define DSP_DBGCNTL_MODULE_OFFSET 0xE30
27#define DSP_DBGCNTL_INST_OFFSET \
28 (DSP_CHIP_OFFSET + DSP_DBGCNTL_MODULE_OFFSET)
29
30#define DSP_DBGCNTL_EXEC_LOBIT 0x0
31#define DSP_DBGCNTL_EXEC_HIBIT 0x3
32#define DSP_DBGCNTL_EXEC_MASK 0xF
33
34#define DSP_DBGCNTL_SS_LOBIT 0x4
35#define DSP_DBGCNTL_SS_HIBIT 0x7
36#define DSP_DBGCNTL_SS_MASK 0xF0
37
38#define DSP_DBGCNTL_STATE_LOBIT 0xA
39#define DSP_DBGCNTL_STATE_HIBIT 0xD
40#define DSP_DBGCNTL_STATE_MASK 0x3C00
41
42#define XRAM_CHIP_OFFSET 0x0
43#define XRAM_XRAM_CHANNEL_COUNT 0xE000
44#define XRAM_XRAM_MODULE_OFFSET 0x0
45#define XRAM_XRAM_CHAN_INCR 4
46#define XRAM_XRAM_INST_OFFSET(_chan) \
47 (XRAM_CHIP_OFFSET + XRAM_XRAM_MODULE_OFFSET + \
48 (_chan * XRAM_XRAM_CHAN_INCR))
49
50#define YRAM_CHIP_OFFSET 0x40000
51#define YRAM_YRAM_CHANNEL_COUNT 0x8000
52#define YRAM_YRAM_MODULE_OFFSET 0x0
53#define YRAM_YRAM_CHAN_INCR 4
54#define YRAM_YRAM_INST_OFFSET(_chan) \
55 (YRAM_CHIP_OFFSET + YRAM_YRAM_MODULE_OFFSET + \
56 (_chan * YRAM_YRAM_CHAN_INCR))
57
58#define UC_CHIP_OFFSET 0x80000
59#define UC_UC_CHANNEL_COUNT 0x10000
60#define UC_UC_MODULE_OFFSET 0x0
61#define UC_UC_CHAN_INCR 4
62#define UC_UC_INST_OFFSET(_chan) \
63 (UC_CHIP_OFFSET + UC_UC_MODULE_OFFSET + \
64 (_chan * UC_UC_CHAN_INCR))
65
66#define AXRAM_CHIP_OFFSET 0x3C000
67#define AXRAM_AXRAM_CHANNEL_COUNT 0x1000
68#define AXRAM_AXRAM_MODULE_OFFSET 0x0
69#define AXRAM_AXRAM_CHAN_INCR 4
70#define AXRAM_AXRAM_INST_OFFSET(_chan) \
71 (AXRAM_CHIP_OFFSET + AXRAM_AXRAM_MODULE_OFFSET + \
72 (_chan * AXRAM_AXRAM_CHAN_INCR))
73
74#define AYRAM_CHIP_OFFSET 0x78000
75#define AYRAM_AYRAM_CHANNEL_COUNT 0x1000
76#define AYRAM_AYRAM_MODULE_OFFSET 0x0
77#define AYRAM_AYRAM_CHAN_INCR 4
78#define AYRAM_AYRAM_INST_OFFSET(_chan) \
79 (AYRAM_CHIP_OFFSET + AYRAM_AYRAM_MODULE_OFFSET + \
80 (_chan * AYRAM_AYRAM_CHAN_INCR))
81
82#define DSPDMAC_CHIP_OFFSET 0x110000
83#define DSPDMAC_DMA_CFG_CHANNEL_COUNT 12
84#define DSPDMAC_DMACFG_MODULE_OFFSET 0xF00
85#define DSPDMAC_DMACFG_CHAN_INCR 0x10
86#define DSPDMAC_DMACFG_INST_OFFSET(_chan) \
87 (DSPDMAC_CHIP_OFFSET + DSPDMAC_DMACFG_MODULE_OFFSET + \
88 (_chan * DSPDMAC_DMACFG_CHAN_INCR))
89
90#define DSPDMAC_DMACFG_DBADR_LOBIT 0x0
91#define DSPDMAC_DMACFG_DBADR_HIBIT 0x10
92#define DSPDMAC_DMACFG_DBADR_MASK 0x1FFFF
93#define DSPDMAC_DMACFG_LP_LOBIT 0x11
94#define DSPDMAC_DMACFG_LP_HIBIT 0x11
95#define DSPDMAC_DMACFG_LP_MASK 0x20000
96
97#define DSPDMAC_DMACFG_AINCR_LOBIT 0x12
98#define DSPDMAC_DMACFG_AINCR_HIBIT 0x12
99#define DSPDMAC_DMACFG_AINCR_MASK 0x40000
100
101#define DSPDMAC_DMACFG_DWR_LOBIT 0x13
102#define DSPDMAC_DMACFG_DWR_HIBIT 0x13
103#define DSPDMAC_DMACFG_DWR_MASK 0x80000
104
105#define DSPDMAC_DMACFG_AJUMP_LOBIT 0x14
106#define DSPDMAC_DMACFG_AJUMP_HIBIT 0x17
107#define DSPDMAC_DMACFG_AJUMP_MASK 0xF00000
108
109#define DSPDMAC_DMACFG_AMODE_LOBIT 0x18
110#define DSPDMAC_DMACFG_AMODE_HIBIT 0x19
111#define DSPDMAC_DMACFG_AMODE_MASK 0x3000000
112
113#define DSPDMAC_DMACFG_LK_LOBIT 0x1A
114#define DSPDMAC_DMACFG_LK_HIBIT 0x1A
115#define DSPDMAC_DMACFG_LK_MASK 0x4000000
116
117#define DSPDMAC_DMACFG_AICS_LOBIT 0x1B
118#define DSPDMAC_DMACFG_AICS_HIBIT 0x1F
119#define DSPDMAC_DMACFG_AICS_MASK 0xF8000000
120
121#define DSPDMAC_DMACFG_LP_SINGLE 0
122#define DSPDMAC_DMACFG_LP_LOOPING 1
123
124#define DSPDMAC_DMACFG_AINCR_XANDY 0
125#define DSPDMAC_DMACFG_AINCR_XORY 1
126
127#define DSPDMAC_DMACFG_DWR_DMA_RD 0
128#define DSPDMAC_DMACFG_DWR_DMA_WR 1
129
130#define DSPDMAC_DMACFG_AMODE_LINEAR 0
131#define DSPDMAC_DMACFG_AMODE_RSV1 1
132#define DSPDMAC_DMACFG_AMODE_WINTLV 2
133#define DSPDMAC_DMACFG_AMODE_GINTLV 3
134
135#define DSPDMAC_DSP_ADR_OFS_CHANNEL_COUNT 12
136#define DSPDMAC_DSPADROFS_MODULE_OFFSET 0xF04
137#define DSPDMAC_DSPADROFS_CHAN_INCR 0x10
138#define DSPDMAC_DSPADROFS_INST_OFFSET(_chan) \
139 (DSPDMAC_CHIP_OFFSET + DSPDMAC_DSPADROFS_MODULE_OFFSET + \
140 (_chan * DSPDMAC_DSPADROFS_CHAN_INCR))
141
142#define DSPDMAC_DSPADROFS_COFS_LOBIT 0x0
143#define DSPDMAC_DSPADROFS_COFS_HIBIT 0xF
144#define DSPDMAC_DSPADROFS_COFS_MASK 0xFFFF
145
146#define DSPDMAC_DSPADROFS_BOFS_LOBIT 0x10
147#define DSPDMAC_DSPADROFS_BOFS_HIBIT 0x1F
148#define DSPDMAC_DSPADROFS_BOFS_MASK 0xFFFF0000
149
150#define DSPDMAC_DSP_ADR_WOFS_CHANNEL_COUNT 12
151#define DSPDMAC_DSPADRWOFS_MODULE_OFFSET 0xF04
152#define DSPDMAC_DSPADRWOFS_CHAN_INCR 0x10
153
154#define DSPDMAC_DSPADRWOFS_INST_OFFSET(_chan) \
155 (DSPDMAC_CHIP_OFFSET + DSPDMAC_DSPADRWOFS_MODULE_OFFSET + \
156 (_chan * DSPDMAC_DSPADRWOFS_CHAN_INCR))
157
158#define DSPDMAC_DSPADRWOFS_WCOFS_LOBIT 0x0
159#define DSPDMAC_DSPADRWOFS_WCOFS_HIBIT 0xA
160#define DSPDMAC_DSPADRWOFS_WCOFS_MASK 0x7FF
161
162#define DSPDMAC_DSPADRWOFS_WCBFR_LOBIT 0xB
163#define DSPDMAC_DSPADRWOFS_WCBFR_HIBIT 0xF
164#define DSPDMAC_DSPADRWOFS_WCBFR_MASK 0xF800
165
166#define DSPDMAC_DSPADRWOFS_WBOFS_LOBIT 0x10
167#define DSPDMAC_DSPADRWOFS_WBOFS_HIBIT 0x1A
168#define DSPDMAC_DSPADRWOFS_WBOFS_MASK 0x7FF0000
169
170#define DSPDMAC_DSPADRWOFS_WBBFR_LOBIT 0x1B
171#define DSPDMAC_DSPADRWOFS_WBBFR_HIBIT 0x1F
172#define DSPDMAC_DSPADRWOFS_WBBFR_MASK 0xF8000000
173
174#define DSPDMAC_DSP_ADR_GOFS_CHANNEL_COUNT 12
175#define DSPDMAC_DSPADRGOFS_MODULE_OFFSET 0xF04
176#define DSPDMAC_DSPADRGOFS_CHAN_INCR 0x10
177#define DSPDMAC_DSPADRGOFS_INST_OFFSET(_chan) \
178 (DSPDMAC_CHIP_OFFSET + DSPDMAC_DSPADRGOFS_MODULE_OFFSET + \
179 (_chan * DSPDMAC_DSPADRGOFS_CHAN_INCR))
180
181#define DSPDMAC_DSPADRGOFS_GCOFS_LOBIT 0x0
182#define DSPDMAC_DSPADRGOFS_GCOFS_HIBIT 0x9
183#define DSPDMAC_DSPADRGOFS_GCOFS_MASK 0x3FF
184
185#define DSPDMAC_DSPADRGOFS_GCS_LOBIT 0xA
186#define DSPDMAC_DSPADRGOFS_GCS_HIBIT 0xC
187#define DSPDMAC_DSPADRGOFS_GCS_MASK 0x1C00
188
189#define DSPDMAC_DSPADRGOFS_GCBFR_LOBIT 0xD
190#define DSPDMAC_DSPADRGOFS_GCBFR_HIBIT 0xF
191#define DSPDMAC_DSPADRGOFS_GCBFR_MASK 0xE000
192
193#define DSPDMAC_DSPADRGOFS_GBOFS_LOBIT 0x10
194#define DSPDMAC_DSPADRGOFS_GBOFS_HIBIT 0x19
195#define DSPDMAC_DSPADRGOFS_GBOFS_MASK 0x3FF0000
196
197#define DSPDMAC_DSPADRGOFS_GBS_LOBIT 0x1A
198#define DSPDMAC_DSPADRGOFS_GBS_HIBIT 0x1C
199#define DSPDMAC_DSPADRGOFS_GBS_MASK 0x1C000000
200
201#define DSPDMAC_DSPADRGOFS_GBBFR_LOBIT 0x1D
202#define DSPDMAC_DSPADRGOFS_GBBFR_HIBIT 0x1F
203#define DSPDMAC_DSPADRGOFS_GBBFR_MASK 0xE0000000
204
205#define DSPDMAC_XFR_CNT_CHANNEL_COUNT 12
206#define DSPDMAC_XFRCNT_MODULE_OFFSET 0xF08
207#define DSPDMAC_XFRCNT_CHAN_INCR 0x10
208
209#define DSPDMAC_XFRCNT_INST_OFFSET(_chan) \
210 (DSPDMAC_CHIP_OFFSET + DSPDMAC_XFRCNT_MODULE_OFFSET + \
211 (_chan * DSPDMAC_XFRCNT_CHAN_INCR))
212
213#define DSPDMAC_XFRCNT_CCNT_LOBIT 0x0
214#define DSPDMAC_XFRCNT_CCNT_HIBIT 0xF
215#define DSPDMAC_XFRCNT_CCNT_MASK 0xFFFF
216
217#define DSPDMAC_XFRCNT_BCNT_LOBIT 0x10
218#define DSPDMAC_XFRCNT_BCNT_HIBIT 0x1F
219#define DSPDMAC_XFRCNT_BCNT_MASK 0xFFFF0000
220
221#define DSPDMAC_IRQ_CNT_CHANNEL_COUNT 12
222#define DSPDMAC_IRQCNT_MODULE_OFFSET 0xF0C
223#define DSPDMAC_IRQCNT_CHAN_INCR 0x10
224#define DSPDMAC_IRQCNT_INST_OFFSET(_chan) \
225 (DSPDMAC_CHIP_OFFSET + DSPDMAC_IRQCNT_MODULE_OFFSET + \
226 (_chan * DSPDMAC_IRQCNT_CHAN_INCR))
227
228#define DSPDMAC_IRQCNT_CICNT_LOBIT 0x0
229#define DSPDMAC_IRQCNT_CICNT_HIBIT 0xF
230#define DSPDMAC_IRQCNT_CICNT_MASK 0xFFFF
231
232#define DSPDMAC_IRQCNT_BICNT_LOBIT 0x10
233#define DSPDMAC_IRQCNT_BICNT_HIBIT 0x1F
234#define DSPDMAC_IRQCNT_BICNT_MASK 0xFFFF0000
235
236#define DSPDMAC_AUD_CHSEL_CHANNEL_COUNT 12
237#define DSPDMAC_AUDCHSEL_MODULE_OFFSET 0xFC0
238#define DSPDMAC_AUDCHSEL_CHAN_INCR 0x4
239#define DSPDMAC_AUDCHSEL_INST_OFFSET(_chan) \
240 (DSPDMAC_CHIP_OFFSET + DSPDMAC_AUDCHSEL_MODULE_OFFSET + \
241 (_chan * DSPDMAC_AUDCHSEL_CHAN_INCR))
242
243#define DSPDMAC_AUDCHSEL_ACS_LOBIT 0x0
244#define DSPDMAC_AUDCHSEL_ACS_HIBIT 0x1F
245#define DSPDMAC_AUDCHSEL_ACS_MASK 0xFFFFFFFF
246
247#define DSPDMAC_CHNLSTART_MODULE_OFFSET 0xFF0
248#define DSPDMAC_CHNLSTART_INST_OFFSET \
249 (DSPDMAC_CHIP_OFFSET + DSPDMAC_CHNLSTART_MODULE_OFFSET)
250
251#define DSPDMAC_CHNLSTART_EN_LOBIT 0x0
252#define DSPDMAC_CHNLSTART_EN_HIBIT 0xB
253#define DSPDMAC_CHNLSTART_EN_MASK 0xFFF
254
255#define DSPDMAC_CHNLSTART_VAI1_LOBIT 0xC
256#define DSPDMAC_CHNLSTART_VAI1_HIBIT 0xF
257#define DSPDMAC_CHNLSTART_VAI1_MASK 0xF000
258
259#define DSPDMAC_CHNLSTART_DIS_LOBIT 0x10
260#define DSPDMAC_CHNLSTART_DIS_HIBIT 0x1B
261#define DSPDMAC_CHNLSTART_DIS_MASK 0xFFF0000
262
263#define DSPDMAC_CHNLSTART_VAI2_LOBIT 0x1C
264#define DSPDMAC_CHNLSTART_VAI2_HIBIT 0x1F
265#define DSPDMAC_CHNLSTART_VAI2_MASK 0xF0000000
266
267#define DSPDMAC_CHNLSTATUS_MODULE_OFFSET 0xFF4
268#define DSPDMAC_CHNLSTATUS_INST_OFFSET \
269 (DSPDMAC_CHIP_OFFSET + DSPDMAC_CHNLSTATUS_MODULE_OFFSET)
270
271#define DSPDMAC_CHNLSTATUS_ISC_LOBIT 0x0
272#define DSPDMAC_CHNLSTATUS_ISC_HIBIT 0xB
273#define DSPDMAC_CHNLSTATUS_ISC_MASK 0xFFF
274
275#define DSPDMAC_CHNLSTATUS_AOO_LOBIT 0xC
276#define DSPDMAC_CHNLSTATUS_AOO_HIBIT 0xC
277#define DSPDMAC_CHNLSTATUS_AOO_MASK 0x1000
278
279#define DSPDMAC_CHNLSTATUS_AOU_LOBIT 0xD
280#define DSPDMAC_CHNLSTATUS_AOU_HIBIT 0xD
281#define DSPDMAC_CHNLSTATUS_AOU_MASK 0x2000
282
283#define DSPDMAC_CHNLSTATUS_AIO_LOBIT 0xE
284#define DSPDMAC_CHNLSTATUS_AIO_HIBIT 0xE
285#define DSPDMAC_CHNLSTATUS_AIO_MASK 0x4000
286
287#define DSPDMAC_CHNLSTATUS_AIU_LOBIT 0xF
288#define DSPDMAC_CHNLSTATUS_AIU_HIBIT 0xF
289#define DSPDMAC_CHNLSTATUS_AIU_MASK 0x8000
290
291#define DSPDMAC_CHNLSTATUS_IEN_LOBIT 0x10
292#define DSPDMAC_CHNLSTATUS_IEN_HIBIT 0x1B
293#define DSPDMAC_CHNLSTATUS_IEN_MASK 0xFFF0000
294
295#define DSPDMAC_CHNLSTATUS_VAI0_LOBIT 0x1C
296#define DSPDMAC_CHNLSTATUS_VAI0_HIBIT 0x1F
297#define DSPDMAC_CHNLSTATUS_VAI0_MASK 0xF0000000
298
299#define DSPDMAC_CHNLPROP_MODULE_OFFSET 0xFF8
300#define DSPDMAC_CHNLPROP_INST_OFFSET \
301 (DSPDMAC_CHIP_OFFSET + DSPDMAC_CHNLPROP_MODULE_OFFSET)
302
303#define DSPDMAC_CHNLPROP_DCON_LOBIT 0x0
304#define DSPDMAC_CHNLPROP_DCON_HIBIT 0xB
305#define DSPDMAC_CHNLPROP_DCON_MASK 0xFFF
306
307#define DSPDMAC_CHNLPROP_FFS_LOBIT 0xC
308#define DSPDMAC_CHNLPROP_FFS_HIBIT 0xC
309#define DSPDMAC_CHNLPROP_FFS_MASK 0x1000
310
311#define DSPDMAC_CHNLPROP_NAJ_LOBIT 0xD
312#define DSPDMAC_CHNLPROP_NAJ_HIBIT 0xD
313#define DSPDMAC_CHNLPROP_NAJ_MASK 0x2000
314
315#define DSPDMAC_CHNLPROP_ENH_LOBIT 0xE
316#define DSPDMAC_CHNLPROP_ENH_HIBIT 0xE
317#define DSPDMAC_CHNLPROP_ENH_MASK 0x4000
318
319#define DSPDMAC_CHNLPROP_MSPCE_LOBIT 0x10
320#define DSPDMAC_CHNLPROP_MSPCE_HIBIT 0x1B
321#define DSPDMAC_CHNLPROP_MSPCE_MASK 0xFFF0000
322
323#define DSPDMAC_CHNLPROP_AC_LOBIT 0x1C
324#define DSPDMAC_CHNLPROP_AC_HIBIT 0x1F
325#define DSPDMAC_CHNLPROP_AC_MASK 0xF0000000
326
327#define DSPDMAC_ACTIVE_MODULE_OFFSET 0xFFC
328#define DSPDMAC_ACTIVE_INST_OFFSET \
329 (DSPDMAC_CHIP_OFFSET + DSPDMAC_ACTIVE_MODULE_OFFSET)
330
331#define DSPDMAC_ACTIVE_AAR_LOBIT 0x0
332#define DSPDMAC_ACTIVE_AAR_HIBIT 0xB
333#define DSPDMAC_ACTIVE_AAR_MASK 0xFFF
334
335#define DSPDMAC_ACTIVE_WFR_LOBIT 0xC
336#define DSPDMAC_ACTIVE_WFR_HIBIT 0x17
337#define DSPDMAC_ACTIVE_WFR_MASK 0xFFF000
338
339#define DSP_AUX_MEM_BASE 0xE000
340#define INVALID_CHIP_ADDRESS (~0U)
341
342#define X_SIZE (XRAM_XRAM_CHANNEL_COUNT * XRAM_XRAM_CHAN_INCR)
343#define Y_SIZE (YRAM_YRAM_CHANNEL_COUNT * YRAM_YRAM_CHAN_INCR)
344#define AX_SIZE (AXRAM_AXRAM_CHANNEL_COUNT * AXRAM_AXRAM_CHAN_INCR)
345#define AY_SIZE (AYRAM_AYRAM_CHANNEL_COUNT * AYRAM_AYRAM_CHAN_INCR)
346#define UC_SIZE (UC_UC_CHANNEL_COUNT * UC_UC_CHAN_INCR)
347
348#define XEXT_SIZE (X_SIZE + AX_SIZE)
349#define YEXT_SIZE (Y_SIZE + AY_SIZE)
350
351#define U64K 0x10000UL
352
353#define X_END (XRAM_CHIP_OFFSET + X_SIZE)
354#define X_EXT (XRAM_CHIP_OFFSET + XEXT_SIZE)
355#define AX_END (XRAM_CHIP_OFFSET + U64K*4)
356
357#define Y_END (YRAM_CHIP_OFFSET + Y_SIZE)
358#define Y_EXT (YRAM_CHIP_OFFSET + YEXT_SIZE)
359#define AY_END (YRAM_CHIP_OFFSET + U64K*4)
360
361#define UC_END (UC_CHIP_OFFSET + UC_SIZE)
362
363#define X_RANGE_MAIN(a, s) \
364 (((a)+((s)-1)*XRAM_XRAM_CHAN_INCR < X_END))
365#define X_RANGE_AUX(a, s) \
366 (((a) >= X_END) && ((a)+((s)-1)*XRAM_XRAM_CHAN_INCR < AX_END))
367#define X_RANGE_EXT(a, s) \
368 (((a)+((s)-1)*XRAM_XRAM_CHAN_INCR < X_EXT))
369#define X_RANGE_ALL(a, s) \
370 (((a)+((s)-1)*XRAM_XRAM_CHAN_INCR < AX_END))
371
372#define Y_RANGE_MAIN(a, s) \
373 (((a) >= YRAM_CHIP_OFFSET) && \
374 ((a)+((s)-1)*YRAM_YRAM_CHAN_INCR < Y_END))
375#define Y_RANGE_AUX(a, s) \
376 (((a) >= Y_END) && \
377 ((a)+((s)-1)*YRAM_YRAM_CHAN_INCR < AY_END))
378#define Y_RANGE_EXT(a, s) \
379 (((a) >= YRAM_CHIP_OFFSET) && \
380 ((a)+((s)-1)*YRAM_YRAM_CHAN_INCR < Y_EXT))
381#define Y_RANGE_ALL(a, s) \
382 (((a) >= YRAM_CHIP_OFFSET) && \
383 ((a)+((s)-1)*YRAM_YRAM_CHAN_INCR < AY_END))
384
385#define UC_RANGE(a, s) \
386 (((a) >= UC_CHIP_OFFSET) && \
387 ((a)+((s)-1)*UC_UC_CHAN_INCR < UC_END))
388
389#define X_OFF(a) \
390 (((a) - XRAM_CHIP_OFFSET) / XRAM_XRAM_CHAN_INCR)
391#define AX_OFF(a) \
392 (((a) % (AXRAM_AXRAM_CHANNEL_COUNT * \
393 AXRAM_AXRAM_CHAN_INCR)) / AXRAM_AXRAM_CHAN_INCR)
394
395#define Y_OFF(a) \
396 (((a) - YRAM_CHIP_OFFSET) / YRAM_YRAM_CHAN_INCR)
397#define AY_OFF(a) \
398 (((a) % (AYRAM_AYRAM_CHANNEL_COUNT * \
399 AYRAM_AYRAM_CHAN_INCR)) / AYRAM_AYRAM_CHAN_INCR)
400
401#define UC_OFF(a) (((a) - UC_CHIP_OFFSET) / UC_UC_CHAN_INCR)
402
403#define X_EXT_MAIN_SIZE(a) (XRAM_XRAM_CHANNEL_COUNT - X_OFF(a))
404#define X_EXT_AUX_SIZE(a, s) ((s) - X_EXT_MAIN_SIZE(a))
405
406#define Y_EXT_MAIN_SIZE(a) (YRAM_YRAM_CHANNEL_COUNT - Y_OFF(a))
407#define Y_EXT_AUX_SIZE(a, s) ((s) - Y_EXT_MAIN_SIZE(a))
408
409#endif
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c
index 7da883a464e3..a3ea76a4c9d2 100644
--- a/sound/pci/hda/hda_auto_parser.c
+++ b/sound/pci/hda/hda_auto_parser.c
@@ -97,6 +97,28 @@ static void reorder_outputs(unsigned int nums, hda_nid_t *pins)
97 } 97 }
98} 98}
99 99
100/* check whether the given pin has a proper pin I/O capability bit */
101static bool check_pincap_validity(struct hda_codec *codec, hda_nid_t pin,
102 unsigned int dev)
103{
104 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
105
106 /* some old hardware don't return the proper pincaps */
107 if (!pincap)
108 return true;
109
110 switch (dev) {
111 case AC_JACK_LINE_OUT:
112 case AC_JACK_SPEAKER:
113 case AC_JACK_HP_OUT:
114 case AC_JACK_SPDIF_OUT:
115 case AC_JACK_DIG_OTHER_OUT:
116 return !!(pincap & AC_PINCAP_OUT);
117 default:
118 return !!(pincap & AC_PINCAP_IN);
119 }
120}
121
100/* 122/*
101 * Parse all pin widgets and store the useful pin nids to cfg 123 * Parse all pin widgets and store the useful pin nids to cfg
102 * 124 *
@@ -126,6 +148,9 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
126 struct auto_out_pin hp_out[ARRAY_SIZE(cfg->hp_pins)]; 148 struct auto_out_pin hp_out[ARRAY_SIZE(cfg->hp_pins)];
127 int i; 149 int i;
128 150
151 if (!snd_hda_get_int_hint(codec, "parser_flags", &i))
152 cond_flags = i;
153
129 memset(cfg, 0, sizeof(*cfg)); 154 memset(cfg, 0, sizeof(*cfg));
130 155
131 memset(line_out, 0, sizeof(line_out)); 156 memset(line_out, 0, sizeof(line_out));
@@ -156,10 +181,14 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
156 181
157 /* workaround for buggy BIOS setups */ 182 /* workaround for buggy BIOS setups */
158 if (dev == AC_JACK_LINE_OUT) { 183 if (dev == AC_JACK_LINE_OUT) {
159 if (conn == AC_JACK_PORT_FIXED) 184 if (conn == AC_JACK_PORT_FIXED ||
185 conn == AC_JACK_PORT_BOTH)
160 dev = AC_JACK_SPEAKER; 186 dev = AC_JACK_SPEAKER;
161 } 187 }
162 188
189 if (!check_pincap_validity(codec, nid, dev))
190 continue;
191
163 switch (dev) { 192 switch (dev) {
164 case AC_JACK_LINE_OUT: 193 case AC_JACK_LINE_OUT:
165 seq = get_defcfg_sequence(def_conf); 194 seq = get_defcfg_sequence(def_conf);
@@ -363,7 +392,7 @@ static const char *hda_get_input_pin_label(struct hda_codec *codec,
363{ 392{
364 unsigned int def_conf; 393 unsigned int def_conf;
365 static const char * const mic_names[] = { 394 static const char * const mic_names[] = {
366 "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic", 395 "Internal Mic", "Dock Mic", "Mic", "Rear Mic", "Front Mic"
367 }; 396 };
368 int attr; 397 int attr;
369 398
@@ -394,6 +423,8 @@ static const char *hda_get_input_pin_label(struct hda_codec *codec,
394 return "SPDIF In"; 423 return "SPDIF In";
395 case AC_JACK_DIG_OTHER_IN: 424 case AC_JACK_DIG_OTHER_IN:
396 return "Digital In"; 425 return "Digital In";
426 case AC_JACK_HP_OUT:
427 return "Headphone Mic";
397 default: 428 default:
398 return "Misc"; 429 return "Misc";
399 } 430 }
@@ -552,6 +583,9 @@ static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
552 return 1; 583 return 1;
553} 584}
554 585
586#define is_hdmi_cfg(conf) \
587 (get_defcfg_location(conf) == AC_JACK_LOC_HDMI)
588
555/** 589/**
556 * snd_hda_get_pin_label - Get a label for the given I/O pin 590 * snd_hda_get_pin_label - Get a label for the given I/O pin
557 * 591 *
@@ -572,6 +606,7 @@ int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
572 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); 606 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
573 const char *name = NULL; 607 const char *name = NULL;
574 int i; 608 int i;
609 bool hdmi;
575 610
576 if (indexp) 611 if (indexp)
577 *indexp = 0; 612 *indexp = 0;
@@ -590,16 +625,18 @@ int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
590 label, maxlen, indexp); 625 label, maxlen, indexp);
591 case AC_JACK_SPDIF_OUT: 626 case AC_JACK_SPDIF_OUT:
592 case AC_JACK_DIG_OTHER_OUT: 627 case AC_JACK_DIG_OTHER_OUT:
593 if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI) 628 hdmi = is_hdmi_cfg(def_conf);
594 name = "HDMI"; 629 name = hdmi ? "HDMI" : "SPDIF";
595 else 630 if (cfg && indexp)
596 name = "SPDIF"; 631 for (i = 0; i < cfg->dig_outs; i++) {
597 if (cfg && indexp) { 632 hda_nid_t pin = cfg->dig_out_pins[i];
598 i = find_idx_in_nid_list(nid, cfg->dig_out_pins, 633 unsigned int c;
599 cfg->dig_outs); 634 if (pin == nid)
600 if (i >= 0) 635 break;
601 *indexp = i; 636 c = snd_hda_codec_get_pincfg(codec, pin);
602 } 637 if (hdmi == is_hdmi_cfg(c))
638 (*indexp)++;
639 }
603 break; 640 break;
604 default: 641 default:
605 if (cfg) { 642 if (cfg) {
@@ -622,28 +659,27 @@ int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
622} 659}
623EXPORT_SYMBOL_HDA(snd_hda_get_pin_label); 660EXPORT_SYMBOL_HDA(snd_hda_get_pin_label);
624 661
625int snd_hda_gen_add_verbs(struct hda_gen_spec *spec, 662int snd_hda_add_verbs(struct hda_codec *codec,
626 const struct hda_verb *list) 663 const struct hda_verb *list)
627{ 664{
628 const struct hda_verb **v; 665 const struct hda_verb **v;
629 v = snd_array_new(&spec->verbs); 666 v = snd_array_new(&codec->verbs);
630 if (!v) 667 if (!v)
631 return -ENOMEM; 668 return -ENOMEM;
632 *v = list; 669 *v = list;
633 return 0; 670 return 0;
634} 671}
635EXPORT_SYMBOL_HDA(snd_hda_gen_add_verbs); 672EXPORT_SYMBOL_HDA(snd_hda_add_verbs);
636 673
637void snd_hda_gen_apply_verbs(struct hda_codec *codec) 674void snd_hda_apply_verbs(struct hda_codec *codec)
638{ 675{
639 struct hda_gen_spec *spec = codec->spec;
640 int i; 676 int i;
641 for (i = 0; i < spec->verbs.used; i++) { 677 for (i = 0; i < codec->verbs.used; i++) {
642 struct hda_verb **v = snd_array_elem(&spec->verbs, i); 678 struct hda_verb **v = snd_array_elem(&codec->verbs, i);
643 snd_hda_sequence_write(codec, *v); 679 snd_hda_sequence_write(codec, *v);
644 } 680 }
645} 681}
646EXPORT_SYMBOL_HDA(snd_hda_gen_apply_verbs); 682EXPORT_SYMBOL_HDA(snd_hda_apply_verbs);
647 683
648void snd_hda_apply_pincfgs(struct hda_codec *codec, 684void snd_hda_apply_pincfgs(struct hda_codec *codec,
649 const struct hda_pintbl *cfg) 685 const struct hda_pintbl *cfg)
@@ -653,20 +689,22 @@ void snd_hda_apply_pincfgs(struct hda_codec *codec,
653} 689}
654EXPORT_SYMBOL_HDA(snd_hda_apply_pincfgs); 690EXPORT_SYMBOL_HDA(snd_hda_apply_pincfgs);
655 691
656void snd_hda_apply_fixup(struct hda_codec *codec, int action) 692static void set_pin_targets(struct hda_codec *codec,
693 const struct hda_pintbl *cfg)
657{ 694{
658 struct hda_gen_spec *spec = codec->spec; 695 for (; cfg->nid; cfg++)
659 int id = spec->fixup_id; 696 snd_hda_set_pin_ctl_cache(codec, cfg->nid, cfg->val);
660#ifdef CONFIG_SND_DEBUG_VERBOSE 697}
661 const char *modelname = spec->fixup_name;
662#endif
663 int depth = 0;
664 698
665 if (!spec->fixup_list) 699static void apply_fixup(struct hda_codec *codec, int id, int action, int depth)
666 return; 700{
701 const char *modelname = codec->fixup_name;
667 702
668 while (id >= 0) { 703 while (id >= 0) {
669 const struct hda_fixup *fix = spec->fixup_list + id; 704 const struct hda_fixup *fix = codec->fixup_list + id;
705
706 if (fix->chained_before)
707 apply_fixup(codec, fix->chain_id, action, depth + 1);
670 708
671 switch (fix->type) { 709 switch (fix->type) {
672 case HDA_FIXUP_PINS: 710 case HDA_FIXUP_PINS:
@@ -683,7 +721,7 @@ void snd_hda_apply_fixup(struct hda_codec *codec, int action)
683 snd_printdd(KERN_INFO SFX 721 snd_printdd(KERN_INFO SFX
684 "%s: Apply fix-verbs for %s\n", 722 "%s: Apply fix-verbs for %s\n",
685 codec->chip_name, modelname); 723 codec->chip_name, modelname);
686 snd_hda_gen_add_verbs(codec->spec, fix->v.verbs); 724 snd_hda_add_verbs(codec, fix->v.verbs);
687 break; 725 break;
688 case HDA_FIXUP_FUNC: 726 case HDA_FIXUP_FUNC:
689 if (!fix->v.func) 727 if (!fix->v.func)
@@ -693,19 +731,33 @@ void snd_hda_apply_fixup(struct hda_codec *codec, int action)
693 codec->chip_name, modelname); 731 codec->chip_name, modelname);
694 fix->v.func(codec, fix, action); 732 fix->v.func(codec, fix, action);
695 break; 733 break;
734 case HDA_FIXUP_PINCTLS:
735 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins)
736 break;
737 snd_printdd(KERN_INFO SFX
738 "%s: Apply pinctl for %s\n",
739 codec->chip_name, modelname);
740 set_pin_targets(codec, fix->v.pins);
741 break;
696 default: 742 default:
697 snd_printk(KERN_ERR SFX 743 snd_printk(KERN_ERR SFX
698 "%s: Invalid fixup type %d\n", 744 "%s: Invalid fixup type %d\n",
699 codec->chip_name, fix->type); 745 codec->chip_name, fix->type);
700 break; 746 break;
701 } 747 }
702 if (!fix->chained) 748 if (!fix->chained || fix->chained_before)
703 break; 749 break;
704 if (++depth > 10) 750 if (++depth > 10)
705 break; 751 break;
706 id = fix->chain_id; 752 id = fix->chain_id;
707 } 753 }
708} 754}
755
756void snd_hda_apply_fixup(struct hda_codec *codec, int action)
757{
758 if (codec->fixup_list)
759 apply_fixup(codec, codec->fixup_id, action, 0);
760}
709EXPORT_SYMBOL_HDA(snd_hda_apply_fixup); 761EXPORT_SYMBOL_HDA(snd_hda_apply_fixup);
710 762
711void snd_hda_pick_fixup(struct hda_codec *codec, 763void snd_hda_pick_fixup(struct hda_codec *codec,
@@ -713,15 +765,14 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
713 const struct snd_pci_quirk *quirk, 765 const struct snd_pci_quirk *quirk,
714 const struct hda_fixup *fixlist) 766 const struct hda_fixup *fixlist)
715{ 767{
716 struct hda_gen_spec *spec = codec->spec;
717 const struct snd_pci_quirk *q; 768 const struct snd_pci_quirk *q;
718 int id = -1; 769 int id = -1;
719 const char *name = NULL; 770 const char *name = NULL;
720 771
721 /* when model=nofixup is given, don't pick up any fixups */ 772 /* when model=nofixup is given, don't pick up any fixups */
722 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) { 773 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
723 spec->fixup_list = NULL; 774 codec->fixup_list = NULL;
724 spec->fixup_id = -1; 775 codec->fixup_id = -1;
725 return; 776 return;
726 } 777 }
727 778
@@ -759,10 +810,10 @@ void snd_hda_pick_fixup(struct hda_codec *codec,
759 } 810 }
760 } 811 }
761 812
762 spec->fixup_id = id; 813 codec->fixup_id = id;
763 if (id >= 0) { 814 if (id >= 0) {
764 spec->fixup_list = fixlist; 815 codec->fixup_list = fixlist;
765 spec->fixup_name = name; 816 codec->fixup_name = name;
766 } 817 }
767} 818}
768EXPORT_SYMBOL_HDA(snd_hda_pick_fixup); 819EXPORT_SYMBOL_HDA(snd_hda_pick_fixup);
diff --git a/sound/pci/hda/hda_auto_parser.h b/sound/pci/hda/hda_auto_parser.h
index 632ad0ad3007..f74807138b49 100644
--- a/sound/pci/hda/hda_auto_parser.h
+++ b/sound/pci/hda/hda_auto_parser.h
@@ -51,8 +51,9 @@ enum {
51 INPUT_PIN_ATTR_INT, /* internal mic/line-in */ 51 INPUT_PIN_ATTR_INT, /* internal mic/line-in */
52 INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */ 52 INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */
53 INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */ 53 INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */
54 INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */
55 INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */ 54 INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */
55 INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */
56 INPUT_PIN_ATTR_LAST = INPUT_PIN_ATTR_FRONT,
56}; 57};
57 58
58int snd_hda_get_input_pin_attr(unsigned int def_conf); 59int snd_hda_get_input_pin_attr(unsigned int def_conf);
@@ -89,82 +90,4 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
89#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \ 90#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
90 snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0) 91 snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
91 92
92/*
93 */
94
95struct hda_gen_spec {
96 /* fix-up list */
97 int fixup_id;
98 const struct hda_fixup *fixup_list;
99 const char *fixup_name;
100
101 /* additional init verbs */
102 struct snd_array verbs;
103};
104
105
106/*
107 * Fix-up pin default configurations and add default verbs
108 */
109
110struct hda_pintbl {
111 hda_nid_t nid;
112 u32 val;
113};
114
115struct hda_model_fixup {
116 const int id;
117 const char *name;
118};
119
120struct hda_fixup {
121 int type;
122 bool chained;
123 int chain_id;
124 union {
125 const struct hda_pintbl *pins;
126 const struct hda_verb *verbs;
127 void (*func)(struct hda_codec *codec,
128 const struct hda_fixup *fix,
129 int action);
130 } v;
131};
132
133/* fixup types */
134enum {
135 HDA_FIXUP_INVALID,
136 HDA_FIXUP_PINS,
137 HDA_FIXUP_VERBS,
138 HDA_FIXUP_FUNC,
139};
140
141/* fixup action definitions */
142enum {
143 HDA_FIXUP_ACT_PRE_PROBE,
144 HDA_FIXUP_ACT_PROBE,
145 HDA_FIXUP_ACT_INIT,
146 HDA_FIXUP_ACT_BUILD,
147};
148
149int snd_hda_gen_add_verbs(struct hda_gen_spec *spec,
150 const struct hda_verb *list);
151void snd_hda_gen_apply_verbs(struct hda_codec *codec);
152void snd_hda_apply_pincfgs(struct hda_codec *codec,
153 const struct hda_pintbl *cfg);
154void snd_hda_apply_fixup(struct hda_codec *codec, int action);
155void snd_hda_pick_fixup(struct hda_codec *codec,
156 const struct hda_model_fixup *models,
157 const struct snd_pci_quirk *quirk,
158 const struct hda_fixup *fixlist);
159
160static inline void snd_hda_gen_init(struct hda_gen_spec *spec)
161{
162 snd_array_init(&spec->verbs, sizeof(struct hda_verb *), 8);
163}
164
165static inline void snd_hda_gen_free(struct hda_gen_spec *spec)
166{
167 snd_array_free(&spec->verbs);
168}
169
170#endif /* __SOUND_HDA_AUTO_PARSER_H */ 93#endif /* __SOUND_HDA_AUTO_PARSER_H */
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 822df971972c..04b57383e8cb 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -222,8 +222,14 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
222 again: 222 again:
223 snd_hda_power_up(codec); 223 snd_hda_power_up(codec);
224 mutex_lock(&bus->cmd_mutex); 224 mutex_lock(&bus->cmd_mutex);
225 trace_hda_send_cmd(codec, cmd); 225 for (;;) {
226 err = bus->ops.command(bus, cmd); 226 trace_hda_send_cmd(codec, cmd);
227 err = bus->ops.command(bus, cmd);
228 if (err != -EAGAIN)
229 break;
230 /* process pending verbs */
231 bus->ops.get_response(bus, codec->addr);
232 }
227 if (!err && res) { 233 if (!err && res) {
228 *res = bus->ops.get_response(bus, codec->addr); 234 *res = bus->ops.get_response(bus, codec->addr);
229 trace_hda_get_response(codec, *res); 235 trace_hda_get_response(codec, *res);
@@ -328,33 +334,117 @@ int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
328} 334}
329EXPORT_SYMBOL_HDA(snd_hda_get_sub_nodes); 335EXPORT_SYMBOL_HDA(snd_hda_get_sub_nodes);
330 336
337/* connection list element */
338struct hda_conn_list {
339 struct list_head list;
340 int len;
341 hda_nid_t nid;
342 hda_nid_t conns[0];
343};
344
331/* look up the cached results */ 345/* look up the cached results */
332static hda_nid_t *lookup_conn_list(struct snd_array *array, hda_nid_t nid) 346static struct hda_conn_list *
347lookup_conn_list(struct hda_codec *codec, hda_nid_t nid)
333{ 348{
334 int i, len; 349 struct hda_conn_list *p;
335 for (i = 0; i < array->used; ) { 350 list_for_each_entry(p, &codec->conn_list, list) {
336 hda_nid_t *p = snd_array_elem(array, i); 351 if (p->nid == nid)
337 if (nid == *p)
338 return p; 352 return p;
339 len = p[1];
340 i += len + 2;
341 } 353 }
342 return NULL; 354 return NULL;
343} 355}
344 356
357static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
358 const hda_nid_t *list)
359{
360 struct hda_conn_list *p;
361
362 p = kmalloc(sizeof(*p) + len * sizeof(hda_nid_t), GFP_KERNEL);
363 if (!p)
364 return -ENOMEM;
365 p->len = len;
366 p->nid = nid;
367 memcpy(p->conns, list, len * sizeof(hda_nid_t));
368 list_add(&p->list, &codec->conn_list);
369 return 0;
370}
371
372static void remove_conn_list(struct hda_codec *codec)
373{
374 while (!list_empty(&codec->conn_list)) {
375 struct hda_conn_list *p;
376 p = list_first_entry(&codec->conn_list, typeof(*p), list);
377 list_del(&p->list);
378 kfree(p);
379 }
380}
381
345/* read the connection and add to the cache */ 382/* read the connection and add to the cache */
346static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid) 383static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
347{ 384{
348 hda_nid_t list[HDA_MAX_CONNECTIONS]; 385 hda_nid_t list[32];
386 hda_nid_t *result = list;
349 int len; 387 int len;
350 388
351 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list)); 389 len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list));
352 if (len < 0) 390 if (len == -ENOSPC) {
353 return len; 391 len = snd_hda_get_num_raw_conns(codec, nid);
354 return snd_hda_override_conn_list(codec, nid, len, list); 392 result = kmalloc(sizeof(hda_nid_t) * len, GFP_KERNEL);
393 if (!result)
394 return -ENOMEM;
395 len = snd_hda_get_raw_connections(codec, nid, result, len);
396 }
397 if (len >= 0)
398 len = snd_hda_override_conn_list(codec, nid, len, result);
399 if (result != list)
400 kfree(result);
401 return len;
355} 402}
356 403
357/** 404/**
405 * snd_hda_get_conn_list - get connection list
406 * @codec: the HDA codec
407 * @nid: NID to parse
408 * @len: number of connection list entries
409 * @listp: the pointer to store NID list
410 *
411 * Parses the connection list of the given widget and stores the pointer
412 * to the list of NIDs.
413 *
414 * Returns the number of connections, or a negative error code.
415 *
416 * Note that the returned pointer isn't protected against the list
417 * modification. If snd_hda_override_conn_list() might be called
418 * concurrently, protect with a mutex appropriately.
419 */
420int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
421 const hda_nid_t **listp)
422{
423 bool added = false;
424
425 for (;;) {
426 int err;
427 const struct hda_conn_list *p;
428
429 /* if the connection-list is already cached, read it */
430 p = lookup_conn_list(codec, nid);
431 if (p) {
432 if (listp)
433 *listp = p->conns;
434 return p->len;
435 }
436 if (snd_BUG_ON(added))
437 return -EINVAL;
438
439 err = read_and_add_raw_conns(codec, nid);
440 if (err < 0)
441 return err;
442 added = true;
443 }
444}
445EXPORT_SYMBOL_HDA(snd_hda_get_conn_list);
446
447/**
358 * snd_hda_get_connections - copy connection list 448 * snd_hda_get_connections - copy connection list
359 * @codec: the HDA codec 449 * @codec: the HDA codec
360 * @nid: NID to parse 450 * @nid: NID to parse
@@ -369,42 +459,44 @@ static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
369int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid, 459int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
370 hda_nid_t *conn_list, int max_conns) 460 hda_nid_t *conn_list, int max_conns)
371{ 461{
372 struct snd_array *array = &codec->conn_lists; 462 const hda_nid_t *list;
373 int len; 463 int len = snd_hda_get_conn_list(codec, nid, &list);
374 hda_nid_t *p;
375 bool added = false;
376 464
377 again: 465 if (len > 0 && conn_list) {
378 mutex_lock(&codec->hash_mutex); 466 if (len > max_conns) {
379 len = -1;
380 /* if the connection-list is already cached, read it */
381 p = lookup_conn_list(array, nid);
382 if (p) {
383 len = p[1];
384 if (conn_list && len > max_conns) {
385 snd_printk(KERN_ERR "hda_codec: " 467 snd_printk(KERN_ERR "hda_codec: "
386 "Too many connections %d for NID 0x%x\n", 468 "Too many connections %d for NID 0x%x\n",
387 len, nid); 469 len, nid);
388 mutex_unlock(&codec->hash_mutex);
389 return -EINVAL; 470 return -EINVAL;
390 } 471 }
391 if (conn_list && len) 472 memcpy(conn_list, list, len * sizeof(hda_nid_t));
392 memcpy(conn_list, p + 2, len * sizeof(hda_nid_t));
393 } 473 }
394 mutex_unlock(&codec->hash_mutex);
395 if (len >= 0)
396 return len;
397 if (snd_BUG_ON(added))
398 return -EINVAL;
399 474
400 len = read_and_add_raw_conns(codec, nid); 475 return len;
401 if (len < 0)
402 return len;
403 added = true;
404 goto again;
405} 476}
406EXPORT_SYMBOL_HDA(snd_hda_get_connections); 477EXPORT_SYMBOL_HDA(snd_hda_get_connections);
407 478
479/* return CONNLIST_LEN parameter of the given widget */
480static unsigned int get_num_conns(struct hda_codec *codec, hda_nid_t nid)
481{
482 unsigned int wcaps = get_wcaps(codec, nid);
483 unsigned int parm;
484
485 if (!(wcaps & AC_WCAP_CONN_LIST) &&
486 get_wcaps_type(wcaps) != AC_WID_VOL_KNB)
487 return 0;
488
489 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
490 if (parm == -1)
491 parm = 0;
492 return parm;
493}
494
495int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid)
496{
497 return get_num_conns(codec, nid) & AC_CLIST_LENGTH;
498}
499
408/** 500/**
409 * snd_hda_get_raw_connections - copy connection list without cache 501 * snd_hda_get_raw_connections - copy connection list without cache
410 * @codec: the HDA codec 502 * @codec: the HDA codec
@@ -422,18 +514,16 @@ int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
422 unsigned int parm; 514 unsigned int parm;
423 int i, conn_len, conns; 515 int i, conn_len, conns;
424 unsigned int shift, num_elems, mask; 516 unsigned int shift, num_elems, mask;
425 unsigned int wcaps;
426 hda_nid_t prev_nid; 517 hda_nid_t prev_nid;
518 int null_count = 0;
427 519
428 if (snd_BUG_ON(!conn_list || max_conns <= 0)) 520 if (snd_BUG_ON(!conn_list || max_conns <= 0))
429 return -EINVAL; 521 return -EINVAL;
430 522
431 wcaps = get_wcaps(codec, nid); 523 parm = get_num_conns(codec, nid);
432 if (!(wcaps & AC_WCAP_CONN_LIST) && 524 if (!parm)
433 get_wcaps_type(wcaps) != AC_WID_VOL_KNB)
434 return 0; 525 return 0;
435 526
436 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
437 if (parm & AC_CLIST_LONG) { 527 if (parm & AC_CLIST_LONG) {
438 /* long form */ 528 /* long form */
439 shift = 16; 529 shift = 16;
@@ -474,7 +564,7 @@ int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
474 } 564 }
475 range_val = !!(parm & (1 << (shift-1))); /* ranges */ 565 range_val = !!(parm & (1 << (shift-1))); /* ranges */
476 val = parm & mask; 566 val = parm & mask;
477 if (val == 0) { 567 if (val == 0 && null_count++) { /* no second chance */
478 snd_printk(KERN_WARNING "hda_codec: " 568 snd_printk(KERN_WARNING "hda_codec: "
479 "invalid CONNECT_LIST verb %x[%i]:%x\n", 569 "invalid CONNECT_LIST verb %x[%i]:%x\n",
480 nid, i, parm); 570 nid, i, parm);
@@ -490,21 +580,13 @@ int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
490 continue; 580 continue;
491 } 581 }
492 for (n = prev_nid + 1; n <= val; n++) { 582 for (n = prev_nid + 1; n <= val; n++) {
493 if (conns >= max_conns) { 583 if (conns >= max_conns)
494 snd_printk(KERN_ERR "hda_codec: " 584 return -ENOSPC;
495 "Too many connections %d for NID 0x%x\n",
496 conns, nid);
497 return -EINVAL;
498 }
499 conn_list[conns++] = n; 585 conn_list[conns++] = n;
500 } 586 }
501 } else { 587 } else {
502 if (conns >= max_conns) { 588 if (conns >= max_conns)
503 snd_printk(KERN_ERR "hda_codec: " 589 return -ENOSPC;
504 "Too many connections %d for NID 0x%x\n",
505 conns, nid);
506 return -EINVAL;
507 }
508 conn_list[conns++] = val; 590 conn_list[conns++] = val;
509 } 591 }
510 prev_nid = val; 592 prev_nid = val;
@@ -512,15 +594,6 @@ int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
512 return conns; 594 return conns;
513} 595}
514 596
515static bool add_conn_list(struct snd_array *array, hda_nid_t nid)
516{
517 hda_nid_t *p = snd_array_new(array);
518 if (!p)
519 return false;
520 *p = nid;
521 return true;
522}
523
524/** 597/**
525 * snd_hda_override_conn_list - add/modify the connection-list to cache 598 * snd_hda_override_conn_list - add/modify the connection-list to cache
526 * @codec: the HDA codec 599 * @codec: the HDA codec
@@ -536,28 +609,15 @@ static bool add_conn_list(struct snd_array *array, hda_nid_t nid)
536int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, 609int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
537 const hda_nid_t *list) 610 const hda_nid_t *list)
538{ 611{
539 struct snd_array *array = &codec->conn_lists; 612 struct hda_conn_list *p;
540 hda_nid_t *p;
541 int i, old_used;
542 613
543 mutex_lock(&codec->hash_mutex); 614 p = lookup_conn_list(codec, nid);
544 p = lookup_conn_list(array, nid); 615 if (p) {
545 if (p) 616 list_del(&p->list);
546 *p = -1; /* invalidate the old entry */ 617 kfree(p);
547 618 }
548 old_used = array->used;
549 if (!add_conn_list(array, nid) || !add_conn_list(array, len))
550 goto error_add;
551 for (i = 0; i < len; i++)
552 if (!add_conn_list(array, list[i]))
553 goto error_add;
554 mutex_unlock(&codec->hash_mutex);
555 return 0;
556 619
557 error_add: 620 return add_conn_list(codec, nid, len, list);
558 array->used = old_used;
559 mutex_unlock(&codec->hash_mutex);
560 return -ENOMEM;
561} 621}
562EXPORT_SYMBOL_HDA(snd_hda_override_conn_list); 622EXPORT_SYMBOL_HDA(snd_hda_override_conn_list);
563 623
@@ -575,16 +635,16 @@ EXPORT_SYMBOL_HDA(snd_hda_override_conn_list);
575int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, 635int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
576 hda_nid_t nid, int recursive) 636 hda_nid_t nid, int recursive)
577{ 637{
578 hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 638 const hda_nid_t *conn;
579 int i, nums; 639 int i, nums;
580 640
581 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 641 nums = snd_hda_get_conn_list(codec, mux, &conn);
582 for (i = 0; i < nums; i++) 642 for (i = 0; i < nums; i++)
583 if (conn[i] == nid) 643 if (conn[i] == nid)
584 return i; 644 return i;
585 if (!recursive) 645 if (!recursive)
586 return -1; 646 return -1;
587 if (recursive > 5) { 647 if (recursive > 10) {
588 snd_printd("hda_codec: too deep connection for 0x%x\n", nid); 648 snd_printd("hda_codec: too deep connection for 0x%x\n", nid);
589 return -1; 649 return -1;
590 } 650 }
@@ -1046,9 +1106,16 @@ unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
1046 struct hda_pincfg *pin; 1106 struct hda_pincfg *pin;
1047 1107
1048#ifdef CONFIG_SND_HDA_HWDEP 1108#ifdef CONFIG_SND_HDA_HWDEP
1049 pin = look_up_pincfg(codec, &codec->user_pins, nid); 1109 {
1050 if (pin) 1110 unsigned int cfg = 0;
1051 return pin->cfg; 1111 mutex_lock(&codec->user_mutex);
1112 pin = look_up_pincfg(codec, &codec->user_pins, nid);
1113 if (pin)
1114 cfg = pin->cfg;
1115 mutex_unlock(&codec->user_mutex);
1116 if (cfg)
1117 return cfg;
1118 }
1052#endif 1119#endif
1053 pin = look_up_pincfg(codec, &codec->driver_pins, nid); 1120 pin = look_up_pincfg(codec, &codec->driver_pins, nid);
1054 if (pin) 1121 if (pin)
@@ -1060,6 +1127,32 @@ unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
1060} 1127}
1061EXPORT_SYMBOL_HDA(snd_hda_codec_get_pincfg); 1128EXPORT_SYMBOL_HDA(snd_hda_codec_get_pincfg);
1062 1129
1130/* remember the current pinctl target value */
1131int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
1132 unsigned int val)
1133{
1134 struct hda_pincfg *pin;
1135
1136 pin = look_up_pincfg(codec, &codec->init_pins, nid);
1137 if (!pin)
1138 return -EINVAL;
1139 pin->target = val;
1140 return 0;
1141}
1142EXPORT_SYMBOL_HDA(snd_hda_codec_set_pin_target);
1143
1144/* return the current pinctl target value */
1145int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid)
1146{
1147 struct hda_pincfg *pin;
1148
1149 pin = look_up_pincfg(codec, &codec->init_pins, nid);
1150 if (!pin)
1151 return 0;
1152 return pin->target;
1153}
1154EXPORT_SYMBOL_HDA(snd_hda_codec_get_pin_target);
1155
1063/** 1156/**
1064 * snd_hda_shutup_pins - Shut up all pins 1157 * snd_hda_shutup_pins - Shut up all pins
1065 * @codec: the HDA codec 1158 * @codec: the HDA codec
@@ -1179,8 +1272,8 @@ static void snd_hda_codec_free(struct hda_codec *codec)
1179 snd_array_free(&codec->mixers); 1272 snd_array_free(&codec->mixers);
1180 snd_array_free(&codec->nids); 1273 snd_array_free(&codec->nids);
1181 snd_array_free(&codec->cvt_setups); 1274 snd_array_free(&codec->cvt_setups);
1182 snd_array_free(&codec->conn_lists);
1183 snd_array_free(&codec->spdif_out); 1275 snd_array_free(&codec->spdif_out);
1276 remove_conn_list(codec);
1184 codec->bus->caddr_tbl[codec->addr] = NULL; 1277 codec->bus->caddr_tbl[codec->addr] = NULL;
1185 if (codec->patch_ops.free) 1278 if (codec->patch_ops.free)
1186 codec->patch_ops.free(codec); 1279 codec->patch_ops.free(codec);
@@ -1203,6 +1296,8 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
1203 1296
1204static unsigned int hda_set_power_state(struct hda_codec *codec, 1297static unsigned int hda_set_power_state(struct hda_codec *codec,
1205 unsigned int power_state); 1298 unsigned int power_state);
1299static unsigned int default_power_filter(struct hda_codec *codec, hda_nid_t nid,
1300 unsigned int power_state);
1206 1301
1207/** 1302/**
1208 * snd_hda_codec_new - create a HDA codec 1303 * snd_hda_codec_new - create a HDA codec
@@ -1250,9 +1345,11 @@ int snd_hda_codec_new(struct hda_bus *bus,
1250 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); 1345 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
1251 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); 1346 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
1252 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); 1347 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
1253 snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64);
1254 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); 1348 snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16);
1255 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); 1349 snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16);
1350 snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8);
1351 INIT_LIST_HEAD(&codec->conn_list);
1352
1256 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); 1353 INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work);
1257 1354
1258#ifdef CONFIG_PM 1355#ifdef CONFIG_PM
@@ -1321,6 +1418,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
1321#endif 1418#endif
1322 codec->epss = snd_hda_codec_get_supported_ps(codec, fg, 1419 codec->epss = snd_hda_codec_get_supported_ps(codec, fg,
1323 AC_PWRST_EPSS); 1420 AC_PWRST_EPSS);
1421 codec->power_filter = default_power_filter;
1324 1422
1325 /* power-up all before initialization */ 1423 /* power-up all before initialization */
1326 hda_set_power_state(codec, AC_PWRST_D0); 1424 hda_set_power_state(codec, AC_PWRST_D0);
@@ -1343,6 +1441,30 @@ int snd_hda_codec_new(struct hda_bus *bus,
1343} 1441}
1344EXPORT_SYMBOL_HDA(snd_hda_codec_new); 1442EXPORT_SYMBOL_HDA(snd_hda_codec_new);
1345 1443
1444int snd_hda_codec_update_widgets(struct hda_codec *codec)
1445{
1446 hda_nid_t fg;
1447 int err;
1448
1449 /* Assume the function group node does not change,
1450 * only the widget nodes may change.
1451 */
1452 kfree(codec->wcaps);
1453 fg = codec->afg ? codec->afg : codec->mfg;
1454 err = read_widget_caps(codec, fg);
1455 if (err < 0) {
1456 snd_printk(KERN_ERR "hda_codec: cannot malloc\n");
1457 return err;
1458 }
1459
1460 snd_array_free(&codec->init_pins);
1461 err = read_pin_defaults(codec);
1462
1463 return err;
1464}
1465EXPORT_SYMBOL_HDA(snd_hda_codec_update_widgets);
1466
1467
1346/** 1468/**
1347 * snd_hda_codec_configure - (Re-)configure the HD-audio codec 1469 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1348 * @codec: the HDA codec 1470 * @codec: the HDA codec
@@ -1451,7 +1573,7 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1451 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n", 1573 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
1452 nid, stream_tag, channel_id, format); 1574 nid, stream_tag, channel_id, format);
1453 p = get_hda_cvt_setup(codec, nid); 1575 p = get_hda_cvt_setup(codec, nid);
1454 if (!p) 1576 if (!p || p->active)
1455 return; 1577 return;
1456 1578
1457 if (codec->pcm_format_first) 1579 if (codec->pcm_format_first)
@@ -1498,7 +1620,7 @@ void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
1498 1620
1499 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid); 1621 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
1500 p = get_hda_cvt_setup(codec, nid); 1622 p = get_hda_cvt_setup(codec, nid);
1501 if (p) { 1623 if (p && p->active) {
1502 /* here we just clear the active flag when do_now isn't set; 1624 /* here we just clear the active flag when do_now isn't set;
1503 * actual clean-ups will be done later in 1625 * actual clean-ups will be done later in
1504 * purify_inactive_streams() called from snd_hda_codec_prpapre() 1626 * purify_inactive_streams() called from snd_hda_codec_prpapre()
@@ -1610,6 +1732,7 @@ static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
1610 cur = snd_array_index(&cache->buf, info); 1732 cur = snd_array_index(&cache->buf, info);
1611 info->key = key; 1733 info->key = key;
1612 info->val = 0; 1734 info->val = 0;
1735 info->dirty = 0;
1613 idx = key % (u16)ARRAY_SIZE(cache->hash); 1736 idx = key % (u16)ARRAY_SIZE(cache->hash);
1614 info->next = cache->hash[idx]; 1737 info->next = cache->hash[idx];
1615 cache->hash[idx] = cur; 1738 cache->hash[idx] = cur;
@@ -1764,7 +1887,7 @@ EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps);
1764 */ 1887 */
1765static struct hda_amp_info * 1888static struct hda_amp_info *
1766update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch, 1889update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch,
1767 int direction, int index) 1890 int direction, int index, bool init_only)
1768{ 1891{
1769 struct hda_amp_info *info; 1892 struct hda_amp_info *info;
1770 unsigned int parm, val = 0; 1893 unsigned int parm, val = 0;
@@ -1790,14 +1913,15 @@ update_amp_hash(struct hda_codec *codec, hda_nid_t nid, int ch,
1790 } 1913 }
1791 info->vol[ch] = val; 1914 info->vol[ch] = val;
1792 info->head.val |= INFO_AMP_VOL(ch); 1915 info->head.val |= INFO_AMP_VOL(ch);
1793 } 1916 } else if (init_only)
1917 return NULL;
1794 return info; 1918 return info;
1795} 1919}
1796 1920
1797/* 1921/*
1798 * write the current volume in info to the h/w 1922 * write the current volume in info to the h/w
1799 */ 1923 */
1800static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info, 1924static void put_vol_mute(struct hda_codec *codec, unsigned int amp_caps,
1801 hda_nid_t nid, int ch, int direction, int index, 1925 hda_nid_t nid, int ch, int direction, int index,
1802 int val) 1926 int val)
1803{ 1927{
@@ -1806,8 +1930,8 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1806 parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT; 1930 parm = ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT;
1807 parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT; 1931 parm |= direction == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT;
1808 parm |= index << AC_AMP_SET_INDEX_SHIFT; 1932 parm |= index << AC_AMP_SET_INDEX_SHIFT;
1809 if ((val & HDA_AMP_MUTE) && !(info->amp_caps & AC_AMPCAP_MUTE) && 1933 if ((val & HDA_AMP_MUTE) && !(amp_caps & AC_AMPCAP_MUTE) &&
1810 (info->amp_caps & AC_AMPCAP_MIN_MUTE)) 1934 (amp_caps & AC_AMPCAP_MIN_MUTE))
1811 ; /* set the zero value as a fake mute */ 1935 ; /* set the zero value as a fake mute */
1812 else 1936 else
1813 parm |= val; 1937 parm |= val;
@@ -1831,7 +1955,7 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1831 unsigned int val = 0; 1955 unsigned int val = 0;
1832 1956
1833 mutex_lock(&codec->hash_mutex); 1957 mutex_lock(&codec->hash_mutex);
1834 info = update_amp_hash(codec, nid, ch, direction, index); 1958 info = update_amp_hash(codec, nid, ch, direction, index, false);
1835 if (info) 1959 if (info)
1836 val = info->vol[ch]; 1960 val = info->vol[ch];
1837 mutex_unlock(&codec->hash_mutex); 1961 mutex_unlock(&codec->hash_mutex);
@@ -1839,30 +1963,20 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1839} 1963}
1840EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); 1964EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1841 1965
1842/** 1966static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1843 * snd_hda_codec_amp_update - update the AMP value 1967 int direction, int idx, int mask, int val,
1844 * @codec: HD-audio codec 1968 bool init_only)
1845 * @nid: NID to read the AMP value
1846 * @ch: channel (left=0 or right=1)
1847 * @direction: #HDA_INPUT or #HDA_OUTPUT
1848 * @idx: the index value (only for input direction)
1849 * @mask: bit mask to set
1850 * @val: the bits value to set
1851 *
1852 * Update the AMP value with a bit mask.
1853 * Returns 0 if the value is unchanged, 1 if changed.
1854 */
1855int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1856 int direction, int idx, int mask, int val)
1857{ 1969{
1858 struct hda_amp_info *info; 1970 struct hda_amp_info *info;
1971 unsigned int caps;
1972 unsigned int cache_only;
1859 1973
1860 if (snd_BUG_ON(mask & ~0xff)) 1974 if (snd_BUG_ON(mask & ~0xff))
1861 mask &= 0xff; 1975 mask &= 0xff;
1862 val &= mask; 1976 val &= mask;
1863 1977
1864 mutex_lock(&codec->hash_mutex); 1978 mutex_lock(&codec->hash_mutex);
1865 info = update_amp_hash(codec, nid, ch, direction, idx); 1979 info = update_amp_hash(codec, nid, ch, direction, idx, init_only);
1866 if (!info) { 1980 if (!info) {
1867 mutex_unlock(&codec->hash_mutex); 1981 mutex_unlock(&codec->hash_mutex);
1868 return 0; 1982 return 0;
@@ -1873,10 +1987,32 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1873 return 0; 1987 return 0;
1874 } 1988 }
1875 info->vol[ch] = val; 1989 info->vol[ch] = val;
1990 cache_only = info->head.dirty = codec->cached_write;
1991 caps = info->amp_caps;
1876 mutex_unlock(&codec->hash_mutex); 1992 mutex_unlock(&codec->hash_mutex);
1877 put_vol_mute(codec, info, nid, ch, direction, idx, val); 1993 if (!cache_only)
1994 put_vol_mute(codec, caps, nid, ch, direction, idx, val);
1878 return 1; 1995 return 1;
1879} 1996}
1997
1998/**
1999 * snd_hda_codec_amp_update - update the AMP value
2000 * @codec: HD-audio codec
2001 * @nid: NID to read the AMP value
2002 * @ch: channel (left=0 or right=1)
2003 * @direction: #HDA_INPUT or #HDA_OUTPUT
2004 * @idx: the index value (only for input direction)
2005 * @mask: bit mask to set
2006 * @val: the bits value to set
2007 *
2008 * Update the AMP value with a bit mask.
2009 * Returns 0 if the value is unchanged, 1 if changed.
2010 */
2011int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
2012 int direction, int idx, int mask, int val)
2013{
2014 return codec_amp_update(codec, nid, ch, direction, idx, mask, val, false);
2015}
1880EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update); 2016EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
1881 2017
1882/** 2018/**
@@ -1905,7 +2041,31 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1905} 2041}
1906EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo); 2042EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1907 2043
1908#ifdef CONFIG_PM 2044/* Works like snd_hda_codec_amp_update() but it writes the value only at
2045 * the first access. If the amp was already initialized / updated beforehand,
2046 * this does nothing.
2047 */
2048int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
2049 int dir, int idx, int mask, int val)
2050{
2051 return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true);
2052}
2053EXPORT_SYMBOL_HDA(snd_hda_codec_amp_init);
2054
2055int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
2056 int dir, int idx, int mask, int val)
2057{
2058 int ch, ret = 0;
2059
2060 if (snd_BUG_ON(mask & ~0xff))
2061 mask &= 0xff;
2062 for (ch = 0; ch < 2; ch++)
2063 ret |= snd_hda_codec_amp_init(codec, nid, ch, dir,
2064 idx, mask, val);
2065 return ret;
2066}
2067EXPORT_SYMBOL_HDA(snd_hda_codec_amp_init_stereo);
2068
1909/** 2069/**
1910 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache 2070 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
1911 * @codec: HD-audio codec 2071 * @codec: HD-audio codec
@@ -1914,28 +2074,40 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1914 */ 2074 */
1915void snd_hda_codec_resume_amp(struct hda_codec *codec) 2075void snd_hda_codec_resume_amp(struct hda_codec *codec)
1916{ 2076{
1917 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
1918 int i; 2077 int i;
1919 2078
1920 for (i = 0; i < codec->amp_cache.buf.used; i++, buffer++) { 2079 mutex_lock(&codec->hash_mutex);
1921 u32 key = buffer->head.key; 2080 codec->cached_write = 0;
2081 for (i = 0; i < codec->amp_cache.buf.used; i++) {
2082 struct hda_amp_info *buffer;
2083 u32 key;
1922 hda_nid_t nid; 2084 hda_nid_t nid;
1923 unsigned int idx, dir, ch; 2085 unsigned int idx, dir, ch;
2086 struct hda_amp_info info;
2087
2088 buffer = snd_array_elem(&codec->amp_cache.buf, i);
2089 if (!buffer->head.dirty)
2090 continue;
2091 buffer->head.dirty = 0;
2092 info = *buffer;
2093 key = info.head.key;
1924 if (!key) 2094 if (!key)
1925 continue; 2095 continue;
1926 nid = key & 0xff; 2096 nid = key & 0xff;
1927 idx = (key >> 16) & 0xff; 2097 idx = (key >> 16) & 0xff;
1928 dir = (key >> 24) & 0xff; 2098 dir = (key >> 24) & 0xff;
1929 for (ch = 0; ch < 2; ch++) { 2099 for (ch = 0; ch < 2; ch++) {
1930 if (!(buffer->head.val & INFO_AMP_VOL(ch))) 2100 if (!(info.head.val & INFO_AMP_VOL(ch)))
1931 continue; 2101 continue;
1932 put_vol_mute(codec, buffer, nid, ch, dir, idx, 2102 mutex_unlock(&codec->hash_mutex);
1933 buffer->vol[ch]); 2103 put_vol_mute(codec, info.amp_caps, nid, ch, dir, idx,
2104 info.vol[ch]);
2105 mutex_lock(&codec->hash_mutex);
1934 } 2106 }
1935 } 2107 }
2108 mutex_unlock(&codec->hash_mutex);
1936} 2109}
1937EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp); 2110EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
1938#endif /* CONFIG_PM */
1939 2111
1940static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir, 2112static u32 get_amp_max_value(struct hda_codec *codec, hda_nid_t nid, int dir,
1941 unsigned int ofs) 2113 unsigned int ofs)
@@ -2160,11 +2332,12 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
2160EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl); 2332EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
2161 2333
2162static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name, 2334static int find_empty_mixer_ctl_idx(struct hda_codec *codec, const char *name,
2163 int dev) 2335 int start_idx)
2164{ 2336{
2165 int idx; 2337 int i, idx;
2166 for (idx = 0; idx < 16; idx++) { /* 16 ctlrs should be large enough */ 2338 /* 16 ctlrs should be large enough */
2167 if (!find_mixer_ctl(codec, name, dev, idx)) 2339 for (i = 0, idx = start_idx; i < 16; i++, idx++) {
2340 if (!find_mixer_ctl(codec, name, 0, idx))
2168 return idx; 2341 return idx;
2169 } 2342 }
2170 return -EBUSY; 2343 return -EBUSY;
@@ -2362,6 +2535,7 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2362 snd_array_free(&codec->driver_pins); 2535 snd_array_free(&codec->driver_pins);
2363 snd_array_free(&codec->cvt_setups); 2536 snd_array_free(&codec->cvt_setups);
2364 snd_array_free(&codec->spdif_out); 2537 snd_array_free(&codec->spdif_out);
2538 snd_array_free(&codec->verbs);
2365 codec->num_pcms = 0; 2539 codec->num_pcms = 0;
2366 codec->pcm_info = NULL; 2540 codec->pcm_info = NULL;
2367 codec->preset = NULL; 2541 codec->preset = NULL;
@@ -3132,30 +3306,29 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
3132 int err; 3306 int err;
3133 struct snd_kcontrol *kctl; 3307 struct snd_kcontrol *kctl;
3134 struct snd_kcontrol_new *dig_mix; 3308 struct snd_kcontrol_new *dig_mix;
3135 int idx, dev = 0; 3309 int idx = 0;
3136 const int spdif_pcm_dev = 1; 3310 const int spdif_index = 16;
3137 struct hda_spdif_out *spdif; 3311 struct hda_spdif_out *spdif;
3312 struct hda_bus *bus = codec->bus;
3138 3313
3139 if (codec->primary_dig_out_type == HDA_PCM_TYPE_HDMI && 3314 if (bus->primary_dig_out_type == HDA_PCM_TYPE_HDMI &&
3140 type == HDA_PCM_TYPE_SPDIF) { 3315 type == HDA_PCM_TYPE_SPDIF) {
3141 dev = spdif_pcm_dev; 3316 idx = spdif_index;
3142 } else if (codec->primary_dig_out_type == HDA_PCM_TYPE_SPDIF && 3317 } else if (bus->primary_dig_out_type == HDA_PCM_TYPE_SPDIF &&
3143 type == HDA_PCM_TYPE_HDMI) { 3318 type == HDA_PCM_TYPE_HDMI) {
3144 for (idx = 0; idx < codec->spdif_out.used; idx++) { 3319 /* suppose a single SPDIF device */
3145 spdif = snd_array_elem(&codec->spdif_out, idx); 3320 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
3146 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { 3321 kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0);
3147 kctl = find_mixer_ctl(codec, dig_mix->name, 0, idx); 3322 if (!kctl)
3148 if (!kctl) 3323 break;
3149 break; 3324 kctl->id.index = spdif_index;
3150 kctl->id.device = spdif_pcm_dev;
3151 }
3152 } 3325 }
3153 codec->primary_dig_out_type = HDA_PCM_TYPE_HDMI; 3326 bus->primary_dig_out_type = HDA_PCM_TYPE_HDMI;
3154 } 3327 }
3155 if (!codec->primary_dig_out_type) 3328 if (!bus->primary_dig_out_type)
3156 codec->primary_dig_out_type = type; 3329 bus->primary_dig_out_type = type;
3157 3330
3158 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", dev); 3331 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx);
3159 if (idx < 0) { 3332 if (idx < 0) {
3160 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n"); 3333 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n");
3161 return -EBUSY; 3334 return -EBUSY;
@@ -3165,7 +3338,6 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
3165 kctl = snd_ctl_new1(dig_mix, codec); 3338 kctl = snd_ctl_new1(dig_mix, codec);
3166 if (!kctl) 3339 if (!kctl)
3167 return -ENOMEM; 3340 return -ENOMEM;
3168 kctl->id.device = dev;
3169 kctl->id.index = idx; 3341 kctl->id.index = idx;
3170 kctl->private_value = codec->spdif_out.used - 1; 3342 kctl->private_value = codec->spdif_out.used - 1;
3171 err = snd_hda_ctl_add(codec, associated_nid, kctl); 3343 err = snd_hda_ctl_add(codec, associated_nid, kctl);
@@ -3375,12 +3547,11 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
3375} 3547}
3376EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls); 3548EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls);
3377 3549
3378#ifdef CONFIG_PM
3379/* 3550/*
3380 * command cache 3551 * command cache
3381 */ 3552 */
3382 3553
3383/* build a 32bit cache key with the widget id and the command parameter */ 3554/* build a 31bit cache key with the widget id and the command parameter */
3384#define build_cmd_cache_key(nid, verb) ((verb << 8) | nid) 3555#define build_cmd_cache_key(nid, verb) ((verb << 8) | nid)
3385#define get_cmd_cache_nid(key) ((key) & 0xff) 3556#define get_cmd_cache_nid(key) ((key) & 0xff)
3386#define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff) 3557#define get_cmd_cache_cmd(key) (((key) >> 8) & 0xffff)
@@ -3400,20 +3571,28 @@ EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls);
3400int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, 3571int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
3401 int direct, unsigned int verb, unsigned int parm) 3572 int direct, unsigned int verb, unsigned int parm)
3402{ 3573{
3403 int err = snd_hda_codec_write(codec, nid, direct, verb, parm); 3574 int err;
3404 struct hda_cache_head *c; 3575 struct hda_cache_head *c;
3405 u32 key; 3576 u32 key;
3577 unsigned int cache_only;
3578
3579 cache_only = codec->cached_write;
3580 if (!cache_only) {
3581 err = snd_hda_codec_write(codec, nid, direct, verb, parm);
3582 if (err < 0)
3583 return err;
3584 }
3406 3585
3407 if (err < 0)
3408 return err;
3409 /* parm may contain the verb stuff for get/set amp */ 3586 /* parm may contain the verb stuff for get/set amp */
3410 verb = verb | (parm >> 8); 3587 verb = verb | (parm >> 8);
3411 parm &= 0xff; 3588 parm &= 0xff;
3412 key = build_cmd_cache_key(nid, verb); 3589 key = build_cmd_cache_key(nid, verb);
3413 mutex_lock(&codec->bus->cmd_mutex); 3590 mutex_lock(&codec->bus->cmd_mutex);
3414 c = get_alloc_hash(&codec->cmd_cache, key); 3591 c = get_alloc_hash(&codec->cmd_cache, key);
3415 if (c) 3592 if (c) {
3416 c->val = parm; 3593 c->val = parm;
3594 c->dirty = cache_only;
3595 }
3417 mutex_unlock(&codec->bus->cmd_mutex); 3596 mutex_unlock(&codec->bus->cmd_mutex);
3418 return 0; 3597 return 0;
3419} 3598}
@@ -3462,16 +3641,27 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_update_cache);
3462 */ 3641 */
3463void snd_hda_codec_resume_cache(struct hda_codec *codec) 3642void snd_hda_codec_resume_cache(struct hda_codec *codec)
3464{ 3643{
3465 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
3466 int i; 3644 int i;
3467 3645
3468 for (i = 0; i < codec->cmd_cache.buf.used; i++, buffer++) { 3646 mutex_lock(&codec->hash_mutex);
3469 u32 key = buffer->key; 3647 codec->cached_write = 0;
3648 for (i = 0; i < codec->cmd_cache.buf.used; i++) {
3649 struct hda_cache_head *buffer;
3650 u32 key;
3651
3652 buffer = snd_array_elem(&codec->cmd_cache.buf, i);
3653 key = buffer->key;
3470 if (!key) 3654 if (!key)
3471 continue; 3655 continue;
3656 if (!buffer->dirty)
3657 continue;
3658 buffer->dirty = 0;
3659 mutex_unlock(&codec->hash_mutex);
3472 snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0, 3660 snd_hda_codec_write(codec, get_cmd_cache_nid(key), 0,
3473 get_cmd_cache_cmd(key), buffer->val); 3661 get_cmd_cache_cmd(key), buffer->val);
3662 mutex_lock(&codec->hash_mutex);
3474 } 3663 }
3664 mutex_unlock(&codec->hash_mutex);
3475} 3665}
3476EXPORT_SYMBOL_HDA(snd_hda_codec_resume_cache); 3666EXPORT_SYMBOL_HDA(snd_hda_codec_resume_cache);
3477 3667
@@ -3492,32 +3682,36 @@ void snd_hda_sequence_write_cache(struct hda_codec *codec,
3492 seq->param); 3682 seq->param);
3493} 3683}
3494EXPORT_SYMBOL_HDA(snd_hda_sequence_write_cache); 3684EXPORT_SYMBOL_HDA(snd_hda_sequence_write_cache);
3495#endif /* CONFIG_PM */ 3685
3686/**
3687 * snd_hda_codec_flush_cache - Execute all pending (cached) amps / verbs
3688 * @codec: HD-audio codec
3689 */
3690void snd_hda_codec_flush_cache(struct hda_codec *codec)
3691{
3692 snd_hda_codec_resume_amp(codec);
3693 snd_hda_codec_resume_cache(codec);
3694}
3695EXPORT_SYMBOL_HDA(snd_hda_codec_flush_cache);
3496 3696
3497void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, 3697void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
3498 unsigned int power_state, 3698 unsigned int power_state)
3499 bool eapd_workaround)
3500{ 3699{
3501 hda_nid_t nid = codec->start_nid; 3700 hda_nid_t nid = codec->start_nid;
3502 int i; 3701 int i;
3503 3702
3504 for (i = 0; i < codec->num_nodes; i++, nid++) { 3703 for (i = 0; i < codec->num_nodes; i++, nid++) {
3505 unsigned int wcaps = get_wcaps(codec, nid); 3704 unsigned int wcaps = get_wcaps(codec, nid);
3705 unsigned int state = power_state;
3506 if (!(wcaps & AC_WCAP_POWER)) 3706 if (!(wcaps & AC_WCAP_POWER))
3507 continue; 3707 continue;
3508 /* don't power down the widget if it controls eapd and 3708 if (codec->power_filter) {
3509 * EAPD_BTLENABLE is set. 3709 state = codec->power_filter(codec, nid, power_state);
3510 */ 3710 if (state != power_state && power_state == AC_PWRST_D3)
3511 if (eapd_workaround && power_state == AC_PWRST_D3 &&
3512 get_wcaps_type(wcaps) == AC_WID_PIN &&
3513 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) {
3514 int eapd = snd_hda_codec_read(codec, nid, 0,
3515 AC_VERB_GET_EAPD_BTLENABLE, 0);
3516 if (eapd & 0x02)
3517 continue; 3711 continue;
3518 } 3712 }
3519 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, 3713 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
3520 power_state); 3714 state);
3521 } 3715 }
3522} 3716}
3523EXPORT_SYMBOL_HDA(snd_hda_codec_set_power_to_all); 3717EXPORT_SYMBOL_HDA(snd_hda_codec_set_power_to_all);
@@ -3564,6 +3758,21 @@ static unsigned int hda_sync_power_state(struct hda_codec *codec,
3564 return state; 3758 return state;
3565} 3759}
3566 3760
3761/* don't power down the widget if it controls eapd and EAPD_BTLENABLE is set */
3762static unsigned int default_power_filter(struct hda_codec *codec, hda_nid_t nid,
3763 unsigned int power_state)
3764{
3765 if (power_state == AC_PWRST_D3 &&
3766 get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN &&
3767 (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) {
3768 int eapd = snd_hda_codec_read(codec, nid, 0,
3769 AC_VERB_GET_EAPD_BTLENABLE, 0);
3770 if (eapd & 0x02)
3771 return AC_PWRST_D0;
3772 }
3773 return power_state;
3774}
3775
3567/* 3776/*
3568 * set power state of the codec, and return the power state 3777 * set power state of the codec, and return the power state
3569 */ 3778 */
@@ -3589,8 +3798,7 @@ static unsigned int hda_set_power_state(struct hda_codec *codec,
3589 snd_hda_codec_read(codec, fg, 0, 3798 snd_hda_codec_read(codec, fg, 0,
3590 AC_VERB_SET_POWER_STATE, 3799 AC_VERB_SET_POWER_STATE,
3591 power_state); 3800 power_state);
3592 snd_hda_codec_set_power_to_all(codec, fg, power_state, 3801 snd_hda_codec_set_power_to_all(codec, fg, power_state);
3593 true);
3594 } 3802 }
3595 state = hda_sync_power_state(codec, fg, power_state); 3803 state = hda_sync_power_state(codec, fg, power_state);
3596 if (!(state & AC_PWRST_ERROR)) 3804 if (!(state & AC_PWRST_ERROR))
@@ -3600,6 +3808,32 @@ static unsigned int hda_set_power_state(struct hda_codec *codec,
3600 return state; 3808 return state;
3601} 3809}
3602 3810
3811/* sync power states of all widgets;
3812 * this is called at the end of codec parsing
3813 */
3814static void sync_power_up_states(struct hda_codec *codec)
3815{
3816 hda_nid_t nid = codec->start_nid;
3817 int i;
3818
3819 /* don't care if no or standard filter is used */
3820 if (!codec->power_filter || codec->power_filter == default_power_filter)
3821 return;
3822
3823 for (i = 0; i < codec->num_nodes; i++, nid++) {
3824 unsigned int wcaps = get_wcaps(codec, nid);
3825 unsigned int target;
3826 if (!(wcaps & AC_WCAP_POWER))
3827 continue;
3828 target = codec->power_filter(codec, nid, AC_PWRST_D0);
3829 if (target == AC_PWRST_D0)
3830 continue;
3831 if (!snd_hda_check_power_state(codec, nid, target))
3832 snd_hda_codec_write(codec, nid, 0,
3833 AC_VERB_SET_POWER_STATE, target);
3834 }
3835}
3836
3603#ifdef CONFIG_SND_HDA_HWDEP 3837#ifdef CONFIG_SND_HDA_HWDEP
3604/* execute additional init verbs */ 3838/* execute additional init verbs */
3605static void hda_exec_init_verbs(struct hda_codec *codec) 3839static void hda_exec_init_verbs(struct hda_codec *codec)
@@ -3640,6 +3874,22 @@ static unsigned int hda_call_codec_suspend(struct hda_codec *codec, bool in_wq)
3640 return state; 3874 return state;
3641} 3875}
3642 3876
3877/* mark all entries of cmd and amp caches dirty */
3878static void hda_mark_cmd_cache_dirty(struct hda_codec *codec)
3879{
3880 int i;
3881 for (i = 0; i < codec->cmd_cache.buf.used; i++) {
3882 struct hda_cache_head *cmd;
3883 cmd = snd_array_elem(&codec->cmd_cache.buf, i);
3884 cmd->dirty = 1;
3885 }
3886 for (i = 0; i < codec->amp_cache.buf.used; i++) {
3887 struct hda_amp_info *amp;
3888 amp = snd_array_elem(&codec->amp_cache.buf, i);
3889 amp->head.dirty = 1;
3890 }
3891}
3892
3643/* 3893/*
3644 * kick up codec; used both from PM and power-save 3894 * kick up codec; used both from PM and power-save
3645 */ 3895 */
@@ -3647,6 +3897,8 @@ static void hda_call_codec_resume(struct hda_codec *codec)
3647{ 3897{
3648 codec->in_pm = 1; 3898 codec->in_pm = 1;
3649 3899
3900 hda_mark_cmd_cache_dirty(codec);
3901
3650 /* set as if powered on for avoiding re-entering the resume 3902 /* set as if powered on for avoiding re-entering the resume
3651 * in the resume / power-save sequence 3903 * in the resume / power-save sequence
3652 */ 3904 */
@@ -3769,6 +4021,7 @@ int snd_hda_codec_build_controls(struct hda_codec *codec)
3769 hda_jackpoll_work(&codec->jackpoll_work.work); 4021 hda_jackpoll_work(&codec->jackpoll_work.work);
3770 else 4022 else
3771 snd_hda_jack_report_sync(codec); /* call at the last init point */ 4023 snd_hda_jack_report_sync(codec); /* call at the last init point */
4024 sync_power_up_states(codec);
3772 return 0; 4025 return 0;
3773} 4026}
3774 4027
@@ -5120,23 +5373,62 @@ unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin)
5120} 5373}
5121EXPORT_SYMBOL_HDA(snd_hda_get_default_vref); 5374EXPORT_SYMBOL_HDA(snd_hda_get_default_vref);
5122 5375
5123int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, 5376/* correct the pin ctl value for matching with the pin cap */
5124 unsigned int val, bool cached) 5377unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
5378 hda_nid_t pin, unsigned int val)
5125{ 5379{
5126 if (val) { 5380 static unsigned int cap_lists[][2] = {
5127 unsigned int cap = snd_hda_query_pin_caps(codec, pin); 5381 { AC_PINCTL_VREF_100, AC_PINCAP_VREF_100 },
5128 if (cap && (val & AC_PINCTL_OUT_EN)) { 5382 { AC_PINCTL_VREF_80, AC_PINCAP_VREF_80 },
5129 if (!(cap & AC_PINCAP_OUT)) 5383 { AC_PINCTL_VREF_50, AC_PINCAP_VREF_50 },
5130 val &= ~(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN); 5384 { AC_PINCTL_VREF_GRD, AC_PINCAP_VREF_GRD },
5131 else if ((val & AC_PINCTL_HP_EN) && 5385 };
5132 !(cap & AC_PINCAP_HP_DRV)) 5386 unsigned int cap;
5133 val &= ~AC_PINCTL_HP_EN; 5387
5134 } 5388 if (!val)
5135 if (cap && (val & AC_PINCTL_IN_EN)) { 5389 return 0;
5136 if (!(cap & AC_PINCAP_IN)) 5390 cap = snd_hda_query_pin_caps(codec, pin);
5137 val &= ~(AC_PINCTL_IN_EN | AC_PINCTL_VREFEN); 5391 if (!cap)
5392 return val; /* don't know what to do... */
5393
5394 if (val & AC_PINCTL_OUT_EN) {
5395 if (!(cap & AC_PINCAP_OUT))
5396 val &= ~(AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
5397 else if ((val & AC_PINCTL_HP_EN) && !(cap & AC_PINCAP_HP_DRV))
5398 val &= ~AC_PINCTL_HP_EN;
5399 }
5400
5401 if (val & AC_PINCTL_IN_EN) {
5402 if (!(cap & AC_PINCAP_IN))
5403 val &= ~(AC_PINCTL_IN_EN | AC_PINCTL_VREFEN);
5404 else {
5405 unsigned int vcap, vref;
5406 int i;
5407 vcap = (cap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
5408 vref = val & AC_PINCTL_VREFEN;
5409 for (i = 0; i < ARRAY_SIZE(cap_lists); i++) {
5410 if (vref == cap_lists[i][0] &&
5411 !(vcap & cap_lists[i][1])) {
5412 if (i == ARRAY_SIZE(cap_lists) - 1)
5413 vref = AC_PINCTL_VREF_HIZ;
5414 else
5415 vref = cap_lists[i + 1][0];
5416 }
5417 }
5418 val &= ~AC_PINCTL_VREFEN;
5419 val |= vref;
5138 } 5420 }
5139 } 5421 }
5422
5423 return val;
5424}
5425EXPORT_SYMBOL_HDA(snd_hda_correct_pin_ctl);
5426
5427int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
5428 unsigned int val, bool cached)
5429{
5430 val = snd_hda_correct_pin_ctl(codec, pin, val);
5431 snd_hda_codec_set_pin_target(codec, pin, val);
5140 if (cached) 5432 if (cached)
5141 return snd_hda_codec_update_cache(codec, pin, 0, 5433 return snd_hda_codec_update_cache(codec, pin, 0,
5142 AC_VERB_SET_PIN_WIDGET_CONTROL, val); 5434 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 8665540e55aa..23ca1722aff1 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -551,9 +551,6 @@ enum {
551 AC_JACK_PORT_BOTH, 551 AC_JACK_PORT_BOTH,
552}; 552};
553 553
554/* max. connections to a widget */
555#define HDA_MAX_CONNECTIONS 32
556
557/* max. codec address */ 554/* max. codec address */
558#define HDA_MAX_CODEC_ADDRESS 0x0f 555#define HDA_MAX_CODEC_ADDRESS 0x0f
559 556
@@ -618,6 +615,17 @@ struct hda_bus_ops {
618 /* notify power-up/down from codec to controller */ 615 /* notify power-up/down from codec to controller */
619 void (*pm_notify)(struct hda_bus *bus, bool power_up); 616 void (*pm_notify)(struct hda_bus *bus, bool power_up);
620#endif 617#endif
618#ifdef CONFIG_SND_HDA_DSP_LOADER
619 /* prepare DSP transfer */
620 int (*load_dsp_prepare)(struct hda_bus *bus, unsigned int format,
621 unsigned int byte_size,
622 struct snd_dma_buffer *bufp);
623 /* start/stop DSP transfer */
624 void (*load_dsp_trigger)(struct hda_bus *bus, bool start);
625 /* clean up DSP transfer */
626 void (*load_dsp_cleanup)(struct hda_bus *bus,
627 struct snd_dma_buffer *dmab);
628#endif
621}; 629};
622 630
623/* template to pass to the bus constructor */ 631/* template to pass to the bus constructor */
@@ -671,6 +679,8 @@ struct hda_bus {
671 unsigned int response_reset:1; /* controller was reset */ 679 unsigned int response_reset:1; /* controller was reset */
672 unsigned int in_reset:1; /* during reset operation */ 680 unsigned int in_reset:1; /* during reset operation */
673 unsigned int power_keep_link_on:1; /* don't power off HDA link */ 681 unsigned int power_keep_link_on:1; /* don't power off HDA link */
682
683 int primary_dig_out_type; /* primary digital out PCM type */
674}; 684};
675 685
676/* 686/*
@@ -719,9 +729,10 @@ struct hda_codec_ops {
719 729
720/* record for amp information cache */ 730/* record for amp information cache */
721struct hda_cache_head { 731struct hda_cache_head {
722 u32 key; /* hash key */ 732 u32 key:31; /* hash key */
733 u32 dirty:1;
723 u16 val; /* assigned value */ 734 u16 val; /* assigned value */
724 u16 next; /* next link; -1 = terminal */ 735 u16 next;
725}; 736};
726 737
727struct hda_amp_info { 738struct hda_amp_info {
@@ -830,20 +841,20 @@ struct hda_codec {
830 struct hda_cache_rec amp_cache; /* cache for amp access */ 841 struct hda_cache_rec amp_cache; /* cache for amp access */
831 struct hda_cache_rec cmd_cache; /* cache for other commands */ 842 struct hda_cache_rec cmd_cache; /* cache for other commands */
832 843
833 struct snd_array conn_lists; /* connection-list array */ 844 struct list_head conn_list; /* linked-list of connection-list */
834 845
835 struct mutex spdif_mutex; 846 struct mutex spdif_mutex;
836 struct mutex control_mutex; 847 struct mutex control_mutex;
837 struct mutex hash_mutex; 848 struct mutex hash_mutex;
838 struct snd_array spdif_out; 849 struct snd_array spdif_out;
839 unsigned int spdif_in_enable; /* SPDIF input enable? */ 850 unsigned int spdif_in_enable; /* SPDIF input enable? */
840 int primary_dig_out_type; /* primary digital out PCM type */
841 const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ 851 const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
842 struct snd_array init_pins; /* initial (BIOS) pin configurations */ 852 struct snd_array init_pins; /* initial (BIOS) pin configurations */
843 struct snd_array driver_pins; /* pin configs set by codec parser */ 853 struct snd_array driver_pins; /* pin configs set by codec parser */
844 struct snd_array cvt_setups; /* audio convert setups */ 854 struct snd_array cvt_setups; /* audio convert setups */
845 855
846#ifdef CONFIG_SND_HDA_HWDEP 856#ifdef CONFIG_SND_HDA_HWDEP
857 struct mutex user_mutex;
847 struct snd_hwdep *hwdep; /* assigned hwdep device */ 858 struct snd_hwdep *hwdep; /* assigned hwdep device */
848 struct snd_array init_verbs; /* additional init verbs */ 859 struct snd_array init_verbs; /* additional init verbs */
849 struct snd_array hints; /* additional hints */ 860 struct snd_array hints; /* additional hints */
@@ -865,8 +876,11 @@ struct hda_codec {
865 unsigned int pins_shutup:1; /* pins are shut up */ 876 unsigned int pins_shutup:1; /* pins are shut up */
866 unsigned int no_trigger_sense:1; /* don't trigger at pin-sensing */ 877 unsigned int no_trigger_sense:1; /* don't trigger at pin-sensing */
867 unsigned int no_jack_detect:1; /* Machine has no jack-detection */ 878 unsigned int no_jack_detect:1; /* Machine has no jack-detection */
879 unsigned int inv_eapd:1; /* broken h/w: inverted EAPD control */
880 unsigned int inv_jack_detect:1; /* broken h/w: inverted detection bit */
868 unsigned int pcm_format_first:1; /* PCM format must be set first */ 881 unsigned int pcm_format_first:1; /* PCM format must be set first */
869 unsigned int epss:1; /* supporting EPSS? */ 882 unsigned int epss:1; /* supporting EPSS? */
883 unsigned int cached_write:1; /* write only to caches */
870#ifdef CONFIG_PM 884#ifdef CONFIG_PM
871 unsigned int power_on :1; /* current (global) power-state */ 885 unsigned int power_on :1; /* current (global) power-state */
872 unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ 886 unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */
@@ -881,6 +895,10 @@ struct hda_codec {
881 spinlock_t power_lock; 895 spinlock_t power_lock;
882#endif 896#endif
883 897
898 /* filter the requested power state per nid */
899 unsigned int (*power_filter)(struct hda_codec *codec, hda_nid_t nid,
900 unsigned int power_state);
901
884 /* codec-specific additional proc output */ 902 /* codec-specific additional proc output */
885 void (*proc_widget_hook)(struct snd_info_buffer *buffer, 903 void (*proc_widget_hook)(struct snd_info_buffer *buffer,
886 struct hda_codec *codec, hda_nid_t nid); 904 struct hda_codec *codec, hda_nid_t nid);
@@ -894,6 +912,14 @@ struct hda_codec {
894 /* jack detection */ 912 /* jack detection */
895 struct snd_array jacks; 913 struct snd_array jacks;
896#endif 914#endif
915
916 /* fix-up list */
917 int fixup_id;
918 const struct hda_fixup *fixup_list;
919 const char *fixup_name;
920
921 /* additional init verbs */
922 struct snd_array verbs;
897}; 923};
898 924
899/* direction */ 925/* direction */
@@ -910,6 +936,7 @@ int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp,
910int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 936int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
911 struct hda_codec **codecp); 937 struct hda_codec **codecp);
912int snd_hda_codec_configure(struct hda_codec *codec); 938int snd_hda_codec_configure(struct hda_codec *codec);
939int snd_hda_codec_update_widgets(struct hda_codec *codec);
913 940
914/* 941/*
915 * low level functions 942 * low level functions
@@ -930,8 +957,11 @@ snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
930{ 957{
931 return snd_hda_get_connections(codec, nid, NULL, 0); 958 return snd_hda_get_connections(codec, nid, NULL, 0);
932} 959}
960int snd_hda_get_num_raw_conns(struct hda_codec *codec, hda_nid_t nid);
933int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid, 961int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
934 hda_nid_t *conn_list, int max_conns); 962 hda_nid_t *conn_list, int max_conns);
963int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
964 const hda_nid_t **listp);
935int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, 965int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,
936 const hda_nid_t *list); 966 const hda_nid_t *list);
937int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, 967int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
@@ -952,7 +982,6 @@ void snd_hda_sequence_write(struct hda_codec *codec,
952int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex); 982int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex);
953 983
954/* cached write */ 984/* cached write */
955#ifdef CONFIG_PM
956int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, 985int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
957 int direct, unsigned int verb, unsigned int parm); 986 int direct, unsigned int verb, unsigned int parm);
958void snd_hda_sequence_write_cache(struct hda_codec *codec, 987void snd_hda_sequence_write_cache(struct hda_codec *codec,
@@ -960,17 +989,14 @@ void snd_hda_sequence_write_cache(struct hda_codec *codec,
960int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, 989int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
961 int direct, unsigned int verb, unsigned int parm); 990 int direct, unsigned int verb, unsigned int parm);
962void snd_hda_codec_resume_cache(struct hda_codec *codec); 991void snd_hda_codec_resume_cache(struct hda_codec *codec);
963#else 992/* both for cmd & amp caches */
964#define snd_hda_codec_write_cache snd_hda_codec_write 993void snd_hda_codec_flush_cache(struct hda_codec *codec);
965#define snd_hda_codec_update_cache snd_hda_codec_write
966#define snd_hda_sequence_write_cache snd_hda_sequence_write
967#endif
968 994
969/* the struct for codec->pin_configs */ 995/* the struct for codec->pin_configs */
970struct hda_pincfg { 996struct hda_pincfg {
971 hda_nid_t nid; 997 hda_nid_t nid;
972 unsigned char ctrl; /* current pin control value */ 998 unsigned char ctrl; /* original pin control value */
973 unsigned char pad; /* reserved */ 999 unsigned char target; /* target pin control value */
974 unsigned int cfg; /* default configuration */ 1000 unsigned int cfg; /* default configuration */
975}; 1001};
976 1002
@@ -1036,8 +1062,7 @@ extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
1036void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); 1062void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
1037void snd_hda_bus_reboot_notify(struct hda_bus *bus); 1063void snd_hda_bus_reboot_notify(struct hda_bus *bus);
1038void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, 1064void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
1039 unsigned int power_state, 1065 unsigned int power_state);
1040 bool eapd_workaround);
1041 1066
1042int snd_hda_lock_devices(struct hda_bus *bus); 1067int snd_hda_lock_devices(struct hda_bus *bus);
1043void snd_hda_unlock_devices(struct hda_bus *bus); 1068void snd_hda_unlock_devices(struct hda_bus *bus);
@@ -1136,6 +1161,40 @@ static inline void snd_hda_power_sync(struct hda_codec *codec)
1136int snd_hda_load_patch(struct hda_bus *bus, size_t size, const void *buf); 1161int snd_hda_load_patch(struct hda_bus *bus, size_t size, const void *buf);
1137#endif 1162#endif
1138 1163
1164#ifdef CONFIG_SND_HDA_DSP_LOADER
1165static inline int
1166snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
1167 unsigned int size,
1168 struct snd_dma_buffer *bufp)
1169{
1170 return codec->bus->ops.load_dsp_prepare(codec->bus, format, size, bufp);
1171}
1172static inline void
1173snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start)
1174{
1175 return codec->bus->ops.load_dsp_trigger(codec->bus, start);
1176}
1177static inline void
1178snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec,
1179 struct snd_dma_buffer *dmab)
1180{
1181 return codec->bus->ops.load_dsp_cleanup(codec->bus, dmab);
1182}
1183#else
1184static inline int
1185snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
1186 unsigned int size,
1187 struct snd_dma_buffer *bufp)
1188{
1189 return -ENOSYS;
1190}
1191static inline void
1192snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start) {}
1193static inline void
1194snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec,
1195 struct snd_dma_buffer *dmab) {}
1196#endif
1197
1139/* 1198/*
1140 * Codec modularization 1199 * Codec modularization
1141 */ 1200 */
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index 4c054f4486b9..7dd846380a50 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -246,8 +246,8 @@ static void hdmi_update_short_audio_desc(struct cea_sad *a,
246/* 246/*
247 * Be careful, ELD buf could be totally rubbish! 247 * Be careful, ELD buf could be totally rubbish!
248 */ 248 */
249static int hdmi_update_eld(struct hdmi_eld *e, 249int snd_hdmi_parse_eld(struct parsed_hdmi_eld *e,
250 const unsigned char *buf, int size) 250 const unsigned char *buf, int size)
251{ 251{
252 int mnl; 252 int mnl;
253 int i; 253 int i;
@@ -260,7 +260,6 @@ static int hdmi_update_eld(struct hdmi_eld *e,
260 goto out_fail; 260 goto out_fail;
261 } 261 }
262 262
263 e->eld_size = size;
264 e->baseline_len = GRAB_BITS(buf, 2, 0, 8); 263 e->baseline_len = GRAB_BITS(buf, 2, 0, 8);
265 mnl = GRAB_BITS(buf, 4, 0, 5); 264 mnl = GRAB_BITS(buf, 4, 0, 5);
266 e->cea_edid_ver = GRAB_BITS(buf, 4, 5, 3); 265 e->cea_edid_ver = GRAB_BITS(buf, 4, 5, 3);
@@ -305,7 +304,6 @@ static int hdmi_update_eld(struct hdmi_eld *e,
305 if (!e->spk_alloc) 304 if (!e->spk_alloc)
306 e->spk_alloc = 0xffff; 305 e->spk_alloc = 0xffff;
307 306
308 e->eld_valid = true;
309 return 0; 307 return 0;
310 308
311out_fail: 309out_fail:
@@ -318,17 +316,16 @@ int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid)
318 AC_DIPSIZE_ELD_BUF); 316 AC_DIPSIZE_ELD_BUF);
319} 317}
320 318
321int snd_hdmi_get_eld(struct hdmi_eld *eld, 319int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
322 struct hda_codec *codec, hda_nid_t nid) 320 unsigned char *buf, int *eld_size)
323{ 321{
324 int i; 322 int i;
325 int ret; 323 int ret;
326 int size; 324 int size;
327 unsigned char *buf;
328 325
329 /* 326 /*
330 * ELD size is initialized to zero in caller function. If no errors and 327 * ELD size is initialized to zero in caller function. If no errors and
331 * ELD is valid, actual eld_size is assigned in hdmi_update_eld() 328 * ELD is valid, actual eld_size is assigned.
332 */ 329 */
333 330
334 size = snd_hdmi_get_eld_size(codec, nid); 331 size = snd_hdmi_get_eld_size(codec, nid);
@@ -343,8 +340,6 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
343 } 340 }
344 341
345 /* set ELD buffer */ 342 /* set ELD buffer */
346 buf = eld->eld_buffer;
347
348 for (i = 0; i < size; i++) { 343 for (i = 0; i < size; i++) {
349 unsigned int val = hdmi_get_eld_data(codec, nid, i); 344 unsigned int val = hdmi_get_eld_data(codec, nid, i);
350 /* 345 /*
@@ -372,8 +367,7 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
372 buf[i] = val; 367 buf[i] = val;
373 } 368 }
374 369
375 ret = hdmi_update_eld(eld, buf, size); 370 *eld_size = size;
376
377error: 371error:
378 return ret; 372 return ret;
379} 373}
@@ -438,7 +432,7 @@ void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen)
438 buf[j] = '\0'; /* necessary when j == 0 */ 432 buf[j] = '\0'; /* necessary when j == 0 */
439} 433}
440 434
441void snd_hdmi_show_eld(struct hdmi_eld *e) 435void snd_hdmi_show_eld(struct parsed_hdmi_eld *e)
442{ 436{
443 int i; 437 int i;
444 438
@@ -487,10 +481,11 @@ static void hdmi_print_sad_info(int i, struct cea_sad *a,
487static void hdmi_print_eld_info(struct snd_info_entry *entry, 481static void hdmi_print_eld_info(struct snd_info_entry *entry,
488 struct snd_info_buffer *buffer) 482 struct snd_info_buffer *buffer)
489{ 483{
490 struct hdmi_eld *e = entry->private_data; 484 struct hdmi_eld *eld = entry->private_data;
485 struct parsed_hdmi_eld *e = &eld->info;
491 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; 486 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
492 int i; 487 int i;
493 static char *eld_versoin_names[32] = { 488 static char *eld_version_names[32] = {
494 "reserved", 489 "reserved",
495 "reserved", 490 "reserved",
496 "CEA-861D or below", 491 "CEA-861D or below",
@@ -505,15 +500,18 @@ static void hdmi_print_eld_info(struct snd_info_entry *entry,
505 [4 ... 7] = "reserved" 500 [4 ... 7] = "reserved"
506 }; 501 };
507 502
508 snd_iprintf(buffer, "monitor_present\t\t%d\n", e->monitor_present); 503 mutex_lock(&eld->lock);
509 snd_iprintf(buffer, "eld_valid\t\t%d\n", e->eld_valid); 504 snd_iprintf(buffer, "monitor_present\t\t%d\n", eld->monitor_present);
510 if (!e->eld_valid) 505 snd_iprintf(buffer, "eld_valid\t\t%d\n", eld->eld_valid);
506 if (!eld->eld_valid) {
507 mutex_unlock(&eld->lock);
511 return; 508 return;
509 }
512 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name); 510 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name);
513 snd_iprintf(buffer, "connection_type\t\t%s\n", 511 snd_iprintf(buffer, "connection_type\t\t%s\n",
514 eld_connection_type_names[e->conn_type]); 512 eld_connection_type_names[e->conn_type]);
515 snd_iprintf(buffer, "eld_version\t\t[0x%x] %s\n", e->eld_ver, 513 snd_iprintf(buffer, "eld_version\t\t[0x%x] %s\n", e->eld_ver,
516 eld_versoin_names[e->eld_ver]); 514 eld_version_names[e->eld_ver]);
517 snd_iprintf(buffer, "edid_version\t\t[0x%x] %s\n", e->cea_edid_ver, 515 snd_iprintf(buffer, "edid_version\t\t[0x%x] %s\n", e->cea_edid_ver,
518 cea_edid_version_names[e->cea_edid_ver]); 516 cea_edid_version_names[e->cea_edid_ver]);
519 snd_iprintf(buffer, "manufacture_id\t\t0x%x\n", e->manufacture_id); 517 snd_iprintf(buffer, "manufacture_id\t\t0x%x\n", e->manufacture_id);
@@ -530,18 +528,21 @@ static void hdmi_print_eld_info(struct snd_info_entry *entry,
530 528
531 for (i = 0; i < e->sad_count; i++) 529 for (i = 0; i < e->sad_count; i++)
532 hdmi_print_sad_info(i, e->sad + i, buffer); 530 hdmi_print_sad_info(i, e->sad + i, buffer);
531 mutex_unlock(&eld->lock);
533} 532}
534 533
535static void hdmi_write_eld_info(struct snd_info_entry *entry, 534static void hdmi_write_eld_info(struct snd_info_entry *entry,
536 struct snd_info_buffer *buffer) 535 struct snd_info_buffer *buffer)
537{ 536{
538 struct hdmi_eld *e = entry->private_data; 537 struct hdmi_eld *eld = entry->private_data;
538 struct parsed_hdmi_eld *e = &eld->info;
539 char line[64]; 539 char line[64];
540 char name[64]; 540 char name[64];
541 char *sname; 541 char *sname;
542 long long val; 542 long long val;
543 unsigned int n; 543 unsigned int n;
544 544
545 mutex_lock(&eld->lock);
545 while (!snd_info_get_line(buffer, line, sizeof(line))) { 546 while (!snd_info_get_line(buffer, line, sizeof(line))) {
546 if (sscanf(line, "%s %llx", name, &val) != 2) 547 if (sscanf(line, "%s %llx", name, &val) != 2)
547 continue; 548 continue;
@@ -551,9 +552,9 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
551 * eld_version edid_version 552 * eld_version edid_version
552 */ 553 */
553 if (!strcmp(name, "monitor_present")) 554 if (!strcmp(name, "monitor_present"))
554 e->monitor_present = val; 555 eld->monitor_present = val;
555 else if (!strcmp(name, "eld_valid")) 556 else if (!strcmp(name, "eld_valid"))
556 e->eld_valid = val; 557 eld->eld_valid = val;
557 else if (!strcmp(name, "connection_type")) 558 else if (!strcmp(name, "connection_type"))
558 e->conn_type = val; 559 e->conn_type = val;
559 else if (!strcmp(name, "port_id")) 560 else if (!strcmp(name, "port_id"))
@@ -593,6 +594,7 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
593 e->sad_count = n + 1; 594 e->sad_count = n + 1;
594 } 595 }
595 } 596 }
597 mutex_unlock(&eld->lock);
596} 598}
597 599
598 600
@@ -627,7 +629,7 @@ void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld)
627#endif /* CONFIG_PROC_FS */ 629#endif /* CONFIG_PROC_FS */
628 630
629/* update PCM info based on ELD */ 631/* update PCM info based on ELD */
630void snd_hdmi_eld_update_pcm_info(struct hdmi_eld *eld, 632void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
631 struct hda_pcm_stream *hinfo) 633 struct hda_pcm_stream *hinfo)
632{ 634{
633 u32 rates; 635 u32 rates;
@@ -644,8 +646,8 @@ void snd_hdmi_eld_update_pcm_info(struct hdmi_eld *eld,
644 formats = SNDRV_PCM_FMTBIT_S16_LE; 646 formats = SNDRV_PCM_FMTBIT_S16_LE;
645 maxbps = 16; 647 maxbps = 16;
646 channels_max = 2; 648 channels_max = 2;
647 for (i = 0; i < eld->sad_count; i++) { 649 for (i = 0; i < e->sad_count; i++) {
648 struct cea_sad *a = &eld->sad[i]; 650 struct cea_sad *a = &e->sad[i];
649 rates |= a->rates; 651 rates |= a->rates;
650 if (a->channels > channels_max) 652 if (a->channels > channels_max)
651 channels_max = a->channels; 653 channels_max = a->channels;
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index b81d3d0b952d..78897d05d80f 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -23,836 +23,3210 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/export.h> 25#include <linux/export.h>
26#include <linux/sort.h>
27#include <linux/delay.h>
28#include <linux/ctype.h>
29#include <linux/string.h>
30#include <linux/bitops.h>
26#include <sound/core.h> 31#include <sound/core.h>
32#include <sound/jack.h>
27#include "hda_codec.h" 33#include "hda_codec.h"
28#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_auto_parser.h"
36#include "hda_jack.h"
37#include "hda_generic.h"
29 38
30/* widget node for parsing */
31struct hda_gnode {
32 hda_nid_t nid; /* NID of this widget */
33 unsigned short nconns; /* number of input connections */
34 hda_nid_t *conn_list;
35 hda_nid_t slist[2]; /* temporay list */
36 unsigned int wid_caps; /* widget capabilities */
37 unsigned char type; /* widget type */
38 unsigned char pin_ctl; /* pin controls */
39 unsigned char checked; /* the flag indicates that the node is already parsed */
40 unsigned int pin_caps; /* pin widget capabilities */
41 unsigned int def_cfg; /* default configuration */
42 unsigned int amp_out_caps; /* AMP out capabilities */
43 unsigned int amp_in_caps; /* AMP in capabilities */
44 struct list_head list;
45};
46 39
47/* patch-specific record */ 40/* initialize hda_gen_spec struct */
41int snd_hda_gen_spec_init(struct hda_gen_spec *spec)
42{
43 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
44 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
45 snd_array_init(&spec->loopback_list, sizeof(struct hda_amp_list), 8);
46 mutex_init(&spec->pcm_mutex);
47 return 0;
48}
49EXPORT_SYMBOL_HDA(snd_hda_gen_spec_init);
48 50
49#define MAX_PCM_VOLS 2 51struct snd_kcontrol_new *
50struct pcm_vol { 52snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name,
51 struct hda_gnode *node; /* Node for PCM volume */ 53 const struct snd_kcontrol_new *temp)
52 unsigned int index; /* connection of PCM volume */ 54{
53}; 55 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
56 if (!knew)
57 return NULL;
58 *knew = *temp;
59 if (name)
60 knew->name = kstrdup(name, GFP_KERNEL);
61 else if (knew->name)
62 knew->name = kstrdup(knew->name, GFP_KERNEL);
63 if (!knew->name)
64 return NULL;
65 return knew;
66}
67EXPORT_SYMBOL_HDA(snd_hda_gen_add_kctl);
54 68
55struct hda_gspec { 69static void free_kctls(struct hda_gen_spec *spec)
56 struct hda_gnode *dac_node[2]; /* DAC node */ 70{
57 struct hda_gnode *out_pin_node[2]; /* Output pin (Line-Out) node */ 71 if (spec->kctls.list) {
58 struct pcm_vol pcm_vol[MAX_PCM_VOLS]; /* PCM volumes */ 72 struct snd_kcontrol_new *kctl = spec->kctls.list;
59 unsigned int pcm_vol_nodes; /* number of PCM volumes */ 73 int i;
74 for (i = 0; i < spec->kctls.used; i++)
75 kfree(kctl[i].name);
76 }
77 snd_array_free(&spec->kctls);
78}
60 79
61 struct hda_gnode *adc_node; /* ADC node */ 80void snd_hda_gen_spec_free(struct hda_gen_spec *spec)
62 struct hda_gnode *cap_vol_node; /* Node for capture volume */ 81{
63 unsigned int cur_cap_src; /* current capture source */ 82 if (!spec)
64 struct hda_input_mux input_mux; 83 return;
84 free_kctls(spec);
85 snd_array_free(&spec->paths);
86 snd_array_free(&spec->loopback_list);
87}
88EXPORT_SYMBOL_HDA(snd_hda_gen_spec_free);
65 89
66 unsigned int def_amp_in_caps; 90/*
67 unsigned int def_amp_out_caps; 91 * store user hints
92 */
93static void parse_user_hints(struct hda_codec *codec)
94{
95 struct hda_gen_spec *spec = codec->spec;
96 int val;
68 97
69 struct hda_pcm pcm_rec; /* PCM information */ 98 val = snd_hda_get_bool_hint(codec, "jack_detect");
99 if (val >= 0)
100 codec->no_jack_detect = !val;
101 val = snd_hda_get_bool_hint(codec, "inv_jack_detect");
102 if (val >= 0)
103 codec->inv_jack_detect = !!val;
104 val = snd_hda_get_bool_hint(codec, "trigger_sense");
105 if (val >= 0)
106 codec->no_trigger_sense = !val;
107 val = snd_hda_get_bool_hint(codec, "inv_eapd");
108 if (val >= 0)
109 codec->inv_eapd = !!val;
110 val = snd_hda_get_bool_hint(codec, "pcm_format_first");
111 if (val >= 0)
112 codec->pcm_format_first = !!val;
113 val = snd_hda_get_bool_hint(codec, "sticky_stream");
114 if (val >= 0)
115 codec->no_sticky_stream = !val;
116 val = snd_hda_get_bool_hint(codec, "spdif_status_reset");
117 if (val >= 0)
118 codec->spdif_status_reset = !!val;
119 val = snd_hda_get_bool_hint(codec, "pin_amp_workaround");
120 if (val >= 0)
121 codec->pin_amp_workaround = !!val;
122 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
123 if (val >= 0)
124 codec->single_adc_amp = !!val;
70 125
71 struct list_head nid_list; /* list of widgets */ 126 val = snd_hda_get_bool_hint(codec, "auto_mute");
127 if (val >= 0)
128 spec->suppress_auto_mute = !val;
129 val = snd_hda_get_bool_hint(codec, "auto_mic");
130 if (val >= 0)
131 spec->suppress_auto_mic = !val;
132 val = snd_hda_get_bool_hint(codec, "line_in_auto_switch");
133 if (val >= 0)
134 spec->line_in_auto_switch = !!val;
135 val = snd_hda_get_bool_hint(codec, "need_dac_fix");
136 if (val >= 0)
137 spec->need_dac_fix = !!val;
138 val = snd_hda_get_bool_hint(codec, "primary_hp");
139 if (val >= 0)
140 spec->no_primary_hp = !val;
141 val = snd_hda_get_bool_hint(codec, "multi_cap_vol");
142 if (val >= 0)
143 spec->multi_cap_vol = !!val;
144 val = snd_hda_get_bool_hint(codec, "inv_dmic_split");
145 if (val >= 0)
146 spec->inv_dmic_split = !!val;
147 val = snd_hda_get_bool_hint(codec, "indep_hp");
148 if (val >= 0)
149 spec->indep_hp = !!val;
150 val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input");
151 if (val >= 0)
152 spec->add_stereo_mix_input = !!val;
153 val = snd_hda_get_bool_hint(codec, "add_out_jack_modes");
154 if (val >= 0)
155 spec->add_out_jack_modes = !!val;
156 val = snd_hda_get_bool_hint(codec, "add_in_jack_modes");
157 if (val >= 0)
158 spec->add_in_jack_modes = !!val;
159 val = snd_hda_get_bool_hint(codec, "power_down_unused");
160 if (val >= 0)
161 spec->power_down_unused = !!val;
72 162
73#ifdef CONFIG_PM 163 if (!snd_hda_get_int_hint(codec, "mixer_nid", &val))
74#define MAX_LOOPBACK_AMPS 7 164 spec->mixer_nid = val;
75 struct hda_loopback_check loopback; 165}
76 int num_loopbacks;
77 struct hda_amp_list loopback_list[MAX_LOOPBACK_AMPS + 1];
78#endif
79};
80 166
81/* 167/*
82 * retrieve the default device type from the default config value 168 * pin control value accesses
83 */ 169 */
84#define defcfg_type(node) (((node)->def_cfg & AC_DEFCFG_DEVICE) >> \
85 AC_DEFCFG_DEVICE_SHIFT)
86#define defcfg_location(node) (((node)->def_cfg & AC_DEFCFG_LOCATION) >> \
87 AC_DEFCFG_LOCATION_SHIFT)
88#define defcfg_port_conn(node) (((node)->def_cfg & AC_DEFCFG_PORT_CONN) >> \
89 AC_DEFCFG_PORT_CONN_SHIFT)
90 170
91/* 171#define update_pin_ctl(codec, pin, val) \
92 * destructor 172 snd_hda_codec_update_cache(codec, pin, 0, \
93 */ 173 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
94static void snd_hda_generic_free(struct hda_codec *codec) 174
175/* restore the pinctl based on the cached value */
176static inline void restore_pin_ctl(struct hda_codec *codec, hda_nid_t pin)
95{ 177{
96 struct hda_gspec *spec = codec->spec; 178 update_pin_ctl(codec, pin, snd_hda_codec_get_pin_target(codec, pin));
97 struct hda_gnode *node, *n; 179}
98 180
99 if (! spec) 181/* set the pinctl target value and write it if requested */
182static void set_pin_target(struct hda_codec *codec, hda_nid_t pin,
183 unsigned int val, bool do_write)
184{
185 if (!pin)
100 return; 186 return;
101 /* free all widgets */ 187 val = snd_hda_correct_pin_ctl(codec, pin, val);
102 list_for_each_entry_safe(node, n, &spec->nid_list, list) { 188 snd_hda_codec_set_pin_target(codec, pin, val);
103 if (node->conn_list != node->slist) 189 if (do_write)
104 kfree(node->conn_list); 190 update_pin_ctl(codec, pin, val);
105 kfree(node);
106 }
107 kfree(spec);
108} 191}
109 192
193/* set pinctl target values for all given pins */
194static void set_pin_targets(struct hda_codec *codec, int num_pins,
195 hda_nid_t *pins, unsigned int val)
196{
197 int i;
198 for (i = 0; i < num_pins; i++)
199 set_pin_target(codec, pins[i], val, false);
200}
110 201
111/* 202/*
112 * add a new widget node and read its attributes 203 * parsing paths
113 */ 204 */
114static int add_new_node(struct hda_codec *codec, struct hda_gspec *spec, hda_nid_t nid) 205
206/* return the position of NID in the list, or -1 if not found */
207static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
115{ 208{
116 struct hda_gnode *node; 209 int i;
117 int nconns; 210 for (i = 0; i < nums; i++)
118 hda_nid_t conn_list[HDA_MAX_CONNECTIONS]; 211 if (list[i] == nid)
212 return i;
213 return -1;
214}
119 215
120 node = kzalloc(sizeof(*node), GFP_KERNEL); 216/* return true if the given NID is contained in the path */
121 if (node == NULL) 217static bool is_nid_contained(struct nid_path *path, hda_nid_t nid)
122 return -ENOMEM; 218{
123 node->nid = nid; 219 return find_idx_in_nid_list(nid, path->path, path->depth) >= 0;
124 node->wid_caps = get_wcaps(codec, nid); 220}
125 node->type = get_wcaps_type(node->wid_caps); 221
126 if (node->wid_caps & AC_WCAP_CONN_LIST) { 222static struct nid_path *get_nid_path(struct hda_codec *codec,
127 nconns = snd_hda_get_connections(codec, nid, conn_list, 223 hda_nid_t from_nid, hda_nid_t to_nid,
128 HDA_MAX_CONNECTIONS); 224 int anchor_nid)
129 if (nconns < 0) { 225{
130 kfree(node); 226 struct hda_gen_spec *spec = codec->spec;
131 return nconns; 227 int i;
132 } 228
133 } else { 229 for (i = 0; i < spec->paths.used; i++) {
134 nconns = 0; 230 struct nid_path *path = snd_array_elem(&spec->paths, i);
135 } 231 if (path->depth <= 0)
136 if (nconns <= ARRAY_SIZE(node->slist)) 232 continue;
137 node->conn_list = node->slist; 233 if ((!from_nid || path->path[0] == from_nid) &&
138 else { 234 (!to_nid || path->path[path->depth - 1] == to_nid)) {
139 node->conn_list = kmalloc(sizeof(hda_nid_t) * nconns, 235 if (!anchor_nid ||
140 GFP_KERNEL); 236 (anchor_nid > 0 && is_nid_contained(path, anchor_nid)) ||
141 if (! node->conn_list) { 237 (anchor_nid < 0 && !is_nid_contained(path, anchor_nid)))
142 snd_printk(KERN_ERR "hda-generic: cannot malloc\n"); 238 return path;
143 kfree(node);
144 return -ENOMEM;
145 } 239 }
146 } 240 }
147 memcpy(node->conn_list, conn_list, nconns * sizeof(hda_nid_t)); 241 return NULL;
148 node->nconns = nconns; 242}
149 243
150 if (node->type == AC_WID_PIN) { 244/* get the path between the given NIDs;
151 node->pin_caps = snd_hda_query_pin_caps(codec, node->nid); 245 * passing 0 to either @pin or @dac behaves as a wildcard
152 node->pin_ctl = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 246 */
153 node->def_cfg = snd_hda_codec_get_pincfg(codec, node->nid); 247struct nid_path *snd_hda_get_nid_path(struct hda_codec *codec,
248 hda_nid_t from_nid, hda_nid_t to_nid)
249{
250 return get_nid_path(codec, from_nid, to_nid, 0);
251}
252EXPORT_SYMBOL_HDA(snd_hda_get_nid_path);
253
254/* get the index number corresponding to the path instance;
255 * the index starts from 1, for easier checking the invalid value
256 */
257int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path)
258{
259 struct hda_gen_spec *spec = codec->spec;
260 struct nid_path *array = spec->paths.list;
261 ssize_t idx;
262
263 if (!spec->paths.used)
264 return 0;
265 idx = path - array;
266 if (idx < 0 || idx >= spec->paths.used)
267 return 0;
268 return idx + 1;
269}
270EXPORT_SYMBOL_HDA(snd_hda_get_path_idx);
271
272/* get the path instance corresponding to the given index number */
273struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx)
274{
275 struct hda_gen_spec *spec = codec->spec;
276
277 if (idx <= 0 || idx > spec->paths.used)
278 return NULL;
279 return snd_array_elem(&spec->paths, idx - 1);
280}
281EXPORT_SYMBOL_HDA(snd_hda_get_path_from_idx);
282
283/* check whether the given DAC is already found in any existing paths */
284static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
285{
286 struct hda_gen_spec *spec = codec->spec;
287 int i;
288
289 for (i = 0; i < spec->paths.used; i++) {
290 struct nid_path *path = snd_array_elem(&spec->paths, i);
291 if (path->path[0] == nid)
292 return true;
154 } 293 }
294 return false;
295}
155 296
156 if (node->wid_caps & AC_WCAP_OUT_AMP) { 297/* check whether the given two widgets can be connected */
157 if (node->wid_caps & AC_WCAP_AMP_OVRD) 298static bool is_reachable_path(struct hda_codec *codec,
158 node->amp_out_caps = snd_hda_param_read(codec, node->nid, AC_PAR_AMP_OUT_CAP); 299 hda_nid_t from_nid, hda_nid_t to_nid)
159 if (! node->amp_out_caps) 300{
160 node->amp_out_caps = spec->def_amp_out_caps; 301 if (!from_nid || !to_nid)
302 return false;
303 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
304}
305
306/* nid, dir and idx */
307#define AMP_VAL_COMPARE_MASK (0xffff | (1U << 18) | (0x0f << 19))
308
309/* check whether the given ctl is already assigned in any path elements */
310static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
311{
312 struct hda_gen_spec *spec = codec->spec;
313 int i;
314
315 val &= AMP_VAL_COMPARE_MASK;
316 for (i = 0; i < spec->paths.used; i++) {
317 struct nid_path *path = snd_array_elem(&spec->paths, i);
318 if ((path->ctls[type] & AMP_VAL_COMPARE_MASK) == val)
319 return true;
161 } 320 }
162 if (node->wid_caps & AC_WCAP_IN_AMP) { 321 return false;
163 if (node->wid_caps & AC_WCAP_AMP_OVRD) 322}
164 node->amp_in_caps = snd_hda_param_read(codec, node->nid, AC_PAR_AMP_IN_CAP); 323
165 if (! node->amp_in_caps) 324/* check whether a control with the given (nid, dir, idx) was assigned */
166 node->amp_in_caps = spec->def_amp_in_caps; 325static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
326 int dir, int idx, int type)
327{
328 unsigned int val = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir);
329 return is_ctl_used(codec, val, type);
330}
331
332static void print_nid_path(const char *pfx, struct nid_path *path)
333{
334 char buf[40];
335 int i;
336
337
338 buf[0] = 0;
339 for (i = 0; i < path->depth; i++) {
340 char tmp[4];
341 sprintf(tmp, ":%02x", path->path[i]);
342 strlcat(buf, tmp, sizeof(buf));
167 } 343 }
168 list_add_tail(&node->list, &spec->nid_list); 344 snd_printdd("%s path: depth=%d %s\n", pfx, path->depth, buf);
169 return 0;
170} 345}
171 346
347/* called recursively */
348static bool __parse_nid_path(struct hda_codec *codec,
349 hda_nid_t from_nid, hda_nid_t to_nid,
350 int anchor_nid, struct nid_path *path,
351 int depth)
352{
353 const hda_nid_t *conn;
354 int i, nums;
355
356 if (to_nid == anchor_nid)
357 anchor_nid = 0; /* anchor passed */
358 else if (to_nid == (hda_nid_t)(-anchor_nid))
359 return false; /* hit the exclusive nid */
360
361 nums = snd_hda_get_conn_list(codec, to_nid, &conn);
362 for (i = 0; i < nums; i++) {
363 if (conn[i] != from_nid) {
364 /* special case: when from_nid is 0,
365 * try to find an empty DAC
366 */
367 if (from_nid ||
368 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
369 is_dac_already_used(codec, conn[i]))
370 continue;
371 }
372 /* anchor is not requested or already passed? */
373 if (anchor_nid <= 0)
374 goto found;
375 }
376 if (depth >= MAX_NID_PATH_DEPTH)
377 return false;
378 for (i = 0; i < nums; i++) {
379 unsigned int type;
380 type = get_wcaps_type(get_wcaps(codec, conn[i]));
381 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
382 type == AC_WID_PIN)
383 continue;
384 if (__parse_nid_path(codec, from_nid, conn[i],
385 anchor_nid, path, depth + 1))
386 goto found;
387 }
388 return false;
389
390 found:
391 path->path[path->depth] = conn[i];
392 path->idx[path->depth + 1] = i;
393 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
394 path->multi[path->depth + 1] = 1;
395 path->depth++;
396 return true;
397}
398
399/* parse the widget path from the given nid to the target nid;
400 * when @from_nid is 0, try to find an empty DAC;
401 * when @anchor_nid is set to a positive value, only paths through the widget
402 * with the given value are evaluated.
403 * when @anchor_nid is set to a negative value, paths through the widget
404 * with the negative of given value are excluded, only other paths are chosen.
405 * when @anchor_nid is zero, no special handling about path selection.
406 */
407bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
408 hda_nid_t to_nid, int anchor_nid,
409 struct nid_path *path)
410{
411 if (__parse_nid_path(codec, from_nid, to_nid, anchor_nid, path, 1)) {
412 path->path[path->depth] = to_nid;
413 path->depth++;
414 return true;
415 }
416 return false;
417}
418EXPORT_SYMBOL_HDA(snd_hda_parse_nid_path);
419
172/* 420/*
173 * build the AFG subtree 421 * parse the path between the given NIDs and add to the path list.
422 * if no valid path is found, return NULL
174 */ 423 */
175static int build_afg_tree(struct hda_codec *codec) 424struct nid_path *
425snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
426 hda_nid_t to_nid, int anchor_nid)
176{ 427{
177 struct hda_gspec *spec = codec->spec; 428 struct hda_gen_spec *spec = codec->spec;
178 int i, nodes, err; 429 struct nid_path *path;
179 hda_nid_t nid;
180 430
181 if (snd_BUG_ON(!spec)) 431 if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid))
182 return -EINVAL; 432 return NULL;
183 433
184 spec->def_amp_out_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_OUT_CAP); 434 /* check whether the path has been already added */
185 spec->def_amp_in_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_IN_CAP); 435 path = get_nid_path(codec, from_nid, to_nid, anchor_nid);
436 if (path)
437 return path;
186 438
187 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 439 path = snd_array_new(&spec->paths);
188 if (! nid || nodes < 0) { 440 if (!path)
189 printk(KERN_ERR "Invalid AFG subtree\n"); 441 return NULL;
190 return -EINVAL; 442 memset(path, 0, sizeof(*path));
191 } 443 if (snd_hda_parse_nid_path(codec, from_nid, to_nid, anchor_nid, path))
444 return path;
445 /* push back */
446 spec->paths.used--;
447 return NULL;
448}
449EXPORT_SYMBOL_HDA(snd_hda_add_new_path);
192 450
193 /* parse all nodes belonging to the AFG */ 451/* clear the given path as invalid so that it won't be picked up later */
194 for (i = 0; i < nodes; i++, nid++) { 452static void invalidate_nid_path(struct hda_codec *codec, int idx)
195 if ((err = add_new_node(codec, spec, nid)) < 0) 453{
196 return err; 454 struct nid_path *path = snd_hda_get_path_from_idx(codec, idx);
455 if (!path)
456 return;
457 memset(path, 0, sizeof(*path));
458}
459
460/* look for an empty DAC slot */
461static hda_nid_t look_for_dac(struct hda_codec *codec, hda_nid_t pin,
462 bool is_digital)
463{
464 struct hda_gen_spec *spec = codec->spec;
465 bool cap_digital;
466 int i;
467
468 for (i = 0; i < spec->num_all_dacs; i++) {
469 hda_nid_t nid = spec->all_dacs[i];
470 if (!nid || is_dac_already_used(codec, nid))
471 continue;
472 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
473 if (is_digital != cap_digital)
474 continue;
475 if (is_reachable_path(codec, nid, pin))
476 return nid;
197 } 477 }
478 return 0;
479}
480
481/* replace the channels in the composed amp value with the given number */
482static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
483{
484 val &= ~(0x3U << 16);
485 val |= chs << 16;
486 return val;
487}
488
489/* check whether the widget has the given amp capability for the direction */
490static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
491 int dir, unsigned int bits)
492{
493 if (!nid)
494 return false;
495 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
496 if (query_amp_caps(codec, nid, dir) & bits)
497 return true;
498 return false;
499}
500
501static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1,
502 hda_nid_t nid2, int dir)
503{
504 if (!(get_wcaps(codec, nid1) & (1 << (dir + 1))))
505 return !(get_wcaps(codec, nid2) & (1 << (dir + 1)));
506 return (query_amp_caps(codec, nid1, dir) ==
507 query_amp_caps(codec, nid2, dir));
508}
509
510#define nid_has_mute(codec, nid, dir) \
511 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
512#define nid_has_volume(codec, nid, dir) \
513 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
198 514
515/* look for a widget suitable for assigning a mute switch in the path */
516static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
517 struct nid_path *path)
518{
519 int i;
520
521 for (i = path->depth - 1; i >= 0; i--) {
522 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
523 return path->path[i];
524 if (i != path->depth - 1 && i != 0 &&
525 nid_has_mute(codec, path->path[i], HDA_INPUT))
526 return path->path[i];
527 }
199 return 0; 528 return 0;
200} 529}
201 530
531/* look for a widget suitable for assigning a volume ctl in the path */
532static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
533 struct nid_path *path)
534{
535 int i;
536
537 for (i = path->depth - 1; i >= 0; i--) {
538 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
539 return path->path[i];
540 }
541 return 0;
542}
202 543
203/* 544/*
204 * look for the node record for the given NID 545 * path activation / deactivation
205 */ 546 */
206/* FIXME: should avoid the braindead linear search */ 547
207static struct hda_gnode *hda_get_node(struct hda_gspec *spec, hda_nid_t nid) 548/* can have the amp-in capability? */
549static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
208{ 550{
209 struct hda_gnode *node; 551 hda_nid_t nid = path->path[idx];
552 unsigned int caps = get_wcaps(codec, nid);
553 unsigned int type = get_wcaps_type(caps);
210 554
211 list_for_each_entry(node, &spec->nid_list, list) { 555 if (!(caps & AC_WCAP_IN_AMP))
212 if (node->nid == nid) 556 return false;
213 return node; 557 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
558 return false;
559 return true;
560}
561
562/* can have the amp-out capability? */
563static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
564{
565 hda_nid_t nid = path->path[idx];
566 unsigned int caps = get_wcaps(codec, nid);
567 unsigned int type = get_wcaps_type(caps);
568
569 if (!(caps & AC_WCAP_OUT_AMP))
570 return false;
571 if (type == AC_WID_PIN && !idx) /* only for output pins */
572 return false;
573 return true;
574}
575
576/* check whether the given (nid,dir,idx) is active */
577static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
578 unsigned int dir, unsigned int idx)
579{
580 struct hda_gen_spec *spec = codec->spec;
581 int i, n;
582
583 for (n = 0; n < spec->paths.used; n++) {
584 struct nid_path *path = snd_array_elem(&spec->paths, n);
585 if (!path->active)
586 continue;
587 for (i = 0; i < path->depth; i++) {
588 if (path->path[i] == nid) {
589 if (dir == HDA_OUTPUT || path->idx[i] == idx)
590 return true;
591 break;
592 }
593 }
214 } 594 }
215 return NULL; 595 return false;
216} 596}
217 597
218/* 598/* get the default amp value for the target state */
219 * unmute (and set max vol) the output amplifier 599static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
600 int dir, unsigned int caps, bool enable)
601{
602 unsigned int val = 0;
603
604 if (caps & AC_AMPCAP_NUM_STEPS) {
605 /* set to 0dB */
606 if (enable)
607 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
608 }
609 if (caps & AC_AMPCAP_MUTE) {
610 if (!enable)
611 val |= HDA_AMP_MUTE;
612 }
613 return val;
614}
615
616/* initialize the amp value (only at the first time) */
617static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
618{
619 unsigned int caps = query_amp_caps(codec, nid, dir);
620 int val = get_amp_val_to_activate(codec, nid, dir, caps, false);
621 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
622}
623
624/* calculate amp value mask we can modify;
625 * if the given amp is controlled by mixers, don't touch it
220 */ 626 */
221static int unmute_output(struct hda_codec *codec, struct hda_gnode *node) 627static unsigned int get_amp_mask_to_modify(struct hda_codec *codec,
222{ 628 hda_nid_t nid, int dir, int idx,
223 unsigned int val, ofs; 629 unsigned int caps)
224 snd_printdd("UNMUTE OUT: NID=0x%x\n", node->nid); 630{
225 val = (node->amp_out_caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; 631 unsigned int mask = 0xff;
226 ofs = (node->amp_out_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; 632
227 if (val >= ofs) 633 if (caps & AC_AMPCAP_MUTE) {
228 val -= ofs; 634 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL))
229 snd_hda_codec_amp_stereo(codec, node->nid, HDA_OUTPUT, 0, 0xff, val); 635 mask &= ~0x80;
230 return 0; 636 }
637 if (caps & AC_AMPCAP_NUM_STEPS) {
638 if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
639 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
640 mask &= ~0x7f;
641 }
642 return mask;
231} 643}
232 644
233/* 645static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
234 * unmute (and set max vol) the input amplifier 646 int idx, int idx_to_check, bool enable)
647{
648 unsigned int caps;
649 unsigned int mask, val;
650
651 if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
652 return;
653
654 caps = query_amp_caps(codec, nid, dir);
655 val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
656 mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
657 if (!mask)
658 return;
659
660 val &= mask;
661 snd_hda_codec_amp_stereo(codec, nid, dir, idx, mask, val);
662}
663
664static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
665 int i, bool enable)
666{
667 hda_nid_t nid = path->path[i];
668 init_amp(codec, nid, HDA_OUTPUT, 0);
669 activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
670}
671
672static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
673 int i, bool enable, bool add_aamix)
674{
675 struct hda_gen_spec *spec = codec->spec;
676 const hda_nid_t *conn;
677 int n, nums, idx;
678 int type;
679 hda_nid_t nid = path->path[i];
680
681 nums = snd_hda_get_conn_list(codec, nid, &conn);
682 type = get_wcaps_type(get_wcaps(codec, nid));
683 if (type == AC_WID_PIN ||
684 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
685 nums = 1;
686 idx = 0;
687 } else
688 idx = path->idx[i];
689
690 for (n = 0; n < nums; n++)
691 init_amp(codec, nid, HDA_INPUT, n);
692
693 /* here is a little bit tricky in comparison with activate_amp_out();
694 * when aa-mixer is available, we need to enable the path as well
695 */
696 for (n = 0; n < nums; n++) {
697 if (n != idx && (!add_aamix || conn[n] != spec->mixer_merge_nid))
698 continue;
699 activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
700 }
701}
702
703/* activate or deactivate the given path
704 * if @add_aamix is set, enable the input from aa-mix NID as well (if any)
235 */ 705 */
236static int unmute_input(struct hda_codec *codec, struct hda_gnode *node, unsigned int index) 706void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
237{ 707 bool enable, bool add_aamix)
238 unsigned int val, ofs; 708{
239 snd_printdd("UNMUTE IN: NID=0x%x IDX=0x%x\n", node->nid, index); 709 struct hda_gen_spec *spec = codec->spec;
240 val = (node->amp_in_caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; 710 int i;
241 ofs = (node->amp_in_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; 711
242 if (val >= ofs) 712 if (!enable)
243 val -= ofs; 713 path->active = false;
244 snd_hda_codec_amp_stereo(codec, node->nid, HDA_INPUT, index, 0xff, val); 714
245 return 0; 715 for (i = path->depth - 1; i >= 0; i--) {
716 hda_nid_t nid = path->path[i];
717 if (enable && spec->power_down_unused) {
718 /* make sure the widget is powered up */
719 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0))
720 snd_hda_codec_write(codec, nid, 0,
721 AC_VERB_SET_POWER_STATE,
722 AC_PWRST_D0);
723 }
724 if (enable && path->multi[i])
725 snd_hda_codec_write_cache(codec, nid, 0,
726 AC_VERB_SET_CONNECT_SEL,
727 path->idx[i]);
728 if (has_amp_in(codec, path, i))
729 activate_amp_in(codec, path, i, enable, add_aamix);
730 if (has_amp_out(codec, path, i))
731 activate_amp_out(codec, path, i, enable);
732 }
733
734 if (enable)
735 path->active = true;
246} 736}
737EXPORT_SYMBOL_HDA(snd_hda_activate_path);
738
739/* if the given path is inactive, put widgets into D3 (only if suitable) */
740static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
741{
742 struct hda_gen_spec *spec = codec->spec;
743 bool changed;
744 int i;
745
746 if (!spec->power_down_unused || path->active)
747 return;
748
749 for (i = 0; i < path->depth; i++) {
750 hda_nid_t nid = path->path[i];
751 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D3)) {
752 snd_hda_codec_write(codec, nid, 0,
753 AC_VERB_SET_POWER_STATE,
754 AC_PWRST_D3);
755 changed = true;
756 }
757 }
758
759 if (changed) {
760 msleep(10);
761 snd_hda_codec_read(codec, path->path[0], 0,
762 AC_VERB_GET_POWER_STATE, 0);
763 }
764}
765
766/* turn on/off EAPD on the given pin */
767static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
768{
769 struct hda_gen_spec *spec = codec->spec;
770 if (spec->own_eapd_ctl ||
771 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
772 return;
773 if (codec->inv_eapd)
774 enable = !enable;
775 snd_hda_codec_update_cache(codec, pin, 0,
776 AC_VERB_SET_EAPD_BTLENABLE,
777 enable ? 0x02 : 0x00);
778}
779
780/* re-initialize the path specified by the given path index */
781static void resume_path_from_idx(struct hda_codec *codec, int path_idx)
782{
783 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
784 if (path)
785 snd_hda_activate_path(codec, path, path->active, false);
786}
787
247 788
248/* 789/*
249 * select the input connection of the given node. 790 * Helper functions for creating mixer ctl elements
250 */ 791 */
251static int select_input_connection(struct hda_codec *codec, struct hda_gnode *node, 792
252 unsigned int index) 793enum {
794 HDA_CTL_WIDGET_VOL,
795 HDA_CTL_WIDGET_MUTE,
796 HDA_CTL_BIND_MUTE,
797};
798static const struct snd_kcontrol_new control_templates[] = {
799 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
800 HDA_CODEC_MUTE(NULL, 0, 0, 0),
801 HDA_BIND_MUTE(NULL, 0, 0, 0),
802};
803
804/* add dynamic controls from template */
805static struct snd_kcontrol_new *
806add_control(struct hda_gen_spec *spec, int type, const char *name,
807 int cidx, unsigned long val)
253{ 808{
254 snd_printdd("CONNECT: NID=0x%x IDX=0x%x\n", node->nid, index); 809 struct snd_kcontrol_new *knew;
255 return snd_hda_codec_write_cache(codec, node->nid, 0, 810
256 AC_VERB_SET_CONNECT_SEL, index); 811 knew = snd_hda_gen_add_kctl(spec, name, &control_templates[type]);
812 if (!knew)
813 return NULL;
814 knew->index = cidx;
815 if (get_amp_nid_(val))
816 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
817 knew->private_value = val;
818 return knew;
257} 819}
258 820
259/* 821static int add_control_with_pfx(struct hda_gen_spec *spec, int type,
260 * clear checked flag of each node in the node list 822 const char *pfx, const char *dir,
823 const char *sfx, int cidx, unsigned long val)
824{
825 char name[32];
826 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
827 if (!add_control(spec, type, name, cidx, val))
828 return -ENOMEM;
829 return 0;
830}
831
832#define add_pb_vol_ctrl(spec, type, pfx, val) \
833 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
834#define add_pb_sw_ctrl(spec, type, pfx, val) \
835 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
836#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
837 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
838#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
839 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
840
841static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx,
842 unsigned int chs, struct nid_path *path)
843{
844 unsigned int val;
845 if (!path)
846 return 0;
847 val = path->ctls[NID_PATH_VOL_CTL];
848 if (!val)
849 return 0;
850 val = amp_val_replace_channels(val, chs);
851 return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val);
852}
853
854/* return the channel bits suitable for the given path->ctls[] */
855static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
856 int type)
857{
858 int chs = 1; /* mono (left only) */
859 if (path) {
860 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
861 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
862 chs = 3; /* stereo */
863 }
864 return chs;
865}
866
867static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx,
868 struct nid_path *path)
869{
870 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
871 return add_vol_ctl(codec, pfx, cidx, chs, path);
872}
873
874/* create a mute-switch for the given mixer widget;
875 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
261 */ 876 */
262static void clear_check_flags(struct hda_gspec *spec) 877static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx,
878 unsigned int chs, struct nid_path *path)
879{
880 unsigned int val;
881 int type = HDA_CTL_WIDGET_MUTE;
882
883 if (!path)
884 return 0;
885 val = path->ctls[NID_PATH_MUTE_CTL];
886 if (!val)
887 return 0;
888 val = amp_val_replace_channels(val, chs);
889 if (get_amp_direction_(val) == HDA_INPUT) {
890 hda_nid_t nid = get_amp_nid_(val);
891 int nums = snd_hda_get_num_conns(codec, nid);
892 if (nums > 1) {
893 type = HDA_CTL_BIND_MUTE;
894 val |= nums << 19;
895 }
896 }
897 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
898}
899
900static int add_stereo_sw(struct hda_codec *codec, const char *pfx,
901 int cidx, struct nid_path *path)
902{
903 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
904 return add_sw_ctl(codec, pfx, cidx, chs, path);
905}
906
907/* any ctl assigned to the path with the given index? */
908static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type)
909{
910 struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx);
911 return path && path->ctls[ctl_type];
912}
913
914static const char * const channel_name[4] = {
915 "Front", "Surround", "CLFE", "Side"
916};
917
918/* give some appropriate ctl name prefix for the given line out channel */
919static const char *get_line_out_pfx(struct hda_codec *codec, int ch,
920 int *index, int ctl_type)
263{ 921{
264 struct hda_gnode *node; 922 struct hda_gen_spec *spec = codec->spec;
923 struct auto_pin_cfg *cfg = &spec->autocfg;
924
925 *index = 0;
926 if (cfg->line_outs == 1 && !spec->multi_ios &&
927 !cfg->hp_outs && !cfg->speaker_outs)
928 return spec->vmaster_mute.hook ? "PCM" : "Master";
929
930 /* if there is really a single DAC used in the whole output paths,
931 * use it master (or "PCM" if a vmaster hook is present)
932 */
933 if (spec->multiout.num_dacs == 1 && !spec->mixer_nid &&
934 !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0])
935 return spec->vmaster_mute.hook ? "PCM" : "Master";
936
937 /* multi-io channels */
938 if (ch >= cfg->line_outs)
939 return channel_name[ch];
940
941 switch (cfg->line_out_type) {
942 case AUTO_PIN_SPEAKER_OUT:
943 /* if the primary channel vol/mute is shared with HP volume,
944 * don't name it as Speaker
945 */
946 if (!ch && cfg->hp_outs &&
947 !path_has_mixer(codec, spec->hp_paths[0], ctl_type))
948 break;
949 if (cfg->line_outs == 1)
950 return "Speaker";
951 if (cfg->line_outs == 2)
952 return ch ? "Bass Speaker" : "Speaker";
953 break;
954 case AUTO_PIN_HP_OUT:
955 /* if the primary channel vol/mute is shared with spk volume,
956 * don't name it as Headphone
957 */
958 if (!ch && cfg->speaker_outs &&
959 !path_has_mixer(codec, spec->speaker_paths[0], ctl_type))
960 break;
961 /* for multi-io case, only the primary out */
962 if (ch && spec->multi_ios)
963 break;
964 *index = ch;
965 return "Headphone";
966 }
967
968 /* for a single channel output, we don't have to name the channel */
969 if (cfg->line_outs == 1 && !spec->multi_ios)
970 return "PCM";
265 971
266 list_for_each_entry(node, &spec->nid_list, list) { 972 if (ch >= ARRAY_SIZE(channel_name)) {
267 node->checked = 0; 973 snd_BUG();
974 return "PCM";
268 } 975 }
976
977 return channel_name[ch];
269} 978}
270 979
271/* 980/*
272 * parse the output path recursively until reach to an audio output widget 981 * Parse output paths
982 */
983
984/* badness definition */
985enum {
986 /* No primary DAC is found for the main output */
987 BAD_NO_PRIMARY_DAC = 0x10000,
988 /* No DAC is found for the extra output */
989 BAD_NO_DAC = 0x4000,
990 /* No possible multi-ios */
991 BAD_MULTI_IO = 0x120,
992 /* No individual DAC for extra output */
993 BAD_NO_EXTRA_DAC = 0x102,
994 /* No individual DAC for extra surrounds */
995 BAD_NO_EXTRA_SURR_DAC = 0x101,
996 /* Primary DAC shared with main surrounds */
997 BAD_SHARED_SURROUND = 0x100,
998 /* Primary DAC shared with main CLFE */
999 BAD_SHARED_CLFE = 0x10,
1000 /* Primary DAC shared with extra surrounds */
1001 BAD_SHARED_EXTRA_SURROUND = 0x10,
1002 /* Volume widget is shared */
1003 BAD_SHARED_VOL = 0x10,
1004};
1005
1006/* look for widgets in the given path which are appropriate for
1007 * volume and mute controls, and assign the values to ctls[].
273 * 1008 *
274 * returns 0 if not found, 1 if found, or a negative error code. 1009 * When no appropriate widget is found in the path, the badness value
1010 * is incremented depending on the situation. The function returns the
1011 * total badness for both volume and mute controls.
275 */ 1012 */
276static int parse_output_path(struct hda_codec *codec, struct hda_gspec *spec, 1013static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path)
277 struct hda_gnode *node, int dac_idx)
278{ 1014{
279 int i, err; 1015 hda_nid_t nid;
280 struct hda_gnode *child; 1016 unsigned int val;
1017 int badness = 0;
1018
1019 if (!path)
1020 return BAD_SHARED_VOL * 2;
1021
1022 if (path->ctls[NID_PATH_VOL_CTL] ||
1023 path->ctls[NID_PATH_MUTE_CTL])
1024 return 0; /* already evaluated */
281 1025
282 if (node->checked) 1026 nid = look_for_out_vol_nid(codec, path);
1027 if (nid) {
1028 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
1029 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
1030 badness += BAD_SHARED_VOL;
1031 else
1032 path->ctls[NID_PATH_VOL_CTL] = val;
1033 } else
1034 badness += BAD_SHARED_VOL;
1035 nid = look_for_out_mute_nid(codec, path);
1036 if (nid) {
1037 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
1038 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
1039 nid_has_mute(codec, nid, HDA_OUTPUT))
1040 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
1041 else
1042 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
1043 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
1044 badness += BAD_SHARED_VOL;
1045 else
1046 path->ctls[NID_PATH_MUTE_CTL] = val;
1047 } else
1048 badness += BAD_SHARED_VOL;
1049 return badness;
1050}
1051
1052struct badness_table {
1053 int no_primary_dac; /* no primary DAC */
1054 int no_dac; /* no secondary DACs */
1055 int shared_primary; /* primary DAC is shared with main output */
1056 int shared_surr; /* secondary DAC shared with main or primary */
1057 int shared_clfe; /* third DAC shared with main or primary */
1058 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
1059};
1060
1061static struct badness_table main_out_badness = {
1062 .no_primary_dac = BAD_NO_PRIMARY_DAC,
1063 .no_dac = BAD_NO_DAC,
1064 .shared_primary = BAD_NO_PRIMARY_DAC,
1065 .shared_surr = BAD_SHARED_SURROUND,
1066 .shared_clfe = BAD_SHARED_CLFE,
1067 .shared_surr_main = BAD_SHARED_SURROUND,
1068};
1069
1070static struct badness_table extra_out_badness = {
1071 .no_primary_dac = BAD_NO_DAC,
1072 .no_dac = BAD_NO_DAC,
1073 .shared_primary = BAD_NO_EXTRA_DAC,
1074 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
1075 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
1076 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
1077};
1078
1079/* get the DAC of the primary output corresponding to the given array index */
1080static hda_nid_t get_primary_out(struct hda_codec *codec, int idx)
1081{
1082 struct hda_gen_spec *spec = codec->spec;
1083 struct auto_pin_cfg *cfg = &spec->autocfg;
1084
1085 if (cfg->line_outs > idx)
1086 return spec->private_dac_nids[idx];
1087 idx -= cfg->line_outs;
1088 if (spec->multi_ios > idx)
1089 return spec->multi_io[idx].dac;
1090 return 0;
1091}
1092
1093/* return the DAC if it's reachable, otherwise zero */
1094static inline hda_nid_t try_dac(struct hda_codec *codec,
1095 hda_nid_t dac, hda_nid_t pin)
1096{
1097 return is_reachable_path(codec, dac, pin) ? dac : 0;
1098}
1099
1100/* try to assign DACs to pins and return the resultant badness */
1101static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1102 const hda_nid_t *pins, hda_nid_t *dacs,
1103 int *path_idx,
1104 const struct badness_table *bad)
1105{
1106 struct hda_gen_spec *spec = codec->spec;
1107 int i, j;
1108 int badness = 0;
1109 hda_nid_t dac;
1110
1111 if (!num_outs)
283 return 0; 1112 return 0;
284 1113
285 node->checked = 1; 1114 for (i = 0; i < num_outs; i++) {
286 if (node->type == AC_WID_AUD_OUT) { 1115 struct nid_path *path;
287 if (node->wid_caps & AC_WCAP_DIGITAL) { 1116 hda_nid_t pin = pins[i];
288 snd_printdd("Skip Digital OUT node %x\n", node->nid); 1117
289 return 0; 1118 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1119 if (path) {
1120 badness += assign_out_path_ctls(codec, path);
1121 continue;
1122 }
1123
1124 dacs[i] = look_for_dac(codec, pin, false);
1125 if (!dacs[i] && !i) {
1126 /* try to steal the DAC of surrounds for the front */
1127 for (j = 1; j < num_outs; j++) {
1128 if (is_reachable_path(codec, dacs[j], pin)) {
1129 dacs[0] = dacs[j];
1130 dacs[j] = 0;
1131 invalidate_nid_path(codec, path_idx[j]);
1132 path_idx[j] = 0;
1133 break;
1134 }
1135 }
1136 }
1137 dac = dacs[i];
1138 if (!dac) {
1139 if (num_outs > 2)
1140 dac = try_dac(codec, get_primary_out(codec, i), pin);
1141 if (!dac)
1142 dac = try_dac(codec, dacs[0], pin);
1143 if (!dac)
1144 dac = try_dac(codec, get_primary_out(codec, i), pin);
1145 if (dac) {
1146 if (!i)
1147 badness += bad->shared_primary;
1148 else if (i == 1)
1149 badness += bad->shared_surr;
1150 else
1151 badness += bad->shared_clfe;
1152 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
1153 dac = spec->private_dac_nids[0];
1154 badness += bad->shared_surr_main;
1155 } else if (!i)
1156 badness += bad->no_primary_dac;
1157 else
1158 badness += bad->no_dac;
290 } 1159 }
291 snd_printdd("AUD_OUT found %x\n", node->nid); 1160 if (!dac)
292 if (spec->dac_node[dac_idx]) { 1161 continue;
293 /* already DAC node is assigned, just unmute & connect */ 1162 path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid);
294 return node == spec->dac_node[dac_idx]; 1163 if (!path && !i && spec->mixer_nid) {
1164 /* try with aamix */
1165 path = snd_hda_add_new_path(codec, dac, pin, 0);
295 } 1166 }
296 spec->dac_node[dac_idx] = node; 1167 if (!path) {
297 if ((node->wid_caps & AC_WCAP_OUT_AMP) && 1168 dac = dacs[i] = 0;
298 spec->pcm_vol_nodes < MAX_PCM_VOLS) { 1169 badness += bad->no_dac;
299 spec->pcm_vol[spec->pcm_vol_nodes].node = node; 1170 } else {
300 spec->pcm_vol[spec->pcm_vol_nodes].index = 0; 1171 /* print_nid_path("output", path); */
301 spec->pcm_vol_nodes++; 1172 path->active = true;
1173 path_idx[i] = snd_hda_get_path_idx(codec, path);
1174 badness += assign_out_path_ctls(codec, path);
302 } 1175 }
303 return 1; /* found */
304 } 1176 }
305 1177
306 for (i = 0; i < node->nconns; i++) { 1178 return badness;
307 child = hda_get_node(spec, node->conn_list[i]); 1179}
308 if (! child) 1180
1181/* return NID if the given pin has only a single connection to a certain DAC */
1182static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
1183{
1184 struct hda_gen_spec *spec = codec->spec;
1185 int i;
1186 hda_nid_t nid_found = 0;
1187
1188 for (i = 0; i < spec->num_all_dacs; i++) {
1189 hda_nid_t nid = spec->all_dacs[i];
1190 if (!nid || is_dac_already_used(codec, nid))
309 continue; 1191 continue;
310 err = parse_output_path(codec, spec, child, dac_idx); 1192 if (is_reachable_path(codec, nid, pin)) {
311 if (err < 0) 1193 if (nid_found)
312 return err; 1194 return 0;
313 else if (err > 0) { 1195 nid_found = nid;
314 /* found one,
315 * select the path, unmute both input and output
316 */
317 if (node->nconns > 1)
318 select_input_connection(codec, node, i);
319 unmute_input(codec, node, i);
320 unmute_output(codec, node);
321 if (spec->dac_node[dac_idx] &&
322 spec->pcm_vol_nodes < MAX_PCM_VOLS &&
323 !(spec->dac_node[dac_idx]->wid_caps &
324 AC_WCAP_OUT_AMP)) {
325 if ((node->wid_caps & AC_WCAP_IN_AMP) ||
326 (node->wid_caps & AC_WCAP_OUT_AMP)) {
327 int n = spec->pcm_vol_nodes;
328 spec->pcm_vol[n].node = node;
329 spec->pcm_vol[n].index = i;
330 spec->pcm_vol_nodes++;
331 }
332 }
333 return 1;
334 } 1196 }
335 } 1197 }
336 return 0; 1198 return nid_found;
1199}
1200
1201/* check whether the given pin can be a multi-io pin */
1202static bool can_be_multiio_pin(struct hda_codec *codec,
1203 unsigned int location, hda_nid_t nid)
1204{
1205 unsigned int defcfg, caps;
1206
1207 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1208 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
1209 return false;
1210 if (location && get_defcfg_location(defcfg) != location)
1211 return false;
1212 caps = snd_hda_query_pin_caps(codec, nid);
1213 if (!(caps & AC_PINCAP_OUT))
1214 return false;
1215 return true;
1216}
1217
1218/* count the number of input pins that are capable to be multi-io */
1219static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin)
1220{
1221 struct hda_gen_spec *spec = codec->spec;
1222 struct auto_pin_cfg *cfg = &spec->autocfg;
1223 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1224 unsigned int location = get_defcfg_location(defcfg);
1225 int type, i;
1226 int num_pins = 0;
1227
1228 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
1229 for (i = 0; i < cfg->num_inputs; i++) {
1230 if (cfg->inputs[i].type != type)
1231 continue;
1232 if (can_be_multiio_pin(codec, location,
1233 cfg->inputs[i].pin))
1234 num_pins++;
1235 }
1236 }
1237 return num_pins;
337} 1238}
338 1239
339/* 1240/*
340 * Look for the output PIN widget with the given jack type 1241 * multi-io helper
341 * and parse the output path to that PIN.
342 * 1242 *
343 * Returns the PIN node when the path to DAC is established. 1243 * When hardwired is set, try to fill ony hardwired pins, and returns
1244 * zero if any pins are filled, non-zero if nothing found.
1245 * When hardwired is off, try to fill possible input pins, and returns
1246 * the badness value.
344 */ 1247 */
345static struct hda_gnode *parse_output_jack(struct hda_codec *codec, 1248static int fill_multi_ios(struct hda_codec *codec,
346 struct hda_gspec *spec, 1249 hda_nid_t reference_pin,
347 int jack_type) 1250 bool hardwired)
348{ 1251{
349 struct hda_gnode *node; 1252 struct hda_gen_spec *spec = codec->spec;
350 int err; 1253 struct auto_pin_cfg *cfg = &spec->autocfg;
1254 int type, i, j, num_pins, old_pins;
1255 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
1256 unsigned int location = get_defcfg_location(defcfg);
1257 int badness = 0;
1258 struct nid_path *path;
351 1259
352 list_for_each_entry(node, &spec->nid_list, list) { 1260 old_pins = spec->multi_ios;
353 if (node->type != AC_WID_PIN) 1261 if (old_pins >= 2)
354 continue; 1262 goto end_fill;
355 /* output capable? */ 1263
356 if (! (node->pin_caps & AC_PINCAP_OUT)) 1264 num_pins = count_multiio_pins(codec, reference_pin);
357 continue; 1265 if (num_pins < 2)
358 if (defcfg_port_conn(node) == AC_JACK_PORT_NONE) 1266 goto end_fill;
359 continue; /* unconnected */ 1267
360 if (jack_type >= 0) { 1268 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
361 if (jack_type != defcfg_type(node)) 1269 for (i = 0; i < cfg->num_inputs; i++) {
1270 hda_nid_t nid = cfg->inputs[i].pin;
1271 hda_nid_t dac = 0;
1272
1273 if (cfg->inputs[i].type != type)
362 continue; 1274 continue;
363 if (node->wid_caps & AC_WCAP_DIGITAL) 1275 if (!can_be_multiio_pin(codec, location, nid))
364 continue; /* skip SPDIF */ 1276 continue;
365 } else { 1277 for (j = 0; j < spec->multi_ios; j++) {
366 /* output as default? */ 1278 if (nid == spec->multi_io[j].pin)
367 if (! (node->pin_ctl & AC_PINCTL_OUT_EN)) 1279 break;
1280 }
1281 if (j < spec->multi_ios)
368 continue; 1282 continue;
1283
1284 if (hardwired)
1285 dac = get_dac_if_single(codec, nid);
1286 else if (!dac)
1287 dac = look_for_dac(codec, nid, false);
1288 if (!dac) {
1289 badness++;
1290 continue;
1291 }
1292 path = snd_hda_add_new_path(codec, dac, nid,
1293 -spec->mixer_nid);
1294 if (!path) {
1295 badness++;
1296 continue;
1297 }
1298 /* print_nid_path("multiio", path); */
1299 spec->multi_io[spec->multi_ios].pin = nid;
1300 spec->multi_io[spec->multi_ios].dac = dac;
1301 spec->out_paths[cfg->line_outs + spec->multi_ios] =
1302 snd_hda_get_path_idx(codec, path);
1303 spec->multi_ios++;
1304 if (spec->multi_ios >= 2)
1305 break;
1306 }
1307 }
1308 end_fill:
1309 if (badness)
1310 badness = BAD_MULTI_IO;
1311 if (old_pins == spec->multi_ios) {
1312 if (hardwired)
1313 return 1; /* nothing found */
1314 else
1315 return badness; /* no badness if nothing found */
1316 }
1317 if (!hardwired && spec->multi_ios < 2) {
1318 /* cancel newly assigned paths */
1319 spec->paths.used -= spec->multi_ios - old_pins;
1320 spec->multi_ios = old_pins;
1321 return badness;
1322 }
1323
1324 /* assign volume and mute controls */
1325 for (i = old_pins; i < spec->multi_ios; i++) {
1326 path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]);
1327 badness += assign_out_path_ctls(codec, path);
1328 }
1329
1330 return badness;
1331}
1332
1333/* map DACs for all pins in the list if they are single connections */
1334static bool map_singles(struct hda_codec *codec, int outs,
1335 const hda_nid_t *pins, hda_nid_t *dacs, int *path_idx)
1336{
1337 struct hda_gen_spec *spec = codec->spec;
1338 int i;
1339 bool found = false;
1340 for (i = 0; i < outs; i++) {
1341 struct nid_path *path;
1342 hda_nid_t dac;
1343 if (dacs[i])
1344 continue;
1345 dac = get_dac_if_single(codec, pins[i]);
1346 if (!dac)
1347 continue;
1348 path = snd_hda_add_new_path(codec, dac, pins[i],
1349 -spec->mixer_nid);
1350 if (!path && !i && spec->mixer_nid)
1351 path = snd_hda_add_new_path(codec, dac, pins[i], 0);
1352 if (path) {
1353 dacs[i] = dac;
1354 found = true;
1355 /* print_nid_path("output", path); */
1356 path->active = true;
1357 path_idx[i] = snd_hda_get_path_idx(codec, path);
369 } 1358 }
370 clear_check_flags(spec); 1359 }
371 err = parse_output_path(codec, spec, node, 0); 1360 return found;
1361}
1362
1363/* create a new path including aamix if available, and return its index */
1364static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1365{
1366 struct hda_gen_spec *spec = codec->spec;
1367 struct nid_path *path;
1368 hda_nid_t dac, pin;
1369
1370 path = snd_hda_get_path_from_idx(codec, path_idx);
1371 if (!path || !path->depth ||
1372 is_nid_contained(path, spec->mixer_nid))
1373 return 0;
1374 dac = path->path[0];
1375 pin = path->path[path->depth - 1];
1376 path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid);
1377 if (!path) {
1378 if (dac != spec->multiout.dac_nids[0])
1379 dac = spec->multiout.dac_nids[0];
1380 else if (spec->multiout.hp_out_nid[0])
1381 dac = spec->multiout.hp_out_nid[0];
1382 else if (spec->multiout.extra_out_nid[0])
1383 dac = spec->multiout.extra_out_nid[0];
1384 if (dac)
1385 path = snd_hda_add_new_path(codec, dac, pin,
1386 spec->mixer_nid);
1387 }
1388 if (!path)
1389 return 0;
1390 /* print_nid_path("output-aamix", path); */
1391 path->active = false; /* unused as default */
1392 return snd_hda_get_path_idx(codec, path);
1393}
1394
1395/* fill the empty entries in the dac array for speaker/hp with the
1396 * shared dac pointed by the paths
1397 */
1398static void refill_shared_dacs(struct hda_codec *codec, int num_outs,
1399 hda_nid_t *dacs, int *path_idx)
1400{
1401 struct nid_path *path;
1402 int i;
1403
1404 for (i = 0; i < num_outs; i++) {
1405 if (dacs[i])
1406 continue;
1407 path = snd_hda_get_path_from_idx(codec, path_idx[i]);
1408 if (!path)
1409 continue;
1410 dacs[i] = path->path[0];
1411 }
1412}
1413
1414/* fill in the dac_nids table from the parsed pin configuration */
1415static int fill_and_eval_dacs(struct hda_codec *codec,
1416 bool fill_hardwired,
1417 bool fill_mio_first)
1418{
1419 struct hda_gen_spec *spec = codec->spec;
1420 struct auto_pin_cfg *cfg = &spec->autocfg;
1421 int i, err, badness;
1422
1423 /* set num_dacs once to full for look_for_dac() */
1424 spec->multiout.num_dacs = cfg->line_outs;
1425 spec->multiout.dac_nids = spec->private_dac_nids;
1426 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
1427 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
1428 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
1429 spec->multi_ios = 0;
1430 snd_array_free(&spec->paths);
1431
1432 /* clear path indices */
1433 memset(spec->out_paths, 0, sizeof(spec->out_paths));
1434 memset(spec->hp_paths, 0, sizeof(spec->hp_paths));
1435 memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths));
1436 memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths));
1437 memset(spec->digout_paths, 0, sizeof(spec->digout_paths));
1438 memset(spec->input_paths, 0, sizeof(spec->input_paths));
1439 memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths));
1440 memset(&spec->digin_path, 0, sizeof(spec->digin_path));
1441
1442 badness = 0;
1443
1444 /* fill hard-wired DACs first */
1445 if (fill_hardwired) {
1446 bool mapped;
1447 do {
1448 mapped = map_singles(codec, cfg->line_outs,
1449 cfg->line_out_pins,
1450 spec->private_dac_nids,
1451 spec->out_paths);
1452 mapped |= map_singles(codec, cfg->hp_outs,
1453 cfg->hp_pins,
1454 spec->multiout.hp_out_nid,
1455 spec->hp_paths);
1456 mapped |= map_singles(codec, cfg->speaker_outs,
1457 cfg->speaker_pins,
1458 spec->multiout.extra_out_nid,
1459 spec->speaker_paths);
1460 if (fill_mio_first && cfg->line_outs == 1 &&
1461 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1462 err = fill_multi_ios(codec, cfg->line_out_pins[0], true);
1463 if (!err)
1464 mapped = true;
1465 }
1466 } while (mapped);
1467 }
1468
1469 badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins,
1470 spec->private_dac_nids, spec->out_paths,
1471 &main_out_badness);
1472
1473 if (fill_mio_first &&
1474 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1475 /* try to fill multi-io first */
1476 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
1477 if (err < 0)
1478 return err;
1479 /* we don't count badness at this stage yet */
1480 }
1481
1482 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
1483 err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins,
1484 spec->multiout.hp_out_nid,
1485 spec->hp_paths,
1486 &extra_out_badness);
1487 if (err < 0)
1488 return err;
1489 badness += err;
1490 }
1491 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1492 err = try_assign_dacs(codec, cfg->speaker_outs,
1493 cfg->speaker_pins,
1494 spec->multiout.extra_out_nid,
1495 spec->speaker_paths,
1496 &extra_out_badness);
1497 if (err < 0)
1498 return err;
1499 badness += err;
1500 }
1501 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1502 err = fill_multi_ios(codec, cfg->line_out_pins[0], false);
372 if (err < 0) 1503 if (err < 0)
373 return NULL; 1504 return err;
374 if (! err && spec->out_pin_node[0]) { 1505 badness += err;
375 err = parse_output_path(codec, spec, node, 1); 1506 }
1507
1508 if (spec->mixer_nid) {
1509 spec->aamix_out_paths[0] =
1510 check_aamix_out_path(codec, spec->out_paths[0]);
1511 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1512 spec->aamix_out_paths[1] =
1513 check_aamix_out_path(codec, spec->hp_paths[0]);
1514 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1515 spec->aamix_out_paths[2] =
1516 check_aamix_out_path(codec, spec->speaker_paths[0]);
1517 }
1518
1519 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
1520 if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2)
1521 spec->multi_ios = 1; /* give badness */
1522
1523 /* re-count num_dacs and squash invalid entries */
1524 spec->multiout.num_dacs = 0;
1525 for (i = 0; i < cfg->line_outs; i++) {
1526 if (spec->private_dac_nids[i])
1527 spec->multiout.num_dacs++;
1528 else {
1529 memmove(spec->private_dac_nids + i,
1530 spec->private_dac_nids + i + 1,
1531 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
1532 spec->private_dac_nids[cfg->line_outs - 1] = 0;
1533 }
1534 }
1535
1536 spec->ext_channel_count = spec->min_channel_count =
1537 spec->multiout.num_dacs * 2;
1538
1539 if (spec->multi_ios == 2) {
1540 for (i = 0; i < 2; i++)
1541 spec->private_dac_nids[spec->multiout.num_dacs++] =
1542 spec->multi_io[i].dac;
1543 } else if (spec->multi_ios) {
1544 spec->multi_ios = 0;
1545 badness += BAD_MULTI_IO;
1546 }
1547
1548 /* re-fill the shared DAC for speaker / headphone */
1549 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1550 refill_shared_dacs(codec, cfg->hp_outs,
1551 spec->multiout.hp_out_nid,
1552 spec->hp_paths);
1553 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1554 refill_shared_dacs(codec, cfg->speaker_outs,
1555 spec->multiout.extra_out_nid,
1556 spec->speaker_paths);
1557
1558 return badness;
1559}
1560
1561#define DEBUG_BADNESS
1562
1563#ifdef DEBUG_BADNESS
1564#define debug_badness snd_printdd
1565#else
1566#define debug_badness(...)
1567#endif
1568
1569#ifdef DEBUG_BADNESS
1570static inline void print_nid_path_idx(struct hda_codec *codec,
1571 const char *pfx, int idx)
1572{
1573 struct nid_path *path;
1574
1575 path = snd_hda_get_path_from_idx(codec, idx);
1576 if (path)
1577 print_nid_path(pfx, path);
1578}
1579
1580static void debug_show_configs(struct hda_codec *codec,
1581 struct auto_pin_cfg *cfg)
1582{
1583 struct hda_gen_spec *spec = codec->spec;
1584 static const char * const lo_type[3] = { "LO", "SP", "HP" };
1585 int i;
1586
1587 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x (type %s)\n",
1588 cfg->line_out_pins[0], cfg->line_out_pins[1],
1589 cfg->line_out_pins[2], cfg->line_out_pins[3],
1590 spec->multiout.dac_nids[0],
1591 spec->multiout.dac_nids[1],
1592 spec->multiout.dac_nids[2],
1593 spec->multiout.dac_nids[3],
1594 lo_type[cfg->line_out_type]);
1595 for (i = 0; i < cfg->line_outs; i++)
1596 print_nid_path_idx(codec, " out", spec->out_paths[i]);
1597 if (spec->multi_ios > 0)
1598 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
1599 spec->multi_ios,
1600 spec->multi_io[0].pin, spec->multi_io[1].pin,
1601 spec->multi_io[0].dac, spec->multi_io[1].dac);
1602 for (i = 0; i < spec->multi_ios; i++)
1603 print_nid_path_idx(codec, " mio",
1604 spec->out_paths[cfg->line_outs + i]);
1605 if (cfg->hp_outs)
1606 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1607 cfg->hp_pins[0], cfg->hp_pins[1],
1608 cfg->hp_pins[2], cfg->hp_pins[3],
1609 spec->multiout.hp_out_nid[0],
1610 spec->multiout.hp_out_nid[1],
1611 spec->multiout.hp_out_nid[2],
1612 spec->multiout.hp_out_nid[3]);
1613 for (i = 0; i < cfg->hp_outs; i++)
1614 print_nid_path_idx(codec, " hp ", spec->hp_paths[i]);
1615 if (cfg->speaker_outs)
1616 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1617 cfg->speaker_pins[0], cfg->speaker_pins[1],
1618 cfg->speaker_pins[2], cfg->speaker_pins[3],
1619 spec->multiout.extra_out_nid[0],
1620 spec->multiout.extra_out_nid[1],
1621 spec->multiout.extra_out_nid[2],
1622 spec->multiout.extra_out_nid[3]);
1623 for (i = 0; i < cfg->speaker_outs; i++)
1624 print_nid_path_idx(codec, " spk", spec->speaker_paths[i]);
1625 for (i = 0; i < 3; i++)
1626 print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]);
1627}
1628#else
1629#define debug_show_configs(codec, cfg) /* NOP */
1630#endif
1631
1632/* find all available DACs of the codec */
1633static void fill_all_dac_nids(struct hda_codec *codec)
1634{
1635 struct hda_gen_spec *spec = codec->spec;
1636 int i;
1637 hda_nid_t nid = codec->start_nid;
1638
1639 spec->num_all_dacs = 0;
1640 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
1641 for (i = 0; i < codec->num_nodes; i++, nid++) {
1642 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1643 continue;
1644 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1645 snd_printk(KERN_ERR "hda: Too many DACs!\n");
1646 break;
1647 }
1648 spec->all_dacs[spec->num_all_dacs++] = nid;
1649 }
1650}
1651
1652static int parse_output_paths(struct hda_codec *codec)
1653{
1654 struct hda_gen_spec *spec = codec->spec;
1655 struct auto_pin_cfg *cfg = &spec->autocfg;
1656 struct auto_pin_cfg *best_cfg;
1657 unsigned int val;
1658 int best_badness = INT_MAX;
1659 int badness;
1660 bool fill_hardwired = true, fill_mio_first = true;
1661 bool best_wired = true, best_mio = true;
1662 bool hp_spk_swapped = false;
1663
1664 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
1665 if (!best_cfg)
1666 return -ENOMEM;
1667 *best_cfg = *cfg;
1668
1669 for (;;) {
1670 badness = fill_and_eval_dacs(codec, fill_hardwired,
1671 fill_mio_first);
1672 if (badness < 0) {
1673 kfree(best_cfg);
1674 return badness;
1675 }
1676 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
1677 cfg->line_out_type, fill_hardwired, fill_mio_first,
1678 badness);
1679 debug_show_configs(codec, cfg);
1680 if (badness < best_badness) {
1681 best_badness = badness;
1682 *best_cfg = *cfg;
1683 best_wired = fill_hardwired;
1684 best_mio = fill_mio_first;
1685 }
1686 if (!badness)
1687 break;
1688 fill_mio_first = !fill_mio_first;
1689 if (!fill_mio_first)
1690 continue;
1691 fill_hardwired = !fill_hardwired;
1692 if (!fill_hardwired)
1693 continue;
1694 if (hp_spk_swapped)
1695 break;
1696 hp_spk_swapped = true;
1697 if (cfg->speaker_outs > 0 &&
1698 cfg->line_out_type == AUTO_PIN_HP_OUT) {
1699 cfg->hp_outs = cfg->line_outs;
1700 memcpy(cfg->hp_pins, cfg->line_out_pins,
1701 sizeof(cfg->hp_pins));
1702 cfg->line_outs = cfg->speaker_outs;
1703 memcpy(cfg->line_out_pins, cfg->speaker_pins,
1704 sizeof(cfg->speaker_pins));
1705 cfg->speaker_outs = 0;
1706 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
1707 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
1708 fill_hardwired = true;
1709 continue;
1710 }
1711 if (cfg->hp_outs > 0 &&
1712 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
1713 cfg->speaker_outs = cfg->line_outs;
1714 memcpy(cfg->speaker_pins, cfg->line_out_pins,
1715 sizeof(cfg->speaker_pins));
1716 cfg->line_outs = cfg->hp_outs;
1717 memcpy(cfg->line_out_pins, cfg->hp_pins,
1718 sizeof(cfg->hp_pins));
1719 cfg->hp_outs = 0;
1720 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
1721 cfg->line_out_type = AUTO_PIN_HP_OUT;
1722 fill_hardwired = true;
1723 continue;
1724 }
1725 break;
1726 }
1727
1728 if (badness) {
1729 debug_badness("==> restoring best_cfg\n");
1730 *cfg = *best_cfg;
1731 fill_and_eval_dacs(codec, best_wired, best_mio);
1732 }
1733 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
1734 cfg->line_out_type, best_wired, best_mio);
1735 debug_show_configs(codec, cfg);
1736
1737 if (cfg->line_out_pins[0]) {
1738 struct nid_path *path;
1739 path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]);
1740 if (path)
1741 spec->vmaster_nid = look_for_out_vol_nid(codec, path);
1742 if (spec->vmaster_nid)
1743 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1744 HDA_OUTPUT, spec->vmaster_tlv);
1745 }
1746
1747 /* set initial pinctl targets */
1748 if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT)
1749 val = PIN_HP;
1750 else
1751 val = PIN_OUT;
1752 set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val);
1753 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1754 set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP);
1755 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
1756 val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT;
1757 set_pin_targets(codec, cfg->speaker_outs,
1758 cfg->speaker_pins, val);
1759 }
1760
1761 kfree(best_cfg);
1762 return 0;
1763}
1764
1765/* add playback controls from the parsed DAC table */
1766static int create_multi_out_ctls(struct hda_codec *codec,
1767 const struct auto_pin_cfg *cfg)
1768{
1769 struct hda_gen_spec *spec = codec->spec;
1770 int i, err, noutputs;
1771
1772 noutputs = cfg->line_outs;
1773 if (spec->multi_ios > 0 && cfg->line_outs < 3)
1774 noutputs += spec->multi_ios;
1775
1776 for (i = 0; i < noutputs; i++) {
1777 const char *name;
1778 int index;
1779 struct nid_path *path;
1780
1781 path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]);
1782 if (!path)
1783 continue;
1784
1785 name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL);
1786 if (!name || !strcmp(name, "CLFE")) {
1787 /* Center/LFE */
1788 err = add_vol_ctl(codec, "Center", 0, 1, path);
376 if (err < 0) 1789 if (err < 0)
377 return NULL; 1790 return err;
1791 err = add_vol_ctl(codec, "LFE", 0, 2, path);
1792 if (err < 0)
1793 return err;
1794 } else {
1795 err = add_stereo_vol(codec, name, index, path);
1796 if (err < 0)
1797 return err;
378 } 1798 }
379 if (err > 0) { 1799
380 /* unmute the PIN output */ 1800 name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL);
381 unmute_output(codec, node); 1801 if (!name || !strcmp(name, "CLFE")) {
382 /* set PIN-Out enable */ 1802 err = add_sw_ctl(codec, "Center", 0, 1, path);
383 snd_hda_codec_write_cache(codec, node->nid, 0, 1803 if (err < 0)
384 AC_VERB_SET_PIN_WIDGET_CONTROL, 1804 return err;
385 AC_PINCTL_OUT_EN | 1805 err = add_sw_ctl(codec, "LFE", 0, 2, path);
386 ((node->pin_caps & AC_PINCAP_HP_DRV) ? 1806 if (err < 0)
387 AC_PINCTL_HP_EN : 0)); 1807 return err;
388 return node; 1808 } else {
1809 err = add_stereo_sw(codec, name, index, path);
1810 if (err < 0)
1811 return err;
389 } 1812 }
390 } 1813 }
391 return NULL; 1814 return 0;
392} 1815}
393 1816
1817static int create_extra_out(struct hda_codec *codec, int path_idx,
1818 const char *pfx, int cidx)
1819{
1820 struct nid_path *path;
1821 int err;
1822
1823 path = snd_hda_get_path_from_idx(codec, path_idx);
1824 if (!path)
1825 return 0;
1826 err = add_stereo_vol(codec, pfx, cidx, path);
1827 if (err < 0)
1828 return err;
1829 err = add_stereo_sw(codec, pfx, cidx, path);
1830 if (err < 0)
1831 return err;
1832 return 0;
1833}
1834
1835/* add playback controls for speaker and HP outputs */
1836static int create_extra_outs(struct hda_codec *codec, int num_pins,
1837 const int *paths, const char *pfx)
1838{
1839 int i;
1840
1841 for (i = 0; i < num_pins; i++) {
1842 const char *name;
1843 char tmp[44];
1844 int err, idx = 0;
1845
1846 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker"))
1847 name = "Bass Speaker";
1848 else if (num_pins >= 3) {
1849 snprintf(tmp, sizeof(tmp), "%s %s",
1850 pfx, channel_name[i]);
1851 name = tmp;
1852 } else {
1853 name = pfx;
1854 idx = i;
1855 }
1856 err = create_extra_out(codec, paths[i], name, idx);
1857 if (err < 0)
1858 return err;
1859 }
1860 return 0;
1861}
1862
1863static int create_hp_out_ctls(struct hda_codec *codec)
1864{
1865 struct hda_gen_spec *spec = codec->spec;
1866 return create_extra_outs(codec, spec->autocfg.hp_outs,
1867 spec->hp_paths,
1868 "Headphone");
1869}
1870
1871static int create_speaker_out_ctls(struct hda_codec *codec)
1872{
1873 struct hda_gen_spec *spec = codec->spec;
1874 return create_extra_outs(codec, spec->autocfg.speaker_outs,
1875 spec->speaker_paths,
1876 "Speaker");
1877}
394 1878
395/* 1879/*
396 * parse outputs 1880 * independent HP controls
397 */ 1881 */
398static int parse_output(struct hda_codec *codec) 1882
1883static int indep_hp_info(struct snd_kcontrol *kcontrol,
1884 struct snd_ctl_elem_info *uinfo)
399{ 1885{
400 struct hda_gspec *spec = codec->spec; 1886 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
401 struct hda_gnode *node; 1887}
402 1888
403 /* 1889static int indep_hp_get(struct snd_kcontrol *kcontrol,
404 * Look for the output PIN widget 1890 struct snd_ctl_elem_value *ucontrol)
405 */ 1891{
406 /* first, look for the line-out pin */ 1892 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 node = parse_output_jack(codec, spec, AC_JACK_LINE_OUT); 1893 struct hda_gen_spec *spec = codec->spec;
408 if (node) /* found, remember the PIN node */ 1894 ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled;
409 spec->out_pin_node[0] = node; 1895 return 0;
410 else { 1896}
411 /* if no line-out is found, try speaker out */ 1897
412 node = parse_output_jack(codec, spec, AC_JACK_SPEAKER); 1898static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
413 if (node) 1899 int nomix_path_idx, int mix_path_idx,
414 spec->out_pin_node[0] = node; 1900 int out_type);
415 } 1901
416 /* look for the HP-out pin */ 1902static int indep_hp_put(struct snd_kcontrol *kcontrol,
417 node = parse_output_jack(codec, spec, AC_JACK_HP_OUT); 1903 struct snd_ctl_elem_value *ucontrol)
418 if (node) { 1904{
419 if (! spec->out_pin_node[0]) 1905 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420 spec->out_pin_node[0] = node; 1906 struct hda_gen_spec *spec = codec->spec;
1907 unsigned int select = ucontrol->value.enumerated.item[0];
1908 int ret = 0;
1909
1910 mutex_lock(&spec->pcm_mutex);
1911 if (spec->active_streams) {
1912 ret = -EBUSY;
1913 goto unlock;
1914 }
1915
1916 if (spec->indep_hp_enabled != select) {
1917 hda_nid_t *dacp;
1918 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
1919 dacp = &spec->private_dac_nids[0];
1920 else
1921 dacp = &spec->multiout.hp_out_nid[0];
1922
1923 /* update HP aamix paths in case it conflicts with indep HP */
1924 if (spec->have_aamix_ctl) {
1925 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
1926 update_aamix_paths(codec, spec->aamix_mode,
1927 spec->out_paths[0],
1928 spec->aamix_out_paths[0],
1929 spec->autocfg.line_out_type);
1930 else
1931 update_aamix_paths(codec, spec->aamix_mode,
1932 spec->hp_paths[0],
1933 spec->aamix_out_paths[1],
1934 AUTO_PIN_HP_OUT);
1935 }
1936
1937 spec->indep_hp_enabled = select;
1938 if (spec->indep_hp_enabled)
1939 *dacp = 0;
1940 else
1941 *dacp = spec->alt_dac_nid;
1942
1943 /* update HP auto-mute state too */
1944 if (spec->hp_automute_hook)
1945 spec->hp_automute_hook(codec, NULL);
421 else 1946 else
422 spec->out_pin_node[1] = node; 1947 snd_hda_gen_hp_automute(codec, NULL);
1948
1949 ret = 1;
423 } 1950 }
1951 unlock:
1952 mutex_unlock(&spec->pcm_mutex);
1953 return ret;
1954}
424 1955
425 if (! spec->out_pin_node[0]) { 1956static const struct snd_kcontrol_new indep_hp_ctl = {
426 /* no line-out or HP pins found, 1957 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
427 * then choose for the first output pin 1958 .name = "Independent HP",
428 */ 1959 .info = indep_hp_info,
429 spec->out_pin_node[0] = parse_output_jack(codec, spec, -1); 1960 .get = indep_hp_get,
430 if (! spec->out_pin_node[0]) 1961 .put = indep_hp_put,
431 snd_printd("hda_generic: no proper output path found\n"); 1962};
1963
1964
1965static int create_indep_hp_ctls(struct hda_codec *codec)
1966{
1967 struct hda_gen_spec *spec = codec->spec;
1968 hda_nid_t dac;
1969
1970 if (!spec->indep_hp)
1971 return 0;
1972 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
1973 dac = spec->multiout.dac_nids[0];
1974 else
1975 dac = spec->multiout.hp_out_nid[0];
1976 if (!dac) {
1977 spec->indep_hp = 0;
1978 return 0;
432 } 1979 }
433 1980
1981 spec->indep_hp_enabled = false;
1982 spec->alt_dac_nid = dac;
1983 if (!snd_hda_gen_add_kctl(spec, NULL, &indep_hp_ctl))
1984 return -ENOMEM;
434 return 0; 1985 return 0;
435} 1986}
436 1987
437/* 1988/*
438 * input MUX 1989 * channel mode enum control
439 */ 1990 */
440 1991
441/* control callbacks */ 1992static int ch_mode_info(struct snd_kcontrol *kcontrol,
442static int capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1993 struct snd_ctl_elem_info *uinfo)
443{ 1994{
444 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1995 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
445 struct hda_gspec *spec = codec->spec; 1996 struct hda_gen_spec *spec = codec->spec;
446 return snd_hda_input_mux_info(&spec->input_mux, uinfo); 1997 int chs;
1998
1999 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2000 uinfo->count = 1;
2001 uinfo->value.enumerated.items = spec->multi_ios + 1;
2002 if (uinfo->value.enumerated.item > spec->multi_ios)
2003 uinfo->value.enumerated.item = spec->multi_ios;
2004 chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count;
2005 sprintf(uinfo->value.enumerated.name, "%dch", chs);
2006 return 0;
447} 2007}
448 2008
449static int capture_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2009static int ch_mode_get(struct snd_kcontrol *kcontrol,
2010 struct snd_ctl_elem_value *ucontrol)
450{ 2011{
451 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
452 struct hda_gspec *spec = codec->spec; 2013 struct hda_gen_spec *spec = codec->spec;
2014 ucontrol->value.enumerated.item[0] =
2015 (spec->ext_channel_count - spec->min_channel_count) / 2;
2016 return 0;
2017}
2018
2019static inline struct nid_path *
2020get_multiio_path(struct hda_codec *codec, int idx)
2021{
2022 struct hda_gen_spec *spec = codec->spec;
2023 return snd_hda_get_path_from_idx(codec,
2024 spec->out_paths[spec->autocfg.line_outs + idx]);
2025}
2026
2027static void update_automute_all(struct hda_codec *codec);
2028
2029static int set_multi_io(struct hda_codec *codec, int idx, bool output)
2030{
2031 struct hda_gen_spec *spec = codec->spec;
2032 hda_nid_t nid = spec->multi_io[idx].pin;
2033 struct nid_path *path;
2034
2035 path = get_multiio_path(codec, idx);
2036 if (!path)
2037 return -EINVAL;
2038
2039 if (path->active == output)
2040 return 0;
2041
2042 if (output) {
2043 set_pin_target(codec, nid, PIN_OUT, true);
2044 snd_hda_activate_path(codec, path, true, true);
2045 set_pin_eapd(codec, nid, true);
2046 } else {
2047 set_pin_eapd(codec, nid, false);
2048 snd_hda_activate_path(codec, path, false, true);
2049 set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true);
2050 path_power_down_sync(codec, path);
2051 }
2052
2053 /* update jack retasking in case it modifies any of them */
2054 update_automute_all(codec);
453 2055
454 ucontrol->value.enumerated.item[0] = spec->cur_cap_src;
455 return 0; 2056 return 0;
456} 2057}
457 2058
458static int capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2059static int ch_mode_put(struct snd_kcontrol *kcontrol,
2060 struct snd_ctl_elem_value *ucontrol)
459{ 2061{
460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2062 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
461 struct hda_gspec *spec = codec->spec; 2063 struct hda_gen_spec *spec = codec->spec;
462 return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol, 2064 int i, ch;
463 spec->adc_node->nid, &spec->cur_cap_src); 2065
2066 ch = ucontrol->value.enumerated.item[0];
2067 if (ch < 0 || ch > spec->multi_ios)
2068 return -EINVAL;
2069 if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2)
2070 return 0;
2071 spec->ext_channel_count = ch * 2 + spec->min_channel_count;
2072 for (i = 0; i < spec->multi_ios; i++)
2073 set_multi_io(codec, i, i < ch);
2074 spec->multiout.max_channels = max(spec->ext_channel_count,
2075 spec->const_channel_count);
2076 if (spec->need_dac_fix)
2077 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
2078 return 1;
464} 2079}
465 2080
466/* 2081static const struct snd_kcontrol_new channel_mode_enum = {
467 * return the string name of the given input PIN widget 2082 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
468 */ 2083 .name = "Channel Mode",
469static const char *get_input_type(struct hda_gnode *node, unsigned int *pinctl) 2084 .info = ch_mode_info,
470{ 2085 .get = ch_mode_get,
471 unsigned int location = defcfg_location(node); 2086 .put = ch_mode_put,
472 switch (defcfg_type(node)) { 2087};
473 case AC_JACK_LINE_IN: 2088
474 if ((location & 0x0f) == AC_JACK_LOC_FRONT) 2089static int create_multi_channel_mode(struct hda_codec *codec)
475 return "Front Line"; 2090{
476 return "Line"; 2091 struct hda_gen_spec *spec = codec->spec;
477 case AC_JACK_CD: 2092
478#if 0 2093 if (spec->multi_ios > 0) {
479 if (pinctl) 2094 if (!snd_hda_gen_add_kctl(spec, NULL, &channel_mode_enum))
480 *pinctl |= AC_PINCTL_VREF_GRD; 2095 return -ENOMEM;
481#endif
482 return "CD";
483 case AC_JACK_AUX:
484 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
485 return "Front Aux";
486 return "Aux";
487 case AC_JACK_MIC_IN:
488 if (pinctl &&
489 (node->pin_caps &
490 (AC_PINCAP_VREF_80 << AC_PINCAP_VREF_SHIFT)))
491 *pinctl |= AC_PINCTL_VREF_80;
492 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
493 return "Front Mic";
494 return "Mic";
495 case AC_JACK_SPDIF_IN:
496 return "SPDIF";
497 case AC_JACK_DIG_OTHER_IN:
498 return "Digital";
499 } 2096 }
500 return NULL; 2097 return 0;
501} 2098}
502 2099
503/* 2100/*
504 * parse the nodes recursively until reach to the input PIN 2101 * aamix loopback enable/disable switch
505 *
506 * returns 0 if not found, 1 if found, or a negative error code.
507 */ 2102 */
508static int parse_adc_sub_nodes(struct hda_codec *codec, struct hda_gspec *spec, 2103
509 struct hda_gnode *node, int idx) 2104#define loopback_mixing_info indep_hp_info
2105
2106static int loopback_mixing_get(struct snd_kcontrol *kcontrol,
2107 struct snd_ctl_elem_value *ucontrol)
510{ 2108{
511 int i, err; 2109 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
512 unsigned int pinctl; 2110 struct hda_gen_spec *spec = codec->spec;
513 const char *type; 2111 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2112 return 0;
2113}
514 2114
515 if (node->checked) 2115static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
2116 int nomix_path_idx, int mix_path_idx,
2117 int out_type)
2118{
2119 struct hda_gen_spec *spec = codec->spec;
2120 struct nid_path *nomix_path, *mix_path;
2121
2122 nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx);
2123 mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx);
2124 if (!nomix_path || !mix_path)
2125 return;
2126
2127 /* if HP aamix path is driven from a different DAC and the
2128 * independent HP mode is ON, can't turn on aamix path
2129 */
2130 if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled &&
2131 mix_path->path[0] != spec->alt_dac_nid)
2132 do_mix = false;
2133
2134 if (do_mix) {
2135 snd_hda_activate_path(codec, nomix_path, false, true);
2136 snd_hda_activate_path(codec, mix_path, true, true);
2137 path_power_down_sync(codec, nomix_path);
2138 } else {
2139 snd_hda_activate_path(codec, mix_path, false, true);
2140 snd_hda_activate_path(codec, nomix_path, true, true);
2141 path_power_down_sync(codec, mix_path);
2142 }
2143}
2144
2145static int loopback_mixing_put(struct snd_kcontrol *kcontrol,
2146 struct snd_ctl_elem_value *ucontrol)
2147{
2148 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2149 struct hda_gen_spec *spec = codec->spec;
2150 unsigned int val = ucontrol->value.enumerated.item[0];
2151
2152 if (val == spec->aamix_mode)
516 return 0; 2153 return 0;
2154 spec->aamix_mode = val;
2155 update_aamix_paths(codec, val, spec->out_paths[0],
2156 spec->aamix_out_paths[0],
2157 spec->autocfg.line_out_type);
2158 update_aamix_paths(codec, val, spec->hp_paths[0],
2159 spec->aamix_out_paths[1],
2160 AUTO_PIN_HP_OUT);
2161 update_aamix_paths(codec, val, spec->speaker_paths[0],
2162 spec->aamix_out_paths[2],
2163 AUTO_PIN_SPEAKER_OUT);
2164 return 1;
2165}
517 2166
518 node->checked = 1; 2167static const struct snd_kcontrol_new loopback_mixing_enum = {
519 if (node->type != AC_WID_PIN) { 2168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
520 for (i = 0; i < node->nconns; i++) { 2169 .name = "Loopback Mixing",
521 struct hda_gnode *child; 2170 .info = loopback_mixing_info,
522 child = hda_get_node(spec, node->conn_list[i]); 2171 .get = loopback_mixing_get,
523 if (! child) 2172 .put = loopback_mixing_put,
524 continue; 2173};
525 err = parse_adc_sub_nodes(codec, spec, child, idx); 2174
526 if (err < 0) 2175static int create_loopback_mixing_ctl(struct hda_codec *codec)
527 return err; 2176{
528 if (err > 0) { 2177 struct hda_gen_spec *spec = codec->spec;
529 /* found one, 2178
530 * select the path, unmute both input and output 2179 if (!spec->mixer_nid)
531 */ 2180 return 0;
532 if (node->nconns > 1) 2181 if (!(spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
533 select_input_connection(codec, node, i); 2182 spec->aamix_out_paths[2]))
534 unmute_input(codec, node, i);
535 unmute_output(codec, node);
536 return err;
537 }
538 }
539 return 0; 2183 return 0;
2184 if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum))
2185 return -ENOMEM;
2186 spec->have_aamix_ctl = 1;
2187 return 0;
2188}
2189
2190/*
2191 * shared headphone/mic handling
2192 */
2193
2194static void call_update_outputs(struct hda_codec *codec);
2195
2196/* for shared I/O, change the pin-control accordingly */
2197static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
2198{
2199 struct hda_gen_spec *spec = codec->spec;
2200 unsigned int val;
2201 hda_nid_t pin = spec->autocfg.inputs[1].pin;
2202 /* NOTE: this assumes that there are only two inputs, the
2203 * first is the real internal mic and the second is HP/mic jack.
2204 */
2205
2206 val = snd_hda_get_default_vref(codec, pin);
2207
2208 /* This pin does not have vref caps - let's enable vref on pin 0x18
2209 instead, as suggested by Realtek */
2210 if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) {
2211 const hda_nid_t vref_pin = spec->shared_mic_vref_pin;
2212 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
2213 if (vref_val != AC_PINCTL_VREF_HIZ)
2214 snd_hda_set_pin_ctl_cache(codec, vref_pin,
2215 PIN_IN | (set_as_mic ? vref_val : 0));
540 } 2216 }
541 2217
542 /* input capable? */ 2218 val = set_as_mic ? val | PIN_IN : PIN_HP;
543 if (! (node->pin_caps & AC_PINCAP_IN)) 2219 set_pin_target(codec, pin, val, true);
2220
2221 spec->automute_speaker = !set_as_mic;
2222 call_update_outputs(codec);
2223}
2224
2225/* create a shared input with the headphone out */
2226static int create_shared_input(struct hda_codec *codec)
2227{
2228 struct hda_gen_spec *spec = codec->spec;
2229 struct auto_pin_cfg *cfg = &spec->autocfg;
2230 unsigned int defcfg;
2231 hda_nid_t nid;
2232
2233 /* only one internal input pin? */
2234 if (cfg->num_inputs != 1)
2235 return 0;
2236 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2237 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
544 return 0; 2238 return 0;
545 2239
546 if (defcfg_port_conn(node) == AC_JACK_PORT_NONE) 2240 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
547 return 0; /* unconnected */ 2241 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2242 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2243 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2244 else
2245 return 0; /* both not available */
548 2246
549 if (node->wid_caps & AC_WCAP_DIGITAL) 2247 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
550 return 0; /* skip SPDIF */ 2248 return 0; /* no input */
551 2249
552 if (spec->input_mux.num_items >= HDA_MAX_NUM_INPUTS) { 2250 cfg->inputs[1].pin = nid;
553 snd_printk(KERN_ERR "hda_generic: Too many items for capture\n"); 2251 cfg->inputs[1].type = AUTO_PIN_MIC;
554 return -EINVAL; 2252 cfg->num_inputs = 2;
555 } 2253 spec->shared_mic_hp = 1;
2254 snd_printdd("hda-codec: Enable shared I/O jack on NID 0x%x\n", nid);
2255 return 0;
2256}
556 2257
557 pinctl = AC_PINCTL_IN_EN; 2258/*
558 /* create a proper capture source label */ 2259 * output jack mode
559 type = get_input_type(node, &pinctl); 2260 */
560 if (! type) { 2261static int out_jack_mode_info(struct snd_kcontrol *kcontrol,
561 /* input as default? */ 2262 struct snd_ctl_elem_info *uinfo)
562 if (! (node->pin_ctl & AC_PINCTL_IN_EN)) 2263{
563 return 0; 2264 static const char * const texts[] = {
564 type = "Input"; 2265 "Line Out", "Headphone Out",
2266 };
2267 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts);
2268}
2269
2270static int out_jack_mode_get(struct snd_kcontrol *kcontrol,
2271 struct snd_ctl_elem_value *ucontrol)
2272{
2273 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2274 hda_nid_t nid = kcontrol->private_value;
2275 if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP)
2276 ucontrol->value.enumerated.item[0] = 1;
2277 else
2278 ucontrol->value.enumerated.item[0] = 0;
2279 return 0;
2280}
2281
2282static int out_jack_mode_put(struct snd_kcontrol *kcontrol,
2283 struct snd_ctl_elem_value *ucontrol)
2284{
2285 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2286 hda_nid_t nid = kcontrol->private_value;
2287 unsigned int val;
2288
2289 val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT;
2290 if (snd_hda_codec_get_pin_target(codec, nid) == val)
2291 return 0;
2292 snd_hda_set_pin_ctl_cache(codec, nid, val);
2293 return 1;
2294}
2295
2296static const struct snd_kcontrol_new out_jack_mode_enum = {
2297 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2298 .info = out_jack_mode_info,
2299 .get = out_jack_mode_get,
2300 .put = out_jack_mode_put,
2301};
2302
2303static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx)
2304{
2305 struct hda_gen_spec *spec = codec->spec;
2306 int i;
2307
2308 for (i = 0; i < spec->kctls.used; i++) {
2309 struct snd_kcontrol_new *kctl = snd_array_elem(&spec->kctls, i);
2310 if (!strcmp(kctl->name, name) && kctl->index == idx)
2311 return true;
565 } 2312 }
566 snd_hda_add_imux_item(&spec->input_mux, type, idx, NULL); 2313 return false;
2314}
2315
2316static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,
2317 char *name, size_t name_len)
2318{
2319 struct hda_gen_spec *spec = codec->spec;
2320 int idx = 0;
567 2321
568 /* unmute the PIN external input */ 2322 snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx);
569 unmute_input(codec, node, 0); /* index = 0? */ 2323 strlcat(name, " Jack Mode", name_len);
570 /* set PIN-In enable */
571 snd_hda_codec_write_cache(codec, node->nid, 0,
572 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
573 2324
574 return 1; /* found */ 2325 for (; find_kctl_name(codec, name, idx); idx++)
2326 ;
2327}
2328
2329static int create_out_jack_modes(struct hda_codec *codec, int num_pins,
2330 hda_nid_t *pins)
2331{
2332 struct hda_gen_spec *spec = codec->spec;
2333 int i;
2334
2335 for (i = 0; i < num_pins; i++) {
2336 hda_nid_t pin = pins[i];
2337 unsigned int pincap = snd_hda_query_pin_caps(codec, pin);
2338 if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV)) {
2339 struct snd_kcontrol_new *knew;
2340 char name[44];
2341 get_jack_mode_name(codec, pin, name, sizeof(name));
2342 knew = snd_hda_gen_add_kctl(spec, name,
2343 &out_jack_mode_enum);
2344 if (!knew)
2345 return -ENOMEM;
2346 knew->private_value = pin;
2347 }
2348 }
2349
2350 return 0;
575} 2351}
576 2352
577/* 2353/*
578 * parse input 2354 * input jack mode
579 */ 2355 */
580static int parse_input_path(struct hda_codec *codec, struct hda_gnode *adc_node) 2356
2357/* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */
2358#define NUM_VREFS 6
2359
2360static const char * const vref_texts[NUM_VREFS] = {
2361 "Line In", "Mic 50pc Bias", "Mic 0V Bias",
2362 "", "Mic 80pc Bias", "Mic 100pc Bias"
2363};
2364
2365static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin)
581{ 2366{
582 struct hda_gspec *spec = codec->spec; 2367 unsigned int pincap;
583 struct hda_gnode *node;
584 int i, err;
585 2368
586 snd_printdd("AUD_IN = %x\n", adc_node->nid); 2369 pincap = snd_hda_query_pin_caps(codec, pin);
587 clear_check_flags(spec); 2370 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2371 /* filter out unusual vrefs */
2372 pincap &= ~(AC_PINCAP_VREF_GRD | AC_PINCAP_VREF_100);
2373 return pincap;
2374}
588 2375
589 // awk added - fixed no recording due to muted widget 2376/* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */
590 unmute_input(codec, adc_node, 0); 2377static int get_vref_idx(unsigned int vref_caps, unsigned int item_idx)
591 2378{
592 /* 2379 unsigned int i, n = 0;
593 * check each connection of the ADC 2380
594 * if it reaches to a proper input PIN, add the path as the 2381 for (i = 0; i < NUM_VREFS; i++) {
595 * input path. 2382 if (vref_caps & (1 << i)) {
596 */ 2383 if (n == item_idx)
597 /* first, check the direct connections to PIN widgets */ 2384 return i;
598 for (i = 0; i < adc_node->nconns; i++) { 2385 n++;
599 node = hda_get_node(spec, adc_node->conn_list[i]);
600 if (node && node->type == AC_WID_PIN) {
601 err = parse_adc_sub_nodes(codec, spec, node, i);
602 if (err < 0)
603 return err;
604 } 2386 }
605 } 2387 }
606 /* ... then check the rests, more complicated connections */ 2388 return 0;
607 for (i = 0; i < adc_node->nconns; i++) { 2389}
608 node = hda_get_node(spec, adc_node->conn_list[i]); 2390
609 if (node && node->type != AC_WID_PIN) { 2391/* convert back from the vref ctl index to the enum item index */
610 err = parse_adc_sub_nodes(codec, spec, node, i); 2392static int cvt_from_vref_idx(unsigned int vref_caps, unsigned int idx)
611 if (err < 0) 2393{
612 return err; 2394 unsigned int i, n = 0;
613 } 2395
2396 for (i = 0; i < NUM_VREFS; i++) {
2397 if (i == idx)
2398 return n;
2399 if (vref_caps & (1 << i))
2400 n++;
614 } 2401 }
2402 return 0;
2403}
2404
2405static int in_jack_mode_info(struct snd_kcontrol *kcontrol,
2406 struct snd_ctl_elem_info *uinfo)
2407{
2408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2409 hda_nid_t nid = kcontrol->private_value;
2410 unsigned int vref_caps = get_vref_caps(codec, nid);
2411
2412 snd_hda_enum_helper_info(kcontrol, uinfo, hweight32(vref_caps),
2413 vref_texts);
2414 /* set the right text */
2415 strcpy(uinfo->value.enumerated.name,
2416 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]);
2417 return 0;
2418}
2419
2420static int in_jack_mode_get(struct snd_kcontrol *kcontrol,
2421 struct snd_ctl_elem_value *ucontrol)
2422{
2423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2424 hda_nid_t nid = kcontrol->private_value;
2425 unsigned int vref_caps = get_vref_caps(codec, nid);
2426 unsigned int idx;
2427
2428 idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN;
2429 ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx);
2430 return 0;
2431}
615 2432
616 if (! spec->input_mux.num_items) 2433static int in_jack_mode_put(struct snd_kcontrol *kcontrol,
617 return 0; /* no input path found... */ 2434 struct snd_ctl_elem_value *ucontrol)
2435{
2436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2437 hda_nid_t nid = kcontrol->private_value;
2438 unsigned int vref_caps = get_vref_caps(codec, nid);
2439 unsigned int val, idx;
618 2440
619 snd_printdd("[Capture Source] NID=0x%x, #SRC=%d\n", adc_node->nid, spec->input_mux.num_items); 2441 val = snd_hda_codec_get_pin_target(codec, nid);
620 for (i = 0; i < spec->input_mux.num_items; i++) 2442 idx = cvt_from_vref_idx(vref_caps, val & AC_PINCTL_VREFEN);
621 snd_printdd(" [%s] IDX=0x%x\n", spec->input_mux.items[i].label, 2443 if (idx == ucontrol->value.enumerated.item[0])
622 spec->input_mux.items[i].index); 2444 return 0;
623 2445
624 spec->adc_node = adc_node; 2446 val &= ~AC_PINCTL_VREFEN;
2447 val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]);
2448 snd_hda_set_pin_ctl_cache(codec, nid, val);
625 return 1; 2449 return 1;
626} 2450}
627 2451
2452static const struct snd_kcontrol_new in_jack_mode_enum = {
2453 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2454 .info = in_jack_mode_info,
2455 .get = in_jack_mode_get,
2456 .put = in_jack_mode_put,
2457};
2458
2459static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin)
2460{
2461 struct hda_gen_spec *spec = codec->spec;
2462 unsigned int defcfg;
2463 struct snd_kcontrol_new *knew;
2464 char name[44];
2465
2466 /* no jack mode for fixed pins */
2467 defcfg = snd_hda_codec_get_pincfg(codec, pin);
2468 if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
2469 return 0;
2470
2471 /* no multiple vref caps? */
2472 if (hweight32(get_vref_caps(codec, pin)) <= 1)
2473 return 0;
2474
2475 get_jack_mode_name(codec, pin, name, sizeof(name));
2476 knew = snd_hda_gen_add_kctl(spec, name, &in_jack_mode_enum);
2477 if (!knew)
2478 return -ENOMEM;
2479 knew->private_value = pin;
2480 return 0;
2481}
2482
2483
628/* 2484/*
629 * parse input 2485 * Parse input paths
630 */ 2486 */
631static int parse_input(struct hda_codec *codec) 2487
2488/* add the powersave loopback-list entry */
2489static int add_loopback_list(struct hda_gen_spec *spec, hda_nid_t mix, int idx)
632{ 2490{
633 struct hda_gspec *spec = codec->spec; 2491 struct hda_amp_list *list;
634 struct hda_gnode *node;
635 int err;
636 2492
637 /* 2493 list = snd_array_new(&spec->loopback_list);
638 * At first we look for an audio input widget. 2494 if (!list)
639 * If it reaches to certain input PINs, we take it as the 2495 return -ENOMEM;
640 * input path. 2496 list->nid = mix;
641 */ 2497 list->dir = HDA_INPUT;
642 list_for_each_entry(node, &spec->nid_list, list) { 2498 list->idx = idx;
643 if (node->wid_caps & AC_WCAP_DIGITAL) 2499 spec->loopback.amplist = spec->loopback_list.list;
644 continue; /* skip SPDIF */ 2500 return 0;
645 if (node->type == AC_WID_AUD_IN) { 2501}
646 err = parse_input_path(codec, node); 2502
647 if (err < 0) 2503/* create input playback/capture controls for the given pin */
648 return err; 2504static int new_analog_input(struct hda_codec *codec, int input_idx,
649 else if (err > 0) 2505 hda_nid_t pin, const char *ctlname, int ctlidx,
650 return 0; 2506 hda_nid_t mix_nid)
2507{
2508 struct hda_gen_spec *spec = codec->spec;
2509 struct nid_path *path;
2510 unsigned int val;
2511 int err, idx;
2512
2513 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2514 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2515 return 0; /* no need for analog loopback */
2516
2517 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
2518 if (!path)
2519 return -EINVAL;
2520 print_nid_path("loopback", path);
2521 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
2522
2523 idx = path->idx[path->depth - 1];
2524 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
2525 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2526 err = __add_pb_vol_ctrl(spec, HDA_CTL_WIDGET_VOL, ctlname, ctlidx, val);
2527 if (err < 0)
2528 return err;
2529 path->ctls[NID_PATH_VOL_CTL] = val;
2530 }
2531
2532 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
2533 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2534 err = __add_pb_sw_ctrl(spec, HDA_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
2535 if (err < 0)
2536 return err;
2537 path->ctls[NID_PATH_MUTE_CTL] = val;
2538 }
2539
2540 path->active = true;
2541 err = add_loopback_list(spec, mix_nid, idx);
2542 if (err < 0)
2543 return err;
2544
2545 if (spec->mixer_nid != spec->mixer_merge_nid &&
2546 !spec->loopback_merge_path) {
2547 path = snd_hda_add_new_path(codec, spec->mixer_nid,
2548 spec->mixer_merge_nid, 0);
2549 if (path) {
2550 print_nid_path("loopback-merge", path);
2551 path->active = true;
2552 spec->loopback_merge_path =
2553 snd_hda_get_path_idx(codec, path);
651 } 2554 }
652 } 2555 }
653 snd_printd("hda_generic: no proper input path found\n"); 2556
654 return 0; 2557 return 0;
655} 2558}
656 2559
657#ifdef CONFIG_PM 2560static int is_input_pin(struct hda_codec *codec, hda_nid_t nid)
658static void add_input_loopback(struct hda_codec *codec, hda_nid_t nid,
659 int dir, int idx)
660{ 2561{
661 struct hda_gspec *spec = codec->spec; 2562 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
662 struct hda_amp_list *p; 2563 return (pincap & AC_PINCAP_IN) != 0;
2564}
663 2565
664 if (spec->num_loopbacks >= MAX_LOOPBACK_AMPS) { 2566/* Parse the codec tree and retrieve ADCs */
665 snd_printk(KERN_ERR "hda_generic: Too many loopback ctls\n"); 2567static int fill_adc_nids(struct hda_codec *codec)
666 return; 2568{
2569 struct hda_gen_spec *spec = codec->spec;
2570 hda_nid_t nid;
2571 hda_nid_t *adc_nids = spec->adc_nids;
2572 int max_nums = ARRAY_SIZE(spec->adc_nids);
2573 int i, nums = 0;
2574
2575 nid = codec->start_nid;
2576 for (i = 0; i < codec->num_nodes; i++, nid++) {
2577 unsigned int caps = get_wcaps(codec, nid);
2578 int type = get_wcaps_type(caps);
2579
2580 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2581 continue;
2582 adc_nids[nums] = nid;
2583 if (++nums >= max_nums)
2584 break;
667 } 2585 }
668 p = &spec->loopback_list[spec->num_loopbacks++]; 2586 spec->num_adc_nids = nums;
669 p->nid = nid; 2587
670 p->dir = dir; 2588 /* copy the detected ADCs to all_adcs[] */
671 p->idx = idx; 2589 spec->num_all_adcs = nums;
672 spec->loopback.amplist = spec->loopback_list; 2590 memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t));
2591
2592 return nums;
2593}
2594
2595/* filter out invalid adc_nids that don't give all active input pins;
2596 * if needed, check whether dynamic ADC-switching is available
2597 */
2598static int check_dyn_adc_switch(struct hda_codec *codec)
2599{
2600 struct hda_gen_spec *spec = codec->spec;
2601 struct hda_input_mux *imux = &spec->input_mux;
2602 unsigned int ok_bits;
2603 int i, n, nums;
2604
2605 again:
2606 nums = 0;
2607 ok_bits = 0;
2608 for (n = 0; n < spec->num_adc_nids; n++) {
2609 for (i = 0; i < imux->num_items; i++) {
2610 if (!spec->input_paths[i][n])
2611 break;
2612 }
2613 if (i >= imux->num_items) {
2614 ok_bits |= (1 << n);
2615 nums++;
2616 }
2617 }
2618
2619 if (!ok_bits) {
2620 if (spec->shared_mic_hp) {
2621 spec->shared_mic_hp = 0;
2622 imux->num_items = 1;
2623 goto again;
2624 }
2625
2626 /* check whether ADC-switch is possible */
2627 for (i = 0; i < imux->num_items; i++) {
2628 for (n = 0; n < spec->num_adc_nids; n++) {
2629 if (spec->input_paths[i][n]) {
2630 spec->dyn_adc_idx[i] = n;
2631 break;
2632 }
2633 }
2634 }
2635
2636 snd_printdd("hda-codec: enabling ADC switching\n");
2637 spec->dyn_adc_switch = 1;
2638 } else if (nums != spec->num_adc_nids) {
2639 /* shrink the invalid adcs and input paths */
2640 nums = 0;
2641 for (n = 0; n < spec->num_adc_nids; n++) {
2642 if (!(ok_bits & (1 << n)))
2643 continue;
2644 if (n != nums) {
2645 spec->adc_nids[nums] = spec->adc_nids[n];
2646 for (i = 0; i < imux->num_items; i++) {
2647 invalidate_nid_path(codec,
2648 spec->input_paths[i][nums]);
2649 spec->input_paths[i][nums] =
2650 spec->input_paths[i][n];
2651 }
2652 }
2653 nums++;
2654 }
2655 spec->num_adc_nids = nums;
2656 }
2657
2658 if (imux->num_items == 1 || spec->shared_mic_hp) {
2659 snd_printdd("hda-codec: reducing to a single ADC\n");
2660 spec->num_adc_nids = 1; /* reduce to a single ADC */
2661 }
2662
2663 /* single index for individual volumes ctls */
2664 if (!spec->dyn_adc_switch && spec->multi_cap_vol)
2665 spec->num_adc_nids = 1;
2666
2667 return 0;
2668}
2669
2670/* parse capture source paths from the given pin and create imux items */
2671static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
2672 int cfg_idx, int num_adcs,
2673 const char *label, int anchor)
2674{
2675 struct hda_gen_spec *spec = codec->spec;
2676 struct hda_input_mux *imux = &spec->input_mux;
2677 int imux_idx = imux->num_items;
2678 bool imux_added = false;
2679 int c;
2680
2681 for (c = 0; c < num_adcs; c++) {
2682 struct nid_path *path;
2683 hda_nid_t adc = spec->adc_nids[c];
2684
2685 if (!is_reachable_path(codec, pin, adc))
2686 continue;
2687 path = snd_hda_add_new_path(codec, pin, adc, anchor);
2688 if (!path)
2689 continue;
2690 print_nid_path("input", path);
2691 spec->input_paths[imux_idx][c] =
2692 snd_hda_get_path_idx(codec, path);
2693
2694 if (!imux_added) {
2695 spec->imux_pins[imux->num_items] = pin;
2696 snd_hda_add_imux_item(imux, label, cfg_idx, NULL);
2697 imux_added = true;
2698 }
2699 }
2700
2701 return 0;
673} 2702}
674#else
675#define add_input_loopback(codec,nid,dir,idx)
676#endif
677 2703
678/* 2704/*
679 * create mixer controls if possible 2705 * create playback/capture controls for input pins
680 */ 2706 */
681static int create_mixer(struct hda_codec *codec, struct hda_gnode *node, 2707
682 unsigned int index, const char *type, 2708/* fill the label for each input at first */
683 const char *dir_sfx, int is_loopback) 2709static int fill_input_pin_labels(struct hda_codec *codec)
684{ 2710{
685 char name[32]; 2711 struct hda_gen_spec *spec = codec->spec;
686 int err; 2712 const struct auto_pin_cfg *cfg = &spec->autocfg;
687 int created = 0; 2713 int i;
688 struct snd_kcontrol_new knew;
689 2714
690 if (type) 2715 for (i = 0; i < cfg->num_inputs; i++) {
691 sprintf(name, "%s %s Switch", type, dir_sfx); 2716 hda_nid_t pin = cfg->inputs[i].pin;
692 else 2717 const char *label;
693 sprintf(name, "%s Switch", dir_sfx); 2718 int j, idx;
694 if ((node->wid_caps & AC_WCAP_IN_AMP) && 2719
695 (node->amp_in_caps & AC_AMPCAP_MUTE)) { 2720 if (!is_input_pin(codec, pin))
696 knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, index, HDA_INPUT); 2721 continue;
697 if (is_loopback) 2722
698 add_input_loopback(codec, node->nid, HDA_INPUT, index); 2723 label = hda_get_autocfg_input_label(codec, cfg, i);
699 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); 2724 idx = 0;
700 err = snd_hda_ctl_add(codec, node->nid, 2725 for (j = i - 1; j >= 0; j--) {
701 snd_ctl_new1(&knew, codec)); 2726 if (spec->input_labels[j] &&
702 if (err < 0) 2727 !strcmp(spec->input_labels[j], label)) {
703 return err; 2728 idx = spec->input_label_idxs[j] + 1;
704 created = 1; 2729 break;
705 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) && 2730 }
706 (node->amp_out_caps & AC_AMPCAP_MUTE)) { 2731 }
707 knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, 0, HDA_OUTPUT); 2732
708 if (is_loopback) 2733 spec->input_labels[i] = label;
709 add_input_loopback(codec, node->nid, HDA_OUTPUT, 0); 2734 spec->input_label_idxs[i] = idx;
710 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
711 err = snd_hda_ctl_add(codec, node->nid,
712 snd_ctl_new1(&knew, codec));
713 if (err < 0)
714 return err;
715 created = 1;
716 } 2735 }
717 2736
718 if (type) 2737 return 0;
719 sprintf(name, "%s %s Volume", type, dir_sfx); 2738}
720 else 2739
721 sprintf(name, "%s Volume", dir_sfx); 2740#define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
722 if ((node->wid_caps & AC_WCAP_IN_AMP) && 2741
723 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) { 2742static int create_input_ctls(struct hda_codec *codec)
724 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT); 2743{
725 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); 2744 struct hda_gen_spec *spec = codec->spec;
726 err = snd_hda_ctl_add(codec, node->nid, 2745 const struct auto_pin_cfg *cfg = &spec->autocfg;
727 snd_ctl_new1(&knew, codec)); 2746 hda_nid_t mixer = spec->mixer_nid;
2747 int num_adcs;
2748 int i, err;
2749 unsigned int val;
2750
2751 num_adcs = fill_adc_nids(codec);
2752 if (num_adcs < 0)
2753 return 0;
2754
2755 err = fill_input_pin_labels(codec);
2756 if (err < 0)
2757 return err;
2758
2759 for (i = 0; i < cfg->num_inputs; i++) {
2760 hda_nid_t pin;
2761
2762 pin = cfg->inputs[i].pin;
2763 if (!is_input_pin(codec, pin))
2764 continue;
2765
2766 val = PIN_IN;
2767 if (cfg->inputs[i].type == AUTO_PIN_MIC)
2768 val |= snd_hda_get_default_vref(codec, pin);
2769 set_pin_target(codec, pin, val, false);
2770
2771 if (mixer) {
2772 if (is_reachable_path(codec, pin, mixer)) {
2773 err = new_analog_input(codec, i, pin,
2774 spec->input_labels[i],
2775 spec->input_label_idxs[i],
2776 mixer);
2777 if (err < 0)
2778 return err;
2779 }
2780 }
2781
2782 err = parse_capture_source(codec, pin, i, num_adcs,
2783 spec->input_labels[i], -mixer);
728 if (err < 0) 2784 if (err < 0)
729 return err; 2785 return err;
730 created = 1; 2786
731 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) && 2787 if (spec->add_in_jack_modes) {
732 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) { 2788 err = create_in_jack_mode(codec, pin);
733 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT); 2789 if (err < 0)
734 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); 2790 return err;
735 err = snd_hda_ctl_add(codec, node->nid, 2791 }
736 snd_ctl_new1(&knew, codec)); 2792 }
2793
2794 if (mixer && spec->add_stereo_mix_input) {
2795 err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs,
2796 "Stereo Mix", 0);
737 if (err < 0) 2797 if (err < 0)
738 return err; 2798 return err;
739 created = 1;
740 } 2799 }
741 2800
742 return created; 2801 return 0;
743} 2802}
744 2803
2804
745/* 2805/*
746 * check whether the controls with the given name and direction suffix already exist 2806 * input source mux
747 */ 2807 */
748static int check_existing_control(struct hda_codec *codec, const char *type, const char *dir) 2808
749{ 2809/* get the input path specified by the given adc and imux indices */
750 struct snd_ctl_elem_id id; 2810static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx)
751 memset(&id, 0, sizeof(id)); 2811{
752 sprintf(id.name, "%s %s Volume", type, dir); 2812 struct hda_gen_spec *spec = codec->spec;
753 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2813 if (imux_idx < 0 || imux_idx >= HDA_MAX_NUM_INPUTS) {
754 if (snd_ctl_find_id(codec->bus->card, &id)) 2814 snd_BUG();
755 return 1; 2815 return NULL;
756 sprintf(id.name, "%s %s Switch", type, dir); 2816 }
757 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2817 if (spec->dyn_adc_switch)
758 if (snd_ctl_find_id(codec->bus->card, &id)) 2818 adc_idx = spec->dyn_adc_idx[imux_idx];
759 return 1; 2819 if (adc_idx < 0 || adc_idx >= AUTO_CFG_MAX_INS) {
2820 snd_BUG();
2821 return NULL;
2822 }
2823 return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]);
2824}
2825
2826static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
2827 unsigned int idx);
2828
2829static int mux_enum_info(struct snd_kcontrol *kcontrol,
2830 struct snd_ctl_elem_info *uinfo)
2831{
2832 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2833 struct hda_gen_spec *spec = codec->spec;
2834 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
2835}
2836
2837static int mux_enum_get(struct snd_kcontrol *kcontrol,
2838 struct snd_ctl_elem_value *ucontrol)
2839{
2840 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2841 struct hda_gen_spec *spec = codec->spec;
2842 /* the ctls are created at once with multiple counts */
2843 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2844
2845 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
760 return 0; 2846 return 0;
761} 2847}
762 2848
2849static int mux_enum_put(struct snd_kcontrol *kcontrol,
2850 struct snd_ctl_elem_value *ucontrol)
2851{
2852 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2853 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2854 return mux_select(codec, adc_idx,
2855 ucontrol->value.enumerated.item[0]);
2856}
2857
2858static const struct snd_kcontrol_new cap_src_temp = {
2859 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2860 .name = "Input Source",
2861 .info = mux_enum_info,
2862 .get = mux_enum_get,
2863 .put = mux_enum_put,
2864};
2865
763/* 2866/*
764 * build output mixer controls 2867 * capture volume and capture switch ctls
765 */ 2868 */
766static int create_output_mixers(struct hda_codec *codec, 2869
767 const char * const *names) 2870typedef int (*put_call_t)(struct snd_kcontrol *kcontrol,
2871 struct snd_ctl_elem_value *ucontrol);
2872
2873/* call the given amp update function for all amps in the imux list at once */
2874static int cap_put_caller(struct snd_kcontrol *kcontrol,
2875 struct snd_ctl_elem_value *ucontrol,
2876 put_call_t func, int type)
768{ 2877{
769 struct hda_gspec *spec = codec->spec; 2878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
770 int i, err; 2879 struct hda_gen_spec *spec = codec->spec;
2880 const struct hda_input_mux *imux;
2881 struct nid_path *path;
2882 int i, adc_idx, err = 0;
771 2883
772 for (i = 0; i < spec->pcm_vol_nodes; i++) { 2884 imux = &spec->input_mux;
773 err = create_mixer(codec, spec->pcm_vol[i].node, 2885 adc_idx = kcontrol->id.index;
774 spec->pcm_vol[i].index, 2886 mutex_lock(&codec->control_mutex);
775 names[i], "Playback", 0); 2887 /* we use the cache-only update at first since multiple input paths
2888 * may shared the same amp; by updating only caches, the redundant
2889 * writes to hardware can be reduced.
2890 */
2891 codec->cached_write = 1;
2892 for (i = 0; i < imux->num_items; i++) {
2893 path = get_input_path(codec, adc_idx, i);
2894 if (!path || !path->ctls[type])
2895 continue;
2896 kcontrol->private_value = path->ctls[type];
2897 err = func(kcontrol, ucontrol);
776 if (err < 0) 2898 if (err < 0)
777 return err; 2899 goto error;
778 } 2900 }
779 return 0; 2901 error:
2902 codec->cached_write = 0;
2903 mutex_unlock(&codec->control_mutex);
2904 snd_hda_codec_flush_cache(codec); /* flush the updates */
2905 if (err >= 0 && spec->cap_sync_hook)
2906 spec->cap_sync_hook(codec, ucontrol);
2907 return err;
780} 2908}
781 2909
782static int build_output_controls(struct hda_codec *codec) 2910/* capture volume ctl callbacks */
2911#define cap_vol_info snd_hda_mixer_amp_volume_info
2912#define cap_vol_get snd_hda_mixer_amp_volume_get
2913#define cap_vol_tlv snd_hda_mixer_amp_tlv
2914
2915static int cap_vol_put(struct snd_kcontrol *kcontrol,
2916 struct snd_ctl_elem_value *ucontrol)
783{ 2917{
784 struct hda_gspec *spec = codec->spec; 2918 return cap_put_caller(kcontrol, ucontrol,
785 static const char * const types_speaker[] = { "Speaker", "Headphone" }; 2919 snd_hda_mixer_amp_volume_put,
786 static const char * const types_line[] = { "Front", "Headphone" }; 2920 NID_PATH_VOL_CTL);
2921}
787 2922
788 switch (spec->pcm_vol_nodes) { 2923static const struct snd_kcontrol_new cap_vol_temp = {
789 case 1: 2924 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
790 return create_mixer(codec, spec->pcm_vol[0].node, 2925 .name = "Capture Volume",
791 spec->pcm_vol[0].index, 2926 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
792 "Master", "Playback", 0); 2927 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
793 case 2: 2928 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK),
794 if (defcfg_type(spec->out_pin_node[0]) == AC_JACK_SPEAKER) 2929 .info = cap_vol_info,
795 return create_output_mixers(codec, types_speaker); 2930 .get = cap_vol_get,
796 else 2931 .put = cap_vol_put,
797 return create_output_mixers(codec, types_line); 2932 .tlv = { .c = cap_vol_tlv },
2933};
2934
2935/* capture switch ctl callbacks */
2936#define cap_sw_info snd_ctl_boolean_stereo_info
2937#define cap_sw_get snd_hda_mixer_amp_switch_get
2938
2939static int cap_sw_put(struct snd_kcontrol *kcontrol,
2940 struct snd_ctl_elem_value *ucontrol)
2941{
2942 return cap_put_caller(kcontrol, ucontrol,
2943 snd_hda_mixer_amp_switch_put,
2944 NID_PATH_MUTE_CTL);
2945}
2946
2947static const struct snd_kcontrol_new cap_sw_temp = {
2948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2949 .name = "Capture Switch",
2950 .info = cap_sw_info,
2951 .get = cap_sw_get,
2952 .put = cap_sw_put,
2953};
2954
2955static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path)
2956{
2957 hda_nid_t nid;
2958 int i, depth;
2959
2960 path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0;
2961 for (depth = 0; depth < 3; depth++) {
2962 if (depth >= path->depth)
2963 return -EINVAL;
2964 i = path->depth - depth - 1;
2965 nid = path->path[i];
2966 if (!path->ctls[NID_PATH_VOL_CTL]) {
2967 if (nid_has_volume(codec, nid, HDA_OUTPUT))
2968 path->ctls[NID_PATH_VOL_CTL] =
2969 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2970 else if (nid_has_volume(codec, nid, HDA_INPUT)) {
2971 int idx = path->idx[i];
2972 if (!depth && codec->single_adc_amp)
2973 idx = 0;
2974 path->ctls[NID_PATH_VOL_CTL] =
2975 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2976 }
2977 }
2978 if (!path->ctls[NID_PATH_MUTE_CTL]) {
2979 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2980 path->ctls[NID_PATH_MUTE_CTL] =
2981 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2982 else if (nid_has_mute(codec, nid, HDA_INPUT)) {
2983 int idx = path->idx[i];
2984 if (!depth && codec->single_adc_amp)
2985 idx = 0;
2986 path->ctls[NID_PATH_MUTE_CTL] =
2987 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT);
2988 }
2989 }
798 } 2990 }
799 return 0; 2991 return 0;
800} 2992}
801 2993
802/* create capture volume/switch */ 2994static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
803static int build_input_controls(struct hda_codec *codec)
804{ 2995{
805 struct hda_gspec *spec = codec->spec; 2996 struct hda_gen_spec *spec = codec->spec;
806 struct hda_gnode *adc_node = spec->adc_node; 2997 struct auto_pin_cfg *cfg = &spec->autocfg;
807 int i, err; 2998 unsigned int val;
808 static struct snd_kcontrol_new cap_sel = { 2999 int i;
809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3000
810 .name = "Capture Source", 3001 if (!spec->inv_dmic_split)
811 .info = capture_source_info, 3002 return false;
812 .get = capture_source_get, 3003 for (i = 0; i < cfg->num_inputs; i++) {
813 .put = capture_source_put, 3004 if (cfg->inputs[i].pin != nid)
814 }; 3005 continue;
3006 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3007 return false;
3008 val = snd_hda_codec_get_pincfg(codec, nid);
3009 return snd_hda_get_input_pin_attr(val) == INPUT_PIN_ATTR_INT;
3010 }
3011 return false;
3012}
815 3013
816 if (! adc_node || ! spec->input_mux.num_items) 3014/* capture switch put callback for a single control with hook call */
817 return 0; /* not found */ 3015static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
3016 struct snd_ctl_elem_value *ucontrol)
3017{
3018 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3019 struct hda_gen_spec *spec = codec->spec;
3020 int ret;
818 3021
819 spec->cur_cap_src = 0; 3022 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
820 select_input_connection(codec, adc_node, 3023 if (ret < 0)
821 spec->input_mux.items[0].index); 3024 return ret;
822 3025
823 /* create capture volume and switch controls if the ADC has an amp */ 3026 if (spec->cap_sync_hook)
824 /* do we have only a single item? */ 3027 spec->cap_sync_hook(codec, ucontrol);
825 if (spec->input_mux.num_items == 1) { 3028
826 err = create_mixer(codec, adc_node, 3029 return ret;
827 spec->input_mux.items[0].index, 3030}
828 NULL, "Capture", 0); 3031
829 if (err < 0) 3032static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
830 return err; 3033 int idx, bool is_switch, unsigned int ctl,
3034 bool inv_dmic)
3035{
3036 struct hda_gen_spec *spec = codec->spec;
3037 char tmpname[44];
3038 int type = is_switch ? HDA_CTL_WIDGET_MUTE : HDA_CTL_WIDGET_VOL;
3039 const char *sfx = is_switch ? "Switch" : "Volume";
3040 unsigned int chs = inv_dmic ? 1 : 3;
3041 struct snd_kcontrol_new *knew;
3042
3043 if (!ctl)
831 return 0; 3044 return 0;
832 }
833 3045
834 /* create input MUX if multiple sources are available */ 3046 if (label)
835 err = snd_hda_ctl_add(codec, spec->adc_node->nid, 3047 snprintf(tmpname, sizeof(tmpname),
836 snd_ctl_new1(&cap_sel, codec)); 3048 "%s Capture %s", label, sfx);
3049 else
3050 snprintf(tmpname, sizeof(tmpname),
3051 "Capture %s", sfx);
3052 knew = add_control(spec, type, tmpname, idx,
3053 amp_val_replace_channels(ctl, chs));
3054 if (!knew)
3055 return -ENOMEM;
3056 if (is_switch)
3057 knew->put = cap_single_sw_put;
3058 if (!inv_dmic)
3059 return 0;
3060
3061 /* Make independent right kcontrol */
3062 if (label)
3063 snprintf(tmpname, sizeof(tmpname),
3064 "Inverted %s Capture %s", label, sfx);
3065 else
3066 snprintf(tmpname, sizeof(tmpname),
3067 "Inverted Capture %s", sfx);
3068 knew = add_control(spec, type, tmpname, idx,
3069 amp_val_replace_channels(ctl, 2));
3070 if (!knew)
3071 return -ENOMEM;
3072 if (is_switch)
3073 knew->put = cap_single_sw_put;
3074 return 0;
3075}
3076
3077/* create single (and simple) capture volume and switch controls */
3078static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx,
3079 unsigned int vol_ctl, unsigned int sw_ctl,
3080 bool inv_dmic)
3081{
3082 int err;
3083 err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic);
837 if (err < 0) 3084 if (err < 0)
838 return err; 3085 return err;
3086 err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic);
3087 if (err < 0)
3088 return err;
3089 return 0;
3090}
3091
3092/* create bound capture volume and switch controls */
3093static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx,
3094 unsigned int vol_ctl, unsigned int sw_ctl)
3095{
3096 struct hda_gen_spec *spec = codec->spec;
3097 struct snd_kcontrol_new *knew;
839 3098
840 /* no volume control? */ 3099 if (vol_ctl) {
841 if (! (adc_node->wid_caps & AC_WCAP_IN_AMP) || 3100 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_vol_temp);
842 ! (adc_node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) 3101 if (!knew)
3102 return -ENOMEM;
3103 knew->index = idx;
3104 knew->private_value = vol_ctl;
3105 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3106 }
3107 if (sw_ctl) {
3108 knew = snd_hda_gen_add_kctl(spec, NULL, &cap_sw_temp);
3109 if (!knew)
3110 return -ENOMEM;
3111 knew->index = idx;
3112 knew->private_value = sw_ctl;
3113 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
3114 }
3115 return 0;
3116}
3117
3118/* return the vol ctl when used first in the imux list */
3119static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type)
3120{
3121 struct nid_path *path;
3122 unsigned int ctl;
3123 int i;
3124
3125 path = get_input_path(codec, 0, idx);
3126 if (!path)
843 return 0; 3127 return 0;
3128 ctl = path->ctls[type];
3129 if (!ctl)
3130 return 0;
3131 for (i = 0; i < idx - 1; i++) {
3132 path = get_input_path(codec, 0, i);
3133 if (path && path->ctls[type] == ctl)
3134 return 0;
3135 }
3136 return ctl;
3137}
3138
3139/* create individual capture volume and switch controls per input */
3140static int create_multi_cap_vol_ctl(struct hda_codec *codec)
3141{
3142 struct hda_gen_spec *spec = codec->spec;
3143 struct hda_input_mux *imux = &spec->input_mux;
3144 int i, err, type;
3145
3146 for (i = 0; i < imux->num_items; i++) {
3147 bool inv_dmic;
3148 int idx;
3149
3150 idx = imux->items[i].index;
3151 if (idx >= spec->autocfg.num_inputs)
3152 continue;
3153 inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]);
844 3154
845 for (i = 0; i < spec->input_mux.num_items; i++) { 3155 for (type = 0; type < 2; type++) {
846 struct snd_kcontrol_new knew; 3156 err = add_single_cap_ctl(codec,
847 char name[32]; 3157 spec->input_labels[idx],
848 sprintf(name, "%s Capture Volume", 3158 spec->input_label_idxs[idx],
849 spec->input_mux.items[i].label); 3159 type,
850 knew = (struct snd_kcontrol_new) 3160 get_first_cap_ctl(codec, i, type),
851 HDA_CODEC_VOLUME(name, adc_node->nid, 3161 inv_dmic);
852 spec->input_mux.items[i].index, 3162 if (err < 0)
853 HDA_INPUT); 3163 return err;
854 err = snd_hda_ctl_add(codec, adc_node->nid, 3164 }
855 snd_ctl_new1(&knew, codec)); 3165 }
3166 return 0;
3167}
3168
3169static int create_capture_mixers(struct hda_codec *codec)
3170{
3171 struct hda_gen_spec *spec = codec->spec;
3172 struct hda_input_mux *imux = &spec->input_mux;
3173 int i, n, nums, err;
3174
3175 if (spec->dyn_adc_switch)
3176 nums = 1;
3177 else
3178 nums = spec->num_adc_nids;
3179
3180 if (!spec->auto_mic && imux->num_items > 1) {
3181 struct snd_kcontrol_new *knew;
3182 const char *name;
3183 name = nums > 1 ? "Input Source" : "Capture Source";
3184 knew = snd_hda_gen_add_kctl(spec, name, &cap_src_temp);
3185 if (!knew)
3186 return -ENOMEM;
3187 knew->count = nums;
3188 }
3189
3190 for (n = 0; n < nums; n++) {
3191 bool multi = false;
3192 bool multi_cap_vol = spec->multi_cap_vol;
3193 bool inv_dmic = false;
3194 int vol, sw;
3195
3196 vol = sw = 0;
3197 for (i = 0; i < imux->num_items; i++) {
3198 struct nid_path *path;
3199 path = get_input_path(codec, n, i);
3200 if (!path)
3201 continue;
3202 parse_capvol_in_path(codec, path);
3203 if (!vol)
3204 vol = path->ctls[NID_PATH_VOL_CTL];
3205 else if (vol != path->ctls[NID_PATH_VOL_CTL]) {
3206 multi = true;
3207 if (!same_amp_caps(codec, vol,
3208 path->ctls[NID_PATH_VOL_CTL], HDA_INPUT))
3209 multi_cap_vol = true;
3210 }
3211 if (!sw)
3212 sw = path->ctls[NID_PATH_MUTE_CTL];
3213 else if (sw != path->ctls[NID_PATH_MUTE_CTL]) {
3214 multi = true;
3215 if (!same_amp_caps(codec, sw,
3216 path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT))
3217 multi_cap_vol = true;
3218 }
3219 if (is_inv_dmic_pin(codec, spec->imux_pins[i]))
3220 inv_dmic = true;
3221 }
3222
3223 if (!multi)
3224 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3225 inv_dmic);
3226 else if (!multi_cap_vol)
3227 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3228 else
3229 err = create_multi_cap_vol_ctl(codec);
856 if (err < 0) 3230 if (err < 0)
857 return err; 3231 return err;
858 } 3232 }
@@ -860,226 +3234,1696 @@ static int build_input_controls(struct hda_codec *codec)
860 return 0; 3234 return 0;
861} 3235}
862 3236
3237/*
3238 * add mic boosts if needed
3239 */
3240
3241/* check whether the given amp is feasible as a boost volume */
3242static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid,
3243 int dir, int idx)
3244{
3245 unsigned int step;
3246
3247 if (!nid_has_volume(codec, nid, dir) ||
3248 is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) ||
3249 is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL))
3250 return false;
3251
3252 step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE)
3253 >> AC_AMPCAP_STEP_SIZE_SHIFT;
3254 if (step < 0x20)
3255 return false;
3256 return true;
3257}
3258
3259/* look for a boost amp in a widget close to the pin */
3260static unsigned int look_for_boost_amp(struct hda_codec *codec,
3261 struct nid_path *path)
3262{
3263 unsigned int val = 0;
3264 hda_nid_t nid;
3265 int depth;
3266
3267 for (depth = 0; depth < 3; depth++) {
3268 if (depth >= path->depth - 1)
3269 break;
3270 nid = path->path[depth];
3271 if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) {
3272 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3273 break;
3274 } else if (check_boost_vol(codec, nid, HDA_INPUT,
3275 path->idx[depth])) {
3276 val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth],
3277 HDA_INPUT);
3278 break;
3279 }
3280 }
3281
3282 return val;
3283}
3284
3285static int parse_mic_boost(struct hda_codec *codec)
3286{
3287 struct hda_gen_spec *spec = codec->spec;
3288 struct auto_pin_cfg *cfg = &spec->autocfg;
3289 struct hda_input_mux *imux = &spec->input_mux;
3290 int i;
3291
3292 if (!spec->num_adc_nids)
3293 return 0;
3294
3295 for (i = 0; i < imux->num_items; i++) {
3296 struct nid_path *path;
3297 unsigned int val;
3298 int idx;
3299 char boost_label[44];
3300
3301 idx = imux->items[i].index;
3302 if (idx >= imux->num_items)
3303 continue;
3304
3305 /* check only line-in and mic pins */
3306 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3307 continue;
3308
3309 path = get_input_path(codec, 0, i);
3310 if (!path)
3311 continue;
3312
3313 val = look_for_boost_amp(codec, path);
3314 if (!val)
3315 continue;
3316
3317 /* create a boost control */
3318 snprintf(boost_label, sizeof(boost_label),
3319 "%s Boost Volume", spec->input_labels[idx]);
3320 if (!add_control(spec, HDA_CTL_WIDGET_VOL, boost_label,
3321 spec->input_label_idxs[idx], val))
3322 return -ENOMEM;
3323
3324 path->ctls[NID_PATH_BOOST_CTL] = val;
3325 }
3326 return 0;
3327}
863 3328
864/* 3329/*
865 * parse the nodes recursively until reach to the output PIN. 3330 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
866 * 3331 */
867 * returns 0 - if not found, 3332static void parse_digital(struct hda_codec *codec)
868 * 1 - if found, but no mixer is created 3333{
869 * 2 - if found and mixer was already created, (just skip) 3334 struct hda_gen_spec *spec = codec->spec;
870 * a negative error code 3335 struct nid_path *path;
3336 int i, nums;
3337 hda_nid_t dig_nid, pin;
3338
3339 /* support multiple SPDIFs; the secondary is set up as a slave */
3340 nums = 0;
3341 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3342 pin = spec->autocfg.dig_out_pins[i];
3343 dig_nid = look_for_dac(codec, pin, true);
3344 if (!dig_nid)
3345 continue;
3346 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
3347 if (!path)
3348 continue;
3349 print_nid_path("digout", path);
3350 path->active = true;
3351 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
3352 set_pin_target(codec, pin, PIN_OUT, false);
3353 if (!nums) {
3354 spec->multiout.dig_out_nid = dig_nid;
3355 spec->dig_out_type = spec->autocfg.dig_out_type[0];
3356 } else {
3357 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
3358 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
3359 break;
3360 spec->slave_dig_outs[nums - 1] = dig_nid;
3361 }
3362 nums++;
3363 }
3364
3365 if (spec->autocfg.dig_in_pin) {
3366 pin = spec->autocfg.dig_in_pin;
3367 dig_nid = codec->start_nid;
3368 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3369 unsigned int wcaps = get_wcaps(codec, dig_nid);
3370 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3371 continue;
3372 if (!(wcaps & AC_WCAP_DIGITAL))
3373 continue;
3374 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
3375 if (path) {
3376 print_nid_path("digin", path);
3377 path->active = true;
3378 spec->dig_in_nid = dig_nid;
3379 spec->digin_path = snd_hda_get_path_idx(codec, path);
3380 set_pin_target(codec, pin, PIN_IN, false);
3381 break;
3382 }
3383 }
3384 }
3385}
3386
3387
3388/*
3389 * input MUX handling
3390 */
3391
3392static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur);
3393
3394/* select the given imux item; either unmute exclusively or select the route */
3395static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3396 unsigned int idx)
3397{
3398 struct hda_gen_spec *spec = codec->spec;
3399 const struct hda_input_mux *imux;
3400 struct nid_path *old_path, *path;
3401
3402 imux = &spec->input_mux;
3403 if (!imux->num_items)
3404 return 0;
3405
3406 if (idx >= imux->num_items)
3407 idx = imux->num_items - 1;
3408 if (spec->cur_mux[adc_idx] == idx)
3409 return 0;
3410
3411 old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]);
3412 if (!old_path)
3413 return 0;
3414 if (old_path->active)
3415 snd_hda_activate_path(codec, old_path, false, false);
3416
3417 spec->cur_mux[adc_idx] = idx;
3418
3419 if (spec->shared_mic_hp)
3420 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
3421
3422 if (spec->dyn_adc_switch)
3423 dyn_adc_pcm_resetup(codec, idx);
3424
3425 path = get_input_path(codec, adc_idx, idx);
3426 if (!path)
3427 return 0;
3428 if (path->active)
3429 return 0;
3430 snd_hda_activate_path(codec, path, true, false);
3431 if (spec->cap_sync_hook)
3432 spec->cap_sync_hook(codec, NULL);
3433 path_power_down_sync(codec, old_path);
3434 return 1;
3435}
3436
3437
3438/*
3439 * Jack detections for HP auto-mute and mic-switch
3440 */
3441
3442/* check each pin in the given array; returns true if any of them is plugged */
3443static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3444{
3445 int i, present = 0;
3446
3447 for (i = 0; i < num_pins; i++) {
3448 hda_nid_t nid = pins[i];
3449 if (!nid)
3450 break;
3451 /* don't detect pins retasked as inputs */
3452 if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN)
3453 continue;
3454 present |= snd_hda_jack_detect(codec, nid);
3455 }
3456 return present;
3457}
3458
3459/* standard HP/line-out auto-mute helper */
3460static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3461 bool mute)
3462{
3463 struct hda_gen_spec *spec = codec->spec;
3464 int i;
3465
3466 for (i = 0; i < num_pins; i++) {
3467 hda_nid_t nid = pins[i];
3468 unsigned int val;
3469 if (!nid)
3470 break;
3471 /* don't reset VREF value in case it's controlling
3472 * the amp (see alc861_fixup_asus_amp_vref_0f())
3473 */
3474 if (spec->keep_vref_in_automute)
3475 val = snd_hda_codec_get_pin_target(codec, nid) & ~PIN_HP;
3476 else
3477 val = 0;
3478 if (!mute)
3479 val |= snd_hda_codec_get_pin_target(codec, nid);
3480 /* here we call update_pin_ctl() so that the pinctl is changed
3481 * without changing the pinctl target value;
3482 * the original target value will be still referred at the
3483 * init / resume again
3484 */
3485 update_pin_ctl(codec, nid, val);
3486 set_pin_eapd(codec, nid, !mute);
3487 }
3488}
3489
3490/* Toggle outputs muting */
3491void snd_hda_gen_update_outputs(struct hda_codec *codec)
3492{
3493 struct hda_gen_spec *spec = codec->spec;
3494 int on;
3495
3496 /* Control HP pins/amps depending on master_mute state;
3497 * in general, HP pins/amps control should be enabled in all cases,
3498 * but currently set only for master_mute, just to be safe
3499 */
3500 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
3501 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
3502 spec->autocfg.hp_pins, spec->master_mute);
3503
3504 if (!spec->automute_speaker)
3505 on = 0;
3506 else
3507 on = spec->hp_jack_present | spec->line_jack_present;
3508 on |= spec->master_mute;
3509 spec->speaker_muted = on;
3510 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
3511 spec->autocfg.speaker_pins, on);
3512
3513 /* toggle line-out mutes if needed, too */
3514 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3515 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
3516 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
3517 return;
3518 if (!spec->automute_lo)
3519 on = 0;
3520 else
3521 on = spec->hp_jack_present;
3522 on |= spec->master_mute;
3523 spec->line_out_muted = on;
3524 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
3525 spec->autocfg.line_out_pins, on);
3526}
3527EXPORT_SYMBOL_HDA(snd_hda_gen_update_outputs);
3528
3529static void call_update_outputs(struct hda_codec *codec)
3530{
3531 struct hda_gen_spec *spec = codec->spec;
3532 if (spec->automute_hook)
3533 spec->automute_hook(codec);
3534 else
3535 snd_hda_gen_update_outputs(codec);
3536}
3537
3538/* standard HP-automute helper */
3539void snd_hda_gen_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3540{
3541 struct hda_gen_spec *spec = codec->spec;
3542 hda_nid_t *pins = spec->autocfg.hp_pins;
3543 int num_pins = ARRAY_SIZE(spec->autocfg.hp_pins);
3544
3545 /* No detection for the first HP jack during indep-HP mode */
3546 if (spec->indep_hp_enabled) {
3547 pins++;
3548 num_pins--;
3549 }
3550
3551 spec->hp_jack_present = detect_jacks(codec, num_pins, pins);
3552 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
3553 return;
3554 call_update_outputs(codec);
3555}
3556EXPORT_SYMBOL_HDA(snd_hda_gen_hp_automute);
3557
3558/* standard line-out-automute helper */
3559void snd_hda_gen_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3560{
3561 struct hda_gen_spec *spec = codec->spec;
3562
3563 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3564 return;
3565 /* check LO jack only when it's different from HP */
3566 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
3567 return;
3568
3569 spec->line_jack_present =
3570 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
3571 spec->autocfg.line_out_pins);
3572 if (!spec->automute_speaker || !spec->detect_lo)
3573 return;
3574 call_update_outputs(codec);
3575}
3576EXPORT_SYMBOL_HDA(snd_hda_gen_line_automute);
3577
3578/* standard mic auto-switch helper */
3579void snd_hda_gen_mic_autoswitch(struct hda_codec *codec, struct hda_jack_tbl *jack)
3580{
3581 struct hda_gen_spec *spec = codec->spec;
3582 int i;
3583
3584 if (!spec->auto_mic)
3585 return;
3586
3587 for (i = spec->am_num_entries - 1; i > 0; i--) {
3588 hda_nid_t pin = spec->am_entry[i].pin;
3589 /* don't detect pins retasked as outputs */
3590 if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN)
3591 continue;
3592 if (snd_hda_jack_detect(codec, pin)) {
3593 mux_select(codec, 0, spec->am_entry[i].idx);
3594 return;
3595 }
3596 }
3597 mux_select(codec, 0, spec->am_entry[0].idx);
3598}
3599EXPORT_SYMBOL_HDA(snd_hda_gen_mic_autoswitch);
3600
3601/* update jack retasking */
3602static void update_automute_all(struct hda_codec *codec)
3603{
3604 struct hda_gen_spec *spec = codec->spec;
3605
3606 if (spec->hp_automute_hook)
3607 spec->hp_automute_hook(codec, NULL);
3608 else
3609 snd_hda_gen_hp_automute(codec, NULL);
3610 if (spec->line_automute_hook)
3611 spec->line_automute_hook(codec, NULL);
3612 else
3613 snd_hda_gen_line_automute(codec, NULL);
3614 if (spec->mic_autoswitch_hook)
3615 spec->mic_autoswitch_hook(codec, NULL);
3616 else
3617 snd_hda_gen_mic_autoswitch(codec, NULL);
3618}
3619
3620/*
3621 * Auto-Mute mode mixer enum support
3622 */
3623static int automute_mode_info(struct snd_kcontrol *kcontrol,
3624 struct snd_ctl_elem_info *uinfo)
3625{
3626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3627 struct hda_gen_spec *spec = codec->spec;
3628 static const char * const texts3[] = {
3629 "Disabled", "Speaker Only", "Line Out+Speaker"
3630 };
3631
3632 if (spec->automute_speaker_possible && spec->automute_lo_possible)
3633 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
3634 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
3635}
3636
3637static int automute_mode_get(struct snd_kcontrol *kcontrol,
3638 struct snd_ctl_elem_value *ucontrol)
3639{
3640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3641 struct hda_gen_spec *spec = codec->spec;
3642 unsigned int val = 0;
3643 if (spec->automute_speaker)
3644 val++;
3645 if (spec->automute_lo)
3646 val++;
3647
3648 ucontrol->value.enumerated.item[0] = val;
3649 return 0;
3650}
3651
3652static int automute_mode_put(struct snd_kcontrol *kcontrol,
3653 struct snd_ctl_elem_value *ucontrol)
3654{
3655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3656 struct hda_gen_spec *spec = codec->spec;
3657
3658 switch (ucontrol->value.enumerated.item[0]) {
3659 case 0:
3660 if (!spec->automute_speaker && !spec->automute_lo)
3661 return 0;
3662 spec->automute_speaker = 0;
3663 spec->automute_lo = 0;
3664 break;
3665 case 1:
3666 if (spec->automute_speaker_possible) {
3667 if (!spec->automute_lo && spec->automute_speaker)
3668 return 0;
3669 spec->automute_speaker = 1;
3670 spec->automute_lo = 0;
3671 } else if (spec->automute_lo_possible) {
3672 if (spec->automute_lo)
3673 return 0;
3674 spec->automute_lo = 1;
3675 } else
3676 return -EINVAL;
3677 break;
3678 case 2:
3679 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
3680 return -EINVAL;
3681 if (spec->automute_speaker && spec->automute_lo)
3682 return 0;
3683 spec->automute_speaker = 1;
3684 spec->automute_lo = 1;
3685 break;
3686 default:
3687 return -EINVAL;
3688 }
3689 call_update_outputs(codec);
3690 return 1;
3691}
3692
3693static const struct snd_kcontrol_new automute_mode_enum = {
3694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3695 .name = "Auto-Mute Mode",
3696 .info = automute_mode_info,
3697 .get = automute_mode_get,
3698 .put = automute_mode_put,
3699};
3700
3701static int add_automute_mode_enum(struct hda_codec *codec)
3702{
3703 struct hda_gen_spec *spec = codec->spec;
3704
3705 if (!snd_hda_gen_add_kctl(spec, NULL, &automute_mode_enum))
3706 return -ENOMEM;
3707 return 0;
3708}
3709
3710/*
3711 * Check the availability of HP/line-out auto-mute;
3712 * Set up appropriately if really supported
871 */ 3713 */
872static int parse_loopback_path(struct hda_codec *codec, struct hda_gspec *spec, 3714static int check_auto_mute_availability(struct hda_codec *codec)
873 struct hda_gnode *node, struct hda_gnode *dest_node,
874 const char *type)
875{ 3715{
3716 struct hda_gen_spec *spec = codec->spec;
3717 struct auto_pin_cfg *cfg = &spec->autocfg;
3718 int present = 0;
876 int i, err; 3719 int i, err;
877 3720
878 if (node->checked) 3721 if (spec->suppress_auto_mute)
879 return 0; 3722 return 0;
880 3723
881 node->checked = 1; 3724 if (cfg->hp_pins[0])
882 if (node == dest_node) { 3725 present++;
883 /* loopback connection found */ 3726 if (cfg->line_out_pins[0])
884 return 1; 3727 present++;
3728 if (cfg->speaker_pins[0])
3729 present++;
3730 if (present < 2) /* need two different output types */
3731 return 0;
3732
3733 if (!cfg->speaker_pins[0] &&
3734 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3735 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3736 sizeof(cfg->speaker_pins));
3737 cfg->speaker_outs = cfg->line_outs;
3738 }
3739
3740 if (!cfg->hp_pins[0] &&
3741 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3742 memcpy(cfg->hp_pins, cfg->line_out_pins,
3743 sizeof(cfg->hp_pins));
3744 cfg->hp_outs = cfg->line_outs;
885 } 3745 }
886 3746
887 for (i = 0; i < node->nconns; i++) { 3747 for (i = 0; i < cfg->hp_outs; i++) {
888 struct hda_gnode *child = hda_get_node(spec, node->conn_list[i]); 3748 hda_nid_t nid = cfg->hp_pins[i];
889 if (! child) 3749 if (!is_jack_detectable(codec, nid))
890 continue; 3750 continue;
891 err = parse_loopback_path(codec, spec, child, dest_node, type); 3751 snd_printdd("hda-codec: Enable HP auto-muting on NID 0x%x\n",
892 if (err < 0) 3752 nid);
893 return err; 3753 snd_hda_jack_detect_enable_callback(codec, nid, HDA_GEN_HP_EVENT,
894 else if (err >= 1) { 3754 spec->hp_automute_hook ?
895 if (err == 1) { 3755 spec->hp_automute_hook :
896 err = create_mixer(codec, node, i, type, 3756 snd_hda_gen_hp_automute);
897 "Playback", 1); 3757 spec->detect_hp = 1;
898 if (err < 0) 3758 }
899 return err; 3759
900 if (err > 0) 3760 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
901 return 2; /* ok, created */ 3761 if (cfg->speaker_outs)
902 /* not created, maybe in the lower path */ 3762 for (i = 0; i < cfg->line_outs; i++) {
903 err = 1; 3763 hda_nid_t nid = cfg->line_out_pins[i];
3764 if (!is_jack_detectable(codec, nid))
3765 continue;
3766 snd_printdd("hda-codec: Enable Line-Out auto-muting on NID 0x%x\n", nid);
3767 snd_hda_jack_detect_enable_callback(codec, nid,
3768 HDA_GEN_FRONT_EVENT,
3769 spec->line_automute_hook ?
3770 spec->line_automute_hook :
3771 snd_hda_gen_line_automute);
3772 spec->detect_lo = 1;
904 } 3773 }
905 /* connect and unmute */ 3774 spec->automute_lo_possible = spec->detect_hp;
906 if (node->nconns > 1) 3775 }
907 select_input_connection(codec, node, i); 3776
908 unmute_input(codec, node, i); 3777 spec->automute_speaker_possible = cfg->speaker_outs &&
909 unmute_output(codec, node); 3778 (spec->detect_hp || spec->detect_lo);
3779
3780 spec->automute_lo = spec->automute_lo_possible;
3781 spec->automute_speaker = spec->automute_speaker_possible;
3782
3783 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
3784 /* create a control for automute mode */
3785 err = add_automute_mode_enum(codec);
3786 if (err < 0)
910 return err; 3787 return err;
911 }
912 } 3788 }
913 return 0; 3789 return 0;
914} 3790}
915 3791
3792/* check whether all auto-mic pins are valid; setup indices if OK */
3793static bool auto_mic_check_imux(struct hda_codec *codec)
3794{
3795 struct hda_gen_spec *spec = codec->spec;
3796 const struct hda_input_mux *imux;
3797 int i;
3798
3799 imux = &spec->input_mux;
3800 for (i = 0; i < spec->am_num_entries; i++) {
3801 spec->am_entry[i].idx =
3802 find_idx_in_nid_list(spec->am_entry[i].pin,
3803 spec->imux_pins, imux->num_items);
3804 if (spec->am_entry[i].idx < 0)
3805 return false; /* no corresponding imux */
3806 }
3807
3808 /* we don't need the jack detection for the first pin */
3809 for (i = 1; i < spec->am_num_entries; i++)
3810 snd_hda_jack_detect_enable_callback(codec,
3811 spec->am_entry[i].pin,
3812 HDA_GEN_MIC_EVENT,
3813 spec->mic_autoswitch_hook ?
3814 spec->mic_autoswitch_hook :
3815 snd_hda_gen_mic_autoswitch);
3816 return true;
3817}
3818
3819static int compare_attr(const void *ap, const void *bp)
3820{
3821 const struct automic_entry *a = ap;
3822 const struct automic_entry *b = bp;
3823 return (int)(a->attr - b->attr);
3824}
3825
916/* 3826/*
917 * parse the tree and build the loopback controls 3827 * Check the availability of auto-mic switch;
3828 * Set up if really supported
918 */ 3829 */
919static int build_loopback_controls(struct hda_codec *codec) 3830static int check_auto_mic_availability(struct hda_codec *codec)
920{ 3831{
921 struct hda_gspec *spec = codec->spec; 3832 struct hda_gen_spec *spec = codec->spec;
922 struct hda_gnode *node; 3833 struct auto_pin_cfg *cfg = &spec->autocfg;
923 int err; 3834 unsigned int types;
924 const char *type; 3835 int i, num_pins;
925 3836
926 if (! spec->out_pin_node[0]) 3837 if (spec->suppress_auto_mic)
927 return 0; 3838 return 0;
928 3839
929 list_for_each_entry(node, &spec->nid_list, list) { 3840 types = 0;
930 if (node->type != AC_WID_PIN) 3841 num_pins = 0;
931 continue; 3842 for (i = 0; i < cfg->num_inputs; i++) {
932 /* input capable? */ 3843 hda_nid_t nid = cfg->inputs[i].pin;
933 if (! (node->pin_caps & AC_PINCAP_IN)) 3844 unsigned int attr;
3845 attr = snd_hda_codec_get_pincfg(codec, nid);
3846 attr = snd_hda_get_input_pin_attr(attr);
3847 if (types & (1 << attr))
3848 return 0; /* already occupied */
3849 switch (attr) {
3850 case INPUT_PIN_ATTR_INT:
3851 if (cfg->inputs[i].type != AUTO_PIN_MIC)
3852 return 0; /* invalid type */
3853 break;
3854 case INPUT_PIN_ATTR_UNUSED:
3855 return 0; /* invalid entry */
3856 default:
3857 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
3858 return 0; /* invalid type */
3859 if (!spec->line_in_auto_switch &&
3860 cfg->inputs[i].type != AUTO_PIN_MIC)
3861 return 0; /* only mic is allowed */
3862 if (!is_jack_detectable(codec, nid))
3863 return 0; /* no unsol support */
3864 break;
3865 }
3866 if (num_pins >= MAX_AUTO_MIC_PINS)
934 return 0; 3867 return 0;
935 type = get_input_type(node, NULL); 3868 types |= (1 << attr);
936 if (type) { 3869 spec->am_entry[num_pins].pin = nid;
937 if (check_existing_control(codec, type, "Playback")) 3870 spec->am_entry[num_pins].attr = attr;
938 continue; 3871 num_pins++;
939 clear_check_flags(spec); 3872 }
940 err = parse_loopback_path(codec, spec, 3873
941 spec->out_pin_node[0], 3874 if (num_pins < 2)
942 node, type); 3875 return 0;
3876
3877 spec->am_num_entries = num_pins;
3878 /* sort the am_entry in the order of attr so that the pin with a
3879 * higher attr will be selected when the jack is plugged.
3880 */
3881 sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]),
3882 compare_attr, NULL);
3883
3884 if (!auto_mic_check_imux(codec))
3885 return 0;
3886
3887 spec->auto_mic = 1;
3888 spec->num_adc_nids = 1;
3889 spec->cur_mux[0] = spec->am_entry[0].idx;
3890 snd_printdd("hda-codec: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
3891 spec->am_entry[0].pin,
3892 spec->am_entry[1].pin,
3893 spec->am_entry[2].pin);
3894
3895 return 0;
3896}
3897
3898/* power_filter hook; make inactive widgets into power down */
3899static unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
3900 hda_nid_t nid,
3901 unsigned int power_state)
3902{
3903 if (power_state != AC_PWRST_D0)
3904 return power_state;
3905 if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER)
3906 return power_state;
3907 if (is_active_nid(codec, nid, HDA_OUTPUT, 0))
3908 return power_state;
3909 return AC_PWRST_D3;
3910}
3911
3912
3913/*
3914 * Parse the given BIOS configuration and set up the hda_gen_spec
3915 *
3916 * return 1 if successful, 0 if the proper config is not found,
3917 * or a negative error code
3918 */
3919int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
3920 struct auto_pin_cfg *cfg)
3921{
3922 struct hda_gen_spec *spec = codec->spec;
3923 int err;
3924
3925 parse_user_hints(codec);
3926
3927 if (spec->mixer_nid && !spec->mixer_merge_nid)
3928 spec->mixer_merge_nid = spec->mixer_nid;
3929
3930 if (cfg != &spec->autocfg) {
3931 spec->autocfg = *cfg;
3932 cfg = &spec->autocfg;
3933 }
3934
3935 fill_all_dac_nids(codec);
3936
3937 if (!cfg->line_outs) {
3938 if (cfg->dig_outs || cfg->dig_in_pin) {
3939 spec->multiout.max_channels = 2;
3940 spec->no_analog = 1;
3941 goto dig_only;
3942 }
3943 return 0; /* can't find valid BIOS pin config */
3944 }
3945
3946 if (!spec->no_primary_hp &&
3947 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3948 cfg->line_outs <= cfg->hp_outs) {
3949 /* use HP as primary out */
3950 cfg->speaker_outs = cfg->line_outs;
3951 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3952 sizeof(cfg->speaker_pins));
3953 cfg->line_outs = cfg->hp_outs;
3954 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3955 cfg->hp_outs = 0;
3956 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3957 cfg->line_out_type = AUTO_PIN_HP_OUT;
3958 }
3959
3960 err = parse_output_paths(codec);
3961 if (err < 0)
3962 return err;
3963 err = create_multi_channel_mode(codec);
3964 if (err < 0)
3965 return err;
3966 err = create_multi_out_ctls(codec, cfg);
3967 if (err < 0)
3968 return err;
3969 err = create_hp_out_ctls(codec);
3970 if (err < 0)
3971 return err;
3972 err = create_speaker_out_ctls(codec);
3973 if (err < 0)
3974 return err;
3975 err = create_indep_hp_ctls(codec);
3976 if (err < 0)
3977 return err;
3978 err = create_loopback_mixing_ctl(codec);
3979 if (err < 0)
3980 return err;
3981 err = create_shared_input(codec);
3982 if (err < 0)
3983 return err;
3984 err = create_input_ctls(codec);
3985 if (err < 0)
3986 return err;
3987
3988 spec->const_channel_count = spec->ext_channel_count;
3989 /* check the multiple speaker and headphone pins */
3990 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3991 spec->const_channel_count = max(spec->const_channel_count,
3992 cfg->speaker_outs * 2);
3993 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3994 spec->const_channel_count = max(spec->const_channel_count,
3995 cfg->hp_outs * 2);
3996 spec->multiout.max_channels = max(spec->ext_channel_count,
3997 spec->const_channel_count);
3998
3999 err = check_auto_mute_availability(codec);
4000 if (err < 0)
4001 return err;
4002
4003 err = check_dyn_adc_switch(codec);
4004 if (err < 0)
4005 return err;
4006
4007 if (!spec->shared_mic_hp) {
4008 err = check_auto_mic_availability(codec);
4009 if (err < 0)
4010 return err;
4011 }
4012
4013 err = create_capture_mixers(codec);
4014 if (err < 0)
4015 return err;
4016
4017 err = parse_mic_boost(codec);
4018 if (err < 0)
4019 return err;
4020
4021 if (spec->add_out_jack_modes) {
4022 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4023 err = create_out_jack_modes(codec, cfg->line_outs,
4024 cfg->line_out_pins);
4025 if (err < 0)
4026 return err;
4027 }
4028 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4029 err = create_out_jack_modes(codec, cfg->hp_outs,
4030 cfg->hp_pins);
943 if (err < 0) 4031 if (err < 0)
944 return err; 4032 return err;
945 if (! err)
946 continue;
947 } 4033 }
948 } 4034 }
949 return 0; 4035
4036 dig_only:
4037 parse_digital(codec);
4038
4039 if (spec->power_down_unused)
4040 codec->power_filter = snd_hda_gen_path_power_filter;
4041
4042 return 1;
950} 4043}
4044EXPORT_SYMBOL_HDA(snd_hda_gen_parse_auto_config);
4045
951 4046
952/* 4047/*
953 * build mixer controls 4048 * Build control elements
954 */ 4049 */
955static int build_generic_controls(struct hda_codec *codec) 4050
4051/* slave controls for virtual master */
4052static const char * const slave_pfxs[] = {
4053 "Front", "Surround", "Center", "LFE", "Side",
4054 "Headphone", "Speaker", "Mono", "Line Out",
4055 "CLFE", "Bass Speaker", "PCM",
4056 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
4057 "Headphone Front", "Headphone Surround", "Headphone CLFE",
4058 "Headphone Side",
4059 NULL,
4060};
4061
4062int snd_hda_gen_build_controls(struct hda_codec *codec)
956{ 4063{
4064 struct hda_gen_spec *spec = codec->spec;
957 int err; 4065 int err;
958 4066
959 if ((err = build_input_controls(codec)) < 0 || 4067 if (spec->kctls.used) {
960 (err = build_output_controls(codec)) < 0 || 4068 err = snd_hda_add_new_ctls(codec, spec->kctls.list);
961 (err = build_loopback_controls(codec)) < 0) 4069 if (err < 0)
4070 return err;
4071 }
4072
4073 if (spec->multiout.dig_out_nid) {
4074 err = snd_hda_create_dig_out_ctls(codec,
4075 spec->multiout.dig_out_nid,
4076 spec->multiout.dig_out_nid,
4077 spec->pcm_rec[1].pcm_type);
4078 if (err < 0)
4079 return err;
4080 if (!spec->no_analog) {
4081 err = snd_hda_create_spdif_share_sw(codec,
4082 &spec->multiout);
4083 if (err < 0)
4084 return err;
4085 spec->multiout.share_spdif = 1;
4086 }
4087 }
4088 if (spec->dig_in_nid) {
4089 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
4090 if (err < 0)
4091 return err;
4092 }
4093
4094 /* if we have no master control, let's create it */
4095 if (!spec->no_analog &&
4096 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
4097 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
4098 spec->vmaster_tlv, slave_pfxs,
4099 "Playback Volume");
4100 if (err < 0)
4101 return err;
4102 }
4103 if (!spec->no_analog &&
4104 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
4105 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
4106 NULL, slave_pfxs,
4107 "Playback Switch",
4108 true, &spec->vmaster_mute.sw_kctl);
4109 if (err < 0)
4110 return err;
4111 if (spec->vmaster_mute.hook)
4112 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4113 spec->vmaster_mute_enum);
4114 }
4115
4116 free_kctls(spec); /* no longer needed */
4117
4118 if (spec->shared_mic_hp) {
4119 int err;
4120 int nid = spec->autocfg.inputs[1].pin;
4121 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
4122 if (err < 0)
4123 return err;
4124 err = snd_hda_jack_detect_enable(codec, nid, 0);
4125 if (err < 0)
4126 return err;
4127 }
4128
4129 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4130 if (err < 0)
962 return err; 4131 return err;
963 4132
964 return 0; 4133 return 0;
965} 4134}
4135EXPORT_SYMBOL_HDA(snd_hda_gen_build_controls);
4136
966 4137
967/* 4138/*
968 * PCM 4139 * PCM definitions
969 */ 4140 */
970static struct hda_pcm_stream generic_pcm_playback = {
971 .substreams = 1,
972 .channels_min = 2,
973 .channels_max = 2,
974};
975 4141
976static int generic_pcm2_prepare(struct hda_pcm_stream *hinfo, 4142static void call_pcm_playback_hook(struct hda_pcm_stream *hinfo,
4143 struct hda_codec *codec,
4144 struct snd_pcm_substream *substream,
4145 int action)
4146{
4147 struct hda_gen_spec *spec = codec->spec;
4148 if (spec->pcm_playback_hook)
4149 spec->pcm_playback_hook(hinfo, codec, substream, action);
4150}
4151
4152static void call_pcm_capture_hook(struct hda_pcm_stream *hinfo,
4153 struct hda_codec *codec,
4154 struct snd_pcm_substream *substream,
4155 int action)
4156{
4157 struct hda_gen_spec *spec = codec->spec;
4158 if (spec->pcm_capture_hook)
4159 spec->pcm_capture_hook(hinfo, codec, substream, action);
4160}
4161
4162/*
4163 * Analog playback callbacks
4164 */
4165static int playback_pcm_open(struct hda_pcm_stream *hinfo,
4166 struct hda_codec *codec,
4167 struct snd_pcm_substream *substream)
4168{
4169 struct hda_gen_spec *spec = codec->spec;
4170 int err;
4171
4172 mutex_lock(&spec->pcm_mutex);
4173 err = snd_hda_multi_out_analog_open(codec,
4174 &spec->multiout, substream,
4175 hinfo);
4176 if (!err) {
4177 spec->active_streams |= 1 << STREAM_MULTI_OUT;
4178 call_pcm_playback_hook(hinfo, codec, substream,
4179 HDA_GEN_PCM_ACT_OPEN);
4180 }
4181 mutex_unlock(&spec->pcm_mutex);
4182 return err;
4183}
4184
4185static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
977 struct hda_codec *codec, 4186 struct hda_codec *codec,
978 unsigned int stream_tag, 4187 unsigned int stream_tag,
979 unsigned int format, 4188 unsigned int format,
980 struct snd_pcm_substream *substream) 4189 struct snd_pcm_substream *substream)
981{ 4190{
982 struct hda_gspec *spec = codec->spec; 4191 struct hda_gen_spec *spec = codec->spec;
4192 int err;
983 4193
984 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); 4194 err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
985 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, 4195 stream_tag, format, substream);
986 stream_tag, 0, format); 4196 if (!err)
987 return 0; 4197 call_pcm_playback_hook(hinfo, codec, substream,
4198 HDA_GEN_PCM_ACT_PREPARE);
4199 return err;
988} 4200}
989 4201
990static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo, 4202static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
991 struct hda_codec *codec, 4203 struct hda_codec *codec,
992 struct snd_pcm_substream *substream) 4204 struct snd_pcm_substream *substream)
993{ 4205{
994 struct hda_gspec *spec = codec->spec; 4206 struct hda_gen_spec *spec = codec->spec;
4207 int err;
4208
4209 err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
4210 if (!err)
4211 call_pcm_playback_hook(hinfo, codec, substream,
4212 HDA_GEN_PCM_ACT_CLEANUP);
4213 return err;
4214}
4215
4216static int playback_pcm_close(struct hda_pcm_stream *hinfo,
4217 struct hda_codec *codec,
4218 struct snd_pcm_substream *substream)
4219{
4220 struct hda_gen_spec *spec = codec->spec;
4221 mutex_lock(&spec->pcm_mutex);
4222 spec->active_streams &= ~(1 << STREAM_MULTI_OUT);
4223 call_pcm_playback_hook(hinfo, codec, substream,
4224 HDA_GEN_PCM_ACT_CLOSE);
4225 mutex_unlock(&spec->pcm_mutex);
4226 return 0;
4227}
4228
4229static int capture_pcm_open(struct hda_pcm_stream *hinfo,
4230 struct hda_codec *codec,
4231 struct snd_pcm_substream *substream)
4232{
4233 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN);
4234 return 0;
4235}
4236
4237static int capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4238 struct hda_codec *codec,
4239 unsigned int stream_tag,
4240 unsigned int format,
4241 struct snd_pcm_substream *substream)
4242{
4243 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
4244 call_pcm_capture_hook(hinfo, codec, substream,
4245 HDA_GEN_PCM_ACT_PREPARE);
4246 return 0;
4247}
995 4248
4249static int capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4250 struct hda_codec *codec,
4251 struct snd_pcm_substream *substream)
4252{
996 snd_hda_codec_cleanup_stream(codec, hinfo->nid); 4253 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
997 snd_hda_codec_cleanup_stream(codec, spec->dac_node[1]->nid); 4254 call_pcm_capture_hook(hinfo, codec, substream,
4255 HDA_GEN_PCM_ACT_CLEANUP);
4256 return 0;
4257}
4258
4259static int capture_pcm_close(struct hda_pcm_stream *hinfo,
4260 struct hda_codec *codec,
4261 struct snd_pcm_substream *substream)
4262{
4263 call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE);
998 return 0; 4264 return 0;
999} 4265}
1000 4266
1001static int build_generic_pcms(struct hda_codec *codec) 4267static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
4268 struct hda_codec *codec,
4269 struct snd_pcm_substream *substream)
1002{ 4270{
1003 struct hda_gspec *spec = codec->spec; 4271 struct hda_gen_spec *spec = codec->spec;
1004 struct hda_pcm *info = &spec->pcm_rec; 4272 int err = 0;
1005 4273
1006 if (! spec->dac_node[0] && ! spec->adc_node) { 4274 mutex_lock(&spec->pcm_mutex);
1007 snd_printd("hda_generic: no PCM found\n"); 4275 if (!spec->indep_hp_enabled)
1008 return 0; 4276 err = -EBUSY;
4277 else
4278 spec->active_streams |= 1 << STREAM_INDEP_HP;
4279 call_pcm_playback_hook(hinfo, codec, substream,
4280 HDA_GEN_PCM_ACT_OPEN);
4281 mutex_unlock(&spec->pcm_mutex);
4282 return err;
4283}
4284
4285static int alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
4286 struct hda_codec *codec,
4287 struct snd_pcm_substream *substream)
4288{
4289 struct hda_gen_spec *spec = codec->spec;
4290 mutex_lock(&spec->pcm_mutex);
4291 spec->active_streams &= ~(1 << STREAM_INDEP_HP);
4292 call_pcm_playback_hook(hinfo, codec, substream,
4293 HDA_GEN_PCM_ACT_CLOSE);
4294 mutex_unlock(&spec->pcm_mutex);
4295 return 0;
4296}
4297
4298static int alt_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4299 struct hda_codec *codec,
4300 unsigned int stream_tag,
4301 unsigned int format,
4302 struct snd_pcm_substream *substream)
4303{
4304 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
4305 call_pcm_playback_hook(hinfo, codec, substream,
4306 HDA_GEN_PCM_ACT_PREPARE);
4307 return 0;
4308}
4309
4310static int alt_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4311 struct hda_codec *codec,
4312 struct snd_pcm_substream *substream)
4313{
4314 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
4315 call_pcm_playback_hook(hinfo, codec, substream,
4316 HDA_GEN_PCM_ACT_CLEANUP);
4317 return 0;
4318}
4319
4320/*
4321 * Digital out
4322 */
4323static int dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
4324 struct hda_codec *codec,
4325 struct snd_pcm_substream *substream)
4326{
4327 struct hda_gen_spec *spec = codec->spec;
4328 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
4329}
4330
4331static int dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4332 struct hda_codec *codec,
4333 unsigned int stream_tag,
4334 unsigned int format,
4335 struct snd_pcm_substream *substream)
4336{
4337 struct hda_gen_spec *spec = codec->spec;
4338 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
4339 stream_tag, format, substream);
4340}
4341
4342static int dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4343 struct hda_codec *codec,
4344 struct snd_pcm_substream *substream)
4345{
4346 struct hda_gen_spec *spec = codec->spec;
4347 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
4348}
4349
4350static int dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
4351 struct hda_codec *codec,
4352 struct snd_pcm_substream *substream)
4353{
4354 struct hda_gen_spec *spec = codec->spec;
4355 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
4356}
4357
4358/*
4359 * Analog capture
4360 */
4361#define alt_capture_pcm_open capture_pcm_open
4362#define alt_capture_pcm_close capture_pcm_close
4363
4364static int alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4365 struct hda_codec *codec,
4366 unsigned int stream_tag,
4367 unsigned int format,
4368 struct snd_pcm_substream *substream)
4369{
4370 struct hda_gen_spec *spec = codec->spec;
4371
4372 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
4373 stream_tag, 0, format);
4374 call_pcm_capture_hook(hinfo, codec, substream,
4375 HDA_GEN_PCM_ACT_PREPARE);
4376 return 0;
4377}
4378
4379static int alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4380 struct hda_codec *codec,
4381 struct snd_pcm_substream *substream)
4382{
4383 struct hda_gen_spec *spec = codec->spec;
4384
4385 snd_hda_codec_cleanup_stream(codec,
4386 spec->adc_nids[substream->number + 1]);
4387 call_pcm_capture_hook(hinfo, codec, substream,
4388 HDA_GEN_PCM_ACT_CLEANUP);
4389 return 0;
4390}
4391
4392/*
4393 */
4394static const struct hda_pcm_stream pcm_analog_playback = {
4395 .substreams = 1,
4396 .channels_min = 2,
4397 .channels_max = 8,
4398 /* NID is set in build_pcms */
4399 .ops = {
4400 .open = playback_pcm_open,
4401 .close = playback_pcm_close,
4402 .prepare = playback_pcm_prepare,
4403 .cleanup = playback_pcm_cleanup
4404 },
4405};
4406
4407static const struct hda_pcm_stream pcm_analog_capture = {
4408 .substreams = 1,
4409 .channels_min = 2,
4410 .channels_max = 2,
4411 /* NID is set in build_pcms */
4412 .ops = {
4413 .open = capture_pcm_open,
4414 .close = capture_pcm_close,
4415 .prepare = capture_pcm_prepare,
4416 .cleanup = capture_pcm_cleanup
4417 },
4418};
4419
4420static const struct hda_pcm_stream pcm_analog_alt_playback = {
4421 .substreams = 1,
4422 .channels_min = 2,
4423 .channels_max = 2,
4424 /* NID is set in build_pcms */
4425 .ops = {
4426 .open = alt_playback_pcm_open,
4427 .close = alt_playback_pcm_close,
4428 .prepare = alt_playback_pcm_prepare,
4429 .cleanup = alt_playback_pcm_cleanup
4430 },
4431};
4432
4433static const struct hda_pcm_stream pcm_analog_alt_capture = {
4434 .substreams = 2, /* can be overridden */
4435 .channels_min = 2,
4436 .channels_max = 2,
4437 /* NID is set in build_pcms */
4438 .ops = {
4439 .open = alt_capture_pcm_open,
4440 .close = alt_capture_pcm_close,
4441 .prepare = alt_capture_pcm_prepare,
4442 .cleanup = alt_capture_pcm_cleanup
4443 },
4444};
4445
4446static const struct hda_pcm_stream pcm_digital_playback = {
4447 .substreams = 1,
4448 .channels_min = 2,
4449 .channels_max = 2,
4450 /* NID is set in build_pcms */
4451 .ops = {
4452 .open = dig_playback_pcm_open,
4453 .close = dig_playback_pcm_close,
4454 .prepare = dig_playback_pcm_prepare,
4455 .cleanup = dig_playback_pcm_cleanup
4456 },
4457};
4458
4459static const struct hda_pcm_stream pcm_digital_capture = {
4460 .substreams = 1,
4461 .channels_min = 2,
4462 .channels_max = 2,
4463 /* NID is set in build_pcms */
4464};
4465
4466/* Used by build_pcms to flag that a PCM has no playback stream */
4467static const struct hda_pcm_stream pcm_null_stream = {
4468 .substreams = 0,
4469 .channels_min = 0,
4470 .channels_max = 0,
4471};
4472
4473/*
4474 * dynamic changing ADC PCM streams
4475 */
4476static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
4477{
4478 struct hda_gen_spec *spec = codec->spec;
4479 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
4480
4481 if (spec->cur_adc && spec->cur_adc != new_adc) {
4482 /* stream is running, let's swap the current ADC */
4483 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
4484 spec->cur_adc = new_adc;
4485 snd_hda_codec_setup_stream(codec, new_adc,
4486 spec->cur_adc_stream_tag, 0,
4487 spec->cur_adc_format);
4488 return true;
1009 } 4489 }
4490 return false;
4491}
4492
4493/* analog capture with dynamic dual-adc changes */
4494static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4495 struct hda_codec *codec,
4496 unsigned int stream_tag,
4497 unsigned int format,
4498 struct snd_pcm_substream *substream)
4499{
4500 struct hda_gen_spec *spec = codec->spec;
4501 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
4502 spec->cur_adc_stream_tag = stream_tag;
4503 spec->cur_adc_format = format;
4504 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
4505 return 0;
4506}
4507
4508static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4509 struct hda_codec *codec,
4510 struct snd_pcm_substream *substream)
4511{
4512 struct hda_gen_spec *spec = codec->spec;
4513 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
4514 spec->cur_adc = 0;
4515 return 0;
4516}
4517
4518static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
4519 .substreams = 1,
4520 .channels_min = 2,
4521 .channels_max = 2,
4522 .nid = 0, /* fill later */
4523 .ops = {
4524 .prepare = dyn_adc_capture_pcm_prepare,
4525 .cleanup = dyn_adc_capture_pcm_cleanup
4526 },
4527};
4528
4529static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
4530 const char *chip_name)
4531{
4532 char *p;
4533
4534 if (*str)
4535 return;
4536 strlcpy(str, chip_name, len);
4537
4538 /* drop non-alnum chars after a space */
4539 for (p = strchr(str, ' '); p; p = strchr(p + 1, ' ')) {
4540 if (!isalnum(p[1])) {
4541 *p = 0;
4542 break;
4543 }
4544 }
4545 strlcat(str, sfx, len);
4546}
4547
4548/* build PCM streams based on the parsed results */
4549int snd_hda_gen_build_pcms(struct hda_codec *codec)
4550{
4551 struct hda_gen_spec *spec = codec->spec;
4552 struct hda_pcm *info = spec->pcm_rec;
4553 const struct hda_pcm_stream *p;
4554 bool have_multi_adcs;
1010 4555
1011 codec->num_pcms = 1; 4556 codec->num_pcms = 1;
1012 codec->pcm_info = info; 4557 codec->pcm_info = info;
1013 4558
1014 info->name = "HDA Generic"; 4559 if (spec->no_analog)
1015 if (spec->dac_node[0]) { 4560 goto skip_analog;
1016 info->stream[0] = generic_pcm_playback; 4561
1017 info->stream[0].nid = spec->dac_node[0]->nid; 4562 fill_pcm_stream_name(spec->stream_name_analog,
1018 if (spec->dac_node[1]) { 4563 sizeof(spec->stream_name_analog),
1019 info->stream[0].ops.prepare = generic_pcm2_prepare; 4564 " Analog", codec->chip_name);
1020 info->stream[0].ops.cleanup = generic_pcm2_cleanup; 4565 info->name = spec->stream_name_analog;
4566
4567 if (spec->multiout.num_dacs > 0) {
4568 p = spec->stream_analog_playback;
4569 if (!p)
4570 p = &pcm_analog_playback;
4571 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
4572 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
4573 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
4574 spec->multiout.max_channels;
4575 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
4576 spec->autocfg.line_outs == 2)
4577 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
4578 snd_pcm_2_1_chmaps;
4579 }
4580 if (spec->num_adc_nids) {
4581 p = spec->stream_analog_capture;
4582 if (!p) {
4583 if (spec->dyn_adc_switch)
4584 p = &dyn_adc_pcm_analog_capture;
4585 else
4586 p = &pcm_analog_capture;
4587 }
4588 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
4589 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
4590 }
4591
4592 skip_analog:
4593 /* SPDIF for stream index #1 */
4594 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
4595 fill_pcm_stream_name(spec->stream_name_digital,
4596 sizeof(spec->stream_name_digital),
4597 " Digital", codec->chip_name);
4598 codec->num_pcms = 2;
4599 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
4600 info = spec->pcm_rec + 1;
4601 info->name = spec->stream_name_digital;
4602 if (spec->dig_out_type)
4603 info->pcm_type = spec->dig_out_type;
4604 else
4605 info->pcm_type = HDA_PCM_TYPE_SPDIF;
4606 if (spec->multiout.dig_out_nid) {
4607 p = spec->stream_digital_playback;
4608 if (!p)
4609 p = &pcm_digital_playback;
4610 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
4611 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
4612 }
4613 if (spec->dig_in_nid) {
4614 p = spec->stream_digital_capture;
4615 if (!p)
4616 p = &pcm_digital_capture;
4617 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
4618 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
4619 }
4620 }
4621
4622 if (spec->no_analog)
4623 return 0;
4624
4625 /* If the use of more than one ADC is requested for the current
4626 * model, configure a second analog capture-only PCM.
4627 */
4628 have_multi_adcs = (spec->num_adc_nids > 1) &&
4629 !spec->dyn_adc_switch && !spec->auto_mic;
4630 /* Additional Analaog capture for index #2 */
4631 if (spec->alt_dac_nid || have_multi_adcs) {
4632 fill_pcm_stream_name(spec->stream_name_alt_analog,
4633 sizeof(spec->stream_name_alt_analog),
4634 " Alt Analog", codec->chip_name);
4635 codec->num_pcms = 3;
4636 info = spec->pcm_rec + 2;
4637 info->name = spec->stream_name_alt_analog;
4638 if (spec->alt_dac_nid) {
4639 p = spec->stream_analog_alt_playback;
4640 if (!p)
4641 p = &pcm_analog_alt_playback;
4642 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
4643 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
4644 spec->alt_dac_nid;
4645 } else {
4646 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4647 pcm_null_stream;
4648 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
4649 }
4650 if (have_multi_adcs) {
4651 p = spec->stream_analog_alt_capture;
4652 if (!p)
4653 p = &pcm_analog_alt_capture;
4654 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
4655 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
4656 spec->adc_nids[1];
4657 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
4658 spec->num_adc_nids - 1;
4659 } else {
4660 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4661 pcm_null_stream;
4662 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
4663 }
4664 }
4665
4666 return 0;
4667}
4668EXPORT_SYMBOL_HDA(snd_hda_gen_build_pcms);
4669
4670
4671/*
4672 * Standard auto-parser initializations
4673 */
4674
4675/* configure the given path as a proper output */
4676static void set_output_and_unmute(struct hda_codec *codec, int path_idx)
4677{
4678 struct nid_path *path;
4679 hda_nid_t pin;
4680
4681 path = snd_hda_get_path_from_idx(codec, path_idx);
4682 if (!path || !path->depth)
4683 return;
4684 pin = path->path[path->depth - 1];
4685 restore_pin_ctl(codec, pin);
4686 snd_hda_activate_path(codec, path, path->active, true);
4687 set_pin_eapd(codec, pin, path->active);
4688}
4689
4690/* initialize primary output paths */
4691static void init_multi_out(struct hda_codec *codec)
4692{
4693 struct hda_gen_spec *spec = codec->spec;
4694 int i;
4695
4696 for (i = 0; i < spec->autocfg.line_outs; i++)
4697 set_output_and_unmute(codec, spec->out_paths[i]);
4698}
4699
4700
4701static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths)
4702{
4703 int i;
4704
4705 for (i = 0; i < num_outs; i++)
4706 set_output_and_unmute(codec, paths[i]);
4707}
4708
4709/* initialize hp and speaker paths */
4710static void init_extra_out(struct hda_codec *codec)
4711{
4712 struct hda_gen_spec *spec = codec->spec;
4713
4714 if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT)
4715 __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths);
4716 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT)
4717 __init_extra_out(codec, spec->autocfg.speaker_outs,
4718 spec->speaker_paths);
4719}
4720
4721/* initialize multi-io paths */
4722static void init_multi_io(struct hda_codec *codec)
4723{
4724 struct hda_gen_spec *spec = codec->spec;
4725 int i;
4726
4727 for (i = 0; i < spec->multi_ios; i++) {
4728 hda_nid_t pin = spec->multi_io[i].pin;
4729 struct nid_path *path;
4730 path = get_multiio_path(codec, i);
4731 if (!path)
4732 continue;
4733 if (!spec->multi_io[i].ctl_in)
4734 spec->multi_io[i].ctl_in =
4735 snd_hda_codec_get_pin_target(codec, pin);
4736 snd_hda_activate_path(codec, path, path->active, true);
4737 }
4738}
4739
4740/* set up input pins and loopback paths */
4741static void init_analog_input(struct hda_codec *codec)
4742{
4743 struct hda_gen_spec *spec = codec->spec;
4744 struct auto_pin_cfg *cfg = &spec->autocfg;
4745 int i;
4746
4747 for (i = 0; i < cfg->num_inputs; i++) {
4748 hda_nid_t nid = cfg->inputs[i].pin;
4749 if (is_input_pin(codec, nid))
4750 restore_pin_ctl(codec, nid);
4751
4752 /* init loopback inputs */
4753 if (spec->mixer_nid) {
4754 resume_path_from_idx(codec, spec->loopback_paths[i]);
4755 resume_path_from_idx(codec, spec->loopback_merge_path);
4756 }
4757 }
4758}
4759
4760/* initialize ADC paths */
4761static void init_input_src(struct hda_codec *codec)
4762{
4763 struct hda_gen_spec *spec = codec->spec;
4764 struct hda_input_mux *imux = &spec->input_mux;
4765 struct nid_path *path;
4766 int i, c, nums;
4767
4768 if (spec->dyn_adc_switch)
4769 nums = 1;
4770 else
4771 nums = spec->num_adc_nids;
4772
4773 for (c = 0; c < nums; c++) {
4774 for (i = 0; i < imux->num_items; i++) {
4775 path = get_input_path(codec, c, i);
4776 if (path) {
4777 bool active = path->active;
4778 if (i == spec->cur_mux[c])
4779 active = true;
4780 snd_hda_activate_path(codec, path, active, false);
4781 }
1021 } 4782 }
1022 } 4783 }
1023 if (spec->adc_node) { 4784
1024 info->stream[1] = generic_pcm_playback; 4785 if (spec->shared_mic_hp)
1025 info->stream[1].nid = spec->adc_node->nid; 4786 update_shared_mic_hp(codec, spec->cur_mux[0]);
4787
4788 if (spec->cap_sync_hook)
4789 spec->cap_sync_hook(codec, NULL);
4790}
4791
4792/* set right pin controls for digital I/O */
4793static void init_digital(struct hda_codec *codec)
4794{
4795 struct hda_gen_spec *spec = codec->spec;
4796 int i;
4797 hda_nid_t pin;
4798
4799 for (i = 0; i < spec->autocfg.dig_outs; i++)
4800 set_output_and_unmute(codec, spec->digout_paths[i]);
4801 pin = spec->autocfg.dig_in_pin;
4802 if (pin) {
4803 restore_pin_ctl(codec, pin);
4804 resume_path_from_idx(codec, spec->digin_path);
4805 }
4806}
4807
4808/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
4809 * invalid unsol tags by some reason
4810 */
4811static void clear_unsol_on_unused_pins(struct hda_codec *codec)
4812{
4813 int i;
4814
4815 for (i = 0; i < codec->init_pins.used; i++) {
4816 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4817 hda_nid_t nid = pin->nid;
4818 if (is_jack_detectable(codec, nid) &&
4819 !snd_hda_jack_tbl_get(codec, nid))
4820 snd_hda_codec_update_cache(codec, nid, 0,
4821 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
1026 } 4822 }
4823}
4824
4825/*
4826 * initialize the generic spec;
4827 * this can be put as patch_ops.init function
4828 */
4829int snd_hda_gen_init(struct hda_codec *codec)
4830{
4831 struct hda_gen_spec *spec = codec->spec;
4832
4833 if (spec->init_hook)
4834 spec->init_hook(codec);
4835
4836 snd_hda_apply_verbs(codec);
4837
4838 codec->cached_write = 1;
4839
4840 init_multi_out(codec);
4841 init_extra_out(codec);
4842 init_multi_io(codec);
4843 init_analog_input(codec);
4844 init_input_src(codec);
4845 init_digital(codec);
1027 4846
4847 clear_unsol_on_unused_pins(codec);
4848
4849 /* call init functions of standard auto-mute helpers */
4850 update_automute_all(codec);
4851
4852 snd_hda_codec_flush_cache(codec);
4853
4854 if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook)
4855 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4856
4857 hda_call_check_power_status(codec, 0x01);
1028 return 0; 4858 return 0;
1029} 4859}
4860EXPORT_SYMBOL_HDA(snd_hda_gen_init);
4861
4862/*
4863 * free the generic spec;
4864 * this can be put as patch_ops.free function
4865 */
4866void snd_hda_gen_free(struct hda_codec *codec)
4867{
4868 snd_hda_gen_spec_free(codec->spec);
4869 kfree(codec->spec);
4870 codec->spec = NULL;
4871}
4872EXPORT_SYMBOL_HDA(snd_hda_gen_free);
1030 4873
1031#ifdef CONFIG_PM 4874#ifdef CONFIG_PM
1032static int generic_check_power_status(struct hda_codec *codec, hda_nid_t nid) 4875/*
4876 * check the loopback power save state;
4877 * this can be put as patch_ops.check_power_status function
4878 */
4879int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1033{ 4880{
1034 struct hda_gspec *spec = codec->spec; 4881 struct hda_gen_spec *spec = codec->spec;
1035 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); 4882 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1036} 4883}
4884EXPORT_SYMBOL_HDA(snd_hda_gen_check_power_status);
1037#endif 4885#endif
1038 4886
1039 4887
1040/* 4888/*
4889 * the generic codec support
1041 */ 4890 */
1042static struct hda_codec_ops generic_patch_ops = { 4891
1043 .build_controls = build_generic_controls, 4892static const struct hda_codec_ops generic_patch_ops = {
1044 .build_pcms = build_generic_pcms, 4893 .build_controls = snd_hda_gen_build_controls,
1045 .free = snd_hda_generic_free, 4894 .build_pcms = snd_hda_gen_build_pcms,
4895 .init = snd_hda_gen_init,
4896 .free = snd_hda_gen_free,
4897 .unsol_event = snd_hda_jack_unsol_event,
1046#ifdef CONFIG_PM 4898#ifdef CONFIG_PM
1047 .check_power_status = generic_check_power_status, 4899 .check_power_status = snd_hda_gen_check_power_status,
1048#endif 4900#endif
1049}; 4901};
1050 4902
1051/*
1052 * the generic parser
1053 */
1054int snd_hda_parse_generic_codec(struct hda_codec *codec) 4903int snd_hda_parse_generic_codec(struct hda_codec *codec)
1055{ 4904{
1056 struct hda_gspec *spec; 4905 struct hda_gen_spec *spec;
1057 int err; 4906 int err;
1058 4907
1059 if(!codec->afg)
1060 return 0;
1061
1062 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4908 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1063 if (spec == NULL) { 4909 if (!spec)
1064 printk(KERN_ERR "hda_generic: can't allocate spec\n");
1065 return -ENOMEM; 4910 return -ENOMEM;
1066 } 4911 snd_hda_gen_spec_init(spec);
1067 codec->spec = spec; 4912 codec->spec = spec;
1068 INIT_LIST_HEAD(&spec->nid_list);
1069 4913
1070 if ((err = build_afg_tree(codec)) < 0) 4914 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
1071 goto error; 4915 if (err < 0)
4916 return err;
1072 4917
1073 if ((err = parse_input(codec)) < 0 || 4918 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
1074 (err = parse_output(codec)) < 0) 4919 if (err < 0)
1075 goto error; 4920 goto error;
1076 4921
1077 codec->patch_ops = generic_patch_ops; 4922 codec->patch_ops = generic_patch_ops;
1078
1079 return 0; 4923 return 0;
1080 4924
1081 error: 4925error:
1082 snd_hda_generic_free(codec); 4926 snd_hda_gen_free(codec);
1083 return err; 4927 return err;
1084} 4928}
1085EXPORT_SYMBOL(snd_hda_parse_generic_codec); 4929EXPORT_SYMBOL_HDA(snd_hda_parse_generic_codec);
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
new file mode 100644
index 000000000000..009b57be96d3
--- /dev/null
+++ b/sound/pci/hda/hda_generic.h
@@ -0,0 +1,303 @@
1/*
2 * Generic BIOS auto-parser helper functions for HD-audio
3 *
4 * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef __SOUND_HDA_GENERIC_H
13#define __SOUND_HDA_GENERIC_H
14
15/* unsol event tags */
16enum {
17 HDA_GEN_HP_EVENT = 1, HDA_GEN_FRONT_EVENT, HDA_GEN_MIC_EVENT,
18 HDA_GEN_LAST_EVENT = HDA_GEN_MIC_EVENT
19};
20
21/* table entry for multi-io paths */
22struct hda_multi_io {
23 hda_nid_t pin; /* multi-io widget pin NID */
24 hda_nid_t dac; /* DAC to be connected */
25 unsigned int ctl_in; /* cached input-pin control value */
26};
27
28/* Widget connection path
29 *
30 * For output, stored in the order of DAC -> ... -> pin,
31 * for input, pin -> ... -> ADC.
32 *
33 * idx[i] contains the source index number to select on of the widget path[i];
34 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
35 * multi[] indicates whether it's a selector widget with multi-connectors
36 * (i.e. the connection selection is mandatory)
37 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
38 */
39
40#define MAX_NID_PATH_DEPTH 10
41
42enum {
43 NID_PATH_VOL_CTL,
44 NID_PATH_MUTE_CTL,
45 NID_PATH_BOOST_CTL,
46 NID_PATH_NUM_CTLS
47};
48
49struct nid_path {
50 int depth;
51 hda_nid_t path[MAX_NID_PATH_DEPTH];
52 unsigned char idx[MAX_NID_PATH_DEPTH];
53 unsigned char multi[MAX_NID_PATH_DEPTH];
54 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
55 bool active;
56};
57
58/* mic/line-in auto switching entry */
59
60#define MAX_AUTO_MIC_PINS 3
61
62struct automic_entry {
63 hda_nid_t pin; /* pin */
64 int idx; /* imux index, -1 = invalid */
65 unsigned int attr; /* pin attribute (INPUT_PIN_ATTR_*) */
66};
67
68/* active stream id */
69enum { STREAM_MULTI_OUT, STREAM_INDEP_HP };
70
71/* PCM hook action */
72enum {
73 HDA_GEN_PCM_ACT_OPEN,
74 HDA_GEN_PCM_ACT_PREPARE,
75 HDA_GEN_PCM_ACT_CLEANUP,
76 HDA_GEN_PCM_ACT_CLOSE,
77};
78
79struct hda_gen_spec {
80 char stream_name_analog[32]; /* analog PCM stream */
81 const struct hda_pcm_stream *stream_analog_playback;
82 const struct hda_pcm_stream *stream_analog_capture;
83
84 char stream_name_alt_analog[32]; /* alternative analog PCM stream */
85 const struct hda_pcm_stream *stream_analog_alt_playback;
86 const struct hda_pcm_stream *stream_analog_alt_capture;
87
88 char stream_name_digital[32]; /* digital PCM stream */
89 const struct hda_pcm_stream *stream_digital_playback;
90 const struct hda_pcm_stream *stream_digital_capture;
91
92 /* PCM */
93 unsigned int active_streams;
94 struct mutex pcm_mutex;
95
96 /* playback */
97 struct hda_multi_out multiout; /* playback set-up
98 * max_channels, dacs must be set
99 * dig_out_nid and hp_nid are optional
100 */
101 hda_nid_t alt_dac_nid;
102 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
103 int dig_out_type;
104
105 /* capture */
106 unsigned int num_adc_nids;
107 hda_nid_t adc_nids[AUTO_CFG_MAX_INS];
108 hda_nid_t dig_in_nid; /* digital-in NID; optional */
109 hda_nid_t mixer_nid; /* analog-mixer NID */
110 hda_nid_t mixer_merge_nid; /* aamix merge-point NID (optional) */
111 const char *input_labels[HDA_MAX_NUM_INPUTS];
112 int input_label_idxs[HDA_MAX_NUM_INPUTS];
113
114 /* capture setup for dynamic dual-adc switch */
115 hda_nid_t cur_adc;
116 unsigned int cur_adc_stream_tag;
117 unsigned int cur_adc_format;
118
119 /* capture source */
120 struct hda_input_mux input_mux;
121 unsigned int cur_mux[3];
122
123 /* channel model */
124 /* min_channel_count contains the minimum channel count for primary
125 * outputs. When multi_ios is set, the channels can be configured
126 * between min_channel_count and (min_channel_count + multi_ios * 2).
127 *
128 * ext_channel_count contains the current channel count of the primary
129 * out. This varies in the range above.
130 *
131 * Meanwhile, const_channel_count is the channel count for all outputs
132 * including headphone and speakers. It's a constant value, and the
133 * PCM is set up as max(ext_channel_count, const_channel_count).
134 */
135 int min_channel_count; /* min. channel count for primary out */
136 int ext_channel_count; /* current channel count for primary */
137 int const_channel_count; /* channel count for all */
138
139 /* PCM information */
140 struct hda_pcm pcm_rec[3]; /* used in build_pcms() */
141
142 /* dynamic controls, init_verbs and input_mux */
143 struct auto_pin_cfg autocfg;
144 struct snd_array kctls;
145 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
146 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
147 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
148 hda_nid_t shared_mic_vref_pin;
149
150 /* DAC/ADC lists */
151 int num_all_dacs;
152 hda_nid_t all_dacs[16];
153 int num_all_adcs;
154 hda_nid_t all_adcs[AUTO_CFG_MAX_INS];
155
156 /* path list */
157 struct snd_array paths;
158
159 /* path indices */
160 int out_paths[AUTO_CFG_MAX_OUTS];
161 int hp_paths[AUTO_CFG_MAX_OUTS];
162 int speaker_paths[AUTO_CFG_MAX_OUTS];
163 int aamix_out_paths[3];
164 int digout_paths[AUTO_CFG_MAX_OUTS];
165 int input_paths[HDA_MAX_NUM_INPUTS][AUTO_CFG_MAX_INS];
166 int loopback_paths[HDA_MAX_NUM_INPUTS];
167 int loopback_merge_path;
168 int digin_path;
169
170 /* auto-mic stuff */
171 int am_num_entries;
172 struct automic_entry am_entry[MAX_AUTO_MIC_PINS];
173
174 /* for pin sensing */
175 /* current status; set in hda_geneic.c */
176 unsigned int hp_jack_present:1;
177 unsigned int line_jack_present:1;
178 unsigned int speaker_muted:1; /* current status of speaker mute */
179 unsigned int line_out_muted:1; /* current status of LO mute */
180
181 /* internal states of automute / autoswitch behavior */
182 unsigned int auto_mic:1;
183 unsigned int automute_speaker:1; /* automute speaker outputs */
184 unsigned int automute_lo:1; /* automute LO outputs */
185
186 /* capabilities detected by parser */
187 unsigned int detect_hp:1; /* Headphone detection enabled */
188 unsigned int detect_lo:1; /* Line-out detection enabled */
189 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
190 unsigned int automute_lo_possible:1; /* there are line outs and HP */
191
192 /* additional parameters set by codec drivers */
193 unsigned int master_mute:1; /* master mute over all */
194 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
195 unsigned int line_in_auto_switch:1; /* allow line-in auto switch */
196
197 /* parser behavior flags; set before snd_hda_gen_parse_auto_config() */
198 unsigned int suppress_auto_mute:1; /* suppress input jack auto mute */
199 unsigned int suppress_auto_mic:1; /* suppress input jack auto switch */
200
201 /* other parse behavior flags */
202 unsigned int need_dac_fix:1; /* need to limit DACs for multi channels */
203 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
204 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
205 unsigned int multi_cap_vol:1; /* allow multiple capture xxx volumes */
206 unsigned int inv_dmic_split:1; /* inverted dmic w/a for conexant */
207 unsigned int own_eapd_ctl:1; /* set EAPD by own function */
208 unsigned int vmaster_mute_enum:1; /* add vmaster mute mode enum */
209 unsigned int indep_hp:1; /* independent HP supported */
210 unsigned int prefer_hp_amp:1; /* enable HP amp for speaker if any */
211 unsigned int add_stereo_mix_input:1; /* add aamix as a capture src */
212 unsigned int add_out_jack_modes:1; /* add output jack mode enum ctls */
213 unsigned int add_in_jack_modes:1; /* add input jack mode enum ctls */
214 unsigned int power_down_unused:1; /* power down unused widgets */
215
216 /* other internal flags */
217 unsigned int no_analog:1; /* digital I/O only */
218 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
219 unsigned int indep_hp_enabled:1; /* independent HP enabled */
220 unsigned int have_aamix_ctl:1;
221
222 /* loopback mixing mode */
223 bool aamix_mode;
224
225 /* for virtual master */
226 hda_nid_t vmaster_nid;
227 unsigned int vmaster_tlv[4];
228 struct hda_vmaster_mute_hook vmaster_mute;
229
230 struct hda_loopback_check loopback;
231 struct snd_array loopback_list;
232
233 /* multi-io */
234 int multi_ios;
235 struct hda_multi_io multi_io[4];
236
237 /* hooks */
238 void (*init_hook)(struct hda_codec *codec);
239 void (*automute_hook)(struct hda_codec *codec);
240 void (*cap_sync_hook)(struct hda_codec *codec,
241 struct snd_ctl_elem_value *ucontrol);
242
243 /* PCM hooks */
244 void (*pcm_playback_hook)(struct hda_pcm_stream *hinfo,
245 struct hda_codec *codec,
246 struct snd_pcm_substream *substream,
247 int action);
248 void (*pcm_capture_hook)(struct hda_pcm_stream *hinfo,
249 struct hda_codec *codec,
250 struct snd_pcm_substream *substream,
251 int action);
252
253 /* automute / autoswitch hooks */
254 void (*hp_automute_hook)(struct hda_codec *codec,
255 struct hda_jack_tbl *tbl);
256 void (*line_automute_hook)(struct hda_codec *codec,
257 struct hda_jack_tbl *tbl);
258 void (*mic_autoswitch_hook)(struct hda_codec *codec,
259 struct hda_jack_tbl *tbl);
260};
261
262int snd_hda_gen_spec_init(struct hda_gen_spec *spec);
263void snd_hda_gen_spec_free(struct hda_gen_spec *spec);
264
265int snd_hda_gen_init(struct hda_codec *codec);
266void snd_hda_gen_free(struct hda_codec *codec);
267
268struct nid_path *snd_hda_get_nid_path(struct hda_codec *codec,
269 hda_nid_t from_nid, hda_nid_t to_nid);
270int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path);
271struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx);
272bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
273 hda_nid_t to_nid, int anchor_nid,
274 struct nid_path *path);
275struct nid_path *
276snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid,
277 hda_nid_t to_nid, int anchor_nid);
278void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
279 bool enable, bool add_aamix);
280
281struct snd_kcontrol_new *
282snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name,
283 const struct snd_kcontrol_new *temp);
284
285int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
286 struct auto_pin_cfg *cfg);
287int snd_hda_gen_build_controls(struct hda_codec *codec);
288int snd_hda_gen_build_pcms(struct hda_codec *codec);
289
290/* standard jack event callbacks */
291void snd_hda_gen_hp_automute(struct hda_codec *codec,
292 struct hda_jack_tbl *jack);
293void snd_hda_gen_line_automute(struct hda_codec *codec,
294 struct hda_jack_tbl *jack);
295void snd_hda_gen_mic_autoswitch(struct hda_codec *codec,
296 struct hda_jack_tbl *jack);
297void snd_hda_gen_update_outputs(struct hda_codec *codec);
298
299#ifdef CONFIG_PM
300int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid);
301#endif
302
303#endif /* __SOUND_HDA_GENERIC_H */
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index a5c9411bb367..ce67608734b5 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -148,6 +148,7 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
148 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat; 148 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat;
149#endif 149#endif
150 150
151 mutex_init(&codec->user_mutex);
151 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32); 152 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32);
152 snd_array_init(&codec->hints, sizeof(struct hda_hint), 32); 153 snd_array_init(&codec->hints, sizeof(struct hda_hint), 32);
153 snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16); 154 snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16);
@@ -346,12 +347,14 @@ static ssize_t init_verbs_show(struct device *dev,
346 struct snd_hwdep *hwdep = dev_get_drvdata(dev); 347 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
347 struct hda_codec *codec = hwdep->private_data; 348 struct hda_codec *codec = hwdep->private_data;
348 int i, len = 0; 349 int i, len = 0;
350 mutex_lock(&codec->user_mutex);
349 for (i = 0; i < codec->init_verbs.used; i++) { 351 for (i = 0; i < codec->init_verbs.used; i++) {
350 struct hda_verb *v = snd_array_elem(&codec->init_verbs, i); 352 struct hda_verb *v = snd_array_elem(&codec->init_verbs, i);
351 len += snprintf(buf + len, PAGE_SIZE - len, 353 len += snprintf(buf + len, PAGE_SIZE - len,
352 "0x%02x 0x%03x 0x%04x\n", 354 "0x%02x 0x%03x 0x%04x\n",
353 v->nid, v->verb, v->param); 355 v->nid, v->verb, v->param);
354 } 356 }
357 mutex_unlock(&codec->user_mutex);
355 return len; 358 return len;
356} 359}
357 360
@@ -364,12 +367,16 @@ static int parse_init_verbs(struct hda_codec *codec, const char *buf)
364 return -EINVAL; 367 return -EINVAL;
365 if (!nid || !verb) 368 if (!nid || !verb)
366 return -EINVAL; 369 return -EINVAL;
370 mutex_lock(&codec->user_mutex);
367 v = snd_array_new(&codec->init_verbs); 371 v = snd_array_new(&codec->init_verbs);
368 if (!v) 372 if (!v) {
373 mutex_unlock(&codec->user_mutex);
369 return -ENOMEM; 374 return -ENOMEM;
375 }
370 v->nid = nid; 376 v->nid = nid;
371 v->verb = verb; 377 v->verb = verb;
372 v->param = param; 378 v->param = param;
379 mutex_unlock(&codec->user_mutex);
373 return 0; 380 return 0;
374} 381}
375 382
@@ -392,11 +399,13 @@ static ssize_t hints_show(struct device *dev,
392 struct snd_hwdep *hwdep = dev_get_drvdata(dev); 399 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
393 struct hda_codec *codec = hwdep->private_data; 400 struct hda_codec *codec = hwdep->private_data;
394 int i, len = 0; 401 int i, len = 0;
402 mutex_lock(&codec->user_mutex);
395 for (i = 0; i < codec->hints.used; i++) { 403 for (i = 0; i < codec->hints.used; i++) {
396 struct hda_hint *hint = snd_array_elem(&codec->hints, i); 404 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
397 len += snprintf(buf + len, PAGE_SIZE - len, 405 len += snprintf(buf + len, PAGE_SIZE - len,
398 "%s = %s\n", hint->key, hint->val); 406 "%s = %s\n", hint->key, hint->val);
399 } 407 }
408 mutex_unlock(&codec->user_mutex);
400 return len; 409 return len;
401} 410}
402 411
@@ -431,6 +440,7 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
431{ 440{
432 char *key, *val; 441 char *key, *val;
433 struct hda_hint *hint; 442 struct hda_hint *hint;
443 int err = 0;
434 444
435 buf = skip_spaces(buf); 445 buf = skip_spaces(buf);
436 if (!*buf || *buf == '#' || *buf == '\n') 446 if (!*buf || *buf == '#' || *buf == '\n')
@@ -450,26 +460,31 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
450 val = skip_spaces(val); 460 val = skip_spaces(val);
451 remove_trail_spaces(key); 461 remove_trail_spaces(key);
452 remove_trail_spaces(val); 462 remove_trail_spaces(val);
463 mutex_lock(&codec->user_mutex);
453 hint = get_hint(codec, key); 464 hint = get_hint(codec, key);
454 if (hint) { 465 if (hint) {
455 /* replace */ 466 /* replace */
456 kfree(hint->key); 467 kfree(hint->key);
457 hint->key = key; 468 hint->key = key;
458 hint->val = val; 469 hint->val = val;
459 return 0; 470 goto unlock;
460 } 471 }
461 /* allocate a new hint entry */ 472 /* allocate a new hint entry */
462 if (codec->hints.used >= MAX_HINTS) 473 if (codec->hints.used >= MAX_HINTS)
463 hint = NULL; 474 hint = NULL;
464 else 475 else
465 hint = snd_array_new(&codec->hints); 476 hint = snd_array_new(&codec->hints);
466 if (!hint) { 477 if (hint) {
467 kfree(key); 478 hint->key = key;
468 return -ENOMEM; 479 hint->val = val;
480 } else {
481 err = -ENOMEM;
469 } 482 }
470 hint->key = key; 483 unlock:
471 hint->val = val; 484 mutex_unlock(&codec->user_mutex);
472 return 0; 485 if (err)
486 kfree(key);
487 return err;
473} 488}
474 489
475static ssize_t hints_store(struct device *dev, 490static ssize_t hints_store(struct device *dev,
@@ -489,11 +504,13 @@ static ssize_t pin_configs_show(struct hda_codec *codec,
489 char *buf) 504 char *buf)
490{ 505{
491 int i, len = 0; 506 int i, len = 0;
507 mutex_lock(&codec->user_mutex);
492 for (i = 0; i < list->used; i++) { 508 for (i = 0; i < list->used; i++) {
493 struct hda_pincfg *pin = snd_array_elem(list, i); 509 struct hda_pincfg *pin = snd_array_elem(list, i);
494 len += sprintf(buf + len, "0x%02x 0x%08x\n", 510 len += sprintf(buf + len, "0x%02x 0x%08x\n",
495 pin->nid, pin->cfg); 511 pin->nid, pin->cfg);
496 } 512 }
513 mutex_unlock(&codec->user_mutex);
497 return len; 514 return len;
498} 515}
499 516
@@ -528,13 +545,16 @@ static ssize_t driver_pin_configs_show(struct device *dev,
528 545
529static int parse_user_pin_configs(struct hda_codec *codec, const char *buf) 546static int parse_user_pin_configs(struct hda_codec *codec, const char *buf)
530{ 547{
531 int nid, cfg; 548 int nid, cfg, err;
532 549
533 if (sscanf(buf, "%i %i", &nid, &cfg) != 2) 550 if (sscanf(buf, "%i %i", &nid, &cfg) != 2)
534 return -EINVAL; 551 return -EINVAL;
535 if (!nid) 552 if (!nid)
536 return -EINVAL; 553 return -EINVAL;
537 return snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg); 554 mutex_lock(&codec->user_mutex);
555 err = snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg);
556 mutex_unlock(&codec->user_mutex);
557 return err;
538} 558}
539 559
540static ssize_t user_pin_configs_store(struct device *dev, 560static ssize_t user_pin_configs_store(struct device *dev,
@@ -600,19 +620,50 @@ EXPORT_SYMBOL_HDA(snd_hda_get_hint);
600 620
601int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key) 621int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
602{ 622{
603 const char *p = snd_hda_get_hint(codec, key); 623 const char *p;
624 int ret;
625
626 mutex_lock(&codec->user_mutex);
627 p = snd_hda_get_hint(codec, key);
604 if (!p || !*p) 628 if (!p || !*p)
605 return -ENOENT; 629 ret = -ENOENT;
606 switch (toupper(*p)) { 630 else {
607 case 'T': /* true */ 631 switch (toupper(*p)) {
608 case 'Y': /* yes */ 632 case 'T': /* true */
609 case '1': 633 case 'Y': /* yes */
610 return 1; 634 case '1':
635 ret = 1;
636 break;
637 default:
638 ret = 0;
639 break;
640 }
611 } 641 }
612 return 0; 642 mutex_unlock(&codec->user_mutex);
643 return ret;
613} 644}
614EXPORT_SYMBOL_HDA(snd_hda_get_bool_hint); 645EXPORT_SYMBOL_HDA(snd_hda_get_bool_hint);
615 646
647int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
648{
649 const char *p;
650 unsigned long val;
651 int ret;
652
653 mutex_lock(&codec->user_mutex);
654 p = snd_hda_get_hint(codec, key);
655 if (!p)
656 ret = -ENOENT;
657 else if (strict_strtoul(p, 0, &val))
658 ret = -EINVAL;
659 else {
660 *valp = val;
661 ret = 0;
662 }
663 mutex_unlock(&codec->user_mutex);
664 return ret;
665}
666EXPORT_SYMBOL_HDA(snd_hda_get_int_hint);
616#endif /* CONFIG_SND_HDA_RECONFIG */ 667#endif /* CONFIG_SND_HDA_RECONFIG */
617 668
618#ifdef CONFIG_SND_HDA_PATCH_LOADER 669#ifdef CONFIG_SND_HDA_PATCH_LOADER
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index c78286f6e5d8..4cea6bb6fade 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -134,8 +134,8 @@ MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
134 * this may give more power-saving, but will take longer time to 134 * this may give more power-saving, but will take longer time to
135 * wake up. 135 * wake up.
136 */ 136 */
137static bool power_save_controller = 1; 137static int power_save_controller = -1;
138module_param(power_save_controller, bool, 0644); 138module_param(power_save_controller, bint, 0644);
139MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); 139MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
140#endif /* CONFIG_PM */ 140#endif /* CONFIG_PM */
141 141
@@ -811,7 +811,7 @@ static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
811{ 811{
812 struct azx *chip = bus->private_data; 812 struct azx *chip = bus->private_data;
813 unsigned int addr = azx_command_addr(val); 813 unsigned int addr = azx_command_addr(val);
814 unsigned int wp; 814 unsigned int wp, rp;
815 815
816 spin_lock_irq(&chip->reg_lock); 816 spin_lock_irq(&chip->reg_lock);
817 817
@@ -820,11 +820,18 @@ static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
820 if (wp == 0xffff) { 820 if (wp == 0xffff) {
821 /* something wrong, controller likely turned to D3 */ 821 /* something wrong, controller likely turned to D3 */
822 spin_unlock_irq(&chip->reg_lock); 822 spin_unlock_irq(&chip->reg_lock);
823 return -1; 823 return -EIO;
824 } 824 }
825 wp++; 825 wp++;
826 wp %= ICH6_MAX_CORB_ENTRIES; 826 wp %= ICH6_MAX_CORB_ENTRIES;
827 827
828 rp = azx_readw(chip, CORBRP);
829 if (wp == rp) {
830 /* oops, it's full */
831 spin_unlock_irq(&chip->reg_lock);
832 return -EAGAIN;
833 }
834
828 chip->rirb.cmds[addr]++; 835 chip->rirb.cmds[addr]++;
829 chip->corb.buf[wp] = cpu_to_le32(val); 836 chip->corb.buf[wp] = cpu_to_le32(val);
830 azx_writel(chip, CORBWP, wp); 837 azx_writel(chip, CORBWP, wp);
@@ -1078,6 +1085,15 @@ static unsigned int azx_get_response(struct hda_bus *bus,
1078static void azx_power_notify(struct hda_bus *bus, bool power_up); 1085static void azx_power_notify(struct hda_bus *bus, bool power_up);
1079#endif 1086#endif
1080 1087
1088#ifdef CONFIG_SND_HDA_DSP_LOADER
1089static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
1090 unsigned int byte_size,
1091 struct snd_dma_buffer *bufp);
1092static void azx_load_dsp_trigger(struct hda_bus *bus, bool start);
1093static void azx_load_dsp_cleanup(struct hda_bus *bus,
1094 struct snd_dma_buffer *dmab);
1095#endif
1096
1081/* reset codec link */ 1097/* reset codec link */
1082static int azx_reset(struct azx *chip, int full_reset) 1098static int azx_reset(struct azx *chip, int full_reset)
1083{ 1099{
@@ -1401,7 +1417,7 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
1401 * set up a BDL entry 1417 * set up a BDL entry
1402 */ 1418 */
1403static int setup_bdle(struct azx *chip, 1419static int setup_bdle(struct azx *chip,
1404 struct snd_pcm_substream *substream, 1420 struct snd_dma_buffer *dmab,
1405 struct azx_dev *azx_dev, u32 **bdlp, 1421 struct azx_dev *azx_dev, u32 **bdlp,
1406 int ofs, int size, int with_ioc) 1422 int ofs, int size, int with_ioc)
1407{ 1423{
@@ -1414,12 +1430,12 @@ static int setup_bdle(struct azx *chip,
1414 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES) 1430 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
1415 return -EINVAL; 1431 return -EINVAL;
1416 1432
1417 addr = snd_pcm_sgbuf_get_addr(substream, ofs); 1433 addr = snd_sgbuf_get_addr(dmab, ofs);
1418 /* program the address field of the BDL entry */ 1434 /* program the address field of the BDL entry */
1419 bdl[0] = cpu_to_le32((u32)addr); 1435 bdl[0] = cpu_to_le32((u32)addr);
1420 bdl[1] = cpu_to_le32(upper_32_bits(addr)); 1436 bdl[1] = cpu_to_le32(upper_32_bits(addr));
1421 /* program the size field of the BDL entry */ 1437 /* program the size field of the BDL entry */
1422 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size); 1438 chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size);
1423 /* one BDLE cannot cross 4K boundary on CTHDA chips */ 1439 /* one BDLE cannot cross 4K boundary on CTHDA chips */
1424 if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) { 1440 if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) {
1425 u32 remain = 0x1000 - (ofs & 0xfff); 1441 u32 remain = 0x1000 - (ofs & 0xfff);
@@ -1478,7 +1494,8 @@ static int azx_setup_periods(struct azx *chip,
1478 pci_name(chip->pci), bdl_pos_adj[chip->dev_index]); 1494 pci_name(chip->pci), bdl_pos_adj[chip->dev_index]);
1479 pos_adj = 0; 1495 pos_adj = 0;
1480 } else { 1496 } else {
1481 ofs = setup_bdle(chip, substream, azx_dev, 1497 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
1498 azx_dev,
1482 &bdl, ofs, pos_adj, true); 1499 &bdl, ofs, pos_adj, true);
1483 if (ofs < 0) 1500 if (ofs < 0)
1484 goto error; 1501 goto error;
@@ -1487,10 +1504,12 @@ static int azx_setup_periods(struct azx *chip,
1487 pos_adj = 0; 1504 pos_adj = 0;
1488 for (i = 0; i < periods; i++) { 1505 for (i = 0; i < periods; i++) {
1489 if (i == periods - 1 && pos_adj) 1506 if (i == periods - 1 && pos_adj)
1490 ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs, 1507 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
1508 azx_dev, &bdl, ofs,
1491 period_bytes - pos_adj, 0); 1509 period_bytes - pos_adj, 0);
1492 else 1510 else
1493 ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs, 1511 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
1512 azx_dev, &bdl, ofs,
1494 period_bytes, 1513 period_bytes,
1495 !azx_dev->no_period_wakeup); 1514 !azx_dev->no_period_wakeup);
1496 if (ofs < 0) 1515 if (ofs < 0)
@@ -1668,6 +1687,11 @@ static int azx_codec_create(struct azx *chip, const char *model)
1668 bus_temp.power_save = &power_save; 1687 bus_temp.power_save = &power_save;
1669 bus_temp.ops.pm_notify = azx_power_notify; 1688 bus_temp.ops.pm_notify = azx_power_notify;
1670#endif 1689#endif
1690#ifdef CONFIG_SND_HDA_DSP_LOADER
1691 bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare;
1692 bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger;
1693 bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup;
1694#endif
1671 1695
1672 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); 1696 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
1673 if (err < 0) 1697 if (err < 0)
@@ -2576,6 +2600,102 @@ static void azx_stop_chip(struct azx *chip)
2576 chip->initialized = 0; 2600 chip->initialized = 0;
2577} 2601}
2578 2602
2603#ifdef CONFIG_SND_HDA_DSP_LOADER
2604/*
2605 * DSP loading code (e.g. for CA0132)
2606 */
2607
2608/* use the first stream for loading DSP */
2609static struct azx_dev *
2610azx_get_dsp_loader_dev(struct azx *chip)
2611{
2612 return &chip->azx_dev[chip->playback_index_offset];
2613}
2614
2615static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
2616 unsigned int byte_size,
2617 struct snd_dma_buffer *bufp)
2618{
2619 u32 *bdl;
2620 struct azx *chip = bus->private_data;
2621 struct azx_dev *azx_dev;
2622 int err;
2623
2624 if (snd_hda_lock_devices(bus))
2625 return -EBUSY;
2626
2627 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG,
2628 snd_dma_pci_data(chip->pci),
2629 byte_size, bufp);
2630 if (err < 0)
2631 goto unlock;
2632
2633 mark_pages_wc(chip, bufp, true);
2634 azx_dev = azx_get_dsp_loader_dev(chip);
2635 azx_dev->bufsize = byte_size;
2636 azx_dev->period_bytes = byte_size;
2637 azx_dev->format_val = format;
2638
2639 azx_stream_reset(chip, azx_dev);
2640
2641 /* reset BDL address */
2642 azx_sd_writel(azx_dev, SD_BDLPL, 0);
2643 azx_sd_writel(azx_dev, SD_BDLPU, 0);
2644
2645 azx_dev->frags = 0;
2646 bdl = (u32 *)azx_dev->bdl.area;
2647 err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0);
2648 if (err < 0)
2649 goto error;
2650
2651 azx_setup_controller(chip, azx_dev);
2652 return azx_dev->stream_tag;
2653
2654 error:
2655 mark_pages_wc(chip, bufp, false);
2656 snd_dma_free_pages(bufp);
2657unlock:
2658 snd_hda_unlock_devices(bus);
2659 return err;
2660}
2661
2662static void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
2663{
2664 struct azx *chip = bus->private_data;
2665 struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
2666
2667 if (start)
2668 azx_stream_start(chip, azx_dev);
2669 else
2670 azx_stream_stop(chip, azx_dev);
2671 azx_dev->running = start;
2672}
2673
2674static void azx_load_dsp_cleanup(struct hda_bus *bus,
2675 struct snd_dma_buffer *dmab)
2676{
2677 struct azx *chip = bus->private_data;
2678 struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
2679
2680 if (!dmab->area)
2681 return;
2682
2683 /* reset BDL address */
2684 azx_sd_writel(azx_dev, SD_BDLPL, 0);
2685 azx_sd_writel(azx_dev, SD_BDLPU, 0);
2686 azx_sd_writel(azx_dev, SD_CTL, 0);
2687 azx_dev->bufsize = 0;
2688 azx_dev->period_bytes = 0;
2689 azx_dev->format_val = 0;
2690
2691 mark_pages_wc(chip, dmab, false);
2692 snd_dma_free_pages(dmab);
2693 dmab->area = NULL;
2694
2695 snd_hda_unlock_devices(bus);
2696}
2697#endif /* CONFIG_SND_HDA_DSP_LOADER */
2698
2579#ifdef CONFIG_PM 2699#ifdef CONFIG_PM
2580/* power-up/down the controller */ 2700/* power-up/down the controller */
2581static void azx_power_notify(struct hda_bus *bus, bool power_up) 2701static void azx_power_notify(struct hda_bus *bus, bool power_up)
@@ -2726,6 +2846,8 @@ static int azx_runtime_idle(struct device *dev)
2726 struct snd_card *card = dev_get_drvdata(dev); 2846 struct snd_card *card = dev_get_drvdata(dev);
2727 struct azx *chip = card->private_data; 2847 struct azx *chip = card->private_data;
2728 2848
2849 if (power_save_controller > 0)
2850 return 0;
2729 if (!power_save_controller || 2851 if (!power_save_controller ||
2730 !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) 2852 !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
2731 return -EBUSY; 2853 return -EBUSY;
@@ -3150,6 +3272,9 @@ static void azx_check_snoop_available(struct azx *chip)
3150 /* new ATI HDMI requires non-snoop */ 3272 /* new ATI HDMI requires non-snoop */
3151 snoop = false; 3273 snoop = false;
3152 break; 3274 break;
3275 case AZX_DRIVER_CTHDA:
3276 snoop = false;
3277 break;
3153 } 3278 }
3154 3279
3155 if (snoop != chip->snoop) { 3280 if (snoop != chip->snoop) {
@@ -3611,6 +3736,11 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
3611 /* Lynx Point */ 3736 /* Lynx Point */
3612 { PCI_DEVICE(0x8086, 0x8c20), 3737 { PCI_DEVICE(0x8086, 0x8c20),
3613 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, 3738 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
3739 /* Wellsburg */
3740 { PCI_DEVICE(0x8086, 0x8d20),
3741 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
3742 { PCI_DEVICE(0x8086, 0x8d21),
3743 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
3614 /* Lynx Point-LP */ 3744 /* Lynx Point-LP */
3615 { PCI_DEVICE(0x8086, 0x9c20), 3745 { PCI_DEVICE(0x8086, 0x9c20),
3616 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, 3746 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
@@ -3618,13 +3748,15 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
3618 { PCI_DEVICE(0x8086, 0x9c21), 3748 { PCI_DEVICE(0x8086, 0x9c21),
3619 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, 3749 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
3620 /* Haswell */ 3750 /* Haswell */
3751 { PCI_DEVICE(0x8086, 0x0a0c),
3752 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
3621 { PCI_DEVICE(0x8086, 0x0c0c), 3753 { PCI_DEVICE(0x8086, 0x0c0c),
3622 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH }, 3754 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
3623 { PCI_DEVICE(0x8086, 0x0d0c), 3755 { PCI_DEVICE(0x8086, 0x0d0c),
3624 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH }, 3756 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH },
3625 /* 5 Series/3400 */ 3757 /* 5 Series/3400 */
3626 { PCI_DEVICE(0x8086, 0x3b56), 3758 { PCI_DEVICE(0x8086, 0x3b56),
3627 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH }, 3759 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
3628 /* Poulsbo */ 3760 /* Poulsbo */
3629 { PCI_DEVICE(0x8086, 0x811b), 3761 { PCI_DEVICE(0x8086, 0x811b),
3630 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, 3762 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index 6e9f57bbe667..1d035efeff4f 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -29,7 +29,8 @@ bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
29 if (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) & 29 if (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
30 AC_DEFCFG_MISC_NO_PRESENCE) 30 AC_DEFCFG_MISC_NO_PRESENCE)
31 return false; 31 return false;
32 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)) 32 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) &&
33 !codec->jackpoll_interval)
33 return false; 34 return false;
34 return true; 35 return true;
35} 36}
@@ -39,6 +40,7 @@ EXPORT_SYMBOL_HDA(is_jack_detectable);
39static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid) 40static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid)
40{ 41{
41 u32 pincap; 42 u32 pincap;
43 u32 val;
42 44
43 if (!codec->no_trigger_sense) { 45 if (!codec->no_trigger_sense) {
44 pincap = snd_hda_query_pin_caps(codec, nid); 46 pincap = snd_hda_query_pin_caps(codec, nid);
@@ -46,8 +48,11 @@ static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid)
46 snd_hda_codec_read(codec, nid, 0, 48 snd_hda_codec_read(codec, nid, 0,
47 AC_VERB_SET_PIN_SENSE, 0); 49 AC_VERB_SET_PIN_SENSE, 0);
48 } 50 }
49 return snd_hda_codec_read(codec, nid, 0, 51 val = snd_hda_codec_read(codec, nid, 0,
50 AC_VERB_GET_PIN_SENSE, 0); 52 AC_VERB_GET_PIN_SENSE, 0);
53 if (codec->inv_jack_detect)
54 val ^= AC_PINSENSE_PRESENCE;
55 return val;
51} 56}
52 57
53/** 58/**
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 4b40a5e7a8f5..83b7486c8eff 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -133,9 +133,11 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
133 int direction, int idx, int mask, int val); 133 int direction, int idx, int mask, int val);
134int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, 134int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
135 int dir, int idx, int mask, int val); 135 int dir, int idx, int mask, int val);
136#ifdef CONFIG_PM 136int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
137 int direction, int idx, int mask, int val);
138int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
139 int dir, int idx, int mask, int val);
137void snd_hda_codec_resume_amp(struct hda_codec *codec); 140void snd_hda_codec_resume_amp(struct hda_codec *codec);
138#endif
139 141
140void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, 142void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
141 unsigned int *tlv); 143 unsigned int *tlv);
@@ -384,6 +386,61 @@ int snd_hda_add_new_ctls(struct hda_codec *codec,
384 const struct snd_kcontrol_new *knew); 386 const struct snd_kcontrol_new *knew);
385 387
386/* 388/*
389 * Fix-up pin default configurations and add default verbs
390 */
391
392struct hda_pintbl {
393 hda_nid_t nid;
394 u32 val;
395};
396
397struct hda_model_fixup {
398 const int id;
399 const char *name;
400};
401
402struct hda_fixup {
403 int type;
404 bool chained:1; /* call the chained fixup(s) after this */
405 bool chained_before:1; /* call the chained fixup(s) before this */
406 int chain_id;
407 union {
408 const struct hda_pintbl *pins;
409 const struct hda_verb *verbs;
410 void (*func)(struct hda_codec *codec,
411 const struct hda_fixup *fix,
412 int action);
413 } v;
414};
415
416/* fixup types */
417enum {
418 HDA_FIXUP_INVALID,
419 HDA_FIXUP_PINS,
420 HDA_FIXUP_VERBS,
421 HDA_FIXUP_FUNC,
422 HDA_FIXUP_PINCTLS,
423};
424
425/* fixup action definitions */
426enum {
427 HDA_FIXUP_ACT_PRE_PROBE,
428 HDA_FIXUP_ACT_PROBE,
429 HDA_FIXUP_ACT_INIT,
430 HDA_FIXUP_ACT_BUILD,
431};
432
433int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
434void snd_hda_apply_verbs(struct hda_codec *codec);
435void snd_hda_apply_pincfgs(struct hda_codec *codec,
436 const struct hda_pintbl *cfg);
437void snd_hda_apply_fixup(struct hda_codec *codec, int action);
438void snd_hda_pick_fixup(struct hda_codec *codec,
439 const struct hda_model_fixup *models,
440 const struct snd_pci_quirk *quirk,
441 const struct hda_fixup *fixlist);
442
443/*
387 * unsolicited event handler 444 * unsolicited event handler
388 */ 445 */
389 446
@@ -431,6 +488,8 @@ struct hda_bus_unsolicited {
431#define PIN_HP_AMP (AC_PINCTL_HP_EN) 488#define PIN_HP_AMP (AC_PINCTL_HP_EN)
432 489
433unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin); 490unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
491unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
492 hda_nid_t pin, unsigned int val);
434int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, 493int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
435 unsigned int val, bool cached); 494 unsigned int val, bool cached);
436 495
@@ -470,6 +529,10 @@ snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
470 return _snd_hda_set_pin_ctl(codec, pin, val, true); 529 return _snd_hda_set_pin_ctl(codec, pin, val, true);
471} 530}
472 531
532int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid);
533int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
534 unsigned int val);
535
473/* 536/*
474 * get widget capabilities 537 * get widget capabilities
475 */ 538 */
@@ -552,6 +615,7 @@ static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
552#ifdef CONFIG_SND_HDA_RECONFIG 615#ifdef CONFIG_SND_HDA_RECONFIG
553const char *snd_hda_get_hint(struct hda_codec *codec, const char *key); 616const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
554int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key); 617int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
618int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp);
555#else 619#else
556static inline 620static inline
557const char *snd_hda_get_hint(struct hda_codec *codec, const char *key) 621const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
@@ -564,6 +628,12 @@ int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
564{ 628{
565 return -ENOENT; 629 return -ENOENT;
566} 630}
631
632static inline
633int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
634{
635 return -ENOENT;
636}
567#endif 637#endif
568 638
569/* 639/*
@@ -587,6 +657,19 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
587 struct hda_loopback_check *check, 657 struct hda_loopback_check *check,
588 hda_nid_t nid); 658 hda_nid_t nid);
589 659
660/* check whether the actual power state matches with the target state */
661static inline bool
662snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
663 unsigned int target_state)
664{
665 unsigned int state = snd_hda_codec_read(codec, nid, 0,
666 AC_VERB_GET_POWER_STATE, 0);
667 if (state & AC_PWRST_ERROR)
668 return true;
669 state = (state >> 4) & 0x0f;
670 return (state != target_state);
671}
672
590/* 673/*
591 * AMP control callbacks 674 * AMP control callbacks
592 */ 675 */
@@ -596,7 +679,8 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
596#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3) 679#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
597#define get_amp_direction_(pv) (((pv) >> 18) & 0x1) 680#define get_amp_direction_(pv) (((pv) >> 18) & 0x1)
598#define get_amp_direction(kc) get_amp_direction_((kc)->private_value) 681#define get_amp_direction(kc) get_amp_direction_((kc)->private_value)
599#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf) 682#define get_amp_index_(pv) (((pv) >> 19) & 0xf)
683#define get_amp_index(kc) get_amp_index_((kc)->private_value)
600#define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f) 684#define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
601#define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1) 685#define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
602 686
@@ -629,10 +713,10 @@ struct cea_sad {
629/* 713/*
630 * ELD: EDID Like Data 714 * ELD: EDID Like Data
631 */ 715 */
632struct hdmi_eld { 716struct parsed_hdmi_eld {
633 bool monitor_present; 717 /*
634 bool eld_valid; 718 * all fields will be cleared before updating ELD
635 int eld_size; 719 */
636 int baseline_len; 720 int baseline_len;
637 int eld_ver; 721 int eld_ver;
638 int cea_edid_ver; 722 int cea_edid_ver;
@@ -647,19 +731,27 @@ struct hdmi_eld {
647 int spk_alloc; 731 int spk_alloc;
648 int sad_count; 732 int sad_count;
649 struct cea_sad sad[ELD_MAX_SAD]; 733 struct cea_sad sad[ELD_MAX_SAD];
650 /* 734};
651 * all fields above eld_buffer will be cleared before updating ELD 735
652 */ 736struct hdmi_eld {
737 bool monitor_present;
738 bool eld_valid;
739 int eld_size;
653 char eld_buffer[ELD_MAX_SIZE]; 740 char eld_buffer[ELD_MAX_SIZE];
741 struct parsed_hdmi_eld info;
742 struct mutex lock;
654#ifdef CONFIG_PROC_FS 743#ifdef CONFIG_PROC_FS
655 struct snd_info_entry *proc_entry; 744 struct snd_info_entry *proc_entry;
656#endif 745#endif
657}; 746};
658 747
659int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid); 748int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
660int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t); 749int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
661void snd_hdmi_show_eld(struct hdmi_eld *eld); 750 unsigned char *buf, int *eld_size);
662void snd_hdmi_eld_update_pcm_info(struct hdmi_eld *eld, 751int snd_hdmi_parse_eld(struct parsed_hdmi_eld *e,
752 const unsigned char *buf, int size);
753void snd_hdmi_show_eld(struct parsed_hdmi_eld *e);
754void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
663 struct hda_pcm_stream *hinfo); 755 struct hda_pcm_stream *hinfo);
664 756
665#ifdef CONFIG_PROC_FS 757#ifdef CONFIG_PROC_FS
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 045e5d32f5de..0fee8fae590a 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h>
25#include <sound/core.h> 26#include <sound/core.h>
26#include "hda_codec.h" 27#include "hda_codec.h"
27#include "hda_local.h" 28#include "hda_local.h"
@@ -138,16 +139,17 @@ static void print_amp_vals(struct snd_info_buffer *buffer,
138 dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT; 139 dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
139 for (i = 0; i < indices; i++) { 140 for (i = 0; i < indices; i++) {
140 snd_iprintf(buffer, " ["); 141 snd_iprintf(buffer, " [");
142 val = snd_hda_codec_read(codec, nid, 0,
143 AC_VERB_GET_AMP_GAIN_MUTE,
144 AC_AMP_GET_LEFT | dir | i);
145 snd_iprintf(buffer, "0x%02x", val);
141 if (stereo) { 146 if (stereo) {
142 val = snd_hda_codec_read(codec, nid, 0, 147 val = snd_hda_codec_read(codec, nid, 0,
143 AC_VERB_GET_AMP_GAIN_MUTE, 148 AC_VERB_GET_AMP_GAIN_MUTE,
144 AC_AMP_GET_LEFT | dir | i); 149 AC_AMP_GET_RIGHT | dir | i);
145 snd_iprintf(buffer, "0x%02x ", val); 150 snd_iprintf(buffer, " 0x%02x", val);
146 } 151 }
147 val = snd_hda_codec_read(codec, nid, 0, 152 snd_iprintf(buffer, "]");
148 AC_VERB_GET_AMP_GAIN_MUTE,
149 AC_AMP_GET_RIGHT | dir | i);
150 snd_iprintf(buffer, "0x%02x]", val);
151 } 153 }
152 snd_iprintf(buffer, "\n"); 154 snd_iprintf(buffer, "\n");
153} 155}
@@ -603,6 +605,8 @@ static void print_codec_info(struct snd_info_entry *entry,
603 print_amp_caps(buffer, codec, codec->afg, HDA_INPUT); 605 print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
604 snd_iprintf(buffer, "Default Amp-Out caps: "); 606 snd_iprintf(buffer, "Default Amp-Out caps: ");
605 print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT); 607 print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
608 snd_iprintf(buffer, "State of AFG node 0x%02x:\n", codec->afg);
609 print_power_state(buffer, codec, codec->afg);
606 610
607 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 611 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
608 if (! nid || nodes < 0) { 612 if (! nid || nodes < 0) {
@@ -620,7 +624,7 @@ static void print_codec_info(struct snd_info_entry *entry,
620 snd_hda_param_read(codec, nid, 624 snd_hda_param_read(codec, nid,
621 AC_PAR_AUDIO_WIDGET_CAP); 625 AC_PAR_AUDIO_WIDGET_CAP);
622 unsigned int wid_type = get_wcaps_type(wid_caps); 626 unsigned int wid_type = get_wcaps_type(wid_caps);
623 hda_nid_t conn[HDA_MAX_CONNECTIONS]; 627 hda_nid_t *conn = NULL;
624 int conn_len = 0; 628 int conn_len = 0;
625 629
626 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid, 630 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
@@ -657,9 +661,18 @@ static void print_codec_info(struct snd_info_entry *entry,
657 if (wid_type == AC_WID_VOL_KNB) 661 if (wid_type == AC_WID_VOL_KNB)
658 wid_caps |= AC_WCAP_CONN_LIST; 662 wid_caps |= AC_WCAP_CONN_LIST;
659 663
660 if (wid_caps & AC_WCAP_CONN_LIST) 664 if (wid_caps & AC_WCAP_CONN_LIST) {
661 conn_len = snd_hda_get_raw_connections(codec, nid, conn, 665 conn_len = snd_hda_get_num_raw_conns(codec, nid);
662 HDA_MAX_CONNECTIONS); 666 if (conn_len > 0) {
667 conn = kmalloc(sizeof(hda_nid_t) * conn_len,
668 GFP_KERNEL);
669 if (!conn)
670 return;
671 if (snd_hda_get_raw_connections(codec, nid, conn,
672 conn_len) < 0)
673 conn_len = 0;
674 }
675 }
663 676
664 if (wid_caps & AC_WCAP_IN_AMP) { 677 if (wid_caps & AC_WCAP_IN_AMP) {
665 snd_iprintf(buffer, " Amp-In caps: "); 678 snd_iprintf(buffer, " Amp-In caps: ");
@@ -732,6 +745,8 @@ static void print_codec_info(struct snd_info_entry *entry,
732 745
733 if (codec->proc_widget_hook) 746 if (codec->proc_widget_hook)
734 codec->proc_widget_hook(buffer, codec, nid); 747 codec->proc_widget_hook(buffer, codec, nid);
748
749 kfree(conn);
735 } 750 }
736 snd_hda_power_down(codec); 751 snd_hda_power_down(codec);
737} 752}
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 89fc5030ec79..df8014b27596 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -20,7 +20,6 @@
20 */ 20 */
21 21
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25#include <linux/pci.h> 24#include <linux/pci.h>
26#include <linux/module.h> 25#include <linux/module.h>
@@ -31,11 +30,24 @@
31#include "hda_auto_parser.h" 30#include "hda_auto_parser.h"
32#include "hda_beep.h" 31#include "hda_beep.h"
33#include "hda_jack.h" 32#include "hda_jack.h"
33#include "hda_generic.h"
34
35#define ENABLE_AD_STATIC_QUIRKS
34 36
35struct ad198x_spec { 37struct ad198x_spec {
38 struct hda_gen_spec gen;
39
40 /* for auto parser */
41 int smux_paths[4];
42 unsigned int cur_smux;
43 hda_nid_t eapd_nid;
44
45 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
46 hda_nid_t beep_dev_nid;
47
48#ifdef ENABLE_AD_STATIC_QUIRKS
36 const struct snd_kcontrol_new *mixers[6]; 49 const struct snd_kcontrol_new *mixers[6];
37 int num_mixers; 50 int num_mixers;
38 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
39 const struct hda_verb *init_verbs[6]; /* initialization verbs 51 const struct hda_verb *init_verbs[6]; /* initialization verbs
40 * don't forget NULL termination! 52 * don't forget NULL termination!
41 */ 53 */
@@ -49,11 +61,6 @@ struct ad198x_spec {
49 unsigned int cur_eapd; 61 unsigned int cur_eapd;
50 unsigned int need_dac_fix; 62 unsigned int need_dac_fix;
51 63
52 const hda_nid_t *alt_dac_nid;
53 const struct hda_pcm_stream *stream_analog_alt_playback;
54 int independent_hp;
55 int num_active_streams;
56
57 /* capture */ 64 /* capture */
58 unsigned int num_adc_nids; 65 unsigned int num_adc_nids;
59 const hda_nid_t *adc_nids; 66 const hda_nid_t *adc_nids;
@@ -73,15 +80,8 @@ struct ad198x_spec {
73 80
74 unsigned int spdif_route; 81 unsigned int spdif_route;
75 82
76 /* dynamic controls, init_verbs and input_mux */
77 struct auto_pin_cfg autocfg;
78 struct snd_array kctls;
79 struct hda_input_mux private_imux;
80 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
81
82 unsigned int jack_present: 1; 83 unsigned int jack_present: 1;
83 unsigned int inv_jack_detect: 1;/* inverted jack-detection */ 84 unsigned int inv_jack_detect: 1;/* inverted jack-detection */
84 unsigned int inv_eapd: 1; /* inverted EAPD implementation */
85 unsigned int analog_beep: 1; /* analog beep input present */ 85 unsigned int analog_beep: 1; /* analog beep input present */
86 unsigned int avoid_init_slave_vol:1; 86 unsigned int avoid_init_slave_vol:1;
87 87
@@ -92,8 +92,10 @@ struct ad198x_spec {
92 hda_nid_t vmaster_nid; 92 hda_nid_t vmaster_nid;
93 const char * const *slave_vols; 93 const char * const *slave_vols;
94 const char * const *slave_sws; 94 const char * const *slave_sws;
95#endif /* ENABLE_AD_STATIC_QUIRKS */
95}; 96};
96 97
98#ifdef ENABLE_AD_STATIC_QUIRKS
97/* 99/*
98 * input MUX handling (common part) 100 * input MUX handling (common part)
99 */ 101 */
@@ -149,8 +151,7 @@ static const char * const ad1988_6stack_fp_slave_pfxs[] = {
149 "Front", "Surround", "Center", "LFE", "Side", "IEC958", 151 "Front", "Surround", "Center", "LFE", "Side", "IEC958",
150 NULL 152 NULL
151}; 153};
152 154#endif /* ENABLE_AD_STATIC_QUIRKS */
153static void ad198x_free_kctls(struct hda_codec *codec);
154 155
155#ifdef CONFIG_SND_HDA_INPUT_BEEP 156#ifdef CONFIG_SND_HDA_INPUT_BEEP
156/* additional beep mixers; the actual parameters are overwritten at build */ 157/* additional beep mixers; the actual parameters are overwritten at build */
@@ -172,6 +173,34 @@ static const struct snd_kcontrol_new ad_beep2_mixer[] = {
172#define set_beep_amp(spec, nid, idx, dir) /* NOP */ 173#define set_beep_amp(spec, nid, idx, dir) /* NOP */
173#endif 174#endif
174 175
176#ifdef CONFIG_SND_HDA_INPUT_BEEP
177static int create_beep_ctls(struct hda_codec *codec)
178{
179 struct ad198x_spec *spec = codec->spec;
180 const struct snd_kcontrol_new *knew;
181
182 if (!spec->beep_amp)
183 return 0;
184
185 knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
186 for ( ; knew->name; knew++) {
187 int err;
188 struct snd_kcontrol *kctl;
189 kctl = snd_ctl_new1(knew, codec);
190 if (!kctl)
191 return -ENOMEM;
192 kctl->private_value = spec->beep_amp;
193 err = snd_hda_ctl_add(codec, 0, kctl);
194 if (err < 0)
195 return err;
196 }
197 return 0;
198}
199#else
200#define create_beep_ctls(codec) 0
201#endif
202
203#ifdef ENABLE_AD_STATIC_QUIRKS
175static int ad198x_build_controls(struct hda_codec *codec) 204static int ad198x_build_controls(struct hda_codec *codec)
176{ 205{
177 struct ad198x_spec *spec = codec->spec; 206 struct ad198x_spec *spec = codec->spec;
@@ -203,22 +232,9 @@ static int ad198x_build_controls(struct hda_codec *codec)
203 } 232 }
204 233
205 /* create beep controls if needed */ 234 /* create beep controls if needed */
206#ifdef CONFIG_SND_HDA_INPUT_BEEP 235 err = create_beep_ctls(codec);
207 if (spec->beep_amp) { 236 if (err < 0)
208 const struct snd_kcontrol_new *knew; 237 return err;
209 knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
210 for ( ; knew->name; knew++) {
211 struct snd_kcontrol *kctl;
212 kctl = snd_ctl_new1(knew, codec);
213 if (!kctl)
214 return -ENOMEM;
215 kctl->private_value = spec->beep_amp;
216 err = snd_hda_ctl_add(codec, 0, kctl);
217 if (err < 0)
218 return err;
219 }
220 }
221#endif
222 238
223 /* if we have no master control, let's create it */ 239 /* if we have no master control, let's create it */
224 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 240 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
@@ -244,8 +260,6 @@ static int ad198x_build_controls(struct hda_codec *codec)
244 return err; 260 return err;
245 } 261 }
246 262
247 ad198x_free_kctls(codec); /* no longer needed */
248
249 /* assign Capture Source enums to NID */ 263 /* assign Capture Source enums to NID */
250 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source"); 264 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
251 if (!kctl) 265 if (!kctl)
@@ -277,72 +291,6 @@ static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
277} 291}
278#endif 292#endif
279 293
280static void activate_ctl(struct hda_codec *codec, const char *name, int active)
281{
282 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
283 if (ctl) {
284 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
285 ctl->vd[0].access |= active ? 0 :
286 SNDRV_CTL_ELEM_ACCESS_INACTIVE;
287 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE;
288 ctl->vd[0].access |= active ?
289 SNDRV_CTL_ELEM_ACCESS_WRITE : 0;
290 snd_ctl_notify(codec->bus->card,
291 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
292 }
293}
294
295static void set_stream_active(struct hda_codec *codec, bool active)
296{
297 struct ad198x_spec *spec = codec->spec;
298 if (active)
299 spec->num_active_streams++;
300 else
301 spec->num_active_streams--;
302 activate_ctl(codec, "Independent HP", spec->num_active_streams == 0);
303}
304
305static int ad1988_independent_hp_info(struct snd_kcontrol *kcontrol,
306 struct snd_ctl_elem_info *uinfo)
307{
308 static const char * const texts[] = { "OFF", "ON", NULL};
309 int index;
310 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
311 uinfo->count = 1;
312 uinfo->value.enumerated.items = 2;
313 index = uinfo->value.enumerated.item;
314 if (index >= 2)
315 index = 1;
316 strcpy(uinfo->value.enumerated.name, texts[index]);
317 return 0;
318}
319
320static int ad1988_independent_hp_get(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_value *ucontrol)
322{
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 struct ad198x_spec *spec = codec->spec;
325 ucontrol->value.enumerated.item[0] = spec->independent_hp;
326 return 0;
327}
328
329static int ad1988_independent_hp_put(struct snd_kcontrol *kcontrol,
330 struct snd_ctl_elem_value *ucontrol)
331{
332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
333 struct ad198x_spec *spec = codec->spec;
334 unsigned int select = ucontrol->value.enumerated.item[0];
335 if (spec->independent_hp != select) {
336 spec->independent_hp = select;
337 if (spec->independent_hp)
338 spec->multiout.hp_nid = 0;
339 else
340 spec->multiout.hp_nid = spec->alt_dac_nid[0];
341 return 1;
342 }
343 return 0;
344}
345
346/* 294/*
347 * Analog playback callbacks 295 * Analog playback callbacks
348 */ 296 */
@@ -351,15 +299,8 @@ static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
351 struct snd_pcm_substream *substream) 299 struct snd_pcm_substream *substream)
352{ 300{
353 struct ad198x_spec *spec = codec->spec; 301 struct ad198x_spec *spec = codec->spec;
354 int err; 302 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
355 set_stream_active(codec, true);
356 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
357 hinfo); 303 hinfo);
358 if (err < 0) {
359 set_stream_active(codec, false);
360 return err;
361 }
362 return 0;
363} 304}
364 305
365static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 306static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -381,43 +322,6 @@ static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
381 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 322 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
382} 323}
383 324
384static int ad198x_playback_pcm_close(struct hda_pcm_stream *hinfo,
385 struct hda_codec *codec,
386 struct snd_pcm_substream *substream)
387{
388 set_stream_active(codec, false);
389 return 0;
390}
391
392static int ad1988_alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
393 struct hda_codec *codec,
394 struct snd_pcm_substream *substream)
395{
396 struct ad198x_spec *spec = codec->spec;
397 if (!spec->independent_hp)
398 return -EBUSY;
399 set_stream_active(codec, true);
400 return 0;
401}
402
403static int ad1988_alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
404 struct hda_codec *codec,
405 struct snd_pcm_substream *substream)
406{
407 set_stream_active(codec, false);
408 return 0;
409}
410
411static const struct hda_pcm_stream ad198x_pcm_analog_alt_playback = {
412 .substreams = 1,
413 .channels_min = 2,
414 .channels_max = 2,
415 .ops = {
416 .open = ad1988_alt_playback_pcm_open,
417 .close = ad1988_alt_playback_pcm_close
418 },
419};
420
421/* 325/*
422 * Digital out 326 * Digital out
423 */ 327 */
@@ -491,7 +395,6 @@ static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
491 .open = ad198x_playback_pcm_open, 395 .open = ad198x_playback_pcm_open,
492 .prepare = ad198x_playback_pcm_prepare, 396 .prepare = ad198x_playback_pcm_prepare,
493 .cleanup = ad198x_playback_pcm_cleanup, 397 .cleanup = ad198x_playback_pcm_cleanup,
494 .close = ad198x_playback_pcm_close
495 }, 398 },
496}; 399};
497 400
@@ -556,43 +459,19 @@ static int ad198x_build_pcms(struct hda_codec *codec)
556 } 459 }
557 } 460 }
558 461
559 if (spec->alt_dac_nid && spec->stream_analog_alt_playback) {
560 codec->num_pcms++;
561 info = spec->pcm_rec + 2;
562 info->name = "AD198x Headphone";
563 info->pcm_type = HDA_PCM_TYPE_AUDIO;
564 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
565 *spec->stream_analog_alt_playback;
566 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
567 spec->alt_dac_nid[0];
568 }
569
570 return 0; 462 return 0;
571} 463}
572 464#endif /* ENABLE_AD_STATIC_QUIRKS */
573static void ad198x_free_kctls(struct hda_codec *codec)
574{
575 struct ad198x_spec *spec = codec->spec;
576
577 if (spec->kctls.list) {
578 struct snd_kcontrol_new *kctl = spec->kctls.list;
579 int i;
580 for (i = 0; i < spec->kctls.used; i++)
581 kfree(kctl[i].name);
582 }
583 snd_array_free(&spec->kctls);
584}
585 465
586static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front, 466static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
587 hda_nid_t hp) 467 hda_nid_t hp)
588{ 468{
589 struct ad198x_spec *spec = codec->spec;
590 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD) 469 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
591 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE, 470 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
592 !spec->inv_eapd ? 0x00 : 0x02); 471 !codec->inv_eapd ? 0x00 : 0x02);
593 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD) 472 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
594 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE, 473 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
595 !spec->inv_eapd ? 0x00 : 0x02); 474 !codec->inv_eapd ? 0x00 : 0x02);
596} 475}
597 476
598static void ad198x_power_eapd(struct hda_codec *codec) 477static void ad198x_power_eapd(struct hda_codec *codec)
@@ -636,7 +515,7 @@ static void ad198x_free(struct hda_codec *codec)
636 if (!spec) 515 if (!spec)
637 return; 516 return;
638 517
639 ad198x_free_kctls(codec); 518 snd_hda_gen_spec_free(&spec->gen);
640 kfree(spec); 519 kfree(spec);
641 snd_hda_detach_beep_device(codec); 520 snd_hda_detach_beep_device(codec);
642} 521}
@@ -649,6 +528,7 @@ static int ad198x_suspend(struct hda_codec *codec)
649} 528}
650#endif 529#endif
651 530
531#ifdef ENABLE_AD_STATIC_QUIRKS
652static const struct hda_codec_ops ad198x_patch_ops = { 532static const struct hda_codec_ops ad198x_patch_ops = {
653 .build_controls = ad198x_build_controls, 533 .build_controls = ad198x_build_controls,
654 .build_pcms = ad198x_build_pcms, 534 .build_pcms = ad198x_build_pcms,
@@ -673,7 +553,7 @@ static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
673{ 553{
674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
675 struct ad198x_spec *spec = codec->spec; 555 struct ad198x_spec *spec = codec->spec;
676 if (spec->inv_eapd) 556 if (codec->inv_eapd)
677 ucontrol->value.integer.value[0] = ! spec->cur_eapd; 557 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
678 else 558 else
679 ucontrol->value.integer.value[0] = spec->cur_eapd; 559 ucontrol->value.integer.value[0] = spec->cur_eapd;
@@ -688,7 +568,7 @@ static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
688 hda_nid_t nid = kcontrol->private_value & 0xff; 568 hda_nid_t nid = kcontrol->private_value & 0xff;
689 unsigned int eapd; 569 unsigned int eapd;
690 eapd = !!ucontrol->value.integer.value[0]; 570 eapd = !!ucontrol->value.integer.value[0];
691 if (spec->inv_eapd) 571 if (codec->inv_eapd)
692 eapd = !eapd; 572 eapd = !eapd;
693 if (eapd == spec->cur_eapd) 573 if (eapd == spec->cur_eapd)
694 return 0; 574 return 0;
@@ -705,12 +585,75 @@ static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
705 struct snd_ctl_elem_value *ucontrol); 585 struct snd_ctl_elem_value *ucontrol);
706static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol, 586static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
707 struct snd_ctl_elem_value *ucontrol); 587 struct snd_ctl_elem_value *ucontrol);
588#endif /* ENABLE_AD_STATIC_QUIRKS */
589
590
591/*
592 * Automatic parse of I/O pins from the BIOS configuration
593 */
594
595static int ad198x_auto_build_controls(struct hda_codec *codec)
596{
597 int err;
598
599 err = snd_hda_gen_build_controls(codec);
600 if (err < 0)
601 return err;
602 err = create_beep_ctls(codec);
603 if (err < 0)
604 return err;
605 return 0;
606}
607
608static const struct hda_codec_ops ad198x_auto_patch_ops = {
609 .build_controls = ad198x_auto_build_controls,
610 .build_pcms = snd_hda_gen_build_pcms,
611 .init = snd_hda_gen_init,
612 .free = ad198x_free,
613 .unsol_event = snd_hda_jack_unsol_event,
614#ifdef CONFIG_PM
615 .check_power_status = snd_hda_gen_check_power_status,
616 .suspend = ad198x_suspend,
617#endif
618 .reboot_notify = ad198x_shutup,
619};
620
621
622static int ad198x_parse_auto_config(struct hda_codec *codec)
623{
624 struct ad198x_spec *spec = codec->spec;
625 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
626 int err;
627
628 codec->spdif_status_reset = 1;
629 codec->no_trigger_sense = 1;
630 codec->no_sticky_stream = 1;
631
632 spec->gen.indep_hp = 1;
633
634 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
635 if (err < 0)
636 return err;
637 err = snd_hda_gen_parse_auto_config(codec, cfg);
638 if (err < 0)
639 return err;
640
641 if (spec->beep_dev_nid) {
642 err = snd_hda_attach_beep_device(codec, spec->beep_dev_nid);
643 if (err < 0)
644 return err;
645 }
708 646
647 codec->patch_ops = ad198x_auto_patch_ops;
648
649 return 0;
650}
709 651
710/* 652/*
711 * AD1986A specific 653 * AD1986A specific
712 */ 654 */
713 655
656#ifdef ENABLE_AD_STATIC_QUIRKS
714#define AD1986A_SPDIF_OUT 0x02 657#define AD1986A_SPDIF_OUT 0x02
715#define AD1986A_FRONT_DAC 0x03 658#define AD1986A_FRONT_DAC 0x03
716#define AD1986A_SURR_DAC 0x04 659#define AD1986A_SURR_DAC 0x04
@@ -995,15 +938,7 @@ static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
995 struct snd_ctl_elem_value *ucontrol) 938 struct snd_ctl_elem_value *ucontrol)
996{ 939{
997 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 940 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
998 long *valp = ucontrol->value.integer.value; 941 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
999 int change;
1000
1001 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
1002 HDA_AMP_MUTE,
1003 valp[0] ? 0 : HDA_AMP_MUTE);
1004 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
1005 HDA_AMP_MUTE,
1006 valp[1] ? 0 : HDA_AMP_MUTE);
1007 if (change) 942 if (change)
1008 ad1986a_update_hp(codec); 943 ad1986a_update_hp(codec);
1009 return change; 944 return change;
@@ -1176,6 +1111,7 @@ static int ad1986a_samsung_p50_init(struct hda_codec *codec)
1176 1111
1177/* models */ 1112/* models */
1178enum { 1113enum {
1114 AD1986A_AUTO,
1179 AD1986A_6STACK, 1115 AD1986A_6STACK,
1180 AD1986A_3STACK, 1116 AD1986A_3STACK,
1181 AD1986A_LAPTOP, 1117 AD1986A_LAPTOP,
@@ -1188,6 +1124,7 @@ enum {
1188}; 1124};
1189 1125
1190static const char * const ad1986a_models[AD1986A_MODELS] = { 1126static const char * const ad1986a_models[AD1986A_MODELS] = {
1127 [AD1986A_AUTO] = "auto",
1191 [AD1986A_6STACK] = "6stack", 1128 [AD1986A_6STACK] = "6stack",
1192 [AD1986A_3STACK] = "3stack", 1129 [AD1986A_3STACK] = "3stack",
1193 [AD1986A_LAPTOP] = "laptop", 1130 [AD1986A_LAPTOP] = "laptop",
@@ -1245,6 +1182,7 @@ static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1245 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid); 1182 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
1246 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE; 1183 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1247} 1184}
1185#endif /* ENABLE_AD_STATIC_QUIRKS */
1248 1186
1249static int alloc_ad_spec(struct hda_codec *codec) 1187static int alloc_ad_spec(struct hda_codec *codec)
1250{ 1188{
@@ -1254,15 +1192,97 @@ static int alloc_ad_spec(struct hda_codec *codec)
1254 if (!spec) 1192 if (!spec)
1255 return -ENOMEM; 1193 return -ENOMEM;
1256 codec->spec = spec; 1194 codec->spec = spec;
1257 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); 1195 snd_hda_gen_spec_init(&spec->gen);
1196 return 0;
1197}
1198
1199/*
1200 * AD1986A fixup codes
1201 */
1202
1203/* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
1204static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
1205 const struct hda_fixup *fix, int action)
1206{
1207 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1208 codec->inv_jack_detect = 1;
1209}
1210
1211enum {
1212 AD1986A_FIXUP_INV_JACK_DETECT,
1213};
1214
1215static const struct hda_fixup ad1986a_fixups[] = {
1216 [AD1986A_FIXUP_INV_JACK_DETECT] = {
1217 .type = HDA_FIXUP_FUNC,
1218 .v.func = ad_fixup_inv_jack_detect,
1219 },
1220};
1221
1222static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
1223 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
1224 {}
1225};
1226
1227/*
1228 */
1229static int ad1986a_parse_auto_config(struct hda_codec *codec)
1230{
1231 int err;
1232 struct ad198x_spec *spec;
1233
1234 err = alloc_ad_spec(codec);
1235 if (err < 0)
1236 return err;
1237 spec = codec->spec;
1238
1239 /* AD1986A has the inverted EAPD implementation */
1240 codec->inv_eapd = 1;
1241
1242 spec->gen.mixer_nid = 0x07;
1243 spec->beep_dev_nid = 0x19;
1244 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1245
1246 /* AD1986A has a hardware problem that it can't share a stream
1247 * with multiple output pins. The copy of front to surrounds
1248 * causes noisy or silent outputs at a certain timing, e.g.
1249 * changing the volume.
1250 * So, let's disable the shared stream.
1251 */
1252 spec->gen.multiout.no_share_stream = 1;
1253
1254 snd_hda_pick_fixup(codec, NULL, ad1986a_fixup_tbl, ad1986a_fixups);
1255 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1256
1257 err = ad198x_parse_auto_config(codec);
1258 if (err < 0) {
1259 ad198x_free(codec);
1260 return err;
1261 }
1262
1263 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1264
1258 return 0; 1265 return 0;
1259} 1266}
1260 1267
1268#ifdef ENABLE_AD_STATIC_QUIRKS
1261static int patch_ad1986a(struct hda_codec *codec) 1269static int patch_ad1986a(struct hda_codec *codec)
1262{ 1270{
1263 struct ad198x_spec *spec; 1271 struct ad198x_spec *spec;
1264 int err, board_config; 1272 int err, board_config;
1265 1273
1274 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1275 ad1986a_models,
1276 ad1986a_cfg_tbl);
1277 if (board_config < 0) {
1278 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
1279 codec->chip_name);
1280 board_config = AD1986A_AUTO;
1281 }
1282
1283 if (board_config == AD1986A_AUTO)
1284 return ad1986a_parse_auto_config(codec);
1285
1266 err = alloc_ad_spec(codec); 1286 err = alloc_ad_spec(codec);
1267 if (err < 0) 1287 if (err < 0)
1268 return err; 1288 return err;
@@ -1291,14 +1311,11 @@ static int patch_ad1986a(struct hda_codec *codec)
1291 spec->loopback.amplist = ad1986a_loopbacks; 1311 spec->loopback.amplist = ad1986a_loopbacks;
1292#endif 1312#endif
1293 spec->vmaster_nid = 0x1b; 1313 spec->vmaster_nid = 0x1b;
1294 spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */ 1314 codec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
1295 1315
1296 codec->patch_ops = ad198x_patch_ops; 1316 codec->patch_ops = ad198x_patch_ops;
1297 1317
1298 /* override some parameters */ 1318 /* override some parameters */
1299 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1300 ad1986a_models,
1301 ad1986a_cfg_tbl);
1302 switch (board_config) { 1319 switch (board_config) {
1303 case AD1986A_3STACK: 1320 case AD1986A_3STACK:
1304 spec->num_mixers = 2; 1321 spec->num_mixers = 2;
@@ -1409,11 +1426,15 @@ static int patch_ad1986a(struct hda_codec *codec)
1409 1426
1410 return 0; 1427 return 0;
1411} 1428}
1429#else /* ENABLE_AD_STATIC_QUIRKS */
1430#define patch_ad1986a ad1986a_parse_auto_config
1431#endif /* ENABLE_AD_STATIC_QUIRKS */
1412 1432
1413/* 1433/*
1414 * AD1983 specific 1434 * AD1983 specific
1415 */ 1435 */
1416 1436
1437#ifdef ENABLE_AD_STATIC_QUIRKS
1417#define AD1983_SPDIF_OUT 0x02 1438#define AD1983_SPDIF_OUT 0x02
1418#define AD1983_DAC 0x03 1439#define AD1983_DAC 0x03
1419#define AD1983_ADC 0x04 1440#define AD1983_ADC 0x04
@@ -1554,11 +1575,137 @@ static const struct hda_amp_list ad1983_loopbacks[] = {
1554}; 1575};
1555#endif 1576#endif
1556 1577
1578/* models */
1579enum {
1580 AD1983_AUTO,
1581 AD1983_BASIC,
1582 AD1983_MODELS
1583};
1584
1585static const char * const ad1983_models[AD1983_MODELS] = {
1586 [AD1983_AUTO] = "auto",
1587 [AD1983_BASIC] = "basic",
1588};
1589#endif /* ENABLE_AD_STATIC_QUIRKS */
1590
1591
1592/*
1593 * SPDIF mux control for AD1983 auto-parser
1594 */
1595static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
1596 struct snd_ctl_elem_info *uinfo)
1597{
1598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1599 struct ad198x_spec *spec = codec->spec;
1600 static const char * const texts2[] = { "PCM", "ADC" };
1601 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
1602 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
1603 int num_conns = snd_hda_get_num_conns(codec, dig_out);
1604
1605 if (num_conns == 2)
1606 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
1607 else if (num_conns == 3)
1608 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
1609 else
1610 return -EINVAL;
1611}
1612
1613static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
1614 struct snd_ctl_elem_value *ucontrol)
1615{
1616 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1617 struct ad198x_spec *spec = codec->spec;
1618
1619 ucontrol->value.enumerated.item[0] = spec->cur_smux;
1620 return 0;
1621}
1622
1623static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1625{
1626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1627 struct ad198x_spec *spec = codec->spec;
1628 unsigned int val = ucontrol->value.enumerated.item[0];
1629 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
1630 int num_conns = snd_hda_get_num_conns(codec, dig_out);
1631
1632 if (val >= num_conns)
1633 return -EINVAL;
1634 if (spec->cur_smux == val)
1635 return 0;
1636 spec->cur_smux = val;
1637 snd_hda_codec_write_cache(codec, dig_out, 0,
1638 AC_VERB_SET_CONNECT_SEL, val);
1639 return 1;
1640}
1641
1642static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
1643 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1644 .name = "IEC958 Playback Source",
1645 .info = ad1983_auto_smux_enum_info,
1646 .get = ad1983_auto_smux_enum_get,
1647 .put = ad1983_auto_smux_enum_put,
1648};
1649
1650static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
1651{
1652 struct ad198x_spec *spec = codec->spec;
1653 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
1654 int num_conns;
1655
1656 if (!dig_out)
1657 return 0;
1658 num_conns = snd_hda_get_num_conns(codec, dig_out);
1659 if (num_conns != 2 && num_conns != 3)
1660 return 0;
1661 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
1662 return -ENOMEM;
1663 return 0;
1664}
1665
1666static int ad1983_parse_auto_config(struct hda_codec *codec)
1667{
1668 struct ad198x_spec *spec;
1669 int err;
1670
1671 err = alloc_ad_spec(codec);
1672 if (err < 0)
1673 return err;
1674 spec = codec->spec;
1675
1676 spec->beep_dev_nid = 0x10;
1677 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1678 err = ad198x_parse_auto_config(codec);
1679 if (err < 0)
1680 goto error;
1681 err = ad1983_add_spdif_mux_ctl(codec);
1682 if (err < 0)
1683 goto error;
1684 return 0;
1685
1686 error:
1687 ad198x_free(codec);
1688 return err;
1689}
1690
1691#ifdef ENABLE_AD_STATIC_QUIRKS
1557static int patch_ad1983(struct hda_codec *codec) 1692static int patch_ad1983(struct hda_codec *codec)
1558{ 1693{
1559 struct ad198x_spec *spec; 1694 struct ad198x_spec *spec;
1695 int board_config;
1560 int err; 1696 int err;
1561 1697
1698 board_config = snd_hda_check_board_config(codec, AD1983_MODELS,
1699 ad1983_models, NULL);
1700 if (board_config < 0) {
1701 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
1702 codec->chip_name);
1703 board_config = AD1983_AUTO;
1704 }
1705
1706 if (board_config == AD1983_AUTO)
1707 return ad1983_parse_auto_config(codec);
1708
1562 err = alloc_ad_spec(codec); 1709 err = alloc_ad_spec(codec);
1563 if (err < 0) 1710 if (err < 0)
1564 return err; 1711 return err;
@@ -1596,12 +1743,16 @@ static int patch_ad1983(struct hda_codec *codec)
1596 1743
1597 return 0; 1744 return 0;
1598} 1745}
1746#else /* ENABLE_AD_STATIC_QUIRKS */
1747#define patch_ad1983 ad1983_parse_auto_config
1748#endif /* ENABLE_AD_STATIC_QUIRKS */
1599 1749
1600 1750
1601/* 1751/*
1602 * AD1981 HD specific 1752 * AD1981 HD specific
1603 */ 1753 */
1604 1754
1755#ifdef ENABLE_AD_STATIC_QUIRKS
1605#define AD1981_SPDIF_OUT 0x02 1756#define AD1981_SPDIF_OUT 0x02
1606#define AD1981_DAC 0x03 1757#define AD1981_DAC 0x03
1607#define AD1981_ADC 0x04 1758#define AD1981_ADC 0x04
@@ -1932,6 +2083,7 @@ static const struct hda_input_mux ad1981_thinkpad_capture_source = {
1932 2083
1933/* models */ 2084/* models */
1934enum { 2085enum {
2086 AD1981_AUTO,
1935 AD1981_BASIC, 2087 AD1981_BASIC,
1936 AD1981_HP, 2088 AD1981_HP,
1937 AD1981_THINKPAD, 2089 AD1981_THINKPAD,
@@ -1940,6 +2092,7 @@ enum {
1940}; 2092};
1941 2093
1942static const char * const ad1981_models[AD1981_MODELS] = { 2094static const char * const ad1981_models[AD1981_MODELS] = {
2095 [AD1981_AUTO] = "auto",
1943 [AD1981_HP] = "hp", 2096 [AD1981_HP] = "hp",
1944 [AD1981_THINKPAD] = "thinkpad", 2097 [AD1981_THINKPAD] = "thinkpad",
1945 [AD1981_BASIC] = "basic", 2098 [AD1981_BASIC] = "basic",
@@ -1958,12 +2111,122 @@ static const struct snd_pci_quirk ad1981_cfg_tbl[] = {
1958 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP), 2111 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1959 {} 2112 {}
1960}; 2113};
2114#endif /* ENABLE_AD_STATIC_QUIRKS */
2115
2116
2117/* follow EAPD via vmaster hook */
2118static void ad_vmaster_eapd_hook(void *private_data, int enabled)
2119{
2120 struct hda_codec *codec = private_data;
2121 struct ad198x_spec *spec = codec->spec;
2122 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
2123 AC_VERB_SET_EAPD_BTLENABLE,
2124 enabled ? 0x02 : 0x00);
2125}
2126
2127static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
2128 const struct hda_fixup *fix, int action)
2129{
2130 struct ad198x_spec *spec = codec->spec;
2131
2132 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2133 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
2134 spec->eapd_nid = 0x05;
2135 }
2136}
2137
2138/* set the upper-limit for mixer amp to 0dB for avoiding the possible
2139 * damage by overloading
2140 */
2141static void ad1981_fixup_amp_override(struct hda_codec *codec,
2142 const struct hda_fixup *fix, int action)
2143{
2144 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2145 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
2146 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2147 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2148 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2149 (1 << AC_AMPCAP_MUTE_SHIFT));
2150}
2151
2152enum {
2153 AD1981_FIXUP_AMP_OVERRIDE,
2154 AD1981_FIXUP_HP_EAPD,
2155};
2156
2157static const struct hda_fixup ad1981_fixups[] = {
2158 [AD1981_FIXUP_AMP_OVERRIDE] = {
2159 .type = HDA_FIXUP_FUNC,
2160 .v.func = ad1981_fixup_amp_override,
2161 },
2162 [AD1981_FIXUP_HP_EAPD] = {
2163 .type = HDA_FIXUP_FUNC,
2164 .v.func = ad1981_fixup_hp_eapd,
2165 .chained = true,
2166 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
2167 },
2168};
2169
2170static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
2171 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
2172 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
2173 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
2174 /* HP nx6320 (reversed SSID, H/W bug) */
2175 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
2176 {}
2177};
2178
2179static int ad1981_parse_auto_config(struct hda_codec *codec)
2180{
2181 struct ad198x_spec *spec;
2182 int err;
1961 2183
2184 err = alloc_ad_spec(codec);
2185 if (err < 0)
2186 return -ENOMEM;
2187 spec = codec->spec;
2188
2189 spec->gen.mixer_nid = 0x0e;
2190 spec->beep_dev_nid = 0x10;
2191 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
2192
2193 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
2194 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2195
2196 err = ad198x_parse_auto_config(codec);
2197 if (err < 0)
2198 goto error;
2199 err = ad1983_add_spdif_mux_ctl(codec);
2200 if (err < 0)
2201 goto error;
2202
2203 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2204
2205 return 0;
2206
2207 error:
2208 ad198x_free(codec);
2209 return err;
2210}
2211
2212#ifdef ENABLE_AD_STATIC_QUIRKS
1962static int patch_ad1981(struct hda_codec *codec) 2213static int patch_ad1981(struct hda_codec *codec)
1963{ 2214{
1964 struct ad198x_spec *spec; 2215 struct ad198x_spec *spec;
1965 int err, board_config; 2216 int err, board_config;
1966 2217
2218 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
2219 ad1981_models,
2220 ad1981_cfg_tbl);
2221 if (board_config < 0) {
2222 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
2223 codec->chip_name);
2224 board_config = AD1981_AUTO;
2225 }
2226
2227 if (board_config == AD1981_AUTO)
2228 return ad1981_parse_auto_config(codec);
2229
1967 err = alloc_ad_spec(codec); 2230 err = alloc_ad_spec(codec);
1968 if (err < 0) 2231 if (err < 0)
1969 return -ENOMEM; 2232 return -ENOMEM;
@@ -1997,9 +2260,6 @@ static int patch_ad1981(struct hda_codec *codec)
1997 codec->patch_ops = ad198x_patch_ops; 2260 codec->patch_ops = ad198x_patch_ops;
1998 2261
1999 /* override some parameters */ 2262 /* override some parameters */
2000 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
2001 ad1981_models,
2002 ad1981_cfg_tbl);
2003 switch (board_config) { 2263 switch (board_config) {
2004 case AD1981_HP: 2264 case AD1981_HP:
2005 spec->mixers[0] = ad1981_hp_mixers; 2265 spec->mixers[0] = ad1981_hp_mixers;
@@ -2049,6 +2309,9 @@ static int patch_ad1981(struct hda_codec *codec)
2049 2309
2050 return 0; 2310 return 0;
2051} 2311}
2312#else /* ENABLE_AD_STATIC_QUIRKS */
2313#define patch_ad1981 ad1981_parse_auto_config
2314#endif /* ENABLE_AD_STATIC_QUIRKS */
2052 2315
2053 2316
2054/* 2317/*
@@ -2137,15 +2400,16 @@ static int patch_ad1981(struct hda_codec *codec)
2137 */ 2400 */
2138 2401
2139 2402
2403#ifdef ENABLE_AD_STATIC_QUIRKS
2140/* models */ 2404/* models */
2141enum { 2405enum {
2406 AD1988_AUTO,
2142 AD1988_6STACK, 2407 AD1988_6STACK,
2143 AD1988_6STACK_DIG, 2408 AD1988_6STACK_DIG,
2144 AD1988_3STACK, 2409 AD1988_3STACK,
2145 AD1988_3STACK_DIG, 2410 AD1988_3STACK_DIG,
2146 AD1988_LAPTOP, 2411 AD1988_LAPTOP,
2147 AD1988_LAPTOP_DIG, 2412 AD1988_LAPTOP_DIG,
2148 AD1988_AUTO,
2149 AD1988_MODEL_LAST, 2413 AD1988_MODEL_LAST,
2150}; 2414};
2151 2415
@@ -2250,17 +2514,6 @@ static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
2250 return err; 2514 return err;
2251} 2515}
2252 2516
2253static const struct snd_kcontrol_new ad1988_hp_mixers[] = {
2254 {
2255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2256 .name = "Independent HP",
2257 .info = ad1988_independent_hp_info,
2258 .get = ad1988_independent_hp_get,
2259 .put = ad1988_independent_hp_put,
2260 },
2261 { } /* end */
2262};
2263
2264/* 6-stack mode */ 2517/* 6-stack mode */
2265static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = { 2518static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
2266 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT), 2519 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
@@ -2823,421 +3076,185 @@ static const struct hda_amp_list ad1988_loopbacks[] = {
2823 { } /* end */ 3076 { } /* end */
2824}; 3077};
2825#endif 3078#endif
3079#endif /* ENABLE_AD_STATIC_QUIRKS */
2826 3080
2827/* 3081static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
2828 * Automatic parse of I/O pins from the BIOS configuration 3082 struct snd_ctl_elem_info *uinfo)
2829 */
2830
2831enum {
2832 AD_CTL_WIDGET_VOL,
2833 AD_CTL_WIDGET_MUTE,
2834 AD_CTL_BIND_MUTE,
2835};
2836static const struct snd_kcontrol_new ad1988_control_templates[] = {
2837 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2838 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2839 HDA_BIND_MUTE(NULL, 0, 0, 0),
2840};
2841
2842/* add dynamic controls */
2843static int add_control(struct ad198x_spec *spec, int type, const char *name,
2844 unsigned long val)
2845{
2846 struct snd_kcontrol_new *knew;
2847
2848 knew = snd_array_new(&spec->kctls);
2849 if (!knew)
2850 return -ENOMEM;
2851 *knew = ad1988_control_templates[type];
2852 knew->name = kstrdup(name, GFP_KERNEL);
2853 if (! knew->name)
2854 return -ENOMEM;
2855 if (get_amp_nid_(val))
2856 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2857 knew->private_value = val;
2858 return 0;
2859}
2860
2861#define AD1988_PIN_CD_NID 0x18
2862#define AD1988_PIN_BEEP_NID 0x10
2863
2864static const hda_nid_t ad1988_mixer_nids[8] = {
2865 /* A B C D E F G H */
2866 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2867};
2868
2869static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2870{
2871 static const hda_nid_t idx_to_dac[8] = {
2872 /* A B C D E F G H */
2873 0x03, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2874 };
2875 static const hda_nid_t idx_to_dac_rev2[8] = {
2876 /* A B C D E F G H */
2877 0x03, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2878 };
2879 if (is_rev2(codec))
2880 return idx_to_dac_rev2[idx];
2881 else
2882 return idx_to_dac[idx];
2883}
2884
2885static const hda_nid_t ad1988_boost_nids[8] = {
2886 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2887};
2888
2889static int ad1988_pin_idx(hda_nid_t nid)
2890{
2891 static const hda_nid_t ad1988_io_pins[8] = {
2892 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2893 };
2894 int i;
2895 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2896 if (ad1988_io_pins[i] == nid)
2897 return i;
2898 return 0; /* should be -1 */
2899}
2900
2901static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2902{ 3083{
2903 static const int loopback_idx[8] = { 3084 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2904 2, 0, 1, 3, 4, 5, 1, 4 3085 static const char * const texts[] = {
2905 }; 3086 "PCM", "ADC1", "ADC2", "ADC3",
2906 switch (nid) {
2907 case AD1988_PIN_CD_NID:
2908 return 6;
2909 default:
2910 return loopback_idx[ad1988_pin_idx(nid)];
2911 }
2912}
2913
2914static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2915{
2916 static const int adc_idx[8] = {
2917 0, 1, 2, 8, 4, 3, 6, 7
2918 }; 3087 };
2919 switch (nid) { 3088 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
2920 case AD1988_PIN_CD_NID: 3089 if (num_conns > 4)
2921 return 5; 3090 num_conns = 4;
2922 default: 3091 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
2923 return adc_idx[ad1988_pin_idx(nid)];
2924 }
2925} 3092}
2926 3093
2927/* fill in the dac_nids table from the parsed pin configuration */ 3094static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
2928static int ad1988_auto_fill_dac_nids(struct hda_codec *codec, 3095 struct snd_ctl_elem_value *ucontrol)
2929 const struct auto_pin_cfg *cfg)
2930{ 3096{
3097 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2931 struct ad198x_spec *spec = codec->spec; 3098 struct ad198x_spec *spec = codec->spec;
2932 int i, idx;
2933 3099
2934 spec->multiout.dac_nids = spec->private_dac_nids; 3100 ucontrol->value.enumerated.item[0] = spec->cur_smux;
2935
2936 /* check the pins hardwired to audio widget */
2937 for (i = 0; i < cfg->line_outs; i++) {
2938 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2939 spec->private_dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2940 }
2941 spec->multiout.num_dacs = cfg->line_outs;
2942 return 0; 3101 return 0;
2943} 3102}
2944 3103
2945/* add playback controls from the parsed DAC table */ 3104static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
2946static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec, 3105 struct snd_ctl_elem_value *ucontrol)
2947 const struct auto_pin_cfg *cfg)
2948{
2949 char name[32];
2950 static const char * const chname[4] = {
2951 "Front", "Surround", NULL /*CLFE*/, "Side"
2952 };
2953 hda_nid_t nid;
2954 int i, err;
2955
2956 for (i = 0; i < cfg->line_outs; i++) {
2957 hda_nid_t dac = spec->multiout.dac_nids[i];
2958 if (! dac)
2959 continue;
2960 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2961 if (i == 2) {
2962 /* Center/LFE */
2963 err = add_control(spec, AD_CTL_WIDGET_VOL,
2964 "Center Playback Volume",
2965 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2966 if (err < 0)
2967 return err;
2968 err = add_control(spec, AD_CTL_WIDGET_VOL,
2969 "LFE Playback Volume",
2970 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2971 if (err < 0)
2972 return err;
2973 err = add_control(spec, AD_CTL_BIND_MUTE,
2974 "Center Playback Switch",
2975 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2976 if (err < 0)
2977 return err;
2978 err = add_control(spec, AD_CTL_BIND_MUTE,
2979 "LFE Playback Switch",
2980 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2981 if (err < 0)
2982 return err;
2983 } else {
2984 sprintf(name, "%s Playback Volume", chname[i]);
2985 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2986 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2987 if (err < 0)
2988 return err;
2989 sprintf(name, "%s Playback Switch", chname[i]);
2990 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2991 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2992 if (err < 0)
2993 return err;
2994 }
2995 }
2996 return 0;
2997}
2998
2999/* add playback controls for speaker and HP outputs */
3000static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3001 const char *pfx)
3002{ 3106{
3107 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3003 struct ad198x_spec *spec = codec->spec; 3108 struct ad198x_spec *spec = codec->spec;
3004 hda_nid_t nid; 3109 unsigned int val = ucontrol->value.enumerated.item[0];
3005 int i, idx, err; 3110 struct nid_path *path;
3006 char name[32]; 3111 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
3007 3112
3008 if (! pin) 3113 if (val >= num_conns)
3114 return -EINVAL;
3115 if (spec->cur_smux == val)
3009 return 0; 3116 return 0;
3010 3117
3011 idx = ad1988_pin_idx(pin); 3118 mutex_lock(&codec->control_mutex);
3012 nid = ad1988_idx_to_dac(codec, idx); 3119 codec->cached_write = 1;
3013 /* check whether the corresponding DAC was already taken */ 3120 path = snd_hda_get_path_from_idx(codec,
3014 for (i = 0; i < spec->autocfg.line_outs; i++) { 3121 spec->smux_paths[spec->cur_smux]);
3015 hda_nid_t pin = spec->autocfg.line_out_pins[i]; 3122 if (path)
3016 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin)); 3123 snd_hda_activate_path(codec, path, false, true);
3017 if (dac == nid) 3124 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
3018 break; 3125 if (path)
3019 } 3126 snd_hda_activate_path(codec, path, true, true);
3020 if (i >= spec->autocfg.line_outs) { 3127 spec->cur_smux = val;
3021 /* specify the DAC as the extra output */ 3128 codec->cached_write = 0;
3022 if (!spec->multiout.hp_nid) 3129 mutex_unlock(&codec->control_mutex);
3023 spec->multiout.hp_nid = nid; 3130 snd_hda_codec_flush_cache(codec); /* flush the updates */
3024 else 3131 return 1;
3025 spec->multiout.extra_out_nid[0] = nid;
3026 /* control HP volume/switch on the output mixer amp */
3027 sprintf(name, "%s Playback Volume", pfx);
3028 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
3029 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3030 if (err < 0)
3031 return err;
3032 }
3033 nid = ad1988_mixer_nids[idx];
3034 sprintf(name, "%s Playback Switch", pfx);
3035 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
3036 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
3037 return err;
3038 return 0;
3039} 3132}
3040 3133
3041/* create input playback/capture controls for the given pin */ 3134static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
3042static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin, 3135 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3043 const char *ctlname, int ctlidx, int boost) 3136 .name = "IEC958 Playback Source",
3137 .info = ad1988_auto_smux_enum_info,
3138 .get = ad1988_auto_smux_enum_get,
3139 .put = ad1988_auto_smux_enum_put,
3140};
3141
3142static int ad1988_auto_init(struct hda_codec *codec)
3044{ 3143{
3045 char name[32]; 3144 struct ad198x_spec *spec = codec->spec;
3046 int err, idx; 3145 int i, err;
3047 3146
3048 sprintf(name, "%s Playback Volume", ctlname); 3147 err = snd_hda_gen_init(codec);
3049 idx = ad1988_pin_to_loopback_idx(pin); 3148 if (err < 0)
3050 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
3051 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
3052 return err;
3053 sprintf(name, "%s Playback Switch", ctlname);
3054 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
3055 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
3056 return err; 3149 return err;
3057 if (boost) { 3150 if (!spec->gen.autocfg.dig_outs)
3058 hda_nid_t bnid; 3151 return 0;
3059 idx = ad1988_pin_idx(pin);
3060 bnid = ad1988_boost_nids[idx];
3061 if (bnid) {
3062 sprintf(name, "%s Boost Volume", ctlname);
3063 return add_control(spec, AD_CTL_WIDGET_VOL, name,
3064 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
3065 3152
3066 } 3153 for (i = 0; i < 4; i++) {
3154 struct nid_path *path;
3155 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
3156 if (path)
3157 snd_hda_activate_path(codec, path, path->active, false);
3067 } 3158 }
3159
3068 return 0; 3160 return 0;
3069} 3161}
3070 3162
3071/* create playback/capture controls for input pins */ 3163static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
3072static int ad1988_auto_create_analog_input_ctls(struct hda_codec *codec,
3073 const struct auto_pin_cfg *cfg)
3074{ 3164{
3075 struct ad198x_spec *spec = codec->spec; 3165 struct ad198x_spec *spec = codec->spec;
3076 struct hda_input_mux *imux = &spec->private_imux; 3166 int i, num_conns;
3077 int i, err, type, type_idx; 3167 /* we create four static faked paths, since AD codecs have odd
3078 3168 * widget connections regarding the SPDIF out source
3079 for (i = 0; i < cfg->num_inputs; i++) { 3169 */
3080 const char *label; 3170 static struct nid_path fake_paths[4] = {
3081 type = cfg->inputs[i].type; 3171 {
3082 label = hda_get_autocfg_input_label(codec, cfg, i); 3172 .depth = 3,
3083 snd_hda_add_imux_item(imux, label, 3173 .path = { 0x02, 0x1d, 0x1b },
3084 ad1988_pin_to_adc_idx(cfg->inputs[i].pin), 3174 .idx = { 0, 0, 0 },
3085 &type_idx); 3175 .multi = { 0, 0, 0 },
3086 err = new_analog_input(spec, cfg->inputs[i].pin, 3176 },
3087 label, type_idx, 3177 {
3088 type == AUTO_PIN_MIC); 3178 .depth = 4,
3089 if (err < 0) 3179 .path = { 0x08, 0x0b, 0x1d, 0x1b },
3090 return err; 3180 .idx = { 0, 0, 1, 0 },
3091 } 3181 .multi = { 0, 1, 0, 0 },
3092 snd_hda_add_imux_item(imux, "Mix", 9, NULL); 3182 },
3183 {
3184 .depth = 4,
3185 .path = { 0x09, 0x0b, 0x1d, 0x1b },
3186 .idx = { 0, 1, 1, 0 },
3187 .multi = { 0, 1, 0, 0 },
3188 },
3189 {
3190 .depth = 4,
3191 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
3192 .idx = { 0, 2, 1, 0 },
3193 .multi = { 0, 1, 0, 0 },
3194 },
3195 };
3093 3196
3094 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, 3197 /* SPDIF source mux appears to be present only on AD1988A */
3095 "Analog Mix Playback Volume", 3198 if (!spec->gen.autocfg.dig_outs ||
3096 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0) 3199 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
3097 return err; 3200 return 0;
3098 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
3099 "Analog Mix Playback Switch",
3100 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
3101 return err;
3102 3201
3103 return 0; 3202 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
3104} 3203 if (num_conns != 3 && num_conns != 4)
3204 return 0;
3105 3205
3106static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec, 3206 for (i = 0; i < num_conns; i++) {
3107 hda_nid_t nid, int pin_type, 3207 struct nid_path *path = snd_array_new(&spec->gen.paths);
3108 int dac_idx) 3208 if (!path)
3109{ 3209 return -ENOMEM;
3110 /* set as output */ 3210 *path = fake_paths[i];
3111 snd_hda_set_pin_ctl(codec, nid, pin_type); 3211 if (!i)
3112 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 3212 path->active = 1;
3113 switch (nid) { 3213 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
3114 case 0x11: /* port-A - DAC 03 */
3115 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
3116 break;
3117 case 0x14: /* port-B - DAC 06 */
3118 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
3119 break;
3120 case 0x15: /* port-C - DAC 05 */
3121 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
3122 break;
3123 case 0x17: /* port-E - DAC 0a */
3124 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
3125 break;
3126 case 0x13: /* mono - DAC 04 */
3127 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
3128 break;
3129 } 3214 }
3130}
3131 3215
3132static void ad1988_auto_init_multi_out(struct hda_codec *codec) 3216 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
3133{ 3217 return -ENOMEM;
3134 struct ad198x_spec *spec = codec->spec;
3135 int i;
3136 3218
3137 for (i = 0; i < spec->autocfg.line_outs; i++) { 3219 codec->patch_ops.init = ad1988_auto_init;
3138 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3139 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
3140 }
3141}
3142 3220
3143static void ad1988_auto_init_extra_out(struct hda_codec *codec) 3221 return 0;
3144{
3145 struct ad198x_spec *spec = codec->spec;
3146 hda_nid_t pin;
3147
3148 pin = spec->autocfg.speaker_pins[0];
3149 if (pin) /* connect to front */
3150 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3151 pin = spec->autocfg.hp_pins[0];
3152 if (pin) /* connect to front */
3153 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3154} 3222}
3155 3223
3156static void ad1988_auto_init_analog_input(struct hda_codec *codec) 3224/*
3157{ 3225 */
3158 struct ad198x_spec *spec = codec->spec;
3159 const struct auto_pin_cfg *cfg = &spec->autocfg;
3160 int i, idx;
3161
3162 for (i = 0; i < cfg->num_inputs; i++) {
3163 hda_nid_t nid = cfg->inputs[i].pin;
3164 int type = cfg->inputs[i].type;
3165 int val;
3166 switch (nid) {
3167 case 0x15: /* port-C */
3168 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
3169 break;
3170 case 0x17: /* port-E */
3171 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
3172 break;
3173 }
3174 val = PIN_IN;
3175 if (type == AUTO_PIN_MIC)
3176 val |= snd_hda_get_default_vref(codec, nid);
3177 snd_hda_set_pin_ctl(codec, nid, val);
3178 if (nid != AD1988_PIN_CD_NID)
3179 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3180 AMP_OUT_MUTE);
3181 idx = ad1988_pin_idx(nid);
3182 if (ad1988_boost_nids[idx])
3183 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
3184 AC_VERB_SET_AMP_GAIN_MUTE,
3185 AMP_OUT_ZERO);
3186 }
3187}
3188 3226
3189/* parse the BIOS configuration and set up the alc_spec */
3190/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
3191static int ad1988_parse_auto_config(struct hda_codec *codec) 3227static int ad1988_parse_auto_config(struct hda_codec *codec)
3192{ 3228{
3193 struct ad198x_spec *spec = codec->spec; 3229 struct ad198x_spec *spec;
3194 int err; 3230 int err;
3195 3231
3196 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0) 3232 err = alloc_ad_spec(codec);
3197 return err; 3233 if (err < 0)
3198 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3199 return err;
3200 if (! spec->autocfg.line_outs)
3201 return 0; /* can't find valid BIOS pin config */
3202 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
3203 (err = ad1988_auto_create_extra_out(codec,
3204 spec->autocfg.speaker_pins[0],
3205 "Speaker")) < 0 ||
3206 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
3207 "Headphone")) < 0 ||
3208 (err = ad1988_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3209 return err; 3234 return err;
3235 spec = codec->spec;
3210 3236
3211 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3237 spec->gen.mixer_nid = 0x20;
3212 3238 spec->gen.mixer_merge_nid = 0x21;
3213 if (spec->autocfg.dig_outs) 3239 spec->beep_dev_nid = 0x10;
3214 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT; 3240 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3215 if (spec->autocfg.dig_in_pin) 3241 err = ad198x_parse_auto_config(codec);
3216 spec->dig_in_nid = AD1988_SPDIF_IN; 3242 if (err < 0)
3217 3243 goto error;
3218 if (spec->kctls.list) 3244 err = ad1988_add_spdif_mux_ctl(codec);
3219 spec->mixers[spec->num_mixers++] = spec->kctls.list; 3245 if (err < 0)
3220 3246 goto error;
3221 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
3222
3223 spec->input_mux = &spec->private_imux;
3224
3225 return 1;
3226}
3227
3228/* init callback for auto-configuration model -- overriding the default init */
3229static int ad1988_auto_init(struct hda_codec *codec)
3230{
3231 ad198x_init(codec);
3232 ad1988_auto_init_multi_out(codec);
3233 ad1988_auto_init_extra_out(codec);
3234 ad1988_auto_init_analog_input(codec);
3235 return 0; 3247 return 0;
3248
3249 error:
3250 ad198x_free(codec);
3251 return err;
3236} 3252}
3237 3253
3238/* 3254/*
3239 */ 3255 */
3240 3256
3257#ifdef ENABLE_AD_STATIC_QUIRKS
3241static const char * const ad1988_models[AD1988_MODEL_LAST] = { 3258static const char * const ad1988_models[AD1988_MODEL_LAST] = {
3242 [AD1988_6STACK] = "6stack", 3259 [AD1988_6STACK] = "6stack",
3243 [AD1988_6STACK_DIG] = "6stack-dig", 3260 [AD1988_6STACK_DIG] = "6stack-dig",
@@ -3262,14 +3279,6 @@ static int patch_ad1988(struct hda_codec *codec)
3262 struct ad198x_spec *spec; 3279 struct ad198x_spec *spec;
3263 int err, board_config; 3280 int err, board_config;
3264 3281
3265 err = alloc_ad_spec(codec);
3266 if (err < 0)
3267 return err;
3268 spec = codec->spec;
3269
3270 if (is_rev2(codec))
3271 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
3272
3273 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST, 3282 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
3274 ad1988_models, ad1988_cfg_tbl); 3283 ad1988_models, ad1988_cfg_tbl);
3275 if (board_config < 0) { 3284 if (board_config < 0) {
@@ -3278,17 +3287,16 @@ static int patch_ad1988(struct hda_codec *codec)
3278 board_config = AD1988_AUTO; 3287 board_config = AD1988_AUTO;
3279 } 3288 }
3280 3289
3281 if (board_config == AD1988_AUTO) { 3290 if (board_config == AD1988_AUTO)
3282 /* automatic parse from the BIOS config */ 3291 return ad1988_parse_auto_config(codec);
3283 err = ad1988_parse_auto_config(codec); 3292
3284 if (err < 0) { 3293 err = alloc_ad_spec(codec);
3285 ad198x_free(codec); 3294 if (err < 0)
3286 return err; 3295 return err;
3287 } else if (! err) { 3296 spec = codec->spec;
3288 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n"); 3297
3289 board_config = AD1988_6STACK; 3298 if (is_rev2(codec))
3290 } 3299 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
3291 }
3292 3300
3293 err = snd_hda_attach_beep_device(codec, 0x10); 3301 err = snd_hda_attach_beep_device(codec, 0x10);
3294 if (err < 0) { 3302 if (err < 0) {
@@ -3352,7 +3360,7 @@ static int patch_ad1988(struct hda_codec *codec)
3352 spec->input_mux = &ad1988_laptop_capture_source; 3360 spec->input_mux = &ad1988_laptop_capture_source;
3353 spec->num_mixers = 1; 3361 spec->num_mixers = 1;
3354 spec->mixers[0] = ad1988_laptop_mixers; 3362 spec->mixers[0] = ad1988_laptop_mixers;
3355 spec->inv_eapd = 1; /* inverted EAPD */ 3363 codec->inv_eapd = 1; /* inverted EAPD */
3356 spec->num_init_verbs = 1; 3364 spec->num_init_verbs = 1;
3357 spec->init_verbs[0] = ad1988_laptop_init_verbs; 3365 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3358 if (board_config == AD1988_LAPTOP_DIG) 3366 if (board_config == AD1988_LAPTOP_DIG)
@@ -3360,15 +3368,6 @@ static int patch_ad1988(struct hda_codec *codec)
3360 break; 3368 break;
3361 } 3369 }
3362 3370
3363 if (spec->autocfg.hp_pins[0]) {
3364 spec->mixers[spec->num_mixers++] = ad1988_hp_mixers;
3365 spec->slave_vols = ad1988_6stack_fp_slave_pfxs;
3366 spec->slave_sws = ad1988_6stack_fp_slave_pfxs;
3367 spec->alt_dac_nid = ad1988_alt_dac_nid;
3368 spec->stream_analog_alt_playback =
3369 &ad198x_pcm_analog_alt_playback;
3370 }
3371
3372 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids); 3371 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3373 spec->adc_nids = ad1988_adc_nids; 3372 spec->adc_nids = ad1988_adc_nids;
3374 spec->capsrc_nids = ad1988_capsrc_nids; 3373 spec->capsrc_nids = ad1988_capsrc_nids;
@@ -3396,9 +3395,6 @@ static int patch_ad1988(struct hda_codec *codec)
3396 3395
3397 codec->patch_ops = ad198x_patch_ops; 3396 codec->patch_ops = ad198x_patch_ops;
3398 switch (board_config) { 3397 switch (board_config) {
3399 case AD1988_AUTO:
3400 codec->patch_ops.init = ad1988_auto_init;
3401 break;
3402 case AD1988_LAPTOP: 3398 case AD1988_LAPTOP:
3403 case AD1988_LAPTOP_DIG: 3399 case AD1988_LAPTOP_DIG:
3404 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event; 3400 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
@@ -3414,6 +3410,9 @@ static int patch_ad1988(struct hda_codec *codec)
3414 3410
3415 return 0; 3411 return 0;
3416} 3412}
3413#else /* ENABLE_AD_STATIC_QUIRKS */
3414#define patch_ad1988 ad1988_parse_auto_config
3415#endif /* ENABLE_AD_STATIC_QUIRKS */
3417 3416
3418 3417
3419/* 3418/*
@@ -3434,6 +3433,7 @@ static int patch_ad1988(struct hda_codec *codec)
3434 * but no build-up framework is given, so far. 3433 * but no build-up framework is given, so far.
3435 */ 3434 */
3436 3435
3436#ifdef ENABLE_AD_STATIC_QUIRKS
3437static const hda_nid_t ad1884_dac_nids[1] = { 3437static const hda_nid_t ad1884_dac_nids[1] = {
3438 0x04, 3438 0x04,
3439}; 3439};
@@ -3576,7 +3576,107 @@ static const char * const ad1884_slave_vols[] = {
3576 NULL 3576 NULL
3577}; 3577};
3578 3578
3579static int patch_ad1884(struct hda_codec *codec) 3579enum {
3580 AD1884_AUTO,
3581 AD1884_BASIC,
3582 AD1884_MODELS
3583};
3584
3585static const char * const ad1884_models[AD1884_MODELS] = {
3586 [AD1884_AUTO] = "auto",
3587 [AD1884_BASIC] = "basic",
3588};
3589#endif /* ENABLE_AD_STATIC_QUIRKS */
3590
3591
3592/* set the upper-limit for mixer amp to 0dB for avoiding the possible
3593 * damage by overloading
3594 */
3595static void ad1884_fixup_amp_override(struct hda_codec *codec,
3596 const struct hda_fixup *fix, int action)
3597{
3598 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3599 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
3600 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3601 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3602 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3603 (1 << AC_AMPCAP_MUTE_SHIFT));
3604}
3605
3606static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
3607 const struct hda_fixup *fix, int action)
3608{
3609 struct ad198x_spec *spec = codec->spec;
3610
3611 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3612 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3613 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
3614 else
3615 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
3616 if (spec->eapd_nid)
3617 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
3618 }
3619}
3620
3621enum {
3622 AD1884_FIXUP_AMP_OVERRIDE,
3623 AD1884_FIXUP_HP_EAPD,
3624};
3625
3626static const struct hda_fixup ad1884_fixups[] = {
3627 [AD1884_FIXUP_AMP_OVERRIDE] = {
3628 .type = HDA_FIXUP_FUNC,
3629 .v.func = ad1884_fixup_amp_override,
3630 },
3631 [AD1884_FIXUP_HP_EAPD] = {
3632 .type = HDA_FIXUP_FUNC,
3633 .v.func = ad1884_fixup_hp_eapd,
3634 .chained = true,
3635 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
3636 },
3637};
3638
3639static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
3640 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
3641 {}
3642};
3643
3644
3645static int ad1884_parse_auto_config(struct hda_codec *codec)
3646{
3647 struct ad198x_spec *spec;
3648 int err;
3649
3650 err = alloc_ad_spec(codec);
3651 if (err < 0)
3652 return err;
3653 spec = codec->spec;
3654
3655 spec->gen.mixer_nid = 0x20;
3656 spec->beep_dev_nid = 0x10;
3657 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3658
3659 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
3660 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3661
3662 err = ad198x_parse_auto_config(codec);
3663 if (err < 0)
3664 goto error;
3665 err = ad1983_add_spdif_mux_ctl(codec);
3666 if (err < 0)
3667 goto error;
3668
3669 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
3670
3671 return 0;
3672
3673 error:
3674 ad198x_free(codec);
3675 return err;
3676}
3677
3678#ifdef ENABLE_AD_STATIC_QUIRKS
3679static int patch_ad1884_basic(struct hda_codec *codec)
3580{ 3680{
3581 struct ad198x_spec *spec; 3681 struct ad198x_spec *spec;
3582 int err; 3682 int err;
@@ -3623,6 +3723,29 @@ static int patch_ad1884(struct hda_codec *codec)
3623 return 0; 3723 return 0;
3624} 3724}
3625 3725
3726static int patch_ad1884(struct hda_codec *codec)
3727{
3728 int board_config;
3729
3730 board_config = snd_hda_check_board_config(codec, AD1884_MODELS,
3731 ad1884_models, NULL);
3732 if (board_config < 0) {
3733 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3734 codec->chip_name);
3735 board_config = AD1884_AUTO;
3736 }
3737
3738 if (board_config == AD1884_AUTO)
3739 return ad1884_parse_auto_config(codec);
3740 else
3741 return patch_ad1884_basic(codec);
3742}
3743#else /* ENABLE_AD_STATIC_QUIRKS */
3744#define patch_ad1884 ad1884_parse_auto_config
3745#endif /* ENABLE_AD_STATIC_QUIRKS */
3746
3747
3748#ifdef ENABLE_AD_STATIC_QUIRKS
3626/* 3749/*
3627 * Lenovo Thinkpad T61/X61 3750 * Lenovo Thinkpad T61/X61
3628 */ 3751 */
@@ -3795,6 +3918,7 @@ static int ad1984_build_pcms(struct hda_codec *codec)
3795 3918
3796/* models */ 3919/* models */
3797enum { 3920enum {
3921 AD1984_AUTO,
3798 AD1984_BASIC, 3922 AD1984_BASIC,
3799 AD1984_THINKPAD, 3923 AD1984_THINKPAD,
3800 AD1984_DELL_DESKTOP, 3924 AD1984_DELL_DESKTOP,
@@ -3802,6 +3926,7 @@ enum {
3802}; 3926};
3803 3927
3804static const char * const ad1984_models[AD1984_MODELS] = { 3928static const char * const ad1984_models[AD1984_MODELS] = {
3929 [AD1984_AUTO] = "auto",
3805 [AD1984_BASIC] = "basic", 3930 [AD1984_BASIC] = "basic",
3806 [AD1984_THINKPAD] = "thinkpad", 3931 [AD1984_THINKPAD] = "thinkpad",
3807 [AD1984_DELL_DESKTOP] = "dell_desktop", 3932 [AD1984_DELL_DESKTOP] = "dell_desktop",
@@ -3820,12 +3945,22 @@ static int patch_ad1984(struct hda_codec *codec)
3820 struct ad198x_spec *spec; 3945 struct ad198x_spec *spec;
3821 int board_config, err; 3946 int board_config, err;
3822 3947
3823 err = patch_ad1884(codec); 3948 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3949 ad1984_models, ad1984_cfg_tbl);
3950 if (board_config < 0) {
3951 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3952 codec->chip_name);
3953 board_config = AD1984_AUTO;
3954 }
3955
3956 if (board_config == AD1984_AUTO)
3957 return ad1884_parse_auto_config(codec);
3958
3959 err = patch_ad1884_basic(codec);
3824 if (err < 0) 3960 if (err < 0)
3825 return err; 3961 return err;
3826 spec = codec->spec; 3962 spec = codec->spec;
3827 board_config = snd_hda_check_board_config(codec, AD1984_MODELS, 3963
3828 ad1984_models, ad1984_cfg_tbl);
3829 switch (board_config) { 3964 switch (board_config) {
3830 case AD1984_BASIC: 3965 case AD1984_BASIC:
3831 /* additional digital mics */ 3966 /* additional digital mics */
@@ -3852,6 +3987,9 @@ static int patch_ad1984(struct hda_codec *codec)
3852 } 3987 }
3853 return 0; 3988 return 0;
3854} 3989}
3990#else /* ENABLE_AD_STATIC_QUIRKS */
3991#define patch_ad1984 ad1884_parse_auto_config
3992#endif /* ENABLE_AD_STATIC_QUIRKS */
3855 3993
3856 3994
3857/* 3995/*
@@ -3872,6 +4010,7 @@ static int patch_ad1984(struct hda_codec *codec)
3872 * We share the single DAC for both HP and line-outs (see AD1884/1984). 4010 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3873 */ 4011 */
3874 4012
4013#ifdef ENABLE_AD_STATIC_QUIRKS
3875static const hda_nid_t ad1884a_dac_nids[1] = { 4014static const hda_nid_t ad1884a_dac_nids[1] = {
3876 0x03, 4015 0x03,
3877}; 4016};
@@ -4542,6 +4681,7 @@ static int ad1984a_touchsmart_init(struct hda_codec *codec)
4542 */ 4681 */
4543 4682
4544enum { 4683enum {
4684 AD1884A_AUTO,
4545 AD1884A_DESKTOP, 4685 AD1884A_DESKTOP,
4546 AD1884A_LAPTOP, 4686 AD1884A_LAPTOP,
4547 AD1884A_MOBILE, 4687 AD1884A_MOBILE,
@@ -4552,6 +4692,7 @@ enum {
4552}; 4692};
4553 4693
4554static const char * const ad1884a_models[AD1884A_MODELS] = { 4694static const char * const ad1884a_models[AD1884A_MODELS] = {
4695 [AD1884A_AUTO] = "auto",
4555 [AD1884A_DESKTOP] = "desktop", 4696 [AD1884A_DESKTOP] = "desktop",
4556 [AD1884A_LAPTOP] = "laptop", 4697 [AD1884A_LAPTOP] = "laptop",
4557 [AD1884A_MOBILE] = "mobile", 4698 [AD1884A_MOBILE] = "mobile",
@@ -4580,6 +4721,18 @@ static int patch_ad1884a(struct hda_codec *codec)
4580 struct ad198x_spec *spec; 4721 struct ad198x_spec *spec;
4581 int err, board_config; 4722 int err, board_config;
4582 4723
4724 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
4725 ad1884a_models,
4726 ad1884a_cfg_tbl);
4727 if (board_config < 0) {
4728 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4729 codec->chip_name);
4730 board_config = AD1884A_AUTO;
4731 }
4732
4733 if (board_config == AD1884A_AUTO)
4734 return ad1884_parse_auto_config(codec);
4735
4583 err = alloc_ad_spec(codec); 4736 err = alloc_ad_spec(codec);
4584 if (err < 0) 4737 if (err < 0)
4585 return err; 4738 return err;
@@ -4611,9 +4764,6 @@ static int patch_ad1884a(struct hda_codec *codec)
4611 codec->patch_ops = ad198x_patch_ops; 4764 codec->patch_ops = ad198x_patch_ops;
4612 4765
4613 /* override some parameters */ 4766 /* override some parameters */
4614 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
4615 ad1884a_models,
4616 ad1884a_cfg_tbl);
4617 switch (board_config) { 4767 switch (board_config) {
4618 case AD1884A_LAPTOP: 4768 case AD1884A_LAPTOP:
4619 spec->mixers[0] = ad1884a_laptop_mixers; 4769 spec->mixers[0] = ad1884a_laptop_mixers;
@@ -4684,6 +4834,9 @@ static int patch_ad1884a(struct hda_codec *codec)
4684 4834
4685 return 0; 4835 return 0;
4686} 4836}
4837#else /* ENABLE_AD_STATIC_QUIRKS */
4838#define patch_ad1884a ad1884_parse_auto_config
4839#endif /* ENABLE_AD_STATIC_QUIRKS */
4687 4840
4688 4841
4689/* 4842/*
@@ -4698,6 +4851,7 @@ static int patch_ad1884a(struct hda_codec *codec)
4698 * port-G - rear clfe-out (6stack) 4851 * port-G - rear clfe-out (6stack)
4699 */ 4852 */
4700 4853
4854#ifdef ENABLE_AD_STATIC_QUIRKS
4701static const hda_nid_t ad1882_dac_nids[3] = { 4855static const hda_nid_t ad1882_dac_nids[3] = {
4702 0x04, 0x03, 0x05 4856 0x04, 0x03, 0x05
4703}; 4857};
@@ -4974,6 +5128,7 @@ static const struct hda_amp_list ad1882_loopbacks[] = {
4974 5128
4975/* models */ 5129/* models */
4976enum { 5130enum {
5131 AD1882_AUTO,
4977 AD1882_3STACK, 5132 AD1882_3STACK,
4978 AD1882_6STACK, 5133 AD1882_6STACK,
4979 AD1882_3STACK_AUTOMUTE, 5134 AD1882_3STACK_AUTOMUTE,
@@ -4981,17 +5136,57 @@ enum {
4981}; 5136};
4982 5137
4983static const char * const ad1882_models[AD1986A_MODELS] = { 5138static const char * const ad1882_models[AD1986A_MODELS] = {
5139 [AD1882_AUTO] = "auto",
4984 [AD1882_3STACK] = "3stack", 5140 [AD1882_3STACK] = "3stack",
4985 [AD1882_6STACK] = "6stack", 5141 [AD1882_6STACK] = "6stack",
4986 [AD1882_3STACK_AUTOMUTE] = "3stack-automute", 5142 [AD1882_3STACK_AUTOMUTE] = "3stack-automute",
4987}; 5143};
5144#endif /* ENABLE_AD_STATIC_QUIRKS */
5145
5146static int ad1882_parse_auto_config(struct hda_codec *codec)
5147{
5148 struct ad198x_spec *spec;
5149 int err;
4988 5150
5151 err = alloc_ad_spec(codec);
5152 if (err < 0)
5153 return err;
5154 spec = codec->spec;
4989 5155
5156 spec->gen.mixer_nid = 0x20;
5157 spec->gen.mixer_merge_nid = 0x21;
5158 spec->beep_dev_nid = 0x10;
5159 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
5160 err = ad198x_parse_auto_config(codec);
5161 if (err < 0)
5162 goto error;
5163 err = ad1988_add_spdif_mux_ctl(codec);
5164 if (err < 0)
5165 goto error;
5166 return 0;
5167
5168 error:
5169 ad198x_free(codec);
5170 return err;
5171}
5172
5173#ifdef ENABLE_AD_STATIC_QUIRKS
4990static int patch_ad1882(struct hda_codec *codec) 5174static int patch_ad1882(struct hda_codec *codec)
4991{ 5175{
4992 struct ad198x_spec *spec; 5176 struct ad198x_spec *spec;
4993 int err, board_config; 5177 int err, board_config;
4994 5178
5179 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
5180 ad1882_models, NULL);
5181 if (board_config < 0) {
5182 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5183 codec->chip_name);
5184 board_config = AD1882_AUTO;
5185 }
5186
5187 if (board_config == AD1882_AUTO)
5188 return ad1882_parse_auto_config(codec);
5189
4995 err = alloc_ad_spec(codec); 5190 err = alloc_ad_spec(codec);
4996 if (err < 0) 5191 if (err < 0)
4997 return err; 5192 return err;
@@ -5032,8 +5227,6 @@ static int patch_ad1882(struct hda_codec *codec)
5032 codec->patch_ops = ad198x_patch_ops; 5227 codec->patch_ops = ad198x_patch_ops;
5033 5228
5034 /* override some parameters */ 5229 /* override some parameters */
5035 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
5036 ad1882_models, NULL);
5037 switch (board_config) { 5230 switch (board_config) {
5038 default: 5231 default:
5039 case AD1882_3STACK: 5232 case AD1882_3STACK:
@@ -5063,6 +5256,9 @@ static int patch_ad1882(struct hda_codec *codec)
5063 5256
5064 return 0; 5257 return 0;
5065} 5258}
5259#else /* ENABLE_AD_STATIC_QUIRKS */
5260#define patch_ad1882 ad1882_parse_auto_config
5261#endif /* ENABLE_AD_STATIC_QUIRKS */
5066 5262
5067 5263
5068/* 5264/*
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index 19ae14f739cb..30b3a4bc06ee 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -19,7 +19,6 @@
19 */ 19 */
20 20
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/slab.h> 22#include <linux/slab.h>
24#include <linux/pci.h> 23#include <linux/pci.h>
25#include <linux/module.h> 24#include <linux/module.h>
@@ -27,502 +26,46 @@
27#include "hda_codec.h" 26#include "hda_codec.h"
28#include "hda_local.h" 27#include "hda_local.h"
29#include "hda_auto_parser.h" 28#include "hda_auto_parser.h"
29#include "hda_jack.h"
30#include "hda_generic.h"
30 31
31/*
32 */
33
34struct ca0110_spec {
35 struct auto_pin_cfg autocfg;
36 struct hda_multi_out multiout;
37 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS];
38 hda_nid_t dacs[AUTO_CFG_MAX_OUTS];
39 hda_nid_t hp_dac;
40 hda_nid_t input_pins[AUTO_PIN_LAST];
41 hda_nid_t adcs[AUTO_PIN_LAST];
42 hda_nid_t dig_out;
43 hda_nid_t dig_in;
44 unsigned int num_inputs;
45 char input_labels[AUTO_PIN_LAST][32];
46 struct hda_pcm pcm_rec[2]; /* PCM information */
47};
48
49/*
50 * PCM callbacks
51 */
52static int ca0110_playback_pcm_open(struct hda_pcm_stream *hinfo,
53 struct hda_codec *codec,
54 struct snd_pcm_substream *substream)
55{
56 struct ca0110_spec *spec = codec->spec;
57 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
58 hinfo);
59}
60
61static int ca0110_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
62 struct hda_codec *codec,
63 unsigned int stream_tag,
64 unsigned int format,
65 struct snd_pcm_substream *substream)
66{
67 struct ca0110_spec *spec = codec->spec;
68 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
69 stream_tag, format, substream);
70}
71
72static int ca0110_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
73 struct hda_codec *codec,
74 struct snd_pcm_substream *substream)
75{
76 struct ca0110_spec *spec = codec->spec;
77 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
78}
79
80/*
81 * Digital out
82 */
83static int ca0110_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
84 struct hda_codec *codec,
85 struct snd_pcm_substream *substream)
86{
87 struct ca0110_spec *spec = codec->spec;
88 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
89}
90
91static int ca0110_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
92 struct hda_codec *codec,
93 struct snd_pcm_substream *substream)
94{
95 struct ca0110_spec *spec = codec->spec;
96 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
97}
98
99static int ca0110_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
100 struct hda_codec *codec,
101 unsigned int stream_tag,
102 unsigned int format,
103 struct snd_pcm_substream *substream)
104{
105 struct ca0110_spec *spec = codec->spec;
106 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
107 format, substream);
108}
109
110/*
111 * Analog capture
112 */
113static int ca0110_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
114 struct hda_codec *codec,
115 unsigned int stream_tag,
116 unsigned int format,
117 struct snd_pcm_substream *substream)
118{
119 struct ca0110_spec *spec = codec->spec;
120
121 snd_hda_codec_setup_stream(codec, spec->adcs[substream->number],
122 stream_tag, 0, format);
123 return 0;
124}
125
126static int ca0110_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
127 struct hda_codec *codec,
128 struct snd_pcm_substream *substream)
129{
130 struct ca0110_spec *spec = codec->spec;
131
132 snd_hda_codec_cleanup_stream(codec, spec->adcs[substream->number]);
133 return 0;
134}
135
136/*
137 */
138
139static const char * const dirstr[2] = { "Playback", "Capture" };
140
141static int _add_switch(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
142 int chan, int dir)
143{
144 char namestr[44];
145 int type = dir ? HDA_INPUT : HDA_OUTPUT;
146 struct snd_kcontrol_new knew =
147 HDA_CODEC_MUTE_MONO(namestr, nid, chan, 0, type);
148 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
149 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
150}
151
152static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
153 int chan, int dir)
154{
155 char namestr[44];
156 int type = dir ? HDA_INPUT : HDA_OUTPUT;
157 struct snd_kcontrol_new knew =
158 HDA_CODEC_VOLUME_MONO(namestr, nid, chan, 0, type);
159 sprintf(namestr, "%s %s Volume", pfx, dirstr[dir]);
160 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
161}
162
163#define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0)
164#define add_out_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 0)
165#define add_in_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 1)
166#define add_in_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 1)
167#define add_mono_switch(codec, nid, pfx, chan) \
168 _add_switch(codec, nid, pfx, chan, 0)
169#define add_mono_volume(codec, nid, pfx, chan) \
170 _add_volume(codec, nid, pfx, chan, 0)
171
172static int ca0110_build_controls(struct hda_codec *codec)
173{
174 struct ca0110_spec *spec = codec->spec;
175 struct auto_pin_cfg *cfg = &spec->autocfg;
176 static const char * const prefix[AUTO_CFG_MAX_OUTS] = {
177 "Front", "Surround", NULL, "Side", "Multi"
178 };
179 hda_nid_t mutenid;
180 int i, err;
181
182 for (i = 0; i < spec->multiout.num_dacs; i++) {
183 if (get_wcaps(codec, spec->out_pins[i]) & AC_WCAP_OUT_AMP)
184 mutenid = spec->out_pins[i];
185 else
186 mutenid = spec->multiout.dac_nids[i];
187 if (!prefix[i]) {
188 err = add_mono_switch(codec, mutenid,
189 "Center", 1);
190 if (err < 0)
191 return err;
192 err = add_mono_switch(codec, mutenid,
193 "LFE", 1);
194 if (err < 0)
195 return err;
196 err = add_mono_volume(codec, spec->multiout.dac_nids[i],
197 "Center", 1);
198 if (err < 0)
199 return err;
200 err = add_mono_volume(codec, spec->multiout.dac_nids[i],
201 "LFE", 1);
202 if (err < 0)
203 return err;
204 } else {
205 err = add_out_switch(codec, mutenid,
206 prefix[i]);
207 if (err < 0)
208 return err;
209 err = add_out_volume(codec, spec->multiout.dac_nids[i],
210 prefix[i]);
211 if (err < 0)
212 return err;
213 }
214 }
215 if (cfg->hp_outs) {
216 if (get_wcaps(codec, cfg->hp_pins[0]) & AC_WCAP_OUT_AMP)
217 mutenid = cfg->hp_pins[0];
218 else
219 mutenid = spec->multiout.dac_nids[i];
220
221 err = add_out_switch(codec, mutenid, "Headphone");
222 if (err < 0)
223 return err;
224 if (spec->hp_dac) {
225 err = add_out_volume(codec, spec->hp_dac, "Headphone");
226 if (err < 0)
227 return err;
228 }
229 }
230 for (i = 0; i < spec->num_inputs; i++) {
231 const char *label = spec->input_labels[i];
232 if (get_wcaps(codec, spec->input_pins[i]) & AC_WCAP_IN_AMP)
233 mutenid = spec->input_pins[i];
234 else
235 mutenid = spec->adcs[i];
236 err = add_in_switch(codec, mutenid, label);
237 if (err < 0)
238 return err;
239 err = add_in_volume(codec, spec->adcs[i], label);
240 if (err < 0)
241 return err;
242 }
243
244 if (spec->dig_out) {
245 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
246 spec->dig_out);
247 if (err < 0)
248 return err;
249 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
250 if (err < 0)
251 return err;
252 spec->multiout.share_spdif = 1;
253 }
254 if (spec->dig_in) {
255 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
256 if (err < 0)
257 return err;
258 err = add_in_volume(codec, spec->dig_in, "IEC958");
259 }
260 return 0;
261}
262
263/*
264 */
265static const struct hda_pcm_stream ca0110_pcm_analog_playback = {
266 .substreams = 1,
267 .channels_min = 2,
268 .channels_max = 8,
269 .ops = {
270 .open = ca0110_playback_pcm_open,
271 .prepare = ca0110_playback_pcm_prepare,
272 .cleanup = ca0110_playback_pcm_cleanup
273 },
274};
275
276static const struct hda_pcm_stream ca0110_pcm_analog_capture = {
277 .substreams = 1,
278 .channels_min = 2,
279 .channels_max = 2,
280 .ops = {
281 .prepare = ca0110_capture_pcm_prepare,
282 .cleanup = ca0110_capture_pcm_cleanup
283 },
284};
285
286static const struct hda_pcm_stream ca0110_pcm_digital_playback = {
287 .substreams = 1,
288 .channels_min = 2,
289 .channels_max = 2,
290 .ops = {
291 .open = ca0110_dig_playback_pcm_open,
292 .close = ca0110_dig_playback_pcm_close,
293 .prepare = ca0110_dig_playback_pcm_prepare
294 },
295};
296
297static const struct hda_pcm_stream ca0110_pcm_digital_capture = {
298 .substreams = 1,
299 .channels_min = 2,
300 .channels_max = 2,
301};
302
303static int ca0110_build_pcms(struct hda_codec *codec)
304{
305 struct ca0110_spec *spec = codec->spec;
306 struct hda_pcm *info = spec->pcm_rec;
307
308 codec->pcm_info = info;
309 codec->num_pcms = 0;
310
311 info->name = "CA0110 Analog";
312 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0110_pcm_analog_playback;
313 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
314 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
315 spec->multiout.max_channels;
316 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0110_pcm_analog_capture;
317 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_inputs;
318 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
319 codec->num_pcms++;
320
321 if (!spec->dig_out && !spec->dig_in)
322 return 0;
323
324 info++;
325 info->name = "CA0110 Digital";
326 info->pcm_type = HDA_PCM_TYPE_SPDIF;
327 if (spec->dig_out) {
328 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
329 ca0110_pcm_digital_playback;
330 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
331 }
332 if (spec->dig_in) {
333 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
334 ca0110_pcm_digital_capture;
335 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
336 }
337 codec->num_pcms++;
338
339 return 0;
340}
341
342static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
343{
344 if (pin) {
345 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
346 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
347 snd_hda_codec_write(codec, pin, 0,
348 AC_VERB_SET_AMP_GAIN_MUTE,
349 AMP_OUT_UNMUTE);
350 }
351 if (dac)
352 snd_hda_codec_write(codec, dac, 0,
353 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
354}
355
356static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
357{
358 if (pin) {
359 snd_hda_set_pin_ctl(codec, pin, PIN_IN |
360 snd_hda_get_default_vref(codec, pin));
361 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
362 snd_hda_codec_write(codec, pin, 0,
363 AC_VERB_SET_AMP_GAIN_MUTE,
364 AMP_IN_UNMUTE(0));
365 }
366 if (adc)
367 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
368 AMP_IN_UNMUTE(0));
369}
370
371static int ca0110_init(struct hda_codec *codec)
372{
373 struct ca0110_spec *spec = codec->spec;
374 struct auto_pin_cfg *cfg = &spec->autocfg;
375 int i;
376
377 for (i = 0; i < spec->multiout.num_dacs; i++)
378 init_output(codec, spec->out_pins[i],
379 spec->multiout.dac_nids[i]);
380 init_output(codec, cfg->hp_pins[0], spec->hp_dac);
381 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
382
383 for (i = 0; i < spec->num_inputs; i++)
384 init_input(codec, spec->input_pins[i], spec->adcs[i]);
385 init_input(codec, cfg->dig_in_pin, spec->dig_in);
386 return 0;
387}
388
389static void ca0110_free(struct hda_codec *codec)
390{
391 kfree(codec->spec);
392}
393 32
394static const struct hda_codec_ops ca0110_patch_ops = { 33static const struct hda_codec_ops ca0110_patch_ops = {
395 .build_controls = ca0110_build_controls, 34 .build_controls = snd_hda_gen_build_controls,
396 .build_pcms = ca0110_build_pcms, 35 .build_pcms = snd_hda_gen_build_pcms,
397 .init = ca0110_init, 36 .init = snd_hda_gen_init,
398 .free = ca0110_free, 37 .free = snd_hda_gen_free,
38 .unsol_event = snd_hda_jack_unsol_event,
399}; 39};
400 40
401
402static void parse_line_outs(struct hda_codec *codec)
403{
404 struct ca0110_spec *spec = codec->spec;
405 struct auto_pin_cfg *cfg = &spec->autocfg;
406 int i, n;
407 unsigned int def_conf;
408 hda_nid_t nid;
409
410 n = 0;
411 for (i = 0; i < cfg->line_outs; i++) {
412 nid = cfg->line_out_pins[i];
413 def_conf = snd_hda_codec_get_pincfg(codec, nid);
414 if (!def_conf)
415 continue; /* invalid pin */
416 if (snd_hda_get_connections(codec, nid, &spec->dacs[i], 1) != 1)
417 continue;
418 spec->out_pins[n++] = nid;
419 }
420 spec->multiout.dac_nids = spec->dacs;
421 spec->multiout.num_dacs = n;
422 spec->multiout.max_channels = n * 2;
423}
424
425static void parse_hp_out(struct hda_codec *codec)
426{
427 struct ca0110_spec *spec = codec->spec;
428 struct auto_pin_cfg *cfg = &spec->autocfg;
429 int i;
430 unsigned int def_conf;
431 hda_nid_t nid, dac;
432
433 if (!cfg->hp_outs)
434 return;
435 nid = cfg->hp_pins[0];
436 def_conf = snd_hda_codec_get_pincfg(codec, nid);
437 if (!def_conf) {
438 cfg->hp_outs = 0;
439 return;
440 }
441 if (snd_hda_get_connections(codec, nid, &dac, 1) != 1)
442 return;
443
444 for (i = 0; i < cfg->line_outs; i++)
445 if (dac == spec->dacs[i])
446 break;
447 if (i >= cfg->line_outs) {
448 spec->hp_dac = dac;
449 spec->multiout.hp_nid = dac;
450 }
451}
452
453static void parse_input(struct hda_codec *codec)
454{
455 struct ca0110_spec *spec = codec->spec;
456 struct auto_pin_cfg *cfg = &spec->autocfg;
457 hda_nid_t nid, pin;
458 int n, i, j;
459
460 n = 0;
461 nid = codec->start_nid;
462 for (i = 0; i < codec->num_nodes; i++, nid++) {
463 unsigned int wcaps = get_wcaps(codec, nid);
464 unsigned int type = get_wcaps_type(wcaps);
465 if (type != AC_WID_AUD_IN)
466 continue;
467 if (snd_hda_get_connections(codec, nid, &pin, 1) != 1)
468 continue;
469 if (pin == cfg->dig_in_pin) {
470 spec->dig_in = nid;
471 continue;
472 }
473 for (j = 0; j < cfg->num_inputs; j++)
474 if (cfg->inputs[j].pin == pin)
475 break;
476 if (j >= cfg->num_inputs)
477 continue;
478 spec->input_pins[n] = pin;
479 snd_hda_get_pin_label(codec, pin, cfg,
480 spec->input_labels[n],
481 sizeof(spec->input_labels[n]), NULL);
482 spec->adcs[n] = nid;
483 n++;
484 }
485 spec->num_inputs = n;
486}
487
488static void parse_digital(struct hda_codec *codec)
489{
490 struct ca0110_spec *spec = codec->spec;
491 struct auto_pin_cfg *cfg = &spec->autocfg;
492
493 if (cfg->dig_outs &&
494 snd_hda_get_connections(codec, cfg->dig_out_pins[0],
495 &spec->dig_out, 1) == 1)
496 spec->multiout.dig_out_nid = spec->dig_out;
497}
498
499static int ca0110_parse_auto_config(struct hda_codec *codec) 41static int ca0110_parse_auto_config(struct hda_codec *codec)
500{ 42{
501 struct ca0110_spec *spec = codec->spec; 43 struct hda_gen_spec *spec = codec->spec;
502 int err; 44 int err;
503 45
504 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 46 err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0);
47 if (err < 0)
48 return err;
49 err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg);
505 if (err < 0) 50 if (err < 0)
506 return err; 51 return err;
507 52
508 parse_line_outs(codec);
509 parse_hp_out(codec);
510 parse_digital(codec);
511 parse_input(codec);
512 return 0; 53 return 0;
513} 54}
514 55
515 56
516static int patch_ca0110(struct hda_codec *codec) 57static int patch_ca0110(struct hda_codec *codec)
517{ 58{
518 struct ca0110_spec *spec; 59 struct hda_gen_spec *spec;
519 int err; 60 int err;
520 61
521 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 62 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
522 if (!spec) 63 if (!spec)
523 return -ENOMEM; 64 return -ENOMEM;
65 snd_hda_gen_spec_init(spec);
524 codec->spec = spec; 66 codec->spec = spec;
525 67
68 spec->multi_cap_vol = 1;
526 codec->bus->needs_damn_long_delay = 1; 69 codec->bus->needs_damn_long_delay = 1;
527 70
528 err = ca0110_parse_auto_config(codec); 71 err = ca0110_parse_auto_config(codec);
@@ -534,8 +77,7 @@ static int patch_ca0110(struct hda_codec *codec)
534 return 0; 77 return 0;
535 78
536 error: 79 error:
537 kfree(codec->spec); 80 snd_hda_gen_free(codec);
538 codec->spec = NULL;
539 return err; 81 return err;
540} 82}
541 83
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 49750a96d649..db02c1e96b08 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -27,16 +27,445 @@
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/firmware.h>
30#include <sound/core.h> 31#include <sound/core.h>
31#include "hda_codec.h" 32#include "hda_codec.h"
32#include "hda_local.h" 33#include "hda_local.h"
33#include "hda_auto_parser.h" 34#include "hda_auto_parser.h"
35#include "hda_jack.h"
36
37#include "ca0132_regs.h"
38
39/* Enable this to see controls for tuning purpose. */
40/*#define ENABLE_TUNING_CONTROLS*/
41
42#define FLOAT_ZERO 0x00000000
43#define FLOAT_ONE 0x3f800000
44#define FLOAT_TWO 0x40000000
45#define FLOAT_MINUS_5 0xc0a00000
46
47#define UNSOL_TAG_HP 0x10
48#define UNSOL_TAG_AMIC1 0x12
49#define UNSOL_TAG_DSP 0x16
50
51#define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18)
52#define DSP_DMA_WRITE_BUFLEN_OVLY (1UL<<15)
53
54#define DMA_TRANSFER_FRAME_SIZE_NWORDS 8
55#define DMA_TRANSFER_MAX_FRAME_SIZE_NWORDS 32
56#define DMA_OVERLAY_FRAME_SIZE_NWORDS 2
57
58#define MASTERCONTROL 0x80
59#define MASTERCONTROL_ALLOC_DMA_CHAN 10
60#define MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS 60
34 61
35#define WIDGET_CHIP_CTRL 0x15 62#define WIDGET_CHIP_CTRL 0x15
36#define WIDGET_DSP_CTRL 0x16 63#define WIDGET_DSP_CTRL 0x16
37 64
38#define WUH_MEM_CONNID 10 65#define MEM_CONNID_MICIN1 3
39#define DSP_MEM_CONNID 16 66#define MEM_CONNID_MICIN2 5
67#define MEM_CONNID_MICOUT1 12
68#define MEM_CONNID_MICOUT2 14
69#define MEM_CONNID_WUH 10
70#define MEM_CONNID_DSP 16
71#define MEM_CONNID_DMIC 100
72
73#define SCP_SET 0
74#define SCP_GET 1
75
76#define EFX_FILE "ctefx.bin"
77
78#ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
79MODULE_FIRMWARE(EFX_FILE);
80#endif
81
82static char *dirstr[2] = { "Playback", "Capture" };
83
84enum {
85 SPEAKER_OUT,
86 HEADPHONE_OUT
87};
88
89enum {
90 DIGITAL_MIC,
91 LINE_MIC_IN
92};
93
94enum {
95#define VNODE_START_NID 0x80
96 VNID_SPK = VNODE_START_NID, /* Speaker vnid */
97 VNID_MIC,
98 VNID_HP_SEL,
99 VNID_AMIC1_SEL,
100 VNID_HP_ASEL,
101 VNID_AMIC1_ASEL,
102 VNODE_END_NID,
103#define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
104
105#define EFFECT_START_NID 0x90
106#define OUT_EFFECT_START_NID EFFECT_START_NID
107 SURROUND = OUT_EFFECT_START_NID,
108 CRYSTALIZER,
109 DIALOG_PLUS,
110 SMART_VOLUME,
111 X_BASS,
112 EQUALIZER,
113 OUT_EFFECT_END_NID,
114#define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
115
116#define IN_EFFECT_START_NID OUT_EFFECT_END_NID
117 ECHO_CANCELLATION = IN_EFFECT_START_NID,
118 VOICE_FOCUS,
119 MIC_SVM,
120 NOISE_REDUCTION,
121 IN_EFFECT_END_NID,
122#define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
123
124 VOICEFX = IN_EFFECT_END_NID,
125 PLAY_ENHANCEMENT,
126 CRYSTAL_VOICE,
127 EFFECT_END_NID
128#define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
129};
130
131/* Effects values size*/
132#define EFFECT_VALS_MAX_COUNT 12
133
134struct ct_effect {
135 char name[44];
136 hda_nid_t nid;
137 int mid; /*effect module ID*/
138 int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/
139 int direct; /* 0:output; 1:input*/
140 int params; /* number of default non-on/off params */
141 /*effect default values, 1st is on/off. */
142 unsigned int def_vals[EFFECT_VALS_MAX_COUNT];
143};
144
145#define EFX_DIR_OUT 0
146#define EFX_DIR_IN 1
147
148static struct ct_effect ca0132_effects[EFFECTS_COUNT] = {
149 { .name = "Surround",
150 .nid = SURROUND,
151 .mid = 0x96,
152 .reqs = {0, 1},
153 .direct = EFX_DIR_OUT,
154 .params = 1,
155 .def_vals = {0x3F800000, 0x3F2B851F}
156 },
157 { .name = "Crystalizer",
158 .nid = CRYSTALIZER,
159 .mid = 0x96,
160 .reqs = {7, 8},
161 .direct = EFX_DIR_OUT,
162 .params = 1,
163 .def_vals = {0x3F800000, 0x3F266666}
164 },
165 { .name = "Dialog Plus",
166 .nid = DIALOG_PLUS,
167 .mid = 0x96,
168 .reqs = {2, 3},
169 .direct = EFX_DIR_OUT,
170 .params = 1,
171 .def_vals = {0x00000000, 0x3F000000}
172 },
173 { .name = "Smart Volume",
174 .nid = SMART_VOLUME,
175 .mid = 0x96,
176 .reqs = {4, 5, 6},
177 .direct = EFX_DIR_OUT,
178 .params = 2,
179 .def_vals = {0x3F800000, 0x3F3D70A4, 0x00000000}
180 },
181 { .name = "X-Bass",
182 .nid = X_BASS,
183 .mid = 0x96,
184 .reqs = {24, 23, 25},
185 .direct = EFX_DIR_OUT,
186 .params = 2,
187 .def_vals = {0x3F800000, 0x42A00000, 0x3F000000}
188 },
189 { .name = "Equalizer",
190 .nid = EQUALIZER,
191 .mid = 0x96,
192 .reqs = {9, 10, 11, 12, 13, 14,
193 15, 16, 17, 18, 19, 20},
194 .direct = EFX_DIR_OUT,
195 .params = 11,
196 .def_vals = {0x00000000, 0x00000000, 0x00000000, 0x00000000,
197 0x00000000, 0x00000000, 0x00000000, 0x00000000,
198 0x00000000, 0x00000000, 0x00000000, 0x00000000}
199 },
200 { .name = "Echo Cancellation",
201 .nid = ECHO_CANCELLATION,
202 .mid = 0x95,
203 .reqs = {0, 1, 2, 3},
204 .direct = EFX_DIR_IN,
205 .params = 3,
206 .def_vals = {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
207 },
208 { .name = "Voice Focus",
209 .nid = VOICE_FOCUS,
210 .mid = 0x95,
211 .reqs = {6, 7, 8, 9},
212 .direct = EFX_DIR_IN,
213 .params = 3,
214 .def_vals = {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
215 },
216 { .name = "Mic SVM",
217 .nid = MIC_SVM,
218 .mid = 0x95,
219 .reqs = {44, 45},
220 .direct = EFX_DIR_IN,
221 .params = 1,
222 .def_vals = {0x00000000, 0x3F3D70A4}
223 },
224 { .name = "Noise Reduction",
225 .nid = NOISE_REDUCTION,
226 .mid = 0x95,
227 .reqs = {4, 5},
228 .direct = EFX_DIR_IN,
229 .params = 1,
230 .def_vals = {0x3F800000, 0x3F000000}
231 },
232 { .name = "VoiceFX",
233 .nid = VOICEFX,
234 .mid = 0x95,
235 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18},
236 .direct = EFX_DIR_IN,
237 .params = 8,
238 .def_vals = {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
239 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
240 0x00000000}
241 }
242};
243
244/* Tuning controls */
245#ifdef ENABLE_TUNING_CONTROLS
246
247enum {
248#define TUNING_CTL_START_NID 0xC0
249 WEDGE_ANGLE = TUNING_CTL_START_NID,
250 SVM_LEVEL,
251 EQUALIZER_BAND_0,
252 EQUALIZER_BAND_1,
253 EQUALIZER_BAND_2,
254 EQUALIZER_BAND_3,
255 EQUALIZER_BAND_4,
256 EQUALIZER_BAND_5,
257 EQUALIZER_BAND_6,
258 EQUALIZER_BAND_7,
259 EQUALIZER_BAND_8,
260 EQUALIZER_BAND_9,
261 TUNING_CTL_END_NID
262#define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
263};
264
265struct ct_tuning_ctl {
266 char name[44];
267 hda_nid_t parent_nid;
268 hda_nid_t nid;
269 int mid; /*effect module ID*/
270 int req; /*effect module request*/
271 int direct; /* 0:output; 1:input*/
272 unsigned int def_val;/*effect default values*/
273};
274
275static struct ct_tuning_ctl ca0132_tuning_ctls[] = {
276 { .name = "Wedge Angle",
277 .parent_nid = VOICE_FOCUS,
278 .nid = WEDGE_ANGLE,
279 .mid = 0x95,
280 .req = 8,
281 .direct = EFX_DIR_IN,
282 .def_val = 0x41F00000
283 },
284 { .name = "SVM Level",
285 .parent_nid = MIC_SVM,
286 .nid = SVM_LEVEL,
287 .mid = 0x95,
288 .req = 45,
289 .direct = EFX_DIR_IN,
290 .def_val = 0x3F3D70A4
291 },
292 { .name = "EQ Band0",
293 .parent_nid = EQUALIZER,
294 .nid = EQUALIZER_BAND_0,
295 .mid = 0x96,
296 .req = 11,
297 .direct = EFX_DIR_OUT,
298 .def_val = 0x00000000
299 },
300 { .name = "EQ Band1",
301 .parent_nid = EQUALIZER,
302 .nid = EQUALIZER_BAND_1,
303 .mid = 0x96,
304 .req = 12,
305 .direct = EFX_DIR_OUT,
306 .def_val = 0x00000000
307 },
308 { .name = "EQ Band2",
309 .parent_nid = EQUALIZER,
310 .nid = EQUALIZER_BAND_2,
311 .mid = 0x96,
312 .req = 13,
313 .direct = EFX_DIR_OUT,
314 .def_val = 0x00000000
315 },
316 { .name = "EQ Band3",
317 .parent_nid = EQUALIZER,
318 .nid = EQUALIZER_BAND_3,
319 .mid = 0x96,
320 .req = 14,
321 .direct = EFX_DIR_OUT,
322 .def_val = 0x00000000
323 },
324 { .name = "EQ Band4",
325 .parent_nid = EQUALIZER,
326 .nid = EQUALIZER_BAND_4,
327 .mid = 0x96,
328 .req = 15,
329 .direct = EFX_DIR_OUT,
330 .def_val = 0x00000000
331 },
332 { .name = "EQ Band5",
333 .parent_nid = EQUALIZER,
334 .nid = EQUALIZER_BAND_5,
335 .mid = 0x96,
336 .req = 16,
337 .direct = EFX_DIR_OUT,
338 .def_val = 0x00000000
339 },
340 { .name = "EQ Band6",
341 .parent_nid = EQUALIZER,
342 .nid = EQUALIZER_BAND_6,
343 .mid = 0x96,
344 .req = 17,
345 .direct = EFX_DIR_OUT,
346 .def_val = 0x00000000
347 },
348 { .name = "EQ Band7",
349 .parent_nid = EQUALIZER,
350 .nid = EQUALIZER_BAND_7,
351 .mid = 0x96,
352 .req = 18,
353 .direct = EFX_DIR_OUT,
354 .def_val = 0x00000000
355 },
356 { .name = "EQ Band8",
357 .parent_nid = EQUALIZER,
358 .nid = EQUALIZER_BAND_8,
359 .mid = 0x96,
360 .req = 19,
361 .direct = EFX_DIR_OUT,
362 .def_val = 0x00000000
363 },
364 { .name = "EQ Band9",
365 .parent_nid = EQUALIZER,
366 .nid = EQUALIZER_BAND_9,
367 .mid = 0x96,
368 .req = 20,
369 .direct = EFX_DIR_OUT,
370 .def_val = 0x00000000
371 }
372};
373#endif
374
375/* Voice FX Presets */
376#define VOICEFX_MAX_PARAM_COUNT 9
377
378struct ct_voicefx {
379 char *name;
380 hda_nid_t nid;
381 int mid;
382 int reqs[VOICEFX_MAX_PARAM_COUNT]; /*effect module request*/
383};
384
385struct ct_voicefx_preset {
386 char *name; /*preset name*/
387 unsigned int vals[VOICEFX_MAX_PARAM_COUNT];
388};
389
390static struct ct_voicefx ca0132_voicefx = {
391 .name = "VoiceFX Capture Switch",
392 .nid = VOICEFX,
393 .mid = 0x95,
394 .reqs = {10, 11, 12, 13, 14, 15, 16, 17, 18}
395};
396
397static struct ct_voicefx_preset ca0132_voicefx_presets[] = {
398 { .name = "Neutral",
399 .vals = { 0x00000000, 0x43C80000, 0x44AF0000,
400 0x44FA0000, 0x3F800000, 0x3F800000,
401 0x3F800000, 0x00000000, 0x00000000 }
402 },
403 { .name = "Female2Male",
404 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
405 0x44FA0000, 0x3F19999A, 0x3F866666,
406 0x3F800000, 0x00000000, 0x00000000 }
407 },
408 { .name = "Male2Female",
409 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
410 0x450AC000, 0x4017AE14, 0x3F6B851F,
411 0x3F800000, 0x00000000, 0x00000000 }
412 },
413 { .name = "ScrappyKid",
414 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
415 0x44FA0000, 0x40400000, 0x3F28F5C3,
416 0x3F800000, 0x00000000, 0x00000000 }
417 },
418 { .name = "Elderly",
419 .vals = { 0x3F800000, 0x44324000, 0x44BB8000,
420 0x44E10000, 0x3FB33333, 0x3FB9999A,
421 0x3F800000, 0x3E3A2E43, 0x00000000 }
422 },
423 { .name = "Orc",
424 .vals = { 0x3F800000, 0x43EA0000, 0x44A52000,
425 0x45098000, 0x3F266666, 0x3FC00000,
426 0x3F800000, 0x00000000, 0x00000000 }
427 },
428 { .name = "Elf",
429 .vals = { 0x3F800000, 0x43C70000, 0x44AE6000,
430 0x45193000, 0x3F8E147B, 0x3F75C28F,
431 0x3F800000, 0x00000000, 0x00000000 }
432 },
433 { .name = "Dwarf",
434 .vals = { 0x3F800000, 0x43930000, 0x44BEE000,
435 0x45007000, 0x3F451EB8, 0x3F7851EC,
436 0x3F800000, 0x00000000, 0x00000000 }
437 },
438 { .name = "AlienBrute",
439 .vals = { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
440 0x451F6000, 0x3F266666, 0x3FA7D945,
441 0x3F800000, 0x3CF5C28F, 0x00000000 }
442 },
443 { .name = "Robot",
444 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
445 0x44FA0000, 0x3FB2718B, 0x3F800000,
446 0xBC07010E, 0x00000000, 0x00000000 }
447 },
448 { .name = "Marine",
449 .vals = { 0x3F800000, 0x43C20000, 0x44906000,
450 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
451 0x3F0A3D71, 0x00000000, 0x00000000 }
452 },
453 { .name = "Emo",
454 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
455 0x44FA0000, 0x3F800000, 0x3F800000,
456 0x3E4CCCCD, 0x00000000, 0x00000000 }
457 },
458 { .name = "DeepVoice",
459 .vals = { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
460 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
461 0x3F800000, 0x00000000, 0x00000000 }
462 },
463 { .name = "Munchkin",
464 .vals = { 0x3F800000, 0x43C80000, 0x44AF0000,
465 0x44FA0000, 0x3F800000, 0x3F1A043C,
466 0x3F800000, 0x00000000, 0x00000000 }
467 }
468};
40 469
41enum hda_cmd_vendor_io { 470enum hda_cmd_vendor_io {
42 /* for DspIO node */ 471 /* for DspIO node */
@@ -62,7 +491,11 @@ enum hda_cmd_vendor_io {
62 VENDOR_CHIPIO_HIC_POST_READ = 0x702, 491 VENDOR_CHIPIO_HIC_POST_READ = 0x702,
63 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03, 492 VENDOR_CHIPIO_HIC_READ_DATA = 0xF03,
64 493
494 VENDOR_CHIPIO_8051_DATA_WRITE = 0x707,
495 VENDOR_CHIPIO_8051_DATA_READ = 0xF07,
496
65 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A, 497 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A,
498 VENDOR_CHIPIO_CT_EXTENSIONS_GET = 0xF0A,
66 499
67 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C, 500 VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C,
68 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C, 501 VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C,
@@ -70,18 +503,27 @@ enum hda_cmd_vendor_io {
70 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E, 503 VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E,
71 VENDOR_CHIPIO_FLAG_SET = 0x70F, 504 VENDOR_CHIPIO_FLAG_SET = 0x70F,
72 VENDOR_CHIPIO_FLAGS_GET = 0xF0F, 505 VENDOR_CHIPIO_FLAGS_GET = 0xF0F,
73 VENDOR_CHIPIO_PARAMETER_SET = 0x710, 506 VENDOR_CHIPIO_PARAM_SET = 0x710,
74 VENDOR_CHIPIO_PARAMETER_GET = 0xF10, 507 VENDOR_CHIPIO_PARAM_GET = 0xF10,
75 508
76 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711, 509 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711,
77 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712, 510 VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712,
78 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12, 511 VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12,
79 VENDOR_CHIPIO_PORT_FREE_SET = 0x713, 512 VENDOR_CHIPIO_PORT_FREE_SET = 0x713,
80 513
81 VENDOR_CHIPIO_PARAMETER_EX_ID_GET = 0xF17, 514 VENDOR_CHIPIO_PARAM_EX_ID_GET = 0xF17,
82 VENDOR_CHIPIO_PARAMETER_EX_ID_SET = 0x717, 515 VENDOR_CHIPIO_PARAM_EX_ID_SET = 0x717,
83 VENDOR_CHIPIO_PARAMETER_EX_VALUE_GET = 0xF18, 516 VENDOR_CHIPIO_PARAM_EX_VALUE_GET = 0xF18,
84 VENDOR_CHIPIO_PARAMETER_EX_VALUE_SET = 0x718 517 VENDOR_CHIPIO_PARAM_EX_VALUE_SET = 0x718,
518
519 VENDOR_CHIPIO_DMIC_CTL_SET = 0x788,
520 VENDOR_CHIPIO_DMIC_CTL_GET = 0xF88,
521 VENDOR_CHIPIO_DMIC_PIN_SET = 0x789,
522 VENDOR_CHIPIO_DMIC_PIN_GET = 0xF89,
523 VENDOR_CHIPIO_DMIC_MCLK_SET = 0x78A,
524 VENDOR_CHIPIO_DMIC_MCLK_GET = 0xF8A,
525
526 VENDOR_CHIPIO_EAPD_SEL_SET = 0x78D
85}; 527};
86 528
87/* 529/*
@@ -131,7 +573,7 @@ enum control_flag_id {
131 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */ 573 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
132 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20, 574 CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20,
133 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */ 575 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
134 CONTROL_FLAG_PORT_D_10K0HM_LOAD = 21, 576 CONTROL_FLAG_PORT_D_10KOHM_LOAD = 21,
135 /* ASI rate is 48kHz/96kHz */ 577 /* ASI rate is 48kHz/96kHz */
136 CONTROL_FLAG_ASI_96KHZ = 22, 578 CONTROL_FLAG_ASI_96KHZ = 22,
137 /* DAC power settings able to control attached ports no/yes */ 579 /* DAC power settings able to control attached ports no/yes */
@@ -145,9 +587,17 @@ enum control_flag_id {
145/* 587/*
146 * Control parameter IDs 588 * Control parameter IDs
147 */ 589 */
148enum control_parameter_id { 590enum control_param_id {
591 /* 0: None, 1: Mic1In*/
592 CONTROL_PARAM_VIP_SOURCE = 1,
149 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */ 593 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
150 CONTROL_PARAM_SPDIF1_SOURCE = 2, 594 CONTROL_PARAM_SPDIF1_SOURCE = 2,
595 /* Port A output stage gain setting to use when 16 Ohm output
596 * impedance is selected*/
597 CONTROL_PARAM_PORTA_160OHM_GAIN = 8,
598 /* Port D output stage gain setting to use when 16 Ohm output
599 * impedance is selected*/
600 CONTROL_PARAM_PORTD_160OHM_GAIN = 10,
151 601
152 /* Stream Control */ 602 /* Stream Control */
153 603
@@ -225,123 +675,115 @@ enum ca0132_sample_rate {
225 SR_RATE_UNKNOWN = 0x1F 675 SR_RATE_UNKNOWN = 0x1F
226}; 676};
227 677
228/* 678enum dsp_download_state {
229 * Scp Helper function 679 DSP_DOWNLOAD_FAILED = -1,
230 */ 680 DSP_DOWNLOAD_INIT = 0,
231enum get_set { 681 DSP_DOWNLOADING = 1,
232 IS_SET = 0, 682 DSP_DOWNLOADED = 2
233 IS_GET = 1,
234}; 683};
235 684
236/* 685/* retrieve parameters from hda format */
237 * Duplicated from ca0110 codec 686#define get_hdafmt_chs(fmt) (fmt & 0xf)
238 */ 687#define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
239 688#define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
240static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) 689#define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
241{
242 if (pin) {
243 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
244 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
245 snd_hda_codec_write(codec, pin, 0,
246 AC_VERB_SET_AMP_GAIN_MUTE,
247 AMP_OUT_UNMUTE);
248 }
249 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
250 snd_hda_codec_write(codec, dac, 0,
251 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
252}
253
254static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
255{
256 if (pin) {
257 snd_hda_set_pin_ctl(codec, pin, PIN_IN |
258 snd_hda_get_default_vref(codec, pin));
259 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
260 snd_hda_codec_write(codec, pin, 0,
261 AC_VERB_SET_AMP_GAIN_MUTE,
262 AMP_IN_UNMUTE(0));
263 }
264 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP))
265 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
266 AMP_IN_UNMUTE(0));
267}
268
269static char *dirstr[2] = { "Playback", "Capture" };
270
271static int _add_switch(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
272 int chan, int dir)
273{
274 char namestr[44];
275 int type = dir ? HDA_INPUT : HDA_OUTPUT;
276 struct snd_kcontrol_new knew =
277 HDA_CODEC_MUTE_MONO(namestr, nid, chan, 0, type);
278 if ((query_amp_caps(codec, nid, type) & AC_AMPCAP_MUTE) == 0) {
279 snd_printdd("Skipping '%s %s Switch' (no mute on node 0x%x)\n", pfx, dirstr[dir], nid);
280 return 0;
281 }
282 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
283 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
284}
285
286static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
287 int chan, int dir)
288{
289 char namestr[44];
290 int type = dir ? HDA_INPUT : HDA_OUTPUT;
291 struct snd_kcontrol_new knew =
292 HDA_CODEC_VOLUME_MONO(namestr, nid, chan, 0, type);
293 if ((query_amp_caps(codec, nid, type) & AC_AMPCAP_NUM_STEPS) == 0) {
294 snd_printdd("Skipping '%s %s Volume' (no amp on node 0x%x)\n", pfx, dirstr[dir], nid);
295 return 0;
296 }
297 sprintf(namestr, "%s %s Volume", pfx, dirstr[dir]);
298 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
299}
300
301#define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0)
302#define add_out_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 0)
303#define add_in_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 1)
304#define add_in_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 1)
305#define add_mono_switch(codec, nid, pfx, chan) \
306 _add_switch(codec, nid, pfx, chan, 0)
307#define add_mono_volume(codec, nid, pfx, chan) \
308 _add_volume(codec, nid, pfx, chan, 0)
309#define add_in_mono_switch(codec, nid, pfx, chan) \
310 _add_switch(codec, nid, pfx, chan, 1)
311#define add_in_mono_volume(codec, nid, pfx, chan) \
312 _add_volume(codec, nid, pfx, chan, 1)
313
314 690
315/* 691/*
316 * CA0132 specific 692 * CA0132 specific
317 */ 693 */
318 694
319struct ca0132_spec { 695struct ca0132_spec {
696 struct snd_kcontrol_new *mixers[5];
697 unsigned int num_mixers;
698 const struct hda_verb *base_init_verbs;
699 const struct hda_verb *base_exit_verbs;
700 const struct hda_verb *init_verbs[5];
701 unsigned int num_init_verbs; /* exclude base init verbs */
320 struct auto_pin_cfg autocfg; 702 struct auto_pin_cfg autocfg;
703
704 /* Nodes configurations */
321 struct hda_multi_out multiout; 705 struct hda_multi_out multiout;
322 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS]; 706 hda_nid_t out_pins[AUTO_CFG_MAX_OUTS];
323 hda_nid_t dacs[AUTO_CFG_MAX_OUTS]; 707 hda_nid_t dacs[AUTO_CFG_MAX_OUTS];
324 hda_nid_t hp_dac; 708 unsigned int num_outputs;
325 hda_nid_t input_pins[AUTO_PIN_LAST]; 709 hda_nid_t input_pins[AUTO_PIN_LAST];
326 hda_nid_t adcs[AUTO_PIN_LAST]; 710 hda_nid_t adcs[AUTO_PIN_LAST];
327 hda_nid_t dig_out; 711 hda_nid_t dig_out;
328 hda_nid_t dig_in; 712 hda_nid_t dig_in;
329 unsigned int num_inputs; 713 unsigned int num_inputs;
330 long curr_hp_switch; 714 hda_nid_t shared_mic_nid;
331 long curr_hp_volume[2]; 715 hda_nid_t shared_out_nid;
332 long curr_speaker_switch; 716 struct hda_pcm pcm_rec[5]; /* PCM information */
333 struct mutex chipio_mutex; 717
334 const char *input_labels[AUTO_PIN_LAST]; 718 /* chip access */
335 struct hda_pcm pcm_rec[2]; /* PCM information */ 719 struct mutex chipio_mutex; /* chip access mutex */
720 u32 curr_chip_addx;
721
722 /* DSP download related */
723 enum dsp_download_state dsp_state;
724 unsigned int dsp_stream_id;
725 unsigned int wait_scp;
726 unsigned int wait_scp_header;
727 unsigned int wait_num_data;
728 unsigned int scp_resp_header;
729 unsigned int scp_resp_data[4];
730 unsigned int scp_resp_count;
731
732 /* mixer and effects related */
733 unsigned char dmic_ctl;
734 int cur_out_type;
735 int cur_mic_type;
736 long vnode_lvol[VNODES_COUNT];
737 long vnode_rvol[VNODES_COUNT];
738 long vnode_lswitch[VNODES_COUNT];
739 long vnode_rswitch[VNODES_COUNT];
740 long effects_switch[EFFECTS_COUNT];
741 long voicefx_val;
742 long cur_mic_boost;
743
744#ifdef ENABLE_TUNING_CONTROLS
745 long cur_ctl_vals[TUNING_CTLS_COUNT];
746#endif
336}; 747};
337 748
749/*
750 * CA0132 codec access
751 */
752unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
753 unsigned int verb, unsigned int parm, unsigned int *res)
754{
755 unsigned int response;
756 response = snd_hda_codec_read(codec, nid, 0, verb, parm);
757 *res = response;
758
759 return ((response == -1) ? -1 : 0);
760}
761
762static int codec_set_converter_format(struct hda_codec *codec, hda_nid_t nid,
763 unsigned short converter_format, unsigned int *res)
764{
765 return codec_send_command(codec, nid, VENDOR_CHIPIO_STREAM_FORMAT,
766 converter_format & 0xffff, res);
767}
768
769static int codec_set_converter_stream_channel(struct hda_codec *codec,
770 hda_nid_t nid, unsigned char stream,
771 unsigned char channel, unsigned int *res)
772{
773 unsigned char converter_stream_channel = 0;
774
775 converter_stream_channel = (stream << 4) | (channel & 0x0f);
776 return codec_send_command(codec, nid, AC_VERB_SET_CHANNEL_STREAMID,
777 converter_stream_channel, res);
778}
779
338/* Chip access helper function */ 780/* Chip access helper function */
339static int chipio_send(struct hda_codec *codec, 781static int chipio_send(struct hda_codec *codec,
340 unsigned int reg, 782 unsigned int reg,
341 unsigned int data) 783 unsigned int data)
342{ 784{
343 unsigned int res; 785 unsigned int res;
344 int retry = 50; 786 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
345 787
346 /* send bits of data specified by reg */ 788 /* send bits of data specified by reg */
347 do { 789 do {
@@ -349,7 +791,9 @@ static int chipio_send(struct hda_codec *codec,
349 reg, data); 791 reg, data);
350 if (res == VENDOR_STATUS_CHIPIO_OK) 792 if (res == VENDOR_STATUS_CHIPIO_OK)
351 return 0; 793 return 0;
352 } while (--retry); 794 msleep(20);
795 } while (time_before(jiffies, timeout));
796
353 return -EIO; 797 return -EIO;
354} 798}
355 799
@@ -359,8 +803,12 @@ static int chipio_send(struct hda_codec *codec,
359static int chipio_write_address(struct hda_codec *codec, 803static int chipio_write_address(struct hda_codec *codec,
360 unsigned int chip_addx) 804 unsigned int chip_addx)
361{ 805{
806 struct ca0132_spec *spec = codec->spec;
362 int res; 807 int res;
363 808
809 if (spec->curr_chip_addx == chip_addx)
810 return 0;
811
364 /* send low 16 bits of the address */ 812 /* send low 16 bits of the address */
365 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW, 813 res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
366 chip_addx & 0xffff); 814 chip_addx & 0xffff);
@@ -371,15 +819,17 @@ static int chipio_write_address(struct hda_codec *codec,
371 chip_addx >> 16); 819 chip_addx >> 16);
372 } 820 }
373 821
822 spec->curr_chip_addx = (res < 0) ? ~0UL : chip_addx;
823
374 return res; 824 return res;
375} 825}
376 826
377/* 827/*
378 * Write data through the vendor widget -- NOT protected by the Mutex! 828 * Write data through the vendor widget -- NOT protected by the Mutex!
379 */ 829 */
380
381static int chipio_write_data(struct hda_codec *codec, unsigned int data) 830static int chipio_write_data(struct hda_codec *codec, unsigned int data)
382{ 831{
832 struct ca0132_spec *spec = codec->spec;
383 int res; 833 int res;
384 834
385 /* send low 16 bits of the data */ 835 /* send low 16 bits of the data */
@@ -391,14 +841,40 @@ static int chipio_write_data(struct hda_codec *codec, unsigned int data)
391 data >> 16); 841 data >> 16);
392 } 842 }
393 843
844 /*If no error encountered, automatically increment the address
845 as per chip behaviour*/
846 spec->curr_chip_addx = (res != -EIO) ?
847 (spec->curr_chip_addx + 4) : ~0UL;
394 return res; 848 return res;
395} 849}
396 850
397/* 851/*
852 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
853 */
854static int chipio_write_data_multiple(struct hda_codec *codec,
855 const u32 *data,
856 unsigned int count)
857{
858 int status = 0;
859
860 if (data == NULL) {
861 snd_printdd(KERN_ERR "chipio_write_data null ptr\n");
862 return -EINVAL;
863 }
864
865 while ((count-- != 0) && (status == 0))
866 status = chipio_write_data(codec, *data++);
867
868 return status;
869}
870
871
872/*
398 * Read data through the vendor widget -- NOT protected by the Mutex! 873 * Read data through the vendor widget -- NOT protected by the Mutex!
399 */ 874 */
400static int chipio_read_data(struct hda_codec *codec, unsigned int *data) 875static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
401{ 876{
877 struct ca0132_spec *spec = codec->spec;
402 int res; 878 int res;
403 879
404 /* post read */ 880 /* post read */
@@ -416,6 +892,10 @@ static int chipio_read_data(struct hda_codec *codec, unsigned int *data)
416 0); 892 0);
417 } 893 }
418 894
895 /*If no error encountered, automatically increment the address
896 as per chip behaviour*/
897 spec->curr_chip_addx = (res != -EIO) ?
898 (spec->curr_chip_addx + 4) : ~0UL;
419 return res; 899 return res;
420} 900}
421 901
@@ -446,6 +926,30 @@ exit:
446} 926}
447 927
448/* 928/*
929 * Write multiple values to the given address through the chip I/O widget.
930 * protected by the Mutex
931 */
932static int chipio_write_multiple(struct hda_codec *codec,
933 u32 chip_addx,
934 const u32 *data,
935 unsigned int count)
936{
937 struct ca0132_spec *spec = codec->spec;
938 int status;
939
940 mutex_lock(&spec->chipio_mutex);
941 status = chipio_write_address(codec, chip_addx);
942 if (status < 0)
943 goto error;
944
945 status = chipio_write_data_multiple(codec, data, count);
946error:
947 mutex_unlock(&spec->chipio_mutex);
948
949 return status;
950}
951
952/*
449 * Read the given address through the chip I/O widget 953 * Read the given address through the chip I/O widget
450 * protected by the Mutex 954 * protected by the Mutex
451 */ 955 */
@@ -472,17 +976,1734 @@ exit:
472} 976}
473 977
474/* 978/*
475 * PCM callbacks 979 * Set chip control flags through the chip I/O widget.
980 */
981static void chipio_set_control_flag(struct hda_codec *codec,
982 enum control_flag_id flag_id,
983 bool flag_state)
984{
985 unsigned int val;
986 unsigned int flag_bit;
987
988 flag_bit = (flag_state ? 1 : 0);
989 val = (flag_bit << 7) | (flag_id);
990 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
991 VENDOR_CHIPIO_FLAG_SET, val);
992}
993
994/*
995 * Set chip parameters through the chip I/O widget.
996 */
997static void chipio_set_control_param(struct hda_codec *codec,
998 enum control_param_id param_id, int param_val)
999{
1000 struct ca0132_spec *spec = codec->spec;
1001 int val;
1002
1003 if ((param_id < 32) && (param_val < 8)) {
1004 val = (param_val << 5) | (param_id);
1005 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1006 VENDOR_CHIPIO_PARAM_SET, val);
1007 } else {
1008 mutex_lock(&spec->chipio_mutex);
1009 if (chipio_send(codec, VENDOR_CHIPIO_STATUS, 0) == 0) {
1010 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1011 VENDOR_CHIPIO_PARAM_EX_ID_SET,
1012 param_id);
1013 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1014 VENDOR_CHIPIO_PARAM_EX_VALUE_SET,
1015 param_val);
1016 }
1017 mutex_unlock(&spec->chipio_mutex);
1018 }
1019}
1020
1021/*
1022 * Set sampling rate of the connection point.
1023 */
1024static void chipio_set_conn_rate(struct hda_codec *codec,
1025 int connid, enum ca0132_sample_rate rate)
1026{
1027 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_ID, connid);
1028 chipio_set_control_param(codec, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE,
1029 rate);
1030}
1031
1032/*
1033 * Enable clocks.
1034 */
1035static void chipio_enable_clocks(struct hda_codec *codec)
1036{
1037 struct ca0132_spec *spec = codec->spec;
1038
1039 mutex_lock(&spec->chipio_mutex);
1040 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1041 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0);
1042 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1043 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1044 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1045 VENDOR_CHIPIO_8051_ADDRESS_LOW, 5);
1046 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1047 VENDOR_CHIPIO_PLL_PMU_WRITE, 0x0b);
1048 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1049 VENDOR_CHIPIO_8051_ADDRESS_LOW, 6);
1050 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1051 VENDOR_CHIPIO_PLL_PMU_WRITE, 0xff);
1052 mutex_unlock(&spec->chipio_mutex);
1053}
1054
1055/*
1056 * CA0132 DSP IO stuffs
1057 */
1058static int dspio_send(struct hda_codec *codec, unsigned int reg,
1059 unsigned int data)
1060{
1061 int res;
1062 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1063
1064 /* send bits of data specified by reg to dsp */
1065 do {
1066 res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
1067 if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
1068 return res;
1069 msleep(20);
1070 } while (time_before(jiffies, timeout));
1071
1072 return -EIO;
1073}
1074
1075/*
1076 * Wait for DSP to be ready for commands
1077 */
1078static void dspio_write_wait(struct hda_codec *codec)
1079{
1080 int status;
1081 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1082
1083 do {
1084 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1085 VENDOR_DSPIO_STATUS, 0);
1086 if ((status == VENDOR_STATUS_DSPIO_OK) ||
1087 (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
1088 break;
1089 msleep(1);
1090 } while (time_before(jiffies, timeout));
1091}
1092
1093/*
1094 * Write SCP data to DSP
1095 */
1096static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
1097{
1098 struct ca0132_spec *spec = codec->spec;
1099 int status;
1100
1101 dspio_write_wait(codec);
1102
1103 mutex_lock(&spec->chipio_mutex);
1104 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_LOW,
1105 scp_data & 0xffff);
1106 if (status < 0)
1107 goto error;
1108
1109 status = dspio_send(codec, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH,
1110 scp_data >> 16);
1111 if (status < 0)
1112 goto error;
1113
1114 /* OK, now check if the write itself has executed*/
1115 status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1116 VENDOR_DSPIO_STATUS, 0);
1117error:
1118 mutex_unlock(&spec->chipio_mutex);
1119
1120 return (status == VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL) ?
1121 -EIO : 0;
1122}
1123
1124/*
1125 * Write multiple SCP data to DSP
1126 */
1127static int dspio_write_multiple(struct hda_codec *codec,
1128 unsigned int *buffer, unsigned int size)
1129{
1130 int status = 0;
1131 unsigned int count;
1132
1133 if ((buffer == NULL))
1134 return -EINVAL;
1135
1136 count = 0;
1137 while (count < size) {
1138 status = dspio_write(codec, *buffer++);
1139 if (status != 0)
1140 break;
1141 count++;
1142 }
1143
1144 return status;
1145}
1146
1147static int dspio_read(struct hda_codec *codec, unsigned int *data)
1148{
1149 int status;
1150
1151 status = dspio_send(codec, VENDOR_DSPIO_SCP_POST_READ_DATA, 0);
1152 if (status == -EIO)
1153 return status;
1154
1155 status = dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
1156 if (status == -EIO ||
1157 status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)
1158 return -EIO;
1159
1160 *data = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
1161 VENDOR_DSPIO_SCP_READ_DATA, 0);
1162
1163 return 0;
1164}
1165
1166static int dspio_read_multiple(struct hda_codec *codec, unsigned int *buffer,
1167 unsigned int *buf_size, unsigned int size_count)
1168{
1169 int status = 0;
1170 unsigned int size = *buf_size;
1171 unsigned int count;
1172 unsigned int skip_count;
1173 unsigned int dummy;
1174
1175 if ((buffer == NULL))
1176 return -1;
1177
1178 count = 0;
1179 while (count < size && count < size_count) {
1180 status = dspio_read(codec, buffer++);
1181 if (status != 0)
1182 break;
1183 count++;
1184 }
1185
1186 skip_count = count;
1187 if (status == 0) {
1188 while (skip_count < size) {
1189 status = dspio_read(codec, &dummy);
1190 if (status != 0)
1191 break;
1192 skip_count++;
1193 }
1194 }
1195 *buf_size = count;
1196
1197 return status;
1198}
1199
1200/*
1201 * Construct the SCP header using corresponding fields
1202 */
1203static inline unsigned int
1204make_scp_header(unsigned int target_id, unsigned int source_id,
1205 unsigned int get_flag, unsigned int req,
1206 unsigned int device_flag, unsigned int resp_flag,
1207 unsigned int error_flag, unsigned int data_size)
1208{
1209 unsigned int header = 0;
1210
1211 header = (data_size & 0x1f) << 27;
1212 header |= (error_flag & 0x01) << 26;
1213 header |= (resp_flag & 0x01) << 25;
1214 header |= (device_flag & 0x01) << 24;
1215 header |= (req & 0x7f) << 17;
1216 header |= (get_flag & 0x01) << 16;
1217 header |= (source_id & 0xff) << 8;
1218 header |= target_id & 0xff;
1219
1220 return header;
1221}
1222
1223/*
1224 * Extract corresponding fields from SCP header
1225 */
1226static inline void
1227extract_scp_header(unsigned int header,
1228 unsigned int *target_id, unsigned int *source_id,
1229 unsigned int *get_flag, unsigned int *req,
1230 unsigned int *device_flag, unsigned int *resp_flag,
1231 unsigned int *error_flag, unsigned int *data_size)
1232{
1233 if (data_size)
1234 *data_size = (header >> 27) & 0x1f;
1235 if (error_flag)
1236 *error_flag = (header >> 26) & 0x01;
1237 if (resp_flag)
1238 *resp_flag = (header >> 25) & 0x01;
1239 if (device_flag)
1240 *device_flag = (header >> 24) & 0x01;
1241 if (req)
1242 *req = (header >> 17) & 0x7f;
1243 if (get_flag)
1244 *get_flag = (header >> 16) & 0x01;
1245 if (source_id)
1246 *source_id = (header >> 8) & 0xff;
1247 if (target_id)
1248 *target_id = header & 0xff;
1249}
1250
1251#define SCP_MAX_DATA_WORDS (16)
1252
1253/* Structure to contain any SCP message */
1254struct scp_msg {
1255 unsigned int hdr;
1256 unsigned int data[SCP_MAX_DATA_WORDS];
1257};
1258
1259static void dspio_clear_response_queue(struct hda_codec *codec)
1260{
1261 unsigned int dummy = 0;
1262 int status = -1;
1263
1264 /* clear all from the response queue */
1265 do {
1266 status = dspio_read(codec, &dummy);
1267 } while (status == 0);
1268}
1269
1270static int dspio_get_response_data(struct hda_codec *codec)
1271{
1272 struct ca0132_spec *spec = codec->spec;
1273 unsigned int data = 0;
1274 unsigned int count;
1275
1276 if (dspio_read(codec, &data) < 0)
1277 return -EIO;
1278
1279 if ((data & 0x00ffffff) == spec->wait_scp_header) {
1280 spec->scp_resp_header = data;
1281 spec->scp_resp_count = data >> 27;
1282 count = spec->wait_num_data;
1283 dspio_read_multiple(codec, spec->scp_resp_data,
1284 &spec->scp_resp_count, count);
1285 return 0;
1286 }
1287
1288 return -EIO;
1289}
1290
1291/*
1292 * Send SCP message to DSP
1293 */
1294static int dspio_send_scp_message(struct hda_codec *codec,
1295 unsigned char *send_buf,
1296 unsigned int send_buf_size,
1297 unsigned char *return_buf,
1298 unsigned int return_buf_size,
1299 unsigned int *bytes_returned)
1300{
1301 struct ca0132_spec *spec = codec->spec;
1302 int status = -1;
1303 unsigned int scp_send_size = 0;
1304 unsigned int total_size;
1305 bool waiting_for_resp = false;
1306 unsigned int header;
1307 struct scp_msg *ret_msg;
1308 unsigned int resp_src_id, resp_target_id;
1309 unsigned int data_size, src_id, target_id, get_flag, device_flag;
1310
1311 if (bytes_returned)
1312 *bytes_returned = 0;
1313
1314 /* get scp header from buffer */
1315 header = *((unsigned int *)send_buf);
1316 extract_scp_header(header, &target_id, &src_id, &get_flag, NULL,
1317 &device_flag, NULL, NULL, &data_size);
1318 scp_send_size = data_size + 1;
1319 total_size = (scp_send_size * 4);
1320
1321 if (send_buf_size < total_size)
1322 return -EINVAL;
1323
1324 if (get_flag || device_flag) {
1325 if (!return_buf || return_buf_size < 4 || !bytes_returned)
1326 return -EINVAL;
1327
1328 spec->wait_scp_header = *((unsigned int *)send_buf);
1329
1330 /* swap source id with target id */
1331 resp_target_id = src_id;
1332 resp_src_id = target_id;
1333 spec->wait_scp_header &= 0xffff0000;
1334 spec->wait_scp_header |= (resp_src_id << 8) | (resp_target_id);
1335 spec->wait_num_data = return_buf_size/sizeof(unsigned int) - 1;
1336 spec->wait_scp = 1;
1337 waiting_for_resp = true;
1338 }
1339
1340 status = dspio_write_multiple(codec, (unsigned int *)send_buf,
1341 scp_send_size);
1342 if (status < 0) {
1343 spec->wait_scp = 0;
1344 return status;
1345 }
1346
1347 if (waiting_for_resp) {
1348 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
1349 memset(return_buf, 0, return_buf_size);
1350 do {
1351 msleep(20);
1352 } while (spec->wait_scp && time_before(jiffies, timeout));
1353 waiting_for_resp = false;
1354 if (!spec->wait_scp) {
1355 ret_msg = (struct scp_msg *)return_buf;
1356 memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
1357 memcpy(&ret_msg->data, spec->scp_resp_data,
1358 spec->wait_num_data);
1359 *bytes_returned = (spec->scp_resp_count + 1) * 4;
1360 status = 0;
1361 } else {
1362 status = -EIO;
1363 }
1364 spec->wait_scp = 0;
1365 }
1366
1367 return status;
1368}
1369
1370/**
1371 * Prepare and send the SCP message to DSP
1372 * @codec: the HDA codec
1373 * @mod_id: ID of the DSP module to send the command
1374 * @req: ID of request to send to the DSP module
1375 * @dir: SET or GET
1376 * @data: pointer to the data to send with the request, request specific
1377 * @len: length of the data, in bytes
1378 * @reply: point to the buffer to hold data returned for a reply
1379 * @reply_len: length of the reply buffer returned from GET
1380 *
1381 * Returns zero or a negative error code.
1382 */
1383static int dspio_scp(struct hda_codec *codec,
1384 int mod_id, int req, int dir, void *data, unsigned int len,
1385 void *reply, unsigned int *reply_len)
1386{
1387 int status = 0;
1388 struct scp_msg scp_send, scp_reply;
1389 unsigned int ret_bytes, send_size, ret_size;
1390 unsigned int send_get_flag, reply_resp_flag, reply_error_flag;
1391 unsigned int reply_data_size;
1392
1393 memset(&scp_send, 0, sizeof(scp_send));
1394 memset(&scp_reply, 0, sizeof(scp_reply));
1395
1396 if ((len != 0 && data == NULL) || (len > SCP_MAX_DATA_WORDS))
1397 return -EINVAL;
1398
1399 if (dir == SCP_GET && reply == NULL) {
1400 snd_printdd(KERN_ERR "dspio_scp get but has no buffer\n");
1401 return -EINVAL;
1402 }
1403
1404 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
1405 snd_printdd(KERN_ERR "dspio_scp bad resp buf len parms\n");
1406 return -EINVAL;
1407 }
1408
1409 scp_send.hdr = make_scp_header(mod_id, 0x20, (dir == SCP_GET), req,
1410 0, 0, 0, len/sizeof(unsigned int));
1411 if (data != NULL && len > 0) {
1412 len = min((unsigned int)(sizeof(scp_send.data)), len);
1413 memcpy(scp_send.data, data, len);
1414 }
1415
1416 ret_bytes = 0;
1417 send_size = sizeof(unsigned int) + len;
1418 status = dspio_send_scp_message(codec, (unsigned char *)&scp_send,
1419 send_size, (unsigned char *)&scp_reply,
1420 sizeof(scp_reply), &ret_bytes);
1421
1422 if (status < 0) {
1423 snd_printdd(KERN_ERR "dspio_scp: send scp msg failed\n");
1424 return status;
1425 }
1426
1427 /* extract send and reply headers members */
1428 extract_scp_header(scp_send.hdr, NULL, NULL, &send_get_flag,
1429 NULL, NULL, NULL, NULL, NULL);
1430 extract_scp_header(scp_reply.hdr, NULL, NULL, NULL, NULL, NULL,
1431 &reply_resp_flag, &reply_error_flag,
1432 &reply_data_size);
1433
1434 if (!send_get_flag)
1435 return 0;
1436
1437 if (reply_resp_flag && !reply_error_flag) {
1438 ret_size = (ret_bytes - sizeof(scp_reply.hdr))
1439 / sizeof(unsigned int);
1440
1441 if (*reply_len < ret_size*sizeof(unsigned int)) {
1442 snd_printdd(KERN_ERR "reply too long for buf\n");
1443 return -EINVAL;
1444 } else if (ret_size != reply_data_size) {
1445 snd_printdd(KERN_ERR "RetLen and HdrLen .NE.\n");
1446 return -EINVAL;
1447 } else {
1448 *reply_len = ret_size*sizeof(unsigned int);
1449 memcpy(reply, scp_reply.data, *reply_len);
1450 }
1451 } else {
1452 snd_printdd(KERN_ERR "reply ill-formed or errflag set\n");
1453 return -EIO;
1454 }
1455
1456 return status;
1457}
1458
1459/*
1460 * Set DSP parameters
1461 */
1462static int dspio_set_param(struct hda_codec *codec, int mod_id,
1463 int req, void *data, unsigned int len)
1464{
1465 return dspio_scp(codec, mod_id, req, SCP_SET, data, len, NULL, NULL);
1466}
1467
1468static int dspio_set_uint_param(struct hda_codec *codec, int mod_id,
1469 int req, unsigned int data)
1470{
1471 return dspio_set_param(codec, mod_id, req, &data, sizeof(unsigned int));
1472}
1473
1474/*
1475 * Allocate a DSP DMA channel via an SCP message
1476 */
1477static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
1478{
1479 int status = 0;
1480 unsigned int size = sizeof(dma_chan);
1481
1482 snd_printdd(KERN_INFO " dspio_alloc_dma_chan() -- begin\n");
1483 status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN,
1484 SCP_GET, NULL, 0, dma_chan, &size);
1485
1486 if (status < 0) {
1487 snd_printdd(KERN_INFO "dspio_alloc_dma_chan: SCP Failed\n");
1488 return status;
1489 }
1490
1491 if ((*dma_chan + 1) == 0) {
1492 snd_printdd(KERN_INFO "no free dma channels to allocate\n");
1493 return -EBUSY;
1494 }
1495
1496 snd_printdd("dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
1497 snd_printdd(KERN_INFO " dspio_alloc_dma_chan() -- complete\n");
1498
1499 return status;
1500}
1501
1502/*
1503 * Free a DSP DMA via an SCP message
1504 */
1505static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
1506{
1507 int status = 0;
1508 unsigned int dummy = 0;
1509
1510 snd_printdd(KERN_INFO " dspio_free_dma_chan() -- begin\n");
1511 snd_printdd("dspio_free_dma_chan: chan=%d\n", dma_chan);
1512
1513 status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN,
1514 SCP_SET, &dma_chan, sizeof(dma_chan), NULL, &dummy);
1515
1516 if (status < 0) {
1517 snd_printdd(KERN_INFO "dspio_free_dma_chan: SCP Failed\n");
1518 return status;
1519 }
1520
1521 snd_printdd(KERN_INFO " dspio_free_dma_chan() -- complete\n");
1522
1523 return status;
1524}
1525
1526/*
1527 * (Re)start the DSP
476 */ 1528 */
477static int ca0132_playback_pcm_open(struct hda_pcm_stream *hinfo, 1529static int dsp_set_run_state(struct hda_codec *codec)
478 struct hda_codec *codec, 1530{
479 struct snd_pcm_substream *substream) 1531 unsigned int dbg_ctrl_reg;
1532 unsigned int halt_state;
1533 int err;
1534
1535 err = chipio_read(codec, DSP_DBGCNTL_INST_OFFSET, &dbg_ctrl_reg);
1536 if (err < 0)
1537 return err;
1538
1539 halt_state = (dbg_ctrl_reg & DSP_DBGCNTL_STATE_MASK) >>
1540 DSP_DBGCNTL_STATE_LOBIT;
1541
1542 if (halt_state != 0) {
1543 dbg_ctrl_reg &= ~((halt_state << DSP_DBGCNTL_SS_LOBIT) &
1544 DSP_DBGCNTL_SS_MASK);
1545 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
1546 dbg_ctrl_reg);
1547 if (err < 0)
1548 return err;
1549
1550 dbg_ctrl_reg |= (halt_state << DSP_DBGCNTL_EXEC_LOBIT) &
1551 DSP_DBGCNTL_EXEC_MASK;
1552 err = chipio_write(codec, DSP_DBGCNTL_INST_OFFSET,
1553 dbg_ctrl_reg);
1554 if (err < 0)
1555 return err;
1556 }
1557
1558 return 0;
1559}
1560
1561/*
1562 * Reset the DSP
1563 */
1564static int dsp_reset(struct hda_codec *codec)
1565{
1566 unsigned int res;
1567 int retry = 20;
1568
1569 snd_printdd("dsp_reset\n");
1570 do {
1571 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
1572 retry--;
1573 } while (res == -EIO && retry);
1574
1575 if (!retry) {
1576 snd_printdd("dsp_reset timeout\n");
1577 return -EIO;
1578 }
1579
1580 return 0;
1581}
1582
1583/*
1584 * Convert chip address to DSP address
1585 */
1586static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
1587 bool *code, bool *yram)
1588{
1589 *code = *yram = false;
1590
1591 if (UC_RANGE(chip_addx, 1)) {
1592 *code = true;
1593 return UC_OFF(chip_addx);
1594 } else if (X_RANGE_ALL(chip_addx, 1)) {
1595 return X_OFF(chip_addx);
1596 } else if (Y_RANGE_ALL(chip_addx, 1)) {
1597 *yram = true;
1598 return Y_OFF(chip_addx);
1599 }
1600
1601 return INVALID_CHIP_ADDRESS;
1602}
1603
1604/*
1605 * Check if the DSP DMA is active
1606 */
1607static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
1608{
1609 unsigned int dma_chnlstart_reg;
1610
1611 chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, &dma_chnlstart_reg);
1612
1613 return ((dma_chnlstart_reg & (1 <<
1614 (DSPDMAC_CHNLSTART_EN_LOBIT + dma_chan))) != 0);
1615}
1616
1617static int dsp_dma_setup_common(struct hda_codec *codec,
1618 unsigned int chip_addx,
1619 unsigned int dma_chan,
1620 unsigned int port_map_mask,
1621 bool ovly)
1622{
1623 int status = 0;
1624 unsigned int chnl_prop;
1625 unsigned int dsp_addx;
1626 unsigned int active;
1627 bool code, yram;
1628
1629 snd_printdd(KERN_INFO "-- dsp_dma_setup_common() -- Begin ---------\n");
1630
1631 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
1632 snd_printdd(KERN_ERR "dma chan num invalid\n");
1633 return -EINVAL;
1634 }
1635
1636 if (dsp_is_dma_active(codec, dma_chan)) {
1637 snd_printdd(KERN_ERR "dma already active\n");
1638 return -EBUSY;
1639 }
1640
1641 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
1642
1643 if (dsp_addx == INVALID_CHIP_ADDRESS) {
1644 snd_printdd(KERN_ERR "invalid chip addr\n");
1645 return -ENXIO;
1646 }
1647
1648 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
1649 active = 0;
1650
1651 snd_printdd(KERN_INFO " dsp_dma_setup_common() start reg pgm\n");
1652
1653 if (ovly) {
1654 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
1655 &chnl_prop);
1656
1657 if (status < 0) {
1658 snd_printdd(KERN_ERR "read CHNLPROP Reg fail\n");
1659 return status;
1660 }
1661 snd_printdd(KERN_INFO "dsp_dma_setup_common() Read CHNLPROP\n");
1662 }
1663
1664 if (!code)
1665 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
1666 else
1667 chnl_prop |= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT + dma_chan));
1668
1669 chnl_prop &= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT + dma_chan));
1670
1671 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
1672 if (status < 0) {
1673 snd_printdd(KERN_ERR "write CHNLPROP Reg fail\n");
1674 return status;
1675 }
1676 snd_printdd(KERN_INFO " dsp_dma_setup_common() Write CHNLPROP\n");
1677
1678 if (ovly) {
1679 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
1680 &active);
1681
1682 if (status < 0) {
1683 snd_printdd(KERN_ERR "read ACTIVE Reg fail\n");
1684 return status;
1685 }
1686 snd_printdd(KERN_INFO "dsp_dma_setup_common() Read ACTIVE\n");
1687 }
1688
1689 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
1690 DSPDMAC_ACTIVE_AAR_MASK;
1691
1692 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
1693 if (status < 0) {
1694 snd_printdd(KERN_ERR "write ACTIVE Reg fail\n");
1695 return status;
1696 }
1697
1698 snd_printdd(KERN_INFO " dsp_dma_setup_common() Write ACTIVE\n");
1699
1700 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
1701 port_map_mask);
1702 if (status < 0) {
1703 snd_printdd(KERN_ERR "write AUDCHSEL Reg fail\n");
1704 return status;
1705 }
1706 snd_printdd(KERN_INFO " dsp_dma_setup_common() Write AUDCHSEL\n");
1707
1708 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
1709 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
1710 if (status < 0) {
1711 snd_printdd(KERN_ERR "write IRQCNT Reg fail\n");
1712 return status;
1713 }
1714 snd_printdd(KERN_INFO " dsp_dma_setup_common() Write IRQCNT\n");
1715
1716 snd_printdd(
1717 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
1718 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
1719 chip_addx, dsp_addx, dma_chan,
1720 port_map_mask, chnl_prop, active);
1721
1722 snd_printdd(KERN_INFO "-- dsp_dma_setup_common() -- Complete ------\n");
1723
1724 return 0;
1725}
1726
1727/*
1728 * Setup the DSP DMA per-transfer-specific registers
1729 */
1730static int dsp_dma_setup(struct hda_codec *codec,
1731 unsigned int chip_addx,
1732 unsigned int count,
1733 unsigned int dma_chan)
1734{
1735 int status = 0;
1736 bool code, yram;
1737 unsigned int dsp_addx;
1738 unsigned int addr_field;
1739 unsigned int incr_field;
1740 unsigned int base_cnt;
1741 unsigned int cur_cnt;
1742 unsigned int dma_cfg = 0;
1743 unsigned int adr_ofs = 0;
1744 unsigned int xfr_cnt = 0;
1745 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
1746 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
1747
1748 snd_printdd(KERN_INFO "-- dsp_dma_setup() -- Begin ---------\n");
1749
1750 if (count > max_dma_count) {
1751 snd_printdd(KERN_ERR "count too big\n");
1752 return -EINVAL;
1753 }
1754
1755 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
1756 if (dsp_addx == INVALID_CHIP_ADDRESS) {
1757 snd_printdd(KERN_ERR "invalid chip addr\n");
1758 return -ENXIO;
1759 }
1760
1761 snd_printdd(KERN_INFO " dsp_dma_setup() start reg pgm\n");
1762
1763 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
1764 incr_field = 0;
1765
1766 if (!code) {
1767 addr_field <<= 1;
1768 if (yram)
1769 addr_field |= (1 << DSPDMAC_DMACFG_DBADR_LOBIT);
1770
1771 incr_field = (1 << DSPDMAC_DMACFG_AINCR_LOBIT);
1772 }
1773
1774 dma_cfg = addr_field + incr_field;
1775 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
1776 dma_cfg);
1777 if (status < 0) {
1778 snd_printdd(KERN_ERR "write DMACFG Reg fail\n");
1779 return status;
1780 }
1781 snd_printdd(KERN_INFO " dsp_dma_setup() Write DMACFG\n");
1782
1783 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
1784 (code ? 0 : 1));
1785
1786 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
1787 adr_ofs);
1788 if (status < 0) {
1789 snd_printdd(KERN_ERR "write DSPADROFS Reg fail\n");
1790 return status;
1791 }
1792 snd_printdd(KERN_INFO " dsp_dma_setup() Write DSPADROFS\n");
1793
1794 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
1795
1796 cur_cnt = (count - 1) << DSPDMAC_XFRCNT_CCNT_LOBIT;
1797
1798 xfr_cnt = base_cnt | cur_cnt;
1799
1800 status = chipio_write(codec,
1801 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
1802 if (status < 0) {
1803 snd_printdd(KERN_ERR "write XFRCNT Reg fail\n");
1804 return status;
1805 }
1806 snd_printdd(KERN_INFO " dsp_dma_setup() Write XFRCNT\n");
1807
1808 snd_printdd(
1809 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
1810 "ADROFS=0x%x, XFRCNT=0x%x\n",
1811 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
1812
1813 snd_printdd(KERN_INFO "-- dsp_dma_setup() -- Complete ---------\n");
1814
1815 return 0;
1816}
1817
1818/*
1819 * Start the DSP DMA
1820 */
1821static int dsp_dma_start(struct hda_codec *codec,
1822 unsigned int dma_chan, bool ovly)
1823{
1824 unsigned int reg = 0;
1825 int status = 0;
1826
1827 snd_printdd(KERN_INFO "-- dsp_dma_start() -- Begin ---------\n");
1828
1829 if (ovly) {
1830 status = chipio_read(codec,
1831 DSPDMAC_CHNLSTART_INST_OFFSET, &reg);
1832
1833 if (status < 0) {
1834 snd_printdd(KERN_ERR "read CHNLSTART reg fail\n");
1835 return status;
1836 }
1837 snd_printdd(KERN_INFO "-- dsp_dma_start() Read CHNLSTART\n");
1838
1839 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
1840 DSPDMAC_CHNLSTART_DIS_MASK);
1841 }
1842
1843 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
1844 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
1845 if (status < 0) {
1846 snd_printdd(KERN_ERR "write CHNLSTART reg fail\n");
1847 return status;
1848 }
1849 snd_printdd(KERN_INFO "-- dsp_dma_start() -- Complete ---------\n");
1850
1851 return status;
1852}
1853
1854/*
1855 * Stop the DSP DMA
1856 */
1857static int dsp_dma_stop(struct hda_codec *codec,
1858 unsigned int dma_chan, bool ovly)
1859{
1860 unsigned int reg = 0;
1861 int status = 0;
1862
1863 snd_printdd(KERN_INFO "-- dsp_dma_stop() -- Begin ---------\n");
1864
1865 if (ovly) {
1866 status = chipio_read(codec,
1867 DSPDMAC_CHNLSTART_INST_OFFSET, &reg);
1868
1869 if (status < 0) {
1870 snd_printdd(KERN_ERR "read CHNLSTART reg fail\n");
1871 return status;
1872 }
1873 snd_printdd(KERN_INFO "-- dsp_dma_stop() Read CHNLSTART\n");
1874 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
1875 DSPDMAC_CHNLSTART_DIS_MASK);
1876 }
1877
1878 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
1879 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
1880 if (status < 0) {
1881 snd_printdd(KERN_ERR "write CHNLSTART reg fail\n");
1882 return status;
1883 }
1884 snd_printdd(KERN_INFO "-- dsp_dma_stop() -- Complete ---------\n");
1885
1886 return status;
1887}
1888
1889/**
1890 * Allocate router ports
1891 *
1892 * @codec: the HDA codec
1893 * @num_chans: number of channels in the stream
1894 * @ports_per_channel: number of ports per channel
1895 * @start_device: start device
1896 * @port_map: pointer to the port list to hold the allocated ports
1897 *
1898 * Returns zero or a negative error code.
1899 */
1900static int dsp_allocate_router_ports(struct hda_codec *codec,
1901 unsigned int num_chans,
1902 unsigned int ports_per_channel,
1903 unsigned int start_device,
1904 unsigned int *port_map)
1905{
1906 int status = 0;
1907 int res;
1908 u8 val;
1909
1910 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1911 if (status < 0)
1912 return status;
1913
1914 val = start_device << 6;
1915 val |= (ports_per_channel - 1) << 4;
1916 val |= num_chans - 1;
1917
1918 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1919 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET,
1920 val);
1921
1922 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1923 VENDOR_CHIPIO_PORT_ALLOC_SET,
1924 MEM_CONNID_DSP);
1925
1926 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1927 if (status < 0)
1928 return status;
1929
1930 res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0,
1931 VENDOR_CHIPIO_PORT_ALLOC_GET, 0);
1932
1933 *port_map = res;
1934
1935 return (res < 0) ? res : 0;
1936}
1937
1938/*
1939 * Free router ports
1940 */
1941static int dsp_free_router_ports(struct hda_codec *codec)
1942{
1943 int status = 0;
1944
1945 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1946 if (status < 0)
1947 return status;
1948
1949 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
1950 VENDOR_CHIPIO_PORT_FREE_SET,
1951 MEM_CONNID_DSP);
1952
1953 status = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0);
1954
1955 return status;
1956}
1957
1958/*
1959 * Allocate DSP ports for the download stream
1960 */
1961static int dsp_allocate_ports(struct hda_codec *codec,
1962 unsigned int num_chans,
1963 unsigned int rate_multi, unsigned int *port_map)
1964{
1965 int status;
1966
1967 snd_printdd(KERN_INFO " dsp_allocate_ports() -- begin\n");
1968
1969 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
1970 snd_printdd(KERN_ERR "bad rate multiple\n");
1971 return -EINVAL;
1972 }
1973
1974 status = dsp_allocate_router_ports(codec, num_chans,
1975 rate_multi, 0, port_map);
1976
1977 snd_printdd(KERN_INFO " dsp_allocate_ports() -- complete\n");
1978
1979 return status;
1980}
1981
1982static int dsp_allocate_ports_format(struct hda_codec *codec,
1983 const unsigned short fmt,
1984 unsigned int *port_map)
1985{
1986 int status;
1987 unsigned int num_chans;
1988
1989 unsigned int sample_rate_div = ((get_hdafmt_rate(fmt) >> 0) & 3) + 1;
1990 unsigned int sample_rate_mul = ((get_hdafmt_rate(fmt) >> 3) & 3) + 1;
1991 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
1992
1993 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
1994 snd_printdd(KERN_ERR "bad rate multiple\n");
1995 return -EINVAL;
1996 }
1997
1998 num_chans = get_hdafmt_chs(fmt) + 1;
1999
2000 status = dsp_allocate_ports(codec, num_chans, rate_multi, port_map);
2001
2002 return status;
2003}
2004
2005/*
2006 * free DSP ports
2007 */
2008static int dsp_free_ports(struct hda_codec *codec)
2009{
2010 int status;
2011
2012 snd_printdd(KERN_INFO " dsp_free_ports() -- begin\n");
2013
2014 status = dsp_free_router_ports(codec);
2015 if (status < 0) {
2016 snd_printdd(KERN_ERR "free router ports fail\n");
2017 return status;
2018 }
2019 snd_printdd(KERN_INFO " dsp_free_ports() -- complete\n");
2020
2021 return status;
2022}
2023
2024/*
2025 * HDA DMA engine stuffs for DSP code download
2026 */
2027struct dma_engine {
2028 struct hda_codec *codec;
2029 unsigned short m_converter_format;
2030 struct snd_dma_buffer *dmab;
2031 unsigned int buf_size;
2032};
2033
2034
2035enum dma_state {
2036 DMA_STATE_STOP = 0,
2037 DMA_STATE_RUN = 1
2038};
2039
2040static int dma_convert_to_hda_format(
2041 unsigned int sample_rate,
2042 unsigned short channels,
2043 unsigned short *hda_format)
2044{
2045 unsigned int format_val;
2046
2047 format_val = snd_hda_calc_stream_format(
2048 sample_rate,
2049 channels,
2050 SNDRV_PCM_FORMAT_S32_LE,
2051 32, 0);
2052
2053 if (hda_format)
2054 *hda_format = (unsigned short)format_val;
2055
2056 return 0;
2057}
2058
2059/*
2060 * Reset DMA for DSP download
2061 */
2062static int dma_reset(struct dma_engine *dma)
2063{
2064 struct hda_codec *codec = dma->codec;
2065 struct ca0132_spec *spec = codec->spec;
2066 int status;
2067
2068 if (dma->dmab->area)
2069 snd_hda_codec_load_dsp_cleanup(codec, dma->dmab);
2070
2071 status = snd_hda_codec_load_dsp_prepare(codec,
2072 dma->m_converter_format,
2073 dma->buf_size,
2074 dma->dmab);
2075 if (status < 0)
2076 return status;
2077 spec->dsp_stream_id = status;
2078 return 0;
2079}
2080
2081static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2082{
2083 bool cmd;
2084
2085 snd_printdd("dma_set_state state=%d\n", state);
2086
2087 switch (state) {
2088 case DMA_STATE_STOP:
2089 cmd = false;
2090 break;
2091 case DMA_STATE_RUN:
2092 cmd = true;
2093 break;
2094 default:
2095 return 0;
2096 }
2097
2098 snd_hda_codec_load_dsp_trigger(dma->codec, cmd);
2099 return 0;
2100}
2101
2102static unsigned int dma_get_buffer_size(struct dma_engine *dma)
2103{
2104 return dma->dmab->bytes;
2105}
2106
2107static unsigned char *dma_get_buffer_addr(struct dma_engine *dma)
2108{
2109 return dma->dmab->area;
2110}
2111
2112static int dma_xfer(struct dma_engine *dma,
2113 const unsigned int *data,
2114 unsigned int count)
2115{
2116 memcpy(dma->dmab->area, data, count);
2117 return 0;
2118}
2119
2120static void dma_get_converter_format(
2121 struct dma_engine *dma,
2122 unsigned short *format)
2123{
2124 if (format)
2125 *format = dma->m_converter_format;
2126}
2127
2128static unsigned int dma_get_stream_id(struct dma_engine *dma)
2129{
2130 struct ca0132_spec *spec = dma->codec->spec;
2131
2132 return spec->dsp_stream_id;
2133}
2134
2135struct dsp_image_seg {
2136 u32 magic;
2137 u32 chip_addr;
2138 u32 count;
2139 u32 data[0];
2140};
2141
2142static const u32 g_magic_value = 0x4c46584d;
2143static const u32 g_chip_addr_magic_value = 0xFFFFFF01;
2144
2145static bool is_valid(const struct dsp_image_seg *p)
2146{
2147 return p->magic == g_magic_value;
2148}
2149
2150static bool is_hci_prog_list_seg(const struct dsp_image_seg *p)
2151{
2152 return g_chip_addr_magic_value == p->chip_addr;
2153}
2154
2155static bool is_last(const struct dsp_image_seg *p)
2156{
2157 return p->count == 0;
2158}
2159
2160static size_t dsp_sizeof(const struct dsp_image_seg *p)
2161{
2162 return sizeof(*p) + p->count*sizeof(u32);
2163}
2164
2165static const struct dsp_image_seg *get_next_seg_ptr(
2166 const struct dsp_image_seg *p)
2167{
2168 return (struct dsp_image_seg *)((unsigned char *)(p) + dsp_sizeof(p));
2169}
2170
2171/*
2172 * CA0132 chip DSP transfer stuffs. For DSP download.
2173 */
2174#define INVALID_DMA_CHANNEL (~0U)
2175
2176/*
2177 * Program a list of address/data pairs via the ChipIO widget.
2178 * The segment data is in the format of successive pairs of words.
2179 * These are repeated as indicated by the segment's count field.
2180 */
2181static int dspxfr_hci_write(struct hda_codec *codec,
2182 const struct dsp_image_seg *fls)
2183{
2184 int status;
2185 const u32 *data;
2186 unsigned int count;
2187
2188 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
2189 snd_printdd(KERN_ERR "hci_write invalid params\n");
2190 return -EINVAL;
2191 }
2192
2193 count = fls->count;
2194 data = (u32 *)(fls->data);
2195 while (count >= 2) {
2196 status = chipio_write(codec, data[0], data[1]);
2197 if (status < 0) {
2198 snd_printdd(KERN_ERR "hci_write chipio failed\n");
2199 return status;
2200 }
2201 count -= 2;
2202 data += 2;
2203 }
2204 return 0;
2205}
2206
2207/**
2208 * Write a block of data into DSP code or data RAM using pre-allocated
2209 * DMA engine.
2210 *
2211 * @codec: the HDA codec
2212 * @fls: pointer to a fast load image
2213 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2214 * no relocation
2215 * @dma_engine: pointer to DMA engine to be used for DSP download
2216 * @dma_chan: The number of DMA channels used for DSP download
2217 * @port_map_mask: port mapping
2218 * @ovly: TRUE if overlay format is required
2219 *
2220 * Returns zero or a negative error code.
2221 */
2222static int dspxfr_one_seg(struct hda_codec *codec,
2223 const struct dsp_image_seg *fls,
2224 unsigned int reloc,
2225 struct dma_engine *dma_engine,
2226 unsigned int dma_chan,
2227 unsigned int port_map_mask,
2228 bool ovly)
2229{
2230 int status = 0;
2231 bool comm_dma_setup_done = false;
2232 const unsigned int *data;
2233 unsigned int chip_addx;
2234 unsigned int words_to_write;
2235 unsigned int buffer_size_words;
2236 unsigned char *buffer_addx;
2237 unsigned short hda_format;
2238 unsigned int sample_rate_div;
2239 unsigned int sample_rate_mul;
2240 unsigned int num_chans;
2241 unsigned int hda_frame_size_words;
2242 unsigned int remainder_words;
2243 const u32 *data_remainder;
2244 u32 chip_addx_remainder;
2245 unsigned int run_size_words;
2246 const struct dsp_image_seg *hci_write = NULL;
2247 unsigned long timeout;
2248 bool dma_active;
2249
2250 if (fls == NULL)
2251 return -EINVAL;
2252 if (is_hci_prog_list_seg(fls)) {
2253 hci_write = fls;
2254 fls = get_next_seg_ptr(fls);
2255 }
2256
2257 if (hci_write && (!fls || is_last(fls))) {
2258 snd_printdd("hci_write\n");
2259 return dspxfr_hci_write(codec, hci_write);
2260 }
2261
2262 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
2263 snd_printdd("Invalid Params\n");
2264 return -EINVAL;
2265 }
2266
2267 data = fls->data;
2268 chip_addx = fls->chip_addr,
2269 words_to_write = fls->count;
2270
2271 if (!words_to_write)
2272 return hci_write ? dspxfr_hci_write(codec, hci_write) : 0;
2273 if (reloc)
2274 chip_addx = (chip_addx & (0xFFFF0000 << 2)) + (reloc << 2);
2275
2276 if (!UC_RANGE(chip_addx, words_to_write) &&
2277 !X_RANGE_ALL(chip_addx, words_to_write) &&
2278 !Y_RANGE_ALL(chip_addx, words_to_write)) {
2279 snd_printdd("Invalid chip_addx Params\n");
2280 return -EINVAL;
2281 }
2282
2283 buffer_size_words = (unsigned int)dma_get_buffer_size(dma_engine) /
2284 sizeof(u32);
2285
2286 buffer_addx = dma_get_buffer_addr(dma_engine);
2287
2288 if (buffer_addx == NULL) {
2289 snd_printdd(KERN_ERR "dma_engine buffer NULL\n");
2290 return -EINVAL;
2291 }
2292
2293 dma_get_converter_format(dma_engine, &hda_format);
2294 sample_rate_div = ((get_hdafmt_rate(hda_format) >> 0) & 3) + 1;
2295 sample_rate_mul = ((get_hdafmt_rate(hda_format) >> 3) & 3) + 1;
2296 num_chans = get_hdafmt_chs(hda_format) + 1;
2297
2298 hda_frame_size_words = ((sample_rate_div == 0) ? 0 :
2299 (num_chans * sample_rate_mul / sample_rate_div));
2300
2301 buffer_size_words = min(buffer_size_words,
2302 (unsigned int)(UC_RANGE(chip_addx, 1) ?
2303 65536 : 32768));
2304 buffer_size_words -= buffer_size_words % hda_frame_size_words;
2305 snd_printdd(
2306 "chpadr=0x%08x frmsz=%u nchan=%u "
2307 "rate_mul=%u div=%u bufsz=%u\n",
2308 chip_addx, hda_frame_size_words, num_chans,
2309 sample_rate_mul, sample_rate_div, buffer_size_words);
2310
2311 if ((buffer_addx == NULL) || (hda_frame_size_words == 0) ||
2312 (buffer_size_words < hda_frame_size_words)) {
2313 snd_printdd(KERN_ERR "dspxfr_one_seg:failed\n");
2314 return -EINVAL;
2315 }
2316
2317 remainder_words = words_to_write % hda_frame_size_words;
2318 data_remainder = data;
2319 chip_addx_remainder = chip_addx;
2320
2321 data += remainder_words;
2322 chip_addx += remainder_words*sizeof(u32);
2323 words_to_write -= remainder_words;
2324
2325 while (words_to_write != 0) {
2326 run_size_words = min(buffer_size_words, words_to_write);
2327 snd_printdd("dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2328 words_to_write, run_size_words, remainder_words);
2329 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
2330 if (!comm_dma_setup_done) {
2331 status = dsp_dma_stop(codec, dma_chan, ovly);
2332 if (status < 0)
2333 return status;
2334 status = dsp_dma_setup_common(codec, chip_addx,
2335 dma_chan, port_map_mask, ovly);
2336 if (status < 0)
2337 return status;
2338 comm_dma_setup_done = true;
2339 }
2340
2341 status = dsp_dma_setup(codec, chip_addx,
2342 run_size_words, dma_chan);
2343 if (status < 0)
2344 return status;
2345 status = dsp_dma_start(codec, dma_chan, ovly);
2346 if (status < 0)
2347 return status;
2348 if (!dsp_is_dma_active(codec, dma_chan)) {
2349 snd_printdd(KERN_ERR "dspxfr:DMA did not start\n");
2350 return -EIO;
2351 }
2352 status = dma_set_state(dma_engine, DMA_STATE_RUN);
2353 if (status < 0)
2354 return status;
2355 if (remainder_words != 0) {
2356 status = chipio_write_multiple(codec,
2357 chip_addx_remainder,
2358 data_remainder,
2359 remainder_words);
2360 if (status < 0)
2361 return status;
2362 remainder_words = 0;
2363 }
2364 if (hci_write) {
2365 status = dspxfr_hci_write(codec, hci_write);
2366 if (status < 0)
2367 return status;
2368 hci_write = NULL;
2369 }
2370
2371 timeout = jiffies + msecs_to_jiffies(2000);
2372 do {
2373 dma_active = dsp_is_dma_active(codec, dma_chan);
2374 if (!dma_active)
2375 break;
2376 msleep(20);
2377 } while (time_before(jiffies, timeout));
2378 if (dma_active)
2379 break;
2380
2381 snd_printdd(KERN_INFO "+++++ DMA complete\n");
2382 dma_set_state(dma_engine, DMA_STATE_STOP);
2383 status = dma_reset(dma_engine);
2384
2385 if (status < 0)
2386 return status;
2387
2388 data += run_size_words;
2389 chip_addx += run_size_words*sizeof(u32);
2390 words_to_write -= run_size_words;
2391 }
2392
2393 if (remainder_words != 0) {
2394 status = chipio_write_multiple(codec, chip_addx_remainder,
2395 data_remainder, remainder_words);
2396 }
2397
2398 return status;
2399}
2400
2401/**
2402 * Write the entire DSP image of a DSP code/data overlay to DSP memories
2403 *
2404 * @codec: the HDA codec
2405 * @fls_data: pointer to a fast load image
2406 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2407 * no relocation
2408 * @sample_rate: sampling rate of the stream used for DSP download
2409 * @number_channels: channels of the stream used for DSP download
2410 * @ovly: TRUE if overlay format is required
2411 *
2412 * Returns zero or a negative error code.
2413 */
2414static int dspxfr_image(struct hda_codec *codec,
2415 const struct dsp_image_seg *fls_data,
2416 unsigned int reloc,
2417 unsigned int sample_rate,
2418 unsigned short channels,
2419 bool ovly)
480{ 2420{
481 struct ca0132_spec *spec = codec->spec; 2421 struct ca0132_spec *spec = codec->spec;
482 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 2422 int status;
483 hinfo); 2423 unsigned short hda_format = 0;
2424 unsigned int response;
2425 unsigned char stream_id = 0;
2426 struct dma_engine *dma_engine;
2427 unsigned int dma_chan;
2428 unsigned int port_map_mask;
2429
2430 if (fls_data == NULL)
2431 return -EINVAL;
2432
2433 dma_engine = kzalloc(sizeof(*dma_engine), GFP_KERNEL);
2434 if (!dma_engine)
2435 return -ENOMEM;
2436
2437 dma_engine->dmab = kzalloc(sizeof(*dma_engine->dmab), GFP_KERNEL);
2438 if (!dma_engine->dmab) {
2439 kfree(dma_engine);
2440 return -ENOMEM;
2441 }
2442
2443 dma_engine->codec = codec;
2444 dma_convert_to_hda_format(sample_rate, channels, &hda_format);
2445 dma_engine->m_converter_format = hda_format;
2446 dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY :
2447 DSP_DMA_WRITE_BUFLEN_INIT) * 2;
2448
2449 dma_chan = ovly ? INVALID_DMA_CHANNEL : 0;
2450
2451 status = codec_set_converter_format(codec, WIDGET_CHIP_CTRL,
2452 hda_format, &response);
2453
2454 if (status < 0) {
2455 snd_printdd(KERN_ERR "set converter format fail\n");
2456 goto exit;
2457 }
2458
2459 status = snd_hda_codec_load_dsp_prepare(codec,
2460 dma_engine->m_converter_format,
2461 dma_engine->buf_size,
2462 dma_engine->dmab);
2463 if (status < 0)
2464 goto exit;
2465 spec->dsp_stream_id = status;
2466
2467 if (ovly) {
2468 status = dspio_alloc_dma_chan(codec, &dma_chan);
2469 if (status < 0) {
2470 snd_printdd(KERN_ERR "alloc dmachan fail\n");
2471 dma_chan = INVALID_DMA_CHANNEL;
2472 goto exit;
2473 }
2474 }
2475
2476 port_map_mask = 0;
2477 status = dsp_allocate_ports_format(codec, hda_format,
2478 &port_map_mask);
2479 if (status < 0) {
2480 snd_printdd(KERN_ERR "alloc ports fail\n");
2481 goto exit;
2482 }
2483
2484 stream_id = dma_get_stream_id(dma_engine);
2485 status = codec_set_converter_stream_channel(codec,
2486 WIDGET_CHIP_CTRL, stream_id, 0, &response);
2487 if (status < 0) {
2488 snd_printdd(KERN_ERR "set stream chan fail\n");
2489 goto exit;
2490 }
2491
2492 while ((fls_data != NULL) && !is_last(fls_data)) {
2493 if (!is_valid(fls_data)) {
2494 snd_printdd(KERN_ERR "FLS check fail\n");
2495 status = -EINVAL;
2496 goto exit;
2497 }
2498 status = dspxfr_one_seg(codec, fls_data, reloc,
2499 dma_engine, dma_chan,
2500 port_map_mask, ovly);
2501 if (status < 0)
2502 break;
2503
2504 if (is_hci_prog_list_seg(fls_data))
2505 fls_data = get_next_seg_ptr(fls_data);
2506
2507 if ((fls_data != NULL) && !is_last(fls_data))
2508 fls_data = get_next_seg_ptr(fls_data);
2509 }
2510
2511 if (port_map_mask != 0)
2512 status = dsp_free_ports(codec);
2513
2514 if (status < 0)
2515 goto exit;
2516
2517 status = codec_set_converter_stream_channel(codec,
2518 WIDGET_CHIP_CTRL, 0, 0, &response);
2519
2520exit:
2521 if (ovly && (dma_chan != INVALID_DMA_CHANNEL))
2522 dspio_free_dma_chan(codec, dma_chan);
2523
2524 if (dma_engine->dmab->area)
2525 snd_hda_codec_load_dsp_cleanup(codec, dma_engine->dmab);
2526 kfree(dma_engine->dmab);
2527 kfree(dma_engine);
2528
2529 return status;
2530}
2531
2532/*
2533 * CA0132 DSP download stuffs.
2534 */
2535static void dspload_post_setup(struct hda_codec *codec)
2536{
2537 snd_printdd(KERN_INFO "---- dspload_post_setup ------\n");
2538
2539 /*set DSP speaker to 2.0 configuration*/
2540 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
2541 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
2542
2543 /*update write pointer*/
2544 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
2545}
2546
2547/**
2548 * Download DSP from a DSP Image Fast Load structure. This structure is a
2549 * linear, non-constant sized element array of structures, each of which
2550 * contain the count of the data to be loaded, the data itself, and the
2551 * corresponding starting chip address of the starting data location.
2552 *
2553 * @codec: the HDA codec
2554 * @fls: pointer to a fast load image
2555 * @ovly: TRUE if overlay format is required
2556 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2557 * no relocation
2558 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
2559 * @router_chans: number of audio router channels to be allocated (0 means use
2560 * internal defaults; max is 32)
2561 *
2562 * Returns zero or a negative error code.
2563 */
2564static int dspload_image(struct hda_codec *codec,
2565 const struct dsp_image_seg *fls,
2566 bool ovly,
2567 unsigned int reloc,
2568 bool autostart,
2569 int router_chans)
2570{
2571 int status = 0;
2572 unsigned int sample_rate;
2573 unsigned short channels;
2574
2575 snd_printdd(KERN_INFO "---- dspload_image begin ------\n");
2576 if (router_chans == 0) {
2577 if (!ovly)
2578 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
2579 else
2580 router_chans = DMA_OVERLAY_FRAME_SIZE_NWORDS;
2581 }
2582
2583 sample_rate = 48000;
2584 channels = (unsigned short)router_chans;
2585
2586 while (channels > 16) {
2587 sample_rate *= 2;
2588 channels /= 2;
2589 }
2590
2591 do {
2592 snd_printdd(KERN_INFO "Ready to program DMA\n");
2593 if (!ovly)
2594 status = dsp_reset(codec);
2595
2596 if (status < 0)
2597 break;
2598
2599 snd_printdd(KERN_INFO "dsp_reset() complete\n");
2600 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
2601 ovly);
2602
2603 if (status < 0)
2604 break;
2605
2606 snd_printdd(KERN_INFO "dspxfr_image() complete\n");
2607 if (autostart && !ovly) {
2608 dspload_post_setup(codec);
2609 status = dsp_set_run_state(codec);
2610 }
2611
2612 snd_printdd(KERN_INFO "LOAD FINISHED\n");
2613 } while (0);
2614
2615 return status;
484} 2616}
485 2617
2618#ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
2619static bool dspload_is_loaded(struct hda_codec *codec)
2620{
2621 unsigned int data = 0;
2622 int status = 0;
2623
2624 status = chipio_read(codec, 0x40004, &data);
2625 if ((status < 0) || (data != 1))
2626 return false;
2627
2628 return true;
2629}
2630#else
2631#define dspload_is_loaded(codec) false
2632#endif
2633
2634static bool dspload_wait_loaded(struct hda_codec *codec)
2635{
2636 unsigned long timeout = jiffies + msecs_to_jiffies(2000);
2637
2638 do {
2639 if (dspload_is_loaded(codec)) {
2640 pr_info("ca0132 DOWNLOAD OK :-) DSP IS RUNNING.\n");
2641 return true;
2642 }
2643 msleep(20);
2644 } while (time_before(jiffies, timeout));
2645
2646 pr_err("ca0132 DOWNLOAD FAILED!!! DSP IS NOT RUNNING.\n");
2647 return false;
2648}
2649
2650/*
2651 * PCM stuffs
2652 */
2653static void ca0132_setup_stream(struct hda_codec *codec, hda_nid_t nid,
2654 u32 stream_tag,
2655 int channel_id, int format)
2656{
2657 unsigned int oldval, newval;
2658
2659 if (!nid)
2660 return;
2661
2662 snd_printdd(
2663 "ca0132_setup_stream: NID=0x%x, stream=0x%x, "
2664 "channel=%d, format=0x%x\n",
2665 nid, stream_tag, channel_id, format);
2666
2667 /* update the format-id if changed */
2668 oldval = snd_hda_codec_read(codec, nid, 0,
2669 AC_VERB_GET_STREAM_FORMAT,
2670 0);
2671 if (oldval != format) {
2672 msleep(20);
2673 snd_hda_codec_write(codec, nid, 0,
2674 AC_VERB_SET_STREAM_FORMAT,
2675 format);
2676 }
2677
2678 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
2679 newval = (stream_tag << 4) | channel_id;
2680 if (oldval != newval) {
2681 snd_hda_codec_write(codec, nid, 0,
2682 AC_VERB_SET_CHANNEL_STREAMID,
2683 newval);
2684 }
2685}
2686
2687static void ca0132_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
2688{
2689 unsigned int val;
2690
2691 if (!nid)
2692 return;
2693
2694 snd_printdd(KERN_INFO "ca0132_cleanup_stream: NID=0x%x\n", nid);
2695
2696 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
2697 if (!val)
2698 return;
2699
2700 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
2701 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
2702}
2703
2704/*
2705 * PCM callbacks
2706 */
486static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2707static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
487 struct hda_codec *codec, 2708 struct hda_codec *codec,
488 unsigned int stream_tag, 2709 unsigned int stream_tag,
@@ -490,8 +2711,10 @@ static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
490 struct snd_pcm_substream *substream) 2711 struct snd_pcm_substream *substream)
491{ 2712{
492 struct ca0132_spec *spec = codec->spec; 2713 struct ca0132_spec *spec = codec->spec;
493 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 2714
494 stream_tag, format, substream); 2715 ca0132_setup_stream(codec, spec->dacs[0], stream_tag, 0, format);
2716
2717 return 0;
495} 2718}
496 2719
497static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 2720static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
@@ -499,7 +2722,18 @@ static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
499 struct snd_pcm_substream *substream) 2722 struct snd_pcm_substream *substream)
500{ 2723{
501 struct ca0132_spec *spec = codec->spec; 2724 struct ca0132_spec *spec = codec->spec;
502 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 2725
2726 if (spec->dsp_state == DSP_DOWNLOADING)
2727 return 0;
2728
2729 /*If Playback effects are on, allow stream some time to flush
2730 *effects tail*/
2731 if (spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
2732 msleep(50);
2733
2734 ca0132_cleanup_stream(codec, spec->dacs[0]);
2735
2736 return 0;
503} 2737}
504 2738
505/* 2739/*
@@ -541,308 +2775,1189 @@ static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
541} 2775}
542 2776
543/* 2777/*
2778 * Analog capture
544 */ 2779 */
545static struct hda_pcm_stream ca0132_pcm_analog_playback = { 2780static int ca0132_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
546 .substreams = 1, 2781 struct hda_codec *codec,
547 .channels_min = 2, 2782 unsigned int stream_tag,
548 .channels_max = 2, 2783 unsigned int format,
549 .ops = { 2784 struct snd_pcm_substream *substream)
550 .open = ca0132_playback_pcm_open, 2785{
551 .prepare = ca0132_playback_pcm_prepare, 2786 struct ca0132_spec *spec = codec->spec;
552 .cleanup = ca0132_playback_pcm_cleanup
553 },
554};
555 2787
556static struct hda_pcm_stream ca0132_pcm_analog_capture = { 2788 ca0132_setup_stream(codec, spec->adcs[substream->number],
557 .substreams = 1, 2789 stream_tag, 0, format);
558 .channels_min = 2, 2790
559 .channels_max = 2, 2791 return 0;
2792}
2793
2794static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2795 struct hda_codec *codec,
2796 struct snd_pcm_substream *substream)
2797{
2798 struct ca0132_spec *spec = codec->spec;
2799
2800 if (spec->dsp_state == DSP_DOWNLOADING)
2801 return 0;
2802
2803 ca0132_cleanup_stream(codec, hinfo->nid);
2804 return 0;
2805}
2806
2807/*
2808 * Controls stuffs.
2809 */
2810
2811/*
2812 * Mixer controls helpers.
2813 */
2814#define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
2815 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2816 .name = xname, \
2817 .subdevice = HDA_SUBDEV_AMP_FLAG, \
2818 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2819 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2820 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2821 .info = ca0132_volume_info, \
2822 .get = ca0132_volume_get, \
2823 .put = ca0132_volume_put, \
2824 .tlv = { .c = ca0132_volume_tlv }, \
2825 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
2826
2827#define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
2828 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2829 .name = xname, \
2830 .subdevice = HDA_SUBDEV_AMP_FLAG, \
2831 .info = snd_hda_mixer_amp_switch_info, \
2832 .get = ca0132_switch_get, \
2833 .put = ca0132_switch_put, \
2834 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
2835
2836/* stereo */
2837#define CA0132_CODEC_VOL(xname, nid, dir) \
2838 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
2839#define CA0132_CODEC_MUTE(xname, nid, dir) \
2840 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
2841
2842/* The followings are for tuning of products */
2843#ifdef ENABLE_TUNING_CONTROLS
2844
2845static unsigned int voice_focus_vals_lookup[] = {
28460x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
28470x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
28480x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
28490x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
28500x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
28510x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
28520x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
28530x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
28540x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
28550x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
28560x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
28570x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
28580x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
28590x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
28600x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
28610x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
28620x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
28630x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
28640x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
28650x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
28660x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
28670x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
28680x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
28690x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
28700x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
28710x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
28720x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
560}; 2873};
561 2874
562static struct hda_pcm_stream ca0132_pcm_digital_playback = { 2875static unsigned int mic_svm_vals_lookup[] = {
563 .substreams = 1, 28760x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
564 .channels_min = 2, 28770x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
565 .channels_max = 2, 28780x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
566 .ops = { 28790x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
567 .open = ca0132_dig_playback_pcm_open, 28800x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
568 .close = ca0132_dig_playback_pcm_close, 28810x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
569 .prepare = ca0132_dig_playback_pcm_prepare, 28820x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
570 .cleanup = ca0132_dig_playback_pcm_cleanup 28830x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
571 }, 28840x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
28850x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
28860x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
28870x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
28880x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
28890x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
28900x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
28910x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
28920x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
572}; 2893};
573 2894
574static struct hda_pcm_stream ca0132_pcm_digital_capture = { 2895static unsigned int equalizer_vals_lookup[] = {
575 .substreams = 1, 28960xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
576 .channels_min = 2, 28970xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
577 .channels_max = 2, 28980xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
28990xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
29000x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
29010x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
29020x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
29030x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
29040x41C00000
578}; 2905};
579 2906
580static int ca0132_build_pcms(struct hda_codec *codec) 2907static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid,
2908 unsigned int *lookup, int idx)
581{ 2909{
582 struct ca0132_spec *spec = codec->spec; 2910 int i = 0;
583 struct hda_pcm *info = spec->pcm_rec;
584 2911
585 codec->pcm_info = info; 2912 for (i = 0; i < TUNING_CTLS_COUNT; i++)
586 codec->num_pcms = 0; 2913 if (nid == ca0132_tuning_ctls[i].nid)
2914 break;
587 2915
588 info->name = "CA0132 Analog"; 2916 snd_hda_power_up(codec);
589 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback; 2917 dspio_set_param(codec, ca0132_tuning_ctls[i].mid,
590 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0]; 2918 ca0132_tuning_ctls[i].req,
591 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 2919 &(lookup[idx]), sizeof(unsigned int));
592 spec->multiout.max_channels; 2920 snd_hda_power_down(codec);
593 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
594 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_inputs;
595 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
596 codec->num_pcms++;
597 2921
598 if (!spec->dig_out && !spec->dig_in) 2922 return 1;
599 return 0; 2923}
600 2924
601 info++; 2925static int tuning_ctl_get(struct snd_kcontrol *kcontrol,
602 info->name = "CA0132 Digital"; 2926 struct snd_ctl_elem_value *ucontrol)
603 info->pcm_type = HDA_PCM_TYPE_SPDIF; 2927{
604 if (spec->dig_out) { 2928 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 2929 struct ca0132_spec *spec = codec->spec;
606 ca0132_pcm_digital_playback; 2930 hda_nid_t nid = get_amp_nid(kcontrol);
607 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out; 2931 long *valp = ucontrol->value.integer.value;
608 } 2932 int idx = nid - TUNING_CTL_START_NID;
609 if (spec->dig_in) {
610 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
611 ca0132_pcm_digital_capture;
612 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
613 }
614 codec->num_pcms++;
615 2933
2934 *valp = spec->cur_ctl_vals[idx];
616 return 0; 2935 return 0;
617} 2936}
618 2937
619#define REG_CODEC_MUTE 0x18b014 2938static int voice_focus_ctl_info(struct snd_kcontrol *kcontrol,
620#define REG_CODEC_HP_VOL_L 0x18b070 2939 struct snd_ctl_elem_info *uinfo)
621#define REG_CODEC_HP_VOL_R 0x18b074 2940{
2941 int chs = get_amp_channels(kcontrol);
2942 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2943 uinfo->count = chs == 3 ? 2 : 1;
2944 uinfo->value.integer.min = 20;
2945 uinfo->value.integer.max = 180;
2946 uinfo->value.integer.step = 1;
2947
2948 return 0;
2949}
622 2950
623static int ca0132_hp_switch_get(struct snd_kcontrol *kcontrol, 2951static int voice_focus_ctl_put(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_value *ucontrol) 2952 struct snd_ctl_elem_value *ucontrol)
625{ 2953{
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2954 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct ca0132_spec *spec = codec->spec; 2955 struct ca0132_spec *spec = codec->spec;
2956 hda_nid_t nid = get_amp_nid(kcontrol);
628 long *valp = ucontrol->value.integer.value; 2957 long *valp = ucontrol->value.integer.value;
2958 int idx;
2959
2960 idx = nid - TUNING_CTL_START_NID;
2961 /* any change? */
2962 if (spec->cur_ctl_vals[idx] == *valp)
2963 return 0;
2964
2965 spec->cur_ctl_vals[idx] = *valp;
2966
2967 idx = *valp - 20;
2968 tuning_ctl_set(codec, nid, voice_focus_vals_lookup, idx);
2969
2970 return 1;
2971}
2972
2973static int mic_svm_ctl_info(struct snd_kcontrol *kcontrol,
2974 struct snd_ctl_elem_info *uinfo)
2975{
2976 int chs = get_amp_channels(kcontrol);
2977 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2978 uinfo->count = chs == 3 ? 2 : 1;
2979 uinfo->value.integer.min = 0;
2980 uinfo->value.integer.max = 100;
2981 uinfo->value.integer.step = 1;
629 2982
630 *valp = spec->curr_hp_switch;
631 return 0; 2983 return 0;
632} 2984}
633 2985
634static int ca0132_hp_switch_put(struct snd_kcontrol *kcontrol, 2986static int mic_svm_ctl_put(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol) 2987 struct snd_ctl_elem_value *ucontrol)
636{ 2988{
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2989 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct ca0132_spec *spec = codec->spec; 2990 struct ca0132_spec *spec = codec->spec;
2991 hda_nid_t nid = get_amp_nid(kcontrol);
639 long *valp = ucontrol->value.integer.value; 2992 long *valp = ucontrol->value.integer.value;
640 unsigned int data; 2993 int idx;
641 int err;
642 2994
2995 idx = nid - TUNING_CTL_START_NID;
643 /* any change? */ 2996 /* any change? */
644 if (spec->curr_hp_switch == *valp) 2997 if (spec->cur_ctl_vals[idx] == *valp)
645 return 0; 2998 return 0;
646 2999
647 snd_hda_power_up(codec); 3000 spec->cur_ctl_vals[idx] = *valp;
648 3001
649 err = chipio_read(codec, REG_CODEC_MUTE, &data); 3002 idx = *valp;
650 if (err < 0) 3003 tuning_ctl_set(codec, nid, mic_svm_vals_lookup, idx);
651 goto exit;
652 3004
653 /* *valp 0 is mute, 1 is unmute */ 3005 return 0;
654 data = (data & 0x7f) | (*valp ? 0 : 0x80); 3006}
655 err = chipio_write(codec, REG_CODEC_MUTE, data);
656 if (err < 0)
657 goto exit;
658 3007
659 spec->curr_hp_switch = *valp; 3008static int equalizer_ctl_info(struct snd_kcontrol *kcontrol,
3009 struct snd_ctl_elem_info *uinfo)
3010{
3011 int chs = get_amp_channels(kcontrol);
3012 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3013 uinfo->count = chs == 3 ? 2 : 1;
3014 uinfo->value.integer.min = 0;
3015 uinfo->value.integer.max = 48;
3016 uinfo->value.integer.step = 1;
660 3017
661 exit: 3018 return 0;
662 snd_hda_power_down(codec);
663 return err < 0 ? err : 1;
664} 3019}
665 3020
666static int ca0132_speaker_switch_get(struct snd_kcontrol *kcontrol, 3021static int equalizer_ctl_put(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol) 3022 struct snd_ctl_elem_value *ucontrol)
668{ 3023{
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3024 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct ca0132_spec *spec = codec->spec; 3025 struct ca0132_spec *spec = codec->spec;
3026 hda_nid_t nid = get_amp_nid(kcontrol);
671 long *valp = ucontrol->value.integer.value; 3027 long *valp = ucontrol->value.integer.value;
3028 int idx;
3029
3030 idx = nid - TUNING_CTL_START_NID;
3031 /* any change? */
3032 if (spec->cur_ctl_vals[idx] == *valp)
3033 return 0;
3034
3035 spec->cur_ctl_vals[idx] = *valp;
3036
3037 idx = *valp;
3038 tuning_ctl_set(codec, nid, equalizer_vals_lookup, idx);
3039
3040 return 1;
3041}
3042
3043static const DECLARE_TLV_DB_SCALE(voice_focus_db_scale, 2000, 100, 0);
3044static const DECLARE_TLV_DB_SCALE(eq_db_scale, -2400, 100, 0);
3045
3046static int add_tuning_control(struct hda_codec *codec,
3047 hda_nid_t pnid, hda_nid_t nid,
3048 const char *name, int dir)
3049{
3050 char namestr[44];
3051 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3052 struct snd_kcontrol_new knew =
3053 HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type);
3054
3055 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3056 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
3057 knew.tlv.c = 0;
3058 knew.tlv.p = 0;
3059 switch (pnid) {
3060 case VOICE_FOCUS:
3061 knew.info = voice_focus_ctl_info;
3062 knew.get = tuning_ctl_get;
3063 knew.put = voice_focus_ctl_put;
3064 knew.tlv.p = voice_focus_db_scale;
3065 break;
3066 case MIC_SVM:
3067 knew.info = mic_svm_ctl_info;
3068 knew.get = tuning_ctl_get;
3069 knew.put = mic_svm_ctl_put;
3070 break;
3071 case EQUALIZER:
3072 knew.info = equalizer_ctl_info;
3073 knew.get = tuning_ctl_get;
3074 knew.put = equalizer_ctl_put;
3075 knew.tlv.p = eq_db_scale;
3076 break;
3077 default:
3078 return 0;
3079 }
3080 knew.private_value =
3081 HDA_COMPOSE_AMP_VAL(nid, 1, 0, type);
3082 sprintf(namestr, "%s %s Volume", name, dirstr[dir]);
3083 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
3084}
3085
3086static int add_tuning_ctls(struct hda_codec *codec)
3087{
3088 int i;
3089 int err;
3090
3091 for (i = 0; i < TUNING_CTLS_COUNT; i++) {
3092 err = add_tuning_control(codec,
3093 ca0132_tuning_ctls[i].parent_nid,
3094 ca0132_tuning_ctls[i].nid,
3095 ca0132_tuning_ctls[i].name,
3096 ca0132_tuning_ctls[i].direct);
3097 if (err < 0)
3098 return err;
3099 }
672 3100
673 *valp = spec->curr_speaker_switch;
674 return 0; 3101 return 0;
675} 3102}
676 3103
677static int ca0132_speaker_switch_put(struct snd_kcontrol *kcontrol, 3104static void ca0132_init_tuning_defaults(struct hda_codec *codec)
678 struct snd_ctl_elem_value *ucontrol)
679{ 3105{
680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
681 struct ca0132_spec *spec = codec->spec; 3106 struct ca0132_spec *spec = codec->spec;
682 long *valp = ucontrol->value.integer.value; 3107 int i;
683 unsigned int data; 3108
3109 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
3110 spec->cur_ctl_vals[WEDGE_ANGLE - TUNING_CTL_START_NID] = 10;
3111 /* SVM level defaults to 0.74. */
3112 spec->cur_ctl_vals[SVM_LEVEL - TUNING_CTL_START_NID] = 74;
3113
3114 /* EQ defaults to 0dB. */
3115 for (i = 2; i < TUNING_CTLS_COUNT; i++)
3116 spec->cur_ctl_vals[i] = 24;
3117}
3118#endif /*ENABLE_TUNING_CONTROLS*/
3119
3120/*
3121 * Select the active output.
3122 * If autodetect is enabled, output will be selected based on jack detection.
3123 * If jack inserted, headphone will be selected, else built-in speakers
3124 * If autodetect is disabled, output will be selected based on selection.
3125 */
3126static int ca0132_select_out(struct hda_codec *codec)
3127{
3128 struct ca0132_spec *spec = codec->spec;
3129 unsigned int pin_ctl;
3130 int jack_present;
3131 int auto_jack;
3132 unsigned int tmp;
684 int err; 3133 int err;
685 3134
686 /* any change? */ 3135 snd_printdd(KERN_INFO "ca0132_select_out\n");
687 if (spec->curr_speaker_switch == *valp) 3136
3137 snd_hda_power_up(codec);
3138
3139 auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
3140
3141 if (auto_jack)
3142 jack_present = snd_hda_jack_detect(codec, spec->out_pins[1]);
3143 else
3144 jack_present =
3145 spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID];
3146
3147 if (jack_present)
3148 spec->cur_out_type = HEADPHONE_OUT;
3149 else
3150 spec->cur_out_type = SPEAKER_OUT;
3151
3152 if (spec->cur_out_type == SPEAKER_OUT) {
3153 snd_printdd(KERN_INFO "ca0132_select_out speaker\n");
3154 /*speaker out config*/
3155 tmp = FLOAT_ONE;
3156 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
3157 if (err < 0)
3158 goto exit;
3159 /*enable speaker EQ*/
3160 tmp = FLOAT_ONE;
3161 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
3162 if (err < 0)
3163 goto exit;
3164
3165 /* Setup EAPD */
3166 snd_hda_codec_write(codec, spec->out_pins[1], 0,
3167 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
3168 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3169 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
3170 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3171 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
3172 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3173 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3174
3175 /* disable headphone node */
3176 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
3177 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3178 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
3179 pin_ctl & ~PIN_HP);
3180 /* enable speaker node */
3181 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
3182 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3183 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
3184 pin_ctl | PIN_OUT);
3185 } else {
3186 snd_printdd(KERN_INFO "ca0132_select_out hp\n");
3187 /*headphone out config*/
3188 tmp = FLOAT_ZERO;
3189 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
3190 if (err < 0)
3191 goto exit;
3192 /*disable speaker EQ*/
3193 tmp = FLOAT_ZERO;
3194 err = dspio_set_uint_param(codec, 0x8f, 0x00, tmp);
3195 if (err < 0)
3196 goto exit;
3197
3198 /* Setup EAPD */
3199 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3200 VENDOR_CHIPIO_EAPD_SEL_SET, 0x00);
3201 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3202 AC_VERB_SET_EAPD_BTLENABLE, 0x00);
3203 snd_hda_codec_write(codec, spec->out_pins[1], 0,
3204 VENDOR_CHIPIO_EAPD_SEL_SET, 0x02);
3205 snd_hda_codec_write(codec, spec->out_pins[0], 0,
3206 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3207
3208 /* disable speaker*/
3209 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[0], 0,
3210 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3211 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
3212 pin_ctl & ~PIN_HP);
3213 /* enable headphone*/
3214 pin_ctl = snd_hda_codec_read(codec, spec->out_pins[1], 0,
3215 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3216 snd_hda_set_pin_ctl(codec, spec->out_pins[1],
3217 pin_ctl | PIN_HP);
3218 }
3219
3220exit:
3221 snd_hda_power_down(codec);
3222
3223 return err < 0 ? err : 0;
3224}
3225
3226static void ca0132_set_dmic(struct hda_codec *codec, int enable);
3227static int ca0132_mic_boost_set(struct hda_codec *codec, long val);
3228static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val);
3229
3230/*
3231 * Select the active VIP source
3232 */
3233static int ca0132_set_vipsource(struct hda_codec *codec, int val)
3234{
3235 struct ca0132_spec *spec = codec->spec;
3236 unsigned int tmp;
3237
3238 if (!dspload_is_loaded(codec))
688 return 0; 3239 return 0;
689 3240
3241 /* if CrystalVoice if off, vipsource should be 0 */
3242 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ||
3243 (val == 0)) {
3244 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, 0);
3245 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
3246 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
3247 if (spec->cur_mic_type == DIGITAL_MIC)
3248 tmp = FLOAT_TWO;
3249 else
3250 tmp = FLOAT_ONE;
3251 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
3252 tmp = FLOAT_ZERO;
3253 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
3254 } else {
3255 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_16_000);
3256 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_16_000);
3257 if (spec->cur_mic_type == DIGITAL_MIC)
3258 tmp = FLOAT_TWO;
3259 else
3260 tmp = FLOAT_ONE;
3261 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
3262 tmp = FLOAT_ONE;
3263 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
3264 msleep(20);
3265 chipio_set_control_param(codec, CONTROL_PARAM_VIP_SOURCE, val);
3266 }
3267
3268 return 1;
3269}
3270
3271/*
3272 * Select the active microphone.
3273 * If autodetect is enabled, mic will be selected based on jack detection.
3274 * If jack inserted, ext.mic will be selected, else built-in mic
3275 * If autodetect is disabled, mic will be selected based on selection.
3276 */
3277static int ca0132_select_mic(struct hda_codec *codec)
3278{
3279 struct ca0132_spec *spec = codec->spec;
3280 int jack_present;
3281 int auto_jack;
3282
3283 snd_printdd(KERN_INFO "ca0132_select_mic\n");
3284
690 snd_hda_power_up(codec); 3285 snd_hda_power_up(codec);
691 3286
692 err = chipio_read(codec, REG_CODEC_MUTE, &data); 3287 auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
693 if (err < 0) 3288
694 goto exit; 3289 if (auto_jack)
3290 jack_present = snd_hda_jack_detect(codec, spec->input_pins[0]);
3291 else
3292 jack_present =
3293 spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID];
3294
3295 if (jack_present)
3296 spec->cur_mic_type = LINE_MIC_IN;
3297 else
3298 spec->cur_mic_type = DIGITAL_MIC;
3299
3300 if (spec->cur_mic_type == DIGITAL_MIC) {
3301 /* enable digital Mic */
3302 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_32_000);
3303 ca0132_set_dmic(codec, 1);
3304 ca0132_mic_boost_set(codec, 0);
3305 /* set voice focus */
3306 ca0132_effects_set(codec, VOICE_FOCUS,
3307 spec->effects_switch
3308 [VOICE_FOCUS - EFFECT_START_NID]);
3309 } else {
3310 /* disable digital Mic */
3311 chipio_set_conn_rate(codec, MEM_CONNID_DMIC, SR_96_000);
3312 ca0132_set_dmic(codec, 0);
3313 ca0132_mic_boost_set(codec, spec->cur_mic_boost);
3314 /* disable voice focus */
3315 ca0132_effects_set(codec, VOICE_FOCUS, 0);
3316 }
3317
3318 snd_hda_power_down(codec);
3319
3320 return 0;
3321}
3322
3323/*
3324 * Check if VNODE settings take effect immediately.
3325 */
3326static bool ca0132_is_vnode_effective(struct hda_codec *codec,
3327 hda_nid_t vnid,
3328 hda_nid_t *shared_nid)
3329{
3330 struct ca0132_spec *spec = codec->spec;
3331 hda_nid_t nid;
3332
3333 switch (vnid) {
3334 case VNID_SPK:
3335 nid = spec->shared_out_nid;
3336 break;
3337 case VNID_MIC:
3338 nid = spec->shared_mic_nid;
3339 break;
3340 default:
3341 return false;
3342 }
3343
3344 if (shared_nid)
3345 *shared_nid = nid;
3346
3347 return true;
3348}
3349
3350/*
3351* The following functions are control change helpers.
3352* They return 0 if no changed. Return 1 if changed.
3353*/
3354static int ca0132_voicefx_set(struct hda_codec *codec, int enable)
3355{
3356 struct ca0132_spec *spec = codec->spec;
3357 unsigned int tmp;
3358
3359 /* based on CrystalVoice state to enable VoiceFX. */
3360 if (enable) {
3361 tmp = spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] ?
3362 FLOAT_ONE : FLOAT_ZERO;
3363 } else {
3364 tmp = FLOAT_ZERO;
3365 }
3366
3367 dspio_set_uint_param(codec, ca0132_voicefx.mid,
3368 ca0132_voicefx.reqs[0], tmp);
3369
3370 return 1;
3371}
3372
3373/*
3374 * Set the effects parameters
3375 */
3376static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
3377{
3378 struct ca0132_spec *spec = codec->spec;
3379 unsigned int on;
3380 int num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
3381 int err = 0;
3382 int idx = nid - EFFECT_START_NID;
3383
3384 if ((idx < 0) || (idx >= num_fx))
3385 return 0; /* no changed */
3386
3387 /* for out effect, qualify with PE */
3388 if ((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) {
3389 /* if PE if off, turn off out effects. */
3390 if (!spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID])
3391 val = 0;
3392 }
3393
3394 /* for in effect, qualify with CrystalVoice */
3395 if ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID)) {
3396 /* if CrystalVoice if off, turn off in effects. */
3397 if (!spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID])
3398 val = 0;
3399
3400 /* Voice Focus applies to 2-ch Mic, Digital Mic */
3401 if ((nid == VOICE_FOCUS) && (spec->cur_mic_type != DIGITAL_MIC))
3402 val = 0;
3403 }
3404
3405 snd_printdd(KERN_INFO "ca0132_effect_set: nid=0x%x, val=%ld\n",
3406 nid, val);
3407
3408 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
3409 err = dspio_set_uint_param(codec, ca0132_effects[idx].mid,
3410 ca0132_effects[idx].reqs[0], on);
695 3411
696 /* *valp 0 is mute, 1 is unmute */
697 data = (data & 0xef) | (*valp ? 0 : 0x10);
698 err = chipio_write(codec, REG_CODEC_MUTE, data);
699 if (err < 0) 3412 if (err < 0)
700 goto exit; 3413 return 0; /* no changed */
701 3414
702 spec->curr_speaker_switch = *valp; 3415 return 1;
3416}
703 3417
704 exit: 3418/*
705 snd_hda_power_down(codec); 3419 * Turn on/off Playback Enhancements
706 return err < 0 ? err : 1; 3420 */
3421static int ca0132_pe_switch_set(struct hda_codec *codec)
3422{
3423 struct ca0132_spec *spec = codec->spec;
3424 hda_nid_t nid;
3425 int i, ret = 0;
3426
3427 snd_printdd(KERN_INFO "ca0132_pe_switch_set: val=%ld\n",
3428 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
3429
3430 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
3431 nid = OUT_EFFECT_START_NID;
3432 /* PE affects all out effects */
3433 for (; nid < OUT_EFFECT_END_NID; nid++, i++)
3434 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
3435
3436 return ret;
3437}
3438
3439/* Check if Mic1 is streaming, if so, stop streaming */
3440static int stop_mic1(struct hda_codec *codec)
3441{
3442 struct ca0132_spec *spec = codec->spec;
3443 unsigned int oldval = snd_hda_codec_read(codec, spec->adcs[0], 0,
3444 AC_VERB_GET_CONV, 0);
3445 if (oldval != 0)
3446 snd_hda_codec_write(codec, spec->adcs[0], 0,
3447 AC_VERB_SET_CHANNEL_STREAMID,
3448 0);
3449 return oldval;
3450}
3451
3452/* Resume Mic1 streaming if it was stopped. */
3453static void resume_mic1(struct hda_codec *codec, unsigned int oldval)
3454{
3455 struct ca0132_spec *spec = codec->spec;
3456 /* Restore the previous stream and channel */
3457 if (oldval != 0)
3458 snd_hda_codec_write(codec, spec->adcs[0], 0,
3459 AC_VERB_SET_CHANNEL_STREAMID,
3460 oldval);
3461}
3462
3463/*
3464 * Turn on/off CrystalVoice
3465 */
3466static int ca0132_cvoice_switch_set(struct hda_codec *codec)
3467{
3468 struct ca0132_spec *spec = codec->spec;
3469 hda_nid_t nid;
3470 int i, ret = 0;
3471 unsigned int oldval;
3472
3473 snd_printdd(KERN_INFO "ca0132_cvoice_switch_set: val=%ld\n",
3474 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
3475
3476 i = IN_EFFECT_START_NID - EFFECT_START_NID;
3477 nid = IN_EFFECT_START_NID;
3478 /* CrystalVoice affects all in effects */
3479 for (; nid < IN_EFFECT_END_NID; nid++, i++)
3480 ret |= ca0132_effects_set(codec, nid, spec->effects_switch[i]);
3481
3482 /* including VoiceFX */
3483 ret |= ca0132_voicefx_set(codec, (spec->voicefx_val ? 1 : 0));
3484
3485 /* set correct vipsource */
3486 oldval = stop_mic1(codec);
3487 ret |= ca0132_set_vipsource(codec, 1);
3488 resume_mic1(codec, oldval);
3489 return ret;
707} 3490}
708 3491
709static int ca0132_hp_volume_get(struct snd_kcontrol *kcontrol, 3492static int ca0132_mic_boost_set(struct hda_codec *codec, long val)
3493{
3494 struct ca0132_spec *spec = codec->spec;
3495 int ret = 0;
3496
3497 if (val) /* on */
3498 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
3499 HDA_INPUT, 0, HDA_AMP_VOLMASK, 3);
3500 else /* off */
3501 ret = snd_hda_codec_amp_update(codec, spec->input_pins[0], 0,
3502 HDA_INPUT, 0, HDA_AMP_VOLMASK, 0);
3503
3504 return ret;
3505}
3506
3507static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
710 struct snd_ctl_elem_value *ucontrol) 3508 struct snd_ctl_elem_value *ucontrol)
711{ 3509{
712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3511 hda_nid_t nid = get_amp_nid(kcontrol);
3512 hda_nid_t shared_nid = 0;
3513 bool effective;
3514 int ret = 0;
713 struct ca0132_spec *spec = codec->spec; 3515 struct ca0132_spec *spec = codec->spec;
714 long *valp = ucontrol->value.integer.value; 3516 int auto_jack;
3517
3518 if (nid == VNID_HP_SEL) {
3519 auto_jack =
3520 spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID];
3521 if (!auto_jack)
3522 ca0132_select_out(codec);
3523 return 1;
3524 }
3525
3526 if (nid == VNID_AMIC1_SEL) {
3527 auto_jack =
3528 spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID];
3529 if (!auto_jack)
3530 ca0132_select_mic(codec);
3531 return 1;
3532 }
3533
3534 if (nid == VNID_HP_ASEL) {
3535 ca0132_select_out(codec);
3536 return 1;
3537 }
3538
3539 if (nid == VNID_AMIC1_ASEL) {
3540 ca0132_select_mic(codec);
3541 return 1;
3542 }
3543
3544 /* if effective conditions, then update hw immediately. */
3545 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
3546 if (effective) {
3547 int dir = get_amp_direction(kcontrol);
3548 int ch = get_amp_channels(kcontrol);
3549 unsigned long pval;
3550
3551 mutex_lock(&codec->control_mutex);
3552 pval = kcontrol->private_value;
3553 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
3554 0, dir);
3555 ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3556 kcontrol->private_value = pval;
3557 mutex_unlock(&codec->control_mutex);
3558 }
3559
3560 return ret;
3561}
3562/* End of control change helpers. */
3563
3564static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
3565 struct snd_ctl_elem_info *uinfo)
3566{
3567 unsigned int items = sizeof(ca0132_voicefx_presets)
3568 / sizeof(struct ct_voicefx_preset);
3569
3570 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3571 uinfo->count = 1;
3572 uinfo->value.enumerated.items = items;
3573 if (uinfo->value.enumerated.item >= items)
3574 uinfo->value.enumerated.item = items - 1;
3575 strcpy(uinfo->value.enumerated.name,
3576 ca0132_voicefx_presets[uinfo->value.enumerated.item].name);
3577 return 0;
3578}
715 3579
716 *valp++ = spec->curr_hp_volume[0]; 3580static int ca0132_voicefx_get(struct snd_kcontrol *kcontrol,
717 *valp = spec->curr_hp_volume[1]; 3581 struct snd_ctl_elem_value *ucontrol)
3582{
3583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3584 struct ca0132_spec *spec = codec->spec;
3585
3586 ucontrol->value.enumerated.item[0] = spec->voicefx_val;
718 return 0; 3587 return 0;
719} 3588}
720 3589
721static int ca0132_hp_volume_put(struct snd_kcontrol *kcontrol, 3590static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
3591 struct snd_ctl_elem_value *ucontrol)
3592{
3593 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3594 struct ca0132_spec *spec = codec->spec;
3595 int i, err = 0;
3596 int sel = ucontrol->value.enumerated.item[0];
3597 unsigned int items = sizeof(ca0132_voicefx_presets)
3598 / sizeof(struct ct_voicefx_preset);
3599
3600 if (sel >= items)
3601 return 0;
3602
3603 snd_printdd(KERN_INFO "ca0132_voicefx_put: sel=%d, preset=%s\n",
3604 sel, ca0132_voicefx_presets[sel].name);
3605
3606 /*
3607 * Idx 0 is default.
3608 * Default needs to qualify with CrystalVoice state.
3609 */
3610 for (i = 0; i < VOICEFX_MAX_PARAM_COUNT; i++) {
3611 err = dspio_set_uint_param(codec, ca0132_voicefx.mid,
3612 ca0132_voicefx.reqs[i],
3613 ca0132_voicefx_presets[sel].vals[i]);
3614 if (err < 0)
3615 break;
3616 }
3617
3618 if (err >= 0) {
3619 spec->voicefx_val = sel;
3620 /* enable voice fx */
3621 ca0132_voicefx_set(codec, (sel ? 1 : 0));
3622 }
3623
3624 return 1;
3625}
3626
3627static int ca0132_switch_get(struct snd_kcontrol *kcontrol,
722 struct snd_ctl_elem_value *ucontrol) 3628 struct snd_ctl_elem_value *ucontrol)
723{ 3629{
724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3630 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
725 struct ca0132_spec *spec = codec->spec; 3631 struct ca0132_spec *spec = codec->spec;
3632 hda_nid_t nid = get_amp_nid(kcontrol);
3633 int ch = get_amp_channels(kcontrol);
726 long *valp = ucontrol->value.integer.value; 3634 long *valp = ucontrol->value.integer.value;
727 long left_vol, right_vol;
728 unsigned int data;
729 int val;
730 int err;
731 3635
732 left_vol = *valp++; 3636 /* vnode */
733 right_vol = *valp; 3637 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
3638 if (ch & 1) {
3639 *valp = spec->vnode_lswitch[nid - VNODE_START_NID];
3640 valp++;
3641 }
3642 if (ch & 2) {
3643 *valp = spec->vnode_rswitch[nid - VNODE_START_NID];
3644 valp++;
3645 }
3646 return 0;
3647 }
734 3648
735 /* any change? */ 3649 /* effects, include PE and CrystalVoice */
736 if ((spec->curr_hp_volume[0] == left_vol) && 3650 if ((nid >= EFFECT_START_NID) && (nid < EFFECT_END_NID)) {
737 (spec->curr_hp_volume[1] == right_vol)) 3651 *valp = spec->effects_switch[nid - EFFECT_START_NID];
738 return 0; 3652 return 0;
3653 }
3654
3655 /* mic boost */
3656 if (nid == spec->input_pins[0]) {
3657 *valp = spec->cur_mic_boost;
3658 return 0;
3659 }
3660
3661 return 0;
3662}
3663
3664static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
3665 struct snd_ctl_elem_value *ucontrol)
3666{
3667 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3668 struct ca0132_spec *spec = codec->spec;
3669 hda_nid_t nid = get_amp_nid(kcontrol);
3670 int ch = get_amp_channels(kcontrol);
3671 long *valp = ucontrol->value.integer.value;
3672 int changed = 1;
3673
3674 snd_printdd(KERN_INFO "ca0132_switch_put: nid=0x%x, val=%ld\n",
3675 nid, *valp);
739 3676
740 snd_hda_power_up(codec); 3677 snd_hda_power_up(codec);
3678 /* vnode */
3679 if ((nid >= VNODE_START_NID) && (nid < VNODE_END_NID)) {
3680 if (ch & 1) {
3681 spec->vnode_lswitch[nid - VNODE_START_NID] = *valp;
3682 valp++;
3683 }
3684 if (ch & 2) {
3685 spec->vnode_rswitch[nid - VNODE_START_NID] = *valp;
3686 valp++;
3687 }
3688 changed = ca0132_vnode_switch_set(kcontrol, ucontrol);
3689 goto exit;
3690 }
741 3691
742 err = chipio_read(codec, REG_CODEC_HP_VOL_L, &data); 3692 /* PE */
743 if (err < 0) 3693 if (nid == PLAY_ENHANCEMENT) {
3694 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
3695 changed = ca0132_pe_switch_set(codec);
744 goto exit; 3696 goto exit;
3697 }
745 3698
746 val = 31 - left_vol; 3699 /* CrystalVoice */
747 data = (data & 0xe0) | val; 3700 if (nid == CRYSTAL_VOICE) {
748 err = chipio_write(codec, REG_CODEC_HP_VOL_L, data); 3701 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
749 if (err < 0) 3702 changed = ca0132_cvoice_switch_set(codec);
750 goto exit; 3703 goto exit;
3704 }
751 3705
752 val = 31 - right_vol; 3706 /* out and in effects */
753 data = (data & 0xe0) | val; 3707 if (((nid >= OUT_EFFECT_START_NID) && (nid < OUT_EFFECT_END_NID)) ||
754 err = chipio_write(codec, REG_CODEC_HP_VOL_R, data); 3708 ((nid >= IN_EFFECT_START_NID) && (nid < IN_EFFECT_END_NID))) {
755 if (err < 0) 3709 spec->effects_switch[nid - EFFECT_START_NID] = *valp;
3710 changed = ca0132_effects_set(codec, nid, *valp);
756 goto exit; 3711 goto exit;
3712 }
3713
3714 /* mic boost */
3715 if (nid == spec->input_pins[0]) {
3716 spec->cur_mic_boost = *valp;
757 3717
758 spec->curr_hp_volume[0] = left_vol; 3718 /* Mic boost does not apply to Digital Mic */
759 spec->curr_hp_volume[1] = right_vol; 3719 if (spec->cur_mic_type != DIGITAL_MIC)
3720 changed = ca0132_mic_boost_set(codec, *valp);
3721 goto exit;
3722 }
760 3723
761 exit: 3724exit:
762 snd_hda_power_down(codec); 3725 snd_hda_power_down(codec);
763 return err < 0 ? err : 1; 3726 return changed;
764} 3727}
765 3728
766static int add_hp_switch(struct hda_codec *codec, hda_nid_t nid) 3729/*
3730 * Volume related
3731 */
3732static int ca0132_volume_info(struct snd_kcontrol *kcontrol,
3733 struct snd_ctl_elem_info *uinfo)
767{ 3734{
768 struct snd_kcontrol_new knew = 3735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
769 HDA_CODEC_MUTE_MONO("Headphone Playback Switch", 3736 struct ca0132_spec *spec = codec->spec;
770 nid, 1, 0, HDA_OUTPUT); 3737 hda_nid_t nid = get_amp_nid(kcontrol);
771 knew.get = ca0132_hp_switch_get; 3738 int ch = get_amp_channels(kcontrol);
772 knew.put = ca0132_hp_switch_put; 3739 int dir = get_amp_direction(kcontrol);
773 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); 3740 unsigned long pval;
3741 int err;
3742
3743 switch (nid) {
3744 case VNID_SPK:
3745 /* follow shared_out info */
3746 nid = spec->shared_out_nid;
3747 mutex_lock(&codec->control_mutex);
3748 pval = kcontrol->private_value;
3749 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
3750 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
3751 kcontrol->private_value = pval;
3752 mutex_unlock(&codec->control_mutex);
3753 break;
3754 case VNID_MIC:
3755 /* follow shared_mic info */
3756 nid = spec->shared_mic_nid;
3757 mutex_lock(&codec->control_mutex);
3758 pval = kcontrol->private_value;
3759 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
3760 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
3761 kcontrol->private_value = pval;
3762 mutex_unlock(&codec->control_mutex);
3763 break;
3764 default:
3765 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
3766 }
3767 return err;
774} 3768}
775 3769
776static int add_hp_volume(struct hda_codec *codec, hda_nid_t nid) 3770static int ca0132_volume_get(struct snd_kcontrol *kcontrol,
3771 struct snd_ctl_elem_value *ucontrol)
777{ 3772{
778 struct snd_kcontrol_new knew = 3773 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
779 HDA_CODEC_VOLUME_MONO("Headphone Playback Volume", 3774 struct ca0132_spec *spec = codec->spec;
780 nid, 3, 0, HDA_OUTPUT); 3775 hda_nid_t nid = get_amp_nid(kcontrol);
781 knew.get = ca0132_hp_volume_get; 3776 int ch = get_amp_channels(kcontrol);
782 knew.put = ca0132_hp_volume_put; 3777 long *valp = ucontrol->value.integer.value;
783 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); 3778
3779 /* store the left and right volume */
3780 if (ch & 1) {
3781 *valp = spec->vnode_lvol[nid - VNODE_START_NID];
3782 valp++;
3783 }
3784 if (ch & 2) {
3785 *valp = spec->vnode_rvol[nid - VNODE_START_NID];
3786 valp++;
3787 }
3788 return 0;
784} 3789}
785 3790
786static int add_speaker_switch(struct hda_codec *codec, hda_nid_t nid) 3791static int ca0132_volume_put(struct snd_kcontrol *kcontrol,
3792 struct snd_ctl_elem_value *ucontrol)
787{ 3793{
788 struct snd_kcontrol_new knew = 3794 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
789 HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 3795 struct ca0132_spec *spec = codec->spec;
790 nid, 1, 0, HDA_OUTPUT); 3796 hda_nid_t nid = get_amp_nid(kcontrol);
791 knew.get = ca0132_speaker_switch_get; 3797 int ch = get_amp_channels(kcontrol);
792 knew.put = ca0132_speaker_switch_put; 3798 long *valp = ucontrol->value.integer.value;
793 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); 3799 hda_nid_t shared_nid = 0;
3800 bool effective;
3801 int changed = 1;
3802
3803 /* store the left and right volume */
3804 if (ch & 1) {
3805 spec->vnode_lvol[nid - VNODE_START_NID] = *valp;
3806 valp++;
3807 }
3808 if (ch & 2) {
3809 spec->vnode_rvol[nid - VNODE_START_NID] = *valp;
3810 valp++;
3811 }
3812
3813 /* if effective conditions, then update hw immediately. */
3814 effective = ca0132_is_vnode_effective(codec, nid, &shared_nid);
3815 if (effective) {
3816 int dir = get_amp_direction(kcontrol);
3817 unsigned long pval;
3818
3819 snd_hda_power_up(codec);
3820 mutex_lock(&codec->control_mutex);
3821 pval = kcontrol->private_value;
3822 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(shared_nid, ch,
3823 0, dir);
3824 changed = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
3825 kcontrol->private_value = pval;
3826 mutex_unlock(&codec->control_mutex);
3827 snd_hda_power_down(codec);
3828 }
3829
3830 return changed;
794} 3831}
795 3832
796static void ca0132_fix_hp_caps(struct hda_codec *codec) 3833static int ca0132_volume_tlv(struct snd_kcontrol *kcontrol, int op_flag,
3834 unsigned int size, unsigned int __user *tlv)
797{ 3835{
3836 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct ca0132_spec *spec = codec->spec; 3837 struct ca0132_spec *spec = codec->spec;
799 struct auto_pin_cfg *cfg = &spec->autocfg; 3838 hda_nid_t nid = get_amp_nid(kcontrol);
800 unsigned int caps; 3839 int ch = get_amp_channels(kcontrol);
3840 int dir = get_amp_direction(kcontrol);
3841 unsigned long pval;
3842 int err;
3843
3844 switch (nid) {
3845 case VNID_SPK:
3846 /* follow shared_out tlv */
3847 nid = spec->shared_out_nid;
3848 mutex_lock(&codec->control_mutex);
3849 pval = kcontrol->private_value;
3850 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
3851 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
3852 kcontrol->private_value = pval;
3853 mutex_unlock(&codec->control_mutex);
3854 break;
3855 case VNID_MIC:
3856 /* follow shared_mic tlv */
3857 nid = spec->shared_mic_nid;
3858 mutex_lock(&codec->control_mutex);
3859 pval = kcontrol->private_value;
3860 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(nid, ch, 0, dir);
3861 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
3862 kcontrol->private_value = pval;
3863 mutex_unlock(&codec->control_mutex);
3864 break;
3865 default:
3866 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
3867 }
3868 return err;
3869}
3870
3871static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid,
3872 const char *pfx, int dir)
3873{
3874 char namestr[44];
3875 int type = dir ? HDA_INPUT : HDA_OUTPUT;
3876 struct snd_kcontrol_new knew =
3877 CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type);
3878 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
3879 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
3880}
801 3881
802 /* set mute-capable, 1db step, 32 steps, ofs 6 */ 3882static int add_voicefx(struct hda_codec *codec)
803 caps = 0x80031f06; 3883{
804 snd_hda_override_amp_caps(codec, cfg->hp_pins[0], HDA_OUTPUT, caps); 3884 struct snd_kcontrol_new knew =
3885 HDA_CODEC_MUTE_MONO(ca0132_voicefx.name,
3886 VOICEFX, 1, 0, HDA_INPUT);
3887 knew.info = ca0132_voicefx_info;
3888 knew.get = ca0132_voicefx_get;
3889 knew.put = ca0132_voicefx_put;
3890 return snd_hda_ctl_add(codec, VOICEFX, snd_ctl_new1(&knew, codec));
805} 3891}
806 3892
3893/*
3894 * When changing Node IDs for Mixer Controls below, make sure to update
3895 * Node IDs in ca0132_config() as well.
3896 */
3897static struct snd_kcontrol_new ca0132_mixer[] = {
3898 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK, HDA_OUTPUT),
3899 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK, HDA_OUTPUT),
3900 CA0132_CODEC_VOL("Capture Volume", VNID_MIC, HDA_INPUT),
3901 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC, HDA_INPUT),
3902 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT),
3903 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT),
3904 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT),
3905 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT),
3906 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
3907 0x12, 1, HDA_INPUT),
3908 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
3909 VNID_HP_SEL, 1, HDA_OUTPUT),
3910 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
3911 VNID_AMIC1_SEL, 1, HDA_INPUT),
3912 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
3913 VNID_HP_ASEL, 1, HDA_OUTPUT),
3914 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
3915 VNID_AMIC1_ASEL, 1, HDA_INPUT),
3916 { } /* end */
3917};
3918
807static int ca0132_build_controls(struct hda_codec *codec) 3919static int ca0132_build_controls(struct hda_codec *codec)
808{ 3920{
809 struct ca0132_spec *spec = codec->spec; 3921 struct ca0132_spec *spec = codec->spec;
810 struct auto_pin_cfg *cfg = &spec->autocfg; 3922 int i, num_fx;
811 int i, err; 3923 int err = 0;
812 3924
813 if (spec->multiout.num_dacs) { 3925 /* Add Mixer controls */
814 err = add_speaker_switch(codec, spec->out_pins[0]); 3926 for (i = 0; i < spec->num_mixers; i++) {
3927 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
815 if (err < 0) 3928 if (err < 0)
816 return err; 3929 return err;
817 } 3930 }
818 3931
819 if (cfg->hp_outs) { 3932 /* Add in and out effects controls.
820 ca0132_fix_hp_caps(codec); 3933 * VoiceFX, PE and CrystalVoice are added separately.
821 err = add_hp_switch(codec, cfg->hp_pins[0]); 3934 */
822 if (err < 0) 3935 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
823 return err; 3936 for (i = 0; i < num_fx; i++) {
824 err = add_hp_volume(codec, cfg->hp_pins[0]); 3937 err = add_fx_switch(codec, ca0132_effects[i].nid,
3938 ca0132_effects[i].name,
3939 ca0132_effects[i].direct);
825 if (err < 0) 3940 if (err < 0)
826 return err; 3941 return err;
827 } 3942 }
828 3943
829 for (i = 0; i < spec->num_inputs; i++) { 3944 err = add_fx_switch(codec, PLAY_ENHANCEMENT, "PlayEnhancement", 0);
830 const char *label = spec->input_labels[i]; 3945 if (err < 0)
3946 return err;
831 3947
832 err = add_in_switch(codec, spec->adcs[i], label); 3948 err = add_fx_switch(codec, CRYSTAL_VOICE, "CrystalVoice", 1);
833 if (err < 0) 3949 if (err < 0)
834 return err; 3950 return err;
835 err = add_in_volume(codec, spec->adcs[i], label); 3951
836 if (err < 0) 3952 add_voicefx(codec);
837 return err; 3953
838 if (cfg->inputs[i].type == AUTO_PIN_MIC) { 3954#ifdef ENABLE_TUNING_CONTROLS
839 /* add Mic-Boost */ 3955 add_tuning_ctls(codec);
840 err = add_in_mono_volume(codec, spec->input_pins[i], 3956#endif
841 "Mic Boost", 1); 3957
842 if (err < 0) 3958 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
843 return err; 3959 if (err < 0)
844 } 3960 return err;
845 }
846 3961
847 if (spec->dig_out) { 3962 if (spec->dig_out) {
848 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out, 3963 err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out,
@@ -863,83 +3978,559 @@ static int ca0132_build_controls(struct hda_codec *codec)
863 return 0; 3978 return 0;
864} 3979}
865 3980
3981/*
3982 * PCM
3983 */
3984static struct hda_pcm_stream ca0132_pcm_analog_playback = {
3985 .substreams = 1,
3986 .channels_min = 2,
3987 .channels_max = 6,
3988 .ops = {
3989 .prepare = ca0132_playback_pcm_prepare,
3990 .cleanup = ca0132_playback_pcm_cleanup
3991 },
3992};
3993
3994static struct hda_pcm_stream ca0132_pcm_analog_capture = {
3995 .substreams = 1,
3996 .channels_min = 2,
3997 .channels_max = 2,
3998 .ops = {
3999 .prepare = ca0132_capture_pcm_prepare,
4000 .cleanup = ca0132_capture_pcm_cleanup
4001 },
4002};
4003
4004static struct hda_pcm_stream ca0132_pcm_digital_playback = {
4005 .substreams = 1,
4006 .channels_min = 2,
4007 .channels_max = 2,
4008 .ops = {
4009 .open = ca0132_dig_playback_pcm_open,
4010 .close = ca0132_dig_playback_pcm_close,
4011 .prepare = ca0132_dig_playback_pcm_prepare,
4012 .cleanup = ca0132_dig_playback_pcm_cleanup
4013 },
4014};
866 4015
867static void ca0132_set_ct_ext(struct hda_codec *codec, int enable) 4016static struct hda_pcm_stream ca0132_pcm_digital_capture = {
4017 .substreams = 1,
4018 .channels_min = 2,
4019 .channels_max = 2,
4020};
4021
4022static int ca0132_build_pcms(struct hda_codec *codec)
868{ 4023{
869 /* Set Creative extension */ 4024 struct ca0132_spec *spec = codec->spec;
870 snd_printdd("SET CREATIVE EXTENSION\n"); 4025 struct hda_pcm *info = spec->pcm_rec;
871 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, 4026
872 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 4027 codec->pcm_info = info;
873 enable); 4028 codec->num_pcms = 0;
874 msleep(20); 4029
4030 info->name = "CA0132 Analog";
4031 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback;
4032 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0];
4033 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
4034 spec->multiout.max_channels;
4035 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4036 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4037 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0];
4038 codec->num_pcms++;
4039
4040 info++;
4041 info->name = "CA0132 Analog Mic-In2";
4042 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4043 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4044 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1];
4045 codec->num_pcms++;
4046
4047 info++;
4048 info->name = "CA0132 What U Hear";
4049 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture;
4050 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1;
4051 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2];
4052 codec->num_pcms++;
4053
4054 if (!spec->dig_out && !spec->dig_in)
4055 return 0;
4056
4057 info++;
4058 info->name = "CA0132 Digital";
4059 info->pcm_type = HDA_PCM_TYPE_SPDIF;
4060 if (spec->dig_out) {
4061 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4062 ca0132_pcm_digital_playback;
4063 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out;
4064 }
4065 if (spec->dig_in) {
4066 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4067 ca0132_pcm_digital_capture;
4068 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
4069 }
4070 codec->num_pcms++;
4071
4072 return 0;
875} 4073}
876 4074
4075static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
4076{
4077 if (pin) {
4078 snd_hda_set_pin_ctl(codec, pin, PIN_HP);
4079 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
4080 snd_hda_codec_write(codec, pin, 0,
4081 AC_VERB_SET_AMP_GAIN_MUTE,
4082 AMP_OUT_UNMUTE);
4083 }
4084 if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
4085 snd_hda_codec_write(codec, dac, 0,
4086 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO);
4087}
877 4088
878static void ca0132_config(struct hda_codec *codec) 4089static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
4090{
4091 if (pin) {
4092 snd_hda_set_pin_ctl(codec, pin, PIN_VREF80);
4093 if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
4094 snd_hda_codec_write(codec, pin, 0,
4095 AC_VERB_SET_AMP_GAIN_MUTE,
4096 AMP_IN_UNMUTE(0));
4097 }
4098 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) {
4099 snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4100 AMP_IN_UNMUTE(0));
4101
4102 /* init to 0 dB and unmute. */
4103 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
4104 HDA_AMP_VOLMASK, 0x5a);
4105 snd_hda_codec_amp_stereo(codec, adc, HDA_INPUT, 0,
4106 HDA_AMP_MUTE, 0);
4107 }
4108}
4109
4110static void ca0132_init_unsol(struct hda_codec *codec)
4111{
4112 snd_hda_jack_detect_enable(codec, UNSOL_TAG_HP, UNSOL_TAG_HP);
4113 snd_hda_jack_detect_enable(codec, UNSOL_TAG_AMIC1, UNSOL_TAG_AMIC1);
4114}
4115
4116static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir)
4117{
4118 unsigned int caps;
4119
4120 caps = snd_hda_param_read(codec, nid, dir == HDA_OUTPUT ?
4121 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
4122 snd_hda_override_amp_caps(codec, nid, dir, caps);
4123}
4124
4125/*
4126 * Switch between Digital built-in mic and analog mic.
4127 */
4128static void ca0132_set_dmic(struct hda_codec *codec, int enable)
879{ 4129{
880 struct ca0132_spec *spec = codec->spec; 4130 struct ca0132_spec *spec = codec->spec;
881 struct auto_pin_cfg *cfg = &spec->autocfg; 4131 unsigned int tmp;
4132 u8 val;
4133 unsigned int oldval;
4134
4135 snd_printdd(KERN_INFO "ca0132_set_dmic: enable=%d\n", enable);
4136
4137 oldval = stop_mic1(codec);
4138 ca0132_set_vipsource(codec, 0);
4139 if (enable) {
4140 /* set DMic input as 2-ch */
4141 tmp = FLOAT_TWO;
4142 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4143
4144 val = spec->dmic_ctl;
4145 val |= 0x80;
4146 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4147 VENDOR_CHIPIO_DMIC_CTL_SET, val);
4148
4149 if (!(spec->dmic_ctl & 0x20))
4150 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 1);
4151 } else {
4152 /* set AMic input as mono */
4153 tmp = FLOAT_ONE;
4154 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4155
4156 val = spec->dmic_ctl;
4157 /* clear bit7 and bit5 to disable dmic */
4158 val &= 0x5f;
4159 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4160 VENDOR_CHIPIO_DMIC_CTL_SET, val);
4161
4162 if (!(spec->dmic_ctl & 0x20))
4163 chipio_set_control_flag(codec, CONTROL_FLAG_DMIC, 0);
4164 }
4165 ca0132_set_vipsource(codec, 1);
4166 resume_mic1(codec, oldval);
4167}
882 4168
883 codec->pcm_format_first = 1; 4169/*
884 codec->no_sticky_stream = 1; 4170 * Initialization for Digital Mic.
4171 */
4172static void ca0132_init_dmic(struct hda_codec *codec)
4173{
4174 struct ca0132_spec *spec = codec->spec;
4175 u8 val;
4176
4177 /* Setup Digital Mic here, but don't enable.
4178 * Enable based on jack detect.
4179 */
4180
4181 /* MCLK uses MPIO1, set to enable.
4182 * Bit 2-0: MPIO select
4183 * Bit 3: set to disable
4184 * Bit 7-4: reserved
4185 */
4186 val = 0x01;
4187 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4188 VENDOR_CHIPIO_DMIC_MCLK_SET, val);
4189
4190 /* Data1 uses MPIO3. Data2 not use
4191 * Bit 2-0: Data1 MPIO select
4192 * Bit 3: set disable Data1
4193 * Bit 6-4: Data2 MPIO select
4194 * Bit 7: set disable Data2
4195 */
4196 val = 0x83;
4197 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4198 VENDOR_CHIPIO_DMIC_PIN_SET, val);
4199
4200 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
4201 * Bit 3-0: Channel mask
4202 * Bit 4: set for 48KHz, clear for 32KHz
4203 * Bit 5: mode
4204 * Bit 6: set to select Data2, clear for Data1
4205 * Bit 7: set to enable DMic, clear for AMic
4206 */
4207 val = 0x23;
4208 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
4209 spec->dmic_ctl = val;
4210 snd_hda_codec_write(codec, spec->input_pins[0], 0,
4211 VENDOR_CHIPIO_DMIC_CTL_SET, val);
4212}
885 4213
886 /* line-outs */ 4214/*
887 cfg->line_outs = 1; 4215 * Initialization for Analog Mic 2
888 cfg->line_out_pins[0] = 0x0b; /* front */ 4216 */
889 cfg->line_out_type = AUTO_PIN_LINE_OUT; 4217static void ca0132_init_analog_mic2(struct hda_codec *codec)
4218{
4219 struct ca0132_spec *spec = codec->spec;
890 4220
891 spec->dacs[0] = 0x02; 4221 mutex_lock(&spec->chipio_mutex);
892 spec->out_pins[0] = 0x0b; 4222 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
893 spec->multiout.dac_nids = spec->dacs; 4223 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x20);
894 spec->multiout.num_dacs = 1; 4224 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
895 spec->multiout.max_channels = 2; 4225 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
4226 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4227 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
4228 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4229 VENDOR_CHIPIO_8051_ADDRESS_LOW, 0x2D);
4230 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4231 VENDOR_CHIPIO_8051_ADDRESS_HIGH, 0x19);
4232 snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0,
4233 VENDOR_CHIPIO_8051_DATA_WRITE, 0x00);
4234 mutex_unlock(&spec->chipio_mutex);
4235}
896 4236
897 /* headphone */ 4237static void ca0132_refresh_widget_caps(struct hda_codec *codec)
898 cfg->hp_outs = 1; 4238{
899 cfg->hp_pins[0] = 0x0f; 4239 struct ca0132_spec *spec = codec->spec;
4240 int i;
4241 hda_nid_t nid;
900 4242
901 spec->hp_dac = 0; 4243 snd_printdd(KERN_INFO "ca0132_refresh_widget_caps.\n");
902 spec->multiout.hp_nid = 0; 4244 nid = codec->start_nid;
4245 for (i = 0; i < codec->num_nodes; i++, nid++)
4246 codec->wcaps[i] = snd_hda_param_read(codec, nid,
4247 AC_PAR_AUDIO_WIDGET_CAP);
903 4248
904 /* inputs */ 4249 for (i = 0; i < spec->multiout.num_dacs; i++)
905 cfg->num_inputs = 2; /* Mic-in and line-in */ 4250 refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT);
906 cfg->inputs[0].pin = 0x12;
907 cfg->inputs[0].type = AUTO_PIN_MIC;
908 cfg->inputs[1].pin = 0x11;
909 cfg->inputs[1].type = AUTO_PIN_LINE_IN;
910 4251
911 /* Mic-in */ 4252 for (i = 0; i < spec->num_outputs; i++)
912 spec->input_pins[0] = 0x12; 4253 refresh_amp_caps(codec, spec->out_pins[i], HDA_OUTPUT);
913 spec->input_labels[0] = "Mic";
914 spec->adcs[0] = 0x07;
915 4254
916 /* Line-In */ 4255 for (i = 0; i < spec->num_inputs; i++) {
917 spec->input_pins[1] = 0x11; 4256 refresh_amp_caps(codec, spec->adcs[i], HDA_INPUT);
918 spec->input_labels[1] = "Line"; 4257 refresh_amp_caps(codec, spec->input_pins[i], HDA_INPUT);
919 spec->adcs[1] = 0x08; 4258 }
920 spec->num_inputs = 2; 4259}
921 4260
922 /* SPDIF I/O */ 4261/*
923 spec->dig_out = 0x05; 4262 * Setup default parameters for DSP
924 spec->multiout.dig_out_nid = spec->dig_out; 4263 */
925 cfg->dig_out_pins[0] = 0x0c; 4264static void ca0132_setup_defaults(struct hda_codec *codec)
926 cfg->dig_outs = 1; 4265{
927 cfg->dig_out_type[0] = HDA_PCM_TYPE_SPDIF; 4266 unsigned int tmp;
928 spec->dig_in = 0x09; 4267 int num_fx;
929 cfg->dig_in_pin = 0x0e; 4268 int idx, i;
930 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; 4269
4270 if (!dspload_is_loaded(codec))
4271 return;
4272
4273 /* out, in effects + voicefx */
4274 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT + 1;
4275 for (idx = 0; idx < num_fx; idx++) {
4276 for (i = 0; i <= ca0132_effects[idx].params; i++) {
4277 dspio_set_uint_param(codec, ca0132_effects[idx].mid,
4278 ca0132_effects[idx].reqs[i],
4279 ca0132_effects[idx].def_vals[i]);
4280 }
4281 }
4282
4283 /*remove DSP headroom*/
4284 tmp = FLOAT_ZERO;
4285 dspio_set_uint_param(codec, 0x96, 0x3C, tmp);
4286
4287 /*set speaker EQ bypass attenuation*/
4288 dspio_set_uint_param(codec, 0x8f, 0x01, tmp);
4289
4290 /* set AMic1 and AMic2 as mono mic */
4291 tmp = FLOAT_ONE;
4292 dspio_set_uint_param(codec, 0x80, 0x00, tmp);
4293 dspio_set_uint_param(codec, 0x80, 0x01, tmp);
4294
4295 /* set AMic1 as CrystalVoice input */
4296 tmp = FLOAT_ONE;
4297 dspio_set_uint_param(codec, 0x80, 0x05, tmp);
4298
4299 /* set WUH source */
4300 tmp = FLOAT_TWO;
4301 dspio_set_uint_param(codec, 0x31, 0x00, tmp);
4302}
4303
4304/*
4305 * Initialization of flags in chip
4306 */
4307static void ca0132_init_flags(struct hda_codec *codec)
4308{
4309 chipio_set_control_flag(codec, CONTROL_FLAG_IDLE_ENABLE, 0);
4310 chipio_set_control_flag(codec, CONTROL_FLAG_PORT_A_COMMON_MODE, 0);
4311 chipio_set_control_flag(codec, CONTROL_FLAG_PORT_D_COMMON_MODE, 0);
4312 chipio_set_control_flag(codec, CONTROL_FLAG_PORT_A_10KOHM_LOAD, 0);
4313 chipio_set_control_flag(codec, CONTROL_FLAG_PORT_D_10KOHM_LOAD, 0);
4314 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_HIGH_PASS, 1);
4315}
4316
4317/*
4318 * Initialization of parameters in chip
4319 */
4320static void ca0132_init_params(struct hda_codec *codec)
4321{
4322 chipio_set_control_param(codec, CONTROL_PARAM_PORTA_160OHM_GAIN, 6);
4323 chipio_set_control_param(codec, CONTROL_PARAM_PORTD_160OHM_GAIN, 6);
4324}
4325
4326static void ca0132_set_dsp_msr(struct hda_codec *codec, bool is96k)
4327{
4328 chipio_set_control_flag(codec, CONTROL_FLAG_DSP_96KHZ, is96k);
4329 chipio_set_control_flag(codec, CONTROL_FLAG_DAC_96KHZ, is96k);
4330 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_RATE_96KHZ, is96k);
4331 chipio_set_control_flag(codec, CONTROL_FLAG_SRC_CLOCK_196MHZ, is96k);
4332 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_B_96KHZ, is96k);
4333 chipio_set_control_flag(codec, CONTROL_FLAG_ADC_C_96KHZ, is96k);
4334
4335 chipio_set_conn_rate(codec, MEM_CONNID_MICIN1, SR_96_000);
4336 chipio_set_conn_rate(codec, MEM_CONNID_MICOUT1, SR_96_000);
4337 chipio_set_conn_rate(codec, MEM_CONNID_WUH, SR_48_000);
4338}
4339
4340static bool ca0132_download_dsp_images(struct hda_codec *codec)
4341{
4342 bool dsp_loaded = false;
4343 const struct dsp_image_seg *dsp_os_image;
4344 const struct firmware *fw_entry;
4345
4346 if (request_firmware(&fw_entry, EFX_FILE, codec->bus->card->dev) != 0)
4347 return false;
4348
4349 dsp_os_image = (struct dsp_image_seg *)(fw_entry->data);
4350 dspload_image(codec, dsp_os_image, 0, 0, true, 0);
4351 dsp_loaded = dspload_wait_loaded(codec);
4352
4353 release_firmware(fw_entry);
4354
4355
4356 return dsp_loaded;
4357}
4358
4359static void ca0132_download_dsp(struct hda_codec *codec)
4360{
4361 struct ca0132_spec *spec = codec->spec;
4362
4363#ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
4364 return; /* NOP */
4365#endif
4366 spec->dsp_state = DSP_DOWNLOAD_INIT;
4367
4368 if (spec->dsp_state == DSP_DOWNLOAD_INIT) {
4369 chipio_enable_clocks(codec);
4370 spec->dsp_state = DSP_DOWNLOADING;
4371 if (!ca0132_download_dsp_images(codec))
4372 spec->dsp_state = DSP_DOWNLOAD_FAILED;
4373 else
4374 spec->dsp_state = DSP_DOWNLOADED;
4375 }
4376
4377 if (spec->dsp_state == DSP_DOWNLOADED)
4378 ca0132_set_dsp_msr(codec, true);
4379}
4380
4381static void ca0132_process_dsp_response(struct hda_codec *codec)
4382{
4383 struct ca0132_spec *spec = codec->spec;
4384
4385 snd_printdd(KERN_INFO "ca0132_process_dsp_response\n");
4386 if (spec->wait_scp) {
4387 if (dspio_get_response_data(codec) >= 0)
4388 spec->wait_scp = 0;
4389 }
4390
4391 dspio_clear_response_queue(codec);
4392}
4393
4394static void ca0132_unsol_event(struct hda_codec *codec, unsigned int res)
4395{
4396 snd_printdd(KERN_INFO "ca0132_unsol_event: 0x%x\n", res);
4397
4398
4399 if (((res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f) == UNSOL_TAG_DSP) {
4400 ca0132_process_dsp_response(codec);
4401 } else {
4402 res = snd_hda_jack_get_action(codec,
4403 (res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f);
4404
4405 snd_printdd(KERN_INFO "snd_hda_jack_get_action: 0x%x\n", res);
4406
4407 switch (res) {
4408 case UNSOL_TAG_HP:
4409 ca0132_select_out(codec);
4410 snd_hda_jack_report_sync(codec);
4411 break;
4412 case UNSOL_TAG_AMIC1:
4413 ca0132_select_mic(codec);
4414 snd_hda_jack_report_sync(codec);
4415 break;
4416 default:
4417 break;
4418 }
4419 }
931} 4420}
932 4421
4422/*
4423 * Verbs tables.
4424 */
4425
4426/* Sends before DSP download. */
4427static struct hda_verb ca0132_base_init_verbs[] = {
4428 /*enable ct extension*/
4429 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1},
4430 /*enable DSP node unsol, needed for DSP download*/
4431 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_DSP},
4432 {}
4433};
4434
4435/* Send at exit. */
4436static struct hda_verb ca0132_base_exit_verbs[] = {
4437 /*set afg to D3*/
4438 {0x01, AC_VERB_SET_POWER_STATE, 0x03},
4439 /*disable ct extension*/
4440 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0},
4441 {}
4442};
4443
4444/* Other verbs tables. Sends after DSP download. */
4445static struct hda_verb ca0132_init_verbs0[] = {
4446 /* chip init verbs */
4447 {0x15, 0x70D, 0xF0},
4448 {0x15, 0x70E, 0xFE},
4449 {0x15, 0x707, 0x75},
4450 {0x15, 0x707, 0xD3},
4451 {0x15, 0x707, 0x09},
4452 {0x15, 0x707, 0x53},
4453 {0x15, 0x707, 0xD4},
4454 {0x15, 0x707, 0xEF},
4455 {0x15, 0x707, 0x75},
4456 {0x15, 0x707, 0xD3},
4457 {0x15, 0x707, 0x09},
4458 {0x15, 0x707, 0x02},
4459 {0x15, 0x707, 0x37},
4460 {0x15, 0x707, 0x78},
4461 {0x15, 0x53C, 0xCE},
4462 {0x15, 0x575, 0xC9},
4463 {0x15, 0x53D, 0xCE},
4464 {0x15, 0x5B7, 0xC9},
4465 {0x15, 0x70D, 0xE8},
4466 {0x15, 0x70E, 0xFE},
4467 {0x15, 0x707, 0x02},
4468 {0x15, 0x707, 0x68},
4469 {0x15, 0x707, 0x62},
4470 {0x15, 0x53A, 0xCE},
4471 {0x15, 0x546, 0xC9},
4472 {0x15, 0x53B, 0xCE},
4473 {0x15, 0x5E8, 0xC9},
4474 {0x15, 0x717, 0x0D},
4475 {0x15, 0x718, 0x20},
4476 {}
4477};
4478
4479static struct hda_verb ca0132_init_verbs1[] = {
4480 {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_HP},
4481 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_AMIC1},
4482 /* config EAPD */
4483 {0x0b, 0x78D, 0x00},
4484 /*{0x0b, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/
4485 /*{0x10, 0x78D, 0x02},*/
4486 /*{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/
4487 {}
4488};
4489
933static void ca0132_init_chip(struct hda_codec *codec) 4490static void ca0132_init_chip(struct hda_codec *codec)
934{ 4491{
935 struct ca0132_spec *spec = codec->spec; 4492 struct ca0132_spec *spec = codec->spec;
4493 int num_fx;
4494 int i;
4495 unsigned int on;
936 4496
937 mutex_init(&spec->chipio_mutex); 4497 mutex_init(&spec->chipio_mutex);
4498
4499 spec->cur_out_type = SPEAKER_OUT;
4500 spec->cur_mic_type = DIGITAL_MIC;
4501 spec->cur_mic_boost = 0;
4502
4503 for (i = 0; i < VNODES_COUNT; i++) {
4504 spec->vnode_lvol[i] = 0x5a;
4505 spec->vnode_rvol[i] = 0x5a;
4506 spec->vnode_lswitch[i] = 0;
4507 spec->vnode_rswitch[i] = 0;
4508 }
4509
4510 /*
4511 * Default states for effects are in ca0132_effects[].
4512 */
4513 num_fx = OUT_EFFECTS_COUNT + IN_EFFECTS_COUNT;
4514 for (i = 0; i < num_fx; i++) {
4515 on = (unsigned int)ca0132_effects[i].reqs[0];
4516 spec->effects_switch[i] = on ? 1 : 0;
4517 }
4518
4519 spec->voicefx_val = 0;
4520 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID] = 1;
4521 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID] = 0;
4522
4523#ifdef ENABLE_TUNING_CONTROLS
4524 ca0132_init_tuning_defaults(codec);
4525#endif
938} 4526}
939 4527
940static void ca0132_exit_chip(struct hda_codec *codec) 4528static void ca0132_exit_chip(struct hda_codec *codec)
941{ 4529{
942 /* put any chip cleanup stuffs here. */ 4530 /* put any chip cleanup stuffs here. */
4531
4532 if (dspload_is_loaded(codec))
4533 dsp_reset(codec);
943} 4534}
944 4535
945static int ca0132_init(struct hda_codec *codec) 4536static int ca0132_init(struct hda_codec *codec)
@@ -948,11 +4539,23 @@ static int ca0132_init(struct hda_codec *codec)
948 struct auto_pin_cfg *cfg = &spec->autocfg; 4539 struct auto_pin_cfg *cfg = &spec->autocfg;
949 int i; 4540 int i;
950 4541
951 for (i = 0; i < spec->multiout.num_dacs; i++) { 4542 spec->dsp_state = DSP_DOWNLOAD_INIT;
952 init_output(codec, spec->out_pins[i], 4543 spec->curr_chip_addx = INVALID_CHIP_ADDRESS;
953 spec->multiout.dac_nids[i]); 4544
954 } 4545 snd_hda_power_up(codec);
955 init_output(codec, cfg->hp_pins[0], spec->hp_dac); 4546
4547 ca0132_init_params(codec);
4548 ca0132_init_flags(codec);
4549 snd_hda_sequence_write(codec, spec->base_init_verbs);
4550 ca0132_download_dsp(codec);
4551 ca0132_refresh_widget_caps(codec);
4552 ca0132_setup_defaults(codec);
4553 ca0132_init_analog_mic2(codec);
4554 ca0132_init_dmic(codec);
4555
4556 for (i = 0; i < spec->num_outputs; i++)
4557 init_output(codec, spec->out_pins[i], spec->dacs[0]);
4558
956 init_output(codec, cfg->dig_out_pins[0], spec->dig_out); 4559 init_output(codec, cfg->dig_out_pins[0], spec->dig_out);
957 4560
958 for (i = 0; i < spec->num_inputs; i++) 4561 for (i = 0; i < spec->num_inputs; i++)
@@ -960,16 +4563,29 @@ static int ca0132_init(struct hda_codec *codec)
960 4563
961 init_input(codec, cfg->dig_in_pin, spec->dig_in); 4564 init_input(codec, cfg->dig_in_pin, spec->dig_in);
962 4565
963 ca0132_set_ct_ext(codec, 1); 4566 for (i = 0; i < spec->num_init_verbs; i++)
4567 snd_hda_sequence_write(codec, spec->init_verbs[i]);
4568
4569 ca0132_init_unsol(codec);
4570
4571 ca0132_select_out(codec);
4572 ca0132_select_mic(codec);
4573
4574 snd_hda_jack_report_sync(codec);
4575
4576 snd_hda_power_down(codec);
964 4577
965 return 0; 4578 return 0;
966} 4579}
967 4580
968
969static void ca0132_free(struct hda_codec *codec) 4581static void ca0132_free(struct hda_codec *codec)
970{ 4582{
971 ca0132_set_ct_ext(codec, 0); 4583 struct ca0132_spec *spec = codec->spec;
4584
4585 snd_hda_power_up(codec);
4586 snd_hda_sequence_write(codec, spec->base_exit_verbs);
972 ca0132_exit_chip(codec); 4587 ca0132_exit_chip(codec);
4588 snd_hda_power_down(codec);
973 kfree(codec->spec); 4589 kfree(codec->spec);
974} 4590}
975 4591
@@ -978,13 +4594,52 @@ static struct hda_codec_ops ca0132_patch_ops = {
978 .build_pcms = ca0132_build_pcms, 4594 .build_pcms = ca0132_build_pcms,
979 .init = ca0132_init, 4595 .init = ca0132_init,
980 .free = ca0132_free, 4596 .free = ca0132_free,
4597 .unsol_event = ca0132_unsol_event,
981}; 4598};
982 4599
4600static void ca0132_config(struct hda_codec *codec)
4601{
4602 struct ca0132_spec *spec = codec->spec;
4603 struct auto_pin_cfg *cfg = &spec->autocfg;
4604
4605 spec->dacs[0] = 0x2;
4606 spec->dacs[1] = 0x3;
4607 spec->dacs[2] = 0x4;
4608
4609 spec->multiout.dac_nids = spec->dacs;
4610 spec->multiout.num_dacs = 3;
4611 spec->multiout.max_channels = 2;
4612
4613 spec->num_outputs = 2;
4614 spec->out_pins[0] = 0x0b; /* speaker out */
4615 spec->out_pins[1] = 0x10; /* headphone out */
4616 spec->shared_out_nid = 0x2;
983 4617
4618 spec->num_inputs = 3;
4619 spec->adcs[0] = 0x7; /* digital mic / analog mic1 */
4620 spec->adcs[1] = 0x8; /* analog mic2 */
4621 spec->adcs[2] = 0xa; /* what u hear */
4622 spec->shared_mic_nid = 0x7;
4623
4624 spec->input_pins[0] = 0x12;
4625 spec->input_pins[1] = 0x11;
4626 spec->input_pins[2] = 0x13;
4627
4628 /* SPDIF I/O */
4629 spec->dig_out = 0x05;
4630 spec->multiout.dig_out_nid = spec->dig_out;
4631 cfg->dig_out_pins[0] = 0x0c;
4632 cfg->dig_outs = 1;
4633 cfg->dig_out_type[0] = HDA_PCM_TYPE_SPDIF;
4634 spec->dig_in = 0x09;
4635 cfg->dig_in_pin = 0x0e;
4636 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF;
4637}
984 4638
985static int patch_ca0132(struct hda_codec *codec) 4639static int patch_ca0132(struct hda_codec *codec)
986{ 4640{
987 struct ca0132_spec *spec; 4641 struct ca0132_spec *spec;
4642 int err;
988 4643
989 snd_printdd("patch_ca0132\n"); 4644 snd_printdd("patch_ca0132\n");
990 4645
@@ -993,10 +4648,23 @@ static int patch_ca0132(struct hda_codec *codec)
993 return -ENOMEM; 4648 return -ENOMEM;
994 codec->spec = spec; 4649 codec->spec = spec;
995 4650
4651 spec->num_mixers = 1;
4652 spec->mixers[0] = ca0132_mixer;
4653
4654 spec->base_init_verbs = ca0132_base_init_verbs;
4655 spec->base_exit_verbs = ca0132_base_exit_verbs;
4656 spec->init_verbs[0] = ca0132_init_verbs0;
4657 spec->init_verbs[1] = ca0132_init_verbs1;
4658 spec->num_init_verbs = 2;
4659
996 ca0132_init_chip(codec); 4660 ca0132_init_chip(codec);
997 4661
998 ca0132_config(codec); 4662 ca0132_config(codec);
999 4663
4664 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4665 if (err < 0)
4666 return err;
4667
1000 codec->patch_ops = ca0132_patch_ops; 4668 codec->patch_ops = ca0132_patch_ops;
1001 4669
1002 return 0; 4670 return 0;
@@ -1013,7 +4681,7 @@ static struct hda_codec_preset snd_hda_preset_ca0132[] = {
1013MODULE_ALIAS("snd-hda-codec-id:11020011"); 4681MODULE_ALIAS("snd-hda-codec-id:11020011");
1014 4682
1015MODULE_LICENSE("GPL"); 4683MODULE_LICENSE("GPL");
1016MODULE_DESCRIPTION("Creative CA0132, CA0132 HD-audio codec"); 4684MODULE_DESCRIPTION("Creative Sound Core3D codec");
1017 4685
1018static struct hda_codec_preset_list ca0132_list = { 4686static struct hda_codec_preset_list ca0132_list = {
1019 .preset = snd_hda_preset_ca0132, 4687 .preset = snd_hda_preset_ca0132,
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index a2537b2f8724..72ebb8a36b13 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -19,16 +19,16 @@
19 */ 19 */
20 20
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/slab.h> 22#include <linux/slab.h>
24#include <linux/pci.h> 23#include <linux/pci.h>
25#include <linux/module.h> 24#include <linux/module.h>
26#include <sound/core.h> 25#include <sound/core.h>
26#include <sound/tlv.h>
27#include "hda_codec.h" 27#include "hda_codec.h"
28#include "hda_local.h" 28#include "hda_local.h"
29#include "hda_auto_parser.h" 29#include "hda_auto_parser.h"
30#include "hda_jack.h" 30#include "hda_jack.h"
31#include <sound/tlv.h> 31#include "hda_generic.h"
32 32
33/* 33/*
34 */ 34 */
@@ -36,45 +36,17 @@
36struct cs_spec { 36struct cs_spec {
37 struct hda_gen_spec gen; 37 struct hda_gen_spec gen;
38 38
39 struct auto_pin_cfg autocfg;
40 struct hda_multi_out multiout;
41 struct snd_kcontrol *vmaster_sw;
42 struct snd_kcontrol *vmaster_vol;
43
44 hda_nid_t dac_nid[AUTO_CFG_MAX_OUTS];
45 hda_nid_t slave_dig_outs[2];
46
47 unsigned int input_idx[AUTO_PIN_LAST];
48 unsigned int capsrc_idx[AUTO_PIN_LAST];
49 hda_nid_t adc_nid[AUTO_PIN_LAST];
50 unsigned int adc_idx[AUTO_PIN_LAST];
51 unsigned int num_inputs;
52 unsigned int cur_input;
53 unsigned int automic_idx;
54 hda_nid_t cur_adc;
55 unsigned int cur_adc_stream_tag;
56 unsigned int cur_adc_format;
57 hda_nid_t dig_in;
58
59 const struct hda_bind_ctls *capture_bind[2];
60
61 unsigned int gpio_mask; 39 unsigned int gpio_mask;
62 unsigned int gpio_dir; 40 unsigned int gpio_dir;
63 unsigned int gpio_data; 41 unsigned int gpio_data;
64 unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */ 42 unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */
65 unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */ 43 unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */
66 44
67 struct hda_pcm pcm_rec[2]; /* PCM information */
68
69 unsigned int hp_detect:1;
70 unsigned int mic_detect:1;
71 unsigned int speaker_2_1:1;
72 /* CS421x */ 45 /* CS421x */
73 unsigned int spdif_detect:1; 46 unsigned int spdif_detect:1;
47 unsigned int spdif_present:1;
74 unsigned int sense_b:1; 48 unsigned int sense_b:1;
75 hda_nid_t vendor_nid; 49 hda_nid_t vendor_nid;
76 struct hda_input_mux input_mux;
77 unsigned int last_input;
78}; 50};
79 51
80/* available models with CS420x */ 52/* available models with CS420x */
@@ -180,915 +152,43 @@ static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
180 AC_VERB_SET_PROC_COEF, coef); 152 AC_VERB_SET_PROC_COEF, coef);
181} 153}
182 154
183
184#define HP_EVENT 1
185#define MIC_EVENT 2
186
187/*
188 * PCM callbacks
189 */
190static int cs_playback_pcm_open(struct hda_pcm_stream *hinfo,
191 struct hda_codec *codec,
192 struct snd_pcm_substream *substream)
193{
194 struct cs_spec *spec = codec->spec;
195 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
196 hinfo);
197}
198
199static int cs_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
200 struct hda_codec *codec,
201 unsigned int stream_tag,
202 unsigned int format,
203 struct snd_pcm_substream *substream)
204{
205 struct cs_spec *spec = codec->spec;
206 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
207 stream_tag, format, substream);
208}
209
210static int cs_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 struct snd_pcm_substream *substream)
213{
214 struct cs_spec *spec = codec->spec;
215 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
216}
217
218/*
219 * Digital out
220 */
221static int cs_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
222 struct hda_codec *codec,
223 struct snd_pcm_substream *substream)
224{
225 struct cs_spec *spec = codec->spec;
226 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
227}
228
229static int cs_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
230 struct hda_codec *codec,
231 struct snd_pcm_substream *substream)
232{
233 struct cs_spec *spec = codec->spec;
234 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
235}
236
237static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
238 struct hda_codec *codec,
239 unsigned int stream_tag,
240 unsigned int format,
241 struct snd_pcm_substream *substream)
242{
243 struct cs_spec *spec = codec->spec;
244 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
245 format, substream);
246}
247
248static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
249 struct hda_codec *codec,
250 struct snd_pcm_substream *substream)
251{
252 struct cs_spec *spec = codec->spec;
253 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
254}
255
256static void cs_update_input_select(struct hda_codec *codec)
257{
258 struct cs_spec *spec = codec->spec;
259 if (spec->cur_adc)
260 snd_hda_codec_write(codec, spec->cur_adc, 0,
261 AC_VERB_SET_CONNECT_SEL,
262 spec->adc_idx[spec->cur_input]);
263}
264
265/*
266 * Analog capture
267 */
268static int cs_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
269 struct hda_codec *codec,
270 unsigned int stream_tag,
271 unsigned int format,
272 struct snd_pcm_substream *substream)
273{
274 struct cs_spec *spec = codec->spec;
275 spec->cur_adc = spec->adc_nid[spec->cur_input];
276 spec->cur_adc_stream_tag = stream_tag;
277 spec->cur_adc_format = format;
278 cs_update_input_select(codec);
279 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
280 return 0;
281}
282
283static int cs_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
284 struct hda_codec *codec,
285 struct snd_pcm_substream *substream)
286{
287 struct cs_spec *spec = codec->spec;
288 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
289 spec->cur_adc = 0;
290 return 0;
291}
292
293/*
294 */
295static const struct hda_pcm_stream cs_pcm_analog_playback = {
296 .substreams = 1,
297 .channels_min = 2,
298 .channels_max = 2,
299 .ops = {
300 .open = cs_playback_pcm_open,
301 .prepare = cs_playback_pcm_prepare,
302 .cleanup = cs_playback_pcm_cleanup
303 },
304};
305
306static const struct hda_pcm_stream cs_pcm_analog_capture = {
307 .substreams = 1,
308 .channels_min = 2,
309 .channels_max = 2,
310 .ops = {
311 .prepare = cs_capture_pcm_prepare,
312 .cleanup = cs_capture_pcm_cleanup
313 },
314};
315
316static const struct hda_pcm_stream cs_pcm_digital_playback = {
317 .substreams = 1,
318 .channels_min = 2,
319 .channels_max = 2,
320 .ops = {
321 .open = cs_dig_playback_pcm_open,
322 .close = cs_dig_playback_pcm_close,
323 .prepare = cs_dig_playback_pcm_prepare,
324 .cleanup = cs_dig_playback_pcm_cleanup
325 },
326};
327
328static const struct hda_pcm_stream cs_pcm_digital_capture = {
329 .substreams = 1,
330 .channels_min = 2,
331 .channels_max = 2,
332};
333
334static int cs_build_pcms(struct hda_codec *codec)
335{
336 struct cs_spec *spec = codec->spec;
337 struct hda_pcm *info = spec->pcm_rec;
338
339 codec->pcm_info = info;
340 codec->num_pcms = 0;
341
342 info->name = "Cirrus Analog";
343 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cs_pcm_analog_playback;
344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0];
345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
346 spec->multiout.max_channels;
347 if (spec->speaker_2_1)
348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
349 snd_pcm_2_1_chmaps;
350 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture;
351 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
352 spec->adc_nid[spec->cur_input];
353 codec->num_pcms++;
354
355 if (!spec->multiout.dig_out_nid && !spec->dig_in)
356 return 0;
357
358 info++;
359 info->name = "Cirrus Digital";
360 info->pcm_type = spec->autocfg.dig_out_type[0];
361 if (!info->pcm_type)
362 info->pcm_type = HDA_PCM_TYPE_SPDIF;
363 if (spec->multiout.dig_out_nid) {
364 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
365 cs_pcm_digital_playback;
366 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
367 spec->multiout.dig_out_nid;
368 }
369 if (spec->dig_in) {
370 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
371 cs_pcm_digital_capture;
372 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
373 }
374 codec->num_pcms++;
375
376 return 0;
377}
378
379/*
380 * parse codec topology
381 */
382
383static hda_nid_t get_dac(struct hda_codec *codec, hda_nid_t pin)
384{
385 hda_nid_t dac;
386 if (!pin)
387 return 0;
388 if (snd_hda_get_connections(codec, pin, &dac, 1) != 1)
389 return 0;
390 return dac;
391}
392
393static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
394{
395 struct cs_spec *spec = codec->spec;
396 struct auto_pin_cfg *cfg = &spec->autocfg;
397 hda_nid_t pin = cfg->inputs[idx].pin;
398 unsigned int val;
399 if (!is_jack_detectable(codec, pin))
400 return 0;
401 val = snd_hda_codec_get_pincfg(codec, pin);
402 return (snd_hda_get_input_pin_attr(val) != INPUT_PIN_ATTR_INT);
403}
404
405static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
406 unsigned int *idxp)
407{
408 int i, idx;
409 hda_nid_t nid;
410
411 nid = codec->start_nid;
412 for (i = 0; i < codec->num_nodes; i++, nid++) {
413 unsigned int type;
414 type = get_wcaps_type(get_wcaps(codec, nid));
415 if (type != AC_WID_AUD_IN)
416 continue;
417 idx = snd_hda_get_conn_index(codec, nid, pin, false);
418 if (idx >= 0) {
419 *idxp = idx;
420 return nid;
421 }
422 }
423 return 0;
424}
425
426static int is_active_pin(struct hda_codec *codec, hda_nid_t nid)
427{
428 unsigned int val;
429 val = snd_hda_codec_get_pincfg(codec, nid);
430 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
431}
432
433static int parse_output(struct hda_codec *codec)
434{
435 struct cs_spec *spec = codec->spec;
436 struct auto_pin_cfg *cfg = &spec->autocfg;
437 int i, extra_nids;
438 hda_nid_t dac;
439
440 for (i = 0; i < cfg->line_outs; i++) {
441 dac = get_dac(codec, cfg->line_out_pins[i]);
442 if (!dac)
443 break;
444 spec->dac_nid[i] = dac;
445 }
446 spec->multiout.num_dacs = i;
447 spec->multiout.dac_nids = spec->dac_nid;
448 spec->multiout.max_channels = i * 2;
449
450 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && i == 2)
451 spec->speaker_2_1 = 1; /* assume 2.1 speakers */
452
453 /* add HP and speakers */
454 extra_nids = 0;
455 for (i = 0; i < cfg->hp_outs; i++) {
456 dac = get_dac(codec, cfg->hp_pins[i]);
457 if (!dac)
458 break;
459 if (!i)
460 spec->multiout.hp_nid = dac;
461 else
462 spec->multiout.extra_out_nid[extra_nids++] = dac;
463 }
464 for (i = 0; i < cfg->speaker_outs; i++) {
465 dac = get_dac(codec, cfg->speaker_pins[i]);
466 if (!dac)
467 break;
468 spec->multiout.extra_out_nid[extra_nids++] = dac;
469 }
470
471 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
472 cfg->speaker_outs = cfg->line_outs;
473 memcpy(cfg->speaker_pins, cfg->line_out_pins,
474 sizeof(cfg->speaker_pins));
475 cfg->line_outs = 0;
476 memset(cfg->line_out_pins, 0, sizeof(cfg->line_out_pins));
477 }
478
479 return 0;
480}
481
482static int parse_input(struct hda_codec *codec)
483{
484 struct cs_spec *spec = codec->spec;
485 struct auto_pin_cfg *cfg = &spec->autocfg;
486 int i;
487
488 for (i = 0; i < cfg->num_inputs; i++) {
489 hda_nid_t pin = cfg->inputs[i].pin;
490 spec->input_idx[spec->num_inputs] = i;
491 spec->capsrc_idx[i] = spec->num_inputs++;
492 spec->cur_input = i;
493 spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]);
494 }
495 if (!spec->num_inputs)
496 return 0;
497
498 /* check whether the automatic mic switch is available */
499 if (spec->num_inputs == 2 &&
500 cfg->inputs[0].type == AUTO_PIN_MIC &&
501 cfg->inputs[1].type == AUTO_PIN_MIC) {
502 if (is_ext_mic(codec, cfg->inputs[0].pin)) {
503 if (!is_ext_mic(codec, cfg->inputs[1].pin)) {
504 spec->mic_detect = 1;
505 spec->automic_idx = 0;
506 }
507 } else {
508 if (is_ext_mic(codec, cfg->inputs[1].pin)) {
509 spec->mic_detect = 1;
510 spec->automic_idx = 1;
511 }
512 }
513 }
514 return 0;
515}
516
517
518static int parse_digital_output(struct hda_codec *codec)
519{
520 struct cs_spec *spec = codec->spec;
521 struct auto_pin_cfg *cfg = &spec->autocfg;
522 hda_nid_t nid;
523
524 if (!cfg->dig_outs)
525 return 0;
526 if (snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) < 1)
527 return 0;
528 spec->multiout.dig_out_nid = nid;
529 spec->multiout.share_spdif = 1;
530 if (cfg->dig_outs > 1 &&
531 snd_hda_get_connections(codec, cfg->dig_out_pins[1], &nid, 1) > 0) {
532 spec->slave_dig_outs[0] = nid;
533 codec->slave_dig_outs = spec->slave_dig_outs;
534 }
535 return 0;
536}
537
538static int parse_digital_input(struct hda_codec *codec)
539{
540 struct cs_spec *spec = codec->spec;
541 struct auto_pin_cfg *cfg = &spec->autocfg;
542 int idx;
543
544 if (cfg->dig_in_pin)
545 spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx);
546 return 0;
547}
548
549/*
550 * create mixer controls
551 */
552
553static const char * const dir_sfx[2] = { "Playback", "Capture" };
554
555static int add_mute(struct hda_codec *codec, const char *name, int index,
556 unsigned int pval, int dir, struct snd_kcontrol **kctlp)
557{
558 char tmp[44];
559 struct snd_kcontrol_new knew =
560 HDA_CODEC_MUTE_IDX(tmp, index, 0, 0, HDA_OUTPUT);
561 knew.private_value = pval;
562 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]);
563 *kctlp = snd_ctl_new1(&knew, codec);
564 (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
565 return snd_hda_ctl_add(codec, 0, *kctlp);
566}
567
568static int add_volume(struct hda_codec *codec, const char *name,
569 int index, unsigned int pval, int dir,
570 struct snd_kcontrol **kctlp)
571{
572 char tmp[44];
573 struct snd_kcontrol_new knew =
574 HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT);
575 knew.private_value = pval;
576 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
577 *kctlp = snd_ctl_new1(&knew, codec);
578 (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
579 return snd_hda_ctl_add(codec, 0, *kctlp);
580}
581
582static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
583{
584 unsigned int caps;
585
586 /* set the upper-limit for mixer amp to 0dB */
587 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
588 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
589 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
590 << AC_AMPCAP_NUM_STEPS_SHIFT;
591 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
592}
593
594static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
595{
596 struct cs_spec *spec = codec->spec;
597 unsigned int tlv[4];
598 int err;
599
600 spec->vmaster_sw =
601 snd_ctl_make_virtual_master("Master Playback Switch", NULL);
602 err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw);
603 if (err < 0)
604 return err;
605
606 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
607 spec->vmaster_vol =
608 snd_ctl_make_virtual_master("Master Playback Volume", tlv);
609 err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol);
610 if (err < 0)
611 return err;
612 return 0;
613}
614
615static int add_output(struct hda_codec *codec, hda_nid_t dac, int idx,
616 int num_ctls, int type)
617{
618 struct cs_spec *spec = codec->spec;
619 const char *name;
620 int err, index;
621 struct snd_kcontrol *kctl;
622 static const char * const speakers[] = {
623 "Front Speaker", "Surround Speaker", "Bass Speaker"
624 };
625 static const char * const line_outs[] = {
626 "Front Line Out", "Surround Line Out", "Bass Line Out"
627 };
628
629 fix_volume_caps(codec, dac);
630 if (!spec->vmaster_sw) {
631 err = add_vmaster(codec, dac);
632 if (err < 0)
633 return err;
634 }
635
636 index = 0;
637 switch (type) {
638 case AUTO_PIN_HP_OUT:
639 name = "Headphone";
640 index = idx;
641 break;
642 case AUTO_PIN_SPEAKER_OUT:
643 if (spec->speaker_2_1)
644 name = idx ? "Bass Speaker" : "Speaker";
645 else if (num_ctls > 1)
646 name = speakers[idx];
647 else
648 name = "Speaker";
649 break;
650 default:
651 if (num_ctls > 1)
652 name = line_outs[idx];
653 else
654 name = "Line Out";
655 break;
656 }
657
658 err = add_mute(codec, name, index,
659 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
660 if (err < 0)
661 return err;
662 err = snd_ctl_add_slave(spec->vmaster_sw, kctl);
663 if (err < 0)
664 return err;
665
666 err = add_volume(codec, name, index,
667 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
668 if (err < 0)
669 return err;
670 err = snd_ctl_add_slave(spec->vmaster_vol, kctl);
671 if (err < 0)
672 return err;
673
674 return 0;
675}
676
677static int build_output(struct hda_codec *codec)
678{
679 struct cs_spec *spec = codec->spec;
680 struct auto_pin_cfg *cfg = &spec->autocfg;
681 int i, err;
682
683 for (i = 0; i < cfg->line_outs; i++) {
684 err = add_output(codec, get_dac(codec, cfg->line_out_pins[i]),
685 i, cfg->line_outs, cfg->line_out_type);
686 if (err < 0)
687 return err;
688 }
689 for (i = 0; i < cfg->hp_outs; i++) {
690 err = add_output(codec, get_dac(codec, cfg->hp_pins[i]),
691 i, cfg->hp_outs, AUTO_PIN_HP_OUT);
692 if (err < 0)
693 return err;
694 }
695 for (i = 0; i < cfg->speaker_outs; i++) {
696 err = add_output(codec, get_dac(codec, cfg->speaker_pins[i]),
697 i, cfg->speaker_outs, AUTO_PIN_SPEAKER_OUT);
698 if (err < 0)
699 return err;
700 }
701 return 0;
702}
703
704/*
705 */
706
707static const struct snd_kcontrol_new cs_capture_ctls[] = {
708 HDA_BIND_SW("Capture Switch", 0),
709 HDA_BIND_VOL("Capture Volume", 0),
710};
711
712static int change_cur_input(struct hda_codec *codec, unsigned int idx,
713 int force)
714{
715 struct cs_spec *spec = codec->spec;
716
717 if (spec->cur_input == idx && !force)
718 return 0;
719 if (spec->cur_adc && spec->cur_adc != spec->adc_nid[idx]) {
720 /* stream is running, let's swap the current ADC */
721 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
722 spec->cur_adc = spec->adc_nid[idx];
723 snd_hda_codec_setup_stream(codec, spec->cur_adc,
724 spec->cur_adc_stream_tag, 0,
725 spec->cur_adc_format);
726 }
727 spec->cur_input = idx;
728 cs_update_input_select(codec);
729 return 1;
730}
731
732static int cs_capture_source_info(struct snd_kcontrol *kcontrol,
733 struct snd_ctl_elem_info *uinfo)
734{
735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
736 struct cs_spec *spec = codec->spec;
737 struct auto_pin_cfg *cfg = &spec->autocfg;
738 unsigned int idx;
739
740 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
741 uinfo->count = 1;
742 uinfo->value.enumerated.items = spec->num_inputs;
743 if (uinfo->value.enumerated.item >= spec->num_inputs)
744 uinfo->value.enumerated.item = spec->num_inputs - 1;
745 idx = spec->input_idx[uinfo->value.enumerated.item];
746 snd_hda_get_pin_label(codec, cfg->inputs[idx].pin, cfg,
747 uinfo->value.enumerated.name,
748 sizeof(uinfo->value.enumerated.name), NULL);
749 return 0;
750}
751
752static int cs_capture_source_get(struct snd_kcontrol *kcontrol,
753 struct snd_ctl_elem_value *ucontrol)
754{
755 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
756 struct cs_spec *spec = codec->spec;
757 ucontrol->value.enumerated.item[0] = spec->capsrc_idx[spec->cur_input];
758 return 0;
759}
760
761static int cs_capture_source_put(struct snd_kcontrol *kcontrol,
762 struct snd_ctl_elem_value *ucontrol)
763{
764 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
765 struct cs_spec *spec = codec->spec;
766 unsigned int idx = ucontrol->value.enumerated.item[0];
767
768 if (idx >= spec->num_inputs)
769 return -EINVAL;
770 idx = spec->input_idx[idx];
771 return change_cur_input(codec, idx, 0);
772}
773
774static const struct snd_kcontrol_new cs_capture_source = {
775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
776 .name = "Capture Source",
777 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
778 .info = cs_capture_source_info,
779 .get = cs_capture_source_get,
780 .put = cs_capture_source_put,
781};
782
783static const struct hda_bind_ctls *make_bind_capture(struct hda_codec *codec,
784 struct hda_ctl_ops *ops)
785{
786 struct cs_spec *spec = codec->spec;
787 struct hda_bind_ctls *bind;
788 int i, n;
789
790 bind = kzalloc(sizeof(*bind) + sizeof(long) * (spec->num_inputs + 1),
791 GFP_KERNEL);
792 if (!bind)
793 return NULL;
794 bind->ops = ops;
795 n = 0;
796 for (i = 0; i < AUTO_PIN_LAST; i++) {
797 if (!spec->adc_nid[i])
798 continue;
799 bind->values[n++] =
800 HDA_COMPOSE_AMP_VAL(spec->adc_nid[i], 3,
801 spec->adc_idx[i], HDA_INPUT);
802 }
803 return bind;
804}
805
806/* add a (input-boost) volume control to the given input pin */
807static int add_input_volume_control(struct hda_codec *codec,
808 struct auto_pin_cfg *cfg,
809 int item)
810{
811 hda_nid_t pin = cfg->inputs[item].pin;
812 u32 caps;
813 const char *label;
814 struct snd_kcontrol *kctl;
815
816 if (!(get_wcaps(codec, pin) & AC_WCAP_IN_AMP))
817 return 0;
818 caps = query_amp_caps(codec, pin, HDA_INPUT);
819 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
820 if (caps <= 1)
821 return 0;
822 label = hda_get_autocfg_input_label(codec, cfg, item);
823 return add_volume(codec, label, 0,
824 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT), 1, &kctl);
825}
826
827static int build_input(struct hda_codec *codec)
828{
829 struct cs_spec *spec = codec->spec;
830 int i, err;
831
832 if (!spec->num_inputs)
833 return 0;
834
835 /* make bind-capture */
836 spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw);
837 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
838 for (i = 0; i < 2; i++) {
839 struct snd_kcontrol *kctl;
840 int n;
841 if (!spec->capture_bind[i])
842 return -ENOMEM;
843 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
844 if (!kctl)
845 return -ENOMEM;
846 kctl->private_value = (long)spec->capture_bind[i];
847 err = snd_hda_ctl_add(codec, 0, kctl);
848 if (err < 0)
849 return err;
850 for (n = 0; n < AUTO_PIN_LAST; n++) {
851 if (!spec->adc_nid[n])
852 continue;
853 err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]);
854 if (err < 0)
855 return err;
856 }
857 }
858
859 if (spec->num_inputs > 1 && !spec->mic_detect) {
860 err = snd_hda_ctl_add(codec, 0,
861 snd_ctl_new1(&cs_capture_source, codec));
862 if (err < 0)
863 return err;
864 }
865
866 for (i = 0; i < spec->num_inputs; i++) {
867 err = add_input_volume_control(codec, &spec->autocfg, i);
868 if (err < 0)
869 return err;
870 }
871
872 return 0;
873}
874
875/*
876 */
877
878static int build_digital_output(struct hda_codec *codec)
879{
880 struct cs_spec *spec = codec->spec;
881 int err;
882
883 if (!spec->multiout.dig_out_nid)
884 return 0;
885
886 err = snd_hda_create_dig_out_ctls(codec, spec->multiout.dig_out_nid,
887 spec->multiout.dig_out_nid,
888 spec->pcm_rec[1].pcm_type);
889 if (err < 0)
890 return err;
891 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
892 if (err < 0)
893 return err;
894 return 0;
895}
896
897static int build_digital_input(struct hda_codec *codec)
898{
899 struct cs_spec *spec = codec->spec;
900 if (spec->dig_in)
901 return snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
902 return 0;
903}
904
905/* 155/*
906 * auto-mute and auto-mic switching 156 * auto-mute and auto-mic switching
907 * CS421x auto-output redirecting 157 * CS421x auto-output redirecting
908 * HP/SPK/SPDIF 158 * HP/SPK/SPDIF
909 */ 159 */
910 160
911static void cs_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl) 161static void cs_automute(struct hda_codec *codec)
912{ 162{
913 struct cs_spec *spec = codec->spec; 163 struct cs_spec *spec = codec->spec;
914 struct auto_pin_cfg *cfg = &spec->autocfg;
915 unsigned int hp_present;
916 unsigned int spdif_present;
917 hda_nid_t nid;
918 int i;
919
920 spdif_present = 0;
921 if (cfg->dig_outs) {
922 nid = cfg->dig_out_pins[0];
923 if (is_jack_detectable(codec, nid)) {
924 /*
925 TODO: SPDIF output redirect when SENSE_B is enabled.
926 Shared (SENSE_A) jack (e.g HP/mini-TOSLINK)
927 assumed.
928 */
929 if (snd_hda_jack_detect(codec, nid)
930 /* && spec->sense_b */)
931 spdif_present = 1;
932 }
933 }
934 164
935 hp_present = 0; 165 /* mute HPs if spdif jack (SENSE_B) is present */
936 for (i = 0; i < cfg->hp_outs; i++) { 166 spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b);
937 nid = cfg->hp_pins[i];
938 if (!is_jack_detectable(codec, nid))
939 continue;
940 hp_present = snd_hda_jack_detect(codec, nid);
941 if (hp_present)
942 break;
943 }
944 167
945 /* mute speakers if spdif or hp jack is plugged in */ 168 snd_hda_gen_update_outputs(codec);
946 for (i = 0; i < cfg->speaker_outs; i++) {
947 int pin_ctl = hp_present ? 0 : PIN_OUT;
948 /* detect on spdif is specific to CS4210 */
949 if (spdif_present && (spec->vendor_nid == CS4210_VENDOR_NID))
950 pin_ctl = 0;
951 169
952 nid = cfg->speaker_pins[i];
953 snd_hda_set_pin_ctl(codec, nid, pin_ctl);
954 }
955 if (spec->gpio_eapd_hp) { 170 if (spec->gpio_eapd_hp) {
956 unsigned int gpio = hp_present ? 171 unsigned int gpio = spec->gen.hp_jack_present ?
957 spec->gpio_eapd_hp : spec->gpio_eapd_speaker; 172 spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
958 snd_hda_codec_write(codec, 0x01, 0, 173 snd_hda_codec_write(codec, 0x01, 0,
959 AC_VERB_SET_GPIO_DATA, gpio); 174 AC_VERB_SET_GPIO_DATA, gpio);
960 } 175 }
961
962 /* specific to CS4210 */
963 if (spec->vendor_nid == CS4210_VENDOR_NID) {
964 /* mute HPs if spdif jack (SENSE_B) is present */
965 for (i = 0; i < cfg->hp_outs; i++) {
966 nid = cfg->hp_pins[i];
967 snd_hda_set_pin_ctl(codec, nid,
968 (spdif_present && spec->sense_b) ? 0 : PIN_HP);
969 }
970
971 /* SPDIF TX on/off */
972 if (cfg->dig_outs) {
973 nid = cfg->dig_out_pins[0];
974 snd_hda_set_pin_ctl(codec, nid,
975 spdif_present ? PIN_OUT : 0);
976
977 }
978 /* Update board GPIOs if neccessary ... */
979 }
980} 176}
981 177
982/* 178static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid)
983 * Auto-input redirect for CS421x
984 * Switch max 3 inputs of a single ADC (nid 3)
985*/
986
987static void cs_automic(struct hda_codec *codec, struct hda_jack_tbl *tbl)
988{ 179{
989 struct cs_spec *spec = codec->spec; 180 unsigned int val;
990 struct auto_pin_cfg *cfg = &spec->autocfg; 181 val = snd_hda_codec_get_pincfg(codec, nid);
991 hda_nid_t nid; 182 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
992 unsigned int present;
993
994 nid = cfg->inputs[spec->automic_idx].pin;
995 present = snd_hda_jack_detect(codec, nid);
996
997 /* specific to CS421x, single ADC */
998 if (spec->vendor_nid == CS420X_VENDOR_NID) {
999 if (present)
1000 change_cur_input(codec, spec->automic_idx, 0);
1001 else
1002 change_cur_input(codec, !spec->automic_idx, 0);
1003 } else {
1004 if (present) {
1005 if (spec->cur_input != spec->automic_idx) {
1006 spec->last_input = spec->cur_input;
1007 spec->cur_input = spec->automic_idx;
1008 }
1009 } else {
1010 spec->cur_input = spec->last_input;
1011 }
1012 cs_update_input_select(codec);
1013 }
1014}
1015
1016/*
1017 */
1018
1019static void init_output(struct hda_codec *codec)
1020{
1021 struct cs_spec *spec = codec->spec;
1022 struct auto_pin_cfg *cfg = &spec->autocfg;
1023 int i;
1024
1025 /* mute first */
1026 for (i = 0; i < spec->multiout.num_dacs; i++)
1027 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
1028 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
1029 if (spec->multiout.hp_nid)
1030 snd_hda_codec_write(codec, spec->multiout.hp_nid, 0,
1031 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
1032 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
1033 if (!spec->multiout.extra_out_nid[i])
1034 break;
1035 snd_hda_codec_write(codec, spec->multiout.extra_out_nid[i], 0,
1036 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
1037 }
1038
1039 /* set appropriate pin controls */
1040 for (i = 0; i < cfg->line_outs; i++)
1041 snd_hda_set_pin_ctl(codec, cfg->line_out_pins[i], PIN_OUT);
1042 /* HP */
1043 for (i = 0; i < cfg->hp_outs; i++) {
1044 hda_nid_t nid = cfg->hp_pins[i];
1045 snd_hda_set_pin_ctl(codec, nid, PIN_HP);
1046 if (!cfg->speaker_outs)
1047 continue;
1048 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
1049 snd_hda_jack_detect_enable_callback(codec, nid, HP_EVENT, cs_automute);
1050 spec->hp_detect = 1;
1051 }
1052 }
1053
1054 /* Speaker */
1055 for (i = 0; i < cfg->speaker_outs; i++)
1056 snd_hda_set_pin_ctl(codec, cfg->speaker_pins[i], PIN_OUT);
1057
1058 /* SPDIF is enabled on presence detect for CS421x */
1059 if (spec->hp_detect || spec->spdif_detect)
1060 cs_automute(codec, NULL);
1061} 183}
1062 184
1063static void init_input(struct hda_codec *codec) 185static void init_input_coef(struct hda_codec *codec)
1064{ 186{
1065 struct cs_spec *spec = codec->spec; 187 struct cs_spec *spec = codec->spec;
1066 struct auto_pin_cfg *cfg = &spec->autocfg;
1067 unsigned int coef; 188 unsigned int coef;
1068 int i;
1069 189
1070 for (i = 0; i < cfg->num_inputs; i++) {
1071 unsigned int ctl;
1072 hda_nid_t pin = cfg->inputs[i].pin;
1073 if (!spec->adc_nid[i])
1074 continue;
1075 /* set appropriate pin control and mute first */
1076 ctl = PIN_IN;
1077 if (cfg->inputs[i].type == AUTO_PIN_MIC)
1078 ctl |= snd_hda_get_default_vref(codec, pin);
1079 snd_hda_set_pin_ctl(codec, pin, ctl);
1080 snd_hda_codec_write(codec, spec->adc_nid[i], 0,
1081 AC_VERB_SET_AMP_GAIN_MUTE,
1082 AMP_IN_MUTE(spec->adc_idx[i]));
1083 if (spec->mic_detect && spec->automic_idx == i)
1084 snd_hda_jack_detect_enable_callback(codec, pin, MIC_EVENT, cs_automic);
1085 }
1086 /* CS420x has multiple ADC, CS421x has single ADC */ 190 /* CS420x has multiple ADC, CS421x has single ADC */
1087 if (spec->vendor_nid == CS420X_VENDOR_NID) { 191 if (spec->vendor_nid == CS420X_VENDOR_NID) {
1088 change_cur_input(codec, spec->cur_input, 1);
1089 if (spec->mic_detect)
1090 cs_automic(codec, NULL);
1091
1092 coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG); 192 coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG);
1093 if (is_active_pin(codec, CS_DMIC2_PIN_NID)) 193 if (is_active_pin(codec, CS_DMIC2_PIN_NID))
1094 coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */ 194 coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */
@@ -1099,13 +199,6 @@ static void init_input(struct hda_codec *codec)
1099 */ 199 */
1100 200
1101 cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef); 201 cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef);
1102 } else {
1103 if (spec->mic_detect)
1104 cs_automic(codec, NULL);
1105 else {
1106 spec->cur_adc = spec->adc_nid[spec->cur_input];
1107 cs_update_input_select(codec);
1108 }
1109 } 202 }
1110} 203}
1111 204
@@ -1178,7 +271,7 @@ static const struct hda_verb cs_errata_init_verbs[] = {
1178}; 271};
1179 272
1180/* SPDIF setup */ 273/* SPDIF setup */
1181static void init_digital(struct hda_codec *codec) 274static void init_digital_coef(struct hda_codec *codec)
1182{ 275{
1183 unsigned int coef; 276 unsigned int coef;
1184 277
@@ -1201,7 +294,7 @@ static int cs_init(struct hda_codec *codec)
1201 294
1202 snd_hda_sequence_write(codec, cs_coef_init_verbs); 295 snd_hda_sequence_write(codec, cs_coef_init_verbs);
1203 296
1204 snd_hda_gen_apply_verbs(codec); 297 snd_hda_gen_init(codec);
1205 298
1206 if (spec->gpio_mask) { 299 if (spec->gpio_mask) {
1207 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, 300 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
@@ -1212,53 +305,17 @@ static int cs_init(struct hda_codec *codec)
1212 spec->gpio_data); 305 spec->gpio_data);
1213 } 306 }
1214 307
1215 init_output(codec); 308 init_input_coef(codec);
1216 init_input(codec); 309 init_digital_coef(codec);
1217 init_digital(codec);
1218
1219 return 0;
1220}
1221
1222static int cs_build_controls(struct hda_codec *codec)
1223{
1224 struct cs_spec *spec = codec->spec;
1225 int err;
1226
1227 err = build_output(codec);
1228 if (err < 0)
1229 return err;
1230 err = build_input(codec);
1231 if (err < 0)
1232 return err;
1233 err = build_digital_output(codec);
1234 if (err < 0)
1235 return err;
1236 err = build_digital_input(codec);
1237 if (err < 0)
1238 return err;
1239 err = cs_init(codec);
1240 if (err < 0)
1241 return err;
1242
1243 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1244 if (err < 0)
1245 return err;
1246 310
1247 return 0; 311 return 0;
1248} 312}
1249 313
1250static void cs_free(struct hda_codec *codec) 314#define cs_free snd_hda_gen_free
1251{
1252 struct cs_spec *spec = codec->spec;
1253 kfree(spec->capture_bind[0]);
1254 kfree(spec->capture_bind[1]);
1255 snd_hda_gen_free(&spec->gen);
1256 kfree(codec->spec);
1257}
1258 315
1259static const struct hda_codec_ops cs_patch_ops = { 316static const struct hda_codec_ops cs_patch_ops = {
1260 .build_controls = cs_build_controls, 317 .build_controls = snd_hda_gen_build_controls,
1261 .build_pcms = cs_build_pcms, 318 .build_pcms = snd_hda_gen_build_pcms,
1262 .init = cs_init, 319 .init = cs_init,
1263 .free = cs_free, 320 .free = cs_free,
1264 .unsol_event = snd_hda_jack_unsol_event, 321 .unsol_event = snd_hda_jack_unsol_event,
@@ -1269,22 +326,14 @@ static int cs_parse_auto_config(struct hda_codec *codec)
1269 struct cs_spec *spec = codec->spec; 326 struct cs_spec *spec = codec->spec;
1270 int err; 327 int err;
1271 328
1272 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 329 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
1273 if (err < 0) 330 if (err < 0)
1274 return err; 331 return err;
1275 332
1276 err = parse_output(codec); 333 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1277 if (err < 0)
1278 return err;
1279 err = parse_input(codec);
1280 if (err < 0)
1281 return err;
1282 err = parse_digital_output(codec);
1283 if (err < 0)
1284 return err;
1285 err = parse_digital_input(codec);
1286 if (err < 0) 334 if (err < 0)
1287 return err; 335 return err;
336
1288 return 0; 337 return 0;
1289} 338}
1290 339
@@ -1434,18 +483,28 @@ static const struct hda_fixup cs420x_fixups[] = {
1434 }, 483 },
1435}; 484};
1436 485
1437static int patch_cs420x(struct hda_codec *codec) 486static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid)
1438{ 487{
1439 struct cs_spec *spec; 488 struct cs_spec *spec;
1440 int err;
1441 489
1442 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 490 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1443 if (!spec) 491 if (!spec)
1444 return -ENOMEM; 492 return NULL;
1445 codec->spec = spec; 493 codec->spec = spec;
1446 snd_hda_gen_init(&spec->gen); 494 spec->vendor_nid = vendor_nid;
495 snd_hda_gen_spec_init(&spec->gen);
496
497 return spec;
498}
499
500static int patch_cs420x(struct hda_codec *codec)
501{
502 struct cs_spec *spec;
503 int err;
1447 504
1448 spec->vendor_nid = CS420X_VENDOR_NID; 505 spec = cs_alloc_spec(codec, CS420X_VENDOR_NID);
506 if (!spec)
507 return -ENOMEM;
1449 508
1450 snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl, 509 snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl,
1451 cs420x_fixups); 510 cs420x_fixups);
@@ -1463,7 +522,6 @@ static int patch_cs420x(struct hda_codec *codec)
1463 522
1464 error: 523 error:
1465 cs_free(codec); 524 cs_free(codec);
1466 codec->spec = NULL;
1467 return err; 525 return err;
1468} 526}
1469 527
@@ -1622,7 +680,7 @@ static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol,
1622 } 680 }
1623} 681}
1624 682
1625static const struct snd_kcontrol_new cs421x_speaker_bost_ctl = { 683static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = {
1626 684
1627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1628 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 686 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
@@ -1667,20 +725,44 @@ static void cs4210_pinmux_init(struct hda_codec *codec)
1667 } 725 }
1668} 726}
1669 727
1670static void init_cs421x_digital(struct hda_codec *codec) 728static void cs4210_spdif_automute(struct hda_codec *codec,
729 struct hda_jack_tbl *tbl)
1671{ 730{
1672 struct cs_spec *spec = codec->spec; 731 struct cs_spec *spec = codec->spec;
1673 struct auto_pin_cfg *cfg = &spec->autocfg; 732 bool spdif_present = false;
1674 int i; 733 hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0];
734
735 /* detect on spdif is specific to CS4210 */
736 if (!spec->spdif_detect ||
737 spec->vendor_nid != CS4210_VENDOR_NID)
738 return;
1675 739
740 spdif_present = snd_hda_jack_detect(codec, spdif_pin);
741 if (spdif_present == spec->spdif_present)
742 return;
743
744 spec->spdif_present = spdif_present;
745 /* SPDIF TX on/off */
746 if (spdif_present)
747 snd_hda_set_pin_ctl(codec, spdif_pin,
748 spdif_present ? PIN_OUT : 0);
749
750 cs_automute(codec);
751}
752
753static void parse_cs421x_digital(struct hda_codec *codec)
754{
755 struct cs_spec *spec = codec->spec;
756 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
757 int i;
1676 758
1677 for (i = 0; i < cfg->dig_outs; i++) { 759 for (i = 0; i < cfg->dig_outs; i++) {
1678 hda_nid_t nid = cfg->dig_out_pins[i]; 760 hda_nid_t nid = cfg->dig_out_pins[i];
1679 if (!cfg->speaker_outs)
1680 continue;
1681 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { 761 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
1682 snd_hda_jack_detect_enable_callback(codec, nid, SPDIF_EVENT, cs_automute);
1683 spec->spdif_detect = 1; 762 spec->spdif_detect = 1;
763 snd_hda_jack_detect_enable_callback(codec, nid,
764 SPDIF_EVENT,
765 cs4210_spdif_automute);
1684 } 766 }
1685 } 767 }
1686} 768}
@@ -1695,6 +777,8 @@ static int cs421x_init(struct hda_codec *codec)
1695 cs4210_pinmux_init(codec); 777 cs4210_pinmux_init(codec);
1696 } 778 }
1697 779
780 snd_hda_gen_init(codec);
781
1698 if (spec->gpio_mask) { 782 if (spec->gpio_mask) {
1699 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, 783 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
1700 spec->gpio_mask); 784 spec->gpio_mask);
@@ -1704,233 +788,61 @@ static int cs421x_init(struct hda_codec *codec)
1704 spec->gpio_data); 788 spec->gpio_data);
1705 } 789 }
1706 790
1707 init_output(codec); 791 init_input_coef(codec);
1708 init_input(codec);
1709 init_cs421x_digital(codec);
1710 792
1711 return 0; 793 cs4210_spdif_automute(codec, NULL);
1712}
1713 794
1714/*
1715 * CS4210 Input MUX (1 ADC)
1716 */
1717static int cs421x_mux_enum_info(struct snd_kcontrol *kcontrol,
1718 struct snd_ctl_elem_info *uinfo)
1719{
1720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1721 struct cs_spec *spec = codec->spec;
1722
1723 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
1724}
1725
1726static int cs421x_mux_enum_get(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol)
1728{
1729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1730 struct cs_spec *spec = codec->spec;
1731
1732 ucontrol->value.enumerated.item[0] = spec->cur_input;
1733 return 0; 795 return 0;
1734} 796}
1735 797
1736static int cs421x_mux_enum_put(struct snd_kcontrol *kcontrol, 798static int cs421x_build_controls(struct hda_codec *codec)
1737 struct snd_ctl_elem_value *ucontrol)
1738{
1739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1740 struct cs_spec *spec = codec->spec;
1741
1742 return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol,
1743 spec->adc_nid[0], &spec->cur_input);
1744
1745}
1746
1747static const struct snd_kcontrol_new cs421x_capture_source = {
1748 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1749 .name = "Capture Source",
1750 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1751 .info = cs421x_mux_enum_info,
1752 .get = cs421x_mux_enum_get,
1753 .put = cs421x_mux_enum_put,
1754};
1755
1756static int cs421x_add_input_volume_control(struct hda_codec *codec, int item)
1757{
1758 struct cs_spec *spec = codec->spec;
1759 struct auto_pin_cfg *cfg = &spec->autocfg;
1760 const struct hda_input_mux *imux = &spec->input_mux;
1761 hda_nid_t pin = cfg->inputs[item].pin;
1762 struct snd_kcontrol *kctl;
1763 u32 caps;
1764
1765 if (!(get_wcaps(codec, pin) & AC_WCAP_IN_AMP))
1766 return 0;
1767
1768 caps = query_amp_caps(codec, pin, HDA_INPUT);
1769 caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
1770 if (caps <= 1)
1771 return 0;
1772
1773 return add_volume(codec, imux->items[item].label, 0,
1774 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT), 1, &kctl);
1775}
1776
1777/* add a (input-boost) volume control to the given input pin */
1778static int build_cs421x_input(struct hda_codec *codec)
1779{
1780 struct cs_spec *spec = codec->spec;
1781 struct auto_pin_cfg *cfg = &spec->autocfg;
1782 struct hda_input_mux *imux = &spec->input_mux;
1783 int i, err, type_idx;
1784 const char *label;
1785
1786 if (!spec->num_inputs)
1787 return 0;
1788
1789 /* make bind-capture */
1790 spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw);
1791 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
1792 for (i = 0; i < 2; i++) {
1793 struct snd_kcontrol *kctl;
1794 int n;
1795 if (!spec->capture_bind[i])
1796 return -ENOMEM;
1797 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
1798 if (!kctl)
1799 return -ENOMEM;
1800 kctl->private_value = (long)spec->capture_bind[i];
1801 err = snd_hda_ctl_add(codec, 0, kctl);
1802 if (err < 0)
1803 return err;
1804 for (n = 0; n < AUTO_PIN_LAST; n++) {
1805 if (!spec->adc_nid[n])
1806 continue;
1807 err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]);
1808 if (err < 0)
1809 return err;
1810 }
1811 }
1812
1813 /* Add Input MUX Items + Capture Volume/Switch */
1814 for (i = 0; i < spec->num_inputs; i++) {
1815 label = hda_get_autocfg_input_label(codec, cfg, i);
1816 snd_hda_add_imux_item(imux, label, spec->adc_idx[i], &type_idx);
1817
1818 err = cs421x_add_input_volume_control(codec, i);
1819 if (err < 0)
1820 return err;
1821 }
1822
1823 /*
1824 Add 'Capture Source' Switch if
1825 * 2 inputs and no mic detec
1826 * 3 inputs
1827 */
1828 if ((spec->num_inputs == 2 && !spec->mic_detect) ||
1829 (spec->num_inputs == 3)) {
1830
1831 err = snd_hda_ctl_add(codec, spec->adc_nid[0],
1832 snd_ctl_new1(&cs421x_capture_source, codec));
1833 if (err < 0)
1834 return err;
1835 }
1836
1837 return 0;
1838}
1839
1840/* Single DAC (Mute/Gain) */
1841static int build_cs421x_output(struct hda_codec *codec)
1842{ 799{
1843 hda_nid_t dac = CS4210_DAC_NID;
1844 struct cs_spec *spec = codec->spec; 800 struct cs_spec *spec = codec->spec;
1845 struct auto_pin_cfg *cfg = &spec->autocfg;
1846 struct snd_kcontrol *kctl;
1847 int err; 801 int err;
1848 char *name = "Master";
1849
1850 fix_volume_caps(codec, dac);
1851 802
1852 err = add_mute(codec, name, 0, 803 err = snd_hda_gen_build_controls(codec);
1853 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
1854 if (err < 0) 804 if (err < 0)
1855 return err; 805 return err;
1856 806
1857 err = add_volume(codec, name, 0, 807 if (spec->gen.autocfg.speaker_outs &&
1858 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); 808 spec->vendor_nid == CS4210_VENDOR_NID) {
1859 if (err < 0)
1860 return err;
1861
1862 if (cfg->speaker_outs && (spec->vendor_nid == CS4210_VENDOR_NID)) {
1863 err = snd_hda_ctl_add(codec, 0, 809 err = snd_hda_ctl_add(codec, 0,
1864 snd_ctl_new1(&cs421x_speaker_bost_ctl, codec)); 810 snd_ctl_new1(&cs421x_speaker_boost_ctl, codec));
1865 if (err < 0) 811 if (err < 0)
1866 return err; 812 return err;
1867 } 813 }
1868 return err;
1869}
1870
1871static int cs421x_build_controls(struct hda_codec *codec)
1872{
1873 struct cs_spec *spec = codec->spec;
1874 int err;
1875
1876 err = build_cs421x_output(codec);
1877 if (err < 0)
1878 return err;
1879 err = build_cs421x_input(codec);
1880 if (err < 0)
1881 return err;
1882 err = build_digital_output(codec);
1883 if (err < 0)
1884 return err;
1885 err = cs421x_init(codec);
1886 if (err < 0)
1887 return err;
1888
1889 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1890 if (err < 0)
1891 return err;
1892
1893 return 0; 814 return 0;
1894} 815}
1895 816
1896static int parse_cs421x_input(struct hda_codec *codec) 817static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
1897{ 818{
1898 struct cs_spec *spec = codec->spec; 819 unsigned int caps;
1899 struct auto_pin_cfg *cfg = &spec->autocfg;
1900 int i;
1901
1902 for (i = 0; i < cfg->num_inputs; i++) {
1903 hda_nid_t pin = cfg->inputs[i].pin;
1904 spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]);
1905 spec->cur_input = spec->last_input = i;
1906 spec->num_inputs++;
1907 820
1908 /* check whether the automatic mic switch is available */ 821 /* set the upper-limit for mixer amp to 0dB */
1909 if (is_ext_mic(codec, i) && cfg->num_inputs >= 2) { 822 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
1910 spec->mic_detect = 1; 823 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
1911 spec->automic_idx = i; 824 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
1912 } 825 << AC_AMPCAP_NUM_STEPS_SHIFT;
1913 } 826 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
1914 return 0;
1915} 827}
1916 828
1917static int cs421x_parse_auto_config(struct hda_codec *codec) 829static int cs421x_parse_auto_config(struct hda_codec *codec)
1918{ 830{
1919 struct cs_spec *spec = codec->spec; 831 struct cs_spec *spec = codec->spec;
832 hda_nid_t dac = CS4210_DAC_NID;
1920 int err; 833 int err;
1921 834
1922 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 835 fix_volume_caps(codec, dac);
1923 if (err < 0) 836
1924 return err; 837 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
1925 err = parse_output(codec);
1926 if (err < 0)
1927 return err;
1928 err = parse_cs421x_input(codec);
1929 if (err < 0) 838 if (err < 0)
1930 return err; 839 return err;
1931 err = parse_digital_output(codec); 840
841 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1932 if (err < 0) 842 if (err < 0)
1933 return err; 843 return err;
844
845 parse_cs421x_digital(codec);
1934 return 0; 846 return 0;
1935} 847}
1936 848
@@ -1963,7 +875,7 @@ static int cs421x_suspend(struct hda_codec *codec)
1963 875
1964static const struct hda_codec_ops cs421x_patch_ops = { 876static const struct hda_codec_ops cs421x_patch_ops = {
1965 .build_controls = cs421x_build_controls, 877 .build_controls = cs421x_build_controls,
1966 .build_pcms = cs_build_pcms, 878 .build_pcms = snd_hda_gen_build_pcms,
1967 .init = cs421x_init, 879 .init = cs421x_init,
1968 .free = cs_free, 880 .free = cs_free,
1969 .unsol_event = snd_hda_jack_unsol_event, 881 .unsol_event = snd_hda_jack_unsol_event,
@@ -1977,13 +889,9 @@ static int patch_cs4210(struct hda_codec *codec)
1977 struct cs_spec *spec; 889 struct cs_spec *spec;
1978 int err; 890 int err;
1979 891
1980 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 892 spec = cs_alloc_spec(codec, CS4210_VENDOR_NID);
1981 if (!spec) 893 if (!spec)
1982 return -ENOMEM; 894 return -ENOMEM;
1983 codec->spec = spec;
1984 snd_hda_gen_init(&spec->gen);
1985
1986 spec->vendor_nid = CS4210_VENDOR_NID;
1987 895
1988 snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl, 896 snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl,
1989 cs421x_fixups); 897 cs421x_fixups);
@@ -2008,7 +916,6 @@ static int patch_cs4210(struct hda_codec *codec)
2008 916
2009 error: 917 error:
2010 cs_free(codec); 918 cs_free(codec);
2011 codec->spec = NULL;
2012 return err; 919 return err;
2013} 920}
2014 921
@@ -2017,13 +924,9 @@ static int patch_cs4213(struct hda_codec *codec)
2017 struct cs_spec *spec; 924 struct cs_spec *spec;
2018 int err; 925 int err;
2019 926
2020 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 927 spec = cs_alloc_spec(codec, CS4213_VENDOR_NID);
2021 if (!spec) 928 if (!spec)
2022 return -ENOMEM; 929 return -ENOMEM;
2023 codec->spec = spec;
2024 snd_hda_gen_init(&spec->gen);
2025
2026 spec->vendor_nid = CS4213_VENDOR_NID;
2027 930
2028 err = cs421x_parse_auto_config(codec); 931 err = cs421x_parse_auto_config(codec);
2029 if (err < 0) 932 if (err < 0)
@@ -2034,7 +937,6 @@ static int patch_cs4213(struct hda_codec *codec)
2034 937
2035 error: 938 error:
2036 cs_free(codec); 939 cs_free(codec);
2037 codec->spec = NULL;
2038 return err; 940 return err;
2039} 941}
2040 942
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index c8fdaaefe702..9c6ce73b03c5 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -22,7 +22,6 @@
22 */ 22 */
23 23
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27#include <linux/pci.h> 26#include <linux/pci.h>
28#include <linux/module.h> 27#include <linux/module.h>
@@ -30,6 +29,9 @@
30#include "hda_codec.h" 29#include "hda_codec.h"
31#include "hda_local.h" 30#include "hda_local.h"
32#include "hda_auto_parser.h" 31#include "hda_auto_parser.h"
32#include "hda_jack.h"
33#include "hda_generic.h"
34
33#define NUM_PINS 11 35#define NUM_PINS 11
34 36
35 37
@@ -45,6 +47,10 @@ enum {
45}; 47};
46 48
47struct cmi_spec { 49struct cmi_spec {
50 struct hda_gen_spec gen;
51
52 /* below are only for static models */
53
48 int board_config; 54 int board_config;
49 unsigned int no_line_in: 1; /* no line-in (5-jack) */ 55 unsigned int no_line_in: 1; /* no line-in (5-jack) */
50 unsigned int front_panel: 1; /* has front-panel 2-jack */ 56 unsigned int front_panel: 1; /* has front-panel 2-jack */
@@ -356,77 +362,6 @@ static int cmi9880_build_controls(struct hda_codec *codec)
356 return 0; 362 return 0;
357} 363}
358 364
359/* fill in the multi_dac_nids table, which will decide
360 which audio widget to use for each channel */
361static int cmi9880_fill_multi_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
362{
363 struct cmi_spec *spec = codec->spec;
364 hda_nid_t nid;
365 int assigned[4];
366 int i, j;
367
368 /* clear the table, only one c-media dac assumed here */
369 memset(spec->dac_nids, 0, sizeof(spec->dac_nids));
370 memset(assigned, 0, sizeof(assigned));
371 /* check the pins we found */
372 for (i = 0; i < cfg->line_outs; i++) {
373 nid = cfg->line_out_pins[i];
374 /* nid 0x0b~0x0e is hardwired to audio widget 0x3~0x6 */
375 if (nid >= 0x0b && nid <= 0x0e) {
376 spec->dac_nids[i] = (nid - 0x0b) + 0x03;
377 assigned[nid - 0x0b] = 1;
378 }
379 }
380 /* left pin can be connect to any audio widget */
381 for (i = 0; i < cfg->line_outs; i++) {
382 nid = cfg->line_out_pins[i];
383 if (nid <= 0x0e)
384 continue;
385 /* search for an empty channel */
386 for (j = 0; j < cfg->line_outs; j++) {
387 if (! assigned[j]) {
388 spec->dac_nids[i] = j + 0x03;
389 assigned[j] = 1;
390 break;
391 }
392 }
393 }
394 spec->num_dacs = cfg->line_outs;
395 return 0;
396}
397
398/* create multi_init table, which is used for multichannel initialization */
399static int cmi9880_fill_multi_init(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
400{
401 struct cmi_spec *spec = codec->spec;
402 hda_nid_t nid;
403 int i, j, k;
404
405 /* clear the table, only one c-media dac assumed here */
406 memset(spec->multi_init, 0, sizeof(spec->multi_init));
407 for (j = 0, i = 0; i < cfg->line_outs; i++) {
408 nid = cfg->line_out_pins[i];
409 /* set as output */
410 spec->multi_init[j].nid = nid;
411 spec->multi_init[j].verb = AC_VERB_SET_PIN_WIDGET_CONTROL;
412 spec->multi_init[j].param = PIN_OUT;
413 j++;
414 if (nid > 0x0e) {
415 /* set connection */
416 spec->multi_init[j].nid = nid;
417 spec->multi_init[j].verb = AC_VERB_SET_CONNECT_SEL;
418 spec->multi_init[j].param = 0;
419 /* find the index in connect list */
420 k = snd_hda_get_conn_index(codec, nid,
421 spec->dac_nids[i], 0);
422 if (k >= 0)
423 spec->multi_init[j].param = k;
424 j++;
425 }
426 }
427 return 0;
428}
429
430static int cmi9880_init(struct hda_codec *codec) 365static int cmi9880_init(struct hda_codec *codec)
431{ 366{
432 struct cmi_spec *spec = codec->spec; 367 struct cmi_spec *spec = codec->spec;
@@ -632,6 +567,36 @@ static const struct hda_codec_ops cmi9880_patch_ops = {
632 .free = cmi9880_free, 567 .free = cmi9880_free,
633}; 568};
634 569
570/*
571 * stuff for auto-parser
572 */
573static const struct hda_codec_ops cmi_auto_patch_ops = {
574 .build_controls = snd_hda_gen_build_controls,
575 .build_pcms = snd_hda_gen_build_pcms,
576 .init = snd_hda_gen_init,
577 .free = snd_hda_gen_free,
578 .unsol_event = snd_hda_jack_unsol_event,
579};
580
581static int cmi_parse_auto_config(struct hda_codec *codec)
582{
583 struct cmi_spec *spec = codec->spec;
584 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
585 int err;
586
587 snd_hda_gen_spec_init(&spec->gen);
588
589 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
590 if (err < 0)
591 return err;
592 err = snd_hda_gen_parse_auto_config(codec, cfg);
593 if (err < 0)
594 return err;
595
596 codec->patch_ops = cmi_auto_patch_ops;
597 return 0;
598}
599
635static int patch_cmi9880(struct hda_codec *codec) 600static int patch_cmi9880(struct hda_codec *codec)
636{ 601{
637 struct cmi_spec *spec; 602 struct cmi_spec *spec;
@@ -650,6 +615,15 @@ static int patch_cmi9880(struct hda_codec *codec)
650 spec->board_config = CMI_AUTO; /* try everything */ 615 spec->board_config = CMI_AUTO; /* try everything */
651 } 616 }
652 617
618 if (spec->board_config == CMI_AUTO) {
619 int err = cmi_parse_auto_config(codec);
620 if (err < 0) {
621 snd_hda_gen_free(codec);
622 return err;
623 }
624 return 0;
625 }
626
653 /* copy default DAC NIDs */ 627 /* copy default DAC NIDs */
654 memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids)); 628 memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids));
655 spec->num_dacs = 4; 629 spec->num_dacs = 4;
@@ -678,59 +652,13 @@ static int patch_cmi9880(struct hda_codec *codec)
678 } 652 }
679 break; 653 break;
680 case CMI_ALLOUT: 654 case CMI_ALLOUT:
655 default:
681 spec->front_panel = 1; 656 spec->front_panel = 1;
682 spec->multiout.max_channels = 8; 657 spec->multiout.max_channels = 8;
683 spec->no_line_in = 1; 658 spec->no_line_in = 1;
684 spec->input_mux = &cmi9880_no_line_mux; 659 spec->input_mux = &cmi9880_no_line_mux;
685 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID; 660 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
686 break; 661 break;
687 case CMI_AUTO:
688 {
689 unsigned int port_e, port_f, port_g, port_h;
690 unsigned int port_spdifi, port_spdifo;
691 struct auto_pin_cfg cfg;
692
693 /* collect pin default configuration */
694 port_e = snd_hda_codec_get_pincfg(codec, 0x0f);
695 port_f = snd_hda_codec_get_pincfg(codec, 0x10);
696 spec->front_panel = 1;
697 if (get_defcfg_connect(port_e) == AC_JACK_PORT_NONE ||
698 get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) {
699 port_g = snd_hda_codec_get_pincfg(codec, 0x1f);
700 port_h = snd_hda_codec_get_pincfg(codec, 0x20);
701 spec->channel_modes = cmi9880_channel_modes;
702 /* no front panel */
703 if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE ||
704 get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) {
705 /* no optional rear panel */
706 spec->board_config = CMI_MINIMAL;
707 spec->front_panel = 0;
708 spec->num_channel_modes = 2;
709 } else {
710 spec->board_config = CMI_MIN_FP;
711 spec->num_channel_modes = 3;
712 }
713 spec->input_mux = &cmi9880_basic_mux;
714 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
715 } else {
716 spec->input_mux = &cmi9880_basic_mux;
717 port_spdifi = snd_hda_codec_get_pincfg(codec, 0x13);
718 port_spdifo = snd_hda_codec_get_pincfg(codec, 0x12);
719 if (get_defcfg_connect(port_spdifo) != AC_JACK_PORT_NONE)
720 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
721 if (get_defcfg_connect(port_spdifi) != AC_JACK_PORT_NONE)
722 spec->dig_in_nid = CMI_DIG_IN_NID;
723 spec->multiout.max_channels = 8;
724 }
725 snd_hda_parse_pin_def_config(codec, &cfg, NULL);
726 if (cfg.line_outs) {
727 spec->multiout.max_channels = cfg.line_outs * 2;
728 cmi9880_fill_multi_dac_nids(codec, &cfg);
729 cmi9880_fill_multi_init(codec, &cfg);
730 } else
731 snd_printd("patch_cmedia: cannot detect association in defcfg\n");
732 break;
733 }
734 } 662 }
735 663
736 spec->multiout.num_dacs = spec->num_dacs; 664 spec->multiout.num_dacs = spec->num_dacs;
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 009b77a693cf..941bf6c766ec 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -33,6 +33,9 @@
33#include "hda_auto_parser.h" 33#include "hda_auto_parser.h"
34#include "hda_beep.h" 34#include "hda_beep.h"
35#include "hda_jack.h" 35#include "hda_jack.h"
36#include "hda_generic.h"
37
38#define ENABLE_CXT_STATIC_QUIRKS
36 39
37#define CXT_PIN_DIR_IN 0x00 40#define CXT_PIN_DIR_IN 0x00
38#define CXT_PIN_DIR_OUT 0x01 41#define CXT_PIN_DIR_OUT 0x01
@@ -53,27 +56,19 @@
53#define AUTO_MIC_PORTB (1 << 1) 56#define AUTO_MIC_PORTB (1 << 1)
54#define AUTO_MIC_PORTC (1 << 2) 57#define AUTO_MIC_PORTC (1 << 2)
55 58
56struct pin_dac_pair {
57 hda_nid_t pin;
58 hda_nid_t dac;
59 int type;
60};
61
62struct imux_info {
63 hda_nid_t pin; /* input pin NID */
64 hda_nid_t adc; /* connected ADC NID */
65 hda_nid_t boost; /* optional boost volume NID */
66 int index; /* corresponding to autocfg.input */
67};
68
69struct conexant_spec { 59struct conexant_spec {
70 struct hda_gen_spec gen; 60 struct hda_gen_spec gen;
71 61
62 unsigned int beep_amp;
63
64 /* extra EAPD pins */
65 unsigned int num_eapds;
66 hda_nid_t eapds[4];
67
68#ifdef ENABLE_CXT_STATIC_QUIRKS
72 const struct snd_kcontrol_new *mixers[5]; 69 const struct snd_kcontrol_new *mixers[5];
73 int num_mixers; 70 int num_mixers;
74 hda_nid_t vmaster_nid; 71 hda_nid_t vmaster_nid;
75 struct hda_vmaster_mute_hook vmaster_mute;
76 bool vmaster_mute_led;
77 72
78 const struct hda_verb *init_verbs[5]; /* initialization verbs 73 const struct hda_verb *init_verbs[5]; /* initialization verbs
79 * don't forget NULL 74 * don't forget NULL
@@ -90,11 +85,6 @@ struct conexant_spec {
90 unsigned int hp_present; 85 unsigned int hp_present;
91 unsigned int line_present; 86 unsigned int line_present;
92 unsigned int auto_mic; 87 unsigned int auto_mic;
93 int auto_mic_ext; /* imux_pins[] index for ext mic */
94 int auto_mic_dock; /* imux_pins[] index for dock mic */
95 int auto_mic_int; /* imux_pins[] index for int mic */
96 unsigned int need_dac_fix;
97 hda_nid_t slave_dig_outs[2];
98 88
99 /* capture */ 89 /* capture */
100 unsigned int num_adc_nids; 90 unsigned int num_adc_nids;
@@ -122,30 +112,13 @@ struct conexant_spec {
122 112
123 unsigned int spdif_route; 113 unsigned int spdif_route;
124 114
125 /* dynamic controls, init_verbs and input_mux */
126 struct auto_pin_cfg autocfg;
127 struct hda_input_mux private_imux;
128 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
129 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
130 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
131 struct pin_dac_pair dac_info[8];
132 int dac_info_filled;
133
134 unsigned int port_d_mode; 115 unsigned int port_d_mode;
135 unsigned int auto_mute:1; /* used in auto-parser */
136 unsigned int detect_line:1; /* Line-out detection enabled */
137 unsigned int automute_lines:1; /* automute line-out as well */
138 unsigned int automute_hp_lo:1; /* both HP and LO available */
139 unsigned int dell_automute:1; 116 unsigned int dell_automute:1;
140 unsigned int dell_vostro:1; 117 unsigned int dell_vostro:1;
141 unsigned int ideapad:1; 118 unsigned int ideapad:1;
142 unsigned int thinkpad:1; 119 unsigned int thinkpad:1;
143 unsigned int hp_laptop:1; 120 unsigned int hp_laptop:1;
144 unsigned int asus:1; 121 unsigned int asus:1;
145 unsigned int pin_eapd_ctrls:1;
146 unsigned int fixup_stereo_dmic:1;
147
148 unsigned int adc_switching:1;
149 122
150 unsigned int ext_mic_present; 123 unsigned int ext_mic_present;
151 unsigned int recording; 124 unsigned int recording;
@@ -161,14 +134,48 @@ struct conexant_spec {
161 unsigned int dc_enable; 134 unsigned int dc_enable;
162 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 135 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
163 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 136 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
137#endif /* ENABLE_CXT_STATIC_QUIRKS */
138};
164 139
165 unsigned int beep_amp;
166 140
167 /* extra EAPD pins */ 141#ifdef CONFIG_SND_HDA_INPUT_BEEP
168 unsigned int num_eapds; 142#define set_beep_amp(spec, nid, idx, dir) \
169 hda_nid_t eapds[4]; 143 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
144/* additional beep mixers; the actual parameters are overwritten at build */
145static const struct snd_kcontrol_new cxt_beep_mixer[] = {
146 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
147 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
148 { } /* end */
170}; 149};
171 150
151/* create beep controls if needed */
152static int add_beep_ctls(struct hda_codec *codec)
153{
154 struct conexant_spec *spec = codec->spec;
155 int err;
156
157 if (spec->beep_amp) {
158 const struct snd_kcontrol_new *knew;
159 for (knew = cxt_beep_mixer; knew->name; knew++) {
160 struct snd_kcontrol *kctl;
161 kctl = snd_ctl_new1(knew, codec);
162 if (!kctl)
163 return -ENOMEM;
164 kctl->private_value = spec->beep_amp;
165 err = snd_hda_ctl_add(codec, 0, kctl);
166 if (err < 0)
167 return err;
168 }
169 }
170 return 0;
171}
172#else
173#define set_beep_amp(spec, nid, idx, dir) /* NOP */
174#define add_beep_ctls(codec) 0
175#endif
176
177
178#ifdef ENABLE_CXT_STATIC_QUIRKS
172static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 179static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
173 struct hda_codec *codec, 180 struct hda_codec *codec,
174 struct snd_pcm_substream *substream) 181 struct snd_pcm_substream *substream)
@@ -337,8 +344,6 @@ static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
337 }, 344 },
338}; 345};
339 346
340static bool is_2_1_speaker(struct conexant_spec *spec);
341
342static int conexant_build_pcms(struct hda_codec *codec) 347static int conexant_build_pcms(struct hda_codec *codec)
343{ 348{
344 struct conexant_spec *spec = codec->spec; 349 struct conexant_spec *spec = codec->spec;
@@ -353,9 +358,6 @@ static int conexant_build_pcms(struct hda_codec *codec)
353 spec->multiout.max_channels; 358 spec->multiout.max_channels;
354 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
355 spec->multiout.dac_nids[0]; 360 spec->multiout.dac_nids[0];
356 if (is_2_1_speaker(spec))
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
358 snd_pcm_2_1_chmaps;
359 if (spec->capture_stream) 361 if (spec->capture_stream)
360 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; 362 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
361 else { 363 else {
@@ -386,8 +388,6 @@ static int conexant_build_pcms(struct hda_codec *codec)
386 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 388 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
387 spec->dig_in_nid; 389 spec->dig_in_nid;
388 } 390 }
389 if (spec->slave_dig_outs[0])
390 codec->slave_dig_outs = spec->slave_dig_outs;
391 } 391 }
392 392
393 return 0; 393 return 0;
@@ -435,7 +435,7 @@ static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
435 /* partial workaround for "azx_get_response timeout" */ 435 /* partial workaround for "azx_get_response timeout" */
436 if (power_state == AC_PWRST_D0) 436 if (power_state == AC_PWRST_D0)
437 msleep(10); 437 msleep(10);
438 snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 438 snd_hda_codec_set_power_to_all(codec, fg, power_state);
439} 439}
440 440
441static int conexant_init(struct hda_codec *codec) 441static int conexant_init(struct hda_codec *codec)
@@ -451,7 +451,6 @@ static int conexant_init(struct hda_codec *codec)
451static void conexant_free(struct hda_codec *codec) 451static void conexant_free(struct hda_codec *codec)
452{ 452{
453 struct conexant_spec *spec = codec->spec; 453 struct conexant_spec *spec = codec->spec;
454 snd_hda_gen_free(&spec->gen);
455 snd_hda_detach_beep_device(codec); 454 snd_hda_detach_beep_device(codec);
456 kfree(spec); 455 kfree(spec);
457} 456}
@@ -467,15 +466,6 @@ static const struct snd_kcontrol_new cxt_capture_mixers[] = {
467 {} 466 {}
468}; 467};
469 468
470#ifdef CONFIG_SND_HDA_INPUT_BEEP
471/* additional beep mixers; the actual parameters are overwritten at build */
472static const struct snd_kcontrol_new cxt_beep_mixer[] = {
473 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
474 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
475 { } /* end */
476};
477#endif
478
479static const char * const slave_pfxs[] = { 469static const char * const slave_pfxs[] = {
480 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE", 470 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
481 NULL 471 NULL
@@ -524,10 +514,9 @@ static int conexant_build_controls(struct hda_codec *codec)
524 } 514 }
525 if (spec->vmaster_nid && 515 if (spec->vmaster_nid &&
526 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 516 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
527 err = __snd_hda_add_vmaster(codec, "Master Playback Switch", 517 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
528 NULL, slave_pfxs, 518 NULL, slave_pfxs,
529 "Playback Switch", true, 519 "Playback Switch");
530 &spec->vmaster_mute.sw_kctl);
531 if (err < 0) 520 if (err < 0)
532 return err; 521 return err;
533 } 522 }
@@ -538,22 +527,9 @@ static int conexant_build_controls(struct hda_codec *codec)
538 return err; 527 return err;
539 } 528 }
540 529
541#ifdef CONFIG_SND_HDA_INPUT_BEEP 530 err = add_beep_ctls(codec);
542 /* create beep controls if needed */ 531 if (err < 0)
543 if (spec->beep_amp) { 532 return err;
544 const struct snd_kcontrol_new *knew;
545 for (knew = cxt_beep_mixer; knew->name; knew++) {
546 struct snd_kcontrol *kctl;
547 kctl = snd_ctl_new1(knew, codec);
548 if (!kctl)
549 return -ENOMEM;
550 kctl->private_value = spec->beep_amp;
551 err = snd_hda_ctl_add(codec, 0, kctl);
552 if (err < 0)
553 return err;
554 }
555 }
556#endif
557 533
558 return 0; 534 return 0;
559} 535}
@@ -566,13 +542,6 @@ static const struct hda_codec_ops conexant_patch_ops = {
566 .set_power_state = conexant_set_power, 542 .set_power_state = conexant_set_power,
567}; 543};
568 544
569#ifdef CONFIG_SND_HDA_INPUT_BEEP
570#define set_beep_amp(spec, nid, idx, dir) \
571 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
572#else
573#define set_beep_amp(spec, nid, idx, dir) /* NOP */
574#endif
575
576static int patch_conexant_auto(struct hda_codec *codec); 545static int patch_conexant_auto(struct hda_codec *codec);
577/* 546/*
578 * EAPD control 547 * EAPD control
@@ -656,8 +625,6 @@ static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
656 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 625 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
657 spec->num_channel_mode, 626 spec->num_channel_mode,
658 &spec->multiout.max_channels); 627 &spec->multiout.max_channels);
659 if (err >= 0 && spec->need_dac_fix)
660 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
661 return err; 628 return err;
662} 629}
663 630
@@ -2496,10 +2463,6 @@ static void conexant_check_dig_outs(struct hda_codec *codec,
2496 continue; 2463 continue;
2497 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2464 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2498 continue; 2465 continue;
2499 if (spec->slave_dig_outs[0])
2500 nid_loc++;
2501 else
2502 nid_loc = spec->slave_dig_outs;
2503 } 2466 }
2504} 2467}
2505 2468
@@ -3141,626 +3104,12 @@ static int patch_cxt5066(struct hda_codec *codec)
3141 return 0; 3104 return 0;
3142} 3105}
3143 3106
3144/* 3107#endif /* ENABLE_CXT_STATIC_QUIRKS */
3145 * Automatic parser for CX20641 & co
3146 */
3147 3108
3148static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3149 struct hda_codec *codec,
3150 unsigned int stream_tag,
3151 unsigned int format,
3152 struct snd_pcm_substream *substream)
3153{
3154 struct conexant_spec *spec = codec->spec;
3155 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
3156 if (spec->adc_switching) {
3157 spec->cur_adc = adc;
3158 spec->cur_adc_stream_tag = stream_tag;
3159 spec->cur_adc_format = format;
3160 }
3161 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3162 return 0;
3163}
3164
3165static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3166 struct hda_codec *codec,
3167 struct snd_pcm_substream *substream)
3168{
3169 struct conexant_spec *spec = codec->spec;
3170 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3171 spec->cur_adc = 0;
3172 return 0;
3173}
3174
3175static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3176 .substreams = 1,
3177 .channels_min = 2,
3178 .channels_max = 2,
3179 .nid = 0, /* fill later */
3180 .ops = {
3181 .prepare = cx_auto_capture_pcm_prepare,
3182 .cleanup = cx_auto_capture_pcm_cleanup
3183 },
3184};
3185
3186static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3187
3188#define get_connection_index(codec, mux, nid)\
3189 snd_hda_get_conn_index(codec, mux, nid, 0)
3190
3191/* get an unassigned DAC from the given list.
3192 * Return the nid if found and reduce the DAC list, or return zero if
3193 * not found
3194 */
3195static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3196 hda_nid_t *dacs, int *num_dacs)
3197{
3198 int i, nums = *num_dacs;
3199 hda_nid_t ret = 0;
3200
3201 for (i = 0; i < nums; i++) {
3202 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3203 ret = dacs[i];
3204 break;
3205 }
3206 }
3207 if (!ret)
3208 return 0;
3209 if (--nums > 0)
3210 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3211 *num_dacs = nums;
3212 return ret;
3213}
3214
3215#define MAX_AUTO_DACS 5
3216
3217#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3218
3219/* fill analog DAC list from the widget tree */
3220static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3221{
3222 hda_nid_t nid, end_nid;
3223 int nums = 0;
3224
3225 end_nid = codec->start_nid + codec->num_nodes;
3226 for (nid = codec->start_nid; nid < end_nid; nid++) {
3227 unsigned int wcaps = get_wcaps(codec, nid);
3228 unsigned int type = get_wcaps_type(wcaps);
3229 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3230 dacs[nums++] = nid;
3231 if (nums >= MAX_AUTO_DACS)
3232 break;
3233 }
3234 }
3235 return nums;
3236}
3237
3238/* fill pin_dac_pair list from the pin and dac list */
3239static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3240 int num_pins, hda_nid_t *dacs, int *rest,
3241 struct pin_dac_pair *filled, int nums,
3242 int type)
3243{
3244 int i, start = nums;
3245
3246 for (i = 0; i < num_pins; i++, nums++) {
3247 filled[nums].pin = pins[i];
3248 filled[nums].type = type;
3249 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3250 if (filled[nums].dac)
3251 continue;
3252 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3253 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3254 continue;
3255 }
3256 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
3257 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
3258 continue;
3259 }
3260 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
3261 }
3262 return nums;
3263}
3264
3265/* parse analog output paths */
3266static void cx_auto_parse_output(struct hda_codec *codec)
3267{
3268 struct conexant_spec *spec = codec->spec;
3269 struct auto_pin_cfg *cfg = &spec->autocfg;
3270 hda_nid_t dacs[MAX_AUTO_DACS];
3271 int i, j, nums, rest;
3272
3273 rest = fill_cx_auto_dacs(codec, dacs);
3274 /* parse all analog output pins */
3275 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3276 dacs, &rest, spec->dac_info, 0,
3277 AUTO_PIN_LINE_OUT);
3278 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3279 dacs, &rest, spec->dac_info, nums,
3280 AUTO_PIN_HP_OUT);
3281 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3282 dacs, &rest, spec->dac_info, nums,
3283 AUTO_PIN_SPEAKER_OUT);
3284 spec->dac_info_filled = nums;
3285 /* fill multiout struct */
3286 for (i = 0; i < nums; i++) {
3287 hda_nid_t dac = spec->dac_info[i].dac;
3288 if (!dac || (dac & DAC_SLAVE_FLAG))
3289 continue;
3290 switch (spec->dac_info[i].type) {
3291 case AUTO_PIN_LINE_OUT:
3292 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3293 spec->multiout.num_dacs++;
3294 break;
3295 case AUTO_PIN_HP_OUT:
3296 case AUTO_PIN_SPEAKER_OUT:
3297 if (!spec->multiout.hp_nid) {
3298 spec->multiout.hp_nid = dac;
3299 break;
3300 }
3301 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3302 if (!spec->multiout.extra_out_nid[j]) {
3303 spec->multiout.extra_out_nid[j] = dac;
3304 break;
3305 }
3306 break;
3307 }
3308 }
3309 spec->multiout.dac_nids = spec->private_dac_nids;
3310 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3311
3312 for (i = 0; i < cfg->hp_outs; i++) {
3313 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3314 spec->auto_mute = 1;
3315 break;
3316 }
3317 }
3318 if (spec->auto_mute &&
3319 cfg->line_out_pins[0] &&
3320 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
3321 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3322 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3323 for (i = 0; i < cfg->line_outs; i++) {
3324 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3325 spec->detect_line = 1;
3326 break;
3327 }
3328 }
3329 spec->automute_lines = spec->detect_line;
3330 }
3331
3332 spec->vmaster_nid = spec->private_dac_nids[0];
3333}
3334
3335static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3336 hda_nid_t *pins, bool on);
3337
3338static void do_automute(struct hda_codec *codec, int num_pins,
3339 hda_nid_t *pins, bool on)
3340{
3341 struct conexant_spec *spec = codec->spec;
3342 int i;
3343 for (i = 0; i < num_pins; i++)
3344 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
3345 if (spec->pin_eapd_ctrls)
3346 cx_auto_turn_eapd(codec, num_pins, pins, on);
3347}
3348
3349static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3350{
3351 int i, present = 0;
3352
3353 for (i = 0; i < num_pins; i++) {
3354 hda_nid_t nid = pins[i];
3355 if (!nid || !is_jack_detectable(codec, nid))
3356 break;
3357 present |= snd_hda_jack_detect(codec, nid);
3358 }
3359 return present;
3360}
3361
3362/* auto-mute/unmute speaker and line outs according to headphone jack */
3363static void cx_auto_update_speakers(struct hda_codec *codec)
3364{
3365 struct conexant_spec *spec = codec->spec;
3366 struct auto_pin_cfg *cfg = &spec->autocfg;
3367 int on = 1;
3368
3369 /* turn on HP EAPD when HP jacks are present */
3370 if (spec->pin_eapd_ctrls) {
3371 if (spec->auto_mute)
3372 on = spec->hp_present;
3373 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3374 }
3375
3376 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3377 if (spec->auto_mute)
3378 on = !(spec->hp_present ||
3379 (spec->detect_line && spec->line_present));
3380 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
3381
3382 /* toggle line-out mutes if needed, too */
3383 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3384 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3385 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3386 return;
3387 if (spec->auto_mute) {
3388 /* mute LO in auto-mode when HP jack is present */
3389 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3390 spec->automute_lines)
3391 on = !spec->hp_present;
3392 else
3393 on = 1;
3394 }
3395 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
3396}
3397
3398static void cx_auto_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3399{
3400 struct conexant_spec *spec = codec->spec;
3401 struct auto_pin_cfg *cfg = &spec->autocfg;
3402
3403 if (!spec->auto_mute)
3404 return;
3405 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3406 cx_auto_update_speakers(codec);
3407}
3408
3409static void cx_auto_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3410{
3411 struct conexant_spec *spec = codec->spec;
3412 struct auto_pin_cfg *cfg = &spec->autocfg;
3413
3414 if (!spec->auto_mute || !spec->detect_line)
3415 return;
3416 spec->line_present = detect_jacks(codec, cfg->line_outs,
3417 cfg->line_out_pins);
3418 cx_auto_update_speakers(codec);
3419}
3420
3421static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3422 struct snd_ctl_elem_info *uinfo)
3423{
3424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3425 struct conexant_spec *spec = codec->spec;
3426 static const char * const texts3[] = {
3427 "Disabled", "Speaker Only", "Line Out+Speaker"
3428 };
3429
3430 if (spec->automute_hp_lo)
3431 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
3432 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
3433}
3434
3435static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3436 struct snd_ctl_elem_value *ucontrol)
3437{
3438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3439 struct conexant_spec *spec = codec->spec;
3440 unsigned int val;
3441 if (!spec->auto_mute)
3442 val = 0;
3443 else if (!spec->automute_lines)
3444 val = 1;
3445 else
3446 val = 2;
3447 ucontrol->value.enumerated.item[0] = val;
3448 return 0;
3449}
3450
3451static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3452 struct snd_ctl_elem_value *ucontrol)
3453{
3454 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3455 struct conexant_spec *spec = codec->spec;
3456
3457 switch (ucontrol->value.enumerated.item[0]) {
3458 case 0:
3459 if (!spec->auto_mute)
3460 return 0;
3461 spec->auto_mute = 0;
3462 break;
3463 case 1:
3464 if (spec->auto_mute && !spec->automute_lines)
3465 return 0;
3466 spec->auto_mute = 1;
3467 spec->automute_lines = 0;
3468 break;
3469 case 2:
3470 if (!spec->automute_hp_lo)
3471 return -EINVAL;
3472 if (spec->auto_mute && spec->automute_lines)
3473 return 0;
3474 spec->auto_mute = 1;
3475 spec->automute_lines = 1;
3476 break;
3477 default:
3478 return -EINVAL;
3479 }
3480 cx_auto_update_speakers(codec);
3481 return 1;
3482}
3483
3484static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3485 {
3486 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3487 .name = "Auto-Mute Mode",
3488 .info = cx_automute_mode_info,
3489 .get = cx_automute_mode_get,
3490 .put = cx_automute_mode_put,
3491 },
3492 { }
3493};
3494
3495static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3496 struct snd_ctl_elem_info *uinfo)
3497{
3498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3499 struct conexant_spec *spec = codec->spec;
3500
3501 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3502}
3503
3504static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3505 struct snd_ctl_elem_value *ucontrol)
3506{
3507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3508 struct conexant_spec *spec = codec->spec;
3509
3510 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3511 return 0;
3512}
3513
3514/* look for the route the given pin from mux and return the index;
3515 * if do_select is set, actually select the route.
3516 */
3517static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3518 hda_nid_t pin, hda_nid_t *srcp,
3519 bool do_select, int depth)
3520{
3521 struct conexant_spec *spec = codec->spec;
3522 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3523 int startidx, i, nums;
3524
3525 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3526 case AC_WID_AUD_IN:
3527 case AC_WID_AUD_SEL:
3528 case AC_WID_AUD_MIX:
3529 break;
3530 default:
3531 return -1;
3532 }
3533
3534 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3535 for (i = 0; i < nums; i++)
3536 if (conn[i] == pin) {
3537 if (do_select)
3538 snd_hda_codec_write(codec, mux, 0,
3539 AC_VERB_SET_CONNECT_SEL, i);
3540 if (srcp)
3541 *srcp = mux;
3542 return i;
3543 }
3544 depth++;
3545 if (depth == 2)
3546 return -1;
3547
3548 /* Try to rotate around connections to avoid one boost controlling
3549 another input path as well */
3550 startidx = 0;
3551 for (i = 0; i < spec->private_imux.num_items; i++)
3552 if (spec->imux_info[i].pin == pin) {
3553 startidx = i;
3554 break;
3555 }
3556
3557 for (i = 0; i < nums; i++) {
3558 int j = (i + startidx) % nums;
3559 int ret = __select_input_connection(codec, conn[j], pin, srcp,
3560 do_select, depth);
3561 if (ret >= 0) {
3562 if (do_select)
3563 snd_hda_codec_write(codec, mux, 0,
3564 AC_VERB_SET_CONNECT_SEL, j);
3565 return j;
3566 }
3567 }
3568 return -1;
3569}
3570
3571static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3572 hda_nid_t pin)
3573{
3574 __select_input_connection(codec, mux, pin, NULL, true, 0);
3575}
3576
3577static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3578 hda_nid_t pin)
3579{
3580 return __select_input_connection(codec, mux, pin, NULL, false, 0);
3581}
3582
3583static int cx_auto_mux_enum_update(struct hda_codec *codec,
3584 const struct hda_input_mux *imux,
3585 unsigned int idx)
3586{
3587 struct conexant_spec *spec = codec->spec;
3588 hda_nid_t adc;
3589 int changed = 1;
3590
3591 if (!imux->num_items)
3592 return 0;
3593 if (idx >= imux->num_items)
3594 idx = imux->num_items - 1;
3595 if (spec->cur_mux[0] == idx)
3596 changed = 0;
3597 adc = spec->imux_info[idx].adc;
3598 select_input_connection(codec, spec->imux_info[idx].adc,
3599 spec->imux_info[idx].pin);
3600 if (spec->cur_adc && spec->cur_adc != adc) {
3601 /* stream is running, let's swap the current ADC */
3602 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3603 spec->cur_adc = adc;
3604 snd_hda_codec_setup_stream(codec, adc,
3605 spec->cur_adc_stream_tag, 0,
3606 spec->cur_adc_format);
3607 }
3608 spec->cur_mux[0] = idx;
3609 return changed;
3610}
3611 3109
3612static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 3110/*
3613 struct snd_ctl_elem_value *ucontrol) 3111 * Automatic parser for CX20641 & co
3614{
3615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3616 struct conexant_spec *spec = codec->spec;
3617
3618 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3619 ucontrol->value.enumerated.item[0]);
3620}
3621
3622static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3623 {
3624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3625 .name = "Capture Source",
3626 .info = cx_auto_mux_enum_info,
3627 .get = cx_auto_mux_enum_get,
3628 .put = cx_auto_mux_enum_put
3629 },
3630 {}
3631};
3632
3633static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3634{
3635 struct conexant_spec *spec = codec->spec;
3636 if (idx < 0)
3637 return false;
3638 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3639 return false;
3640 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3641 return true;
3642}
3643
3644/* automatic switch internal and external mic */
3645static void cx_auto_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
3646{
3647 struct conexant_spec *spec = codec->spec;
3648
3649 if (!spec->auto_mic)
3650 return;
3651 if (!select_automic(codec, spec->auto_mic_ext, true))
3652 if (!select_automic(codec, spec->auto_mic_dock, true))
3653 select_automic(codec, spec->auto_mic_int, false);
3654}
3655
3656/* check whether the pin config is suitable for auto-mic switching;
3657 * auto-mic is enabled only when one int-mic and one ext- and/or
3658 * one dock-mic exist
3659 */ 3112 */
3660static void cx_auto_check_auto_mic(struct hda_codec *codec)
3661{
3662 struct conexant_spec *spec = codec->spec;
3663 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3664 int i;
3665
3666 for (i = 0; i < ARRAY_SIZE(pset); i++)
3667 pset[i] = -1;
3668 for (i = 0; i < spec->private_imux.num_items; i++) {
3669 hda_nid_t pin = spec->imux_info[i].pin;
3670 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3671 int type, attr;
3672 attr = snd_hda_get_input_pin_attr(def_conf);
3673 if (attr == INPUT_PIN_ATTR_UNUSED)
3674 return; /* invalid entry */
3675 if (attr > INPUT_PIN_ATTR_NORMAL)
3676 attr = INPUT_PIN_ATTR_NORMAL;
3677 if (attr != INPUT_PIN_ATTR_INT &&
3678 !is_jack_detectable(codec, pin))
3679 return; /* non-detectable pin */
3680 type = get_defcfg_device(def_conf);
3681 if (type != AC_JACK_MIC_IN &&
3682 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3683 return; /* no valid input type */
3684 if (pset[attr] >= 0)
3685 return; /* already occupied */
3686 pset[attr] = i;
3687 }
3688 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3689 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3690 return; /* no input to switch*/
3691 spec->auto_mic = 1;
3692 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3693 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3694 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
3695}
3696
3697static void cx_auto_parse_input(struct hda_codec *codec)
3698{
3699 struct conexant_spec *spec = codec->spec;
3700 struct auto_pin_cfg *cfg = &spec->autocfg;
3701 struct hda_input_mux *imux;
3702 int i, j;
3703
3704 imux = &spec->private_imux;
3705 for (i = 0; i < cfg->num_inputs; i++) {
3706 for (j = 0; j < spec->num_adc_nids; j++) {
3707 hda_nid_t adc = spec->adc_nids[j];
3708 int idx = get_input_connection(codec, adc,
3709 cfg->inputs[i].pin);
3710 if (idx >= 0) {
3711 const char *label;
3712 label = hda_get_autocfg_input_label(codec, cfg, i);
3713 spec->imux_info[imux->num_items].index = i;
3714 spec->imux_info[imux->num_items].boost = 0;
3715 spec->imux_info[imux->num_items].adc = adc;
3716 spec->imux_info[imux->num_items].pin =
3717 cfg->inputs[i].pin;
3718 snd_hda_add_imux_item(imux, label, idx, NULL);
3719 break;
3720 }
3721 }
3722 }
3723 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3724 cx_auto_check_auto_mic(codec);
3725 if (imux->num_items > 1) {
3726 for (i = 1; i < imux->num_items; i++) {
3727 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
3728 spec->adc_switching = 1;
3729 break;
3730 }
3731 }
3732 }
3733}
3734
3735/* get digital-input audio widget corresponding to the given pin */
3736static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3737{
3738 hda_nid_t nid, end_nid;
3739
3740 end_nid = codec->start_nid + codec->num_nodes;
3741 for (nid = codec->start_nid; nid < end_nid; nid++) {
3742 unsigned int wcaps = get_wcaps(codec, nid);
3743 unsigned int type = get_wcaps_type(wcaps);
3744 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3745 if (get_connection_index(codec, nid, pin) >= 0)
3746 return nid;
3747 }
3748 }
3749 return 0;
3750}
3751
3752static void cx_auto_parse_digital(struct hda_codec *codec)
3753{
3754 struct conexant_spec *spec = codec->spec;
3755 struct auto_pin_cfg *cfg = &spec->autocfg;
3756 hda_nid_t nid;
3757
3758 if (cfg->dig_outs &&
3759 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3760 spec->multiout.dig_out_nid = nid;
3761 if (cfg->dig_in_pin)
3762 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3763}
3764 3113
3765#ifdef CONFIG_SND_HDA_INPUT_BEEP 3114#ifdef CONFIG_SND_HDA_INPUT_BEEP
3766static void cx_auto_parse_beep(struct hda_codec *codec) 3115static void cx_auto_parse_beep(struct hda_codec *codec)
@@ -3802,24 +3151,8 @@ static void cx_auto_parse_eapd(struct hda_codec *codec)
3802 * OTOH, if only one or two EAPDs are found, it's an old chip, 3151 * OTOH, if only one or two EAPDs are found, it's an old chip,
3803 * thus it might control over all pins. 3152 * thus it might control over all pins.
3804 */ 3153 */
3805 spec->pin_eapd_ctrls = spec->num_eapds > 2; 3154 if (spec->num_eapds > 2)
3806} 3155 spec->gen.own_eapd_ctl = 1;
3807
3808static int cx_auto_parse_auto_config(struct hda_codec *codec)
3809{
3810 struct conexant_spec *spec = codec->spec;
3811 int err;
3812
3813 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3814 if (err < 0)
3815 return err;
3816
3817 cx_auto_parse_output(codec);
3818 cx_auto_parse_input(codec);
3819 cx_auto_parse_digital(codec);
3820 cx_auto_parse_beep(codec);
3821 cx_auto_parse_eapd(codec);
3822 return 0;
3823} 3156}
3824 3157
3825static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3158static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
@@ -3834,565 +3167,39 @@ static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3834 } 3167 }
3835} 3168}
3836 3169
3837static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3838 hda_nid_t src)
3839{
3840 int idx = get_connection_index(codec, pin, src);
3841 if (idx >= 0)
3842 snd_hda_codec_write(codec, pin, 0,
3843 AC_VERB_SET_CONNECT_SEL, idx);
3844}
3845
3846static void mute_outputs(struct hda_codec *codec, int num_nids,
3847 const hda_nid_t *nids)
3848{
3849 int i, val;
3850
3851 for (i = 0; i < num_nids; i++) {
3852 hda_nid_t nid = nids[i];
3853 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3854 continue;
3855 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3856 val = AMP_OUT_MUTE;
3857 else
3858 val = AMP_OUT_ZERO;
3859 snd_hda_codec_write(codec, nid, 0,
3860 AC_VERB_SET_AMP_GAIN_MUTE, val);
3861 }
3862}
3863
3864static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3865 hda_nid_t *pins, unsigned int action,
3866 hda_jack_callback cb)
3867{
3868 int i;
3869 for (i = 0; i < num_pins; i++)
3870 snd_hda_jack_detect_enable_callback(codec, pins[i], action, cb);
3871}
3872
3873static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3874{
3875 int i;
3876 for (i = 0; i < nums; i++)
3877 if (list[i] == nid)
3878 return true;
3879 return false;
3880}
3881
3882/* is the given NID found in any of autocfg items? */
3883static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3884{
3885 int i;
3886
3887 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3888 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3889 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3890 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3891 return true;
3892 for (i = 0; i < cfg->num_inputs; i++)
3893 if (cfg->inputs[i].pin == nid)
3894 return true;
3895 if (cfg->dig_in_pin == nid)
3896 return true;
3897 return false;
3898}
3899
3900/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3901 * invalid unsol tags by some reason
3902 */
3903static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3904{
3905 struct conexant_spec *spec = codec->spec;
3906 struct auto_pin_cfg *cfg = &spec->autocfg;
3907 int i;
3908
3909 for (i = 0; i < codec->init_pins.used; i++) {
3910 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3911 if (!found_in_autocfg(cfg, pin->nid))
3912 snd_hda_codec_write(codec, pin->nid, 0,
3913 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3914 }
3915}
3916
3917/* turn on/off EAPD according to Master switch */ 3170/* turn on/off EAPD according to Master switch */
3918static void cx_auto_vmaster_hook(void *private_data, int enabled) 3171static void cx_auto_vmaster_hook(void *private_data, int enabled)
3919{ 3172{
3920 struct hda_codec *codec = private_data; 3173 struct hda_codec *codec = private_data;
3921 struct conexant_spec *spec = codec->spec; 3174 struct conexant_spec *spec = codec->spec;
3922 3175
3923 if (enabled && spec->pin_eapd_ctrls) {
3924 cx_auto_update_speakers(codec);
3925 return;
3926 }
3927 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 3176 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3928} 3177}
3929 3178
3930static void cx_auto_init_output(struct hda_codec *codec)
3931{
3932 struct conexant_spec *spec = codec->spec;
3933 struct auto_pin_cfg *cfg = &spec->autocfg;
3934 hda_nid_t nid;
3935 int i;
3936
3937 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
3938 for (i = 0; i < cfg->hp_outs; i++) {
3939 unsigned int val = PIN_OUT;
3940 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3941 AC_PINCAP_HP_DRV)
3942 val |= AC_PINCTL_HP_EN;
3943 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
3944 }
3945 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3946 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3947 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
3948 for (i = 0; i < spec->dac_info_filled; i++) {
3949 nid = spec->dac_info[i].dac;
3950 if (!nid)
3951 nid = spec->multiout.dac_nids[0];
3952 else if (nid & DAC_SLAVE_FLAG)
3953 nid &= ~DAC_SLAVE_FLAG;
3954 select_connection(codec, spec->dac_info[i].pin, nid);
3955 }
3956 if (spec->auto_mute) {
3957 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3958 CONEXANT_HP_EVENT, cx_auto_hp_automute);
3959 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3960 cfg->hp_pins);
3961 if (spec->detect_line) {
3962 enable_unsol_pins(codec, cfg->line_outs,
3963 cfg->line_out_pins,
3964 CONEXANT_LINE_EVENT,
3965 cx_auto_line_automute);
3966 spec->line_present =
3967 detect_jacks(codec, cfg->line_outs,
3968 cfg->line_out_pins);
3969 }
3970 }
3971 cx_auto_update_speakers(codec);
3972 /* turn on all EAPDs if no individual EAPD control is available */
3973 if (!spec->pin_eapd_ctrls)
3974 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
3975 clear_unsol_on_unused_pins(codec);
3976}
3977
3978static void cx_auto_init_input(struct hda_codec *codec)
3979{
3980 struct conexant_spec *spec = codec->spec;
3981 struct auto_pin_cfg *cfg = &spec->autocfg;
3982 int i, val;
3983
3984 for (i = 0; i < spec->num_adc_nids; i++) {
3985 hda_nid_t nid = spec->adc_nids[i];
3986 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3987 continue;
3988 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3989 val = AMP_IN_MUTE(0);
3990 else
3991 val = AMP_IN_UNMUTE(0);
3992 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3993 val);
3994 }
3995
3996 for (i = 0; i < cfg->num_inputs; i++) {
3997 hda_nid_t pin = cfg->inputs[i].pin;
3998 unsigned int type = PIN_IN;
3999 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4000 type |= snd_hda_get_default_vref(codec, pin);
4001 snd_hda_set_pin_ctl(codec, pin, type);
4002 }
4003
4004 if (spec->auto_mic) {
4005 if (spec->auto_mic_ext >= 0) {
4006 snd_hda_jack_detect_enable_callback(codec,
4007 cfg->inputs[spec->auto_mic_ext].pin,
4008 CONEXANT_MIC_EVENT, cx_auto_automic);
4009 }
4010 if (spec->auto_mic_dock >= 0) {
4011 snd_hda_jack_detect_enable_callback(codec,
4012 cfg->inputs[spec->auto_mic_dock].pin,
4013 CONEXANT_MIC_EVENT, cx_auto_automic);
4014 }
4015 cx_auto_automic(codec, NULL);
4016 } else {
4017 select_input_connection(codec, spec->imux_info[0].adc,
4018 spec->imux_info[0].pin);
4019 }
4020}
4021
4022static void cx_auto_init_digital(struct hda_codec *codec)
4023{
4024 struct conexant_spec *spec = codec->spec;
4025 struct auto_pin_cfg *cfg = &spec->autocfg;
4026
4027 if (spec->multiout.dig_out_nid)
4028 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
4029 if (spec->dig_in_nid)
4030 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
4031}
4032
4033static int cx_auto_init(struct hda_codec *codec)
4034{
4035 struct conexant_spec *spec = codec->spec;
4036 snd_hda_gen_apply_verbs(codec);
4037 cx_auto_init_output(codec);
4038 cx_auto_init_input(codec);
4039 cx_auto_init_digital(codec);
4040 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4041 return 0;
4042}
4043
4044static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4045 const char *dir, int cidx,
4046 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
4047{
4048 static char name[44];
4049 static struct snd_kcontrol_new knew[] = {
4050 HDA_CODEC_VOLUME(name, 0, 0, 0),
4051 HDA_CODEC_MUTE(name, 0, 0, 0),
4052 };
4053 static const char * const sfx[2] = { "Volume", "Switch" };
4054 int i, err;
4055
4056 for (i = 0; i < 2; i++) {
4057 struct snd_kcontrol *kctl;
4058 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
4059 hda_dir);
4060 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4061 knew[i].index = cidx;
4062 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4063 kctl = snd_ctl_new1(&knew[i], codec);
4064 if (!kctl)
4065 return -ENOMEM;
4066 err = snd_hda_ctl_add(codec, nid, kctl);
4067 if (err < 0)
4068 return err;
4069 if (!(query_amp_caps(codec, nid, hda_dir) &
4070 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
4071 break;
4072 }
4073 return 0;
4074}
4075
4076#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4077 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
4078
4079#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4080 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4081
4082static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4083 hda_nid_t pin, const char *name, int idx)
4084{
4085 unsigned int caps;
4086 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4087 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4088 if (caps & AC_AMPCAP_NUM_STEPS)
4089 return cx_auto_add_pb_volume(codec, dac, name, idx);
4090 }
4091 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4092 if (caps & AC_AMPCAP_NUM_STEPS)
4093 return cx_auto_add_pb_volume(codec, pin, name, idx);
4094 return 0;
4095}
4096
4097static bool is_2_1_speaker(struct conexant_spec *spec)
4098{
4099 int i, type, num_spk = 0;
4100
4101 for (i = 0; i < spec->dac_info_filled; i++) {
4102 type = spec->dac_info[i].type;
4103 if (type == AUTO_PIN_LINE_OUT)
4104 type = spec->autocfg.line_out_type;
4105 if (type == AUTO_PIN_SPEAKER_OUT)
4106 num_spk++;
4107 }
4108 return (num_spk == 2 && spec->autocfg.line_out_type != AUTO_PIN_LINE_OUT);
4109}
4110
4111static int cx_auto_build_output_controls(struct hda_codec *codec)
4112{
4113 struct conexant_spec *spec = codec->spec;
4114 int i, err;
4115 int num_line = 0, num_hp = 0, num_spk = 0;
4116 bool speaker_2_1;
4117 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
4118
4119 if (spec->dac_info_filled == 1)
4120 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4121 spec->dac_info[0].pin,
4122 "Master", 0);
4123
4124 speaker_2_1 = is_2_1_speaker(spec);
4125
4126 for (i = 0; i < spec->dac_info_filled; i++) {
4127 const char *label;
4128 int idx, type;
4129 hda_nid_t dac = spec->dac_info[i].dac;
4130 type = spec->dac_info[i].type;
4131 if (type == AUTO_PIN_LINE_OUT)
4132 type = spec->autocfg.line_out_type;
4133 switch (type) {
4134 case AUTO_PIN_LINE_OUT:
4135 default:
4136 label = texts[num_line++];
4137 idx = 0;
4138 break;
4139 case AUTO_PIN_HP_OUT:
4140 label = "Headphone";
4141 idx = num_hp++;
4142 break;
4143 case AUTO_PIN_SPEAKER_OUT:
4144 if (speaker_2_1) {
4145 label = num_spk++ ? "Bass Speaker" : "Speaker";
4146 idx = 0;
4147 } else {
4148 label = "Speaker";
4149 idx = num_spk++;
4150 }
4151 break;
4152 }
4153 err = try_add_pb_volume(codec, dac,
4154 spec->dac_info[i].pin,
4155 label, idx);
4156 if (err < 0)
4157 return err;
4158 }
4159
4160 if (spec->auto_mute) {
4161 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4162 if (err < 0)
4163 return err;
4164 }
4165
4166 return 0;
4167}
4168
4169/* Returns zero if this is a normal stereo channel, and non-zero if it should
4170 be split in two independent channels.
4171 dest_label must be at least 44 characters. */
4172static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4173 char *dest_label, int nid)
4174{
4175 struct conexant_spec *spec = codec->spec;
4176 int i;
4177
4178 if (!spec->fixup_stereo_dmic)
4179 return 0;
4180
4181 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4182 int def_conf;
4183 if (spec->autocfg.inputs[i].pin != nid)
4184 continue;
4185
4186 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4187 return 0;
4188 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4189 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4190 return 0;
4191
4192 /* Finally found the inverted internal mic! */
4193 snprintf(dest_label, 44, "Inverted %s", label);
4194 return 1;
4195 }
4196 return 0;
4197}
4198
4199static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4200 const char *label, const char *pfx,
4201 int cidx)
4202{
4203 struct conexant_spec *spec = codec->spec;
4204 int i;
4205
4206 for (i = 0; i < spec->num_adc_nids; i++) {
4207 char rightch_label[44];
4208 hda_nid_t adc_nid = spec->adc_nids[i];
4209 int idx = get_input_connection(codec, adc_nid, nid);
4210 if (idx < 0)
4211 continue;
4212 if (codec->single_adc_amp)
4213 idx = 0;
4214
4215 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4216 /* Make two independent kcontrols for left and right */
4217 int err = cx_auto_add_volume_idx(codec, label, pfx,
4218 cidx, adc_nid, HDA_INPUT, idx, 1);
4219 if (err < 0)
4220 return err;
4221 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4222 cidx, adc_nid, HDA_INPUT, idx, 2);
4223 }
4224 return cx_auto_add_volume_idx(codec, label, pfx,
4225 cidx, adc_nid, HDA_INPUT, idx, 3);
4226 }
4227 return 0;
4228}
4229
4230static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4231 const char *label, int cidx)
4232{
4233 struct conexant_spec *spec = codec->spec;
4234 hda_nid_t mux, nid;
4235 int i, con;
4236
4237 nid = spec->imux_info[idx].pin;
4238 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4239 char rightch_label[44];
4240 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4241 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4242 cidx, nid, HDA_INPUT, 0, 1);
4243 if (err < 0)
4244 return err;
4245 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4246 cidx, nid, HDA_INPUT, 0, 2);
4247 }
4248 return cx_auto_add_volume(codec, label, " Boost", cidx,
4249 nid, HDA_INPUT);
4250 }
4251 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4252 &mux, false, 0);
4253 if (con < 0)
4254 return 0;
4255 for (i = 0; i < idx; i++) {
4256 if (spec->imux_info[i].boost == mux)
4257 return 0; /* already present */
4258 }
4259
4260 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
4261 spec->imux_info[idx].boost = mux;
4262 return cx_auto_add_volume(codec, label, " Boost", cidx,
4263 mux, HDA_OUTPUT);
4264 }
4265 return 0;
4266}
4267
4268static int cx_auto_build_input_controls(struct hda_codec *codec)
4269{
4270 struct conexant_spec *spec = codec->spec;
4271 struct hda_input_mux *imux = &spec->private_imux;
4272 const char *prev_label;
4273 int input_conn[HDA_MAX_NUM_INPUTS];
4274 int i, j, err, cidx;
4275 int multi_connection;
4276
4277 if (!imux->num_items)
4278 return 0;
4279
4280 multi_connection = 0;
4281 for (i = 0; i < imux->num_items; i++) {
4282 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4283 spec->imux_info[i].pin);
4284 if (cidx < 0)
4285 continue;
4286 input_conn[i] = spec->imux_info[i].adc;
4287 if (!codec->single_adc_amp)
4288 input_conn[i] |= cidx << 8;
4289 if (i > 0 && input_conn[i] != input_conn[0])
4290 multi_connection = 1;
4291 }
4292
4293 prev_label = NULL;
4294 cidx = 0;
4295 for (i = 0; i < imux->num_items; i++) {
4296 hda_nid_t nid = spec->imux_info[i].pin;
4297 const char *label;
4298
4299 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
4300 spec->imux_info[i].index);
4301 if (label == prev_label)
4302 cidx++;
4303 else
4304 cidx = 0;
4305 prev_label = label;
4306
4307 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4308 if (err < 0)
4309 return err;
4310
4311 if (!multi_connection) {
4312 if (i > 0)
4313 continue;
4314 err = cx_auto_add_capture_volume(codec, nid,
4315 "Capture", "", cidx);
4316 } else {
4317 bool dup_found = false;
4318 for (j = 0; j < i; j++) {
4319 if (input_conn[j] == input_conn[i]) {
4320 dup_found = true;
4321 break;
4322 }
4323 }
4324 if (dup_found)
4325 continue;
4326 err = cx_auto_add_capture_volume(codec, nid,
4327 label, " Capture", cidx);
4328 }
4329 if (err < 0)
4330 return err;
4331 }
4332
4333 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4334 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4335 if (err < 0)
4336 return err;
4337 }
4338
4339 return 0;
4340}
4341
4342static int cx_auto_build_controls(struct hda_codec *codec) 3179static int cx_auto_build_controls(struct hda_codec *codec)
4343{ 3180{
4344 struct conexant_spec *spec = codec->spec;
4345 int err; 3181 int err;
4346 3182
4347 err = cx_auto_build_output_controls(codec); 3183 err = snd_hda_gen_build_controls(codec);
4348 if (err < 0) 3184 if (err < 0)
4349 return err; 3185 return err;
4350 err = cx_auto_build_input_controls(codec); 3186
4351 if (err < 0) 3187 err = add_beep_ctls(codec);
4352 return err;
4353 err = conexant_build_controls(codec);
4354 if (err < 0)
4355 return err;
4356 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4357 if (err < 0) 3188 if (err < 0)
4358 return err; 3189 return err;
4359 if (spec->vmaster_mute.sw_kctl) {
4360 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4361 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4362 spec->vmaster_mute_led);
4363 if (err < 0)
4364 return err;
4365 }
4366 return 0;
4367}
4368 3190
4369static int cx_auto_search_adcs(struct hda_codec *codec)
4370{
4371 struct conexant_spec *spec = codec->spec;
4372 hda_nid_t nid, end_nid;
4373
4374 end_nid = codec->start_nid + codec->num_nodes;
4375 for (nid = codec->start_nid; nid < end_nid; nid++) {
4376 unsigned int caps = get_wcaps(codec, nid);
4377 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4378 continue;
4379 if (caps & AC_WCAP_DIGITAL)
4380 continue;
4381 if (snd_BUG_ON(spec->num_adc_nids >=
4382 ARRAY_SIZE(spec->private_adc_nids)))
4383 break;
4384 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4385 }
4386 spec->adc_nids = spec->private_adc_nids;
4387 return 0; 3191 return 0;
4388} 3192}
4389 3193
4390static const struct hda_codec_ops cx_auto_patch_ops = { 3194static const struct hda_codec_ops cx_auto_patch_ops = {
4391 .build_controls = cx_auto_build_controls, 3195 .build_controls = cx_auto_build_controls,
4392 .build_pcms = conexant_build_pcms, 3196 .build_pcms = snd_hda_gen_build_pcms,
4393 .init = cx_auto_init, 3197 .init = snd_hda_gen_init,
4394 .free = conexant_free, 3198 .free = snd_hda_gen_free,
4395 .unsol_event = snd_hda_jack_unsol_event, 3199 .unsol_event = snd_hda_jack_unsol_event,
3200#ifdef CONFIG_PM
3201 .check_power_status = snd_hda_gen_check_power_status,
3202#endif
4396}; 3203};
4397 3204
4398/* 3205/*
@@ -4411,7 +3218,7 @@ static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
4411 const struct hda_fixup *fix, int action) 3218 const struct hda_fixup *fix, int action)
4412{ 3219{
4413 struct conexant_spec *spec = codec->spec; 3220 struct conexant_spec *spec = codec->spec;
4414 spec->fixup_stereo_dmic = 1; 3221 spec->gen.inv_dmic_split = 1;
4415} 3222}
4416 3223
4417static void cxt5066_increase_mic_boost(struct hda_codec *codec, 3224static void cxt5066_increase_mic_boost(struct hda_codec *codec,
@@ -4532,12 +3339,22 @@ static int patch_conexant_auto(struct hda_codec *codec)
4532 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3339 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4533 if (!spec) 3340 if (!spec)
4534 return -ENOMEM; 3341 return -ENOMEM;
3342 snd_hda_gen_spec_init(&spec->gen);
4535 codec->spec = spec; 3343 codec->spec = spec;
4536 snd_hda_gen_init(&spec->gen); 3344
3345 cx_auto_parse_beep(codec);
3346 cx_auto_parse_eapd(codec);
3347 if (spec->gen.own_eapd_ctl)
3348 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
4537 3349
4538 switch (codec->vendor_id) { 3350 switch (codec->vendor_id) {
4539 case 0x14f15045: 3351 case 0x14f15045:
4540 codec->single_adc_amp = 1; 3352 codec->single_adc_amp = 1;
3353 codec->power_filter = NULL; /* Needs speaker amp to D3 to avoid click */
3354 break;
3355 case 0x14f15047:
3356 codec->pin_amp_workaround = 1;
3357 spec->gen.mixer_nid = 0x19;
4541 break; 3358 break;
4542 case 0x14f15051: 3359 case 0x14f15051:
4543 add_cx5051_fake_mutes(codec); 3360 add_cx5051_fake_mutes(codec);
@@ -4550,8 +3367,6 @@ static int patch_conexant_auto(struct hda_codec *codec)
4550 break; 3367 break;
4551 } 3368 }
4552 3369
4553 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4554
4555 /* Show mute-led control only on HP laptops 3370 /* Show mute-led control only on HP laptops
4556 * This is a sort of white-list: on HP laptops, EAPD corresponds 3371 * This is a sort of white-list: on HP laptops, EAPD corresponds
4557 * only to the mute-LED without actualy amp function. Meanwhile, 3372 * only to the mute-LED without actualy amp function. Meanwhile,
@@ -4560,20 +3375,20 @@ static int patch_conexant_auto(struct hda_codec *codec)
4560 */ 3375 */
4561 switch (codec->subsystem_id >> 16) { 3376 switch (codec->subsystem_id >> 16) {
4562 case 0x103c: 3377 case 0x103c:
4563 spec->vmaster_mute_led = 1; 3378 spec->gen.vmaster_mute_enum = 1;
4564 break; 3379 break;
4565 } 3380 }
4566 3381
4567 err = cx_auto_search_adcs(codec); 3382 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3383
3384 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
4568 if (err < 0) 3385 if (err < 0)
4569 return err; 3386 goto error;
4570 err = cx_auto_parse_auto_config(codec); 3387
4571 if (err < 0) { 3388 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
4572 kfree(codec->spec); 3389 if (err < 0)
4573 codec->spec = NULL; 3390 goto error;
4574 return err; 3391
4575 }
4576 spec->capture_stream = &cx_auto_pcm_analog_capture;
4577 codec->patch_ops = cx_auto_patch_ops; 3392 codec->patch_ops = cx_auto_patch_ops;
4578 if (spec->beep_amp) 3393 if (spec->beep_amp)
4579 snd_hda_attach_beep_device(codec, spec->beep_amp); 3394 snd_hda_attach_beep_device(codec, spec->beep_amp);
@@ -4590,8 +3405,19 @@ static int patch_conexant_auto(struct hda_codec *codec)
4590 } 3405 }
4591 3406
4592 return 0; 3407 return 0;
3408
3409 error:
3410 snd_hda_gen_free(codec);
3411 return err;
4593} 3412}
4594 3413
3414#ifndef ENABLE_CXT_STATIC_QUIRKS
3415#define patch_cxt5045 patch_conexant_auto
3416#define patch_cxt5047 patch_conexant_auto
3417#define patch_cxt5051 patch_conexant_auto
3418#define patch_cxt5066 patch_conexant_auto
3419#endif
3420
4595/* 3421/*
4596 */ 3422 */
4597 3423
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 807a2aa1ff38..21425fb51fe0 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -64,6 +64,9 @@ struct hdmi_spec_per_cvt {
64 unsigned int maxbps; 64 unsigned int maxbps;
65}; 65};
66 66
67/* max. connections to a widget */
68#define HDA_MAX_CONNECTIONS 32
69
67struct hdmi_spec_per_pin { 70struct hdmi_spec_per_pin {
68 hda_nid_t pin_nid; 71 hda_nid_t pin_nid;
69 int num_mux_nids; 72 int num_mux_nids;
@@ -72,6 +75,7 @@ struct hdmi_spec_per_pin {
72 struct hda_codec *codec; 75 struct hda_codec *codec;
73 struct hdmi_eld sink_eld; 76 struct hdmi_eld sink_eld;
74 struct delayed_work work; 77 struct delayed_work work;
78 struct snd_kcontrol *eld_ctl;
75 int repoll_count; 79 int repoll_count;
76 bool non_pcm; 80 bool non_pcm;
77 bool chmap_set; /* channel-map override by ALSA API? */ 81 bool chmap_set; /* channel-map override by ALSA API? */
@@ -81,12 +85,14 @@ struct hdmi_spec_per_pin {
81struct hdmi_spec { 85struct hdmi_spec {
82 int num_cvts; 86 int num_cvts;
83 struct hdmi_spec_per_cvt cvts[MAX_HDMI_CVTS]; 87 struct hdmi_spec_per_cvt cvts[MAX_HDMI_CVTS];
88 hda_nid_t cvt_nids[MAX_HDMI_CVTS];
84 89
85 int num_pins; 90 int num_pins;
86 struct hdmi_spec_per_pin pins[MAX_HDMI_PINS]; 91 struct hdmi_spec_per_pin pins[MAX_HDMI_PINS];
87 struct hda_pcm pcm_rec[MAX_HDMI_PINS]; 92 struct hda_pcm pcm_rec[MAX_HDMI_PINS];
88 unsigned int channels_max; /* max over all cvts */ 93 unsigned int channels_max; /* max over all cvts */
89 94
95 struct hdmi_eld temp_eld;
90 /* 96 /*
91 * Non-generic ATI/NVIDIA specific 97 * Non-generic ATI/NVIDIA specific
92 */ 98 */
@@ -339,14 +345,18 @@ static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
339 struct snd_ctl_elem_info *uinfo) 345 struct snd_ctl_elem_info *uinfo)
340{ 346{
341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 347 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342 struct hdmi_spec *spec; 348 struct hdmi_spec *spec = codec->spec;
349 struct hdmi_eld *eld;
343 int pin_idx; 350 int pin_idx;
344 351
345 spec = codec->spec;
346 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 352 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
347 353
348 pin_idx = kcontrol->private_value; 354 pin_idx = kcontrol->private_value;
349 uinfo->count = spec->pins[pin_idx].sink_eld.eld_size; 355 eld = &spec->pins[pin_idx].sink_eld;
356
357 mutex_lock(&eld->lock);
358 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
359 mutex_unlock(&eld->lock);
350 360
351 return 0; 361 return 0;
352} 362}
@@ -355,14 +365,26 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
355 struct snd_ctl_elem_value *ucontrol) 365 struct snd_ctl_elem_value *ucontrol)
356{ 366{
357 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
358 struct hdmi_spec *spec; 368 struct hdmi_spec *spec = codec->spec;
369 struct hdmi_eld *eld;
359 int pin_idx; 370 int pin_idx;
360 371
361 spec = codec->spec;
362 pin_idx = kcontrol->private_value; 372 pin_idx = kcontrol->private_value;
373 eld = &spec->pins[pin_idx].sink_eld;
374
375 mutex_lock(&eld->lock);
376 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
377 mutex_unlock(&eld->lock);
378 snd_BUG();
379 return -EINVAL;
380 }
363 381
364 memcpy(ucontrol->value.bytes.data, 382 memset(ucontrol->value.bytes.data, 0,
365 spec->pins[pin_idx].sink_eld.eld_buffer, ELD_MAX_SIZE); 383 ARRAY_SIZE(ucontrol->value.bytes.data));
384 if (eld->eld_valid)
385 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
386 eld->eld_size);
387 mutex_unlock(&eld->lock);
366 388
367 return 0; 389 return 0;
368} 390}
@@ -392,6 +414,7 @@ static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
392 if (err < 0) 414 if (err < 0)
393 return err; 415 return err;
394 416
417 spec->pins[pin_idx].eld_ctl = kctl;
395 return 0; 418 return 0;
396} 419}
397 420
@@ -516,7 +539,7 @@ static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
516 * expand ELD's notions to match the ones used by Audio InfoFrame. 539 * expand ELD's notions to match the ones used by Audio InfoFrame.
517 */ 540 */
518 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { 541 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
519 if (eld->spk_alloc & (1 << i)) 542 if (eld->info.spk_alloc & (1 << i))
520 spk_mask |= eld_speaker_allocation_bits[i]; 543 spk_mask |= eld_speaker_allocation_bits[i];
521 } 544 }
522 545
@@ -530,7 +553,7 @@ static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
530 } 553 }
531 } 554 }
532 555
533 snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf)); 556 snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf));
534 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n", 557 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
535 ca, channels, buf); 558 ca, channels, buf);
536 559
@@ -714,9 +737,10 @@ static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
714 737
715static void hdmi_setup_channel_mapping(struct hda_codec *codec, 738static void hdmi_setup_channel_mapping(struct hda_codec *codec,
716 hda_nid_t pin_nid, bool non_pcm, int ca, 739 hda_nid_t pin_nid, bool non_pcm, int ca,
717 int channels, unsigned char *map) 740 int channels, unsigned char *map,
741 bool chmap_set)
718{ 742{
719 if (!non_pcm && map) { 743 if (!non_pcm && chmap_set) {
720 hdmi_manual_setup_channel_mapping(codec, pin_nid, 744 hdmi_manual_setup_channel_mapping(codec, pin_nid,
721 channels, map); 745 channels, map);
722 } else { 746 } else {
@@ -870,7 +894,7 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
870 ca = 0; 894 ca = 0;
871 895
872 memset(&ai, 0, sizeof(ai)); 896 memset(&ai, 0, sizeof(ai));
873 if (eld->conn_type == 0) { /* HDMI */ 897 if (eld->info.conn_type == 0) { /* HDMI */
874 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi; 898 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
875 899
876 hdmi_ai->type = 0x84; 900 hdmi_ai->type = 0x84;
@@ -879,7 +903,7 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
879 hdmi_ai->CC02_CT47 = channels - 1; 903 hdmi_ai->CC02_CT47 = channels - 1;
880 hdmi_ai->CA = ca; 904 hdmi_ai->CA = ca;
881 hdmi_checksum_audio_infoframe(hdmi_ai); 905 hdmi_checksum_audio_infoframe(hdmi_ai);
882 } else if (eld->conn_type == 1) { /* DisplayPort */ 906 } else if (eld->info.conn_type == 1) { /* DisplayPort */
883 struct dp_audio_infoframe *dp_ai = &ai.dp; 907 struct dp_audio_infoframe *dp_ai = &ai.dp;
884 908
885 dp_ai->type = 0x84; 909 dp_ai->type = 0x84;
@@ -905,7 +929,8 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
905 pin_nid, 929 pin_nid,
906 channels); 930 channels);
907 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca, 931 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
908 channels, per_pin->chmap); 932 channels, per_pin->chmap,
933 per_pin->chmap_set);
909 hdmi_stop_infoframe_trans(codec, pin_nid); 934 hdmi_stop_infoframe_trans(codec, pin_nid);
910 hdmi_fill_audio_infoframe(codec, pin_nid, 935 hdmi_fill_audio_infoframe(codec, pin_nid,
911 ai.bytes, sizeof(ai)); 936 ai.bytes, sizeof(ai));
@@ -915,7 +940,8 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
915 * accordingly */ 940 * accordingly */
916 if (per_pin->non_pcm != non_pcm) 941 if (per_pin->non_pcm != non_pcm)
917 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca, 942 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
918 channels, per_pin->chmap); 943 channels, per_pin->chmap,
944 per_pin->chmap_set);
919 } 945 }
920 946
921 per_pin->non_pcm = non_pcm; 947 per_pin->non_pcm = non_pcm;
@@ -1098,10 +1124,14 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1098 1124
1099 /* Restrict capabilities by ELD if this isn't disabled */ 1125 /* Restrict capabilities by ELD if this isn't disabled */
1100 if (!static_hdmi_pcm && eld->eld_valid) { 1126 if (!static_hdmi_pcm && eld->eld_valid) {
1101 snd_hdmi_eld_update_pcm_info(eld, hinfo); 1127 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
1102 if (hinfo->channels_min > hinfo->channels_max || 1128 if (hinfo->channels_min > hinfo->channels_max ||
1103 !hinfo->rates || !hinfo->formats) 1129 !hinfo->rates || !hinfo->formats) {
1130 per_cvt->assigned = 0;
1131 hinfo->nid = 0;
1132 snd_hda_spdif_ctls_unassign(codec, pin_idx);
1104 return -ENODEV; 1133 return -ENODEV;
1134 }
1105 } 1135 }
1106 1136
1107 /* Store the updated parameters */ 1137 /* Store the updated parameters */
@@ -1142,7 +1172,9 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1142static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) 1172static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1143{ 1173{
1144 struct hda_codec *codec = per_pin->codec; 1174 struct hda_codec *codec = per_pin->codec;
1145 struct hdmi_eld *eld = &per_pin->sink_eld; 1175 struct hdmi_spec *spec = codec->spec;
1176 struct hdmi_eld *eld = &spec->temp_eld;
1177 struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1146 hda_nid_t pin_nid = per_pin->pin_nid; 1178 hda_nid_t pin_nid = per_pin->pin_nid;
1147 /* 1179 /*
1148 * Always execute a GetPinSense verb here, even when called from 1180 * Always execute a GetPinSense verb here, even when called from
@@ -1153,27 +1185,64 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1153 * the unsolicited response to avoid custom WARs. 1185 * the unsolicited response to avoid custom WARs.
1154 */ 1186 */
1155 int present = snd_hda_pin_sense(codec, pin_nid); 1187 int present = snd_hda_pin_sense(codec, pin_nid);
1156 bool eld_valid = false; 1188 bool update_eld = false;
1189 bool eld_changed = false;
1157 1190
1158 memset(eld, 0, offsetof(struct hdmi_eld, eld_buffer)); 1191 pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1159 1192 if (pin_eld->monitor_present)
1160 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); 1193 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
1161 if (eld->monitor_present) 1194 else
1162 eld_valid = !!(present & AC_PINSENSE_ELDV); 1195 eld->eld_valid = false;
1163 1196
1164 _snd_printd(SND_PR_VERBOSE, 1197 _snd_printd(SND_PR_VERBOSE,
1165 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n", 1198 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
1166 codec->addr, pin_nid, eld->monitor_present, eld_valid); 1199 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
1200
1201 if (eld->eld_valid) {
1202 if (snd_hdmi_get_eld(codec, pin_nid, eld->eld_buffer,
1203 &eld->eld_size) < 0)
1204 eld->eld_valid = false;
1205 else {
1206 memset(&eld->info, 0, sizeof(struct parsed_hdmi_eld));
1207 if (snd_hdmi_parse_eld(&eld->info, eld->eld_buffer,
1208 eld->eld_size) < 0)
1209 eld->eld_valid = false;
1210 }
1167 1211
1168 if (eld_valid) { 1212 if (eld->eld_valid) {
1169 if (!snd_hdmi_get_eld(eld, codec, pin_nid)) 1213 snd_hdmi_show_eld(&eld->info);
1170 snd_hdmi_show_eld(eld); 1214 update_eld = true;
1215 }
1171 else if (repoll) { 1216 else if (repoll) {
1172 queue_delayed_work(codec->bus->workq, 1217 queue_delayed_work(codec->bus->workq,
1173 &per_pin->work, 1218 &per_pin->work,
1174 msecs_to_jiffies(300)); 1219 msecs_to_jiffies(300));
1220 return;
1175 } 1221 }
1176 } 1222 }
1223
1224 mutex_lock(&pin_eld->lock);
1225 if (pin_eld->eld_valid && !eld->eld_valid) {
1226 update_eld = true;
1227 eld_changed = true;
1228 }
1229 if (update_eld) {
1230 pin_eld->eld_valid = eld->eld_valid;
1231 eld_changed = pin_eld->eld_size != eld->eld_size ||
1232 memcmp(pin_eld->eld_buffer, eld->eld_buffer,
1233 eld->eld_size) != 0;
1234 if (eld_changed)
1235 memcpy(pin_eld->eld_buffer, eld->eld_buffer,
1236 eld->eld_size);
1237 pin_eld->eld_size = eld->eld_size;
1238 pin_eld->info = eld->info;
1239 }
1240 mutex_unlock(&pin_eld->lock);
1241
1242 if (eld_changed)
1243 snd_ctl_notify(codec->bus->card,
1244 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
1245 &per_pin->eld_ctl->id);
1177} 1246}
1178 1247
1179static void hdmi_repoll_eld(struct work_struct *work) 1248static void hdmi_repoll_eld(struct work_struct *work)
@@ -1187,6 +1256,9 @@ static void hdmi_repoll_eld(struct work_struct *work)
1187 hdmi_present_sense(per_pin, per_pin->repoll_count); 1256 hdmi_present_sense(per_pin, per_pin->repoll_count);
1188} 1257}
1189 1258
1259static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1260 hda_nid_t nid);
1261
1190static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) 1262static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1191{ 1263{
1192 struct hdmi_spec *spec = codec->spec; 1264 struct hdmi_spec *spec = codec->spec;
@@ -1206,6 +1278,9 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1206 if (snd_BUG_ON(spec->num_pins >= MAX_HDMI_PINS)) 1278 if (snd_BUG_ON(spec->num_pins >= MAX_HDMI_PINS))
1207 return -E2BIG; 1279 return -E2BIG;
1208 1280
1281 if (codec->vendor_id == 0x80862807)
1282 intel_haswell_fixup_connect_list(codec, pin_nid);
1283
1209 pin_idx = spec->num_pins; 1284 pin_idx = spec->num_pins;
1210 per_pin = &spec->pins[pin_idx]; 1285 per_pin = &spec->pins[pin_idx];
1211 1286
@@ -1253,7 +1328,7 @@ static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
1253 if (err < 0) 1328 if (err < 0)
1254 return err; 1329 return err;
1255 1330
1256 spec->num_cvts++; 1331 spec->cvt_nids[spec->num_cvts++] = cvt_nid;
1257 1332
1258 return 0; 1333 return 0;
1259} 1334}
@@ -1635,6 +1710,7 @@ static int generic_hdmi_init_per_pins(struct hda_codec *codec)
1635 struct hdmi_eld *eld = &per_pin->sink_eld; 1710 struct hdmi_eld *eld = &per_pin->sink_eld;
1636 1711
1637 per_pin->codec = codec; 1712 per_pin->codec = codec;
1713 mutex_init(&eld->lock);
1638 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld); 1714 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
1639 snd_hda_eld_proc_new(codec, eld, pin_idx); 1715 snd_hda_eld_proc_new(codec, eld, pin_idx);
1640 } 1716 }
@@ -1681,30 +1757,92 @@ static const struct hda_codec_ops generic_hdmi_patch_ops = {
1681 .unsol_event = hdmi_unsol_event, 1757 .unsol_event = hdmi_unsol_event,
1682}; 1758};
1683 1759
1684static void intel_haswell_fixup_connect_list(struct hda_codec *codec) 1760
1761static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1762 hda_nid_t nid)
1763{
1764 struct hdmi_spec *spec = codec->spec;
1765 hda_nid_t conns[4];
1766 int nconns;
1767
1768 nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
1769 if (nconns == spec->num_cvts &&
1770 !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
1771 return;
1772
1773 /* override pins connection list */
1774 snd_printdd("hdmi: haswell: override pin connection 0x%x\n", nid);
1775 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
1776}
1777
1778#define INTEL_VENDOR_NID 0x08
1779#define INTEL_GET_VENDOR_VERB 0xf81
1780#define INTEL_SET_VENDOR_VERB 0x781
1781#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
1782#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
1783
1784static void intel_haswell_enable_all_pins(struct hda_codec *codec,
1785 const struct hda_fixup *fix, int action)
1685{ 1786{
1686 unsigned int vendor_param; 1787 unsigned int vendor_param;
1687 hda_nid_t list[3] = {0x2, 0x3, 0x4};
1688 1788
1689 vendor_param = snd_hda_codec_read(codec, 0x08, 0, 0xf81, 0); 1789 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1690 if (vendor_param == -1 || vendor_param & 0x02) 1790 return;
1791 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
1792 INTEL_GET_VENDOR_VERB, 0);
1793 if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
1691 return; 1794 return;
1692 1795
1693 /* enable DP1.2 mode */ 1796 vendor_param |= INTEL_EN_ALL_PIN_CVTS;
1694 vendor_param |= 0x02; 1797 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
1695 snd_hda_codec_read(codec, 0x08, 0, 0x781, vendor_param); 1798 INTEL_SET_VENDOR_VERB, vendor_param);
1799 if (vendor_param == -1)
1800 return;
1801
1802 snd_hda_codec_update_widgets(codec);
1803 return;
1804}
1805
1806static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
1807{
1808 unsigned int vendor_param;
1696 1809
1697 vendor_param = snd_hda_codec_read(codec, 0x08, 0, 0xf81, 0); 1810 vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
1698 if (vendor_param == -1 || !(vendor_param & 0x02)) 1811 INTEL_GET_VENDOR_VERB, 0);
1812 if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
1699 return; 1813 return;
1700 1814
1701 /* override 3 pins connection list */ 1815 /* enable DP1.2 mode */
1702 snd_hda_override_conn_list(codec, 0x05, 3, list); 1816 vendor_param |= INTEL_EN_DP12;
1703 snd_hda_override_conn_list(codec, 0x06, 3, list); 1817 snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
1704 snd_hda_override_conn_list(codec, 0x07, 3, list); 1818 INTEL_SET_VENDOR_VERB, vendor_param);
1705} 1819}
1706 1820
1707 1821
1822
1823/* available models for fixup */
1824enum {
1825 INTEL_HASWELL,
1826};
1827
1828static const struct hda_model_fixup hdmi_models[] = {
1829 {.id = INTEL_HASWELL, .name = "Haswell"},
1830 {}
1831};
1832
1833static const struct snd_pci_quirk hdmi_fixup_tbl[] = {
1834 SND_PCI_QUIRK(0x8086, 0x2010, "Haswell", INTEL_HASWELL),
1835 {} /* terminator */
1836};
1837
1838static const struct hda_fixup hdmi_fixups[] = {
1839 [INTEL_HASWELL] = {
1840 .type = HDA_FIXUP_FUNC,
1841 .v.func = intel_haswell_enable_all_pins,
1842 },
1843};
1844
1845
1708static int patch_generic_hdmi(struct hda_codec *codec) 1846static int patch_generic_hdmi(struct hda_codec *codec)
1709{ 1847{
1710 struct hdmi_spec *spec; 1848 struct hdmi_spec *spec;
@@ -1715,8 +1853,11 @@ static int patch_generic_hdmi(struct hda_codec *codec)
1715 1853
1716 codec->spec = spec; 1854 codec->spec = spec;
1717 1855
1856 snd_hda_pick_fixup(codec, hdmi_models, hdmi_fixup_tbl, hdmi_fixups);
1857 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1858
1718 if (codec->vendor_id == 0x80862807) 1859 if (codec->vendor_id == 0x80862807)
1719 intel_haswell_fixup_connect_list(codec); 1860 intel_haswell_fixup_enable_dp12(codec);
1720 1861
1721 if (hdmi_parse_codec(codec) < 0) { 1862 if (hdmi_parse_codec(codec) < 0) {
1722 codec->spec = NULL; 1863 codec->spec = NULL;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 5faaad219a7f..61478fd82565 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -27,6 +27,7 @@
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/dmi.h>
30#include <linux/module.h> 31#include <linux/module.h>
31#include <sound/core.h> 32#include <sound/core.h>
32#include <sound/jack.h> 33#include <sound/jack.h>
@@ -35,12 +36,10 @@
35#include "hda_auto_parser.h" 36#include "hda_auto_parser.h"
36#include "hda_beep.h" 37#include "hda_beep.h"
37#include "hda_jack.h" 38#include "hda_jack.h"
39#include "hda_generic.h"
38 40
39/* unsol event tags */ 41/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01 42#define ALC_DCVOL_EVENT 0x08
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
44 43
45/* for GPIO Poll */ 44/* for GPIO Poll */
46#define GPIO_MASK 0x03 45#define GPIO_MASK 0x03
@@ -67,355 +66,42 @@ struct alc_customize_define {
67 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */ 66 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
68}; 67};
69 68
70struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
76enum {
77 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
80};
81
82#define MAX_VOL_NIDS 0x40
83
84/* make compatible with old code */
85#define alc_apply_pincfgs snd_hda_apply_pincfgs
86#define alc_apply_fixup snd_hda_apply_fixup
87#define alc_pick_fixup snd_hda_pick_fixup
88#define alc_fixup hda_fixup
89#define alc_pincfg hda_pintbl
90#define alc_model_fixup hda_model_fixup
91
92#define ALC_FIXUP_PINS HDA_FIXUP_PINS
93#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
95
96#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
100
101
102struct alc_spec { 69struct alc_spec {
103 struct hda_gen_spec gen; 70 struct hda_gen_spec gen; /* must be at head */
104 71
105 /* codec parameterization */ 72 /* codec parameterization */
106 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ 73 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
107 unsigned int num_mixers; 74 unsigned int num_mixers;
108 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
109 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ 75 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
110 76
111 char stream_name_analog[32]; /* analog PCM stream */
112 const struct hda_pcm_stream *stream_analog_playback;
113 const struct hda_pcm_stream *stream_analog_capture;
114 const struct hda_pcm_stream *stream_analog_alt_playback;
115 const struct hda_pcm_stream *stream_analog_alt_capture;
116
117 char stream_name_digital[32]; /* digital PCM stream */
118 const struct hda_pcm_stream *stream_digital_playback;
119 const struct hda_pcm_stream *stream_digital_capture;
120
121 /* playback */
122 struct hda_multi_out multiout; /* playback set-up
123 * max_channels, dacs must be set
124 * dig_out_nid and hp_nid are optional
125 */
126 hda_nid_t alt_dac_nid;
127 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
128 int dig_out_type;
129
130 /* capture */
131 unsigned int num_adc_nids;
132 const hda_nid_t *adc_nids;
133 const hda_nid_t *capsrc_nids;
134 hda_nid_t dig_in_nid; /* digital-in NID; optional */
135 hda_nid_t mixer_nid; /* analog-mixer NID */
136 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
137 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
138
139 /* capture setup for dynamic dual-adc switch */
140 hda_nid_t cur_adc;
141 unsigned int cur_adc_stream_tag;
142 unsigned int cur_adc_format;
143
144 /* capture source */
145 unsigned int num_mux_defs;
146 const struct hda_input_mux *input_mux;
147 unsigned int cur_mux[3];
148 hda_nid_t ext_mic_pin;
149 hda_nid_t dock_mic_pin;
150 hda_nid_t int_mic_pin;
151
152 /* channel model */
153 const struct hda_channel_mode *channel_mode;
154 int num_channel_mode;
155 int need_dac_fix;
156 int const_channel_count; /* min. channel count (for speakers) */
157 int ext_channel_count; /* current channel count for multi-io */
158
159 /* PCM information */
160 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
161
162 /* dynamic controls, init_verbs and input_mux */
163 struct auto_pin_cfg autocfg;
164 struct alc_customize_define cdefine; 77 struct alc_customize_define cdefine;
165 struct snd_array kctls; 78 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
166 struct hda_input_mux private_imux[3]; 79
167 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 80 /* inverted dmic fix */
168 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS]; 81 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
169 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS]; 82 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
170 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
171 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
172 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
173 hda_nid_t inv_dmic_pin; 83 hda_nid_t inv_dmic_pin;
174 84
85 /* mute LED for HP laptops, see alc269_fixup_mic_mute_hook() */
86 int mute_led_polarity;
87 hda_nid_t mute_led_nid;
88
175 /* hooks */ 89 /* hooks */
176 void (*init_hook)(struct hda_codec *codec); 90 void (*init_hook)(struct hda_codec *codec);
177#ifdef CONFIG_PM 91#ifdef CONFIG_PM
178 void (*power_hook)(struct hda_codec *codec); 92 void (*power_hook)(struct hda_codec *codec);
179#endif 93#endif
180 void (*shutup)(struct hda_codec *codec); 94 void (*shutup)(struct hda_codec *codec);
181 void (*automute_hook)(struct hda_codec *codec);
182
183 /* for pin sensing */
184 unsigned int hp_jack_present:1;
185 unsigned int line_jack_present:1;
186 unsigned int master_mute:1;
187 unsigned int auto_mic:1;
188 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
189 unsigned int automute_speaker:1; /* automute speaker outputs */
190 unsigned int automute_lo:1; /* automute LO outputs */
191 unsigned int detect_hp:1; /* Headphone detection enabled */
192 unsigned int detect_lo:1; /* Line-out detection enabled */
193 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
194 unsigned int automute_lo_possible:1; /* there are line outs and HP */
195 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
196
197 /* other flags */
198 unsigned int no_analog :1; /* digital I/O only */
199 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
200 unsigned int single_input_src:1;
201 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
202 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
203 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
204 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
205 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
206 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
207
208 /* auto-mute control */
209 int automute_mode;
210 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
211 95
212 int init_amp; 96 int init_amp;
213 int codec_variant; /* flag for other variants */ 97 int codec_variant; /* flag for other variants */
214 98
215 /* for virtual master */
216 hda_nid_t vmaster_nid;
217 struct hda_vmaster_mute_hook vmaster_mute;
218#ifdef CONFIG_PM
219 struct hda_loopback_check loopback;
220 int num_loopbacks;
221 struct hda_amp_list loopback_list[8];
222#endif
223
224 /* for PLL fix */ 99 /* for PLL fix */
225 hda_nid_t pll_nid; 100 hda_nid_t pll_nid;
226 unsigned int pll_coef_idx, pll_coef_bit; 101 unsigned int pll_coef_idx, pll_coef_bit;
227 unsigned int coef0; 102 unsigned int coef0;
228
229 /* multi-io */
230 int multi_ios;
231 struct alc_multi_io multi_io[4];
232
233 /* bind volumes */
234 struct snd_array bind_ctls;
235}; 103};
236 104
237static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
238 int dir, unsigned int bits)
239{
240 if (!nid)
241 return false;
242 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
243 if (query_amp_caps(codec, nid, dir) & bits)
244 return true;
245 return false;
246}
247
248#define nid_has_mute(codec, nid, dir) \
249 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
250#define nid_has_volume(codec, nid, dir) \
251 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
252
253/*
254 * input MUX handling
255 */
256static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_info *uinfo)
258{
259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
260 struct alc_spec *spec = codec->spec;
261 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
262 if (mux_idx >= spec->num_mux_defs)
263 mux_idx = 0;
264 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
265 mux_idx = 0;
266 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
267}
268
269static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *ucontrol)
271{
272 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
273 struct alc_spec *spec = codec->spec;
274 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
275
276 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
277 return 0;
278}
279
280static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
281{
282 struct alc_spec *spec = codec->spec;
283 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
284
285 if (spec->cur_adc && spec->cur_adc != new_adc) {
286 /* stream is running, let's swap the current ADC */
287 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
288 spec->cur_adc = new_adc;
289 snd_hda_codec_setup_stream(codec, new_adc,
290 spec->cur_adc_stream_tag, 0,
291 spec->cur_adc_format);
292 return true;
293 }
294 return false;
295}
296
297static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
298{
299 return spec->capsrc_nids ?
300 spec->capsrc_nids[idx] : spec->adc_nids[idx];
301}
302
303static void call_update_outputs(struct hda_codec *codec);
304static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
305
306/* for shared I/O, change the pin-control accordingly */
307static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
308{
309 struct alc_spec *spec = codec->spec;
310 unsigned int val;
311 hda_nid_t pin = spec->autocfg.inputs[1].pin;
312 /* NOTE: this assumes that there are only two inputs, the
313 * first is the real internal mic and the second is HP/mic jack.
314 */
315
316 val = snd_hda_get_default_vref(codec, pin);
317
318 /* This pin does not have vref caps - let's enable vref on pin 0x18
319 instead, as suggested by Realtek */
320 if (val == AC_PINCTL_VREF_HIZ) {
321 const hda_nid_t vref_pin = 0x18;
322 /* Sanity check pin 0x18 */
323 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
324 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
325 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
326 if (vref_val != AC_PINCTL_VREF_HIZ)
327 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
328 }
329 }
330
331 val = set_as_mic ? val | PIN_IN : PIN_HP;
332 snd_hda_set_pin_ctl(codec, pin, val);
333
334 spec->automute_speaker = !set_as_mic;
335 call_update_outputs(codec);
336}
337
338/* select the given imux item; either unmute exclusively or select the route */
339static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
340 unsigned int idx, bool force)
341{
342 struct alc_spec *spec = codec->spec;
343 const struct hda_input_mux *imux;
344 unsigned int mux_idx;
345 int i, type, num_conns;
346 hda_nid_t nid;
347
348 if (!spec->input_mux)
349 return 0;
350
351 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
352 imux = &spec->input_mux[mux_idx];
353 if (!imux->num_items && mux_idx > 0)
354 imux = &spec->input_mux[0];
355 if (!imux->num_items)
356 return 0;
357
358 if (idx >= imux->num_items)
359 idx = imux->num_items - 1;
360 if (spec->cur_mux[adc_idx] == idx && !force)
361 return 0;
362 spec->cur_mux[adc_idx] = idx;
363
364 if (spec->shared_mic_hp)
365 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
366
367 if (spec->dyn_adc_switch) {
368 alc_dyn_adc_pcm_resetup(codec, idx);
369 adc_idx = spec->dyn_adc_idx[idx];
370 }
371
372 nid = get_capsrc(spec, adc_idx);
373
374 /* no selection? */
375 num_conns = snd_hda_get_num_conns(codec, nid);
376 if (num_conns <= 1)
377 return 1;
378
379 type = get_wcaps_type(get_wcaps(codec, nid));
380 if (type == AC_WID_AUD_MIX) {
381 /* Matrix-mixer style (e.g. ALC882) */
382 int active = imux->items[idx].index;
383 for (i = 0; i < num_conns; i++) {
384 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
385 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
386 HDA_AMP_MUTE, v);
387 }
388 } else {
389 /* MUX style (e.g. ALC880) */
390 snd_hda_codec_write_cache(codec, nid, 0,
391 AC_VERB_SET_CONNECT_SEL,
392 imux->items[idx].index);
393 }
394 alc_inv_dmic_sync(codec, true);
395 return 1;
396}
397
398static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 return alc_mux_select(codec, adc_idx,
404 ucontrol->value.enumerated.item[0], false);
405}
406
407/*
408 * set up the input pin config (depending on the given auto-pin type)
409 */
410static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
411 int auto_pin_type)
412{
413 unsigned int val = PIN_IN;
414 if (auto_pin_type == AUTO_PIN_MIC)
415 val |= snd_hda_get_default_vref(codec, nid);
416 snd_hda_set_pin_ctl(codec, nid, val);
417}
418
419/* 105/*
420 * Append the given mixer and verb elements for the later use 106 * Append the given mixer and verb elements for the later use
421 * The mixer array is referred in build_controls(), and init_verbs are 107 * The mixer array is referred in build_controls(), and init_verbs are
@@ -485,171 +171,6 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
485 alc_fix_pll(codec); 171 alc_fix_pll(codec);
486} 172}
487 173
488/*
489 * Jack detections for HP auto-mute and mic-switch
490 */
491
492/* check each pin in the given array; returns true if any of them is plugged */
493static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
494{
495 int i, present = 0;
496
497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
499 if (!nid)
500 break;
501 present |= snd_hda_jack_detect(codec, nid);
502 }
503 return present;
504}
505
506/* standard HP/line-out auto-mute helper */
507static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
508 bool mute, bool hp_out)
509{
510 struct alc_spec *spec = codec->spec;
511 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
512 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
513 int i;
514
515 for (i = 0; i < num_pins; i++) {
516 hda_nid_t nid = pins[i];
517 unsigned int val;
518 if (!nid)
519 break;
520 switch (spec->automute_mode) {
521 case ALC_AUTOMUTE_PIN:
522 /* don't reset VREF value in case it's controlling
523 * the amp (see alc861_fixup_asus_amp_vref_0f())
524 */
525 if (spec->keep_vref_in_automute) {
526 val = snd_hda_codec_read(codec, nid, 0,
527 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
528 val &= ~PIN_HP;
529 } else
530 val = 0;
531 val |= pin_bits;
532 snd_hda_set_pin_ctl(codec, nid, val);
533 break;
534 case ALC_AUTOMUTE_AMP:
535 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
536 HDA_AMP_MUTE, mute_bits);
537 break;
538 case ALC_AUTOMUTE_MIXER:
539 nid = spec->automute_mixer_nid[i];
540 if (!nid)
541 break;
542 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
543 HDA_AMP_MUTE, mute_bits);
544 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
545 HDA_AMP_MUTE, mute_bits);
546 break;
547 }
548 }
549}
550
551/* Toggle outputs muting */
552static void update_outputs(struct hda_codec *codec)
553{
554 struct alc_spec *spec = codec->spec;
555 int on;
556
557 /* Control HP pins/amps depending on master_mute state;
558 * in general, HP pins/amps control should be enabled in all cases,
559 * but currently set only for master_mute, just to be safe
560 */
561 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
562 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
563 spec->autocfg.hp_pins, spec->master_mute, true);
564
565 if (!spec->automute_speaker)
566 on = 0;
567 else
568 on = spec->hp_jack_present | spec->line_jack_present;
569 on |= spec->master_mute;
570 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
571 spec->autocfg.speaker_pins, on, false);
572
573 /* toggle line-out mutes if needed, too */
574 /* if LO is a copy of either HP or Speaker, don't need to handle it */
575 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
576 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
577 return;
578 if (!spec->automute_lo)
579 on = 0;
580 else
581 on = spec->hp_jack_present;
582 on |= spec->master_mute;
583 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
584 spec->autocfg.line_out_pins, on, false);
585}
586
587static void call_update_outputs(struct hda_codec *codec)
588{
589 struct alc_spec *spec = codec->spec;
590 if (spec->automute_hook)
591 spec->automute_hook(codec);
592 else
593 update_outputs(codec);
594}
595
596/* standard HP-automute helper */
597static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
598{
599 struct alc_spec *spec = codec->spec;
600
601 spec->hp_jack_present =
602 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
603 spec->autocfg.hp_pins);
604 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
605 return;
606 call_update_outputs(codec);
607}
608
609/* standard line-out-automute helper */
610static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
611{
612 struct alc_spec *spec = codec->spec;
613
614 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
615 return;
616 /* check LO jack only when it's different from HP */
617 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
618 return;
619
620 spec->line_jack_present =
621 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
622 spec->autocfg.line_out_pins);
623 if (!spec->automute_speaker || !spec->detect_lo)
624 return;
625 call_update_outputs(codec);
626}
627
628#define get_connection_index(codec, mux, nid) \
629 snd_hda_get_conn_index(codec, mux, nid, 0)
630
631/* standard mic auto-switch helper */
632static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
633{
634 struct alc_spec *spec = codec->spec;
635 hda_nid_t *pins = spec->imux_pins;
636
637 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
638 return;
639 if (snd_BUG_ON(!spec->adc_nids))
640 return;
641 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
642 return;
643
644 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
645 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
646 else if (spec->dock_mic_idx >= 0 &&
647 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
648 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
649 else
650 alc_mux_select(codec, 0, spec->int_mic_idx, false);
651}
652
653/* update the master volume per volume-knob's unsol event */ 174/* update the master volume per volume-knob's unsol event */
654static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack) 175static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
655{ 176{
@@ -679,14 +200,6 @@ static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
679 snd_hda_jack_unsol_event(codec, res >> 2); 200 snd_hda_jack_unsol_event(codec, res >> 2);
680} 201}
681 202
682/* call init functions of standard auto-mute helpers */
683static void alc_inithook(struct hda_codec *codec)
684{
685 alc_hp_automute(codec, NULL);
686 alc_line_automute(codec, NULL);
687 alc_mic_automute(codec, NULL);
688}
689
690/* additional initialization for ALC888 variants */ 203/* additional initialization for ALC888 variants */
691static void alc888_coef_init(struct hda_codec *codec) 204static void alc888_coef_init(struct hda_codec *codec)
692{ 205{
@@ -807,366 +320,6 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
807 } 320 }
808} 321}
809 322
810/*
811 * Auto-Mute mode mixer enum support
812 */
813static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_info *uinfo)
815{
816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct alc_spec *spec = codec->spec;
818 static const char * const texts3[] = {
819 "Disabled", "Speaker Only", "Line Out+Speaker"
820 };
821
822 if (spec->automute_speaker_possible && spec->automute_lo_possible)
823 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
824 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
825}
826
827static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_value *ucontrol)
829{
830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct alc_spec *spec = codec->spec;
832 unsigned int val = 0;
833 if (spec->automute_speaker)
834 val++;
835 if (spec->automute_lo)
836 val++;
837
838 ucontrol->value.enumerated.item[0] = val;
839 return 0;
840}
841
842static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
843 struct snd_ctl_elem_value *ucontrol)
844{
845 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
846 struct alc_spec *spec = codec->spec;
847
848 switch (ucontrol->value.enumerated.item[0]) {
849 case 0:
850 if (!spec->automute_speaker && !spec->automute_lo)
851 return 0;
852 spec->automute_speaker = 0;
853 spec->automute_lo = 0;
854 break;
855 case 1:
856 if (spec->automute_speaker_possible) {
857 if (!spec->automute_lo && spec->automute_speaker)
858 return 0;
859 spec->automute_speaker = 1;
860 spec->automute_lo = 0;
861 } else if (spec->automute_lo_possible) {
862 if (spec->automute_lo)
863 return 0;
864 spec->automute_lo = 1;
865 } else
866 return -EINVAL;
867 break;
868 case 2:
869 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
870 return -EINVAL;
871 if (spec->automute_speaker && spec->automute_lo)
872 return 0;
873 spec->automute_speaker = 1;
874 spec->automute_lo = 1;
875 break;
876 default:
877 return -EINVAL;
878 }
879 call_update_outputs(codec);
880 return 1;
881}
882
883static const struct snd_kcontrol_new alc_automute_mode_enum = {
884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
885 .name = "Auto-Mute Mode",
886 .info = alc_automute_mode_info,
887 .get = alc_automute_mode_get,
888 .put = alc_automute_mode_put,
889};
890
891static struct snd_kcontrol_new *
892alc_kcontrol_new(struct alc_spec *spec, const char *name,
893 const struct snd_kcontrol_new *temp)
894{
895 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
896 if (!knew)
897 return NULL;
898 *knew = *temp;
899 knew->name = kstrdup(name, GFP_KERNEL);
900 if (!knew->name)
901 return NULL;
902 return knew;
903}
904
905static int alc_add_automute_mode_enum(struct hda_codec *codec)
906{
907 struct alc_spec *spec = codec->spec;
908
909 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
910 return -ENOMEM;
911 return 0;
912}
913
914/*
915 * Check the availability of HP/line-out auto-mute;
916 * Set up appropriately if really supported
917 */
918static int alc_init_automute(struct hda_codec *codec)
919{
920 struct alc_spec *spec = codec->spec;
921 struct auto_pin_cfg *cfg = &spec->autocfg;
922 int present = 0;
923 int i, err;
924
925 if (cfg->hp_pins[0])
926 present++;
927 if (cfg->line_out_pins[0])
928 present++;
929 if (cfg->speaker_pins[0])
930 present++;
931 if (present < 2) /* need two different output types */
932 return 0;
933
934 if (!cfg->speaker_pins[0] &&
935 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
936 memcpy(cfg->speaker_pins, cfg->line_out_pins,
937 sizeof(cfg->speaker_pins));
938 cfg->speaker_outs = cfg->line_outs;
939 }
940
941 if (!cfg->hp_pins[0] &&
942 cfg->line_out_type == AUTO_PIN_HP_OUT) {
943 memcpy(cfg->hp_pins, cfg->line_out_pins,
944 sizeof(cfg->hp_pins));
945 cfg->hp_outs = cfg->line_outs;
946 }
947
948 spec->automute_mode = ALC_AUTOMUTE_PIN;
949
950 for (i = 0; i < cfg->hp_outs; i++) {
951 hda_nid_t nid = cfg->hp_pins[i];
952 if (!is_jack_detectable(codec, nid))
953 continue;
954 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
955 nid);
956 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
957 alc_hp_automute);
958 spec->detect_hp = 1;
959 }
960
961 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
962 if (cfg->speaker_outs)
963 for (i = 0; i < cfg->line_outs; i++) {
964 hda_nid_t nid = cfg->line_out_pins[i];
965 if (!is_jack_detectable(codec, nid))
966 continue;
967 snd_printdd("realtek: Enable Line-Out "
968 "auto-muting on NID 0x%x\n", nid);
969 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
970 alc_line_automute);
971 spec->detect_lo = 1;
972 }
973 spec->automute_lo_possible = spec->detect_hp;
974 }
975
976 spec->automute_speaker_possible = cfg->speaker_outs &&
977 (spec->detect_hp || spec->detect_lo);
978
979 spec->automute_lo = spec->automute_lo_possible;
980 spec->automute_speaker = spec->automute_speaker_possible;
981
982 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
983 /* create a control for automute mode */
984 err = alc_add_automute_mode_enum(codec);
985 if (err < 0)
986 return err;
987 }
988 return 0;
989}
990
991/* return the position of NID in the list, or -1 if not found */
992static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
993{
994 int i;
995 for (i = 0; i < nums; i++)
996 if (list[i] == nid)
997 return i;
998 return -1;
999}
1000
1001/* check whether dynamic ADC-switching is available */
1002static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1003{
1004 struct alc_spec *spec = codec->spec;
1005 struct hda_input_mux *imux = &spec->private_imux[0];
1006 int i, n, idx;
1007 hda_nid_t cap, pin;
1008
1009 if (imux != spec->input_mux) /* no dynamic imux? */
1010 return false;
1011
1012 for (n = 0; n < spec->num_adc_nids; n++) {
1013 cap = spec->private_capsrc_nids[n];
1014 for (i = 0; i < imux->num_items; i++) {
1015 pin = spec->imux_pins[i];
1016 if (!pin)
1017 return false;
1018 if (get_connection_index(codec, cap, pin) < 0)
1019 break;
1020 }
1021 if (i >= imux->num_items)
1022 return true; /* no ADC-switch is needed */
1023 }
1024
1025 for (i = 0; i < imux->num_items; i++) {
1026 pin = spec->imux_pins[i];
1027 for (n = 0; n < spec->num_adc_nids; n++) {
1028 cap = spec->private_capsrc_nids[n];
1029 idx = get_connection_index(codec, cap, pin);
1030 if (idx >= 0) {
1031 imux->items[i].index = idx;
1032 spec->dyn_adc_idx[i] = n;
1033 break;
1034 }
1035 }
1036 }
1037
1038 snd_printdd("realtek: enabling ADC switching\n");
1039 spec->dyn_adc_switch = 1;
1040 return true;
1041}
1042
1043/* check whether all auto-mic pins are valid; setup indices if OK */
1044static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1045{
1046 struct alc_spec *spec = codec->spec;
1047 const struct hda_input_mux *imux;
1048
1049 if (!spec->auto_mic)
1050 return false;
1051 if (spec->auto_mic_valid_imux)
1052 return true; /* already checked */
1053
1054 /* fill up imux indices */
1055 if (!alc_check_dyn_adc_switch(codec)) {
1056 spec->auto_mic = 0;
1057 return false;
1058 }
1059
1060 imux = spec->input_mux;
1061 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1062 spec->imux_pins, imux->num_items);
1063 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1064 spec->imux_pins, imux->num_items);
1065 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1066 spec->imux_pins, imux->num_items);
1067 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1068 spec->auto_mic = 0;
1069 return false; /* no corresponding imux */
1070 }
1071
1072 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1073 ALC_MIC_EVENT, alc_mic_automute);
1074 if (spec->dock_mic_pin)
1075 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1076 ALC_MIC_EVENT,
1077 alc_mic_automute);
1078
1079 spec->auto_mic_valid_imux = 1;
1080 spec->auto_mic = 1;
1081 return true;
1082}
1083
1084/*
1085 * Check the availability of auto-mic switch;
1086 * Set up if really supported
1087 */
1088static int alc_init_auto_mic(struct hda_codec *codec)
1089{
1090 struct alc_spec *spec = codec->spec;
1091 struct auto_pin_cfg *cfg = &spec->autocfg;
1092 hda_nid_t fixed, ext, dock;
1093 int i;
1094
1095 if (spec->shared_mic_hp)
1096 return 0; /* no auto-mic for the shared I/O */
1097
1098 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1099
1100 fixed = ext = dock = 0;
1101 for (i = 0; i < cfg->num_inputs; i++) {
1102 hda_nid_t nid = cfg->inputs[i].pin;
1103 unsigned int defcfg;
1104 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1105 switch (snd_hda_get_input_pin_attr(defcfg)) {
1106 case INPUT_PIN_ATTR_INT:
1107 if (fixed)
1108 return 0; /* already occupied */
1109 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1110 return 0; /* invalid type */
1111 fixed = nid;
1112 break;
1113 case INPUT_PIN_ATTR_UNUSED:
1114 return 0; /* invalid entry */
1115 case INPUT_PIN_ATTR_DOCK:
1116 if (dock)
1117 return 0; /* already occupied */
1118 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1119 return 0; /* invalid type */
1120 dock = nid;
1121 break;
1122 default:
1123 if (ext)
1124 return 0; /* already occupied */
1125 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1126 return 0; /* invalid type */
1127 ext = nid;
1128 break;
1129 }
1130 }
1131 if (!ext && dock) {
1132 ext = dock;
1133 dock = 0;
1134 }
1135 if (!ext || !fixed)
1136 return 0;
1137 if (!is_jack_detectable(codec, ext))
1138 return 0; /* no unsol support */
1139 if (dock && !is_jack_detectable(codec, dock))
1140 return 0; /* no unsol support */
1141
1142 /* check imux indices */
1143 spec->ext_mic_pin = ext;
1144 spec->int_mic_pin = fixed;
1145 spec->dock_mic_pin = dock;
1146
1147 spec->auto_mic = 1;
1148 if (!alc_auto_mic_check_imux(codec))
1149 return 0;
1150
1151 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1152 ext, fixed, dock);
1153
1154 return 0;
1155}
1156
1157/* check the availabilities of auto-mute and auto-mic switches */
1158static int alc_auto_check_switches(struct hda_codec *codec)
1159{
1160 int err;
1161
1162 err = alc_init_automute(codec);
1163 if (err < 0)
1164 return err;
1165 err = alc_init_auto_mic(codec);
1166 if (err < 0)
1167 return err;
1168 return 0;
1169}
1170 323
1171/* 324/*
1172 * Realtek SSID verification 325 * Realtek SSID verification
@@ -1252,6 +405,15 @@ do_sku:
1252 return 0; 405 return 0;
1253} 406}
1254 407
408/* return the position of NID in the list, or -1 if not found */
409static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
410{
411 int i;
412 for (i = 0; i < nums; i++)
413 if (list[i] == nid)
414 return i;
415 return -1;
416}
1255/* return true if the given NID is found in the list */ 417/* return true if the given NID is found in the list */
1256static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 418static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1257{ 419{
@@ -1354,9 +516,9 @@ do_sku:
1354 * 15 : 1 --> enable the function "Mute internal speaker 516 * 15 : 1 --> enable the function "Mute internal speaker
1355 * when the external headphone out jack is plugged" 517 * when the external headphone out jack is plugged"
1356 */ 518 */
1357 if (!spec->autocfg.hp_pins[0] && 519 if (!spec->gen.autocfg.hp_pins[0] &&
1358 !(spec->autocfg.line_out_pins[0] && 520 !(spec->gen.autocfg.line_out_pins[0] &&
1359 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) { 521 spec->gen.autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1360 hda_nid_t nid; 522 hda_nid_t nid;
1361 tmp = (ass >> 11) & 0x3; /* HP to chassis */ 523 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1362 if (tmp == 0) 524 if (tmp == 0)
@@ -1369,10 +531,10 @@ do_sku:
1369 nid = porti; 531 nid = porti;
1370 else 532 else
1371 return 1; 533 return 1;
1372 if (found_in_nid_list(nid, spec->autocfg.line_out_pins, 534 if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins,
1373 spec->autocfg.line_outs)) 535 spec->gen.autocfg.line_outs))
1374 return 1; 536 return 1;
1375 spec->autocfg.hp_pins[0] = nid; 537 spec->gen.autocfg.hp_pins[0] = nid;
1376 } 538 }
1377 return 1; 539 return 1;
1378} 540}
@@ -1422,252 +584,54 @@ static unsigned int alc_get_coef0(struct hda_codec *codec)
1422} 584}
1423 585
1424/* 586/*
1425 * Digital I/O handling
1426 */ 587 */
1427 588
1428/* set right pin controls for digital I/O */ 589static hda_nid_t get_adc_nid(struct hda_codec *codec, int adc_idx, int imux_idx)
1429static void alc_auto_init_digital(struct hda_codec *codec)
1430{ 590{
1431 struct alc_spec *spec = codec->spec; 591 struct hda_gen_spec *spec = codec->spec;
1432 int i; 592 if (spec->dyn_adc_switch)
1433 hda_nid_t pin, dac; 593 adc_idx = spec->dyn_adc_idx[imux_idx];
1434 594 return spec->adc_nids[adc_idx];
1435 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1436 pin = spec->autocfg.dig_out_pins[i];
1437 if (!pin)
1438 continue;
1439 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
1440 if (!i)
1441 dac = spec->multiout.dig_out_nid;
1442 else
1443 dac = spec->slave_dig_outs[i - 1];
1444 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1445 continue;
1446 snd_hda_codec_write(codec, dac, 0,
1447 AC_VERB_SET_AMP_GAIN_MUTE,
1448 AMP_OUT_UNMUTE);
1449 }
1450 pin = spec->autocfg.dig_in_pin;
1451 if (pin)
1452 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
1453}
1454
1455/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1456static void alc_auto_parse_digital(struct hda_codec *codec)
1457{
1458 struct alc_spec *spec = codec->spec;
1459 int i, err, nums;
1460 hda_nid_t dig_nid;
1461
1462 /* support multiple SPDIFs; the secondary is set up as a slave */
1463 nums = 0;
1464 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1465 hda_nid_t conn[4];
1466 err = snd_hda_get_connections(codec,
1467 spec->autocfg.dig_out_pins[i],
1468 conn, ARRAY_SIZE(conn));
1469 if (err <= 0)
1470 continue;
1471 dig_nid = conn[0]; /* assume the first element is audio-out */
1472 if (!nums) {
1473 spec->multiout.dig_out_nid = dig_nid;
1474 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1475 } else {
1476 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1477 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1478 break;
1479 spec->slave_dig_outs[nums - 1] = dig_nid;
1480 }
1481 nums++;
1482 }
1483
1484 if (spec->autocfg.dig_in_pin) {
1485 dig_nid = codec->start_nid;
1486 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1487 unsigned int wcaps = get_wcaps(codec, dig_nid);
1488 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1489 continue;
1490 if (!(wcaps & AC_WCAP_DIGITAL))
1491 continue;
1492 if (!(wcaps & AC_WCAP_CONN_LIST))
1493 continue;
1494 err = get_connection_index(codec, dig_nid,
1495 spec->autocfg.dig_in_pin);
1496 if (err >= 0) {
1497 spec->dig_in_nid = dig_nid;
1498 break;
1499 }
1500 }
1501 }
1502}
1503
1504/*
1505 * capture mixer elements
1506 */
1507static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1508 struct snd_ctl_elem_info *uinfo)
1509{
1510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1511 struct alc_spec *spec = codec->spec;
1512 unsigned long val;
1513 int err;
1514
1515 mutex_lock(&codec->control_mutex);
1516 if (spec->vol_in_capsrc)
1517 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1518 else
1519 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1520 kcontrol->private_value = val;
1521 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1522 mutex_unlock(&codec->control_mutex);
1523 return err;
1524}
1525
1526static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1527 unsigned int size, unsigned int __user *tlv)
1528{
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 struct alc_spec *spec = codec->spec;
1531 unsigned long val;
1532 int err;
1533
1534 mutex_lock(&codec->control_mutex);
1535 if (spec->vol_in_capsrc)
1536 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1537 else
1538 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1539 kcontrol->private_value = val;
1540 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1541 mutex_unlock(&codec->control_mutex);
1542 return err;
1543} 595}
1544 596
1545typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol, 597static void alc_inv_dmic_sync_adc(struct hda_codec *codec, int adc_idx)
1546 struct snd_ctl_elem_value *ucontrol);
1547
1548static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1549 struct snd_ctl_elem_value *ucontrol,
1550 getput_call_t func, bool is_put)
1551{ 598{
1552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1553 struct alc_spec *spec = codec->spec; 599 struct alc_spec *spec = codec->spec;
1554 int i, err = 0; 600 struct hda_input_mux *imux = &spec->gen.input_mux;
1555 601 struct nid_path *path;
1556 mutex_lock(&codec->control_mutex); 602 hda_nid_t nid;
1557 if (is_put && spec->dyn_adc_switch) { 603 int i, dir, parm;
1558 for (i = 0; i < spec->num_adc_nids; i++) { 604 unsigned int val;
1559 kcontrol->private_value =
1560 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1561 3, 0, HDA_INPUT);
1562 err = func(kcontrol, ucontrol);
1563 if (err < 0)
1564 goto error;
1565 }
1566 } else {
1567 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1568 if (spec->vol_in_capsrc)
1569 kcontrol->private_value =
1570 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1571 3, 0, HDA_OUTPUT);
1572 else
1573 kcontrol->private_value =
1574 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1575 3, 0, HDA_INPUT);
1576 err = func(kcontrol, ucontrol);
1577 }
1578 if (err >= 0 && is_put)
1579 alc_inv_dmic_sync(codec, false);
1580 error:
1581 mutex_unlock(&codec->control_mutex);
1582 return err;
1583}
1584
1585static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1586 struct snd_ctl_elem_value *ucontrol)
1587{
1588 return alc_cap_getput_caller(kcontrol, ucontrol,
1589 snd_hda_mixer_amp_volume_get, false);
1590}
1591
1592static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1594{
1595 return alc_cap_getput_caller(kcontrol, ucontrol,
1596 snd_hda_mixer_amp_volume_put, true);
1597}
1598
1599/* capture mixer elements */
1600#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1601
1602static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1603 struct snd_ctl_elem_value *ucontrol)
1604{
1605 return alc_cap_getput_caller(kcontrol, ucontrol,
1606 snd_hda_mixer_amp_switch_get, false);
1607}
1608
1609static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1611{
1612 return alc_cap_getput_caller(kcontrol, ucontrol,
1613 snd_hda_mixer_amp_switch_put, true);
1614}
1615 605
1616#define _DEFINE_CAPMIX(num) \ 606 for (i = 0; i < imux->num_items; i++) {
1617 { \ 607 if (spec->gen.imux_pins[i] == spec->inv_dmic_pin)
1618 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 608 break;
1619 .name = "Capture Switch", \
1620 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1621 .count = num, \
1622 .info = alc_cap_sw_info, \
1623 .get = alc_cap_sw_get, \
1624 .put = alc_cap_sw_put, \
1625 }, \
1626 { \
1627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1628 .name = "Capture Volume", \
1629 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1630 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1631 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1632 .count = num, \
1633 .info = alc_cap_vol_info, \
1634 .get = alc_cap_vol_get, \
1635 .put = alc_cap_vol_put, \
1636 .tlv = { .c = alc_cap_vol_tlv }, \
1637 } 609 }
610 if (i >= imux->num_items)
611 return;
1638 612
1639#define _DEFINE_CAPSRC(num) \ 613 path = snd_hda_get_nid_path(codec, spec->inv_dmic_pin,
1640 { \ 614 get_adc_nid(codec, adc_idx, i));
1641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 615 val = path->ctls[NID_PATH_MUTE_CTL];
1642 /* .name = "Capture Source", */ \ 616 if (!val)
1643 .name = "Input Source", \ 617 return;
1644 .count = num, \ 618 nid = get_amp_nid_(val);
1645 .info = alc_mux_enum_info, \ 619 dir = get_amp_direction_(val);
1646 .get = alc_mux_enum_get, \ 620 parm = AC_AMP_SET_RIGHT |
1647 .put = alc_mux_enum_put, \ 621 (dir == HDA_OUTPUT ? AC_AMP_SET_OUTPUT : AC_AMP_SET_INPUT);
1648 }
1649 622
1650#define DEFINE_CAPMIX(num) \ 623 /* flush all cached amps at first */
1651static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \ 624 snd_hda_codec_flush_cache(codec);
1652 _DEFINE_CAPMIX(num), \
1653 _DEFINE_CAPSRC(num), \
1654 { } /* end */ \
1655}
1656 625
1657#define DEFINE_CAPMIX_NOSRC(num) \ 626 /* we care only right channel */
1658static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \ 627 val = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1659 _DEFINE_CAPMIX(num), \ 628 if (val & 0x80) /* if already muted, we don't need to touch */
1660 { } /* end */ \ 629 return;
630 val |= 0x80;
631 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
632 parm | val);
1661} 633}
1662 634
1663/* up to three ADCs */
1664DEFINE_CAPMIX(1);
1665DEFINE_CAPMIX(2);
1666DEFINE_CAPMIX(3);
1667DEFINE_CAPMIX_NOSRC(1);
1668DEFINE_CAPMIX_NOSRC(2);
1669DEFINE_CAPMIX_NOSRC(3);
1670
1671/* 635/*
1672 * Inverted digital-mic handling 636 * Inverted digital-mic handling
1673 * 637 *
@@ -1686,43 +650,31 @@ DEFINE_CAPMIX_NOSRC(3);
1686static void alc_inv_dmic_sync(struct hda_codec *codec, bool force) 650static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1687{ 651{
1688 struct alc_spec *spec = codec->spec; 652 struct alc_spec *spec = codec->spec;
1689 int i; 653 int src, nums;
1690 654
1691 if (!spec->inv_dmic_fixup) 655 if (!spec->inv_dmic_fixup)
1692 return; 656 return;
1693 if (!spec->inv_dmic_muted && !force) 657 if (!spec->inv_dmic_muted && !force)
1694 return; 658 return;
1695 for (i = 0; i < spec->num_adc_nids; i++) { 659 nums = spec->gen.dyn_adc_switch ? 1 : spec->gen.num_adc_nids;
1696 int src = spec->dyn_adc_switch ? 0 : i; 660 for (src = 0; src < nums; src++) {
1697 bool dmic_fixup = false; 661 bool dmic_fixup = false;
1698 hda_nid_t nid;
1699 int parm, dir, v;
1700 662
1701 if (spec->inv_dmic_muted && 663 if (spec->inv_dmic_muted &&
1702 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin) 664 spec->gen.imux_pins[spec->gen.cur_mux[src]] == spec->inv_dmic_pin)
1703 dmic_fixup = true; 665 dmic_fixup = true;
1704 if (!dmic_fixup && !force) 666 if (!dmic_fixup && !force)
1705 continue; 667 continue;
1706 if (spec->vol_in_capsrc) { 668 alc_inv_dmic_sync_adc(codec, src);
1707 nid = spec->capsrc_nids[i];
1708 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1709 dir = HDA_OUTPUT;
1710 } else {
1711 nid = spec->adc_nids[i];
1712 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1713 dir = HDA_INPUT;
1714 }
1715 /* we care only right channel */
1716 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1717 if (v & 0x80) /* if already muted, we don't need to touch */
1718 continue;
1719 if (dmic_fixup) /* add mute for d-mic */
1720 v |= 0x80;
1721 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1722 parm | v);
1723 } 669 }
1724} 670}
1725 671
672static void alc_inv_dmic_hook(struct hda_codec *codec,
673 struct snd_ctl_elem_value *ucontrol)
674{
675 alc_inv_dmic_sync(codec, false);
676}
677
1726static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol, 678static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol) 679 struct snd_ctl_elem_value *ucontrol)
1728{ 680{
@@ -1749,6 +701,7 @@ static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1749 701
1750static const struct snd_kcontrol_new alc_inv_dmic_sw = { 702static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 703 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
704 .name = "Inverted Internal Mic Capture Switch",
1752 .info = snd_ctl_boolean_mono_info, 705 .info = snd_ctl_boolean_mono_info,
1753 .get = alc_inv_dmic_sw_get, 706 .get = alc_inv_dmic_sw_get,
1754 .put = alc_inv_dmic_sw_put, 707 .put = alc_inv_dmic_sw_put,
@@ -1758,51 +711,23 @@ static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1758{ 711{
1759 struct alc_spec *spec = codec->spec; 712 struct alc_spec *spec = codec->spec;
1760 713
1761 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch", 714 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &alc_inv_dmic_sw))
1762 &alc_inv_dmic_sw))
1763 return -ENOMEM; 715 return -ENOMEM;
1764 spec->inv_dmic_fixup = 1; 716 spec->inv_dmic_fixup = 1;
1765 spec->inv_dmic_muted = 0; 717 spec->inv_dmic_muted = 0;
1766 spec->inv_dmic_pin = nid; 718 spec->inv_dmic_pin = nid;
719 spec->gen.cap_sync_hook = alc_inv_dmic_hook;
1767 return 0; 720 return 0;
1768} 721}
1769 722
1770/* typically the digital mic is put at node 0x12 */ 723/* typically the digital mic is put at node 0x12 */
1771static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec, 724static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1772 const struct alc_fixup *fix, int action) 725 const struct hda_fixup *fix, int action)
1773{ 726{
1774 if (action == ALC_FIXUP_ACT_PROBE) 727 if (action == HDA_FIXUP_ACT_PROBE)
1775 alc_add_inv_dmic_mixer(codec, 0x12); 728 alc_add_inv_dmic_mixer(codec, 0x12);
1776} 729}
1777 730
1778/*
1779 * virtual master controls
1780 */
1781
1782/*
1783 * slave controls for virtual master
1784 */
1785static const char * const alc_slave_pfxs[] = {
1786 "Front", "Surround", "Center", "LFE", "Side",
1787 "Headphone", "Speaker", "Mono", "Line Out",
1788 "CLFE", "Bass Speaker", "PCM",
1789 NULL,
1790};
1791
1792/*
1793 * build control elements
1794 */
1795
1796#define NID_MAPPING (-1)
1797
1798#define SUBDEV_SPEAKER_ (0 << 6)
1799#define SUBDEV_HP_ (1 << 6)
1800#define SUBDEV_LINE_ (2 << 6)
1801#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1802#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1803#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1804
1805static void alc_free_kctls(struct hda_codec *codec);
1806 731
1807#ifdef CONFIG_SND_HDA_INPUT_BEEP 732#ifdef CONFIG_SND_HDA_INPUT_BEEP
1808/* additional beep mixers; the actual parameters are overwritten at build */ 733/* additional beep mixers; the actual parameters are overwritten at build */
@@ -1813,45 +738,20 @@ static const struct snd_kcontrol_new alc_beep_mixer[] = {
1813}; 738};
1814#endif 739#endif
1815 740
1816static int __alc_build_controls(struct hda_codec *codec) 741static int alc_build_controls(struct hda_codec *codec)
1817{ 742{
1818 struct alc_spec *spec = codec->spec; 743 struct alc_spec *spec = codec->spec;
1819 struct snd_kcontrol *kctl = NULL; 744 int i, err;
1820 const struct snd_kcontrol_new *knew; 745
1821 int i, j, err; 746 err = snd_hda_gen_build_controls(codec);
1822 unsigned int u; 747 if (err < 0)
1823 hda_nid_t nid; 748 return err;
1824 749
1825 for (i = 0; i < spec->num_mixers; i++) { 750 for (i = 0; i < spec->num_mixers; i++) {
1826 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 751 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1827 if (err < 0) 752 if (err < 0)
1828 return err; 753 return err;
1829 } 754 }
1830 if (spec->cap_mixer) {
1831 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1832 if (err < 0)
1833 return err;
1834 }
1835 if (spec->multiout.dig_out_nid) {
1836 err = snd_hda_create_dig_out_ctls(codec,
1837 spec->multiout.dig_out_nid,
1838 spec->multiout.dig_out_nid,
1839 spec->pcm_rec[1].pcm_type);
1840 if (err < 0)
1841 return err;
1842 if (!spec->no_analog) {
1843 err = snd_hda_create_spdif_share_sw(codec,
1844 &spec->multiout);
1845 if (err < 0)
1846 return err;
1847 spec->multiout.share_spdif = 1;
1848 }
1849 }
1850 if (spec->dig_in_nid) {
1851 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1852 if (err < 0)
1853 return err;
1854 }
1855 755
1856#ifdef CONFIG_SND_HDA_INPUT_BEEP 756#ifdef CONFIG_SND_HDA_INPUT_BEEP
1857 /* create beep controls if needed */ 757 /* create beep controls if needed */
@@ -1870,130 +770,7 @@ static int __alc_build_controls(struct hda_codec *codec)
1870 } 770 }
1871#endif 771#endif
1872 772
1873 /* if we have no master control, let's create it */ 773 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
1874 if (!spec->no_analog &&
1875 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1876 unsigned int vmaster_tlv[4];
1877 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1878 HDA_OUTPUT, vmaster_tlv);
1879 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1880 vmaster_tlv, alc_slave_pfxs,
1881 "Playback Volume");
1882 if (err < 0)
1883 return err;
1884 }
1885 if (!spec->no_analog &&
1886 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1887 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1888 NULL, alc_slave_pfxs,
1889 "Playback Switch",
1890 true, &spec->vmaster_mute.sw_kctl);
1891 if (err < 0)
1892 return err;
1893 }
1894
1895 /* assign Capture Source enums to NID */
1896 if (spec->capsrc_nids || spec->adc_nids) {
1897 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1898 if (!kctl)
1899 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1900 for (i = 0; kctl && i < kctl->count; i++) {
1901 err = snd_hda_add_nid(codec, kctl, i,
1902 get_capsrc(spec, i));
1903 if (err < 0)
1904 return err;
1905 }
1906 }
1907 if (spec->cap_mixer && spec->adc_nids) {
1908 const char *kname = kctl ? kctl->id.name : NULL;
1909 for (knew = spec->cap_mixer; knew->name; knew++) {
1910 if (kname && strcmp(knew->name, kname) == 0)
1911 continue;
1912 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1913 for (i = 0; kctl && i < kctl->count; i++) {
1914 err = snd_hda_add_nid(codec, kctl, i,
1915 spec->adc_nids[i]);
1916 if (err < 0)
1917 return err;
1918 }
1919 }
1920 }
1921
1922 /* other nid->control mapping */
1923 for (i = 0; i < spec->num_mixers; i++) {
1924 for (knew = spec->mixers[i]; knew->name; knew++) {
1925 if (knew->iface != NID_MAPPING)
1926 continue;
1927 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1928 if (kctl == NULL)
1929 continue;
1930 u = knew->subdevice;
1931 for (j = 0; j < 4; j++, u >>= 8) {
1932 nid = u & 0x3f;
1933 if (nid == 0)
1934 continue;
1935 switch (u & 0xc0) {
1936 case SUBDEV_SPEAKER_:
1937 nid = spec->autocfg.speaker_pins[nid];
1938 break;
1939 case SUBDEV_LINE_:
1940 nid = spec->autocfg.line_out_pins[nid];
1941 break;
1942 case SUBDEV_HP_:
1943 nid = spec->autocfg.hp_pins[nid];
1944 break;
1945 default:
1946 continue;
1947 }
1948 err = snd_hda_add_nid(codec, kctl, 0, nid);
1949 if (err < 0)
1950 return err;
1951 }
1952 u = knew->private_value;
1953 for (j = 0; j < 4; j++, u >>= 8) {
1954 nid = u & 0xff;
1955 if (nid == 0)
1956 continue;
1957 err = snd_hda_add_nid(codec, kctl, 0, nid);
1958 if (err < 0)
1959 return err;
1960 }
1961 }
1962 }
1963
1964 alc_free_kctls(codec); /* no longer needed */
1965
1966 return 0;
1967}
1968
1969static int alc_build_jacks(struct hda_codec *codec)
1970{
1971 struct alc_spec *spec = codec->spec;
1972
1973 if (spec->shared_mic_hp) {
1974 int err;
1975 int nid = spec->autocfg.inputs[1].pin;
1976 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1977 if (err < 0)
1978 return err;
1979 err = snd_hda_jack_detect_enable(codec, nid, 0);
1980 if (err < 0)
1981 return err;
1982 }
1983
1984 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1985}
1986
1987static int alc_build_controls(struct hda_codec *codec)
1988{
1989 int err = __alc_build_controls(codec);
1990 if (err < 0)
1991 return err;
1992
1993 err = alc_build_jacks(codec);
1994 if (err < 0)
1995 return err;
1996 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1997 return 0; 774 return 0;
1998} 775}
1999 776
@@ -2002,9 +779,6 @@ static int alc_build_controls(struct hda_codec *codec)
2002 * Common callbacks 779 * Common callbacks
2003 */ 780 */
2004 781
2005static void alc_init_special_input_src(struct hda_codec *codec);
2006static void alc_auto_init_std(struct hda_codec *codec);
2007
2008static int alc_init(struct hda_codec *codec) 782static int alc_init(struct hda_codec *codec)
2009{ 783{
2010 struct alc_spec *spec = codec->spec; 784 struct alc_spec *spec = codec->spec;
@@ -2015,347 +789,9 @@ static int alc_init(struct hda_codec *codec)
2015 alc_fix_pll(codec); 789 alc_fix_pll(codec);
2016 alc_auto_init_amp(codec, spec->init_amp); 790 alc_auto_init_amp(codec, spec->init_amp);
2017 791
2018 snd_hda_gen_apply_verbs(codec); 792 snd_hda_gen_init(codec);
2019 alc_init_special_input_src(codec);
2020 alc_auto_init_std(codec);
2021
2022 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2023
2024 hda_call_check_power_status(codec, 0x01);
2025 return 0;
2026}
2027
2028#ifdef CONFIG_PM
2029static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2030{
2031 struct alc_spec *spec = codec->spec;
2032 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2033}
2034#endif
2035
2036/*
2037 * Analog playback callbacks
2038 */
2039static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
2040 struct hda_codec *codec,
2041 struct snd_pcm_substream *substream)
2042{
2043 struct alc_spec *spec = codec->spec;
2044 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2045 hinfo);
2046}
2047
2048static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2049 struct hda_codec *codec,
2050 unsigned int stream_tag,
2051 unsigned int format,
2052 struct snd_pcm_substream *substream)
2053{
2054 struct alc_spec *spec = codec->spec;
2055 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2056 stream_tag, format, substream);
2057}
2058 793
2059static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 794 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
2060 struct hda_codec *codec,
2061 struct snd_pcm_substream *substream)
2062{
2063 struct alc_spec *spec = codec->spec;
2064 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2065}
2066
2067/*
2068 * Digital out
2069 */
2070static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2071 struct hda_codec *codec,
2072 struct snd_pcm_substream *substream)
2073{
2074 struct alc_spec *spec = codec->spec;
2075 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2076}
2077
2078static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2079 struct hda_codec *codec,
2080 unsigned int stream_tag,
2081 unsigned int format,
2082 struct snd_pcm_substream *substream)
2083{
2084 struct alc_spec *spec = codec->spec;
2085 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2086 stream_tag, format, substream);
2087}
2088
2089static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2090 struct hda_codec *codec,
2091 struct snd_pcm_substream *substream)
2092{
2093 struct alc_spec *spec = codec->spec;
2094 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2095}
2096
2097static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2098 struct hda_codec *codec,
2099 struct snd_pcm_substream *substream)
2100{
2101 struct alc_spec *spec = codec->spec;
2102 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2103}
2104
2105/*
2106 * Analog capture
2107 */
2108static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2109 struct hda_codec *codec,
2110 unsigned int stream_tag,
2111 unsigned int format,
2112 struct snd_pcm_substream *substream)
2113{
2114 struct alc_spec *spec = codec->spec;
2115
2116 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2117 stream_tag, 0, format);
2118 return 0;
2119}
2120
2121static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2122 struct hda_codec *codec,
2123 struct snd_pcm_substream *substream)
2124{
2125 struct alc_spec *spec = codec->spec;
2126
2127 snd_hda_codec_cleanup_stream(codec,
2128 spec->adc_nids[substream->number + 1]);
2129 return 0;
2130}
2131
2132/* analog capture with dynamic dual-adc changes */
2133static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2134 struct hda_codec *codec,
2135 unsigned int stream_tag,
2136 unsigned int format,
2137 struct snd_pcm_substream *substream)
2138{
2139 struct alc_spec *spec = codec->spec;
2140 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
2141 spec->cur_adc_stream_tag = stream_tag;
2142 spec->cur_adc_format = format;
2143 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2144 return 0;
2145}
2146
2147static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2148 struct hda_codec *codec,
2149 struct snd_pcm_substream *substream)
2150{
2151 struct alc_spec *spec = codec->spec;
2152 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2153 spec->cur_adc = 0;
2154 return 0;
2155}
2156
2157static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
2158 .substreams = 1,
2159 .channels_min = 2,
2160 .channels_max = 2,
2161 .nid = 0, /* fill later */
2162 .ops = {
2163 .prepare = dyn_adc_capture_pcm_prepare,
2164 .cleanup = dyn_adc_capture_pcm_cleanup
2165 },
2166};
2167
2168/*
2169 */
2170static const struct hda_pcm_stream alc_pcm_analog_playback = {
2171 .substreams = 1,
2172 .channels_min = 2,
2173 .channels_max = 8,
2174 /* NID is set in alc_build_pcms */
2175 .ops = {
2176 .open = alc_playback_pcm_open,
2177 .prepare = alc_playback_pcm_prepare,
2178 .cleanup = alc_playback_pcm_cleanup
2179 },
2180};
2181
2182static const struct hda_pcm_stream alc_pcm_analog_capture = {
2183 .substreams = 1,
2184 .channels_min = 2,
2185 .channels_max = 2,
2186 /* NID is set in alc_build_pcms */
2187};
2188
2189static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
2190 .substreams = 1,
2191 .channels_min = 2,
2192 .channels_max = 2,
2193 /* NID is set in alc_build_pcms */
2194};
2195
2196static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
2197 .substreams = 2, /* can be overridden */
2198 .channels_min = 2,
2199 .channels_max = 2,
2200 /* NID is set in alc_build_pcms */
2201 .ops = {
2202 .prepare = alc_alt_capture_pcm_prepare,
2203 .cleanup = alc_alt_capture_pcm_cleanup
2204 },
2205};
2206
2207static const struct hda_pcm_stream alc_pcm_digital_playback = {
2208 .substreams = 1,
2209 .channels_min = 2,
2210 .channels_max = 2,
2211 /* NID is set in alc_build_pcms */
2212 .ops = {
2213 .open = alc_dig_playback_pcm_open,
2214 .close = alc_dig_playback_pcm_close,
2215 .prepare = alc_dig_playback_pcm_prepare,
2216 .cleanup = alc_dig_playback_pcm_cleanup
2217 },
2218};
2219
2220static const struct hda_pcm_stream alc_pcm_digital_capture = {
2221 .substreams = 1,
2222 .channels_min = 2,
2223 .channels_max = 2,
2224 /* NID is set in alc_build_pcms */
2225};
2226
2227/* Used by alc_build_pcms to flag that a PCM has no playback stream */
2228static const struct hda_pcm_stream alc_pcm_null_stream = {
2229 .substreams = 0,
2230 .channels_min = 0,
2231 .channels_max = 0,
2232};
2233
2234static int alc_build_pcms(struct hda_codec *codec)
2235{
2236 struct alc_spec *spec = codec->spec;
2237 struct hda_pcm *info = spec->pcm_rec;
2238 const struct hda_pcm_stream *p;
2239 bool have_multi_adcs;
2240 int i;
2241
2242 codec->num_pcms = 1;
2243 codec->pcm_info = info;
2244
2245 if (spec->no_analog)
2246 goto skip_analog;
2247
2248 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2249 "%s Analog", codec->chip_name);
2250 info->name = spec->stream_name_analog;
2251
2252 if (spec->multiout.num_dacs > 0) {
2253 p = spec->stream_analog_playback;
2254 if (!p)
2255 p = &alc_pcm_analog_playback;
2256 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2257 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2258 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2259 spec->multiout.max_channels;
2260 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2261 spec->autocfg.line_outs == 2)
2262 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2263 snd_pcm_2_1_chmaps;
2264 }
2265 if (spec->adc_nids) {
2266 p = spec->stream_analog_capture;
2267 if (!p) {
2268 if (spec->dyn_adc_switch)
2269 p = &dyn_adc_pcm_analog_capture;
2270 else
2271 p = &alc_pcm_analog_capture;
2272 }
2273 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2274 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2275 }
2276
2277 if (spec->channel_mode) {
2278 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2279 for (i = 0; i < spec->num_channel_mode; i++) {
2280 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2281 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2282 }
2283 }
2284 }
2285
2286 skip_analog:
2287 /* SPDIF for stream index #1 */
2288 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2289 snprintf(spec->stream_name_digital,
2290 sizeof(spec->stream_name_digital),
2291 "%s Digital", codec->chip_name);
2292 codec->num_pcms = 2;
2293 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
2294 info = spec->pcm_rec + 1;
2295 info->name = spec->stream_name_digital;
2296 if (spec->dig_out_type)
2297 info->pcm_type = spec->dig_out_type;
2298 else
2299 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2300 if (spec->multiout.dig_out_nid) {
2301 p = spec->stream_digital_playback;
2302 if (!p)
2303 p = &alc_pcm_digital_playback;
2304 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2306 }
2307 if (spec->dig_in_nid) {
2308 p = spec->stream_digital_capture;
2309 if (!p)
2310 p = &alc_pcm_digital_capture;
2311 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2312 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2313 }
2314 /* FIXME: do we need this for all Realtek codec models? */
2315 codec->spdif_status_reset = 1;
2316 }
2317
2318 if (spec->no_analog)
2319 return 0;
2320
2321 /* If the use of more than one ADC is requested for the current
2322 * model, configure a second analog capture-only PCM.
2323 */
2324 have_multi_adcs = (spec->num_adc_nids > 1) &&
2325 !spec->dyn_adc_switch && !spec->auto_mic &&
2326 (!spec->input_mux || spec->input_mux->num_items > 1);
2327 /* Additional Analaog capture for index #2 */
2328 if (spec->alt_dac_nid || have_multi_adcs) {
2329 codec->num_pcms = 3;
2330 info = spec->pcm_rec + 2;
2331 info->name = spec->stream_name_analog;
2332 if (spec->alt_dac_nid) {
2333 p = spec->stream_analog_alt_playback;
2334 if (!p)
2335 p = &alc_pcm_analog_alt_playback;
2336 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
2337 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2338 spec->alt_dac_nid;
2339 } else {
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2341 alc_pcm_null_stream;
2342 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2343 }
2344 if (have_multi_adcs) {
2345 p = spec->stream_analog_alt_capture;
2346 if (!p)
2347 p = &alc_pcm_analog_alt_capture;
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
2349 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2350 spec->adc_nids[1];
2351 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2352 spec->num_adc_nids - 1;
2353 } else {
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2355 alc_pcm_null_stream;
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2357 }
2358 }
2359 795
2360 return 0; 796 return 0;
2361} 797}
@@ -2369,31 +805,6 @@ static inline void alc_shutup(struct hda_codec *codec)
2369 snd_hda_shutup_pins(codec); 805 snd_hda_shutup_pins(codec);
2370} 806}
2371 807
2372static void alc_free_kctls(struct hda_codec *codec)
2373{
2374 struct alc_spec *spec = codec->spec;
2375
2376 if (spec->kctls.list) {
2377 struct snd_kcontrol_new *kctl = spec->kctls.list;
2378 int i;
2379 for (i = 0; i < spec->kctls.used; i++)
2380 kfree(kctl[i].name);
2381 }
2382 snd_array_free(&spec->kctls);
2383}
2384
2385static void alc_free_bind_ctls(struct hda_codec *codec)
2386{
2387 struct alc_spec *spec = codec->spec;
2388 if (spec->bind_ctls.list) {
2389 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2390 int i;
2391 for (i = 0; i < spec->bind_ctls.used; i++)
2392 kfree(ctl[i]);
2393 }
2394 snd_array_free(&spec->bind_ctls);
2395}
2396
2397static void alc_free(struct hda_codec *codec) 808static void alc_free(struct hda_codec *codec)
2398{ 809{
2399 struct alc_spec *spec = codec->spec; 810 struct alc_spec *spec = codec->spec;
@@ -2401,11 +812,9 @@ static void alc_free(struct hda_codec *codec)
2401 if (!spec) 812 if (!spec)
2402 return; 813 return;
2403 814
2404 alc_free_kctls(codec); 815 snd_hda_gen_spec_free(&spec->gen);
2405 alc_free_bind_ctls(codec);
2406 snd_hda_gen_free(&spec->gen);
2407 kfree(spec);
2408 snd_hda_detach_beep_device(codec); 816 snd_hda_detach_beep_device(codec);
817 kfree(spec);
2409} 818}
2410 819
2411#ifdef CONFIG_PM 820#ifdef CONFIG_PM
@@ -2441,16 +850,14 @@ static int alc_resume(struct hda_codec *codec)
2441 */ 850 */
2442static const struct hda_codec_ops alc_patch_ops = { 851static const struct hda_codec_ops alc_patch_ops = {
2443 .build_controls = alc_build_controls, 852 .build_controls = alc_build_controls,
2444 .build_pcms = alc_build_pcms, 853 .build_pcms = snd_hda_gen_build_pcms,
2445 .init = alc_init, 854 .init = alc_init,
2446 .free = alc_free, 855 .free = alc_free,
2447 .unsol_event = snd_hda_jack_unsol_event, 856 .unsol_event = snd_hda_jack_unsol_event,
2448#ifdef CONFIG_PM 857#ifdef CONFIG_PM
2449 .resume = alc_resume, 858 .resume = alc_resume,
2450#endif
2451#ifdef CONFIG_PM
2452 .suspend = alc_suspend, 859 .suspend = alc_suspend,
2453 .check_power_status = alc_check_power_status, 860 .check_power_status = snd_hda_gen_check_power_status,
2454#endif 861#endif
2455 .reboot_notify = alc_shutup, 862 .reboot_notify = alc_shutup,
2456}; 863};
@@ -2510,1727 +917,6 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec)
2510 return 0; 917 return 0;
2511} 918}
2512 919
2513/*
2514 * Automatic parse of I/O pins from the BIOS configuration
2515 */
2516
2517enum {
2518 ALC_CTL_WIDGET_VOL,
2519 ALC_CTL_WIDGET_MUTE,
2520 ALC_CTL_BIND_MUTE,
2521 ALC_CTL_BIND_VOL,
2522 ALC_CTL_BIND_SW,
2523};
2524static const struct snd_kcontrol_new alc_control_templates[] = {
2525 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2526 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2527 HDA_BIND_MUTE(NULL, 0, 0, 0),
2528 HDA_BIND_VOL(NULL, 0),
2529 HDA_BIND_SW(NULL, 0),
2530};
2531
2532/* add dynamic controls */
2533static int add_control(struct alc_spec *spec, int type, const char *name,
2534 int cidx, unsigned long val)
2535{
2536 struct snd_kcontrol_new *knew;
2537
2538 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
2539 if (!knew)
2540 return -ENOMEM;
2541 knew->index = cidx;
2542 if (get_amp_nid_(val))
2543 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2544 knew->private_value = val;
2545 return 0;
2546}
2547
2548static int add_control_with_pfx(struct alc_spec *spec, int type,
2549 const char *pfx, const char *dir,
2550 const char *sfx, int cidx, unsigned long val)
2551{
2552 char name[32];
2553 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
2554 return add_control(spec, type, name, cidx, val);
2555}
2556
2557#define add_pb_vol_ctrl(spec, type, pfx, val) \
2558 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2559#define add_pb_sw_ctrl(spec, type, pfx, val) \
2560 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2561#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2562 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2563#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2564 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2565
2566static const char * const channel_name[4] = {
2567 "Front", "Surround", "CLFE", "Side"
2568};
2569
2570static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2571 bool can_be_master, int *index)
2572{
2573 struct auto_pin_cfg *cfg = &spec->autocfg;
2574
2575 *index = 0;
2576 if (cfg->line_outs == 1 && !spec->multi_ios &&
2577 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
2578 return "Master";
2579
2580 switch (cfg->line_out_type) {
2581 case AUTO_PIN_SPEAKER_OUT:
2582 if (cfg->line_outs == 1)
2583 return "Speaker";
2584 if (cfg->line_outs == 2)
2585 return ch ? "Bass Speaker" : "Speaker";
2586 break;
2587 case AUTO_PIN_HP_OUT:
2588 /* for multi-io case, only the primary out */
2589 if (ch && spec->multi_ios)
2590 break;
2591 *index = ch;
2592 return "Headphone";
2593 default:
2594 if (cfg->line_outs == 1 && !spec->multi_ios)
2595 return "PCM";
2596 break;
2597 }
2598 if (ch >= ARRAY_SIZE(channel_name)) {
2599 snd_BUG();
2600 return "PCM";
2601 }
2602
2603 return channel_name[ch];
2604}
2605
2606#ifdef CONFIG_PM
2607/* add the powersave loopback-list entry */
2608static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2609{
2610 struct hda_amp_list *list;
2611
2612 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2613 return;
2614 list = spec->loopback_list + spec->num_loopbacks;
2615 list->nid = mix;
2616 list->dir = HDA_INPUT;
2617 list->idx = idx;
2618 spec->num_loopbacks++;
2619 spec->loopback.amplist = spec->loopback_list;
2620}
2621#else
2622#define add_loopback_list(spec, mix, idx) /* NOP */
2623#endif
2624
2625/* create input playback/capture controls for the given pin */
2626static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
2627 const char *ctlname, int ctlidx,
2628 int idx, hda_nid_t mix_nid)
2629{
2630 int err;
2631
2632 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
2633 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2634 if (err < 0)
2635 return err;
2636 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
2637 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2638 if (err < 0)
2639 return err;
2640 add_loopback_list(spec, mix_nid, idx);
2641 return 0;
2642}
2643
2644static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
2645{
2646 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2647 return (pincap & AC_PINCAP_IN) != 0;
2648}
2649
2650/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
2651static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2652{
2653 struct alc_spec *spec = codec->spec;
2654 hda_nid_t nid;
2655 hda_nid_t *adc_nids = spec->private_adc_nids;
2656 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2657 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2658 int i, nums = 0;
2659
2660 nid = codec->start_nid;
2661 for (i = 0; i < codec->num_nodes; i++, nid++) {
2662 hda_nid_t src;
2663 unsigned int caps = get_wcaps(codec, nid);
2664 int type = get_wcaps_type(caps);
2665
2666 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2667 continue;
2668 adc_nids[nums] = nid;
2669 cap_nids[nums] = nid;
2670 src = nid;
2671 for (;;) {
2672 int n;
2673 type = get_wcaps_type(get_wcaps(codec, src));
2674 if (type == AC_WID_PIN)
2675 break;
2676 if (type == AC_WID_AUD_SEL) {
2677 cap_nids[nums] = src;
2678 break;
2679 }
2680 n = snd_hda_get_num_conns(codec, src);
2681 if (n > 1) {
2682 cap_nids[nums] = src;
2683 break;
2684 } else if (n != 1)
2685 break;
2686 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2687 break;
2688 }
2689 if (++nums >= max_nums)
2690 break;
2691 }
2692 spec->adc_nids = spec->private_adc_nids;
2693 spec->capsrc_nids = spec->private_capsrc_nids;
2694 spec->num_adc_nids = nums;
2695 return nums;
2696}
2697
2698/* create playback/capture controls for input pins */
2699static int alc_auto_create_input_ctls(struct hda_codec *codec)
2700{
2701 struct alc_spec *spec = codec->spec;
2702 const struct auto_pin_cfg *cfg = &spec->autocfg;
2703 hda_nid_t mixer = spec->mixer_nid;
2704 struct hda_input_mux *imux = &spec->private_imux[0];
2705 int num_adcs;
2706 int i, c, err, idx, type_idx = 0;
2707 const char *prev_label = NULL;
2708
2709 num_adcs = alc_auto_fill_adc_caps(codec);
2710 if (num_adcs < 0)
2711 return 0;
2712
2713 for (i = 0; i < cfg->num_inputs; i++) {
2714 hda_nid_t pin;
2715 const char *label;
2716
2717 pin = cfg->inputs[i].pin;
2718 if (!alc_is_input_pin(codec, pin))
2719 continue;
2720
2721 label = hda_get_autocfg_input_label(codec, cfg, i);
2722 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2723 label = "Headphone Mic";
2724 if (prev_label && !strcmp(label, prev_label))
2725 type_idx++;
2726 else
2727 type_idx = 0;
2728 prev_label = label;
2729
2730 if (mixer) {
2731 idx = get_connection_index(codec, mixer, pin);
2732 if (idx >= 0) {
2733 err = new_analog_input(spec, pin,
2734 label, type_idx,
2735 idx, mixer);
2736 if (err < 0)
2737 return err;
2738 }
2739 }
2740
2741 for (c = 0; c < num_adcs; c++) {
2742 hda_nid_t cap = get_capsrc(spec, c);
2743 idx = get_connection_index(codec, cap, pin);
2744 if (idx >= 0) {
2745 spec->imux_pins[imux->num_items] = pin;
2746 snd_hda_add_imux_item(imux, label, idx, NULL);
2747 break;
2748 }
2749 }
2750 }
2751
2752 spec->num_mux_defs = 1;
2753 spec->input_mux = imux;
2754
2755 return 0;
2756}
2757
2758/* create a shared input with the headphone out */
2759static int alc_auto_create_shared_input(struct hda_codec *codec)
2760{
2761 struct alc_spec *spec = codec->spec;
2762 struct auto_pin_cfg *cfg = &spec->autocfg;
2763 unsigned int defcfg;
2764 hda_nid_t nid;
2765
2766 /* only one internal input pin? */
2767 if (cfg->num_inputs != 1)
2768 return 0;
2769 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2770 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2771 return 0;
2772
2773 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2774 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2775 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2776 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2777 else
2778 return 0; /* both not available */
2779
2780 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2781 return 0; /* no input */
2782
2783 cfg->inputs[1].pin = nid;
2784 cfg->inputs[1].type = AUTO_PIN_MIC;
2785 cfg->num_inputs = 2;
2786 spec->shared_mic_hp = 1;
2787 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2788 return 0;
2789}
2790
2791static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2792 unsigned int pin_type)
2793{
2794 snd_hda_set_pin_ctl(codec, nid, pin_type);
2795 /* unmute pin */
2796 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2797 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2798 AMP_OUT_UNMUTE);
2799}
2800
2801static int get_pin_type(int line_out_type)
2802{
2803 if (line_out_type == AUTO_PIN_HP_OUT)
2804 return PIN_HP;
2805 else
2806 return PIN_OUT;
2807}
2808
2809static void alc_auto_init_analog_input(struct hda_codec *codec)
2810{
2811 struct alc_spec *spec = codec->spec;
2812 struct auto_pin_cfg *cfg = &spec->autocfg;
2813 int i;
2814
2815 for (i = 0; i < cfg->num_inputs; i++) {
2816 hda_nid_t nid = cfg->inputs[i].pin;
2817 if (alc_is_input_pin(codec, nid)) {
2818 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
2819 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
2820 snd_hda_codec_write(codec, nid, 0,
2821 AC_VERB_SET_AMP_GAIN_MUTE,
2822 AMP_OUT_MUTE);
2823 }
2824 }
2825
2826 /* mute all loopback inputs */
2827 if (spec->mixer_nid) {
2828 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
2829 for (i = 0; i < nums; i++)
2830 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2831 AC_VERB_SET_AMP_GAIN_MUTE,
2832 AMP_IN_MUTE(i));
2833 }
2834}
2835
2836/* convert from MIX nid to DAC */
2837static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
2838{
2839 hda_nid_t list[5];
2840 int i, num;
2841
2842 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2843 return nid;
2844 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2845 for (i = 0; i < num; i++) {
2846 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2847 return list[i];
2848 }
2849 return 0;
2850}
2851
2852/* go down to the selector widget before the mixer */
2853static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2854{
2855 hda_nid_t srcs[5];
2856 int num = snd_hda_get_connections(codec, pin, srcs,
2857 ARRAY_SIZE(srcs));
2858 if (num != 1 ||
2859 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2860 return pin;
2861 return srcs[0];
2862}
2863
2864/* get MIX nid connected to the given pin targeted to DAC */
2865static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
2866 hda_nid_t dac)
2867{
2868 hda_nid_t mix[5];
2869 int i, num;
2870
2871 pin = alc_go_down_to_selector(codec, pin);
2872 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2873 for (i = 0; i < num; i++) {
2874 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
2875 return mix[i];
2876 }
2877 return 0;
2878}
2879
2880/* select the connection from pin to DAC if needed */
2881static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2882 hda_nid_t dac)
2883{
2884 hda_nid_t mix[5];
2885 int i, num;
2886
2887 pin = alc_go_down_to_selector(codec, pin);
2888 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2889 if (num < 2)
2890 return 0;
2891 for (i = 0; i < num; i++) {
2892 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2893 snd_hda_codec_update_cache(codec, pin, 0,
2894 AC_VERB_SET_CONNECT_SEL, i);
2895 return 0;
2896 }
2897 }
2898 return 0;
2899}
2900
2901static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2902{
2903 struct alc_spec *spec = codec->spec;
2904 int i;
2905 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2906 ARRAY_SIZE(spec->private_dac_nids)) ||
2907 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2908 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2909 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2910 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2911 return true;
2912 for (i = 0; i < spec->multi_ios; i++) {
2913 if (spec->multi_io[i].dac == nid)
2914 return true;
2915 }
2916 return false;
2917}
2918
2919/* look for an empty DAC slot */
2920static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2921{
2922 hda_nid_t srcs[5];
2923 int i, num;
2924
2925 pin = alc_go_down_to_selector(codec, pin);
2926 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2927 for (i = 0; i < num; i++) {
2928 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2929 if (!nid)
2930 continue;
2931 if (!alc_is_dac_already_used(codec, nid))
2932 return nid;
2933 }
2934 return 0;
2935}
2936
2937/* check whether the DAC is reachable from the pin */
2938static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2939 hda_nid_t pin, hda_nid_t dac)
2940{
2941 hda_nid_t srcs[5];
2942 int i, num;
2943
2944 if (!pin || !dac)
2945 return false;
2946 pin = alc_go_down_to_selector(codec, pin);
2947 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2948 for (i = 0; i < num; i++) {
2949 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2950 if (nid == dac)
2951 return true;
2952 }
2953 return false;
2954}
2955
2956static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2957{
2958 struct alc_spec *spec = codec->spec;
2959 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2960 hda_nid_t nid, nid_found, srcs[5];
2961 int i, num = snd_hda_get_connections(codec, sel, srcs,
2962 ARRAY_SIZE(srcs));
2963 if (num == 1)
2964 return alc_auto_look_for_dac(codec, pin);
2965 nid_found = 0;
2966 for (i = 0; i < num; i++) {
2967 if (srcs[i] == spec->mixer_nid)
2968 continue;
2969 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2970 if (nid && !alc_is_dac_already_used(codec, nid)) {
2971 if (nid_found)
2972 return 0;
2973 nid_found = nid;
2974 }
2975 }
2976 return nid_found;
2977}
2978
2979/* mark up volume and mute control NIDs: used during badness parsing and
2980 * at creating actual controls
2981 */
2982static inline unsigned int get_ctl_pos(unsigned int data)
2983{
2984 hda_nid_t nid = get_amp_nid_(data);
2985 unsigned int dir;
2986 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2987 return 0;
2988 dir = get_amp_direction_(data);
2989 return (nid << 1) | dir;
2990}
2991
2992#define is_ctl_used(bits, data) \
2993 test_bit(get_ctl_pos(data), bits)
2994#define mark_ctl_usage(bits, data) \
2995 set_bit(get_ctl_pos(data), bits)
2996
2997static void clear_vol_marks(struct hda_codec *codec)
2998{
2999 struct alc_spec *spec = codec->spec;
3000 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3001 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3002}
3003
3004/* badness definition */
3005enum {
3006 /* No primary DAC is found for the main output */
3007 BAD_NO_PRIMARY_DAC = 0x10000,
3008 /* No DAC is found for the extra output */
3009 BAD_NO_DAC = 0x4000,
3010 /* No possible multi-ios */
3011 BAD_MULTI_IO = 0x103,
3012 /* No individual DAC for extra output */
3013 BAD_NO_EXTRA_DAC = 0x102,
3014 /* No individual DAC for extra surrounds */
3015 BAD_NO_EXTRA_SURR_DAC = 0x101,
3016 /* Primary DAC shared with main surrounds */
3017 BAD_SHARED_SURROUND = 0x100,
3018 /* Primary DAC shared with main CLFE */
3019 BAD_SHARED_CLFE = 0x10,
3020 /* Primary DAC shared with extra surrounds */
3021 BAD_SHARED_EXTRA_SURROUND = 0x10,
3022 /* Volume widget is shared */
3023 BAD_SHARED_VOL = 0x10,
3024};
3025
3026static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3027 hda_nid_t pin, hda_nid_t dac);
3028static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3029 hda_nid_t pin, hda_nid_t dac);
3030
3031static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3032 hda_nid_t dac)
3033{
3034 struct alc_spec *spec = codec->spec;
3035 hda_nid_t nid;
3036 unsigned int val;
3037 int badness = 0;
3038
3039 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3040 if (nid) {
3041 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3042 if (is_ctl_used(spec->vol_ctls, nid))
3043 badness += BAD_SHARED_VOL;
3044 else
3045 mark_ctl_usage(spec->vol_ctls, val);
3046 } else
3047 badness += BAD_SHARED_VOL;
3048 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3049 if (nid) {
3050 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3051 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3052 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3053 else
3054 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3055 if (is_ctl_used(spec->sw_ctls, val))
3056 badness += BAD_SHARED_VOL;
3057 else
3058 mark_ctl_usage(spec->sw_ctls, val);
3059 } else
3060 badness += BAD_SHARED_VOL;
3061 return badness;
3062}
3063
3064struct badness_table {
3065 int no_primary_dac; /* no primary DAC */
3066 int no_dac; /* no secondary DACs */
3067 int shared_primary; /* primary DAC is shared with main output */
3068 int shared_surr; /* secondary DAC shared with main or primary */
3069 int shared_clfe; /* third DAC shared with main or primary */
3070 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3071};
3072
3073static struct badness_table main_out_badness = {
3074 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3075 .no_dac = BAD_NO_DAC,
3076 .shared_primary = BAD_NO_PRIMARY_DAC,
3077 .shared_surr = BAD_SHARED_SURROUND,
3078 .shared_clfe = BAD_SHARED_CLFE,
3079 .shared_surr_main = BAD_SHARED_SURROUND,
3080};
3081
3082static struct badness_table extra_out_badness = {
3083 .no_primary_dac = BAD_NO_DAC,
3084 .no_dac = BAD_NO_DAC,
3085 .shared_primary = BAD_NO_EXTRA_DAC,
3086 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3087 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3088 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3089};
3090
3091/* try to assign DACs to pins and return the resultant badness */
3092static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3093 const hda_nid_t *pins, hda_nid_t *dacs,
3094 const struct badness_table *bad)
3095{
3096 struct alc_spec *spec = codec->spec;
3097 struct auto_pin_cfg *cfg = &spec->autocfg;
3098 int i, j;
3099 int badness = 0;
3100 hda_nid_t dac;
3101
3102 if (!num_outs)
3103 return 0;
3104
3105 for (i = 0; i < num_outs; i++) {
3106 hda_nid_t pin = pins[i];
3107 if (!dacs[i])
3108 dacs[i] = alc_auto_look_for_dac(codec, pin);
3109 if (!dacs[i] && !i) {
3110 for (j = 1; j < num_outs; j++) {
3111 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3112 dacs[0] = dacs[j];
3113 dacs[j] = 0;
3114 break;
3115 }
3116 }
3117 }
3118 dac = dacs[i];
3119 if (!dac) {
3120 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
3121 dac = dacs[0];
3122 else if (cfg->line_outs > i &&
3123 alc_auto_is_dac_reachable(codec, pin,
3124 spec->private_dac_nids[i]))
3125 dac = spec->private_dac_nids[i];
3126 if (dac) {
3127 if (!i)
3128 badness += bad->shared_primary;
3129 else if (i == 1)
3130 badness += bad->shared_surr;
3131 else
3132 badness += bad->shared_clfe;
3133 } else if (alc_auto_is_dac_reachable(codec, pin,
3134 spec->private_dac_nids[0])) {
3135 dac = spec->private_dac_nids[0];
3136 badness += bad->shared_surr_main;
3137 } else if (!i)
3138 badness += bad->no_primary_dac;
3139 else
3140 badness += bad->no_dac;
3141 }
3142 if (dac)
3143 badness += eval_shared_vol_badness(codec, pin, dac);
3144 }
3145
3146 return badness;
3147}
3148
3149static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3150 hda_nid_t reference_pin,
3151 bool hardwired, int offset);
3152
3153static bool alc_map_singles(struct hda_codec *codec, int outs,
3154 const hda_nid_t *pins, hda_nid_t *dacs)
3155{
3156 int i;
3157 bool found = false;
3158 for (i = 0; i < outs; i++) {
3159 if (dacs[i])
3160 continue;
3161 dacs[i] = get_dac_if_single(codec, pins[i]);
3162 if (dacs[i])
3163 found = true;
3164 }
3165 return found;
3166}
3167
3168/* fill in the dac_nids table from the parsed pin configuration */
3169static int fill_and_eval_dacs(struct hda_codec *codec,
3170 bool fill_hardwired,
3171 bool fill_mio_first)
3172{
3173 struct alc_spec *spec = codec->spec;
3174 struct auto_pin_cfg *cfg = &spec->autocfg;
3175 int i, err, badness;
3176
3177 /* set num_dacs once to full for alc_auto_look_for_dac() */
3178 spec->multiout.num_dacs = cfg->line_outs;
3179 spec->multiout.dac_nids = spec->private_dac_nids;
3180 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3181 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3182 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
3183 spec->multi_ios = 0;
3184 clear_vol_marks(codec);
3185 badness = 0;
3186
3187 /* fill hard-wired DACs first */
3188 if (fill_hardwired) {
3189 bool mapped;
3190 do {
3191 mapped = alc_map_singles(codec, cfg->line_outs,
3192 cfg->line_out_pins,
3193 spec->private_dac_nids);
3194 mapped |= alc_map_singles(codec, cfg->hp_outs,
3195 cfg->hp_pins,
3196 spec->multiout.hp_out_nid);
3197 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3198 cfg->speaker_pins,
3199 spec->multiout.extra_out_nid);
3200 if (fill_mio_first && cfg->line_outs == 1 &&
3201 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3202 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3203 if (!err)
3204 mapped = true;
3205 }
3206 } while (mapped);
3207 }
3208
3209 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3210 spec->private_dac_nids,
3211 &main_out_badness);
3212
3213 /* re-count num_dacs and squash invalid entries */
3214 spec->multiout.num_dacs = 0;
3215 for (i = 0; i < cfg->line_outs; i++) {
3216 if (spec->private_dac_nids[i])
3217 spec->multiout.num_dacs++;
3218 else {
3219 memmove(spec->private_dac_nids + i,
3220 spec->private_dac_nids + i + 1,
3221 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3222 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3223 }
3224 }
3225
3226 if (fill_mio_first &&
3227 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3228 /* try to fill multi-io first */
3229 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3230 if (err < 0)
3231 return err;
3232 /* we don't count badness at this stage yet */
3233 }
3234
3235 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
3236 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3237 spec->multiout.hp_out_nid,
3238 &extra_out_badness);
3239 if (err < 0)
3240 return err;
3241 badness += err;
3242 }
3243 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3244 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3245 cfg->speaker_pins,
3246 spec->multiout.extra_out_nid,
3247 &extra_out_badness);
3248 if (err < 0)
3249 return err;
3250 badness += err;
3251 }
3252 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3253 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
3254 if (err < 0)
3255 return err;
3256 badness += err;
3257 }
3258 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3259 /* try multi-ios with HP + inputs */
3260 int offset = 0;
3261 if (cfg->line_outs >= 3)
3262 offset = 1;
3263 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3264 offset);
3265 if (err < 0)
3266 return err;
3267 badness += err;
3268 }
3269
3270 if (spec->multi_ios == 2) {
3271 for (i = 0; i < 2; i++)
3272 spec->private_dac_nids[spec->multiout.num_dacs++] =
3273 spec->multi_io[i].dac;
3274 spec->ext_channel_count = 2;
3275 } else if (spec->multi_ios) {
3276 spec->multi_ios = 0;
3277 badness += BAD_MULTI_IO;
3278 }
3279
3280 return badness;
3281}
3282
3283#define DEBUG_BADNESS
3284
3285#ifdef DEBUG_BADNESS
3286#define debug_badness snd_printdd
3287#else
3288#define debug_badness(...)
3289#endif
3290
3291static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3292{
3293 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3294 cfg->line_out_pins[0], cfg->line_out_pins[1],
3295 cfg->line_out_pins[2], cfg->line_out_pins[2],
3296 spec->multiout.dac_nids[0],
3297 spec->multiout.dac_nids[1],
3298 spec->multiout.dac_nids[2],
3299 spec->multiout.dac_nids[3]);
3300 if (spec->multi_ios > 0)
3301 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3302 spec->multi_ios,
3303 spec->multi_io[0].pin, spec->multi_io[1].pin,
3304 spec->multi_io[0].dac, spec->multi_io[1].dac);
3305 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3306 cfg->hp_pins[0], cfg->hp_pins[1],
3307 cfg->hp_pins[2], cfg->hp_pins[2],
3308 spec->multiout.hp_out_nid[0],
3309 spec->multiout.hp_out_nid[1],
3310 spec->multiout.hp_out_nid[2],
3311 spec->multiout.hp_out_nid[3]);
3312 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3313 cfg->speaker_pins[0], cfg->speaker_pins[1],
3314 cfg->speaker_pins[2], cfg->speaker_pins[3],
3315 spec->multiout.extra_out_nid[0],
3316 spec->multiout.extra_out_nid[1],
3317 spec->multiout.extra_out_nid[2],
3318 spec->multiout.extra_out_nid[3]);
3319}
3320
3321static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3322{
3323 struct alc_spec *spec = codec->spec;
3324 struct auto_pin_cfg *cfg = &spec->autocfg;
3325 struct auto_pin_cfg *best_cfg;
3326 int best_badness = INT_MAX;
3327 int badness;
3328 bool fill_hardwired = true, fill_mio_first = true;
3329 bool best_wired = true, best_mio = true;
3330 bool hp_spk_swapped = false;
3331
3332 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3333 if (!best_cfg)
3334 return -ENOMEM;
3335 *best_cfg = *cfg;
3336
3337 for (;;) {
3338 badness = fill_and_eval_dacs(codec, fill_hardwired,
3339 fill_mio_first);
3340 if (badness < 0) {
3341 kfree(best_cfg);
3342 return badness;
3343 }
3344 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3345 cfg->line_out_type, fill_hardwired, fill_mio_first,
3346 badness);
3347 debug_show_configs(spec, cfg);
3348 if (badness < best_badness) {
3349 best_badness = badness;
3350 *best_cfg = *cfg;
3351 best_wired = fill_hardwired;
3352 best_mio = fill_mio_first;
3353 }
3354 if (!badness)
3355 break;
3356 fill_mio_first = !fill_mio_first;
3357 if (!fill_mio_first)
3358 continue;
3359 fill_hardwired = !fill_hardwired;
3360 if (!fill_hardwired)
3361 continue;
3362 if (hp_spk_swapped)
3363 break;
3364 hp_spk_swapped = true;
3365 if (cfg->speaker_outs > 0 &&
3366 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3367 cfg->hp_outs = cfg->line_outs;
3368 memcpy(cfg->hp_pins, cfg->line_out_pins,
3369 sizeof(cfg->hp_pins));
3370 cfg->line_outs = cfg->speaker_outs;
3371 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3372 sizeof(cfg->speaker_pins));
3373 cfg->speaker_outs = 0;
3374 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3375 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3376 fill_hardwired = true;
3377 continue;
3378 }
3379 if (cfg->hp_outs > 0 &&
3380 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3381 cfg->speaker_outs = cfg->line_outs;
3382 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3383 sizeof(cfg->speaker_pins));
3384 cfg->line_outs = cfg->hp_outs;
3385 memcpy(cfg->line_out_pins, cfg->hp_pins,
3386 sizeof(cfg->hp_pins));
3387 cfg->hp_outs = 0;
3388 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3389 cfg->line_out_type = AUTO_PIN_HP_OUT;
3390 fill_hardwired = true;
3391 continue;
3392 }
3393 break;
3394 }
3395
3396 if (badness) {
3397 *cfg = *best_cfg;
3398 fill_and_eval_dacs(codec, best_wired, best_mio);
3399 }
3400 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3401 cfg->line_out_type, best_wired, best_mio);
3402 debug_show_configs(spec, cfg);
3403
3404 if (cfg->line_out_pins[0])
3405 spec->vmaster_nid =
3406 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3407 spec->multiout.dac_nids[0]);
3408
3409 /* clear the bitmap flags for creating controls */
3410 clear_vol_marks(codec);
3411 kfree(best_cfg);
3412 return 0;
3413}
3414
3415static int alc_auto_add_vol_ctl(struct hda_codec *codec,
3416 const char *pfx, int cidx,
3417 hda_nid_t nid, unsigned int chs)
3418{
3419 struct alc_spec *spec = codec->spec;
3420 unsigned int val;
3421 if (!nid)
3422 return 0;
3423 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3424 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3425 return 0;
3426 mark_ctl_usage(spec->vol_ctls, val);
3427 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3428 val);
3429}
3430
3431static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3432 const char *pfx, int cidx,
3433 hda_nid_t nid)
3434{
3435 int chs = 1;
3436 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3437 chs = 3;
3438 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3439}
3440
3441/* create a mute-switch for the given mixer widget;
3442 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3443 */
3444static int alc_auto_add_sw_ctl(struct hda_codec *codec,
3445 const char *pfx, int cidx,
3446 hda_nid_t nid, unsigned int chs)
3447{
3448 struct alc_spec *spec = codec->spec;
3449 int wid_type;
3450 int type;
3451 unsigned long val;
3452 if (!nid)
3453 return 0;
3454 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3455 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3456 type = ALC_CTL_WIDGET_MUTE;
3457 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3458 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
3459 type = ALC_CTL_WIDGET_MUTE;
3460 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3461 } else {
3462 type = ALC_CTL_BIND_MUTE;
3463 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3464 }
3465 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3466 return 0;
3467 mark_ctl_usage(spec->sw_ctls, val);
3468 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
3469}
3470
3471static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3472 int cidx, hda_nid_t nid)
3473{
3474 int chs = 1;
3475 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3476 chs = 3;
3477 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3478}
3479
3480static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3481 hda_nid_t pin, hda_nid_t dac)
3482{
3483 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3484 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3485 return pin;
3486 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3487 return mix;
3488 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3489 return dac;
3490 return 0;
3491}
3492
3493static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3494 hda_nid_t pin, hda_nid_t dac)
3495{
3496 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3497 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3498 return dac;
3499 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3500 return mix;
3501 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3502 return pin;
3503 return 0;
3504}
3505
3506/* add playback controls from the parsed DAC table */
3507static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
3508 const struct auto_pin_cfg *cfg)
3509{
3510 struct alc_spec *spec = codec->spec;
3511 int i, err, noutputs;
3512
3513 noutputs = cfg->line_outs;
3514 if (spec->multi_ios > 0 && cfg->line_outs < 3)
3515 noutputs += spec->multi_ios;
3516
3517 for (i = 0; i < noutputs; i++) {
3518 const char *name;
3519 int index;
3520 hda_nid_t dac, pin;
3521 hda_nid_t sw, vol;
3522
3523 dac = spec->multiout.dac_nids[i];
3524 if (!dac)
3525 continue;
3526 if (i >= cfg->line_outs) {
3527 pin = spec->multi_io[i - 1].pin;
3528 index = 0;
3529 name = channel_name[i];
3530 } else {
3531 pin = cfg->line_out_pins[i];
3532 name = alc_get_line_out_pfx(spec, i, true, &index);
3533 }
3534
3535 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3536 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3537 if (!name || !strcmp(name, "CLFE")) {
3538 /* Center/LFE */
3539 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
3540 if (err < 0)
3541 return err;
3542 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
3543 if (err < 0)
3544 return err;
3545 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
3546 if (err < 0)
3547 return err;
3548 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
3549 if (err < 0)
3550 return err;
3551 } else {
3552 err = alc_auto_add_stereo_vol(codec, name, index, vol);
3553 if (err < 0)
3554 return err;
3555 err = alc_auto_add_stereo_sw(codec, name, index, sw);
3556 if (err < 0)
3557 return err;
3558 }
3559 }
3560 return 0;
3561}
3562
3563static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3564 hda_nid_t dac, const char *pfx,
3565 int cidx)
3566{
3567 struct alc_spec *spec = codec->spec;
3568 hda_nid_t sw, vol;
3569 int err;
3570
3571 if (!dac) {
3572 unsigned int val;
3573 /* the corresponding DAC is already occupied */
3574 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3575 return 0; /* no way */
3576 /* create a switch only */
3577 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3578 if (is_ctl_used(spec->sw_ctls, val))
3579 return 0; /* already created */
3580 mark_ctl_usage(spec->sw_ctls, val);
3581 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
3582 }
3583
3584 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3585 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3586 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
3587 if (err < 0)
3588 return err;
3589 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
3590 if (err < 0)
3591 return err;
3592 return 0;
3593}
3594
3595static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3596 unsigned int nums,
3597 struct hda_ctl_ops *ops)
3598{
3599 struct alc_spec *spec = codec->spec;
3600 struct hda_bind_ctls **ctlp, *ctl;
3601 ctlp = snd_array_new(&spec->bind_ctls);
3602 if (!ctlp)
3603 return NULL;
3604 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3605 *ctlp = ctl;
3606 if (ctl)
3607 ctl->ops = ops;
3608 return ctl;
3609}
3610
3611/* add playback controls for speaker and HP outputs */
3612static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3613 const hda_nid_t *pins,
3614 const hda_nid_t *dacs,
3615 const char *pfx)
3616{
3617 struct alc_spec *spec = codec->spec;
3618 struct hda_bind_ctls *ctl;
3619 char name[32];
3620 int i, n, err;
3621
3622 if (!num_pins || !pins[0])
3623 return 0;
3624
3625 if (num_pins == 1) {
3626 hda_nid_t dac = *dacs;
3627 if (!dac)
3628 dac = spec->multiout.dac_nids[0];
3629 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
3630 }
3631
3632 for (i = 0; i < num_pins; i++) {
3633 hda_nid_t dac;
3634 if (dacs[num_pins - 1])
3635 dac = dacs[i]; /* with individual volumes */
3636 else
3637 dac = 0;
3638 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3639 err = alc_auto_create_extra_out(codec, pins[i], dac,
3640 "Bass Speaker", 0);
3641 } else if (num_pins >= 3) {
3642 snprintf(name, sizeof(name), "%s %s",
3643 pfx, channel_name[i]);
3644 err = alc_auto_create_extra_out(codec, pins[i], dac,
3645 name, 0);
3646 } else {
3647 err = alc_auto_create_extra_out(codec, pins[i], dac,
3648 pfx, i);
3649 }
3650 if (err < 0)
3651 return err;
3652 }
3653 if (dacs[num_pins - 1])
3654 return 0;
3655
3656 /* Let's create a bind-controls for volumes */
3657 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3658 if (!ctl)
3659 return -ENOMEM;
3660 n = 0;
3661 for (i = 0; i < num_pins; i++) {
3662 hda_nid_t vol;
3663 if (!pins[i] || !dacs[i])
3664 continue;
3665 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3666 if (vol)
3667 ctl->values[n++] =
3668 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3669 }
3670 if (n) {
3671 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3672 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3673 if (err < 0)
3674 return err;
3675 }
3676 return 0;
3677}
3678
3679static int alc_auto_create_hp_out(struct hda_codec *codec)
3680{
3681 struct alc_spec *spec = codec->spec;
3682 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3683 spec->autocfg.hp_pins,
3684 spec->multiout.hp_out_nid,
3685 "Headphone");
3686}
3687
3688static int alc_auto_create_speaker_out(struct hda_codec *codec)
3689{
3690 struct alc_spec *spec = codec->spec;
3691 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3692 spec->autocfg.speaker_pins,
3693 spec->multiout.extra_out_nid,
3694 "Speaker");
3695}
3696
3697static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3698 hda_nid_t pin, int pin_type,
3699 hda_nid_t dac)
3700{
3701 int i, num;
3702 hda_nid_t nid, mix = 0;
3703 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
3704
3705 alc_set_pin_output(codec, pin, pin_type);
3706 nid = alc_go_down_to_selector(codec, pin);
3707 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
3708 for (i = 0; i < num; i++) {
3709 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
3710 continue;
3711 mix = srcs[i];
3712 break;
3713 }
3714 if (!mix)
3715 return;
3716
3717 /* need the manual connection? */
3718 if (num > 1)
3719 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3720 /* unmute mixer widget inputs */
3721 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3722 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3723 AMP_IN_UNMUTE(0));
3724 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3725 AMP_IN_UNMUTE(1));
3726 }
3727 /* initialize volume */
3728 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3729 if (nid)
3730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3731 AMP_OUT_ZERO);
3732
3733 /* unmute DAC if it's not assigned to a mixer */
3734 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3735 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3736 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3737 AMP_OUT_ZERO);
3738}
3739
3740static void alc_auto_init_multi_out(struct hda_codec *codec)
3741{
3742 struct alc_spec *spec = codec->spec;
3743 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3744 int i;
3745
3746 for (i = 0; i <= HDA_SIDE; i++) {
3747 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3748 if (nid)
3749 alc_auto_set_output_and_unmute(codec, nid, pin_type,
3750 spec->multiout.dac_nids[i]);
3751 }
3752}
3753
3754static void alc_auto_init_extra_out(struct hda_codec *codec)
3755{
3756 struct alc_spec *spec = codec->spec;
3757 int i;
3758 hda_nid_t pin, dac;
3759
3760 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3761 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3762 break;
3763 pin = spec->autocfg.hp_pins[i];
3764 if (!pin)
3765 break;
3766 dac = spec->multiout.hp_out_nid[i];
3767 if (!dac) {
3768 if (i > 0 && spec->multiout.hp_out_nid[0])
3769 dac = spec->multiout.hp_out_nid[0];
3770 else
3771 dac = spec->multiout.dac_nids[0];
3772 }
3773 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3774 }
3775 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3776 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3777 break;
3778 pin = spec->autocfg.speaker_pins[i];
3779 if (!pin)
3780 break;
3781 dac = spec->multiout.extra_out_nid[i];
3782 if (!dac) {
3783 if (i > 0 && spec->multiout.extra_out_nid[0])
3784 dac = spec->multiout.extra_out_nid[0];
3785 else
3786 dac = spec->multiout.dac_nids[0];
3787 }
3788 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3789 }
3790}
3791
3792/* check whether the given pin can be a multi-io pin */
3793static bool can_be_multiio_pin(struct hda_codec *codec,
3794 unsigned int location, hda_nid_t nid)
3795{
3796 unsigned int defcfg, caps;
3797
3798 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3799 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3800 return false;
3801 if (location && get_defcfg_location(defcfg) != location)
3802 return false;
3803 caps = snd_hda_query_pin_caps(codec, nid);
3804 if (!(caps & AC_PINCAP_OUT))
3805 return false;
3806 return true;
3807}
3808
3809/*
3810 * multi-io helper
3811 *
3812 * When hardwired is set, try to fill ony hardwired pins, and returns
3813 * zero if any pins are filled, non-zero if nothing found.
3814 * When hardwired is off, try to fill possible input pins, and returns
3815 * the badness value.
3816 */
3817static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3818 hda_nid_t reference_pin,
3819 bool hardwired, int offset)
3820{
3821 struct alc_spec *spec = codec->spec;
3822 struct auto_pin_cfg *cfg = &spec->autocfg;
3823 int type, i, j, dacs, num_pins, old_pins;
3824 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3825 unsigned int location = get_defcfg_location(defcfg);
3826 int badness = 0;
3827
3828 old_pins = spec->multi_ios;
3829 if (old_pins >= 2)
3830 goto end_fill;
3831
3832 num_pins = 0;
3833 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3834 for (i = 0; i < cfg->num_inputs; i++) {
3835 if (cfg->inputs[i].type != type)
3836 continue;
3837 if (can_be_multiio_pin(codec, location,
3838 cfg->inputs[i].pin))
3839 num_pins++;
3840 }
3841 }
3842 if (num_pins < 2)
3843 goto end_fill;
3844
3845 dacs = spec->multiout.num_dacs;
3846 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3847 for (i = 0; i < cfg->num_inputs; i++) {
3848 hda_nid_t nid = cfg->inputs[i].pin;
3849 hda_nid_t dac = 0;
3850
3851 if (cfg->inputs[i].type != type)
3852 continue;
3853 if (!can_be_multiio_pin(codec, location, nid))
3854 continue;
3855 for (j = 0; j < spec->multi_ios; j++) {
3856 if (nid == spec->multi_io[j].pin)
3857 break;
3858 }
3859 if (j < spec->multi_ios)
3860 continue;
3861
3862 if (offset && offset + spec->multi_ios < dacs) {
3863 dac = spec->private_dac_nids[offset + spec->multi_ios];
3864 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3865 dac = 0;
3866 }
3867 if (hardwired)
3868 dac = get_dac_if_single(codec, nid);
3869 else if (!dac)
3870 dac = alc_auto_look_for_dac(codec, nid);
3871 if (!dac) {
3872 badness++;
3873 continue;
3874 }
3875 spec->multi_io[spec->multi_ios].pin = nid;
3876 spec->multi_io[spec->multi_ios].dac = dac;
3877 spec->multi_ios++;
3878 if (spec->multi_ios >= 2)
3879 break;
3880 }
3881 }
3882 end_fill:
3883 if (badness)
3884 badness = BAD_MULTI_IO;
3885 if (old_pins == spec->multi_ios) {
3886 if (hardwired)
3887 return 1; /* nothing found */
3888 else
3889 return badness; /* no badness if nothing found */
3890 }
3891 if (!hardwired && spec->multi_ios < 2) {
3892 spec->multi_ios = old_pins;
3893 return badness;
3894 }
3895
3896 return 0;
3897}
3898
3899static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3900 struct snd_ctl_elem_info *uinfo)
3901{
3902 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3903 struct alc_spec *spec = codec->spec;
3904
3905 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3906 uinfo->count = 1;
3907 uinfo->value.enumerated.items = spec->multi_ios + 1;
3908 if (uinfo->value.enumerated.item > spec->multi_ios)
3909 uinfo->value.enumerated.item = spec->multi_ios;
3910 sprintf(uinfo->value.enumerated.name, "%dch",
3911 (uinfo->value.enumerated.item + 1) * 2);
3912 return 0;
3913}
3914
3915static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3916 struct snd_ctl_elem_value *ucontrol)
3917{
3918 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3919 struct alc_spec *spec = codec->spec;
3920 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3921 return 0;
3922}
3923
3924static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3925{
3926 struct alc_spec *spec = codec->spec;
3927 hda_nid_t nid = spec->multi_io[idx].pin;
3928
3929 if (!spec->multi_io[idx].ctl_in)
3930 spec->multi_io[idx].ctl_in =
3931 snd_hda_codec_read(codec, nid, 0,
3932 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3933 if (output) {
3934 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
3935 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3936 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3937 HDA_AMP_MUTE, 0);
3938 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3939 } else {
3940 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3941 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3942 HDA_AMP_MUTE, HDA_AMP_MUTE);
3943 snd_hda_set_pin_ctl_cache(codec, nid,
3944 spec->multi_io[idx].ctl_in);
3945 }
3946 return 0;
3947}
3948
3949static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3950 struct snd_ctl_elem_value *ucontrol)
3951{
3952 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3953 struct alc_spec *spec = codec->spec;
3954 int i, ch;
3955
3956 ch = ucontrol->value.enumerated.item[0];
3957 if (ch < 0 || ch > spec->multi_ios)
3958 return -EINVAL;
3959 if (ch == (spec->ext_channel_count - 1) / 2)
3960 return 0;
3961 spec->ext_channel_count = (ch + 1) * 2;
3962 for (i = 0; i < spec->multi_ios; i++)
3963 alc_set_multi_io(codec, i, i < ch);
3964 spec->multiout.max_channels = max(spec->ext_channel_count,
3965 spec->const_channel_count);
3966 if (spec->need_dac_fix)
3967 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
3968 return 1;
3969}
3970
3971static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3972 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3973 .name = "Channel Mode",
3974 .info = alc_auto_ch_mode_info,
3975 .get = alc_auto_ch_mode_get,
3976 .put = alc_auto_ch_mode_put,
3977};
3978
3979static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3980{
3981 struct alc_spec *spec = codec->spec;
3982
3983 if (spec->multi_ios > 0) {
3984 if (!alc_kcontrol_new(spec, "Channel Mode",
3985 &alc_auto_channel_mode_enum))
3986 return -ENOMEM;
3987 }
3988 return 0;
3989}
3990
3991/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3992 * active input pins
3993 */
3994static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3995{
3996 struct alc_spec *spec = codec->spec;
3997 const struct hda_input_mux *imux;
3998 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3999 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4000 int i, n, nums;
4001
4002 imux = spec->input_mux;
4003 if (!imux)
4004 return;
4005 if (spec->dyn_adc_switch)
4006 return;
4007
4008 again:
4009 nums = 0;
4010 for (n = 0; n < spec->num_adc_nids; n++) {
4011 hda_nid_t cap = spec->private_capsrc_nids[n];
4012 int num_conns = snd_hda_get_num_conns(codec, cap);
4013 for (i = 0; i < imux->num_items; i++) {
4014 hda_nid_t pin = spec->imux_pins[i];
4015 if (pin) {
4016 if (get_connection_index(codec, cap, pin) < 0)
4017 break;
4018 } else if (num_conns <= imux->items[i].index)
4019 break;
4020 }
4021 if (i >= imux->num_items) {
4022 adc_nids[nums] = spec->private_adc_nids[n];
4023 capsrc_nids[nums++] = cap;
4024 }
4025 }
4026 if (!nums) {
4027 /* check whether ADC-switch is possible */
4028 if (!alc_check_dyn_adc_switch(codec)) {
4029 if (spec->shared_mic_hp) {
4030 spec->shared_mic_hp = 0;
4031 spec->private_imux[0].num_items = 1;
4032 goto again;
4033 }
4034 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4035 " using fallback 0x%x\n",
4036 codec->chip_name, spec->private_adc_nids[0]);
4037 spec->num_adc_nids = 1;
4038 spec->auto_mic = 0;
4039 return;
4040 }
4041 } else if (nums != spec->num_adc_nids) {
4042 memcpy(spec->private_adc_nids, adc_nids,
4043 nums * sizeof(hda_nid_t));
4044 memcpy(spec->private_capsrc_nids, capsrc_nids,
4045 nums * sizeof(hda_nid_t));
4046 spec->num_adc_nids = nums;
4047 }
4048
4049 if (spec->auto_mic)
4050 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4051 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
4052 spec->num_adc_nids = 1; /* reduce to a single ADC */
4053}
4054
4055/*
4056 * initialize ADC paths
4057 */
4058static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4059{
4060 struct alc_spec *spec = codec->spec;
4061 hda_nid_t nid;
4062
4063 nid = spec->adc_nids[adc_idx];
4064 /* mute ADC */
4065 if (nid_has_mute(codec, nid, HDA_INPUT)) {
4066 snd_hda_codec_write(codec, nid, 0,
4067 AC_VERB_SET_AMP_GAIN_MUTE,
4068 AMP_IN_MUTE(0));
4069 return;
4070 }
4071 if (!spec->capsrc_nids)
4072 return;
4073 nid = spec->capsrc_nids[adc_idx];
4074 if (nid_has_mute(codec, nid, HDA_OUTPUT))
4075 snd_hda_codec_write(codec, nid, 0,
4076 AC_VERB_SET_AMP_GAIN_MUTE,
4077 AMP_OUT_MUTE);
4078}
4079
4080static void alc_auto_init_input_src(struct hda_codec *codec)
4081{
4082 struct alc_spec *spec = codec->spec;
4083 int c, nums;
4084
4085 for (c = 0; c < spec->num_adc_nids; c++)
4086 alc_auto_init_adc(codec, c);
4087 if (spec->dyn_adc_switch)
4088 nums = 1;
4089 else
4090 nums = spec->num_adc_nids;
4091 for (c = 0; c < nums; c++)
4092 alc_mux_select(codec, c, spec->cur_mux[c], true);
4093}
4094
4095/* add mic boosts if needed */
4096static int alc_auto_add_mic_boost(struct hda_codec *codec)
4097{
4098 struct alc_spec *spec = codec->spec;
4099 struct auto_pin_cfg *cfg = &spec->autocfg;
4100 int i, err;
4101 int type_idx = 0;
4102 hda_nid_t nid;
4103 const char *prev_label = NULL;
4104
4105 for (i = 0; i < cfg->num_inputs; i++) {
4106 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4107 break;
4108 nid = cfg->inputs[i].pin;
4109 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4110 const char *label;
4111 char boost_label[32];
4112
4113 label = hda_get_autocfg_input_label(codec, cfg, i);
4114 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4115 label = "Headphone Mic";
4116 if (prev_label && !strcmp(label, prev_label))
4117 type_idx++;
4118 else
4119 type_idx = 0;
4120 prev_label = label;
4121
4122 snprintf(boost_label, sizeof(boost_label),
4123 "%s Boost Volume", label);
4124 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4125 boost_label, type_idx,
4126 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4127 if (err < 0)
4128 return err;
4129 }
4130 }
4131 return 0;
4132}
4133
4134/* select or unmute the given capsrc route */
4135static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4136 int idx)
4137{
4138 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4139 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4140 HDA_AMP_MUTE, 0);
4141 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
4142 snd_hda_codec_write_cache(codec, cap, 0,
4143 AC_VERB_SET_CONNECT_SEL, idx);
4144 }
4145}
4146
4147/* set the default connection to that pin */
4148static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4149{
4150 struct alc_spec *spec = codec->spec;
4151 int i;
4152
4153 if (!pin)
4154 return 0;
4155 for (i = 0; i < spec->num_adc_nids; i++) {
4156 hda_nid_t cap = get_capsrc(spec, i);
4157 int idx;
4158
4159 idx = get_connection_index(codec, cap, pin);
4160 if (idx < 0)
4161 continue;
4162 select_or_unmute_capsrc(codec, cap, idx);
4163 return i; /* return the found index */
4164 }
4165 return -1; /* not found */
4166}
4167
4168/* initialize some special cases for input sources */
4169static void alc_init_special_input_src(struct hda_codec *codec)
4170{
4171 struct alc_spec *spec = codec->spec;
4172 int i;
4173
4174 for (i = 0; i < spec->autocfg.num_inputs; i++)
4175 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4176}
4177
4178/* assign appropriate capture mixers */
4179static void set_capture_mixer(struct hda_codec *codec)
4180{
4181 struct alc_spec *spec = codec->spec;
4182 static const struct snd_kcontrol_new *caps[2][3] = {
4183 { alc_capture_mixer_nosrc1,
4184 alc_capture_mixer_nosrc2,
4185 alc_capture_mixer_nosrc3 },
4186 { alc_capture_mixer1,
4187 alc_capture_mixer2,
4188 alc_capture_mixer3 },
4189 };
4190
4191 /* check whether either of ADC or MUX has a volume control */
4192 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
4193 if (!spec->capsrc_nids)
4194 return; /* no volume */
4195 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
4196 return; /* no volume in capsrc, too */
4197 spec->vol_in_capsrc = 1;
4198 }
4199
4200 if (spec->num_adc_nids > 0) {
4201 int mux = 0;
4202 int num_adcs = 0;
4203
4204 if (spec->input_mux && spec->input_mux->num_items > 1)
4205 mux = 1;
4206 if (spec->auto_mic) {
4207 num_adcs = 1;
4208 mux = 0;
4209 } else if (spec->dyn_adc_switch)
4210 num_adcs = 1;
4211 if (!num_adcs) {
4212 if (spec->num_adc_nids > 3)
4213 spec->num_adc_nids = 3;
4214 else if (!spec->num_adc_nids)
4215 return;
4216 num_adcs = spec->num_adc_nids;
4217 }
4218 spec->cap_mixer = caps[mux][num_adcs - 1];
4219 }
4220}
4221
4222/*
4223 * standard auto-parser initializations
4224 */
4225static void alc_auto_init_std(struct hda_codec *codec)
4226{
4227 alc_auto_init_multi_out(codec);
4228 alc_auto_init_extra_out(codec);
4229 alc_auto_init_analog_input(codec);
4230 alc_auto_init_input_src(codec);
4231 alc_auto_init_digital(codec);
4232 alc_inithook(codec);
4233}
4234 920
4235/* 921/*
4236 * Digital-beep handlers 922 * Digital-beep handlers
@@ -4273,93 +959,20 @@ static int alc_parse_auto_config(struct hda_codec *codec,
4273 const hda_nid_t *ssid_nids) 959 const hda_nid_t *ssid_nids)
4274{ 960{
4275 struct alc_spec *spec = codec->spec; 961 struct alc_spec *spec = codec->spec;
4276 struct auto_pin_cfg *cfg = &spec->autocfg; 962 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
4277 int err; 963 int err;
4278 964
4279 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids, 965 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4280 spec->parse_flags); 966 spec->parse_flags);
4281 if (err < 0) 967 if (err < 0)
4282 return err; 968 return err;
4283 if (!cfg->line_outs) {
4284 if (cfg->dig_outs || cfg->dig_in_pin) {
4285 spec->multiout.max_channels = 2;
4286 spec->no_analog = 1;
4287 goto dig_only;
4288 }
4289 return 0; /* can't find valid BIOS pin config */
4290 }
4291
4292 if (!spec->no_primary_hp &&
4293 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4294 cfg->line_outs <= cfg->hp_outs) {
4295 /* use HP as primary out */
4296 cfg->speaker_outs = cfg->line_outs;
4297 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4298 sizeof(cfg->speaker_pins));
4299 cfg->line_outs = cfg->hp_outs;
4300 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4301 cfg->hp_outs = 0;
4302 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4303 cfg->line_out_type = AUTO_PIN_HP_OUT;
4304 }
4305
4306 err = alc_auto_fill_dac_nids(codec);
4307 if (err < 0)
4308 return err;
4309 err = alc_auto_add_multi_channel_mode(codec);
4310 if (err < 0)
4311 return err;
4312 err = alc_auto_create_multi_out_ctls(codec, cfg);
4313 if (err < 0)
4314 return err;
4315 err = alc_auto_create_hp_out(codec);
4316 if (err < 0)
4317 return err;
4318 err = alc_auto_create_speaker_out(codec);
4319 if (err < 0)
4320 return err;
4321 err = alc_auto_create_shared_input(codec);
4322 if (err < 0)
4323 return err;
4324 err = alc_auto_create_input_ctls(codec);
4325 if (err < 0)
4326 return err;
4327
4328 /* check the multiple speaker pins */
4329 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4330 spec->const_channel_count = cfg->line_outs * 2;
4331 else
4332 spec->const_channel_count = cfg->speaker_outs * 2;
4333
4334 if (spec->multi_ios > 0)
4335 spec->multiout.max_channels = max(spec->ext_channel_count,
4336 spec->const_channel_count);
4337 else
4338 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4339
4340 dig_only:
4341 alc_auto_parse_digital(codec);
4342
4343 if (!spec->no_analog)
4344 alc_remove_invalid_adc_nids(codec);
4345 969
4346 if (ssid_nids) 970 if (ssid_nids)
4347 alc_ssid_check(codec, ssid_nids); 971 alc_ssid_check(codec, ssid_nids);
4348 972
4349 if (!spec->no_analog) { 973 err = snd_hda_gen_parse_auto_config(codec, cfg);
4350 err = alc_auto_check_switches(codec); 974 if (err < 0)
4351 if (err < 0) 975 return err;
4352 return err;
4353 err = alc_auto_add_mic_boost(codec);
4354 if (err < 0)
4355 return err;
4356 }
4357
4358 if (spec->kctls.list)
4359 add_mixer(spec, spec->kctls.list);
4360
4361 if (!spec->no_analog && !spec->cap_mixer)
4362 set_capture_mixer(codec);
4363 976
4364 return 1; 977 return 1;
4365} 978}
@@ -4373,11 +986,12 @@ static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4373 if (!spec) 986 if (!spec)
4374 return -ENOMEM; 987 return -ENOMEM;
4375 codec->spec = spec; 988 codec->spec = spec;
989 snd_hda_gen_spec_init(&spec->gen);
990 spec->gen.mixer_nid = mixer_nid;
991 spec->gen.own_eapd_ctl = 1;
4376 codec->single_adc_amp = 1; 992 codec->single_adc_amp = 1;
4377 spec->mixer_nid = mixer_nid; 993 /* FIXME: do we need this for all Realtek codec models? */
4378 snd_hda_gen_init(&spec->gen); 994 codec->spdif_status_reset = 1;
4379 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4380 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
4381 995
4382 err = alc_codec_rename_from_preset(codec); 996 err = alc_codec_rename_from_preset(codec);
4383 if (err < 0) { 997 if (err < 0) {
@@ -4420,27 +1034,28 @@ enum {
4420 ALC880_FIXUP_6ST_BASE, 1034 ALC880_FIXUP_6ST_BASE,
4421 ALC880_FIXUP_6ST, 1035 ALC880_FIXUP_6ST,
4422 ALC880_FIXUP_6ST_DIG, 1036 ALC880_FIXUP_6ST_DIG,
1037 ALC880_FIXUP_6ST_AUTOMUTE,
4423}; 1038};
4424 1039
4425/* enable the volume-knob widget support on NID 0x21 */ 1040/* enable the volume-knob widget support on NID 0x21 */
4426static void alc880_fixup_vol_knob(struct hda_codec *codec, 1041static void alc880_fixup_vol_knob(struct hda_codec *codec,
4427 const struct alc_fixup *fix, int action) 1042 const struct hda_fixup *fix, int action)
4428{ 1043{
4429 if (action == ALC_FIXUP_ACT_PROBE) 1044 if (action == HDA_FIXUP_ACT_PROBE)
4430 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master); 1045 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
4431} 1046}
4432 1047
4433static const struct alc_fixup alc880_fixups[] = { 1048static const struct hda_fixup alc880_fixups[] = {
4434 [ALC880_FIXUP_GPIO1] = { 1049 [ALC880_FIXUP_GPIO1] = {
4435 .type = ALC_FIXUP_VERBS, 1050 .type = HDA_FIXUP_VERBS,
4436 .v.verbs = alc_gpio1_init_verbs, 1051 .v.verbs = alc_gpio1_init_verbs,
4437 }, 1052 },
4438 [ALC880_FIXUP_GPIO2] = { 1053 [ALC880_FIXUP_GPIO2] = {
4439 .type = ALC_FIXUP_VERBS, 1054 .type = HDA_FIXUP_VERBS,
4440 .v.verbs = alc_gpio2_init_verbs, 1055 .v.verbs = alc_gpio2_init_verbs,
4441 }, 1056 },
4442 [ALC880_FIXUP_MEDION_RIM] = { 1057 [ALC880_FIXUP_MEDION_RIM] = {
4443 .type = ALC_FIXUP_VERBS, 1058 .type = HDA_FIXUP_VERBS,
4444 .v.verbs = (const struct hda_verb[]) { 1059 .v.verbs = (const struct hda_verb[]) {
4445 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1060 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4446 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 }, 1061 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
@@ -4450,8 +1065,8 @@ static const struct alc_fixup alc880_fixups[] = {
4450 .chain_id = ALC880_FIXUP_GPIO2, 1065 .chain_id = ALC880_FIXUP_GPIO2,
4451 }, 1066 },
4452 [ALC880_FIXUP_LG] = { 1067 [ALC880_FIXUP_LG] = {
4453 .type = ALC_FIXUP_PINS, 1068 .type = HDA_FIXUP_PINS,
4454 .v.pins = (const struct alc_pincfg[]) { 1069 .v.pins = (const struct hda_pintbl[]) {
4455 /* disable bogus unused pins */ 1070 /* disable bogus unused pins */
4456 { 0x16, 0x411111f0 }, 1071 { 0x16, 0x411111f0 },
4457 { 0x18, 0x411111f0 }, 1072 { 0x18, 0x411111f0 },
@@ -4460,8 +1075,8 @@ static const struct alc_fixup alc880_fixups[] = {
4460 } 1075 }
4461 }, 1076 },
4462 [ALC880_FIXUP_W810] = { 1077 [ALC880_FIXUP_W810] = {
4463 .type = ALC_FIXUP_PINS, 1078 .type = HDA_FIXUP_PINS,
4464 .v.pins = (const struct alc_pincfg[]) { 1079 .v.pins = (const struct hda_pintbl[]) {
4465 /* disable bogus unused pins */ 1080 /* disable bogus unused pins */
4466 { 0x17, 0x411111f0 }, 1081 { 0x17, 0x411111f0 },
4467 { } 1082 { }
@@ -4470,7 +1085,7 @@ static const struct alc_fixup alc880_fixups[] = {
4470 .chain_id = ALC880_FIXUP_GPIO2, 1085 .chain_id = ALC880_FIXUP_GPIO2,
4471 }, 1086 },
4472 [ALC880_FIXUP_EAPD_COEF] = { 1087 [ALC880_FIXUP_EAPD_COEF] = {
4473 .type = ALC_FIXUP_VERBS, 1088 .type = HDA_FIXUP_VERBS,
4474 .v.verbs = (const struct hda_verb[]) { 1089 .v.verbs = (const struct hda_verb[]) {
4475 /* change to EAPD mode */ 1090 /* change to EAPD mode */
4476 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1091 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -4479,7 +1094,7 @@ static const struct alc_fixup alc880_fixups[] = {
4479 }, 1094 },
4480 }, 1095 },
4481 [ALC880_FIXUP_TCL_S700] = { 1096 [ALC880_FIXUP_TCL_S700] = {
4482 .type = ALC_FIXUP_VERBS, 1097 .type = HDA_FIXUP_VERBS,
4483 .v.verbs = (const struct hda_verb[]) { 1098 .v.verbs = (const struct hda_verb[]) {
4484 /* change to EAPD mode */ 1099 /* change to EAPD mode */
4485 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1100 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -4490,13 +1105,13 @@ static const struct alc_fixup alc880_fixups[] = {
4490 .chain_id = ALC880_FIXUP_GPIO2, 1105 .chain_id = ALC880_FIXUP_GPIO2,
4491 }, 1106 },
4492 [ALC880_FIXUP_VOL_KNOB] = { 1107 [ALC880_FIXUP_VOL_KNOB] = {
4493 .type = ALC_FIXUP_FUNC, 1108 .type = HDA_FIXUP_FUNC,
4494 .v.func = alc880_fixup_vol_knob, 1109 .v.func = alc880_fixup_vol_knob,
4495 }, 1110 },
4496 [ALC880_FIXUP_FUJITSU] = { 1111 [ALC880_FIXUP_FUJITSU] = {
4497 /* override all pins as BIOS on old Amilo is broken */ 1112 /* override all pins as BIOS on old Amilo is broken */
4498 .type = ALC_FIXUP_PINS, 1113 .type = HDA_FIXUP_PINS,
4499 .v.pins = (const struct alc_pincfg[]) { 1114 .v.pins = (const struct hda_pintbl[]) {
4500 { 0x14, 0x0121411f }, /* HP */ 1115 { 0x14, 0x0121411f }, /* HP */
4501 { 0x15, 0x99030120 }, /* speaker */ 1116 { 0x15, 0x99030120 }, /* speaker */
4502 { 0x16, 0x99030130 }, /* bass speaker */ 1117 { 0x16, 0x99030130 }, /* bass speaker */
@@ -4515,8 +1130,8 @@ static const struct alc_fixup alc880_fixups[] = {
4515 }, 1130 },
4516 [ALC880_FIXUP_F1734] = { 1131 [ALC880_FIXUP_F1734] = {
4517 /* almost compatible with FUJITSU, but no bass and SPDIF */ 1132 /* almost compatible with FUJITSU, but no bass and SPDIF */
4518 .type = ALC_FIXUP_PINS, 1133 .type = HDA_FIXUP_PINS,
4519 .v.pins = (const struct alc_pincfg[]) { 1134 .v.pins = (const struct hda_pintbl[]) {
4520 { 0x14, 0x0121411f }, /* HP */ 1135 { 0x14, 0x0121411f }, /* HP */
4521 { 0x15, 0x99030120 }, /* speaker */ 1136 { 0x15, 0x99030120 }, /* speaker */
4522 { 0x16, 0x411111f0 }, /* N/A */ 1137 { 0x16, 0x411111f0 }, /* N/A */
@@ -4535,8 +1150,8 @@ static const struct alc_fixup alc880_fixups[] = {
4535 }, 1150 },
4536 [ALC880_FIXUP_UNIWILL] = { 1151 [ALC880_FIXUP_UNIWILL] = {
4537 /* need to fix HP and speaker pins to be parsed correctly */ 1152 /* need to fix HP and speaker pins to be parsed correctly */
4538 .type = ALC_FIXUP_PINS, 1153 .type = HDA_FIXUP_PINS,
4539 .v.pins = (const struct alc_pincfg[]) { 1154 .v.pins = (const struct hda_pintbl[]) {
4540 { 0x14, 0x0121411f }, /* HP */ 1155 { 0x14, 0x0121411f }, /* HP */
4541 { 0x15, 0x99030120 }, /* speaker */ 1156 { 0x15, 0x99030120 }, /* speaker */
4542 { 0x16, 0x99030130 }, /* bass speaker */ 1157 { 0x16, 0x99030130 }, /* bass speaker */
@@ -4544,8 +1159,8 @@ static const struct alc_fixup alc880_fixups[] = {
4544 }, 1159 },
4545 }, 1160 },
4546 [ALC880_FIXUP_UNIWILL_DIG] = { 1161 [ALC880_FIXUP_UNIWILL_DIG] = {
4547 .type = ALC_FIXUP_PINS, 1162 .type = HDA_FIXUP_PINS,
4548 .v.pins = (const struct alc_pincfg[]) { 1163 .v.pins = (const struct hda_pintbl[]) {
4549 /* disable bogus unused pins */ 1164 /* disable bogus unused pins */
4550 { 0x17, 0x411111f0 }, 1165 { 0x17, 0x411111f0 },
4551 { 0x19, 0x411111f0 }, 1166 { 0x19, 0x411111f0 },
@@ -4555,8 +1170,8 @@ static const struct alc_fixup alc880_fixups[] = {
4555 } 1170 }
4556 }, 1171 },
4557 [ALC880_FIXUP_Z71V] = { 1172 [ALC880_FIXUP_Z71V] = {
4558 .type = ALC_FIXUP_PINS, 1173 .type = HDA_FIXUP_PINS,
4559 .v.pins = (const struct alc_pincfg[]) { 1174 .v.pins = (const struct hda_pintbl[]) {
4560 /* set up the whole pins as BIOS is utterly broken */ 1175 /* set up the whole pins as BIOS is utterly broken */
4561 { 0x14, 0x99030120 }, /* speaker */ 1176 { 0x14, 0x99030120 }, /* speaker */
4562 { 0x15, 0x0121411f }, /* HP */ 1177 { 0x15, 0x0121411f }, /* HP */
@@ -4573,8 +1188,8 @@ static const struct alc_fixup alc880_fixups[] = {
4573 } 1188 }
4574 }, 1189 },
4575 [ALC880_FIXUP_3ST_BASE] = { 1190 [ALC880_FIXUP_3ST_BASE] = {
4576 .type = ALC_FIXUP_PINS, 1191 .type = HDA_FIXUP_PINS,
4577 .v.pins = (const struct alc_pincfg[]) { 1192 .v.pins = (const struct hda_pintbl[]) {
4578 { 0x14, 0x01014010 }, /* line-out */ 1193 { 0x14, 0x01014010 }, /* line-out */
4579 { 0x15, 0x411111f0 }, /* N/A */ 1194 { 0x15, 0x411111f0 }, /* N/A */
4580 { 0x16, 0x411111f0 }, /* N/A */ 1195 { 0x16, 0x411111f0 }, /* N/A */
@@ -4591,8 +1206,8 @@ static const struct alc_fixup alc880_fixups[] = {
4591 } 1206 }
4592 }, 1207 },
4593 [ALC880_FIXUP_3ST] = { 1208 [ALC880_FIXUP_3ST] = {
4594 .type = ALC_FIXUP_PINS, 1209 .type = HDA_FIXUP_PINS,
4595 .v.pins = (const struct alc_pincfg[]) { 1210 .v.pins = (const struct hda_pintbl[]) {
4596 { 0x1e, 0x411111f0 }, /* N/A */ 1211 { 0x1e, 0x411111f0 }, /* N/A */
4597 { } 1212 { }
4598 }, 1213 },
@@ -4600,8 +1215,8 @@ static const struct alc_fixup alc880_fixups[] = {
4600 .chain_id = ALC880_FIXUP_3ST_BASE, 1215 .chain_id = ALC880_FIXUP_3ST_BASE,
4601 }, 1216 },
4602 [ALC880_FIXUP_3ST_DIG] = { 1217 [ALC880_FIXUP_3ST_DIG] = {
4603 .type = ALC_FIXUP_PINS, 1218 .type = HDA_FIXUP_PINS,
4604 .v.pins = (const struct alc_pincfg[]) { 1219 .v.pins = (const struct hda_pintbl[]) {
4605 { 0x1e, 0x0144111e }, /* SPDIF */ 1220 { 0x1e, 0x0144111e }, /* SPDIF */
4606 { } 1221 { }
4607 }, 1222 },
@@ -4609,8 +1224,8 @@ static const struct alc_fixup alc880_fixups[] = {
4609 .chain_id = ALC880_FIXUP_3ST_BASE, 1224 .chain_id = ALC880_FIXUP_3ST_BASE,
4610 }, 1225 },
4611 [ALC880_FIXUP_5ST_BASE] = { 1226 [ALC880_FIXUP_5ST_BASE] = {
4612 .type = ALC_FIXUP_PINS, 1227 .type = HDA_FIXUP_PINS,
4613 .v.pins = (const struct alc_pincfg[]) { 1228 .v.pins = (const struct hda_pintbl[]) {
4614 { 0x14, 0x01014010 }, /* front */ 1229 { 0x14, 0x01014010 }, /* front */
4615 { 0x15, 0x411111f0 }, /* N/A */ 1230 { 0x15, 0x411111f0 }, /* N/A */
4616 { 0x16, 0x01011411 }, /* CLFE */ 1231 { 0x16, 0x01011411 }, /* CLFE */
@@ -4627,8 +1242,8 @@ static const struct alc_fixup alc880_fixups[] = {
4627 } 1242 }
4628 }, 1243 },
4629 [ALC880_FIXUP_5ST] = { 1244 [ALC880_FIXUP_5ST] = {
4630 .type = ALC_FIXUP_PINS, 1245 .type = HDA_FIXUP_PINS,
4631 .v.pins = (const struct alc_pincfg[]) { 1246 .v.pins = (const struct hda_pintbl[]) {
4632 { 0x1e, 0x411111f0 }, /* N/A */ 1247 { 0x1e, 0x411111f0 }, /* N/A */
4633 { } 1248 { }
4634 }, 1249 },
@@ -4636,8 +1251,8 @@ static const struct alc_fixup alc880_fixups[] = {
4636 .chain_id = ALC880_FIXUP_5ST_BASE, 1251 .chain_id = ALC880_FIXUP_5ST_BASE,
4637 }, 1252 },
4638 [ALC880_FIXUP_5ST_DIG] = { 1253 [ALC880_FIXUP_5ST_DIG] = {
4639 .type = ALC_FIXUP_PINS, 1254 .type = HDA_FIXUP_PINS,
4640 .v.pins = (const struct alc_pincfg[]) { 1255 .v.pins = (const struct hda_pintbl[]) {
4641 { 0x1e, 0x0144111e }, /* SPDIF */ 1256 { 0x1e, 0x0144111e }, /* SPDIF */
4642 { } 1257 { }
4643 }, 1258 },
@@ -4645,8 +1260,8 @@ static const struct alc_fixup alc880_fixups[] = {
4645 .chain_id = ALC880_FIXUP_5ST_BASE, 1260 .chain_id = ALC880_FIXUP_5ST_BASE,
4646 }, 1261 },
4647 [ALC880_FIXUP_6ST_BASE] = { 1262 [ALC880_FIXUP_6ST_BASE] = {
4648 .type = ALC_FIXUP_PINS, 1263 .type = HDA_FIXUP_PINS,
4649 .v.pins = (const struct alc_pincfg[]) { 1264 .v.pins = (const struct hda_pintbl[]) {
4650 { 0x14, 0x01014010 }, /* front */ 1265 { 0x14, 0x01014010 }, /* front */
4651 { 0x15, 0x01016412 }, /* surr */ 1266 { 0x15, 0x01016412 }, /* surr */
4652 { 0x16, 0x01011411 }, /* CLFE */ 1267 { 0x16, 0x01011411 }, /* CLFE */
@@ -4663,8 +1278,8 @@ static const struct alc_fixup alc880_fixups[] = {
4663 } 1278 }
4664 }, 1279 },
4665 [ALC880_FIXUP_6ST] = { 1280 [ALC880_FIXUP_6ST] = {
4666 .type = ALC_FIXUP_PINS, 1281 .type = HDA_FIXUP_PINS,
4667 .v.pins = (const struct alc_pincfg[]) { 1282 .v.pins = (const struct hda_pintbl[]) {
4668 { 0x1e, 0x411111f0 }, /* N/A */ 1283 { 0x1e, 0x411111f0 }, /* N/A */
4669 { } 1284 { }
4670 }, 1285 },
@@ -4672,14 +1287,23 @@ static const struct alc_fixup alc880_fixups[] = {
4672 .chain_id = ALC880_FIXUP_6ST_BASE, 1287 .chain_id = ALC880_FIXUP_6ST_BASE,
4673 }, 1288 },
4674 [ALC880_FIXUP_6ST_DIG] = { 1289 [ALC880_FIXUP_6ST_DIG] = {
4675 .type = ALC_FIXUP_PINS, 1290 .type = HDA_FIXUP_PINS,
4676 .v.pins = (const struct alc_pincfg[]) { 1291 .v.pins = (const struct hda_pintbl[]) {
4677 { 0x1e, 0x0144111e }, /* SPDIF */ 1292 { 0x1e, 0x0144111e }, /* SPDIF */
4678 { } 1293 { }
4679 }, 1294 },
4680 .chained = true, 1295 .chained = true,
4681 .chain_id = ALC880_FIXUP_6ST_BASE, 1296 .chain_id = ALC880_FIXUP_6ST_BASE,
4682 }, 1297 },
1298 [ALC880_FIXUP_6ST_AUTOMUTE] = {
1299 .type = HDA_FIXUP_PINS,
1300 .v.pins = (const struct hda_pintbl[]) {
1301 { 0x1b, 0x0121401f }, /* HP with jack detect */
1302 { }
1303 },
1304 .chained_before = true,
1305 .chain_id = ALC880_FIXUP_6ST_BASE,
1306 },
4683}; 1307};
4684 1308
4685static const struct snd_pci_quirk alc880_fixup_tbl[] = { 1309static const struct snd_pci_quirk alc880_fixup_tbl[] = {
@@ -4694,7 +1318,7 @@ static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4694 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB), 1318 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
4695 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810), 1319 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
4696 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM), 1320 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4697 SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST), 1321 SND_PCI_QUIRK(0x1631, 0xe011, "PB 13201056", ALC880_FIXUP_6ST_AUTOMUTE),
4698 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734), 1322 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
4699 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU), 1323 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
4700 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734), 1324 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
@@ -4750,13 +1374,14 @@ static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4750 {} 1374 {}
4751}; 1375};
4752 1376
4753static const struct alc_model_fixup alc880_fixup_models[] = { 1377static const struct hda_model_fixup alc880_fixup_models[] = {
4754 {.id = ALC880_FIXUP_3ST, .name = "3stack"}, 1378 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4755 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"}, 1379 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4756 {.id = ALC880_FIXUP_5ST, .name = "5stack"}, 1380 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4757 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"}, 1381 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4758 {.id = ALC880_FIXUP_6ST, .name = "6stack"}, 1382 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4759 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"}, 1383 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
1384 {.id = ALC880_FIXUP_6ST_AUTOMUTE, .name = "6stack-automute"},
4760 {} 1385 {}
4761}; 1386};
4762 1387
@@ -4774,18 +1399,18 @@ static int patch_alc880(struct hda_codec *codec)
4774 return err; 1399 return err;
4775 1400
4776 spec = codec->spec; 1401 spec = codec->spec;
4777 spec->need_dac_fix = 1; 1402 spec->gen.need_dac_fix = 1;
4778 1403
4779 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl, 1404 snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4780 alc880_fixups); 1405 alc880_fixups);
4781 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 1406 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4782 1407
4783 /* automatic parse from the BIOS config */ 1408 /* automatic parse from the BIOS config */
4784 err = alc880_parse_auto_config(codec); 1409 err = alc880_parse_auto_config(codec);
4785 if (err < 0) 1410 if (err < 0)
4786 goto error; 1411 goto error;
4787 1412
4788 if (!spec->no_analog) { 1413 if (!spec->gen.no_analog) {
4789 err = snd_hda_attach_beep_device(codec, 0x1); 1414 err = snd_hda_attach_beep_device(codec, 0x1);
4790 if (err < 0) 1415 if (err < 0)
4791 goto error; 1416 goto error;
@@ -4796,7 +1421,7 @@ static int patch_alc880(struct hda_codec *codec)
4796 codec->patch_ops.unsol_event = alc880_unsol_event; 1421 codec->patch_ops.unsol_event = alc880_unsol_event;
4797 1422
4798 1423
4799 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 1424 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4800 1425
4801 return 0; 1426 return 0;
4802 1427
@@ -4828,38 +1453,39 @@ enum {
4828 ALC260_FIXUP_REPLACER, 1453 ALC260_FIXUP_REPLACER,
4829 ALC260_FIXUP_HP_B1900, 1454 ALC260_FIXUP_HP_B1900,
4830 ALC260_FIXUP_KN1, 1455 ALC260_FIXUP_KN1,
1456 ALC260_FIXUP_FSC_S7020,
4831}; 1457};
4832 1458
4833static void alc260_gpio1_automute(struct hda_codec *codec) 1459static void alc260_gpio1_automute(struct hda_codec *codec)
4834{ 1460{
4835 struct alc_spec *spec = codec->spec; 1461 struct alc_spec *spec = codec->spec;
4836 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 1462 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4837 spec->hp_jack_present); 1463 spec->gen.hp_jack_present);
4838} 1464}
4839 1465
4840static void alc260_fixup_gpio1_toggle(struct hda_codec *codec, 1466static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4841 const struct alc_fixup *fix, int action) 1467 const struct hda_fixup *fix, int action)
4842{ 1468{
4843 struct alc_spec *spec = codec->spec; 1469 struct alc_spec *spec = codec->spec;
4844 if (action == ALC_FIXUP_ACT_PROBE) { 1470 if (action == HDA_FIXUP_ACT_PROBE) {
4845 /* although the machine has only one output pin, we need to 1471 /* although the machine has only one output pin, we need to
4846 * toggle GPIO1 according to the jack state 1472 * toggle GPIO1 according to the jack state
4847 */ 1473 */
4848 spec->automute_hook = alc260_gpio1_automute; 1474 spec->gen.automute_hook = alc260_gpio1_automute;
4849 spec->detect_hp = 1; 1475 spec->gen.detect_hp = 1;
4850 spec->automute_speaker = 1; 1476 spec->gen.automute_speaker = 1;
4851 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */ 1477 spec->gen.autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4852 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT, 1478 snd_hda_jack_detect_enable_callback(codec, 0x0f, HDA_GEN_HP_EVENT,
4853 alc_hp_automute); 1479 snd_hda_gen_hp_automute);
4854 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs); 1480 snd_hda_add_verbs(codec, alc_gpio1_init_verbs);
4855 } 1481 }
4856} 1482}
4857 1483
4858static void alc260_fixup_kn1(struct hda_codec *codec, 1484static void alc260_fixup_kn1(struct hda_codec *codec,
4859 const struct alc_fixup *fix, int action) 1485 const struct hda_fixup *fix, int action)
4860{ 1486{
4861 struct alc_spec *spec = codec->spec; 1487 struct alc_spec *spec = codec->spec;
4862 static const struct alc_pincfg pincfgs[] = { 1488 static const struct hda_pintbl pincfgs[] = {
4863 { 0x0f, 0x02214000 }, /* HP/speaker */ 1489 { 0x0f, 0x02214000 }, /* HP/speaker */
4864 { 0x12, 0x90a60160 }, /* int mic */ 1490 { 0x12, 0x90a60160 }, /* int mic */
4865 { 0x13, 0x02a19000 }, /* ext mic */ 1491 { 0x13, 0x02a19000 }, /* ext mic */
@@ -4876,32 +1502,47 @@ static void alc260_fixup_kn1(struct hda_codec *codec,
4876 }; 1502 };
4877 1503
4878 switch (action) { 1504 switch (action) {
4879 case ALC_FIXUP_ACT_PRE_PROBE: 1505 case HDA_FIXUP_ACT_PRE_PROBE:
4880 alc_apply_pincfgs(codec, pincfgs); 1506 snd_hda_apply_pincfgs(codec, pincfgs);
4881 break; 1507 break;
4882 case ALC_FIXUP_ACT_PROBE: 1508 case HDA_FIXUP_ACT_PROBE:
4883 spec->init_amp = ALC_INIT_NONE; 1509 spec->init_amp = ALC_INIT_NONE;
4884 break; 1510 break;
4885 } 1511 }
4886} 1512}
4887 1513
4888static const struct alc_fixup alc260_fixups[] = { 1514static void alc260_fixup_fsc_s7020(struct hda_codec *codec,
1515 const struct hda_fixup *fix, int action)
1516{
1517 struct alc_spec *spec = codec->spec;
1518
1519 switch (action) {
1520 case HDA_FIXUP_ACT_PRE_PROBE:
1521 spec->gen.add_out_jack_modes = 1;
1522 break;
1523 case HDA_FIXUP_ACT_PROBE:
1524 spec->init_amp = ALC_INIT_NONE;
1525 break;
1526 }
1527}
1528
1529static const struct hda_fixup alc260_fixups[] = {
4889 [ALC260_FIXUP_HP_DC5750] = { 1530 [ALC260_FIXUP_HP_DC5750] = {
4890 .type = ALC_FIXUP_PINS, 1531 .type = HDA_FIXUP_PINS,
4891 .v.pins = (const struct alc_pincfg[]) { 1532 .v.pins = (const struct hda_pintbl[]) {
4892 { 0x11, 0x90130110 }, /* speaker */ 1533 { 0x11, 0x90130110 }, /* speaker */
4893 { } 1534 { }
4894 } 1535 }
4895 }, 1536 },
4896 [ALC260_FIXUP_HP_PIN_0F] = { 1537 [ALC260_FIXUP_HP_PIN_0F] = {
4897 .type = ALC_FIXUP_PINS, 1538 .type = HDA_FIXUP_PINS,
4898 .v.pins = (const struct alc_pincfg[]) { 1539 .v.pins = (const struct hda_pintbl[]) {
4899 { 0x0f, 0x01214000 }, /* HP */ 1540 { 0x0f, 0x01214000 }, /* HP */
4900 { } 1541 { }
4901 } 1542 }
4902 }, 1543 },
4903 [ALC260_FIXUP_COEF] = { 1544 [ALC260_FIXUP_COEF] = {
4904 .type = ALC_FIXUP_VERBS, 1545 .type = HDA_FIXUP_VERBS,
4905 .v.verbs = (const struct hda_verb[]) { 1546 .v.verbs = (const struct hda_verb[]) {
4906 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1547 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4907 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 }, 1548 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
@@ -4911,17 +1552,17 @@ static const struct alc_fixup alc260_fixups[] = {
4911 .chain_id = ALC260_FIXUP_HP_PIN_0F, 1552 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4912 }, 1553 },
4913 [ALC260_FIXUP_GPIO1] = { 1554 [ALC260_FIXUP_GPIO1] = {
4914 .type = ALC_FIXUP_VERBS, 1555 .type = HDA_FIXUP_VERBS,
4915 .v.verbs = alc_gpio1_init_verbs, 1556 .v.verbs = alc_gpio1_init_verbs,
4916 }, 1557 },
4917 [ALC260_FIXUP_GPIO1_TOGGLE] = { 1558 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4918 .type = ALC_FIXUP_FUNC, 1559 .type = HDA_FIXUP_FUNC,
4919 .v.func = alc260_fixup_gpio1_toggle, 1560 .v.func = alc260_fixup_gpio1_toggle,
4920 .chained = true, 1561 .chained = true,
4921 .chain_id = ALC260_FIXUP_HP_PIN_0F, 1562 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4922 }, 1563 },
4923 [ALC260_FIXUP_REPLACER] = { 1564 [ALC260_FIXUP_REPLACER] = {
4924 .type = ALC_FIXUP_VERBS, 1565 .type = HDA_FIXUP_VERBS,
4925 .v.verbs = (const struct hda_verb[]) { 1566 .v.verbs = (const struct hda_verb[]) {
4926 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1567 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4927 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, 1568 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
@@ -4931,15 +1572,19 @@ static const struct alc_fixup alc260_fixups[] = {
4931 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE, 1572 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4932 }, 1573 },
4933 [ALC260_FIXUP_HP_B1900] = { 1574 [ALC260_FIXUP_HP_B1900] = {
4934 .type = ALC_FIXUP_FUNC, 1575 .type = HDA_FIXUP_FUNC,
4935 .v.func = alc260_fixup_gpio1_toggle, 1576 .v.func = alc260_fixup_gpio1_toggle,
4936 .chained = true, 1577 .chained = true,
4937 .chain_id = ALC260_FIXUP_COEF, 1578 .chain_id = ALC260_FIXUP_COEF,
4938 }, 1579 },
4939 [ALC260_FIXUP_KN1] = { 1580 [ALC260_FIXUP_KN1] = {
4940 .type = ALC_FIXUP_FUNC, 1581 .type = HDA_FIXUP_FUNC,
4941 .v.func = alc260_fixup_kn1, 1582 .v.func = alc260_fixup_kn1,
4942 }, 1583 },
1584 [ALC260_FIXUP_FSC_S7020] = {
1585 .type = HDA_FIXUP_FUNC,
1586 .v.func = alc260_fixup_fsc_s7020,
1587 },
4943}; 1588};
4944 1589
4945static const struct snd_pci_quirk alc260_fixup_tbl[] = { 1590static const struct snd_pci_quirk alc260_fixup_tbl[] = {
@@ -4948,6 +1593,7 @@ static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4948 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1), 1593 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
4949 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750), 1594 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
4950 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900), 1595 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
1596 SND_PCI_QUIRK(0x10cf, 0x1326, "FSC LifeBook S7020", ALC260_FIXUP_FSC_S7020),
4951 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1), 1597 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
4952 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1), 1598 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
4953 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER), 1599 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
@@ -4967,16 +1613,21 @@ static int patch_alc260(struct hda_codec *codec)
4967 return err; 1613 return err;
4968 1614
4969 spec = codec->spec; 1615 spec = codec->spec;
1616 /* as quite a few machines require HP amp for speaker outputs,
1617 * it's easier to enable it unconditionally; even if it's unneeded,
1618 * it's almost harmless.
1619 */
1620 spec->gen.prefer_hp_amp = 1;
4970 1621
4971 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups); 1622 snd_hda_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4972 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 1623 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4973 1624
4974 /* automatic parse from the BIOS config */ 1625 /* automatic parse from the BIOS config */
4975 err = alc260_parse_auto_config(codec); 1626 err = alc260_parse_auto_config(codec);
4976 if (err < 0) 1627 if (err < 0)
4977 goto error; 1628 goto error;
4978 1629
4979 if (!spec->no_analog) { 1630 if (!spec->gen.no_analog) {
4980 err = snd_hda_attach_beep_device(codec, 0x1); 1631 err = snd_hda_attach_beep_device(codec, 0x1);
4981 if (err < 0) 1632 if (err < 0)
4982 goto error; 1633 goto error;
@@ -4986,7 +1637,7 @@ static int patch_alc260(struct hda_codec *codec)
4986 codec->patch_ops = alc_patch_ops; 1637 codec->patch_ops = alc_patch_ops;
4987 spec->shutup = alc_eapd_shutup; 1638 spec->shutup = alc_eapd_shutup;
4988 1639
4989 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 1640 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4990 1641
4991 return 0; 1642 return 0;
4992 1643
@@ -5040,9 +1691,9 @@ enum {
5040}; 1691};
5041 1692
5042static void alc889_fixup_coef(struct hda_codec *codec, 1693static void alc889_fixup_coef(struct hda_codec *codec,
5043 const struct alc_fixup *fix, int action) 1694 const struct hda_fixup *fix, int action)
5044{ 1695{
5045 if (action != ALC_FIXUP_ACT_INIT) 1696 if (action != HDA_FIXUP_ACT_INIT)
5046 return; 1697 return;
5047 alc889_coef_init(codec); 1698 alc889_coef_init(codec);
5048} 1699}
@@ -5082,9 +1733,9 @@ static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5082 1733
5083/* set up GPIO at initialization */ 1734/* set up GPIO at initialization */
5084static void alc885_fixup_macpro_gpio(struct hda_codec *codec, 1735static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5085 const struct alc_fixup *fix, int action) 1736 const struct hda_fixup *fix, int action)
5086{ 1737{
5087 if (action != ALC_FIXUP_ACT_INIT) 1738 if (action != HDA_FIXUP_ACT_INIT)
5088 return; 1739 return;
5089 alc882_gpio_mute(codec, 0, 0); 1740 alc882_gpio_mute(codec, 0, 0);
5090 alc882_gpio_mute(codec, 1, 0); 1741 alc882_gpio_mute(codec, 1, 0);
@@ -5095,9 +1746,9 @@ static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5095 * work correctly (bko#42740) 1746 * work correctly (bko#42740)
5096 */ 1747 */
5097static void alc889_fixup_dac_route(struct hda_codec *codec, 1748static void alc889_fixup_dac_route(struct hda_codec *codec,
5098 const struct alc_fixup *fix, int action) 1749 const struct hda_fixup *fix, int action)
5099{ 1750{
5100 if (action == ALC_FIXUP_ACT_PRE_PROBE) { 1751 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5101 /* fake the connections during parsing the tree */ 1752 /* fake the connections during parsing the tree */
5102 hda_nid_t conn1[2] = { 0x0c, 0x0d }; 1753 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5103 hda_nid_t conn2[2] = { 0x0e, 0x0f }; 1754 hda_nid_t conn2[2] = { 0x0e, 0x0f };
@@ -5105,7 +1756,7 @@ static void alc889_fixup_dac_route(struct hda_codec *codec,
5105 snd_hda_override_conn_list(codec, 0x15, 2, conn1); 1756 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5106 snd_hda_override_conn_list(codec, 0x18, 2, conn2); 1757 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5107 snd_hda_override_conn_list(codec, 0x1a, 2, conn2); 1758 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5108 } else if (action == ALC_FIXUP_ACT_PROBE) { 1759 } else if (action == HDA_FIXUP_ACT_PROBE) {
5109 /* restore the connections */ 1760 /* restore the connections */
5110 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 }; 1761 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5111 snd_hda_override_conn_list(codec, 0x14, 5, conn); 1762 snd_hda_override_conn_list(codec, 0x14, 5, conn);
@@ -5117,62 +1768,61 @@ static void alc889_fixup_dac_route(struct hda_codec *codec,
5117 1768
5118/* Set VREF on HP pin */ 1769/* Set VREF on HP pin */
5119static void alc889_fixup_mbp_vref(struct hda_codec *codec, 1770static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5120 const struct alc_fixup *fix, int action) 1771 const struct hda_fixup *fix, int action)
5121{ 1772{
5122 struct alc_spec *spec = codec->spec; 1773 struct alc_spec *spec = codec->spec;
5123 static hda_nid_t nids[2] = { 0x14, 0x15 }; 1774 static hda_nid_t nids[2] = { 0x14, 0x15 };
5124 int i; 1775 int i;
5125 1776
5126 if (action != ALC_FIXUP_ACT_INIT) 1777 if (action != HDA_FIXUP_ACT_INIT)
5127 return; 1778 return;
5128 for (i = 0; i < ARRAY_SIZE(nids); i++) { 1779 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5129 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]); 1780 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5130 if (get_defcfg_device(val) != AC_JACK_HP_OUT) 1781 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5131 continue; 1782 continue;
5132 val = snd_hda_codec_read(codec, nids[i], 0, 1783 val = snd_hda_codec_get_pin_target(codec, nids[i]);
5133 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5134 val |= AC_PINCTL_VREF_80; 1784 val |= AC_PINCTL_VREF_80;
5135 snd_hda_set_pin_ctl(codec, nids[i], val); 1785 snd_hda_set_pin_ctl(codec, nids[i], val);
5136 spec->keep_vref_in_automute = 1; 1786 spec->gen.keep_vref_in_automute = 1;
5137 break; 1787 break;
5138 } 1788 }
5139} 1789}
5140 1790
5141/* Set VREF on speaker pins on imac91 */ 1791/* Set VREF on speaker pins on imac91 */
5142static void alc889_fixup_imac91_vref(struct hda_codec *codec, 1792static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5143 const struct alc_fixup *fix, int action) 1793 const struct hda_fixup *fix, int action)
5144{ 1794{
5145 struct alc_spec *spec = codec->spec; 1795 struct alc_spec *spec = codec->spec;
5146 static hda_nid_t nids[2] = { 0x18, 0x1a }; 1796 static hda_nid_t nids[2] = { 0x18, 0x1a };
5147 int i; 1797 int i;
5148 1798
5149 if (action != ALC_FIXUP_ACT_INIT) 1799 if (action != HDA_FIXUP_ACT_INIT)
5150 return; 1800 return;
5151 for (i = 0; i < ARRAY_SIZE(nids); i++) { 1801 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5152 unsigned int val; 1802 unsigned int val;
5153 val = snd_hda_codec_read(codec, nids[i], 0, 1803 val = snd_hda_codec_get_pin_target(codec, nids[i]);
5154 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5155 val |= AC_PINCTL_VREF_50; 1804 val |= AC_PINCTL_VREF_50;
5156 snd_hda_set_pin_ctl(codec, nids[i], val); 1805 snd_hda_set_pin_ctl(codec, nids[i], val);
5157 } 1806 }
5158 spec->keep_vref_in_automute = 1; 1807 spec->gen.keep_vref_in_automute = 1;
5159} 1808}
5160 1809
5161/* Don't take HP output as primary 1810/* Don't take HP output as primary
5162 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05 1811 * Strangely, the speaker output doesn't work on Vaio Z and some Vaio
1812 * all-in-one desktop PCs (for example VGC-LN51JGB) through DAC 0x05
5163 */ 1813 */
5164static void alc882_fixup_no_primary_hp(struct hda_codec *codec, 1814static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5165 const struct alc_fixup *fix, int action) 1815 const struct hda_fixup *fix, int action)
5166{ 1816{
5167 struct alc_spec *spec = codec->spec; 1817 struct alc_spec *spec = codec->spec;
5168 if (action == ALC_FIXUP_ACT_PRE_PROBE) 1818 if (action == HDA_FIXUP_ACT_PRE_PROBE)
5169 spec->no_primary_hp = 1; 1819 spec->gen.no_primary_hp = 1;
5170} 1820}
5171 1821
5172static const struct alc_fixup alc882_fixups[] = { 1822static const struct hda_fixup alc882_fixups[] = {
5173 [ALC882_FIXUP_ABIT_AW9D_MAX] = { 1823 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
5174 .type = ALC_FIXUP_PINS, 1824 .type = HDA_FIXUP_PINS,
5175 .v.pins = (const struct alc_pincfg[]) { 1825 .v.pins = (const struct hda_pintbl[]) {
5176 { 0x15, 0x01080104 }, /* side */ 1826 { 0x15, 0x01080104 }, /* side */
5177 { 0x16, 0x01011012 }, /* rear */ 1827 { 0x16, 0x01011012 }, /* rear */
5178 { 0x17, 0x01016011 }, /* clfe */ 1828 { 0x17, 0x01016011 }, /* clfe */
@@ -5180,47 +1830,47 @@ static const struct alc_fixup alc882_fixups[] = {
5180 } 1830 }
5181 }, 1831 },
5182 [ALC882_FIXUP_LENOVO_Y530] = { 1832 [ALC882_FIXUP_LENOVO_Y530] = {
5183 .type = ALC_FIXUP_PINS, 1833 .type = HDA_FIXUP_PINS,
5184 .v.pins = (const struct alc_pincfg[]) { 1834 .v.pins = (const struct hda_pintbl[]) {
5185 { 0x15, 0x99130112 }, /* rear int speakers */ 1835 { 0x15, 0x99130112 }, /* rear int speakers */
5186 { 0x16, 0x99130111 }, /* subwoofer */ 1836 { 0x16, 0x99130111 }, /* subwoofer */
5187 { } 1837 { }
5188 } 1838 }
5189 }, 1839 },
5190 [ALC882_FIXUP_PB_M5210] = { 1840 [ALC882_FIXUP_PB_M5210] = {
5191 .type = ALC_FIXUP_VERBS, 1841 .type = HDA_FIXUP_PINCTLS,
5192 .v.verbs = (const struct hda_verb[]) { 1842 .v.pins = (const struct hda_pintbl[]) {
5193 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, 1843 { 0x19, PIN_VREF50 },
5194 {} 1844 {}
5195 } 1845 }
5196 }, 1846 },
5197 [ALC882_FIXUP_ACER_ASPIRE_7736] = { 1847 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
5198 .type = ALC_FIXUP_FUNC, 1848 .type = HDA_FIXUP_FUNC,
5199 .v.func = alc_fixup_sku_ignore, 1849 .v.func = alc_fixup_sku_ignore,
5200 }, 1850 },
5201 [ALC882_FIXUP_ASUS_W90V] = { 1851 [ALC882_FIXUP_ASUS_W90V] = {
5202 .type = ALC_FIXUP_PINS, 1852 .type = HDA_FIXUP_PINS,
5203 .v.pins = (const struct alc_pincfg[]) { 1853 .v.pins = (const struct hda_pintbl[]) {
5204 { 0x16, 0x99130110 }, /* fix sequence for CLFE */ 1854 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5205 { } 1855 { }
5206 } 1856 }
5207 }, 1857 },
5208 [ALC889_FIXUP_CD] = { 1858 [ALC889_FIXUP_CD] = {
5209 .type = ALC_FIXUP_PINS, 1859 .type = HDA_FIXUP_PINS,
5210 .v.pins = (const struct alc_pincfg[]) { 1860 .v.pins = (const struct hda_pintbl[]) {
5211 { 0x1c, 0x993301f0 }, /* CD */ 1861 { 0x1c, 0x993301f0 }, /* CD */
5212 { } 1862 { }
5213 } 1863 }
5214 }, 1864 },
5215 [ALC889_FIXUP_VAIO_TT] = { 1865 [ALC889_FIXUP_VAIO_TT] = {
5216 .type = ALC_FIXUP_PINS, 1866 .type = HDA_FIXUP_PINS,
5217 .v.pins = (const struct alc_pincfg[]) { 1867 .v.pins = (const struct hda_pintbl[]) {
5218 { 0x17, 0x90170111 }, /* hidden surround speaker */ 1868 { 0x17, 0x90170111 }, /* hidden surround speaker */
5219 { } 1869 { }
5220 } 1870 }
5221 }, 1871 },
5222 [ALC888_FIXUP_EEE1601] = { 1872 [ALC888_FIXUP_EEE1601] = {
5223 .type = ALC_FIXUP_VERBS, 1873 .type = HDA_FIXUP_VERBS,
5224 .v.verbs = (const struct hda_verb[]) { 1874 .v.verbs = (const struct hda_verb[]) {
5225 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b }, 1875 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5226 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 }, 1876 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
@@ -5228,7 +1878,7 @@ static const struct alc_fixup alc882_fixups[] = {
5228 } 1878 }
5229 }, 1879 },
5230 [ALC882_FIXUP_EAPD] = { 1880 [ALC882_FIXUP_EAPD] = {
5231 .type = ALC_FIXUP_VERBS, 1881 .type = HDA_FIXUP_VERBS,
5232 .v.verbs = (const struct hda_verb[]) { 1882 .v.verbs = (const struct hda_verb[]) {
5233 /* change to EAPD mode */ 1883 /* change to EAPD mode */
5234 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1884 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -5237,7 +1887,7 @@ static const struct alc_fixup alc882_fixups[] = {
5237 } 1887 }
5238 }, 1888 },
5239 [ALC883_FIXUP_EAPD] = { 1889 [ALC883_FIXUP_EAPD] = {
5240 .type = ALC_FIXUP_VERBS, 1890 .type = HDA_FIXUP_VERBS,
5241 .v.verbs = (const struct hda_verb[]) { 1891 .v.verbs = (const struct hda_verb[]) {
5242 /* change to EAPD mode */ 1892 /* change to EAPD mode */
5243 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1893 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -5246,7 +1896,7 @@ static const struct alc_fixup alc882_fixups[] = {
5246 } 1896 }
5247 }, 1897 },
5248 [ALC883_FIXUP_ACER_EAPD] = { 1898 [ALC883_FIXUP_ACER_EAPD] = {
5249 .type = ALC_FIXUP_VERBS, 1899 .type = HDA_FIXUP_VERBS,
5250 .v.verbs = (const struct hda_verb[]) { 1900 .v.verbs = (const struct hda_verb[]) {
5251 /* eanable EAPD on Acer laptops */ 1901 /* eanable EAPD on Acer laptops */
5252 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 1902 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
@@ -5255,30 +1905,30 @@ static const struct alc_fixup alc882_fixups[] = {
5255 } 1905 }
5256 }, 1906 },
5257 [ALC882_FIXUP_GPIO1] = { 1907 [ALC882_FIXUP_GPIO1] = {
5258 .type = ALC_FIXUP_VERBS, 1908 .type = HDA_FIXUP_VERBS,
5259 .v.verbs = alc_gpio1_init_verbs, 1909 .v.verbs = alc_gpio1_init_verbs,
5260 }, 1910 },
5261 [ALC882_FIXUP_GPIO2] = { 1911 [ALC882_FIXUP_GPIO2] = {
5262 .type = ALC_FIXUP_VERBS, 1912 .type = HDA_FIXUP_VERBS,
5263 .v.verbs = alc_gpio2_init_verbs, 1913 .v.verbs = alc_gpio2_init_verbs,
5264 }, 1914 },
5265 [ALC882_FIXUP_GPIO3] = { 1915 [ALC882_FIXUP_GPIO3] = {
5266 .type = ALC_FIXUP_VERBS, 1916 .type = HDA_FIXUP_VERBS,
5267 .v.verbs = alc_gpio3_init_verbs, 1917 .v.verbs = alc_gpio3_init_verbs,
5268 }, 1918 },
5269 [ALC882_FIXUP_ASUS_W2JC] = { 1919 [ALC882_FIXUP_ASUS_W2JC] = {
5270 .type = ALC_FIXUP_VERBS, 1920 .type = HDA_FIXUP_VERBS,
5271 .v.verbs = alc_gpio1_init_verbs, 1921 .v.verbs = alc_gpio1_init_verbs,
5272 .chained = true, 1922 .chained = true,
5273 .chain_id = ALC882_FIXUP_EAPD, 1923 .chain_id = ALC882_FIXUP_EAPD,
5274 }, 1924 },
5275 [ALC889_FIXUP_COEF] = { 1925 [ALC889_FIXUP_COEF] = {
5276 .type = ALC_FIXUP_FUNC, 1926 .type = HDA_FIXUP_FUNC,
5277 .v.func = alc889_fixup_coef, 1927 .v.func = alc889_fixup_coef,
5278 }, 1928 },
5279 [ALC882_FIXUP_ACER_ASPIRE_4930G] = { 1929 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5280 .type = ALC_FIXUP_PINS, 1930 .type = HDA_FIXUP_PINS,
5281 .v.pins = (const struct alc_pincfg[]) { 1931 .v.pins = (const struct hda_pintbl[]) {
5282 { 0x16, 0x99130111 }, /* CLFE speaker */ 1932 { 0x16, 0x99130111 }, /* CLFE speaker */
5283 { 0x17, 0x99130112 }, /* surround speaker */ 1933 { 0x17, 0x99130112 }, /* surround speaker */
5284 { } 1934 { }
@@ -5287,8 +1937,8 @@ static const struct alc_fixup alc882_fixups[] = {
5287 .chain_id = ALC882_FIXUP_GPIO1, 1937 .chain_id = ALC882_FIXUP_GPIO1,
5288 }, 1938 },
5289 [ALC882_FIXUP_ACER_ASPIRE_8930G] = { 1939 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5290 .type = ALC_FIXUP_PINS, 1940 .type = HDA_FIXUP_PINS,
5291 .v.pins = (const struct alc_pincfg[]) { 1941 .v.pins = (const struct hda_pintbl[]) {
5292 { 0x16, 0x99130111 }, /* CLFE speaker */ 1942 { 0x16, 0x99130111 }, /* CLFE speaker */
5293 { 0x1b, 0x99130112 }, /* surround speaker */ 1943 { 0x1b, 0x99130112 }, /* surround speaker */
5294 { } 1944 { }
@@ -5298,7 +1948,7 @@ static const struct alc_fixup alc882_fixups[] = {
5298 }, 1948 },
5299 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = { 1949 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5300 /* additional init verbs for Acer Aspire 8930G */ 1950 /* additional init verbs for Acer Aspire 8930G */
5301 .type = ALC_FIXUP_VERBS, 1951 .type = HDA_FIXUP_VERBS,
5302 .v.verbs = (const struct hda_verb[]) { 1952 .v.verbs = (const struct hda_verb[]) {
5303 /* Enable all DACs */ 1953 /* Enable all DACs */
5304 /* DAC DISABLE/MUTE 1? */ 1954 /* DAC DISABLE/MUTE 1? */
@@ -5332,31 +1982,31 @@ static const struct alc_fixup alc882_fixups[] = {
5332 .chain_id = ALC882_FIXUP_GPIO1, 1982 .chain_id = ALC882_FIXUP_GPIO1,
5333 }, 1983 },
5334 [ALC885_FIXUP_MACPRO_GPIO] = { 1984 [ALC885_FIXUP_MACPRO_GPIO] = {
5335 .type = ALC_FIXUP_FUNC, 1985 .type = HDA_FIXUP_FUNC,
5336 .v.func = alc885_fixup_macpro_gpio, 1986 .v.func = alc885_fixup_macpro_gpio,
5337 }, 1987 },
5338 [ALC889_FIXUP_DAC_ROUTE] = { 1988 [ALC889_FIXUP_DAC_ROUTE] = {
5339 .type = ALC_FIXUP_FUNC, 1989 .type = HDA_FIXUP_FUNC,
5340 .v.func = alc889_fixup_dac_route, 1990 .v.func = alc889_fixup_dac_route,
5341 }, 1991 },
5342 [ALC889_FIXUP_MBP_VREF] = { 1992 [ALC889_FIXUP_MBP_VREF] = {
5343 .type = ALC_FIXUP_FUNC, 1993 .type = HDA_FIXUP_FUNC,
5344 .v.func = alc889_fixup_mbp_vref, 1994 .v.func = alc889_fixup_mbp_vref,
5345 .chained = true, 1995 .chained = true,
5346 .chain_id = ALC882_FIXUP_GPIO1, 1996 .chain_id = ALC882_FIXUP_GPIO1,
5347 }, 1997 },
5348 [ALC889_FIXUP_IMAC91_VREF] = { 1998 [ALC889_FIXUP_IMAC91_VREF] = {
5349 .type = ALC_FIXUP_FUNC, 1999 .type = HDA_FIXUP_FUNC,
5350 .v.func = alc889_fixup_imac91_vref, 2000 .v.func = alc889_fixup_imac91_vref,
5351 .chained = true, 2001 .chained = true,
5352 .chain_id = ALC882_FIXUP_GPIO1, 2002 .chain_id = ALC882_FIXUP_GPIO1,
5353 }, 2003 },
5354 [ALC882_FIXUP_INV_DMIC] = { 2004 [ALC882_FIXUP_INV_DMIC] = {
5355 .type = ALC_FIXUP_FUNC, 2005 .type = HDA_FIXUP_FUNC,
5356 .v.func = alc_fixup_inv_dmic_0x12, 2006 .v.func = alc_fixup_inv_dmic_0x12,
5357 }, 2007 },
5358 [ALC882_FIXUP_NO_PRIMARY_HP] = { 2008 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5359 .type = ALC_FIXUP_FUNC, 2009 .type = HDA_FIXUP_FUNC,
5360 .v.func = alc882_fixup_no_primary_hp, 2010 .v.func = alc882_fixup_no_primary_hp,
5361 }, 2011 },
5362}; 2012};
@@ -5394,6 +2044,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5394 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601), 2044 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
5395 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT), 2045 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
5396 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP), 2046 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
2047 SND_PCI_QUIRK(0x104d, 0x9043, "Sony Vaio VGC-LN51JGB", ALC882_FIXUP_NO_PRIMARY_HP),
5397 2048
5398 /* All Apple entries are in codec SSIDs */ 2049 /* All Apple entries are in codec SSIDs */
5399 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF), 2050 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
@@ -5431,7 +2082,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
5431 {} 2082 {}
5432}; 2083};
5433 2084
5434static const struct alc_model_fixup alc882_fixup_models[] = { 2085static const struct hda_model_fixup alc882_fixup_models[] = {
5435 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"}, 2086 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5436 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"}, 2087 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5437 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"}, 2088 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
@@ -5474,9 +2125,9 @@ static int patch_alc882(struct hda_codec *codec)
5474 break; 2125 break;
5475 } 2126 }
5476 2127
5477 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl, 2128 snd_hda_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5478 alc882_fixups); 2129 alc882_fixups);
5479 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 2130 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5480 2131
5481 alc_auto_parse_customize_define(codec); 2132 alc_auto_parse_customize_define(codec);
5482 2133
@@ -5485,7 +2136,7 @@ static int patch_alc882(struct hda_codec *codec)
5485 if (err < 0) 2136 if (err < 0)
5486 goto error; 2137 goto error;
5487 2138
5488 if (!spec->no_analog && has_cdefine_beep(codec)) { 2139 if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
5489 err = snd_hda_attach_beep_device(codec, 0x1); 2140 err = snd_hda_attach_beep_device(codec, 0x1);
5490 if (err < 0) 2141 if (err < 0)
5491 goto error; 2142 goto error;
@@ -5494,7 +2145,7 @@ static int patch_alc882(struct hda_codec *codec)
5494 2145
5495 codec->patch_ops = alc_patch_ops; 2146 codec->patch_ops = alc_patch_ops;
5496 2147
5497 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 2148 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5498 2149
5499 return 0; 2150 return 0;
5500 2151
@@ -5519,6 +2170,7 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
5519 */ 2170 */
5520enum { 2171enum {
5521 ALC262_FIXUP_FSC_H270, 2172 ALC262_FIXUP_FSC_H270,
2173 ALC262_FIXUP_FSC_S7110,
5522 ALC262_FIXUP_HP_Z200, 2174 ALC262_FIXUP_HP_Z200,
5523 ALC262_FIXUP_TYAN, 2175 ALC262_FIXUP_TYAN,
5524 ALC262_FIXUP_LENOVO_3000, 2176 ALC262_FIXUP_LENOVO_3000,
@@ -5527,41 +2179,50 @@ enum {
5527 ALC262_FIXUP_INV_DMIC, 2179 ALC262_FIXUP_INV_DMIC,
5528}; 2180};
5529 2181
5530static const struct alc_fixup alc262_fixups[] = { 2182static const struct hda_fixup alc262_fixups[] = {
5531 [ALC262_FIXUP_FSC_H270] = { 2183 [ALC262_FIXUP_FSC_H270] = {
5532 .type = ALC_FIXUP_PINS, 2184 .type = HDA_FIXUP_PINS,
5533 .v.pins = (const struct alc_pincfg[]) { 2185 .v.pins = (const struct hda_pintbl[]) {
5534 { 0x14, 0x99130110 }, /* speaker */ 2186 { 0x14, 0x99130110 }, /* speaker */
5535 { 0x15, 0x0221142f }, /* front HP */ 2187 { 0x15, 0x0221142f }, /* front HP */
5536 { 0x1b, 0x0121141f }, /* rear HP */ 2188 { 0x1b, 0x0121141f }, /* rear HP */
5537 { } 2189 { }
5538 } 2190 }
5539 }, 2191 },
2192 [ALC262_FIXUP_FSC_S7110] = {
2193 .type = HDA_FIXUP_PINS,
2194 .v.pins = (const struct hda_pintbl[]) {
2195 { 0x15, 0x90170110 }, /* speaker */
2196 { }
2197 },
2198 .chained = true,
2199 .chain_id = ALC262_FIXUP_BENQ,
2200 },
5540 [ALC262_FIXUP_HP_Z200] = { 2201 [ALC262_FIXUP_HP_Z200] = {
5541 .type = ALC_FIXUP_PINS, 2202 .type = HDA_FIXUP_PINS,
5542 .v.pins = (const struct alc_pincfg[]) { 2203 .v.pins = (const struct hda_pintbl[]) {
5543 { 0x16, 0x99130120 }, /* internal speaker */ 2204 { 0x16, 0x99130120 }, /* internal speaker */
5544 { } 2205 { }
5545 } 2206 }
5546 }, 2207 },
5547 [ALC262_FIXUP_TYAN] = { 2208 [ALC262_FIXUP_TYAN] = {
5548 .type = ALC_FIXUP_PINS, 2209 .type = HDA_FIXUP_PINS,
5549 .v.pins = (const struct alc_pincfg[]) { 2210 .v.pins = (const struct hda_pintbl[]) {
5550 { 0x14, 0x1993e1f0 }, /* int AUX */ 2211 { 0x14, 0x1993e1f0 }, /* int AUX */
5551 { } 2212 { }
5552 } 2213 }
5553 }, 2214 },
5554 [ALC262_FIXUP_LENOVO_3000] = { 2215 [ALC262_FIXUP_LENOVO_3000] = {
5555 .type = ALC_FIXUP_VERBS, 2216 .type = HDA_FIXUP_PINCTLS,
5556 .v.verbs = (const struct hda_verb[]) { 2217 .v.pins = (const struct hda_pintbl[]) {
5557 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 }, 2218 { 0x19, PIN_VREF50 },
5558 {} 2219 {}
5559 }, 2220 },
5560 .chained = true, 2221 .chained = true,
5561 .chain_id = ALC262_FIXUP_BENQ, 2222 .chain_id = ALC262_FIXUP_BENQ,
5562 }, 2223 },
5563 [ALC262_FIXUP_BENQ] = { 2224 [ALC262_FIXUP_BENQ] = {
5564 .type = ALC_FIXUP_VERBS, 2225 .type = HDA_FIXUP_VERBS,
5565 .v.verbs = (const struct hda_verb[]) { 2226 .v.verbs = (const struct hda_verb[]) {
5566 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 2227 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5567 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 }, 2228 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
@@ -5569,7 +2230,7 @@ static const struct alc_fixup alc262_fixups[] = {
5569 } 2230 }
5570 }, 2231 },
5571 [ALC262_FIXUP_BENQ_T31] = { 2232 [ALC262_FIXUP_BENQ_T31] = {
5572 .type = ALC_FIXUP_VERBS, 2233 .type = HDA_FIXUP_VERBS,
5573 .v.verbs = (const struct hda_verb[]) { 2234 .v.verbs = (const struct hda_verb[]) {
5574 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 }, 2235 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5575 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 }, 2236 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
@@ -5577,14 +2238,14 @@ static const struct alc_fixup alc262_fixups[] = {
5577 } 2238 }
5578 }, 2239 },
5579 [ALC262_FIXUP_INV_DMIC] = { 2240 [ALC262_FIXUP_INV_DMIC] = {
5580 .type = ALC_FIXUP_FUNC, 2241 .type = HDA_FIXUP_FUNC,
5581 .v.func = alc_fixup_inv_dmic_0x12, 2242 .v.func = alc_fixup_inv_dmic_0x12,
5582 }, 2243 },
5583}; 2244};
5584 2245
5585static const struct snd_pci_quirk alc262_fixup_tbl[] = { 2246static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5586 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200), 2247 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
5587 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ), 2248 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu Lifebook S7110", ALC262_FIXUP_FSC_S7110),
5588 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ), 2249 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
5589 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN), 2250 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5590 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270), 2251 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
@@ -5594,7 +2255,7 @@ static const struct snd_pci_quirk alc262_fixup_tbl[] = {
5594 {} 2255 {}
5595}; 2256};
5596 2257
5597static const struct alc_model_fixup alc262_fixup_models[] = { 2258static const struct hda_model_fixup alc262_fixup_models[] = {
5598 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"}, 2259 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5599 {} 2260 {}
5600}; 2261};
@@ -5611,6 +2272,7 @@ static int patch_alc262(struct hda_codec *codec)
5611 return err; 2272 return err;
5612 2273
5613 spec = codec->spec; 2274 spec = codec->spec;
2275 spec->gen.shared_mic_vref_pin = 0x18;
5614 2276
5615#if 0 2277#if 0
5616 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is 2278 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
@@ -5626,9 +2288,9 @@ static int patch_alc262(struct hda_codec *codec)
5626#endif 2288#endif
5627 alc_fix_pll_init(codec, 0x20, 0x0a, 10); 2289 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5628 2290
5629 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl, 2291 snd_hda_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5630 alc262_fixups); 2292 alc262_fixups);
5631 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 2293 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5632 2294
5633 alc_auto_parse_customize_define(codec); 2295 alc_auto_parse_customize_define(codec);
5634 2296
@@ -5637,7 +2299,7 @@ static int patch_alc262(struct hda_codec *codec)
5637 if (err < 0) 2299 if (err < 0)
5638 goto error; 2300 goto error;
5639 2301
5640 if (!spec->no_analog && has_cdefine_beep(codec)) { 2302 if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
5641 err = snd_hda_attach_beep_device(codec, 0x1); 2303 err = snd_hda_attach_beep_device(codec, 0x1);
5642 if (err < 0) 2304 if (err < 0)
5643 goto error; 2305 goto error;
@@ -5647,7 +2309,7 @@ static int patch_alc262(struct hda_codec *codec)
5647 codec->patch_ops = alc_patch_ops; 2309 codec->patch_ops = alc_patch_ops;
5648 spec->shutup = alc_eapd_shutup; 2310 spec->shutup = alc_eapd_shutup;
5649 2311
5650 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 2312 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5651 2313
5652 return 0; 2314 return 0;
5653 2315
@@ -5688,13 +2350,13 @@ enum {
5688 ALC268_FIXUP_HP_EAPD, 2350 ALC268_FIXUP_HP_EAPD,
5689}; 2351};
5690 2352
5691static const struct alc_fixup alc268_fixups[] = { 2353static const struct hda_fixup alc268_fixups[] = {
5692 [ALC268_FIXUP_INV_DMIC] = { 2354 [ALC268_FIXUP_INV_DMIC] = {
5693 .type = ALC_FIXUP_FUNC, 2355 .type = HDA_FIXUP_FUNC,
5694 .v.func = alc_fixup_inv_dmic_0x12, 2356 .v.func = alc_fixup_inv_dmic_0x12,
5695 }, 2357 },
5696 [ALC268_FIXUP_HP_EAPD] = { 2358 [ALC268_FIXUP_HP_EAPD] = {
5697 .type = ALC_FIXUP_VERBS, 2359 .type = HDA_FIXUP_VERBS,
5698 .v.verbs = (const struct hda_verb[]) { 2360 .v.verbs = (const struct hda_verb[]) {
5699 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0}, 2361 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5700 {} 2362 {}
@@ -5702,7 +2364,7 @@ static const struct alc_fixup alc268_fixups[] = {
5702 }, 2364 },
5703}; 2365};
5704 2366
5705static const struct alc_model_fixup alc268_fixup_models[] = { 2367static const struct hda_model_fixup alc268_fixup_models[] = {
5706 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"}, 2368 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5707 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"}, 2369 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5708 {} 2370 {}
@@ -5726,9 +2388,10 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
5726 struct alc_spec *spec = codec->spec; 2388 struct alc_spec *spec = codec->spec;
5727 int err = alc_parse_auto_config(codec, NULL, alc268_ssids); 2389 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5728 if (err > 0) { 2390 if (err > 0) {
5729 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) { 2391 if (!spec->gen.no_analog &&
2392 spec->gen.autocfg.speaker_pins[0] != 0x1d) {
5730 add_mixer(spec, alc268_beep_mixer); 2393 add_mixer(spec, alc268_beep_mixer);
5731 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs); 2394 snd_hda_add_verbs(codec, alc268_beep_init_verbs);
5732 } 2395 }
5733 } 2396 }
5734 return err; 2397 return err;
@@ -5748,8 +2411,8 @@ static int patch_alc268(struct hda_codec *codec)
5748 2411
5749 spec = codec->spec; 2412 spec = codec->spec;
5750 2413
5751 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups); 2414 snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
5752 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 2415 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5753 2416
5754 /* automatic parse from the BIOS config */ 2417 /* automatic parse from the BIOS config */
5755 err = alc268_parse_auto_config(codec); 2418 err = alc268_parse_auto_config(codec);
@@ -5780,7 +2443,7 @@ static int patch_alc268(struct hda_codec *codec)
5780 codec->patch_ops = alc_patch_ops; 2443 codec->patch_ops = alc_patch_ops;
5781 spec->shutup = alc_eapd_shutup; 2444 spec->shutup = alc_eapd_shutup;
5782 2445
5783 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 2446 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5784 2447
5785 return 0; 2448 return 0;
5786 2449
@@ -5792,6 +2455,35 @@ static int patch_alc268(struct hda_codec *codec)
5792/* 2455/*
5793 * ALC269 2456 * ALC269
5794 */ 2457 */
2458
2459static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2460 struct hda_codec *codec,
2461 struct snd_pcm_substream *substream)
2462{
2463 struct hda_gen_spec *spec = codec->spec;
2464 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2465 hinfo);
2466}
2467
2468static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2469 struct hda_codec *codec,
2470 unsigned int stream_tag,
2471 unsigned int format,
2472 struct snd_pcm_substream *substream)
2473{
2474 struct hda_gen_spec *spec = codec->spec;
2475 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2476 stream_tag, format, substream);
2477}
2478
2479static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2480 struct hda_codec *codec,
2481 struct snd_pcm_substream *substream)
2482{
2483 struct hda_gen_spec *spec = codec->spec;
2484 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2485}
2486
5795static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { 2487static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5796 .substreams = 1, 2488 .substreams = 1,
5797 .channels_min = 2, 2489 .channels_min = 2,
@@ -5799,9 +2491,9 @@ static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5799 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ 2491 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5800 /* NID is set in alc_build_pcms */ 2492 /* NID is set in alc_build_pcms */
5801 .ops = { 2493 .ops = {
5802 .open = alc_playback_pcm_open, 2494 .open = playback_pcm_open,
5803 .prepare = alc_playback_pcm_prepare, 2495 .prepare = playback_pcm_prepare,
5804 .cleanup = alc_playback_pcm_cleanup 2496 .cleanup = playback_pcm_cleanup
5805 }, 2497 },
5806}; 2498};
5807 2499
@@ -5909,27 +2601,27 @@ static int alc269_resume(struct hda_codec *codec)
5909#endif /* CONFIG_PM */ 2601#endif /* CONFIG_PM */
5910 2602
5911static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec, 2603static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
5912 const struct alc_fixup *fix, int action) 2604 const struct hda_fixup *fix, int action)
5913{ 2605{
5914 struct alc_spec *spec = codec->spec; 2606 struct alc_spec *spec = codec->spec;
5915 2607
5916 if (action == ALC_FIXUP_ACT_PRE_PROBE) 2608 if (action == HDA_FIXUP_ACT_PRE_PROBE)
5917 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; 2609 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5918} 2610}
5919 2611
5920static void alc269_fixup_hweq(struct hda_codec *codec, 2612static void alc269_fixup_hweq(struct hda_codec *codec,
5921 const struct alc_fixup *fix, int action) 2613 const struct hda_fixup *fix, int action)
5922{ 2614{
5923 int coef; 2615 int coef;
5924 2616
5925 if (action != ALC_FIXUP_ACT_INIT) 2617 if (action != HDA_FIXUP_ACT_INIT)
5926 return; 2618 return;
5927 coef = alc_read_coef_idx(codec, 0x1e); 2619 coef = alc_read_coef_idx(codec, 0x1e);
5928 alc_write_coef_idx(codec, 0x1e, coef | 0x80); 2620 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5929} 2621}
5930 2622
5931static void alc271_fixup_dmic(struct hda_codec *codec, 2623static void alc271_fixup_dmic(struct hda_codec *codec,
5932 const struct alc_fixup *fix, int action) 2624 const struct hda_fixup *fix, int action)
5933{ 2625{
5934 static const struct hda_verb verbs[] = { 2626 static const struct hda_verb verbs[] = {
5935 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d}, 2627 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
@@ -5946,26 +2638,26 @@ static void alc271_fixup_dmic(struct hda_codec *codec,
5946} 2638}
5947 2639
5948static void alc269_fixup_pcm_44k(struct hda_codec *codec, 2640static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5949 const struct alc_fixup *fix, int action) 2641 const struct hda_fixup *fix, int action)
5950{ 2642{
5951 struct alc_spec *spec = codec->spec; 2643 struct alc_spec *spec = codec->spec;
5952 2644
5953 if (action != ALC_FIXUP_ACT_PROBE) 2645 if (action != HDA_FIXUP_ACT_PROBE)
5954 return; 2646 return;
5955 2647
5956 /* Due to a hardware problem on Lenovo Ideadpad, we need to 2648 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5957 * fix the sample rate of analog I/O to 44.1kHz 2649 * fix the sample rate of analog I/O to 44.1kHz
5958 */ 2650 */
5959 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback; 2651 spec->gen.stream_analog_playback = &alc269_44k_pcm_analog_playback;
5960 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; 2652 spec->gen.stream_analog_capture = &alc269_44k_pcm_analog_capture;
5961} 2653}
5962 2654
5963static void alc269_fixup_stereo_dmic(struct hda_codec *codec, 2655static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5964 const struct alc_fixup *fix, int action) 2656 const struct hda_fixup *fix, int action)
5965{ 2657{
5966 int coef; 2658 int coef;
5967 2659
5968 if (action != ALC_FIXUP_ACT_INIT) 2660 if (action != HDA_FIXUP_ACT_INIT)
5969 return; 2661 return;
5970 /* The digital-mic unit sends PDM (differential signal) instead of 2662 /* The digital-mic unit sends PDM (differential signal) instead of
5971 * the standard PCM, thus you can't record a valid mono stream as is. 2663 * the standard PCM, thus you can't record a valid mono stream as is.
@@ -5978,7 +2670,7 @@ static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5978 2670
5979static void alc269_quanta_automute(struct hda_codec *codec) 2671static void alc269_quanta_automute(struct hda_codec *codec)
5980{ 2672{
5981 update_outputs(codec); 2673 snd_hda_gen_update_outputs(codec);
5982 2674
5983 snd_hda_codec_write(codec, 0x20, 0, 2675 snd_hda_codec_write(codec, 0x20, 0,
5984 AC_VERB_SET_COEF_INDEX, 0x0c); 2676 AC_VERB_SET_COEF_INDEX, 0x0c);
@@ -5992,70 +2684,91 @@ static void alc269_quanta_automute(struct hda_codec *codec)
5992} 2684}
5993 2685
5994static void alc269_fixup_quanta_mute(struct hda_codec *codec, 2686static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5995 const struct alc_fixup *fix, int action) 2687 const struct hda_fixup *fix, int action)
5996{ 2688{
5997 struct alc_spec *spec = codec->spec; 2689 struct alc_spec *spec = codec->spec;
5998 if (action != ALC_FIXUP_ACT_PROBE) 2690 if (action != HDA_FIXUP_ACT_PROBE)
5999 return; 2691 return;
6000 spec->automute_hook = alc269_quanta_automute; 2692 spec->gen.automute_hook = alc269_quanta_automute;
6001} 2693}
6002 2694
6003/* update mute-LED according to the speaker mute state via mic1 VREF pin */ 2695/* update mute-LED according to the speaker mute state via mic VREF pin */
6004static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled) 2696static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
6005{ 2697{
6006 struct hda_codec *codec = private_data; 2698 struct hda_codec *codec = private_data;
6007 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ? 2699 struct alc_spec *spec = codec->spec;
6008 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80); 2700 unsigned int pinval;
6009 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval); 2701
2702 if (spec->mute_led_polarity)
2703 enabled = !enabled;
2704 pinval = AC_PINCTL_IN_EN |
2705 (enabled ? AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
2706 if (spec->mute_led_nid)
2707 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
6010} 2708}
6011 2709
6012static void alc269_fixup_mic1_mute(struct hda_codec *codec, 2710static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
6013 const struct alc_fixup *fix, int action) 2711 const struct hda_fixup *fix, int action)
6014{ 2712{
6015 struct alc_spec *spec = codec->spec; 2713 struct alc_spec *spec = codec->spec;
6016 switch (action) { 2714 const struct dmi_device *dev = NULL;
6017 case ALC_FIXUP_ACT_BUILD: 2715
6018 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook; 2716 if (action != HDA_FIXUP_ACT_PRE_PROBE)
6019 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true); 2717 return;
6020 /* fallthru */ 2718
6021 case ALC_FIXUP_ACT_INIT: 2719 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
6022 snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 2720 int pol, pin;
2721 if (sscanf(dev->name, "HP_Mute_LED_%d_%x", &pol, &pin) != 2)
2722 continue;
2723 if (pin < 0x0a || pin >= 0x10)
2724 break;
2725 spec->mute_led_polarity = pol;
2726 spec->mute_led_nid = pin - 0x0a + 0x18;
2727 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2728 spec->gen.vmaster_mute_enum = 1;
2729 snd_printd("Detected mute LED for %x:%d\n", spec->mute_led_nid,
2730 spec->mute_led_polarity);
6023 break; 2731 break;
6024 } 2732 }
6025} 2733}
6026 2734
6027/* update mute-LED according to the speaker mute state via mic2 VREF pin */ 2735static void alc269_fixup_hp_mute_led_mic1(struct hda_codec *codec,
6028static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled) 2736 const struct hda_fixup *fix, int action)
6029{ 2737{
6030 struct hda_codec *codec = private_data; 2738 struct alc_spec *spec = codec->spec;
6031 unsigned int pinval = enabled ? 0x20 : 0x24; 2739 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
6032 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval); 2740 spec->mute_led_polarity = 0;
2741 spec->mute_led_nid = 0x18;
2742 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2743 spec->gen.vmaster_mute_enum = 1;
2744 }
6033} 2745}
6034 2746
6035static void alc269_fixup_mic2_mute(struct hda_codec *codec, 2747static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
6036 const struct alc_fixup *fix, int action) 2748 const struct hda_fixup *fix, int action)
6037{ 2749{
6038 struct alc_spec *spec = codec->spec; 2750 struct alc_spec *spec = codec->spec;
6039 switch (action) { 2751 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
6040 case ALC_FIXUP_ACT_BUILD: 2752 spec->mute_led_polarity = 0;
6041 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook; 2753 spec->mute_led_nid = 0x19;
6042 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true); 2754 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
6043 /* fallthru */ 2755 spec->gen.vmaster_mute_enum = 1;
6044 case ALC_FIXUP_ACT_INIT:
6045 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6046 break;
6047 } 2756 }
6048} 2757}
6049 2758
6050static void alc271_hp_gate_mic_jack(struct hda_codec *codec, 2759static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6051 const struct alc_fixup *fix, 2760 const struct hda_fixup *fix,
6052 int action) 2761 int action)
6053{ 2762{
6054 struct alc_spec *spec = codec->spec; 2763 struct alc_spec *spec = codec->spec;
6055 2764
6056 if (action == ALC_FIXUP_ACT_PROBE) 2765 if (action == HDA_FIXUP_ACT_PROBE) {
6057 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin, 2766 if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
6058 spec->autocfg.hp_pins[0]); 2767 !spec->gen.autocfg.hp_pins[0]))
2768 return;
2769 snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin,
2770 spec->gen.autocfg.hp_pins[0]);
2771 }
6059} 2772}
6060 2773
6061enum { 2774enum {
@@ -6075,8 +2788,9 @@ enum {
6075 ALC269_FIXUP_DMIC, 2788 ALC269_FIXUP_DMIC,
6076 ALC269VB_FIXUP_AMIC, 2789 ALC269VB_FIXUP_AMIC,
6077 ALC269VB_FIXUP_DMIC, 2790 ALC269VB_FIXUP_DMIC,
6078 ALC269_FIXUP_MIC1_MUTE_LED, 2791 ALC269_FIXUP_HP_MUTE_LED,
6079 ALC269_FIXUP_MIC2_MUTE_LED, 2792 ALC269_FIXUP_HP_MUTE_LED_MIC1,
2793 ALC269_FIXUP_HP_MUTE_LED_MIC2,
6080 ALC269_FIXUP_INV_DMIC, 2794 ALC269_FIXUP_INV_DMIC,
6081 ALC269_FIXUP_LENOVO_DOCK, 2795 ALC269_FIXUP_LENOVO_DOCK,
6082 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, 2796 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
@@ -6084,16 +2798,16 @@ enum {
6084 ALC271_FIXUP_HP_GATE_MIC_JACK, 2798 ALC271_FIXUP_HP_GATE_MIC_JACK,
6085}; 2799};
6086 2800
6087static const struct alc_fixup alc269_fixups[] = { 2801static const struct hda_fixup alc269_fixups[] = {
6088 [ALC269_FIXUP_SONY_VAIO] = { 2802 [ALC269_FIXUP_SONY_VAIO] = {
6089 .type = ALC_FIXUP_VERBS, 2803 .type = HDA_FIXUP_PINCTLS,
6090 .v.verbs = (const struct hda_verb[]) { 2804 .v.pins = (const struct hda_pintbl[]) {
6091 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD}, 2805 {0x19, PIN_VREFGRD},
6092 {} 2806 {}
6093 } 2807 }
6094 }, 2808 },
6095 [ALC275_FIXUP_SONY_VAIO_GPIO2] = { 2809 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6096 .type = ALC_FIXUP_VERBS, 2810 .type = HDA_FIXUP_VERBS,
6097 .v.verbs = (const struct hda_verb[]) { 2811 .v.verbs = (const struct hda_verb[]) {
6098 {0x01, AC_VERB_SET_GPIO_MASK, 0x04}, 2812 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6099 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04}, 2813 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
@@ -6104,7 +2818,7 @@ static const struct alc_fixup alc269_fixups[] = {
6104 .chain_id = ALC269_FIXUP_SONY_VAIO 2818 .chain_id = ALC269_FIXUP_SONY_VAIO
6105 }, 2819 },
6106 [ALC269_FIXUP_DELL_M101Z] = { 2820 [ALC269_FIXUP_DELL_M101Z] = {
6107 .type = ALC_FIXUP_VERBS, 2821 .type = HDA_FIXUP_VERBS,
6108 .v.verbs = (const struct hda_verb[]) { 2822 .v.verbs = (const struct hda_verb[]) {
6109 /* Enables internal speaker */ 2823 /* Enables internal speaker */
6110 {0x20, AC_VERB_SET_COEF_INDEX, 13}, 2824 {0x20, AC_VERB_SET_COEF_INDEX, 13},
@@ -6113,50 +2827,50 @@ static const struct alc_fixup alc269_fixups[] = {
6113 } 2827 }
6114 }, 2828 },
6115 [ALC269_FIXUP_SKU_IGNORE] = { 2829 [ALC269_FIXUP_SKU_IGNORE] = {
6116 .type = ALC_FIXUP_FUNC, 2830 .type = HDA_FIXUP_FUNC,
6117 .v.func = alc_fixup_sku_ignore, 2831 .v.func = alc_fixup_sku_ignore,
6118 }, 2832 },
6119 [ALC269_FIXUP_ASUS_G73JW] = { 2833 [ALC269_FIXUP_ASUS_G73JW] = {
6120 .type = ALC_FIXUP_PINS, 2834 .type = HDA_FIXUP_PINS,
6121 .v.pins = (const struct alc_pincfg[]) { 2835 .v.pins = (const struct hda_pintbl[]) {
6122 { 0x17, 0x99130111 }, /* subwoofer */ 2836 { 0x17, 0x99130111 }, /* subwoofer */
6123 { } 2837 { }
6124 } 2838 }
6125 }, 2839 },
6126 [ALC269_FIXUP_LENOVO_EAPD] = { 2840 [ALC269_FIXUP_LENOVO_EAPD] = {
6127 .type = ALC_FIXUP_VERBS, 2841 .type = HDA_FIXUP_VERBS,
6128 .v.verbs = (const struct hda_verb[]) { 2842 .v.verbs = (const struct hda_verb[]) {
6129 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, 2843 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6130 {} 2844 {}
6131 } 2845 }
6132 }, 2846 },
6133 [ALC275_FIXUP_SONY_HWEQ] = { 2847 [ALC275_FIXUP_SONY_HWEQ] = {
6134 .type = ALC_FIXUP_FUNC, 2848 .type = HDA_FIXUP_FUNC,
6135 .v.func = alc269_fixup_hweq, 2849 .v.func = alc269_fixup_hweq,
6136 .chained = true, 2850 .chained = true,
6137 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2 2851 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6138 }, 2852 },
6139 [ALC271_FIXUP_DMIC] = { 2853 [ALC271_FIXUP_DMIC] = {
6140 .type = ALC_FIXUP_FUNC, 2854 .type = HDA_FIXUP_FUNC,
6141 .v.func = alc271_fixup_dmic, 2855 .v.func = alc271_fixup_dmic,
6142 }, 2856 },
6143 [ALC269_FIXUP_PCM_44K] = { 2857 [ALC269_FIXUP_PCM_44K] = {
6144 .type = ALC_FIXUP_FUNC, 2858 .type = HDA_FIXUP_FUNC,
6145 .v.func = alc269_fixup_pcm_44k, 2859 .v.func = alc269_fixup_pcm_44k,
6146 .chained = true, 2860 .chained = true,
6147 .chain_id = ALC269_FIXUP_QUANTA_MUTE 2861 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6148 }, 2862 },
6149 [ALC269_FIXUP_STEREO_DMIC] = { 2863 [ALC269_FIXUP_STEREO_DMIC] = {
6150 .type = ALC_FIXUP_FUNC, 2864 .type = HDA_FIXUP_FUNC,
6151 .v.func = alc269_fixup_stereo_dmic, 2865 .v.func = alc269_fixup_stereo_dmic,
6152 }, 2866 },
6153 [ALC269_FIXUP_QUANTA_MUTE] = { 2867 [ALC269_FIXUP_QUANTA_MUTE] = {
6154 .type = ALC_FIXUP_FUNC, 2868 .type = HDA_FIXUP_FUNC,
6155 .v.func = alc269_fixup_quanta_mute, 2869 .v.func = alc269_fixup_quanta_mute,
6156 }, 2870 },
6157 [ALC269_FIXUP_LIFEBOOK] = { 2871 [ALC269_FIXUP_LIFEBOOK] = {
6158 .type = ALC_FIXUP_PINS, 2872 .type = HDA_FIXUP_PINS,
6159 .v.pins = (const struct alc_pincfg[]) { 2873 .v.pins = (const struct hda_pintbl[]) {
6160 { 0x1a, 0x2101103f }, /* dock line-out */ 2874 { 0x1a, 0x2101103f }, /* dock line-out */
6161 { 0x1b, 0x23a11040 }, /* dock mic-in */ 2875 { 0x1b, 0x23a11040 }, /* dock mic-in */
6162 { } 2876 { }
@@ -6165,8 +2879,8 @@ static const struct alc_fixup alc269_fixups[] = {
6165 .chain_id = ALC269_FIXUP_QUANTA_MUTE 2879 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6166 }, 2880 },
6167 [ALC269_FIXUP_AMIC] = { 2881 [ALC269_FIXUP_AMIC] = {
6168 .type = ALC_FIXUP_PINS, 2882 .type = HDA_FIXUP_PINS,
6169 .v.pins = (const struct alc_pincfg[]) { 2883 .v.pins = (const struct hda_pintbl[]) {
6170 { 0x14, 0x99130110 }, /* speaker */ 2884 { 0x14, 0x99130110 }, /* speaker */
6171 { 0x15, 0x0121401f }, /* HP out */ 2885 { 0x15, 0x0121401f }, /* HP out */
6172 { 0x18, 0x01a19c20 }, /* mic */ 2886 { 0x18, 0x01a19c20 }, /* mic */
@@ -6175,8 +2889,8 @@ static const struct alc_fixup alc269_fixups[] = {
6175 }, 2889 },
6176 }, 2890 },
6177 [ALC269_FIXUP_DMIC] = { 2891 [ALC269_FIXUP_DMIC] = {
6178 .type = ALC_FIXUP_PINS, 2892 .type = HDA_FIXUP_PINS,
6179 .v.pins = (const struct alc_pincfg[]) { 2893 .v.pins = (const struct hda_pintbl[]) {
6180 { 0x12, 0x99a3092f }, /* int-mic */ 2894 { 0x12, 0x99a3092f }, /* int-mic */
6181 { 0x14, 0x99130110 }, /* speaker */ 2895 { 0x14, 0x99130110 }, /* speaker */
6182 { 0x15, 0x0121401f }, /* HP out */ 2896 { 0x15, 0x0121401f }, /* HP out */
@@ -6185,8 +2899,8 @@ static const struct alc_fixup alc269_fixups[] = {
6185 }, 2899 },
6186 }, 2900 },
6187 [ALC269VB_FIXUP_AMIC] = { 2901 [ALC269VB_FIXUP_AMIC] = {
6188 .type = ALC_FIXUP_PINS, 2902 .type = HDA_FIXUP_PINS,
6189 .v.pins = (const struct alc_pincfg[]) { 2903 .v.pins = (const struct hda_pintbl[]) {
6190 { 0x14, 0x99130110 }, /* speaker */ 2904 { 0x14, 0x99130110 }, /* speaker */
6191 { 0x18, 0x01a19c20 }, /* mic */ 2905 { 0x18, 0x01a19c20 }, /* mic */
6192 { 0x19, 0x99a3092f }, /* int-mic */ 2906 { 0x19, 0x99a3092f }, /* int-mic */
@@ -6195,8 +2909,8 @@ static const struct alc_fixup alc269_fixups[] = {
6195 }, 2909 },
6196 }, 2910 },
6197 [ALC269VB_FIXUP_DMIC] = { 2911 [ALC269VB_FIXUP_DMIC] = {
6198 .type = ALC_FIXUP_PINS, 2912 .type = HDA_FIXUP_PINS,
6199 .v.pins = (const struct alc_pincfg[]) { 2913 .v.pins = (const struct hda_pintbl[]) {
6200 { 0x12, 0x99a3092f }, /* int-mic */ 2914 { 0x12, 0x99a3092f }, /* int-mic */
6201 { 0x14, 0x99130110 }, /* speaker */ 2915 { 0x14, 0x99130110 }, /* speaker */
6202 { 0x18, 0x01a19c20 }, /* mic */ 2916 { 0x18, 0x01a19c20 }, /* mic */
@@ -6204,21 +2918,25 @@ static const struct alc_fixup alc269_fixups[] = {
6204 { } 2918 { }
6205 }, 2919 },
6206 }, 2920 },
6207 [ALC269_FIXUP_MIC1_MUTE_LED] = { 2921 [ALC269_FIXUP_HP_MUTE_LED] = {
6208 .type = ALC_FIXUP_FUNC, 2922 .type = HDA_FIXUP_FUNC,
6209 .v.func = alc269_fixup_mic1_mute, 2923 .v.func = alc269_fixup_hp_mute_led,
6210 }, 2924 },
6211 [ALC269_FIXUP_MIC2_MUTE_LED] = { 2925 [ALC269_FIXUP_HP_MUTE_LED_MIC1] = {
6212 .type = ALC_FIXUP_FUNC, 2926 .type = HDA_FIXUP_FUNC,
6213 .v.func = alc269_fixup_mic2_mute, 2927 .v.func = alc269_fixup_hp_mute_led_mic1,
2928 },
2929 [ALC269_FIXUP_HP_MUTE_LED_MIC2] = {
2930 .type = HDA_FIXUP_FUNC,
2931 .v.func = alc269_fixup_hp_mute_led_mic2,
6214 }, 2932 },
6215 [ALC269_FIXUP_INV_DMIC] = { 2933 [ALC269_FIXUP_INV_DMIC] = {
6216 .type = ALC_FIXUP_FUNC, 2934 .type = HDA_FIXUP_FUNC,
6217 .v.func = alc_fixup_inv_dmic_0x12, 2935 .v.func = alc_fixup_inv_dmic_0x12,
6218 }, 2936 },
6219 [ALC269_FIXUP_LENOVO_DOCK] = { 2937 [ALC269_FIXUP_LENOVO_DOCK] = {
6220 .type = ALC_FIXUP_PINS, 2938 .type = HDA_FIXUP_PINS,
6221 .v.pins = (const struct alc_pincfg[]) { 2939 .v.pins = (const struct hda_pintbl[]) {
6222 { 0x19, 0x23a11040 }, /* dock mic */ 2940 { 0x19, 0x23a11040 }, /* dock mic */
6223 { 0x1b, 0x2121103f }, /* dock headphone */ 2941 { 0x1b, 0x2121103f }, /* dock headphone */
6224 { } 2942 { }
@@ -6227,12 +2945,12 @@ static const struct alc_fixup alc269_fixups[] = {
6227 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT 2945 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6228 }, 2946 },
6229 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = { 2947 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6230 .type = ALC_FIXUP_FUNC, 2948 .type = HDA_FIXUP_FUNC,
6231 .v.func = alc269_fixup_pincfg_no_hp_to_lineout, 2949 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6232 }, 2950 },
6233 [ALC271_FIXUP_AMIC_MIC2] = { 2951 [ALC271_FIXUP_AMIC_MIC2] = {
6234 .type = ALC_FIXUP_PINS, 2952 .type = HDA_FIXUP_PINS,
6235 .v.pins = (const struct alc_pincfg[]) { 2953 .v.pins = (const struct hda_pintbl[]) {
6236 { 0x14, 0x99130110 }, /* speaker */ 2954 { 0x14, 0x99130110 }, /* speaker */
6237 { 0x19, 0x01a19c20 }, /* mic */ 2955 { 0x19, 0x01a19c20 }, /* mic */
6238 { 0x1b, 0x99a7012f }, /* int-mic */ 2956 { 0x1b, 0x99a7012f }, /* int-mic */
@@ -6241,7 +2959,7 @@ static const struct alc_fixup alc269_fixups[] = {
6241 }, 2959 },
6242 }, 2960 },
6243 [ALC271_FIXUP_HP_GATE_MIC_JACK] = { 2961 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6244 .type = ALC_FIXUP_FUNC, 2962 .type = HDA_FIXUP_FUNC,
6245 .v.func = alc271_hp_gate_mic_jack, 2963 .v.func = alc271_hp_gate_mic_jack,
6246 .chained = true, 2964 .chained = true,
6247 .chain_id = ALC271_FIXUP_AMIC_MIC2, 2965 .chain_id = ALC271_FIXUP_AMIC_MIC2,
@@ -6251,9 +2969,10 @@ static const struct alc_fixup alc269_fixups[] = {
6251static const struct snd_pci_quirk alc269_fixup_tbl[] = { 2969static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6252 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC), 2970 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6253 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC), 2971 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
6254 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED), 2972 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
6255 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED), 2973 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
6256 SND_PCI_QUIRK(0x103c, 0x1977, "HP Pavilion 14", ALC269_FIXUP_MIC1_MUTE_LED), 2974 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
2975 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
6257 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC), 2976 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
6258 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC), 2977 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
6259 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), 2978 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
@@ -6336,7 +3055,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6336 {} 3055 {}
6337}; 3056};
6338 3057
6339static const struct alc_model_fixup alc269_fixup_models[] = { 3058static const struct hda_model_fixup alc269_fixup_models[] = {
6340 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"}, 3059 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6341 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"}, 3060 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
6342 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"}, 3061 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
@@ -6403,10 +3122,11 @@ static int patch_alc269(struct hda_codec *codec)
6403 return err; 3122 return err;
6404 3123
6405 spec = codec->spec; 3124 spec = codec->spec;
3125 spec->gen.shared_mic_vref_pin = 0x18;
6406 3126
6407 alc_pick_fixup(codec, alc269_fixup_models, 3127 snd_hda_pick_fixup(codec, alc269_fixup_models,
6408 alc269_fixup_tbl, alc269_fixups); 3128 alc269_fixup_tbl, alc269_fixups);
6409 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 3129 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6410 3130
6411 alc_auto_parse_customize_define(codec); 3131 alc_auto_parse_customize_define(codec);
6412 3132
@@ -6457,7 +3177,7 @@ static int patch_alc269(struct hda_codec *codec)
6457 if (err < 0) 3177 if (err < 0)
6458 goto error; 3178 goto error;
6459 3179
6460 if (!spec->no_analog && has_cdefine_beep(codec)) { 3180 if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
6461 err = snd_hda_attach_beep_device(codec, 0x1); 3181 err = snd_hda_attach_beep_device(codec, 0x1);
6462 if (err < 0) 3182 if (err < 0)
6463 goto error; 3183 goto error;
@@ -6470,7 +3190,7 @@ static int patch_alc269(struct hda_codec *codec)
6470#endif 3190#endif
6471 spec->shutup = alc269_shutup; 3191 spec->shutup = alc269_shutup;
6472 3192
6473 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 3193 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6474 3194
6475 return 0; 3195 return 0;
6476 3196
@@ -6500,49 +3220,48 @@ enum {
6500 3220
6501/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */ 3221/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6502static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec, 3222static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6503 const struct alc_fixup *fix, int action) 3223 const struct hda_fixup *fix, int action)
6504{ 3224{
6505 struct alc_spec *spec = codec->spec; 3225 struct alc_spec *spec = codec->spec;
6506 unsigned int val; 3226 unsigned int val;
6507 3227
6508 if (action != ALC_FIXUP_ACT_INIT) 3228 if (action != HDA_FIXUP_ACT_INIT)
6509 return; 3229 return;
6510 val = snd_hda_codec_read(codec, 0x0f, 0, 3230 val = snd_hda_codec_get_pin_target(codec, 0x0f);
6511 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6512 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))) 3231 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6513 val |= AC_PINCTL_IN_EN; 3232 val |= AC_PINCTL_IN_EN;
6514 val |= AC_PINCTL_VREF_50; 3233 val |= AC_PINCTL_VREF_50;
6515 snd_hda_set_pin_ctl(codec, 0x0f, val); 3234 snd_hda_set_pin_ctl(codec, 0x0f, val);
6516 spec->keep_vref_in_automute = 1; 3235 spec->gen.keep_vref_in_automute = 1;
6517} 3236}
6518 3237
6519/* suppress the jack-detection */ 3238/* suppress the jack-detection */
6520static void alc_fixup_no_jack_detect(struct hda_codec *codec, 3239static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6521 const struct alc_fixup *fix, int action) 3240 const struct hda_fixup *fix, int action)
6522{ 3241{
6523 if (action == ALC_FIXUP_ACT_PRE_PROBE) 3242 if (action == HDA_FIXUP_ACT_PRE_PROBE)
6524 codec->no_jack_detect = 1; 3243 codec->no_jack_detect = 1;
6525} 3244}
6526 3245
6527static const struct alc_fixup alc861_fixups[] = { 3246static const struct hda_fixup alc861_fixups[] = {
6528 [ALC861_FIXUP_FSC_AMILO_PI1505] = { 3247 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
6529 .type = ALC_FIXUP_PINS, 3248 .type = HDA_FIXUP_PINS,
6530 .v.pins = (const struct alc_pincfg[]) { 3249 .v.pins = (const struct hda_pintbl[]) {
6531 { 0x0b, 0x0221101f }, /* HP */ 3250 { 0x0b, 0x0221101f }, /* HP */
6532 { 0x0f, 0x90170310 }, /* speaker */ 3251 { 0x0f, 0x90170310 }, /* speaker */
6533 { } 3252 { }
6534 } 3253 }
6535 }, 3254 },
6536 [ALC861_FIXUP_AMP_VREF_0F] = { 3255 [ALC861_FIXUP_AMP_VREF_0F] = {
6537 .type = ALC_FIXUP_FUNC, 3256 .type = HDA_FIXUP_FUNC,
6538 .v.func = alc861_fixup_asus_amp_vref_0f, 3257 .v.func = alc861_fixup_asus_amp_vref_0f,
6539 }, 3258 },
6540 [ALC861_FIXUP_NO_JACK_DETECT] = { 3259 [ALC861_FIXUP_NO_JACK_DETECT] = {
6541 .type = ALC_FIXUP_FUNC, 3260 .type = HDA_FIXUP_FUNC,
6542 .v.func = alc_fixup_no_jack_detect, 3261 .v.func = alc_fixup_no_jack_detect,
6543 }, 3262 },
6544 [ALC861_FIXUP_ASUS_A6RP] = { 3263 [ALC861_FIXUP_ASUS_A6RP] = {
6545 .type = ALC_FIXUP_FUNC, 3264 .type = HDA_FIXUP_FUNC,
6546 .v.func = alc861_fixup_asus_amp_vref_0f, 3265 .v.func = alc861_fixup_asus_amp_vref_0f,
6547 .chained = true, 3266 .chained = true,
6548 .chain_id = ALC861_FIXUP_NO_JACK_DETECT, 3267 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
@@ -6572,15 +3291,15 @@ static int patch_alc861(struct hda_codec *codec)
6572 3291
6573 spec = codec->spec; 3292 spec = codec->spec;
6574 3293
6575 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups); 3294 snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6576 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 3295 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6577 3296
6578 /* automatic parse from the BIOS config */ 3297 /* automatic parse from the BIOS config */
6579 err = alc861_parse_auto_config(codec); 3298 err = alc861_parse_auto_config(codec);
6580 if (err < 0) 3299 if (err < 0)
6581 goto error; 3300 goto error;
6582 3301
6583 if (!spec->no_analog) { 3302 if (!spec->gen.no_analog) {
6584 err = snd_hda_attach_beep_device(codec, 0x23); 3303 err = snd_hda_attach_beep_device(codec, 0x23);
6585 if (err < 0) 3304 if (err < 0)
6586 goto error; 3305 goto error;
@@ -6592,7 +3311,7 @@ static int patch_alc861(struct hda_codec *codec)
6592 spec->power_hook = alc_power_eapd; 3311 spec->power_hook = alc_power_eapd;
6593#endif 3312#endif
6594 3313
6595 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 3314 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6596 3315
6597 return 0; 3316 return 0;
6598 3317
@@ -6622,17 +3341,17 @@ enum {
6622 3341
6623/* exclude VREF80 */ 3342/* exclude VREF80 */
6624static void alc861vd_fixup_dallas(struct hda_codec *codec, 3343static void alc861vd_fixup_dallas(struct hda_codec *codec,
6625 const struct alc_fixup *fix, int action) 3344 const struct hda_fixup *fix, int action)
6626{ 3345{
6627 if (action == ALC_FIXUP_ACT_PRE_PROBE) { 3346 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
6628 snd_hda_override_pin_caps(codec, 0x18, 0x00000734); 3347 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6629 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c); 3348 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
6630 } 3349 }
6631} 3350}
6632 3351
6633static const struct alc_fixup alc861vd_fixups[] = { 3352static const struct hda_fixup alc861vd_fixups[] = {
6634 [ALC660VD_FIX_ASUS_GPIO1] = { 3353 [ALC660VD_FIX_ASUS_GPIO1] = {
6635 .type = ALC_FIXUP_VERBS, 3354 .type = HDA_FIXUP_VERBS,
6636 .v.verbs = (const struct hda_verb[]) { 3355 .v.verbs = (const struct hda_verb[]) {
6637 /* reset GPIO1 */ 3356 /* reset GPIO1 */
6638 {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, 3357 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
@@ -6642,7 +3361,7 @@ static const struct alc_fixup alc861vd_fixups[] = {
6642 } 3361 }
6643 }, 3362 },
6644 [ALC861VD_FIX_DALLAS] = { 3363 [ALC861VD_FIX_DALLAS] = {
6645 .type = ALC_FIXUP_FUNC, 3364 .type = HDA_FIXUP_FUNC,
6646 .v.func = alc861vd_fixup_dallas, 3365 .v.func = alc861vd_fixup_dallas,
6647 }, 3366 },
6648}; 3367};
@@ -6667,15 +3386,15 @@ static int patch_alc861vd(struct hda_codec *codec)
6667 3386
6668 spec = codec->spec; 3387 spec = codec->spec;
6669 3388
6670 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups); 3389 snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6671 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 3390 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6672 3391
6673 /* automatic parse from the BIOS config */ 3392 /* automatic parse from the BIOS config */
6674 err = alc861vd_parse_auto_config(codec); 3393 err = alc861vd_parse_auto_config(codec);
6675 if (err < 0) 3394 if (err < 0)
6676 goto error; 3395 goto error;
6677 3396
6678 if (!spec->no_analog) { 3397 if (!spec->gen.no_analog) {
6679 err = snd_hda_attach_beep_device(codec, 0x23); 3398 err = snd_hda_attach_beep_device(codec, 0x23);
6680 if (err < 0) 3399 if (err < 0)
6681 goto error; 3400 goto error;
@@ -6686,7 +3405,7 @@ static int patch_alc861vd(struct hda_codec *codec)
6686 3405
6687 spec->shutup = alc_eapd_shutup; 3406 spec->shutup = alc_eapd_shutup;
6688 3407
6689 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 3408 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6690 3409
6691 return 0; 3410 return 0;
6692 3411
@@ -6727,9 +3446,9 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
6727} 3446}
6728 3447
6729static void alc272_fixup_mario(struct hda_codec *codec, 3448static void alc272_fixup_mario(struct hda_codec *codec,
6730 const struct alc_fixup *fix, int action) 3449 const struct hda_fixup *fix, int action)
6731{ 3450{
6732 if (action != ALC_FIXUP_ACT_PROBE) 3451 if (action != HDA_FIXUP_ACT_PRE_PROBE)
6733 return; 3452 return;
6734 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT, 3453 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6735 (0x3b << AC_AMPCAP_OFFSET_SHIFT) | 3454 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
@@ -6760,39 +3479,39 @@ enum {
6760 ALC662_FIXUP_INV_DMIC, 3479 ALC662_FIXUP_INV_DMIC,
6761}; 3480};
6762 3481
6763static const struct alc_fixup alc662_fixups[] = { 3482static const struct hda_fixup alc662_fixups[] = {
6764 [ALC662_FIXUP_ASPIRE] = { 3483 [ALC662_FIXUP_ASPIRE] = {
6765 .type = ALC_FIXUP_PINS, 3484 .type = HDA_FIXUP_PINS,
6766 .v.pins = (const struct alc_pincfg[]) { 3485 .v.pins = (const struct hda_pintbl[]) {
6767 { 0x15, 0x99130112 }, /* subwoofer */ 3486 { 0x15, 0x99130112 }, /* subwoofer */
6768 { } 3487 { }
6769 } 3488 }
6770 }, 3489 },
6771 [ALC662_FIXUP_IDEAPAD] = { 3490 [ALC662_FIXUP_IDEAPAD] = {
6772 .type = ALC_FIXUP_PINS, 3491 .type = HDA_FIXUP_PINS,
6773 .v.pins = (const struct alc_pincfg[]) { 3492 .v.pins = (const struct hda_pintbl[]) {
6774 { 0x17, 0x99130112 }, /* subwoofer */ 3493 { 0x17, 0x99130112 }, /* subwoofer */
6775 { } 3494 { }
6776 } 3495 }
6777 }, 3496 },
6778 [ALC272_FIXUP_MARIO] = { 3497 [ALC272_FIXUP_MARIO] = {
6779 .type = ALC_FIXUP_FUNC, 3498 .type = HDA_FIXUP_FUNC,
6780 .v.func = alc272_fixup_mario, 3499 .v.func = alc272_fixup_mario,
6781 }, 3500 },
6782 [ALC662_FIXUP_CZC_P10T] = { 3501 [ALC662_FIXUP_CZC_P10T] = {
6783 .type = ALC_FIXUP_VERBS, 3502 .type = HDA_FIXUP_VERBS,
6784 .v.verbs = (const struct hda_verb[]) { 3503 .v.verbs = (const struct hda_verb[]) {
6785 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0}, 3504 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6786 {} 3505 {}
6787 } 3506 }
6788 }, 3507 },
6789 [ALC662_FIXUP_SKU_IGNORE] = { 3508 [ALC662_FIXUP_SKU_IGNORE] = {
6790 .type = ALC_FIXUP_FUNC, 3509 .type = HDA_FIXUP_FUNC,
6791 .v.func = alc_fixup_sku_ignore, 3510 .v.func = alc_fixup_sku_ignore,
6792 }, 3511 },
6793 [ALC662_FIXUP_HP_RP5800] = { 3512 [ALC662_FIXUP_HP_RP5800] = {
6794 .type = ALC_FIXUP_PINS, 3513 .type = HDA_FIXUP_PINS,
6795 .v.pins = (const struct alc_pincfg[]) { 3514 .v.pins = (const struct hda_pintbl[]) {
6796 { 0x14, 0x0221201f }, /* HP out */ 3515 { 0x14, 0x0221201f }, /* HP out */
6797 { } 3516 { }
6798 }, 3517 },
@@ -6800,8 +3519,8 @@ static const struct alc_fixup alc662_fixups[] = {
6800 .chain_id = ALC662_FIXUP_SKU_IGNORE 3519 .chain_id = ALC662_FIXUP_SKU_IGNORE
6801 }, 3520 },
6802 [ALC662_FIXUP_ASUS_MODE1] = { 3521 [ALC662_FIXUP_ASUS_MODE1] = {
6803 .type = ALC_FIXUP_PINS, 3522 .type = HDA_FIXUP_PINS,
6804 .v.pins = (const struct alc_pincfg[]) { 3523 .v.pins = (const struct hda_pintbl[]) {
6805 { 0x14, 0x99130110 }, /* speaker */ 3524 { 0x14, 0x99130110 }, /* speaker */
6806 { 0x18, 0x01a19c20 }, /* mic */ 3525 { 0x18, 0x01a19c20 }, /* mic */
6807 { 0x19, 0x99a3092f }, /* int-mic */ 3526 { 0x19, 0x99a3092f }, /* int-mic */
@@ -6812,8 +3531,8 @@ static const struct alc_fixup alc662_fixups[] = {
6812 .chain_id = ALC662_FIXUP_SKU_IGNORE 3531 .chain_id = ALC662_FIXUP_SKU_IGNORE
6813 }, 3532 },
6814 [ALC662_FIXUP_ASUS_MODE2] = { 3533 [ALC662_FIXUP_ASUS_MODE2] = {
6815 .type = ALC_FIXUP_PINS, 3534 .type = HDA_FIXUP_PINS,
6816 .v.pins = (const struct alc_pincfg[]) { 3535 .v.pins = (const struct hda_pintbl[]) {
6817 { 0x14, 0x99130110 }, /* speaker */ 3536 { 0x14, 0x99130110 }, /* speaker */
6818 { 0x18, 0x01a19820 }, /* mic */ 3537 { 0x18, 0x01a19820 }, /* mic */
6819 { 0x19, 0x99a3092f }, /* int-mic */ 3538 { 0x19, 0x99a3092f }, /* int-mic */
@@ -6824,8 +3543,8 @@ static const struct alc_fixup alc662_fixups[] = {
6824 .chain_id = ALC662_FIXUP_SKU_IGNORE 3543 .chain_id = ALC662_FIXUP_SKU_IGNORE
6825 }, 3544 },
6826 [ALC662_FIXUP_ASUS_MODE3] = { 3545 [ALC662_FIXUP_ASUS_MODE3] = {
6827 .type = ALC_FIXUP_PINS, 3546 .type = HDA_FIXUP_PINS,
6828 .v.pins = (const struct alc_pincfg[]) { 3547 .v.pins = (const struct hda_pintbl[]) {
6829 { 0x14, 0x99130110 }, /* speaker */ 3548 { 0x14, 0x99130110 }, /* speaker */
6830 { 0x15, 0x0121441f }, /* HP */ 3549 { 0x15, 0x0121441f }, /* HP */
6831 { 0x18, 0x01a19840 }, /* mic */ 3550 { 0x18, 0x01a19840 }, /* mic */
@@ -6837,8 +3556,8 @@ static const struct alc_fixup alc662_fixups[] = {
6837 .chain_id = ALC662_FIXUP_SKU_IGNORE 3556 .chain_id = ALC662_FIXUP_SKU_IGNORE
6838 }, 3557 },
6839 [ALC662_FIXUP_ASUS_MODE4] = { 3558 [ALC662_FIXUP_ASUS_MODE4] = {
6840 .type = ALC_FIXUP_PINS, 3559 .type = HDA_FIXUP_PINS,
6841 .v.pins = (const struct alc_pincfg[]) { 3560 .v.pins = (const struct hda_pintbl[]) {
6842 { 0x14, 0x99130110 }, /* speaker */ 3561 { 0x14, 0x99130110 }, /* speaker */
6843 { 0x16, 0x99130111 }, /* speaker */ 3562 { 0x16, 0x99130111 }, /* speaker */
6844 { 0x18, 0x01a19840 }, /* mic */ 3563 { 0x18, 0x01a19840 }, /* mic */
@@ -6850,8 +3569,8 @@ static const struct alc_fixup alc662_fixups[] = {
6850 .chain_id = ALC662_FIXUP_SKU_IGNORE 3569 .chain_id = ALC662_FIXUP_SKU_IGNORE
6851 }, 3570 },
6852 [ALC662_FIXUP_ASUS_MODE5] = { 3571 [ALC662_FIXUP_ASUS_MODE5] = {
6853 .type = ALC_FIXUP_PINS, 3572 .type = HDA_FIXUP_PINS,
6854 .v.pins = (const struct alc_pincfg[]) { 3573 .v.pins = (const struct hda_pintbl[]) {
6855 { 0x14, 0x99130110 }, /* speaker */ 3574 { 0x14, 0x99130110 }, /* speaker */
6856 { 0x15, 0x0121441f }, /* HP */ 3575 { 0x15, 0x0121441f }, /* HP */
6857 { 0x16, 0x99130111 }, /* speaker */ 3576 { 0x16, 0x99130111 }, /* speaker */
@@ -6863,8 +3582,8 @@ static const struct alc_fixup alc662_fixups[] = {
6863 .chain_id = ALC662_FIXUP_SKU_IGNORE 3582 .chain_id = ALC662_FIXUP_SKU_IGNORE
6864 }, 3583 },
6865 [ALC662_FIXUP_ASUS_MODE6] = { 3584 [ALC662_FIXUP_ASUS_MODE6] = {
6866 .type = ALC_FIXUP_PINS, 3585 .type = HDA_FIXUP_PINS,
6867 .v.pins = (const struct alc_pincfg[]) { 3586 .v.pins = (const struct hda_pintbl[]) {
6868 { 0x14, 0x99130110 }, /* speaker */ 3587 { 0x14, 0x99130110 }, /* speaker */
6869 { 0x15, 0x01211420 }, /* HP2 */ 3588 { 0x15, 0x01211420 }, /* HP2 */
6870 { 0x18, 0x01a19840 }, /* mic */ 3589 { 0x18, 0x01a19840 }, /* mic */
@@ -6876,8 +3595,8 @@ static const struct alc_fixup alc662_fixups[] = {
6876 .chain_id = ALC662_FIXUP_SKU_IGNORE 3595 .chain_id = ALC662_FIXUP_SKU_IGNORE
6877 }, 3596 },
6878 [ALC662_FIXUP_ASUS_MODE7] = { 3597 [ALC662_FIXUP_ASUS_MODE7] = {
6879 .type = ALC_FIXUP_PINS, 3598 .type = HDA_FIXUP_PINS,
6880 .v.pins = (const struct alc_pincfg[]) { 3599 .v.pins = (const struct hda_pintbl[]) {
6881 { 0x14, 0x99130110 }, /* speaker */ 3600 { 0x14, 0x99130110 }, /* speaker */
6882 { 0x17, 0x99130111 }, /* speaker */ 3601 { 0x17, 0x99130111 }, /* speaker */
6883 { 0x18, 0x01a19840 }, /* mic */ 3602 { 0x18, 0x01a19840 }, /* mic */
@@ -6890,8 +3609,8 @@ static const struct alc_fixup alc662_fixups[] = {
6890 .chain_id = ALC662_FIXUP_SKU_IGNORE 3609 .chain_id = ALC662_FIXUP_SKU_IGNORE
6891 }, 3610 },
6892 [ALC662_FIXUP_ASUS_MODE8] = { 3611 [ALC662_FIXUP_ASUS_MODE8] = {
6893 .type = ALC_FIXUP_PINS, 3612 .type = HDA_FIXUP_PINS,
6894 .v.pins = (const struct alc_pincfg[]) { 3613 .v.pins = (const struct hda_pintbl[]) {
6895 { 0x14, 0x99130110 }, /* speaker */ 3614 { 0x14, 0x99130110 }, /* speaker */
6896 { 0x12, 0x99a30970 }, /* int-mic */ 3615 { 0x12, 0x99a30970 }, /* int-mic */
6897 { 0x15, 0x01214020 }, /* HP */ 3616 { 0x15, 0x01214020 }, /* HP */
@@ -6904,18 +3623,18 @@ static const struct alc_fixup alc662_fixups[] = {
6904 .chain_id = ALC662_FIXUP_SKU_IGNORE 3623 .chain_id = ALC662_FIXUP_SKU_IGNORE
6905 }, 3624 },
6906 [ALC662_FIXUP_NO_JACK_DETECT] = { 3625 [ALC662_FIXUP_NO_JACK_DETECT] = {
6907 .type = ALC_FIXUP_FUNC, 3626 .type = HDA_FIXUP_FUNC,
6908 .v.func = alc_fixup_no_jack_detect, 3627 .v.func = alc_fixup_no_jack_detect,
6909 }, 3628 },
6910 [ALC662_FIXUP_ZOTAC_Z68] = { 3629 [ALC662_FIXUP_ZOTAC_Z68] = {
6911 .type = ALC_FIXUP_PINS, 3630 .type = HDA_FIXUP_PINS,
6912 .v.pins = (const struct alc_pincfg[]) { 3631 .v.pins = (const struct hda_pintbl[]) {
6913 { 0x1b, 0x02214020 }, /* Front HP */ 3632 { 0x1b, 0x02214020 }, /* Front HP */
6914 { } 3633 { }
6915 } 3634 }
6916 }, 3635 },
6917 [ALC662_FIXUP_INV_DMIC] = { 3636 [ALC662_FIXUP_INV_DMIC] = {
6918 .type = ALC_FIXUP_FUNC, 3637 .type = HDA_FIXUP_FUNC,
6919 .v.func = alc_fixup_inv_dmic_0x12, 3638 .v.func = alc_fixup_inv_dmic_0x12,
6920 }, 3639 },
6921}; 3640};
@@ -6995,7 +3714,7 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
6995 {} 3714 {}
6996}; 3715};
6997 3716
6998static const struct alc_model_fixup alc662_fixup_models[] = { 3717static const struct hda_model_fixup alc662_fixup_models[] = {
6999 {.id = ALC272_FIXUP_MARIO, .name = "mario"}, 3718 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
7000 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"}, 3719 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7001 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"}, 3720 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
@@ -7056,9 +3775,9 @@ static int patch_alc662(struct hda_codec *codec)
7056 spec->init_hook = alc662_fill_coef; 3775 spec->init_hook = alc662_fill_coef;
7057 alc662_fill_coef(codec); 3776 alc662_fill_coef(codec);
7058 3777
7059 alc_pick_fixup(codec, alc662_fixup_models, 3778 snd_hda_pick_fixup(codec, alc662_fixup_models,
7060 alc662_fixup_tbl, alc662_fixups); 3779 alc662_fixup_tbl, alc662_fixups);
7061 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 3780 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
7062 3781
7063 alc_auto_parse_customize_define(codec); 3782 alc_auto_parse_customize_define(codec);
7064 3783
@@ -7074,7 +3793,7 @@ static int patch_alc662(struct hda_codec *codec)
7074 if (err < 0) 3793 if (err < 0)
7075 goto error; 3794 goto error;
7076 3795
7077 if (!spec->no_analog && has_cdefine_beep(codec)) { 3796 if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
7078 err = snd_hda_attach_beep_device(codec, 0x1); 3797 err = snd_hda_attach_beep_device(codec, 0x1);
7079 if (err < 0) 3798 if (err < 0)
7080 goto error; 3799 goto error;
@@ -7096,7 +3815,7 @@ static int patch_alc662(struct hda_codec *codec)
7096 codec->patch_ops = alc_patch_ops; 3815 codec->patch_ops = alc_patch_ops;
7097 spec->shutup = alc_eapd_shutup; 3816 spec->shutup = alc_eapd_shutup;
7098 3817
7099 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 3818 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
7100 3819
7101 return 0; 3820 return 0;
7102 3821
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index a86547ca17c8..83d5335ac348 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -31,7 +31,6 @@
31#include <linux/dmi.h> 31#include <linux/dmi.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <sound/core.h> 33#include <sound/core.h>
34#include <sound/asoundef.h>
35#include <sound/jack.h> 34#include <sound/jack.h>
36#include <sound/tlv.h> 35#include <sound/tlv.h>
37#include "hda_codec.h" 36#include "hda_codec.h"
@@ -39,18 +38,14 @@
39#include "hda_auto_parser.h" 38#include "hda_auto_parser.h"
40#include "hda_beep.h" 39#include "hda_beep.h"
41#include "hda_jack.h" 40#include "hda_jack.h"
41#include "hda_generic.h"
42 42
43enum { 43enum {
44 STAC_VREF_EVENT = 1, 44 STAC_VREF_EVENT = 8,
45 STAC_INSERT_EVENT,
46 STAC_PWR_EVENT, 45 STAC_PWR_EVENT,
47 STAC_HP_EVENT,
48 STAC_LO_EVENT,
49 STAC_MIC_EVENT,
50}; 46};
51 47
52enum { 48enum {
53 STAC_AUTO,
54 STAC_REF, 49 STAC_REF,
55 STAC_9200_OQO, 50 STAC_9200_OQO,
56 STAC_9200_DELL_D21, 51 STAC_9200_DELL_D21,
@@ -66,11 +61,11 @@ enum {
66 STAC_9200_M4, 61 STAC_9200_M4,
67 STAC_9200_M4_2, 62 STAC_9200_M4_2,
68 STAC_9200_PANASONIC, 63 STAC_9200_PANASONIC,
64 STAC_9200_EAPD_INIT,
69 STAC_9200_MODELS 65 STAC_9200_MODELS
70}; 66};
71 67
72enum { 68enum {
73 STAC_9205_AUTO,
74 STAC_9205_REF, 69 STAC_9205_REF,
75 STAC_9205_DELL_M42, 70 STAC_9205_DELL_M42,
76 STAC_9205_DELL_M43, 71 STAC_9205_DELL_M43,
@@ -80,7 +75,6 @@ enum {
80}; 75};
81 76
82enum { 77enum {
83 STAC_92HD73XX_AUTO,
84 STAC_92HD73XX_NO_JD, /* no jack-detection */ 78 STAC_92HD73XX_NO_JD, /* no jack-detection */
85 STAC_92HD73XX_REF, 79 STAC_92HD73XX_REF,
86 STAC_92HD73XX_INTEL, 80 STAC_92HD73XX_INTEL,
@@ -93,7 +87,6 @@ enum {
93}; 87};
94 88
95enum { 89enum {
96 STAC_92HD83XXX_AUTO,
97 STAC_92HD83XXX_REF, 90 STAC_92HD83XXX_REF,
98 STAC_92HD83XXX_PWR_REF, 91 STAC_92HD83XXX_PWR_REF,
99 STAC_DELL_S14, 92 STAC_DELL_S14,
@@ -105,11 +98,12 @@ enum {
105 STAC_92HD83XXX_HP_INV_LED, 98 STAC_92HD83XXX_HP_INV_LED,
106 STAC_92HD83XXX_HP_MIC_LED, 99 STAC_92HD83XXX_HP_MIC_LED,
107 STAC_92HD83XXX_HEADSET_JACK, 100 STAC_92HD83XXX_HEADSET_JACK,
101 STAC_92HD83XXX_HP,
102 STAC_HP_ENVY_BASS,
108 STAC_92HD83XXX_MODELS 103 STAC_92HD83XXX_MODELS
109}; 104};
110 105
111enum { 106enum {
112 STAC_92HD71BXX_AUTO,
113 STAC_92HD71BXX_REF, 107 STAC_92HD71BXX_REF,
114 STAC_DELL_M4_1, 108 STAC_DELL_M4_1,
115 STAC_DELL_M4_2, 109 STAC_DELL_M4_2,
@@ -118,12 +112,13 @@ enum {
118 STAC_HP_DV4, 112 STAC_HP_DV4,
119 STAC_HP_DV5, 113 STAC_HP_DV5,
120 STAC_HP_HDX, 114 STAC_HP_HDX,
121 STAC_HP_DV4_1222NR, 115 STAC_92HD71BXX_HP,
116 STAC_92HD71BXX_NO_DMIC,
117 STAC_92HD71BXX_NO_SMUX,
122 STAC_92HD71BXX_MODELS 118 STAC_92HD71BXX_MODELS
123}; 119};
124 120
125enum { 121enum {
126 STAC_925x_AUTO,
127 STAC_925x_REF, 122 STAC_925x_REF,
128 STAC_M1, 123 STAC_M1,
129 STAC_M1_2, 124 STAC_M1_2,
@@ -136,7 +131,6 @@ enum {
136}; 131};
137 132
138enum { 133enum {
139 STAC_922X_AUTO,
140 STAC_D945_REF, 134 STAC_D945_REF,
141 STAC_D945GTP3, 135 STAC_D945GTP3,
142 STAC_D945GTP5, 136 STAC_D945GTP5,
@@ -145,67 +139,45 @@ enum {
145 STAC_INTEL_MAC_V3, 139 STAC_INTEL_MAC_V3,
146 STAC_INTEL_MAC_V4, 140 STAC_INTEL_MAC_V4,
147 STAC_INTEL_MAC_V5, 141 STAC_INTEL_MAC_V5,
148 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter 142 STAC_INTEL_MAC_AUTO,
149 * is given, one of the above models will be
150 * chosen according to the subsystem id. */
151 /* for backward compatibility */
152 STAC_MACMINI,
153 STAC_MACBOOK,
154 STAC_MACBOOK_PRO_V1,
155 STAC_MACBOOK_PRO_V2,
156 STAC_IMAC_INTEL,
157 STAC_IMAC_INTEL_20,
158 STAC_ECS_202, 143 STAC_ECS_202,
159 STAC_922X_DELL_D81, 144 STAC_922X_DELL_D81,
160 STAC_922X_DELL_D82, 145 STAC_922X_DELL_D82,
161 STAC_922X_DELL_M81, 146 STAC_922X_DELL_M81,
162 STAC_922X_DELL_M82, 147 STAC_922X_DELL_M82,
148 STAC_922X_INTEL_MAC_GPIO,
163 STAC_922X_MODELS 149 STAC_922X_MODELS
164}; 150};
165 151
166enum { 152enum {
167 STAC_927X_AUTO,
168 STAC_D965_REF_NO_JD, /* no jack-detection */ 153 STAC_D965_REF_NO_JD, /* no jack-detection */
169 STAC_D965_REF, 154 STAC_D965_REF,
170 STAC_D965_3ST, 155 STAC_D965_3ST,
171 STAC_D965_5ST, 156 STAC_D965_5ST,
172 STAC_D965_5ST_NO_FP, 157 STAC_D965_5ST_NO_FP,
158 STAC_D965_VERBS,
173 STAC_DELL_3ST, 159 STAC_DELL_3ST,
174 STAC_DELL_BIOS, 160 STAC_DELL_BIOS,
161 STAC_DELL_BIOS_SPDIF,
162 STAC_927X_DELL_DMIC,
175 STAC_927X_VOLKNOB, 163 STAC_927X_VOLKNOB,
176 STAC_927X_MODELS 164 STAC_927X_MODELS
177}; 165};
178 166
179enum { 167enum {
180 STAC_9872_AUTO,
181 STAC_9872_VAIO, 168 STAC_9872_VAIO,
182 STAC_9872_MODELS 169 STAC_9872_MODELS
183}; 170};
184 171
185struct sigmatel_mic_route {
186 hda_nid_t pin;
187 signed char mux_idx;
188 signed char dmux_idx;
189};
190
191#define MAX_PINS_NUM 16
192#define MAX_ADCS_NUM 4
193#define MAX_DMICS_NUM 4
194
195struct sigmatel_spec { 172struct sigmatel_spec {
196 struct snd_kcontrol_new *mixers[4]; 173 struct hda_gen_spec gen;
197 unsigned int num_mixers;
198 174
199 int board_config;
200 unsigned int eapd_switch: 1; 175 unsigned int eapd_switch: 1;
201 unsigned int surr_switch: 1;
202 unsigned int alt_switch: 1;
203 unsigned int hp_detect: 1;
204 unsigned int spdif_mute: 1;
205 unsigned int check_volume_offset:1;
206 unsigned int auto_mic:1;
207 unsigned int linear_tone_beep:1; 176 unsigned int linear_tone_beep:1;
208 unsigned int headset_jack:1; /* 4-pin headset jack (hp + mono mic) */ 177 unsigned int headset_jack:1; /* 4-pin headset jack (hp + mono mic) */
178 unsigned int volknob_init:1; /* special volume-knob initialization */
179 unsigned int powerdown_adcs:1;
180 unsigned int have_spdif_mux:1;
209 181
210 /* gpio lines */ 182 /* gpio lines */
211 unsigned int eapd_mask; 183 unsigned int eapd_mask;
@@ -217,6 +189,7 @@ struct sigmatel_spec {
217 unsigned int gpio_led_polarity; 189 unsigned int gpio_led_polarity;
218 unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */ 190 unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
219 unsigned int vref_led; 191 unsigned int vref_led;
192 int default_polarity;
220 193
221 unsigned int mic_mute_led_gpio; /* capture mute LED GPIO */ 194 unsigned int mic_mute_led_gpio; /* capture mute LED GPIO */
222 bool mic_mute_led_on; /* current mic mute state */ 195 bool mic_mute_led_on; /* current mic mute state */
@@ -226,6 +199,7 @@ struct sigmatel_spec {
226 199
227 /* analog loopback */ 200 /* analog loopback */
228 const struct snd_kcontrol_new *aloopback_ctl; 201 const struct snd_kcontrol_new *aloopback_ctl;
202 unsigned int aloopback;
229 unsigned char aloopback_mask; 203 unsigned char aloopback_mask;
230 unsigned char aloopback_shift; 204 unsigned char aloopback_shift;
231 205
@@ -233,647 +207,778 @@ struct sigmatel_spec {
233 unsigned int power_map_bits; 207 unsigned int power_map_bits;
234 unsigned int num_pwrs; 208 unsigned int num_pwrs;
235 const hda_nid_t *pwr_nids; 209 const hda_nid_t *pwr_nids;
236 const hda_nid_t *dac_list; 210 unsigned int active_adcs;
237
238 /* playback */
239 struct hda_input_mux *mono_mux;
240 unsigned int cur_mmux;
241 struct hda_multi_out multiout;
242 hda_nid_t dac_nids[5];
243 hda_nid_t hp_dacs[5];
244 hda_nid_t speaker_dacs[5];
245
246 int volume_offset;
247
248 /* capture */
249 const hda_nid_t *adc_nids;
250 unsigned int num_adcs;
251 const hda_nid_t *mux_nids;
252 unsigned int num_muxes;
253 const hda_nid_t *dmic_nids;
254 unsigned int num_dmics;
255 const hda_nid_t *dmux_nids;
256 unsigned int num_dmuxes;
257 const hda_nid_t *smux_nids;
258 unsigned int num_smuxes;
259 unsigned int num_analog_muxes;
260
261 const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
262 const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
263 unsigned int num_caps; /* number of capture volume/switch elements */
264
265 struct sigmatel_mic_route ext_mic;
266 struct sigmatel_mic_route int_mic;
267 struct sigmatel_mic_route dock_mic;
268 211
269 const char * const *spdif_labels; 212 /* beep widgets */
270
271 hda_nid_t dig_in_nid;
272 hda_nid_t mono_nid;
273 hda_nid_t anabeep_nid; 213 hda_nid_t anabeep_nid;
274 hda_nid_t digbeep_nid; 214 hda_nid_t digbeep_nid;
275 215
276 /* pin widgets */ 216 /* SPDIF-out mux */
277 const hda_nid_t *pin_nids; 217 const char * const *spdif_labels;
278 unsigned int num_pins; 218 struct hda_input_mux spdif_mux;
279
280 /* codec specific stuff */
281 const struct hda_verb *init;
282 const struct snd_kcontrol_new *mixer;
283
284 /* capture source */
285 struct hda_input_mux *dinput_mux;
286 unsigned int cur_dmux[2];
287 struct hda_input_mux *input_mux;
288 unsigned int cur_mux[3];
289 struct hda_input_mux *sinput_mux;
290 unsigned int cur_smux[2]; 219 unsigned int cur_smux[2];
291 unsigned int cur_amux;
292 hda_nid_t *amp_nids;
293 unsigned int powerdown_adcs;
294
295 /* i/o switches */
296 unsigned int io_switch[2];
297 unsigned int clfe_swap;
298 hda_nid_t line_switch; /* shared line-in for input and output */
299 hda_nid_t mic_switch; /* shared mic-in for input and output */
300 hda_nid_t hp_switch; /* NID of HP as line-out */
301 unsigned int aloopback;
302
303 struct hda_pcm pcm_rec[2]; /* PCM information */
304
305 /* dynamic controls and input_mux */
306 struct auto_pin_cfg autocfg;
307 struct snd_array kctls;
308 struct hda_input_mux private_dimux;
309 struct hda_input_mux private_imux;
310 struct hda_input_mux private_smux;
311 struct hda_input_mux private_mono_mux;
312
313 /* auto spec */
314 unsigned auto_pin_cnt;
315 hda_nid_t auto_pin_nids[MAX_PINS_NUM];
316 unsigned auto_adc_cnt;
317 hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
318 hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
319 hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
320 unsigned long auto_capvols[MAX_ADCS_NUM];
321 unsigned auto_dmic_cnt;
322 hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
323
324 struct hda_vmaster_mute_hook vmaster_mute;
325}; 220};
326 221
327#define AC_VERB_IDT_SET_POWER_MAP 0x7ec 222#define AC_VERB_IDT_SET_POWER_MAP 0x7ec
328#define AC_VERB_IDT_GET_POWER_MAP 0xfec 223#define AC_VERB_IDT_GET_POWER_MAP 0xfec
329 224
330static const hda_nid_t stac9200_adc_nids[1] = {
331 0x03,
332};
333
334static const hda_nid_t stac9200_mux_nids[1] = {
335 0x0c,
336};
337
338static const hda_nid_t stac9200_dac_nids[1] = {
339 0x02,
340};
341
342static const hda_nid_t stac92hd73xx_pwr_nids[8] = { 225static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
343 0x0a, 0x0b, 0x0c, 0xd, 0x0e, 226 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
344 0x0f, 0x10, 0x11 227 0x0f, 0x10, 0x11
345}; 228};
346 229
347static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = { 230static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
348 0x26, 0, 231 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
349}; 232 0x0f, 0x10
350
351static const hda_nid_t stac92hd73xx_adc_nids[2] = {
352 0x1a, 0x1b
353};
354
355#define STAC92HD73XX_NUM_DMICS 2
356static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
357 0x13, 0x14, 0
358};
359
360#define STAC92HD73_DAC_COUNT 5
361
362static const hda_nid_t stac92hd73xx_mux_nids[2] = {
363 0x20, 0x21,
364}; 233};
365 234
366static const hda_nid_t stac92hd73xx_dmux_nids[2] = { 235static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
367 0x20, 0x21, 236 0x0a, 0x0d, 0x0f
368}; 237};
369 238
370static const hda_nid_t stac92hd73xx_smux_nids[2] = {
371 0x22, 0x23,
372};
373 239
374#define STAC92HD73XX_NUM_CAPS 2 240/*
375static const unsigned long stac92hd73xx_capvols[] = { 241 * PCM hooks
376 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT), 242 */
377 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT), 243static void stac_playback_pcm_hook(struct hda_pcm_stream *hinfo,
378}; 244 struct hda_codec *codec,
379#define stac92hd73xx_capsws stac92hd73xx_capvols 245 struct snd_pcm_substream *substream,
246 int action)
247{
248 struct sigmatel_spec *spec = codec->spec;
249 if (action == HDA_GEN_PCM_ACT_OPEN && spec->stream_delay)
250 msleep(spec->stream_delay);
251}
380 252
381#define STAC92HD83_DAC_COUNT 3 253static void stac_capture_pcm_hook(struct hda_pcm_stream *hinfo,
254 struct hda_codec *codec,
255 struct snd_pcm_substream *substream,
256 int action)
257{
258 struct sigmatel_spec *spec = codec->spec;
259 int i, idx = 0;
382 260
383static const hda_nid_t stac92hd83xxx_pwr_nids[7] = { 261 if (!spec->powerdown_adcs)
384 0x0a, 0x0b, 0x0c, 0xd, 0x0e, 262 return;
385 0x0f, 0x10
386};
387 263
388static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = { 264 for (i = 0; i < spec->gen.num_all_adcs; i++) {
389 0x1e, 0, 265 if (spec->gen.all_adcs[i] == hinfo->nid) {
390}; 266 idx = i;
267 break;
268 }
269 }
391 270
392static const hda_nid_t stac92hd83xxx_dmic_nids[] = { 271 switch (action) {
393 0x11, 0x20, 272 case HDA_GEN_PCM_ACT_OPEN:
394}; 273 msleep(40);
274 snd_hda_codec_write(codec, hinfo->nid, 0,
275 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
276 spec->active_adcs |= (1 << idx);
277 break;
278 case HDA_GEN_PCM_ACT_CLOSE:
279 snd_hda_codec_write(codec, hinfo->nid, 0,
280 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
281 spec->active_adcs &= ~(1 << idx);
282 break;
283 }
284}
395 285
396static const hda_nid_t stac92hd71bxx_pwr_nids[3] = { 286/*
397 0x0a, 0x0d, 0x0f 287 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
398}; 288 * funky external mute control using GPIO pins.
289 */
399 290
400static const hda_nid_t stac92hd71bxx_adc_nids[2] = { 291static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
401 0x12, 0x13, 292 unsigned int dir_mask, unsigned int data)
402}; 293{
294 unsigned int gpiostate, gpiomask, gpiodir;
403 295
404static const hda_nid_t stac92hd71bxx_mux_nids[2] = { 296 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
405 0x1a, 0x1b
406};
407 297
408static const hda_nid_t stac92hd71bxx_dmux_nids[2] = { 298 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
409 0x1c, 0x1d, 299 AC_VERB_GET_GPIO_DATA, 0);
410}; 300 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
411 301
412static const hda_nid_t stac92hd71bxx_smux_nids[2] = { 302 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
413 0x24, 0x25, 303 AC_VERB_GET_GPIO_MASK, 0);
414}; 304 gpiomask |= mask;
415 305
416#define STAC92HD71BXX_NUM_DMICS 2 306 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
417static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = { 307 AC_VERB_GET_GPIO_DIRECTION, 0);
418 0x18, 0x19, 0 308 gpiodir |= dir_mask;
419};
420 309
421static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = { 310 /* Configure GPIOx as CMOS */
422 0x18, 0 311 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
423};
424 312
425static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = { 313 snd_hda_codec_write(codec, codec->afg, 0,
426 0x22, 0 314 AC_VERB_SET_GPIO_MASK, gpiomask);
427}; 315 snd_hda_codec_read(codec, codec->afg, 0,
316 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
428 317
429#define STAC92HD71BXX_NUM_CAPS 2 318 msleep(1);
430static const unsigned long stac92hd71bxx_capvols[] = {
431 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
432 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
433};
434#define stac92hd71bxx_capsws stac92hd71bxx_capvols
435 319
436static const hda_nid_t stac925x_adc_nids[1] = { 320 snd_hda_codec_read(codec, codec->afg, 0,
437 0x03, 321 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
438}; 322}
439 323
440static const hda_nid_t stac925x_mux_nids[1] = { 324/* hook for controlling mic-mute LED GPIO */
441 0x0f, 325static void stac_capture_led_hook(struct hda_codec *codec,
442}; 326 struct snd_ctl_elem_value *ucontrol)
327{
328 struct sigmatel_spec *spec = codec->spec;
329 bool mute;
443 330
444static const hda_nid_t stac925x_dac_nids[1] = { 331 if (!ucontrol)
445 0x02, 332 return;
446};
447 333
448#define STAC925X_NUM_DMICS 1 334 mute = !(ucontrol->value.integer.value[0] ||
449static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = { 335 ucontrol->value.integer.value[1]);
450 0x15, 0 336 if (spec->mic_mute_led_on != mute) {
451}; 337 spec->mic_mute_led_on = mute;
338 if (mute)
339 spec->gpio_data |= spec->mic_mute_led_gpio;
340 else
341 spec->gpio_data &= ~spec->mic_mute_led_gpio;
342 stac_gpio_set(codec, spec->gpio_mask,
343 spec->gpio_dir, spec->gpio_data);
344 }
345}
452 346
453static const hda_nid_t stac925x_dmux_nids[1] = { 347static int stac_vrefout_set(struct hda_codec *codec,
454 0x14, 348 hda_nid_t nid, unsigned int new_vref)
455}; 349{
350 int error, pinctl;
456 351
457static const unsigned long stac925x_capvols[] = { 352 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
458 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT), 353 pinctl = snd_hda_codec_read(codec, nid, 0,
459}; 354 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
460static const unsigned long stac925x_capsws[] = {
461 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
462};
463 355
464static const hda_nid_t stac922x_adc_nids[2] = { 356 if (pinctl < 0)
465 0x06, 0x07, 357 return pinctl;
466};
467 358
468static const hda_nid_t stac922x_mux_nids[2] = { 359 pinctl &= 0xff;
469 0x12, 0x13, 360 pinctl &= ~AC_PINCTL_VREFEN;
470}; 361 pinctl |= (new_vref & AC_PINCTL_VREFEN);
471 362
472#define STAC922X_NUM_CAPS 2 363 error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl);
473static const unsigned long stac922x_capvols[] = { 364 if (error < 0)
474 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT), 365 return error;
475 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
476};
477#define stac922x_capsws stac922x_capvols
478 366
479static const hda_nid_t stac927x_slave_dig_outs[2] = { 367 return 1;
480 0x1f, 0, 368}
481};
482 369
483static const hda_nid_t stac927x_adc_nids[3] = { 370/* update mute-LED accoring to the master switch */
484 0x07, 0x08, 0x09 371static void stac_update_led_status(struct hda_codec *codec, int enabled)
485}; 372{
373 struct sigmatel_spec *spec = codec->spec;
374 int muted = !enabled;
486 375
487static const hda_nid_t stac927x_mux_nids[3] = { 376 if (!spec->gpio_led)
488 0x15, 0x16, 0x17 377 return;
489};
490 378
491static const hda_nid_t stac927x_smux_nids[1] = { 379 /* LED state is inverted on these systems */
492 0x21, 380 if (spec->gpio_led_polarity)
493}; 381 muted = !muted;
494 382
495static const hda_nid_t stac927x_dac_nids[6] = { 383 if (!spec->vref_mute_led_nid) {
496 0x02, 0x03, 0x04, 0x05, 0x06, 0 384 if (muted)
497}; 385 spec->gpio_data |= spec->gpio_led;
386 else
387 spec->gpio_data &= ~spec->gpio_led;
388 stac_gpio_set(codec, spec->gpio_mask,
389 spec->gpio_dir, spec->gpio_data);
390 } else {
391 spec->vref_led = muted ? AC_PINCTL_VREF_50 : AC_PINCTL_VREF_GRD;
392 stac_vrefout_set(codec, spec->vref_mute_led_nid,
393 spec->vref_led);
394 }
395}
498 396
499static const hda_nid_t stac927x_dmux_nids[1] = { 397/* vmaster hook to update mute LED */
500 0x1b, 398static void stac_vmaster_hook(void *private_data, int val)
501}; 399{
400 stac_update_led_status(private_data, val);
401}
502 402
503#define STAC927X_NUM_DMICS 2 403/* automute hook to handle GPIO mute and EAPD updates */
504static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = { 404static void stac_update_outputs(struct hda_codec *codec)
505 0x13, 0x14, 0 405{
506}; 406 struct sigmatel_spec *spec = codec->spec;
507 407
508#define STAC927X_NUM_CAPS 3 408 if (spec->gpio_mute)
509static const unsigned long stac927x_capvols[] = { 409 spec->gen.master_mute =
510 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT), 410 !(snd_hda_codec_read(codec, codec->afg, 0,
511 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT), 411 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
512 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
513};
514static const unsigned long stac927x_capsws[] = {
515 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
516 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
517 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
518};
519 412
520static const char * const stac927x_spdif_labels[5] = { 413 snd_hda_gen_update_outputs(codec);
521 "Digital Playback", "ADAT", "Analog Mux 1",
522 "Analog Mux 2", "Analog Mux 3"
523};
524 414
525static const hda_nid_t stac9205_adc_nids[2] = { 415 if (spec->eapd_mask && spec->eapd_switch) {
526 0x12, 0x13 416 unsigned int val = spec->gpio_data;
527}; 417 if (spec->gen.speaker_muted)
418 val &= ~spec->eapd_mask;
419 else
420 val |= spec->eapd_mask;
421 if (spec->gpio_data != val)
422 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir,
423 val);
424 }
425}
528 426
529static const hda_nid_t stac9205_mux_nids[2] = { 427static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
530 0x19, 0x1a 428 bool enable, bool do_write)
531}; 429{
430 struct sigmatel_spec *spec = codec->spec;
431 unsigned int idx, val;
532 432
533static const hda_nid_t stac9205_dmux_nids[1] = { 433 for (idx = 0; idx < spec->num_pwrs; idx++) {
534 0x1d, 434 if (spec->pwr_nids[idx] == nid)
535}; 435 break;
436 }
437 if (idx >= spec->num_pwrs)
438 return;
536 439
537static const hda_nid_t stac9205_smux_nids[1] = { 440 idx = 1 << idx;
538 0x21,
539};
540 441
541#define STAC9205_NUM_DMICS 2 442 val = spec->power_map_bits;
542static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = { 443 if (enable)
543 0x17, 0x18, 0 444 val &= ~idx;
544}; 445 else
446 val |= idx;
545 447
546#define STAC9205_NUM_CAPS 2 448 /* power down unused output ports */
547static const unsigned long stac9205_capvols[] = { 449 if (val != spec->power_map_bits) {
548 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT), 450 spec->power_map_bits = val;
549 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT), 451 if (do_write)
550}; 452 snd_hda_codec_write(codec, codec->afg, 0,
551static const unsigned long stac9205_capsws[] = { 453 AC_VERB_IDT_SET_POWER_MAP, val);
552 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT), 454 }
553 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT), 455}
554};
555 456
556static const hda_nid_t stac9200_pin_nids[8] = { 457/* update power bit per jack plug/unplug */
557 0x08, 0x09, 0x0d, 0x0e, 458static void jack_update_power(struct hda_codec *codec,
558 0x0f, 0x10, 0x11, 0x12, 459 struct hda_jack_tbl *jack)
559}; 460{
461 struct sigmatel_spec *spec = codec->spec;
462 int i;
560 463
561static const hda_nid_t stac925x_pin_nids[8] = { 464 if (!spec->num_pwrs)
562 0x07, 0x08, 0x0a, 0x0b, 465 return;
563 0x0c, 0x0d, 0x10, 0x11,
564};
565 466
566static const hda_nid_t stac922x_pin_nids[10] = { 467 if (jack && jack->nid) {
567 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 468 stac_toggle_power_map(codec, jack->nid,
568 0x0f, 0x10, 0x11, 0x15, 0x1b, 469 snd_hda_jack_detect(codec, jack->nid),
569}; 470 true);
471 return;
472 }
570 473
571static const hda_nid_t stac92hd73xx_pin_nids[13] = { 474 /* update all jacks */
572 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 475 for (i = 0; i < spec->num_pwrs; i++) {
573 0x0f, 0x10, 0x11, 0x12, 0x13, 476 hda_nid_t nid = spec->pwr_nids[i];
574 0x14, 0x22, 0x23 477 jack = snd_hda_jack_tbl_get(codec, nid);
575}; 478 if (!jack || !jack->action)
479 continue;
480 if (jack->action == STAC_PWR_EVENT ||
481 jack->action <= HDA_GEN_LAST_EVENT)
482 stac_toggle_power_map(codec, nid,
483 snd_hda_jack_detect(codec, nid),
484 false);
485 }
576 486
577#define STAC92HD71BXX_NUM_PINS 13 487 snd_hda_codec_write(codec, codec->afg, 0, AC_VERB_IDT_SET_POWER_MAP,
578static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = { 488 spec->power_map_bits);
579 0x0a, 0x0b, 0x0c, 0x0d, 0x00, 489}
580 0x00, 0x14, 0x18, 0x19, 0x1e,
581 0x1f, 0x20, 0x27
582};
583static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
584 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
585 0x0f, 0x14, 0x18, 0x19, 0x1e,
586 0x1f, 0x20, 0x27
587};
588 490
589static const hda_nid_t stac927x_pin_nids[14] = { 491static void stac_hp_automute(struct hda_codec *codec,
590 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 492 struct hda_jack_tbl *jack)
591 0x0f, 0x10, 0x11, 0x12, 0x13, 493{
592 0x14, 0x21, 0x22, 0x23, 494 snd_hda_gen_hp_automute(codec, jack);
593}; 495 jack_update_power(codec, jack);
496}
594 497
595static const hda_nid_t stac9205_pin_nids[12] = { 498static void stac_line_automute(struct hda_codec *codec,
596 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 499 struct hda_jack_tbl *jack)
597 0x0f, 0x14, 0x16, 0x17, 0x18, 500{
598 0x21, 0x22, 501 snd_hda_gen_line_automute(codec, jack);
599}; 502 jack_update_power(codec, jack);
503}
600 504
601static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol, 505static void stac_mic_autoswitch(struct hda_codec *codec,
602 struct snd_ctl_elem_info *uinfo) 506 struct hda_jack_tbl *jack)
603{ 507{
604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 508 snd_hda_gen_mic_autoswitch(codec, jack);
605 struct sigmatel_spec *spec = codec->spec; 509 jack_update_power(codec, jack);
606 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
607} 510}
608 511
609static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol, 512static void stac_vref_event(struct hda_codec *codec, struct hda_jack_tbl *event)
610 struct snd_ctl_elem_value *ucontrol)
611{ 513{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 514 unsigned int data;
613 struct sigmatel_spec *spec = codec->spec;
614 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
615 515
616 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx]; 516 data = snd_hda_codec_read(codec, codec->afg, 0,
617 return 0; 517 AC_VERB_GET_GPIO_DATA, 0);
518 /* toggle VREF state based on GPIOx status */
519 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
520 !!(data & (1 << event->private_data)));
618} 521}
619 522
620static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol, 523/* initialize the power map and enable the power event to jacks that
621 struct snd_ctl_elem_value *ucontrol) 524 * haven't been assigned to automute
525 */
526static void stac_init_power_map(struct hda_codec *codec)
622{ 527{
623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
624 struct sigmatel_spec *spec = codec->spec; 528 struct sigmatel_spec *spec = codec->spec;
625 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 529 int i;
626 530
627 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol, 531 for (i = 0; i < spec->num_pwrs; i++) {
628 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]); 532 hda_nid_t nid = spec->pwr_nids[i];
533 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
534 def_conf = get_defcfg_connect(def_conf);
535 if (snd_hda_jack_tbl_get(codec, nid))
536 continue;
537 if (def_conf == AC_JACK_PORT_COMPLEX &&
538 !(spec->vref_mute_led_nid == nid ||
539 is_jack_detectable(codec, nid))) {
540 snd_hda_jack_detect_enable_callback(codec, nid,
541 STAC_PWR_EVENT,
542 jack_update_power);
543 } else {
544 if (def_conf == AC_JACK_PORT_NONE)
545 stac_toggle_power_map(codec, nid, false, false);
546 else
547 stac_toggle_power_map(codec, nid, true, false);
548 }
549 }
629} 550}
630 551
631static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol, 552/*
632 struct snd_ctl_elem_info *uinfo) 553 */
554
555static inline bool get_int_hint(struct hda_codec *codec, const char *key,
556 int *valp)
633{ 557{
634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 558 return !snd_hda_get_int_hint(codec, key, valp);
635 struct sigmatel_spec *spec = codec->spec;
636 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
637} 559}
638 560
639static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol, 561/* override some hints from the hwdep entry */
640 struct snd_ctl_elem_value *ucontrol) 562static void stac_store_hints(struct hda_codec *codec)
641{ 563{
642 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
643 struct sigmatel_spec *spec = codec->spec; 564 struct sigmatel_spec *spec = codec->spec;
644 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 565 int val;
645 566
646 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx]; 567 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
647 return 0; 568 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
569 spec->gpio_mask;
570 }
571 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
572 spec->gpio_mask &= spec->gpio_mask;
573 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
574 spec->gpio_dir &= spec->gpio_mask;
575 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
576 spec->eapd_mask &= spec->gpio_mask;
577 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
578 spec->gpio_mute &= spec->gpio_mask;
579 val = snd_hda_get_bool_hint(codec, "eapd_switch");
580 if (val >= 0)
581 spec->eapd_switch = val;
648} 582}
649 583
650static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol, 584/*
651 struct snd_ctl_elem_value *ucontrol) 585 * loopback controls
586 */
587
588#define stac_aloopback_info snd_ctl_boolean_mono_info
589
590static int stac_aloopback_get(struct snd_kcontrol *kcontrol,
591 struct snd_ctl_elem_value *ucontrol)
652{ 592{
653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 593 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
594 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
654 struct sigmatel_spec *spec = codec->spec; 595 struct sigmatel_spec *spec = codec->spec;
655 struct hda_input_mux *smux = &spec->private_smux;
656 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
657 int err, val;
658 hda_nid_t nid;
659
660 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
661 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
662 if (err < 0)
663 return err;
664 596
665 if (spec->spdif_mute) { 597 ucontrol->value.integer.value[0] = !!(spec->aloopback &
666 if (smux_idx == 0) 598 (spec->aloopback_mask << idx));
667 nid = spec->multiout.dig_out_nid;
668 else
669 nid = codec->slave_dig_outs[smux_idx - 1];
670 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
671 val = HDA_AMP_MUTE;
672 else
673 val = 0;
674 /* un/mute SPDIF out */
675 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
676 HDA_AMP_MUTE, val);
677 }
678 return 0; 599 return 0;
679} 600}
680 601
681static int stac_vrefout_set(struct hda_codec *codec, 602static int stac_aloopback_put(struct snd_kcontrol *kcontrol,
682 hda_nid_t nid, unsigned int new_vref) 603 struct snd_ctl_elem_value *ucontrol)
683{ 604{
684 int error, pinctl; 605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606 struct sigmatel_spec *spec = codec->spec;
607 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
608 unsigned int dac_mode;
609 unsigned int val, idx_val;
685 610
686 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref); 611 idx_val = spec->aloopback_mask << idx;
687 pinctl = snd_hda_codec_read(codec, nid, 0, 612 if (ucontrol->value.integer.value[0])
688 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 613 val = spec->aloopback | idx_val;
614 else
615 val = spec->aloopback & ~idx_val;
616 if (spec->aloopback == val)
617 return 0;
689 618
690 if (pinctl < 0) 619 spec->aloopback = val;
691 return pinctl;
692 620
693 pinctl &= 0xff; 621 /* Only return the bits defined by the shift value of the
694 pinctl &= ~AC_PINCTL_VREFEN; 622 * first two bytes of the mask
695 pinctl |= (new_vref & AC_PINCTL_VREFEN); 623 */
624 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
625 kcontrol->private_value & 0xFFFF, 0x0);
626 dac_mode >>= spec->aloopback_shift;
696 627
697 error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl); 628 if (spec->aloopback & idx_val) {
698 if (error < 0) 629 snd_hda_power_up(codec);
699 return error; 630 dac_mode |= idx_val;
631 } else {
632 snd_hda_power_down(codec);
633 dac_mode &= ~idx_val;
634 }
635
636 snd_hda_codec_write_cache(codec, codec->afg, 0,
637 kcontrol->private_value >> 16, dac_mode);
700 638
701 return 1; 639 return 1;
702} 640}
703 641
704static unsigned int stac92xx_vref_set(struct hda_codec *codec, 642#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
705 hda_nid_t nid, unsigned int new_vref) 643 { \
644 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
645 .name = "Analog Loopback", \
646 .count = cnt, \
647 .info = stac_aloopback_info, \
648 .get = stac_aloopback_get, \
649 .put = stac_aloopback_put, \
650 .private_value = verb_read | (verb_write << 16), \
651 }
652
653/*
654 * Mute LED handling on HP laptops
655 */
656
657/* check whether it's a HP laptop with a docking port */
658static bool hp_bnb2011_with_dock(struct hda_codec *codec)
706{ 659{
707 int error; 660 if (codec->vendor_id != 0x111d7605 &&
708 unsigned int pincfg; 661 codec->vendor_id != 0x111d76d1)
709 pincfg = snd_hda_codec_read(codec, nid, 0, 662 return false;
710 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
711 663
712 pincfg &= 0xff; 664 switch (codec->subsystem_id) {
713 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); 665 case 0x103c1618:
714 pincfg |= new_vref; 666 case 0x103c1619:
667 case 0x103c161a:
668 case 0x103c161b:
669 case 0x103c161c:
670 case 0x103c161d:
671 case 0x103c161e:
672 case 0x103c161f:
715 673
716 if (new_vref == AC_PINCTL_VREF_HIZ) 674 case 0x103c162a:
717 pincfg |= AC_PINCTL_OUT_EN; 675 case 0x103c162b:
718 else
719 pincfg |= AC_PINCTL_IN_EN;
720 676
721 error = snd_hda_set_pin_ctl_cache(codec, nid, pincfg); 677 case 0x103c1630:
722 if (error < 0) 678 case 0x103c1631:
723 return error; 679
724 else 680 case 0x103c1633:
725 return 1; 681 case 0x103c1634:
682 case 0x103c1635:
683
684 case 0x103c3587:
685 case 0x103c3588:
686 case 0x103c3589:
687 case 0x103c358a:
688
689 case 0x103c3667:
690 case 0x103c3668:
691 case 0x103c3669:
692
693 return true;
694 }
695 return false;
726} 696}
727 697
728static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid) 698static bool hp_blike_system(u32 subsystem_id)
729{ 699{
730 unsigned int vref; 700 switch (subsystem_id) {
731 vref = snd_hda_codec_read(codec, nid, 0, 701 case 0x103c1520:
732 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 702 case 0x103c1521:
733 vref &= AC_PINCTL_VREFEN; 703 case 0x103c1523:
734 return vref; 704 case 0x103c1524:
705 case 0x103c1525:
706 case 0x103c1722:
707 case 0x103c1723:
708 case 0x103c1724:
709 case 0x103c1725:
710 case 0x103c1726:
711 case 0x103c1727:
712 case 0x103c1728:
713 case 0x103c1729:
714 case 0x103c172a:
715 case 0x103c172b:
716 case 0x103c307e:
717 case 0x103c307f:
718 case 0x103c3080:
719 case 0x103c3081:
720 case 0x103c7007:
721 case 0x103c7008:
722 return true;
723 }
724 return false;
735} 725}
736 726
737static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 727static void set_hp_led_gpio(struct hda_codec *codec)
738{ 728{
739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
740 struct sigmatel_spec *spec = codec->spec; 729 struct sigmatel_spec *spec = codec->spec;
741 return snd_hda_input_mux_info(spec->input_mux, uinfo); 730 unsigned int gpio;
731
732 if (spec->gpio_led)
733 return;
734
735 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
736 gpio &= AC_GPIO_IO_COUNT;
737 if (gpio > 3)
738 spec->gpio_led = 0x08; /* GPIO 3 */
739 else
740 spec->gpio_led = 0x01; /* GPIO 0 */
742} 741}
743 742
744static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 743/*
744 * This method searches for the mute LED GPIO configuration
745 * provided as OEM string in SMBIOS. The format of that string
746 * is HP_Mute_LED_P_G or HP_Mute_LED_P
747 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
748 * that corresponds to the NOT muted state of the master volume
749 * and G is the index of the GPIO to use as the mute LED control (0..9)
750 * If _G portion is missing it is assigned based on the codec ID
751 *
752 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
753 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
754 *
755 *
756 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
757 * SMBIOS - at least the ones I have seen do not have them - which include
758 * my own system (HP Pavilion dv6-1110ax) and my cousin's
759 * HP Pavilion dv9500t CTO.
760 * Need more information on whether it is true across the entire series.
761 * -- kunal
762 */
763static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
745{ 764{
746 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
747 struct sigmatel_spec *spec = codec->spec; 765 struct sigmatel_spec *spec = codec->spec;
748 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 766 const struct dmi_device *dev = NULL;
749 767
750 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 768 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
769 get_int_hint(codec, "gpio_led_polarity",
770 &spec->gpio_led_polarity);
771 return 1;
772 }
773
774 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
775 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
776 &spec->gpio_led_polarity,
777 &spec->gpio_led) == 2) {
778 unsigned int max_gpio;
779 max_gpio = snd_hda_param_read(codec, codec->afg,
780 AC_PAR_GPIO_CAP);
781 max_gpio &= AC_GPIO_IO_COUNT;
782 if (spec->gpio_led < max_gpio)
783 spec->gpio_led = 1 << spec->gpio_led;
784 else
785 spec->vref_mute_led_nid = spec->gpio_led;
786 return 1;
787 }
788 if (sscanf(dev->name, "HP_Mute_LED_%d",
789 &spec->gpio_led_polarity) == 1) {
790 set_hp_led_gpio(codec);
791 return 1;
792 }
793 /* BIOS bug: unfilled OEM string */
794 if (strstr(dev->name, "HP_Mute_LED_P_G")) {
795 set_hp_led_gpio(codec);
796 if (default_polarity >= 0)
797 spec->gpio_led_polarity = default_polarity;
798 else
799 spec->gpio_led_polarity = 1;
800 return 1;
801 }
802 }
803
804 /*
805 * Fallback case - if we don't find the DMI strings,
806 * we statically set the GPIO - if not a B-series system
807 * and default polarity is provided
808 */
809 if (!hp_blike_system(codec->subsystem_id) &&
810 (default_polarity == 0 || default_polarity == 1)) {
811 set_hp_led_gpio(codec);
812 spec->gpio_led_polarity = default_polarity;
813 return 1;
814 }
751 return 0; 815 return 0;
752} 816}
753 817
754static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 818/*
819 * PC beep controls
820 */
821
822/* create PC beep volume controls */
823static int stac_auto_create_beep_ctls(struct hda_codec *codec,
824 hda_nid_t nid)
755{ 825{
756 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
757 struct sigmatel_spec *spec = codec->spec; 826 struct sigmatel_spec *spec = codec->spec;
758 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 827 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
759 const struct hda_input_mux *imux = spec->input_mux; 828 struct snd_kcontrol_new *knew;
760 unsigned int idx, prev_idx, didx; 829 static struct snd_kcontrol_new abeep_mute_ctl =
761 830 HDA_CODEC_MUTE(NULL, 0, 0, 0);
762 idx = ucontrol->value.enumerated.item[0]; 831 static struct snd_kcontrol_new dbeep_mute_ctl =
763 if (idx >= imux->num_items) 832 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0);
764 idx = imux->num_items - 1; 833 static struct snd_kcontrol_new beep_vol_ctl =
765 prev_idx = spec->cur_mux[adc_idx]; 834 HDA_CODEC_VOLUME(NULL, 0, 0, 0);
766 if (prev_idx == idx) 835
767 return 0; 836 /* check for mute support for the the amp */
768 if (idx < spec->num_analog_muxes) { 837 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
769 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0, 838 const struct snd_kcontrol_new *temp;
770 AC_VERB_SET_CONNECT_SEL, 839 if (spec->anabeep_nid == nid)
771 imux->items[idx].index); 840 temp = &abeep_mute_ctl;
772 if (prev_idx >= spec->num_analog_muxes && 841 else
773 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) { 842 temp = &dbeep_mute_ctl;
774 imux = spec->dinput_mux; 843 knew = snd_hda_gen_add_kctl(&spec->gen,
775 /* 0 = analog */ 844 "Beep Playback Switch", temp);
776 snd_hda_codec_write_cache(codec, 845 if (!knew)
777 spec->dmux_nids[adc_idx], 0, 846 return -ENOMEM;
778 AC_VERB_SET_CONNECT_SEL, 847 knew->private_value =
779 imux->items[0].index); 848 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT);
780 }
781 } else {
782 imux = spec->dinput_mux;
783 /* first dimux item is hardcoded to select analog imux,
784 * so lets skip it
785 */
786 didx = idx - spec->num_analog_muxes + 1;
787 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
788 AC_VERB_SET_CONNECT_SEL,
789 imux->items[didx].index);
790 } 849 }
791 spec->cur_mux[adc_idx] = idx; 850
792 return 1; 851 /* check to see if there is volume support for the amp */
852 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
853 knew = snd_hda_gen_add_kctl(&spec->gen,
854 "Beep Playback Volume",
855 &beep_vol_ctl);
856 if (!knew)
857 return -ENOMEM;
858 knew->private_value =
859 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT);
860 }
861 return 0;
793} 862}
794 863
795static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol, 864#ifdef CONFIG_SND_HDA_INPUT_BEEP
796 struct snd_ctl_elem_info *uinfo) 865#define stac_dig_beep_switch_info snd_ctl_boolean_mono_info
866
867static int stac_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
868 struct snd_ctl_elem_value *ucontrol)
797{ 869{
798 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 870 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
799 struct sigmatel_spec *spec = codec->spec; 871 ucontrol->value.integer.value[0] = codec->beep->enabled;
800 return snd_hda_input_mux_info(spec->mono_mux, uinfo); 872 return 0;
801} 873}
802 874
803static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol, 875static int stac_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
804 struct snd_ctl_elem_value *ucontrol) 876 struct snd_ctl_elem_value *ucontrol)
805{ 877{
806 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
879 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
880}
881
882static const struct snd_kcontrol_new stac_dig_beep_ctrl = {
883 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
884 .name = "Beep Playback Switch",
885 .info = stac_dig_beep_switch_info,
886 .get = stac_dig_beep_switch_get,
887 .put = stac_dig_beep_switch_put,
888};
889
890static int stac_beep_switch_ctl(struct hda_codec *codec)
891{
807 struct sigmatel_spec *spec = codec->spec; 892 struct sigmatel_spec *spec = codec->spec;
808 893
809 ucontrol->value.enumerated.item[0] = spec->cur_mmux; 894 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &stac_dig_beep_ctrl))
895 return -ENOMEM;
810 return 0; 896 return 0;
811} 897}
898#endif
899
900/*
901 * SPDIF-out mux controls
902 */
812 903
813static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol, 904static int stac_smux_enum_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_value *ucontrol) 905 struct snd_ctl_elem_info *uinfo)
815{ 906{
816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 907 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct sigmatel_spec *spec = codec->spec; 908 struct sigmatel_spec *spec = codec->spec;
818 909 return snd_hda_input_mux_info(&spec->spdif_mux, uinfo);
819 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
820 spec->mono_nid, &spec->cur_mmux);
821} 910}
822 911
823#define stac92xx_aloopback_info snd_ctl_boolean_mono_info 912static int stac_smux_enum_get(struct snd_kcontrol *kcontrol,
824 913 struct snd_ctl_elem_value *ucontrol)
825static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
826 struct snd_ctl_elem_value *ucontrol)
827{ 914{
828 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 915 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
829 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
830 struct sigmatel_spec *spec = codec->spec; 916 struct sigmatel_spec *spec = codec->spec;
917 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
831 918
832 ucontrol->value.integer.value[0] = !!(spec->aloopback & 919 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
833 (spec->aloopback_mask << idx));
834 return 0; 920 return 0;
835} 921}
836 922
837static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol, 923static int stac_smux_enum_put(struct snd_kcontrol *kcontrol,
838 struct snd_ctl_elem_value *ucontrol) 924 struct snd_ctl_elem_value *ucontrol)
839{ 925{
840 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 926 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
841 struct sigmatel_spec *spec = codec->spec; 927 struct sigmatel_spec *spec = codec->spec;
842 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 928 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
843 unsigned int dac_mode;
844 unsigned int val, idx_val;
845 929
846 idx_val = spec->aloopback_mask << idx; 930 return snd_hda_input_mux_put(codec, &spec->spdif_mux, ucontrol,
847 if (ucontrol->value.integer.value[0]) 931 spec->gen.autocfg.dig_out_pins[smux_idx],
848 val = spec->aloopback | idx_val; 932 &spec->cur_smux[smux_idx]);
849 else 933}
850 val = spec->aloopback & ~idx_val;
851 if (spec->aloopback == val)
852 return 0;
853 934
854 spec->aloopback = val; 935static struct snd_kcontrol_new stac_smux_mixer = {
936 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
937 .name = "IEC958 Playback Source",
938 /* count set later */
939 .info = stac_smux_enum_info,
940 .get = stac_smux_enum_get,
941 .put = stac_smux_enum_put,
942};
855 943
856 /* Only return the bits defined by the shift value of the 944static const char * const stac_spdif_labels[] = {
857 * first two bytes of the mask 945 "Digital Playback", "Analog Mux 1", "Analog Mux 2", NULL
858 */ 946};
859 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
860 kcontrol->private_value & 0xFFFF, 0x0);
861 dac_mode >>= spec->aloopback_shift;
862 947
863 if (spec->aloopback & idx_val) { 948static int stac_create_spdif_mux_ctls(struct hda_codec *codec)
864 snd_hda_power_up(codec); 949{
865 dac_mode |= idx_val; 950 struct sigmatel_spec *spec = codec->spec;
866 } else { 951 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
867 snd_hda_power_down(codec); 952 const char * const *labels = spec->spdif_labels;
868 dac_mode &= ~idx_val; 953 struct snd_kcontrol_new *kctl;
954 int i, num_cons;
955
956 if (cfg->dig_outs < 1)
957 return 0;
958
959 num_cons = snd_hda_get_num_conns(codec, cfg->dig_out_pins[0]);
960 if (num_cons <= 1)
961 return 0;
962
963 if (!labels)
964 labels = stac_spdif_labels;
965 for (i = 0; i < num_cons; i++) {
966 if (snd_BUG_ON(!labels[i]))
967 return -EINVAL;
968 snd_hda_add_imux_item(&spec->spdif_mux, labels[i], i, NULL);
869 } 969 }
870 970
871 snd_hda_codec_write_cache(codec, codec->afg, 0, 971 kctl = snd_hda_gen_add_kctl(&spec->gen, NULL, &stac_smux_mixer);
872 kcontrol->private_value >> 16, dac_mode); 972 if (!kctl)
973 return -ENOMEM;
974 kctl->count = cfg->dig_outs;
873 975
874 return 1; 976 return 0;
875} 977}
876 978
979/*
980 */
981
877static const struct hda_verb stac9200_core_init[] = { 982static const struct hda_verb stac9200_core_init[] = {
878 /* set dac0mux for dac converter */ 983 /* set dac0mux for dac converter */
879 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00}, 984 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -936,17 +1041,15 @@ static const struct hda_verb stac925x_core_init[] = {
936}; 1041};
937 1042
938static const struct hda_verb stac922x_core_init[] = { 1043static const struct hda_verb stac922x_core_init[] = {
939 /* set master volume and direct control */ 1044 /* set master volume and direct control */
940 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 1045 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
941 {} 1046 {}
942}; 1047};
943 1048
944static const struct hda_verb d965_core_init[] = { 1049static const struct hda_verb d965_core_init[] = {
945 /* set master volume and direct control */
946 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
947 /* unmute node 0x1b */ 1050 /* unmute node 0x1b */
948 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 1051 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
949 /* select node 0x03 as DAC */ 1052 /* select node 0x03 as DAC */
950 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01}, 1053 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
951 {} 1054 {}
952}; 1055};
@@ -962,7 +1065,7 @@ static const struct hda_verb dell_3st_core_init[] = {
962}; 1065};
963 1066
964static const struct hda_verb stac927x_core_init[] = { 1067static const struct hda_verb stac927x_core_init[] = {
965 /* set master volume and direct control */ 1068 /* set master volume and direct control */
966 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 1069 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
967 /* enable analog pc beep path */ 1070 /* enable analog pc beep path */
968 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5}, 1071 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
@@ -978,261 +1081,103 @@ static const struct hda_verb stac927x_volknob_core_init[] = {
978}; 1081};
979 1082
980static const struct hda_verb stac9205_core_init[] = { 1083static const struct hda_verb stac9205_core_init[] = {
981 /* set master volume and direct control */ 1084 /* set master volume and direct control */
982 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 1085 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
983 /* enable analog pc beep path */ 1086 /* enable analog pc beep path */
984 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5}, 1087 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
985 {} 1088 {}
986}; 1089};
987 1090
988#define STAC_MONO_MUX \ 1091static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback =
989 { \ 1092 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3);
990 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
991 .name = "Mono Mux", \
992 .count = 1, \
993 .info = stac92xx_mono_mux_enum_info, \
994 .get = stac92xx_mono_mux_enum_get, \
995 .put = stac92xx_mono_mux_enum_put, \
996 }
997 1093
998#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \ 1094static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback =
999 { \ 1095 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4);
1000 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1001 .name = "Analog Loopback", \
1002 .count = cnt, \
1003 .info = stac92xx_aloopback_info, \
1004 .get = stac92xx_aloopback_get, \
1005 .put = stac92xx_aloopback_put, \
1006 .private_value = verb_read | (verb_write << 16), \
1007 }
1008 1096
1009#define DC_BIAS(xname, idx, nid) \ 1097static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback =
1010 { \ 1098 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5);
1011 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1012 .name = xname, \
1013 .index = idx, \
1014 .info = stac92xx_dc_bias_info, \
1015 .get = stac92xx_dc_bias_get, \
1016 .put = stac92xx_dc_bias_put, \
1017 .private_value = nid, \
1018 }
1019 1099
1020static const struct snd_kcontrol_new stac9200_mixer[] = { 1100static const struct snd_kcontrol_new stac92hd71bxx_loopback =
1021 HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xb, 0, HDA_OUTPUT), 1101 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2);
1022 HDA_CODEC_MUTE("PCM Playback Switch", 0xb, 0, HDA_OUTPUT),
1023 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1024 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1025 { } /* end */
1026};
1027 1102
1028static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = { 1103static const struct snd_kcontrol_new stac9205_loopback =
1029 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3), 1104 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1);
1030 {}
1031};
1032 1105
1033static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = { 1106static const struct snd_kcontrol_new stac927x_loopback =
1034 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4), 1107 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1);
1035 {}
1036};
1037 1108
1038static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = { 1109static const struct hda_pintbl ref9200_pin_configs[] = {
1039 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5), 1110 { 0x08, 0x01c47010 },
1111 { 0x09, 0x01447010 },
1112 { 0x0d, 0x0221401f },
1113 { 0x0e, 0x01114010 },
1114 { 0x0f, 0x02a19020 },
1115 { 0x10, 0x01a19021 },
1116 { 0x11, 0x90100140 },
1117 { 0x12, 0x01813122 },
1040 {} 1118 {}
1041}; 1119};
1042 1120
1043 1121static const struct hda_pintbl gateway9200_m4_pin_configs[] = {
1044static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = { 1122 { 0x08, 0x400000fe },
1045 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2) 1123 { 0x09, 0x404500f4 },
1046}; 1124 { 0x0d, 0x400100f0 },
1047 1125 { 0x0e, 0x90110010 },
1048static const struct snd_kcontrol_new stac925x_mixer[] = { 1126 { 0x0f, 0x400100f1 },
1049 HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xe, 0, HDA_OUTPUT), 1127 { 0x10, 0x02a1902e },
1050 HDA_CODEC_MUTE("PCM Playback Switch", 0x0e, 0, HDA_OUTPUT), 1128 { 0x11, 0x500000f2 },
1051 { } /* end */ 1129 { 0x12, 0x500000f3 },
1052};
1053
1054static const struct snd_kcontrol_new stac9205_loopback[] = {
1055 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1056 {} 1130 {}
1057}; 1131};
1058 1132
1059static const struct snd_kcontrol_new stac927x_loopback[] = { 1133static const struct hda_pintbl gateway9200_m4_2_pin_configs[] = {
1060 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1), 1134 { 0x08, 0x400000fe },
1135 { 0x09, 0x404500f4 },
1136 { 0x0d, 0x400100f0 },
1137 { 0x0e, 0x90110010 },
1138 { 0x0f, 0x400100f1 },
1139 { 0x10, 0x02a1902e },
1140 { 0x11, 0x500000f2 },
1141 { 0x12, 0x500000f3 },
1061 {} 1142 {}
1062}; 1143};
1063 1144
1064static struct snd_kcontrol_new stac_dmux_mixer = {
1065 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1066 .name = "Digital Input Source",
1067 /* count set later */
1068 .info = stac92xx_dmux_enum_info,
1069 .get = stac92xx_dmux_enum_get,
1070 .put = stac92xx_dmux_enum_put,
1071};
1072
1073static struct snd_kcontrol_new stac_smux_mixer = {
1074 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1075 .name = "IEC958 Playback Source",
1076 /* count set later */
1077 .info = stac92xx_smux_enum_info,
1078 .get = stac92xx_smux_enum_get,
1079 .put = stac92xx_smux_enum_put,
1080};
1081
1082static const char * const slave_pfxs[] = {
1083 "Front", "Surround", "Center", "LFE", "Side",
1084 "Headphone", "Speaker", "Bass Speaker", "IEC958", "PCM",
1085 NULL
1086};
1087
1088static void stac92xx_update_led_status(struct hda_codec *codec, int enabled);
1089
1090static void stac92xx_vmaster_hook(void *private_data, int val)
1091{
1092 stac92xx_update_led_status(private_data, val);
1093}
1094
1095static void stac92xx_free_kctls(struct hda_codec *codec);
1096
1097static int stac92xx_build_controls(struct hda_codec *codec)
1098{
1099 struct sigmatel_spec *spec = codec->spec;
1100 unsigned int vmaster_tlv[4];
1101 int err;
1102 int i;
1103
1104 if (spec->mixer) {
1105 err = snd_hda_add_new_ctls(codec, spec->mixer);
1106 if (err < 0)
1107 return err;
1108 }
1109
1110 for (i = 0; i < spec->num_mixers; i++) {
1111 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1112 if (err < 0)
1113 return err;
1114 }
1115 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1116 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1117 stac_dmux_mixer.count = spec->num_dmuxes;
1118 err = snd_hda_ctl_add(codec, 0,
1119 snd_ctl_new1(&stac_dmux_mixer, codec));
1120 if (err < 0)
1121 return err;
1122 }
1123 if (spec->num_smuxes > 0) {
1124 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1125 struct hda_input_mux *smux = &spec->private_smux;
1126 /* check for mute support on SPDIF out */
1127 if (wcaps & AC_WCAP_OUT_AMP) {
1128 snd_hda_add_imux_item(smux, "Off", 0, NULL);
1129 spec->spdif_mute = 1;
1130 }
1131 stac_smux_mixer.count = spec->num_smuxes;
1132 err = snd_hda_ctl_add(codec, 0,
1133 snd_ctl_new1(&stac_smux_mixer, codec));
1134 if (err < 0)
1135 return err;
1136 }
1137
1138 if (spec->multiout.dig_out_nid) {
1139 err = snd_hda_create_dig_out_ctls(codec,
1140 spec->multiout.dig_out_nid,
1141 spec->multiout.dig_out_nid,
1142 spec->autocfg.dig_out_type[0]);
1143 if (err < 0)
1144 return err;
1145 err = snd_hda_create_spdif_share_sw(codec,
1146 &spec->multiout);
1147 if (err < 0)
1148 return err;
1149 spec->multiout.share_spdif = 1;
1150 }
1151 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1152 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1153 if (err < 0)
1154 return err;
1155 }
1156
1157 /* if we have no master control, let's create it */
1158 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1159 HDA_OUTPUT, vmaster_tlv);
1160 /* correct volume offset */
1161 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1162 /* minimum value is actually mute */
1163 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
1164 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1165 vmaster_tlv, slave_pfxs,
1166 "Playback Volume");
1167 if (err < 0)
1168 return err;
1169
1170 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1171 NULL, slave_pfxs,
1172 "Playback Switch", true,
1173 &spec->vmaster_mute.sw_kctl);
1174 if (err < 0)
1175 return err;
1176
1177 if (spec->gpio_led) {
1178 spec->vmaster_mute.hook = stac92xx_vmaster_hook;
1179 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
1180 if (err < 0)
1181 return err;
1182 }
1183
1184 if (spec->aloopback_ctl &&
1185 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1186 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1187 if (err < 0)
1188 return err;
1189 }
1190
1191 stac92xx_free_kctls(codec); /* no longer needed */
1192
1193 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1194 if (err < 0)
1195 return err;
1196
1197 return 0;
1198}
1199
1200static const unsigned int ref9200_pin_configs[8] = {
1201 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1202 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1203};
1204
1205static const unsigned int gateway9200_m4_pin_configs[8] = {
1206 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1207 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1208};
1209static const unsigned int gateway9200_m4_2_pin_configs[8] = {
1210 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1211 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1212};
1213
1214/* 1145/*
1215 STAC 9200 pin configs for 1146 STAC 9200 pin configs for
1216 102801A8 1147 102801A8
1217 102801DE 1148 102801DE
1218 102801E8 1149 102801E8
1219*/ 1150*/
1220static const unsigned int dell9200_d21_pin_configs[8] = { 1151static const struct hda_pintbl dell9200_d21_pin_configs[] = {
1221 0x400001f0, 0x400001f1, 0x02214030, 0x01014010, 1152 { 0x08, 0x400001f0 },
1222 0x02a19020, 0x01a19021, 0x90100140, 0x01813122, 1153 { 0x09, 0x400001f1 },
1154 { 0x0d, 0x02214030 },
1155 { 0x0e, 0x01014010 },
1156 { 0x0f, 0x02a19020 },
1157 { 0x10, 0x01a19021 },
1158 { 0x11, 0x90100140 },
1159 { 0x12, 0x01813122 },
1160 {}
1223}; 1161};
1224 1162
1225/* 1163/*
1226 STAC 9200 pin configs for 1164 STAC 9200 pin configs for
1227 102801C0 1165 102801C0
1228 102801C1 1166 102801C1
1229*/ 1167*/
1230static const unsigned int dell9200_d22_pin_configs[8] = { 1168static const struct hda_pintbl dell9200_d22_pin_configs[] = {
1231 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 1169 { 0x08, 0x400001f0 },
1232 0x01813020, 0x02a19021, 0x90100140, 0x400001f2, 1170 { 0x09, 0x400001f1 },
1171 { 0x0d, 0x0221401f },
1172 { 0x0e, 0x01014010 },
1173 { 0x0f, 0x01813020 },
1174 { 0x10, 0x02a19021 },
1175 { 0x11, 0x90100140 },
1176 { 0x12, 0x400001f2 },
1177 {}
1233}; 1178};
1234 1179
1235/* 1180/*
1236 STAC 9200 pin configs for 1181 STAC 9200 pin configs for
1237 102801C4 (Dell Dimension E310) 1182 102801C4 (Dell Dimension E310)
1238 102801C5 1183 102801C5
@@ -1241,9 +1186,16 @@ static const unsigned int dell9200_d22_pin_configs[8] = {
1241 102801DA 1186 102801DA
1242 102801E3 1187 102801E3
1243*/ 1188*/
1244static const unsigned int dell9200_d23_pin_configs[8] = { 1189static const struct hda_pintbl dell9200_d23_pin_configs[] = {
1245 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 1190 { 0x08, 0x400001f0 },
1246 0x01813020, 0x01a19021, 0x90100140, 0x400001f2, 1191 { 0x09, 0x400001f1 },
1192 { 0x0d, 0x0221401f },
1193 { 0x0e, 0x01014010 },
1194 { 0x0f, 0x01813020 },
1195 { 0x10, 0x01a19021 },
1196 { 0x11, 0x90100140 },
1197 { 0x12, 0x400001f2 },
1198 {}
1247}; 1199};
1248 1200
1249 1201
@@ -1252,9 +1204,16 @@ static const unsigned int dell9200_d23_pin_configs[8] = {
1252 102801B5 (Dell Inspiron 630m) 1204 102801B5 (Dell Inspiron 630m)
1253 102801D8 (Dell Inspiron 640m) 1205 102801D8 (Dell Inspiron 640m)
1254*/ 1206*/
1255static const unsigned int dell9200_m21_pin_configs[8] = { 1207static const struct hda_pintbl dell9200_m21_pin_configs[] = {
1256 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310, 1208 { 0x08, 0x40c003fa },
1257 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd, 1209 { 0x09, 0x03441340 },
1210 { 0x0d, 0x0321121f },
1211 { 0x0e, 0x90170310 },
1212 { 0x0f, 0x408003fb },
1213 { 0x10, 0x03a11020 },
1214 { 0x11, 0x401003fc },
1215 { 0x12, 0x403003fd },
1216 {}
1258}; 1217};
1259 1218
1260/* 1219/*
@@ -1265,9 +1224,16 @@ static const unsigned int dell9200_m21_pin_configs[8] = {
1265 102801D4 1224 102801D4
1266 102801D6 1225 102801D6
1267*/ 1226*/
1268static const unsigned int dell9200_m22_pin_configs[8] = { 1227static const struct hda_pintbl dell9200_m22_pin_configs[] = {
1269 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310, 1228 { 0x08, 0x40c003fa },
1270 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc, 1229 { 0x09, 0x0144131f },
1230 { 0x0d, 0x0321121f },
1231 { 0x0e, 0x90170310 },
1232 { 0x0f, 0x90a70321 },
1233 { 0x10, 0x03a11020 },
1234 { 0x11, 0x401003fb },
1235 { 0x12, 0x40f000fc },
1236 {}
1271}; 1237};
1272 1238
1273/* 1239/*
@@ -1275,9 +1241,16 @@ static const unsigned int dell9200_m22_pin_configs[8] = {
1275 102801CE (Dell XPS M1710) 1241 102801CE (Dell XPS M1710)
1276 102801CF (Dell Precision M90) 1242 102801CF (Dell Precision M90)
1277*/ 1243*/
1278static const unsigned int dell9200_m23_pin_configs[8] = { 1244static const struct hda_pintbl dell9200_m23_pin_configs[] = {
1279 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310, 1245 { 0x08, 0x40c003fa },
1280 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc, 1246 { 0x09, 0x01441340 },
1247 { 0x0d, 0x0421421f },
1248 { 0x0e, 0x90170310 },
1249 { 0x0f, 0x408003fb },
1250 { 0x10, 0x04a1102e },
1251 { 0x11, 0x90170311 },
1252 { 0x12, 0x403003fc },
1253 {}
1281}; 1254};
1282 1255
1283/* 1256/*
@@ -1287,9 +1260,16 @@ static const unsigned int dell9200_m23_pin_configs[8] = {
1287 102801CB (Dell Latitude 120L) 1260 102801CB (Dell Latitude 120L)
1288 102801D3 1261 102801D3
1289*/ 1262*/
1290static const unsigned int dell9200_m24_pin_configs[8] = { 1263static const struct hda_pintbl dell9200_m24_pin_configs[] = {
1291 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310, 1264 { 0x08, 0x40c003fa },
1292 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe, 1265 { 0x09, 0x404003fb },
1266 { 0x0d, 0x0321121f },
1267 { 0x0e, 0x90170310 },
1268 { 0x0f, 0x408003fc },
1269 { 0x10, 0x03a11020 },
1270 { 0x11, 0x401003fd },
1271 { 0x12, 0x403003fe },
1272 {}
1293}; 1273};
1294 1274
1295/* 1275/*
@@ -1298,9 +1278,16 @@ static const unsigned int dell9200_m24_pin_configs[8] = {
1298 102801EE 1278 102801EE
1299 102801EF 1279 102801EF
1300*/ 1280*/
1301static const unsigned int dell9200_m25_pin_configs[8] = { 1281static const struct hda_pintbl dell9200_m25_pin_configs[] = {
1302 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310, 1282 { 0x08, 0x40c003fa },
1303 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd, 1283 { 0x09, 0x01441340 },
1284 { 0x0d, 0x0421121f },
1285 { 0x0e, 0x90170310 },
1286 { 0x0f, 0x408003fb },
1287 { 0x10, 0x04a11020 },
1288 { 0x11, 0x401003fc },
1289 { 0x12, 0x403003fd },
1290 {}
1304}; 1291};
1305 1292
1306/* 1293/*
@@ -1308,64 +1295,159 @@ static const unsigned int dell9200_m25_pin_configs[8] = {
1308 102801F5 (Dell Inspiron 1501) 1295 102801F5 (Dell Inspiron 1501)
1309 102801F6 1296 102801F6
1310*/ 1297*/
1311static const unsigned int dell9200_m26_pin_configs[8] = { 1298static const struct hda_pintbl dell9200_m26_pin_configs[] = {
1312 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310, 1299 { 0x08, 0x40c003fa },
1313 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe, 1300 { 0x09, 0x404003fb },
1301 { 0x0d, 0x0421121f },
1302 { 0x0e, 0x90170310 },
1303 { 0x0f, 0x408003fc },
1304 { 0x10, 0x04a11020 },
1305 { 0x11, 0x401003fd },
1306 { 0x12, 0x403003fe },
1307 {}
1314}; 1308};
1315 1309
1316/* 1310/*
1317 STAC 9200-32 1311 STAC 9200-32
1318 102801CD (Dell Inspiron E1705/9400) 1312 102801CD (Dell Inspiron E1705/9400)
1319*/ 1313*/
1320static const unsigned int dell9200_m27_pin_configs[8] = { 1314static const struct hda_pintbl dell9200_m27_pin_configs[] = {
1321 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310, 1315 { 0x08, 0x40c003fa },
1322 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc, 1316 { 0x09, 0x01441340 },
1317 { 0x0d, 0x0421121f },
1318 { 0x0e, 0x90170310 },
1319 { 0x0f, 0x90170310 },
1320 { 0x10, 0x04a11020 },
1321 { 0x11, 0x90170310 },
1322 { 0x12, 0x40f003fc },
1323 {}
1323}; 1324};
1324 1325
1325static const unsigned int oqo9200_pin_configs[8] = { 1326static const struct hda_pintbl oqo9200_pin_configs[] = {
1326 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210, 1327 { 0x08, 0x40c000f0 },
1327 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3, 1328 { 0x09, 0x404000f1 },
1329 { 0x0d, 0x0221121f },
1330 { 0x0e, 0x02211210 },
1331 { 0x0f, 0x90170111 },
1332 { 0x10, 0x90a70120 },
1333 { 0x11, 0x400000f2 },
1334 { 0x12, 0x400000f3 },
1335 {}
1328}; 1336};
1329 1337
1330 1338
1331static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = { 1339static void stac9200_fixup_panasonic(struct hda_codec *codec,
1332 [STAC_REF] = ref9200_pin_configs, 1340 const struct hda_fixup *fix, int action)
1333 [STAC_9200_OQO] = oqo9200_pin_configs, 1341{
1334 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs, 1342 struct sigmatel_spec *spec = codec->spec;
1335 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs, 1343
1336 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs, 1344 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1337 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs, 1345 spec->gpio_mask = spec->gpio_dir = 0x09;
1338 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs, 1346 spec->gpio_data = 0x00;
1339 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs, 1347 /* CF-74 has no headphone detection, and the driver should *NOT*
1340 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs, 1348 * do detection and HP/speaker toggle because the hardware does it.
1341 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs, 1349 */
1342 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs, 1350 spec->gen.suppress_auto_mute = 1;
1343 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs, 1351 }
1344 [STAC_9200_M4] = gateway9200_m4_pin_configs, 1352}
1345 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs, 1353
1346 [STAC_9200_PANASONIC] = ref9200_pin_configs, 1354
1355static const struct hda_fixup stac9200_fixups[] = {
1356 [STAC_REF] = {
1357 .type = HDA_FIXUP_PINS,
1358 .v.pins = ref9200_pin_configs,
1359 },
1360 [STAC_9200_OQO] = {
1361 .type = HDA_FIXUP_PINS,
1362 .v.pins = oqo9200_pin_configs,
1363 .chained = true,
1364 .chain_id = STAC_9200_EAPD_INIT,
1365 },
1366 [STAC_9200_DELL_D21] = {
1367 .type = HDA_FIXUP_PINS,
1368 .v.pins = dell9200_d21_pin_configs,
1369 },
1370 [STAC_9200_DELL_D22] = {
1371 .type = HDA_FIXUP_PINS,
1372 .v.pins = dell9200_d22_pin_configs,
1373 },
1374 [STAC_9200_DELL_D23] = {
1375 .type = HDA_FIXUP_PINS,
1376 .v.pins = dell9200_d23_pin_configs,
1377 },
1378 [STAC_9200_DELL_M21] = {
1379 .type = HDA_FIXUP_PINS,
1380 .v.pins = dell9200_m21_pin_configs,
1381 },
1382 [STAC_9200_DELL_M22] = {
1383 .type = HDA_FIXUP_PINS,
1384 .v.pins = dell9200_m22_pin_configs,
1385 },
1386 [STAC_9200_DELL_M23] = {
1387 .type = HDA_FIXUP_PINS,
1388 .v.pins = dell9200_m23_pin_configs,
1389 },
1390 [STAC_9200_DELL_M24] = {
1391 .type = HDA_FIXUP_PINS,
1392 .v.pins = dell9200_m24_pin_configs,
1393 },
1394 [STAC_9200_DELL_M25] = {
1395 .type = HDA_FIXUP_PINS,
1396 .v.pins = dell9200_m25_pin_configs,
1397 },
1398 [STAC_9200_DELL_M26] = {
1399 .type = HDA_FIXUP_PINS,
1400 .v.pins = dell9200_m26_pin_configs,
1401 },
1402 [STAC_9200_DELL_M27] = {
1403 .type = HDA_FIXUP_PINS,
1404 .v.pins = dell9200_m27_pin_configs,
1405 },
1406 [STAC_9200_M4] = {
1407 .type = HDA_FIXUP_PINS,
1408 .v.pins = gateway9200_m4_pin_configs,
1409 .chained = true,
1410 .chain_id = STAC_9200_EAPD_INIT,
1411 },
1412 [STAC_9200_M4_2] = {
1413 .type = HDA_FIXUP_PINS,
1414 .v.pins = gateway9200_m4_2_pin_configs,
1415 .chained = true,
1416 .chain_id = STAC_9200_EAPD_INIT,
1417 },
1418 [STAC_9200_PANASONIC] = {
1419 .type = HDA_FIXUP_FUNC,
1420 .v.func = stac9200_fixup_panasonic,
1421 },
1422 [STAC_9200_EAPD_INIT] = {
1423 .type = HDA_FIXUP_VERBS,
1424 .v.verbs = (const struct hda_verb[]) {
1425 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1426 {}
1427 },
1428 },
1347}; 1429};
1348 1430
1349static const char * const stac9200_models[STAC_9200_MODELS] = { 1431static const struct hda_model_fixup stac9200_models[] = {
1350 [STAC_AUTO] = "auto", 1432 { .id = STAC_REF, .name = "ref" },
1351 [STAC_REF] = "ref", 1433 { .id = STAC_9200_OQO, .name = "oqo" },
1352 [STAC_9200_OQO] = "oqo", 1434 { .id = STAC_9200_DELL_D21, .name = "dell-d21" },
1353 [STAC_9200_DELL_D21] = "dell-d21", 1435 { .id = STAC_9200_DELL_D22, .name = "dell-d22" },
1354 [STAC_9200_DELL_D22] = "dell-d22", 1436 { .id = STAC_9200_DELL_D23, .name = "dell-d23" },
1355 [STAC_9200_DELL_D23] = "dell-d23", 1437 { .id = STAC_9200_DELL_M21, .name = "dell-m21" },
1356 [STAC_9200_DELL_M21] = "dell-m21", 1438 { .id = STAC_9200_DELL_M22, .name = "dell-m22" },
1357 [STAC_9200_DELL_M22] = "dell-m22", 1439 { .id = STAC_9200_DELL_M23, .name = "dell-m23" },
1358 [STAC_9200_DELL_M23] = "dell-m23", 1440 { .id = STAC_9200_DELL_M24, .name = "dell-m24" },
1359 [STAC_9200_DELL_M24] = "dell-m24", 1441 { .id = STAC_9200_DELL_M25, .name = "dell-m25" },
1360 [STAC_9200_DELL_M25] = "dell-m25", 1442 { .id = STAC_9200_DELL_M26, .name = "dell-m26" },
1361 [STAC_9200_DELL_M26] = "dell-m26", 1443 { .id = STAC_9200_DELL_M27, .name = "dell-m27" },
1362 [STAC_9200_DELL_M27] = "dell-m27", 1444 { .id = STAC_9200_M4, .name = "gateway-m4" },
1363 [STAC_9200_M4] = "gateway-m4", 1445 { .id = STAC_9200_M4_2, .name = "gateway-m4-2" },
1364 [STAC_9200_M4_2] = "gateway-m4-2", 1446 { .id = STAC_9200_PANASONIC, .name = "panasonic" },
1365 [STAC_9200_PANASONIC] = "panasonic", 1447 {}
1366}; 1448};
1367 1449
1368static const struct snd_pci_quirk stac9200_cfg_tbl[] = { 1450static const struct snd_pci_quirk stac9200_fixup_tbl[] = {
1369 /* SigmaTel reference board */ 1451 /* SigmaTel reference board */
1370 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1452 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1371 "DFI LanParty", STAC_REF), 1453 "DFI LanParty", STAC_REF),
@@ -1441,70 +1523,159 @@ static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
1441 {} /* terminator */ 1523 {} /* terminator */
1442}; 1524};
1443 1525
1444static const unsigned int ref925x_pin_configs[8] = { 1526static const struct hda_pintbl ref925x_pin_configs[] = {
1445 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021, 1527 { 0x07, 0x40c003f0 },
1446 0x90a70320, 0x02214210, 0x01019020, 0x9033032e, 1528 { 0x08, 0x424503f2 },
1529 { 0x0a, 0x01813022 },
1530 { 0x0b, 0x02a19021 },
1531 { 0x0c, 0x90a70320 },
1532 { 0x0d, 0x02214210 },
1533 { 0x10, 0x01019020 },
1534 { 0x11, 0x9033032e },
1535 {}
1447}; 1536};
1448 1537
1449static const unsigned int stac925xM1_pin_configs[8] = { 1538static const struct hda_pintbl stac925xM1_pin_configs[] = {
1450 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020, 1539 { 0x07, 0x40c003f4 },
1451 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e, 1540 { 0x08, 0x424503f2 },
1541 { 0x0a, 0x400000f3 },
1542 { 0x0b, 0x02a19020 },
1543 { 0x0c, 0x40a000f0 },
1544 { 0x0d, 0x90100210 },
1545 { 0x10, 0x400003f1 },
1546 { 0x11, 0x9033032e },
1547 {}
1452}; 1548};
1453 1549
1454static const unsigned int stac925xM1_2_pin_configs[8] = { 1550static const struct hda_pintbl stac925xM1_2_pin_configs[] = {
1455 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020, 1551 { 0x07, 0x40c003f4 },
1456 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e, 1552 { 0x08, 0x424503f2 },
1553 { 0x0a, 0x400000f3 },
1554 { 0x0b, 0x02a19020 },
1555 { 0x0c, 0x40a000f0 },
1556 { 0x0d, 0x90100210 },
1557 { 0x10, 0x400003f1 },
1558 { 0x11, 0x9033032e },
1559 {}
1457}; 1560};
1458 1561
1459static const unsigned int stac925xM2_pin_configs[8] = { 1562static const struct hda_pintbl stac925xM2_pin_configs[] = {
1460 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020, 1563 { 0x07, 0x40c003f4 },
1461 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e, 1564 { 0x08, 0x424503f2 },
1565 { 0x0a, 0x400000f3 },
1566 { 0x0b, 0x02a19020 },
1567 { 0x0c, 0x40a000f0 },
1568 { 0x0d, 0x90100210 },
1569 { 0x10, 0x400003f1 },
1570 { 0x11, 0x9033032e },
1571 {}
1462}; 1572};
1463 1573
1464static const unsigned int stac925xM2_2_pin_configs[8] = { 1574static const struct hda_pintbl stac925xM2_2_pin_configs[] = {
1465 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020, 1575 { 0x07, 0x40c003f4 },
1466 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e, 1576 { 0x08, 0x424503f2 },
1577 { 0x0a, 0x400000f3 },
1578 { 0x0b, 0x02a19020 },
1579 { 0x0c, 0x40a000f0 },
1580 { 0x0d, 0x90100210 },
1581 { 0x10, 0x400003f1 },
1582 { 0x11, 0x9033032e },
1583 {}
1467}; 1584};
1468 1585
1469static const unsigned int stac925xM3_pin_configs[8] = { 1586static const struct hda_pintbl stac925xM3_pin_configs[] = {
1470 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020, 1587 { 0x07, 0x40c003f4 },
1471 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3, 1588 { 0x08, 0x424503f2 },
1589 { 0x0a, 0x400000f3 },
1590 { 0x0b, 0x02a19020 },
1591 { 0x0c, 0x40a000f0 },
1592 { 0x0d, 0x90100210 },
1593 { 0x10, 0x400003f1 },
1594 { 0x11, 0x503303f3 },
1595 {}
1472}; 1596};
1473 1597
1474static const unsigned int stac925xM5_pin_configs[8] = { 1598static const struct hda_pintbl stac925xM5_pin_configs[] = {
1475 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020, 1599 { 0x07, 0x40c003f4 },
1476 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e, 1600 { 0x08, 0x424503f2 },
1601 { 0x0a, 0x400000f3 },
1602 { 0x0b, 0x02a19020 },
1603 { 0x0c, 0x40a000f0 },
1604 { 0x0d, 0x90100210 },
1605 { 0x10, 0x400003f1 },
1606 { 0x11, 0x9033032e },
1607 {}
1477}; 1608};
1478 1609
1479static const unsigned int stac925xM6_pin_configs[8] = { 1610static const struct hda_pintbl stac925xM6_pin_configs[] = {
1480 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020, 1611 { 0x07, 0x40c003f4 },
1481 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320, 1612 { 0x08, 0x424503f2 },
1613 { 0x0a, 0x400000f3 },
1614 { 0x0b, 0x02a19020 },
1615 { 0x0c, 0x40a000f0 },
1616 { 0x0d, 0x90100210 },
1617 { 0x10, 0x400003f1 },
1618 { 0x11, 0x90330320 },
1619 {}
1482}; 1620};
1483 1621
1484static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = { 1622static const struct hda_fixup stac925x_fixups[] = {
1485 [STAC_REF] = ref925x_pin_configs, 1623 [STAC_REF] = {
1486 [STAC_M1] = stac925xM1_pin_configs, 1624 .type = HDA_FIXUP_PINS,
1487 [STAC_M1_2] = stac925xM1_2_pin_configs, 1625 .v.pins = ref925x_pin_configs,
1488 [STAC_M2] = stac925xM2_pin_configs, 1626 },
1489 [STAC_M2_2] = stac925xM2_2_pin_configs, 1627 [STAC_M1] = {
1490 [STAC_M3] = stac925xM3_pin_configs, 1628 .type = HDA_FIXUP_PINS,
1491 [STAC_M5] = stac925xM5_pin_configs, 1629 .v.pins = stac925xM1_pin_configs,
1492 [STAC_M6] = stac925xM6_pin_configs, 1630 },
1631 [STAC_M1_2] = {
1632 .type = HDA_FIXUP_PINS,
1633 .v.pins = stac925xM1_2_pin_configs,
1634 },
1635 [STAC_M2] = {
1636 .type = HDA_FIXUP_PINS,
1637 .v.pins = stac925xM2_pin_configs,
1638 },
1639 [STAC_M2_2] = {
1640 .type = HDA_FIXUP_PINS,
1641 .v.pins = stac925xM2_2_pin_configs,
1642 },
1643 [STAC_M3] = {
1644 .type = HDA_FIXUP_PINS,
1645 .v.pins = stac925xM3_pin_configs,
1646 },
1647 [STAC_M5] = {
1648 .type = HDA_FIXUP_PINS,
1649 .v.pins = stac925xM5_pin_configs,
1650 },
1651 [STAC_M6] = {
1652 .type = HDA_FIXUP_PINS,
1653 .v.pins = stac925xM6_pin_configs,
1654 },
1493}; 1655};
1494 1656
1495static const char * const stac925x_models[STAC_925x_MODELS] = { 1657static const struct hda_model_fixup stac925x_models[] = {
1496 [STAC_925x_AUTO] = "auto", 1658 { .id = STAC_REF, .name = "ref" },
1497 [STAC_REF] = "ref", 1659 { .id = STAC_M1, .name = "m1" },
1498 [STAC_M1] = "m1", 1660 { .id = STAC_M1_2, .name = "m1-2" },
1499 [STAC_M1_2] = "m1-2", 1661 { .id = STAC_M2, .name = "m2" },
1500 [STAC_M2] = "m2", 1662 { .id = STAC_M2_2, .name = "m2-2" },
1501 [STAC_M2_2] = "m2-2", 1663 { .id = STAC_M3, .name = "m3" },
1502 [STAC_M3] = "m3", 1664 { .id = STAC_M5, .name = "m5" },
1503 [STAC_M5] = "m5", 1665 { .id = STAC_M6, .name = "m6" },
1504 [STAC_M6] = "m6", 1666 {}
1505}; 1667};
1506 1668
1507static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = { 1669static const struct snd_pci_quirk stac925x_fixup_tbl[] = {
1670 /* SigmaTel reference board */
1671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1672 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1673 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1674
1675 /* Default table for unknown ID */
1676 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1677
1678 /* gateway machines are checked via codec ssid */
1508 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2), 1679 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1509 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5), 1680 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1510 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1), 1681 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
@@ -1518,67 +1689,202 @@ static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1518 {} /* terminator */ 1689 {} /* terminator */
1519}; 1690};
1520 1691
1521static const struct snd_pci_quirk stac925x_cfg_tbl[] = { 1692static const struct hda_pintbl ref92hd73xx_pin_configs[] = {
1522 /* SigmaTel reference board */ 1693 { 0x0a, 0x02214030 },
1523 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF), 1694 { 0x0b, 0x02a19040 },
1524 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF), 1695 { 0x0c, 0x01a19020 },
1525 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF), 1696 { 0x0d, 0x02214030 },
1526 1697 { 0x0e, 0x0181302e },
1527 /* Default table for unknown ID */ 1698 { 0x0f, 0x01014010 },
1528 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2), 1699 { 0x10, 0x01014020 },
1529 1700 { 0x11, 0x01014030 },
1530 {} /* terminator */ 1701 { 0x12, 0x02319040 },
1702 { 0x13, 0x90a000f0 },
1703 { 0x14, 0x90a000f0 },
1704 { 0x22, 0x01452050 },
1705 { 0x23, 0x01452050 },
1706 {}
1531}; 1707};
1532 1708
1533static const unsigned int ref92hd73xx_pin_configs[13] = { 1709static const struct hda_pintbl dell_m6_pin_configs[] = {
1534 0x02214030, 0x02a19040, 0x01a19020, 0x02214030, 1710 { 0x0a, 0x0321101f },
1535 0x0181302e, 0x01014010, 0x01014020, 0x01014030, 1711 { 0x0b, 0x4f00000f },
1536 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050, 1712 { 0x0c, 0x4f0000f0 },
1537 0x01452050, 1713 { 0x0d, 0x90170110 },
1714 { 0x0e, 0x03a11020 },
1715 { 0x0f, 0x0321101f },
1716 { 0x10, 0x4f0000f0 },
1717 { 0x11, 0x4f0000f0 },
1718 { 0x12, 0x4f0000f0 },
1719 { 0x13, 0x90a60160 },
1720 { 0x14, 0x4f0000f0 },
1721 { 0x22, 0x4f0000f0 },
1722 { 0x23, 0x4f0000f0 },
1723 {}
1538}; 1724};
1539 1725
1540static const unsigned int dell_m6_pin_configs[13] = { 1726static const struct hda_pintbl alienware_m17x_pin_configs[] = {
1541 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110, 1727 { 0x0a, 0x0321101f },
1542 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0, 1728 { 0x0b, 0x0321101f },
1543 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0, 1729 { 0x0c, 0x03a11020 },
1544 0x4f0000f0, 1730 { 0x0d, 0x03014020 },
1731 { 0x0e, 0x90170110 },
1732 { 0x0f, 0x4f0000f0 },
1733 { 0x10, 0x4f0000f0 },
1734 { 0x11, 0x4f0000f0 },
1735 { 0x12, 0x4f0000f0 },
1736 { 0x13, 0x90a60160 },
1737 { 0x14, 0x4f0000f0 },
1738 { 0x22, 0x4f0000f0 },
1739 { 0x23, 0x904601b0 },
1740 {}
1545}; 1741};
1546 1742
1547static const unsigned int alienware_m17x_pin_configs[13] = { 1743static const struct hda_pintbl intel_dg45id_pin_configs[] = {
1548 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020, 1744 { 0x0a, 0x02214230 },
1549 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0, 1745 { 0x0b, 0x02A19240 },
1550 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0, 1746 { 0x0c, 0x01013214 },
1551 0x904601b0, 1747 { 0x0d, 0x01014210 },
1748 { 0x0e, 0x01A19250 },
1749 { 0x0f, 0x01011212 },
1750 { 0x10, 0x01016211 },
1751 {}
1552}; 1752};
1553 1753
1554static const unsigned int intel_dg45id_pin_configs[13] = { 1754static void stac92hd73xx_fixup_ref(struct hda_codec *codec,
1555 0x02214230, 0x02A19240, 0x01013214, 0x01014210, 1755 const struct hda_fixup *fix, int action)
1556 0x01A19250, 0x01011212, 0x01016211 1756{
1557}; 1757 struct sigmatel_spec *spec = codec->spec;
1758
1759 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1760 return;
1761
1762 snd_hda_apply_pincfgs(codec, ref92hd73xx_pin_configs);
1763 spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0;
1764}
1765
1766static void stac92hd73xx_fixup_dell(struct hda_codec *codec)
1767{
1768 struct sigmatel_spec *spec = codec->spec;
1769
1770 snd_hda_apply_pincfgs(codec, dell_m6_pin_configs);
1771 spec->eapd_switch = 0;
1772}
1773
1774static void stac92hd73xx_fixup_dell_eq(struct hda_codec *codec,
1775 const struct hda_fixup *fix, int action)
1776{
1777 struct sigmatel_spec *spec = codec->spec;
1558 1778
1559static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = { 1779 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1560 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs, 1780 return;
1561 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs, 1781
1562 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs, 1782 stac92hd73xx_fixup_dell(codec);
1563 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs, 1783 snd_hda_add_verbs(codec, dell_eq_core_init);
1564 [STAC_DELL_EQ] = dell_m6_pin_configs, 1784 spec->volknob_init = 1;
1565 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs, 1785}
1566 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs, 1786
1787/* Analog Mics */
1788static void stac92hd73xx_fixup_dell_m6_amic(struct hda_codec *codec,
1789 const struct hda_fixup *fix, int action)
1790{
1791 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1792 return;
1793
1794 stac92hd73xx_fixup_dell(codec);
1795 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
1796}
1797
1798/* Digital Mics */
1799static void stac92hd73xx_fixup_dell_m6_dmic(struct hda_codec *codec,
1800 const struct hda_fixup *fix, int action)
1801{
1802 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1803 return;
1804
1805 stac92hd73xx_fixup_dell(codec);
1806 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
1807}
1808
1809/* Both */
1810static void stac92hd73xx_fixup_dell_m6_both(struct hda_codec *codec,
1811 const struct hda_fixup *fix, int action)
1812{
1813 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1814 return;
1815
1816 stac92hd73xx_fixup_dell(codec);
1817 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
1818 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
1819}
1820
1821static void stac92hd73xx_fixup_alienware_m17x(struct hda_codec *codec,
1822 const struct hda_fixup *fix, int action)
1823{
1824 struct sigmatel_spec *spec = codec->spec;
1825
1826 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1827 return;
1828
1829 snd_hda_apply_pincfgs(codec, alienware_m17x_pin_configs);
1830 spec->eapd_switch = 0;
1831}
1832
1833static void stac92hd73xx_fixup_no_jd(struct hda_codec *codec,
1834 const struct hda_fixup *fix, int action)
1835{
1836 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1837 codec->no_jack_detect = 1;
1838}
1839
1840static const struct hda_fixup stac92hd73xx_fixups[] = {
1841 [STAC_92HD73XX_REF] = {
1842 .type = HDA_FIXUP_FUNC,
1843 .v.func = stac92hd73xx_fixup_ref,
1844 },
1845 [STAC_DELL_M6_AMIC] = {
1846 .type = HDA_FIXUP_FUNC,
1847 .v.func = stac92hd73xx_fixup_dell_m6_amic,
1848 },
1849 [STAC_DELL_M6_DMIC] = {
1850 .type = HDA_FIXUP_FUNC,
1851 .v.func = stac92hd73xx_fixup_dell_m6_dmic,
1852 },
1853 [STAC_DELL_M6_BOTH] = {
1854 .type = HDA_FIXUP_FUNC,
1855 .v.func = stac92hd73xx_fixup_dell_m6_both,
1856 },
1857 [STAC_DELL_EQ] = {
1858 .type = HDA_FIXUP_FUNC,
1859 .v.func = stac92hd73xx_fixup_dell_eq,
1860 },
1861 [STAC_ALIENWARE_M17X] = {
1862 .type = HDA_FIXUP_FUNC,
1863 .v.func = stac92hd73xx_fixup_alienware_m17x,
1864 },
1865 [STAC_92HD73XX_INTEL] = {
1866 .type = HDA_FIXUP_PINS,
1867 .v.pins = intel_dg45id_pin_configs,
1868 },
1869 [STAC_92HD73XX_NO_JD] = {
1870 .type = HDA_FIXUP_FUNC,
1871 .v.func = stac92hd73xx_fixup_no_jd,
1872 }
1567}; 1873};
1568 1874
1569static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = { 1875static const struct hda_model_fixup stac92hd73xx_models[] = {
1570 [STAC_92HD73XX_AUTO] = "auto", 1876 { .id = STAC_92HD73XX_NO_JD, .name = "no-jd" },
1571 [STAC_92HD73XX_NO_JD] = "no-jd", 1877 { .id = STAC_92HD73XX_REF, .name = "ref" },
1572 [STAC_92HD73XX_REF] = "ref", 1878 { .id = STAC_92HD73XX_INTEL, .name = "intel" },
1573 [STAC_92HD73XX_INTEL] = "intel", 1879 { .id = STAC_DELL_M6_AMIC, .name = "dell-m6-amic" },
1574 [STAC_DELL_M6_AMIC] = "dell-m6-amic", 1880 { .id = STAC_DELL_M6_DMIC, .name = "dell-m6-dmic" },
1575 [STAC_DELL_M6_DMIC] = "dell-m6-dmic", 1881 { .id = STAC_DELL_M6_BOTH, .name = "dell-m6" },
1576 [STAC_DELL_M6_BOTH] = "dell-m6", 1882 { .id = STAC_DELL_EQ, .name = "dell-eq" },
1577 [STAC_DELL_EQ] = "dell-eq", 1883 { .id = STAC_ALIENWARE_M17X, .name = "alienware" },
1578 [STAC_ALIENWARE_M17X] = "alienware", 1884 {}
1579}; 1885};
1580 1886
1581static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = { 1887static const struct snd_pci_quirk stac92hd73xx_fixup_tbl[] = {
1582 /* SigmaTel reference board */ 1888 /* SigmaTel reference board */
1583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1889 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1584 "DFI LanParty", STAC_92HD73XX_REF), 1890 "DFI LanParty", STAC_92HD73XX_REF),
@@ -1616,10 +1922,7 @@ static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1616 "Dell Studio XPS 1645", STAC_DELL_M6_DMIC), 1922 "Dell Studio XPS 1645", STAC_DELL_M6_DMIC),
1617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413, 1923 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1618 "Dell Studio 1558", STAC_DELL_M6_DMIC), 1924 "Dell Studio 1558", STAC_DELL_M6_DMIC),
1619 {} /* terminator */ 1925 /* codec SSID matching */
1620};
1621
1622static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1, 1926 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1624 "Alienware M17x", STAC_ALIENWARE_M17X), 1927 "Alienware M17x", STAC_ALIENWARE_M17X),
1625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a, 1928 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
@@ -1629,68 +1932,240 @@ static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1629 {} /* terminator */ 1932 {} /* terminator */
1630}; 1933};
1631 1934
1632static const unsigned int ref92hd83xxx_pin_configs[10] = { 1935static const struct hda_pintbl ref92hd83xxx_pin_configs[] = {
1633 0x02214030, 0x02211010, 0x02a19020, 0x02170130, 1936 { 0x0a, 0x02214030 },
1634 0x01014050, 0x01819040, 0x01014020, 0x90a3014e, 1937 { 0x0b, 0x02211010 },
1635 0x01451160, 0x98560170, 1938 { 0x0c, 0x02a19020 },
1939 { 0x0d, 0x02170130 },
1940 { 0x0e, 0x01014050 },
1941 { 0x0f, 0x01819040 },
1942 { 0x10, 0x01014020 },
1943 { 0x11, 0x90a3014e },
1944 { 0x1f, 0x01451160 },
1945 { 0x20, 0x98560170 },
1946 {}
1636}; 1947};
1637 1948
1638static const unsigned int dell_s14_pin_configs[10] = { 1949static const struct hda_pintbl dell_s14_pin_configs[] = {
1639 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110, 1950 { 0x0a, 0x0221403f },
1640 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160, 1951 { 0x0b, 0x0221101f },
1641 0x40f000f0, 0x40f000f0, 1952 { 0x0c, 0x02a19020 },
1953 { 0x0d, 0x90170110 },
1954 { 0x0e, 0x40f000f0 },
1955 { 0x0f, 0x40f000f0 },
1956 { 0x10, 0x40f000f0 },
1957 { 0x11, 0x90a60160 },
1958 { 0x1f, 0x40f000f0 },
1959 { 0x20, 0x40f000f0 },
1960 {}
1642}; 1961};
1643 1962
1644static const unsigned int dell_vostro_3500_pin_configs[10] = { 1963static const struct hda_pintbl dell_vostro_3500_pin_configs[] = {
1645 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110, 1964 { 0x0a, 0x02a11020 },
1646 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160, 1965 { 0x0b, 0x0221101f },
1647 0x400000f4, 0x400000f5, 1966 { 0x0c, 0x400000f0 },
1967 { 0x0d, 0x90170110 },
1968 { 0x0e, 0x400000f1 },
1969 { 0x0f, 0x400000f2 },
1970 { 0x10, 0x400000f3 },
1971 { 0x11, 0x90a60160 },
1972 { 0x1f, 0x400000f4 },
1973 { 0x20, 0x400000f5 },
1974 {}
1648}; 1975};
1649 1976
1650static const unsigned int hp_dv7_4000_pin_configs[10] = { 1977static const struct hda_pintbl hp_dv7_4000_pin_configs[] = {
1651 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110, 1978 { 0x0a, 0x03a12050 },
1652 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140, 1979 { 0x0b, 0x0321201f },
1653 0x40f000f0, 0x40f000f0, 1980 { 0x0c, 0x40f000f0 },
1981 { 0x0d, 0x90170110 },
1982 { 0x0e, 0x40f000f0 },
1983 { 0x0f, 0x40f000f0 },
1984 { 0x10, 0x90170110 },
1985 { 0x11, 0xd5a30140 },
1986 { 0x1f, 0x40f000f0 },
1987 { 0x20, 0x40f000f0 },
1988 {}
1654}; 1989};
1655 1990
1656static const unsigned int hp_zephyr_pin_configs[10] = { 1991static const struct hda_pintbl hp_zephyr_pin_configs[] = {
1657 0x01813050, 0x0421201f, 0x04a1205e, 0x96130310, 1992 { 0x0a, 0x01813050 },
1658 0x96130310, 0x0101401f, 0x1111611f, 0xd5a30130, 1993 { 0x0b, 0x0421201f },
1659 0, 0, 1994 { 0x0c, 0x04a1205e },
1995 { 0x0d, 0x96130310 },
1996 { 0x0e, 0x96130310 },
1997 { 0x0f, 0x0101401f },
1998 { 0x10, 0x1111611f },
1999 { 0x11, 0xd5a30130 },
2000 {}
1660}; 2001};
1661 2002
1662static const unsigned int hp_cNB11_intquad_pin_configs[10] = { 2003static const struct hda_pintbl hp_cNB11_intquad_pin_configs[] = {
1663 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110, 2004 { 0x0a, 0x40f000f0 },
1664 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130, 2005 { 0x0b, 0x0221101f },
1665 0x40f000f0, 0x40f000f0, 2006 { 0x0c, 0x02a11020 },
2007 { 0x0d, 0x92170110 },
2008 { 0x0e, 0x40f000f0 },
2009 { 0x0f, 0x92170110 },
2010 { 0x10, 0x40f000f0 },
2011 { 0x11, 0xd5a30130 },
2012 { 0x1f, 0x40f000f0 },
2013 { 0x20, 0x40f000f0 },
2014 {}
1666}; 2015};
1667 2016
1668static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = { 2017static void stac92hd83xxx_fixup_hp(struct hda_codec *codec,
1669 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs, 2018 const struct hda_fixup *fix, int action)
1670 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs, 2019{
1671 [STAC_DELL_S14] = dell_s14_pin_configs, 2020 struct sigmatel_spec *spec = codec->spec;
1672 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs, 2021
1673 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs, 2022 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1674 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs, 2023 return;
1675 [STAC_HP_ZEPHYR] = hp_zephyr_pin_configs, 2024
2025 if (hp_bnb2011_with_dock(codec)) {
2026 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
2027 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
2028 }
2029
2030 if (find_mute_led_cfg(codec, spec->default_polarity))
2031 snd_printd("mute LED gpio %d polarity %d\n",
2032 spec->gpio_led,
2033 spec->gpio_led_polarity);
2034}
2035
2036static void stac92hd83xxx_fixup_hp_zephyr(struct hda_codec *codec,
2037 const struct hda_fixup *fix, int action)
2038{
2039 if (action != HDA_FIXUP_ACT_PRE_PROBE)
2040 return;
2041
2042 snd_hda_apply_pincfgs(codec, hp_zephyr_pin_configs);
2043 snd_hda_add_verbs(codec, stac92hd83xxx_hp_zephyr_init);
2044}
2045
2046static void stac92hd83xxx_fixup_hp_led(struct hda_codec *codec,
2047 const struct hda_fixup *fix, int action)
2048{
2049 struct sigmatel_spec *spec = codec->spec;
2050
2051 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2052 spec->default_polarity = 0;
2053}
2054
2055static void stac92hd83xxx_fixup_hp_inv_led(struct hda_codec *codec,
2056 const struct hda_fixup *fix, int action)
2057{
2058 struct sigmatel_spec *spec = codec->spec;
2059
2060 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2061 spec->default_polarity = 1;
2062}
2063
2064static void stac92hd83xxx_fixup_hp_mic_led(struct hda_codec *codec,
2065 const struct hda_fixup *fix, int action)
2066{
2067 struct sigmatel_spec *spec = codec->spec;
2068
2069 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2070 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */
2071}
2072
2073static void stac92hd83xxx_fixup_headset_jack(struct hda_codec *codec,
2074 const struct hda_fixup *fix, int action)
2075{
2076 struct sigmatel_spec *spec = codec->spec;
2077
2078 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2079 spec->headset_jack = 1;
2080}
2081
2082static const struct hda_fixup stac92hd83xxx_fixups[] = {
2083 [STAC_92HD83XXX_REF] = {
2084 .type = HDA_FIXUP_PINS,
2085 .v.pins = ref92hd83xxx_pin_configs,
2086 },
2087 [STAC_92HD83XXX_PWR_REF] = {
2088 .type = HDA_FIXUP_PINS,
2089 .v.pins = ref92hd83xxx_pin_configs,
2090 },
2091 [STAC_DELL_S14] = {
2092 .type = HDA_FIXUP_PINS,
2093 .v.pins = dell_s14_pin_configs,
2094 },
2095 [STAC_DELL_VOSTRO_3500] = {
2096 .type = HDA_FIXUP_PINS,
2097 .v.pins = dell_vostro_3500_pin_configs,
2098 },
2099 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = {
2100 .type = HDA_FIXUP_PINS,
2101 .v.pins = hp_cNB11_intquad_pin_configs,
2102 .chained = true,
2103 .chain_id = STAC_92HD83XXX_HP,
2104 },
2105 [STAC_92HD83XXX_HP] = {
2106 .type = HDA_FIXUP_FUNC,
2107 .v.func = stac92hd83xxx_fixup_hp,
2108 },
2109 [STAC_HP_DV7_4000] = {
2110 .type = HDA_FIXUP_PINS,
2111 .v.pins = hp_dv7_4000_pin_configs,
2112 .chained = true,
2113 .chain_id = STAC_92HD83XXX_HP,
2114 },
2115 [STAC_HP_ZEPHYR] = {
2116 .type = HDA_FIXUP_FUNC,
2117 .v.func = stac92hd83xxx_fixup_hp_zephyr,
2118 .chained = true,
2119 .chain_id = STAC_92HD83XXX_HP,
2120 },
2121 [STAC_92HD83XXX_HP_LED] = {
2122 .type = HDA_FIXUP_FUNC,
2123 .v.func = stac92hd83xxx_fixup_hp_led,
2124 .chained = true,
2125 .chain_id = STAC_92HD83XXX_HP,
2126 },
2127 [STAC_92HD83XXX_HP_INV_LED] = {
2128 .type = HDA_FIXUP_FUNC,
2129 .v.func = stac92hd83xxx_fixup_hp_inv_led,
2130 .chained = true,
2131 .chain_id = STAC_92HD83XXX_HP,
2132 },
2133 [STAC_92HD83XXX_HP_MIC_LED] = {
2134 .type = HDA_FIXUP_FUNC,
2135 .v.func = stac92hd83xxx_fixup_hp_mic_led,
2136 .chained = true,
2137 .chain_id = STAC_92HD83XXX_HP,
2138 },
2139 [STAC_92HD83XXX_HEADSET_JACK] = {
2140 .type = HDA_FIXUP_FUNC,
2141 .v.func = stac92hd83xxx_fixup_headset_jack,
2142 },
2143 [STAC_HP_ENVY_BASS] = {
2144 .type = HDA_FIXUP_PINS,
2145 .v.pins = (const struct hda_pintbl[]) {
2146 { 0x0f, 0x90170111 },
2147 {}
2148 },
2149 },
1676}; 2150};
1677 2151
1678static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = { 2152static const struct hda_model_fixup stac92hd83xxx_models[] = {
1679 [STAC_92HD83XXX_AUTO] = "auto", 2153 { .id = STAC_92HD83XXX_REF, .name = "ref" },
1680 [STAC_92HD83XXX_REF] = "ref", 2154 { .id = STAC_92HD83XXX_PWR_REF, .name = "mic-ref" },
1681 [STAC_92HD83XXX_PWR_REF] = "mic-ref", 2155 { .id = STAC_DELL_S14, .name = "dell-s14" },
1682 [STAC_DELL_S14] = "dell-s14", 2156 { .id = STAC_DELL_VOSTRO_3500, .name = "dell-vostro-3500" },
1683 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500", 2157 { .id = STAC_92HD83XXX_HP_cNB11_INTQUAD, .name = "hp_cNB11_intquad" },
1684 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad", 2158 { .id = STAC_HP_DV7_4000, .name = "hp-dv7-4000" },
1685 [STAC_HP_DV7_4000] = "hp-dv7-4000", 2159 { .id = STAC_HP_ZEPHYR, .name = "hp-zephyr" },
1686 [STAC_HP_ZEPHYR] = "hp-zephyr", 2160 { .id = STAC_92HD83XXX_HP_LED, .name = "hp-led" },
1687 [STAC_92HD83XXX_HP_LED] = "hp-led", 2161 { .id = STAC_92HD83XXX_HP_INV_LED, .name = "hp-inv-led" },
1688 [STAC_92HD83XXX_HP_INV_LED] = "hp-inv-led", 2162 { .id = STAC_92HD83XXX_HP_MIC_LED, .name = "hp-mic-led" },
1689 [STAC_92HD83XXX_HP_MIC_LED] = "hp-mic-led", 2163 { .id = STAC_92HD83XXX_HEADSET_JACK, .name = "headset-jack" },
1690 [STAC_92HD83XXX_HEADSET_JACK] = "headset-jack", 2164 { .id = STAC_HP_ENVY_BASS, .name = "hp-envy-bass" },
2165 {}
1691}; 2166};
1692 2167
1693static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = { 2168static const struct snd_pci_quirk stac92hd83xxx_fixup_tbl[] = {
1694 /* SigmaTel reference board */ 2169 /* SigmaTel reference board */
1695 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 2170 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1696 "DFI LanParty", STAC_92HD83XXX_REF), 2171 "DFI LanParty", STAC_92HD83XXX_REF),
@@ -1730,8 +2205,12 @@ static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1730 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD), 2205 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1731 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B, 2206 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1732 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD), 2207 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2208 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1888,
2209 "HP Envy Spectre", STAC_HP_ENVY_BASS),
1733 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df, 2210 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df,
1734 "HP Folio", STAC_92HD83XXX_HP_MIC_LED), 2211 "HP Folio", STAC_92HD83XXX_HP_MIC_LED),
2212 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x1900,
2213 "HP", STAC_92HD83XXX_HP_MIC_LED),
1735 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388, 2214 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1736 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD), 2215 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1737 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389, 2216 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
@@ -1766,76 +2245,297 @@ static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1766 "HP Mini", STAC_92HD83XXX_HP_LED), 2245 "HP Mini", STAC_92HD83XXX_HP_LED),
1767 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x144E, 2246 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x144E,
1768 "HP Pavilion dv5", STAC_92HD83XXX_HP_INV_LED), 2247 "HP Pavilion dv5", STAC_92HD83XXX_HP_INV_LED),
2248 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x148a,
2249 "HP Mini", STAC_92HD83XXX_HP_LED),
2250 SND_PCI_QUIRK_VENDOR(PCI_VENDOR_ID_HP, "HP", STAC_92HD83XXX_HP),
1769 {} /* terminator */ 2251 {} /* terminator */
1770}; 2252};
1771 2253
1772static const struct snd_pci_quirk stac92hd83xxx_codec_id_cfg_tbl[] = { 2254/* HP dv7 bass switch - GPIO5 */
1773 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561, 2255#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
1774 "HP", STAC_HP_ZEPHYR), 2256static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
1775 {} /* terminator */ 2257 struct snd_ctl_elem_value *ucontrol)
2258{
2259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2260 struct sigmatel_spec *spec = codec->spec;
2261 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
2262 return 0;
2263}
2264
2265static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
2266 struct snd_ctl_elem_value *ucontrol)
2267{
2268 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2269 struct sigmatel_spec *spec = codec->spec;
2270 unsigned int gpio_data;
2271
2272 gpio_data = (spec->gpio_data & ~0x20) |
2273 (ucontrol->value.integer.value[0] ? 0x20 : 0);
2274 if (gpio_data == spec->gpio_data)
2275 return 0;
2276 spec->gpio_data = gpio_data;
2277 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
2278 return 1;
2279}
2280
2281static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
2282 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2283 .info = stac_hp_bass_gpio_info,
2284 .get = stac_hp_bass_gpio_get,
2285 .put = stac_hp_bass_gpio_put,
1776}; 2286};
1777 2287
1778static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = { 2288static int stac_add_hp_bass_switch(struct hda_codec *codec)
1779 0x02214030, 0x02a19040, 0x01a19020, 0x01014010, 2289{
1780 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0, 2290 struct sigmatel_spec *spec = codec->spec;
1781 0x90a000f0, 0x01452050, 0x01452050, 0x00000000, 2291
1782 0x00000000 2292 if (!snd_hda_gen_add_kctl(&spec->gen, "Bass Speaker Playback Switch",
2293 &stac_hp_bass_sw_ctrl))
2294 return -ENOMEM;
2295
2296 spec->gpio_mask |= 0x20;
2297 spec->gpio_dir |= 0x20;
2298 spec->gpio_data |= 0x20;
2299 return 0;
2300}
2301
2302static const struct hda_pintbl ref92hd71bxx_pin_configs[] = {
2303 { 0x0a, 0x02214030 },
2304 { 0x0b, 0x02a19040 },
2305 { 0x0c, 0x01a19020 },
2306 { 0x0d, 0x01014010 },
2307 { 0x0e, 0x0181302e },
2308 { 0x0f, 0x01014010 },
2309 { 0x14, 0x01019020 },
2310 { 0x18, 0x90a000f0 },
2311 { 0x19, 0x90a000f0 },
2312 { 0x1e, 0x01452050 },
2313 { 0x1f, 0x01452050 },
2314 {}
1783}; 2315};
1784 2316
1785static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = { 2317static const struct hda_pintbl dell_m4_1_pin_configs[] = {
1786 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110, 2318 { 0x0a, 0x0421101f },
1787 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0, 2319 { 0x0b, 0x04a11221 },
1788 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000, 2320 { 0x0c, 0x40f000f0 },
1789 0x00000000 2321 { 0x0d, 0x90170110 },
2322 { 0x0e, 0x23a1902e },
2323 { 0x0f, 0x23014250 },
2324 { 0x14, 0x40f000f0 },
2325 { 0x18, 0x90a000f0 },
2326 { 0x19, 0x40f000f0 },
2327 { 0x1e, 0x4f0000f0 },
2328 { 0x1f, 0x4f0000f0 },
2329 {}
1790}; 2330};
1791 2331
1792static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = { 2332static const struct hda_pintbl dell_m4_2_pin_configs[] = {
1793 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110, 2333 { 0x0a, 0x0421101f },
1794 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0, 2334 { 0x0b, 0x04a11221 },
1795 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000, 2335 { 0x0c, 0x90a70330 },
1796 0x00000000 2336 { 0x0d, 0x90170110 },
2337 { 0x0e, 0x23a1902e },
2338 { 0x0f, 0x23014250 },
2339 { 0x14, 0x40f000f0 },
2340 { 0x18, 0x40f000f0 },
2341 { 0x19, 0x40f000f0 },
2342 { 0x1e, 0x044413b0 },
2343 { 0x1f, 0x044413b0 },
2344 {}
1797}; 2345};
1798 2346
1799static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = { 2347static const struct hda_pintbl dell_m4_3_pin_configs[] = {
1800 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110, 2348 { 0x0a, 0x0421101f },
1801 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0, 2349 { 0x0b, 0x04a11221 },
1802 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000, 2350 { 0x0c, 0x90a70330 },
1803 0x00000000 2351 { 0x0d, 0x90170110 },
2352 { 0x0e, 0x40f000f0 },
2353 { 0x0f, 0x40f000f0 },
2354 { 0x14, 0x40f000f0 },
2355 { 0x18, 0x90a000f0 },
2356 { 0x19, 0x40f000f0 },
2357 { 0x1e, 0x044413b0 },
2358 { 0x1f, 0x044413b0 },
2359 {}
1804}; 2360};
1805 2361
1806static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = { 2362static void stac92hd71bxx_fixup_ref(struct hda_codec *codec,
1807 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs, 2363 const struct hda_fixup *fix, int action)
1808 [STAC_DELL_M4_1] = dell_m4_1_pin_configs, 2364{
1809 [STAC_DELL_M4_2] = dell_m4_2_pin_configs, 2365 struct sigmatel_spec *spec = codec->spec;
1810 [STAC_DELL_M4_3] = dell_m4_3_pin_configs, 2366
1811 [STAC_HP_M4] = NULL, 2367 if (action != HDA_FIXUP_ACT_PRE_PROBE)
1812 [STAC_HP_DV4] = NULL, 2368 return;
1813 [STAC_HP_DV5] = NULL, 2369
1814 [STAC_HP_HDX] = NULL, 2370 snd_hda_apply_pincfgs(codec, ref92hd71bxx_pin_configs);
1815 [STAC_HP_DV4_1222NR] = NULL, 2371 spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0;
2372}
2373
2374static void stac92hd71bxx_fixup_hp_m4(struct hda_codec *codec,
2375 const struct hda_fixup *fix, int action)
2376{
2377 struct sigmatel_spec *spec = codec->spec;
2378 struct hda_jack_tbl *jack;
2379
2380 if (action != HDA_FIXUP_ACT_PRE_PROBE)
2381 return;
2382
2383 /* Enable VREF power saving on GPIO1 detect */
2384 snd_hda_codec_write_cache(codec, codec->afg, 0,
2385 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
2386 snd_hda_jack_detect_enable_callback(codec, codec->afg,
2387 STAC_VREF_EVENT,
2388 stac_vref_event);
2389 jack = snd_hda_jack_tbl_get(codec, codec->afg);
2390 if (jack)
2391 jack->private_data = 0x02;
2392
2393 spec->gpio_mask |= 0x02;
2394
2395 /* enable internal microphone */
2396 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
2397}
2398
2399static void stac92hd71bxx_fixup_hp_dv4(struct hda_codec *codec,
2400 const struct hda_fixup *fix, int action)
2401{
2402 struct sigmatel_spec *spec = codec->spec;
2403
2404 if (action != HDA_FIXUP_ACT_PRE_PROBE)
2405 return;
2406 spec->gpio_led = 0x01;
2407}
2408
2409static void stac92hd71bxx_fixup_hp_dv5(struct hda_codec *codec,
2410 const struct hda_fixup *fix, int action)
2411{
2412 unsigned int cap;
2413
2414 switch (action) {
2415 case HDA_FIXUP_ACT_PRE_PROBE:
2416 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
2417 break;
2418
2419 case HDA_FIXUP_ACT_PROBE:
2420 /* enable bass on HP dv7 */
2421 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
2422 cap &= AC_GPIO_IO_COUNT;
2423 if (cap >= 6)
2424 stac_add_hp_bass_switch(codec);
2425 break;
2426 }
2427}
2428
2429static void stac92hd71bxx_fixup_hp_hdx(struct hda_codec *codec,
2430 const struct hda_fixup *fix, int action)
2431{
2432 struct sigmatel_spec *spec = codec->spec;
2433
2434 if (action != HDA_FIXUP_ACT_PRE_PROBE)
2435 return;
2436 spec->gpio_led = 0x08;
2437}
2438
2439
2440static void stac92hd71bxx_fixup_hp(struct hda_codec *codec,
2441 const struct hda_fixup *fix, int action)
2442{
2443 struct sigmatel_spec *spec = codec->spec;
2444
2445 if (action != HDA_FIXUP_ACT_PRE_PROBE)
2446 return;
2447
2448 if (hp_blike_system(codec->subsystem_id)) {
2449 unsigned int pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
2450 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
2451 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
2452 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
2453 /* It was changed in the BIOS to just satisfy MS DTM.
2454 * Lets turn it back into slaved HP
2455 */
2456 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
2457 | (AC_JACK_HP_OUT <<
2458 AC_DEFCFG_DEVICE_SHIFT);
2459 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
2460 | AC_DEFCFG_SEQUENCE)))
2461 | 0x1f;
2462 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
2463 }
2464 }
2465
2466 if (find_mute_led_cfg(codec, 1))
2467 snd_printd("mute LED gpio %d polarity %d\n",
2468 spec->gpio_led,
2469 spec->gpio_led_polarity);
2470
2471}
2472
2473static const struct hda_fixup stac92hd71bxx_fixups[] = {
2474 [STAC_92HD71BXX_REF] = {
2475 .type = HDA_FIXUP_FUNC,
2476 .v.func = stac92hd71bxx_fixup_ref,
2477 },
2478 [STAC_DELL_M4_1] = {
2479 .type = HDA_FIXUP_PINS,
2480 .v.pins = dell_m4_1_pin_configs,
2481 },
2482 [STAC_DELL_M4_2] = {
2483 .type = HDA_FIXUP_PINS,
2484 .v.pins = dell_m4_2_pin_configs,
2485 },
2486 [STAC_DELL_M4_3] = {
2487 .type = HDA_FIXUP_PINS,
2488 .v.pins = dell_m4_3_pin_configs,
2489 },
2490 [STAC_HP_M4] = {
2491 .type = HDA_FIXUP_FUNC,
2492 .v.func = stac92hd71bxx_fixup_hp_m4,
2493 .chained = true,
2494 .chain_id = STAC_92HD71BXX_HP,
2495 },
2496 [STAC_HP_DV4] = {
2497 .type = HDA_FIXUP_FUNC,
2498 .v.func = stac92hd71bxx_fixup_hp_dv4,
2499 .chained = true,
2500 .chain_id = STAC_HP_DV5,
2501 },
2502 [STAC_HP_DV5] = {
2503 .type = HDA_FIXUP_FUNC,
2504 .v.func = stac92hd71bxx_fixup_hp_dv5,
2505 .chained = true,
2506 .chain_id = STAC_92HD71BXX_HP,
2507 },
2508 [STAC_HP_HDX] = {
2509 .type = HDA_FIXUP_FUNC,
2510 .v.func = stac92hd71bxx_fixup_hp_hdx,
2511 .chained = true,
2512 .chain_id = STAC_92HD71BXX_HP,
2513 },
2514 [STAC_92HD71BXX_HP] = {
2515 .type = HDA_FIXUP_FUNC,
2516 .v.func = stac92hd71bxx_fixup_hp,
2517 },
1816}; 2518};
1817 2519
1818static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = { 2520static const struct hda_model_fixup stac92hd71bxx_models[] = {
1819 [STAC_92HD71BXX_AUTO] = "auto", 2521 { .id = STAC_92HD71BXX_REF, .name = "ref" },
1820 [STAC_92HD71BXX_REF] = "ref", 2522 { .id = STAC_DELL_M4_1, .name = "dell-m4-1" },
1821 [STAC_DELL_M4_1] = "dell-m4-1", 2523 { .id = STAC_DELL_M4_2, .name = "dell-m4-2" },
1822 [STAC_DELL_M4_2] = "dell-m4-2", 2524 { .id = STAC_DELL_M4_3, .name = "dell-m4-3" },
1823 [STAC_DELL_M4_3] = "dell-m4-3", 2525 { .id = STAC_HP_M4, .name = "hp-m4" },
1824 [STAC_HP_M4] = "hp-m4", 2526 { .id = STAC_HP_DV4, .name = "hp-dv4" },
1825 [STAC_HP_DV4] = "hp-dv4", 2527 { .id = STAC_HP_DV5, .name = "hp-dv5" },
1826 [STAC_HP_DV5] = "hp-dv5", 2528 { .id = STAC_HP_HDX, .name = "hp-hdx" },
1827 [STAC_HP_HDX] = "hp-hdx", 2529 { .id = STAC_HP_DV4, .name = "hp-dv4-1222nr" },
1828 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr", 2530 {}
1829}; 2531};
1830 2532
1831static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = { 2533static const struct snd_pci_quirk stac92hd71bxx_fixup_tbl[] = {
1832 /* SigmaTel reference board */ 2534 /* SigmaTel reference board */
1833 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 2535 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1834 "DFI LanParty", STAC_92HD71BXX_REF), 2536 "DFI LanParty", STAC_92HD71BXX_REF),
1835 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, 2537 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1836 "DFI LanParty", STAC_92HD71BXX_REF), 2538 "DFI LanParty", STAC_92HD71BXX_REF),
1837 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1838 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1839 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720, 2539 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1840 "HP", STAC_HP_DV5), 2540 "HP", STAC_HP_DV5),
1841 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080, 2541 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
@@ -1858,6 +2558,7 @@ static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1858 "HP DV6", STAC_HP_DV5), 2558 "HP DV6", STAC_HP_DV5),
1859 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010, 2559 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1860 "HP", STAC_HP_DV5), 2560 "HP", STAC_HP_DV5),
2561 SND_PCI_QUIRK_VENDOR(PCI_VENDOR_ID_HP, "HP", STAC_92HD71BXX_HP),
1861 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233, 2562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1862 "unknown Dell", STAC_DELL_M4_1), 2563 "unknown Dell", STAC_DELL_M4_1),
1863 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234, 2564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
@@ -1885,10 +2586,18 @@ static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1885 {} /* terminator */ 2586 {} /* terminator */
1886}; 2587};
1887 2588
1888static const unsigned int ref922x_pin_configs[10] = { 2589static const struct hda_pintbl ref922x_pin_configs[] = {
1889 0x01014010, 0x01016011, 0x01012012, 0x0221401f, 2590 { 0x0a, 0x01014010 },
1890 0x01813122, 0x01011014, 0x01441030, 0x01c41030, 2591 { 0x0b, 0x01016011 },
1891 0x40000100, 0x40000100, 2592 { 0x0c, 0x01012012 },
2593 { 0x0d, 0x0221401f },
2594 { 0x0e, 0x01813122 },
2595 { 0x0f, 0x01011014 },
2596 { 0x10, 0x01441030 },
2597 { 0x11, 0x01c41030 },
2598 { 0x15, 0x40000100 },
2599 { 0x1b, 0x40000100 },
2600 {}
1892}; 2601};
1893 2602
1894/* 2603/*
@@ -1899,10 +2608,18 @@ static const unsigned int ref922x_pin_configs[10] = {
1899 102801D1 2608 102801D1
1900 102801D2 2609 102801D2
1901*/ 2610*/
1902static const unsigned int dell_922x_d81_pin_configs[10] = { 2611static const struct hda_pintbl dell_922x_d81_pin_configs[] = {
1903 0x02214030, 0x01a19021, 0x01111012, 0x01114010, 2612 { 0x0a, 0x02214030 },
1904 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1, 2613 { 0x0b, 0x01a19021 },
1905 0x01813122, 0x400001f2, 2614 { 0x0c, 0x01111012 },
2615 { 0x0d, 0x01114010 },
2616 { 0x0e, 0x02a19020 },
2617 { 0x0f, 0x01117011 },
2618 { 0x10, 0x400001f0 },
2619 { 0x11, 0x400001f1 },
2620 { 0x15, 0x01813122 },
2621 { 0x1b, 0x400001f2 },
2622 {}
1906}; 2623};
1907 2624
1908/* 2625/*
@@ -1910,130 +2627,311 @@ static const unsigned int dell_922x_d81_pin_configs[10] = {
1910 102801AC 2627 102801AC
1911 102801D0 2628 102801D0
1912*/ 2629*/
1913static const unsigned int dell_922x_d82_pin_configs[10] = { 2630static const struct hda_pintbl dell_922x_d82_pin_configs[] = {
1914 0x02214030, 0x01a19021, 0x01111012, 0x01114010, 2631 { 0x0a, 0x02214030 },
1915 0x02a19020, 0x01117011, 0x01451140, 0x400001f0, 2632 { 0x0b, 0x01a19021 },
1916 0x01813122, 0x400001f1, 2633 { 0x0c, 0x01111012 },
2634 { 0x0d, 0x01114010 },
2635 { 0x0e, 0x02a19020 },
2636 { 0x0f, 0x01117011 },
2637 { 0x10, 0x01451140 },
2638 { 0x11, 0x400001f0 },
2639 { 0x15, 0x01813122 },
2640 { 0x1b, 0x400001f1 },
2641 {}
1917}; 2642};
1918 2643
1919/* 2644/*
1920 STAC 922X pin configs for 2645 STAC 922X pin configs for
1921 102801BF 2646 102801BF
1922*/ 2647*/
1923static const unsigned int dell_922x_m81_pin_configs[10] = { 2648static const struct hda_pintbl dell_922x_m81_pin_configs[] = {
1924 0x0321101f, 0x01112024, 0x01111222, 0x91174220, 2649 { 0x0a, 0x0321101f },
1925 0x03a11050, 0x01116221, 0x90a70330, 0x01452340, 2650 { 0x0b, 0x01112024 },
1926 0x40C003f1, 0x405003f0, 2651 { 0x0c, 0x01111222 },
2652 { 0x0d, 0x91174220 },
2653 { 0x0e, 0x03a11050 },
2654 { 0x0f, 0x01116221 },
2655 { 0x10, 0x90a70330 },
2656 { 0x11, 0x01452340 },
2657 { 0x15, 0x40C003f1 },
2658 { 0x1b, 0x405003f0 },
2659 {}
1927}; 2660};
1928 2661
1929/* 2662/*
1930 STAC 9221 A1 pin configs for 2663 STAC 9221 A1 pin configs for
1931 102801D7 (Dell XPS M1210) 2664 102801D7 (Dell XPS M1210)
1932*/ 2665*/
1933static const unsigned int dell_922x_m82_pin_configs[10] = { 2666static const struct hda_pintbl dell_922x_m82_pin_configs[] = {
1934 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310, 2667 { 0x0a, 0x02211211 },
1935 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2, 2668 { 0x0b, 0x408103ff },
1936 0x508003f3, 0x405003f4, 2669 { 0x0c, 0x02a1123e },
2670 { 0x0d, 0x90100310 },
2671 { 0x0e, 0x408003f1 },
2672 { 0x0f, 0x0221121f },
2673 { 0x10, 0x03451340 },
2674 { 0x11, 0x40c003f2 },
2675 { 0x15, 0x508003f3 },
2676 { 0x1b, 0x405003f4 },
2677 {}
1937}; 2678};
1938 2679
1939static const unsigned int d945gtp3_pin_configs[10] = { 2680static const struct hda_pintbl d945gtp3_pin_configs[] = {
1940 0x0221401f, 0x01a19022, 0x01813021, 0x01014010, 2681 { 0x0a, 0x0221401f },
1941 0x40000100, 0x40000100, 0x40000100, 0x40000100, 2682 { 0x0b, 0x01a19022 },
1942 0x02a19120, 0x40000100, 2683 { 0x0c, 0x01813021 },
2684 { 0x0d, 0x01014010 },
2685 { 0x0e, 0x40000100 },
2686 { 0x0f, 0x40000100 },
2687 { 0x10, 0x40000100 },
2688 { 0x11, 0x40000100 },
2689 { 0x15, 0x02a19120 },
2690 { 0x1b, 0x40000100 },
2691 {}
1943}; 2692};
1944 2693
1945static const unsigned int d945gtp5_pin_configs[10] = { 2694static const struct hda_pintbl d945gtp5_pin_configs[] = {
1946 0x0221401f, 0x01011012, 0x01813024, 0x01014010, 2695 { 0x0a, 0x0221401f },
1947 0x01a19021, 0x01016011, 0x01452130, 0x40000100, 2696 { 0x0b, 0x01011012 },
1948 0x02a19320, 0x40000100, 2697 { 0x0c, 0x01813024 },
2698 { 0x0d, 0x01014010 },
2699 { 0x0e, 0x01a19021 },
2700 { 0x0f, 0x01016011 },
2701 { 0x10, 0x01452130 },
2702 { 0x11, 0x40000100 },
2703 { 0x15, 0x02a19320 },
2704 { 0x1b, 0x40000100 },
2705 {}
1949}; 2706};
1950 2707
1951static const unsigned int intel_mac_v1_pin_configs[10] = { 2708static const struct hda_pintbl intel_mac_v1_pin_configs[] = {
1952 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd, 2709 { 0x0a, 0x0121e21f },
1953 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240, 2710 { 0x0b, 0x400000ff },
1954 0x400000fc, 0x400000fb, 2711 { 0x0c, 0x9017e110 },
2712 { 0x0d, 0x400000fd },
2713 { 0x0e, 0x400000fe },
2714 { 0x0f, 0x0181e020 },
2715 { 0x10, 0x1145e030 },
2716 { 0x11, 0x11c5e240 },
2717 { 0x15, 0x400000fc },
2718 { 0x1b, 0x400000fb },
2719 {}
1955}; 2720};
1956 2721
1957static const unsigned int intel_mac_v2_pin_configs[10] = { 2722static const struct hda_pintbl intel_mac_v2_pin_configs[] = {
1958 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd, 2723 { 0x0a, 0x0121e21f },
1959 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa, 2724 { 0x0b, 0x90a7012e },
1960 0x400000fc, 0x400000fb, 2725 { 0x0c, 0x9017e110 },
2726 { 0x0d, 0x400000fd },
2727 { 0x0e, 0x400000fe },
2728 { 0x0f, 0x0181e020 },
2729 { 0x10, 0x1145e230 },
2730 { 0x11, 0x500000fa },
2731 { 0x15, 0x400000fc },
2732 { 0x1b, 0x400000fb },
2733 {}
1961}; 2734};
1962 2735
1963static const unsigned int intel_mac_v3_pin_configs[10] = { 2736static const struct hda_pintbl intel_mac_v3_pin_configs[] = {
1964 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd, 2737 { 0x0a, 0x0121e21f },
1965 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240, 2738 { 0x0b, 0x90a7012e },
1966 0x400000fc, 0x400000fb, 2739 { 0x0c, 0x9017e110 },
2740 { 0x0d, 0x400000fd },
2741 { 0x0e, 0x400000fe },
2742 { 0x0f, 0x0181e020 },
2743 { 0x10, 0x1145e230 },
2744 { 0x11, 0x11c5e240 },
2745 { 0x15, 0x400000fc },
2746 { 0x1b, 0x400000fb },
2747 {}
1967}; 2748};
1968 2749
1969static const unsigned int intel_mac_v4_pin_configs[10] = { 2750static const struct hda_pintbl intel_mac_v4_pin_configs[] = {
1970 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f, 2751 { 0x0a, 0x0321e21f },
1971 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240, 2752 { 0x0b, 0x03a1e02e },
1972 0x400000fc, 0x400000fb, 2753 { 0x0c, 0x9017e110 },
2754 { 0x0d, 0x9017e11f },
2755 { 0x0e, 0x400000fe },
2756 { 0x0f, 0x0381e020 },
2757 { 0x10, 0x1345e230 },
2758 { 0x11, 0x13c5e240 },
2759 { 0x15, 0x400000fc },
2760 { 0x1b, 0x400000fb },
2761 {}
1973}; 2762};
1974 2763
1975static const unsigned int intel_mac_v5_pin_configs[10] = { 2764static const struct hda_pintbl intel_mac_v5_pin_configs[] = {
1976 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f, 2765 { 0x0a, 0x0321e21f },
1977 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240, 2766 { 0x0b, 0x03a1e02e },
1978 0x400000fc, 0x400000fb, 2767 { 0x0c, 0x9017e110 },
2768 { 0x0d, 0x9017e11f },
2769 { 0x0e, 0x400000fe },
2770 { 0x0f, 0x0381e020 },
2771 { 0x10, 0x1345e230 },
2772 { 0x11, 0x13c5e240 },
2773 { 0x15, 0x400000fc },
2774 { 0x1b, 0x400000fb },
2775 {}
1979}; 2776};
1980 2777
1981static const unsigned int ecs202_pin_configs[10] = { 2778static const struct hda_pintbl ecs202_pin_configs[] = {
1982 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010, 2779 { 0x0a, 0x0221401f },
1983 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1, 2780 { 0x0b, 0x02a19020 },
1984 0x9037012e, 0x40e000f2, 2781 { 0x0c, 0x01a19020 },
2782 { 0x0d, 0x01114010 },
2783 { 0x0e, 0x408000f0 },
2784 { 0x0f, 0x01813022 },
2785 { 0x10, 0x074510a0 },
2786 { 0x11, 0x40c400f1 },
2787 { 0x15, 0x9037012e },
2788 { 0x1b, 0x40e000f2 },
2789 {}
1985}; 2790};
1986 2791
1987static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = { 2792/* codec SSIDs for Intel Mac sharing the same PCI SSID 8384:7680 */
1988 [STAC_D945_REF] = ref922x_pin_configs, 2793static const struct snd_pci_quirk stac922x_intel_mac_fixup_tbl[] = {
1989 [STAC_D945GTP3] = d945gtp3_pin_configs, 2794 SND_PCI_QUIRK(0x106b, 0x0800, "Mac", STAC_INTEL_MAC_V1),
1990 [STAC_D945GTP5] = d945gtp5_pin_configs, 2795 SND_PCI_QUIRK(0x106b, 0x0600, "Mac", STAC_INTEL_MAC_V2),
1991 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs, 2796 SND_PCI_QUIRK(0x106b, 0x0700, "Mac", STAC_INTEL_MAC_V2),
1992 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs, 2797 SND_PCI_QUIRK(0x106b, 0x0e00, "Mac", STAC_INTEL_MAC_V3),
1993 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs, 2798 SND_PCI_QUIRK(0x106b, 0x0f00, "Mac", STAC_INTEL_MAC_V3),
1994 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs, 2799 SND_PCI_QUIRK(0x106b, 0x1600, "Mac", STAC_INTEL_MAC_V3),
1995 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs, 2800 SND_PCI_QUIRK(0x106b, 0x1700, "Mac", STAC_INTEL_MAC_V3),
1996 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs, 2801 SND_PCI_QUIRK(0x106b, 0x0200, "Mac", STAC_INTEL_MAC_V3),
1997 /* for backward compatibility */ 2802 SND_PCI_QUIRK(0x106b, 0x1e00, "Mac", STAC_INTEL_MAC_V3),
1998 [STAC_MACMINI] = intel_mac_v3_pin_configs, 2803 SND_PCI_QUIRK(0x106b, 0x1a00, "Mac", STAC_INTEL_MAC_V4),
1999 [STAC_MACBOOK] = intel_mac_v5_pin_configs, 2804 SND_PCI_QUIRK(0x106b, 0x0a00, "Mac", STAC_INTEL_MAC_V5),
2000 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs, 2805 SND_PCI_QUIRK(0x106b, 0x2200, "Mac", STAC_INTEL_MAC_V5),
2001 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs, 2806 {}
2002 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2003 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
2004 [STAC_ECS_202] = ecs202_pin_configs,
2005 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2006 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2007 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2008 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
2009}; 2807};
2010 2808
2011static const char * const stac922x_models[STAC_922X_MODELS] = { 2809static const struct hda_fixup stac922x_fixups[];
2012 [STAC_922X_AUTO] = "auto", 2810
2013 [STAC_D945_REF] = "ref", 2811/* remap the fixup from codec SSID and apply it */
2014 [STAC_D945GTP5] = "5stack", 2812static void stac922x_fixup_intel_mac_auto(struct hda_codec *codec,
2015 [STAC_D945GTP3] = "3stack", 2813 const struct hda_fixup *fix,
2016 [STAC_INTEL_MAC_V1] = "intel-mac-v1", 2814 int action)
2017 [STAC_INTEL_MAC_V2] = "intel-mac-v2", 2815{
2018 [STAC_INTEL_MAC_V3] = "intel-mac-v3", 2816 if (action != HDA_FIXUP_ACT_PRE_PROBE)
2019 [STAC_INTEL_MAC_V4] = "intel-mac-v4", 2817 return;
2020 [STAC_INTEL_MAC_V5] = "intel-mac-v5", 2818 snd_hda_pick_fixup(codec, NULL, stac922x_intel_mac_fixup_tbl,
2021 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto", 2819 stac922x_fixups);
2820 if (codec->fixup_id != STAC_INTEL_MAC_AUTO)
2821 snd_hda_apply_fixup(codec, action);
2822}
2823
2824static void stac922x_fixup_intel_mac_gpio(struct hda_codec *codec,
2825 const struct hda_fixup *fix,
2826 int action)
2827{
2828 struct sigmatel_spec *spec = codec->spec;
2829
2830 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2831 spec->gpio_mask = spec->gpio_dir = 0x03;
2832 spec->gpio_data = 0x03;
2833 }
2834}
2835
2836static const struct hda_fixup stac922x_fixups[] = {
2837 [STAC_D945_REF] = {
2838 .type = HDA_FIXUP_PINS,
2839 .v.pins = ref922x_pin_configs,
2840 },
2841 [STAC_D945GTP3] = {
2842 .type = HDA_FIXUP_PINS,
2843 .v.pins = d945gtp3_pin_configs,
2844 },
2845 [STAC_D945GTP5] = {
2846 .type = HDA_FIXUP_PINS,
2847 .v.pins = d945gtp5_pin_configs,
2848 },
2849 [STAC_INTEL_MAC_AUTO] = {
2850 .type = HDA_FIXUP_FUNC,
2851 .v.func = stac922x_fixup_intel_mac_auto,
2852 },
2853 [STAC_INTEL_MAC_V1] = {
2854 .type = HDA_FIXUP_PINS,
2855 .v.pins = intel_mac_v1_pin_configs,
2856 .chained = true,
2857 .chain_id = STAC_922X_INTEL_MAC_GPIO,
2858 },
2859 [STAC_INTEL_MAC_V2] = {
2860 .type = HDA_FIXUP_PINS,
2861 .v.pins = intel_mac_v2_pin_configs,
2862 .chained = true,
2863 .chain_id = STAC_922X_INTEL_MAC_GPIO,
2864 },
2865 [STAC_INTEL_MAC_V3] = {
2866 .type = HDA_FIXUP_PINS,
2867 .v.pins = intel_mac_v3_pin_configs,
2868 .chained = true,
2869 .chain_id = STAC_922X_INTEL_MAC_GPIO,
2870 },
2871 [STAC_INTEL_MAC_V4] = {
2872 .type = HDA_FIXUP_PINS,
2873 .v.pins = intel_mac_v4_pin_configs,
2874 .chained = true,
2875 .chain_id = STAC_922X_INTEL_MAC_GPIO,
2876 },
2877 [STAC_INTEL_MAC_V5] = {
2878 .type = HDA_FIXUP_PINS,
2879 .v.pins = intel_mac_v5_pin_configs,
2880 .chained = true,
2881 .chain_id = STAC_922X_INTEL_MAC_GPIO,
2882 },
2883 [STAC_922X_INTEL_MAC_GPIO] = {
2884 .type = HDA_FIXUP_FUNC,
2885 .v.func = stac922x_fixup_intel_mac_gpio,
2886 },
2887 [STAC_ECS_202] = {
2888 .type = HDA_FIXUP_PINS,
2889 .v.pins = ecs202_pin_configs,
2890 },
2891 [STAC_922X_DELL_D81] = {
2892 .type = HDA_FIXUP_PINS,
2893 .v.pins = dell_922x_d81_pin_configs,
2894 },
2895 [STAC_922X_DELL_D82] = {
2896 .type = HDA_FIXUP_PINS,
2897 .v.pins = dell_922x_d82_pin_configs,
2898 },
2899 [STAC_922X_DELL_M81] = {
2900 .type = HDA_FIXUP_PINS,
2901 .v.pins = dell_922x_m81_pin_configs,
2902 },
2903 [STAC_922X_DELL_M82] = {
2904 .type = HDA_FIXUP_PINS,
2905 .v.pins = dell_922x_m82_pin_configs,
2906 },
2907};
2908
2909static const struct hda_model_fixup stac922x_models[] = {
2910 { .id = STAC_D945_REF, .name = "ref" },
2911 { .id = STAC_D945GTP5, .name = "5stack" },
2912 { .id = STAC_D945GTP3, .name = "3stack" },
2913 { .id = STAC_INTEL_MAC_V1, .name = "intel-mac-v1" },
2914 { .id = STAC_INTEL_MAC_V2, .name = "intel-mac-v2" },
2915 { .id = STAC_INTEL_MAC_V3, .name = "intel-mac-v3" },
2916 { .id = STAC_INTEL_MAC_V4, .name = "intel-mac-v4" },
2917 { .id = STAC_INTEL_MAC_V5, .name = "intel-mac-v5" },
2918 { .id = STAC_INTEL_MAC_AUTO, .name = "intel-mac-auto" },
2919 { .id = STAC_ECS_202, .name = "ecs202" },
2920 { .id = STAC_922X_DELL_D81, .name = "dell-d81" },
2921 { .id = STAC_922X_DELL_D82, .name = "dell-d82" },
2922 { .id = STAC_922X_DELL_M81, .name = "dell-m81" },
2923 { .id = STAC_922X_DELL_M82, .name = "dell-m82" },
2022 /* for backward compatibility */ 2924 /* for backward compatibility */
2023 [STAC_MACMINI] = "macmini", 2925 { .id = STAC_INTEL_MAC_V3, .name = "macmini" },
2024 [STAC_MACBOOK] = "macbook", 2926 { .id = STAC_INTEL_MAC_V5, .name = "macbook" },
2025 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1", 2927 { .id = STAC_INTEL_MAC_V3, .name = "macbook-pro-v1" },
2026 [STAC_MACBOOK_PRO_V2] = "macbook-pro", 2928 { .id = STAC_INTEL_MAC_V3, .name = "macbook-pro" },
2027 [STAC_IMAC_INTEL] = "imac-intel", 2929 { .id = STAC_INTEL_MAC_V2, .name = "imac-intel" },
2028 [STAC_IMAC_INTEL_20] = "imac-intel-20", 2930 { .id = STAC_INTEL_MAC_V3, .name = "imac-intel-20" },
2029 [STAC_ECS_202] = "ecs202", 2931 {}
2030 [STAC_922X_DELL_D81] = "dell-d81",
2031 [STAC_922X_DELL_D82] = "dell-d82",
2032 [STAC_922X_DELL_M81] = "dell-m81",
2033 [STAC_922X_DELL_M82] = "dell-m82",
2034}; 2932};
2035 2933
2036static const struct snd_pci_quirk stac922x_cfg_tbl[] = { 2934static const struct snd_pci_quirk stac922x_fixup_tbl[] = {
2037 /* SigmaTel reference board */ 2935 /* SigmaTel reference board */
2038 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 2936 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2039 "DFI LanParty", STAC_D945_REF), 2937 "DFI LanParty", STAC_D945_REF),
@@ -2096,9 +2994,10 @@ static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204, 2994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2097 "Intel D945", STAC_D945_REF), 2995 "Intel D945", STAC_D945_REF),
2098 /* other systems */ 2996 /* other systems */
2997
2099 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */ 2998 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2100 SND_PCI_QUIRK(0x8384, 0x7680, 2999 SND_PCI_QUIRK(0x8384, 0x7680, "Mac", STAC_INTEL_MAC_AUTO),
2101 "Mac", STAC_INTEL_MAC_AUTO), 3000
2102 /* Dell systems */ 3001 /* Dell systems */
2103 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7, 3002 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2104 "unknown Dell", STAC_922X_DELL_D81), 3003 "unknown Dell", STAC_922X_DELL_D81),
@@ -2124,65 +3023,229 @@ static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
2124 {} /* terminator */ 3023 {} /* terminator */
2125}; 3024};
2126 3025
2127static const unsigned int ref927x_pin_configs[14] = { 3026static const struct hda_pintbl ref927x_pin_configs[] = {
2128 0x02214020, 0x02a19080, 0x0181304e, 0x01014010, 3027 { 0x0a, 0x02214020 },
2129 0x01a19040, 0x01011012, 0x01016011, 0x0101201f, 3028 { 0x0b, 0x02a19080 },
2130 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070, 3029 { 0x0c, 0x0181304e },
2131 0x01c42190, 0x40000100, 3030 { 0x0d, 0x01014010 },
3031 { 0x0e, 0x01a19040 },
3032 { 0x0f, 0x01011012 },
3033 { 0x10, 0x01016011 },
3034 { 0x11, 0x0101201f },
3035 { 0x12, 0x183301f0 },
3036 { 0x13, 0x18a001f0 },
3037 { 0x14, 0x18a001f0 },
3038 { 0x21, 0x01442070 },
3039 { 0x22, 0x01c42190 },
3040 { 0x23, 0x40000100 },
3041 {}
2132}; 3042};
2133 3043
2134static const unsigned int d965_3st_pin_configs[14] = { 3044static const struct hda_pintbl d965_3st_pin_configs[] = {
2135 0x0221401f, 0x02a19120, 0x40000100, 0x01014011, 3045 { 0x0a, 0x0221401f },
2136 0x01a19021, 0x01813024, 0x40000100, 0x40000100, 3046 { 0x0b, 0x02a19120 },
2137 0x40000100, 0x40000100, 0x40000100, 0x40000100, 3047 { 0x0c, 0x40000100 },
2138 0x40000100, 0x40000100 3048 { 0x0d, 0x01014011 },
3049 { 0x0e, 0x01a19021 },
3050 { 0x0f, 0x01813024 },
3051 { 0x10, 0x40000100 },
3052 { 0x11, 0x40000100 },
3053 { 0x12, 0x40000100 },
3054 { 0x13, 0x40000100 },
3055 { 0x14, 0x40000100 },
3056 { 0x21, 0x40000100 },
3057 { 0x22, 0x40000100 },
3058 { 0x23, 0x40000100 },
3059 {}
2139}; 3060};
2140 3061
2141static const unsigned int d965_5st_pin_configs[14] = { 3062static const struct hda_pintbl d965_5st_pin_configs[] = {
2142 0x02214020, 0x02a19080, 0x0181304e, 0x01014010, 3063 { 0x0a, 0x02214020 },
2143 0x01a19040, 0x01011012, 0x01016011, 0x40000100, 3064 { 0x0b, 0x02a19080 },
2144 0x40000100, 0x40000100, 0x40000100, 0x01442070, 3065 { 0x0c, 0x0181304e },
2145 0x40000100, 0x40000100 3066 { 0x0d, 0x01014010 },
3067 { 0x0e, 0x01a19040 },
3068 { 0x0f, 0x01011012 },
3069 { 0x10, 0x01016011 },
3070 { 0x11, 0x40000100 },
3071 { 0x12, 0x40000100 },
3072 { 0x13, 0x40000100 },
3073 { 0x14, 0x40000100 },
3074 { 0x21, 0x01442070 },
3075 { 0x22, 0x40000100 },
3076 { 0x23, 0x40000100 },
3077 {}
2146}; 3078};
2147 3079
2148static const unsigned int d965_5st_no_fp_pin_configs[14] = { 3080static const struct hda_pintbl d965_5st_no_fp_pin_configs[] = {
2149 0x40000100, 0x40000100, 0x0181304e, 0x01014010, 3081 { 0x0a, 0x40000100 },
2150 0x01a19040, 0x01011012, 0x01016011, 0x40000100, 3082 { 0x0b, 0x40000100 },
2151 0x40000100, 0x40000100, 0x40000100, 0x01442070, 3083 { 0x0c, 0x0181304e },
2152 0x40000100, 0x40000100 3084 { 0x0d, 0x01014010 },
3085 { 0x0e, 0x01a19040 },
3086 { 0x0f, 0x01011012 },
3087 { 0x10, 0x01016011 },
3088 { 0x11, 0x40000100 },
3089 { 0x12, 0x40000100 },
3090 { 0x13, 0x40000100 },
3091 { 0x14, 0x40000100 },
3092 { 0x21, 0x01442070 },
3093 { 0x22, 0x40000100 },
3094 { 0x23, 0x40000100 },
3095 {}
2153}; 3096};
2154 3097
2155static const unsigned int dell_3st_pin_configs[14] = { 3098static const struct hda_pintbl dell_3st_pin_configs[] = {
2156 0x02211230, 0x02a11220, 0x01a19040, 0x01114210, 3099 { 0x0a, 0x02211230 },
2157 0x01111212, 0x01116211, 0x01813050, 0x01112214, 3100 { 0x0b, 0x02a11220 },
2158 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb, 3101 { 0x0c, 0x01a19040 },
2159 0x40c003fc, 0x40000100 3102 { 0x0d, 0x01114210 },
3103 { 0x0e, 0x01111212 },
3104 { 0x0f, 0x01116211 },
3105 { 0x10, 0x01813050 },
3106 { 0x11, 0x01112214 },
3107 { 0x12, 0x403003fa },
3108 { 0x13, 0x90a60040 },
3109 { 0x14, 0x90a60040 },
3110 { 0x21, 0x404003fb },
3111 { 0x22, 0x40c003fc },
3112 { 0x23, 0x40000100 },
3113 {}
2160}; 3114};
2161 3115
2162static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = { 3116static void stac927x_fixup_ref_no_jd(struct hda_codec *codec,
2163 [STAC_D965_REF_NO_JD] = ref927x_pin_configs, 3117 const struct hda_fixup *fix, int action)
2164 [STAC_D965_REF] = ref927x_pin_configs, 3118{
2165 [STAC_D965_3ST] = d965_3st_pin_configs, 3119 /* no jack detecion for ref-no-jd model */
2166 [STAC_D965_5ST] = d965_5st_pin_configs, 3120 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2167 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs, 3121 codec->no_jack_detect = 1;
2168 [STAC_DELL_3ST] = dell_3st_pin_configs, 3122}
2169 [STAC_DELL_BIOS] = NULL, 3123
2170 [STAC_927X_VOLKNOB] = NULL, 3124static void stac927x_fixup_ref(struct hda_codec *codec,
3125 const struct hda_fixup *fix, int action)
3126{
3127 struct sigmatel_spec *spec = codec->spec;
3128
3129 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3130 snd_hda_apply_pincfgs(codec, ref927x_pin_configs);
3131 spec->eapd_mask = spec->gpio_mask = 0;
3132 spec->gpio_dir = spec->gpio_data = 0;
3133 }
3134}
3135
3136static void stac927x_fixup_dell_dmic(struct hda_codec *codec,
3137 const struct hda_fixup *fix, int action)
3138{
3139 struct sigmatel_spec *spec = codec->spec;
3140
3141 if (action != HDA_FIXUP_ACT_PRE_PROBE)
3142 return;
3143
3144 if (codec->subsystem_id != 0x1028022f) {
3145 /* GPIO2 High = Enable EAPD */
3146 spec->eapd_mask = spec->gpio_mask = 0x04;
3147 spec->gpio_dir = spec->gpio_data = 0x04;
3148 }
3149
3150 snd_hda_add_verbs(codec, dell_3st_core_init);
3151 spec->volknob_init = 1;
3152}
3153
3154static void stac927x_fixup_volknob(struct hda_codec *codec,
3155 const struct hda_fixup *fix, int action)
3156{
3157 struct sigmatel_spec *spec = codec->spec;
3158
3159 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3160 snd_hda_add_verbs(codec, stac927x_volknob_core_init);
3161 spec->volknob_init = 1;
3162 }
3163}
3164
3165static const struct hda_fixup stac927x_fixups[] = {
3166 [STAC_D965_REF_NO_JD] = {
3167 .type = HDA_FIXUP_FUNC,
3168 .v.func = stac927x_fixup_ref_no_jd,
3169 .chained = true,
3170 .chain_id = STAC_D965_REF,
3171 },
3172 [STAC_D965_REF] = {
3173 .type = HDA_FIXUP_FUNC,
3174 .v.func = stac927x_fixup_ref,
3175 },
3176 [STAC_D965_3ST] = {
3177 .type = HDA_FIXUP_PINS,
3178 .v.pins = d965_3st_pin_configs,
3179 .chained = true,
3180 .chain_id = STAC_D965_VERBS,
3181 },
3182 [STAC_D965_5ST] = {
3183 .type = HDA_FIXUP_PINS,
3184 .v.pins = d965_5st_pin_configs,
3185 .chained = true,
3186 .chain_id = STAC_D965_VERBS,
3187 },
3188 [STAC_D965_VERBS] = {
3189 .type = HDA_FIXUP_VERBS,
3190 .v.verbs = d965_core_init,
3191 },
3192 [STAC_D965_5ST_NO_FP] = {
3193 .type = HDA_FIXUP_PINS,
3194 .v.pins = d965_5st_no_fp_pin_configs,
3195 },
3196 [STAC_DELL_3ST] = {
3197 .type = HDA_FIXUP_PINS,
3198 .v.pins = dell_3st_pin_configs,
3199 .chained = true,
3200 .chain_id = STAC_927X_DELL_DMIC,
3201 },
3202 [STAC_DELL_BIOS] = {
3203 .type = HDA_FIXUP_PINS,
3204 .v.pins = (const struct hda_pintbl[]) {
3205 /* configure the analog microphone on some laptops */
3206 { 0x0c, 0x90a79130 },
3207 /* correct the front output jack as a hp out */
3208 { 0x0f, 0x0227011f },
3209 /* correct the front input jack as a mic */
3210 { 0x0e, 0x02a79130 },
3211 {}
3212 },
3213 .chained = true,
3214 .chain_id = STAC_927X_DELL_DMIC,
3215 },
3216 [STAC_DELL_BIOS_SPDIF] = {
3217 .type = HDA_FIXUP_PINS,
3218 .v.pins = (const struct hda_pintbl[]) {
3219 /* correct the device field to SPDIF out */
3220 { 0x21, 0x01442070 },
3221 {}
3222 },
3223 .chained = true,
3224 .chain_id = STAC_DELL_BIOS,
3225 },
3226 [STAC_927X_DELL_DMIC] = {
3227 .type = HDA_FIXUP_FUNC,
3228 .v.func = stac927x_fixup_dell_dmic,
3229 },
3230 [STAC_927X_VOLKNOB] = {
3231 .type = HDA_FIXUP_FUNC,
3232 .v.func = stac927x_fixup_volknob,
3233 },
2171}; 3234};
2172 3235
2173static const char * const stac927x_models[STAC_927X_MODELS] = { 3236static const struct hda_model_fixup stac927x_models[] = {
2174 [STAC_927X_AUTO] = "auto", 3237 { .id = STAC_D965_REF_NO_JD, .name = "ref-no-jd" },
2175 [STAC_D965_REF_NO_JD] = "ref-no-jd", 3238 { .id = STAC_D965_REF, .name = "ref" },
2176 [STAC_D965_REF] = "ref", 3239 { .id = STAC_D965_3ST, .name = "3stack" },
2177 [STAC_D965_3ST] = "3stack", 3240 { .id = STAC_D965_5ST, .name = "5stack" },
2178 [STAC_D965_5ST] = "5stack", 3241 { .id = STAC_D965_5ST_NO_FP, .name = "5stack-no-fp" },
2179 [STAC_D965_5ST_NO_FP] = "5stack-no-fp", 3242 { .id = STAC_DELL_3ST, .name = "dell-3stack" },
2180 [STAC_DELL_3ST] = "dell-3stack", 3243 { .id = STAC_DELL_BIOS, .name = "dell-bios" },
2181 [STAC_DELL_BIOS] = "dell-bios", 3244 { .id = STAC_927X_VOLKNOB, .name = "volknob" },
2182 [STAC_927X_VOLKNOB] = "volknob", 3245 {}
2183}; 3246};
2184 3247
2185static const struct snd_pci_quirk stac927x_cfg_tbl[] = { 3248static const struct snd_pci_quirk stac927x_fixup_tbl[] = {
2186 /* SigmaTel reference board */ 3249 /* SigmaTel reference board */
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 3250 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2188 "DFI LanParty", STAC_D965_REF), 3251 "DFI LanParty", STAC_D965_REF),
@@ -2204,12 +3267,12 @@ static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS), 3267 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2205 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS), 3268 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
2206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS), 3269 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2207 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS), 3270 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS_SPDIF),
2208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS), 3271 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2209 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS), 3272 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS), 3273 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2211 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS), 3274 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS), 3275 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS_SPDIF),
2213 /* 965 based 5 stack systems */ 3276 /* 965 based 5 stack systems */
2214 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300, 3277 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2215 "Intel D965", STAC_D965_5ST), 3278 "Intel D965", STAC_D965_5ST),
@@ -2220,10 +3283,20 @@ static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
2220 {} /* terminator */ 3283 {} /* terminator */
2221}; 3284};
2222 3285
2223static const unsigned int ref9205_pin_configs[12] = { 3286static const struct hda_pintbl ref9205_pin_configs[] = {
2224 0x40000100, 0x40000100, 0x01016011, 0x01014010, 3287 { 0x0a, 0x40000100 },
2225 0x01813122, 0x01a19021, 0x01019020, 0x40000100, 3288 { 0x0b, 0x40000100 },
2226 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030 3289 { 0x0c, 0x01016011 },
3290 { 0x0d, 0x01014010 },
3291 { 0x0e, 0x01813122 },
3292 { 0x0f, 0x01a19021 },
3293 { 0x14, 0x01019020 },
3294 { 0x16, 0x40000100 },
3295 { 0x17, 0x90a000f0 },
3296 { 0x18, 0x90a000f0 },
3297 { 0x21, 0x01441030 },
3298 { 0x22, 0x01c41030 },
3299 {}
2227}; 3300};
2228 3301
2229/* 3302/*
@@ -2237,10 +3310,20 @@ static const unsigned int ref9205_pin_configs[12] = {
2237 10280228 (Dell Vostro 1500) 3310 10280228 (Dell Vostro 1500)
2238 10280229 (Dell Vostro 1700) 3311 10280229 (Dell Vostro 1700)
2239*/ 3312*/
2240static const unsigned int dell_9205_m42_pin_configs[12] = { 3313static const struct hda_pintbl dell_9205_m42_pin_configs[] = {
2241 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310, 3314 { 0x0a, 0x0321101F },
2242 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9, 3315 { 0x0b, 0x03A11020 },
2243 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE, 3316 { 0x0c, 0x400003FA },
3317 { 0x0d, 0x90170310 },
3318 { 0x0e, 0x400003FB },
3319 { 0x0f, 0x400003FC },
3320 { 0x14, 0x400003FD },
3321 { 0x16, 0x40F000F9 },
3322 { 0x17, 0x90A60330 },
3323 { 0x18, 0x400003FF },
3324 { 0x21, 0x0144131F },
3325 { 0x22, 0x40C003FE },
3326 {}
2244}; 3327};
2245 3328
2246/* 3329/*
@@ -2253,36 +3336,126 @@ static const unsigned int dell_9205_m42_pin_configs[12] = {
2253 10280200 3336 10280200
2254 10280201 3337 10280201
2255*/ 3338*/
2256static const unsigned int dell_9205_m43_pin_configs[12] = { 3339static const struct hda_pintbl dell_9205_m43_pin_configs[] = {
2257 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310, 3340 { 0x0a, 0x0321101f },
2258 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9, 3341 { 0x0b, 0x03a11020 },
2259 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8, 3342 { 0x0c, 0x90a70330 },
3343 { 0x0d, 0x90170310 },
3344 { 0x0e, 0x400000fe },
3345 { 0x0f, 0x400000ff },
3346 { 0x14, 0x400000fd },
3347 { 0x16, 0x40f000f9 },
3348 { 0x17, 0x400000fa },
3349 { 0x18, 0x400000fc },
3350 { 0x21, 0x0144131f },
3351 { 0x22, 0x40c003f8 },
3352 /* Enable SPDIF in/out */
3353 { 0x1f, 0x01441030 },
3354 { 0x20, 0x1c410030 },
3355 {}
2260}; 3356};
2261 3357
2262static const unsigned int dell_9205_m44_pin_configs[12] = { 3358static const struct hda_pintbl dell_9205_m44_pin_configs[] = {
2263 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310, 3359 { 0x0a, 0x0421101f },
2264 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9, 3360 { 0x0b, 0x04a11020 },
2265 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe, 3361 { 0x0c, 0x400003fa },
3362 { 0x0d, 0x90170310 },
3363 { 0x0e, 0x400003fb },
3364 { 0x0f, 0x400003fc },
3365 { 0x14, 0x400003fd },
3366 { 0x16, 0x400003f9 },
3367 { 0x17, 0x90a60330 },
3368 { 0x18, 0x400003ff },
3369 { 0x21, 0x01441340 },
3370 { 0x22, 0x40c003fe },
3371 {}
2266}; 3372};
2267 3373
2268static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = { 3374static void stac9205_fixup_ref(struct hda_codec *codec,
2269 [STAC_9205_REF] = ref9205_pin_configs, 3375 const struct hda_fixup *fix, int action)
2270 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs, 3376{
2271 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs, 3377 struct sigmatel_spec *spec = codec->spec;
2272 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs, 3378
2273 [STAC_9205_EAPD] = NULL, 3379 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3380 snd_hda_apply_pincfgs(codec, ref9205_pin_configs);
3381 /* SPDIF-In enabled */
3382 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0;
3383 }
3384}
3385
3386static void stac9205_fixup_dell_m43(struct hda_codec *codec,
3387 const struct hda_fixup *fix, int action)
3388{
3389 struct sigmatel_spec *spec = codec->spec;
3390 struct hda_jack_tbl *jack;
3391
3392 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3393 snd_hda_apply_pincfgs(codec, dell_9205_m43_pin_configs);
3394
3395 /* Enable unsol response for GPIO4/Dock HP connection */
3396 snd_hda_codec_write_cache(codec, codec->afg, 0,
3397 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
3398 snd_hda_jack_detect_enable_callback(codec, codec->afg,
3399 STAC_VREF_EVENT,
3400 stac_vref_event);
3401 jack = snd_hda_jack_tbl_get(codec, codec->afg);
3402 if (jack)
3403 jack->private_data = 0x01;
3404
3405 spec->gpio_dir = 0x0b;
3406 spec->eapd_mask = 0x01;
3407 spec->gpio_mask = 0x1b;
3408 spec->gpio_mute = 0x10;
3409 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
3410 * GPIO3 Low = DRM
3411 */
3412 spec->gpio_data = 0x01;
3413 }
3414}
3415
3416static void stac9205_fixup_eapd(struct hda_codec *codec,
3417 const struct hda_fixup *fix, int action)
3418{
3419 struct sigmatel_spec *spec = codec->spec;
3420
3421 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3422 spec->eapd_switch = 0;
3423}
3424
3425static const struct hda_fixup stac9205_fixups[] = {
3426 [STAC_9205_REF] = {
3427 .type = HDA_FIXUP_FUNC,
3428 .v.func = stac9205_fixup_ref,
3429 },
3430 [STAC_9205_DELL_M42] = {
3431 .type = HDA_FIXUP_PINS,
3432 .v.pins = dell_9205_m42_pin_configs,
3433 },
3434 [STAC_9205_DELL_M43] = {
3435 .type = HDA_FIXUP_FUNC,
3436 .v.func = stac9205_fixup_dell_m43,
3437 },
3438 [STAC_9205_DELL_M44] = {
3439 .type = HDA_FIXUP_PINS,
3440 .v.pins = dell_9205_m44_pin_configs,
3441 },
3442 [STAC_9205_EAPD] = {
3443 .type = HDA_FIXUP_FUNC,
3444 .v.func = stac9205_fixup_eapd,
3445 },
3446 {}
2274}; 3447};
2275 3448
2276static const char * const stac9205_models[STAC_9205_MODELS] = { 3449static const struct hda_model_fixup stac9205_models[] = {
2277 [STAC_9205_AUTO] = "auto", 3450 { .id = STAC_9205_REF, .name = "ref" },
2278 [STAC_9205_REF] = "ref", 3451 { .id = STAC_9205_DELL_M42, .name = "dell-m42" },
2279 [STAC_9205_DELL_M42] = "dell-m42", 3452 { .id = STAC_9205_DELL_M43, .name = "dell-m43" },
2280 [STAC_9205_DELL_M43] = "dell-m43", 3453 { .id = STAC_9205_DELL_M44, .name = "dell-m44" },
2281 [STAC_9205_DELL_M44] = "dell-m44", 3454 { .id = STAC_9205_EAPD, .name = "eapd" },
2282 [STAC_9205_EAPD] = "eapd", 3455 {}
2283}; 3456};
2284 3457
2285static const struct snd_pci_quirk stac9205_cfg_tbl[] = { 3458static const struct snd_pci_quirk stac9205_fixup_tbl[] = {
2286 /* SigmaTel reference board */ 3459 /* SigmaTel reference board */
2287 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 3460 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2288 "DFI LanParty", STAC_9205_REF), 3461 "DFI LanParty", STAC_9205_REF),
@@ -2329,1640 +3502,35 @@ static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
2329 {} /* terminator */ 3502 {} /* terminator */
2330}; 3503};
2331 3504
2332static void stac92xx_set_config_regs(struct hda_codec *codec, 3505static int stac_parse_auto_config(struct hda_codec *codec)
2333 const unsigned int *pincfgs)
2334{
2335 int i;
2336 struct sigmatel_spec *spec = codec->spec;
2337
2338 if (!pincfgs)
2339 return;
2340
2341 for (i = 0; i < spec->num_pins; i++)
2342 if (spec->pin_nids[i] && pincfgs[i])
2343 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2344 pincfgs[i]);
2345}
2346
2347/*
2348 * Analog playback callbacks
2349 */
2350static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2351 struct hda_codec *codec,
2352 struct snd_pcm_substream *substream)
2353{
2354 struct sigmatel_spec *spec = codec->spec;
2355 if (spec->stream_delay)
2356 msleep(spec->stream_delay);
2357 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2358 hinfo);
2359}
2360
2361static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2362 struct hda_codec *codec,
2363 unsigned int stream_tag,
2364 unsigned int format,
2365 struct snd_pcm_substream *substream)
2366{
2367 struct sigmatel_spec *spec = codec->spec;
2368 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2369}
2370
2371static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2372 struct hda_codec *codec,
2373 struct snd_pcm_substream *substream)
2374{
2375 struct sigmatel_spec *spec = codec->spec;
2376 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2377}
2378
2379/*
2380 * Digital playback callbacks
2381 */
2382static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2383 struct hda_codec *codec,
2384 struct snd_pcm_substream *substream)
2385{
2386 struct sigmatel_spec *spec = codec->spec;
2387 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2388}
2389
2390static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2391 struct hda_codec *codec,
2392 struct snd_pcm_substream *substream)
2393{
2394 struct sigmatel_spec *spec = codec->spec;
2395 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2396}
2397
2398static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2399 struct hda_codec *codec,
2400 unsigned int stream_tag,
2401 unsigned int format,
2402 struct snd_pcm_substream *substream)
2403{
2404 struct sigmatel_spec *spec = codec->spec;
2405 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2406 stream_tag, format, substream);
2407}
2408
2409static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2410 struct hda_codec *codec,
2411 struct snd_pcm_substream *substream)
2412{
2413 struct sigmatel_spec *spec = codec->spec;
2414 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2415}
2416
2417
2418/*
2419 * Analog capture callbacks
2420 */
2421static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2422 struct hda_codec *codec,
2423 unsigned int stream_tag,
2424 unsigned int format,
2425 struct snd_pcm_substream *substream)
2426{
2427 struct sigmatel_spec *spec = codec->spec;
2428 hda_nid_t nid = spec->adc_nids[substream->number];
2429
2430 if (spec->powerdown_adcs) {
2431 msleep(40);
2432 snd_hda_codec_write(codec, nid, 0,
2433 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2434 }
2435 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2436 return 0;
2437}
2438
2439static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2440 struct hda_codec *codec,
2441 struct snd_pcm_substream *substream)
2442{
2443 struct sigmatel_spec *spec = codec->spec;
2444 hda_nid_t nid = spec->adc_nids[substream->number];
2445
2446 snd_hda_codec_cleanup_stream(codec, nid);
2447 if (spec->powerdown_adcs)
2448 snd_hda_codec_write(codec, nid, 0,
2449 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2450 return 0;
2451}
2452
2453static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2454 .substreams = 1,
2455 .channels_min = 2,
2456 .channels_max = 2,
2457 /* NID is set in stac92xx_build_pcms */
2458 .ops = {
2459 .open = stac92xx_dig_playback_pcm_open,
2460 .close = stac92xx_dig_playback_pcm_close,
2461 .prepare = stac92xx_dig_playback_pcm_prepare,
2462 .cleanup = stac92xx_dig_playback_pcm_cleanup
2463 },
2464};
2465
2466static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2467 .substreams = 1,
2468 .channels_min = 2,
2469 .channels_max = 2,
2470 /* NID is set in stac92xx_build_pcms */
2471};
2472
2473static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2474 .substreams = 1,
2475 .channels_min = 2,
2476 .channels_max = 8,
2477 .nid = 0x02, /* NID to query formats and rates */
2478 .ops = {
2479 .open = stac92xx_playback_pcm_open,
2480 .prepare = stac92xx_playback_pcm_prepare,
2481 .cleanup = stac92xx_playback_pcm_cleanup
2482 },
2483};
2484
2485static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2486 .substreams = 1,
2487 .channels_min = 2,
2488 .channels_max = 2,
2489 .nid = 0x06, /* NID to query formats and rates */
2490 .ops = {
2491 .open = stac92xx_playback_pcm_open,
2492 .prepare = stac92xx_playback_pcm_prepare,
2493 .cleanup = stac92xx_playback_pcm_cleanup
2494 },
2495};
2496
2497static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2498 .channels_min = 2,
2499 .channels_max = 2,
2500 /* NID + .substreams is set in stac92xx_build_pcms */
2501 .ops = {
2502 .prepare = stac92xx_capture_pcm_prepare,
2503 .cleanup = stac92xx_capture_pcm_cleanup
2504 },
2505};
2506
2507static int stac92xx_build_pcms(struct hda_codec *codec)
2508{
2509 struct sigmatel_spec *spec = codec->spec;
2510 struct hda_pcm *info = spec->pcm_rec;
2511
2512 codec->num_pcms = 1;
2513 codec->pcm_info = info;
2514
2515 info->name = "STAC92xx Analog";
2516 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2517 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2518 spec->multiout.dac_nids[0];
2519 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2520 spec->autocfg.line_outs == 2)
2521 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2522 snd_pcm_2_1_chmaps;
2523
2524 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2525 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2526 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2527
2528 if (spec->alt_switch) {
2529 codec->num_pcms++;
2530 info++;
2531 info->name = "STAC92xx Analog Alt";
2532 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2533 }
2534
2535 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2536 codec->num_pcms++;
2537 info++;
2538 info->name = "STAC92xx Digital";
2539 info->pcm_type = spec->autocfg.dig_out_type[0];
2540 if (spec->multiout.dig_out_nid) {
2541 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2542 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2543 }
2544 if (spec->dig_in_nid) {
2545 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2546 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2547 }
2548 }
2549
2550 return 0;
2551}
2552
2553static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2554
2555{
2556 snd_hda_set_pin_ctl_cache(codec, nid, pin_type);
2557}
2558
2559#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2560
2561static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2562 struct snd_ctl_elem_value *ucontrol)
2563{
2564 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2565 struct sigmatel_spec *spec = codec->spec;
2566
2567 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2568 return 0;
2569}
2570
2571static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2572
2573static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2574 struct snd_ctl_elem_value *ucontrol)
2575{
2576 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2577 struct sigmatel_spec *spec = codec->spec;
2578 int nid = kcontrol->private_value;
2579
2580 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2581
2582 /* check to be sure that the ports are up to date with
2583 * switch changes
2584 */
2585 stac_issue_unsol_event(codec, nid);
2586
2587 return 1;
2588}
2589
2590static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2591 struct snd_ctl_elem_info *uinfo)
2592{
2593 int i;
2594 static const char * const texts[] = {
2595 "Mic In", "Line In", "Line Out"
2596 };
2597
2598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2599 struct sigmatel_spec *spec = codec->spec;
2600 hda_nid_t nid = kcontrol->private_value;
2601
2602 if (nid == spec->mic_switch || nid == spec->line_switch)
2603 i = 3;
2604 else
2605 i = 2;
2606
2607 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2608 uinfo->value.enumerated.items = i;
2609 uinfo->count = 1;
2610 if (uinfo->value.enumerated.item >= i)
2611 uinfo->value.enumerated.item = i-1;
2612 strcpy(uinfo->value.enumerated.name,
2613 texts[uinfo->value.enumerated.item]);
2614
2615 return 0;
2616}
2617
2618static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2619 struct snd_ctl_elem_value *ucontrol)
2620{
2621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2622 hda_nid_t nid = kcontrol->private_value;
2623 unsigned int vref = stac92xx_vref_get(codec, nid);
2624
2625 if (vref == snd_hda_get_default_vref(codec, nid))
2626 ucontrol->value.enumerated.item[0] = 0;
2627 else if (vref == AC_PINCTL_VREF_GRD)
2628 ucontrol->value.enumerated.item[0] = 1;
2629 else if (vref == AC_PINCTL_VREF_HIZ)
2630 ucontrol->value.enumerated.item[0] = 2;
2631
2632 return 0;
2633}
2634
2635static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2636 struct snd_ctl_elem_value *ucontrol)
2637{
2638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2639 unsigned int new_vref = 0;
2640 int error;
2641 hda_nid_t nid = kcontrol->private_value;
2642
2643 if (ucontrol->value.enumerated.item[0] == 0)
2644 new_vref = snd_hda_get_default_vref(codec, nid);
2645 else if (ucontrol->value.enumerated.item[0] == 1)
2646 new_vref = AC_PINCTL_VREF_GRD;
2647 else if (ucontrol->value.enumerated.item[0] == 2)
2648 new_vref = AC_PINCTL_VREF_HIZ;
2649 else
2650 return 0;
2651
2652 if (new_vref != stac92xx_vref_get(codec, nid)) {
2653 error = stac92xx_vref_set(codec, nid, new_vref);
2654 return error;
2655 }
2656
2657 return 0;
2658}
2659
2660static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2661 struct snd_ctl_elem_info *uinfo)
2662{
2663 char *texts[2];
2664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2665 struct sigmatel_spec *spec = codec->spec;
2666
2667 if (kcontrol->private_value == spec->line_switch)
2668 texts[0] = "Line In";
2669 else
2670 texts[0] = "Mic In";
2671 texts[1] = "Line Out";
2672 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2673 uinfo->value.enumerated.items = 2;
2674 uinfo->count = 1;
2675
2676 if (uinfo->value.enumerated.item >= 2)
2677 uinfo->value.enumerated.item = 1;
2678 strcpy(uinfo->value.enumerated.name,
2679 texts[uinfo->value.enumerated.item]);
2680
2681 return 0;
2682}
2683
2684static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2685{
2686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2687 struct sigmatel_spec *spec = codec->spec;
2688 hda_nid_t nid = kcontrol->private_value;
2689 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2690
2691 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2692 return 0;
2693}
2694
2695static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2696{
2697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2698 struct sigmatel_spec *spec = codec->spec;
2699 hda_nid_t nid = kcontrol->private_value;
2700 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2701 unsigned short val = !!ucontrol->value.enumerated.item[0];
2702
2703 spec->io_switch[io_idx] = val;
2704
2705 if (val)
2706 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2707 else {
2708 unsigned int pinctl = AC_PINCTL_IN_EN;
2709 if (io_idx) /* set VREF for mic */
2710 pinctl |= snd_hda_get_default_vref(codec, nid);
2711 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2712 }
2713
2714 /* check the auto-mute again: we need to mute/unmute the speaker
2715 * appropriately according to the pin direction
2716 */
2717 if (spec->hp_detect)
2718 stac_issue_unsol_event(codec, nid);
2719
2720 return 1;
2721}
2722
2723#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2724
2725static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2726 struct snd_ctl_elem_value *ucontrol)
2727{
2728 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2729 struct sigmatel_spec *spec = codec->spec;
2730
2731 ucontrol->value.integer.value[0] = spec->clfe_swap;
2732 return 0;
2733}
2734
2735static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2736 struct snd_ctl_elem_value *ucontrol)
2737{
2738 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2739 struct sigmatel_spec *spec = codec->spec;
2740 hda_nid_t nid = kcontrol->private_value & 0xff;
2741 unsigned int val = !!ucontrol->value.integer.value[0];
2742
2743 if (spec->clfe_swap == val)
2744 return 0;
2745
2746 spec->clfe_swap = val;
2747
2748 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2749 spec->clfe_swap ? 0x4 : 0x0);
2750
2751 return 1;
2752}
2753
2754#define STAC_CODEC_HP_SWITCH(xname) \
2755 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2756 .name = xname, \
2757 .index = 0, \
2758 .info = stac92xx_hp_switch_info, \
2759 .get = stac92xx_hp_switch_get, \
2760 .put = stac92xx_hp_switch_put, \
2761 }
2762
2763#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2764 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2765 .name = xname, \
2766 .index = 0, \
2767 .info = stac92xx_io_switch_info, \
2768 .get = stac92xx_io_switch_get, \
2769 .put = stac92xx_io_switch_put, \
2770 .private_value = xpval, \
2771 }
2772
2773#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2774 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2775 .name = xname, \
2776 .index = 0, \
2777 .info = stac92xx_clfe_switch_info, \
2778 .get = stac92xx_clfe_switch_get, \
2779 .put = stac92xx_clfe_switch_put, \
2780 .private_value = xpval, \
2781 }
2782
2783enum {
2784 STAC_CTL_WIDGET_VOL,
2785 STAC_CTL_WIDGET_MUTE,
2786 STAC_CTL_WIDGET_MUTE_BEEP,
2787 STAC_CTL_WIDGET_MONO_MUX,
2788 STAC_CTL_WIDGET_HP_SWITCH,
2789 STAC_CTL_WIDGET_IO_SWITCH,
2790 STAC_CTL_WIDGET_CLFE_SWITCH,
2791 STAC_CTL_WIDGET_DC_BIAS
2792};
2793
2794static const struct snd_kcontrol_new stac92xx_control_templates[] = {
2795 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2796 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2797 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2798 STAC_MONO_MUX,
2799 STAC_CODEC_HP_SWITCH(NULL),
2800 STAC_CODEC_IO_SWITCH(NULL, 0),
2801 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2802 DC_BIAS(NULL, 0, 0),
2803};
2804
2805/* add dynamic controls */
2806static struct snd_kcontrol_new *
2807stac_control_new(struct sigmatel_spec *spec,
2808 const struct snd_kcontrol_new *ktemp,
2809 const char *name,
2810 unsigned int subdev)
2811{
2812 struct snd_kcontrol_new *knew;
2813
2814 knew = snd_array_new(&spec->kctls);
2815 if (!knew)
2816 return NULL;
2817 *knew = *ktemp;
2818 knew->name = kstrdup(name, GFP_KERNEL);
2819 if (!knew->name) {
2820 /* roolback */
2821 memset(knew, 0, sizeof(*knew));
2822 spec->kctls.alloced--;
2823 return NULL;
2824 }
2825 knew->subdevice = subdev;
2826 return knew;
2827}
2828
2829static struct snd_kcontrol_new *
2830add_control_temp(struct sigmatel_spec *spec,
2831 const struct snd_kcontrol_new *ktemp,
2832 int idx, const char *name,
2833 unsigned long val)
2834{
2835 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2836 HDA_SUBDEV_AMP_FLAG);
2837 if (!knew)
2838 return NULL;
2839 knew->index = idx;
2840 knew->private_value = val;
2841 return knew;
2842}
2843
2844static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2845 const struct snd_kcontrol_new *ktemp,
2846 int idx, const char *name,
2847 unsigned long val)
2848{
2849 return add_control_temp(spec, ktemp, idx, name, val) ? 0 : -ENOMEM;
2850}
2851
2852static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2853 int type, int idx, const char *name,
2854 unsigned long val)
2855{
2856 return stac92xx_add_control_temp(spec,
2857 &stac92xx_control_templates[type],
2858 idx, name, val);
2859}
2860
2861
2862/* add dynamic controls */
2863static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2864 const char *name, unsigned long val)
2865{
2866 return stac92xx_add_control_idx(spec, type, 0, name, val);
2867}
2868
2869static const struct snd_kcontrol_new stac_input_src_temp = {
2870 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2871 .name = "Input Source",
2872 .info = stac92xx_mux_enum_info,
2873 .get = stac92xx_mux_enum_get,
2874 .put = stac92xx_mux_enum_put,
2875};
2876
2877static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2878 hda_nid_t nid, int idx)
2879{
2880 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2881 int control = 0;
2882 struct sigmatel_spec *spec = codec->spec;
2883 char name[22];
2884
2885 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2886 if (spec->headset_jack && snd_hda_get_input_pin_attr(def_conf)
2887 != INPUT_PIN_ATTR_DOCK)
2888 return 0;
2889 if (snd_hda_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2890 && nid == spec->line_switch)
2891 control = STAC_CTL_WIDGET_IO_SWITCH;
2892 else if (snd_hda_query_pin_caps(codec, nid)
2893 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2894 control = STAC_CTL_WIDGET_DC_BIAS;
2895 else if (nid == spec->mic_switch)
2896 control = STAC_CTL_WIDGET_IO_SWITCH;
2897 }
2898
2899 if (control) {
2900 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
2901 name, sizeof(name), NULL);
2902 return stac92xx_add_control(codec->spec, control,
2903 strcat(name, " Jack Mode"), nid);
2904 }
2905
2906 return 0;
2907}
2908
2909static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2910{
2911 struct snd_kcontrol_new *knew;
2912 struct hda_input_mux *imux = &spec->private_imux;
2913
2914 if (spec->auto_mic)
2915 return 0; /* no need for input source */
2916 if (!spec->num_adcs || imux->num_items <= 1)
2917 return 0; /* no need for input source control */
2918 knew = stac_control_new(spec, &stac_input_src_temp,
2919 stac_input_src_temp.name, 0);
2920 if (!knew)
2921 return -ENOMEM;
2922 knew->count = spec->num_adcs;
2923 return 0;
2924}
2925
2926/* check whether the line-input can be used as line-out */
2927static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2928{ 3506{
2929 struct sigmatel_spec *spec = codec->spec; 3507 struct sigmatel_spec *spec = codec->spec;
2930 struct auto_pin_cfg *cfg = &spec->autocfg;
2931 hda_nid_t nid;
2932 unsigned int pincap;
2933 int i;
2934
2935 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2936 return 0;
2937 for (i = 0; i < cfg->num_inputs; i++) {
2938 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
2939 nid = cfg->inputs[i].pin;
2940 pincap = snd_hda_query_pin_caps(codec, nid);
2941 if (pincap & AC_PINCAP_OUT)
2942 return nid;
2943 }
2944 }
2945 return 0;
2946}
2947
2948static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2949
2950/* check whether the mic-input can be used as line-out */
2951static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
2952{
2953 struct sigmatel_spec *spec = codec->spec;
2954 struct auto_pin_cfg *cfg = &spec->autocfg;
2955 unsigned int def_conf, pincap;
2956 int i;
2957
2958 *dac = 0;
2959 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2960 return 0;
2961 for (i = 0; i < cfg->num_inputs; i++) {
2962 hda_nid_t nid = cfg->inputs[i].pin;
2963 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2964 continue;
2965 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2966 /* some laptops have an internal analog microphone
2967 * which can't be used as a output */
2968 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2969 pincap = snd_hda_query_pin_caps(codec, nid);
2970 if (pincap & AC_PINCAP_OUT) {
2971 *dac = get_unassigned_dac(codec, nid);
2972 if (*dac)
2973 return nid;
2974 }
2975 }
2976 }
2977 return 0;
2978}
2979
2980static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2981{
2982 int i;
2983
2984 for (i = 0; i < spec->multiout.num_dacs; i++) {
2985 if (spec->multiout.dac_nids[i] == nid)
2986 return 1;
2987 }
2988
2989 return 0;
2990}
2991
2992static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2993{
2994 int i;
2995 if (is_in_dac_nids(spec, nid))
2996 return 1;
2997 for (i = 0; i < spec->autocfg.hp_outs; i++)
2998 if (spec->hp_dacs[i] == nid)
2999 return 1;
3000 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3001 if (spec->speaker_dacs[i] == nid)
3002 return 1;
3003 return 0;
3004}
3005
3006static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3007{
3008 struct sigmatel_spec *spec = codec->spec;
3009 struct auto_pin_cfg *cfg = &spec->autocfg;
3010 int j, conn_len;
3011 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
3012 unsigned int wcaps, wtype;
3013
3014 conn_len = snd_hda_get_connections(codec, nid, conn,
3015 HDA_MAX_CONNECTIONS);
3016 /* 92HD88: trace back up the link of nids to find the DAC */
3017 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
3018 != AC_WID_AUD_OUT)) {
3019 nid = conn[0];
3020 conn_len = snd_hda_get_connections(codec, nid, conn,
3021 HDA_MAX_CONNECTIONS);
3022 }
3023 for (j = 0; j < conn_len; j++) {
3024 wcaps = get_wcaps(codec, conn[j]);
3025 wtype = get_wcaps_type(wcaps);
3026 /* we check only analog outputs */
3027 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3028 continue;
3029 /* if this route has a free DAC, assign it */
3030 if (!check_all_dac_nids(spec, conn[j])) {
3031 if (conn_len > 1) {
3032 /* select this DAC in the pin's input mux */
3033 snd_hda_codec_write_cache(codec, nid, 0,
3034 AC_VERB_SET_CONNECT_SEL, j);
3035 }
3036 return conn[j];
3037 }
3038 }
3039
3040 /* if all DACs are already assigned, connect to the primary DAC,
3041 unless we're assigning a secondary headphone */
3042 fallback_dac = spec->multiout.dac_nids[0];
3043 if (spec->multiout.hp_nid) {
3044 for (j = 0; j < cfg->hp_outs; j++)
3045 if (cfg->hp_pins[j] == nid) {
3046 fallback_dac = spec->multiout.hp_nid;
3047 break;
3048 }
3049 }
3050
3051 if (conn_len > 1) {
3052 for (j = 0; j < conn_len; j++) {
3053 if (conn[j] == fallback_dac) {
3054 snd_hda_codec_write_cache(codec, nid, 0,
3055 AC_VERB_SET_CONNECT_SEL, j);
3056 break;
3057 }
3058 }
3059 }
3060 return 0;
3061}
3062
3063static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3064static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3065
3066/*
3067 * Fill in the dac_nids table from the parsed pin configuration
3068 * This function only works when every pin in line_out_pins[]
3069 * contains atleast one DAC in its connection list. Some 92xx
3070 * codecs are not connected directly to a DAC, such as the 9200
3071 * and 9202/925x. For those, dac_nids[] must be hard-coded.
3072 */
3073static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
3074{
3075 struct sigmatel_spec *spec = codec->spec;
3076 struct auto_pin_cfg *cfg = &spec->autocfg;
3077 int i;
3078 hda_nid_t nid, dac;
3079
3080 for (i = 0; i < cfg->line_outs; i++) {
3081 nid = cfg->line_out_pins[i];
3082 dac = get_unassigned_dac(codec, nid);
3083 if (!dac) {
3084 if (spec->multiout.num_dacs > 0) {
3085 /* we have already working output pins,
3086 * so let's drop the broken ones again
3087 */
3088 cfg->line_outs = spec->multiout.num_dacs;
3089 break;
3090 }
3091 /* error out, no available DAC found */
3092 snd_printk(KERN_ERR
3093 "%s: No available DAC for pin 0x%x\n",
3094 __func__, nid);
3095 return -ENODEV;
3096 }
3097 add_spec_dacs(spec, dac);
3098 }
3099
3100 for (i = 0; i < cfg->hp_outs; i++) {
3101 nid = cfg->hp_pins[i];
3102 dac = get_unassigned_dac(codec, nid);
3103 if (dac) {
3104 if (!spec->multiout.hp_nid)
3105 spec->multiout.hp_nid = dac;
3106 else
3107 add_spec_extra_dacs(spec, dac);
3108 }
3109 spec->hp_dacs[i] = dac;
3110 }
3111
3112 for (i = 0; i < cfg->speaker_outs; i++) {
3113 nid = cfg->speaker_pins[i];
3114 dac = get_unassigned_dac(codec, nid);
3115 if (dac)
3116 add_spec_extra_dacs(spec, dac);
3117 spec->speaker_dacs[i] = dac;
3118 }
3119
3120 /* add line-in as output */
3121 nid = check_line_out_switch(codec);
3122 if (nid) {
3123 dac = get_unassigned_dac(codec, nid);
3124 if (dac) {
3125 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3126 nid, cfg->line_outs);
3127 cfg->line_out_pins[cfg->line_outs] = nid;
3128 cfg->line_outs++;
3129 spec->line_switch = nid;
3130 add_spec_dacs(spec, dac);
3131 }
3132 }
3133 /* add mic as output */
3134 nid = check_mic_out_switch(codec, &dac);
3135 if (nid && dac) {
3136 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3137 nid, cfg->line_outs);
3138 cfg->line_out_pins[cfg->line_outs] = nid;
3139 cfg->line_outs++;
3140 spec->mic_switch = nid;
3141 add_spec_dacs(spec, dac);
3142 }
3143
3144 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3145 spec->multiout.num_dacs,
3146 spec->multiout.dac_nids[0],
3147 spec->multiout.dac_nids[1],
3148 spec->multiout.dac_nids[2],
3149 spec->multiout.dac_nids[3],
3150 spec->multiout.dac_nids[4]);
3151
3152 return 0;
3153}
3154
3155/* create volume control/switch for the given prefx type */
3156static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3157 int idx, hda_nid_t nid, int chs)
3158{
3159 struct sigmatel_spec *spec = codec->spec;
3160 char name[32];
3161 int err; 3508 int err;
3162 3509
3163 if (!spec->check_volume_offset) { 3510 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
3164 unsigned int caps, step, nums, db_scale;
3165 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3166 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3167 AC_AMPCAP_STEP_SIZE_SHIFT;
3168 step = (step + 1) * 25; /* in .01dB unit */
3169 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3170 AC_AMPCAP_NUM_STEPS_SHIFT;
3171 db_scale = nums * step;
3172 /* if dB scale is over -64dB, and finer enough,
3173 * let's reduce it to half
3174 */
3175 if (db_scale > 6400 && nums >= 0x1f)
3176 spec->volume_offset = nums / 2;
3177 spec->check_volume_offset = 1;
3178 }
3179
3180 sprintf(name, "%s Playback Volume", pfx);
3181 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3182 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3183 spec->volume_offset));
3184 if (err < 0)
3185 return err;
3186 sprintf(name, "%s Playback Switch", pfx);
3187 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3188 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3189 if (err < 0) 3511 if (err < 0)
3190 return err; 3512 return err;
3191 return 0;
3192}
3193
3194#define create_controls(codec, pfx, nid, chs) \
3195 create_controls_idx(codec, pfx, 0, nid, chs)
3196
3197static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3198{
3199 if (spec->multiout.num_dacs > 4) {
3200 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3201 return 1;
3202 } else {
3203 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3204 spec->dac_nids[spec->multiout.num_dacs] = nid;
3205 spec->multiout.num_dacs++;
3206 }
3207 return 0;
3208}
3209 3513
3210static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid) 3514 /* add hooks */
3211{ 3515 spec->gen.pcm_playback_hook = stac_playback_pcm_hook;
3212 int i; 3516 spec->gen.pcm_capture_hook = stac_capture_pcm_hook;
3213 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3214 if (!spec->multiout.extra_out_nid[i]) {
3215 spec->multiout.extra_out_nid[i] = nid;
3216 return 0;
3217 }
3218 }
3219 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3220 return 1;
3221}
3222 3517
3223/* Create output controls 3518 spec->gen.automute_hook = stac_update_outputs;
3224 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT) 3519 spec->gen.hp_automute_hook = stac_hp_automute;
3225 */ 3520 spec->gen.line_automute_hook = stac_line_automute;
3226static int create_multi_out_ctls(struct hda_codec *codec, int num_outs, 3521 spec->gen.mic_autoswitch_hook = stac_mic_autoswitch;
3227 const hda_nid_t *pins,
3228 const hda_nid_t *dac_nids,
3229 int type)
3230{
3231 struct sigmatel_spec *spec = codec->spec;
3232 static const char * const chname[4] = {
3233 "Front", "Surround", NULL /*CLFE*/, "Side"
3234 };
3235 hda_nid_t nid;
3236 int i, err;
3237 unsigned int wid_caps;
3238
3239 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3240 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3241 if (is_jack_detectable(codec, pins[i]))
3242 spec->hp_detect = 1;
3243 }
3244 nid = dac_nids[i];
3245 if (!nid)
3246 continue;
3247 if (type != AUTO_PIN_HP_OUT && i == 2) {
3248 /* Center/LFE */
3249 err = create_controls(codec, "Center", nid, 1);
3250 if (err < 0)
3251 return err;
3252 err = create_controls(codec, "LFE", nid, 2);
3253 if (err < 0)
3254 return err;
3255
3256 wid_caps = get_wcaps(codec, nid);
3257
3258 if (wid_caps & AC_WCAP_LR_SWAP) {
3259 err = stac92xx_add_control(spec,
3260 STAC_CTL_WIDGET_CLFE_SWITCH,
3261 "Swap Center/LFE Playback Switch", nid);
3262 3522
3263 if (err < 0) 3523 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
3264 return err;
3265 }
3266
3267 } else {
3268 const char *name;
3269 int idx;
3270 switch (type) {
3271 case AUTO_PIN_HP_OUT:
3272 name = "Headphone";
3273 idx = i;
3274 break;
3275 case AUTO_PIN_SPEAKER_OUT:
3276 if (num_outs <= 2) {
3277 name = i ? "Bass Speaker" : "Speaker";
3278 idx = 0;
3279 break;
3280 }
3281 /* Fall through in case of multi speaker outs */
3282 default:
3283 name = chname[i];
3284 idx = 0;
3285 break;
3286 }
3287 err = create_controls_idx(codec, name, idx, nid, 3);
3288 if (err < 0)
3289 return err;
3290 }
3291 }
3292 return 0;
3293}
3294
3295static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3296 unsigned int dir_mask, unsigned int data);
3297
3298/* hook for controlling mic-mute LED GPIO */
3299static int stac92xx_capture_sw_put_led(struct snd_kcontrol *kcontrol,
3300 struct snd_ctl_elem_value *ucontrol)
3301{
3302 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3303 struct sigmatel_spec *spec = codec->spec;
3304 int err;
3305 bool mute;
3306
3307 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3308 if (err <= 0)
3309 return err;
3310 mute = !(ucontrol->value.integer.value[0] &&
3311 ucontrol->value.integer.value[1]);
3312 if (spec->mic_mute_led_on != mute) {
3313 spec->mic_mute_led_on = mute;
3314 if (mute)
3315 spec->gpio_data |= spec->mic_mute_led_gpio;
3316 else
3317 spec->gpio_data &= ~spec->mic_mute_led_gpio;
3318 stac_gpio_set(codec, spec->gpio_mask,
3319 spec->gpio_dir, spec->gpio_data);
3320 }
3321 return err;
3322}
3323
3324static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3325 unsigned long sw, int idx)
3326{
3327 struct sigmatel_spec *spec = codec->spec;
3328 struct snd_kcontrol_new *knew;
3329 int err;
3330
3331 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3332 "Capture Volume", vol);
3333 if (err < 0) 3524 if (err < 0)
3334 return err; 3525 return err;
3335 3526
3336 knew = add_control_temp(spec, 3527 /* minimum value is actually mute */
3337 &stac92xx_control_templates[STAC_CTL_WIDGET_MUTE], 3528 spec->gen.vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
3338 idx, "Capture Switch", sw);
3339 if (!knew)
3340 return -ENOMEM;
3341 /* add a LED hook for some HP laptops */
3342 if (spec->mic_mute_led_gpio)
3343 knew->put = stac92xx_capture_sw_put_led;
3344
3345 return 0;
3346}
3347
3348/* add playback controls from the parsed DAC table */
3349static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3350 const struct auto_pin_cfg *cfg)
3351{
3352 struct sigmatel_spec *spec = codec->spec;
3353 hda_nid_t nid;
3354 int err;
3355 int idx;
3356
3357 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3358 spec->multiout.dac_nids,
3359 cfg->line_out_type);
3360 if (err < 0)
3361 return err;
3362
3363 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3364 err = stac92xx_add_control(spec,
3365 STAC_CTL_WIDGET_HP_SWITCH,
3366 "Headphone as Line Out Switch",
3367 cfg->hp_pins[cfg->hp_outs - 1]);
3368 if (err < 0)
3369 return err;
3370 }
3371
3372 for (idx = 0; idx < cfg->num_inputs; idx++) {
3373 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
3374 break;
3375 nid = cfg->inputs[idx].pin;
3376 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3377 if (err < 0)
3378 return err;
3379 }
3380
3381 return 0;
3382}
3383
3384/* add playback controls for Speaker and HP outputs */
3385static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3386 struct auto_pin_cfg *cfg)
3387{
3388 struct sigmatel_spec *spec = codec->spec;
3389 int err;
3390
3391 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3392 spec->hp_dacs, AUTO_PIN_HP_OUT);
3393 if (err < 0)
3394 return err;
3395
3396 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3397 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3398 if (err < 0)
3399 return err;
3400
3401 return 0;
3402}
3403
3404/* labels for mono mux outputs */
3405static const char * const stac92xx_mono_labels[4] = {
3406 "DAC0", "DAC1", "Mixer", "DAC2"
3407};
3408
3409/* create mono mux for mono out on capable codecs */
3410static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3411{
3412 struct sigmatel_spec *spec = codec->spec;
3413 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3414 int i, num_cons;
3415 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3416
3417 num_cons = snd_hda_get_connections(codec,
3418 spec->mono_nid,
3419 con_lst,
3420 HDA_MAX_NUM_INPUTS);
3421 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3422 return -EINVAL;
3423
3424 for (i = 0; i < num_cons; i++)
3425 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3426 NULL);
3427
3428 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3429 "Mono Mux", spec->mono_nid);
3430}
3431
3432/* create PC beep volume controls */
3433static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3434 hda_nid_t nid)
3435{
3436 struct sigmatel_spec *spec = codec->spec;
3437 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3438 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3439
3440 if (spec->anabeep_nid == nid)
3441 type = STAC_CTL_WIDGET_MUTE;
3442
3443 /* check for mute support for the the amp */
3444 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3445 err = stac92xx_add_control(spec, type,
3446 "Beep Playback Switch",
3447 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3448 if (err < 0)
3449 return err;
3450 }
3451
3452 /* check to see if there is volume support for the amp */
3453 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3454 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3455 "Beep Playback Volume",
3456 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3457 if (err < 0)
3458 return err;
3459 }
3460 return 0;
3461}
3462
3463#ifdef CONFIG_SND_HDA_INPUT_BEEP
3464#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3465
3466static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3467 struct snd_ctl_elem_value *ucontrol)
3468{
3469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3470 ucontrol->value.integer.value[0] = codec->beep->enabled;
3471 return 0;
3472}
3473
3474static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3475 struct snd_ctl_elem_value *ucontrol)
3476{
3477 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3478 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3479}
3480
3481static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3482 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3483 .info = stac92xx_dig_beep_switch_info,
3484 .get = stac92xx_dig_beep_switch_get,
3485 .put = stac92xx_dig_beep_switch_put,
3486};
3487
3488static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3489{
3490 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3491 0, "Beep Playback Switch", 0);
3492}
3493#endif
3494
3495static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3496{
3497 struct sigmatel_spec *spec = codec->spec;
3498 int i, j, err = 0;
3499
3500 for (i = 0; i < spec->num_muxes; i++) {
3501 hda_nid_t nid;
3502 unsigned int wcaps;
3503 unsigned long val;
3504
3505 nid = spec->mux_nids[i];
3506 wcaps = get_wcaps(codec, nid);
3507 if (!(wcaps & AC_WCAP_OUT_AMP))
3508 continue;
3509
3510 /* check whether already the same control was created as
3511 * normal Capture Volume.
3512 */
3513 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3514 for (j = 0; j < spec->num_caps; j++) {
3515 if (spec->capvols[j] == val)
3516 break;
3517 }
3518 if (j < spec->num_caps)
3519 continue;
3520
3521 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3522 "Mux Capture Volume", val);
3523 if (err < 0)
3524 return err;
3525 }
3526 return 0;
3527};
3528
3529static const char * const stac92xx_spdif_labels[3] = {
3530 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3531};
3532
3533static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3534{
3535 struct sigmatel_spec *spec = codec->spec;
3536 struct hda_input_mux *spdif_mux = &spec->private_smux;
3537 const char * const *labels = spec->spdif_labels;
3538 int i, num_cons;
3539 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3540
3541 num_cons = snd_hda_get_connections(codec,
3542 spec->smux_nids[0],
3543 con_lst,
3544 HDA_MAX_NUM_INPUTS);
3545 if (num_cons <= 0)
3546 return -EINVAL;
3547
3548 if (!labels)
3549 labels = stac92xx_spdif_labels;
3550
3551 for (i = 0; i < num_cons; i++)
3552 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
3553
3554 return 0;
3555}
3556
3557/* labels for dmic mux inputs */
3558static const char * const stac92xx_dmic_labels[5] = {
3559 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3560 "Digital Mic 3", "Digital Mic 4"
3561};
3562
3563static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3564 int idx)
3565{
3566 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3567 int nums;
3568 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3569 if (idx >= 0 && idx < nums)
3570 return conn[idx];
3571 return 0;
3572}
3573
3574/* look for NID recursively */
3575#define get_connection_index(codec, mux, nid) \
3576 snd_hda_get_conn_index(codec, mux, nid, 1)
3577
3578/* create a volume assigned to the given pin (only if supported) */
3579/* return 1 if the volume control is created */
3580static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3581 const char *label, int idx, int direction)
3582{
3583 unsigned int caps, nums;
3584 char name[32];
3585 int err;
3586
3587 if (direction == HDA_OUTPUT)
3588 caps = AC_WCAP_OUT_AMP;
3589 else
3590 caps = AC_WCAP_IN_AMP;
3591 if (!(get_wcaps(codec, nid) & caps))
3592 return 0;
3593 caps = query_amp_caps(codec, nid, direction);
3594 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3595 if (!nums)
3596 return 0;
3597 snprintf(name, sizeof(name), "%s Capture Volume", label);
3598 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3599 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3600 if (err < 0)
3601 return err;
3602 return 1;
3603}
3604
3605/* create playback/capture controls for input pins on dmic capable codecs */
3606static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3607 const struct auto_pin_cfg *cfg)
3608{
3609 struct sigmatel_spec *spec = codec->spec;
3610 struct hda_input_mux *imux = &spec->private_imux;
3611 struct hda_input_mux *dimux = &spec->private_dimux;
3612 int err, i;
3613 unsigned int def_conf;
3614
3615 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
3616
3617 for (i = 0; i < spec->num_dmics; i++) {
3618 hda_nid_t nid;
3619 int index, type_idx;
3620 char label[32];
3621
3622 nid = spec->dmic_nids[i];
3623 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3624 continue;
3625 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3626 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3627 continue;
3628
3629 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3630 if (index < 0)
3631 continue;
3632
3633 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3634 label, sizeof(label), NULL);
3635 snd_hda_add_imux_item(dimux, label, index, &type_idx);
3636 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3637 snd_hda_add_imux_item(imux, label, index, &type_idx);
3638
3639 err = create_elem_capture_vol(codec, nid, label, type_idx,
3640 HDA_INPUT);
3641 if (err < 0)
3642 return err;
3643 if (!err) {
3644 err = create_elem_capture_vol(codec, nid, label,
3645 type_idx, HDA_OUTPUT);
3646 if (err < 0)
3647 return err;
3648 if (!err) {
3649 nid = get_connected_node(codec,
3650 spec->dmux_nids[0], index);
3651 if (nid)
3652 err = create_elem_capture_vol(codec,
3653 nid, label,
3654 type_idx, HDA_INPUT);
3655 if (err < 0)
3656 return err;
3657 }
3658 }
3659 }
3660
3661 return 0;
3662}
3663
3664static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3665 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
3666{
3667 unsigned int cfg;
3668 unsigned int type;
3669
3670 if (!nid)
3671 return 0;
3672 cfg = snd_hda_codec_get_pincfg(codec, nid);
3673 type = get_defcfg_device(cfg);
3674 switch (snd_hda_get_input_pin_attr(cfg)) {
3675 case INPUT_PIN_ATTR_INT:
3676 if (*fixed)
3677 return 1; /* already occupied */
3678 if (type != AC_JACK_MIC_IN)
3679 return 1; /* invalid type */
3680 *fixed = nid;
3681 break;
3682 case INPUT_PIN_ATTR_UNUSED:
3683 break;
3684 case INPUT_PIN_ATTR_DOCK:
3685 if (*dock)
3686 return 1; /* already occupied */
3687 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3688 return 1; /* invalid type */
3689 *dock = nid;
3690 break;
3691 default:
3692 if (*ext)
3693 return 1; /* already occupied */
3694 if (type != AC_JACK_MIC_IN)
3695 return 1; /* invalid type */
3696 *ext = nid;
3697 break;
3698 }
3699 return 0;
3700}
3701
3702static int set_mic_route(struct hda_codec *codec,
3703 struct sigmatel_mic_route *mic,
3704 hda_nid_t pin)
3705{
3706 struct sigmatel_spec *spec = codec->spec;
3707 struct auto_pin_cfg *cfg = &spec->autocfg;
3708 int i;
3709
3710 mic->pin = pin;
3711 if (pin == 0)
3712 return 0;
3713 for (i = 0; i < cfg->num_inputs; i++) {
3714 if (pin == cfg->inputs[i].pin)
3715 break;
3716 }
3717 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
3718 /* analog pin */
3719 i = get_connection_index(codec, spec->mux_nids[0], pin);
3720 if (i < 0)
3721 return -1;
3722 mic->mux_idx = i;
3723 mic->dmux_idx = -1;
3724 if (spec->dmux_nids)
3725 mic->dmux_idx = get_connection_index(codec,
3726 spec->dmux_nids[0],
3727 spec->mux_nids[0]);
3728 } else if (spec->dmux_nids) {
3729 /* digital pin */
3730 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3731 if (i < 0)
3732 return -1;
3733 mic->dmux_idx = i;
3734 mic->mux_idx = -1;
3735 if (spec->mux_nids)
3736 mic->mux_idx = get_connection_index(codec,
3737 spec->mux_nids[0],
3738 spec->dmux_nids[0]);
3739 }
3740 return 0;
3741}
3742
3743/* return non-zero if the device is for automatic mic switch */
3744static int stac_check_auto_mic(struct hda_codec *codec)
3745{
3746 struct sigmatel_spec *spec = codec->spec;
3747 struct auto_pin_cfg *cfg = &spec->autocfg;
3748 hda_nid_t fixed, ext, dock;
3749 int i;
3750
3751 fixed = ext = dock = 0;
3752 for (i = 0; i < cfg->num_inputs; i++)
3753 if (check_mic_pin(codec, cfg->inputs[i].pin,
3754 &fixed, &ext, &dock))
3755 return 0;
3756 for (i = 0; i < spec->num_dmics; i++)
3757 if (check_mic_pin(codec, spec->dmic_nids[i],
3758 &fixed, &ext, &dock))
3759 return 0;
3760 if (!fixed || (!ext && !dock))
3761 return 0; /* no input to switch */
3762 if (!is_jack_detectable(codec, ext))
3763 return 0; /* no unsol support */
3764 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3765 set_mic_route(codec, &spec->int_mic, fixed) ||
3766 set_mic_route(codec, &spec->dock_mic, dock))
3767 return 0; /* something is wrong */
3768 return 1;
3769}
3770
3771/* create playback/capture controls for input pins */
3772static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3773{
3774 struct sigmatel_spec *spec = codec->spec;
3775 struct hda_input_mux *imux = &spec->private_imux;
3776 int i, j;
3777 const char *label;
3778
3779 for (i = 0; i < cfg->num_inputs; i++) {
3780 hda_nid_t nid = cfg->inputs[i].pin;
3781 int index, err, type_idx;
3782
3783 index = -1;
3784 for (j = 0; j < spec->num_muxes; j++) {
3785 index = get_connection_index(codec, spec->mux_nids[j],
3786 nid);
3787 if (index >= 0)
3788 break;
3789 }
3790 if (index < 0)
3791 continue;
3792
3793 label = hda_get_autocfg_input_label(codec, cfg, i);
3794 snd_hda_add_imux_item(imux, label, index, &type_idx);
3795
3796 err = create_elem_capture_vol(codec, nid,
3797 label, type_idx,
3798 HDA_INPUT);
3799 if (err < 0)
3800 return err;
3801 }
3802 spec->num_analog_muxes = imux->num_items;
3803
3804 if (imux->num_items) {
3805 /*
3806 * Set the current input for the muxes.
3807 * The STAC9221 has two input muxes with identical source
3808 * NID lists. Hopefully this won't get confused.
3809 */
3810 for (i = 0; i < spec->num_muxes; i++) {
3811 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3812 AC_VERB_SET_CONNECT_SEL,
3813 imux->items[0].index);
3814 }
3815 }
3816
3817 return 0;
3818}
3819
3820static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3821{
3822 struct sigmatel_spec *spec = codec->spec;
3823 int i;
3824
3825 for (i = 0; i < spec->autocfg.line_outs; i++) {
3826 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3827 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3828 }
3829}
3830
3831static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3832{
3833 struct sigmatel_spec *spec = codec->spec;
3834 int i;
3835
3836 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3837 hda_nid_t pin;
3838 pin = spec->autocfg.hp_pins[i];
3839 if (pin) /* connect to front */
3840 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3841 }
3842 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3843 hda_nid_t pin;
3844 pin = spec->autocfg.speaker_pins[i];
3845 if (pin) /* connect to front */
3846 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3847 }
3848}
3849
3850static int is_dual_headphones(struct hda_codec *codec)
3851{
3852 struct sigmatel_spec *spec = codec->spec;
3853 int i, valid_hps;
3854
3855 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3856 spec->autocfg.hp_outs <= 1)
3857 return 0;
3858 valid_hps = 0;
3859 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3860 hda_nid_t nid = spec->autocfg.hp_pins[i];
3861 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3862 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3863 continue;
3864 valid_hps++;
3865 }
3866 return (valid_hps > 1);
3867}
3868
3869
3870static int stac92xx_parse_auto_config(struct hda_codec *codec)
3871{
3872 struct sigmatel_spec *spec = codec->spec;
3873 hda_nid_t dig_out = 0, dig_in = 0;
3874 int hp_swap = 0;
3875 int i, err;
3876
3877 if ((err = snd_hda_parse_pin_def_config(codec,
3878 &spec->autocfg,
3879 spec->dmic_nids)) < 0)
3880 return err;
3881 if (! spec->autocfg.line_outs)
3882 return 0; /* can't find valid pin config */
3883
3884 /* If we have no real line-out pin and multiple hp-outs, HPs should
3885 * be set up as multi-channel outputs.
3886 */
3887 if (is_dual_headphones(codec)) {
3888 /* Copy hp_outs to line_outs, backup line_outs in
3889 * speaker_outs so that the following routines can handle
3890 * HP pins as primary outputs.
3891 */
3892 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3893 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3894 sizeof(spec->autocfg.line_out_pins));
3895 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3896 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3897 sizeof(spec->autocfg.hp_pins));
3898 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3899 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3900 spec->autocfg.hp_outs = 0;
3901 hp_swap = 1;
3902 }
3903 if (spec->autocfg.mono_out_pin) {
3904 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3905 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3906 u32 caps = query_amp_caps(codec,
3907 spec->autocfg.mono_out_pin, dir);
3908 hda_nid_t conn_list[1];
3909
3910 /* get the mixer node and then the mono mux if it exists */
3911 if (snd_hda_get_connections(codec,
3912 spec->autocfg.mono_out_pin, conn_list, 1) &&
3913 snd_hda_get_connections(codec, conn_list[0],
3914 conn_list, 1) > 0) {
3915
3916 int wcaps = get_wcaps(codec, conn_list[0]);
3917 int wid_type = get_wcaps_type(wcaps);
3918 /* LR swap check, some stac925x have a mux that
3919 * changes the DACs output path instead of the
3920 * mono-mux path.
3921 */
3922 if (wid_type == AC_WID_AUD_SEL &&
3923 !(wcaps & AC_WCAP_LR_SWAP))
3924 spec->mono_nid = conn_list[0];
3925 }
3926 if (dir) {
3927 hda_nid_t nid = spec->autocfg.mono_out_pin;
3928
3929 /* most mono outs have a least a mute/unmute switch */
3930 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3931 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3932 "Mono Playback Switch",
3933 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3934 if (err < 0)
3935 return err;
3936 /* check for volume support for the amp */
3937 if ((caps & AC_AMPCAP_NUM_STEPS)
3938 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3939 err = stac92xx_add_control(spec,
3940 STAC_CTL_WIDGET_VOL,
3941 "Mono Playback Volume",
3942 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3943 if (err < 0)
3944 return err;
3945 }
3946 }
3947
3948 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3949 AC_PINCTL_OUT_EN);
3950 }
3951
3952 if (!spec->multiout.num_dacs) {
3953 err = stac92xx_auto_fill_dac_nids(codec);
3954 if (err < 0)
3955 return err;
3956 err = stac92xx_auto_create_multi_out_ctls(codec,
3957 &spec->autocfg);
3958 if (err < 0)
3959 return err;
3960 }
3961 3529
3962 /* setup analog beep controls */ 3530 /* setup analog beep controls */
3963 if (spec->anabeep_nid > 0) { 3531 if (spec->anabeep_nid > 0) {
3964 err = stac92xx_auto_create_beep_ctls(codec, 3532 err = stac_auto_create_beep_ctls(codec,
3965 spec->anabeep_nid); 3533 spec->anabeep_nid);
3966 if (err < 0) 3534 if (err < 0)
3967 return err; 3535 return err;
3968 } 3536 }
@@ -3973,7 +3541,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec)
3973 hda_nid_t nid = spec->digbeep_nid; 3541 hda_nid_t nid = spec->digbeep_nid;
3974 unsigned int caps; 3542 unsigned int caps;
3975 3543
3976 err = stac92xx_auto_create_beep_ctls(codec, nid); 3544 err = stac_auto_create_beep_ctls(codec, nid);
3977 if (err < 0) 3545 if (err < 0)
3978 return err; 3546 return err;
3979 err = snd_hda_attach_beep_device(codec, nid); 3547 err = snd_hda_attach_beep_device(codec, nid);
@@ -3985,7 +3553,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec)
3985 /* if no beep switch is available, make its own one */ 3553 /* if no beep switch is available, make its own one */
3986 caps = query_amp_caps(codec, nid, HDA_OUTPUT); 3554 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3987 if (!(caps & AC_AMPCAP_MUTE)) { 3555 if (!(caps & AC_AMPCAP_MUTE)) {
3988 err = stac92xx_beep_switch_ctl(codec); 3556 err = stac_beep_switch_ctl(codec);
3989 if (err < 0) 3557 if (err < 0)
3990 return err; 3558 return err;
3991 } 3559 }
@@ -3993,387 +3561,33 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec)
3993 } 3561 }
3994#endif 3562#endif
3995 3563
3996 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg); 3564 if (spec->gpio_led)
3997 if (err < 0) 3565 spec->gen.vmaster_mute.hook = stac_vmaster_hook;
3998 return err;
3999
4000 /* All output parsing done, now restore the swapped hp pins */
4001 if (hp_swap) {
4002 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
4003 sizeof(spec->autocfg.hp_pins));
4004 spec->autocfg.hp_outs = spec->autocfg.line_outs;
4005 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
4006 spec->autocfg.line_outs = 0;
4007 }
4008
4009 if (stac_check_auto_mic(codec)) {
4010 spec->auto_mic = 1;
4011 /* only one capture for auto-mic */
4012 spec->num_adcs = 1;
4013 spec->num_caps = 1;
4014 spec->num_muxes = 1;
4015 }
4016
4017 for (i = 0; i < spec->num_caps; i++) {
4018 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
4019 spec->capsws[i], i);
4020 if (err < 0)
4021 return err;
4022 }
4023
4024 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
4025 if (err < 0)
4026 return err;
4027
4028 if (spec->mono_nid > 0) {
4029 err = stac92xx_auto_create_mono_output_ctls(codec);
4030 if (err < 0)
4031 return err;
4032 }
4033 if (spec->num_dmics > 0 && !spec->dinput_mux)
4034 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
4035 &spec->autocfg)) < 0)
4036 return err;
4037 if (spec->num_muxes > 0) {
4038 err = stac92xx_auto_create_mux_input_ctls(codec);
4039 if (err < 0)
4040 return err;
4041 }
4042 if (spec->num_smuxes > 0) {
4043 err = stac92xx_auto_create_spdif_mux_ctls(codec);
4044 if (err < 0)
4045 return err;
4046 }
4047
4048 err = stac92xx_add_input_source(spec);
4049 if (err < 0)
4050 return err;
4051
4052 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4053 if (spec->multiout.max_channels > 2)
4054 spec->surr_switch = 1;
4055
4056 /* find digital out and in converters */
4057 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
4058 unsigned int wid_caps = get_wcaps(codec, i);
4059 if (wid_caps & AC_WCAP_DIGITAL) {
4060 switch (get_wcaps_type(wid_caps)) {
4061 case AC_WID_AUD_OUT:
4062 if (!dig_out)
4063 dig_out = i;
4064 break;
4065 case AC_WID_AUD_IN:
4066 if (!dig_in)
4067 dig_in = i;
4068 break;
4069 }
4070 }
4071 }
4072 if (spec->autocfg.dig_outs)
4073 spec->multiout.dig_out_nid = dig_out;
4074 if (dig_in && spec->autocfg.dig_in_pin)
4075 spec->dig_in_nid = dig_in;
4076
4077 if (spec->kctls.list)
4078 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4079
4080 spec->input_mux = &spec->private_imux;
4081 if (!spec->dinput_mux)
4082 spec->dinput_mux = &spec->private_dimux;
4083 spec->sinput_mux = &spec->private_smux;
4084 spec->mono_mux = &spec->private_mono_mux;
4085 return 1;
4086}
4087
4088/* add playback controls for HP output */
4089static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4090 struct auto_pin_cfg *cfg)
4091{
4092 struct sigmatel_spec *spec = codec->spec;
4093 hda_nid_t pin = cfg->hp_pins[0];
4094
4095 if (! pin)
4096 return 0;
4097
4098 if (is_jack_detectable(codec, pin))
4099 spec->hp_detect = 1;
4100
4101 return 0;
4102}
4103
4104/* add playback controls for LFE output */
4105static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4106 struct auto_pin_cfg *cfg)
4107{
4108 struct sigmatel_spec *spec = codec->spec;
4109 int err;
4110 hda_nid_t lfe_pin = 0x0;
4111 int i;
4112
4113 /*
4114 * search speaker outs and line outs for a mono speaker pin
4115 * with an amp. If one is found, add LFE controls
4116 * for it.
4117 */
4118 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4119 hda_nid_t pin = spec->autocfg.speaker_pins[i];
4120 unsigned int wcaps = get_wcaps(codec, pin);
4121 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4122 if (wcaps == AC_WCAP_OUT_AMP)
4123 /* found a mono speaker with an amp, must be lfe */
4124 lfe_pin = pin;
4125 }
4126 3566
4127 /* if speaker_outs is 0, then speakers may be in line_outs */ 3567 if (spec->aloopback_ctl &&
4128 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) { 3568 snd_hda_get_bool_hint(codec, "loopback") == 1) {
4129 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) { 3569 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, spec->aloopback_ctl))
4130 hda_nid_t pin = spec->autocfg.line_out_pins[i]; 3570 return -ENOMEM;
4131 unsigned int defcfg;
4132 defcfg = snd_hda_codec_get_pincfg(codec, pin);
4133 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
4134 unsigned int wcaps = get_wcaps(codec, pin);
4135 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4136 if (wcaps == AC_WCAP_OUT_AMP)
4137 /* found a mono speaker with an amp,
4138 must be lfe */
4139 lfe_pin = pin;
4140 }
4141 }
4142 } 3571 }
4143 3572
4144 if (lfe_pin) { 3573 if (spec->have_spdif_mux) {
4145 err = create_controls(codec, "LFE", lfe_pin, 1); 3574 err = stac_create_spdif_mux_ctls(codec);
4146 if (err < 0) 3575 if (err < 0)
4147 return err; 3576 return err;
4148 } 3577 }
4149 3578
4150 return 0; 3579 stac_init_power_map(codec);
4151}
4152
4153static int stac9200_parse_auto_config(struct hda_codec *codec)
4154{
4155 struct sigmatel_spec *spec = codec->spec;
4156 int err;
4157
4158 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
4159 return err;
4160
4161 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4162 return err;
4163
4164 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4165 return err;
4166
4167 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4168 return err;
4169
4170 if (spec->num_muxes > 0) {
4171 err = stac92xx_auto_create_mux_input_ctls(codec);
4172 if (err < 0)
4173 return err;
4174 }
4175
4176 err = stac92xx_add_input_source(spec);
4177 if (err < 0)
4178 return err;
4179
4180 if (spec->autocfg.dig_outs)
4181 spec->multiout.dig_out_nid = 0x05;
4182 if (spec->autocfg.dig_in_pin)
4183 spec->dig_in_nid = 0x04;
4184
4185 if (spec->kctls.list)
4186 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4187
4188 spec->input_mux = &spec->private_imux;
4189 spec->dinput_mux = &spec->private_dimux;
4190
4191 return 1;
4192}
4193
4194/*
4195 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4196 * funky external mute control using GPIO pins.
4197 */
4198
4199static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4200 unsigned int dir_mask, unsigned int data)
4201{
4202 unsigned int gpiostate, gpiomask, gpiodir;
4203
4204 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4205
4206 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4207 AC_VERB_GET_GPIO_DATA, 0);
4208 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4209
4210 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4211 AC_VERB_GET_GPIO_MASK, 0);
4212 gpiomask |= mask;
4213
4214 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4215 AC_VERB_GET_GPIO_DIRECTION, 0);
4216 gpiodir |= dir_mask;
4217
4218 /* Configure GPIOx as CMOS */
4219 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4220
4221 snd_hda_codec_write(codec, codec->afg, 0,
4222 AC_VERB_SET_GPIO_MASK, gpiomask);
4223 snd_hda_codec_read(codec, codec->afg, 0,
4224 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4225
4226 msleep(1);
4227
4228 snd_hda_codec_read(codec, codec->afg, 0,
4229 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4230}
4231
4232static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
4233 unsigned char type, int data)
4234{
4235 struct hda_jack_tbl *event;
4236
4237 event = snd_hda_jack_tbl_new(codec, nid);
4238 if (!event)
4239 return -ENOMEM;
4240 event->action = type;
4241 event->private_data = data;
4242 3580
4243 return 0; 3581 return 0;
4244} 3582}
4245 3583
4246static void handle_unsol_event(struct hda_codec *codec,
4247 struct hda_jack_tbl *event);
4248 3584
4249/* check if given nid is a valid pin and no other events are assigned 3585static int stac_init(struct hda_codec *codec)
4250 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4251 * Otherwise, returns zero.
4252 */
4253static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4254 unsigned int type)
4255{
4256 struct hda_jack_tbl *event;
4257
4258 if (!is_jack_detectable(codec, nid))
4259 return 0;
4260 event = snd_hda_jack_tbl_new(codec, nid);
4261 if (!event)
4262 return -ENOMEM;
4263 if (event->action && event->action != type)
4264 return 0;
4265 event->action = type;
4266 event->callback = handle_unsol_event;
4267 snd_hda_jack_detect_enable(codec, nid, 0);
4268 return 1;
4269}
4270
4271static int is_nid_out_jack_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4272{
4273 int i;
4274 for (i = 0; i < cfg->hp_outs; i++)
4275 if (cfg->hp_pins[i] == nid)
4276 return 1; /* nid is a HP-Out */
4277 for (i = 0; i < cfg->line_outs; i++)
4278 if (cfg->line_out_pins[i] == nid)
4279 return 1; /* nid is a line-Out */
4280 return 0; /* nid is not a HP-Out */
4281};
4282
4283static void stac92xx_power_down(struct hda_codec *codec)
4284{ 3586{
4285 struct sigmatel_spec *spec = codec->spec; 3587 struct sigmatel_spec *spec = codec->spec;
4286
4287 /* power down inactive DACs */
4288 const hda_nid_t *dac;
4289 for (dac = spec->dac_list; *dac; dac++)
4290 if (!check_all_dac_nids(spec, *dac))
4291 snd_hda_codec_write(codec, *dac, 0,
4292 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4293}
4294
4295static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4296 int enable);
4297
4298static inline int get_int_hint(struct hda_codec *codec, const char *key,
4299 int *valp)
4300{
4301 const char *p;
4302 p = snd_hda_get_hint(codec, key);
4303 if (p) {
4304 unsigned long val;
4305 if (!strict_strtoul(p, 0, &val)) {
4306 *valp = val;
4307 return 1;
4308 }
4309 }
4310 return 0;
4311}
4312
4313/* override some hints from the hwdep entry */
4314static void stac_store_hints(struct hda_codec *codec)
4315{
4316 struct sigmatel_spec *spec = codec->spec;
4317 int val;
4318
4319 val = snd_hda_get_bool_hint(codec, "hp_detect");
4320 if (val >= 0)
4321 spec->hp_detect = val;
4322 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4323 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4324 spec->gpio_mask;
4325 }
4326 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4327 spec->gpio_mask &= spec->gpio_mask;
4328 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4329 spec->gpio_dir &= spec->gpio_mask;
4330 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4331 spec->eapd_mask &= spec->gpio_mask;
4332 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4333 spec->gpio_mute &= spec->gpio_mask;
4334 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4335 if (val >= 0)
4336 spec->eapd_switch = val;
4337}
4338
4339static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
4340 const hda_nid_t *pins)
4341{
4342 while (num_pins--)
4343 stac_issue_unsol_event(codec, *pins++);
4344}
4345
4346/* fake event to set up pins */
4347static void stac_fake_hp_events(struct hda_codec *codec)
4348{
4349 struct sigmatel_spec *spec = codec->spec;
4350
4351 if (spec->autocfg.hp_outs)
4352 stac_issue_unsol_events(codec, spec->autocfg.hp_outs,
4353 spec->autocfg.hp_pins);
4354 if (spec->autocfg.line_outs &&
4355 spec->autocfg.line_out_pins[0] != spec->autocfg.hp_pins[0])
4356 stac_issue_unsol_events(codec, spec->autocfg.line_outs,
4357 spec->autocfg.line_out_pins);
4358}
4359
4360static int stac92xx_init(struct hda_codec *codec)
4361{
4362 struct sigmatel_spec *spec = codec->spec;
4363 struct auto_pin_cfg *cfg = &spec->autocfg;
4364 unsigned int gpio; 3588 unsigned int gpio;
4365 int i; 3589 int i;
4366 3590
4367 if (spec->init)
4368 snd_hda_sequence_write(codec, spec->init);
4369
4370 /* power down adcs initially */
4371 if (spec->powerdown_adcs)
4372 for (i = 0; i < spec->num_adcs; i++)
4373 snd_hda_codec_write(codec,
4374 spec->adc_nids[i], 0,
4375 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4376
4377 /* override some hints */ 3591 /* override some hints */
4378 stac_store_hints(codec); 3592 stac_store_hints(codec);
4379 3593
@@ -4386,180 +3600,33 @@ static int stac92xx_init(struct hda_codec *codec)
4386 gpio |= spec->eapd_mask; 3600 gpio |= spec->eapd_mask;
4387 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio); 3601 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4388 3602
4389 /* set up pins */ 3603 snd_hda_gen_init(codec);
4390 if (spec->hp_detect) {
4391 /* Enable unsolicited responses on the HP widget */
4392 for (i = 0; i < cfg->hp_outs; i++) {
4393 hda_nid_t nid = cfg->hp_pins[i];
4394 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4395 }
4396 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4397 cfg->speaker_outs > 0) {
4398 /* enable pin-detect for line-outs as well */
4399 for (i = 0; i < cfg->line_outs; i++) {
4400 hda_nid_t nid = cfg->line_out_pins[i];
4401 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4402 }
4403 }
4404
4405 /* force to enable the first line-out; the others are set up
4406 * in unsol_event
4407 */
4408 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4409 AC_PINCTL_OUT_EN);
4410 /* fake event to set up pins */
4411 stac_fake_hp_events(codec);
4412 } else {
4413 stac92xx_auto_init_multi_out(codec);
4414 stac92xx_auto_init_hp_out(codec);
4415 for (i = 0; i < cfg->hp_outs; i++)
4416 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4417 }
4418 if (spec->auto_mic) {
4419 /* initialize connection to analog input */
4420 if (spec->dmux_nids)
4421 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4422 AC_VERB_SET_CONNECT_SEL, 0);
4423 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4424 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4425 if (enable_pin_detect(codec, spec->dock_mic.pin,
4426 STAC_MIC_EVENT))
4427 stac_issue_unsol_event(codec, spec->dock_mic.pin);
4428 }
4429 for (i = 0; i < cfg->num_inputs; i++) {
4430 hda_nid_t nid = cfg->inputs[i].pin;
4431 int type = cfg->inputs[i].type;
4432 unsigned int pinctl, conf;
4433 if (type == AUTO_PIN_MIC) {
4434 /* for mic pins, force to initialize */
4435 pinctl = snd_hda_get_default_vref(codec, nid);
4436 pinctl |= AC_PINCTL_IN_EN;
4437 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4438 } else {
4439 pinctl = snd_hda_codec_read(codec, nid, 0,
4440 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4441 /* if PINCTL already set then skip */
4442 /* Also, if both INPUT and OUTPUT are set,
4443 * it must be a BIOS bug; need to override, too
4444 */
4445 if (!(pinctl & AC_PINCTL_IN_EN) ||
4446 (pinctl & AC_PINCTL_OUT_EN)) {
4447 pinctl &= ~AC_PINCTL_OUT_EN;
4448 pinctl |= AC_PINCTL_IN_EN;
4449 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4450 }
4451 }
4452 conf = snd_hda_codec_get_pincfg(codec, nid);
4453 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4454 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4455 stac_issue_unsol_event(codec, nid);
4456 }
4457 }
4458 for (i = 0; i < spec->num_dmics; i++)
4459 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4460 AC_PINCTL_IN_EN);
4461 if (cfg->dig_out_pins[0])
4462 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4463 AC_PINCTL_OUT_EN);
4464 if (cfg->dig_in_pin)
4465 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4466 AC_PINCTL_IN_EN);
4467 for (i = 0; i < spec->num_pwrs; i++) {
4468 hda_nid_t nid = spec->pwr_nids[i];
4469 unsigned int pinctl, def_conf;
4470
4471 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4472 def_conf = get_defcfg_connect(def_conf);
4473 if (def_conf == AC_JACK_PORT_NONE) {
4474 /* power off unused ports */
4475 stac_toggle_power_map(codec, nid, 0);
4476 continue;
4477 }
4478 if (def_conf == AC_JACK_PORT_FIXED) {
4479 /* no need for jack detection for fixed pins */
4480 stac_toggle_power_map(codec, nid, 1);
4481 continue;
4482 }
4483 /* power on when no jack detection is available */
4484 /* or when the VREF is used for controlling LED */
4485 if (!spec->hp_detect ||
4486 spec->vref_mute_led_nid == nid ||
4487 !is_jack_detectable(codec, nid)) {
4488 stac_toggle_power_map(codec, nid, 1);
4489 continue;
4490 }
4491
4492 if (is_nid_out_jack_pin(cfg, nid))
4493 continue; /* already has an unsol event */
4494
4495 pinctl = snd_hda_codec_read(codec, nid, 0,
4496 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4497 /* outputs are only ports capable of power management
4498 * any attempts on powering down a input port cause the
4499 * referenced VREF to act quirky.
4500 */
4501 if (pinctl & AC_PINCTL_IN_EN) {
4502 stac_toggle_power_map(codec, nid, 1);
4503 continue;
4504 }
4505 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
4506 stac_issue_unsol_event(codec, nid);
4507 continue;
4508 }
4509 /* none of the above, turn the port OFF */
4510 stac_toggle_power_map(codec, nid, 0);
4511 }
4512
4513 /* sync mute LED */
4514 if (spec->gpio_led) {
4515 if (spec->vmaster_mute.hook)
4516 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4517 else /* the very first init call doesn't have vmaster yet */
4518 stac92xx_update_led_status(codec, false);
4519 }
4520 3604
4521 /* sync the power-map */ 3605 /* sync the power-map */
4522 if (spec->num_pwrs) 3606 if (spec->num_pwrs)
4523 snd_hda_codec_write(codec, codec->afg, 0, 3607 snd_hda_codec_write(codec, codec->afg, 0,
4524 AC_VERB_IDT_SET_POWER_MAP, 3608 AC_VERB_IDT_SET_POWER_MAP,
4525 spec->power_map_bits); 3609 spec->power_map_bits);
4526 if (spec->dac_list)
4527 stac92xx_power_down(codec);
4528 return 0;
4529}
4530 3610
4531static void stac92xx_free_kctls(struct hda_codec *codec) 3611 /* power down inactive ADCs */
4532{ 3612 if (spec->powerdown_adcs) {
4533 struct sigmatel_spec *spec = codec->spec; 3613 for (i = 0; i < spec->gen.num_all_adcs; i++) {
4534 3614 if (spec->active_adcs & (1 << i))
4535 if (spec->kctls.list) { 3615 continue;
4536 struct snd_kcontrol_new *kctl = spec->kctls.list; 3616 snd_hda_codec_write(codec, spec->gen.all_adcs[i], 0,
4537 int i; 3617 AC_VERB_SET_POWER_STATE,
4538 for (i = 0; i < spec->kctls.used; i++) 3618 AC_PWRST_D3);
4539 kfree(kctl[i].name); 3619 }
4540 } 3620 }
4541 snd_array_free(&spec->kctls);
4542}
4543 3621
4544static void stac92xx_shutup_pins(struct hda_codec *codec) 3622 return 0;
4545{
4546 unsigned int i, def_conf;
4547
4548 if (codec->bus->shutdown)
4549 return;
4550 for (i = 0; i < codec->init_pins.used; i++) {
4551 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4552 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4553 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4554 snd_hda_set_pin_ctl(codec, pin->nid, 0);
4555 }
4556} 3623}
4557 3624
4558static void stac92xx_shutup(struct hda_codec *codec) 3625static void stac_shutup(struct hda_codec *codec)
4559{ 3626{
4560 struct sigmatel_spec *spec = codec->spec; 3627 struct sigmatel_spec *spec = codec->spec;
4561 3628
4562 stac92xx_shutup_pins(codec); 3629 snd_hda_shutup_pins(codec);
4563 3630
4564 if (spec->eapd_mask) 3631 if (spec->eapd_mask)
4565 stac_gpio_set(codec, spec->gpio_mask, 3632 stac_gpio_set(codec, spec->gpio_mask,
@@ -4567,467 +3634,18 @@ static void stac92xx_shutup(struct hda_codec *codec)
4567 ~spec->eapd_mask); 3634 ~spec->eapd_mask);
4568} 3635}
4569 3636
4570static void stac92xx_free(struct hda_codec *codec) 3637static void stac_free(struct hda_codec *codec)
4571{ 3638{
4572 struct sigmatel_spec *spec = codec->spec; 3639 struct sigmatel_spec *spec = codec->spec;
4573 3640
4574 if (! spec) 3641 if (!spec)
4575 return; 3642 return;
4576 3643
3644 snd_hda_gen_spec_free(&spec->gen);
4577 kfree(spec); 3645 kfree(spec);
4578 snd_hda_detach_beep_device(codec); 3646 snd_hda_detach_beep_device(codec);
4579} 3647}
4580 3648
4581static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4582 unsigned int flag)
4583{
4584 unsigned int old_ctl, pin_ctl;
4585
4586 pin_ctl = snd_hda_codec_read(codec, nid,
4587 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4588
4589 if (pin_ctl & AC_PINCTL_IN_EN) {
4590 /*
4591 * we need to check the current set-up direction of
4592 * shared input pins since they can be switched via
4593 * "xxx as Output" mixer switch
4594 */
4595 struct sigmatel_spec *spec = codec->spec;
4596 if (nid == spec->line_switch || nid == spec->mic_switch)
4597 return;
4598 }
4599
4600 old_ctl = pin_ctl;
4601 /* if setting pin direction bits, clear the current
4602 direction bits first */
4603 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4604 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4605
4606 pin_ctl |= flag;
4607 if (old_ctl != pin_ctl)
4608 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl);
4609}
4610
4611static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4612 unsigned int flag)
4613{
4614 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4615 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4616 if (pin_ctl & flag)
4617 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl & ~flag);
4618}
4619
4620static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4621{
4622 if (!nid)
4623 return 0;
4624 return snd_hda_jack_detect(codec, nid);
4625}
4626
4627static void stac92xx_line_out_detect(struct hda_codec *codec,
4628 int presence)
4629{
4630 struct sigmatel_spec *spec = codec->spec;
4631 struct auto_pin_cfg *cfg = &spec->autocfg;
4632 int i;
4633
4634 if (cfg->speaker_outs == 0)
4635 return;
4636
4637 for (i = 0; i < cfg->line_outs; i++) {
4638 if (presence)
4639 break;
4640 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4641 if (presence) {
4642 unsigned int pinctl;
4643 pinctl = snd_hda_codec_read(codec,
4644 cfg->line_out_pins[i], 0,
4645 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4646 if (pinctl & AC_PINCTL_IN_EN)
4647 presence = 0; /* mic- or line-input */
4648 }
4649 }
4650
4651 if (presence) {
4652 /* disable speakers */
4653 for (i = 0; i < cfg->speaker_outs; i++)
4654 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4655 AC_PINCTL_OUT_EN);
4656 if (spec->eapd_mask && spec->eapd_switch)
4657 stac_gpio_set(codec, spec->gpio_mask,
4658 spec->gpio_dir, spec->gpio_data &
4659 ~spec->eapd_mask);
4660 } else {
4661 /* enable speakers */
4662 for (i = 0; i < cfg->speaker_outs; i++)
4663 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4664 AC_PINCTL_OUT_EN);
4665 if (spec->eapd_mask && spec->eapd_switch)
4666 stac_gpio_set(codec, spec->gpio_mask,
4667 spec->gpio_dir, spec->gpio_data |
4668 spec->eapd_mask);
4669 }
4670}
4671
4672/* return non-zero if the hp-pin of the given array index isn't
4673 * a jack-detection target
4674 */
4675static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4676{
4677 struct auto_pin_cfg *cfg = &spec->autocfg;
4678
4679 /* ignore sensing of shared line and mic jacks */
4680 if (cfg->hp_pins[i] == spec->line_switch)
4681 return 1;
4682 if (cfg->hp_pins[i] == spec->mic_switch)
4683 return 1;
4684 /* ignore if the pin is set as line-out */
4685 if (cfg->hp_pins[i] == spec->hp_switch)
4686 return 1;
4687 return 0;
4688}
4689
4690static void stac92xx_hp_detect(struct hda_codec *codec)
4691{
4692 struct sigmatel_spec *spec = codec->spec;
4693 struct auto_pin_cfg *cfg = &spec->autocfg;
4694 int i, presence;
4695
4696 presence = 0;
4697 if (spec->gpio_mute)
4698 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4699 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4700
4701 for (i = 0; i < cfg->hp_outs; i++) {
4702 if (presence)
4703 break;
4704 if (no_hp_sensing(spec, i))
4705 continue;
4706 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4707 if (presence) {
4708 unsigned int pinctl;
4709 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4710 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4711 if (pinctl & AC_PINCTL_IN_EN)
4712 presence = 0; /* mic- or line-input */
4713 }
4714 }
4715
4716 if (presence) {
4717 /* disable lineouts */
4718 if (spec->hp_switch)
4719 stac92xx_reset_pinctl(codec, spec->hp_switch,
4720 AC_PINCTL_OUT_EN);
4721 for (i = 0; i < cfg->line_outs; i++)
4722 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4723 AC_PINCTL_OUT_EN);
4724 } else {
4725 /* enable lineouts */
4726 if (spec->hp_switch)
4727 stac92xx_set_pinctl(codec, spec->hp_switch,
4728 AC_PINCTL_OUT_EN);
4729 for (i = 0; i < cfg->line_outs; i++)
4730 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4731 AC_PINCTL_OUT_EN);
4732 }
4733 stac92xx_line_out_detect(codec, presence);
4734 /* toggle hp outs */
4735 for (i = 0; i < cfg->hp_outs; i++) {
4736 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4737 if (no_hp_sensing(spec, i))
4738 continue;
4739 if (1 /*presence*/)
4740 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4741#if 0 /* FIXME */
4742/* Resetting the pinctl like below may lead to (a sort of) regressions
4743 * on some devices since they use the HP pin actually for line/speaker
4744 * outs although the default pin config shows a different pin (that is
4745 * wrong and useless).
4746 *
4747 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4748 * But, disabling the code below just works around it, and I'm too tired of
4749 * bug reports with such devices...
4750 */
4751 else
4752 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4753#endif /* FIXME */
4754 }
4755}
4756
4757static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4758 int enable)
4759{
4760 struct sigmatel_spec *spec = codec->spec;
4761 unsigned int idx, val;
4762
4763 for (idx = 0; idx < spec->num_pwrs; idx++) {
4764 if (spec->pwr_nids[idx] == nid)
4765 break;
4766 }
4767 if (idx >= spec->num_pwrs)
4768 return;
4769
4770 idx = 1 << idx;
4771
4772 val = spec->power_map_bits;
4773 if (enable)
4774 val &= ~idx;
4775 else
4776 val |= idx;
4777
4778 /* power down unused output ports */
4779 if (val != spec->power_map_bits) {
4780 spec->power_map_bits = val;
4781 snd_hda_codec_write(codec, codec->afg, 0,
4782 AC_VERB_IDT_SET_POWER_MAP, val);
4783 }
4784}
4785
4786static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4787{
4788 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4789}
4790
4791/* get the pin connection (fixed, none, etc) */
4792static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4793{
4794 struct sigmatel_spec *spec = codec->spec;
4795 unsigned int cfg;
4796
4797 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4798 return get_defcfg_connect(cfg);
4799}
4800
4801static int stac92xx_connected_ports(struct hda_codec *codec,
4802 const hda_nid_t *nids, int num_nids)
4803{
4804 struct sigmatel_spec *spec = codec->spec;
4805 int idx, num;
4806 unsigned int def_conf;
4807
4808 for (num = 0; num < num_nids; num++) {
4809 for (idx = 0; idx < spec->num_pins; idx++)
4810 if (spec->pin_nids[idx] == nids[num])
4811 break;
4812 if (idx >= spec->num_pins)
4813 break;
4814 def_conf = stac_get_defcfg_connect(codec, idx);
4815 if (def_conf == AC_JACK_PORT_NONE)
4816 break;
4817 }
4818 return num;
4819}
4820
4821static void stac92xx_mic_detect(struct hda_codec *codec)
4822{
4823 struct sigmatel_spec *spec = codec->spec;
4824 struct sigmatel_mic_route *mic;
4825
4826 if (get_pin_presence(codec, spec->ext_mic.pin))
4827 mic = &spec->ext_mic;
4828 else if (get_pin_presence(codec, spec->dock_mic.pin))
4829 mic = &spec->dock_mic;
4830 else
4831 mic = &spec->int_mic;
4832 if (mic->dmux_idx >= 0)
4833 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4834 AC_VERB_SET_CONNECT_SEL,
4835 mic->dmux_idx);
4836 if (mic->mux_idx >= 0)
4837 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4838 AC_VERB_SET_CONNECT_SEL,
4839 mic->mux_idx);
4840}
4841
4842static void handle_unsol_event(struct hda_codec *codec,
4843 struct hda_jack_tbl *event)
4844{
4845 struct sigmatel_spec *spec = codec->spec;
4846 int data;
4847
4848 switch (event->action) {
4849 case STAC_HP_EVENT:
4850 case STAC_LO_EVENT:
4851 stac92xx_hp_detect(codec);
4852 break;
4853 case STAC_MIC_EVENT:
4854 stac92xx_mic_detect(codec);
4855 break;
4856 }
4857
4858 switch (event->action) {
4859 case STAC_HP_EVENT:
4860 case STAC_LO_EVENT:
4861 case STAC_MIC_EVENT:
4862 case STAC_INSERT_EVENT:
4863 case STAC_PWR_EVENT:
4864 if (spec->num_pwrs > 0)
4865 stac92xx_pin_sense(codec, event->nid);
4866
4867 switch (codec->subsystem_id) {
4868 case 0x103c308f:
4869 if (event->nid == 0xb) {
4870 int pin = AC_PINCTL_IN_EN;
4871
4872 if (get_pin_presence(codec, 0xa)
4873 && get_pin_presence(codec, 0xb))
4874 pin |= AC_PINCTL_VREF_80;
4875 if (!get_pin_presence(codec, 0xb))
4876 pin |= AC_PINCTL_VREF_80;
4877
4878 /* toggle VREF state based on mic + hp pin
4879 * status
4880 */
4881 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4882 }
4883 }
4884 break;
4885 case STAC_VREF_EVENT:
4886 data = snd_hda_codec_read(codec, codec->afg, 0,
4887 AC_VERB_GET_GPIO_DATA, 0);
4888 /* toggle VREF state based on GPIOx status */
4889 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4890 !!(data & (1 << event->private_data)));
4891 break;
4892 }
4893}
4894
4895static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4896{
4897 struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
4898 if (!event)
4899 return;
4900 handle_unsol_event(codec, event);
4901}
4902
4903static int hp_blike_system(u32 subsystem_id);
4904
4905static void set_hp_led_gpio(struct hda_codec *codec)
4906{
4907 struct sigmatel_spec *spec = codec->spec;
4908 unsigned int gpio;
4909
4910 if (spec->gpio_led)
4911 return;
4912
4913 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4914 gpio &= AC_GPIO_IO_COUNT;
4915 if (gpio > 3)
4916 spec->gpio_led = 0x08; /* GPIO 3 */
4917 else
4918 spec->gpio_led = 0x01; /* GPIO 0 */
4919}
4920
4921/*
4922 * This method searches for the mute LED GPIO configuration
4923 * provided as OEM string in SMBIOS. The format of that string
4924 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4925 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4926 * that corresponds to the NOT muted state of the master volume
4927 * and G is the index of the GPIO to use as the mute LED control (0..9)
4928 * If _G portion is missing it is assigned based on the codec ID
4929 *
4930 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4931 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4932 *
4933 *
4934 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4935 * SMBIOS - at least the ones I have seen do not have them - which include
4936 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4937 * HP Pavilion dv9500t CTO.
4938 * Need more information on whether it is true across the entire series.
4939 * -- kunal
4940 */
4941static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
4942{
4943 struct sigmatel_spec *spec = codec->spec;
4944 const struct dmi_device *dev = NULL;
4945
4946 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4947 get_int_hint(codec, "gpio_led_polarity",
4948 &spec->gpio_led_polarity);
4949 return 1;
4950 }
4951 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4952 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4953 NULL, dev))) {
4954 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
4955 &spec->gpio_led_polarity,
4956 &spec->gpio_led) == 2) {
4957 unsigned int max_gpio;
4958 max_gpio = snd_hda_param_read(codec, codec->afg,
4959 AC_PAR_GPIO_CAP);
4960 max_gpio &= AC_GPIO_IO_COUNT;
4961 if (spec->gpio_led < max_gpio)
4962 spec->gpio_led = 1 << spec->gpio_led;
4963 else
4964 spec->vref_mute_led_nid = spec->gpio_led;
4965 return 1;
4966 }
4967 if (sscanf(dev->name, "HP_Mute_LED_%d",
4968 &spec->gpio_led_polarity) == 1) {
4969 set_hp_led_gpio(codec);
4970 return 1;
4971 }
4972 /* BIOS bug: unfilled OEM string */
4973 if (strstr(dev->name, "HP_Mute_LED_P_G")) {
4974 set_hp_led_gpio(codec);
4975 switch (codec->subsystem_id) {
4976 case 0x103c148a:
4977 spec->gpio_led_polarity = 0;
4978 break;
4979 default:
4980 spec->gpio_led_polarity = 1;
4981 break;
4982 }
4983 return 1;
4984 }
4985 }
4986
4987 /*
4988 * Fallback case - if we don't find the DMI strings,
4989 * we statically set the GPIO - if not a B-series system
4990 * and default polarity is provided
4991 */
4992 if (!hp_blike_system(codec->subsystem_id) &&
4993 (default_polarity == 0 || default_polarity == 1)) {
4994 set_hp_led_gpio(codec);
4995 spec->gpio_led_polarity = default_polarity;
4996 return 1;
4997 }
4998 }
4999 return 0;
5000}
5001
5002static int hp_blike_system(u32 subsystem_id)
5003{
5004 switch (subsystem_id) {
5005 case 0x103c1520:
5006 case 0x103c1521:
5007 case 0x103c1523:
5008 case 0x103c1524:
5009 case 0x103c1525:
5010 case 0x103c1722:
5011 case 0x103c1723:
5012 case 0x103c1724:
5013 case 0x103c1725:
5014 case 0x103c1726:
5015 case 0x103c1727:
5016 case 0x103c1728:
5017 case 0x103c1729:
5018 case 0x103c172a:
5019 case 0x103c172b:
5020 case 0x103c307e:
5021 case 0x103c307f:
5022 case 0x103c3080:
5023 case 0x103c3081:
5024 case 0x103c7007:
5025 case 0x103c7008:
5026 return 1;
5027 }
5028 return 0;
5029}
5030
5031#ifdef CONFIG_PROC_FS 3649#ifdef CONFIG_PROC_FS
5032static void stac92hd_proc_hook(struct snd_info_buffer *buffer, 3650static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
5033 struct hda_codec *codec, hda_nid_t nid) 3651 struct hda_codec *codec, hda_nid_t nid)
@@ -5076,24 +3694,22 @@ static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5076#endif 3694#endif
5077 3695
5078#ifdef CONFIG_PM 3696#ifdef CONFIG_PM
5079static int stac92xx_resume(struct hda_codec *codec) 3697static int stac_resume(struct hda_codec *codec)
5080{ 3698{
5081 stac92xx_init(codec); 3699 codec->patch_ops.init(codec);
5082 snd_hda_codec_resume_amp(codec); 3700 snd_hda_codec_resume_amp(codec);
5083 snd_hda_codec_resume_cache(codec); 3701 snd_hda_codec_resume_cache(codec);
5084 /* fake event to set up pins again to override cached values */
5085 stac_fake_hp_events(codec);
5086 return 0; 3702 return 0;
5087} 3703}
5088 3704
5089static int stac92xx_suspend(struct hda_codec *codec) 3705static int stac_suspend(struct hda_codec *codec)
5090{ 3706{
5091 stac92xx_shutup(codec); 3707 stac_shutup(codec);
5092 return 0; 3708 return 0;
5093} 3709}
5094 3710
5095static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg, 3711static void stac_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5096 unsigned int power_state) 3712 unsigned int power_state)
5097{ 3713{
5098 unsigned int afg_power_state = power_state; 3714 unsigned int afg_power_state = power_state;
5099 struct sigmatel_spec *spec = codec->spec; 3715 struct sigmatel_spec *spec = codec->spec;
@@ -5110,67 +3726,37 @@ static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5110 } 3726 }
5111 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 3727 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5112 afg_power_state); 3728 afg_power_state);
5113 snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 3729 snd_hda_codec_set_power_to_all(codec, fg, power_state);
5114} 3730}
5115#else 3731#else
5116#define stac92xx_suspend NULL 3732#define stac_suspend NULL
5117#define stac92xx_resume NULL 3733#define stac_resume NULL
5118#define stac92xx_set_power_state NULL 3734#define stac_set_power_state NULL
5119#endif /* CONFIG_PM */ 3735#endif /* CONFIG_PM */
5120 3736
5121/* update mute-LED accoring to the master switch */ 3737static const struct hda_codec_ops stac_patch_ops = {
5122static void stac92xx_update_led_status(struct hda_codec *codec, int enabled) 3738 .build_controls = snd_hda_gen_build_controls,
5123{ 3739 .build_pcms = snd_hda_gen_build_pcms,
5124 struct sigmatel_spec *spec = codec->spec; 3740 .init = stac_init,
5125 int muted = !enabled; 3741 .free = stac_free,
5126
5127 if (!spec->gpio_led)
5128 return;
5129
5130 /* LED state is inverted on these systems */
5131 if (spec->gpio_led_polarity)
5132 muted = !muted;
5133
5134 if (!spec->vref_mute_led_nid) {
5135 if (muted)
5136 spec->gpio_data |= spec->gpio_led;
5137 else
5138 spec->gpio_data &= ~spec->gpio_led;
5139 stac_gpio_set(codec, spec->gpio_mask,
5140 spec->gpio_dir, spec->gpio_data);
5141 } else {
5142 spec->vref_led = muted ? AC_PINCTL_VREF_50 : AC_PINCTL_VREF_GRD;
5143 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5144 spec->vref_led);
5145 }
5146}
5147
5148static const struct hda_codec_ops stac92xx_patch_ops = {
5149 .build_controls = stac92xx_build_controls,
5150 .build_pcms = stac92xx_build_pcms,
5151 .init = stac92xx_init,
5152 .free = stac92xx_free,
5153 .unsol_event = snd_hda_jack_unsol_event, 3742 .unsol_event = snd_hda_jack_unsol_event,
5154#ifdef CONFIG_PM 3743#ifdef CONFIG_PM
5155 .suspend = stac92xx_suspend, 3744 .suspend = stac_suspend,
5156 .resume = stac92xx_resume, 3745 .resume = stac_resume,
5157#endif 3746#endif
5158 .reboot_notify = stac92xx_shutup, 3747 .reboot_notify = stac_shutup,
5159}; 3748};
5160 3749
5161static int alloc_stac_spec(struct hda_codec *codec, int num_pins, 3750static int alloc_stac_spec(struct hda_codec *codec)
5162 const hda_nid_t *pin_nids)
5163{ 3751{
5164 struct sigmatel_spec *spec; 3752 struct sigmatel_spec *spec;
5165 3753
5166 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3754 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5167 if (!spec) 3755 if (!spec)
5168 return -ENOMEM; 3756 return -ENOMEM;
3757 snd_hda_gen_spec_init(&spec->gen);
5169 codec->spec = spec; 3758 codec->spec = spec;
5170 codec->no_trigger_sense = 1; /* seems common with STAC/IDT codecs */ 3759 codec->no_trigger_sense = 1; /* seems common with STAC/IDT codecs */
5171 spec->num_pins = num_pins;
5172 spec->pin_nids = pin_nids;
5173 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
5174 return 0; 3760 return 0;
5175} 3761}
5176 3762
@@ -5179,59 +3765,29 @@ static int patch_stac9200(struct hda_codec *codec)
5179 struct sigmatel_spec *spec; 3765 struct sigmatel_spec *spec;
5180 int err; 3766 int err;
5181 3767
5182 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9200_pin_nids), 3768 err = alloc_stac_spec(codec);
5183 stac9200_pin_nids);
5184 if (err < 0) 3769 if (err < 0)
5185 return err; 3770 return err;
5186 3771
5187 spec = codec->spec; 3772 spec = codec->spec;
5188 spec->linear_tone_beep = 1; 3773 spec->linear_tone_beep = 1;
5189 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS, 3774 spec->gen.own_eapd_ctl = 1;
5190 stac9200_models,
5191 stac9200_cfg_tbl);
5192 if (spec->board_config < 0)
5193 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5194 codec->chip_name);
5195 else
5196 stac92xx_set_config_regs(codec,
5197 stac9200_brd_tbl[spec->board_config]);
5198
5199 spec->multiout.max_channels = 2;
5200 spec->multiout.num_dacs = 1;
5201 spec->multiout.dac_nids = stac9200_dac_nids;
5202 spec->adc_nids = stac9200_adc_nids;
5203 spec->mux_nids = stac9200_mux_nids;
5204 spec->num_muxes = 1;
5205 spec->num_dmics = 0;
5206 spec->num_adcs = 1;
5207 spec->num_pwrs = 0;
5208
5209 if (spec->board_config == STAC_9200_M4 ||
5210 spec->board_config == STAC_9200_M4_2 ||
5211 spec->board_config == STAC_9200_OQO)
5212 spec->init = stac9200_eapd_init;
5213 else
5214 spec->init = stac9200_core_init;
5215 spec->mixer = stac9200_mixer;
5216 3775
5217 if (spec->board_config == STAC_9200_PANASONIC) { 3776 codec->patch_ops = stac_patch_ops;
5218 spec->gpio_mask = spec->gpio_dir = 0x09;
5219 spec->gpio_data = 0x00;
5220 }
5221 3777
5222 err = stac9200_parse_auto_config(codec); 3778 snd_hda_add_verbs(codec, stac9200_eapd_init);
3779
3780 snd_hda_pick_fixup(codec, stac9200_models, stac9200_fixup_tbl,
3781 stac9200_fixups);
3782 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3783
3784 err = stac_parse_auto_config(codec);
5223 if (err < 0) { 3785 if (err < 0) {
5224 stac92xx_free(codec); 3786 stac_free(codec);
5225 return err; 3787 return err;
5226 } 3788 }
5227 3789
5228 /* CF-74 has no headphone detection, and the driver should *NOT* 3790 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5229 * do detection and HP/speaker toggle because the hardware does it.
5230 */
5231 if (spec->board_config == STAC_9200_PANASONIC)
5232 spec->hp_detect = 0;
5233
5234 codec->patch_ops = stac92xx_patch_ops;
5235 3791
5236 return 0; 3792 return 0;
5237} 3793}
@@ -5241,79 +3797,29 @@ static int patch_stac925x(struct hda_codec *codec)
5241 struct sigmatel_spec *spec; 3797 struct sigmatel_spec *spec;
5242 int err; 3798 int err;
5243 3799
5244 err = alloc_stac_spec(codec, ARRAY_SIZE(stac925x_pin_nids), 3800 err = alloc_stac_spec(codec);
5245 stac925x_pin_nids);
5246 if (err < 0) 3801 if (err < 0)
5247 return err; 3802 return err;
5248 3803
5249 spec = codec->spec; 3804 spec = codec->spec;
5250 spec->linear_tone_beep = 1; 3805 spec->linear_tone_beep = 1;
3806 spec->gen.own_eapd_ctl = 1;
5251 3807
5252 /* Check first for codec ID */ 3808 codec->patch_ops = stac_patch_ops;
5253 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5254 STAC_925x_MODELS,
5255 stac925x_models,
5256 stac925x_codec_id_cfg_tbl);
5257
5258 /* Now checks for PCI ID, if codec ID is not found */
5259 if (spec->board_config < 0)
5260 spec->board_config = snd_hda_check_board_config(codec,
5261 STAC_925x_MODELS,
5262 stac925x_models,
5263 stac925x_cfg_tbl);
5264 again:
5265 if (spec->board_config < 0)
5266 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5267 codec->chip_name);
5268 else
5269 stac92xx_set_config_regs(codec,
5270 stac925x_brd_tbl[spec->board_config]);
5271
5272 spec->multiout.max_channels = 2;
5273 spec->multiout.num_dacs = 1;
5274 spec->multiout.dac_nids = stac925x_dac_nids;
5275 spec->adc_nids = stac925x_adc_nids;
5276 spec->mux_nids = stac925x_mux_nids;
5277 spec->num_muxes = 1;
5278 spec->num_adcs = 1;
5279 spec->num_pwrs = 0;
5280 switch (codec->vendor_id) {
5281 case 0x83847632: /* STAC9202 */
5282 case 0x83847633: /* STAC9202D */
5283 case 0x83847636: /* STAC9251 */
5284 case 0x83847637: /* STAC9251D */
5285 spec->num_dmics = STAC925X_NUM_DMICS;
5286 spec->dmic_nids = stac925x_dmic_nids;
5287 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5288 spec->dmux_nids = stac925x_dmux_nids;
5289 break;
5290 default:
5291 spec->num_dmics = 0;
5292 break;
5293 }
5294 3809
5295 spec->init = stac925x_core_init; 3810 snd_hda_add_verbs(codec, stac925x_core_init);
5296 spec->mixer = stac925x_mixer; 3811
5297 spec->num_caps = 1; 3812 snd_hda_pick_fixup(codec, stac925x_models, stac925x_fixup_tbl,
5298 spec->capvols = stac925x_capvols; 3813 stac925x_fixups);
5299 spec->capsws = stac925x_capsws; 3814 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5300 3815
5301 err = stac92xx_parse_auto_config(codec); 3816 err = stac_parse_auto_config(codec);
5302 if (!err) {
5303 if (spec->board_config < 0) {
5304 printk(KERN_WARNING "hda_codec: No auto-config is "
5305 "available, default to model=ref\n");
5306 spec->board_config = STAC_925x_REF;
5307 goto again;
5308 }
5309 err = -EINVAL;
5310 }
5311 if (err < 0) { 3817 if (err < 0) {
5312 stac92xx_free(codec); 3818 stac_free(codec);
5313 return err; 3819 return err;
5314 } 3820 }
5315 3821
5316 codec->patch_ops = stac92xx_patch_ops; 3822 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5317 3823
5318 return 0; 3824 return 0;
5319} 3825}
@@ -5321,467 +3827,181 @@ static int patch_stac925x(struct hda_codec *codec)
5321static int patch_stac92hd73xx(struct hda_codec *codec) 3827static int patch_stac92hd73xx(struct hda_codec *codec)
5322{ 3828{
5323 struct sigmatel_spec *spec; 3829 struct sigmatel_spec *spec;
5324 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5325 int err; 3830 int err;
5326 int num_dacs; 3831 int num_dacs;
5327 3832
5328 err = alloc_stac_spec(codec, ARRAY_SIZE(stac92hd73xx_pin_nids), 3833 err = alloc_stac_spec(codec);
5329 stac92hd73xx_pin_nids);
5330 if (err < 0) 3834 if (err < 0)
5331 return err; 3835 return err;
5332 3836
5333 spec = codec->spec; 3837 spec = codec->spec;
5334 spec->linear_tone_beep = 0; 3838 spec->linear_tone_beep = 0;
5335 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs; 3839 spec->gen.mixer_nid = 0x1d;
5336 spec->board_config = snd_hda_check_board_config(codec, 3840 spec->have_spdif_mux = 1;
5337 STAC_92HD73XX_MODELS,
5338 stac92hd73xx_models,
5339 stac92hd73xx_cfg_tbl);
5340 /* check codec subsystem id if not found */
5341 if (spec->board_config < 0)
5342 spec->board_config =
5343 snd_hda_check_board_codec_sid_config(codec,
5344 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5345 stac92hd73xx_codec_id_cfg_tbl);
5346again:
5347 if (spec->board_config < 0)
5348 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5349 codec->chip_name);
5350 else
5351 stac92xx_set_config_regs(codec,
5352 stac92hd73xx_brd_tbl[spec->board_config]);
5353
5354 num_dacs = snd_hda_get_connections(codec, 0x0a,
5355 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5356 3841
3842 num_dacs = snd_hda_get_num_conns(codec, 0x0a) - 1;
5357 if (num_dacs < 3 || num_dacs > 5) { 3843 if (num_dacs < 3 || num_dacs > 5) {
5358 printk(KERN_WARNING "hda_codec: Could not determine " 3844 printk(KERN_WARNING "hda_codec: Could not determine "
5359 "number of channels defaulting to DAC count\n"); 3845 "number of channels defaulting to DAC count\n");
5360 num_dacs = STAC92HD73_DAC_COUNT; 3846 num_dacs = 5;
5361 } 3847 }
5362 spec->init = stac92hd73xx_core_init; 3848
5363 switch (num_dacs) { 3849 switch (num_dacs) {
5364 case 0x3: /* 6 Channel */ 3850 case 0x3: /* 6 Channel */
5365 spec->aloopback_ctl = stac92hd73xx_6ch_loopback; 3851 spec->aloopback_ctl = &stac92hd73xx_6ch_loopback;
5366 break; 3852 break;
5367 case 0x4: /* 8 Channel */ 3853 case 0x4: /* 8 Channel */
5368 spec->aloopback_ctl = stac92hd73xx_8ch_loopback; 3854 spec->aloopback_ctl = &stac92hd73xx_8ch_loopback;
5369 break; 3855 break;
5370 case 0x5: /* 10 Channel */ 3856 case 0x5: /* 10 Channel */
5371 spec->aloopback_ctl = stac92hd73xx_10ch_loopback; 3857 spec->aloopback_ctl = &stac92hd73xx_10ch_loopback;
5372 break; 3858 break;
5373 } 3859 }
5374 spec->multiout.dac_nids = spec->dac_nids;
5375 3860
5376 spec->aloopback_mask = 0x01; 3861 spec->aloopback_mask = 0x01;
5377 spec->aloopback_shift = 8; 3862 spec->aloopback_shift = 8;
5378 3863
5379 spec->digbeep_nid = 0x1c; 3864 spec->digbeep_nid = 0x1c;
5380 spec->mux_nids = stac92hd73xx_mux_nids;
5381 spec->adc_nids = stac92hd73xx_adc_nids;
5382 spec->dmic_nids = stac92hd73xx_dmic_nids;
5383 spec->dmux_nids = stac92hd73xx_dmux_nids;
5384 spec->smux_nids = stac92hd73xx_smux_nids;
5385
5386 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5387 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
5388 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
5389
5390 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5391 spec->capvols = stac92hd73xx_capvols;
5392 spec->capsws = stac92hd73xx_capsws;
5393
5394 switch (spec->board_config) {
5395 case STAC_DELL_EQ:
5396 spec->init = dell_eq_core_init;
5397 /* fallthru */
5398 case STAC_DELL_M6_AMIC:
5399 case STAC_DELL_M6_DMIC:
5400 case STAC_DELL_M6_BOTH:
5401 spec->num_smuxes = 0;
5402 spec->eapd_switch = 0;
5403 3865
5404 switch (spec->board_config) { 3866 /* GPIO0 High = Enable EAPD */
5405 case STAC_DELL_M6_AMIC: /* Analog Mics */ 3867 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5406 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170); 3868 spec->gpio_data = 0x01;
5407 spec->num_dmics = 0; 3869
5408 break; 3870 spec->eapd_switch = 1;
5409 case STAC_DELL_M6_DMIC: /* Digital Mics */
5410 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5411 spec->num_dmics = 1;
5412 break;
5413 case STAC_DELL_M6_BOTH: /* Both */
5414 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5415 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5416 spec->num_dmics = 1;
5417 break;
5418 }
5419 break;
5420 case STAC_ALIENWARE_M17X:
5421 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5422 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5423 spec->eapd_switch = 0;
5424 break;
5425 default:
5426 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5427 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5428 spec->eapd_switch = 1;
5429 break;
5430 }
5431 if (spec->board_config != STAC_92HD73XX_REF) {
5432 /* GPIO0 High = Enable EAPD */
5433 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5434 spec->gpio_data = 0x01;
5435 }
5436 3871
5437 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 3872 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5438 spec->pwr_nids = stac92hd73xx_pwr_nids; 3873 spec->pwr_nids = stac92hd73xx_pwr_nids;
5439 3874
5440 err = stac92xx_parse_auto_config(codec); 3875 spec->gen.own_eapd_ctl = 1;
3876 spec->gen.power_down_unused = 1;
5441 3877
5442 if (!err) { 3878 codec->patch_ops = stac_patch_ops;
5443 if (spec->board_config < 0) { 3879
5444 printk(KERN_WARNING "hda_codec: No auto-config is " 3880 snd_hda_pick_fixup(codec, stac92hd73xx_models, stac92hd73xx_fixup_tbl,
5445 "available, default to model=ref\n"); 3881 stac92hd73xx_fixups);
5446 spec->board_config = STAC_92HD73XX_REF; 3882 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5447 goto again;
5448 }
5449 err = -EINVAL;
5450 }
5451 3883
3884 if (!spec->volknob_init)
3885 snd_hda_add_verbs(codec, stac92hd73xx_core_init);
3886
3887 err = stac_parse_auto_config(codec);
5452 if (err < 0) { 3888 if (err < 0) {
5453 stac92xx_free(codec); 3889 stac_free(codec);
5454 return err; 3890 return err;
5455 } 3891 }
5456 3892
5457 if (spec->board_config == STAC_92HD73XX_NO_JD)
5458 spec->hp_detect = 0;
5459
5460 codec->patch_ops = stac92xx_patch_ops;
5461
5462 codec->proc_widget_hook = stac92hd7x_proc_hook; 3893 codec->proc_widget_hook = stac92hd7x_proc_hook;
5463 3894
5464 return 0; 3895 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5465}
5466
5467static int hp_bnb2011_with_dock(struct hda_codec *codec)
5468{
5469 if (codec->vendor_id != 0x111d7605 &&
5470 codec->vendor_id != 0x111d76d1)
5471 return 0;
5472 3896
5473 switch (codec->subsystem_id) {
5474 case 0x103c1618:
5475 case 0x103c1619:
5476 case 0x103c161a:
5477 case 0x103c161b:
5478 case 0x103c161c:
5479 case 0x103c161d:
5480 case 0x103c161e:
5481 case 0x103c161f:
5482
5483 case 0x103c162a:
5484 case 0x103c162b:
5485
5486 case 0x103c1630:
5487 case 0x103c1631:
5488
5489 case 0x103c1633:
5490 case 0x103c1634:
5491 case 0x103c1635:
5492
5493 case 0x103c3587:
5494 case 0x103c3588:
5495 case 0x103c3589:
5496 case 0x103c358a:
5497
5498 case 0x103c3667:
5499 case 0x103c3668:
5500 case 0x103c3669:
5501
5502 return 1;
5503 }
5504 return 0; 3897 return 0;
5505} 3898}
5506 3899
5507static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid) 3900static void stac_setup_gpio(struct hda_codec *codec)
5508{
5509 struct sigmatel_spec *spec = codec->spec;
5510 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5511 int i;
5512
5513 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5514 spec->auto_pin_cnt++;
5515
5516 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5517 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5518 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5519 if (nid == stac92hd83xxx_dmic_nids[i]) {
5520 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5521 spec->auto_dmic_cnt++;
5522 }
5523 }
5524 }
5525}
5526
5527static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5528{
5529 struct sigmatel_spec *spec = codec->spec;
5530
5531 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5532 spec->auto_adc_cnt++;
5533}
5534
5535static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5536{ 3901{
5537 int i, j;
5538 struct sigmatel_spec *spec = codec->spec; 3902 struct sigmatel_spec *spec = codec->spec;
5539 3903
5540 for (i = 0; i < spec->auto_adc_cnt; i++) { 3904 if (spec->gpio_led) {
5541 if (get_connection_index(codec, 3905 if (!spec->vref_mute_led_nid) {
5542 spec->auto_adc_nids[i], nid) >= 0) { 3906 spec->gpio_mask |= spec->gpio_led;
5543 /* mux and volume for adc_nids[i] */ 3907 spec->gpio_dir |= spec->gpio_led;
5544 if (!spec->auto_mux_nids[i]) { 3908 spec->gpio_data |= spec->gpio_led;
5545 spec->auto_mux_nids[i] = nid; 3909 } else {
5546 /* 92hd codecs capture volume is in mux */ 3910 codec->patch_ops.set_power_state =
5547 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid, 3911 stac_set_power_state;
5548 3, 0, HDA_OUTPUT);
5549 }
5550 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5551 if (get_connection_index(codec, nid,
5552 spec->auto_dmic_nids[j]) >= 0) {
5553 /* dmux for adc_nids[i] */
5554 if (!spec->auto_dmux_nids[i])
5555 spec->auto_dmux_nids[i] = nid;
5556 break;
5557 }
5558 }
5559 break;
5560 } 3912 }
5561 } 3913 }
5562}
5563
5564static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5565{
5566 hda_nid_t nid, end_nid;
5567 unsigned int wid_caps, wid_type;
5568 struct sigmatel_spec *spec = codec->spec;
5569
5570 end_nid = codec->start_nid + codec->num_nodes;
5571
5572 for (nid = codec->start_nid; nid < end_nid; nid++) {
5573 wid_caps = get_wcaps(codec, nid);
5574 wid_type = get_wcaps_type(wid_caps);
5575
5576 if (wid_type == AC_WID_PIN)
5577 stac92hd8x_add_pin(codec, nid);
5578
5579 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5580 stac92hd8x_add_adc(codec, nid);
5581 }
5582 3914
5583 for (nid = codec->start_nid; nid < end_nid; nid++) { 3915 if (spec->mic_mute_led_gpio) {
5584 wid_caps = get_wcaps(codec, nid); 3916 spec->gpio_mask |= spec->mic_mute_led_gpio;
5585 wid_type = get_wcaps_type(wid_caps); 3917 spec->gpio_dir |= spec->mic_mute_led_gpio;
3918 spec->mic_mute_led_on = true;
3919 spec->gpio_data |= spec->mic_mute_led_gpio;
5586 3920
5587 if (wid_type == AC_WID_AUD_SEL) 3921 spec->gen.cap_sync_hook = stac_capture_led_hook;
5588 stac92hd8x_add_mux(codec, nid);
5589 } 3922 }
5590
5591 spec->pin_nids = spec->auto_pin_nids;
5592 spec->num_pins = spec->auto_pin_cnt;
5593 spec->adc_nids = spec->auto_adc_nids;
5594 spec->num_adcs = spec->auto_adc_cnt;
5595 spec->capvols = spec->auto_capvols;
5596 spec->capsws = spec->auto_capvols;
5597 spec->num_caps = spec->auto_adc_cnt;
5598 spec->mux_nids = spec->auto_mux_nids;
5599 spec->num_muxes = spec->auto_adc_cnt;
5600 spec->dmux_nids = spec->auto_dmux_nids;
5601 spec->num_dmuxes = spec->auto_adc_cnt;
5602 spec->dmic_nids = spec->auto_dmic_nids;
5603 spec->num_dmics = spec->auto_dmic_cnt;
5604} 3923}
5605 3924
5606static int patch_stac92hd83xxx(struct hda_codec *codec) 3925static int patch_stac92hd83xxx(struct hda_codec *codec)
5607{ 3926{
5608 struct sigmatel_spec *spec; 3927 struct sigmatel_spec *spec;
5609 int default_polarity = -1; /* no default cfg */
5610 int err; 3928 int err;
5611 3929
5612 err = alloc_stac_spec(codec, 0, NULL); /* pins filled later */ 3930 err = alloc_stac_spec(codec);
5613 if (err < 0) 3931 if (err < 0)
5614 return err; 3932 return err;
5615 3933
5616 if (hp_bnb2011_with_dock(codec)) {
5617 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5618 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5619 }
5620
5621 codec->epss = 0; /* longer delay needed for D3 */ 3934 codec->epss = 0; /* longer delay needed for D3 */
5622 stac92hd8x_fill_auto_spec(codec);
5623 3935
5624 spec = codec->spec; 3936 spec = codec->spec;
5625 spec->linear_tone_beep = 0; 3937 spec->linear_tone_beep = 0;
5626 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs; 3938 spec->gen.own_eapd_ctl = 1;
3939 spec->gen.power_down_unused = 1;
3940 spec->gen.mixer_nid = 0x1b;
3941
5627 spec->digbeep_nid = 0x21; 3942 spec->digbeep_nid = 0x21;
5628 spec->pwr_nids = stac92hd83xxx_pwr_nids; 3943 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5629 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids); 3944 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5630 spec->multiout.dac_nids = spec->dac_nids; 3945 spec->default_polarity = -1; /* no default cfg */
5631 spec->init = stac92hd83xxx_core_init;
5632
5633 spec->board_config = snd_hda_check_board_config(codec,
5634 STAC_92HD83XXX_MODELS,
5635 stac92hd83xxx_models,
5636 stac92hd83xxx_cfg_tbl);
5637 /* check codec subsystem id if not found */
5638 if (spec->board_config < 0)
5639 spec->board_config =
5640 snd_hda_check_board_codec_sid_config(codec,
5641 STAC_92HD83XXX_MODELS, stac92hd83xxx_models,
5642 stac92hd83xxx_codec_id_cfg_tbl);
5643again:
5644 if (spec->board_config < 0)
5645 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5646 codec->chip_name);
5647 else
5648 stac92xx_set_config_regs(codec,
5649 stac92hd83xxx_brd_tbl[spec->board_config]);
5650
5651 codec->patch_ops = stac92xx_patch_ops;
5652
5653 switch (spec->board_config) {
5654 case STAC_HP_ZEPHYR:
5655 spec->init = stac92hd83xxx_hp_zephyr_init;
5656 break;
5657 case STAC_92HD83XXX_HP_LED:
5658 default_polarity = 0;
5659 break;
5660 case STAC_92HD83XXX_HP_INV_LED:
5661 default_polarity = 1;
5662 break;
5663 case STAC_92HD83XXX_HP_MIC_LED:
5664 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */
5665 break;
5666 case STAC_92HD83XXX_HEADSET_JACK:
5667 spec->headset_jack = 1;
5668 break;
5669 }
5670 3946
5671 if (find_mute_led_cfg(codec, default_polarity)) 3947 codec->patch_ops = stac_patch_ops;
5672 snd_printd("mute LED gpio %d polarity %d\n",
5673 spec->gpio_led,
5674 spec->gpio_led_polarity);
5675 3948
5676 if (spec->gpio_led) { 3949 snd_hda_add_verbs(codec, stac92hd83xxx_core_init);
5677 if (!spec->vref_mute_led_nid) {
5678 spec->gpio_mask |= spec->gpio_led;
5679 spec->gpio_dir |= spec->gpio_led;
5680 spec->gpio_data |= spec->gpio_led;
5681 } else {
5682 codec->patch_ops.set_power_state =
5683 stac92xx_set_power_state;
5684 }
5685 }
5686 3950
5687 if (spec->mic_mute_led_gpio) { 3951 snd_hda_pick_fixup(codec, stac92hd83xxx_models, stac92hd83xxx_fixup_tbl,
5688 spec->gpio_mask |= spec->mic_mute_led_gpio; 3952 stac92hd83xxx_fixups);
5689 spec->gpio_dir |= spec->mic_mute_led_gpio; 3953 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5690 spec->mic_mute_led_on = true;
5691 spec->gpio_data |= spec->mic_mute_led_gpio;
5692 }
5693 3954
5694 err = stac92xx_parse_auto_config(codec); 3955 stac_setup_gpio(codec);
5695 if (!err) {
5696 if (spec->board_config < 0) {
5697 printk(KERN_WARNING "hda_codec: No auto-config is "
5698 "available, default to model=ref\n");
5699 spec->board_config = STAC_92HD83XXX_REF;
5700 goto again;
5701 }
5702 err = -EINVAL;
5703 }
5704 3956
3957 err = stac_parse_auto_config(codec);
5705 if (err < 0) { 3958 if (err < 0) {
5706 stac92xx_free(codec); 3959 stac_free(codec);
5707 return err; 3960 return err;
5708 } 3961 }
5709 3962
5710 codec->proc_widget_hook = stac92hd_proc_hook; 3963 codec->proc_widget_hook = stac92hd_proc_hook;
5711 3964
3965 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
3966
5712 return 0; 3967 return 0;
5713} 3968}
5714 3969
5715static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec, 3970static const hda_nid_t stac92hd95_pwr_nids[] = {
5716 hda_nid_t dig0pin) 3971 0x0a, 0x0b, 0x0c, 0x0d
5717{ 3972};
5718 struct sigmatel_spec *spec = codec->spec;
5719 int idx;
5720
5721 for (idx = 0; idx < spec->num_pins; idx++)
5722 if (spec->pin_nids[idx] == dig0pin)
5723 break;
5724 if ((idx + 2) >= spec->num_pins)
5725 return 0;
5726 3973
5727 /* dig1pin case */ 3974static int patch_stac92hd95(struct hda_codec *codec)
5728 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE) 3975{
5729 return 2; 3976 struct sigmatel_spec *spec;
3977 int err;
5730 3978
5731 /* dig0pin + dig2pin case */ 3979 err = alloc_stac_spec(codec);
5732 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE) 3980 if (err < 0)
5733 return 2; 3981 return err;
5734 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5735 return 1;
5736 else
5737 return 0;
5738}
5739 3982
5740/* HP dv7 bass switch - GPIO5 */ 3983 codec->epss = 0; /* longer delay needed for D3 */
5741#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5742static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5743 struct snd_ctl_elem_value *ucontrol)
5744{
5745 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5746 struct sigmatel_spec *spec = codec->spec;
5747 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5748 return 0;
5749}
5750 3984
5751static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol, 3985 spec = codec->spec;
5752 struct snd_ctl_elem_value *ucontrol) 3986 spec->linear_tone_beep = 0;
5753{ 3987 spec->gen.own_eapd_ctl = 1;
5754 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3988 spec->gen.power_down_unused = 1;
5755 struct sigmatel_spec *spec = codec->spec;
5756 unsigned int gpio_data;
5757 3989
5758 gpio_data = (spec->gpio_data & ~0x20) | 3990 spec->digbeep_nid = 0x19;
5759 (ucontrol->value.integer.value[0] ? 0x20 : 0); 3991 spec->pwr_nids = stac92hd95_pwr_nids;
5760 if (gpio_data == spec->gpio_data) 3992 spec->num_pwrs = ARRAY_SIZE(stac92hd95_pwr_nids);
5761 return 0; 3993 spec->default_polarity = -1; /* no default cfg */
5762 spec->gpio_data = gpio_data;
5763 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5764 return 1;
5765}
5766 3994
5767static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = { 3995 codec->patch_ops = stac_patch_ops;
5768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5769 .info = stac_hp_bass_gpio_info,
5770 .get = stac_hp_bass_gpio_get,
5771 .put = stac_hp_bass_gpio_put,
5772};
5773 3996
5774static int stac_add_hp_bass_switch(struct hda_codec *codec) 3997 err = stac_parse_auto_config(codec);
5775{ 3998 if (err < 0) {
5776 struct sigmatel_spec *spec = codec->spec; 3999 stac_free(codec);
4000 return err;
4001 }
5777 4002
5778 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl, 4003 codec->proc_widget_hook = stac92hd_proc_hook;
5779 "Bass Speaker Playback Switch", 0))
5780 return -ENOMEM;
5781 4004
5782 spec->gpio_mask |= 0x20;
5783 spec->gpio_dir |= 0x20;
5784 spec->gpio_data |= 0x20;
5785 return 0; 4005 return 0;
5786} 4006}
5787 4007
@@ -5789,82 +4009,32 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
5789{ 4009{
5790 struct sigmatel_spec *spec; 4010 struct sigmatel_spec *spec;
5791 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init; 4011 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5792 unsigned int pin_cfg;
5793 int err; 4012 int err;
5794 4013
5795 err = alloc_stac_spec(codec, STAC92HD71BXX_NUM_PINS, 4014 err = alloc_stac_spec(codec);
5796 stac92hd71bxx_pin_nids_4port);
5797 if (err < 0) 4015 if (err < 0)
5798 return err; 4016 return err;
5799 4017
5800 spec = codec->spec; 4018 spec = codec->spec;
5801 spec->linear_tone_beep = 0; 4019 spec->linear_tone_beep = 0;
5802 codec->patch_ops = stac92xx_patch_ops; 4020 spec->gen.own_eapd_ctl = 1;
5803 switch (codec->vendor_id) { 4021 spec->gen.power_down_unused = 1;
5804 case 0x111d76b6: 4022 spec->gen.mixer_nid = 0x17;
5805 case 0x111d76b7: 4023 spec->have_spdif_mux = 1;
5806 break;
5807 case 0x111d7603:
5808 case 0x111d7608:
5809 /* On 92HD75Bx 0x27 isn't a pin nid */
5810 spec->num_pins--;
5811 /* fallthrough */
5812 default:
5813 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5814 }
5815 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5816 spec->board_config = snd_hda_check_board_config(codec,
5817 STAC_92HD71BXX_MODELS,
5818 stac92hd71bxx_models,
5819 stac92hd71bxx_cfg_tbl);
5820again:
5821 if (spec->board_config < 0)
5822 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5823 codec->chip_name);
5824 else
5825 stac92xx_set_config_regs(codec,
5826 stac92hd71bxx_brd_tbl[spec->board_config]);
5827 4024
5828 if (spec->board_config != STAC_92HD71BXX_REF) { 4025 codec->patch_ops = stac_patch_ops;
5829 /* GPIO0 = EAPD */
5830 spec->gpio_mask = 0x01;
5831 spec->gpio_dir = 0x01;
5832 spec->gpio_data = 0x01;
5833 }
5834
5835 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5836 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5837 4026
5838 spec->num_caps = STAC92HD71BXX_NUM_CAPS; 4027 /* GPIO0 = EAPD */
5839 spec->capvols = stac92hd71bxx_capvols; 4028 spec->gpio_mask = 0x01;
5840 spec->capsws = stac92hd71bxx_capsws; 4029 spec->gpio_dir = 0x01;
4030 spec->gpio_data = 0x01;
5841 4031
5842 switch (codec->vendor_id) { 4032 switch (codec->vendor_id) {
5843 case 0x111d76b6: /* 4 Port without Analog Mixer */ 4033 case 0x111d76b6: /* 4 Port without Analog Mixer */
5844 case 0x111d76b7: 4034 case 0x111d76b7:
5845 unmute_init++; 4035 unmute_init++;
5846 /* fallthru */
5847 case 0x111d76b4: /* 6 Port without Analog Mixer */
5848 case 0x111d76b5:
5849 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5850 spec->num_dmics = stac92xx_connected_ports(codec,
5851 stac92hd71bxx_dmic_nids,
5852 STAC92HD71BXX_NUM_DMICS);
5853 break; 4036 break;
5854 case 0x111d7608: /* 5 Port with Analog Mixer */ 4037 case 0x111d7608: /* 5 Port with Analog Mixer */
5855 switch (spec->board_config) {
5856 case STAC_HP_M4:
5857 /* Enable VREF power saving on GPIO1 detect */
5858 err = stac_add_event(codec, codec->afg,
5859 STAC_VREF_EVENT, 0x02);
5860 if (err < 0)
5861 return err;
5862 snd_hda_codec_write_cache(codec, codec->afg, 0,
5863 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5864 snd_hda_jack_detect_enable(codec, codec->afg, 0);
5865 spec->gpio_mask |= 0x02;
5866 break;
5867 }
5868 if ((codec->revision_id & 0xf) == 0 || 4038 if ((codec->revision_id & 0xf) == 0 ||
5869 (codec->revision_id & 0xf) == 1) 4039 (codec->revision_id & 0xf) == 1)
5870 spec->stream_delay = 40; /* 40 milliseconds */ 4040 spec->stream_delay = 40; /* 40 milliseconds */
@@ -5873,158 +4043,45 @@ again:
5873 unmute_init++; 4043 unmute_init++;
5874 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0); 4044 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5875 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3); 4045 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5876 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
5877 spec->num_dmics = stac92xx_connected_ports(codec,
5878 stac92hd71bxx_dmic_5port_nids,
5879 STAC92HD71BXX_NUM_DMICS - 1);
5880 break; 4046 break;
5881 case 0x111d7603: /* 6 Port with Analog Mixer */ 4047 case 0x111d7603: /* 6 Port with Analog Mixer */
5882 if ((codec->revision_id & 0xf) == 1) 4048 if ((codec->revision_id & 0xf) == 1)
5883 spec->stream_delay = 40; /* 40 milliseconds */ 4049 spec->stream_delay = 40; /* 40 milliseconds */
5884 4050
5885 /* fallthru */
5886 default:
5887 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5888 spec->num_dmics = stac92xx_connected_ports(codec,
5889 stac92hd71bxx_dmic_nids,
5890 STAC92HD71BXX_NUM_DMICS);
5891 break; 4051 break;
5892 } 4052 }
5893 4053
5894 if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB) 4054 if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB)
5895 spec->init = stac92hd71bxx_core_init; 4055 snd_hda_add_verbs(codec, stac92hd71bxx_core_init);
5896 4056
5897 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP) 4057 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5898 snd_hda_sequence_write_cache(codec, unmute_init); 4058 snd_hda_sequence_write_cache(codec, unmute_init);
5899 4059
5900 spec->aloopback_ctl = stac92hd71bxx_loopback; 4060 spec->aloopback_ctl = &stac92hd71bxx_loopback;
5901 spec->aloopback_mask = 0x50; 4061 spec->aloopback_mask = 0x50;
5902 spec->aloopback_shift = 0; 4062 spec->aloopback_shift = 0;
5903 4063
5904 spec->powerdown_adcs = 1; 4064 spec->powerdown_adcs = 1;
5905 spec->digbeep_nid = 0x26; 4065 spec->digbeep_nid = 0x26;
5906 spec->mux_nids = stac92hd71bxx_mux_nids; 4066 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5907 spec->adc_nids = stac92hd71bxx_adc_nids;
5908 spec->smux_nids = stac92hd71bxx_smux_nids;
5909 spec->pwr_nids = stac92hd71bxx_pwr_nids; 4067 spec->pwr_nids = stac92hd71bxx_pwr_nids;
5910 4068
5911 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids); 4069 snd_hda_pick_fixup(codec, stac92hd71bxx_models, stac92hd71bxx_fixup_tbl,
5912 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids); 4070 stac92hd71bxx_fixups);
5913 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids); 4071 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5914 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5915
5916 snd_printdd("Found board config: %d\n", spec->board_config);
5917
5918 switch (spec->board_config) {
5919 case STAC_HP_M4:
5920 /* enable internal microphone */
5921 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5922 stac92xx_auto_set_pinctl(codec, 0x0e,
5923 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5924 /* fallthru */
5925 case STAC_DELL_M4_2:
5926 spec->num_dmics = 0;
5927 spec->num_smuxes = 0;
5928 spec->num_dmuxes = 0;
5929 break;
5930 case STAC_DELL_M4_1:
5931 case STAC_DELL_M4_3:
5932 spec->num_dmics = 1;
5933 spec->num_smuxes = 0;
5934 spec->num_dmuxes = 1;
5935 break;
5936 case STAC_HP_DV4_1222NR:
5937 spec->num_dmics = 1;
5938 /* I don't know if it needs 1 or 2 smuxes - will wait for
5939 * bug reports to fix if needed
5940 */
5941 spec->num_smuxes = 1;
5942 spec->num_dmuxes = 1;
5943 /* fallthrough */
5944 case STAC_HP_DV4:
5945 spec->gpio_led = 0x01;
5946 /* fallthrough */
5947 case STAC_HP_DV5:
5948 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5949 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5950 /* HP dv6 gives the headphone pin as a line-out. Thus we
5951 * need to set hp_detect flag here to force to enable HP
5952 * detection.
5953 */
5954 spec->hp_detect = 1;
5955 break;
5956 case STAC_HP_HDX:
5957 spec->num_dmics = 1;
5958 spec->num_dmuxes = 1;
5959 spec->num_smuxes = 1;
5960 spec->gpio_led = 0x08;
5961 break;
5962 }
5963 4072
5964 if (hp_blike_system(codec->subsystem_id)) { 4073 stac_setup_gpio(codec);
5965 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5966 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5967 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5968 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5969 /* It was changed in the BIOS to just satisfy MS DTM.
5970 * Lets turn it back into slaved HP
5971 */
5972 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5973 | (AC_JACK_HP_OUT <<
5974 AC_DEFCFG_DEVICE_SHIFT);
5975 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5976 | AC_DEFCFG_SEQUENCE)))
5977 | 0x1f;
5978 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5979 }
5980 }
5981
5982 if (find_mute_led_cfg(codec, 1))
5983 snd_printd("mute LED gpio %d polarity %d\n",
5984 spec->gpio_led,
5985 spec->gpio_led_polarity);
5986
5987 if (spec->gpio_led) {
5988 if (!spec->vref_mute_led_nid) {
5989 spec->gpio_mask |= spec->gpio_led;
5990 spec->gpio_dir |= spec->gpio_led;
5991 spec->gpio_data |= spec->gpio_led;
5992 } else {
5993 codec->patch_ops.set_power_state =
5994 stac92xx_set_power_state;
5995 }
5996 }
5997
5998 spec->multiout.dac_nids = spec->dac_nids;
5999
6000 err = stac92xx_parse_auto_config(codec);
6001 if (!err) {
6002 if (spec->board_config < 0) {
6003 printk(KERN_WARNING "hda_codec: No auto-config is "
6004 "available, default to model=ref\n");
6005 spec->board_config = STAC_92HD71BXX_REF;
6006 goto again;
6007 }
6008 err = -EINVAL;
6009 }
6010 4074
4075 err = stac_parse_auto_config(codec);
6011 if (err < 0) { 4076 if (err < 0) {
6012 stac92xx_free(codec); 4077 stac_free(codec);
6013 return err; 4078 return err;
6014 } 4079 }
6015 4080
6016 /* enable bass on HP dv7 */
6017 if (spec->board_config == STAC_HP_DV4 ||
6018 spec->board_config == STAC_HP_DV5) {
6019 unsigned int cap;
6020 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6021 cap &= AC_GPIO_IO_COUNT;
6022 if (cap >= 6)
6023 stac_add_hp_bass_switch(codec);
6024 }
6025
6026 codec->proc_widget_hook = stac92hd7x_proc_hook; 4081 codec->proc_widget_hook = stac92hd7x_proc_hook;
6027 4082
4083 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4084
6028 return 0; 4085 return 0;
6029} 4086}
6030 4087
@@ -6033,93 +4090,17 @@ static int patch_stac922x(struct hda_codec *codec)
6033 struct sigmatel_spec *spec; 4090 struct sigmatel_spec *spec;
6034 int err; 4091 int err;
6035 4092
6036 err = alloc_stac_spec(codec, ARRAY_SIZE(stac922x_pin_nids), 4093 err = alloc_stac_spec(codec);
6037 stac922x_pin_nids);
6038 if (err < 0) 4094 if (err < 0)
6039 return err; 4095 return err;
6040 4096
6041 spec = codec->spec; 4097 spec = codec->spec;
6042 spec->linear_tone_beep = 1; 4098 spec->linear_tone_beep = 1;
6043 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS, 4099 spec->gen.own_eapd_ctl = 1;
6044 stac922x_models,
6045 stac922x_cfg_tbl);
6046 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
6047 spec->gpio_mask = spec->gpio_dir = 0x03;
6048 spec->gpio_data = 0x03;
6049 /* Intel Macs have all same PCI SSID, so we need to check
6050 * codec SSID to distinguish the exact models
6051 */
6052 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
6053 switch (codec->subsystem_id) {
6054
6055 case 0x106b0800:
6056 spec->board_config = STAC_INTEL_MAC_V1;
6057 break;
6058 case 0x106b0600:
6059 case 0x106b0700:
6060 spec->board_config = STAC_INTEL_MAC_V2;
6061 break;
6062 case 0x106b0e00:
6063 case 0x106b0f00:
6064 case 0x106b1600:
6065 case 0x106b1700:
6066 case 0x106b0200:
6067 case 0x106b1e00:
6068 spec->board_config = STAC_INTEL_MAC_V3;
6069 break;
6070 case 0x106b1a00:
6071 case 0x00000100:
6072 spec->board_config = STAC_INTEL_MAC_V4;
6073 break;
6074 case 0x106b0a00:
6075 case 0x106b2200:
6076 spec->board_config = STAC_INTEL_MAC_V5;
6077 break;
6078 default:
6079 spec->board_config = STAC_INTEL_MAC_V3;
6080 break;
6081 }
6082 }
6083
6084 again:
6085 if (spec->board_config < 0)
6086 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6087 codec->chip_name);
6088 else
6089 stac92xx_set_config_regs(codec,
6090 stac922x_brd_tbl[spec->board_config]);
6091
6092 spec->adc_nids = stac922x_adc_nids;
6093 spec->mux_nids = stac922x_mux_nids;
6094 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
6095 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
6096 spec->num_dmics = 0;
6097 spec->num_pwrs = 0;
6098 4100
6099 spec->init = stac922x_core_init; 4101 codec->patch_ops = stac_patch_ops;
6100
6101 spec->num_caps = STAC922X_NUM_CAPS;
6102 spec->capvols = stac922x_capvols;
6103 spec->capsws = stac922x_capsws;
6104
6105 spec->multiout.dac_nids = spec->dac_nids;
6106
6107 err = stac92xx_parse_auto_config(codec);
6108 if (!err) {
6109 if (spec->board_config < 0) {
6110 printk(KERN_WARNING "hda_codec: No auto-config is "
6111 "available, default to model=ref\n");
6112 spec->board_config = STAC_D945_REF;
6113 goto again;
6114 }
6115 err = -EINVAL;
6116 }
6117 if (err < 0) {
6118 stac92xx_free(codec);
6119 return err;
6120 }
6121 4102
6122 codec->patch_ops = stac92xx_patch_ops; 4103 snd_hda_add_verbs(codec, stac922x_core_init);
6123 4104
6124 /* Fix Mux capture level; max to 2 */ 4105 /* Fix Mux capture level; max to 2 */
6125 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT, 4106 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
@@ -6128,122 +4109,67 @@ static int patch_stac922x(struct hda_codec *codec)
6128 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) | 4109 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6129 (0 << AC_AMPCAP_MUTE_SHIFT)); 4110 (0 << AC_AMPCAP_MUTE_SHIFT));
6130 4111
4112 snd_hda_pick_fixup(codec, stac922x_models, stac922x_fixup_tbl,
4113 stac922x_fixups);
4114 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4115
4116 err = stac_parse_auto_config(codec);
4117 if (err < 0) {
4118 stac_free(codec);
4119 return err;
4120 }
4121
4122 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4123
6131 return 0; 4124 return 0;
6132} 4125}
6133 4126
4127static const char * const stac927x_spdif_labels[] = {
4128 "Digital Playback", "ADAT", "Analog Mux 1",
4129 "Analog Mux 2", "Analog Mux 3", NULL
4130};
4131
6134static int patch_stac927x(struct hda_codec *codec) 4132static int patch_stac927x(struct hda_codec *codec)
6135{ 4133{
6136 struct sigmatel_spec *spec; 4134 struct sigmatel_spec *spec;
6137 int err; 4135 int err;
6138 4136
6139 err = alloc_stac_spec(codec, ARRAY_SIZE(stac927x_pin_nids), 4137 err = alloc_stac_spec(codec);
6140 stac927x_pin_nids);
6141 if (err < 0) 4138 if (err < 0)
6142 return err; 4139 return err;
6143 4140
6144 spec = codec->spec; 4141 spec = codec->spec;
6145 spec->linear_tone_beep = 1; 4142 spec->linear_tone_beep = 1;
6146 codec->slave_dig_outs = stac927x_slave_dig_outs; 4143 spec->gen.own_eapd_ctl = 1;
6147 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS, 4144 spec->have_spdif_mux = 1;
6148 stac927x_models,
6149 stac927x_cfg_tbl);
6150 again:
6151 if (spec->board_config < 0)
6152 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6153 codec->chip_name);
6154 else
6155 stac92xx_set_config_regs(codec,
6156 stac927x_brd_tbl[spec->board_config]);
6157
6158 spec->digbeep_nid = 0x23;
6159 spec->adc_nids = stac927x_adc_nids;
6160 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6161 spec->mux_nids = stac927x_mux_nids;
6162 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
6163 spec->smux_nids = stac927x_smux_nids;
6164 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
6165 spec->spdif_labels = stac927x_spdif_labels; 4145 spec->spdif_labels = stac927x_spdif_labels;
6166 spec->dac_list = stac927x_dac_nids;
6167 spec->multiout.dac_nids = spec->dac_nids;
6168
6169 if (spec->board_config != STAC_D965_REF) {
6170 /* GPIO0 High = Enable EAPD */
6171 spec->eapd_mask = spec->gpio_mask = 0x01;
6172 spec->gpio_dir = spec->gpio_data = 0x01;
6173 }
6174 4146
6175 switch (spec->board_config) { 4147 spec->digbeep_nid = 0x23;
6176 case STAC_D965_3ST:
6177 case STAC_D965_5ST:
6178 /* GPIO0 High = Enable EAPD */
6179 spec->num_dmics = 0;
6180 spec->init = d965_core_init;
6181 break;
6182 case STAC_DELL_BIOS:
6183 switch (codec->subsystem_id) {
6184 case 0x10280209:
6185 case 0x1028022e:
6186 /* correct the device field to SPDIF out */
6187 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
6188 break;
6189 }
6190 /* configure the analog microphone on some laptops */
6191 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
6192 /* correct the front output jack as a hp out */
6193 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
6194 /* correct the front input jack as a mic */
6195 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
6196 /* fallthru */
6197 case STAC_DELL_3ST:
6198 if (codec->subsystem_id != 0x1028022f) {
6199 /* GPIO2 High = Enable EAPD */
6200 spec->eapd_mask = spec->gpio_mask = 0x04;
6201 spec->gpio_dir = spec->gpio_data = 0x04;
6202 }
6203 spec->dmic_nids = stac927x_dmic_nids;
6204 spec->num_dmics = STAC927X_NUM_DMICS;
6205
6206 spec->init = dell_3st_core_init;
6207 spec->dmux_nids = stac927x_dmux_nids;
6208 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
6209 break;
6210 case STAC_927X_VOLKNOB:
6211 spec->num_dmics = 0;
6212 spec->init = stac927x_volknob_core_init;
6213 break;
6214 default:
6215 spec->num_dmics = 0;
6216 spec->init = stac927x_core_init;
6217 break;
6218 }
6219 4148
6220 spec->num_caps = STAC927X_NUM_CAPS; 4149 /* GPIO0 High = Enable EAPD */
6221 spec->capvols = stac927x_capvols; 4150 spec->eapd_mask = spec->gpio_mask = 0x01;
6222 spec->capsws = stac927x_capsws; 4151 spec->gpio_dir = spec->gpio_data = 0x01;
6223 4152
6224 spec->num_pwrs = 0; 4153 spec->aloopback_ctl = &stac927x_loopback;
6225 spec->aloopback_ctl = stac927x_loopback;
6226 spec->aloopback_mask = 0x40; 4154 spec->aloopback_mask = 0x40;
6227 spec->aloopback_shift = 0; 4155 spec->aloopback_shift = 0;
6228 spec->eapd_switch = 1; 4156 spec->eapd_switch = 1;
6229 4157
6230 err = stac92xx_parse_auto_config(codec); 4158 codec->patch_ops = stac_patch_ops;
6231 if (!err) { 4159
6232 if (spec->board_config < 0) { 4160 snd_hda_pick_fixup(codec, stac927x_models, stac927x_fixup_tbl,
6233 printk(KERN_WARNING "hda_codec: No auto-config is " 4161 stac927x_fixups);
6234 "available, default to model=ref\n"); 4162 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6235 spec->board_config = STAC_D965_REF; 4163
6236 goto again; 4164 if (!spec->volknob_init)
6237 } 4165 snd_hda_add_verbs(codec, stac927x_core_init);
6238 err = -EINVAL; 4166
6239 } 4167 err = stac_parse_auto_config(codec);
6240 if (err < 0) { 4168 if (err < 0) {
6241 stac92xx_free(codec); 4169 stac_free(codec);
6242 return err; 4170 return err;
6243 } 4171 }
6244 4172
6245 codec->patch_ops = stac92xx_patch_ops;
6246
6247 codec->proc_widget_hook = stac927x_proc_hook; 4173 codec->proc_widget_hook = stac927x_proc_hook;
6248 4174
6249 /* 4175 /*
@@ -6258,9 +4184,7 @@ static int patch_stac927x(struct hda_codec *codec)
6258 */ 4184 */
6259 codec->bus->needs_damn_long_delay = 1; 4185 codec->bus->needs_damn_long_delay = 1;
6260 4186
6261 /* no jack detecion for ref-no-jd model */ 4187 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6262 if (spec->board_config == STAC_D965_REF_NO_JD)
6263 spec->hp_detect = 0;
6264 4188
6265 return 0; 4189 return 0;
6266} 4190}
@@ -6270,103 +4194,46 @@ static int patch_stac9205(struct hda_codec *codec)
6270 struct sigmatel_spec *spec; 4194 struct sigmatel_spec *spec;
6271 int err; 4195 int err;
6272 4196
6273 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9205_pin_nids), 4197 err = alloc_stac_spec(codec);
6274 stac9205_pin_nids);
6275 if (err < 0) 4198 if (err < 0)
6276 return err; 4199 return err;
6277 4200
6278 spec = codec->spec; 4201 spec = codec->spec;
6279 spec->linear_tone_beep = 1; 4202 spec->linear_tone_beep = 1;
6280 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS, 4203 spec->gen.own_eapd_ctl = 1;
6281 stac9205_models, 4204 spec->have_spdif_mux = 1;
6282 stac9205_cfg_tbl);
6283 again:
6284 if (spec->board_config < 0)
6285 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6286 codec->chip_name);
6287 else
6288 stac92xx_set_config_regs(codec,
6289 stac9205_brd_tbl[spec->board_config]);
6290 4205
6291 spec->digbeep_nid = 0x23; 4206 spec->digbeep_nid = 0x23;
6292 spec->adc_nids = stac9205_adc_nids; 4207
6293 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids); 4208 snd_hda_add_verbs(codec, stac9205_core_init);
6294 spec->mux_nids = stac9205_mux_nids; 4209 spec->aloopback_ctl = &stac9205_loopback;
6295 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
6296 spec->smux_nids = stac9205_smux_nids;
6297 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
6298 spec->dmic_nids = stac9205_dmic_nids;
6299 spec->num_dmics = STAC9205_NUM_DMICS;
6300 spec->dmux_nids = stac9205_dmux_nids;
6301 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
6302 spec->num_pwrs = 0;
6303
6304 spec->init = stac9205_core_init;
6305 spec->aloopback_ctl = stac9205_loopback;
6306
6307 spec->num_caps = STAC9205_NUM_CAPS;
6308 spec->capvols = stac9205_capvols;
6309 spec->capsws = stac9205_capsws;
6310 4210
6311 spec->aloopback_mask = 0x40; 4211 spec->aloopback_mask = 0x40;
6312 spec->aloopback_shift = 0; 4212 spec->aloopback_shift = 0;
6313 /* Turn on/off EAPD per HP plugging */
6314 if (spec->board_config != STAC_9205_EAPD)
6315 spec->eapd_switch = 1;
6316 spec->multiout.dac_nids = spec->dac_nids;
6317 4213
6318 switch (spec->board_config){ 4214 /* GPIO0 High = EAPD */
6319 case STAC_9205_DELL_M43: 4215 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6320 /* Enable SPDIF in/out */ 4216 spec->gpio_data = 0x01;
6321 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6322 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6323 4217
6324 /* Enable unsol response for GPIO4/Dock HP connection */ 4218 /* Turn on/off EAPD per HP plugging */
6325 err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01); 4219 spec->eapd_switch = 1;
6326 if (err < 0)
6327 return err;
6328 snd_hda_codec_write_cache(codec, codec->afg, 0,
6329 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6330 snd_hda_jack_detect_enable(codec, codec->afg, 0);
6331 4220
6332 spec->gpio_dir = 0x0b; 4221 codec->patch_ops = stac_patch_ops;
6333 spec->eapd_mask = 0x01;
6334 spec->gpio_mask = 0x1b;
6335 spec->gpio_mute = 0x10;
6336 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
6337 * GPIO3 Low = DRM
6338 */
6339 spec->gpio_data = 0x01;
6340 break;
6341 case STAC_9205_REF:
6342 /* SPDIF-In enabled */
6343 break;
6344 default:
6345 /* GPIO0 High = EAPD */
6346 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6347 spec->gpio_data = 0x01;
6348 break;
6349 }
6350 4222
6351 err = stac92xx_parse_auto_config(codec); 4223 snd_hda_pick_fixup(codec, stac9205_models, stac9205_fixup_tbl,
6352 if (!err) { 4224 stac9205_fixups);
6353 if (spec->board_config < 0) { 4225 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6354 printk(KERN_WARNING "hda_codec: No auto-config is " 4226
6355 "available, default to model=ref\n"); 4227 err = stac_parse_auto_config(codec);
6356 spec->board_config = STAC_9205_REF;
6357 goto again;
6358 }
6359 err = -EINVAL;
6360 }
6361 if (err < 0) { 4228 if (err < 0) {
6362 stac92xx_free(codec); 4229 stac_free(codec);
6363 return err; 4230 return err;
6364 } 4231 }
6365 4232
6366 codec->patch_ops = stac92xx_patch_ops;
6367
6368 codec->proc_widget_hook = stac9205_proc_hook; 4233 codec->proc_widget_hook = stac9205_proc_hook;
6369 4234
4235 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4236
6370 return 0; 4237 return 0;
6371} 4238}
6372 4239
@@ -6380,40 +4247,32 @@ static const struct hda_verb stac9872_core_init[] = {
6380 {} 4247 {}
6381}; 4248};
6382 4249
6383static const hda_nid_t stac9872_pin_nids[] = { 4250static const struct hda_pintbl stac9872_vaio_pin_configs[] = {
6384 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 4251 { 0x0a, 0x03211020 },
6385 0x11, 0x13, 0x14, 4252 { 0x0b, 0x411111f0 },
6386}; 4253 { 0x0c, 0x411111f0 },
6387 4254 { 0x0d, 0x03a15030 },
6388static const hda_nid_t stac9872_adc_nids[] = { 4255 { 0x0e, 0x411111f0 },
6389 0x8 /*,0x6*/ 4256 { 0x0f, 0x90170110 },
6390}; 4257 { 0x11, 0x411111f0 },
6391 4258 { 0x13, 0x411111f0 },
6392static const hda_nid_t stac9872_mux_nids[] = { 4259 { 0x14, 0x90a7013e },
6393 0x15 4260 {}
6394};
6395
6396static const unsigned long stac9872_capvols[] = {
6397 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6398};
6399#define stac9872_capsws stac9872_capvols
6400
6401static const unsigned int stac9872_vaio_pin_configs[9] = {
6402 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6403 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6404 0x90a7013e
6405}; 4261};
6406 4262
6407static const char * const stac9872_models[STAC_9872_MODELS] = { 4263static const struct hda_model_fixup stac9872_models[] = {
6408 [STAC_9872_AUTO] = "auto", 4264 { .id = STAC_9872_VAIO, .name = "vaio" },
6409 [STAC_9872_VAIO] = "vaio", 4265 {}
6410}; 4266};
6411 4267
6412static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = { 4268static const struct hda_fixup stac9872_fixups[] = {
6413 [STAC_9872_VAIO] = stac9872_vaio_pin_configs, 4269 [STAC_9872_VAIO] = {
4270 .type = HDA_FIXUP_PINS,
4271 .v.pins = stac9872_vaio_pin_configs,
4272 },
6414}; 4273};
6415 4274
6416static const struct snd_pci_quirk stac9872_cfg_tbl[] = { 4275static const struct snd_pci_quirk stac9872_fixup_tbl[] = {
6417 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0, 4276 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6418 "Sony VAIO F/S", STAC_9872_VAIO), 4277 "Sony VAIO F/S", STAC_9872_VAIO),
6419 {} /* terminator */ 4278 {} /* terminator */
@@ -6424,41 +4283,30 @@ static int patch_stac9872(struct hda_codec *codec)
6424 struct sigmatel_spec *spec; 4283 struct sigmatel_spec *spec;
6425 int err; 4284 int err;
6426 4285
6427 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9872_pin_nids), 4286 err = alloc_stac_spec(codec);
6428 stac9872_pin_nids);
6429 if (err < 0) 4287 if (err < 0)
6430 return err; 4288 return err;
6431 4289
6432 spec = codec->spec; 4290 spec = codec->spec;
6433 spec->linear_tone_beep = 1; 4291 spec->linear_tone_beep = 1;
4292 spec->gen.own_eapd_ctl = 1;
6434 4293
6435 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS, 4294 codec->patch_ops = stac_patch_ops;
6436 stac9872_models, 4295
6437 stac9872_cfg_tbl); 4296 snd_hda_add_verbs(codec, stac9872_core_init);
6438 if (spec->board_config < 0) 4297
6439 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 4298 snd_hda_pick_fixup(codec, stac9872_models, stac9872_fixup_tbl,
6440 codec->chip_name); 4299 stac9872_fixups);
6441 else 4300 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
6442 stac92xx_set_config_regs(codec, 4301
6443 stac9872_brd_tbl[spec->board_config]); 4302 err = stac_parse_auto_config(codec);
6444
6445 spec->multiout.dac_nids = spec->dac_nids;
6446 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6447 spec->adc_nids = stac9872_adc_nids;
6448 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6449 spec->mux_nids = stac9872_mux_nids;
6450 spec->init = stac9872_core_init;
6451 spec->num_caps = 1;
6452 spec->capvols = stac9872_capvols;
6453 spec->capsws = stac9872_capsws;
6454
6455 err = stac92xx_parse_auto_config(codec);
6456 if (err < 0) { 4303 if (err < 0) {
6457 stac92xx_free(codec); 4304 stac_free(codec);
6458 return -EINVAL; 4305 return -EINVAL;
6459 } 4306 }
6460 spec->input_mux = &spec->private_imux; 4307
6461 codec->patch_ops = stac92xx_patch_ops; 4308 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
4309
6462 return 0; 4310 return 0;
6463} 4311}
6464 4312
@@ -6529,6 +4377,7 @@ static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6529 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx }, 4377 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6530 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx }, 4378 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
6531 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx }, 4379 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
4380 { .id = 0x111d7695, .name = "92HD95", .patch = patch_stac92hd95 },
6532 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx }, 4381 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6533 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx }, 4382 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6534 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx }, 4383 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 09bb64996d72..c35338a8771d 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -56,6 +56,7 @@
56#include "hda_local.h" 56#include "hda_local.h"
57#include "hda_auto_parser.h" 57#include "hda_auto_parser.h"
58#include "hda_jack.h" 58#include "hda_jack.h"
59#include "hda_generic.h"
59 60
60/* Pin Widget NID */ 61/* Pin Widget NID */
61#define VT1708_HP_PIN_NID 0x20 62#define VT1708_HP_PIN_NID 0x20
@@ -86,39 +87,6 @@ enum VIA_HDA_CODEC {
86 (spec)->codec_type == VT1812 ||\ 87 (spec)->codec_type == VT1812 ||\
87 (spec)->codec_type == VT1802) 88 (spec)->codec_type == VT1802)
88 89
89#define MAX_NID_PATH_DEPTH 5
90
91/* output-path: DAC -> ... -> pin
92 * idx[] contains the source index number of the next widget;
93 * e.g. idx[0] is the index of the DAC selected by path[1] widget
94 * multi[] indicates whether it's a selector widget with multi-connectors
95 * (i.e. the connection selection is mandatory)
96 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
97 */
98struct nid_path {
99 int depth;
100 hda_nid_t path[MAX_NID_PATH_DEPTH];
101 unsigned char idx[MAX_NID_PATH_DEPTH];
102 unsigned char multi[MAX_NID_PATH_DEPTH];
103 unsigned int vol_ctl;
104 unsigned int mute_ctl;
105};
106
107/* input-path */
108struct via_input {
109 hda_nid_t pin; /* input-pin or aa-mix */
110 int adc_idx; /* ADC index to be used */
111 int mux_idx; /* MUX index (if any) */
112 const char *label; /* input-source label */
113};
114
115#define VIA_MAX_ADCS 3
116
117enum {
118 STREAM_MULTI_OUT = (1 << 0),
119 STREAM_INDEP_HP = (1 << 1),
120};
121
122struct via_spec { 90struct via_spec {
123 struct hda_gen_spec gen; 91 struct hda_gen_spec gen;
124 92
@@ -129,77 +97,7 @@ struct via_spec {
129 const struct hda_verb *init_verbs[5]; 97 const struct hda_verb *init_verbs[5];
130 unsigned int num_iverbs; 98 unsigned int num_iverbs;
131 99
132 char stream_name_analog[32];
133 char stream_name_hp[32];
134 const struct hda_pcm_stream *stream_analog_playback;
135 const struct hda_pcm_stream *stream_analog_capture;
136
137 char stream_name_digital[32];
138 const struct hda_pcm_stream *stream_digital_playback;
139 const struct hda_pcm_stream *stream_digital_capture;
140
141 /* playback */
142 struct hda_multi_out multiout;
143 hda_nid_t slave_dig_outs[2];
144 hda_nid_t hp_dac_nid;
145 hda_nid_t speaker_dac_nid;
146 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
147 int opened_streams; /* STREAM_* bits */
148 int active_streams; /* STREAM_* bits */
149 int aamix_mode; /* loopback is enabled for output-path? */
150
151 /* Output-paths:
152 * There are different output-paths depending on the setup.
153 * out_path, hp_path and speaker_path are primary paths. If both
154 * direct DAC and aa-loopback routes are available, these contain
155 * the former paths. Meanwhile *_mix_path contain the paths with
156 * loopback mixer. (Since the loopback is only for front channel,
157 * no out_mix_path for surround channels.)
158 * The HP output has another path, hp_indep_path, which is used in
159 * the independent-HP mode.
160 */
161 struct nid_path out_path[HDA_SIDE + 1];
162 struct nid_path out_mix_path;
163 struct nid_path hp_path;
164 struct nid_path hp_mix_path;
165 struct nid_path hp_indep_path;
166 struct nid_path speaker_path;
167 struct nid_path speaker_mix_path;
168
169 /* capture */
170 unsigned int num_adc_nids;
171 hda_nid_t adc_nids[VIA_MAX_ADCS];
172 hda_nid_t mux_nids[VIA_MAX_ADCS];
173 hda_nid_t aa_mix_nid;
174 hda_nid_t dig_in_nid;
175
176 /* capture source */
177 bool dyn_adc_switch;
178 int num_inputs;
179 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
180 unsigned int cur_mux[VIA_MAX_ADCS];
181
182 /* dynamic DAC switching */
183 unsigned int cur_dac_stream_tag;
184 unsigned int cur_dac_format;
185 unsigned int cur_hp_stream_tag;
186 unsigned int cur_hp_format;
187
188 /* dynamic ADC switching */
189 hda_nid_t cur_adc;
190 unsigned int cur_adc_stream_tag;
191 unsigned int cur_adc_format;
192
193 /* PCM information */
194 struct hda_pcm pcm_rec[3];
195
196 /* dynamic controls, init_verbs and input_mux */
197 struct auto_pin_cfg autocfg;
198 struct snd_array kctls;
199 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
200
201 /* HP mode source */ 100 /* HP mode source */
202 unsigned int hp_independent_mode;
203 unsigned int dmic_enabled; 101 unsigned int dmic_enabled;
204 unsigned int no_pin_power_ctl; 102 unsigned int no_pin_power_ctl;
205 enum VIA_HDA_CODEC codec_type; 103 enum VIA_HDA_CODEC codec_type;
@@ -207,36 +105,22 @@ struct via_spec {
207 /* analog low-power control */ 105 /* analog low-power control */
208 bool alc_mode; 106 bool alc_mode;
209 107
210 /* smart51 setup */
211 unsigned int smart51_nums;
212 hda_nid_t smart51_pins[2];
213 int smart51_idxs[2];
214 const char *smart51_labels[2];
215 unsigned int smart51_enabled;
216
217 /* work to check hp jack state */ 108 /* work to check hp jack state */
218 struct hda_codec *codec;
219 struct delayed_work vt1708_hp_work;
220 int hp_work_active; 109 int hp_work_active;
221 int vt1708_jack_detect; 110 int vt1708_jack_detect;
222 int vt1708_hp_present;
223 111
224 void (*set_widgets_power_state)(struct hda_codec *codec); 112 void (*set_widgets_power_state)(struct hda_codec *codec);
225 unsigned int dac_stream_tag[4]; 113 unsigned int dac_stream_tag[4];
226
227 struct hda_loopback_check loopback;
228 int num_loopbacks;
229 struct hda_amp_list loopback_list[8];
230
231 /* bind capture-volume */
232 struct hda_bind_ctls *bind_cap_vol;
233 struct hda_bind_ctls *bind_cap_sw;
234
235 struct mutex config_mutex;
236}; 114};
237 115
238static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); 116static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
239static struct via_spec * via_new_spec(struct hda_codec *codec) 117static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
118 struct hda_codec *codec,
119 struct snd_pcm_substream *substream,
120 int action);
121static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl);
122
123static struct via_spec *via_new_spec(struct hda_codec *codec)
240{ 124{
241 struct via_spec *spec; 125 struct via_spec *spec;
242 126
@@ -244,15 +128,15 @@ static struct via_spec * via_new_spec(struct hda_codec *codec)
244 if (spec == NULL) 128 if (spec == NULL)
245 return NULL; 129 return NULL;
246 130
247 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
248 mutex_init(&spec->config_mutex);
249 codec->spec = spec; 131 codec->spec = spec;
250 spec->codec = codec; 132 snd_hda_gen_spec_init(&spec->gen);
251 spec->codec_type = get_codec_type(codec); 133 spec->codec_type = get_codec_type(codec);
252 /* VT1708BCE & VT1708S are almost same */ 134 /* VT1708BCE & VT1708S are almost same */
253 if (spec->codec_type == VT1708BCE) 135 if (spec->codec_type == VT1708BCE)
254 spec->codec_type = VT1708S; 136 spec->codec_type = VT1708S;
255 snd_hda_gen_init(&spec->gen); 137 spec->no_pin_power_ctl = 1;
138 spec->gen.indep_hp = 1;
139 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
256 return spec; 140 return spec;
257} 141}
258 142
@@ -308,16 +192,6 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
308 return codec_type; 192 return codec_type;
309}; 193};
310 194
311#define VIA_JACK_EVENT 0x20
312#define VIA_HP_EVENT 0x01
313#define VIA_LINE_EVENT 0x03
314
315enum {
316 VIA_CTL_WIDGET_VOL,
317 VIA_CTL_WIDGET_MUTE,
318 VIA_CTL_WIDGET_ANALOG_MUTE,
319};
320
321static void analog_low_current_mode(struct hda_codec *codec); 195static void analog_low_current_mode(struct hda_codec *codec);
322static bool is_aa_path_mute(struct hda_codec *codec); 196static bool is_aa_path_mute(struct hda_codec *codec);
323 197
@@ -325,31 +199,34 @@ static bool is_aa_path_mute(struct hda_codec *codec);
325 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \ 199 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
326 !is_aa_path_mute(codec)) 200 !is_aa_path_mute(codec))
327 201
328static void vt1708_stop_hp_work(struct via_spec *spec) 202static void vt1708_stop_hp_work(struct hda_codec *codec)
329{ 203{
330 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) 204 struct via_spec *spec = codec->spec;
205 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
331 return; 206 return;
332 if (spec->hp_work_active) { 207 if (spec->hp_work_active) {
333 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1); 208 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
334 cancel_delayed_work_sync(&spec->vt1708_hp_work); 209 cancel_delayed_work_sync(&codec->jackpoll_work);
335 spec->hp_work_active = 0; 210 spec->hp_work_active = false;
211 codec->jackpoll_interval = 0;
336 } 212 }
337} 213}
338 214
339static void vt1708_update_hp_work(struct via_spec *spec) 215static void vt1708_update_hp_work(struct hda_codec *codec)
340{ 216{
341 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) 217 struct via_spec *spec = codec->spec;
218 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
342 return; 219 return;
343 if (spec->vt1708_jack_detect && 220 if (spec->vt1708_jack_detect) {
344 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
345 if (!spec->hp_work_active) { 221 if (!spec->hp_work_active) {
346 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0); 222 codec->jackpoll_interval = msecs_to_jiffies(100);
347 schedule_delayed_work(&spec->vt1708_hp_work, 223 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
348 msecs_to_jiffies(100)); 224 queue_delayed_work(codec->bus->workq,
349 spec->hp_work_active = 1; 225 &codec->jackpoll_work, 0);
226 spec->hp_work_active = true;
350 } 227 }
351 } else if (!hp_detect_with_aa(spec->codec)) 228 } else if (!hp_detect_with_aa(codec))
352 vt1708_stop_hp_work(spec); 229 vt1708_stop_hp_work(codec);
353} 230}
354 231
355static void set_widgets_power_state(struct hda_codec *codec) 232static void set_widgets_power_state(struct hda_codec *codec)
@@ -359,361 +236,10 @@ static void set_widgets_power_state(struct hda_codec *codec)
359 spec->set_widgets_power_state(codec); 236 spec->set_widgets_power_state(codec);
360} 237}
361 238
362static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
363 struct snd_ctl_elem_value *ucontrol)
364{
365 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
367
368 set_widgets_power_state(codec);
369 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
370 vt1708_update_hp_work(codec->spec);
371 return change;
372}
373
374/* modify .put = snd_hda_mixer_amp_switch_put */
375#define ANALOG_INPUT_MUTE \
376 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
377 .name = NULL, \
378 .index = 0, \
379 .info = snd_hda_mixer_amp_switch_info, \
380 .get = snd_hda_mixer_amp_switch_get, \
381 .put = analog_input_switch_put, \
382 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
383
384static const struct snd_kcontrol_new via_control_templates[] = {
385 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
386 HDA_CODEC_MUTE(NULL, 0, 0, 0),
387 ANALOG_INPUT_MUTE,
388};
389
390
391/* add dynamic controls */
392static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
393 const struct snd_kcontrol_new *tmpl,
394 const char *name)
395{
396 struct snd_kcontrol_new *knew;
397
398 knew = snd_array_new(&spec->kctls);
399 if (!knew)
400 return NULL;
401 *knew = *tmpl;
402 if (!name)
403 name = tmpl->name;
404 if (name) {
405 knew->name = kstrdup(name, GFP_KERNEL);
406 if (!knew->name)
407 return NULL;
408 }
409 return knew;
410}
411
412static int __via_add_control(struct via_spec *spec, int type, const char *name,
413 int idx, unsigned long val)
414{
415 struct snd_kcontrol_new *knew;
416
417 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
418 if (!knew)
419 return -ENOMEM;
420 knew->index = idx;
421 if (get_amp_nid_(val))
422 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
423 knew->private_value = val;
424 return 0;
425}
426
427#define via_add_control(spec, type, name, val) \
428 __via_add_control(spec, type, name, 0, val)
429
430#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
431
432static void via_free_kctls(struct hda_codec *codec)
433{
434 struct via_spec *spec = codec->spec;
435
436 if (spec->kctls.list) {
437 struct snd_kcontrol_new *kctl = spec->kctls.list;
438 int i;
439 for (i = 0; i < spec->kctls.used; i++)
440 kfree(kctl[i].name);
441 }
442 snd_array_free(&spec->kctls);
443}
444
445/* create input playback/capture controls for the given pin */
446static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
447 int type_idx, int idx, int mix_nid)
448{
449 char name[32];
450 int err;
451
452 sprintf(name, "%s Playback Volume", ctlname);
453 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
454 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
455 if (err < 0)
456 return err;
457 sprintf(name, "%s Playback Switch", ctlname);
458 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
459 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
460 if (err < 0)
461 return err;
462 return 0;
463}
464
465#define get_connection_index(codec, mux, nid) \
466 snd_hda_get_conn_index(codec, mux, nid, 0)
467
468static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
469 unsigned int mask)
470{
471 unsigned int caps;
472 if (!nid)
473 return false;
474 caps = get_wcaps(codec, nid);
475 if (dir == HDA_INPUT)
476 caps &= AC_WCAP_IN_AMP;
477 else
478 caps &= AC_WCAP_OUT_AMP;
479 if (!caps)
480 return false;
481 if (query_amp_caps(codec, nid, dir) & mask)
482 return true;
483 return false;
484}
485
486#define have_mute(codec, nid, dir) \
487 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
488
489/* enable/disable the output-route mixers */
490static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
491 hda_nid_t mix_nid, int idx, bool enable)
492{
493 int i, num, val;
494
495 if (!path)
496 return;
497 num = snd_hda_get_num_conns(codec, mix_nid);
498 for (i = 0; i < num; i++) {
499 if (i == idx)
500 val = AMP_IN_UNMUTE(i);
501 else
502 val = AMP_IN_MUTE(i);
503 snd_hda_codec_write(codec, mix_nid, 0,
504 AC_VERB_SET_AMP_GAIN_MUTE, val);
505 }
506}
507
508/* enable/disable the output-route */
509static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
510 bool enable, bool force)
511{
512 struct via_spec *spec = codec->spec;
513 int i;
514 for (i = 0; i < path->depth; i++) {
515 hda_nid_t src, dst;
516 int idx = path->idx[i];
517 src = path->path[i];
518 if (i < path->depth - 1)
519 dst = path->path[i + 1];
520 else
521 dst = 0;
522 if (enable && path->multi[i])
523 snd_hda_codec_write(codec, dst, 0,
524 AC_VERB_SET_CONNECT_SEL, idx);
525 if (!force && (dst == spec->aa_mix_nid))
526 continue;
527 if (have_mute(codec, dst, HDA_INPUT))
528 activate_output_mix(codec, path, dst, idx, enable);
529 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
530 continue;
531 if (have_mute(codec, src, HDA_OUTPUT)) {
532 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
533 snd_hda_codec_write(codec, src, 0,
534 AC_VERB_SET_AMP_GAIN_MUTE, val);
535 }
536 }
537}
538
539/* set the given pin as output */
540static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
541 int pin_type)
542{
543 if (!pin)
544 return;
545 snd_hda_set_pin_ctl(codec, pin, pin_type);
546 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
547 snd_hda_codec_write(codec, pin, 0,
548 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
549}
550
551static void via_auto_init_output(struct hda_codec *codec,
552 struct nid_path *path, int pin_type)
553{
554 unsigned int caps;
555 hda_nid_t pin;
556
557 if (!path->depth)
558 return;
559 pin = path->path[path->depth - 1];
560
561 init_output_pin(codec, pin, pin_type);
562 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
563 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
564 else
565 caps = 0;
566 if (caps & AC_AMPCAP_MUTE) {
567 unsigned int val;
568 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
569 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
570 AMP_OUT_MUTE | val);
571 }
572 activate_output_path(codec, path, true, true); /* force on */
573}
574
575static void via_auto_init_multi_out(struct hda_codec *codec)
576{
577 struct via_spec *spec = codec->spec;
578 struct nid_path *path;
579 int i;
580
581 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
582 path = &spec->out_path[i];
583 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
584 path = &spec->out_mix_path;
585 via_auto_init_output(codec, path, PIN_OUT);
586 }
587}
588
589/* deactivate the inactive headphone-paths */
590static void deactivate_hp_paths(struct hda_codec *codec)
591{
592 struct via_spec *spec = codec->spec;
593 int shared = spec->hp_indep_shared;
594
595 if (spec->hp_independent_mode) {
596 activate_output_path(codec, &spec->hp_path, false, false);
597 activate_output_path(codec, &spec->hp_mix_path, false, false);
598 if (shared)
599 activate_output_path(codec, &spec->out_path[shared],
600 false, false);
601 } else if (spec->aamix_mode || !spec->hp_path.depth) {
602 activate_output_path(codec, &spec->hp_indep_path, false, false);
603 activate_output_path(codec, &spec->hp_path, false, false);
604 } else {
605 activate_output_path(codec, &spec->hp_indep_path, false, false);
606 activate_output_path(codec, &spec->hp_mix_path, false, false);
607 }
608}
609
610static void via_auto_init_hp_out(struct hda_codec *codec)
611{
612 struct via_spec *spec = codec->spec;
613
614 if (!spec->hp_path.depth) {
615 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
616 return;
617 }
618 deactivate_hp_paths(codec);
619 if (spec->hp_independent_mode)
620 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
621 else if (spec->aamix_mode)
622 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
623 else
624 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
625}
626
627static void via_auto_init_speaker_out(struct hda_codec *codec)
628{
629 struct via_spec *spec = codec->spec;
630
631 if (!spec->autocfg.speaker_outs)
632 return;
633 if (!spec->speaker_path.depth) {
634 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
635 return;
636 }
637 if (!spec->aamix_mode) {
638 activate_output_path(codec, &spec->speaker_mix_path,
639 false, false);
640 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
641 } else {
642 activate_output_path(codec, &spec->speaker_path, false, false);
643 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
644 }
645}
646
647static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
648static void via_hp_automute(struct hda_codec *codec);
649
650static void via_auto_init_analog_input(struct hda_codec *codec)
651{
652 struct via_spec *spec = codec->spec;
653 const struct auto_pin_cfg *cfg = &spec->autocfg;
654 hda_nid_t conn[HDA_MAX_CONNECTIONS];
655 unsigned int ctl;
656 int i, num_conns;
657
658 /* init ADCs */
659 for (i = 0; i < spec->num_adc_nids; i++) {
660 hda_nid_t nid = spec->adc_nids[i];
661 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) ||
662 !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE))
663 continue;
664 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
665 AC_VERB_SET_AMP_GAIN_MUTE,
666 AMP_IN_UNMUTE(0));
667 }
668
669 /* init pins */
670 for (i = 0; i < cfg->num_inputs; i++) {
671 hda_nid_t nid = cfg->inputs[i].pin;
672 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
673 ctl = PIN_OUT;
674 else {
675 ctl = PIN_IN;
676 if (cfg->inputs[i].type == AUTO_PIN_MIC)
677 ctl |= snd_hda_get_default_vref(codec, nid);
678 }
679 snd_hda_set_pin_ctl(codec, nid, ctl);
680 }
681
682 /* init input-src */
683 for (i = 0; i < spec->num_adc_nids; i++) {
684 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
685 /* secondary ADCs must have the unique MUX */
686 if (i > 0 && !spec->mux_nids[i])
687 break;
688 if (spec->mux_nids[adc_idx]) {
689 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
690 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
691 AC_VERB_SET_CONNECT_SEL,
692 mux_idx);
693 }
694 if (spec->dyn_adc_switch)
695 break; /* only one input-src */
696 }
697
698 /* init aa-mixer */
699 if (!spec->aa_mix_nid)
700 return;
701 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
702 ARRAY_SIZE(conn));
703 for (i = 0; i < num_conns; i++) {
704 unsigned int caps = get_wcaps(codec, conn[i]);
705 if (get_wcaps_type(caps) == AC_WID_PIN)
706 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
707 AC_VERB_SET_AMP_GAIN_MUTE,
708 AMP_IN_MUTE(i));
709 }
710}
711
712static void update_power_state(struct hda_codec *codec, hda_nid_t nid, 239static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
713 unsigned int parm) 240 unsigned int parm)
714{ 241{
715 if (snd_hda_codec_read(codec, nid, 0, 242 if (snd_hda_check_power_state(codec, nid, parm))
716 AC_VERB_GET_POWER_STATE, 0) == parm)
717 return; 243 return;
718 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); 244 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
719} 245}
@@ -723,8 +249,8 @@ static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
723{ 249{
724 struct via_spec *spec = codec->spec; 250 struct via_spec *spec = codec->spec;
725 unsigned int format; 251 unsigned int format;
726 if (snd_hda_codec_read(codec, nid, 0, 252
727 AC_VERB_GET_POWER_STATE, 0) == parm) 253 if (snd_hda_check_power_state(codec, nid, parm))
728 return; 254 return;
729 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); 255 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
730 if (format && (spec->dac_stream_tag[index] != format)) 256 if (format && (spec->dac_stream_tag[index] != format))
@@ -740,6 +266,23 @@ static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
740 } 266 }
741} 267}
742 268
269static bool smart51_enabled(struct hda_codec *codec)
270{
271 struct via_spec *spec = codec->spec;
272 return spec->gen.ext_channel_count > 2;
273}
274
275static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
276{
277 struct via_spec *spec = codec->spec;
278 int i;
279
280 for (i = 0; i < spec->gen.multi_ios; i++)
281 if (spec->gen.multi_io[i].pin == pin)
282 return true;
283 return false;
284}
285
743static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, 286static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
744 unsigned int *affected_parm) 287 unsigned int *affected_parm)
745{ 288{
@@ -754,7 +297,7 @@ static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
754 no_presence |= spec->no_pin_power_ctl; 297 no_presence |= spec->no_pin_power_ctl;
755 if (!no_presence) 298 if (!no_presence)
756 present = snd_hda_jack_detect(codec, nid); 299 present = snd_hda_jack_detect(codec, nid);
757 if ((spec->smart51_enabled && is_smart51_pins(codec, nid)) 300 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
758 || ((no_presence || present) 301 || ((no_presence || present)
759 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { 302 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
760 *affected_parm = AC_PWRST_D0; /* if it's connected */ 303 *affected_parm = AC_PWRST_D0; /* if it's connected */
@@ -795,277 +338,29 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
795 return 1; 338 return 1;
796} 339}
797 340
798static const struct snd_kcontrol_new via_pin_power_ctl_enum = { 341static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
342 {
799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 343 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
800 .name = "Dynamic Power-Control", 344 .name = "Dynamic Power-Control",
801 .info = via_pin_power_ctl_info, 345 .info = via_pin_power_ctl_info,
802 .get = via_pin_power_ctl_get, 346 .get = via_pin_power_ctl_get,
803 .put = via_pin_power_ctl_put, 347 .put = via_pin_power_ctl_put,
348 },
349 {} /* terminator */
804}; 350};
805 351
806 352
807static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
808 struct snd_ctl_elem_info *uinfo)
809{
810 static const char * const texts[] = { "OFF", "ON" };
811
812 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
813 uinfo->count = 1;
814 uinfo->value.enumerated.items = 2;
815 if (uinfo->value.enumerated.item >= 2)
816 uinfo->value.enumerated.item = 1;
817 strcpy(uinfo->value.enumerated.name,
818 texts[uinfo->value.enumerated.item]);
819 return 0;
820}
821
822static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
823 struct snd_ctl_elem_value *ucontrol)
824{
825 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
826 struct via_spec *spec = codec->spec;
827
828 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
829 return 0;
830}
831
832/* adjust spec->multiout setup according to the current flags */
833static void setup_playback_multi_pcm(struct via_spec *spec)
834{
835 const struct auto_pin_cfg *cfg = &spec->autocfg;
836 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
837 spec->multiout.hp_nid = 0;
838 if (!spec->hp_independent_mode) {
839 if (!spec->hp_indep_shared)
840 spec->multiout.hp_nid = spec->hp_dac_nid;
841 } else {
842 if (spec->hp_indep_shared)
843 spec->multiout.num_dacs = cfg->line_outs - 1;
844 }
845}
846
847/* update DAC setups according to indep-HP switch;
848 * this function is called only when indep-HP is modified
849 */
850static void switch_indep_hp_dacs(struct hda_codec *codec)
851{
852 struct via_spec *spec = codec->spec;
853 int shared = spec->hp_indep_shared;
854 hda_nid_t shared_dac, hp_dac;
855
856 if (!spec->opened_streams)
857 return;
858
859 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
860 hp_dac = spec->hp_dac_nid;
861 if (spec->hp_independent_mode) {
862 /* switch to indep-HP mode */
863 if (spec->active_streams & STREAM_MULTI_OUT) {
864 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
865 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
866 }
867 if (spec->active_streams & STREAM_INDEP_HP)
868 snd_hda_codec_setup_stream(codec, hp_dac,
869 spec->cur_hp_stream_tag, 0,
870 spec->cur_hp_format);
871 } else {
872 /* back to HP or shared-DAC */
873 if (spec->active_streams & STREAM_INDEP_HP)
874 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
875 if (spec->active_streams & STREAM_MULTI_OUT) {
876 hda_nid_t dac;
877 int ch;
878 if (shared_dac) { /* reset mutli-ch DAC */
879 dac = shared_dac;
880 ch = shared * 2;
881 } else { /* reset HP DAC */
882 dac = hp_dac;
883 ch = 0;
884 }
885 snd_hda_codec_setup_stream(codec, dac,
886 spec->cur_dac_stream_tag, ch,
887 spec->cur_dac_format);
888 }
889 }
890 setup_playback_multi_pcm(spec);
891}
892
893static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
894 struct snd_ctl_elem_value *ucontrol)
895{
896 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
897 struct via_spec *spec = codec->spec;
898 int cur, shared;
899
900 mutex_lock(&spec->config_mutex);
901 cur = !!ucontrol->value.enumerated.item[0];
902 if (spec->hp_independent_mode == cur) {
903 mutex_unlock(&spec->config_mutex);
904 return 0;
905 }
906 spec->hp_independent_mode = cur;
907 shared = spec->hp_indep_shared;
908 deactivate_hp_paths(codec);
909 if (cur)
910 activate_output_path(codec, &spec->hp_indep_path, true, false);
911 else {
912 if (shared)
913 activate_output_path(codec, &spec->out_path[shared],
914 true, false);
915 if (spec->aamix_mode || !spec->hp_path.depth)
916 activate_output_path(codec, &spec->hp_mix_path,
917 true, false);
918 else
919 activate_output_path(codec, &spec->hp_path,
920 true, false);
921 }
922
923 switch_indep_hp_dacs(codec);
924 mutex_unlock(&spec->config_mutex);
925
926 /* update jack power state */
927 set_widgets_power_state(codec);
928 via_hp_automute(codec);
929 return 1;
930}
931
932static const struct snd_kcontrol_new via_hp_mixer = {
933 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
934 .name = "Independent HP",
935 .info = via_independent_hp_info,
936 .get = via_independent_hp_get,
937 .put = via_independent_hp_put,
938};
939
940static int via_hp_build(struct hda_codec *codec)
941{
942 struct via_spec *spec = codec->spec;
943 struct snd_kcontrol_new *knew;
944 hda_nid_t nid;
945
946 nid = spec->autocfg.hp_pins[0];
947 knew = via_clone_control(spec, &via_hp_mixer);
948 if (knew == NULL)
949 return -ENOMEM;
950
951 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
952
953 return 0;
954}
955
956static void notify_aa_path_ctls(struct hda_codec *codec)
957{
958 struct via_spec *spec = codec->spec;
959 int i;
960
961 for (i = 0; i < spec->smart51_nums; i++) {
962 struct snd_kcontrol *ctl;
963 struct snd_ctl_elem_id id;
964 memset(&id, 0, sizeof(id));
965 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
966 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
967 ctl = snd_hda_find_mixer_ctl(codec, id.name);
968 if (ctl)
969 snd_ctl_notify(codec->bus->card,
970 SNDRV_CTL_EVENT_MASK_VALUE,
971 &ctl->id);
972 }
973}
974
975static void mute_aa_path(struct hda_codec *codec, int mute)
976{
977 struct via_spec *spec = codec->spec;
978 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
979 int i;
980
981 /* check AA path's mute status */
982 for (i = 0; i < spec->smart51_nums; i++) {
983 if (spec->smart51_idxs[i] < 0)
984 continue;
985 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
986 HDA_INPUT, spec->smart51_idxs[i],
987 HDA_AMP_MUTE, val);
988 }
989}
990
991static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
992{
993 struct via_spec *spec = codec->spec;
994 int i;
995
996 for (i = 0; i < spec->smart51_nums; i++)
997 if (spec->smart51_pins[i] == pin)
998 return true;
999 return false;
1000}
1001
1002static int via_smart51_get(struct snd_kcontrol *kcontrol,
1003 struct snd_ctl_elem_value *ucontrol)
1004{
1005 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1006 struct via_spec *spec = codec->spec;
1007
1008 *ucontrol->value.integer.value = spec->smart51_enabled;
1009 return 0;
1010}
1011
1012static int via_smart51_put(struct snd_kcontrol *kcontrol,
1013 struct snd_ctl_elem_value *ucontrol)
1014{
1015 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1016 struct via_spec *spec = codec->spec;
1017 int out_in = *ucontrol->value.integer.value
1018 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1019 int i;
1020
1021 for (i = 0; i < spec->smart51_nums; i++) {
1022 hda_nid_t nid = spec->smart51_pins[i];
1023 unsigned int parm;
1024
1025 parm = snd_hda_codec_read(codec, nid, 0,
1026 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1027 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1028 parm |= out_in;
1029 snd_hda_set_pin_ctl(codec, nid, parm);
1030 if (out_in == AC_PINCTL_OUT_EN) {
1031 mute_aa_path(codec, 1);
1032 notify_aa_path_ctls(codec);
1033 }
1034 }
1035 spec->smart51_enabled = *ucontrol->value.integer.value;
1036 set_widgets_power_state(codec);
1037 return 1;
1038}
1039
1040static const struct snd_kcontrol_new via_smart51_mixer = {
1041 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1042 .name = "Smart 5.1",
1043 .count = 1,
1044 .info = snd_ctl_boolean_mono_info,
1045 .get = via_smart51_get,
1046 .put = via_smart51_put,
1047};
1048
1049static int via_smart51_build(struct hda_codec *codec)
1050{
1051 struct via_spec *spec = codec->spec;
1052
1053 if (!spec->smart51_nums)
1054 return 0;
1055 if (!via_clone_control(spec, &via_smart51_mixer))
1056 return -ENOMEM;
1057 return 0;
1058}
1059
1060/* check AA path's mute status */ 353/* check AA path's mute status */
1061static bool is_aa_path_mute(struct hda_codec *codec) 354static bool is_aa_path_mute(struct hda_codec *codec)
1062{ 355{
1063 struct via_spec *spec = codec->spec; 356 struct via_spec *spec = codec->spec;
1064 const struct hda_amp_list *p; 357 const struct hda_amp_list *p;
1065 int i, ch, v; 358 int ch, v;
1066 359
1067 for (i = 0; i < spec->num_loopbacks; i++) { 360 p = spec->gen.loopback.amplist;
1068 p = &spec->loopback_list[i]; 361 if (!p)
362 return true;
363 for (; p->nid; p++) {
1069 for (ch = 0; ch < 2; ch++) { 364 for (ch = 0; ch < 2; ch++) {
1070 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, 365 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1071 p->idx); 366 p->idx);
@@ -1086,7 +381,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force)
1086 if (spec->no_pin_power_ctl) 381 if (spec->no_pin_power_ctl)
1087 enable = false; 382 enable = false;
1088 else 383 else
1089 enable = is_aa_path_mute(codec) && !spec->opened_streams; 384 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
1090 if (enable == spec->alc_mode && !force) 385 if (enable == spec->alc_mode && !force)
1091 return; 386 return;
1092 spec->alc_mode = enable; 387 spec->alc_mode = enable;
@@ -1131,366 +426,17 @@ static void analog_low_current_mode(struct hda_codec *codec)
1131 return __analog_low_current_mode(codec, false); 426 return __analog_low_current_mode(codec, false);
1132} 427}
1133 428
1134/*
1135 * generic initialization of ADC, input mixers and output mixers
1136 */
1137static const struct hda_verb vt1708_init_verbs[] = {
1138 /* power down jack detect function */
1139 {0x1, 0xf81, 0x1},
1140 { }
1141};
1142
1143static void set_stream_open(struct hda_codec *codec, int bit, bool active)
1144{
1145 struct via_spec *spec = codec->spec;
1146
1147 if (active)
1148 spec->opened_streams |= bit;
1149 else
1150 spec->opened_streams &= ~bit;
1151 analog_low_current_mode(codec);
1152}
1153
1154static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1155 struct hda_codec *codec,
1156 struct snd_pcm_substream *substream)
1157{
1158 struct via_spec *spec = codec->spec;
1159 const struct auto_pin_cfg *cfg = &spec->autocfg;
1160 int err;
1161
1162 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1163 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1164 set_stream_open(codec, STREAM_MULTI_OUT, true);
1165 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1166 hinfo);
1167 if (err < 0) {
1168 set_stream_open(codec, STREAM_MULTI_OUT, false);
1169 return err;
1170 }
1171 return 0;
1172}
1173
1174static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1175 struct hda_codec *codec,
1176 struct snd_pcm_substream *substream)
1177{
1178 set_stream_open(codec, STREAM_MULTI_OUT, false);
1179 return 0;
1180}
1181
1182static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1183 struct hda_codec *codec,
1184 struct snd_pcm_substream *substream)
1185{
1186 struct via_spec *spec = codec->spec;
1187
1188 if (snd_BUG_ON(!spec->hp_dac_nid))
1189 return -EINVAL;
1190 set_stream_open(codec, STREAM_INDEP_HP, true);
1191 return 0;
1192}
1193
1194static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1195 struct hda_codec *codec,
1196 struct snd_pcm_substream *substream)
1197{
1198 set_stream_open(codec, STREAM_INDEP_HP, false);
1199 return 0;
1200}
1201
1202static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1203 struct hda_codec *codec,
1204 unsigned int stream_tag,
1205 unsigned int format,
1206 struct snd_pcm_substream *substream)
1207{
1208 struct via_spec *spec = codec->spec;
1209
1210 mutex_lock(&spec->config_mutex);
1211 setup_playback_multi_pcm(spec);
1212 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1213 format, substream);
1214 /* remember for dynamic DAC switch with indep-HP */
1215 spec->active_streams |= STREAM_MULTI_OUT;
1216 spec->cur_dac_stream_tag = stream_tag;
1217 spec->cur_dac_format = format;
1218 mutex_unlock(&spec->config_mutex);
1219 vt1708_update_hp_work(spec);
1220 return 0;
1221}
1222
1223static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1224 struct hda_codec *codec,
1225 unsigned int stream_tag,
1226 unsigned int format,
1227 struct snd_pcm_substream *substream)
1228{
1229 struct via_spec *spec = codec->spec;
1230
1231 mutex_lock(&spec->config_mutex);
1232 if (spec->hp_independent_mode)
1233 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1234 stream_tag, 0, format);
1235 spec->active_streams |= STREAM_INDEP_HP;
1236 spec->cur_hp_stream_tag = stream_tag;
1237 spec->cur_hp_format = format;
1238 mutex_unlock(&spec->config_mutex);
1239 vt1708_update_hp_work(spec);
1240 return 0;
1241}
1242
1243static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1244 struct hda_codec *codec,
1245 struct snd_pcm_substream *substream)
1246{
1247 struct via_spec *spec = codec->spec;
1248
1249 mutex_lock(&spec->config_mutex);
1250 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1251 spec->active_streams &= ~STREAM_MULTI_OUT;
1252 mutex_unlock(&spec->config_mutex);
1253 vt1708_update_hp_work(spec);
1254 return 0;
1255}
1256
1257static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1258 struct hda_codec *codec,
1259 struct snd_pcm_substream *substream)
1260{
1261 struct via_spec *spec = codec->spec;
1262
1263 mutex_lock(&spec->config_mutex);
1264 if (spec->hp_independent_mode)
1265 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1266 spec->active_streams &= ~STREAM_INDEP_HP;
1267 mutex_unlock(&spec->config_mutex);
1268 vt1708_update_hp_work(spec);
1269 return 0;
1270}
1271
1272/*
1273 * Digital out
1274 */
1275static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1276 struct hda_codec *codec,
1277 struct snd_pcm_substream *substream)
1278{
1279 struct via_spec *spec = codec->spec;
1280 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1281}
1282
1283static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1284 struct hda_codec *codec,
1285 struct snd_pcm_substream *substream)
1286{
1287 struct via_spec *spec = codec->spec;
1288 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1289}
1290
1291static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1292 struct hda_codec *codec,
1293 unsigned int stream_tag,
1294 unsigned int format,
1295 struct snd_pcm_substream *substream)
1296{
1297 struct via_spec *spec = codec->spec;
1298 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1299 stream_tag, format, substream);
1300}
1301
1302static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1303 struct hda_codec *codec,
1304 struct snd_pcm_substream *substream)
1305{
1306 struct via_spec *spec = codec->spec;
1307 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1308 return 0;
1309}
1310
1311/*
1312 * Analog capture
1313 */
1314static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1315 struct hda_codec *codec,
1316 unsigned int stream_tag,
1317 unsigned int format,
1318 struct snd_pcm_substream *substream)
1319{
1320 struct via_spec *spec = codec->spec;
1321
1322 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1323 stream_tag, 0, format);
1324 return 0;
1325}
1326
1327static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1328 struct hda_codec *codec,
1329 struct snd_pcm_substream *substream)
1330{
1331 struct via_spec *spec = codec->spec;
1332 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1333 return 0;
1334}
1335
1336/* analog capture with dynamic ADC switching */
1337static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1338 struct hda_codec *codec,
1339 unsigned int stream_tag,
1340 unsigned int format,
1341 struct snd_pcm_substream *substream)
1342{
1343 struct via_spec *spec = codec->spec;
1344 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1345
1346 mutex_lock(&spec->config_mutex);
1347 spec->cur_adc = spec->adc_nids[adc_idx];
1348 spec->cur_adc_stream_tag = stream_tag;
1349 spec->cur_adc_format = format;
1350 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1351 mutex_unlock(&spec->config_mutex);
1352 return 0;
1353}
1354
1355static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1356 struct hda_codec *codec,
1357 struct snd_pcm_substream *substream)
1358{
1359 struct via_spec *spec = codec->spec;
1360
1361 mutex_lock(&spec->config_mutex);
1362 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1363 spec->cur_adc = 0;
1364 mutex_unlock(&spec->config_mutex);
1365 return 0;
1366}
1367
1368/* re-setup the stream if running; called from input-src put */
1369static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1370{
1371 struct via_spec *spec = codec->spec;
1372 int adc_idx = spec->inputs[cur].adc_idx;
1373 hda_nid_t adc = spec->adc_nids[adc_idx];
1374 bool ret = false;
1375
1376 mutex_lock(&spec->config_mutex);
1377 if (spec->cur_adc && spec->cur_adc != adc) {
1378 /* stream is running, let's swap the current ADC */
1379 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1380 spec->cur_adc = adc;
1381 snd_hda_codec_setup_stream(codec, adc,
1382 spec->cur_adc_stream_tag, 0,
1383 spec->cur_adc_format);
1384 ret = true;
1385 }
1386 mutex_unlock(&spec->config_mutex);
1387 return ret;
1388}
1389
1390static const struct hda_pcm_stream via_pcm_analog_playback = {
1391 .substreams = 1,
1392 .channels_min = 2,
1393 .channels_max = 8,
1394 /* NID is set in via_build_pcms */
1395 .ops = {
1396 .open = via_playback_multi_pcm_open,
1397 .close = via_playback_multi_pcm_close,
1398 .prepare = via_playback_multi_pcm_prepare,
1399 .cleanup = via_playback_multi_pcm_cleanup
1400 },
1401};
1402
1403static const struct hda_pcm_stream via_pcm_hp_playback = {
1404 .substreams = 1,
1405 .channels_min = 2,
1406 .channels_max = 2,
1407 /* NID is set in via_build_pcms */
1408 .ops = {
1409 .open = via_playback_hp_pcm_open,
1410 .close = via_playback_hp_pcm_close,
1411 .prepare = via_playback_hp_pcm_prepare,
1412 .cleanup = via_playback_hp_pcm_cleanup
1413 },
1414};
1415
1416static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1417 .substreams = 1,
1418 .channels_min = 2,
1419 .channels_max = 8,
1420 /* NID is set in via_build_pcms */
1421 /* We got noisy outputs on the right channel on VT1708 when
1422 * 24bit samples are used. Until any workaround is found,
1423 * disable the 24bit format, so far.
1424 */
1425 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1426 .ops = {
1427 .open = via_playback_multi_pcm_open,
1428 .close = via_playback_multi_pcm_close,
1429 .prepare = via_playback_multi_pcm_prepare,
1430 .cleanup = via_playback_multi_pcm_cleanup
1431 },
1432};
1433
1434static const struct hda_pcm_stream via_pcm_analog_capture = {
1435 .substreams = 1, /* will be changed in via_build_pcms() */
1436 .channels_min = 2,
1437 .channels_max = 2,
1438 /* NID is set in via_build_pcms */
1439 .ops = {
1440 .prepare = via_capture_pcm_prepare,
1441 .cleanup = via_capture_pcm_cleanup
1442 },
1443};
1444
1445static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1446 .substreams = 1,
1447 .channels_min = 2,
1448 .channels_max = 2,
1449 /* NID is set in via_build_pcms */
1450 .ops = {
1451 .prepare = via_dyn_adc_capture_pcm_prepare,
1452 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1453 },
1454};
1455
1456static const struct hda_pcm_stream via_pcm_digital_playback = {
1457 .substreams = 1,
1458 .channels_min = 2,
1459 .channels_max = 2,
1460 /* NID is set in via_build_pcms */
1461 .ops = {
1462 .open = via_dig_playback_pcm_open,
1463 .close = via_dig_playback_pcm_close,
1464 .prepare = via_dig_playback_pcm_prepare,
1465 .cleanup = via_dig_playback_pcm_cleanup
1466 },
1467};
1468
1469static const struct hda_pcm_stream via_pcm_digital_capture = {
1470 .substreams = 1,
1471 .channels_min = 2,
1472 .channels_max = 2,
1473};
1474
1475/*
1476 * slave controls for virtual master
1477 */
1478static const char * const via_slave_pfxs[] = {
1479 "Front", "Surround", "Center", "LFE", "Side",
1480 "Headphone", "Speaker", "Bass Speaker",
1481 NULL,
1482};
1483
1484static int via_build_controls(struct hda_codec *codec) 429static int via_build_controls(struct hda_codec *codec)
1485{ 430{
1486 struct via_spec *spec = codec->spec; 431 struct via_spec *spec = codec->spec;
1487 struct snd_kcontrol *kctl;
1488 int err, i; 432 int err, i;
1489 433
1490 spec->no_pin_power_ctl = 1; 434 err = snd_hda_gen_build_controls(codec);
435 if (err < 0)
436 return err;
437
1491 if (spec->set_widgets_power_state) 438 if (spec->set_widgets_power_state)
1492 if (!via_clone_control(spec, &via_pin_power_ctl_enum)) 439 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
1493 return -ENOMEM;
1494 440
1495 for (i = 0; i < spec->num_mixers; i++) { 441 for (i = 0; i < spec->num_mixers; i++) {
1496 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 442 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
@@ -1498,152 +444,16 @@ static int via_build_controls(struct hda_codec *codec)
1498 return err; 444 return err;
1499 } 445 }
1500 446
1501 if (spec->multiout.dig_out_nid) {
1502 err = snd_hda_create_spdif_out_ctls(codec,
1503 spec->multiout.dig_out_nid,
1504 spec->multiout.dig_out_nid);
1505 if (err < 0)
1506 return err;
1507 err = snd_hda_create_spdif_share_sw(codec,
1508 &spec->multiout);
1509 if (err < 0)
1510 return err;
1511 spec->multiout.share_spdif = 1;
1512 }
1513 if (spec->dig_in_nid) {
1514 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1515 if (err < 0)
1516 return err;
1517 }
1518
1519 /* if we have no master control, let's create it */
1520 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1521 unsigned int vmaster_tlv[4];
1522 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1523 HDA_OUTPUT, vmaster_tlv);
1524 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1525 vmaster_tlv, via_slave_pfxs,
1526 "Playback Volume");
1527 if (err < 0)
1528 return err;
1529 }
1530 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1531 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1532 NULL, via_slave_pfxs,
1533 "Playback Switch");
1534 if (err < 0)
1535 return err;
1536 }
1537
1538 /* assign Capture Source enums to NID */
1539 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1540 for (i = 0; kctl && i < kctl->count; i++) {
1541 if (!spec->mux_nids[i])
1542 continue;
1543 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1544 if (err < 0)
1545 return err;
1546 }
1547
1548 via_free_kctls(codec); /* no longer needed */
1549
1550 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1551 if (err < 0)
1552 return err;
1553
1554 return 0; 447 return 0;
1555} 448}
1556 449
1557static int via_build_pcms(struct hda_codec *codec) 450static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
451 struct hda_codec *codec,
452 struct snd_pcm_substream *substream,
453 int action)
1558{ 454{
1559 struct via_spec *spec = codec->spec; 455 analog_low_current_mode(codec);
1560 struct hda_pcm *info = spec->pcm_rec; 456 vt1708_update_hp_work(codec);
1561
1562 codec->num_pcms = 0;
1563 codec->pcm_info = info;
1564
1565 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1566 snprintf(spec->stream_name_analog,
1567 sizeof(spec->stream_name_analog),
1568 "%s Analog", codec->chip_name);
1569 info->name = spec->stream_name_analog;
1570
1571 if (spec->multiout.num_dacs) {
1572 if (!spec->stream_analog_playback)
1573 spec->stream_analog_playback =
1574 &via_pcm_analog_playback;
1575 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1576 *spec->stream_analog_playback;
1577 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1578 spec->multiout.dac_nids[0];
1579 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1580 spec->multiout.max_channels;
1581 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT
1582 && spec->autocfg.line_outs == 2)
1583 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1584 snd_pcm_2_1_chmaps;
1585 }
1586
1587 if (!spec->stream_analog_capture) {
1588 if (spec->dyn_adc_switch)
1589 spec->stream_analog_capture =
1590 &via_pcm_dyn_adc_analog_capture;
1591 else
1592 spec->stream_analog_capture =
1593 &via_pcm_analog_capture;
1594 }
1595 if (spec->num_adc_nids) {
1596 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1597 *spec->stream_analog_capture;
1598 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1599 spec->adc_nids[0];
1600 if (!spec->dyn_adc_switch)
1601 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1602 spec->num_adc_nids;
1603 }
1604 codec->num_pcms++;
1605 info++;
1606 }
1607
1608 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1609 snprintf(spec->stream_name_digital,
1610 sizeof(spec->stream_name_digital),
1611 "%s Digital", codec->chip_name);
1612 info->name = spec->stream_name_digital;
1613 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1614 if (spec->multiout.dig_out_nid) {
1615 if (!spec->stream_digital_playback)
1616 spec->stream_digital_playback =
1617 &via_pcm_digital_playback;
1618 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1619 *spec->stream_digital_playback;
1620 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1621 spec->multiout.dig_out_nid;
1622 }
1623 if (spec->dig_in_nid) {
1624 if (!spec->stream_digital_capture)
1625 spec->stream_digital_capture =
1626 &via_pcm_digital_capture;
1627 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1628 *spec->stream_digital_capture;
1629 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1630 spec->dig_in_nid;
1631 }
1632 codec->num_pcms++;
1633 info++;
1634 }
1635
1636 if (spec->hp_dac_nid) {
1637 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1638 "%s HP", codec->chip_name);
1639 info->name = spec->stream_name_hp;
1640 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1641 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1642 spec->hp_dac_nid;
1643 codec->num_pcms++;
1644 info++;
1645 }
1646 return 0;
1647} 457}
1648 458
1649static void via_free(struct hda_codec *codec) 459static void via_free(struct hda_codec *codec)
@@ -1653,79 +463,22 @@ static void via_free(struct hda_codec *codec)
1653 if (!spec) 463 if (!spec)
1654 return; 464 return;
1655 465
1656 via_free_kctls(codec); 466 vt1708_stop_hp_work(codec);
1657 vt1708_stop_hp_work(spec); 467 snd_hda_gen_spec_free(&spec->gen);
1658 kfree(spec->bind_cap_vol);
1659 kfree(spec->bind_cap_sw);
1660 snd_hda_gen_free(&spec->gen);
1661 kfree(spec); 468 kfree(spec);
1662} 469}
1663 470
1664/* mute/unmute outputs */
1665static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1666 hda_nid_t *pins, bool mute)
1667{
1668 int i;
1669 for (i = 0; i < num_pins; i++) {
1670 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1671 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1672 if (parm & AC_PINCTL_IN_EN)
1673 continue;
1674 if (mute)
1675 parm &= ~AC_PINCTL_OUT_EN;
1676 else
1677 parm |= AC_PINCTL_OUT_EN;
1678 snd_hda_set_pin_ctl(codec, pins[i], parm);
1679 }
1680}
1681
1682/* mute internal speaker if line-out is plugged */
1683static void via_line_automute(struct hda_codec *codec, int present)
1684{
1685 struct via_spec *spec = codec->spec;
1686
1687 if (!spec->autocfg.speaker_outs)
1688 return;
1689 if (!present)
1690 present = snd_hda_jack_detect(codec,
1691 spec->autocfg.line_out_pins[0]);
1692 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1693 spec->autocfg.speaker_pins,
1694 present);
1695}
1696
1697/* mute internal speaker if HP is plugged */
1698static void via_hp_automute(struct hda_codec *codec)
1699{
1700 int present = 0;
1701 int nums;
1702 struct via_spec *spec = codec->spec;
1703
1704 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
1705 (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
1706 is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
1707 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1708
1709 if (spec->smart51_enabled)
1710 nums = spec->autocfg.line_outs + spec->smart51_nums;
1711 else
1712 nums = spec->autocfg.line_outs;
1713 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1714
1715 via_line_automute(codec, present);
1716}
1717
1718#ifdef CONFIG_PM 471#ifdef CONFIG_PM
1719static int via_suspend(struct hda_codec *codec) 472static int via_suspend(struct hda_codec *codec)
1720{ 473{
1721 struct via_spec *spec = codec->spec; 474 struct via_spec *spec = codec->spec;
1722 vt1708_stop_hp_work(spec); 475 vt1708_stop_hp_work(codec);
1723 476
1724 if (spec->codec_type == VT1802) { 477 if (spec->codec_type == VT1802) {
1725 /* Fix pop noise on headphones */ 478 /* Fix pop noise on headphones */
1726 int i; 479 int i;
1727 for (i = 0; i < spec->autocfg.hp_outs; i++) 480 for (i = 0; i < spec->gen.autocfg.hp_outs; i++)
1728 snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0); 481 snd_hda_set_pin_ctl(codec, spec->gen.autocfg.hp_pins[i], 0);
1729 } 482 }
1730 483
1731 return 0; 484 return 0;
@@ -1736,7 +489,10 @@ static int via_suspend(struct hda_codec *codec)
1736static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) 489static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1737{ 490{
1738 struct via_spec *spec = codec->spec; 491 struct via_spec *spec = codec->spec;
1739 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); 492 set_widgets_power_state(codec);
493 analog_low_current_mode(codec);
494 vt1708_update_hp_work(codec);
495 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
1740} 496}
1741#endif 497#endif
1742 498
@@ -1747,7 +503,7 @@ static int via_init(struct hda_codec *codec);
1747 503
1748static const struct hda_codec_ops via_patch_ops = { 504static const struct hda_codec_ops via_patch_ops = {
1749 .build_controls = via_build_controls, 505 .build_controls = via_build_controls,
1750 .build_pcms = via_build_pcms, 506 .build_pcms = snd_hda_gen_build_pcms,
1751 .init = via_init, 507 .init = via_init,
1752 .free = via_free, 508 .free = via_free,
1753 .unsol_event = snd_hda_jack_unsol_event, 509 .unsol_event = snd_hda_jack_unsol_event,
@@ -1757,840 +513,12 @@ static const struct hda_codec_ops via_patch_ops = {
1757#endif 513#endif
1758}; 514};
1759 515
1760static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1761{
1762 struct via_spec *spec = codec->spec;
1763 int i;
1764
1765 for (i = 0; i < spec->multiout.num_dacs; i++) {
1766 if (spec->multiout.dac_nids[i] == dac)
1767 return false;
1768 }
1769 if (spec->hp_dac_nid == dac)
1770 return false;
1771 return true;
1772}
1773
1774static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1775 hda_nid_t target_dac, int with_aa_mix,
1776 struct nid_path *path, int depth)
1777{
1778 struct via_spec *spec = codec->spec;
1779 hda_nid_t conn[8];
1780 int i, nums;
1781
1782 if (nid == spec->aa_mix_nid) {
1783 if (!with_aa_mix)
1784 return false;
1785 with_aa_mix = 2; /* mark aa-mix is included */
1786 }
1787
1788 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1789 for (i = 0; i < nums; i++) {
1790 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1791 continue;
1792 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1793 /* aa-mix is requested but not included? */
1794 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1795 goto found;
1796 }
1797 }
1798 if (depth >= MAX_NID_PATH_DEPTH)
1799 return false;
1800 for (i = 0; i < nums; i++) {
1801 unsigned int type;
1802 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1803 if (type == AC_WID_AUD_OUT)
1804 continue;
1805 if (__parse_output_path(codec, conn[i], target_dac,
1806 with_aa_mix, path, depth + 1))
1807 goto found;
1808 }
1809 return false;
1810
1811 found:
1812 path->path[path->depth] = conn[i];
1813 path->idx[path->depth] = i;
1814 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1815 path->multi[path->depth] = 1;
1816 path->depth++;
1817 return true;
1818}
1819
1820static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1821 hda_nid_t target_dac, int with_aa_mix,
1822 struct nid_path *path)
1823{
1824 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1825 path->path[path->depth] = nid;
1826 path->depth++;
1827 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1828 path->depth, path->path[0], path->path[1],
1829 path->path[2], path->path[3], path->path[4]);
1830 return true;
1831 }
1832 return false;
1833}
1834
1835static int via_auto_fill_dac_nids(struct hda_codec *codec)
1836{
1837 struct via_spec *spec = codec->spec;
1838 const struct auto_pin_cfg *cfg = &spec->autocfg;
1839 int i;
1840 hda_nid_t nid;
1841
1842 spec->multiout.num_dacs = 0;
1843 spec->multiout.dac_nids = spec->private_dac_nids;
1844 for (i = 0; i < cfg->line_outs; i++) {
1845 hda_nid_t dac = 0;
1846 nid = cfg->line_out_pins[i];
1847 if (!nid)
1848 continue;
1849 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1850 dac = spec->out_path[i].path[0];
1851 if (!i && parse_output_path(codec, nid, dac, 1,
1852 &spec->out_mix_path))
1853 dac = spec->out_mix_path.path[0];
1854 if (dac)
1855 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
1856 }
1857 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1858 spec->out_path[0] = spec->out_mix_path;
1859 spec->out_mix_path.depth = 0;
1860 }
1861 return 0;
1862}
1863
1864static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1865 int chs, bool check_dac, struct nid_path *path)
1866{
1867 struct via_spec *spec = codec->spec;
1868 char name[32];
1869 hda_nid_t dac, pin, sel, nid;
1870 int err;
1871
1872 dac = check_dac ? path->path[0] : 0;
1873 pin = path->path[path->depth - 1];
1874 sel = path->depth > 1 ? path->path[1] : 0;
1875
1876 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1877 nid = dac;
1878 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1879 nid = pin;
1880 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1881 nid = sel;
1882 else
1883 nid = 0;
1884 if (nid) {
1885 sprintf(name, "%s Playback Volume", pfx);
1886 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1887 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1888 if (err < 0)
1889 return err;
1890 path->vol_ctl = nid;
1891 }
1892
1893 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1894 nid = dac;
1895 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1896 nid = pin;
1897 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1898 nid = sel;
1899 else
1900 nid = 0;
1901 if (nid) {
1902 sprintf(name, "%s Playback Switch", pfx);
1903 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1904 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1905 if (err < 0)
1906 return err;
1907 path->mute_ctl = nid;
1908 }
1909 return 0;
1910}
1911
1912static void mangle_smart51(struct hda_codec *codec)
1913{
1914 struct via_spec *spec = codec->spec;
1915 struct auto_pin_cfg *cfg = &spec->autocfg;
1916 struct auto_pin_cfg_item *ins = cfg->inputs;
1917 int i, j, nums, attr;
1918 int pins[AUTO_CFG_MAX_INS];
1919
1920 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1921 nums = 0;
1922 for (i = 0; i < cfg->num_inputs; i++) {
1923 unsigned int def;
1924 if (ins[i].type > AUTO_PIN_LINE_IN)
1925 continue;
1926 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1927 if (snd_hda_get_input_pin_attr(def) != attr)
1928 continue;
1929 for (j = 0; j < nums; j++)
1930 if (ins[pins[j]].type < ins[i].type) {
1931 memmove(pins + j + 1, pins + j,
1932 (nums - j) * sizeof(int));
1933 break;
1934 }
1935 pins[j] = i;
1936 nums++;
1937 }
1938 if (cfg->line_outs + nums < 3)
1939 continue;
1940 for (i = 0; i < nums; i++) {
1941 hda_nid_t pin = ins[pins[i]].pin;
1942 spec->smart51_pins[spec->smart51_nums++] = pin;
1943 cfg->line_out_pins[cfg->line_outs++] = pin;
1944 if (cfg->line_outs == 3)
1945 break;
1946 }
1947 return;
1948 }
1949}
1950
1951static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1952{
1953 dst->vol_ctl = src->vol_ctl;
1954 dst->mute_ctl = src->mute_ctl;
1955}
1956
1957/* add playback controls from the parsed DAC table */
1958static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1959{
1960 struct via_spec *spec = codec->spec;
1961 struct auto_pin_cfg *cfg = &spec->autocfg;
1962 struct nid_path *path;
1963 static const char * const chname[4] = {
1964 "Front", "Surround", NULL /* "CLFE" */, "Side"
1965 };
1966 int i, idx, err;
1967 int old_line_outs;
1968
1969 /* check smart51 */
1970 old_line_outs = cfg->line_outs;
1971 if (cfg->line_outs == 1)
1972 mangle_smart51(codec);
1973
1974 err = via_auto_fill_dac_nids(codec);
1975 if (err < 0)
1976 return err;
1977
1978 if (spec->multiout.num_dacs < 3) {
1979 spec->smart51_nums = 0;
1980 cfg->line_outs = old_line_outs;
1981 }
1982 for (i = 0; i < cfg->line_outs; i++) {
1983 hda_nid_t pin, dac;
1984 pin = cfg->line_out_pins[i];
1985 dac = spec->multiout.dac_nids[i];
1986 if (!pin || !dac)
1987 continue;
1988 path = spec->out_path + i;
1989 if (i == HDA_CLFE) {
1990 err = create_ch_ctls(codec, "Center", 1, true, path);
1991 if (err < 0)
1992 return err;
1993 err = create_ch_ctls(codec, "LFE", 2, true, path);
1994 if (err < 0)
1995 return err;
1996 } else {
1997 const char *pfx = chname[i];
1998 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1999 cfg->line_outs <= 2)
2000 pfx = i ? "Bass Speaker" : "Speaker";
2001 err = create_ch_ctls(codec, pfx, 3, true, path);
2002 if (err < 0)
2003 return err;
2004 }
2005 if (path != spec->out_path + i)
2006 copy_path_mixer_ctls(&spec->out_path[i], path);
2007 if (path == spec->out_path && spec->out_mix_path.depth)
2008 copy_path_mixer_ctls(&spec->out_mix_path, path);
2009 }
2010
2011 idx = get_connection_index(codec, spec->aa_mix_nid,
2012 spec->multiout.dac_nids[0]);
2013 if (idx >= 0) {
2014 /* add control to mixer */
2015 const char *name;
2016 name = spec->out_mix_path.depth ?
2017 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2018 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2019 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2020 idx, HDA_INPUT));
2021 if (err < 0)
2022 return err;
2023 name = spec->out_mix_path.depth ?
2024 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2025 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2026 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2027 idx, HDA_INPUT));
2028 if (err < 0)
2029 return err;
2030 }
2031
2032 cfg->line_outs = old_line_outs;
2033
2034 return 0;
2035}
2036
2037static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2038{
2039 struct via_spec *spec = codec->spec;
2040 struct nid_path *path;
2041 bool check_dac;
2042 int i, err;
2043
2044 if (!pin)
2045 return 0;
2046
2047 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2048 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2049 if (i < spec->multiout.num_dacs &&
2050 parse_output_path(codec, pin,
2051 spec->multiout.dac_nids[i], 0,
2052 &spec->hp_indep_path)) {
2053 spec->hp_indep_shared = i;
2054 break;
2055 }
2056 }
2057 }
2058 if (spec->hp_indep_path.depth) {
2059 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2060 if (!spec->hp_indep_shared)
2061 spec->hp_path = spec->hp_indep_path;
2062 }
2063 /* optionally check front-path w/o AA-mix */
2064 if (!spec->hp_path.depth)
2065 parse_output_path(codec, pin,
2066 spec->multiout.dac_nids[HDA_FRONT], 0,
2067 &spec->hp_path);
2068
2069 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2070 1, &spec->hp_mix_path) && !spec->hp_path.depth)
2071 return 0;
2072
2073 if (spec->hp_path.depth) {
2074 path = &spec->hp_path;
2075 check_dac = true;
2076 } else {
2077 path = &spec->hp_mix_path;
2078 check_dac = false;
2079 }
2080 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
2081 if (err < 0)
2082 return err;
2083 if (check_dac)
2084 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2085 else
2086 copy_path_mixer_ctls(&spec->hp_path, path);
2087 if (spec->hp_indep_path.depth)
2088 copy_path_mixer_ctls(&spec->hp_indep_path, path);
2089 return 0;
2090}
2091
2092static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2093{
2094 struct via_spec *spec = codec->spec;
2095 struct nid_path *path;
2096 bool check_dac;
2097 hda_nid_t pin, dac = 0;
2098 int err;
2099
2100 pin = spec->autocfg.speaker_pins[0];
2101 if (!spec->autocfg.speaker_outs || !pin)
2102 return 0;
2103
2104 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
2105 dac = spec->speaker_path.path[0];
2106 if (!dac)
2107 parse_output_path(codec, pin,
2108 spec->multiout.dac_nids[HDA_FRONT], 0,
2109 &spec->speaker_path);
2110 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2111 1, &spec->speaker_mix_path) && !dac)
2112 return 0;
2113
2114 /* no AA-path for front? */
2115 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2116 dac = 0;
2117
2118 spec->speaker_dac_nid = dac;
2119 spec->multiout.extra_out_nid[0] = dac;
2120 if (dac) {
2121 path = &spec->speaker_path;
2122 check_dac = true;
2123 } else {
2124 path = &spec->speaker_mix_path;
2125 check_dac = false;
2126 }
2127 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2128 if (err < 0)
2129 return err;
2130 if (check_dac)
2131 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2132 else
2133 copy_path_mixer_ctls(&spec->speaker_path, path);
2134 return 0;
2135}
2136
2137#define via_aamix_ctl_info via_pin_power_ctl_info
2138
2139static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2140 struct snd_ctl_elem_value *ucontrol)
2141{
2142 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2143 struct via_spec *spec = codec->spec;
2144 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2145 return 0;
2146}
2147
2148static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2149 struct nid_path *nomix, struct nid_path *mix)
2150{
2151 if (do_mix) {
2152 activate_output_path(codec, nomix, false, false);
2153 activate_output_path(codec, mix, true, false);
2154 } else {
2155 activate_output_path(codec, mix, false, false);
2156 activate_output_path(codec, nomix, true, false);
2157 }
2158}
2159
2160static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2161 struct snd_ctl_elem_value *ucontrol)
2162{
2163 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2164 struct via_spec *spec = codec->spec;
2165 unsigned int val = ucontrol->value.enumerated.item[0];
2166
2167 if (val == spec->aamix_mode)
2168 return 0;
2169 spec->aamix_mode = val;
2170 /* update front path */
2171 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2172 /* update HP path */
2173 if (!spec->hp_independent_mode) {
2174 update_aamix_paths(codec, val, &spec->hp_path,
2175 &spec->hp_mix_path);
2176 }
2177 /* update speaker path */
2178 update_aamix_paths(codec, val, &spec->speaker_path,
2179 &spec->speaker_mix_path);
2180 return 1;
2181}
2182
2183static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2184 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2185 .name = "Loopback Mixing",
2186 .info = via_aamix_ctl_info,
2187 .get = via_aamix_ctl_get,
2188 .put = via_aamix_ctl_put,
2189};
2190
2191static int via_auto_create_loopback_switch(struct hda_codec *codec)
2192{
2193 struct via_spec *spec = codec->spec;
2194
2195 if (!spec->aa_mix_nid)
2196 return 0; /* no loopback switching available */
2197 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2198 spec->speaker_path.depth))
2199 return 0; /* no loopback switching available */
2200 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2201 return -ENOMEM;
2202 return 0;
2203}
2204
2205/* look for ADCs */
2206static int via_fill_adcs(struct hda_codec *codec)
2207{
2208 struct via_spec *spec = codec->spec;
2209 hda_nid_t nid = codec->start_nid;
2210 int i;
2211
2212 for (i = 0; i < codec->num_nodes; i++, nid++) {
2213 unsigned int wcaps = get_wcaps(codec, nid);
2214 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2215 continue;
2216 if (wcaps & AC_WCAP_DIGITAL)
2217 continue;
2218 if (!(wcaps & AC_WCAP_CONN_LIST))
2219 continue;
2220 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2221 return -ENOMEM;
2222 spec->adc_nids[spec->num_adc_nids++] = nid;
2223 }
2224 return 0;
2225}
2226 516
2227/* input-src control */ 517static const struct hda_verb vt1708_init_verbs[] = {
2228static int via_mux_enum_info(struct snd_kcontrol *kcontrol, 518 /* power down jack detect function */
2229 struct snd_ctl_elem_info *uinfo) 519 {0x1, 0xf81, 0x1},
2230{ 520 { }
2231 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2232 struct via_spec *spec = codec->spec;
2233
2234 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2235 uinfo->count = 1;
2236 uinfo->value.enumerated.items = spec->num_inputs;
2237 if (uinfo->value.enumerated.item >= spec->num_inputs)
2238 uinfo->value.enumerated.item = spec->num_inputs - 1;
2239 strcpy(uinfo->value.enumerated.name,
2240 spec->inputs[uinfo->value.enumerated.item].label);
2241 return 0;
2242}
2243
2244static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2245 struct snd_ctl_elem_value *ucontrol)
2246{
2247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2248 struct via_spec *spec = codec->spec;
2249 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2250
2251 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2252 return 0;
2253}
2254
2255static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2256 struct snd_ctl_elem_value *ucontrol)
2257{
2258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2259 struct via_spec *spec = codec->spec;
2260 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2261 hda_nid_t mux;
2262 int cur;
2263
2264 cur = ucontrol->value.enumerated.item[0];
2265 if (cur < 0 || cur >= spec->num_inputs)
2266 return -EINVAL;
2267 if (spec->cur_mux[idx] == cur)
2268 return 0;
2269 spec->cur_mux[idx] = cur;
2270 if (spec->dyn_adc_switch) {
2271 int adc_idx = spec->inputs[cur].adc_idx;
2272 mux = spec->mux_nids[adc_idx];
2273 via_dyn_adc_pcm_resetup(codec, cur);
2274 } else {
2275 mux = spec->mux_nids[idx];
2276 if (snd_BUG_ON(!mux))
2277 return -EINVAL;
2278 }
2279
2280 if (mux) {
2281 /* switch to D0 beofre change index */
2282 update_power_state(codec, mux, AC_PWRST_D0);
2283 snd_hda_codec_write(codec, mux, 0,
2284 AC_VERB_SET_CONNECT_SEL,
2285 spec->inputs[cur].mux_idx);
2286 }
2287
2288 /* update jack power state */
2289 set_widgets_power_state(codec);
2290 return 0;
2291}
2292
2293static const struct snd_kcontrol_new via_input_src_ctl = {
2294 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2295 /* The multiple "Capture Source" controls confuse alsamixer
2296 * So call somewhat different..
2297 */
2298 /* .name = "Capture Source", */
2299 .name = "Input Source",
2300 .info = via_mux_enum_info,
2301 .get = via_mux_enum_get,
2302 .put = via_mux_enum_put,
2303}; 521};
2304
2305static int create_input_src_ctls(struct hda_codec *codec, int count)
2306{
2307 struct via_spec *spec = codec->spec;
2308 struct snd_kcontrol_new *knew;
2309
2310 if (spec->num_inputs <= 1 || !count)
2311 return 0; /* no need for single src */
2312
2313 knew = via_clone_control(spec, &via_input_src_ctl);
2314 if (!knew)
2315 return -ENOMEM;
2316 knew->count = count;
2317 return 0;
2318}
2319
2320/* add the powersave loopback-list entry */
2321static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2322{
2323 struct hda_amp_list *list;
2324
2325 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2326 return;
2327 list = spec->loopback_list + spec->num_loopbacks;
2328 list->nid = mix;
2329 list->dir = HDA_INPUT;
2330 list->idx = idx;
2331 spec->num_loopbacks++;
2332 spec->loopback.amplist = spec->loopback_list;
2333}
2334
2335static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2336 hda_nid_t dst)
2337{
2338 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2339}
2340
2341/* add the input-route to the given pin */
2342static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2343{
2344 struct via_spec *spec = codec->spec;
2345 int c, idx;
2346
2347 spec->inputs[spec->num_inputs].adc_idx = -1;
2348 spec->inputs[spec->num_inputs].pin = pin;
2349 for (c = 0; c < spec->num_adc_nids; c++) {
2350 if (spec->mux_nids[c]) {
2351 idx = get_connection_index(codec, spec->mux_nids[c],
2352 pin);
2353 if (idx < 0)
2354 continue;
2355 spec->inputs[spec->num_inputs].mux_idx = idx;
2356 } else {
2357 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2358 continue;
2359 }
2360 spec->inputs[spec->num_inputs].adc_idx = c;
2361 /* Can primary ADC satisfy all inputs? */
2362 if (!spec->dyn_adc_switch &&
2363 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2364 snd_printd(KERN_INFO
2365 "via: dynamic ADC switching enabled\n");
2366 spec->dyn_adc_switch = 1;
2367 }
2368 return true;
2369 }
2370 return false;
2371}
2372
2373static int get_mux_nids(struct hda_codec *codec);
2374
2375/* parse input-routes; fill ADCs, MUXs and input-src entries */
2376static int parse_analog_inputs(struct hda_codec *codec)
2377{
2378 struct via_spec *spec = codec->spec;
2379 const struct auto_pin_cfg *cfg = &spec->autocfg;
2380 int i, err;
2381
2382 err = via_fill_adcs(codec);
2383 if (err < 0)
2384 return err;
2385 err = get_mux_nids(codec);
2386 if (err < 0)
2387 return err;
2388
2389 /* fill all input-routes */
2390 for (i = 0; i < cfg->num_inputs; i++) {
2391 if (add_input_route(codec, cfg->inputs[i].pin))
2392 spec->inputs[spec->num_inputs++].label =
2393 hda_get_autocfg_input_label(codec, cfg, i);
2394 }
2395
2396 /* check for internal loopback recording */
2397 if (spec->aa_mix_nid &&
2398 add_input_route(codec, spec->aa_mix_nid))
2399 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2400
2401 return 0;
2402}
2403
2404/* create analog-loopback volume/switch controls */
2405static int create_loopback_ctls(struct hda_codec *codec)
2406{
2407 struct via_spec *spec = codec->spec;
2408 const struct auto_pin_cfg *cfg = &spec->autocfg;
2409 const char *prev_label = NULL;
2410 int type_idx = 0;
2411 int i, j, err, idx;
2412
2413 if (!spec->aa_mix_nid)
2414 return 0;
2415
2416 for (i = 0; i < cfg->num_inputs; i++) {
2417 hda_nid_t pin = cfg->inputs[i].pin;
2418 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2419
2420 if (prev_label && !strcmp(label, prev_label))
2421 type_idx++;
2422 else
2423 type_idx = 0;
2424 prev_label = label;
2425 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2426 if (idx >= 0) {
2427 err = via_new_analog_input(spec, label, type_idx,
2428 idx, spec->aa_mix_nid);
2429 if (err < 0)
2430 return err;
2431 add_loopback_list(spec, spec->aa_mix_nid, idx);
2432 }
2433
2434 /* remember the label for smart51 control */
2435 for (j = 0; j < spec->smart51_nums; j++) {
2436 if (spec->smart51_pins[j] == pin) {
2437 spec->smart51_idxs[j] = idx;
2438 spec->smart51_labels[j] = label;
2439 break;
2440 }
2441 }
2442 }
2443 return 0;
2444}
2445
2446/* create mic-boost controls (if present) */
2447static int create_mic_boost_ctls(struct hda_codec *codec)
2448{
2449 struct via_spec *spec = codec->spec;
2450 const struct auto_pin_cfg *cfg = &spec->autocfg;
2451 const char *prev_label = NULL;
2452 int type_idx = 0;
2453 int i, err;
2454
2455 for (i = 0; i < cfg->num_inputs; i++) {
2456 hda_nid_t pin = cfg->inputs[i].pin;
2457 unsigned int caps;
2458 const char *label;
2459 char name[32];
2460
2461 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2462 continue;
2463 caps = query_amp_caps(codec, pin, HDA_INPUT);
2464 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2465 continue;
2466 label = hda_get_autocfg_input_label(codec, cfg, i);
2467 if (prev_label && !strcmp(label, prev_label))
2468 type_idx++;
2469 else
2470 type_idx = 0;
2471 prev_label = label;
2472 snprintf(name, sizeof(name), "%s Boost Volume", label);
2473 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
2474 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2475 if (err < 0)
2476 return err;
2477 }
2478 return 0;
2479}
2480
2481/* create capture and input-src controls for multiple streams */
2482static int create_multi_adc_ctls(struct hda_codec *codec)
2483{
2484 struct via_spec *spec = codec->spec;
2485 int i, err;
2486
2487 /* create capture mixer elements */
2488 for (i = 0; i < spec->num_adc_nids; i++) {
2489 hda_nid_t adc = spec->adc_nids[i];
2490 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2491 "Capture Volume", i,
2492 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2493 HDA_INPUT));
2494 if (err < 0)
2495 return err;
2496 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2497 "Capture Switch", i,
2498 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2499 HDA_INPUT));
2500 if (err < 0)
2501 return err;
2502 }
2503
2504 /* input-source control */
2505 for (i = 0; i < spec->num_adc_nids; i++)
2506 if (!spec->mux_nids[i])
2507 break;
2508 err = create_input_src_ctls(codec, i);
2509 if (err < 0)
2510 return err;
2511 return 0;
2512}
2513
2514/* bind capture volume/switch */
2515static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2516 HDA_BIND_VOL("Capture Volume", 0);
2517static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2518 HDA_BIND_SW("Capture Switch", 0);
2519
2520static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2521 struct hda_ctl_ops *ops)
2522{
2523 struct hda_bind_ctls *ctl;
2524 int i;
2525
2526 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2527 if (!ctl)
2528 return -ENOMEM;
2529 ctl->ops = ops;
2530 for (i = 0; i < spec->num_adc_nids; i++)
2531 ctl->values[i] =
2532 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2533 *ctl_ret = ctl;
2534 return 0;
2535}
2536
2537/* create capture and input-src controls for dynamic ADC-switch case */
2538static int create_dyn_adc_ctls(struct hda_codec *codec)
2539{
2540 struct via_spec *spec = codec->spec;
2541 struct snd_kcontrol_new *knew;
2542 int err;
2543
2544 /* set up the bind capture ctls */
2545 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2546 if (err < 0)
2547 return err;
2548 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2549 if (err < 0)
2550 return err;
2551
2552 /* create capture mixer elements */
2553 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2554 if (!knew)
2555 return -ENOMEM;
2556 knew->private_value = (long)spec->bind_cap_vol;
2557
2558 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2559 if (!knew)
2560 return -ENOMEM;
2561 knew->private_value = (long)spec->bind_cap_sw;
2562
2563 /* input-source control */
2564 err = create_input_src_ctls(codec, 1);
2565 if (err < 0)
2566 return err;
2567 return 0;
2568}
2569
2570/* parse and create capture-related stuff */
2571static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2572{
2573 struct via_spec *spec = codec->spec;
2574 int err;
2575
2576 err = parse_analog_inputs(codec);
2577 if (err < 0)
2578 return err;
2579 if (spec->dyn_adc_switch)
2580 err = create_dyn_adc_ctls(codec);
2581 else
2582 err = create_multi_adc_ctls(codec);
2583 if (err < 0)
2584 return err;
2585 err = create_loopback_ctls(codec);
2586 if (err < 0)
2587 return err;
2588 err = create_mic_boost_ctls(codec);
2589 if (err < 0)
2590 return err;
2591 return 0;
2592}
2593
2594static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) 522static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2595{ 523{
2596 unsigned int def_conf; 524 unsigned int def_conf;
@@ -2633,102 +561,32 @@ static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2633 if (spec->vt1708_jack_detect == val) 561 if (spec->vt1708_jack_detect == val)
2634 return 0; 562 return 0;
2635 spec->vt1708_jack_detect = val; 563 spec->vt1708_jack_detect = val;
2636 if (spec->vt1708_jack_detect && 564 vt1708_update_hp_work(codec);
2637 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
2638 mute_aa_path(codec, 1);
2639 notify_aa_path_ctls(codec);
2640 }
2641 via_hp_automute(codec);
2642 vt1708_update_hp_work(spec);
2643 return 1; 565 return 1;
2644} 566}
2645 567
2646static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { 568static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
569 {
2647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 570 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2648 .name = "Jack Detect", 571 .name = "Jack Detect",
2649 .count = 1, 572 .count = 1,
2650 .info = snd_ctl_boolean_mono_info, 573 .info = snd_ctl_boolean_mono_info,
2651 .get = vt1708_jack_detect_get, 574 .get = vt1708_jack_detect_get,
2652 .put = vt1708_jack_detect_put, 575 .put = vt1708_jack_detect_put,
576 },
577 {} /* terminator */
2653}; 578};
2654 579
2655static void fill_dig_outs(struct hda_codec *codec); 580static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2656static void fill_dig_in(struct hda_codec *codec);
2657
2658static int via_parse_auto_config(struct hda_codec *codec)
2659{ 581{
2660 struct via_spec *spec = codec->spec; 582 set_widgets_power_state(codec);
2661 int err; 583 snd_hda_gen_hp_automute(codec, tbl);
2662
2663 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2664 if (err < 0)
2665 return err;
2666 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2667 return -EINVAL;
2668
2669 err = via_auto_create_multi_out_ctls(codec);
2670 if (err < 0)
2671 return err;
2672 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2673 if (err < 0)
2674 return err;
2675 err = via_auto_create_speaker_ctls(codec);
2676 if (err < 0)
2677 return err;
2678 err = via_auto_create_loopback_switch(codec);
2679 if (err < 0)
2680 return err;
2681 err = via_auto_create_analog_input_ctls(codec);
2682 if (err < 0)
2683 return err;
2684
2685 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2686
2687 fill_dig_outs(codec);
2688 fill_dig_in(codec);
2689
2690 if (spec->kctls.list)
2691 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2692
2693
2694 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2695 err = via_hp_build(codec);
2696 if (err < 0)
2697 return err;
2698 }
2699
2700 err = via_smart51_build(codec);
2701 if (err < 0)
2702 return err;
2703
2704 /* assign slave outs */
2705 if (spec->slave_dig_outs[0])
2706 codec->slave_dig_outs = spec->slave_dig_outs;
2707
2708 return 1;
2709}
2710
2711static void via_auto_init_dig_outs(struct hda_codec *codec)
2712{
2713 struct via_spec *spec = codec->spec;
2714 if (spec->multiout.dig_out_nid)
2715 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2716 if (spec->slave_dig_outs[0])
2717 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2718}
2719
2720static void via_auto_init_dig_in(struct hda_codec *codec)
2721{
2722 struct via_spec *spec = codec->spec;
2723 if (!spec->dig_in_nid)
2724 return;
2725 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
2726} 584}
2727 585
2728static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl) 586static void via_line_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2729{ 587{
2730 set_widgets_power_state(codec); 588 set_widgets_power_state(codec);
2731 via_hp_automute(codec); 589 snd_hda_gen_line_automute(codec, tbl);
2732} 590}
2733 591
2734static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl) 592static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
@@ -2736,41 +594,55 @@ static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_t
2736 set_widgets_power_state(codec); 594 set_widgets_power_state(codec);
2737} 595}
2738 596
2739/* initialize the unsolicited events */ 597#define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
2740static void via_auto_init_unsol_event(struct hda_codec *codec) 598
599static void via_set_jack_unsol_events(struct hda_codec *codec)
2741{ 600{
2742 struct via_spec *spec = codec->spec; 601 struct via_spec *spec = codec->spec;
2743 struct auto_pin_cfg *cfg = &spec->autocfg; 602 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
2744 unsigned int ev; 603 hda_nid_t pin;
2745 int i; 604 int i;
2746 hda_jack_callback cb;
2747
2748 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2749 snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0],
2750 VIA_HP_EVENT | VIA_JACK_EVENT,
2751 via_jack_output_event);
2752 605
606 spec->gen.hp_automute_hook = via_hp_automute;
2753 if (cfg->speaker_pins[0]) 607 if (cfg->speaker_pins[0])
2754 ev = VIA_LINE_EVENT; 608 spec->gen.line_automute_hook = via_line_automute;
2755 else
2756 ev = 0;
2757 cb = ev ? via_jack_output_event : via_jack_powerstate_event;
2758 609
2759 for (i = 0; i < cfg->line_outs; i++) { 610 for (i = 0; i < cfg->line_outs; i++) {
2760 if (cfg->line_out_pins[i] && 611 pin = cfg->line_out_pins[i];
2761 is_jack_detectable(codec, cfg->line_out_pins[i])) 612 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
2762 snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i], 613 is_jack_detectable(codec, pin))
2763 ev | VIA_JACK_EVENT, cb); 614 snd_hda_jack_detect_enable_callback(codec, pin,
615 VIA_JACK_EVENT,
616 via_jack_powerstate_event);
2764 } 617 }
2765 618
2766 for (i = 0; i < cfg->num_inputs; i++) { 619 for (i = 0; i < cfg->num_inputs; i++) {
2767 if (is_jack_detectable(codec, cfg->inputs[i].pin)) 620 pin = cfg->line_out_pins[i];
2768 snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin, 621 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
622 is_jack_detectable(codec, pin))
623 snd_hda_jack_detect_enable_callback(codec, pin,
2769 VIA_JACK_EVENT, 624 VIA_JACK_EVENT,
2770 via_jack_powerstate_event); 625 via_jack_powerstate_event);
2771 } 626 }
2772} 627}
2773 628
629static int via_parse_auto_config(struct hda_codec *codec)
630{
631 struct via_spec *spec = codec->spec;
632 int err;
633
634 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
635 if (err < 0)
636 return err;
637
638 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
639 if (err < 0)
640 return err;
641
642 via_set_jack_unsol_events(codec);
643 return 0;
644}
645
2774static int via_init(struct hda_codec *codec) 646static int via_init(struct hda_codec *codec)
2775{ 647{
2776 struct via_spec *spec = codec->spec; 648 struct via_spec *spec = codec->spec;
@@ -2783,63 +655,47 @@ static int via_init(struct hda_codec *codec)
2783 set_widgets_power_state(codec); 655 set_widgets_power_state(codec);
2784 __analog_low_current_mode(codec, true); 656 __analog_low_current_mode(codec, true);
2785 657
2786 via_auto_init_multi_out(codec); 658 snd_hda_gen_init(codec);
2787 via_auto_init_hp_out(codec);
2788 via_auto_init_speaker_out(codec);
2789 via_auto_init_analog_input(codec);
2790 via_auto_init_dig_outs(codec);
2791 via_auto_init_dig_in(codec);
2792 659
2793 via_auto_init_unsol_event(codec); 660 vt1708_update_hp_work(codec);
2794
2795 via_hp_automute(codec);
2796 vt1708_update_hp_work(spec);
2797 661
2798 return 0; 662 return 0;
2799} 663}
2800 664
2801static void vt1708_update_hp_jack_state(struct work_struct *work) 665static int vt1708_build_controls(struct hda_codec *codec)
2802{ 666{
2803 struct via_spec *spec = container_of(work, struct via_spec, 667 /* In order not to create "Phantom Jack" controls,
2804 vt1708_hp_work.work); 668 temporary enable jackpoll */
2805 if (spec->codec_type != VT1708) 669 int err;
2806 return; 670 int old_interval = codec->jackpoll_interval;
2807 snd_hda_jack_set_dirty_all(spec->codec); 671 codec->jackpoll_interval = msecs_to_jiffies(100);
2808 /* if jack state toggled */ 672 err = via_build_controls(codec);
2809 if (spec->vt1708_hp_present 673 codec->jackpoll_interval = old_interval;
2810 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { 674 return err;
2811 spec->vt1708_hp_present ^= 1;
2812 via_hp_automute(spec->codec);
2813 }
2814 if (spec->vt1708_jack_detect)
2815 schedule_delayed_work(&spec->vt1708_hp_work,
2816 msecs_to_jiffies(100));
2817} 675}
2818 676
2819static int get_mux_nids(struct hda_codec *codec) 677static int vt1708_build_pcms(struct hda_codec *codec)
2820{ 678{
2821 struct via_spec *spec = codec->spec; 679 struct via_spec *spec = codec->spec;
2822 hda_nid_t nid, conn[8]; 680 int i, err;
2823 unsigned int type; 681
2824 int i, n; 682 err = snd_hda_gen_build_pcms(codec);
2825 683 if (err < 0 || codec->vendor_id != 0x11061708)
2826 for (i = 0; i < spec->num_adc_nids; i++) { 684 return err;
2827 nid = spec->adc_nids[i]; 685
2828 while (nid) { 686 /* We got noisy outputs on the right channel on VT1708 when
2829 type = get_wcaps_type(get_wcaps(codec, nid)); 687 * 24bit samples are used. Until any workaround is found,
2830 if (type == AC_WID_PIN) 688 * disable the 24bit format, so far.
2831 break; 689 */
2832 n = snd_hda_get_connections(codec, nid, conn, 690 for (i = 0; i < codec->num_pcms; i++) {
2833 ARRAY_SIZE(conn)); 691 struct hda_pcm *info = &spec->gen.pcm_rec[i];
2834 if (n <= 0) 692 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
2835 break; 693 info->pcm_type != HDA_PCM_TYPE_AUDIO)
2836 if (n > 1) { 694 continue;
2837 spec->mux_nids[i] = nid; 695 info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
2838 break; 696 SNDRV_PCM_FMTBIT_S16_LE;
2839 }
2840 nid = conn[0];
2841 }
2842 } 697 }
698
2843 return 0; 699 return 0;
2844} 700}
2845 701
@@ -2853,7 +709,15 @@ static int patch_vt1708(struct hda_codec *codec)
2853 if (spec == NULL) 709 if (spec == NULL)
2854 return -ENOMEM; 710 return -ENOMEM;
2855 711
2856 spec->aa_mix_nid = 0x17; 712 spec->gen.mixer_nid = 0x17;
713
714 /* set jackpoll_interval while parsing the codec */
715 codec->jackpoll_interval = msecs_to_jiffies(100);
716 spec->vt1708_jack_detect = 1;
717
718 /* don't support the input jack switching due to lack of unsol event */
719 /* (it may work with polling, though, but it needs testing) */
720 spec->gen.suppress_auto_mic = 1;
2857 721
2858 /* Add HP and CD pin config connect bit re-config action */ 722 /* Add HP and CD pin config connect bit re-config action */
2859 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); 723 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
@@ -2867,18 +731,17 @@ static int patch_vt1708(struct hda_codec *codec)
2867 } 731 }
2868 732
2869 /* add jack detect on/off control */ 733 /* add jack detect on/off control */
2870 if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) 734 spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
2871 return -ENOMEM;
2872
2873 /* disable 32bit format on VT1708 */
2874 if (codec->vendor_id == 0x11061708)
2875 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2876 735
2877 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; 736 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2878 737
2879 codec->patch_ops = via_patch_ops; 738 codec->patch_ops = via_patch_ops;
739 codec->patch_ops.build_controls = vt1708_build_controls;
740 codec->patch_ops.build_pcms = vt1708_build_pcms;
741
742 /* clear jackpoll_interval again; it's set dynamically */
743 codec->jackpoll_interval = 0;
2880 744
2881 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2882 return 0; 745 return 0;
2883} 746}
2884 747
@@ -2892,7 +755,7 @@ static int patch_vt1709(struct hda_codec *codec)
2892 if (spec == NULL) 755 if (spec == NULL)
2893 return -ENOMEM; 756 return -ENOMEM;
2894 757
2895 spec->aa_mix_nid = 0x18; 758 spec->gen.mixer_nid = 0x18;
2896 759
2897 err = via_parse_auto_config(codec); 760 err = via_parse_auto_config(codec);
2898 if (err < 0) { 761 if (err < 0) {
@@ -2936,7 +799,7 @@ static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2936 /* PW0 (19h), SW1 (18h), AOW1 (11h) */ 799 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2937 parm = AC_PWRST_D3; 800 parm = AC_PWRST_D3;
2938 set_pin_power_state(codec, 0x19, &parm); 801 set_pin_power_state(codec, 0x19, &parm);
2939 if (spec->smart51_enabled) 802 if (smart51_enabled(codec))
2940 set_pin_power_state(codec, 0x1b, &parm); 803 set_pin_power_state(codec, 0x1b, &parm);
2941 update_power_state(codec, 0x18, parm); 804 update_power_state(codec, 0x18, parm);
2942 update_power_state(codec, 0x11, parm); 805 update_power_state(codec, 0x11, parm);
@@ -2945,7 +808,7 @@ static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2945 if (is_8ch) { 808 if (is_8ch) {
2946 parm = AC_PWRST_D3; 809 parm = AC_PWRST_D3;
2947 set_pin_power_state(codec, 0x22, &parm); 810 set_pin_power_state(codec, 0x22, &parm);
2948 if (spec->smart51_enabled) 811 if (smart51_enabled(codec))
2949 set_pin_power_state(codec, 0x1a, &parm); 812 set_pin_power_state(codec, 0x1a, &parm);
2950 update_power_state(codec, 0x26, parm); 813 update_power_state(codec, 0x26, parm);
2951 update_power_state(codec, 0x24, parm); 814 update_power_state(codec, 0x24, parm);
@@ -2953,7 +816,7 @@ static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2953 /* PW7(23h), SW2(27h), AOW2(25h) */ 816 /* PW7(23h), SW2(27h), AOW2(25h) */
2954 parm = AC_PWRST_D3; 817 parm = AC_PWRST_D3;
2955 set_pin_power_state(codec, 0x23, &parm); 818 set_pin_power_state(codec, 0x23, &parm);
2956 if (spec->smart51_enabled) 819 if (smart51_enabled(codec))
2957 set_pin_power_state(codec, 0x1a, &parm); 820 set_pin_power_state(codec, 0x1a, &parm);
2958 update_power_state(codec, 0x27, parm); 821 update_power_state(codec, 0x27, parm);
2959 update_power_state(codec, 0x25, parm); 822 update_power_state(codec, 0x25, parm);
@@ -2973,7 +836,7 @@ static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2973 if (is_8ch) { 836 if (is_8ch) {
2974 update_power_state(codec, 0x25, parm); 837 update_power_state(codec, 0x25, parm);
2975 update_power_state(codec, 0x27, parm); 838 update_power_state(codec, 0x27, parm);
2976 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) 839 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
2977 update_power_state(codec, 0x25, parm); 840 update_power_state(codec, 0x25, parm);
2978} 841}
2979 842
@@ -2991,7 +854,7 @@ static int patch_vt1708B(struct hda_codec *codec)
2991 if (spec == NULL) 854 if (spec == NULL)
2992 return -ENOMEM; 855 return -ENOMEM;
2993 856
2994 spec->aa_mix_nid = 0x16; 857 spec->gen.mixer_nid = 0x16;
2995 858
2996 /* automatic parse from the BIOS config */ 859 /* automatic parse from the BIOS config */
2997 err = via_parse_auto_config(codec); 860 err = via_parse_auto_config(codec);
@@ -3016,58 +879,6 @@ static const struct hda_verb vt1708S_init_verbs[] = {
3016 { } 879 { }
3017}; 880};
3018 881
3019/* fill out digital output widgets; one for master and one for slave outputs */
3020static void fill_dig_outs(struct hda_codec *codec)
3021{
3022 struct via_spec *spec = codec->spec;
3023 int i;
3024
3025 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3026 hda_nid_t nid;
3027 int conn;
3028
3029 nid = spec->autocfg.dig_out_pins[i];
3030 if (!nid)
3031 continue;
3032 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3033 if (conn < 1)
3034 continue;
3035 if (!spec->multiout.dig_out_nid)
3036 spec->multiout.dig_out_nid = nid;
3037 else {
3038 spec->slave_dig_outs[0] = nid;
3039 break; /* at most two dig outs */
3040 }
3041 }
3042}
3043
3044static void fill_dig_in(struct hda_codec *codec)
3045{
3046 struct via_spec *spec = codec->spec;
3047 hda_nid_t dig_nid;
3048 int i, err;
3049
3050 if (!spec->autocfg.dig_in_pin)
3051 return;
3052
3053 dig_nid = codec->start_nid;
3054 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3055 unsigned int wcaps = get_wcaps(codec, dig_nid);
3056 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3057 continue;
3058 if (!(wcaps & AC_WCAP_DIGITAL))
3059 continue;
3060 if (!(wcaps & AC_WCAP_CONN_LIST))
3061 continue;
3062 err = get_connection_index(codec, dig_nid,
3063 spec->autocfg.dig_in_pin);
3064 if (err >= 0) {
3065 spec->dig_in_nid = dig_nid;
3066 break;
3067 }
3068 }
3069}
3070
3071static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, 882static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3072 int offset, int num_steps, int step_size) 883 int offset, int num_steps, int step_size)
3073{ 884{
@@ -3088,21 +899,10 @@ static int patch_vt1708S(struct hda_codec *codec)
3088 if (spec == NULL) 899 if (spec == NULL)
3089 return -ENOMEM; 900 return -ENOMEM;
3090 901
3091 spec->aa_mix_nid = 0x16; 902 spec->gen.mixer_nid = 0x16;
3092 override_mic_boost(codec, 0x1a, 0, 3, 40); 903 override_mic_boost(codec, 0x1a, 0, 3, 40);
3093 override_mic_boost(codec, 0x1e, 0, 3, 40); 904 override_mic_boost(codec, 0x1e, 0, 3, 40);
3094 905
3095 /* automatic parse from the BIOS config */
3096 err = via_parse_auto_config(codec);
3097 if (err < 0) {
3098 via_free(codec);
3099 return err;
3100 }
3101
3102 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
3103
3104 codec->patch_ops = via_patch_ops;
3105
3106 /* correct names for VT1708BCE */ 906 /* correct names for VT1708BCE */
3107 if (get_codec_type(codec) == VT1708BCE) { 907 if (get_codec_type(codec) == VT1708BCE) {
3108 kfree(codec->chip_name); 908 kfree(codec->chip_name);
@@ -3119,6 +919,18 @@ static int patch_vt1708S(struct hda_codec *codec)
3119 sizeof(codec->bus->card->mixername), 919 sizeof(codec->bus->card->mixername),
3120 "%s %s", codec->vendor_name, codec->chip_name); 920 "%s %s", codec->vendor_name, codec->chip_name);
3121 } 921 }
922
923 /* automatic parse from the BIOS config */
924 err = via_parse_auto_config(codec);
925 if (err < 0) {
926 via_free(codec);
927 return err;
928 }
929
930 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
931
932 codec->patch_ops = via_patch_ops;
933
3122 spec->set_widgets_power_state = set_widgets_power_state_vt1708B; 934 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3123 return 0; 935 return 0;
3124} 936}
@@ -3173,7 +985,7 @@ static int patch_vt1702(struct hda_codec *codec)
3173 if (spec == NULL) 985 if (spec == NULL)
3174 return -ENOMEM; 986 return -ENOMEM;
3175 987
3176 spec->aa_mix_nid = 0x1a; 988 spec->gen.mixer_nid = 0x1a;
3177 989
3178 /* limit AA path volume to 0 dB */ 990 /* limit AA path volume to 0 dB */
3179 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, 991 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
@@ -3240,17 +1052,17 @@ static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3240 /* PW2 (26h), AOW2 (ah) */ 1052 /* PW2 (26h), AOW2 (ah) */
3241 parm = AC_PWRST_D3; 1053 parm = AC_PWRST_D3;
3242 set_pin_power_state(codec, 0x26, &parm); 1054 set_pin_power_state(codec, 0x26, &parm);
3243 if (spec->smart51_enabled) 1055 if (smart51_enabled(codec))
3244 set_pin_power_state(codec, 0x2b, &parm); 1056 set_pin_power_state(codec, 0x2b, &parm);
3245 update_power_state(codec, 0xa, parm); 1057 update_power_state(codec, 0xa, parm);
3246 1058
3247 /* PW0 (24h), AOW0 (8h) */ 1059 /* PW0 (24h), AOW0 (8h) */
3248 parm = AC_PWRST_D3; 1060 parm = AC_PWRST_D3;
3249 set_pin_power_state(codec, 0x24, &parm); 1061 set_pin_power_state(codec, 0x24, &parm);
3250 if (!spec->hp_independent_mode) /* check for redirected HP */ 1062 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
3251 set_pin_power_state(codec, 0x28, &parm); 1063 set_pin_power_state(codec, 0x28, &parm);
3252 update_power_state(codec, 0x8, parm); 1064 update_power_state(codec, 0x8, parm);
3253 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3) 1065 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
3254 parm = parm2; 1066 parm = parm2;
3255 update_power_state(codec, 0xb, parm); 1067 update_power_state(codec, 0xb, parm);
3256 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ 1068 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
@@ -3259,11 +1071,11 @@ static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3259 /* PW1 (25h), AOW1 (9h) */ 1071 /* PW1 (25h), AOW1 (9h) */
3260 parm = AC_PWRST_D3; 1072 parm = AC_PWRST_D3;
3261 set_pin_power_state(codec, 0x25, &parm); 1073 set_pin_power_state(codec, 0x25, &parm);
3262 if (spec->smart51_enabled) 1074 if (smart51_enabled(codec))
3263 set_pin_power_state(codec, 0x2a, &parm); 1075 set_pin_power_state(codec, 0x2a, &parm);
3264 update_power_state(codec, 0x9, parm); 1076 update_power_state(codec, 0x9, parm);
3265 1077
3266 if (spec->hp_independent_mode) { 1078 if (spec->gen.indep_hp_enabled) {
3267 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ 1079 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3268 parm = AC_PWRST_D3; 1080 parm = AC_PWRST_D3;
3269 set_pin_power_state(codec, 0x28, &parm); 1081 set_pin_power_state(codec, 0x28, &parm);
@@ -3283,9 +1095,9 @@ static int add_secret_dac_path(struct hda_codec *codec)
3283 hda_nid_t conn[8]; 1095 hda_nid_t conn[8];
3284 hda_nid_t nid; 1096 hda_nid_t nid;
3285 1097
3286 if (!spec->aa_mix_nid) 1098 if (!spec->gen.mixer_nid)
3287 return 0; 1099 return 0;
3288 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn, 1100 nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
3289 ARRAY_SIZE(conn) - 1); 1101 ARRAY_SIZE(conn) - 1);
3290 for (i = 0; i < nums; i++) { 1102 for (i = 0; i < nums; i++) {
3291 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT) 1103 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
@@ -3300,7 +1112,7 @@ static int add_secret_dac_path(struct hda_codec *codec)
3300 !(caps & AC_WCAP_DIGITAL)) { 1112 !(caps & AC_WCAP_DIGITAL)) {
3301 conn[nums++] = nid; 1113 conn[nums++] = nid;
3302 return snd_hda_override_conn_list(codec, 1114 return snd_hda_override_conn_list(codec,
3303 spec->aa_mix_nid, 1115 spec->gen.mixer_nid,
3304 nums, conn); 1116 nums, conn);
3305 } 1117 }
3306 } 1118 }
@@ -3318,7 +1130,7 @@ static int patch_vt1718S(struct hda_codec *codec)
3318 if (spec == NULL) 1130 if (spec == NULL)
3319 return -ENOMEM; 1131 return -ENOMEM;
3320 1132
3321 spec->aa_mix_nid = 0x21; 1133 spec->gen.mixer_nid = 0x21;
3322 override_mic_boost(codec, 0x2b, 0, 3, 40); 1134 override_mic_boost(codec, 0x2b, 0, 3, 40);
3323 override_mic_boost(codec, 0x29, 0, 3, 40); 1135 override_mic_boost(codec, 0x29, 0, 3, 40);
3324 add_secret_dac_path(codec); 1136 add_secret_dac_path(codec);
@@ -3449,7 +1261,7 @@ static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3449 parm = AC_PWRST_D3; 1261 parm = AC_PWRST_D3;
3450 set_pin_power_state(codec, 0x19, &parm); 1262 set_pin_power_state(codec, 0x19, &parm);
3451 /* Smart 5.1 PW2(1bh) */ 1263 /* Smart 5.1 PW2(1bh) */
3452 if (spec->smart51_enabled) 1264 if (smart51_enabled(codec))
3453 set_pin_power_state(codec, 0x1b, &parm); 1265 set_pin_power_state(codec, 0x1b, &parm);
3454 update_power_state(codec, 0x18, parm); 1266 update_power_state(codec, 0x18, parm);
3455 update_power_state(codec, 0x11, parm); 1267 update_power_state(codec, 0x11, parm);
@@ -3458,12 +1270,12 @@ static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3458 parm = AC_PWRST_D3; 1270 parm = AC_PWRST_D3;
3459 set_pin_power_state(codec, 0x23, &parm); 1271 set_pin_power_state(codec, 0x23, &parm);
3460 /* Smart 5.1 PW1(1ah) */ 1272 /* Smart 5.1 PW1(1ah) */
3461 if (spec->smart51_enabled) 1273 if (smart51_enabled(codec))
3462 set_pin_power_state(codec, 0x1a, &parm); 1274 set_pin_power_state(codec, 0x1a, &parm);
3463 update_power_state(codec, 0x27, parm); 1275 update_power_state(codec, 0x27, parm);
3464 1276
3465 /* Smart 5.1 PW5(1eh) */ 1277 /* Smart 5.1 PW5(1eh) */
3466 if (spec->smart51_enabled) 1278 if (smart51_enabled(codec))
3467 set_pin_power_state(codec, 0x1e, &parm); 1279 set_pin_power_state(codec, 0x1e, &parm);
3468 update_power_state(codec, 0x25, parm); 1280 update_power_state(codec, 0x25, parm);
3469 1281
@@ -3475,7 +1287,7 @@ static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3475 mono_out = 0; 1287 mono_out = 0;
3476 else { 1288 else {
3477 present = snd_hda_jack_detect(codec, 0x1d); 1289 present = snd_hda_jack_detect(codec, 0x1d);
3478 if (!spec->hp_independent_mode && present) 1290 if (!spec->gen.indep_hp_enabled && present)
3479 mono_out = 0; 1291 mono_out = 0;
3480 else 1292 else
3481 mono_out = 1; 1293 mono_out = 1;
@@ -3490,7 +1302,7 @@ static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3490 set_pin_power_state(codec, 0x1c, &parm); 1302 set_pin_power_state(codec, 0x1c, &parm);
3491 set_pin_power_state(codec, 0x1d, &parm); 1303 set_pin_power_state(codec, 0x1d, &parm);
3492 /* HP Independent Mode, power on AOW3 */ 1304 /* HP Independent Mode, power on AOW3 */
3493 if (spec->hp_independent_mode) 1305 if (spec->gen.indep_hp_enabled)
3494 update_power_state(codec, 0x25, parm); 1306 update_power_state(codec, 0x25, parm);
3495 1307
3496 /* force to D0 for internal Speaker */ 1308 /* force to D0 for internal Speaker */
@@ -3509,7 +1321,7 @@ static int patch_vt1716S(struct hda_codec *codec)
3509 if (spec == NULL) 1321 if (spec == NULL)
3510 return -ENOMEM; 1322 return -ENOMEM;
3511 1323
3512 spec->aa_mix_nid = 0x16; 1324 spec->gen.mixer_nid = 0x16;
3513 override_mic_boost(codec, 0x1a, 0, 3, 40); 1325 override_mic_boost(codec, 0x1a, 0, 3, 40);
3514 override_mic_boost(codec, 0x1e, 0, 3, 40); 1326 override_mic_boost(codec, 0x1e, 0, 3, 40);
3515 1327
@@ -3522,9 +1334,7 @@ static int patch_vt1716S(struct hda_codec *codec)
3522 1334
3523 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs; 1335 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3524 1336
3525 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; 1337 spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
3526 spec->num_mixers++;
3527
3528 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; 1338 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3529 1339
3530 codec->patch_ops = via_patch_ops; 1340 codec->patch_ops = via_patch_ops;
@@ -3609,7 +1419,7 @@ static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3609 update_power_state(codec, 0x35, parm); 1419 update_power_state(codec, 0x35, parm);
3610 } 1420 }
3611 1421
3612 if (spec->hp_independent_mode) 1422 if (spec->gen.indep_hp_enabled)
3613 update_power_state(codec, 0x9, AC_PWRST_D0); 1423 update_power_state(codec, 0x9, AC_PWRST_D0);
3614 1424
3615 /* Class-D */ 1425 /* Class-D */
@@ -3707,7 +1517,7 @@ static int patch_vt2002P(struct hda_codec *codec)
3707 if (spec == NULL) 1517 if (spec == NULL)
3708 return -ENOMEM; 1518 return -ENOMEM;
3709 1519
3710 spec->aa_mix_nid = 0x21; 1520 spec->gen.mixer_nid = 0x21;
3711 override_mic_boost(codec, 0x2b, 0, 3, 40); 1521 override_mic_boost(codec, 0x2b, 0, 3, 40);
3712 override_mic_boost(codec, 0x29, 0, 3, 40); 1522 override_mic_boost(codec, 0x29, 0, 3, 40);
3713 if (spec->codec_type == VT1802) 1523 if (spec->codec_type == VT1802)
@@ -3778,7 +1588,7 @@ static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3778 set_pin_power_state(codec, 0x25, &parm); 1588 set_pin_power_state(codec, 0x25, &parm);
3779 update_power_state(codec, 0x15, parm); 1589 update_power_state(codec, 0x15, parm);
3780 update_power_state(codec, 0x35, parm); 1590 update_power_state(codec, 0x35, parm);
3781 if (spec->hp_independent_mode) 1591 if (spec->gen.indep_hp_enabled)
3782 update_power_state(codec, 0x9, AC_PWRST_D0); 1592 update_power_state(codec, 0x9, AC_PWRST_D0);
3783 1593
3784 /* Internal Speaker */ 1594 /* Internal Speaker */
@@ -3831,7 +1641,7 @@ static int patch_vt1812(struct hda_codec *codec)
3831 if (spec == NULL) 1641 if (spec == NULL)
3832 return -ENOMEM; 1642 return -ENOMEM;
3833 1643
3834 spec->aa_mix_nid = 0x21; 1644 spec->gen.mixer_nid = 0x21;
3835 override_mic_boost(codec, 0x2b, 0, 3, 40); 1645 override_mic_boost(codec, 0x2b, 0, 3, 40);
3836 override_mic_boost(codec, 0x29, 0, 3, 40); 1646 override_mic_boost(codec, 0x29, 0, 3, 40);
3837 add_secret_dac_path(codec); 1647 add_secret_dac_path(codec);
@@ -3901,7 +1711,7 @@ static void set_widgets_power_state_vt3476(struct hda_codec *codec)
3901 parm = AC_PWRST_D3; 1711 parm = AC_PWRST_D3;
3902 set_pin_power_state(codec, 0x26, &parm); 1712 set_pin_power_state(codec, 0x26, &parm);
3903 update_power_state(codec, 0x36, parm); 1713 update_power_state(codec, 0x36, parm);
3904 if (spec->smart51_enabled) { 1714 if (smart51_enabled(codec)) {
3905 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */ 1715 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
3906 set_pin_power_state(codec, 0x2b, &parm); 1716 set_pin_power_state(codec, 0x2b, &parm);
3907 update_power_state(codec, 0x3b, parm); 1717 update_power_state(codec, 0x3b, parm);
@@ -3913,7 +1723,7 @@ static void set_widgets_power_state_vt3476(struct hda_codec *codec)
3913 parm = AC_PWRST_D3; 1723 parm = AC_PWRST_D3;
3914 set_pin_power_state(codec, 0x25, &parm); 1724 set_pin_power_state(codec, 0x25, &parm);
3915 update_power_state(codec, 0x35, parm); 1725 update_power_state(codec, 0x35, parm);
3916 if (spec->smart51_enabled) { 1726 if (smart51_enabled(codec)) {
3917 /* PW6(2ah), MW6(3ah), MUX6(1ah) */ 1727 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
3918 set_pin_power_state(codec, 0x2a, &parm); 1728 set_pin_power_state(codec, 0x2a, &parm);
3919 update_power_state(codec, 0x3a, parm); 1729 update_power_state(codec, 0x3a, parm);
@@ -3926,7 +1736,7 @@ static void set_widgets_power_state_vt3476(struct hda_codec *codec)
3926 set_pin_power_state(codec, 0x28, &parm); 1736 set_pin_power_state(codec, 0x28, &parm);
3927 update_power_state(codec, 0x38, parm); 1737 update_power_state(codec, 0x38, parm);
3928 update_power_state(codec, 0x18, parm); 1738 update_power_state(codec, 0x18, parm);
3929 if (spec->hp_independent_mode) 1739 if (spec->gen.indep_hp_enabled)
3930 update_conv_power_state(codec, 0xb, parm, 3); 1740 update_conv_power_state(codec, 0xb, parm, 3);
3931 parm2 = parm; /* for pin 0x0b */ 1741 parm2 = parm; /* for pin 0x0b */
3932 1742
@@ -3934,7 +1744,7 @@ static void set_widgets_power_state_vt3476(struct hda_codec *codec)
3934 parm = AC_PWRST_D3; 1744 parm = AC_PWRST_D3;
3935 set_pin_power_state(codec, 0x24, &parm); 1745 set_pin_power_state(codec, 0x24, &parm);
3936 update_power_state(codec, 0x34, parm); 1746 update_power_state(codec, 0x34, parm);
3937 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3) 1747 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
3938 parm = parm2; 1748 parm = parm2;
3939 update_conv_power_state(codec, 0x8, parm, 0); 1749 update_conv_power_state(codec, 0x8, parm, 0);
3940 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ 1750 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
@@ -3951,7 +1761,7 @@ static int patch_vt3476(struct hda_codec *codec)
3951 if (spec == NULL) 1761 if (spec == NULL)
3952 return -ENOMEM; 1762 return -ENOMEM;
3953 1763
3954 spec->aa_mix_nid = 0x3f; 1764 spec->gen.mixer_nid = 0x3f;
3955 add_secret_dac_path(codec); 1765 add_secret_dac_path(codec);
3956 1766
3957 /* automatic parse from the BIOS config */ 1767 /* automatic parse from the BIOS config */
diff --git a/sound/pci/ice1712/wm8766.c b/sound/pci/ice1712/wm8766.c
index 8072adeecf68..e473f8a88f9c 100644
--- a/sound/pci/ice1712/wm8766.c
+++ b/sound/pci/ice1712/wm8766.c
@@ -31,7 +31,7 @@
31 31
32static void snd_wm8766_write(struct snd_wm8766 *wm, u16 addr, u16 data) 32static void snd_wm8766_write(struct snd_wm8766 *wm, u16 addr, u16 data)
33{ 33{
34 if (addr < WM8766_REG_RESET) 34 if (addr < WM8766_REG_COUNT)
35 wm->regs[addr] = data; 35 wm->regs[addr] = data;
36 wm->ops.write(wm, addr, data); 36 wm->ops.write(wm, addr, data);
37} 37}
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 3b9be752f3e2..b8fe40531b9c 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -3266,11 +3266,13 @@ static int check_default_spdif_aclink(struct pci_dev *pci)
3266 w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults); 3266 w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults);
3267 if (w) { 3267 if (w) {
3268 if (w->value) 3268 if (w->value)
3269 snd_printdd(KERN_INFO "intel8x0: Using SPDIF over " 3269 snd_printdd(KERN_INFO
3270 "AC-Link for %s\n", w->name); 3270 "intel8x0: Using SPDIF over AC-Link for %s\n",
3271 snd_pci_quirk_name(w));
3271 else 3272 else
3272 snd_printdd(KERN_INFO "intel8x0: Using integrated " 3273 snd_printdd(KERN_INFO
3273 "SPDIF DMA for %s\n", w->name); 3274 "intel8x0: Using integrated SPDIF DMA for %s\n",
3275 snd_pci_quirk_name(w));
3274 return w->value; 3276 return w->value;
3275 } 3277 }
3276 return 0; 3278 return 0;
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 9387533f70dc..c76ac1411210 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -2586,8 +2586,9 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
2586 else { 2586 else {
2587 quirk = snd_pci_quirk_lookup(pci, m3_amp_quirk_list); 2587 quirk = snd_pci_quirk_lookup(pci, m3_amp_quirk_list);
2588 if (quirk) { 2588 if (quirk) {
2589 snd_printdd(KERN_INFO "maestro3: set amp-gpio " 2589 snd_printdd(KERN_INFO
2590 "for '%s'\n", quirk->name); 2590 "maestro3: set amp-gpio for '%s'\n",
2591 snd_pci_quirk_name(quirk));
2591 chip->amp_gpio = quirk->value; 2592 chip->amp_gpio = quirk->value;
2592 } else if (chip->allegro_flag) 2593 } else if (chip->allegro_flag)
2593 chip->amp_gpio = GPO_EXT_AMP_ALLEGRO; 2594 chip->amp_gpio = GPO_EXT_AMP_ALLEGRO;
@@ -2597,8 +2598,9 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
2597 2598
2598 quirk = snd_pci_quirk_lookup(pci, m3_irda_quirk_list); 2599 quirk = snd_pci_quirk_lookup(pci, m3_irda_quirk_list);
2599 if (quirk) { 2600 if (quirk) {
2600 snd_printdd(KERN_INFO "maestro3: enabled irda workaround " 2601 snd_printdd(KERN_INFO
2601 "for '%s'\n", quirk->name); 2602 "maestro3: enabled irda workaround for '%s'\n",
2603 snd_pci_quirk_name(quirk));
2602 chip->irda_workaround = 1; 2604 chip->irda_workaround = 1;
2603 } 2605 }
2604 quirk = snd_pci_quirk_lookup(pci, m3_hv_quirk_list); 2606 quirk = snd_pci_quirk_lookup(pci, m3_hv_quirk_list);
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 563a193e36a3..6febedb05936 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -1660,7 +1660,8 @@ static int snd_nm256_probe(struct pci_dev *pci,
1660 1660
1661 q = snd_pci_quirk_lookup(pci, nm256_quirks); 1661 q = snd_pci_quirk_lookup(pci, nm256_quirks);
1662 if (q) { 1662 if (q) {
1663 snd_printdd(KERN_INFO "nm256: Enabled quirk for %s.\n", q->name); 1663 snd_printdd(KERN_INFO "nm256: Enabled quirk for %s.\n",
1664 snd_pci_quirk_name(q));
1664 switch (q->value) { 1665 switch (q->value) {
1665 case NM_BLACKLISTED: 1666 case NM_BLACKLISTED:
1666 printk(KERN_INFO "nm256: The device is blacklisted. " 1667 printk(KERN_INFO "nm256: The device is blacklisted. "
diff --git a/sound/pci/pcxhr/pcxhr_core.c b/sound/pci/pcxhr/pcxhr_core.c
index b33db1e006e7..37b431b9b69d 100644
--- a/sound/pci/pcxhr/pcxhr_core.c
+++ b/sound/pci/pcxhr/pcxhr_core.c
@@ -1012,13 +1012,12 @@ static int pcxhr_handle_async_err(struct pcxhr_mgr *mgr, u32 err,
1012 enum pcxhr_async_err_src err_src, int pipe, 1012 enum pcxhr_async_err_src err_src, int pipe,
1013 int is_capture) 1013 int is_capture)
1014{ 1014{
1015#ifdef CONFIG_SND_DEBUG_VERBOSE
1016 static char* err_src_name[] = { 1015 static char* err_src_name[] = {
1017 [PCXHR_ERR_PIPE] = "Pipe", 1016 [PCXHR_ERR_PIPE] = "Pipe",
1018 [PCXHR_ERR_STREAM] = "Stream", 1017 [PCXHR_ERR_STREAM] = "Stream",
1019 [PCXHR_ERR_AUDIO] = "Audio" 1018 [PCXHR_ERR_AUDIO] = "Audio"
1020 }; 1019 };
1021#endif 1020
1022 if (err & 0xfff) 1021 if (err & 0xfff)
1023 err &= 0xfff; 1022 err &= 0xfff;
1024 else 1023 else
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index 2450663e1a18..0ecd4100713e 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1017,7 +1017,7 @@ static int snd_rme32_capture_close(struct snd_pcm_substream *substream)
1017 spin_lock_irq(&rme32->lock); 1017 spin_lock_irq(&rme32->lock);
1018 rme32->capture_substream = NULL; 1018 rme32->capture_substream = NULL;
1019 rme32->capture_periodsize = 0; 1019 rme32->capture_periodsize = 0;
1020 spin_unlock(&rme32->lock); 1020 spin_unlock_irq(&rme32->lock);
1021 return 0; 1021 return 0;
1022} 1022}
1023 1023
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 4fae81f21efb..94084cdb130c 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -154,10 +154,13 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
154#define HDSP_BIGENDIAN_MODE 0x200 154#define HDSP_BIGENDIAN_MODE 0x200
155#define HDSP_RD_MULTIPLE 0x400 155#define HDSP_RD_MULTIPLE 0x400
156#define HDSP_9652_ENABLE_MIXER 0x800 156#define HDSP_9652_ENABLE_MIXER 0x800
157#define HDSP_S200 0x800
158#define HDSP_S300 (0x100 | HDSP_S200) /* dummy, purpose of 0x100 unknown */
159#define HDSP_CYCLIC_MODE 0x1000
157#define HDSP_TDO 0x10000000 160#define HDSP_TDO 0x10000000
158 161
159#define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0) 162#define HDSP_S_PROGRAM (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
160#define HDSP_S_LOAD (HDSP_PROGRAM|HDSP_CONFIG_MODE_1) 163#define HDSP_S_LOAD (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
161 164
162/* Control Register bits */ 165/* Control Register bits */
163 166
@@ -671,13 +674,23 @@ static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
671 674
672static int hdsp_check_for_iobox (struct hdsp *hdsp) 675static int hdsp_check_for_iobox (struct hdsp *hdsp)
673{ 676{
677 int i;
678
674 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; 679 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
675 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) { 680 for (i = 0; i < 500; i++) {
676 snd_printk("Hammerfall-DSP: no IO box connected!\n"); 681 if (0 == (hdsp_read(hdsp, HDSP_statusRegister) &
677 hdsp->state &= ~HDSP_FirmwareLoaded; 682 HDSP_ConfigError)) {
678 return -EIO; 683 if (i) {
684 snd_printd("Hammerfall-DSP: IO box found after %d ms\n",
685 (20 * i));
686 }
687 return 0;
688 }
689 msleep(20);
679 } 690 }
680 return 0; 691 snd_printk(KERN_ERR "Hammerfall-DSP: no IO box connected!\n");
692 hdsp->state &= ~HDSP_FirmwareLoaded;
693 return -EIO;
681} 694}
682 695
683static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops, 696static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
@@ -728,6 +741,7 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
728 741
729 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { 742 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
730 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n"); 743 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
744 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
731 return -EIO; 745 return -EIO;
732 } 746 }
733 747
@@ -737,17 +751,15 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
737 hdsp_write(hdsp, HDSP_fifoData, cache[i]); 751 hdsp_write(hdsp, HDSP_fifoData, cache[i]);
738 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) { 752 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
739 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n"); 753 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n");
754 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
740 return -EIO; 755 return -EIO;
741 } 756 }
742 } 757 }
743 758
744 ssleep(3); 759 hdsp_fifo_wait(hdsp, 3, HDSP_LONG_WAIT);
745 760 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
746 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
747 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
748 return -EIO;
749 }
750 761
762 ssleep(3);
751#ifdef SNDRV_BIG_ENDIAN 763#ifdef SNDRV_BIG_ENDIAN
752 hdsp->control2_register = HDSP_BIGENDIAN_MODE; 764 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
753#else 765#else
@@ -773,24 +785,51 @@ static int hdsp_get_iobox_version (struct hdsp *hdsp)
773{ 785{
774 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 786 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
775 787
776 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM); 788 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
777 hdsp_write (hdsp, HDSP_fifoData, 0); 789 hdsp_write(hdsp, HDSP_fifoData, 0);
778 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
779 return -EIO;
780 790
781 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 791 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
792 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
793 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
794 }
795
796 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200 | HDSP_PROGRAM);
782 hdsp_write (hdsp, HDSP_fifoData, 0); 797 hdsp_write (hdsp, HDSP_fifoData, 0);
798 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
799 hdsp->io_type = Multiface;
800 snd_printk("Hammerfall-DSP: Multiface found\n");
801 return 0;
802 }
783 803
784 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT)) { 804 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
785 hdsp_write(hdsp, HDSP_control2Reg, HDSP_VERSION_BIT); 805 hdsp_write(hdsp, HDSP_fifoData, 0);
786 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); 806 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
787 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT))
788 hdsp->io_type = RPM;
789 else
790 hdsp->io_type = Multiface;
791 } else {
792 hdsp->io_type = Digiface; 807 hdsp->io_type = Digiface;
808 snd_printk("Hammerfall-DSP: Digiface found\n");
809 return 0;
793 } 810 }
811
812 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
813 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
814 hdsp_write(hdsp, HDSP_fifoData, 0);
815 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
816 hdsp->io_type = Multiface;
817 snd_printk("Hammerfall-DSP: Multiface found\n");
818 return 0;
819 }
820
821 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
822 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
823 hdsp_write(hdsp, HDSP_fifoData, 0);
824 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
825 hdsp->io_type = Multiface;
826 snd_printk("Hammerfall-DSP: Multiface found\n");
827 return 0;
828 }
829
830 hdsp->io_type = RPM;
831 snd_printk("Hammerfall-DSP: RPM found\n");
832 return 0;
794 } else { 833 } else {
795 /* firmware was already loaded, get iobox type */ 834 /* firmware was already loaded, get iobox type */
796 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2) 835 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
@@ -1674,171 +1713,50 @@ static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_e
1674 return change; 1713 return change;
1675} 1714}
1676 1715
1677#define HDSP_SPDIF_OUT(xname, xindex) \ 1716#define HDSP_TOGGLE_SETTING(xname, xindex) \
1678{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 1717{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1679 .info = snd_hdsp_info_spdif_bits, \ 1718 .name = xname, \
1680 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out } 1719 .private_value = xindex, \
1681 1720 .info = snd_hdsp_info_toggle_setting, \
1682static int hdsp_spdif_out(struct hdsp *hdsp) 1721 .get = snd_hdsp_get_toggle_setting, \
1683{ 1722 .put = snd_hdsp_put_toggle_setting \
1684 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1685}
1686
1687static int hdsp_set_spdif_output(struct hdsp *hdsp, int out)
1688{
1689 if (out)
1690 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1691 else
1692 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1693 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1694 return 0;
1695}
1696
1697#define snd_hdsp_info_spdif_bits snd_ctl_boolean_mono_info
1698
1699static int snd_hdsp_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1700{
1701 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1702
1703 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1704 return 0;
1705}
1706
1707static int snd_hdsp_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1708{
1709 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1710 int change;
1711 unsigned int val;
1712
1713 if (!snd_hdsp_use_is_exclusive(hdsp))
1714 return -EBUSY;
1715 val = ucontrol->value.integer.value[0] & 1;
1716 spin_lock_irq(&hdsp->lock);
1717 change = (int)val != hdsp_spdif_out(hdsp);
1718 hdsp_set_spdif_output(hdsp, val);
1719 spin_unlock_irq(&hdsp->lock);
1720 return change;
1721} 1723}
1722 1724
1723#define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \ 1725static int hdsp_toggle_setting(struct hdsp *hdsp, u32 regmask)
1724{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1725 .info = snd_hdsp_info_spdif_bits, \
1726 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1727
1728static int hdsp_spdif_professional(struct hdsp *hdsp)
1729{ 1726{
1730 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0; 1727 return (hdsp->control_register & regmask) ? 1 : 0;
1731} 1728}
1732 1729
1733static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val) 1730static int hdsp_set_toggle_setting(struct hdsp *hdsp, u32 regmask, int out)
1734{ 1731{
1735 if (val) 1732 if (out)
1736 hdsp->control_register |= HDSP_SPDIFProfessional; 1733 hdsp->control_register |= regmask;
1737 else 1734 else
1738 hdsp->control_register &= ~HDSP_SPDIFProfessional; 1735 hdsp->control_register &= ~regmask;
1739 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1736 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1740 return 0;
1741}
1742
1743static int snd_hdsp_get_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1744{
1745 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1746 1737
1747 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1748 return 0; 1738 return 0;
1749} 1739}
1750 1740
1751static int snd_hdsp_put_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1741#define snd_hdsp_info_toggle_setting snd_ctl_boolean_mono_info
1752{
1753 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1754 int change;
1755 unsigned int val;
1756
1757 if (!snd_hdsp_use_is_exclusive(hdsp))
1758 return -EBUSY;
1759 val = ucontrol->value.integer.value[0] & 1;
1760 spin_lock_irq(&hdsp->lock);
1761 change = (int)val != hdsp_spdif_professional(hdsp);
1762 hdsp_set_spdif_professional(hdsp, val);
1763 spin_unlock_irq(&hdsp->lock);
1764 return change;
1765}
1766
1767#define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1768{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1769 .info = snd_hdsp_info_spdif_bits, \
1770 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1771 1742
1772static int hdsp_spdif_emphasis(struct hdsp *hdsp) 1743static int snd_hdsp_get_toggle_setting(struct snd_kcontrol *kcontrol,
1773{ 1744 struct snd_ctl_elem_value *ucontrol)
1774 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1775}
1776
1777static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val)
1778{
1779 if (val)
1780 hdsp->control_register |= HDSP_SPDIFEmphasis;
1781 else
1782 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1783 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1784 return 0;
1785}
1786
1787static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1788{ 1745{
1789 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1746 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1747 u32 regmask = kcontrol->private_value;
1790 1748
1791 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1792 return 0;
1793}
1794
1795static int snd_hdsp_put_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1796{
1797 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1798 int change;
1799 unsigned int val;
1800
1801 if (!snd_hdsp_use_is_exclusive(hdsp))
1802 return -EBUSY;
1803 val = ucontrol->value.integer.value[0] & 1;
1804 spin_lock_irq(&hdsp->lock); 1749 spin_lock_irq(&hdsp->lock);
1805 change = (int)val != hdsp_spdif_emphasis(hdsp); 1750 ucontrol->value.integer.value[0] = hdsp_toggle_setting(hdsp, regmask);
1806 hdsp_set_spdif_emphasis(hdsp, val);
1807 spin_unlock_irq(&hdsp->lock); 1751 spin_unlock_irq(&hdsp->lock);
1808 return change;
1809}
1810
1811#define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1812{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1813 .info = snd_hdsp_info_spdif_bits, \
1814 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1815
1816static int hdsp_spdif_nonaudio(struct hdsp *hdsp)
1817{
1818 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1819}
1820
1821static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val)
1822{
1823 if (val)
1824 hdsp->control_register |= HDSP_SPDIFNonAudio;
1825 else
1826 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1827 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1828 return 0;
1829}
1830
1831static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1832{
1833 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1834
1835 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1836 return 0; 1752 return 0;
1837} 1753}
1838 1754
1839static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1755static int snd_hdsp_put_toggle_setting(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1840{ 1757{
1841 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1758 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1759 u32 regmask = kcontrol->private_value;
1842 int change; 1760 int change;
1843 unsigned int val; 1761 unsigned int val;
1844 1762
@@ -1846,8 +1764,9 @@ static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd
1846 return -EBUSY; 1764 return -EBUSY;
1847 val = ucontrol->value.integer.value[0] & 1; 1765 val = ucontrol->value.integer.value[0] & 1;
1848 spin_lock_irq(&hdsp->lock); 1766 spin_lock_irq(&hdsp->lock);
1849 change = (int)val != hdsp_spdif_nonaudio(hdsp); 1767 change = (int) val != hdsp_toggle_setting(hdsp, regmask);
1850 hdsp_set_spdif_nonaudio(hdsp, val); 1768 if (change)
1769 hdsp_set_toggle_setting(hdsp, regmask, val);
1851 spin_unlock_irq(&hdsp->lock); 1770 spin_unlock_irq(&hdsp->lock);
1852 return change; 1771 return change;
1853} 1772}
@@ -2451,114 +2370,6 @@ static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl
2451 return change; 2370 return change;
2452} 2371}
2453 2372
2454#define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2455{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2456 .name = xname, \
2457 .index = xindex, \
2458 .info = snd_hdsp_info_xlr_breakout_cable, \
2459 .get = snd_hdsp_get_xlr_breakout_cable, \
2460 .put = snd_hdsp_put_xlr_breakout_cable \
2461}
2462
2463static int hdsp_xlr_breakout_cable(struct hdsp *hdsp)
2464{
2465 if (hdsp->control_register & HDSP_XLRBreakoutCable)
2466 return 1;
2467 return 0;
2468}
2469
2470static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)
2471{
2472 if (mode)
2473 hdsp->control_register |= HDSP_XLRBreakoutCable;
2474 else
2475 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2476 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2477 return 0;
2478}
2479
2480#define snd_hdsp_info_xlr_breakout_cable snd_ctl_boolean_mono_info
2481
2482static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2483{
2484 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2485
2486 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2487 return 0;
2488}
2489
2490static int snd_hdsp_put_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2491{
2492 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2493 int change;
2494 int val;
2495
2496 if (!snd_hdsp_use_is_exclusive(hdsp))
2497 return -EBUSY;
2498 val = ucontrol->value.integer.value[0] & 1;
2499 spin_lock_irq(&hdsp->lock);
2500 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2501 hdsp_set_xlr_breakout_cable(hdsp, val);
2502 spin_unlock_irq(&hdsp->lock);
2503 return change;
2504}
2505
2506/* (De)activates old RME Analog Extension Board
2507 These are connected to the internal ADAT connector
2508 Switching this on desactivates external ADAT
2509*/
2510#define HDSP_AEB(xname, xindex) \
2511{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2512 .name = xname, \
2513 .index = xindex, \
2514 .info = snd_hdsp_info_aeb, \
2515 .get = snd_hdsp_get_aeb, \
2516 .put = snd_hdsp_put_aeb \
2517}
2518
2519static int hdsp_aeb(struct hdsp *hdsp)
2520{
2521 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
2522 return 1;
2523 return 0;
2524}
2525
2526static int hdsp_set_aeb(struct hdsp *hdsp, int mode)
2527{
2528 if (mode)
2529 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2530 else
2531 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2532 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2533 return 0;
2534}
2535
2536#define snd_hdsp_info_aeb snd_ctl_boolean_mono_info
2537
2538static int snd_hdsp_get_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2539{
2540 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2541
2542 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2543 return 0;
2544}
2545
2546static int snd_hdsp_put_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2547{
2548 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2549 int change;
2550 int val;
2551
2552 if (!snd_hdsp_use_is_exclusive(hdsp))
2553 return -EBUSY;
2554 val = ucontrol->value.integer.value[0] & 1;
2555 spin_lock_irq(&hdsp->lock);
2556 change = (int)val != hdsp_aeb(hdsp);
2557 hdsp_set_aeb(hdsp, val);
2558 spin_unlock_irq(&hdsp->lock);
2559 return change;
2560}
2561
2562#define HDSP_PREF_SYNC_REF(xname, xindex) \ 2373#define HDSP_PREF_SYNC_REF(xname, xindex) \
2563{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 2374{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2564 .name = xname, \ 2375 .name = xname, \
@@ -2747,58 +2558,6 @@ static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_c
2747 return 0; 2558 return 0;
2748} 2559}
2749 2560
2750#define HDSP_LINE_OUT(xname, xindex) \
2751{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2752 .name = xname, \
2753 .index = xindex, \
2754 .info = snd_hdsp_info_line_out, \
2755 .get = snd_hdsp_get_line_out, \
2756 .put = snd_hdsp_put_line_out \
2757}
2758
2759static int hdsp_line_out(struct hdsp *hdsp)
2760{
2761 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2762}
2763
2764static int hdsp_set_line_output(struct hdsp *hdsp, int out)
2765{
2766 if (out)
2767 hdsp->control_register |= HDSP_LineOut;
2768 else
2769 hdsp->control_register &= ~HDSP_LineOut;
2770 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2771 return 0;
2772}
2773
2774#define snd_hdsp_info_line_out snd_ctl_boolean_mono_info
2775
2776static int snd_hdsp_get_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2777{
2778 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2779
2780 spin_lock_irq(&hdsp->lock);
2781 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2782 spin_unlock_irq(&hdsp->lock);
2783 return 0;
2784}
2785
2786static int snd_hdsp_put_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2787{
2788 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2789 int change;
2790 unsigned int val;
2791
2792 if (!snd_hdsp_use_is_exclusive(hdsp))
2793 return -EBUSY;
2794 val = ucontrol->value.integer.value[0] & 1;
2795 spin_lock_irq(&hdsp->lock);
2796 change = (int)val != hdsp_line_out(hdsp);
2797 hdsp_set_line_output(hdsp, val);
2798 spin_unlock_irq(&hdsp->lock);
2799 return change;
2800}
2801
2802#define HDSP_PRECISE_POINTER(xname, xindex) \ 2561#define HDSP_PRECISE_POINTER(xname, xindex) \
2803{ .iface = SNDRV_CTL_ELEM_IFACE_CARD, \ 2562{ .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2804 .name = xname, \ 2563 .name = xname, \
@@ -3190,7 +2949,7 @@ static struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
3190HDSP_DA_GAIN("DA Gain", 0), 2949HDSP_DA_GAIN("DA Gain", 0),
3191HDSP_AD_GAIN("AD Gain", 0), 2950HDSP_AD_GAIN("AD Gain", 0),
3192HDSP_PHONE_GAIN("Phones Gain", 0), 2951HDSP_PHONE_GAIN("Phones Gain", 0),
3193HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0), 2952HDSP_TOGGLE_SETTING("XLR Breakout Cable", HDSP_XLRBreakoutCable),
3194HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0) 2953HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
3195}; 2954};
3196 2955
@@ -3232,10 +2991,10 @@ static struct snd_kcontrol_new snd_hdsp_controls[] = {
3232}, 2991},
3233HDSP_MIXER("Mixer", 0), 2992HDSP_MIXER("Mixer", 0),
3234HDSP_SPDIF_IN("IEC958 Input Connector", 0), 2993HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3235HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0), 2994HDSP_TOGGLE_SETTING("IEC958 Output also on ADAT1", HDSP_SPDIFOpticalOut),
3236HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0), 2995HDSP_TOGGLE_SETTING("IEC958 Professional Bit", HDSP_SPDIFProfessional),
3237HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0), 2996HDSP_TOGGLE_SETTING("IEC958 Emphasis Bit", HDSP_SPDIFEmphasis),
3238HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0), 2997HDSP_TOGGLE_SETTING("IEC958 Non-audio Bit", HDSP_SPDIFNonAudio),
3239/* 'Sample Clock Source' complies with the alsa control naming scheme */ 2998/* 'Sample Clock Source' complies with the alsa control naming scheme */
3240HDSP_CLOCK_SOURCE("Sample Clock Source", 0), 2999HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3241{ 3000{
@@ -3255,7 +3014,7 @@ HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3255HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0), 3014HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3256HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0), 3015HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3257HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0), 3016HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3258HDSP_LINE_OUT("Line Out", 0), 3017HDSP_TOGGLE_SETTING("Line Out", HDSP_LineOut),
3259HDSP_PRECISE_POINTER("Precise Pointer", 0), 3018HDSP_PRECISE_POINTER("Precise Pointer", 0),
3260HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0), 3019HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
3261}; 3020};
@@ -3572,7 +3331,9 @@ static struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
3572 HDSP_MIXER("Mixer", 0) 3331 HDSP_MIXER("Mixer", 0)
3573}; 3332};
3574 3333
3575static struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0); 3334static struct snd_kcontrol_new snd_hdsp_96xx_aeb =
3335 HDSP_TOGGLE_SETTING("Analog Extension Board",
3336 HDSP_AnalogExtensionBoard);
3576static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK; 3337static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3577 3338
3578static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp) 3339static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
@@ -3995,7 +3756,9 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3995 } 3756 }
3996 snd_iprintf(buffer, "Phones Gain : %s\n", tmp); 3757 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3997 3758
3998 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no"); 3759 snd_iprintf(buffer, "XLR Breakout Cable : %s\n",
3760 hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable) ?
3761 "yes" : "no");
3999 3762
4000 if (hdsp->control_register & HDSP_AnalogExtensionBoard) 3763 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
4001 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n"); 3764 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
@@ -5026,29 +4789,38 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
5026 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i) 4789 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i)
5027 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); 4790 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
5028 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 4791 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
5029 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp); 4792 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp,
5030 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp); 4793 HDSP_SPDIFOpticalOut);
5031 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp); 4794 info.spdif_professional = (unsigned char)
5032 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp); 4795 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional);
4796 info.spdif_emphasis = (unsigned char)
4797 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis);
4798 info.spdif_nonaudio = (unsigned char)
4799 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio);
5033 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp); 4800 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
5034 info.system_sample_rate = hdsp->system_sample_rate; 4801 info.system_sample_rate = hdsp->system_sample_rate;
5035 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp); 4802 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
5036 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp); 4803 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
5037 info.clock_source = (unsigned char)hdsp_clock_source(hdsp); 4804 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
5038 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp); 4805 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
5039 info.line_out = (unsigned char)hdsp_line_out(hdsp); 4806 info.line_out = (unsigned char)
4807 hdsp_toggle_setting(hdsp, HDSP_LineOut);
5040 if (hdsp->io_type == H9632) { 4808 if (hdsp->io_type == H9632) {
5041 info.da_gain = (unsigned char)hdsp_da_gain(hdsp); 4809 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
5042 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp); 4810 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
5043 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp); 4811 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
5044 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp); 4812 info.xlr_breakout_cable =
4813 (unsigned char)hdsp_toggle_setting(hdsp,
4814 HDSP_XLRBreakoutCable);
5045 4815
5046 } else if (hdsp->io_type == RPM) { 4816 } else if (hdsp->io_type == RPM) {
5047 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp); 4817 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp);
5048 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp); 4818 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp);
5049 } 4819 }
5050 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) 4820 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
5051 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp); 4821 info.analog_extension_board =
4822 (unsigned char)hdsp_toggle_setting(hdsp,
4823 HDSP_AnalogExtensionBoard);
5052 spin_unlock_irqrestore(&hdsp->lock, flags); 4824 spin_unlock_irqrestore(&hdsp->lock, flags);
5053 if (copy_to_user(argp, &info, sizeof(info))) 4825 if (copy_to_user(argp, &info, sizeof(info)))
5054 return -EFAULT; 4826 return -EFAULT;
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 6442f611a07b..d756a3562706 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -2517,7 +2517,7 @@ static int check_dxs_list(struct pci_dev *pci, int revision)
2517 w = snd_pci_quirk_lookup(pci, dxs_whitelist); 2517 w = snd_pci_quirk_lookup(pci, dxs_whitelist);
2518 if (w) { 2518 if (w) {
2519 snd_printdd(KERN_INFO "via82xx: DXS white list for %s found\n", 2519 snd_printdd(KERN_INFO "via82xx: DXS white list for %s found\n",
2520 w->name); 2520 snd_pci_quirk_name(w));
2521 return w->value; 2521 return w->value;
2522 } 2522 }
2523 2523
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index d1b691bf8e2d..3fdd87fa18a9 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -1,6 +1,6 @@
1config SND_ATMEL_SOC 1config SND_ATMEL_SOC
2 tristate "SoC Audio for the Atmel System-on-Chip" 2 tristate "SoC Audio for the Atmel System-on-Chip"
3 depends on ARCH_AT91 3 depends on HAS_IOMEM
4 help 4 help
5 Say Y or M if you want to add support for codecs attached to 5 Say Y or M if you want to add support for codecs attached to
6 the ATMEL SSC interface. You will also need 6 the ATMEL SSC interface. You will also need
@@ -24,7 +24,7 @@ config SND_ATMEL_SOC_SSC
24 24
25config SND_AT91_SOC_SAM9G20_WM8731 25config SND_AT91_SOC_SAM9G20_WM8731
26 tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board" 26 tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board"
27 depends on ATMEL_SSC && SND_ATMEL_SOC && AT91_PROGRAMMABLE_CLOCKS 27 depends on ARCH_AT91 && ATMEL_SSC && SND_ATMEL_SOC && AT91_PROGRAMMABLE_CLOCKS
28 select SND_ATMEL_SOC_PDC 28 select SND_ATMEL_SOC_PDC
29 select SND_ATMEL_SOC_SSC 29 select SND_ATMEL_SOC_SSC
30 select SND_SOC_WM8731 30 select SND_SOC_WM8731
@@ -34,7 +34,7 @@ config SND_AT91_SOC_SAM9G20_WM8731
34 34
35config SND_AT91_SOC_AFEB9260 35config SND_AT91_SOC_AFEB9260
36 tristate "SoC Audio support for AFEB9260 board" 36 tristate "SoC Audio support for AFEB9260 board"
37 depends on ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC 37 depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC
38 select SND_ATMEL_SOC_PDC 38 select SND_ATMEL_SOC_PDC
39 select SND_ATMEL_SOC_SSC 39 select SND_ATMEL_SOC_SSC
40 select SND_SOC_TLV320AIC23 40 select SND_SOC_TLV320AIC23
diff --git a/sound/soc/atmel/atmel-pcm-pdc.c b/sound/soc/atmel/atmel-pcm-pdc.c
index 6a293c713a38..054ea4d9326a 100644
--- a/sound/soc/atmel/atmel-pcm-pdc.c
+++ b/sound/soc/atmel/atmel-pcm-pdc.c
@@ -159,7 +159,7 @@ static int atmel_pcm_hw_params(struct snd_pcm_substream *substream,
159 159
160 pr_debug("atmel-pcm: " 160 pr_debug("atmel-pcm: "
161 "hw_params: DMA for %s initialized " 161 "hw_params: DMA for %s initialized "
162 "(dma_bytes=%u, period_size=%u)\n", 162 "(dma_bytes=%zu, period_size=%zu)\n",
163 prtd->params->name, 163 prtd->params->name,
164 runtime->dma_bytes, 164 runtime->dma_bytes,
165 prtd->period_size); 165 prtd->period_size);
@@ -201,7 +201,7 @@ static int atmel_pcm_trigger(struct snd_pcm_substream *substream,
201 int ret = 0; 201 int ret = 0;
202 202
203 pr_debug("atmel-pcm:buffer_size = %ld," 203 pr_debug("atmel-pcm:buffer_size = %ld,"
204 "dma_area = %p, dma_bytes = %u\n", 204 "dma_area = %p, dma_bytes = %zu\n",
205 rtd->buffer_size, rtd->dma_area, rtd->dma_bytes); 205 rtd->buffer_size, rtd->dma_area, rtd->dma_bytes);
206 206
207 switch (cmd) { 207 switch (cmd) {
diff --git a/sound/soc/atmel/atmel-pcm.c b/sound/soc/atmel/atmel-pcm.c
index e99f1811300a..3109db7b9017 100644
--- a/sound/soc/atmel/atmel-pcm.c
+++ b/sound/soc/atmel/atmel-pcm.c
@@ -49,7 +49,7 @@ static int atmel_pcm_preallocate_dma_buffer(struct snd_pcm *pcm,
49 buf->private_data = NULL; 49 buf->private_data = NULL;
50 buf->area = dma_alloc_coherent(pcm->card->dev, size, 50 buf->area = dma_alloc_coherent(pcm->card->dev, size,
51 &buf->addr, GFP_KERNEL); 51 &buf->addr, GFP_KERNEL);
52 pr_debug("atmel-pcm: alloc dma buffer: area=%p, addr=%p, size=%d\n", 52 pr_debug("atmel-pcm: alloc dma buffer: area=%p, addr=%p, size=%zu\n",
53 (void *)buf->area, (void *)buf->addr, size); 53 (void *)buf->area, (void *)buf->addr, size);
54 54
55 if (!buf->area) 55 if (!buf->area)
diff --git a/sound/soc/atmel/atmel-pcm.h b/sound/soc/atmel/atmel-pcm.h
index bb45d20e7250..12ae814eff21 100644
--- a/sound/soc/atmel/atmel-pcm.h
+++ b/sound/soc/atmel/atmel-pcm.h
@@ -88,7 +88,8 @@ void atmel_pcm_free(struct snd_pcm *pcm);
88int atmel_pcm_mmap(struct snd_pcm_substream *substream, 88int atmel_pcm_mmap(struct snd_pcm_substream *substream,
89 struct vm_area_struct *vma); 89 struct vm_area_struct *vma);
90 90
91#ifdef CONFIG_SND_ATMEL_SOC_PDC 91#if defined(CONFIG_SND_ATMEL_SOC_PDC) || \
92 defined(CONFIG_SND_ATMEL_SOC_PDC_MODULE)
92int atmel_pcm_pdc_platform_register(struct device *dev); 93int atmel_pcm_pdc_platform_register(struct device *dev);
93void atmel_pcm_pdc_platform_unregister(struct device *dev); 94void atmel_pcm_pdc_platform_unregister(struct device *dev);
94#else 95#else
@@ -101,7 +102,8 @@ static inline void atmel_pcm_pdc_platform_unregister(struct device *dev)
101} 102}
102#endif 103#endif
103 104
104#ifdef CONFIG_SND_ATMEL_SOC_DMA 105#if defined(CONFIG_SND_ATMEL_SOC_DMA) || \
106 defined(CONFIG_SND_ATMEL_SOC_DMA_MODULE)
105int atmel_pcm_dma_platform_register(struct device *dev); 107int atmel_pcm_dma_platform_register(struct device *dev);
106void atmel_pcm_dma_platform_unregister(struct device *dev); 108void atmel_pcm_dma_platform_unregister(struct device *dev);
107#else 109#else
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index 1c7663422054..e13580d6c476 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -42,8 +42,6 @@
42#include <sound/initval.h> 42#include <sound/initval.h>
43#include <sound/soc.h> 43#include <sound/soc.h>
44 44
45#include <mach/hardware.h>
46
47#include "atmel-pcm.h" 45#include "atmel-pcm.h"
48#include "atmel_ssc_dai.h" 46#include "atmel_ssc_dai.h"
49 47
@@ -679,15 +677,6 @@ static int atmel_ssc_resume(struct snd_soc_dai *cpu_dai)
679# define atmel_ssc_resume NULL 677# define atmel_ssc_resume NULL
680#endif /* CONFIG_PM */ 678#endif /* CONFIG_PM */
681 679
682static int atmel_ssc_probe(struct snd_soc_dai *dai)
683{
684 struct atmel_ssc_info *ssc_p = &ssc_info[dai->id];
685
686 snd_soc_dai_set_drvdata(dai, ssc_p);
687
688 return 0;
689}
690
691#define ATMEL_SSC_RATES (SNDRV_PCM_RATE_8000_96000) 680#define ATMEL_SSC_RATES (SNDRV_PCM_RATE_8000_96000)
692 681
693#define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ 682#define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
@@ -703,7 +692,6 @@ static const struct snd_soc_dai_ops atmel_ssc_dai_ops = {
703}; 692};
704 693
705static struct snd_soc_dai_driver atmel_ssc_dai = { 694static struct snd_soc_dai_driver atmel_ssc_dai = {
706 .probe = atmel_ssc_probe,
707 .suspend = atmel_ssc_suspend, 695 .suspend = atmel_ssc_suspend,
708 .resume = atmel_ssc_resume, 696 .resume = atmel_ssc_resume,
709 .playback = { 697 .playback = {
@@ -790,8 +778,8 @@ void atmel_ssc_put_audio(int ssc_id)
790{ 778{
791 struct ssc_device *ssc = ssc_info[ssc_id].ssc; 779 struct ssc_device *ssc = ssc_info[ssc_id].ssc;
792 780
793 ssc_free(ssc);
794 asoc_ssc_exit(&ssc->pdev->dev); 781 asoc_ssc_exit(&ssc->pdev->dev);
782 ssc_free(ssc);
795} 783}
796EXPORT_SYMBOL_GPL(atmel_ssc_put_audio); 784EXPORT_SYMBOL_GPL(atmel_ssc_put_audio);
797 785
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index da976291da9e..2d6fbd0125b9 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -305,10 +305,10 @@ static int at91sam9g20ek_audio_remove(struct platform_device *pdev)
305{ 305{
306 struct snd_soc_card *card = platform_get_drvdata(pdev); 306 struct snd_soc_card *card = platform_get_drvdata(pdev);
307 307
308 atmel_ssc_put_audio(0); 308 clk_disable(mclk);
309 snd_soc_unregister_card(card);
310 clk_put(mclk);
311 mclk = NULL; 309 mclk = NULL;
310 snd_soc_unregister_card(card);
311 atmel_ssc_put_audio(0);
312 312
313 return 0; 313 return 0;
314} 314}
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 3a847828932a..133025fbb6d4 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -36,6 +36,7 @@ config SND_SOC_ALL_CODECS
36 select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI 36 select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI
37 select SND_SOC_CX20442 37 select SND_SOC_CX20442
38 select SND_SOC_DA7210 if I2C 38 select SND_SOC_DA7210 if I2C
39 select SND_SOC_DA7213 if I2C
39 select SND_SOC_DA732X if I2C 40 select SND_SOC_DA732X if I2C
40 select SND_SOC_DA9055 if I2C 41 select SND_SOC_DA9055 if I2C
41 select SND_SOC_DFBMCS320 42 select SND_SOC_DFBMCS320
@@ -98,7 +99,7 @@ config SND_SOC_ALL_CODECS
98 select SND_SOC_WM8782 99 select SND_SOC_WM8782
99 select SND_SOC_WM8804 if SND_SOC_I2C_AND_SPI 100 select SND_SOC_WM8804 if SND_SOC_I2C_AND_SPI
100 select SND_SOC_WM8900 if I2C 101 select SND_SOC_WM8900 if I2C
101 select SND_SOC_WM8903 if I2C 102 select SND_SOC_WM8903 if I2C && GENERIC_HARDIRQS
102 select SND_SOC_WM8904 if I2C 103 select SND_SOC_WM8904 if I2C
103 select SND_SOC_WM8940 if I2C 104 select SND_SOC_WM8940 if I2C
104 select SND_SOC_WM8955 if I2C 105 select SND_SOC_WM8955 if I2C
@@ -247,6 +248,9 @@ config SND_SOC_L3
247config SND_SOC_DA7210 248config SND_SOC_DA7210
248 tristate 249 tristate
249 250
251config SND_SOC_DA7213
252 tristate
253
250config SND_SOC_DA732X 254config SND_SOC_DA732X
251 tristate 255 tristate
252 256
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index f6e8e36cceb7..6a3b3c3b8b41 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -23,6 +23,7 @@ snd-soc-cs4270-objs := cs4270.o
23snd-soc-cs4271-objs := cs4271.o 23snd-soc-cs4271-objs := cs4271.o
24snd-soc-cx20442-objs := cx20442.o 24snd-soc-cx20442-objs := cx20442.o
25snd-soc-da7210-objs := da7210.o 25snd-soc-da7210-objs := da7210.o
26snd-soc-da7213-objs := da7213.o
26snd-soc-da732x-objs := da732x.o 27snd-soc-da732x-objs := da732x.o
27snd-soc-da9055-objs := da9055.o 28snd-soc-da9055-objs := da9055.o
28snd-soc-dfbmcs320-objs := dfbmcs320.o 29snd-soc-dfbmcs320-objs := dfbmcs320.o
@@ -147,6 +148,7 @@ obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
147obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o 148obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o
148obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o 149obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o
149obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o 150obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o
151obj-$(CONFIG_SND_SOC_DA7213) += snd-soc-da7213.o
150obj-$(CONFIG_SND_SOC_DA732X) += snd-soc-da732x.o 152obj-$(CONFIG_SND_SOC_DA732X) += snd-soc-da732x.o
151obj-$(CONFIG_SND_SOC_DA9055) += snd-soc-da9055.o 153obj-$(CONFIG_SND_SOC_DA9055) += snd-soc-da9055.o
152obj-$(CONFIG_SND_SOC_DFBMCS320) += snd-soc-dfbmcs320.o 154obj-$(CONFIG_SND_SOC_DFBMCS320) += snd-soc-dfbmcs320.o
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 1f0cdab03294..2d0378709702 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/of_device.h>
29#include <linux/module.h> 30#include <linux/module.h>
30#include <sound/soc.h> 31#include <sound/soc.h>
31#include <sound/initval.h> 32#include <sound/initval.h>
@@ -513,12 +514,31 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4648 = {
513}; 514};
514 515
515#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 516#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
517static struct of_device_id ak4642_of_match[];
516static int ak4642_i2c_probe(struct i2c_client *i2c, 518static int ak4642_i2c_probe(struct i2c_client *i2c,
517 const struct i2c_device_id *id) 519 const struct i2c_device_id *id)
518{ 520{
521 struct device_node *np = i2c->dev.of_node;
522 const struct snd_soc_codec_driver *driver;
523
524 driver = NULL;
525 if (np) {
526 const struct of_device_id *of_id;
527
528 of_id = of_match_device(ak4642_of_match, &i2c->dev);
529 if (of_id)
530 driver = of_id->data;
531 } else {
532 driver = (struct snd_soc_codec_driver *)id->driver_data;
533 }
534
535 if (!driver) {
536 dev_err(&i2c->dev, "no driver\n");
537 return -EINVAL;
538 }
539
519 return snd_soc_register_codec(&i2c->dev, 540 return snd_soc_register_codec(&i2c->dev,
520 (struct snd_soc_codec_driver *)id->driver_data, 541 driver, &ak4642_dai, 1);
521 &ak4642_dai, 1);
522} 542}
523 543
524static int ak4642_i2c_remove(struct i2c_client *client) 544static int ak4642_i2c_remove(struct i2c_client *client)
@@ -527,6 +547,14 @@ static int ak4642_i2c_remove(struct i2c_client *client)
527 return 0; 547 return 0;
528} 548}
529 549
550static struct of_device_id ak4642_of_match[] = {
551 { .compatible = "asahi-kasei,ak4642", .data = &soc_codec_dev_ak4642},
552 { .compatible = "asahi-kasei,ak4643", .data = &soc_codec_dev_ak4642},
553 { .compatible = "asahi-kasei,ak4648", .data = &soc_codec_dev_ak4648},
554 {},
555};
556MODULE_DEVICE_TABLE(of, ak4642_of_match);
557
530static const struct i2c_device_id ak4642_i2c_id[] = { 558static const struct i2c_device_id ak4642_i2c_id[] = {
531 { "ak4642", (kernel_ulong_t)&soc_codec_dev_ak4642 }, 559 { "ak4642", (kernel_ulong_t)&soc_codec_dev_ak4642 },
532 { "ak4643", (kernel_ulong_t)&soc_codec_dev_ak4642 }, 560 { "ak4643", (kernel_ulong_t)&soc_codec_dev_ak4642 },
@@ -539,6 +567,7 @@ static struct i2c_driver ak4642_i2c_driver = {
539 .driver = { 567 .driver = {
540 .name = "ak4642-codec", 568 .name = "ak4642-codec",
541 .owner = THIS_MODULE, 569 .owner = THIS_MODULE,
570 .of_match_table = ak4642_of_match,
542 }, 571 },
543 .probe = ak4642_i2c_probe, 572 .probe = ak4642_i2c_probe,
544 .remove = ak4642_i2c_remove, 573 .remove = ak4642_i2c_remove,
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index ef62c435848e..ac948a671ea6 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -56,14 +56,14 @@
56#define arizona_fll_warn(_fll, fmt, ...) \ 56#define arizona_fll_warn(_fll, fmt, ...) \
57 dev_warn(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__) 57 dev_warn(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
58#define arizona_fll_dbg(_fll, fmt, ...) \ 58#define arizona_fll_dbg(_fll, fmt, ...) \
59 dev_err(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__) 59 dev_dbg(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
60 60
61#define arizona_aif_err(_dai, fmt, ...) \ 61#define arizona_aif_err(_dai, fmt, ...) \
62 dev_err(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__) 62 dev_err(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
63#define arizona_aif_warn(_dai, fmt, ...) \ 63#define arizona_aif_warn(_dai, fmt, ...) \
64 dev_warn(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__) 64 dev_warn(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
65#define arizona_aif_dbg(_dai, fmt, ...) \ 65#define arizona_aif_dbg(_dai, fmt, ...) \
66 dev_err(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__) 66 dev_dbg(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
67 67
68const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS] = { 68const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS] = {
69 "None", 69 "None",
@@ -141,6 +141,30 @@ const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS] = {
141 "ASRC1R", 141 "ASRC1R",
142 "ASRC2L", 142 "ASRC2L",
143 "ASRC2R", 143 "ASRC2R",
144 "ISRC1INT1",
145 "ISRC1INT2",
146 "ISRC1INT3",
147 "ISRC1INT4",
148 "ISRC1DEC1",
149 "ISRC1DEC2",
150 "ISRC1DEC3",
151 "ISRC1DEC4",
152 "ISRC2INT1",
153 "ISRC2INT2",
154 "ISRC2INT3",
155 "ISRC2INT4",
156 "ISRC2DEC1",
157 "ISRC2DEC2",
158 "ISRC2DEC3",
159 "ISRC2DEC4",
160 "ISRC3INT1",
161 "ISRC3INT2",
162 "ISRC3INT3",
163 "ISRC3INT4",
164 "ISRC3DEC1",
165 "ISRC3DEC2",
166 "ISRC3DEC3",
167 "ISRC3DEC4",
144}; 168};
145EXPORT_SYMBOL_GPL(arizona_mixer_texts); 169EXPORT_SYMBOL_GPL(arizona_mixer_texts);
146 170
@@ -220,6 +244,30 @@ int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS] = {
220 0x91, 244 0x91,
221 0x92, 245 0x92,
222 0x93, 246 0x93,
247 0xa0, /* ISRC1INT1 */
248 0xa1,
249 0xa2,
250 0xa3,
251 0xa4, /* ISRC1DEC1 */
252 0xa5,
253 0xa6,
254 0xa7,
255 0xa8, /* ISRC2DEC1 */
256 0xa9,
257 0xaa,
258 0xab,
259 0xac, /* ISRC2INT1 */
260 0xad,
261 0xae,
262 0xaf,
263 0xb0, /* ISRC3DEC1 */
264 0xb1,
265 0xb2,
266 0xb3,
267 0xb4, /* ISRC3INT1 */
268 0xb5,
269 0xb6,
270 0xb7,
223}; 271};
224EXPORT_SYMBOL_GPL(arizona_mixer_values); 272EXPORT_SYMBOL_GPL(arizona_mixer_values);
225 273
@@ -275,9 +323,35 @@ const struct soc_enum arizona_lhpf4_mode =
275 arizona_lhpf_mode_text); 323 arizona_lhpf_mode_text);
276EXPORT_SYMBOL_GPL(arizona_lhpf4_mode); 324EXPORT_SYMBOL_GPL(arizona_lhpf4_mode);
277 325
326static const char *arizona_ng_hold_text[] = {
327 "30ms", "120ms", "250ms", "500ms",
328};
329
330const struct soc_enum arizona_ng_hold =
331 SOC_ENUM_SINGLE(ARIZONA_NOISE_GATE_CONTROL, ARIZONA_NGATE_HOLD_SHIFT,
332 4, arizona_ng_hold_text);
333EXPORT_SYMBOL_GPL(arizona_ng_hold);
334
278int arizona_in_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, 335int arizona_in_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
279 int event) 336 int event)
280{ 337{
338 unsigned int reg;
339
340 if (w->shift % 2)
341 reg = ARIZONA_ADC_DIGITAL_VOLUME_1L + ((w->shift / 2) * 8);
342 else
343 reg = ARIZONA_ADC_DIGITAL_VOLUME_1R + ((w->shift / 2) * 8);
344
345 switch (event) {
346 case SND_SOC_DAPM_POST_PMU:
347 snd_soc_update_bits(w->codec, reg, ARIZONA_IN1L_MUTE, 0);
348 break;
349 case SND_SOC_DAPM_PRE_PMD:
350 snd_soc_update_bits(w->codec, reg, ARIZONA_IN1L_MUTE,
351 ARIZONA_IN1L_MUTE);
352 break;
353 }
354
281 return 0; 355 return 0;
282} 356}
283EXPORT_SYMBOL_GPL(arizona_in_ev); 357EXPORT_SYMBOL_GPL(arizona_in_ev);
@@ -417,6 +491,10 @@ int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
417 case 147456000: 491 case 147456000:
418 val |= 6 << ARIZONA_SYSCLK_FREQ_SHIFT; 492 val |= 6 << ARIZONA_SYSCLK_FREQ_SHIFT;
419 break; 493 break;
494 case 0:
495 dev_dbg(arizona->dev, "%s cleared\n", name);
496 *clk = freq;
497 return 0;
420 default: 498 default:
421 return -EINVAL; 499 return -EINVAL;
422 } 500 }
@@ -635,6 +713,9 @@ static int arizona_startup(struct snd_pcm_substream *substream,
635 return 0; 713 return 0;
636 } 714 }
637 715
716 if (base_rate == 0)
717 return 0;
718
638 if (base_rate % 8000) 719 if (base_rate % 8000)
639 constraint = &arizona_44k1_constraint; 720 constraint = &arizona_44k1_constraint;
640 else 721 else
@@ -645,25 +726,81 @@ static int arizona_startup(struct snd_pcm_substream *substream,
645 constraint); 726 constraint);
646} 727}
647 728
729static int arizona_hw_params_rate(struct snd_pcm_substream *substream,
730 struct snd_pcm_hw_params *params,
731 struct snd_soc_dai *dai)
732{
733 struct snd_soc_codec *codec = dai->codec;
734 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
735 struct arizona_dai_priv *dai_priv = &priv->dai[dai->id - 1];
736 int base = dai->driver->base;
737 int i, sr_val;
738
739 /*
740 * We will need to be more flexible than this in future,
741 * currently we use a single sample rate for SYSCLK.
742 */
743 for (i = 0; i < ARRAY_SIZE(arizona_sr_vals); i++)
744 if (arizona_sr_vals[i] == params_rate(params))
745 break;
746 if (i == ARRAY_SIZE(arizona_sr_vals)) {
747 arizona_aif_err(dai, "Unsupported sample rate %dHz\n",
748 params_rate(params));
749 return -EINVAL;
750 }
751 sr_val = i;
752
753 switch (dai_priv->clk) {
754 case ARIZONA_CLK_SYSCLK:
755 snd_soc_update_bits(codec, ARIZONA_SAMPLE_RATE_1,
756 ARIZONA_SAMPLE_RATE_1_MASK, sr_val);
757 if (base)
758 snd_soc_update_bits(codec, base + ARIZONA_AIF_RATE_CTRL,
759 ARIZONA_AIF1_RATE_MASK, 0);
760 break;
761 case ARIZONA_CLK_ASYNCCLK:
762 snd_soc_update_bits(codec, ARIZONA_ASYNC_SAMPLE_RATE_1,
763 ARIZONA_ASYNC_SAMPLE_RATE_MASK, sr_val);
764 if (base)
765 snd_soc_update_bits(codec, base + ARIZONA_AIF_RATE_CTRL,
766 ARIZONA_AIF1_RATE_MASK,
767 8 << ARIZONA_AIF1_RATE_SHIFT);
768 break;
769 default:
770 arizona_aif_err(dai, "Invalid clock %d\n", dai_priv->clk);
771 return -EINVAL;
772 }
773
774 return 0;
775}
776
648static int arizona_hw_params(struct snd_pcm_substream *substream, 777static int arizona_hw_params(struct snd_pcm_substream *substream,
649 struct snd_pcm_hw_params *params, 778 struct snd_pcm_hw_params *params,
650 struct snd_soc_dai *dai) 779 struct snd_soc_dai *dai)
651{ 780{
652 struct snd_soc_codec *codec = dai->codec; 781 struct snd_soc_codec *codec = dai->codec;
653 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 782 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
654 struct arizona_dai_priv *dai_priv = &priv->dai[dai->id - 1]; 783 struct arizona *arizona = priv->arizona;
655 int base = dai->driver->base; 784 int base = dai->driver->base;
656 const int *rates; 785 const int *rates;
657 int i; 786 int i, ret;
658 int bclk, lrclk, wl, frame, sr_val; 787 int chan_limit = arizona->pdata.max_channels_clocked[dai->id - 1];
788 int bclk, lrclk, wl, frame, bclk_target;
659 789
660 if (params_rate(params) % 8000) 790 if (params_rate(params) % 8000)
661 rates = &arizona_44k1_bclk_rates[0]; 791 rates = &arizona_44k1_bclk_rates[0];
662 else 792 else
663 rates = &arizona_48k_bclk_rates[0]; 793 rates = &arizona_48k_bclk_rates[0];
664 794
795 bclk_target = snd_soc_params_to_bclk(params);
796 if (chan_limit && chan_limit < params_channels(params)) {
797 arizona_aif_dbg(dai, "Limiting to %d channels\n", chan_limit);
798 bclk_target /= params_channels(params);
799 bclk_target *= chan_limit;
800 }
801
665 for (i = 0; i < ARRAY_SIZE(arizona_44k1_bclk_rates); i++) { 802 for (i = 0; i < ARRAY_SIZE(arizona_44k1_bclk_rates); i++) {
666 if (rates[i] >= snd_soc_params_to_bclk(params) && 803 if (rates[i] >= bclk_target &&
667 rates[i] % params_rate(params) == 0) { 804 rates[i] % params_rate(params) == 0) {
668 bclk = i; 805 bclk = i;
669 break; 806 break;
@@ -675,16 +812,6 @@ static int arizona_hw_params(struct snd_pcm_substream *substream,
675 return -EINVAL; 812 return -EINVAL;
676 } 813 }
677 814
678 for (i = 0; i < ARRAY_SIZE(arizona_sr_vals); i++)
679 if (arizona_sr_vals[i] == params_rate(params))
680 break;
681 if (i == ARRAY_SIZE(arizona_sr_vals)) {
682 arizona_aif_err(dai, "Unsupported sample rate %dHz\n",
683 params_rate(params));
684 return -EINVAL;
685 }
686 sr_val = i;
687
688 lrclk = rates[bclk] / params_rate(params); 815 lrclk = rates[bclk] / params_rate(params);
689 816
690 arizona_aif_dbg(dai, "BCLK %dHz LRCLK %dHz\n", 817 arizona_aif_dbg(dai, "BCLK %dHz LRCLK %dHz\n",
@@ -693,28 +820,9 @@ static int arizona_hw_params(struct snd_pcm_substream *substream,
693 wl = snd_pcm_format_width(params_format(params)); 820 wl = snd_pcm_format_width(params_format(params));
694 frame = wl << ARIZONA_AIF1TX_WL_SHIFT | wl; 821 frame = wl << ARIZONA_AIF1TX_WL_SHIFT | wl;
695 822
696 /* 823 ret = arizona_hw_params_rate(substream, params, dai);
697 * We will need to be more flexible than this in future, 824 if (ret != 0)
698 * currently we use a single sample rate for SYSCLK. 825 return ret;
699 */
700 switch (dai_priv->clk) {
701 case ARIZONA_CLK_SYSCLK:
702 snd_soc_update_bits(codec, ARIZONA_SAMPLE_RATE_1,
703 ARIZONA_SAMPLE_RATE_1_MASK, sr_val);
704 snd_soc_update_bits(codec, base + ARIZONA_AIF_RATE_CTRL,
705 ARIZONA_AIF1_RATE_MASK, 0);
706 break;
707 case ARIZONA_CLK_ASYNCCLK:
708 snd_soc_update_bits(codec, ARIZONA_ASYNC_SAMPLE_RATE_1,
709 ARIZONA_ASYNC_SAMPLE_RATE_MASK, sr_val);
710 snd_soc_update_bits(codec, base + ARIZONA_AIF_RATE_CTRL,
711 ARIZONA_AIF1_RATE_MASK,
712 8 << ARIZONA_AIF1_RATE_SHIFT);
713 break;
714 default:
715 arizona_aif_err(dai, "Invalid clock %d\n", dai_priv->clk);
716 return -EINVAL;
717 }
718 826
719 snd_soc_update_bits(codec, base + ARIZONA_AIF_BCLK_CTRL, 827 snd_soc_update_bits(codec, base + ARIZONA_AIF_BCLK_CTRL,
720 ARIZONA_AIF1_BCLK_FREQ_MASK, bclk); 828 ARIZONA_AIF1_BCLK_FREQ_MASK, bclk);
@@ -789,11 +897,27 @@ static int arizona_dai_set_sysclk(struct snd_soc_dai *dai,
789 return snd_soc_dapm_sync(&codec->dapm); 897 return snd_soc_dapm_sync(&codec->dapm);
790} 898}
791 899
900static int arizona_set_tristate(struct snd_soc_dai *dai, int tristate)
901{
902 struct snd_soc_codec *codec = dai->codec;
903 int base = dai->driver->base;
904 unsigned int reg;
905
906 if (tristate)
907 reg = ARIZONA_AIF1_TRI;
908 else
909 reg = 0;
910
911 return snd_soc_update_bits(codec, base + ARIZONA_AIF_RATE_CTRL,
912 ARIZONA_AIF1_TRI, reg);
913}
914
792const struct snd_soc_dai_ops arizona_dai_ops = { 915const struct snd_soc_dai_ops arizona_dai_ops = {
793 .startup = arizona_startup, 916 .startup = arizona_startup,
794 .set_fmt = arizona_set_fmt, 917 .set_fmt = arizona_set_fmt,
795 .hw_params = arizona_hw_params, 918 .hw_params = arizona_hw_params,
796 .set_sysclk = arizona_dai_set_sysclk, 919 .set_sysclk = arizona_dai_set_sysclk,
920 .set_tristate = arizona_set_tristate,
797}; 921};
798EXPORT_SYMBOL_GPL(arizona_dai_ops); 922EXPORT_SYMBOL_GPL(arizona_dai_ops);
799 923
@@ -807,17 +931,6 @@ int arizona_init_dai(struct arizona_priv *priv, int id)
807} 931}
808EXPORT_SYMBOL_GPL(arizona_init_dai); 932EXPORT_SYMBOL_GPL(arizona_init_dai);
809 933
810static irqreturn_t arizona_fll_lock(int irq, void *data)
811{
812 struct arizona_fll *fll = data;
813
814 arizona_fll_dbg(fll, "Lock status changed\n");
815
816 complete(&fll->lock);
817
818 return IRQ_HANDLED;
819}
820
821static irqreturn_t arizona_fll_clock_ok(int irq, void *data) 934static irqreturn_t arizona_fll_clock_ok(int irq, void *data)
822{ 935{
823 struct arizona_fll *fll = data; 936 struct arizona_fll *fll = data;
@@ -910,7 +1023,7 @@ static int arizona_calc_fll(struct arizona_fll *fll,
910 1023
911 cfg->n = target / (ratio * Fref); 1024 cfg->n = target / (ratio * Fref);
912 1025
913 if (target % Fref) { 1026 if (target % (ratio * Fref)) {
914 gcd_fll = gcd(target, ratio * Fref); 1027 gcd_fll = gcd(target, ratio * Fref);
915 arizona_fll_dbg(fll, "GCD=%u\n", gcd_fll); 1028 arizona_fll_dbg(fll, "GCD=%u\n", gcd_fll);
916 1029
@@ -922,6 +1035,15 @@ static int arizona_calc_fll(struct arizona_fll *fll,
922 cfg->lambda = 0; 1035 cfg->lambda = 0;
923 } 1036 }
924 1037
1038 /* Round down to 16bit range with cost of accuracy lost.
1039 * Denominator must be bigger than numerator so we only
1040 * take care of it.
1041 */
1042 while (cfg->lambda >= (1 << 16)) {
1043 cfg->theta >>= 1;
1044 cfg->lambda >>= 1;
1045 }
1046
925 arizona_fll_dbg(fll, "N=%x THETA=%x LAMBDA=%x\n", 1047 arizona_fll_dbg(fll, "N=%x THETA=%x LAMBDA=%x\n",
926 cfg->n, cfg->theta, cfg->lambda); 1048 cfg->n, cfg->theta, cfg->lambda);
927 arizona_fll_dbg(fll, "FRATIO=%x(%d) OUTDIV=%x REFCLK_DIV=%x\n", 1049 arizona_fll_dbg(fll, "FRATIO=%x(%d) OUTDIV=%x REFCLK_DIV=%x\n",
@@ -1057,7 +1179,6 @@ int arizona_init_fll(struct arizona *arizona, int id, int base, int lock_irq,
1057{ 1179{
1058 int ret; 1180 int ret;
1059 1181
1060 init_completion(&fll->lock);
1061 init_completion(&fll->ok); 1182 init_completion(&fll->ok);
1062 1183
1063 fll->id = id; 1184 fll->id = id;
@@ -1068,13 +1189,6 @@ int arizona_init_fll(struct arizona *arizona, int id, int base, int lock_irq,
1068 snprintf(fll->clock_ok_name, sizeof(fll->clock_ok_name), 1189 snprintf(fll->clock_ok_name, sizeof(fll->clock_ok_name),
1069 "FLL%d clock OK", id); 1190 "FLL%d clock OK", id);
1070 1191
1071 ret = arizona_request_irq(arizona, lock_irq, fll->lock_name,
1072 arizona_fll_lock, fll);
1073 if (ret != 0) {
1074 dev_err(arizona->dev, "Failed to get FLL%d lock IRQ: %d\n",
1075 id, ret);
1076 }
1077
1078 ret = arizona_request_irq(arizona, ok_irq, fll->clock_ok_name, 1192 ret = arizona_request_irq(arizona, ok_irq, fll->clock_ok_name,
1079 arizona_fll_clock_ok, fll); 1193 arizona_fll_clock_ok, fll);
1080 if (ret != 0) { 1194 if (ret != 0) {
@@ -1089,6 +1203,40 @@ int arizona_init_fll(struct arizona *arizona, int id, int base, int lock_irq,
1089} 1203}
1090EXPORT_SYMBOL_GPL(arizona_init_fll); 1204EXPORT_SYMBOL_GPL(arizona_init_fll);
1091 1205
1206/**
1207 * arizona_set_output_mode - Set the mode of the specified output
1208 *
1209 * @codec: Device to configure
1210 * @output: Output number
1211 * @diff: True to set the output to differential mode
1212 *
1213 * Some systems use external analogue switches to connect more
1214 * analogue devices to the CODEC than are supported by the device. In
1215 * some systems this requires changing the switched output from single
1216 * ended to differential mode dynamically at runtime, an operation
1217 * supported using this function.
1218 *
1219 * Most systems have a single static configuration and should use
1220 * platform data instead.
1221 */
1222int arizona_set_output_mode(struct snd_soc_codec *codec, int output, bool diff)
1223{
1224 unsigned int reg, val;
1225
1226 if (output < 1 || output > 6)
1227 return -EINVAL;
1228
1229 reg = ARIZONA_OUTPUT_PATH_CONFIG_1L + (output - 1) * 8;
1230
1231 if (diff)
1232 val = ARIZONA_OUT1_MONO;
1233 else
1234 val = 0;
1235
1236 return snd_soc_update_bits(codec, reg, ARIZONA_OUT1_MONO, val);
1237}
1238EXPORT_SYMBOL_GPL(arizona_set_output_mode);
1239
1092MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support"); 1240MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support");
1093MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 1241MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
1094MODULE_LICENSE("GPL"); 1242MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/arizona.h b/sound/soc/codecs/arizona.h
index 4deebeb07177..116372c91f5d 100644
--- a/sound/soc/codecs/arizona.h
+++ b/sound/soc/codecs/arizona.h
@@ -66,7 +66,7 @@ struct arizona_priv {
66 struct arizona_dai_priv dai[ARIZONA_MAX_DAI]; 66 struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
67}; 67};
68 68
69#define ARIZONA_NUM_MIXER_INPUTS 75 69#define ARIZONA_NUM_MIXER_INPUTS 99
70 70
71extern const unsigned int arizona_mixer_tlv[]; 71extern const unsigned int arizona_mixer_tlv[];
72extern const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS]; 72extern const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
@@ -176,6 +176,8 @@ extern const struct soc_enum arizona_lhpf2_mode;
176extern const struct soc_enum arizona_lhpf3_mode; 176extern const struct soc_enum arizona_lhpf3_mode;
177extern const struct soc_enum arizona_lhpf4_mode; 177extern const struct soc_enum arizona_lhpf4_mode;
178 178
179extern const struct soc_enum arizona_ng_hold;
180
179extern int arizona_in_ev(struct snd_soc_dapm_widget *w, 181extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
180 struct snd_kcontrol *kcontrol, 182 struct snd_kcontrol *kcontrol,
181 int event); 183 int event);
@@ -195,7 +197,6 @@ struct arizona_fll {
195 int id; 197 int id;
196 unsigned int base; 198 unsigned int base;
197 unsigned int vco_mult; 199 unsigned int vco_mult;
198 struct completion lock;
199 struct completion ok; 200 struct completion ok;
200 unsigned int fref; 201 unsigned int fref;
201 unsigned int fout; 202 unsigned int fout;
@@ -211,4 +212,7 @@ extern int arizona_set_fll(struct arizona_fll *fll, int source,
211 212
212extern int arizona_init_dai(struct arizona_priv *priv, int dai); 213extern int arizona_init_dai(struct arizona_priv *priv, int dai);
213 214
215int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
216 bool diff);
217
214#endif 218#endif
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
index ac8742a1f25a..2415a4118dbd 100644
--- a/sound/soc/codecs/cs4271.c
+++ b/sound/soc/codecs/cs4271.c
@@ -167,6 +167,8 @@ struct cs4271_private {
167 int gpio_nreset; 167 int gpio_nreset;
168 /* GPIO that disable serial bus, if any */ 168 /* GPIO that disable serial bus, if any */
169 int gpio_disable; 169 int gpio_disable;
170 /* enable soft reset workaround */
171 bool enable_soft_reset;
170}; 172};
171 173
172/* 174/*
@@ -325,6 +327,33 @@ static int cs4271_hw_params(struct snd_pcm_substream *substream,
325 int i, ret; 327 int i, ret;
326 unsigned int ratio, val; 328 unsigned int ratio, val;
327 329
330 if (cs4271->enable_soft_reset) {
331 /*
332 * Put the codec in soft reset and back again in case it's not
333 * currently streaming data. This way of bringing the codec in
334 * sync to the current clocks is not explicitly documented in
335 * the data sheet, but it seems to work fine, and in contrast
336 * to a read hardware reset, we don't have to sync back all
337 * registers every time.
338 */
339
340 if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
341 !dai->capture_active) ||
342 (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
343 !dai->playback_active)) {
344 ret = snd_soc_update_bits(codec, CS4271_MODE2,
345 CS4271_MODE2_PDN,
346 CS4271_MODE2_PDN);
347 if (ret < 0)
348 return ret;
349
350 ret = snd_soc_update_bits(codec, CS4271_MODE2,
351 CS4271_MODE2_PDN, 0);
352 if (ret < 0)
353 return ret;
354 }
355 }
356
328 cs4271->rate = params_rate(params); 357 cs4271->rate = params_rate(params);
329 358
330 /* Configure DAC */ 359 /* Configure DAC */
@@ -484,6 +513,10 @@ static int cs4271_probe(struct snd_soc_codec *codec)
484 if (of_get_property(codec->dev->of_node, 513 if (of_get_property(codec->dev->of_node,
485 "cirrus,amutec-eq-bmutec", NULL)) 514 "cirrus,amutec-eq-bmutec", NULL))
486 amutec_eq_bmutec = true; 515 amutec_eq_bmutec = true;
516
517 if (of_get_property(codec->dev->of_node,
518 "cirrus,enable-soft-reset", NULL))
519 cs4271->enable_soft_reset = true;
487 } 520 }
488#endif 521#endif
489 522
@@ -492,6 +525,7 @@ static int cs4271_probe(struct snd_soc_codec *codec)
492 gpio_nreset = cs4271plat->gpio_nreset; 525 gpio_nreset = cs4271plat->gpio_nreset;
493 526
494 amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec; 527 amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec;
528 cs4271->enable_soft_reset = cs4271plat->enable_soft_reset;
495 } 529 }
496 530
497 if (gpio_nreset >= 0) 531 if (gpio_nreset >= 0)
diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c
index 9811a5478c87..0f6f481cec09 100644
--- a/sound/soc/codecs/cs42l52.c
+++ b/sound/soc/codecs/cs42l52.c
@@ -1038,7 +1038,7 @@ static void cs42l52_init_beep(struct snd_soc_codec *codec)
1038 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); 1038 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
1039 int ret; 1039 int ret;
1040 1040
1041 cs42l52->beep = input_allocate_device(); 1041 cs42l52->beep = devm_input_allocate_device(codec->dev);
1042 if (!cs42l52->beep) { 1042 if (!cs42l52->beep) {
1043 dev_err(codec->dev, "Failed to allocate beep device\n"); 1043 dev_err(codec->dev, "Failed to allocate beep device\n");
1044 return; 1044 return;
@@ -1059,7 +1059,6 @@ static void cs42l52_init_beep(struct snd_soc_codec *codec)
1059 1059
1060 ret = input_register_device(cs42l52->beep); 1060 ret = input_register_device(cs42l52->beep);
1061 if (ret != 0) { 1061 if (ret != 0) {
1062 input_free_device(cs42l52->beep);
1063 cs42l52->beep = NULL; 1062 cs42l52->beep = NULL;
1064 dev_err(codec->dev, "Failed to register beep device\n"); 1063 dev_err(codec->dev, "Failed to register beep device\n");
1065 } 1064 }
@@ -1076,7 +1075,6 @@ static void cs42l52_free_beep(struct snd_soc_codec *codec)
1076 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); 1075 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
1077 1076
1078 device_remove_file(codec->dev, &dev_attr_beep); 1077 device_remove_file(codec->dev, &dev_attr_beep);
1079 input_unregister_device(cs42l52->beep);
1080 cancel_work_sync(&cs42l52->beep_work); 1078 cancel_work_sync(&cs42l52->beep_work);
1081 cs42l52->beep = NULL; 1079 cs42l52->beep = NULL;
1082 1080
diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c
new file mode 100644
index 000000000000..41230ad1c3e0
--- /dev/null
+++ b/sound/soc/codecs/da7213.c
@@ -0,0 +1,1599 @@
1/*
2 * DA7213 ALSA SoC Codec Driver
3 *
4 * Copyright (c) 2013 Dialog Semiconductor
5 *
6 * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
7 * Based on DA9055 ALSA SoC codec driver.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15#include <linux/delay.h>
16#include <linux/i2c.h>
17#include <linux/regmap.h>
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22#include <sound/soc.h>
23#include <sound/initval.h>
24#include <sound/tlv.h>
25
26#include <sound/da7213.h>
27#include "da7213.h"
28
29
30/* Gain and Volume */
31static const unsigned int aux_vol_tlv[] = {
32 TLV_DB_RANGE_HEAD(2),
33 /* -54dB */
34 0x0, 0x11, TLV_DB_SCALE_ITEM(-5400, 0, 0),
35 /* -52.5dB to 15dB */
36 0x12, 0x3f, TLV_DB_SCALE_ITEM(-5250, 150, 0)
37};
38
39static const unsigned int digital_gain_tlv[] = {
40 TLV_DB_RANGE_HEAD(2),
41 0x0, 0x07, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
42 /* -78dB to 12dB */
43 0x08, 0x7f, TLV_DB_SCALE_ITEM(-7800, 75, 0)
44};
45
46static const unsigned int alc_analog_gain_tlv[] = {
47 TLV_DB_RANGE_HEAD(2),
48 0x0, 0x0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
49 /* 0dB to 36dB */
50 0x01, 0x07, TLV_DB_SCALE_ITEM(0, 600, 0)
51};
52
53static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
54static const DECLARE_TLV_DB_SCALE(mixin_gain_tlv, -450, 150, 0);
55static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
56static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -5700, 100, 0);
57static const DECLARE_TLV_DB_SCALE(lineout_vol_tlv, -4800, 100, 0);
58static const DECLARE_TLV_DB_SCALE(alc_threshold_tlv, -9450, 150, 0);
59static const DECLARE_TLV_DB_SCALE(alc_gain_tlv, 0, 600, 0);
60
61/* ADC and DAC voice mode (8kHz) high pass cutoff value */
62static const char * const da7213_voice_hpf_corner_txt[] = {
63 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
64};
65
66static const struct soc_enum da7213_dac_voice_hpf_corner =
67 SOC_ENUM_SINGLE(DA7213_DAC_FILTERS1, DA7213_VOICE_HPF_CORNER_SHIFT,
68 DA7213_VOICE_HPF_CORNER_MAX,
69 da7213_voice_hpf_corner_txt);
70
71static const struct soc_enum da7213_adc_voice_hpf_corner =
72 SOC_ENUM_SINGLE(DA7213_ADC_FILTERS1, DA7213_VOICE_HPF_CORNER_SHIFT,
73 DA7213_VOICE_HPF_CORNER_MAX,
74 da7213_voice_hpf_corner_txt);
75
76/* ADC and DAC high pass filter cutoff value */
77static const char * const da7213_audio_hpf_corner_txt[] = {
78 "Fs/24000", "Fs/12000", "Fs/6000", "Fs/3000"
79};
80
81static const struct soc_enum da7213_dac_audio_hpf_corner =
82 SOC_ENUM_SINGLE(DA7213_DAC_FILTERS1, DA7213_AUDIO_HPF_CORNER_SHIFT,
83 DA7213_AUDIO_HPF_CORNER_MAX,
84 da7213_audio_hpf_corner_txt);
85
86static const struct soc_enum da7213_adc_audio_hpf_corner =
87 SOC_ENUM_SINGLE(DA7213_ADC_FILTERS1, DA7213_AUDIO_HPF_CORNER_SHIFT,
88 DA7213_AUDIO_HPF_CORNER_MAX,
89 da7213_audio_hpf_corner_txt);
90
91/* Gain ramping rate value */
92static const char * const da7213_gain_ramp_rate_txt[] = {
93 "nominal rate * 8", "nominal rate * 16", "nominal rate / 16",
94 "nominal rate / 32"
95};
96
97static const struct soc_enum da7213_gain_ramp_rate =
98 SOC_ENUM_SINGLE(DA7213_GAIN_RAMP_CTRL, DA7213_GAIN_RAMP_RATE_SHIFT,
99 DA7213_GAIN_RAMP_RATE_MAX, da7213_gain_ramp_rate_txt);
100
101/* DAC noise gate setup time value */
102static const char * const da7213_dac_ng_setup_time_txt[] = {
103 "256 samples", "512 samples", "1024 samples", "2048 samples"
104};
105
106static const struct soc_enum da7213_dac_ng_setup_time =
107 SOC_ENUM_SINGLE(DA7213_DAC_NG_SETUP_TIME,
108 DA7213_DAC_NG_SETUP_TIME_SHIFT,
109 DA7213_DAC_NG_SETUP_TIME_MAX,
110 da7213_dac_ng_setup_time_txt);
111
112/* DAC noise gate rampup rate value */
113static const char * const da7213_dac_ng_rampup_txt[] = {
114 "0.02 ms/dB", "0.16 ms/dB"
115};
116
117static const struct soc_enum da7213_dac_ng_rampup_rate =
118 SOC_ENUM_SINGLE(DA7213_DAC_NG_SETUP_TIME,
119 DA7213_DAC_NG_RAMPUP_RATE_SHIFT,
120 DA7213_DAC_NG_RAMP_RATE_MAX,
121 da7213_dac_ng_rampup_txt);
122
123/* DAC noise gate rampdown rate value */
124static const char * const da7213_dac_ng_rampdown_txt[] = {
125 "0.64 ms/dB", "20.48 ms/dB"
126};
127
128static const struct soc_enum da7213_dac_ng_rampdown_rate =
129 SOC_ENUM_SINGLE(DA7213_DAC_NG_SETUP_TIME,
130 DA7213_DAC_NG_RAMPDN_RATE_SHIFT,
131 DA7213_DAC_NG_RAMP_RATE_MAX,
132 da7213_dac_ng_rampdown_txt);
133
134/* DAC soft mute rate value */
135static const char * const da7213_dac_soft_mute_rate_txt[] = {
136 "1", "2", "4", "8", "16", "32", "64"
137};
138
139static const struct soc_enum da7213_dac_soft_mute_rate =
140 SOC_ENUM_SINGLE(DA7213_DAC_FILTERS5, DA7213_DAC_SOFTMUTE_RATE_SHIFT,
141 DA7213_DAC_SOFTMUTE_RATE_MAX,
142 da7213_dac_soft_mute_rate_txt);
143
144/* ALC Attack Rate select */
145static const char * const da7213_alc_attack_rate_txt[] = {
146 "44/fs", "88/fs", "176/fs", "352/fs", "704/fs", "1408/fs", "2816/fs",
147 "5632/fs", "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
148};
149
150static const struct soc_enum da7213_alc_attack_rate =
151 SOC_ENUM_SINGLE(DA7213_ALC_CTRL2, DA7213_ALC_ATTACK_SHIFT,
152 DA7213_ALC_ATTACK_MAX, da7213_alc_attack_rate_txt);
153
154/* ALC Release Rate select */
155static const char * const da7213_alc_release_rate_txt[] = {
156 "176/fs", "352/fs", "704/fs", "1408/fs", "2816/fs", "5632/fs",
157 "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
158};
159
160static const struct soc_enum da7213_alc_release_rate =
161 SOC_ENUM_SINGLE(DA7213_ALC_CTRL2, DA7213_ALC_RELEASE_SHIFT,
162 DA7213_ALC_RELEASE_MAX, da7213_alc_release_rate_txt);
163
164/* ALC Hold Time select */
165static const char * const da7213_alc_hold_time_txt[] = {
166 "62/fs", "124/fs", "248/fs", "496/fs", "992/fs", "1984/fs", "3968/fs",
167 "7936/fs", "15872/fs", "31744/fs", "63488/fs", "126976/fs",
168 "253952/fs", "507904/fs", "1015808/fs", "2031616/fs"
169};
170
171static const struct soc_enum da7213_alc_hold_time =
172 SOC_ENUM_SINGLE(DA7213_ALC_CTRL3, DA7213_ALC_HOLD_SHIFT,
173 DA7213_ALC_HOLD_MAX, da7213_alc_hold_time_txt);
174
175/* ALC Input Signal Tracking rate select */
176static const char * const da7213_alc_integ_rate_txt[] = {
177 "1/4", "1/16", "1/256", "1/65536"
178};
179
180static const struct soc_enum da7213_alc_integ_attack_rate =
181 SOC_ENUM_SINGLE(DA7213_ALC_CTRL3, DA7213_ALC_INTEG_ATTACK_SHIFT,
182 DA7213_ALC_INTEG_MAX, da7213_alc_integ_rate_txt);
183
184static const struct soc_enum da7213_alc_integ_release_rate =
185 SOC_ENUM_SINGLE(DA7213_ALC_CTRL3, DA7213_ALC_INTEG_RELEASE_SHIFT,
186 DA7213_ALC_INTEG_MAX, da7213_alc_integ_rate_txt);
187
188
189/*
190 * Control Functions
191 */
192
193static int da7213_get_alc_data(struct snd_soc_codec *codec, u8 reg_val)
194{
195 int mid_data, top_data;
196 int sum = 0;
197 u8 iteration;
198
199 for (iteration = 0; iteration < DA7213_ALC_AVG_ITERATIONS;
200 iteration++) {
201 /* Select the left or right channel and capture data */
202 snd_soc_write(codec, DA7213_ALC_CIC_OP_LVL_CTRL, reg_val);
203
204 /* Select middle 8 bits for read back from data register */
205 snd_soc_write(codec, DA7213_ALC_CIC_OP_LVL_CTRL,
206 reg_val | DA7213_ALC_DATA_MIDDLE);
207 mid_data = snd_soc_read(codec, DA7213_ALC_CIC_OP_LVL_DATA);
208
209 /* Select top 8 bits for read back from data register */
210 snd_soc_write(codec, DA7213_ALC_CIC_OP_LVL_CTRL,
211 reg_val | DA7213_ALC_DATA_TOP);
212 top_data = snd_soc_read(codec, DA7213_ALC_CIC_OP_LVL_DATA);
213
214 sum += ((mid_data << 8) | (top_data << 16));
215 }
216
217 return sum / DA7213_ALC_AVG_ITERATIONS;
218}
219
220static void da7213_alc_calib_man(struct snd_soc_codec *codec)
221{
222 u8 reg_val;
223 int avg_left_data, avg_right_data, offset_l, offset_r;
224
225 /* Calculate average for Left and Right data */
226 /* Left Data */
227 avg_left_data = da7213_get_alc_data(codec,
228 DA7213_ALC_CIC_OP_CHANNEL_LEFT);
229 /* Right Data */
230 avg_right_data = da7213_get_alc_data(codec,
231 DA7213_ALC_CIC_OP_CHANNEL_RIGHT);
232
233 /* Calculate DC offset */
234 offset_l = -avg_left_data;
235 offset_r = -avg_right_data;
236
237 reg_val = (offset_l & DA7213_ALC_OFFSET_15_8) >> 8;
238 snd_soc_write(codec, DA7213_ALC_OFFSET_MAN_M_L, reg_val);
239 reg_val = (offset_l & DA7213_ALC_OFFSET_19_16) >> 16;
240 snd_soc_write(codec, DA7213_ALC_OFFSET_MAN_U_L, reg_val);
241
242 reg_val = (offset_r & DA7213_ALC_OFFSET_15_8) >> 8;
243 snd_soc_write(codec, DA7213_ALC_OFFSET_MAN_M_R, reg_val);
244 reg_val = (offset_r & DA7213_ALC_OFFSET_19_16) >> 16;
245 snd_soc_write(codec, DA7213_ALC_OFFSET_MAN_U_R, reg_val);
246
247 /* Enable analog/digital gain mode & offset cancellation */
248 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
249 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE,
250 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE);
251}
252
253static void da7213_alc_calib_auto(struct snd_soc_codec *codec)
254{
255 u8 alc_ctrl1;
256
257 /* Begin auto calibration and wait for completion */
258 snd_soc_update_bits(codec, DA7213_ALC_CTRL1, DA7213_ALC_AUTO_CALIB_EN,
259 DA7213_ALC_AUTO_CALIB_EN);
260 do {
261 alc_ctrl1 = snd_soc_read(codec, DA7213_ALC_CTRL1);
262 } while (alc_ctrl1 & DA7213_ALC_AUTO_CALIB_EN);
263
264 /* If auto calibration fails, fall back to digital gain only mode */
265 if (alc_ctrl1 & DA7213_ALC_CALIB_OVERFLOW) {
266 dev_warn(codec->dev,
267 "ALC auto calibration failed with overflow\n");
268 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
269 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE,
270 0);
271 } else {
272 /* Enable analog/digital gain mode & offset cancellation */
273 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
274 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE,
275 DA7213_ALC_OFFSET_EN | DA7213_ALC_SYNC_MODE);
276 }
277
278}
279
280static void da7213_alc_calib(struct snd_soc_codec *codec)
281{
282 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
283 u8 adc_l_ctrl, adc_r_ctrl;
284 u8 mixin_l_sel, mixin_r_sel;
285 u8 mic_1_ctrl, mic_2_ctrl;
286
287 /* Save current values from ADC control registers */
288 adc_l_ctrl = snd_soc_read(codec, DA7213_ADC_L_CTRL);
289 adc_r_ctrl = snd_soc_read(codec, DA7213_ADC_R_CTRL);
290
291 /* Save current values from MIXIN_L/R_SELECT registers */
292 mixin_l_sel = snd_soc_read(codec, DA7213_MIXIN_L_SELECT);
293 mixin_r_sel = snd_soc_read(codec, DA7213_MIXIN_R_SELECT);
294
295 /* Save current values from MIC control registers */
296 mic_1_ctrl = snd_soc_read(codec, DA7213_MIC_1_CTRL);
297 mic_2_ctrl = snd_soc_read(codec, DA7213_MIC_2_CTRL);
298
299 /* Enable ADC Left and Right */
300 snd_soc_update_bits(codec, DA7213_ADC_L_CTRL, DA7213_ADC_EN,
301 DA7213_ADC_EN);
302 snd_soc_update_bits(codec, DA7213_ADC_R_CTRL, DA7213_ADC_EN,
303 DA7213_ADC_EN);
304
305 /* Enable MIC paths */
306 snd_soc_update_bits(codec, DA7213_MIXIN_L_SELECT,
307 DA7213_MIXIN_L_MIX_SELECT_MIC_1 |
308 DA7213_MIXIN_L_MIX_SELECT_MIC_2,
309 DA7213_MIXIN_L_MIX_SELECT_MIC_1 |
310 DA7213_MIXIN_L_MIX_SELECT_MIC_2);
311 snd_soc_update_bits(codec, DA7213_MIXIN_R_SELECT,
312 DA7213_MIXIN_R_MIX_SELECT_MIC_2 |
313 DA7213_MIXIN_R_MIX_SELECT_MIC_1,
314 DA7213_MIXIN_R_MIX_SELECT_MIC_2 |
315 DA7213_MIXIN_R_MIX_SELECT_MIC_1);
316
317 /* Mute MIC PGAs */
318 snd_soc_update_bits(codec, DA7213_MIC_1_CTRL, DA7213_MUTE_EN,
319 DA7213_MUTE_EN);
320 snd_soc_update_bits(codec, DA7213_MIC_2_CTRL, DA7213_MUTE_EN,
321 DA7213_MUTE_EN);
322
323 /* Perform calibration */
324 if (da7213->alc_calib_auto)
325 da7213_alc_calib_auto(codec);
326 else
327 da7213_alc_calib_man(codec);
328
329 /* Restore MIXIN_L/R_SELECT registers to their original states */
330 snd_soc_write(codec, DA7213_MIXIN_L_SELECT, mixin_l_sel);
331 snd_soc_write(codec, DA7213_MIXIN_R_SELECT, mixin_r_sel);
332
333 /* Restore ADC control registers to their original states */
334 snd_soc_write(codec, DA7213_ADC_L_CTRL, adc_l_ctrl);
335 snd_soc_write(codec, DA7213_ADC_R_CTRL, adc_r_ctrl);
336
337 /* Restore original values of MIC control registers */
338 snd_soc_write(codec, DA7213_MIC_1_CTRL, mic_1_ctrl);
339 snd_soc_write(codec, DA7213_MIC_2_CTRL, mic_2_ctrl);
340}
341
342static int da7213_put_mixin_gain(struct snd_kcontrol *kcontrol,
343 struct snd_ctl_elem_value *ucontrol)
344{
345 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
346 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
347 int ret;
348
349 ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
350
351 /* If ALC in operation, make sure calibrated offsets are updated */
352 if ((!ret) && (da7213->alc_en))
353 da7213_alc_calib(codec);
354
355 return ret;
356}
357
358static int da7213_put_alc_sw(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_value *ucontrol)
360{
361 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
362 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
363
364 /* Force ALC offset calibration if enabling ALC */
365 if (ucontrol->value.integer.value[0] ||
366 ucontrol->value.integer.value[1]) {
367 if (!da7213->alc_en) {
368 da7213_alc_calib(codec);
369 da7213->alc_en = true;
370 }
371 } else {
372 da7213->alc_en = false;
373 }
374
375 return snd_soc_put_volsw(kcontrol, ucontrol);
376}
377
378
379/*
380 * KControls
381 */
382
383static const struct snd_kcontrol_new da7213_snd_controls[] = {
384
385 /* Volume controls */
386 SOC_SINGLE_TLV("Mic 1 Volume", DA7213_MIC_1_GAIN,
387 DA7213_MIC_AMP_GAIN_SHIFT, DA7213_MIC_AMP_GAIN_MAX,
388 DA7213_NO_INVERT, mic_vol_tlv),
389 SOC_SINGLE_TLV("Mic 2 Volume", DA7213_MIC_2_GAIN,
390 DA7213_MIC_AMP_GAIN_SHIFT, DA7213_MIC_AMP_GAIN_MAX,
391 DA7213_NO_INVERT, mic_vol_tlv),
392 SOC_DOUBLE_R_TLV("Aux Volume", DA7213_AUX_L_GAIN, DA7213_AUX_R_GAIN,
393 DA7213_AUX_AMP_GAIN_SHIFT, DA7213_AUX_AMP_GAIN_MAX,
394 DA7213_NO_INVERT, aux_vol_tlv),
395 SOC_DOUBLE_R_EXT_TLV("Mixin PGA Volume", DA7213_MIXIN_L_GAIN,
396 DA7213_MIXIN_R_GAIN, DA7213_MIXIN_AMP_GAIN_SHIFT,
397 DA7213_MIXIN_AMP_GAIN_MAX, DA7213_NO_INVERT,
398 snd_soc_get_volsw_2r, da7213_put_mixin_gain,
399 mixin_gain_tlv),
400 SOC_DOUBLE_R_TLV("ADC Volume", DA7213_ADC_L_GAIN, DA7213_ADC_R_GAIN,
401 DA7213_ADC_AMP_GAIN_SHIFT, DA7213_ADC_AMP_GAIN_MAX,
402 DA7213_NO_INVERT, digital_gain_tlv),
403 SOC_DOUBLE_R_TLV("DAC Volume", DA7213_DAC_L_GAIN, DA7213_DAC_R_GAIN,
404 DA7213_DAC_AMP_GAIN_SHIFT, DA7213_DAC_AMP_GAIN_MAX,
405 DA7213_NO_INVERT, digital_gain_tlv),
406 SOC_DOUBLE_R_TLV("Headphone Volume", DA7213_HP_L_GAIN, DA7213_HP_R_GAIN,
407 DA7213_HP_AMP_GAIN_SHIFT, DA7213_HP_AMP_GAIN_MAX,
408 DA7213_NO_INVERT, hp_vol_tlv),
409 SOC_SINGLE_TLV("Lineout Volume", DA7213_LINE_GAIN,
410 DA7213_LINE_AMP_GAIN_SHIFT, DA7213_LINE_AMP_GAIN_MAX,
411 DA7213_NO_INVERT, lineout_vol_tlv),
412
413 /* DAC Equalizer controls */
414 SOC_SINGLE("DAC EQ Switch", DA7213_DAC_FILTERS4, DA7213_DAC_EQ_EN_SHIFT,
415 DA7213_DAC_EQ_EN_MAX, DA7213_NO_INVERT),
416 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7213_DAC_FILTERS2,
417 DA7213_DAC_EQ_BAND1_SHIFT, DA7213_DAC_EQ_BAND_MAX,
418 DA7213_NO_INVERT, eq_gain_tlv),
419 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7213_DAC_FILTERS2,
420 DA7213_DAC_EQ_BAND2_SHIFT, DA7213_DAC_EQ_BAND_MAX,
421 DA7213_NO_INVERT, eq_gain_tlv),
422 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7213_DAC_FILTERS3,
423 DA7213_DAC_EQ_BAND3_SHIFT, DA7213_DAC_EQ_BAND_MAX,
424 DA7213_NO_INVERT, eq_gain_tlv),
425 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7213_DAC_FILTERS3,
426 DA7213_DAC_EQ_BAND4_SHIFT, DA7213_DAC_EQ_BAND_MAX,
427 DA7213_NO_INVERT, eq_gain_tlv),
428 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7213_DAC_FILTERS4,
429 DA7213_DAC_EQ_BAND5_SHIFT, DA7213_DAC_EQ_BAND_MAX,
430 DA7213_NO_INVERT, eq_gain_tlv),
431
432 /* High Pass Filter and Voice Mode controls */
433 SOC_SINGLE("ADC HPF Switch", DA7213_ADC_FILTERS1, DA7213_HPF_EN_SHIFT,
434 DA7213_HPF_EN_MAX, DA7213_NO_INVERT),
435 SOC_ENUM("ADC HPF Cutoff", da7213_adc_audio_hpf_corner),
436 SOC_SINGLE("ADC Voice Mode Switch", DA7213_ADC_FILTERS1,
437 DA7213_VOICE_EN_SHIFT, DA7213_VOICE_EN_MAX,
438 DA7213_NO_INVERT),
439 SOC_ENUM("ADC Voice Cutoff", da7213_adc_voice_hpf_corner),
440
441 SOC_SINGLE("DAC HPF Switch", DA7213_DAC_FILTERS1, DA7213_HPF_EN_SHIFT,
442 DA7213_HPF_EN_MAX, DA7213_NO_INVERT),
443 SOC_ENUM("DAC HPF Cutoff", da7213_dac_audio_hpf_corner),
444 SOC_SINGLE("DAC Voice Mode Switch", DA7213_DAC_FILTERS1,
445 DA7213_VOICE_EN_SHIFT, DA7213_VOICE_EN_MAX,
446 DA7213_NO_INVERT),
447 SOC_ENUM("DAC Voice Cutoff", da7213_dac_voice_hpf_corner),
448
449 /* Mute controls */
450 SOC_SINGLE("Mic 1 Switch", DA7213_MIC_1_CTRL, DA7213_MUTE_EN_SHIFT,
451 DA7213_MUTE_EN_MAX, DA7213_INVERT),
452 SOC_SINGLE("Mic 2 Switch", DA7213_MIC_2_CTRL, DA7213_MUTE_EN_SHIFT,
453 DA7213_MUTE_EN_MAX, DA7213_INVERT),
454 SOC_DOUBLE_R("Aux Switch", DA7213_AUX_L_CTRL, DA7213_AUX_R_CTRL,
455 DA7213_MUTE_EN_SHIFT, DA7213_MUTE_EN_MAX, DA7213_INVERT),
456 SOC_DOUBLE_R("Mixin PGA Switch", DA7213_MIXIN_L_CTRL,
457 DA7213_MIXIN_R_CTRL, DA7213_MUTE_EN_SHIFT,
458 DA7213_MUTE_EN_MAX, DA7213_INVERT),
459 SOC_DOUBLE_R("ADC Switch", DA7213_ADC_L_CTRL, DA7213_ADC_R_CTRL,
460 DA7213_MUTE_EN_SHIFT, DA7213_MUTE_EN_MAX, DA7213_INVERT),
461 SOC_DOUBLE_R("Headphone Switch", DA7213_HP_L_CTRL, DA7213_HP_R_CTRL,
462 DA7213_MUTE_EN_SHIFT, DA7213_MUTE_EN_MAX, DA7213_INVERT),
463 SOC_SINGLE("Lineout Switch", DA7213_LINE_CTRL, DA7213_MUTE_EN_SHIFT,
464 DA7213_MUTE_EN_MAX, DA7213_INVERT),
465 SOC_SINGLE("DAC Soft Mute Switch", DA7213_DAC_FILTERS5,
466 DA7213_DAC_SOFTMUTE_EN_SHIFT, DA7213_DAC_SOFTMUTE_EN_MAX,
467 DA7213_NO_INVERT),
468 SOC_ENUM("DAC Soft Mute Rate", da7213_dac_soft_mute_rate),
469
470 /* Zero Cross controls */
471 SOC_DOUBLE_R("Aux ZC Switch", DA7213_AUX_L_CTRL, DA7213_AUX_R_CTRL,
472 DA7213_ZC_EN_SHIFT, DA7213_ZC_EN_MAX, DA7213_NO_INVERT),
473 SOC_DOUBLE_R("Mixin PGA ZC Switch", DA7213_MIXIN_L_CTRL,
474 DA7213_MIXIN_R_CTRL, DA7213_ZC_EN_SHIFT, DA7213_ZC_EN_MAX,
475 DA7213_NO_INVERT),
476 SOC_DOUBLE_R("Headphone ZC Switch", DA7213_HP_L_CTRL, DA7213_HP_R_CTRL,
477 DA7213_ZC_EN_SHIFT, DA7213_ZC_EN_MAX, DA7213_NO_INVERT),
478
479 /* Gain Ramping controls */
480 SOC_DOUBLE_R("Aux Gain Ramping Switch", DA7213_AUX_L_CTRL,
481 DA7213_AUX_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
482 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
483 SOC_DOUBLE_R("Mixin Gain Ramping Switch", DA7213_MIXIN_L_CTRL,
484 DA7213_MIXIN_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
485 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
486 SOC_DOUBLE_R("ADC Gain Ramping Switch", DA7213_ADC_L_CTRL,
487 DA7213_ADC_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
488 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
489 SOC_DOUBLE_R("DAC Gain Ramping Switch", DA7213_DAC_L_CTRL,
490 DA7213_DAC_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
491 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
492 SOC_DOUBLE_R("Headphone Gain Ramping Switch", DA7213_HP_L_CTRL,
493 DA7213_HP_R_CTRL, DA7213_GAIN_RAMP_EN_SHIFT,
494 DA7213_GAIN_RAMP_EN_MAX, DA7213_NO_INVERT),
495 SOC_SINGLE("Lineout Gain Ramping Switch", DA7213_LINE_CTRL,
496 DA7213_GAIN_RAMP_EN_SHIFT, DA7213_GAIN_RAMP_EN_MAX,
497 DA7213_NO_INVERT),
498 SOC_ENUM("Gain Ramping Rate", da7213_gain_ramp_rate),
499
500 /* DAC Noise Gate controls */
501 SOC_SINGLE("DAC NG Switch", DA7213_DAC_NG_CTRL, DA7213_DAC_NG_EN_SHIFT,
502 DA7213_DAC_NG_EN_MAX, DA7213_NO_INVERT),
503 SOC_ENUM("DAC NG Setup Time", da7213_dac_ng_setup_time),
504 SOC_ENUM("DAC NG Rampup Rate", da7213_dac_ng_rampup_rate),
505 SOC_ENUM("DAC NG Rampdown Rate", da7213_dac_ng_rampdown_rate),
506 SOC_SINGLE("DAC NG OFF Threshold", DA7213_DAC_NG_OFF_THRESHOLD,
507 DA7213_DAC_NG_THRESHOLD_SHIFT, DA7213_DAC_NG_THRESHOLD_MAX,
508 DA7213_NO_INVERT),
509 SOC_SINGLE("DAC NG ON Threshold", DA7213_DAC_NG_ON_THRESHOLD,
510 DA7213_DAC_NG_THRESHOLD_SHIFT, DA7213_DAC_NG_THRESHOLD_MAX,
511 DA7213_NO_INVERT),
512
513 /* DAC Routing & Inversion */
514 SOC_DOUBLE("DAC Mono Switch", DA7213_DIG_ROUTING_DAC,
515 DA7213_DAC_L_MONO_SHIFT, DA7213_DAC_R_MONO_SHIFT,
516 DA7213_DAC_MONO_MAX, DA7213_NO_INVERT),
517 SOC_DOUBLE("DAC Invert Switch", DA7213_DIG_CTRL, DA7213_DAC_L_INV_SHIFT,
518 DA7213_DAC_R_INV_SHIFT, DA7213_DAC_INV_MAX,
519 DA7213_NO_INVERT),
520
521 /* DMIC controls */
522 SOC_DOUBLE_R("DMIC Switch", DA7213_MIXIN_L_SELECT,
523 DA7213_MIXIN_R_SELECT, DA7213_DMIC_EN_SHIFT,
524 DA7213_DMIC_EN_MAX, DA7213_NO_INVERT),
525
526 /* ALC Controls */
527 SOC_DOUBLE_EXT("ALC Switch", DA7213_ALC_CTRL1, DA7213_ALC_L_EN_SHIFT,
528 DA7213_ALC_R_EN_SHIFT, DA7213_ALC_EN_MAX,
529 DA7213_NO_INVERT, snd_soc_get_volsw, da7213_put_alc_sw),
530 SOC_ENUM("ALC Attack Rate", da7213_alc_attack_rate),
531 SOC_ENUM("ALC Release Rate", da7213_alc_release_rate),
532 SOC_ENUM("ALC Hold Time", da7213_alc_hold_time),
533 /*
534 * Rate at which input signal envelope is tracked as the signal gets
535 * larger
536 */
537 SOC_ENUM("ALC Integ Attack Rate", da7213_alc_integ_attack_rate),
538 /*
539 * Rate at which input signal envelope is tracked as the signal gets
540 * smaller
541 */
542 SOC_ENUM("ALC Integ Release Rate", da7213_alc_integ_release_rate),
543 SOC_SINGLE_TLV("ALC Noise Threshold Volume", DA7213_ALC_NOISE,
544 DA7213_ALC_THRESHOLD_SHIFT, DA7213_ALC_THRESHOLD_MAX,
545 DA7213_INVERT, alc_threshold_tlv),
546 SOC_SINGLE_TLV("ALC Min Threshold Volume", DA7213_ALC_TARGET_MIN,
547 DA7213_ALC_THRESHOLD_SHIFT, DA7213_ALC_THRESHOLD_MAX,
548 DA7213_INVERT, alc_threshold_tlv),
549 SOC_SINGLE_TLV("ALC Max Threshold Volume", DA7213_ALC_TARGET_MAX,
550 DA7213_ALC_THRESHOLD_SHIFT, DA7213_ALC_THRESHOLD_MAX,
551 DA7213_INVERT, alc_threshold_tlv),
552 SOC_SINGLE_TLV("ALC Max Attenuation Volume", DA7213_ALC_GAIN_LIMITS,
553 DA7213_ALC_ATTEN_MAX_SHIFT,
554 DA7213_ALC_ATTEN_GAIN_MAX_MAX, DA7213_NO_INVERT,
555 alc_gain_tlv),
556 SOC_SINGLE_TLV("ALC Max Gain Volume", DA7213_ALC_GAIN_LIMITS,
557 DA7213_ALC_GAIN_MAX_SHIFT, DA7213_ALC_ATTEN_GAIN_MAX_MAX,
558 DA7213_NO_INVERT, alc_gain_tlv),
559 SOC_SINGLE_TLV("ALC Min Analog Gain Volume", DA7213_ALC_ANA_GAIN_LIMITS,
560 DA7213_ALC_ANA_GAIN_MIN_SHIFT, DA7213_ALC_ANA_GAIN_MAX,
561 DA7213_NO_INVERT, alc_analog_gain_tlv),
562 SOC_SINGLE_TLV("ALC Max Analog Gain Volume", DA7213_ALC_ANA_GAIN_LIMITS,
563 DA7213_ALC_ANA_GAIN_MAX_SHIFT, DA7213_ALC_ANA_GAIN_MAX,
564 DA7213_NO_INVERT, alc_analog_gain_tlv),
565 SOC_SINGLE("ALC Anticlip Mode Switch", DA7213_ALC_ANTICLIP_CTRL,
566 DA7213_ALC_ANTICLIP_EN_SHIFT, DA7213_ALC_ANTICLIP_EN_MAX,
567 DA7213_NO_INVERT),
568 SOC_SINGLE("ALC Anticlip Level", DA7213_ALC_ANTICLIP_LEVEL,
569 DA7213_ALC_ANTICLIP_LEVEL_SHIFT,
570 DA7213_ALC_ANTICLIP_LEVEL_MAX, DA7213_NO_INVERT),
571};
572
573
574/*
575 * DAPM
576 */
577
578/*
579 * Enums
580 */
581
582/* MIC PGA source select */
583static const char * const da7213_mic_amp_in_sel_txt[] = {
584 "Differential", "MIC_P", "MIC_N"
585};
586
587static const struct soc_enum da7213_mic_1_amp_in_sel =
588 SOC_ENUM_SINGLE(DA7213_MIC_1_CTRL, DA7213_MIC_AMP_IN_SEL_SHIFT,
589 DA7213_MIC_AMP_IN_SEL_MAX, da7213_mic_amp_in_sel_txt);
590static const struct snd_kcontrol_new da7213_mic_1_amp_in_sel_mux =
591 SOC_DAPM_ENUM("Mic 1 Amp Source MUX", da7213_mic_1_amp_in_sel);
592
593static const struct soc_enum da7213_mic_2_amp_in_sel =
594 SOC_ENUM_SINGLE(DA7213_MIC_2_CTRL, DA7213_MIC_AMP_IN_SEL_SHIFT,
595 DA7213_MIC_AMP_IN_SEL_MAX, da7213_mic_amp_in_sel_txt);
596static const struct snd_kcontrol_new da7213_mic_2_amp_in_sel_mux =
597 SOC_DAPM_ENUM("Mic 2 Amp Source MUX", da7213_mic_2_amp_in_sel);
598
599/* DAI routing select */
600static const char * const da7213_dai_src_txt[] = {
601 "ADC Left", "ADC Right", "DAI Input Left", "DAI Input Right"
602};
603
604static const struct soc_enum da7213_dai_l_src =
605 SOC_ENUM_SINGLE(DA7213_DIG_ROUTING_DAI, DA7213_DAI_L_SRC_SHIFT,
606 DA7213_DAI_SRC_MAX, da7213_dai_src_txt);
607static const struct snd_kcontrol_new da7213_dai_l_src_mux =
608 SOC_DAPM_ENUM("DAI Left Source MUX", da7213_dai_l_src);
609
610static const struct soc_enum da7213_dai_r_src =
611 SOC_ENUM_SINGLE(DA7213_DIG_ROUTING_DAI, DA7213_DAI_R_SRC_SHIFT,
612 DA7213_DAI_SRC_MAX, da7213_dai_src_txt);
613static const struct snd_kcontrol_new da7213_dai_r_src_mux =
614 SOC_DAPM_ENUM("DAI Right Source MUX", da7213_dai_r_src);
615
616/* DAC routing select */
617static const char * const da7213_dac_src_txt[] = {
618 "ADC Output Left", "ADC Output Right", "DAI Input Left",
619 "DAI Input Right"
620};
621
622static const struct soc_enum da7213_dac_l_src =
623 SOC_ENUM_SINGLE(DA7213_DIG_ROUTING_DAC, DA7213_DAC_L_SRC_SHIFT,
624 DA7213_DAC_SRC_MAX, da7213_dac_src_txt);
625static const struct snd_kcontrol_new da7213_dac_l_src_mux =
626 SOC_DAPM_ENUM("DAC Left Source MUX", da7213_dac_l_src);
627
628static const struct soc_enum da7213_dac_r_src =
629 SOC_ENUM_SINGLE(DA7213_DIG_ROUTING_DAC, DA7213_DAC_R_SRC_SHIFT,
630 DA7213_DAC_SRC_MAX, da7213_dac_src_txt);
631static const struct snd_kcontrol_new da7213_dac_r_src_mux =
632 SOC_DAPM_ENUM("DAC Right Source MUX", da7213_dac_r_src);
633
634/*
635 * Mixer Controls
636 */
637
638/* Mixin Left */
639static const struct snd_kcontrol_new da7213_dapm_mixinl_controls[] = {
640 SOC_DAPM_SINGLE("Aux Left Switch", DA7213_MIXIN_L_SELECT,
641 DA7213_MIXIN_L_MIX_SELECT_AUX_L_SHIFT,
642 DA7213_MIXIN_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
643 SOC_DAPM_SINGLE("Mic 1 Switch", DA7213_MIXIN_L_SELECT,
644 DA7213_MIXIN_L_MIX_SELECT_MIC_1_SHIFT,
645 DA7213_MIXIN_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
646 SOC_DAPM_SINGLE("Mic 2 Switch", DA7213_MIXIN_L_SELECT,
647 DA7213_MIXIN_L_MIX_SELECT_MIC_2_SHIFT,
648 DA7213_MIXIN_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
649 SOC_DAPM_SINGLE("Mixin Right Switch", DA7213_MIXIN_L_SELECT,
650 DA7213_MIXIN_L_MIX_SELECT_MIXIN_R_SHIFT,
651 DA7213_MIXIN_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
652};
653
654/* Mixin Right */
655static const struct snd_kcontrol_new da7213_dapm_mixinr_controls[] = {
656 SOC_DAPM_SINGLE("Aux Right Switch", DA7213_MIXIN_R_SELECT,
657 DA7213_MIXIN_R_MIX_SELECT_AUX_R_SHIFT,
658 DA7213_MIXIN_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
659 SOC_DAPM_SINGLE("Mic 2 Switch", DA7213_MIXIN_R_SELECT,
660 DA7213_MIXIN_R_MIX_SELECT_MIC_2_SHIFT,
661 DA7213_MIXIN_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
662 SOC_DAPM_SINGLE("Mic 1 Switch", DA7213_MIXIN_R_SELECT,
663 DA7213_MIXIN_R_MIX_SELECT_MIC_1_SHIFT,
664 DA7213_MIXIN_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
665 SOC_DAPM_SINGLE("Mixin Left Switch", DA7213_MIXIN_R_SELECT,
666 DA7213_MIXIN_R_MIX_SELECT_MIXIN_L_SHIFT,
667 DA7213_MIXIN_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
668};
669
670/* Mixout Left */
671static const struct snd_kcontrol_new da7213_dapm_mixoutl_controls[] = {
672 SOC_DAPM_SINGLE("Aux Left Switch", DA7213_MIXOUT_L_SELECT,
673 DA7213_MIXOUT_L_MIX_SELECT_AUX_L_SHIFT,
674 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
675 SOC_DAPM_SINGLE("Mixin Left Switch", DA7213_MIXOUT_L_SELECT,
676 DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_SHIFT,
677 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
678 SOC_DAPM_SINGLE("Mixin Right Switch", DA7213_MIXOUT_L_SELECT,
679 DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_SHIFT,
680 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
681 SOC_DAPM_SINGLE("DAC Left Switch", DA7213_MIXOUT_L_SELECT,
682 DA7213_MIXOUT_L_MIX_SELECT_DAC_L_SHIFT,
683 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
684 SOC_DAPM_SINGLE("Aux Left Invert Switch", DA7213_MIXOUT_L_SELECT,
685 DA7213_MIXOUT_L_MIX_SELECT_AUX_L_INVERTED_SHIFT,
686 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
687 SOC_DAPM_SINGLE("Mixin Left Invert Switch", DA7213_MIXOUT_L_SELECT,
688 DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_INVERTED_SHIFT,
689 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
690 SOC_DAPM_SINGLE("Mixin Right Invert Switch", DA7213_MIXOUT_L_SELECT,
691 DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_INVERTED_SHIFT,
692 DA7213_MIXOUT_L_MIX_SELECT_MAX, DA7213_NO_INVERT),
693};
694
695/* Mixout Right */
696static const struct snd_kcontrol_new da7213_dapm_mixoutr_controls[] = {
697 SOC_DAPM_SINGLE("Aux Right Switch", DA7213_MIXOUT_R_SELECT,
698 DA7213_MIXOUT_R_MIX_SELECT_AUX_R_SHIFT,
699 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
700 SOC_DAPM_SINGLE("Mixin Right Switch", DA7213_MIXOUT_R_SELECT,
701 DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_SHIFT,
702 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
703 SOC_DAPM_SINGLE("Mixin Left Switch", DA7213_MIXOUT_R_SELECT,
704 DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_SHIFT,
705 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
706 SOC_DAPM_SINGLE("DAC Right Switch", DA7213_MIXOUT_R_SELECT,
707 DA7213_MIXOUT_R_MIX_SELECT_DAC_R_SHIFT,
708 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
709 SOC_DAPM_SINGLE("Aux Right Invert Switch", DA7213_MIXOUT_R_SELECT,
710 DA7213_MIXOUT_R_MIX_SELECT_AUX_R_INVERTED_SHIFT,
711 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
712 SOC_DAPM_SINGLE("Mixin Right Invert Switch", DA7213_MIXOUT_R_SELECT,
713 DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_INVERTED_SHIFT,
714 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
715 SOC_DAPM_SINGLE("Mixin Left Invert Switch", DA7213_MIXOUT_R_SELECT,
716 DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_INVERTED_SHIFT,
717 DA7213_MIXOUT_R_MIX_SELECT_MAX, DA7213_NO_INVERT),
718};
719
720
721/*
722 * DAPM widgets
723 */
724
725static const struct snd_soc_dapm_widget da7213_dapm_widgets[] = {
726 /*
727 * Input & Output
728 */
729
730 /* Use a supply here as this controls both input & output DAIs */
731 SND_SOC_DAPM_SUPPLY("DAI", DA7213_DAI_CTRL, DA7213_DAI_EN_SHIFT,
732 DA7213_NO_INVERT, NULL, 0),
733
734 /*
735 * Input
736 */
737
738 /* Input Lines */
739 SND_SOC_DAPM_INPUT("MIC1"),
740 SND_SOC_DAPM_INPUT("MIC2"),
741 SND_SOC_DAPM_INPUT("AUXL"),
742 SND_SOC_DAPM_INPUT("AUXR"),
743
744 /* MUXs for Mic PGA source selection */
745 SND_SOC_DAPM_MUX("Mic 1 Amp Source MUX", SND_SOC_NOPM, 0, 0,
746 &da7213_mic_1_amp_in_sel_mux),
747 SND_SOC_DAPM_MUX("Mic 2 Amp Source MUX", SND_SOC_NOPM, 0, 0,
748 &da7213_mic_2_amp_in_sel_mux),
749
750 /* Input PGAs */
751 SND_SOC_DAPM_PGA("Mic 1 PGA", DA7213_MIC_1_CTRL, DA7213_AMP_EN_SHIFT,
752 DA7213_NO_INVERT, NULL, 0),
753 SND_SOC_DAPM_PGA("Mic 2 PGA", DA7213_MIC_2_CTRL, DA7213_AMP_EN_SHIFT,
754 DA7213_NO_INVERT, NULL, 0),
755 SND_SOC_DAPM_PGA("Aux Left PGA", DA7213_AUX_L_CTRL, DA7213_AMP_EN_SHIFT,
756 DA7213_NO_INVERT, NULL, 0),
757 SND_SOC_DAPM_PGA("Aux Right PGA", DA7213_AUX_R_CTRL,
758 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
759 SND_SOC_DAPM_PGA("Mixin Left PGA", DA7213_MIXIN_L_CTRL,
760 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
761 SND_SOC_DAPM_PGA("Mixin Right PGA", DA7213_MIXIN_R_CTRL,
762 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
763
764 /* Mic Biases */
765 SND_SOC_DAPM_SUPPLY("Mic Bias 1", DA7213_MICBIAS_CTRL,
766 DA7213_MICBIAS1_EN_SHIFT, DA7213_NO_INVERT,
767 NULL, 0),
768 SND_SOC_DAPM_SUPPLY("Mic Bias 2", DA7213_MICBIAS_CTRL,
769 DA7213_MICBIAS2_EN_SHIFT, DA7213_NO_INVERT,
770 NULL, 0),
771
772 /* Input Mixers */
773 SND_SOC_DAPM_MIXER("Mixin Left", SND_SOC_NOPM, 0, 0,
774 &da7213_dapm_mixinl_controls[0],
775 ARRAY_SIZE(da7213_dapm_mixinl_controls)),
776 SND_SOC_DAPM_MIXER("Mixin Right", SND_SOC_NOPM, 0, 0,
777 &da7213_dapm_mixinr_controls[0],
778 ARRAY_SIZE(da7213_dapm_mixinr_controls)),
779
780 /* ADCs */
781 SND_SOC_DAPM_ADC("ADC Left", NULL, DA7213_ADC_L_CTRL,
782 DA7213_ADC_EN_SHIFT, DA7213_NO_INVERT),
783 SND_SOC_DAPM_ADC("ADC Right", NULL, DA7213_ADC_R_CTRL,
784 DA7213_ADC_EN_SHIFT, DA7213_NO_INVERT),
785
786 /* DAI */
787 SND_SOC_DAPM_MUX("DAI Left Source MUX", SND_SOC_NOPM, 0, 0,
788 &da7213_dai_l_src_mux),
789 SND_SOC_DAPM_MUX("DAI Right Source MUX", SND_SOC_NOPM, 0, 0,
790 &da7213_dai_r_src_mux),
791 SND_SOC_DAPM_AIF_OUT("DAIOUTL", "Capture", 0, SND_SOC_NOPM, 0, 0),
792 SND_SOC_DAPM_AIF_OUT("DAIOUTR", "Capture", 1, SND_SOC_NOPM, 0, 0),
793
794 /*
795 * Output
796 */
797
798 /* DAI */
799 SND_SOC_DAPM_AIF_IN("DAIINL", "Playback", 0, SND_SOC_NOPM, 0, 0),
800 SND_SOC_DAPM_AIF_IN("DAIINR", "Playback", 1, SND_SOC_NOPM, 0, 0),
801 SND_SOC_DAPM_MUX("DAC Left Source MUX", SND_SOC_NOPM, 0, 0,
802 &da7213_dac_l_src_mux),
803 SND_SOC_DAPM_MUX("DAC Right Source MUX", SND_SOC_NOPM, 0, 0,
804 &da7213_dac_r_src_mux),
805
806 /* DACs */
807 SND_SOC_DAPM_DAC("DAC Left", NULL, DA7213_DAC_L_CTRL,
808 DA7213_DAC_EN_SHIFT, DA7213_NO_INVERT),
809 SND_SOC_DAPM_DAC("DAC Right", NULL, DA7213_DAC_R_CTRL,
810 DA7213_DAC_EN_SHIFT, DA7213_NO_INVERT),
811
812 /* Output Mixers */
813 SND_SOC_DAPM_MIXER("Mixout Left", SND_SOC_NOPM, 0, 0,
814 &da7213_dapm_mixoutl_controls[0],
815 ARRAY_SIZE(da7213_dapm_mixoutl_controls)),
816 SND_SOC_DAPM_MIXER("Mixout Right", SND_SOC_NOPM, 0, 0,
817 &da7213_dapm_mixoutr_controls[0],
818 ARRAY_SIZE(da7213_dapm_mixoutr_controls)),
819
820 /* Output PGAs */
821 SND_SOC_DAPM_PGA("Mixout Left PGA", DA7213_MIXOUT_L_CTRL,
822 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
823 SND_SOC_DAPM_PGA("Mixout Right PGA", DA7213_MIXOUT_R_CTRL,
824 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
825 SND_SOC_DAPM_PGA("Lineout PGA", DA7213_LINE_CTRL, DA7213_AMP_EN_SHIFT,
826 DA7213_NO_INVERT, NULL, 0),
827 SND_SOC_DAPM_PGA("Headphone Left PGA", DA7213_HP_L_CTRL,
828 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
829 SND_SOC_DAPM_PGA("Headphone Right PGA", DA7213_HP_R_CTRL,
830 DA7213_AMP_EN_SHIFT, DA7213_NO_INVERT, NULL, 0),
831
832 /* Charge Pump */
833 SND_SOC_DAPM_SUPPLY("Charge Pump", DA7213_CP_CTRL, DA7213_CP_EN_SHIFT,
834 DA7213_NO_INVERT, NULL, 0),
835
836 /* Output Lines */
837 SND_SOC_DAPM_OUTPUT("HPL"),
838 SND_SOC_DAPM_OUTPUT("HPR"),
839 SND_SOC_DAPM_OUTPUT("LINE"),
840};
841
842
843/*
844 * DAPM audio route definition
845 */
846
847static const struct snd_soc_dapm_route da7213_audio_map[] = {
848 /* Dest Connecting Widget source */
849
850 /* Input path */
851 {"MIC1", NULL, "Mic Bias 1"},
852 {"MIC2", NULL, "Mic Bias 2"},
853
854 {"Mic 1 Amp Source MUX", "Differential", "MIC1"},
855 {"Mic 1 Amp Source MUX", "MIC_P", "MIC1"},
856 {"Mic 1 Amp Source MUX", "MIC_N", "MIC1"},
857
858 {"Mic 2 Amp Source MUX", "Differential", "MIC2"},
859 {"Mic 2 Amp Source MUX", "MIC_P", "MIC2"},
860 {"Mic 2 Amp Source MUX", "MIC_N", "MIC2"},
861
862 {"Mic 1 PGA", NULL, "Mic 1 Amp Source MUX"},
863 {"Mic 2 PGA", NULL, "Mic 2 Amp Source MUX"},
864
865 {"Aux Left PGA", NULL, "AUXL"},
866 {"Aux Right PGA", NULL, "AUXR"},
867
868 {"Mixin Left", "Aux Left Switch", "Aux Left PGA"},
869 {"Mixin Left", "Mic 1 Switch", "Mic 1 PGA"},
870 {"Mixin Left", "Mic 2 Switch", "Mic 2 PGA"},
871 {"Mixin Left", "Mixin Right Switch", "Mixin Right PGA"},
872
873 {"Mixin Right", "Aux Right Switch", "Aux Right PGA"},
874 {"Mixin Right", "Mic 2 Switch", "Mic 2 PGA"},
875 {"Mixin Right", "Mic 1 Switch", "Mic 1 PGA"},
876 {"Mixin Right", "Mixin Left Switch", "Mixin Left PGA"},
877
878 {"Mixin Left PGA", NULL, "Mixin Left"},
879 {"ADC Left", NULL, "Mixin Left PGA"},
880
881 {"Mixin Right PGA", NULL, "Mixin Right"},
882 {"ADC Right", NULL, "Mixin Right PGA"},
883
884 {"DAI Left Source MUX", "ADC Left", "ADC Left"},
885 {"DAI Left Source MUX", "ADC Right", "ADC Right"},
886 {"DAI Left Source MUX", "DAI Input Left", "DAIINL"},
887 {"DAI Left Source MUX", "DAI Input Right", "DAIINR"},
888
889 {"DAI Right Source MUX", "ADC Left", "ADC Left"},
890 {"DAI Right Source MUX", "ADC Right", "ADC Right"},
891 {"DAI Right Source MUX", "DAI Input Left", "DAIINL"},
892 {"DAI Right Source MUX", "DAI Input Right", "DAIINR"},
893
894 {"DAIOUTL", NULL, "DAI Left Source MUX"},
895 {"DAIOUTR", NULL, "DAI Right Source MUX"},
896
897 {"DAIOUTL", NULL, "DAI"},
898 {"DAIOUTR", NULL, "DAI"},
899
900 /* Output path */
901 {"DAIINL", NULL, "DAI"},
902 {"DAIINR", NULL, "DAI"},
903
904 {"DAC Left Source MUX", "ADC Output Left", "ADC Left"},
905 {"DAC Left Source MUX", "ADC Output Right", "ADC Right"},
906 {"DAC Left Source MUX", "DAI Input Left", "DAIINL"},
907 {"DAC Left Source MUX", "DAI Input Right", "DAIINR"},
908
909 {"DAC Right Source MUX", "ADC Output Left", "ADC Left"},
910 {"DAC Right Source MUX", "ADC Output Right", "ADC Right"},
911 {"DAC Right Source MUX", "DAI Input Left", "DAIINL"},
912 {"DAC Right Source MUX", "DAI Input Right", "DAIINR"},
913
914 {"DAC Left", NULL, "DAC Left Source MUX"},
915 {"DAC Right", NULL, "DAC Right Source MUX"},
916
917 {"Mixout Left", "Aux Left Switch", "Aux Left PGA"},
918 {"Mixout Left", "Mixin Left Switch", "Mixin Left PGA"},
919 {"Mixout Left", "Mixin Right Switch", "Mixin Right PGA"},
920 {"Mixout Left", "DAC Left Switch", "DAC Left"},
921 {"Mixout Left", "Aux Left Invert Switch", "Aux Left PGA"},
922 {"Mixout Left", "Mixin Left Invert Switch", "Mixin Left PGA"},
923 {"Mixout Left", "Mixin Right Invert Switch", "Mixin Right PGA"},
924
925 {"Mixout Right", "Aux Right Switch", "Aux Right PGA"},
926 {"Mixout Right", "Mixin Right Switch", "Mixin Right PGA"},
927 {"Mixout Right", "Mixin Left Switch", "Mixin Left PGA"},
928 {"Mixout Right", "DAC Right Switch", "DAC Right"},
929 {"Mixout Right", "Aux Right Invert Switch", "Aux Right PGA"},
930 {"Mixout Right", "Mixin Right Invert Switch", "Mixin Right PGA"},
931 {"Mixout Right", "Mixin Left Invert Switch", "Mixin Left PGA"},
932
933 {"Mixout Left PGA", NULL, "Mixout Left"},
934 {"Mixout Right PGA", NULL, "Mixout Right"},
935
936 {"Headphone Left PGA", NULL, "Mixout Left PGA"},
937 {"Headphone Left PGA", NULL, "Charge Pump"},
938 {"HPL", NULL, "Headphone Left PGA"},
939
940 {"Headphone Right PGA", NULL, "Mixout Right PGA"},
941 {"Headphone Right PGA", NULL, "Charge Pump"},
942 {"HPR", NULL, "Headphone Right PGA"},
943
944 {"Lineout PGA", NULL, "Mixout Right PGA"},
945 {"LINE", NULL, "Lineout PGA"},
946};
947
948static struct reg_default da7213_reg_defaults[] = {
949 { DA7213_DIG_ROUTING_DAI, 0x10 },
950 { DA7213_SR, 0x0A },
951 { DA7213_REFERENCES, 0x80 },
952 { DA7213_PLL_FRAC_TOP, 0x00 },
953 { DA7213_PLL_FRAC_BOT, 0x00 },
954 { DA7213_PLL_INTEGER, 0x20 },
955 { DA7213_PLL_CTRL, 0x0C },
956 { DA7213_DAI_CLK_MODE, 0x01 },
957 { DA7213_DAI_CTRL, 0x08 },
958 { DA7213_DIG_ROUTING_DAC, 0x32 },
959 { DA7213_AUX_L_GAIN, 0x35 },
960 { DA7213_AUX_R_GAIN, 0x35 },
961 { DA7213_MIXIN_L_SELECT, 0x00 },
962 { DA7213_MIXIN_R_SELECT, 0x00 },
963 { DA7213_MIXIN_L_GAIN, 0x03 },
964 { DA7213_MIXIN_R_GAIN, 0x03 },
965 { DA7213_ADC_L_GAIN, 0x6F },
966 { DA7213_ADC_R_GAIN, 0x6F },
967 { DA7213_ADC_FILTERS1, 0x80 },
968 { DA7213_MIC_1_GAIN, 0x01 },
969 { DA7213_MIC_2_GAIN, 0x01 },
970 { DA7213_DAC_FILTERS5, 0x00 },
971 { DA7213_DAC_FILTERS2, 0x88 },
972 { DA7213_DAC_FILTERS3, 0x88 },
973 { DA7213_DAC_FILTERS4, 0x08 },
974 { DA7213_DAC_FILTERS1, 0x80 },
975 { DA7213_DAC_L_GAIN, 0x6F },
976 { DA7213_DAC_R_GAIN, 0x6F },
977 { DA7213_CP_CTRL, 0x61 },
978 { DA7213_HP_L_GAIN, 0x39 },
979 { DA7213_HP_R_GAIN, 0x39 },
980 { DA7213_LINE_GAIN, 0x30 },
981 { DA7213_MIXOUT_L_SELECT, 0x00 },
982 { DA7213_MIXOUT_R_SELECT, 0x00 },
983 { DA7213_SYSTEM_MODES_INPUT, 0x00 },
984 { DA7213_SYSTEM_MODES_OUTPUT, 0x00 },
985 { DA7213_AUX_L_CTRL, 0x44 },
986 { DA7213_AUX_R_CTRL, 0x44 },
987 { DA7213_MICBIAS_CTRL, 0x11 },
988 { DA7213_MIC_1_CTRL, 0x40 },
989 { DA7213_MIC_2_CTRL, 0x40 },
990 { DA7213_MIXIN_L_CTRL, 0x40 },
991 { DA7213_MIXIN_R_CTRL, 0x40 },
992 { DA7213_ADC_L_CTRL, 0x40 },
993 { DA7213_ADC_R_CTRL, 0x40 },
994 { DA7213_DAC_L_CTRL, 0x48 },
995 { DA7213_DAC_R_CTRL, 0x40 },
996 { DA7213_HP_L_CTRL, 0x41 },
997 { DA7213_HP_R_CTRL, 0x40 },
998 { DA7213_LINE_CTRL, 0x40 },
999 { DA7213_MIXOUT_L_CTRL, 0x10 },
1000 { DA7213_MIXOUT_R_CTRL, 0x10 },
1001 { DA7213_LDO_CTRL, 0x00 },
1002 { DA7213_IO_CTRL, 0x00 },
1003 { DA7213_GAIN_RAMP_CTRL, 0x00},
1004 { DA7213_MIC_CONFIG, 0x00 },
1005 { DA7213_PC_COUNT, 0x00 },
1006 { DA7213_CP_VOL_THRESHOLD1, 0x32 },
1007 { DA7213_CP_DELAY, 0x95 },
1008 { DA7213_CP_DETECTOR, 0x00 },
1009 { DA7213_DAI_OFFSET, 0x00 },
1010 { DA7213_DIG_CTRL, 0x00 },
1011 { DA7213_ALC_CTRL2, 0x00 },
1012 { DA7213_ALC_CTRL3, 0x00 },
1013 { DA7213_ALC_NOISE, 0x3F },
1014 { DA7213_ALC_TARGET_MIN, 0x3F },
1015 { DA7213_ALC_TARGET_MAX, 0x00 },
1016 { DA7213_ALC_GAIN_LIMITS, 0xFF },
1017 { DA7213_ALC_ANA_GAIN_LIMITS, 0x71 },
1018 { DA7213_ALC_ANTICLIP_CTRL, 0x00 },
1019 { DA7213_ALC_ANTICLIP_LEVEL, 0x00 },
1020 { DA7213_ALC_OFFSET_MAN_M_L, 0x00 },
1021 { DA7213_ALC_OFFSET_MAN_U_L, 0x00 },
1022 { DA7213_ALC_OFFSET_MAN_M_R, 0x00 },
1023 { DA7213_ALC_OFFSET_MAN_U_R, 0x00 },
1024 { DA7213_ALC_CIC_OP_LVL_CTRL, 0x00 },
1025 { DA7213_DAC_NG_SETUP_TIME, 0x00 },
1026 { DA7213_DAC_NG_OFF_THRESHOLD, 0x00 },
1027 { DA7213_DAC_NG_ON_THRESHOLD, 0x00 },
1028 { DA7213_DAC_NG_CTRL, 0x00 },
1029};
1030
1031static bool da7213_volatile_register(struct device *dev, unsigned int reg)
1032{
1033 switch (reg) {
1034 case DA7213_STATUS1:
1035 case DA7213_PLL_STATUS:
1036 case DA7213_AUX_L_GAIN_STATUS:
1037 case DA7213_AUX_R_GAIN_STATUS:
1038 case DA7213_MIC_1_GAIN_STATUS:
1039 case DA7213_MIC_2_GAIN_STATUS:
1040 case DA7213_MIXIN_L_GAIN_STATUS:
1041 case DA7213_MIXIN_R_GAIN_STATUS:
1042 case DA7213_ADC_L_GAIN_STATUS:
1043 case DA7213_ADC_R_GAIN_STATUS:
1044 case DA7213_DAC_L_GAIN_STATUS:
1045 case DA7213_DAC_R_GAIN_STATUS:
1046 case DA7213_HP_L_GAIN_STATUS:
1047 case DA7213_HP_R_GAIN_STATUS:
1048 case DA7213_LINE_GAIN_STATUS:
1049 case DA7213_ALC_CTRL1:
1050 case DA7213_ALC_OFFSET_AUTO_M_L:
1051 case DA7213_ALC_OFFSET_AUTO_U_L:
1052 case DA7213_ALC_OFFSET_AUTO_M_R:
1053 case DA7213_ALC_OFFSET_AUTO_U_R:
1054 case DA7213_ALC_CIC_OP_LVL_DATA:
1055 return 1;
1056 default:
1057 return 0;
1058 }
1059}
1060
1061static int da7213_hw_params(struct snd_pcm_substream *substream,
1062 struct snd_pcm_hw_params *params,
1063 struct snd_soc_dai *dai)
1064{
1065 struct snd_soc_codec *codec = dai->codec;
1066 u8 dai_ctrl = 0;
1067 u8 fs;
1068
1069 /* Set DAI format */
1070 switch (params_format(params)) {
1071 case SNDRV_PCM_FORMAT_S16_LE:
1072 dai_ctrl |= DA7213_DAI_WORD_LENGTH_S16_LE;
1073 break;
1074 case SNDRV_PCM_FORMAT_S20_3LE:
1075 dai_ctrl |= DA7213_DAI_WORD_LENGTH_S20_LE;
1076 break;
1077 case SNDRV_PCM_FORMAT_S24_LE:
1078 dai_ctrl |= DA7213_DAI_WORD_LENGTH_S24_LE;
1079 break;
1080 case SNDRV_PCM_FORMAT_S32_LE:
1081 dai_ctrl |= DA7213_DAI_WORD_LENGTH_S32_LE;
1082 break;
1083 default:
1084 return -EINVAL;
1085 }
1086
1087 /* Set sampling rate */
1088 switch (params_rate(params)) {
1089 case 8000:
1090 fs = DA7213_SR_8000;
1091 break;
1092 case 11025:
1093 fs = DA7213_SR_11025;
1094 break;
1095 case 12000:
1096 fs = DA7213_SR_12000;
1097 break;
1098 case 16000:
1099 fs = DA7213_SR_16000;
1100 break;
1101 case 22050:
1102 fs = DA7213_SR_22050;
1103 break;
1104 case 32000:
1105 fs = DA7213_SR_32000;
1106 break;
1107 case 44100:
1108 fs = DA7213_SR_44100;
1109 break;
1110 case 48000:
1111 fs = DA7213_SR_48000;
1112 break;
1113 case 88200:
1114 fs = DA7213_SR_88200;
1115 break;
1116 case 96000:
1117 fs = DA7213_SR_96000;
1118 break;
1119 default:
1120 return -EINVAL;
1121 }
1122
1123 snd_soc_update_bits(codec, DA7213_DAI_CTRL, DA7213_DAI_WORD_LENGTH_MASK,
1124 dai_ctrl);
1125 snd_soc_write(codec, DA7213_SR, fs);
1126
1127 return 0;
1128}
1129
1130static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1131{
1132 struct snd_soc_codec *codec = codec_dai->codec;
1133 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1134 u8 dai_clk_mode = 0, dai_ctrl = 0;
1135
1136 /* Set master/slave mode */
1137 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1138 case SND_SOC_DAIFMT_CBM_CFM:
1139 dai_clk_mode |= DA7213_DAI_CLK_EN_MASTER_MODE;
1140 da7213->master = true;
1141 break;
1142 case SND_SOC_DAIFMT_CBS_CFS:
1143 dai_clk_mode |= DA7213_DAI_CLK_EN_SLAVE_MODE;
1144 da7213->master = false;
1145 break;
1146 default:
1147 return -EINVAL;
1148 }
1149
1150 /* Set clock normal/inverted */
1151 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1152 case SND_SOC_DAIFMT_NB_NF:
1153 break;
1154 case SND_SOC_DAIFMT_NB_IF:
1155 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV;
1156 break;
1157 case SND_SOC_DAIFMT_IB_NF:
1158 dai_clk_mode |= DA7213_DAI_CLK_POL_INV;
1159 break;
1160 case SND_SOC_DAIFMT_IB_IF:
1161 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV | DA7213_DAI_CLK_POL_INV;
1162 break;
1163 default:
1164 return -EINVAL;
1165 }
1166
1167 /* Only I2S is supported */
1168 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1169 case SND_SOC_DAIFMT_I2S:
1170 dai_ctrl |= DA7213_DAI_FORMAT_I2S_MODE;
1171 break;
1172 case SND_SOC_DAIFMT_LEFT_J:
1173 dai_ctrl |= DA7213_DAI_FORMAT_LEFT_J;
1174 break;
1175 case SND_SOC_DAIFMT_RIGHT_J:
1176 dai_ctrl |= DA7213_DAI_FORMAT_RIGHT_J;
1177 break;
1178 default:
1179 return -EINVAL;
1180 }
1181
1182 /* By default only 32 BCLK per WCLK is supported */
1183 dai_clk_mode |= DA7213_DAI_BCLKS_PER_WCLK_32;
1184
1185 snd_soc_write(codec, DA7213_DAI_CLK_MODE, dai_clk_mode);
1186 snd_soc_update_bits(codec, DA7213_DAI_CTRL, DA7213_DAI_FORMAT_MASK,
1187 dai_ctrl);
1188
1189 return 0;
1190}
1191
1192static int da7213_mute(struct snd_soc_dai *dai, int mute)
1193{
1194 struct snd_soc_codec *codec = dai->codec;
1195
1196 if (mute) {
1197 snd_soc_update_bits(codec, DA7213_DAC_L_CTRL,
1198 DA7213_MUTE_EN, DA7213_MUTE_EN);
1199 snd_soc_update_bits(codec, DA7213_DAC_R_CTRL,
1200 DA7213_MUTE_EN, DA7213_MUTE_EN);
1201 } else {
1202 snd_soc_update_bits(codec, DA7213_DAC_L_CTRL,
1203 DA7213_MUTE_EN, 0);
1204 snd_soc_update_bits(codec, DA7213_DAC_R_CTRL,
1205 DA7213_MUTE_EN, 0);
1206 }
1207
1208 return 0;
1209}
1210
1211#define DA7213_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1212 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1213
1214static int da7213_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1215 int clk_id, unsigned int freq, int dir)
1216{
1217 struct snd_soc_codec *codec = codec_dai->codec;
1218 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1219
1220 switch (clk_id) {
1221 case DA7213_CLKSRC_MCLK:
1222 if ((freq == 32768) ||
1223 ((freq >= 5000000) && (freq <= 54000000))) {
1224 da7213->mclk_rate = freq;
1225 return 0;
1226 } else {
1227 dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
1228 freq);
1229 return -EINVAL;
1230 }
1231 break;
1232 default:
1233 dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id);
1234 return -EINVAL;
1235 }
1236}
1237
1238/* Supported PLL input frequencies are 5MHz - 54MHz. */
1239static int da7213_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1240 int source, unsigned int fref, unsigned int fout)
1241{
1242 struct snd_soc_codec *codec = codec_dai->codec;
1243 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1244
1245 u8 pll_ctrl, indiv_bits, indiv;
1246 u8 pll_frac_top, pll_frac_bot, pll_integer;
1247 u32 freq_ref;
1248 u64 frac_div;
1249
1250 /* Reset PLL configuration */
1251 snd_soc_write(codec, DA7213_PLL_CTRL, 0);
1252
1253 pll_ctrl = 0;
1254
1255 /* Workout input divider based on MCLK rate */
1256 if ((da7213->mclk_rate == 32768) && (source == DA7213_SYSCLK_PLL)) {
1257 /* 32KHz PLL Mode */
1258 indiv_bits = DA7213_PLL_INDIV_10_20_MHZ;
1259 indiv = DA7213_PLL_INDIV_10_20_MHZ_VAL;
1260 freq_ref = 3750000;
1261 pll_ctrl |= DA7213_PLL_32K_MODE;
1262 } else {
1263 /* 5 - 54MHz MCLK */
1264 if (da7213->mclk_rate < 5000000) {
1265 goto pll_err;
1266 } else if (da7213->mclk_rate <= 10000000) {
1267 indiv_bits = DA7213_PLL_INDIV_5_10_MHZ;
1268 indiv = DA7213_PLL_INDIV_5_10_MHZ_VAL;
1269 } else if (da7213->mclk_rate <= 20000000) {
1270 indiv_bits = DA7213_PLL_INDIV_10_20_MHZ;
1271 indiv = DA7213_PLL_INDIV_10_20_MHZ_VAL;
1272 } else if (da7213->mclk_rate <= 40000000) {
1273 indiv_bits = DA7213_PLL_INDIV_20_40_MHZ;
1274 indiv = DA7213_PLL_INDIV_20_40_MHZ_VAL;
1275 } else if (da7213->mclk_rate <= 54000000) {
1276 indiv_bits = DA7213_PLL_INDIV_40_54_MHZ;
1277 indiv = DA7213_PLL_INDIV_40_54_MHZ_VAL;
1278 } else {
1279 goto pll_err;
1280 }
1281 freq_ref = (da7213->mclk_rate / indiv);
1282 }
1283
1284 pll_ctrl |= indiv_bits;
1285
1286 /* PLL Bypass mode */
1287 if (source == DA7213_SYSCLK_MCLK) {
1288 snd_soc_write(codec, DA7213_PLL_CTRL, pll_ctrl);
1289 return 0;
1290 }
1291
1292 /*
1293 * If Codec is slave and SRM enabled,
1294 * freq_out is (98304000 + 90316800)/2 = 94310400
1295 */
1296 if (!da7213->master && da7213->srm_en) {
1297 fout = DA7213_PLL_FREQ_OUT_94310400;
1298 pll_ctrl |= DA7213_PLL_SRM_EN;
1299 }
1300
1301 /* Enable MCLK squarer if required */
1302 if (da7213->mclk_squarer_en)
1303 pll_ctrl |= DA7213_PLL_MCLK_SQR_EN;
1304
1305 /* Calculate dividers for PLL */
1306 pll_integer = fout / freq_ref;
1307 frac_div = (u64)(fout % freq_ref) * 8192ULL;
1308 do_div(frac_div, freq_ref);
1309 pll_frac_top = (frac_div >> DA7213_BYTE_SHIFT) & DA7213_BYTE_MASK;
1310 pll_frac_bot = (frac_div) & DA7213_BYTE_MASK;
1311
1312 /* Write PLL dividers */
1313 snd_soc_write(codec, DA7213_PLL_FRAC_TOP, pll_frac_top);
1314 snd_soc_write(codec, DA7213_PLL_FRAC_BOT, pll_frac_bot);
1315 snd_soc_write(codec, DA7213_PLL_INTEGER, pll_integer);
1316
1317 /* Enable PLL */
1318 pll_ctrl |= DA7213_PLL_EN;
1319 snd_soc_write(codec, DA7213_PLL_CTRL, pll_ctrl);
1320
1321 return 0;
1322
1323pll_err:
1324 dev_err(codec_dai->dev, "Unsupported PLL input frequency %d\n",
1325 da7213->mclk_rate);
1326 return -EINVAL;
1327}
1328
1329/* DAI operations */
1330static const struct snd_soc_dai_ops da7213_dai_ops = {
1331 .hw_params = da7213_hw_params,
1332 .set_fmt = da7213_set_dai_fmt,
1333 .set_sysclk = da7213_set_dai_sysclk,
1334 .set_pll = da7213_set_dai_pll,
1335 .digital_mute = da7213_mute,
1336};
1337
1338static struct snd_soc_dai_driver da7213_dai = {
1339 .name = "da7213-hifi",
1340 /* Playback Capabilities */
1341 .playback = {
1342 .stream_name = "Playback",
1343 .channels_min = 1,
1344 .channels_max = 2,
1345 .rates = SNDRV_PCM_RATE_8000_96000,
1346 .formats = DA7213_FORMATS,
1347 },
1348 /* Capture Capabilities */
1349 .capture = {
1350 .stream_name = "Capture",
1351 .channels_min = 1,
1352 .channels_max = 2,
1353 .rates = SNDRV_PCM_RATE_8000_96000,
1354 .formats = DA7213_FORMATS,
1355 },
1356 .ops = &da7213_dai_ops,
1357 .symmetric_rates = 1,
1358};
1359
1360static int da7213_set_bias_level(struct snd_soc_codec *codec,
1361 enum snd_soc_bias_level level)
1362{
1363 switch (level) {
1364 case SND_SOC_BIAS_ON:
1365 case SND_SOC_BIAS_PREPARE:
1366 break;
1367 case SND_SOC_BIAS_STANDBY:
1368 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1369 /* Enable VMID reference & master bias */
1370 snd_soc_update_bits(codec, DA7213_REFERENCES,
1371 DA7213_VMID_EN | DA7213_BIAS_EN,
1372 DA7213_VMID_EN | DA7213_BIAS_EN);
1373 }
1374 break;
1375 case SND_SOC_BIAS_OFF:
1376 /* Disable VMID reference & master bias */
1377 snd_soc_update_bits(codec, DA7213_REFERENCES,
1378 DA7213_VMID_EN | DA7213_BIAS_EN, 0);
1379 break;
1380 }
1381 codec->dapm.bias_level = level;
1382 return 0;
1383}
1384
1385static int da7213_probe(struct snd_soc_codec *codec)
1386{
1387 int ret;
1388 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1389 struct da7213_platform_data *pdata = da7213->pdata;
1390
1391 codec->control_data = da7213->regmap;
1392 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1393 if (ret < 0) {
1394 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1395 return ret;
1396 }
1397
1398 /* Default to using ALC auto offset calibration mode. */
1399 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
1400 DA7213_ALC_CALIB_MODE_MAN, 0);
1401 da7213->alc_calib_auto = true;
1402
1403 /* Default to using SRM for slave mode */
1404 da7213->srm_en = true;
1405
1406 /* Enable all Gain Ramps */
1407 snd_soc_update_bits(codec, DA7213_AUX_L_CTRL,
1408 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1409 snd_soc_update_bits(codec, DA7213_AUX_R_CTRL,
1410 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1411 snd_soc_update_bits(codec, DA7213_MIXIN_L_CTRL,
1412 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1413 snd_soc_update_bits(codec, DA7213_MIXIN_R_CTRL,
1414 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1415 snd_soc_update_bits(codec, DA7213_ADC_L_CTRL,
1416 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1417 snd_soc_update_bits(codec, DA7213_ADC_R_CTRL,
1418 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1419 snd_soc_update_bits(codec, DA7213_DAC_L_CTRL,
1420 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1421 snd_soc_update_bits(codec, DA7213_DAC_R_CTRL,
1422 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1423 snd_soc_update_bits(codec, DA7213_HP_L_CTRL,
1424 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1425 snd_soc_update_bits(codec, DA7213_HP_R_CTRL,
1426 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1427 snd_soc_update_bits(codec, DA7213_LINE_CTRL,
1428 DA7213_GAIN_RAMP_EN, DA7213_GAIN_RAMP_EN);
1429
1430 /*
1431 * There are two separate control bits for input and output mixers as
1432 * well as headphone and line outs.
1433 * One to enable corresponding amplifier and other to enable its
1434 * output. As amplifier bits are related to power control, they are
1435 * being managed by DAPM while other (non power related) bits are
1436 * enabled here
1437 */
1438 snd_soc_update_bits(codec, DA7213_MIXIN_L_CTRL,
1439 DA7213_MIXIN_MIX_EN, DA7213_MIXIN_MIX_EN);
1440 snd_soc_update_bits(codec, DA7213_MIXIN_R_CTRL,
1441 DA7213_MIXIN_MIX_EN, DA7213_MIXIN_MIX_EN);
1442
1443 snd_soc_update_bits(codec, DA7213_MIXOUT_L_CTRL,
1444 DA7213_MIXOUT_MIX_EN, DA7213_MIXOUT_MIX_EN);
1445 snd_soc_update_bits(codec, DA7213_MIXOUT_R_CTRL,
1446 DA7213_MIXOUT_MIX_EN, DA7213_MIXOUT_MIX_EN);
1447
1448 snd_soc_update_bits(codec, DA7213_HP_L_CTRL,
1449 DA7213_HP_AMP_OE, DA7213_HP_AMP_OE);
1450 snd_soc_update_bits(codec, DA7213_HP_R_CTRL,
1451 DA7213_HP_AMP_OE, DA7213_HP_AMP_OE);
1452
1453 snd_soc_update_bits(codec, DA7213_LINE_CTRL,
1454 DA7213_LINE_AMP_OE, DA7213_LINE_AMP_OE);
1455
1456 /* Set platform data values */
1457 if (da7213->pdata) {
1458 u8 micbias_lvl = 0, dmic_cfg = 0;
1459
1460 /* Set Mic Bias voltages */
1461 switch (pdata->micbias1_lvl) {
1462 case DA7213_MICBIAS_1_6V:
1463 case DA7213_MICBIAS_2_2V:
1464 case DA7213_MICBIAS_2_5V:
1465 case DA7213_MICBIAS_3_0V:
1466 micbias_lvl |= (pdata->micbias1_lvl <<
1467 DA7213_MICBIAS1_LEVEL_SHIFT);
1468 break;
1469 }
1470 switch (pdata->micbias2_lvl) {
1471 case DA7213_MICBIAS_1_6V:
1472 case DA7213_MICBIAS_2_2V:
1473 case DA7213_MICBIAS_2_5V:
1474 case DA7213_MICBIAS_3_0V:
1475 micbias_lvl |= (pdata->micbias2_lvl <<
1476 DA7213_MICBIAS2_LEVEL_SHIFT);
1477 break;
1478 }
1479 snd_soc_update_bits(codec, DA7213_MICBIAS_CTRL,
1480 DA7213_MICBIAS1_LEVEL_MASK |
1481 DA7213_MICBIAS2_LEVEL_MASK, micbias_lvl);
1482
1483 /* Set DMIC configuration */
1484 switch (pdata->dmic_data_sel) {
1485 case DA7213_DMIC_DATA_LFALL_RRISE:
1486 case DA7213_DMIC_DATA_LRISE_RFALL:
1487 dmic_cfg |= (pdata->dmic_data_sel <<
1488 DA7213_DMIC_DATA_SEL_SHIFT);
1489 break;
1490 }
1491 switch (pdata->dmic_data_sel) {
1492 case DA7213_DMIC_SAMPLE_ON_CLKEDGE:
1493 case DA7213_DMIC_SAMPLE_BETWEEN_CLKEDGE:
1494 dmic_cfg |= (pdata->dmic_data_sel <<
1495 DA7213_DMIC_SAMPLEPHASE_SHIFT);
1496 break;
1497 }
1498 switch (pdata->dmic_data_sel) {
1499 case DA7213_DMIC_CLK_3_0MHZ:
1500 case DA7213_DMIC_CLK_1_5MHZ:
1501 dmic_cfg |= (pdata->dmic_data_sel <<
1502 DA7213_DMIC_CLK_RATE_SHIFT);
1503 break;
1504 }
1505 snd_soc_update_bits(codec, DA7213_MIC_CONFIG,
1506 DA7213_DMIC_DATA_SEL_MASK |
1507 DA7213_DMIC_SAMPLEPHASE_MASK |
1508 DA7213_DMIC_CLK_RATE_MASK, dmic_cfg);
1509
1510 /* Set MCLK squaring */
1511 da7213->mclk_squarer_en = pdata->mclk_squaring;
1512 }
1513 return 0;
1514}
1515
1516static struct snd_soc_codec_driver soc_codec_dev_da7213 = {
1517 .probe = da7213_probe,
1518 .set_bias_level = da7213_set_bias_level,
1519
1520 .controls = da7213_snd_controls,
1521 .num_controls = ARRAY_SIZE(da7213_snd_controls),
1522
1523 .dapm_widgets = da7213_dapm_widgets,
1524 .num_dapm_widgets = ARRAY_SIZE(da7213_dapm_widgets),
1525 .dapm_routes = da7213_audio_map,
1526 .num_dapm_routes = ARRAY_SIZE(da7213_audio_map),
1527};
1528
1529static const struct regmap_config da7213_regmap_config = {
1530 .reg_bits = 8,
1531 .val_bits = 8,
1532
1533 .reg_defaults = da7213_reg_defaults,
1534 .num_reg_defaults = ARRAY_SIZE(da7213_reg_defaults),
1535 .volatile_reg = da7213_volatile_register,
1536 .cache_type = REGCACHE_RBTREE,
1537};
1538
1539static int da7213_i2c_probe(struct i2c_client *i2c,
1540 const struct i2c_device_id *id)
1541{
1542 struct da7213_priv *da7213;
1543 struct da7213_platform_data *pdata = dev_get_platdata(&i2c->dev);
1544 int ret;
1545
1546 da7213 = devm_kzalloc(&i2c->dev, sizeof(struct da7213_priv),
1547 GFP_KERNEL);
1548 if (!da7213)
1549 return -ENOMEM;
1550
1551 if (pdata)
1552 da7213->pdata = pdata;
1553
1554 i2c_set_clientdata(i2c, da7213);
1555
1556 da7213->regmap = devm_regmap_init_i2c(i2c, &da7213_regmap_config);
1557 if (IS_ERR(da7213->regmap)) {
1558 ret = PTR_ERR(da7213->regmap);
1559 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1560 return ret;
1561 }
1562
1563 ret = snd_soc_register_codec(&i2c->dev,
1564 &soc_codec_dev_da7213, &da7213_dai, 1);
1565 if (ret < 0) {
1566 dev_err(&i2c->dev, "Failed to register da7213 codec: %d\n",
1567 ret);
1568 }
1569 return ret;
1570}
1571
1572static int da7213_remove(struct i2c_client *client)
1573{
1574 snd_soc_unregister_codec(&client->dev);
1575 return 0;
1576}
1577
1578static const struct i2c_device_id da7213_i2c_id[] = {
1579 { "da7213", 0 },
1580 { }
1581};
1582MODULE_DEVICE_TABLE(i2c, da7213_i2c_id);
1583
1584/* I2C codec control layer */
1585static struct i2c_driver da7213_i2c_driver = {
1586 .driver = {
1587 .name = "da7213",
1588 .owner = THIS_MODULE,
1589 },
1590 .probe = da7213_i2c_probe,
1591 .remove = da7213_remove,
1592 .id_table = da7213_i2c_id,
1593};
1594
1595module_i2c_driver(da7213_i2c_driver);
1596
1597MODULE_DESCRIPTION("ASoC DA7213 Codec driver");
1598MODULE_AUTHOR("Adam Thomson <Adam.Thomson.Opensource@diasemi.com>");
1599MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/da7213.h b/sound/soc/codecs/da7213.h
new file mode 100644
index 000000000000..9cb9ddd01282
--- /dev/null
+++ b/sound/soc/codecs/da7213.h
@@ -0,0 +1,523 @@
1/*
2 * da7213.h - DA7213 ASoC Codec Driver
3 *
4 * Copyright (c) 2013 Dialog Semiconductor
5 *
6 * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#ifndef _DA7213_H
14#define _DA7213_H
15
16#include <linux/regmap.h>
17#include <sound/da7213.h>
18
19/*
20 * Registers
21 */
22
23/* Status Registers */
24#define DA7213_STATUS1 0x02
25#define DA7213_PLL_STATUS 0x03
26#define DA7213_AUX_L_GAIN_STATUS 0x04
27#define DA7213_AUX_R_GAIN_STATUS 0x05
28#define DA7213_MIC_1_GAIN_STATUS 0x06
29#define DA7213_MIC_2_GAIN_STATUS 0x07
30#define DA7213_MIXIN_L_GAIN_STATUS 0x08
31#define DA7213_MIXIN_R_GAIN_STATUS 0x09
32#define DA7213_ADC_L_GAIN_STATUS 0x0A
33#define DA7213_ADC_R_GAIN_STATUS 0x0B
34#define DA7213_DAC_L_GAIN_STATUS 0x0C
35#define DA7213_DAC_R_GAIN_STATUS 0x0D
36#define DA7213_HP_L_GAIN_STATUS 0x0E
37#define DA7213_HP_R_GAIN_STATUS 0x0F
38#define DA7213_LINE_GAIN_STATUS 0x10
39
40/* System Initialisation Registers */
41#define DA7213_DIG_ROUTING_DAI 0x21
42#define DA7213_SR 0x22
43#define DA7213_REFERENCES 0x23
44#define DA7213_PLL_FRAC_TOP 0x24
45#define DA7213_PLL_FRAC_BOT 0x25
46#define DA7213_PLL_INTEGER 0x26
47#define DA7213_PLL_CTRL 0x27
48#define DA7213_DAI_CLK_MODE 0x28
49#define DA7213_DAI_CTRL 0x29
50#define DA7213_DIG_ROUTING_DAC 0x2A
51#define DA7213_ALC_CTRL1 0x2B
52
53/* Input - Gain, Select and Filter Registers */
54#define DA7213_AUX_L_GAIN 0x30
55#define DA7213_AUX_R_GAIN 0x31
56#define DA7213_MIXIN_L_SELECT 0x32
57#define DA7213_MIXIN_R_SELECT 0x33
58#define DA7213_MIXIN_L_GAIN 0x34
59#define DA7213_MIXIN_R_GAIN 0x35
60#define DA7213_ADC_L_GAIN 0x36
61#define DA7213_ADC_R_GAIN 0x37
62#define DA7213_ADC_FILTERS1 0x38
63#define DA7213_MIC_1_GAIN 0x39
64#define DA7213_MIC_2_GAIN 0x3A
65
66/* Output - Gain, Select and Filter Registers */
67#define DA7213_DAC_FILTERS5 0x40
68#define DA7213_DAC_FILTERS2 0x41
69#define DA7213_DAC_FILTERS3 0x42
70#define DA7213_DAC_FILTERS4 0x43
71#define DA7213_DAC_FILTERS1 0x44
72#define DA7213_DAC_L_GAIN 0x45
73#define DA7213_DAC_R_GAIN 0x46
74#define DA7213_CP_CTRL 0x47
75#define DA7213_HP_L_GAIN 0x48
76#define DA7213_HP_R_GAIN 0x49
77#define DA7213_LINE_GAIN 0x4A
78#define DA7213_MIXOUT_L_SELECT 0x4B
79#define DA7213_MIXOUT_R_SELECT 0x4C
80
81/* System Controller Registers */
82#define DA7213_SYSTEM_MODES_INPUT 0x50
83#define DA7213_SYSTEM_MODES_OUTPUT 0x51
84
85/* Control Registers */
86#define DA7213_AUX_L_CTRL 0x60
87#define DA7213_AUX_R_CTRL 0x61
88#define DA7213_MICBIAS_CTRL 0x62
89#define DA7213_MIC_1_CTRL 0x63
90#define DA7213_MIC_2_CTRL 0x64
91#define DA7213_MIXIN_L_CTRL 0x65
92#define DA7213_MIXIN_R_CTRL 0x66
93#define DA7213_ADC_L_CTRL 0x67
94#define DA7213_ADC_R_CTRL 0x68
95#define DA7213_DAC_L_CTRL 0x69
96#define DA7213_DAC_R_CTRL 0x6A
97#define DA7213_HP_L_CTRL 0x6B
98#define DA7213_HP_R_CTRL 0x6C
99#define DA7213_LINE_CTRL 0x6D
100#define DA7213_MIXOUT_L_CTRL 0x6E
101#define DA7213_MIXOUT_R_CTRL 0x6F
102
103/* Configuration Registers */
104#define DA7213_LDO_CTRL 0x90
105#define DA7213_IO_CTRL 0x91
106#define DA7213_GAIN_RAMP_CTRL 0x92
107#define DA7213_MIC_CONFIG 0x93
108#define DA7213_PC_COUNT 0x94
109#define DA7213_CP_VOL_THRESHOLD1 0x95
110#define DA7213_CP_DELAY 0x96
111#define DA7213_CP_DETECTOR 0x97
112#define DA7213_DAI_OFFSET 0x98
113#define DA7213_DIG_CTRL 0x99
114#define DA7213_ALC_CTRL2 0x9A
115#define DA7213_ALC_CTRL3 0x9B
116#define DA7213_ALC_NOISE 0x9C
117#define DA7213_ALC_TARGET_MIN 0x9D
118#define DA7213_ALC_TARGET_MAX 0x9E
119#define DA7213_ALC_GAIN_LIMITS 0x9F
120#define DA7213_ALC_ANA_GAIN_LIMITS 0xA0
121#define DA7213_ALC_ANTICLIP_CTRL 0xA1
122#define DA7213_ALC_ANTICLIP_LEVEL 0xA2
123
124#define DA7213_ALC_OFFSET_AUTO_M_L 0xA3
125#define DA7213_ALC_OFFSET_AUTO_U_L 0xA4
126#define DA7213_ALC_OFFSET_MAN_M_L 0xA6
127#define DA7213_ALC_OFFSET_MAN_U_L 0xA7
128#define DA7213_ALC_OFFSET_AUTO_M_R 0xA8
129#define DA7213_ALC_OFFSET_AUTO_U_R 0xA9
130#define DA7213_ALC_OFFSET_MAN_M_R 0xAB
131#define DA7213_ALC_OFFSET_MAN_U_R 0xAC
132#define DA7213_ALC_CIC_OP_LVL_CTRL 0xAD
133#define DA7213_ALC_CIC_OP_LVL_DATA 0xAE
134#define DA7213_DAC_NG_SETUP_TIME 0xAF
135#define DA7213_DAC_NG_OFF_THRESHOLD 0xB0
136#define DA7213_DAC_NG_ON_THRESHOLD 0xB1
137#define DA7213_DAC_NG_CTRL 0xB2
138
139
140/*
141 * Bit fields
142 */
143
144/* DA7213_SR = 0x22 */
145#define DA7213_SR_8000 (0x1 << 0)
146#define DA7213_SR_11025 (0x2 << 0)
147#define DA7213_SR_12000 (0x3 << 0)
148#define DA7213_SR_16000 (0x5 << 0)
149#define DA7213_SR_22050 (0x6 << 0)
150#define DA7213_SR_24000 (0x7 << 0)
151#define DA7213_SR_32000 (0x9 << 0)
152#define DA7213_SR_44100 (0xA << 0)
153#define DA7213_SR_48000 (0xB << 0)
154#define DA7213_SR_88200 (0xE << 0)
155#define DA7213_SR_96000 (0xF << 0)
156
157/* DA7213_REFERENCES = 0x23 */
158#define DA7213_BIAS_EN (0x1 << 3)
159#define DA7213_VMID_EN (0x1 << 7)
160
161/* DA7213_PLL_CTRL = 0x27 */
162#define DA7213_PLL_INDIV_5_10_MHZ (0x0 << 2)
163#define DA7213_PLL_INDIV_10_20_MHZ (0x1 << 2)
164#define DA7213_PLL_INDIV_20_40_MHZ (0x2 << 2)
165#define DA7213_PLL_INDIV_40_54_MHZ (0x3 << 2)
166#define DA7213_PLL_INDIV_MASK (0x3 << 2)
167#define DA7213_PLL_MCLK_SQR_EN (0x1 << 4)
168#define DA7213_PLL_32K_MODE (0x1 << 5)
169#define DA7213_PLL_SRM_EN (0x1 << 6)
170#define DA7213_PLL_EN (0x1 << 7)
171
172/* DA7213_DAI_CLK_MODE = 0x28 */
173#define DA7213_DAI_BCLKS_PER_WCLK_32 (0x0 << 0)
174#define DA7213_DAI_BCLKS_PER_WCLK_64 (0x1 << 0)
175#define DA7213_DAI_BCLKS_PER_WCLK_128 (0x2 << 0)
176#define DA7213_DAI_BCLKS_PER_WCLK_256 (0x3 << 0)
177#define DA7213_DAI_BCLKS_PER_WCLK_MASK (0x3 << 0)
178#define DA7213_DAI_CLK_POL_INV (0x1 << 2)
179#define DA7213_DAI_WCLK_POL_INV (0x1 << 3)
180#define DA7213_DAI_CLK_EN_SLAVE_MODE (0x0 << 7)
181#define DA7213_DAI_CLK_EN_MASTER_MODE (0x1 << 7)
182#define DA7213_DAI_CLK_EN_MASK (0x1 << 7)
183
184/* DA7213_DAI_CTRL = 0x29 */
185#define DA7213_DAI_FORMAT_I2S_MODE (0x0 << 0)
186#define DA7213_DAI_FORMAT_LEFT_J (0x1 << 0)
187#define DA7213_DAI_FORMAT_RIGHT_J (0x2 << 0)
188#define DA7213_DAI_FORMAT_MASK (0x3 << 0)
189#define DA7213_DAI_WORD_LENGTH_S16_LE (0x0 << 2)
190#define DA7213_DAI_WORD_LENGTH_S20_LE (0x1 << 2)
191#define DA7213_DAI_WORD_LENGTH_S24_LE (0x2 << 2)
192#define DA7213_DAI_WORD_LENGTH_S32_LE (0x3 << 2)
193#define DA7213_DAI_WORD_LENGTH_MASK (0x3 << 2)
194#define DA7213_DAI_EN_SHIFT 7
195
196/* DA7213_DIG_ROUTING_DAI = 0x21 */
197#define DA7213_DAI_L_SRC_SHIFT 0
198#define DA7213_DAI_R_SRC_SHIFT 4
199#define DA7213_DAI_SRC_MAX 4
200
201/* DA7213_DIG_ROUTING_DAC = 0x2A */
202#define DA7213_DAC_L_SRC_SHIFT 0
203#define DA7213_DAC_L_MONO_SHIFT 3
204#define DA7213_DAC_R_SRC_SHIFT 4
205#define DA7213_DAC_R_MONO_SHIFT 7
206#define DA7213_DAC_SRC_MAX 4
207#define DA7213_DAC_MONO_MAX 0x1
208
209/* DA7213_ALC_CTRL1 = 0x2B */
210#define DA7213_ALC_OFFSET_EN_SHIFT 0
211#define DA7213_ALC_OFFSET_EN_MAX 0x1
212#define DA7213_ALC_OFFSET_EN (0x1 << 0)
213#define DA7213_ALC_SYNC_MODE (0x1 << 1)
214#define DA7213_ALC_CALIB_MODE_MAN (0x1 << 2)
215#define DA7213_ALC_L_EN_SHIFT 3
216#define DA7213_ALC_AUTO_CALIB_EN (0x1 << 4)
217#define DA7213_ALC_CALIB_OVERFLOW (0x1 << 5)
218#define DA7213_ALC_R_EN_SHIFT 7
219#define DA7213_ALC_EN_MAX 0x1
220
221/* DA7213_AUX_L/R_GAIN = 0x30/0x31 */
222#define DA7213_AUX_AMP_GAIN_SHIFT 0
223#define DA7213_AUX_AMP_GAIN_MAX 0x3F
224
225/* DA7213_MIXIN_L/R_SELECT = 0x32/0x33 */
226#define DA7213_DMIC_EN_SHIFT 7
227#define DA7213_DMIC_EN_MAX 0x1
228
229/* DA7213_MIXIN_L_SELECT = 0x32 */
230#define DA7213_MIXIN_L_MIX_SELECT_AUX_L_SHIFT 0
231#define DA7213_MIXIN_L_MIX_SELECT_MIC_1_SHIFT 1
232#define DA7213_MIXIN_L_MIX_SELECT_MIC_1 (0x1 << 1)
233#define DA7213_MIXIN_L_MIX_SELECT_MIC_2_SHIFT 2
234#define DA7213_MIXIN_L_MIX_SELECT_MIC_2 (0x1 << 2)
235#define DA7213_MIXIN_L_MIX_SELECT_MIXIN_R_SHIFT 3
236#define DA7213_MIXIN_L_MIX_SELECT_MAX 0x1
237
238/* DA7213_MIXIN_R_SELECT = 0x33 */
239#define DA7213_MIXIN_R_MIX_SELECT_AUX_R_SHIFT 0
240#define DA7213_MIXIN_R_MIX_SELECT_MIC_2_SHIFT 1
241#define DA7213_MIXIN_R_MIX_SELECT_MIC_2 (0x1 << 1)
242#define DA7213_MIXIN_R_MIX_SELECT_MIC_1_SHIFT 2
243#define DA7213_MIXIN_R_MIX_SELECT_MIC_1 (0x1 << 2)
244#define DA7213_MIXIN_R_MIX_SELECT_MIXIN_L_SHIFT 3
245#define DA7213_MIXIN_R_MIX_SELECT_MAX 0x1
246#define DA7213_MIC_BIAS_OUTPUT_SELECT_2 (0x1 << 6)
247
248/* DA7213_MIXIN_L/R_GAIN = 0x34/0x35 */
249#define DA7213_MIXIN_AMP_GAIN_SHIFT 0
250#define DA7213_MIXIN_AMP_GAIN_MAX 0xF
251
252/* DA7213_ADC_L/R_GAIN = 0x36/0x37 */
253#define DA7213_ADC_AMP_GAIN_SHIFT 0
254#define DA7213_ADC_AMP_GAIN_MAX 0x7F
255
256/* DA7213_ADC/DAC_FILTERS1 = 0x38/0x44 */
257#define DA7213_VOICE_HPF_CORNER_SHIFT 0
258#define DA7213_VOICE_HPF_CORNER_MAX 8
259#define DA7213_VOICE_EN_SHIFT 3
260#define DA7213_VOICE_EN_MAX 0x1
261#define DA7213_AUDIO_HPF_CORNER_SHIFT 4
262#define DA7213_AUDIO_HPF_CORNER_MAX 4
263#define DA7213_HPF_EN_SHIFT 7
264#define DA7213_HPF_EN_MAX 0x1
265
266/* DA7213_MIC_1/2_GAIN = 0x39/0x3A */
267#define DA7213_MIC_AMP_GAIN_SHIFT 0
268#define DA7213_MIC_AMP_GAIN_MAX 0x7
269
270/* DA7213_DAC_FILTERS5 = 0x40 */
271#define DA7213_DAC_SOFTMUTE_EN_SHIFT 7
272#define DA7213_DAC_SOFTMUTE_EN_MAX 0x1
273#define DA7213_DAC_SOFTMUTE_RATE_SHIFT 4
274#define DA7213_DAC_SOFTMUTE_RATE_MAX 7
275
276/* DA7213_DAC_FILTERS2/3/4 = 0x41/0x42/0x43 */
277#define DA7213_DAC_EQ_BAND_MAX 0xF
278
279/* DA7213_DAC_FILTERS2 = 0x41 */
280#define DA7213_DAC_EQ_BAND1_SHIFT 0
281#define DA7213_DAC_EQ_BAND2_SHIFT 4
282
283/* DA7213_DAC_FILTERS2 = 0x42 */
284#define DA7213_DAC_EQ_BAND3_SHIFT 0
285#define DA7213_DAC_EQ_BAND4_SHIFT 4
286
287/* DA7213_DAC_FILTERS4 = 0x43 */
288#define DA7213_DAC_EQ_BAND5_SHIFT 0
289#define DA7213_DAC_EQ_EN_SHIFT 7
290#define DA7213_DAC_EQ_EN_MAX 0x1
291
292/* DA7213_DAC_L/R_GAIN = 0x45/0x46 */
293#define DA7213_DAC_AMP_GAIN_SHIFT 0
294#define DA7213_DAC_AMP_GAIN_MAX 0x7F
295
296/* DA7213_HP_L/R_GAIN = 0x45/0x46 */
297#define DA7213_HP_AMP_GAIN_SHIFT 0
298#define DA7213_HP_AMP_GAIN_MAX 0x3F
299
300/* DA7213_CP_CTRL = 0x47 */
301#define DA7213_CP_EN_SHIFT 7
302
303/* DA7213_LINE_GAIN = 0x4A */
304#define DA7213_LINE_AMP_GAIN_SHIFT 0
305#define DA7213_LINE_AMP_GAIN_MAX 0x3F
306
307/* DA7213_MIXOUT_L_SELECT = 0x4B */
308#define DA7213_MIXOUT_L_MIX_SELECT_AUX_L_SHIFT 0
309#define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_SHIFT 1
310#define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_SHIFT 2
311#define DA7213_MIXOUT_L_MIX_SELECT_DAC_L_SHIFT 3
312#define DA7213_MIXOUT_L_MIX_SELECT_AUX_L_INVERTED_SHIFT 4
313#define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_INVERTED_SHIFT 5
314#define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_INVERTED_SHIFT 6
315#define DA7213_MIXOUT_L_MIX_SELECT_MAX 0x1
316
317/* DA7213_MIXOUT_R_SELECT = 0x4C */
318#define DA7213_MIXOUT_R_MIX_SELECT_AUX_R_SHIFT 0
319#define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_SHIFT 1
320#define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_SHIFT 2
321#define DA7213_MIXOUT_R_MIX_SELECT_DAC_R_SHIFT 3
322#define DA7213_MIXOUT_R_MIX_SELECT_AUX_R_INVERTED_SHIFT 4
323#define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_INVERTED_SHIFT 5
324#define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_INVERTED_SHIFT 6
325#define DA7213_MIXOUT_R_MIX_SELECT_MAX 0x1
326
327/*
328 * DA7213_AUX_L/R_CTRL = 0x60/0x61,
329 * DA7213_MIC_1/2_CTRL = 0x63/0x64,
330 * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
331 * DA7213_ADC_L/R_CTRL = 0x65/0x66,
332 * DA7213_DAC_L/R_CTRL = 0x69/0x6A,
333 * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
334 * DA7213_LINE_CTRL = 0x6D
335 */
336#define DA7213_MUTE_EN_SHIFT 6
337#define DA7213_MUTE_EN_MAX 0x1
338#define DA7213_MUTE_EN (0x1 << 6)
339
340/*
341 * DA7213_AUX_L/R_CTRL = 0x60/0x61,
342 * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
343 * DA7213_ADC_L/R_CTRL = 0x65/0x66,
344 * DA7213_DAC_L/R_CTRL = 0x69/0x6A,
345 * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
346 * DA7213_LINE_CTRL = 0x6D
347 */
348#define DA7213_GAIN_RAMP_EN_SHIFT 5
349#define DA7213_GAIN_RAMP_EN_MAX 0x1
350#define DA7213_GAIN_RAMP_EN (0x1 << 5)
351
352/*
353 * DA7213_AUX_L/R_CTRL = 0x60/0x61,
354 * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
355 * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
356 * DA7213_LINE_CTRL = 0x6D
357 */
358#define DA7213_ZC_EN_SHIFT 4
359#define DA7213_ZC_EN_MAX 0x1
360
361/*
362 * DA7213_AUX_L/R_CTRL = 0x60/0x61,
363 * DA7213_MIC_1/2_CTRL = 0x63/0x64,
364 * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
365 * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
366 * DA7213_MIXOUT_L/R_CTRL = 0x6E/0x6F,
367 * DA7213_LINE_CTRL = 0x6D
368 */
369#define DA7213_AMP_EN_SHIFT 7
370
371/* DA7213_MIC_1/2_CTRL = 0x63/0x64 */
372#define DA7213_MIC_AMP_IN_SEL_SHIFT 2
373#define DA7213_MIC_AMP_IN_SEL_MAX 3
374
375/* DA7213_MICBIAS_CTRL = 0x62 */
376#define DA7213_MICBIAS1_LEVEL_SHIFT 0
377#define DA7213_MICBIAS1_LEVEL_MASK (0x3 << 0)
378#define DA7213_MICBIAS1_EN_SHIFT 3
379#define DA7213_MICBIAS2_LEVEL_SHIFT 4
380#define DA7213_MICBIAS2_LEVEL_MASK (0x3 << 4)
381#define DA7213_MICBIAS2_EN_SHIFT 7
382
383/* DA7213_MIXIN_L/R_CTRL = 0x65/0x66 */
384#define DA7213_MIXIN_MIX_EN (0x1 << 3)
385
386/* DA7213_ADC_L/R_CTRL = 0x67/0x68 */
387#define DA7213_ADC_EN_SHIFT 7
388#define DA7213_ADC_EN (0x1 << 7)
389
390/* DA7213_DAC_L/R_CTRL = 0x69/0x6A*/
391#define DA7213_DAC_EN_SHIFT 7
392
393/* DA7213_HP_L/R_CTRL = 0x6B/0x6C */
394#define DA7213_HP_AMP_OE (0x1 << 3)
395
396/* DA7213_LINE_CTRL = 0x6D */
397#define DA7213_LINE_AMP_OE (0x1 << 3)
398
399/* DA7213_MIXOUT_L/R_CTRL = 0x6E/0x6F */
400#define DA7213_MIXOUT_MIX_EN (0x1 << 3)
401
402/* DA7213_GAIN_RAMP_CTRL = 0x92 */
403#define DA7213_GAIN_RAMP_RATE_SHIFT 0
404#define DA7213_GAIN_RAMP_RATE_MAX 4
405
406/* DA7213_MIC_CONFIG = 0x93 */
407#define DA7213_DMIC_DATA_SEL_SHIFT 0
408#define DA7213_DMIC_DATA_SEL_MASK (0x1 << 0)
409#define DA7213_DMIC_SAMPLEPHASE_SHIFT 1
410#define DA7213_DMIC_SAMPLEPHASE_MASK (0x1 << 1)
411#define DA7213_DMIC_CLK_RATE_SHIFT 2
412#define DA7213_DMIC_CLK_RATE_MASK (0x1 << 2)
413
414/* DA7213_DIG_CTRL = 0x99 */
415#define DA7213_DAC_L_INV_SHIFT 3
416#define DA7213_DAC_R_INV_SHIFT 7
417#define DA7213_DAC_INV_MAX 0x1
418
419/* DA7213_ALC_CTRL2 = 0x9A */
420#define DA7213_ALC_ATTACK_SHIFT 0
421#define DA7213_ALC_ATTACK_MAX 13
422#define DA7213_ALC_RELEASE_SHIFT 4
423#define DA7213_ALC_RELEASE_MAX 11
424
425/* DA7213_ALC_CTRL3 = 0x9B */
426#define DA7213_ALC_HOLD_SHIFT 0
427#define DA7213_ALC_HOLD_MAX 16
428#define DA7213_ALC_INTEG_ATTACK_SHIFT 4
429#define DA7213_ALC_INTEG_RELEASE_SHIFT 6
430#define DA7213_ALC_INTEG_MAX 4
431
432/*
433 * DA7213_ALC_NOISE = 0x9C,
434 * DA7213_ALC_TARGET_MIN/MAX = 0x9D/0x9E
435 */
436#define DA7213_ALC_THRESHOLD_SHIFT 0
437#define DA7213_ALC_THRESHOLD_MAX 0x3F
438
439/* DA7213_ALC_GAIN_LIMITS = 0x9F */
440#define DA7213_ALC_ATTEN_MAX_SHIFT 0
441#define DA7213_ALC_GAIN_MAX_SHIFT 4
442#define DA7213_ALC_ATTEN_GAIN_MAX_MAX 0xF
443
444/* DA7213_ALC_ANA_GAIN_LIMITS = 0xA0 */
445#define DA7213_ALC_ANA_GAIN_MIN_SHIFT 0
446#define DA7213_ALC_ANA_GAIN_MAX_SHIFT 4
447#define DA7213_ALC_ANA_GAIN_MAX 0x7
448
449/* DA7213_ALC_ANTICLIP_CTRL = 0xA1 */
450#define DA7213_ALC_ANTICLIP_EN_SHIFT 7
451#define DA7213_ALC_ANTICLIP_EN_MAX 0x1
452
453/* DA7213_ALC_ANTICLIP_LEVEL = 0xA2 */
454#define DA7213_ALC_ANTICLIP_LEVEL_SHIFT 0
455#define DA7213_ALC_ANTICLIP_LEVEL_MAX 0x7F
456
457/* DA7213_ALC_CIC_OP_LVL_CTRL = 0xAD */
458#define DA7213_ALC_DATA_MIDDLE (0x2 << 0)
459#define DA7213_ALC_DATA_TOP (0x3 << 0)
460#define DA7213_ALC_CIC_OP_CHANNEL_LEFT (0x0 << 7)
461#define DA7213_ALC_CIC_OP_CHANNEL_RIGHT (0x1 << 7)
462
463/* DA7213_DAC_NG_SETUP_TIME = 0xAF */
464#define DA7213_DAC_NG_SETUP_TIME_SHIFT 0
465#define DA7213_DAC_NG_SETUP_TIME_MAX 4
466#define DA7213_DAC_NG_RAMPUP_RATE_SHIFT 2
467#define DA7213_DAC_NG_RAMPDN_RATE_SHIFT 3
468#define DA7213_DAC_NG_RAMP_RATE_MAX 2
469
470/* DA7213_DAC_NG_OFF/ON_THRESH = 0xB0/0xB1 */
471#define DA7213_DAC_NG_THRESHOLD_SHIFT 0
472#define DA7213_DAC_NG_THRESHOLD_MAX 0x7
473
474/* DA7213_DAC_NG_CTRL = 0xB2 */
475#define DA7213_DAC_NG_EN_SHIFT 7
476#define DA7213_DAC_NG_EN_MAX 0x1
477
478
479/*
480 * General defines
481 */
482
483/* Register inversion */
484#define DA7213_NO_INVERT 0
485#define DA7213_INVERT 1
486
487/* Byte related defines */
488#define DA7213_BYTE_SHIFT 8
489#define DA7213_BYTE_MASK 0xFF
490
491/* ALC related */
492#define DA7213_ALC_OFFSET_15_8 0x00FF00
493#define DA7213_ALC_OFFSET_19_16 0x0F0000
494#define DA7213_ALC_AVG_ITERATIONS 5
495
496/* PLL related */
497#define DA7213_SYSCLK_MCLK 0
498#define DA7213_SYSCLK_PLL 1
499#define DA7213_PLL_FREQ_OUT_90316800 90316800
500#define DA7213_PLL_FREQ_OUT_98304000 98304000
501#define DA7213_PLL_FREQ_OUT_94310400 94310400
502#define DA7213_PLL_INDIV_5_10_MHZ_VAL 2
503#define DA7213_PLL_INDIV_10_20_MHZ_VAL 4
504#define DA7213_PLL_INDIV_20_40_MHZ_VAL 8
505#define DA7213_PLL_INDIV_40_54_MHZ_VAL 16
506
507enum clk_src {
508 DA7213_CLKSRC_MCLK
509};
510
511/* Codec private data */
512struct da7213_priv {
513 struct regmap *regmap;
514 unsigned int mclk_rate;
515 bool master;
516 bool mclk_squarer_en;
517 bool srm_en;
518 bool alc_calib_auto;
519 bool alc_en;
520 struct da7213_platform_data *pdata;
521};
522
523#endif /* _DA7213_H */
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index c9772ca3da4f..fc176044994d 100644..100755
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -1,562 +1,2381 @@
1/* 1/*
2 * max98090.c -- MAX98090 ALSA SoC Audio driver 2 * max98090.c -- MAX98090 ALSA SoC Audio driver
3 * based on Rev0p8 datasheet
4 * 3 *
5 * Copyright (C) 2012 Renesas Solutions Corp. 4 * Copyright 2011-2012 Maxim Integrated Products
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 *
8 * Based on
9 *
10 * max98095.c
11 * Copyright 2011 Maxim Integrated Products
12 *
13 * https://github.com/hardkernel/linux/commit/\
14 * 3417d7166b17113b3b33b0a337c74d1c7cc313df#sound/soc/codecs/max98090.c
15 * Copyright 2011 Maxim Integrated Products
16 * 5 *
17 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
20 */ 9 */
21 10
11#include <linux/delay.h>
22#include <linux/i2c.h> 12#include <linux/i2c.h>
23#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/pm.h>
15#include <linux/pm_runtime.h>
24#include <linux/regmap.h> 16#include <linux/regmap.h>
17#include <linux/slab.h>
18#include <sound/jack.h>
19#include <sound/pcm.h>
20#include <sound/pcm_params.h>
25#include <sound/soc.h> 21#include <sound/soc.h>
26#include <sound/tlv.h> 22#include <sound/tlv.h>
23#include <sound/max98090.h>
24#include "max98090.h"
25
26#include <linux/version.h>
27
28#define DEBUG
29#define EXTMIC_METHOD
30#define EXTMIC_METHOD_TEST
31
32/* Allows for sparsely populated register maps */
33static struct reg_default max98090_reg[] = {
34 { 0x00, 0x00 }, /* 00 Software Reset */
35 { 0x03, 0x04 }, /* 03 Interrupt Masks */
36 { 0x04, 0x00 }, /* 04 System Clock Quick */
37 { 0x05, 0x00 }, /* 05 Sample Rate Quick */
38 { 0x06, 0x00 }, /* 06 DAI Interface Quick */
39 { 0x07, 0x00 }, /* 07 DAC Path Quick */
40 { 0x08, 0x00 }, /* 08 Mic/Direct to ADC Quick */
41 { 0x09, 0x00 }, /* 09 Line to ADC Quick */
42 { 0x0A, 0x00 }, /* 0A Analog Mic Loop Quick */
43 { 0x0B, 0x00 }, /* 0B Analog Line Loop Quick */
44 { 0x0C, 0x00 }, /* 0C Reserved */
45 { 0x0D, 0x00 }, /* 0D Input Config */
46 { 0x0E, 0x1B }, /* 0E Line Input Level */
47 { 0x0F, 0x00 }, /* 0F Line Config */
48
49 { 0x10, 0x14 }, /* 10 Mic1 Input Level */
50 { 0x11, 0x14 }, /* 11 Mic2 Input Level */
51 { 0x12, 0x00 }, /* 12 Mic Bias Voltage */
52 { 0x13, 0x00 }, /* 13 Digital Mic Config */
53 { 0x14, 0x00 }, /* 14 Digital Mic Mode */
54 { 0x15, 0x00 }, /* 15 Left ADC Mixer */
55 { 0x16, 0x00 }, /* 16 Right ADC Mixer */
56 { 0x17, 0x03 }, /* 17 Left ADC Level */
57 { 0x18, 0x03 }, /* 18 Right ADC Level */
58 { 0x19, 0x00 }, /* 19 ADC Biquad Level */
59 { 0x1A, 0x00 }, /* 1A ADC Sidetone */
60 { 0x1B, 0x00 }, /* 1B System Clock */
61 { 0x1C, 0x00 }, /* 1C Clock Mode */
62 { 0x1D, 0x00 }, /* 1D Any Clock 1 */
63 { 0x1E, 0x00 }, /* 1E Any Clock 2 */
64 { 0x1F, 0x00 }, /* 1F Any Clock 3 */
65
66 { 0x20, 0x00 }, /* 20 Any Clock 4 */
67 { 0x21, 0x00 }, /* 21 Master Mode */
68 { 0x22, 0x00 }, /* 22 Interface Format */
69 { 0x23, 0x00 }, /* 23 TDM Format 1*/
70 { 0x24, 0x00 }, /* 24 TDM Format 2*/
71 { 0x25, 0x00 }, /* 25 I/O Configuration */
72 { 0x26, 0x80 }, /* 26 Filter Config */
73 { 0x27, 0x00 }, /* 27 DAI Playback Level */
74 { 0x28, 0x00 }, /* 28 EQ Playback Level */
75 { 0x29, 0x00 }, /* 29 Left HP Mixer */
76 { 0x2A, 0x00 }, /* 2A Right HP Mixer */
77 { 0x2B, 0x00 }, /* 2B HP Control */
78 { 0x2C, 0x1A }, /* 2C Left HP Volume */
79 { 0x2D, 0x1A }, /* 2D Right HP Volume */
80 { 0x2E, 0x00 }, /* 2E Left Spk Mixer */
81 { 0x2F, 0x00 }, /* 2F Right Spk Mixer */
82
83 { 0x30, 0x00 }, /* 30 Spk Control */
84 { 0x31, 0x2C }, /* 31 Left Spk Volume */
85 { 0x32, 0x2C }, /* 32 Right Spk Volume */
86 { 0x33, 0x00 }, /* 33 ALC Timing */
87 { 0x34, 0x00 }, /* 34 ALC Compressor */
88 { 0x35, 0x00 }, /* 35 ALC Expander */
89 { 0x36, 0x00 }, /* 36 ALC Gain */
90 { 0x37, 0x00 }, /* 37 Rcv/Line OutL Mixer */
91 { 0x38, 0x00 }, /* 38 Rcv/Line OutL Control */
92 { 0x39, 0x15 }, /* 39 Rcv/Line OutL Volume */
93 { 0x3A, 0x00 }, /* 3A Line OutR Mixer */
94 { 0x3B, 0x00 }, /* 3B Line OutR Control */
95 { 0x3C, 0x15 }, /* 3C Line OutR Volume */
96 { 0x3D, 0x00 }, /* 3D Jack Detect */
97 { 0x3E, 0x00 }, /* 3E Input Enable */
98 { 0x3F, 0x00 }, /* 3F Output Enable */
99
100 { 0x40, 0x00 }, /* 40 Level Control */
101 { 0x41, 0x00 }, /* 41 DSP Filter Enable */
102 { 0x42, 0x00 }, /* 42 Bias Control */
103 { 0x43, 0x00 }, /* 43 DAC Control */
104 { 0x44, 0x06 }, /* 44 ADC Control */
105 { 0x45, 0x00 }, /* 45 Device Shutdown */
106 { 0x46, 0x00 }, /* 46 Equalizer Band 1 Coefficient B0 */
107 { 0x47, 0x00 }, /* 47 Equalizer Band 1 Coefficient B0 */
108 { 0x48, 0x00 }, /* 48 Equalizer Band 1 Coefficient B0 */
109 { 0x49, 0x00 }, /* 49 Equalizer Band 1 Coefficient B1 */
110 { 0x4A, 0x00 }, /* 4A Equalizer Band 1 Coefficient B1 */
111 { 0x4B, 0x00 }, /* 4B Equalizer Band 1 Coefficient B1 */
112 { 0x4C, 0x00 }, /* 4C Equalizer Band 1 Coefficient B2 */
113 { 0x4D, 0x00 }, /* 4D Equalizer Band 1 Coefficient B2 */
114 { 0x4E, 0x00 }, /* 4E Equalizer Band 1 Coefficient B2 */
115 { 0x4F, 0x00 }, /* 4F Equalizer Band 1 Coefficient A1 */
116
117 { 0x50, 0x00 }, /* 50 Equalizer Band 1 Coefficient A1 */
118 { 0x51, 0x00 }, /* 51 Equalizer Band 1 Coefficient A1 */
119 { 0x52, 0x00 }, /* 52 Equalizer Band 1 Coefficient A2 */
120 { 0x53, 0x00 }, /* 53 Equalizer Band 1 Coefficient A2 */
121 { 0x54, 0x00 }, /* 54 Equalizer Band 1 Coefficient A2 */
122 { 0x55, 0x00 }, /* 55 Equalizer Band 2 Coefficient B0 */
123 { 0x56, 0x00 }, /* 56 Equalizer Band 2 Coefficient B0 */
124 { 0x57, 0x00 }, /* 57 Equalizer Band 2 Coefficient B0 */
125 { 0x58, 0x00 }, /* 58 Equalizer Band 2 Coefficient B1 */
126 { 0x59, 0x00 }, /* 59 Equalizer Band 2 Coefficient B1 */
127 { 0x5A, 0x00 }, /* 5A Equalizer Band 2 Coefficient B1 */
128 { 0x5B, 0x00 }, /* 5B Equalizer Band 2 Coefficient B2 */
129 { 0x5C, 0x00 }, /* 5C Equalizer Band 2 Coefficient B2 */
130 { 0x5D, 0x00 }, /* 5D Equalizer Band 2 Coefficient B2 */
131 { 0x5E, 0x00 }, /* 5E Equalizer Band 2 Coefficient A1 */
132 { 0x5F, 0x00 }, /* 5F Equalizer Band 2 Coefficient A1 */
133
134 { 0x60, 0x00 }, /* 60 Equalizer Band 2 Coefficient A1 */
135 { 0x61, 0x00 }, /* 61 Equalizer Band 2 Coefficient A2 */
136 { 0x62, 0x00 }, /* 62 Equalizer Band 2 Coefficient A2 */
137 { 0x63, 0x00 }, /* 63 Equalizer Band 2 Coefficient A2 */
138 { 0x64, 0x00 }, /* 64 Equalizer Band 3 Coefficient B0 */
139 { 0x65, 0x00 }, /* 65 Equalizer Band 3 Coefficient B0 */
140 { 0x66, 0x00 }, /* 66 Equalizer Band 3 Coefficient B0 */
141 { 0x67, 0x00 }, /* 67 Equalizer Band 3 Coefficient B1 */
142 { 0x68, 0x00 }, /* 68 Equalizer Band 3 Coefficient B1 */
143 { 0x69, 0x00 }, /* 69 Equalizer Band 3 Coefficient B1 */
144 { 0x6A, 0x00 }, /* 6A Equalizer Band 3 Coefficient B2 */
145 { 0x6B, 0x00 }, /* 6B Equalizer Band 3 Coefficient B2 */
146 { 0x6C, 0x00 }, /* 6C Equalizer Band 3 Coefficient B2 */
147 { 0x6D, 0x00 }, /* 6D Equalizer Band 3 Coefficient A1 */
148 { 0x6E, 0x00 }, /* 6E Equalizer Band 3 Coefficient A1 */
149 { 0x6F, 0x00 }, /* 6F Equalizer Band 3 Coefficient A1 */
150
151 { 0x70, 0x00 }, /* 70 Equalizer Band 3 Coefficient A2 */
152 { 0x71, 0x00 }, /* 71 Equalizer Band 3 Coefficient A2 */
153 { 0x72, 0x00 }, /* 72 Equalizer Band 3 Coefficient A2 */
154 { 0x73, 0x00 }, /* 73 Equalizer Band 4 Coefficient B0 */
155 { 0x74, 0x00 }, /* 74 Equalizer Band 4 Coefficient B0 */
156 { 0x75, 0x00 }, /* 75 Equalizer Band 4 Coefficient B0 */
157 { 0x76, 0x00 }, /* 76 Equalizer Band 4 Coefficient B1 */
158 { 0x77, 0x00 }, /* 77 Equalizer Band 4 Coefficient B1 */
159 { 0x78, 0x00 }, /* 78 Equalizer Band 4 Coefficient B1 */
160 { 0x79, 0x00 }, /* 79 Equalizer Band 4 Coefficient B2 */
161 { 0x7A, 0x00 }, /* 7A Equalizer Band 4 Coefficient B2 */
162 { 0x7B, 0x00 }, /* 7B Equalizer Band 4 Coefficient B2 */
163 { 0x7C, 0x00 }, /* 7C Equalizer Band 4 Coefficient A1 */
164 { 0x7D, 0x00 }, /* 7D Equalizer Band 4 Coefficient A1 */
165 { 0x7E, 0x00 }, /* 7E Equalizer Band 4 Coefficient A1 */
166 { 0x7F, 0x00 }, /* 7F Equalizer Band 4 Coefficient A2 */
167
168 { 0x80, 0x00 }, /* 80 Equalizer Band 4 Coefficient A2 */
169 { 0x81, 0x00 }, /* 81 Equalizer Band 4 Coefficient A2 */
170 { 0x82, 0x00 }, /* 82 Equalizer Band 5 Coefficient B0 */
171 { 0x83, 0x00 }, /* 83 Equalizer Band 5 Coefficient B0 */
172 { 0x84, 0x00 }, /* 84 Equalizer Band 5 Coefficient B0 */
173 { 0x85, 0x00 }, /* 85 Equalizer Band 5 Coefficient B1 */
174 { 0x86, 0x00 }, /* 86 Equalizer Band 5 Coefficient B1 */
175 { 0x87, 0x00 }, /* 87 Equalizer Band 5 Coefficient B1 */
176 { 0x88, 0x00 }, /* 88 Equalizer Band 5 Coefficient B2 */
177 { 0x89, 0x00 }, /* 89 Equalizer Band 5 Coefficient B2 */
178 { 0x8A, 0x00 }, /* 8A Equalizer Band 5 Coefficient B2 */
179 { 0x8B, 0x00 }, /* 8B Equalizer Band 5 Coefficient A1 */
180 { 0x8C, 0x00 }, /* 8C Equalizer Band 5 Coefficient A1 */
181 { 0x8D, 0x00 }, /* 8D Equalizer Band 5 Coefficient A1 */
182 { 0x8E, 0x00 }, /* 8E Equalizer Band 5 Coefficient A2 */
183 { 0x8F, 0x00 }, /* 8F Equalizer Band 5 Coefficient A2 */
184
185 { 0x90, 0x00 }, /* 90 Equalizer Band 5 Coefficient A2 */
186 { 0x91, 0x00 }, /* 91 Equalizer Band 6 Coefficient B0 */
187 { 0x92, 0x00 }, /* 92 Equalizer Band 6 Coefficient B0 */
188 { 0x93, 0x00 }, /* 93 Equalizer Band 6 Coefficient B0 */
189 { 0x94, 0x00 }, /* 94 Equalizer Band 6 Coefficient B1 */
190 { 0x95, 0x00 }, /* 95 Equalizer Band 6 Coefficient B1 */
191 { 0x96, 0x00 }, /* 96 Equalizer Band 6 Coefficient B1 */
192 { 0x97, 0x00 }, /* 97 Equalizer Band 6 Coefficient B2 */
193 { 0x98, 0x00 }, /* 98 Equalizer Band 6 Coefficient B2 */
194 { 0x99, 0x00 }, /* 99 Equalizer Band 6 Coefficient B2 */
195 { 0x9A, 0x00 }, /* 9A Equalizer Band 6 Coefficient A1 */
196 { 0x9B, 0x00 }, /* 9B Equalizer Band 6 Coefficient A1 */
197 { 0x9C, 0x00 }, /* 9C Equalizer Band 6 Coefficient A1 */
198 { 0x9D, 0x00 }, /* 9D Equalizer Band 6 Coefficient A2 */
199 { 0x9E, 0x00 }, /* 9E Equalizer Band 6 Coefficient A2 */
200 { 0x9F, 0x00 }, /* 9F Equalizer Band 6 Coefficient A2 */
201
202 { 0xA0, 0x00 }, /* A0 Equalizer Band 7 Coefficient B0 */
203 { 0xA1, 0x00 }, /* A1 Equalizer Band 7 Coefficient B0 */
204 { 0xA2, 0x00 }, /* A2 Equalizer Band 7 Coefficient B0 */
205 { 0xA3, 0x00 }, /* A3 Equalizer Band 7 Coefficient B1 */
206 { 0xA4, 0x00 }, /* A4 Equalizer Band 7 Coefficient B1 */
207 { 0xA5, 0x00 }, /* A5 Equalizer Band 7 Coefficient B1 */
208 { 0xA6, 0x00 }, /* A6 Equalizer Band 7 Coefficient B2 */
209 { 0xA7, 0x00 }, /* A7 Equalizer Band 7 Coefficient B2 */
210 { 0xA8, 0x00 }, /* A8 Equalizer Band 7 Coefficient B2 */
211 { 0xA9, 0x00 }, /* A9 Equalizer Band 7 Coefficient A1 */
212 { 0xAA, 0x00 }, /* AA Equalizer Band 7 Coefficient A1 */
213 { 0xAB, 0x00 }, /* AB Equalizer Band 7 Coefficient A1 */
214 { 0xAC, 0x00 }, /* AC Equalizer Band 7 Coefficient A2 */
215 { 0xAD, 0x00 }, /* AD Equalizer Band 7 Coefficient A2 */
216 { 0xAE, 0x00 }, /* AE Equalizer Band 7 Coefficient A2 */
217 { 0xAF, 0x00 }, /* AF ADC Biquad Coefficient B0 */
218
219 { 0xB0, 0x00 }, /* B0 ADC Biquad Coefficient B0 */
220 { 0xB1, 0x00 }, /* B1 ADC Biquad Coefficient B0 */
221 { 0xB2, 0x00 }, /* B2 ADC Biquad Coefficient B1 */
222 { 0xB3, 0x00 }, /* B3 ADC Biquad Coefficient B1 */
223 { 0xB4, 0x00 }, /* B4 ADC Biquad Coefficient B1 */
224 { 0xB5, 0x00 }, /* B5 ADC Biquad Coefficient B2 */
225 { 0xB6, 0x00 }, /* B6 ADC Biquad Coefficient B2 */
226 { 0xB7, 0x00 }, /* B7 ADC Biquad Coefficient B2 */
227 { 0xB8, 0x00 }, /* B8 ADC Biquad Coefficient A1 */
228 { 0xB9, 0x00 }, /* B9 ADC Biquad Coefficient A1 */
229 { 0xBA, 0x00 }, /* BA ADC Biquad Coefficient A1 */
230 { 0xBB, 0x00 }, /* BB ADC Biquad Coefficient A2 */
231 { 0xBC, 0x00 }, /* BC ADC Biquad Coefficient A2 */
232 { 0xBD, 0x00 }, /* BD ADC Biquad Coefficient A2 */
233 { 0xBE, 0x00 }, /* BE Digital Mic 3 Volume */
234 { 0xBF, 0x00 }, /* BF Digital Mic 4 Volume */
235
236 { 0xC0, 0x00 }, /* C0 Digital Mic 34 Biquad Pre Atten */
237 { 0xC1, 0x00 }, /* C1 Record TDM Slot */
238 { 0xC2, 0x00 }, /* C2 Sample Rate */
239 { 0xC3, 0x00 }, /* C3 Digital Mic 34 Biquad Coefficient C3 */
240 { 0xC4, 0x00 }, /* C4 Digital Mic 34 Biquad Coefficient C4 */
241 { 0xC5, 0x00 }, /* C5 Digital Mic 34 Biquad Coefficient C5 */
242 { 0xC6, 0x00 }, /* C6 Digital Mic 34 Biquad Coefficient C6 */
243 { 0xC7, 0x00 }, /* C7 Digital Mic 34 Biquad Coefficient C7 */
244 { 0xC8, 0x00 }, /* C8 Digital Mic 34 Biquad Coefficient C8 */
245 { 0xC9, 0x00 }, /* C9 Digital Mic 34 Biquad Coefficient C9 */
246 { 0xCA, 0x00 }, /* CA Digital Mic 34 Biquad Coefficient CA */
247 { 0xCB, 0x00 }, /* CB Digital Mic 34 Biquad Coefficient CB */
248 { 0xCC, 0x00 }, /* CC Digital Mic 34 Biquad Coefficient CC */
249 { 0xCD, 0x00 }, /* CD Digital Mic 34 Biquad Coefficient CD */
250 { 0xCE, 0x00 }, /* CE Digital Mic 34 Biquad Coefficient CE */
251 { 0xCF, 0x00 }, /* CF Digital Mic 34 Biquad Coefficient CF */
252
253 { 0xD0, 0x00 }, /* D0 Digital Mic 34 Biquad Coefficient D0 */
254 { 0xD1, 0x00 }, /* D1 Digital Mic 34 Biquad Coefficient D1 */
255};
27 256
28/* 257static bool max98090_volatile_register(struct device *dev, unsigned int reg)
29 * 258{
30 * MAX98090 Registers Definition 259 switch (reg) {
31 * 260 case M98090_REG_DEVICE_STATUS:
32 */ 261 case M98090_REG_JACK_STATUS:
262 case M98090_REG_REVISION_ID:
263 return true;
264 default:
265 return false;
266 }
267}
33 268
34/* RESET / STATUS / INTERRUPT REGISTERS */ 269static bool max98090_readable_register(struct device *dev, unsigned int reg)
35#define MAX98090_0x00_SW_RESET 0x00 270{
36#define MAX98090_0x01_INT_STS 0x01 271 switch (reg) {
37#define MAX98090_0x02_JACK_STS 0x02 272 case M98090_REG_DEVICE_STATUS:
38#define MAX98090_0x03_INT_MASK 0x03 273 case M98090_REG_JACK_STATUS:
39 274 case M98090_REG_INTERRUPT_S:
40/* QUICK SETUP REGISTERS */ 275 case M98090_REG_RESERVED:
41#define MAX98090_0x04_SYS_CLK 0x04 276 case M98090_REG_LINE_INPUT_CONFIG:
42#define MAX98090_0x05_SAMPLE_RATE 0x05 277 case M98090_REG_LINE_INPUT_LEVEL:
43#define MAX98090_0x06_DAI_IF 0x06 278 case M98090_REG_INPUT_MODE:
44#define MAX98090_0x07_DAC_PATH 0x07 279 case M98090_REG_MIC1_INPUT_LEVEL:
45#define MAX98090_0x08_MIC_TO_ADC 0x08 280 case M98090_REG_MIC2_INPUT_LEVEL:
46#define MAX98090_0x09_LINE_TO_ADC 0x09 281 case M98090_REG_MIC_BIAS_VOLTAGE:
47#define MAX98090_0x0A_ANALOG_MIC_LOOP 0x0A 282 case M98090_REG_DIGITAL_MIC_ENABLE:
48#define MAX98090_0x0B_ANALOG_LINE_LOOP 0x0B 283 case M98090_REG_DIGITAL_MIC_CONFIG:
49 284 case M98090_REG_LEFT_ADC_MIXER:
50/* ANALOG INPUT CONFIGURATION REGISTERS */ 285 case M98090_REG_RIGHT_ADC_MIXER:
51#define MAX98090_0x0D_INPUT_CONFIG 0x0D 286 case M98090_REG_LEFT_ADC_LEVEL:
52#define MAX98090_0x0E_LINE_IN_LVL 0x0E 287 case M98090_REG_RIGHT_ADC_LEVEL:
53#define MAX98090_0x0F_LINI_IN_CFG 0x0F 288 case M98090_REG_ADC_BIQUAD_LEVEL:
54#define MAX98090_0x10_MIC1_IN_LVL 0x10 289 case M98090_REG_ADC_SIDETONE:
55#define MAX98090_0x11_MIC2_IN_LVL 0x11 290 case M98090_REG_SYSTEM_CLOCK:
56 291 case M98090_REG_CLOCK_MODE:
57/* MICROPHONE CONFIGURATION REGISTERS */ 292 case M98090_REG_CLOCK_RATIO_NI_MSB:
58#define MAX98090_0x12_MIC_BIAS_VOL 0x12 293 case M98090_REG_CLOCK_RATIO_NI_LSB:
59#define MAX98090_0x13_DIGITAL_MIC_CFG 0x13 294 case M98090_REG_CLOCK_RATIO_MI_MSB:
60#define MAX98090_0x14_DIGITAL_MIC_MODE 0x14 295 case M98090_REG_CLOCK_RATIO_MI_LSB:
61 296 case M98090_REG_MASTER_MODE:
62/* ADC PATH AND CONFIGURATION REGISTERS */ 297 case M98090_REG_INTERFACE_FORMAT:
63#define MAX98090_0x15_L_ADC_MIX 0x15 298 case M98090_REG_TDM_CONTROL:
64#define MAX98090_0x16_R_ADC_MIX 0x16 299 case M98090_REG_TDM_FORMAT:
65#define MAX98090_0x17_L_ADC_LVL 0x17 300 case M98090_REG_IO_CONFIGURATION:
66#define MAX98090_0x18_R_ADC_LVL 0x18 301 case M98090_REG_FILTER_CONFIG:
67#define MAX98090_0x19_ADC_BIQUAD_LVL 0x19 302 case M98090_REG_DAI_PLAYBACK_LEVEL:
68#define MAX98090_0x1A_ADC_SIDETONE 0x1A 303 case M98090_REG_DAI_PLAYBACK_LEVEL_EQ:
69 304 case M98090_REG_LEFT_HP_MIXER:
70/* CLOCK CONFIGURATION REGISTERS */ 305 case M98090_REG_RIGHT_HP_MIXER:
71#define MAX98090_0x1B_SYS_CLK 0x1B 306 case M98090_REG_HP_CONTROL:
72#define MAX98090_0x1C_CLK_MODE 0x1C 307 case M98090_REG_LEFT_HP_VOLUME:
73#define MAX98090_0x1D_ANY_CLK1 0x1D 308 case M98090_REG_RIGHT_HP_VOLUME:
74#define MAX98090_0x1E_ANY_CLK2 0x1E 309 case M98090_REG_LEFT_SPK_MIXER:
75#define MAX98090_0x1F_ANY_CLK3 0x1F 310 case M98090_REG_RIGHT_SPK_MIXER:
76#define MAX98090_0x20_ANY_CLK4 0x20 311 case M98090_REG_SPK_CONTROL:
77#define MAX98090_0x21_MASTER_MODE 0x21 312 case M98090_REG_LEFT_SPK_VOLUME:
78 313 case M98090_REG_RIGHT_SPK_VOLUME:
79/* INTERFACE CONTROL REGISTERS */ 314 case M98090_REG_DRC_TIMING:
80#define MAX98090_0x22_DAI_IF_FMT 0x22 315 case M98090_REG_DRC_COMPRESSOR:
81#define MAX98090_0x23_DAI_TDM_FMT1 0x23 316 case M98090_REG_DRC_EXPANDER:
82#define MAX98090_0x24_DAI_TDM_FMT2 0x24 317 case M98090_REG_DRC_GAIN:
83#define MAX98090_0x25_DAI_IO_CFG 0x25 318 case M98090_REG_RCV_LOUTL_MIXER:
84#define MAX98090_0x26_FILTER_CFG 0x26 319 case M98090_REG_RCV_LOUTL_CONTROL:
85#define MAX98090_0x27_DAI_PLAYBACK_LVL 0x27 320 case M98090_REG_RCV_LOUTL_VOLUME:
86#define MAX98090_0x28_EQ_PLAYBACK_LVL 0x28 321 case M98090_REG_LOUTR_MIXER:
87 322 case M98090_REG_LOUTR_CONTROL:
88/* HEADPHONE CONTROL REGISTERS */ 323 case M98090_REG_LOUTR_VOLUME:
89#define MAX98090_0x29_L_HP_MIX 0x29 324 case M98090_REG_JACK_DETECT:
90#define MAX98090_0x2A_R_HP_MIX 0x2A 325 case M98090_REG_INPUT_ENABLE:
91#define MAX98090_0x2B_HP_CTR 0x2B 326 case M98090_REG_OUTPUT_ENABLE:
92#define MAX98090_0x2C_L_HP_VOL 0x2C 327 case M98090_REG_LEVEL_CONTROL:
93#define MAX98090_0x2D_R_HP_VOL 0x2D 328 case M98090_REG_DSP_FILTER_ENABLE:
94 329 case M98090_REG_BIAS_CONTROL:
95/* SPEAKER CONFIGURATION REGISTERS */ 330 case M98090_REG_DAC_CONTROL:
96#define MAX98090_0x2E_L_SPK_MIX 0x2E 331 case M98090_REG_ADC_CONTROL:
97#define MAX98090_0x2F_R_SPK_MIX 0x2F 332 case M98090_REG_DEVICE_SHUTDOWN:
98#define MAX98090_0x30_SPK_CTR 0x30 333 case M98090_REG_EQUALIZER_BASE ... M98090_REG_EQUALIZER_BASE + 0x68:
99#define MAX98090_0x31_L_SPK_VOL 0x31 334 case M98090_REG_RECORD_BIQUAD_BASE ... M98090_REG_RECORD_BIQUAD_BASE + 0x0E:
100#define MAX98090_0x32_R_SPK_VOL 0x32 335 case M98090_REG_DMIC3_VOLUME:
101 336 case M98090_REG_DMIC4_VOLUME:
102/* ALC CONFIGURATION REGISTERS */ 337 case M98090_REG_DMIC34_BQ_PREATTEN:
103#define MAX98090_0x33_ALC_TIMING 0x33 338 case M98090_REG_RECORD_TDM_SLOT:
104#define MAX98090_0x34_ALC_COMPRESSOR 0x34 339 case M98090_REG_SAMPLE_RATE:
105#define MAX98090_0x35_ALC_EXPANDER 0x35 340 case M98090_REG_DMIC34_BIQUAD_BASE ... M98090_REG_DMIC34_BIQUAD_BASE + 0x0E:
106#define MAX98090_0x36_ALC_GAIN 0x36 341 return true;
107 342 default:
108/* RECEIVER AND LINE_OUTPUT REGISTERS */ 343 return false;
109#define MAX98090_0x37_RCV_LOUT_L_MIX 0x37 344 }
110#define MAX98090_0x38_RCV_LOUT_L_CNTL 0x38 345}
111#define MAX98090_0x39_RCV_LOUT_L_VOL 0x39
112#define MAX98090_0x3A_LOUT_R_MIX 0x3A
113#define MAX98090_0x3B_LOUT_R_CNTL 0x3B
114#define MAX98090_0x3C_LOUT_R_VOL 0x3C
115
116/* JACK DETECT AND ENABLE REGISTERS */
117#define MAX98090_0x3D_JACK_DETECT 0x3D
118#define MAX98090_0x3E_IN_ENABLE 0x3E
119#define MAX98090_0x3F_OUT_ENABLE 0x3F
120#define MAX98090_0x40_LVL_CTR 0x40
121#define MAX98090_0x41_DSP_FILTER_ENABLE 0x41
122
123/* BIAS AND POWER MODE CONFIGURATION REGISTERS */
124#define MAX98090_0x42_BIAS_CTR 0x42
125#define MAX98090_0x43_DAC_CTR 0x43
126#define MAX98090_0x44_ADC_CTR 0x44
127#define MAX98090_0x45_DEV_SHUTDOWN 0x45
128
129/* REVISION ID REGISTER */
130#define MAX98090_0xFF_REV_ID 0xFF
131
132#define MAX98090_REG_MAX_CACHED 0x45
133#define MAX98090_REG_END 0xFF
134 346
135/* 347static int max98090_reset(struct max98090_priv *max98090)
136 * 348{
137 * MAX98090 Registers Bit Fields 349 int ret;
138 *
139 */
140 350
141/* MAX98090_0x06_DAI_IF */ 351 /* Reset the codec by writing to this write-only reset register */
142#define MAX98090_DAI_IF_MASK 0x3F 352 ret = regmap_write(max98090->regmap, M98090_REG_SOFTWARE_RESET,
143#define MAX98090_RJ_M (1 << 5) 353 M98090_SWRESET_MASK);
144#define MAX98090_RJ_S (1 << 4) 354 if (ret < 0) {
145#define MAX98090_LJ_M (1 << 3) 355 dev_err(max98090->codec->dev,
146#define MAX98090_LJ_S (1 << 2) 356 "Failed to reset codec: %d\n", ret);
147#define MAX98090_I2S_M (1 << 1) 357 return ret;
148#define MAX98090_I2S_S (1 << 0) 358 }
149 359
150/* MAX98090_0x45_DEV_SHUTDOWN */ 360 msleep(20);
151#define MAX98090_SHDNRUN (1 << 7) 361 return ret;
152 362}
153/* codec private data */ 363
154struct max98090_priv { 364static const unsigned int max98090_micboost_tlv[] = {
155 struct regmap *regmap; 365 TLV_DB_RANGE_HEAD(2),
156}; 366 0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0),
157 367 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
158static const struct reg_default max98090_reg_defaults[] = { 368};
159 /* RESET / STATUS / INTERRUPT REGISTERS */ 369
160 {MAX98090_0x00_SW_RESET, 0x00}, 370static const DECLARE_TLV_DB_SCALE(max98090_mic_tlv, 0, 100, 0);
161 {MAX98090_0x01_INT_STS, 0x00}, 371
162 {MAX98090_0x02_JACK_STS, 0x00}, 372static const DECLARE_TLV_DB_SCALE(max98090_line_single_ended_tlv,
163 {MAX98090_0x03_INT_MASK, 0x04}, 373 -600, 600, 0);
164 374
165 /* QUICK SETUP REGISTERS */ 375static const unsigned int max98090_line_tlv[] = {
166 {MAX98090_0x04_SYS_CLK, 0x00}, 376 TLV_DB_RANGE_HEAD(2),
167 {MAX98090_0x05_SAMPLE_RATE, 0x00}, 377 0, 3, TLV_DB_SCALE_ITEM(-600, 300, 0),
168 {MAX98090_0x06_DAI_IF, 0x00}, 378 4, 5, TLV_DB_SCALE_ITEM(1400, 600, 0),
169 {MAX98090_0x07_DAC_PATH, 0x00}, 379};
170 {MAX98090_0x08_MIC_TO_ADC, 0x00}, 380
171 {MAX98090_0x09_LINE_TO_ADC, 0x00}, 381static const DECLARE_TLV_DB_SCALE(max98090_avg_tlv, 0, 600, 0);
172 {MAX98090_0x0A_ANALOG_MIC_LOOP, 0x00}, 382static const DECLARE_TLV_DB_SCALE(max98090_av_tlv, -1200, 100, 0);
173 {MAX98090_0x0B_ANALOG_LINE_LOOP, 0x00}, 383
174 384static const DECLARE_TLV_DB_SCALE(max98090_dvg_tlv, 0, 600, 0);
175 /* ANALOG INPUT CONFIGURATION REGISTERS */ 385static const DECLARE_TLV_DB_SCALE(max98090_dv_tlv, -1500, 100, 0);
176 {MAX98090_0x0D_INPUT_CONFIG, 0x00}, 386
177 {MAX98090_0x0E_LINE_IN_LVL, 0x1B}, 387static const DECLARE_TLV_DB_SCALE(max98090_sidetone_tlv, -6050, 200, 0);
178 {MAX98090_0x0F_LINI_IN_CFG, 0x00}, 388
179 {MAX98090_0x10_MIC1_IN_LVL, 0x11}, 389static const DECLARE_TLV_DB_SCALE(max98090_alc_tlv, -1500, 100, 0);
180 {MAX98090_0x11_MIC2_IN_LVL, 0x11}, 390static const DECLARE_TLV_DB_SCALE(max98090_alcmakeup_tlv, 0, 100, 0);
181 391static const DECLARE_TLV_DB_SCALE(max98090_alccomp_tlv, -3100, 100, 0);
182 /* MICROPHONE CONFIGURATION REGISTERS */ 392static const DECLARE_TLV_DB_SCALE(max98090_drcexp_tlv, -6600, 100, 0);
183 {MAX98090_0x12_MIC_BIAS_VOL, 0x00}, 393
184 {MAX98090_0x13_DIGITAL_MIC_CFG, 0x00}, 394static const unsigned int max98090_mixout_tlv[] = {
185 {MAX98090_0x14_DIGITAL_MIC_MODE, 0x00}, 395 TLV_DB_RANGE_HEAD(2),
186 396 0, 1, TLV_DB_SCALE_ITEM(-1200, 250, 0),
187 /* ADC PATH AND CONFIGURATION REGISTERS */ 397 2, 3, TLV_DB_SCALE_ITEM(-600, 600, 0),
188 {MAX98090_0x15_L_ADC_MIX, 0x00},
189 {MAX98090_0x16_R_ADC_MIX, 0x00},
190 {MAX98090_0x17_L_ADC_LVL, 0x03},
191 {MAX98090_0x18_R_ADC_LVL, 0x03},
192 {MAX98090_0x19_ADC_BIQUAD_LVL, 0x00},
193 {MAX98090_0x1A_ADC_SIDETONE, 0x00},
194
195 /* CLOCK CONFIGURATION REGISTERS */
196 {MAX98090_0x1B_SYS_CLK, 0x00},
197 {MAX98090_0x1C_CLK_MODE, 0x00},
198 {MAX98090_0x1D_ANY_CLK1, 0x00},
199 {MAX98090_0x1E_ANY_CLK2, 0x00},
200 {MAX98090_0x1F_ANY_CLK3, 0x00},
201 {MAX98090_0x20_ANY_CLK4, 0x00},
202 {MAX98090_0x21_MASTER_MODE, 0x00},
203
204 /* INTERFACE CONTROL REGISTERS */
205 {MAX98090_0x22_DAI_IF_FMT, 0x00},
206 {MAX98090_0x23_DAI_TDM_FMT1, 0x00},
207 {MAX98090_0x24_DAI_TDM_FMT2, 0x00},
208 {MAX98090_0x25_DAI_IO_CFG, 0x00},
209 {MAX98090_0x26_FILTER_CFG, 0x80},
210 {MAX98090_0x27_DAI_PLAYBACK_LVL, 0x00},
211 {MAX98090_0x28_EQ_PLAYBACK_LVL, 0x00},
212
213 /* HEADPHONE CONTROL REGISTERS */
214 {MAX98090_0x29_L_HP_MIX, 0x00},
215 {MAX98090_0x2A_R_HP_MIX, 0x00},
216 {MAX98090_0x2B_HP_CTR, 0x00},
217 {MAX98090_0x2C_L_HP_VOL, 0x1A},
218 {MAX98090_0x2D_R_HP_VOL, 0x1A},
219
220 /* SPEAKER CONFIGURATION REGISTERS */
221 {MAX98090_0x2E_L_SPK_MIX, 0x00},
222 {MAX98090_0x2F_R_SPK_MIX, 0x00},
223 {MAX98090_0x30_SPK_CTR, 0x00},
224 {MAX98090_0x31_L_SPK_VOL, 0x2C},
225 {MAX98090_0x32_R_SPK_VOL, 0x2C},
226
227 /* ALC CONFIGURATION REGISTERS */
228 {MAX98090_0x33_ALC_TIMING, 0x00},
229 {MAX98090_0x34_ALC_COMPRESSOR, 0x00},
230 {MAX98090_0x35_ALC_EXPANDER, 0x00},
231 {MAX98090_0x36_ALC_GAIN, 0x00},
232
233 /* RECEIVER AND LINE_OUTPUT REGISTERS */
234 {MAX98090_0x37_RCV_LOUT_L_MIX, 0x00},
235 {MAX98090_0x38_RCV_LOUT_L_CNTL, 0x00},
236 {MAX98090_0x39_RCV_LOUT_L_VOL, 0x15},
237 {MAX98090_0x3A_LOUT_R_MIX, 0x00},
238 {MAX98090_0x3B_LOUT_R_CNTL, 0x00},
239 {MAX98090_0x3C_LOUT_R_VOL, 0x15},
240
241 /* JACK DETECT AND ENABLE REGISTERS */
242 {MAX98090_0x3D_JACK_DETECT, 0x00},
243 {MAX98090_0x3E_IN_ENABLE, 0x00},
244 {MAX98090_0x3F_OUT_ENABLE, 0x00},
245 {MAX98090_0x40_LVL_CTR, 0x00},
246 {MAX98090_0x41_DSP_FILTER_ENABLE, 0x00},
247
248 /* BIAS AND POWER MODE CONFIGURATION REGISTERS */
249 {MAX98090_0x42_BIAS_CTR, 0x00},
250 {MAX98090_0x43_DAC_CTR, 0x00},
251 {MAX98090_0x44_ADC_CTR, 0x06},
252 {MAX98090_0x45_DEV_SHUTDOWN, 0x00},
253}; 398};
254 399
255static const unsigned int max98090_hp_tlv[] = { 400static const unsigned int max98090_hp_tlv[] = {
256 TLV_DB_RANGE_HEAD(5), 401 TLV_DB_RANGE_HEAD(5),
257 0x0, 0x6, TLV_DB_SCALE_ITEM(-6700, 400, 0), 402 0, 6, TLV_DB_SCALE_ITEM(-6700, 400, 0),
258 0x7, 0xE, TLV_DB_SCALE_ITEM(-4000, 300, 0), 403 7, 14, TLV_DB_SCALE_ITEM(-4000, 300, 0),
259 0xF, 0x15, TLV_DB_SCALE_ITEM(-1700, 200, 0), 404 15, 21, TLV_DB_SCALE_ITEM(-1700, 200, 0),
260 0x16, 0x1B, TLV_DB_SCALE_ITEM(-400, 100, 0), 405 22, 27, TLV_DB_SCALE_ITEM(-400, 100, 0),
261 0x1C, 0x1F, TLV_DB_SCALE_ITEM(150, 50, 0), 406 28, 31, TLV_DB_SCALE_ITEM(150, 50, 0),
262}; 407};
263 408
264static struct snd_kcontrol_new max98090_snd_controls[] = { 409static const unsigned int max98090_spk_tlv[] = {
265 SOC_DOUBLE_R_TLV("Headphone Volume", MAX98090_0x2C_L_HP_VOL, 410 TLV_DB_RANGE_HEAD(5),
266 MAX98090_0x2D_R_HP_VOL, 0, 31, 0, max98090_hp_tlv), 411 0, 4, TLV_DB_SCALE_ITEM(-4800, 400, 0),
412 5, 10, TLV_DB_SCALE_ITEM(-2900, 300, 0),
413 11, 14, TLV_DB_SCALE_ITEM(-1200, 200, 0),
414 15, 29, TLV_DB_SCALE_ITEM(-500, 100, 0),
415 30, 39, TLV_DB_SCALE_ITEM(950, 50, 0),
267}; 416};
268 417
269/* Left HeadPhone Mixer Switch */ 418static const unsigned int max98090_rcv_lout_tlv[] = {
270static struct snd_kcontrol_new max98090_left_hp_mixer_controls[] = { 419 TLV_DB_RANGE_HEAD(5),
271 SOC_DAPM_SINGLE("DACR Switch", MAX98090_0x29_L_HP_MIX, 1, 1, 0), 420 0, 6, TLV_DB_SCALE_ITEM(-6200, 400, 0),
272 SOC_DAPM_SINGLE("DACL Switch", MAX98090_0x29_L_HP_MIX, 0, 1, 0), 421 7, 14, TLV_DB_SCALE_ITEM(-3500, 300, 0),
422 15, 21, TLV_DB_SCALE_ITEM(-1200, 200, 0),
423 22, 27, TLV_DB_SCALE_ITEM(100, 100, 0),
424 28, 31, TLV_DB_SCALE_ITEM(650, 50, 0),
273}; 425};
274 426
275/* Right HeadPhone Mixer Switch */ 427static int max98090_get_enab_tlv(struct snd_kcontrol *kcontrol,
276static struct snd_kcontrol_new max98090_right_hp_mixer_controls[] = { 428 struct snd_ctl_elem_value *ucontrol)
277 SOC_DAPM_SINGLE("DACR Switch", MAX98090_0x2A_R_HP_MIX, 1, 1, 0), 429{
278 SOC_DAPM_SINGLE("DACL Switch", MAX98090_0x2A_R_HP_MIX, 0, 1, 0), 430 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
431 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
432 struct soc_mixer_control *mc =
433 (struct soc_mixer_control *)kcontrol->private_value;
434 unsigned int mask = (1 << fls(mc->max)) - 1;
435 unsigned int val = snd_soc_read(codec, mc->reg);
436 unsigned int *select;
437
438 switch (mc->reg) {
439 case M98090_REG_MIC1_INPUT_LEVEL:
440 select = &(max98090->pa1en);
441 break;
442 case M98090_REG_MIC2_INPUT_LEVEL:
443 select = &(max98090->pa2en);
444 break;
445 case M98090_REG_ADC_SIDETONE:
446 select = &(max98090->sidetone);
447 break;
448 default:
449 return -EINVAL;
450 }
451
452 val = (val >> mc->shift) & mask;
453
454 if (val >= 1) {
455 /* If on, return the volume */
456 val = val - 1;
457 *select = val;
458 } else {
459 /* If off, return last stored value */
460 val = *select;
461 }
462
463 ucontrol->value.integer.value[0] = val;
464 return 0;
465}
466
467static int max98090_put_enab_tlv(struct snd_kcontrol *kcontrol,
468 struct snd_ctl_elem_value *ucontrol)
469{
470 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
471 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
472 struct soc_mixer_control *mc =
473 (struct soc_mixer_control *)kcontrol->private_value;
474 unsigned int mask = (1 << fls(mc->max)) - 1;
475 unsigned int sel = ucontrol->value.integer.value[0];
476 unsigned int val = snd_soc_read(codec, mc->reg);
477 unsigned int *select;
478
479 switch (mc->reg) {
480 case M98090_REG_MIC1_INPUT_LEVEL:
481 select = &(max98090->pa1en);
482 break;
483 case M98090_REG_MIC2_INPUT_LEVEL:
484 select = &(max98090->pa2en);
485 break;
486 case M98090_REG_ADC_SIDETONE:
487 select = &(max98090->sidetone);
488 break;
489 default:
490 return -EINVAL;
491 }
492
493 val = (val >> mc->shift) & mask;
494
495 *select = sel;
496
497 /* Setting a volume is only valid if it is already On */
498 if (val >= 1) {
499 sel = sel + 1;
500 } else {
501 /* Write what was already there */
502 sel = val;
503 }
504
505 snd_soc_update_bits(codec, mc->reg,
506 mask << mc->shift,
507 sel << mc->shift);
508
509 return 0;
510}
511
512static const char * max98090_perf_pwr_text[] =
513 { "High Performance", "Low Power" };
514static const char * max98090_pwr_perf_text[] =
515 { "Low Power", "High Performance" };
516
517static const struct soc_enum max98090_vcmbandgap_enum =
518 SOC_ENUM_SINGLE(M98090_REG_BIAS_CONTROL, M98090_VCM_MODE_SHIFT,
519 ARRAY_SIZE(max98090_pwr_perf_text), max98090_pwr_perf_text);
520
521static const char * max98090_osr128_text[] = { "64*fs", "128*fs" };
522
523static const struct soc_enum max98090_osr128_enum =
524 SOC_ENUM_SINGLE(M98090_REG_ADC_CONTROL, M98090_OSR128_SHIFT,
525 ARRAY_SIZE(max98090_osr128_text), max98090_osr128_text);
526
527static const char *max98090_mode_text[] = { "Voice", "Music" };
528
529static const struct soc_enum max98090_mode_enum =
530 SOC_ENUM_SINGLE(M98090_REG_FILTER_CONFIG, M98090_MODE_SHIFT,
531 ARRAY_SIZE(max98090_mode_text), max98090_mode_text);
532
533static const struct soc_enum max98090_filter_dmic34mode_enum =
534 SOC_ENUM_SINGLE(M98090_REG_FILTER_CONFIG,
535 M98090_FLT_DMIC34MODE_SHIFT,
536 ARRAY_SIZE(max98090_mode_text), max98090_mode_text);
537
538static const char * max98090_drcatk_text[] =
539 { "0.5ms", "1ms", "5ms", "10ms", "25ms", "50ms", "100ms", "200ms" };
540
541static const struct soc_enum max98090_drcatk_enum =
542 SOC_ENUM_SINGLE(M98090_REG_DRC_TIMING, M98090_DRCATK_SHIFT,
543 ARRAY_SIZE(max98090_drcatk_text), max98090_drcatk_text);
544
545static const char * max98090_drcrls_text[] =
546 { "8s", "4s", "2s", "1s", "0.5s", "0.25s", "0.125s", "0.0625s" };
547
548static const struct soc_enum max98090_drcrls_enum =
549 SOC_ENUM_SINGLE(M98090_REG_DRC_TIMING, M98090_DRCRLS_SHIFT,
550 ARRAY_SIZE(max98090_drcrls_text), max98090_drcrls_text);
551
552static const char * max98090_alccmp_text[] =
553 { "1:1", "1:1.5", "1:2", "1:4", "1:INF" };
554
555static const struct soc_enum max98090_alccmp_enum =
556 SOC_ENUM_SINGLE(M98090_REG_DRC_COMPRESSOR, M98090_DRCCMP_SHIFT,
557 ARRAY_SIZE(max98090_alccmp_text), max98090_alccmp_text);
558
559static const char * max98090_drcexp_text[] = { "1:1", "2:1", "3:1" };
560
561static const struct soc_enum max98090_drcexp_enum =
562 SOC_ENUM_SINGLE(M98090_REG_DRC_EXPANDER, M98090_DRCEXP_SHIFT,
563 ARRAY_SIZE(max98090_drcexp_text), max98090_drcexp_text);
564
565static const struct soc_enum max98090_dac_perfmode_enum =
566 SOC_ENUM_SINGLE(M98090_REG_DAC_CONTROL, M98090_PERFMODE_SHIFT,
567 ARRAY_SIZE(max98090_perf_pwr_text), max98090_perf_pwr_text);
568
569static const struct soc_enum max98090_dachp_enum =
570 SOC_ENUM_SINGLE(M98090_REG_DAC_CONTROL, M98090_DACHP_SHIFT,
571 ARRAY_SIZE(max98090_pwr_perf_text), max98090_pwr_perf_text);
572
573static const struct soc_enum max98090_adchp_enum =
574 SOC_ENUM_SINGLE(M98090_REG_ADC_CONTROL, M98090_ADCHP_SHIFT,
575 ARRAY_SIZE(max98090_pwr_perf_text), max98090_pwr_perf_text);
576
577static const struct snd_kcontrol_new max98090_snd_controls[] = {
578 SOC_ENUM("MIC Bias VCM Bandgap", max98090_vcmbandgap_enum),
579
580 SOC_SINGLE("DMIC MIC Comp Filter Config", M98090_REG_DIGITAL_MIC_CONFIG,
581 M98090_DMIC_COMP_SHIFT, M98090_DMIC_COMP_NUM - 1, 0),
582
583 SOC_SINGLE_EXT_TLV("MIC1 Boost Volume",
584 M98090_REG_MIC1_INPUT_LEVEL, M98090_MIC_PA1EN_SHIFT,
585 M98090_MIC_PA1EN_NUM - 1, 0, max98090_get_enab_tlv,
586 max98090_put_enab_tlv, max98090_micboost_tlv),
587
588 SOC_SINGLE_EXT_TLV("MIC2 Boost Volume",
589 M98090_REG_MIC2_INPUT_LEVEL, M98090_MIC_PA2EN_SHIFT,
590 M98090_MIC_PA2EN_NUM - 1, 0, max98090_get_enab_tlv,
591 max98090_put_enab_tlv, max98090_micboost_tlv),
592
593 SOC_SINGLE_TLV("MIC1 Volume", M98090_REG_MIC1_INPUT_LEVEL,
594 M98090_MIC_PGAM1_SHIFT, M98090_MIC_PGAM1_NUM - 1, 1,
595 max98090_mic_tlv),
596
597 SOC_SINGLE_TLV("MIC2 Volume", M98090_REG_MIC2_INPUT_LEVEL,
598 M98090_MIC_PGAM2_SHIFT, M98090_MIC_PGAM2_NUM - 1, 1,
599 max98090_mic_tlv),
600
601 SOC_SINGLE_RANGE_TLV("LINEA Single Ended Volume",
602 M98090_REG_LINE_INPUT_LEVEL, M98090_MIXG135_SHIFT, 0,
603 M98090_MIXG135_NUM - 1, 1, max98090_line_single_ended_tlv),
604
605 SOC_SINGLE_RANGE_TLV("LINEB Single Ended Volume",
606 M98090_REG_LINE_INPUT_LEVEL, M98090_MIXG246_SHIFT, 0,
607 M98090_MIXG246_NUM - 1, 1, max98090_line_single_ended_tlv),
608
609 SOC_SINGLE_RANGE_TLV("LINEA Volume", M98090_REG_LINE_INPUT_LEVEL,
610 M98090_LINAPGA_SHIFT, 0, M98090_LINAPGA_NUM - 1, 1,
611 max98090_line_tlv),
612
613 SOC_SINGLE_RANGE_TLV("LINEB Volume", M98090_REG_LINE_INPUT_LEVEL,
614 M98090_LINBPGA_SHIFT, 0, M98090_LINBPGA_NUM - 1, 1,
615 max98090_line_tlv),
616
617 SOC_SINGLE("LINEA Ext Resistor Gain Mode", M98090_REG_INPUT_MODE,
618 M98090_EXTBUFA_SHIFT, M98090_EXTBUFA_NUM - 1, 0),
619 SOC_SINGLE("LINEB Ext Resistor Gain Mode", M98090_REG_INPUT_MODE,
620 M98090_EXTBUFB_SHIFT, M98090_EXTBUFB_NUM - 1, 0),
621
622 SOC_SINGLE_TLV("ADCL Boost Volume", M98090_REG_LEFT_ADC_LEVEL,
623 M98090_AVLG_SHIFT, M98090_AVLG_NUM - 1, 0,
624 max98090_avg_tlv),
625 SOC_SINGLE_TLV("ADCR Boost Volume", M98090_REG_RIGHT_ADC_LEVEL,
626 M98090_AVRG_SHIFT, M98090_AVLG_NUM - 1, 0,
627 max98090_avg_tlv),
628
629 SOC_SINGLE_TLV("ADCL Volume", M98090_REG_LEFT_ADC_LEVEL,
630 M98090_AVL_SHIFT, M98090_AVL_NUM - 1, 1,
631 max98090_av_tlv),
632 SOC_SINGLE_TLV("ADCR Volume", M98090_REG_RIGHT_ADC_LEVEL,
633 M98090_AVR_SHIFT, M98090_AVR_NUM - 1, 1,
634 max98090_av_tlv),
635
636 SOC_ENUM("ADC Oversampling Rate", max98090_osr128_enum),
637 SOC_SINGLE("ADC Quantizer Dither", M98090_REG_ADC_CONTROL,
638 M98090_ADCDITHER_SHIFT, M98090_ADCDITHER_NUM - 1, 0),
639 SOC_ENUM("ADC High Performance Mode", max98090_adchp_enum),
640
641 SOC_SINGLE("DAC Mono Mode", M98090_REG_IO_CONFIGURATION,
642 M98090_DMONO_SHIFT, M98090_DMONO_NUM - 1, 0),
643 SOC_SINGLE("SDIN Mode", M98090_REG_IO_CONFIGURATION,
644 M98090_SDIEN_SHIFT, M98090_SDIEN_NUM - 1, 0),
645 SOC_SINGLE("SDOUT Mode", M98090_REG_IO_CONFIGURATION,
646 M98090_SDOEN_SHIFT, M98090_SDOEN_NUM - 1, 0),
647 SOC_SINGLE("SDOUT Hi-Z Mode", M98090_REG_IO_CONFIGURATION,
648 M98090_HIZOFF_SHIFT, M98090_HIZOFF_NUM - 1, 1),
649 SOC_ENUM("Filter Mode", max98090_mode_enum),
650 SOC_SINGLE("Record Path DC Blocking", M98090_REG_FILTER_CONFIG,
651 M98090_AHPF_SHIFT, M98090_AHPF_NUM - 1, 0),
652 SOC_SINGLE("Playback Path DC Blocking", M98090_REG_FILTER_CONFIG,
653 M98090_DHPF_SHIFT, M98090_DHPF_NUM - 1, 0),
654 SOC_SINGLE_TLV("Digital BQ Volume", M98090_REG_ADC_BIQUAD_LEVEL,
655 M98090_AVBQ_SHIFT, M98090_AVBQ_NUM - 1, 1, max98090_dv_tlv),
656 SOC_SINGLE_EXT_TLV("Digital Sidetone Volume",
657 M98090_REG_ADC_SIDETONE, M98090_DVST_SHIFT,
658 M98090_DVST_NUM - 1, 1, max98090_get_enab_tlv,
659 max98090_put_enab_tlv, max98090_micboost_tlv),
660 SOC_SINGLE_TLV("Digital Coarse Volume", M98090_REG_DAI_PLAYBACK_LEVEL,
661 M98090_DVG_SHIFT, M98090_DVG_NUM - 1, 0,
662 max98090_dvg_tlv),
663 SOC_SINGLE_TLV("Digital Volume", M98090_REG_DAI_PLAYBACK_LEVEL,
664 M98090_DV_SHIFT, M98090_DV_NUM - 1, 1,
665 max98090_dv_tlv),
666 SND_SOC_BYTES("EQ Coefficients", M98090_REG_EQUALIZER_BASE, 105),
667 SOC_SINGLE("Digital EQ 3 Band Switch", M98090_REG_DSP_FILTER_ENABLE,
668 M98090_EQ3BANDEN_SHIFT, M98090_EQ3BANDEN_NUM - 1, 0),
669 SOC_SINGLE("Digital EQ 5 Band Switch", M98090_REG_DSP_FILTER_ENABLE,
670 M98090_EQ5BANDEN_SHIFT, M98090_EQ5BANDEN_NUM - 1, 0),
671 SOC_SINGLE("Digital EQ 7 Band Switch", M98090_REG_DSP_FILTER_ENABLE,
672 M98090_EQ7BANDEN_SHIFT, M98090_EQ7BANDEN_NUM - 1, 0),
673 SOC_SINGLE("Digital EQ Clipping Detection", M98090_REG_DAI_PLAYBACK_LEVEL_EQ,
674 M98090_EQCLPN_SHIFT, M98090_EQCLPN_NUM - 1,
675 1),
676 SOC_SINGLE_TLV("Digital EQ Volume", M98090_REG_DAI_PLAYBACK_LEVEL_EQ,
677 M98090_DVEQ_SHIFT, M98090_DVEQ_NUM - 1, 1,
678 max98090_dv_tlv),
679
680 SOC_SINGLE("ALC Enable", M98090_REG_DRC_TIMING,
681 M98090_DRCEN_SHIFT, M98090_DRCEN_NUM - 1, 0),
682 SOC_ENUM("ALC Attack Time", max98090_drcatk_enum),
683 SOC_ENUM("ALC Release Time", max98090_drcrls_enum),
684 SOC_SINGLE_TLV("ALC Make Up Volume", M98090_REG_DRC_GAIN,
685 M98090_DRCG_SHIFT, M98090_DRCG_NUM - 1, 0,
686 max98090_alcmakeup_tlv),
687 SOC_ENUM("ALC Compression Ratio", max98090_alccmp_enum),
688 SOC_ENUM("ALC Expansion Ratio", max98090_drcexp_enum),
689 SOC_SINGLE_TLV("ALC Compression Threshold Volume",
690 M98090_REG_DRC_COMPRESSOR, M98090_DRCTHC_SHIFT,
691 M98090_DRCTHC_NUM - 1, 1, max98090_alccomp_tlv),
692 SOC_SINGLE_TLV("ALC Expansion Threshold Volume",
693 M98090_REG_DRC_EXPANDER, M98090_DRCTHE_SHIFT,
694 M98090_DRCTHE_NUM - 1, 1, max98090_drcexp_tlv),
695
696 SOC_ENUM("DAC HP Playback Performance Mode",
697 max98090_dac_perfmode_enum),
698 SOC_ENUM("DAC High Performance Mode", max98090_dachp_enum),
699
700 SOC_SINGLE_TLV("Headphone Left Mixer Volume",
701 M98090_REG_HP_CONTROL, M98090_MIXHPLG_SHIFT,
702 M98090_MIXHPLG_NUM - 1, 1, max98090_mixout_tlv),
703 SOC_SINGLE_TLV("Headphone Right Mixer Volume",
704 M98090_REG_HP_CONTROL, M98090_MIXHPRG_SHIFT,
705 M98090_MIXHPRG_NUM - 1, 1, max98090_mixout_tlv),
706
707 SOC_SINGLE_TLV("Speaker Left Mixer Volume",
708 M98090_REG_SPK_CONTROL, M98090_MIXSPLG_SHIFT,
709 M98090_MIXSPLG_NUM - 1, 1, max98090_mixout_tlv),
710 SOC_SINGLE_TLV("Speaker Right Mixer Volume",
711 M98090_REG_SPK_CONTROL, M98090_MIXSPRG_SHIFT,
712 M98090_MIXSPRG_NUM - 1, 1, max98090_mixout_tlv),
713
714 SOC_SINGLE_TLV("Receiver Left Mixer Volume",
715 M98090_REG_RCV_LOUTL_CONTROL, M98090_MIXRCVLG_SHIFT,
716 M98090_MIXRCVLG_NUM - 1, 1, max98090_mixout_tlv),
717 SOC_SINGLE_TLV("Receiver Right Mixer Volume",
718 M98090_REG_LOUTR_CONTROL, M98090_MIXRCVRG_SHIFT,
719 M98090_MIXRCVRG_NUM - 1, 1, max98090_mixout_tlv),
720
721 SOC_DOUBLE_R_TLV("Headphone Volume", M98090_REG_LEFT_HP_VOLUME,
722 M98090_REG_RIGHT_HP_VOLUME, M98090_HPVOLL_SHIFT,
723 M98090_HPVOLL_NUM - 1, 0, max98090_hp_tlv),
724
725 SOC_DOUBLE_R_RANGE_TLV("Speaker Volume",
726 M98090_REG_LEFT_SPK_VOLUME, M98090_REG_RIGHT_SPK_VOLUME,
727 M98090_SPVOLL_SHIFT, 24, M98090_SPVOLL_NUM - 1 + 24,
728 0, max98090_spk_tlv),
729
730 SOC_DOUBLE_R_TLV("Receiver Volume", M98090_REG_RCV_LOUTL_VOLUME,
731 M98090_REG_LOUTR_VOLUME, M98090_RCVLVOL_SHIFT,
732 M98090_RCVLVOL_NUM - 1, 0, max98090_rcv_lout_tlv),
733
734 SOC_SINGLE("Headphone Left Switch", M98090_REG_LEFT_HP_VOLUME,
735 M98090_HPLM_SHIFT, 1, 1),
736 SOC_SINGLE("Headphone Right Switch", M98090_REG_RIGHT_HP_VOLUME,
737 M98090_HPRM_SHIFT, 1, 1),
738
739 SOC_SINGLE("Speaker Left Switch", M98090_REG_LEFT_SPK_VOLUME,
740 M98090_SPLM_SHIFT, 1, 1),
741 SOC_SINGLE("Speaker Right Switch", M98090_REG_RIGHT_SPK_VOLUME,
742 M98090_SPRM_SHIFT, 1, 1),
743
744 SOC_SINGLE("Receiver Left Switch", M98090_REG_RCV_LOUTL_VOLUME,
745 M98090_RCVLM_SHIFT, 1, 1),
746 SOC_SINGLE("Receiver Right Switch", M98090_REG_LOUTR_VOLUME,
747 M98090_RCVRM_SHIFT, 1, 1),
748
749 SOC_SINGLE("Zero-Crossing Detection", M98090_REG_LEVEL_CONTROL,
750 M98090_ZDENN_SHIFT, M98090_ZDENN_NUM - 1, 1),
751 SOC_SINGLE("Enhanced Vol Smoothing", M98090_REG_LEVEL_CONTROL,
752 M98090_VS2ENN_SHIFT, M98090_VS2ENN_NUM - 1, 1),
753 SOC_SINGLE("Volume Adjustment Smoothing", M98090_REG_LEVEL_CONTROL,
754 M98090_VSENN_SHIFT, M98090_VSENN_NUM - 1, 1),
755
756 SND_SOC_BYTES("Biquad Coefficients", M98090_REG_RECORD_BIQUAD_BASE, 15),
757 SOC_SINGLE("Biquad Switch", M98090_REG_DSP_FILTER_ENABLE,
758 M98090_ADCBQEN_SHIFT, M98090_ADCBQEN_NUM - 1, 0),
279}; 759};
280 760
281static struct snd_soc_dapm_widget max98090_dapm_widgets[] = { 761static const struct snd_kcontrol_new max98091_snd_controls[] = {
282 /* Output */ 762
763 SOC_SINGLE("DMIC34 Zeropad", M98090_REG_SAMPLE_RATE,
764 M98090_DMIC34_ZEROPAD_SHIFT,
765 M98090_DMIC34_ZEROPAD_NUM - 1, 0),
766
767 SOC_ENUM("Filter DMIC34 Mode", max98090_filter_dmic34mode_enum),
768 SOC_SINGLE("DMIC34 DC Blocking", M98090_REG_FILTER_CONFIG,
769 M98090_FLT_DMIC34HPF_SHIFT,
770 M98090_FLT_DMIC34HPF_NUM - 1, 0),
771
772 SOC_SINGLE_TLV("DMIC3 Boost Volume", M98090_REG_DMIC3_VOLUME,
773 M98090_DMIC_AV3G_SHIFT, M98090_DMIC_AV3G_NUM - 1, 0,
774 max98090_avg_tlv),
775 SOC_SINGLE_TLV("DMIC4 Boost Volume", M98090_REG_DMIC4_VOLUME,
776 M98090_DMIC_AV4G_SHIFT, M98090_DMIC_AV4G_NUM - 1, 0,
777 max98090_avg_tlv),
778
779 SOC_SINGLE_TLV("DMIC3 Volume", M98090_REG_DMIC3_VOLUME,
780 M98090_DMIC_AV3_SHIFT, M98090_DMIC_AV3_NUM - 1, 1,
781 max98090_av_tlv),
782 SOC_SINGLE_TLV("DMIC4 Volume", M98090_REG_DMIC4_VOLUME,
783 M98090_DMIC_AV4_SHIFT, M98090_DMIC_AV4_NUM - 1, 1,
784 max98090_av_tlv),
785
786 SND_SOC_BYTES("DMIC34 Biquad Coefficients",
787 M98090_REG_DMIC34_BIQUAD_BASE, 15),
788 SOC_SINGLE("DMIC34 Biquad Switch", M98090_REG_DSP_FILTER_ENABLE,
789 M98090_DMIC34BQEN_SHIFT, M98090_DMIC34BQEN_NUM - 1, 0),
790
791 SOC_SINGLE_TLV("DMIC34 BQ PreAttenuation Volume",
792 M98090_REG_DMIC34_BQ_PREATTEN, M98090_AV34BQ_SHIFT,
793 M98090_AV34BQ_NUM - 1, 1, max98090_dv_tlv),
794};
795
796static int max98090_micinput_event(struct snd_soc_dapm_widget *w,
797 struct snd_kcontrol *kcontrol, int event)
798{
799 struct snd_soc_codec *codec = w->codec;
800 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
801
802 unsigned int val = snd_soc_read(codec, w->reg);
803
804 if (w->reg == M98090_REG_MIC1_INPUT_LEVEL)
805 val = (val & M98090_MIC_PA1EN_MASK) >> M98090_MIC_PA1EN_SHIFT;
806 else
807 val = (val & M98090_MIC_PA2EN_MASK) >> M98090_MIC_PA2EN_SHIFT;
808
809
810 if (val >= 1) {
811 if (w->reg == M98090_REG_MIC1_INPUT_LEVEL) {
812 max98090->pa1en = val - 1; /* Update for volatile */
813 } else {
814 max98090->pa2en = val - 1; /* Update for volatile */
815 }
816 }
817
818 switch (event) {
819 case SND_SOC_DAPM_POST_PMU:
820 /* If turning on, set to most recently selected volume */
821 if (w->reg == M98090_REG_MIC1_INPUT_LEVEL)
822 val = max98090->pa1en + 1;
823 else
824 val = max98090->pa2en + 1;
825 break;
826 case SND_SOC_DAPM_POST_PMD:
827 /* If turning off, turn off */
828 val = 0;
829 break;
830 default:
831 return -EINVAL;
832 }
833
834 if (w->reg == M98090_REG_MIC1_INPUT_LEVEL)
835 snd_soc_update_bits(codec, w->reg, M98090_MIC_PA1EN_MASK,
836 val << M98090_MIC_PA1EN_SHIFT);
837 else
838 snd_soc_update_bits(codec, w->reg, M98090_MIC_PA2EN_MASK,
839 val << M98090_MIC_PA2EN_SHIFT);
840
841 return 0;
842}
843
844static const char *mic1_mux_text[] = { "IN12", "IN56" };
845
846static const struct soc_enum mic1_mux_enum =
847 SOC_ENUM_SINGLE(M98090_REG_INPUT_MODE, M98090_EXTMIC1_SHIFT,
848 ARRAY_SIZE(mic1_mux_text), mic1_mux_text);
849
850static const struct snd_kcontrol_new max98090_mic1_mux =
851 SOC_DAPM_ENUM("MIC1 Mux", mic1_mux_enum);
852
853static const char *mic2_mux_text[] = { "IN34", "IN56" };
854
855static const struct soc_enum mic2_mux_enum =
856 SOC_ENUM_SINGLE(M98090_REG_INPUT_MODE, M98090_EXTMIC2_SHIFT,
857 ARRAY_SIZE(mic2_mux_text), mic2_mux_text);
858
859static const struct snd_kcontrol_new max98090_mic2_mux =
860 SOC_DAPM_ENUM("MIC2 Mux", mic2_mux_enum);
861
862static const char * max98090_micpre_text[] = { "Off", "On" };
863
864static const struct soc_enum max98090_pa1en_enum =
865 SOC_ENUM_SINGLE(M98090_REG_MIC1_INPUT_LEVEL, M98090_MIC_PA1EN_SHIFT,
866 ARRAY_SIZE(max98090_micpre_text), max98090_micpre_text);
867
868static const struct soc_enum max98090_pa2en_enum =
869 SOC_ENUM_SINGLE(M98090_REG_MIC2_INPUT_LEVEL, M98090_MIC_PA2EN_SHIFT,
870 ARRAY_SIZE(max98090_micpre_text), max98090_micpre_text);
871
872/* LINEA mixer switch */
873static const struct snd_kcontrol_new max98090_linea_mixer_controls[] = {
874 SOC_DAPM_SINGLE("IN1 Switch", M98090_REG_LINE_INPUT_CONFIG,
875 M98090_IN1SEEN_SHIFT, 1, 0),
876 SOC_DAPM_SINGLE("IN3 Switch", M98090_REG_LINE_INPUT_CONFIG,
877 M98090_IN3SEEN_SHIFT, 1, 0),
878 SOC_DAPM_SINGLE("IN5 Switch", M98090_REG_LINE_INPUT_CONFIG,
879 M98090_IN5SEEN_SHIFT, 1, 0),
880 SOC_DAPM_SINGLE("IN34 Switch", M98090_REG_LINE_INPUT_CONFIG,
881 M98090_IN34DIFF_SHIFT, 1, 0),
882};
883
884/* LINEB mixer switch */
885static const struct snd_kcontrol_new max98090_lineb_mixer_controls[] = {
886 SOC_DAPM_SINGLE("IN2 Switch", M98090_REG_LINE_INPUT_CONFIG,
887 M98090_IN2SEEN_SHIFT, 1, 0),
888 SOC_DAPM_SINGLE("IN4 Switch", M98090_REG_LINE_INPUT_CONFIG,
889 M98090_IN4SEEN_SHIFT, 1, 0),
890 SOC_DAPM_SINGLE("IN6 Switch", M98090_REG_LINE_INPUT_CONFIG,
891 M98090_IN6SEEN_SHIFT, 1, 0),
892 SOC_DAPM_SINGLE("IN56 Switch", M98090_REG_LINE_INPUT_CONFIG,
893 M98090_IN56DIFF_SHIFT, 1, 0),
894};
895
896/* Left ADC mixer switch */
897static const struct snd_kcontrol_new max98090_left_adc_mixer_controls[] = {
898 SOC_DAPM_SINGLE("IN12 Switch", M98090_REG_LEFT_ADC_MIXER,
899 M98090_MIXADL_IN12DIFF_SHIFT, 1, 0),
900 SOC_DAPM_SINGLE("IN34 Switch", M98090_REG_LEFT_ADC_MIXER,
901 M98090_MIXADL_IN34DIFF_SHIFT, 1, 0),
902 SOC_DAPM_SINGLE("IN56 Switch", M98090_REG_LEFT_ADC_MIXER,
903 M98090_MIXADL_IN65DIFF_SHIFT, 1, 0),
904 SOC_DAPM_SINGLE("LINEA Switch", M98090_REG_LEFT_ADC_MIXER,
905 M98090_MIXADL_LINEA_SHIFT, 1, 0),
906 SOC_DAPM_SINGLE("LINEB Switch", M98090_REG_LEFT_ADC_MIXER,
907 M98090_MIXADL_LINEB_SHIFT, 1, 0),
908 SOC_DAPM_SINGLE("MIC1 Switch", M98090_REG_LEFT_ADC_MIXER,
909 M98090_MIXADL_MIC1_SHIFT, 1, 0),
910 SOC_DAPM_SINGLE("MIC2 Switch", M98090_REG_LEFT_ADC_MIXER,
911 M98090_MIXADL_MIC2_SHIFT, 1, 0),
912};
913
914/* Right ADC mixer switch */
915static const struct snd_kcontrol_new max98090_right_adc_mixer_controls[] = {
916 SOC_DAPM_SINGLE("IN12 Switch", M98090_REG_RIGHT_ADC_MIXER,
917 M98090_MIXADR_IN12DIFF_SHIFT, 1, 0),
918 SOC_DAPM_SINGLE("IN34 Switch", M98090_REG_RIGHT_ADC_MIXER,
919 M98090_MIXADR_IN34DIFF_SHIFT, 1, 0),
920 SOC_DAPM_SINGLE("IN56 Switch", M98090_REG_RIGHT_ADC_MIXER,
921 M98090_MIXADR_IN65DIFF_SHIFT, 1, 0),
922 SOC_DAPM_SINGLE("LINEA Switch", M98090_REG_RIGHT_ADC_MIXER,
923 M98090_MIXADR_LINEA_SHIFT, 1, 0),
924 SOC_DAPM_SINGLE("LINEB Switch", M98090_REG_RIGHT_ADC_MIXER,
925 M98090_MIXADR_LINEB_SHIFT, 1, 0),
926 SOC_DAPM_SINGLE("MIC1 Switch", M98090_REG_RIGHT_ADC_MIXER,
927 M98090_MIXADR_MIC1_SHIFT, 1, 0),
928 SOC_DAPM_SINGLE("MIC2 Switch", M98090_REG_RIGHT_ADC_MIXER,
929 M98090_MIXADR_MIC2_SHIFT, 1, 0),
930};
931
932static const char *lten_mux_text[] = { "Normal", "Loopthrough" };
933
934static const struct soc_enum ltenl_mux_enum =
935 SOC_ENUM_SINGLE(M98090_REG_IO_CONFIGURATION, M98090_LTEN_SHIFT,
936 ARRAY_SIZE(lten_mux_text), lten_mux_text);
937
938static const struct soc_enum ltenr_mux_enum =
939 SOC_ENUM_SINGLE(M98090_REG_IO_CONFIGURATION, M98090_LTEN_SHIFT,
940 ARRAY_SIZE(lten_mux_text), lten_mux_text);
941
942static const struct snd_kcontrol_new max98090_ltenl_mux =
943 SOC_DAPM_ENUM("LTENL Mux", ltenl_mux_enum);
944
945static const struct snd_kcontrol_new max98090_ltenr_mux =
946 SOC_DAPM_ENUM("LTENR Mux", ltenr_mux_enum);
947
948static const char *lben_mux_text[] = { "Normal", "Loopback" };
949
950static const struct soc_enum lbenl_mux_enum =
951 SOC_ENUM_SINGLE(M98090_REG_IO_CONFIGURATION, M98090_LBEN_SHIFT,
952 ARRAY_SIZE(lben_mux_text), lben_mux_text);
953
954static const struct soc_enum lbenr_mux_enum =
955 SOC_ENUM_SINGLE(M98090_REG_IO_CONFIGURATION, M98090_LBEN_SHIFT,
956 ARRAY_SIZE(lben_mux_text), lben_mux_text);
957
958static const struct snd_kcontrol_new max98090_lbenl_mux =
959 SOC_DAPM_ENUM("LBENL Mux", lbenl_mux_enum);
960
961static const struct snd_kcontrol_new max98090_lbenr_mux =
962 SOC_DAPM_ENUM("LBENR Mux", lbenr_mux_enum);
963
964static const char *stenl_mux_text[] = { "Normal", "Sidetone Left" };
965
966static const char *stenr_mux_text[] = { "Normal", "Sidetone Right" };
967
968static const struct soc_enum stenl_mux_enum =
969 SOC_ENUM_SINGLE(M98090_REG_ADC_SIDETONE, M98090_DSTSL_SHIFT,
970 ARRAY_SIZE(stenl_mux_text), stenl_mux_text);
971
972static const struct soc_enum stenr_mux_enum =
973 SOC_ENUM_SINGLE(M98090_REG_ADC_SIDETONE, M98090_DSTSR_SHIFT,
974 ARRAY_SIZE(stenr_mux_text), stenr_mux_text);
975
976static const struct snd_kcontrol_new max98090_stenl_mux =
977 SOC_DAPM_ENUM("STENL Mux", stenl_mux_enum);
978
979static const struct snd_kcontrol_new max98090_stenr_mux =
980 SOC_DAPM_ENUM("STENR Mux", stenr_mux_enum);
981
982/* Left speaker mixer switch */
983static const struct
984 snd_kcontrol_new max98090_left_speaker_mixer_controls[] = {
985 SOC_DAPM_SINGLE("Left DAC Switch", M98090_REG_LEFT_SPK_MIXER,
986 M98090_MIXSPL_DACL_SHIFT, 1, 0),
987 SOC_DAPM_SINGLE("Right DAC Switch", M98090_REG_LEFT_SPK_MIXER,
988 M98090_MIXSPL_DACR_SHIFT, 1, 0),
989 SOC_DAPM_SINGLE("LINEA Switch", M98090_REG_LEFT_SPK_MIXER,
990 M98090_MIXSPL_LINEA_SHIFT, 1, 0),
991 SOC_DAPM_SINGLE("LINEB Switch", M98090_REG_LEFT_SPK_MIXER,
992 M98090_MIXSPL_LINEB_SHIFT, 1, 0),
993 SOC_DAPM_SINGLE("MIC1 Switch", M98090_REG_LEFT_SPK_MIXER,
994 M98090_MIXSPL_MIC1_SHIFT, 1, 0),
995 SOC_DAPM_SINGLE("MIC2 Switch", M98090_REG_LEFT_SPK_MIXER,
996 M98090_MIXSPL_MIC2_SHIFT, 1, 0),
997};
998
999/* Right speaker mixer switch */
1000static const struct
1001 snd_kcontrol_new max98090_right_speaker_mixer_controls[] = {
1002 SOC_DAPM_SINGLE("Left DAC Switch", M98090_REG_RIGHT_SPK_MIXER,
1003 M98090_MIXSPR_DACL_SHIFT, 1, 0),
1004 SOC_DAPM_SINGLE("Right DAC Switch", M98090_REG_RIGHT_SPK_MIXER,
1005 M98090_MIXSPR_DACR_SHIFT, 1, 0),
1006 SOC_DAPM_SINGLE("LINEA Switch", M98090_REG_RIGHT_SPK_MIXER,
1007 M98090_MIXSPR_LINEA_SHIFT, 1, 0),
1008 SOC_DAPM_SINGLE("LINEB Switch", M98090_REG_RIGHT_SPK_MIXER,
1009 M98090_MIXSPR_LINEB_SHIFT, 1, 0),
1010 SOC_DAPM_SINGLE("MIC1 Switch", M98090_REG_RIGHT_SPK_MIXER,
1011 M98090_MIXSPR_MIC1_SHIFT, 1, 0),
1012 SOC_DAPM_SINGLE("MIC2 Switch", M98090_REG_RIGHT_SPK_MIXER,
1013 M98090_MIXSPR_MIC2_SHIFT, 1, 0),
1014};
1015
1016/* Left headphone mixer switch */
1017static const struct snd_kcontrol_new max98090_left_hp_mixer_controls[] = {
1018 SOC_DAPM_SINGLE("Left DAC Switch", M98090_REG_LEFT_HP_MIXER,
1019 M98090_MIXHPL_DACL_SHIFT, 1, 0),
1020 SOC_DAPM_SINGLE("Right DAC Switch", M98090_REG_LEFT_HP_MIXER,
1021 M98090_MIXHPL_DACR_SHIFT, 1, 0),
1022 SOC_DAPM_SINGLE("LINEA Switch", M98090_REG_LEFT_HP_MIXER,
1023 M98090_MIXHPL_LINEA_SHIFT, 1, 0),
1024 SOC_DAPM_SINGLE("LINEB Switch", M98090_REG_LEFT_HP_MIXER,
1025 M98090_MIXHPL_LINEB_SHIFT, 1, 0),
1026 SOC_DAPM_SINGLE("MIC1 Switch", M98090_REG_LEFT_HP_MIXER,
1027 M98090_MIXHPL_MIC1_SHIFT, 1, 0),
1028 SOC_DAPM_SINGLE("MIC2 Switch", M98090_REG_LEFT_HP_MIXER,
1029 M98090_MIXHPL_MIC2_SHIFT, 1, 0),
1030};
1031
1032/* Right headphone mixer switch */
1033static const struct snd_kcontrol_new max98090_right_hp_mixer_controls[] = {
1034 SOC_DAPM_SINGLE("Left DAC Switch", M98090_REG_RIGHT_HP_MIXER,
1035 M98090_MIXHPR_DACL_SHIFT, 1, 0),
1036 SOC_DAPM_SINGLE("Right DAC Switch", M98090_REG_RIGHT_HP_MIXER,
1037 M98090_MIXHPR_DACR_SHIFT, 1, 0),
1038 SOC_DAPM_SINGLE("LINEA Switch", M98090_REG_RIGHT_HP_MIXER,
1039 M98090_MIXHPR_LINEA_SHIFT, 1, 0),
1040 SOC_DAPM_SINGLE("LINEB Switch", M98090_REG_RIGHT_HP_MIXER,
1041 M98090_MIXHPR_LINEB_SHIFT, 1, 0),
1042 SOC_DAPM_SINGLE("MIC1 Switch", M98090_REG_RIGHT_HP_MIXER,
1043 M98090_MIXHPR_MIC1_SHIFT, 1, 0),
1044 SOC_DAPM_SINGLE("MIC2 Switch", M98090_REG_RIGHT_HP_MIXER,
1045 M98090_MIXHPR_MIC2_SHIFT, 1, 0),
1046};
1047
1048/* Left receiver mixer switch */
1049static const struct snd_kcontrol_new max98090_left_rcv_mixer_controls[] = {
1050 SOC_DAPM_SINGLE("Left DAC Switch", M98090_REG_RCV_LOUTL_MIXER,
1051 M98090_MIXRCVL_DACL_SHIFT, 1, 0),
1052 SOC_DAPM_SINGLE("Right DAC Switch", M98090_REG_RCV_LOUTL_MIXER,
1053 M98090_MIXRCVL_DACR_SHIFT, 1, 0),
1054 SOC_DAPM_SINGLE("LINEA Switch", M98090_REG_RCV_LOUTL_MIXER,
1055 M98090_MIXRCVL_LINEA_SHIFT, 1, 0),
1056 SOC_DAPM_SINGLE("LINEB Switch", M98090_REG_RCV_LOUTL_MIXER,
1057 M98090_MIXRCVL_LINEB_SHIFT, 1, 0),
1058 SOC_DAPM_SINGLE("MIC1 Switch", M98090_REG_RCV_LOUTL_MIXER,
1059 M98090_MIXRCVL_MIC1_SHIFT, 1, 0),
1060 SOC_DAPM_SINGLE("MIC2 Switch", M98090_REG_RCV_LOUTL_MIXER,
1061 M98090_MIXRCVL_MIC2_SHIFT, 1, 0),
1062};
1063
1064/* Right receiver mixer switch */
1065static const struct snd_kcontrol_new max98090_right_rcv_mixer_controls[] = {
1066 SOC_DAPM_SINGLE("Left DAC Switch", M98090_REG_LOUTR_MIXER,
1067 M98090_MIXRCVR_DACL_SHIFT, 1, 0),
1068 SOC_DAPM_SINGLE("Right DAC Switch", M98090_REG_LOUTR_MIXER,
1069 M98090_MIXRCVR_DACR_SHIFT, 1, 0),
1070 SOC_DAPM_SINGLE("LINEA Switch", M98090_REG_LOUTR_MIXER,
1071 M98090_MIXRCVR_LINEA_SHIFT, 1, 0),
1072 SOC_DAPM_SINGLE("LINEB Switch", M98090_REG_LOUTR_MIXER,
1073 M98090_MIXRCVR_LINEB_SHIFT, 1, 0),
1074 SOC_DAPM_SINGLE("MIC1 Switch", M98090_REG_LOUTR_MIXER,
1075 M98090_MIXRCVR_MIC1_SHIFT, 1, 0),
1076 SOC_DAPM_SINGLE("MIC2 Switch", M98090_REG_LOUTR_MIXER,
1077 M98090_MIXRCVR_MIC2_SHIFT, 1, 0),
1078};
1079
1080static const char *linmod_mux_text[] = { "Left Only", "Left and Right" };
1081
1082static const struct soc_enum linmod_mux_enum =
1083 SOC_ENUM_SINGLE(M98090_REG_LOUTR_MIXER, M98090_LINMOD_SHIFT,
1084 ARRAY_SIZE(linmod_mux_text), linmod_mux_text);
1085
1086static const struct snd_kcontrol_new max98090_linmod_mux =
1087 SOC_DAPM_ENUM("LINMOD Mux", linmod_mux_enum);
1088
1089static const char *mixhpsel_mux_text[] = { "DAC Only", "HP Mixer" };
1090
1091/*
1092 * This is a mux as it selects the HP output, but to DAPM it is a Mixer enable
1093 */
1094static const struct soc_enum mixhplsel_mux_enum =
1095 SOC_ENUM_SINGLE(M98090_REG_HP_CONTROL, M98090_MIXHPLSEL_SHIFT,
1096 ARRAY_SIZE(mixhpsel_mux_text), mixhpsel_mux_text);
1097
1098static const struct snd_kcontrol_new max98090_mixhplsel_mux =
1099 SOC_DAPM_ENUM("MIXHPLSEL Mux", mixhplsel_mux_enum);
1100
1101static const struct soc_enum mixhprsel_mux_enum =
1102 SOC_ENUM_SINGLE(M98090_REG_HP_CONTROL, M98090_MIXHPRSEL_SHIFT,
1103 ARRAY_SIZE(mixhpsel_mux_text), mixhpsel_mux_text);
1104
1105static const struct snd_kcontrol_new max98090_mixhprsel_mux =
1106 SOC_DAPM_ENUM("MIXHPRSEL Mux", mixhprsel_mux_enum);
1107
1108static const struct snd_soc_dapm_widget max98090_dapm_widgets[] = {
1109
1110 SND_SOC_DAPM_INPUT("MIC1"),
1111 SND_SOC_DAPM_INPUT("MIC2"),
1112 SND_SOC_DAPM_INPUT("DMICL"),
1113 SND_SOC_DAPM_INPUT("DMICR"),
1114 SND_SOC_DAPM_INPUT("IN1"),
1115 SND_SOC_DAPM_INPUT("IN2"),
1116 SND_SOC_DAPM_INPUT("IN3"),
1117 SND_SOC_DAPM_INPUT("IN4"),
1118 SND_SOC_DAPM_INPUT("IN5"),
1119 SND_SOC_DAPM_INPUT("IN6"),
1120 SND_SOC_DAPM_INPUT("IN12"),
1121 SND_SOC_DAPM_INPUT("IN34"),
1122 SND_SOC_DAPM_INPUT("IN56"),
1123
1124 SND_SOC_DAPM_SUPPLY("MICBIAS", M98090_REG_INPUT_ENABLE,
1125 M98090_MBEN_SHIFT, 0, NULL, 0),
1126 SND_SOC_DAPM_SUPPLY("SHDN", M98090_REG_DEVICE_SHUTDOWN,
1127 M98090_SHDNN_SHIFT, 0, NULL, 0),
1128 SND_SOC_DAPM_SUPPLY("SDIEN", M98090_REG_IO_CONFIGURATION,
1129 M98090_SDIEN_SHIFT, 0, NULL, 0),
1130 SND_SOC_DAPM_SUPPLY("SDOEN", M98090_REG_IO_CONFIGURATION,
1131 M98090_SDOEN_SHIFT, 0, NULL, 0),
1132 SND_SOC_DAPM_SUPPLY("DMICL_ENA", M98090_REG_DIGITAL_MIC_ENABLE,
1133 M98090_DIGMICL_SHIFT, 0, NULL, 0),
1134 SND_SOC_DAPM_SUPPLY("DMICR_ENA", M98090_REG_DIGITAL_MIC_ENABLE,
1135 M98090_DIGMICR_SHIFT, 0, NULL, 0),
1136 SND_SOC_DAPM_SUPPLY("AHPF", M98090_REG_FILTER_CONFIG,
1137 M98090_AHPF_SHIFT, 0, NULL, 0),
1138
1139/*
1140 * Note: Sysclk and misc power supplies are taken care of by SHDN
1141 */
1142
1143 SND_SOC_DAPM_MUX("MIC1 Mux", SND_SOC_NOPM,
1144 0, 0, &max98090_mic1_mux),
1145
1146 SND_SOC_DAPM_MUX("MIC2 Mux", SND_SOC_NOPM,
1147 0, 0, &max98090_mic2_mux),
1148
1149 SND_SOC_DAPM_PGA_E("MIC1 Input", M98090_REG_MIC1_INPUT_LEVEL,
1150 M98090_MIC_PA1EN_SHIFT, 0, NULL, 0, max98090_micinput_event,
1151 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1152
1153 SND_SOC_DAPM_PGA_E("MIC2 Input", M98090_REG_MIC2_INPUT_LEVEL,
1154 M98090_MIC_PA2EN_SHIFT, 0, NULL, 0, max98090_micinput_event,
1155 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1156
1157 SND_SOC_DAPM_MIXER("LINEA Mixer", SND_SOC_NOPM, 0, 0,
1158 &max98090_linea_mixer_controls[0],
1159 ARRAY_SIZE(max98090_linea_mixer_controls)),
1160
1161 SND_SOC_DAPM_MIXER("LINEB Mixer", SND_SOC_NOPM, 0, 0,
1162 &max98090_lineb_mixer_controls[0],
1163 ARRAY_SIZE(max98090_lineb_mixer_controls)),
1164
1165 SND_SOC_DAPM_PGA("LINEA Input", M98090_REG_INPUT_ENABLE,
1166 M98090_LINEAEN_SHIFT, 0, NULL, 0),
1167 SND_SOC_DAPM_PGA("LINEB Input", M98090_REG_INPUT_ENABLE,
1168 M98090_LINEBEN_SHIFT, 0, NULL, 0),
1169
1170 SND_SOC_DAPM_MIXER("Left ADC Mixer", SND_SOC_NOPM, 0, 0,
1171 &max98090_left_adc_mixer_controls[0],
1172 ARRAY_SIZE(max98090_left_adc_mixer_controls)),
1173
1174 SND_SOC_DAPM_MIXER("Right ADC Mixer", SND_SOC_NOPM, 0, 0,
1175 &max98090_right_adc_mixer_controls[0],
1176 ARRAY_SIZE(max98090_right_adc_mixer_controls)),
1177
1178 SND_SOC_DAPM_ADC("ADCL", NULL, M98090_REG_INPUT_ENABLE,
1179 M98090_ADLEN_SHIFT, 0),
1180 SND_SOC_DAPM_ADC("ADCR", NULL, M98090_REG_INPUT_ENABLE,
1181 M98090_ADREN_SHIFT, 0),
1182
1183 SND_SOC_DAPM_AIF_OUT("AIFOUTL", "HiFi Capture", 0,
1184 SND_SOC_NOPM, 0, 0),
1185 SND_SOC_DAPM_AIF_OUT("AIFOUTR", "HiFi Capture", 1,
1186 SND_SOC_NOPM, 0, 0),
1187
1188 SND_SOC_DAPM_MUX("LBENL Mux", SND_SOC_NOPM,
1189 0, 0, &max98090_lbenl_mux),
1190
1191 SND_SOC_DAPM_MUX("LBENR Mux", SND_SOC_NOPM,
1192 0, 0, &max98090_lbenr_mux),
1193
1194 SND_SOC_DAPM_MUX("LTENL Mux", SND_SOC_NOPM,
1195 0, 0, &max98090_ltenl_mux),
1196
1197 SND_SOC_DAPM_MUX("LTENR Mux", SND_SOC_NOPM,
1198 0, 0, &max98090_ltenr_mux),
1199
1200 SND_SOC_DAPM_MUX("STENL Mux", SND_SOC_NOPM,
1201 0, 0, &max98090_stenl_mux),
1202
1203 SND_SOC_DAPM_MUX("STENR Mux", SND_SOC_NOPM,
1204 0, 0, &max98090_stenr_mux),
1205
1206 SND_SOC_DAPM_AIF_IN("AIFINL", "HiFi Playback", 0, SND_SOC_NOPM, 0, 0),
1207 SND_SOC_DAPM_AIF_IN("AIFINR", "HiFi Playback", 1, SND_SOC_NOPM, 0, 0),
1208
1209 SND_SOC_DAPM_DAC("DACL", NULL, M98090_REG_OUTPUT_ENABLE,
1210 M98090_DALEN_SHIFT, 0),
1211 SND_SOC_DAPM_DAC("DACR", NULL, M98090_REG_OUTPUT_ENABLE,
1212 M98090_DAREN_SHIFT, 0),
1213
1214 SND_SOC_DAPM_MIXER("Left Headphone Mixer", SND_SOC_NOPM, 0, 0,
1215 &max98090_left_hp_mixer_controls[0],
1216 ARRAY_SIZE(max98090_left_hp_mixer_controls)),
1217
1218 SND_SOC_DAPM_MIXER("Right Headphone Mixer", SND_SOC_NOPM, 0, 0,
1219 &max98090_right_hp_mixer_controls[0],
1220 ARRAY_SIZE(max98090_right_hp_mixer_controls)),
1221
1222 SND_SOC_DAPM_MIXER("Left Speaker Mixer", SND_SOC_NOPM, 0, 0,
1223 &max98090_left_speaker_mixer_controls[0],
1224 ARRAY_SIZE(max98090_left_speaker_mixer_controls)),
1225
1226 SND_SOC_DAPM_MIXER("Right Speaker Mixer", SND_SOC_NOPM, 0, 0,
1227 &max98090_right_speaker_mixer_controls[0],
1228 ARRAY_SIZE(max98090_right_speaker_mixer_controls)),
1229
1230 SND_SOC_DAPM_MIXER("Left Receiver Mixer", SND_SOC_NOPM, 0, 0,
1231 &max98090_left_rcv_mixer_controls[0],
1232 ARRAY_SIZE(max98090_left_rcv_mixer_controls)),
1233
1234 SND_SOC_DAPM_MIXER("Right Receiver Mixer", SND_SOC_NOPM, 0, 0,
1235 &max98090_right_rcv_mixer_controls[0],
1236 ARRAY_SIZE(max98090_right_rcv_mixer_controls)),
1237
1238 SND_SOC_DAPM_MUX("LINMOD Mux", M98090_REG_LOUTR_MIXER,
1239 M98090_LINMOD_SHIFT, 0, &max98090_linmod_mux),
1240
1241 SND_SOC_DAPM_MUX("MIXHPLSEL Mux", M98090_REG_HP_CONTROL,
1242 M98090_MIXHPLSEL_SHIFT, 0, &max98090_mixhplsel_mux),
1243
1244 SND_SOC_DAPM_MUX("MIXHPRSEL Mux", M98090_REG_HP_CONTROL,
1245 M98090_MIXHPRSEL_SHIFT, 0, &max98090_mixhprsel_mux),
1246
1247 SND_SOC_DAPM_PGA("HP Left Out", M98090_REG_OUTPUT_ENABLE,
1248 M98090_HPLEN_SHIFT, 0, NULL, 0),
1249 SND_SOC_DAPM_PGA("HP Right Out", M98090_REG_OUTPUT_ENABLE,
1250 M98090_HPREN_SHIFT, 0, NULL, 0),
1251
1252 SND_SOC_DAPM_PGA("SPK Left Out", M98090_REG_OUTPUT_ENABLE,
1253 M98090_SPLEN_SHIFT, 0, NULL, 0),
1254 SND_SOC_DAPM_PGA("SPK Right Out", M98090_REG_OUTPUT_ENABLE,
1255 M98090_SPREN_SHIFT, 0, NULL, 0),
1256
1257 SND_SOC_DAPM_PGA("RCV Left Out", M98090_REG_OUTPUT_ENABLE,
1258 M98090_RCVLEN_SHIFT, 0, NULL, 0),
1259 SND_SOC_DAPM_PGA("RCV Right Out", M98090_REG_OUTPUT_ENABLE,
1260 M98090_RCVREN_SHIFT, 0, NULL, 0),
1261
283 SND_SOC_DAPM_OUTPUT("HPL"), 1262 SND_SOC_DAPM_OUTPUT("HPL"),
284 SND_SOC_DAPM_OUTPUT("HPR"), 1263 SND_SOC_DAPM_OUTPUT("HPR"),
1264 SND_SOC_DAPM_OUTPUT("SPKL"),
1265 SND_SOC_DAPM_OUTPUT("SPKR"),
1266 SND_SOC_DAPM_OUTPUT("RCVL"),
1267 SND_SOC_DAPM_OUTPUT("RCVR"),
1268};
1269
1270static const struct snd_soc_dapm_widget max98091_dapm_widgets[] = {
285 1271
286 /* PGA */ 1272 SND_SOC_DAPM_INPUT("DMIC3"),
287 SND_SOC_DAPM_PGA("HPL Out", MAX98090_0x3F_OUT_ENABLE, 7, 0, NULL, 0), 1273 SND_SOC_DAPM_INPUT("DMIC4"),
288 SND_SOC_DAPM_PGA("HPR Out", MAX98090_0x3F_OUT_ENABLE, 6, 0, NULL, 0),
289 1274
290 /* Mixer */ 1275 SND_SOC_DAPM_SUPPLY("DMIC3_ENA", M98090_REG_DIGITAL_MIC_ENABLE,
291 SND_SOC_DAPM_MIXER("HPL Mixer", SND_SOC_NOPM, 0, 0, 1276 M98090_DIGMIC3_SHIFT, 0, NULL, 0),
292 max98090_left_hp_mixer_controls, 1277 SND_SOC_DAPM_SUPPLY("DMIC4_ENA", M98090_REG_DIGITAL_MIC_ENABLE,
293 ARRAY_SIZE(max98090_left_hp_mixer_controls)), 1278 M98090_DIGMIC4_SHIFT, 0, NULL, 0),
1279};
294 1280
295 SND_SOC_DAPM_MIXER("HPR Mixer", SND_SOC_NOPM, 0, 0, 1281static const struct snd_soc_dapm_route max98090_dapm_routes[] = {
296 max98090_right_hp_mixer_controls, 1282
297 ARRAY_SIZE(max98090_right_hp_mixer_controls)), 1283 {"MIC1 Input", NULL, "MIC1"},
1284 {"MIC2 Input", NULL, "MIC2"},
1285
1286 {"DMICL", NULL, "DMICL_ENA"},
1287 {"DMICR", NULL, "DMICR_ENA"},
1288 {"DMICL", NULL, "AHPF"},
1289 {"DMICR", NULL, "AHPF"},
1290
1291 /* MIC1 input mux */
1292 {"MIC1 Mux", "IN12", "IN12"},
1293 {"MIC1 Mux", "IN56", "IN56"},
1294
1295 /* MIC2 input mux */
1296 {"MIC2 Mux", "IN34", "IN34"},
1297 {"MIC2 Mux", "IN56", "IN56"},
1298
1299 {"MIC1 Input", NULL, "MIC1 Mux"},
1300 {"MIC2 Input", NULL, "MIC2 Mux"},
1301
1302 /* Left ADC input mixer */
1303 {"Left ADC Mixer", "IN12 Switch", "IN12"},
1304 {"Left ADC Mixer", "IN34 Switch", "IN34"},
1305 {"Left ADC Mixer", "IN56 Switch", "IN56"},
1306 {"Left ADC Mixer", "LINEA Switch", "LINEA Input"},
1307 {"Left ADC Mixer", "LINEB Switch", "LINEB Input"},
1308 {"Left ADC Mixer", "MIC1 Switch", "MIC1 Input"},
1309 {"Left ADC Mixer", "MIC2 Switch", "MIC2 Input"},
1310
1311 /* Right ADC input mixer */
1312 {"Right ADC Mixer", "IN12 Switch", "IN12"},
1313 {"Right ADC Mixer", "IN34 Switch", "IN34"},
1314 {"Right ADC Mixer", "IN56 Switch", "IN56"},
1315 {"Right ADC Mixer", "LINEA Switch", "LINEA Input"},
1316 {"Right ADC Mixer", "LINEB Switch", "LINEB Input"},
1317 {"Right ADC Mixer", "MIC1 Switch", "MIC1 Input"},
1318 {"Right ADC Mixer", "MIC2 Switch", "MIC2 Input"},
1319
1320 /* Line A input mixer */
1321 {"LINEA Mixer", "IN1 Switch", "IN1"},
1322 {"LINEA Mixer", "IN3 Switch", "IN3"},
1323 {"LINEA Mixer", "IN5 Switch", "IN5"},
1324 {"LINEA Mixer", "IN34 Switch", "IN34"},
1325
1326 /* Line B input mixer */
1327 {"LINEB Mixer", "IN2 Switch", "IN2"},
1328 {"LINEB Mixer", "IN4 Switch", "IN4"},
1329 {"LINEB Mixer", "IN6 Switch", "IN6"},
1330 {"LINEB Mixer", "IN56 Switch", "IN56"},
1331
1332 {"LINEA Input", NULL, "LINEA Mixer"},
1333 {"LINEB Input", NULL, "LINEB Mixer"},
1334
1335 /* Inputs */
1336 {"ADCL", NULL, "Left ADC Mixer"},
1337 {"ADCR", NULL, "Right ADC Mixer"},
1338 {"ADCL", NULL, "SHDN"},
1339 {"ADCR", NULL, "SHDN"},
1340
1341 {"LBENL Mux", "Normal", "ADCL"},
1342 {"LBENL Mux", "Normal", "DMICL"},
1343 {"LBENL Mux", "Loopback", "LTENL Mux"},
1344 {"LBENR Mux", "Normal", "ADCR"},
1345 {"LBENR Mux", "Normal", "DMICR"},
1346 {"LBENR Mux", "Loopback", "LTENR Mux"},
1347
1348 {"AIFOUTL", NULL, "LBENL Mux"},
1349 {"AIFOUTR", NULL, "LBENR Mux"},
1350 {"AIFOUTL", NULL, "SHDN"},
1351 {"AIFOUTR", NULL, "SHDN"},
1352 {"AIFOUTL", NULL, "SDOEN"},
1353 {"AIFOUTR", NULL, "SDOEN"},
1354
1355 {"LTENL Mux", "Normal", "AIFINL"},
1356 {"LTENL Mux", "Loopthrough", "LBENL Mux"},
1357 {"LTENR Mux", "Normal", "AIFINR"},
1358 {"LTENR Mux", "Loopthrough", "LBENR Mux"},
1359
1360 {"DACL", NULL, "LTENL Mux"},
1361 {"DACR", NULL, "LTENR Mux"},
1362
1363 {"STENL Mux", "Sidetone Left", "ADCL"},
1364 {"STENL Mux", "Sidetone Left", "DMICL"},
1365 {"STENR Mux", "Sidetone Right", "ADCR"},
1366 {"STENR Mux", "Sidetone Right", "DMICR"},
1367 {"DACL", "NULL", "STENL Mux"},
1368 {"DACR", "NULL", "STENL Mux"},
1369
1370 {"AIFINL", NULL, "SHDN"},
1371 {"AIFINR", NULL, "SHDN"},
1372 {"AIFINL", NULL, "SDIEN"},
1373 {"AIFINR", NULL, "SDIEN"},
1374 {"DACL", NULL, "SHDN"},
1375 {"DACR", NULL, "SHDN"},
1376
1377 /* Left headphone output mixer */
1378 {"Left Headphone Mixer", "Left DAC Switch", "DACL"},
1379 {"Left Headphone Mixer", "Right DAC Switch", "DACR"},
1380 {"Left Headphone Mixer", "MIC1 Switch", "MIC1 Input"},
1381 {"Left Headphone Mixer", "MIC2 Switch", "MIC2 Input"},
1382 {"Left Headphone Mixer", "LINEA Switch", "LINEA Input"},
1383 {"Left Headphone Mixer", "LINEB Switch", "LINEB Input"},
1384
1385 /* Right headphone output mixer */
1386 {"Right Headphone Mixer", "Left DAC Switch", "DACL"},
1387 {"Right Headphone Mixer", "Right DAC Switch", "DACR"},
1388 {"Right Headphone Mixer", "MIC1 Switch", "MIC1 Input"},
1389 {"Right Headphone Mixer", "MIC2 Switch", "MIC2 Input"},
1390 {"Right Headphone Mixer", "LINEA Switch", "LINEA Input"},
1391 {"Right Headphone Mixer", "LINEB Switch", "LINEB Input"},
1392
1393 /* Left speaker output mixer */
1394 {"Left Speaker Mixer", "Left DAC Switch", "DACL"},
1395 {"Left Speaker Mixer", "Right DAC Switch", "DACR"},
1396 {"Left Speaker Mixer", "MIC1 Switch", "MIC1 Input"},
1397 {"Left Speaker Mixer", "MIC2 Switch", "MIC2 Input"},
1398 {"Left Speaker Mixer", "LINEA Switch", "LINEA Input"},
1399 {"Left Speaker Mixer", "LINEB Switch", "LINEB Input"},
1400
1401 /* Right speaker output mixer */
1402 {"Right Speaker Mixer", "Left DAC Switch", "DACL"},
1403 {"Right Speaker Mixer", "Right DAC Switch", "DACR"},
1404 {"Right Speaker Mixer", "MIC1 Switch", "MIC1 Input"},
1405 {"Right Speaker Mixer", "MIC2 Switch", "MIC2 Input"},
1406 {"Right Speaker Mixer", "LINEA Switch", "LINEA Input"},
1407 {"Right Speaker Mixer", "LINEB Switch", "LINEB Input"},
1408
1409 /* Left Receiver output mixer */
1410 {"Left Receiver Mixer", "Left DAC Switch", "DACL"},
1411 {"Left Receiver Mixer", "Right DAC Switch", "DACR"},
1412 {"Left Receiver Mixer", "MIC1 Switch", "MIC1 Input"},
1413 {"Left Receiver Mixer", "MIC2 Switch", "MIC2 Input"},
1414 {"Left Receiver Mixer", "LINEA Switch", "LINEA Input"},
1415 {"Left Receiver Mixer", "LINEB Switch", "LINEB Input"},
1416
1417 /* Right Receiver output mixer */
1418 {"Right Receiver Mixer", "Left DAC Switch", "DACL"},
1419 {"Right Receiver Mixer", "Right DAC Switch", "DACR"},
1420 {"Right Receiver Mixer", "MIC1 Switch", "MIC1 Input"},
1421 {"Right Receiver Mixer", "MIC2 Switch", "MIC2 Input"},
1422 {"Right Receiver Mixer", "LINEA Switch", "LINEA Input"},
1423 {"Right Receiver Mixer", "LINEB Switch", "LINEB Input"},
1424
1425 {"MIXHPLSEL Mux", "HP Mixer", "Left Headphone Mixer"},
1426
1427 /*
1428 * Disable this for lowest power if bypassing
1429 * the DAC with an analog signal
1430 */
1431 {"HP Left Out", NULL, "DACL"},
1432 {"HP Left Out", NULL, "MIXHPLSEL Mux"},
1433
1434 {"MIXHPRSEL Mux", "HP Mixer", "Right Headphone Mixer"},
1435
1436 /*
1437 * Disable this for lowest power if bypassing
1438 * the DAC with an analog signal
1439 */
1440 {"HP Right Out", NULL, "DACR"},
1441 {"HP Right Out", NULL, "MIXHPRSEL Mux"},
1442
1443 {"SPK Left Out", NULL, "Left Speaker Mixer"},
1444 {"SPK Right Out", NULL, "Right Speaker Mixer"},
1445 {"RCV Left Out", NULL, "Left Receiver Mixer"},
1446
1447 {"LINMOD Mux", "Left and Right", "Right Receiver Mixer"},
1448 {"LINMOD Mux", "Left Only", "Left Receiver Mixer"},
1449 {"RCV Right Out", NULL, "LINMOD Mux"},
1450
1451 {"HPL", NULL, "HP Left Out"},
1452 {"HPR", NULL, "HP Right Out"},
1453 {"SPKL", NULL, "SPK Left Out"},
1454 {"SPKR", NULL, "SPK Right Out"},
1455 {"RCVL", NULL, "RCV Left Out"},
1456 {"RCVR", NULL, "RCV Right Out"},
298 1457
299 /* DAC */
300 SND_SOC_DAPM_DAC("DACL", "Hifi Playback", MAX98090_0x3F_OUT_ENABLE, 0, 0),
301 SND_SOC_DAPM_DAC("DACR", "Hifi Playback", MAX98090_0x3F_OUT_ENABLE, 1, 0),
302}; 1458};
303 1459
304static struct snd_soc_dapm_route max98090_audio_map[] = { 1460static const struct snd_soc_dapm_route max98091_dapm_routes[] = {
305 /* Output */ 1461
306 {"HPL", NULL, "HPL Out"}, 1462 /* DMIC inputs */
307 {"HPR", NULL, "HPR Out"}, 1463 {"DMIC3", NULL, "DMIC3_ENA"},
1464 {"DMIC4", NULL, "DMIC4_ENA"},
1465 {"DMIC3", NULL, "AHPF"},
1466 {"DMIC4", NULL, "AHPF"},
1467
1468};
1469
1470static int max98090_add_widgets(struct snd_soc_codec *codec)
1471{
1472 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
1473 struct snd_soc_dapm_context *dapm = &codec->dapm;
1474
1475 snd_soc_add_codec_controls(codec, max98090_snd_controls,
1476 ARRAY_SIZE(max98090_snd_controls));
308 1477
309 /* PGA */ 1478 if (max98090->devtype == MAX98091) {
310 {"HPL Out", NULL, "HPL Mixer"}, 1479 snd_soc_add_codec_controls(codec, max98091_snd_controls,
311 {"HPR Out", NULL, "HPR Mixer"}, 1480 ARRAY_SIZE(max98091_snd_controls));
1481 }
1482
1483 snd_soc_dapm_new_controls(dapm, max98090_dapm_widgets,
1484 ARRAY_SIZE(max98090_dapm_widgets));
1485
1486 snd_soc_dapm_add_routes(dapm, max98090_dapm_routes,
1487 ARRAY_SIZE(max98090_dapm_routes));
1488
1489 if (max98090->devtype == MAX98091) {
1490 snd_soc_dapm_new_controls(dapm, max98091_dapm_widgets,
1491 ARRAY_SIZE(max98091_dapm_widgets));
1492
1493 snd_soc_dapm_add_routes(dapm, max98091_dapm_routes,
1494 ARRAY_SIZE(max98091_dapm_routes));
1495
1496 }
312 1497
313 /* Mixer*/ 1498 return 0;
314 {"HPL Mixer", "DACR Switch", "DACR"}, 1499}
315 {"HPL Mixer", "DACL Switch", "DACL"}, 1500
1501static const int pclk_rates[] = {
1502 12000000, 12000000, 13000000, 13000000,
1503 16000000, 16000000, 19200000, 19200000
1504};
1505
1506static const int lrclk_rates[] = {
1507 8000, 16000, 8000, 16000,
1508 8000, 16000, 8000, 16000
1509};
316 1510
317 {"HPR Mixer", "DACR Switch", "DACR"}, 1511static const int user_pclk_rates[] = {
318 {"HPR Mixer", "DACL Switch", "DACL"}, 1512 13000000, 13000000
319}; 1513};
320 1514
321static bool max98090_volatile(struct device *dev, unsigned int reg) 1515static const int user_lrclk_rates[] = {
1516 44100, 48000
1517};
1518
1519static const unsigned long long ni_value[] = {
1520 3528, 768
1521};
1522
1523static const unsigned long long mi_value[] = {
1524 8125, 1625
1525};
1526
1527static void max98090_configure_bclk(struct snd_soc_codec *codec)
322{ 1528{
323 if ((reg == MAX98090_0x01_INT_STS) || 1529 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
324 (reg == MAX98090_0x02_JACK_STS) || 1530 unsigned long long ni;
325 (reg > MAX98090_REG_MAX_CACHED)) 1531 int i;
326 return true; 1532
1533 if (!max98090->sysclk) {
1534 dev_err(codec->dev, "No SYSCLK configured\n");
1535 return;
1536 }
1537
1538 if (!max98090->bclk || !max98090->lrclk) {
1539 dev_err(codec->dev, "No audio clocks configured\n");
1540 return;
1541 }
1542
1543 /* Skip configuration when operating as slave */
1544 if (!(snd_soc_read(codec, M98090_REG_MASTER_MODE) &
1545 M98090_MAS_MASK)) {
1546 return;
1547 }
327 1548
328 return false; 1549 /* Check for supported PCLK to LRCLK ratios */
1550 for (i = 0; i < ARRAY_SIZE(pclk_rates); i++) {
1551 if ((pclk_rates[i] == max98090->sysclk) &&
1552 (lrclk_rates[i] == max98090->lrclk)) {
1553 dev_dbg(codec->dev,
1554 "Found supported PCLK to LRCLK rates 0x%x\n",
1555 i + 0x8);
1556
1557 snd_soc_update_bits(codec, M98090_REG_CLOCK_MODE,
1558 M98090_FREQ_MASK,
1559 (i + 0x8) << M98090_FREQ_SHIFT);
1560 snd_soc_update_bits(codec, M98090_REG_CLOCK_MODE,
1561 M98090_USE_M1_MASK, 0);
1562 return;
1563 }
1564 }
1565
1566 /* Check for user calculated MI and NI ratios */
1567 for (i = 0; i < ARRAY_SIZE(user_pclk_rates); i++) {
1568 if ((user_pclk_rates[i] == max98090->sysclk) &&
1569 (user_lrclk_rates[i] == max98090->lrclk)) {
1570 dev_dbg(codec->dev,
1571 "Found user supported PCLK to LRCLK rates\n");
1572 dev_dbg(codec->dev, "i %d ni %lld mi %lld\n",
1573 i, ni_value[i], mi_value[i]);
1574
1575 snd_soc_update_bits(codec, M98090_REG_CLOCK_MODE,
1576 M98090_FREQ_MASK, 0);
1577 snd_soc_update_bits(codec, M98090_REG_CLOCK_MODE,
1578 M98090_USE_M1_MASK,
1579 1 << M98090_USE_M1_SHIFT);
1580
1581 snd_soc_write(codec, M98090_REG_CLOCK_RATIO_NI_MSB,
1582 (ni_value[i] >> 8) & 0x7F);
1583 snd_soc_write(codec, M98090_REG_CLOCK_RATIO_NI_LSB,
1584 ni_value[i] & 0xFF);
1585 snd_soc_write(codec, M98090_REG_CLOCK_RATIO_MI_MSB,
1586 (mi_value[i] >> 8) & 0x7F);
1587 snd_soc_write(codec, M98090_REG_CLOCK_RATIO_MI_LSB,
1588 mi_value[i] & 0xFF);
1589
1590 return;
1591 }
1592 }
1593
1594 /*
1595 * Calculate based on MI = 65536 (not as good as either method above)
1596 */
1597 snd_soc_update_bits(codec, M98090_REG_CLOCK_MODE,
1598 M98090_FREQ_MASK, 0);
1599 snd_soc_update_bits(codec, M98090_REG_CLOCK_MODE,
1600 M98090_USE_M1_MASK, 0);
1601
1602 /*
1603 * Configure NI when operating as master
1604 * Note: There is a small, but significant audio quality improvement
1605 * by calculating ni and mi.
1606 */
1607 ni = 65536ULL * (max98090->lrclk < 50000 ? 96ULL : 48ULL)
1608 * (unsigned long long int)max98090->lrclk;
1609 do_div(ni, (unsigned long long int)max98090->sysclk);
1610 dev_info(codec->dev, "No better method found\n");
1611 dev_info(codec->dev, "Calculating ni %lld with mi 65536\n", ni);
1612 snd_soc_write(codec, M98090_REG_CLOCK_RATIO_NI_MSB,
1613 (ni >> 8) & 0x7F);
1614 snd_soc_write(codec, M98090_REG_CLOCK_RATIO_NI_LSB, ni & 0xFF);
329} 1615}
330 1616
331static int max98090_dai_hw_params(struct snd_pcm_substream *substream, 1617static int max98090_dai_set_fmt(struct snd_soc_dai *codec_dai,
332 struct snd_pcm_hw_params *params, 1618 unsigned int fmt)
333 struct snd_soc_dai *dai)
334{ 1619{
335 struct snd_soc_codec *codec = dai->codec; 1620 struct snd_soc_codec *codec = codec_dai->codec;
336 unsigned int val; 1621 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
1622 struct max98090_cdata *cdata;
1623 u8 regval;
1624
1625 max98090->dai_fmt = fmt;
1626 cdata = &max98090->dai[0];
1627
1628 if (fmt != cdata->fmt) {
1629 cdata->fmt = fmt;
1630
1631 regval = 0;
1632 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1633 case SND_SOC_DAIFMT_CBS_CFS:
1634 /* Set to slave mode PLL - MAS mode off */
1635 snd_soc_write(codec,
1636 M98090_REG_CLOCK_RATIO_NI_MSB, 0x00);
1637 snd_soc_write(codec,
1638 M98090_REG_CLOCK_RATIO_NI_LSB, 0x00);
1639 snd_soc_update_bits(codec, M98090_REG_CLOCK_MODE,
1640 M98090_USE_M1_MASK, 0);
1641 break;
1642 case SND_SOC_DAIFMT_CBM_CFM:
1643 /* Set to master mode */
1644 if (max98090->tdm_slots == 4) {
1645 /* TDM */
1646 regval |= M98090_MAS_MASK |
1647 M98090_BSEL_64;
1648 } else if (max98090->tdm_slots == 3) {
1649 /* TDM */
1650 regval |= M98090_MAS_MASK |
1651 M98090_BSEL_48;
1652 } else {
1653 /* Few TDM slots, or No TDM */
1654 regval |= M98090_MAS_MASK |
1655 M98090_BSEL_32;
1656 }
1657 break;
1658 case SND_SOC_DAIFMT_CBS_CFM:
1659 case SND_SOC_DAIFMT_CBM_CFS:
1660 default:
1661 dev_err(codec->dev, "DAI clock mode unsupported");
1662 return -EINVAL;
1663 }
1664 snd_soc_write(codec, M98090_REG_MASTER_MODE, regval);
1665
1666 regval = 0;
1667 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1668 case SND_SOC_DAIFMT_I2S:
1669 regval |= M98090_DLY_MASK;
1670 break;
1671 case SND_SOC_DAIFMT_LEFT_J:
1672 break;
1673 case SND_SOC_DAIFMT_RIGHT_J:
1674 regval |= M98090_RJ_MASK;
1675 break;
1676 case SND_SOC_DAIFMT_DSP_A:
1677 /* Not supported mode */
1678 default:
1679 dev_err(codec->dev, "DAI format unsupported");
1680 return -EINVAL;
1681 }
1682
1683 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1684 case SND_SOC_DAIFMT_NB_NF:
1685 break;
1686 case SND_SOC_DAIFMT_NB_IF:
1687 regval |= M98090_WCI_MASK;
1688 break;
1689 case SND_SOC_DAIFMT_IB_NF:
1690 regval |= M98090_BCI_MASK;
1691 break;
1692 case SND_SOC_DAIFMT_IB_IF:
1693 regval |= M98090_BCI_MASK|M98090_WCI_MASK;
1694 break;
1695 default:
1696 dev_err(codec->dev, "DAI invert mode unsupported");
1697 return -EINVAL;
1698 }
1699
1700 /*
1701 * This accommodates an inverted logic in the MAX98090 chip
1702 * for Bit Clock Invert (BCI). The inverted logic is only
1703 * seen for the case of TDM mode. The remaining cases have
1704 * normal logic.
1705 */
1706 if (max98090->tdm_slots > 1) {
1707 regval ^= M98090_BCI_MASK;
1708 }
1709
1710 snd_soc_write(codec,
1711 M98090_REG_INTERFACE_FORMAT, regval);
1712 }
337 1713
338 switch (params_rate(params)) { 1714 return 0;
339 case 96000: 1715}
340 val = 1 << 5; 1716
341 break; 1717static int max98090_set_tdm_slot(struct snd_soc_dai *codec_dai,
342 case 32000: 1718 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
343 val = 1 << 4; 1719{
344 break; 1720 struct snd_soc_codec *codec = codec_dai->codec;
345 case 48000: 1721 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
346 val = 1 << 3; 1722 struct max98090_cdata *cdata;
1723 cdata = &max98090->dai[0];
1724
1725 if (slots < 0 || slots > 4)
1726 return -EINVAL;
1727
1728 max98090->tdm_slots = slots;
1729 max98090->tdm_width = slot_width;
1730
1731 if (max98090->tdm_slots > 1) {
1732 /* SLOTL SLOTR SLOTDLY */
1733 snd_soc_write(codec, M98090_REG_TDM_FORMAT,
1734 0 << M98090_TDM_SLOTL_SHIFT |
1735 1 << M98090_TDM_SLOTR_SHIFT |
1736 0 << M98090_TDM_SLOTDLY_SHIFT);
1737
1738 /* FSW TDM */
1739 snd_soc_update_bits(codec, M98090_REG_TDM_CONTROL,
1740 M98090_TDM_MASK,
1741 M98090_TDM_MASK);
1742 }
1743
1744 /*
1745 * Normally advisable to set TDM first, but this permits either order
1746 */
1747 cdata->fmt = 0;
1748 max98090_dai_set_fmt(codec_dai, max98090->dai_fmt);
1749
1750 return 0;
1751}
1752
1753static int max98090_set_bias_level(struct snd_soc_codec *codec,
1754 enum snd_soc_bias_level level)
1755{
1756 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
1757 int ret;
1758
1759 switch (level) {
1760 case SND_SOC_BIAS_ON:
1761 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1762 ret = regcache_sync(max98090->regmap);
1763
1764 if (ret != 0) {
1765 dev_err(codec->dev,
1766 "Failed to sync cache: %d\n", ret);
1767 return ret;
1768 }
1769 }
1770
1771 if (max98090->jack_state == M98090_JACK_STATE_HEADSET) {
1772 /*
1773 * Set to normal bias level.
1774 */
1775 snd_soc_update_bits(codec, M98090_REG_MIC_BIAS_VOLTAGE,
1776 M98090_MBVSEL_MASK, M98090_MBVSEL_2V8);
1777 }
347 break; 1778 break;
348 case 44100: 1779
349 val = 1 << 2; 1780 case SND_SOC_BIAS_PREPARE:
350 break; 1781 break;
351 case 16000: 1782
352 val = 1 << 1; 1783 case SND_SOC_BIAS_STANDBY:
1784 case SND_SOC_BIAS_OFF:
1785 /* Set internal pull-up to lowest power mode */
1786 snd_soc_update_bits(codec, M98090_REG_JACK_DETECT,
1787 M98090_JDWK_MASK, M98090_JDWK_MASK);
1788 regcache_mark_dirty(max98090->regmap);
353 break; 1789 break;
354 case 8000: 1790 }
355 val = 1 << 0; 1791 codec->dapm.bias_level = level;
1792 return 0;
1793}
1794
1795static const int comp_pclk_rates[] = {
1796 11289600, 12288000, 12000000, 13000000, 19200000
1797};
1798
1799static const int dmic_micclk[] = {
1800 2, 2, 2, 2, 4, 2
1801};
1802
1803static const int comp_lrclk_rates[] = {
1804 8000, 16000, 32000, 44100, 48000, 96000
1805};
1806
1807static const int dmic_comp[6][6] = {
1808 {7, 8, 3, 3, 3, 3},
1809 {7, 8, 3, 3, 3, 3},
1810 {7, 8, 3, 3, 3, 3},
1811 {7, 8, 3, 1, 1, 1},
1812 {7, 8, 3, 1, 2, 2},
1813 {7, 8, 3, 3, 3, 3}
1814};
1815
1816static int max98090_dai_hw_params(struct snd_pcm_substream *substream,
1817 struct snd_pcm_hw_params *params,
1818 struct snd_soc_dai *dai)
1819{
1820 struct snd_soc_codec *codec = dai->codec;
1821 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
1822 struct max98090_cdata *cdata;
1823 int i, j;
1824
1825 cdata = &max98090->dai[0];
1826 max98090->bclk = snd_soc_params_to_bclk(params);
1827 if (params_channels(params) == 1)
1828 max98090->bclk *= 2;
1829
1830 max98090->lrclk = params_rate(params);
1831
1832 switch (params_format(params)) {
1833 case SNDRV_PCM_FORMAT_S16_LE:
1834 snd_soc_update_bits(codec, M98090_REG_INTERFACE_FORMAT,
1835 M98090_WS_MASK, 0);
356 break; 1836 break;
357 default: 1837 default:
358 dev_err(codec->dev, "unsupported rate\n");
359 return -EINVAL; 1838 return -EINVAL;
360 } 1839 }
361 snd_soc_update_bits(codec, MAX98090_0x05_SAMPLE_RATE, 0x03F, val); 1840
1841 max98090_configure_bclk(codec);
1842
1843 cdata->rate = max98090->lrclk;
1844
1845 /* Update filter mode */
1846 if (max98090->lrclk < 24000)
1847 snd_soc_update_bits(codec, M98090_REG_FILTER_CONFIG,
1848 M98090_MODE_MASK, 0);
1849 else
1850 snd_soc_update_bits(codec, M98090_REG_FILTER_CONFIG,
1851 M98090_MODE_MASK, M98090_MODE_MASK);
1852
1853 /* Update sample rate mode */
1854 if (max98090->lrclk < 50000)
1855 snd_soc_update_bits(codec, M98090_REG_FILTER_CONFIG,
1856 M98090_DHF_MASK, 0);
1857 else
1858 snd_soc_update_bits(codec, M98090_REG_FILTER_CONFIG,
1859 M98090_DHF_MASK, M98090_DHF_MASK);
1860
1861 /* Check for supported PCLK to LRCLK ratios */
1862 for (j = 0; j < ARRAY_SIZE(comp_pclk_rates); j++) {
1863 if (comp_pclk_rates[j] == max98090->sysclk) {
1864 break;
1865 }
1866 }
1867
1868 for (i = 0; i < ARRAY_SIZE(comp_lrclk_rates) - 1; i++) {
1869 if (max98090->lrclk <= (comp_lrclk_rates[i] +
1870 comp_lrclk_rates[i + 1]) / 2) {
1871 break;
1872 }
1873 }
1874
1875 snd_soc_update_bits(codec, M98090_REG_DIGITAL_MIC_ENABLE,
1876 M98090_MICCLK_MASK,
1877 dmic_micclk[j] << M98090_MICCLK_SHIFT);
1878
1879 snd_soc_update_bits(codec, M98090_REG_DIGITAL_MIC_CONFIG,
1880 M98090_DMIC_COMP_MASK,
1881 dmic_comp[j][i] << M98090_DMIC_COMP_SHIFT);
362 1882
363 return 0; 1883 return 0;
364} 1884}
365 1885
1886/*
1887 * PLL / Sysclk
1888 */
366static int max98090_dai_set_sysclk(struct snd_soc_dai *dai, 1889static int max98090_dai_set_sysclk(struct snd_soc_dai *dai,
367 int clk_id, unsigned int freq, int dir) 1890 int clk_id, unsigned int freq, int dir)
368{ 1891{
369 struct snd_soc_codec *codec = dai->codec; 1892 struct snd_soc_codec *codec = dai->codec;
370 unsigned int val; 1893 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
371 1894
372 snd_soc_update_bits(codec, MAX98090_0x45_DEV_SHUTDOWN, 1895 /* Requested clock frequency is already setup */
373 MAX98090_SHDNRUN, 0); 1896 if (freq == max98090->sysclk)
374 1897 return 0;
375 switch (freq) { 1898
376 case 26000000: 1899 /* Setup clocks for slave mode, and using the PLL
377 val = 1 << 7; 1900 * PSCLK = 0x01 (when master clk is 10MHz to 20MHz)
378 break; 1901 * 0x02 (when master clk is 20MHz to 40MHz)..
379 case 19200000: 1902 * 0x03 (when master clk is 40MHz to 60MHz)..
380 val = 1 << 6; 1903 */
381 break; 1904 if ((freq >= 10000000) && (freq < 20000000)) {
382 case 13000000: 1905 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
383 val = 1 << 5; 1906 M98090_PSCLK_DIV1);
384 break; 1907 } else if ((freq >= 20000000) && (freq < 40000000)) {
385 case 12288000: 1908 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
386 val = 1 << 4; 1909 M98090_PSCLK_DIV2);
387 break; 1910 } else if ((freq >= 40000000) && (freq < 60000000)) {
388 case 12000000: 1911 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
389 val = 1 << 3; 1912 M98090_PSCLK_DIV4);
390 break; 1913 } else {
391 case 11289600:
392 val = 1 << 2;
393 break;
394 default:
395 dev_err(codec->dev, "Invalid master clock frequency\n"); 1914 dev_err(codec->dev, "Invalid master clock frequency\n");
396 return -EINVAL; 1915 return -EINVAL;
397 } 1916 }
398 snd_soc_update_bits(codec, MAX98090_0x04_SYS_CLK, 0xFD, val);
399 1917
400 snd_soc_update_bits(codec, MAX98090_0x45_DEV_SHUTDOWN, 1918 max98090->sysclk = freq;
401 MAX98090_SHDNRUN, MAX98090_SHDNRUN);
402 1919
403 dev_dbg(dai->dev, "sysclk is %uHz\n", freq); 1920 max98090_configure_bclk(codec);
404 1921
405 return 0; 1922 return 0;
406} 1923}
407 1924
408static int max98090_dai_set_fmt(struct snd_soc_dai *dai, 1925static int max98090_dai_digital_mute(struct snd_soc_dai *codec_dai, int mute)
409 unsigned int fmt)
410{ 1926{
411 struct snd_soc_codec *codec = dai->codec; 1927 struct snd_soc_codec *codec = codec_dai->codec;
412 int is_master; 1928 int regval;
413 u8 val;
414 1929
415 /* master/slave mode */ 1930 regval = mute ? M98090_DVM_MASK : 0;
416 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1931 snd_soc_update_bits(codec, M98090_REG_DAI_PLAYBACK_LEVEL,
417 case SND_SOC_DAIFMT_CBM_CFM: 1932 M98090_DVM_MASK, regval);
418 is_master = 1; 1933
419 break; 1934 return 0;
420 case SND_SOC_DAIFMT_CBS_CFS: 1935}
421 is_master = 0; 1936
422 break; 1937static void max98090_jack_work(struct work_struct *work)
423 default: 1938{
424 dev_err(codec->dev, "unsupported clock\n"); 1939 struct max98090_priv *max98090 = container_of(work,
425 return -EINVAL; 1940 struct max98090_priv,
1941 jack_work.work);
1942 struct snd_soc_codec *codec = max98090->codec;
1943 struct snd_soc_dapm_context *dapm = &codec->dapm;
1944 int status = 0;
1945 int reg;
1946
1947 /* Read a second time */
1948 if (max98090->jack_state == M98090_JACK_STATE_NO_HEADSET) {
1949
1950 /* Strong pull up allows mic detection */
1951 snd_soc_update_bits(codec, M98090_REG_JACK_DETECT,
1952 M98090_JDWK_MASK, 0);
1953
1954 msleep(50);
1955
1956 reg = snd_soc_read(codec, M98090_REG_JACK_STATUS);
1957
1958 /* Weak pull up allows only insertion detection */
1959 snd_soc_update_bits(codec, M98090_REG_JACK_DETECT,
1960 M98090_JDWK_MASK, M98090_JDWK_MASK);
1961 } else {
1962 reg = snd_soc_read(codec, M98090_REG_JACK_STATUS);
426 } 1963 }
427 1964
428 /* format */ 1965 reg = snd_soc_read(codec, M98090_REG_JACK_STATUS);
429 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1966
430 case SND_SOC_DAIFMT_I2S: 1967 switch (reg & (M98090_LSNS_MASK | M98090_JKSNS_MASK)) {
431 val = (is_master) ? MAX98090_I2S_M : MAX98090_I2S_S; 1968 case M98090_LSNS_MASK | M98090_JKSNS_MASK:
432 break; 1969 dev_dbg(codec->dev, "No Headset Detected\n");
433 case SND_SOC_DAIFMT_RIGHT_J: 1970
434 val = (is_master) ? MAX98090_RJ_M : MAX98090_RJ_S; 1971 max98090->jack_state = M98090_JACK_STATE_NO_HEADSET;
435 break; 1972
436 case SND_SOC_DAIFMT_LEFT_J: 1973 status |= 0;
437 val = (is_master) ? MAX98090_LJ_M : MAX98090_LJ_S; 1974
438 break; 1975 break;
439 default: 1976
440 dev_err(codec->dev, "unsupported format\n"); 1977 case 0:
441 return -EINVAL; 1978 if (max98090->jack_state ==
1979 M98090_JACK_STATE_HEADSET) {
1980
1981 dev_dbg(codec->dev,
1982 "Headset Button Down Detected\n");
1983
1984 /*
1985 * max98090_headset_button_event(codec)
1986 * could be defined, then called here.
1987 */
1988
1989 status |= SND_JACK_HEADSET;
1990 status |= SND_JACK_BTN_0;
1991
1992 break;
1993 }
1994
1995 /* Line is reported as Headphone */
1996 /* Nokia Headset is reported as Headphone */
1997 /* Mono Headphone is reported as Headphone */
1998 dev_dbg(codec->dev, "Headphone Detected\n");
1999
2000 max98090->jack_state = M98090_JACK_STATE_HEADPHONE;
2001
2002 status |= SND_JACK_HEADPHONE;
2003
2004 break;
2005
2006 case M98090_JKSNS_MASK:
2007 dev_dbg(codec->dev, "Headset Detected\n");
2008
2009 max98090->jack_state = M98090_JACK_STATE_HEADSET;
2010
2011 status |= SND_JACK_HEADSET;
2012
2013 break;
2014
2015 default:
2016 dev_dbg(codec->dev, "Unrecognized Jack Status\n");
2017 break;
2018 }
2019
2020 snd_soc_jack_report(max98090->jack, status,
2021 SND_JACK_HEADSET | SND_JACK_BTN_0);
2022
2023 snd_soc_dapm_sync(dapm);
2024}
2025
2026static irqreturn_t max98090_interrupt(int irq, void *data)
2027{
2028 struct snd_soc_codec *codec = data;
2029 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
2030 int ret;
2031 unsigned int mask;
2032 unsigned int active;
2033
2034 dev_dbg(codec->dev, "***** max98090_interrupt *****\n");
2035
2036 ret = regmap_read(max98090->regmap, M98090_REG_INTERRUPT_S, &mask);
2037
2038 if (ret != 0) {
2039 dev_err(codec->dev,
2040 "failed to read M98090_REG_INTERRUPT_S: %d\n",
2041 ret);
2042 return IRQ_NONE;
2043 }
2044
2045 ret = regmap_read(max98090->regmap, M98090_REG_DEVICE_STATUS, &active);
2046
2047 if (ret != 0) {
2048 dev_err(codec->dev,
2049 "failed to read M98090_REG_DEVICE_STATUS: %d\n",
2050 ret);
2051 return IRQ_NONE;
2052 }
2053
2054 dev_dbg(codec->dev, "active=0x%02x mask=0x%02x -> active=0x%02x\n",
2055 active, mask, active & mask);
2056
2057 active &= mask;
2058
2059 if (!active)
2060 return IRQ_NONE;
2061
2062 if (active & M98090_CLD_MASK) {
2063 dev_err(codec->dev, "M98090_CLD_MASK\n");
2064 }
2065
2066 if (active & M98090_SLD_MASK) {
2067 dev_dbg(codec->dev, "M98090_SLD_MASK\n");
442 } 2068 }
443 snd_soc_update_bits(codec, MAX98090_0x06_DAI_IF, 2069
444 MAX98090_DAI_IF_MASK, val); 2070 if (active & M98090_ULK_MASK) {
2071 dev_err(codec->dev, "M98090_ULK_MASK\n");
2072 }
2073
2074 if (active & M98090_JDET_MASK) {
2075 dev_dbg(codec->dev, "M98090_JDET_MASK\n");
2076
2077 pm_wakeup_event(codec->dev, 100);
2078
2079 schedule_delayed_work(&max98090->jack_work,
2080 msecs_to_jiffies(100));
2081 }
2082
2083 if (active & M98090_DRCACT_MASK) {
2084 dev_dbg(codec->dev, "M98090_DRCACT_MASK\n");
2085 }
2086
2087 if (active & M98090_DRCCLP_MASK) {
2088 dev_err(codec->dev, "M98090_DRCCLP_MASK\n");
2089 }
2090
2091 return IRQ_HANDLED;
2092}
2093
2094/**
2095 * max98090_mic_detect - Enable microphone detection via the MAX98090 IRQ
2096 *
2097 * @codec: MAX98090 codec
2098 * @jack: jack to report detection events on
2099 *
2100 * Enable microphone detection via IRQ on the MAX98090. If GPIOs are
2101 * being used to bring out signals to the processor then only platform
2102 * data configuration is needed for MAX98090 and processor GPIOs should
2103 * be configured using snd_soc_jack_add_gpios() instead.
2104 *
2105 * If no jack is supplied detection will be disabled.
2106 */
2107int max98090_mic_detect(struct snd_soc_codec *codec,
2108 struct snd_soc_jack *jack)
2109{
2110 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
2111
2112 dev_dbg(codec->dev, "max98090_mic_detect\n");
2113
2114 max98090->jack = jack;
2115 if (jack) {
2116 snd_soc_update_bits(codec, M98090_REG_INTERRUPT_S,
2117 M98090_IJDET_MASK,
2118 1 << M98090_IJDET_SHIFT);
2119 } else {
2120 snd_soc_update_bits(codec, M98090_REG_INTERRUPT_S,
2121 M98090_IJDET_MASK,
2122 0);
2123 }
2124
2125 /* Send an initial empty report */
2126 snd_soc_jack_report(max98090->jack, 0,
2127 SND_JACK_HEADSET | SND_JACK_BTN_0);
2128
2129 schedule_delayed_work(&max98090->jack_work,
2130 msecs_to_jiffies(100));
445 2131
446 return 0; 2132 return 0;
447} 2133}
2134EXPORT_SYMBOL_GPL(max98090_mic_detect);
448 2135
449#define MAX98090_RATES SNDRV_PCM_RATE_8000_96000 2136#define MAX98090_RATES SNDRV_PCM_RATE_8000_96000
450#define MAX98090_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE) 2137#define MAX98090_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
451 2138
452static struct snd_soc_dai_ops max98090_dai_ops = { 2139static struct snd_soc_dai_ops max98090_dai_ops = {
453 .set_sysclk = max98090_dai_set_sysclk, 2140 .set_sysclk = max98090_dai_set_sysclk,
454 .set_fmt = max98090_dai_set_fmt, 2141 .set_fmt = max98090_dai_set_fmt,
455 .hw_params = max98090_dai_hw_params, 2142 .set_tdm_slot = max98090_set_tdm_slot,
2143 .hw_params = max98090_dai_hw_params,
2144 .digital_mute = max98090_dai_digital_mute,
456}; 2145};
457 2146
458static struct snd_soc_dai_driver max98090_dai = { 2147static struct snd_soc_dai_driver max98090_dai[] = {
459 .name = "max98090-Hifi", 2148{
2149 .name = "HiFi",
460 .playback = { 2150 .playback = {
461 .stream_name = "Playback", 2151 .stream_name = "HiFi Playback",
462 .channels_min = 1, 2152 .channels_min = 2,
463 .channels_max = 2, 2153 .channels_max = 2,
464 .rates = MAX98090_RATES, 2154 .rates = MAX98090_RATES,
465 .formats = MAX98090_FORMATS, 2155 .formats = MAX98090_FORMATS,
2156 },
2157 .capture = {
2158 .stream_name = "HiFi Capture",
2159 .channels_min = 1,
2160 .channels_max = 2,
2161 .rates = MAX98090_RATES,
2162 .formats = MAX98090_FORMATS,
466 }, 2163 },
467 .ops = &max98090_dai_ops, 2164 .ops = &max98090_dai_ops,
2165}
468}; 2166};
469 2167
2168static void max98090_handle_pdata(struct snd_soc_codec *codec)
2169{
2170 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
2171 struct max98090_pdata *pdata = max98090->pdata;
2172
2173 if (!pdata) {
2174 dev_err(codec->dev, "No platform data\n");
2175 return;
2176 }
2177
2178}
2179
470static int max98090_probe(struct snd_soc_codec *codec) 2180static int max98090_probe(struct snd_soc_codec *codec)
471{ 2181{
472 struct max98090_priv *priv = snd_soc_codec_get_drvdata(codec); 2182 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
473 struct device *dev = codec->dev; 2183 struct max98090_cdata *cdata;
474 int ret; 2184 int ret = 0;
2185
2186 dev_dbg(codec->dev, "max98090_probe\n");
2187
2188 max98090->codec = codec;
2189
2190 codec->control_data = max98090->regmap;
475 2191
476 codec->control_data = priv->regmap;
477 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP); 2192 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
478 if (ret < 0) { 2193 if (ret != 0) {
479 dev_err(dev, "Failed to set cache I/O: %d\n", ret); 2194 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
480 return ret; 2195 return ret;
481 } 2196 }
482 2197
483 /* Device active */ 2198 /* Reset the codec, the DSP core, and disable all interrupts */
484 snd_soc_update_bits(codec, MAX98090_0x45_DEV_SHUTDOWN, 2199 max98090_reset(max98090);
485 MAX98090_SHDNRUN, MAX98090_SHDNRUN);
486 2200
487 return 0; 2201 /* Initialize private data */
2202
2203 max98090->sysclk = (unsigned)-1;
2204
2205 cdata = &max98090->dai[0];
2206 cdata->rate = (unsigned)-1;
2207 cdata->fmt = (unsigned)-1;
2208
2209 max98090->lin_state = 0;
2210 max98090->pa1en = 0;
2211 max98090->pa2en = 0;
2212 max98090->extmic_mux = 0;
2213
2214 ret = snd_soc_read(codec, M98090_REG_REVISION_ID);
2215 if (ret < 0) {
2216 dev_err(codec->dev, "Failed to read device revision: %d\n",
2217 ret);
2218 goto err_access;
2219 }
2220
2221 if ((ret >= M98090_REVA) && (ret <= M98090_REVA + 0x0f)) {
2222 max98090->devtype = MAX98090;
2223 dev_info(codec->dev, "MAX98090 REVID=0x%02x\n", ret);
2224 } else if ((ret >= M98091_REVA) && (ret <= M98091_REVA + 0x0f)) {
2225 max98090->devtype = MAX98091;
2226 dev_info(codec->dev, "MAX98091 REVID=0x%02x\n", ret);
2227 } else {
2228 max98090->devtype = MAX98090;
2229 dev_err(codec->dev, "Unrecognized revision 0x%02x\n", ret);
2230 }
2231
2232 max98090->jack_state = M98090_JACK_STATE_NO_HEADSET;
2233
2234 INIT_DELAYED_WORK(&max98090->jack_work, max98090_jack_work);
2235
2236 /* Enable jack detection */
2237 snd_soc_write(codec, M98090_REG_JACK_DETECT,
2238 M98090_JDETEN_MASK | M98090_JDEB_25MS);
2239
2240 /* Register for interrupts */
2241 dev_dbg(codec->dev, "irq = %d\n", max98090->irq);
2242
2243 ret = request_threaded_irq(max98090->irq, NULL,
2244 max98090_interrupt, IRQF_TRIGGER_FALLING,
2245 "max98090_interrupt", codec);
2246 if (ret < 0) {
2247 dev_err(codec->dev, "request_irq failed: %d\n",
2248 ret);
2249 }
2250
2251 /*
2252 * Clear any old interrupts.
2253 * An old interrupt ocurring prior to installing the ISR
2254 * can keep a new interrupt from generating a trigger.
2255 */
2256 snd_soc_read(codec, M98090_REG_DEVICE_STATUS);
2257
2258 /* High Performance is default */
2259 snd_soc_update_bits(codec, M98090_REG_DAC_CONTROL,
2260 M98090_DACHP_MASK,
2261 1 << M98090_DACHP_SHIFT);
2262 snd_soc_update_bits(codec, M98090_REG_DAC_CONTROL,
2263 M98090_PERFMODE_MASK,
2264 0 << M98090_PERFMODE_SHIFT);
2265 snd_soc_update_bits(codec, M98090_REG_ADC_CONTROL,
2266 M98090_ADCHP_MASK,
2267 1 << M98090_ADCHP_SHIFT);
2268
2269 /* Turn on VCM bandgap reference */
2270 snd_soc_write(codec, M98090_REG_BIAS_CONTROL,
2271 M98090_VCM_MODE_MASK);
2272
2273 max98090_handle_pdata(codec);
2274
2275 max98090_add_widgets(codec);
2276
2277err_access:
2278 return ret;
488} 2279}
489 2280
490static int max98090_remove(struct snd_soc_codec *codec) 2281static int max98090_remove(struct snd_soc_codec *codec)
491{ 2282{
2283 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
2284
2285 cancel_delayed_work_sync(&max98090->jack_work);
2286
492 return 0; 2287 return 0;
493} 2288}
494 2289
495static struct snd_soc_codec_driver soc_codec_dev_max98090 = { 2290static struct snd_soc_codec_driver soc_codec_dev_max98090 = {
496 .probe = max98090_probe, 2291 .probe = max98090_probe,
497 .remove = max98090_remove, 2292 .remove = max98090_remove,
498 .controls = max98090_snd_controls, 2293 .set_bias_level = max98090_set_bias_level,
499 .num_controls = ARRAY_SIZE(max98090_snd_controls),
500 .dapm_widgets = max98090_dapm_widgets,
501 .num_dapm_widgets = ARRAY_SIZE(max98090_dapm_widgets),
502 .dapm_routes = max98090_audio_map,
503 .num_dapm_routes = ARRAY_SIZE(max98090_audio_map),
504}; 2294};
505 2295
506static const struct regmap_config max98090_regmap = { 2296static const struct regmap_config max98090_regmap = {
507 .reg_bits = 8, 2297 .reg_bits = 8,
508 .val_bits = 8, 2298 .val_bits = 8,
509 .max_register = MAX98090_REG_END, 2299
510 .volatile_reg = max98090_volatile, 2300 .max_register = MAX98090_MAX_REGISTER,
511 .cache_type = REGCACHE_RBTREE, 2301 .reg_defaults = max98090_reg,
512 .reg_defaults = max98090_reg_defaults, 2302 .num_reg_defaults = ARRAY_SIZE(max98090_reg),
513 .num_reg_defaults = ARRAY_SIZE(max98090_reg_defaults), 2303 .volatile_reg = max98090_volatile_register,
2304 .readable_reg = max98090_readable_register,
2305 .cache_type = REGCACHE_RBTREE,
514}; 2306};
515 2307
516static int max98090_i2c_probe(struct i2c_client *i2c, 2308static int max98090_i2c_probe(struct i2c_client *i2c,
517 const struct i2c_device_id *id) 2309 const struct i2c_device_id *id)
518{ 2310{
519 struct max98090_priv *priv; 2311 struct max98090_priv *max98090;
520 struct device *dev = &i2c->dev;
521 unsigned int val;
522 int ret; 2312 int ret;
523 2313
524 priv = devm_kzalloc(dev, sizeof(struct max98090_priv), 2314 pr_debug("max98090_i2c_probe\n");
525 GFP_KERNEL);
526 if (!priv)
527 return -ENOMEM;
528
529 priv->regmap = devm_regmap_init_i2c(i2c, &max98090_regmap);
530 if (IS_ERR(priv->regmap)) {
531 ret = PTR_ERR(priv->regmap);
532 dev_err(dev, "Failed to init regmap: %d\n", ret);
533 return ret;
534 }
535 2315
536 i2c_set_clientdata(i2c, priv); 2316 max98090 = devm_kzalloc(&i2c->dev, sizeof(struct max98090_priv),
2317 GFP_KERNEL);
2318 if (max98090 == NULL)
2319 return -ENOMEM;
537 2320
538 ret = regmap_read(priv->regmap, MAX98090_0xFF_REV_ID, &val); 2321 max98090->devtype = id->driver_data;
539 if (ret < 0) { 2322 i2c_set_clientdata(i2c, max98090);
540 dev_err(dev, "Failed to read device revision: %d\n", ret); 2323 max98090->control_data = i2c;
541 return ret; 2324 max98090->pdata = i2c->dev.platform_data;
2325 max98090->irq = i2c->irq;
2326
2327 max98090->regmap = regmap_init_i2c(i2c, &max98090_regmap);
2328 if (IS_ERR(max98090->regmap)) {
2329 ret = PTR_ERR(max98090->regmap);
2330 dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret);
2331 goto err_enable;
542 } 2332 }
543 dev_info(dev, "revision 0x%02x\n", val);
544 2333
545 ret = snd_soc_register_codec(dev, 2334 ret = snd_soc_register_codec(&i2c->dev,
546 &soc_codec_dev_max98090, 2335 &soc_codec_dev_max98090, max98090_dai,
547 &max98090_dai, 1); 2336 ARRAY_SIZE(max98090_dai));
2337 if (ret < 0)
2338 regmap_exit(max98090->regmap);
548 2339
2340err_enable:
549 return ret; 2341 return ret;
550} 2342}
551 2343
552static int max98090_i2c_remove(struct i2c_client *client) 2344static int max98090_i2c_remove(struct i2c_client *client)
553{ 2345{
2346 struct max98090_priv *max98090 = dev_get_drvdata(&client->dev);
554 snd_soc_unregister_codec(&client->dev); 2347 snd_soc_unregister_codec(&client->dev);
2348 regmap_exit(max98090->regmap);
2349 return 0;
2350}
2351
2352static int max98090_runtime_resume(struct device *dev)
2353{
2354 struct max98090_priv *max98090 = dev_get_drvdata(dev);
2355
2356 regcache_cache_only(max98090->regmap, false);
2357
2358 regcache_sync(max98090->regmap);
2359
555 return 0; 2360 return 0;
556} 2361}
557 2362
2363static int max98090_runtime_suspend(struct device *dev)
2364{
2365 struct max98090_priv *max98090 = dev_get_drvdata(dev);
2366
2367 regcache_cache_only(max98090->regmap, true);
2368
2369 return 0;
2370}
2371
2372static struct dev_pm_ops max98090_pm = {
2373 SET_RUNTIME_PM_OPS(max98090_runtime_suspend,
2374 max98090_runtime_resume, NULL)
2375};
2376
558static const struct i2c_device_id max98090_i2c_id[] = { 2377static const struct i2c_device_id max98090_i2c_id[] = {
559 { "max98090", 0 }, 2378 { "max98090", MAX98090 },
560 { } 2379 { }
561}; 2380};
562MODULE_DEVICE_TABLE(i2c, max98090_i2c_id); 2381MODULE_DEVICE_TABLE(i2c, max98090_i2c_id);
@@ -565,13 +2384,15 @@ static struct i2c_driver max98090_i2c_driver = {
565 .driver = { 2384 .driver = {
566 .name = "max98090", 2385 .name = "max98090",
567 .owner = THIS_MODULE, 2386 .owner = THIS_MODULE,
2387 .pm = &max98090_pm,
568 }, 2388 },
569 .probe = max98090_i2c_probe, 2389 .probe = max98090_i2c_probe,
570 .remove = max98090_i2c_remove, 2390 .remove = max98090_i2c_remove,
571 .id_table = max98090_i2c_id, 2391 .id_table = max98090_i2c_id,
572}; 2392};
2393
573module_i2c_driver(max98090_i2c_driver); 2394module_i2c_driver(max98090_i2c_driver);
574 2395
575MODULE_DESCRIPTION("ALSA SoC MAX98090 driver"); 2396MODULE_DESCRIPTION("ALSA SoC MAX98090 driver");
576MODULE_AUTHOR("Peter Hsiang, Kuninori Morimoto"); 2397MODULE_AUTHOR("Peter Hsiang, Jesse Marroqin, Jerry Wong");
577MODULE_LICENSE("GPL"); 2398MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/max98090.h b/sound/soc/codecs/max98090.h
new file mode 100755
index 000000000000..7e103f249053
--- /dev/null
+++ b/sound/soc/codecs/max98090.h
@@ -0,0 +1,1549 @@
1/*
2 * max98090.h -- MAX98090 ALSA SoC Audio driver
3 *
4 * Copyright 2011-2012 Maxim Integrated Products
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef _MAX98090_H
12#define _MAX98090_H
13
14#include <linux/version.h>
15
16/* One can override the Linux version here with an explicit version number */
17#define M98090_LINUX_VERSION LINUX_VERSION_CODE
18
19/*
20 * MAX98090 Register Definitions
21 */
22
23#define M98090_REG_SOFTWARE_RESET 0x00
24#define M98090_REG_DEVICE_STATUS 0x01
25#define M98090_REG_JACK_STATUS 0x02
26#define M98090_REG_INTERRUPT_S 0x03
27#define M98090_REG_QUICK_SYSTEM_CLOCK 0x04
28#define M98090_REG_QUICK_SAMPLE_RATE 0x05
29#define M98090_REG_DAI_INTERFACE 0x06
30#define M98090_REG_DAC_PATH 0x07
31#define M98090_REG_MIC_DIRECT_TO_ADC 0x08
32#define M98090_REG_LINE_TO_ADC 0x09
33#define M98090_REG_ANALOG_MIC_LOOP 0x0A
34#define M98090_REG_ANALOG_LINE_LOOP 0x0B
35#define M98090_REG_RESERVED 0x0C
36#define M98090_REG_LINE_INPUT_CONFIG 0x0D
37#define M98090_REG_LINE_INPUT_LEVEL 0x0E
38#define M98090_REG_INPUT_MODE 0x0F
39#define M98090_REG_MIC1_INPUT_LEVEL 0x10
40#define M98090_REG_MIC2_INPUT_LEVEL 0x11
41#define M98090_REG_MIC_BIAS_VOLTAGE 0x12
42#define M98090_REG_DIGITAL_MIC_ENABLE 0x13
43#define M98090_REG_DIGITAL_MIC_CONFIG 0x14
44#define M98090_REG_LEFT_ADC_MIXER 0x15
45#define M98090_REG_RIGHT_ADC_MIXER 0x16
46#define M98090_REG_LEFT_ADC_LEVEL 0x17
47#define M98090_REG_RIGHT_ADC_LEVEL 0x18
48#define M98090_REG_ADC_BIQUAD_LEVEL 0x19
49#define M98090_REG_ADC_SIDETONE 0x1A
50#define M98090_REG_SYSTEM_CLOCK 0x1B
51#define M98090_REG_CLOCK_MODE 0x1C
52#define M98090_REG_CLOCK_RATIO_NI_MSB 0x1D
53#define M98090_REG_CLOCK_RATIO_NI_LSB 0x1E
54#define M98090_REG_CLOCK_RATIO_MI_MSB 0x1F
55#define M98090_REG_CLOCK_RATIO_MI_LSB 0x20
56#define M98090_REG_MASTER_MODE 0x21
57#define M98090_REG_INTERFACE_FORMAT 0x22
58#define M98090_REG_TDM_CONTROL 0x23
59#define M98090_REG_TDM_FORMAT 0x24
60#define M98090_REG_IO_CONFIGURATION 0x25
61#define M98090_REG_FILTER_CONFIG 0x26
62#define M98090_REG_DAI_PLAYBACK_LEVEL 0x27
63#define M98090_REG_DAI_PLAYBACK_LEVEL_EQ 0x28
64#define M98090_REG_LEFT_HP_MIXER 0x29
65#define M98090_REG_RIGHT_HP_MIXER 0x2A
66#define M98090_REG_HP_CONTROL 0x2B
67#define M98090_REG_LEFT_HP_VOLUME 0x2C
68#define M98090_REG_RIGHT_HP_VOLUME 0x2D
69#define M98090_REG_LEFT_SPK_MIXER 0x2E
70#define M98090_REG_RIGHT_SPK_MIXER 0x2F
71#define M98090_REG_SPK_CONTROL 0x30
72#define M98090_REG_LEFT_SPK_VOLUME 0x31
73#define M98090_REG_RIGHT_SPK_VOLUME 0x32
74#define M98090_REG_DRC_TIMING 0x33
75#define M98090_REG_DRC_COMPRESSOR 0x34
76#define M98090_REG_DRC_EXPANDER 0x35
77#define M98090_REG_DRC_GAIN 0x36
78#define M98090_REG_RCV_LOUTL_MIXER 0x37
79#define M98090_REG_RCV_LOUTL_CONTROL 0x38
80#define M98090_REG_RCV_LOUTL_VOLUME 0x39
81#define M98090_REG_LOUTR_MIXER 0x3A
82#define M98090_REG_LOUTR_CONTROL 0x3B
83#define M98090_REG_LOUTR_VOLUME 0x3C
84#define M98090_REG_JACK_DETECT 0x3D
85#define M98090_REG_INPUT_ENABLE 0x3E
86#define M98090_REG_OUTPUT_ENABLE 0x3F
87#define M98090_REG_LEVEL_CONTROL 0x40
88#define M98090_REG_DSP_FILTER_ENABLE 0x41
89#define M98090_REG_BIAS_CONTROL 0x42
90#define M98090_REG_DAC_CONTROL 0x43
91#define M98090_REG_ADC_CONTROL 0x44
92#define M98090_REG_DEVICE_SHUTDOWN 0x45
93#define M98090_REG_EQUALIZER_BASE 0x46
94#define M98090_REG_RECORD_BIQUAD_BASE 0xAF
95#define M98090_REG_DMIC3_VOLUME 0xBE
96#define M98090_REG_DMIC4_VOLUME 0xBF
97#define M98090_REG_DMIC34_BQ_PREATTEN 0xC0
98#define M98090_REG_RECORD_TDM_SLOT 0xC1
99#define M98090_REG_SAMPLE_RATE 0xC2
100#define M98090_REG_DMIC34_BIQUAD_BASE 0xC3
101#define M98090_REG_REVISION_ID 0xFF
102
103#define M98090_REG_CNT (0xFF+1)
104#define MAX98090_MAX_REGISTER 0xFF
105
106/* MAX98090 Register Bit Fields */
107
108/*
109 * M98090_REG_SOFTWARE_RESET
110 */
111#define M98090_SWRESET_MASK (1<<7)
112#define M98090_SWRESET_SHIFT 7
113#define M98090_SWRESET_WIDTH 1
114
115/*
116 * M98090_REG_DEVICE_STATUS
117 */
118#define M98090_CLD_MASK (1<<7)
119#define M98090_CLD_SHIFT 7
120#define M98090_CLD_WIDTH 1
121#define M98090_SLD_MASK (1<<6)
122#define M98090_SLD_SHIFT 6
123#define M98090_SLD_WIDTH 1
124#define M98090_ULK_MASK (1<<5)
125#define M98090_ULK_SHIFT 5
126#define M98090_ULK_WIDTH 1
127#define M98090_JDET_MASK (1<<2)
128#define M98090_JDET_SHIFT 2
129#define M98090_JDET_WIDTH 1
130#define M98090_DRCACT_MASK (1<<1)
131#define M98090_DRCACT_SHIFT 1
132#define M98090_DRCACT_WIDTH 1
133#define M98090_DRCCLP_MASK (1<<0)
134#define M98090_DRCCLP_SHIFT 0
135#define M98090_DRCCLP_WIDTH 1
136
137/*
138 * M98090_REG_JACK_STATUS
139 */
140#define M98090_LSNS_MASK (1<<2)
141#define M98090_LSNS_SHIFT 2
142#define M98090_LSNS_WIDTH 1
143#define M98090_JKSNS_MASK (1<<1)
144#define M98090_JKSNS_SHIFT 1
145#define M98090_JKSNS_WIDTH 1
146
147/*
148 * M98090_REG_INTERRUPT_S
149 */
150#define M98090_ICLD_MASK (1<<7)
151#define M98090_ICLD_SHIFT 7
152#define M98090_ICLD_WIDTH 1
153#define M98090_ISLD_MASK (1<<6)
154#define M98090_ISLD_SHIFT 6
155#define M98090_ISLD_WIDTH 1
156#define M98090_IULK_MASK (1<<5)
157#define M98090_IULK_SHIFT 5
158#define M98090_IULK_WIDTH 1
159#define M98090_IJDET_MASK (1<<2)
160#define M98090_IJDET_SHIFT 2
161#define M98090_IJDET_WIDTH 1
162#define M98090_IDRCACT_MASK (1<<1)
163#define M98090_IDRCACT_SHIFT 1
164#define M98090_IDRCACT_WIDTH 1
165#define M98090_IDRCCLP_MASK (1<<0)
166#define M98090_IDRCCLP_SHIFT 0
167#define M98090_IDRCCLP_WIDTH 1
168
169/*
170 * M98090_REG_QUICK_SYSTEM_CLOCK
171 */
172#define M98090_26M_MASK (1<<7)
173#define M98090_26M_SHIFT 7
174#define M98090_26M_WIDTH 1
175#define M98090_19P2M_MASK (1<<6)
176#define M98090_19P2M_SHIFT 6
177#define M98090_19P2M_WIDTH 1
178#define M98090_13M_MASK (1<<5)
179#define M98090_13M_SHIFT 5
180#define M98090_13M_WIDTH 1
181#define M98090_12P288M_MASK (1<<4)
182#define M98090_12P288M_SHIFT 4
183#define M98090_12P288M_WIDTH 1
184#define M98090_12M_MASK (1<<3)
185#define M98090_12M_SHIFT 3
186#define M98090_12M_WIDTH 1
187#define M98090_11P2896M_MASK (1<<2)
188#define M98090_11P2896M_SHIFT 2
189#define M98090_11P2896M_WIDTH 1
190#define M98090_256FS_MASK (1<<0)
191#define M98090_256FS_SHIFT 0
192#define M98090_256FS_WIDTH 1
193#define M98090_CLK_ALL_SHIFT 0
194#define M98090_CLK_ALL_WIDTH 8
195#define M98090_CLK_ALL_NUM (1<<M98090_CLK_ALL_WIDTH)
196
197/*
198 * M98090_REG_QUICK_SAMPLE_RATE
199 */
200#define M98090_SR_96K_MASK (1<<5)
201#define M98090_SR_96K_SHIFT 5
202#define M98090_SR_96K_WIDTH 1
203#define M98090_SR_32K_MASK (1<<4)
204#define M98090_SR_32K_SHIFT 4
205#define M98090_SR_32K_WIDTH 1
206#define M98090_SR_48K_MASK (1<<3)
207#define M98090_SR_48K_SHIFT 3
208#define M98090_SR_48K_WIDTH 1
209#define M98090_SR_44K1_MASK (1<<2)
210#define M98090_SR_44K1_SHIFT 2
211#define M98090_SR_44K1_WIDTH 1
212#define M98090_SR_16K_MASK (1<<1)
213#define M98090_SR_16K_SHIFT 1
214#define M98090_SR_16K_WIDTH 1
215#define M98090_SR_8K_MASK (1<<0)
216#define M98090_SR_8K_SHIFT 0
217#define M98090_SR_8K_WIDTH 1
218#define M98090_SR_MASK 0x3F
219#define M98090_SR_ALL_SHIFT 0
220#define M98090_SR_ALL_WIDTH 8
221#define M98090_SR_ALL_NUM (1<<M98090_SR_ALL_WIDTH)
222
223/*
224 * M98090_REG_DAI_INTERFACE
225 */
226#define M98090_RJ_M_MASK (1<<5)
227#define M98090_RJ_M_SHIFT 5
228#define M98090_RJ_M_WIDTH 1
229#define M98090_RJ_S_MASK (1<<4)
230#define M98090_RJ_S_SHIFT 4
231#define M98090_RJ_S_WIDTH 1
232#define M98090_LJ_M_MASK (1<<3)
233#define M98090_LJ_M_SHIFT 3
234#define M98090_LJ_M_WIDTH 1
235#define M98090_LJ_S_MASK (1<<2)
236#define M98090_LJ_S_SHIFT 2
237#define M98090_LJ_S_WIDTH 1
238#define M98090_I2S_M_MASK (1<<1)
239#define M98090_I2S_M_SHIFT 1
240#define M98090_I2S_M_WIDTH 1
241#define M98090_I2S_S_MASK (1<<0)
242#define M98090_I2S_S_SHIFT 0
243#define M98090_I2S_S_WIDTH 1
244#define M98090_DAI_ALL_SHIFT 0
245#define M98090_DAI_ALL_WIDTH 8
246#define M98090_DAI_ALL_NUM (1<<M98090_DAI_ALL_WIDTH)
247
248/*
249 * M98090_REG_DAC_PATH
250 */
251#define M98090_DIG2_HP_MASK (1<<7)
252#define M98090_DIG2_HP_SHIFT 7
253#define M98090_DIG2_HP_WIDTH 1
254#define M98090_DIG2_EAR_MASK (1<<6)
255#define M98090_DIG2_EAR_SHIFT 6
256#define M98090_DIG2_EAR_WIDTH 1
257#define M98090_DIG2_SPK_MASK (1<<5)
258#define M98090_DIG2_SPK_SHIFT 5
259#define M98090_DIG2_SPK_WIDTH 1
260#define M98090_DIG2_LOUT_MASK (1<<4)
261#define M98090_DIG2_LOUT_SHIFT 4
262#define M98090_DIG2_LOUT_WIDTH 1
263#define M98090_DIG2_ALL_SHIFT 0
264#define M98090_DIG2_ALL_WIDTH 8
265#define M98090_DIG2_ALL_NUM (1<<M98090_DIG2_ALL_WIDTH)
266
267/*
268 * M98090_REG_MIC_DIRECT_TO_ADC
269 */
270#define M98090_IN12_MIC1_MASK (1<<7)
271#define M98090_IN12_MIC1_SHIFT 7
272#define M98090_IN12_MIC1_WIDTH 1
273#define M98090_IN34_MIC2_MASK (1<<6)
274#define M98090_IN34_MIC2_SHIFT 6
275#define M98090_IN34_MIC2_WIDTH 1
276#define M98090_IN56_MIC1_MASK (1<<5)
277#define M98090_IN56_MIC1_SHIFT 5
278#define M98090_IN56_MIC1_WIDTH 1
279#define M98090_IN56_MIC2_MASK (1<<4)
280#define M98090_IN56_MIC2_SHIFT 4
281#define M98090_IN56_MIC2_WIDTH 1
282#define M98090_IN12_DADC_MASK (1<<3)
283#define M98090_IN12_DADC_SHIFT 3
284#define M98090_IN12_DADC_WIDTH 1
285#define M98090_IN34_DADC_MASK (1<<2)
286#define M98090_IN34_DADC_SHIFT 2
287#define M98090_IN34_DADC_WIDTH 1
288#define M98090_IN56_DADC_MASK (1<<1)
289#define M98090_IN56_DADC_SHIFT 1
290#define M98090_IN56_DADC_WIDTH 1
291#define M98090_MIC_ALL_SHIFT 0
292#define M98090_MIC_ALL_WIDTH 8
293#define M98090_MIC_ALL_NUM (1<<M98090_MIC_ALL_WIDTH)
294
295/*
296 * M98090_REG_LINE_TO_ADC
297 */
298#define M98090_IN12S_AB_MASK (1<<7)
299#define M98090_IN12S_AB_SHIFT 7
300#define M98090_IN12S_AB_WIDTH 1
301#define M98090_IN34S_AB_MASK (1<<6)
302#define M98090_IN34S_AB_SHIFT 6
303#define M98090_IN34S_AB_WIDTH 1
304#define M98090_IN56S_AB_MASK (1<<5)
305#define M98090_IN56S_AB_SHIFT 5
306#define M98090_IN56S_AB_WIDTH 1
307#define M98090_IN34D_A_MASK (1<<4)
308#define M98090_IN34D_A_SHIFT 4
309#define M98090_IN34D_A_WIDTH 1
310#define M98090_IN56D_B_MASK (1<<3)
311#define M98090_IN56D_B_SHIFT 3
312#define M98090_IN56D_B_WIDTH 1
313#define M98090_LINE_ALL_SHIFT 0
314#define M98090_LINE_ALL_WIDTH 8
315#define M98090_LINE_ALL_NUM (1<<M98090_LINE_ALL_WIDTH)
316
317/*
318 * M98090_REG_ANALOG_MIC_LOOP
319 */
320#define M98090_IN12_M1HPL_MASK (1<<7)
321#define M98090_IN12_M1HPL_SHIFT 7
322#define M98090_IN12_M1HPL_WIDTH 1
323#define M98090_IN12_M1SPKL_MASK (1<<6)
324#define M98090_IN12_M1SPKL_SHIFT 6
325#define M98090_IN12_M1SPKL_WIDTH 1
326#define M98090_IN12_M1EAR_MASK (1<<5)
327#define M98090_IN12_M1EAR_SHIFT 5
328#define M98090_IN12_M1EAR_WIDTH 1
329#define M98090_IN12_M1LOUTL_MASK (1<<4)
330#define M98090_IN12_M1LOUTL_SHIFT 4
331#define M98090_IN12_M1LOUTL_WIDTH 1
332#define M98090_IN34_M2HPR_MASK (1<<3)
333#define M98090_IN34_M2HPR_SHIFT 3
334#define M98090_IN34_M2HPR_WIDTH 1
335#define M98090_IN34_M2SPKR_MASK (1<<2)
336#define M98090_IN34_M2SPKR_SHIFT 2
337#define M98090_IN34_M2SPKR_WIDTH 1
338#define M98090_IN34_M2EAR_MASK (1<<1)
339#define M98090_IN34_M2EAR_SHIFT 1
340#define M98090_IN34_M2EAR_WIDTH 1
341#define M98090_IN34_M2LOUTR_MASK (1<<0)
342#define M98090_IN34_M2LOUTR_SHIFT 0
343#define M98090_IN34_M2LOUTR_WIDTH 1
344#define M98090_AMIC_ALL_SHIFT 0
345#define M98090_AMIC_ALL_WIDTH 8
346#define M98090_AMIC_ALL_NUM (1<<M98090_AMIC_ALL_WIDTH)
347
348/*
349 * M98090_REG_ANALOG_LINE_LOOP
350 */
351#define M98090_IN12S_ABHP_MASK (1<<7)
352#define M98090_IN12S_ABHP_SHIFT 7
353#define M98090_IN12S_ABHP_WIDTH 1
354#define M98090_IN34D_ASPKL_MASK (1<<6)
355#define M98090_IN34D_ASPKL_SHIFT 6
356#define M98090_IN34D_ASPKL_WIDTH 1
357#define M98090_IN34D_AEAR_MASK (1<<5)
358#define M98090_IN34D_AEAR_SHIFT 5
359#define M98090_IN34D_AEAR_WIDTH 1
360#define M98090_IN12S_ABLOUT_MASK (1<<4)
361#define M98090_IN12S_ABLOUT_SHIFT 4
362#define M98090_IN12S_ABLOUT_WIDTH 1
363#define M98090_IN34S_ABHP_MASK (1<<3)
364#define M98090_IN34S_ABHP_SHIFT 3
365#define M98090_IN34S_ABHP_WIDTH 1
366#define M98090_IN56D_BSPKR_MASK (1<<2)
367#define M98090_IN56D_BSPKR_SHIFT 2
368#define M98090_IN56D_BSPKR_WIDTH 1
369#define M98090_IN56D_BEAR_MASK (1<<1)
370#define M98090_IN56D_BEAR_SHIFT 1
371#define M98090_IN56D_BEAR_WIDTH 1
372#define M98090_IN34S_ABLOUT_MASK (1<<0)
373#define M98090_IN34S_ABLOUT_SHIFT 0
374#define M98090_IN34S_ABLOUT_WIDTH 1
375#define M98090_ALIN_ALL_SHIFT 0
376#define M98090_ALIN_ALL_WIDTH 8
377#define M98090_ALIN_ALL_NUM (1<<M98090_ALIN_ALL_WIDTH)
378
379/*
380 * M98090_REG_RESERVED
381 */
382
383/*
384 * M98090_REG_LINE_INPUT_CONFIG
385 */
386#define M98090_IN34DIFF_MASK (1<<7)
387#define M98090_IN34DIFF_SHIFT 7
388#define M98090_IN34DIFF_WIDTH 1
389#define M98090_IN56DIFF_MASK (1<<6)
390#define M98090_IN56DIFF_SHIFT 6
391#define M98090_IN56DIFF_WIDTH 1
392#define M98090_IN1SEEN_MASK (1<<5)
393#define M98090_IN1SEEN_SHIFT 5
394#define M98090_IN1SEEN_WIDTH 1
395#define M98090_IN2SEEN_MASK (1<<4)
396#define M98090_IN2SEEN_SHIFT 4
397#define M98090_IN2SEEN_WIDTH 1
398#define M98090_IN3SEEN_MASK (1<<3)
399#define M98090_IN3SEEN_SHIFT 3
400#define M98090_IN3SEEN_WIDTH 1
401#define M98090_IN4SEEN_MASK (1<<2)
402#define M98090_IN4SEEN_SHIFT 2
403#define M98090_IN4SEEN_WIDTH 1
404#define M98090_IN5SEEN_MASK (1<<1)
405#define M98090_IN5SEEN_SHIFT 1
406#define M98090_IN5SEEN_WIDTH 1
407#define M98090_IN6SEEN_MASK (1<<0)
408#define M98090_IN6SEEN_SHIFT 0
409#define M98090_IN6SEEN_WIDTH 1
410
411/*
412 * M98090_REG_LINE_INPUT_LEVEL
413 */
414#define M98090_MIXG135_MASK (1<<7)
415#define M98090_MIXG135_SHIFT 7
416#define M98090_MIXG135_WIDTH 1
417#define M98090_MIXG135_NUM (1<<M98090_MIXG135_WIDTH)
418#define M98090_MIXG246_MASK (1<<6)
419#define M98090_MIXG246_SHIFT 6
420#define M98090_MIXG246_WIDTH 1
421#define M98090_MIXG246_NUM (1<<M98090_MIXG246_WIDTH)
422#define M98090_LINAPGA_MASK (7<<3)
423#define M98090_LINAPGA_SHIFT 3
424#define M98090_LINAPGA_WIDTH 3
425#define M98090_LINAPGA_NUM 6
426#define M98090_LINBPGA_MASK (7<<0)
427#define M98090_LINBPGA_SHIFT 0
428#define M98090_LINBPGA_WIDTH 3
429#define M98090_LINBPGA_NUM 6
430
431/*
432 * M98090_REG_INPUT_MODE
433 */
434#define M98090_EXTBUFA_MASK (1<<7)
435#define M98090_EXTBUFA_SHIFT 7
436#define M98090_EXTBUFA_WIDTH 1
437#define M98090_EXTBUFA_NUM (1<<M98090_EXTBUFA_WIDTH)
438#define M98090_EXTBUFB_MASK (1<<6)
439#define M98090_EXTBUFB_SHIFT 6
440#define M98090_EXTBUFB_WIDTH 1
441#define M98090_EXTBUFB_NUM (1<<M98090_EXTBUFB_WIDTH)
442#define M98090_EXTMIC_MASK (3<<0)
443#define M98090_EXTMIC_SHIFT 0
444#define M98090_EXTMIC1_SHIFT 0
445#define M98090_EXTMIC2_SHIFT 1
446#define M98090_EXTMIC_WIDTH 2
447#define M98090_EXTMIC_NONE (0<<0)
448#define M98090_EXTMIC_MIC1 (1<<0)
449#define M98090_EXTMIC_MIC2 (2<<0)
450
451/*
452 * M98090_REG_MIC1_INPUT_LEVEL
453 */
454#define M98090_MIC_PA1EN_MASK (3<<5)
455#define M98090_MIC_PA1EN_SHIFT 5
456#define M98090_MIC_PA1EN_WIDTH 2
457#define M98090_MIC_PA1EN_NUM 3
458#define M98090_MIC_PGAM1_MASK (31<<0)
459#define M98090_MIC_PGAM1_SHIFT 0
460#define M98090_MIC_PGAM1_WIDTH 5
461#define M98090_MIC_PGAM1_NUM 21
462
463/*
464 * M98090_REG_MIC2_INPUT_LEVEL
465 */
466#define M98090_MIC_PA2EN_MASK (3<<5)
467#define M98090_MIC_PA2EN_SHIFT 5
468#define M98090_MIC_PA2EN_WIDTH 2
469#define M98090_MIC_PA2EN_NUM 3
470#define M98090_MIC_PGAM2_MASK (31<<0)
471#define M98090_MIC_PGAM2_SHIFT 0
472#define M98090_MIC_PGAM2_WIDTH 5
473#define M98090_MIC_PGAM2_NUM 21
474
475/*
476 * M98090_REG_MIC_BIAS_VOLTAGE
477 */
478#define M98090_MBVSEL_MASK (3<<0)
479#define M98090_MBVSEL_SHIFT 0
480#define M98090_MBVSEL_WIDTH 2
481#define M98090_MBVSEL_2V8 (3<<0)
482#define M98090_MBVSEL_2V55 (2<<0)
483#define M98090_MBVSEL_2V4 (1<<0)
484#define M98090_MBVSEL_2V2 (0<<0)
485
486/*
487 * M98090_REG_DIGITAL_MIC_ENABLE
488 */
489#define M98090_MICCLK_MASK (7<<4)
490#define M98090_MICCLK_SHIFT 4
491#define M98090_MICCLK_WIDTH 3
492#define M98090_DIGMIC4_MASK (1<<3)
493#define M98090_DIGMIC4_SHIFT 3
494#define M98090_DIGMIC4_WIDTH 1
495#define M98090_DIGMIC4_NUM (1<<M98090_DIGMIC4_WIDTH)
496#define M98090_DIGMIC3_MASK (1<<2)
497#define M98090_DIGMIC3_SHIFT 2
498#define M98090_DIGMIC3_WIDTH 1
499#define M98090_DIGMIC3_NUM (1<<M98090_DIGMIC3_WIDTH)
500#define M98090_DIGMICR_MASK (1<<1)
501#define M98090_DIGMICR_SHIFT 1
502#define M98090_DIGMICR_WIDTH 1
503#define M98090_DIGMICR_NUM (1<<M98090_DIGMICR_WIDTH)
504#define M98090_DIGMICL_MASK (1<<0)
505#define M98090_DIGMICL_SHIFT 0
506#define M98090_DIGMICL_WIDTH 1
507#define M98090_DIGMICL_NUM (1<<M98090_DIGMICL_WIDTH)
508
509/*
510 * M98090_REG_DIGITAL_MIC_CONFIG
511 */
512#define M98090_DMIC_COMP_MASK (15<<4)
513#define M98090_DMIC_COMP_SHIFT 4
514#define M98090_DMIC_COMP_WIDTH 4
515#define M98090_DMIC_COMP_NUM (1<<M98090_DMIC_COMP_WIDTH)
516#define M98090_DMIC_FREQ_MASK (3<<0)
517#define M98090_DMIC_FREQ_SHIFT 0
518#define M98090_DMIC_FREQ_WIDTH 2
519
520/*
521 * M98090_REG_LEFT_ADC_MIXER
522 */
523#define M98090_MIXADL_MIC2_MASK (1<<6)
524#define M98090_MIXADL_MIC2_SHIFT 6
525#define M98090_MIXADL_MIC2_WIDTH 1
526#define M98090_MIXADL_MIC1_MASK (1<<5)
527#define M98090_MIXADL_MIC1_SHIFT 5
528#define M98090_MIXADL_MIC1_WIDTH 1
529#define M98090_MIXADL_LINEB_MASK (1<<4)
530#define M98090_MIXADL_LINEB_SHIFT 4
531#define M98090_MIXADL_LINEB_WIDTH 1
532#define M98090_MIXADL_LINEA_MASK (1<<3)
533#define M98090_MIXADL_LINEA_SHIFT 3
534#define M98090_MIXADL_LINEA_WIDTH 1
535#define M98090_MIXADL_IN65DIFF_MASK (1<<2)
536#define M98090_MIXADL_IN65DIFF_SHIFT 2
537#define M98090_MIXADL_IN65DIFF_WIDTH 1
538#define M98090_MIXADL_IN34DIFF_MASK (1<<1)
539#define M98090_MIXADL_IN34DIFF_SHIFT 1
540#define M98090_MIXADL_IN34DIFF_WIDTH 1
541#define M98090_MIXADL_IN12DIFF_MASK (1<<0)
542#define M98090_MIXADL_IN12DIFF_SHIFT 0
543#define M98090_MIXADL_IN12DIFF_WIDTH 1
544#define M98090_MIXADL_MASK (255<<0)
545#define M98090_MIXADL_SHIFT 0
546#define M98090_MIXADL_WIDTH 8
547
548/*
549 * M98090_REG_RIGHT_ADC_MIXER
550 */
551#define M98090_MIXADR_MIC2_MASK (1<<6)
552#define M98090_MIXADR_MIC2_SHIFT 6
553#define M98090_MIXADR_MIC2_WIDTH 1
554#define M98090_MIXADR_MIC1_MASK (1<<5)
555#define M98090_MIXADR_MIC1_SHIFT 5
556#define M98090_MIXADR_MIC1_WIDTH 1
557#define M98090_MIXADR_LINEB_MASK (1<<4)
558#define M98090_MIXADR_LINEB_SHIFT 4
559#define M98090_MIXADR_LINEB_WIDTH 1
560#define M98090_MIXADR_LINEA_MASK (1<<3)
561#define M98090_MIXADR_LINEA_SHIFT 3
562#define M98090_MIXADR_LINEA_WIDTH 1
563#define M98090_MIXADR_IN65DIFF_MASK (1<<2)
564#define M98090_MIXADR_IN65DIFF_SHIFT 2
565#define M98090_MIXADR_IN65DIFF_WIDTH 1
566#define M98090_MIXADR_IN34DIFF_MASK (1<<1)
567#define M98090_MIXADR_IN34DIFF_SHIFT 1
568#define M98090_MIXADR_IN34DIFF_WIDTH 1
569#define M98090_MIXADR_IN12DIFF_MASK (1<<0)
570#define M98090_MIXADR_IN12DIFF_SHIFT 0
571#define M98090_MIXADR_IN12DIFF_WIDTH 1
572#define M98090_MIXADR_MASK (255<<0)
573#define M98090_MIXADR_SHIFT 0
574#define M98090_MIXADR_WIDTH 8
575
576/*
577 * M98090_REG_LEFT_ADC_LEVEL
578 */
579#define M98090_AVLG_MASK (7<<4)
580#define M98090_AVLG_SHIFT 4
581#define M98090_AVLG_WIDTH 3
582#define M98090_AVLG_NUM (1<<M98090_AVLG_WIDTH)
583#define M98090_AVL_MASK (15<<0)
584#define M98090_AVL_SHIFT 0
585#define M98090_AVL_WIDTH 4
586#define M98090_AVL_NUM (1<<M98090_AVL_WIDTH)
587
588/*
589 * M98090_REG_RIGHT_ADC_LEVEL
590 */
591#define M98090_AVRG_MASK (7<<4)
592#define M98090_AVRG_SHIFT 4
593#define M98090_AVRG_WIDTH 3
594#define M98090_AVRG_NUM (1<<M98090_AVRG_WIDTH)
595#define M98090_AVR_MASK (15<<0)
596#define M98090_AVR_SHIFT 0
597#define M98090_AVR_WIDTH 4
598#define M98090_AVR_NUM (1<<M98090_AVR_WIDTH)
599
600/*
601 * M98090_REG_ADC_BIQUAD_LEVEL
602 */
603#define M98090_AVBQ_MASK (15<<0)
604#define M98090_AVBQ_SHIFT 0
605#define M98090_AVBQ_WIDTH 4
606#define M98090_AVBQ_NUM (1<<M98090_AVBQ_WIDTH)
607
608/*
609 * M98090_REG_ADC_SIDETONE
610 */
611#define M98090_DSTSR_MASK (1<<7)
612#define M98090_DSTSR_SHIFT 7
613#define M98090_DSTSR_WIDTH 1
614#define M98090_DSTSL_MASK (1<<6)
615#define M98090_DSTSL_SHIFT 6
616#define M98090_DSTSL_WIDTH 1
617#define M98090_DVST_MASK (31<<0)
618#define M98090_DVST_SHIFT 0
619#define M98090_DVST_WIDTH 5
620#define M98090_DVST_NUM 31
621
622/*
623 * M98090_REG_SYSTEM_CLOCK
624 */
625#define M98090_PSCLK_MASK (3<<4)
626#define M98090_PSCLK_SHIFT 4
627#define M98090_PSCLK_WIDTH 2
628#define M98090_PSCLK_DISABLED (0<<4)
629#define M98090_PSCLK_DIV1 (1<<4)
630#define M98090_PSCLK_DIV2 (2<<4)
631#define M98090_PSCLK_DIV4 (3<<4)
632
633/*
634 * M98090_REG_CLOCK_MODE
635 */
636#define M98090_FREQ_MASK (15<<4)
637#define M98090_FREQ_SHIFT 4
638#define M98090_FREQ_WIDTH 4
639#define M98090_USE_M1_MASK (1<<0)
640#define M98090_USE_M1_SHIFT 0
641#define M98090_USE_M1_WIDTH 1
642#define M98090_USE_M1_NUM (1<<M98090_USE_M1_WIDTH)
643
644/*
645 * M98090_REG_CLOCK_RATIO_NI_MSB
646 */
647#define M98090_NI_HI_MASK (127<<0)
648#define M98090_NI_HI_SHIFT 0
649#define M98090_NI_HI_WIDTH 7
650#define M98090_NI_HI_NUM (1<<M98090_NI_HI_WIDTH)
651
652/*
653 * M98090_REG_CLOCK_RATIO_NI_LSB
654 */
655#define M98090_NI_LO_MASK (255<<0)
656#define M98090_NI_LO_SHIFT 0
657#define M98090_NI_LO_WIDTH 8
658#define M98090_NI_LO_NUM (1<<M98090_NI_LO_WIDTH)
659
660/*
661 * M98090_REG_CLOCK_RATIO_MI_MSB
662 */
663#define M98090_MI_HI_MASK (255<<0)
664#define M98090_MI_HI_SHIFT 0
665#define M98090_MI_HI_WIDTH 8
666#define M98090_MI_HI_NUM (1<<M98090_MI_HI_WIDTH)
667
668/*
669 * M98090_REG_CLOCK_RATIO_MI_LSB
670 */
671#define M98090_MI_LO_MASK (255<<0)
672#define M98090_MI_LO_SHIFT 0
673#define M98090_MI_LO_WIDTH 8
674#define M98090_MI_LO_NUM (1<<M98090_MI_LO_WIDTH)
675
676/*
677 * M98090_REG_MASTER_MODE
678 */
679#define M98090_MAS_MASK (1<<7)
680#define M98090_MAS_SHIFT 7
681#define M98090_MAS_WIDTH 1
682#define M98090_BSEL_MASK (1<<0)
683#define M98090_BSEL_SHIFT 0
684#define M98090_BSEL_WIDTH 1
685#define M98090_BSEL_32 (1<<0)
686#define M98090_BSEL_48 (2<<0)
687#define M98090_BSEL_64 (3<<0)
688
689/*
690 * M98090_REG_INTERFACE_FORMAT
691 */
692#define M98090_RJ_MASK (1<<5)
693#define M98090_RJ_SHIFT 5
694#define M98090_RJ_WIDTH 1
695#define M98090_WCI_MASK (1<<4)
696#define M98090_WCI_SHIFT 4
697#define M98090_WCI_WIDTH 1
698#define M98090_BCI_MASK (1<<3)
699#define M98090_BCI_SHIFT 3
700#define M98090_BCI_WIDTH 1
701#define M98090_DLY_MASK (1<<2)
702#define M98090_DLY_SHIFT 2
703#define M98090_DLY_WIDTH 1
704#define M98090_WS_MASK (3<<0)
705#define M98090_WS_SHIFT 0
706#define M98090_WS_WIDTH 2
707#define M98090_WS_NUM (1<<M98090_WS_WIDTH)
708
709/*
710 * M98090_REG_TDM_CONTROL
711 */
712#define M98090_FSW_MASK (1<<1)
713#define M98090_FSW_SHIFT 1
714#define M98090_FSW_WIDTH 1
715#define M98090_TDM_MASK (1<<0)
716#define M98090_TDM_SHIFT 0
717#define M98090_TDM_WIDTH 1
718#define M98090_TDM_NUM (1<<M98090_TDM_WIDTH)
719
720/*
721 * M98090_REG_TDM_FORMAT
722 */
723#define M98090_TDM_SLOTL_MASK (3<<6)
724#define M98090_TDM_SLOTL_SHIFT 6
725#define M98090_TDM_SLOTL_WIDTH 2
726#define M98090_TDM_SLOTL_NUM (1<<M98090_TDM_SLOTL_WIDTH)
727#define M98090_TDM_SLOTR_MASK (3<<4)
728#define M98090_TDM_SLOTR_SHIFT 4
729#define M98090_TDM_SLOTR_WIDTH 2
730#define M98090_TDM_SLOTR_NUM (1<<M98090_TDM_SLOTR_WIDTH)
731#define M98090_TDM_SLOTDLY_MASK (15<<0)
732#define M98090_TDM_SLOTDLY_SHIFT 0
733#define M98090_TDM_SLOTDLY_WIDTH 4
734#define M98090_TDM_SLOTDLY_NUM (1<<M98090_TDM_SLOTDLY_WIDTH)
735
736/*
737 * M98090_REG_IO_CONFIGURATION
738 */
739#define M98090_LTEN_MASK (1<<5)
740#define M98090_LTEN_SHIFT 5
741#define M98090_LTEN_WIDTH 1
742#define M98090_LTEN_NUM (1<<M98090_LTEN_WIDTH)
743#define M98090_LBEN_MASK (1<<4)
744#define M98090_LBEN_SHIFT 4
745#define M98090_LBEN_WIDTH 1
746#define M98090_LBEN_NUM (1<<M98090_LBEN_WIDTH)
747#define M98090_DMONO_MASK (1<<3)
748#define M98090_DMONO_SHIFT 3
749#define M98090_DMONO_WIDTH 1
750#define M98090_DMONO_NUM (1<<M98090_DMONO_WIDTH)
751#define M98090_HIZOFF_MASK (1<<2)
752#define M98090_HIZOFF_SHIFT 2
753#define M98090_HIZOFF_WIDTH 1
754#define M98090_HIZOFF_NUM (1<<M98090_HIZOFF_WIDTH)
755#define M98090_SDOEN_MASK (1<<1)
756#define M98090_SDOEN_SHIFT 1
757#define M98090_SDOEN_WIDTH 1
758#define M98090_SDOEN_NUM (1<<M98090_SDOEN_WIDTH)
759#define M98090_SDIEN_MASK (1<<0)
760#define M98090_SDIEN_SHIFT 0
761#define M98090_SDIEN_WIDTH 1
762#define M98090_SDIEN_NUM (1<<M98090_SDIEN_WIDTH)
763
764/*
765 * M98090_REG_FILTER_CONFIG
766 */
767#define M98090_MODE_MASK (1<<7)
768#define M98090_MODE_SHIFT 7
769#define M98090_MODE_WIDTH 1
770#define M98090_AHPF_MASK (1<<6)
771#define M98090_AHPF_SHIFT 6
772#define M98090_AHPF_WIDTH 1
773#define M98090_AHPF_NUM (1<<M98090_AHPF_WIDTH)
774#define M98090_DHPF_MASK (1<<5)
775#define M98090_DHPF_SHIFT 5
776#define M98090_DHPF_WIDTH 1
777#define M98090_DHPF_NUM (1<<M98090_DHPF_WIDTH)
778#define M98090_DHF_MASK (1<<4)
779#define M98090_DHF_SHIFT 4
780#define M98090_DHF_WIDTH 1
781#define M98090_FLT_DMIC34MODE_MASK (1<<3)
782#define M98090_FLT_DMIC34MODE_SHIFT 3
783#define M98090_FLT_DMIC34MODE_WIDTH 1
784#define M98090_FLT_DMIC34HPF_MASK (1<<2)
785#define M98090_FLT_DMIC34HPF_SHIFT 2
786#define M98090_FLT_DMIC34HPF_WIDTH 1
787#define M98090_FLT_DMIC34HPF_NUM (1<<M98090_FLT_DMIC34HPF_WIDTH)
788
789/*
790 * M98090_REG_DAI_PLAYBACK_LEVEL
791 */
792#define M98090_DVM_MASK (1<<7)
793#define M98090_DVM_SHIFT 7
794#define M98090_DVM_WIDTH 1
795#define M98090_DVG_MASK (3<<4)
796#define M98090_DVG_SHIFT 4
797#define M98090_DVG_WIDTH 2
798#define M98090_DVG_NUM (1<<M98090_DVG_WIDTH)
799#define M98090_DV_MASK (15<<0)
800#define M98090_DV_SHIFT 0
801#define M98090_DV_WIDTH 4
802#define M98090_DV_NUM (1<<M98090_DV_WIDTH)
803
804/*
805 * M98090_REG_DAI_PLAYBACK_LEVEL_EQ
806 */
807#define M98090_EQCLPN_MASK (1<<4)
808#define M98090_EQCLPN_SHIFT 4
809#define M98090_EQCLPN_WIDTH 1
810#define M98090_EQCLPN_NUM (1<<M98090_EQCLPN_WIDTH)
811#define M98090_DVEQ_MASK (15<<0)
812#define M98090_DVEQ_SHIFT 0
813#define M98090_DVEQ_WIDTH 4
814#define M98090_DVEQ_NUM (1<<M98090_DVEQ_WIDTH)
815
816/*
817 * M98090_REG_LEFT_HP_MIXER
818 */
819#define M98090_MIXHPL_MIC2_MASK (1<<5)
820#define M98090_MIXHPL_MIC2_SHIFT 5
821#define M98090_MIXHPL_MIC2_WIDTH 1
822#define M98090_MIXHPL_MIC1_MASK (1<<4)
823#define M98090_MIXHPL_MIC1_SHIFT 4
824#define M98090_MIXHPL_MIC1_WIDTH 1
825#define M98090_MIXHPL_LINEB_MASK (1<<3)
826#define M98090_MIXHPL_LINEB_SHIFT 3
827#define M98090_MIXHPL_LINEB_WIDTH 1
828#define M98090_MIXHPL_LINEA_MASK (1<<2)
829#define M98090_MIXHPL_LINEA_SHIFT 2
830#define M98090_MIXHPL_LINEA_WIDTH 1
831#define M98090_MIXHPL_DACR_MASK (1<<1)
832#define M98090_MIXHPL_DACR_SHIFT 1
833#define M98090_MIXHPL_DACR_WIDTH 1
834#define M98090_MIXHPL_DACL_MASK (1<<0)
835#define M98090_MIXHPL_DACL_SHIFT 0
836#define M98090_MIXHPL_DACL_WIDTH 1
837#define M98090_MIXHPL_MASK (63<<0)
838#define M98090_MIXHPL_SHIFT 0
839#define M98090_MIXHPL_WIDTH 6
840
841/*
842 * M98090_REG_RIGHT_HP_MIXER
843 */
844#define M98090_MIXHPR_MIC2_MASK (1<<5)
845#define M98090_MIXHPR_MIC2_SHIFT 5
846#define M98090_MIXHPR_MIC2_WIDTH 1
847#define M98090_MIXHPR_MIC1_MASK (1<<4)
848#define M98090_MIXHPR_MIC1_SHIFT 4
849#define M98090_MIXHPR_MIC1_WIDTH 1
850#define M98090_MIXHPR_LINEB_MASK (1<<3)
851#define M98090_MIXHPR_LINEB_SHIFT 3
852#define M98090_MIXHPR_LINEB_WIDTH 1
853#define M98090_MIXHPR_LINEA_MASK (1<<2)
854#define M98090_MIXHPR_LINEA_SHIFT 2
855#define M98090_MIXHPR_LINEA_WIDTH 1
856#define M98090_MIXHPR_DACR_MASK (1<<1)
857#define M98090_MIXHPR_DACR_SHIFT 1
858#define M98090_MIXHPR_DACR_WIDTH 1
859#define M98090_MIXHPR_DACL_MASK (1<<0)
860#define M98090_MIXHPR_DACL_SHIFT 0
861#define M98090_MIXHPR_DACL_WIDTH 1
862#define M98090_MIXHPR_MASK (63<<0)
863#define M98090_MIXHPR_SHIFT 0
864#define M98090_MIXHPR_WIDTH 6
865
866/*
867 * M98090_REG_HP_CONTROL
868 */
869#define M98090_MIXHPRSEL_MASK (1<<5)
870#define M98090_MIXHPRSEL_SHIFT 5
871#define M98090_MIXHPRSEL_WIDTH 1
872#define M98090_MIXHPLSEL_MASK (1<<4)
873#define M98090_MIXHPLSEL_SHIFT 4
874#define M98090_MIXHPLSEL_WIDTH 1
875#define M98090_MIXHPRG_MASK (3<<2)
876#define M98090_MIXHPRG_SHIFT 2
877#define M98090_MIXHPRG_WIDTH 2
878#define M98090_MIXHPRG_NUM (1<<M98090_MIXHPRG_WIDTH)
879#define M98090_MIXHPLG_MASK (3<<0)
880#define M98090_MIXHPLG_SHIFT 0
881#define M98090_MIXHPLG_WIDTH 2
882#define M98090_MIXHPLG_NUM (1<<M98090_MIXHPLG_WIDTH)
883
884/*
885 * M98090_REG_LEFT_HP_VOLUME
886 */
887#define M98090_HPLM_MASK (1<<7)
888#define M98090_HPLM_SHIFT 7
889#define M98090_HPLM_WIDTH 1
890#define M98090_HPVOLL_MASK (31<<0)
891#define M98090_HPVOLL_SHIFT 0
892#define M98090_HPVOLL_WIDTH 5
893#define M98090_HPVOLL_NUM (1<<M98090_HPVOLL_WIDTH)
894
895/*
896 * M98090_REG_RIGHT_HP_VOLUME
897 */
898#define M98090_HPRM_MASK (1<<7)
899#define M98090_HPRM_SHIFT 7
900#define M98090_HPRM_WIDTH 1
901#define M98090_HPVOLR_MASK (31<<0)
902#define M98090_HPVOLR_SHIFT 0
903#define M98090_HPVOLR_WIDTH 5
904#define M98090_HPVOLR_NUM (1<<M98090_HPVOLR_WIDTH)
905
906/*
907 * M98090_REG_LEFT_SPK_MIXER
908 */
909#define M98090_MIXSPL_MIC2_MASK (1<<5)
910#define M98090_MIXSPL_MIC2_SHIFT 5
911#define M98090_MIXSPL_MIC2_WIDTH 1
912#define M98090_MIXSPL_MIC1_MASK (1<<4)
913#define M98090_MIXSPL_MIC1_SHIFT 4
914#define M98090_MIXSPL_MIC1_WIDTH 1
915#define M98090_MIXSPL_LINEB_MASK (1<<3)
916#define M98090_MIXSPL_LINEB_SHIFT 3
917#define M98090_MIXSPL_LINEB_WIDTH 1
918#define M98090_MIXSPL_LINEA_MASK (1<<2)
919#define M98090_MIXSPL_LINEA_SHIFT 2
920#define M98090_MIXSPL_LINEA_WIDTH 1
921#define M98090_MIXSPL_DACR_MASK (1<<1)
922#define M98090_MIXSPL_DACR_SHIFT 1
923#define M98090_MIXSPL_DACR_WIDTH 1
924#define M98090_MIXSPL_DACL_MASK (1<<0)
925#define M98090_MIXSPL_DACL_SHIFT 0
926#define M98090_MIXSPL_DACL_WIDTH 1
927#define M98090_MIXSPL_MASK (63<<0)
928#define M98090_MIXSPL_SHIFT 0
929#define M98090_MIXSPL_WIDTH 6
930#define M98090_MIXSPR_DACR_MASK (1<<1)
931#define M98090_MIXSPR_DACR_SHIFT 1
932#define M98090_MIXSPR_DACR_WIDTH 1
933
934
935/*
936 * M98090_REG_RIGHT_SPK_MIXER
937 */
938#define M98090_SPK_SLAVE_MASK (1<<6)
939#define M98090_SPK_SLAVE_SHIFT 6
940#define M98090_SPK_SLAVE_WIDTH 1
941#define M98090_MIXSPR_MIC2_MASK (1<<5)
942#define M98090_MIXSPR_MIC2_SHIFT 5
943#define M98090_MIXSPR_MIC2_WIDTH 1
944#define M98090_MIXSPR_MIC1_MASK (1<<4)
945#define M98090_MIXSPR_MIC1_SHIFT 4
946#define M98090_MIXSPR_MIC1_WIDTH 1
947#define M98090_MIXSPR_LINEB_MASK (1<<3)
948#define M98090_MIXSPR_LINEB_SHIFT 3
949#define M98090_MIXSPR_LINEB_WIDTH 1
950#define M98090_MIXSPR_LINEA_MASK (1<<2)
951#define M98090_MIXSPR_LINEA_SHIFT 2
952#define M98090_MIXSPR_LINEA_WIDTH 1
953#define M98090_MIXSPR_DACR_MASK (1<<1)
954#define M98090_MIXSPR_DACR_SHIFT 1
955#define M98090_MIXSPR_DACR_WIDTH 1
956#define M98090_MIXSPR_DACL_MASK (1<<0)
957#define M98090_MIXSPR_DACL_SHIFT 0
958#define M98090_MIXSPR_DACL_WIDTH 1
959#define M98090_MIXSPR_MASK (63<<0)
960#define M98090_MIXSPR_SHIFT 0
961#define M98090_MIXSPR_WIDTH 6
962
963/*
964 * M98090_REG_SPK_CONTROL
965 */
966#define M98090_MIXSPRG_MASK (3<<2)
967#define M98090_MIXSPRG_SHIFT 2
968#define M98090_MIXSPRG_WIDTH 2
969#define M98090_MIXSPRG_NUM (1<<M98090_MIXSPRG_WIDTH)
970#define M98090_MIXSPLG_MASK (3<<0)
971#define M98090_MIXSPLG_SHIFT 0
972#define M98090_MIXSPLG_WIDTH 2
973#define M98090_MIXSPLG_NUM (1<<M98090_MIXSPLG_WIDTH)
974
975/*
976 * M98090_REG_LEFT_SPK_VOLUME
977 */
978#define M98090_SPLM_MASK (1<<7)
979#define M98090_SPLM_SHIFT 7
980#define M98090_SPLM_WIDTH 1
981#define M98090_SPVOLL_MASK (63<<0)
982#define M98090_SPVOLL_SHIFT 0
983#define M98090_SPVOLL_WIDTH 6
984#define M98090_SPVOLL_NUM 40
985
986/*
987 * M98090_REG_RIGHT_SPK_VOLUME
988 */
989#define M98090_SPRM_MASK (1<<7)
990#define M98090_SPRM_SHIFT 7
991#define M98090_SPRM_WIDTH 1
992#define M98090_SPVOLR_MASK (63<<0)
993#define M98090_SPVOLR_SHIFT 0
994#define M98090_SPVOLR_WIDTH 6
995#define M98090_SPVOLR_NUM 40
996
997/*
998 * M98090_REG_DRC_TIMING
999 */
1000#define M98090_DRCEN_MASK (1<<7)
1001#define M98090_DRCEN_SHIFT 7
1002#define M98090_DRCEN_WIDTH 1
1003#define M98090_DRCEN_NUM (1<<M98090_DRCEN_WIDTH)
1004#define M98090_DRCRLS_MASK (7<<4)
1005#define M98090_DRCRLS_SHIFT 4
1006#define M98090_DRCRLS_WIDTH 3
1007#define M98090_DRCATK_MASK (7<<0)
1008#define M98090_DRCATK_SHIFT 0
1009#define M98090_DRCATK_WIDTH 3
1010
1011/*
1012 * M98090_REG_DRC_COMPRESSOR
1013 */
1014#define M98090_DRCCMP_MASK (7<<5)
1015#define M98090_DRCCMP_SHIFT 5
1016#define M98090_DRCCMP_WIDTH 3
1017#define M98090_DRCTHC_MASK (31<<0)
1018#define M98090_DRCTHC_SHIFT 0
1019#define M98090_DRCTHC_WIDTH 5
1020#define M98090_DRCTHC_NUM (1<<M98090_DRCTHC_WIDTH)
1021
1022/*
1023 * M98090_REG_DRC_EXPANDER
1024 */
1025#define M98090_DRCEXP_MASK (7<<5)
1026#define M98090_DRCEXP_SHIFT 5
1027#define M98090_DRCEXP_WIDTH 3
1028#define M98090_DRCTHE_MASK (31<<0)
1029#define M98090_DRCTHE_SHIFT 0
1030#define M98090_DRCTHE_WIDTH 5
1031#define M98090_DRCTHE_NUM (1<<M98090_DRCTHE_WIDTH)
1032
1033/*
1034 * M98090_REG_DRC_GAIN
1035 */
1036#define M98090_DRCG_MASK (31<<0)
1037#define M98090_DRCG_SHIFT 0
1038#define M98090_DRCG_WIDTH 5
1039#define M98090_DRCG_NUM 13
1040
1041/*
1042 * M98090_REG_RCV_LOUTL_MIXER
1043 */
1044#define M98090_MIXRCVL_MIC2_MASK (1<<5)
1045#define M98090_MIXRCVL_MIC2_SHIFT 5
1046#define M98090_MIXRCVL_MIC2_WIDTH 1
1047#define M98090_MIXRCVL_MIC1_MASK (1<<4)
1048#define M98090_MIXRCVL_MIC1_SHIFT 4
1049#define M98090_MIXRCVL_MIC1_WIDTH 1
1050#define M98090_MIXRCVL_LINEB_MASK (1<<3)
1051#define M98090_MIXRCVL_LINEB_SHIFT 3
1052#define M98090_MIXRCVL_LINEB_WIDTH 1
1053#define M98090_MIXRCVL_LINEA_MASK (1<<2)
1054#define M98090_MIXRCVL_LINEA_SHIFT 2
1055#define M98090_MIXRCVL_LINEA_WIDTH 1
1056#define M98090_MIXRCVL_DACR_MASK (1<<1)
1057#define M98090_MIXRCVL_DACR_SHIFT 1
1058#define M98090_MIXRCVL_DACR_WIDTH 1
1059#define M98090_MIXRCVL_DACL_MASK (1<<0)
1060#define M98090_MIXRCVL_DACL_SHIFT 0
1061#define M98090_MIXRCVL_DACL_WIDTH 1
1062#define M98090_MIXRCVL_MASK (63<<0)
1063#define M98090_MIXRCVL_SHIFT 0
1064#define M98090_MIXRCVL_WIDTH 6
1065
1066/*
1067 * M98090_REG_RCV_LOUTL_CONTROL
1068 */
1069#define M98090_MIXRCVLG_MASK (3<<0)
1070#define M98090_MIXRCVLG_SHIFT 0
1071#define M98090_MIXRCVLG_WIDTH 2
1072#define M98090_MIXRCVLG_NUM (1<<M98090_MIXRCVLG_WIDTH)
1073
1074/*
1075 * M98090_REG_RCV_LOUTL_VOLUME
1076 */
1077#define M98090_RCVLM_MASK (1<<7)
1078#define M98090_RCVLM_SHIFT 7
1079#define M98090_RCVLM_WIDTH 1
1080#define M98090_RCVLVOL_MASK (31<<0)
1081#define M98090_RCVLVOL_SHIFT 0
1082#define M98090_RCVLVOL_WIDTH 5
1083#define M98090_RCVLVOL_NUM (1<<M98090_RCVLVOL_WIDTH)
1084
1085/*
1086 * M98090_REG_LOUTR_MIXER
1087 */
1088#define M98090_LINMOD_MASK (1<<7)
1089#define M98090_LINMOD_SHIFT 7
1090#define M98090_LINMOD_WIDTH 1
1091#define M98090_MIXRCVR_MIC2_MASK (1<<5)
1092#define M98090_MIXRCVR_MIC2_SHIFT 5
1093#define M98090_MIXRCVR_MIC2_WIDTH 1
1094#define M98090_MIXRCVR_MIC1_MASK (1<<4)
1095#define M98090_MIXRCVR_MIC1_SHIFT 4
1096#define M98090_MIXRCVR_MIC1_WIDTH 1
1097#define M98090_MIXRCVR_LINEB_MASK (1<<3)
1098#define M98090_MIXRCVR_LINEB_SHIFT 3
1099#define M98090_MIXRCVR_LINEB_WIDTH 1
1100#define M98090_MIXRCVR_LINEA_MASK (1<<2)
1101#define M98090_MIXRCVR_LINEA_SHIFT 2
1102#define M98090_MIXRCVR_LINEA_WIDTH 1
1103#define M98090_MIXRCVR_DACR_MASK (1<<1)
1104#define M98090_MIXRCVR_DACR_SHIFT 1
1105#define M98090_MIXRCVR_DACR_WIDTH 1
1106#define M98090_MIXRCVR_DACL_MASK (1<<0)
1107#define M98090_MIXRCVR_DACL_SHIFT 0
1108#define M98090_MIXRCVR_DACL_WIDTH 1
1109#define M98090_MIXRCVR_MASK (63<<0)
1110#define M98090_MIXRCVR_SHIFT 0
1111#define M98090_MIXRCVR_WIDTH 6
1112
1113/*
1114 * M98090_REG_LOUTR_CONTROL
1115 */
1116#define M98090_MIXRCVRG_MASK (3<<0)
1117#define M98090_MIXRCVRG_SHIFT 0
1118#define M98090_MIXRCVRG_WIDTH 2
1119#define M98090_MIXRCVRG_NUM (1<<M98090_MIXRCVRG_WIDTH)
1120
1121/*
1122 * M98090_REG_LOUTR_VOLUME
1123 */
1124#define M98090_RCVRM_MASK (1<<7)
1125#define M98090_RCVRM_SHIFT 7
1126#define M98090_RCVRM_WIDTH 1
1127#define M98090_RCVRVOL_MASK (31<<0)
1128#define M98090_RCVRVOL_SHIFT 0
1129#define M98090_RCVRVOL_WIDTH 5
1130#define M98090_RCVRVOL_NUM (1<<M98090_RCVRVOL_WIDTH)
1131
1132/*
1133 * M98090_REG_JACK_DETECT
1134 */
1135#define M98090_JDETEN_MASK (1<<7)
1136#define M98090_JDETEN_SHIFT 7
1137#define M98090_JDETEN_WIDTH 1
1138#define M98090_JDWK_MASK (1<<6)
1139#define M98090_JDWK_SHIFT 6
1140#define M98090_JDWK_WIDTH 1
1141#define M98090_JDEB_MASK (3<<0)
1142#define M98090_JDEB_SHIFT 0
1143#define M98090_JDEB_WIDTH 2
1144#define M98090_JDEB_25MS (0<<0)
1145#define M98090_JDEB_50MS (1<<0)
1146#define M98090_JDEB_100MS (2<<0)
1147#define M98090_JDEB_200MS (3<<0)
1148
1149/*
1150 * M98090_REG_INPUT_ENABLE
1151 */
1152#define M98090_MBEN_MASK (1<<4)
1153#define M98090_MBEN_SHIFT 4
1154#define M98090_MBEN_WIDTH 1
1155#define M98090_LINEAEN_MASK (1<<3)
1156#define M98090_LINEAEN_SHIFT 3
1157#define M98090_LINEAEN_WIDTH 1
1158#define M98090_LINEBEN_MASK (1<<2)
1159#define M98090_LINEBEN_SHIFT 2
1160#define M98090_LINEBEN_WIDTH 1
1161#define M98090_ADREN_MASK (1<<1)
1162#define M98090_ADREN_SHIFT 1
1163#define M98090_ADREN_WIDTH 1
1164#define M98090_ADLEN_MASK (1<<0)
1165#define M98090_ADLEN_SHIFT 0
1166#define M98090_ADLEN_WIDTH 1
1167
1168/*
1169 * M98090_REG_OUTPUT_ENABLE
1170 */
1171#define M98090_HPREN_MASK (1<<7)
1172#define M98090_HPREN_SHIFT 7
1173#define M98090_HPREN_WIDTH 1
1174#define M98090_HPLEN_MASK (1<<6)
1175#define M98090_HPLEN_SHIFT 6
1176#define M98090_HPLEN_WIDTH 1
1177#define M98090_SPREN_MASK (1<<5)
1178#define M98090_SPREN_SHIFT 5
1179#define M98090_SPREN_WIDTH 1
1180#define M98090_SPLEN_MASK (1<<4)
1181#define M98090_SPLEN_SHIFT 4
1182#define M98090_SPLEN_WIDTH 1
1183#define M98090_RCVLEN_MASK (1<<3)
1184#define M98090_RCVLEN_SHIFT 3
1185#define M98090_RCVLEN_WIDTH 1
1186#define M98090_RCVREN_MASK (1<<2)
1187#define M98090_RCVREN_SHIFT 2
1188#define M98090_RCVREN_WIDTH 1
1189#define M98090_DAREN_MASK (1<<1)
1190#define M98090_DAREN_SHIFT 1
1191#define M98090_DAREN_WIDTH 1
1192#define M98090_DALEN_MASK (1<<0)
1193#define M98090_DALEN_SHIFT 0
1194#define M98090_DALEN_WIDTH 1
1195
1196/*
1197 * M98090_REG_LEVEL_CONTROL
1198 */
1199#define M98090_ZDENN_MASK (1<<2)
1200#define M98090_ZDENN_SHIFT 2
1201#define M98090_ZDENN_WIDTH 1
1202#define M98090_ZDENN_NUM (1<<M98090_ZDENN_WIDTH)
1203#define M98090_VS2ENN_MASK (1<<1)
1204#define M98090_VS2ENN_SHIFT 1
1205#define M98090_VS2ENN_WIDTH 1
1206#define M98090_VS2ENN_NUM (1<<M98090_VS2ENN_WIDTH)
1207#define M98090_VSENN_MASK (1<<0)
1208#define M98090_VSENN_SHIFT 0
1209#define M98090_VSENN_WIDTH 1
1210#define M98090_VSENN_NUM (1<<M98090_VSENN_WIDTH)
1211
1212/*
1213 * M98090_REG_DSP_FILTER_ENABLE
1214 */
1215#define M98090_DMIC34BQEN_MASK (1<<4)
1216#define M98090_DMIC34BQEN_SHIFT 4
1217#define M98090_DMIC34BQEN_WIDTH 1
1218#define M98090_DMIC34BQEN_NUM (1<<M98090_DMIC34BQEN_WIDTH)
1219#define M98090_ADCBQEN_MASK (1<<3)
1220#define M98090_ADCBQEN_SHIFT 3
1221#define M98090_ADCBQEN_WIDTH 1
1222#define M98090_ADCBQEN_NUM (1<<M98090_ADCBQEN_WIDTH)
1223#define M98090_EQ3BANDEN_MASK (1<<2)
1224#define M98090_EQ3BANDEN_SHIFT 2
1225#define M98090_EQ3BANDEN_WIDTH 1
1226#define M98090_EQ3BANDEN_NUM (1<<M98090_EQ3BANDEN_WIDTH)
1227#define M98090_EQ5BANDEN_MASK (1<<1)
1228#define M98090_EQ5BANDEN_SHIFT 1
1229#define M98090_EQ5BANDEN_WIDTH 1
1230#define M98090_EQ5BANDEN_NUM (1<<M98090_EQ5BANDEN_WIDTH)
1231#define M98090_EQ7BANDEN_MASK (1<<0)
1232#define M98090_EQ7BANDEN_SHIFT 0
1233#define M98090_EQ7BANDEN_WIDTH 1
1234#define M98090_EQ7BANDEN_NUM (1<<M98090_EQ7BANDEN_WIDTH)
1235
1236/*
1237 * M98090_REG_BIAS_CONTROL
1238 */
1239#define M98090_VCM_MODE_MASK (1<<0)
1240#define M98090_VCM_MODE_SHIFT 0
1241#define M98090_VCM_MODE_WIDTH 1
1242#define M98090_VCM_MODE_NUM (1<<M98090_VCM_MODE_WIDTH)
1243
1244/*
1245 * M98090_REG_DAC_CONTROL
1246 */
1247#define M98090_PERFMODE_MASK (1<<1)
1248#define M98090_PERFMODE_SHIFT 1
1249#define M98090_PERFMODE_WIDTH 1
1250#define M98090_PERFMODE_NUM (1<<M98090_PERFMODE_WIDTH)
1251#define M98090_DACHP_MASK (1<<0)
1252#define M98090_DACHP_SHIFT 0
1253#define M98090_DACHP_WIDTH 1
1254#define M98090_DACHP_NUM (1<<M98090_DACHP_WIDTH)
1255
1256/*
1257 * M98090_REG_ADC_CONTROL
1258 */
1259#define M98090_OSR128_MASK (1<<2)
1260#define M98090_OSR128_SHIFT 2
1261#define M98090_OSR128_WIDTH 1
1262#define M98090_ADCDITHER_MASK (1<<1)
1263#define M98090_ADCDITHER_SHIFT 1
1264#define M98090_ADCDITHER_WIDTH 1
1265#define M98090_ADCDITHER_NUM (1<<M98090_ADCDITHER_WIDTH)
1266#define M98090_ADCHP_MASK (1<<0)
1267#define M98090_ADCHP_SHIFT 0
1268#define M98090_ADCHP_WIDTH 1
1269#define M98090_ADCHP_NUM (1<<M98090_ADCHP_WIDTH)
1270
1271/*
1272 * M98090_REG_DEVICE_SHUTDOWN
1273 */
1274#define M98090_SHDNN_MASK (1<<7)
1275#define M98090_SHDNN_SHIFT 7
1276#define M98090_SHDNN_WIDTH 1
1277
1278/*
1279 * M98090_REG_EQUALIZER_BASE
1280 */
1281#define M98090_B0_1_HI_MASK (255<<0)
1282#define M98090_B0_1_HI_SHIFT 0
1283#define M98090_B0_1_HI_WIDTH 8
1284#define M98090_B0_1_MID_MASK (255<<0)
1285#define M98090_B0_1_MID_SHIFT 0
1286#define M98090_B0_1_MID_WIDTH 8
1287#define M98090_B0_1_LO_MASK (255<<0)
1288#define M98090_B0_1_LO_SHIFT 0
1289#define M98090_B0_1_LO_WIDTH 8
1290#define M98090_B1_1_HI_MASK (255<<0)
1291#define M98090_B1_1_HI_SHIFT 0
1292#define M98090_B1_1_HI_WIDTH 8
1293#define M98090_B1_1_MID_MASK (255<<0)
1294#define M98090_B1_1_MID_SHIFT 0
1295#define M98090_B1_1_MID_WIDTH 8
1296#define M98090_B1_1_LO_MASK (255<<0)
1297#define M98090_B1_1_LO_SHIFT 0
1298#define M98090_B1_1_LO_WIDTH 8
1299#define M98090_B2_1_HI_MASK (255<<0)
1300#define M98090_B2_1_HI_SHIFT 0
1301#define M98090_B2_1_HI_WIDTH 8
1302#define M98090_B2_1_MID_MASK (255<<0)
1303#define M98090_B2_1_MID_SHIFT 0
1304#define M98090_B2_1_MID_WIDTH 8
1305#define M98090_B2_1_LO_MASK (255<<0)
1306#define M98090_B2_1_LO_SHIFT 0
1307#define M98090_B2_1_LO_WIDTH 8
1308#define M98090_A1_1_HI_MASK (255<<0)
1309#define M98090_A1_1_HI_SHIFT 0
1310#define M98090_A1_1_HI_WIDTH 8
1311#define M98090_A1_1_MID_MASK (255<<0)
1312#define M98090_A1_1_MID_SHIFT 0
1313#define M98090_A1_1_MID_WIDTH 8
1314#define M98090_A1_1_LO_MASK (255<<0)
1315#define M98090_A1_1_LO_SHIFT 0
1316#define M98090_A1_1_LO_WIDTH 8
1317#define M98090_A2_1_HI_MASK (255<<0)
1318#define M98090_A2_1_HI_SHIFT 0
1319#define M98090_A2_1_HI_WIDTH 8
1320#define M98090_A2_1_MID_MASK (255<<0)
1321#define M98090_A2_1_MID_SHIFT 0
1322#define M98090_A2_1_MID_WIDTH 8
1323#define M98090_A2_1_LO_MASK (255<<0)
1324#define M98090_A2_1_LO_SHIFT 0
1325#define M98090_A2_1_LO_WIDTH 8
1326
1327#define M98090_COEFS_PER_BAND 5
1328#define M98090_COEFS_BLK_SZ (M98090_COEFS_PER_BAND * 3)
1329#define M98090_COEFS_MAX_SZ (M98090_COEFS_BLK_SZ * 7)
1330
1331/*
1332 * M98090_REG_RECORD_BIQUAD_BASE
1333 */
1334#define M98090_REC_B0_HI_MASK (255<<0)
1335#define M98090_REC_B0_HI_SHIFT 0
1336#define M98090_REC_B0_HI_WIDTH 8
1337#define M98090_REC_B0_MID_MASK (255<<0)
1338#define M98090_REC_B0_MID_SHIFT 0
1339#define M98090_REC_B0_MID_WIDTH 8
1340#define M98090_REC_B0_LO_MASK (255<<0)
1341#define M98090_REC_B0_LO_SHIFT 0
1342#define M98090_REC_B0_LO_WIDTH 8
1343#define M98090_REC_B1_HI_MASK (255<<0)
1344#define M98090_REC_B1_HI_SHIFT 0
1345#define M98090_REC_B1_HI_WIDTH 8
1346#define M98090_REC_B1_MID_MASK (255<<0)
1347#define M98090_REC_B1_MID_SHIFT 0
1348#define M98090_REC_B1_MID_WIDTH 8
1349#define M98090_REC_B1_LO_MASK (255<<0)
1350#define M98090_REC_B1_LO_SHIFT 0
1351#define M98090_REC_B1_LO_WIDTH 8
1352#define M98090_REC_B2_HI_MASK (255<<0)
1353#define M98090_REC_B2_HI_SHIFT 0
1354#define M98090_REC_B2_HI_WIDTH 8
1355#define M98090_REC_B2_MID_MASK (255<<0)
1356#define M98090_REC_B2_MID_SHIFT 0
1357#define M98090_REC_B2_MID_WIDTH 8
1358#define M98090_REC_B2_LO_MASK (255<<0)
1359#define M98090_REC_B2_LO_SHIFT 0
1360#define M98090_REC_B2_LO_WIDTH 8
1361#define M98090_REC_A1_HI_MASK (255<<0)
1362#define M98090_REC_A1_HI_SHIFT 0
1363#define M98090_REC_A1_HI_WIDTH 8
1364#define M98090_REC_A1_MID_MASK (255<<0)
1365#define M98090_REC_A1_MID_SHIFT 0
1366#define M98090_REC_A1_MID_WIDTH 8
1367#define M98090_REC_A1_LO_MASK (255<<0)
1368#define M98090_REC_A1_LO_SHIFT 0
1369#define M98090_REC_A1_LO_WIDTH 8
1370#define M98090_REC_A2_HI_MASK (255<<0)
1371#define M98090_REC_A2_HI_SHIFT 0
1372#define M98090_REC_A2_HI_WIDTH 8
1373#define M98090_REC_A2_MID_MASK (255<<0)
1374#define M98090_REC_A2_MID_SHIFT 0
1375#define M98090_REC_A2_MID_WIDTH 8
1376#define M98090_REC_A2_LO_MASK (255<<0)
1377#define M98090_REC_A2_LO_SHIFT 0
1378#define M98090_REC_A2_LO_WIDTH 8
1379
1380/*
1381 * M98090_REG_DMIC3_VOLUME
1382 */
1383#define M98090_DMIC_AV3G_MASK (7<<4)
1384#define M98090_DMIC_AV3G_SHIFT 4
1385#define M98090_DMIC_AV3G_WIDTH 3
1386#define M98090_DMIC_AV3G_NUM (1<<M98090_DMIC_AV3G_WIDTH)
1387#define M98090_DMIC_AV3_MASK (15<<0)
1388#define M98090_DMIC_AV3_SHIFT 0
1389#define M98090_DMIC_AV3_WIDTH 4
1390#define M98090_DMIC_AV3_NUM (1<<M98090_DMIC_AV3_WIDTH)
1391
1392/*
1393 * M98090_REG_DMIC4_VOLUME
1394 */
1395#define M98090_DMIC_AV4G_MASK (7<<4)
1396#define M98090_DMIC_AV4G_SHIFT 4
1397#define M98090_DMIC_AV4G_WIDTH 3
1398#define M98090_DMIC_AV4G_NUM (1<<M98090_DMIC_AV4G_WIDTH)
1399#define M98090_DMIC_AV4_MASK (15<<0)
1400#define M98090_DMIC_AV4_SHIFT 0
1401#define M98090_DMIC_AV4_WIDTH 4
1402#define M98090_DMIC_AV4_NUM (1<<M98090_DMIC_AV4_WIDTH)
1403
1404/*
1405 * M98090_REG_DMIC34_BQ_PREATTEN
1406 */
1407#define M98090_AV34BQ_MASK (15<<0)
1408#define M98090_AV34BQ_SHIFT 0
1409#define M98090_AV34BQ_WIDTH 4
1410#define M98090_AV34BQ_NUM (1<<M98090_AV34BQ_WIDTH)
1411
1412/*
1413 * M98090_REG_RECORD_TDM_SLOT
1414 */
1415#define M98090_TDM_SLOTADCL_MASK (3<<6)
1416#define M98090_TDM_SLOTADCL_SHIFT 6
1417#define M98090_TDM_SLOTADCL_WIDTH 2
1418#define M98090_TDM_SLOTADCL_NUM (1<<M98090_TDM_SLOTADCL_WIDTH)
1419#define M98090_TDM_SLOTADCR_MASK (3<<4)
1420#define M98090_TDM_SLOTADCR_SHIFT 4
1421#define M98090_TDM_SLOTADCR_WIDTH 2
1422#define M98090_TDM_SLOTADCR_NUM (1<<M98090_TDM_SLOTADCR_WIDTH)
1423#define M98090_TDM_SLOTDMIC3_MASK (3<<2)
1424#define M98090_TDM_SLOTDMIC3_SHIFT 2
1425#define M98090_TDM_SLOTDMIC3_WIDTH 2
1426#define M98090_TDM_SLOTDMIC3_NUM (1<<M98090_TDM_SLOTDMIC3_WIDTH)
1427#define M98090_TDM_SLOTDMIC4_MASK (3<<0)
1428#define M98090_TDM_SLOTDMIC4_SHIFT 0
1429#define M98090_TDM_SLOTDMIC4_WIDTH 2
1430#define M98090_TDM_SLOTDMIC4_NUM (1<<M98090_TDM_SLOTDMIC4_WIDTH)
1431
1432/*
1433 * M98090_REG_SAMPLE_RATE
1434 */
1435#define M98090_DMIC34_ZEROPAD_MASK (1<<4)
1436#define M98090_DMIC34_ZEROPAD_SHIFT 4
1437#define M98090_DMIC34_ZEROPAD_WIDTH 1
1438#define M98090_DMIC34_ZEROPAD_NUM (1<<M98090_DIGMIC4_WIDTH)
1439#define M98090_DMIC34_SRDIV_MASK (7<<0)
1440#define M98090_DMIC34_SRDIV_SHIFT 0
1441#define M98090_DMIC34_SRDIV_WIDTH 3
1442
1443/*
1444 * M98090_REG_DMIC34_BIQUAD_BASE
1445 */
1446#define M98090_DMIC34_B0_HI_MASK (255<<0)
1447#define M98090_DMIC34_B0_HI_SHIFT 0
1448#define M98090_DMIC34_B0_HI_WIDTH 8
1449#define M98090_DMIC34_B0_MID_MASK (255<<0)
1450#define M98090_DMIC34_B0_MID_SHIFT 0
1451#define M98090_DMIC34_B0_MID_WIDTH 8
1452#define M98090_DMIC34_B0_LO_MASK (255<<0)
1453#define M98090_DMIC34_B0_LO_SHIFT 0
1454#define M98090_DMIC34_B0_LO_WIDTH 8
1455#define M98090_DMIC34_B1_HI_MASK (255<<0)
1456#define M98090_DMIC34_B1_HI_SHIFT 0
1457#define M98090_DMIC34_B1_HI_WIDTH 8
1458#define M98090_DMIC34_B1_MID_MASK (255<<0)
1459#define M98090_DMIC34_B1_MID_SHIFT 0
1460#define M98090_DMIC34_B1_MID_WIDTH 8
1461#define M98090_DMIC34_B1_LO_MASK (255<<0)
1462#define M98090_DMIC34_B1_LO_SHIFT 0
1463#define M98090_DMIC34_B1_LO_WIDTH 8
1464#define M98090_DMIC34_B2_HI_MASK (255<<0)
1465#define M98090_DMIC34_B2_HI_SHIFT 0
1466#define M98090_DMIC34_B2_HI_WIDTH 8
1467#define M98090_DMIC34_B2_MID_MASK (255<<0)
1468#define M98090_DMIC34_B2_MID_SHIFT 0
1469#define M98090_DMIC34_B2_MID_WIDTH 8
1470#define M98090_DMIC34_B2_LO_MASK (255<<0)
1471#define M98090_DMIC34_B2_LO_SHIFT 0
1472#define M98090_DMIC34_B2_LO_WIDTH 8
1473#define M98090_DMIC34_A1_HI_MASK (255<<0)
1474#define M98090_DMIC34_A1_HI_SHIFT 0
1475#define M98090_DMIC34_A1_HI_WIDTH 8
1476#define M98090_DMIC34_A1_MID_MASK (255<<0)
1477#define M98090_DMIC34_A1_MID_SHIFT 0
1478#define M98090_DMIC34_A1_MID_WIDTH 8
1479#define M98090_DMIC34_A1_LO_MASK (255<<0)
1480#define M98090_DMIC34_A1_LO_SHIFT 0
1481#define M98090_DMIC34_A1_LO_WIDTH 8
1482#define M98090_DMIC34_A2_HI_MASK (255<<0)
1483#define M98090_DMIC34_A2_HI_SHIFT 0
1484#define M98090_DMIC34_A2_HI_WIDTH 8
1485#define M98090_DMIC34_A2_MID_MASK (255<<0)
1486#define M98090_DMIC34_A2_MID_SHIFT 0
1487#define M98090_DMIC34_A2_MID_WIDTH 8
1488#define M98090_DMIC34_A2_LO_MASK (255<<0)
1489#define M98090_DMIC34_A2_LO_SHIFT 0
1490#define M98090_DMIC34_A2_LO_WIDTH 8
1491
1492#define M98090_JACK_STATE_NO_HEADSET 0
1493#define M98090_JACK_STATE_NO_HEADSET_2 1
1494#define M98090_JACK_STATE_HEADPHONE 2
1495#define M98090_JACK_STATE_HEADSET 3
1496
1497/*
1498 * M98090_REG_REVISION_ID
1499 */
1500#define M98090_REVID_MASK (255<<0)
1501#define M98090_REVID_SHIFT 0
1502#define M98090_REVID_WIDTH 8
1503#define M98090_REVID_NUM (1<<M98090_REVID_WIDTH)
1504
1505#define M98090_BYTE1(w) ((w >> 8) & 0xff)
1506#define M98090_BYTE0(w) (w & 0xff)
1507
1508/* Silicon revision number */
1509#define M98090_REVA 0x40
1510#define M98091_REVA 0x50
1511
1512enum max98090_type {
1513 MAX98090,
1514 MAX98091,
1515};
1516
1517struct max98090_cdata {
1518 unsigned int rate;
1519 unsigned int fmt;
1520};
1521
1522struct max98090_priv {
1523 struct regmap *regmap;
1524 struct snd_soc_codec *codec;
1525 enum max98090_type devtype;
1526 void *control_data;
1527 struct max98090_pdata *pdata;
1528 unsigned int sysclk;
1529 unsigned int bclk;
1530 unsigned int lrclk;
1531 struct max98090_cdata dai[1];
1532 int irq;
1533 int jack_state;
1534 struct delayed_work jack_work;
1535 struct snd_soc_jack *jack;
1536 unsigned int dai_fmt;
1537 int tdm_slots;
1538 int tdm_width;
1539 u8 lin_state;
1540 unsigned int pa1en;
1541 unsigned int pa2en;
1542 unsigned int extmic_mux;
1543 unsigned int sidetone;
1544};
1545
1546int max98090_mic_detect(struct snd_soc_codec *codec,
1547 struct snd_soc_jack *jack);
1548
1549#endif
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 5708a973a776..65d09d60b7c6 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -85,6 +85,9 @@ struct aic3x_priv {
85#define AIC3X_MODEL_33 1 85#define AIC3X_MODEL_33 1
86#define AIC3X_MODEL_3007 2 86#define AIC3X_MODEL_3007 2
87 u16 model; 87 u16 model;
88
89 /* Selects the micbias voltage */
90 enum aic3x_micbias_voltage micbias_vg;
88}; 91};
89 92
90/* 93/*
@@ -195,6 +198,37 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
195 return ret; 198 return ret;
196} 199}
197 200
201/*
202 * mic bias power on/off share the same register bits with
203 * output voltage of mic bias. when power on mic bias, we
204 * need reclaim it to voltage value.
205 * 0x0 = Powered off
206 * 0x1 = MICBIAS output is powered to 2.0V,
207 * 0x2 = MICBIAS output is powered to 2.5V
208 * 0x3 = MICBIAS output is connected to AVDD
209 */
210static int mic_bias_event(struct snd_soc_dapm_widget *w,
211 struct snd_kcontrol *kcontrol, int event)
212{
213 struct snd_soc_codec *codec = w->codec;
214 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
215
216 switch (event) {
217 case SND_SOC_DAPM_POST_PMU:
218 /* change mic bias voltage to user defined */
219 snd_soc_update_bits(codec, MICBIAS_CTRL,
220 MICBIAS_LEVEL_MASK,
221 aic3x->micbias_vg << MICBIAS_LEVEL_SHIFT);
222 break;
223
224 case SND_SOC_DAPM_PRE_PMD:
225 snd_soc_update_bits(codec, MICBIAS_CTRL,
226 MICBIAS_LEVEL_MASK, 0);
227 break;
228 }
229 return 0;
230}
231
198static const char *aic3x_left_dac_mux[] = { "DAC_L1", "DAC_L3", "DAC_L2" }; 232static const char *aic3x_left_dac_mux[] = { "DAC_L1", "DAC_L3", "DAC_L2" };
199static const char *aic3x_right_dac_mux[] = { "DAC_R1", "DAC_R3", "DAC_R2" }; 233static const char *aic3x_right_dac_mux[] = { "DAC_R1", "DAC_R3", "DAC_R2" };
200static const char *aic3x_left_hpcom_mux[] = 234static const char *aic3x_left_hpcom_mux[] =
@@ -596,12 +630,9 @@ static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
596 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0), 630 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
597 631
598 /* Mic Bias */ 632 /* Mic Bias */
599 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2V", 633 SND_SOC_DAPM_SUPPLY("Mic Bias", MICBIAS_CTRL, 6, 0,
600 MICBIAS_CTRL, 6, 3, 1, 0), 634 mic_bias_event,
601 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2.5V", 635 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
602 MICBIAS_CTRL, 6, 3, 2, 0),
603 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias AVDD",
604 MICBIAS_CTRL, 6, 3, 3, 0),
605 636
606 /* Output mixers */ 637 /* Output mixers */
607 SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0, 638 SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
@@ -1210,13 +1241,13 @@ static struct snd_soc_dai_driver aic3x_dai = {
1210 .name = "tlv320aic3x-hifi", 1241 .name = "tlv320aic3x-hifi",
1211 .playback = { 1242 .playback = {
1212 .stream_name = "Playback", 1243 .stream_name = "Playback",
1213 .channels_min = 1, 1244 .channels_min = 2,
1214 .channels_max = 2, 1245 .channels_max = 2,
1215 .rates = AIC3X_RATES, 1246 .rates = AIC3X_RATES,
1216 .formats = AIC3X_FORMATS,}, 1247 .formats = AIC3X_FORMATS,},
1217 .capture = { 1248 .capture = {
1218 .stream_name = "Capture", 1249 .stream_name = "Capture",
1219 .channels_min = 1, 1250 .channels_min = 2,
1220 .channels_max = 2, 1251 .channels_max = 2,
1221 .rates = AIC3X_RATES, 1252 .rates = AIC3X_RATES,
1222 .formats = AIC3X_FORMATS,}, 1253 .formats = AIC3X_FORMATS,},
@@ -1386,6 +1417,24 @@ static int aic3x_probe(struct snd_soc_codec *codec)
1386 if (aic3x->model == AIC3X_MODEL_3007) 1417 if (aic3x->model == AIC3X_MODEL_3007)
1387 snd_soc_add_codec_controls(codec, &aic3x_classd_amp_gain_ctrl, 1); 1418 snd_soc_add_codec_controls(codec, &aic3x_classd_amp_gain_ctrl, 1);
1388 1419
1420 /* set mic bias voltage */
1421 switch (aic3x->micbias_vg) {
1422 case AIC3X_MICBIAS_2_0V:
1423 case AIC3X_MICBIAS_2_5V:
1424 case AIC3X_MICBIAS_AVDDV:
1425 snd_soc_update_bits(codec, MICBIAS_CTRL,
1426 MICBIAS_LEVEL_MASK,
1427 (aic3x->micbias_vg) << MICBIAS_LEVEL_SHIFT);
1428 break;
1429 case AIC3X_MICBIAS_OFF:
1430 /*
1431 * noting to do. target won't enter here. This is just to avoid
1432 * compile time warning "warning: enumeration value
1433 * 'AIC3X_MICBIAS_OFF' not handled in switch"
1434 */
1435 break;
1436 }
1437
1389 aic3x_add_widgets(codec); 1438 aic3x_add_widgets(codec);
1390 list_add(&aic3x->list, &reset_list); 1439 list_add(&aic3x->list, &reset_list);
1391 1440
@@ -1461,6 +1510,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
1461 struct aic3x_setup_data *ai3x_setup; 1510 struct aic3x_setup_data *ai3x_setup;
1462 struct device_node *np = i2c->dev.of_node; 1511 struct device_node *np = i2c->dev.of_node;
1463 int ret; 1512 int ret;
1513 u32 value;
1464 1514
1465 aic3x = devm_kzalloc(&i2c->dev, sizeof(struct aic3x_priv), GFP_KERNEL); 1515 aic3x = devm_kzalloc(&i2c->dev, sizeof(struct aic3x_priv), GFP_KERNEL);
1466 if (aic3x == NULL) { 1516 if (aic3x == NULL) {
@@ -1474,6 +1524,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
1474 if (pdata) { 1524 if (pdata) {
1475 aic3x->gpio_reset = pdata->gpio_reset; 1525 aic3x->gpio_reset = pdata->gpio_reset;
1476 aic3x->setup = pdata->setup; 1526 aic3x->setup = pdata->setup;
1527 aic3x->micbias_vg = pdata->micbias_vg;
1477 } else if (np) { 1528 } else if (np) {
1478 ai3x_setup = devm_kzalloc(&i2c->dev, sizeof(*ai3x_setup), 1529 ai3x_setup = devm_kzalloc(&i2c->dev, sizeof(*ai3x_setup),
1479 GFP_KERNEL); 1530 GFP_KERNEL);
@@ -1493,6 +1544,26 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
1493 aic3x->setup = ai3x_setup; 1544 aic3x->setup = ai3x_setup;
1494 } 1545 }
1495 1546
1547 if (!of_property_read_u32(np, "ai3x-micbias-vg", &value)) {
1548 switch (value) {
1549 case 1 :
1550 aic3x->micbias_vg = AIC3X_MICBIAS_2_0V;
1551 break;
1552 case 2 :
1553 aic3x->micbias_vg = AIC3X_MICBIAS_2_5V;
1554 break;
1555 case 3 :
1556 aic3x->micbias_vg = AIC3X_MICBIAS_AVDDV;
1557 break;
1558 default :
1559 aic3x->micbias_vg = AIC3X_MICBIAS_OFF;
1560 dev_err(&i2c->dev, "Unsuitable MicBias voltage "
1561 "found in DT\n");
1562 }
1563 } else {
1564 aic3x->micbias_vg = AIC3X_MICBIAS_OFF;
1565 }
1566
1496 } else { 1567 } else {
1497 aic3x->gpio_reset = -1; 1568 aic3x->gpio_reset = -1;
1498 } 1569 }
diff --git a/sound/soc/codecs/tlv320aic3x.h b/sound/soc/codecs/tlv320aic3x.h
index 6db3c41b0163..e521ac3ddde8 100644
--- a/sound/soc/codecs/tlv320aic3x.h
+++ b/sound/soc/codecs/tlv320aic3x.h
@@ -238,6 +238,10 @@
238/* Default input volume */ 238/* Default input volume */
239#define DEFAULT_GAIN 0x20 239#define DEFAULT_GAIN 0x20
240 240
241/* MICBIAS Control Register */
242#define MICBIAS_LEVEL_SHIFT (6)
243#define MICBIAS_LEVEL_MASK (3 << 6)
244
241/* headset detection / button API */ 245/* headset detection / button API */
242 246
243/* The AIC3x supports detection of stereo headsets (GND + left + right signal) 247/* The AIC3x supports detection of stereo headsets (GND + left + right signal)
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 782b0cded2e6..4f358393d6d6 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -1452,20 +1452,6 @@ static int dac33_soc_remove(struct snd_soc_codec *codec)
1452 return 0; 1452 return 0;
1453} 1453}
1454 1454
1455static int dac33_soc_suspend(struct snd_soc_codec *codec)
1456{
1457 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
1458
1459 return 0;
1460}
1461
1462static int dac33_soc_resume(struct snd_soc_codec *codec)
1463{
1464 dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1465
1466 return 0;
1467}
1468
1469static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = { 1455static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
1470 .read = dac33_read_reg_cache, 1456 .read = dac33_read_reg_cache,
1471 .write = dac33_write_locked, 1457 .write = dac33_write_locked,
@@ -1476,8 +1462,6 @@ static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
1476 .reg_cache_default = dac33_reg, 1462 .reg_cache_default = dac33_reg,
1477 .probe = dac33_soc_probe, 1463 .probe = dac33_soc_probe,
1478 .remove = dac33_soc_remove, 1464 .remove = dac33_soc_remove,
1479 .suspend = dac33_soc_suspend,
1480 .resume = dac33_soc_resume,
1481 1465
1482 .controls = dac33_snd_controls, 1466 .controls = dac33_snd_controls,
1483 .num_controls = ARRAY_SIZE(dac33_snd_controls), 1467 .num_controls = ARRAY_SIZE(dac33_snd_controls),
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 63b280b06035..8e6e5b016021 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -41,6 +41,11 @@
41/* Register descriptions are here */ 41/* Register descriptions are here */
42#include <linux/mfd/twl4030-audio.h> 42#include <linux/mfd/twl4030-audio.h>
43 43
44/* TWL4030 PMBR1 Register */
45#define TWL4030_PMBR1_REG 0x0D
46/* TWL4030 PMBR1 Register GPIO6 mux bits */
47#define TWL4030_GPIO6_PWM0_MUTE(value) ((value & 0x03) << 2)
48
44/* Shadow register used by the audio driver */ 49/* Shadow register used by the audio driver */
45#define TWL4030_REG_SW_SHADOW 0x4A 50#define TWL4030_REG_SW_SHADOW 0x4A
46#define TWL4030_CACHEREGNUM (TWL4030_REG_SW_SHADOW + 1) 51#define TWL4030_CACHEREGNUM (TWL4030_REG_SW_SHADOW + 1)
@@ -348,19 +353,32 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
348 353
349 pdata = twl4030_get_pdata(codec); 354 pdata = twl4030_get_pdata(codec);
350 355
351 if (pdata && pdata->hs_extmute && 356 if (pdata && pdata->hs_extmute) {
352 gpio_is_valid(pdata->hs_extmute_gpio)) { 357 if (gpio_is_valid(pdata->hs_extmute_gpio)) {
353 int ret; 358 int ret;
354 359
355 if (!pdata->hs_extmute_gpio) 360 if (!pdata->hs_extmute_gpio)
356 dev_warn(codec->dev, 361 dev_warn(codec->dev,
357 "Extmute GPIO is 0 is this correct?\n"); 362 "Extmute GPIO is 0 is this correct?\n");
358 363
359 ret = gpio_request_one(pdata->hs_extmute_gpio, 364 ret = gpio_request_one(pdata->hs_extmute_gpio,
360 GPIOF_OUT_INIT_LOW, "hs_extmute"); 365 GPIOF_OUT_INIT_LOW,
361 if (ret) { 366 "hs_extmute");
362 dev_err(codec->dev, "Failed to get hs_extmute GPIO\n"); 367 if (ret) {
363 pdata->hs_extmute_gpio = -1; 368 dev_err(codec->dev,
369 "Failed to get hs_extmute GPIO\n");
370 pdata->hs_extmute_gpio = -1;
371 }
372 } else {
373 u8 pin_mux;
374
375 /* Set TWL4030 GPIO6 as EXTMUTE signal */
376 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
377 TWL4030_PMBR1_REG);
378 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
379 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
380 twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
381 TWL4030_PMBR1_REG);
364 } 382 }
365 } 383 }
366 384
@@ -1306,6 +1324,9 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
1306 SND_SOC_DAPM_DAC("DAC Left2", NULL, SND_SOC_NOPM, 0, 0), 1324 SND_SOC_DAPM_DAC("DAC Left2", NULL, SND_SOC_NOPM, 0, 0),
1307 SND_SOC_DAPM_DAC("DAC Voice", NULL, SND_SOC_NOPM, 0, 0), 1325 SND_SOC_DAPM_DAC("DAC Voice", NULL, SND_SOC_NOPM, 0, 0),
1308 1326
1327 SND_SOC_DAPM_AIF_IN("VAIFIN", "Voice Playback", 0,
1328 TWL4030_REG_VOICE_IF, 6, 0),
1329
1309 /* Analog bypasses */ 1330 /* Analog bypasses */
1310 SND_SOC_DAPM_SWITCH("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0, 1331 SND_SOC_DAPM_SWITCH("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0,
1311 &twl4030_dapm_abypassr1_control), 1332 &twl4030_dapm_abypassr1_control),
@@ -1438,6 +1459,9 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
1438 SND_SOC_DAPM_ADC("ADC Virtual Left2", NULL, SND_SOC_NOPM, 0, 0), 1459 SND_SOC_DAPM_ADC("ADC Virtual Left2", NULL, SND_SOC_NOPM, 0, 0),
1439 SND_SOC_DAPM_ADC("ADC Virtual Right2", NULL, SND_SOC_NOPM, 0, 0), 1460 SND_SOC_DAPM_ADC("ADC Virtual Right2", NULL, SND_SOC_NOPM, 0, 0),
1440 1461
1462 SND_SOC_DAPM_AIF_OUT("VAIFOUT", "Voice Capture", 0,
1463 TWL4030_REG_VOICE_IF, 5, 0),
1464
1441 /* Analog/Digital mic path selection. 1465 /* Analog/Digital mic path selection.
1442 TX1 Left/Right: either analog Left/Right or Digimic0 1466 TX1 Left/Right: either analog Left/Right or Digimic0
1443 TX2 Left/Right: either analog Left/Right or Digimic1 */ 1467 TX2 Left/Right: either analog Left/Right or Digimic1 */
@@ -1473,10 +1497,15 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
1473 SND_SOC_DAPM_SUPPLY("micbias2 select", TWL4030_REG_MICBIAS_CTL, 6, 0, 1497 SND_SOC_DAPM_SUPPLY("micbias2 select", TWL4030_REG_MICBIAS_CTL, 6, 0,
1474 NULL, 0), 1498 NULL, 0),
1475 1499
1476 SND_SOC_DAPM_MICBIAS("Mic Bias 1", TWL4030_REG_MICBIAS_CTL, 0, 0), 1500 /* Microphone bias */
1477 SND_SOC_DAPM_MICBIAS("Mic Bias 2", TWL4030_REG_MICBIAS_CTL, 1, 0), 1501 SND_SOC_DAPM_SUPPLY("Mic Bias 1",
1478 SND_SOC_DAPM_MICBIAS("Headset Mic Bias", TWL4030_REG_MICBIAS_CTL, 2, 0), 1502 TWL4030_REG_MICBIAS_CTL, 0, 0, NULL, 0),
1503 SND_SOC_DAPM_SUPPLY("Mic Bias 2",
1504 TWL4030_REG_MICBIAS_CTL, 1, 0, NULL, 0),
1505 SND_SOC_DAPM_SUPPLY("Headset Mic Bias",
1506 TWL4030_REG_MICBIAS_CTL, 2, 0, NULL, 0),
1479 1507
1508 SND_SOC_DAPM_SUPPLY("VIF Enable", TWL4030_REG_VOICE_IF, 0, 0, NULL, 0),
1480}; 1509};
1481 1510
1482static const struct snd_soc_dapm_route intercon[] = { 1511static const struct snd_soc_dapm_route intercon[] = {
@@ -1485,17 +1514,16 @@ static const struct snd_soc_dapm_route intercon[] = {
1485 {"DAC Left1", NULL, "HiFi Playback"}, 1514 {"DAC Left1", NULL, "HiFi Playback"},
1486 {"DAC Right2", NULL, "HiFi Playback"}, 1515 {"DAC Right2", NULL, "HiFi Playback"},
1487 {"DAC Left2", NULL, "HiFi Playback"}, 1516 {"DAC Left2", NULL, "HiFi Playback"},
1488 {"DAC Voice", NULL, "Voice Playback"}, 1517 {"DAC Voice", NULL, "VAIFIN"},
1489 1518
1490 /* ADC -> Stream mapping */ 1519 /* ADC -> Stream mapping */
1491 {"HiFi Capture", NULL, "ADC Virtual Left1"}, 1520 {"HiFi Capture", NULL, "ADC Virtual Left1"},
1492 {"HiFi Capture", NULL, "ADC Virtual Right1"}, 1521 {"HiFi Capture", NULL, "ADC Virtual Right1"},
1493 {"HiFi Capture", NULL, "ADC Virtual Left2"}, 1522 {"HiFi Capture", NULL, "ADC Virtual Left2"},
1494 {"HiFi Capture", NULL, "ADC Virtual Right2"}, 1523 {"HiFi Capture", NULL, "ADC Virtual Right2"},
1495 {"Voice Capture", NULL, "ADC Virtual Left1"}, 1524 {"VAIFOUT", NULL, "ADC Virtual Left2"},
1496 {"Voice Capture", NULL, "ADC Virtual Right1"}, 1525 {"VAIFOUT", NULL, "ADC Virtual Right2"},
1497 {"Voice Capture", NULL, "ADC Virtual Left2"}, 1526 {"VAIFOUT", NULL, "VIF Enable"},
1498 {"Voice Capture", NULL, "ADC Virtual Right2"},
1499 1527
1500 {"Digital L1 Playback Mixer", NULL, "DAC Left1"}, 1528 {"Digital L1 Playback Mixer", NULL, "DAC Left1"},
1501 {"Digital R1 Playback Mixer", NULL, "DAC Right1"}, 1529 {"Digital R1 Playback Mixer", NULL, "DAC Right1"},
@@ -1510,6 +1538,7 @@ static const struct snd_soc_dapm_route intercon[] = {
1510 {"DAC Right1", NULL, "AIF Enable"}, 1538 {"DAC Right1", NULL, "AIF Enable"},
1511 {"DAC Left2", NULL, "AIF Enable"}, 1539 {"DAC Left2", NULL, "AIF Enable"},
1512 {"DAC Right1", NULL, "AIF Enable"}, 1540 {"DAC Right1", NULL, "AIF Enable"},
1541 {"DAC Voice", NULL, "VIF Enable"},
1513 1542
1514 {"Digital R2 Playback Mixer", NULL, "AIF Enable"}, 1543 {"Digital R2 Playback Mixer", NULL, "AIF Enable"},
1515 {"Digital L2 Playback Mixer", NULL, "AIF Enable"}, 1544 {"Digital L2 Playback Mixer", NULL, "AIF Enable"},
@@ -2267,18 +2296,6 @@ static struct snd_soc_dai_driver twl4030_dai[] = {
2267}, 2296},
2268}; 2297};
2269 2298
2270static int twl4030_soc_suspend(struct snd_soc_codec *codec)
2271{
2272 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
2273 return 0;
2274}
2275
2276static int twl4030_soc_resume(struct snd_soc_codec *codec)
2277{
2278 twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2279 return 0;
2280}
2281
2282static int twl4030_soc_probe(struct snd_soc_codec *codec) 2299static int twl4030_soc_probe(struct snd_soc_codec *codec)
2283{ 2300{
2284 struct twl4030_priv *twl4030; 2301 struct twl4030_priv *twl4030;
@@ -2316,8 +2333,6 @@ static int twl4030_soc_remove(struct snd_soc_codec *codec)
2316static struct snd_soc_codec_driver soc_codec_dev_twl4030 = { 2333static struct snd_soc_codec_driver soc_codec_dev_twl4030 = {
2317 .probe = twl4030_soc_probe, 2334 .probe = twl4030_soc_probe,
2318 .remove = twl4030_soc_remove, 2335 .remove = twl4030_soc_remove,
2319 .suspend = twl4030_soc_suspend,
2320 .resume = twl4030_soc_resume,
2321 .read = twl4030_read_reg_cache, 2336 .read = twl4030_read_reg_cache,
2322 .write = twl4030_write, 2337 .write = twl4030_write,
2323 .set_bias_level = twl4030_set_bias_level, 2338 .set_bias_level = twl4030_set_bias_level,
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index 3fc3fc64dd8b..9b9a6e587610 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -69,13 +69,8 @@ struct twl6040_data {
69 int hs_power_mode_locked; 69 int hs_power_mode_locked;
70 unsigned int clk_in; 70 unsigned int clk_in;
71 unsigned int sysclk; 71 unsigned int sysclk;
72 u16 hs_left_step;
73 u16 hs_right_step;
74 u16 hf_left_step;
75 u16 hf_right_step;
76 struct twl6040_jack_data hs_jack; 72 struct twl6040_jack_data hs_jack;
77 struct snd_soc_codec *codec; 73 struct snd_soc_codec *codec;
78 struct workqueue_struct *workqueue;
79 struct mutex mutex; 74 struct mutex mutex;
80}; 75};
81 76
@@ -404,8 +399,7 @@ static irqreturn_t twl6040_audio_handler(int irq, void *data)
404 struct snd_soc_codec *codec = data; 399 struct snd_soc_codec *codec = data;
405 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 400 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
406 401
407 queue_delayed_work(priv->workqueue, &priv->hs_jack.work, 402 schedule_delayed_work(&priv->hs_jack.work, msecs_to_jiffies(200));
408 msecs_to_jiffies(200));
409 403
410 return IRQ_HANDLED; 404 return IRQ_HANDLED;
411} 405}
@@ -1115,7 +1109,6 @@ static int twl6040_suspend(struct snd_soc_codec *codec)
1115static int twl6040_resume(struct snd_soc_codec *codec) 1109static int twl6040_resume(struct snd_soc_codec *codec)
1116{ 1110{
1117 twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1111 twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1118 twl6040_set_bias_level(codec, codec->dapm.suspend_bias_level);
1119 1112
1120 return 0; 1113 return 0;
1121} 1114}
@@ -1127,83 +1120,46 @@ static int twl6040_resume(struct snd_soc_codec *codec)
1127static int twl6040_probe(struct snd_soc_codec *codec) 1120static int twl6040_probe(struct snd_soc_codec *codec)
1128{ 1121{
1129 struct twl6040_data *priv; 1122 struct twl6040_data *priv;
1130 struct twl6040_codec_data *pdata = dev_get_platdata(codec->dev);
1131 struct platform_device *pdev = container_of(codec->dev, 1123 struct platform_device *pdev = container_of(codec->dev,
1132 struct platform_device, dev); 1124 struct platform_device, dev);
1133 int ret = 0; 1125 int ret = 0;
1134 1126
1135 priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL); 1127 priv = devm_kzalloc(codec->dev, sizeof(*priv), GFP_KERNEL);
1136 if (priv == NULL) 1128 if (priv == NULL)
1137 return -ENOMEM; 1129 return -ENOMEM;
1130
1138 snd_soc_codec_set_drvdata(codec, priv); 1131 snd_soc_codec_set_drvdata(codec, priv);
1139 1132
1140 priv->codec = codec; 1133 priv->codec = codec;
1141 codec->control_data = dev_get_drvdata(codec->dev->parent); 1134 codec->control_data = dev_get_drvdata(codec->dev->parent);
1142 1135
1143 if (pdata && pdata->hs_left_step && pdata->hs_right_step) {
1144 priv->hs_left_step = pdata->hs_left_step;
1145 priv->hs_right_step = pdata->hs_right_step;
1146 } else {
1147 priv->hs_left_step = 1;
1148 priv->hs_right_step = 1;
1149 }
1150
1151 if (pdata && pdata->hf_left_step && pdata->hf_right_step) {
1152 priv->hf_left_step = pdata->hf_left_step;
1153 priv->hf_right_step = pdata->hf_right_step;
1154 } else {
1155 priv->hf_left_step = 1;
1156 priv->hf_right_step = 1;
1157 }
1158
1159 priv->plug_irq = platform_get_irq(pdev, 0); 1136 priv->plug_irq = platform_get_irq(pdev, 0);
1160 if (priv->plug_irq < 0) { 1137 if (priv->plug_irq < 0) {
1161 dev_err(codec->dev, "invalid irq\n"); 1138 dev_err(codec->dev, "invalid irq\n");
1162 ret = -EINVAL; 1139 return -EINVAL;
1163 goto work_err;
1164 }
1165
1166 priv->workqueue = alloc_workqueue("twl6040-codec", 0, 0);
1167 if (!priv->workqueue) {
1168 ret = -ENOMEM;
1169 goto work_err;
1170 } 1140 }
1171 1141
1172 INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work); 1142 INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work);
1173 1143
1174 mutex_init(&priv->mutex); 1144 mutex_init(&priv->mutex);
1175 1145
1176 ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler, 1146 ret = devm_request_threaded_irq(codec->dev, priv->plug_irq, NULL,
1177 0, "twl6040_irq_plug", codec); 1147 twl6040_audio_handler, IRQF_NO_SUSPEND,
1148 "twl6040_irq_plug", codec);
1178 if (ret) { 1149 if (ret) {
1179 dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret); 1150 dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret);
1180 goto plugirq_err; 1151 return ret;
1181 } 1152 }
1182 1153
1183 twl6040_init_chip(codec); 1154 twl6040_init_chip(codec);
1184 1155
1185 /* power on device */ 1156 /* power on device */
1186 ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1157 return twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1187 if (!ret)
1188 return 0;
1189
1190 /* Error path */
1191 free_irq(priv->plug_irq, codec);
1192plugirq_err:
1193 destroy_workqueue(priv->workqueue);
1194work_err:
1195 kfree(priv);
1196 return ret;
1197} 1158}
1198 1159
1199static int twl6040_remove(struct snd_soc_codec *codec) 1160static int twl6040_remove(struct snd_soc_codec *codec)
1200{ 1161{
1201 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1202
1203 twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); 1162 twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
1204 free_irq(priv->plug_irq, codec);
1205 destroy_workqueue(priv->workqueue);
1206 kfree(priv);
1207 1163
1208 return 0; 1164 return 0;
1209} 1165}
diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index 12bcae63a7f0..f2ac38b61a1b 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -26,6 +26,7 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/firmware.h> 28#include <linux/firmware.h>
29#include <linux/clk.h>
29#include <linux/delay.h> 30#include <linux/delay.h>
30#include <linux/pm.h> 31#include <linux/pm.h>
31#include <linux/i2c.h> 32#include <linux/i2c.h>
@@ -62,6 +63,7 @@ enum wm2000_anc_mode {
62struct wm2000_priv { 63struct wm2000_priv {
63 struct i2c_client *i2c; 64 struct i2c_client *i2c;
64 struct regmap *regmap; 65 struct regmap *regmap;
66 struct clk *mclk;
65 67
66 struct regulator_bulk_data supplies[WM2000_NUM_SUPPLIES]; 68 struct regulator_bulk_data supplies[WM2000_NUM_SUPPLIES];
67 69
@@ -71,11 +73,12 @@ struct wm2000_priv {
71 unsigned int anc_eng_ena:1; 73 unsigned int anc_eng_ena:1;
72 unsigned int spk_ena:1; 74 unsigned int spk_ena:1;
73 75
74 unsigned int mclk_div:1;
75 unsigned int speech_clarity:1; 76 unsigned int speech_clarity:1;
76 77
77 int anc_download_size; 78 int anc_download_size;
78 char *anc_download; 79 char *anc_download;
80
81 struct mutex lock;
79}; 82};
80 83
81static int wm2000_write(struct i2c_client *i2c, unsigned int reg, 84static int wm2000_write(struct i2c_client *i2c, unsigned int reg,
@@ -131,6 +134,7 @@ static int wm2000_poll_bit(struct i2c_client *i2c,
131static int wm2000_power_up(struct i2c_client *i2c, int analogue) 134static int wm2000_power_up(struct i2c_client *i2c, int analogue)
132{ 135{
133 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev); 136 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
137 unsigned long rate;
134 int ret; 138 int ret;
135 139
136 BUG_ON(wm2000->anc_mode != ANC_OFF); 140 BUG_ON(wm2000->anc_mode != ANC_OFF);
@@ -143,7 +147,8 @@ static int wm2000_power_up(struct i2c_client *i2c, int analogue)
143 return ret; 147 return ret;
144 } 148 }
145 149
146 if (!wm2000->mclk_div) { 150 rate = clk_get_rate(wm2000->mclk);
151 if (rate <= 13500000) {
147 dev_dbg(&i2c->dev, "Disabling MCLK divider\n"); 152 dev_dbg(&i2c->dev, "Disabling MCLK divider\n");
148 wm2000_write(i2c, WM2000_REG_SYS_CTL2, 153 wm2000_write(i2c, WM2000_REG_SYS_CTL2,
149 WM2000_MCLK_DIV2_ENA_CLR); 154 WM2000_MCLK_DIV2_ENA_CLR);
@@ -550,6 +555,15 @@ static int wm2000_anc_transition(struct wm2000_priv *wm2000,
550 return -EINVAL; 555 return -EINVAL;
551 } 556 }
552 557
558 /* Maintain clock while active */
559 if (anc_transitions[i].source == ANC_OFF) {
560 ret = clk_prepare_enable(wm2000->mclk);
561 if (ret != 0) {
562 dev_err(&i2c->dev, "Failed to enable MCLK: %d\n", ret);
563 return ret;
564 }
565 }
566
553 for (j = 0; j < ARRAY_SIZE(anc_transitions[j].step); j++) { 567 for (j = 0; j < ARRAY_SIZE(anc_transitions[j].step); j++) {
554 if (!anc_transitions[i].step[j]) 568 if (!anc_transitions[i].step[j])
555 break; 569 break;
@@ -559,7 +573,10 @@ static int wm2000_anc_transition(struct wm2000_priv *wm2000,
559 return ret; 573 return ret;
560 } 574 }
561 575
562 return 0; 576 if (anc_transitions[i].dest == ANC_OFF)
577 clk_disable_unprepare(wm2000->mclk);
578
579 return ret;
563} 580}
564 581
565static int wm2000_anc_set_mode(struct wm2000_priv *wm2000) 582static int wm2000_anc_set_mode(struct wm2000_priv *wm2000)
@@ -599,13 +616,20 @@ static int wm2000_anc_mode_put(struct snd_kcontrol *kcontrol,
599 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 616 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
600 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev); 617 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev);
601 int anc_active = ucontrol->value.enumerated.item[0]; 618 int anc_active = ucontrol->value.enumerated.item[0];
619 int ret;
602 620
603 if (anc_active > 1) 621 if (anc_active > 1)
604 return -EINVAL; 622 return -EINVAL;
605 623
624 mutex_lock(&wm2000->lock);
625
606 wm2000->anc_active = anc_active; 626 wm2000->anc_active = anc_active;
607 627
608 return wm2000_anc_set_mode(wm2000); 628 ret = wm2000_anc_set_mode(wm2000);
629
630 mutex_unlock(&wm2000->lock);
631
632 return ret;
609} 633}
610 634
611static int wm2000_speaker_get(struct snd_kcontrol *kcontrol, 635static int wm2000_speaker_get(struct snd_kcontrol *kcontrol,
@@ -625,16 +649,24 @@ static int wm2000_speaker_put(struct snd_kcontrol *kcontrol,
625 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 649 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
626 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev); 650 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev);
627 int val = ucontrol->value.enumerated.item[0]; 651 int val = ucontrol->value.enumerated.item[0];
652 int ret;
628 653
629 if (val > 1) 654 if (val > 1)
630 return -EINVAL; 655 return -EINVAL;
631 656
657 mutex_lock(&wm2000->lock);
658
632 wm2000->spk_ena = val; 659 wm2000->spk_ena = val;
633 660
634 return wm2000_anc_set_mode(wm2000); 661 ret = wm2000_anc_set_mode(wm2000);
662
663 mutex_unlock(&wm2000->lock);
664
665 return ret;
635} 666}
636 667
637static const struct snd_kcontrol_new wm2000_controls[] = { 668static const struct snd_kcontrol_new wm2000_controls[] = {
669 SOC_SINGLE("ANC Volume", WM2000_REG_ANC_GAIN_CTRL, 0, 255, 0),
638 SOC_SINGLE_BOOL_EXT("WM2000 ANC Switch", 0, 670 SOC_SINGLE_BOOL_EXT("WM2000 ANC Switch", 0,
639 wm2000_anc_mode_get, 671 wm2000_anc_mode_get,
640 wm2000_anc_mode_put), 672 wm2000_anc_mode_put),
@@ -648,6 +680,9 @@ static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w,
648{ 680{
649 struct snd_soc_codec *codec = w->codec; 681 struct snd_soc_codec *codec = w->codec;
650 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev); 682 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev);
683 int ret;
684
685 mutex_lock(&wm2000->lock);
651 686
652 if (SND_SOC_DAPM_EVENT_ON(event)) 687 if (SND_SOC_DAPM_EVENT_ON(event))
653 wm2000->anc_eng_ena = 1; 688 wm2000->anc_eng_ena = 1;
@@ -655,7 +690,11 @@ static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w,
655 if (SND_SOC_DAPM_EVENT_OFF(event)) 690 if (SND_SOC_DAPM_EVENT_OFF(event))
656 wm2000->anc_eng_ena = 0; 691 wm2000->anc_eng_ena = 0;
657 692
658 return wm2000_anc_set_mode(wm2000); 693 ret = wm2000_anc_set_mode(wm2000);
694
695 mutex_unlock(&wm2000->lock);
696
697 return ret;
659} 698}
660 699
661static const struct snd_soc_dapm_widget wm2000_dapm_widgets[] = { 700static const struct snd_soc_dapm_widget wm2000_dapm_widgets[] = {
@@ -702,6 +741,9 @@ static bool wm2000_readable_reg(struct device *dev, unsigned int reg)
702{ 741{
703 switch (reg) { 742 switch (reg) {
704 case WM2000_REG_SYS_START: 743 case WM2000_REG_SYS_START:
744 case WM2000_REG_ANC_GAIN_CTRL:
745 case WM2000_REG_MSE_TH1:
746 case WM2000_REG_MSE_TH2:
705 case WM2000_REG_SPEECH_CLARITY: 747 case WM2000_REG_SPEECH_CLARITY:
706 case WM2000_REG_SYS_WATCHDOG: 748 case WM2000_REG_SYS_WATCHDOG:
707 case WM2000_REG_ANA_VMID_PD_TIME: 749 case WM2000_REG_ANA_VMID_PD_TIME:
@@ -737,6 +779,8 @@ static int wm2000_probe(struct snd_soc_codec *codec)
737{ 779{
738 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev); 780 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev);
739 781
782 snd_soc_codec_set_cache_io(codec, 16, 8, SND_SOC_REGMAP);
783
740 /* This will trigger a transition to standby mode by default */ 784 /* This will trigger a transition to standby mode by default */
741 wm2000_anc_set_mode(wm2000); 785 wm2000_anc_set_mode(wm2000);
742 786
@@ -782,6 +826,8 @@ static int wm2000_i2c_probe(struct i2c_client *i2c,
782 return -ENOMEM; 826 return -ENOMEM;
783 } 827 }
784 828
829 mutex_init(&wm2000->lock);
830
785 dev_set_drvdata(&i2c->dev, wm2000); 831 dev_set_drvdata(&i2c->dev, wm2000);
786 832
787 wm2000->regmap = devm_regmap_init_i2c(i2c, &wm2000_regmap); 833 wm2000->regmap = devm_regmap_init_i2c(i2c, &wm2000_regmap);
@@ -823,10 +869,16 @@ static int wm2000_i2c_probe(struct i2c_client *i2c,
823 reg = wm2000_read(i2c, WM2000_REG_REVISON); 869 reg = wm2000_read(i2c, WM2000_REG_REVISON);
824 dev_info(&i2c->dev, "revision %c\n", reg + 'A'); 870 dev_info(&i2c->dev, "revision %c\n", reg + 'A');
825 871
872 wm2000->mclk = devm_clk_get(&i2c->dev, "MCLK");
873 if (IS_ERR(wm2000->mclk)) {
874 ret = PTR_ERR(wm2000->mclk);
875 dev_err(&i2c->dev, "Failed to get MCLK: %d\n", ret);
876 goto err_supplies;
877 }
878
826 filename = "wm2000_anc.bin"; 879 filename = "wm2000_anc.bin";
827 pdata = dev_get_platdata(&i2c->dev); 880 pdata = dev_get_platdata(&i2c->dev);
828 if (pdata) { 881 if (pdata) {
829 wm2000->mclk_div = pdata->mclkdiv2;
830 wm2000->speech_clarity = !pdata->speech_enh_disable; 882 wm2000->speech_clarity = !pdata->speech_enh_disable;
831 883
832 if (pdata->download_file) 884 if (pdata->download_file)
diff --git a/sound/soc/codecs/wm2000.h b/sound/soc/codecs/wm2000.h
index abcd82a93995..fb812cd9e77d 100644
--- a/sound/soc/codecs/wm2000.h
+++ b/sound/soc/codecs/wm2000.h
@@ -10,6 +10,9 @@
10#define _WM2000_H 10#define _WM2000_H
11 11
12#define WM2000_REG_SYS_START 0x8000 12#define WM2000_REG_SYS_START 0x8000
13#define WM2000_REG_ANC_GAIN_CTRL 0x8fa2
14#define WM2000_REG_MSE_TH2 0x8fdf
15#define WM2000_REG_MSE_TH1 0x8fe0
13#define WM2000_REG_SPEECH_CLARITY 0x8fef 16#define WM2000_REG_SPEECH_CLARITY 0x8fef
14#define WM2000_REG_SYS_WATCHDOG 0x8ff6 17#define WM2000_REG_SYS_WATCHDOG 0x8ff6
15#define WM2000_REG_ANA_VMID_PD_TIME 0x8ff7 18#define WM2000_REG_ANA_VMID_PD_TIME 0x8ff7
diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c
index d8c65f574658..ddc98f02ecbd 100644
--- a/sound/soc/codecs/wm2200.c
+++ b/sound/soc/codecs/wm2200.c
@@ -1109,6 +1109,16 @@ static int wm2200_mixer_values[] = {
1109 static WM2200_MUX_CTL_DECL(name##_aux5); \ 1109 static WM2200_MUX_CTL_DECL(name##_aux5); \
1110 static WM2200_MUX_CTL_DECL(name##_aux6); 1110 static WM2200_MUX_CTL_DECL(name##_aux6);
1111 1111
1112static const char *wm2200_rxanc_input_sel_texts[] = {
1113 "None", "IN1", "IN2", "IN3",
1114};
1115
1116static const struct soc_enum wm2200_rxanc_input_sel =
1117 SOC_ENUM_SINGLE(WM2200_RXANC_SRC,
1118 WM2200_IN_RXANC_SEL_SHIFT,
1119 ARRAY_SIZE(wm2200_rxanc_input_sel_texts),
1120 wm2200_rxanc_input_sel_texts);
1121
1112static const struct snd_kcontrol_new wm2200_snd_controls[] = { 1122static const struct snd_kcontrol_new wm2200_snd_controls[] = {
1113SOC_SINGLE("IN1 High Performance Switch", WM2200_IN1L_CONTROL, 1123SOC_SINGLE("IN1 High Performance Switch", WM2200_IN1L_CONTROL,
1114 WM2200_IN1_OSR_SHIFT, 1, 0), 1124 WM2200_IN1_OSR_SHIFT, 1, 0),
@@ -1126,9 +1136,9 @@ SOC_DOUBLE_R_TLV("IN3 Volume", WM2200_IN3L_CONTROL, WM2200_IN3R_CONTROL,
1126 1136
1127SOC_DOUBLE_R("IN1 Digital Switch", WM2200_ADC_DIGITAL_VOLUME_1L, 1137SOC_DOUBLE_R("IN1 Digital Switch", WM2200_ADC_DIGITAL_VOLUME_1L,
1128 WM2200_ADC_DIGITAL_VOLUME_1R, WM2200_IN1L_MUTE_SHIFT, 1, 1), 1138 WM2200_ADC_DIGITAL_VOLUME_1R, WM2200_IN1L_MUTE_SHIFT, 1, 1),
1129SOC_DOUBLE_R("IN2 Digital Switch", WM2200_ADC_DIGITAL_VOLUME_1L, 1139SOC_DOUBLE_R("IN2 Digital Switch", WM2200_ADC_DIGITAL_VOLUME_2L,
1130 WM2200_ADC_DIGITAL_VOLUME_2R, WM2200_IN2L_MUTE_SHIFT, 1, 1), 1140 WM2200_ADC_DIGITAL_VOLUME_2R, WM2200_IN2L_MUTE_SHIFT, 1, 1),
1131SOC_DOUBLE_R("IN3 Digital Switch", WM2200_ADC_DIGITAL_VOLUME_1L, 1141SOC_DOUBLE_R("IN3 Digital Switch", WM2200_ADC_DIGITAL_VOLUME_3L,
1132 WM2200_ADC_DIGITAL_VOLUME_3R, WM2200_IN3L_MUTE_SHIFT, 1, 1), 1142 WM2200_ADC_DIGITAL_VOLUME_3R, WM2200_IN3L_MUTE_SHIFT, 1, 1),
1133 1143
1134SOC_DOUBLE_R_TLV("IN1 Digital Volume", WM2200_ADC_DIGITAL_VOLUME_1L, 1144SOC_DOUBLE_R_TLV("IN1 Digital Volume", WM2200_ADC_DIGITAL_VOLUME_1L,
@@ -1141,6 +1151,12 @@ SOC_DOUBLE_R_TLV("IN3 Digital Volume", WM2200_ADC_DIGITAL_VOLUME_3L,
1141 WM2200_ADC_DIGITAL_VOLUME_3R, WM2200_IN3L_DIG_VOL_SHIFT, 1151 WM2200_ADC_DIGITAL_VOLUME_3R, WM2200_IN3L_DIG_VOL_SHIFT,
1142 0xbf, 0, digital_tlv), 1152 0xbf, 0, digital_tlv),
1143 1153
1154SND_SOC_BYTES_MASK("EQL Coefficients", WM2200_EQL_1, 20, WM2200_EQL_ENA),
1155SND_SOC_BYTES_MASK("EQR Coefficients", WM2200_EQR_1, 20, WM2200_EQR_ENA),
1156
1157SND_SOC_BYTES("LHPF1 Coefficeints", WM2200_HPLPF1_2, 1),
1158SND_SOC_BYTES("LHPF2 Coefficeints", WM2200_HPLPF2_2, 1),
1159
1144SOC_SINGLE("OUT1 High Performance Switch", WM2200_DAC_DIGITAL_VOLUME_1L, 1160SOC_SINGLE("OUT1 High Performance Switch", WM2200_DAC_DIGITAL_VOLUME_1L,
1145 WM2200_OUT1_OSR_SHIFT, 1, 0), 1161 WM2200_OUT1_OSR_SHIFT, 1, 0),
1146SOC_SINGLE("OUT2 High Performance Switch", WM2200_DAC_DIGITAL_VOLUME_2L, 1162SOC_SINGLE("OUT2 High Performance Switch", WM2200_DAC_DIGITAL_VOLUME_2L,
@@ -1162,6 +1178,7 @@ SOC_DOUBLE_R_TLV("OUT2 Digital Volume", WM2200_DAC_DIGITAL_VOLUME_2L,
1162 digital_tlv), 1178 digital_tlv),
1163SOC_DOUBLE("OUT2 Switch", WM2200_PDM_1, WM2200_SPK1L_MUTE_SHIFT, 1179SOC_DOUBLE("OUT2 Switch", WM2200_PDM_1, WM2200_SPK1L_MUTE_SHIFT,
1164 WM2200_SPK1R_MUTE_SHIFT, 1, 1), 1180 WM2200_SPK1R_MUTE_SHIFT, 1, 1),
1181SOC_ENUM("RxANC Src", wm2200_rxanc_input_sel),
1165}; 1182};
1166 1183
1167WM2200_MIXER_ENUMS(OUT1L, WM2200_OUT1LMIX_INPUT_1_SOURCE); 1184WM2200_MIXER_ENUMS(OUT1L, WM2200_OUT1LMIX_INPUT_1_SOURCE);
@@ -1548,6 +1565,10 @@ static int wm2200_probe(struct snd_soc_codec *codec)
1548 return ret; 1565 return ret;
1549 } 1566 }
1550 1567
1568 ret = snd_soc_add_codec_controls(codec, wm_adsp_fw_controls, 2);
1569 if (ret != 0)
1570 return ret;
1571
1551 return ret; 1572 return ret;
1552} 1573}
1553 1574
@@ -2182,6 +2203,7 @@ static int wm2200_i2c_probe(struct i2c_client *i2c,
2182 struct wm2200_priv *wm2200; 2203 struct wm2200_priv *wm2200;
2183 unsigned int reg; 2204 unsigned int reg;
2184 int ret, i; 2205 int ret, i;
2206 int val;
2185 2207
2186 wm2200 = devm_kzalloc(&i2c->dev, sizeof(struct wm2200_priv), 2208 wm2200 = devm_kzalloc(&i2c->dev, sizeof(struct wm2200_priv),
2187 GFP_KERNEL); 2209 GFP_KERNEL);
@@ -2205,6 +2227,9 @@ static int wm2200_i2c_probe(struct i2c_client *i2c,
2205 wm2200->dsp[i].num = i + 1; 2227 wm2200->dsp[i].num = i + 1;
2206 wm2200->dsp[i].dev = &i2c->dev; 2228 wm2200->dsp[i].dev = &i2c->dev;
2207 wm2200->dsp[i].regmap = wm2200->regmap; 2229 wm2200->dsp[i].regmap = wm2200->regmap;
2230 wm2200->dsp[i].sysclk_reg = WM2200_CLOCKING_3;
2231 wm2200->dsp[i].sysclk_mask = WM2200_SYSCLK_FREQ_MASK;
2232 wm2200->dsp[i].sysclk_shift = WM2200_SYSCLK_FREQ_SHIFT;
2208 } 2233 }
2209 2234
2210 wm2200->dsp[0].base = WM2200_DSP1_CONTROL_1; 2235 wm2200->dsp[0].base = WM2200_DSP1_CONTROL_1;
@@ -2215,6 +2240,9 @@ static int wm2200_i2c_probe(struct i2c_client *i2c,
2215 wm2200->dsp[1].mem = wm2200_dsp2_regions; 2240 wm2200->dsp[1].mem = wm2200_dsp2_regions;
2216 wm2200->dsp[1].num_mems = ARRAY_SIZE(wm2200_dsp2_regions); 2241 wm2200->dsp[1].num_mems = ARRAY_SIZE(wm2200_dsp2_regions);
2217 2242
2243 for (i = 0; i < ARRAY_SIZE(wm2200->dsp); i++)
2244 wm_adsp1_init(&wm2200->dsp[i]);
2245
2218 if (pdata) 2246 if (pdata)
2219 wm2200->pdata = *pdata; 2247 wm2200->pdata = *pdata;
2220 2248
@@ -2326,6 +2354,36 @@ static int wm2200_i2c_probe(struct i2c_client *i2c,
2326 regmap_write(wm2200->regmap, WM2200_AUDIO_IF_1_16 + i, i); 2354 regmap_write(wm2200->regmap, WM2200_AUDIO_IF_1_16 + i, i);
2327 } 2355 }
2328 2356
2357 for (i = 0; i < WM2200_MAX_MICBIAS; i++) {
2358 if (!wm2200->pdata.micbias[i].mb_lvl &&
2359 !wm2200->pdata.micbias[i].bypass)
2360 continue;
2361
2362 /* Apply default for bypass mode */
2363 if (!wm2200->pdata.micbias[i].mb_lvl)
2364 wm2200->pdata.micbias[i].mb_lvl
2365 = WM2200_MBIAS_LVL_1V5;
2366
2367 val = (wm2200->pdata.micbias[i].mb_lvl -1)
2368 << WM2200_MICB1_LVL_SHIFT;
2369
2370 if (wm2200->pdata.micbias[i].discharge)
2371 val |= WM2200_MICB1_DISCH;
2372
2373 if (wm2200->pdata.micbias[i].fast_start)
2374 val |= WM2200_MICB1_RATE;
2375
2376 if (wm2200->pdata.micbias[i].bypass)
2377 val |= WM2200_MICB1_MODE;
2378
2379 regmap_update_bits(wm2200->regmap,
2380 WM2200_MIC_BIAS_CTRL_1 + i,
2381 WM2200_MICB1_LVL_MASK |
2382 WM2200_MICB1_DISCH |
2383 WM2200_MICB1_MODE |
2384 WM2200_MICB1_RATE, val);
2385 }
2386
2329 for (i = 0; i < ARRAY_SIZE(wm2200->pdata.in_mode); i++) { 2387 for (i = 0; i < ARRAY_SIZE(wm2200->pdata.in_mode); i++) {
2330 regmap_update_bits(wm2200->regmap, wm2200_mic_ctrl_reg[i], 2388 regmap_update_bits(wm2200->regmap, wm2200_mic_ctrl_reg[i],
2331 WM2200_IN1_MODE_MASK | 2389 WM2200_IN1_MODE_MASK |
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c
index 54397a508073..ac1745d030d6 100644
--- a/sound/soc/codecs/wm5100.c
+++ b/sound/soc/codecs/wm5100.c
@@ -563,6 +563,19 @@ SOC_DOUBLE_R("IN3 Switch", WM5100_ADC_DIGITAL_VOLUME_3L,
563SOC_DOUBLE_R("IN4 Switch", WM5100_ADC_DIGITAL_VOLUME_4L, 563SOC_DOUBLE_R("IN4 Switch", WM5100_ADC_DIGITAL_VOLUME_4L,
564 WM5100_ADC_DIGITAL_VOLUME_4R, WM5100_IN4L_MUTE_SHIFT, 1, 1), 564 WM5100_ADC_DIGITAL_VOLUME_4R, WM5100_IN4L_MUTE_SHIFT, 1, 1),
565 565
566SND_SOC_BYTES_MASK("EQ1 Coefficients", WM5100_EQ1_1, 20, WM5100_EQ1_ENA),
567SND_SOC_BYTES_MASK("EQ2 Coefficients", WM5100_EQ2_1, 20, WM5100_EQ2_ENA),
568SND_SOC_BYTES_MASK("EQ3 Coefficients", WM5100_EQ3_1, 20, WM5100_EQ3_ENA),
569SND_SOC_BYTES_MASK("EQ4 Coefficients", WM5100_EQ4_1, 20, WM5100_EQ4_ENA),
570
571SND_SOC_BYTES_MASK("DRC Coefficients", WM5100_DRC1_CTRL1, 5,
572 WM5100_DRCL_ENA | WM5100_DRCR_ENA),
573
574SND_SOC_BYTES("LHPF1 Coefficeints", WM5100_HPLPF1_2, 1),
575SND_SOC_BYTES("LHPF2 Coefficeints", WM5100_HPLPF2_2, 1),
576SND_SOC_BYTES("LHPF3 Coefficeints", WM5100_HPLPF3_2, 1),
577SND_SOC_BYTES("LHPF4 Coefficeints", WM5100_HPLPF4_2, 1),
578
566SOC_SINGLE("HPOUT1 High Performance Switch", WM5100_OUT_VOLUME_1L, 579SOC_SINGLE("HPOUT1 High Performance Switch", WM5100_OUT_VOLUME_1L,
567 WM5100_OUT1_OSR_SHIFT, 1, 0), 580 WM5100_OUT1_OSR_SHIFT, 1, 0),
568SOC_SINGLE("HPOUT2 High Performance Switch", WM5100_OUT_VOLUME_2L, 581SOC_SINGLE("HPOUT2 High Performance Switch", WM5100_OUT_VOLUME_2L,
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index 988e817dca05..b8d461db369f 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -45,6 +45,7 @@ static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0);
45static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 45static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
46static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0); 46static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0);
47static DECLARE_TLV_DB_SCALE(noise_tlv, 0, 600, 0); 47static DECLARE_TLV_DB_SCALE(noise_tlv, 0, 600, 0);
48static DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
48 49
49static const struct wm_adsp_region wm5102_dsp1_regions[] = { 50static const struct wm_adsp_region wm5102_dsp1_regions[] = {
50 { .type = WMFW_ADSP2_PM, .base = 0x100000 }, 51 { .type = WMFW_ADSP2_PM, .base = 0x100000 },
@@ -603,6 +604,17 @@ static int wm5102_sysclk_ev(struct snd_soc_dapm_widget *w,
603 return 0; 604 return 0;
604} 605}
605 606
607#define WM5102_NG_SRC(name, base) \
608 SOC_SINGLE(name " NG HPOUT1L Switch", base, 0, 1, 0), \
609 SOC_SINGLE(name " NG HPOUT1R Switch", base, 1, 1, 0), \
610 SOC_SINGLE(name " NG HPOUT2L Switch", base, 2, 1, 0), \
611 SOC_SINGLE(name " NG HPOUT2R Switch", base, 3, 1, 0), \
612 SOC_SINGLE(name " NG EPOUT Switch", base, 4, 1, 0), \
613 SOC_SINGLE(name " NG SPKOUTL Switch", base, 6, 1, 0), \
614 SOC_SINGLE(name " NG SPKOUTR Switch", base, 7, 1, 0), \
615 SOC_SINGLE(name " NG SPKDAT1L Switch", base, 8, 1, 0), \
616 SOC_SINGLE(name " NG SPKDAT1R Switch", base, 9, 1, 0)
617
606static const struct snd_kcontrol_new wm5102_snd_controls[] = { 618static const struct snd_kcontrol_new wm5102_snd_controls[] = {
607SOC_SINGLE("IN1 High Performance Switch", ARIZONA_IN1L_CONTROL, 619SOC_SINGLE("IN1 High Performance Switch", ARIZONA_IN1L_CONTROL,
608 ARIZONA_IN1_OSR_SHIFT, 1, 0), 620 ARIZONA_IN1_OSR_SHIFT, 1, 0),
@@ -611,32 +623,31 @@ SOC_SINGLE("IN2 High Performance Switch", ARIZONA_IN2L_CONTROL,
611SOC_SINGLE("IN3 High Performance Switch", ARIZONA_IN3L_CONTROL, 623SOC_SINGLE("IN3 High Performance Switch", ARIZONA_IN3L_CONTROL,
612 ARIZONA_IN3_OSR_SHIFT, 1, 0), 624 ARIZONA_IN3_OSR_SHIFT, 1, 0),
613 625
614SOC_DOUBLE_R_RANGE_TLV("IN1 Volume", ARIZONA_IN1L_CONTROL, 626SOC_SINGLE_RANGE_TLV("IN1L Volume", ARIZONA_IN1L_CONTROL,
615 ARIZONA_IN1R_CONTROL, 627 ARIZONA_IN1L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
616 ARIZONA_IN1L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 628SOC_SINGLE_RANGE_TLV("IN1R Volume", ARIZONA_IN1R_CONTROL,
617SOC_DOUBLE_R_RANGE_TLV("IN2 Volume", ARIZONA_IN2L_CONTROL, 629 ARIZONA_IN1R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
618 ARIZONA_IN2R_CONTROL, 630SOC_SINGLE_RANGE_TLV("IN2L Volume", ARIZONA_IN2L_CONTROL,
619 ARIZONA_IN2L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 631 ARIZONA_IN2L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
620SOC_DOUBLE_R_RANGE_TLV("IN3 Volume", ARIZONA_IN3L_CONTROL, 632SOC_SINGLE_RANGE_TLV("IN2R Volume", ARIZONA_IN2R_CONTROL,
621 ARIZONA_IN3R_CONTROL, 633 ARIZONA_IN2R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
622 ARIZONA_IN3L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 634SOC_SINGLE_RANGE_TLV("IN3L Volume", ARIZONA_IN3L_CONTROL,
623 635 ARIZONA_IN3L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
624SOC_DOUBLE_R("IN1 Digital Switch", ARIZONA_ADC_DIGITAL_VOLUME_1L, 636SOC_SINGLE_RANGE_TLV("IN3R Volume", ARIZONA_IN3R_CONTROL,
625 ARIZONA_ADC_DIGITAL_VOLUME_1R, ARIZONA_IN1L_MUTE_SHIFT, 1, 1), 637 ARIZONA_IN3R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
626SOC_DOUBLE_R("IN2 Digital Switch", ARIZONA_ADC_DIGITAL_VOLUME_2L, 638
627 ARIZONA_ADC_DIGITAL_VOLUME_2R, ARIZONA_IN2L_MUTE_SHIFT, 1, 1), 639SOC_SINGLE_TLV("IN1L Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_1L,
628SOC_DOUBLE_R("IN3 Digital Switch", ARIZONA_ADC_DIGITAL_VOLUME_3L, 640 ARIZONA_IN1L_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
629 ARIZONA_ADC_DIGITAL_VOLUME_3R, ARIZONA_IN3L_MUTE_SHIFT, 1, 1), 641SOC_SINGLE_TLV("IN1R Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_1R,
630 642 ARIZONA_IN1R_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
631SOC_DOUBLE_R_TLV("IN1 Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_1L, 643SOC_SINGLE_TLV("IN2L Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_2L,
632 ARIZONA_ADC_DIGITAL_VOLUME_1R, ARIZONA_IN1L_DIG_VOL_SHIFT, 644 ARIZONA_IN2L_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
633 0xbf, 0, digital_tlv), 645SOC_SINGLE_TLV("IN2R Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_2R,
634SOC_DOUBLE_R_TLV("IN2 Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_2L, 646 ARIZONA_IN2R_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
635 ARIZONA_ADC_DIGITAL_VOLUME_2R, ARIZONA_IN2L_DIG_VOL_SHIFT, 647SOC_SINGLE_TLV("IN3L Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_3L,
636 0xbf, 0, digital_tlv), 648 ARIZONA_IN3L_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
637SOC_DOUBLE_R_TLV("IN3 Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_3L, 649SOC_SINGLE_TLV("IN3R Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_3R,
638 ARIZONA_ADC_DIGITAL_VOLUME_3R, ARIZONA_IN3L_DIG_VOL_SHIFT, 650 ARIZONA_IN3R_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
639 0xbf, 0, digital_tlv),
640 651
641SOC_ENUM("Input Ramp Up", arizona_in_vi_ramp), 652SOC_ENUM("Input Ramp Up", arizona_in_vi_ramp),
642SOC_ENUM("Input Ramp Down", arizona_in_vd_ramp), 653SOC_ENUM("Input Ramp Down", arizona_in_vd_ramp),
@@ -774,6 +785,22 @@ SOC_ENUM("Output Ramp Down", arizona_out_vd_ramp),
774SOC_DOUBLE("SPKDAT1 Switch", ARIZONA_PDM_SPK1_CTRL_1, ARIZONA_SPK1L_MUTE_SHIFT, 785SOC_DOUBLE("SPKDAT1 Switch", ARIZONA_PDM_SPK1_CTRL_1, ARIZONA_SPK1L_MUTE_SHIFT,
775 ARIZONA_SPK1R_MUTE_SHIFT, 1, 1), 786 ARIZONA_SPK1R_MUTE_SHIFT, 1, 1),
776 787
788SOC_SINGLE("Noise Gate Switch", ARIZONA_NOISE_GATE_CONTROL,
789 ARIZONA_NGATE_ENA_SHIFT, 1, 0),
790SOC_SINGLE_TLV("Noise Gate Threshold Volume", ARIZONA_NOISE_GATE_CONTROL,
791 ARIZONA_NGATE_THR_SHIFT, 7, 1, ng_tlv),
792SOC_ENUM("Noise Gate Hold", arizona_ng_hold),
793
794WM5102_NG_SRC("HPOUT1L", ARIZONA_NOISE_GATE_SELECT_1L),
795WM5102_NG_SRC("HPOUT1R", ARIZONA_NOISE_GATE_SELECT_1R),
796WM5102_NG_SRC("HPOUT2L", ARIZONA_NOISE_GATE_SELECT_2L),
797WM5102_NG_SRC("HPOUT2R", ARIZONA_NOISE_GATE_SELECT_2R),
798WM5102_NG_SRC("EPOUT", ARIZONA_NOISE_GATE_SELECT_3L),
799WM5102_NG_SRC("SPKOUTL", ARIZONA_NOISE_GATE_SELECT_4L),
800WM5102_NG_SRC("SPKOUTR", ARIZONA_NOISE_GATE_SELECT_4R),
801WM5102_NG_SRC("SPKDAT1L", ARIZONA_NOISE_GATE_SELECT_5L),
802WM5102_NG_SRC("SPKDAT1R", ARIZONA_NOISE_GATE_SELECT_5R),
803
777ARIZONA_MIXER_CONTROLS("AIF1TX1", ARIZONA_AIF1TX1MIX_INPUT_1_SOURCE), 804ARIZONA_MIXER_CONTROLS("AIF1TX1", ARIZONA_AIF1TX1MIX_INPUT_1_SOURCE),
778ARIZONA_MIXER_CONTROLS("AIF1TX2", ARIZONA_AIF1TX2MIX_INPUT_1_SOURCE), 805ARIZONA_MIXER_CONTROLS("AIF1TX2", ARIZONA_AIF1TX2MIX_INPUT_1_SOURCE),
779ARIZONA_MIXER_CONTROLS("AIF1TX3", ARIZONA_AIF1TX3MIX_INPUT_1_SOURCE), 806ARIZONA_MIXER_CONTROLS("AIF1TX3", ARIZONA_AIF1TX3MIX_INPUT_1_SOURCE),
@@ -880,6 +907,18 @@ ARIZONA_MUX_ENUMS(ASRC1R, ARIZONA_ASRC1RMIX_INPUT_1_SOURCE);
880ARIZONA_MUX_ENUMS(ASRC2L, ARIZONA_ASRC2LMIX_INPUT_1_SOURCE); 907ARIZONA_MUX_ENUMS(ASRC2L, ARIZONA_ASRC2LMIX_INPUT_1_SOURCE);
881ARIZONA_MUX_ENUMS(ASRC2R, ARIZONA_ASRC2RMIX_INPUT_1_SOURCE); 908ARIZONA_MUX_ENUMS(ASRC2R, ARIZONA_ASRC2RMIX_INPUT_1_SOURCE);
882 909
910ARIZONA_MUX_ENUMS(ISRC1INT1, ARIZONA_ISRC1INT1MIX_INPUT_1_SOURCE);
911ARIZONA_MUX_ENUMS(ISRC1INT2, ARIZONA_ISRC1INT2MIX_INPUT_1_SOURCE);
912
913ARIZONA_MUX_ENUMS(ISRC1DEC1, ARIZONA_ISRC1DEC1MIX_INPUT_1_SOURCE);
914ARIZONA_MUX_ENUMS(ISRC1DEC2, ARIZONA_ISRC1DEC2MIX_INPUT_1_SOURCE);
915
916ARIZONA_MUX_ENUMS(ISRC2INT1, ARIZONA_ISRC2INT1MIX_INPUT_1_SOURCE);
917ARIZONA_MUX_ENUMS(ISRC2INT2, ARIZONA_ISRC2INT2MIX_INPUT_1_SOURCE);
918
919ARIZONA_MUX_ENUMS(ISRC2DEC1, ARIZONA_ISRC2DEC1MIX_INPUT_1_SOURCE);
920ARIZONA_MUX_ENUMS(ISRC2DEC2, ARIZONA_ISRC2DEC2MIX_INPUT_1_SOURCE);
921
883ARIZONA_MIXER_ENUMS(DSP1L, ARIZONA_DSP1LMIX_INPUT_1_SOURCE); 922ARIZONA_MIXER_ENUMS(DSP1L, ARIZONA_DSP1LMIX_INPUT_1_SOURCE);
884ARIZONA_MIXER_ENUMS(DSP1R, ARIZONA_DSP1RMIX_INPUT_1_SOURCE); 923ARIZONA_MIXER_ENUMS(DSP1R, ARIZONA_DSP1RMIX_INPUT_1_SOURCE);
885 924
@@ -1002,6 +1041,26 @@ SND_SOC_DAPM_PGA("ASRC2L", ARIZONA_ASRC_ENABLE, ARIZONA_ASRC2L_ENA_SHIFT, 0,
1002SND_SOC_DAPM_PGA("ASRC2R", ARIZONA_ASRC_ENABLE, ARIZONA_ASRC2R_ENA_SHIFT, 0, 1041SND_SOC_DAPM_PGA("ASRC2R", ARIZONA_ASRC_ENABLE, ARIZONA_ASRC2R_ENA_SHIFT, 0,
1003 NULL, 0), 1042 NULL, 0),
1004 1043
1044SND_SOC_DAPM_PGA("ISRC1INT1", ARIZONA_ISRC_1_CTRL_3,
1045 ARIZONA_ISRC1_INT0_ENA_SHIFT, 0, NULL, 0),
1046SND_SOC_DAPM_PGA("ISRC1INT2", ARIZONA_ISRC_1_CTRL_3,
1047 ARIZONA_ISRC1_INT1_ENA_SHIFT, 0, NULL, 0),
1048
1049SND_SOC_DAPM_PGA("ISRC1DEC1", ARIZONA_ISRC_1_CTRL_3,
1050 ARIZONA_ISRC1_DEC0_ENA_SHIFT, 0, NULL, 0),
1051SND_SOC_DAPM_PGA("ISRC1DEC2", ARIZONA_ISRC_1_CTRL_3,
1052 ARIZONA_ISRC1_DEC1_ENA_SHIFT, 0, NULL, 0),
1053
1054SND_SOC_DAPM_PGA("ISRC2INT1", ARIZONA_ISRC_2_CTRL_3,
1055 ARIZONA_ISRC2_INT0_ENA_SHIFT, 0, NULL, 0),
1056SND_SOC_DAPM_PGA("ISRC2INT2", ARIZONA_ISRC_2_CTRL_3,
1057 ARIZONA_ISRC2_INT1_ENA_SHIFT, 0, NULL, 0),
1058
1059SND_SOC_DAPM_PGA("ISRC2DEC1", ARIZONA_ISRC_2_CTRL_3,
1060 ARIZONA_ISRC2_DEC0_ENA_SHIFT, 0, NULL, 0),
1061SND_SOC_DAPM_PGA("ISRC2DEC2", ARIZONA_ISRC_2_CTRL_3,
1062 ARIZONA_ISRC2_DEC1_ENA_SHIFT, 0, NULL, 0),
1063
1005SND_SOC_DAPM_AIF_OUT("AIF1TX1", NULL, 0, 1064SND_SOC_DAPM_AIF_OUT("AIF1TX1", NULL, 0,
1006 ARIZONA_AIF1_TX_ENABLES, ARIZONA_AIF1TX1_ENA_SHIFT, 0), 1065 ARIZONA_AIF1_TX_ENABLES, ARIZONA_AIF1TX1_ENA_SHIFT, 0),
1007SND_SOC_DAPM_AIF_OUT("AIF1TX2", NULL, 0, 1066SND_SOC_DAPM_AIF_OUT("AIF1TX2", NULL, 0,
@@ -1138,6 +1197,18 @@ ARIZONA_MUX_WIDGETS(ASRC1R, "ASRC1R"),
1138ARIZONA_MUX_WIDGETS(ASRC2L, "ASRC2L"), 1197ARIZONA_MUX_WIDGETS(ASRC2L, "ASRC2L"),
1139ARIZONA_MUX_WIDGETS(ASRC2R, "ASRC2R"), 1198ARIZONA_MUX_WIDGETS(ASRC2R, "ASRC2R"),
1140 1199
1200ARIZONA_MUX_WIDGETS(ISRC1DEC1, "ISRC1DEC1"),
1201ARIZONA_MUX_WIDGETS(ISRC1DEC2, "ISRC1DEC2"),
1202
1203ARIZONA_MUX_WIDGETS(ISRC1INT1, "ISRC1INT1"),
1204ARIZONA_MUX_WIDGETS(ISRC1INT2, "ISRC1INT2"),
1205
1206ARIZONA_MUX_WIDGETS(ISRC2DEC1, "ISRC2DEC1"),
1207ARIZONA_MUX_WIDGETS(ISRC2DEC2, "ISRC2DEC2"),
1208
1209ARIZONA_MUX_WIDGETS(ISRC2INT1, "ISRC2INT1"),
1210ARIZONA_MUX_WIDGETS(ISRC2INT2, "ISRC2INT2"),
1211
1141WM_ADSP2("DSP1", 0), 1212WM_ADSP2("DSP1", 0),
1142 1213
1143SND_SOC_DAPM_OUTPUT("HPOUT1L"), 1214SND_SOC_DAPM_OUTPUT("HPOUT1L"),
@@ -1195,6 +1266,14 @@ SND_SOC_DAPM_OUTPUT("MICSUPP"),
1195 { name, "ASRC1R", "ASRC1R" }, \ 1266 { name, "ASRC1R", "ASRC1R" }, \
1196 { name, "ASRC2L", "ASRC2L" }, \ 1267 { name, "ASRC2L", "ASRC2L" }, \
1197 { name, "ASRC2R", "ASRC2R" }, \ 1268 { name, "ASRC2R", "ASRC2R" }, \
1269 { name, "ISRC1DEC1", "ISRC1DEC1" }, \
1270 { name, "ISRC1DEC2", "ISRC1DEC2" }, \
1271 { name, "ISRC1INT1", "ISRC1INT1" }, \
1272 { name, "ISRC1INT2", "ISRC1INT2" }, \
1273 { name, "ISRC2DEC1", "ISRC2DEC1" }, \
1274 { name, "ISRC2DEC2", "ISRC2DEC2" }, \
1275 { name, "ISRC2INT1", "ISRC2INT1" }, \
1276 { name, "ISRC2INT2", "ISRC2INT2" }, \
1198 { name, "DSP1.1", "DSP1" }, \ 1277 { name, "DSP1.1", "DSP1" }, \
1199 { name, "DSP1.2", "DSP1" }, \ 1278 { name, "DSP1.2", "DSP1" }, \
1200 { name, "DSP1.3", "DSP1" }, \ 1279 { name, "DSP1.3", "DSP1" }, \
@@ -1291,6 +1370,18 @@ static const struct snd_soc_dapm_route wm5102_dapm_routes[] = {
1291 { "ASRC2L", NULL, "ASRC2L Input" }, 1370 { "ASRC2L", NULL, "ASRC2L Input" },
1292 { "ASRC2R", NULL, "ASRC2R Input" }, 1371 { "ASRC2R", NULL, "ASRC2R Input" },
1293 1372
1373 { "ISRC1DEC1", NULL, "ISRC1DEC1 Input" },
1374 { "ISRC1DEC2", NULL, "ISRC1DEC2 Input" },
1375
1376 { "ISRC1INT1", NULL, "ISRC1INT1 Input" },
1377 { "ISRC1INT2", NULL, "ISRC1INT2 Input" },
1378
1379 { "ISRC2DEC1", NULL, "ISRC2DEC1 Input" },
1380 { "ISRC2DEC2", NULL, "ISRC2DEC2 Input" },
1381
1382 { "ISRC2INT1", NULL, "ISRC2INT1 Input" },
1383 { "ISRC2INT2", NULL, "ISRC2INT2 Input" },
1384
1294 ARIZONA_MIXER_ROUTES("OUT1L", "HPOUT1L"), 1385 ARIZONA_MIXER_ROUTES("OUT1L", "HPOUT1L"),
1295 ARIZONA_MIXER_ROUTES("OUT1R", "HPOUT1R"), 1386 ARIZONA_MIXER_ROUTES("OUT1R", "HPOUT1R"),
1296 ARIZONA_MIXER_ROUTES("OUT2L", "HPOUT2L"), 1387 ARIZONA_MIXER_ROUTES("OUT2L", "HPOUT2L"),
@@ -1338,6 +1429,18 @@ static const struct snd_soc_dapm_route wm5102_dapm_routes[] = {
1338 ARIZONA_MUX_ROUTES("ASRC2L"), 1429 ARIZONA_MUX_ROUTES("ASRC2L"),
1339 ARIZONA_MUX_ROUTES("ASRC2R"), 1430 ARIZONA_MUX_ROUTES("ASRC2R"),
1340 1431
1432 ARIZONA_MUX_ROUTES("ISRC1INT1"),
1433 ARIZONA_MUX_ROUTES("ISRC1INT2"),
1434
1435 ARIZONA_MUX_ROUTES("ISRC1DEC1"),
1436 ARIZONA_MUX_ROUTES("ISRC1DEC2"),
1437
1438 ARIZONA_MUX_ROUTES("ISRC2INT1"),
1439 ARIZONA_MUX_ROUTES("ISRC2INT2"),
1440
1441 ARIZONA_MUX_ROUTES("ISRC2DEC1"),
1442 ARIZONA_MUX_ROUTES("ISRC2DEC2"),
1443
1341 ARIZONA_DSP_ROUTES("DSP1"), 1444 ARIZONA_DSP_ROUTES("DSP1"),
1342 1445
1343 { "AEC Loopback", "HPOUT1L", "OUT1L" }, 1446 { "AEC Loopback", "HPOUT1L", "OUT1L" },
@@ -1467,6 +1570,10 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
1467 if (ret != 0) 1570 if (ret != 0)
1468 return ret; 1571 return ret;
1469 1572
1573 ret = snd_soc_add_codec_controls(codec, wm_adsp_fw_controls, 1);
1574 if (ret != 0)
1575 return ret;
1576
1470 snd_soc_dapm_disable_pin(&codec->dapm, "HAPTICS"); 1577 snd_soc_dapm_disable_pin(&codec->dapm, "HAPTICS");
1471 1578
1472 priv->core.arizona->dapm = &codec->dapm; 1579 priv->core.arizona->dapm = &codec->dapm;
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index 0320a32670d3..cd17b477781d 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -41,6 +41,21 @@ static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0);
41static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 41static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
42static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0); 42static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0);
43static DECLARE_TLV_DB_SCALE(noise_tlv, 0, 600, 0); 43static DECLARE_TLV_DB_SCALE(noise_tlv, 0, 600, 0);
44static DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
45
46#define WM5110_NG_SRC(name, base) \
47 SOC_SINGLE(name " NG HPOUT1L Switch", base, 0, 1, 0), \
48 SOC_SINGLE(name " NG HPOUT1R Switch", base, 1, 1, 0), \
49 SOC_SINGLE(name " NG HPOUT2L Switch", base, 2, 1, 0), \
50 SOC_SINGLE(name " NG HPOUT2R Switch", base, 3, 1, 0), \
51 SOC_SINGLE(name " NG HPOUT3L Switch", base, 4, 1, 0), \
52 SOC_SINGLE(name " NG HPOUT3R Switch", base, 5, 1, 0), \
53 SOC_SINGLE(name " NG SPKOUTL Switch", base, 6, 1, 0), \
54 SOC_SINGLE(name " NG SPKOUTR Switch", base, 7, 1, 0), \
55 SOC_SINGLE(name " NG SPKDAT1L Switch", base, 8, 1, 0), \
56 SOC_SINGLE(name " NG SPKDAT1R Switch", base, 9, 1, 0), \
57 SOC_SINGLE(name " NG SPKDAT2L Switch", base, 10, 1, 0), \
58 SOC_SINGLE(name " NG SPKDAT2R Switch", base, 11, 1, 0)
44 59
45static const struct snd_kcontrol_new wm5110_snd_controls[] = { 60static const struct snd_kcontrol_new wm5110_snd_controls[] = {
46SOC_SINGLE("IN1 High Performance Switch", ARIZONA_IN1L_CONTROL, 61SOC_SINGLE("IN1 High Performance Switch", ARIZONA_IN1L_CONTROL,
@@ -52,37 +67,35 @@ SOC_SINGLE("IN3 High Performance Switch", ARIZONA_IN3L_CONTROL,
52SOC_SINGLE("IN4 High Performance Switch", ARIZONA_IN4L_CONTROL, 67SOC_SINGLE("IN4 High Performance Switch", ARIZONA_IN4L_CONTROL,
53 ARIZONA_IN4_OSR_SHIFT, 1, 0), 68 ARIZONA_IN4_OSR_SHIFT, 1, 0),
54 69
55SOC_DOUBLE_R_RANGE_TLV("IN1 Volume", ARIZONA_IN1L_CONTROL, 70SOC_SINGLE_RANGE_TLV("IN1L Volume", ARIZONA_IN1L_CONTROL,
56 ARIZONA_IN1R_CONTROL, 71 ARIZONA_IN1L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
57 ARIZONA_IN1L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 72SOC_SINGLE_RANGE_TLV("IN1R Volume", ARIZONA_IN1R_CONTROL,
58SOC_DOUBLE_R_RANGE_TLV("IN2 Volume", ARIZONA_IN2L_CONTROL, 73 ARIZONA_IN1R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
59 ARIZONA_IN2R_CONTROL, 74SOC_SINGLE_RANGE_TLV("IN2L Volume", ARIZONA_IN2L_CONTROL,
60 ARIZONA_IN2L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 75 ARIZONA_IN2L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
61SOC_DOUBLE_R_RANGE_TLV("IN3 Volume", ARIZONA_IN3L_CONTROL, 76SOC_SINGLE_RANGE_TLV("IN2R Volume", ARIZONA_IN2R_CONTROL,
62 ARIZONA_IN3R_CONTROL, 77 ARIZONA_IN2R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
63 ARIZONA_IN3L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 78SOC_SINGLE_RANGE_TLV("IN3L Volume", ARIZONA_IN3L_CONTROL,
64 79 ARIZONA_IN3L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
65SOC_DOUBLE_R("IN1 Digital Switch", ARIZONA_ADC_DIGITAL_VOLUME_1L, 80SOC_SINGLE_RANGE_TLV("IN3R Volume", ARIZONA_IN3R_CONTROL,
66 ARIZONA_ADC_DIGITAL_VOLUME_1R, ARIZONA_IN1L_MUTE_SHIFT, 1, 1), 81 ARIZONA_IN3R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv),
67SOC_DOUBLE_R("IN2 Digital Switch", ARIZONA_ADC_DIGITAL_VOLUME_2L, 82
68 ARIZONA_ADC_DIGITAL_VOLUME_2R, ARIZONA_IN2L_MUTE_SHIFT, 1, 1), 83SOC_SINGLE_TLV("IN1L Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_1L,
69SOC_DOUBLE_R("IN3 Digital Switch", ARIZONA_ADC_DIGITAL_VOLUME_3L, 84 ARIZONA_IN1L_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
70 ARIZONA_ADC_DIGITAL_VOLUME_3R, ARIZONA_IN3L_MUTE_SHIFT, 1, 1), 85SOC_SINGLE_TLV("IN1R Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_1R,
71SOC_DOUBLE_R("IN4 Digital Switch", ARIZONA_ADC_DIGITAL_VOLUME_4L, 86 ARIZONA_IN1R_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
72 ARIZONA_ADC_DIGITAL_VOLUME_4R, ARIZONA_IN4L_MUTE_SHIFT, 1, 1), 87SOC_SINGLE_TLV("IN2L Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_2L,
73 88 ARIZONA_IN2L_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
74SOC_DOUBLE_R_TLV("IN1 Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_1L, 89SOC_SINGLE_TLV("IN2R Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_2R,
75 ARIZONA_ADC_DIGITAL_VOLUME_1R, ARIZONA_IN1L_DIG_VOL_SHIFT, 90 ARIZONA_IN2R_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
76 0xbf, 0, digital_tlv), 91SOC_SINGLE_TLV("IN3L Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_3L,
77SOC_DOUBLE_R_TLV("IN2 Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_2L, 92 ARIZONA_IN3L_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
78 ARIZONA_ADC_DIGITAL_VOLUME_2R, ARIZONA_IN2L_DIG_VOL_SHIFT, 93SOC_SINGLE_TLV("IN3R Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_3R,
79 0xbf, 0, digital_tlv), 94 ARIZONA_IN3R_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
80SOC_DOUBLE_R_TLV("IN3 Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_3L, 95SOC_SINGLE_TLV("IN4L Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_4L,
81 ARIZONA_ADC_DIGITAL_VOLUME_3R, ARIZONA_IN3L_DIG_VOL_SHIFT, 96 ARIZONA_IN4L_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
82 0xbf, 0, digital_tlv), 97SOC_SINGLE_TLV("IN4R Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_4R,
83SOC_DOUBLE_R_TLV("IN4 Digital Volume", ARIZONA_ADC_DIGITAL_VOLUME_4L, 98 ARIZONA_IN4R_DIG_VOL_SHIFT, 0xbf, 0, digital_tlv),
84 ARIZONA_ADC_DIGITAL_VOLUME_4R, ARIZONA_IN4L_DIG_VOL_SHIFT,
85 0xbf, 0, digital_tlv),
86 99
87SOC_ENUM("Input Ramp Up", arizona_in_vi_ramp), 100SOC_ENUM("Input Ramp Up", arizona_in_vi_ramp),
88SOC_ENUM("Input Ramp Down", arizona_in_vd_ramp), 101SOC_ENUM("Input Ramp Down", arizona_in_vd_ramp),
@@ -263,6 +276,25 @@ SOC_DOUBLE("SPKDAT2 Switch", ARIZONA_PDM_SPK2_CTRL_1, ARIZONA_SPK2L_MUTE_SHIFT,
263SOC_ENUM("Output Ramp Up", arizona_out_vi_ramp), 276SOC_ENUM("Output Ramp Up", arizona_out_vi_ramp),
264SOC_ENUM("Output Ramp Down", arizona_out_vd_ramp), 277SOC_ENUM("Output Ramp Down", arizona_out_vd_ramp),
265 278
279SOC_SINGLE("Noise Gate Switch", ARIZONA_NOISE_GATE_CONTROL,
280 ARIZONA_NGATE_ENA_SHIFT, 1, 0),
281SOC_SINGLE_TLV("Noise Gate Threshold Volume", ARIZONA_NOISE_GATE_CONTROL,
282 ARIZONA_NGATE_THR_SHIFT, 7, 1, ng_tlv),
283SOC_ENUM("Noise Gate Hold", arizona_ng_hold),
284
285WM5110_NG_SRC("HPOUT1L", ARIZONA_NOISE_GATE_SELECT_1L),
286WM5110_NG_SRC("HPOUT1R", ARIZONA_NOISE_GATE_SELECT_1R),
287WM5110_NG_SRC("HPOUT2L", ARIZONA_NOISE_GATE_SELECT_2L),
288WM5110_NG_SRC("HPOUT2R", ARIZONA_NOISE_GATE_SELECT_2R),
289WM5110_NG_SRC("HPOUT3L", ARIZONA_NOISE_GATE_SELECT_3L),
290WM5110_NG_SRC("HPOUT3R", ARIZONA_NOISE_GATE_SELECT_3R),
291WM5110_NG_SRC("SPKOUTL", ARIZONA_NOISE_GATE_SELECT_4L),
292WM5110_NG_SRC("SPKOUTR", ARIZONA_NOISE_GATE_SELECT_4R),
293WM5110_NG_SRC("SPKDAT1L", ARIZONA_NOISE_GATE_SELECT_5L),
294WM5110_NG_SRC("SPKDAT1R", ARIZONA_NOISE_GATE_SELECT_5R),
295WM5110_NG_SRC("SPKDAT2L", ARIZONA_NOISE_GATE_SELECT_6L),
296WM5110_NG_SRC("SPKDAT2R", ARIZONA_NOISE_GATE_SELECT_6R),
297
266ARIZONA_MIXER_CONTROLS("AIF1TX1", ARIZONA_AIF1TX1MIX_INPUT_1_SOURCE), 298ARIZONA_MIXER_CONTROLS("AIF1TX1", ARIZONA_AIF1TX1MIX_INPUT_1_SOURCE),
267ARIZONA_MIXER_CONTROLS("AIF1TX2", ARIZONA_AIF1TX2MIX_INPUT_1_SOURCE), 299ARIZONA_MIXER_CONTROLS("AIF1TX2", ARIZONA_AIF1TX2MIX_INPUT_1_SOURCE),
268ARIZONA_MIXER_CONTROLS("AIF1TX3", ARIZONA_AIF1TX3MIX_INPUT_1_SOURCE), 300ARIZONA_MIXER_CONTROLS("AIF1TX3", ARIZONA_AIF1TX3MIX_INPUT_1_SOURCE),
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index fb92fb47d636..ec0efc1443ba 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -283,18 +283,16 @@ static int pga_event(struct snd_soc_dapm_widget *w,
283 out->ramp = WM8350_RAMP_UP; 283 out->ramp = WM8350_RAMP_UP;
284 out->active = 1; 284 out->active = 1;
285 285
286 if (!delayed_work_pending(&codec->dapm.delayed_work)) 286 schedule_delayed_work(&codec->dapm.delayed_work,
287 schedule_delayed_work(&codec->dapm.delayed_work, 287 msecs_to_jiffies(1));
288 msecs_to_jiffies(1));
289 break; 288 break;
290 289
291 case SND_SOC_DAPM_PRE_PMD: 290 case SND_SOC_DAPM_PRE_PMD:
292 out->ramp = WM8350_RAMP_DOWN; 291 out->ramp = WM8350_RAMP_DOWN;
293 out->active = 0; 292 out->active = 0;
294 293
295 if (!delayed_work_pending(&codec->dapm.delayed_work)) 294 schedule_delayed_work(&codec->dapm.delayed_work,
296 schedule_delayed_work(&codec->dapm.delayed_work, 295 msecs_to_jiffies(1));
297 msecs_to_jiffies(1));
298 break; 296 break;
299 } 297 }
300 298
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
index d321a875b029..1704b1e119cb 100644
--- a/sound/soc/codecs/wm8804.c
+++ b/sound/soc/codecs/wm8804.c
@@ -395,9 +395,6 @@ static int wm8804_set_pll(struct snd_soc_dai *dai, int pll_id,
395 /* power down the PLL before reprogramming it */ 395 /* power down the PLL before reprogramming it */
396 snd_soc_update_bits(codec, WM8804_PWRDN, 0x1, 0x1); 396 snd_soc_update_bits(codec, WM8804_PWRDN, 0x1, 0x1);
397 397
398 if (!freq_in || !freq_out)
399 return 0;
400
401 /* set PLLN and PRESCALE */ 398 /* set PLLN and PRESCALE */
402 snd_soc_update_bits(codec, WM8804_PLL4, 0xf | 0x10, 399 snd_soc_update_bits(codec, WM8804_PLL4, 0xf | 0x10,
403 pll_div.n | (pll_div.prescale << 4)); 400 pll_div.n | (pll_div.prescale << 4));
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index bd4b0db4cdaa..e9710280e5e1 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -2873,22 +2873,20 @@ static int wm8962_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
2873 2873
2874 ret = 0; 2874 ret = 0;
2875 2875
2876 if (fll1 & WM8962_FLL_ENA) { 2876 /* This should be a massive overestimate but go even
2877 /* This should be a massive overestimate but go even 2877 * higher if we'll error out
2878 * higher if we'll error out 2878 */
2879 */ 2879 if (wm8962->irq)
2880 if (wm8962->irq) 2880 timeout = msecs_to_jiffies(5);
2881 timeout = msecs_to_jiffies(5); 2881 else
2882 else 2882 timeout = msecs_to_jiffies(1);
2883 timeout = msecs_to_jiffies(1);
2884 2883
2885 timeout = wait_for_completion_timeout(&wm8962->fll_lock, 2884 timeout = wait_for_completion_timeout(&wm8962->fll_lock,
2886 timeout); 2885 timeout);
2887 2886
2888 if (timeout == 0 && wm8962->irq) { 2887 if (timeout == 0 && wm8962->irq) {
2889 dev_err(codec->dev, "FLL lock timed out"); 2888 dev_err(codec->dev, "FLL lock timed out");
2890 ret = -ETIMEDOUT; 2889 ret = -ETIMEDOUT;
2891 }
2892 } 2890 }
2893 2891
2894 wm8962->fll_fref = Fref; 2892 wm8962->fll_fref = Fref;
@@ -3189,7 +3187,7 @@ static void wm8962_init_beep(struct snd_soc_codec *codec)
3189 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3187 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3190 int ret; 3188 int ret;
3191 3189
3192 wm8962->beep = input_allocate_device(); 3190 wm8962->beep = devm_input_allocate_device(codec->dev);
3193 if (!wm8962->beep) { 3191 if (!wm8962->beep) {
3194 dev_err(codec->dev, "Failed to allocate beep device\n"); 3192 dev_err(codec->dev, "Failed to allocate beep device\n");
3195 return; 3193 return;
@@ -3210,7 +3208,6 @@ static void wm8962_init_beep(struct snd_soc_codec *codec)
3210 3208
3211 ret = input_register_device(wm8962->beep); 3209 ret = input_register_device(wm8962->beep);
3212 if (ret != 0) { 3210 if (ret != 0) {
3213 input_free_device(wm8962->beep);
3214 wm8962->beep = NULL; 3211 wm8962->beep = NULL;
3215 dev_err(codec->dev, "Failed to register beep device\n"); 3212 dev_err(codec->dev, "Failed to register beep device\n");
3216 } 3213 }
@@ -3227,7 +3224,6 @@ static void wm8962_free_beep(struct snd_soc_codec *codec)
3227 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3224 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3228 3225
3229 device_remove_file(codec->dev, &dev_attr_beep); 3226 device_remove_file(codec->dev, &dev_attr_beep);
3230 input_unregister_device(wm8962->beep);
3231 cancel_work_sync(&wm8962->beep_work); 3227 cancel_work_sync(&wm8962->beep_work);
3232 wm8962->beep = NULL; 3228 wm8962->beep = NULL;
3233 3229
@@ -3758,10 +3754,17 @@ static const struct i2c_device_id wm8962_i2c_id[] = {
3758}; 3754};
3759MODULE_DEVICE_TABLE(i2c, wm8962_i2c_id); 3755MODULE_DEVICE_TABLE(i2c, wm8962_i2c_id);
3760 3756
3757static const struct of_device_id wm8962_of_match[] = {
3758 { .compatible = "wlf,wm8962", },
3759 { }
3760};
3761MODULE_DEVICE_TABLE(of, wm8962_of_match);
3762
3761static struct i2c_driver wm8962_i2c_driver = { 3763static struct i2c_driver wm8962_i2c_driver = {
3762 .driver = { 3764 .driver = {
3763 .name = "wm8962", 3765 .name = "wm8962",
3764 .owner = THIS_MODULE, 3766 .owner = THIS_MODULE,
3767 .of_match_table = wm8962_of_match,
3765 .pm = &wm8962_pm, 3768 .pm = &wm8962_pm,
3766 }, 3769 },
3767 .probe = wm8962_i2c_probe, 3770 .probe = wm8962_i2c_probe,
diff --git a/sound/soc/codecs/wm8983.c b/sound/soc/codecs/wm8983.c
index 9fe1e041da49..c9c707b8698f 100644
--- a/sound/soc/codecs/wm8983.c
+++ b/sound/soc/codecs/wm8983.c
@@ -851,30 +851,33 @@ static int wm8983_set_pll(struct snd_soc_dai *dai, int pll_id,
851 struct pll_div pll_div; 851 struct pll_div pll_div;
852 852
853 codec = dai->codec; 853 codec = dai->codec;
854 if (freq_in && freq_out) { 854 if (!freq_in || !freq_out) {
855 /* disable the PLL */
856 snd_soc_update_bits(codec, WM8983_POWER_MANAGEMENT_1,
857 WM8983_PLLEN_MASK, 0);
858 return 0;
859 } else {
855 ret = pll_factors(&pll_div, freq_out * 4 * 2, freq_in); 860 ret = pll_factors(&pll_div, freq_out * 4 * 2, freq_in);
856 if (ret) 861 if (ret)
857 return ret; 862 return ret;
858 }
859
860 /* disable the PLL before re-programming it */
861 snd_soc_update_bits(codec, WM8983_POWER_MANAGEMENT_1,
862 WM8983_PLLEN_MASK, 0);
863 863
864 if (!freq_in || !freq_out) 864 /* disable the PLL before re-programming it */
865 return 0; 865 snd_soc_update_bits(codec, WM8983_POWER_MANAGEMENT_1,
866 WM8983_PLLEN_MASK, 0);
867
868 /* set PLLN and PRESCALE */
869 snd_soc_write(codec, WM8983_PLL_N,
870 (pll_div.div2 << WM8983_PLL_PRESCALE_SHIFT)
871 | pll_div.n);
872 /* set PLLK */
873 snd_soc_write(codec, WM8983_PLL_K_3, pll_div.k & 0x1ff);
874 snd_soc_write(codec, WM8983_PLL_K_2, (pll_div.k >> 9) & 0x1ff);
875 snd_soc_write(codec, WM8983_PLL_K_1, (pll_div.k >> 18));
876 /* enable the PLL */
877 snd_soc_update_bits(codec, WM8983_POWER_MANAGEMENT_1,
878 WM8983_PLLEN_MASK, WM8983_PLLEN);
879 }
866 880
867 /* set PLLN and PRESCALE */
868 snd_soc_write(codec, WM8983_PLL_N,
869 (pll_div.div2 << WM8983_PLL_PRESCALE_SHIFT)
870 | pll_div.n);
871 /* set PLLK */
872 snd_soc_write(codec, WM8983_PLL_K_3, pll_div.k & 0x1ff);
873 snd_soc_write(codec, WM8983_PLL_K_2, (pll_div.k >> 9) & 0x1ff);
874 snd_soc_write(codec, WM8983_PLL_K_1, (pll_div.k >> 18));
875 /* enable the PLL */
876 snd_soc_update_bits(codec, WM8983_POWER_MANAGEMENT_1,
877 WM8983_PLLEN_MASK, WM8983_PLLEN);
878 return 0; 881 return 0;
879} 882}
880 883
diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c
index ab3782657ac8..dd6ce3bc01cf 100644
--- a/sound/soc/codecs/wm8985.c
+++ b/sound/soc/codecs/wm8985.c
@@ -830,33 +830,30 @@ static int wm8985_set_pll(struct snd_soc_dai *dai, int pll_id,
830 struct pll_div pll_div; 830 struct pll_div pll_div;
831 831
832 codec = dai->codec; 832 codec = dai->codec;
833 if (freq_in && freq_out) { 833 if (!freq_in || !freq_out) {
834 /* disable the PLL */
835 snd_soc_update_bits(codec, WM8985_POWER_MANAGEMENT_1,
836 WM8985_PLLEN_MASK, 0);
837 } else {
834 ret = pll_factors(&pll_div, freq_out * 4 * 2, freq_in); 838 ret = pll_factors(&pll_div, freq_out * 4 * 2, freq_in);
835 if (ret) 839 if (ret)
836 return ret; 840 return ret;
837 }
838 841
839 /* disable the PLL before reprogramming it */ 842 /* set PLLN and PRESCALE */
840 snd_soc_update_bits(codec, WM8985_POWER_MANAGEMENT_1, 843 snd_soc_write(codec, WM8985_PLL_N,
841 WM8985_PLLEN_MASK, 0); 844 (pll_div.div2 << WM8985_PLL_PRESCALE_SHIFT)
842 845 | pll_div.n);
843 if (!freq_in || !freq_out) 846 /* set PLLK */
844 return 0; 847 snd_soc_write(codec, WM8985_PLL_K_3, pll_div.k & 0x1ff);
845 848 snd_soc_write(codec, WM8985_PLL_K_2, (pll_div.k >> 9) & 0x1ff);
846 /* set PLLN and PRESCALE */ 849 snd_soc_write(codec, WM8985_PLL_K_1, (pll_div.k >> 18));
847 snd_soc_write(codec, WM8985_PLL_N, 850 /* set the source of the clock to be the PLL */
848 (pll_div.div2 << WM8985_PLL_PRESCALE_SHIFT) 851 snd_soc_update_bits(codec, WM8985_CLOCK_GEN_CONTROL,
849 | pll_div.n); 852 WM8985_CLKSEL_MASK, WM8985_CLKSEL);
850 /* set PLLK */ 853 /* enable the PLL */
851 snd_soc_write(codec, WM8985_PLL_K_3, pll_div.k & 0x1ff); 854 snd_soc_update_bits(codec, WM8985_POWER_MANAGEMENT_1,
852 snd_soc_write(codec, WM8985_PLL_K_2, (pll_div.k >> 9) & 0x1ff); 855 WM8985_PLLEN_MASK, WM8985_PLLEN);
853 snd_soc_write(codec, WM8985_PLL_K_1, (pll_div.k >> 18)); 856 }
854 /* set the source of the clock to be the PLL */
855 snd_soc_update_bits(codec, WM8985_CLOCK_GEN_CONTROL,
856 WM8985_CLKSEL_MASK, WM8985_CLKSEL);
857 /* enable the PLL */
858 snd_soc_update_bits(codec, WM8985_POWER_MANAGEMENT_1,
859 WM8985_PLLEN_MASK, WM8985_PLLEN);
860 return 0; 857 return 0;
861} 858}
862 859
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 3b269fa226bd..c9bd445c4976 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -3737,7 +3737,7 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
3737{ 3737{
3738 struct wm8994_priv *wm8994 = data; 3738 struct wm8994_priv *wm8994 = data;
3739 struct snd_soc_codec *codec = wm8994->hubs.codec; 3739 struct snd_soc_codec *codec = wm8994->hubs.codec;
3740 int reg, count; 3740 int reg, count, ret;
3741 3741
3742 /* 3742 /*
3743 * Jack detection may have detected a removal simulataneously 3743 * Jack detection may have detected a removal simulataneously
@@ -3783,11 +3783,11 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
3783 3783
3784 /* Avoid a transient report when the accessory is being removed */ 3784 /* Avoid a transient report when the accessory is being removed */
3785 if (wm8994->jackdet) { 3785 if (wm8994->jackdet) {
3786 reg = snd_soc_read(codec, WM1811_JACKDET_CTRL); 3786 ret = snd_soc_read(codec, WM1811_JACKDET_CTRL);
3787 if (reg < 0) { 3787 if (ret < 0) {
3788 dev_err(codec->dev, "Failed to read jack status: %d\n", 3788 dev_err(codec->dev, "Failed to read jack status: %d\n",
3789 reg); 3789 ret);
3790 } else if (!(reg & WM1811_JACKDET_LVL)) { 3790 } else if (!(ret & WM1811_JACKDET_LVL)) {
3791 dev_dbg(codec->dev, "Ignoring removed jack\n"); 3791 dev_dbg(codec->dev, "Ignoring removed jack\n");
3792 return IRQ_HANDLED; 3792 return IRQ_HANDLED;
3793 } 3793 }
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index b6b654837585..f3f7e75f8628 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/firmware.h> 17#include <linux/firmware.h>
18#include <linux/list.h>
18#include <linux/pm.h> 19#include <linux/pm.h>
19#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
20#include <linux/regmap.h> 21#include <linux/regmap.h>
@@ -103,9 +104,19 @@
103#define ADSP1_START_SHIFT 0 /* DSP1_START */ 104#define ADSP1_START_SHIFT 0 /* DSP1_START */
104#define ADSP1_START_WIDTH 1 /* DSP1_START */ 105#define ADSP1_START_WIDTH 1 /* DSP1_START */
105 106
106#define ADSP2_CONTROL 0 107/*
107#define ADSP2_CLOCKING 1 108 * ADSP1 Control 31
108#define ADSP2_STATUS1 4 109 */
110#define ADSP1_CLK_SEL_MASK 0x0007 /* CLK_SEL_ENA */
111#define ADSP1_CLK_SEL_SHIFT 0 /* CLK_SEL_ENA */
112#define ADSP1_CLK_SEL_WIDTH 3 /* CLK_SEL_ENA */
113
114#define ADSP2_CONTROL 0x0
115#define ADSP2_CLOCKING 0x1
116#define ADSP2_STATUS1 0x4
117#define ADSP2_WDMA_CONFIG_1 0x30
118#define ADSP2_WDMA_CONFIG_2 0x31
119#define ADSP2_RDMA_CONFIG_1 0x34
109 120
110/* 121/*
111 * ADSP2 Control 122 * ADSP2 Control
@@ -143,6 +154,109 @@
143#define ADSP2_RAM_RDY_SHIFT 0 154#define ADSP2_RAM_RDY_SHIFT 0
144#define ADSP2_RAM_RDY_WIDTH 1 155#define ADSP2_RAM_RDY_WIDTH 1
145 156
157struct wm_adsp_buf {
158 struct list_head list;
159 void *buf;
160};
161
162static struct wm_adsp_buf *wm_adsp_buf_alloc(const void *src, size_t len,
163 struct list_head *list)
164{
165 struct wm_adsp_buf *buf = kzalloc(sizeof(*buf), GFP_KERNEL);
166
167 if (buf == NULL)
168 return NULL;
169
170 buf->buf = kmemdup(src, len, GFP_KERNEL | GFP_DMA);
171 if (!buf->buf) {
172 kfree(buf);
173 return NULL;
174 }
175
176 if (list)
177 list_add_tail(&buf->list, list);
178
179 return buf;
180}
181
182static void wm_adsp_buf_free(struct list_head *list)
183{
184 while (!list_empty(list)) {
185 struct wm_adsp_buf *buf = list_first_entry(list,
186 struct wm_adsp_buf,
187 list);
188 list_del(&buf->list);
189 kfree(buf->buf);
190 kfree(buf);
191 }
192}
193
194#define WM_ADSP_NUM_FW 4
195
196static const char *wm_adsp_fw_text[WM_ADSP_NUM_FW] = {
197 "MBC/VSS", "Tx", "Tx Speaker", "Rx ANC"
198};
199
200static struct {
201 const char *file;
202} wm_adsp_fw[WM_ADSP_NUM_FW] = {
203 { .file = "mbc-vss" },
204 { .file = "tx" },
205 { .file = "tx-spk" },
206 { .file = "rx-anc" },
207};
208
209static int wm_adsp_fw_get(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_value *ucontrol)
211{
212 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
213 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
214 struct wm_adsp *adsp = snd_soc_codec_get_drvdata(codec);
215
216 ucontrol->value.integer.value[0] = adsp[e->shift_l].fw;
217
218 return 0;
219}
220
221static int wm_adsp_fw_put(struct snd_kcontrol *kcontrol,
222 struct snd_ctl_elem_value *ucontrol)
223{
224 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
225 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
226 struct wm_adsp *adsp = snd_soc_codec_get_drvdata(codec);
227
228 if (ucontrol->value.integer.value[0] == adsp[e->shift_l].fw)
229 return 0;
230
231 if (ucontrol->value.integer.value[0] >= WM_ADSP_NUM_FW)
232 return -EINVAL;
233
234 if (adsp[e->shift_l].running)
235 return -EBUSY;
236
237 adsp[e->shift_l].fw = ucontrol->value.integer.value[0];
238
239 return 0;
240}
241
242static const struct soc_enum wm_adsp_fw_enum[] = {
243 SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text),
244 SOC_ENUM_SINGLE(0, 1, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text),
245 SOC_ENUM_SINGLE(0, 2, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text),
246 SOC_ENUM_SINGLE(0, 3, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text),
247};
248
249const struct snd_kcontrol_new wm_adsp_fw_controls[] = {
250 SOC_ENUM_EXT("DSP1 Firmware", wm_adsp_fw_enum[0],
251 wm_adsp_fw_get, wm_adsp_fw_put),
252 SOC_ENUM_EXT("DSP2 Firmware", wm_adsp_fw_enum[1],
253 wm_adsp_fw_get, wm_adsp_fw_put),
254 SOC_ENUM_EXT("DSP3 Firmware", wm_adsp_fw_enum[2],
255 wm_adsp_fw_get, wm_adsp_fw_put),
256 SOC_ENUM_EXT("DSP4 Firmware", wm_adsp_fw_enum[3],
257 wm_adsp_fw_get, wm_adsp_fw_put),
258};
259EXPORT_SYMBOL_GPL(wm_adsp_fw_controls);
146 260
147static struct wm_adsp_region const *wm_adsp_find_region(struct wm_adsp *dsp, 261static struct wm_adsp_region const *wm_adsp_find_region(struct wm_adsp *dsp,
148 int type) 262 int type)
@@ -156,8 +270,29 @@ static struct wm_adsp_region const *wm_adsp_find_region(struct wm_adsp *dsp,
156 return NULL; 270 return NULL;
157} 271}
158 272
273static unsigned int wm_adsp_region_to_reg(struct wm_adsp_region const *region,
274 unsigned int offset)
275{
276 switch (region->type) {
277 case WMFW_ADSP1_PM:
278 return region->base + (offset * 3);
279 case WMFW_ADSP1_DM:
280 return region->base + (offset * 2);
281 case WMFW_ADSP2_XM:
282 return region->base + (offset * 2);
283 case WMFW_ADSP2_YM:
284 return region->base + (offset * 2);
285 case WMFW_ADSP1_ZM:
286 return region->base + (offset * 2);
287 default:
288 WARN_ON(NULL != "Unknown memory region type");
289 return offset;
290 }
291}
292
159static int wm_adsp_load(struct wm_adsp *dsp) 293static int wm_adsp_load(struct wm_adsp *dsp)
160{ 294{
295 LIST_HEAD(buf_list);
161 const struct firmware *firmware; 296 const struct firmware *firmware;
162 struct regmap *regmap = dsp->regmap; 297 struct regmap *regmap = dsp->regmap;
163 unsigned int pos = 0; 298 unsigned int pos = 0;
@@ -169,7 +304,7 @@ static int wm_adsp_load(struct wm_adsp *dsp)
169 const struct wm_adsp_region *mem; 304 const struct wm_adsp_region *mem;
170 const char *region_name; 305 const char *region_name;
171 char *file, *text; 306 char *file, *text;
172 void *buf; 307 struct wm_adsp_buf *buf;
173 unsigned int reg; 308 unsigned int reg;
174 int regions = 0; 309 int regions = 0;
175 int ret, offset, type, sizes; 310 int ret, offset, type, sizes;
@@ -178,7 +313,8 @@ static int wm_adsp_load(struct wm_adsp *dsp)
178 if (file == NULL) 313 if (file == NULL)
179 return -ENOMEM; 314 return -ENOMEM;
180 315
181 snprintf(file, PAGE_SIZE, "%s-dsp%d.wmfw", dsp->part, dsp->num); 316 snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.wmfw", dsp->part, dsp->num,
317 wm_adsp_fw[dsp->fw].file);
182 file[PAGE_SIZE - 1] = '\0'; 318 file[PAGE_SIZE - 1] = '\0';
183 319
184 ret = request_firmware(&firmware, file, dsp->dev); 320 ret = request_firmware(&firmware, file, dsp->dev);
@@ -283,27 +419,27 @@ static int wm_adsp_load(struct wm_adsp *dsp)
283 case WMFW_ADSP1_PM: 419 case WMFW_ADSP1_PM:
284 BUG_ON(!mem); 420 BUG_ON(!mem);
285 region_name = "PM"; 421 region_name = "PM";
286 reg = mem->base + (offset * 3); 422 reg = wm_adsp_region_to_reg(mem, offset);
287 break; 423 break;
288 case WMFW_ADSP1_DM: 424 case WMFW_ADSP1_DM:
289 BUG_ON(!mem); 425 BUG_ON(!mem);
290 region_name = "DM"; 426 region_name = "DM";
291 reg = mem->base + (offset * 2); 427 reg = wm_adsp_region_to_reg(mem, offset);
292 break; 428 break;
293 case WMFW_ADSP2_XM: 429 case WMFW_ADSP2_XM:
294 BUG_ON(!mem); 430 BUG_ON(!mem);
295 region_name = "XM"; 431 region_name = "XM";
296 reg = mem->base + (offset * 2); 432 reg = wm_adsp_region_to_reg(mem, offset);
297 break; 433 break;
298 case WMFW_ADSP2_YM: 434 case WMFW_ADSP2_YM:
299 BUG_ON(!mem); 435 BUG_ON(!mem);
300 region_name = "YM"; 436 region_name = "YM";
301 reg = mem->base + (offset * 2); 437 reg = wm_adsp_region_to_reg(mem, offset);
302 break; 438 break;
303 case WMFW_ADSP1_ZM: 439 case WMFW_ADSP1_ZM:
304 BUG_ON(!mem); 440 BUG_ON(!mem);
305 region_name = "ZM"; 441 region_name = "ZM";
306 reg = mem->base + (offset * 2); 442 reg = wm_adsp_region_to_reg(mem, offset);
307 break; 443 break;
308 default: 444 default:
309 adsp_warn(dsp, 445 adsp_warn(dsp,
@@ -323,18 +459,16 @@ static int wm_adsp_load(struct wm_adsp *dsp)
323 } 459 }
324 460
325 if (reg) { 461 if (reg) {
326 buf = kmemdup(region->data, le32_to_cpu(region->len), 462 buf = wm_adsp_buf_alloc(region->data,
327 GFP_KERNEL | GFP_DMA); 463 le32_to_cpu(region->len),
464 &buf_list);
328 if (!buf) { 465 if (!buf) {
329 adsp_err(dsp, "Out of memory\n"); 466 adsp_err(dsp, "Out of memory\n");
330 return -ENOMEM; 467 return -ENOMEM;
331 } 468 }
332 469
333 ret = regmap_raw_write(regmap, reg, buf, 470 ret = regmap_raw_write_async(regmap, reg, buf->buf,
334 le32_to_cpu(region->len)); 471 le32_to_cpu(region->len));
335
336 kfree(buf);
337
338 if (ret != 0) { 472 if (ret != 0) {
339 adsp_err(dsp, 473 adsp_err(dsp,
340 "%s.%d: Failed to write %d bytes at %d in %s: %d\n", 474 "%s.%d: Failed to write %d bytes at %d in %s: %d\n",
@@ -348,12 +482,20 @@ static int wm_adsp_load(struct wm_adsp *dsp)
348 pos += le32_to_cpu(region->len) + sizeof(*region); 482 pos += le32_to_cpu(region->len) + sizeof(*region);
349 regions++; 483 regions++;
350 } 484 }
351 485
486 ret = regmap_async_complete(regmap);
487 if (ret != 0) {
488 adsp_err(dsp, "Failed to complete async write: %d\n", ret);
489 goto out_fw;
490 }
491
352 if (pos > firmware->size) 492 if (pos > firmware->size)
353 adsp_warn(dsp, "%s.%d: %zu bytes at end of file\n", 493 adsp_warn(dsp, "%s.%d: %zu bytes at end of file\n",
354 file, regions, pos - firmware->size); 494 file, regions, pos - firmware->size);
355 495
356out_fw: 496out_fw:
497 regmap_async_complete(regmap);
498 wm_adsp_buf_free(&buf_list);
357 release_firmware(firmware); 499 release_firmware(firmware);
358out: 500out:
359 kfree(file); 501 kfree(file);
@@ -361,22 +503,222 @@ out:
361 return ret; 503 return ret;
362} 504}
363 505
506static int wm_adsp_setup_algs(struct wm_adsp *dsp)
507{
508 struct regmap *regmap = dsp->regmap;
509 struct wmfw_adsp1_id_hdr adsp1_id;
510 struct wmfw_adsp2_id_hdr adsp2_id;
511 struct wmfw_adsp1_alg_hdr *adsp1_alg;
512 struct wmfw_adsp2_alg_hdr *adsp2_alg;
513 void *alg, *buf;
514 struct wm_adsp_alg_region *region;
515 const struct wm_adsp_region *mem;
516 unsigned int pos, term;
517 size_t algs, buf_size;
518 __be32 val;
519 int i, ret;
520
521 switch (dsp->type) {
522 case WMFW_ADSP1:
523 mem = wm_adsp_find_region(dsp, WMFW_ADSP1_DM);
524 break;
525 case WMFW_ADSP2:
526 mem = wm_adsp_find_region(dsp, WMFW_ADSP2_XM);
527 break;
528 default:
529 mem = NULL;
530 break;
531 }
532
533 if (mem == NULL) {
534 BUG_ON(mem != NULL);
535 return -EINVAL;
536 }
537
538 switch (dsp->type) {
539 case WMFW_ADSP1:
540 ret = regmap_raw_read(regmap, mem->base, &adsp1_id,
541 sizeof(adsp1_id));
542 if (ret != 0) {
543 adsp_err(dsp, "Failed to read algorithm info: %d\n",
544 ret);
545 return ret;
546 }
547
548 buf = &adsp1_id;
549 buf_size = sizeof(adsp1_id);
550
551 algs = be32_to_cpu(adsp1_id.algs);
552 adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n",
553 be32_to_cpu(adsp1_id.fw.id),
554 (be32_to_cpu(adsp1_id.fw.ver) & 0xff0000) >> 16,
555 (be32_to_cpu(adsp1_id.fw.ver) & 0xff00) >> 8,
556 be32_to_cpu(adsp1_id.fw.ver) & 0xff,
557 algs);
558
559 pos = sizeof(adsp1_id) / 2;
560 term = pos + ((sizeof(*adsp1_alg) * algs) / 2);
561 break;
562
563 case WMFW_ADSP2:
564 ret = regmap_raw_read(regmap, mem->base, &adsp2_id,
565 sizeof(adsp2_id));
566 if (ret != 0) {
567 adsp_err(dsp, "Failed to read algorithm info: %d\n",
568 ret);
569 return ret;
570 }
571
572 buf = &adsp2_id;
573 buf_size = sizeof(adsp2_id);
574
575 algs = be32_to_cpu(adsp2_id.algs);
576 adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n",
577 be32_to_cpu(adsp2_id.fw.id),
578 (be32_to_cpu(adsp2_id.fw.ver) & 0xff0000) >> 16,
579 (be32_to_cpu(adsp2_id.fw.ver) & 0xff00) >> 8,
580 be32_to_cpu(adsp2_id.fw.ver) & 0xff,
581 algs);
582
583 pos = sizeof(adsp2_id) / 2;
584 term = pos + ((sizeof(*adsp2_alg) * algs) / 2);
585 break;
586
587 default:
588 BUG_ON(NULL == "Unknown DSP type");
589 return -EINVAL;
590 }
591
592 if (algs == 0) {
593 adsp_err(dsp, "No algorithms\n");
594 return -EINVAL;
595 }
596
597 if (algs > 1024) {
598 adsp_err(dsp, "Algorithm count %zx excessive\n", algs);
599 print_hex_dump_bytes(dev_name(dsp->dev), DUMP_PREFIX_OFFSET,
600 buf, buf_size);
601 return -EINVAL;
602 }
603
604 /* Read the terminator first to validate the length */
605 ret = regmap_raw_read(regmap, mem->base + term, &val, sizeof(val));
606 if (ret != 0) {
607 adsp_err(dsp, "Failed to read algorithm list end: %d\n",
608 ret);
609 return ret;
610 }
611
612 if (be32_to_cpu(val) != 0xbedead)
613 adsp_warn(dsp, "Algorithm list end %x 0x%x != 0xbeadead\n",
614 term, be32_to_cpu(val));
615
616 alg = kzalloc((term - pos) * 2, GFP_KERNEL | GFP_DMA);
617 if (!alg)
618 return -ENOMEM;
619
620 ret = regmap_raw_read(regmap, mem->base + pos, alg, (term - pos) * 2);
621 if (ret != 0) {
622 adsp_err(dsp, "Failed to read algorithm list: %d\n",
623 ret);
624 goto out;
625 }
626
627 adsp1_alg = alg;
628 adsp2_alg = alg;
629
630 for (i = 0; i < algs; i++) {
631 switch (dsp->type) {
632 case WMFW_ADSP1:
633 adsp_info(dsp, "%d: ID %x v%d.%d.%d DM@%x ZM@%x\n",
634 i, be32_to_cpu(adsp1_alg[i].alg.id),
635 (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff0000) >> 16,
636 (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff00) >> 8,
637 be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff,
638 be32_to_cpu(adsp1_alg[i].dm),
639 be32_to_cpu(adsp1_alg[i].zm));
640
641 region = kzalloc(sizeof(*region), GFP_KERNEL);
642 if (!region)
643 return -ENOMEM;
644 region->type = WMFW_ADSP1_DM;
645 region->alg = be32_to_cpu(adsp1_alg[i].alg.id);
646 region->base = be32_to_cpu(adsp1_alg[i].dm);
647 list_add_tail(&region->list, &dsp->alg_regions);
648
649 region = kzalloc(sizeof(*region), GFP_KERNEL);
650 if (!region)
651 return -ENOMEM;
652 region->type = WMFW_ADSP1_ZM;
653 region->alg = be32_to_cpu(adsp1_alg[i].alg.id);
654 region->base = be32_to_cpu(adsp1_alg[i].zm);
655 list_add_tail(&region->list, &dsp->alg_regions);
656 break;
657
658 case WMFW_ADSP2:
659 adsp_info(dsp,
660 "%d: ID %x v%d.%d.%d XM@%x YM@%x ZM@%x\n",
661 i, be32_to_cpu(adsp2_alg[i].alg.id),
662 (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff0000) >> 16,
663 (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff00) >> 8,
664 be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff,
665 be32_to_cpu(adsp2_alg[i].xm),
666 be32_to_cpu(adsp2_alg[i].ym),
667 be32_to_cpu(adsp2_alg[i].zm));
668
669 region = kzalloc(sizeof(*region), GFP_KERNEL);
670 if (!region)
671 return -ENOMEM;
672 region->type = WMFW_ADSP2_XM;
673 region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
674 region->base = be32_to_cpu(adsp2_alg[i].xm);
675 list_add_tail(&region->list, &dsp->alg_regions);
676
677 region = kzalloc(sizeof(*region), GFP_KERNEL);
678 if (!region)
679 return -ENOMEM;
680 region->type = WMFW_ADSP2_YM;
681 region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
682 region->base = be32_to_cpu(adsp2_alg[i].ym);
683 list_add_tail(&region->list, &dsp->alg_regions);
684
685 region = kzalloc(sizeof(*region), GFP_KERNEL);
686 if (!region)
687 return -ENOMEM;
688 region->type = WMFW_ADSP2_ZM;
689 region->alg = be32_to_cpu(adsp2_alg[i].alg.id);
690 region->base = be32_to_cpu(adsp2_alg[i].zm);
691 list_add_tail(&region->list, &dsp->alg_regions);
692 break;
693 }
694 }
695
696out:
697 kfree(alg);
698 return ret;
699}
700
364static int wm_adsp_load_coeff(struct wm_adsp *dsp) 701static int wm_adsp_load_coeff(struct wm_adsp *dsp)
365{ 702{
703 LIST_HEAD(buf_list);
366 struct regmap *regmap = dsp->regmap; 704 struct regmap *regmap = dsp->regmap;
367 struct wmfw_coeff_hdr *hdr; 705 struct wmfw_coeff_hdr *hdr;
368 struct wmfw_coeff_item *blk; 706 struct wmfw_coeff_item *blk;
369 const struct firmware *firmware; 707 const struct firmware *firmware;
708 const struct wm_adsp_region *mem;
709 struct wm_adsp_alg_region *alg_region;
370 const char *region_name; 710 const char *region_name;
371 int ret, pos, blocks, type, offset, reg; 711 int ret, pos, blocks, type, offset, reg;
372 char *file; 712 char *file;
373 void *buf; 713 struct wm_adsp_buf *buf;
714 int tmp;
374 715
375 file = kzalloc(PAGE_SIZE, GFP_KERNEL); 716 file = kzalloc(PAGE_SIZE, GFP_KERNEL);
376 if (file == NULL) 717 if (file == NULL)
377 return -ENOMEM; 718 return -ENOMEM;
378 719
379 snprintf(file, PAGE_SIZE, "%s-dsp%d.bin", dsp->part, dsp->num); 720 snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.bin", dsp->part, dsp->num,
721 wm_adsp_fw[dsp->fw].file);
380 file[PAGE_SIZE - 1] = '\0'; 722 file[PAGE_SIZE - 1] = '\0';
381 723
382 ret = request_firmware(&firmware, file, dsp->dev); 724 ret = request_firmware(&firmware, file, dsp->dev);
@@ -399,6 +741,16 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
399 goto out_fw; 741 goto out_fw;
400 } 742 }
401 743
744 switch (be32_to_cpu(hdr->rev) & 0xff) {
745 case 1:
746 break;
747 default:
748 adsp_err(dsp, "%s: Unsupported coefficient file format %d\n",
749 file, be32_to_cpu(hdr->rev) & 0xff);
750 ret = -EINVAL;
751 goto out_fw;
752 }
753
402 adsp_dbg(dsp, "%s: v%d.%d.%d\n", file, 754 adsp_dbg(dsp, "%s: v%d.%d.%d\n", file,
403 (le32_to_cpu(hdr->ver) >> 16) & 0xff, 755 (le32_to_cpu(hdr->ver) >> 16) & 0xff,
404 (le32_to_cpu(hdr->ver) >> 8) & 0xff, 756 (le32_to_cpu(hdr->ver) >> 8) & 0xff,
@@ -411,8 +763,8 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
411 pos - firmware->size > sizeof(*blk)) { 763 pos - firmware->size > sizeof(*blk)) {
412 blk = (void*)(&firmware->data[pos]); 764 blk = (void*)(&firmware->data[pos]);
413 765
414 type = be32_to_cpu(blk->type) & 0xff; 766 type = le16_to_cpu(blk->type);
415 offset = le32_to_cpu(blk->offset) & 0xffffff; 767 offset = le16_to_cpu(blk->offset);
416 768
417 adsp_dbg(dsp, "%s.%d: %x v%d.%d.%d\n", 769 adsp_dbg(dsp, "%s.%d: %x v%d.%d.%d\n",
418 file, blocks, le32_to_cpu(blk->id), 770 file, blocks, le32_to_cpu(blk->id),
@@ -425,52 +777,105 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
425 reg = 0; 777 reg = 0;
426 region_name = "Unknown"; 778 region_name = "Unknown";
427 switch (type) { 779 switch (type) {
428 case WMFW_NAME_TEXT: 780 case (WMFW_NAME_TEXT << 8):
429 case WMFW_INFO_TEXT: 781 case (WMFW_INFO_TEXT << 8):
430 break; 782 break;
431 case WMFW_ABSOLUTE: 783 case (WMFW_ABSOLUTE << 8):
432 region_name = "register"; 784 region_name = "register";
433 reg = offset; 785 reg = offset;
434 break; 786 break;
787
788 case WMFW_ADSP1_DM:
789 case WMFW_ADSP1_ZM:
790 case WMFW_ADSP2_XM:
791 case WMFW_ADSP2_YM:
792 adsp_dbg(dsp, "%s.%d: %d bytes in %x for %x\n",
793 file, blocks, le32_to_cpu(blk->len),
794 type, le32_to_cpu(blk->id));
795
796 mem = wm_adsp_find_region(dsp, type);
797 if (!mem) {
798 adsp_err(dsp, "No base for region %x\n", type);
799 break;
800 }
801
802 reg = 0;
803 list_for_each_entry(alg_region,
804 &dsp->alg_regions, list) {
805 if (le32_to_cpu(blk->id) == alg_region->alg &&
806 type == alg_region->type) {
807 reg = alg_region->base;
808 reg = wm_adsp_region_to_reg(mem,
809 reg);
810 reg += offset;
811 }
812 }
813
814 if (reg == 0)
815 adsp_err(dsp, "No %x for algorithm %x\n",
816 type, le32_to_cpu(blk->id));
817 break;
818
435 default: 819 default:
436 adsp_err(dsp, "Unknown region type %x\n", type); 820 adsp_err(dsp, "%s.%d: Unknown region type %x at %d\n",
821 file, blocks, type, pos);
437 break; 822 break;
438 } 823 }
439 824
440 if (reg) { 825 if (reg) {
441 buf = kmemdup(blk->data, le32_to_cpu(blk->len), 826 buf = wm_adsp_buf_alloc(blk->data,
442 GFP_KERNEL | GFP_DMA); 827 le32_to_cpu(blk->len),
828 &buf_list);
443 if (!buf) { 829 if (!buf) {
444 adsp_err(dsp, "Out of memory\n"); 830 adsp_err(dsp, "Out of memory\n");
445 return -ENOMEM; 831 return -ENOMEM;
446 } 832 }
447 833
448 ret = regmap_raw_write(regmap, reg, blk->data, 834 adsp_dbg(dsp, "%s.%d: Writing %d bytes at %x\n",
449 le32_to_cpu(blk->len)); 835 file, blocks, le32_to_cpu(blk->len),
836 reg);
837 ret = regmap_raw_write_async(regmap, reg, buf->buf,
838 le32_to_cpu(blk->len));
450 if (ret != 0) { 839 if (ret != 0) {
451 adsp_err(dsp, 840 adsp_err(dsp,
452 "%s.%d: Failed to write to %x in %s\n", 841 "%s.%d: Failed to write to %x in %s\n",
453 file, blocks, reg, region_name); 842 file, blocks, reg, region_name);
454 } 843 }
455
456 kfree(buf);
457 } 844 }
458 845
459 pos += le32_to_cpu(blk->len) + sizeof(*blk); 846 tmp = le32_to_cpu(blk->len) % 4;
847 if (tmp)
848 pos += le32_to_cpu(blk->len) + (4 - tmp) + sizeof(*blk);
849 else
850 pos += le32_to_cpu(blk->len) + sizeof(*blk);
851
460 blocks++; 852 blocks++;
461 } 853 }
462 854
855 ret = regmap_async_complete(regmap);
856 if (ret != 0)
857 adsp_err(dsp, "Failed to complete async write: %d\n", ret);
858
463 if (pos > firmware->size) 859 if (pos > firmware->size)
464 adsp_warn(dsp, "%s.%d: %zu bytes at end of file\n", 860 adsp_warn(dsp, "%s.%d: %zu bytes at end of file\n",
465 file, blocks, pos - firmware->size); 861 file, blocks, pos - firmware->size);
466 862
467out_fw: 863out_fw:
468 release_firmware(firmware); 864 release_firmware(firmware);
865 wm_adsp_buf_free(&buf_list);
469out: 866out:
470 kfree(file); 867 kfree(file);
471 return 0; 868 return 0;
472} 869}
473 870
871int wm_adsp1_init(struct wm_adsp *adsp)
872{
873 INIT_LIST_HEAD(&adsp->alg_regions);
874
875 return 0;
876}
877EXPORT_SYMBOL_GPL(wm_adsp1_init);
878
474int wm_adsp1_event(struct snd_soc_dapm_widget *w, 879int wm_adsp1_event(struct snd_soc_dapm_widget *w,
475 struct snd_kcontrol *kcontrol, 880 struct snd_kcontrol *kcontrol,
476 int event) 881 int event)
@@ -479,16 +884,46 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
479 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); 884 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec);
480 struct wm_adsp *dsp = &dsps[w->shift]; 885 struct wm_adsp *dsp = &dsps[w->shift];
481 int ret; 886 int ret;
887 int val;
482 888
483 switch (event) { 889 switch (event) {
484 case SND_SOC_DAPM_POST_PMU: 890 case SND_SOC_DAPM_POST_PMU:
485 regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, 891 regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30,
486 ADSP1_SYS_ENA, ADSP1_SYS_ENA); 892 ADSP1_SYS_ENA, ADSP1_SYS_ENA);
487 893
894 /*
895 * For simplicity set the DSP clock rate to be the
896 * SYSCLK rate rather than making it configurable.
897 */
898 if(dsp->sysclk_reg) {
899 ret = regmap_read(dsp->regmap, dsp->sysclk_reg, &val);
900 if (ret != 0) {
901 adsp_err(dsp, "Failed to read SYSCLK state: %d\n",
902 ret);
903 return ret;
904 }
905
906 val = (val & dsp->sysclk_mask)
907 >> dsp->sysclk_shift;
908
909 ret = regmap_update_bits(dsp->regmap,
910 dsp->base + ADSP1_CONTROL_31,
911 ADSP1_CLK_SEL_MASK, val);
912 if (ret != 0) {
913 adsp_err(dsp, "Failed to set clock rate: %d\n",
914 ret);
915 return ret;
916 }
917 }
918
488 ret = wm_adsp_load(dsp); 919 ret = wm_adsp_load(dsp);
489 if (ret != 0) 920 if (ret != 0)
490 goto err; 921 goto err;
491 922
923 ret = wm_adsp_setup_algs(dsp);
924 if (ret != 0)
925 goto err;
926
492 ret = wm_adsp_load_coeff(dsp); 927 ret = wm_adsp_load_coeff(dsp);
493 if (ret != 0) 928 if (ret != 0)
494 goto err; 929 goto err;
@@ -560,6 +995,7 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
560 struct snd_soc_codec *codec = w->codec; 995 struct snd_soc_codec *codec = w->codec;
561 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); 996 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec);
562 struct wm_adsp *dsp = &dsps[w->shift]; 997 struct wm_adsp *dsp = &dsps[w->shift];
998 struct wm_adsp_alg_region *alg_region;
563 unsigned int val; 999 unsigned int val;
564 int ret; 1000 int ret;
565 1001
@@ -625,6 +1061,10 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
625 if (ret != 0) 1061 if (ret != 0)
626 goto err; 1062 goto err;
627 1063
1064 ret = wm_adsp_setup_algs(dsp);
1065 if (ret != 0)
1066 goto err;
1067
628 ret = wm_adsp_load_coeff(dsp); 1068 ret = wm_adsp_load_coeff(dsp);
629 if (ret != 0) 1069 if (ret != 0)
630 goto err; 1070 goto err;
@@ -635,13 +1075,22 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
635 ADSP2_CORE_ENA | ADSP2_START); 1075 ADSP2_CORE_ENA | ADSP2_START);
636 if (ret != 0) 1076 if (ret != 0)
637 goto err; 1077 goto err;
1078
1079 dsp->running = true;
638 break; 1080 break;
639 1081
640 case SND_SOC_DAPM_PRE_PMD: 1082 case SND_SOC_DAPM_PRE_PMD:
1083 dsp->running = false;
1084
641 regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, 1085 regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL,
642 ADSP2_SYS_ENA | ADSP2_CORE_ENA | 1086 ADSP2_SYS_ENA | ADSP2_CORE_ENA |
643 ADSP2_START, 0); 1087 ADSP2_START, 0);
644 1088
1089 /* Make sure DMAs are quiesced */
1090 regmap_write(dsp->regmap, dsp->base + ADSP2_WDMA_CONFIG_1, 0);
1091 regmap_write(dsp->regmap, dsp->base + ADSP2_WDMA_CONFIG_2, 0);
1092 regmap_write(dsp->regmap, dsp->base + ADSP2_RDMA_CONFIG_1, 0);
1093
645 if (dsp->dvfs) { 1094 if (dsp->dvfs) {
646 ret = regulator_set_voltage(dsp->dvfs, 1200000, 1095 ret = regulator_set_voltage(dsp->dvfs, 1200000,
647 1800000); 1096 1800000);
@@ -656,6 +1105,14 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
656 "Failed to enable supply: %d\n", 1105 "Failed to enable supply: %d\n",
657 ret); 1106 ret);
658 } 1107 }
1108
1109 while (!list_empty(&dsp->alg_regions)) {
1110 alg_region = list_first_entry(&dsp->alg_regions,
1111 struct wm_adsp_alg_region,
1112 list);
1113 list_del(&alg_region->list);
1114 kfree(alg_region);
1115 }
659 break; 1116 break;
660 1117
661 default: 1118 default:
@@ -685,6 +1142,8 @@ int wm_adsp2_init(struct wm_adsp *adsp, bool dvfs)
685 return ret; 1142 return ret;
686 } 1143 }
687 1144
1145 INIT_LIST_HEAD(&adsp->alg_regions);
1146
688 if (dvfs) { 1147 if (dvfs) {
689 adsp->dvfs = devm_regulator_get(adsp->dev, "DCVDD"); 1148 adsp->dvfs = devm_regulator_get(adsp->dev, "DCVDD");
690 if (IS_ERR(adsp->dvfs)) { 1149 if (IS_ERR(adsp->dvfs)) {
diff --git a/sound/soc/codecs/wm_adsp.h b/sound/soc/codecs/wm_adsp.h
index ffd29a4609e2..cb8871a3ec00 100644
--- a/sound/soc/codecs/wm_adsp.h
+++ b/sound/soc/codecs/wm_adsp.h
@@ -25,6 +25,13 @@ struct wm_adsp_region {
25 unsigned int base; 25 unsigned int base;
26}; 26};
27 27
28struct wm_adsp_alg_region {
29 struct list_head list;
30 unsigned int alg;
31 int type;
32 unsigned int base;
33};
34
28struct wm_adsp { 35struct wm_adsp {
29 const char *part; 36 const char *part;
30 int num; 37 int num;
@@ -33,10 +40,18 @@ struct wm_adsp {
33 struct regmap *regmap; 40 struct regmap *regmap;
34 41
35 int base; 42 int base;
43 int sysclk_reg;
44 int sysclk_mask;
45 int sysclk_shift;
46
47 struct list_head alg_regions;
36 48
37 const struct wm_adsp_region *mem; 49 const struct wm_adsp_region *mem;
38 int num_mems; 50 int num_mems;
39 51
52 int fw;
53 bool running;
54
40 struct regulator *dvfs; 55 struct regulator *dvfs;
41}; 56};
42 57
@@ -50,6 +65,9 @@ struct wm_adsp {
50 .shift = num, .event = wm_adsp2_event, \ 65 .shift = num, .event = wm_adsp2_event, \
51 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD } 66 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD }
52 67
68extern const struct snd_kcontrol_new wm_adsp_fw_controls[];
69
70int wm_adsp1_init(struct wm_adsp *adsp);
53int wm_adsp2_init(struct wm_adsp *adsp, bool dvfs); 71int wm_adsp2_init(struct wm_adsp *adsp, bool dvfs);
54int wm_adsp1_event(struct snd_soc_dapm_widget *w, 72int wm_adsp1_event(struct snd_soc_dapm_widget *w,
55 struct snd_kcontrol *kcontrol, int event); 73 struct snd_kcontrol *kcontrol, int event);
diff --git a/sound/soc/codecs/wmfw.h b/sound/soc/codecs/wmfw.h
index 5632ded67fdd..ef163360a745 100644
--- a/sound/soc/codecs/wmfw.h
+++ b/sound/soc/codecs/wmfw.h
@@ -93,15 +93,20 @@ struct wmfw_adsp2_alg_hdr {
93struct wmfw_coeff_hdr { 93struct wmfw_coeff_hdr {
94 u8 magic[4]; 94 u8 magic[4];
95 __le32 len; 95 __le32 len;
96 __le32 ver; 96 union {
97 __be32 rev;
98 __le32 ver;
99 };
100 union {
101 __be32 core;
102 __le32 core_ver;
103 };
97 u8 data[]; 104 u8 data[];
98} __packed; 105} __packed;
99 106
100struct wmfw_coeff_item { 107struct wmfw_coeff_item {
101 union { 108 __le16 offset;
102 __be32 type; 109 __le16 type;
103 __le32 offset;
104 };
105 __le32 id; 110 __le32 id;
106 __le32 ver; 111 __le32 ver;
107 __le32 sr; 112 __le32 sr;
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index d55e6477bff0..484b22c5df5d 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -116,9 +116,9 @@ static const struct snd_soc_dapm_route audio_map[] = {
116 {"Line Out", NULL, "RLOUT"}, 116 {"Line Out", NULL, "RLOUT"},
117 117
118 /* Mic connected to (MIC3L | MIC3R) */ 118 /* Mic connected to (MIC3L | MIC3R) */
119 {"MIC3L", NULL, "Mic Bias 2V"}, 119 {"MIC3L", NULL, "Mic Bias"},
120 {"MIC3R", NULL, "Mic Bias 2V"}, 120 {"MIC3R", NULL, "Mic Bias"},
121 {"Mic Bias 2V", NULL, "Mic Jack"}, 121 {"Mic Bias", NULL, "Mic Jack"},
122 122
123 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */ 123 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
124 {"LINE1L", NULL, "Line In"}, 124 {"LINE1L", NULL, "Line In"},
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 55e2bf652bef..9321e5c9d8c1 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -626,7 +626,7 @@ static int davinci_config_channel_size(struct davinci_audio_dev *dev,
626 int word_length) 626 int word_length)
627{ 627{
628 u32 fmt; 628 u32 fmt;
629 u32 rotate = (32 - word_length) / 4; 629 u32 rotate = (word_length / 4) & 0x7;
630 u32 mask = (1ULL << word_length) - 1; 630 u32 mask = (1ULL << word_length) - 1;
631 631
632 /* 632 /*
diff --git a/sound/soc/dwc/designware_i2s.c b/sound/soc/dwc/designware_i2s.c
index 1aa51300c564..deb30d59965e 100644
--- a/sound/soc/dwc/designware_i2s.c
+++ b/sound/soc/dwc/designware_i2s.c
@@ -210,15 +210,19 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream,
210 switch (config->chan_nr) { 210 switch (config->chan_nr) {
211 case EIGHT_CHANNEL_SUPPORT: 211 case EIGHT_CHANNEL_SUPPORT:
212 ch_reg = 3; 212 ch_reg = 3;
213 break;
213 case SIX_CHANNEL_SUPPORT: 214 case SIX_CHANNEL_SUPPORT:
214 ch_reg = 2; 215 ch_reg = 2;
216 break;
215 case FOUR_CHANNEL_SUPPORT: 217 case FOUR_CHANNEL_SUPPORT:
216 ch_reg = 1; 218 ch_reg = 1;
219 break;
217 case TWO_CHANNEL_SUPPORT: 220 case TWO_CHANNEL_SUPPORT:
218 ch_reg = 0; 221 ch_reg = 0;
219 break; 222 break;
220 default: 223 default:
221 dev_err(dev->dev, "channel not supported\n"); 224 dev_err(dev->dev, "channel not supported\n");
225 return -EINVAL;
222 } 226 }
223 227
224 i2s_disable_channels(dev, substream->stream); 228 i2s_disable_channels(dev, substream->stream);
diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index 251f4d981e0c..fab912ea7a50 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -176,7 +176,7 @@ static inline void audmux_debugfs_remove(void)
176} 176}
177#endif 177#endif
178 178
179enum imx_audmux_type { 179static enum imx_audmux_type {
180 IMX21_AUDMUX, 180 IMX21_AUDMUX,
181 IMX31_AUDMUX, 181 IMX31_AUDMUX,
182} audmux_type; 182} audmux_type;
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index b4b4cab30232..6cf8355a8542 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -16,33 +16,38 @@
16#define asoc_simple_get_card_info(p) \ 16#define asoc_simple_get_card_info(p) \
17 container_of(p->dai_link, struct asoc_simple_card_info, snd_link) 17 container_of(p->dai_link, struct asoc_simple_card_info, snd_link)
18 18
19static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
20 struct asoc_simple_dai *set,
21 unsigned int daifmt)
22{
23 int ret = 0;
24
25 daifmt |= set->fmt;
26
27 if (!ret && daifmt)
28 ret = snd_soc_dai_set_fmt(dai, daifmt);
29
30 if (!ret && set->sysclk)
31 ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
32
33 return ret;
34}
35
19static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) 36static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
20{ 37{
21 struct asoc_simple_card_info *cinfo = asoc_simple_get_card_info(rtd); 38 struct asoc_simple_card_info *info = asoc_simple_get_card_info(rtd);
22 struct asoc_simple_dai_init_info *iinfo = cinfo->init;
23 struct snd_soc_dai *codec = rtd->codec_dai; 39 struct snd_soc_dai *codec = rtd->codec_dai;
24 struct snd_soc_dai *cpu = rtd->cpu_dai; 40 struct snd_soc_dai *cpu = rtd->cpu_dai;
25 unsigned int cpu_daifmt = iinfo->fmt | iinfo->cpu_daifmt; 41 unsigned int daifmt = info->daifmt;
26 unsigned int codec_daifmt = iinfo->fmt | iinfo->codec_daifmt;
27 int ret; 42 int ret;
28 43
29 if (codec_daifmt) { 44 ret = __asoc_simple_card_dai_init(codec, &info->codec_dai, daifmt);
30 ret = snd_soc_dai_set_fmt(codec, codec_daifmt); 45 if (ret < 0)
31 if (ret < 0) 46 return ret;
32 return ret;
33 }
34
35 if (iinfo->sysclk) {
36 ret = snd_soc_dai_set_sysclk(codec, 0, iinfo->sysclk, 0);
37 if (ret < 0)
38 return ret;
39 }
40 47
41 if (cpu_daifmt) { 48 ret = __asoc_simple_card_dai_init(cpu, &info->cpu_dai, daifmt);
42 ret = snd_soc_dai_set_fmt(cpu, cpu_daifmt); 49 if (ret < 0)
43 if (ret < 0) 50 return ret;
44 return ret;
45 }
46 51
47 return 0; 52 return 0;
48} 53}
@@ -50,19 +55,20 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
50static int asoc_simple_card_probe(struct platform_device *pdev) 55static int asoc_simple_card_probe(struct platform_device *pdev)
51{ 56{
52 struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; 57 struct asoc_simple_card_info *cinfo = pdev->dev.platform_data;
58 struct device *dev = &pdev->dev;
53 59
54 if (!cinfo) { 60 if (!cinfo) {
55 dev_err(&pdev->dev, "no info for asoc-simple-card\n"); 61 dev_err(dev, "no info for asoc-simple-card\n");
56 return -EINVAL; 62 return -EINVAL;
57 } 63 }
58 64
59 if (!cinfo->name || 65 if (!cinfo->name ||
60 !cinfo->card || 66 !cinfo->card ||
61 !cinfo->cpu_dai ||
62 !cinfo->codec || 67 !cinfo->codec ||
63 !cinfo->platform || 68 !cinfo->platform ||
64 !cinfo->codec_dai) { 69 !cinfo->cpu_dai.name ||
65 dev_err(&pdev->dev, "insufficient asoc_simple_card_info settings\n"); 70 !cinfo->codec_dai.name) {
71 dev_err(dev, "insufficient asoc_simple_card_info settings\n");
66 return -EINVAL; 72 return -EINVAL;
67 } 73 }
68 74
@@ -71,14 +77,11 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
71 */ 77 */
72 cinfo->snd_link.name = cinfo->name; 78 cinfo->snd_link.name = cinfo->name;
73 cinfo->snd_link.stream_name = cinfo->name; 79 cinfo->snd_link.stream_name = cinfo->name;
74 cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai; 80 cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai.name;
75 cinfo->snd_link.platform_name = cinfo->platform; 81 cinfo->snd_link.platform_name = cinfo->platform;
76 cinfo->snd_link.codec_name = cinfo->codec; 82 cinfo->snd_link.codec_name = cinfo->codec;
77 cinfo->snd_link.codec_dai_name = cinfo->codec_dai; 83 cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name;
78 84 cinfo->snd_link.init = asoc_simple_card_dai_init;
79 /* enable snd_link.init if cinfo has settings */
80 if (cinfo->init)
81 cinfo->snd_link.init = asoc_simple_card_dai_init;
82 85
83 /* 86 /*
84 * init snd_soc_card 87 * init snd_soc_card
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index 365d9d27a321..e70e6c844f96 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -32,7 +32,6 @@
32#include <sound/pcm.h> 32#include <sound/pcm.h>
33#include <sound/pcm_params.h> 33#include <sound/pcm_params.h>
34#include <sound/soc.h> 34#include <sound/soc.h>
35#include <sound/saif.h>
36#include <asm/mach-types.h> 35#include <asm/mach-types.h>
37#include <mach/hardware.h> 36#include <mach/hardware.h>
38#include <mach/mxs.h> 37#include <mach/mxs.h>
@@ -662,46 +661,40 @@ static int mxs_saif_probe(struct platform_device *pdev)
662 struct device_node *np = pdev->dev.of_node; 661 struct device_node *np = pdev->dev.of_node;
663 struct resource *iores, *dmares; 662 struct resource *iores, *dmares;
664 struct mxs_saif *saif; 663 struct mxs_saif *saif;
665 struct mxs_saif_platform_data *pdata;
666 struct pinctrl *pinctrl; 664 struct pinctrl *pinctrl;
667 int ret = 0; 665 int ret = 0;
666 struct device_node *master;
668 667
669 668 if (!np)
670 if (!np && pdev->id >= ARRAY_SIZE(mxs_saif))
671 return -EINVAL; 669 return -EINVAL;
672 670
673 saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL); 671 saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL);
674 if (!saif) 672 if (!saif)
675 return -ENOMEM; 673 return -ENOMEM;
676 674
677 if (np) { 675 ret = of_alias_get_id(np, "saif");
678 struct device_node *master; 676 if (ret < 0)
679 saif->id = of_alias_get_id(np, "saif"); 677 return ret;
680 if (saif->id < 0) 678 else
681 return saif->id; 679 saif->id = ret;
682 /* 680
683 * If there is no "fsl,saif-master" phandle, it's a saif 681 /*
684 * master. Otherwise, it's a slave and its phandle points 682 * If there is no "fsl,saif-master" phandle, it's a saif
685 * to the master. 683 * master. Otherwise, it's a slave and its phandle points
686 */ 684 * to the master.
687 master = of_parse_phandle(np, "fsl,saif-master", 0); 685 */
688 if (!master) { 686 master = of_parse_phandle(np, "fsl,saif-master", 0);
689 saif->master_id = saif->id; 687 if (!master) {
690 } else { 688 saif->master_id = saif->id;
691 saif->master_id = of_alias_get_id(master, "saif");
692 if (saif->master_id < 0)
693 return saif->master_id;
694 }
695 } else { 689 } else {
696 saif->id = pdev->id; 690 ret = of_alias_get_id(master, "saif");
697 pdata = pdev->dev.platform_data; 691 if (ret < 0)
698 if (pdata && !pdata->master_mode) 692 return ret;
699 saif->master_id = pdata->master_id;
700 else 693 else
701 saif->master_id = saif->id; 694 saif->master_id = ret;
702 } 695 }
703 696
704 if (saif->master_id < 0 || saif->master_id >= ARRAY_SIZE(mxs_saif)) { 697 if (saif->master_id >= ARRAY_SIZE(mxs_saif)) {
705 dev_err(&pdev->dev, "get wrong master id\n"); 698 dev_err(&pdev->dev, "get wrong master id\n");
706 return -EINVAL; 699 return -EINVAL;
707 } 700 }
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index 7048137f9a33..60259f2f3f2c 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -70,15 +70,6 @@ config SND_OMAP_SOC_AM3517EVM
70 Say Y if you want to add support for SoC audio on the OMAP3517 / AM3517 70 Say Y if you want to add support for SoC audio on the OMAP3517 / AM3517
71 EVM. 71 EVM.
72 72
73config SND_OMAP_SOC_SDP3430
74 tristate "SoC Audio support for Texas Instruments SDP3430"
75 depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP_3430SDP
76 select SND_OMAP_SOC_MCBSP
77 select SND_SOC_TWL4030
78 help
79 Say Y if you want to add support for SoC audio on Texas Instruments
80 SDP3430.
81
82config SND_OMAP_SOC_OMAP_TWL4030 73config SND_OMAP_SOC_OMAP_TWL4030
83 tristate "SoC Audio support for TI SoC based boards with twl4030 codec" 74 tristate "SoC Audio support for TI SoC based boards with twl4030 codec"
84 depends on TWL4030_CORE && SND_OMAP_SOC 75 depends on TWL4030_CORE && SND_OMAP_SOC
@@ -91,6 +82,8 @@ config SND_OMAP_SOC_OMAP_TWL4030
91 - Gumstix Overo or CompuLab CM-T35/CM-T3730 82 - Gumstix Overo or CompuLab CM-T35/CM-T3730
92 - IGEP v2 83 - IGEP v2
93 - OMAP3EVM 84 - OMAP3EVM
85 - SDP3430
86 - Zoom2
94 87
95config SND_OMAP_SOC_OMAP_ABE_TWL6040 88config SND_OMAP_SOC_OMAP_ABE_TWL6040
96 tristate "SoC Audio support for OMAP boards using ABE and twl6040 codec" 89 tristate "SoC Audio support for OMAP boards using ABE and twl6040 codec"
@@ -123,11 +116,3 @@ config SND_OMAP_SOC_OMAP3_PANDORA
123 select SND_SOC_TWL4030 116 select SND_SOC_TWL4030
124 help 117 help
125 Say Y if you want to add support for SoC audio on the OMAP3 Pandora. 118 Say Y if you want to add support for SoC audio on the OMAP3 Pandora.
126
127config SND_OMAP_SOC_ZOOM2
128 tristate "SoC Audio support for Zoom2"
129 depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP_ZOOM2
130 select SND_OMAP_SOC_MCBSP
131 select SND_SOC_TWL4030
132 help
133 Say Y if you want to add support for Soc audio on Zoom2 board.
diff --git a/sound/soc/omap/Makefile b/sound/soc/omap/Makefile
index 19637e55ea48..2b225945359b 100644
--- a/sound/soc/omap/Makefile
+++ b/sound/soc/omap/Makefile
@@ -17,11 +17,9 @@ snd-soc-rx51-objs := rx51.o
17snd-soc-ams-delta-objs := ams-delta.o 17snd-soc-ams-delta-objs := ams-delta.o
18snd-soc-osk5912-objs := osk5912.o 18snd-soc-osk5912-objs := osk5912.o
19snd-soc-am3517evm-objs := am3517evm.o 19snd-soc-am3517evm-objs := am3517evm.o
20snd-soc-sdp3430-objs := sdp3430.o
21snd-soc-omap-abe-twl6040-objs := omap-abe-twl6040.o 20snd-soc-omap-abe-twl6040-objs := omap-abe-twl6040.o
22snd-soc-omap-twl4030-objs := omap-twl4030.o 21snd-soc-omap-twl4030-objs := omap-twl4030.o
23snd-soc-omap3pandora-objs := omap3pandora.o 22snd-soc-omap3pandora-objs := omap3pandora.o
24snd-soc-zoom2-objs := zoom2.o
25snd-soc-omap-hdmi-card-objs := omap-hdmi-card.o 23snd-soc-omap-hdmi-card-objs := omap-hdmi-card.o
26 24
27obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o 25obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o
@@ -30,9 +28,7 @@ obj-$(CONFIG_SND_OMAP_SOC_AMS_DELTA) += snd-soc-ams-delta.o
30obj-$(CONFIG_SND_OMAP_SOC_OSK5912) += snd-soc-osk5912.o 28obj-$(CONFIG_SND_OMAP_SOC_OSK5912) += snd-soc-osk5912.o
31obj-$(CONFIG_SND_OMAP_SOC_OMAP2EVM) += snd-soc-omap2evm.o 29obj-$(CONFIG_SND_OMAP_SOC_OMAP2EVM) += snd-soc-omap2evm.o
32obj-$(CONFIG_SND_OMAP_SOC_AM3517EVM) += snd-soc-am3517evm.o 30obj-$(CONFIG_SND_OMAP_SOC_AM3517EVM) += snd-soc-am3517evm.o
33obj-$(CONFIG_SND_OMAP_SOC_SDP3430) += snd-soc-sdp3430.o
34obj-$(CONFIG_SND_OMAP_SOC_OMAP_ABE_TWL6040) += snd-soc-omap-abe-twl6040.o 31obj-$(CONFIG_SND_OMAP_SOC_OMAP_ABE_TWL6040) += snd-soc-omap-abe-twl6040.o
35obj-$(CONFIG_SND_OMAP_SOC_OMAP_TWL4030) += snd-soc-omap-twl4030.o 32obj-$(CONFIG_SND_OMAP_SOC_OMAP_TWL4030) += snd-soc-omap-twl4030.o
36obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o 33obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o
37obj-$(CONFIG_SND_OMAP_SOC_ZOOM2) += snd-soc-zoom2.o
38obj-$(CONFIG_SND_OMAP_SOC_OMAP_HDMI) += snd-soc-omap-hdmi-card.o 34obj-$(CONFIG_SND_OMAP_SOC_OMAP_HDMI) += snd-soc-omap-hdmi-card.o
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
index 230b8c144848..ee7cd53aa3ee 100644
--- a/sound/soc/omap/n810.c
+++ b/sound/soc/omap/n810.c
@@ -230,8 +230,8 @@ static const struct snd_soc_dapm_route audio_map[] = {
230 {"Ext Spk", NULL, "LLOUT"}, 230 {"Ext Spk", NULL, "LLOUT"},
231 {"Ext Spk", NULL, "RLOUT"}, 231 {"Ext Spk", NULL, "RLOUT"},
232 232
233 {"DMic Rate 64", NULL, "Mic Bias 2V"}, 233 {"DMic Rate 64", NULL, "Mic Bias"},
234 {"Mic Bias 2V", NULL, "DMic"}, 234 {"Mic Bias", NULL, "DMic"},
235}; 235};
236 236
237static const char *spk_function[] = {"Off", "On"}; 237static const char *spk_function[] = {"Off", "On"};
diff --git a/sound/soc/omap/omap-hdmi.c b/sound/soc/omap/omap-hdmi.c
index 7ea24819d570..32fa840c493e 100644
--- a/sound/soc/omap/omap-hdmi.c
+++ b/sound/soc/omap/omap-hdmi.c
@@ -110,6 +110,8 @@ static int omap_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
110 /* 110 /*
111 * fill the IEC-60958 channel status word 111 * fill the IEC-60958 channel status word
112 */ 112 */
113 /* initialize the word bytes */
114 memset(iec->status, 0, sizeof(iec->status));
113 115
114 /* specify IEC-60958-3 (commercial use) */ 116 /* specify IEC-60958-3 (commercial use) */
115 iec->status[0] &= ~IEC958_AES0_PROFESSIONAL; 117 iec->status[0] &= ~IEC958_AES0_PROFESSIONAL;
diff --git a/sound/soc/omap/omap-mcpdm.c b/sound/soc/omap/omap-mcpdm.c
index 2fe8be209452..5ca11bdac21e 100644
--- a/sound/soc/omap/omap-mcpdm.c
+++ b/sound/soc/omap/omap-mcpdm.c
@@ -449,10 +449,6 @@ static int asoc_mcpdm_probe(struct platform_device *pdev)
449 omap_mcpdm_dai_dma_params[0].port_addr = res->start + MCPDM_REG_DN_DATA; 449 omap_mcpdm_dai_dma_params[0].port_addr = res->start + MCPDM_REG_DN_DATA;
450 omap_mcpdm_dai_dma_params[1].port_addr = res->start + MCPDM_REG_UP_DATA; 450 omap_mcpdm_dai_dma_params[1].port_addr = res->start + MCPDM_REG_UP_DATA;
451 451
452 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
453 if (res == NULL)
454 return -ENOMEM;
455
456 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "dn_link"); 452 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "dn_link");
457 if (!res) 453 if (!res)
458 return -ENODEV; 454 return -ENODEV;
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c
index 47bdbd415ad8..c722c2ef9665 100644
--- a/sound/soc/omap/omap-pcm.c
+++ b/sound/soc/omap/omap-pcm.c
@@ -174,23 +174,15 @@ static snd_pcm_uframes_t omap_pcm_pointer(struct snd_pcm_substream *substream)
174 174
175static int omap_pcm_open(struct snd_pcm_substream *substream) 175static int omap_pcm_open(struct snd_pcm_substream *substream)
176{ 176{
177 struct snd_pcm_runtime *runtime = substream->runtime;
178 struct snd_soc_pcm_runtime *rtd = substream->private_data; 177 struct snd_soc_pcm_runtime *rtd = substream->private_data;
179 struct omap_pcm_dma_data *dma_data; 178 struct omap_pcm_dma_data *dma_data;
180 int ret;
181 179
182 snd_soc_set_runtime_hwparams(substream, &omap_pcm_hardware); 180 snd_soc_set_runtime_hwparams(substream, &omap_pcm_hardware);
183 181
184 /* Ensure that buffer size is a multiple of period size */
185 ret = snd_pcm_hw_constraint_integer(runtime,
186 SNDRV_PCM_HW_PARAM_PERIODS);
187 if (ret < 0)
188 return ret;
189
190 dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); 182 dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
191 ret = snd_dmaengine_pcm_open(substream, omap_dma_filter_fn, 183
192 &dma_data->dma_req); 184 return snd_dmaengine_pcm_open(substream, omap_dma_filter_fn,
193 return ret; 185 &dma_data->dma_req);
194} 186}
195 187
196static int omap_pcm_close(struct snd_pcm_substream *substream) 188static int omap_pcm_close(struct snd_pcm_substream *substream)
diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4030.c
index 4541d28b5314..fd98509d0f49 100644
--- a/sound/soc/omap/omap-twl4030.c
+++ b/sound/soc/omap/omap-twl4030.c
@@ -11,6 +11,8 @@
11 * omap3evm (Author: Anuj Aggarwal <anuj.aggarwal@ti.com>) 11 * omap3evm (Author: Anuj Aggarwal <anuj.aggarwal@ti.com>)
12 * overo (Author: Steve Sakoman <steve@sakoman.com>) 12 * overo (Author: Steve Sakoman <steve@sakoman.com>)
13 * igep0020 (Author: Enric Balletbo i Serra <eballetbo@iseebcn.com>) 13 * igep0020 (Author: Enric Balletbo i Serra <eballetbo@iseebcn.com>)
14 * zoom2 (Author: Misael Lopez Cruz <misael.lopez@ti.com>)
15 * sdp3430 (Author: Misael Lopez Cruz <misael.lopez@ti.com>)
14 * 16 *
15 * This program is free software; you can redistribute it and/or 17 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License 18 * modify it under the terms of the GNU General Public License
@@ -32,14 +34,22 @@
32#include <linux/platform_data/omap-twl4030.h> 34#include <linux/platform_data/omap-twl4030.h>
33#include <linux/module.h> 35#include <linux/module.h>
34#include <linux/of.h> 36#include <linux/of.h>
37#include <linux/gpio.h>
38#include <linux/of_gpio.h>
35 39
36#include <sound/core.h> 40#include <sound/core.h>
37#include <sound/pcm.h> 41#include <sound/pcm.h>
38#include <sound/soc.h> 42#include <sound/soc.h>
43#include <sound/jack.h>
39 44
40#include "omap-mcbsp.h" 45#include "omap-mcbsp.h"
41#include "omap-pcm.h" 46#include "omap-pcm.h"
42 47
48struct omap_twl4030 {
49 int jack_detect; /* board can detect jack events */
50 struct snd_soc_jack hs_jack;
51};
52
43static int omap_twl4030_hw_params(struct snd_pcm_substream *substream, 53static int omap_twl4030_hw_params(struct snd_pcm_substream *substream,
44 struct snd_pcm_hw_params *params) 54 struct snd_pcm_hw_params *params)
45{ 55{
@@ -87,17 +97,164 @@ static struct snd_soc_ops omap_twl4030_ops = {
87 .hw_params = omap_twl4030_hw_params, 97 .hw_params = omap_twl4030_hw_params,
88}; 98};
89 99
100static const struct snd_soc_dapm_widget dapm_widgets[] = {
101 SND_SOC_DAPM_SPK("Earpiece Spk", NULL),
102 SND_SOC_DAPM_SPK("Handsfree Spk", NULL),
103 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
104 SND_SOC_DAPM_SPK("Ext Spk", NULL),
105 SND_SOC_DAPM_SPK("Carkit Spk", NULL),
106
107 SND_SOC_DAPM_MIC("Main Mic", NULL),
108 SND_SOC_DAPM_MIC("Sub Mic", NULL),
109 SND_SOC_DAPM_MIC("Headset Mic", NULL),
110 SND_SOC_DAPM_MIC("Carkit Mic", NULL),
111 SND_SOC_DAPM_MIC("Digital0 Mic", NULL),
112 SND_SOC_DAPM_MIC("Digital1 Mic", NULL),
113 SND_SOC_DAPM_LINE("Line In", NULL),
114};
115
116static const struct snd_soc_dapm_route audio_map[] = {
117 /* Headset Stereophone: HSOL, HSOR */
118 {"Headset Stereophone", NULL, "HSOL"},
119 {"Headset Stereophone", NULL, "HSOR"},
120 /* External Speakers: HFL, HFR */
121 {"Handsfree Spk", NULL, "HFL"},
122 {"Handsfree Spk", NULL, "HFR"},
123 /* External Speakers: PredrivL, PredrivR */
124 {"Ext Spk", NULL, "PREDRIVEL"},
125 {"Ext Spk", NULL, "PREDRIVER"},
126 /* Carkit speakers: CARKITL, CARKITR */
127 {"Carkit Spk", NULL, "CARKITL"},
128 {"Carkit Spk", NULL, "CARKITR"},
129 /* Earpiece */
130 {"Earpiece Spk", NULL, "EARPIECE"},
131
132 /* External Mics: MAINMIC, SUBMIC with bias */
133 {"MAINMIC", NULL, "Main Mic"},
134 {"Main Mic", NULL, "Mic Bias 1"},
135 {"SUBMIC", NULL, "Sub Mic"},
136 {"Sub Mic", NULL, "Mic Bias 2"},
137 /* Headset Mic: HSMIC with bias */
138 {"HSMIC", NULL, "Headset Mic"},
139 {"Headset Mic", NULL, "Headset Mic Bias"},
140 /* Digital Mics: DIGIMIC0, DIGIMIC1 with bias */
141 {"DIGIMIC0", NULL, "Digital0 Mic"},
142 {"Digital0 Mic", NULL, "Mic Bias 1"},
143 {"DIGIMIC1", NULL, "Digital1 Mic"},
144 {"Digital1 Mic", NULL, "Mic Bias 2"},
145 /* Carkit In: CARKITMIC */
146 {"CARKITMIC", NULL, "Carkit Mic"},
147 /* Aux In: AUXL, AUXR */
148 {"AUXL", NULL, "Line In"},
149 {"AUXR", NULL, "Line In"},
150};
151
152/* Headset jack detection DAPM pins */
153static struct snd_soc_jack_pin hs_jack_pins[] = {
154 {
155 .pin = "Headset Mic",
156 .mask = SND_JACK_MICROPHONE,
157 },
158 {
159 .pin = "Headset Stereophone",
160 .mask = SND_JACK_HEADPHONE,
161 },
162};
163
164/* Headset jack detection gpios */
165static struct snd_soc_jack_gpio hs_jack_gpios[] = {
166 {
167 .name = "hsdet-gpio",
168 .report = SND_JACK_HEADSET,
169 .debounce_time = 200,
170 },
171};
172
173static inline void twl4030_disconnect_pin(struct snd_soc_dapm_context *dapm,
174 int connected, char *pin)
175{
176 if (!connected)
177 snd_soc_dapm_disable_pin(dapm, pin);
178}
179
180static int omap_twl4030_init(struct snd_soc_pcm_runtime *rtd)
181{
182 struct snd_soc_codec *codec = rtd->codec;
183 struct snd_soc_card *card = codec->card;
184 struct snd_soc_dapm_context *dapm = &codec->dapm;
185 struct omap_tw4030_pdata *pdata = dev_get_platdata(card->dev);
186 struct omap_twl4030 *priv = snd_soc_card_get_drvdata(card);
187 int ret = 0;
188
189 /* Headset jack detection only if it is supported */
190 if (priv->jack_detect > 0) {
191 hs_jack_gpios[0].gpio = priv->jack_detect;
192
193 ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
194 &priv->hs_jack);
195 if (ret)
196 return ret;
197
198 ret = snd_soc_jack_add_pins(&priv->hs_jack,
199 ARRAY_SIZE(hs_jack_pins),
200 hs_jack_pins);
201 if (ret)
202 return ret;
203
204 ret = snd_soc_jack_add_gpios(&priv->hs_jack,
205 ARRAY_SIZE(hs_jack_gpios),
206 hs_jack_gpios);
207 if (ret)
208 return ret;
209 }
210
211 /*
212 * NULL pdata means we booted with DT. In this case the routing is
213 * provided and the card is fully routed, no need to mark pins.
214 */
215 if (!pdata || !pdata->custom_routing)
216 return ret;
217
218 /* Disable not connected paths if not used */
219 twl4030_disconnect_pin(dapm, pdata->has_ear, "Earpiece Spk");
220 twl4030_disconnect_pin(dapm, pdata->has_hf, "Handsfree Spk");
221 twl4030_disconnect_pin(dapm, pdata->has_hs, "Headset Stereophone");
222 twl4030_disconnect_pin(dapm, pdata->has_predriv, "Ext Spk");
223 twl4030_disconnect_pin(dapm, pdata->has_carkit, "Carkit Spk");
224
225 twl4030_disconnect_pin(dapm, pdata->has_mainmic, "Main Mic");
226 twl4030_disconnect_pin(dapm, pdata->has_submic, "Sub Mic");
227 twl4030_disconnect_pin(dapm, pdata->has_hsmic, "Headset Mic");
228 twl4030_disconnect_pin(dapm, pdata->has_carkitmic, "Carkit Mic");
229 twl4030_disconnect_pin(dapm, pdata->has_digimic0, "Digital0 Mic");
230 twl4030_disconnect_pin(dapm, pdata->has_digimic1, "Digital1 Mic");
231 twl4030_disconnect_pin(dapm, pdata->has_linein, "Line In");
232
233 return ret;
234}
235
90/* Digital audio interface glue - connects codec <--> CPU */ 236/* Digital audio interface glue - connects codec <--> CPU */
91static struct snd_soc_dai_link omap_twl4030_dai_links[] = { 237static struct snd_soc_dai_link omap_twl4030_dai_links[] = {
92 { 238 {
93 .name = "TWL4030", 239 .name = "TWL4030 HiFi",
94 .stream_name = "TWL4030", 240 .stream_name = "TWL4030 HiFi",
95 .cpu_dai_name = "omap-mcbsp.2", 241 .cpu_dai_name = "omap-mcbsp.2",
96 .codec_dai_name = "twl4030-hifi", 242 .codec_dai_name = "twl4030-hifi",
97 .platform_name = "omap-pcm-audio", 243 .platform_name = "omap-pcm-audio",
98 .codec_name = "twl4030-codec", 244 .codec_name = "twl4030-codec",
245 .init = omap_twl4030_init,
99 .ops = &omap_twl4030_ops, 246 .ops = &omap_twl4030_ops,
100 }, 247 },
248 {
249 .name = "TWL4030 Voice",
250 .stream_name = "TWL4030 Voice",
251 .cpu_dai_name = "omap-mcbsp.3",
252 .codec_dai_name = "twl4030-voice",
253 .platform_name = "omap-pcm-audio",
254 .codec_name = "twl4030-codec",
255 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
256 SND_SOC_DAIFMT_CBM_CFM,
257 },
101}; 258};
102 259
103/* Audio machine driver */ 260/* Audio machine driver */
@@ -105,6 +262,11 @@ static struct snd_soc_card omap_twl4030_card = {
105 .owner = THIS_MODULE, 262 .owner = THIS_MODULE,
106 .dai_link = omap_twl4030_dai_links, 263 .dai_link = omap_twl4030_dai_links,
107 .num_links = ARRAY_SIZE(omap_twl4030_dai_links), 264 .num_links = ARRAY_SIZE(omap_twl4030_dai_links),
265
266 .dapm_widgets = dapm_widgets,
267 .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
268 .dapm_routes = audio_map,
269 .num_dapm_routes = ARRAY_SIZE(audio_map),
108}; 270};
109 271
110static int omap_twl4030_probe(struct platform_device *pdev) 272static int omap_twl4030_probe(struct platform_device *pdev)
@@ -112,12 +274,18 @@ static int omap_twl4030_probe(struct platform_device *pdev)
112 struct omap_tw4030_pdata *pdata = dev_get_platdata(&pdev->dev); 274 struct omap_tw4030_pdata *pdata = dev_get_platdata(&pdev->dev);
113 struct device_node *node = pdev->dev.of_node; 275 struct device_node *node = pdev->dev.of_node;
114 struct snd_soc_card *card = &omap_twl4030_card; 276 struct snd_soc_card *card = &omap_twl4030_card;
277 struct omap_twl4030 *priv;
115 int ret = 0; 278 int ret = 0;
116 279
117 card->dev = &pdev->dev; 280 card->dev = &pdev->dev;
118 281
282 priv = devm_kzalloc(&pdev->dev, sizeof(struct omap_twl4030), GFP_KERNEL);
283 if (priv == NULL)
284 return -ENOMEM;
285
119 if (node) { 286 if (node) {
120 struct device_node *dai_node; 287 struct device_node *dai_node;
288 struct property *prop;
121 289
122 if (snd_soc_of_parse_card_name(card, "ti,model")) { 290 if (snd_soc_of_parse_card_name(card, "ti,model")) {
123 dev_err(&pdev->dev, "Card name is not provided\n"); 291 dev_err(&pdev->dev, "Card name is not provided\n");
@@ -132,6 +300,27 @@ static int omap_twl4030_probe(struct platform_device *pdev)
132 omap_twl4030_dai_links[0].cpu_dai_name = NULL; 300 omap_twl4030_dai_links[0].cpu_dai_name = NULL;
133 omap_twl4030_dai_links[0].cpu_of_node = dai_node; 301 omap_twl4030_dai_links[0].cpu_of_node = dai_node;
134 302
303 dai_node = of_parse_phandle(node, "ti,mcbsp-voice", 0);
304 if (!dai_node) {
305 card->num_links = 1;
306 } else {
307 omap_twl4030_dai_links[1].cpu_dai_name = NULL;
308 omap_twl4030_dai_links[1].cpu_of_node = dai_node;
309 }
310
311 priv->jack_detect = of_get_named_gpio(node,
312 "ti,jack-det-gpio", 0);
313
314 /* Optional: audio routing can be provided */
315 prop = of_find_property(node, "ti,audio-routing", NULL);
316 if (prop) {
317 ret = snd_soc_of_parse_audio_routing(card,
318 "ti,audio-routing");
319 if (ret)
320 return ret;
321
322 card->fully_routed = 1;
323 }
135 } else if (pdata) { 324 } else if (pdata) {
136 if (pdata->card_name) { 325 if (pdata->card_name) {
137 card->name = pdata->card_name; 326 card->name = pdata->card_name;
@@ -139,11 +328,17 @@ static int omap_twl4030_probe(struct platform_device *pdev)
139 dev_err(&pdev->dev, "Card name is not provided\n"); 328 dev_err(&pdev->dev, "Card name is not provided\n");
140 return -ENODEV; 329 return -ENODEV;
141 } 330 }
331
332 if (!pdata->voice_connected)
333 card->num_links = 1;
334
335 priv->jack_detect = pdata->jack_detect;
142 } else { 336 } else {
143 dev_err(&pdev->dev, "Missing pdata\n"); 337 dev_err(&pdev->dev, "Missing pdata\n");
144 return -ENODEV; 338 return -ENODEV;
145 } 339 }
146 340
341 snd_soc_card_set_drvdata(card, priv);
147 ret = snd_soc_register_card(card); 342 ret = snd_soc_register_card(card);
148 if (ret) { 343 if (ret) {
149 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 344 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
@@ -157,7 +352,12 @@ static int omap_twl4030_probe(struct platform_device *pdev)
157static int omap_twl4030_remove(struct platform_device *pdev) 352static int omap_twl4030_remove(struct platform_device *pdev)
158{ 353{
159 struct snd_soc_card *card = platform_get_drvdata(pdev); 354 struct snd_soc_card *card = platform_get_drvdata(pdev);
355 struct omap_twl4030 *priv = snd_soc_card_get_drvdata(card);
160 356
357 if (priv->jack_detect > 0)
358 snd_soc_jack_free_gpios(&priv->hs_jack,
359 ARRAY_SIZE(hs_jack_gpios),
360 hs_jack_gpios);
161 snd_soc_unregister_card(card); 361 snd_soc_unregister_card(card);
162 362
163 return 0; 363 return 0;
diff --git a/sound/soc/omap/omap3pandora.c b/sound/soc/omap/omap3pandora.c
index 43d950a79ff9..805512f2555a 100644
--- a/sound/soc/omap/omap3pandora.c
+++ b/sound/soc/omap/omap3pandora.c
@@ -144,11 +144,11 @@ static const struct snd_soc_dapm_route omap3pandora_in_map[] = {
144 {"AUXL", NULL, "Line In"}, 144 {"AUXL", NULL, "Line In"},
145 {"AUXR", NULL, "Line In"}, 145 {"AUXR", NULL, "Line In"},
146 146
147 {"MAINMIC", NULL, "Mic Bias 1"}, 147 {"MAINMIC", NULL, "Mic (internal)"},
148 {"Mic Bias 1", NULL, "Mic (internal)"}, 148 {"Mic (internal)", NULL, "Mic Bias 1"},
149 149
150 {"SUBMIC", NULL, "Mic Bias 2"}, 150 {"SUBMIC", NULL, "Mic (external)"},
151 {"Mic Bias 2", NULL, "Mic (external)"}, 151 {"Mic (external)", NULL, "Mic Bias 2"},
152}; 152};
153 153
154static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd) 154static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd)
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c
index d921ddbe3ecb..3cd525748975 100644
--- a/sound/soc/omap/rx51.c
+++ b/sound/soc/omap/rx51.c
@@ -248,16 +248,16 @@ static const struct snd_soc_dapm_route audio_map[] = {
248 {"FM Transmitter", NULL, "LLOUT"}, 248 {"FM Transmitter", NULL, "LLOUT"},
249 {"FM Transmitter", NULL, "RLOUT"}, 249 {"FM Transmitter", NULL, "RLOUT"},
250 250
251 {"DMic Rate 64", NULL, "Mic Bias 2V"}, 251 {"DMic Rate 64", NULL, "Mic Bias"},
252 {"Mic Bias 2V", NULL, "DMic"}, 252 {"Mic Bias", NULL, "DMic"},
253}; 253};
254 254
255static const struct snd_soc_dapm_route audio_mapb[] = { 255static const struct snd_soc_dapm_route audio_mapb[] = {
256 {"b LINE2R", NULL, "MONO_LOUT"}, 256 {"b LINE2R", NULL, "MONO_LOUT"},
257 {"Earphone", NULL, "b HPLOUT"}, 257 {"Earphone", NULL, "b HPLOUT"},
258 258
259 {"LINE1L", NULL, "b Mic Bias 2.5V"}, 259 {"LINE1L", NULL, "b Mic Bias"},
260 {"b Mic Bias 2.5V", NULL, "HS Mic"} 260 {"b Mic Bias", NULL, "HS Mic"}
261}; 261};
262 262
263static const char *spk_function[] = {"Off", "On"}; 263static const char *spk_function[] = {"Off", "On"};
diff --git a/sound/soc/omap/sdp3430.c b/sound/soc/omap/sdp3430.c
deleted file mode 100644
index b462a2c9385f..000000000000
--- a/sound/soc/omap/sdp3430.c
+++ /dev/null
@@ -1,278 +0,0 @@
1/*
2 * sdp3430.c -- SoC audio for TI OMAP3430 SDP
3 *
4 * Author: Misael Lopez Cruz <x0052729@ti.com>
5 *
6 * Based on:
7 * Author: Steve Sakoman <steve@sakoman.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * 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., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/clk.h>
26#include <linux/platform_device.h>
27#include <linux/i2c/twl.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/soc.h>
31#include <sound/jack.h>
32
33#include <asm/mach-types.h>
34#include <linux/platform_data/gpio-omap.h>
35#include <linux/platform_data/asoc-ti-mcbsp.h>
36
37/* Register descriptions for twl4030 codec part */
38#include <linux/mfd/twl4030-audio.h>
39#include <linux/module.h>
40
41#include "omap-mcbsp.h"
42#include "omap-pcm.h"
43
44/* TWL4030 PMBR1 Register */
45#define TWL4030_INTBR_PMBR1 0x0D
46/* TWL4030 PMBR1 Register GPIO6 mux bit */
47#define TWL4030_GPIO6_PWM0_MUTE(value) (value << 2)
48
49static struct snd_soc_card snd_soc_sdp3430;
50
51static int sdp3430_hw_params(struct snd_pcm_substream *substream,
52 struct snd_pcm_hw_params *params)
53{
54 struct snd_soc_pcm_runtime *rtd = substream->private_data;
55 struct snd_soc_dai *codec_dai = rtd->codec_dai;
56 int ret;
57
58 /* Set the codec system clock for DAC and ADC */
59 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
60 SND_SOC_CLOCK_IN);
61 if (ret < 0) {
62 printk(KERN_ERR "can't set codec system clock\n");
63 return ret;
64 }
65
66 return 0;
67}
68
69static struct snd_soc_ops sdp3430_ops = {
70 .hw_params = sdp3430_hw_params,
71};
72
73/* Headset jack */
74static struct snd_soc_jack hs_jack;
75
76/* Headset jack detection DAPM pins */
77static struct snd_soc_jack_pin hs_jack_pins[] = {
78 {
79 .pin = "Headset Mic",
80 .mask = SND_JACK_MICROPHONE,
81 },
82 {
83 .pin = "Headset Stereophone",
84 .mask = SND_JACK_HEADPHONE,
85 },
86};
87
88/* Headset jack detection gpios */
89static struct snd_soc_jack_gpio hs_jack_gpios[] = {
90 {
91 .gpio = (OMAP_MAX_GPIO_LINES + 2),
92 .name = "hsdet-gpio",
93 .report = SND_JACK_HEADSET,
94 .debounce_time = 200,
95 },
96};
97
98/* SDP3430 machine DAPM */
99static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
100 SND_SOC_DAPM_MIC("Ext Mic", NULL),
101 SND_SOC_DAPM_SPK("Ext Spk", NULL),
102 SND_SOC_DAPM_MIC("Headset Mic", NULL),
103 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
104};
105
106static const struct snd_soc_dapm_route audio_map[] = {
107 /* External Mics: MAINMIC, SUBMIC with bias*/
108 {"MAINMIC", NULL, "Mic Bias 1"},
109 {"SUBMIC", NULL, "Mic Bias 2"},
110 {"Mic Bias 1", NULL, "Ext Mic"},
111 {"Mic Bias 2", NULL, "Ext Mic"},
112
113 /* External Speakers: HFL, HFR */
114 {"Ext Spk", NULL, "HFL"},
115 {"Ext Spk", NULL, "HFR"},
116
117 /* Headset Mic: HSMIC with bias */
118 {"HSMIC", NULL, "Headset Mic Bias"},
119 {"Headset Mic Bias", NULL, "Headset Mic"},
120
121 /* Headset Stereophone (Headphone): HSOL, HSOR */
122 {"Headset Stereophone", NULL, "HSOL"},
123 {"Headset Stereophone", NULL, "HSOR"},
124};
125
126static int sdp3430_twl4030_init(struct snd_soc_pcm_runtime *rtd)
127{
128 struct snd_soc_codec *codec = rtd->codec;
129 struct snd_soc_dapm_context *dapm = &codec->dapm;
130 int ret;
131
132 /* SDP3430 connected pins */
133 snd_soc_dapm_enable_pin(dapm, "Ext Mic");
134 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
135 snd_soc_dapm_disable_pin(dapm, "Headset Mic");
136 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
137
138 /* TWL4030 not connected pins */
139 snd_soc_dapm_nc_pin(dapm, "AUXL");
140 snd_soc_dapm_nc_pin(dapm, "AUXR");
141 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
142 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
143 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
144
145 snd_soc_dapm_nc_pin(dapm, "OUTL");
146 snd_soc_dapm_nc_pin(dapm, "OUTR");
147 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
148 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
149 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
150 snd_soc_dapm_nc_pin(dapm, "CARKITL");
151 snd_soc_dapm_nc_pin(dapm, "CARKITR");
152
153 /* Headset jack detection */
154 ret = snd_soc_jack_new(codec, "Headset Jack",
155 SND_JACK_HEADSET, &hs_jack);
156 if (ret)
157 return ret;
158
159 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
160 hs_jack_pins);
161 if (ret)
162 return ret;
163
164 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
165 hs_jack_gpios);
166
167 return ret;
168}
169
170static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
171{
172 struct snd_soc_codec *codec = rtd->codec;
173 unsigned short reg;
174
175 /* Enable voice interface */
176 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
177 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
178 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
179
180 return 0;
181}
182
183
184/* Digital audio interface glue - connects codec <--> CPU */
185static struct snd_soc_dai_link sdp3430_dai[] = {
186 {
187 .name = "TWL4030 I2S",
188 .stream_name = "TWL4030 Audio",
189 .cpu_dai_name = "omap-mcbsp.2",
190 .codec_dai_name = "twl4030-hifi",
191 .platform_name = "omap-pcm-audio",
192 .codec_name = "twl4030-codec",
193 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
194 SND_SOC_DAIFMT_CBM_CFM,
195 .init = sdp3430_twl4030_init,
196 .ops = &sdp3430_ops,
197 },
198 {
199 .name = "TWL4030 PCM",
200 .stream_name = "TWL4030 Voice",
201 .cpu_dai_name = "omap-mcbsp.3",
202 .codec_dai_name = "twl4030-voice",
203 .platform_name = "omap-pcm-audio",
204 .codec_name = "twl4030-codec",
205 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
206 SND_SOC_DAIFMT_CBM_CFM,
207 .init = sdp3430_twl4030_voice_init,
208 .ops = &sdp3430_ops,
209 },
210};
211
212/* Audio machine driver */
213static struct snd_soc_card snd_soc_sdp3430 = {
214 .name = "SDP3430",
215 .owner = THIS_MODULE,
216 .dai_link = sdp3430_dai,
217 .num_links = ARRAY_SIZE(sdp3430_dai),
218
219 .dapm_widgets = sdp3430_twl4030_dapm_widgets,
220 .num_dapm_widgets = ARRAY_SIZE(sdp3430_twl4030_dapm_widgets),
221 .dapm_routes = audio_map,
222 .num_dapm_routes = ARRAY_SIZE(audio_map),
223};
224
225static struct platform_device *sdp3430_snd_device;
226
227static int __init sdp3430_soc_init(void)
228{
229 int ret;
230 u8 pin_mux;
231
232 if (!machine_is_omap_3430sdp())
233 return -ENODEV;
234 printk(KERN_INFO "SDP3430 SoC init\n");
235
236 sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
237 if (!sdp3430_snd_device) {
238 printk(KERN_ERR "Platform device allocation failed\n");
239 return -ENOMEM;
240 }
241
242 platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
243
244 /* Set TWL4030 GPIO6 as EXTMUTE signal */
245 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
246 TWL4030_INTBR_PMBR1);
247 pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
248 pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
249 twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
250 TWL4030_INTBR_PMBR1);
251
252 ret = platform_device_add(sdp3430_snd_device);
253 if (ret)
254 goto err1;
255
256 return 0;
257
258err1:
259 printk(KERN_ERR "Unable to add platform device\n");
260 platform_device_put(sdp3430_snd_device);
261
262 return ret;
263}
264module_init(sdp3430_soc_init);
265
266static void __exit sdp3430_soc_exit(void)
267{
268 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
269 hs_jack_gpios);
270
271 platform_device_unregister(sdp3430_snd_device);
272}
273module_exit(sdp3430_soc_exit);
274
275MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
276MODULE_DESCRIPTION("ALSA SoC SDP3430");
277MODULE_LICENSE("GPL");
278
diff --git a/sound/soc/omap/zoom2.c b/sound/soc/omap/zoom2.c
deleted file mode 100644
index 771bff27ac3e..000000000000
--- a/sound/soc/omap/zoom2.c
+++ /dev/null
@@ -1,207 +0,0 @@
1/*
2 * zoom2.c -- SoC audio for Zoom2
3 *
4 * Author: Misael Lopez Cruz <x0052729@ti.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/clk.h>
23#include <linux/platform_device.h>
24#include <linux/gpio.h>
25#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/soc.h>
28
29#include <asm/mach-types.h>
30#include <linux/platform_data/asoc-ti-mcbsp.h>
31#include <linux/platform_data/gpio-omap.h>
32
33/* Register descriptions for twl4030 codec part */
34#include <linux/mfd/twl4030-audio.h>
35#include <linux/module.h>
36
37#include "omap-mcbsp.h"
38#include "omap-pcm.h"
39
40static int zoom2_hw_params(struct snd_pcm_substream *substream,
41 struct snd_pcm_hw_params *params)
42{
43 struct snd_soc_pcm_runtime *rtd = substream->private_data;
44 struct snd_soc_dai *codec_dai = rtd->codec_dai;
45 int ret;
46
47 /* Set the codec system clock for DAC and ADC */
48 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
49 SND_SOC_CLOCK_IN);
50 if (ret < 0) {
51 printk(KERN_ERR "can't set codec system clock\n");
52 return ret;
53 }
54
55 return 0;
56}
57
58static struct snd_soc_ops zoom2_ops = {
59 .hw_params = zoom2_hw_params,
60};
61
62/* Zoom2 machine DAPM */
63static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = {
64 SND_SOC_DAPM_MIC("Ext Mic", NULL),
65 SND_SOC_DAPM_SPK("Ext Spk", NULL),
66 SND_SOC_DAPM_MIC("Headset Mic", NULL),
67 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
68 SND_SOC_DAPM_LINE("Aux In", NULL),
69};
70
71static const struct snd_soc_dapm_route audio_map[] = {
72 /* External Mics: MAINMIC, SUBMIC with bias*/
73 {"MAINMIC", NULL, "Mic Bias 1"},
74 {"SUBMIC", NULL, "Mic Bias 2"},
75 {"Mic Bias 1", NULL, "Ext Mic"},
76 {"Mic Bias 2", NULL, "Ext Mic"},
77
78 /* External Speakers: HFL, HFR */
79 {"Ext Spk", NULL, "HFL"},
80 {"Ext Spk", NULL, "HFR"},
81
82 /* Headset Stereophone: HSOL, HSOR */
83 {"Headset Stereophone", NULL, "HSOL"},
84 {"Headset Stereophone", NULL, "HSOR"},
85
86 /* Headset Mic: HSMIC with bias */
87 {"HSMIC", NULL, "Headset Mic Bias"},
88 {"Headset Mic Bias", NULL, "Headset Mic"},
89
90 /* Aux In: AUXL, AUXR */
91 {"Aux In", NULL, "AUXL"},
92 {"Aux In", NULL, "AUXR"},
93};
94
95static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
96{
97 struct snd_soc_codec *codec = rtd->codec;
98 struct snd_soc_dapm_context *dapm = &codec->dapm;
99
100 /* TWL4030 not connected pins */
101 snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
102 snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
103 snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
104 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
105 snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
106 snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
107 snd_soc_dapm_nc_pin(dapm, "CARKITL");
108 snd_soc_dapm_nc_pin(dapm, "CARKITR");
109
110 return 0;
111}
112
113static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
114{
115 struct snd_soc_codec *codec = rtd->codec;
116 unsigned short reg;
117
118 /* Enable voice interface */
119 reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
120 reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
121 codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
122
123 return 0;
124}
125
126/* Digital audio interface glue - connects codec <--> CPU */
127static struct snd_soc_dai_link zoom2_dai[] = {
128 {
129 .name = "TWL4030 I2S",
130 .stream_name = "TWL4030 Audio",
131 .cpu_dai_name = "omap-mcbsp.2",
132 .codec_dai_name = "twl4030-hifi",
133 .platform_name = "omap-pcm-audio",
134 .codec_name = "twl4030-codec",
135 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
136 SND_SOC_DAIFMT_CBM_CFM,
137 .init = zoom2_twl4030_init,
138 .ops = &zoom2_ops,
139 },
140 {
141 .name = "TWL4030 PCM",
142 .stream_name = "TWL4030 Voice",
143 .cpu_dai_name = "omap-mcbsp.3",
144 .codec_dai_name = "twl4030-voice",
145 .platform_name = "omap-pcm-audio",
146 .codec_name = "twl4030-codec",
147 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
148 SND_SOC_DAIFMT_CBM_CFM,
149 .init = zoom2_twl4030_voice_init,
150 .ops = &zoom2_ops,
151 },
152};
153
154/* Audio machine driver */
155static struct snd_soc_card snd_soc_zoom2 = {
156 .name = "Zoom2",
157 .owner = THIS_MODULE,
158 .dai_link = zoom2_dai,
159 .num_links = ARRAY_SIZE(zoom2_dai),
160
161 .dapm_widgets = zoom2_twl4030_dapm_widgets,
162 .num_dapm_widgets = ARRAY_SIZE(zoom2_twl4030_dapm_widgets),
163 .dapm_routes = audio_map,
164 .num_dapm_routes = ARRAY_SIZE(audio_map),
165};
166
167static struct platform_device *zoom2_snd_device;
168
169static int __init zoom2_soc_init(void)
170{
171 int ret;
172
173 if (!machine_is_omap_zoom2())
174 return -ENODEV;
175 printk(KERN_INFO "Zoom2 SoC init\n");
176
177 zoom2_snd_device = platform_device_alloc("soc-audio", -1);
178 if (!zoom2_snd_device) {
179 printk(KERN_ERR "Platform device allocation failed\n");
180 return -ENOMEM;
181 }
182
183 platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2);
184 ret = platform_device_add(zoom2_snd_device);
185 if (ret)
186 goto err1;
187
188 return 0;
189
190err1:
191 printk(KERN_ERR "Unable to add platform device\n");
192 platform_device_put(zoom2_snd_device);
193
194 return ret;
195}
196module_init(zoom2_soc_init);
197
198static void __exit zoom2_soc_exit(void)
199{
200 platform_device_unregister(zoom2_snd_device);
201}
202module_exit(zoom2_soc_exit);
203
204MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
205MODULE_DESCRIPTION("ALSA SoC Zoom2");
206MODULE_LICENSE("GPL");
207
diff --git a/sound/soc/pxa/palm27x.c b/sound/soc/pxa/palm27x.c
index 2074e2daf9c6..e1ffcdd9a649 100644
--- a/sound/soc/pxa/palm27x.c
+++ b/sound/soc/pxa/palm27x.c
@@ -79,17 +79,6 @@ static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
79 struct snd_soc_dapm_context *dapm = &codec->dapm; 79 struct snd_soc_dapm_context *dapm = &codec->dapm;
80 int err; 80 int err;
81 81
82 /* add palm27x specific widgets */
83 err = snd_soc_dapm_new_controls(dapm, palm27x_dapm_widgets,
84 ARRAY_SIZE(palm27x_dapm_widgets));
85 if (err)
86 return err;
87
88 /* set up palm27x specific audio path audio_map */
89 err = snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
90 if (err)
91 return err;
92
93 /* connected pins */ 82 /* connected pins */
94 if (machine_is_palmld()) 83 if (machine_is_palmld())
95 snd_soc_dapm_enable_pin(dapm, "MIC1"); 84 snd_soc_dapm_enable_pin(dapm, "MIC1");
@@ -149,10 +138,12 @@ static struct snd_soc_card palm27x_asoc = {
149 .owner = THIS_MODULE, 138 .owner = THIS_MODULE,
150 .dai_link = palm27x_dai, 139 .dai_link = palm27x_dai,
151 .num_links = ARRAY_SIZE(palm27x_dai), 140 .num_links = ARRAY_SIZE(palm27x_dai),
141 .dapm_widgets = palm27x_dapm_widgets,
142 .num_dapm_widgets = ARRAY_SIZE(palm27x_dapm_widgets),
143 .dapm_routes = audio_map,
144 .num_dapm_routes = ARRAY_SIZE(audio_map)
152}; 145};
153 146
154static struct platform_device *palm27x_snd_device;
155
156static int palm27x_asoc_probe(struct platform_device *pdev) 147static int palm27x_asoc_probe(struct platform_device *pdev)
157{ 148{
158 int ret; 149 int ret;
@@ -169,27 +160,18 @@ static int palm27x_asoc_probe(struct platform_device *pdev)
169 hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *) 160 hs_jack_gpios[0].gpio = ((struct palm27x_asoc_info *)
170 (pdev->dev.platform_data))->jack_gpio; 161 (pdev->dev.platform_data))->jack_gpio;
171 162
172 palm27x_snd_device = platform_device_alloc("soc-audio", -1); 163 palm27x_asoc.dev = &pdev->dev;
173 if (!palm27x_snd_device)
174 return -ENOMEM;
175
176 platform_set_drvdata(palm27x_snd_device, &palm27x_asoc);
177 ret = platform_device_add(palm27x_snd_device);
178
179 if (ret != 0)
180 goto put_device;
181
182 return 0;
183
184put_device:
185 platform_device_put(palm27x_snd_device);
186 164
165 ret = snd_soc_register_card(&palm27x_asoc);
166 if (ret)
167 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
168 ret);
187 return ret; 169 return ret;
188} 170}
189 171
190static int palm27x_asoc_remove(struct platform_device *pdev) 172static int palm27x_asoc_remove(struct platform_device *pdev)
191{ 173{
192 platform_device_unregister(palm27x_snd_device); 174 snd_soc_unregister_card(&palm27x_asoc);
193 return 0; 175 return 0;
194} 176}
195 177
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
index 3c7c3a59ed39..90e7e6653233 100644
--- a/sound/soc/samsung/Kconfig
+++ b/sound/soc/samsung/Kconfig
@@ -63,7 +63,7 @@ config SND_SOC_SAMSUNG_SMDK_WM8580
63 63
64config SND_SOC_SAMSUNG_SMDK_WM8994 64config SND_SOC_SAMSUNG_SMDK_WM8994
65 tristate "SoC I2S Audio support for WM8994 on SMDK" 65 tristate "SoC I2S Audio support for WM8994 on SMDK"
66 depends on SND_SOC_SAMSUNG && (MACH_SMDKV310 || MACH_SMDKC210 || MACH_SMDK4212) 66 depends on SND_SOC_SAMSUNG
67 depends on I2C=y && GENERIC_HARDIRQS 67 depends on I2C=y && GENERIC_HARDIRQS
68 select MFD_WM8994 68 select MFD_WM8994
69 select SND_SOC_WM8994 69 select SND_SOC_WM8994
@@ -162,7 +162,7 @@ config SND_SOC_GONI_AQUILA_WM8994
162 162
163config SND_SOC_SAMSUNG_SMDK_SPDIF 163config SND_SOC_SAMSUNG_SMDK_SPDIF
164 tristate "SoC S/PDIF Audio support for SMDK" 164 tristate "SoC S/PDIF Audio support for SMDK"
165 depends on SND_SOC_SAMSUNG && (MACH_SMDKC100 || MACH_SMDKC110 || MACH_SMDKV210 || MACH_SMDKV310 || MACH_SMDK4212) 165 depends on SND_SOC_SAMSUNG
166 select SND_SAMSUNG_SPDIF 166 select SND_SAMSUNG_SPDIF
167 help 167 help
168 Say Y if you want to add support for SoC S/PDIF audio on the SMDK. 168 Say Y if you want to add support for SoC S/PDIF audio on the SMDK.
@@ -177,7 +177,7 @@ config SND_SOC_SMDK_WM8580_PCM
177 177
178config SND_SOC_SMDK_WM8994_PCM 178config SND_SOC_SMDK_WM8994_PCM
179 tristate "SoC PCM Audio support for WM8994 on SMDK" 179 tristate "SoC PCM Audio support for WM8994 on SMDK"
180 depends on SND_SOC_SAMSUNG && (MACH_SMDKC210 || MACH_SMDKV310 || MACH_SMDK4212) 180 depends on SND_SOC_SAMSUNG
181 depends on I2C=y && GENERIC_HARDIRQS 181 depends on I2C=y && GENERIC_HARDIRQS
182 select MFD_WM8994 182 select MFD_WM8994
183 select SND_SOC_WM8994 183 select SND_SOC_WM8994
diff --git a/sound/soc/samsung/dma.c b/sound/soc/samsung/dma.c
index db87628d7630..21b79262010e 100644
--- a/sound/soc/samsung/dma.c
+++ b/sound/soc/samsung/dma.c
@@ -174,7 +174,8 @@ static int dma_hw_params(struct snd_pcm_substream *substream,
174 config.width = prtd->params->dma_size; 174 config.width = prtd->params->dma_size;
175 config.fifo = prtd->params->dma_addr; 175 config.fifo = prtd->params->dma_addr;
176 prtd->params->ch = prtd->params->ops->request( 176 prtd->params->ch = prtd->params->ops->request(
177 prtd->params->channel, &req); 177 prtd->params->channel, &req, rtd->cpu_dai->dev,
178 prtd->params->ch_name);
178 prtd->params->ops->config(prtd->params->ch, &config); 179 prtd->params->ops->config(prtd->params->ch, &config);
179 } 180 }
180 181
diff --git a/sound/soc/samsung/dma.h b/sound/soc/samsung/dma.h
index 73d8c7c8a1e8..189a7a6d5020 100644
--- a/sound/soc/samsung/dma.h
+++ b/sound/soc/samsung/dma.h
@@ -19,6 +19,7 @@ struct s3c_dma_params {
19 int dma_size; /* Size of the DMA transfer */ 19 int dma_size; /* Size of the DMA transfer */
20 unsigned ch; 20 unsigned ch;
21 struct samsung_dma_ops *ops; 21 struct samsung_dma_ops *ops;
22 char *ch_name;
22}; 23};
23 24
24int asoc_dma_platform_register(struct device *dev); 25int asoc_dma_platform_register(struct device *dev);
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index d2d124f1dd1b..d7231e336a7c 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -15,11 +15,15 @@
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/of_gpio.h>
18#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
19 21
20#include <sound/soc.h> 22#include <sound/soc.h>
21#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
22 24
25#include <mach/dma.h>
26
23#include <linux/platform_data/asoc-s3c.h> 27#include <linux/platform_data/asoc-s3c.h>
24 28
25#include "dma.h" 29#include "dma.h"
@@ -29,6 +33,15 @@
29 33
30#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) 34#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
31 35
36enum samsung_dai_type {
37 TYPE_PRI,
38 TYPE_SEC,
39};
40
41struct samsung_i2s_dai_data {
42 int dai_type;
43};
44
32struct i2s_dai { 45struct i2s_dai {
33 /* Platform device for this DAI */ 46 /* Platform device for this DAI */
34 struct platform_device *pdev; 47 struct platform_device *pdev;
@@ -66,6 +79,7 @@ struct i2s_dai {
66 u32 suspend_i2smod; 79 u32 suspend_i2smod;
67 u32 suspend_i2scon; 80 u32 suspend_i2scon;
68 u32 suspend_i2spsr; 81 u32 suspend_i2spsr;
82 unsigned long gpios[7]; /* i2s gpio line numbers */
69}; 83};
70 84
71/* Lock for cross i/f checks */ 85/* Lock for cross i/f checks */
@@ -651,6 +665,9 @@ static int i2s_startup(struct snd_pcm_substream *substream,
651 /* Enforce set_sysclk in Master mode */ 665 /* Enforce set_sysclk in Master mode */
652 i2s->rclk_srcrate = 0; 666 i2s->rclk_srcrate = 0;
653 667
668 if (!any_active(i2s) && (i2s->quirks & QUIRK_NEED_RSTCLR))
669 writel(CON_RSTCLR, i2s->addr + I2SCON);
670
654 spin_unlock_irqrestore(&lock, flags); 671 spin_unlock_irqrestore(&lock, flags);
655 672
656 return 0; 673 return 0;
@@ -981,8 +998,7 @@ static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
981 i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS; 998 i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
982 } else { /* Create a new platform_device for Secondary */ 999 } else { /* Create a new platform_device for Secondary */
983 i2s->pdev = platform_device_register_resndata(NULL, 1000 i2s->pdev = platform_device_register_resndata(NULL,
984 pdev->name, pdev->id + SAMSUNG_I2S_SECOFF, 1001 "samsung-i2s-sec", -1, NULL, 0, NULL, 0);
985 NULL, 0, NULL, 0);
986 if (IS_ERR(i2s->pdev)) 1002 if (IS_ERR(i2s->pdev))
987 return NULL; 1003 return NULL;
988 } 1004 }
@@ -993,18 +1009,103 @@ static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
993 return i2s; 1009 return i2s;
994} 1010}
995 1011
1012#ifdef CONFIG_OF
1013static int samsung_i2s_parse_dt_gpio(struct i2s_dai *i2s)
1014{
1015 struct device *dev = &i2s->pdev->dev;
1016 int index, gpio, ret;
1017
1018 for (index = 0; index < 7; index++) {
1019 gpio = of_get_gpio(dev->of_node, index);
1020 if (!gpio_is_valid(gpio)) {
1021 dev_err(dev, "invalid gpio[%d]: %d\n", index, gpio);
1022 goto free_gpio;
1023 }
1024
1025 ret = gpio_request(gpio, dev_name(dev));
1026 if (ret) {
1027 dev_err(dev, "gpio [%d] request failed\n", gpio);
1028 goto free_gpio;
1029 }
1030 i2s->gpios[index] = gpio;
1031 }
1032 return 0;
1033
1034free_gpio:
1035 while (--index >= 0)
1036 gpio_free(i2s->gpios[index]);
1037 return -EINVAL;
1038}
1039
1040static void samsung_i2s_dt_gpio_free(struct i2s_dai *i2s)
1041{
1042 unsigned int index;
1043 for (index = 0; index < 7; index++)
1044 gpio_free(i2s->gpios[index]);
1045}
1046#else
1047static int samsung_i2s_parse_dt_gpio(struct i2s_dai *dai)
1048{
1049 return -EINVAL;
1050}
1051
1052static void samsung_i2s_dt_gpio_free(struct i2s_dai *dai)
1053{
1054}
1055
1056#endif
1057
1058static const struct of_device_id exynos_i2s_match[];
1059
1060static inline int samsung_i2s_get_driver_data(struct platform_device *pdev)
1061{
1062#ifdef CONFIG_OF
1063 struct samsung_i2s_dai_data *data;
1064 if (pdev->dev.of_node) {
1065 const struct of_device_id *match;
1066 match = of_match_node(exynos_i2s_match, pdev->dev.of_node);
1067 data = (struct samsung_i2s_dai_data *) match->data;
1068 return data->dai_type;
1069 } else
1070#endif
1071 return platform_get_device_id(pdev)->driver_data;
1072}
1073
1074#ifdef CONFIG_PM_RUNTIME
1075static int i2s_runtime_suspend(struct device *dev)
1076{
1077 struct i2s_dai *i2s = dev_get_drvdata(dev);
1078
1079 clk_disable_unprepare(i2s->clk);
1080
1081 return 0;
1082}
1083
1084static int i2s_runtime_resume(struct device *dev)
1085{
1086 struct i2s_dai *i2s = dev_get_drvdata(dev);
1087
1088 clk_prepare_enable(i2s->clk);
1089
1090 return 0;
1091}
1092#endif /* CONFIG_PM_RUNTIME */
1093
996static int samsung_i2s_probe(struct platform_device *pdev) 1094static int samsung_i2s_probe(struct platform_device *pdev)
997{ 1095{
998 u32 dma_pl_chan, dma_cp_chan, dma_pl_sec_chan;
999 struct i2s_dai *pri_dai, *sec_dai = NULL; 1096 struct i2s_dai *pri_dai, *sec_dai = NULL;
1000 struct s3c_audio_pdata *i2s_pdata; 1097 struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data;
1001 struct samsung_i2s *i2s_cfg; 1098 struct samsung_i2s *i2s_cfg = NULL;
1002 struct resource *res; 1099 struct resource *res;
1003 u32 regs_base, quirks; 1100 u32 regs_base, quirks = 0, idma_addr = 0;
1101 struct device_node *np = pdev->dev.of_node;
1102 enum samsung_dai_type samsung_dai_type;
1004 int ret = 0; 1103 int ret = 0;
1005 1104
1006 /* Call during Seconday interface registration */ 1105 /* Call during Seconday interface registration */
1007 if (pdev->id >= SAMSUNG_I2S_SECOFF) { 1106 samsung_dai_type = samsung_i2s_get_driver_data(pdev);
1107
1108 if (samsung_dai_type == TYPE_SEC) {
1008 sec_dai = dev_get_drvdata(&pdev->dev); 1109 sec_dai = dev_get_drvdata(&pdev->dev);
1009 snd_soc_register_dai(&sec_dai->pdev->dev, 1110 snd_soc_register_dai(&sec_dai->pdev->dev,
1010 &sec_dai->i2s_dai_drv); 1111 &sec_dai->i2s_dai_drv);
@@ -1012,31 +1113,60 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1012 return 0; 1113 return 0;
1013 } 1114 }
1014 1115
1015 i2s_pdata = pdev->dev.platform_data; 1116 pri_dai = i2s_alloc_dai(pdev, false);
1016 if (i2s_pdata == NULL) { 1117 if (!pri_dai) {
1017 dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n"); 1118 dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
1018 return -EINVAL; 1119 return -ENOMEM;
1019 } 1120 }
1020 1121
1021 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 1122 if (!np) {
1022 if (!res) { 1123 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1023 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n"); 1124 if (!res) {
1024 return -ENXIO; 1125 dev_err(&pdev->dev,
1025 } 1126 "Unable to get I2S-TX dma resource\n");
1026 dma_pl_chan = res->start; 1127 return -ENXIO;
1128 }
1129 pri_dai->dma_playback.channel = res->start;
1027 1130
1028 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 1131 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1029 if (!res) { 1132 if (!res) {
1030 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n"); 1133 dev_err(&pdev->dev,
1031 return -ENXIO; 1134 "Unable to get I2S-RX dma resource\n");
1032 } 1135 return -ENXIO;
1033 dma_cp_chan = res->start; 1136 }
1137 pri_dai->dma_capture.channel = res->start;
1034 1138
1035 res = platform_get_resource(pdev, IORESOURCE_DMA, 2); 1139 if (i2s_pdata == NULL) {
1036 if (res) 1140 dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
1037 dma_pl_sec_chan = res->start; 1141 return -EINVAL;
1038 else 1142 }
1039 dma_pl_sec_chan = 0; 1143
1144 if (&i2s_pdata->type)
1145 i2s_cfg = &i2s_pdata->type.i2s;
1146
1147 if (i2s_cfg) {
1148 quirks = i2s_cfg->quirks;
1149 idma_addr = i2s_cfg->idma_addr;
1150 }
1151 } else {
1152 if (of_find_property(np, "samsung,supports-6ch", NULL))
1153 quirks |= QUIRK_PRI_6CHAN;
1154
1155 if (of_find_property(np, "samsung,supports-secdai", NULL))
1156 quirks |= QUIRK_SEC_DAI;
1157
1158 if (of_find_property(np, "samsung,supports-rstclr", NULL))
1159 quirks |= QUIRK_NEED_RSTCLR;
1160
1161 if (of_property_read_u32(np, "samsung,idma-addr",
1162 &idma_addr)) {
1163 if (quirks & QUIRK_SEC_DAI) {
1164 dev_err(&pdev->dev, "idma address is not"\
1165 "specified");
1166 return -EINVAL;
1167 }
1168 }
1169 }
1040 1170
1041 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1171 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1042 if (!res) { 1172 if (!res) {
@@ -1051,24 +1181,14 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1051 } 1181 }
1052 regs_base = res->start; 1182 regs_base = res->start;
1053 1183
1054 i2s_cfg = &i2s_pdata->type.i2s;
1055 quirks = i2s_cfg->quirks;
1056
1057 pri_dai = i2s_alloc_dai(pdev, false);
1058 if (!pri_dai) {
1059 dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
1060 ret = -ENOMEM;
1061 goto err;
1062 }
1063
1064 pri_dai->dma_playback.dma_addr = regs_base + I2STXD; 1184 pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
1065 pri_dai->dma_capture.dma_addr = regs_base + I2SRXD; 1185 pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
1066 pri_dai->dma_playback.client = 1186 pri_dai->dma_playback.client =
1067 (struct s3c2410_dma_client *)&pri_dai->dma_playback; 1187 (struct s3c2410_dma_client *)&pri_dai->dma_playback;
1188 pri_dai->dma_playback.ch_name = "tx";
1068 pri_dai->dma_capture.client = 1189 pri_dai->dma_capture.client =
1069 (struct s3c2410_dma_client *)&pri_dai->dma_capture; 1190 (struct s3c2410_dma_client *)&pri_dai->dma_capture;
1070 pri_dai->dma_playback.channel = dma_pl_chan; 1191 pri_dai->dma_capture.ch_name = "rx";
1071 pri_dai->dma_capture.channel = dma_cp_chan;
1072 pri_dai->dma_playback.dma_size = 4; 1192 pri_dai->dma_playback.dma_size = 4;
1073 pri_dai->dma_capture.dma_size = 4; 1193 pri_dai->dma_capture.dma_size = 4;
1074 pri_dai->base = regs_base; 1194 pri_dai->base = regs_base;
@@ -1087,20 +1207,34 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1087 sec_dai->dma_playback.dma_addr = regs_base + I2STXDS; 1207 sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
1088 sec_dai->dma_playback.client = 1208 sec_dai->dma_playback.client =
1089 (struct s3c2410_dma_client *)&sec_dai->dma_playback; 1209 (struct s3c2410_dma_client *)&sec_dai->dma_playback;
1090 /* Use iDMA always if SysDMA not provided */ 1210 sec_dai->dma_playback.ch_name = "tx-sec";
1091 sec_dai->dma_playback.channel = dma_pl_sec_chan ? : -1; 1211
1212 if (!np) {
1213 res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
1214 if (res)
1215 sec_dai->dma_playback.channel = res->start;
1216 }
1217
1092 sec_dai->dma_playback.dma_size = 4; 1218 sec_dai->dma_playback.dma_size = 4;
1093 sec_dai->base = regs_base; 1219 sec_dai->base = regs_base;
1094 sec_dai->quirks = quirks; 1220 sec_dai->quirks = quirks;
1095 sec_dai->idma_playback.dma_addr = i2s_cfg->idma_addr; 1221 sec_dai->idma_playback.dma_addr = idma_addr;
1096 sec_dai->pri_dai = pri_dai; 1222 sec_dai->pri_dai = pri_dai;
1097 pri_dai->sec_dai = sec_dai; 1223 pri_dai->sec_dai = sec_dai;
1098 } 1224 }
1099 1225
1100 if (i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) { 1226 if (np) {
1101 dev_err(&pdev->dev, "Unable to configure gpio\n"); 1227 if (samsung_i2s_parse_dt_gpio(pri_dai)) {
1102 ret = -EINVAL; 1228 dev_err(&pdev->dev, "Unable to configure gpio\n");
1103 goto err; 1229 ret = -EINVAL;
1230 goto err;
1231 }
1232 } else {
1233 if (i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
1234 dev_err(&pdev->dev, "Unable to configure gpio\n");
1235 ret = -EINVAL;
1236 goto err;
1237 }
1104 } 1238 }
1105 1239
1106 snd_soc_register_dai(&pri_dai->pdev->dev, &pri_dai->i2s_dai_drv); 1240 snd_soc_register_dai(&pri_dai->pdev->dev, &pri_dai->i2s_dai_drv);
@@ -1120,10 +1254,14 @@ static int samsung_i2s_remove(struct platform_device *pdev)
1120{ 1254{
1121 struct i2s_dai *i2s, *other; 1255 struct i2s_dai *i2s, *other;
1122 struct resource *res; 1256 struct resource *res;
1257 struct s3c_audio_pdata *i2s_pdata = pdev->dev.platform_data;
1123 1258
1124 i2s = dev_get_drvdata(&pdev->dev); 1259 i2s = dev_get_drvdata(&pdev->dev);
1125 other = i2s->pri_dai ? : i2s->sec_dai; 1260 other = i2s->pri_dai ? : i2s->sec_dai;
1126 1261
1262 if (!i2s_pdata->cfg_gpio && pdev->dev.of_node)
1263 samsung_i2s_dt_gpio_free(i2s->pri_dai);
1264
1127 if (other) { 1265 if (other) {
1128 other->pri_dai = NULL; 1266 other->pri_dai = NULL;
1129 other->sec_dai = NULL; 1267 other->sec_dai = NULL;
@@ -1143,12 +1281,47 @@ static int samsung_i2s_remove(struct platform_device *pdev)
1143 return 0; 1281 return 0;
1144} 1282}
1145 1283
1284static struct platform_device_id samsung_i2s_driver_ids[] = {
1285 {
1286 .name = "samsung-i2s",
1287 .driver_data = TYPE_PRI,
1288 }, {
1289 .name = "samsung-i2s-sec",
1290 .driver_data = TYPE_SEC,
1291 },
1292 {},
1293};
1294MODULE_DEVICE_TABLE(platform, samsung-i2s-driver-ids);
1295
1296#ifdef CONFIG_OF
1297static struct samsung_i2s_dai_data samsung_i2s_dai_data_array[] = {
1298 [TYPE_PRI] = { TYPE_PRI },
1299 [TYPE_SEC] = { TYPE_SEC },
1300};
1301
1302static const struct of_device_id exynos_i2s_match[] = {
1303 { .compatible = "samsung,i2s-v5",
1304 .data = &samsung_i2s_dai_data_array[TYPE_PRI],
1305 },
1306 {},
1307};
1308MODULE_DEVICE_TABLE(of, exynos_i2s_match);
1309#endif
1310
1311static const struct dev_pm_ops samsung_i2s_pm = {
1312 SET_RUNTIME_PM_OPS(i2s_runtime_suspend,
1313 i2s_runtime_resume, NULL)
1314};
1315
1146static struct platform_driver samsung_i2s_driver = { 1316static struct platform_driver samsung_i2s_driver = {
1147 .probe = samsung_i2s_probe, 1317 .probe = samsung_i2s_probe,
1148 .remove = samsung_i2s_remove, 1318 .remove = samsung_i2s_remove,
1319 .id_table = samsung_i2s_driver_ids,
1149 .driver = { 1320 .driver = {
1150 .name = "samsung-i2s", 1321 .name = "samsung-i2s",
1151 .owner = THIS_MODULE, 1322 .owner = THIS_MODULE,
1323 .of_match_table = of_match_ptr(exynos_i2s_match),
1324 .pm = &samsung_i2s_pm,
1152 }, 1325 },
1153}; 1326};
1154 1327
diff --git a/sound/soc/samsung/i2s.h b/sound/soc/samsung/i2s.h
index d420a7ca56ca..7966afc934db 100644
--- a/sound/soc/samsung/i2s.h
+++ b/sound/soc/samsung/i2s.h
@@ -13,13 +13,6 @@
13#ifndef __SND_SOC_SAMSUNG_I2S_H 13#ifndef __SND_SOC_SAMSUNG_I2S_H
14#define __SND_SOC_SAMSUNG_I2S_H 14#define __SND_SOC_SAMSUNG_I2S_H
15 15
16/*
17 * Maximum number of I2S blocks that any SoC can have.
18 * The secondary interface of a CPU dai(if there exists any),
19 * is indexed at [cpu-dai's ID + SAMSUNG_I2S_SECOFF]
20 */
21#define SAMSUNG_I2S_SECOFF 4
22
23#define SAMSUNG_I2S_DIV_BCLK 1 16#define SAMSUNG_I2S_DIV_BCLK 1
24 17
25#define SAMSUNG_I2S_RCLKSRC_0 0 18#define SAMSUNG_I2S_RCLKSRC_0 0
diff --git a/sound/soc/samsung/s3c24xx-i2s.c b/sound/soc/samsung/s3c24xx-i2s.c
index ee10e8704e97..13f6dd1ceb00 100644
--- a/sound/soc/samsung/s3c24xx-i2s.c
+++ b/sound/soc/samsung/s3c24xx-i2s.c
@@ -469,7 +469,7 @@ static int s3c24xx_iis_dev_probe(struct platform_device *pdev)
469{ 469{
470 int ret = 0; 470 int ret = 0;
471 471
472 ret = s3c_i2sv2_register_dai(&pdev->dev, -1, &s3c2412_i2s_dai); 472 ret = snd_soc_register_dai(&pdev->dev, &s3c24xx_i2s_dai);
473 if (ret) { 473 if (ret) {
474 pr_err("failed to register the dai\n"); 474 pr_err("failed to register the dai\n");
475 return ret; 475 return ret;
diff --git a/sound/soc/samsung/smdk_wm8580.c b/sound/soc/samsung/smdk_wm8580.c
index 7e2b710763be..7a16b32ed673 100644
--- a/sound/soc/samsung/smdk_wm8580.c
+++ b/sound/soc/samsung/smdk_wm8580.c
@@ -193,9 +193,9 @@ static struct snd_soc_dai_link smdk_dai[] = {
193 [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */ 193 [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
194 .name = "Sec_FIFO TX", 194 .name = "Sec_FIFO TX",
195 .stream_name = "Playback", 195 .stream_name = "Playback",
196 .cpu_dai_name = "samsung-i2s.x", 196 .cpu_dai_name = "samsung-i2s-sec",
197 .codec_dai_name = "wm8580-hifi-playback", 197 .codec_dai_name = "wm8580-hifi-playback",
198 .platform_name = "samsung-i2s.x", 198 .platform_name = "samsung-i2s-sec",
199 .codec_name = "wm8580.0-001b", 199 .codec_name = "wm8580.0-001b",
200 .ops = &smdk_ops, 200 .ops = &smdk_ops,
201 }, 201 },
@@ -223,9 +223,6 @@ static int __init smdk_audio_init(void)
223 if (machine_is_smdkc100() 223 if (machine_is_smdkc100()
224 || machine_is_smdkv210() || machine_is_smdkc110()) { 224 || machine_is_smdkv210() || machine_is_smdkc110()) {
225 smdk.num_links = 3; 225 smdk.num_links = 3;
226 /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
227 str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name;
228 str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF;
229 } else if (machine_is_smdk6410()) { 226 } else if (machine_is_smdk6410()) {
230 str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name; 227 str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
231 str[strlen(str) - 1] = '2'; 228 str[strlen(str) - 1] = '2';
diff --git a/sound/soc/samsung/smdk_wm8994.c b/sound/soc/samsung/smdk_wm8994.c
index b0d0ab8bff5a..581ea4a06fc6 100644
--- a/sound/soc/samsung/smdk_wm8994.c
+++ b/sound/soc/samsung/smdk_wm8994.c
@@ -10,6 +10,7 @@
10#include "../codecs/wm8994.h" 10#include "../codecs/wm8994.h"
11#include <sound/pcm_params.h> 11#include <sound/pcm_params.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/of.h>
13 14
14 /* 15 /*
15 * Default CFG switch settings to use this driver: 16 * Default CFG switch settings to use this driver:
@@ -134,9 +135,9 @@ static struct snd_soc_dai_link smdk_dai[] = {
134 }, { /* Sec_Fifo Playback i/f */ 135 }, { /* Sec_Fifo Playback i/f */
135 .name = "Sec_FIFO TX", 136 .name = "Sec_FIFO TX",
136 .stream_name = "Sec_Dai", 137 .stream_name = "Sec_Dai",
137 .cpu_dai_name = "samsung-i2s.4", 138 .cpu_dai_name = "samsung-i2s-sec",
138 .codec_dai_name = "wm8994-aif1", 139 .codec_dai_name = "wm8994-aif1",
139 .platform_name = "samsung-i2s.4", 140 .platform_name = "samsung-i2s-sec",
140 .codec_name = "wm8994-codec", 141 .codec_name = "wm8994-codec",
141 .ops = &smdk_ops, 142 .ops = &smdk_ops,
142 }, 143 },
@@ -153,9 +154,25 @@ static struct snd_soc_card smdk = {
153static int smdk_audio_probe(struct platform_device *pdev) 154static int smdk_audio_probe(struct platform_device *pdev)
154{ 155{
155 int ret; 156 int ret;
157 struct device_node *np = pdev->dev.of_node;
156 struct snd_soc_card *card = &smdk; 158 struct snd_soc_card *card = &smdk;
157 159
158 card->dev = &pdev->dev; 160 card->dev = &pdev->dev;
161
162 if (np) {
163 smdk_dai[0].cpu_dai_name = NULL;
164 smdk_dai[0].cpu_of_node = of_parse_phandle(np,
165 "samsung,i2s-controller", 0);
166 if (!smdk_dai[0].cpu_of_node) {
167 dev_err(&pdev->dev,
168 "Property 'samsung,i2s-controller' missing or invalid\n");
169 ret = -EINVAL;
170 }
171
172 smdk_dai[0].platform_name = NULL;
173 smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
174 }
175
159 ret = snd_soc_register_card(card); 176 ret = snd_soc_register_card(card);
160 177
161 if (ret) 178 if (ret)
@@ -173,10 +190,19 @@ static int smdk_audio_remove(struct platform_device *pdev)
173 return 0; 190 return 0;
174} 191}
175 192
193#ifdef CONFIG_OF
194static const struct of_device_id samsung_wm8994_of_match[] = {
195 { .compatible = "samsung,smdk-wm8994", },
196 {},
197};
198MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
199#endif /* CONFIG_OF */
200
176static struct platform_driver smdk_audio_driver = { 201static struct platform_driver smdk_audio_driver = {
177 .driver = { 202 .driver = {
178 .name = "smdk-audio", 203 .name = "smdk-audio",
179 .owner = THIS_MODULE, 204 .owner = THIS_MODULE,
205 .of_match_table = of_match_ptr(samsung_wm8994_of_match),
180 }, 206 },
181 .probe = smdk_audio_probe, 207 .probe = smdk_audio_probe,
182 .remove = smdk_audio_remove, 208 .remove = smdk_audio_remove,
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index a606d0f93d1c..c724026a246f 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -16,6 +16,8 @@
16#include <linux/dma-mapping.h> 16#include <linux/dma-mapping.h>
17#include <linux/pm_runtime.h> 17#include <linux/pm_runtime.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/of.h>
20#include <linux/of_device.h>
19#include <linux/scatterlist.h> 21#include <linux/scatterlist.h>
20#include <linux/sh_dma.h> 22#include <linux/sh_dma.h>
21#include <linux/slab.h> 23#include <linux/slab.h>
@@ -131,8 +133,6 @@
131 133
132#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) 134#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
133 135
134typedef int (*set_rate_func)(struct device *dev, int rate, int enable);
135
136/* 136/*
137 * bus options 137 * bus options
138 * 138 *
@@ -244,8 +244,7 @@ struct fsi_clk {
244 struct clk *ick; 244 struct clk *ick;
245 struct clk *div; 245 struct clk *div;
246 int (*set_rate)(struct device *dev, 246 int (*set_rate)(struct device *dev,
247 struct fsi_priv *fsi, 247 struct fsi_priv *fsi);
248 unsigned long rate);
249 248
250 unsigned long rate; 249 unsigned long rate;
251 unsigned int count; 250 unsigned int count;
@@ -254,7 +253,6 @@ struct fsi_clk {
254struct fsi_priv { 253struct fsi_priv {
255 void __iomem *base; 254 void __iomem *base;
256 struct fsi_master *master; 255 struct fsi_master *master;
257 struct sh_fsi_port_info *info;
258 256
259 struct fsi_stream playback; 257 struct fsi_stream playback;
260 struct fsi_stream capture; 258 struct fsi_stream capture;
@@ -270,8 +268,6 @@ struct fsi_priv {
270 int enable_stream:1; 268 int enable_stream:1;
271 int bit_clk_inv:1; 269 int bit_clk_inv:1;
272 int lr_clk_inv:1; 270 int lr_clk_inv:1;
273
274 long rate;
275}; 271};
276 272
277struct fsi_stream_handler { 273struct fsi_stream_handler {
@@ -303,7 +299,7 @@ struct fsi_master {
303 int irq; 299 int irq;
304 struct fsi_priv fsia; 300 struct fsi_priv fsia;
305 struct fsi_priv fsib; 301 struct fsi_priv fsib;
306 struct fsi_core *core; 302 const struct fsi_core *core;
307 spinlock_t lock; 303 spinlock_t lock;
308}; 304};
309 305
@@ -431,22 +427,6 @@ static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream)
431 return fsi_get_priv_frm_dai(fsi_get_dai(substream)); 427 return fsi_get_priv_frm_dai(fsi_get_dai(substream));
432} 428}
433 429
434static set_rate_func fsi_get_info_set_rate(struct fsi_priv *fsi)
435{
436 if (!fsi->info)
437 return NULL;
438
439 return fsi->info->set_rate;
440}
441
442static u32 fsi_get_info_flags(struct fsi_priv *fsi)
443{
444 if (!fsi->info)
445 return 0;
446
447 return fsi->info->flags;
448}
449
450static u32 fsi_get_port_shift(struct fsi_priv *fsi, struct fsi_stream *io) 430static u32 fsi_get_port_shift(struct fsi_priv *fsi, struct fsi_stream *io)
451{ 431{
452 int is_play = fsi_stream_is_play(fsi, io); 432 int is_play = fsi_stream_is_play(fsi, io);
@@ -757,8 +737,7 @@ static int fsi_clk_init(struct device *dev,
757 int ick, 737 int ick,
758 int div, 738 int div,
759 int (*set_rate)(struct device *dev, 739 int (*set_rate)(struct device *dev,
760 struct fsi_priv *fsi, 740 struct fsi_priv *fsi))
761 unsigned long rate))
762{ 741{
763 struct fsi_clk *clock = &fsi->clock; 742 struct fsi_clk *clock = &fsi->clock;
764 int is_porta = fsi_is_port_a(fsi); 743 int is_porta = fsi_is_port_a(fsi);
@@ -829,8 +808,7 @@ static int fsi_clk_is_valid(struct fsi_priv *fsi)
829} 808}
830 809
831static int fsi_clk_enable(struct device *dev, 810static int fsi_clk_enable(struct device *dev,
832 struct fsi_priv *fsi, 811 struct fsi_priv *fsi)
833 unsigned long rate)
834{ 812{
835 struct fsi_clk *clock = &fsi->clock; 813 struct fsi_clk *clock = &fsi->clock;
836 int ret = -EINVAL; 814 int ret = -EINVAL;
@@ -839,7 +817,7 @@ static int fsi_clk_enable(struct device *dev,
839 return ret; 817 return ret;
840 818
841 if (0 == clock->count) { 819 if (0 == clock->count) {
842 ret = clock->set_rate(dev, fsi, rate); 820 ret = clock->set_rate(dev, fsi);
843 if (ret < 0) { 821 if (ret < 0) {
844 fsi_clk_invalid(fsi); 822 fsi_clk_invalid(fsi);
845 return ret; 823 return ret;
@@ -946,11 +924,11 @@ static int fsi_clk_set_ackbpf(struct device *dev,
946} 924}
947 925
948static int fsi_clk_set_rate_external(struct device *dev, 926static int fsi_clk_set_rate_external(struct device *dev,
949 struct fsi_priv *fsi, 927 struct fsi_priv *fsi)
950 unsigned long rate)
951{ 928{
952 struct clk *xck = fsi->clock.xck; 929 struct clk *xck = fsi->clock.xck;
953 struct clk *ick = fsi->clock.ick; 930 struct clk *ick = fsi->clock.ick;
931 unsigned long rate = fsi->clock.rate;
954 unsigned long xrate; 932 unsigned long xrate;
955 int ackmd, bpfmd; 933 int ackmd, bpfmd;
956 int ret = 0; 934 int ret = 0;
@@ -978,11 +956,11 @@ static int fsi_clk_set_rate_external(struct device *dev,
978} 956}
979 957
980static int fsi_clk_set_rate_cpg(struct device *dev, 958static int fsi_clk_set_rate_cpg(struct device *dev,
981 struct fsi_priv *fsi, 959 struct fsi_priv *fsi)
982 unsigned long rate)
983{ 960{
984 struct clk *ick = fsi->clock.ick; 961 struct clk *ick = fsi->clock.ick;
985 struct clk *div = fsi->clock.div; 962 struct clk *div = fsi->clock.div;
963 unsigned long rate = fsi->clock.rate;
986 unsigned long target = 0; /* 12288000 or 11289600 */ 964 unsigned long target = 0; /* 12288000 or 11289600 */
987 unsigned long actual, cout; 965 unsigned long actual, cout;
988 unsigned long diff, min; 966 unsigned long diff, min;
@@ -1063,85 +1041,6 @@ static int fsi_clk_set_rate_cpg(struct device *dev,
1063 return ret; 1041 return ret;
1064} 1042}
1065 1043
1066static int fsi_set_master_clk(struct device *dev, struct fsi_priv *fsi,
1067 long rate, int enable)
1068{
1069 set_rate_func set_rate = fsi_get_info_set_rate(fsi);
1070 int ret;
1071
1072 /*
1073 * CAUTION
1074 *
1075 * set_rate will be deleted
1076 */
1077 if (!set_rate) {
1078 if (enable)
1079 return fsi_clk_enable(dev, fsi, rate);
1080 else
1081 return fsi_clk_disable(dev, fsi);
1082 }
1083
1084 ret = set_rate(dev, rate, enable);
1085 if (ret < 0) /* error */
1086 return ret;
1087
1088 if (!enable)
1089 return 0;
1090
1091 if (ret > 0) {
1092 u32 data = 0;
1093
1094 switch (ret & SH_FSI_ACKMD_MASK) {
1095 default:
1096 /* FALL THROUGH */
1097 case SH_FSI_ACKMD_512:
1098 data |= (0x0 << 12);
1099 break;
1100 case SH_FSI_ACKMD_256:
1101 data |= (0x1 << 12);
1102 break;
1103 case SH_FSI_ACKMD_128:
1104 data |= (0x2 << 12);
1105 break;
1106 case SH_FSI_ACKMD_64:
1107 data |= (0x3 << 12);
1108 break;
1109 case SH_FSI_ACKMD_32:
1110 data |= (0x4 << 12);
1111 break;
1112 }
1113
1114 switch (ret & SH_FSI_BPFMD_MASK) {
1115 default:
1116 /* FALL THROUGH */
1117 case SH_FSI_BPFMD_32:
1118 data |= (0x0 << 8);
1119 break;
1120 case SH_FSI_BPFMD_64:
1121 data |= (0x1 << 8);
1122 break;
1123 case SH_FSI_BPFMD_128:
1124 data |= (0x2 << 8);
1125 break;
1126 case SH_FSI_BPFMD_256:
1127 data |= (0x3 << 8);
1128 break;
1129 case SH_FSI_BPFMD_512:
1130 data |= (0x4 << 8);
1131 break;
1132 case SH_FSI_BPFMD_16:
1133 data |= (0x7 << 8);
1134 break;
1135 }
1136
1137 fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data);
1138 udelay(10);
1139 ret = 0;
1140 }
1141
1142 return ret;
1143}
1144
1145/* 1044/*
1146 * pio data transfer handler 1045 * pio data transfer handler
1147 */ 1046 */
@@ -1637,7 +1536,6 @@ static int fsi_hw_startup(struct fsi_priv *fsi,
1637 struct fsi_stream *io, 1536 struct fsi_stream *io,
1638 struct device *dev) 1537 struct device *dev)
1639{ 1538{
1640 u32 flags = fsi_get_info_flags(fsi);
1641 u32 data = 0; 1539 u32 data = 0;
1642 1540
1643 /* clock setting */ 1541 /* clock setting */
@@ -1654,19 +1552,6 @@ static int fsi_hw_startup(struct fsi_priv *fsi,
1654 data |= (1 << 4); 1552 data |= (1 << 4);
1655 if (fsi_is_clk_master(fsi)) 1553 if (fsi_is_clk_master(fsi))
1656 data <<= 8; 1554 data <<= 8;
1657 /* FIXME
1658 *
1659 * SH_FSI_xxx_INV style will be removed
1660 */
1661 if (SH_FSI_LRM_INV & flags)
1662 data |= 1 << 12;
1663 if (SH_FSI_BRM_INV & flags)
1664 data |= 1 << 8;
1665 if (SH_FSI_LRS_INV & flags)
1666 data |= 1 << 4;
1667 if (SH_FSI_BRS_INV & flags)
1668 data |= 1 << 0;
1669
1670 fsi_reg_write(fsi, CKG2, data); 1555 fsi_reg_write(fsi, CKG2, data);
1671 1556
1672 /* spdif ? */ 1557 /* spdif ? */
@@ -1698,7 +1583,7 @@ static int fsi_hw_startup(struct fsi_priv *fsi,
1698 1583
1699 /* start master clock */ 1584 /* start master clock */
1700 if (fsi_is_clk_master(fsi)) 1585 if (fsi_is_clk_master(fsi))
1701 return fsi_set_master_clk(dev, fsi, fsi->rate, 1); 1586 return fsi_clk_enable(dev, fsi);
1702 1587
1703 return 0; 1588 return 0;
1704} 1589}
@@ -1708,7 +1593,7 @@ static int fsi_hw_shutdown(struct fsi_priv *fsi,
1708{ 1593{
1709 /* stop master clock */ 1594 /* stop master clock */
1710 if (fsi_is_clk_master(fsi)) 1595 if (fsi_is_clk_master(fsi))
1711 return fsi_set_master_clk(dev, fsi, fsi->rate, 0); 1596 return fsi_clk_disable(dev, fsi);
1712 1597
1713 return 0; 1598 return 0;
1714} 1599}
@@ -1719,7 +1604,6 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
1719 struct fsi_priv *fsi = fsi_get_priv(substream); 1604 struct fsi_priv *fsi = fsi_get_priv(substream);
1720 1605
1721 fsi_clk_invalid(fsi); 1606 fsi_clk_invalid(fsi);
1722 fsi->rate = 0;
1723 1607
1724 return 0; 1608 return 0;
1725} 1609}
@@ -1730,7 +1614,6 @@ static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
1730 struct fsi_priv *fsi = fsi_get_priv(substream); 1614 struct fsi_priv *fsi = fsi_get_priv(substream);
1731 1615
1732 fsi_clk_invalid(fsi); 1616 fsi_clk_invalid(fsi);
1733 fsi->rate = 0;
1734} 1617}
1735 1618
1736static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, 1619static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
@@ -1795,7 +1678,6 @@ static int fsi_set_fmt_spdif(struct fsi_priv *fsi)
1795static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 1678static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1796{ 1679{
1797 struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai); 1680 struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai);
1798 set_rate_func set_rate = fsi_get_info_set_rate(fsi);
1799 int ret; 1681 int ret;
1800 1682
1801 /* set master/slave audio interface */ 1683 /* set master/slave audio interface */
@@ -1831,14 +1713,6 @@ static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1831 } 1713 }
1832 1714
1833 if (fsi_is_clk_master(fsi)) { 1715 if (fsi_is_clk_master(fsi)) {
1834 /*
1835 * CAUTION
1836 *
1837 * set_rate will be deleted
1838 */
1839 if (set_rate)
1840 dev_warn(dai->dev, "set_rate will be removed soon\n");
1841
1842 if (fsi->clk_cpg) 1716 if (fsi->clk_cpg)
1843 fsi_clk_init(dai->dev, fsi, 0, 1, 1, 1717 fsi_clk_init(dai->dev, fsi, 0, 1, 1,
1844 fsi_clk_set_rate_cpg); 1718 fsi_clk_set_rate_cpg);
@@ -1862,10 +1736,8 @@ static int fsi_dai_hw_params(struct snd_pcm_substream *substream,
1862{ 1736{
1863 struct fsi_priv *fsi = fsi_get_priv(substream); 1737 struct fsi_priv *fsi = fsi_get_priv(substream);
1864 1738
1865 if (fsi_is_clk_master(fsi)) { 1739 if (fsi_is_clk_master(fsi))
1866 fsi->rate = params_rate(params); 1740 fsi_clk_valid(fsi, params_rate(params));
1867 fsi_clk_valid(fsi, fsi->rate);
1868 }
1869 1741
1870 return 0; 1742 return 0;
1871} 1743}
@@ -2017,6 +1889,33 @@ static struct snd_soc_platform_driver fsi_soc_platform = {
2017/* 1889/*
2018 * platform function 1890 * platform function
2019 */ 1891 */
1892static void fsi_of_parse(char *name,
1893 struct device_node *np,
1894 struct sh_fsi_port_info *info,
1895 struct device *dev)
1896{
1897 int i;
1898 char prop[128];
1899 unsigned long flags = 0;
1900 struct {
1901 char *name;
1902 unsigned int val;
1903 } of_parse_property[] = {
1904 { "spdif-connection", SH_FSI_FMT_SPDIF },
1905 { "stream-mode-support", SH_FSI_ENABLE_STREAM_MODE },
1906 { "use-internal-clock", SH_FSI_CLK_CPG },
1907 };
1908
1909 for (i = 0; i < ARRAY_SIZE(of_parse_property); i++) {
1910 sprintf(prop, "%s,%s", name, of_parse_property[i].name);
1911 if (of_get_property(np, prop, NULL))
1912 flags |= of_parse_property[i].val;
1913 }
1914 info->flags = flags;
1915
1916 dev_dbg(dev, "%s flags : %lx\n", name, info->flags);
1917}
1918
2020static void fsi_port_info_init(struct fsi_priv *fsi, 1919static void fsi_port_info_init(struct fsi_priv *fsi,
2021 struct sh_fsi_port_info *info) 1920 struct sh_fsi_port_info *info)
2022{ 1921{
@@ -2044,23 +1943,40 @@ static void fsi_handler_init(struct fsi_priv *fsi,
2044 } 1943 }
2045} 1944}
2046 1945
1946static struct of_device_id fsi_of_match[];
2047static int fsi_probe(struct platform_device *pdev) 1947static int fsi_probe(struct platform_device *pdev)
2048{ 1948{
2049 struct fsi_master *master; 1949 struct fsi_master *master;
2050 const struct platform_device_id *id_entry; 1950 struct device_node *np = pdev->dev.of_node;
2051 struct sh_fsi_platform_info *info = pdev->dev.platform_data; 1951 struct sh_fsi_platform_info info;
2052 struct sh_fsi_port_info nul_info, *pinfo; 1952 const struct fsi_core *core;
2053 struct fsi_priv *fsi; 1953 struct fsi_priv *fsi;
2054 struct resource *res; 1954 struct resource *res;
2055 unsigned int irq; 1955 unsigned int irq;
2056 int ret; 1956 int ret;
2057 1957
2058 nul_info.flags = 0; 1958 memset(&info, 0, sizeof(info));
2059 nul_info.tx_id = 0; 1959
2060 nul_info.rx_id = 0; 1960 core = NULL;
1961 if (np) {
1962 const struct of_device_id *of_id;
2061 1963
2062 id_entry = pdev->id_entry; 1964 of_id = of_match_device(fsi_of_match, &pdev->dev);
2063 if (!id_entry) { 1965 if (of_id) {
1966 core = of_id->data;
1967 fsi_of_parse("fsia", np, &info.port_a, &pdev->dev);
1968 fsi_of_parse("fsib", np, &info.port_b, &pdev->dev);
1969 }
1970 } else {
1971 const struct platform_device_id *id_entry = pdev->id_entry;
1972 if (id_entry)
1973 core = (struct fsi_core *)id_entry->driver_data;
1974
1975 if (pdev->dev.platform_data)
1976 memcpy(&info, pdev->dev.platform_data, sizeof(info));
1977 }
1978
1979 if (!core) {
2064 dev_err(&pdev->dev, "unknown fsi device\n"); 1980 dev_err(&pdev->dev, "unknown fsi device\n");
2065 return -ENODEV; 1981 return -ENODEV;
2066 } 1982 }
@@ -2087,17 +2003,15 @@ static int fsi_probe(struct platform_device *pdev)
2087 2003
2088 /* master setting */ 2004 /* master setting */
2089 master->irq = irq; 2005 master->irq = irq;
2090 master->core = (struct fsi_core *)id_entry->driver_data; 2006 master->core = core;
2091 spin_lock_init(&master->lock); 2007 spin_lock_init(&master->lock);
2092 2008
2093 /* FSI A setting */ 2009 /* FSI A setting */
2094 pinfo = (info) ? &info->port_a : &nul_info;
2095 fsi = &master->fsia; 2010 fsi = &master->fsia;
2096 fsi->base = master->base; 2011 fsi->base = master->base;
2097 fsi->master = master; 2012 fsi->master = master;
2098 fsi->info = pinfo; 2013 fsi_port_info_init(fsi, &info.port_a);
2099 fsi_port_info_init(fsi, pinfo); 2014 fsi_handler_init(fsi, &info.port_a);
2100 fsi_handler_init(fsi, pinfo);
2101 ret = fsi_stream_probe(fsi, &pdev->dev); 2015 ret = fsi_stream_probe(fsi, &pdev->dev);
2102 if (ret < 0) { 2016 if (ret < 0) {
2103 dev_err(&pdev->dev, "FSIA stream probe failed\n"); 2017 dev_err(&pdev->dev, "FSIA stream probe failed\n");
@@ -2105,13 +2019,11 @@ static int fsi_probe(struct platform_device *pdev)
2105 } 2019 }
2106 2020
2107 /* FSI B setting */ 2021 /* FSI B setting */
2108 pinfo = (info) ? &info->port_b : &nul_info;
2109 fsi = &master->fsib; 2022 fsi = &master->fsib;
2110 fsi->base = master->base + 0x40; 2023 fsi->base = master->base + 0x40;
2111 fsi->master = master; 2024 fsi->master = master;
2112 fsi->info = pinfo; 2025 fsi_port_info_init(fsi, &info.port_b);
2113 fsi_port_info_init(fsi, pinfo); 2026 fsi_handler_init(fsi, &info.port_b);
2114 fsi_handler_init(fsi, pinfo);
2115 ret = fsi_stream_probe(fsi, &pdev->dev); 2027 ret = fsi_stream_probe(fsi, &pdev->dev);
2116 if (ret < 0) { 2028 if (ret < 0) {
2117 dev_err(&pdev->dev, "FSIB stream probe failed\n"); 2029 dev_err(&pdev->dev, "FSIB stream probe failed\n");
@@ -2122,7 +2034,7 @@ static int fsi_probe(struct platform_device *pdev)
2122 dev_set_drvdata(&pdev->dev, master); 2034 dev_set_drvdata(&pdev->dev, master);
2123 2035
2124 ret = devm_request_irq(&pdev->dev, irq, &fsi_interrupt, 0, 2036 ret = devm_request_irq(&pdev->dev, irq, &fsi_interrupt, 0,
2125 id_entry->name, master); 2037 dev_name(&pdev->dev), master);
2126 if (ret) { 2038 if (ret) {
2127 dev_err(&pdev->dev, "irq request err\n"); 2039 dev_err(&pdev->dev, "irq request err\n");
2128 goto exit_fsib; 2040 goto exit_fsib;
@@ -2248,6 +2160,13 @@ static struct fsi_core fsi2_core = {
2248 .b_mclk = B_MST_CTLR, 2160 .b_mclk = B_MST_CTLR,
2249}; 2161};
2250 2162
2163static struct of_device_id fsi_of_match[] = {
2164 { .compatible = "renesas,sh_fsi", .data = &fsi1_core},
2165 { .compatible = "renesas,sh_fsi2", .data = &fsi2_core},
2166 {},
2167};
2168MODULE_DEVICE_TABLE(of, fsi_of_match);
2169
2251static struct platform_device_id fsi_id_table[] = { 2170static struct platform_device_id fsi_id_table[] = {
2252 { "sh_fsi", (kernel_ulong_t)&fsi1_core }, 2171 { "sh_fsi", (kernel_ulong_t)&fsi1_core },
2253 { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, 2172 { "sh_fsi2", (kernel_ulong_t)&fsi2_core },
@@ -2259,6 +2178,7 @@ static struct platform_driver fsi_driver = {
2259 .driver = { 2178 .driver = {
2260 .name = "fsi-pcm-audio", 2179 .name = "fsi-pcm-audio",
2261 .pm = &fsi_pm_ops, 2180 .pm = &fsi_pm_ops,
2181 .of_match_table = fsi_of_match,
2262 }, 2182 },
2263 .probe = fsi_probe, 2183 .probe = fsi_probe,
2264 .remove = fsi_remove, 2184 .remove = fsi_remove,
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 5fbfb06e8083..b5b3db71e253 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -33,6 +33,8 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
33 struct snd_soc_dai *codec_dai = rtd->codec_dai; 33 struct snd_soc_dai *codec_dai = rtd->codec_dai;
34 int ret = 0; 34 int ret = 0;
35 35
36 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
37
36 if (platform->driver->compr_ops && platform->driver->compr_ops->open) { 38 if (platform->driver->compr_ops && platform->driver->compr_ops->open) {
37 ret = platform->driver->compr_ops->open(cstream); 39 ret = platform->driver->compr_ops->open(cstream);
38 if (ret < 0) { 40 if (ret < 0) {
@@ -61,15 +63,46 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
61 codec_dai->active++; 63 codec_dai->active++;
62 rtd->codec->active++; 64 rtd->codec->active++;
63 65
66 mutex_unlock(&rtd->pcm_mutex);
67
64 return 0; 68 return 0;
65 69
66machine_err: 70machine_err:
67 if (platform->driver->compr_ops && platform->driver->compr_ops->free) 71 if (platform->driver->compr_ops && platform->driver->compr_ops->free)
68 platform->driver->compr_ops->free(cstream); 72 platform->driver->compr_ops->free(cstream);
69out: 73out:
74 mutex_unlock(&rtd->pcm_mutex);
70 return ret; 75 return ret;
71} 76}
72 77
78/*
79 * Power down the audio subsystem pmdown_time msecs after close is called.
80 * This is to ensure there are no pops or clicks in between any music tracks
81 * due to DAPM power cycling.
82 */
83static void close_delayed_work(struct work_struct *work)
84{
85 struct snd_soc_pcm_runtime *rtd =
86 container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
87 struct snd_soc_dai *codec_dai = rtd->codec_dai;
88
89 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
90
91 dev_dbg(rtd->dev, "ASoC: pop wq checking: %s status: %s waiting: %s\n",
92 codec_dai->driver->playback.stream_name,
93 codec_dai->playback_active ? "active" : "inactive",
94 rtd->pop_wait ? "yes" : "no");
95
96 /* are we waiting on this codec DAI stream */
97 if (rtd->pop_wait == 1) {
98 rtd->pop_wait = 0;
99 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
100 SND_SOC_DAPM_STREAM_STOP);
101 }
102
103 mutex_unlock(&rtd->pcm_mutex);
104}
105
73static int soc_compr_free(struct snd_compr_stream *cstream) 106static int soc_compr_free(struct snd_compr_stream *cstream)
74{ 107{
75 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 108 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
@@ -78,6 +111,8 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
78 struct snd_soc_dai *codec_dai = rtd->codec_dai; 111 struct snd_soc_dai *codec_dai = rtd->codec_dai;
79 struct snd_soc_codec *codec = rtd->codec; 112 struct snd_soc_codec *codec = rtd->codec;
80 113
114 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
115
81 if (cstream->direction == SND_COMPRESS_PLAYBACK) { 116 if (cstream->direction == SND_COMPRESS_PLAYBACK) {
82 cpu_dai->playback_active--; 117 cpu_dai->playback_active--;
83 codec_dai->playback_active--; 118 codec_dai->playback_active--;
@@ -86,7 +121,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
86 codec_dai->capture_active--; 121 codec_dai->capture_active--;
87 } 122 }
88 123
89 snd_soc_dai_digital_mute(codec_dai, 1); 124 snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
90 125
91 cpu_dai->active--; 126 cpu_dai->active--;
92 codec_dai->active--; 127 codec_dai->active--;
@@ -112,10 +147,11 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
112 snd_soc_dapm_stream_event(rtd, 147 snd_soc_dapm_stream_event(rtd,
113 SNDRV_PCM_STREAM_PLAYBACK, 148 SNDRV_PCM_STREAM_PLAYBACK,
114 SND_SOC_DAPM_STREAM_STOP); 149 SND_SOC_DAPM_STREAM_STOP);
115 } else 150 } else {
116 rtd->pop_wait = 1; 151 rtd->pop_wait = 1;
117 schedule_delayed_work(&rtd->delayed_work, 152 schedule_delayed_work(&rtd->delayed_work,
118 msecs_to_jiffies(rtd->pmdown_time)); 153 msecs_to_jiffies(rtd->pmdown_time));
154 }
119 } else { 155 } else {
120 /* capture streams can be powered down now */ 156 /* capture streams can be powered down now */
121 snd_soc_dapm_stream_event(rtd, 157 snd_soc_dapm_stream_event(rtd,
@@ -123,6 +159,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
123 SND_SOC_DAPM_STREAM_STOP); 159 SND_SOC_DAPM_STREAM_STOP);
124 } 160 }
125 161
162 mutex_unlock(&rtd->pcm_mutex);
126 return 0; 163 return 0;
127} 164}
128 165
@@ -134,17 +171,25 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
134 struct snd_soc_dai *codec_dai = rtd->codec_dai; 171 struct snd_soc_dai *codec_dai = rtd->codec_dai;
135 int ret = 0; 172 int ret = 0;
136 173
174 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
175
137 if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) { 176 if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) {
138 ret = platform->driver->compr_ops->trigger(cstream, cmd); 177 ret = platform->driver->compr_ops->trigger(cstream, cmd);
139 if (ret < 0) 178 if (ret < 0)
140 return ret; 179 goto out;
141 } 180 }
142 181
143 if (cmd == SNDRV_PCM_TRIGGER_START) 182 switch (cmd) {
144 snd_soc_dai_digital_mute(codec_dai, 0); 183 case SNDRV_PCM_TRIGGER_START:
145 else if (cmd == SNDRV_PCM_TRIGGER_STOP) 184 snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction);
146 snd_soc_dai_digital_mute(codec_dai, 1); 185 break;
186 case SNDRV_PCM_TRIGGER_STOP:
187 snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
188 break;
189 }
147 190
191out:
192 mutex_unlock(&rtd->pcm_mutex);
148 return ret; 193 return ret;
149} 194}
150 195
@@ -155,6 +200,8 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
155 struct snd_soc_platform *platform = rtd->platform; 200 struct snd_soc_platform *platform = rtd->platform;
156 int ret = 0; 201 int ret = 0;
157 202
203 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
204
158 /* first we call set_params for the platform driver 205 /* first we call set_params for the platform driver
159 * this should configure the soc side 206 * this should configure the soc side
160 * if the machine has compressed ops then we call that as well 207 * if the machine has compressed ops then we call that as well
@@ -164,18 +211,20 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
164 if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) { 211 if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) {
165 ret = platform->driver->compr_ops->set_params(cstream, params); 212 ret = platform->driver->compr_ops->set_params(cstream, params);
166 if (ret < 0) 213 if (ret < 0)
167 return ret; 214 goto out;
168 } 215 }
169 216
170 if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) { 217 if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) {
171 ret = rtd->dai_link->compr_ops->set_params(cstream); 218 ret = rtd->dai_link->compr_ops->set_params(cstream);
172 if (ret < 0) 219 if (ret < 0)
173 return ret; 220 goto out;
174 } 221 }
175 222
176 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, 223 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
177 SND_SOC_DAPM_STREAM_START); 224 SND_SOC_DAPM_STREAM_START);
178 225
226out:
227 mutex_unlock(&rtd->pcm_mutex);
179 return ret; 228 return ret;
180} 229}
181 230
@@ -186,9 +235,12 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
186 struct snd_soc_platform *platform = rtd->platform; 235 struct snd_soc_platform *platform = rtd->platform;
187 int ret = 0; 236 int ret = 0;
188 237
238 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
239
189 if (platform->driver->compr_ops && platform->driver->compr_ops->get_params) 240 if (platform->driver->compr_ops && platform->driver->compr_ops->get_params)
190 ret = platform->driver->compr_ops->get_params(cstream, params); 241 ret = platform->driver->compr_ops->get_params(cstream, params);
191 242
243 mutex_unlock(&rtd->pcm_mutex);
192 return ret; 244 return ret;
193} 245}
194 246
@@ -199,9 +251,12 @@ static int soc_compr_get_caps(struct snd_compr_stream *cstream,
199 struct snd_soc_platform *platform = rtd->platform; 251 struct snd_soc_platform *platform = rtd->platform;
200 int ret = 0; 252 int ret = 0;
201 253
254 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
255
202 if (platform->driver->compr_ops && platform->driver->compr_ops->get_caps) 256 if (platform->driver->compr_ops && platform->driver->compr_ops->get_caps)
203 ret = platform->driver->compr_ops->get_caps(cstream, caps); 257 ret = platform->driver->compr_ops->get_caps(cstream, caps);
204 258
259 mutex_unlock(&rtd->pcm_mutex);
205 return ret; 260 return ret;
206} 261}
207 262
@@ -212,9 +267,12 @@ static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream,
212 struct snd_soc_platform *platform = rtd->platform; 267 struct snd_soc_platform *platform = rtd->platform;
213 int ret = 0; 268 int ret = 0;
214 269
270 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
271
215 if (platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps) 272 if (platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps)
216 ret = platform->driver->compr_ops->get_codec_caps(cstream, codec); 273 ret = platform->driver->compr_ops->get_codec_caps(cstream, codec);
217 274
275 mutex_unlock(&rtd->pcm_mutex);
218 return ret; 276 return ret;
219} 277}
220 278
@@ -224,9 +282,12 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
224 struct snd_soc_platform *platform = rtd->platform; 282 struct snd_soc_platform *platform = rtd->platform;
225 int ret = 0; 283 int ret = 0;
226 284
285 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
286
227 if (platform->driver->compr_ops && platform->driver->compr_ops->ack) 287 if (platform->driver->compr_ops && platform->driver->compr_ops->ack)
228 ret = platform->driver->compr_ops->ack(cstream, bytes); 288 ret = platform->driver->compr_ops->ack(cstream, bytes);
229 289
290 mutex_unlock(&rtd->pcm_mutex);
230 return ret; 291 return ret;
231} 292}
232 293
@@ -236,12 +297,31 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
236 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 297 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
237 struct snd_soc_platform *platform = rtd->platform; 298 struct snd_soc_platform *platform = rtd->platform;
238 299
300 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
301
239 if (platform->driver->compr_ops && platform->driver->compr_ops->pointer) 302 if (platform->driver->compr_ops && platform->driver->compr_ops->pointer)
240 platform->driver->compr_ops->pointer(cstream, tstamp); 303 platform->driver->compr_ops->pointer(cstream, tstamp);
241 304
305 mutex_unlock(&rtd->pcm_mutex);
242 return 0; 306 return 0;
243} 307}
244 308
309static int soc_compr_copy(struct snd_compr_stream *cstream,
310 const char __user *buf, size_t count)
311{
312 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
313 struct snd_soc_platform *platform = rtd->platform;
314 int ret = 0;
315
316 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
317
318 if (platform->driver->compr_ops && platform->driver->compr_ops->copy)
319 ret = platform->driver->compr_ops->copy(cstream, buf, count);
320
321 mutex_unlock(&rtd->pcm_mutex);
322 return ret;
323}
324
245/* ASoC Compress operations */ 325/* ASoC Compress operations */
246static struct snd_compr_ops soc_compr_ops = { 326static struct snd_compr_ops soc_compr_ops = {
247 .open = soc_compr_open, 327 .open = soc_compr_open,
@@ -259,6 +339,7 @@ static struct snd_compr_ops soc_compr_ops = {
259int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) 339int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
260{ 340{
261 struct snd_soc_codec *codec = rtd->codec; 341 struct snd_soc_codec *codec = rtd->codec;
342 struct snd_soc_platform *platform = rtd->platform;
262 struct snd_soc_dai *codec_dai = rtd->codec_dai; 343 struct snd_soc_dai *codec_dai = rtd->codec_dai;
263 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 344 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
264 struct snd_compr *compr; 345 struct snd_compr *compr;
@@ -275,20 +356,38 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
275 return -ENOMEM; 356 return -ENOMEM;
276 } 357 }
277 358
278 compr->ops = &soc_compr_ops; 359 compr->ops = devm_kzalloc(rtd->card->dev, sizeof(soc_compr_ops),
360 GFP_KERNEL);
361 if (compr->ops == NULL) {
362 dev_err(rtd->card->dev, "Cannot allocate compressed ops\n");
363 ret = -ENOMEM;
364 goto compr_err;
365 }
366 memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
367
368 /* Add copy callback for not memory mapped DSPs */
369 if (platform->driver->compr_ops && platform->driver->compr_ops->copy)
370 compr->ops->copy = soc_compr_copy;
371
279 mutex_init(&compr->lock); 372 mutex_init(&compr->lock);
280 ret = snd_compress_new(rtd->card->snd_card, num, direction, compr); 373 ret = snd_compress_new(rtd->card->snd_card, num, direction, compr);
281 if (ret < 0) { 374 if (ret < 0) {
282 pr_err("compress asoc: can't create compress for codec %s\n", 375 pr_err("compress asoc: can't create compress for codec %s\n",
283 codec->name); 376 codec->name);
284 kfree(compr); 377 goto compr_err;
285 return ret;
286 } 378 }
287 379
380 /* DAPM dai link stream work */
381 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
382
288 rtd->compr = compr; 383 rtd->compr = compr;
289 compr->private_data = rtd; 384 compr->private_data = rtd;
290 385
291 printk(KERN_INFO "compress asoc: %s <-> %s mapping ok\n", codec_dai->name, 386 printk(KERN_INFO "compress asoc: %s <-> %s mapping ok\n", codec_dai->name,
292 cpu_dai->name); 387 cpu_dai->name);
293 return ret; 388 return ret;
389
390compr_err:
391 kfree(compr);
392 return ret;
294} 393}
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 2370063b5824..8df1b3feaf2b 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1107,6 +1107,10 @@ static int soc_probe_codec(struct snd_soc_card *card,
1107 "ASoC: failed to probe CODEC %d\n", ret); 1107 "ASoC: failed to probe CODEC %d\n", ret);
1108 goto err_probe; 1108 goto err_probe;
1109 } 1109 }
1110 WARN(codec->dapm.idle_bias_off &&
1111 codec->dapm.bias_level != SND_SOC_BIAS_OFF,
1112 "codec %s can not start from non-off bias"
1113 " with idle_bias_off==1\n", codec->name);
1110 } 1114 }
1111 1115
1112 /* If the driver didn't set I/O up try regmap */ 1116 /* If the driver didn't set I/O up try regmap */
@@ -3122,9 +3126,12 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3122 if (!codec->using_regmap) 3126 if (!codec->using_regmap)
3123 return -EINVAL; 3127 return -EINVAL;
3124 3128
3125 data = ucontrol->value.bytes.data;
3126 len = params->num_regs * codec->val_bytes; 3129 len = params->num_regs * codec->val_bytes;
3127 3130
3131 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
3132 if (!data)
3133 return -ENOMEM;
3134
3128 /* 3135 /*
3129 * If we've got a mask then we need to preserve the register 3136 * If we've got a mask then we need to preserve the register
3130 * bits. We shouldn't modify the incoming data so take a 3137 * bits. We shouldn't modify the incoming data so take a
@@ -3137,10 +3144,6 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3137 3144
3138 val &= params->mask; 3145 val &= params->mask;
3139 3146
3140 data = kmemdup(data, len, GFP_KERNEL);
3141 if (!data)
3142 return -ENOMEM;
3143
3144 switch (codec->val_bytes) { 3147 switch (codec->val_bytes) {
3145 case 1: 3148 case 1:
3146 ((u8 *)data)[0] &= ~params->mask; 3149 ((u8 *)data)[0] &= ~params->mask;
@@ -3162,8 +3165,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3162 ret = regmap_raw_write(codec->control_data, params->base, 3165 ret = regmap_raw_write(codec->control_data, params->base,
3163 data, len); 3166 data, len);
3164 3167
3165 if (params->mask) 3168 kfree(data);
3166 kfree(data);
3167 3169
3168 return ret; 3170 return ret;
3169} 3171}
@@ -3540,12 +3542,20 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
3540 * snd_soc_dai_digital_mute - configure DAI system or master clock. 3542 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3541 * @dai: DAI 3543 * @dai: DAI
3542 * @mute: mute enable 3544 * @mute: mute enable
3545 * @direction: stream to mute
3543 * 3546 *
3544 * Mutes the DAI DAC. 3547 * Mutes the DAI DAC.
3545 */ 3548 */
3546int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) 3549int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
3550 int direction)
3547{ 3551{
3548 if (dai->driver && dai->driver->ops->digital_mute) 3552 if (!dai->driver)
3553 return -ENOTSUPP;
3554
3555 if (dai->driver->ops->mute_stream)
3556 return dai->driver->ops->mute_stream(dai, mute, direction);
3557 else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
3558 dai->driver->ops->digital_mute)
3549 return dai->driver->ops->digital_mute(dai, mute); 3559 return dai->driver->ops->digital_mute(dai, mute);
3550 else 3560 else
3551 return -ENOTSUPP; 3561 return -ENOTSUPP;
@@ -4208,6 +4218,113 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4208} 4218}
4209EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); 4219EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
4210 4220
4221unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
4222 const char *prefix)
4223{
4224 int ret, i;
4225 char prop[128];
4226 unsigned int format = 0;
4227 int bit, frame;
4228 const char *str;
4229 struct {
4230 char *name;
4231 unsigned int val;
4232 } of_fmt_table[] = {
4233 { "i2s", SND_SOC_DAIFMT_I2S },
4234 { "right_j", SND_SOC_DAIFMT_RIGHT_J },
4235 { "left_j", SND_SOC_DAIFMT_LEFT_J },
4236 { "dsp_a", SND_SOC_DAIFMT_DSP_A },
4237 { "dsp_b", SND_SOC_DAIFMT_DSP_B },
4238 { "ac97", SND_SOC_DAIFMT_AC97 },
4239 { "pdm", SND_SOC_DAIFMT_PDM},
4240 { "msb", SND_SOC_DAIFMT_MSB },
4241 { "lsb", SND_SOC_DAIFMT_LSB },
4242 };
4243
4244 if (!prefix)
4245 prefix = "";
4246
4247 /*
4248 * check "[prefix]format = xxx"
4249 * SND_SOC_DAIFMT_FORMAT_MASK area
4250 */
4251 snprintf(prop, sizeof(prop), "%sformat", prefix);
4252 ret = of_property_read_string(np, prop, &str);
4253 if (ret == 0) {
4254 for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
4255 if (strcmp(str, of_fmt_table[i].name) == 0) {
4256 format |= of_fmt_table[i].val;
4257 break;
4258 }
4259 }
4260 }
4261
4262 /*
4263 * check "[prefix]continuous-clock"
4264 * SND_SOC_DAIFMT_CLOCK_MASK area
4265 */
4266 snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
4267 if (of_get_property(np, prop, NULL))
4268 format |= SND_SOC_DAIFMT_CONT;
4269 else
4270 format |= SND_SOC_DAIFMT_GATED;
4271
4272 /*
4273 * check "[prefix]bitclock-inversion"
4274 * check "[prefix]frame-inversion"
4275 * SND_SOC_DAIFMT_INV_MASK area
4276 */
4277 snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
4278 bit = !!of_get_property(np, prop, NULL);
4279
4280 snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
4281 frame = !!of_get_property(np, prop, NULL);
4282
4283 switch ((bit << 4) + frame) {
4284 case 0x11:
4285 format |= SND_SOC_DAIFMT_IB_IF;
4286 break;
4287 case 0x10:
4288 format |= SND_SOC_DAIFMT_IB_NF;
4289 break;
4290 case 0x01:
4291 format |= SND_SOC_DAIFMT_NB_IF;
4292 break;
4293 default:
4294 /* SND_SOC_DAIFMT_NB_NF is default */
4295 break;
4296 }
4297
4298 /*
4299 * check "[prefix]bitclock-master"
4300 * check "[prefix]frame-master"
4301 * SND_SOC_DAIFMT_MASTER_MASK area
4302 */
4303 snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
4304 bit = !!of_get_property(np, prop, NULL);
4305
4306 snprintf(prop, sizeof(prop), "%sframe-master", prefix);
4307 frame = !!of_get_property(np, prop, NULL);
4308
4309 switch ((bit << 4) + frame) {
4310 case 0x11:
4311 format |= SND_SOC_DAIFMT_CBM_CFM;
4312 break;
4313 case 0x10:
4314 format |= SND_SOC_DAIFMT_CBM_CFS;
4315 break;
4316 case 0x01:
4317 format |= SND_SOC_DAIFMT_CBS_CFM;
4318 break;
4319 default:
4320 format |= SND_SOC_DAIFMT_CBS_CFS;
4321 break;
4322 }
4323
4324 return format;
4325}
4326EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
4327
4211static int __init snd_soc_init(void) 4328static int __init snd_soc_init(void)
4212{ 4329{
4213#ifdef CONFIG_DEBUG_FS 4330#ifdef CONFIG_DEBUG_FS
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 258acadb9e7d..1d6a9b3ceb27 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -3255,14 +3255,16 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3255 break; 3255 break;
3256 3256
3257 case SND_SOC_DAPM_POST_PMU: 3257 case SND_SOC_DAPM_POST_PMU:
3258 ret = snd_soc_dai_digital_mute(sink, 0); 3258 ret = snd_soc_dai_digital_mute(sink, 0,
3259 SNDRV_PCM_STREAM_PLAYBACK);
3259 if (ret != 0 && ret != -ENOTSUPP) 3260 if (ret != 0 && ret != -ENOTSUPP)
3260 dev_warn(sink->dev, "ASoC: Failed to unmute: %d\n", ret); 3261 dev_warn(sink->dev, "ASoC: Failed to unmute: %d\n", ret);
3261 ret = 0; 3262 ret = 0;
3262 break; 3263 break;
3263 3264
3264 case SND_SOC_DAPM_PRE_PMD: 3265 case SND_SOC_DAPM_PRE_PMD:
3265 ret = snd_soc_dai_digital_mute(sink, 1); 3266 ret = snd_soc_dai_digital_mute(sink, 1,
3267 SNDRV_PCM_STREAM_PLAYBACK);
3266 if (ret != 0 && ret != -ENOTSUPP) 3268 if (ret != 0 && ret != -ENOTSUPP)
3267 dev_warn(sink->dev, "ASoC: Failed to mute: %d\n", ret); 3269 dev_warn(sink->dev, "ASoC: Failed to mute: %d\n", ret);
3268 ret = 0; 3270 ret = 0;
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index cf191e6aebbe..73bb8eefa491 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -383,8 +383,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
383 /* Muting the DAC suppresses artifacts caused during digital 383 /* Muting the DAC suppresses artifacts caused during digital
384 * shutdown, for example from stopping clocks. 384 * shutdown, for example from stopping clocks.
385 */ 385 */
386 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 386 snd_soc_dai_digital_mute(codec_dai, 1, substream->stream);
387 snd_soc_dai_digital_mute(codec_dai, 1);
388 387
389 if (cpu_dai->driver->ops->shutdown) 388 if (cpu_dai->driver->ops->shutdown)
390 cpu_dai->driver->ops->shutdown(substream, cpu_dai); 389 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
@@ -488,7 +487,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
488 snd_soc_dapm_stream_event(rtd, substream->stream, 487 snd_soc_dapm_stream_event(rtd, substream->stream,
489 SND_SOC_DAPM_STREAM_START); 488 SND_SOC_DAPM_STREAM_START);
490 489
491 snd_soc_dai_digital_mute(codec_dai, 0); 490 snd_soc_dai_digital_mute(codec_dai, 0, substream->stream);
492 491
493out: 492out:
494 mutex_unlock(&rtd->pcm_mutex); 493 mutex_unlock(&rtd->pcm_mutex);
@@ -586,7 +585,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
586 585
587 /* apply codec digital mute */ 586 /* apply codec digital mute */
588 if (!codec->active) 587 if (!codec->active)
589 snd_soc_dai_digital_mute(codec_dai, 1); 588 snd_soc_dai_digital_mute(codec_dai, 1, substream->stream);
590 589
591 /* free any machine hw params */ 590 /* free any machine hw params */
592 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free) 591 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
@@ -1729,20 +1728,16 @@ static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
1729 1728
1730 /* startup must always be called for new BEs */ 1729 /* startup must always be called for new BEs */
1731 ret = dpcm_be_dai_startup(fe, stream); 1730 ret = dpcm_be_dai_startup(fe, stream);
1732 if (ret < 0) { 1731 if (ret < 0)
1733 goto disconnect; 1732 goto disconnect;
1734 return ret;
1735 }
1736 1733
1737 /* keep going if FE state is > open */ 1734 /* keep going if FE state is > open */
1738 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN) 1735 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
1739 return 0; 1736 return 0;
1740 1737
1741 ret = dpcm_be_dai_hw_params(fe, stream); 1738 ret = dpcm_be_dai_hw_params(fe, stream);
1742 if (ret < 0) { 1739 if (ret < 0)
1743 goto close; 1740 goto close;
1744 return ret;
1745 }
1746 1741
1747 /* keep going if FE state is > hw_params */ 1742 /* keep going if FE state is > hw_params */
1748 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS) 1743 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
@@ -1750,10 +1745,8 @@ static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
1750 1745
1751 1746
1752 ret = dpcm_be_dai_prepare(fe, stream); 1747 ret = dpcm_be_dai_prepare(fe, stream);
1753 if (ret < 0) { 1748 if (ret < 0)
1754 goto hw_free; 1749 goto hw_free;
1755 return ret;
1756 }
1757 1750
1758 /* run the stream event for each BE */ 1751 /* run the stream event for each BE */
1759 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP); 1752 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index 19e5fe7cc403..dbc27ce1d4de 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -6,6 +6,16 @@ config SND_SOC_TEGRA
6 help 6 help
7 Say Y or M here if you want support for SoC audio on Tegra. 7 Say Y or M here if you want support for SoC audio on Tegra.
8 8
9config SND_SOC_TEGRA20_AC97
10 tristate
11 depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC
12 select SND_SOC_AC97_BUS
13 select SND_SOC_TEGRA20_DAS
14 help
15 Say Y or M if you want to add support for codecs attached to the
16 Tegra20 AC97 interface. You will also need to select the individual
17 machine drivers to support below.
18
9config SND_SOC_TEGRA20_DAS 19config SND_SOC_TEGRA20_DAS
10 tristate 20 tristate
11 depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC 21 depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC
@@ -70,6 +80,15 @@ config SND_SOC_TEGRA_WM8903
70 boards using the WM8093 codec. Currently, the supported boards are 80 boards using the WM8093 codec. Currently, the supported boards are
71 Harmony, Ventana, Seaboard, Kaen, and Aebl. 81 Harmony, Ventana, Seaboard, Kaen, and Aebl.
72 82
83config SND_SOC_TEGRA_WM9712
84 tristate "SoC Audio support for Tegra boards using a WM9712 codec"
85 depends on SND_SOC_TEGRA && ARCH_TEGRA_2x_SOC
86 select SND_SOC_TEGRA20_AC97
87 select SND_SOC_WM9712
88 help
89 Say Y or M here if you want to add support for SoC audio on Tegra
90 boards using the WM9712 (or compatible) codec.
91
73config SND_SOC_TEGRA_TRIMSLICE 92config SND_SOC_TEGRA_TRIMSLICE
74 tristate "SoC Audio support for TrimSlice board" 93 tristate "SoC Audio support for TrimSlice board"
75 depends on SND_SOC_TEGRA && I2C 94 depends on SND_SOC_TEGRA && I2C
diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile
index 391e78a34c06..416a14bde41b 100644
--- a/sound/soc/tegra/Makefile
+++ b/sound/soc/tegra/Makefile
@@ -1,6 +1,7 @@
1# Tegra platform Support 1# Tegra platform Support
2snd-soc-tegra-pcm-objs := tegra_pcm.o 2snd-soc-tegra-pcm-objs := tegra_pcm.o
3snd-soc-tegra-utils-objs += tegra_asoc_utils.o 3snd-soc-tegra-utils-objs += tegra_asoc_utils.o
4snd-soc-tegra20-ac97-objs := tegra20_ac97.o
4snd-soc-tegra20-das-objs := tegra20_das.o 5snd-soc-tegra20-das-objs := tegra20_das.o
5snd-soc-tegra20-i2s-objs := tegra20_i2s.o 6snd-soc-tegra20-i2s-objs := tegra20_i2s.o
6snd-soc-tegra20-spdif-objs := tegra20_spdif.o 7snd-soc-tegra20-spdif-objs := tegra20_spdif.o
@@ -9,6 +10,7 @@ snd-soc-tegra30-i2s-objs := tegra30_i2s.o
9 10
10obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o 11obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
11obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o 12obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
13obj-$(CONFIG_SND_SOC_TEGRA20_AC97) += snd-soc-tegra20-ac97.o
12obj-$(CONFIG_SND_SOC_TEGRA20_DAS) += snd-soc-tegra20-das.o 14obj-$(CONFIG_SND_SOC_TEGRA20_DAS) += snd-soc-tegra20-das.o
13obj-$(CONFIG_SND_SOC_TEGRA20_I2S) += snd-soc-tegra20-i2s.o 15obj-$(CONFIG_SND_SOC_TEGRA20_I2S) += snd-soc-tegra20-i2s.o
14obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o 16obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o
@@ -18,10 +20,12 @@ obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
18# Tegra machine Support 20# Tegra machine Support
19snd-soc-tegra-wm8753-objs := tegra_wm8753.o 21snd-soc-tegra-wm8753-objs := tegra_wm8753.o
20snd-soc-tegra-wm8903-objs := tegra_wm8903.o 22snd-soc-tegra-wm8903-objs := tegra_wm8903.o
23snd-soc-tegra-wm9712-objs := tegra_wm9712.o
21snd-soc-tegra-trimslice-objs := trimslice.o 24snd-soc-tegra-trimslice-objs := trimslice.o
22snd-soc-tegra-alc5632-objs := tegra_alc5632.o 25snd-soc-tegra-alc5632-objs := tegra_alc5632.o
23 26
24obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o 27obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o
25obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o 28obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o
29obj-$(CONFIG_SND_SOC_TEGRA_WM9712) += snd-soc-tegra-wm9712.o
26obj-$(CONFIG_SND_SOC_TEGRA_TRIMSLICE) += snd-soc-tegra-trimslice.o 30obj-$(CONFIG_SND_SOC_TEGRA_TRIMSLICE) += snd-soc-tegra-trimslice.o
27obj-$(CONFIG_SND_SOC_TEGRA_ALC5632) += snd-soc-tegra-alc5632.o 31obj-$(CONFIG_SND_SOC_TEGRA_ALC5632) += snd-soc-tegra-alc5632.o
diff --git a/sound/soc/tegra/tegra20_ac97.c b/sound/soc/tegra/tegra20_ac97.c
new file mode 100644
index 000000000000..336dcdd3e8a4
--- /dev/null
+++ b/sound/soc/tegra/tegra20_ac97.c
@@ -0,0 +1,480 @@
1/*
2 * tegra20_ac97.c - Tegra20 AC97 platform driver
3 *
4 * Copyright (c) 2012 Lucas Stach <dev@lynxeye.de>
5 *
6 * Partly based on code copyright/by:
7 *
8 * Copyright (c) 2011,2012 Toradex Inc.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 */
20
21#include <linux/clk.h>
22#include <linux/delay.h>
23#include <linux/device.h>
24#include <linux/gpio.h>
25#include <linux/io.h>
26#include <linux/jiffies.h>
27#include <linux/module.h>
28#include <linux/of.h>
29#include <linux/of_gpio.h>
30#include <linux/platform_device.h>
31#include <linux/pm_runtime.h>
32#include <linux/regmap.h>
33#include <linux/slab.h>
34#include <sound/core.h>
35#include <sound/pcm.h>
36#include <sound/pcm_params.h>
37#include <sound/soc.h>
38
39#include "tegra_asoc_utils.h"
40#include "tegra20_ac97.h"
41
42#define DRV_NAME "tegra20-ac97"
43
44static struct tegra20_ac97 *workdata;
45
46static void tegra20_ac97_codec_reset(struct snd_ac97 *ac97)
47{
48 u32 readback;
49 unsigned long timeout;
50
51 /* reset line is not driven by DAC pad group, have to toggle GPIO */
52 gpio_set_value(workdata->reset_gpio, 0);
53 udelay(2);
54
55 gpio_set_value(workdata->reset_gpio, 1);
56 udelay(2);
57
58 timeout = jiffies + msecs_to_jiffies(100);
59
60 do {
61 regmap_read(workdata->regmap, TEGRA20_AC97_STATUS1, &readback);
62 if (readback & TEGRA20_AC97_STATUS1_CODEC1_RDY)
63 break;
64 usleep_range(1000, 2000);
65 } while (!time_after(jiffies, timeout));
66}
67
68static void tegra20_ac97_codec_warm_reset(struct snd_ac97 *ac97)
69{
70 u32 readback;
71 unsigned long timeout;
72
73 /*
74 * although sync line is driven by the DAC pad group warm reset using
75 * the controller cmd is not working, have to toggle sync line
76 * manually.
77 */
78 gpio_request(workdata->sync_gpio, "codec-sync");
79
80 gpio_direction_output(workdata->sync_gpio, 1);
81
82 udelay(2);
83 gpio_set_value(workdata->sync_gpio, 0);
84 udelay(2);
85 gpio_free(workdata->sync_gpio);
86
87 timeout = jiffies + msecs_to_jiffies(100);
88
89 do {
90 regmap_read(workdata->regmap, TEGRA20_AC97_STATUS1, &readback);
91 if (readback & TEGRA20_AC97_STATUS1_CODEC1_RDY)
92 break;
93 usleep_range(1000, 2000);
94 } while (!time_after(jiffies, timeout));
95}
96
97static unsigned short tegra20_ac97_codec_read(struct snd_ac97 *ac97_snd,
98 unsigned short reg)
99{
100 u32 readback;
101 unsigned long timeout;
102
103 regmap_write(workdata->regmap, TEGRA20_AC97_CMD,
104 (((reg | 0x80) << TEGRA20_AC97_CMD_CMD_ADDR_SHIFT) &
105 TEGRA20_AC97_CMD_CMD_ADDR_MASK) |
106 TEGRA20_AC97_CMD_BUSY);
107
108 timeout = jiffies + msecs_to_jiffies(100);
109
110 do {
111 regmap_read(workdata->regmap, TEGRA20_AC97_STATUS1, &readback);
112 if (readback & TEGRA20_AC97_STATUS1_STA_VALID1)
113 break;
114 usleep_range(1000, 2000);
115 } while (!time_after(jiffies, timeout));
116
117 return ((readback & TEGRA20_AC97_STATUS1_STA_DATA1_MASK) >>
118 TEGRA20_AC97_STATUS1_STA_DATA1_SHIFT);
119}
120
121static void tegra20_ac97_codec_write(struct snd_ac97 *ac97_snd,
122 unsigned short reg, unsigned short val)
123{
124 u32 readback;
125 unsigned long timeout;
126
127 regmap_write(workdata->regmap, TEGRA20_AC97_CMD,
128 ((reg << TEGRA20_AC97_CMD_CMD_ADDR_SHIFT) &
129 TEGRA20_AC97_CMD_CMD_ADDR_MASK) |
130 ((val << TEGRA20_AC97_CMD_CMD_DATA_SHIFT) &
131 TEGRA20_AC97_CMD_CMD_DATA_MASK) |
132 TEGRA20_AC97_CMD_BUSY);
133
134 timeout = jiffies + msecs_to_jiffies(100);
135
136 do {
137 regmap_read(workdata->regmap, TEGRA20_AC97_CMD, &readback);
138 if (!(readback & TEGRA20_AC97_CMD_BUSY))
139 break;
140 usleep_range(1000, 2000);
141 } while (!time_after(jiffies, timeout));
142}
143
144struct snd_ac97_bus_ops soc_ac97_ops = {
145 .read = tegra20_ac97_codec_read,
146 .write = tegra20_ac97_codec_write,
147 .reset = tegra20_ac97_codec_reset,
148 .warm_reset = tegra20_ac97_codec_warm_reset,
149};
150EXPORT_SYMBOL_GPL(soc_ac97_ops);
151
152static inline void tegra20_ac97_start_playback(struct tegra20_ac97 *ac97)
153{
154 regmap_update_bits(ac97->regmap, TEGRA20_AC97_FIFO1_SCR,
155 TEGRA20_AC97_FIFO_SCR_PB_QRT_MT_EN,
156 TEGRA20_AC97_FIFO_SCR_PB_QRT_MT_EN);
157
158 regmap_update_bits(ac97->regmap, TEGRA20_AC97_CTRL,
159 TEGRA20_AC97_CTRL_PCM_DAC_EN |
160 TEGRA20_AC97_CTRL_STM_EN,
161 TEGRA20_AC97_CTRL_PCM_DAC_EN |
162 TEGRA20_AC97_CTRL_STM_EN);
163}
164
165static inline void tegra20_ac97_stop_playback(struct tegra20_ac97 *ac97)
166{
167 regmap_update_bits(ac97->regmap, TEGRA20_AC97_FIFO1_SCR,
168 TEGRA20_AC97_FIFO_SCR_PB_QRT_MT_EN, 0);
169
170 regmap_update_bits(ac97->regmap, TEGRA20_AC97_CTRL,
171 TEGRA20_AC97_CTRL_PCM_DAC_EN, 0);
172}
173
174static inline void tegra20_ac97_start_capture(struct tegra20_ac97 *ac97)
175{
176 regmap_update_bits(ac97->regmap, TEGRA20_AC97_FIFO1_SCR,
177 TEGRA20_AC97_FIFO_SCR_REC_FULL_EN,
178 TEGRA20_AC97_FIFO_SCR_REC_FULL_EN);
179}
180
181static inline void tegra20_ac97_stop_capture(struct tegra20_ac97 *ac97)
182{
183 regmap_update_bits(ac97->regmap, TEGRA20_AC97_FIFO1_SCR,
184 TEGRA20_AC97_FIFO_SCR_REC_FULL_EN, 0);
185}
186
187static int tegra20_ac97_trigger(struct snd_pcm_substream *substream, int cmd,
188 struct snd_soc_dai *dai)
189{
190 struct tegra20_ac97 *ac97 = snd_soc_dai_get_drvdata(dai);
191
192 switch (cmd) {
193 case SNDRV_PCM_TRIGGER_START:
194 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
195 case SNDRV_PCM_TRIGGER_RESUME:
196 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
197 tegra20_ac97_start_playback(ac97);
198 else
199 tegra20_ac97_start_capture(ac97);
200 break;
201 case SNDRV_PCM_TRIGGER_STOP:
202 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
203 case SNDRV_PCM_TRIGGER_SUSPEND:
204 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
205 tegra20_ac97_stop_playback(ac97);
206 else
207 tegra20_ac97_stop_capture(ac97);
208 break;
209 default:
210 return -EINVAL;
211 }
212
213 return 0;
214}
215
216static const struct snd_soc_dai_ops tegra20_ac97_dai_ops = {
217 .trigger = tegra20_ac97_trigger,
218};
219
220static int tegra20_ac97_probe(struct snd_soc_dai *dai)
221{
222 struct tegra20_ac97 *ac97 = snd_soc_dai_get_drvdata(dai);
223
224 dai->capture_dma_data = &ac97->capture_dma_data;
225 dai->playback_dma_data = &ac97->playback_dma_data;
226
227 return 0;
228}
229
230static struct snd_soc_dai_driver tegra20_ac97_dai = {
231 .name = "tegra-ac97-pcm",
232 .ac97_control = 1,
233 .probe = tegra20_ac97_probe,
234 .playback = {
235 .stream_name = "PCM Playback",
236 .channels_min = 2,
237 .channels_max = 2,
238 .rates = SNDRV_PCM_RATE_8000_48000,
239 .formats = SNDRV_PCM_FMTBIT_S16_LE,
240 },
241 .capture = {
242 .stream_name = "PCM Capture",
243 .channels_min = 2,
244 .channels_max = 2,
245 .rates = SNDRV_PCM_RATE_8000_48000,
246 .formats = SNDRV_PCM_FMTBIT_S16_LE,
247 },
248 .ops = &tegra20_ac97_dai_ops,
249};
250
251static bool tegra20_ac97_wr_rd_reg(struct device *dev, unsigned int reg)
252{
253 switch (reg) {
254 case TEGRA20_AC97_CTRL:
255 case TEGRA20_AC97_CMD:
256 case TEGRA20_AC97_STATUS1:
257 case TEGRA20_AC97_FIFO1_SCR:
258 case TEGRA20_AC97_FIFO_TX1:
259 case TEGRA20_AC97_FIFO_RX1:
260 return true;
261 default:
262 break;
263 }
264
265 return false;
266}
267
268static bool tegra20_ac97_volatile_reg(struct device *dev, unsigned int reg)
269{
270 switch (reg) {
271 case TEGRA20_AC97_STATUS1:
272 case TEGRA20_AC97_FIFO1_SCR:
273 case TEGRA20_AC97_FIFO_TX1:
274 case TEGRA20_AC97_FIFO_RX1:
275 return true;
276 default:
277 break;
278 }
279
280 return false;
281}
282
283static bool tegra20_ac97_precious_reg(struct device *dev, unsigned int reg)
284{
285 switch (reg) {
286 case TEGRA20_AC97_FIFO_TX1:
287 case TEGRA20_AC97_FIFO_RX1:
288 return true;
289 default:
290 break;
291 }
292
293 return false;
294}
295
296static const struct regmap_config tegra20_ac97_regmap_config = {
297 .reg_bits = 32,
298 .reg_stride = 4,
299 .val_bits = 32,
300 .max_register = TEGRA20_AC97_FIFO_RX1,
301 .writeable_reg = tegra20_ac97_wr_rd_reg,
302 .readable_reg = tegra20_ac97_wr_rd_reg,
303 .volatile_reg = tegra20_ac97_volatile_reg,
304 .precious_reg = tegra20_ac97_precious_reg,
305 .cache_type = REGCACHE_RBTREE,
306};
307
308static int tegra20_ac97_platform_probe(struct platform_device *pdev)
309{
310 struct tegra20_ac97 *ac97;
311 struct resource *mem, *memregion;
312 u32 of_dma[2];
313 void __iomem *regs;
314 int ret = 0;
315
316 ac97 = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_ac97),
317 GFP_KERNEL);
318 if (!ac97) {
319 dev_err(&pdev->dev, "Can't allocate tegra20_ac97\n");
320 ret = -ENOMEM;
321 goto err;
322 }
323 dev_set_drvdata(&pdev->dev, ac97);
324
325 ac97->clk_ac97 = clk_get(&pdev->dev, NULL);
326 if (IS_ERR(ac97->clk_ac97)) {
327 dev_err(&pdev->dev, "Can't retrieve ac97 clock\n");
328 ret = PTR_ERR(ac97->clk_ac97);
329 goto err;
330 }
331
332 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
333 if (!mem) {
334 dev_err(&pdev->dev, "No memory resource\n");
335 ret = -ENODEV;
336 goto err_clk_put;
337 }
338
339 memregion = devm_request_mem_region(&pdev->dev, mem->start,
340 resource_size(mem), DRV_NAME);
341 if (!memregion) {
342 dev_err(&pdev->dev, "Memory region already claimed\n");
343 ret = -EBUSY;
344 goto err_clk_put;
345 }
346
347 regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
348 if (!regs) {
349 dev_err(&pdev->dev, "ioremap failed\n");
350 ret = -ENOMEM;
351 goto err_clk_put;
352 }
353
354 ac97->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
355 &tegra20_ac97_regmap_config);
356 if (IS_ERR(ac97->regmap)) {
357 dev_err(&pdev->dev, "regmap init failed\n");
358 ret = PTR_ERR(ac97->regmap);
359 goto err_clk_put;
360 }
361
362 if (of_property_read_u32_array(pdev->dev.of_node,
363 "nvidia,dma-request-selector",
364 of_dma, 2) < 0) {
365 dev_err(&pdev->dev, "No DMA resource\n");
366 ret = -ENODEV;
367 goto err_clk_put;
368 }
369
370 ac97->reset_gpio = of_get_named_gpio(pdev->dev.of_node,
371 "nvidia,codec-reset-gpio", 0);
372 if (gpio_is_valid(ac97->reset_gpio)) {
373 ret = devm_gpio_request_one(&pdev->dev, ac97->reset_gpio,
374 GPIOF_OUT_INIT_HIGH, "codec-reset");
375 if (ret) {
376 dev_err(&pdev->dev, "could not get codec-reset GPIO\n");
377 goto err_clk_put;
378 }
379 } else {
380 dev_err(&pdev->dev, "no codec-reset GPIO supplied\n");
381 goto err_clk_put;
382 }
383
384 ac97->sync_gpio = of_get_named_gpio(pdev->dev.of_node,
385 "nvidia,codec-sync-gpio", 0);
386 if (!gpio_is_valid(ac97->sync_gpio)) {
387 dev_err(&pdev->dev, "no codec-sync GPIO supplied\n");
388 goto err_clk_put;
389 }
390
391 ac97->capture_dma_data.addr = mem->start + TEGRA20_AC97_FIFO_RX1;
392 ac97->capture_dma_data.wrap = 4;
393 ac97->capture_dma_data.width = 32;
394 ac97->capture_dma_data.req_sel = of_dma[1];
395
396 ac97->playback_dma_data.addr = mem->start + TEGRA20_AC97_FIFO_TX1;
397 ac97->playback_dma_data.wrap = 4;
398 ac97->playback_dma_data.width = 32;
399 ac97->playback_dma_data.req_sel = of_dma[1];
400
401 ret = snd_soc_register_dais(&pdev->dev, &tegra20_ac97_dai, 1);
402 if (ret) {
403 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
404 ret = -ENOMEM;
405 goto err_clk_put;
406 }
407
408 ret = tegra_pcm_platform_register(&pdev->dev);
409 if (ret) {
410 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
411 goto err_unregister_dai;
412 }
413
414 ret = tegra_asoc_utils_init(&ac97->util_data, &pdev->dev);
415 if (ret)
416 goto err_unregister_pcm;
417
418 ret = tegra_asoc_utils_set_ac97_rate(&ac97->util_data);
419 if (ret)
420 goto err_asoc_utils_fini;
421
422 ret = clk_prepare_enable(ac97->clk_ac97);
423 if (ret) {
424 dev_err(&pdev->dev, "clk_enable failed: %d\n", ret);
425 goto err_asoc_utils_fini;
426 }
427
428 /* XXX: crufty ASoC AC97 API - only one AC97 codec allowed */
429 workdata = ac97;
430
431 return 0;
432
433err_asoc_utils_fini:
434 tegra_asoc_utils_fini(&ac97->util_data);
435err_unregister_pcm:
436 tegra_pcm_platform_unregister(&pdev->dev);
437err_unregister_dai:
438 snd_soc_unregister_dai(&pdev->dev);
439err_clk_put:
440 clk_put(ac97->clk_ac97);
441err:
442 return ret;
443}
444
445static int tegra20_ac97_platform_remove(struct platform_device *pdev)
446{
447 struct tegra20_ac97 *ac97 = dev_get_drvdata(&pdev->dev);
448
449 tegra_pcm_platform_unregister(&pdev->dev);
450 snd_soc_unregister_dai(&pdev->dev);
451
452 tegra_asoc_utils_fini(&ac97->util_data);
453
454 clk_disable_unprepare(ac97->clk_ac97);
455 clk_put(ac97->clk_ac97);
456
457 return 0;
458}
459
460static const struct of_device_id tegra20_ac97_of_match[] = {
461 { .compatible = "nvidia,tegra20-ac97", },
462 {},
463};
464
465static struct platform_driver tegra20_ac97_driver = {
466 .driver = {
467 .name = DRV_NAME,
468 .owner = THIS_MODULE,
469 .of_match_table = tegra20_ac97_of_match,
470 },
471 .probe = tegra20_ac97_platform_probe,
472 .remove = tegra20_ac97_platform_remove,
473};
474module_platform_driver(tegra20_ac97_driver);
475
476MODULE_AUTHOR("Lucas Stach");
477MODULE_DESCRIPTION("Tegra20 AC97 ASoC driver");
478MODULE_LICENSE("GPL v2");
479MODULE_ALIAS("platform:" DRV_NAME);
480MODULE_DEVICE_TABLE(of, tegra20_ac97_of_match);
diff --git a/sound/soc/tegra/tegra20_ac97.h b/sound/soc/tegra/tegra20_ac97.h
new file mode 100644
index 000000000000..dddc6828004e
--- /dev/null
+++ b/sound/soc/tegra/tegra20_ac97.h
@@ -0,0 +1,95 @@
1/*
2 * tegra20_ac97.h - Definitions for the Tegra20 AC97 controller driver
3 *
4 * Copyright (c) 2012 Lucas Stach <dev@lynxeye.de>
5 *
6 * Partly based on code copyright/by:
7 *
8 * Copyright (c) 2011,2012 Toradex Inc.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 */
20
21#ifndef __TEGRA20_AC97_H__
22#define __TEGRA20_AC97_H__
23
24#include "tegra_pcm.h"
25
26#define TEGRA20_AC97_CTRL 0x00
27#define TEGRA20_AC97_CMD 0x04
28#define TEGRA20_AC97_STATUS1 0x08
29/* ... */
30#define TEGRA20_AC97_FIFO1_SCR 0x1c
31/* ... */
32#define TEGRA20_AC97_FIFO_TX1 0x40
33#define TEGRA20_AC97_FIFO_RX1 0x80
34
35/* TEGRA20_AC97_CTRL */
36#define TEGRA20_AC97_CTRL_STM2_EN (1 << 16)
37#define TEGRA20_AC97_CTRL_DOUBLE_SAMPLING_EN (1 << 11)
38#define TEGRA20_AC97_CTRL_IO_CNTRL_EN (1 << 10)
39#define TEGRA20_AC97_CTRL_HSET_DAC_EN (1 << 9)
40#define TEGRA20_AC97_CTRL_LINE2_DAC_EN (1 << 8)
41#define TEGRA20_AC97_CTRL_PCM_LFE_EN (1 << 7)
42#define TEGRA20_AC97_CTRL_PCM_SUR_EN (1 << 6)
43#define TEGRA20_AC97_CTRL_PCM_CEN_DAC_EN (1 << 5)
44#define TEGRA20_AC97_CTRL_LINE1_DAC_EN (1 << 4)
45#define TEGRA20_AC97_CTRL_PCM_DAC_EN (1 << 3)
46#define TEGRA20_AC97_CTRL_COLD_RESET (1 << 2)
47#define TEGRA20_AC97_CTRL_WARM_RESET (1 << 1)
48#define TEGRA20_AC97_CTRL_STM_EN (1 << 0)
49
50/* TEGRA20_AC97_CMD */
51#define TEGRA20_AC97_CMD_CMD_ADDR_SHIFT 24
52#define TEGRA20_AC97_CMD_CMD_ADDR_MASK (0xff << TEGRA20_AC97_CMD_CMD_ADDR_SHIFT)
53#define TEGRA20_AC97_CMD_CMD_DATA_SHIFT 8
54#define TEGRA20_AC97_CMD_CMD_DATA_MASK (0xffff << TEGRA20_AC97_CMD_CMD_DATA_SHIFT)
55#define TEGRA20_AC97_CMD_CMD_ID_SHIFT 2
56#define TEGRA20_AC97_CMD_CMD_ID_MASK (0x3 << TEGRA20_AC97_CMD_CMD_ID_SHIFT)
57#define TEGRA20_AC97_CMD_BUSY (1 << 0)
58
59/* TEGRA20_AC97_STATUS1 */
60#define TEGRA20_AC97_STATUS1_STA_ADDR1_SHIFT 24
61#define TEGRA20_AC97_STATUS1_STA_ADDR1_MASK (0xff << TEGRA20_AC97_STATUS1_STA_ADDR1_SHIFT)
62#define TEGRA20_AC97_STATUS1_STA_DATA1_SHIFT 8
63#define TEGRA20_AC97_STATUS1_STA_DATA1_MASK (0xffff << TEGRA20_AC97_STATUS1_STA_DATA1_SHIFT)
64#define TEGRA20_AC97_STATUS1_STA_VALID1 (1 << 2)
65#define TEGRA20_AC97_STATUS1_STANDBY1 (1 << 1)
66#define TEGRA20_AC97_STATUS1_CODEC1_RDY (1 << 0)
67
68/* TEGRA20_AC97_FIFO1_SCR */
69#define TEGRA20_AC97_FIFO_SCR_REC_MT_CNT_SHIFT 27
70#define TEGRA20_AC97_FIFO_SCR_REC_MT_CNT_MASK (0x1f << TEGRA20_AC97_FIFO_SCR_REC_MT_CNT_SHIFT)
71#define TEGRA20_AC97_FIFO_SCR_PB_MT_CNT_SHIFT 22
72#define TEGRA20_AC97_FIFO_SCR_PB_MT_CNT_MASK (0x1f << TEGRA20_AC97_FIFO_SCR_PB_MT_CNT_SHIFT)
73#define TEGRA20_AC97_FIFO_SCR_REC_OVERRUN_INT_STA (1 << 19)
74#define TEGRA20_AC97_FIFO_SCR_PB_UNDERRUN_INT_STA (1 << 18)
75#define TEGRA20_AC97_FIFO_SCR_REC_FORCE_MT (1 << 17)
76#define TEGRA20_AC97_FIFO_SCR_PB_FORCE_MT (1 << 16)
77#define TEGRA20_AC97_FIFO_SCR_REC_FULL_EN (1 << 15)
78#define TEGRA20_AC97_FIFO_SCR_REC_3QRT_FULL_EN (1 << 14)
79#define TEGRA20_AC97_FIFO_SCR_REC_QRT_FULL_EN (1 << 13)
80#define TEGRA20_AC97_FIFO_SCR_REC_EMPTY_EN (1 << 12)
81#define TEGRA20_AC97_FIFO_SCR_PB_NOT_FULL_EN (1 << 11)
82#define TEGRA20_AC97_FIFO_SCR_PB_QRT_MT_EN (1 << 10)
83#define TEGRA20_AC97_FIFO_SCR_PB_3QRT_MT_EN (1 << 9)
84#define TEGRA20_AC97_FIFO_SCR_PB_EMPTY_MT_EN (1 << 8)
85
86struct tegra20_ac97 {
87 struct clk *clk_ac97;
88 struct tegra_pcm_dma_params capture_dma_data;
89 struct tegra_pcm_dma_params playback_dma_data;
90 struct regmap *regmap;
91 int reset_gpio;
92 int sync_gpio;
93 struct tegra_asoc_utils_data util_data;
94};
95#endif /* __TEGRA20_AC97_H__ */
diff --git a/sound/soc/tegra/tegra20_das.c b/sound/soc/tegra/tegra20_das.c
index 654318483877..e72392927bd2 100644
--- a/sound/soc/tegra/tegra20_das.c
+++ b/sound/soc/tegra/tegra20_das.c
@@ -191,6 +191,19 @@ static int tegra20_das_probe(struct platform_device *pdev)
191 goto err; 191 goto err;
192 } 192 }
193 193
194 ret = tegra20_das_connect_dap_to_dac(TEGRA20_DAS_DAP_ID_3,
195 TEGRA20_DAS_DAP_SEL_DAC3);
196 if (ret) {
197 dev_err(&pdev->dev, "Can't set up DAS DAP connection\n");
198 goto err;
199 }
200 ret = tegra20_das_connect_dac_to_dap(TEGRA20_DAS_DAC_ID_3,
201 TEGRA20_DAS_DAC_SEL_DAP3);
202 if (ret) {
203 dev_err(&pdev->dev, "Can't set up DAS DAC connection\n");
204 goto err;
205 }
206
194 platform_set_drvdata(pdev, das); 207 platform_set_drvdata(pdev, das);
195 208
196 return 0; 209 return 0;
diff --git a/sound/soc/tegra/tegra30_ahub.c b/sound/soc/tegra/tegra30_ahub.c
index f354dc390a0b..dd146f10fef2 100644
--- a/sound/soc/tegra/tegra30_ahub.c
+++ b/sound/soc/tegra/tegra30_ahub.c
@@ -580,7 +580,7 @@ err_clk_put_apbif:
580 clk_put(ahub->clk_apbif); 580 clk_put(ahub->clk_apbif);
581err_clk_put_d_audio: 581err_clk_put_d_audio:
582 clk_put(ahub->clk_d_audio); 582 clk_put(ahub->clk_d_audio);
583 ahub = 0; 583 ahub = NULL;
584err: 584err:
585 return ret; 585 return ret;
586} 586}
@@ -597,7 +597,7 @@ static int tegra30_ahub_remove(struct platform_device *pdev)
597 clk_put(ahub->clk_apbif); 597 clk_put(ahub->clk_apbif);
598 clk_put(ahub->clk_d_audio); 598 clk_put(ahub->clk_d_audio);
599 599
600 ahub = 0; 600 ahub = NULL;
601 601
602 return 0; 602 return 0;
603} 603}
diff --git a/sound/soc/tegra/tegra30_i2s.c b/sound/soc/tegra/tegra30_i2s.c
index 27e91dd0b91c..f4e1ce82750a 100644
--- a/sound/soc/tegra/tegra30_i2s.c
+++ b/sound/soc/tegra/tegra30_i2s.c
@@ -71,7 +71,7 @@ static int tegra30_i2s_runtime_resume(struct device *dev)
71 return 0; 71 return 0;
72} 72}
73 73
74int tegra30_i2s_startup(struct snd_pcm_substream *substream, 74static int tegra30_i2s_startup(struct snd_pcm_substream *substream,
75 struct snd_soc_dai *dai) 75 struct snd_soc_dai *dai)
76{ 76{
77 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); 77 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
@@ -98,7 +98,7 @@ int tegra30_i2s_startup(struct snd_pcm_substream *substream,
98 return ret; 98 return ret;
99} 99}
100 100
101void tegra30_i2s_shutdown(struct snd_pcm_substream *substream, 101static void tegra30_i2s_shutdown(struct snd_pcm_substream *substream,
102 struct snd_soc_dai *dai) 102 struct snd_soc_dai *dai)
103{ 103{
104 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); 104 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c
index 6872c77a1196..ba419f86384d 100644
--- a/sound/soc/tegra/tegra_asoc_utils.c
+++ b/sound/soc/tegra/tegra_asoc_utils.c
@@ -112,6 +112,59 @@ int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate,
112} 112}
113EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate); 113EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate);
114 114
115int tegra_asoc_utils_set_ac97_rate(struct tegra_asoc_utils_data *data)
116{
117 const int pll_rate = 73728000;
118 const int ac97_rate = 24576000;
119 int err;
120
121 clk_disable_unprepare(data->clk_cdev1);
122 clk_disable_unprepare(data->clk_pll_a_out0);
123 clk_disable_unprepare(data->clk_pll_a);
124
125 /*
126 * AC97 rate is fixed at 24.576MHz and is used for both the host
127 * controller and the external codec
128 */
129 err = clk_set_rate(data->clk_pll_a, pll_rate);
130 if (err) {
131 dev_err(data->dev, "Can't set pll_a rate: %d\n", err);
132 return err;
133 }
134
135 err = clk_set_rate(data->clk_pll_a_out0, ac97_rate);
136 if (err) {
137 dev_err(data->dev, "Can't set pll_a_out0 rate: %d\n", err);
138 return err;
139 }
140
141 /* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */
142
143 err = clk_prepare_enable(data->clk_pll_a);
144 if (err) {
145 dev_err(data->dev, "Can't enable pll_a: %d\n", err);
146 return err;
147 }
148
149 err = clk_prepare_enable(data->clk_pll_a_out0);
150 if (err) {
151 dev_err(data->dev, "Can't enable pll_a_out0: %d\n", err);
152 return err;
153 }
154
155 err = clk_prepare_enable(data->clk_cdev1);
156 if (err) {
157 dev_err(data->dev, "Can't enable cdev1: %d\n", err);
158 return err;
159 }
160
161 data->set_baseclock = pll_rate;
162 data->set_mclk = ac97_rate;
163
164 return 0;
165}
166EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_ac97_rate);
167
115int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data, 168int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data,
116 struct device *dev) 169 struct device *dev)
117{ 170{
diff --git a/sound/soc/tegra/tegra_asoc_utils.h b/sound/soc/tegra/tegra_asoc_utils.h
index 44db1dbb8f21..974c9f8830f9 100644
--- a/sound/soc/tegra/tegra_asoc_utils.h
+++ b/sound/soc/tegra/tegra_asoc_utils.h
@@ -43,6 +43,7 @@ struct tegra_asoc_utils_data {
43 43
44int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate, 44int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate,
45 int mclk); 45 int mclk);
46int tegra_asoc_utils_set_ac97_rate(struct tegra_asoc_utils_data *data);
46int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data, 47int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data,
47 struct device *dev); 48 struct device *dev);
48void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data); 49void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data);
diff --git a/sound/soc/tegra/tegra_wm9712.c b/sound/soc/tegra/tegra_wm9712.c
new file mode 100644
index 000000000000..68d42403d9b5
--- /dev/null
+++ b/sound/soc/tegra/tegra_wm9712.c
@@ -0,0 +1,176 @@
1/*
2 * tegra20_wm9712.c - Tegra machine ASoC driver for boards using WM9712 codec.
3 *
4 * Copyright 2012 Lucas Stach <dev@lynxeye.de>
5 *
6 * Partly based on code copyright/by:
7 * Copyright 2011,2012 Toradex Inc.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23#include <linux/gpio.h>
24#include <linux/of_gpio.h>
25
26#include <sound/core.h>
27#include <sound/jack.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31
32#define DRV_NAME "tegra-snd-wm9712"
33
34struct tegra_wm9712 {
35 struct platform_device *codec;
36};
37
38static const struct snd_soc_dapm_widget tegra_wm9712_dapm_widgets[] = {
39 SND_SOC_DAPM_HP("Headphone", NULL),
40 SND_SOC_DAPM_LINE("LineIn", NULL),
41 SND_SOC_DAPM_MIC("Mic", NULL),
42};
43
44static int tegra_wm9712_init(struct snd_soc_pcm_runtime *rtd)
45{
46 struct snd_soc_dai *codec_dai = rtd->codec_dai;
47 struct snd_soc_codec *codec = codec_dai->codec;
48 struct snd_soc_dapm_context *dapm = &codec->dapm;
49
50 snd_soc_dapm_force_enable_pin(dapm, "Mic Bias");
51
52 return snd_soc_dapm_sync(dapm);
53}
54
55static struct snd_soc_dai_link tegra_wm9712_dai = {
56 .name = "AC97 HiFi",
57 .stream_name = "AC97 HiFi",
58 .cpu_dai_name = "tegra-ac97-pcm",
59 .codec_dai_name = "wm9712-hifi",
60 .codec_name = "wm9712-codec",
61 .init = tegra_wm9712_init,
62};
63
64static struct snd_soc_card snd_soc_tegra_wm9712 = {
65 .name = "tegra-wm9712",
66 .owner = THIS_MODULE,
67 .dai_link = &tegra_wm9712_dai,
68 .num_links = 1,
69
70 .dapm_widgets = tegra_wm9712_dapm_widgets,
71 .num_dapm_widgets = ARRAY_SIZE(tegra_wm9712_dapm_widgets),
72 .fully_routed = true,
73};
74
75static int tegra_wm9712_driver_probe(struct platform_device *pdev)
76{
77 struct device_node *np = pdev->dev.of_node;
78 struct snd_soc_card *card = &snd_soc_tegra_wm9712;
79 struct tegra_wm9712 *machine;
80 int ret;
81
82 if (!pdev->dev.of_node) {
83 dev_err(&pdev->dev, "No platform data supplied\n");
84 return -EINVAL;
85 }
86
87 machine = devm_kzalloc(&pdev->dev, sizeof(struct tegra_wm9712),
88 GFP_KERNEL);
89 if (!machine) {
90 dev_err(&pdev->dev, "Can't allocate tegra_wm9712 struct\n");
91 return -ENOMEM;
92 }
93
94 card->dev = &pdev->dev;
95 platform_set_drvdata(pdev, card);
96 snd_soc_card_set_drvdata(card, machine);
97
98 machine->codec = platform_device_alloc("wm9712-codec", -1);
99 if (!machine->codec) {
100 dev_err(&pdev->dev, "Can't allocate wm9712 platform device\n");
101 return -ENOMEM;
102 }
103
104 ret = platform_device_add(machine->codec);
105 if (ret)
106 goto codec_put;
107
108 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
109 if (ret)
110 goto codec_unregister;
111
112 ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
113 if (ret)
114 goto codec_unregister;
115
116 tegra_wm9712_dai.cpu_of_node = of_parse_phandle(np,
117 "nvidia,ac97-controller", 0);
118 if (!tegra_wm9712_dai.cpu_of_node) {
119 dev_err(&pdev->dev,
120 "Property 'nvidia,ac97-controller' missing or invalid\n");
121 ret = -EINVAL;
122 goto codec_unregister;
123 }
124
125 tegra_wm9712_dai.platform_of_node = tegra_wm9712_dai.cpu_of_node;
126
127 ret = snd_soc_register_card(card);
128 if (ret) {
129 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
130 ret);
131 goto codec_unregister;
132 }
133
134 return 0;
135
136codec_unregister:
137 platform_device_del(machine->codec);
138codec_put:
139 platform_device_put(machine->codec);
140 return ret;
141}
142
143static int tegra_wm9712_driver_remove(struct platform_device *pdev)
144{
145 struct snd_soc_card *card = platform_get_drvdata(pdev);
146 struct tegra_wm9712 *machine = snd_soc_card_get_drvdata(card);
147
148 snd_soc_unregister_card(card);
149
150 platform_device_unregister(machine->codec);
151
152 return 0;
153}
154
155static const struct of_device_id tegra_wm9712_of_match[] = {
156 { .compatible = "nvidia,tegra-audio-wm9712", },
157 {},
158};
159
160static struct platform_driver tegra_wm9712_driver = {
161 .driver = {
162 .name = DRV_NAME,
163 .owner = THIS_MODULE,
164 .pm = &snd_soc_pm_ops,
165 .of_match_table = tegra_wm9712_of_match,
166 },
167 .probe = tegra_wm9712_driver_probe,
168 .remove = tegra_wm9712_driver_remove,
169};
170module_platform_driver(tegra_wm9712_driver);
171
172MODULE_AUTHOR("Lucas Stach");
173MODULE_DESCRIPTION("Tegra+WM9712 machine ASoC driver");
174MODULE_LICENSE("GPL v2");
175MODULE_ALIAS("platform:" DRV_NAME);
176MODULE_DEVICE_TABLE(of, tegra_wm9712_of_match);
diff --git a/sound/soc/ux500/mop500.c b/sound/soc/ux500/mop500.c
index ae6990738783..204b899c2311 100644
--- a/sound/soc/ux500/mop500.c
+++ b/sound/soc/ux500/mop500.c
@@ -24,7 +24,7 @@
24#include "ux500_pcm.h" 24#include "ux500_pcm.h"
25#include "ux500_msp_dai.h" 25#include "ux500_msp_dai.h"
26 26
27#include <mop500_ab8500.h> 27#include "mop500_ab8500.h"
28 28
29/* Define the whole MOP500 soundcard, linking platform to the codec-drivers */ 29/* Define the whole MOP500 soundcard, linking platform to the codec-drivers */
30struct snd_soc_dai_link mop500_dai_links[] = { 30struct snd_soc_dai_link mop500_dai_links[] = {
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index c828f8189c25..e4d6dbb0342d 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -48,10 +48,10 @@ MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
48 "{Native Instruments, Audio 8 DJ}," 48 "{Native Instruments, Audio 8 DJ},"
49 "{Native Instruments, Traktor Audio 2}," 49 "{Native Instruments, Traktor Audio 2},"
50 "{Native Instruments, Session I/O}," 50 "{Native Instruments, Session I/O},"
51 "{Native Instruments, GuitarRig mobile}" 51 "{Native Instruments, GuitarRig mobile},"
52 "{Native Instruments, Traktor Kontrol X1}" 52 "{Native Instruments, Traktor Kontrol X1},"
53 "{Native Instruments, Traktor Kontrol S4}" 53 "{Native Instruments, Traktor Kontrol S4},"
54 "{Native Instruments, Maschine Controller}"); 54 "{Native Instruments, Maschine Controller}}");
55 55
56static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ 56static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
57static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ 57static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
diff --git a/sound/usb/card.c b/sound/usb/card.c
index ccf95cfe186f..803953a9bff3 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -646,7 +646,7 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
646 as->substream[0].need_setup_ep = 646 as->substream[0].need_setup_ep =
647 as->substream[1].need_setup_ep = true; 647 as->substream[1].need_setup_ep = true;
648 } 648 }
649 } 649 }
650 } else { 650 } else {
651 /* 651 /*
652 * otherwise we keep the rest of the system in the dark 652 * otherwise we keep the rest of the system in the dark
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index e90daf8cdaa8..638e7f738018 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -807,6 +807,7 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval,
807{ 807{
808 switch (cval->mixer->chip->usb_id) { 808 switch (cval->mixer->chip->usb_id) {
809 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ 809 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
810 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */
810 if (strcmp(kctl->id.name, "Effect Duration") == 0) { 811 if (strcmp(kctl->id.name, "Effect Duration") == 0) {
811 cval->min = 0x0000; 812 cval->min = 0x0000;
812 cval->max = 0xffff; 813 cval->max = 0xffff;
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index 0e2ed3d05c45..cc2dd1f0decb 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -380,6 +380,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
380 .selector_map = c400_selectors, 380 .selector_map = c400_selectors,
381 }, 381 },
382 { 382 {
383 .id = USB_ID(0x0763, 0x2031),
384 .selector_map = c400_selectors,
385 },
386 {
383 .id = USB_ID(0x08bb, 0x2702), 387 .id = USB_ID(0x08bb, 0x2702),
384 .map = linex_map, 388 .map = linex_map,
385 .ignore_ctl_error = 1, 389 .ignore_ctl_error = 1,
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 15520de1df56..497d2741d119 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -637,7 +637,7 @@ static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer,
637} 637}
638 638
639/* M-Audio FastTrack Ultra quirks */ 639/* M-Audio FastTrack Ultra quirks */
640/* FTU Effect switch (also used by C400) */ 640/* FTU Effect switch (also used by C400/C600) */
641struct snd_ftu_eff_switch_priv_val { 641struct snd_ftu_eff_switch_priv_val {
642 struct usb_mixer_interface *mixer; 642 struct usb_mixer_interface *mixer;
643 int cached_value; 643 int cached_value;
@@ -1029,32 +1029,45 @@ void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
1029 } 1029 }
1030} 1030}
1031 1031
1032/* M-Audio Fast Track C400 */ 1032/* M-Audio Fast Track C400/C600 */
1033/* C400 volume controls, this control needs a volume quirk, see mixer.c */ 1033/* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */
1034static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer) 1034static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
1035{ 1035{
1036 char name[64]; 1036 char name[64];
1037 unsigned int cmask, offset; 1037 unsigned int cmask, offset;
1038 int out, chan, err; 1038 int out, chan, err;
1039 int num_outs = 0;
1040 int num_ins = 0;
1039 1041
1040 const unsigned int id = 0x40; 1042 const unsigned int id = 0x40;
1041 const int val_type = USB_MIXER_S16; 1043 const int val_type = USB_MIXER_S16;
1042 const int control = 1; 1044 const int control = 1;
1043 1045
1044 for (chan = 0; chan < 10; chan++) { 1046 switch (mixer->chip->usb_id) {
1045 for (out = 0; out < 6; out++) { 1047 case USB_ID(0x0763, 0x2030):
1046 if (chan < 6) { 1048 num_outs = 6;
1049 num_ins = 4;
1050 break;
1051 case USB_ID(0x0763, 0x2031):
1052 num_outs = 8;
1053 num_ins = 6;
1054 break;
1055 }
1056
1057 for (chan = 0; chan < num_outs + num_ins; chan++) {
1058 for (out = 0; out < num_outs; out++) {
1059 if (chan < num_outs) {
1047 snprintf(name, sizeof(name), 1060 snprintf(name, sizeof(name),
1048 "PCM%d-Out%d Playback Volume", 1061 "PCM%d-Out%d Playback Volume",
1049 chan + 1, out + 1); 1062 chan + 1, out + 1);
1050 } else { 1063 } else {
1051 snprintf(name, sizeof(name), 1064 snprintf(name, sizeof(name),
1052 "In%d-Out%d Playback Volume", 1065 "In%d-Out%d Playback Volume",
1053 chan - 5, out + 1); 1066 chan - num_outs + 1, out + 1);
1054 } 1067 }
1055 1068
1056 cmask = (out == 0) ? 0 : 1 << (out - 1); 1069 cmask = (out == 0) ? 0 : 1 << (out - 1);
1057 offset = chan * 6; 1070 offset = chan * num_outs;
1058 err = snd_create_std_mono_ctl_offset(mixer, id, control, 1071 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1059 cmask, val_type, offset, name, 1072 cmask, val_type, offset, name,
1060 &snd_usb_mixer_vol_tlv); 1073 &snd_usb_mixer_vol_tlv);
@@ -1110,20 +1123,33 @@ static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
1110 char name[64]; 1123 char name[64];
1111 unsigned int cmask; 1124 unsigned int cmask;
1112 int chan, err; 1125 int chan, err;
1126 int num_outs = 0;
1127 int num_ins = 0;
1113 1128
1114 const unsigned int id = 0x42; 1129 const unsigned int id = 0x42;
1115 const int val_type = USB_MIXER_S16; 1130 const int val_type = USB_MIXER_S16;
1116 const int control = 1; 1131 const int control = 1;
1117 1132
1118 for (chan = 0; chan < 10; chan++) { 1133 switch (mixer->chip->usb_id) {
1119 if (chan < 6) { 1134 case USB_ID(0x0763, 0x2030):
1135 num_outs = 6;
1136 num_ins = 4;
1137 break;
1138 case USB_ID(0x0763, 0x2031):
1139 num_outs = 8;
1140 num_ins = 6;
1141 break;
1142 }
1143
1144 for (chan = 0; chan < num_outs + num_ins; chan++) {
1145 if (chan < num_outs) {
1120 snprintf(name, sizeof(name), 1146 snprintf(name, sizeof(name),
1121 "Effect Send DOut%d", 1147 "Effect Send DOut%d",
1122 chan + 1); 1148 chan + 1);
1123 } else { 1149 } else {
1124 snprintf(name, sizeof(name), 1150 snprintf(name, sizeof(name),
1125 "Effect Send AIn%d", 1151 "Effect Send AIn%d",
1126 chan - 5); 1152 chan - num_outs + 1);
1127 } 1153 }
1128 1154
1129 cmask = (chan == 0) ? 0 : 1 << (chan - 1); 1155 cmask = (chan == 0) ? 0 : 1 << (chan - 1);
@@ -1142,20 +1168,33 @@ static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer
1142 char name[64]; 1168 char name[64];
1143 unsigned int cmask; 1169 unsigned int cmask;
1144 int chan, err; 1170 int chan, err;
1171 int num_outs = 0;
1172 int offset = 0;
1145 1173
1146 const unsigned int id = 0x40; 1174 const unsigned int id = 0x40;
1147 const int val_type = USB_MIXER_S16; 1175 const int val_type = USB_MIXER_S16;
1148 const int control = 1; 1176 const int control = 1;
1149 const int chan_id[6] = { 0, 7, 2, 9, 4, 0xb };
1150 const unsigned int offset = 0x3c;
1151 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1152 1177
1153 for (chan = 0; chan < 6; chan++) { 1178 switch (mixer->chip->usb_id) {
1179 case USB_ID(0x0763, 0x2030):
1180 num_outs = 6;
1181 offset = 0x3c;
1182 /* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */
1183 break;
1184 case USB_ID(0x0763, 0x2031):
1185 num_outs = 8;
1186 offset = 0x70;
1187 /* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */
1188 break;
1189 }
1190
1191 for (chan = 0; chan < num_outs; chan++) {
1154 snprintf(name, sizeof(name), 1192 snprintf(name, sizeof(name),
1155 "Effect Return %d", 1193 "Effect Return %d",
1156 chan + 1); 1194 chan + 1);
1157 1195
1158 cmask = (chan_id[chan] == 0) ? 0 : 1 << (chan_id[chan] - 1); 1196 cmask = (chan == 0) ? 0 :
1197 1 << (chan + (chan % 2) * num_outs - 1);
1159 err = snd_create_std_mono_ctl_offset(mixer, id, control, 1198 err = snd_create_std_mono_ctl_offset(mixer, id, control,
1160 cmask, val_type, offset, name, 1199 cmask, val_type, offset, name,
1161 &snd_usb_mixer_vol_tlv); 1200 &snd_usb_mixer_vol_tlv);
@@ -1299,6 +1338,7 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1299 break; 1338 break;
1300 1339
1301 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ 1340 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1341 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1302 err = snd_c400_create_mixer(mixer); 1342 err = snd_c400_create_mixer(mixer);
1303 break; 1343 break;
1304 1344
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index d82e378d37cb..f94397b42aa5 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -59,7 +59,12 @@ snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
59 59
60 /* Approximation based on number of samples per USB frame (ms), 60 /* Approximation based on number of samples per USB frame (ms),
61 some truncation for 44.1 but the estimate is good enough */ 61 some truncation for 44.1 but the estimate is good enough */
62 est_delay = subs->last_delay - (frame_diff * rate / 1000); 62 est_delay = frame_diff * rate / 1000;
63 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK)
64 est_delay = subs->last_delay - est_delay;
65 else
66 est_delay = subs->last_delay + est_delay;
67
63 if (est_delay < 0) 68 if (est_delay < 0)
64 est_delay = 0; 69 est_delay = 0;
65 return est_delay; 70 return est_delay;
@@ -78,8 +83,7 @@ static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream
78 return SNDRV_PCM_POS_XRUN; 83 return SNDRV_PCM_POS_XRUN;
79 spin_lock(&subs->lock); 84 spin_lock(&subs->lock);
80 hwptr_done = subs->hwptr_done; 85 hwptr_done = subs->hwptr_done;
81 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 86 substream->runtime->delay = snd_usb_pcm_delay(subs,
82 substream->runtime->delay = snd_usb_pcm_delay(subs,
83 substream->runtime->rate); 87 substream->runtime->rate);
84 spin_unlock(&subs->lock); 88 spin_unlock(&subs->lock);
85 return hwptr_done / (substream->runtime->frame_bits >> 3); 89 return hwptr_done / (substream->runtime->frame_bits >> 3);
@@ -363,6 +367,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
363 367
364 switch (subs->stream->chip->usb_id) { 368 switch (subs->stream->chip->usb_id) {
365 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ 369 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
370 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */
366 if (is_playback) { 371 if (is_playback) {
367 implicit_fb = 1; 372 implicit_fb = 1;
368 ep = 0x81; 373 ep = 0x81;
@@ -1157,6 +1162,10 @@ static void retire_capture_urb(struct snd_usb_substream *subs,
1157 int i, period_elapsed = 0; 1162 int i, period_elapsed = 0;
1158 unsigned long flags; 1163 unsigned long flags;
1159 unsigned char *cp; 1164 unsigned char *cp;
1165 int current_frame_number;
1166
1167 /* read frame number here, update pointer in critical section */
1168 current_frame_number = usb_get_current_frame_number(subs->dev);
1160 1169
1161 stride = runtime->frame_bits >> 3; 1170 stride = runtime->frame_bits >> 3;
1162 1171
@@ -1171,9 +1180,7 @@ static void retire_capture_urb(struct snd_usb_substream *subs,
1171 if (!subs->txfr_quirk) 1180 if (!subs->txfr_quirk)
1172 bytes = frames * stride; 1181 bytes = frames * stride;
1173 if (bytes % (runtime->sample_bits >> 3) != 0) { 1182 if (bytes % (runtime->sample_bits >> 3) != 0) {
1174#ifdef CONFIG_SND_DEBUG_VERBOSE
1175 int oldbytes = bytes; 1183 int oldbytes = bytes;
1176#endif
1177 bytes = frames * stride; 1184 bytes = frames * stride;
1178 snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", 1185 snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
1179 oldbytes, bytes); 1186 oldbytes, bytes);
@@ -1190,6 +1197,15 @@ static void retire_capture_urb(struct snd_usb_substream *subs,
1190 subs->transfer_done -= runtime->period_size; 1197 subs->transfer_done -= runtime->period_size;
1191 period_elapsed = 1; 1198 period_elapsed = 1;
1192 } 1199 }
1200 /* capture delay is by construction limited to one URB,
1201 * reset delays here
1202 */
1203 runtime->delay = subs->last_delay = 0;
1204
1205 /* realign last_frame_number */
1206 subs->last_frame_number = current_frame_number;
1207 subs->last_frame_number &= 0xFF; /* keep 8 LSBs */
1208
1193 spin_unlock_irqrestore(&subs->lock, flags); 1209 spin_unlock_irqrestore(&subs->lock, flags);
1194 /* copy a data chunk */ 1210 /* copy a data chunk */
1195 if (oldptr + bytes > runtime->buffer_size * stride) { 1211 if (oldptr + bytes > runtime->buffer_size * stride) {
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index 64d25a7a4d59..c39f898b15d2 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -1750,7 +1750,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1750 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 1750 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1751 /* .vendor_name = "Roland", */ 1751 /* .vendor_name = "Roland", */
1752 /* .product_name = "A-PRO", */ 1752 /* .product_name = "A-PRO", */
1753 .ifnum = 1, 1753 .ifnum = 0,
1754 .type = QUIRK_MIDI_FIXED_ENDPOINT, 1754 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1755 .data = & (const struct snd_usb_midi_endpoint_info) { 1755 .data = & (const struct snd_usb_midi_endpoint_info) {
1756 .out_cables = 0x0003, 1756 .out_cables = 0x0003,
@@ -2326,6 +2326,77 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2326 } 2326 }
2327}, 2327},
2328{ 2328{
2329 USB_DEVICE_VENDOR_SPEC(0x0763, 0x2031),
2330 .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
2331 /* .vendor_name = "M-Audio", */
2332 /* .product_name = "Fast Track C600", */
2333 .ifnum = QUIRK_ANY_INTERFACE,
2334 .type = QUIRK_COMPOSITE,
2335 .data = &(const struct snd_usb_audio_quirk[]) {
2336 {
2337 .ifnum = 1,
2338 .type = QUIRK_AUDIO_STANDARD_MIXER,
2339 },
2340 /* Playback */
2341 {
2342 .ifnum = 2,
2343 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
2344 .data = &(const struct audioformat) {
2345 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
2346 .channels = 8,
2347 .iface = 2,
2348 .altsetting = 1,
2349 .altset_idx = 1,
2350 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2351 .endpoint = 0x01,
2352 .ep_attr = 0x09,
2353 .rates = SNDRV_PCM_RATE_44100 |
2354 SNDRV_PCM_RATE_48000 |
2355 SNDRV_PCM_RATE_88200 |
2356 SNDRV_PCM_RATE_96000,
2357 .rate_min = 44100,
2358 .rate_max = 96000,
2359 .nr_rates = 4,
2360 .rate_table = (unsigned int[]) {
2361 44100, 48000, 88200, 96000
2362 },
2363 .clock = 0x80,
2364 }
2365 },
2366 /* Capture */
2367 {
2368 .ifnum = 3,
2369 .type = QUIRK_AUDIO_FIXED_ENDPOINT,
2370 .data = &(const struct audioformat) {
2371 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
2372 .channels = 6,
2373 .iface = 3,
2374 .altsetting = 1,
2375 .altset_idx = 1,
2376 .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
2377 .endpoint = 0x81,
2378 .ep_attr = 0x05,
2379 .rates = SNDRV_PCM_RATE_44100 |
2380 SNDRV_PCM_RATE_48000 |
2381 SNDRV_PCM_RATE_88200 |
2382 SNDRV_PCM_RATE_96000,
2383 .rate_min = 44100,
2384 .rate_max = 96000,
2385 .nr_rates = 4,
2386 .rate_table = (unsigned int[]) {
2387 44100, 48000, 88200, 96000
2388 },
2389 .clock = 0x80,
2390 }
2391 },
2392 /* MIDI */
2393 {
2394 .ifnum = -1 /* Interface = 4 */
2395 }
2396 }
2397 }
2398},
2399{
2329 USB_DEVICE_VENDOR_SPEC(0x0763, 0x2080), 2400 USB_DEVICE_VENDOR_SPEC(0x0763, 0x2080),
2330 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 2401 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2331 /* .vendor_name = "M-Audio", */ 2402 /* .vendor_name = "M-Audio", */
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 2c971858d6b7..5325a3869bb7 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -533,7 +533,7 @@ static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
533{ 533{
534 struct usb_host_config *config = dev->actconfig; 534 struct usb_host_config *config = dev->actconfig;
535 int err; 535 int err;
536 u8 bootresponse[12]; 536 u8 bootresponse[0x12];
537 int fwsize; 537 int fwsize;
538 int count; 538 int count;
539 539
@@ -863,13 +863,14 @@ void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
863 ep->skip_packets = 4; 863 ep->skip_packets = 4;
864 864
865 /* 865 /*
866 * M-Audio Fast Track C400 - when packets are not skipped, real world 866 * M-Audio Fast Track C400/C600 - when packets are not skipped, real
867 * latency varies by approx. +/- 50 frames (at 96KHz) each time the 867 * world latency varies by approx. +/- 50 frames (at 96KHz) each time
868 * stream is (re)started. When skipping packets 16 at endpoint start 868 * the stream is (re)started. When skipping packets 16 at endpoint
869 * up, the real world latency is stable within +/- 1 frame (also 869 * start up, the real world latency is stable within +/- 1 frame (also
870 * across power cycles). 870 * across power cycles).
871 */ 871 */
872 if (ep->chip->usb_id == USB_ID(0x0763, 0x2030) && 872 if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
873 ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
873 ep->type == SND_USB_ENDPOINT_TYPE_DATA) 874 ep->type == SND_USB_ENDPOINT_TYPE_DATA)
874 ep->skip_packets = 16; 875 ep->skip_packets = 16;
875} 876}