aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-12-28 14:41:32 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-12-28 14:41:32 -0500
commitcb10ea549fdc0ab2dd8988adab5bf40b4fa642f3 (patch)
tree6bc11e0af9f0639a5eedd055401086c8c771f21e /sound/pci
parent81d6e59dabb1ae0c782e9eb7e3d88f699d25b314 (diff)
parent5ce442fe2c9423ec5451222aee6f9b2127bb8311 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6: (367 commits) ALSA: ASoC: fix a typo in omp-pcm.c ASoC: Fix DSP formats in SSM2602 audio codec ASoC: Fix incorrect DSP format in OMAP McBSP DAI and affected drivers ALSA: hda: fix incorrect mixer index values for 92hd83xx ALSA: hda: dinput_mux check ALSA: hda - Add quirk for another HP dv7 ALSA: ASoC - Add missing __devexit annotation to wm8350.c ALSA: ASoc: DaVinci: davinci-evm use dsp_b mode ALSA: ASoC: DaVinci: i2s, evm, pass same value to codec and cpu_dai ALSA: ASoC: tlv320aic3x add dsp_a ALSA: ASoC: DaVinci: document I2S limitations ALSA: ASoC: DaVinci: davinci-i2s clean up ALSA: ASoC: DaVinci: davinci-i2s clean up ALSA: ASoC: DaVinci: davinci-i2s add comments to explain polarity ALSA: ASoC: DaVinci: davinvi-evm, make requests explicit ALSA: ca0106 - disable 44.1kHz capture ALSA: ca0106 - Add missing card->private_data initialization ALSA: ca0106 - Check ac97 availability at PM ALSA: hda - Power up always when no jack detection is available ALSA: hda - Fix unused variable warnings in patch_sigmatel.c ...
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/Kconfig127
-rw-r--r--sound/pci/ac97/ac97_codec.c2
-rw-r--r--sound/pci/ac97/ac97_patch.c7
-rw-r--r--sound/pci/ca0106/ca0106.h30
-rw-r--r--sound/pci/ca0106/ca0106_main.c550
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c263
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c5
-rw-r--r--sound/pci/cs5535audio/Makefile3
-rw-r--r--sound/pci/cs5535audio/cs5535audio.c12
-rw-r--r--sound/pci/cs5535audio/cs5535audio.h39
-rw-r--r--sound/pci/cs5535audio/cs5535audio_olpc.c179
-rw-r--r--sound/pci/cs5535audio/cs5535audio_pcm.c15
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c494
-rw-r--r--sound/pci/emu10k1/emumixer.c46
-rw-r--r--sound/pci/es1968.c2
-rw-r--r--sound/pci/hda/Kconfig188
-rw-r--r--sound/pci/hda/Makefile75
-rw-r--r--sound/pci/hda/hda_beep.c2
-rw-r--r--sound/pci/hda/hda_codec.c781
-rw-r--r--sound/pci/hda/hda_codec.h107
-rw-r--r--sound/pci/hda/hda_eld.c590
-rw-r--r--sound/pci/hda/hda_generic.c21
-rw-r--r--sound/pci/hda/hda_hwdep.c234
-rw-r--r--sound/pci/hda/hda_intel.c348
-rw-r--r--sound/pci/hda/hda_local.h100
-rw-r--r--sound/pci/hda/hda_patch.h22
-rw-r--r--sound/pci/hda/hda_proc.c91
-rw-r--r--sound/pci/hda/patch_analog.c132
-rw-r--r--sound/pci/hda/patch_atihdmi.c40
-rw-r--r--sound/pci/hda/patch_cmedia.c27
-rw-r--r--sound/pci/hda/patch_conexant.c39
-rw-r--r--sound/pci/hda/patch_intelhdmi.c711
-rw-r--r--sound/pci/hda/patch_nvhdmi.c32
-rw-r--r--sound/pci/hda/patch_realtek.c1663
-rw-r--r--sound/pci/hda/patch_si3054.c35
-rw-r--r--sound/pci/hda/patch_sigmatel.c1318
-rw-r--r--sound/pci/hda/patch_via.c171
-rw-r--r--sound/pci/ice1712/ice1724.c23
-rw-r--r--sound/pci/maestro3.c2
-rw-r--r--sound/pci/mixart/mixart.c4
-rw-r--r--sound/pci/mixart/mixart_core.c2
-rw-r--r--sound/pci/oxygen/oxygen.c4
-rw-r--r--sound/pci/pcxhr/Makefile2
-rw-r--r--sound/pci/pcxhr/pcxhr.c558
-rw-r--r--sound/pci/pcxhr/pcxhr.h76
-rw-r--r--sound/pci/pcxhr/pcxhr_core.c293
-rw-r--r--sound/pci/pcxhr/pcxhr_core.h5
-rw-r--r--sound/pci/pcxhr/pcxhr_hwdep.c158
-rw-r--r--sound/pci/pcxhr/pcxhr_mix22.c820
-rw-r--r--sound/pci/pcxhr/pcxhr_mix22.h56
-rw-r--r--sound/pci/pcxhr/pcxhr_mixer.c556
-rw-r--r--sound/pci/riptide/riptide.c4
-rw-r--r--sound/pci/rme9652/hdsp.c4
-rw-r--r--sound/pci/rme9652/hdspm.c4
54 files changed, 7952 insertions, 3120 deletions
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 7003711f4fcc..6e3a1848447c 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -208,7 +208,8 @@ config SND_OXYGEN
208 * AuzenTech X-Meridian 208 * AuzenTech X-Meridian
209 * Bgears b-Enspirer 209 * Bgears b-Enspirer
210 * Club3D Theatron DTS 210 * Club3D Theatron DTS
211 * HT-Omega Claro 211 * HT-Omega Claro (plus)
212 * HT-Omega Claro halo (XT)
212 * Razer Barracuda AC-1 213 * Razer Barracuda AC-1
213 * Sondigo Inferno 214 * Sondigo Inferno
214 215
@@ -497,129 +498,7 @@ config SND_FM801_TEA575X
497 depends on SND_FM801_TEA575X_BOOL 498 depends on SND_FM801_TEA575X_BOOL
498 default SND_FM801 499 default SND_FM801
499 500
500config SND_HDA_INTEL 501source "sound/pci/hda/Kconfig"
501 tristate "Intel HD Audio"
502 select SND_PCM
503 select SND_VMASTER
504 help
505 Say Y here to include support for Intel "High Definition
506 Audio" (Azalia) motherboard devices.
507
508 To compile this driver as a module, choose M here: the module
509 will be called snd-hda-intel.
510
511config SND_HDA_HWDEP
512 bool "Build hwdep interface for HD-audio driver"
513 depends on SND_HDA_INTEL
514 select SND_HWDEP
515 help
516 Say Y here to build a hwdep interface for HD-audio driver.
517 This interface can be used for out-of-band communication
518 with codecs for debugging purposes.
519
520config SND_HDA_INPUT_BEEP
521 bool "Support digital beep via input layer"
522 depends on SND_HDA_INTEL
523 depends on INPUT=y || INPUT=SND_HDA_INTEL
524 help
525 Say Y here to build a digital beep interface for HD-audio
526 driver. This interface is used to generate digital beeps.
527
528config SND_HDA_CODEC_REALTEK
529 bool "Build Realtek HD-audio codec support"
530 depends on SND_HDA_INTEL
531 default y
532 help
533 Say Y here to include Realtek HD-audio codec support in
534 snd-hda-intel driver, such as ALC880.
535
536config SND_HDA_CODEC_ANALOG
537 bool "Build Analog Device HD-audio codec support"
538 depends on SND_HDA_INTEL
539 default y
540 help
541 Say Y here to include Analog Device HD-audio codec support in
542 snd-hda-intel driver, such as AD1986A.
543
544config SND_HDA_CODEC_SIGMATEL
545 bool "Build IDT/Sigmatel HD-audio codec support"
546 depends on SND_HDA_INTEL
547 default y
548 help
549 Say Y here to include IDT (Sigmatel) HD-audio codec support in
550 snd-hda-intel driver, such as STAC9200.
551
552config SND_HDA_CODEC_VIA
553 bool "Build VIA HD-audio codec support"
554 depends on SND_HDA_INTEL
555 default y
556 help
557 Say Y here to include VIA HD-audio codec support in
558 snd-hda-intel driver, such as VT1708.
559
560config SND_HDA_CODEC_ATIHDMI
561 bool "Build ATI HDMI HD-audio codec support"
562 depends on SND_HDA_INTEL
563 default y
564 help
565 Say Y here to include ATI HDMI HD-audio codec support in
566 snd-hda-intel driver, such as ATI RS600 HDMI.
567
568config SND_HDA_CODEC_NVHDMI
569 bool "Build NVIDIA HDMI HD-audio codec support"
570 depends on SND_HDA_INTEL
571 default y
572 help
573 Say Y here to include NVIDIA HDMI HD-audio codec support in
574 snd-hda-intel driver, such as NVIDIA MCP78 HDMI.
575
576config SND_HDA_CODEC_CONEXANT
577 bool "Build Conexant HD-audio codec support"
578 depends on SND_HDA_INTEL
579 default y
580 help
581 Say Y here to include Conexant HD-audio codec support in
582 snd-hda-intel driver, such as CX20549.
583
584config SND_HDA_CODEC_CMEDIA
585 bool "Build C-Media HD-audio codec support"
586 depends on SND_HDA_INTEL
587 default y
588 help
589 Say Y here to include C-Media HD-audio codec support in
590 snd-hda-intel driver, such as CMI9880.
591
592config SND_HDA_CODEC_SI3054
593 bool "Build Silicon Labs 3054 HD-modem codec support"
594 depends on SND_HDA_INTEL
595 default y
596 help
597 Say Y here to include Silicon Labs 3054 HD-modem codec
598 (and compatibles) support in snd-hda-intel driver.
599
600config SND_HDA_GENERIC
601 bool "Enable generic HD-audio codec parser"
602 depends on SND_HDA_INTEL
603 default y
604 help
605 Say Y here to enable the generic HD-audio codec parser
606 in snd-hda-intel driver.
607
608config SND_HDA_POWER_SAVE
609 bool "Aggressive power-saving on HD-audio"
610 depends on SND_HDA_INTEL && EXPERIMENTAL
611 help
612 Say Y here to enable more aggressive power-saving mode on
613 HD-audio driver. The power-saving timeout can be configured
614 via power_save option or over sysfs on-the-fly.
615
616config SND_HDA_POWER_SAVE_DEFAULT
617 int "Default time-out for HD-audio power-save mode"
618 depends on SND_HDA_POWER_SAVE
619 default 0
620 help
621 The default time-out value in seconds for HD-audio automatic
622 power-save mode. 0 means to disable the power-save mode.
623 502
624config SND_HDSP 503config SND_HDSP
625 tristate "RME Hammerfall DSP Audio" 504 tristate "RME Hammerfall DSP Audio"
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index bd510eceff1f..e2b843b4f9d0 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -175,7 +175,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = {
175{ 0x574d4C04, 0xffffffff, "WM9704M,WM9704Q", patch_wolfson04, NULL}, 175{ 0x574d4C04, 0xffffffff, "WM9704M,WM9704Q", patch_wolfson04, NULL},
176{ 0x574d4C05, 0xffffffff, "WM9705,WM9710", patch_wolfson05, NULL}, 176{ 0x574d4C05, 0xffffffff, "WM9705,WM9710", patch_wolfson05, NULL},
177{ 0x574d4C09, 0xffffffff, "WM9709", NULL, NULL}, 177{ 0x574d4C09, 0xffffffff, "WM9709", NULL, NULL},
178{ 0x574d4C12, 0xffffffff, "WM9711,WM9712", patch_wolfson11, NULL}, 178{ 0x574d4C12, 0xffffffff, "WM9711,WM9712,WM9715", patch_wolfson11, NULL},
179{ 0x574d4c13, 0xffffffff, "WM9713,WM9714", patch_wolfson13, NULL, AC97_DEFAULT_POWER_OFF}, 179{ 0x574d4c13, 0xffffffff, "WM9713,WM9714", patch_wolfson13, NULL, AC97_DEFAULT_POWER_OFF},
180{ 0x594d4800, 0xffffffff, "YMF743", patch_yamaha_ymf743, NULL }, 180{ 0x594d4800, 0xffffffff, "YMF743", patch_yamaha_ymf743, NULL },
181{ 0x594d4802, 0xffffffff, "YMF752", NULL, NULL }, 181{ 0x594d4802, 0xffffffff, "YMF752", NULL, NULL },
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 6e831aff1bd0..81bc93e5f1e3 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -2054,8 +2054,9 @@ static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
2054 .get = snd_ac97_ad1888_lohpsel_get, 2054 .get = snd_ac97_ad1888_lohpsel_get,
2055 .put = snd_ac97_ad1888_lohpsel_put 2055 .put = snd_ac97_ad1888_lohpsel_put
2056 }, 2056 },
2057 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, 2, 1, 1), 2057 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1),
2058 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1), 2058 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2,
2059 AC97_AD_HPFD_SHIFT, 1, 1),
2059 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), 2060 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
2060 { 2061 {
2061 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2062 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -2832,6 +2833,8 @@ static int patch_alc655(struct snd_ac97 * ac97)
2832 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */ 2833 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2833 else 2834 else
2834 val |= (1 << 1); /* Pin 47 is spdif input pin */ 2835 val |= (1 << 1); /* Pin 47 is spdif input pin */
2836 /* this seems missing on some hardwares */
2837 ac97->ext_id |= AC97_EI_SPDIF;
2835 } 2838 }
2836 val &= ~(1 << 12); /* vref enable */ 2839 val &= ~(1 << 12); /* vref enable */
2837 snd_ac97_write_cache(ac97, 0x7a, val); 2840 snd_ac97_write_cache(ac97, 0x7a, val);
diff --git a/sound/pci/ca0106/ca0106.h b/sound/pci/ca0106/ca0106.h
index 74175fc80c7f..14b8d9a91aae 100644
--- a/sound/pci/ca0106/ca0106.h
+++ b/sound/pci/ca0106/ca0106.h
@@ -664,10 +664,14 @@ struct snd_ca0106_pcm {
664struct snd_ca0106_details { 664struct snd_ca0106_details {
665 u32 serial; 665 u32 serial;
666 char * name; 666 char * name;
667 int ac97; 667 int ac97; /* ac97 = 0 -> Select MIC, Line in, TAD in, AUX in.
668 int gpio_type; 668 ac97 = 1 -> Default to AC97 in. */
669 int i2c_adc; 669 int gpio_type; /* gpio_type = 1 -> shared mic-in/line-in
670 int spi_dac; 670 gpio_type = 2 -> shared side-out/line-in. */
671 int i2c_adc; /* with i2c_adc=1, the driver adds some capture volume
672 controls, phone, mic, line-in and aux. */
673 int spi_dac; /* spi_dac=1 adds the mute switch for each analog
674 output, front, rear, etc. */
671}; 675};
672 676
673// definition of the chip-specific record 677// definition of the chip-specific record
@@ -686,11 +690,12 @@ struct snd_ca0106 {
686 spinlock_t emu_lock; 690 spinlock_t emu_lock;
687 691
688 struct snd_ac97 *ac97; 692 struct snd_ac97 *ac97;
689 struct snd_pcm *pcm; 693 struct snd_pcm *pcm[4];
690 694
691 struct snd_ca0106_channel playback_channels[4]; 695 struct snd_ca0106_channel playback_channels[4];
692 struct snd_ca0106_channel capture_channels[4]; 696 struct snd_ca0106_channel capture_channels[4];
693 u32 spdif_bits[4]; /* s/pdif out setup */ 697 u32 spdif_bits[4]; /* s/pdif out default setup */
698 u32 spdif_str_bits[4]; /* s/pdif out per-stream setup */
694 int spdif_enable; 699 int spdif_enable;
695 int capture_source; 700 int capture_source;
696 int i2c_capture_source; 701 int i2c_capture_source;
@@ -703,6 +708,11 @@ struct snd_ca0106 {
703 struct snd_ca_midi midi2; 708 struct snd_ca_midi midi2;
704 709
705 u16 spi_dac_reg[16]; 710 u16 spi_dac_reg[16];
711
712#ifdef CONFIG_PM
713#define NUM_SAVED_VOLUMES 9
714 unsigned int saved_vol[NUM_SAVED_VOLUMES];
715#endif
706}; 716};
707 717
708int snd_ca0106_mixer(struct snd_ca0106 *emu); 718int snd_ca0106_mixer(struct snd_ca0106 *emu);
@@ -721,3 +731,11 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu, u32 reg, u32 value);
721 731
722int snd_ca0106_spi_write(struct snd_ca0106 * emu, 732int snd_ca0106_spi_write(struct snd_ca0106 * emu,
723 unsigned int data); 733 unsigned int data);
734
735#ifdef CONFIG_PM
736void snd_ca0106_mixer_suspend(struct snd_ca0106 *chip);
737void snd_ca0106_mixer_resume(struct snd_ca0106 *chip);
738#else
739#define snd_ca0106_mixer_suspend(chip) do { } while (0)
740#define snd_ca0106_mixer_resume(chip) do { } while (0)
741#endif
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 88fbf285d2b7..0e62205d4081 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -254,7 +254,7 @@ static struct snd_ca0106_details ca0106_chip_details[] = {
254 .name = "MSI K8N Diamond MB", 254 .name = "MSI K8N Diamond MB",
255 .gpio_type = 2, 255 .gpio_type = 2,
256 .i2c_adc = 1, 256 .i2c_adc = 1,
257 .spi_dac = 2 } , 257 .spi_dac = 1 } ,
258 /* Shuttle XPC SD31P which has an onboard Creative Labs 258 /* Shuttle XPC SD31P which has an onboard Creative Labs
259 * Sound Blaster Live! 24-bit EAX 259 * Sound Blaster Live! 24-bit EAX
260 * high-definition 7.1 audio processor". 260 * high-definition 7.1 audio processor".
@@ -305,9 +305,15 @@ static struct snd_pcm_hardware snd_ca0106_capture_hw = {
305 SNDRV_PCM_INFO_BLOCK_TRANSFER | 305 SNDRV_PCM_INFO_BLOCK_TRANSFER |
306 SNDRV_PCM_INFO_MMAP_VALID), 306 SNDRV_PCM_INFO_MMAP_VALID),
307 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, 307 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
308#if 0 /* FIXME: looks like 44.1kHz capture causes noisy output on 48kHz */
308 .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 309 .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
309 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000), 310 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000),
310 .rate_min = 44100, 311 .rate_min = 44100,
312#else
313 .rates = (SNDRV_PCM_RATE_48000 |
314 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000),
315 .rate_min = 48000,
316#endif /* FIXME */
311 .rate_max = 192000, 317 .rate_max = 192000,
312 .channels_min = 2, 318 .channels_min = 2,
313 .channels_max = 2, 319 .channels_max = 2,
@@ -479,6 +485,15 @@ static const int spi_dacd_bit[] = {
479 [PCM_UNKNOWN_CHANNEL] = SPI_DACD1_BIT, 485 [PCM_UNKNOWN_CHANNEL] = SPI_DACD1_BIT,
480}; 486};
481 487
488static void restore_spdif_bits(struct snd_ca0106 *chip, int idx)
489{
490 if (chip->spdif_str_bits[idx] != chip->spdif_bits[idx]) {
491 chip->spdif_str_bits[idx] = chip->spdif_bits[idx];
492 snd_ca0106_ptr_write(chip, SPCS0 + idx, 0,
493 chip->spdif_str_bits[idx]);
494 }
495}
496
482/* open_playback callback */ 497/* open_playback callback */
483static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substream, 498static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substream,
484 int channel_id) 499 int channel_id)
@@ -524,6 +539,9 @@ static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substr
524 if (err < 0) 539 if (err < 0)
525 return err; 540 return err;
526 } 541 }
542
543 restore_spdif_bits(chip, channel_id);
544
527 return 0; 545 return 0;
528} 546}
529 547
@@ -535,6 +553,8 @@ static int snd_ca0106_pcm_close_playback(struct snd_pcm_substream *substream)
535 struct snd_ca0106_pcm *epcm = runtime->private_data; 553 struct snd_ca0106_pcm *epcm = runtime->private_data;
536 chip->playback_channels[epcm->channel_id].use = 0; 554 chip->playback_channels[epcm->channel_id].use = 0;
537 555
556 restore_spdif_bits(chip, epcm->channel_id);
557
538 if (chip->details->spi_dac && epcm->channel_id != PCM_FRONT_CHANNEL) { 558 if (chip->details->spi_dac && epcm->channel_id != PCM_FRONT_CHANNEL) {
539 const int reg = spi_dacd_reg[epcm->channel_id]; 559 const int reg = spi_dacd_reg[epcm->channel_id];
540 560
@@ -847,15 +867,18 @@ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
847 struct snd_pcm_substream *s; 867 struct snd_pcm_substream *s;
848 u32 basic = 0; 868 u32 basic = 0;
849 u32 extended = 0; 869 u32 extended = 0;
850 int running=0; 870 u32 bits;
871 int running = 0;
851 872
852 switch (cmd) { 873 switch (cmd) {
853 case SNDRV_PCM_TRIGGER_START: 874 case SNDRV_PCM_TRIGGER_START:
854 running=1; 875 case SNDRV_PCM_TRIGGER_RESUME:
876 running = 1;
855 break; 877 break;
856 case SNDRV_PCM_TRIGGER_STOP: 878 case SNDRV_PCM_TRIGGER_STOP:
879 case SNDRV_PCM_TRIGGER_SUSPEND:
857 default: 880 default:
858 running=0; 881 running = 0;
859 break; 882 break;
860 } 883 }
861 snd_pcm_group_for_each_entry(s, substream) { 884 snd_pcm_group_for_each_entry(s, substream) {
@@ -865,22 +888,32 @@ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
865 runtime = s->runtime; 888 runtime = s->runtime;
866 epcm = runtime->private_data; 889 epcm = runtime->private_data;
867 channel = epcm->channel_id; 890 channel = epcm->channel_id;
868 //snd_printk("channel=%d\n",channel); 891 /* snd_printk("channel=%d\n",channel); */
869 epcm->running = running; 892 epcm->running = running;
870 basic |= (0x1<<channel); 893 basic |= (0x1 << channel);
871 extended |= (0x10<<channel); 894 extended |= (0x10 << channel);
872 snd_pcm_trigger_done(s, substream); 895 snd_pcm_trigger_done(s, substream);
873 } 896 }
874 //snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); 897 /* snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); */
875 898
876 switch (cmd) { 899 switch (cmd) {
877 case SNDRV_PCM_TRIGGER_START: 900 case SNDRV_PCM_TRIGGER_START:
878 snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (extended)); 901 case SNDRV_PCM_TRIGGER_RESUME:
879 snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(basic)); 902 bits = snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0);
903 bits |= extended;
904 snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, bits);
905 bits = snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0);
906 bits |= basic;
907 snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, bits);
880 break; 908 break;
881 case SNDRV_PCM_TRIGGER_STOP: 909 case SNDRV_PCM_TRIGGER_STOP:
882 snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(basic)); 910 case SNDRV_PCM_TRIGGER_SUSPEND:
883 snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(extended)); 911 bits = snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0);
912 bits &= ~basic;
913 snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, bits);
914 bits = snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0);
915 bits &= ~extended;
916 snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, bits);
884 break; 917 break;
885 default: 918 default:
886 result = -EINVAL; 919 result = -EINVAL;
@@ -1103,21 +1136,13 @@ static int snd_ca0106_ac97(struct snd_ca0106 *chip)
1103 return snd_ac97_mixer(pbus, &ac97, &chip->ac97); 1136 return snd_ac97_mixer(pbus, &ac97, &chip->ac97);
1104} 1137}
1105 1138
1139static void ca0106_stop_chip(struct snd_ca0106 *chip);
1140
1106static int snd_ca0106_free(struct snd_ca0106 *chip) 1141static int snd_ca0106_free(struct snd_ca0106 *chip)
1107{ 1142{
1108 if (chip->res_port != NULL) { /* avoid access to already used hardware */ 1143 if (chip->res_port != NULL) {
1109 // disable interrupts 1144 /* avoid access to already used hardware */
1110 snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0); 1145 ca0106_stop_chip(chip);
1111 outl(0, chip->port + INTE);
1112 snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0);
1113 udelay(1000);
1114 // disable audio
1115 //outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
1116 outl(0, chip->port + HCFG);
1117 /* FIXME: We need to stop and DMA transfers here.
1118 * But as I am not sure how yet, we cannot from the dma pages.
1119 * So we can fix: snd-malloc: Memory leak? pages not freed = 8
1120 */
1121 } 1146 }
1122 if (chip->irq >= 0) 1147 if (chip->irq >= 0)
1123 free_irq(chip->irq, chip); 1148 free_irq(chip->irq, chip);
@@ -1203,15 +1228,14 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id)
1203 return IRQ_HANDLED; 1228 return IRQ_HANDLED;
1204} 1229}
1205 1230
1206static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct snd_pcm **rpcm) 1231static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device)
1207{ 1232{
1208 struct snd_pcm *pcm; 1233 struct snd_pcm *pcm;
1209 struct snd_pcm_substream *substream; 1234 struct snd_pcm_substream *substream;
1210 int err; 1235 int err;
1211 1236
1212 if (rpcm) 1237 err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm);
1213 *rpcm = NULL; 1238 if (err < 0)
1214 if ((err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm)) < 0)
1215 return err; 1239 return err;
1216 1240
1217 pcm->private_data = emu; 1241 pcm->private_data = emu;
@@ -1238,7 +1262,6 @@ static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct s
1238 pcm->info_flags = 0; 1262 pcm->info_flags = 0;
1239 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 1263 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
1240 strcpy(pcm->name, "CA0106"); 1264 strcpy(pcm->name, "CA0106");
1241 emu->pcm = pcm;
1242 1265
1243 for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; 1266 for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
1244 substream; 1267 substream;
@@ -1260,8 +1283,7 @@ static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct s
1260 return err; 1283 return err;
1261 } 1284 }
1262 1285
1263 if (rpcm) 1286 emu->pcm[device] = pcm;
1264 *rpcm = pcm;
1265 1287
1266 return 0; 1288 return 0;
1267} 1289}
@@ -1301,89 +1323,10 @@ static unsigned int i2c_adc_init[][2] = {
1301 { 0x15, ADC_MUX_LINEIN }, /* ADC Mixer control */ 1323 { 0x15, ADC_MUX_LINEIN }, /* ADC Mixer control */
1302}; 1324};
1303 1325
1304static int __devinit snd_ca0106_create(int dev, struct snd_card *card, 1326static void ca0106_init_chip(struct snd_ca0106 *chip, int resume)
1305 struct pci_dev *pci,
1306 struct snd_ca0106 **rchip)
1307{ 1327{
1308 struct snd_ca0106 *chip;
1309 struct snd_ca0106_details *c;
1310 int err;
1311 int ch; 1328 int ch;
1312 static struct snd_device_ops ops = { 1329 unsigned int def_bits;
1313 .dev_free = snd_ca0106_dev_free,
1314 };
1315
1316 *rchip = NULL;
1317
1318 if ((err = pci_enable_device(pci)) < 0)
1319 return err;
1320 if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 ||
1321 pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) {
1322 printk(KERN_ERR "error to set 32bit mask DMA\n");
1323 pci_disable_device(pci);
1324 return -ENXIO;
1325 }
1326
1327 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1328 if (chip == NULL) {
1329 pci_disable_device(pci);
1330 return -ENOMEM;
1331 }
1332
1333 chip->card = card;
1334 chip->pci = pci;
1335 chip->irq = -1;
1336
1337 spin_lock_init(&chip->emu_lock);
1338
1339 chip->port = pci_resource_start(pci, 0);
1340 if ((chip->res_port = request_region(chip->port, 0x20,
1341 "snd_ca0106")) == NULL) {
1342 snd_ca0106_free(chip);
1343 printk(KERN_ERR "cannot allocate the port\n");
1344 return -EBUSY;
1345 }
1346
1347 if (request_irq(pci->irq, snd_ca0106_interrupt,
1348 IRQF_SHARED, "snd_ca0106", chip)) {
1349 snd_ca0106_free(chip);
1350 printk(KERN_ERR "cannot grab irq\n");
1351 return -EBUSY;
1352 }
1353 chip->irq = pci->irq;
1354
1355 /* This stores the periods table. */
1356 if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &chip->buffer) < 0) {
1357 snd_ca0106_free(chip);
1358 return -ENOMEM;
1359 }
1360
1361 pci_set_master(pci);
1362 /* read serial */
1363 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
1364 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
1365#if 1
1366 printk(KERN_INFO "snd-ca0106: Model %04x Rev %08x Serial %08x\n", chip->model,
1367 pci->revision, chip->serial);
1368#endif
1369 strcpy(card->driver, "CA0106");
1370 strcpy(card->shortname, "CA0106");
1371
1372 for (c = ca0106_chip_details; c->serial; c++) {
1373 if (subsystem[dev]) {
1374 if (c->serial == subsystem[dev])
1375 break;
1376 } else if (c->serial == chip->serial)
1377 break;
1378 }
1379 chip->details = c;
1380 if (subsystem[dev]) {
1381 printk(KERN_INFO "snd-ca0106: Sound card name=%s, subsystem=0x%x. Forced to subsystem=0x%x\n",
1382 c->name, chip->serial, subsystem[dev]);
1383 }
1384
1385 sprintf(card->longname, "%s at 0x%lx irq %i",
1386 c->name, chip->port, chip->irq);
1387 1330
1388 outl(0, chip->port + INTE); 1331 outl(0, chip->port + INTE);
1389 1332
@@ -1401,31 +1344,22 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
1401 * AN = 0 (Audio data) 1344 * AN = 0 (Audio data)
1402 * P = 0 (Consumer) 1345 * P = 0 (Consumer)
1403 */ 1346 */
1404 snd_ca0106_ptr_write(chip, SPCS0, 0, 1347 def_bits =
1405 chip->spdif_bits[0] = 1348 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1406 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | 1349 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1407 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | 1350 SPCS_GENERATIONSTATUS | 0x00001200 |
1408 SPCS_GENERATIONSTATUS | 0x00001200 | 1351 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
1409 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); 1352 if (!resume) {
1353 chip->spdif_str_bits[0] = chip->spdif_bits[0] = def_bits;
1354 chip->spdif_str_bits[1] = chip->spdif_bits[1] = def_bits;
1355 chip->spdif_str_bits[2] = chip->spdif_bits[2] = def_bits;
1356 chip->spdif_str_bits[3] = chip->spdif_bits[3] = def_bits;
1357 }
1410 /* Only SPCS1 has been tested */ 1358 /* Only SPCS1 has been tested */
1411 snd_ca0106_ptr_write(chip, SPCS1, 0, 1359 snd_ca0106_ptr_write(chip, SPCS1, 0, chip->spdif_str_bits[1]);
1412 chip->spdif_bits[1] = 1360 snd_ca0106_ptr_write(chip, SPCS0, 0, chip->spdif_str_bits[0]);
1413 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | 1361 snd_ca0106_ptr_write(chip, SPCS2, 0, chip->spdif_str_bits[2]);
1414 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | 1362 snd_ca0106_ptr_write(chip, SPCS3, 0, chip->spdif_str_bits[3]);
1415 SPCS_GENERATIONSTATUS | 0x00001200 |
1416 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
1417 snd_ca0106_ptr_write(chip, SPCS2, 0,
1418 chip->spdif_bits[2] =
1419 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1420 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1421 SPCS_GENERATIONSTATUS | 0x00001200 |
1422 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
1423 snd_ca0106_ptr_write(chip, SPCS3, 0,
1424 chip->spdif_bits[3] =
1425 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1426 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1427 SPCS_GENERATIONSTATUS | 0x00001200 |
1428 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
1429 1363
1430 snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000); 1364 snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000);
1431 snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000); 1365 snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000);
@@ -1433,92 +1367,124 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
1433 /* Write 0x8000 to AC97_REC_GAIN to mute it. */ 1367 /* Write 0x8000 to AC97_REC_GAIN to mute it. */
1434 outb(AC97_REC_GAIN, chip->port + AC97ADDRESS); 1368 outb(AC97_REC_GAIN, chip->port + AC97ADDRESS);
1435 outw(0x8000, chip->port + AC97DATA); 1369 outw(0x8000, chip->port + AC97DATA);
1436#if 0 1370#if 0 /* FIXME: what are these? */
1437 snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006); 1371 snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006);
1438 snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006); 1372 snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006);
1439 snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006); 1373 snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006);
1440 snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006); 1374 snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006);
1441#endif 1375#endif
1442 1376
1443 //snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */ 1377 /* OSS drivers set this. */
1378 /* snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); */
1379
1444 /* Analog or Digital output */ 1380 /* Analog or Digital output */
1445 snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf); 1381 snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf);
1446 snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */ 1382 /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers.
1383 * Use 0x000f0000 for surround71
1384 */
1385 snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000);
1386
1447 chip->spdif_enable = 0; /* Set digital SPDIF output off */ 1387 chip->spdif_enable = 0; /* Set digital SPDIF output off */
1448 //snd_ca0106_ptr_write(chip, 0x45, 0, 0); /* Analogue out */ 1388 /*snd_ca0106_ptr_write(chip, 0x45, 0, 0);*/ /* Analogue out */
1449 //snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00); /* Digital out */ 1389 /*snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00);*/ /* Digital out */
1390
1391 /* goes to 0x40c80000 when doing SPDIF IN/OUT */
1392 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000);
1393 /* (Mute) CAPTURE feedback into PLAYBACK volume.
1394 * Only lower 16 bits matter.
1395 */
1396 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff);
1397 /* SPDIF IN Volume */
1398 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000);
1399 /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */
1400 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000);
1450 1401
1451 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); /* goes to 0x40c80000 when doing SPDIF IN/OUT */
1452 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); /* (Mute) CAPTURE feedback into PLAYBACK volume. Only lower 16 bits matter. */
1453 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); /* SPDIF IN Volume */
1454 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */
1455 snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410); 1402 snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410);
1456 snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676); 1403 snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676);
1457 snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410); 1404 snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410);
1458 snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676); 1405 snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676);
1459 for(ch = 0; ch < 4; ch++) { 1406
1460 snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); /* Only high 16 bits matter */ 1407 for (ch = 0; ch < 4; ch++) {
1408 /* Only high 16 bits matter */
1409 snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030);
1461 snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030); 1410 snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030);
1462 //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); /* Mute */ 1411#if 0 /* Mute */
1463 //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); /* Mute */ 1412 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040);
1464 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); /* Mute */ 1413 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040);
1465 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); /* Mute */ 1414 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff);
1415 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff);
1416#endif
1466 } 1417 }
1467 if (chip->details->i2c_adc == 1) { 1418 if (chip->details->i2c_adc == 1) {
1468 /* Select MIC, Line in, TAD in, AUX in */ 1419 /* Select MIC, Line in, TAD in, AUX in */
1469 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); 1420 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4);
1470 /* Default to CAPTURE_SOURCE to i2s in */ 1421 /* Default to CAPTURE_SOURCE to i2s in */
1471 chip->capture_source = 3; 1422 if (!resume)
1423 chip->capture_source = 3;
1472 } else if (chip->details->ac97 == 1) { 1424 } else if (chip->details->ac97 == 1) {
1473 /* Default to AC97 in */ 1425 /* Default to AC97 in */
1474 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x444400e4); 1426 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x444400e4);
1475 /* Default to CAPTURE_SOURCE to AC97 in */ 1427 /* Default to CAPTURE_SOURCE to AC97 in */
1476 chip->capture_source = 4; 1428 if (!resume)
1429 chip->capture_source = 4;
1477 } else { 1430 } else {
1478 /* Select MIC, Line in, TAD in, AUX in */ 1431 /* Select MIC, Line in, TAD in, AUX in */
1479 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); 1432 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4);
1480 /* Default to Set CAPTURE_SOURCE to i2s in */ 1433 /* Default to Set CAPTURE_SOURCE to i2s in */
1481 chip->capture_source = 3; 1434 if (!resume)
1435 chip->capture_source = 3;
1482 } 1436 }
1483 1437
1484 if (chip->details->gpio_type == 2) { /* The SB0438 use GPIO differently. */ 1438 if (chip->details->gpio_type == 2) {
1485 /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */ 1439 /* The SB0438 use GPIO differently. */
1440 /* FIXME: Still need to find out what the other GPIO bits do.
1441 * E.g. For digital spdif out.
1442 */
1486 outl(0x0, chip->port+GPIO); 1443 outl(0x0, chip->port+GPIO);
1487 //outl(0x00f0e000, chip->port+GPIO); /* Analog */ 1444 /* outl(0x00f0e000, chip->port+GPIO); */ /* Analog */
1488 outl(0x005f5301, chip->port+GPIO); /* Analog */ 1445 outl(0x005f5301, chip->port+GPIO); /* Analog */
1489 } else if (chip->details->gpio_type == 1) { /* The SB0410 and SB0413 use GPIO differently. */ 1446 } else if (chip->details->gpio_type == 1) {
1490 /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */ 1447 /* The SB0410 and SB0413 use GPIO differently. */
1448 /* FIXME: Still need to find out what the other GPIO bits do.
1449 * E.g. For digital spdif out.
1450 */
1491 outl(0x0, chip->port+GPIO); 1451 outl(0x0, chip->port+GPIO);
1492 //outl(0x00f0e000, chip->port+GPIO); /* Analog */ 1452 /* outl(0x00f0e000, chip->port+GPIO); */ /* Analog */
1493 outl(0x005f5301, chip->port+GPIO); /* Analog */ 1453 outl(0x005f5301, chip->port+GPIO); /* Analog */
1494 } else { 1454 } else {
1495 outl(0x0, chip->port+GPIO); 1455 outl(0x0, chip->port+GPIO);
1496 outl(0x005f03a3, chip->port+GPIO); /* Analog */ 1456 outl(0x005f03a3, chip->port+GPIO); /* Analog */
1497 //outl(0x005f02a2, chip->port+GPIO); /* SPDIF */ 1457 /* outl(0x005f02a2, chip->port+GPIO); */ /* SPDIF */
1498 } 1458 }
1499 snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */ 1459 snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */
1500 1460
1501 //outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG); 1461 /* outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG); */
1502 //outl(0x00001409, chip->port+HCFG); /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */ 1462 /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */
1503 //outl(0x00000009, chip->port+HCFG); 1463 /* outl(0x00001409, chip->port+HCFG); */
1504 outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG); /* AC97 2.0, Enable outputs. */ 1464 /* outl(0x00000009, chip->port+HCFG); */
1465 /* AC97 2.0, Enable outputs. */
1466 outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG);
1505 1467
1506 if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */ 1468 if (chip->details->i2c_adc == 1) {
1469 /* The SB0410 and SB0413 use I2C to control ADC. */
1507 int size, n; 1470 int size, n;
1508 1471
1509 size = ARRAY_SIZE(i2c_adc_init); 1472 size = ARRAY_SIZE(i2c_adc_init);
1510 //snd_printk("I2C:array size=0x%x\n", size); 1473 /* snd_printk("I2C:array size=0x%x\n", size); */
1511 for (n=0; n < size; n++) { 1474 for (n = 0; n < size; n++)
1512 snd_ca0106_i2c_write(chip, i2c_adc_init[n][0], i2c_adc_init[n][1]); 1475 snd_ca0106_i2c_write(chip, i2c_adc_init[n][0],
1513 } 1476 i2c_adc_init[n][1]);
1514 for (n=0; n < 4; n++) { 1477 for (n = 0; n < 4; n++) {
1515 chip->i2c_capture_volume[n][0]= 0xcf; 1478 chip->i2c_capture_volume[n][0] = 0xcf;
1516 chip->i2c_capture_volume[n][1]= 0xcf; 1479 chip->i2c_capture_volume[n][1] = 0xcf;
1517 } 1480 }
1518 chip->i2c_capture_source=2; /* Line in */ 1481 chip->i2c_capture_source = 2; /* Line in */
1519 //snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */ 1482 /* Enable Line-in capture. MIC in currently untested. */
1483 /* snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); */
1520 } 1484 }
1521 if (chip->details->spi_dac == 1) { /* The SB0570 use SPI to control DAC. */ 1485
1486 if (chip->details->spi_dac == 1) {
1487 /* The SB0570 use SPI to control DAC. */
1522 int size, n; 1488 int size, n;
1523 1489
1524 size = ARRAY_SIZE(spi_dac_init); 1490 size = ARRAY_SIZE(spi_dac_init);
@@ -1530,9 +1496,112 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
1530 chip->spi_dac_reg[reg] = spi_dac_init[n]; 1496 chip->spi_dac_reg[reg] = spi_dac_init[n];
1531 } 1497 }
1532 } 1498 }
1499}
1533 1500
1534 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, 1501static void ca0106_stop_chip(struct snd_ca0106 *chip)
1535 chip, &ops)) < 0) { 1502{
1503 /* disable interrupts */
1504 snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0);
1505 outl(0, chip->port + INTE);
1506 snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0);
1507 udelay(1000);
1508 /* disable audio */
1509 /* outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); */
1510 outl(0, chip->port + HCFG);
1511 /* FIXME: We need to stop and DMA transfers here.
1512 * But as I am not sure how yet, we cannot from the dma pages.
1513 * So we can fix: snd-malloc: Memory leak? pages not freed = 8
1514 */
1515}
1516
1517static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
1518 struct pci_dev *pci,
1519 struct snd_ca0106 **rchip)
1520{
1521 struct snd_ca0106 *chip;
1522 struct snd_ca0106_details *c;
1523 int err;
1524 static struct snd_device_ops ops = {
1525 .dev_free = snd_ca0106_dev_free,
1526 };
1527
1528 *rchip = NULL;
1529
1530 err = pci_enable_device(pci);
1531 if (err < 0)
1532 return err;
1533 if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 ||
1534 pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) {
1535 printk(KERN_ERR "error to set 32bit mask DMA\n");
1536 pci_disable_device(pci);
1537 return -ENXIO;
1538 }
1539
1540 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1541 if (chip == NULL) {
1542 pci_disable_device(pci);
1543 return -ENOMEM;
1544 }
1545
1546 chip->card = card;
1547 chip->pci = pci;
1548 chip->irq = -1;
1549
1550 spin_lock_init(&chip->emu_lock);
1551
1552 chip->port = pci_resource_start(pci, 0);
1553 chip->res_port = request_region(chip->port, 0x20, "snd_ca0106");
1554 if (!chip->res_port) {
1555 snd_ca0106_free(chip);
1556 printk(KERN_ERR "cannot allocate the port\n");
1557 return -EBUSY;
1558 }
1559
1560 if (request_irq(pci->irq, snd_ca0106_interrupt,
1561 IRQF_SHARED, "snd_ca0106", chip)) {
1562 snd_ca0106_free(chip);
1563 printk(KERN_ERR "cannot grab irq\n");
1564 return -EBUSY;
1565 }
1566 chip->irq = pci->irq;
1567
1568 /* This stores the periods table. */
1569 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1570 1024, &chip->buffer) < 0) {
1571 snd_ca0106_free(chip);
1572 return -ENOMEM;
1573 }
1574
1575 pci_set_master(pci);
1576 /* read serial */
1577 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
1578 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
1579 printk(KERN_INFO "snd-ca0106: Model %04x Rev %08x Serial %08x\n",
1580 chip->model, pci->revision, chip->serial);
1581 strcpy(card->driver, "CA0106");
1582 strcpy(card->shortname, "CA0106");
1583
1584 for (c = ca0106_chip_details; c->serial; c++) {
1585 if (subsystem[dev]) {
1586 if (c->serial == subsystem[dev])
1587 break;
1588 } else if (c->serial == chip->serial)
1589 break;
1590 }
1591 chip->details = c;
1592 if (subsystem[dev]) {
1593 printk(KERN_INFO "snd-ca0106: Sound card name=%s, "
1594 "subsystem=0x%x. Forced to subsystem=0x%x\n",
1595 c->name, chip->serial, subsystem[dev]);
1596 }
1597
1598 sprintf(card->longname, "%s at 0x%lx irq %i",
1599 c->name, chip->port, chip->irq);
1600
1601 ca0106_init_chip(chip, 0);
1602
1603 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1604 if (err < 0) {
1536 snd_ca0106_free(chip); 1605 snd_ca0106_free(chip);
1537 return err; 1606 return err;
1538 } 1607 }
@@ -1629,7 +1698,7 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1629 static int dev; 1698 static int dev;
1630 struct snd_card *card; 1699 struct snd_card *card;
1631 struct snd_ca0106 *chip; 1700 struct snd_ca0106 *chip;
1632 int err; 1701 int i, err;
1633 1702
1634 if (dev >= SNDRV_CARDS) 1703 if (dev >= SNDRV_CARDS)
1635 return -ENODEV; 1704 return -ENODEV;
@@ -1642,44 +1711,31 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1642 if (card == NULL) 1711 if (card == NULL)
1643 return -ENOMEM; 1712 return -ENOMEM;
1644 1713
1645 if ((err = snd_ca0106_create(dev, card, pci, &chip)) < 0) { 1714 err = snd_ca0106_create(dev, card, pci, &chip);
1646 snd_card_free(card); 1715 if (err < 0)
1647 return err; 1716 goto error;
1648 } 1717 card->private_data = chip;
1649 1718
1650 if ((err = snd_ca0106_pcm(chip, 0, NULL)) < 0) { 1719 for (i = 0; i < 4; i++) {
1651 snd_card_free(card); 1720 err = snd_ca0106_pcm(chip, i);
1652 return err; 1721 if (err < 0)
1653 } 1722 goto error;
1654 if ((err = snd_ca0106_pcm(chip, 1, NULL)) < 0) {
1655 snd_card_free(card);
1656 return err;
1657 }
1658 if ((err = snd_ca0106_pcm(chip, 2, NULL)) < 0) {
1659 snd_card_free(card);
1660 return err;
1661 }
1662 if ((err = snd_ca0106_pcm(chip, 3, NULL)) < 0) {
1663 snd_card_free(card);
1664 return err;
1665 }
1666 if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */
1667 if ((err = snd_ca0106_ac97(chip)) < 0) {
1668 snd_card_free(card);
1669 return err;
1670 }
1671 } 1723 }
1672 if ((err = snd_ca0106_mixer(chip)) < 0) { 1724
1673 snd_card_free(card); 1725 if (chip->details->ac97 == 1) {
1674 return err; 1726 /* The SB0410 and SB0413 do not have an AC97 chip. */
1727 err = snd_ca0106_ac97(chip);
1728 if (err < 0)
1729 goto error;
1675 } 1730 }
1731 err = snd_ca0106_mixer(chip);
1732 if (err < 0)
1733 goto error;
1676 1734
1677 snd_printdd("ca0106: probe for MIDI channel A ..."); 1735 snd_printdd("ca0106: probe for MIDI channel A ...");
1678 if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) { 1736 err = snd_ca0106_midi(chip, CA0106_MIDI_CHAN_A);
1679 snd_card_free(card); 1737 if (err < 0)
1680 snd_printdd(" failed, err=0x%x\n",err); 1738 goto error;
1681 return err;
1682 }
1683 snd_printdd(" done.\n"); 1739 snd_printdd(" done.\n");
1684 1740
1685#ifdef CONFIG_PROC_FS 1741#ifdef CONFIG_PROC_FS
@@ -1688,14 +1744,17 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1688 1744
1689 snd_card_set_dev(card, &pci->dev); 1745 snd_card_set_dev(card, &pci->dev);
1690 1746
1691 if ((err = snd_card_register(card)) < 0) { 1747 err = snd_card_register(card);
1692 snd_card_free(card); 1748 if (err < 0)
1693 return err; 1749 goto error;
1694 }
1695 1750
1696 pci_set_drvdata(pci, card); 1751 pci_set_drvdata(pci, card);
1697 dev++; 1752 dev++;
1698 return 0; 1753 return 0;
1754
1755 error:
1756 snd_card_free(card);
1757 return err;
1699} 1758}
1700 1759
1701static void __devexit snd_ca0106_remove(struct pci_dev *pci) 1760static void __devexit snd_ca0106_remove(struct pci_dev *pci)
@@ -1704,6 +1763,59 @@ static void __devexit snd_ca0106_remove(struct pci_dev *pci)
1704 pci_set_drvdata(pci, NULL); 1763 pci_set_drvdata(pci, NULL);
1705} 1764}
1706 1765
1766#ifdef CONFIG_PM
1767static int snd_ca0106_suspend(struct pci_dev *pci, pm_message_t state)
1768{
1769 struct snd_card *card = pci_get_drvdata(pci);
1770 struct snd_ca0106 *chip = card->private_data;
1771 int i;
1772
1773 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1774 for (i = 0; i < 4; i++)
1775 snd_pcm_suspend_all(chip->pcm[i]);
1776 if (chip->details->ac97)
1777 snd_ac97_suspend(chip->ac97);
1778 snd_ca0106_mixer_suspend(chip);
1779
1780 ca0106_stop_chip(chip);
1781
1782 pci_disable_device(pci);
1783 pci_save_state(pci);
1784 pci_set_power_state(pci, pci_choose_state(pci, state));
1785 return 0;
1786}
1787
1788static int snd_ca0106_resume(struct pci_dev *pci)
1789{
1790 struct snd_card *card = pci_get_drvdata(pci);
1791 struct snd_ca0106 *chip = card->private_data;
1792 int i;
1793
1794 pci_set_power_state(pci, PCI_D0);
1795 pci_restore_state(pci);
1796
1797 if (pci_enable_device(pci) < 0) {
1798 snd_card_disconnect(card);
1799 return -EIO;
1800 }
1801
1802 pci_set_master(pci);
1803
1804 ca0106_init_chip(chip, 1);
1805
1806 if (chip->details->ac97)
1807 snd_ac97_resume(chip->ac97);
1808 snd_ca0106_mixer_resume(chip);
1809 if (chip->details->spi_dac) {
1810 for (i = 0; i < ARRAY_SIZE(chip->spi_dac_reg); i++)
1811 snd_ca0106_spi_write(chip, chip->spi_dac_reg[i]);
1812 }
1813
1814 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1815 return 0;
1816}
1817#endif
1818
1707// PCI IDs 1819// PCI IDs
1708static struct pci_device_id snd_ca0106_ids[] = { 1820static struct pci_device_id snd_ca0106_ids[] = {
1709 { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */ 1821 { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */
@@ -1717,6 +1829,10 @@ static struct pci_driver driver = {
1717 .id_table = snd_ca0106_ids, 1829 .id_table = snd_ca0106_ids,
1718 .probe = snd_ca0106_probe, 1830 .probe = snd_ca0106_probe,
1719 .remove = __devexit_p(snd_ca0106_remove), 1831 .remove = __devexit_p(snd_ca0106_remove),
1832#ifdef CONFIG_PM
1833 .suspend = snd_ca0106_suspend,
1834 .resume = snd_ca0106_resume,
1835#endif
1720}; 1836};
1721 1837
1722// initialization of the module 1838// initialization of the module
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index 3025ed1b6e1e..ad2888705d2a 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -75,6 +75,84 @@
75 75
76#include "ca0106.h" 76#include "ca0106.h"
77 77
78static void ca0106_spdif_enable(struct snd_ca0106 *emu)
79{
80 unsigned int val;
81
82 if (emu->spdif_enable) {
83 /* Digital */
84 snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
85 snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000);
86 val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000;
87 snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val);
88 val = inl(emu->port + GPIO) & ~0x101;
89 outl(val, emu->port + GPIO);
90
91 } else {
92 /* Analog */
93 snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
94 snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000);
95 val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000;
96 snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val);
97 val = inl(emu->port + GPIO) | 0x101;
98 outl(val, emu->port + GPIO);
99 }
100}
101
102static void ca0106_set_capture_source(struct snd_ca0106 *emu)
103{
104 unsigned int val = emu->capture_source;
105 unsigned int source, mask;
106 source = (val << 28) | (val << 24) | (val << 20) | (val << 16);
107 mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff;
108 snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask);
109}
110
111static void ca0106_set_i2c_capture_source(struct snd_ca0106 *emu,
112 unsigned int val, int force)
113{
114 unsigned int ngain, ogain;
115 u32 source;
116
117 snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */
118 ngain = emu->i2c_capture_volume[val][0]; /* Left */
119 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */
120 if (force || ngain != ogain)
121 snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ngain & 0xff);
122 ngain = emu->i2c_capture_volume[val][1]; /* Right */
123 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */
124 if (force || ngain != ogain)
125 snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ngain & 0xff);
126 source = 1 << val;
127 snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */
128 emu->i2c_capture_source = val;
129}
130
131static void ca0106_set_capture_mic_line_in(struct snd_ca0106 *emu)
132{
133 u32 tmp;
134
135 if (emu->capture_mic_line_in) {
136 /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */
137 tmp = inl(emu->port+GPIO) & ~0x400;
138 tmp = tmp | 0x400;
139 outl(tmp, emu->port+GPIO);
140 /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC); */
141 } else {
142 /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */
143 tmp = inl(emu->port+GPIO) & ~0x400;
144 outl(tmp, emu->port+GPIO);
145 /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN); */
146 }
147}
148
149static void ca0106_set_spdif_bits(struct snd_ca0106 *emu, int idx)
150{
151 snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, emu->spdif_str_bits[idx]);
152}
153
154/*
155 */
78static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1); 156static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1);
79static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1); 157static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1);
80 158
@@ -95,30 +173,12 @@ static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol,
95 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); 173 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
96 unsigned int val; 174 unsigned int val;
97 int change = 0; 175 int change = 0;
98 u32 mask;
99 176
100 val = !!ucontrol->value.integer.value[0]; 177 val = !!ucontrol->value.integer.value[0];
101 change = (emu->spdif_enable != val); 178 change = (emu->spdif_enable != val);
102 if (change) { 179 if (change) {
103 emu->spdif_enable = val; 180 emu->spdif_enable = val;
104 if (val) { 181 ca0106_spdif_enable(emu);
105 /* Digital */
106 snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
107 snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000);
108 snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0,
109 snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000);
110 mask = inl(emu->port + GPIO) & ~0x101;
111 outl(mask, emu->port + GPIO);
112
113 } else {
114 /* Analog */
115 snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
116 snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000);
117 snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0,
118 snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000);
119 mask = inl(emu->port + GPIO) | 0x101;
120 outl(mask, emu->port + GPIO);
121 }
122 } 182 }
123 return change; 183 return change;
124} 184}
@@ -154,8 +214,6 @@ static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol,
154 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); 214 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
155 unsigned int val; 215 unsigned int val;
156 int change = 0; 216 int change = 0;
157 u32 mask;
158 u32 source;
159 217
160 val = ucontrol->value.enumerated.item[0] ; 218 val = ucontrol->value.enumerated.item[0] ;
161 if (val >= 6) 219 if (val >= 6)
@@ -163,9 +221,7 @@ static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol,
163 change = (emu->capture_source != val); 221 change = (emu->capture_source != val);
164 if (change) { 222 if (change) {
165 emu->capture_source = val; 223 emu->capture_source = val;
166 source = (val << 28) | (val << 24) | (val << 20) | (val << 16); 224 ca0106_set_capture_source(emu);
167 mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff;
168 snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask);
169 } 225 }
170 return change; 226 return change;
171} 227}
@@ -200,9 +256,7 @@ static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
200{ 256{
201 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); 257 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
202 unsigned int source_id; 258 unsigned int source_id;
203 unsigned int ngain, ogain;
204 int change = 0; 259 int change = 0;
205 u32 source;
206 /* If the capture source has changed, 260 /* If the capture source has changed,
207 * update the capture volume from the cached value 261 * update the capture volume from the cached value
208 * for the particular source. 262 * for the particular source.
@@ -212,18 +266,7 @@ static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
212 return -EINVAL; 266 return -EINVAL;
213 change = (emu->i2c_capture_source != source_id); 267 change = (emu->i2c_capture_source != source_id);
214 if (change) { 268 if (change) {
215 snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */ 269 ca0106_set_i2c_capture_source(emu, source_id, 0);
216 ngain = emu->i2c_capture_volume[source_id][0]; /* Left */
217 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */
218 if (ngain != ogain)
219 snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff));
220 ngain = emu->i2c_capture_volume[source_id][1]; /* Left */
221 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Left */
222 if (ngain != ogain)
223 snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
224 source = 1 << source_id;
225 snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */
226 emu->i2c_capture_source = source_id;
227 } 270 }
228 return change; 271 return change;
229} 272}
@@ -271,7 +314,6 @@ static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol,
271 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); 314 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
272 unsigned int val; 315 unsigned int val;
273 int change = 0; 316 int change = 0;
274 u32 tmp;
275 317
276 val = ucontrol->value.enumerated.item[0] ; 318 val = ucontrol->value.enumerated.item[0] ;
277 if (val > 1) 319 if (val > 1)
@@ -279,18 +321,7 @@ static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol,
279 change = (emu->capture_mic_line_in != val); 321 change = (emu->capture_mic_line_in != val);
280 if (change) { 322 if (change) {
281 emu->capture_mic_line_in = val; 323 emu->capture_mic_line_in = val;
282 if (val) { 324 ca0106_set_capture_mic_line_in(emu);
283 //snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */
284 tmp = inl(emu->port+GPIO) & ~0x400;
285 tmp = tmp | 0x400;
286 outl(tmp, emu->port+GPIO);
287 //snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC);
288 } else {
289 //snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */
290 tmp = inl(emu->port+GPIO) & ~0x400;
291 outl(tmp, emu->port+GPIO);
292 //snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN);
293 }
294 } 325 }
295 return change; 326 return change;
296} 327}
@@ -322,16 +353,33 @@ static int snd_ca0106_spdif_info(struct snd_kcontrol *kcontrol,
322 return 0; 353 return 0;
323} 354}
324 355
325static int snd_ca0106_spdif_get(struct snd_kcontrol *kcontrol, 356static void decode_spdif_bits(unsigned char *status, unsigned int bits)
357{
358 status[0] = (bits >> 0) & 0xff;
359 status[1] = (bits >> 8) & 0xff;
360 status[2] = (bits >> 16) & 0xff;
361 status[3] = (bits >> 24) & 0xff;
362}
363
364static int snd_ca0106_spdif_get_default(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol) 365 struct snd_ctl_elem_value *ucontrol)
327{ 366{
328 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); 367 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
329 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 368 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
330 369
331 ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff; 370 decode_spdif_bits(ucontrol->value.iec958.status,
332 ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff; 371 emu->spdif_bits[idx]);
333 ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff; 372 return 0;
334 ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff; 373}
374
375static int snd_ca0106_spdif_get_stream(struct snd_kcontrol *kcontrol,
376 struct snd_ctl_elem_value *ucontrol)
377{
378 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
379 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
380
381 decode_spdif_bits(ucontrol->value.iec958.status,
382 emu->spdif_str_bits[idx]);
335 return 0; 383 return 0;
336} 384}
337 385
@@ -345,24 +393,48 @@ static int snd_ca0106_spdif_get_mask(struct snd_kcontrol *kcontrol,
345 return 0; 393 return 0;
346} 394}
347 395
348static int snd_ca0106_spdif_put(struct snd_kcontrol *kcontrol, 396static unsigned int encode_spdif_bits(unsigned char *status)
397{
398 return ((unsigned int)status[0] << 0) |
399 ((unsigned int)status[1] << 8) |
400 ((unsigned int)status[2] << 16) |
401 ((unsigned int)status[3] << 24);
402}
403
404static int snd_ca0106_spdif_put_default(struct snd_kcontrol *kcontrol,
349 struct snd_ctl_elem_value *ucontrol) 405 struct snd_ctl_elem_value *ucontrol)
350{ 406{
351 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); 407 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
352 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 408 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
353 int change;
354 unsigned int val; 409 unsigned int val;
355 410
356 val = (ucontrol->value.iec958.status[0] << 0) | 411 val = encode_spdif_bits(ucontrol->value.iec958.status);
357 (ucontrol->value.iec958.status[1] << 8) | 412 if (val != emu->spdif_bits[idx]) {
358 (ucontrol->value.iec958.status[2] << 16) |
359 (ucontrol->value.iec958.status[3] << 24);
360 change = val != emu->spdif_bits[idx];
361 if (change) {
362 snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, val);
363 emu->spdif_bits[idx] = val; 413 emu->spdif_bits[idx] = val;
414 /* FIXME: this isn't safe, but needed to keep the compatibility
415 * with older alsa-lib config
416 */
417 emu->spdif_str_bits[idx] = val;
418 ca0106_set_spdif_bits(emu, idx);
419 return 1;
364 } 420 }
365 return change; 421 return 0;
422}
423
424static int snd_ca0106_spdif_put_stream(struct snd_kcontrol *kcontrol,
425 struct snd_ctl_elem_value *ucontrol)
426{
427 struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
428 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
429 unsigned int val;
430
431 val = encode_spdif_bits(ucontrol->value.iec958.status);
432 if (val != emu->spdif_str_bits[idx]) {
433 emu->spdif_str_bits[idx] = val;
434 ca0106_set_spdif_bits(emu, idx);
435 return 1;
436 }
437 return 0;
366} 438}
367 439
368static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol, 440static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol,
@@ -573,8 +645,16 @@ static struct snd_kcontrol_new snd_ca0106_volume_ctls[] __devinitdata = {
573 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 645 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
574 .count = 4, 646 .count = 4,
575 .info = snd_ca0106_spdif_info, 647 .info = snd_ca0106_spdif_info,
576 .get = snd_ca0106_spdif_get, 648 .get = snd_ca0106_spdif_get_default,
577 .put = snd_ca0106_spdif_put 649 .put = snd_ca0106_spdif_put_default
650 },
651 {
652 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
653 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
654 .count = 4,
655 .info = snd_ca0106_spdif_info,
656 .get = snd_ca0106_spdif_get_stream,
657 .put = snd_ca0106_spdif_put_stream
578 }, 658 },
579}; 659};
580 660
@@ -773,3 +853,50 @@ int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
773 return 0; 853 return 0;
774} 854}
775 855
856#ifdef CONFIG_PM
857struct ca0106_vol_tbl {
858 unsigned int channel_id;
859 unsigned int reg;
860};
861
862static struct ca0106_vol_tbl saved_volumes[NUM_SAVED_VOLUMES] = {
863 { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2 },
864 { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2 },
865 { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2 },
866 { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2 },
867 { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1 },
868 { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1 },
869 { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1 },
870 { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1 },
871 { 1, CAPTURE_CONTROL },
872};
873
874void snd_ca0106_mixer_suspend(struct snd_ca0106 *chip)
875{
876 int i;
877
878 /* save volumes */
879 for (i = 0; i < NUM_SAVED_VOLUMES; i++)
880 chip->saved_vol[i] =
881 snd_ca0106_ptr_read(chip, saved_volumes[i].reg,
882 saved_volumes[i].channel_id);
883}
884
885void snd_ca0106_mixer_resume(struct snd_ca0106 *chip)
886{
887 int i;
888
889 for (i = 0; i < NUM_SAVED_VOLUMES; i++)
890 snd_ca0106_ptr_write(chip, saved_volumes[i].reg,
891 saved_volumes[i].channel_id,
892 chip->saved_vol[i]);
893
894 ca0106_spdif_enable(chip);
895 ca0106_set_capture_source(chip);
896 ca0106_set_i2c_capture_source(chip, chip->i2c_capture_source, 1);
897 for (i = 0; i < 4; i++)
898 ca0106_set_spdif_bits(chip, i);
899 if (chip->details->i2c_adc)
900 ca0106_set_capture_mic_line_in(chip);
901}
902#endif /* CONFIG_PM */
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index fb6dc3980257..8ab07aa63652 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -3640,7 +3640,10 @@ int snd_cs46xx_resume(struct pci_dev *pci)
3640{ 3640{
3641 struct snd_card *card = pci_get_drvdata(pci); 3641 struct snd_card *card = pci_get_drvdata(pci);
3642 struct snd_cs46xx *chip = card->private_data; 3642 struct snd_cs46xx *chip = card->private_data;
3643 int i, amp_saved; 3643 int amp_saved;
3644#ifdef CONFIG_SND_CS46XX_NEW_DSP
3645 int i;
3646#endif
3644 3647
3645 pci_set_power_state(pci, PCI_D0); 3648 pci_set_power_state(pci, PCI_D0);
3646 pci_restore_state(pci); 3649 pci_restore_state(pci);
diff --git a/sound/pci/cs5535audio/Makefile b/sound/pci/cs5535audio/Makefile
index bb3d57e6a3cb..fda7a94c992f 100644
--- a/sound/pci/cs5535audio/Makefile
+++ b/sound/pci/cs5535audio/Makefile
@@ -4,6 +4,9 @@
4 4
5snd-cs5535audio-y := cs5535audio.o cs5535audio_pcm.o 5snd-cs5535audio-y := cs5535audio.o cs5535audio_pcm.o
6snd-cs5535audio-$(CONFIG_PM) += cs5535audio_pm.o 6snd-cs5535audio-$(CONFIG_PM) += cs5535audio_pm.o
7ifdef CONFIG_MGEODE_LX
8snd-cs5535audio-$(CONFIG_OLPC) += cs5535audio_olpc.o
9endif
7 10
8# Toplevel Module Dependency 11# Toplevel Module Dependency
9obj-$(CONFIG_SND_CS5535AUDIO) += snd-cs5535audio.o 12obj-$(CONFIG_SND_CS5535AUDIO) += snd-cs5535audio.o
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c
index 1d8b16052535..826e6dec2e97 100644
--- a/sound/pci/cs5535audio/cs5535audio.c
+++ b/sound/pci/cs5535audio/cs5535audio.c
@@ -159,10 +159,14 @@ static int __devinit snd_cs5535audio_mixer(struct cs5535audio *cs5535au)
159 return err; 159 return err;
160 160
161 memset(&ac97, 0, sizeof(ac97)); 161 memset(&ac97, 0, sizeof(ac97));
162 ac97.scaps = AC97_SCAP_AUDIO|AC97_SCAP_SKIP_MODEM; 162 ac97.scaps = AC97_SCAP_AUDIO | AC97_SCAP_SKIP_MODEM
163 | AC97_SCAP_POWER_SAVE;
163 ac97.private_data = cs5535au; 164 ac97.private_data = cs5535au;
164 ac97.pci = cs5535au->pci; 165 ac97.pci = cs5535au->pci;
165 166
167 /* set any OLPC-specific scaps */
168 olpc_prequirks(card, &ac97);
169
166 if ((err = snd_ac97_mixer(pbus, &ac97, &cs5535au->ac97)) < 0) { 170 if ((err = snd_ac97_mixer(pbus, &ac97, &cs5535au->ac97)) < 0) {
167 snd_printk(KERN_ERR "mixer failed\n"); 171 snd_printk(KERN_ERR "mixer failed\n");
168 return err; 172 return err;
@@ -170,6 +174,12 @@ static int __devinit snd_cs5535audio_mixer(struct cs5535audio *cs5535au)
170 174
171 snd_ac97_tune_hardware(cs5535au->ac97, ac97_quirks, ac97_quirk); 175 snd_ac97_tune_hardware(cs5535au->ac97, ac97_quirks, ac97_quirk);
172 176
177 err = olpc_quirks(card, cs5535au->ac97);
178 if (err < 0) {
179 snd_printk(KERN_ERR "olpc quirks failed\n");
180 return err;
181 }
182
173 return 0; 183 return 0;
174} 184}
175 185
diff --git a/sound/pci/cs5535audio/cs5535audio.h b/sound/pci/cs5535audio/cs5535audio.h
index 66bae7664193..7a298ac662e3 100644
--- a/sound/pci/cs5535audio/cs5535audio.h
+++ b/sound/pci/cs5535audio/cs5535audio.h
@@ -78,6 +78,7 @@ struct cs5535audio_dma {
78 unsigned int buf_addr, buf_bytes; 78 unsigned int buf_addr, buf_bytes;
79 unsigned int period_bytes, periods; 79 unsigned int period_bytes, periods;
80 u32 saved_prd; 80 u32 saved_prd;
81 int pcm_open_flag;
81}; 82};
82 83
83struct cs5535audio { 84struct cs5535audio {
@@ -93,8 +94,46 @@ struct cs5535audio {
93 struct cs5535audio_dma dmas[NUM_CS5535AUDIO_DMAS]; 94 struct cs5535audio_dma dmas[NUM_CS5535AUDIO_DMAS];
94}; 95};
95 96
97#ifdef CONFIG_PM
96int snd_cs5535audio_suspend(struct pci_dev *pci, pm_message_t state); 98int snd_cs5535audio_suspend(struct pci_dev *pci, pm_message_t state);
97int snd_cs5535audio_resume(struct pci_dev *pci); 99int snd_cs5535audio_resume(struct pci_dev *pci);
100#endif
101
102#if defined(CONFIG_OLPC) && defined(CONFIG_MGEODE_LX)
103void __devinit olpc_prequirks(struct snd_card *card,
104 struct snd_ac97_template *ac97);
105int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97);
106void olpc_analog_input(struct snd_ac97 *ac97, int on);
107void olpc_mic_bias(struct snd_ac97 *ac97, int on);
108
109static inline void olpc_capture_open(struct snd_ac97 *ac97)
110{
111 /* default to Analog Input off */
112 olpc_analog_input(ac97, 0);
113 /* enable MIC Bias for recording */
114 olpc_mic_bias(ac97, 1);
115}
116
117static inline void olpc_capture_close(struct snd_ac97 *ac97)
118{
119 /* disable Analog Input */
120 olpc_analog_input(ac97, 0);
121 /* disable the MIC Bias (so the recording LED turns off) */
122 olpc_mic_bias(ac97, 0);
123}
124#else
125static inline void olpc_prequirks(struct snd_card *card,
126 struct snd_ac97_template *ac97) { }
127static inline int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
128{
129 return 0;
130}
131static inline void olpc_analog_input(struct snd_ac97 *ac97, int on) { }
132static inline void olpc_mic_bias(struct snd_ac97 *ac97, int on) { }
133static inline void olpc_capture_open(struct snd_ac97 *ac97) { }
134static inline void olpc_capture_close(struct snd_ac97 *ac97) { }
135#endif
136
98int __devinit snd_cs5535audio_pcm(struct cs5535audio *cs5535audio); 137int __devinit snd_cs5535audio_pcm(struct cs5535audio *cs5535audio);
99 138
100#endif /* __SOUND_CS5535AUDIO_H */ 139#endif /* __SOUND_CS5535AUDIO_H */
diff --git a/sound/pci/cs5535audio/cs5535audio_olpc.c b/sound/pci/cs5535audio/cs5535audio_olpc.c
new file mode 100644
index 000000000000..5c6814335cd7
--- /dev/null
+++ b/sound/pci/cs5535audio/cs5535audio_olpc.c
@@ -0,0 +1,179 @@
1/*
2 * OLPC XO-1 additional sound features
3 *
4 * Copyright © 2006 Jaya Kumar <jayakumar.lkml@gmail.com>
5 * Copyright © 2007-2008 Andres Salomon <dilinger@debian.org>
6 *
7 * This program 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#include <sound/core.h>
13#include <sound/info.h>
14#include <sound/control.h>
15#include <sound/ac97_codec.h>
16
17#include <asm/olpc.h>
18#include "cs5535audio.h"
19
20/*
21 * OLPC has an additional feature on top of the regular AD1888 codec features.
22 * It has an Analog Input mode that is switched into (after disabling the
23 * High Pass Filter) via GPIO. It is supported on B2 and later models.
24 */
25void olpc_analog_input(struct snd_ac97 *ac97, int on)
26{
27 int err;
28
29 if (!machine_is_olpc())
30 return;
31
32 /* update the High Pass Filter (via AC97_AD_TEST2) */
33 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
34 1 << AC97_AD_HPFD_SHIFT, on << AC97_AD_HPFD_SHIFT);
35 if (err < 0) {
36 snd_printk(KERN_ERR "setting High Pass Filter - %d\n", err);
37 return;
38 }
39
40 /* set Analog Input through GPIO */
41 if (on)
42 geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
43 else
44 geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
45}
46
47/*
48 * OLPC XO-1's V_REFOUT is a mic bias enable.
49 */
50void olpc_mic_bias(struct snd_ac97 *ac97, int on)
51{
52 int err;
53
54 if (!machine_is_olpc())
55 return;
56
57 on = on ? 0 : 1;
58 err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
59 1 << AC97_AD_VREFD_SHIFT, on << AC97_AD_VREFD_SHIFT);
60 if (err < 0)
61 snd_printk(KERN_ERR "setting MIC Bias - %d\n", err);
62}
63
64static int olpc_dc_info(struct snd_kcontrol *kctl,
65 struct snd_ctl_elem_info *uinfo)
66{
67 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
68 uinfo->count = 1;
69 uinfo->value.integer.min = 0;
70 uinfo->value.integer.max = 1;
71 return 0;
72}
73
74static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
75{
76 v->value.integer.value[0] = geode_gpio_isset(OLPC_GPIO_MIC_AC,
77 GPIO_OUTPUT_VAL);
78 return 0;
79}
80
81static int olpc_dc_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
82{
83 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
84
85 olpc_analog_input(cs5535au->ac97, v->value.integer.value[0]);
86 return 1;
87}
88
89static int olpc_mic_info(struct snd_kcontrol *kctl,
90 struct snd_ctl_elem_info *uinfo)
91{
92 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
93 uinfo->count = 1;
94 uinfo->value.integer.min = 0;
95 uinfo->value.integer.max = 1;
96 return 0;
97}
98
99static int olpc_mic_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
100{
101 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
102 struct snd_ac97 *ac97 = cs5535au->ac97;
103 int i;
104
105 i = (snd_ac97_read(ac97, AC97_AD_MISC) >> AC97_AD_VREFD_SHIFT) & 0x1;
106 v->value.integer.value[0] = i ? 0 : 1;
107 return 0;
108}
109
110static int olpc_mic_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
111{
112 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
113
114 olpc_mic_bias(cs5535au->ac97, v->value.integer.value[0]);
115 return 1;
116}
117
118static struct snd_kcontrol_new olpc_cs5535audio_ctls[] __devinitdata = {
119{
120 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
121 .name = "DC Mode Enable",
122 .info = olpc_dc_info,
123 .get = olpc_dc_get,
124 .put = olpc_dc_put,
125 .private_value = 0,
126},
127{
128 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
129 .name = "MIC Bias Enable",
130 .info = olpc_mic_info,
131 .get = olpc_mic_get,
132 .put = olpc_mic_put,
133 .private_value = 0,
134},
135};
136
137void __devinit olpc_prequirks(struct snd_card *card,
138 struct snd_ac97_template *ac97)
139{
140 if (!machine_is_olpc())
141 return;
142
143 /* invert EAPD if on an OLPC B3 or higher */
144 if (olpc_board_at_least(olpc_board_pre(0xb3)))
145 ac97->scaps |= AC97_SCAP_INV_EAPD;
146}
147
148int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
149{
150 struct snd_ctl_elem_id elem;
151 int i, err;
152
153 if (!machine_is_olpc())
154 return 0;
155
156 /* drop the original AD1888 HPF control */
157 memset(&elem, 0, sizeof(elem));
158 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
159 strncpy(elem.name, "High Pass Filter Enable", sizeof(elem.name));
160 snd_ctl_remove_id(card, &elem);
161
162 /* drop the original V_REFOUT control */
163 memset(&elem, 0, sizeof(elem));
164 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
165 strncpy(elem.name, "V_REFOUT Enable", sizeof(elem.name));
166 snd_ctl_remove_id(card, &elem);
167
168 /* add the OLPC-specific controls */
169 for (i = 0; i < ARRAY_SIZE(olpc_cs5535audio_ctls); i++) {
170 err = snd_ctl_add(card, snd_ctl_new1(&olpc_cs5535audio_ctls[i],
171 ac97->private_data));
172 if (err < 0)
173 return err;
174 }
175
176 /* turn off the mic by default */
177 olpc_mic_bias(ac97, 0);
178 return 0;
179}
diff --git a/sound/pci/cs5535audio/cs5535audio_pcm.c b/sound/pci/cs5535audio/cs5535audio_pcm.c
index cdcda87116c3..0f48a871f17b 100644
--- a/sound/pci/cs5535audio/cs5535audio_pcm.c
+++ b/sound/pci/cs5535audio/cs5535audio_pcm.c
@@ -260,6 +260,9 @@ static int snd_cs5535audio_hw_params(struct snd_pcm_substream *substream,
260 err = cs5535audio_build_dma_packets(cs5535au, dma, substream, 260 err = cs5535audio_build_dma_packets(cs5535au, dma, substream,
261 params_periods(hw_params), 261 params_periods(hw_params),
262 params_period_bytes(hw_params)); 262 params_period_bytes(hw_params));
263 if (!err)
264 dma->pcm_open_flag = 1;
265
263 return err; 266 return err;
264} 267}
265 268
@@ -268,6 +271,15 @@ static int snd_cs5535audio_hw_free(struct snd_pcm_substream *substream)
268 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); 271 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
269 struct cs5535audio_dma *dma = substream->runtime->private_data; 272 struct cs5535audio_dma *dma = substream->runtime->private_data;
270 273
274 if (dma->pcm_open_flag) {
275 if (substream == cs5535au->playback_substream)
276 snd_ac97_update_power(cs5535au->ac97,
277 AC97_PCM_FRONT_DAC_RATE, 0);
278 else
279 snd_ac97_update_power(cs5535au->ac97,
280 AC97_PCM_LR_ADC_RATE, 0);
281 dma->pcm_open_flag = 0;
282 }
271 cs5535audio_clear_dma_packets(cs5535au, dma, substream); 283 cs5535audio_clear_dma_packets(cs5535au, dma, substream);
272 return snd_pcm_lib_free_pages(substream); 284 return snd_pcm_lib_free_pages(substream);
273} 285}
@@ -351,11 +363,14 @@ static int snd_cs5535audio_capture_open(struct snd_pcm_substream *substream)
351 if ((err = snd_pcm_hw_constraint_integer(runtime, 363 if ((err = snd_pcm_hw_constraint_integer(runtime,
352 SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 364 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
353 return err; 365 return err;
366 olpc_capture_open(cs5535au->ac97);
354 return 0; 367 return 0;
355} 368}
356 369
357static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream) 370static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream)
358{ 371{
372 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
373 olpc_capture_close(cs5535au->ac97);
359 return 0; 374 return 0;
360} 375}
361 376
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index de5ee8f097f6..7958006a1d66 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -69,7 +69,7 @@ MODULE_FIRMWARE(EMU1010_NOTEBOOK_FILENAME);
69 * EMU10K1 init / done 69 * EMU10K1 init / done
70 *************************************************************************/ 70 *************************************************************************/
71 71
72void snd_emu10k1_voice_init(struct snd_emu10k1 * emu, int ch) 72void snd_emu10k1_voice_init(struct snd_emu10k1 *emu, int ch)
73{ 73{
74 snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0); 74 snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
75 snd_emu10k1_ptr_write(emu, IP, ch, 0); 75 snd_emu10k1_ptr_write(emu, IP, ch, 0);
@@ -151,9 +151,9 @@ static unsigned int i2c_adc_init[][2] = {
151 { 0x12, 0x32 }, /* ALC Control 3 */ 151 { 0x12, 0x32 }, /* ALC Control 3 */
152 { 0x13, 0x00 }, /* Noise gate control */ 152 { 0x13, 0x00 }, /* Noise gate control */
153 { 0x14, 0xa6 }, /* Limiter control */ 153 { 0x14, 0xa6 }, /* Limiter control */
154 { 0x15, ADC_MUX_2 }, /* ADC Mixer control. Mic for Audigy 2 ZS Notebook */ 154 { 0x15, ADC_MUX_2 }, /* ADC Mixer control. Mic for A2ZS Notebook */
155}; 155};
156 156
157static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume) 157static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
158{ 158{
159 unsigned int silent_page; 159 unsigned int silent_page;
@@ -161,8 +161,8 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
161 u32 tmp; 161 u32 tmp;
162 162
163 /* disable audio and lock cache */ 163 /* disable audio and lock cache */
164 outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, 164 outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK |
165 emu->port + HCFG); 165 HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
166 166
167 /* reset recording buffers */ 167 /* reset recording buffers */
168 snd_emu10k1_ptr_write(emu, MICBS, 0, ADCBS_BUFSIZE_NONE); 168 snd_emu10k1_ptr_write(emu, MICBS, 0, ADCBS_BUFSIZE_NONE);
@@ -179,7 +179,7 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
179 snd_emu10k1_ptr_write(emu, SOLEL, 0, 0); 179 snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
180 snd_emu10k1_ptr_write(emu, SOLEH, 0, 0); 180 snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
181 181
182 if (emu->audigy){ 182 if (emu->audigy) {
183 /* set SPDIF bypass mode */ 183 /* set SPDIF bypass mode */
184 snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT); 184 snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT);
185 /* enable rear left + rear right AC97 slots */ 185 /* enable rear left + rear right AC97 slots */
@@ -197,12 +197,12 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
197 197
198 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */ 198 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
199 /* Hacks for Alice3 to work independent of haP16V driver */ 199 /* Hacks for Alice3 to work independent of haP16V driver */
200 //Setup SRCMulti_I2S SamplingRate 200 /* Setup SRCMulti_I2S SamplingRate */
201 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); 201 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
202 tmp &= 0xfffff1ff; 202 tmp &= 0xfffff1ff;
203 tmp |= (0x2<<9); 203 tmp |= (0x2<<9);
204 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp); 204 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
205 205
206 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */ 206 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
207 snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14); 207 snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14);
208 /* Setup SRCMulti Input Audio Enable */ 208 /* Setup SRCMulti Input Audio Enable */
@@ -217,7 +217,7 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
217 if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */ 217 if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
218 /* Hacks for Alice3 to work independent of haP16V driver */ 218 /* Hacks for Alice3 to work independent of haP16V driver */
219 snd_printk(KERN_INFO "Audigy2 value: Special config.\n"); 219 snd_printk(KERN_INFO "Audigy2 value: Special config.\n");
220 //Setup SRCMulti_I2S SamplingRate 220 /* Setup SRCMulti_I2S SamplingRate */
221 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); 221 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
222 tmp &= 0xfffff1ff; 222 tmp &= 0xfffff1ff;
223 tmp |= (0x2<<9); 223 tmp |= (0x2<<9);
@@ -270,13 +270,13 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
270 size = ARRAY_SIZE(i2c_adc_init); 270 size = ARRAY_SIZE(i2c_adc_init);
271 for (n = 0; n < size; n++) 271 for (n = 0; n < size; n++)
272 snd_emu10k1_i2c_write(emu, i2c_adc_init[n][0], i2c_adc_init[n][1]); 272 snd_emu10k1_i2c_write(emu, i2c_adc_init[n][0], i2c_adc_init[n][1]);
273 for (n=0; n < 4; n++) { 273 for (n = 0; n < 4; n++) {
274 emu->i2c_capture_volume[n][0]= 0xcf; 274 emu->i2c_capture_volume[n][0] = 0xcf;
275 emu->i2c_capture_volume[n][1]= 0xcf; 275 emu->i2c_capture_volume[n][1] = 0xcf;
276 } 276 }
277 } 277 }
278 278
279 279
280 snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr); 280 snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
281 snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */ 281 snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */
282 snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */ 282 snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
@@ -313,7 +313,7 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
313 (emu->model == 0x21 && emu->revision < 6)) 313 (emu->model == 0x21 && emu->revision < 6))
314 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE, emu->port + HCFG); 314 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE, emu->port + HCFG);
315 else 315 else
316 // With on-chip joystick 316 /* With on-chip joystick */
317 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG); 317 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
318 318
319 if (enable_ir) { /* enable IR for SB Live */ 319 if (enable_ir) { /* enable IR for SB Live */
@@ -335,9 +335,9 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
335 outl(reg | HCFG_GPOUT1 | HCFG_GPOUT2, emu->port + HCFG); 335 outl(reg | HCFG_GPOUT1 | HCFG_GPOUT2, emu->port + HCFG);
336 udelay(100); 336 udelay(100);
337 outl(reg, emu->port + HCFG); 337 outl(reg, emu->port + HCFG);
338 } 338 }
339 } 339 }
340 340
341 if (emu->card_capabilities->emu_model) { 341 if (emu->card_capabilities->emu_model) {
342 ; /* Disable all access to A_IOCFG for the emu1010 */ 342 ; /* Disable all access to A_IOCFG for the emu1010 */
343 } else if (emu->card_capabilities->i2c_adc) { 343 } else if (emu->card_capabilities->i2c_adc) {
@@ -364,7 +364,7 @@ static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
364 ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */ 364 ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
365 } else if (emu->audigy) { 365 } else if (emu->audigy) {
366 outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG); 366 outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG);
367 367
368 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */ 368 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
369 /* Unmute Analog now. Set GPO6 to 1 for Apollo. 369 /* Unmute Analog now. Set GPO6 to 1 for Apollo.
370 * This has to be done after init ALice3 I2SOut beyond 48KHz. 370 * This has to be done after init ALice3 I2SOut beyond 48KHz.
@@ -378,12 +378,12 @@ static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
378 outl(inl(emu->port + A_IOCFG) | 0x0080, emu->port + A_IOCFG); 378 outl(inl(emu->port + A_IOCFG) | 0x0080, emu->port + A_IOCFG);
379 } 379 }
380 } 380 }
381 381
382#if 0 382#if 0
383 { 383 {
384 unsigned int tmp; 384 unsigned int tmp;
385 /* FIXME: the following routine disables LiveDrive-II !! */ 385 /* FIXME: the following routine disables LiveDrive-II !! */
386 // TOSLink detection 386 /* TOSLink detection */
387 emu->tos_link = 0; 387 emu->tos_link = 0;
388 tmp = inl(emu->port + HCFG); 388 tmp = inl(emu->port + HCFG);
389 if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) { 389 if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
@@ -400,7 +400,7 @@ static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
400 snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE); 400 snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE);
401} 401}
402 402
403int snd_emu10k1_done(struct snd_emu10k1 * emu) 403int snd_emu10k1_done(struct snd_emu10k1 *emu)
404{ 404{
405 int ch; 405 int ch;
406 406
@@ -495,7 +495,7 @@ int snd_emu10k1_done(struct snd_emu10k1 * emu)
495 495
496#define EC_LAST_PROMFILE_ADDR 0x2f 496#define EC_LAST_PROMFILE_ADDR 0x2f
497 497
498#define EC_SERIALNUM_ADDR 0x30 /* First word of serial number. The 498#define EC_SERIALNUM_ADDR 0x30 /* First word of serial number. The
499 * can be up to 30 characters in length 499 * can be up to 30 characters in length
500 * and is stored as a NULL-terminated 500 * and is stored as a NULL-terminated
501 * ASCII string. Any unused bytes must be 501 * ASCII string. Any unused bytes must be
@@ -503,8 +503,8 @@ int snd_emu10k1_done(struct snd_emu10k1 * emu)
503#define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */ 503#define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */
504 504
505 505
506/* Most of this stuff is pretty self-evident. According to the hardware 506/* Most of this stuff is pretty self-evident. According to the hardware
507 * dudes, we need to leave the ADCCAL bit low in order to avoid a DC 507 * dudes, we need to leave the ADCCAL bit low in order to avoid a DC
508 * offset problem. Weird. 508 * offset problem. Weird.
509 */ 509 */
510#define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \ 510#define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \
@@ -523,7 +523,7 @@ int snd_emu10k1_done(struct snd_emu10k1 * emu)
523 * register. 523 * register.
524 */ 524 */
525 525
526static void snd_emu10k1_ecard_write(struct snd_emu10k1 * emu, unsigned int value) 526static void snd_emu10k1_ecard_write(struct snd_emu10k1 *emu, unsigned int value)
527{ 527{
528 unsigned short count; 528 unsigned short count;
529 unsigned int data; 529 unsigned int data;
@@ -561,7 +561,7 @@ static void snd_emu10k1_ecard_write(struct snd_emu10k1 * emu, unsigned int value
561 * channel. 561 * channel.
562 */ 562 */
563 563
564static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 * emu, 564static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 *emu,
565 unsigned short gain) 565 unsigned short gain)
566{ 566{
567 unsigned int bit; 567 unsigned int bit;
@@ -574,7 +574,7 @@ static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 * emu,
574 574
575 for (bit = (1 << 15); bit; bit >>= 1) { 575 for (bit = (1 << 15); bit; bit >>= 1) {
576 unsigned int value; 576 unsigned int value;
577 577
578 value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA); 578 value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA);
579 579
580 if (gain & bit) 580 if (gain & bit)
@@ -589,7 +589,7 @@ static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 * emu,
589 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl); 589 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
590} 590}
591 591
592static int snd_emu10k1_ecard_init(struct snd_emu10k1 * emu) 592static int snd_emu10k1_ecard_init(struct snd_emu10k1 *emu)
593{ 593{
594 unsigned int hc_value; 594 unsigned int hc_value;
595 595
@@ -598,7 +598,7 @@ static int snd_emu10k1_ecard_init(struct snd_emu10k1 * emu)
598 EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) | 598 EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) |
599 EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL); 599 EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL);
600 600
601 /* Step 0: Set the codec type in the hardware control register 601 /* Step 0: Set the codec type in the hardware control register
602 * and enable audio output */ 602 * and enable audio output */
603 hc_value = inl(emu->port + HCFG); 603 hc_value = inl(emu->port + HCFG);
604 outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG); 604 outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG);
@@ -629,7 +629,7 @@ static int snd_emu10k1_ecard_init(struct snd_emu10k1 * emu)
629 return 0; 629 return 0;
630} 630}
631 631
632static int snd_emu10k1_cardbus_init(struct snd_emu10k1 * emu) 632static int snd_emu10k1_cardbus_init(struct snd_emu10k1 *emu)
633{ 633{
634 unsigned long special_port; 634 unsigned long special_port;
635 unsigned int value; 635 unsigned int value;
@@ -656,7 +656,7 @@ static int snd_emu10k1_cardbus_init(struct snd_emu10k1 * emu)
656 return 0; 656 return 0;
657} 657}
658 658
659static int snd_emu1010_load_firmware(struct snd_emu10k1 * emu, const char * filename) 659static int snd_emu1010_load_firmware(struct snd_emu10k1 *emu, const char *filename)
660{ 660{
661 int err; 661 int err;
662 int n, i; 662 int n, i;
@@ -666,11 +666,12 @@ static int snd_emu1010_load_firmware(struct snd_emu10k1 * emu, const char * file
666 unsigned long flags; 666 unsigned long flags;
667 const struct firmware *fw_entry; 667 const struct firmware *fw_entry;
668 668
669 if ((err = request_firmware(&fw_entry, filename, &emu->pci->dev)) != 0) { 669 err = request_firmware(&fw_entry, filename, &emu->pci->dev);
670 snd_printk(KERN_ERR "firmware: %s not found. Err=%d\n",filename, err); 670 if (err != 0) {
671 snd_printk(KERN_ERR "firmware: %s not found. Err = %d\n", filename, err);
671 return err; 672 return err;
672 } 673 }
673 snd_printk(KERN_INFO "firmware size=0x%zx\n", fw_entry->size); 674 snd_printk(KERN_INFO "firmware size = 0x%zx\n", fw_entry->size);
674 675
675 /* The FPGA is a Xilinx Spartan IIE XC2S50E */ 676 /* The FPGA is a Xilinx Spartan IIE XC2S50E */
676 /* GPIO7 -> FPGA PGMN 677 /* GPIO7 -> FPGA PGMN
@@ -685,13 +686,13 @@ static int snd_emu1010_load_firmware(struct snd_emu10k1 * emu, const char * file
685 outl(0x80, emu->port + A_IOCFG); /* Leave bit 7 set during netlist setup. */ 686 outl(0x80, emu->port + A_IOCFG); /* Leave bit 7 set during netlist setup. */
686 write_post = inl(emu->port + A_IOCFG); 687 write_post = inl(emu->port + A_IOCFG);
687 udelay(100); /* Allow FPGA memory to clean */ 688 udelay(100); /* Allow FPGA memory to clean */
688 for(n = 0; n < fw_entry->size; n++) { 689 for (n = 0; n < fw_entry->size; n++) {
689 value=fw_entry->data[n]; 690 value = fw_entry->data[n];
690 for(i = 0; i < 8; i++) { 691 for (i = 0; i < 8; i++) {
691 reg = 0x80; 692 reg = 0x80;
692 if (value & 0x1) 693 if (value & 0x1)
693 reg = reg | 0x20; 694 reg = reg | 0x20;
694 value = value >> 1; 695 value = value >> 1;
695 outl(reg, emu->port + A_IOCFG); 696 outl(reg, emu->port + A_IOCFG);
696 write_post = inl(emu->port + A_IOCFG); 697 write_post = inl(emu->port + A_IOCFG);
697 outl(reg | 0x40, emu->port + A_IOCFG); 698 outl(reg | 0x40, emu->port + A_IOCFG);
@@ -703,14 +704,14 @@ static int snd_emu1010_load_firmware(struct snd_emu10k1 * emu, const char * file
703 write_post = inl(emu->port + A_IOCFG); 704 write_post = inl(emu->port + A_IOCFG);
704 spin_unlock_irqrestore(&emu->emu_lock, flags); 705 spin_unlock_irqrestore(&emu->emu_lock, flags);
705 706
706 release_firmware(fw_entry); 707 release_firmware(fw_entry);
707 return 0; 708 return 0;
708} 709}
709 710
710static int emu1010_firmware_thread(void *data) 711static int emu1010_firmware_thread(void *data)
711{ 712{
712 struct snd_emu10k1 * emu = data; 713 struct snd_emu10k1 *emu = data;
713 int tmp,tmp2; 714 int tmp, tmp2;
714 int reg; 715 int reg;
715 int err; 716 int err;
716 717
@@ -719,50 +720,50 @@ static int emu1010_firmware_thread(void *data)
719 msleep_interruptible(1000); 720 msleep_interruptible(1000);
720 if (kthread_should_stop()) 721 if (kthread_should_stop())
721 break; 722 break;
722 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp ); /* IRQ Status */ 723 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp); /* IRQ Status */
723 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg ); /* OPTIONS: Which cards are attached to the EMU */ 724 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg); /* OPTIONS: Which cards are attached to the EMU */
724 if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) { 725 if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) {
725 /* Audio Dock attached */ 726 /* Audio Dock attached */
726 /* Return to Audio Dock programming mode */ 727 /* Return to Audio Dock programming mode */
727 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware\n"); 728 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware\n");
728 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK ); 729 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK);
729 if (emu->card_capabilities->emu_model == 730 if (emu->card_capabilities->emu_model ==
730 EMU_MODEL_EMU1010) { 731 EMU_MODEL_EMU1010) {
731 if ((err = snd_emu1010_load_firmware(emu, DOCK_FILENAME)) != 0) { 732 err = snd_emu1010_load_firmware(emu, DOCK_FILENAME);
733 if (err != 0)
732 continue; 734 continue;
733 }
734 } else if (emu->card_capabilities->emu_model == 735 } else if (emu->card_capabilities->emu_model ==
735 EMU_MODEL_EMU1010B) { 736 EMU_MODEL_EMU1010B) {
736 if ((err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME)) != 0) { 737 err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME);
738 if (err != 0)
737 continue; 739 continue;
738 }
739 } else if (emu->card_capabilities->emu_model == 740 } else if (emu->card_capabilities->emu_model ==
740 EMU_MODEL_EMU1616) { 741 EMU_MODEL_EMU1616) {
741 if ((err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME)) != 0) { 742 err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME);
743 if (err != 0)
742 continue; 744 continue;
743 }
744 } 745 }
745 746
746 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0 ); 747 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0);
747 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg ); 748 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg);
748 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_IRQ_STATUS=0x%x\n",reg); 749 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_IRQ_STATUS = 0x%x\n", reg);
749 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */ 750 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
750 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg ); 751 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
751 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_ID=0x%x\n",reg); 752 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_ID = 0x%x\n", reg);
752 if ((reg & 0x1f) != 0x15) { 753 if ((reg & 0x1f) != 0x15) {
753 /* FPGA failed to be programmed */ 754 /* FPGA failed to be programmed */
754 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware file failed, reg=0x%x\n", reg); 755 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware file failed, reg = 0x%x\n", reg);
755 continue; 756 continue;
756 } 757 }
757 snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n"); 758 snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n");
758 snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp ); 759 snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp);
759 snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2 ); 760 snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2);
760 snd_printk("Audio Dock ver:%d.%d\n",tmp ,tmp2); 761 snd_printk("Audio Dock ver:%d.%d\n", tmp, tmp2);
761 /* Sync clocking between 1010 and Dock */ 762 /* Sync clocking between 1010 and Dock */
762 /* Allow DLL to settle */ 763 /* Allow DLL to settle */
763 msleep(10); 764 msleep(10);
764 /* Unmute all. Default is muted after a firmware load */ 765 /* Unmute all. Default is muted after a firmware load */
765 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); 766 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
766 } 767 }
767 } 768 }
768 snd_printk(KERN_INFO "emu1010: firmware thread stopping\n"); 769 snd_printk(KERN_INFO "emu1010: firmware thread stopping\n");
@@ -800,10 +801,10 @@ static int emu1010_firmware_thread(void *data)
800 * 16 x 16-bit playback - snd_emu10k1_fx8010_playback_ops 801 * 16 x 16-bit playback - snd_emu10k1_fx8010_playback_ops
801 * 16 x 32-bit capture - snd_emu10k1_capture_efx_ops 802 * 16 x 32-bit capture - snd_emu10k1_capture_efx_ops
802 */ 803 */
803static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu) 804static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
804{ 805{
805 unsigned int i; 806 unsigned int i;
806 int tmp,tmp2; 807 int tmp, tmp2;
807 int reg; 808 int reg;
808 int err; 809 int err;
809 const char *filename = NULL; 810 const char *filename = NULL;
@@ -818,7 +819,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
818 * Lock Tank Memory Cache, 819 * Lock Tank Memory Cache,
819 * Mute all codecs. 820 * Mute all codecs.
820 */ 821 */
821 outl(0x0005a004, emu->port + HCFG); 822 outl(0x0005a004, emu->port + HCFG);
822 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave, 823 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
823 * Mute all codecs. 824 * Mute all codecs.
824 */ 825 */
@@ -829,25 +830,25 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
829 outl(0x0005a000, emu->port + HCFG); 830 outl(0x0005a000, emu->port + HCFG);
830 831
831 /* Disable 48Volt power to Audio Dock */ 832 /* Disable 48Volt power to Audio Dock */
832 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0 ); 833 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0);
833 834
834 /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */ 835 /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */
835 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg ); 836 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
836 snd_printdd("reg1=0x%x\n",reg); 837 snd_printdd("reg1 = 0x%x\n", reg);
837 if ((reg & 0x3f) == 0x15) { 838 if ((reg & 0x3f) == 0x15) {
838 /* FPGA netlist already present so clear it */ 839 /* FPGA netlist already present so clear it */
839 /* Return to programming mode */ 840 /* Return to programming mode */
840 841
841 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0x02 ); 842 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0x02);
842 } 843 }
843 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg ); 844 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
844 snd_printdd("reg2=0x%x\n",reg); 845 snd_printdd("reg2 = 0x%x\n", reg);
845 if ((reg & 0x3f) == 0x15) { 846 if ((reg & 0x3f) == 0x15) {
846 /* FPGA failed to return to programming mode */ 847 /* FPGA failed to return to programming mode */
847 snd_printk(KERN_INFO "emu1010: FPGA failed to return to programming mode\n"); 848 snd_printk(KERN_INFO "emu1010: FPGA failed to return to programming mode\n");
848 return -ENODEV; 849 return -ENODEV;
849 } 850 }
850 snd_printk(KERN_INFO "emu1010: EMU_HANA_ID=0x%x\n",reg); 851 snd_printk(KERN_INFO "emu1010: EMU_HANA_ID = 0x%x\n", reg);
851 switch (emu->card_capabilities->emu_model) { 852 switch (emu->card_capabilities->emu_model) {
852 case EMU_MODEL_EMU1010: 853 case EMU_MODEL_EMU1010:
853 filename = HANA_FILENAME; 854 filename = HANA_FILENAME;
@@ -876,25 +877,25 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
876 } 877 }
877 878
878 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */ 879 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
879 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg ); 880 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
880 if ((reg & 0x3f) != 0x15) { 881 if ((reg & 0x3f) != 0x15) {
881 /* FPGA failed to be programmed */ 882 /* FPGA failed to be programmed */
882 snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file failed, reg=0x%x\n", reg); 883 snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file failed, reg = 0x%x\n", reg);
883 return -ENODEV; 884 return -ENODEV;
884 } 885 }
885 886
886 snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n"); 887 snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n");
887 snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp ); 888 snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp);
888 snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2 ); 889 snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2);
889 snd_printk("Hana ver:%d.%d\n",tmp ,tmp2); 890 snd_printk("emu1010: Hana version: %d.%d\n", tmp, tmp2);
890 /* Enable 48Volt power to Audio Dock */ 891 /* Enable 48Volt power to Audio Dock */
891 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON ); 892 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON);
892 893
893 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg ); 894 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
894 snd_printk(KERN_INFO "emu1010: Card options=0x%x\n",reg); 895 snd_printk(KERN_INFO "emu1010: Card options = 0x%x\n", reg);
895 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg ); 896 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
896 snd_printk(KERN_INFO "emu1010: Card options=0x%x\n",reg); 897 snd_printk(KERN_INFO "emu1010: Card options = 0x%x\n", reg);
897 snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp ); 898 snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp);
898 /* Optical -> ADAT I/O */ 899 /* Optical -> ADAT I/O */
899 /* 0 : SPDIF 900 /* 0 : SPDIF
900 * 1 : ADAT 901 * 1 : ADAT
@@ -904,41 +905,42 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
904 tmp = 0; 905 tmp = 0;
905 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) | 906 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) |
906 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0); 907 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0);
907 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp ); 908 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
908 snd_emu1010_fpga_read(emu, EMU_HANA_ADC_PADS, &tmp ); 909 snd_emu1010_fpga_read(emu, EMU_HANA_ADC_PADS, &tmp);
909 /* Set no attenuation on Audio Dock pads. */ 910 /* Set no attenuation on Audio Dock pads. */
910 snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, 0x00 ); 911 snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, 0x00);
911 emu->emu1010.adc_pads = 0x00; 912 emu->emu1010.adc_pads = 0x00;
912 snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp ); 913 snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp);
913 /* Unmute Audio dock DACs, Headphone source DAC-4. */ 914 /* Unmute Audio dock DACs, Headphone source DAC-4. */
914 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30 ); 915 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30);
915 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12 ); 916 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12);
916 snd_emu1010_fpga_read(emu, EMU_HANA_DAC_PADS, &tmp ); 917 snd_emu1010_fpga_read(emu, EMU_HANA_DAC_PADS, &tmp);
917 /* DAC PADs. */ 918 /* DAC PADs. */
918 snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, 0x0f ); 919 snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, 0x0f);
919 emu->emu1010.dac_pads = 0x0f; 920 emu->emu1010.dac_pads = 0x0f;
920 snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp ); 921 snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp);
921 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30 ); 922 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30);
922 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp ); 923 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp);
923 /* SPDIF Format. Set Consumer mode, 24bit, copy enable */ 924 /* SPDIF Format. Set Consumer mode, 24bit, copy enable */
924 snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10 ); 925 snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10);
925 /* MIDI routing */ 926 /* MIDI routing */
926 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); 927 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19);
927 /* Unknown. */ 928 /* Unknown. */
928 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); 929 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c);
929 /* snd_emu1010_fpga_write(emu, 0x09, 0x0f ); // IRQ Enable: All on */ 930 /* IRQ Enable: Alll on */
931 /* snd_emu1010_fpga_write(emu, 0x09, 0x0f ); */
930 /* IRQ Enable: All off */ 932 /* IRQ Enable: All off */
931 snd_emu1010_fpga_write(emu, EMU_HANA_IRQ_ENABLE, 0x00 ); 933 snd_emu1010_fpga_write(emu, EMU_HANA_IRQ_ENABLE, 0x00);
932 934
933 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg ); 935 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
934 snd_printk(KERN_INFO "emu1010: Card options3=0x%x\n",reg); 936 snd_printk(KERN_INFO "emu1010: Card options3 = 0x%x\n", reg);
935 /* Default WCLK set to 48kHz. */ 937 /* Default WCLK set to 48kHz. */
936 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00 ); 938 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00);
937 /* Word Clock source, Internal 48kHz x1 */ 939 /* Word Clock source, Internal 48kHz x1 */
938 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K ); 940 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K);
939 //snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X ); 941 /* snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X); */
940 /* Audio Dock LEDs. */ 942 /* Audio Dock LEDs. */
941 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12 ); 943 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12);
942 944
943#if 0 945#if 0
944 /* For 96kHz */ 946 /* For 96kHz */
@@ -992,7 +994,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
992 * Defaults only, users will set their own values anyways, let's 994 * Defaults only, users will set their own values anyways, let's
993 * just copy/paste. 995 * just copy/paste.
994 */ 996 */
995 997
996 snd_emu1010_fpga_link_dst_src_write(emu, 998 snd_emu1010_fpga_link_dst_src_write(emu,
997 EMU_DST_ALICE2_EMU32_8, EMU_SRC_DOCK_MIC_A1); 999 EMU_DST_ALICE2_EMU32_8, EMU_SRC_DOCK_MIC_A1);
998 snd_emu1010_fpga_link_dst_src_write(emu, 1000 snd_emu1010_fpga_link_dst_src_write(emu,
@@ -1037,19 +1039,19 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
1037 snd_emu1010_fpga_link_dst_src_write(emu, 1039 snd_emu1010_fpga_link_dst_src_write(emu,
1038 EMU_DST_ALICE2_EMU32_F, EMU_SRC_HAMOA_ADC_LEFT2); 1040 EMU_DST_ALICE2_EMU32_F, EMU_SRC_HAMOA_ADC_LEFT2);
1039#endif 1041#endif
1040 for (i = 0;i < 0x20; i++ ) { 1042 for (i = 0; i < 0x20; i++) {
1041 /* AudioDock Elink <- Silence */ 1043 /* AudioDock Elink <- Silence */
1042 snd_emu1010_fpga_link_dst_src_write(emu, 0x0100+i, EMU_SRC_SILENCE); 1044 snd_emu1010_fpga_link_dst_src_write(emu, 0x0100 + i, EMU_SRC_SILENCE);
1043 } 1045 }
1044 for (i = 0;i < 4; i++) { 1046 for (i = 0; i < 4; i++) {
1045 /* Hana SPDIF Out <- Silence */ 1047 /* Hana SPDIF Out <- Silence */
1046 snd_emu1010_fpga_link_dst_src_write(emu, 0x0200+i, EMU_SRC_SILENCE); 1048 snd_emu1010_fpga_link_dst_src_write(emu, 0x0200 + i, EMU_SRC_SILENCE);
1047 } 1049 }
1048 for (i = 0;i < 7; i++) { 1050 for (i = 0; i < 7; i++) {
1049 /* Hamoa DAC <- Silence */ 1051 /* Hamoa DAC <- Silence */
1050 snd_emu1010_fpga_link_dst_src_write(emu, 0x0300+i, EMU_SRC_SILENCE); 1052 snd_emu1010_fpga_link_dst_src_write(emu, 0x0300 + i, EMU_SRC_SILENCE);
1051 } 1053 }
1052 for (i = 0;i < 7; i++) { 1054 for (i = 0; i < 7; i++) {
1053 /* Hana ADAT Out <- Silence */ 1055 /* Hana ADAT Out <- Silence */
1054 snd_emu1010_fpga_link_dst_src_write(emu, EMU_DST_HANA_ADAT + i, EMU_SRC_SILENCE); 1056 snd_emu1010_fpga_link_dst_src_write(emu, EMU_DST_HANA_ADAT + i, EMU_SRC_SILENCE);
1055 } 1057 }
@@ -1065,30 +1067,30 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
1065 EMU_DST_ALICE_I2S2_LEFT, EMU_SRC_DOCK_ADC3_LEFT1); 1067 EMU_DST_ALICE_I2S2_LEFT, EMU_SRC_DOCK_ADC3_LEFT1);
1066 snd_emu1010_fpga_link_dst_src_write(emu, 1068 snd_emu1010_fpga_link_dst_src_write(emu,
1067 EMU_DST_ALICE_I2S2_RIGHT, EMU_SRC_DOCK_ADC3_RIGHT1); 1069 EMU_DST_ALICE_I2S2_RIGHT, EMU_SRC_DOCK_ADC3_RIGHT1);
1068 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x01 ); // Unmute all 1070 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x01); /* Unmute all */
1071
1072 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp);
1069 1073
1070 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp );
1071
1072 /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave, 1074 /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
1073 * Lock Sound Memory Cache, Lock Tank Memory Cache, 1075 * Lock Sound Memory Cache, Lock Tank Memory Cache,
1074 * Mute all codecs. 1076 * Mute all codecs.
1075 */ 1077 */
1076 outl(0x0000a000, emu->port + HCFG); 1078 outl(0x0000a000, emu->port + HCFG);
1077 /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave, 1079 /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
1078 * Lock Sound Memory Cache, Lock Tank Memory Cache, 1080 * Lock Sound Memory Cache, Lock Tank Memory Cache,
1079 * Un-Mute all codecs. 1081 * Un-Mute all codecs.
1080 */ 1082 */
1081 outl(0x0000a001, emu->port + HCFG); 1083 outl(0x0000a001, emu->port + HCFG);
1082 1084
1083 /* Initial boot complete. Now patches */ 1085 /* Initial boot complete. Now patches */
1084 1086
1085 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp ); 1087 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp);
1086 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); /* MIDI Route */ 1088 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19); /* MIDI Route */
1087 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); /* Unknown */ 1089 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c); /* Unknown */
1088 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); /* MIDI Route */ 1090 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19); /* MIDI Route */
1089 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); /* Unknown */ 1091 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c); /* Unknown */
1090 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp ); 1092 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp);
1091 snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10 ); /* SPDIF Format spdif (or 0x11 for aes/ebu) */ 1093 snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10); /* SPDIF Format spdif (or 0x11 for aes/ebu) */
1092 1094
1093 /* Start Micro/Audio Dock firmware loader thread */ 1095 /* Start Micro/Audio Dock firmware loader thread */
1094 if (!emu->emu1010.firmware_thread) { 1096 if (!emu->emu1010.firmware_thread) {
@@ -1218,20 +1220,20 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
1218 emu->emu1010.output_source[23] = 28; 1220 emu->emu1010.output_source[23] = 28;
1219 } 1221 }
1220 /* TEMP: Select SPDIF in/out */ 1222 /* TEMP: Select SPDIF in/out */
1221 //snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, 0x0); /* Output spdif */ 1223 /* snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, 0x0); */ /* Output spdif */
1222 1224
1223 /* TEMP: Select 48kHz SPDIF out */ 1225 /* TEMP: Select 48kHz SPDIF out */
1224 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x0); /* Mute all */ 1226 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x0); /* Mute all */
1225 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x0); /* Default fallback clock 48kHz */ 1227 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x0); /* Default fallback clock 48kHz */
1226 /* Word Clock source, Internal 48kHz x1 */ 1228 /* Word Clock source, Internal 48kHz x1 */
1227 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K ); 1229 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K);
1228 //snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X ); 1230 /* snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X); */
1229 emu->emu1010.internal_clock = 1; /* 48000 */ 1231 emu->emu1010.internal_clock = 1; /* 48000 */
1230 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12);/* Set LEDs on Audio Dock */ 1232 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12); /* Set LEDs on Audio Dock */
1231 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x1); /* Unmute all */ 1233 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x1); /* Unmute all */
1232 //snd_emu1010_fpga_write(emu, 0x7, 0x0); /* Mute all */ 1234 /* snd_emu1010_fpga_write(emu, 0x7, 0x0); */ /* Mute all */
1233 //snd_emu1010_fpga_write(emu, 0x7, 0x1); /* Unmute all */ 1235 /* snd_emu1010_fpga_write(emu, 0x7, 0x1); */ /* Unmute all */
1234 //snd_emu1010_fpga_write(emu, 0xe, 0x12); /* Set LEDs on Audio Dock */ 1236 /* snd_emu1010_fpga_write(emu, 0xe, 0x12); */ /* Set LEDs on Audio Dock */
1235 1237
1236 return 0; 1238 return 0;
1237} 1239}
@@ -1247,13 +1249,13 @@ static void free_pm_buffer(struct snd_emu10k1 *emu);
1247static int snd_emu10k1_free(struct snd_emu10k1 *emu) 1249static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1248{ 1250{
1249 if (emu->port) { /* avoid access to already used hardware */ 1251 if (emu->port) { /* avoid access to already used hardware */
1250 snd_emu10k1_fx8010_tram_setup(emu, 0); 1252 snd_emu10k1_fx8010_tram_setup(emu, 0);
1251 snd_emu10k1_done(emu); 1253 snd_emu10k1_done(emu);
1252 snd_emu10k1_free_efx(emu); 1254 snd_emu10k1_free_efx(emu);
1253 } 1255 }
1254 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) { 1256 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) {
1255 /* Disable 48Volt power to Audio Dock */ 1257 /* Disable 48Volt power to Audio Dock */
1256 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0 ); 1258 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0);
1257 } 1259 }
1258 if (emu->emu1010.firmware_thread) 1260 if (emu->emu1010.firmware_thread)
1259 kthread_stop(emu->emu1010.firmware_thread); 1261 kthread_stop(emu->emu1010.firmware_thread);
@@ -1278,7 +1280,7 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1278#endif 1280#endif
1279 if (emu->port) 1281 if (emu->port)
1280 pci_release_regions(emu->pci); 1282 pci_release_regions(emu->pci);
1281 if (emu->card_capabilities->ca0151_chip) /* P16V */ 1283 if (emu->card_capabilities->ca0151_chip) /* P16V */
1282 snd_p16v_free(emu); 1284 snd_p16v_free(emu);
1283 pci_disable_device(emu->pci); 1285 pci_disable_device(emu->pci);
1284 kfree(emu); 1286 kfree(emu);
@@ -1292,21 +1294,6 @@ static int snd_emu10k1_dev_free(struct snd_device *device)
1292} 1294}
1293 1295
1294static struct snd_emu_chip_details emu_chip_details[] = { 1296static struct snd_emu_chip_details emu_chip_details[] = {
1295 /* Audigy 2 Value AC3 out does not work yet. Need to find out how to turn off interpolators.*/
1296 /* Tested by James@superbug.co.uk 3rd July 2005 */
1297 /* DSP: CA0108-IAT
1298 * DAC: CS4382-KQ
1299 * ADC: Philips 1361T
1300 * AC97: STAC9750
1301 * CA0151: None
1302 */
1303 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
1304 .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
1305 .id = "Audigy2",
1306 .emu10k2_chip = 1,
1307 .ca0108_chip = 1,
1308 .spk71 = 1,
1309 .ac97_chip = 1} ,
1310 /* Audigy4 (Not PRO) SB0610 */ 1297 /* Audigy4 (Not PRO) SB0610 */
1311 /* Tested by James@superbug.co.uk 4th April 2006 */ 1298 /* Tested by James@superbug.co.uk 4th April 2006 */
1312 /* A_IOCFG bits 1299 /* A_IOCFG bits
@@ -1346,20 +1333,37 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1346 * CA0151: None 1333 * CA0151: None
1347 */ 1334 */
1348 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10211102, 1335 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10211102,
1349 .driver = "Audigy2", .name = "Audigy 4 [SB0610]", 1336 .driver = "Audigy2", .name = "SB Audigy 4 [SB0610]",
1350 .id = "Audigy2", 1337 .id = "Audigy2",
1351 .emu10k2_chip = 1, 1338 .emu10k2_chip = 1,
1352 .ca0108_chip = 1, 1339 .ca0108_chip = 1,
1353 .spk71 = 1, 1340 .spk71 = 1,
1354 .adc_1361t = 1, /* 24 bit capture instead of 16bit */ 1341 .adc_1361t = 1, /* 24 bit capture instead of 16bit */
1355 .ac97_chip = 1} , 1342 .ac97_chip = 1} ,
1343 /* Audigy 2 Value AC3 out does not work yet.
1344 * Need to find out how to turn off interpolators.
1345 */
1346 /* Tested by James@superbug.co.uk 3rd July 2005 */
1347 /* DSP: CA0108-IAT
1348 * DAC: CS4382-KQ
1349 * ADC: Philips 1361T
1350 * AC97: STAC9750
1351 * CA0151: None
1352 */
1353 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
1354 .driver = "Audigy2", .name = "SB Audigy 2 Value [SB0400]",
1355 .id = "Audigy2",
1356 .emu10k2_chip = 1,
1357 .ca0108_chip = 1,
1358 .spk71 = 1,
1359 .ac97_chip = 1} ,
1356 /* Audigy 2 ZS Notebook Cardbus card.*/ 1360 /* Audigy 2 ZS Notebook Cardbus card.*/
1357 /* Tested by James@superbug.co.uk 6th November 2006 */ 1361 /* Tested by James@superbug.co.uk 6th November 2006 */
1358 /* Audio output 7.1/Headphones working. 1362 /* Audio output 7.1/Headphones working.
1359 * Digital output working. (AC3 not checked, only PCM) 1363 * Digital output working. (AC3 not checked, only PCM)
1360 * Audio Mic/Line inputs working. 1364 * Audio Mic/Line inputs working.
1361 * Digital input not tested. 1365 * Digital input not tested.
1362 */ 1366 */
1363 /* DSP: Tina2 1367 /* DSP: Tina2
1364 * DAC: Wolfson WM8768/WM8568 1368 * DAC: Wolfson WM8768/WM8568
1365 * ADC: Wolfson WM8775 1369 * ADC: Wolfson WM8775
@@ -1386,7 +1390,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1386 * 1390 *
1387 */ 1391 */
1388 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102, 1392 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
1389 .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]", 1393 .driver = "Audigy2", .name = "SB Audigy 2 ZS Notebook [SB0530]",
1390 .id = "Audigy2", 1394 .id = "Audigy2",
1391 .emu10k2_chip = 1, 1395 .emu10k2_chip = 1,
1392 .ca0108_chip = 1, 1396 .ca0108_chip = 1,
@@ -1396,7 +1400,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1396 .spk71 = 1} , 1400 .spk71 = 1} ,
1397 /* Tested by James@superbug.co.uk 4th Nov 2007. */ 1401 /* Tested by James@superbug.co.uk 4th Nov 2007. */
1398 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x42011102, 1402 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x42011102,
1399 .driver = "Audigy2", .name = "E-mu 1010 Notebook [MAEM8950]", 1403 .driver = "Audigy2", .name = "E-mu 1010 Notebook [MAEM8950]",
1400 .id = "EMU1010", 1404 .id = "EMU1010",
1401 .emu10k2_chip = 1, 1405 .emu10k2_chip = 1,
1402 .ca0108_chip = 1, 1406 .ca0108_chip = 1,
@@ -1404,47 +1408,49 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1404 .spk71 = 1 , 1408 .spk71 = 1 ,
1405 .emu_model = EMU_MODEL_EMU1616}, 1409 .emu_model = EMU_MODEL_EMU1616},
1406 /* Tested by James@superbug.co.uk 4th Nov 2007. */ 1410 /* Tested by James@superbug.co.uk 4th Nov 2007. */
1411 /* This is MAEM8960, 0202 is MAEM 8980 */
1407 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40041102, 1412 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40041102,
1408 .driver = "Audigy2", .name = "E-mu 1010b PCI [MAEM????]", 1413 .driver = "Audigy2", .name = "E-mu 1010b PCI [MAEM8960]",
1409 .id = "EMU1010", 1414 .id = "EMU1010",
1410 .emu10k2_chip = 1, 1415 .emu10k2_chip = 1,
1411 .ca0108_chip = 1, 1416 .ca0108_chip = 1,
1412 .spk71 = 1, 1417 .spk71 = 1,
1413 .emu_model = EMU_MODEL_EMU1010B}, 1418 .emu_model = EMU_MODEL_EMU1010B}, /* EMU 1010 new revision */
1414 /* Tested by James@superbug.co.uk 8th July 2005. */ 1419 /* Tested by James@superbug.co.uk 8th July 2005. */
1420 /* This is MAEM8810, 0202 is MAEM8820 */
1415 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102, 1421 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
1416 .driver = "Audigy2", .name = "E-mu 1010 [4001]", 1422 .driver = "Audigy2", .name = "E-mu 1010 [MAEM8810]",
1417 .id = "EMU1010", 1423 .id = "EMU1010",
1418 .emu10k2_chip = 1, 1424 .emu10k2_chip = 1,
1419 .ca0102_chip = 1, 1425 .ca0102_chip = 1,
1420 .spk71 = 1, 1426 .spk71 = 1,
1421 .emu_model = EMU_MODEL_EMU1010}, /* Emu 1010 */ 1427 .emu_model = EMU_MODEL_EMU1010}, /* EMU 1010 old revision */
1422 /* EMU0404b */ 1428 /* EMU0404b */
1423 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40021102, 1429 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40021102,
1424 .driver = "Audigy2", .name = "E-mu 0404b [4002]", 1430 .driver = "Audigy2", .name = "E-mu 0404b PCI [MAEM8852]",
1425 .id = "EMU0404", 1431 .id = "EMU0404",
1426 .emu10k2_chip = 1, 1432 .emu10k2_chip = 1,
1427 .ca0108_chip = 1, 1433 .ca0108_chip = 1,
1428 .spk71 = 1, 1434 .spk71 = 1,
1429 .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 */ 1435 .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 new revision */
1430 /* Tested by James@superbug.co.uk 20-3-2007. */ 1436 /* Tested by James@superbug.co.uk 20-3-2007. */
1431 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40021102, 1437 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40021102,
1432 .driver = "Audigy2", .name = "E-mu 0404 [4002]", 1438 .driver = "Audigy2", .name = "E-mu 0404 [MAEM8850]",
1433 .id = "EMU0404", 1439 .id = "EMU0404",
1434 .emu10k2_chip = 1, 1440 .emu10k2_chip = 1,
1435 .ca0102_chip = 1, 1441 .ca0102_chip = 1,
1436 .spk71 = 1, 1442 .spk71 = 1,
1437 .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 */ 1443 .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 */
1438 /* Audigy4 (Not PRO) SB0610 */ 1444 /* Note that all E-mu cards require kernel 2.6 or newer. */
1439 {.vendor = 0x1102, .device = 0x0008, 1445 {.vendor = 0x1102, .device = 0x0008,
1440 .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]", 1446 .driver = "Audigy2", .name = "SB Audigy 2 Value [Unknown]",
1441 .id = "Audigy2", 1447 .id = "Audigy2",
1442 .emu10k2_chip = 1, 1448 .emu10k2_chip = 1,
1443 .ca0108_chip = 1, 1449 .ca0108_chip = 1,
1444 .ac97_chip = 1} , 1450 .ac97_chip = 1} ,
1445 /* Tested by James@superbug.co.uk 3rd July 2005 */ 1451 /* Tested by James@superbug.co.uk 3rd July 2005 */
1446 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102, 1452 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
1447 .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]", 1453 .driver = "Audigy2", .name = "SB Audigy 4 PRO [SB0380]",
1448 .id = "Audigy2", 1454 .id = "Audigy2",
1449 .emu10k2_chip = 1, 1455 .emu10k2_chip = 1,
1450 .ca0102_chip = 1, 1456 .ca0102_chip = 1,
@@ -1457,7 +1463,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1457 * Just like 0x20021102 1463 * Just like 0x20021102
1458 */ 1464 */
1459 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102, 1465 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102,
1460 .driver = "Audigy2", .name = "Audigy 2 [SB0350b]", 1466 .driver = "Audigy2", .name = "SB Audigy 2 [SB0350b]",
1461 .id = "Audigy2", 1467 .id = "Audigy2",
1462 .emu10k2_chip = 1, 1468 .emu10k2_chip = 1,
1463 .ca0102_chip = 1, 1469 .ca0102_chip = 1,
@@ -1467,7 +1473,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1467 .invert_shared_spdif = 1, /* digital/analog switch swapped */ 1473 .invert_shared_spdif = 1, /* digital/analog switch swapped */
1468 .ac97_chip = 1} , 1474 .ac97_chip = 1} ,
1469 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102, 1475 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
1470 .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]", 1476 .driver = "Audigy2", .name = "SB Audigy 2 ZS [SB0350]",
1471 .id = "Audigy2", 1477 .id = "Audigy2",
1472 .emu10k2_chip = 1, 1478 .emu10k2_chip = 1,
1473 .ca0102_chip = 1, 1479 .ca0102_chip = 1,
@@ -1477,7 +1483,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1477 .invert_shared_spdif = 1, /* digital/analog switch swapped */ 1483 .invert_shared_spdif = 1, /* digital/analog switch swapped */
1478 .ac97_chip = 1} , 1484 .ac97_chip = 1} ,
1479 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102, 1485 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
1480 .driver = "Audigy2", .name = "Audigy 2 ZS [2001]", 1486 .driver = "Audigy2", .name = "SB Audigy 2 ZS [SB0360]",
1481 .id = "Audigy2", 1487 .id = "Audigy2",
1482 .emu10k2_chip = 1, 1488 .emu10k2_chip = 1,
1483 .ca0102_chip = 1, 1489 .ca0102_chip = 1,
@@ -1495,7 +1501,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1495 * CA0151: Yes 1501 * CA0151: Yes
1496 */ 1502 */
1497 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102, 1503 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
1498 .driver = "Audigy2", .name = "Audigy 2 [SB0240]", 1504 .driver = "Audigy2", .name = "SB Audigy 2 [SB0240]",
1499 .id = "Audigy2", 1505 .id = "Audigy2",
1500 .emu10k2_chip = 1, 1506 .emu10k2_chip = 1,
1501 .ca0102_chip = 1, 1507 .ca0102_chip = 1,
@@ -1505,7 +1511,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1505 .adc_1361t = 1, /* 24 bit capture instead of 16bit */ 1511 .adc_1361t = 1, /* 24 bit capture instead of 16bit */
1506 .ac97_chip = 1} , 1512 .ac97_chip = 1} ,
1507 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102, 1513 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
1508 .driver = "Audigy2", .name = "Audigy 2 EX [1005]", 1514 .driver = "Audigy2", .name = "SB Audigy 2 Platinum EX [SB0280]",
1509 .id = "Audigy2", 1515 .id = "Audigy2",
1510 .emu10k2_chip = 1, 1516 .emu10k2_chip = 1,
1511 .ca0102_chip = 1, 1517 .ca0102_chip = 1,
@@ -1515,7 +1521,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1515 /* Dell OEM/Creative Labs Audigy 2 ZS */ 1521 /* Dell OEM/Creative Labs Audigy 2 ZS */
1516 /* See ALSA bug#1365 */ 1522 /* See ALSA bug#1365 */
1517 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10031102, 1523 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10031102,
1518 .driver = "Audigy2", .name = "Audigy 2 ZS [SB0353]", 1524 .driver = "Audigy2", .name = "SB Audigy 2 ZS [SB0353]",
1519 .id = "Audigy2", 1525 .id = "Audigy2",
1520 .emu10k2_chip = 1, 1526 .emu10k2_chip = 1,
1521 .ca0102_chip = 1, 1527 .ca0102_chip = 1,
@@ -1524,7 +1530,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1524 .spdif_bug = 1, 1530 .spdif_bug = 1,
1525 .ac97_chip = 1} , 1531 .ac97_chip = 1} ,
1526 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102, 1532 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
1527 .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]", 1533 .driver = "Audigy2", .name = "SB Audigy 2 Platinum [SB0240P]",
1528 .id = "Audigy2", 1534 .id = "Audigy2",
1529 .emu10k2_chip = 1, 1535 .emu10k2_chip = 1,
1530 .ca0102_chip = 1, 1536 .ca0102_chip = 1,
@@ -1535,7 +1541,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1535 .adc_1361t = 1, /* 24 bit capture instead of 16bit. Fixes ALSA bug#324 */ 1541 .adc_1361t = 1, /* 24 bit capture instead of 16bit. Fixes ALSA bug#324 */
1536 .ac97_chip = 1} , 1542 .ac97_chip = 1} ,
1537 {.vendor = 0x1102, .device = 0x0004, .revision = 0x04, 1543 {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
1538 .driver = "Audigy2", .name = "Audigy 2 [Unknown]", 1544 .driver = "Audigy2", .name = "SB Audigy 2 [Unknown]",
1539 .id = "Audigy2", 1545 .id = "Audigy2",
1540 .emu10k2_chip = 1, 1546 .emu10k2_chip = 1,
1541 .ca0102_chip = 1, 1547 .ca0102_chip = 1,
@@ -1543,78 +1549,79 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1543 .spdif_bug = 1, 1549 .spdif_bug = 1,
1544 .ac97_chip = 1} , 1550 .ac97_chip = 1} ,
1545 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102, 1551 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
1546 .driver = "Audigy", .name = "Audigy 1 [SB0090]", 1552 .driver = "Audigy", .name = "SB Audigy 1 [SB0092]",
1547 .id = "Audigy", 1553 .id = "Audigy",
1548 .emu10k2_chip = 1, 1554 .emu10k2_chip = 1,
1549 .ca0102_chip = 1, 1555 .ca0102_chip = 1,
1550 .ac97_chip = 1} , 1556 .ac97_chip = 1} ,
1551 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102, 1557 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
1552 .driver = "Audigy", .name = "Audigy 1 ES [SB0160]", 1558 .driver = "Audigy", .name = "SB Audigy 1 ES [SB0160]",
1553 .id = "Audigy", 1559 .id = "Audigy",
1554 .emu10k2_chip = 1, 1560 .emu10k2_chip = 1,
1555 .ca0102_chip = 1, 1561 .ca0102_chip = 1,
1556 .spdif_bug = 1, 1562 .spdif_bug = 1,
1557 .ac97_chip = 1} , 1563 .ac97_chip = 1} ,
1558 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102, 1564 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
1559 .driver = "Audigy", .name = "Audigy 1 [SB0090]", 1565 .driver = "Audigy", .name = "SB Audigy 1 [SB0090]",
1560 .id = "Audigy", 1566 .id = "Audigy",
1561 .emu10k2_chip = 1, 1567 .emu10k2_chip = 1,
1562 .ca0102_chip = 1, 1568 .ca0102_chip = 1,
1563 .ac97_chip = 1} , 1569 .ac97_chip = 1} ,
1564 {.vendor = 0x1102, .device = 0x0004, 1570 {.vendor = 0x1102, .device = 0x0004,
1565 .driver = "Audigy", .name = "Audigy 1 [Unknown]", 1571 .driver = "Audigy", .name = "Audigy 1 [Unknown]",
1566 .id = "Audigy", 1572 .id = "Audigy",
1567 .emu10k2_chip = 1, 1573 .emu10k2_chip = 1,
1568 .ca0102_chip = 1, 1574 .ca0102_chip = 1,
1569 .ac97_chip = 1} , 1575 .ac97_chip = 1} ,
1570 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102, 1576 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
1571 .driver = "EMU10K1", .name = "SBLive! [SB0105]", 1577 .driver = "EMU10K1", .name = "SB Live! 5.1 [SB0220]",
1578 .id = "Live",
1579 .emu10k1_chip = 1,
1580 .ac97_chip = 1,
1581 .sblive51 = 1} ,
1582 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806b1102,
1583 .driver = "EMU10K1", .name = "SB Live! [SB0105]",
1572 .id = "Live", 1584 .id = "Live",
1573 .emu10k1_chip = 1, 1585 .emu10k1_chip = 1,
1574 .ac97_chip = 1, 1586 .ac97_chip = 1,
1575 .sblive51 = 1} , 1587 .sblive51 = 1} ,
1576 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102, 1588 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806a1102,
1577 .driver = "EMU10K1", .name = "SBLive! Value [SB0103]", 1589 .driver = "EMU10K1", .name = "SB Live! Value [SB0103]",
1578 .id = "Live", 1590 .id = "Live",
1579 .emu10k1_chip = 1, 1591 .emu10k1_chip = 1,
1580 .ac97_chip = 1, 1592 .ac97_chip = 1,
1581 .sblive51 = 1} , 1593 .sblive51 = 1} ,
1582 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102, 1594 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
1583 .driver = "EMU10K1", .name = "SBLive! Value [SB0101]", 1595 .driver = "EMU10K1", .name = "SB Live! Value [SB0101]",
1584 .id = "Live", 1596 .id = "Live",
1585 .emu10k1_chip = 1, 1597 .emu10k1_chip = 1,
1586 .ac97_chip = 1, 1598 .ac97_chip = 1,
1587 .sblive51 = 1} , 1599 .sblive51 = 1} ,
1588 /* Tested by ALSA bug#1680 26th December 2005 */ 1600 /* Tested by ALSA bug#1680 26th December 2005 */
1589 /* note: It really has SB0220 written on the card. */ 1601 /* note: It really has SB0220 written on the card, */
1602 /* but it's SB0228 according to kx.inf */
1590 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80661102, 1603 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80661102,
1591 .driver = "EMU10K1", .name = "SB Live 5.1 Dell OEM [SB0220]", 1604 .driver = "EMU10K1", .name = "SB Live! 5.1 Dell OEM [SB0228]",
1592 .id = "Live", 1605 .id = "Live",
1593 .emu10k1_chip = 1, 1606 .emu10k1_chip = 1,
1594 .ac97_chip = 1, 1607 .ac97_chip = 1,
1595 .sblive51 = 1} , 1608 .sblive51 = 1} ,
1596 /* Tested by Thomas Zehetbauer 27th Aug 2005 */ 1609 /* Tested by Thomas Zehetbauer 27th Aug 2005 */
1597 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102, 1610 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
1598 .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]", 1611 .driver = "EMU10K1", .name = "SB Live! 5.1 [SB0220]",
1599 .id = "Live",
1600 .emu10k1_chip = 1,
1601 .ac97_chip = 1,
1602 .sblive51 = 1} ,
1603 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
1604 .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
1605 .id = "Live", 1612 .id = "Live",
1606 .emu10k1_chip = 1, 1613 .emu10k1_chip = 1,
1607 .ac97_chip = 1, 1614 .ac97_chip = 1,
1608 .sblive51 = 1} , 1615 .sblive51 = 1} ,
1609 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102, 1616 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
1610 .driver = "EMU10K1", .name = "SB Live 5.1", 1617 .driver = "EMU10K1", .name = "SB Live! 5.1",
1611 .id = "Live", 1618 .id = "Live",
1612 .emu10k1_chip = 1, 1619 .emu10k1_chip = 1,
1613 .ac97_chip = 1, 1620 .ac97_chip = 1,
1614 .sblive51 = 1} , 1621 .sblive51 = 1} ,
1615 /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */ 1622 /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
1616 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102, 1623 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
1617 .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]", 1624 .driver = "EMU10K1", .name = "SB Live! 5.1 [SB0060]",
1618 .id = "Live", 1625 .id = "Live",
1619 .emu10k1_chip = 1, 1626 .emu10k1_chip = 1,
1620 .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum 1627 .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
@@ -1622,78 +1629,78 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1622 */ 1629 */
1623 .sblive51 = 1} , 1630 .sblive51 = 1} ,
1624 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102, 1631 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
1625 .driver = "EMU10K1", .name = "SBLive! Value [CT4850]", 1632 .driver = "EMU10K1", .name = "SB Live! Value [CT4850]",
1626 .id = "Live", 1633 .id = "Live",
1627 .emu10k1_chip = 1, 1634 .emu10k1_chip = 1,
1628 .ac97_chip = 1, 1635 .ac97_chip = 1,
1629 .sblive51 = 1} , 1636 .sblive51 = 1} ,
1630 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102, 1637 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
1631 .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]", 1638 .driver = "EMU10K1", .name = "SB Live! Platinum [CT4760P]",
1632 .id = "Live", 1639 .id = "Live",
1633 .emu10k1_chip = 1, 1640 .emu10k1_chip = 1,
1634 .ac97_chip = 1} , 1641 .ac97_chip = 1} ,
1635 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102, 1642 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
1636 .driver = "EMU10K1", .name = "SBLive! Value [CT4871]", 1643 .driver = "EMU10K1", .name = "SB Live! Value [CT4871]",
1637 .id = "Live", 1644 .id = "Live",
1638 .emu10k1_chip = 1, 1645 .emu10k1_chip = 1,
1639 .ac97_chip = 1, 1646 .ac97_chip = 1,
1640 .sblive51 = 1} , 1647 .sblive51 = 1} ,
1641 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102, 1648 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
1642 .driver = "EMU10K1", .name = "SBLive! Value [CT4831]", 1649 .driver = "EMU10K1", .name = "SB Live! Value [CT4831]",
1643 .id = "Live", 1650 .id = "Live",
1644 .emu10k1_chip = 1, 1651 .emu10k1_chip = 1,
1645 .ac97_chip = 1, 1652 .ac97_chip = 1,
1646 .sblive51 = 1} , 1653 .sblive51 = 1} ,
1647 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102, 1654 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
1648 .driver = "EMU10K1", .name = "SBLive! Value [CT4870]", 1655 .driver = "EMU10K1", .name = "SB Live! Value [CT4870]",
1649 .id = "Live", 1656 .id = "Live",
1650 .emu10k1_chip = 1, 1657 .emu10k1_chip = 1,
1651 .ac97_chip = 1, 1658 .ac97_chip = 1,
1652 .sblive51 = 1} , 1659 .sblive51 = 1} ,
1653 /* Tested by James@superbug.co.uk 3rd July 2005 */ 1660 /* Tested by James@superbug.co.uk 3rd July 2005 */
1654 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102, 1661 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
1655 .driver = "EMU10K1", .name = "SBLive! Value [CT4832]", 1662 .driver = "EMU10K1", .name = "SB Live! Value [CT4832]",
1656 .id = "Live", 1663 .id = "Live",
1657 .emu10k1_chip = 1, 1664 .emu10k1_chip = 1,
1658 .ac97_chip = 1, 1665 .ac97_chip = 1,
1659 .sblive51 = 1} , 1666 .sblive51 = 1} ,
1660 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102, 1667 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
1661 .driver = "EMU10K1", .name = "SBLive! Value [CT4830]", 1668 .driver = "EMU10K1", .name = "SB Live! Value [CT4830]",
1662 .id = "Live", 1669 .id = "Live",
1663 .emu10k1_chip = 1, 1670 .emu10k1_chip = 1,
1664 .ac97_chip = 1, 1671 .ac97_chip = 1,
1665 .sblive51 = 1} , 1672 .sblive51 = 1} ,
1666 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102, 1673 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
1667 .driver = "EMU10K1", .name = "SB PCI512 [CT4790]", 1674 .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
1668 .id = "Live", 1675 .id = "Live",
1669 .emu10k1_chip = 1, 1676 .emu10k1_chip = 1,
1670 .ac97_chip = 1, 1677 .ac97_chip = 1,
1671 .sblive51 = 1} , 1678 .sblive51 = 1} ,
1672 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102, 1679 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
1673 .driver = "EMU10K1", .name = "SBLive! Value [CT4780]", 1680 .driver = "EMU10K1", .name = "SB Live! Value [CT4780]",
1674 .id = "Live", 1681 .id = "Live",
1675 .emu10k1_chip = 1, 1682 .emu10k1_chip = 1,
1676 .ac97_chip = 1, 1683 .ac97_chip = 1,
1677 .sblive51 = 1} , 1684 .sblive51 = 1} ,
1678 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102, 1685 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
1679 .driver = "EMU10K1", .name = "E-mu APS [4001]", 1686 .driver = "EMU10K1", .name = "E-mu APS [PC545]",
1680 .id = "APS", 1687 .id = "APS",
1681 .emu10k1_chip = 1, 1688 .emu10k1_chip = 1,
1682 .ecard = 1} , 1689 .ecard = 1} ,
1683 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102, 1690 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
1684 .driver = "EMU10K1", .name = "SBLive! [CT4620]", 1691 .driver = "EMU10K1", .name = "SB Live! [CT4620]",
1685 .id = "Live", 1692 .id = "Live",
1686 .emu10k1_chip = 1, 1693 .emu10k1_chip = 1,
1687 .ac97_chip = 1, 1694 .ac97_chip = 1,
1688 .sblive51 = 1} , 1695 .sblive51 = 1} ,
1689 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102, 1696 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
1690 .driver = "EMU10K1", .name = "SBLive! Value [CT4670]", 1697 .driver = "EMU10K1", .name = "SB Live! Value [CT4670]",
1691 .id = "Live", 1698 .id = "Live",
1692 .emu10k1_chip = 1, 1699 .emu10k1_chip = 1,
1693 .ac97_chip = 1, 1700 .ac97_chip = 1,
1694 .sblive51 = 1} , 1701 .sblive51 = 1} ,
1695 {.vendor = 0x1102, .device = 0x0002, 1702 {.vendor = 0x1102, .device = 0x0002,
1696 .driver = "EMU10K1", .name = "SB Live [Unknown]", 1703 .driver = "EMU10K1", .name = "SB Live! [Unknown]",
1697 .id = "Live", 1704 .id = "Live",
1698 .emu10k1_chip = 1, 1705 .emu10k1_chip = 1,
1699 .ac97_chip = 1, 1706 .ac97_chip = 1,
@@ -1702,13 +1709,13 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1702}; 1709};
1703 1710
1704int __devinit snd_emu10k1_create(struct snd_card *card, 1711int __devinit snd_emu10k1_create(struct snd_card *card,
1705 struct pci_dev * pci, 1712 struct pci_dev *pci,
1706 unsigned short extin_mask, 1713 unsigned short extin_mask,
1707 unsigned short extout_mask, 1714 unsigned short extout_mask,
1708 long max_cache_bytes, 1715 long max_cache_bytes,
1709 int enable_ir, 1716 int enable_ir,
1710 uint subsystem, 1717 uint subsystem,
1711 struct snd_emu10k1 ** remu) 1718 struct snd_emu10k1 **remu)
1712{ 1719{
1713 struct snd_emu10k1 *emu; 1720 struct snd_emu10k1 *emu;
1714 int idx, err; 1721 int idx, err;
@@ -1718,11 +1725,12 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
1718 static struct snd_device_ops ops = { 1725 static struct snd_device_ops ops = {
1719 .dev_free = snd_emu10k1_dev_free, 1726 .dev_free = snd_emu10k1_dev_free,
1720 }; 1727 };
1721 1728
1722 *remu = NULL; 1729 *remu = NULL;
1723 1730
1724 /* enable PCI device */ 1731 /* enable PCI device */
1725 if ((err = pci_enable_device(pci)) < 0) 1732 err = pci_enable_device(pci);
1733 if (err < 0)
1726 return err; 1734 return err;
1727 1735
1728 emu = kzalloc(sizeof(*emu), GFP_KERNEL); 1736 emu = kzalloc(sizeof(*emu), GFP_KERNEL);
@@ -1749,16 +1757,17 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
1749 emu->revision = pci->revision; 1757 emu->revision = pci->revision;
1750 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial); 1758 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
1751 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model); 1759 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
1752 snd_printdd("vendor=0x%x, device=0x%x, subsystem_vendor_id=0x%x, subsystem_id=0x%x\n",pci->vendor, pci->device, emu->serial, emu->model); 1760 snd_printdd("vendor = 0x%x, device = 0x%x, subsystem_vendor_id = 0x%x, subsystem_id = 0x%x\n", pci->vendor, pci->device, emu->serial, emu->model);
1753 1761
1754 for (c = emu_chip_details; c->vendor; c++) { 1762 for (c = emu_chip_details; c->vendor; c++) {
1755 if (c->vendor == pci->vendor && c->device == pci->device) { 1763 if (c->vendor == pci->vendor && c->device == pci->device) {
1756 if (subsystem) { 1764 if (subsystem) {
1757 if (c->subsystem && (c->subsystem == subsystem) ) { 1765 if (c->subsystem && (c->subsystem == subsystem))
1758 break; 1766 break;
1759 } else continue; 1767 else
1768 continue;
1760 } else { 1769 } else {
1761 if (c->subsystem && (c->subsystem != emu->serial) ) 1770 if (c->subsystem && (c->subsystem != emu->serial))
1762 continue; 1771 continue;
1763 if (c->revision && c->revision != emu->revision) 1772 if (c->revision && c->revision != emu->revision)
1764 continue; 1773 continue;
@@ -1774,14 +1783,18 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
1774 } 1783 }
1775 emu->card_capabilities = c; 1784 emu->card_capabilities = c;
1776 if (c->subsystem && !subsystem) 1785 if (c->subsystem && !subsystem)
1777 snd_printdd("Sound card name=%s\n", c->name); 1786 snd_printdd("Sound card name = %s\n", c->name);
1778 else if (subsystem) 1787 else if (subsystem)
1779 snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n", 1788 snd_printdd("Sound card name = %s, "
1780 c->name, pci->vendor, pci->device, emu->serial, c->subsystem); 1789 "vendor = 0x%x, device = 0x%x, subsystem = 0x%x. "
1781 else 1790 "Forced to subsytem = 0x%x\n", c->name,
1782 snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n", 1791 pci->vendor, pci->device, emu->serial, c->subsystem);
1783 c->name, pci->vendor, pci->device, emu->serial); 1792 else
1784 1793 snd_printdd("Sound card name = %s, "
1794 "vendor = 0x%x, device = 0x%x, subsystem = 0x%x.\n",
1795 c->name, pci->vendor, pci->device,
1796 emu->serial);
1797
1785 if (!*card->id && c->id) { 1798 if (!*card->id && c->id) {
1786 int i, n = 0; 1799 int i, n = 0;
1787 strlcpy(card->id, c->id, sizeof(card->id)); 1800 strlcpy(card->id, c->id, sizeof(card->id));
@@ -1815,7 +1828,8 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
1815 else 1828 else
1816 emu->gpr_base = FXGPREGBASE; 1829 emu->gpr_base = FXGPREGBASE;
1817 1830
1818 if ((err = pci_request_regions(pci, "EMU10K1")) < 0) { 1831 err = pci_request_regions(pci, "EMU10K1");
1832 if (err < 0) {
1819 kfree(emu); 1833 kfree(emu);
1820 pci_disable_device(pci); 1834 pci_disable_device(pci);
1821 return err; 1835 return err;
@@ -1862,21 +1876,25 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
1862 emu->enable_ir = enable_ir; 1876 emu->enable_ir = enable_ir;
1863 1877
1864 if (emu->card_capabilities->ca_cardbus_chip) { 1878 if (emu->card_capabilities->ca_cardbus_chip) {
1865 if ((err = snd_emu10k1_cardbus_init(emu)) < 0) 1879 err = snd_emu10k1_cardbus_init(emu);
1880 if (err < 0)
1866 goto error; 1881 goto error;
1867 } 1882 }
1868 if (emu->card_capabilities->ecard) { 1883 if (emu->card_capabilities->ecard) {
1869 if ((err = snd_emu10k1_ecard_init(emu)) < 0) 1884 err = snd_emu10k1_ecard_init(emu);
1885 if (err < 0)
1870 goto error; 1886 goto error;
1871 } else if (emu->card_capabilities->emu_model) { 1887 } else if (emu->card_capabilities->emu_model) {
1872 if ((err = snd_emu10k1_emu1010_init(emu)) < 0) { 1888 err = snd_emu10k1_emu1010_init(emu);
1873 snd_emu10k1_free(emu); 1889 if (err < 0) {
1874 return err; 1890 snd_emu10k1_free(emu);
1875 } 1891 return err;
1892 }
1876 } else { 1893 } else {
1877 /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version 1894 /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
1878 does not support this, it shouldn't do any harm */ 1895 does not support this, it shouldn't do any harm */
1879 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE); 1896 snd_emu10k1_ptr_write(emu, AC97SLOT, 0,
1897 AC97SLOT_CNTR|AC97SLOT_LFE);
1880 } 1898 }
1881 1899
1882 /* initialize TRAM setup */ 1900 /* initialize TRAM setup */
@@ -1916,7 +1934,7 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
1916 snd_emu10k1_synth_alloc(emu, 4096); 1934 snd_emu10k1_synth_alloc(emu, 4096);
1917 if (emu->reserved_page) 1935 if (emu->reserved_page)
1918 emu->reserved_page->map_locked = 1; 1936 emu->reserved_page->map_locked = 1;
1919 1937
1920 /* Clear silent pages and set up pointers */ 1938 /* Clear silent pages and set up pointers */
1921 memset(emu->silent_page.area, 0, PAGE_SIZE); 1939 memset(emu->silent_page.area, 0, PAGE_SIZE);
1922 silent_page = emu->silent_page.addr << 1; 1940 silent_page = emu->silent_page.addr << 1;
@@ -1929,19 +1947,23 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
1929 emu->voices[idx].number = idx; 1947 emu->voices[idx].number = idx;
1930 } 1948 }
1931 1949
1932 if ((err = snd_emu10k1_init(emu, enable_ir, 0)) < 0) 1950 err = snd_emu10k1_init(emu, enable_ir, 0);
1951 if (err < 0)
1933 goto error; 1952 goto error;
1934#ifdef CONFIG_PM 1953#ifdef CONFIG_PM
1935 if ((err = alloc_pm_buffer(emu)) < 0) 1954 err = alloc_pm_buffer(emu);
1955 if (err < 0)
1936 goto error; 1956 goto error;
1937#endif 1957#endif
1938 1958
1939 /* Initialize the effect engine */ 1959 /* Initialize the effect engine */
1940 if ((err = snd_emu10k1_init_efx(emu)) < 0) 1960 err = snd_emu10k1_init_efx(emu);
1961 if (err < 0)
1941 goto error; 1962 goto error;
1942 snd_emu10k1_audio_enable(emu); 1963 snd_emu10k1_audio_enable(emu);
1943 1964
1944 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0) 1965 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops);
1966 if (err < 0)
1945 goto error; 1967 goto error;
1946 1968
1947#ifdef CONFIG_PROC_FS 1969#ifdef CONFIG_PROC_FS
@@ -1981,7 +2003,7 @@ static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
1981 if (emu->audigy) 2003 if (emu->audigy)
1982 size += ARRAY_SIZE(saved_regs_audigy); 2004 size += ARRAY_SIZE(saved_regs_audigy);
1983 emu->saved_ptr = vmalloc(4 * NUM_G * size); 2005 emu->saved_ptr = vmalloc(4 * NUM_G * size);
1984 if (! emu->saved_ptr) 2006 if (!emu->saved_ptr)
1985 return -ENOMEM; 2007 return -ENOMEM;
1986 if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0) 2008 if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
1987 return -ENOMEM; 2009 return -ENOMEM;
@@ -2026,7 +2048,7 @@ void snd_emu10k1_resume_init(struct snd_emu10k1 *emu)
2026 if (emu->card_capabilities->ecard) 2048 if (emu->card_capabilities->ecard)
2027 snd_emu10k1_ecard_init(emu); 2049 snd_emu10k1_ecard_init(emu);
2028 else if (emu->card_capabilities->emu_model) 2050 else if (emu->card_capabilities->emu_model)
2029 snd_emu10k1_emu1010_init(emu); 2051 snd_emu10k1_emu1010_init(emu);
2030 else 2052 else
2031 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE); 2053 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
2032 snd_emu10k1_init(emu, emu->enable_ir, 1); 2054 snd_emu10k1_init(emu, emu->enable_ir, 1);
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index f34bbfb705f5..b0fb6c917c38 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -1639,6 +1639,45 @@ static struct snd_kcontrol_new snd_audigy_shared_spdif __devinitdata =
1639 .put = snd_emu10k1_shared_spdif_put 1639 .put = snd_emu10k1_shared_spdif_put
1640}; 1640};
1641 1641
1642/* workaround for too low volume on Audigy due to 16bit/24bit conversion */
1643
1644#define snd_audigy_capture_boost_info snd_ctl_boolean_mono_info
1645
1646static int snd_audigy_capture_boost_get(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_value *ucontrol)
1648{
1649 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1650 unsigned int val;
1651
1652 /* FIXME: better to use a cached version */
1653 val = snd_ac97_read(emu->ac97, AC97_REC_GAIN);
1654 ucontrol->value.integer.value[0] = !!val;
1655 return 0;
1656}
1657
1658static int snd_audigy_capture_boost_put(struct snd_kcontrol *kcontrol,
1659 struct snd_ctl_elem_value *ucontrol)
1660{
1661 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1662 unsigned int val;
1663
1664 if (ucontrol->value.integer.value[0])
1665 val = 0x0f0f;
1666 else
1667 val = 0;
1668 return snd_ac97_update(emu->ac97, AC97_REC_GAIN, val);
1669}
1670
1671static struct snd_kcontrol_new snd_audigy_capture_boost __devinitdata =
1672{
1673 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1674 .name = "Analog Capture Boost",
1675 .info = snd_audigy_capture_boost_info,
1676 .get = snd_audigy_capture_boost_get,
1677 .put = snd_audigy_capture_boost_put
1678};
1679
1680
1642/* 1681/*
1643 */ 1682 */
1644static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97) 1683static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
@@ -2087,5 +2126,12 @@ int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
2087 } 2126 }
2088 } 2127 }
2089 2128
2129 if (emu->card_capabilities->ac97_chip && emu->audigy) {
2130 err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_capture_boost,
2131 emu));
2132 if (err < 0)
2133 return err;
2134 }
2135
2090 return 0; 2136 return 0;
2091} 2137}
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 20ee7599600b..e9c3794bbcb8 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -1953,7 +1953,7 @@ static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id)
1953 outw(inw(chip->io_port + 4) & 1, chip->io_port + 4); 1953 outw(inw(chip->io_port + 4) & 1, chip->io_port + 4);
1954 1954
1955 if (event & ESM_HWVOL_IRQ) 1955 if (event & ESM_HWVOL_IRQ)
1956 tasklet_hi_schedule(&chip->hwvol_tq); /* we'll do this later */ 1956 tasklet_schedule(&chip->hwvol_tq); /* we'll do this later */
1957 1957
1958 /* else ack 'em all, i imagine */ 1958 /* else ack 'em all, i imagine */
1959 outb(0xFF, chip->io_port + 0x1A); 1959 outb(0xFF, chip->io_port + 0x1A);
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
new file mode 100644
index 000000000000..eb2a19b894a0
--- /dev/null
+++ b/sound/pci/hda/Kconfig
@@ -0,0 +1,188 @@
1menuconfig SND_HDA_INTEL
2 tristate "Intel HD Audio"
3 select SND_PCM
4 select SND_VMASTER
5 select SND_JACK if INPUT=y || INPUT=SND
6 help
7 Say Y here to include support for Intel "High Definition
8 Audio" (Azalia) and its compatible devices.
9
10 This option enables the HD-audio controller. Don't forget
11 to choose the appropriate codec options below.
12
13 To compile this driver as a module, choose M here: the module
14 will be called snd-hda-intel.
15
16if SND_HDA_INTEL
17
18config SND_HDA_HWDEP
19 bool "Build hwdep interface for HD-audio driver"
20 select SND_HWDEP
21 help
22 Say Y here to build a hwdep interface for HD-audio driver.
23 This interface can be used for out-of-band communication
24 with codecs for debugging purposes.
25
26config SND_HDA_RECONFIG
27 bool "Allow dynamic codec reconfiguration (EXPERIMENTAL)"
28 depends on SND_HDA_HWDEP && EXPERIMENTAL
29 help
30 Say Y here to enable the HD-audio codec re-configuration feature.
31 This adds the sysfs interfaces to allow user to clear the whole
32 codec configuration, change the codec setup, add extra verbs,
33 and re-configure the codec dynamically.
34
35config SND_HDA_INPUT_BEEP
36 bool "Support digital beep via input layer"
37 depends on INPUT=y || INPUT=SND_HDA_INTEL
38 help
39 Say Y here to build a digital beep interface for HD-audio
40 driver. This interface is used to generate digital beeps.
41
42config SND_HDA_CODEC_REALTEK
43 bool "Build Realtek HD-audio codec support"
44 default y
45 help
46 Say Y here to include Realtek HD-audio codec support in
47 snd-hda-intel driver, such as ALC880.
48
49 When the HD-audio driver is built as a module, the codec
50 support code is also built as another module,
51 snd-hda-codec-realtek.
52 This module is automatically loaded at probing.
53
54config SND_HDA_CODEC_ANALOG
55 bool "Build Analog Device HD-audio codec support"
56 default y
57 help
58 Say Y here to include Analog Device HD-audio codec support in
59 snd-hda-intel driver, such as AD1986A.
60
61 When the HD-audio driver is built as a module, the codec
62 support code is also built as another module,
63 snd-hda-codec-analog.
64 This module is automatically loaded at probing.
65
66config SND_HDA_CODEC_SIGMATEL
67 bool "Build IDT/Sigmatel HD-audio codec support"
68 default y
69 help
70 Say Y here to include IDT (Sigmatel) HD-audio codec support in
71 snd-hda-intel driver, such as STAC9200.
72
73 When the HD-audio driver is built as a module, the codec
74 support code is also built as another module,
75 snd-hda-codec-idt.
76 This module is automatically loaded at probing.
77
78config SND_HDA_CODEC_VIA
79 bool "Build VIA HD-audio codec support"
80 default y
81 help
82 Say Y here to include VIA HD-audio codec support in
83 snd-hda-intel driver, such as VT1708.
84
85 When the HD-audio driver is built as a module, the codec
86 support code is also built as another module,
87 snd-hda-codec-via.
88 This module is automatically loaded at probing.
89
90config SND_HDA_CODEC_ATIHDMI
91 bool "Build ATI HDMI HD-audio codec support"
92 default y
93 help
94 Say Y here to include ATI HDMI HD-audio codec support in
95 snd-hda-intel driver, such as ATI RS600 HDMI.
96
97 When the HD-audio driver is built as a module, the codec
98 support code is also built as another module,
99 snd-hda-codec-atihdmi.
100 This module is automatically loaded at probing.
101
102config SND_HDA_CODEC_NVHDMI
103 bool "Build NVIDIA HDMI HD-audio codec support"
104 default y
105 help
106 Say Y here to include NVIDIA HDMI HD-audio codec support in
107 snd-hda-intel driver, such as NVIDIA MCP78 HDMI.
108
109 When the HD-audio driver is built as a module, the codec
110 support code is also built as another module,
111 snd-hda-codec-nvhdmi.
112 This module is automatically loaded at probing.
113
114config SND_HDA_CODEC_INTELHDMI
115 bool "Build INTEL HDMI HD-audio codec support"
116 default y
117 help
118 Say Y here to include INTEL HDMI HD-audio codec support in
119 snd-hda-intel driver, such as Eaglelake integrated HDMI.
120
121 When the HD-audio driver is built as a module, the codec
122 support code is also built as another module,
123 snd-hda-codec-intelhdmi.
124 This module is automatically loaded at probing.
125
126config SND_HDA_ELD
127 def_bool y
128 depends on SND_HDA_CODEC_INTELHDMI
129
130config SND_HDA_CODEC_CONEXANT
131 bool "Build Conexant HD-audio codec support"
132 default y
133 help
134 Say Y here to include Conexant HD-audio codec support in
135 snd-hda-intel driver, such as CX20549.
136
137 When the HD-audio driver is built as a module, the codec
138 support code is also built as another module,
139 snd-hda-codec-conexant.
140 This module is automatically loaded at probing.
141
142config SND_HDA_CODEC_CMEDIA
143 bool "Build C-Media HD-audio codec support"
144 default y
145 help
146 Say Y here to include C-Media HD-audio codec support in
147 snd-hda-intel driver, such as CMI9880.
148
149 When the HD-audio driver is built as a module, the codec
150 support code is also built as another module,
151 snd-hda-codec-cmedia.
152 This module is automatically loaded at probing.
153
154config SND_HDA_CODEC_SI3054
155 bool "Build Silicon Labs 3054 HD-modem codec support"
156 default y
157 help
158 Say Y here to include Silicon Labs 3054 HD-modem codec
159 (and compatibles) support in snd-hda-intel driver.
160
161 When the HD-audio driver is built as a module, the codec
162 support code is also built as another module,
163 snd-hda-codec-si3054.
164 This module is automatically loaded at probing.
165
166config SND_HDA_GENERIC
167 bool "Enable generic HD-audio codec parser"
168 default y
169 help
170 Say Y here to enable the generic HD-audio codec parser
171 in snd-hda-intel driver.
172
173config SND_HDA_POWER_SAVE
174 bool "Aggressive power-saving on HD-audio"
175 help
176 Say Y here to enable more aggressive power-saving mode on
177 HD-audio driver. The power-saving timeout can be configured
178 via power_save option or over sysfs on-the-fly.
179
180config SND_HDA_POWER_SAVE_DEFAULT
181 int "Default time-out for HD-audio power-save mode"
182 depends on SND_HDA_POWER_SAVE
183 default 0
184 help
185 The default time-out value in seconds for HD-audio automatic
186 power-save mode. 0 means to disable the power-save mode.
187
188endif
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 1980c6d207e7..50f9d0967251 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -1,20 +1,59 @@
1snd-hda-intel-y := hda_intel.o 1snd-hda-intel-objs := hda_intel.o
2# since snd-hda-intel is the only driver using hda-codec,
3# merge it into a single module although it was originally
4# designed to be individual modules
5snd-hda-intel-y += hda_codec.o
6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o
7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-intel-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
9snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
10snd-hda-intel-$(CONFIG_SND_HDA_CODEC_REALTEK) += patch_realtek.o
11snd-hda-intel-$(CONFIG_SND_HDA_CODEC_CMEDIA) += patch_cmedia.o
12snd-hda-intel-$(CONFIG_SND_HDA_CODEC_ANALOG) += patch_analog.o
13snd-hda-intel-$(CONFIG_SND_HDA_CODEC_SIGMATEL) += patch_sigmatel.o
14snd-hda-intel-$(CONFIG_SND_HDA_CODEC_SI3054) += patch_si3054.o
15snd-hda-intel-$(CONFIG_SND_HDA_CODEC_ATIHDMI) += patch_atihdmi.o
16snd-hda-intel-$(CONFIG_SND_HDA_CODEC_CONEXANT) += patch_conexant.o
17snd-hda-intel-$(CONFIG_SND_HDA_CODEC_VIA) += patch_via.o
18snd-hda-intel-$(CONFIG_SND_HDA_CODEC_NVHDMI) += patch_nvhdmi.o
19 2
3snd-hda-codec-y := hda_codec.o
4snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
5snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
6# snd-hda-codec-$(CONFIG_SND_HDA_ELD) += hda_eld.o
7snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
9
10snd-hda-codec-realtek-objs := patch_realtek.o
11snd-hda-codec-cmedia-objs := patch_cmedia.o
12snd-hda-codec-analog-objs := patch_analog.o
13snd-hda-codec-idt-objs := patch_sigmatel.o
14snd-hda-codec-si3054-objs := patch_si3054.o
15snd-hda-codec-atihdmi-objs := patch_atihdmi.o
16snd-hda-codec-conexant-objs := patch_conexant.o
17snd-hda-codec-via-objs := patch_via.o
18snd-hda-codec-nvhdmi-objs := patch_nvhdmi.o
19snd-hda-codec-intelhdmi-objs := patch_intelhdmi.o hda_eld.o
20
21# common driver
22obj-$(CONFIG_SND_HDA_INTEL) := snd-hda-codec.o
23
24# codec drivers (note: CONFIG_SND_HDA_CODEC_XXX are booleans)
25ifdef CONFIG_SND_HDA_CODEC_REALTEK
26obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-realtek.o
27endif
28ifdef CONFIG_SND_HDA_CODEC_CMEDIA
29obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-cmedia.o
30endif
31ifdef CONFIG_SND_HDA_CODEC_ANALOG
32obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-analog.o
33endif
34ifdef CONFIG_SND_HDA_CODEC_SIGMATEL
35obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-idt.o
36endif
37ifdef CONFIG_SND_HDA_CODEC_SI3054
38obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-si3054.o
39endif
40ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
41obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-atihdmi.o
42endif
43ifdef CONFIG_SND_HDA_CODEC_CONEXANT
44obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-conexant.o
45endif
46ifdef CONFIG_SND_HDA_CODEC_VIA
47obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-via.o
48endif
49ifdef CONFIG_SND_HDA_CODEC_NVHDMI
50obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-nvhdmi.o
51endif
52ifdef CONFIG_SND_HDA_CODEC_INTELHDMI
53obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-codec-intelhdmi.o
54endif
55
56# this must be the last entry after codec drivers;
57# otherwise the codec patches won't be hooked before the PCI probe
58# when built in kernel
20obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-intel.o 59obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-intel.o
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 3ecd7e797dee..e00421c0d8ba 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -128,6 +128,7 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
128 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep); 128 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
129 return 0; 129 return 0;
130} 130}
131EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device);
131 132
132void snd_hda_detach_beep_device(struct hda_codec *codec) 133void snd_hda_detach_beep_device(struct hda_codec *codec)
133{ 134{
@@ -140,3 +141,4 @@ void snd_hda_detach_beep_device(struct hda_codec *codec)
140 kfree(beep); 141 kfree(beep);
141 } 142 }
142} 143}
144EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device);
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index eb9164176dab..e16cf63821ae 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -31,15 +31,6 @@
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include "hda_local.h" 32#include "hda_local.h"
33#include <sound/hda_hwdep.h> 33#include <sound/hda_hwdep.h>
34#include "hda_patch.h" /* codec presets */
35
36#ifdef CONFIG_SND_HDA_POWER_SAVE
37/* define this option here to hide as static */
38static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
39module_param(power_save, int, 0644);
40MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
41 "(in second, 0 = disable).");
42#endif
43 34
44/* 35/*
45 * vendor / preset table 36 * vendor / preset table
@@ -55,6 +46,7 @@ static struct hda_vendor_id hda_vendor_ids[] = {
55 { 0x1002, "ATI" }, 46 { 0x1002, "ATI" },
56 { 0x1057, "Motorola" }, 47 { 0x1057, "Motorola" },
57 { 0x1095, "Silicon Image" }, 48 { 0x1095, "Silicon Image" },
49 { 0x10de, "Nvidia" },
58 { 0x10ec, "Realtek" }, 50 { 0x10ec, "Realtek" },
59 { 0x1106, "VIA" }, 51 { 0x1106, "VIA" },
60 { 0x111d, "IDT" }, 52 { 0x111d, "IDT" },
@@ -66,40 +58,31 @@ static struct hda_vendor_id hda_vendor_ids[] = {
66 { 0x1854, "LG" }, 58 { 0x1854, "LG" },
67 { 0x1aec, "Wolfson Microelectronics" }, 59 { 0x1aec, "Wolfson Microelectronics" },
68 { 0x434d, "C-Media" }, 60 { 0x434d, "C-Media" },
61 { 0x8086, "Intel" },
69 { 0x8384, "SigmaTel" }, 62 { 0x8384, "SigmaTel" },
70 {} /* terminator */ 63 {} /* terminator */
71}; 64};
72 65
73static const struct hda_codec_preset *hda_preset_tables[] = { 66static DEFINE_MUTEX(preset_mutex);
74#ifdef CONFIG_SND_HDA_CODEC_REALTEK 67static LIST_HEAD(hda_preset_tables);
75 snd_hda_preset_realtek, 68
76#endif 69int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset)
77#ifdef CONFIG_SND_HDA_CODEC_CMEDIA 70{
78 snd_hda_preset_cmedia, 71 mutex_lock(&preset_mutex);
79#endif 72 list_add_tail(&preset->list, &hda_preset_tables);
80#ifdef CONFIG_SND_HDA_CODEC_ANALOG 73 mutex_unlock(&preset_mutex);
81 snd_hda_preset_analog, 74 return 0;
82#endif 75}
83#ifdef CONFIG_SND_HDA_CODEC_SIGMATEL 76EXPORT_SYMBOL_HDA(snd_hda_add_codec_preset);
84 snd_hda_preset_sigmatel, 77
85#endif 78int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset)
86#ifdef CONFIG_SND_HDA_CODEC_SI3054 79{
87 snd_hda_preset_si3054, 80 mutex_lock(&preset_mutex);
88#endif 81 list_del(&preset->list);
89#ifdef CONFIG_SND_HDA_CODEC_ATIHDMI 82 mutex_unlock(&preset_mutex);
90 snd_hda_preset_atihdmi, 83 return 0;
91#endif 84}
92#ifdef CONFIG_SND_HDA_CODEC_CONEXANT 85EXPORT_SYMBOL_HDA(snd_hda_delete_codec_preset);
93 snd_hda_preset_conexant,
94#endif
95#ifdef CONFIG_SND_HDA_CODEC_VIA
96 snd_hda_preset_via,
97#endif
98#ifdef CONFIG_SND_HDA_CODEC_NVHDMI
99 snd_hda_preset_nvhdmi,
100#endif
101 NULL
102};
103 86
104#ifdef CONFIG_SND_HDA_POWER_SAVE 87#ifdef CONFIG_SND_HDA_POWER_SAVE
105static void hda_power_work(struct work_struct *work); 88static void hda_power_work(struct work_struct *work);
@@ -108,6 +91,72 @@ static void hda_keep_power_on(struct hda_codec *codec);
108static inline void hda_keep_power_on(struct hda_codec *codec) {} 91static inline void hda_keep_power_on(struct hda_codec *codec) {}
109#endif 92#endif
110 93
94const char *snd_hda_get_jack_location(u32 cfg)
95{
96 static char *bases[7] = {
97 "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom",
98 };
99 static unsigned char specials_idx[] = {
100 0x07, 0x08,
101 0x17, 0x18, 0x19,
102 0x37, 0x38
103 };
104 static char *specials[] = {
105 "Rear Panel", "Drive Bar",
106 "Riser", "HDMI", "ATAPI",
107 "Mobile-In", "Mobile-Out"
108 };
109 int i;
110 cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT;
111 if ((cfg & 0x0f) < 7)
112 return bases[cfg & 0x0f];
113 for (i = 0; i < ARRAY_SIZE(specials_idx); i++) {
114 if (cfg == specials_idx[i])
115 return specials[i];
116 }
117 return "UNKNOWN";
118}
119EXPORT_SYMBOL_HDA(snd_hda_get_jack_location);
120
121const char *snd_hda_get_jack_connectivity(u32 cfg)
122{
123 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
124
125 return jack_locations[(cfg >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3];
126}
127EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity);
128
129const char *snd_hda_get_jack_type(u32 cfg)
130{
131 static char *jack_types[16] = {
132 "Line Out", "Speaker", "HP Out", "CD",
133 "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand",
134 "Line In", "Aux", "Mic", "Telephony",
135 "SPDIF In", "Digitial In", "Reserved", "Other"
136 };
137
138 return jack_types[(cfg & AC_DEFCFG_DEVICE)
139 >> AC_DEFCFG_DEVICE_SHIFT];
140}
141EXPORT_SYMBOL_HDA(snd_hda_get_jack_type);
142
143/*
144 * Compose a 32bit command word to be sent to the HD-audio controller
145 */
146static inline unsigned int
147make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
148 unsigned int verb, unsigned int parm)
149{
150 u32 val;
151
152 val = (u32)(codec->addr & 0x0f) << 28;
153 val |= (u32)direct << 27;
154 val |= (u32)nid << 20;
155 val |= verb << 8;
156 val |= parm;
157 return val;
158}
159
111/** 160/**
112 * snd_hda_codec_read - send a command and get the response 161 * snd_hda_codec_read - send a command and get the response
113 * @codec: the HDA codec 162 * @codec: the HDA codec
@@ -124,17 +173,21 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
124 int direct, 173 int direct,
125 unsigned int verb, unsigned int parm) 174 unsigned int verb, unsigned int parm)
126{ 175{
176 struct hda_bus *bus = codec->bus;
127 unsigned int res; 177 unsigned int res;
178
179 res = make_codec_cmd(codec, nid, direct, verb, parm);
128 snd_hda_power_up(codec); 180 snd_hda_power_up(codec);
129 mutex_lock(&codec->bus->cmd_mutex); 181 mutex_lock(&bus->cmd_mutex);
130 if (!codec->bus->ops.command(codec, nid, direct, verb, parm)) 182 if (!bus->ops.command(bus, res))
131 res = codec->bus->ops.get_response(codec); 183 res = bus->ops.get_response(bus);
132 else 184 else
133 res = (unsigned int)-1; 185 res = (unsigned int)-1;
134 mutex_unlock(&codec->bus->cmd_mutex); 186 mutex_unlock(&bus->cmd_mutex);
135 snd_hda_power_down(codec); 187 snd_hda_power_down(codec);
136 return res; 188 return res;
137} 189}
190EXPORT_SYMBOL_HDA(snd_hda_codec_read);
138 191
139/** 192/**
140 * snd_hda_codec_write - send a single command without waiting for response 193 * snd_hda_codec_write - send a single command without waiting for response
@@ -151,14 +204,19 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
151int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct, 204int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct,
152 unsigned int verb, unsigned int parm) 205 unsigned int verb, unsigned int parm)
153{ 206{
207 struct hda_bus *bus = codec->bus;
208 unsigned int res;
154 int err; 209 int err;
210
211 res = make_codec_cmd(codec, nid, direct, verb, parm);
155 snd_hda_power_up(codec); 212 snd_hda_power_up(codec);
156 mutex_lock(&codec->bus->cmd_mutex); 213 mutex_lock(&bus->cmd_mutex);
157 err = codec->bus->ops.command(codec, nid, direct, verb, parm); 214 err = bus->ops.command(bus, res);
158 mutex_unlock(&codec->bus->cmd_mutex); 215 mutex_unlock(&bus->cmd_mutex);
159 snd_hda_power_down(codec); 216 snd_hda_power_down(codec);
160 return err; 217 return err;
161} 218}
219EXPORT_SYMBOL_HDA(snd_hda_codec_write);
162 220
163/** 221/**
164 * snd_hda_sequence_write - sequence writes 222 * snd_hda_sequence_write - sequence writes
@@ -173,6 +231,7 @@ void snd_hda_sequence_write(struct hda_codec *codec, const struct hda_verb *seq)
173 for (; seq->nid; seq++) 231 for (; seq->nid; seq++)
174 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param); 232 snd_hda_codec_write(codec, seq->nid, 0, seq->verb, seq->param);
175} 233}
234EXPORT_SYMBOL_HDA(snd_hda_sequence_write);
176 235
177/** 236/**
178 * snd_hda_get_sub_nodes - get the range of sub nodes 237 * snd_hda_get_sub_nodes - get the range of sub nodes
@@ -194,6 +253,7 @@ int snd_hda_get_sub_nodes(struct hda_codec *codec, hda_nid_t nid,
194 *start_id = (parm >> 16) & 0x7fff; 253 *start_id = (parm >> 16) & 0x7fff;
195 return (int)(parm & 0x7fff); 254 return (int)(parm & 0x7fff);
196} 255}
256EXPORT_SYMBOL_HDA(snd_hda_get_sub_nodes);
197 257
198/** 258/**
199 * snd_hda_get_connections - get connection list 259 * snd_hda_get_connections - get connection list
@@ -282,6 +342,7 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
282 } 342 }
283 return conns; 343 return conns;
284} 344}
345EXPORT_SYMBOL_HDA(snd_hda_get_connections);
285 346
286 347
287/** 348/**
@@ -316,6 +377,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
316 377
317 return 0; 378 return 0;
318} 379}
380EXPORT_SYMBOL_HDA(snd_hda_queue_unsol_event);
319 381
320/* 382/*
321 * process queued unsolicited events 383 * process queued unsolicited events
@@ -345,7 +407,7 @@ static void process_unsol_events(struct work_struct *work)
345/* 407/*
346 * initialize unsolicited queue 408 * initialize unsolicited queue
347 */ 409 */
348static int __devinit init_unsol_queue(struct hda_bus *bus) 410static int init_unsol_queue(struct hda_bus *bus)
349{ 411{
350 struct hda_bus_unsolicited *unsol; 412 struct hda_bus_unsolicited *unsol;
351 413
@@ -391,9 +453,24 @@ static int snd_hda_bus_free(struct hda_bus *bus)
391static int snd_hda_bus_dev_free(struct snd_device *device) 453static int snd_hda_bus_dev_free(struct snd_device *device)
392{ 454{
393 struct hda_bus *bus = device->device_data; 455 struct hda_bus *bus = device->device_data;
456 bus->shutdown = 1;
394 return snd_hda_bus_free(bus); 457 return snd_hda_bus_free(bus);
395} 458}
396 459
460#ifdef CONFIG_SND_HDA_HWDEP
461static int snd_hda_bus_dev_register(struct snd_device *device)
462{
463 struct hda_bus *bus = device->device_data;
464 struct hda_codec *codec;
465 list_for_each_entry(codec, &bus->codec_list, list) {
466 snd_hda_hwdep_add_sysfs(codec);
467 }
468 return 0;
469}
470#else
471#define snd_hda_bus_dev_register NULL
472#endif
473
397/** 474/**
398 * snd_hda_bus_new - create a HDA bus 475 * snd_hda_bus_new - create a HDA bus
399 * @card: the card entry 476 * @card: the card entry
@@ -402,13 +479,14 @@ static int snd_hda_bus_dev_free(struct snd_device *device)
402 * 479 *
403 * Returns 0 if successful, or a negative error code. 480 * Returns 0 if successful, or a negative error code.
404 */ 481 */
405int __devinit snd_hda_bus_new(struct snd_card *card, 482int /*__devinit*/ snd_hda_bus_new(struct snd_card *card,
406 const struct hda_bus_template *temp, 483 const struct hda_bus_template *temp,
407 struct hda_bus **busp) 484 struct hda_bus **busp)
408{ 485{
409 struct hda_bus *bus; 486 struct hda_bus *bus;
410 int err; 487 int err;
411 static struct snd_device_ops dev_ops = { 488 static struct snd_device_ops dev_ops = {
489 .dev_register = snd_hda_bus_dev_register,
412 .dev_free = snd_hda_bus_dev_free, 490 .dev_free = snd_hda_bus_dev_free,
413 }; 491 };
414 492
@@ -430,6 +508,7 @@ int __devinit snd_hda_bus_new(struct snd_card *card,
430 bus->private_data = temp->private_data; 508 bus->private_data = temp->private_data;
431 bus->pci = temp->pci; 509 bus->pci = temp->pci;
432 bus->modelname = temp->modelname; 510 bus->modelname = temp->modelname;
511 bus->power_save = temp->power_save;
433 bus->ops = temp->ops; 512 bus->ops = temp->ops;
434 513
435 mutex_init(&bus->cmd_mutex); 514 mutex_init(&bus->cmd_mutex);
@@ -444,27 +523,42 @@ int __devinit snd_hda_bus_new(struct snd_card *card,
444 *busp = bus; 523 *busp = bus;
445 return 0; 524 return 0;
446} 525}
526EXPORT_SYMBOL_HDA(snd_hda_bus_new);
447 527
448#ifdef CONFIG_SND_HDA_GENERIC 528#ifdef CONFIG_SND_HDA_GENERIC
449#define is_generic_config(codec) \ 529#define is_generic_config(codec) \
450 (codec->bus->modelname && !strcmp(codec->bus->modelname, "generic")) 530 (codec->modelname && !strcmp(codec->modelname, "generic"))
451#else 531#else
452#define is_generic_config(codec) 0 532#define is_generic_config(codec) 0
453#endif 533#endif
454 534
535#ifdef MODULE
536#define HDA_MODREQ_MAX_COUNT 2 /* two request_modules()'s */
537#else
538#define HDA_MODREQ_MAX_COUNT 0 /* all presets are statically linked */
539#endif
540
455/* 541/*
456 * find a matching codec preset 542 * find a matching codec preset
457 */ 543 */
458static const struct hda_codec_preset __devinit * 544static const struct hda_codec_preset *
459find_codec_preset(struct hda_codec *codec) 545find_codec_preset(struct hda_codec *codec)
460{ 546{
461 const struct hda_codec_preset **tbl, *preset; 547 struct hda_codec_preset_list *tbl;
548 const struct hda_codec_preset *preset;
549 int mod_requested = 0;
462 550
463 if (is_generic_config(codec)) 551 if (is_generic_config(codec))
464 return NULL; /* use the generic parser */ 552 return NULL; /* use the generic parser */
465 553
466 for (tbl = hda_preset_tables; *tbl; tbl++) { 554 again:
467 for (preset = *tbl; preset->id; preset++) { 555 mutex_lock(&preset_mutex);
556 list_for_each_entry(tbl, &hda_preset_tables, list) {
557 if (!try_module_get(tbl->owner)) {
558 snd_printk(KERN_ERR "hda_codec: cannot module_get\n");
559 continue;
560 }
561 for (preset = tbl->preset; preset->id; preset++) {
468 u32 mask = preset->mask; 562 u32 mask = preset->mask;
469 if (preset->afg && preset->afg != codec->afg) 563 if (preset->afg && preset->afg != codec->afg)
470 continue; 564 continue;
@@ -474,23 +568,40 @@ find_codec_preset(struct hda_codec *codec)
474 mask = ~0; 568 mask = ~0;
475 if (preset->id == (codec->vendor_id & mask) && 569 if (preset->id == (codec->vendor_id & mask) &&
476 (!preset->rev || 570 (!preset->rev ||
477 preset->rev == codec->revision_id)) 571 preset->rev == codec->revision_id)) {
572 mutex_unlock(&preset_mutex);
573 codec->owner = tbl->owner;
478 return preset; 574 return preset;
575 }
479 } 576 }
577 module_put(tbl->owner);
578 }
579 mutex_unlock(&preset_mutex);
580
581 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
582 char name[32];
583 if (!mod_requested)
584 snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
585 codec->vendor_id);
586 else
587 snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
588 (codec->vendor_id >> 16) & 0xffff);
589 request_module(name);
590 mod_requested++;
591 goto again;
480 } 592 }
481 return NULL; 593 return NULL;
482} 594}
483 595
484/* 596/*
485 * snd_hda_get_codec_name - store the codec name 597 * get_codec_name - store the codec name
486 */ 598 */
487void snd_hda_get_codec_name(struct hda_codec *codec, 599static int get_codec_name(struct hda_codec *codec)
488 char *name, int namelen)
489{ 600{
490 const struct hda_vendor_id *c; 601 const struct hda_vendor_id *c;
491 const char *vendor = NULL; 602 const char *vendor = NULL;
492 u16 vendor_id = codec->vendor_id >> 16; 603 u16 vendor_id = codec->vendor_id >> 16;
493 char tmp[16]; 604 char tmp[16], name[32];
494 605
495 for (c = hda_vendor_ids; c->id; c++) { 606 for (c = hda_vendor_ids; c->id; c++) {
496 if (c->id == vendor_id) { 607 if (c->id == vendor_id) {
@@ -503,16 +614,21 @@ void snd_hda_get_codec_name(struct hda_codec *codec,
503 vendor = tmp; 614 vendor = tmp;
504 } 615 }
505 if (codec->preset && codec->preset->name) 616 if (codec->preset && codec->preset->name)
506 snprintf(name, namelen, "%s %s", vendor, codec->preset->name); 617 snprintf(name, sizeof(name), "%s %s", vendor,
618 codec->preset->name);
507 else 619 else
508 snprintf(name, namelen, "%s ID %x", vendor, 620 snprintf(name, sizeof(name), "%s ID %x", vendor,
509 codec->vendor_id & 0xffff); 621 codec->vendor_id & 0xffff);
622 codec->name = kstrdup(name, GFP_KERNEL);
623 if (!codec->name)
624 return -ENOMEM;
625 return 0;
510} 626}
511 627
512/* 628/*
513 * look for an AFG and MFG nodes 629 * look for an AFG and MFG nodes
514 */ 630 */
515static void __devinit setup_fg_nodes(struct hda_codec *codec) 631static void /*__devinit*/ setup_fg_nodes(struct hda_codec *codec)
516{ 632{
517 int i, total_nodes; 633 int i, total_nodes;
518 hda_nid_t nid; 634 hda_nid_t nid;
@@ -571,11 +687,15 @@ static void snd_hda_codec_free(struct hda_codec *codec)
571 flush_scheduled_work(); 687 flush_scheduled_work();
572#endif 688#endif
573 list_del(&codec->list); 689 list_del(&codec->list);
690 snd_array_free(&codec->mixers);
574 codec->bus->caddr_tbl[codec->addr] = NULL; 691 codec->bus->caddr_tbl[codec->addr] = NULL;
575 if (codec->patch_ops.free) 692 if (codec->patch_ops.free)
576 codec->patch_ops.free(codec); 693 codec->patch_ops.free(codec);
694 module_put(codec->owner);
577 free_hda_cache(&codec->amp_cache); 695 free_hda_cache(&codec->amp_cache);
578 free_hda_cache(&codec->cmd_cache); 696 free_hda_cache(&codec->cmd_cache);
697 kfree(codec->name);
698 kfree(codec->modelname);
579 kfree(codec->wcaps); 699 kfree(codec->wcaps);
580 kfree(codec); 700 kfree(codec);
581} 701}
@@ -588,8 +708,8 @@ static void snd_hda_codec_free(struct hda_codec *codec)
588 * 708 *
589 * Returns 0 if successful, or a negative error code. 709 * Returns 0 if successful, or a negative error code.
590 */ 710 */
591int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 711int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
592 struct hda_codec **codecp) 712 int do_init, struct hda_codec **codecp)
593{ 713{
594 struct hda_codec *codec; 714 struct hda_codec *codec;
595 char component[31]; 715 char component[31];
@@ -617,6 +737,14 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
617 mutex_init(&codec->spdif_mutex); 737 mutex_init(&codec->spdif_mutex);
618 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 738 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
619 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 739 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
740 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32);
741 if (codec->bus->modelname) {
742 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
743 if (!codec->modelname) {
744 snd_hda_codec_free(codec);
745 return -ENODEV;
746 }
747 }
620 748
621#ifdef CONFIG_SND_HDA_POWER_SAVE 749#ifdef CONFIG_SND_HDA_POWER_SAVE
622 INIT_DELAYED_WORK(&codec->power_work, hda_power_work); 750 INIT_DELAYED_WORK(&codec->power_work, hda_power_work);
@@ -662,12 +790,44 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
662 snd_hda_codec_read(codec, nid, 0, 790 snd_hda_codec_read(codec, nid, 0,
663 AC_VERB_GET_SUBSYSTEM_ID, 0); 791 AC_VERB_GET_SUBSYSTEM_ID, 0);
664 } 792 }
793 if (bus->modelname)
794 codec->modelname = kstrdup(bus->modelname, GFP_KERNEL);
795
796 if (do_init) {
797 err = snd_hda_codec_configure(codec);
798 if (err < 0) {
799 snd_hda_codec_free(codec);
800 return err;
801 }
802 }
803 snd_hda_codec_proc_new(codec);
804
805 snd_hda_create_hwdep(codec);
806
807 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id,
808 codec->subsystem_id, codec->revision_id);
809 snd_component_add(codec->bus->card, component);
810
811 if (codecp)
812 *codecp = codec;
813 return 0;
814}
815EXPORT_SYMBOL_HDA(snd_hda_codec_new);
816
817int snd_hda_codec_configure(struct hda_codec *codec)
818{
819 int err;
665 820
666 codec->preset = find_codec_preset(codec); 821 codec->preset = find_codec_preset(codec);
822 if (!codec->name) {
823 err = get_codec_name(codec);
824 if (err < 0)
825 return err;
826 }
667 /* audio codec should override the mixer name */ 827 /* audio codec should override the mixer name */
668 if (codec->afg || !*bus->card->mixername) 828 if (codec->afg || !*codec->bus->card->mixername)
669 snd_hda_get_codec_name(codec, bus->card->mixername, 829 strlcpy(codec->bus->card->mixername, codec->name,
670 sizeof(bus->card->mixername)); 830 sizeof(codec->bus->card->mixername));
671 831
672 if (is_generic_config(codec)) { 832 if (is_generic_config(codec)) {
673 err = snd_hda_parse_generic_codec(codec); 833 err = snd_hda_parse_generic_codec(codec);
@@ -684,25 +844,9 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
684 printk(KERN_ERR "hda-codec: No codec parser is available\n"); 844 printk(KERN_ERR "hda-codec: No codec parser is available\n");
685 845
686 patched: 846 patched:
687 if (err < 0) { 847 if (!err && codec->patch_ops.unsol_event)
688 snd_hda_codec_free(codec); 848 err = init_unsol_queue(codec->bus);
689 return err; 849 return err;
690 }
691
692 if (codec->patch_ops.unsol_event)
693 init_unsol_queue(bus);
694
695 snd_hda_codec_proc_new(codec);
696#ifdef CONFIG_SND_HDA_HWDEP
697 snd_hda_create_hwdep(codec);
698#endif
699
700 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, codec->subsystem_id, codec->revision_id);
701 snd_component_add(codec->bus->card, component);
702
703 if (codecp)
704 *codecp = codec;
705 return 0;
706} 850}
707 851
708/** 852/**
@@ -728,6 +872,7 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
728 msleep(1); 872 msleep(1);
729 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format); 873 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
730} 874}
875EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
731 876
732void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid) 877void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
733{ 878{
@@ -741,6 +886,7 @@ void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
741 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0); 886 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
742#endif 887#endif
743} 888}
889EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
744 890
745/* 891/*
746 * amp access functions 892 * amp access functions
@@ -752,17 +898,17 @@ void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
752#define INFO_AMP_VOL(ch) (1 << (1 + (ch))) 898#define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
753 899
754/* initialize the hash table */ 900/* initialize the hash table */
755static void __devinit init_hda_cache(struct hda_cache_rec *cache, 901static void /*__devinit*/ init_hda_cache(struct hda_cache_rec *cache,
756 unsigned int record_size) 902 unsigned int record_size)
757{ 903{
758 memset(cache, 0, sizeof(*cache)); 904 memset(cache, 0, sizeof(*cache));
759 memset(cache->hash, 0xff, sizeof(cache->hash)); 905 memset(cache->hash, 0xff, sizeof(cache->hash));
760 cache->record_size = record_size; 906 snd_array_init(&cache->buf, record_size, 64);
761} 907}
762 908
763static void free_hda_cache(struct hda_cache_rec *cache) 909static void free_hda_cache(struct hda_cache_rec *cache)
764{ 910{
765 kfree(cache->buffer); 911 snd_array_free(&cache->buf);
766} 912}
767 913
768/* query the hash. allocate an entry if not found. */ 914/* query the hash. allocate an entry if not found. */
@@ -774,35 +920,17 @@ static struct hda_cache_head *get_alloc_hash(struct hda_cache_rec *cache,
774 struct hda_cache_head *info; 920 struct hda_cache_head *info;
775 921
776 while (cur != 0xffff) { 922 while (cur != 0xffff) {
777 info = (struct hda_cache_head *)(cache->buffer + 923 info = snd_array_elem(&cache->buf, cur);
778 cur * cache->record_size);
779 if (info->key == key) 924 if (info->key == key)
780 return info; 925 return info;
781 cur = info->next; 926 cur = info->next;
782 } 927 }
783 928
784 /* add a new hash entry */ 929 /* add a new hash entry */
785 if (cache->num_entries >= cache->size) { 930 info = snd_array_new(&cache->buf);
786 /* reallocate the array */ 931 if (!info)
787 unsigned int new_size = cache->size + 64; 932 return NULL;
788 void *new_buffer; 933 cur = snd_array_index(&cache->buf, info);
789 new_buffer = kcalloc(new_size, cache->record_size, GFP_KERNEL);
790 if (!new_buffer) {
791 snd_printk(KERN_ERR "hda_codec: "
792 "can't malloc amp_info\n");
793 return NULL;
794 }
795 if (cache->buffer) {
796 memcpy(new_buffer, cache->buffer,
797 cache->size * cache->record_size);
798 kfree(cache->buffer);
799 }
800 cache->size = new_size;
801 cache->buffer = new_buffer;
802 }
803 cur = cache->num_entries++;
804 info = (struct hda_cache_head *)(cache->buffer +
805 cur * cache->record_size);
806 info->key = key; 934 info->key = key;
807 info->val = 0; 935 info->val = 0;
808 info->next = cache->hash[idx]; 936 info->next = cache->hash[idx];
@@ -840,6 +968,7 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
840 } 968 }
841 return info->amp_caps; 969 return info->amp_caps;
842} 970}
971EXPORT_SYMBOL_HDA(query_amp_caps);
843 972
844int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 973int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
845 unsigned int caps) 974 unsigned int caps)
@@ -853,6 +982,7 @@ int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
853 info->head.val |= INFO_AMP_CAPS; 982 info->head.val |= INFO_AMP_CAPS;
854 return 0; 983 return 0;
855} 984}
985EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps);
856 986
857/* 987/*
858 * read the current volume to info 988 * read the current volume to info
@@ -906,6 +1036,7 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
906 return 0; 1036 return 0;
907 return get_vol_mute(codec, info, nid, ch, direction, index); 1037 return get_vol_mute(codec, info, nid, ch, direction, index);
908} 1038}
1039EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
909 1040
910/* 1041/*
911 * update the AMP value, mask = bit mask to set, val = the value 1042 * update the AMP value, mask = bit mask to set, val = the value
@@ -925,6 +1056,7 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
925 put_vol_mute(codec, info, nid, ch, direction, idx, val); 1056 put_vol_mute(codec, info, nid, ch, direction, idx, val);
926 return 1; 1057 return 1;
927} 1058}
1059EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
928 1060
929/* 1061/*
930 * update the AMP stereo with the same mask and value 1062 * update the AMP stereo with the same mask and value
@@ -938,15 +1070,16 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
938 idx, mask, val); 1070 idx, mask, val);
939 return ret; 1071 return ret;
940} 1072}
1073EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
941 1074
942#ifdef SND_HDA_NEEDS_RESUME 1075#ifdef SND_HDA_NEEDS_RESUME
943/* resume the all amp commands from the cache */ 1076/* resume the all amp commands from the cache */
944void snd_hda_codec_resume_amp(struct hda_codec *codec) 1077void snd_hda_codec_resume_amp(struct hda_codec *codec)
945{ 1078{
946 struct hda_amp_info *buffer = codec->amp_cache.buffer; 1079 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
947 int i; 1080 int i;
948 1081
949 for (i = 0; i < codec->amp_cache.size; i++, buffer++) { 1082 for (i = 0; i < codec->amp_cache.buf.used; i++, buffer++) {
950 u32 key = buffer->head.key; 1083 u32 key = buffer->head.key;
951 hda_nid_t nid; 1084 hda_nid_t nid;
952 unsigned int idx, dir, ch; 1085 unsigned int idx, dir, ch;
@@ -963,6 +1096,7 @@ void snd_hda_codec_resume_amp(struct hda_codec *codec)
963 } 1096 }
964 } 1097 }
965} 1098}
1099EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
966#endif /* SND_HDA_NEEDS_RESUME */ 1100#endif /* SND_HDA_NEEDS_RESUME */
967 1101
968/* volume */ 1102/* volume */
@@ -990,6 +1124,7 @@ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
990 uinfo->value.integer.max = caps; 1124 uinfo->value.integer.max = caps;
991 return 0; 1125 return 0;
992} 1126}
1127EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_info);
993 1128
994int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, 1129int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
995 struct snd_ctl_elem_value *ucontrol) 1130 struct snd_ctl_elem_value *ucontrol)
@@ -1009,6 +1144,7 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1009 & HDA_AMP_VOLMASK; 1144 & HDA_AMP_VOLMASK;
1010 return 0; 1145 return 0;
1011} 1146}
1147EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1012 1148
1013int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, 1149int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1014 struct snd_ctl_elem_value *ucontrol) 1150 struct snd_ctl_elem_value *ucontrol)
@@ -1033,6 +1169,7 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1033 snd_hda_power_down(codec); 1169 snd_hda_power_down(codec);
1034 return change; 1170 return change;
1035} 1171}
1172EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1036 1173
1037int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1174int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1038 unsigned int size, unsigned int __user *_tlv) 1175 unsigned int size, unsigned int __user *_tlv)
@@ -1059,6 +1196,7 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1059 return -EFAULT; 1196 return -EFAULT;
1060 return 0; 1197 return 0;
1061} 1198}
1199EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1062 1200
1063/* 1201/*
1064 * set (static) TLV for virtual master volume; recalculated as max 0dB 1202 * set (static) TLV for virtual master volume; recalculated as max 0dB
@@ -1078,6 +1216,7 @@ void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1078 tlv[2] = -nums * step; 1216 tlv[2] = -nums * step;
1079 tlv[3] = step; 1217 tlv[3] = step;
1080} 1218}
1219EXPORT_SYMBOL_HDA(snd_hda_set_vmaster_tlv);
1081 1220
1082/* find a mixer control element with the given name */ 1221/* find a mixer control element with the given name */
1083static struct snd_kcontrol * 1222static struct snd_kcontrol *
@@ -1097,6 +1236,69 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1097{ 1236{
1098 return _snd_hda_find_mixer_ctl(codec, name, 0); 1237 return _snd_hda_find_mixer_ctl(codec, name, 0);
1099} 1238}
1239EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1240
1241/* Add a control element and assign to the codec */
1242int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl)
1243{
1244 int err;
1245 struct snd_kcontrol **knewp;
1246
1247 err = snd_ctl_add(codec->bus->card, kctl);
1248 if (err < 0)
1249 return err;
1250 knewp = snd_array_new(&codec->mixers);
1251 if (!knewp)
1252 return -ENOMEM;
1253 *knewp = kctl;
1254 return 0;
1255}
1256EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1257
1258#ifdef CONFIG_SND_HDA_RECONFIG
1259/* Clear all controls assigned to the given codec */
1260void snd_hda_ctls_clear(struct hda_codec *codec)
1261{
1262 int i;
1263 struct snd_kcontrol **kctls = codec->mixers.list;
1264 for (i = 0; i < codec->mixers.used; i++)
1265 snd_ctl_remove(codec->bus->card, kctls[i]);
1266 snd_array_free(&codec->mixers);
1267}
1268
1269void snd_hda_codec_reset(struct hda_codec *codec)
1270{
1271 int i;
1272
1273#ifdef CONFIG_SND_HDA_POWER_SAVE
1274 cancel_delayed_work(&codec->power_work);
1275 flush_scheduled_work();
1276#endif
1277 snd_hda_ctls_clear(codec);
1278 /* relase PCMs */
1279 for (i = 0; i < codec->num_pcms; i++) {
1280 if (codec->pcm_info[i].pcm) {
1281 snd_device_free(codec->bus->card,
1282 codec->pcm_info[i].pcm);
1283 clear_bit(codec->pcm_info[i].device,
1284 codec->bus->pcm_dev_bits);
1285 }
1286 }
1287 if (codec->patch_ops.free)
1288 codec->patch_ops.free(codec);
1289 codec->proc_widget_hook = NULL;
1290 codec->spec = NULL;
1291 free_hda_cache(&codec->amp_cache);
1292 free_hda_cache(&codec->cmd_cache);
1293 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1294 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1295 codec->num_pcms = 0;
1296 codec->pcm_info = NULL;
1297 codec->preset = NULL;
1298 module_put(codec->owner);
1299 codec->owner = NULL;
1300}
1301#endif /* CONFIG_SND_HDA_RECONFIG */
1100 1302
1101/* create a virtual master control and add slaves */ 1303/* create a virtual master control and add slaves */
1102int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1304int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
@@ -1115,7 +1317,7 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1115 kctl = snd_ctl_make_virtual_master(name, tlv); 1317 kctl = snd_ctl_make_virtual_master(name, tlv);
1116 if (!kctl) 1318 if (!kctl)
1117 return -ENOMEM; 1319 return -ENOMEM;
1118 err = snd_ctl_add(codec->bus->card, kctl); 1320 err = snd_hda_ctl_add(codec, kctl);
1119 if (err < 0) 1321 if (err < 0)
1120 return err; 1322 return err;
1121 1323
@@ -1133,6 +1335,7 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1133 } 1335 }
1134 return 0; 1336 return 0;
1135} 1337}
1338EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
1136 1339
1137/* switch */ 1340/* switch */
1138int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, 1341int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
@@ -1146,6 +1349,7 @@ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1146 uinfo->value.integer.max = 1; 1349 uinfo->value.integer.max = 1;
1147 return 0; 1350 return 0;
1148} 1351}
1352EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
1149 1353
1150int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, 1354int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1151 struct snd_ctl_elem_value *ucontrol) 1355 struct snd_ctl_elem_value *ucontrol)
@@ -1165,6 +1369,7 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1165 HDA_AMP_MUTE) ? 0 : 1; 1369 HDA_AMP_MUTE) ? 0 : 1;
1166 return 0; 1370 return 0;
1167} 1371}
1372EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
1168 1373
1169int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 1374int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1170 struct snd_ctl_elem_value *ucontrol) 1375 struct snd_ctl_elem_value *ucontrol)
@@ -1195,6 +1400,7 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1195 snd_hda_power_down(codec); 1400 snd_hda_power_down(codec);
1196 return change; 1401 return change;
1197} 1402}
1403EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1198 1404
1199/* 1405/*
1200 * bound volume controls 1406 * bound volume controls
@@ -1220,6 +1426,7 @@ int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1220 mutex_unlock(&codec->spdif_mutex); 1426 mutex_unlock(&codec->spdif_mutex);
1221 return err; 1427 return err;
1222} 1428}
1429EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
1223 1430
1224int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, 1431int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1225 struct snd_ctl_elem_value *ucontrol) 1432 struct snd_ctl_elem_value *ucontrol)
@@ -1243,6 +1450,7 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1243 mutex_unlock(&codec->spdif_mutex); 1450 mutex_unlock(&codec->spdif_mutex);
1244 return err < 0 ? err : change; 1451 return err < 0 ? err : change;
1245} 1452}
1453EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
1246 1454
1247/* 1455/*
1248 * generic bound volume/swtich controls 1456 * generic bound volume/swtich controls
@@ -1262,6 +1470,7 @@ int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1262 mutex_unlock(&codec->spdif_mutex); 1470 mutex_unlock(&codec->spdif_mutex);
1263 return err; 1471 return err;
1264} 1472}
1473EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
1265 1474
1266int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, 1475int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1267 struct snd_ctl_elem_value *ucontrol) 1476 struct snd_ctl_elem_value *ucontrol)
@@ -1278,6 +1487,7 @@ int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1278 mutex_unlock(&codec->spdif_mutex); 1487 mutex_unlock(&codec->spdif_mutex);
1279 return err; 1488 return err;
1280} 1489}
1490EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
1281 1491
1282int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, 1492int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1283 struct snd_ctl_elem_value *ucontrol) 1493 struct snd_ctl_elem_value *ucontrol)
@@ -1300,6 +1510,7 @@ int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1300 mutex_unlock(&codec->spdif_mutex); 1510 mutex_unlock(&codec->spdif_mutex);
1301 return err < 0 ? err : change; 1511 return err < 0 ? err : change;
1302} 1512}
1513EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
1303 1514
1304int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1515int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1305 unsigned int size, unsigned int __user *tlv) 1516 unsigned int size, unsigned int __user *tlv)
@@ -1316,6 +1527,7 @@ int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1316 mutex_unlock(&codec->spdif_mutex); 1527 mutex_unlock(&codec->spdif_mutex);
1317 return err; 1528 return err;
1318} 1529}
1530EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_tlv);
1319 1531
1320struct hda_ctl_ops snd_hda_bind_vol = { 1532struct hda_ctl_ops snd_hda_bind_vol = {
1321 .info = snd_hda_mixer_amp_volume_info, 1533 .info = snd_hda_mixer_amp_volume_info,
@@ -1323,6 +1535,7 @@ struct hda_ctl_ops snd_hda_bind_vol = {
1323 .put = snd_hda_mixer_amp_volume_put, 1535 .put = snd_hda_mixer_amp_volume_put,
1324 .tlv = snd_hda_mixer_amp_tlv 1536 .tlv = snd_hda_mixer_amp_tlv
1325}; 1537};
1538EXPORT_SYMBOL_HDA(snd_hda_bind_vol);
1326 1539
1327struct hda_ctl_ops snd_hda_bind_sw = { 1540struct hda_ctl_ops snd_hda_bind_sw = {
1328 .info = snd_hda_mixer_amp_switch_info, 1541 .info = snd_hda_mixer_amp_switch_info,
@@ -1330,6 +1543,7 @@ struct hda_ctl_ops snd_hda_bind_sw = {
1330 .put = snd_hda_mixer_amp_switch_put, 1543 .put = snd_hda_mixer_amp_switch_put,
1331 .tlv = snd_hda_mixer_amp_tlv 1544 .tlv = snd_hda_mixer_amp_tlv
1332}; 1545};
1546EXPORT_SYMBOL_HDA(snd_hda_bind_sw);
1333 1547
1334/* 1548/*
1335 * SPDIF out controls 1549 * SPDIF out controls
@@ -1577,9 +1791,11 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1577 } 1791 }
1578 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { 1792 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
1579 kctl = snd_ctl_new1(dig_mix, codec); 1793 kctl = snd_ctl_new1(dig_mix, codec);
1794 if (!kctl)
1795 return -ENOMEM;
1580 kctl->id.index = idx; 1796 kctl->id.index = idx;
1581 kctl->private_value = nid; 1797 kctl->private_value = nid;
1582 err = snd_ctl_add(codec->bus->card, kctl); 1798 err = snd_hda_ctl_add(codec, kctl);
1583 if (err < 0) 1799 if (err < 0)
1584 return err; 1800 return err;
1585 } 1801 }
@@ -1589,6 +1805,7 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1589 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls); 1805 codec->spdif_status = convert_to_spdif_status(codec->spdif_ctls);
1590 return 0; 1806 return 0;
1591} 1807}
1808EXPORT_SYMBOL_HDA(snd_hda_create_spdif_out_ctls);
1592 1809
1593/* 1810/*
1594 * SPDIF sharing with analog output 1811 * SPDIF sharing with analog output
@@ -1623,9 +1840,10 @@ int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
1623 if (!mout->dig_out_nid) 1840 if (!mout->dig_out_nid)
1624 return 0; 1841 return 0;
1625 /* ATTENTION: here mout is passed as private_data, instead of codec */ 1842 /* ATTENTION: here mout is passed as private_data, instead of codec */
1626 return snd_ctl_add(codec->bus->card, 1843 return snd_hda_ctl_add(codec,
1627 snd_ctl_new1(&spdif_share_sw, mout)); 1844 snd_ctl_new1(&spdif_share_sw, mout));
1628} 1845}
1846EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
1629 1847
1630/* 1848/*
1631 * SPDIF input 1849 * SPDIF input
@@ -1725,7 +1943,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1725 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { 1943 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1726 kctl = snd_ctl_new1(dig_mix, codec); 1944 kctl = snd_ctl_new1(dig_mix, codec);
1727 kctl->private_value = nid; 1945 kctl->private_value = nid;
1728 err = snd_ctl_add(codec->bus->card, kctl); 1946 err = snd_hda_ctl_add(codec, kctl);
1729 if (err < 0) 1947 if (err < 0)
1730 return err; 1948 return err;
1731 } 1949 }
@@ -1735,6 +1953,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1735 AC_DIG1_ENABLE; 1953 AC_DIG1_ENABLE;
1736 return 0; 1954 return 0;
1737} 1955}
1956EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls);
1738 1957
1739#ifdef SND_HDA_NEEDS_RESUME 1958#ifdef SND_HDA_NEEDS_RESUME
1740/* 1959/*
@@ -1761,10 +1980,14 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1761int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, 1980int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
1762 int direct, unsigned int verb, unsigned int parm) 1981 int direct, unsigned int verb, unsigned int parm)
1763{ 1982{
1983 struct hda_bus *bus = codec->bus;
1984 unsigned int res;
1764 int err; 1985 int err;
1986
1987 res = make_codec_cmd(codec, nid, direct, verb, parm);
1765 snd_hda_power_up(codec); 1988 snd_hda_power_up(codec);
1766 mutex_lock(&codec->bus->cmd_mutex); 1989 mutex_lock(&bus->cmd_mutex);
1767 err = codec->bus->ops.command(codec, nid, direct, verb, parm); 1990 err = bus->ops.command(bus, res);
1768 if (!err) { 1991 if (!err) {
1769 struct hda_cache_head *c; 1992 struct hda_cache_head *c;
1770 u32 key = build_cmd_cache_key(nid, verb); 1993 u32 key = build_cmd_cache_key(nid, verb);
@@ -1772,18 +1995,19 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
1772 if (c) 1995 if (c)
1773 c->val = parm; 1996 c->val = parm;
1774 } 1997 }
1775 mutex_unlock(&codec->bus->cmd_mutex); 1998 mutex_unlock(&bus->cmd_mutex);
1776 snd_hda_power_down(codec); 1999 snd_hda_power_down(codec);
1777 return err; 2000 return err;
1778} 2001}
2002EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
1779 2003
1780/* resume the all commands from the cache */ 2004/* resume the all commands from the cache */
1781void snd_hda_codec_resume_cache(struct hda_codec *codec) 2005void snd_hda_codec_resume_cache(struct hda_codec *codec)
1782{ 2006{
1783 struct hda_cache_head *buffer = codec->cmd_cache.buffer; 2007 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
1784 int i; 2008 int i;
1785 2009
1786 for (i = 0; i < codec->cmd_cache.size; i++, buffer++) { 2010 for (i = 0; i < codec->cmd_cache.buf.used; i++, buffer++) {
1787 u32 key = buffer->key; 2011 u32 key = buffer->key;
1788 if (!key) 2012 if (!key)
1789 continue; 2013 continue;
@@ -1791,6 +2015,7 @@ void snd_hda_codec_resume_cache(struct hda_codec *codec)
1791 get_cmd_cache_cmd(key), buffer->val); 2015 get_cmd_cache_cmd(key), buffer->val);
1792 } 2016 }
1793} 2017}
2018EXPORT_SYMBOL_HDA(snd_hda_codec_resume_cache);
1794 2019
1795/** 2020/**
1796 * snd_hda_sequence_write_cache - sequence writes with caching 2021 * snd_hda_sequence_write_cache - sequence writes with caching
@@ -1808,6 +2033,7 @@ void snd_hda_sequence_write_cache(struct hda_codec *codec,
1808 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb, 2033 snd_hda_codec_write_cache(codec, seq->nid, 0, seq->verb,
1809 seq->param); 2034 seq->param);
1810} 2035}
2036EXPORT_SYMBOL_HDA(snd_hda_sequence_write_cache);
1811#endif /* SND_HDA_NEEDS_RESUME */ 2037#endif /* SND_HDA_NEEDS_RESUME */
1812 2038
1813/* 2039/*
@@ -1868,6 +2094,17 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
1868 } 2094 }
1869} 2095}
1870 2096
2097#ifdef CONFIG_SND_HDA_HWDEP
2098/* execute additional init verbs */
2099static void hda_exec_init_verbs(struct hda_codec *codec)
2100{
2101 if (codec->init_verbs.list)
2102 snd_hda_sequence_write(codec, codec->init_verbs.list);
2103}
2104#else
2105static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
2106#endif
2107
1871#ifdef SND_HDA_NEEDS_RESUME 2108#ifdef SND_HDA_NEEDS_RESUME
1872/* 2109/*
1873 * call suspend and power-down; used both from PM and power-save 2110 * call suspend and power-down; used both from PM and power-save
@@ -1894,6 +2131,7 @@ static void hda_call_codec_resume(struct hda_codec *codec)
1894 hda_set_power_state(codec, 2131 hda_set_power_state(codec,
1895 codec->afg ? codec->afg : codec->mfg, 2132 codec->afg ? codec->afg : codec->mfg,
1896 AC_PWRST_D0); 2133 AC_PWRST_D0);
2134 hda_exec_init_verbs(codec);
1897 if (codec->patch_ops.resume) 2135 if (codec->patch_ops.resume)
1898 codec->patch_ops.resume(codec); 2136 codec->patch_ops.resume(codec);
1899 else { 2137 else {
@@ -1914,28 +2152,37 @@ static void hda_call_codec_resume(struct hda_codec *codec)
1914 * 2152 *
1915 * Returns 0 if successful, otherwise a negative error code. 2153 * Returns 0 if successful, otherwise a negative error code.
1916 */ 2154 */
1917int __devinit snd_hda_build_controls(struct hda_bus *bus) 2155int /*__devinit*/ snd_hda_build_controls(struct hda_bus *bus)
1918{ 2156{
1919 struct hda_codec *codec; 2157 struct hda_codec *codec;
1920 2158
1921 list_for_each_entry(codec, &bus->codec_list, list) { 2159 list_for_each_entry(codec, &bus->codec_list, list) {
1922 int err = 0; 2160 int err = snd_hda_codec_build_controls(codec);
1923 /* fake as if already powered-on */
1924 hda_keep_power_on(codec);
1925 /* then fire up */
1926 hda_set_power_state(codec,
1927 codec->afg ? codec->afg : codec->mfg,
1928 AC_PWRST_D0);
1929 /* continue to initialize... */
1930 if (codec->patch_ops.init)
1931 err = codec->patch_ops.init(codec);
1932 if (!err && codec->patch_ops.build_controls)
1933 err = codec->patch_ops.build_controls(codec);
1934 snd_hda_power_down(codec);
1935 if (err < 0) 2161 if (err < 0)
1936 return err; 2162 return err;
1937 } 2163 }
2164 return 0;
2165}
2166EXPORT_SYMBOL_HDA(snd_hda_build_controls);
1938 2167
2168int snd_hda_codec_build_controls(struct hda_codec *codec)
2169{
2170 int err = 0;
2171 /* fake as if already powered-on */
2172 hda_keep_power_on(codec);
2173 /* then fire up */
2174 hda_set_power_state(codec,
2175 codec->afg ? codec->afg : codec->mfg,
2176 AC_PWRST_D0);
2177 hda_exec_init_verbs(codec);
2178 /* continue to initialize... */
2179 if (codec->patch_ops.init)
2180 err = codec->patch_ops.init(codec);
2181 if (!err && codec->patch_ops.build_controls)
2182 err = codec->patch_ops.build_controls(codec);
2183 snd_hda_power_down(codec);
2184 if (err < 0)
2185 return err;
1939 return 0; 2186 return 0;
1940} 2187}
1941 2188
@@ -2028,6 +2275,7 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
2028 2275
2029 return val; 2276 return val;
2030} 2277}
2278EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format);
2031 2279
2032/** 2280/**
2033 * snd_hda_query_supported_pcm - query the supported PCM rates and formats 2281 * snd_hda_query_supported_pcm - query the supported PCM rates and formats
@@ -2042,7 +2290,7 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
2042 * 2290 *
2043 * Returns 0 if successful, otherwise a negative error code. 2291 * Returns 0 if successful, otherwise a negative error code.
2044 */ 2292 */
2045int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid, 2293static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2046 u32 *ratesp, u64 *formatsp, unsigned int *bpsp) 2294 u32 *ratesp, u64 *formatsp, unsigned int *bpsp)
2047{ 2295{
2048 int i; 2296 int i;
@@ -2207,6 +2455,7 @@ int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
2207 2455
2208 return 1; 2456 return 1;
2209} 2457}
2458EXPORT_SYMBOL_HDA(snd_hda_is_supported_format);
2210 2459
2211/* 2460/*
2212 * PCM stuff 2461 * PCM stuff
@@ -2236,8 +2485,8 @@ static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
2236 return 0; 2485 return 0;
2237} 2486}
2238 2487
2239static int __devinit set_pcm_default_values(struct hda_codec *codec, 2488static int set_pcm_default_values(struct hda_codec *codec,
2240 struct hda_pcm_stream *info) 2489 struct hda_pcm_stream *info)
2241{ 2490{
2242 /* query support PCM information from the given NID */ 2491 /* query support PCM information from the given NID */
2243 if (info->nid && (!info->rates || !info->formats)) { 2492 if (info->nid && (!info->rates || !info->formats)) {
@@ -2263,6 +2512,110 @@ static int __devinit set_pcm_default_values(struct hda_codec *codec,
2263 return 0; 2512 return 0;
2264} 2513}
2265 2514
2515/*
2516 * get the empty PCM device number to assign
2517 */
2518static int get_empty_pcm_device(struct hda_bus *bus, int type)
2519{
2520 static const char *dev_name[HDA_PCM_NTYPES] = {
2521 "Audio", "SPDIF", "HDMI", "Modem"
2522 };
2523 /* starting device index for each PCM type */
2524 static int dev_idx[HDA_PCM_NTYPES] = {
2525 [HDA_PCM_TYPE_AUDIO] = 0,
2526 [HDA_PCM_TYPE_SPDIF] = 1,
2527 [HDA_PCM_TYPE_HDMI] = 3,
2528 [HDA_PCM_TYPE_MODEM] = 6
2529 };
2530 /* normal audio device indices; not linear to keep compatibility */
2531 static int audio_idx[4] = { 0, 2, 4, 5 };
2532 int i, dev;
2533
2534 switch (type) {
2535 case HDA_PCM_TYPE_AUDIO:
2536 for (i = 0; i < ARRAY_SIZE(audio_idx); i++) {
2537 dev = audio_idx[i];
2538 if (!test_bit(dev, bus->pcm_dev_bits))
2539 break;
2540 }
2541 if (i >= ARRAY_SIZE(audio_idx)) {
2542 snd_printk(KERN_WARNING "Too many audio devices\n");
2543 return -EAGAIN;
2544 }
2545 break;
2546 case HDA_PCM_TYPE_SPDIF:
2547 case HDA_PCM_TYPE_HDMI:
2548 case HDA_PCM_TYPE_MODEM:
2549 dev = dev_idx[type];
2550 if (test_bit(dev, bus->pcm_dev_bits)) {
2551 snd_printk(KERN_WARNING "%s already defined\n",
2552 dev_name[type]);
2553 return -EAGAIN;
2554 }
2555 break;
2556 default:
2557 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
2558 return -EINVAL;
2559 }
2560 set_bit(dev, bus->pcm_dev_bits);
2561 return dev;
2562}
2563
2564/*
2565 * attach a new PCM stream
2566 */
2567static int snd_hda_attach_pcm(struct hda_codec *codec, struct hda_pcm *pcm)
2568{
2569 struct hda_bus *bus = codec->bus;
2570 struct hda_pcm_stream *info;
2571 int stream, err;
2572
2573 if (snd_BUG_ON(!pcm->name))
2574 return -EINVAL;
2575 for (stream = 0; stream < 2; stream++) {
2576 info = &pcm->stream[stream];
2577 if (info->substreams) {
2578 err = set_pcm_default_values(codec, info);
2579 if (err < 0)
2580 return err;
2581 }
2582 }
2583 return bus->ops.attach_pcm(bus, codec, pcm);
2584}
2585
2586/* assign all PCMs of the given codec */
2587int snd_hda_codec_build_pcms(struct hda_codec *codec)
2588{
2589 unsigned int pcm;
2590 int err;
2591
2592 if (!codec->num_pcms) {
2593 if (!codec->patch_ops.build_pcms)
2594 return 0;
2595 err = codec->patch_ops.build_pcms(codec);
2596 if (err < 0)
2597 return err;
2598 }
2599 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
2600 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
2601 int dev;
2602
2603 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
2604 return 0; /* no substreams assigned */
2605
2606 if (!cpcm->pcm) {
2607 dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type);
2608 if (dev < 0)
2609 return 0;
2610 cpcm->device = dev;
2611 err = snd_hda_attach_pcm(codec, cpcm);
2612 if (err < 0)
2613 return err;
2614 }
2615 }
2616 return 0;
2617}
2618
2266/** 2619/**
2267 * snd_hda_build_pcms - build PCM information 2620 * snd_hda_build_pcms - build PCM information
2268 * @bus: the BUS 2621 * @bus: the BUS
@@ -2294,27 +2647,13 @@ int __devinit snd_hda_build_pcms(struct hda_bus *bus)
2294 struct hda_codec *codec; 2647 struct hda_codec *codec;
2295 2648
2296 list_for_each_entry(codec, &bus->codec_list, list) { 2649 list_for_each_entry(codec, &bus->codec_list, list) {
2297 unsigned int pcm, s; 2650 int err = snd_hda_codec_build_pcms(codec);
2298 int err;
2299 if (!codec->patch_ops.build_pcms)
2300 continue;
2301 err = codec->patch_ops.build_pcms(codec);
2302 if (err < 0) 2651 if (err < 0)
2303 return err; 2652 return err;
2304 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
2305 for (s = 0; s < 2; s++) {
2306 struct hda_pcm_stream *info;
2307 info = &codec->pcm_info[pcm].stream[s];
2308 if (!info->substreams)
2309 continue;
2310 err = set_pcm_default_values(codec, info);
2311 if (err < 0)
2312 return err;
2313 }
2314 }
2315 } 2653 }
2316 return 0; 2654 return 0;
2317} 2655}
2656EXPORT_SYMBOL_HDA(snd_hda_build_pcms);
2318 2657
2319/** 2658/**
2320 * snd_hda_check_board_config - compare the current codec with the config table 2659 * snd_hda_check_board_config - compare the current codec with the config table
@@ -2333,11 +2672,11 @@ int snd_hda_check_board_config(struct hda_codec *codec,
2333 int num_configs, const char **models, 2672 int num_configs, const char **models,
2334 const struct snd_pci_quirk *tbl) 2673 const struct snd_pci_quirk *tbl)
2335{ 2674{
2336 if (codec->bus->modelname && models) { 2675 if (codec->modelname && models) {
2337 int i; 2676 int i;
2338 for (i = 0; i < num_configs; i++) { 2677 for (i = 0; i < num_configs; i++) {
2339 if (models[i] && 2678 if (models[i] &&
2340 !strcmp(codec->bus->modelname, models[i])) { 2679 !strcmp(codec->modelname, models[i])) {
2341 snd_printd(KERN_INFO "hda_codec: model '%s' is " 2680 snd_printd(KERN_INFO "hda_codec: model '%s' is "
2342 "selected\n", models[i]); 2681 "selected\n", models[i]);
2343 return i; 2682 return i;
@@ -2370,6 +2709,7 @@ int snd_hda_check_board_config(struct hda_codec *codec,
2370 } 2709 }
2371 return -1; 2710 return -1;
2372} 2711}
2712EXPORT_SYMBOL_HDA(snd_hda_check_board_config);
2373 2713
2374/** 2714/**
2375 * snd_hda_add_new_ctls - create controls from the array 2715 * snd_hda_add_new_ctls - create controls from the array
@@ -2390,7 +2730,7 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
2390 kctl = snd_ctl_new1(knew, codec); 2730 kctl = snd_ctl_new1(knew, codec);
2391 if (!kctl) 2731 if (!kctl)
2392 return -ENOMEM; 2732 return -ENOMEM;
2393 err = snd_ctl_add(codec->bus->card, kctl); 2733 err = snd_hda_ctl_add(codec, kctl);
2394 if (err < 0) { 2734 if (err < 0) {
2395 if (!codec->addr) 2735 if (!codec->addr)
2396 return err; 2736 return err;
@@ -2398,13 +2738,14 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
2398 if (!kctl) 2738 if (!kctl)
2399 return -ENOMEM; 2739 return -ENOMEM;
2400 kctl->id.device = codec->addr; 2740 kctl->id.device = codec->addr;
2401 err = snd_ctl_add(codec->bus->card, kctl); 2741 err = snd_hda_ctl_add(codec, kctl);
2402 if (err < 0) 2742 if (err < 0)
2403 return err; 2743 return err;
2404 } 2744 }
2405 } 2745 }
2406 return 0; 2746 return 0;
2407} 2747}
2748EXPORT_SYMBOL_HDA(snd_hda_add_new_ctls);
2408 2749
2409#ifdef CONFIG_SND_HDA_POWER_SAVE 2750#ifdef CONFIG_SND_HDA_POWER_SAVE
2410static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, 2751static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
@@ -2414,6 +2755,7 @@ static void hda_power_work(struct work_struct *work)
2414{ 2755{
2415 struct hda_codec *codec = 2756 struct hda_codec *codec =
2416 container_of(work, struct hda_codec, power_work.work); 2757 container_of(work, struct hda_codec, power_work.work);
2758 struct hda_bus *bus = codec->bus;
2417 2759
2418 if (!codec->power_on || codec->power_count) { 2760 if (!codec->power_on || codec->power_count) {
2419 codec->power_transition = 0; 2761 codec->power_transition = 0;
@@ -2421,8 +2763,8 @@ static void hda_power_work(struct work_struct *work)
2421 } 2763 }
2422 2764
2423 hda_call_codec_suspend(codec); 2765 hda_call_codec_suspend(codec);
2424 if (codec->bus->ops.pm_notify) 2766 if (bus->ops.pm_notify)
2425 codec->bus->ops.pm_notify(codec); 2767 bus->ops.pm_notify(bus);
2426} 2768}
2427 2769
2428static void hda_keep_power_on(struct hda_codec *codec) 2770static void hda_keep_power_on(struct hda_codec *codec)
@@ -2433,29 +2775,39 @@ static void hda_keep_power_on(struct hda_codec *codec)
2433 2775
2434void snd_hda_power_up(struct hda_codec *codec) 2776void snd_hda_power_up(struct hda_codec *codec)
2435{ 2777{
2778 struct hda_bus *bus = codec->bus;
2779
2436 codec->power_count++; 2780 codec->power_count++;
2437 if (codec->power_on || codec->power_transition) 2781 if (codec->power_on || codec->power_transition)
2438 return; 2782 return;
2439 2783
2440 codec->power_on = 1; 2784 codec->power_on = 1;
2441 if (codec->bus->ops.pm_notify) 2785 if (bus->ops.pm_notify)
2442 codec->bus->ops.pm_notify(codec); 2786 bus->ops.pm_notify(bus);
2443 hda_call_codec_resume(codec); 2787 hda_call_codec_resume(codec);
2444 cancel_delayed_work(&codec->power_work); 2788 cancel_delayed_work(&codec->power_work);
2445 codec->power_transition = 0; 2789 codec->power_transition = 0;
2446} 2790}
2791EXPORT_SYMBOL_HDA(snd_hda_power_up);
2792
2793#define power_save(codec) \
2794 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
2795
2796#define power_save(codec) \
2797 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
2447 2798
2448void snd_hda_power_down(struct hda_codec *codec) 2799void snd_hda_power_down(struct hda_codec *codec)
2449{ 2800{
2450 --codec->power_count; 2801 --codec->power_count;
2451 if (!codec->power_on || codec->power_count || codec->power_transition) 2802 if (!codec->power_on || codec->power_count || codec->power_transition)
2452 return; 2803 return;
2453 if (power_save) { 2804 if (power_save(codec)) {
2454 codec->power_transition = 1; /* avoid reentrance */ 2805 codec->power_transition = 1; /* avoid reentrance */
2455 schedule_delayed_work(&codec->power_work, 2806 schedule_delayed_work(&codec->power_work,
2456 msecs_to_jiffies(power_save * 1000)); 2807 msecs_to_jiffies(power_save(codec) * 1000));
2457 } 2808 }
2458} 2809}
2810EXPORT_SYMBOL_HDA(snd_hda_power_down);
2459 2811
2460int snd_hda_check_amp_list_power(struct hda_codec *codec, 2812int snd_hda_check_amp_list_power(struct hda_codec *codec,
2461 struct hda_loopback_check *check, 2813 struct hda_loopback_check *check,
@@ -2492,6 +2844,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
2492 } 2844 }
2493 return 0; 2845 return 0;
2494} 2846}
2847EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
2495#endif 2848#endif
2496 2849
2497/* 2850/*
@@ -2511,6 +2864,7 @@ int snd_hda_ch_mode_info(struct hda_codec *codec,
2511 chmode[uinfo->value.enumerated.item].channels); 2864 chmode[uinfo->value.enumerated.item].channels);
2512 return 0; 2865 return 0;
2513} 2866}
2867EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
2514 2868
2515int snd_hda_ch_mode_get(struct hda_codec *codec, 2869int snd_hda_ch_mode_get(struct hda_codec *codec,
2516 struct snd_ctl_elem_value *ucontrol, 2870 struct snd_ctl_elem_value *ucontrol,
@@ -2528,6 +2882,7 @@ int snd_hda_ch_mode_get(struct hda_codec *codec,
2528 } 2882 }
2529 return 0; 2883 return 0;
2530} 2884}
2885EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
2531 2886
2532int snd_hda_ch_mode_put(struct hda_codec *codec, 2887int snd_hda_ch_mode_put(struct hda_codec *codec,
2533 struct snd_ctl_elem_value *ucontrol, 2888 struct snd_ctl_elem_value *ucontrol,
@@ -2548,6 +2903,7 @@ int snd_hda_ch_mode_put(struct hda_codec *codec,
2548 snd_hda_sequence_write_cache(codec, chmode[mode].sequence); 2903 snd_hda_sequence_write_cache(codec, chmode[mode].sequence);
2549 return 1; 2904 return 1;
2550} 2905}
2906EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
2551 2907
2552/* 2908/*
2553 * input MUX helper 2909 * input MUX helper
@@ -2568,6 +2924,7 @@ int snd_hda_input_mux_info(const struct hda_input_mux *imux,
2568 strcpy(uinfo->value.enumerated.name, imux->items[index].label); 2924 strcpy(uinfo->value.enumerated.name, imux->items[index].label);
2569 return 0; 2925 return 0;
2570} 2926}
2927EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
2571 2928
2572int snd_hda_input_mux_put(struct hda_codec *codec, 2929int snd_hda_input_mux_put(struct hda_codec *codec,
2573 const struct hda_input_mux *imux, 2930 const struct hda_input_mux *imux,
@@ -2589,6 +2946,7 @@ int snd_hda_input_mux_put(struct hda_codec *codec,
2589 *cur_val = idx; 2946 *cur_val = idx;
2590 return 1; 2947 return 1;
2591} 2948}
2949EXPORT_SYMBOL_HDA(snd_hda_input_mux_put);
2592 2950
2593 2951
2594/* 2952/*
@@ -2641,6 +2999,7 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
2641 mutex_unlock(&codec->spdif_mutex); 2999 mutex_unlock(&codec->spdif_mutex);
2642 return 0; 3000 return 0;
2643} 3001}
3002EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
2644 3003
2645int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, 3004int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2646 struct hda_multi_out *mout, 3005 struct hda_multi_out *mout,
@@ -2653,6 +3012,7 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
2653 mutex_unlock(&codec->spdif_mutex); 3012 mutex_unlock(&codec->spdif_mutex);
2654 return 0; 3013 return 0;
2655} 3014}
3015EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
2656 3016
2657/* 3017/*
2658 * release the digital out 3018 * release the digital out
@@ -2665,6 +3025,7 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
2665 mutex_unlock(&codec->spdif_mutex); 3025 mutex_unlock(&codec->spdif_mutex);
2666 return 0; 3026 return 0;
2667} 3027}
3028EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
2668 3029
2669/* 3030/*
2670 * set up more restrictions for analog out 3031 * set up more restrictions for analog out
@@ -2704,6 +3065,7 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
2704 return snd_pcm_hw_constraint_step(substream->runtime, 0, 3065 return snd_pcm_hw_constraint_step(substream->runtime, 0,
2705 SNDRV_PCM_HW_PARAM_CHANNELS, 2); 3066 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2706} 3067}
3068EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
2707 3069
2708/* 3070/*
2709 * set up the i/o for analog out 3071 * set up the i/o for analog out
@@ -2762,6 +3124,7 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2762 } 3124 }
2763 return 0; 3125 return 0;
2764} 3126}
3127EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
2765 3128
2766/* 3129/*
2767 * clean up the setting for analog out 3130 * clean up the setting for analog out
@@ -2788,6 +3151,7 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2788 mutex_unlock(&codec->spdif_mutex); 3151 mutex_unlock(&codec->spdif_mutex);
2789 return 0; 3152 return 0;
2790} 3153}
3154EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup);
2791 3155
2792/* 3156/*
2793 * Helper for automatic pin configuration 3157 * Helper for automatic pin configuration
@@ -3073,11 +3437,13 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3073 3437
3074 return 0; 3438 return 0;
3075} 3439}
3440EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config);
3076 3441
3077/* labels for input pins */ 3442/* labels for input pins */
3078const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = { 3443const char *auto_pin_cfg_labels[AUTO_PIN_LAST] = {
3079 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux" 3444 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
3080}; 3445};
3446EXPORT_SYMBOL_HDA(auto_pin_cfg_labels);
3081 3447
3082 3448
3083#ifdef CONFIG_PM 3449#ifdef CONFIG_PM
@@ -3105,11 +3471,11 @@ int snd_hda_suspend(struct hda_bus *bus, pm_message_t state)
3105 } 3471 }
3106 return 0; 3472 return 0;
3107} 3473}
3474EXPORT_SYMBOL_HDA(snd_hda_suspend);
3108 3475
3109/** 3476/**
3110 * snd_hda_resume - resume the codecs 3477 * snd_hda_resume - resume the codecs
3111 * @bus: the HDA bus 3478 * @bus: the HDA bus
3112 * @state: resume state
3113 * 3479 *
3114 * Returns 0 if successful. 3480 * Returns 0 if successful.
3115 * 3481 *
@@ -3126,16 +3492,79 @@ int snd_hda_resume(struct hda_bus *bus)
3126 } 3492 }
3127 return 0; 3493 return 0;
3128} 3494}
3129#ifdef CONFIG_SND_HDA_POWER_SAVE 3495EXPORT_SYMBOL_HDA(snd_hda_resume);
3130int snd_hda_codecs_inuse(struct hda_bus *bus) 3496#endif /* CONFIG_PM */
3131{
3132 struct hda_codec *codec;
3133 3497
3134 list_for_each_entry(codec, &bus->codec_list, list) { 3498/*
3135 if (snd_hda_codec_needs_resume(codec)) 3499 * generic arrays
3136 return 1; 3500 */
3501
3502/* get a new element from the given array
3503 * if it exceeds the pre-allocated array size, re-allocate the array
3504 */
3505void *snd_array_new(struct snd_array *array)
3506{
3507 if (array->used >= array->alloced) {
3508 int num = array->alloced + array->alloc_align;
3509 void *nlist;
3510 if (snd_BUG_ON(num >= 4096))
3511 return NULL;
3512 nlist = kcalloc(num + 1, array->elem_size, GFP_KERNEL);
3513 if (!nlist)
3514 return NULL;
3515 if (array->list) {
3516 memcpy(nlist, array->list,
3517 array->elem_size * array->alloced);
3518 kfree(array->list);
3519 }
3520 array->list = nlist;
3521 array->alloced = num;
3137 } 3522 }
3138 return 0; 3523 return snd_array_elem(array, array->used++);
3139} 3524}
3140#endif 3525EXPORT_SYMBOL_HDA(snd_array_new);
3141#endif 3526
3527/* free the given array elements */
3528void snd_array_free(struct snd_array *array)
3529{
3530 kfree(array->list);
3531 array->used = 0;
3532 array->alloced = 0;
3533 array->list = NULL;
3534}
3535EXPORT_SYMBOL_HDA(snd_array_free);
3536
3537/*
3538 * used by hda_proc.c and hda_eld.c
3539 */
3540void snd_print_pcm_rates(int pcm, char *buf, int buflen)
3541{
3542 static unsigned int rates[] = {
3543 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
3544 96000, 176400, 192000, 384000
3545 };
3546 int i, j;
3547
3548 for (i = 0, j = 0; i < ARRAY_SIZE(rates); i++)
3549 if (pcm & (1 << i))
3550 j += snprintf(buf + j, buflen - j, " %d", rates[i]);
3551
3552 buf[j] = '\0'; /* necessary when j == 0 */
3553}
3554EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
3555
3556void snd_print_pcm_bits(int pcm, char *buf, int buflen)
3557{
3558 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
3559 int i, j;
3560
3561 for (i = 0, j = 0; i < ARRAY_SIZE(bits); i++)
3562 if (pcm & (AC_SUPPCM_BITS_8 << i))
3563 j += snprintf(buf + j, buflen - j, " %d", bits[i]);
3564
3565 buf[j] = '\0'; /* necessary when j == 0 */
3566}
3567EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
3568
3569MODULE_DESCRIPTION("HDA codec core");
3570MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 60468f562400..729fc7642d7f 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -520,6 +520,36 @@ enum {
520#define HDA_MAX_CODEC_ADDRESS 0x0f 520#define HDA_MAX_CODEC_ADDRESS 0x0f
521 521
522/* 522/*
523 * generic arrays
524 */
525struct snd_array {
526 unsigned int used;
527 unsigned int alloced;
528 unsigned int elem_size;
529 unsigned int alloc_align;
530 void *list;
531};
532
533void *snd_array_new(struct snd_array *array);
534void snd_array_free(struct snd_array *array);
535static inline void snd_array_init(struct snd_array *array, unsigned int size,
536 unsigned int align)
537{
538 array->elem_size = size;
539 array->alloc_align = align;
540}
541
542static inline void *snd_array_elem(struct snd_array *array, unsigned int idx)
543{
544 return array->list + idx * array->elem_size;
545}
546
547static inline unsigned int snd_array_index(struct snd_array *array, void *ptr)
548{
549 return (unsigned long)(ptr - array->list) / array->elem_size;
550}
551
552/*
523 * Structures 553 * Structures
524 */ 554 */
525 555
@@ -536,15 +566,17 @@ typedef u16 hda_nid_t;
536/* bus operators */ 566/* bus operators */
537struct hda_bus_ops { 567struct hda_bus_ops {
538 /* send a single command */ 568 /* send a single command */
539 int (*command)(struct hda_codec *codec, hda_nid_t nid, int direct, 569 int (*command)(struct hda_bus *bus, unsigned int cmd);
540 unsigned int verb, unsigned int parm);
541 /* get a response from the last command */ 570 /* get a response from the last command */
542 unsigned int (*get_response)(struct hda_codec *codec); 571 unsigned int (*get_response)(struct hda_bus *bus);
543 /* free the private data */ 572 /* free the private data */
544 void (*private_free)(struct hda_bus *); 573 void (*private_free)(struct hda_bus *);
574 /* attach a PCM stream */
575 int (*attach_pcm)(struct hda_bus *bus, struct hda_codec *codec,
576 struct hda_pcm *pcm);
545#ifdef CONFIG_SND_HDA_POWER_SAVE 577#ifdef CONFIG_SND_HDA_POWER_SAVE
546 /* notify power-up/down from codec to controller */ 578 /* notify power-up/down from codec to controller */
547 void (*pm_notify)(struct hda_codec *codec); 579 void (*pm_notify)(struct hda_bus *bus);
548#endif 580#endif
549}; 581};
550 582
@@ -553,6 +585,7 @@ struct hda_bus_template {
553 void *private_data; 585 void *private_data;
554 struct pci_dev *pci; 586 struct pci_dev *pci;
555 const char *modelname; 587 const char *modelname;
588 int *power_save;
556 struct hda_bus_ops ops; 589 struct hda_bus_ops ops;
557}; 590};
558 591
@@ -569,6 +602,7 @@ struct hda_bus {
569 void *private_data; 602 void *private_data;
570 struct pci_dev *pci; 603 struct pci_dev *pci;
571 const char *modelname; 604 const char *modelname;
605 int *power_save;
572 struct hda_bus_ops ops; 606 struct hda_bus_ops ops;
573 607
574 /* codec linked list */ 608 /* codec linked list */
@@ -581,10 +615,12 @@ struct hda_bus {
581 /* unsolicited event queue */ 615 /* unsolicited event queue */
582 struct hda_bus_unsolicited *unsol; 616 struct hda_bus_unsolicited *unsol;
583 617
584 struct snd_info_entry *proc; 618 /* assigned PCMs */
619 DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES);
585 620
586 /* misc op flags */ 621 /* misc op flags */
587 unsigned int needs_damn_long_delay :1; 622 unsigned int needs_damn_long_delay :1;
623 unsigned int shutdown :1; /* being unloaded */
588}; 624};
589 625
590/* 626/*
@@ -604,6 +640,16 @@ struct hda_codec_preset {
604 int (*patch)(struct hda_codec *codec); 640 int (*patch)(struct hda_codec *codec);
605}; 641};
606 642
643struct hda_codec_preset_list {
644 const struct hda_codec_preset *preset;
645 struct module *owner;
646 struct list_head list;
647};
648
649/* initial hook */
650int snd_hda_add_codec_preset(struct hda_codec_preset_list *preset);
651int snd_hda_delete_codec_preset(struct hda_codec_preset_list *preset);
652
607/* ops set by the preset patch */ 653/* ops set by the preset patch */
608struct hda_codec_ops { 654struct hda_codec_ops {
609 int (*build_controls)(struct hda_codec *codec); 655 int (*build_controls)(struct hda_codec *codec);
@@ -635,10 +681,7 @@ struct hda_amp_info {
635 681
636struct hda_cache_rec { 682struct hda_cache_rec {
637 u16 hash[64]; /* hash table for index */ 683 u16 hash[64]; /* hash table for index */
638 unsigned int num_entries; /* number of assigned entries */ 684 struct snd_array buf; /* record entries */
639 unsigned int size; /* allocated size */
640 unsigned int record_size; /* record size (including header) */
641 void *buffer; /* hash table entries */
642}; 685};
643 686
644/* PCM callbacks */ 687/* PCM callbacks */
@@ -680,7 +723,8 @@ struct hda_pcm {
680 char *name; 723 char *name;
681 struct hda_pcm_stream stream[2]; 724 struct hda_pcm_stream stream[2];
682 unsigned int pcm_type; /* HDA_PCM_TYPE_XXX */ 725 unsigned int pcm_type; /* HDA_PCM_TYPE_XXX */
683 int device; /* assigned device number */ 726 int device; /* device number to assign */
727 struct snd_pcm *pcm; /* assigned PCM instance */
684}; 728};
685 729
686/* codec information */ 730/* codec information */
@@ -699,6 +743,9 @@ struct hda_codec {
699 743
700 /* detected preset */ 744 /* detected preset */
701 const struct hda_codec_preset *preset; 745 const struct hda_codec_preset *preset;
746 struct module *owner;
747 const char *name; /* codec name */
748 const char *modelname; /* model name for preset */
702 749
703 /* set by patch */ 750 /* set by patch */
704 struct hda_codec_ops patch_ops; 751 struct hda_codec_ops patch_ops;
@@ -718,6 +765,8 @@ struct hda_codec {
718 hda_nid_t start_nid; 765 hda_nid_t start_nid;
719 u32 *wcaps; 766 u32 *wcaps;
720 767
768 struct snd_array mixers; /* list of assigned mixer elements */
769
721 struct hda_cache_rec amp_cache; /* cache for amp access */ 770 struct hda_cache_rec amp_cache; /* cache for amp access */
722 struct hda_cache_rec cmd_cache; /* cache for other commands */ 771 struct hda_cache_rec cmd_cache; /* cache for other commands */
723 772
@@ -727,7 +776,11 @@ struct hda_codec {
727 unsigned int spdif_in_enable; /* SPDIF input enable? */ 776 unsigned int spdif_in_enable; /* SPDIF input enable? */
728 hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ 777 hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
729 778
779#ifdef CONFIG_SND_HDA_HWDEP
730 struct snd_hwdep *hwdep; /* assigned hwdep device */ 780 struct snd_hwdep *hwdep; /* assigned hwdep device */
781 struct snd_array init_verbs; /* additional init verbs */
782 struct snd_array hints; /* additional hints */
783#endif
731 784
732 /* misc flags */ 785 /* misc flags */
733 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each 786 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
@@ -740,6 +793,10 @@ struct hda_codec {
740 int power_count; /* current (global) power refcount */ 793 int power_count; /* current (global) power refcount */
741 struct delayed_work power_work; /* delayed task for powerdown */ 794 struct delayed_work power_work; /* delayed task for powerdown */
742#endif 795#endif
796
797 /* codec-specific additional proc output */
798 void (*proc_widget_hook)(struct snd_info_buffer *buffer,
799 struct hda_codec *codec, hda_nid_t nid);
743}; 800};
744 801
745/* direction */ 802/* direction */
@@ -754,7 +811,7 @@ enum {
754int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp, 811int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp,
755 struct hda_bus **busp); 812 struct hda_bus **busp);
756int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 813int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
757 struct hda_codec **codecp); 814 int do_init, struct hda_codec **codecp);
758 815
759/* 816/*
760 * low level functions 817 * low level functions
@@ -799,11 +856,13 @@ void snd_hda_codec_resume_cache(struct hda_codec *codec);
799 * Mixer 856 * Mixer
800 */ 857 */
801int snd_hda_build_controls(struct hda_bus *bus); 858int snd_hda_build_controls(struct hda_bus *bus);
859int snd_hda_codec_build_controls(struct hda_codec *codec);
802 860
803/* 861/*
804 * PCM 862 * PCM
805 */ 863 */
806int snd_hda_build_pcms(struct hda_bus *bus); 864int snd_hda_build_pcms(struct hda_bus *bus);
865int snd_hda_codec_build_pcms(struct hda_codec *codec);
807void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, 866void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
808 u32 stream_tag, 867 u32 stream_tag,
809 int channel_id, int format); 868 int channel_id, int format);
@@ -812,8 +871,6 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
812 unsigned int channels, 871 unsigned int channels,
813 unsigned int format, 872 unsigned int format,
814 unsigned int maxbps); 873 unsigned int maxbps);
815int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
816 u32 *ratesp, u64 *formatsp, unsigned int *bpsp);
817int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid, 874int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
818 unsigned int format); 875 unsigned int format);
819 876
@@ -831,18 +888,38 @@ int snd_hda_resume(struct hda_bus *bus);
831#endif 888#endif
832 889
833/* 890/*
891 * get widget information
892 */
893const char *snd_hda_get_jack_connectivity(u32 cfg);
894const char *snd_hda_get_jack_type(u32 cfg);
895const char *snd_hda_get_jack_location(u32 cfg);
896
897/*
834 * power saving 898 * power saving
835 */ 899 */
836#ifdef CONFIG_SND_HDA_POWER_SAVE 900#ifdef CONFIG_SND_HDA_POWER_SAVE
837void snd_hda_power_up(struct hda_codec *codec); 901void snd_hda_power_up(struct hda_codec *codec);
838void snd_hda_power_down(struct hda_codec *codec); 902void snd_hda_power_down(struct hda_codec *codec);
839#define snd_hda_codec_needs_resume(codec) codec->power_count 903#define snd_hda_codec_needs_resume(codec) codec->power_count
840int snd_hda_codecs_inuse(struct hda_bus *bus);
841#else 904#else
842static inline void snd_hda_power_up(struct hda_codec *codec) {} 905static inline void snd_hda_power_up(struct hda_codec *codec) {}
843static inline void snd_hda_power_down(struct hda_codec *codec) {} 906static inline void snd_hda_power_down(struct hda_codec *codec) {}
844#define snd_hda_codec_needs_resume(codec) 1 907#define snd_hda_codec_needs_resume(codec) 1
845#define snd_hda_codecs_inuse(bus) 1 908#endif
909
910/*
911 * Codec modularization
912 */
913
914/* Export symbols only for communication with codec drivers;
915 * When built in kernel, all HD-audio drivers are supposed to be statically
916 * linked to the kernel. Thus, the symbols don't have to (or shouldn't) be
917 * exported unless it's built as a module.
918 */
919#ifdef MODULE
920#define EXPORT_SYMBOL_HDA(sym) EXPORT_SYMBOL_GPL(sym)
921#else
922#define EXPORT_SYMBOL_HDA(sym)
846#endif 923#endif
847 924
848#endif /* __SOUND_HDA_CODEC_H */ 925#endif /* __SOUND_HDA_CODEC_H */
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
new file mode 100644
index 000000000000..fcad5ec31773
--- /dev/null
+++ b/sound/pci/hda/hda_eld.c
@@ -0,0 +1,590 @@
1/*
2 * Generic routines and proc interface for ELD(EDID Like Data) information
3 *
4 * Copyright(c) 2008 Intel Corporation.
5 *
6 * Authors:
7 * Wu Fengguang <wfg@linux.intel.com>
8 *
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <linux/init.h>
25#include <sound/core.h>
26#include <asm/unaligned.h>
27#include "hda_codec.h"
28#include "hda_local.h"
29
30enum eld_versions {
31 ELD_VER_CEA_861D = 2,
32 ELD_VER_PARTIAL = 31,
33};
34
35enum cea_edid_versions {
36 CEA_EDID_VER_NONE = 0,
37 CEA_EDID_VER_CEA861 = 1,
38 CEA_EDID_VER_CEA861A = 2,
39 CEA_EDID_VER_CEA861BCD = 3,
40 CEA_EDID_VER_RESERVED = 4,
41};
42
43static char *cea_speaker_allocation_names[] = {
44 /* 0 */ "FL/FR",
45 /* 1 */ "LFE",
46 /* 2 */ "FC",
47 /* 3 */ "RL/RR",
48 /* 4 */ "RC",
49 /* 5 */ "FLC/FRC",
50 /* 6 */ "RLC/RRC",
51 /* 7 */ "FLW/FRW",
52 /* 8 */ "FLH/FRH",
53 /* 9 */ "TC",
54 /* 10 */ "FCH",
55};
56
57static char *eld_connection_type_names[4] = {
58 "HDMI",
59 "DisplayPort",
60 "2-reserved",
61 "3-reserved"
62};
63
64enum cea_audio_coding_types {
65 AUDIO_CODING_TYPE_REF_STREAM_HEADER = 0,
66 AUDIO_CODING_TYPE_LPCM = 1,
67 AUDIO_CODING_TYPE_AC3 = 2,
68 AUDIO_CODING_TYPE_MPEG1 = 3,
69 AUDIO_CODING_TYPE_MP3 = 4,
70 AUDIO_CODING_TYPE_MPEG2 = 5,
71 AUDIO_CODING_TYPE_AACLC = 6,
72 AUDIO_CODING_TYPE_DTS = 7,
73 AUDIO_CODING_TYPE_ATRAC = 8,
74 AUDIO_CODING_TYPE_SACD = 9,
75 AUDIO_CODING_TYPE_EAC3 = 10,
76 AUDIO_CODING_TYPE_DTS_HD = 11,
77 AUDIO_CODING_TYPE_MLP = 12,
78 AUDIO_CODING_TYPE_DST = 13,
79 AUDIO_CODING_TYPE_WMAPRO = 14,
80 AUDIO_CODING_TYPE_REF_CXT = 15,
81 /* also include valid xtypes below */
82 AUDIO_CODING_TYPE_HE_AAC = 15,
83 AUDIO_CODING_TYPE_HE_AAC2 = 16,
84 AUDIO_CODING_TYPE_MPEG_SURROUND = 17,
85};
86
87enum cea_audio_coding_xtypes {
88 AUDIO_CODING_XTYPE_HE_REF_CT = 0,
89 AUDIO_CODING_XTYPE_HE_AAC = 1,
90 AUDIO_CODING_XTYPE_HE_AAC2 = 2,
91 AUDIO_CODING_XTYPE_MPEG_SURROUND = 3,
92 AUDIO_CODING_XTYPE_FIRST_RESERVED = 4,
93};
94
95static char *cea_audio_coding_type_names[] = {
96 /* 0 */ "undefined",
97 /* 1 */ "LPCM",
98 /* 2 */ "AC-3",
99 /* 3 */ "MPEG1",
100 /* 4 */ "MP3",
101 /* 5 */ "MPEG2",
102 /* 6 */ "AAC-LC",
103 /* 7 */ "DTS",
104 /* 8 */ "ATRAC",
105 /* 9 */ "DSD (One Bit Audio)",
106 /* 10 */ "E-AC-3/DD+ (Dolby Digital Plus)",
107 /* 11 */ "DTS-HD",
108 /* 12 */ "MLP (Dolby TrueHD)",
109 /* 13 */ "DST",
110 /* 14 */ "WMAPro",
111 /* 15 */ "HE-AAC",
112 /* 16 */ "HE-AACv2",
113 /* 17 */ "MPEG Surround",
114};
115
116/*
117 * The following two lists are shared between
118 * - HDMI audio InfoFrame (source to sink)
119 * - CEA E-EDID Extension (sink to source)
120 */
121
122/*
123 * SS1:SS0 index => sample size
124 */
125static int cea_sample_sizes[4] = {
126 0, /* 0: Refer to Stream Header */
127 AC_SUPPCM_BITS_16, /* 1: 16 bits */
128 AC_SUPPCM_BITS_20, /* 2: 20 bits */
129 AC_SUPPCM_BITS_24, /* 3: 24 bits */
130};
131
132/*
133 * SF2:SF1:SF0 index => sampling frequency
134 */
135static int cea_sampling_frequencies[8] = {
136 0, /* 0: Refer to Stream Header */
137 SNDRV_PCM_RATE_32000, /* 1: 32000Hz */
138 SNDRV_PCM_RATE_44100, /* 2: 44100Hz */
139 SNDRV_PCM_RATE_48000, /* 3: 48000Hz */
140 SNDRV_PCM_RATE_88200, /* 4: 88200Hz */
141 SNDRV_PCM_RATE_96000, /* 5: 96000Hz */
142 SNDRV_PCM_RATE_176400, /* 6: 176400Hz */
143 SNDRV_PCM_RATE_192000, /* 7: 192000Hz */
144};
145
146static unsigned char hdmi_get_eld_byte(struct hda_codec *codec, hda_nid_t nid,
147 int byte_index)
148{
149 unsigned int val;
150
151 val = snd_hda_codec_read(codec, nid, 0,
152 AC_VERB_GET_HDMI_ELDD, byte_index);
153
154#ifdef BE_PARANOID
155 printk(KERN_INFO "HDMI: ELD data byte %d: 0x%x\n", byte_index, val);
156#endif
157
158 if ((val & AC_ELDD_ELD_VALID) == 0) {
159 snd_printd(KERN_INFO "HDMI: invalid ELD data byte %d\n",
160 byte_index);
161 val = 0;
162 }
163
164 return val & AC_ELDD_ELD_DATA;
165}
166
167#define GRAB_BITS(buf, byte, lowbit, bits) \
168({ \
169 BUILD_BUG_ON(lowbit > 7); \
170 BUILD_BUG_ON(bits > 8); \
171 BUILD_BUG_ON(bits <= 0); \
172 \
173 (buf[byte] >> (lowbit)) & ((1 << (bits)) - 1); \
174})
175
176static void hdmi_update_short_audio_desc(struct cea_sad *a,
177 const unsigned char *buf)
178{
179 int i;
180 int val;
181
182 val = GRAB_BITS(buf, 1, 0, 7);
183 a->rates = 0;
184 for (i = 0; i < 7; i++)
185 if (val & (1 << i))
186 a->rates |= cea_sampling_frequencies[i + 1];
187
188 a->channels = GRAB_BITS(buf, 0, 0, 3);
189 a->channels++;
190
191 a->format = GRAB_BITS(buf, 0, 3, 4);
192 switch (a->format) {
193 case AUDIO_CODING_TYPE_REF_STREAM_HEADER:
194 snd_printd(KERN_INFO
195 "HDMI: audio coding type 0 not expected\n");
196 break;
197
198 case AUDIO_CODING_TYPE_LPCM:
199 val = GRAB_BITS(buf, 2, 0, 3);
200 a->sample_bits = 0;
201 for (i = 0; i < 3; i++)
202 if (val & (1 << i))
203 a->sample_bits |= cea_sample_sizes[i + 1];
204 break;
205
206 case AUDIO_CODING_TYPE_AC3:
207 case AUDIO_CODING_TYPE_MPEG1:
208 case AUDIO_CODING_TYPE_MP3:
209 case AUDIO_CODING_TYPE_MPEG2:
210 case AUDIO_CODING_TYPE_AACLC:
211 case AUDIO_CODING_TYPE_DTS:
212 case AUDIO_CODING_TYPE_ATRAC:
213 a->max_bitrate = GRAB_BITS(buf, 2, 0, 8);
214 a->max_bitrate *= 8000;
215 break;
216
217 case AUDIO_CODING_TYPE_SACD:
218 break;
219
220 case AUDIO_CODING_TYPE_EAC3:
221 break;
222
223 case AUDIO_CODING_TYPE_DTS_HD:
224 break;
225
226 case AUDIO_CODING_TYPE_MLP:
227 break;
228
229 case AUDIO_CODING_TYPE_DST:
230 break;
231
232 case AUDIO_CODING_TYPE_WMAPRO:
233 a->profile = GRAB_BITS(buf, 2, 0, 3);
234 break;
235
236 case AUDIO_CODING_TYPE_REF_CXT:
237 a->format = GRAB_BITS(buf, 2, 3, 5);
238 if (a->format == AUDIO_CODING_XTYPE_HE_REF_CT ||
239 a->format >= AUDIO_CODING_XTYPE_FIRST_RESERVED) {
240 snd_printd(KERN_INFO
241 "HDMI: audio coding xtype %d not expected\n",
242 a->format);
243 a->format = 0;
244 } else
245 a->format += AUDIO_CODING_TYPE_HE_AAC -
246 AUDIO_CODING_XTYPE_HE_AAC;
247 break;
248 }
249}
250
251/*
252 * Be careful, ELD buf could be totally rubbish!
253 */
254static int hdmi_update_eld(struct hdmi_eld *e,
255 const unsigned char *buf, int size)
256{
257 int mnl;
258 int i;
259
260 e->eld_ver = GRAB_BITS(buf, 0, 3, 5);
261 if (e->eld_ver != ELD_VER_CEA_861D &&
262 e->eld_ver != ELD_VER_PARTIAL) {
263 snd_printd(KERN_INFO "HDMI: Unknown ELD version %d\n",
264 e->eld_ver);
265 goto out_fail;
266 }
267
268 e->eld_size = size;
269 e->baseline_len = GRAB_BITS(buf, 2, 0, 8);
270 mnl = GRAB_BITS(buf, 4, 0, 5);
271 e->cea_edid_ver = GRAB_BITS(buf, 4, 5, 3);
272
273 e->support_hdcp = GRAB_BITS(buf, 5, 0, 1);
274 e->support_ai = GRAB_BITS(buf, 5, 1, 1);
275 e->conn_type = GRAB_BITS(buf, 5, 2, 2);
276 e->sad_count = GRAB_BITS(buf, 5, 4, 4);
277
278 e->aud_synch_delay = GRAB_BITS(buf, 6, 0, 8) * 2;
279 e->spk_alloc = GRAB_BITS(buf, 7, 0, 7);
280
281 e->port_id = get_unaligned_le64(buf + 8);
282
283 /* not specified, but the spec's tendency is little endian */
284 e->manufacture_id = get_unaligned_le16(buf + 16);
285 e->product_id = get_unaligned_le16(buf + 18);
286
287 if (mnl > ELD_MAX_MNL) {
288 snd_printd(KERN_INFO "HDMI: MNL is reserved value %d\n", mnl);
289 goto out_fail;
290 } else if (ELD_FIXED_BYTES + mnl > size) {
291 snd_printd(KERN_INFO "HDMI: out of range MNL %d\n", mnl);
292 goto out_fail;
293 } else
294 strlcpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl);
295
296 for (i = 0; i < e->sad_count; i++) {
297 if (ELD_FIXED_BYTES + mnl + 3 * (i + 1) > size) {
298 snd_printd(KERN_INFO "HDMI: out of range SAD %d\n", i);
299 goto out_fail;
300 }
301 hdmi_update_short_audio_desc(e->sad + i,
302 buf + ELD_FIXED_BYTES + mnl + 3 * i);
303 }
304
305 return 0;
306
307out_fail:
308 e->eld_ver = 0;
309 return -EINVAL;
310}
311
312static int hdmi_present_sense(struct hda_codec *codec, hda_nid_t nid)
313{
314 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0);
315}
316
317static int hdmi_eld_valid(struct hda_codec *codec, hda_nid_t nid)
318{
319 int eldv;
320 int present;
321
322 present = hdmi_present_sense(codec, nid);
323 eldv = (present & AC_PINSENSE_ELDV);
324 present = (present & AC_PINSENSE_PRESENCE);
325
326#ifdef CONFIG_SND_DEBUG_VERBOSE
327 printk(KERN_INFO "HDMI: sink_present = %d, eld_valid = %d\n",
328 !!present, !!eldv);
329#endif
330
331 return eldv && present;
332}
333
334int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid)
335{
336 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_SIZE,
337 AC_DIPSIZE_ELD_BUF);
338}
339
340int snd_hdmi_get_eld(struct hdmi_eld *eld,
341 struct hda_codec *codec, hda_nid_t nid)
342{
343 int i;
344 int ret;
345 int size;
346 unsigned char *buf;
347
348 if (!hdmi_eld_valid(codec, nid))
349 return -ENOENT;
350
351 size = snd_hdmi_get_eld_size(codec, nid);
352 if (size == 0) {
353 /* wfg: workaround for ASUS P5E-VM HDMI board */
354 snd_printd(KERN_INFO "HDMI: ELD buf size is 0, force 128\n");
355 size = 128;
356 }
357 if (size < ELD_FIXED_BYTES || size > PAGE_SIZE) {
358 snd_printd(KERN_INFO "HDMI: invalid ELD buf size %d\n", size);
359 return -ERANGE;
360 }
361
362 buf = kmalloc(size, GFP_KERNEL);
363 if (!buf)
364 return -ENOMEM;
365
366 for (i = 0; i < size; i++)
367 buf[i] = hdmi_get_eld_byte(codec, nid, i);
368
369 ret = hdmi_update_eld(eld, buf, size);
370
371 kfree(buf);
372 return ret;
373}
374
375static void hdmi_show_short_audio_desc(struct cea_sad *a)
376{
377 char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
378 char buf2[8 + SND_PRINT_BITS_ADVISED_BUFSIZE] = ", bits =";
379
380 if (!a->format)
381 return;
382
383 snd_print_pcm_rates(a->rates, buf, sizeof(buf));
384
385 if (a->format == AUDIO_CODING_TYPE_LPCM)
386 snd_print_pcm_bits(a->sample_bits, buf2 + 8, sizeof(buf2 - 8));
387 else if (a->max_bitrate)
388 snprintf(buf2, sizeof(buf2),
389 ", max bitrate = %d", a->max_bitrate);
390 else
391 buf2[0] = '\0';
392
393 printk(KERN_INFO "HDMI: supports coding type %s:"
394 " channels = %d, rates =%s%s\n",
395 cea_audio_coding_type_names[a->format],
396 a->channels,
397 buf,
398 buf2);
399}
400
401void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen)
402{
403 int i, j;
404
405 for (i = 0, j = 0; i < ARRAY_SIZE(cea_speaker_allocation_names); i++) {
406 if (spk_alloc & (1 << i))
407 j += snprintf(buf + j, buflen - j, " %s",
408 cea_speaker_allocation_names[i]);
409 }
410 buf[j] = '\0'; /* necessary when j == 0 */
411}
412
413void snd_hdmi_show_eld(struct hdmi_eld *e)
414{
415 int i;
416
417 printk(KERN_INFO "HDMI: detected monitor %s at connection type %s\n",
418 e->monitor_name,
419 eld_connection_type_names[e->conn_type]);
420
421 if (e->spk_alloc) {
422 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
423 snd_print_channel_allocation(e->spk_alloc, buf, sizeof(buf));
424 printk(KERN_INFO "HDMI: available speakers:%s\n", buf);
425 }
426
427 for (i = 0; i < e->sad_count; i++)
428 hdmi_show_short_audio_desc(e->sad + i);
429}
430
431#ifdef CONFIG_PROC_FS
432
433static void hdmi_print_sad_info(int i, struct cea_sad *a,
434 struct snd_info_buffer *buffer)
435{
436 char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
437
438 snd_iprintf(buffer, "sad%d_coding_type\t[0x%x] %s\n",
439 i, a->format, cea_audio_coding_type_names[a->format]);
440 snd_iprintf(buffer, "sad%d_channels\t\t%d\n", i, a->channels);
441
442 snd_print_pcm_rates(a->rates, buf, sizeof(buf));
443 snd_iprintf(buffer, "sad%d_rates\t\t[0x%x]%s\n", i, a->rates, buf);
444
445 if (a->format == AUDIO_CODING_TYPE_LPCM) {
446 snd_print_pcm_bits(a->sample_bits, buf, sizeof(buf));
447 snd_iprintf(buffer, "sad%d_bits\t\t[0x%x]%s\n",
448 i, a->sample_bits, buf);
449 }
450
451 if (a->max_bitrate)
452 snd_iprintf(buffer, "sad%d_max_bitrate\t%d\n",
453 i, a->max_bitrate);
454
455 if (a->profile)
456 snd_iprintf(buffer, "sad%d_profile\t\t%d\n", i, a->profile);
457}
458
459static void hdmi_print_eld_info(struct snd_info_entry *entry,
460 struct snd_info_buffer *buffer)
461{
462 struct hdmi_eld *e = entry->private_data;
463 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
464 int i;
465 static char *eld_versoin_names[32] = {
466 "reserved",
467 "reserved",
468 "CEA-861D or below",
469 [3 ... 30] = "reserved",
470 [31] = "partial"
471 };
472 static char *cea_edid_version_names[8] = {
473 "no CEA EDID Timing Extension block present",
474 "CEA-861",
475 "CEA-861-A",
476 "CEA-861-B, C or D",
477 [4 ... 7] = "reserved"
478 };
479
480 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name);
481 snd_iprintf(buffer, "connection_type\t\t%s\n",
482 eld_connection_type_names[e->conn_type]);
483 snd_iprintf(buffer, "eld_version\t\t[0x%x] %s\n", e->eld_ver,
484 eld_versoin_names[e->eld_ver]);
485 snd_iprintf(buffer, "edid_version\t\t[0x%x] %s\n", e->cea_edid_ver,
486 cea_edid_version_names[e->cea_edid_ver]);
487 snd_iprintf(buffer, "manufacture_id\t\t0x%x\n", e->manufacture_id);
488 snd_iprintf(buffer, "product_id\t\t0x%x\n", e->product_id);
489 snd_iprintf(buffer, "port_id\t\t\t0x%llx\n", (long long)e->port_id);
490 snd_iprintf(buffer, "support_hdcp\t\t%d\n", e->support_hdcp);
491 snd_iprintf(buffer, "support_ai\t\t%d\n", e->support_ai);
492 snd_iprintf(buffer, "audio_sync_delay\t%d\n", e->aud_synch_delay);
493
494 snd_print_channel_allocation(e->spk_alloc, buf, sizeof(buf));
495 snd_iprintf(buffer, "speakers\t\t[0x%x]%s\n", e->spk_alloc, buf);
496
497 snd_iprintf(buffer, "sad_count\t\t%d\n", e->sad_count);
498
499 for (i = 0; i < e->sad_count; i++)
500 hdmi_print_sad_info(i, e->sad + i, buffer);
501}
502
503static void hdmi_write_eld_info(struct snd_info_entry *entry,
504 struct snd_info_buffer *buffer)
505{
506 struct hdmi_eld *e = entry->private_data;
507 char line[64];
508 char name[64];
509 char *sname;
510 long long val;
511 int n;
512
513 while (!snd_info_get_line(buffer, line, sizeof(line))) {
514 if (sscanf(line, "%s %llx", name, &val) != 2)
515 continue;
516 /*
517 * We don't allow modification to these fields:
518 * monitor_name manufacture_id product_id
519 * eld_version edid_version
520 */
521 if (!strcmp(name, "connection_type"))
522 e->conn_type = val;
523 else if (!strcmp(name, "port_id"))
524 e->port_id = val;
525 else if (!strcmp(name, "support_hdcp"))
526 e->support_hdcp = val;
527 else if (!strcmp(name, "support_ai"))
528 e->support_ai = val;
529 else if (!strcmp(name, "audio_sync_delay"))
530 e->aud_synch_delay = val;
531 else if (!strcmp(name, "speakers"))
532 e->spk_alloc = val;
533 else if (!strcmp(name, "sad_count"))
534 e->sad_count = val;
535 else if (!strncmp(name, "sad", 3)) {
536 sname = name + 4;
537 n = name[3] - '0';
538 if (name[4] >= '0' && name[4] <= '9') {
539 sname++;
540 n = 10 * n + name[4] - '0';
541 }
542 if (n < 0 || n > 31) /* double the CEA limit */
543 continue;
544 if (!strcmp(sname, "_coding_type"))
545 e->sad[n].format = val;
546 else if (!strcmp(sname, "_channels"))
547 e->sad[n].channels = val;
548 else if (!strcmp(sname, "_rates"))
549 e->sad[n].rates = val;
550 else if (!strcmp(sname, "_bits"))
551 e->sad[n].sample_bits = val;
552 else if (!strcmp(sname, "_max_bitrate"))
553 e->sad[n].max_bitrate = val;
554 else if (!strcmp(sname, "_profile"))
555 e->sad[n].profile = val;
556 if (n >= e->sad_count)
557 e->sad_count = n + 1;
558 }
559 }
560}
561
562
563int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld)
564{
565 char name[32];
566 struct snd_info_entry *entry;
567 int err;
568
569 snprintf(name, sizeof(name), "eld#%d", codec->addr);
570 err = snd_card_proc_new(codec->bus->card, name, &entry);
571 if (err < 0)
572 return err;
573
574 snd_info_set_text_ops(entry, eld, hdmi_print_eld_info);
575 entry->c.text.write = hdmi_write_eld_info;
576 entry->mode |= S_IWUSR;
577 eld->proc_entry = entry;
578
579 return 0;
580}
581
582void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld)
583{
584 if (!codec->bus->shutdown && eld->proc_entry) {
585 snd_device_free(codec->bus->card, eld->proc_entry);
586 eld->proc_entry = NULL;
587 }
588}
589
590#endif /* CONFIG_PROC_FS */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 0ca30894f7c6..65745e96dc70 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -723,7 +723,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
723 if (is_loopback) 723 if (is_loopback)
724 add_input_loopback(codec, node->nid, HDA_INPUT, index); 724 add_input_loopback(codec, node->nid, HDA_INPUT, index);
725 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); 725 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
726 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0) 726 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
727 if (err < 0)
727 return err; 728 return err;
728 created = 1; 729 created = 1;
729 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) && 730 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
@@ -732,7 +733,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
732 if (is_loopback) 733 if (is_loopback)
733 add_input_loopback(codec, node->nid, HDA_OUTPUT, 0); 734 add_input_loopback(codec, node->nid, HDA_OUTPUT, 0);
734 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); 735 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
735 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0) 736 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
737 if (err < 0)
736 return err; 738 return err;
737 created = 1; 739 created = 1;
738 } 740 }
@@ -745,14 +747,16 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
745 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) { 747 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) {
746 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT); 748 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT);
747 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); 749 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
748 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0) 750 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
751 if (err < 0)
749 return err; 752 return err;
750 created = 1; 753 created = 1;
751 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) && 754 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
752 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) { 755 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) {
753 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT); 756 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT);
754 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); 757 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
755 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0) 758 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
759 if (err < 0)
756 return err; 760 return err;
757 created = 1; 761 created = 1;
758 } 762 }
@@ -849,8 +853,8 @@ static int build_input_controls(struct hda_codec *codec)
849 } 853 }
850 854
851 /* create input MUX if multiple sources are available */ 855 /* create input MUX if multiple sources are available */
852 if ((err = snd_ctl_add(codec->bus->card, 856 err = snd_hda_ctl_add(codec, snd_ctl_new1(&cap_sel, codec));
853 snd_ctl_new1(&cap_sel, codec))) < 0) 857 if (err < 0)
854 return err; 858 return err;
855 859
856 /* no volume control? */ 860 /* no volume control? */
@@ -867,8 +871,8 @@ static int build_input_controls(struct hda_codec *codec)
867 HDA_CODEC_VOLUME(name, adc_node->nid, 871 HDA_CODEC_VOLUME(name, adc_node->nid,
868 spec->input_mux.items[i].index, 872 spec->input_mux.items[i].index,
869 HDA_INPUT); 873 HDA_INPUT);
870 if ((err = snd_ctl_add(codec->bus->card, 874 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
871 snd_ctl_new1(&knew, codec))) < 0) 875 if (err < 0)
872 return err; 876 return err;
873 } 877 }
874 878
@@ -1097,3 +1101,4 @@ int snd_hda_parse_generic_codec(struct hda_codec *codec)
1097 snd_hda_generic_free(codec); 1101 snd_hda_generic_free(codec);
1098 return err; 1102 return err;
1099} 1103}
1104EXPORT_SYMBOL(snd_hda_parse_generic_codec);
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index 6e18a422d993..300ab407cf42 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -23,10 +23,12 @@
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/compat.h> 24#include <linux/compat.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/ctype.h>
26#include <sound/core.h> 27#include <sound/core.h>
27#include "hda_codec.h" 28#include "hda_codec.h"
28#include "hda_local.h" 29#include "hda_local.h"
29#include <sound/hda_hwdep.h> 30#include <sound/hda_hwdep.h>
31#include <sound/minors.h>
30 32
31/* 33/*
32 * write/read an out-of-bound verb 34 * write/read an out-of-bound verb
@@ -95,7 +97,26 @@ static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file)
95 return 0; 97 return 0;
96} 98}
97 99
98int __devinit snd_hda_create_hwdep(struct hda_codec *codec) 100static void clear_hwdep_elements(struct hda_codec *codec)
101{
102 char **head;
103 int i;
104
105 /* clear init verbs */
106 snd_array_free(&codec->init_verbs);
107 /* clear hints */
108 head = codec->hints.list;
109 for (i = 0; i < codec->hints.used; i++, head++)
110 kfree(*head);
111 snd_array_free(&codec->hints);
112}
113
114static void hwdep_free(struct snd_hwdep *hwdep)
115{
116 clear_hwdep_elements(hwdep->private_data);
117}
118
119int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec)
99{ 120{
100 char hwname[16]; 121 char hwname[16];
101 struct snd_hwdep *hwdep; 122 struct snd_hwdep *hwdep;
@@ -109,6 +130,7 @@ int __devinit snd_hda_create_hwdep(struct hda_codec *codec)
109 sprintf(hwdep->name, "HDA Codec %d", codec->addr); 130 sprintf(hwdep->name, "HDA Codec %d", codec->addr);
110 hwdep->iface = SNDRV_HWDEP_IFACE_HDA; 131 hwdep->iface = SNDRV_HWDEP_IFACE_HDA;
111 hwdep->private_data = codec; 132 hwdep->private_data = codec;
133 hwdep->private_free = hwdep_free;
112 hwdep->exclusive = 1; 134 hwdep->exclusive = 1;
113 135
114 hwdep->ops.open = hda_hwdep_open; 136 hwdep->ops.open = hda_hwdep_open;
@@ -117,5 +139,215 @@ int __devinit snd_hda_create_hwdep(struct hda_codec *codec)
117 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat; 139 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat;
118#endif 140#endif
119 141
142 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32);
143 snd_array_init(&codec->hints, sizeof(char *), 32);
144
120 return 0; 145 return 0;
121} 146}
147
148#ifdef CONFIG_SND_HDA_RECONFIG
149
150/*
151 * sysfs interface
152 */
153
154static int clear_codec(struct hda_codec *codec)
155{
156 snd_hda_codec_reset(codec);
157 clear_hwdep_elements(codec);
158 return 0;
159}
160
161static int reconfig_codec(struct hda_codec *codec)
162{
163 int err;
164
165 snd_printk(KERN_INFO "hda-codec: reconfiguring\n");
166 snd_hda_codec_reset(codec);
167 err = snd_hda_codec_configure(codec);
168 if (err < 0)
169 return err;
170 /* rebuild PCMs */
171 err = snd_hda_codec_build_pcms(codec);
172 if (err < 0)
173 return err;
174 /* rebuild mixers */
175 err = snd_hda_codec_build_controls(codec);
176 if (err < 0)
177 return err;
178 return 0;
179}
180
181/*
182 * allocate a string at most len chars, and remove the trailing EOL
183 */
184static char *kstrndup_noeol(const char *src, size_t len)
185{
186 char *s = kstrndup(src, len, GFP_KERNEL);
187 char *p;
188 if (!s)
189 return NULL;
190 p = strchr(s, '\n');
191 if (p)
192 *p = 0;
193 return s;
194}
195
196#define CODEC_INFO_SHOW(type) \
197static ssize_t type##_show(struct device *dev, \
198 struct device_attribute *attr, \
199 char *buf) \
200{ \
201 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
202 struct hda_codec *codec = hwdep->private_data; \
203 return sprintf(buf, "0x%x\n", codec->type); \
204}
205
206#define CODEC_INFO_STR_SHOW(type) \
207static ssize_t type##_show(struct device *dev, \
208 struct device_attribute *attr, \
209 char *buf) \
210{ \
211 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
212 struct hda_codec *codec = hwdep->private_data; \
213 return sprintf(buf, "%s\n", \
214 codec->type ? codec->type : ""); \
215}
216
217CODEC_INFO_SHOW(vendor_id);
218CODEC_INFO_SHOW(subsystem_id);
219CODEC_INFO_SHOW(revision_id);
220CODEC_INFO_SHOW(afg);
221CODEC_INFO_SHOW(mfg);
222CODEC_INFO_STR_SHOW(name);
223CODEC_INFO_STR_SHOW(modelname);
224
225#define CODEC_INFO_STORE(type) \
226static ssize_t type##_store(struct device *dev, \
227 struct device_attribute *attr, \
228 const char *buf, size_t count) \
229{ \
230 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
231 struct hda_codec *codec = hwdep->private_data; \
232 char *after; \
233 codec->type = simple_strtoul(buf, &after, 0); \
234 return count; \
235}
236
237#define CODEC_INFO_STR_STORE(type) \
238static ssize_t type##_store(struct device *dev, \
239 struct device_attribute *attr, \
240 const char *buf, size_t count) \
241{ \
242 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
243 struct hda_codec *codec = hwdep->private_data; \
244 char *s = kstrndup_noeol(buf, 64); \
245 if (!s) \
246 return -ENOMEM; \
247 kfree(codec->type); \
248 codec->type = s; \
249 return count; \
250}
251
252CODEC_INFO_STORE(vendor_id);
253CODEC_INFO_STORE(subsystem_id);
254CODEC_INFO_STORE(revision_id);
255CODEC_INFO_STR_STORE(name);
256CODEC_INFO_STR_STORE(modelname);
257
258#define CODEC_ACTION_STORE(type) \
259static ssize_t type##_store(struct device *dev, \
260 struct device_attribute *attr, \
261 const char *buf, size_t count) \
262{ \
263 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
264 struct hda_codec *codec = hwdep->private_data; \
265 int err = 0; \
266 if (*buf) \
267 err = type##_codec(codec); \
268 return err < 0 ? err : count; \
269}
270
271CODEC_ACTION_STORE(reconfig);
272CODEC_ACTION_STORE(clear);
273
274static ssize_t init_verbs_store(struct device *dev,
275 struct device_attribute *attr,
276 const char *buf, size_t count)
277{
278 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
279 struct hda_codec *codec = hwdep->private_data;
280 char *p;
281 struct hda_verb verb, *v;
282
283 verb.nid = simple_strtoul(buf, &p, 0);
284 verb.verb = simple_strtoul(p, &p, 0);
285 verb.param = simple_strtoul(p, &p, 0);
286 if (!verb.nid || !verb.verb || !verb.param)
287 return -EINVAL;
288 v = snd_array_new(&codec->init_verbs);
289 if (!v)
290 return -ENOMEM;
291 *v = verb;
292 return count;
293}
294
295static ssize_t hints_store(struct device *dev,
296 struct device_attribute *attr,
297 const char *buf, size_t count)
298{
299 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
300 struct hda_codec *codec = hwdep->private_data;
301 char *p;
302 char **hint;
303
304 if (!*buf || isspace(*buf) || *buf == '#' || *buf == '\n')
305 return count;
306 p = kstrndup_noeol(buf, 1024);
307 if (!p)
308 return -ENOMEM;
309 hint = snd_array_new(&codec->hints);
310 if (!hint) {
311 kfree(p);
312 return -ENOMEM;
313 }
314 *hint = p;
315 return count;
316}
317
318#define CODEC_ATTR_RW(type) \
319 __ATTR(type, 0644, type##_show, type##_store)
320#define CODEC_ATTR_RO(type) \
321 __ATTR_RO(type)
322#define CODEC_ATTR_WO(type) \
323 __ATTR(type, 0200, NULL, type##_store)
324
325static struct device_attribute codec_attrs[] = {
326 CODEC_ATTR_RW(vendor_id),
327 CODEC_ATTR_RW(subsystem_id),
328 CODEC_ATTR_RW(revision_id),
329 CODEC_ATTR_RO(afg),
330 CODEC_ATTR_RO(mfg),
331 CODEC_ATTR_RW(name),
332 CODEC_ATTR_RW(modelname),
333 CODEC_ATTR_WO(init_verbs),
334 CODEC_ATTR_WO(hints),
335 CODEC_ATTR_WO(reconfig),
336 CODEC_ATTR_WO(clear),
337};
338
339/*
340 * create sysfs files on hwdep directory
341 */
342int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
343{
344 struct snd_hwdep *hwdep = codec->hwdep;
345 int i;
346
347 for (i = 0; i < ARRAY_SIZE(codec_attrs); i++)
348 snd_add_device_sysfs_file(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card,
349 hwdep->device, &codec_attrs[i]);
350 return 0;
351}
352
353#endif /* CONFIG_SND_HDA_RECONFIG */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 35722ec920cb..f04de115ee11 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -58,6 +58,7 @@ static char *model[SNDRV_CARDS];
58static int position_fix[SNDRV_CARDS]; 58static int position_fix[SNDRV_CARDS];
59static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; 59static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
60static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; 60static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
61static int probe_only[SNDRV_CARDS];
61static int single_cmd; 62static int single_cmd;
62static int enable_msi; 63static int enable_msi;
63 64
@@ -76,6 +77,8 @@ module_param_array(bdl_pos_adj, int, NULL, 0644);
76MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset."); 77MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
77module_param_array(probe_mask, int, NULL, 0444); 78module_param_array(probe_mask, int, NULL, 0444);
78MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); 79MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
80module_param_array(probe_only, bool, NULL, 0444);
81MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
79module_param(single_cmd, bool, 0444); 82module_param(single_cmd, bool, 0444);
80MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " 83MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
81 "(for debugging only)."); 84 "(for debugging only).");
@@ -83,7 +86,10 @@ module_param(enable_msi, int, 0444);
83MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)"); 86MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
84 87
85#ifdef CONFIG_SND_HDA_POWER_SAVE 88#ifdef CONFIG_SND_HDA_POWER_SAVE
86/* power_save option is defined in hda_codec.c */ 89static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
90module_param(power_save, int, 0644);
91MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
92 "(in second, 0 = disable).");
87 93
88/* reset the HD-audio controller in power save mode. 94/* reset the HD-audio controller in power save mode.
89 * this may give more power-saving, but will take longer time to 95 * this may give more power-saving, but will take longer time to
@@ -292,6 +298,8 @@ enum {
292/* Define VIA HD Audio Device ID*/ 298/* Define VIA HD Audio Device ID*/
293#define VIA_HDAC_DEVICE_ID 0x3288 299#define VIA_HDAC_DEVICE_ID 0x3288
294 300
301/* HD Audio class code */
302#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
295 303
296/* 304/*
297 */ 305 */
@@ -392,6 +400,7 @@ struct azx {
392 unsigned int msi :1; 400 unsigned int msi :1;
393 unsigned int irq_pending_warned :1; 401 unsigned int irq_pending_warned :1;
394 unsigned int via_dmapos_patch :1; /* enable DMA-position fix for VIA */ 402 unsigned int via_dmapos_patch :1; /* enable DMA-position fix for VIA */
403 unsigned int probing :1; /* codec probing phase */
395 404
396 /* for debugging */ 405 /* for debugging */
397 unsigned int last_cmd; /* last issued command (to sync) */ 406 unsigned int last_cmd; /* last issued command (to sync) */
@@ -414,6 +423,7 @@ enum {
414 AZX_DRIVER_ULI, 423 AZX_DRIVER_ULI,
415 AZX_DRIVER_NVIDIA, 424 AZX_DRIVER_NVIDIA,
416 AZX_DRIVER_TERA, 425 AZX_DRIVER_TERA,
426 AZX_DRIVER_GENERIC,
417 AZX_NUM_DRIVERS, /* keep this as last entry */ 427 AZX_NUM_DRIVERS, /* keep this as last entry */
418}; 428};
419 429
@@ -427,6 +437,7 @@ static char *driver_short_names[] __devinitdata = {
427 [AZX_DRIVER_ULI] = "HDA ULI M5461", 437 [AZX_DRIVER_ULI] = "HDA ULI M5461",
428 [AZX_DRIVER_NVIDIA] = "HDA NVidia", 438 [AZX_DRIVER_NVIDIA] = "HDA NVidia",
429 [AZX_DRIVER_TERA] = "HDA Teradici", 439 [AZX_DRIVER_TERA] = "HDA Teradici",
440 [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
430}; 441};
431 442
432/* 443/*
@@ -527,9 +538,9 @@ static void azx_free_cmd_io(struct azx *chip)
527} 538}
528 539
529/* send a command */ 540/* send a command */
530static int azx_corb_send_cmd(struct hda_codec *codec, u32 val) 541static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
531{ 542{
532 struct azx *chip = codec->bus->private_data; 543 struct azx *chip = bus->private_data;
533 unsigned int wp; 544 unsigned int wp;
534 545
535 /* add command to corb */ 546 /* add command to corb */
@@ -577,9 +588,9 @@ static void azx_update_rirb(struct azx *chip)
577} 588}
578 589
579/* receive a response */ 590/* receive a response */
580static unsigned int azx_rirb_get_response(struct hda_codec *codec) 591static unsigned int azx_rirb_get_response(struct hda_bus *bus)
581{ 592{
582 struct azx *chip = codec->bus->private_data; 593 struct azx *chip = bus->private_data;
583 unsigned long timeout; 594 unsigned long timeout;
584 595
585 again: 596 again:
@@ -596,7 +607,7 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec)
596 } 607 }
597 if (time_after(jiffies, timeout)) 608 if (time_after(jiffies, timeout))
598 break; 609 break;
599 if (codec->bus->needs_damn_long_delay) 610 if (bus->needs_damn_long_delay)
600 msleep(2); /* temporary workaround */ 611 msleep(2); /* temporary workaround */
601 else { 612 else {
602 udelay(10); 613 udelay(10);
@@ -624,6 +635,14 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec)
624 goto again; 635 goto again;
625 } 636 }
626 637
638 if (chip->probing) {
639 /* If this critical timeout happens during the codec probing
640 * phase, this is likely an access to a non-existing codec
641 * slot. Better to return an error and reset the system.
642 */
643 return -1;
644 }
645
627 snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, " 646 snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "
628 "switching to single_cmd mode: last cmd=0x%08x\n", 647 "switching to single_cmd mode: last cmd=0x%08x\n",
629 chip->last_cmd); 648 chip->last_cmd);
@@ -646,9 +665,9 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec)
646 */ 665 */
647 666
648/* send a command */ 667/* send a command */
649static int azx_single_send_cmd(struct hda_codec *codec, u32 val) 668static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
650{ 669{
651 struct azx *chip = codec->bus->private_data; 670 struct azx *chip = bus->private_data;
652 int timeout = 50; 671 int timeout = 50;
653 672
654 while (timeout--) { 673 while (timeout--) {
@@ -671,9 +690,9 @@ static int azx_single_send_cmd(struct hda_codec *codec, u32 val)
671} 690}
672 691
673/* receive a response */ 692/* receive a response */
674static unsigned int azx_single_get_response(struct hda_codec *codec) 693static unsigned int azx_single_get_response(struct hda_bus *bus)
675{ 694{
676 struct azx *chip = codec->bus->private_data; 695 struct azx *chip = bus->private_data;
677 int timeout = 50; 696 int timeout = 50;
678 697
679 while (timeout--) { 698 while (timeout--) {
@@ -696,38 +715,29 @@ static unsigned int azx_single_get_response(struct hda_codec *codec)
696 */ 715 */
697 716
698/* send a command */ 717/* send a command */
699static int azx_send_cmd(struct hda_codec *codec, hda_nid_t nid, 718static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
700 int direct, unsigned int verb,
701 unsigned int para)
702{ 719{
703 struct azx *chip = codec->bus->private_data; 720 struct azx *chip = bus->private_data;
704 u32 val;
705
706 val = (u32)(codec->addr & 0x0f) << 28;
707 val |= (u32)direct << 27;
708 val |= (u32)nid << 20;
709 val |= verb << 8;
710 val |= para;
711 chip->last_cmd = val;
712 721
722 chip->last_cmd = val;
713 if (chip->single_cmd) 723 if (chip->single_cmd)
714 return azx_single_send_cmd(codec, val); 724 return azx_single_send_cmd(bus, val);
715 else 725 else
716 return azx_corb_send_cmd(codec, val); 726 return azx_corb_send_cmd(bus, val);
717} 727}
718 728
719/* get a response */ 729/* get a response */
720static unsigned int azx_get_response(struct hda_codec *codec) 730static unsigned int azx_get_response(struct hda_bus *bus)
721{ 731{
722 struct azx *chip = codec->bus->private_data; 732 struct azx *chip = bus->private_data;
723 if (chip->single_cmd) 733 if (chip->single_cmd)
724 return azx_single_get_response(codec); 734 return azx_single_get_response(bus);
725 else 735 else
726 return azx_rirb_get_response(codec); 736 return azx_rirb_get_response(bus);
727} 737}
728 738
729#ifdef CONFIG_SND_HDA_POWER_SAVE 739#ifdef CONFIG_SND_HDA_POWER_SAVE
730static void azx_power_notify(struct hda_codec *codec); 740static void azx_power_notify(struct hda_bus *bus);
731#endif 741#endif
732 742
733/* reset codec link */ 743/* reset codec link */
@@ -1184,6 +1194,28 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1184 return 0; 1194 return 0;
1185} 1195}
1186 1196
1197/*
1198 * Probe the given codec address
1199 */
1200static int probe_codec(struct azx *chip, int addr)
1201{
1202 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
1203 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
1204 unsigned int res;
1205
1206 chip->probing = 1;
1207 azx_send_cmd(chip->bus, cmd);
1208 res = azx_get_response(chip->bus);
1209 chip->probing = 0;
1210 if (res == -1)
1211 return -EIO;
1212 snd_printdd("hda_intel: codec #%d probed OK\n", addr);
1213 return 0;
1214}
1215
1216static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
1217 struct hda_pcm *cpcm);
1218static void azx_stop_chip(struct azx *chip);
1187 1219
1188/* 1220/*
1189 * Codec initialization 1221 * Codec initialization
@@ -1194,21 +1226,13 @@ static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
1194 [AZX_DRIVER_TERA] = 1, 1226 [AZX_DRIVER_TERA] = 1,
1195}; 1227};
1196 1228
1197/* number of slots to probe as default
1198 * this can be different from azx_max_codecs[] -- e.g. some boards
1199 * report wrongly the non-existing 4th slot availability
1200 */
1201static unsigned int azx_default_codecs[AZX_NUM_DRIVERS] __devinitdata = {
1202 [AZX_DRIVER_ICH] = 3,
1203 [AZX_DRIVER_ATI] = 3,
1204};
1205
1206static int __devinit azx_codec_create(struct azx *chip, const char *model, 1229static int __devinit azx_codec_create(struct azx *chip, const char *model,
1207 unsigned int codec_probe_mask) 1230 unsigned int codec_probe_mask,
1231 int no_init)
1208{ 1232{
1209 struct hda_bus_template bus_temp; 1233 struct hda_bus_template bus_temp;
1210 int c, codecs, audio_codecs, err; 1234 int c, codecs, err;
1211 int def_slots, max_slots; 1235 int max_slots;
1212 1236
1213 memset(&bus_temp, 0, sizeof(bus_temp)); 1237 memset(&bus_temp, 0, sizeof(bus_temp));
1214 bus_temp.private_data = chip; 1238 bus_temp.private_data = chip;
@@ -1216,7 +1240,9 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model,
1216 bus_temp.pci = chip->pci; 1240 bus_temp.pci = chip->pci;
1217 bus_temp.ops.command = azx_send_cmd; 1241 bus_temp.ops.command = azx_send_cmd;
1218 bus_temp.ops.get_response = azx_get_response; 1242 bus_temp.ops.get_response = azx_get_response;
1243 bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
1219#ifdef CONFIG_SND_HDA_POWER_SAVE 1244#ifdef CONFIG_SND_HDA_POWER_SAVE
1245 bus_temp.power_save = &power_save;
1220 bus_temp.ops.pm_notify = azx_power_notify; 1246 bus_temp.ops.pm_notify = azx_power_notify;
1221#endif 1247#endif
1222 1248
@@ -1227,33 +1253,43 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model,
1227 if (chip->driver_type == AZX_DRIVER_NVIDIA) 1253 if (chip->driver_type == AZX_DRIVER_NVIDIA)
1228 chip->bus->needs_damn_long_delay = 1; 1254 chip->bus->needs_damn_long_delay = 1;
1229 1255
1230 codecs = audio_codecs = 0; 1256 codecs = 0;
1231 max_slots = azx_max_codecs[chip->driver_type]; 1257 max_slots = azx_max_codecs[chip->driver_type];
1232 if (!max_slots) 1258 if (!max_slots)
1233 max_slots = AZX_MAX_CODECS; 1259 max_slots = AZX_MAX_CODECS;
1234 def_slots = azx_default_codecs[chip->driver_type]; 1260
1235 if (!def_slots) 1261 /* First try to probe all given codec slots */
1236 def_slots = max_slots; 1262 for (c = 0; c < max_slots; c++) {
1237 for (c = 0; c < def_slots; c++) { 1263 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) {
1264 if (probe_codec(chip, c) < 0) {
1265 /* Some BIOSen give you wrong codec addresses
1266 * that don't exist
1267 */
1268 snd_printk(KERN_WARNING
1269 "hda_intel: Codec #%d probe error; "
1270 "disabling it...\n", c);
1271 chip->codec_mask &= ~(1 << c);
1272 /* More badly, accessing to a non-existing
1273 * codec often screws up the controller chip,
1274 * and distrubs the further communications.
1275 * Thus if an error occurs during probing,
1276 * better to reset the controller chip to
1277 * get back to the sanity state.
1278 */
1279 azx_stop_chip(chip);
1280 azx_init_chip(chip);
1281 }
1282 }
1283 }
1284
1285 /* Then create codec instances */
1286 for (c = 0; c < max_slots; c++) {
1238 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { 1287 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) {
1239 struct hda_codec *codec; 1288 struct hda_codec *codec;
1240 err = snd_hda_codec_new(chip->bus, c, &codec); 1289 err = snd_hda_codec_new(chip->bus, c, !no_init, &codec);
1241 if (err < 0) 1290 if (err < 0)
1242 continue; 1291 continue;
1243 codecs++; 1292 codecs++;
1244 if (codec->afg)
1245 audio_codecs++;
1246 }
1247 }
1248 if (!audio_codecs) {
1249 /* probe additional slots if no codec is found */
1250 for (; c < max_slots; c++) {
1251 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) {
1252 err = snd_hda_codec_new(chip->bus, c, NULL);
1253 if (err < 0)
1254 continue;
1255 codecs++;
1256 }
1257 } 1293 }
1258 } 1294 }
1259 if (!codecs) { 1295 if (!codecs) {
@@ -1722,111 +1758,59 @@ static struct snd_pcm_ops azx_pcm_ops = {
1722 1758
1723static void azx_pcm_free(struct snd_pcm *pcm) 1759static void azx_pcm_free(struct snd_pcm *pcm)
1724{ 1760{
1725 kfree(pcm->private_data); 1761 struct azx_pcm *apcm = pcm->private_data;
1762 if (apcm) {
1763 apcm->chip->pcm[pcm->device] = NULL;
1764 kfree(apcm);
1765 }
1726} 1766}
1727 1767
1728static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec, 1768static int
1729 struct hda_pcm *cpcm) 1769azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
1770 struct hda_pcm *cpcm)
1730{ 1771{
1731 int err; 1772 struct azx *chip = bus->private_data;
1732 struct snd_pcm *pcm; 1773 struct snd_pcm *pcm;
1733 struct azx_pcm *apcm; 1774 struct azx_pcm *apcm;
1775 int pcm_dev = cpcm->device;
1776 int s, err;
1734 1777
1735 /* if no substreams are defined for both playback and capture, 1778 if (pcm_dev >= AZX_MAX_PCMS) {
1736 * it's just a placeholder. ignore it. 1779 snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n",
1737 */ 1780 pcm_dev);
1738 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
1739 return 0;
1740
1741 if (snd_BUG_ON(!cpcm->name))
1742 return -EINVAL; 1781 return -EINVAL;
1743 1782 }
1744 err = snd_pcm_new(chip->card, cpcm->name, cpcm->device, 1783 if (chip->pcm[pcm_dev]) {
1745 cpcm->stream[0].substreams, 1784 snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev);
1746 cpcm->stream[1].substreams, 1785 return -EBUSY;
1786 }
1787 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
1788 cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,
1789 cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,
1747 &pcm); 1790 &pcm);
1748 if (err < 0) 1791 if (err < 0)
1749 return err; 1792 return err;
1750 strcpy(pcm->name, cpcm->name); 1793 strcpy(pcm->name, cpcm->name);
1751 apcm = kmalloc(sizeof(*apcm), GFP_KERNEL); 1794 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
1752 if (apcm == NULL) 1795 if (apcm == NULL)
1753 return -ENOMEM; 1796 return -ENOMEM;
1754 apcm->chip = chip; 1797 apcm->chip = chip;
1755 apcm->codec = codec; 1798 apcm->codec = codec;
1756 apcm->hinfo[0] = &cpcm->stream[0];
1757 apcm->hinfo[1] = &cpcm->stream[1];
1758 pcm->private_data = apcm; 1799 pcm->private_data = apcm;
1759 pcm->private_free = azx_pcm_free; 1800 pcm->private_free = azx_pcm_free;
1760 if (cpcm->stream[0].substreams) 1801 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
1761 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops); 1802 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
1762 if (cpcm->stream[1].substreams) 1803 chip->pcm[pcm_dev] = pcm;
1763 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops); 1804 cpcm->pcm = pcm;
1805 for (s = 0; s < 2; s++) {
1806 apcm->hinfo[s] = &cpcm->stream[s];
1807 if (cpcm->stream[s].substreams)
1808 snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
1809 }
1810 /* buffer pre-allocation */
1764 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1811 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1765 snd_dma_pci_data(chip->pci), 1812 snd_dma_pci_data(chip->pci),
1766 1024 * 64, 32 * 1024 * 1024); 1813 1024 * 64, 32 * 1024 * 1024);
1767 chip->pcm[cpcm->device] = pcm;
1768 return 0;
1769}
1770
1771static int __devinit azx_pcm_create(struct azx *chip)
1772{
1773 static const char *dev_name[HDA_PCM_NTYPES] = {
1774 "Audio", "SPDIF", "HDMI", "Modem"
1775 };
1776 /* starting device index for each PCM type */
1777 static int dev_idx[HDA_PCM_NTYPES] = {
1778 [HDA_PCM_TYPE_AUDIO] = 0,
1779 [HDA_PCM_TYPE_SPDIF] = 1,
1780 [HDA_PCM_TYPE_HDMI] = 3,
1781 [HDA_PCM_TYPE_MODEM] = 6
1782 };
1783 /* normal audio device indices; not linear to keep compatibility */
1784 static int audio_idx[4] = { 0, 2, 4, 5 };
1785 struct hda_codec *codec;
1786 int c, err;
1787 int num_devs[HDA_PCM_NTYPES];
1788
1789 err = snd_hda_build_pcms(chip->bus);
1790 if (err < 0)
1791 return err;
1792
1793 /* create audio PCMs */
1794 memset(num_devs, 0, sizeof(num_devs));
1795 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1796 for (c = 0; c < codec->num_pcms; c++) {
1797 struct hda_pcm *cpcm = &codec->pcm_info[c];
1798 int type = cpcm->pcm_type;
1799 switch (type) {
1800 case HDA_PCM_TYPE_AUDIO:
1801 if (num_devs[type] >= ARRAY_SIZE(audio_idx)) {
1802 snd_printk(KERN_WARNING
1803 "Too many audio devices\n");
1804 continue;
1805 }
1806 cpcm->device = audio_idx[num_devs[type]];
1807 break;
1808 case HDA_PCM_TYPE_SPDIF:
1809 case HDA_PCM_TYPE_HDMI:
1810 case HDA_PCM_TYPE_MODEM:
1811 if (num_devs[type]) {
1812 snd_printk(KERN_WARNING
1813 "%s already defined\n",
1814 dev_name[type]);
1815 continue;
1816 }
1817 cpcm->device = dev_idx[type];
1818 break;
1819 default:
1820 snd_printk(KERN_WARNING
1821 "Invalid PCM type %d\n", type);
1822 continue;
1823 }
1824 num_devs[type]++;
1825 err = create_codec_pcm(chip, codec, cpcm);
1826 if (err < 0)
1827 return err;
1828 }
1829 }
1830 return 0; 1814 return 0;
1831} 1815}
1832 1816
@@ -1903,13 +1887,13 @@ static void azx_stop_chip(struct azx *chip)
1903 1887
1904#ifdef CONFIG_SND_HDA_POWER_SAVE 1888#ifdef CONFIG_SND_HDA_POWER_SAVE
1905/* power-up/down the controller */ 1889/* power-up/down the controller */
1906static void azx_power_notify(struct hda_codec *codec) 1890static void azx_power_notify(struct hda_bus *bus)
1907{ 1891{
1908 struct azx *chip = codec->bus->private_data; 1892 struct azx *chip = bus->private_data;
1909 struct hda_codec *c; 1893 struct hda_codec *c;
1910 int power_on = 0; 1894 int power_on = 0;
1911 1895
1912 list_for_each_entry(c, &codec->bus->codec_list, list) { 1896 list_for_each_entry(c, &bus->codec_list, list) {
1913 if (c->power_on) { 1897 if (c->power_on) {
1914 power_on = 1; 1898 power_on = 1;
1915 break; 1899 break;
@@ -1926,6 +1910,18 @@ static void azx_power_notify(struct hda_codec *codec)
1926/* 1910/*
1927 * power management 1911 * power management
1928 */ 1912 */
1913
1914static int snd_hda_codecs_inuse(struct hda_bus *bus)
1915{
1916 struct hda_codec *codec;
1917
1918 list_for_each_entry(codec, &bus->codec_list, list) {
1919 if (snd_hda_codec_needs_resume(codec))
1920 return 1;
1921 }
1922 return 0;
1923}
1924
1929static int azx_suspend(struct pci_dev *pci, pm_message_t state) 1925static int azx_suspend(struct pci_dev *pci, pm_message_t state)
1930{ 1926{
1931 struct snd_card *card = pci_get_drvdata(pci); 1927 struct snd_card *card = pci_get_drvdata(pci);
@@ -1951,13 +1947,16 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
1951 return 0; 1947 return 0;
1952} 1948}
1953 1949
1950static int azx_resume_early(struct pci_dev *pci)
1951{
1952 return pci_restore_state(pci);
1953}
1954
1954static int azx_resume(struct pci_dev *pci) 1955static int azx_resume(struct pci_dev *pci)
1955{ 1956{
1956 struct snd_card *card = pci_get_drvdata(pci); 1957 struct snd_card *card = pci_get_drvdata(pci);
1957 struct azx *chip = card->private_data; 1958 struct azx *chip = card->private_data;
1958 1959
1959 pci_set_power_state(pci, PCI_D0);
1960 pci_restore_state(pci);
1961 if (pci_enable_device(pci) < 0) { 1960 if (pci_enable_device(pci) < 0) {
1962 printk(KERN_ERR "hda-intel: pci_enable_device failed, " 1961 printk(KERN_ERR "hda-intel: pci_enable_device failed, "
1963 "disabling device\n"); 1962 "disabling device\n");
@@ -2095,6 +2094,10 @@ static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
2095 SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01), 2094 SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
2096 SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01), 2095 SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
2097 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01), 2096 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
2097 /* broken BIOS */
2098 SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
2099 /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
2100 SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
2098 {} 2101 {}
2099}; 2102};
2100 2103
@@ -2229,6 +2232,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2229 chip->playback_streams = ATIHDMI_NUM_PLAYBACK; 2232 chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
2230 chip->capture_streams = ATIHDMI_NUM_CAPTURE; 2233 chip->capture_streams = ATIHDMI_NUM_CAPTURE;
2231 break; 2234 break;
2235 case AZX_DRIVER_GENERIC:
2232 default: 2236 default:
2233 chip->playback_streams = ICH6_NUM_PLAYBACK; 2237 chip->playback_streams = ICH6_NUM_PLAYBACK;
2234 chip->capture_streams = ICH6_NUM_CAPTURE; 2238 chip->capture_streams = ICH6_NUM_CAPTURE;
@@ -2338,40 +2342,31 @@ static int __devinit azx_probe(struct pci_dev *pci,
2338 } 2342 }
2339 2343
2340 err = azx_create(card, pci, dev, pci_id->driver_data, &chip); 2344 err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
2341 if (err < 0) { 2345 if (err < 0)
2342 snd_card_free(card); 2346 goto out_free;
2343 return err;
2344 }
2345 card->private_data = chip; 2347 card->private_data = chip;
2346 2348
2347 /* create codec instances */ 2349 /* create codec instances */
2348 err = azx_codec_create(chip, model[dev], probe_mask[dev]); 2350 err = azx_codec_create(chip, model[dev], probe_mask[dev],
2349 if (err < 0) { 2351 probe_only[dev]);
2350 snd_card_free(card); 2352 if (err < 0)
2351 return err; 2353 goto out_free;
2352 }
2353 2354
2354 /* create PCM streams */ 2355 /* create PCM streams */
2355 err = azx_pcm_create(chip); 2356 err = snd_hda_build_pcms(chip->bus);
2356 if (err < 0) { 2357 if (err < 0)
2357 snd_card_free(card); 2358 goto out_free;
2358 return err;
2359 }
2360 2359
2361 /* create mixer controls */ 2360 /* create mixer controls */
2362 err = azx_mixer_create(chip); 2361 err = azx_mixer_create(chip);
2363 if (err < 0) { 2362 if (err < 0)
2364 snd_card_free(card); 2363 goto out_free;
2365 return err;
2366 }
2367 2364
2368 snd_card_set_dev(card, &pci->dev); 2365 snd_card_set_dev(card, &pci->dev);
2369 2366
2370 err = snd_card_register(card); 2367 err = snd_card_register(card);
2371 if (err < 0) { 2368 if (err < 0)
2372 snd_card_free(card); 2369 goto out_free;
2373 return err;
2374 }
2375 2370
2376 pci_set_drvdata(pci, card); 2371 pci_set_drvdata(pci, card);
2377 chip->running = 1; 2372 chip->running = 1;
@@ -2380,6 +2375,9 @@ static int __devinit azx_probe(struct pci_dev *pci,
2380 2375
2381 dev++; 2376 dev++;
2382 return err; 2377 return err;
2378out_free:
2379 snd_card_free(card);
2380 return err;
2383} 2381}
2384 2382
2385static void __devexit azx_remove(struct pci_dev *pci) 2383static void __devexit azx_remove(struct pci_dev *pci)
@@ -2453,6 +2451,11 @@ static struct pci_device_id azx_ids[] = {
2453 { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA }, 2451 { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA },
2454 /* Teradici */ 2452 /* Teradici */
2455 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA }, 2453 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
2454 /* AMD Generic, PCI class code and Vendor ID for HD Audio */
2455 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
2456 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2457 .class_mask = 0xffffff,
2458 .driver_data = AZX_DRIVER_GENERIC },
2456 { 0, } 2459 { 0, }
2457}; 2460};
2458MODULE_DEVICE_TABLE(pci, azx_ids); 2461MODULE_DEVICE_TABLE(pci, azx_ids);
@@ -2465,6 +2468,7 @@ static struct pci_driver driver = {
2465 .remove = __devexit_p(azx_remove), 2468 .remove = __devexit_p(azx_remove),
2466#ifdef CONFIG_PM 2469#ifdef CONFIG_PM
2467 .suspend = azx_suspend, 2470 .suspend = azx_suspend,
2471 .resume_early = azx_resume_early,
2468 .resume = azx_resume, 2472 .resume = azx_resume,
2469#endif 2473#endif
2470}; 2474};
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 7957fefda730..6f2fe0f9fdd8 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -96,6 +96,8 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
96 const char *name); 96 const char *name);
97int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 97int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
98 unsigned int *tlv, const char **slaves); 98 unsigned int *tlv, const char **slaves);
99void snd_hda_codec_reset(struct hda_codec *codec);
100int snd_hda_codec_configure(struct hda_codec *codec);
99 101
100/* amp value bits */ 102/* amp value bits */
101#define HDA_AMP_MUTE 0x80 103#define HDA_AMP_MUTE 0x80
@@ -282,6 +284,12 @@ int snd_hda_codec_proc_new(struct hda_codec *codec);
282static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; } 284static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
283#endif 285#endif
284 286
287#define SND_PRINT_RATES_ADVISED_BUFSIZE 80
288void snd_print_pcm_rates(int pcm, char *buf, int buflen);
289
290#define SND_PRINT_BITS_ADVISED_BUFSIZE 16
291void snd_print_pcm_bits(int pcm, char *buf, int buflen);
292
285/* 293/*
286 * Misc 294 * Misc
287 */ 295 */
@@ -364,17 +372,17 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
364/* amp values */ 372/* amp values */
365#define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8)) 373#define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
366#define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8)) 374#define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
367#define AMP_OUT_MUTE 0xb080 375#define AMP_OUT_MUTE 0xb080
368#define AMP_OUT_UNMUTE 0xb000 376#define AMP_OUT_UNMUTE 0xb000
369#define AMP_OUT_ZERO 0xb000 377#define AMP_OUT_ZERO 0xb000
370/* pinctl values */ 378/* pinctl values */
371#define PIN_IN (AC_PINCTL_IN_EN) 379#define PIN_IN (AC_PINCTL_IN_EN)
372#define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ) 380#define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
373#define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50) 381#define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
374#define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD) 382#define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
375#define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80) 383#define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
376#define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100) 384#define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
377#define PIN_OUT (AC_PINCTL_OUT_EN) 385#define PIN_OUT (AC_PINCTL_OUT_EN)
378#define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN) 386#define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
379#define PIN_HP_AMP (AC_PINCTL_HP_EN) 387#define PIN_HP_AMP (AC_PINCTL_HP_EN)
380 388
@@ -393,10 +401,26 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
393int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 401int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
394 unsigned int caps); 402 unsigned int caps);
395 403
404int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl);
405void snd_hda_ctls_clear(struct hda_codec *codec);
406
396/* 407/*
397 * hwdep interface 408 * hwdep interface
398 */ 409 */
410#ifdef CONFIG_SND_HDA_HWDEP
399int snd_hda_create_hwdep(struct hda_codec *codec); 411int snd_hda_create_hwdep(struct hda_codec *codec);
412#else
413static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
414#endif
415
416#ifdef CONFIG_SND_HDA_RECONFIG
417int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
418#else
419static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
420{
421 return 0;
422}
423#endif
400 424
401/* 425/*
402 * power-management 426 * power-management
@@ -430,4 +454,66 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
430#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1) 454#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
431#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf) 455#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
432 456
457/*
458 * CEA Short Audio Descriptor data
459 */
460struct cea_sad {
461 int channels;
462 int format; /* (format == 0) indicates invalid SAD */
463 int rates;
464 int sample_bits; /* for LPCM */
465 int max_bitrate; /* for AC3...ATRAC */
466 int profile; /* for WMAPRO */
467};
468
469#define ELD_FIXED_BYTES 20
470#define ELD_MAX_MNL 16
471#define ELD_MAX_SAD 16
472
473/*
474 * ELD: EDID Like Data
475 */
476struct hdmi_eld {
477 int eld_size;
478 int baseline_len;
479 int eld_ver; /* (eld_ver == 0) indicates invalid ELD */
480 int cea_edid_ver;
481 char monitor_name[ELD_MAX_MNL + 1];
482 int manufacture_id;
483 int product_id;
484 u64 port_id;
485 int support_hdcp;
486 int support_ai;
487 int conn_type;
488 int aud_synch_delay;
489 int spk_alloc;
490 int sad_count;
491 struct cea_sad sad[ELD_MAX_SAD];
492#ifdef CONFIG_PROC_FS
493 struct snd_info_entry *proc_entry;
494#endif
495};
496
497int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
498int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
499void snd_hdmi_show_eld(struct hdmi_eld *eld);
500
501#ifdef CONFIG_PROC_FS
502int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld);
503void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
504#else
505static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
506 struct hdmi_eld *eld)
507{
508 return 0;
509}
510static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
511 struct hdmi_eld *eld)
512{
513}
514#endif
515
516#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
517void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
518
433#endif /* __SOUND_HDA_LOCAL_H */ 519#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/hda_patch.h b/sound/pci/hda/hda_patch.h
deleted file mode 100644
index dfbcfa88da44..000000000000
--- a/sound/pci/hda/hda_patch.h
+++ /dev/null
@@ -1,22 +0,0 @@
1/*
2 * HDA Patches - included by hda_codec.c
3 */
4
5/* Realtek codecs */
6extern struct hda_codec_preset snd_hda_preset_realtek[];
7/* C-Media codecs */
8extern struct hda_codec_preset snd_hda_preset_cmedia[];
9/* Analog Devices codecs */
10extern struct hda_codec_preset snd_hda_preset_analog[];
11/* SigmaTel codecs */
12extern struct hda_codec_preset snd_hda_preset_sigmatel[];
13/* SiLabs 3054/3055 modem codecs */
14extern struct hda_codec_preset snd_hda_preset_si3054[];
15/* ATI HDMI codecs */
16extern struct hda_codec_preset snd_hda_preset_atihdmi[];
17/* Conexant audio codec */
18extern struct hda_codec_preset snd_hda_preset_conexant[];
19/* VIA codecs */
20extern struct hda_codec_preset snd_hda_preset_via[];
21/* NVIDIA HDMI codecs */
22extern struct hda_codec_preset snd_hda_preset_nvhdmi[];
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index c39af986bff1..7ca66d654148 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -91,31 +91,21 @@ static void print_amp_vals(struct snd_info_buffer *buffer,
91 91
92static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm) 92static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
93{ 93{
94 static unsigned int rates[] = { 94 char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
95 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
96 96000, 176400, 192000, 384000
97 };
98 int i;
99 95
100 pcm &= AC_SUPPCM_RATES; 96 pcm &= AC_SUPPCM_RATES;
101 snd_iprintf(buffer, " rates [0x%x]:", pcm); 97 snd_iprintf(buffer, " rates [0x%x]:", pcm);
102 for (i = 0; i < ARRAY_SIZE(rates); i++) 98 snd_print_pcm_rates(pcm, buf, sizeof(buf));
103 if (pcm & (1 << i)) 99 snd_iprintf(buffer, "%s\n", buf);
104 snd_iprintf(buffer, " %d", rates[i]);
105 snd_iprintf(buffer, "\n");
106} 100}
107 101
108static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm) 102static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
109{ 103{
110 static unsigned int bits[] = { 8, 16, 20, 24, 32 }; 104 char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
111 int i;
112 105
113 pcm = (pcm >> 16) & 0xff; 106 snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
114 snd_iprintf(buffer, " bits [0x%x]:", pcm); 107 snd_print_pcm_bits(pcm, buf, sizeof(buf));
115 for (i = 0; i < ARRAY_SIZE(bits); i++) 108 snd_iprintf(buffer, "%s\n", buf);
116 if (pcm & (1 << i))
117 snd_iprintf(buffer, " %d", bits[i]);
118 snd_iprintf(buffer, "\n");
119} 109}
120 110
121static void print_pcm_formats(struct snd_info_buffer *buffer, 111static void print_pcm_formats(struct snd_info_buffer *buffer,
@@ -145,32 +135,6 @@ static void print_pcm_caps(struct snd_info_buffer *buffer,
145 print_pcm_formats(buffer, stream); 135 print_pcm_formats(buffer, stream);
146} 136}
147 137
148static const char *get_jack_location(u32 cfg)
149{
150 static char *bases[7] = {
151 "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom",
152 };
153 static unsigned char specials_idx[] = {
154 0x07, 0x08,
155 0x17, 0x18, 0x19,
156 0x37, 0x38
157 };
158 static char *specials[] = {
159 "Rear Panel", "Drive Bar",
160 "Riser", "HDMI", "ATAPI",
161 "Mobile-In", "Mobile-Out"
162 };
163 int i;
164 cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT;
165 if ((cfg & 0x0f) < 7)
166 return bases[cfg & 0x0f];
167 for (i = 0; i < ARRAY_SIZE(specials_idx); i++) {
168 if (cfg == specials_idx[i])
169 return specials[i];
170 }
171 return "UNKNOWN";
172}
173
174static const char *get_jack_connection(u32 cfg) 138static const char *get_jack_connection(u32 cfg)
175{ 139{
176 static char *names[16] = { 140 static char *names[16] = {
@@ -206,13 +170,6 @@ static void print_pin_caps(struct snd_info_buffer *buffer,
206 int *supports_vref) 170 int *supports_vref)
207{ 171{
208 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" }; 172 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
209 static char *jack_types[16] = {
210 "Line Out", "Speaker", "HP Out", "CD",
211 "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand",
212 "Line In", "Aux", "Mic", "Telephony",
213 "SPDIF In", "Digitial In", "Reserved", "Other"
214 };
215 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
216 unsigned int caps, val; 173 unsigned int caps, val;
217 174
218 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 175 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
@@ -274,9 +231,9 @@ static void print_pin_caps(struct snd_info_buffer *buffer,
274 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 231 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
275 snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps, 232 snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
276 jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT], 233 jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
277 jack_types[(caps & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT], 234 snd_hda_get_jack_type(caps),
278 jack_locations[(caps >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3], 235 snd_hda_get_jack_connectivity(caps),
279 get_jack_location(caps)); 236 snd_hda_get_jack_location(caps));
280 snd_iprintf(buffer, " Conn = %s, Color = %s\n", 237 snd_iprintf(buffer, " Conn = %s, Color = %s\n",
281 get_jack_connection(caps), 238 get_jack_connection(caps),
282 get_jack_color(caps)); 239 get_jack_color(caps));
@@ -457,17 +414,6 @@ static void print_conn_list(struct snd_info_buffer *buffer,
457 } 414 }
458} 415}
459 416
460static void print_realtek_coef(struct snd_info_buffer *buffer,
461 struct hda_codec *codec, hda_nid_t nid)
462{
463 int coeff = snd_hda_codec_read(codec, nid, 0,
464 AC_VERB_GET_PROC_COEF, 0);
465 snd_iprintf(buffer, " Processing Coefficient: 0x%02x\n", coeff);
466 coeff = snd_hda_codec_read(codec, nid, 0,
467 AC_VERB_GET_COEF_INDEX, 0);
468 snd_iprintf(buffer, " Coefficient Index: 0x%02x\n", coeff);
469}
470
471static void print_gpio(struct snd_info_buffer *buffer, 417static void print_gpio(struct snd_info_buffer *buffer,
472 struct hda_codec *codec, hda_nid_t nid) 418 struct hda_codec *codec, hda_nid_t nid)
473{ 419{
@@ -500,12 +446,13 @@ static void print_gpio(struct snd_info_buffer *buffer,
500 for (i = 0; i < max; ++i) 446 for (i = 0; i < max; ++i)
501 snd_iprintf(buffer, 447 snd_iprintf(buffer,
502 " IO[%d]: enable=%d, dir=%d, wake=%d, " 448 " IO[%d]: enable=%d, dir=%d, wake=%d, "
503 "sticky=%d, data=%d\n", i, 449 "sticky=%d, data=%d, unsol=%d\n", i,
504 (enable & (1<<i)) ? 1 : 0, 450 (enable & (1<<i)) ? 1 : 0,
505 (direction & (1<<i)) ? 1 : 0, 451 (direction & (1<<i)) ? 1 : 0,
506 (wake & (1<<i)) ? 1 : 0, 452 (wake & (1<<i)) ? 1 : 0,
507 (sticky & (1<<i)) ? 1 : 0, 453 (sticky & (1<<i)) ? 1 : 0,
508 (data & (1<<i)) ? 1 : 0); 454 (data & (1<<i)) ? 1 : 0,
455 (unsol & (1<<i)) ? 1 : 0);
509 /* FIXME: add GPO and GPI pin information */ 456 /* FIXME: add GPO and GPI pin information */
510} 457}
511 458
@@ -513,12 +460,11 @@ static void print_codec_info(struct snd_info_entry *entry,
513 struct snd_info_buffer *buffer) 460 struct snd_info_buffer *buffer)
514{ 461{
515 struct hda_codec *codec = entry->private_data; 462 struct hda_codec *codec = entry->private_data;
516 char buf[32];
517 hda_nid_t nid; 463 hda_nid_t nid;
518 int i, nodes; 464 int i, nodes;
519 465
520 snd_hda_get_codec_name(codec, buf, sizeof(buf)); 466 snd_iprintf(buffer, "Codec: %s\n",
521 snd_iprintf(buffer, "Codec: %s\n", buf); 467 codec->name ? codec->name : "Not Set");
522 snd_iprintf(buffer, "Address: %d\n", codec->addr); 468 snd_iprintf(buffer, "Address: %d\n", codec->addr);
523 snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id); 469 snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id);
524 snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id); 470 snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id);
@@ -547,6 +493,8 @@ static void print_codec_info(struct snd_info_entry *entry,
547 } 493 }
548 494
549 print_gpio(buffer, codec, codec->afg); 495 print_gpio(buffer, codec, codec->afg);
496 if (codec->proc_widget_hook)
497 codec->proc_widget_hook(buffer, codec, codec->afg);
550 498
551 for (i = 0; i < nodes; i++, nid++) { 499 for (i = 0; i < nodes; i++, nid++) {
552 unsigned int wid_caps = 500 unsigned int wid_caps =
@@ -649,9 +597,8 @@ static void print_codec_info(struct snd_info_entry *entry,
649 if (wid_caps & AC_WCAP_PROC_WID) 597 if (wid_caps & AC_WCAP_PROC_WID)
650 print_proc_caps(buffer, codec, nid); 598 print_proc_caps(buffer, codec, nid);
651 599
652 /* NID 0x20 == Realtek Define Registers */ 600 if (codec->proc_widget_hook)
653 if (codec->vendor_id == 0x10ec && nid == 0x20) 601 codec->proc_widget_hook(buffer, codec, nid);
654 print_realtek_coef(buffer, codec, nid);
655 } 602 }
656 snd_hda_power_down(codec); 603 snd_hda_power_down(codec);
657} 604}
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 686c77491dea..26247cfe749d 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -27,7 +27,6 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
31 30
32struct ad198x_spec { 31struct ad198x_spec {
33 struct snd_kcontrol_new *mixers[5]; 32 struct snd_kcontrol_new *mixers[5];
@@ -67,8 +66,7 @@ struct ad198x_spec {
67 66
68 /* dynamic controls, init_verbs and input_mux */ 67 /* dynamic controls, init_verbs and input_mux */
69 struct auto_pin_cfg autocfg; 68 struct auto_pin_cfg autocfg;
70 unsigned int num_kctl_alloc, num_kctl_used; 69 struct snd_array kctls;
71 struct snd_kcontrol_new *kctl_alloc;
72 struct hda_input_mux private_imux; 70 struct hda_input_mux private_imux;
73 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 71 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
74 72
@@ -154,6 +152,8 @@ static const char *ad_slave_sws[] = {
154 NULL 152 NULL
155}; 153};
156 154
155static void ad198x_free_kctls(struct hda_codec *codec);
156
157static int ad198x_build_controls(struct hda_codec *codec) 157static int ad198x_build_controls(struct hda_codec *codec)
158{ 158{
159 struct ad198x_spec *spec = codec->spec; 159 struct ad198x_spec *spec = codec->spec;
@@ -202,6 +202,7 @@ static int ad198x_build_controls(struct hda_codec *codec)
202 return err; 202 return err;
203 } 203 }
204 204
205 ad198x_free_kctls(codec); /* no longer needed */
205 return 0; 206 return 0;
206} 207}
207 208
@@ -375,16 +376,27 @@ static int ad198x_build_pcms(struct hda_codec *codec)
375 return 0; 376 return 0;
376} 377}
377 378
378static void ad198x_free(struct hda_codec *codec) 379static void ad198x_free_kctls(struct hda_codec *codec)
379{ 380{
380 struct ad198x_spec *spec = codec->spec; 381 struct ad198x_spec *spec = codec->spec;
381 unsigned int i;
382 382
383 if (spec->kctl_alloc) { 383 if (spec->kctls.list) {
384 for (i = 0; i < spec->num_kctl_used; i++) 384 struct snd_kcontrol_new *kctl = spec->kctls.list;
385 kfree(spec->kctl_alloc[i].name); 385 int i;
386 kfree(spec->kctl_alloc); 386 for (i = 0; i < spec->kctls.used; i++)
387 kfree(kctl[i].name);
387 } 388 }
389 snd_array_free(&spec->kctls);
390}
391
392static void ad198x_free(struct hda_codec *codec)
393{
394 struct ad198x_spec *spec = codec->spec;
395
396 if (!spec)
397 return;
398
399 ad198x_free_kctls(codec);
388 kfree(codec->spec); 400 kfree(codec->spec);
389} 401}
390 402
@@ -629,6 +641,36 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
629 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw), 641 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
630 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT), 642 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
631 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), 643 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
644 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
645 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
646 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
647 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
648 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
649 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
650 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
651 {
652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
653 .name = "Capture Source",
654 .info = ad198x_mux_enum_info,
655 .get = ad198x_mux_enum_get,
656 .put = ad198x_mux_enum_put,
657 },
658 {
659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
660 .name = "External Amplifier",
661 .info = ad198x_eapd_info,
662 .get = ad198x_eapd_get,
663 .put = ad198x_eapd_put,
664 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
665 },
666 { } /* end */
667};
668
669static struct snd_kcontrol_new ad1986a_samsung_mixers[] = {
670 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
671 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
672 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
673 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
632 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 674 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
633 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 675 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
634 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 676 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
@@ -917,6 +959,7 @@ enum {
917 AD1986A_LAPTOP_EAPD, 959 AD1986A_LAPTOP_EAPD,
918 AD1986A_LAPTOP_AUTOMUTE, 960 AD1986A_LAPTOP_AUTOMUTE,
919 AD1986A_ULTRA, 961 AD1986A_ULTRA,
962 AD1986A_SAMSUNG,
920 AD1986A_MODELS 963 AD1986A_MODELS
921}; 964};
922 965
@@ -927,6 +970,7 @@ static const char *ad1986a_models[AD1986A_MODELS] = {
927 [AD1986A_LAPTOP_EAPD] = "laptop-eapd", 970 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
928 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute", 971 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
929 [AD1986A_ULTRA] = "ultra", 972 [AD1986A_ULTRA] = "ultra",
973 [AD1986A_SAMSUNG] = "samsung",
930}; 974};
931 975
932static struct snd_pci_quirk ad1986a_cfg_tbl[] = { 976static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
@@ -949,9 +993,9 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
949 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD), 993 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
950 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK), 994 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
951 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP), 995 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
952 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD), 996 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_SAMSUNG),
953 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD), 997 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_SAMSUNG),
954 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD), 998 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_SAMSUNG),
955 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA), 999 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
956 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK), 1000 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
957 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP), 1001 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
@@ -1033,6 +1077,17 @@ static int patch_ad1986a(struct hda_codec *codec)
1033 break; 1077 break;
1034 case AD1986A_LAPTOP_EAPD: 1078 case AD1986A_LAPTOP_EAPD:
1035 spec->mixers[0] = ad1986a_laptop_eapd_mixers; 1079 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1080 spec->num_init_verbs = 2;
1081 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1082 spec->multiout.max_channels = 2;
1083 spec->multiout.num_dacs = 1;
1084 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1085 if (!is_jack_available(codec, 0x25))
1086 spec->multiout.dig_out_nid = 0;
1087 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1088 break;
1089 case AD1986A_SAMSUNG:
1090 spec->mixers[0] = ad1986a_samsung_mixers;
1036 spec->num_init_verbs = 3; 1091 spec->num_init_verbs = 3;
1037 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1092 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1038 spec->init_verbs[2] = ad1986a_automic_verbs; 1093 spec->init_verbs[2] = ad1986a_automic_verbs;
@@ -2452,9 +2507,6 @@ static struct hda_amp_list ad1988_loopbacks[] = {
2452 * Automatic parse of I/O pins from the BIOS configuration 2507 * Automatic parse of I/O pins from the BIOS configuration
2453 */ 2508 */
2454 2509
2455#define NUM_CONTROL_ALLOC 32
2456#define NUM_VERB_ALLOC 32
2457
2458enum { 2510enum {
2459 AD_CTL_WIDGET_VOL, 2511 AD_CTL_WIDGET_VOL,
2460 AD_CTL_WIDGET_MUTE, 2512 AD_CTL_WIDGET_MUTE,
@@ -2472,27 +2524,15 @@ static int add_control(struct ad198x_spec *spec, int type, const char *name,
2472{ 2524{
2473 struct snd_kcontrol_new *knew; 2525 struct snd_kcontrol_new *knew;
2474 2526
2475 if (spec->num_kctl_used >= spec->num_kctl_alloc) { 2527 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2476 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC; 2528 knew = snd_array_new(&spec->kctls);
2477 2529 if (!knew)
2478 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */ 2530 return -ENOMEM;
2479 if (! knew)
2480 return -ENOMEM;
2481 if (spec->kctl_alloc) {
2482 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2483 kfree(spec->kctl_alloc);
2484 }
2485 spec->kctl_alloc = knew;
2486 spec->num_kctl_alloc = num;
2487 }
2488
2489 knew = &spec->kctl_alloc[spec->num_kctl_used];
2490 *knew = ad1988_control_templates[type]; 2531 *knew = ad1988_control_templates[type];
2491 knew->name = kstrdup(name, GFP_KERNEL); 2532 knew->name = kstrdup(name, GFP_KERNEL);
2492 if (! knew->name) 2533 if (! knew->name)
2493 return -ENOMEM; 2534 return -ENOMEM;
2494 knew->private_value = val; 2535 knew->private_value = val;
2495 spec->num_kctl_used++;
2496 return 0; 2536 return 0;
2497} 2537}
2498 2538
@@ -2846,8 +2886,8 @@ static int ad1988_parse_auto_config(struct hda_codec *codec)
2846 if (spec->autocfg.dig_in_pin) 2886 if (spec->autocfg.dig_in_pin)
2847 spec->dig_in_nid = AD1988_SPDIF_IN; 2887 spec->dig_in_nid = AD1988_SPDIF_IN;
2848 2888
2849 if (spec->kctl_alloc) 2889 if (spec->kctls.list)
2850 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 2890 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2851 2891
2852 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs; 2892 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2853 2893
@@ -3861,6 +3901,7 @@ static const char *ad1884a_models[AD1884A_MODELS] = {
3861static struct snd_pci_quirk ad1884a_cfg_tbl[] = { 3901static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3862 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE), 3902 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3863 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE), 3903 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3904 SND_PCI_QUIRK(0x103c, 0x30e6, "HP 6730b", AD1884A_LAPTOP),
3864 SND_PCI_QUIRK(0x103c, 0x30e7, "HP EliteBook 8530p", AD1884A_LAPTOP), 3905 SND_PCI_QUIRK(0x103c, 0x30e7, "HP EliteBook 8530p", AD1884A_LAPTOP),
3865 SND_PCI_QUIRK(0x103c, 0x3614, "HP 6730s", AD1884A_LAPTOP), 3906 SND_PCI_QUIRK(0x103c, 0x3614, "HP 6730s", AD1884A_LAPTOP),
3866 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD), 3907 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
@@ -4267,7 +4308,7 @@ static int patch_ad1882(struct hda_codec *codec)
4267/* 4308/*
4268 * patch entries 4309 * patch entries
4269 */ 4310 */
4270struct hda_codec_preset snd_hda_preset_analog[] = { 4311static struct hda_codec_preset snd_hda_preset_analog[] = {
4271 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a }, 4312 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
4272 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 }, 4313 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4273 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a }, 4314 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
@@ -4285,3 +4326,26 @@ struct hda_codec_preset snd_hda_preset_analog[] = {
4285 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 }, 4326 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
4286 {} /* terminator */ 4327 {} /* terminator */
4287}; 4328};
4329
4330MODULE_ALIAS("snd-hda-codec-id:11d4*");
4331
4332MODULE_LICENSE("GPL");
4333MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4334
4335static struct hda_codec_preset_list analog_list = {
4336 .preset = snd_hda_preset_analog,
4337 .owner = THIS_MODULE,
4338};
4339
4340static int __init patch_analog_init(void)
4341{
4342 return snd_hda_add_codec_preset(&analog_list);
4343}
4344
4345static void __exit patch_analog_exit(void)
4346{
4347 snd_hda_delete_codec_preset(&analog_list);
4348}
4349
4350module_init(patch_analog_init)
4351module_exit(patch_analog_exit)
diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c
index ba61575983fd..233e4778bba9 100644
--- a/sound/pci/hda/patch_atihdmi.c
+++ b/sound/pci/hda/patch_atihdmi.c
@@ -27,7 +27,6 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
31 30
32struct atihdmi_spec { 31struct atihdmi_spec {
33 struct hda_multi_out multiout; 32 struct hda_multi_out multiout;
@@ -187,13 +186,40 @@ static int patch_atihdmi(struct hda_codec *codec)
187/* 186/*
188 * patch entries 187 * patch entries
189 */ 188 */
190struct hda_codec_preset snd_hda_preset_atihdmi[] = { 189static struct hda_codec_preset snd_hda_preset_atihdmi[] = {
191 { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, 190 { .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
192 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, 191 { .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
193 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi }, 192 { .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
194 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi }, 193 { .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_atihdmi },
195 { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_atihdmi }, 194 { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_atihdmi },
196 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi },
197 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi }, 195 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi },
198 {} /* terminator */ 196 {} /* terminator */
199}; 197};
198
199MODULE_ALIAS("snd-hda-codec-id:1002793c");
200MODULE_ALIAS("snd-hda-codec-id:10027919");
201MODULE_ALIAS("snd-hda-codec-id:1002791a");
202MODULE_ALIAS("snd-hda-codec-id:1002aa01");
203MODULE_ALIAS("snd-hda-codec-id:10951390");
204MODULE_ALIAS("snd-hda-codec-id:17e80047");
205
206MODULE_LICENSE("GPL");
207MODULE_DESCRIPTION("ATI HDMI HD-audio codec");
208
209static struct hda_codec_preset_list atihdmi_list = {
210 .preset = snd_hda_preset_atihdmi,
211 .owner = THIS_MODULE,
212};
213
214static int __init patch_atihdmi_init(void)
215{
216 return snd_hda_add_codec_preset(&atihdmi_list);
217}
218
219static void __exit patch_atihdmi_exit(void)
220{
221 snd_hda_delete_codec_preset(&atihdmi_list);
222}
223
224module_init(patch_atihdmi_init)
225module_exit(patch_atihdmi_exit)
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 6ef57fbfb6eb..f3ebe837f2d5 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -28,7 +28,6 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_patch.h"
32#define NUM_PINS 11 31#define NUM_PINS 11
33 32
34 33
@@ -736,8 +735,32 @@ static int patch_cmi9880(struct hda_codec *codec)
736/* 735/*
737 * patch entries 736 * patch entries
738 */ 737 */
739struct hda_codec_preset snd_hda_preset_cmedia[] = { 738static struct hda_codec_preset snd_hda_preset_cmedia[] = {
740 { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 }, 739 { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 },
741 { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 }, 740 { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 },
742 {} /* terminator */ 741 {} /* terminator */
743}; 742};
743
744MODULE_ALIAS("snd-hda-codec-id:13f69880");
745MODULE_ALIAS("snd-hda-codec-id:434d4980");
746
747MODULE_LICENSE("GPL");
748MODULE_DESCRIPTION("C-Media HD-audio codec");
749
750static struct hda_codec_preset_list cmedia_list = {
751 .preset = snd_hda_preset_cmedia,
752 .owner = THIS_MODULE,
753};
754
755static int __init patch_cmedia_init(void)
756{
757 return snd_hda_add_codec_preset(&cmedia_list);
758}
759
760static void __exit patch_cmedia_exit(void)
761{
762 snd_hda_delete_codec_preset(&cmedia_list);
763}
764
765module_init(patch_cmedia_init)
766module_exit(patch_cmedia_exit)
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 7c1eb23f0cec..b20e1cede00b 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -27,7 +27,6 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
31 30
32#define CXT_PIN_DIR_IN 0x00 31#define CXT_PIN_DIR_IN 0x00
33#define CXT_PIN_DIR_OUT 0x01 32#define CXT_PIN_DIR_OUT 0x01
@@ -86,8 +85,6 @@ struct conexant_spec {
86 85
87 /* dynamic controls, init_verbs and input_mux */ 86 /* dynamic controls, init_verbs and input_mux */
88 struct auto_pin_cfg autocfg; 87 struct auto_pin_cfg autocfg;
89 unsigned int num_kctl_alloc, num_kctl_used;
90 struct snd_kcontrol_new *kctl_alloc;
91 struct hda_input_mux private_imux; 88 struct hda_input_mux private_imux;
92 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 89 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
93 90
@@ -344,15 +341,6 @@ static int conexant_init(struct hda_codec *codec)
344 341
345static void conexant_free(struct hda_codec *codec) 342static void conexant_free(struct hda_codec *codec)
346{ 343{
347 struct conexant_spec *spec = codec->spec;
348 unsigned int i;
349
350 if (spec->kctl_alloc) {
351 for (i = 0; i < spec->num_kctl_used; i++)
352 kfree(spec->kctl_alloc[i].name);
353 kfree(spec->kctl_alloc);
354 }
355
356 kfree(codec->spec); 344 kfree(codec->spec);
357} 345}
358 346
@@ -1782,7 +1770,7 @@ static int patch_cxt5051(struct hda_codec *codec)
1782/* 1770/*
1783 */ 1771 */
1784 1772
1785struct hda_codec_preset snd_hda_preset_conexant[] = { 1773static struct hda_codec_preset snd_hda_preset_conexant[] = {
1786 { .id = 0x14f15045, .name = "CX20549 (Venice)", 1774 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1787 .patch = patch_cxt5045 }, 1775 .patch = patch_cxt5045 },
1788 { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 1776 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
@@ -1791,3 +1779,28 @@ struct hda_codec_preset snd_hda_preset_conexant[] = {
1791 .patch = patch_cxt5051 }, 1779 .patch = patch_cxt5051 },
1792 {} /* terminator */ 1780 {} /* terminator */
1793}; 1781};
1782
1783MODULE_ALIAS("snd-hda-codec-id:14f15045");
1784MODULE_ALIAS("snd-hda-codec-id:14f15047");
1785MODULE_ALIAS("snd-hda-codec-id:14f15051");
1786
1787MODULE_LICENSE("GPL");
1788MODULE_DESCRIPTION("Conexant HD-audio codec");
1789
1790static struct hda_codec_preset_list conexant_list = {
1791 .preset = snd_hda_preset_conexant,
1792 .owner = THIS_MODULE,
1793};
1794
1795static int __init patch_conexant_init(void)
1796{
1797 return snd_hda_add_codec_preset(&conexant_list);
1798}
1799
1800static void __exit patch_conexant_exit(void)
1801{
1802 snd_hda_delete_codec_preset(&conexant_list);
1803}
1804
1805module_init(patch_conexant_init)
1806module_exit(patch_conexant_exit)
diff --git a/sound/pci/hda/patch_intelhdmi.c b/sound/pci/hda/patch_intelhdmi.c
new file mode 100644
index 000000000000..3564f4e4b74c
--- /dev/null
+++ b/sound/pci/hda/patch_intelhdmi.c
@@ -0,0 +1,711 @@
1/*
2 *
3 * patch_intelhdmi.c - Patch for Intel HDMI codecs
4 *
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
6 *
7 * Authors:
8 * Jiang Zhe <zhe.jiang@intel.com>
9 * Wu Fengguang <wfg@linux.intel.com>
10 *
11 * Maintained by:
12 * Wu Fengguang <wfg@linux.intel.com>
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29#include <linux/init.h>
30#include <linux/delay.h>
31#include <linux/slab.h>
32#include <sound/core.h>
33#include "hda_codec.h"
34#include "hda_local.h"
35
36#define CVT_NID 0x02 /* audio converter */
37#define PIN_NID 0x03 /* HDMI output pin */
38
39#define INTEL_HDMI_EVENT_TAG 0x08
40
41struct intel_hdmi_spec {
42 struct hda_multi_out multiout;
43 struct hda_pcm pcm_rec;
44 struct hdmi_eld sink_eld;
45};
46
47static struct hda_verb pinout_enable_verb[] = {
48 {PIN_NID, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
49 {} /* terminator */
50};
51
52static struct hda_verb pinout_disable_verb[] = {
53 {PIN_NID, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00},
54 {}
55};
56
57static struct hda_verb unsolicited_response_verb[] = {
58 {PIN_NID, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN |
59 INTEL_HDMI_EVENT_TAG},
60 {}
61};
62
63static struct hda_verb def_chan_map[] = {
64 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x00},
65 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x11},
66 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x22},
67 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x33},
68 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x44},
69 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x55},
70 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x66},
71 {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x77},
72 {}
73};
74
75
76struct hdmi_audio_infoframe {
77 u8 type; /* 0x84 */
78 u8 ver; /* 0x01 */
79 u8 len; /* 0x0a */
80
81 u8 checksum; /* PB0 */
82 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
83 u8 SS01_SF24;
84 u8 CXT04;
85 u8 CA;
86 u8 LFEPBL01_LSV36_DM_INH7;
87 u8 reserved[5]; /* PB6 - PB10 */
88};
89
90/*
91 * CEA speaker placement:
92 *
93 * FLH FCH FRH
94 * FLW FL FLC FC FRC FR FRW
95 *
96 * LFE
97 * TC
98 *
99 * RL RLC RC RRC RR
100 *
101 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
102 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
103 */
104enum cea_speaker_placement {
105 FL = (1 << 0), /* Front Left */
106 FC = (1 << 1), /* Front Center */
107 FR = (1 << 2), /* Front Right */
108 FLC = (1 << 3), /* Front Left Center */
109 FRC = (1 << 4), /* Front Right Center */
110 RL = (1 << 5), /* Rear Left */
111 RC = (1 << 6), /* Rear Center */
112 RR = (1 << 7), /* Rear Right */
113 RLC = (1 << 8), /* Rear Left Center */
114 RRC = (1 << 9), /* Rear Right Center */
115 LFE = (1 << 10), /* Low Frequency Effect */
116 FLW = (1 << 11), /* Front Left Wide */
117 FRW = (1 << 12), /* Front Right Wide */
118 FLH = (1 << 13), /* Front Left High */
119 FCH = (1 << 14), /* Front Center High */
120 FRH = (1 << 15), /* Front Right High */
121 TC = (1 << 16), /* Top Center */
122};
123
124/*
125 * ELD SA bits in the CEA Speaker Allocation data block
126 */
127static int eld_speaker_allocation_bits[] = {
128 [0] = FL | FR,
129 [1] = LFE,
130 [2] = FC,
131 [3] = RL | RR,
132 [4] = RC,
133 [5] = FLC | FRC,
134 [6] = RLC | RRC,
135 /* the following are not defined in ELD yet */
136 [7] = FLW | FRW,
137 [8] = FLH | FRH,
138 [9] = TC,
139 [10] = FCH,
140};
141
142struct cea_channel_speaker_allocation {
143 int ca_index;
144 int speakers[8];
145
146 /* derived values, just for convenience */
147 int channels;
148 int spk_mask;
149};
150
151/*
152 * This is an ordered list!
153 *
154 * The preceding ones have better chances to be selected by
155 * hdmi_setup_channel_allocation().
156 */
157static struct cea_channel_speaker_allocation channel_allocations[] = {
158/* channel: 8 7 6 5 4 3 2 1 */
159{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
160 /* 2.1 */
161{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
162 /* Dolby Surround */
163{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
164{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
165{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
166{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
167{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
168{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
169{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
170{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
171{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
172 /* 5.1 */
173{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
174{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
175{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
176{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
177 /* 6.1 */
178{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
179{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
180{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
181{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
182 /* 7.1 */
183{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
184{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
185{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
186{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
187{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
188{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
189{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
190{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
191{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
192{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
193{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
194{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
195{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
196{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
197{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
198{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
199{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
200{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
201{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
202{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
203{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
204{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
205{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
206{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
207{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
208{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
209{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
210{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
211{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
212{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
213{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
214};
215
216/*
217 * HDMI routines
218 */
219
220#ifdef BE_PARANOID
221static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t nid,
222 int *packet_index, int *byte_index)
223{
224 int val;
225
226 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_INDEX, 0);
227
228 *packet_index = val >> 5;
229 *byte_index = val & 0x1f;
230}
231#endif
232
233static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t nid,
234 int packet_index, int byte_index)
235{
236 int val;
237
238 val = (packet_index << 5) | (byte_index & 0x1f);
239
240 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
241}
242
243static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t nid,
244 unsigned char val)
245{
246 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
247}
248
249static void hdmi_enable_output(struct hda_codec *codec)
250{
251 /* Enable Audio InfoFrame Transmission */
252 hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0);
253 snd_hda_codec_write(codec, PIN_NID, 0, AC_VERB_SET_HDMI_DIP_XMIT,
254 AC_DIPXMIT_BEST);
255 /* Unmute */
256 if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP)
257 snd_hda_codec_write(codec, PIN_NID, 0,
258 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
259 /* Enable pin out */
260 snd_hda_sequence_write(codec, pinout_enable_verb);
261}
262
263static void hdmi_disable_output(struct hda_codec *codec)
264{
265 snd_hda_sequence_write(codec, pinout_disable_verb);
266 if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP)
267 snd_hda_codec_write(codec, PIN_NID, 0,
268 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
269
270 /*
271 * FIXME: noises may arise when playing music after reloading the
272 * kernel module, until the next X restart or monitor repower.
273 */
274}
275
276static int hdmi_get_channel_count(struct hda_codec *codec)
277{
278 return 1 + snd_hda_codec_read(codec, CVT_NID, 0,
279 AC_VERB_GET_CVT_CHAN_COUNT, 0);
280}
281
282static void hdmi_set_channel_count(struct hda_codec *codec, int chs)
283{
284 snd_hda_codec_write(codec, CVT_NID, 0,
285 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
286
287 if (chs != hdmi_get_channel_count(codec))
288 snd_printd(KERN_INFO "HDMI channel count: expect %d, get %d\n",
289 chs, hdmi_get_channel_count(codec));
290}
291
292static void hdmi_debug_channel_mapping(struct hda_codec *codec)
293{
294#ifdef CONFIG_SND_DEBUG_VERBOSE
295 int i;
296 int slot;
297
298 for (i = 0; i < 8; i++) {
299 slot = snd_hda_codec_read(codec, CVT_NID, 0,
300 AC_VERB_GET_HDMI_CHAN_SLOT, i);
301 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
302 slot >> 4, slot & 0x7);
303 }
304#endif
305}
306
307static void hdmi_parse_eld(struct hda_codec *codec)
308{
309 struct intel_hdmi_spec *spec = codec->spec;
310 struct hdmi_eld *eld = &spec->sink_eld;
311
312 if (!snd_hdmi_get_eld(eld, codec, PIN_NID))
313 snd_hdmi_show_eld(eld);
314}
315
316
317/*
318 * Audio InfoFrame routines
319 */
320
321static void hdmi_debug_dip_size(struct hda_codec *codec)
322{
323#ifdef CONFIG_SND_DEBUG_VERBOSE
324 int i;
325 int size;
326
327 size = snd_hdmi_get_eld_size(codec, PIN_NID);
328 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
329
330 for (i = 0; i < 8; i++) {
331 size = snd_hda_codec_read(codec, PIN_NID, 0,
332 AC_VERB_GET_HDMI_DIP_SIZE, i);
333 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
334 }
335#endif
336}
337
338static void hdmi_clear_dip_buffers(struct hda_codec *codec)
339{
340#ifdef BE_PARANOID
341 int i, j;
342 int size;
343 int pi, bi;
344 for (i = 0; i < 8; i++) {
345 size = snd_hda_codec_read(codec, PIN_NID, 0,
346 AC_VERB_GET_HDMI_DIP_SIZE, i);
347 if (size == 0)
348 continue;
349
350 hdmi_set_dip_index(codec, PIN_NID, i, 0x0);
351 for (j = 1; j < 1000; j++) {
352 hdmi_write_dip_byte(codec, PIN_NID, 0x0);
353 hdmi_get_dip_index(codec, PIN_NID, &pi, &bi);
354 if (pi != i)
355 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
356 bi, pi, i);
357 if (bi == 0) /* byte index wrapped around */
358 break;
359 }
360 snd_printd(KERN_INFO
361 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
362 i, size, j);
363 }
364#endif
365}
366
367static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
368 struct hdmi_audio_infoframe *ai)
369{
370 u8 *params = (u8 *)ai;
371 int i;
372
373 hdmi_debug_dip_size(codec);
374 hdmi_clear_dip_buffers(codec); /* be paranoid */
375
376 hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0);
377 for (i = 0; i < sizeof(ai); i++)
378 hdmi_write_dip_byte(codec, PIN_NID, params[i]);
379}
380
381/*
382 * Compute derived values in channel_allocations[].
383 */
384static void init_channel_allocations(void)
385{
386 int i, j;
387 struct cea_channel_speaker_allocation *p;
388
389 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
390 p = channel_allocations + i;
391 p->channels = 0;
392 p->spk_mask = 0;
393 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
394 if (p->speakers[j]) {
395 p->channels++;
396 p->spk_mask |= p->speakers[j];
397 }
398 }
399}
400
401/*
402 * The transformation takes two steps:
403 *
404 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
405 * spk_mask => (channel_allocations[]) => ai->CA
406 *
407 * TODO: it could select the wrong CA from multiple candidates.
408*/
409static int hdmi_setup_channel_allocation(struct hda_codec *codec,
410 struct hdmi_audio_infoframe *ai)
411{
412 struct intel_hdmi_spec *spec = codec->spec;
413 struct hdmi_eld *eld = &spec->sink_eld;
414 int i;
415 int spk_mask = 0;
416 int channels = 1 + (ai->CC02_CT47 & 0x7);
417 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
418
419 /*
420 * CA defaults to 0 for basic stereo audio
421 */
422 if (!eld->eld_ver)
423 return 0;
424 if (!eld->spk_alloc)
425 return 0;
426 if (channels <= 2)
427 return 0;
428
429 /*
430 * expand ELD's speaker allocation mask
431 *
432 * ELD tells the speaker mask in a compact(paired) form,
433 * expand ELD's notions to match the ones used by Audio InfoFrame.
434 */
435 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
436 if (eld->spk_alloc & (1 << i))
437 spk_mask |= eld_speaker_allocation_bits[i];
438 }
439
440 /* search for the first working match in the CA table */
441 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
442 if (channels == channel_allocations[i].channels &&
443 (spk_mask & channel_allocations[i].spk_mask) ==
444 channel_allocations[i].spk_mask) {
445 ai->CA = channel_allocations[i].ca_index;
446 break;
447 }
448 }
449
450 snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
451 snd_printdd(KERN_INFO
452 "HDMI: select CA 0x%x for %d-channel allocation: %s\n",
453 ai->CA, channels, buf);
454
455 return ai->CA;
456}
457
458static void hdmi_setup_channel_mapping(struct hda_codec *codec,
459 struct hdmi_audio_infoframe *ai)
460{
461 if (!ai->CA)
462 return;
463
464 /*
465 * TODO: adjust channel mapping if necessary
466 * ALSA sequence is front/surr/clfe/side?
467 */
468
469 snd_hda_sequence_write(codec, def_chan_map);
470 hdmi_debug_channel_mapping(codec);
471}
472
473
474static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
475 struct snd_pcm_substream *substream)
476{
477 struct hdmi_audio_infoframe ai = {
478 .type = 0x84,
479 .ver = 0x01,
480 .len = 0x0a,
481 .CC02_CT47 = substream->runtime->channels - 1,
482 };
483
484 hdmi_setup_channel_allocation(codec, &ai);
485 hdmi_setup_channel_mapping(codec, &ai);
486
487 hdmi_fill_audio_infoframe(codec, &ai);
488}
489
490
491/*
492 * Unsolicited events
493 */
494
495static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
496{
497 int pind = !!(res & AC_UNSOL_RES_PD);
498 int eldv = !!(res & AC_UNSOL_RES_ELDV);
499
500 printk(KERN_INFO
501 "HDMI hot plug event: Presence_Detect=%d ELD_Valid=%d\n",
502 pind, eldv);
503
504 if (pind && eldv) {
505 hdmi_parse_eld(codec);
506 /* TODO: do real things about ELD */
507 }
508}
509
510static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
511{
512 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
513 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
514 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
515
516 printk(KERN_INFO
517 "HDMI content protection event: SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
518 subtag,
519 cp_state,
520 cp_ready);
521
522 /* TODO */
523 if (cp_state)
524 ;
525 if (cp_ready)
526 ;
527}
528
529
530static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
531{
532 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
533 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
534
535 if (tag != INTEL_HDMI_EVENT_TAG) {
536 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
537 return;
538 }
539
540 if (subtag == 0)
541 hdmi_intrinsic_event(codec, res);
542 else
543 hdmi_non_intrinsic_event(codec, res);
544}
545
546/*
547 * Callbacks
548 */
549
550static int intel_hdmi_playback_pcm_open(struct hda_pcm_stream *hinfo,
551 struct hda_codec *codec,
552 struct snd_pcm_substream *substream)
553{
554 struct intel_hdmi_spec *spec = codec->spec;
555
556 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
557}
558
559static int intel_hdmi_playback_pcm_close(struct hda_pcm_stream *hinfo,
560 struct hda_codec *codec,
561 struct snd_pcm_substream *substream)
562{
563 struct intel_hdmi_spec *spec = codec->spec;
564
565 hdmi_disable_output(codec);
566
567 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
568}
569
570static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
571 struct hda_codec *codec,
572 unsigned int stream_tag,
573 unsigned int format,
574 struct snd_pcm_substream *substream)
575{
576 struct intel_hdmi_spec *spec = codec->spec;
577
578 snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
579 format, substream);
580
581 hdmi_set_channel_count(codec, substream->runtime->channels);
582
583 hdmi_setup_audio_infoframe(codec, substream);
584
585 hdmi_enable_output(codec);
586
587 return 0;
588}
589
590static struct hda_pcm_stream intel_hdmi_pcm_playback = {
591 .substreams = 1,
592 .channels_min = 2,
593 .channels_max = 8,
594 .nid = CVT_NID, /* NID to query formats and rates and setup streams */
595 .ops = {
596 .open = intel_hdmi_playback_pcm_open,
597 .close = intel_hdmi_playback_pcm_close,
598 .prepare = intel_hdmi_playback_pcm_prepare
599 },
600};
601
602static int intel_hdmi_build_pcms(struct hda_codec *codec)
603{
604 struct intel_hdmi_spec *spec = codec->spec;
605 struct hda_pcm *info = &spec->pcm_rec;
606
607 codec->num_pcms = 1;
608 codec->pcm_info = info;
609
610 info->name = "INTEL HDMI";
611 info->pcm_type = HDA_PCM_TYPE_HDMI;
612 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = intel_hdmi_pcm_playback;
613
614 return 0;
615}
616
617static int intel_hdmi_build_controls(struct hda_codec *codec)
618{
619 struct intel_hdmi_spec *spec = codec->spec;
620 int err;
621
622 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
623 if (err < 0)
624 return err;
625
626 return 0;
627}
628
629static int intel_hdmi_init(struct hda_codec *codec)
630{
631 /* disable audio output as early as possible */
632 hdmi_disable_output(codec);
633
634 snd_hda_sequence_write(codec, unsolicited_response_verb);
635
636 return 0;
637}
638
639static void intel_hdmi_free(struct hda_codec *codec)
640{
641 struct intel_hdmi_spec *spec = codec->spec;
642
643 snd_hda_eld_proc_free(codec, &spec->sink_eld);
644 kfree(spec);
645}
646
647static struct hda_codec_ops intel_hdmi_patch_ops = {
648 .init = intel_hdmi_init,
649 .free = intel_hdmi_free,
650 .build_pcms = intel_hdmi_build_pcms,
651 .build_controls = intel_hdmi_build_controls,
652 .unsol_event = intel_hdmi_unsol_event,
653};
654
655static int patch_intel_hdmi(struct hda_codec *codec)
656{
657 struct intel_hdmi_spec *spec;
658
659 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
660 if (spec == NULL)
661 return -ENOMEM;
662
663 spec->multiout.num_dacs = 0; /* no analog */
664 spec->multiout.max_channels = 8;
665 spec->multiout.dig_out_nid = CVT_NID;
666
667 codec->spec = spec;
668 codec->patch_ops = intel_hdmi_patch_ops;
669
670 snd_hda_eld_proc_new(codec, &spec->sink_eld);
671
672 init_channel_allocations();
673
674 return 0;
675}
676
677static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
678 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi },
679 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi },
680 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi },
681 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi },
682 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
683 {} /* terminator */
684};
685
686MODULE_ALIAS("snd-hda-codec-id:808629fb");
687MODULE_ALIAS("snd-hda-codec-id:80862801");
688MODULE_ALIAS("snd-hda-codec-id:80862802");
689MODULE_ALIAS("snd-hda-codec-id:80862803");
690MODULE_ALIAS("snd-hda-codec-id:10951392");
691
692MODULE_LICENSE("GPL");
693MODULE_DESCRIPTION("Intel HDMI HD-audio codec");
694
695static struct hda_codec_preset_list intel_list = {
696 .preset = snd_hda_preset_intelhdmi,
697 .owner = THIS_MODULE,
698};
699
700static int __init patch_intelhdmi_init(void)
701{
702 return snd_hda_add_codec_preset(&intel_list);
703}
704
705static void __exit patch_intelhdmi_exit(void)
706{
707 snd_hda_delete_codec_preset(&intel_list);
708}
709
710module_init(patch_intelhdmi_init)
711module_exit(patch_intelhdmi_exit)
diff --git a/sound/pci/hda/patch_nvhdmi.c b/sound/pci/hda/patch_nvhdmi.c
index 2eed2c8b98da..0270fda0bda5 100644
--- a/sound/pci/hda/patch_nvhdmi.c
+++ b/sound/pci/hda/patch_nvhdmi.c
@@ -158,8 +158,34 @@ static int patch_nvhdmi(struct hda_codec *codec)
158/* 158/*
159 * patch entries 159 * patch entries
160 */ 160 */
161struct hda_codec_preset snd_hda_preset_nvhdmi[] = { 161static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
162 { .id = 0x10de0002, .name = "NVIDIA MCP78 HDMI", .patch = patch_nvhdmi }, 162 { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi },
163 { .id = 0x10de0007, .name = "NVIDIA MCP7A HDMI", .patch = patch_nvhdmi }, 163 { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi },
164 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi },
164 {} /* terminator */ 165 {} /* terminator */
165}; 166};
167
168MODULE_ALIAS("snd-hda-codec-id:10de0002");
169MODULE_ALIAS("snd-hda-codec-id:10de0007");
170MODULE_ALIAS("snd-hda-codec-id:10de0067");
171
172MODULE_LICENSE("GPL");
173MODULE_DESCRIPTION("Nvidia HDMI HD-audio codec");
174
175static struct hda_codec_preset_list nvhdmi_list = {
176 .preset = snd_hda_preset_nvhdmi,
177 .owner = THIS_MODULE,
178};
179
180static int __init patch_nvhdmi_init(void)
181{
182 return snd_hda_add_codec_preset(&nvhdmi_list);
183}
184
185static void __exit patch_nvhdmi_exit(void)
186{
187 snd_hda_delete_codec_preset(&nvhdmi_list);
188}
189
190module_init(patch_nvhdmi_init)
191module_exit(patch_nvhdmi_exit)
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index a378c0145125..0bd4e6bf354d 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -30,7 +30,6 @@
30#include <sound/core.h> 30#include <sound/core.h>
31#include "hda_codec.h" 31#include "hda_codec.h"
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_patch.h"
34 33
35#define ALC880_FRONT_EVENT 0x01 34#define ALC880_FRONT_EVENT 0x01
36#define ALC880_DCVOL_EVENT 0x02 35#define ALC880_DCVOL_EVENT 0x02
@@ -114,6 +113,7 @@ enum {
114 ALC268_3ST, 113 ALC268_3ST,
115 ALC268_TOSHIBA, 114 ALC268_TOSHIBA,
116 ALC268_ACER, 115 ALC268_ACER,
116 ALC268_ACER_DMIC,
117 ALC268_ACER_ASPIRE_ONE, 117 ALC268_ACER_ASPIRE_ONE,
118 ALC268_DELL, 118 ALC268_DELL,
119 ALC268_ZEPTO, 119 ALC268_ZEPTO,
@@ -130,6 +130,8 @@ enum {
130 ALC269_QUANTA_FL1, 130 ALC269_QUANTA_FL1,
131 ALC269_ASUS_EEEPC_P703, 131 ALC269_ASUS_EEEPC_P703,
132 ALC269_ASUS_EEEPC_P901, 132 ALC269_ASUS_EEEPC_P901,
133 ALC269_FUJITSU,
134 ALC269_LIFEBOOK,
133 ALC269_AUTO, 135 ALC269_AUTO,
134 ALC269_MODEL_LAST /* last tag */ 136 ALC269_MODEL_LAST /* last tag */
135}; 137};
@@ -152,6 +154,7 @@ enum {
152enum { 154enum {
153 ALC660VD_3ST, 155 ALC660VD_3ST,
154 ALC660VD_3ST_DIG, 156 ALC660VD_3ST_DIG,
157 ALC660VD_ASUS_V1S,
155 ALC861VD_3ST, 158 ALC861VD_3ST,
156 ALC861VD_3ST_DIG, 159 ALC861VD_3ST_DIG,
157 ALC861VD_6ST_DIG, 160 ALC861VD_6ST_DIG,
@@ -212,6 +215,7 @@ enum {
212 ALC883_TARGA_2ch_DIG, 215 ALC883_TARGA_2ch_DIG,
213 ALC883_ACER, 216 ALC883_ACER,
214 ALC883_ACER_ASPIRE, 217 ALC883_ACER_ASPIRE,
218 ALC888_ACER_ASPIRE_4930G,
215 ALC883_MEDION, 219 ALC883_MEDION,
216 ALC883_MEDION_MD2, 220 ALC883_MEDION_MD2,
217 ALC883_LAPTOP_EAPD, 221 ALC883_LAPTOP_EAPD,
@@ -225,9 +229,11 @@ enum {
225 ALC883_MITAC, 229 ALC883_MITAC,
226 ALC883_CLEVO_M720, 230 ALC883_CLEVO_M720,
227 ALC883_FUJITSU_PI2515, 231 ALC883_FUJITSU_PI2515,
232 ALC888_FUJITSU_XA3530,
228 ALC883_3ST_6ch_INTEL, 233 ALC883_3ST_6ch_INTEL,
229 ALC888_ASUS_M90V, 234 ALC888_ASUS_M90V,
230 ALC888_ASUS_EEE1601, 235 ALC888_ASUS_EEE1601,
236 ALC1200_ASUS_P5Q,
231 ALC883_AUTO, 237 ALC883_AUTO,
232 ALC883_MODEL_LAST, 238 ALC883_MODEL_LAST,
233}; 239};
@@ -239,6 +245,7 @@ struct alc_spec {
239 /* codec parameterization */ 245 /* codec parameterization */
240 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ 246 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
241 unsigned int num_mixers; 247 unsigned int num_mixers;
248 struct snd_kcontrol_new *cap_mixer; /* capture mixer */
242 249
243 const struct hda_verb *init_verbs[5]; /* initialization verbs 250 const struct hda_verb *init_verbs[5]; /* initialization verbs
244 * don't forget NULL 251 * don't forget NULL
@@ -268,6 +275,7 @@ struct alc_spec {
268 hda_nid_t *adc_nids; 275 hda_nid_t *adc_nids;
269 hda_nid_t *capsrc_nids; 276 hda_nid_t *capsrc_nids;
270 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 277 hda_nid_t dig_in_nid; /* digital-in NID; optional */
278 unsigned char is_mix_capture; /* matrix-style capture (non-mux) */
271 279
272 /* capture source */ 280 /* capture source */
273 unsigned int num_mux_defs; 281 unsigned int num_mux_defs;
@@ -284,8 +292,7 @@ struct alc_spec {
284 292
285 /* dynamic controls, init_verbs and input_mux */ 293 /* dynamic controls, init_verbs and input_mux */
286 struct auto_pin_cfg autocfg; 294 struct auto_pin_cfg autocfg;
287 unsigned int num_kctl_alloc, num_kctl_used; 295 struct snd_array kctls;
288 struct snd_kcontrol_new *kctl_alloc;
289 struct hda_input_mux private_imux; 296 struct hda_input_mux private_imux;
290 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 297 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
291 298
@@ -323,6 +330,7 @@ struct alc_config_preset {
323 struct snd_kcontrol_new *mixers[5]; /* should be identical size 330 struct snd_kcontrol_new *mixers[5]; /* should be identical size
324 * with spec 331 * with spec
325 */ 332 */
333 struct snd_kcontrol_new *cap_mixer; /* capture mixer */
326 const struct hda_verb *init_verbs[5]; 334 const struct hda_verb *init_verbs[5];
327 unsigned int num_dacs; 335 unsigned int num_dacs;
328 hda_nid_t *dac_nids; 336 hda_nid_t *dac_nids;
@@ -375,14 +383,39 @@ static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
375{ 383{
376 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 384 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377 struct alc_spec *spec = codec->spec; 385 struct alc_spec *spec = codec->spec;
386 const struct hda_input_mux *imux;
378 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 387 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; 388 unsigned int mux_idx;
380 hda_nid_t nid = spec->capsrc_nids ? 389 hda_nid_t nid = spec->capsrc_nids ?
381 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx]; 390 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
382 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
383 nid, &spec->cur_mux[adc_idx]);
384}
385 391
392 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
393 imux = &spec->input_mux[mux_idx];
394
395 if (spec->is_mix_capture) {
396 /* Matrix-mixer style (e.g. ALC882) */
397 unsigned int *cur_val = &spec->cur_mux[adc_idx];
398 unsigned int i, idx;
399
400 idx = ucontrol->value.enumerated.item[0];
401 if (idx >= imux->num_items)
402 idx = imux->num_items - 1;
403 if (*cur_val == idx)
404 return 0;
405 for (i = 0; i < imux->num_items; i++) {
406 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
407 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
408 imux->items[i].index,
409 HDA_AMP_MUTE, v);
410 }
411 *cur_val = idx;
412 return 1;
413 } else {
414 /* MUX style (e.g. ALC880) */
415 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
416 &spec->cur_mux[adc_idx]);
417 }
418}
386 419
387/* 420/*
388 * channel mode setting 421 * channel mode setting
@@ -717,6 +750,43 @@ static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
717#endif /* CONFIG_SND_DEBUG */ 750#endif /* CONFIG_SND_DEBUG */
718 751
719/* 752/*
753 */
754static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
755{
756 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
757 return;
758 spec->mixers[spec->num_mixers++] = mix;
759}
760
761static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
762{
763 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
764 return;
765 spec->init_verbs[spec->num_init_verbs++] = verb;
766}
767
768#ifdef CONFIG_PROC_FS
769/*
770 * hook for proc
771 */
772static void print_realtek_coef(struct snd_info_buffer *buffer,
773 struct hda_codec *codec, hda_nid_t nid)
774{
775 int coeff;
776
777 if (nid != 0x20)
778 return;
779 coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
780 snd_iprintf(buffer, " Processing Coefficient: 0x%02x\n", coeff);
781 coeff = snd_hda_codec_read(codec, nid, 0,
782 AC_VERB_GET_COEF_INDEX, 0);
783 snd_iprintf(buffer, " Coefficient Index: 0x%02x\n", coeff);
784}
785#else
786#define print_realtek_coef NULL
787#endif
788
789/*
720 * set up from the preset table 790 * set up from the preset table
721 */ 791 */
722static void setup_preset(struct alc_spec *spec, 792static void setup_preset(struct alc_spec *spec,
@@ -725,11 +795,11 @@ static void setup_preset(struct alc_spec *spec,
725 int i; 795 int i;
726 796
727 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++) 797 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
728 spec->mixers[spec->num_mixers++] = preset->mixers[i]; 798 add_mixer(spec, preset->mixers[i]);
799 spec->cap_mixer = preset->cap_mixer;
729 for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i]; 800 for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
730 i++) 801 i++)
731 spec->init_verbs[spec->num_init_verbs++] = 802 add_verb(spec, preset->init_verbs[i]);
732 preset->init_verbs[i];
733 803
734 spec->channel_mode = preset->channel_mode; 804 spec->channel_mode = preset->channel_mode;
735 spec->num_channel_mode = preset->num_channel_mode; 805 spec->num_channel_mode = preset->num_channel_mode;
@@ -1107,6 +1177,226 @@ static void alc_fix_pincfg(struct hda_codec *codec,
1107} 1177}
1108 1178
1109/* 1179/*
1180 * ALC888
1181 */
1182
1183/*
1184 * 2ch mode
1185 */
1186static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1187/* Mic-in jack as mic in */
1188 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1189 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1190/* Line-in jack as Line in */
1191 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1192 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1193/* Line-Out as Front */
1194 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1195 { } /* end */
1196};
1197
1198/*
1199 * 4ch mode
1200 */
1201static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1202/* Mic-in jack as mic in */
1203 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1204 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1205/* Line-in jack as Surround */
1206 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1207 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1208/* Line-Out as Front */
1209 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1210 { } /* end */
1211};
1212
1213/*
1214 * 6ch mode
1215 */
1216static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1217/* Mic-in jack as CLFE */
1218 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1219 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1220/* Line-in jack as Surround */
1221 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1222 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1223/* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1224 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1225 { } /* end */
1226};
1227
1228/*
1229 * 8ch mode
1230 */
1231static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1232/* Mic-in jack as CLFE */
1233 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1234 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1235/* Line-in jack as Surround */
1236 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1237 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1238/* Line-Out as Side */
1239 { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1240 { } /* end */
1241};
1242
1243static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1244 { 2, alc888_4ST_ch2_intel_init },
1245 { 4, alc888_4ST_ch4_intel_init },
1246 { 6, alc888_4ST_ch6_intel_init },
1247 { 8, alc888_4ST_ch8_intel_init },
1248};
1249
1250/*
1251 * ALC888 Fujitsu Siemens Amillo xa3530
1252 */
1253
1254static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1255/* Front Mic: set to PIN_IN (empty by default) */
1256 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1257/* Connect Internal HP to Front */
1258 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1259 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1260 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1261/* Connect Bass HP to Front */
1262 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1263 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1264 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1265/* Connect Line-Out side jack (SPDIF) to Side */
1266 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1267 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1268 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1269/* Connect Mic jack to CLFE */
1270 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1271 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1272 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1273/* Connect Line-in jack to Surround */
1274 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1275 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1276 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1277/* Connect HP out jack to Front */
1278 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1279 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1280 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1281/* Enable unsolicited event for HP jack and Line-out jack */
1282 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1283 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1284 {}
1285};
1286
1287static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1288{
1289 unsigned int present;
1290 unsigned int bits;
1291 /* Line out presence */
1292 present = snd_hda_codec_read(codec, 0x17, 0,
1293 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1294 /* HP out presence */
1295 present = present || snd_hda_codec_read(codec, 0x1b, 0,
1296 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1297 bits = present ? HDA_AMP_MUTE : 0;
1298 /* Toggle internal speakers muting */
1299 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1300 HDA_AMP_MUTE, bits);
1301 /* Toggle internal bass muting */
1302 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1303 HDA_AMP_MUTE, bits);
1304}
1305
1306static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1307 unsigned int res)
1308{
1309 if (res >> 26 == ALC880_HP_EVENT)
1310 alc888_fujitsu_xa3530_automute(codec);
1311}
1312
1313
1314/*
1315 * ALC888 Acer Aspire 4930G model
1316 */
1317
1318static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1319/* Front Mic: set to PIN_IN (empty by default) */
1320 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1321/* Unselect Front Mic by default in input mixer 3 */
1322 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1323/* Enable unsolicited event for HP jack */
1324 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1325/* Connect Internal HP to front */
1326 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1327 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1328 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1329/* Connect HP out to front */
1330 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1331 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1332 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1333 { }
1334};
1335
1336static struct hda_input_mux alc888_2_capture_sources[2] = {
1337 /* Front mic only available on one ADC */
1338 {
1339 .num_items = 4,
1340 .items = {
1341 { "Mic", 0x0 },
1342 { "Line", 0x2 },
1343 { "CD", 0x4 },
1344 { "Front Mic", 0xb },
1345 },
1346 },
1347 {
1348 .num_items = 3,
1349 .items = {
1350 { "Mic", 0x0 },
1351 { "Line", 0x2 },
1352 { "CD", 0x4 },
1353 },
1354 }
1355};
1356
1357static struct snd_kcontrol_new alc888_base_mixer[] = {
1358 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1359 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1360 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1361 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1362 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1363 HDA_OUTPUT),
1364 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1365 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1366 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1367 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1368 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1369 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1370 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1371 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1372 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1373 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1374 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1375 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1376 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1377 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1378 { } /* end */
1379};
1380
1381static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1382{
1383 unsigned int present;
1384 unsigned int bits;
1385 present = snd_hda_codec_read(codec, 0x15, 0,
1386 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1387 bits = present ? HDA_AMP_MUTE : 0;
1388 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1389 HDA_AMP_MUTE, bits);
1390}
1391
1392static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1393 unsigned int res)
1394{
1395 if (res >> 26 == ALC880_HP_EVENT)
1396 alc888_acer_aspire_4930g_automute(codec);
1397}
1398
1399/*
1110 * ALC880 3-stack model 1400 * ALC880 3-stack model
1111 * 1401 *
1112 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e) 1402 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
@@ -1205,49 +1495,126 @@ static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1205}; 1495};
1206 1496
1207/* capture mixer elements */ 1497/* capture mixer elements */
1208static struct snd_kcontrol_new alc880_capture_mixer[] = { 1498static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1209 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT), 1499 struct snd_ctl_elem_info *uinfo)
1210 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT), 1500{
1211 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT), 1501 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1212 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT), 1502 struct alc_spec *spec = codec->spec;
1213 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT), 1503 int err;
1214 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1215 {
1216 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1217 /* The multiple "Capture Source" controls confuse alsamixer
1218 * So call somewhat different..
1219 */
1220 /* .name = "Capture Source", */
1221 .name = "Input Source",
1222 .count = 3,
1223 .info = alc_mux_enum_info,
1224 .get = alc_mux_enum_get,
1225 .put = alc_mux_enum_put,
1226 },
1227 { } /* end */
1228};
1229 1504
1230/* capture mixer elements (in case NID 0x07 not available) */ 1505 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1231static struct snd_kcontrol_new alc880_capture_alt_mixer[] = { 1506 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1232 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 1507 HDA_INPUT);
1233 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 1508 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1234 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT), 1509 mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1235 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT), 1510 return err;
1236 { 1511}
1237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1512
1238 /* The multiple "Capture Source" controls confuse alsamixer 1513static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1239 * So call somewhat different.. 1514 unsigned int size, unsigned int __user *tlv)
1240 */ 1515{
1241 /* .name = "Capture Source", */ 1516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1242 .name = "Input Source", 1517 struct alc_spec *spec = codec->spec;
1243 .count = 2, 1518 int err;
1244 .info = alc_mux_enum_info,
1245 .get = alc_mux_enum_get,
1246 .put = alc_mux_enum_put,
1247 },
1248 { } /* end */
1249};
1250 1519
1520 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1521 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1522 HDA_INPUT);
1523 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1524 mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1525 return err;
1526}
1527
1528typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1529 struct snd_ctl_elem_value *ucontrol);
1530
1531static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1532 struct snd_ctl_elem_value *ucontrol,
1533 getput_call_t func)
1534{
1535 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1536 struct alc_spec *spec = codec->spec;
1537 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1538 int err;
1539
1540 mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1541 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1542 3, 0, HDA_INPUT);
1543 err = func(kcontrol, ucontrol);
1544 mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1545 return err;
1546}
1547
1548static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1549 struct snd_ctl_elem_value *ucontrol)
1550{
1551 return alc_cap_getput_caller(kcontrol, ucontrol,
1552 snd_hda_mixer_amp_volume_get);
1553}
1554
1555static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1556 struct snd_ctl_elem_value *ucontrol)
1557{
1558 return alc_cap_getput_caller(kcontrol, ucontrol,
1559 snd_hda_mixer_amp_volume_put);
1560}
1561
1562/* capture mixer elements */
1563#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1564
1565static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1566 struct snd_ctl_elem_value *ucontrol)
1567{
1568 return alc_cap_getput_caller(kcontrol, ucontrol,
1569 snd_hda_mixer_amp_switch_get);
1570}
1571
1572static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1573 struct snd_ctl_elem_value *ucontrol)
1574{
1575 return alc_cap_getput_caller(kcontrol, ucontrol,
1576 snd_hda_mixer_amp_switch_put);
1577}
1578
1579#define DEFINE_CAPMIX(num) \
1580static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1581 { \
1582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1583 .name = "Capture Switch", \
1584 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1585 .count = num, \
1586 .info = alc_cap_sw_info, \
1587 .get = alc_cap_sw_get, \
1588 .put = alc_cap_sw_put, \
1589 }, \
1590 { \
1591 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1592 .name = "Capture Volume", \
1593 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1594 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1595 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1596 .count = num, \
1597 .info = alc_cap_vol_info, \
1598 .get = alc_cap_vol_get, \
1599 .put = alc_cap_vol_put, \
1600 .tlv = { .c = alc_cap_vol_tlv }, \
1601 }, \
1602 { \
1603 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1604 /* .name = "Capture Source", */ \
1605 .name = "Input Source", \
1606 .count = num, \
1607 .info = alc_mux_enum_info, \
1608 .get = alc_mux_enum_get, \
1609 .put = alc_mux_enum_put, \
1610 }, \
1611 { } /* end */ \
1612}
1613
1614/* up to three ADCs */
1615DEFINE_CAPMIX(1);
1616DEFINE_CAPMIX(2);
1617DEFINE_CAPMIX(3);
1251 1618
1252 1619
1253/* 1620/*
@@ -1533,18 +1900,6 @@ static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1533 HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT), 1900 HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1534 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 1901 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1535 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 1902 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1536 {
1537 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1538 /* The multiple "Capture Source" controls confuse alsamixer
1539 * So call somewhat different..
1540 */
1541 /* .name = "Capture Source", */
1542 .name = "Input Source",
1543 .count = 1,
1544 .info = alc_mux_enum_info,
1545 .get = alc_mux_enum_get,
1546 .put = alc_mux_enum_put,
1547 },
1548 { } /* end */ 1903 { } /* end */
1549}; 1904};
1550 1905
@@ -1619,6 +1974,7 @@ static const char *alc_slave_vols[] = {
1619 "Speaker Playback Volume", 1974 "Speaker Playback Volume",
1620 "Mono Playback Volume", 1975 "Mono Playback Volume",
1621 "Line-Out Playback Volume", 1976 "Line-Out Playback Volume",
1977 "PCM Playback Volume",
1622 NULL, 1978 NULL,
1623}; 1979};
1624 1980
@@ -1638,6 +1994,9 @@ static const char *alc_slave_sws[] = {
1638/* 1994/*
1639 * build control elements 1995 * build control elements
1640 */ 1996 */
1997
1998static void alc_free_kctls(struct hda_codec *codec);
1999
1641static int alc_build_controls(struct hda_codec *codec) 2000static int alc_build_controls(struct hda_codec *codec)
1642{ 2001{
1643 struct alc_spec *spec = codec->spec; 2002 struct alc_spec *spec = codec->spec;
@@ -1649,7 +2008,11 @@ static int alc_build_controls(struct hda_codec *codec)
1649 if (err < 0) 2008 if (err < 0)
1650 return err; 2009 return err;
1651 } 2010 }
1652 2011 if (spec->cap_mixer) {
2012 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2013 if (err < 0)
2014 return err;
2015 }
1653 if (spec->multiout.dig_out_nid) { 2016 if (spec->multiout.dig_out_nid) {
1654 err = snd_hda_create_spdif_out_ctls(codec, 2017 err = snd_hda_create_spdif_out_ctls(codec,
1655 spec->multiout.dig_out_nid); 2018 spec->multiout.dig_out_nid);
@@ -1684,6 +2047,7 @@ static int alc_build_controls(struct hda_codec *codec)
1684 return err; 2047 return err;
1685 } 2048 }
1686 2049
2050 alc_free_kctls(codec); /* no longer needed */
1687 return 0; 2051 return 0;
1688} 2052}
1689 2053
@@ -2774,19 +3138,27 @@ static int alc_build_pcms(struct hda_codec *codec)
2774 return 0; 3138 return 0;
2775} 3139}
2776 3140
3141static void alc_free_kctls(struct hda_codec *codec)
3142{
3143 struct alc_spec *spec = codec->spec;
3144
3145 if (spec->kctls.list) {
3146 struct snd_kcontrol_new *kctl = spec->kctls.list;
3147 int i;
3148 for (i = 0; i < spec->kctls.used; i++)
3149 kfree(kctl[i].name);
3150 }
3151 snd_array_free(&spec->kctls);
3152}
3153
2777static void alc_free(struct hda_codec *codec) 3154static void alc_free(struct hda_codec *codec)
2778{ 3155{
2779 struct alc_spec *spec = codec->spec; 3156 struct alc_spec *spec = codec->spec;
2780 unsigned int i;
2781 3157
2782 if (!spec) 3158 if (!spec)
2783 return; 3159 return;
2784 3160
2785 if (spec->kctl_alloc) { 3161 alc_free_kctls(codec);
2786 for (i = 0; i < spec->num_kctl_used; i++)
2787 kfree(spec->kctl_alloc[i].name);
2788 kfree(spec->kctl_alloc);
2789 }
2790 kfree(spec); 3162 kfree(spec);
2791 codec->spec = NULL; /* to be sure */ 3163 codec->spec = NULL; /* to be sure */
2792} 3164}
@@ -3268,6 +3640,8 @@ static struct alc_config_preset alc880_presets[] = {
3268 alc880_gpio2_init_verbs }, 3640 alc880_gpio2_init_verbs },
3269 .num_dacs = ARRAY_SIZE(alc880_dac_nids), 3641 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3270 .dac_nids = alc880_dac_nids, 3642 .dac_nids = alc880_dac_nids,
3643 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3644 .num_adc_nids = 1, /* single ADC */
3271 .hp_nid = 0x03, 3645 .hp_nid = 0x03,
3272 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes), 3646 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3273 .channel_mode = alc880_2_jack_modes, 3647 .channel_mode = alc880_2_jack_modes,
@@ -3532,9 +3906,6 @@ static struct alc_config_preset alc880_presets[] = {
3532 * Automatic parse of I/O pins from the BIOS configuration 3906 * Automatic parse of I/O pins from the BIOS configuration
3533 */ 3907 */
3534 3908
3535#define NUM_CONTROL_ALLOC 32
3536#define NUM_VERB_ALLOC 32
3537
3538enum { 3909enum {
3539 ALC_CTL_WIDGET_VOL, 3910 ALC_CTL_WIDGET_VOL,
3540 ALC_CTL_WIDGET_MUTE, 3911 ALC_CTL_WIDGET_MUTE,
@@ -3552,29 +3923,15 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
3552{ 3923{
3553 struct snd_kcontrol_new *knew; 3924 struct snd_kcontrol_new *knew;
3554 3925
3555 if (spec->num_kctl_used >= spec->num_kctl_alloc) { 3926 snd_array_init(&spec->kctls, sizeof(*knew), 32);
3556 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC; 3927 knew = snd_array_new(&spec->kctls);
3557 3928 if (!knew)
3558 /* array + terminator */ 3929 return -ENOMEM;
3559 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3560 if (!knew)
3561 return -ENOMEM;
3562 if (spec->kctl_alloc) {
3563 memcpy(knew, spec->kctl_alloc,
3564 sizeof(*knew) * spec->num_kctl_alloc);
3565 kfree(spec->kctl_alloc);
3566 }
3567 spec->kctl_alloc = knew;
3568 spec->num_kctl_alloc = num;
3569 }
3570
3571 knew = &spec->kctl_alloc[spec->num_kctl_used];
3572 *knew = alc880_control_templates[type]; 3930 *knew = alc880_control_templates[type];
3573 knew->name = kstrdup(name, GFP_KERNEL); 3931 knew->name = kstrdup(name, GFP_KERNEL);
3574 if (!knew->name) 3932 if (!knew->name)
3575 return -ENOMEM; 3933 return -ENOMEM;
3576 knew->private_value = val; 3934 knew->private_value = val;
3577 spec->num_kctl_used++;
3578 return 0; 3935 return 0;
3579} 3936}
3580 3937
@@ -3898,10 +4255,10 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
3898 if (spec->autocfg.dig_in_pin) 4255 if (spec->autocfg.dig_in_pin)
3899 spec->dig_in_nid = ALC880_DIGIN_NID; 4256 spec->dig_in_nid = ALC880_DIGIN_NID;
3900 4257
3901 if (spec->kctl_alloc) 4258 if (spec->kctls.list)
3902 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 4259 add_mixer(spec, spec->kctls.list);
3903 4260
3904 spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs; 4261 add_verb(spec, alc880_volume_init_verbs);
3905 4262
3906 spec->num_mux_defs = 1; 4263 spec->num_mux_defs = 1;
3907 spec->input_mux = &spec->private_imux; 4264 spec->input_mux = &spec->private_imux;
@@ -3925,6 +4282,17 @@ static void alc880_auto_init(struct hda_codec *codec)
3925 * OK, here we have finally the patch for ALC880 4282 * OK, here we have finally the patch for ALC880
3926 */ 4283 */
3927 4284
4285static void set_capture_mixer(struct alc_spec *spec)
4286{
4287 static struct snd_kcontrol_new *caps[3] = {
4288 alc_capture_mixer1,
4289 alc_capture_mixer2,
4290 alc_capture_mixer3,
4291 };
4292 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4293 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4294}
4295
3928static int patch_alc880(struct hda_codec *codec) 4296static int patch_alc880(struct hda_codec *codec)
3929{ 4297{
3930 struct alc_spec *spec; 4298 struct alc_spec *spec;
@@ -3980,16 +4348,12 @@ static int patch_alc880(struct hda_codec *codec)
3980 if (wcap != AC_WID_AUD_IN) { 4348 if (wcap != AC_WID_AUD_IN) {
3981 spec->adc_nids = alc880_adc_nids_alt; 4349 spec->adc_nids = alc880_adc_nids_alt;
3982 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt); 4350 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3983 spec->mixers[spec->num_mixers] =
3984 alc880_capture_alt_mixer;
3985 spec->num_mixers++;
3986 } else { 4351 } else {
3987 spec->adc_nids = alc880_adc_nids; 4352 spec->adc_nids = alc880_adc_nids;
3988 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids); 4353 spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3989 spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3990 spec->num_mixers++;
3991 } 4354 }
3992 } 4355 }
4356 set_capture_mixer(spec);
3993 4357
3994 spec->vmaster_nid = 0x0c; 4358 spec->vmaster_nid = 0x0c;
3995 4359
@@ -4000,6 +4364,7 @@ static int patch_alc880(struct hda_codec *codec)
4000 if (!spec->loopback.amplist) 4364 if (!spec->loopback.amplist)
4001 spec->loopback.amplist = alc880_loopbacks; 4365 spec->loopback.amplist = alc880_loopbacks;
4002#endif 4366#endif
4367 codec->proc_widget_hook = print_realtek_coef;
4003 4368
4004 return 0; 4369 return 0;
4005} 4370}
@@ -4024,11 +4389,6 @@ static hda_nid_t alc260_adc_nids_alt[1] = {
4024 0x05, 4389 0x05,
4025}; 4390};
4026 4391
4027static hda_nid_t alc260_hp_adc_nids[2] = {
4028 /* ADC1, 0 */
4029 0x05, 0x04
4030};
4031
4032/* NIDs used when simultaneous access to both ADCs makes sense. Note that 4392/* NIDs used when simultaneous access to both ADCs makes sense. Note that
4033 * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC. 4393 * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4034 */ 4394 */
@@ -4157,13 +4517,13 @@ static void alc260_hp_master_update(struct hda_codec *codec,
4157 struct alc_spec *spec = codec->spec; 4517 struct alc_spec *spec = codec->spec;
4158 unsigned int val = spec->master_sw ? PIN_HP : 0; 4518 unsigned int val = spec->master_sw ? PIN_HP : 0;
4159 /* change HP and line-out pins */ 4519 /* change HP and line-out pins */
4160 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 4520 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4161 val); 4521 val);
4162 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 4522 snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4163 val); 4523 val);
4164 /* mono (speaker) depending on the HP jack sense */ 4524 /* mono (speaker) depending on the HP jack sense */
4165 val = (val && !spec->jack_present) ? PIN_OUT : 0; 4525 val = (val && !spec->jack_present) ? PIN_OUT : 0;
4166 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 4526 snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4167 val); 4527 val);
4168} 4528}
4169 4529
@@ -4242,7 +4602,7 @@ static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4242 .info = snd_ctl_boolean_mono_info, 4602 .info = snd_ctl_boolean_mono_info,
4243 .get = alc260_hp_master_sw_get, 4603 .get = alc260_hp_master_sw_get,
4244 .put = alc260_hp_master_sw_put, 4604 .put = alc260_hp_master_sw_put,
4245 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11 4605 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4246 }, 4606 },
4247 HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT), 4607 HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4248 HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT), 4608 HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
@@ -4295,7 +4655,7 @@ static void alc260_hp_3013_automute(struct hda_codec *codec)
4295 present = snd_hda_codec_read(codec, 0x15, 0, 4655 present = snd_hda_codec_read(codec, 0x15, 0,
4296 AC_VERB_GET_PIN_SENSE, 0); 4656 AC_VERB_GET_PIN_SENSE, 0);
4297 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0; 4657 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4298 alc260_hp_master_update(codec, 0x10, 0x15, 0x11); 4658 alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4299} 4659}
4300 4660
4301static void alc260_hp_3013_unsol_event(struct hda_codec *codec, 4661static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
@@ -4427,45 +4787,6 @@ static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4427 { } /* end */ 4787 { } /* end */
4428}; 4788};
4429 4789
4430/* capture mixer elements */
4431static struct snd_kcontrol_new alc260_capture_mixer[] = {
4432 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4433 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4434 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4435 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4436 {
4437 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4438 /* The multiple "Capture Source" controls confuse alsamixer
4439 * So call somewhat different..
4440 */
4441 /* .name = "Capture Source", */
4442 .name = "Input Source",
4443 .count = 2,
4444 .info = alc_mux_enum_info,
4445 .get = alc_mux_enum_get,
4446 .put = alc_mux_enum_put,
4447 },
4448 { } /* end */
4449};
4450
4451static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4452 HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4453 HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4454 {
4455 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4456 /* The multiple "Capture Source" controls confuse alsamixer
4457 * So call somewhat different..
4458 */
4459 /* .name = "Capture Source", */
4460 .name = "Input Source",
4461 .count = 1,
4462 .info = alc_mux_enum_info,
4463 .get = alc_mux_enum_get,
4464 .put = alc_mux_enum_put,
4465 },
4466 { } /* end */
4467};
4468
4469/* 4790/*
4470 * initialization verbs 4791 * initialization verbs
4471 */ 4792 */
@@ -5282,7 +5603,6 @@ static struct hda_verb alc260_volume_init_verbs[] = {
5282static int alc260_parse_auto_config(struct hda_codec *codec) 5603static int alc260_parse_auto_config(struct hda_codec *codec)
5283{ 5604{
5284 struct alc_spec *spec = codec->spec; 5605 struct alc_spec *spec = codec->spec;
5285 unsigned int wcap;
5286 int err; 5606 int err;
5287 static hda_nid_t alc260_ignore[] = { 0x17, 0 }; 5607 static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5288 5608
@@ -5293,7 +5613,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
5293 err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg); 5613 err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5294 if (err < 0) 5614 if (err < 0)
5295 return err; 5615 return err;
5296 if (!spec->kctl_alloc) 5616 if (!spec->kctls.list)
5297 return 0; /* can't find valid BIOS pin config */ 5617 return 0; /* can't find valid BIOS pin config */
5298 err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg); 5618 err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5299 if (err < 0) 5619 if (err < 0)
@@ -5303,28 +5623,14 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
5303 5623
5304 if (spec->autocfg.dig_out_pin) 5624 if (spec->autocfg.dig_out_pin)
5305 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID; 5625 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5306 if (spec->kctl_alloc) 5626 if (spec->kctls.list)
5307 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 5627 add_mixer(spec, spec->kctls.list);
5308 5628
5309 spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs; 5629 add_verb(spec, alc260_volume_init_verbs);
5310 5630
5311 spec->num_mux_defs = 1; 5631 spec->num_mux_defs = 1;
5312 spec->input_mux = &spec->private_imux; 5632 spec->input_mux = &spec->private_imux;
5313 5633
5314 /* check whether NID 0x04 is valid */
5315 wcap = get_wcaps(codec, 0x04);
5316 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5317 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5318 spec->adc_nids = alc260_adc_nids_alt;
5319 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5320 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5321 } else {
5322 spec->adc_nids = alc260_adc_nids;
5323 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5324 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5325 }
5326 spec->num_mixers++;
5327
5328 store_pin_configs(codec); 5634 store_pin_configs(codec);
5329 return 1; 5635 return 1;
5330} 5636}
@@ -5394,12 +5700,11 @@ static struct alc_config_preset alc260_presets[] = {
5394 [ALC260_BASIC] = { 5700 [ALC260_BASIC] = {
5395 .mixers = { alc260_base_output_mixer, 5701 .mixers = { alc260_base_output_mixer,
5396 alc260_input_mixer, 5702 alc260_input_mixer,
5397 alc260_pc_beep_mixer, 5703 alc260_pc_beep_mixer },
5398 alc260_capture_mixer },
5399 .init_verbs = { alc260_init_verbs }, 5704 .init_verbs = { alc260_init_verbs },
5400 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5705 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5401 .dac_nids = alc260_dac_nids, 5706 .dac_nids = alc260_dac_nids,
5402 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids), 5707 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5403 .adc_nids = alc260_adc_nids, 5708 .adc_nids = alc260_adc_nids,
5404 .num_channel_mode = ARRAY_SIZE(alc260_modes), 5709 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5405 .channel_mode = alc260_modes, 5710 .channel_mode = alc260_modes,
@@ -5407,14 +5712,13 @@ static struct alc_config_preset alc260_presets[] = {
5407 }, 5712 },
5408 [ALC260_HP] = { 5713 [ALC260_HP] = {
5409 .mixers = { alc260_hp_output_mixer, 5714 .mixers = { alc260_hp_output_mixer,
5410 alc260_input_mixer, 5715 alc260_input_mixer },
5411 alc260_capture_alt_mixer },
5412 .init_verbs = { alc260_init_verbs, 5716 .init_verbs = { alc260_init_verbs,
5413 alc260_hp_unsol_verbs }, 5717 alc260_hp_unsol_verbs },
5414 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5718 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5415 .dac_nids = alc260_dac_nids, 5719 .dac_nids = alc260_dac_nids,
5416 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids), 5720 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5417 .adc_nids = alc260_hp_adc_nids, 5721 .adc_nids = alc260_adc_nids_alt,
5418 .num_channel_mode = ARRAY_SIZE(alc260_modes), 5722 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5419 .channel_mode = alc260_modes, 5723 .channel_mode = alc260_modes,
5420 .input_mux = &alc260_capture_source, 5724 .input_mux = &alc260_capture_source,
@@ -5423,14 +5727,13 @@ static struct alc_config_preset alc260_presets[] = {
5423 }, 5727 },
5424 [ALC260_HP_DC7600] = { 5728 [ALC260_HP_DC7600] = {
5425 .mixers = { alc260_hp_dc7600_mixer, 5729 .mixers = { alc260_hp_dc7600_mixer,
5426 alc260_input_mixer, 5730 alc260_input_mixer },
5427 alc260_capture_alt_mixer },
5428 .init_verbs = { alc260_init_verbs, 5731 .init_verbs = { alc260_init_verbs,
5429 alc260_hp_dc7600_verbs }, 5732 alc260_hp_dc7600_verbs },
5430 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5733 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5431 .dac_nids = alc260_dac_nids, 5734 .dac_nids = alc260_dac_nids,
5432 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids), 5735 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5433 .adc_nids = alc260_hp_adc_nids, 5736 .adc_nids = alc260_adc_nids_alt,
5434 .num_channel_mode = ARRAY_SIZE(alc260_modes), 5737 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5435 .channel_mode = alc260_modes, 5738 .channel_mode = alc260_modes,
5436 .input_mux = &alc260_capture_source, 5739 .input_mux = &alc260_capture_source,
@@ -5439,14 +5742,13 @@ static struct alc_config_preset alc260_presets[] = {
5439 }, 5742 },
5440 [ALC260_HP_3013] = { 5743 [ALC260_HP_3013] = {
5441 .mixers = { alc260_hp_3013_mixer, 5744 .mixers = { alc260_hp_3013_mixer,
5442 alc260_input_mixer, 5745 alc260_input_mixer },
5443 alc260_capture_alt_mixer },
5444 .init_verbs = { alc260_hp_3013_init_verbs, 5746 .init_verbs = { alc260_hp_3013_init_verbs,
5445 alc260_hp_3013_unsol_verbs }, 5747 alc260_hp_3013_unsol_verbs },
5446 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5748 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5447 .dac_nids = alc260_dac_nids, 5749 .dac_nids = alc260_dac_nids,
5448 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids), 5750 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5449 .adc_nids = alc260_hp_adc_nids, 5751 .adc_nids = alc260_adc_nids_alt,
5450 .num_channel_mode = ARRAY_SIZE(alc260_modes), 5752 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5451 .channel_mode = alc260_modes, 5753 .channel_mode = alc260_modes,
5452 .input_mux = &alc260_capture_source, 5754 .input_mux = &alc260_capture_source,
@@ -5454,8 +5756,7 @@ static struct alc_config_preset alc260_presets[] = {
5454 .init_hook = alc260_hp_3013_automute, 5756 .init_hook = alc260_hp_3013_automute,
5455 }, 5757 },
5456 [ALC260_FUJITSU_S702X] = { 5758 [ALC260_FUJITSU_S702X] = {
5457 .mixers = { alc260_fujitsu_mixer, 5759 .mixers = { alc260_fujitsu_mixer },
5458 alc260_capture_mixer },
5459 .init_verbs = { alc260_fujitsu_init_verbs }, 5760 .init_verbs = { alc260_fujitsu_init_verbs },
5460 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5761 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5461 .dac_nids = alc260_dac_nids, 5762 .dac_nids = alc260_dac_nids,
@@ -5467,8 +5768,7 @@ static struct alc_config_preset alc260_presets[] = {
5467 .input_mux = alc260_fujitsu_capture_sources, 5768 .input_mux = alc260_fujitsu_capture_sources,
5468 }, 5769 },
5469 [ALC260_ACER] = { 5770 [ALC260_ACER] = {
5470 .mixers = { alc260_acer_mixer, 5771 .mixers = { alc260_acer_mixer },
5471 alc260_capture_mixer },
5472 .init_verbs = { alc260_acer_init_verbs }, 5772 .init_verbs = { alc260_acer_init_verbs },
5473 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5773 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5474 .dac_nids = alc260_dac_nids, 5774 .dac_nids = alc260_dac_nids,
@@ -5480,8 +5780,7 @@ static struct alc_config_preset alc260_presets[] = {
5480 .input_mux = alc260_acer_capture_sources, 5780 .input_mux = alc260_acer_capture_sources,
5481 }, 5781 },
5482 [ALC260_WILL] = { 5782 [ALC260_WILL] = {
5483 .mixers = { alc260_will_mixer, 5783 .mixers = { alc260_will_mixer },
5484 alc260_capture_mixer },
5485 .init_verbs = { alc260_init_verbs, alc260_will_verbs }, 5784 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5486 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5785 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5487 .dac_nids = alc260_dac_nids, 5786 .dac_nids = alc260_dac_nids,
@@ -5493,8 +5792,7 @@ static struct alc_config_preset alc260_presets[] = {
5493 .input_mux = &alc260_capture_source, 5792 .input_mux = &alc260_capture_source,
5494 }, 5793 },
5495 [ALC260_REPLACER_672V] = { 5794 [ALC260_REPLACER_672V] = {
5496 .mixers = { alc260_replacer_672v_mixer, 5795 .mixers = { alc260_replacer_672v_mixer },
5497 alc260_capture_mixer },
5498 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs }, 5796 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5499 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5797 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5500 .dac_nids = alc260_dac_nids, 5798 .dac_nids = alc260_dac_nids,
@@ -5509,8 +5807,7 @@ static struct alc_config_preset alc260_presets[] = {
5509 }, 5807 },
5510#ifdef CONFIG_SND_DEBUG 5808#ifdef CONFIG_SND_DEBUG
5511 [ALC260_TEST] = { 5809 [ALC260_TEST] = {
5512 .mixers = { alc260_test_mixer, 5810 .mixers = { alc260_test_mixer },
5513 alc260_capture_mixer },
5514 .init_verbs = { alc260_test_init_verbs }, 5811 .init_verbs = { alc260_test_init_verbs },
5515 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids), 5812 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5516 .dac_nids = alc260_test_dac_nids, 5813 .dac_nids = alc260_test_dac_nids,
@@ -5569,6 +5866,21 @@ static int patch_alc260(struct hda_codec *codec)
5569 spec->stream_digital_playback = &alc260_pcm_digital_playback; 5866 spec->stream_digital_playback = &alc260_pcm_digital_playback;
5570 spec->stream_digital_capture = &alc260_pcm_digital_capture; 5867 spec->stream_digital_capture = &alc260_pcm_digital_capture;
5571 5868
5869 if (!spec->adc_nids && spec->input_mux) {
5870 /* check whether NID 0x04 is valid */
5871 unsigned int wcap = get_wcaps(codec, 0x04);
5872 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5873 /* get type */
5874 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5875 spec->adc_nids = alc260_adc_nids_alt;
5876 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5877 } else {
5878 spec->adc_nids = alc260_adc_nids;
5879 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5880 }
5881 }
5882 set_capture_mixer(spec);
5883
5572 spec->vmaster_nid = 0x08; 5884 spec->vmaster_nid = 0x08;
5573 5885
5574 codec->patch_ops = alc_patch_ops; 5886 codec->patch_ops = alc_patch_ops;
@@ -5578,6 +5890,7 @@ static int patch_alc260(struct hda_codec *codec)
5578 if (!spec->loopback.amplist) 5890 if (!spec->loopback.amplist)
5579 spec->loopback.amplist = alc260_loopbacks; 5891 spec->loopback.amplist = alc260_loopbacks;
5580#endif 5892#endif
5893 codec->proc_widget_hook = print_realtek_coef;
5581 5894
5582 return 0; 5895 return 0;
5583} 5896}
@@ -5625,36 +5938,6 @@ static struct hda_input_mux alc882_capture_source = {
5625 { "CD", 0x4 }, 5938 { "CD", 0x4 },
5626 }, 5939 },
5627}; 5940};
5628#define alc882_mux_enum_info alc_mux_enum_info
5629#define alc882_mux_enum_get alc_mux_enum_get
5630
5631static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5632 struct snd_ctl_elem_value *ucontrol)
5633{
5634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5635 struct alc_spec *spec = codec->spec;
5636 const struct hda_input_mux *imux = spec->input_mux;
5637 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5638 hda_nid_t nid = spec->capsrc_nids ?
5639 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5640 unsigned int *cur_val = &spec->cur_mux[adc_idx];
5641 unsigned int i, idx;
5642
5643 idx = ucontrol->value.enumerated.item[0];
5644 if (idx >= imux->num_items)
5645 idx = imux->num_items - 1;
5646 if (*cur_val == idx)
5647 return 0;
5648 for (i = 0; i < imux->num_items; i++) {
5649 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5650 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5651 imux->items[i].index,
5652 HDA_AMP_MUTE, v);
5653 }
5654 *cur_val = idx;
5655 return 1;
5656}
5657
5658/* 5941/*
5659 * 2ch mode 5942 * 2ch mode
5660 */ 5943 */
@@ -6337,49 +6620,6 @@ static struct hda_verb alc882_auto_init_verbs[] = {
6337 { } 6620 { }
6338}; 6621};
6339 6622
6340/* capture mixer elements */
6341static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6342 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6343 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6344 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6345 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6346 {
6347 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6348 /* The multiple "Capture Source" controls confuse alsamixer
6349 * So call somewhat different..
6350 */
6351 /* .name = "Capture Source", */
6352 .name = "Input Source",
6353 .count = 2,
6354 .info = alc882_mux_enum_info,
6355 .get = alc882_mux_enum_get,
6356 .put = alc882_mux_enum_put,
6357 },
6358 { } /* end */
6359};
6360
6361static struct snd_kcontrol_new alc882_capture_mixer[] = {
6362 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6363 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6364 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6365 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6366 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6367 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6368 {
6369 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6370 /* The multiple "Capture Source" controls confuse alsamixer
6371 * So call somewhat different..
6372 */
6373 /* .name = "Capture Source", */
6374 .name = "Input Source",
6375 .count = 3,
6376 .info = alc882_mux_enum_info,
6377 .get = alc882_mux_enum_get,
6378 .put = alc882_mux_enum_put,
6379 },
6380 { } /* end */
6381};
6382
6383#ifdef CONFIG_SND_HDA_POWER_SAVE 6623#ifdef CONFIG_SND_HDA_POWER_SAVE
6384#define alc882_loopbacks alc880_loopbacks 6624#define alc882_loopbacks alc880_loopbacks
6385#endif 6625#endif
@@ -6508,8 +6748,7 @@ static struct alc_config_preset alc882_presets[] = {
6508 .init_hook = alc885_imac24_init_hook, 6748 .init_hook = alc885_imac24_init_hook,
6509 }, 6749 },
6510 [ALC882_TARGA] = { 6750 [ALC882_TARGA] = {
6511 .mixers = { alc882_targa_mixer, alc882_chmode_mixer, 6751 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6512 alc882_capture_mixer },
6513 .init_verbs = { alc882_init_verbs, alc882_targa_verbs}, 6752 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6514 .num_dacs = ARRAY_SIZE(alc882_dac_nids), 6753 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6515 .dac_nids = alc882_dac_nids, 6754 .dac_nids = alc882_dac_nids,
@@ -6525,8 +6764,7 @@ static struct alc_config_preset alc882_presets[] = {
6525 .init_hook = alc882_targa_automute, 6764 .init_hook = alc882_targa_automute,
6526 }, 6765 },
6527 [ALC882_ASUS_A7J] = { 6766 [ALC882_ASUS_A7J] = {
6528 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer, 6767 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6529 alc882_capture_mixer },
6530 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs}, 6768 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6531 .num_dacs = ARRAY_SIZE(alc882_dac_nids), 6769 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6532 .dac_nids = alc882_dac_nids, 6770 .dac_nids = alc882_dac_nids,
@@ -6831,6 +7069,7 @@ static int patch_alc882(struct hda_codec *codec)
6831 spec->stream_digital_playback = &alc882_pcm_digital_playback; 7069 spec->stream_digital_playback = &alc882_pcm_digital_playback;
6832 spec->stream_digital_capture = &alc882_pcm_digital_capture; 7070 spec->stream_digital_capture = &alc882_pcm_digital_capture;
6833 7071
7072 spec->is_mix_capture = 1; /* matrix-style capture */
6834 if (!spec->adc_nids && spec->input_mux) { 7073 if (!spec->adc_nids && spec->input_mux) {
6835 /* check whether NID 0x07 is valid */ 7074 /* check whether NID 0x07 is valid */
6836 unsigned int wcap = get_wcaps(codec, 0x07); 7075 unsigned int wcap = get_wcaps(codec, 0x07);
@@ -6840,17 +7079,13 @@ static int patch_alc882(struct hda_codec *codec)
6840 spec->adc_nids = alc882_adc_nids_alt; 7079 spec->adc_nids = alc882_adc_nids_alt;
6841 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt); 7080 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6842 spec->capsrc_nids = alc882_capsrc_nids_alt; 7081 spec->capsrc_nids = alc882_capsrc_nids_alt;
6843 spec->mixers[spec->num_mixers] =
6844 alc882_capture_alt_mixer;
6845 spec->num_mixers++;
6846 } else { 7082 } else {
6847 spec->adc_nids = alc882_adc_nids; 7083 spec->adc_nids = alc882_adc_nids;
6848 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids); 7084 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6849 spec->capsrc_nids = alc882_capsrc_nids; 7085 spec->capsrc_nids = alc882_capsrc_nids;
6850 spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6851 spec->num_mixers++;
6852 } 7086 }
6853 } 7087 }
7088 set_capture_mixer(spec);
6854 7089
6855 spec->vmaster_nid = 0x0c; 7090 spec->vmaster_nid = 0x0c;
6856 7091
@@ -6861,6 +7096,7 @@ static int patch_alc882(struct hda_codec *codec)
6861 if (!spec->loopback.amplist) 7096 if (!spec->loopback.amplist)
6862 spec->loopback.amplist = alc882_loopbacks; 7097 spec->loopback.amplist = alc882_loopbacks;
6863#endif 7098#endif
7099 codec->proc_widget_hook = print_realtek_coef;
6864 7100
6865 return 0; 7101 return 0;
6866} 7102}
@@ -6879,6 +7115,8 @@ static int patch_alc882(struct hda_codec *codec)
6879#define ALC883_DIGOUT_NID 0x06 7115#define ALC883_DIGOUT_NID 0x06
6880#define ALC883_DIGIN_NID 0x0a 7116#define ALC883_DIGIN_NID 0x0a
6881 7117
7118#define ALC1200_DIGOUT_NID 0x10
7119
6882static hda_nid_t alc883_dac_nids[4] = { 7120static hda_nid_t alc883_dac_nids[4] = {
6883 /* front, rear, clfe, rear_surr */ 7121 /* front, rear, clfe, rear_surr */
6884 0x02, 0x03, 0x04, 0x05 7122 0x02, 0x03, 0x04, 0x05
@@ -6889,8 +7127,20 @@ static hda_nid_t alc883_adc_nids[2] = {
6889 0x08, 0x09, 7127 0x08, 0x09,
6890}; 7128};
6891 7129
7130static hda_nid_t alc883_adc_nids_alt[1] = {
7131 /* ADC1 */
7132 0x08,
7133};
7134
7135static hda_nid_t alc883_adc_nids_rev[2] = {
7136 /* ADC2-1 */
7137 0x09, 0x08
7138};
7139
6892static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 }; 7140static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6893 7141
7142static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7143
6894/* input MUX */ 7144/* input MUX */
6895/* FIXME: should be a matrix-type input source selection */ 7145/* FIXME: should be a matrix-type input source selection */
6896 7146
@@ -6957,11 +7207,6 @@ static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6957 }, 7207 },
6958}; 7208};
6959 7209
6960#define alc883_mux_enum_info alc_mux_enum_info
6961#define alc883_mux_enum_get alc_mux_enum_get
6962/* ALC883 has the ALC882-type input selection */
6963#define alc883_mux_enum_put alc882_mux_enum_put
6964
6965/* 7210/*
6966 * 2ch mode 7211 * 2ch mode
6967 */ 7212 */
@@ -7115,19 +7360,6 @@ static struct snd_kcontrol_new alc883_base_mixer[] = {
7115 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7360 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7116 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT), 7361 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7117 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT), 7362 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7118 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7119 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7120 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7121 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7122 {
7123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7124 /* .name = "Capture Source", */
7125 .name = "Input Source",
7126 .count = 2,
7127 .info = alc883_mux_enum_info,
7128 .get = alc883_mux_enum_get,
7129 .put = alc883_mux_enum_put,
7130 },
7131 { } /* end */ 7363 { } /* end */
7132}; 7364};
7133 7365
@@ -7145,19 +7377,6 @@ static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7145 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7377 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7146 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 7378 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7147 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7379 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7148 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7149 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7150 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7151 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7152 {
7153 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7154 /* .name = "Capture Source", */
7155 .name = "Input Source",
7156 .count = 2,
7157 .info = alc883_mux_enum_info,
7158 .get = alc883_mux_enum_get,
7159 .put = alc883_mux_enum_put,
7160 },
7161 { } /* end */ 7380 { } /* end */
7162}; 7381};
7163 7382
@@ -7172,19 +7391,6 @@ static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7172 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7391 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7173 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 7392 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7174 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7393 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7175 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7176 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7177 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7178 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7179 {
7180 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7181 /* .name = "Capture Source", */
7182 .name = "Input Source",
7183 .count = 2,
7184 .info = alc883_mux_enum_info,
7185 .get = alc883_mux_enum_get,
7186 .put = alc883_mux_enum_put,
7187 },
7188 { } /* end */ 7394 { } /* end */
7189}; 7395};
7190 7396
@@ -7199,19 +7405,6 @@ static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7199 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7405 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7200 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 7406 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7201 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7407 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7202 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7203 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7204 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7205 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7206 {
7207 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7208 /* .name = "Capture Source", */
7209 .name = "Input Source",
7210 .count = 2,
7211 .info = alc883_mux_enum_info,
7212 .get = alc883_mux_enum_get,
7213 .put = alc883_mux_enum_put,
7214 },
7215 { } /* end */ 7408 { } /* end */
7216}; 7409};
7217 7410
@@ -7231,19 +7424,6 @@ static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7231 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7424 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7232 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT), 7425 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7233 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT), 7426 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7234 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7235 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7236 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7237 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7238 {
7239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7240 /* .name = "Capture Source", */
7241 .name = "Input Source",
7242 .count = 2,
7243 .info = alc883_mux_enum_info,
7244 .get = alc883_mux_enum_get,
7245 .put = alc883_mux_enum_put,
7246 },
7247 { } /* end */ 7427 { } /* end */
7248}; 7428};
7249 7429
@@ -7269,17 +7449,6 @@ static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7269 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7449 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7270 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT), 7450 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7271 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT), 7451 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7272 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7273 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7274 {
7275 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7276 /* .name = "Capture Source", */
7277 .name = "Input Source",
7278 .count = 1,
7279 .info = alc883_mux_enum_info,
7280 .get = alc883_mux_enum_get,
7281 .put = alc883_mux_enum_put,
7282 },
7283 { } /* end */ 7452 { } /* end */
7284}; 7453};
7285 7454
@@ -7306,19 +7475,6 @@ static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7306 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 7475 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7307 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT), 7476 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7308 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT), 7477 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7309 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7310 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7311 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7312 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7313 {
7314 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7315 /* .name = "Capture Source", */
7316 .name = "Input Source",
7317 .count = 2,
7318 .info = alc883_mux_enum_info,
7319 .get = alc883_mux_enum_get,
7320 .put = alc883_mux_enum_put,
7321 },
7322 { } /* end */ 7478 { } /* end */
7323}; 7479};
7324 7480
@@ -7344,18 +7500,6 @@ static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7344 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7500 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7345 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT), 7501 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7346 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT), 7502 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7347 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7348 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7349
7350 {
7351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7352 /* .name = "Capture Source", */
7353 .name = "Input Source",
7354 .count = 1,
7355 .info = alc883_mux_enum_info,
7356 .get = alc883_mux_enum_get,
7357 .put = alc883_mux_enum_put,
7358 },
7359 { } /* end */ 7503 { } /* end */
7360}; 7504};
7361 7505
@@ -7376,19 +7520,6 @@ static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7376 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 7520 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7377 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 7521 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7378 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 7522 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7379 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7380 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7381 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7382 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7383 {
7384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7385 /* .name = "Capture Source", */
7386 .name = "Input Source",
7387 .count = 2,
7388 .info = alc883_mux_enum_info,
7389 .get = alc883_mux_enum_get,
7390 .put = alc883_mux_enum_put,
7391 },
7392 { } /* end */ 7523 { } /* end */
7393}; 7524};
7394 7525
@@ -7404,19 +7535,6 @@ static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7404 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7535 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7405 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 7536 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7406 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7537 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7407 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7408 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7409 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7410 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7411 {
7412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7413 /* .name = "Capture Source", */
7414 .name = "Input Source",
7415 .count = 2,
7416 .info = alc883_mux_enum_info,
7417 .get = alc883_mux_enum_get,
7418 .put = alc883_mux_enum_put,
7419 },
7420 { } /* end */ 7538 { } /* end */
7421}; 7539};
7422 7540
@@ -7429,17 +7547,6 @@ static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7429 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7547 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7430 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 7548 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7431 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7549 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7432 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7433 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7434 {
7435 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7436 /* .name = "Capture Source", */
7437 .name = "Input Source",
7438 .count = 1,
7439 .info = alc883_mux_enum_info,
7440 .get = alc883_mux_enum_get,
7441 .put = alc883_mux_enum_put,
7442 },
7443 { } /* end */ 7550 { } /* end */
7444}; 7551};
7445 7552
@@ -7453,19 +7560,6 @@ static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7453 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 7560 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7454 HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7561 HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7455 HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7562 HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7456 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7457 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7458 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7459 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7460 {
7461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7462 /* .name = "Capture Source", */
7463 .name = "Input Source",
7464 .count = 2,
7465 .info = alc883_mux_enum_info,
7466 .get = alc883_mux_enum_get,
7467 .put = alc883_mux_enum_put,
7468 },
7469 { } /* end */ 7563 { } /* end */
7470}; 7564};
7471 7565
@@ -7479,19 +7573,6 @@ static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7479 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 7573 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7480 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 7574 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7481 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 7575 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7482 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7483 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7484 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7485 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7486 {
7487 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7488 /* .name = "Capture Source", */
7489 .name = "Input Source",
7490 .count = 2,
7491 .info = alc883_mux_enum_info,
7492 .get = alc883_mux_enum_get,
7493 .put = alc883_mux_enum_put,
7494 },
7495 { } /* end */ 7576 { } /* end */
7496}; 7577};
7497 7578
@@ -7504,19 +7585,6 @@ static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7504 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 7585 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7505 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 7586 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7506 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 7587 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7507 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7508 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7509 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7510 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7511 {
7512 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7513 /* .name = "Capture Source", */
7514 .name = "Input Source",
7515 .count = 2,
7516 .info = alc883_mux_enum_info,
7517 .get = alc883_mux_enum_get,
7518 .put = alc883_mux_enum_put,
7519 },
7520 { } /* end */ 7588 { } /* end */
7521}; 7589};
7522 7590
@@ -7544,19 +7612,6 @@ static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7544 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7612 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7545 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 7613 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7546 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7614 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7547 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7548 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7549 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7550 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7551 {
7552 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7553 /* .name = "Capture Source", */
7554 .name = "Input Source",
7555 .count = 2,
7556 .info = alc883_mux_enum_info,
7557 .get = alc883_mux_enum_get,
7558 .put = alc883_mux_enum_put,
7559 },
7560 { } /* end */ 7615 { } /* end */
7561}; 7616};
7562 7617
@@ -7587,6 +7642,10 @@ static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7587 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 7642 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7588 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 7643 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7589 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 7644 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7645 { } /* end */
7646};
7647
7648static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7590 HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol), 7649 HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7591 HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch), 7650 HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7592 { 7651 {
@@ -7594,9 +7653,9 @@ static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7594 /* .name = "Capture Source", */ 7653 /* .name = "Capture Source", */
7595 .name = "Input Source", 7654 .name = "Input Source",
7596 .count = 1, 7655 .count = 1,
7597 .info = alc883_mux_enum_info, 7656 .info = alc_mux_enum_info,
7598 .get = alc883_mux_enum_get, 7657 .get = alc_mux_enum_get,
7599 .put = alc883_mux_enum_put, 7658 .put = alc_mux_enum_put,
7600 }, 7659 },
7601 { } /* end */ 7660 { } /* end */
7602}; 7661};
@@ -8251,27 +8310,6 @@ static struct hda_verb alc883_auto_init_verbs[] = {
8251 { } 8310 { }
8252}; 8311};
8253 8312
8254/* capture mixer elements */
8255static struct snd_kcontrol_new alc883_capture_mixer[] = {
8256 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8257 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8258 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
8259 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
8260 {
8261 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8262 /* The multiple "Capture Source" controls confuse alsamixer
8263 * So call somewhat different..
8264 */
8265 /* .name = "Capture Source", */
8266 .name = "Input Source",
8267 .count = 2,
8268 .info = alc882_mux_enum_info,
8269 .get = alc882_mux_enum_get,
8270 .put = alc882_mux_enum_put,
8271 },
8272 { } /* end */
8273};
8274
8275static struct hda_verb alc888_asus_m90v_verbs[] = { 8313static struct hda_verb alc888_asus_m90v_verbs[] = {
8276 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8314 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8277 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8315 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
@@ -8394,6 +8432,7 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
8394 [ALC883_TARGA_2ch_DIG] = "targa-2ch-dig", 8432 [ALC883_TARGA_2ch_DIG] = "targa-2ch-dig",
8395 [ALC883_ACER] = "acer", 8433 [ALC883_ACER] = "acer",
8396 [ALC883_ACER_ASPIRE] = "acer-aspire", 8434 [ALC883_ACER_ASPIRE] = "acer-aspire",
8435 [ALC888_ACER_ASPIRE_4930G] = "acer-aspire-4930g",
8397 [ALC883_MEDION] = "medion", 8436 [ALC883_MEDION] = "medion",
8398 [ALC883_MEDION_MD2] = "medion-md2", 8437 [ALC883_MEDION_MD2] = "medion-md2",
8399 [ALC883_LAPTOP_EAPD] = "laptop-eapd", 8438 [ALC883_LAPTOP_EAPD] = "laptop-eapd",
@@ -8407,7 +8446,9 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
8407 [ALC883_MITAC] = "mitac", 8446 [ALC883_MITAC] = "mitac",
8408 [ALC883_CLEVO_M720] = "clevo-m720", 8447 [ALC883_CLEVO_M720] = "clevo-m720",
8409 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515", 8448 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8449 [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8410 [ALC883_3ST_6ch_INTEL] = "3stack-6ch-intel", 8450 [ALC883_3ST_6ch_INTEL] = "3stack-6ch-intel",
8451 [ALC1200_ASUS_P5Q] = "asus-p5q",
8411 [ALC883_AUTO] = "auto", 8452 [ALC883_AUTO] = "auto",
8412}; 8453};
8413 8454
@@ -8418,6 +8459,8 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8418 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE), 8459 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8419 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE), 8460 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8420 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE), 8461 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8462 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8463 ALC888_ACER_ASPIRE_4930G),
8421 SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */ 8464 SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8422 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL), 8465 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8423 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), 8466 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
@@ -8426,6 +8469,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8426 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG), 8469 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8427 SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V), 8470 SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8428 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG), 8471 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8472 SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8429 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601), 8473 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8430 SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG), 8474 SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8431 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG), 8475 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
@@ -8452,6 +8496,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8452 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG), 8496 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8453 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG), 8497 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8454 SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG), 8498 SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8499 SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8455 SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG), 8500 SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8456 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG), 8501 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8457 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG), 8502 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
@@ -8463,6 +8508,8 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8463 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch), 8508 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8464 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION), 8509 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8465 SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515), 8510 SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8511 SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8512 ALC888_FUJITSU_XA3530),
8466 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch), 8513 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8467 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763), 8514 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8468 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763), 8515 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
@@ -8553,6 +8600,8 @@ static struct alc_config_preset alc883_presets[] = {
8553 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs}, 8600 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8554 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 8601 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8555 .dac_nids = alc883_dac_nids, 8602 .dac_nids = alc883_dac_nids,
8603 .adc_nids = alc883_adc_nids_alt,
8604 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8556 .dig_out_nid = ALC883_DIGOUT_NID, 8605 .dig_out_nid = ALC883_DIGOUT_NID,
8557 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 8606 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8558 .channel_mode = alc883_3ST_2ch_modes, 8607 .channel_mode = alc883_3ST_2ch_modes,
@@ -8586,6 +8635,26 @@ static struct alc_config_preset alc883_presets[] = {
8586 .unsol_event = alc883_acer_aspire_unsol_event, 8635 .unsol_event = alc883_acer_aspire_unsol_event,
8587 .init_hook = alc883_acer_aspire_automute, 8636 .init_hook = alc883_acer_aspire_automute,
8588 }, 8637 },
8638 [ALC888_ACER_ASPIRE_4930G] = {
8639 .mixers = { alc888_base_mixer,
8640 alc883_chmode_mixer },
8641 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8642 alc888_acer_aspire_4930g_verbs },
8643 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8644 .dac_nids = alc883_dac_nids,
8645 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8646 .adc_nids = alc883_adc_nids_rev,
8647 .capsrc_nids = alc883_capsrc_nids_rev,
8648 .dig_out_nid = ALC883_DIGOUT_NID,
8649 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8650 .channel_mode = alc883_3ST_6ch_modes,
8651 .need_dac_fix = 1,
8652 .num_mux_defs =
8653 ARRAY_SIZE(alc888_2_capture_sources),
8654 .input_mux = alc888_2_capture_sources,
8655 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8656 .init_hook = alc888_acer_aspire_4930g_automute,
8657 },
8589 [ALC883_MEDION] = { 8658 [ALC883_MEDION] = {
8590 .mixers = { alc883_fivestack_mixer, 8659 .mixers = { alc883_fivestack_mixer,
8591 alc883_chmode_mixer }, 8660 alc883_chmode_mixer },
@@ -8593,6 +8662,8 @@ static struct alc_config_preset alc883_presets[] = {
8593 alc883_medion_eapd_verbs }, 8662 alc883_medion_eapd_verbs },
8594 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 8663 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8595 .dac_nids = alc883_dac_nids, 8664 .dac_nids = alc883_dac_nids,
8665 .adc_nids = alc883_adc_nids_alt,
8666 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8596 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 8667 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8597 .channel_mode = alc883_sixstack_modes, 8668 .channel_mode = alc883_sixstack_modes,
8598 .input_mux = &alc883_capture_source, 8669 .input_mux = &alc883_capture_source,
@@ -8635,6 +8706,8 @@ static struct alc_config_preset alc883_presets[] = {
8635 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs}, 8706 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8636 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 8707 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8637 .dac_nids = alc883_dac_nids, 8708 .dac_nids = alc883_dac_nids,
8709 .adc_nids = alc883_adc_nids_alt,
8710 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8638 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 8711 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8639 .channel_mode = alc883_3ST_2ch_modes, 8712 .channel_mode = alc883_3ST_2ch_modes,
8640 .input_mux = &alc883_lenovo_101e_capture_source, 8713 .input_mux = &alc883_lenovo_101e_capture_source,
@@ -8725,14 +8798,30 @@ static struct alc_config_preset alc883_presets[] = {
8725 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event, 8798 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8726 .init_hook = alc883_2ch_fujitsu_pi2515_automute, 8799 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8727 }, 8800 },
8801 [ALC888_FUJITSU_XA3530] = {
8802 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8803 .init_verbs = { alc883_init_verbs,
8804 alc888_fujitsu_xa3530_verbs },
8805 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8806 .dac_nids = alc883_dac_nids,
8807 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8808 .adc_nids = alc883_adc_nids_rev,
8809 .capsrc_nids = alc883_capsrc_nids_rev,
8810 .dig_out_nid = ALC883_DIGOUT_NID,
8811 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8812 .channel_mode = alc888_4ST_8ch_intel_modes,
8813 .num_mux_defs =
8814 ARRAY_SIZE(alc888_2_capture_sources),
8815 .input_mux = alc888_2_capture_sources,
8816 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8817 .init_hook = alc888_fujitsu_xa3530_automute,
8818 },
8728 [ALC888_LENOVO_SKY] = { 8819 [ALC888_LENOVO_SKY] = {
8729 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer }, 8820 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8730 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs}, 8821 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8731 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 8822 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8732 .dac_nids = alc883_dac_nids, 8823 .dac_nids = alc883_dac_nids,
8733 .dig_out_nid = ALC883_DIGOUT_NID, 8824 .dig_out_nid = ALC883_DIGOUT_NID,
8734 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
8735 .adc_nids = alc883_adc_nids,
8736 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 8825 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8737 .channel_mode = alc883_sixstack_modes, 8826 .channel_mode = alc883_sixstack_modes,
8738 .need_dac_fix = 1, 8827 .need_dac_fix = 1,
@@ -8756,6 +8845,7 @@ static struct alc_config_preset alc883_presets[] = {
8756 }, 8845 },
8757 [ALC888_ASUS_EEE1601] = { 8846 [ALC888_ASUS_EEE1601] = {
8758 .mixers = { alc883_asus_eee1601_mixer }, 8847 .mixers = { alc883_asus_eee1601_mixer },
8848 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8759 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs }, 8849 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8760 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 8850 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8761 .dac_nids = alc883_dac_nids, 8851 .dac_nids = alc883_dac_nids,
@@ -8768,6 +8858,17 @@ static struct alc_config_preset alc883_presets[] = {
8768 .unsol_event = alc883_eee1601_unsol_event, 8858 .unsol_event = alc883_eee1601_unsol_event,
8769 .init_hook = alc883_eee1601_inithook, 8859 .init_hook = alc883_eee1601_inithook,
8770 }, 8860 },
8861 [ALC1200_ASUS_P5Q] = {
8862 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8863 .init_verbs = { alc883_init_verbs },
8864 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8865 .dac_nids = alc883_dac_nids,
8866 .dig_out_nid = ALC1200_DIGOUT_NID,
8867 .dig_in_nid = ALC883_DIGIN_NID,
8868 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8869 .channel_mode = alc883_sixstack_modes,
8870 .input_mux = &alc883_capture_source,
8871 },
8771}; 8872};
8772 8873
8773 8874
@@ -8862,8 +8963,6 @@ static int alc883_parse_auto_config(struct hda_codec *codec)
8862 8963
8863 /* hack - override the init verbs */ 8964 /* hack - override the init verbs */
8864 spec->init_verbs[0] = alc883_auto_init_verbs; 8965 spec->init_verbs[0] = alc883_auto_init_verbs;
8865 spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8866 spec->num_mixers++;
8867 8966
8868 return 1; /* config found */ 8967 return 1; /* config found */
8869} 8968}
@@ -8946,9 +9045,15 @@ static int patch_alc883(struct hda_codec *codec)
8946 spec->stream_digital_playback = &alc883_pcm_digital_playback; 9045 spec->stream_digital_playback = &alc883_pcm_digital_playback;
8947 spec->stream_digital_capture = &alc883_pcm_digital_capture; 9046 spec->stream_digital_capture = &alc883_pcm_digital_capture;
8948 9047
8949 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids); 9048 if (!spec->num_adc_nids) {
8950 spec->adc_nids = alc883_adc_nids; 9049 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8951 spec->capsrc_nids = alc883_capsrc_nids; 9050 spec->adc_nids = alc883_adc_nids;
9051 }
9052 if (!spec->capsrc_nids)
9053 spec->capsrc_nids = alc883_capsrc_nids;
9054 spec->is_mix_capture = 1; /* matrix-style capture */
9055 if (!spec->cap_mixer)
9056 set_capture_mixer(spec);
8952 9057
8953 spec->vmaster_nid = 0x0c; 9058 spec->vmaster_nid = 0x0c;
8954 9059
@@ -8960,6 +9065,7 @@ static int patch_alc883(struct hda_codec *codec)
8960 if (!spec->loopback.amplist) 9065 if (!spec->loopback.amplist)
8961 spec->loopback.amplist = alc883_loopbacks; 9066 spec->loopback.amplist = alc883_loopbacks;
8962#endif 9067#endif
9068 codec->proc_widget_hook = print_realtek_coef;
8963 9069
8964 return 0; 9070 return 0;
8965} 9071}
@@ -9439,20 +9545,6 @@ static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9439 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 9545 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9440 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 9546 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9441 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 9547 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9442 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9443 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9444 {
9445 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9446 /* The multiple "Capture Source" controls confuse alsamixer
9447 * So call somewhat different..
9448 */
9449 /* .name = "Capture Source", */
9450 .name = "Input Source",
9451 .count = 1,
9452 .info = alc_mux_enum_info,
9453 .get = alc_mux_enum_get,
9454 .put = alc_mux_enum_put,
9455 },
9456 { } /* end */ 9548 { } /* end */
9457}; 9549};
9458 9550
@@ -9969,7 +10061,7 @@ static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9969 struct alc_spec *spec = codec->spec; 10061 struct alc_spec *spec = codec->spec;
9970 int ret; 10062 int ret;
9971 10063
9972 ret = alc882_mux_enum_put(kcontrol, ucontrol); 10064 ret = alc_mux_enum_put(kcontrol, ucontrol);
9973 if (!ret) 10065 if (!ret)
9974 return 0; 10066 return 0;
9975 /* reprogram the HP pin as mic or HP according to the input source */ 10067 /* reprogram the HP pin as mic or HP according to the input source */
@@ -9986,8 +10078,8 @@ static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9986 { 10078 {
9987 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 10079 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9988 .name = "Capture Source", 10080 .name = "Capture Source",
9989 .info = alc882_mux_enum_info, 10081 .info = alc_mux_enum_info,
9990 .get = alc882_mux_enum_get, 10082 .get = alc_mux_enum_get,
9991 .put = alc262_ultra_mux_enum_put, 10083 .put = alc262_ultra_mux_enum_put,
9992 }, 10084 },
9993 { } /* end */ 10085 { } /* end */
@@ -10380,10 +10472,10 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
10380 if (spec->autocfg.dig_in_pin) 10472 if (spec->autocfg.dig_in_pin)
10381 spec->dig_in_nid = ALC262_DIGIN_NID; 10473 spec->dig_in_nid = ALC262_DIGIN_NID;
10382 10474
10383 if (spec->kctl_alloc) 10475 if (spec->kctls.list)
10384 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 10476 add_mixer(spec, spec->kctls.list);
10385 10477
10386 spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs; 10478 add_verb(spec, alc262_volume_init_verbs);
10387 spec->num_mux_defs = 1; 10479 spec->num_mux_defs = 1;
10388 spec->input_mux = &spec->private_imux; 10480 spec->input_mux = &spec->private_imux;
10389 10481
@@ -10466,6 +10558,8 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
10466 SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD), 10558 SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10467 SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD), 10559 SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10468 SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD), 10560 SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10561 SND_PCI_QUIRK(0x104d, 0x9033, "Sony VAIO VGN-SR19XN",
10562 ALC262_SONY_ASSAMD),
10469 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", 10563 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10470 ALC262_TOSHIBA_RX1), 10564 ALC262_TOSHIBA_RX1),
10471 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06), 10565 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
@@ -10624,7 +10718,8 @@ static struct alc_config_preset alc262_presets[] = {
10624 .init_hook = alc262_hippo_automute, 10718 .init_hook = alc262_hippo_automute,
10625 }, 10719 },
10626 [ALC262_ULTRA] = { 10720 [ALC262_ULTRA] = {
10627 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer }, 10721 .mixers = { alc262_ultra_mixer },
10722 .cap_mixer = alc262_ultra_capture_mixer,
10628 .init_verbs = { alc262_ultra_verbs }, 10723 .init_verbs = { alc262_ultra_verbs },
10629 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 10724 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10630 .dac_nids = alc262_dac_nids, 10725 .dac_nids = alc262_dac_nids,
@@ -10750,6 +10845,7 @@ static int patch_alc262(struct hda_codec *codec)
10750 spec->stream_digital_playback = &alc262_pcm_digital_playback; 10845 spec->stream_digital_playback = &alc262_pcm_digital_playback;
10751 spec->stream_digital_capture = &alc262_pcm_digital_capture; 10846 spec->stream_digital_capture = &alc262_pcm_digital_capture;
10752 10847
10848 spec->is_mix_capture = 1;
10753 if (!spec->adc_nids && spec->input_mux) { 10849 if (!spec->adc_nids && spec->input_mux) {
10754 /* check whether NID 0x07 is valid */ 10850 /* check whether NID 0x07 is valid */
10755 unsigned int wcap = get_wcaps(codec, 0x07); 10851 unsigned int wcap = get_wcaps(codec, 0x07);
@@ -10760,17 +10856,14 @@ static int patch_alc262(struct hda_codec *codec)
10760 spec->adc_nids = alc262_adc_nids_alt; 10856 spec->adc_nids = alc262_adc_nids_alt;
10761 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt); 10857 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10762 spec->capsrc_nids = alc262_capsrc_nids_alt; 10858 spec->capsrc_nids = alc262_capsrc_nids_alt;
10763 spec->mixers[spec->num_mixers] =
10764 alc262_capture_alt_mixer;
10765 spec->num_mixers++;
10766 } else { 10859 } else {
10767 spec->adc_nids = alc262_adc_nids; 10860 spec->adc_nids = alc262_adc_nids;
10768 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids); 10861 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10769 spec->capsrc_nids = alc262_capsrc_nids; 10862 spec->capsrc_nids = alc262_capsrc_nids;
10770 spec->mixers[spec->num_mixers] = alc262_capture_mixer;
10771 spec->num_mixers++;
10772 } 10863 }
10773 } 10864 }
10865 if (!spec->cap_mixer)
10866 set_capture_mixer(spec);
10774 10867
10775 spec->vmaster_nid = 0x0c; 10868 spec->vmaster_nid = 0x0c;
10776 10869
@@ -10781,6 +10874,7 @@ static int patch_alc262(struct hda_codec *codec)
10781 if (!spec->loopback.amplist) 10874 if (!spec->loopback.amplist)
10782 spec->loopback.amplist = alc262_loopbacks; 10875 spec->loopback.amplist = alc262_loopbacks;
10783#endif 10876#endif
10877 codec->proc_widget_hook = print_realtek_coef;
10784 10878
10785 return 0; 10879 return 0;
10786} 10880}
@@ -10942,6 +11036,22 @@ static struct snd_kcontrol_new alc268_acer_mixer[] = {
10942 { } 11036 { }
10943}; 11037};
10944 11038
11039static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11040 /* output mixer control */
11041 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11042 {
11043 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11044 .name = "Master Playback Switch",
11045 .info = snd_hda_mixer_amp_switch_info,
11046 .get = snd_hda_mixer_amp_switch_get,
11047 .put = alc268_acer_master_sw_put,
11048 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11049 },
11050 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11051 HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11052 { }
11053};
11054
10945static struct hda_verb alc268_acer_aspire_one_verbs[] = { 11055static struct hda_verb alc268_acer_aspire_one_verbs[] = {
10946 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 11056 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10947 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 11057 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
@@ -11218,10 +11328,6 @@ static struct hda_verb alc268_volume_init_verbs[] = {
11218 { } 11328 { }
11219}; 11329};
11220 11330
11221#define alc268_mux_enum_info alc_mux_enum_info
11222#define alc268_mux_enum_get alc_mux_enum_get
11223#define alc268_mux_enum_put alc_mux_enum_put
11224
11225static struct snd_kcontrol_new alc268_capture_alt_mixer[] = { 11331static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11226 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT), 11332 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11227 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT), 11333 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
@@ -11233,9 +11339,9 @@ static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11233 /* .name = "Capture Source", */ 11339 /* .name = "Capture Source", */
11234 .name = "Input Source", 11340 .name = "Input Source",
11235 .count = 1, 11341 .count = 1,
11236 .info = alc268_mux_enum_info, 11342 .info = alc_mux_enum_info,
11237 .get = alc268_mux_enum_get, 11343 .get = alc_mux_enum_get,
11238 .put = alc268_mux_enum_put, 11344 .put = alc_mux_enum_put,
11239 }, 11345 },
11240 { } /* end */ 11346 { } /* end */
11241}; 11347};
@@ -11253,9 +11359,9 @@ static struct snd_kcontrol_new alc268_capture_mixer[] = {
11253 /* .name = "Capture Source", */ 11359 /* .name = "Capture Source", */
11254 .name = "Input Source", 11360 .name = "Input Source",
11255 .count = 2, 11361 .count = 2,
11256 .info = alc268_mux_enum_info, 11362 .info = alc_mux_enum_info,
11257 .get = alc268_mux_enum_get, 11363 .get = alc_mux_enum_get,
11258 .put = alc268_mux_enum_put, 11364 .put = alc_mux_enum_put,
11259 }, 11365 },
11260 { } /* end */ 11366 { } /* end */
11261}; 11367};
@@ -11274,6 +11380,15 @@ static struct hda_input_mux alc268_acer_capture_source = {
11274 .num_items = 3, 11380 .num_items = 3,
11275 .items = { 11381 .items = {
11276 { "Mic", 0x0 }, 11382 { "Mic", 0x0 },
11383 { "Internal Mic", 0x1 },
11384 { "Line", 0x2 },
11385 },
11386};
11387
11388static struct hda_input_mux alc268_acer_dmic_capture_source = {
11389 .num_items = 3,
11390 .items = {
11391 { "Mic", 0x0 },
11277 { "Internal Mic", 0x6 }, 11392 { "Internal Mic", 0x6 },
11278 { "Line", 0x2 }, 11393 { "Line", 0x2 },
11279 }, 11394 },
@@ -11512,13 +11627,13 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
11512 if (spec->autocfg.dig_out_pin) 11627 if (spec->autocfg.dig_out_pin)
11513 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID; 11628 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11514 11629
11515 if (spec->kctl_alloc) 11630 if (spec->kctls.list)
11516 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 11631 add_mixer(spec, spec->kctls.list);
11517 11632
11518 if (spec->autocfg.speaker_pins[0] != 0x1d) 11633 if (spec->autocfg.speaker_pins[0] != 0x1d)
11519 spec->mixers[spec->num_mixers++] = alc268_beep_mixer; 11634 add_mixer(spec, alc268_beep_mixer);
11520 11635
11521 spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs; 11636 add_verb(spec, alc268_volume_init_verbs);
11522 spec->num_mux_defs = 1; 11637 spec->num_mux_defs = 1;
11523 spec->input_mux = &spec->private_imux; 11638 spec->input_mux = &spec->private_imux;
11524 11639
@@ -11554,6 +11669,7 @@ static const char *alc268_models[ALC268_MODEL_LAST] = {
11554 [ALC268_3ST] = "3stack", 11669 [ALC268_3ST] = "3stack",
11555 [ALC268_TOSHIBA] = "toshiba", 11670 [ALC268_TOSHIBA] = "toshiba",
11556 [ALC268_ACER] = "acer", 11671 [ALC268_ACER] = "acer",
11672 [ALC268_ACER_DMIC] = "acer-dmic",
11557 [ALC268_ACER_ASPIRE_ONE] = "acer-aspire", 11673 [ALC268_ACER_ASPIRE_ONE] = "acer-aspire",
11558 [ALC268_DELL] = "dell", 11674 [ALC268_DELL] = "dell",
11559 [ALC268_ZEPTO] = "zepto", 11675 [ALC268_ZEPTO] = "zepto",
@@ -11649,6 +11765,23 @@ static struct alc_config_preset alc268_presets[] = {
11649 .unsol_event = alc268_acer_unsol_event, 11765 .unsol_event = alc268_acer_unsol_event,
11650 .init_hook = alc268_acer_init_hook, 11766 .init_hook = alc268_acer_init_hook,
11651 }, 11767 },
11768 [ALC268_ACER_DMIC] = {
11769 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11770 alc268_beep_mixer },
11771 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11772 alc268_acer_verbs },
11773 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11774 .dac_nids = alc268_dac_nids,
11775 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11776 .adc_nids = alc268_adc_nids_alt,
11777 .capsrc_nids = alc268_capsrc_nids,
11778 .hp_nid = 0x02,
11779 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11780 .channel_mode = alc268_modes,
11781 .input_mux = &alc268_acer_dmic_capture_source,
11782 .unsol_event = alc268_acer_unsol_event,
11783 .init_hook = alc268_acer_init_hook,
11784 },
11652 [ALC268_ACER_ASPIRE_ONE] = { 11785 [ALC268_ACER_ASPIRE_ONE] = {
11653 .mixers = { alc268_acer_aspire_one_mixer, 11786 .mixers = { alc268_acer_aspire_one_mixer,
11654 alc268_capture_alt_mixer }, 11787 alc268_capture_alt_mixer },
@@ -11787,15 +11920,11 @@ static int patch_alc268(struct hda_codec *codec)
11787 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) { 11920 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11788 spec->adc_nids = alc268_adc_nids_alt; 11921 spec->adc_nids = alc268_adc_nids_alt;
11789 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt); 11922 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11790 spec->mixers[spec->num_mixers] = 11923 add_mixer(spec, alc268_capture_alt_mixer);
11791 alc268_capture_alt_mixer;
11792 spec->num_mixers++;
11793 } else { 11924 } else {
11794 spec->adc_nids = alc268_adc_nids; 11925 spec->adc_nids = alc268_adc_nids;
11795 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids); 11926 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11796 spec->mixers[spec->num_mixers] = 11927 add_mixer(spec, alc268_capture_mixer);
11797 alc268_capture_mixer;
11798 spec->num_mixers++;
11799 } 11928 }
11800 spec->capsrc_nids = alc268_capsrc_nids; 11929 spec->capsrc_nids = alc268_capsrc_nids;
11801 /* set default input source */ 11930 /* set default input source */
@@ -11811,6 +11940,8 @@ static int patch_alc268(struct hda_codec *codec)
11811 if (board_config == ALC268_AUTO) 11940 if (board_config == ALC268_AUTO)
11812 spec->init_hook = alc268_auto_init; 11941 spec->init_hook = alc268_auto_init;
11813 11942
11943 codec->proc_widget_hook = print_realtek_coef;
11944
11814 return 0; 11945 return 0;
11815} 11946}
11816 11947
@@ -11893,6 +12024,31 @@ static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11893 { } 12024 { }
11894}; 12025};
11895 12026
12027static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12028 /* output mixer control */
12029 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12030 {
12031 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12032 .name = "Master Playback Switch",
12033 .info = snd_hda_mixer_amp_switch_info,
12034 .get = snd_hda_mixer_amp_switch_get,
12035 .put = alc268_acer_master_sw_put,
12036 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12037 },
12038 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12039 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12040 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12041 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12042 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12043 HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12044 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12045 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12046 HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12047 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12048 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12049 { }
12050};
12051
11896/* bind volumes of both NID 0x0c and 0x0d */ 12052/* bind volumes of both NID 0x0c and 0x0d */
11897static struct hda_bind_ctls alc269_epc_bind_vol = { 12053static struct hda_bind_ctls alc269_epc_bind_vol = {
11898 .ops = &snd_hda_bind_vol, 12054 .ops = &snd_hda_bind_vol,
@@ -11911,28 +12067,18 @@ static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11911}; 12067};
11912 12068
11913/* capture mixer elements */ 12069/* capture mixer elements */
11914static struct snd_kcontrol_new alc269_capture_mixer[] = { 12070static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11915 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 12071 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11916 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 12072 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11917 { 12073 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11919 /* The multiple "Capture Source" controls confuse alsamixer
11920 * So call somewhat different..
11921 */
11922 /* .name = "Capture Source", */
11923 .name = "Input Source",
11924 .count = 1,
11925 .info = alc_mux_enum_info,
11926 .get = alc_mux_enum_get,
11927 .put = alc_mux_enum_put,
11928 },
11929 { } /* end */ 12074 { } /* end */
11930}; 12075};
11931 12076
11932/* capture mixer elements */ 12077/* FSC amilo */
11933static struct snd_kcontrol_new alc269_epc_capture_mixer[] = { 12078static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
11934 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 12079 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11935 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 12080 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12081 HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
11936 { } /* end */ 12082 { } /* end */
11937}; 12083};
11938 12084
@@ -11953,6 +12099,20 @@ static struct hda_verb alc269_quanta_fl1_verbs[] = {
11953 { } 12099 { }
11954}; 12100};
11955 12101
12102static struct hda_verb alc269_lifebook_verbs[] = {
12103 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12104 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12105 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12106 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12107 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12108 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12109 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12110 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12111 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12112 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12113 { }
12114};
12115
11956/* toggle speaker-output according to the hp-jack state */ 12116/* toggle speaker-output according to the hp-jack state */
11957static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec) 12117static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
11958{ 12118{
@@ -11978,6 +12138,37 @@ static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
11978 AC_VERB_SET_PROC_COEF, 0x480); 12138 AC_VERB_SET_PROC_COEF, 0x480);
11979} 12139}
11980 12140
12141/* toggle speaker-output according to the hp-jacks state */
12142static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12143{
12144 unsigned int present;
12145 unsigned char bits;
12146
12147 /* Check laptop headphone socket */
12148 present = snd_hda_codec_read(codec, 0x15, 0,
12149 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12150
12151 /* Check port replicator headphone socket */
12152 present |= snd_hda_codec_read(codec, 0x1a, 0,
12153 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12154
12155 bits = present ? AMP_IN_MUTE(0) : 0;
12156 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12157 AMP_IN_MUTE(0), bits);
12158 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12159 AMP_IN_MUTE(0), bits);
12160
12161 snd_hda_codec_write(codec, 0x20, 0,
12162 AC_VERB_SET_COEF_INDEX, 0x0c);
12163 snd_hda_codec_write(codec, 0x20, 0,
12164 AC_VERB_SET_PROC_COEF, 0x680);
12165
12166 snd_hda_codec_write(codec, 0x20, 0,
12167 AC_VERB_SET_COEF_INDEX, 0x0c);
12168 snd_hda_codec_write(codec, 0x20, 0,
12169 AC_VERB_SET_PROC_COEF, 0x480);
12170}
12171
11981static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec) 12172static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
11982{ 12173{
11983 unsigned int present; 12174 unsigned int present;
@@ -11988,6 +12179,29 @@ static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
11988 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1); 12179 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
11989} 12180}
11990 12181
12182static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12183{
12184 unsigned int present_laptop;
12185 unsigned int present_dock;
12186
12187 present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12188 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12189
12190 present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12191 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12192
12193 /* Laptop mic port overrides dock mic port, design decision */
12194 if (present_dock)
12195 snd_hda_codec_write(codec, 0x23, 0,
12196 AC_VERB_SET_CONNECT_SEL, 0x3);
12197 if (present_laptop)
12198 snd_hda_codec_write(codec, 0x23, 0,
12199 AC_VERB_SET_CONNECT_SEL, 0x0);
12200 if (!present_dock && !present_laptop)
12201 snd_hda_codec_write(codec, 0x23, 0,
12202 AC_VERB_SET_CONNECT_SEL, 0x1);
12203}
12204
11991static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec, 12205static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
11992 unsigned int res) 12206 unsigned int res)
11993{ 12207{
@@ -11997,12 +12211,27 @@ static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
11997 alc269_quanta_fl1_mic_automute(codec); 12211 alc269_quanta_fl1_mic_automute(codec);
11998} 12212}
11999 12213
12214static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12215 unsigned int res)
12216{
12217 if ((res >> 26) == ALC880_HP_EVENT)
12218 alc269_lifebook_speaker_automute(codec);
12219 if ((res >> 26) == ALC880_MIC_EVENT)
12220 alc269_lifebook_mic_autoswitch(codec);
12221}
12222
12000static void alc269_quanta_fl1_init_hook(struct hda_codec *codec) 12223static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12001{ 12224{
12002 alc269_quanta_fl1_speaker_automute(codec); 12225 alc269_quanta_fl1_speaker_automute(codec);
12003 alc269_quanta_fl1_mic_automute(codec); 12226 alc269_quanta_fl1_mic_automute(codec);
12004} 12227}
12005 12228
12229static void alc269_lifebook_init_hook(struct hda_codec *codec)
12230{
12231 alc269_lifebook_speaker_automute(codec);
12232 alc269_lifebook_mic_autoswitch(codec);
12233}
12234
12006static struct hda_verb alc269_eeepc_dmic_init_verbs[] = { 12235static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12007 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 12236 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12008 {0x23, AC_VERB_SET_CONNECT_SEL, 0x05}, 12237 {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
@@ -12303,17 +12532,17 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
12303 if (spec->autocfg.dig_out_pin) 12532 if (spec->autocfg.dig_out_pin)
12304 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID; 12533 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12305 12534
12306 if (spec->kctl_alloc) 12535 if (spec->kctls.list)
12307 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 12536 add_mixer(spec, spec->kctls.list);
12308 12537
12309 /* create a beep mixer control if the pin 0x1d isn't assigned */ 12538 /* create a beep mixer control if the pin 0x1d isn't assigned */
12310 for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++) 12539 for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12311 if (spec->autocfg.input_pins[i] == 0x1d) 12540 if (spec->autocfg.input_pins[i] == 0x1d)
12312 break; 12541 break;
12313 if (i >= ARRAY_SIZE(spec->autocfg.input_pins)) 12542 if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12314 spec->mixers[spec->num_mixers++] = alc269_beep_mixer; 12543 add_mixer(spec, alc269_beep_mixer);
12315 12544
12316 spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs; 12545 add_verb(spec, alc269_init_verbs);
12317 spec->num_mux_defs = 1; 12546 spec->num_mux_defs = 1;
12318 spec->input_mux = &spec->private_imux; 12547 spec->input_mux = &spec->private_imux;
12319 /* set default input source */ 12548 /* set default input source */
@@ -12325,8 +12554,8 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
12325 if (err < 0) 12554 if (err < 0)
12326 return err; 12555 return err;
12327 12556
12328 spec->mixers[spec->num_mixers] = alc269_capture_mixer; 12557 if (!spec->cap_mixer)
12329 spec->num_mixers++; 12558 set_capture_mixer(spec);
12330 12559
12331 store_pin_configs(codec); 12560 store_pin_configs(codec);
12332 return 1; 12561 return 1;
@@ -12355,7 +12584,9 @@ static const char *alc269_models[ALC269_MODEL_LAST] = {
12355 [ALC269_BASIC] = "basic", 12584 [ALC269_BASIC] = "basic",
12356 [ALC269_QUANTA_FL1] = "quanta", 12585 [ALC269_QUANTA_FL1] = "quanta",
12357 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703", 12586 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703",
12358 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901" 12587 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901",
12588 [ALC269_FUJITSU] = "fujitsu",
12589 [ALC269_LIFEBOOK] = "lifebook"
12359}; 12590};
12360 12591
12361static struct snd_pci_quirk alc269_cfg_tbl[] = { 12592static struct snd_pci_quirk alc269_cfg_tbl[] = {
@@ -12366,12 +12597,14 @@ static struct snd_pci_quirk alc269_cfg_tbl[] = {
12366 ALC269_ASUS_EEEPC_P901), 12597 ALC269_ASUS_EEEPC_P901),
12367 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101", 12598 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12368 ALC269_ASUS_EEEPC_P901), 12599 ALC269_ASUS_EEEPC_P901),
12600 SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12601 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12369 {} 12602 {}
12370}; 12603};
12371 12604
12372static struct alc_config_preset alc269_presets[] = { 12605static struct alc_config_preset alc269_presets[] = {
12373 [ALC269_BASIC] = { 12606 [ALC269_BASIC] = {
12374 .mixers = { alc269_base_mixer, alc269_capture_mixer }, 12607 .mixers = { alc269_base_mixer },
12375 .init_verbs = { alc269_init_verbs }, 12608 .init_verbs = { alc269_init_verbs },
12376 .num_dacs = ARRAY_SIZE(alc269_dac_nids), 12609 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12377 .dac_nids = alc269_dac_nids, 12610 .dac_nids = alc269_dac_nids,
@@ -12393,7 +12626,8 @@ static struct alc_config_preset alc269_presets[] = {
12393 .init_hook = alc269_quanta_fl1_init_hook, 12626 .init_hook = alc269_quanta_fl1_init_hook,
12394 }, 12627 },
12395 [ALC269_ASUS_EEEPC_P703] = { 12628 [ALC269_ASUS_EEEPC_P703] = {
12396 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer }, 12629 .mixers = { alc269_eeepc_mixer },
12630 .cap_mixer = alc269_epc_capture_mixer,
12397 .init_verbs = { alc269_init_verbs, 12631 .init_verbs = { alc269_init_verbs,
12398 alc269_eeepc_amic_init_verbs }, 12632 alc269_eeepc_amic_init_verbs },
12399 .num_dacs = ARRAY_SIZE(alc269_dac_nids), 12633 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
@@ -12406,7 +12640,8 @@ static struct alc_config_preset alc269_presets[] = {
12406 .init_hook = alc269_eeepc_amic_inithook, 12640 .init_hook = alc269_eeepc_amic_inithook,
12407 }, 12641 },
12408 [ALC269_ASUS_EEEPC_P901] = { 12642 [ALC269_ASUS_EEEPC_P901] = {
12409 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer}, 12643 .mixers = { alc269_eeepc_mixer },
12644 .cap_mixer = alc269_epc_capture_mixer,
12410 .init_verbs = { alc269_init_verbs, 12645 .init_verbs = { alc269_init_verbs,
12411 alc269_eeepc_dmic_init_verbs }, 12646 alc269_eeepc_dmic_init_verbs },
12412 .num_dacs = ARRAY_SIZE(alc269_dac_nids), 12647 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
@@ -12418,6 +12653,32 @@ static struct alc_config_preset alc269_presets[] = {
12418 .unsol_event = alc269_eeepc_dmic_unsol_event, 12653 .unsol_event = alc269_eeepc_dmic_unsol_event,
12419 .init_hook = alc269_eeepc_dmic_inithook, 12654 .init_hook = alc269_eeepc_dmic_inithook,
12420 }, 12655 },
12656 [ALC269_FUJITSU] = {
12657 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12658 .cap_mixer = alc269_epc_capture_mixer,
12659 .init_verbs = { alc269_init_verbs,
12660 alc269_eeepc_dmic_init_verbs },
12661 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12662 .dac_nids = alc269_dac_nids,
12663 .hp_nid = 0x03,
12664 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12665 .channel_mode = alc269_modes,
12666 .input_mux = &alc269_eeepc_dmic_capture_source,
12667 .unsol_event = alc269_eeepc_dmic_unsol_event,
12668 .init_hook = alc269_eeepc_dmic_inithook,
12669 },
12670 [ALC269_LIFEBOOK] = {
12671 .mixers = { alc269_lifebook_mixer },
12672 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12673 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12674 .dac_nids = alc269_dac_nids,
12675 .hp_nid = 0x03,
12676 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12677 .channel_mode = alc269_modes,
12678 .input_mux = &alc269_capture_source,
12679 .unsol_event = alc269_lifebook_unsol_event,
12680 .init_hook = alc269_lifebook_init_hook,
12681 },
12421}; 12682};
12422 12683
12423static int patch_alc269(struct hda_codec *codec) 12684static int patch_alc269(struct hda_codec *codec)
@@ -12472,6 +12733,8 @@ static int patch_alc269(struct hda_codec *codec)
12472 spec->adc_nids = alc269_adc_nids; 12733 spec->adc_nids = alc269_adc_nids;
12473 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids); 12734 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12474 spec->capsrc_nids = alc269_capsrc_nids; 12735 spec->capsrc_nids = alc269_capsrc_nids;
12736 if (!spec->cap_mixer)
12737 set_capture_mixer(spec);
12475 12738
12476 codec->patch_ops = alc_patch_ops; 12739 codec->patch_ops = alc_patch_ops;
12477 if (board_config == ALC269_AUTO) 12740 if (board_config == ALC269_AUTO)
@@ -12480,6 +12743,7 @@ static int patch_alc269(struct hda_codec *codec)
12480 if (!spec->loopback.amplist) 12743 if (!spec->loopback.amplist)
12481 spec->loopback.amplist = alc269_loopbacks; 12744 spec->loopback.amplist = alc269_loopbacks;
12482#endif 12745#endif
12746 codec->proc_widget_hook = print_realtek_coef;
12483 12747
12484 return 0; 12748 return 0;
12485} 12749}
@@ -12612,17 +12876,6 @@ static struct snd_kcontrol_new alc861_base_mixer[] = {
12612 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT), 12876 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12613 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT), 12877 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12614 12878
12615 /* Capture mixer control */
12616 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12617 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12618 {
12619 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12620 .name = "Capture Source",
12621 .count = 1,
12622 .info = alc_mux_enum_info,
12623 .get = alc_mux_enum_get,
12624 .put = alc_mux_enum_put,
12625 },
12626 { } /* end */ 12879 { } /* end */
12627}; 12880};
12628 12881
@@ -12646,17 +12899,6 @@ static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12646 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT), 12899 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12647 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT), 12900 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12648 12901
12649 /* Capture mixer control */
12650 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12651 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12652 {
12653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12654 .name = "Capture Source",
12655 .count = 1,
12656 .info = alc_mux_enum_info,
12657 .get = alc_mux_enum_get,
12658 .put = alc_mux_enum_put,
12659 },
12660 { 12902 {
12661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 12903 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12662 .name = "Channel Mode", 12904 .name = "Channel Mode",
@@ -12674,18 +12916,6 @@ static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12674 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT), 12916 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12675 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT), 12917 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12676 12918
12677 /*Capture mixer control */
12678 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12679 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12680 {
12681 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12682 .name = "Capture Source",
12683 .count = 1,
12684 .info = alc_mux_enum_info,
12685 .get = alc_mux_enum_get,
12686 .put = alc_mux_enum_put,
12687 },
12688
12689 { } /* end */ 12919 { } /* end */
12690}; 12920};
12691 12921
@@ -12709,17 +12939,6 @@ static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12709 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT), 12939 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12710 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT), 12940 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12711 12941
12712 /* Capture mixer control */
12713 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12714 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12715 {
12716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12717 .name = "Capture Source",
12718 .count = 1,
12719 .info = alc_mux_enum_info,
12720 .get = alc_mux_enum_get,
12721 .put = alc_mux_enum_put,
12722 },
12723 { 12942 {
12724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 12943 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12725 .name = "Channel Mode", 12944 .name = "Channel Mode",
@@ -12751,17 +12970,6 @@ static struct snd_kcontrol_new alc861_asus_mixer[] = {
12751 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT), 12970 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12752 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT), 12971 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12753 12972
12754 /* Capture mixer control */
12755 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12756 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12757 {
12758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12759 .name = "Capture Source",
12760 .count = 1,
12761 .info = alc_mux_enum_info,
12762 .get = alc_mux_enum_get,
12763 .put = alc_mux_enum_put,
12764 },
12765 { 12973 {
12766 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 12974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12767 .name = "Channel Mode", 12975 .name = "Channel Mode",
@@ -13293,25 +13501,6 @@ static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13293 return 0; 13501 return 0;
13294} 13502}
13295 13503
13296static struct snd_kcontrol_new alc861_capture_mixer[] = {
13297 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
13298 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13299
13300 {
13301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13302 /* The multiple "Capture Source" controls confuse alsamixer
13303 * So call somewhat different..
13304 */
13305 /* .name = "Capture Source", */
13306 .name = "Input Source",
13307 .count = 1,
13308 .info = alc_mux_enum_info,
13309 .get = alc_mux_enum_get,
13310 .put = alc_mux_enum_put,
13311 },
13312 { } /* end */
13313};
13314
13315static void alc861_auto_set_output_and_unmute(struct hda_codec *codec, 13504static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13316 hda_nid_t nid, 13505 hda_nid_t nid,
13317 int pin_type, int dac_idx) 13506 int pin_type, int dac_idx)
@@ -13402,18 +13591,17 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
13402 if (spec->autocfg.dig_out_pin) 13591 if (spec->autocfg.dig_out_pin)
13403 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID; 13592 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13404 13593
13405 if (spec->kctl_alloc) 13594 if (spec->kctls.list)
13406 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 13595 add_mixer(spec, spec->kctls.list);
13407 13596
13408 spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs; 13597 add_verb(spec, alc861_auto_init_verbs);
13409 13598
13410 spec->num_mux_defs = 1; 13599 spec->num_mux_defs = 1;
13411 spec->input_mux = &spec->private_imux; 13600 spec->input_mux = &spec->private_imux;
13412 13601
13413 spec->adc_nids = alc861_adc_nids; 13602 spec->adc_nids = alc861_adc_nids;
13414 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids); 13603 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13415 spec->mixers[spec->num_mixers] = alc861_capture_mixer; 13604 set_capture_mixer(spec);
13416 spec->num_mixers++;
13417 13605
13418 store_pin_configs(codec); 13606 store_pin_configs(codec);
13419 return 1; 13607 return 1;
@@ -13644,6 +13832,7 @@ static int patch_alc861(struct hda_codec *codec)
13644 if (!spec->loopback.amplist) 13832 if (!spec->loopback.amplist)
13645 spec->loopback.amplist = alc861_loopbacks; 13833 spec->loopback.amplist = alc861_loopbacks;
13646#endif 13834#endif
13835 codec->proc_widget_hook = print_realtek_coef;
13647 13836
13648 return 0; 13837 return 0;
13649} 13838}
@@ -13709,11 +13898,6 @@ static struct hda_input_mux alc861vd_hp_capture_source = {
13709 }, 13898 },
13710}; 13899};
13711 13900
13712#define alc861vd_mux_enum_info alc_mux_enum_info
13713#define alc861vd_mux_enum_get alc_mux_enum_get
13714/* ALC861VD has the ALC882-type input selection (but has only one ADC) */
13715#define alc861vd_mux_enum_put alc882_mux_enum_put
13716
13717/* 13901/*
13718 * 2ch mode 13902 * 2ch mode
13719 */ 13903 */
@@ -13759,25 +13943,6 @@ static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13759 { } /* end */ 13943 { } /* end */
13760}; 13944};
13761 13945
13762static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
13763 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13764 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13765
13766 {
13767 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13768 /* The multiple "Capture Source" controls confuse alsamixer
13769 * So call somewhat different..
13770 */
13771 /* .name = "Capture Source", */
13772 .name = "Input Source",
13773 .count = 1,
13774 .info = alc861vd_mux_enum_info,
13775 .get = alc861vd_mux_enum_get,
13776 .put = alc861vd_mux_enum_put,
13777 },
13778 { } /* end */
13779};
13780
13781/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17 13946/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13782 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b 13947 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13783 */ 13948 */
@@ -14169,6 +14334,7 @@ static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int re
14169static const char *alc861vd_models[ALC861VD_MODEL_LAST] = { 14334static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14170 [ALC660VD_3ST] = "3stack-660", 14335 [ALC660VD_3ST] = "3stack-660",
14171 [ALC660VD_3ST_DIG] = "3stack-660-digout", 14336 [ALC660VD_3ST_DIG] = "3stack-660-digout",
14337 [ALC660VD_ASUS_V1S] = "asus-v1s",
14172 [ALC861VD_3ST] = "3stack", 14338 [ALC861VD_3ST] = "3stack",
14173 [ALC861VD_3ST_DIG] = "3stack-digout", 14339 [ALC861VD_3ST_DIG] = "3stack-digout",
14174 [ALC861VD_6ST_DIG] = "6stack-digout", 14340 [ALC861VD_6ST_DIG] = "6stack-digout",
@@ -14183,7 +14349,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14183 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP), 14349 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14184 SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST), 14350 SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14185 SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST), 14351 SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14186 SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO), 14352 SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14187 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG), 14353 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14188 SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST), 14354 SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14189 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO), 14355 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
@@ -14290,6 +14456,21 @@ static struct alc_config_preset alc861vd_presets[] = {
14290 .unsol_event = alc861vd_dallas_unsol_event, 14456 .unsol_event = alc861vd_dallas_unsol_event,
14291 .init_hook = alc861vd_dallas_automute, 14457 .init_hook = alc861vd_dallas_automute,
14292 }, 14458 },
14459 [ALC660VD_ASUS_V1S] = {
14460 .mixers = { alc861vd_lenovo_mixer },
14461 .init_verbs = { alc861vd_volume_init_verbs,
14462 alc861vd_3stack_init_verbs,
14463 alc861vd_eapd_verbs,
14464 alc861vd_lenovo_unsol_verbs },
14465 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14466 .dac_nids = alc660vd_dac_nids,
14467 .dig_out_nid = ALC861VD_DIGOUT_NID,
14468 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14469 .channel_mode = alc861vd_3stack_2ch_modes,
14470 .input_mux = &alc861vd_capture_source,
14471 .unsol_event = alc861vd_lenovo_unsol_event,
14472 .init_hook = alc861vd_lenovo_automute,
14473 },
14293}; 14474};
14294 14475
14295/* 14476/*
@@ -14514,11 +14695,10 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
14514 if (spec->autocfg.dig_out_pin) 14695 if (spec->autocfg.dig_out_pin)
14515 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID; 14696 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14516 14697
14517 if (spec->kctl_alloc) 14698 if (spec->kctls.list)
14518 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 14699 add_mixer(spec, spec->kctls.list);
14519 14700
14520 spec->init_verbs[spec->num_init_verbs++] 14701 add_verb(spec, alc861vd_volume_init_verbs);
14521 = alc861vd_volume_init_verbs;
14522 14702
14523 spec->num_mux_defs = 1; 14703 spec->num_mux_defs = 1;
14524 spec->input_mux = &spec->private_imux; 14704 spec->input_mux = &spec->private_imux;
@@ -14585,7 +14765,7 @@ static int patch_alc861vd(struct hda_codec *codec)
14585 spec->stream_name_analog = "ALC660-VD Analog"; 14765 spec->stream_name_analog = "ALC660-VD Analog";
14586 spec->stream_name_digital = "ALC660-VD Digital"; 14766 spec->stream_name_digital = "ALC660-VD Digital";
14587 /* always turn on EAPD */ 14767 /* always turn on EAPD */
14588 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs; 14768 add_verb(spec, alc660vd_eapd_verbs);
14589 } else { 14769 } else {
14590 spec->stream_name_analog = "ALC861VD Analog"; 14770 spec->stream_name_analog = "ALC861VD Analog";
14591 spec->stream_name_digital = "ALC861VD Digital"; 14771 spec->stream_name_digital = "ALC861VD Digital";
@@ -14600,9 +14780,9 @@ static int patch_alc861vd(struct hda_codec *codec)
14600 spec->adc_nids = alc861vd_adc_nids; 14780 spec->adc_nids = alc861vd_adc_nids;
14601 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids); 14781 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14602 spec->capsrc_nids = alc861vd_capsrc_nids; 14782 spec->capsrc_nids = alc861vd_capsrc_nids;
14783 spec->is_mix_capture = 1;
14603 14784
14604 spec->mixers[spec->num_mixers] = alc861vd_capture_mixer; 14785 set_capture_mixer(spec);
14605 spec->num_mixers++;
14606 14786
14607 spec->vmaster_nid = 0x02; 14787 spec->vmaster_nid = 0x02;
14608 14788
@@ -14614,6 +14794,7 @@ static int patch_alc861vd(struct hda_codec *codec)
14614 if (!spec->loopback.amplist) 14794 if (!spec->loopback.amplist)
14615 spec->loopback.amplist = alc861vd_loopbacks; 14795 spec->loopback.amplist = alc861vd_loopbacks;
14616#endif 14796#endif
14797 codec->proc_widget_hook = print_realtek_coef;
14617 14798
14618 return 0; 14799 return 0;
14619} 14800}
@@ -14689,10 +14870,6 @@ static struct hda_input_mux alc663_m51va_capture_source = {
14689 }, 14870 },
14690}; 14871};
14691 14872
14692#define alc662_mux_enum_info alc_mux_enum_info
14693#define alc662_mux_enum_get alc_mux_enum_get
14694#define alc662_mux_enum_put alc882_mux_enum_put
14695
14696/* 14873/*
14697 * 2ch mode 14874 * 2ch mode
14698 */ 14875 */
@@ -15278,25 +15455,6 @@ static struct hda_verb alc662_ecs_init_verbs[] = {
15278 {} 15455 {}
15279}; 15456};
15280 15457
15281/* capture mixer elements */
15282static struct snd_kcontrol_new alc662_capture_mixer[] = {
15283 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15284 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15285 {
15286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15287 /* The multiple "Capture Source" controls confuse alsamixer
15288 * So call somewhat different..
15289 */
15290 /* .name = "Capture Source", */
15291 .name = "Input Source",
15292 .count = 1,
15293 .info = alc662_mux_enum_info,
15294 .get = alc662_mux_enum_get,
15295 .put = alc662_mux_enum_put,
15296 },
15297 { } /* end */
15298};
15299
15300static struct snd_kcontrol_new alc662_auto_capture_mixer[] = { 15458static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15301 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT), 15459 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15302 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT), 15460 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
@@ -15868,7 +16026,7 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
15868 16026
15869static struct alc_config_preset alc662_presets[] = { 16027static struct alc_config_preset alc662_presets[] = {
15870 [ALC662_3ST_2ch_DIG] = { 16028 [ALC662_3ST_2ch_DIG] = {
15871 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer }, 16029 .mixers = { alc662_3ST_2ch_mixer },
15872 .init_verbs = { alc662_init_verbs }, 16030 .init_verbs = { alc662_init_verbs },
15873 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16031 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15874 .dac_nids = alc662_dac_nids, 16032 .dac_nids = alc662_dac_nids,
@@ -15879,8 +16037,7 @@ static struct alc_config_preset alc662_presets[] = {
15879 .input_mux = &alc662_capture_source, 16037 .input_mux = &alc662_capture_source,
15880 }, 16038 },
15881 [ALC662_3ST_6ch_DIG] = { 16039 [ALC662_3ST_6ch_DIG] = {
15882 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer, 16040 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
15883 alc662_capture_mixer },
15884 .init_verbs = { alc662_init_verbs }, 16041 .init_verbs = { alc662_init_verbs },
15885 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16042 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15886 .dac_nids = alc662_dac_nids, 16043 .dac_nids = alc662_dac_nids,
@@ -15892,8 +16049,7 @@ static struct alc_config_preset alc662_presets[] = {
15892 .input_mux = &alc662_capture_source, 16049 .input_mux = &alc662_capture_source,
15893 }, 16050 },
15894 [ALC662_3ST_6ch] = { 16051 [ALC662_3ST_6ch] = {
15895 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer, 16052 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
15896 alc662_capture_mixer },
15897 .init_verbs = { alc662_init_verbs }, 16053 .init_verbs = { alc662_init_verbs },
15898 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16054 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15899 .dac_nids = alc662_dac_nids, 16055 .dac_nids = alc662_dac_nids,
@@ -15903,8 +16059,7 @@ static struct alc_config_preset alc662_presets[] = {
15903 .input_mux = &alc662_capture_source, 16059 .input_mux = &alc662_capture_source,
15904 }, 16060 },
15905 [ALC662_5ST_DIG] = { 16061 [ALC662_5ST_DIG] = {
15906 .mixers = { alc662_base_mixer, alc662_chmode_mixer, 16062 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
15907 alc662_capture_mixer },
15908 .init_verbs = { alc662_init_verbs }, 16063 .init_verbs = { alc662_init_verbs },
15909 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16064 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15910 .dac_nids = alc662_dac_nids, 16065 .dac_nids = alc662_dac_nids,
@@ -15915,7 +16070,7 @@ static struct alc_config_preset alc662_presets[] = {
15915 .input_mux = &alc662_capture_source, 16070 .input_mux = &alc662_capture_source,
15916 }, 16071 },
15917 [ALC662_LENOVO_101E] = { 16072 [ALC662_LENOVO_101E] = {
15918 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer }, 16073 .mixers = { alc662_lenovo_101e_mixer },
15919 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs }, 16074 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
15920 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16075 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15921 .dac_nids = alc662_dac_nids, 16076 .dac_nids = alc662_dac_nids,
@@ -15926,7 +16081,7 @@ static struct alc_config_preset alc662_presets[] = {
15926 .init_hook = alc662_lenovo_101e_all_automute, 16081 .init_hook = alc662_lenovo_101e_all_automute,
15927 }, 16082 },
15928 [ALC662_ASUS_EEEPC_P701] = { 16083 [ALC662_ASUS_EEEPC_P701] = {
15929 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer }, 16084 .mixers = { alc662_eeepc_p701_mixer },
15930 .init_verbs = { alc662_init_verbs, 16085 .init_verbs = { alc662_init_verbs,
15931 alc662_eeepc_sue_init_verbs }, 16086 alc662_eeepc_sue_init_verbs },
15932 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16087 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
@@ -15938,7 +16093,7 @@ static struct alc_config_preset alc662_presets[] = {
15938 .init_hook = alc662_eeepc_inithook, 16093 .init_hook = alc662_eeepc_inithook,
15939 }, 16094 },
15940 [ALC662_ASUS_EEEPC_EP20] = { 16095 [ALC662_ASUS_EEEPC_EP20] = {
15941 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer, 16096 .mixers = { alc662_eeepc_ep20_mixer,
15942 alc662_chmode_mixer }, 16097 alc662_chmode_mixer },
15943 .init_verbs = { alc662_init_verbs, 16098 .init_verbs = { alc662_init_verbs,
15944 alc662_eeepc_ep20_sue_init_verbs }, 16099 alc662_eeepc_ep20_sue_init_verbs },
@@ -15951,7 +16106,7 @@ static struct alc_config_preset alc662_presets[] = {
15951 .init_hook = alc662_eeepc_ep20_inithook, 16106 .init_hook = alc662_eeepc_ep20_inithook,
15952 }, 16107 },
15953 [ALC662_ECS] = { 16108 [ALC662_ECS] = {
15954 .mixers = { alc662_ecs_mixer, alc662_capture_mixer }, 16109 .mixers = { alc662_ecs_mixer },
15955 .init_verbs = { alc662_init_verbs, 16110 .init_verbs = { alc662_init_verbs,
15956 alc662_ecs_init_verbs }, 16111 alc662_ecs_init_verbs },
15957 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16112 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
@@ -15963,7 +16118,7 @@ static struct alc_config_preset alc662_presets[] = {
15963 .init_hook = alc662_eeepc_inithook, 16118 .init_hook = alc662_eeepc_inithook,
15964 }, 16119 },
15965 [ALC663_ASUS_M51VA] = { 16120 [ALC663_ASUS_M51VA] = {
15966 .mixers = { alc663_m51va_mixer, alc662_capture_mixer}, 16121 .mixers = { alc663_m51va_mixer },
15967 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs }, 16122 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15968 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16123 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15969 .dac_nids = alc662_dac_nids, 16124 .dac_nids = alc662_dac_nids,
@@ -15975,7 +16130,7 @@ static struct alc_config_preset alc662_presets[] = {
15975 .init_hook = alc663_m51va_inithook, 16130 .init_hook = alc663_m51va_inithook,
15976 }, 16131 },
15977 [ALC663_ASUS_G71V] = { 16132 [ALC663_ASUS_G71V] = {
15978 .mixers = { alc663_g71v_mixer, alc662_capture_mixer}, 16133 .mixers = { alc663_g71v_mixer },
15979 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs }, 16134 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
15980 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16135 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15981 .dac_nids = alc662_dac_nids, 16136 .dac_nids = alc662_dac_nids,
@@ -15987,7 +16142,7 @@ static struct alc_config_preset alc662_presets[] = {
15987 .init_hook = alc663_g71v_inithook, 16142 .init_hook = alc663_g71v_inithook,
15988 }, 16143 },
15989 [ALC663_ASUS_H13] = { 16144 [ALC663_ASUS_H13] = {
15990 .mixers = { alc663_m51va_mixer, alc662_capture_mixer}, 16145 .mixers = { alc663_m51va_mixer },
15991 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs }, 16146 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15992 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16147 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15993 .dac_nids = alc662_dac_nids, 16148 .dac_nids = alc662_dac_nids,
@@ -15998,7 +16153,7 @@ static struct alc_config_preset alc662_presets[] = {
15998 .init_hook = alc663_m51va_inithook, 16153 .init_hook = alc663_m51va_inithook,
15999 }, 16154 },
16000 [ALC663_ASUS_G50V] = { 16155 [ALC663_ASUS_G50V] = {
16001 .mixers = { alc663_g50v_mixer, alc662_capture_mixer}, 16156 .mixers = { alc663_g50v_mixer },
16002 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs }, 16157 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16003 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16158 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16004 .dac_nids = alc662_dac_nids, 16159 .dac_nids = alc662_dac_nids,
@@ -16010,7 +16165,8 @@ static struct alc_config_preset alc662_presets[] = {
16010 .init_hook = alc663_g50v_inithook, 16165 .init_hook = alc663_g50v_inithook,
16011 }, 16166 },
16012 [ALC663_ASUS_MODE1] = { 16167 [ALC663_ASUS_MODE1] = {
16013 .mixers = { alc663_m51va_mixer, alc662_auto_capture_mixer }, 16168 .mixers = { alc663_m51va_mixer },
16169 .cap_mixer = alc662_auto_capture_mixer,
16014 .init_verbs = { alc662_init_verbs, 16170 .init_verbs = { alc662_init_verbs,
16015 alc663_21jd_amic_init_verbs }, 16171 alc663_21jd_amic_init_verbs },
16016 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16172 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
@@ -16024,7 +16180,8 @@ static struct alc_config_preset alc662_presets[] = {
16024 .init_hook = alc663_mode1_inithook, 16180 .init_hook = alc663_mode1_inithook,
16025 }, 16181 },
16026 [ALC662_ASUS_MODE2] = { 16182 [ALC662_ASUS_MODE2] = {
16027 .mixers = { alc662_1bjd_mixer, alc662_auto_capture_mixer }, 16183 .mixers = { alc662_1bjd_mixer },
16184 .cap_mixer = alc662_auto_capture_mixer,
16028 .init_verbs = { alc662_init_verbs, 16185 .init_verbs = { alc662_init_verbs,
16029 alc662_1bjd_amic_init_verbs }, 16186 alc662_1bjd_amic_init_verbs },
16030 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16187 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
@@ -16037,7 +16194,8 @@ static struct alc_config_preset alc662_presets[] = {
16037 .init_hook = alc662_mode2_inithook, 16194 .init_hook = alc662_mode2_inithook,
16038 }, 16195 },
16039 [ALC663_ASUS_MODE3] = { 16196 [ALC663_ASUS_MODE3] = {
16040 .mixers = { alc663_two_hp_m1_mixer, alc662_auto_capture_mixer }, 16197 .mixers = { alc663_two_hp_m1_mixer },
16198 .cap_mixer = alc662_auto_capture_mixer,
16041 .init_verbs = { alc662_init_verbs, 16199 .init_verbs = { alc662_init_verbs,
16042 alc663_two_hp_amic_m1_init_verbs }, 16200 alc663_two_hp_amic_m1_init_verbs },
16043 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16201 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
@@ -16051,8 +16209,8 @@ static struct alc_config_preset alc662_presets[] = {
16051 .init_hook = alc663_mode3_inithook, 16209 .init_hook = alc663_mode3_inithook,
16052 }, 16210 },
16053 [ALC663_ASUS_MODE4] = { 16211 [ALC663_ASUS_MODE4] = {
16054 .mixers = { alc663_asus_21jd_clfe_mixer, 16212 .mixers = { alc663_asus_21jd_clfe_mixer },
16055 alc662_auto_capture_mixer}, 16213 .cap_mixer = alc662_auto_capture_mixer,
16056 .init_verbs = { alc662_init_verbs, 16214 .init_verbs = { alc662_init_verbs,
16057 alc663_21jd_amic_init_verbs}, 16215 alc663_21jd_amic_init_verbs},
16058 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16216 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
@@ -16066,8 +16224,8 @@ static struct alc_config_preset alc662_presets[] = {
16066 .init_hook = alc663_mode4_inithook, 16224 .init_hook = alc663_mode4_inithook,
16067 }, 16225 },
16068 [ALC663_ASUS_MODE5] = { 16226 [ALC663_ASUS_MODE5] = {
16069 .mixers = { alc663_asus_15jd_clfe_mixer, 16227 .mixers = { alc663_asus_15jd_clfe_mixer },
16070 alc662_auto_capture_mixer }, 16228 .cap_mixer = alc662_auto_capture_mixer,
16071 .init_verbs = { alc662_init_verbs, 16229 .init_verbs = { alc662_init_verbs,
16072 alc663_15jd_amic_init_verbs }, 16230 alc663_15jd_amic_init_verbs },
16073 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16231 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
@@ -16081,7 +16239,8 @@ static struct alc_config_preset alc662_presets[] = {
16081 .init_hook = alc663_mode5_inithook, 16239 .init_hook = alc663_mode5_inithook,
16082 }, 16240 },
16083 [ALC663_ASUS_MODE6] = { 16241 [ALC663_ASUS_MODE6] = {
16084 .mixers = { alc663_two_hp_m2_mixer, alc662_auto_capture_mixer }, 16242 .mixers = { alc663_two_hp_m2_mixer },
16243 .cap_mixer = alc662_auto_capture_mixer,
16085 .init_verbs = { alc662_init_verbs, 16244 .init_verbs = { alc662_init_verbs,
16086 alc663_two_hp_amic_m2_init_verbs }, 16245 alc663_two_hp_amic_m2_init_verbs },
16087 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 16246 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
@@ -16342,24 +16501,20 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
16342 if (spec->autocfg.dig_out_pin) 16501 if (spec->autocfg.dig_out_pin)
16343 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID; 16502 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16344 16503
16345 if (spec->kctl_alloc) 16504 if (spec->kctls.list)
16346 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 16505 add_mixer(spec, spec->kctls.list);
16347 16506
16348 spec->num_mux_defs = 1; 16507 spec->num_mux_defs = 1;
16349 spec->input_mux = &spec->private_imux; 16508 spec->input_mux = &spec->private_imux;
16350 16509
16351 spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs; 16510 add_verb(spec, alc662_auto_init_verbs);
16352 if (codec->vendor_id == 0x10ec0663) 16511 if (codec->vendor_id == 0x10ec0663)
16353 spec->init_verbs[spec->num_init_verbs++] = 16512 add_verb(spec, alc663_auto_init_verbs);
16354 alc663_auto_init_verbs;
16355 16513
16356 err = alc_auto_add_mic_boost(codec); 16514 err = alc_auto_add_mic_boost(codec);
16357 if (err < 0) 16515 if (err < 0)
16358 return err; 16516 return err;
16359 16517
16360 spec->mixers[spec->num_mixers] = alc662_capture_mixer;
16361 spec->num_mixers++;
16362
16363 store_pin_configs(codec); 16518 store_pin_configs(codec);
16364 return 1; 16519 return 1;
16365} 16520}
@@ -16435,6 +16590,10 @@ static int patch_alc662(struct hda_codec *codec)
16435 spec->adc_nids = alc662_adc_nids; 16590 spec->adc_nids = alc662_adc_nids;
16436 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids); 16591 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16437 spec->capsrc_nids = alc662_capsrc_nids; 16592 spec->capsrc_nids = alc662_capsrc_nids;
16593 spec->is_mix_capture = 1;
16594
16595 if (!spec->cap_mixer)
16596 set_capture_mixer(spec);
16438 16597
16439 spec->vmaster_nid = 0x02; 16598 spec->vmaster_nid = 0x02;
16440 16599
@@ -16445,6 +16604,7 @@ static int patch_alc662(struct hda_codec *codec)
16445 if (!spec->loopback.amplist) 16604 if (!spec->loopback.amplist)
16446 spec->loopback.amplist = alc662_loopbacks; 16605 spec->loopback.amplist = alc662_loopbacks;
16447#endif 16606#endif
16607 codec->proc_widget_hook = print_realtek_coef;
16448 16608
16449 return 0; 16609 return 0;
16450} 16610}
@@ -16452,7 +16612,7 @@ static int patch_alc662(struct hda_codec *codec)
16452/* 16612/*
16453 * patch entries 16613 * patch entries
16454 */ 16614 */
16455struct hda_codec_preset snd_hda_preset_realtek[] = { 16615static struct hda_codec_preset snd_hda_preset_realtek[] = {
16456 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, 16616 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16457 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, 16617 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16458 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, 16618 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
@@ -16484,3 +16644,26 @@ struct hda_codec_preset snd_hda_preset_realtek[] = {
16484 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 }, 16644 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16485 {} /* terminator */ 16645 {} /* terminator */
16486}; 16646};
16647
16648MODULE_ALIAS("snd-hda-codec-id:10ec*");
16649
16650MODULE_LICENSE("GPL");
16651MODULE_DESCRIPTION("Realtek HD-audio codec");
16652
16653static struct hda_codec_preset_list realtek_list = {
16654 .preset = snd_hda_preset_realtek,
16655 .owner = THIS_MODULE,
16656};
16657
16658static int __init patch_realtek_init(void)
16659{
16660 return snd_hda_add_codec_preset(&realtek_list);
16661}
16662
16663static void __exit patch_realtek_exit(void)
16664{
16665 snd_hda_delete_codec_preset(&realtek_list);
16666}
16667
16668module_init(patch_realtek_init)
16669module_exit(patch_realtek_exit)
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index 9332b63e406c..43b436c5d01b 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -28,7 +28,6 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_patch.h"
32 31
33/* si3054 verbs */ 32/* si3054 verbs */
34#define SI3054_VERB_READ_NODE 0x900 33#define SI3054_VERB_READ_NODE 0x900
@@ -283,7 +282,7 @@ static int patch_si3054(struct hda_codec *codec)
283/* 282/*
284 * patch entries 283 * patch entries
285 */ 284 */
286struct hda_codec_preset snd_hda_preset_si3054[] = { 285static struct hda_codec_preset snd_hda_preset_si3054[] = {
287 { .id = 0x163c3055, .name = "Si3054", .patch = patch_si3054 }, 286 { .id = 0x163c3055, .name = "Si3054", .patch = patch_si3054 },
288 { .id = 0x163c3155, .name = "Si3054", .patch = patch_si3054 }, 287 { .id = 0x163c3155, .name = "Si3054", .patch = patch_si3054 },
289 { .id = 0x11c13026, .name = "Si3054", .patch = patch_si3054 }, 288 { .id = 0x11c13026, .name = "Si3054", .patch = patch_si3054 },
@@ -301,3 +300,35 @@ struct hda_codec_preset snd_hda_preset_si3054[] = {
301 {} 300 {}
302}; 301};
303 302
303MODULE_ALIAS("snd-hda-codec-id:163c3055");
304MODULE_ALIAS("snd-hda-codec-id:163c3155");
305MODULE_ALIAS("snd-hda-codec-id:11c13026");
306MODULE_ALIAS("snd-hda-codec-id:11c13055");
307MODULE_ALIAS("snd-hda-codec-id:11c13155");
308MODULE_ALIAS("snd-hda-codec-id:10573055");
309MODULE_ALIAS("snd-hda-codec-id:10573057");
310MODULE_ALIAS("snd-hda-codec-id:10573155");
311MODULE_ALIAS("snd-hda-codec-id:11063288");
312MODULE_ALIAS("snd-hda-codec-id:15433155");
313MODULE_ALIAS("snd-hda-codec-id:18540018");
314
315MODULE_LICENSE("GPL");
316MODULE_DESCRIPTION("Si3054 HD-audio modem codec");
317
318static struct hda_codec_preset_list si3054_list = {
319 .preset = snd_hda_preset_si3054,
320 .owner = THIS_MODULE,
321};
322
323static int __init patch_si3054_init(void)
324{
325 return snd_hda_add_codec_preset(&si3054_list);
326}
327
328static void __exit patch_si3054_exit(void)
329{
330 snd_hda_delete_codec_preset(&si3054_list);
331}
332
333module_init(patch_si3054_init)
334module_exit(patch_si3054_exit)
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index b77f330d2650..35b83dc6e19e 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -30,17 +30,17 @@
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <sound/core.h> 31#include <sound/core.h>
32#include <sound/asoundef.h> 32#include <sound/asoundef.h>
33#include <sound/jack.h>
33#include "hda_codec.h" 34#include "hda_codec.h"
34#include "hda_local.h" 35#include "hda_local.h"
35#include "hda_patch.h"
36#include "hda_beep.h" 36#include "hda_beep.h"
37 37
38#define NUM_CONTROL_ALLOC 32 38enum {
39 39 STAC_VREF_EVENT = 1,
40#define STAC_VREF_EVENT 0x00 40 STAC_INSERT_EVENT,
41#define STAC_INSERT_EVENT 0x10 41 STAC_PWR_EVENT,
42#define STAC_PWR_EVENT 0x20 42 STAC_HP_EVENT,
43#define STAC_HP_EVENT 0x30 43};
44 44
45enum { 45enum {
46 STAC_REF, 46 STAC_REF,
@@ -137,6 +137,19 @@ enum {
137 STAC_927X_MODELS 137 STAC_927X_MODELS
138}; 138};
139 139
140struct sigmatel_event {
141 hda_nid_t nid;
142 unsigned char type;
143 unsigned char tag;
144 int data;
145};
146
147struct sigmatel_jack {
148 hda_nid_t nid;
149 int type;
150 struct snd_jack *jack;
151};
152
140struct sigmatel_spec { 153struct sigmatel_spec {
141 struct snd_kcontrol_new *mixers[4]; 154 struct snd_kcontrol_new *mixers[4];
142 unsigned int num_mixers; 155 unsigned int num_mixers;
@@ -144,8 +157,6 @@ struct sigmatel_spec {
144 int board_config; 157 int board_config;
145 unsigned int eapd_switch: 1; 158 unsigned int eapd_switch: 1;
146 unsigned int surr_switch: 1; 159 unsigned int surr_switch: 1;
147 unsigned int line_switch: 1;
148 unsigned int mic_switch: 1;
149 unsigned int alt_switch: 1; 160 unsigned int alt_switch: 1;
150 unsigned int hp_detect: 1; 161 unsigned int hp_detect: 1;
151 unsigned int spdif_mute: 1; 162 unsigned int spdif_mute: 1;
@@ -170,12 +181,20 @@ struct sigmatel_spec {
170 hda_nid_t *pwr_nids; 181 hda_nid_t *pwr_nids;
171 hda_nid_t *dac_list; 182 hda_nid_t *dac_list;
172 183
184 /* jack detection */
185 struct snd_array jacks;
186
187 /* events */
188 struct snd_array events;
189
173 /* playback */ 190 /* playback */
174 struct hda_input_mux *mono_mux; 191 struct hda_input_mux *mono_mux;
175 struct hda_input_mux *amp_mux; 192 struct hda_input_mux *amp_mux;
176 unsigned int cur_mmux; 193 unsigned int cur_mmux;
177 struct hda_multi_out multiout; 194 struct hda_multi_out multiout;
178 hda_nid_t dac_nids[5]; 195 hda_nid_t dac_nids[5];
196 hda_nid_t hp_dacs[5];
197 hda_nid_t speaker_dacs[5];
179 198
180 /* capture */ 199 /* capture */
181 hda_nid_t *adc_nids; 200 hda_nid_t *adc_nids;
@@ -199,7 +218,6 @@ struct sigmatel_spec {
199 hda_nid_t *pin_nids; 218 hda_nid_t *pin_nids;
200 unsigned int num_pins; 219 unsigned int num_pins;
201 unsigned int *pin_configs; 220 unsigned int *pin_configs;
202 unsigned int *bios_pin_configs;
203 221
204 /* codec specific stuff */ 222 /* codec specific stuff */
205 struct hda_verb *init; 223 struct hda_verb *init;
@@ -220,15 +238,16 @@ struct sigmatel_spec {
220 /* i/o switches */ 238 /* i/o switches */
221 unsigned int io_switch[2]; 239 unsigned int io_switch[2];
222 unsigned int clfe_swap; 240 unsigned int clfe_swap;
223 unsigned int hp_switch; /* NID of HP as line-out */ 241 hda_nid_t line_switch; /* shared line-in for input and output */
242 hda_nid_t mic_switch; /* shared mic-in for input and output */
243 hda_nid_t hp_switch; /* NID of HP as line-out */
224 unsigned int aloopback; 244 unsigned int aloopback;
225 245
226 struct hda_pcm pcm_rec[2]; /* PCM information */ 246 struct hda_pcm pcm_rec[2]; /* PCM information */
227 247
228 /* dynamic controls and input_mux */ 248 /* dynamic controls and input_mux */
229 struct auto_pin_cfg autocfg; 249 struct auto_pin_cfg autocfg;
230 unsigned int num_kctl_alloc, num_kctl_used; 250 struct snd_array kctls;
231 struct snd_kcontrol_new *kctl_alloc;
232 struct hda_input_mux private_dimux; 251 struct hda_input_mux private_dimux;
233 struct hda_input_mux private_imux; 252 struct hda_input_mux private_imux;
234 struct hda_input_mux private_smux; 253 struct hda_input_mux private_smux;
@@ -272,9 +291,6 @@ static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
272}; 291};
273 292
274#define STAC92HD73_DAC_COUNT 5 293#define STAC92HD73_DAC_COUNT 5
275static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
276 0x15, 0x16, 0x17, 0x18, 0x19,
277};
278 294
279static hda_nid_t stac92hd73xx_mux_nids[4] = { 295static hda_nid_t stac92hd73xx_mux_nids[4] = {
280 0x28, 0x29, 0x2a, 0x2b, 296 0x28, 0x29, 0x2a, 0x2b,
@@ -293,11 +309,7 @@ static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
293 0x11, 0x12, 0 309 0x11, 0x12, 0
294}; 310};
295 311
296#define STAC92HD81_DAC_COUNT 2
297#define STAC92HD83_DAC_COUNT 3 312#define STAC92HD83_DAC_COUNT 3
298static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
299 0x13, 0x14, 0x22,
300};
301 313
302static hda_nid_t stac92hd83xxx_dmux_nids[2] = { 314static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
303 0x17, 0x18, 315 0x17, 0x18,
@@ -339,10 +351,6 @@ static hda_nid_t stac92hd71bxx_smux_nids[2] = {
339 0x24, 0x25, 351 0x24, 0x25,
340}; 352};
341 353
342static hda_nid_t stac92hd71bxx_dac_nids[1] = {
343 0x10, /*0x11, */
344};
345
346#define STAC92HD71BXX_NUM_DMICS 2 354#define STAC92HD71BXX_NUM_DMICS 2
347static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = { 355static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
348 0x18, 0x19, 0 356 0x18, 0x19, 0
@@ -574,12 +582,12 @@ static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
574 else 582 else
575 nid = codec->slave_dig_outs[smux_idx - 1]; 583 nid = codec->slave_dig_outs[smux_idx - 1];
576 if (spec->cur_smux[smux_idx] == smux->num_items - 1) 584 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
577 val = AMP_OUT_MUTE; 585 val = HDA_AMP_MUTE;
578 else 586 else
579 val = AMP_OUT_UNMUTE; 587 val = 0;
580 /* un/mute SPDIF out */ 588 /* un/mute SPDIF out */
581 snd_hda_codec_write_cache(codec, nid, 0, 589 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
582 AC_VERB_SET_AMP_GAIN_MUTE, val); 590 HDA_AMP_MUTE, val);
583 } 591 }
584 return 0; 592 return 0;
585} 593}
@@ -744,10 +752,6 @@ static struct hda_verb stac9200_eapd_init[] = {
744static struct hda_verb stac92hd73xx_6ch_core_init[] = { 752static struct hda_verb stac92hd73xx_6ch_core_init[] = {
745 /* set master volume and direct control */ 753 /* set master volume and direct control */
746 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 754 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
747 /* setup audio connections */
748 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
749 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
750 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
751 /* setup adcs to point to mixer */ 755 /* setup adcs to point to mixer */
752 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b}, 756 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
753 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b}, 757 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
@@ -766,10 +770,6 @@ static struct hda_verb dell_eq_core_init[] = {
766 /* set master volume to max value without distortion 770 /* set master volume to max value without distortion
767 * and direct control */ 771 * and direct control */
768 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec}, 772 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
769 /* setup audio connections */
770 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
771 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
772 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
773 /* setup adcs to point to mixer */ 773 /* setup adcs to point to mixer */
774 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b}, 774 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
775 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b}, 775 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
@@ -783,10 +783,6 @@ static struct hda_verb dell_eq_core_init[] = {
783 783
784static struct hda_verb dell_m6_core_init[] = { 784static struct hda_verb dell_m6_core_init[] = {
785 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 785 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
786 /* setup audio connections */
787 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
788 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
789 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
790 /* setup adcs to point to mixer */ 786 /* setup adcs to point to mixer */
791 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b}, 787 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
792 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b}, 788 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
@@ -801,13 +797,6 @@ static struct hda_verb dell_m6_core_init[] = {
801static struct hda_verb stac92hd73xx_8ch_core_init[] = { 797static struct hda_verb stac92hd73xx_8ch_core_init[] = {
802 /* set master volume and direct control */ 798 /* set master volume and direct control */
803 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 799 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
804 /* setup audio connections */
805 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
806 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
807 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
808 /* connect hp ports to dac3 */
809 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
810 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
811 /* setup adcs to point to mixer */ 800 /* setup adcs to point to mixer */
812 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b}, 801 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
813 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b}, 802 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
@@ -825,15 +814,8 @@ static struct hda_verb stac92hd73xx_8ch_core_init[] = {
825static struct hda_verb stac92hd73xx_10ch_core_init[] = { 814static struct hda_verb stac92hd73xx_10ch_core_init[] = {
826 /* set master volume and direct control */ 815 /* set master volume and direct control */
827 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 816 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
828 /* setup audio connections */
829 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
830 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
831 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
832 /* dac3 is connected to import3 mux */ 817 /* dac3 is connected to import3 mux */
833 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f}, 818 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
834 /* connect hp ports to dac4 */
835 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
836 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
837 /* setup adcs to point to mixer */ 819 /* setup adcs to point to mixer */
838 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b}, 820 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
839 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b}, 821 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
@@ -865,8 +847,6 @@ static struct hda_verb stac92hd83xxx_core_init[] = {
865static struct hda_verb stac92hd71bxx_core_init[] = { 847static struct hda_verb stac92hd71bxx_core_init[] = {
866 /* set master volume and direct control */ 848 /* set master volume and direct control */
867 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 849 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
868 /* connect headphone jack to dac1 */
869 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
870 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */ 850 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
871 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 851 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
872 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 852 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -886,8 +866,6 @@ static struct hda_verb stac92hd71bxx_analog_core_init[] = {
886 866
887 /* set master volume and direct control */ 867 /* set master volume and direct control */
888 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 868 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
889 /* connect headphone jack to dac1 */
890 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
891 /* unmute right and left channels for nodes 0x0a, 0xd */ 869 /* unmute right and left channels for nodes 0x0a, 0xd */
892 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 870 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
893 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 871 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -1087,21 +1065,21 @@ static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1087 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT), 1065 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1088 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT), 1066 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1089 1067
1090 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT), 1068 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1091 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT), 1069 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
1092 1070
1093 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT), 1071 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1094 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT), 1072 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
1095 1073
1096 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT), 1074 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1097 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT), 1075 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
1098 1076
1099 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT), 1077 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1100 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT), 1078 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
1101 1079
1102 /* 1080 /*
1103 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT), 1081 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1104 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT), 1082 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
1105 */ 1083 */
1106 { } /* end */ 1084 { } /* end */
1107}; 1085};
@@ -1240,9 +1218,14 @@ static const char *slave_sws[] = {
1240 NULL 1218 NULL
1241}; 1219};
1242 1220
1221static void stac92xx_free_kctls(struct hda_codec *codec);
1222static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1223
1243static int stac92xx_build_controls(struct hda_codec *codec) 1224static int stac92xx_build_controls(struct hda_codec *codec)
1244{ 1225{
1245 struct sigmatel_spec *spec = codec->spec; 1226 struct sigmatel_spec *spec = codec->spec;
1227 struct auto_pin_cfg *cfg = &spec->autocfg;
1228 hda_nid_t nid;
1246 int err; 1229 int err;
1247 int i; 1230 int i;
1248 1231
@@ -1257,7 +1240,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1257 } 1240 }
1258 if (spec->num_dmuxes > 0) { 1241 if (spec->num_dmuxes > 0) {
1259 stac_dmux_mixer.count = spec->num_dmuxes; 1242 stac_dmux_mixer.count = spec->num_dmuxes;
1260 err = snd_ctl_add(codec->bus->card, 1243 err = snd_hda_ctl_add(codec,
1261 snd_ctl_new1(&stac_dmux_mixer, codec)); 1244 snd_ctl_new1(&stac_dmux_mixer, codec));
1262 if (err < 0) 1245 if (err < 0)
1263 return err; 1246 return err;
@@ -1273,7 +1256,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1273 spec->spdif_mute = 1; 1256 spec->spdif_mute = 1;
1274 } 1257 }
1275 stac_smux_mixer.count = spec->num_smuxes; 1258 stac_smux_mixer.count = spec->num_smuxes;
1276 err = snd_ctl_add(codec->bus->card, 1259 err = snd_hda_ctl_add(codec,
1277 snd_ctl_new1(&stac_smux_mixer, codec)); 1260 snd_ctl_new1(&stac_smux_mixer, codec));
1278 if (err < 0) 1261 if (err < 0)
1279 return err; 1262 return err;
@@ -1312,6 +1295,37 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1312 return err; 1295 return err;
1313 } 1296 }
1314 1297
1298 stac92xx_free_kctls(codec); /* no longer needed */
1299
1300 /* create jack input elements */
1301 if (spec->hp_detect) {
1302 for (i = 0; i < cfg->hp_outs; i++) {
1303 int type = SND_JACK_HEADPHONE;
1304 nid = cfg->hp_pins[i];
1305 /* jack detection */
1306 if (cfg->hp_outs == i)
1307 type |= SND_JACK_LINEOUT;
1308 err = stac92xx_add_jack(codec, nid, type);
1309 if (err < 0)
1310 return err;
1311 }
1312 }
1313 for (i = 0; i < cfg->line_outs; i++) {
1314 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1315 SND_JACK_LINEOUT);
1316 if (err < 0)
1317 return err;
1318 }
1319 for (i = 0; i < AUTO_PIN_LAST; i++) {
1320 nid = cfg->input_pins[i];
1321 if (nid) {
1322 err = stac92xx_add_jack(codec, nid,
1323 SND_JACK_MICROPHONE);
1324 if (err < 0)
1325 return err;
1326 }
1327 }
1328
1315 return 0; 1329 return 0;
1316} 1330}
1317 1331
@@ -1720,6 +1734,8 @@ static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1720 "HP dv5", STAC_HP_M4), 1734 "HP dv5", STAC_HP_M4),
1721 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4, 1735 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1722 "HP dv7", STAC_HP_M4), 1736 "HP dv7", STAC_HP_M4),
1737 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fc,
1738 "HP dv7", STAC_HP_M4),
1723 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a, 1739 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1724 "unknown HP", STAC_HP_M4), 1740 "unknown HP", STAC_HP_M4),
1725 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233, 1741 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
@@ -2203,12 +2219,11 @@ static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2203 int i; 2219 int i;
2204 struct sigmatel_spec *spec = codec->spec; 2220 struct sigmatel_spec *spec = codec->spec;
2205 2221
2206 if (! spec->bios_pin_configs) { 2222 kfree(spec->pin_configs);
2207 spec->bios_pin_configs = kcalloc(spec->num_pins, 2223 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2208 sizeof(*spec->bios_pin_configs), GFP_KERNEL); 2224 GFP_KERNEL);
2209 if (! spec->bios_pin_configs) 2225 if (!spec->pin_configs)
2210 return -ENOMEM; 2226 return -ENOMEM;
2211 }
2212 2227
2213 for (i = 0; i < spec->num_pins; i++) { 2228 for (i = 0; i < spec->num_pins; i++) {
2214 hda_nid_t nid = spec->pin_nids[i]; 2229 hda_nid_t nid = spec->pin_nids[i];
@@ -2218,7 +2233,7 @@ static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2218 AC_VERB_GET_CONFIG_DEFAULT, 0x00); 2233 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2219 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n", 2234 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2220 nid, pin_cfg); 2235 nid, pin_cfg);
2221 spec->bios_pin_configs[i] = pin_cfg; 2236 spec->pin_configs[i] = pin_cfg;
2222 } 2237 }
2223 2238
2224 return 0; 2239 return 0;
@@ -2260,6 +2275,39 @@ static void stac92xx_set_config_regs(struct hda_codec *codec)
2260 spec->pin_configs[i]); 2275 spec->pin_configs[i]);
2261} 2276}
2262 2277
2278static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2279{
2280 struct sigmatel_spec *spec = codec->spec;
2281
2282 if (!pins)
2283 return stac92xx_save_bios_config_regs(codec);
2284
2285 kfree(spec->pin_configs);
2286 spec->pin_configs = kmemdup(pins,
2287 spec->num_pins * sizeof(*pins),
2288 GFP_KERNEL);
2289 if (!spec->pin_configs)
2290 return -ENOMEM;
2291
2292 stac92xx_set_config_regs(codec);
2293 return 0;
2294}
2295
2296static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2297 unsigned int cfg)
2298{
2299 struct sigmatel_spec *spec = codec->spec;
2300 int i;
2301
2302 for (i = 0; i < spec->num_pins; i++) {
2303 if (spec->pin_nids[i] == nid) {
2304 spec->pin_configs[i] = cfg;
2305 stac92xx_set_config_reg(codec, nid, cfg);
2306 break;
2307 }
2308 }
2309}
2310
2263/* 2311/*
2264 * Analog playback callbacks 2312 * Analog playback callbacks
2265 */ 2313 */
@@ -2337,7 +2385,7 @@ static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2337 2385
2338 if (spec->powerdown_adcs) { 2386 if (spec->powerdown_adcs) {
2339 msleep(40); 2387 msleep(40);
2340 snd_hda_codec_write_cache(codec, nid, 0, 2388 snd_hda_codec_write(codec, nid, 0,
2341 AC_VERB_SET_POWER_STATE, AC_PWRST_D0); 2389 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2342 } 2390 }
2343 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); 2391 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
@@ -2353,7 +2401,7 @@ static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2353 2401
2354 snd_hda_codec_cleanup_stream(codec, nid); 2402 snd_hda_codec_cleanup_stream(codec, nid);
2355 if (spec->powerdown_adcs) 2403 if (spec->powerdown_adcs)
2356 snd_hda_codec_write_cache(codec, nid, 0, 2404 snd_hda_codec_write(codec, nid, 0,
2357 AC_VERB_SET_POWER_STATE, AC_PWRST_D3); 2405 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2358 return 0; 2406 return 0;
2359} 2407}
@@ -2485,6 +2533,9 @@ static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2485 return 0; 2533 return 0;
2486} 2534}
2487 2535
2536static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2537 unsigned char type);
2538
2488static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol, 2539static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2489 struct snd_ctl_elem_value *ucontrol) 2540 struct snd_ctl_elem_value *ucontrol)
2490{ 2541{
@@ -2497,7 +2548,7 @@ static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2497 /* check to be sure that the ports are upto date with 2548 /* check to be sure that the ports are upto date with
2498 * switch changes 2549 * switch changes
2499 */ 2550 */
2500 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 2551 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
2501 2552
2502 return 1; 2553 return 1;
2503} 2554}
@@ -2537,7 +2588,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
2537 * appropriately according to the pin direction 2588 * appropriately according to the pin direction
2538 */ 2589 */
2539 if (spec->hp_detect) 2590 if (spec->hp_detect)
2540 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 2591 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
2541 2592
2542 return 1; 2593 return 1;
2543} 2594}
@@ -2632,28 +2683,16 @@ static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2632{ 2683{
2633 struct snd_kcontrol_new *knew; 2684 struct snd_kcontrol_new *knew;
2634 2685
2635 if (spec->num_kctl_used >= spec->num_kctl_alloc) { 2686 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2636 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC; 2687 knew = snd_array_new(&spec->kctls);
2637 2688 if (!knew)
2638 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */ 2689 return -ENOMEM;
2639 if (! knew)
2640 return -ENOMEM;
2641 if (spec->kctl_alloc) {
2642 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2643 kfree(spec->kctl_alloc);
2644 }
2645 spec->kctl_alloc = knew;
2646 spec->num_kctl_alloc = num;
2647 }
2648
2649 knew = &spec->kctl_alloc[spec->num_kctl_used];
2650 *knew = *ktemp; 2690 *knew = *ktemp;
2651 knew->index = idx; 2691 knew->index = idx;
2652 knew->name = kstrdup(name, GFP_KERNEL); 2692 knew->name = kstrdup(name, GFP_KERNEL);
2653 if (!knew->name) 2693 if (!knew->name)
2654 return -ENOMEM; 2694 return -ENOMEM;
2655 knew->private_value = val; 2695 knew->private_value = val;
2656 spec->num_kctl_used++;
2657 return 0; 2696 return 0;
2658} 2697}
2659 2698
@@ -2674,70 +2713,53 @@ static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2674 return stac92xx_add_control_idx(spec, type, 0, name, val); 2713 return stac92xx_add_control_idx(spec, type, 0, name, val);
2675} 2714}
2676 2715
2677/* flag inputs as additional dynamic lineouts */ 2716/* check whether the line-input can be used as line-out */
2678static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg) 2717static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2679{ 2718{
2680 struct sigmatel_spec *spec = codec->spec; 2719 struct sigmatel_spec *spec = codec->spec;
2681 unsigned int wcaps, wtype; 2720 struct auto_pin_cfg *cfg = &spec->autocfg;
2682 int i, num_dacs = 0; 2721 hda_nid_t nid;
2683 2722 unsigned int pincap;
2684 /* use the wcaps cache to count all DACs available for line-outs */
2685 for (i = 0; i < codec->num_nodes; i++) {
2686 wcaps = codec->wcaps[i];
2687 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2688 2723
2689 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) 2724 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2690 num_dacs++; 2725 return 0;
2691 } 2726 nid = cfg->input_pins[AUTO_PIN_LINE];
2727 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2728 if (pincap & AC_PINCAP_OUT)
2729 return nid;
2730 return 0;
2731}
2692 2732
2693 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs); 2733/* check whether the mic-input can be used as line-out */
2694 2734static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2695 switch (cfg->line_outs) { 2735{
2696 case 3: 2736 struct sigmatel_spec *spec = codec->spec;
2697 /* add line-in as side */ 2737 struct auto_pin_cfg *cfg = &spec->autocfg;
2698 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) { 2738 unsigned int def_conf, pincap;
2699 cfg->line_out_pins[cfg->line_outs] = 2739 unsigned int mic_pin;
2700 cfg->input_pins[AUTO_PIN_LINE]; 2740
2701 spec->line_switch = 1; 2741 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2702 cfg->line_outs++; 2742 return 0;
2703 } 2743 mic_pin = AUTO_PIN_MIC;
2704 break; 2744 for (;;) {
2705 case 2: 2745 hda_nid_t nid = cfg->input_pins[mic_pin];
2706 /* add line-in as clfe and mic as side */ 2746 def_conf = snd_hda_codec_read(codec, nid, 0,
2707 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) { 2747 AC_VERB_GET_CONFIG_DEFAULT, 0);
2708 cfg->line_out_pins[cfg->line_outs] = 2748 /* some laptops have an internal analog microphone
2709 cfg->input_pins[AUTO_PIN_LINE]; 2749 * which can't be used as a output */
2710 spec->line_switch = 1; 2750 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2711 cfg->line_outs++; 2751 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2712 } 2752 if (pincap & AC_PINCAP_OUT)
2713 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) { 2753 return nid;
2714 cfg->line_out_pins[cfg->line_outs] =
2715 cfg->input_pins[AUTO_PIN_MIC];
2716 spec->mic_switch = 1;
2717 cfg->line_outs++;
2718 }
2719 break;
2720 case 1:
2721 /* add line-in as surr and mic as clfe */
2722 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
2723 cfg->line_out_pins[cfg->line_outs] =
2724 cfg->input_pins[AUTO_PIN_LINE];
2725 spec->line_switch = 1;
2726 cfg->line_outs++;
2727 }
2728 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
2729 cfg->line_out_pins[cfg->line_outs] =
2730 cfg->input_pins[AUTO_PIN_MIC];
2731 spec->mic_switch = 1;
2732 cfg->line_outs++;
2733 } 2754 }
2734 break; 2755 if (mic_pin == AUTO_PIN_MIC)
2756 mic_pin = AUTO_PIN_FRONT_MIC;
2757 else
2758 break;
2735 } 2759 }
2736
2737 return 0; 2760 return 0;
2738} 2761}
2739 2762
2740
2741static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid) 2763static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2742{ 2764{
2743 int i; 2765 int i;
@@ -2750,6 +2772,52 @@ static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2750 return 0; 2772 return 0;
2751} 2773}
2752 2774
2775static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2776{
2777 int i;
2778 if (is_in_dac_nids(spec, nid))
2779 return 1;
2780 for (i = 0; i < spec->autocfg.hp_outs; i++)
2781 if (spec->hp_dacs[i] == nid)
2782 return 1;
2783 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2784 if (spec->speaker_dacs[i] == nid)
2785 return 1;
2786 return 0;
2787}
2788
2789static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2790{
2791 struct sigmatel_spec *spec = codec->spec;
2792 int j, conn_len;
2793 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2794 unsigned int wcaps, wtype;
2795
2796 conn_len = snd_hda_get_connections(codec, nid, conn,
2797 HDA_MAX_CONNECTIONS);
2798 for (j = 0; j < conn_len; j++) {
2799 wcaps = snd_hda_param_read(codec, conn[j],
2800 AC_PAR_AUDIO_WIDGET_CAP);
2801 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2802 /* we check only analog outputs */
2803 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2804 continue;
2805 /* if this route has a free DAC, assign it */
2806 if (!check_all_dac_nids(spec, conn[j])) {
2807 if (conn_len > 1) {
2808 /* select this DAC in the pin's input mux */
2809 snd_hda_codec_write_cache(codec, nid, 0,
2810 AC_VERB_SET_CONNECT_SEL, j);
2811 }
2812 return conn[j];
2813 }
2814 }
2815 return 0;
2816}
2817
2818static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2819static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2820
2753/* 2821/*
2754 * Fill in the dac_nids table from the parsed pin configuration 2822 * Fill in the dac_nids table from the parsed pin configuration
2755 * This function only works when every pin in line_out_pins[] 2823 * This function only works when every pin in line_out_pins[]
@@ -2757,31 +2825,17 @@ static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2757 * codecs are not connected directly to a DAC, such as the 9200 2825 * codecs are not connected directly to a DAC, such as the 9200
2758 * and 9202/925x. For those, dac_nids[] must be hard-coded. 2826 * and 9202/925x. For those, dac_nids[] must be hard-coded.
2759 */ 2827 */
2760static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, 2828static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2761 struct auto_pin_cfg *cfg)
2762{ 2829{
2763 struct sigmatel_spec *spec = codec->spec; 2830 struct sigmatel_spec *spec = codec->spec;
2764 int i, j, conn_len = 0; 2831 struct auto_pin_cfg *cfg = &spec->autocfg;
2765 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS]; 2832 int i;
2766 unsigned int wcaps, wtype; 2833 hda_nid_t nid, dac;
2767 2834
2768 for (i = 0; i < cfg->line_outs; i++) { 2835 for (i = 0; i < cfg->line_outs; i++) {
2769 nid = cfg->line_out_pins[i]; 2836 nid = cfg->line_out_pins[i];
2770 conn_len = snd_hda_get_connections(codec, nid, conn, 2837 dac = get_unassigned_dac(codec, nid);
2771 HDA_MAX_CONNECTIONS); 2838 if (!dac) {
2772 for (j = 0; j < conn_len; j++) {
2773 wcaps = snd_hda_param_read(codec, conn[j],
2774 AC_PAR_AUDIO_WIDGET_CAP);
2775 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2776 if (wtype != AC_WID_AUD_OUT ||
2777 (wcaps & AC_WCAP_DIGITAL))
2778 continue;
2779 /* conn[j] is a DAC routed to this line-out */
2780 if (!is_in_dac_nids(spec, conn[j]))
2781 break;
2782 }
2783
2784 if (j == conn_len) {
2785 if (spec->multiout.num_dacs > 0) { 2839 if (spec->multiout.num_dacs > 0) {
2786 /* we have already working output pins, 2840 /* we have already working output pins,
2787 * so let's drop the broken ones again 2841 * so let's drop the broken ones again
@@ -2795,24 +2849,64 @@ static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
2795 __func__, nid); 2849 __func__, nid);
2796 return -ENODEV; 2850 return -ENODEV;
2797 } 2851 }
2852 add_spec_dacs(spec, dac);
2853 }
2798 2854
2799 spec->multiout.dac_nids[i] = conn[j]; 2855 /* add line-in as output */
2800 spec->multiout.num_dacs++; 2856 nid = check_line_out_switch(codec);
2801 if (conn_len > 1) { 2857 if (nid) {
2802 /* select this DAC in the pin's input mux */ 2858 dac = get_unassigned_dac(codec, nid);
2803 snd_hda_codec_write_cache(codec, nid, 0, 2859 if (dac) {
2804 AC_VERB_SET_CONNECT_SEL, j); 2860 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2861 nid, cfg->line_outs);
2862 cfg->line_out_pins[cfg->line_outs] = nid;
2863 cfg->line_outs++;
2864 spec->line_switch = nid;
2865 add_spec_dacs(spec, dac);
2866 }
2867 }
2868 /* add mic as output */
2869 nid = check_mic_out_switch(codec);
2870 if (nid) {
2871 dac = get_unassigned_dac(codec, nid);
2872 if (dac) {
2873 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
2874 nid, cfg->line_outs);
2875 cfg->line_out_pins[cfg->line_outs] = nid;
2876 cfg->line_outs++;
2877 spec->mic_switch = nid;
2878 add_spec_dacs(spec, dac);
2879 }
2880 }
2805 2881
2882 for (i = 0; i < cfg->hp_outs; i++) {
2883 nid = cfg->hp_pins[i];
2884 dac = get_unassigned_dac(codec, nid);
2885 if (dac) {
2886 if (!spec->multiout.hp_nid)
2887 spec->multiout.hp_nid = dac;
2888 else
2889 add_spec_extra_dacs(spec, dac);
2806 } 2890 }
2891 spec->hp_dacs[i] = dac;
2892 }
2893
2894 for (i = 0; i < cfg->speaker_outs; i++) {
2895 nid = cfg->speaker_pins[i];
2896 dac = get_unassigned_dac(codec, nid);
2897 if (dac)
2898 add_spec_extra_dacs(spec, dac);
2899 spec->speaker_dacs[i] = dac;
2807 } 2900 }
2808 2901
2809 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", 2902 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2810 spec->multiout.num_dacs, 2903 spec->multiout.num_dacs,
2811 spec->multiout.dac_nids[0], 2904 spec->multiout.dac_nids[0],
2812 spec->multiout.dac_nids[1], 2905 spec->multiout.dac_nids[1],
2813 spec->multiout.dac_nids[2], 2906 spec->multiout.dac_nids[2],
2814 spec->multiout.dac_nids[3], 2907 spec->multiout.dac_nids[3],
2815 spec->multiout.dac_nids[4]); 2908 spec->multiout.dac_nids[4]);
2909
2816 return 0; 2910 return 0;
2817} 2911}
2818 2912
@@ -2837,9 +2931,7 @@ static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_
2837 2931
2838static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid) 2932static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2839{ 2933{
2840 if (!spec->multiout.hp_nid) 2934 if (spec->multiout.num_dacs > 4) {
2841 spec->multiout.hp_nid = nid;
2842 else if (spec->multiout.num_dacs > 4) {
2843 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid); 2935 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2844 return 1; 2936 return 1;
2845 } else { 2937 } else {
@@ -2849,35 +2941,47 @@ static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2849 return 0; 2941 return 0;
2850} 2942}
2851 2943
2852static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid) 2944static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2853{ 2945{
2854 if (is_in_dac_nids(spec, nid)) 2946 int i;
2855 return 1; 2947 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
2948 if (!spec->multiout.extra_out_nid[i]) {
2949 spec->multiout.extra_out_nid[i] = nid;
2950 return 0;
2951 }
2952 }
2953 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
2954 return 1;
2955}
2956
2957static int is_unique_dac(struct sigmatel_spec *spec, hda_nid_t nid)
2958{
2959 int i;
2960
2961 if (spec->autocfg.line_outs != 1)
2962 return 0;
2856 if (spec->multiout.hp_nid == nid) 2963 if (spec->multiout.hp_nid == nid)
2857 return 1; 2964 return 0;
2858 return 0; 2965 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
2966 if (spec->multiout.extra_out_nid[i] == nid)
2967 return 0;
2968 return 1;
2859} 2969}
2860 2970
2861/* add playback controls from the parsed DAC table */ 2971/* add playback controls from the parsed DAC table */
2862static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec, 2972static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2863 const struct auto_pin_cfg *cfg) 2973 const struct auto_pin_cfg *cfg)
2864{ 2974{
2975 struct sigmatel_spec *spec = codec->spec;
2865 static const char *chname[4] = { 2976 static const char *chname[4] = {
2866 "Front", "Surround", NULL /*CLFE*/, "Side" 2977 "Front", "Surround", NULL /*CLFE*/, "Side"
2867 }; 2978 };
2868 hda_nid_t nid = 0; 2979 hda_nid_t nid = 0;
2869 int i, err; 2980 int i, err;
2981 unsigned int wid_caps;
2870 2982
2871 struct sigmatel_spec *spec = codec->spec; 2983 for (i = 0; i < cfg->line_outs && spec->multiout.dac_nids[i]; i++) {
2872 unsigned int wid_caps, pincap;
2873
2874
2875 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
2876 if (!spec->multiout.dac_nids[i])
2877 continue;
2878
2879 nid = spec->multiout.dac_nids[i]; 2984 nid = spec->multiout.dac_nids[i];
2880
2881 if (i == 2) { 2985 if (i == 2) {
2882 /* Center/LFE */ 2986 /* Center/LFE */
2883 err = create_controls(spec, "Center", nid, 1); 2987 err = create_controls(spec, "Center", nid, 1);
@@ -2899,16 +3003,24 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2899 } 3003 }
2900 3004
2901 } else { 3005 } else {
2902 err = create_controls(spec, chname[i], nid, 3); 3006 const char *name = chname[i];
3007 /* if it's a single DAC, assign a better name */
3008 if (!i && is_unique_dac(spec, nid)) {
3009 switch (cfg->line_out_type) {
3010 case AUTO_PIN_HP_OUT:
3011 name = "Headphone";
3012 break;
3013 case AUTO_PIN_SPEAKER_OUT:
3014 name = "Speaker";
3015 break;
3016 }
3017 }
3018 err = create_controls(spec, name, nid, 3);
2903 if (err < 0) 3019 if (err < 0)
2904 return err; 3020 return err;
2905 } 3021 }
2906 } 3022 }
2907 3023
2908 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
2909 cfg->hp_outs == 1 && !spec->multiout.hp_nid)
2910 spec->multiout.hp_nid = nid;
2911
2912 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) { 3024 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
2913 err = stac92xx_add_control(spec, 3025 err = stac92xx_add_control(spec,
2914 STAC_CTL_WIDGET_HP_SWITCH, 3026 STAC_CTL_WIDGET_HP_SWITCH,
@@ -2919,45 +3031,19 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2919 } 3031 }
2920 3032
2921 if (spec->line_switch) { 3033 if (spec->line_switch) {
2922 nid = cfg->input_pins[AUTO_PIN_LINE]; 3034 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
2923 pincap = snd_hda_param_read(codec, nid, 3035 "Line In as Output Switch",
2924 AC_PAR_PIN_CAP); 3036 spec->line_switch << 8);
2925 if (pincap & AC_PINCAP_OUT) { 3037 if (err < 0)
2926 err = stac92xx_add_control(spec, 3038 return err;
2927 STAC_CTL_WIDGET_IO_SWITCH,
2928 "Line In as Output Switch", nid << 8);
2929 if (err < 0)
2930 return err;
2931 }
2932 } 3039 }
2933 3040
2934 if (spec->mic_switch) { 3041 if (spec->mic_switch) {
2935 unsigned int def_conf; 3042 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
2936 unsigned int mic_pin = AUTO_PIN_MIC; 3043 "Mic as Output Switch",
2937again: 3044 (spec->mic_switch << 8) | 1);
2938 nid = cfg->input_pins[mic_pin]; 3045 if (err < 0)
2939 def_conf = snd_hda_codec_read(codec, nid, 0, 3046 return err;
2940 AC_VERB_GET_CONFIG_DEFAULT, 0);
2941 /* some laptops have an internal analog microphone
2942 * which can't be used as a output */
2943 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2944 pincap = snd_hda_param_read(codec, nid,
2945 AC_PAR_PIN_CAP);
2946 if (pincap & AC_PINCAP_OUT) {
2947 err = stac92xx_add_control(spec,
2948 STAC_CTL_WIDGET_IO_SWITCH,
2949 "Mic as Output Switch", (nid << 8) | 1);
2950 nid = snd_hda_codec_read(codec, nid, 0,
2951 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2952 if (!check_in_dac_nids(spec, nid))
2953 add_spec_dacs(spec, nid);
2954 if (err < 0)
2955 return err;
2956 }
2957 } else if (mic_pin == AUTO_PIN_MIC) {
2958 mic_pin = AUTO_PIN_FRONT_MIC;
2959 goto again;
2960 }
2961 } 3047 }
2962 3048
2963 return 0; 3049 return 0;
@@ -2969,55 +3055,39 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2969{ 3055{
2970 struct sigmatel_spec *spec = codec->spec; 3056 struct sigmatel_spec *spec = codec->spec;
2971 hda_nid_t nid; 3057 hda_nid_t nid;
2972 int i, old_num_dacs, err; 3058 int i, err, nums;
2973 3059
2974 old_num_dacs = spec->multiout.num_dacs; 3060 nums = 0;
2975 for (i = 0; i < cfg->hp_outs; i++) { 3061 for (i = 0; i < cfg->hp_outs; i++) {
3062 static const char *pfxs[] = {
3063 "Headphone", "Headphone2", "Headphone3",
3064 };
2976 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]); 3065 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
2977 if (wid_caps & AC_WCAP_UNSOL_CAP) 3066 if (wid_caps & AC_WCAP_UNSOL_CAP)
2978 spec->hp_detect = 1; 3067 spec->hp_detect = 1;
2979 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0, 3068 if (nums >= ARRAY_SIZE(pfxs))
2980 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2981 if (check_in_dac_nids(spec, nid))
2982 nid = 0;
2983 if (! nid)
2984 continue; 3069 continue;
2985 add_spec_dacs(spec, nid); 3070 nid = spec->hp_dacs[i];
2986 } 3071 if (!nid)
2987 for (i = 0; i < cfg->speaker_outs; i++) {
2988 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
2989 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2990 if (check_in_dac_nids(spec, nid))
2991 nid = 0;
2992 if (! nid)
2993 continue; 3072 continue;
2994 add_spec_dacs(spec, nid); 3073 err = create_controls(spec, pfxs[nums++], nid, 3);
2995 } 3074 if (err < 0)
2996 for (i = 0; i < cfg->line_outs; i++) { 3075 return err;
2997 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
2998 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2999 if (check_in_dac_nids(spec, nid))
3000 nid = 0;
3001 if (! nid)
3002 continue;
3003 add_spec_dacs(spec, nid);
3004 } 3076 }
3005 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) { 3077 nums = 0;
3078 for (i = 0; i < cfg->speaker_outs; i++) {
3006 static const char *pfxs[] = { 3079 static const char *pfxs[] = {
3007 "Speaker", "External Speaker", "Speaker2", 3080 "Speaker", "External Speaker", "Speaker2",
3008 }; 3081 };
3009 err = create_controls(spec, pfxs[i - old_num_dacs], 3082 if (nums >= ARRAY_SIZE(pfxs))
3010 spec->multiout.dac_nids[i], 3); 3083 continue;
3011 if (err < 0) 3084 nid = spec->speaker_dacs[i];
3012 return err; 3085 if (!nid)
3013 } 3086 continue;
3014 if (spec->multiout.hp_nid) { 3087 err = create_controls(spec, pfxs[nums++], nid, 3);
3015 err = create_controls(spec, "Headphone",
3016 spec->multiout.hp_nid, 3);
3017 if (err < 0) 3088 if (err < 0)
3018 return err; 3089 return err;
3019 } 3090 }
3020
3021 return 0; 3091 return 0;
3022} 3092}
3023 3093
@@ -3355,7 +3425,6 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3355{ 3425{
3356 struct sigmatel_spec *spec = codec->spec; 3426 struct sigmatel_spec *spec = codec->spec;
3357 int err; 3427 int err;
3358 int hp_speaker_swap = 0;
3359 3428
3360 if ((err = snd_hda_parse_pin_def_config(codec, 3429 if ((err = snd_hda_parse_pin_def_config(codec,
3361 &spec->autocfg, 3430 &spec->autocfg,
@@ -3373,13 +3442,15 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3373 * speaker_outs so that the following routines can handle 3442 * speaker_outs so that the following routines can handle
3374 * HP pins as primary outputs. 3443 * HP pins as primary outputs.
3375 */ 3444 */
3445 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3376 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins, 3446 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3377 sizeof(spec->autocfg.line_out_pins)); 3447 sizeof(spec->autocfg.line_out_pins));
3378 spec->autocfg.speaker_outs = spec->autocfg.line_outs; 3448 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3379 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins, 3449 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3380 sizeof(spec->autocfg.hp_pins)); 3450 sizeof(spec->autocfg.hp_pins));
3381 spec->autocfg.line_outs = spec->autocfg.hp_outs; 3451 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3382 hp_speaker_swap = 1; 3452 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3453 spec->autocfg.hp_outs = 0;
3383 } 3454 }
3384 if (spec->autocfg.mono_out_pin) { 3455 if (spec->autocfg.mono_out_pin) {
3385 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) & 3456 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
@@ -3431,11 +3502,11 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3431 AC_PINCTL_OUT_EN); 3502 AC_PINCTL_OUT_EN);
3432 } 3503 }
3433 3504
3434 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0) 3505 if (!spec->multiout.num_dacs) {
3435 return err; 3506 err = stac92xx_auto_fill_dac_nids(codec);
3436 if (spec->multiout.num_dacs == 0) 3507 if (err < 0)
3437 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3438 return err; 3508 return err;
3509 }
3439 3510
3440 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg); 3511 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3441 3512
@@ -3473,19 +3544,6 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3473 } 3544 }
3474#endif 3545#endif
3475 3546
3476 if (hp_speaker_swap == 1) {
3477 /* Restore the hp_outs and line_outs */
3478 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3479 sizeof(spec->autocfg.line_out_pins));
3480 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3481 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3482 sizeof(spec->autocfg.speaker_pins));
3483 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3484 memset(spec->autocfg.speaker_pins, 0,
3485 sizeof(spec->autocfg.speaker_pins));
3486 spec->autocfg.speaker_outs = 0;
3487 }
3488
3489 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg); 3547 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3490 3548
3491 if (err < 0) 3549 if (err < 0)
@@ -3530,11 +3588,12 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3530 if (dig_in && spec->autocfg.dig_in_pin) 3588 if (dig_in && spec->autocfg.dig_in_pin)
3531 spec->dig_in_nid = dig_in; 3589 spec->dig_in_nid = dig_in;
3532 3590
3533 if (spec->kctl_alloc) 3591 if (spec->kctls.list)
3534 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 3592 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3535 3593
3536 spec->input_mux = &spec->private_imux; 3594 spec->input_mux = &spec->private_imux;
3537 spec->dinput_mux = &spec->private_dimux; 3595 if (!spec->dinput_mux)
3596 spec->dinput_mux = &spec->private_dimux;
3538 spec->sinput_mux = &spec->private_smux; 3597 spec->sinput_mux = &spec->private_smux;
3539 spec->mono_mux = &spec->private_mono_mux; 3598 spec->mono_mux = &spec->private_mono_mux;
3540 spec->amp_mux = &spec->private_amp_mux; 3599 spec->amp_mux = &spec->private_amp_mux;
@@ -3638,8 +3697,8 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
3638 if (spec->autocfg.dig_in_pin) 3697 if (spec->autocfg.dig_in_pin)
3639 spec->dig_in_nid = 0x04; 3698 spec->dig_in_nid = 0x04;
3640 3699
3641 if (spec->kctl_alloc) 3700 if (spec->kctls.list)
3642 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 3701 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3643 3702
3644 spec->input_mux = &spec->private_imux; 3703 spec->input_mux = &spec->private_imux;
3645 spec->dinput_mux = &spec->private_dimux; 3704 spec->dinput_mux = &spec->private_dimux;
@@ -3683,13 +3742,101 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3683 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */ 3742 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
3684} 3743}
3685 3744
3745static int stac92xx_add_jack(struct hda_codec *codec,
3746 hda_nid_t nid, int type)
3747{
3748#ifdef CONFIG_SND_JACK
3749 struct sigmatel_spec *spec = codec->spec;
3750 struct sigmatel_jack *jack;
3751 int def_conf = snd_hda_codec_read(codec, nid,
3752 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3753 int connectivity = get_defcfg_connect(def_conf);
3754 char name[32];
3755
3756 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3757 return 0;
3758
3759 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3760 jack = snd_array_new(&spec->jacks);
3761 if (!jack)
3762 return -ENOMEM;
3763 jack->nid = nid;
3764 jack->type = type;
3765
3766 sprintf(name, "%s at %s %s Jack",
3767 snd_hda_get_jack_type(def_conf),
3768 snd_hda_get_jack_connectivity(def_conf),
3769 snd_hda_get_jack_location(def_conf));
3770
3771 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
3772#else
3773 return 0;
3774#endif
3775}
3776
3777static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3778 unsigned char type, int data)
3779{
3780 struct sigmatel_event *event;
3781
3782 snd_array_init(&spec->events, sizeof(*event), 32);
3783 event = snd_array_new(&spec->events);
3784 if (!event)
3785 return -ENOMEM;
3786 event->nid = nid;
3787 event->type = type;
3788 event->tag = spec->events.used;
3789 event->data = data;
3790
3791 return event->tag;
3792}
3793
3794static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3795 hda_nid_t nid, unsigned char type)
3796{
3797 struct sigmatel_spec *spec = codec->spec;
3798 struct sigmatel_event *event = spec->events.list;
3799 int i;
3800
3801 for (i = 0; i < spec->events.used; i++, event++) {
3802 if (event->nid == nid && event->type == type)
3803 return event;
3804 }
3805 return NULL;
3806}
3807
3808static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3809 unsigned char tag)
3810{
3811 struct sigmatel_spec *spec = codec->spec;
3812 struct sigmatel_event *event = spec->events.list;
3813 int i;
3814
3815 for (i = 0; i < spec->events.used; i++, event++) {
3816 if (event->tag == tag)
3817 return event;
3818 }
3819 return NULL;
3820}
3821
3686static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid, 3822static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
3687 unsigned int event) 3823 unsigned int type)
3688{ 3824{
3689 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) 3825 struct sigmatel_event *event;
3690 snd_hda_codec_write_cache(codec, nid, 0, 3826 int tag;
3691 AC_VERB_SET_UNSOLICITED_ENABLE, 3827
3692 (AC_USRSP_EN | event)); 3828 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3829 return;
3830 event = stac_get_event(codec, nid, type);
3831 if (event)
3832 tag = event->tag;
3833 else
3834 tag = stac_add_event(codec->spec, nid, type, 0);
3835 if (tag < 0)
3836 return;
3837 snd_hda_codec_write_cache(codec, nid, 0,
3838 AC_VERB_SET_UNSOLICITED_ENABLE,
3839 AC_USRSP_EN | tag);
3693} 3840}
3694 3841
3695static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid) 3842static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
@@ -3709,9 +3856,8 @@ static void stac92xx_power_down(struct hda_codec *codec)
3709 /* power down inactive DACs */ 3856 /* power down inactive DACs */
3710 hda_nid_t *dac; 3857 hda_nid_t *dac;
3711 for (dac = spec->dac_list; *dac; dac++) 3858 for (dac = spec->dac_list; *dac; dac++)
3712 if (!is_in_dac_nids(spec, *dac) && 3859 if (!check_all_dac_nids(spec, *dac))
3713 spec->multiout.hp_nid != *dac) 3860 snd_hda_codec_write(codec, *dac, 0,
3714 snd_hda_codec_write_cache(codec, *dac, 0,
3715 AC_VERB_SET_POWER_STATE, AC_PWRST_D3); 3861 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3716} 3862}
3717 3863
@@ -3730,7 +3876,7 @@ static int stac92xx_init(struct hda_codec *codec)
3730 /* power down adcs initially */ 3876 /* power down adcs initially */
3731 if (spec->powerdown_adcs) 3877 if (spec->powerdown_adcs)
3732 for (i = 0; i < spec->num_adcs; i++) 3878 for (i = 0; i < spec->num_adcs; i++)
3733 snd_hda_codec_write_cache(codec, 3879 snd_hda_codec_write(codec,
3734 spec->adc_nids[i], 0, 3880 spec->adc_nids[i], 0,
3735 AC_VERB_SET_POWER_STATE, AC_PWRST_D3); 3881 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3736 3882
@@ -3746,37 +3892,51 @@ static int stac92xx_init(struct hda_codec *codec)
3746 /* set up pins */ 3892 /* set up pins */
3747 if (spec->hp_detect) { 3893 if (spec->hp_detect) {
3748 /* Enable unsolicited responses on the HP widget */ 3894 /* Enable unsolicited responses on the HP widget */
3749 for (i = 0; i < cfg->hp_outs; i++) 3895 for (i = 0; i < cfg->hp_outs; i++) {
3750 enable_pin_detect(codec, cfg->hp_pins[i], 3896 hda_nid_t nid = cfg->hp_pins[i];
3751 STAC_HP_EVENT); 3897 enable_pin_detect(codec, nid, STAC_HP_EVENT);
3898 }
3752 /* force to enable the first line-out; the others are set up 3899 /* force to enable the first line-out; the others are set up
3753 * in unsol_event 3900 * in unsol_event
3754 */ 3901 */
3755 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0], 3902 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
3756 AC_PINCTL_OUT_EN); 3903 AC_PINCTL_OUT_EN);
3757 stac92xx_auto_init_hp_out(codec);
3758 /* fake event to set up pins */ 3904 /* fake event to set up pins */
3759 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 3905 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
3906 STAC_HP_EVENT);
3760 } else { 3907 } else {
3761 stac92xx_auto_init_multi_out(codec); 3908 stac92xx_auto_init_multi_out(codec);
3762 stac92xx_auto_init_hp_out(codec); 3909 stac92xx_auto_init_hp_out(codec);
3910 for (i = 0; i < cfg->hp_outs; i++)
3911 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
3763 } 3912 }
3764 for (i = 0; i < AUTO_PIN_LAST; i++) { 3913 for (i = 0; i < AUTO_PIN_LAST; i++) {
3765 hda_nid_t nid = cfg->input_pins[i]; 3914 hda_nid_t nid = cfg->input_pins[i];
3766 if (nid) { 3915 if (nid) {
3767 unsigned int pinctl; 3916 unsigned int pinctl, conf;
3768 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) { 3917 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3769 /* for mic pins, force to initialize */ 3918 /* for mic pins, force to initialize */
3770 pinctl = stac92xx_get_vref(codec, nid); 3919 pinctl = stac92xx_get_vref(codec, nid);
3920 pinctl |= AC_PINCTL_IN_EN;
3921 stac92xx_auto_set_pinctl(codec, nid, pinctl);
3771 } else { 3922 } else {
3772 pinctl = snd_hda_codec_read(codec, nid, 0, 3923 pinctl = snd_hda_codec_read(codec, nid, 0,
3773 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 3924 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3774 /* if PINCTL already set then skip */ 3925 /* if PINCTL already set then skip */
3775 if (pinctl & AC_PINCTL_IN_EN) 3926 if (!(pinctl & AC_PINCTL_IN_EN)) {
3776 continue; 3927 pinctl |= AC_PINCTL_IN_EN;
3928 stac92xx_auto_set_pinctl(codec, nid,
3929 pinctl);
3930 }
3931 }
3932 conf = snd_hda_codec_read(codec, nid, 0,
3933 AC_VERB_GET_CONFIG_DEFAULT, 0);
3934 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
3935 enable_pin_detect(codec, nid,
3936 STAC_INSERT_EVENT);
3937 stac_issue_unsol_event(codec, nid,
3938 STAC_INSERT_EVENT);
3777 } 3939 }
3778 pinctl |= AC_PINCTL_IN_EN;
3779 stac92xx_auto_set_pinctl(codec, nid, pinctl);
3780 } 3940 }
3781 } 3941 }
3782 for (i = 0; i < spec->num_dmics; i++) 3942 for (i = 0; i < spec->num_dmics; i++)
@@ -3791,9 +3951,14 @@ static int stac92xx_init(struct hda_codec *codec)
3791 for (i = 0; i < spec->num_pwrs; i++) { 3951 for (i = 0; i < spec->num_pwrs; i++) {
3792 hda_nid_t nid = spec->pwr_nids[i]; 3952 hda_nid_t nid = spec->pwr_nids[i];
3793 int pinctl, def_conf; 3953 int pinctl, def_conf;
3794 int event = STAC_PWR_EVENT;
3795 3954
3796 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect) 3955 /* power on when no jack detection is available */
3956 if (!spec->hp_detect) {
3957 stac_toggle_power_map(codec, nid, 1);
3958 continue;
3959 }
3960
3961 if (is_nid_hp_pin(cfg, nid))
3797 continue; /* already has an unsol event */ 3962 continue; /* already has an unsol event */
3798 3963
3799 pinctl = snd_hda_codec_read(codec, nid, 0, 3964 pinctl = snd_hda_codec_read(codec, nid, 0,
@@ -3802,8 +3967,10 @@ static int stac92xx_init(struct hda_codec *codec)
3802 * any attempts on powering down a input port cause the 3967 * any attempts on powering down a input port cause the
3803 * referenced VREF to act quirky. 3968 * referenced VREF to act quirky.
3804 */ 3969 */
3805 if (pinctl & AC_PINCTL_IN_EN) 3970 if (pinctl & AC_PINCTL_IN_EN) {
3971 stac_toggle_power_map(codec, nid, 1);
3806 continue; 3972 continue;
3973 }
3807 def_conf = snd_hda_codec_read(codec, nid, 0, 3974 def_conf = snd_hda_codec_read(codec, nid, 0,
3808 AC_VERB_GET_CONFIG_DEFAULT, 0); 3975 AC_VERB_GET_CONFIG_DEFAULT, 0);
3809 def_conf = get_defcfg_connect(def_conf); 3976 def_conf = get_defcfg_connect(def_conf);
@@ -3814,30 +3981,54 @@ static int stac92xx_init(struct hda_codec *codec)
3814 stac_toggle_power_map(codec, nid, 1); 3981 stac_toggle_power_map(codec, nid, 1);
3815 continue; 3982 continue;
3816 } 3983 }
3817 enable_pin_detect(codec, spec->pwr_nids[i], event | i); 3984 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) {
3818 codec->patch_ops.unsol_event(codec, (event | i) << 26); 3985 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
3986 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
3987 }
3819 } 3988 }
3820 if (spec->dac_list) 3989 if (spec->dac_list)
3821 stac92xx_power_down(codec); 3990 stac92xx_power_down(codec);
3822 return 0; 3991 return 0;
3823} 3992}
3824 3993
3994static void stac92xx_free_jacks(struct hda_codec *codec)
3995{
3996#ifdef CONFIG_SND_JACK
3997 /* free jack instances manually when clearing/reconfiguring */
3998 struct sigmatel_spec *spec = codec->spec;
3999 if (!codec->bus->shutdown && spec->jacks.list) {
4000 struct sigmatel_jack *jacks = spec->jacks.list;
4001 int i;
4002 for (i = 0; i < spec->jacks.used; i++)
4003 snd_device_free(codec->bus->card, &jacks[i].jack);
4004 }
4005 snd_array_free(&spec->jacks);
4006#endif
4007}
4008
4009static void stac92xx_free_kctls(struct hda_codec *codec)
4010{
4011 struct sigmatel_spec *spec = codec->spec;
4012
4013 if (spec->kctls.list) {
4014 struct snd_kcontrol_new *kctl = spec->kctls.list;
4015 int i;
4016 for (i = 0; i < spec->kctls.used; i++)
4017 kfree(kctl[i].name);
4018 }
4019 snd_array_free(&spec->kctls);
4020}
4021
3825static void stac92xx_free(struct hda_codec *codec) 4022static void stac92xx_free(struct hda_codec *codec)
3826{ 4023{
3827 struct sigmatel_spec *spec = codec->spec; 4024 struct sigmatel_spec *spec = codec->spec;
3828 int i;
3829 4025
3830 if (! spec) 4026 if (! spec)
3831 return; 4027 return;
3832 4028
3833 if (spec->kctl_alloc) { 4029 kfree(spec->pin_configs);
3834 for (i = 0; i < spec->num_kctl_used; i++) 4030 stac92xx_free_jacks(codec);
3835 kfree(spec->kctl_alloc[i].name); 4031 snd_array_free(&spec->events);
3836 kfree(spec->kctl_alloc);
3837 }
3838
3839 if (spec->bios_pin_configs)
3840 kfree(spec->bios_pin_configs);
3841 4032
3842 kfree(spec); 4033 kfree(spec);
3843 snd_hda_detach_beep_device(codec); 4034 snd_hda_detach_beep_device(codec);
@@ -3856,11 +4047,7 @@ static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
3856 * "xxx as Output" mixer switch 4047 * "xxx as Output" mixer switch
3857 */ 4048 */
3858 struct sigmatel_spec *spec = codec->spec; 4049 struct sigmatel_spec *spec = codec->spec;
3859 struct auto_pin_cfg *cfg = &spec->autocfg; 4050 if (nid == spec->line_switch || nid == spec->mic_switch)
3860 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
3861 spec->line_switch) ||
3862 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
3863 spec->mic_switch))
3864 return; 4051 return;
3865 } 4052 }
3866 4053
@@ -3884,20 +4071,13 @@ static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
3884 pin_ctl & ~flag); 4071 pin_ctl & ~flag);
3885} 4072}
3886 4073
3887static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid) 4074static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
3888{ 4075{
3889 if (!nid) 4076 if (!nid)
3890 return 0; 4077 return 0;
3891 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00) 4078 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
3892 & (1 << 31)) { 4079 & (1 << 31))
3893 unsigned int pinctl; 4080 return 1;
3894 pinctl = snd_hda_codec_read(codec, nid, 0,
3895 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3896 if (pinctl & AC_PINCTL_IN_EN)
3897 return 0; /* mic- or line-input */
3898 else
3899 return 1; /* HP-output */
3900 }
3901 return 0; 4081 return 0;
3902} 4082}
3903 4083
@@ -3909,11 +4089,9 @@ static int no_hp_sensing(struct sigmatel_spec *spec, int i)
3909 struct auto_pin_cfg *cfg = &spec->autocfg; 4089 struct auto_pin_cfg *cfg = &spec->autocfg;
3910 4090
3911 /* ignore sensing of shared line and mic jacks */ 4091 /* ignore sensing of shared line and mic jacks */
3912 if (spec->line_switch && 4092 if (cfg->hp_pins[i] == spec->line_switch)
3913 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
3914 return 1; 4093 return 1;
3915 if (spec->mic_switch && 4094 if (cfg->hp_pins[i] == spec->mic_switch)
3916 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
3917 return 1; 4095 return 1;
3918 /* ignore if the pin is set as line-out */ 4096 /* ignore if the pin is set as line-out */
3919 if (cfg->hp_pins[i] == spec->hp_switch) 4097 if (cfg->hp_pins[i] == spec->hp_switch)
@@ -3921,7 +4099,7 @@ static int no_hp_sensing(struct sigmatel_spec *spec, int i)
3921 return 0; 4099 return 0;
3922} 4100}
3923 4101
3924static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res) 4102static void stac92xx_hp_detect(struct hda_codec *codec)
3925{ 4103{
3926 struct sigmatel_spec *spec = codec->spec; 4104 struct sigmatel_spec *spec = codec->spec;
3927 struct auto_pin_cfg *cfg = &spec->autocfg; 4105 struct auto_pin_cfg *cfg = &spec->autocfg;
@@ -3937,7 +4115,14 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3937 break; 4115 break;
3938 if (no_hp_sensing(spec, i)) 4116 if (no_hp_sensing(spec, i))
3939 continue; 4117 continue;
3940 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]); 4118 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4119 if (presence) {
4120 unsigned int pinctl;
4121 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4122 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4123 if (pinctl & AC_PINCTL_IN_EN)
4124 presence = 0; /* mic- or line-input */
4125 }
3941 } 4126 }
3942 4127
3943 if (presence) { 4128 if (presence) {
@@ -4014,50 +4199,145 @@ static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4014 4199
4015static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid) 4200static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4016{ 4201{
4017 stac_toggle_power_map(codec, nid, get_hp_pin_presence(codec, nid)); 4202 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4203}
4204
4205static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4206{
4207 struct sigmatel_spec *spec = codec->spec;
4208 struct sigmatel_jack *jacks = spec->jacks.list;
4209
4210 if (jacks) {
4211 int i;
4212 for (i = 0; i < spec->jacks.used; i++) {
4213 if (jacks->nid == nid) {
4214 unsigned int pin_ctl =
4215 snd_hda_codec_read(codec, nid,
4216 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4217 0x00);
4218 int type = jacks->type;
4219 if (type == (SND_JACK_LINEOUT
4220 | SND_JACK_HEADPHONE))
4221 type = (pin_ctl & AC_PINCTL_HP_EN)
4222 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4223 snd_jack_report(jacks->jack,
4224 get_pin_presence(codec, nid)
4225 ? type : 0);
4226 }
4227 jacks++;
4228 }
4229 }
4230}
4231
4232static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4233 unsigned char type)
4234{
4235 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4236 if (!event)
4237 return;
4238 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4018} 4239}
4019 4240
4020static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res) 4241static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4021{ 4242{
4022 struct sigmatel_spec *spec = codec->spec; 4243 struct sigmatel_spec *spec = codec->spec;
4023 int idx = res >> 26 & 0x0f; 4244 struct sigmatel_event *event;
4245 int tag, data;
4024 4246
4025 switch ((res >> 26) & 0x70) { 4247 tag = (res >> 26) & 0x7f;
4248 event = stac_get_event_from_tag(codec, tag);
4249 if (!event)
4250 return;
4251
4252 switch (event->type) {
4026 case STAC_HP_EVENT: 4253 case STAC_HP_EVENT:
4027 stac92xx_hp_detect(codec, res); 4254 stac92xx_hp_detect(codec);
4028 /* fallthru */ 4255 /* fallthru */
4256 case STAC_INSERT_EVENT:
4029 case STAC_PWR_EVENT: 4257 case STAC_PWR_EVENT:
4030 if (spec->num_pwrs > 0) 4258 if (spec->num_pwrs > 0)
4031 stac92xx_pin_sense(codec, idx); 4259 stac92xx_pin_sense(codec, event->nid);
4260 stac92xx_report_jack(codec, event->nid);
4032 break; 4261 break;
4033 case STAC_VREF_EVENT: { 4262 case STAC_VREF_EVENT:
4034 int data = snd_hda_codec_read(codec, codec->afg, 0, 4263 data = snd_hda_codec_read(codec, codec->afg, 0,
4035 AC_VERB_GET_GPIO_DATA, 0); 4264 AC_VERB_GET_GPIO_DATA, 0);
4036 /* toggle VREF state based on GPIOx status */ 4265 /* toggle VREF state based on GPIOx status */
4037 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0, 4266 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4038 !!(data & (1 << idx))); 4267 !!(data & (1 << event->data)));
4039 break; 4268 break;
4040 }
4041 } 4269 }
4042} 4270}
4043 4271
4272#ifdef CONFIG_PROC_FS
4273static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4274 struct hda_codec *codec, hda_nid_t nid)
4275{
4276 if (nid == codec->afg)
4277 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4278 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4279}
4280
4281static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4282 struct hda_codec *codec,
4283 unsigned int verb)
4284{
4285 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4286 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4287}
4288
4289/* stac92hd71bxx, stac92hd73xx */
4290static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4291 struct hda_codec *codec, hda_nid_t nid)
4292{
4293 stac92hd_proc_hook(buffer, codec, nid);
4294 if (nid == codec->afg)
4295 analog_loop_proc_hook(buffer, codec, 0xfa0);
4296}
4297
4298static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4299 struct hda_codec *codec, hda_nid_t nid)
4300{
4301 if (nid == codec->afg)
4302 analog_loop_proc_hook(buffer, codec, 0xfe0);
4303}
4304
4305static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4306 struct hda_codec *codec, hda_nid_t nid)
4307{
4308 if (nid == codec->afg)
4309 analog_loop_proc_hook(buffer, codec, 0xfeb);
4310}
4311#else
4312#define stac92hd_proc_hook NULL
4313#define stac92hd7x_proc_hook NULL
4314#define stac9205_proc_hook NULL
4315#define stac927x_proc_hook NULL
4316#endif
4317
4044#ifdef SND_HDA_NEEDS_RESUME 4318#ifdef SND_HDA_NEEDS_RESUME
4045static int stac92xx_resume(struct hda_codec *codec) 4319static int stac92xx_resume(struct hda_codec *codec)
4046{ 4320{
4047 struct sigmatel_spec *spec = codec->spec; 4321 struct sigmatel_spec *spec = codec->spec;
4048 4322
4049 stac92xx_set_config_regs(codec); 4323 stac92xx_set_config_regs(codec);
4050 snd_hda_sequence_write(codec, spec->init); 4324 stac92xx_init(codec);
4051 stac_gpio_set(codec, spec->gpio_mask,
4052 spec->gpio_dir, spec->gpio_data);
4053 snd_hda_codec_resume_amp(codec); 4325 snd_hda_codec_resume_amp(codec);
4054 snd_hda_codec_resume_cache(codec); 4326 snd_hda_codec_resume_cache(codec);
4055 /* power down inactive DACs */ 4327 /* fake event to set up pins again to override cached values */
4056 if (spec->dac_list)
4057 stac92xx_power_down(codec);
4058 /* invoke unsolicited event to reset the HP state */
4059 if (spec->hp_detect) 4328 if (spec->hp_detect)
4060 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 4329 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4330 STAC_HP_EVENT);
4331 return 0;
4332}
4333
4334static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4335{
4336 struct sigmatel_spec *spec = codec->spec;
4337 if (spec->eapd_mask)
4338 stac_gpio_set(codec, spec->gpio_mask,
4339 spec->gpio_dir, spec->gpio_data &
4340 ~spec->eapd_mask);
4061 return 0; 4341 return 0;
4062} 4342}
4063#endif 4343#endif
@@ -4069,6 +4349,7 @@ static struct hda_codec_ops stac92xx_patch_ops = {
4069 .free = stac92xx_free, 4349 .free = stac92xx_free,
4070 .unsol_event = stac92xx_unsol_event, 4350 .unsol_event = stac92xx_unsol_event,
4071#ifdef SND_HDA_NEEDS_RESUME 4351#ifdef SND_HDA_NEEDS_RESUME
4352 .suspend = stac92xx_suspend,
4072 .resume = stac92xx_resume, 4353 .resume = stac92xx_resume,
4073#endif 4354#endif
4074}; 4355};
@@ -4091,14 +4372,12 @@ static int patch_stac9200(struct hda_codec *codec)
4091 if (spec->board_config < 0) { 4372 if (spec->board_config < 0) {
4092 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n"); 4373 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4093 err = stac92xx_save_bios_config_regs(codec); 4374 err = stac92xx_save_bios_config_regs(codec);
4094 if (err < 0) { 4375 } else
4095 stac92xx_free(codec); 4376 err = stac_save_pin_cfgs(codec,
4096 return err; 4377 stac9200_brd_tbl[spec->board_config]);
4097 } 4378 if (err < 0) {
4098 spec->pin_configs = spec->bios_pin_configs; 4379 stac92xx_free(codec);
4099 } else { 4380 return err;
4100 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
4101 stac92xx_set_config_regs(codec);
4102 } 4381 }
4103 4382
4104 spec->multiout.max_channels = 2; 4383 spec->multiout.max_channels = 2;
@@ -4154,14 +4433,12 @@ static int patch_stac925x(struct hda_codec *codec)
4154 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x," 4433 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4155 "using BIOS defaults\n"); 4434 "using BIOS defaults\n");
4156 err = stac92xx_save_bios_config_regs(codec); 4435 err = stac92xx_save_bios_config_regs(codec);
4157 if (err < 0) { 4436 } else
4158 stac92xx_free(codec); 4437 err = stac_save_pin_cfgs(codec,
4159 return err; 4438 stac925x_brd_tbl[spec->board_config]);
4160 } 4439 if (err < 0) {
4161 spec->pin_configs = spec->bios_pin_configs; 4440 stac92xx_free(codec);
4162 } else if (stac925x_brd_tbl[spec->board_config] != NULL){ 4441 return err;
4163 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
4164 stac92xx_set_config_regs(codec);
4165 } 4442 }
4166 4443
4167 spec->multiout.max_channels = 2; 4444 spec->multiout.max_channels = 2;
@@ -4225,6 +4502,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4225 struct sigmatel_spec *spec; 4502 struct sigmatel_spec *spec;
4226 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2]; 4503 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4227 int err = 0; 4504 int err = 0;
4505 int num_dacs;
4228 4506
4229 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4507 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4230 if (spec == NULL) 4508 if (spec == NULL)
@@ -4243,43 +4521,37 @@ again:
4243 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 4521 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4244 " STAC92HD73XX, using BIOS defaults\n"); 4522 " STAC92HD73XX, using BIOS defaults\n");
4245 err = stac92xx_save_bios_config_regs(codec); 4523 err = stac92xx_save_bios_config_regs(codec);
4246 if (err < 0) { 4524 } else
4247 stac92xx_free(codec); 4525 err = stac_save_pin_cfgs(codec,
4248 return err; 4526 stac92hd73xx_brd_tbl[spec->board_config]);
4249 } 4527 if (err < 0) {
4250 spec->pin_configs = spec->bios_pin_configs; 4528 stac92xx_free(codec);
4251 } else { 4529 return err;
4252 spec->pin_configs = stac92hd73xx_brd_tbl[spec->board_config];
4253 stac92xx_set_config_regs(codec);
4254 } 4530 }
4255 4531
4256 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a, 4532 num_dacs = snd_hda_get_connections(codec, 0x0a,
4257 conn, STAC92HD73_DAC_COUNT + 2) - 1; 4533 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4258 4534
4259 if (spec->multiout.num_dacs < 0) { 4535 if (num_dacs < 3 || num_dacs > 5) {
4260 printk(KERN_WARNING "hda_codec: Could not determine " 4536 printk(KERN_WARNING "hda_codec: Could not determine "
4261 "number of channels defaulting to DAC count\n"); 4537 "number of channels defaulting to DAC count\n");
4262 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT; 4538 num_dacs = STAC92HD73_DAC_COUNT;
4263 } 4539 }
4264 4540 switch (num_dacs) {
4265 switch (spec->multiout.num_dacs) {
4266 case 0x3: /* 6 Channel */ 4541 case 0x3: /* 6 Channel */
4267 spec->multiout.hp_nid = 0x17;
4268 spec->mixer = stac92hd73xx_6ch_mixer; 4542 spec->mixer = stac92hd73xx_6ch_mixer;
4269 spec->init = stac92hd73xx_6ch_core_init; 4543 spec->init = stac92hd73xx_6ch_core_init;
4270 break; 4544 break;
4271 case 0x4: /* 8 Channel */ 4545 case 0x4: /* 8 Channel */
4272 spec->multiout.hp_nid = 0x18;
4273 spec->mixer = stac92hd73xx_8ch_mixer; 4546 spec->mixer = stac92hd73xx_8ch_mixer;
4274 spec->init = stac92hd73xx_8ch_core_init; 4547 spec->init = stac92hd73xx_8ch_core_init;
4275 break; 4548 break;
4276 case 0x5: /* 10 Channel */ 4549 case 0x5: /* 10 Channel */
4277 spec->multiout.hp_nid = 0x19;
4278 spec->mixer = stac92hd73xx_10ch_mixer; 4550 spec->mixer = stac92hd73xx_10ch_mixer;
4279 spec->init = stac92hd73xx_10ch_core_init; 4551 spec->init = stac92hd73xx_10ch_core_init;
4280 }; 4552 }
4553 spec->multiout.dac_nids = spec->dac_nids;
4281 4554
4282 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4283 spec->aloopback_mask = 0x01; 4555 spec->aloopback_mask = 0x01;
4284 spec->aloopback_shift = 8; 4556 spec->aloopback_shift = 8;
4285 4557
@@ -4310,9 +4582,8 @@ again:
4310 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP]; 4582 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
4311 spec->eapd_switch = 0; 4583 spec->eapd_switch = 0;
4312 spec->num_amps = 1; 4584 spec->num_amps = 1;
4313 spec->multiout.hp_nid = 0; /* dual HPs */
4314 4585
4315 if (!spec->init) 4586 if (spec->board_config != STAC_DELL_EQ)
4316 spec->init = dell_m6_core_init; 4587 spec->init = dell_m6_core_init;
4317 switch (spec->board_config) { 4588 switch (spec->board_config) {
4318 case STAC_DELL_M6_AMIC: /* Analog Mics */ 4589 case STAC_DELL_M6_AMIC: /* Analog Mics */
@@ -4370,6 +4641,8 @@ again:
4370 4641
4371 codec->patch_ops = stac92xx_patch_ops; 4642 codec->patch_ops = stac92xx_patch_ops;
4372 4643
4644 codec->proc_widget_hook = stac92hd7x_proc_hook;
4645
4373 return 0; 4646 return 0;
4374} 4647}
4375 4648
@@ -4401,17 +4674,15 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
4401 spec->pwr_nids = stac92hd83xxx_pwr_nids; 4674 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4402 spec->pwr_mapping = stac92hd83xxx_pwr_mapping; 4675 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4403 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids); 4676 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4404 spec->multiout.dac_nids = stac92hd83xxx_dac_nids; 4677 spec->multiout.dac_nids = spec->dac_nids;
4405 4678
4406 spec->init = stac92hd83xxx_core_init; 4679 spec->init = stac92hd83xxx_core_init;
4407 switch (codec->vendor_id) { 4680 switch (codec->vendor_id) {
4408 case 0x111d7605: 4681 case 0x111d7605:
4409 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4410 break; 4682 break;
4411 default: 4683 default:
4412 spec->num_pwrs--; 4684 spec->num_pwrs--;
4413 spec->init++; /* switch to config #2 */ 4685 spec->init++; /* switch to config #2 */
4414 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4415 } 4686 }
4416 4687
4417 spec->mixer = stac92hd83xxx_mixer; 4688 spec->mixer = stac92hd83xxx_mixer;
@@ -4430,14 +4701,12 @@ again:
4430 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 4701 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4431 " STAC92HD83XXX, using BIOS defaults\n"); 4702 " STAC92HD83XXX, using BIOS defaults\n");
4432 err = stac92xx_save_bios_config_regs(codec); 4703 err = stac92xx_save_bios_config_regs(codec);
4433 if (err < 0) { 4704 } else
4434 stac92xx_free(codec); 4705 err = stac_save_pin_cfgs(codec,
4435 return err; 4706 stac92hd83xxx_brd_tbl[spec->board_config]);
4436 } 4707 if (err < 0) {
4437 spec->pin_configs = spec->bios_pin_configs; 4708 stac92xx_free(codec);
4438 } else { 4709 return err;
4439 spec->pin_configs = stac92hd83xxx_brd_tbl[spec->board_config];
4440 stac92xx_set_config_regs(codec);
4441 } 4710 }
4442 4711
4443 err = stac92xx_parse_auto_config(codec, 0x1d, 0); 4712 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
@@ -4458,56 +4727,10 @@ again:
4458 4727
4459 codec->patch_ops = stac92xx_patch_ops; 4728 codec->patch_ops = stac92xx_patch_ops;
4460 4729
4461 return 0; 4730 codec->proc_widget_hook = stac92hd_proc_hook;
4462}
4463 4731
4464#ifdef SND_HDA_NEEDS_RESUME
4465static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
4466{
4467 struct sigmatel_spec *spec = codec->spec;
4468 int i;
4469 snd_hda_codec_write_cache(codec, codec->afg, 0,
4470 AC_VERB_SET_POWER_STATE, pwr);
4471
4472 msleep(1);
4473 for (i = 0; i < spec->num_adcs; i++) {
4474 snd_hda_codec_write_cache(codec,
4475 spec->adc_nids[i], 0,
4476 AC_VERB_SET_POWER_STATE, pwr);
4477 }
4478};
4479
4480static int stac92hd71xx_resume(struct hda_codec *codec)
4481{
4482 stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
4483 return stac92xx_resume(codec);
4484}
4485
4486static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
4487{
4488 struct sigmatel_spec *spec = codec->spec;
4489
4490 stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
4491 if (spec->eapd_mask)
4492 stac_gpio_set(codec, spec->gpio_mask,
4493 spec->gpio_dir, spec->gpio_data &
4494 ~spec->eapd_mask);
4495 return 0; 4732 return 0;
4496}; 4733}
4497
4498#endif
4499
4500static struct hda_codec_ops stac92hd71bxx_patch_ops = {
4501 .build_controls = stac92xx_build_controls,
4502 .build_pcms = stac92xx_build_pcms,
4503 .init = stac92xx_init,
4504 .free = stac92xx_free,
4505 .unsol_event = stac92xx_unsol_event,
4506#ifdef SND_HDA_NEEDS_RESUME
4507 .resume = stac92hd71xx_resume,
4508 .suspend = stac92hd71xx_suspend,
4509#endif
4510};
4511 4734
4512static struct hda_input_mux stac92hd71bxx_dmux = { 4735static struct hda_input_mux stac92hd71bxx_dmux = {
4513 .num_items = 4, 4736 .num_items = 4,
@@ -4544,14 +4767,12 @@ again:
4544 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 4767 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4545 " STAC92HD71BXX, using BIOS defaults\n"); 4768 " STAC92HD71BXX, using BIOS defaults\n");
4546 err = stac92xx_save_bios_config_regs(codec); 4769 err = stac92xx_save_bios_config_regs(codec);
4547 if (err < 0) { 4770 } else
4548 stac92xx_free(codec); 4771 err = stac_save_pin_cfgs(codec,
4549 return err; 4772 stac92hd71bxx_brd_tbl[spec->board_config]);
4550 } 4773 if (err < 0) {
4551 spec->pin_configs = spec->bios_pin_configs; 4774 stac92xx_free(codec);
4552 } else { 4775 return err;
4553 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
4554 stac92xx_set_config_regs(codec);
4555 } 4776 }
4556 4777
4557 if (spec->board_config > STAC_92HD71BXX_REF) { 4778 if (spec->board_config > STAC_92HD71BXX_REF) {
@@ -4574,21 +4795,21 @@ again:
4574 switch (spec->board_config) { 4795 switch (spec->board_config) {
4575 case STAC_HP_M4: 4796 case STAC_HP_M4:
4576 /* Enable VREF power saving on GPIO1 detect */ 4797 /* Enable VREF power saving on GPIO1 detect */
4798 err = stac_add_event(spec, codec->afg,
4799 STAC_VREF_EVENT, 0x02);
4800 if (err < 0)
4801 return err;
4577 snd_hda_codec_write_cache(codec, codec->afg, 0, 4802 snd_hda_codec_write_cache(codec, codec->afg, 0,
4578 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02); 4803 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4579 snd_hda_codec_write_cache(codec, codec->afg, 0, 4804 snd_hda_codec_write_cache(codec, codec->afg, 0,
4580 AC_VERB_SET_UNSOLICITED_ENABLE, 4805 AC_VERB_SET_UNSOLICITED_ENABLE,
4581 (AC_USRSP_EN | STAC_VREF_EVENT | 0x01)); 4806 AC_USRSP_EN | err);
4582 spec->gpio_mask |= 0x02; 4807 spec->gpio_mask |= 0x02;
4583 break; 4808 break;
4584 } 4809 }
4585 if ((codec->revision_id & 0xf) == 0 || 4810 if ((codec->revision_id & 0xf) == 0 ||
4586 (codec->revision_id & 0xf) == 1) { 4811 (codec->revision_id & 0xf) == 1)
4587#ifdef SND_HDA_NEEDS_RESUME
4588 codec->patch_ops = stac92hd71bxx_patch_ops;
4589#endif
4590 spec->stream_delay = 40; /* 40 milliseconds */ 4812 spec->stream_delay = 40; /* 40 milliseconds */
4591 }
4592 4813
4593 /* no output amps */ 4814 /* no output amps */
4594 spec->num_pwrs = 0; 4815 spec->num_pwrs = 0;
@@ -4597,15 +4818,11 @@ again:
4597 4818
4598 /* disable VSW */ 4819 /* disable VSW */
4599 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF]; 4820 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
4600 stac92xx_set_config_reg(codec, 0xf, 0x40f000f0); 4821 stac_change_pin_config(codec, 0xf, 0x40f000f0);
4601 break; 4822 break;
4602 case 0x111d7603: /* 6 Port with Analog Mixer */ 4823 case 0x111d7603: /* 6 Port with Analog Mixer */
4603 if ((codec->revision_id & 0xf) == 1) { 4824 if ((codec->revision_id & 0xf) == 1)
4604#ifdef SND_HDA_NEEDS_RESUME
4605 codec->patch_ops = stac92hd71bxx_patch_ops;
4606#endif
4607 spec->stream_delay = 40; /* 40 milliseconds */ 4825 spec->stream_delay = 40; /* 40 milliseconds */
4608 }
4609 4826
4610 /* no output amps */ 4827 /* no output amps */
4611 spec->num_pwrs = 0; 4828 spec->num_pwrs = 0;
@@ -4635,7 +4852,7 @@ again:
4635 switch (spec->board_config) { 4852 switch (spec->board_config) {
4636 case STAC_HP_M4: 4853 case STAC_HP_M4:
4637 /* enable internal microphone */ 4854 /* enable internal microphone */
4638 stac92xx_set_config_reg(codec, 0x0e, 0x01813040); 4855 stac_change_pin_config(codec, 0x0e, 0x01813040);
4639 stac92xx_auto_set_pinctl(codec, 0x0e, 4856 stac92xx_auto_set_pinctl(codec, 0x0e,
4640 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80); 4857 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
4641 /* fallthru */ 4858 /* fallthru */
@@ -4656,9 +4873,7 @@ again:
4656 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids); 4873 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4657 }; 4874 };
4658 4875
4659 spec->multiout.num_dacs = 1; 4876 spec->multiout.dac_nids = spec->dac_nids;
4660 spec->multiout.hp_nid = 0x11;
4661 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
4662 if (spec->dinput_mux) 4877 if (spec->dinput_mux)
4663 spec->private_dimux.num_items += 4878 spec->private_dimux.num_items +=
4664 spec->num_dmics - 4879 spec->num_dmics -
@@ -4680,6 +4895,8 @@ again:
4680 return err; 4895 return err;
4681 } 4896 }
4682 4897
4898 codec->proc_widget_hook = stac92hd7x_proc_hook;
4899
4683 return 0; 4900 return 0;
4684}; 4901};
4685 4902
@@ -4741,14 +4958,12 @@ static int patch_stac922x(struct hda_codec *codec)
4741 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, " 4958 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
4742 "using BIOS defaults\n"); 4959 "using BIOS defaults\n");
4743 err = stac92xx_save_bios_config_regs(codec); 4960 err = stac92xx_save_bios_config_regs(codec);
4744 if (err < 0) { 4961 } else
4745 stac92xx_free(codec); 4962 err = stac_save_pin_cfgs(codec,
4746 return err; 4963 stac922x_brd_tbl[spec->board_config]);
4747 } 4964 if (err < 0) {
4748 spec->pin_configs = spec->bios_pin_configs; 4965 stac92xx_free(codec);
4749 } else if (stac922x_brd_tbl[spec->board_config] != NULL) { 4966 return err;
4750 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
4751 stac92xx_set_config_regs(codec);
4752 } 4967 }
4753 4968
4754 spec->adc_nids = stac922x_adc_nids; 4969 spec->adc_nids = stac922x_adc_nids;
@@ -4811,14 +5026,12 @@ static int patch_stac927x(struct hda_codec *codec)
4811 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5026 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4812 "STAC927x, using BIOS defaults\n"); 5027 "STAC927x, using BIOS defaults\n");
4813 err = stac92xx_save_bios_config_regs(codec); 5028 err = stac92xx_save_bios_config_regs(codec);
4814 if (err < 0) { 5029 } else
4815 stac92xx_free(codec); 5030 err = stac_save_pin_cfgs(codec,
4816 return err; 5031 stac927x_brd_tbl[spec->board_config]);
4817 } 5032 if (err < 0) {
4818 spec->pin_configs = spec->bios_pin_configs; 5033 stac92xx_free(codec);
4819 } else { 5034 return err;
4820 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
4821 stac92xx_set_config_regs(codec);
4822 } 5035 }
4823 5036
4824 spec->digbeep_nid = 0x23; 5037 spec->digbeep_nid = 0x23;
@@ -4848,15 +5061,15 @@ static int patch_stac927x(struct hda_codec *codec)
4848 case 0x10280209: 5061 case 0x10280209:
4849 case 0x1028022e: 5062 case 0x1028022e:
4850 /* correct the device field to SPDIF out */ 5063 /* correct the device field to SPDIF out */
4851 stac92xx_set_config_reg(codec, 0x21, 0x01442070); 5064 stac_change_pin_config(codec, 0x21, 0x01442070);
4852 break; 5065 break;
4853 }; 5066 };
4854 /* configure the analog microphone on some laptops */ 5067 /* configure the analog microphone on some laptops */
4855 stac92xx_set_config_reg(codec, 0x0c, 0x90a79130); 5068 stac_change_pin_config(codec, 0x0c, 0x90a79130);
4856 /* correct the front output jack as a hp out */ 5069 /* correct the front output jack as a hp out */
4857 stac92xx_set_config_reg(codec, 0x0f, 0x0227011f); 5070 stac_change_pin_config(codec, 0x0f, 0x0227011f);
4858 /* correct the front input jack as a mic */ 5071 /* correct the front input jack as a mic */
4859 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130); 5072 stac_change_pin_config(codec, 0x0e, 0x02a79130);
4860 /* fallthru */ 5073 /* fallthru */
4861 case STAC_DELL_3ST: 5074 case STAC_DELL_3ST:
4862 /* GPIO2 High = Enable EAPD */ 5075 /* GPIO2 High = Enable EAPD */
@@ -4904,6 +5117,8 @@ static int patch_stac927x(struct hda_codec *codec)
4904 5117
4905 codec->patch_ops = stac92xx_patch_ops; 5118 codec->patch_ops = stac92xx_patch_ops;
4906 5119
5120 codec->proc_widget_hook = stac927x_proc_hook;
5121
4907 /* 5122 /*
4908 * !!FIXME!! 5123 * !!FIXME!!
4909 * The STAC927x seem to require fairly long delays for certain 5124 * The STAC927x seem to require fairly long delays for certain
@@ -4942,14 +5157,12 @@ static int patch_stac9205(struct hda_codec *codec)
4942 if (spec->board_config < 0) { 5157 if (spec->board_config < 0) {
4943 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n"); 5158 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
4944 err = stac92xx_save_bios_config_regs(codec); 5159 err = stac92xx_save_bios_config_regs(codec);
4945 if (err < 0) { 5160 } else
4946 stac92xx_free(codec); 5161 err = stac_save_pin_cfgs(codec,
4947 return err; 5162 stac9205_brd_tbl[spec->board_config]);
4948 } 5163 if (err < 0) {
4949 spec->pin_configs = spec->bios_pin_configs; 5164 stac92xx_free(codec);
4950 } else { 5165 return err;
4951 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
4952 stac92xx_set_config_regs(codec);
4953 } 5166 }
4954 5167
4955 spec->digbeep_nid = 0x23; 5168 spec->digbeep_nid = 0x23;
@@ -4976,15 +5189,18 @@ static int patch_stac9205(struct hda_codec *codec)
4976 switch (spec->board_config){ 5189 switch (spec->board_config){
4977 case STAC_9205_DELL_M43: 5190 case STAC_9205_DELL_M43:
4978 /* Enable SPDIF in/out */ 5191 /* Enable SPDIF in/out */
4979 stac92xx_set_config_reg(codec, 0x1f, 0x01441030); 5192 stac_change_pin_config(codec, 0x1f, 0x01441030);
4980 stac92xx_set_config_reg(codec, 0x20, 0x1c410030); 5193 stac_change_pin_config(codec, 0x20, 0x1c410030);
4981 5194
4982 /* Enable unsol response for GPIO4/Dock HP connection */ 5195 /* Enable unsol response for GPIO4/Dock HP connection */
5196 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5197 if (err < 0)
5198 return err;
4983 snd_hda_codec_write_cache(codec, codec->afg, 0, 5199 snd_hda_codec_write_cache(codec, codec->afg, 0,
4984 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10); 5200 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
4985 snd_hda_codec_write_cache(codec, codec->afg, 0, 5201 snd_hda_codec_write_cache(codec, codec->afg, 0,
4986 AC_VERB_SET_UNSOLICITED_ENABLE, 5202 AC_VERB_SET_UNSOLICITED_ENABLE,
4987 (AC_USRSP_EN | STAC_HP_EVENT)); 5203 AC_USRSP_EN | err);
4988 5204
4989 spec->gpio_dir = 0x0b; 5205 spec->gpio_dir = 0x0b;
4990 spec->eapd_mask = 0x01; 5206 spec->eapd_mask = 0x01;
@@ -5022,6 +5238,8 @@ static int patch_stac9205(struct hda_codec *codec)
5022 5238
5023 codec->patch_ops = stac92xx_patch_ops; 5239 codec->patch_ops = stac92xx_patch_ops;
5024 5240
5241 codec->proc_widget_hook = stac9205_proc_hook;
5242
5025 return 0; 5243 return 0;
5026} 5244}
5027 5245
@@ -5078,29 +5296,11 @@ static struct hda_verb vaio_ar_init[] = {
5078 {} 5296 {}
5079}; 5297};
5080 5298
5081/* bind volumes of both NID 0x02 and 0x05 */
5082static struct hda_bind_ctls vaio_bind_master_vol = {
5083 .ops = &snd_hda_bind_vol,
5084 .values = {
5085 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
5086 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
5087 0
5088 },
5089};
5090
5091/* bind volumes of both NID 0x02 and 0x05 */
5092static struct hda_bind_ctls vaio_bind_master_sw = {
5093 .ops = &snd_hda_bind_sw,
5094 .values = {
5095 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
5096 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
5097 0,
5098 },
5099};
5100
5101static struct snd_kcontrol_new vaio_mixer[] = { 5299static struct snd_kcontrol_new vaio_mixer[] = {
5102 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol), 5300 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5103 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw), 5301 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5302 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5303 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
5104 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */ 5304 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5105 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), 5305 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5106 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), 5306 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
@@ -5116,8 +5316,10 @@ static struct snd_kcontrol_new vaio_mixer[] = {
5116}; 5316};
5117 5317
5118static struct snd_kcontrol_new vaio_ar_mixer[] = { 5318static struct snd_kcontrol_new vaio_ar_mixer[] = {
5119 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol), 5319 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5120 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw), 5320 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5321 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5322 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
5121 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */ 5323 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5122 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), 5324 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5123 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), 5325 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
@@ -5158,7 +5360,7 @@ static int stac9872_vaio_init(struct hda_codec *codec)
5158 5360
5159static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res) 5361static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5160{ 5362{
5161 if (get_hp_pin_presence(codec, 0x0a)) { 5363 if (get_pin_presence(codec, 0x0a)) {
5162 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN); 5364 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5163 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN); 5365 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5164 } else { 5366 } else {
@@ -5269,7 +5471,7 @@ static int patch_stac9872(struct hda_codec *codec)
5269/* 5471/*
5270 * patch entries 5472 * patch entries
5271 */ 5473 */
5272struct hda_codec_preset snd_hda_preset_sigmatel[] = { 5474static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5273 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 }, 5475 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5274 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x }, 5476 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5275 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x }, 5477 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
@@ -5333,3 +5535,27 @@ struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5333 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx }, 5535 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5334 {} /* terminator */ 5536 {} /* terminator */
5335}; 5537};
5538
5539MODULE_ALIAS("snd-hda-codec-id:8384*");
5540MODULE_ALIAS("snd-hda-codec-id:111d*");
5541
5542MODULE_LICENSE("GPL");
5543MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5544
5545static struct hda_codec_preset_list sigmatel_list = {
5546 .preset = snd_hda_preset_sigmatel,
5547 .owner = THIS_MODULE,
5548};
5549
5550static int __init patch_sigmatel_init(void)
5551{
5552 return snd_hda_add_codec_preset(&sigmatel_list);
5553}
5554
5555static void __exit patch_sigmatel_exit(void)
5556{
5557 snd_hda_delete_codec_preset(&sigmatel_list);
5558}
5559
5560module_init(patch_sigmatel_init)
5561module_exit(patch_sigmatel_exit)
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 63e4871e5d8f..c761394cbe84 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -47,15 +47,11 @@
47#include <sound/asoundef.h> 47#include <sound/asoundef.h>
48#include "hda_codec.h" 48#include "hda_codec.h"
49#include "hda_local.h" 49#include "hda_local.h"
50#include "hda_patch.h"
51 50
52/* amp values */ 51/* amp values */
53#define AMP_VAL_IDX_SHIFT 19 52#define AMP_VAL_IDX_SHIFT 19
54#define AMP_VAL_IDX_MASK (0x0f<<19) 53#define AMP_VAL_IDX_MASK (0x0f<<19)
55 54
56#define NUM_CONTROL_ALLOC 32
57#define NUM_VERB_ALLOC 32
58
59/* Pin Widget NID */ 55/* Pin Widget NID */
60#define VT1708_HP_NID 0x13 56#define VT1708_HP_NID 0x13
61#define VT1708_DIGOUT_NID 0x14 57#define VT1708_DIGOUT_NID 0x14
@@ -145,8 +141,6 @@ enum {
145 AUTO_SEQ_SIDE 141 AUTO_SEQ_SIDE
146}; 142};
147 143
148#define get_amp_nid(kc) ((kc)->private_value & 0xffff)
149
150/* Some VT1708S based boards gets the micboost setting wrong, so we have 144/* Some VT1708S based boards gets the micboost setting wrong, so we have
151 * to apply some brute-force and re-write the TLV's by software. */ 145 * to apply some brute-force and re-write the TLV's by software. */
152static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag, 146static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
@@ -227,8 +221,7 @@ struct via_spec {
227 221
228 /* dynamic controls, init_verbs and input_mux */ 222 /* dynamic controls, init_verbs and input_mux */
229 struct auto_pin_cfg autocfg; 223 struct auto_pin_cfg autocfg;
230 unsigned int num_kctl_alloc, num_kctl_used; 224 struct snd_array kctls;
231 struct snd_kcontrol_new *kctl_alloc;
232 struct hda_input_mux private_imux[2]; 225 struct hda_input_mux private_imux[2];
233 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 226 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
234 227
@@ -272,33 +265,31 @@ static int via_add_control(struct via_spec *spec, int type, const char *name,
272{ 265{
273 struct snd_kcontrol_new *knew; 266 struct snd_kcontrol_new *knew;
274 267
275 if (spec->num_kctl_used >= spec->num_kctl_alloc) { 268 snd_array_init(&spec->kctls, sizeof(*knew), 32);
276 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC; 269 knew = snd_array_new(&spec->kctls);
277 270 if (!knew)
278 /* array + terminator */ 271 return -ENOMEM;
279 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
280 if (!knew)
281 return -ENOMEM;
282 if (spec->kctl_alloc) {
283 memcpy(knew, spec->kctl_alloc,
284 sizeof(*knew) * spec->num_kctl_alloc);
285 kfree(spec->kctl_alloc);
286 }
287 spec->kctl_alloc = knew;
288 spec->num_kctl_alloc = num;
289 }
290
291 knew = &spec->kctl_alloc[spec->num_kctl_used];
292 *knew = vt1708_control_templates[type]; 272 *knew = vt1708_control_templates[type];
293 knew->name = kstrdup(name, GFP_KERNEL); 273 knew->name = kstrdup(name, GFP_KERNEL);
294
295 if (!knew->name) 274 if (!knew->name)
296 return -ENOMEM; 275 return -ENOMEM;
297 knew->private_value = val; 276 knew->private_value = val;
298 spec->num_kctl_used++;
299 return 0; 277 return 0;
300} 278}
301 279
280static void via_free_kctls(struct hda_codec *codec)
281{
282 struct via_spec *spec = codec->spec;
283
284 if (spec->kctls.list) {
285 struct snd_kcontrol_new *kctl = spec->kctls.list;
286 int i;
287 for (i = 0; i < spec->kctls.used; i++)
288 kfree(kctl[i].name);
289 }
290 snd_array_free(&spec->kctls);
291}
292
302/* create input playback/capture controls for the given pin */ 293/* create input playback/capture controls for the given pin */
303static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin, 294static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
304 const char *ctlname, int idx, int mix_nid) 295 const char *ctlname, int idx, int mix_nid)
@@ -896,6 +887,7 @@ static int via_build_controls(struct hda_codec *codec)
896 if (err < 0) 887 if (err < 0)
897 return err; 888 return err;
898 } 889 }
890 via_free_kctls(codec); /* no longer needed */
899 return 0; 891 return 0;
900} 892}
901 893
@@ -941,17 +933,11 @@ static int via_build_pcms(struct hda_codec *codec)
941static void via_free(struct hda_codec *codec) 933static void via_free(struct hda_codec *codec)
942{ 934{
943 struct via_spec *spec = codec->spec; 935 struct via_spec *spec = codec->spec;
944 unsigned int i;
945 936
946 if (!spec) 937 if (!spec)
947 return; 938 return;
948 939
949 if (spec->kctl_alloc) { 940 via_free_kctls(codec);
950 for (i = 0; i < spec->num_kctl_used; i++)
951 kfree(spec->kctl_alloc[i].name);
952 kfree(spec->kctl_alloc);
953 }
954
955 kfree(codec->spec); 941 kfree(codec->spec);
956} 942}
957 943
@@ -1373,8 +1359,8 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1373 if (spec->autocfg.dig_in_pin) 1359 if (spec->autocfg.dig_in_pin)
1374 spec->dig_in_nid = VT1708_DIGIN_NID; 1360 spec->dig_in_nid = VT1708_DIGIN_NID;
1375 1361
1376 if (spec->kctl_alloc) 1362 if (spec->kctls.list)
1377 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 1363 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1378 1364
1379 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; 1365 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
1380 1366
@@ -1846,8 +1832,8 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
1846 if (spec->autocfg.dig_in_pin) 1832 if (spec->autocfg.dig_in_pin)
1847 spec->dig_in_nid = VT1709_DIGIN_NID; 1833 spec->dig_in_nid = VT1709_DIGIN_NID;
1848 1834
1849 if (spec->kctl_alloc) 1835 if (spec->kctls.list)
1850 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 1836 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1851 1837
1852 spec->input_mux = &spec->private_imux[0]; 1838 spec->input_mux = &spec->private_imux[0];
1853 1839
@@ -2390,8 +2376,8 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
2390 if (spec->autocfg.dig_in_pin) 2376 if (spec->autocfg.dig_in_pin)
2391 spec->dig_in_nid = VT1708B_DIGIN_NID; 2377 spec->dig_in_nid = VT1708B_DIGIN_NID;
2392 2378
2393 if (spec->kctl_alloc) 2379 if (spec->kctls.list)
2394 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 2380 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2395 2381
2396 spec->input_mux = &spec->private_imux[0]; 2382 spec->input_mux = &spec->private_imux[0];
2397 2383
@@ -2855,8 +2841,8 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec)
2855 2841
2856 spec->extra_dig_out_nid = 0x15; 2842 spec->extra_dig_out_nid = 0x15;
2857 2843
2858 if (spec->kctl_alloc) 2844 if (spec->kctls.list)
2859 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 2845 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2860 2846
2861 spec->input_mux = &spec->private_imux[0]; 2847 spec->input_mux = &spec->private_imux[0];
2862 2848
@@ -3174,8 +3160,8 @@ static int vt1702_parse_auto_config(struct hda_codec *codec)
3174 3160
3175 spec->extra_dig_out_nid = 0x1B; 3161 spec->extra_dig_out_nid = 0x1B;
3176 3162
3177 if (spec->kctl_alloc) 3163 if (spec->kctls.list)
3178 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 3164 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3179 3165
3180 spec->input_mux = &spec->private_imux[0]; 3166 spec->input_mux = &spec->private_imux[0];
3181 3167
@@ -3262,74 +3248,97 @@ static int patch_vt1702(struct hda_codec *codec)
3262/* 3248/*
3263 * patch entries 3249 * patch entries
3264 */ 3250 */
3265struct hda_codec_preset snd_hda_preset_via[] = { 3251static struct hda_codec_preset snd_hda_preset_via[] = {
3266 { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708}, 3252 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3267 { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708}, 3253 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3268 { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708}, 3254 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3269 { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708}, 3255 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3270 { .id = 0x1106E710, .name = "VIA VT1709 10-Ch", 3256 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3271 .patch = patch_vt1709_10ch}, 3257 .patch = patch_vt1709_10ch},
3272 { .id = 0x1106E711, .name = "VIA VT1709 10-Ch", 3258 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3273 .patch = patch_vt1709_10ch}, 3259 .patch = patch_vt1709_10ch},
3274 { .id = 0x1106E712, .name = "VIA VT1709 10-Ch", 3260 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3275 .patch = patch_vt1709_10ch}, 3261 .patch = patch_vt1709_10ch},
3276 { .id = 0x1106E713, .name = "VIA VT1709 10-Ch", 3262 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3277 .patch = patch_vt1709_10ch}, 3263 .patch = patch_vt1709_10ch},
3278 { .id = 0x1106E714, .name = "VIA VT1709 6-Ch", 3264 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3279 .patch = patch_vt1709_6ch}, 3265 .patch = patch_vt1709_6ch},
3280 { .id = 0x1106E715, .name = "VIA VT1709 6-Ch", 3266 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3281 .patch = patch_vt1709_6ch}, 3267 .patch = patch_vt1709_6ch},
3282 { .id = 0x1106E716, .name = "VIA VT1709 6-Ch", 3268 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3283 .patch = patch_vt1709_6ch}, 3269 .patch = patch_vt1709_6ch},
3284 { .id = 0x1106E717, .name = "VIA VT1709 6-Ch", 3270 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3285 .patch = patch_vt1709_6ch}, 3271 .patch = patch_vt1709_6ch},
3286 { .id = 0x1106E720, .name = "VIA VT1708B 8-Ch", 3272 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3287 .patch = patch_vt1708B_8ch}, 3273 .patch = patch_vt1708B_8ch},
3288 { .id = 0x1106E721, .name = "VIA VT1708B 8-Ch", 3274 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3289 .patch = patch_vt1708B_8ch}, 3275 .patch = patch_vt1708B_8ch},
3290 { .id = 0x1106E722, .name = "VIA VT1708B 8-Ch", 3276 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3291 .patch = patch_vt1708B_8ch}, 3277 .patch = patch_vt1708B_8ch},
3292 { .id = 0x1106E723, .name = "VIA VT1708B 8-Ch", 3278 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3293 .patch = patch_vt1708B_8ch}, 3279 .patch = patch_vt1708B_8ch},
3294 { .id = 0x1106E724, .name = "VIA VT1708B 4-Ch", 3280 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3295 .patch = patch_vt1708B_4ch}, 3281 .patch = patch_vt1708B_4ch},
3296 { .id = 0x1106E725, .name = "VIA VT1708B 4-Ch", 3282 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3297 .patch = patch_vt1708B_4ch}, 3283 .patch = patch_vt1708B_4ch},
3298 { .id = 0x1106E726, .name = "VIA VT1708B 4-Ch", 3284 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3299 .patch = patch_vt1708B_4ch}, 3285 .patch = patch_vt1708B_4ch},
3300 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch", 3286 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3301 .patch = patch_vt1708B_4ch}, 3287 .patch = patch_vt1708B_4ch},
3302 { .id = 0x11060397, .name = "VIA VT1708S", 3288 { .id = 0x11060397, .name = "VT1708S",
3303 .patch = patch_vt1708S}, 3289 .patch = patch_vt1708S},
3304 { .id = 0x11061397, .name = "VIA VT1708S", 3290 { .id = 0x11061397, .name = "VT1708S",
3305 .patch = patch_vt1708S}, 3291 .patch = patch_vt1708S},
3306 { .id = 0x11062397, .name = "VIA VT1708S", 3292 { .id = 0x11062397, .name = "VT1708S",
3307 .patch = patch_vt1708S}, 3293 .patch = patch_vt1708S},
3308 { .id = 0x11063397, .name = "VIA VT1708S", 3294 { .id = 0x11063397, .name = "VT1708S",
3309 .patch = patch_vt1708S}, 3295 .patch = patch_vt1708S},
3310 { .id = 0x11064397, .name = "VIA VT1708S", 3296 { .id = 0x11064397, .name = "VT1708S",
3311 .patch = patch_vt1708S}, 3297 .patch = patch_vt1708S},
3312 { .id = 0x11065397, .name = "VIA VT1708S", 3298 { .id = 0x11065397, .name = "VT1708S",
3313 .patch = patch_vt1708S}, 3299 .patch = patch_vt1708S},
3314 { .id = 0x11066397, .name = "VIA VT1708S", 3300 { .id = 0x11066397, .name = "VT1708S",
3315 .patch = patch_vt1708S}, 3301 .patch = patch_vt1708S},
3316 { .id = 0x11067397, .name = "VIA VT1708S", 3302 { .id = 0x11067397, .name = "VT1708S",
3317 .patch = patch_vt1708S}, 3303 .patch = patch_vt1708S},
3318 { .id = 0x11060398, .name = "VIA VT1702", 3304 { .id = 0x11060398, .name = "VT1702",
3319 .patch = patch_vt1702}, 3305 .patch = patch_vt1702},
3320 { .id = 0x11061398, .name = "VIA VT1702", 3306 { .id = 0x11061398, .name = "VT1702",
3321 .patch = patch_vt1702}, 3307 .patch = patch_vt1702},
3322 { .id = 0x11062398, .name = "VIA VT1702", 3308 { .id = 0x11062398, .name = "VT1702",
3323 .patch = patch_vt1702}, 3309 .patch = patch_vt1702},
3324 { .id = 0x11063398, .name = "VIA VT1702", 3310 { .id = 0x11063398, .name = "VT1702",
3325 .patch = patch_vt1702}, 3311 .patch = patch_vt1702},
3326 { .id = 0x11064398, .name = "VIA VT1702", 3312 { .id = 0x11064398, .name = "VT1702",
3327 .patch = patch_vt1702}, 3313 .patch = patch_vt1702},
3328 { .id = 0x11065398, .name = "VIA VT1702", 3314 { .id = 0x11065398, .name = "VT1702",
3329 .patch = patch_vt1702}, 3315 .patch = patch_vt1702},
3330 { .id = 0x11066398, .name = "VIA VT1702", 3316 { .id = 0x11066398, .name = "VT1702",
3331 .patch = patch_vt1702}, 3317 .patch = patch_vt1702},
3332 { .id = 0x11067398, .name = "VIA VT1702", 3318 { .id = 0x11067398, .name = "VT1702",
3333 .patch = patch_vt1702}, 3319 .patch = patch_vt1702},
3334 {} /* terminator */ 3320 {} /* terminator */
3335}; 3321};
3322
3323MODULE_ALIAS("snd-hda-codec-id:1106*");
3324
3325static struct hda_codec_preset_list via_list = {
3326 .preset = snd_hda_preset_via,
3327 .owner = THIS_MODULE,
3328};
3329
3330MODULE_LICENSE("GPL");
3331MODULE_DESCRIPTION("VIA HD-audio codec");
3332
3333static int __init patch_via_init(void)
3334{
3335 return snd_hda_add_codec_preset(&via_list);
3336}
3337
3338static void __exit patch_via_exit(void)
3339{
3340 snd_hda_delete_codec_preset(&via_list);
3341}
3342
3343module_init(patch_via_init)
3344module_exit(patch_via_exit)
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 1b3f11702713..0dfa0540ce2c 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -382,23 +382,25 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
382 unsigned char status_mask = 382 unsigned char status_mask =
383 VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX | VT1724_IRQ_MTPCM; 383 VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX | VT1724_IRQ_MTPCM;
384 int handled = 0; 384 int handled = 0;
385#ifdef CONFIG_SND_DEBUG
386 int timeout = 0; 385 int timeout = 0;
387#endif
388 386
389 while (1) { 387 while (1) {
390 status = inb(ICEREG1724(ice, IRQSTAT)); 388 status = inb(ICEREG1724(ice, IRQSTAT));
391 status &= status_mask; 389 status &= status_mask;
392 if (status == 0) 390 if (status == 0)
393 break; 391 break;
394#ifdef CONFIG_SND_DEBUG
395 if (++timeout > 10) { 392 if (++timeout > 10) {
396 printk(KERN_ERR 393 status = inb(ICEREG1724(ice, IRQSTAT));
397 "ice1724: Too long irq loop, status = 0x%x\n", 394 printk(KERN_ERR "ice1724: Too long irq loop, "
398 status); 395 "status = 0x%x\n", status);
396 if (status & VT1724_IRQ_MPU_TX) {
397 printk(KERN_ERR "ice1724: Disabling MPU_TX\n");
398 outb(inb(ICEREG1724(ice, IRQMASK)) |
399 VT1724_IRQ_MPU_TX,
400 ICEREG1724(ice, IRQMASK));
401 }
399 break; 402 break;
400 } 403 }
401#endif
402 handled = 1; 404 handled = 1;
403 if (status & VT1724_IRQ_MPU_TX) { 405 if (status & VT1724_IRQ_MPU_TX) {
404 spin_lock(&ice->reg_lock); 406 spin_lock(&ice->reg_lock);
@@ -2351,7 +2353,6 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2351{ 2353{
2352 struct snd_ice1712 *ice; 2354 struct snd_ice1712 *ice;
2353 int err; 2355 int err;
2354 unsigned char mask;
2355 static struct snd_device_ops ops = { 2356 static struct snd_device_ops ops = {
2356 .dev_free = snd_vt1724_dev_free, 2357 .dev_free = snd_vt1724_dev_free,
2357 }; 2358 };
@@ -2412,9 +2413,9 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2412 return -EIO; 2413 return -EIO;
2413 } 2414 }
2414 2415
2415 /* unmask used interrupts */ 2416 /* MPU_RX and TX irq masks are cleared later dynamically */
2416 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX; 2417 outb(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX , ICEREG1724(ice, IRQMASK));
2417 outb(mask, ICEREG1724(ice, IRQMASK)); 2418
2418 /* don't handle FIFO overrun/underruns (just yet), 2419 /* don't handle FIFO overrun/underruns (just yet),
2419 * since they cause machine lockups 2420 * since they cause machine lockups
2420 */ 2421 */
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 9ff3f9e34404..59bbaf8f3e5b 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -1670,7 +1670,7 @@ static irqreturn_t snd_m3_interrupt(int irq, void *dev_id)
1670 return IRQ_NONE; 1670 return IRQ_NONE;
1671 1671
1672 if (status & HV_INT_PENDING) 1672 if (status & HV_INT_PENDING)
1673 tasklet_hi_schedule(&chip->hwvol_tq); 1673 tasklet_schedule(&chip->hwvol_tq);
1674 1674
1675 /* 1675 /*
1676 * ack an assp int if its running 1676 * ack an assp int if its running
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index ae7601f353a7..f23a73577c22 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -1010,7 +1010,7 @@ static int __devinit snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *
1010 .dev_free = snd_mixart_chip_dev_free, 1010 .dev_free = snd_mixart_chip_dev_free,
1011 }; 1011 };
1012 1012
1013 mgr->chip[idx] = chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1013 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1014 if (! chip) { 1014 if (! chip) {
1015 snd_printk(KERN_ERR "cannot allocate chip\n"); 1015 snd_printk(KERN_ERR "cannot allocate chip\n");
1016 return -ENOMEM; 1016 return -ENOMEM;
@@ -1025,6 +1025,7 @@ static int __devinit snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *
1025 return err; 1025 return err;
1026 } 1026 }
1027 1027
1028 mgr->chip[idx] = chip;
1028 snd_card_set_dev(card, &mgr->pci->dev); 1029 snd_card_set_dev(card, &mgr->pci->dev);
1029 1030
1030 return 0; 1031 return 0;
@@ -1377,6 +1378,7 @@ static int __devinit snd_mixart_probe(struct pci_dev *pci,
1377 sprintf(card->longname, "%s [PCM #%d]", mgr->longname, i); 1378 sprintf(card->longname, "%s [PCM #%d]", mgr->longname, i);
1378 1379
1379 if ((err = snd_mixart_create(mgr, card, i)) < 0) { 1380 if ((err = snd_mixart_create(mgr, card, i)) < 0) {
1381 snd_card_free(card);
1380 snd_mixart_free(mgr); 1382 snd_mixart_free(mgr);
1381 return err; 1383 return err;
1382 } 1384 }
diff --git a/sound/pci/mixart/mixart_core.c b/sound/pci/mixart/mixart_core.c
index b9a06c279397..d3350f383966 100644
--- a/sound/pci/mixart/mixart_core.c
+++ b/sound/pci/mixart/mixart_core.c
@@ -550,7 +550,7 @@ irqreturn_t snd_mixart_interrupt(int irq, void *dev_id)
550 mgr->msg_fifo[mgr->msg_fifo_writeptr] = msg; 550 mgr->msg_fifo[mgr->msg_fifo_writeptr] = msg;
551 mgr->msg_fifo_writeptr++; 551 mgr->msg_fifo_writeptr++;
552 mgr->msg_fifo_writeptr %= MSG_FIFO_SIZE; 552 mgr->msg_fifo_writeptr %= MSG_FIFO_SIZE;
553 tasklet_hi_schedule(&mgr->msg_taskq); 553 tasklet_schedule(&mgr->msg_taskq);
554 } 554 }
555 spin_unlock(&mgr->msg_lock); 555 spin_unlock(&mgr->msg_lock);
556 break; 556 break;
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index b60f6212745a..de999c6d6dd3 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -61,6 +61,7 @@ MODULE_PARM_DESC(enable, "enable card");
61enum { 61enum {
62 MODEL_CMEDIA_REF, /* C-Media's reference design */ 62 MODEL_CMEDIA_REF, /* C-Media's reference design */
63 MODEL_MERIDIAN, /* AuzenTech X-Meridian */ 63 MODEL_MERIDIAN, /* AuzenTech X-Meridian */
64 MODEL_HALO, /* HT-Omega Claro halo */
64}; 65};
65 66
66static struct pci_device_id oxygen_ids[] __devinitdata = { 67static struct pci_device_id oxygen_ids[] __devinitdata = {
@@ -74,6 +75,7 @@ static struct pci_device_id oxygen_ids[] __devinitdata = {
74 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, 75 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF },
75 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN }, 76 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN },
76 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CMEDIA_REF }, 77 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CMEDIA_REF },
78 { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_HALO },
77 { } 79 { }
78}; 80};
79MODULE_DEVICE_TABLE(pci, oxygen_ids); 81MODULE_DEVICE_TABLE(pci, oxygen_ids);
@@ -301,6 +303,8 @@ static int generic_probe(struct oxygen *chip, unsigned long driver_data)
301 PLAYBACK_1_TO_SPDIF | 303 PLAYBACK_1_TO_SPDIF |
302 CAPTURE_0_FROM_I2S_2 | 304 CAPTURE_0_FROM_I2S_2 |
303 CAPTURE_1_FROM_SPDIF; 305 CAPTURE_1_FROM_SPDIF;
306 }
307 if (driver_data == MODEL_MERIDIAN || driver_data == MODEL_HALO) {
304 chip->model.misc_flags = OXYGEN_MISC_MIDI; 308 chip->model.misc_flags = OXYGEN_MISC_MIDI;
305 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT; 309 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT;
306 } 310 }
diff --git a/sound/pci/pcxhr/Makefile b/sound/pci/pcxhr/Makefile
index 10473c05918d..b06128e918ca 100644
--- a/sound/pci/pcxhr/Makefile
+++ b/sound/pci/pcxhr/Makefile
@@ -1,2 +1,2 @@
1snd-pcxhr-objs := pcxhr.o pcxhr_hwdep.o pcxhr_mixer.o pcxhr_core.o 1snd-pcxhr-objs := pcxhr.o pcxhr_hwdep.o pcxhr_mixer.o pcxhr_core.o pcxhr_mix22.o
2obj-$(CONFIG_SND_PCXHR) += snd-pcxhr.o 2obj-$(CONFIG_SND_PCXHR) += snd-pcxhr.o
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index 73de6e989b3d..27cf2c28d113 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -40,18 +40,20 @@
40#include "pcxhr_mixer.h" 40#include "pcxhr_mixer.h"
41#include "pcxhr_hwdep.h" 41#include "pcxhr_hwdep.h"
42#include "pcxhr_core.h" 42#include "pcxhr_core.h"
43#include "pcxhr_mix22.h"
43 44
44#define DRIVER_NAME "pcxhr" 45#define DRIVER_NAME "pcxhr"
45 46
46MODULE_AUTHOR("Markus Bollinger <bollinger@digigram.com>"); 47MODULE_AUTHOR("Markus Bollinger <bollinger@digigram.com>, "
48 "Marc Titinger <titinger@digigram.com>");
47MODULE_DESCRIPTION("Digigram " DRIVER_NAME " " PCXHR_DRIVER_VERSION_STRING); 49MODULE_DESCRIPTION("Digigram " DRIVER_NAME " " PCXHR_DRIVER_VERSION_STRING);
48MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
49MODULE_SUPPORTED_DEVICE("{{Digigram," DRIVER_NAME "}}"); 51MODULE_SUPPORTED_DEVICE("{{Digigram," DRIVER_NAME "}}");
50 52
51static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 53static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
52static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 54static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
53static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 55static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
54static int mono[SNDRV_CARDS]; /* capture in mono only */ 56static int mono[SNDRV_CARDS]; /* capture mono only */
55 57
56module_param_array(index, int, NULL, 0444); 58module_param_array(index, int, NULL, 0444);
57MODULE_PARM_DESC(index, "Index value for Digigram " DRIVER_NAME " soundcard"); 59MODULE_PARM_DESC(index, "Index value for Digigram " DRIVER_NAME " soundcard");
@@ -67,18 +69,58 @@ enum {
67 PCI_ID_PCX882HR, 69 PCI_ID_PCX882HR,
68 PCI_ID_VX881HR, 70 PCI_ID_VX881HR,
69 PCI_ID_PCX881HR, 71 PCI_ID_PCX881HR,
72 PCI_ID_VX882E,
73 PCI_ID_PCX882E,
74 PCI_ID_VX881E,
75 PCI_ID_PCX881E,
76 PCI_ID_VX1222HR,
70 PCI_ID_PCX1222HR, 77 PCI_ID_PCX1222HR,
78 PCI_ID_VX1221HR,
71 PCI_ID_PCX1221HR, 79 PCI_ID_PCX1221HR,
80 PCI_ID_VX1222E,
81 PCI_ID_PCX1222E,
82 PCI_ID_VX1221E,
83 PCI_ID_PCX1221E,
84 PCI_ID_VX222HR,
85 PCI_ID_VX222E,
86 PCI_ID_PCX22HR,
87 PCI_ID_PCX22E,
88 PCI_ID_VX222HRMIC,
89 PCI_ID_VX222E_MIC,
90 PCI_ID_PCX924HR,
91 PCI_ID_PCX924E,
92 PCI_ID_PCX924HRMIC,
93 PCI_ID_PCX924E_MIC,
72 PCI_ID_LAST 94 PCI_ID_LAST
73}; 95};
74 96
75static struct pci_device_id pcxhr_ids[] = { 97static struct pci_device_id pcxhr_ids[] = {
76 { 0x10b5, 0x9656, 0x1369, 0xb001, 0, 0, PCI_ID_VX882HR, }, /* VX882HR */ 98 { 0x10b5, 0x9656, 0x1369, 0xb001, 0, 0, PCI_ID_VX882HR, },
77 { 0x10b5, 0x9656, 0x1369, 0xb101, 0, 0, PCI_ID_PCX882HR, }, /* PCX882HR */ 99 { 0x10b5, 0x9656, 0x1369, 0xb101, 0, 0, PCI_ID_PCX882HR, },
78 { 0x10b5, 0x9656, 0x1369, 0xb201, 0, 0, PCI_ID_VX881HR, }, /* VX881HR */ 100 { 0x10b5, 0x9656, 0x1369, 0xb201, 0, 0, PCI_ID_VX881HR, },
79 { 0x10b5, 0x9656, 0x1369, 0xb301, 0, 0, PCI_ID_PCX881HR, }, /* PCX881HR */ 101 { 0x10b5, 0x9656, 0x1369, 0xb301, 0, 0, PCI_ID_PCX881HR, },
80 { 0x10b5, 0x9656, 0x1369, 0xb501, 0, 0, PCI_ID_PCX1222HR, }, /* PCX1222HR */ 102 { 0x10b5, 0x9056, 0x1369, 0xb021, 0, 0, PCI_ID_VX882E, },
81 { 0x10b5, 0x9656, 0x1369, 0xb701, 0, 0, PCI_ID_PCX1221HR, }, /* PCX1221HR */ 103 { 0x10b5, 0x9056, 0x1369, 0xb121, 0, 0, PCI_ID_PCX882E, },
104 { 0x10b5, 0x9056, 0x1369, 0xb221, 0, 0, PCI_ID_VX881E, },
105 { 0x10b5, 0x9056, 0x1369, 0xb321, 0, 0, PCI_ID_PCX881E, },
106 { 0x10b5, 0x9656, 0x1369, 0xb401, 0, 0, PCI_ID_VX1222HR, },
107 { 0x10b5, 0x9656, 0x1369, 0xb501, 0, 0, PCI_ID_PCX1222HR, },
108 { 0x10b5, 0x9656, 0x1369, 0xb601, 0, 0, PCI_ID_VX1221HR, },
109 { 0x10b5, 0x9656, 0x1369, 0xb701, 0, 0, PCI_ID_PCX1221HR, },
110 { 0x10b5, 0x9056, 0x1369, 0xb421, 0, 0, PCI_ID_VX1222E, },
111 { 0x10b5, 0x9056, 0x1369, 0xb521, 0, 0, PCI_ID_PCX1222E, },
112 { 0x10b5, 0x9056, 0x1369, 0xb621, 0, 0, PCI_ID_VX1221E, },
113 { 0x10b5, 0x9056, 0x1369, 0xb721, 0, 0, PCI_ID_PCX1221E, },
114 { 0x10b5, 0x9056, 0x1369, 0xba01, 0, 0, PCI_ID_VX222HR, },
115 { 0x10b5, 0x9056, 0x1369, 0xba21, 0, 0, PCI_ID_VX222E, },
116 { 0x10b5, 0x9056, 0x1369, 0xbd01, 0, 0, PCI_ID_PCX22HR, },
117 { 0x10b5, 0x9056, 0x1369, 0xbd21, 0, 0, PCI_ID_PCX22E, },
118 { 0x10b5, 0x9056, 0x1369, 0xbc01, 0, 0, PCI_ID_VX222HRMIC, },
119 { 0x10b5, 0x9056, 0x1369, 0xbc21, 0, 0, PCI_ID_VX222E_MIC, },
120 { 0x10b5, 0x9056, 0x1369, 0xbb01, 0, 0, PCI_ID_PCX924HR, },
121 { 0x10b5, 0x9056, 0x1369, 0xbb21, 0, 0, PCI_ID_PCX924E, },
122 { 0x10b5, 0x9056, 0x1369, 0xbf01, 0, 0, PCI_ID_PCX924HRMIC, },
123 { 0x10b5, 0x9056, 0x1369, 0xbf21, 0, 0, PCI_ID_PCX924E_MIC, },
82 { 0, } 124 { 0, }
83}; 125};
84 126
@@ -88,27 +130,55 @@ struct board_parameters {
88 char* board_name; 130 char* board_name;
89 short playback_chips; 131 short playback_chips;
90 short capture_chips; 132 short capture_chips;
133 short fw_file_set;
91 short firmware_num; 134 short firmware_num;
92}; 135};
93static struct board_parameters pcxhr_board_params[] = { 136static struct board_parameters pcxhr_board_params[] = {
94[PCI_ID_VX882HR] = { "VX882HR", 4, 4, 41, }, 137[PCI_ID_VX882HR] = { "VX882HR", 4, 4, 0, 41 },
95[PCI_ID_PCX882HR] = { "PCX882HR", 4, 4, 41, }, 138[PCI_ID_PCX882HR] = { "PCX882HR", 4, 4, 0, 41 },
96[PCI_ID_VX881HR] = { "VX881HR", 4, 4, 41, }, 139[PCI_ID_VX881HR] = { "VX881HR", 4, 4, 0, 41 },
97[PCI_ID_PCX881HR] = { "PCX881HR", 4, 4, 41, }, 140[PCI_ID_PCX881HR] = { "PCX881HR", 4, 4, 0, 41 },
98[PCI_ID_PCX1222HR] = { "PCX1222HR", 6, 1, 42, }, 141[PCI_ID_VX882E] = { "VX882e", 4, 4, 1, 41 },
99[PCI_ID_PCX1221HR] = { "PCX1221HR", 6, 1, 42, }, 142[PCI_ID_PCX882E] = { "PCX882e", 4, 4, 1, 41 },
143[PCI_ID_VX881E] = { "VX881e", 4, 4, 1, 41 },
144[PCI_ID_PCX881E] = { "PCX881e", 4, 4, 1, 41 },
145[PCI_ID_VX1222HR] = { "VX1222HR", 6, 1, 2, 42 },
146[PCI_ID_PCX1222HR] = { "PCX1222HR", 6, 1, 2, 42 },
147[PCI_ID_VX1221HR] = { "VX1221HR", 6, 1, 2, 42 },
148[PCI_ID_PCX1221HR] = { "PCX1221HR", 6, 1, 2, 42 },
149[PCI_ID_VX1222E] = { "VX1222e", 6, 1, 3, 42 },
150[PCI_ID_PCX1222E] = { "PCX1222e", 6, 1, 3, 42 },
151[PCI_ID_VX1221E] = { "VX1221e", 6, 1, 3, 42 },
152[PCI_ID_PCX1221E] = { "PCX1221e", 6, 1, 3, 42 },
153[PCI_ID_VX222HR] = { "VX222HR", 1, 1, 4, 44 },
154[PCI_ID_VX222E] = { "VX222e", 1, 1, 4, 44 },
155[PCI_ID_PCX22HR] = { "PCX22HR", 1, 0, 4, 44 },
156[PCI_ID_PCX22E] = { "PCX22e", 1, 0, 4, 44 },
157[PCI_ID_VX222HRMIC] = { "VX222HR-Mic", 1, 1, 5, 44 },
158[PCI_ID_VX222E_MIC] = { "VX222e-Mic", 1, 1, 5, 44 },
159[PCI_ID_PCX924HR] = { "PCX924HR", 1, 1, 5, 44 },
160[PCI_ID_PCX924E] = { "PCX924e", 1, 1, 5, 44 },
161[PCI_ID_PCX924HRMIC] = { "PCX924HR-Mic", 1, 1, 5, 44 },
162[PCI_ID_PCX924E_MIC] = { "PCX924e-Mic", 1, 1, 5, 44 },
100}; 163};
101 164
165/* boards without hw AES1 and SRC onboard are all using fw_file_set==4 */
166/* VX222HR, VX222e, PCX22HR and PCX22e */
167#define PCXHR_BOARD_HAS_AES1(x) (x->fw_file_set != 4)
168/* some boards do not support 192kHz on digital AES input plugs */
169#define PCXHR_BOARD_AESIN_NO_192K(x) ((x->capture_chips == 0) || \
170 (x->fw_file_set == 0) || \
171 (x->fw_file_set == 2))
102 172
103static int pcxhr_pll_freq_register(unsigned int freq, unsigned int* pllreg, 173static int pcxhr_pll_freq_register(unsigned int freq, unsigned int* pllreg,
104 unsigned int* realfreq) 174 unsigned int* realfreq)
105{ 175{
106 unsigned int reg; 176 unsigned int reg;
107 177
108 if (freq < 6900 || freq > 110250) 178 if (freq < 6900 || freq > 110000)
109 return -EINVAL; 179 return -EINVAL;
110 reg = (28224000 * 10) / freq; 180 reg = (28224000 * 2) / freq;
111 reg = (reg + 5) / 10; 181 reg = (reg - 1) / 2;
112 if (reg < 0x200) 182 if (reg < 0x200)
113 *pllreg = reg + 0x800; 183 *pllreg = reg + 0x800;
114 else if (reg < 0x400) 184 else if (reg < 0x400)
@@ -121,7 +191,7 @@ static int pcxhr_pll_freq_register(unsigned int freq, unsigned int* pllreg,
121 reg &= ~3; 191 reg &= ~3;
122 } 192 }
123 if (realfreq) 193 if (realfreq)
124 *realfreq = ((28224000 * 10) / reg + 5) / 10; 194 *realfreq = (28224000 / (reg + 1));
125 return 0; 195 return 0;
126} 196}
127 197
@@ -151,11 +221,6 @@ static int pcxhr_pll_freq_register(unsigned int freq, unsigned int* pllreg,
151#define PCXHR_FREQ_AES_3 0x03 221#define PCXHR_FREQ_AES_3 0x03
152#define PCXHR_FREQ_AES_4 0x0d 222#define PCXHR_FREQ_AES_4 0x0d
153 223
154#define PCXHR_MODIFY_CLOCK_S_BIT 0x04
155
156#define PCXHR_IRQ_TIMER_FREQ 92000
157#define PCXHR_IRQ_TIMER_PERIOD 48
158
159static int pcxhr_get_clock_reg(struct pcxhr_mgr *mgr, unsigned int rate, 224static int pcxhr_get_clock_reg(struct pcxhr_mgr *mgr, unsigned int rate,
160 unsigned int *reg, unsigned int *freq) 225 unsigned int *reg, unsigned int *freq)
161{ 226{
@@ -196,19 +261,32 @@ static int pcxhr_get_clock_reg(struct pcxhr_mgr *mgr, unsigned int rate,
196 err = pcxhr_send_msg(mgr, &rmh); 261 err = pcxhr_send_msg(mgr, &rmh);
197 if (err < 0) { 262 if (err < 0) {
198 snd_printk(KERN_ERR 263 snd_printk(KERN_ERR
199 "error CMD_ACCESS_IO_WRITE for PLL register : %x!\n", 264 "error CMD_ACCESS_IO_WRITE "
200 err ); 265 "for PLL register : %x!\n", err);
201 return err; 266 return err;
202 } 267 }
203 } 268 }
204 break; 269 break;
205 case PCXHR_CLOCK_TYPE_WORD_CLOCK : val = PCXHR_FREQ_WORD_CLOCK; break; 270 case PCXHR_CLOCK_TYPE_WORD_CLOCK:
206 case PCXHR_CLOCK_TYPE_AES_SYNC : val = PCXHR_FREQ_SYNC_AES; break; 271 val = PCXHR_FREQ_WORD_CLOCK;
207 case PCXHR_CLOCK_TYPE_AES_1 : val = PCXHR_FREQ_AES_1; break; 272 break;
208 case PCXHR_CLOCK_TYPE_AES_2 : val = PCXHR_FREQ_AES_2; break; 273 case PCXHR_CLOCK_TYPE_AES_SYNC:
209 case PCXHR_CLOCK_TYPE_AES_3 : val = PCXHR_FREQ_AES_3; break; 274 val = PCXHR_FREQ_SYNC_AES;
210 case PCXHR_CLOCK_TYPE_AES_4 : val = PCXHR_FREQ_AES_4; break; 275 break;
211 default : return -EINVAL; 276 case PCXHR_CLOCK_TYPE_AES_1:
277 val = PCXHR_FREQ_AES_1;
278 break;
279 case PCXHR_CLOCK_TYPE_AES_2:
280 val = PCXHR_FREQ_AES_2;
281 break;
282 case PCXHR_CLOCK_TYPE_AES_3:
283 val = PCXHR_FREQ_AES_3;
284 break;
285 case PCXHR_CLOCK_TYPE_AES_4:
286 val = PCXHR_FREQ_AES_4;
287 break;
288 default:
289 return -EINVAL;
212 } 290 }
213 *reg = val; 291 *reg = val;
214 *freq = realfreq; 292 *freq = realfreq;
@@ -216,14 +294,13 @@ static int pcxhr_get_clock_reg(struct pcxhr_mgr *mgr, unsigned int rate,
216} 294}
217 295
218 296
219int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate) 297static int pcxhr_sub_set_clock(struct pcxhr_mgr *mgr,
298 unsigned int rate,
299 int *changed)
220{ 300{
221 unsigned int val, realfreq, speed; 301 unsigned int val, realfreq, speed;
222 struct pcxhr_rmh rmh; 302 struct pcxhr_rmh rmh;
223 int err, changed; 303 int err;
224
225 if (rate == 0)
226 return 0; /* nothing to do */
227 304
228 err = pcxhr_get_clock_reg(mgr, rate, &val, &realfreq); 305 err = pcxhr_get_clock_reg(mgr, rate, &val, &realfreq);
229 if (err) 306 if (err)
@@ -237,13 +314,17 @@ int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate)
237 else 314 else
238 speed = 2; /* quad speed */ 315 speed = 2; /* quad speed */
239 if (mgr->codec_speed != speed) { 316 if (mgr->codec_speed != speed) {
240 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); /* mute outputs */ 317 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); /* mute outputs */
241 rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT; 318 rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
319 if (DSP_EXT_CMD_SET(mgr)) {
320 rmh.cmd[1] = 1;
321 rmh.cmd_len = 2;
322 }
242 err = pcxhr_send_msg(mgr, &rmh); 323 err = pcxhr_send_msg(mgr, &rmh);
243 if (err) 324 if (err)
244 return err; 325 return err;
245 326
246 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); /* set speed ratio */ 327 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); /* set speed ratio */
247 rmh.cmd[0] |= IO_NUM_SPEED_RATIO; 328 rmh.cmd[0] |= IO_NUM_SPEED_RATIO;
248 rmh.cmd[1] = speed; 329 rmh.cmd[1] = speed;
249 rmh.cmd_len = 2; 330 rmh.cmd_len = 2;
@@ -253,25 +334,57 @@ int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate)
253 } 334 }
254 /* set the new frequency */ 335 /* set the new frequency */
255 snd_printdd("clock register : set %x\n", val); 336 snd_printdd("clock register : set %x\n", val);
256 err = pcxhr_write_io_num_reg_cont(mgr, PCXHR_FREQ_REG_MASK, val, &changed); 337 err = pcxhr_write_io_num_reg_cont(mgr, PCXHR_FREQ_REG_MASK,
338 val, changed);
257 if (err) 339 if (err)
258 return err; 340 return err;
341
259 mgr->sample_rate_real = realfreq; 342 mgr->sample_rate_real = realfreq;
260 mgr->cur_clock_type = mgr->use_clock_type; 343 mgr->cur_clock_type = mgr->use_clock_type;
261 344
262 /* unmute after codec speed modes */ 345 /* unmute after codec speed modes */
263 if (mgr->codec_speed != speed) { 346 if (mgr->codec_speed != speed) {
264 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); /* unmute outputs */ 347 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); /* unmute outputs */
265 rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT; 348 rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
349 if (DSP_EXT_CMD_SET(mgr)) {
350 rmh.cmd[1] = 1;
351 rmh.cmd_len = 2;
352 }
266 err = pcxhr_send_msg(mgr, &rmh); 353 err = pcxhr_send_msg(mgr, &rmh);
267 if (err) 354 if (err)
268 return err; 355 return err;
269 mgr->codec_speed = speed; /* save new codec speed */ 356 mgr->codec_speed = speed; /* save new codec speed */
270 } 357 }
271 358
359 snd_printdd("pcxhr_sub_set_clock to %dHz (realfreq=%d)\n",
360 rate, realfreq);
361 return 0;
362}
363
364#define PCXHR_MODIFY_CLOCK_S_BIT 0x04
365
366#define PCXHR_IRQ_TIMER_FREQ 92000
367#define PCXHR_IRQ_TIMER_PERIOD 48
368
369int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate)
370{
371 struct pcxhr_rmh rmh;
372 int err, changed;
373
374 if (rate == 0)
375 return 0; /* nothing to do */
376
377 if (mgr->is_hr_stereo)
378 err = hr222_sub_set_clock(mgr, rate, &changed);
379 else
380 err = pcxhr_sub_set_clock(mgr, rate, &changed);
381
382 if (err)
383 return err;
384
272 if (changed) { 385 if (changed) {
273 pcxhr_init_rmh(&rmh, CMD_MODIFY_CLOCK); 386 pcxhr_init_rmh(&rmh, CMD_MODIFY_CLOCK);
274 rmh.cmd[0] |= PCXHR_MODIFY_CLOCK_S_BIT; /* resync fifos */ 387 rmh.cmd[0] |= PCXHR_MODIFY_CLOCK_S_BIT; /* resync fifos */
275 if (rate < PCXHR_IRQ_TIMER_FREQ) 388 if (rate < PCXHR_IRQ_TIMER_FREQ)
276 rmh.cmd[1] = PCXHR_IRQ_TIMER_PERIOD; 389 rmh.cmd[1] = PCXHR_IRQ_TIMER_PERIOD;
277 else 390 else
@@ -282,26 +395,39 @@ int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate)
282 if (err) 395 if (err)
283 return err; 396 return err;
284 } 397 }
285 snd_printdd("pcxhr_set_clock to %dHz (realfreq=%d)\n", rate, realfreq);
286 return 0; 398 return 0;
287} 399}
288 400
289 401
290int pcxhr_get_external_clock(struct pcxhr_mgr *mgr, enum pcxhr_clock_type clock_type, 402static int pcxhr_sub_get_external_clock(struct pcxhr_mgr *mgr,
291 int *sample_rate) 403 enum pcxhr_clock_type clock_type,
404 int *sample_rate)
292{ 405{
293 struct pcxhr_rmh rmh; 406 struct pcxhr_rmh rmh;
294 unsigned char reg; 407 unsigned char reg;
295 int err, rate; 408 int err, rate;
296 409
297 switch (clock_type) { 410 switch (clock_type) {
298 case PCXHR_CLOCK_TYPE_WORD_CLOCK : reg = REG_STATUS_WORD_CLOCK; break; 411 case PCXHR_CLOCK_TYPE_WORD_CLOCK:
299 case PCXHR_CLOCK_TYPE_AES_SYNC : reg = REG_STATUS_AES_SYNC; break; 412 reg = REG_STATUS_WORD_CLOCK;
300 case PCXHR_CLOCK_TYPE_AES_1 : reg = REG_STATUS_AES_1; break; 413 break;
301 case PCXHR_CLOCK_TYPE_AES_2 : reg = REG_STATUS_AES_2; break; 414 case PCXHR_CLOCK_TYPE_AES_SYNC:
302 case PCXHR_CLOCK_TYPE_AES_3 : reg = REG_STATUS_AES_3; break; 415 reg = REG_STATUS_AES_SYNC;
303 case PCXHR_CLOCK_TYPE_AES_4 : reg = REG_STATUS_AES_4; break; 416 break;
304 default : return -EINVAL; 417 case PCXHR_CLOCK_TYPE_AES_1:
418 reg = REG_STATUS_AES_1;
419 break;
420 case PCXHR_CLOCK_TYPE_AES_2:
421 reg = REG_STATUS_AES_2;
422 break;
423 case PCXHR_CLOCK_TYPE_AES_3:
424 reg = REG_STATUS_AES_3;
425 break;
426 case PCXHR_CLOCK_TYPE_AES_4:
427 reg = REG_STATUS_AES_4;
428 break;
429 default:
430 return -EINVAL;
305 } 431 }
306 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); 432 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
307 rmh.cmd_len = 2; 433 rmh.cmd_len = 2;
@@ -311,7 +437,7 @@ int pcxhr_get_external_clock(struct pcxhr_mgr *mgr, enum pcxhr_clock_type clock_
311 err = pcxhr_send_msg(mgr, &rmh); 437 err = pcxhr_send_msg(mgr, &rmh);
312 if (err) 438 if (err)
313 return err; 439 return err;
314 udelay(100); /* wait minimum 2 sample_frames at 32kHz ! */ 440 udelay(100); /* wait minimum 2 sample_frames at 32kHz ! */
315 mgr->last_reg_stat = reg; 441 mgr->last_reg_stat = reg;
316 } 442 }
317 rmh.cmd[1] = REG_STATUS_CURRENT; 443 rmh.cmd[1] = REG_STATUS_CURRENT;
@@ -336,6 +462,18 @@ int pcxhr_get_external_clock(struct pcxhr_mgr *mgr, enum pcxhr_clock_type clock_
336} 462}
337 463
338 464
465int pcxhr_get_external_clock(struct pcxhr_mgr *mgr,
466 enum pcxhr_clock_type clock_type,
467 int *sample_rate)
468{
469 if (mgr->is_hr_stereo)
470 return hr222_get_external_clock(mgr, clock_type,
471 sample_rate);
472 else
473 return pcxhr_sub_get_external_clock(mgr, clock_type,
474 sample_rate);
475}
476
339/* 477/*
340 * start or stop playback/capture substream 478 * start or stop playback/capture substream
341 */ 479 */
@@ -350,7 +488,8 @@ static int pcxhr_set_stream_state(struct pcxhr_stream *stream)
350 start = 1; 488 start = 1;
351 else { 489 else {
352 if (stream->status != PCXHR_STREAM_STATUS_SCHEDULE_STOP) { 490 if (stream->status != PCXHR_STREAM_STATUS_SCHEDULE_STOP) {
353 snd_printk(KERN_ERR "ERROR pcxhr_set_stream_state CANNOT be stopped\n"); 491 snd_printk(KERN_ERR "ERROR pcxhr_set_stream_state "
492 "CANNOT be stopped\n");
354 return -EINVAL; 493 return -EINVAL;
355 } 494 }
356 start = 0; 495 start = 0;
@@ -359,11 +498,12 @@ static int pcxhr_set_stream_state(struct pcxhr_stream *stream)
359 return -EINVAL; 498 return -EINVAL;
360 499
361 stream->timer_abs_periods = 0; 500 stream->timer_abs_periods = 0;
362 stream->timer_period_frag = 0; /* reset theoretical stream pos */ 501 stream->timer_period_frag = 0; /* reset theoretical stream pos */
363 stream->timer_buf_periods = 0; 502 stream->timer_buf_periods = 0;
364 stream->timer_is_synced = 0; 503 stream->timer_is_synced = 0;
365 504
366 stream_mask = stream->pipe->is_capture ? 1 : 1<<stream->substream->number; 505 stream_mask =
506 stream->pipe->is_capture ? 1 : 1<<stream->substream->number;
367 507
368 pcxhr_init_rmh(&rmh, start ? CMD_START_STREAM : CMD_STOP_STREAM); 508 pcxhr_init_rmh(&rmh, start ? CMD_START_STREAM : CMD_STOP_STREAM);
369 pcxhr_set_pipe_cmd_params(&rmh, stream->pipe->is_capture, 509 pcxhr_set_pipe_cmd_params(&rmh, stream->pipe->is_capture,
@@ -373,8 +513,10 @@ static int pcxhr_set_stream_state(struct pcxhr_stream *stream)
373 513
374 err = pcxhr_send_msg(chip->mgr, &rmh); 514 err = pcxhr_send_msg(chip->mgr, &rmh);
375 if (err) 515 if (err)
376 snd_printk(KERN_ERR "ERROR pcxhr_set_stream_state err=%x;\n", err); 516 snd_printk(KERN_ERR "ERROR pcxhr_set_stream_state err=%x;\n",
377 stream->status = start ? PCXHR_STREAM_STATUS_STARTED : PCXHR_STREAM_STATUS_STOPPED; 517 err);
518 stream->status =
519 start ? PCXHR_STREAM_STATUS_STARTED : PCXHR_STREAM_STATUS_STOPPED;
378 return err; 520 return err;
379} 521}
380 522
@@ -399,13 +541,15 @@ static int pcxhr_set_format(struct pcxhr_stream *stream)
399 header = HEADER_FMT_BASE_LIN; 541 header = HEADER_FMT_BASE_LIN;
400 break; 542 break;
401 case SNDRV_PCM_FORMAT_S16_LE: 543 case SNDRV_PCM_FORMAT_S16_LE:
402 header = HEADER_FMT_BASE_LIN | HEADER_FMT_16BITS | HEADER_FMT_INTEL; 544 header = HEADER_FMT_BASE_LIN |
545 HEADER_FMT_16BITS | HEADER_FMT_INTEL;
403 break; 546 break;
404 case SNDRV_PCM_FORMAT_S16_BE: 547 case SNDRV_PCM_FORMAT_S16_BE:
405 header = HEADER_FMT_BASE_LIN | HEADER_FMT_16BITS; 548 header = HEADER_FMT_BASE_LIN | HEADER_FMT_16BITS;
406 break; 549 break;
407 case SNDRV_PCM_FORMAT_S24_3LE: 550 case SNDRV_PCM_FORMAT_S24_3LE:
408 header = HEADER_FMT_BASE_LIN | HEADER_FMT_24BITS | HEADER_FMT_INTEL; 551 header = HEADER_FMT_BASE_LIN |
552 HEADER_FMT_24BITS | HEADER_FMT_INTEL;
409 break; 553 break;
410 case SNDRV_PCM_FORMAT_S24_3BE: 554 case SNDRV_PCM_FORMAT_S24_3BE:
411 header = HEADER_FMT_BASE_LIN | HEADER_FMT_24BITS; 555 header = HEADER_FMT_BASE_LIN | HEADER_FMT_24BITS;
@@ -414,7 +558,8 @@ static int pcxhr_set_format(struct pcxhr_stream *stream)
414 header = HEADER_FMT_BASE_FLOAT | HEADER_FMT_INTEL; 558 header = HEADER_FMT_BASE_FLOAT | HEADER_FMT_INTEL;
415 break; 559 break;
416 default: 560 default:
417 snd_printk(KERN_ERR "error pcxhr_set_format() : unknown format\n"); 561 snd_printk(KERN_ERR
562 "error pcxhr_set_format() : unknown format\n");
418 return -EINVAL; 563 return -EINVAL;
419 } 564 }
420 chip = snd_pcm_substream_chip(stream->substream); 565 chip = snd_pcm_substream_chip(stream->substream);
@@ -432,14 +577,31 @@ static int pcxhr_set_format(struct pcxhr_stream *stream)
432 is_capture = stream->pipe->is_capture; 577 is_capture = stream->pipe->is_capture;
433 stream_num = is_capture ? 0 : stream->substream->number; 578 stream_num = is_capture ? 0 : stream->substream->number;
434 579
435 pcxhr_init_rmh(&rmh, is_capture ? CMD_FORMAT_STREAM_IN : CMD_FORMAT_STREAM_OUT); 580 pcxhr_init_rmh(&rmh, is_capture ?
436 pcxhr_set_pipe_cmd_params(&rmh, is_capture, stream->pipe->first_audio, stream_num, 0); 581 CMD_FORMAT_STREAM_IN : CMD_FORMAT_STREAM_OUT);
437 if (is_capture) 582 pcxhr_set_pipe_cmd_params(&rmh, is_capture, stream->pipe->first_audio,
438 rmh.cmd[0] |= 1<<12; 583 stream_num, 0);
584 if (is_capture) {
585 /* bug with old dsp versions: */
586 /* bit 12 also sets the format of the playback stream */
587 if (DSP_EXT_CMD_SET(chip->mgr))
588 rmh.cmd[0] |= 1<<10;
589 else
590 rmh.cmd[0] |= 1<<12;
591 }
439 rmh.cmd[1] = 0; 592 rmh.cmd[1] = 0;
440 rmh.cmd[2] = header >> 8; 593 rmh.cmd_len = 2;
441 rmh.cmd[3] = (header & 0xff) << 16; 594 if (DSP_EXT_CMD_SET(chip->mgr)) {
442 rmh.cmd_len = 4; 595 /* add channels and set bit 19 if channels>2 */
596 rmh.cmd[1] = stream->channels;
597 if (!is_capture) {
598 /* playback : add channel mask to command */
599 rmh.cmd[2] = (stream->channels == 1) ? 0x01 : 0x03;
600 rmh.cmd_len = 3;
601 }
602 }
603 rmh.cmd[rmh.cmd_len++] = header >> 8;
604 rmh.cmd[rmh.cmd_len++] = (header & 0xff) << 16;
443 err = pcxhr_send_msg(chip->mgr, &rmh); 605 err = pcxhr_send_msg(chip->mgr, &rmh);
444 if (err) 606 if (err)
445 snd_printk(KERN_ERR "ERROR pcxhr_set_format err=%x;\n", err); 607 snd_printk(KERN_ERR "ERROR pcxhr_set_format err=%x;\n", err);
@@ -456,30 +618,38 @@ static int pcxhr_update_r_buffer(struct pcxhr_stream *stream)
456 is_capture = (subs->stream == SNDRV_PCM_STREAM_CAPTURE); 618 is_capture = (subs->stream == SNDRV_PCM_STREAM_CAPTURE);
457 stream_num = is_capture ? 0 : subs->number; 619 stream_num = is_capture ? 0 : subs->number;
458 620
459 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : addr(%p) bytes(%zx) subs(%d)\n", 621 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : "
622 "addr(%p) bytes(%zx) subs(%d)\n",
460 is_capture ? 'c' : 'p', 623 is_capture ? 'c' : 'p',
461 chip->chip_idx, (void *)(long)subs->runtime->dma_addr, 624 chip->chip_idx, (void *)(long)subs->runtime->dma_addr,
462 subs->runtime->dma_bytes, subs->number); 625 subs->runtime->dma_bytes, subs->number);
463 626
464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS); 627 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS);
465 pcxhr_set_pipe_cmd_params(&rmh, is_capture, stream->pipe->first_audio, stream_num, 0); 628 pcxhr_set_pipe_cmd_params(&rmh, is_capture, stream->pipe->first_audio,
629 stream_num, 0);
466 630
467 /* max buffer size is 2 MByte */ 631 /* max buffer size is 2 MByte */
468 snd_BUG_ON(subs->runtime->dma_bytes >= 0x200000); 632 snd_BUG_ON(subs->runtime->dma_bytes >= 0x200000);
469 rmh.cmd[1] = subs->runtime->dma_bytes * 8; /* size in bits */ 633 /* size in bits */
470 rmh.cmd[2] = subs->runtime->dma_addr >> 24; /* most significant byte */ 634 rmh.cmd[1] = subs->runtime->dma_bytes * 8;
471 rmh.cmd[2] |= 1<<19; /* this is a circular buffer */ 635 /* most significant byte */
472 rmh.cmd[3] = subs->runtime->dma_addr & MASK_DSP_WORD; /* least 3 significant bytes */ 636 rmh.cmd[2] = subs->runtime->dma_addr >> 24;
637 /* this is a circular buffer */
638 rmh.cmd[2] |= 1<<19;
639 /* least 3 significant bytes */
640 rmh.cmd[3] = subs->runtime->dma_addr & MASK_DSP_WORD;
473 rmh.cmd_len = 4; 641 rmh.cmd_len = 4;
474 err = pcxhr_send_msg(chip->mgr, &rmh); 642 err = pcxhr_send_msg(chip->mgr, &rmh);
475 if (err) 643 if (err)
476 snd_printk(KERN_ERR "ERROR CMD_UPDATE_R_BUFFERS err=%x;\n", err); 644 snd_printk(KERN_ERR
645 "ERROR CMD_UPDATE_R_BUFFERS err=%x;\n", err);
477 return err; 646 return err;
478} 647}
479 648
480 649
481#if 0 650#if 0
482static int pcxhr_pipe_sample_count(struct pcxhr_stream *stream, snd_pcm_uframes_t *sample_count) 651static int pcxhr_pipe_sample_count(struct pcxhr_stream *stream,
652 snd_pcm_uframes_t *sample_count)
483{ 653{
484 struct pcxhr_rmh rmh; 654 struct pcxhr_rmh rmh;
485 int err; 655 int err;
@@ -533,8 +703,8 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
533 for (j = 0; j < chip->nb_streams_play; j++) { 703 for (j = 0; j < chip->nb_streams_play; j++) {
534 if (pcxhr_stream_scheduled_get_pipe(&chip->playback_stream[j], &pipe)) { 704 if (pcxhr_stream_scheduled_get_pipe(&chip->playback_stream[j], &pipe)) {
535 playback_mask |= (1 << pipe->first_audio); 705 playback_mask |= (1 << pipe->first_audio);
536 break; /* add only once, as all playback streams of 706 break; /* add only once, as all playback
537 * one chip use the same pipe 707 * streams of one chip use the same pipe
538 */ 708 */
539 } 709 }
540 } 710 }
@@ -545,19 +715,21 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
545 return; 715 return;
546 } 716 }
547 717
548 snd_printdd("pcxhr_trigger_tasklet : playback_mask=%x capture_mask=%x\n", 718 snd_printdd("pcxhr_trigger_tasklet : "
719 "playback_mask=%x capture_mask=%x\n",
549 playback_mask, capture_mask); 720 playback_mask, capture_mask);
550 721
551 /* synchronous stop of all the pipes concerned */ 722 /* synchronous stop of all the pipes concerned */
552 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 0); 723 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 0);
553 if (err) { 724 if (err) {
554 mutex_unlock(&mgr->setup_mutex); 725 mutex_unlock(&mgr->setup_mutex);
555 snd_printk(KERN_ERR "pcxhr_trigger_tasklet : error stop pipes (P%x C%x)\n", 726 snd_printk(KERN_ERR "pcxhr_trigger_tasklet : "
727 "error stop pipes (P%x C%x)\n",
556 playback_mask, capture_mask); 728 playback_mask, capture_mask);
557 return; 729 return;
558 } 730 }
559 731
560 /* unfortunately the dsp lost format and buffer info with the stop pipe */ 732 /* the dsp lost format and buffer info with the stop pipe */
561 for (i = 0; i < mgr->num_cards; i++) { 733 for (i = 0; i < mgr->num_cards; i++) {
562 struct pcxhr_stream *stream; 734 struct pcxhr_stream *stream;
563 chip = mgr->chip[i]; 735 chip = mgr->chip[i];
@@ -596,12 +768,15 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
596 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1); 768 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1);
597 if (err) { 769 if (err) {
598 mutex_unlock(&mgr->setup_mutex); 770 mutex_unlock(&mgr->setup_mutex);
599 snd_printk(KERN_ERR "pcxhr_trigger_tasklet : error start pipes (P%x C%x)\n", 771 snd_printk(KERN_ERR "pcxhr_trigger_tasklet : "
772 "error start pipes (P%x C%x)\n",
600 playback_mask, capture_mask); 773 playback_mask, capture_mask);
601 return; 774 return;
602 } 775 }
603 776
604 /* put the streams into the running state now (increment pointer by interrupt) */ 777 /* put the streams into the running state now
778 * (increment pointer by interrupt)
779 */
605 spin_lock_irqsave(&mgr->lock, flags); 780 spin_lock_irqsave(&mgr->lock, flags);
606 for ( i =0; i < mgr->num_cards; i++) { 781 for ( i =0; i < mgr->num_cards; i++) {
607 struct pcxhr_stream *stream; 782 struct pcxhr_stream *stream;
@@ -615,7 +790,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
615 stream = &chip->playback_stream[j]; 790 stream = &chip->playback_stream[j];
616 if (stream->status == PCXHR_STREAM_STATUS_STARTED) { 791 if (stream->status == PCXHR_STREAM_STATUS_STARTED) {
617 /* playback will already have advanced ! */ 792 /* playback will already have advanced ! */
618 stream->timer_period_frag += PCXHR_GRANULARITY; 793 stream->timer_period_frag += mgr->granularity;
619 stream->status = PCXHR_STREAM_STATUS_RUNNING; 794 stream->status = PCXHR_STREAM_STATUS_RUNNING;
620 } 795 }
621 } 796 }
@@ -653,7 +828,7 @@ static int pcxhr_trigger(struct snd_pcm_substream *subs, int cmd)
653 PCXHR_STREAM_STATUS_SCHEDULE_RUN; 828 PCXHR_STREAM_STATUS_SCHEDULE_RUN;
654 snd_pcm_trigger_done(s, subs); 829 snd_pcm_trigger_done(s, subs);
655 } 830 }
656 tasklet_hi_schedule(&chip->mgr->trigger_taskq); 831 tasklet_schedule(&chip->mgr->trigger_taskq);
657 } else { 832 } else {
658 stream = subs->runtime->private_data; 833 stream = subs->runtime->private_data;
659 snd_printdd("Only one Substream %c %d\n", 834 snd_printdd("Only one Substream %c %d\n",
@@ -697,12 +872,14 @@ static int pcxhr_hardware_timer(struct pcxhr_mgr *mgr, int start)
697 872
698 pcxhr_init_rmh(&rmh, CMD_SET_TIMER_INTERRUPT); 873 pcxhr_init_rmh(&rmh, CMD_SET_TIMER_INTERRUPT);
699 if (start) { 874 if (start) {
700 mgr->dsp_time_last = PCXHR_DSP_TIME_INVALID; /* last dsp time invalid */ 875 /* last dsp time invalid */
701 rmh.cmd[0] |= PCXHR_GRANULARITY; 876 mgr->dsp_time_last = PCXHR_DSP_TIME_INVALID;
877 rmh.cmd[0] |= mgr->granularity;
702 } 878 }
703 err = pcxhr_send_msg(mgr, &rmh); 879 err = pcxhr_send_msg(mgr, &rmh);
704 if (err < 0) 880 if (err < 0)
705 snd_printk(KERN_ERR "error pcxhr_hardware_timer err(%x)\n", err); 881 snd_printk(KERN_ERR "error pcxhr_hardware_timer err(%x)\n",
882 err);
706 return err; 883 return err;
707} 884}
708 885
@@ -713,38 +890,16 @@ static int pcxhr_prepare(struct snd_pcm_substream *subs)
713{ 890{
714 struct snd_pcxhr *chip = snd_pcm_substream_chip(subs); 891 struct snd_pcxhr *chip = snd_pcm_substream_chip(subs);
715 struct pcxhr_mgr *mgr = chip->mgr; 892 struct pcxhr_mgr *mgr = chip->mgr;
716 /*
717 struct pcxhr_stream *stream = (pcxhr_stream_t*)subs->runtime->private_data;
718 */
719 int err = 0; 893 int err = 0;
720 894
721 snd_printdd("pcxhr_prepare : period_size(%lx) periods(%x) buffer_size(%lx)\n", 895 snd_printdd("pcxhr_prepare : period_size(%lx) periods(%x) buffer_size(%lx)\n",
722 subs->runtime->period_size, subs->runtime->periods, 896 subs->runtime->period_size, subs->runtime->periods,
723 subs->runtime->buffer_size); 897 subs->runtime->buffer_size);
724 898
725 /*
726 if(subs->runtime->period_size <= PCXHR_GRANULARITY) {
727 snd_printk(KERN_ERR "pcxhr_prepare : error period_size too small (%x)\n",
728 (unsigned int)subs->runtime->period_size);
729 return -EINVAL;
730 }
731 */
732
733 mutex_lock(&mgr->setup_mutex); 899 mutex_lock(&mgr->setup_mutex);
734 900
735 do { 901 do {
736 /* if the stream was stopped before, format and buffer were reset */
737 /*
738 if(stream->status == PCXHR_STREAM_STATUS_STOPPED) {
739 err = pcxhr_set_format(stream);
740 if(err) break;
741 err = pcxhr_update_r_buffer(stream);
742 if(err) break;
743 }
744 */
745
746 /* only the first stream can choose the sample rate */ 902 /* only the first stream can choose the sample rate */
747 /* the further opened streams will be limited to its frequency (see open) */
748 /* set the clock only once (first stream) */ 903 /* set the clock only once (first stream) */
749 if (mgr->sample_rate != subs->runtime->rate) { 904 if (mgr->sample_rate != subs->runtime->rate) {
750 err = pcxhr_set_clock(mgr, subs->runtime->rate); 905 err = pcxhr_set_clock(mgr, subs->runtime->rate);
@@ -787,22 +942,9 @@ static int pcxhr_hw_params(struct snd_pcm_substream *subs,
787 stream->channels = channels; 942 stream->channels = channels;
788 stream->format = format; 943 stream->format = format;
789 944
790 /* set the format to the board */
791 /*
792 err = pcxhr_set_format(stream);
793 if(err) {
794 mutex_unlock(&mgr->setup_mutex);
795 return err;
796 }
797 */
798 /* allocate buffer */ 945 /* allocate buffer */
799 err = snd_pcm_lib_malloc_pages(subs, params_buffer_bytes(hw)); 946 err = snd_pcm_lib_malloc_pages(subs, params_buffer_bytes(hw));
800 947
801 /*
802 if (err > 0) {
803 err = pcxhr_update_r_buffer(stream);
804 }
805 */
806 mutex_unlock(&mgr->setup_mutex); 948 mutex_unlock(&mgr->setup_mutex);
807 949
808 return err; 950 return err;
@@ -820,14 +962,18 @@ static int pcxhr_hw_free(struct snd_pcm_substream *subs)
820 */ 962 */
821static struct snd_pcm_hardware pcxhr_caps = 963static struct snd_pcm_hardware pcxhr_caps =
822{ 964{
823 .info = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 965 .info = (SNDRV_PCM_INFO_MMAP |
824 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START | 966 SNDRV_PCM_INFO_INTERLEAVED |
825 0 /*SNDRV_PCM_INFO_PAUSE*/), 967 SNDRV_PCM_INFO_MMAP_VALID |
826 .formats = ( SNDRV_PCM_FMTBIT_U8 | 968 SNDRV_PCM_INFO_SYNC_START),
827 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | 969 .formats = (SNDRV_PCM_FMTBIT_U8 |
828 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | 970 SNDRV_PCM_FMTBIT_S16_LE |
829 SNDRV_PCM_FMTBIT_FLOAT_LE ), 971 SNDRV_PCM_FMTBIT_S16_BE |
830 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_192000, 972 SNDRV_PCM_FMTBIT_S24_3LE |
973 SNDRV_PCM_FMTBIT_S24_3BE |
974 SNDRV_PCM_FMTBIT_FLOAT_LE),
975 .rates = (SNDRV_PCM_RATE_CONTINUOUS |
976 SNDRV_PCM_RATE_8000_192000),
831 .rate_min = 8000, 977 .rate_min = 8000,
832 .rate_max = 192000, 978 .rate_max = 192000,
833 .channels_min = 1, 979 .channels_min = 1,
@@ -847,6 +993,7 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
847 struct pcxhr_mgr *mgr = chip->mgr; 993 struct pcxhr_mgr *mgr = chip->mgr;
848 struct snd_pcm_runtime *runtime = subs->runtime; 994 struct snd_pcm_runtime *runtime = subs->runtime;
849 struct pcxhr_stream *stream; 995 struct pcxhr_stream *stream;
996 int err;
850 997
851 mutex_lock(&mgr->setup_mutex); 998 mutex_lock(&mgr->setup_mutex);
852 999
@@ -874,6 +1021,18 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
874 return -EBUSY; 1021 return -EBUSY;
875 } 1022 }
876 1023
1024 /* float format support is in some cases buggy on stereo cards */
1025 if (mgr->is_hr_stereo)
1026 runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_FLOAT_LE;
1027
1028 /* buffer-size should better be multiple of period-size */
1029 err = snd_pcm_hw_constraint_integer(runtime,
1030 SNDRV_PCM_HW_PARAM_PERIODS);
1031 if (err < 0) {
1032 mutex_unlock(&mgr->setup_mutex);
1033 return err;
1034 }
1035
877 /* if a sample rate is already used or fixed by external clock, 1036 /* if a sample rate is already used or fixed by external clock,
878 * the stream cannot change 1037 * the stream cannot change
879 */ 1038 */
@@ -889,7 +1048,8 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
889 mutex_unlock(&mgr->setup_mutex); 1048 mutex_unlock(&mgr->setup_mutex);
890 return -EBUSY; 1049 return -EBUSY;
891 } 1050 }
892 runtime->hw.rate_min = runtime->hw.rate_max = external_rate; 1051 runtime->hw.rate_min = external_rate;
1052 runtime->hw.rate_max = external_rate;
893 } 1053 }
894 } 1054 }
895 1055
@@ -899,9 +1059,11 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
899 1059
900 runtime->private_data = stream; 1060 runtime->private_data = stream;
901 1061
902 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 4); 1062 /* better get a divisor of granularity values (96 or 192) */
903 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4); 1063 snd_pcm_hw_constraint_step(runtime, 0,
904 1064 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);
1065 snd_pcm_hw_constraint_step(runtime, 0,
1066 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32);
905 snd_pcm_set_sync(subs); 1067 snd_pcm_set_sync(subs);
906 1068
907 mgr->ref_count_rate++; 1069 mgr->ref_count_rate++;
@@ -919,11 +1081,12 @@ static int pcxhr_close(struct snd_pcm_substream *subs)
919 1081
920 mutex_lock(&mgr->setup_mutex); 1082 mutex_lock(&mgr->setup_mutex);
921 1083
922 snd_printdd("pcxhr_close chip%d subs%d\n", chip->chip_idx, subs->number); 1084 snd_printdd("pcxhr_close chip%d subs%d\n",
1085 chip->chip_idx, subs->number);
923 1086
924 /* sample rate released */ 1087 /* sample rate released */
925 if (--mgr->ref_count_rate == 0) { 1088 if (--mgr->ref_count_rate == 0) {
926 mgr->sample_rate = 0; /* the sample rate is no more locked */ 1089 mgr->sample_rate = 0; /* the sample rate is no more locked */
927 pcxhr_hardware_timer(mgr, 0); /* stop the DSP-timer */ 1090 pcxhr_hardware_timer(mgr, 0); /* stop the DSP-timer */
928 } 1091 }
929 1092
@@ -1016,7 +1179,8 @@ static int pcxhr_chip_dev_free(struct snd_device *device)
1016 1179
1017/* 1180/*
1018 */ 1181 */
1019static int __devinit pcxhr_create(struct pcxhr_mgr *mgr, struct snd_card *card, int idx) 1182static int __devinit pcxhr_create(struct pcxhr_mgr *mgr,
1183 struct snd_card *card, int idx)
1020{ 1184{
1021 int err; 1185 int err;
1022 struct snd_pcxhr *chip; 1186 struct snd_pcxhr *chip;
@@ -1024,7 +1188,7 @@ static int __devinit pcxhr_create(struct pcxhr_mgr *mgr, struct snd_card *card,
1024 .dev_free = pcxhr_chip_dev_free, 1188 .dev_free = pcxhr_chip_dev_free,
1025 }; 1189 };
1026 1190
1027 mgr->chip[idx] = chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1191 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1028 if (! chip) { 1192 if (! chip) {
1029 snd_printk(KERN_ERR "cannot allocate chip\n"); 1193 snd_printk(KERN_ERR "cannot allocate chip\n");
1030 return -ENOMEM; 1194 return -ENOMEM;
@@ -1040,7 +1204,7 @@ static int __devinit pcxhr_create(struct pcxhr_mgr *mgr, struct snd_card *card,
1040 1204
1041 if (idx < mgr->capture_chips) { 1205 if (idx < mgr->capture_chips) {
1042 if (mgr->mono_capture) 1206 if (mgr->mono_capture)
1043 chip->nb_streams_capt = 2; /* 2 mono streams (left+right) */ 1207 chip->nb_streams_capt = 2; /* 2 mono streams */
1044 else 1208 else
1045 chip->nb_streams_capt = 1; /* or 1 stereo stream */ 1209 chip->nb_streams_capt = 1; /* or 1 stereo stream */
1046 } 1210 }
@@ -1050,13 +1214,15 @@ static int __devinit pcxhr_create(struct pcxhr_mgr *mgr, struct snd_card *card,
1050 return err; 1214 return err;
1051 } 1215 }
1052 1216
1217 mgr->chip[idx] = chip;
1053 snd_card_set_dev(card, &mgr->pci->dev); 1218 snd_card_set_dev(card, &mgr->pci->dev);
1054 1219
1055 return 0; 1220 return 0;
1056} 1221}
1057 1222
1058/* proc interface */ 1223/* proc interface */
1059static void pcxhr_proc_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 1224static void pcxhr_proc_info(struct snd_info_entry *entry,
1225 struct snd_info_buffer *buffer)
1060{ 1226{
1061 struct snd_pcxhr *chip = entry->private_data; 1227 struct snd_pcxhr *chip = entry->private_data;
1062 struct pcxhr_mgr *mgr = chip->mgr; 1228 struct pcxhr_mgr *mgr = chip->mgr;
@@ -1069,8 +1235,10 @@ static void pcxhr_proc_info(struct snd_info_entry *entry, struct snd_info_buffer
1069 short ver_maj = (mgr->dsp_version >> 16) & 0xff; 1235 short ver_maj = (mgr->dsp_version >> 16) & 0xff;
1070 short ver_min = (mgr->dsp_version >> 8) & 0xff; 1236 short ver_min = (mgr->dsp_version >> 8) & 0xff;
1071 short ver_build = mgr->dsp_version & 0xff; 1237 short ver_build = mgr->dsp_version & 0xff;
1072 snd_iprintf(buffer, "module version %s\n", PCXHR_DRIVER_VERSION_STRING); 1238 snd_iprintf(buffer, "module version %s\n",
1073 snd_iprintf(buffer, "dsp version %d.%d.%d\n", ver_maj, ver_min, ver_build); 1239 PCXHR_DRIVER_VERSION_STRING);
1240 snd_iprintf(buffer, "dsp version %d.%d.%d\n",
1241 ver_maj, ver_min, ver_build);
1074 if (mgr->board_has_analog) 1242 if (mgr->board_has_analog)
1075 snd_iprintf(buffer, "analog io available\n"); 1243 snd_iprintf(buffer, "analog io available\n");
1076 else 1244 else
@@ -1084,18 +1252,22 @@ static void pcxhr_proc_info(struct snd_info_entry *entry, struct snd_info_buffer
1084 if (ref > 0) { 1252 if (ref > 0) {
1085 if (mgr->sample_rate_real != 0 && 1253 if (mgr->sample_rate_real != 0 &&
1086 mgr->sample_rate_real != 48000) { 1254 mgr->sample_rate_real != 48000) {
1087 ref = (ref * 48000) / mgr->sample_rate_real; 1255 ref = (ref * 48000) /
1088 if (mgr->sample_rate_real >= PCXHR_IRQ_TIMER_FREQ) 1256 mgr->sample_rate_real;
1257 if (mgr->sample_rate_real >=
1258 PCXHR_IRQ_TIMER_FREQ)
1089 ref *= 2; 1259 ref *= 2;
1090 } 1260 }
1091 cur = 100 - (100 * cur) / ref; 1261 cur = 100 - (100 * cur) / ref;
1092 snd_iprintf(buffer, "cpu load %d%%\n", cur); 1262 snd_iprintf(buffer, "cpu load %d%%\n", cur);
1093 snd_iprintf(buffer, "buffer pool %d/%d kWords\n", 1263 snd_iprintf(buffer, "buffer pool %d/%d\n",
1094 rmh.stat[2], rmh.stat[3]); 1264 rmh.stat[2], rmh.stat[3]);
1095 } 1265 }
1096 } 1266 }
1097 snd_iprintf(buffer, "dma granularity : %d\n", PCXHR_GRANULARITY); 1267 snd_iprintf(buffer, "dma granularity : %d\n",
1098 snd_iprintf(buffer, "dsp time errors : %d\n", mgr->dsp_time_err); 1268 mgr->granularity);
1269 snd_iprintf(buffer, "dsp time errors : %d\n",
1270 mgr->dsp_time_err);
1099 snd_iprintf(buffer, "dsp async pipe xrun errors : %d\n", 1271 snd_iprintf(buffer, "dsp async pipe xrun errors : %d\n",
1100 mgr->async_err_pipe_xrun); 1272 mgr->async_err_pipe_xrun);
1101 snd_iprintf(buffer, "dsp async stream xrun errors : %d\n", 1273 snd_iprintf(buffer, "dsp async stream xrun errors : %d\n",
@@ -1110,33 +1282,52 @@ static void pcxhr_proc_info(struct snd_info_entry *entry, struct snd_info_buffer
1110 rmh.cmd_idx = CMD_LAST_INDEX; 1282 rmh.cmd_idx = CMD_LAST_INDEX;
1111 if( ! pcxhr_send_msg(mgr, &rmh) ) { 1283 if( ! pcxhr_send_msg(mgr, &rmh) ) {
1112 int i; 1284 int i;
1285 if (rmh.stat_len > 8)
1286 rmh.stat_len = 8;
1113 for (i = 0; i < rmh.stat_len; i++) 1287 for (i = 0; i < rmh.stat_len; i++)
1114 snd_iprintf(buffer, "debug[%02d] = %06x\n", i, rmh.stat[i]); 1288 snd_iprintf(buffer, "debug[%02d] = %06x\n",
1289 i, rmh.stat[i]);
1115 } 1290 }
1116 } else 1291 } else
1117 snd_iprintf(buffer, "no firmware loaded\n"); 1292 snd_iprintf(buffer, "no firmware loaded\n");
1118 snd_iprintf(buffer, "\n"); 1293 snd_iprintf(buffer, "\n");
1119} 1294}
1120static void pcxhr_proc_sync(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 1295static void pcxhr_proc_sync(struct snd_info_entry *entry,
1296 struct snd_info_buffer *buffer)
1121{ 1297{
1122 struct snd_pcxhr *chip = entry->private_data; 1298 struct snd_pcxhr *chip = entry->private_data;
1123 struct pcxhr_mgr *mgr = chip->mgr; 1299 struct pcxhr_mgr *mgr = chip->mgr;
1124 static char *texts[7] = { 1300 static const char *textsHR22[3] = {
1125 "Internal", "Word", "AES Sync", "AES 1", "AES 2", "AES 3", "AES 4" 1301 "Internal", "AES Sync", "AES 1"
1302 };
1303 static const char *textsPCXHR[7] = {
1304 "Internal", "Word", "AES Sync",
1305 "AES 1", "AES 2", "AES 3", "AES 4"
1126 }; 1306 };
1307 const char **texts;
1308 int max_clock;
1309 if (mgr->is_hr_stereo) {
1310 texts = textsHR22;
1311 max_clock = HR22_CLOCK_TYPE_MAX;
1312 } else {
1313 texts = textsPCXHR;
1314 max_clock = PCXHR_CLOCK_TYPE_MAX;
1315 }
1127 1316
1128 snd_iprintf(buffer, "\n%s\n", mgr->longname); 1317 snd_iprintf(buffer, "\n%s\n", mgr->longname);
1129 snd_iprintf(buffer, "Current Sample Clock\t: %s\n", texts[mgr->cur_clock_type]); 1318 snd_iprintf(buffer, "Current Sample Clock\t: %s\n",
1130 snd_iprintf(buffer, "Current Sample Rate\t= %d\n", mgr->sample_rate_real); 1319 texts[mgr->cur_clock_type]);
1131 1320 snd_iprintf(buffer, "Current Sample Rate\t= %d\n",
1321 mgr->sample_rate_real);
1132 /* commands available when embedded DSP is running */ 1322 /* commands available when embedded DSP is running */
1133 if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) { 1323 if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) {
1134 int i, err, sample_rate; 1324 int i, err, sample_rate;
1135 for (i = PCXHR_CLOCK_TYPE_WORD_CLOCK; i< (3 + mgr->capture_chips); i++) { 1325 for (i = 1; i <= max_clock; i++) {
1136 err = pcxhr_get_external_clock(mgr, i, &sample_rate); 1326 err = pcxhr_get_external_clock(mgr, i, &sample_rate);
1137 if (err) 1327 if (err)
1138 break; 1328 break;
1139 snd_iprintf(buffer, "%s Clock\t\t= %d\n", texts[i], sample_rate); 1329 snd_iprintf(buffer, "%s Clock\t\t= %d\n",
1330 texts[i], sample_rate);
1140 } 1331 }
1141 } else 1332 } else
1142 snd_iprintf(buffer, "no firmware loaded\n"); 1333 snd_iprintf(buffer, "no firmware loaded\n");
@@ -1194,7 +1385,8 @@ static int pcxhr_free(struct pcxhr_mgr *mgr)
1194/* 1385/*
1195 * probe function - creates the card manager 1386 * probe function - creates the card manager
1196 */ 1387 */
1197static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 1388static int __devinit pcxhr_probe(struct pci_dev *pci,
1389 const struct pci_device_id *pci_id)
1198{ 1390{
1199 static int dev; 1391 static int dev;
1200 struct pcxhr_mgr *mgr; 1392 struct pcxhr_mgr *mgr;
@@ -1217,7 +1409,8 @@ static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id
1217 1409
1218 /* check if we can restrict PCI DMA transfers to 32 bits */ 1410 /* check if we can restrict PCI DMA transfers to 32 bits */
1219 if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0) { 1411 if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0) {
1220 snd_printk(KERN_ERR "architecture does not support 32bit PCI busmaster DMA\n"); 1412 snd_printk(KERN_ERR "architecture does not support "
1413 "32bit PCI busmaster DMA\n");
1221 pci_disable_device(pci); 1414 pci_disable_device(pci);
1222 return -ENXIO; 1415 return -ENXIO;
1223 } 1416 }
@@ -1234,11 +1427,25 @@ static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id
1234 pci_disable_device(pci); 1427 pci_disable_device(pci);
1235 return -ENODEV; 1428 return -ENODEV;
1236 } 1429 }
1237 card_name = pcxhr_board_params[pci_id->driver_data].board_name; 1430 card_name =
1238 mgr->playback_chips = pcxhr_board_params[pci_id->driver_data].playback_chips; 1431 pcxhr_board_params[pci_id->driver_data].board_name;
1239 mgr->capture_chips = pcxhr_board_params[pci_id->driver_data].capture_chips; 1432 mgr->playback_chips =
1240 mgr->firmware_num = pcxhr_board_params[pci_id->driver_data].firmware_num; 1433 pcxhr_board_params[pci_id->driver_data].playback_chips;
1434 mgr->capture_chips =
1435 pcxhr_board_params[pci_id->driver_data].capture_chips;
1436 mgr->fw_file_set =
1437 pcxhr_board_params[pci_id->driver_data].fw_file_set;
1438 mgr->firmware_num =
1439 pcxhr_board_params[pci_id->driver_data].firmware_num;
1241 mgr->mono_capture = mono[dev]; 1440 mgr->mono_capture = mono[dev];
1441 mgr->is_hr_stereo = (mgr->playback_chips == 1);
1442 mgr->board_has_aes1 = PCXHR_BOARD_HAS_AES1(mgr);
1443 mgr->board_aes_in_192k = !PCXHR_BOARD_AESIN_NO_192K(mgr);
1444
1445 if (mgr->is_hr_stereo)
1446 mgr->granularity = PCXHR_GRANULARITY_HR22;
1447 else
1448 mgr->granularity = PCXHR_GRANULARITY;
1242 1449
1243 /* resource assignment */ 1450 /* resource assignment */
1244 if ((err = pci_request_regions(pci, card_name)) < 0) { 1451 if ((err = pci_request_regions(pci, card_name)) < 0) {
@@ -1261,7 +1468,8 @@ static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id
1261 mgr->irq = pci->irq; 1468 mgr->irq = pci->irq;
1262 1469
1263 sprintf(mgr->shortname, "Digigram %s", card_name); 1470 sprintf(mgr->shortname, "Digigram %s", card_name);
1264 sprintf(mgr->longname, "%s at 0x%lx & 0x%lx, 0x%lx irq %i", mgr->shortname, 1471 sprintf(mgr->longname, "%s at 0x%lx & 0x%lx, 0x%lx irq %i",
1472 mgr->shortname,
1265 mgr->port[0], mgr->port[1], mgr->port[2], mgr->irq); 1473 mgr->port[0], mgr->port[1], mgr->port[2], mgr->irq);
1266 1474
1267 /* ISR spinlock */ 1475 /* ISR spinlock */
@@ -1272,10 +1480,14 @@ static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id
1272 mutex_init(&mgr->setup_mutex); 1480 mutex_init(&mgr->setup_mutex);
1273 1481
1274 /* init taslket */ 1482 /* init taslket */
1275 tasklet_init(&mgr->msg_taskq, pcxhr_msg_tasklet, (unsigned long) mgr); 1483 tasklet_init(&mgr->msg_taskq, pcxhr_msg_tasklet,
1276 tasklet_init(&mgr->trigger_taskq, pcxhr_trigger_tasklet, (unsigned long) mgr); 1484 (unsigned long) mgr);
1485 tasklet_init(&mgr->trigger_taskq, pcxhr_trigger_tasklet,
1486 (unsigned long) mgr);
1487
1277 mgr->prmh = kmalloc(sizeof(*mgr->prmh) + 1488 mgr->prmh = kmalloc(sizeof(*mgr->prmh) +
1278 sizeof(u32) * (PCXHR_SIZE_MAX_LONG_STATUS - PCXHR_SIZE_MAX_STATUS), 1489 sizeof(u32) * (PCXHR_SIZE_MAX_LONG_STATUS -
1490 PCXHR_SIZE_MAX_STATUS),
1279 GFP_KERNEL); 1491 GFP_KERNEL);
1280 if (! mgr->prmh) { 1492 if (! mgr->prmh) {
1281 pcxhr_free(mgr); 1493 pcxhr_free(mgr);
@@ -1296,7 +1508,8 @@ static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id
1296 else 1508 else
1297 idx = index[dev] + i; 1509 idx = index[dev] + i;
1298 1510
1299 snprintf(tmpid, sizeof(tmpid), "%s-%d", id[dev] ? id[dev] : card_name, i); 1511 snprintf(tmpid, sizeof(tmpid), "%s-%d",
1512 id[dev] ? id[dev] : card_name, i);
1300 card = snd_card_new(idx, tmpid, THIS_MODULE, 0); 1513 card = snd_card_new(idx, tmpid, THIS_MODULE, 0);
1301 1514
1302 if (! card) { 1515 if (! card) {
@@ -1310,6 +1523,7 @@ static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id
1310 sprintf(card->longname, "%s [PCM #%d]", mgr->longname, i); 1523 sprintf(card->longname, "%s [PCM #%d]", mgr->longname, i);
1311 1524
1312 if ((err = pcxhr_create(mgr, card, i)) < 0) { 1525 if ((err = pcxhr_create(mgr, card, i)) < 0) {
1526 snd_card_free(card);
1313 pcxhr_free(mgr); 1527 pcxhr_free(mgr);
1314 return err; 1528 return err;
1315 } 1529 }
diff --git a/sound/pci/pcxhr/pcxhr.h b/sound/pci/pcxhr/pcxhr.h
index 652064787a55..84131a916c92 100644
--- a/sound/pci/pcxhr/pcxhr.h
+++ b/sound/pci/pcxhr/pcxhr.h
@@ -27,15 +27,18 @@
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <sound/pcm.h> 28#include <sound/pcm.h>
29 29
30#define PCXHR_DRIVER_VERSION 0x000804 /* 0.8.4 */ 30#define PCXHR_DRIVER_VERSION 0x000905 /* 0.9.5 */
31#define PCXHR_DRIVER_VERSION_STRING "0.8.4" /* 0.8.4 */ 31#define PCXHR_DRIVER_VERSION_STRING "0.9.5" /* 0.9.5 */
32 32
33 33
34#define PCXHR_MAX_CARDS 6 34#define PCXHR_MAX_CARDS 6
35#define PCXHR_PLAYBACK_STREAMS 4 35#define PCXHR_PLAYBACK_STREAMS 4
36 36
37#define PCXHR_GRANULARITY 96 /* transfer granularity (should be min 96 and multiple of 48) */ 37#define PCXHR_GRANULARITY 96 /* min 96 and multiple of 48 */
38#define PCXHR_GRANULARITY_MIN 96 /* transfer granularity of pipes and the dsp time (MBOX4) */ 38/* transfer granularity of pipes and the dsp time (MBOX4) */
39#define PCXHR_GRANULARITY_MIN 96
40/* TODO : granularity could be 64 or 128 */
41#define PCXHR_GRANULARITY_HR22 192 /* granularity for stereo cards */
39 42
40struct snd_pcxhr; 43struct snd_pcxhr;
41struct pcxhr_mgr; 44struct pcxhr_mgr;
@@ -51,6 +54,11 @@ enum pcxhr_clock_type {
51 PCXHR_CLOCK_TYPE_AES_2, 54 PCXHR_CLOCK_TYPE_AES_2,
52 PCXHR_CLOCK_TYPE_AES_3, 55 PCXHR_CLOCK_TYPE_AES_3,
53 PCXHR_CLOCK_TYPE_AES_4, 56 PCXHR_CLOCK_TYPE_AES_4,
57 PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4,
58 HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL,
59 HR22_CLOCK_TYPE_AES_SYNC,
60 HR22_CLOCK_TYPE_AES_1,
61 HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1,
54}; 62};
55 63
56struct pcxhr_mgr { 64struct pcxhr_mgr {
@@ -61,6 +69,8 @@ struct pcxhr_mgr {
61 69
62 int irq; 70 int irq;
63 71
72 int granularity;
73
64 /* card access with 1 mem bar and 2 io bar's */ 74 /* card access with 1 mem bar and 2 io bar's */
65 unsigned long port[3]; 75 unsigned long port[3];
66 76
@@ -83,11 +93,16 @@ struct pcxhr_mgr {
83 /* hardware interface */ 93 /* hardware interface */
84 unsigned int dsp_loaded; /* bit flags of loaded dsp indices */ 94 unsigned int dsp_loaded; /* bit flags of loaded dsp indices */
85 unsigned int dsp_version; /* read from embedded once firmware is loaded */ 95 unsigned int dsp_version; /* read from embedded once firmware is loaded */
86 int board_has_analog; /* if 0 the board is digital only */ 96 int playback_chips;
87 int mono_capture; /* if 1 the board does mono capture */ 97 int capture_chips;
88 int playback_chips; /* 4 or 6 */ 98 int fw_file_set;
89 int capture_chips; /* 4 or 1 */ 99 int firmware_num;
90 int firmware_num; /* 41 or 42 */ 100 int is_hr_stereo:1;
101 int board_has_aes1:1; /* if 1 board has AES1 plug and SRC */
102 int board_has_analog:1; /* if 0 the board is digital only */
103 int board_has_mic:1; /* if 1 the board has microphone input */
104 int board_aes_in_192k:1;/* if 1 the aes input plugs do support 192kHz */
105 int mono_capture:1; /* if 1 the board does mono capture */
91 106
92 struct snd_dma_buffer hostport; 107 struct snd_dma_buffer hostport;
93 108
@@ -106,6 +121,9 @@ struct pcxhr_mgr {
106 int async_err_stream_xrun; 121 int async_err_stream_xrun;
107 int async_err_pipe_xrun; 122 int async_err_pipe_xrun;
108 int async_err_other_last; 123 int async_err_other_last;
124
125 unsigned char xlx_cfg; /* copy of PCXHR_XLX_CFG register */
126 unsigned char xlx_selmic; /* copy of PCXHR_XLX_SELMIC register */
109}; 127};
110 128
111 129
@@ -155,24 +173,30 @@ struct snd_pcxhr {
155 173
156 struct snd_pcm *pcm; /* PCM */ 174 struct snd_pcm *pcm; /* PCM */
157 175
158 struct pcxhr_pipe playback_pipe; /* 1 stereo pipe only */ 176 struct pcxhr_pipe playback_pipe; /* 1 stereo pipe only */
159 struct pcxhr_pipe capture_pipe[2]; /* 1 stereo pipe or 2 mono pipes */ 177 struct pcxhr_pipe capture_pipe[2]; /* 1 stereo or 2 mono pipes */
160 178
161 struct pcxhr_stream playback_stream[PCXHR_PLAYBACK_STREAMS]; 179 struct pcxhr_stream playback_stream[PCXHR_PLAYBACK_STREAMS];
162 struct pcxhr_stream capture_stream[2]; /* 1 stereo stream or 2 mono streams */ 180 struct pcxhr_stream capture_stream[2]; /* 1 stereo or 2 mono streams */
163 int nb_streams_play; 181 int nb_streams_play;
164 int nb_streams_capt; 182 int nb_streams_capt;
165 183
166 int analog_playback_active[2]; /* Mixer : Master Playback active (!mute) */ 184 int analog_playback_active[2]; /* Mixer : Master Playback !mute */
167 int analog_playback_volume[2]; /* Mixer : Master Playback Volume */ 185 int analog_playback_volume[2]; /* Mixer : Master Playback Volume */
168 int analog_capture_volume[2]; /* Mixer : Master Capture Volume */ 186 int analog_capture_volume[2]; /* Mixer : Master Capture Volume */
169 int digital_playback_active[PCXHR_PLAYBACK_STREAMS][2]; /* Mixer : Digital Playback Active [streams][stereo]*/ 187 int digital_playback_active[PCXHR_PLAYBACK_STREAMS][2];
170 int digital_playback_volume[PCXHR_PLAYBACK_STREAMS][2]; /* Mixer : Digital Playback Volume [streams][stereo]*/ 188 int digital_playback_volume[PCXHR_PLAYBACK_STREAMS][2];
171 int digital_capture_volume[2]; /* Mixer : Digital Capture Volume [stereo] */ 189 int digital_capture_volume[2]; /* Mixer : Digital Capture Volume */
172 int monitoring_active[2]; /* Mixer : Monitoring Active */ 190 int monitoring_active[2]; /* Mixer : Monitoring Active */
173 int monitoring_volume[2]; /* Mixer : Monitoring Volume */ 191 int monitoring_volume[2]; /* Mixer : Monitoring Volume */
174 int audio_capture_source; /* Mixer : Audio Capture Source */ 192 int audio_capture_source; /* Mixer : Audio Capture Source */
175 unsigned char aes_bits[5]; /* Mixer : IEC958_AES bits */ 193 int mic_volume; /* used by cards with MIC only */
194 int mic_boost; /* used by cards with MIC only */
195 int mic_active; /* used by cards with MIC only */
196 int analog_capture_active; /* used by cards with MIC only */
197 int phantom_power; /* used by cards with MIC only */
198
199 unsigned char aes_bits[5]; /* Mixer : IEC958_AES bits */
176}; 200};
177 201
178struct pcxhr_hostport 202struct pcxhr_hostport
@@ -184,6 +208,8 @@ struct pcxhr_hostport
184/* exported */ 208/* exported */
185int pcxhr_create_pcm(struct snd_pcxhr *chip); 209int pcxhr_create_pcm(struct snd_pcxhr *chip);
186int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate); 210int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate);
187int pcxhr_get_external_clock(struct pcxhr_mgr *mgr, enum pcxhr_clock_type clock_type, int *sample_rate); 211int pcxhr_get_external_clock(struct pcxhr_mgr *mgr,
212 enum pcxhr_clock_type clock_type,
213 int *sample_rate);
188 214
189#endif /* __SOUND_PCXHR_H */ 215#endif /* __SOUND_PCXHR_H */
diff --git a/sound/pci/pcxhr/pcxhr_core.c b/sound/pci/pcxhr/pcxhr_core.c
index 7143259cfe34..833e7180ad2d 100644
--- a/sound/pci/pcxhr/pcxhr_core.c
+++ b/sound/pci/pcxhr/pcxhr_core.c
@@ -132,13 +132,15 @@ static int pcxhr_check_reg_bit(struct pcxhr_mgr *mgr, unsigned int reg,
132 *read = PCXHR_INPB(mgr, reg); 132 *read = PCXHR_INPB(mgr, reg);
133 if ((*read & mask) == bit) { 133 if ((*read & mask) == bit) {
134 if (i > 100) 134 if (i > 100)
135 snd_printdd("ATTENTION! check_reg(%x) loopcount=%d\n", 135 snd_printdd("ATTENTION! check_reg(%x) "
136 "loopcount=%d\n",
136 reg, i); 137 reg, i);
137 return 0; 138 return 0;
138 } 139 }
139 i++; 140 i++;
140 } while (time_after_eq(end_time, jiffies)); 141 } while (time_after_eq(end_time, jiffies));
141 snd_printk(KERN_ERR "pcxhr_check_reg_bit: timeout, reg=%x, mask=0x%x, val=0x%x\n", 142 snd_printk(KERN_ERR
143 "pcxhr_check_reg_bit: timeout, reg=%x, mask=0x%x, val=%x\n",
142 reg, mask, *read); 144 reg, mask, *read);
143 return -EIO; 145 return -EIO;
144} 146}
@@ -159,18 +161,22 @@ static int pcxhr_check_reg_bit(struct pcxhr_mgr *mgr, unsigned int reg,
159#define PCXHR_IT_TEST_XILINX (0x0000003C | PCXHR_MASK_IT_HF1 | \ 161#define PCXHR_IT_TEST_XILINX (0x0000003C | PCXHR_MASK_IT_HF1 | \
160 PCXHR_MASK_IT_MANAGE_HF5) 162 PCXHR_MASK_IT_MANAGE_HF5)
161#define PCXHR_IT_DOWNLOAD_BOOT (0x0000000C | PCXHR_MASK_IT_HF1 | \ 163#define PCXHR_IT_DOWNLOAD_BOOT (0x0000000C | PCXHR_MASK_IT_HF1 | \
162 PCXHR_MASK_IT_MANAGE_HF5 | PCXHR_MASK_IT_WAIT) 164 PCXHR_MASK_IT_MANAGE_HF5 | \
165 PCXHR_MASK_IT_WAIT)
163#define PCXHR_IT_RESET_BOARD_FUNC (0x0000000C | PCXHR_MASK_IT_HF0 | \ 166#define PCXHR_IT_RESET_BOARD_FUNC (0x0000000C | PCXHR_MASK_IT_HF0 | \
164 PCXHR_MASK_IT_MANAGE_HF5 | PCXHR_MASK_IT_WAIT_EXTRA) 167 PCXHR_MASK_IT_MANAGE_HF5 | \
168 PCXHR_MASK_IT_WAIT_EXTRA)
165#define PCXHR_IT_DOWNLOAD_DSP (0x0000000C | \ 169#define PCXHR_IT_DOWNLOAD_DSP (0x0000000C | \
166 PCXHR_MASK_IT_MANAGE_HF5 | PCXHR_MASK_IT_WAIT) 170 PCXHR_MASK_IT_MANAGE_HF5 | \
171 PCXHR_MASK_IT_WAIT)
167#define PCXHR_IT_DEBUG (0x0000005A | PCXHR_MASK_IT_NO_HF0_HF1) 172#define PCXHR_IT_DEBUG (0x0000005A | PCXHR_MASK_IT_NO_HF0_HF1)
168#define PCXHR_IT_RESET_SEMAPHORE (0x0000005C | PCXHR_MASK_IT_NO_HF0_HF1) 173#define PCXHR_IT_RESET_SEMAPHORE (0x0000005C | PCXHR_MASK_IT_NO_HF0_HF1)
169#define PCXHR_IT_MESSAGE (0x00000074 | PCXHR_MASK_IT_NO_HF0_HF1) 174#define PCXHR_IT_MESSAGE (0x00000074 | PCXHR_MASK_IT_NO_HF0_HF1)
170#define PCXHR_IT_RESET_CHK (0x00000076 | PCXHR_MASK_IT_NO_HF0_HF1) 175#define PCXHR_IT_RESET_CHK (0x00000076 | PCXHR_MASK_IT_NO_HF0_HF1)
171#define PCXHR_IT_UPDATE_RBUFFER (0x00000078 | PCXHR_MASK_IT_NO_HF0_HF1) 176#define PCXHR_IT_UPDATE_RBUFFER (0x00000078 | PCXHR_MASK_IT_NO_HF0_HF1)
172 177
173static int pcxhr_send_it_dsp(struct pcxhr_mgr *mgr, unsigned int itdsp, int atomic) 178static int pcxhr_send_it_dsp(struct pcxhr_mgr *mgr,
179 unsigned int itdsp, int atomic)
174{ 180{
175 int err; 181 int err;
176 unsigned char reg; 182 unsigned char reg;
@@ -178,17 +184,21 @@ static int pcxhr_send_it_dsp(struct pcxhr_mgr *mgr, unsigned int itdsp, int atom
178 if (itdsp & PCXHR_MASK_IT_MANAGE_HF5) { 184 if (itdsp & PCXHR_MASK_IT_MANAGE_HF5) {
179 /* clear hf5 bit */ 185 /* clear hf5 bit */
180 PCXHR_OUTPL(mgr, PCXHR_PLX_MBOX0, 186 PCXHR_OUTPL(mgr, PCXHR_PLX_MBOX0,
181 PCXHR_INPL(mgr, PCXHR_PLX_MBOX0) & ~PCXHR_MBOX0_HF5); 187 PCXHR_INPL(mgr, PCXHR_PLX_MBOX0) &
188 ~PCXHR_MBOX0_HF5);
182 } 189 }
183 if ((itdsp & PCXHR_MASK_IT_NO_HF0_HF1) == 0) { 190 if ((itdsp & PCXHR_MASK_IT_NO_HF0_HF1) == 0) {
184 reg = PCXHR_ICR_HI08_RREQ | PCXHR_ICR_HI08_TREQ | PCXHR_ICR_HI08_HDRQ; 191 reg = (PCXHR_ICR_HI08_RREQ |
192 PCXHR_ICR_HI08_TREQ |
193 PCXHR_ICR_HI08_HDRQ);
185 if (itdsp & PCXHR_MASK_IT_HF0) 194 if (itdsp & PCXHR_MASK_IT_HF0)
186 reg |= PCXHR_ICR_HI08_HF0; 195 reg |= PCXHR_ICR_HI08_HF0;
187 if (itdsp & PCXHR_MASK_IT_HF1) 196 if (itdsp & PCXHR_MASK_IT_HF1)
188 reg |= PCXHR_ICR_HI08_HF1; 197 reg |= PCXHR_ICR_HI08_HF1;
189 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg); 198 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg);
190 } 199 }
191 reg = (unsigned char)(((itdsp & PCXHR_MASK_EXTRA_INFO) >> 1) | PCXHR_CVR_HI08_HC); 200 reg = (unsigned char)(((itdsp & PCXHR_MASK_EXTRA_INFO) >> 1) |
201 PCXHR_CVR_HI08_HC);
192 PCXHR_OUTPB(mgr, PCXHR_DSP_CVR, reg); 202 PCXHR_OUTPB(mgr, PCXHR_DSP_CVR, reg);
193 if (itdsp & PCXHR_MASK_IT_WAIT) { 203 if (itdsp & PCXHR_MASK_IT_WAIT) {
194 if (atomic) 204 if (atomic)
@@ -211,10 +221,14 @@ static int pcxhr_send_it_dsp(struct pcxhr_mgr *mgr, unsigned int itdsp, int atom
211 } 221 }
212 if (itdsp & PCXHR_MASK_IT_MANAGE_HF5) { 222 if (itdsp & PCXHR_MASK_IT_MANAGE_HF5) {
213 /* wait for hf5 bit */ 223 /* wait for hf5 bit */
214 err = pcxhr_check_reg_bit(mgr, PCXHR_PLX_MBOX0, PCXHR_MBOX0_HF5, 224 err = pcxhr_check_reg_bit(mgr, PCXHR_PLX_MBOX0,
215 PCXHR_MBOX0_HF5, PCXHR_TIMEOUT_DSP, &reg); 225 PCXHR_MBOX0_HF5,
226 PCXHR_MBOX0_HF5,
227 PCXHR_TIMEOUT_DSP,
228 &reg);
216 if (err) { 229 if (err) {
217 snd_printk(KERN_ERR "pcxhr_send_it_dsp : TIMEOUT HF5\n"); 230 snd_printk(KERN_ERR
231 "pcxhr_send_it_dsp : TIMEOUT HF5\n");
218 return err; 232 return err;
219 } 233 }
220 } 234 }
@@ -263,7 +277,8 @@ void pcxhr_enable_dsp(struct pcxhr_mgr *mgr)
263/* 277/*
264 * load the xilinx image 278 * load the xilinx image
265 */ 279 */
266int pcxhr_load_xilinx_binary(struct pcxhr_mgr *mgr, const struct firmware *xilinx, int second) 280int pcxhr_load_xilinx_binary(struct pcxhr_mgr *mgr,
281 const struct firmware *xilinx, int second)
267{ 282{
268 unsigned int i; 283 unsigned int i;
269 unsigned int chipsc; 284 unsigned int chipsc;
@@ -274,7 +289,9 @@ int pcxhr_load_xilinx_binary(struct pcxhr_mgr *mgr, const struct firmware *xilin
274 /* test first xilinx */ 289 /* test first xilinx */
275 chipsc = PCXHR_INPL(mgr, PCXHR_PLX_CHIPSC); 290 chipsc = PCXHR_INPL(mgr, PCXHR_PLX_CHIPSC);
276 /* REV01 cards do not support the PCXHR_CHIPSC_GPI_USERI bit anymore */ 291 /* REV01 cards do not support the PCXHR_CHIPSC_GPI_USERI bit anymore */
277 /* this bit will always be 1; no possibility to test presence of first xilinx */ 292 /* this bit will always be 1;
293 * no possibility to test presence of first xilinx
294 */
278 if(second) { 295 if(second) {
279 if ((chipsc & PCXHR_CHIPSC_GPI_USERI) == 0) { 296 if ((chipsc & PCXHR_CHIPSC_GPI_USERI) == 0) {
280 snd_printk(KERN_ERR "error loading first xilinx\n"); 297 snd_printk(KERN_ERR "error loading first xilinx\n");
@@ -290,7 +307,8 @@ int pcxhr_load_xilinx_binary(struct pcxhr_mgr *mgr, const struct firmware *xilin
290 data = *image; 307 data = *image;
291 mask = 0x80; 308 mask = 0x80;
292 while (mask) { 309 while (mask) {
293 chipsc &= ~(PCXHR_CHIPSC_DATA_CLK | PCXHR_CHIPSC_DATA_IN); 310 chipsc &= ~(PCXHR_CHIPSC_DATA_CLK |
311 PCXHR_CHIPSC_DATA_IN);
294 if (data & mask) 312 if (data & mask)
295 chipsc |= PCXHR_CHIPSC_DATA_IN; 313 chipsc |= PCXHR_CHIPSC_DATA_IN;
296 PCXHR_OUTPL(mgr, PCXHR_PLX_CHIPSC, chipsc); 314 PCXHR_OUTPL(mgr, PCXHR_PLX_CHIPSC, chipsc);
@@ -330,15 +348,20 @@ static int pcxhr_download_dsp(struct pcxhr_mgr *mgr, const struct firmware *dsp)
330 data = dsp->data + i; 348 data = dsp->data + i;
331 if (i == 0) { 349 if (i == 0) {
332 /* test data header consistency */ 350 /* test data header consistency */
333 len = (unsigned int)((data[0]<<16) + (data[1]<<8) + data[2]); 351 len = (unsigned int)((data[0]<<16) +
334 if (len && dsp->size != (len + 2) * 3) 352 (data[1]<<8) +
353 data[2]);
354 if (len && (dsp->size != (len + 2) * 3))
335 return -EINVAL; 355 return -EINVAL;
336 } 356 }
337 /* wait DSP ready for new transfer */ 357 /* wait DSP ready for new transfer */
338 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_TRDY, 358 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR,
339 PCXHR_ISR_HI08_TRDY, PCXHR_TIMEOUT_DSP, &dummy); 359 PCXHR_ISR_HI08_TRDY,
360 PCXHR_ISR_HI08_TRDY,
361 PCXHR_TIMEOUT_DSP, &dummy);
340 if (err) { 362 if (err) {
341 snd_printk(KERN_ERR "dsp loading error at position %d\n", i); 363 snd_printk(KERN_ERR
364 "dsp loading error at position %d\n", i);
342 return err; 365 return err;
343 } 366 }
344 /* send host data */ 367 /* send host data */
@@ -357,7 +380,8 @@ static int pcxhr_download_dsp(struct pcxhr_mgr *mgr, const struct firmware *dsp)
357/* 380/*
358 * load the eeprom image 381 * load the eeprom image
359 */ 382 */
360int pcxhr_load_eeprom_binary(struct pcxhr_mgr *mgr, const struct firmware *eeprom) 383int pcxhr_load_eeprom_binary(struct pcxhr_mgr *mgr,
384 const struct firmware *eeprom)
361{ 385{
362 int err; 386 int err;
363 unsigned char reg; 387 unsigned char reg;
@@ -365,7 +389,9 @@ int pcxhr_load_eeprom_binary(struct pcxhr_mgr *mgr, const struct firmware *eepro
365 /* init value of the ICR register */ 389 /* init value of the ICR register */
366 reg = PCXHR_ICR_HI08_RREQ | PCXHR_ICR_HI08_TREQ | PCXHR_ICR_HI08_HDRQ; 390 reg = PCXHR_ICR_HI08_RREQ | PCXHR_ICR_HI08_TREQ | PCXHR_ICR_HI08_HDRQ;
367 if (PCXHR_INPL(mgr, PCXHR_PLX_MBOX0) & PCXHR_MBOX0_BOOT_HERE) { 391 if (PCXHR_INPL(mgr, PCXHR_PLX_MBOX0) & PCXHR_MBOX0_BOOT_HERE) {
368 /* no need to load the eeprom binary, but init the HI08 interface */ 392 /* no need to load the eeprom binary,
393 * but init the HI08 interface
394 */
369 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg | PCXHR_ICR_HI08_INIT); 395 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg | PCXHR_ICR_HI08_INIT);
370 msleep(PCXHR_WAIT_DEFAULT); 396 msleep(PCXHR_WAIT_DEFAULT);
371 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg); 397 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg);
@@ -429,8 +455,10 @@ int pcxhr_load_dsp_binary(struct pcxhr_mgr *mgr, const struct firmware *dsp)
429 if (err) 455 if (err)
430 return err; 456 return err;
431 /* wait for chk bit */ 457 /* wait for chk bit */
432 return pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_CHK, 458 return pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR,
433 PCXHR_ISR_HI08_CHK, PCXHR_TIMEOUT_DSP, &dummy); 459 PCXHR_ISR_HI08_CHK,
460 PCXHR_ISR_HI08_CHK,
461 PCXHR_TIMEOUT_DSP, &dummy);
434} 462}
435 463
436 464
@@ -443,8 +471,8 @@ struct pcxhr_cmd_info {
443/* RMH status type */ 471/* RMH status type */
444enum { 472enum {
445 RMH_SSIZE_FIXED = 0, /* status size fix (st_length = 0..x) */ 473 RMH_SSIZE_FIXED = 0, /* status size fix (st_length = 0..x) */
446 RMH_SSIZE_ARG = 1, /* status size given in the LSB byte (used with st_length = 1) */ 474 RMH_SSIZE_ARG = 1, /* status size given in the LSB byte */
447 RMH_SSIZE_MASK = 2, /* status size given in bitmask (used with st_length = 1) */ 475 RMH_SSIZE_MASK = 2, /* status size given in bitmask */
448}; 476};
449 477
450/* 478/*
@@ -474,7 +502,7 @@ static struct pcxhr_cmd_info pcxhr_dsp_cmds[] = {
474[CMD_UPDATE_R_BUFFERS] = { 0x840000, 0, RMH_SSIZE_FIXED }, 502[CMD_UPDATE_R_BUFFERS] = { 0x840000, 0, RMH_SSIZE_FIXED },
475[CMD_FORMAT_STREAM_OUT] = { 0x860000, 0, RMH_SSIZE_FIXED }, 503[CMD_FORMAT_STREAM_OUT] = { 0x860000, 0, RMH_SSIZE_FIXED },
476[CMD_FORMAT_STREAM_IN] = { 0x870000, 0, RMH_SSIZE_FIXED }, 504[CMD_FORMAT_STREAM_IN] = { 0x870000, 0, RMH_SSIZE_FIXED },
477[CMD_STREAM_SAMPLE_COUNT] = { 0x902000, 2, RMH_SSIZE_FIXED }, /* stat_len = nb_streams * 2 */ 505[CMD_STREAM_SAMPLE_COUNT] = { 0x902000, 2, RMH_SSIZE_FIXED },
478[CMD_AUDIO_LEVEL_ADJUST] = { 0xc22000, 0, RMH_SSIZE_FIXED }, 506[CMD_AUDIO_LEVEL_ADJUST] = { 0xc22000, 0, RMH_SSIZE_FIXED },
479}; 507};
480 508
@@ -524,10 +552,13 @@ static int pcxhr_read_rmh_status(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
524 552
525 for (i = 0; i < rmh->stat_len; i++) { 553 for (i = 0; i < rmh->stat_len; i++) {
526 /* wait for receiver full */ 554 /* wait for receiver full */
527 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_RXDF, 555 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR,
528 PCXHR_ISR_HI08_RXDF, PCXHR_TIMEOUT_DSP, &reg); 556 PCXHR_ISR_HI08_RXDF,
557 PCXHR_ISR_HI08_RXDF,
558 PCXHR_TIMEOUT_DSP, &reg);
529 if (err) { 559 if (err) {
530 snd_printk(KERN_ERR "ERROR RMH stat: ISR:RXDF=1 (ISR = %x; i=%d )\n", 560 snd_printk(KERN_ERR "ERROR RMH stat: "
561 "ISR:RXDF=1 (ISR = %x; i=%d )\n",
531 reg, i); 562 reg, i);
532 return err; 563 return err;
533 } 564 }
@@ -537,10 +568,10 @@ static int pcxhr_read_rmh_status(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
537 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXL); 568 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXL);
538 569
539 /* need to update rmh->stat_len on the fly ?? */ 570 /* need to update rmh->stat_len on the fly ?? */
540 if (i==0) { 571 if (!i) {
541 if (rmh->dsp_stat != RMH_SSIZE_FIXED) { 572 if (rmh->dsp_stat != RMH_SSIZE_FIXED) {
542 if (rmh->dsp_stat == RMH_SSIZE_ARG) { 573 if (rmh->dsp_stat == RMH_SSIZE_ARG) {
543 rmh->stat_len = (u16)(data & 0x0000ff) + 1; 574 rmh->stat_len = (data & 0x0000ff) + 1;
544 data &= 0xffff00; 575 data &= 0xffff00;
545 } else { 576 } else {
546 /* rmh->dsp_stat == RMH_SSIZE_MASK */ 577 /* rmh->dsp_stat == RMH_SSIZE_MASK */
@@ -562,7 +593,8 @@ static int pcxhr_read_rmh_status(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
562 rmh->stat[i] = data; 593 rmh->stat[i] = data;
563 } 594 }
564 if (rmh->stat_len > max_stat_len) { 595 if (rmh->stat_len > max_stat_len) {
565 snd_printdd("PCXHR : rmh->stat_len=%x too big\n", rmh->stat_len); 596 snd_printdd("PCXHR : rmh->stat_len=%x too big\n",
597 rmh->stat_len);
566 rmh->stat_len = max_stat_len; 598 rmh->stat_len = max_stat_len;
567 } 599 }
568 return 0; 600 return 0;
@@ -605,7 +637,8 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
605 data &= 0xff7fff; /* MASK_1_WORD_COMMAND */ 637 data &= 0xff7fff; /* MASK_1_WORD_COMMAND */
606#ifdef CONFIG_SND_DEBUG_VERBOSE 638#ifdef CONFIG_SND_DEBUG_VERBOSE
607 if (rmh->cmd_idx < CMD_LAST_INDEX) 639 if (rmh->cmd_idx < CMD_LAST_INDEX)
608 snd_printdd("MSG cmd[0]=%x (%s)\n", data, cmd_names[rmh->cmd_idx]); 640 snd_printdd("MSG cmd[0]=%x (%s)\n",
641 data, cmd_names[rmh->cmd_idx]);
609#endif 642#endif
610 643
611 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_TRDY, 644 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_TRDY,
@@ -619,8 +652,10 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
619 if (rmh->cmd_len > 1) { 652 if (rmh->cmd_len > 1) {
620 /* send length */ 653 /* send length */
621 data = rmh->cmd_len - 1; 654 data = rmh->cmd_len - 1;
622 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_TRDY, 655 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR,
623 PCXHR_ISR_HI08_TRDY, PCXHR_TIMEOUT_DSP, &reg); 656 PCXHR_ISR_HI08_TRDY,
657 PCXHR_ISR_HI08_TRDY,
658 PCXHR_TIMEOUT_DSP, &reg);
624 if (err) 659 if (err)
625 return err; 660 return err;
626 PCXHR_OUTPB(mgr, PCXHR_DSP_TXH, (data>>16)&0xFF); 661 PCXHR_OUTPB(mgr, PCXHR_DSP_TXH, (data>>16)&0xFF);
@@ -653,8 +688,10 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
653 /* test status ISR */ 688 /* test status ISR */
654 if (reg & PCXHR_ISR_HI08_ERR) { 689 if (reg & PCXHR_ISR_HI08_ERR) {
655 /* ERROR, wait for receiver full */ 690 /* ERROR, wait for receiver full */
656 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_RXDF, 691 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR,
657 PCXHR_ISR_HI08_RXDF, PCXHR_TIMEOUT_DSP, &reg); 692 PCXHR_ISR_HI08_RXDF,
693 PCXHR_ISR_HI08_RXDF,
694 PCXHR_TIMEOUT_DSP, &reg);
658 if (err) { 695 if (err) {
659 snd_printk(KERN_ERR "ERROR RMH: ISR:RXDF=1 (ISR = %x)\n", reg); 696 snd_printk(KERN_ERR "ERROR RMH: ISR:RXDF=1 (ISR = %x)\n", reg);
660 return err; 697 return err;
@@ -663,7 +700,8 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
663 data = PCXHR_INPB(mgr, PCXHR_DSP_TXH) << 16; 700 data = PCXHR_INPB(mgr, PCXHR_DSP_TXH) << 16;
664 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXM) << 8; 701 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXM) << 8;
665 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXL); 702 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXL);
666 snd_printk(KERN_ERR "ERROR RMH(%d): 0x%x\n", rmh->cmd_idx, data); 703 snd_printk(KERN_ERR "ERROR RMH(%d): 0x%x\n",
704 rmh->cmd_idx, data);
667 err = -EINVAL; 705 err = -EINVAL;
668 } else { 706 } else {
669 /* read the response data */ 707 /* read the response data */
@@ -732,8 +770,9 @@ int pcxhr_send_msg(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
732static inline int pcxhr_pipes_running(struct pcxhr_mgr *mgr) 770static inline int pcxhr_pipes_running(struct pcxhr_mgr *mgr)
733{ 771{
734 int start_mask = PCXHR_INPL(mgr, PCXHR_PLX_MBOX2); 772 int start_mask = PCXHR_INPL(mgr, PCXHR_PLX_MBOX2);
735 /* least segnificant 12 bits are the pipe states for the playback audios */ 773 /* least segnificant 12 bits are the pipe states
736 /* next 12 bits are the pipe states for the capture audios 774 * for the playback audios
775 * next 12 bits are the pipe states for the capture audios
737 * (PCXHR_PIPE_STATE_CAPTURE_OFFSET) 776 * (PCXHR_PIPE_STATE_CAPTURE_OFFSET)
738 */ 777 */
739 start_mask &= 0xffffff; 778 start_mask &= 0xffffff;
@@ -744,7 +783,8 @@ static inline int pcxhr_pipes_running(struct pcxhr_mgr *mgr)
744#define PCXHR_PIPE_STATE_CAPTURE_OFFSET 12 783#define PCXHR_PIPE_STATE_CAPTURE_OFFSET 12
745#define MAX_WAIT_FOR_DSP 20 784#define MAX_WAIT_FOR_DSP 20
746 785
747static int pcxhr_prepair_pipe_start(struct pcxhr_mgr *mgr, int audio_mask, int *retry) 786static int pcxhr_prepair_pipe_start(struct pcxhr_mgr *mgr,
787 int audio_mask, int *retry)
748{ 788{
749 struct pcxhr_rmh rmh; 789 struct pcxhr_rmh rmh;
750 int err; 790 int err;
@@ -760,17 +800,20 @@ static int pcxhr_prepair_pipe_start(struct pcxhr_mgr *mgr, int audio_mask, int *
760 } else { 800 } else {
761 /* can start capture pipe */ 801 /* can start capture pipe */
762 pcxhr_set_pipe_cmd_params(&rmh, 1, audio - 802 pcxhr_set_pipe_cmd_params(&rmh, 1, audio -
763 PCXHR_PIPE_STATE_CAPTURE_OFFSET, 803 PCXHR_PIPE_STATE_CAPTURE_OFFSET,
764 0, 0); 804 0, 0);
765 } 805 }
766 err = pcxhr_send_msg(mgr, &rmh); 806 err = pcxhr_send_msg(mgr, &rmh);
767 if (err) { 807 if (err) {
768 snd_printk(KERN_ERR 808 snd_printk(KERN_ERR
769 "error pipe start (CMD_CAN_START_PIPE) err=%x!\n", 809 "error pipe start "
810 "(CMD_CAN_START_PIPE) err=%x!\n",
770 err); 811 err);
771 return err; 812 return err;
772 } 813 }
773 /* if the pipe couldn't be prepaired for start, retry it later */ 814 /* if the pipe couldn't be prepaired for start,
815 * retry it later
816 */
774 if (rmh.stat[0] == 0) 817 if (rmh.stat[0] == 0)
775 *retry |= (1<<audio); 818 *retry |= (1<<audio);
776 } 819 }
@@ -795,14 +838,14 @@ static int pcxhr_stop_pipes(struct pcxhr_mgr *mgr, int audio_mask)
795 } else { 838 } else {
796 /* stop capture pipe */ 839 /* stop capture pipe */
797 pcxhr_set_pipe_cmd_params(&rmh, 1, audio - 840 pcxhr_set_pipe_cmd_params(&rmh, 1, audio -
798 PCXHR_PIPE_STATE_CAPTURE_OFFSET, 841 PCXHR_PIPE_STATE_CAPTURE_OFFSET,
799 0, 0); 842 0, 0);
800 } 843 }
801 err = pcxhr_send_msg(mgr, &rmh); 844 err = pcxhr_send_msg(mgr, &rmh);
802 if (err) { 845 if (err) {
803 snd_printk(KERN_ERR 846 snd_printk(KERN_ERR
804 "error pipe stop (CMD_STOP_PIPE) err=%x!\n", 847 "error pipe stop "
805 err); 848 "(CMD_STOP_PIPE) err=%x!\n", err);
806 return err; 849 return err;
807 } 850 }
808 } 851 }
@@ -822,15 +865,16 @@ static int pcxhr_toggle_pipes(struct pcxhr_mgr *mgr, int audio_mask)
822 if (audio_mask & 1) { 865 if (audio_mask & 1) {
823 pcxhr_init_rmh(&rmh, CMD_CONF_PIPE); 866 pcxhr_init_rmh(&rmh, CMD_CONF_PIPE);
824 if (audio < PCXHR_PIPE_STATE_CAPTURE_OFFSET) 867 if (audio < PCXHR_PIPE_STATE_CAPTURE_OFFSET)
825 pcxhr_set_pipe_cmd_params(&rmh, 0, 0, 0, 1 << audio); 868 pcxhr_set_pipe_cmd_params(&rmh, 0, 0, 0,
869 1 << audio);
826 else 870 else
827 pcxhr_set_pipe_cmd_params(&rmh, 1, 0, 0, 871 pcxhr_set_pipe_cmd_params(&rmh, 1, 0, 0,
828 1 << (audio - PCXHR_PIPE_STATE_CAPTURE_OFFSET)); 872 1 << (audio - PCXHR_PIPE_STATE_CAPTURE_OFFSET));
829 err = pcxhr_send_msg(mgr, &rmh); 873 err = pcxhr_send_msg(mgr, &rmh);
830 if (err) { 874 if (err) {
831 snd_printk(KERN_ERR 875 snd_printk(KERN_ERR
832 "error pipe start (CMD_CONF_PIPE) err=%x!\n", 876 "error pipe start "
833 err); 877 "(CMD_CONF_PIPE) err=%x!\n", err);
834 return err; 878 return err;
835 } 879 }
836 } 880 }
@@ -841,7 +885,9 @@ static int pcxhr_toggle_pipes(struct pcxhr_mgr *mgr, int audio_mask)
841 pcxhr_init_rmh(&rmh, CMD_SEND_IRQA); 885 pcxhr_init_rmh(&rmh, CMD_SEND_IRQA);
842 err = pcxhr_send_msg(mgr, &rmh); 886 err = pcxhr_send_msg(mgr, &rmh);
843 if (err) { 887 if (err) {
844 snd_printk(KERN_ERR "error pipe start (CMD_SEND_IRQA) err=%x!\n", err ); 888 snd_printk(KERN_ERR
889 "error pipe start (CMD_SEND_IRQA) err=%x!\n",
890 err);
845 return err; 891 return err;
846 } 892 }
847 return 0; 893 return 0;
@@ -849,7 +895,8 @@ static int pcxhr_toggle_pipes(struct pcxhr_mgr *mgr, int audio_mask)
849 895
850 896
851 897
852int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask, int capture_mask, int start) 898int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask,
899 int capture_mask, int start)
853{ 900{
854 int state, i, err; 901 int state, i, err;
855 int audio_mask; 902 int audio_mask;
@@ -858,21 +905,23 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask, int capture_m
858 struct timeval my_tv1, my_tv2; 905 struct timeval my_tv1, my_tv2;
859 do_gettimeofday(&my_tv1); 906 do_gettimeofday(&my_tv1);
860#endif 907#endif
861 audio_mask = (playback_mask | (capture_mask << PCXHR_PIPE_STATE_CAPTURE_OFFSET)); 908 audio_mask = (playback_mask |
909 (capture_mask << PCXHR_PIPE_STATE_CAPTURE_OFFSET));
862 /* current pipe state (playback + record) */ 910 /* current pipe state (playback + record) */
863 state = pcxhr_pipes_running(mgr); 911 state = pcxhr_pipes_running(mgr);
864 snd_printdd("pcxhr_set_pipe_state %s (mask %x current %x)\n", 912 snd_printdd("pcxhr_set_pipe_state %s (mask %x current %x)\n",
865 start ? "START" : "STOP", audio_mask, state); 913 start ? "START" : "STOP", audio_mask, state);
866 if (start) { 914 if (start) {
867 audio_mask &= ~state; /* start only pipes that are not yet started */ 915 /* start only pipes that are not yet started */
916 audio_mask &= ~state;
868 state = audio_mask; 917 state = audio_mask;
869 for (i = 0; i < MAX_WAIT_FOR_DSP; i++) { 918 for (i = 0; i < MAX_WAIT_FOR_DSP; i++) {
870 err = pcxhr_prepair_pipe_start(mgr, state, &state); 919 err = pcxhr_prepair_pipe_start(mgr, state, &state);
871 if (err) 920 if (err)
872 return err; 921 return err;
873 if (state == 0) 922 if (state == 0)
874 break; /* success, all pipes prepaired for start */ 923 break; /* success, all pipes prepaired */
875 mdelay(1); /* otherwise wait 1 millisecond and retry */ 924 mdelay(1); /* wait 1 millisecond and retry */
876 } 925 }
877 } else { 926 } else {
878 audio_mask &= state; /* stop only pipes that are started */ 927 audio_mask &= state; /* stop only pipes that are started */
@@ -891,7 +940,7 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask, int capture_m
891 if ((state & audio_mask) == (start ? audio_mask : 0)) 940 if ((state & audio_mask) == (start ? audio_mask : 0))
892 break; 941 break;
893 if (++i >= MAX_WAIT_FOR_DSP * 100) { 942 if (++i >= MAX_WAIT_FOR_DSP * 100) {
894 snd_printk(KERN_ERR "error pipe start/stop (ED_NO_RESPONSE_AT_IRQA)\n"); 943 snd_printk(KERN_ERR "error pipe start/stop\n");
895 return -EBUSY; 944 return -EBUSY;
896 } 945 }
897 udelay(10); /* wait 10 microseconds */ 946 udelay(10); /* wait 10 microseconds */
@@ -918,7 +967,8 @@ int pcxhr_write_io_num_reg_cont(struct pcxhr_mgr *mgr, unsigned int mask,
918 967
919 spin_lock_irqsave(&mgr->msg_lock, flags); 968 spin_lock_irqsave(&mgr->msg_lock, flags);
920 if ((mgr->io_num_reg_cont & mask) == value) { 969 if ((mgr->io_num_reg_cont & mask) == value) {
921 snd_printdd("IO_NUM_REG_CONT mask %x already is set to %x\n", mask, value); 970 snd_printdd("IO_NUM_REG_CONT mask %x already is set to %x\n",
971 mask, value);
922 if (changed) 972 if (changed)
923 *changed = 0; 973 *changed = 0;
924 spin_unlock_irqrestore(&mgr->msg_lock, flags); 974 spin_unlock_irqrestore(&mgr->msg_lock, flags);
@@ -971,7 +1021,8 @@ static int pcxhr_handle_async_err(struct pcxhr_mgr *mgr, u32 err,
971 err = ((err >> 12) & 0xfff); 1021 err = ((err >> 12) & 0xfff);
972 if (!err) 1022 if (!err)
973 return 0; 1023 return 0;
974 snd_printdd("CMD_ASYNC : Error %s %s Pipe %d err=%x\n", err_src_name[err_src], 1024 snd_printdd("CMD_ASYNC : Error %s %s Pipe %d err=%x\n",
1025 err_src_name[err_src],
975 is_capture ? "Record" : "Play", pipe, err); 1026 is_capture ? "Record" : "Play", pipe, err);
976 if (err == 0xe01) 1027 if (err == 0xe01)
977 mgr->async_err_stream_xrun++; 1028 mgr->async_err_stream_xrun++;
@@ -996,6 +1047,13 @@ void pcxhr_msg_tasklet(unsigned long arg)
996 snd_printdd("TASKLET : PCXHR_IRQ_TIME_CODE event occured\n"); 1047 snd_printdd("TASKLET : PCXHR_IRQ_TIME_CODE event occured\n");
997 if (mgr->src_it_dsp & PCXHR_IRQ_NOTIFY) 1048 if (mgr->src_it_dsp & PCXHR_IRQ_NOTIFY)
998 snd_printdd("TASKLET : PCXHR_IRQ_NOTIFY event occured\n"); 1049 snd_printdd("TASKLET : PCXHR_IRQ_NOTIFY event occured\n");
1050 if (mgr->src_it_dsp & (PCXHR_IRQ_FREQ_CHANGE | PCXHR_IRQ_TIME_CODE)) {
1051 /* clear events FREQ_CHANGE and TIME_CODE */
1052 pcxhr_init_rmh(prmh, CMD_TEST_IT);
1053 err = pcxhr_send_msg(mgr, prmh);
1054 snd_printdd("CMD_TEST_IT : err=%x, stat=%x\n",
1055 err, prmh->stat[0]);
1056 }
999 if (mgr->src_it_dsp & PCXHR_IRQ_ASYNC) { 1057 if (mgr->src_it_dsp & PCXHR_IRQ_ASYNC) {
1000 snd_printdd("TASKLET : PCXHR_IRQ_ASYNC event occured\n"); 1058 snd_printdd("TASKLET : PCXHR_IRQ_ASYNC event occured\n");
1001 1059
@@ -1005,18 +1063,22 @@ void pcxhr_msg_tasklet(unsigned long arg)
1005 prmh->stat_len = PCXHR_SIZE_MAX_LONG_STATUS; 1063 prmh->stat_len = PCXHR_SIZE_MAX_LONG_STATUS;
1006 err = pcxhr_send_msg(mgr, prmh); 1064 err = pcxhr_send_msg(mgr, prmh);
1007 if (err) 1065 if (err)
1008 snd_printk(KERN_ERR "ERROR pcxhr_msg_tasklet=%x;\n", err); 1066 snd_printk(KERN_ERR "ERROR pcxhr_msg_tasklet=%x;\n",
1067 err);
1009 i = 1; 1068 i = 1;
1010 while (i < prmh->stat_len) { 1069 while (i < prmh->stat_len) {
1011 int nb_audio = (prmh->stat[i] >> FIELD_SIZE) & MASK_FIRST_FIELD; 1070 int nb_audio = ((prmh->stat[i] >> FIELD_SIZE) &
1012 int nb_stream = (prmh->stat[i] >> (2*FIELD_SIZE)) & MASK_FIRST_FIELD; 1071 MASK_FIRST_FIELD);
1072 int nb_stream = ((prmh->stat[i] >> (2*FIELD_SIZE)) &
1073 MASK_FIRST_FIELD);
1013 int pipe = prmh->stat[i] & MASK_FIRST_FIELD; 1074 int pipe = prmh->stat[i] & MASK_FIRST_FIELD;
1014 int is_capture = prmh->stat[i] & 0x400000; 1075 int is_capture = prmh->stat[i] & 0x400000;
1015 u32 err2; 1076 u32 err2;
1016 1077
1017 if (prmh->stat[i] & 0x800000) { /* if BIT_END */ 1078 if (prmh->stat[i] & 0x800000) { /* if BIT_END */
1018 snd_printdd("TASKLET : End%sPipe %d\n", 1079 snd_printdd("TASKLET : End%sPipe %d\n",
1019 is_capture ? "Record" : "Play", pipe); 1080 is_capture ? "Record" : "Play",
1081 pipe);
1020 } 1082 }
1021 i++; 1083 i++;
1022 err2 = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1084 err2 = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1];
@@ -1062,7 +1124,7 @@ static u_int64_t pcxhr_stream_read_position(struct pcxhr_mgr *mgr,
1062 pcxhr_init_rmh(&rmh, CMD_STREAM_SAMPLE_COUNT); 1124 pcxhr_init_rmh(&rmh, CMD_STREAM_SAMPLE_COUNT);
1063 pcxhr_set_pipe_cmd_params(&rmh, stream->pipe->is_capture, 1125 pcxhr_set_pipe_cmd_params(&rmh, stream->pipe->is_capture,
1064 stream->pipe->first_audio, 0, stream_mask); 1126 stream->pipe->first_audio, 0, stream_mask);
1065 /* rmh.stat_len = 2; */ /* 2 resp data for each stream of the pipe */ 1127 /* rmh.stat_len = 2; */ /* 2 resp data for each stream of the pipe */
1066 1128
1067 err = pcxhr_send_msg(mgr, &rmh); 1129 err = pcxhr_send_msg(mgr, &rmh);
1068 if (err) 1130 if (err)
@@ -1072,18 +1134,21 @@ static u_int64_t pcxhr_stream_read_position(struct pcxhr_mgr *mgr,
1072 hw_sample_count += (u_int64_t)rmh.stat[1]; 1134 hw_sample_count += (u_int64_t)rmh.stat[1];
1073 1135
1074 snd_printdd("stream %c%d : abs samples real(%ld) timer(%ld)\n", 1136 snd_printdd("stream %c%d : abs samples real(%ld) timer(%ld)\n",
1075 stream->pipe->is_capture ? 'C':'P', stream->substream->number, 1137 stream->pipe->is_capture ? 'C' : 'P',
1138 stream->substream->number,
1076 (long unsigned int)hw_sample_count, 1139 (long unsigned int)hw_sample_count,
1077 (long unsigned int)(stream->timer_abs_periods + 1140 (long unsigned int)(stream->timer_abs_periods +
1078 stream->timer_period_frag + PCXHR_GRANULARITY)); 1141 stream->timer_period_frag +
1079 1142 mgr->granularity));
1080 return hw_sample_count; 1143 return hw_sample_count;
1081} 1144}
1082 1145
1083static void pcxhr_update_timer_pos(struct pcxhr_mgr *mgr, 1146static void pcxhr_update_timer_pos(struct pcxhr_mgr *mgr,
1084 struct pcxhr_stream *stream, int samples_to_add) 1147 struct pcxhr_stream *stream,
1148 int samples_to_add)
1085{ 1149{
1086 if (stream->substream && (stream->status == PCXHR_STREAM_STATUS_RUNNING)) { 1150 if (stream->substream &&
1151 (stream->status == PCXHR_STREAM_STATUS_RUNNING)) {
1087 u_int64_t new_sample_count; 1152 u_int64_t new_sample_count;
1088 int elapsed = 0; 1153 int elapsed = 0;
1089 int hardware_read = 0; 1154 int hardware_read = 0;
@@ -1092,20 +1157,22 @@ static void pcxhr_update_timer_pos(struct pcxhr_mgr *mgr,
1092 if (samples_to_add < 0) { 1157 if (samples_to_add < 0) {
1093 stream->timer_is_synced = 0; 1158 stream->timer_is_synced = 0;
1094 /* add default if no hardware_read possible */ 1159 /* add default if no hardware_read possible */
1095 samples_to_add = PCXHR_GRANULARITY; 1160 samples_to_add = mgr->granularity;
1096 } 1161 }
1097 1162
1098 if (!stream->timer_is_synced) { 1163 if (!stream->timer_is_synced) {
1099 if (stream->timer_abs_periods != 0 || 1164 if ((stream->timer_abs_periods != 0) ||
1100 stream->timer_period_frag + PCXHR_GRANULARITY >= 1165 ((stream->timer_period_frag + samples_to_add) >=
1101 runtime->period_size) { 1166 runtime->period_size)) {
1102 new_sample_count = pcxhr_stream_read_position(mgr, stream); 1167 new_sample_count =
1168 pcxhr_stream_read_position(mgr, stream);
1103 hardware_read = 1; 1169 hardware_read = 1;
1104 if (new_sample_count >= PCXHR_GRANULARITY_MIN) { 1170 if (new_sample_count >= mgr->granularity) {
1105 /* sub security offset because of jitter and 1171 /* sub security offset because of
1106 * finer granularity of dsp time (MBOX4) 1172 * jitter and finer granularity of
1173 * dsp time (MBOX4)
1107 */ 1174 */
1108 new_sample_count -= PCXHR_GRANULARITY_MIN; 1175 new_sample_count -= mgr->granularity;
1109 stream->timer_is_synced = 1; 1176 stream->timer_is_synced = 1;
1110 } 1177 }
1111 } 1178 }
@@ -1128,12 +1195,15 @@ static void pcxhr_update_timer_pos(struct pcxhr_mgr *mgr,
1128 stream->timer_buf_periods = 0; 1195 stream->timer_buf_periods = 0;
1129 stream->timer_abs_periods = new_elapse_pos; 1196 stream->timer_abs_periods = new_elapse_pos;
1130 } 1197 }
1131 if (new_sample_count >= stream->timer_abs_periods) 1198 if (new_sample_count >= stream->timer_abs_periods) {
1132 stream->timer_period_frag = (u_int32_t)(new_sample_count - 1199 stream->timer_period_frag =
1133 stream->timer_abs_periods); 1200 (u_int32_t)(new_sample_count -
1134 else 1201 stream->timer_abs_periods);
1135 snd_printk(KERN_ERR "ERROR new_sample_count too small ??? %lx\n", 1202 } else {
1203 snd_printk(KERN_ERR
1204 "ERROR new_sample_count too small ??? %ld\n",
1136 (long unsigned int)new_sample_count); 1205 (long unsigned int)new_sample_count);
1206 }
1137 1207
1138 if (elapsed) { 1208 if (elapsed) {
1139 spin_unlock(&mgr->lock); 1209 spin_unlock(&mgr->lock);
@@ -1143,7 +1213,6 @@ static void pcxhr_update_timer_pos(struct pcxhr_mgr *mgr,
1143 } 1213 }
1144} 1214}
1145 1215
1146
1147irqreturn_t pcxhr_interrupt(int irq, void *dev_id) 1216irqreturn_t pcxhr_interrupt(int irq, void *dev_id)
1148{ 1217{
1149 struct pcxhr_mgr *mgr = dev_id; 1218 struct pcxhr_mgr *mgr = dev_id;
@@ -1156,7 +1225,8 @@ irqreturn_t pcxhr_interrupt(int irq, void *dev_id)
1156 reg = PCXHR_INPL(mgr, PCXHR_PLX_IRQCS); 1225 reg = PCXHR_INPL(mgr, PCXHR_PLX_IRQCS);
1157 if (! (reg & PCXHR_IRQCS_ACTIVE_PCIDB)) { 1226 if (! (reg & PCXHR_IRQCS_ACTIVE_PCIDB)) {
1158 spin_unlock(&mgr->lock); 1227 spin_unlock(&mgr->lock);
1159 return IRQ_NONE; /* this device did not cause the interrupt */ 1228 /* this device did not cause the interrupt */
1229 return IRQ_NONE;
1160 } 1230 }
1161 1231
1162 /* clear interrupt */ 1232 /* clear interrupt */
@@ -1167,10 +1237,12 @@ irqreturn_t pcxhr_interrupt(int irq, void *dev_id)
1167 if (reg & PCXHR_IRQ_TIMER) { 1237 if (reg & PCXHR_IRQ_TIMER) {
1168 int timer_toggle = reg & PCXHR_IRQ_TIMER; 1238 int timer_toggle = reg & PCXHR_IRQ_TIMER;
1169 /* is a 24 bit counter */ 1239 /* is a 24 bit counter */
1170 int dsp_time_new = PCXHR_INPL(mgr, PCXHR_PLX_MBOX4) & PCXHR_DSP_TIME_MASK; 1240 int dsp_time_new =
1241 PCXHR_INPL(mgr, PCXHR_PLX_MBOX4) & PCXHR_DSP_TIME_MASK;
1171 int dsp_time_diff = dsp_time_new - mgr->dsp_time_last; 1242 int dsp_time_diff = dsp_time_new - mgr->dsp_time_last;
1172 1243
1173 if (dsp_time_diff < 0 && mgr->dsp_time_last != PCXHR_DSP_TIME_INVALID) { 1244 if ((dsp_time_diff < 0) &&
1245 (mgr->dsp_time_last != PCXHR_DSP_TIME_INVALID)) {
1174 snd_printdd("ERROR DSP TIME old(%d) new(%d) -> " 1246 snd_printdd("ERROR DSP TIME old(%d) new(%d) -> "
1175 "resynchronize all streams\n", 1247 "resynchronize all streams\n",
1176 mgr->dsp_time_last, dsp_time_new); 1248 mgr->dsp_time_last, dsp_time_new);
@@ -1178,42 +1250,51 @@ irqreturn_t pcxhr_interrupt(int irq, void *dev_id)
1178 } 1250 }
1179#ifdef CONFIG_SND_DEBUG_VERBOSE 1251#ifdef CONFIG_SND_DEBUG_VERBOSE
1180 if (dsp_time_diff == 0) 1252 if (dsp_time_diff == 0)
1181 snd_printdd("ERROR DSP TIME NO DIFF time(%d)\n", dsp_time_new); 1253 snd_printdd("ERROR DSP TIME NO DIFF time(%d)\n",
1182 else if (dsp_time_diff >= (2*PCXHR_GRANULARITY)) 1254 dsp_time_new);
1255 else if (dsp_time_diff >= (2*mgr->granularity))
1183 snd_printdd("ERROR DSP TIME TOO BIG old(%d) add(%d)\n", 1256 snd_printdd("ERROR DSP TIME TOO BIG old(%d) add(%d)\n",
1184 mgr->dsp_time_last, dsp_time_new - mgr->dsp_time_last); 1257 mgr->dsp_time_last,
1258 dsp_time_new - mgr->dsp_time_last);
1259 else if (dsp_time_diff % mgr->granularity)
1260 snd_printdd("ERROR DSP TIME increased by %d\n",
1261 dsp_time_diff);
1185#endif 1262#endif
1186 mgr->dsp_time_last = dsp_time_new; 1263 mgr->dsp_time_last = dsp_time_new;
1187 1264
1188 if (timer_toggle == mgr->timer_toggle) 1265 if (timer_toggle == mgr->timer_toggle) {
1189 snd_printdd("ERROR TIMER TOGGLE\n"); 1266 snd_printdd("ERROR TIMER TOGGLE\n");
1267 mgr->dsp_time_err++;
1268 }
1190 mgr->timer_toggle = timer_toggle; 1269 mgr->timer_toggle = timer_toggle;
1191 1270
1192 reg &= ~PCXHR_IRQ_TIMER; 1271 reg &= ~PCXHR_IRQ_TIMER;
1193 for (i = 0; i < mgr->num_cards; i++) { 1272 for (i = 0; i < mgr->num_cards; i++) {
1194 chip = mgr->chip[i]; 1273 chip = mgr->chip[i];
1195 for (j = 0; j < chip->nb_streams_capt; j++) 1274 for (j = 0; j < chip->nb_streams_capt; j++)
1196 pcxhr_update_timer_pos(mgr, &chip->capture_stream[j], 1275 pcxhr_update_timer_pos(mgr,
1197 dsp_time_diff); 1276 &chip->capture_stream[j],
1277 dsp_time_diff);
1198 } 1278 }
1199 for (i = 0; i < mgr->num_cards; i++) { 1279 for (i = 0; i < mgr->num_cards; i++) {
1200 chip = mgr->chip[i]; 1280 chip = mgr->chip[i];
1201 for (j = 0; j < chip->nb_streams_play; j++) 1281 for (j = 0; j < chip->nb_streams_play; j++)
1202 pcxhr_update_timer_pos(mgr, &chip->playback_stream[j], 1282 pcxhr_update_timer_pos(mgr,
1203 dsp_time_diff); 1283 &chip->playback_stream[j],
1284 dsp_time_diff);
1204 } 1285 }
1205 } 1286 }
1206 /* other irq's handled in the tasklet */ 1287 /* other irq's handled in the tasklet */
1207 if (reg & PCXHR_IRQ_MASK) { 1288 if (reg & PCXHR_IRQ_MASK) {
1208 1289 if (reg & PCXHR_IRQ_ASYNC) {
1209 /* as we didn't request any notifications, some kind of xrun error 1290 /* as we didn't request any async notifications,
1210 * will probably occured 1291 * some kind of xrun error will probably occured
1211 */ 1292 */
1212 /* better resynchronize all streams next interrupt : */ 1293 /* better resynchronize all streams next interrupt : */
1213 mgr->dsp_time_last = PCXHR_DSP_TIME_INVALID; 1294 mgr->dsp_time_last = PCXHR_DSP_TIME_INVALID;
1214 1295 }
1215 mgr->src_it_dsp = reg; 1296 mgr->src_it_dsp = reg;
1216 tasklet_hi_schedule(&mgr->msg_taskq); 1297 tasklet_schedule(&mgr->msg_taskq);
1217 } 1298 }
1218#ifdef CONFIG_SND_DEBUG_VERBOSE 1299#ifdef CONFIG_SND_DEBUG_VERBOSE
1219 if (reg & PCXHR_FATAL_DSP_ERR) 1300 if (reg & PCXHR_FATAL_DSP_ERR)
diff --git a/sound/pci/pcxhr/pcxhr_core.h b/sound/pci/pcxhr/pcxhr_core.h
index d9a4ab609875..bbbd66d13a64 100644
--- a/sound/pci/pcxhr/pcxhr_core.h
+++ b/sound/pci/pcxhr/pcxhr_core.h
@@ -65,7 +65,7 @@ enum {
65 CMD_RESYNC_AUDIO_INPUTS, /* cmd_len = 1 stat_len = 0 */ 65 CMD_RESYNC_AUDIO_INPUTS, /* cmd_len = 1 stat_len = 0 */
66 CMD_GET_DSP_RESOURCES, /* cmd_len = 1 stat_len = 4 */ 66 CMD_GET_DSP_RESOURCES, /* cmd_len = 1 stat_len = 4 */
67 CMD_SET_TIMER_INTERRUPT, /* cmd_len = 1 stat_len = 0 */ 67 CMD_SET_TIMER_INTERRUPT, /* cmd_len = 1 stat_len = 0 */
68 CMD_RES_PIPE, /* cmd_len = 2 stat_len = 0 */ 68 CMD_RES_PIPE, /* cmd_len >=2 stat_len = 0 */
69 CMD_FREE_PIPE, /* cmd_len = 1 stat_len = 0 */ 69 CMD_FREE_PIPE, /* cmd_len = 1 stat_len = 0 */
70 CMD_CONF_PIPE, /* cmd_len = 2 stat_len = 0 */ 70 CMD_CONF_PIPE, /* cmd_len = 2 stat_len = 0 */
71 CMD_STOP_PIPE, /* cmd_len = 1 stat_len = 0 */ 71 CMD_STOP_PIPE, /* cmd_len = 1 stat_len = 0 */
@@ -96,6 +96,8 @@ void pcxhr_init_rmh(struct pcxhr_rmh *rmh, int cmd);
96void pcxhr_set_pipe_cmd_params(struct pcxhr_rmh* rmh, int capture, unsigned int param1, 96void pcxhr_set_pipe_cmd_params(struct pcxhr_rmh* rmh, int capture, unsigned int param1,
97 unsigned int param2, unsigned int param3); 97 unsigned int param2, unsigned int param3);
98 98
99#define DSP_EXT_CMD_SET(x) (x->dsp_version > 0x012800)
100
99/* 101/*
100 send the rmh 102 send the rmh
101 */ 103 */
@@ -110,6 +112,7 @@ int pcxhr_send_msg(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh);
110#define IO_NUM_REG_STATUS 5 112#define IO_NUM_REG_STATUS 5
111#define IO_NUM_REG_CUER 10 113#define IO_NUM_REG_CUER 10
112#define IO_NUM_UER_CHIP_REG 11 114#define IO_NUM_UER_CHIP_REG 11
115#define IO_NUM_REG_CONFIG_SRC 12
113#define IO_NUM_REG_OUT_ANA_LEVEL 20 116#define IO_NUM_REG_OUT_ANA_LEVEL 20
114#define IO_NUM_REG_IN_ANA_LEVEL 21 117#define IO_NUM_REG_IN_ANA_LEVEL 21
115 118
diff --git a/sound/pci/pcxhr/pcxhr_hwdep.c b/sound/pci/pcxhr/pcxhr_hwdep.c
index 96640d9c227d..592743a298b0 100644
--- a/sound/pci/pcxhr/pcxhr_hwdep.c
+++ b/sound/pci/pcxhr/pcxhr_hwdep.c
@@ -31,6 +31,7 @@
31#include "pcxhr_mixer.h" 31#include "pcxhr_mixer.h"
32#include "pcxhr_hwdep.h" 32#include "pcxhr_hwdep.h"
33#include "pcxhr_core.h" 33#include "pcxhr_core.h"
34#include "pcxhr_mix22.h"
34 35
35 36
36#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE) 37#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
@@ -40,10 +41,10 @@
40#endif 41#endif
41 42
42 43
44static int pcxhr_sub_init(struct pcxhr_mgr *mgr);
43/* 45/*
44 * get basic information and init pcxhr card 46 * get basic information and init pcxhr card
45 */ 47 */
46
47static int pcxhr_init_board(struct pcxhr_mgr *mgr) 48static int pcxhr_init_board(struct pcxhr_mgr *mgr)
48{ 49{
49 int err; 50 int err;
@@ -68,7 +69,7 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
68 if ((rmh.stat[0] & MASK_FIRST_FIELD) != mgr->playback_chips * 2) 69 if ((rmh.stat[0] & MASK_FIRST_FIELD) != mgr->playback_chips * 2)
69 return -EINVAL; 70 return -EINVAL;
70 /* test 8 or 2 phys in */ 71 /* test 8 or 2 phys in */
71 if (((rmh.stat[0] >> (2 * FIELD_SIZE)) & MASK_FIRST_FIELD) != 72 if (((rmh.stat[0] >> (2 * FIELD_SIZE)) & MASK_FIRST_FIELD) <
72 mgr->capture_chips * 2) 73 mgr->capture_chips * 2)
73 return -EINVAL; 74 return -EINVAL;
74 /* test max nb substream per board */ 75 /* test max nb substream per board */
@@ -77,20 +78,34 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
77 /* test max nb substream per pipe */ 78 /* test max nb substream per pipe */
78 if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS) 79 if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS)
79 return -EINVAL; 80 return -EINVAL;
81 snd_printdd("supported formats : playback=%x capture=%x\n",
82 rmh.stat[2], rmh.stat[3]);
80 83
81 pcxhr_init_rmh(&rmh, CMD_VERSION); 84 pcxhr_init_rmh(&rmh, CMD_VERSION);
82 /* firmware num for DSP */ 85 /* firmware num for DSP */
83 rmh.cmd[0] |= mgr->firmware_num; 86 rmh.cmd[0] |= mgr->firmware_num;
84 /* transfer granularity in samples (should be multiple of 48) */ 87 /* transfer granularity in samples (should be multiple of 48) */
85 rmh.cmd[1] = (1<<23) + PCXHR_GRANULARITY; 88 rmh.cmd[1] = (1<<23) + mgr->granularity;
86 rmh.cmd_len = 2; 89 rmh.cmd_len = 2;
87 err = pcxhr_send_msg(mgr, &rmh); 90 err = pcxhr_send_msg(mgr, &rmh);
88 if (err) 91 if (err)
89 return err; 92 return err;
90 snd_printdd("PCXHR DSP version is %d.%d.%d\n", 93 snd_printdd("PCXHR DSP version is %d.%d.%d\n", (rmh.stat[0]>>16)&0xff,
91 (rmh.stat[0]>>16)&0xff, (rmh.stat[0]>>8)&0xff, rmh.stat[0]&0xff); 94 (rmh.stat[0]>>8)&0xff, rmh.stat[0]&0xff);
92 mgr->dsp_version = rmh.stat[0]; 95 mgr->dsp_version = rmh.stat[0];
93 96
97 if (mgr->is_hr_stereo)
98 err = hr222_sub_init(mgr);
99 else
100 err = pcxhr_sub_init(mgr);
101 return err;
102}
103
104static int pcxhr_sub_init(struct pcxhr_mgr *mgr)
105{
106 int err;
107 struct pcxhr_rmh rmh;
108
94 /* get options */ 109 /* get options */
95 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); 110 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
96 rmh.cmd[0] |= IO_NUM_REG_STATUS; 111 rmh.cmd[0] |= IO_NUM_REG_STATUS;
@@ -100,20 +115,22 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
100 if (err) 115 if (err)
101 return err; 116 return err;
102 117
103 if ((rmh.stat[1] & REG_STATUS_OPT_DAUGHTER_MASK) == REG_STATUS_OPT_ANALOG_BOARD) 118 if ((rmh.stat[1] & REG_STATUS_OPT_DAUGHTER_MASK) ==
104 mgr->board_has_analog = 1; /* analog addon board available */ 119 REG_STATUS_OPT_ANALOG_BOARD)
105 else 120 mgr->board_has_analog = 1; /* analog addon board found */
106 /* analog addon board not available -> no support for instance */
107 return -EINVAL;
108 121
109 /* unmute inputs */ 122 /* unmute inputs */
110 err = pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS, 123 err = pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS,
111 REG_CONT_UNMUTE_INPUTS, NULL); 124 REG_CONT_UNMUTE_INPUTS, NULL);
112 if (err) 125 if (err)
113 return err; 126 return err;
114 /* unmute outputs */ 127 /* unmute outputs (a write to IO_NUM_REG_MUTE_OUT mutes!) */
115 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); /* a write to IO_NUM_REG_MUTE_OUT mutes! */ 128 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
116 rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT; 129 rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
130 if (DSP_EXT_CMD_SET(mgr)) {
131 rmh.cmd[1] = 1; /* unmute digital plugs */
132 rmh.cmd_len = 2;
133 }
117 err = pcxhr_send_msg(mgr, &rmh); 134 err = pcxhr_send_msg(mgr, &rmh);
118 return err; 135 return err;
119} 136}
@@ -124,19 +141,25 @@ void pcxhr_reset_board(struct pcxhr_mgr *mgr)
124 141
125 if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) { 142 if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) {
126 /* mute outputs */ 143 /* mute outputs */
144 if (!mgr->is_hr_stereo) {
127 /* a read to IO_NUM_REG_MUTE_OUT register unmutes! */ 145 /* a read to IO_NUM_REG_MUTE_OUT register unmutes! */
128 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); 146 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
129 rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT; 147 rmh.cmd[0] |= IO_NUM_REG_MUTE_OUT;
130 pcxhr_send_msg(mgr, &rmh); 148 pcxhr_send_msg(mgr, &rmh);
131 /* mute inputs */ 149 /* mute inputs */
132 pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS, 0, NULL); 150 pcxhr_write_io_num_reg_cont(mgr, REG_CONT_UNMUTE_INPUTS,
151 0, NULL);
152 }
153 /* stereo cards mute with reset of dsp */
133 } 154 }
134 /* reset pcxhr dsp */ 155 /* reset pcxhr dsp */
135 if (mgr->dsp_loaded & ( 1 << PCXHR_FIRMWARE_DSP_EPRM_INDEX)) 156 if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_EPRM_INDEX))
136 pcxhr_reset_dsp(mgr); 157 pcxhr_reset_dsp(mgr);
137 /* reset second xilinx */ 158 /* reset second xilinx */
138 if (mgr->dsp_loaded & ( 1 << PCXHR_FIRMWARE_XLX_COM_INDEX)) 159 if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_XLX_COM_INDEX)) {
139 pcxhr_reset_xilinx_com(mgr); 160 pcxhr_reset_xilinx_com(mgr);
161 mgr->dsp_loaded = 1;
162 }
140 return; 163 return;
141} 164}
142 165
@@ -144,8 +167,9 @@ void pcxhr_reset_board(struct pcxhr_mgr *mgr)
144/* 167/*
145 * allocate a playback/capture pipe (pcmp0/pcmc0) 168 * allocate a playback/capture pipe (pcmp0/pcmc0)
146 */ 169 */
147static int pcxhr_dsp_allocate_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pipe, 170static int pcxhr_dsp_allocate_pipe(struct pcxhr_mgr *mgr,
148 int is_capture, int pin) 171 struct pcxhr_pipe *pipe,
172 int is_capture, int pin)
149{ 173{
150 int stream_count, audio_count; 174 int stream_count, audio_count;
151 int err; 175 int err;
@@ -161,15 +185,23 @@ static int pcxhr_dsp_allocate_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pi
161 stream_count = PCXHR_PLAYBACK_STREAMS; 185 stream_count = PCXHR_PLAYBACK_STREAMS;
162 audio_count = 2; /* always stereo */ 186 audio_count = 2; /* always stereo */
163 } 187 }
164 snd_printdd("snd_add_ref_pipe pin(%d) pcm%c0\n", pin, is_capture ? 'c' : 'p'); 188 snd_printdd("snd_add_ref_pipe pin(%d) pcm%c0\n",
189 pin, is_capture ? 'c' : 'p');
165 pipe->is_capture = is_capture; 190 pipe->is_capture = is_capture;
166 pipe->first_audio = pin; 191 pipe->first_audio = pin;
167 /* define pipe (P_PCM_ONLY_MASK (0x020000) is not necessary) */ 192 /* define pipe (P_PCM_ONLY_MASK (0x020000) is not necessary) */
168 pcxhr_init_rmh(&rmh, CMD_RES_PIPE); 193 pcxhr_init_rmh(&rmh, CMD_RES_PIPE);
169 pcxhr_set_pipe_cmd_params(&rmh, is_capture, pin, audio_count, stream_count); 194 pcxhr_set_pipe_cmd_params(&rmh, is_capture, pin,
195 audio_count, stream_count);
196 rmh.cmd[1] |= 0x020000; /* add P_PCM_ONLY_MASK */
197 if (DSP_EXT_CMD_SET(mgr)) {
198 /* add channel mask to command */
199 rmh.cmd[rmh.cmd_len++] = (audio_count == 1) ? 0x01 : 0x03;
200 }
170 err = pcxhr_send_msg(mgr, &rmh); 201 err = pcxhr_send_msg(mgr, &rmh);
171 if (err < 0) { 202 if (err < 0) {
172 snd_printk(KERN_ERR "error pipe allocation (CMD_RES_PIPE) err=%x!\n", err ); 203 snd_printk(KERN_ERR "error pipe allocation "
204 "(CMD_RES_PIPE) err=%x!\n", err);
173 return err; 205 return err;
174 } 206 }
175 pipe->status = PCXHR_PIPE_DEFINED; 207 pipe->status = PCXHR_PIPE_DEFINED;
@@ -199,10 +231,12 @@ static int pcxhr_dsp_free_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pipe)
199 snd_printk(KERN_ERR "error stopping pipe!\n"); 231 snd_printk(KERN_ERR "error stopping pipe!\n");
200 /* release the pipe */ 232 /* release the pipe */
201 pcxhr_init_rmh(&rmh, CMD_FREE_PIPE); 233 pcxhr_init_rmh(&rmh, CMD_FREE_PIPE);
202 pcxhr_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->first_audio, 0, 0); 234 pcxhr_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->first_audio,
235 0, 0);
203 err = pcxhr_send_msg(mgr, &rmh); 236 err = pcxhr_send_msg(mgr, &rmh);
204 if (err < 0) 237 if (err < 0)
205 snd_printk(KERN_ERR "error pipe release (CMD_FREE_PIPE) err(%x)\n", err); 238 snd_printk(KERN_ERR "error pipe release "
239 "(CMD_FREE_PIPE) err(%x)\n", err);
206 pipe->status = PCXHR_PIPE_UNDEFINED; 240 pipe->status = PCXHR_PIPE_UNDEFINED;
207 return err; 241 return err;
208} 242}
@@ -248,15 +282,16 @@ static int pcxhr_start_pipes(struct pcxhr_mgr *mgr)
248 for (i = 0; i < mgr->num_cards; i++) { 282 for (i = 0; i < mgr->num_cards; i++) {
249 chip = mgr->chip[i]; 283 chip = mgr->chip[i];
250 if (chip->nb_streams_play) 284 if (chip->nb_streams_play)
251 playback_mask |= (1 << chip->playback_pipe.first_audio); 285 playback_mask |= 1 << chip->playback_pipe.first_audio;
252 for (j = 0; j < chip->nb_streams_capt; j++) 286 for (j = 0; j < chip->nb_streams_capt; j++)
253 capture_mask |= (1 << chip->capture_pipe[j].first_audio); 287 capture_mask |= 1 << chip->capture_pipe[j].first_audio;
254 } 288 }
255 return pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1); 289 return pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1);
256} 290}
257 291
258 292
259static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index, const struct firmware *dsp) 293static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index,
294 const struct firmware *dsp)
260{ 295{
261 int err, card_index; 296 int err, card_index;
262 297
@@ -330,22 +365,33 @@ static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index, const struct firmwar
330 365
331int pcxhr_setup_firmware(struct pcxhr_mgr *mgr) 366int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
332{ 367{
333 static char *fw_files[5] = { 368 static char *fw_files[][5] = {
334 "xi_1_882.dat", 369 [0] = { "xlxint.dat", "xlxc882hr.dat",
335 "xc_1_882.dat", 370 "dspe882.e56", "dspb882hr.b56", "dspd882.d56" },
336 "e321_512.e56", 371 [1] = { "xlxint.dat", "xlxc882e.dat",
337 "b321_512.b56", 372 "dspe882.e56", "dspb882e.b56", "dspd882.d56" },
338 "d321_512.d56" 373 [2] = { "xlxint.dat", "xlxc1222hr.dat",
374 "dspe882.e56", "dspb1222hr.b56", "dspd1222.d56" },
375 [3] = { "xlxint.dat", "xlxc1222e.dat",
376 "dspe882.e56", "dspb1222e.b56", "dspd1222.d56" },
377 [4] = { NULL, "xlxc222.dat",
378 "dspe924.e56", "dspb924.b56", "dspd222.d56" },
379 [5] = { NULL, "xlxc924.dat",
380 "dspe924.e56", "dspb924.b56", "dspd222.d56" },
339 }; 381 };
340 char path[32]; 382 char path[32];
341 383
342 const struct firmware *fw_entry; 384 const struct firmware *fw_entry;
343 int i, err; 385 int i, err;
386 int fw_set = mgr->fw_file_set;
344 387
345 for (i = 0; i < ARRAY_SIZE(fw_files); i++) { 388 for (i = 0; i < 5; i++) {
346 sprintf(path, "pcxhr/%s", fw_files[i]); 389 if (!fw_files[fw_set][i])
390 continue;
391 sprintf(path, "pcxhr/%s", fw_files[fw_set][i]);
347 if (request_firmware(&fw_entry, path, &mgr->pci->dev)) { 392 if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
348 snd_printk(KERN_ERR "pcxhr: can't load firmware %s\n", path); 393 snd_printk(KERN_ERR "pcxhr: can't load firmware %s\n",
394 path);
349 return -ENOENT; 395 return -ENOENT;
350 } 396 }
351 /* fake hwdep dsp record */ 397 /* fake hwdep dsp record */
@@ -358,11 +404,26 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
358 return 0; 404 return 0;
359} 405}
360 406
361MODULE_FIRMWARE("pcxhr/xi_1_882.dat"); 407MODULE_FIRMWARE("pcxhr/xlxint.dat");
362MODULE_FIRMWARE("pcxhr/xc_1_882.dat"); 408MODULE_FIRMWARE("pcxhr/xlxc882hr.dat");
363MODULE_FIRMWARE("pcxhr/e321_512.e56"); 409MODULE_FIRMWARE("pcxhr/xlxc882e.dat");
364MODULE_FIRMWARE("pcxhr/b321_512.b56"); 410MODULE_FIRMWARE("pcxhr/dspe882.e56");
365MODULE_FIRMWARE("pcxhr/d321_512.d56"); 411MODULE_FIRMWARE("pcxhr/dspb882hr.b56");
412MODULE_FIRMWARE("pcxhr/dspb882e.b56");
413MODULE_FIRMWARE("pcxhr/dspd882.d56");
414
415MODULE_FIRMWARE("pcxhr/xlxc1222hr.dat");
416MODULE_FIRMWARE("pcxhr/xlxc1222e.dat");
417MODULE_FIRMWARE("pcxhr/dspb1222hr.b56");
418MODULE_FIRMWARE("pcxhr/dspb1222e.b56");
419MODULE_FIRMWARE("pcxhr/dspd1222.d56");
420
421MODULE_FIRMWARE("pcxhr/xlxc222.dat");
422MODULE_FIRMWARE("pcxhr/xlxc924.dat");
423MODULE_FIRMWARE("pcxhr/dspe924.e56");
424MODULE_FIRMWARE("pcxhr/dspb924.b56");
425MODULE_FIRMWARE("pcxhr/dspd222.d56");
426
366 427
367#else /* old style firmware loading */ 428#else /* old style firmware loading */
368 429
@@ -373,7 +434,8 @@ MODULE_FIRMWARE("pcxhr/d321_512.d56");
373static int pcxhr_hwdep_dsp_status(struct snd_hwdep *hw, 434static int pcxhr_hwdep_dsp_status(struct snd_hwdep *hw,
374 struct snd_hwdep_dsp_status *info) 435 struct snd_hwdep_dsp_status *info)
375{ 436{
376 strcpy(info->id, "pcxhr"); 437 struct pcxhr_mgr *mgr = hw->private_data;
438 sprintf(info->id, "pcxhr%d", mgr->fw_file_set);
377 info->num_dsps = PCXHR_FIRMWARE_FILES_MAX_INDEX; 439 info->num_dsps = PCXHR_FIRMWARE_FILES_MAX_INDEX;
378 440
379 if (hw->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) 441 if (hw->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX))
@@ -393,8 +455,8 @@ static int pcxhr_hwdep_dsp_load(struct snd_hwdep *hw,
393 fw.size = dsp->length; 455 fw.size = dsp->length;
394 fw.data = vmalloc(fw.size); 456 fw.data = vmalloc(fw.size);
395 if (! fw.data) { 457 if (! fw.data) {
396 snd_printk(KERN_ERR "pcxhr: cannot allocate dsp image (%lu bytes)\n", 458 snd_printk(KERN_ERR "pcxhr: cannot allocate dsp image "
397 (unsigned long)fw.size); 459 "(%lu bytes)\n", (unsigned long)fw.size);
398 return -ENOMEM; 460 return -ENOMEM;
399 } 461 }
400 if (copy_from_user((void *)fw.data, dsp->image, dsp->length)) { 462 if (copy_from_user((void *)fw.data, dsp->image, dsp->length)) {
@@ -424,8 +486,11 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
424 int err; 486 int err;
425 struct snd_hwdep *hw; 487 struct snd_hwdep *hw;
426 488
427 /* only create hwdep interface for first cardX (see "index" module parameter)*/ 489 /* only create hwdep interface for first cardX
428 if ((err = snd_hwdep_new(mgr->chip[0]->card, PCXHR_HWDEP_ID, 0, &hw)) < 0) 490 * (see "index" module parameter)
491 */
492 err = snd_hwdep_new(mgr->chip[0]->card, PCXHR_HWDEP_ID, 0, &hw);
493 if (err < 0)
429 return err; 494 return err;
430 495
431 hw->iface = SNDRV_HWDEP_IFACE_PCXHR; 496 hw->iface = SNDRV_HWDEP_IFACE_PCXHR;
@@ -435,10 +500,13 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
435 hw->ops.dsp_status = pcxhr_hwdep_dsp_status; 500 hw->ops.dsp_status = pcxhr_hwdep_dsp_status;
436 hw->ops.dsp_load = pcxhr_hwdep_dsp_load; 501 hw->ops.dsp_load = pcxhr_hwdep_dsp_load;
437 hw->exclusive = 1; 502 hw->exclusive = 1;
503 /* stereo cards don't need fw_file_0 -> dsp_loaded = 1 */
504 hw->dsp_loaded = mgr->is_hr_stereo ? 1 : 0;
438 mgr->dsp_loaded = 0; 505 mgr->dsp_loaded = 0;
439 sprintf(hw->name, PCXHR_HWDEP_ID); 506 sprintf(hw->name, PCXHR_HWDEP_ID);
440 507
441 if ((err = snd_card_register(mgr->chip[0]->card)) < 0) 508 err = snd_card_register(mgr->chip[0]->card);
509 if (err < 0)
442 return err; 510 return err;
443 return 0; 511 return 0;
444} 512}
diff --git a/sound/pci/pcxhr/pcxhr_mix22.c b/sound/pci/pcxhr/pcxhr_mix22.c
new file mode 100644
index 000000000000..ff019126b672
--- /dev/null
+++ b/sound/pci/pcxhr/pcxhr_mix22.c
@@ -0,0 +1,820 @@
1/*
2 * Driver for Digigram pcxhr compatible soundcards
3 *
4 * mixer interface for stereo cards
5 *
6 * Copyright (c) 2004 by Digigram <alsa@digigram.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 as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/delay.h>
24#include <linux/io.h>
25#include <sound/core.h>
26#include <sound/control.h>
27#include <sound/tlv.h>
28#include <sound/asoundef.h>
29#include "pcxhr.h"
30#include "pcxhr_core.h"
31#include "pcxhr_mix22.h"
32
33
34/* registers used on the DSP and Xilinx (port 2) : HR stereo cards only */
35#define PCXHR_DSP_RESET 0x20
36#define PCXHR_XLX_CFG 0x24
37#define PCXHR_XLX_RUER 0x28
38#define PCXHR_XLX_DATA 0x2C
39#define PCXHR_XLX_STATUS 0x30
40#define PCXHR_XLX_LOFREQ 0x34
41#define PCXHR_XLX_HIFREQ 0x38
42#define PCXHR_XLX_CSUER 0x3C
43#define PCXHR_XLX_SELMIC 0x40
44
45#define PCXHR_DSP 2
46
47/* byte access only ! */
48#define PCXHR_INPB(mgr, x) inb((mgr)->port[PCXHR_DSP] + (x))
49#define PCXHR_OUTPB(mgr, x, data) outb((data), (mgr)->port[PCXHR_DSP] + (x))
50
51
52/* values for PCHR_DSP_RESET register */
53#define PCXHR_DSP_RESET_DSP 0x01
54#define PCXHR_DSP_RESET_MUTE 0x02
55#define PCXHR_DSP_RESET_CODEC 0x08
56
57/* values for PCHR_XLX_CFG register */
58#define PCXHR_CFG_SYNCDSP_MASK 0x80
59#define PCXHR_CFG_DEPENDENCY_MASK 0x60
60#define PCXHR_CFG_INDEPENDANT_SEL 0x00
61#define PCXHR_CFG_MASTER_SEL 0x40
62#define PCXHR_CFG_SLAVE_SEL 0x20
63#define PCXHR_CFG_DATA_UER1_SEL_MASK 0x10 /* 0 (UER0), 1(UER1) */
64#define PCXHR_CFG_DATAIN_SEL_MASK 0x08 /* 0 (ana), 1 (UER) */
65#define PCXHR_CFG_SRC_MASK 0x04 /* 0 (Bypass), 1 (SRC Actif) */
66#define PCXHR_CFG_CLOCK_UER1_SEL_MASK 0x02 /* 0 (UER0), 1(UER1) */
67#define PCXHR_CFG_CLOCKIN_SEL_MASK 0x01 /* 0 (internal), 1 (AES/EBU) */
68
69/* values for PCHR_XLX_DATA register */
70#define PCXHR_DATA_CODEC 0x80
71#define AKM_POWER_CONTROL_CMD 0xA007
72#define AKM_RESET_ON_CMD 0xA100
73#define AKM_RESET_OFF_CMD 0xA103
74#define AKM_CLOCK_INF_55K_CMD 0xA240
75#define AKM_CLOCK_SUP_55K_CMD 0xA24D
76#define AKM_MUTE_CMD 0xA38D
77#define AKM_UNMUTE_CMD 0xA30D
78#define AKM_LEFT_LEVEL_CMD 0xA600
79#define AKM_RIGHT_LEVEL_CMD 0xA700
80
81/* values for PCHR_XLX_STATUS register - READ */
82#define PCXHR_STAT_SRC_LOCK 0x01
83#define PCXHR_STAT_LEVEL_IN 0x02
84#define PCXHR_STAT_MIC_CAPS 0x10
85/* values for PCHR_XLX_STATUS register - WRITE */
86#define PCXHR_STAT_FREQ_SYNC_MASK 0x01
87#define PCXHR_STAT_FREQ_UER1_MASK 0x02
88#define PCXHR_STAT_FREQ_SAVE_MASK 0x80
89
90/* values for PCHR_XLX_CSUER register */
91#define PCXHR_SUER1_BIT_U_READ_MASK 0x80
92#define PCXHR_SUER1_BIT_C_READ_MASK 0x40
93#define PCXHR_SUER1_DATA_PRESENT_MASK 0x20
94#define PCXHR_SUER1_CLOCK_PRESENT_MASK 0x10
95#define PCXHR_SUER_BIT_U_READ_MASK 0x08
96#define PCXHR_SUER_BIT_C_READ_MASK 0x04
97#define PCXHR_SUER_DATA_PRESENT_MASK 0x02
98#define PCXHR_SUER_CLOCK_PRESENT_MASK 0x01
99
100#define PCXHR_SUER_BIT_U_WRITE_MASK 0x02
101#define PCXHR_SUER_BIT_C_WRITE_MASK 0x01
102
103/* values for PCXHR_XLX_SELMIC register - WRITE */
104#define PCXHR_SELMIC_PREAMPLI_OFFSET 2
105#define PCXHR_SELMIC_PREAMPLI_MASK 0x0C
106#define PCXHR_SELMIC_PHANTOM_ALIM 0x80
107
108
109static const unsigned char g_hr222_p_level[] = {
110 0x00, /* [000] -49.5 dB: AKM[000] = -1.#INF dB (mute) */
111 0x01, /* [001] -49.0 dB: AKM[001] = -48.131 dB (diff=0.86920 dB) */
112 0x01, /* [002] -48.5 dB: AKM[001] = -48.131 dB (diff=0.36920 dB) */
113 0x01, /* [003] -48.0 dB: AKM[001] = -48.131 dB (diff=0.13080 dB) */
114 0x01, /* [004] -47.5 dB: AKM[001] = -48.131 dB (diff=0.63080 dB) */
115 0x01, /* [005] -46.5 dB: AKM[001] = -48.131 dB (diff=1.63080 dB) */
116 0x01, /* [006] -47.0 dB: AKM[001] = -48.131 dB (diff=1.13080 dB) */
117 0x01, /* [007] -46.0 dB: AKM[001] = -48.131 dB (diff=2.13080 dB) */
118 0x01, /* [008] -45.5 dB: AKM[001] = -48.131 dB (diff=2.63080 dB) */
119 0x02, /* [009] -45.0 dB: AKM[002] = -42.110 dB (diff=2.88980 dB) */
120 0x02, /* [010] -44.5 dB: AKM[002] = -42.110 dB (diff=2.38980 dB) */
121 0x02, /* [011] -44.0 dB: AKM[002] = -42.110 dB (diff=1.88980 dB) */
122 0x02, /* [012] -43.5 dB: AKM[002] = -42.110 dB (diff=1.38980 dB) */
123 0x02, /* [013] -43.0 dB: AKM[002] = -42.110 dB (diff=0.88980 dB) */
124 0x02, /* [014] -42.5 dB: AKM[002] = -42.110 dB (diff=0.38980 dB) */
125 0x02, /* [015] -42.0 dB: AKM[002] = -42.110 dB (diff=0.11020 dB) */
126 0x02, /* [016] -41.5 dB: AKM[002] = -42.110 dB (diff=0.61020 dB) */
127 0x02, /* [017] -41.0 dB: AKM[002] = -42.110 dB (diff=1.11020 dB) */
128 0x02, /* [018] -40.5 dB: AKM[002] = -42.110 dB (diff=1.61020 dB) */
129 0x03, /* [019] -40.0 dB: AKM[003] = -38.588 dB (diff=1.41162 dB) */
130 0x03, /* [020] -39.5 dB: AKM[003] = -38.588 dB (diff=0.91162 dB) */
131 0x03, /* [021] -39.0 dB: AKM[003] = -38.588 dB (diff=0.41162 dB) */
132 0x03, /* [022] -38.5 dB: AKM[003] = -38.588 dB (diff=0.08838 dB) */
133 0x03, /* [023] -38.0 dB: AKM[003] = -38.588 dB (diff=0.58838 dB) */
134 0x03, /* [024] -37.5 dB: AKM[003] = -38.588 dB (diff=1.08838 dB) */
135 0x04, /* [025] -37.0 dB: AKM[004] = -36.090 dB (diff=0.91040 dB) */
136 0x04, /* [026] -36.5 dB: AKM[004] = -36.090 dB (diff=0.41040 dB) */
137 0x04, /* [027] -36.0 dB: AKM[004] = -36.090 dB (diff=0.08960 dB) */
138 0x04, /* [028] -35.5 dB: AKM[004] = -36.090 dB (diff=0.58960 dB) */
139 0x05, /* [029] -35.0 dB: AKM[005] = -34.151 dB (diff=0.84860 dB) */
140 0x05, /* [030] -34.5 dB: AKM[005] = -34.151 dB (diff=0.34860 dB) */
141 0x05, /* [031] -34.0 dB: AKM[005] = -34.151 dB (diff=0.15140 dB) */
142 0x05, /* [032] -33.5 dB: AKM[005] = -34.151 dB (diff=0.65140 dB) */
143 0x06, /* [033] -33.0 dB: AKM[006] = -32.568 dB (diff=0.43222 dB) */
144 0x06, /* [034] -32.5 dB: AKM[006] = -32.568 dB (diff=0.06778 dB) */
145 0x06, /* [035] -32.0 dB: AKM[006] = -32.568 dB (diff=0.56778 dB) */
146 0x07, /* [036] -31.5 dB: AKM[007] = -31.229 dB (diff=0.27116 dB) */
147 0x07, /* [037] -31.0 dB: AKM[007] = -31.229 dB (diff=0.22884 dB) */
148 0x08, /* [038] -30.5 dB: AKM[008] = -30.069 dB (diff=0.43100 dB) */
149 0x08, /* [039] -30.0 dB: AKM[008] = -30.069 dB (diff=0.06900 dB) */
150 0x09, /* [040] -29.5 dB: AKM[009] = -29.046 dB (diff=0.45405 dB) */
151 0x09, /* [041] -29.0 dB: AKM[009] = -29.046 dB (diff=0.04595 dB) */
152 0x0a, /* [042] -28.5 dB: AKM[010] = -28.131 dB (diff=0.36920 dB) */
153 0x0a, /* [043] -28.0 dB: AKM[010] = -28.131 dB (diff=0.13080 dB) */
154 0x0b, /* [044] -27.5 dB: AKM[011] = -27.303 dB (diff=0.19705 dB) */
155 0x0b, /* [045] -27.0 dB: AKM[011] = -27.303 dB (diff=0.30295 dB) */
156 0x0c, /* [046] -26.5 dB: AKM[012] = -26.547 dB (diff=0.04718 dB) */
157 0x0d, /* [047] -26.0 dB: AKM[013] = -25.852 dB (diff=0.14806 dB) */
158 0x0e, /* [048] -25.5 dB: AKM[014] = -25.208 dB (diff=0.29176 dB) */
159 0x0e, /* [049] -25.0 dB: AKM[014] = -25.208 dB (diff=0.20824 dB) */
160 0x0f, /* [050] -24.5 dB: AKM[015] = -24.609 dB (diff=0.10898 dB) */
161 0x10, /* [051] -24.0 dB: AKM[016] = -24.048 dB (diff=0.04840 dB) */
162 0x11, /* [052] -23.5 dB: AKM[017] = -23.522 dB (diff=0.02183 dB) */
163 0x12, /* [053] -23.0 dB: AKM[018] = -23.025 dB (diff=0.02535 dB) */
164 0x13, /* [054] -22.5 dB: AKM[019] = -22.556 dB (diff=0.05573 dB) */
165 0x14, /* [055] -22.0 dB: AKM[020] = -22.110 dB (diff=0.11020 dB) */
166 0x15, /* [056] -21.5 dB: AKM[021] = -21.686 dB (diff=0.18642 dB) */
167 0x17, /* [057] -21.0 dB: AKM[023] = -20.896 dB (diff=0.10375 dB) */
168 0x18, /* [058] -20.5 dB: AKM[024] = -20.527 dB (diff=0.02658 dB) */
169 0x1a, /* [059] -20.0 dB: AKM[026] = -19.831 dB (diff=0.16866 dB) */
170 0x1b, /* [060] -19.5 dB: AKM[027] = -19.504 dB (diff=0.00353 dB) */
171 0x1d, /* [061] -19.0 dB: AKM[029] = -18.883 dB (diff=0.11716 dB) */
172 0x1e, /* [062] -18.5 dB: AKM[030] = -18.588 dB (diff=0.08838 dB) */
173 0x20, /* [063] -18.0 dB: AKM[032] = -18.028 dB (diff=0.02780 dB) */
174 0x22, /* [064] -17.5 dB: AKM[034] = -17.501 dB (diff=0.00123 dB) */
175 0x24, /* [065] -17.0 dB: AKM[036] = -17.005 dB (diff=0.00475 dB) */
176 0x26, /* [066] -16.5 dB: AKM[038] = -16.535 dB (diff=0.03513 dB) */
177 0x28, /* [067] -16.0 dB: AKM[040] = -16.090 dB (diff=0.08960 dB) */
178 0x2b, /* [068] -15.5 dB: AKM[043] = -15.461 dB (diff=0.03857 dB) */
179 0x2d, /* [069] -15.0 dB: AKM[045] = -15.067 dB (diff=0.06655 dB) */
180 0x30, /* [070] -14.5 dB: AKM[048] = -14.506 dB (diff=0.00598 dB) */
181 0x33, /* [071] -14.0 dB: AKM[051] = -13.979 dB (diff=0.02060 dB) */
182 0x36, /* [072] -13.5 dB: AKM[054] = -13.483 dB (diff=0.01707 dB) */
183 0x39, /* [073] -13.0 dB: AKM[057] = -13.013 dB (diff=0.01331 dB) */
184 0x3c, /* [074] -12.5 dB: AKM[060] = -12.568 dB (diff=0.06778 dB) */
185 0x40, /* [075] -12.0 dB: AKM[064] = -12.007 dB (diff=0.00720 dB) */
186 0x44, /* [076] -11.5 dB: AKM[068] = -11.481 dB (diff=0.01937 dB) */
187 0x48, /* [077] -11.0 dB: AKM[072] = -10.984 dB (diff=0.01585 dB) */
188 0x4c, /* [078] -10.5 dB: AKM[076] = -10.515 dB (diff=0.01453 dB) */
189 0x51, /* [079] -10.0 dB: AKM[081] = -9.961 dB (diff=0.03890 dB) */
190 0x55, /* [080] -9.5 dB: AKM[085] = -9.542 dB (diff=0.04243 dB) */
191 0x5a, /* [081] -9.0 dB: AKM[090] = -9.046 dB (diff=0.04595 dB) */
192 0x60, /* [082] -8.5 dB: AKM[096] = -8.485 dB (diff=0.01462 dB) */
193 0x66, /* [083] -8.0 dB: AKM[102] = -7.959 dB (diff=0.04120 dB) */
194 0x6c, /* [084] -7.5 dB: AKM[108] = -7.462 dB (diff=0.03767 dB) */
195 0x72, /* [085] -7.0 dB: AKM[114] = -6.993 dB (diff=0.00729 dB) */
196 0x79, /* [086] -6.5 dB: AKM[121] = -6.475 dB (diff=0.02490 dB) */
197 0x80, /* [087] -6.0 dB: AKM[128] = -5.987 dB (diff=0.01340 dB) */
198 0x87, /* [088] -5.5 dB: AKM[135] = -5.524 dB (diff=0.02413 dB) */
199 0x8f, /* [089] -5.0 dB: AKM[143] = -5.024 dB (diff=0.02408 dB) */
200 0x98, /* [090] -4.5 dB: AKM[152] = -4.494 dB (diff=0.00607 dB) */
201 0xa1, /* [091] -4.0 dB: AKM[161] = -3.994 dB (diff=0.00571 dB) */
202 0xaa, /* [092] -3.5 dB: AKM[170] = -3.522 dB (diff=0.02183 dB) */
203 0xb5, /* [093] -3.0 dB: AKM[181] = -2.977 dB (diff=0.02277 dB) */
204 0xbf, /* [094] -2.5 dB: AKM[191] = -2.510 dB (diff=0.01014 dB) */
205 0xcb, /* [095] -2.0 dB: AKM[203] = -1.981 dB (diff=0.01912 dB) */
206 0xd7, /* [096] -1.5 dB: AKM[215] = -1.482 dB (diff=0.01797 dB) */
207 0xe3, /* [097] -1.0 dB: AKM[227] = -1.010 dB (diff=0.01029 dB) */
208 0xf1, /* [098] -0.5 dB: AKM[241] = -0.490 dB (diff=0.00954 dB) */
209 0xff, /* [099] +0.0 dB: AKM[255] = +0.000 dB (diff=0.00000 dB) */
210};
211
212
213static void hr222_config_akm(struct pcxhr_mgr *mgr, unsigned short data)
214{
215 unsigned short mask = 0x8000;
216 /* activate access to codec registers */
217 PCXHR_INPB(mgr, PCXHR_XLX_HIFREQ);
218
219 while (mask) {
220 PCXHR_OUTPB(mgr, PCXHR_XLX_DATA,
221 data & mask ? PCXHR_DATA_CODEC : 0);
222 mask >>= 1;
223 }
224 /* termiate access to codec registers */
225 PCXHR_INPB(mgr, PCXHR_XLX_RUER);
226}
227
228
229static int hr222_set_hw_playback_level(struct pcxhr_mgr *mgr,
230 int idx, int level)
231{
232 unsigned short cmd;
233 if (idx > 1 ||
234 level < 0 ||
235 level >= ARRAY_SIZE(g_hr222_p_level))
236 return -EINVAL;
237
238 if (idx == 0)
239 cmd = AKM_LEFT_LEVEL_CMD;
240 else
241 cmd = AKM_RIGHT_LEVEL_CMD;
242
243 /* conversion from PmBoardCodedLevel to AKM nonlinear programming */
244 cmd += g_hr222_p_level[level];
245
246 hr222_config_akm(mgr, cmd);
247 return 0;
248}
249
250
251static int hr222_set_hw_capture_level(struct pcxhr_mgr *mgr,
252 int level_l, int level_r, int level_mic)
253{
254 /* program all input levels at the same time */
255 unsigned int data;
256 int i;
257
258 if (!mgr->capture_chips)
259 return -EINVAL; /* no PCX22 */
260
261 data = ((level_mic & 0xff) << 24); /* micro is mono, but apply */
262 data |= ((level_mic & 0xff) << 16); /* level on both channels */
263 data |= ((level_r & 0xff) << 8); /* line input right channel */
264 data |= (level_l & 0xff); /* line input left channel */
265
266 PCXHR_INPB(mgr, PCXHR_XLX_DATA); /* activate input codec */
267 /* send 32 bits (4 x 8 bits) */
268 for (i = 0; i < 32; i++, data <<= 1) {
269 PCXHR_OUTPB(mgr, PCXHR_XLX_DATA,
270 (data & 0x80000000) ? PCXHR_DATA_CODEC : 0);
271 }
272 PCXHR_INPB(mgr, PCXHR_XLX_RUER); /* close input level codec */
273 return 0;
274}
275
276static void hr222_micro_boost(struct pcxhr_mgr *mgr, int level);
277
278int hr222_sub_init(struct pcxhr_mgr *mgr)
279{
280 unsigned char reg;
281
282 mgr->board_has_analog = 1; /* analog always available */
283 mgr->xlx_cfg = PCXHR_CFG_SYNCDSP_MASK;
284
285 reg = PCXHR_INPB(mgr, PCXHR_XLX_STATUS);
286 if (reg & PCXHR_STAT_MIC_CAPS)
287 mgr->board_has_mic = 1; /* microphone available */
288 snd_printdd("MIC input available = %d\n", mgr->board_has_mic);
289
290 /* reset codec */
291 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET,
292 PCXHR_DSP_RESET_DSP);
293 msleep(5);
294 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET,
295 PCXHR_DSP_RESET_DSP |
296 PCXHR_DSP_RESET_MUTE |
297 PCXHR_DSP_RESET_CODEC);
298 msleep(5);
299
300 /* config AKM */
301 hr222_config_akm(mgr, AKM_POWER_CONTROL_CMD);
302 hr222_config_akm(mgr, AKM_CLOCK_INF_55K_CMD);
303 hr222_config_akm(mgr, AKM_UNMUTE_CMD);
304 hr222_config_akm(mgr, AKM_RESET_OFF_CMD);
305
306 /* init micro boost */
307 hr222_micro_boost(mgr, 0);
308
309 return 0;
310}
311
312
313/* calc PLL register */
314/* TODO : there is a very similar fct in pcxhr.c */
315static int hr222_pll_freq_register(unsigned int freq,
316 unsigned int *pllreg,
317 unsigned int *realfreq)
318{
319 unsigned int reg;
320
321 if (freq < 6900 || freq > 219000)
322 return -EINVAL;
323 reg = (28224000 * 2) / freq;
324 reg = (reg - 1) / 2;
325 if (reg < 0x100)
326 *pllreg = reg + 0xC00;
327 else if (reg < 0x200)
328 *pllreg = reg + 0x800;
329 else if (reg < 0x400)
330 *pllreg = reg & 0x1ff;
331 else if (reg < 0x800) {
332 *pllreg = ((reg >> 1) & 0x1ff) + 0x200;
333 reg &= ~1;
334 } else {
335 *pllreg = ((reg >> 2) & 0x1ff) + 0x400;
336 reg &= ~3;
337 }
338 if (realfreq)
339 *realfreq = (28224000 / (reg + 1));
340 return 0;
341}
342
343int hr222_sub_set_clock(struct pcxhr_mgr *mgr,
344 unsigned int rate,
345 int *changed)
346{
347 unsigned int speed, pllreg = 0;
348 int err;
349 unsigned realfreq = rate;
350
351 switch (mgr->use_clock_type) {
352 case HR22_CLOCK_TYPE_INTERNAL:
353 err = hr222_pll_freq_register(rate, &pllreg, &realfreq);
354 if (err)
355 return err;
356
357 mgr->xlx_cfg &= ~(PCXHR_CFG_CLOCKIN_SEL_MASK |
358 PCXHR_CFG_CLOCK_UER1_SEL_MASK);
359 break;
360 case HR22_CLOCK_TYPE_AES_SYNC:
361 mgr->xlx_cfg |= PCXHR_CFG_CLOCKIN_SEL_MASK;
362 mgr->xlx_cfg &= ~PCXHR_CFG_CLOCK_UER1_SEL_MASK;
363 break;
364 case HR22_CLOCK_TYPE_AES_1:
365 if (!mgr->board_has_aes1)
366 return -EINVAL;
367
368 mgr->xlx_cfg |= (PCXHR_CFG_CLOCKIN_SEL_MASK |
369 PCXHR_CFG_CLOCK_UER1_SEL_MASK);
370 break;
371 default:
372 return -EINVAL;
373 }
374 hr222_config_akm(mgr, AKM_MUTE_CMD);
375
376 if (mgr->use_clock_type == HR22_CLOCK_TYPE_INTERNAL) {
377 PCXHR_OUTPB(mgr, PCXHR_XLX_HIFREQ, pllreg >> 8);
378 PCXHR_OUTPB(mgr, PCXHR_XLX_LOFREQ, pllreg & 0xff);
379 }
380
381 /* set clock source */
382 PCXHR_OUTPB(mgr, PCXHR_XLX_CFG, mgr->xlx_cfg);
383
384 /* codec speed modes */
385 speed = rate < 55000 ? 0 : 1;
386 if (mgr->codec_speed != speed) {
387 mgr->codec_speed = speed;
388 if (speed == 0)
389 hr222_config_akm(mgr, AKM_CLOCK_INF_55K_CMD);
390 else
391 hr222_config_akm(mgr, AKM_CLOCK_SUP_55K_CMD);
392 }
393
394 mgr->sample_rate_real = realfreq;
395 mgr->cur_clock_type = mgr->use_clock_type;
396
397 if (changed)
398 *changed = 1;
399
400 hr222_config_akm(mgr, AKM_UNMUTE_CMD);
401
402 snd_printdd("set_clock to %dHz (realfreq=%d pllreg=%x)\n",
403 rate, realfreq, pllreg);
404 return 0;
405}
406
407int hr222_get_external_clock(struct pcxhr_mgr *mgr,
408 enum pcxhr_clock_type clock_type,
409 int *sample_rate)
410{
411 int rate, calc_rate = 0;
412 unsigned int ticks;
413 unsigned char mask, reg;
414
415 if (clock_type == HR22_CLOCK_TYPE_AES_SYNC) {
416
417 mask = (PCXHR_SUER_CLOCK_PRESENT_MASK |
418 PCXHR_SUER_DATA_PRESENT_MASK);
419 reg = PCXHR_STAT_FREQ_SYNC_MASK;
420
421 } else if (clock_type == HR22_CLOCK_TYPE_AES_1 && mgr->board_has_aes1) {
422
423 mask = (PCXHR_SUER1_CLOCK_PRESENT_MASK |
424 PCXHR_SUER1_DATA_PRESENT_MASK);
425 reg = PCXHR_STAT_FREQ_UER1_MASK;
426
427 } else {
428 snd_printdd("get_external_clock : type %d not supported\n",
429 clock_type);
430 return -EINVAL; /* other clocks not supported */
431 }
432
433 if ((PCXHR_INPB(mgr, PCXHR_XLX_CSUER) & mask) != mask) {
434 snd_printdd("get_external_clock(%d) = 0 Hz\n", clock_type);
435 *sample_rate = 0;
436 return 0; /* no external clock locked */
437 }
438
439 PCXHR_OUTPB(mgr, PCXHR_XLX_STATUS, reg); /* calculate freq */
440
441 /* save the measured clock frequency */
442 reg |= PCXHR_STAT_FREQ_SAVE_MASK;
443
444 if (mgr->last_reg_stat != reg) {
445 udelay(500); /* wait min 2 cycles of lowest freq (8000) */
446 mgr->last_reg_stat = reg;
447 }
448
449 PCXHR_OUTPB(mgr, PCXHR_XLX_STATUS, reg); /* save */
450
451 /* get the frequency */
452 ticks = (unsigned int)PCXHR_INPB(mgr, PCXHR_XLX_CFG);
453 ticks = (ticks & 0x03) << 8;
454 ticks |= (unsigned int)PCXHR_INPB(mgr, PCXHR_DSP_RESET);
455
456 if (ticks != 0)
457 calc_rate = 28224000 / ticks;
458 /* rounding */
459 if (calc_rate > 184200)
460 rate = 192000;
461 else if (calc_rate > 152200)
462 rate = 176400;
463 else if (calc_rate > 112000)
464 rate = 128000;
465 else if (calc_rate > 92100)
466 rate = 96000;
467 else if (calc_rate > 76100)
468 rate = 88200;
469 else if (calc_rate > 56000)
470 rate = 64000;
471 else if (calc_rate > 46050)
472 rate = 48000;
473 else if (calc_rate > 38050)
474 rate = 44100;
475 else if (calc_rate > 28000)
476 rate = 32000;
477 else if (calc_rate > 23025)
478 rate = 24000;
479 else if (calc_rate > 19025)
480 rate = 22050;
481 else if (calc_rate > 14000)
482 rate = 16000;
483 else if (calc_rate > 11512)
484 rate = 12000;
485 else if (calc_rate > 9512)
486 rate = 11025;
487 else if (calc_rate > 7000)
488 rate = 8000;
489 else
490 rate = 0;
491
492 snd_printdd("External clock is at %d Hz (measured %d Hz)\n",
493 rate, calc_rate);
494 *sample_rate = rate;
495 return 0;
496}
497
498
499int hr222_update_analog_audio_level(struct snd_pcxhr *chip,
500 int is_capture, int channel)
501{
502 snd_printdd("hr222_update_analog_audio_level(%s chan=%d)\n",
503 is_capture ? "capture" : "playback", channel);
504 if (is_capture) {
505 int level_l, level_r, level_mic;
506 /* we have to update all levels */
507 if (chip->analog_capture_active) {
508 level_l = chip->analog_capture_volume[0];
509 level_r = chip->analog_capture_volume[1];
510 } else {
511 level_l = HR222_LINE_CAPTURE_LEVEL_MIN;
512 level_r = HR222_LINE_CAPTURE_LEVEL_MIN;
513 }
514 if (chip->mic_active)
515 level_mic = chip->mic_volume;
516 else
517 level_mic = HR222_MICRO_CAPTURE_LEVEL_MIN;
518 return hr222_set_hw_capture_level(chip->mgr,
519 level_l, level_r, level_mic);
520 } else {
521 int vol;
522 if (chip->analog_playback_active[channel])
523 vol = chip->analog_playback_volume[channel];
524 else
525 vol = HR222_LINE_PLAYBACK_LEVEL_MIN;
526 return hr222_set_hw_playback_level(chip->mgr, channel, vol);
527 }
528}
529
530
531/*texts[5] = {"Line", "Digital", "Digi+SRC", "Mic", "Line+Mic"}*/
532#define SOURCE_LINE 0
533#define SOURCE_DIGITAL 1
534#define SOURCE_DIGISRC 2
535#define SOURCE_MIC 3
536#define SOURCE_LINEMIC 4
537
538int hr222_set_audio_source(struct snd_pcxhr *chip)
539{
540 int digital = 0;
541 /* default analog source */
542 chip->mgr->xlx_cfg &= ~(PCXHR_CFG_SRC_MASK |
543 PCXHR_CFG_DATAIN_SEL_MASK |
544 PCXHR_CFG_DATA_UER1_SEL_MASK);
545
546 if (chip->audio_capture_source == SOURCE_DIGISRC) {
547 chip->mgr->xlx_cfg |= PCXHR_CFG_SRC_MASK;
548 digital = 1;
549 } else {
550 if (chip->audio_capture_source == SOURCE_DIGITAL)
551 digital = 1;
552 }
553 if (digital) {
554 chip->mgr->xlx_cfg |= PCXHR_CFG_DATAIN_SEL_MASK;
555 if (chip->mgr->board_has_aes1) {
556 /* get data from the AES1 plug */
557 chip->mgr->xlx_cfg |= PCXHR_CFG_DATA_UER1_SEL_MASK;
558 }
559 /* chip->mic_active = 0; */
560 /* chip->analog_capture_active = 0; */
561 } else {
562 int update_lvl = 0;
563 chip->analog_capture_active = 0;
564 chip->mic_active = 0;
565 if (chip->audio_capture_source == SOURCE_LINE ||
566 chip->audio_capture_source == SOURCE_LINEMIC) {
567 if (chip->analog_capture_active == 0)
568 update_lvl = 1;
569 chip->analog_capture_active = 1;
570 }
571 if (chip->audio_capture_source == SOURCE_MIC ||
572 chip->audio_capture_source == SOURCE_LINEMIC) {
573 if (chip->mic_active == 0)
574 update_lvl = 1;
575 chip->mic_active = 1;
576 }
577 if (update_lvl) {
578 /* capture: update all 3 mutes/unmutes with one call */
579 hr222_update_analog_audio_level(chip, 1, 0);
580 }
581 }
582 /* set the source infos (max 3 bits modified) */
583 PCXHR_OUTPB(chip->mgr, PCXHR_XLX_CFG, chip->mgr->xlx_cfg);
584 return 0;
585}
586
587
588int hr222_iec958_capture_byte(struct snd_pcxhr *chip,
589 int aes_idx, unsigned char *aes_bits)
590{
591 unsigned char idx = (unsigned char)(aes_idx * 8);
592 unsigned char temp = 0;
593 unsigned char mask = chip->mgr->board_has_aes1 ?
594 PCXHR_SUER1_BIT_C_READ_MASK : PCXHR_SUER_BIT_C_READ_MASK;
595 int i;
596 for (i = 0; i < 8; i++) {
597 PCXHR_OUTPB(chip->mgr, PCXHR_XLX_RUER, idx++); /* idx < 192 */
598 temp <<= 1;
599 if (PCXHR_INPB(chip->mgr, PCXHR_XLX_CSUER) & mask)
600 temp |= 1;
601 }
602 snd_printdd("read iec958 AES %d byte %d = 0x%x\n",
603 chip->chip_idx, aes_idx, temp);
604 *aes_bits = temp;
605 return 0;
606}
607
608
609int hr222_iec958_update_byte(struct snd_pcxhr *chip,
610 int aes_idx, unsigned char aes_bits)
611{
612 int i;
613 unsigned char new_bits = aes_bits;
614 unsigned char old_bits = chip->aes_bits[aes_idx];
615 unsigned char idx = (unsigned char)(aes_idx * 8);
616 for (i = 0; i < 8; i++) {
617 if ((old_bits & 0x01) != (new_bits & 0x01)) {
618 /* idx < 192 */
619 PCXHR_OUTPB(chip->mgr, PCXHR_XLX_RUER, idx);
620 /* write C and U bit */
621 PCXHR_OUTPB(chip->mgr, PCXHR_XLX_CSUER, new_bits&0x01 ?
622 PCXHR_SUER_BIT_C_WRITE_MASK : 0);
623 }
624 idx++;
625 old_bits >>= 1;
626 new_bits >>= 1;
627 }
628 chip->aes_bits[aes_idx] = aes_bits;
629 return 0;
630}
631
632static void hr222_micro_boost(struct pcxhr_mgr *mgr, int level)
633{
634 unsigned char boost_mask;
635 boost_mask = (unsigned char) (level << PCXHR_SELMIC_PREAMPLI_OFFSET);
636 if (boost_mask & (~PCXHR_SELMIC_PREAMPLI_MASK))
637 return; /* only values form 0 to 3 accepted */
638
639 mgr->xlx_selmic &= ~PCXHR_SELMIC_PREAMPLI_MASK;
640 mgr->xlx_selmic |= boost_mask;
641
642 PCXHR_OUTPB(mgr, PCXHR_XLX_SELMIC, mgr->xlx_selmic);
643
644 snd_printdd("hr222_micro_boost : set %x\n", boost_mask);
645}
646
647static void hr222_phantom_power(struct pcxhr_mgr *mgr, int power)
648{
649 if (power)
650 mgr->xlx_selmic |= PCXHR_SELMIC_PHANTOM_ALIM;
651 else
652 mgr->xlx_selmic &= ~PCXHR_SELMIC_PHANTOM_ALIM;
653
654 PCXHR_OUTPB(mgr, PCXHR_XLX_SELMIC, mgr->xlx_selmic);
655
656 snd_printdd("hr222_phantom_power : set %d\n", power);
657}
658
659
660/* mic level */
661static const DECLARE_TLV_DB_SCALE(db_scale_mic_hr222, -9850, 50, 650);
662
663static int hr222_mic_vol_info(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_info *uinfo)
665{
666 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
667 uinfo->count = 1;
668 uinfo->value.integer.min = HR222_MICRO_CAPTURE_LEVEL_MIN; /* -98 dB */
669 /* gains from 9 dB to 31.5 dB not recommended; use micboost instead */
670 uinfo->value.integer.max = HR222_MICRO_CAPTURE_LEVEL_MAX; /* +7 dB */
671 return 0;
672}
673
674static int hr222_mic_vol_get(struct snd_kcontrol *kcontrol,
675 struct snd_ctl_elem_value *ucontrol)
676{
677 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
678 mutex_lock(&chip->mgr->mixer_mutex);
679 ucontrol->value.integer.value[0] = chip->mic_volume;
680 mutex_unlock(&chip->mgr->mixer_mutex);
681 return 0;
682}
683
684static int hr222_mic_vol_put(struct snd_kcontrol *kcontrol,
685 struct snd_ctl_elem_value *ucontrol)
686{
687 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
688 int changed = 0;
689 mutex_lock(&chip->mgr->mixer_mutex);
690 if (chip->mic_volume != ucontrol->value.integer.value[0]) {
691 changed = 1;
692 chip->mic_volume = ucontrol->value.integer.value[0];
693 hr222_update_analog_audio_level(chip, 1, 0);
694 }
695 mutex_unlock(&chip->mgr->mixer_mutex);
696 return changed;
697}
698
699static struct snd_kcontrol_new hr222_control_mic_level = {
700 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
701 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
702 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
703 .name = "Mic Capture Volume",
704 .info = hr222_mic_vol_info,
705 .get = hr222_mic_vol_get,
706 .put = hr222_mic_vol_put,
707 .tlv = { .p = db_scale_mic_hr222 },
708};
709
710
711/* mic boost level */
712static const DECLARE_TLV_DB_SCALE(db_scale_micboost_hr222, 0, 1800, 5400);
713
714static int hr222_mic_boost_info(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_info *uinfo)
716{
717 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
718 uinfo->count = 1;
719 uinfo->value.integer.min = 0; /* 0 dB */
720 uinfo->value.integer.max = 3; /* 54 dB */
721 return 0;
722}
723
724static int hr222_mic_boost_get(struct snd_kcontrol *kcontrol,
725 struct snd_ctl_elem_value *ucontrol)
726{
727 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
728 mutex_lock(&chip->mgr->mixer_mutex);
729 ucontrol->value.integer.value[0] = chip->mic_boost;
730 mutex_unlock(&chip->mgr->mixer_mutex);
731 return 0;
732}
733
734static int hr222_mic_boost_put(struct snd_kcontrol *kcontrol,
735 struct snd_ctl_elem_value *ucontrol)
736{
737 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
738 int changed = 0;
739 mutex_lock(&chip->mgr->mixer_mutex);
740 if (chip->mic_boost != ucontrol->value.integer.value[0]) {
741 changed = 1;
742 chip->mic_boost = ucontrol->value.integer.value[0];
743 hr222_micro_boost(chip->mgr, chip->mic_boost);
744 }
745 mutex_unlock(&chip->mgr->mixer_mutex);
746 return changed;
747}
748
749static struct snd_kcontrol_new hr222_control_mic_boost = {
750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
751 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
752 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
753 .name = "MicBoost Capture Volume",
754 .info = hr222_mic_boost_info,
755 .get = hr222_mic_boost_get,
756 .put = hr222_mic_boost_put,
757 .tlv = { .p = db_scale_micboost_hr222 },
758};
759
760
761/******************* Phantom power switch *******************/
762#define hr222_phantom_power_info snd_ctl_boolean_mono_info
763
764static int hr222_phantom_power_get(struct snd_kcontrol *kcontrol,
765 struct snd_ctl_elem_value *ucontrol)
766{
767 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
768 mutex_lock(&chip->mgr->mixer_mutex);
769 ucontrol->value.integer.value[0] = chip->phantom_power;
770 mutex_unlock(&chip->mgr->mixer_mutex);
771 return 0;
772}
773
774static int hr222_phantom_power_put(struct snd_kcontrol *kcontrol,
775 struct snd_ctl_elem_value *ucontrol)
776{
777 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
778 int power, changed = 0;
779
780 mutex_lock(&chip->mgr->mixer_mutex);
781 power = !!ucontrol->value.integer.value[0];
782 if (chip->phantom_power != power) {
783 hr222_phantom_power(chip->mgr, power);
784 chip->phantom_power = power;
785 changed = 1;
786 }
787 mutex_unlock(&chip->mgr->mixer_mutex);
788 return changed;
789}
790
791static struct snd_kcontrol_new hr222_phantom_power_switch = {
792 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
793 .name = "Phantom Power Switch",
794 .info = hr222_phantom_power_info,
795 .get = hr222_phantom_power_get,
796 .put = hr222_phantom_power_put,
797};
798
799
800int hr222_add_mic_controls(struct snd_pcxhr *chip)
801{
802 int err;
803 if (!chip->mgr->board_has_mic)
804 return 0;
805
806 /* controls */
807 err = snd_ctl_add(chip->card, snd_ctl_new1(&hr222_control_mic_level,
808 chip));
809 if (err < 0)
810 return err;
811
812 err = snd_ctl_add(chip->card, snd_ctl_new1(&hr222_control_mic_boost,
813 chip));
814 if (err < 0)
815 return err;
816
817 err = snd_ctl_add(chip->card, snd_ctl_new1(&hr222_phantom_power_switch,
818 chip));
819 return err;
820}
diff --git a/sound/pci/pcxhr/pcxhr_mix22.h b/sound/pci/pcxhr/pcxhr_mix22.h
new file mode 100644
index 000000000000..6b318b2f0100
--- /dev/null
+++ b/sound/pci/pcxhr/pcxhr_mix22.h
@@ -0,0 +1,56 @@
1/*
2 * Driver for Digigram pcxhr compatible soundcards
3 *
4 * low level interface with interrupt ans message handling
5 *
6 * Copyright (c) 2004 by Digigram <alsa@digigram.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 as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __SOUND_PCXHR_MIX22_H
24#define __SOUND_PCXHR_MIX22_H
25
26struct pcxhr_mgr;
27
28int hr222_sub_init(struct pcxhr_mgr *mgr);
29int hr222_sub_set_clock(struct pcxhr_mgr *mgr, unsigned int rate,
30 int *changed);
31int hr222_get_external_clock(struct pcxhr_mgr *mgr,
32 enum pcxhr_clock_type clock_type,
33 int *sample_rate);
34
35#define HR222_LINE_PLAYBACK_LEVEL_MIN 0 /* -25.5 dB */
36#define HR222_LINE_PLAYBACK_ZERO_LEVEL 51 /* 0.0 dB */
37#define HR222_LINE_PLAYBACK_LEVEL_MAX 99 /* +24.0 dB */
38
39#define HR222_LINE_CAPTURE_LEVEL_MIN 0 /* -111.5 dB */
40#define HR222_LINE_CAPTURE_ZERO_LEVEL 223 /* 0.0 dB */
41#define HR222_LINE_CAPTURE_LEVEL_MAX 255 /* +16 dB */
42#define HR222_MICRO_CAPTURE_LEVEL_MIN 0 /* -98.5 dB */
43#define HR222_MICRO_CAPTURE_LEVEL_MAX 210 /* +6.5 dB */
44
45int hr222_update_analog_audio_level(struct snd_pcxhr *chip,
46 int is_capture,
47 int channel);
48int hr222_set_audio_source(struct snd_pcxhr *chip);
49int hr222_iec958_capture_byte(struct snd_pcxhr *chip, int aes_idx,
50 unsigned char *aes_bits);
51int hr222_iec958_update_byte(struct snd_pcxhr *chip, int aes_idx,
52 unsigned char aes_bits);
53
54int hr222_add_mic_controls(struct snd_pcxhr *chip);
55
56#endif /* __SOUND_PCXHR_MIX22_H */
diff --git a/sound/pci/pcxhr/pcxhr_mixer.c b/sound/pci/pcxhr/pcxhr_mixer.c
index aabc7bc5321e..2436e374586f 100644
--- a/sound/pci/pcxhr/pcxhr_mixer.c
+++ b/sound/pci/pcxhr/pcxhr_mixer.c
@@ -33,20 +33,24 @@
33#include <sound/tlv.h> 33#include <sound/tlv.h>
34#include <sound/asoundef.h> 34#include <sound/asoundef.h>
35#include "pcxhr_mixer.h" 35#include "pcxhr_mixer.h"
36#include "pcxhr_mix22.h"
36 37
38#define PCXHR_LINE_CAPTURE_LEVEL_MIN 0 /* -112.0 dB */
39#define PCXHR_LINE_CAPTURE_LEVEL_MAX 255 /* +15.5 dB */
40#define PCXHR_LINE_CAPTURE_ZERO_LEVEL 224 /* 0.0 dB ( 0 dBu -> 0 dBFS ) */
37 41
38#define PCXHR_ANALOG_CAPTURE_LEVEL_MIN 0 /* -96.0 dB */ 42#define PCXHR_LINE_PLAYBACK_LEVEL_MIN 0 /* -104.0 dB */
39#define PCXHR_ANALOG_CAPTURE_LEVEL_MAX 255 /* +31.5 dB */ 43#define PCXHR_LINE_PLAYBACK_LEVEL_MAX 128 /* +24.0 dB */
40#define PCXHR_ANALOG_CAPTURE_ZERO_LEVEL 224 /* +16.0 dB ( +31.5 dB - fix level +15.5 dB ) */ 44#define PCXHR_LINE_PLAYBACK_ZERO_LEVEL 104 /* 0.0 dB ( 0 dBFS -> 0 dBu ) */
41 45
42#define PCXHR_ANALOG_PLAYBACK_LEVEL_MIN 0 /* -128.0 dB */ 46static const DECLARE_TLV_DB_SCALE(db_scale_analog_capture, -11200, 50, 1550);
43#define PCXHR_ANALOG_PLAYBACK_LEVEL_MAX 128 /* 0.0 dB */
44#define PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL 104 /* -24.0 dB ( 0.0 dB - fix level +24.0 dB ) */
45
46static const DECLARE_TLV_DB_SCALE(db_scale_analog_capture, -9600, 50, 3150);
47static const DECLARE_TLV_DB_SCALE(db_scale_analog_playback, -10400, 100, 2400); 47static const DECLARE_TLV_DB_SCALE(db_scale_analog_playback, -10400, 100, 2400);
48 48
49static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip, int is_capture, int channel) 49static const DECLARE_TLV_DB_SCALE(db_scale_a_hr222_capture, -11150, 50, 1600);
50static const DECLARE_TLV_DB_SCALE(db_scale_a_hr222_playback, -2550, 50, 2400);
51
52static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip,
53 int is_capture, int channel)
50{ 54{
51 int err, vol; 55 int err, vol;
52 struct pcxhr_rmh rmh; 56 struct pcxhr_rmh rmh;
@@ -60,15 +64,17 @@ static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip, int is_captur
60 if (chip->analog_playback_active[channel]) 64 if (chip->analog_playback_active[channel])
61 vol = chip->analog_playback_volume[channel]; 65 vol = chip->analog_playback_volume[channel];
62 else 66 else
63 vol = PCXHR_ANALOG_PLAYBACK_LEVEL_MIN; 67 vol = PCXHR_LINE_PLAYBACK_LEVEL_MIN;
64 rmh.cmd[2] = PCXHR_ANALOG_PLAYBACK_LEVEL_MAX - vol; /* playback analog levels are inversed */ 68 /* playback analog levels are inversed */
69 rmh.cmd[2] = PCXHR_LINE_PLAYBACK_LEVEL_MAX - vol;
65 } 70 }
66 rmh.cmd[1] = 1 << ((2 * chip->chip_idx) + channel); /* audio mask */ 71 rmh.cmd[1] = 1 << ((2 * chip->chip_idx) + channel); /* audio mask */
67 rmh.cmd_len = 3; 72 rmh.cmd_len = 3;
68 err = pcxhr_send_msg(chip->mgr, &rmh); 73 err = pcxhr_send_msg(chip->mgr, &rmh);
69 if (err < 0) { 74 if (err < 0) {
70 snd_printk(KERN_DEBUG "error update_analog_audio_level card(%d) " 75 snd_printk(KERN_DEBUG "error update_analog_audio_level card(%d)"
71 "is_capture(%d) err(%x)\n", chip->chip_idx, is_capture, err); 76 " is_capture(%d) err(%x)\n",
77 chip->chip_idx, is_capture, err);
72 return -EINVAL; 78 return -EINVAL;
73 } 79 }
74 return 0; 80 return 0;
@@ -80,14 +86,34 @@ static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip, int is_captur
80static int pcxhr_analog_vol_info(struct snd_kcontrol *kcontrol, 86static int pcxhr_analog_vol_info(struct snd_kcontrol *kcontrol,
81 struct snd_ctl_elem_info *uinfo) 87 struct snd_ctl_elem_info *uinfo)
82{ 88{
89 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
90
83 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 91 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
84 uinfo->count = 2; 92 uinfo->count = 2;
85 if (kcontrol->private_value == 0) { /* playback */ 93 if (kcontrol->private_value == 0) { /* playback */
86 uinfo->value.integer.min = PCXHR_ANALOG_PLAYBACK_LEVEL_MIN; /* -128 dB */ 94 if (chip->mgr->is_hr_stereo) {
87 uinfo->value.integer.max = PCXHR_ANALOG_PLAYBACK_LEVEL_MAX; /* 0 dB */ 95 uinfo->value.integer.min =
96 HR222_LINE_PLAYBACK_LEVEL_MIN; /* -25 dB */
97 uinfo->value.integer.max =
98 HR222_LINE_PLAYBACK_LEVEL_MAX; /* +24 dB */
99 } else {
100 uinfo->value.integer.min =
101 PCXHR_LINE_PLAYBACK_LEVEL_MIN; /*-104 dB */
102 uinfo->value.integer.max =
103 PCXHR_LINE_PLAYBACK_LEVEL_MAX; /* +24 dB */
104 }
88 } else { /* capture */ 105 } else { /* capture */
89 uinfo->value.integer.min = PCXHR_ANALOG_CAPTURE_LEVEL_MIN; /* -96 dB */ 106 if (chip->mgr->is_hr_stereo) {
90 uinfo->value.integer.max = PCXHR_ANALOG_CAPTURE_LEVEL_MAX; /* 31.5 dB */ 107 uinfo->value.integer.min =
108 HR222_LINE_CAPTURE_LEVEL_MIN; /*-112 dB */
109 uinfo->value.integer.max =
110 HR222_LINE_CAPTURE_LEVEL_MAX; /* +15.5 dB */
111 } else {
112 uinfo->value.integer.min =
113 PCXHR_LINE_CAPTURE_LEVEL_MIN; /*-112 dB */
114 uinfo->value.integer.max =
115 PCXHR_LINE_CAPTURE_LEVEL_MAX; /* +15.5 dB */
116 }
91 } 117 }
92 return 0; 118 return 0;
93} 119}
@@ -98,11 +124,11 @@ static int pcxhr_analog_vol_get(struct snd_kcontrol *kcontrol,
98 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 124 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
99 mutex_lock(&chip->mgr->mixer_mutex); 125 mutex_lock(&chip->mgr->mixer_mutex);
100 if (kcontrol->private_value == 0) { /* playback */ 126 if (kcontrol->private_value == 0) { /* playback */
101 ucontrol->value.integer.value[0] = chip->analog_playback_volume[0]; 127 ucontrol->value.integer.value[0] = chip->analog_playback_volume[0];
102 ucontrol->value.integer.value[1] = chip->analog_playback_volume[1]; 128 ucontrol->value.integer.value[1] = chip->analog_playback_volume[1];
103 } else { /* capture */ 129 } else { /* capture */
104 ucontrol->value.integer.value[0] = chip->analog_capture_volume[0]; 130 ucontrol->value.integer.value[0] = chip->analog_capture_volume[0];
105 ucontrol->value.integer.value[1] = chip->analog_capture_volume[1]; 131 ucontrol->value.integer.value[1] = chip->analog_capture_volume[1];
106 } 132 }
107 mutex_unlock(&chip->mgr->mixer_mutex); 133 mutex_unlock(&chip->mgr->mixer_mutex);
108 return 0; 134 return 0;
@@ -123,18 +149,35 @@ static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol,
123 &chip->analog_capture_volume[i] : 149 &chip->analog_capture_volume[i] :
124 &chip->analog_playback_volume[i]; 150 &chip->analog_playback_volume[i];
125 if (is_capture) { 151 if (is_capture) {
126 if (new_volume < PCXHR_ANALOG_CAPTURE_LEVEL_MIN || 152 if (chip->mgr->is_hr_stereo) {
127 new_volume > PCXHR_ANALOG_CAPTURE_LEVEL_MAX) 153 if (new_volume < HR222_LINE_CAPTURE_LEVEL_MIN ||
128 continue; 154 new_volume > HR222_LINE_CAPTURE_LEVEL_MAX)
155 continue;
156 } else {
157 if (new_volume < PCXHR_LINE_CAPTURE_LEVEL_MIN ||
158 new_volume > PCXHR_LINE_CAPTURE_LEVEL_MAX)
159 continue;
160 }
129 } else { 161 } else {
130 if (new_volume < PCXHR_ANALOG_PLAYBACK_LEVEL_MIN || 162 if (chip->mgr->is_hr_stereo) {
131 new_volume > PCXHR_ANALOG_PLAYBACK_LEVEL_MAX) 163 if (new_volume < HR222_LINE_PLAYBACK_LEVEL_MIN ||
132 continue; 164 new_volume > HR222_LINE_PLAYBACK_LEVEL_MAX)
165 continue;
166 } else {
167 if (new_volume < PCXHR_LINE_PLAYBACK_LEVEL_MIN ||
168 new_volume > PCXHR_LINE_PLAYBACK_LEVEL_MAX)
169 continue;
170 }
133 } 171 }
134 if (*stored_volume != new_volume) { 172 if (*stored_volume != new_volume) {
135 *stored_volume = new_volume; 173 *stored_volume = new_volume;
136 changed = 1; 174 changed = 1;
137 pcxhr_update_analog_audio_level(chip, is_capture, i); 175 if (chip->mgr->is_hr_stereo)
176 hr222_update_analog_audio_level(chip,
177 is_capture, i);
178 else
179 pcxhr_update_analog_audio_level(chip,
180 is_capture, i);
138 } 181 }
139 } 182 }
140 mutex_unlock(&chip->mgr->mixer_mutex); 183 mutex_unlock(&chip->mgr->mixer_mutex);
@@ -153,6 +196,7 @@ static struct snd_kcontrol_new pcxhr_control_analog_level = {
153}; 196};
154 197
155/* shared */ 198/* shared */
199
156#define pcxhr_sw_info snd_ctl_boolean_stereo_info 200#define pcxhr_sw_info snd_ctl_boolean_stereo_info
157 201
158static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol, 202static int pcxhr_audio_sw_get(struct snd_kcontrol *kcontrol,
@@ -180,7 +224,10 @@ static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol,
180 !!ucontrol->value.integer.value[i]; 224 !!ucontrol->value.integer.value[i];
181 changed = 1; 225 changed = 1;
182 /* update playback levels */ 226 /* update playback levels */
183 pcxhr_update_analog_audio_level(chip, 0, i); 227 if (chip->mgr->is_hr_stereo)
228 hr222_update_analog_audio_level(chip, 0, i);
229 else
230 pcxhr_update_analog_audio_level(chip, 0, i);
184 } 231 }
185 } 232 }
186 mutex_unlock(&chip->mgr->mixer_mutex); 233 mutex_unlock(&chip->mgr->mixer_mutex);
@@ -251,7 +298,8 @@ static int pcxhr_update_playback_stream_level(struct snd_pcxhr* chip, int idx)
251#define VALID_AUDIO_IO_MUTE_LEVEL 0x000004 298#define VALID_AUDIO_IO_MUTE_LEVEL 0x000004
252#define VALID_AUDIO_IO_MUTE_MONITOR_1 0x000008 299#define VALID_AUDIO_IO_MUTE_MONITOR_1 0x000008
253 300
254static int pcxhr_update_audio_pipe_level(struct snd_pcxhr* chip, int capture, int channel) 301static int pcxhr_update_audio_pipe_level(struct snd_pcxhr *chip,
302 int capture, int channel)
255{ 303{
256 int err; 304 int err;
257 struct pcxhr_rmh rmh; 305 struct pcxhr_rmh rmh;
@@ -264,18 +312,20 @@ static int pcxhr_update_audio_pipe_level(struct snd_pcxhr* chip, int capture, in
264 312
265 pcxhr_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST); 313 pcxhr_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST);
266 /* add channel mask */ 314 /* add channel mask */
267 pcxhr_set_pipe_cmd_params(&rmh, capture, 0, 0, 1 << (channel + pipe->first_audio)); 315 pcxhr_set_pipe_cmd_params(&rmh, capture, 0, 0,
268 /* TODO : if mask (3 << pipe->first_audio) is used, left and right channel 316 1 << (channel + pipe->first_audio));
269 * will be programmed to the same params 317 /* TODO : if mask (3 << pipe->first_audio) is used, left and right
270 */ 318 * channel will be programmed to the same params */
271 if (capture) { 319 if (capture) {
272 rmh.cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL; 320 rmh.cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL;
273 /* VALID_AUDIO_IO_MUTE_LEVEL not yet handled (capture pipe level) */ 321 /* VALID_AUDIO_IO_MUTE_LEVEL not yet handled
322 * (capture pipe level) */
274 rmh.cmd[2] = chip->digital_capture_volume[channel]; 323 rmh.cmd[2] = chip->digital_capture_volume[channel];
275 } else { 324 } else {
276 rmh.cmd[0] |= VALID_AUDIO_IO_MONITOR_LEVEL | VALID_AUDIO_IO_MUTE_MONITOR_1; 325 rmh.cmd[0] |= VALID_AUDIO_IO_MONITOR_LEVEL |
277 /* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL not yet 326 VALID_AUDIO_IO_MUTE_MONITOR_1;
278 * handled (playback pipe level) 327 /* VALID_AUDIO_IO_DIGITAL_LEVEL and VALID_AUDIO_IO_MUTE_LEVEL
328 * not yet handled (playback pipe level)
279 */ 329 */
280 rmh.cmd[2] = chip->monitoring_volume[channel] << 10; 330 rmh.cmd[2] = chip->monitoring_volume[channel] << 10;
281 if (chip->monitoring_active[channel] == 0) 331 if (chip->monitoring_active[channel] == 0)
@@ -284,8 +334,8 @@ static int pcxhr_update_audio_pipe_level(struct snd_pcxhr* chip, int capture, in
284 rmh.cmd_len = 3; 334 rmh.cmd_len = 3;
285 335
286 err = pcxhr_send_msg(chip->mgr, &rmh); 336 err = pcxhr_send_msg(chip->mgr, &rmh);
287 if(err<0) { 337 if (err < 0) {
288 snd_printk(KERN_DEBUG "error update_audio_level card(%d) err(%x)\n", 338 snd_printk(KERN_DEBUG "error update_audio_level(%d) err=%x\n",
289 chip->chip_idx, err); 339 chip->chip_idx, err);
290 return -EINVAL; 340 return -EINVAL;
291 } 341 }
@@ -309,15 +359,15 @@ static int pcxhr_pcm_vol_get(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_value *ucontrol) 359 struct snd_ctl_elem_value *ucontrol)
310{ 360{
311 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 361 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
312 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ 362 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
313 int *stored_volume; 363 int *stored_volume;
314 int is_capture = kcontrol->private_value; 364 int is_capture = kcontrol->private_value;
315 365
316 mutex_lock(&chip->mgr->mixer_mutex); 366 mutex_lock(&chip->mgr->mixer_mutex);
317 if (is_capture) 367 if (is_capture) /* digital capture */
318 stored_volume = chip->digital_capture_volume; /* digital capture */ 368 stored_volume = chip->digital_capture_volume;
319 else 369 else /* digital playback */
320 stored_volume = chip->digital_playback_volume[idx]; /* digital playback */ 370 stored_volume = chip->digital_playback_volume[idx];
321 ucontrol->value.integer.value[0] = stored_volume[0]; 371 ucontrol->value.integer.value[0] = stored_volume[0];
322 ucontrol->value.integer.value[1] = stored_volume[1]; 372 ucontrol->value.integer.value[1] = stored_volume[1];
323 mutex_unlock(&chip->mgr->mixer_mutex); 373 mutex_unlock(&chip->mgr->mixer_mutex);
@@ -328,7 +378,7 @@ static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol,
328 struct snd_ctl_elem_value *ucontrol) 378 struct snd_ctl_elem_value *ucontrol)
329{ 379{
330 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 380 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
331 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ 381 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
332 int changed = 0; 382 int changed = 0;
333 int is_capture = kcontrol->private_value; 383 int is_capture = kcontrol->private_value;
334 int *stored_volume; 384 int *stored_volume;
@@ -384,7 +434,8 @@ static int pcxhr_pcm_sw_get(struct snd_kcontrol *kcontrol,
384 return 0; 434 return 0;
385} 435}
386 436
387static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 437static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol,
438 struct snd_ctl_elem_value *ucontrol)
388{ 439{
389 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 440 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
390 int changed = 0; 441 int changed = 0;
@@ -444,8 +495,8 @@ static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol,
444 if (chip->monitoring_volume[i] != 495 if (chip->monitoring_volume[i] !=
445 ucontrol->value.integer.value[i]) { 496 ucontrol->value.integer.value[i]) {
446 chip->monitoring_volume[i] = 497 chip->monitoring_volume[i] =
447 !!ucontrol->value.integer.value[i]; 498 ucontrol->value.integer.value[i];
448 if(chip->monitoring_active[i]) 499 if (chip->monitoring_active[i])
449 /* update monitoring volume and mute */ 500 /* update monitoring volume and mute */
450 /* do only when monitoring is unmuted */ 501 /* do only when monitoring is unmuted */
451 pcxhr_update_audio_pipe_level(chip, 0, i); 502 pcxhr_update_audio_pipe_level(chip, 0, i);
@@ -460,7 +511,7 @@ static struct snd_kcontrol_new pcxhr_control_monitor_vol = {
460 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
461 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 512 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
462 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 513 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
463 .name = "Monitoring Volume", 514 .name = "Monitoring Playback Volume",
464 .info = pcxhr_digital_vol_info, /* shared */ 515 .info = pcxhr_digital_vol_info, /* shared */
465 .get = pcxhr_monitor_vol_get, 516 .get = pcxhr_monitor_vol_get,
466 .put = pcxhr_monitor_vol_put, 517 .put = pcxhr_monitor_vol_put,
@@ -511,7 +562,7 @@ static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol,
511 562
512static struct snd_kcontrol_new pcxhr_control_monitor_sw = { 563static struct snd_kcontrol_new pcxhr_control_monitor_sw = {
513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
514 .name = "Monitoring Switch", 565 .name = "Monitoring Playback Switch",
515 .info = pcxhr_sw_info, /* shared */ 566 .info = pcxhr_sw_info, /* shared */
516 .get = pcxhr_monitor_sw_get, 567 .get = pcxhr_monitor_sw_get,
517 .put = pcxhr_monitor_sw_put 568 .put = pcxhr_monitor_sw_put
@@ -533,7 +584,7 @@ static int pcxhr_set_audio_source(struct snd_pcxhr* chip)
533 struct pcxhr_rmh rmh; 584 struct pcxhr_rmh rmh;
534 unsigned int mask, reg; 585 unsigned int mask, reg;
535 unsigned int codec; 586 unsigned int codec;
536 int err, use_src, changed; 587 int err, changed;
537 588
538 switch (chip->chip_idx) { 589 switch (chip->chip_idx) {
539 case 0 : mask = PCXHR_SOURCE_AUDIO01_UER; codec = CS8420_01_CS; break; 590 case 0 : mask = PCXHR_SOURCE_AUDIO01_UER; codec = CS8420_01_CS; break;
@@ -542,13 +593,10 @@ static int pcxhr_set_audio_source(struct snd_pcxhr* chip)
542 case 3 : mask = PCXHR_SOURCE_AUDIO67_UER; codec = CS8420_67_CS; break; 593 case 3 : mask = PCXHR_SOURCE_AUDIO67_UER; codec = CS8420_67_CS; break;
543 default: return -EINVAL; 594 default: return -EINVAL;
544 } 595 }
545 reg = 0; /* audio source from analog plug */
546 use_src = 0; /* do not activate codec SRC */
547
548 if (chip->audio_capture_source != 0) { 596 if (chip->audio_capture_source != 0) {
549 reg = mask; /* audio source from digital plug */ 597 reg = mask; /* audio source from digital plug */
550 if (chip->audio_capture_source == 2) 598 } else {
551 use_src = 1; 599 reg = 0; /* audio source from analog plug */
552 } 600 }
553 /* set the input source */ 601 /* set the input source */
554 pcxhr_write_io_num_reg_cont(chip->mgr, mask, reg, &changed); 602 pcxhr_write_io_num_reg_cont(chip->mgr, mask, reg, &changed);
@@ -560,29 +608,61 @@ static int pcxhr_set_audio_source(struct snd_pcxhr* chip)
560 if (err) 608 if (err)
561 return err; 609 return err;
562 } 610 }
563 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); /* set codec SRC on off */ 611 if (chip->mgr->board_aes_in_192k) {
564 rmh.cmd_len = 3; 612 int i;
565 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG; 613 unsigned int src_config = 0xC0;
566 rmh.cmd[1] = codec; 614 /* update all src configs with one call */
567 rmh.cmd[2] = (CS8420_DATA_FLOW_CTL & CHIP_SIG_AND_MAP_SPI) | (use_src ? 0x41 : 0x54); 615 for (i = 0; (i < 4) && (i < chip->mgr->capture_chips); i++) {
568 err = pcxhr_send_msg(chip->mgr, &rmh); 616 if (chip->mgr->chip[i]->audio_capture_source == 2)
569 if(err) 617 src_config |= (1 << (3 - i));
570 return err; 618 }
571 rmh.cmd[2] = (CS8420_CLOCK_SRC_CTL & CHIP_SIG_AND_MAP_SPI) | (use_src ? 0x41 : 0x49); 619 /* set codec SRC on off */
572 err = pcxhr_send_msg(chip->mgr, &rmh); 620 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
621 rmh.cmd_len = 2;
622 rmh.cmd[0] |= IO_NUM_REG_CONFIG_SRC;
623 rmh.cmd[1] = src_config;
624 err = pcxhr_send_msg(chip->mgr, &rmh);
625 } else {
626 int use_src = 0;
627 if (chip->audio_capture_source == 2)
628 use_src = 1;
629 /* set codec SRC on off */
630 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
631 rmh.cmd_len = 3;
632 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
633 rmh.cmd[1] = codec;
634 rmh.cmd[2] = ((CS8420_DATA_FLOW_CTL & CHIP_SIG_AND_MAP_SPI) |
635 (use_src ? 0x41 : 0x54));
636 err = pcxhr_send_msg(chip->mgr, &rmh);
637 if (err)
638 return err;
639 rmh.cmd[2] = ((CS8420_CLOCK_SRC_CTL & CHIP_SIG_AND_MAP_SPI) |
640 (use_src ? 0x41 : 0x49));
641 err = pcxhr_send_msg(chip->mgr, &rmh);
642 }
573 return err; 643 return err;
574} 644}
575 645
576static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol, 646static int pcxhr_audio_src_info(struct snd_kcontrol *kcontrol,
577 struct snd_ctl_elem_info *uinfo) 647 struct snd_ctl_elem_info *uinfo)
578{ 648{
579 static char *texts[3] = {"Analog", "Digital", "Digi+SRC"}; 649 static const char *texts[5] = {
650 "Line", "Digital", "Digi+SRC", "Mic", "Line+Mic"
651 };
652 int i;
653 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
580 654
655 i = 2; /* no SRC, no Mic available */
656 if (chip->mgr->board_has_aes1) {
657 i = 3; /* SRC available */
658 if (chip->mgr->board_has_mic)
659 i = 5; /* Mic and MicroMix available */
660 }
581 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 661 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
582 uinfo->count = 1; 662 uinfo->count = 1;
583 uinfo->value.enumerated.items = 3; 663 uinfo->value.enumerated.items = i;
584 if (uinfo->value.enumerated.item > 2) 664 if (uinfo->value.enumerated.item > (i-1))
585 uinfo->value.enumerated.item = 2; 665 uinfo->value.enumerated.item = i-1;
586 strcpy(uinfo->value.enumerated.name, 666 strcpy(uinfo->value.enumerated.name,
587 texts[uinfo->value.enumerated.item]); 667 texts[uinfo->value.enumerated.item]);
588 return 0; 668 return 0;
@@ -601,13 +681,21 @@ static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol,
601{ 681{
602 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 682 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
603 int ret = 0; 683 int ret = 0;
604 684 int i = 2; /* no SRC, no Mic available */
605 if (ucontrol->value.enumerated.item[0] >= 3) 685 if (chip->mgr->board_has_aes1) {
686 i = 3; /* SRC available */
687 if (chip->mgr->board_has_mic)
688 i = 5; /* Mic and MicroMix available */
689 }
690 if (ucontrol->value.enumerated.item[0] >= i)
606 return -EINVAL; 691 return -EINVAL;
607 mutex_lock(&chip->mgr->mixer_mutex); 692 mutex_lock(&chip->mgr->mixer_mutex);
608 if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) { 693 if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) {
609 chip->audio_capture_source = ucontrol->value.enumerated.item[0]; 694 chip->audio_capture_source = ucontrol->value.enumerated.item[0];
610 pcxhr_set_audio_source(chip); 695 if (chip->mgr->is_hr_stereo)
696 hr222_set_audio_source(chip);
697 else
698 pcxhr_set_audio_source(chip);
611 ret = 1; 699 ret = 1;
612 } 700 }
613 mutex_unlock(&chip->mgr->mixer_mutex); 701 mutex_unlock(&chip->mgr->mixer_mutex);
@@ -626,25 +714,46 @@ static struct snd_kcontrol_new pcxhr_control_audio_src = {
626/* 714/*
627 * clock type selection 715 * clock type selection
628 * enum pcxhr_clock_type { 716 * enum pcxhr_clock_type {
629 * PCXHR_CLOCK_TYPE_INTERNAL = 0, 717 * PCXHR_CLOCK_TYPE_INTERNAL = 0,
630 * PCXHR_CLOCK_TYPE_WORD_CLOCK, 718 * PCXHR_CLOCK_TYPE_WORD_CLOCK,
631 * PCXHR_CLOCK_TYPE_AES_SYNC, 719 * PCXHR_CLOCK_TYPE_AES_SYNC,
632 * PCXHR_CLOCK_TYPE_AES_1, 720 * PCXHR_CLOCK_TYPE_AES_1,
633 * PCXHR_CLOCK_TYPE_AES_2, 721 * PCXHR_CLOCK_TYPE_AES_2,
634 * PCXHR_CLOCK_TYPE_AES_3, 722 * PCXHR_CLOCK_TYPE_AES_3,
635 * PCXHR_CLOCK_TYPE_AES_4, 723 * PCXHR_CLOCK_TYPE_AES_4,
636 * }; 724 * PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4,
725 * HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL,
726 * HR22_CLOCK_TYPE_AES_SYNC,
727 * HR22_CLOCK_TYPE_AES_1,
728 * HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1,
729 * };
637 */ 730 */
638 731
639static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol, 732static int pcxhr_clock_type_info(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_info *uinfo) 733 struct snd_ctl_elem_info *uinfo)
641{ 734{
642 static char *texts[7] = { 735 static const char *textsPCXHR[7] = {
643 "Internal", "WordClock", "AES Sync", "AES 1", "AES 2", "AES 3", "AES 4" 736 "Internal", "WordClock", "AES Sync",
737 "AES 1", "AES 2", "AES 3", "AES 4"
738 };
739 static const char *textsHR22[3] = {
740 "Internal", "AES Sync", "AES 1"
644 }; 741 };
742 const char **texts;
645 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); 743 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
646 int clock_items = 3 + mgr->capture_chips; 744 int clock_items = 2; /* at least Internal and AES Sync clock */
647 745 if (mgr->board_has_aes1) {
746 clock_items += mgr->capture_chips; /* add AES x */
747 if (!mgr->is_hr_stereo)
748 clock_items += 1; /* add word clock */
749 }
750 if (mgr->is_hr_stereo) {
751 texts = textsHR22;
752 snd_BUG_ON(clock_items > (HR22_CLOCK_TYPE_MAX+1));
753 } else {
754 texts = textsPCXHR;
755 snd_BUG_ON(clock_items > (PCXHR_CLOCK_TYPE_MAX+1));
756 }
648 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 757 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
649 uinfo->count = 1; 758 uinfo->count = 1;
650 uinfo->value.enumerated.items = clock_items; 759 uinfo->value.enumerated.items = clock_items;
@@ -667,9 +776,13 @@ static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol) 776 struct snd_ctl_elem_value *ucontrol)
668{ 777{
669 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); 778 struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol);
670 unsigned int clock_items = 3 + mgr->capture_chips;
671 int rate, ret = 0; 779 int rate, ret = 0;
672 780 unsigned int clock_items = 2; /* at least Internal and AES Sync clock */
781 if (mgr->board_has_aes1) {
782 clock_items += mgr->capture_chips; /* add AES x */
783 if (!mgr->is_hr_stereo)
784 clock_items += 1; /* add word clock */
785 }
673 if (ucontrol->value.enumerated.item[0] >= clock_items) 786 if (ucontrol->value.enumerated.item[0] >= clock_items)
674 return -EINVAL; 787 return -EINVAL;
675 mutex_lock(&mgr->mixer_mutex); 788 mutex_lock(&mgr->mixer_mutex);
@@ -677,7 +790,8 @@ static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
677 mutex_lock(&mgr->setup_mutex); 790 mutex_lock(&mgr->setup_mutex);
678 mgr->use_clock_type = ucontrol->value.enumerated.item[0]; 791 mgr->use_clock_type = ucontrol->value.enumerated.item[0];
679 if (mgr->use_clock_type) 792 if (mgr->use_clock_type)
680 pcxhr_get_external_clock(mgr, mgr->use_clock_type, &rate); 793 pcxhr_get_external_clock(mgr, mgr->use_clock_type,
794 &rate);
681 else 795 else
682 rate = mgr->sample_rate; 796 rate = mgr->sample_rate;
683 if (rate) { 797 if (rate) {
@@ -686,7 +800,7 @@ static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
686 mgr->sample_rate = rate; 800 mgr->sample_rate = rate;
687 } 801 }
688 mutex_unlock(&mgr->setup_mutex); 802 mutex_unlock(&mgr->setup_mutex);
689 ret = 1; /* return 1 even if the set was not done. ok ? */ 803 ret = 1; /* return 1 even if the set was not done. ok ? */
690 } 804 }
691 mutex_unlock(&mgr->mixer_mutex); 805 mutex_unlock(&mgr->mixer_mutex);
692 return ret; 806 return ret;
@@ -747,14 +861,16 @@ static struct snd_kcontrol_new pcxhr_control_clock_rate = {
747/* 861/*
748 * IEC958 status bits 862 * IEC958 status bits
749 */ 863 */
750static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 864static int pcxhr_iec958_info(struct snd_kcontrol *kcontrol,
865 struct snd_ctl_elem_info *uinfo)
751{ 866{
752 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 867 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
753 uinfo->count = 1; 868 uinfo->count = 1;
754 return 0; 869 return 0;
755} 870}
756 871
757static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip, int aes_idx, unsigned char* aes_bits) 872static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip,
873 int aes_idx, unsigned char *aes_bits)
758{ 874{
759 int i, err; 875 int i, err;
760 unsigned char temp; 876 unsigned char temp;
@@ -763,39 +879,61 @@ static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip, int aes_idx, unsign
763 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ); 879 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_READ);
764 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG; 880 rmh.cmd[0] |= IO_NUM_UER_CHIP_REG;
765 switch (chip->chip_idx) { 881 switch (chip->chip_idx) {
766 case 0: rmh.cmd[1] = CS8420_01_CS; break; /* use CS8416_01_CS for AES SYNC plug */ 882 /* instead of CS8420_01_CS use CS8416_01_CS for AES SYNC plug */
883 case 0: rmh.cmd[1] = CS8420_01_CS; break;
767 case 1: rmh.cmd[1] = CS8420_23_CS; break; 884 case 1: rmh.cmd[1] = CS8420_23_CS; break;
768 case 2: rmh.cmd[1] = CS8420_45_CS; break; 885 case 2: rmh.cmd[1] = CS8420_45_CS; break;
769 case 3: rmh.cmd[1] = CS8420_67_CS; break; 886 case 3: rmh.cmd[1] = CS8420_67_CS; break;
770 default: return -EINVAL; 887 default: return -EINVAL;
771 } 888 }
772 switch (aes_idx) { 889 if (chip->mgr->board_aes_in_192k) {
773 case 0: rmh.cmd[2] = CS8420_CSB0; break; /* use CS8416_CSBx for AES SYNC plug */ 890 switch (aes_idx) {
774 case 1: rmh.cmd[2] = CS8420_CSB1; break; 891 case 0: rmh.cmd[2] = CS8416_CSB0; break;
775 case 2: rmh.cmd[2] = CS8420_CSB2; break; 892 case 1: rmh.cmd[2] = CS8416_CSB1; break;
776 case 3: rmh.cmd[2] = CS8420_CSB3; break; 893 case 2: rmh.cmd[2] = CS8416_CSB2; break;
777 case 4: rmh.cmd[2] = CS8420_CSB4; break; 894 case 3: rmh.cmd[2] = CS8416_CSB3; break;
778 default: return -EINVAL; 895 case 4: rmh.cmd[2] = CS8416_CSB4; break;
896 default: return -EINVAL;
897 }
898 } else {
899 switch (aes_idx) {
900 /* instead of CS8420_CSB0 use CS8416_CSBx for AES SYNC plug */
901 case 0: rmh.cmd[2] = CS8420_CSB0; break;
902 case 1: rmh.cmd[2] = CS8420_CSB1; break;
903 case 2: rmh.cmd[2] = CS8420_CSB2; break;
904 case 3: rmh.cmd[2] = CS8420_CSB3; break;
905 case 4: rmh.cmd[2] = CS8420_CSB4; break;
906 default: return -EINVAL;
907 }
779 } 908 }
780 rmh.cmd[1] &= 0x0fffff; /* size and code the chip id for the fpga */ 909 /* size and code the chip id for the fpga */
781 rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI; /* chip signature + map for spi read */ 910 rmh.cmd[1] &= 0x0fffff;
911 /* chip signature + map for spi read */
912 rmh.cmd[2] &= CHIP_SIG_AND_MAP_SPI;
782 rmh.cmd_len = 3; 913 rmh.cmd_len = 3;
783 err = pcxhr_send_msg(chip->mgr, &rmh); 914 err = pcxhr_send_msg(chip->mgr, &rmh);
784 if (err) 915 if (err)
785 return err; 916 return err;
786 temp = 0; 917
787 for (i = 0; i < 8; i++) { 918 if (chip->mgr->board_aes_in_192k) {
788 /* attention : reversed bit order (not with CS8416_01_CS) */ 919 temp = (unsigned char)rmh.stat[1];
789 temp <<= 1; 920 } else {
790 if (rmh.stat[1] & (1 << i)) 921 temp = 0;
791 temp |= 1; 922 /* reversed bit order (not with CS8416_01_CS) */
923 for (i = 0; i < 8; i++) {
924 temp <<= 1;
925 if (rmh.stat[1] & (1 << i))
926 temp |= 1;
927 }
792 } 928 }
793 snd_printdd("read iec958 AES %d byte %d = 0x%x\n", chip->chip_idx, aes_idx, temp); 929 snd_printdd("read iec958 AES %d byte %d = 0x%x\n",
930 chip->chip_idx, aes_idx, temp);
794 *aes_bits = temp; 931 *aes_bits = temp;
795 return 0; 932 return 0;
796} 933}
797 934
798static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 935static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol,
936 struct snd_ctl_elem_value *ucontrol)
799{ 937{
800 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 938 struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol);
801 unsigned char aes_bits; 939 unsigned char aes_bits;
@@ -806,7 +944,12 @@ static int pcxhr_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
806 if (kcontrol->private_value == 0) /* playback */ 944 if (kcontrol->private_value == 0) /* playback */
807 aes_bits = chip->aes_bits[i]; 945 aes_bits = chip->aes_bits[i];
808 else { /* capture */ 946 else { /* capture */
809 err = pcxhr_iec958_capture_byte(chip, i, &aes_bits); 947 if (chip->mgr->is_hr_stereo)
948 err = hr222_iec958_capture_byte(chip, i,
949 &aes_bits);
950 else
951 err = pcxhr_iec958_capture_byte(chip, i,
952 &aes_bits);
810 if (err) 953 if (err)
811 break; 954 break;
812 } 955 }
@@ -825,7 +968,8 @@ static int pcxhr_iec958_mask_get(struct snd_kcontrol *kcontrol,
825 return 0; 968 return 0;
826} 969}
827 970
828static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip, int aes_idx, unsigned char aes_bits) 971static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip,
972 int aes_idx, unsigned char aes_bits)
829{ 973{
830 int i, err, cmd; 974 int i, err, cmd;
831 unsigned char new_bits = aes_bits; 975 unsigned char new_bits = aes_bits;
@@ -834,12 +978,12 @@ static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip, int aes_idx, unsigne
834 978
835 for (i = 0; i < 8; i++) { 979 for (i = 0; i < 8; i++) {
836 if ((old_bits & 0x01) != (new_bits & 0x01)) { 980 if ((old_bits & 0x01) != (new_bits & 0x01)) {
837 cmd = chip->chip_idx & 0x03; /* chip index 0..3 */ 981 cmd = chip->chip_idx & 0x03; /* chip index 0..3 */
838 if(chip->chip_idx > 3) 982 if (chip->chip_idx > 3)
839 /* new bit used if chip_idx>3 (PCX1222HR) */ 983 /* new bit used if chip_idx>3 (PCX1222HR) */
840 cmd |= 1 << 22; 984 cmd |= 1 << 22;
841 cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */ 985 cmd |= ((aes_idx << 3) + i) << 2; /* add bit offset */
842 cmd |= (new_bits & 0x01) << 23; /* add bit value */ 986 cmd |= (new_bits & 0x01) << 23; /* add bit value */
843 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE); 987 pcxhr_init_rmh(&rmh, CMD_ACCESS_IO_WRITE);
844 rmh.cmd[0] |= IO_NUM_REG_CUER; 988 rmh.cmd[0] |= IO_NUM_REG_CUER;
845 rmh.cmd[1] = cmd; 989 rmh.cmd[1] = cmd;
@@ -867,7 +1011,12 @@ static int pcxhr_iec958_put(struct snd_kcontrol *kcontrol,
867 mutex_lock(&chip->mgr->mixer_mutex); 1011 mutex_lock(&chip->mgr->mixer_mutex);
868 for (i = 0; i < 5; i++) { 1012 for (i = 0; i < 5; i++) {
869 if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) { 1013 if (ucontrol->value.iec958.status[i] != chip->aes_bits[i]) {
870 pcxhr_iec958_update_byte(chip, i, ucontrol->value.iec958.status[i]); 1014 if (chip->mgr->is_hr_stereo)
1015 hr222_iec958_update_byte(chip, i,
1016 ucontrol->value.iec958.status[i]);
1017 else
1018 pcxhr_iec958_update_byte(chip, i,
1019 ucontrol->value.iec958.status[i]);
871 changed = 1; 1020 changed = 1;
872 } 1021 }
873 } 1022 }
@@ -917,29 +1066,53 @@ static void pcxhr_init_audio_levels(struct snd_pcxhr *chip)
917 /* at boot time the digital volumes are unmuted 0dB */ 1066 /* at boot time the digital volumes are unmuted 0dB */
918 for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) { 1067 for (j = 0; j < PCXHR_PLAYBACK_STREAMS; j++) {
919 chip->digital_playback_active[j][i] = 1; 1068 chip->digital_playback_active[j][i] = 1;
920 chip->digital_playback_volume[j][i] = PCXHR_DIGITAL_ZERO_LEVEL; 1069 chip->digital_playback_volume[j][i] =
1070 PCXHR_DIGITAL_ZERO_LEVEL;
921 } 1071 }
922 /* after boot, only two bits are set on the uer interface */ 1072 /* after boot, only two bits are set on the uer
923 chip->aes_bits[0] = IEC958_AES0_PROFESSIONAL | IEC958_AES0_PRO_FS_48000; 1073 * interface
924/* only for test purpose, remove later */ 1074 */
1075 chip->aes_bits[0] = (IEC958_AES0_PROFESSIONAL |
1076 IEC958_AES0_PRO_FS_48000);
925#ifdef CONFIG_SND_DEBUG 1077#ifdef CONFIG_SND_DEBUG
926 /* analog volumes for playback (is LEVEL_MIN after boot) */ 1078 /* analog volumes for playback
1079 * (is LEVEL_MIN after boot)
1080 */
927 chip->analog_playback_active[i] = 1; 1081 chip->analog_playback_active[i] = 1;
928 chip->analog_playback_volume[i] = PCXHR_ANALOG_PLAYBACK_ZERO_LEVEL; 1082 if (chip->mgr->is_hr_stereo)
929 pcxhr_update_analog_audio_level(chip, 0, i); 1083 chip->analog_playback_volume[i] =
1084 HR222_LINE_PLAYBACK_ZERO_LEVEL;
1085 else {
1086 chip->analog_playback_volume[i] =
1087 PCXHR_LINE_PLAYBACK_ZERO_LEVEL;
1088 pcxhr_update_analog_audio_level(chip, 0, i);
1089 }
930#endif 1090#endif
931/* test end */ 1091 /* stereo cards need to be initialised after boot */
1092 if (chip->mgr->is_hr_stereo)
1093 hr222_update_analog_audio_level(chip, 0, i);
932 } 1094 }
933 if (chip->nb_streams_capt) { 1095 if (chip->nb_streams_capt) {
934 /* at boot time the digital volumes are unmuted 0dB */ 1096 /* at boot time the digital volumes are unmuted 0dB */
935 chip->digital_capture_volume[i] = PCXHR_DIGITAL_ZERO_LEVEL; 1097 chip->digital_capture_volume[i] =
936/* only for test purpose, remove later */ 1098 PCXHR_DIGITAL_ZERO_LEVEL;
1099 chip->analog_capture_active = 1;
937#ifdef CONFIG_SND_DEBUG 1100#ifdef CONFIG_SND_DEBUG
938 /* analog volumes for playback (is LEVEL_MIN after boot) */ 1101 /* analog volumes for playback
939 chip->analog_capture_volume[i] = PCXHR_ANALOG_CAPTURE_ZERO_LEVEL; 1102 * (is LEVEL_MIN after boot)
940 pcxhr_update_analog_audio_level(chip, 1, i); 1103 */
1104 if (chip->mgr->is_hr_stereo)
1105 chip->analog_capture_volume[i] =
1106 HR222_LINE_CAPTURE_ZERO_LEVEL;
1107 else {
1108 chip->analog_capture_volume[i] =
1109 PCXHR_LINE_CAPTURE_ZERO_LEVEL;
1110 pcxhr_update_analog_audio_level(chip, 1, i);
1111 }
941#endif 1112#endif
942/* test end */ 1113 /* stereo cards need to be initialised after boot */
1114 if (chip->mgr->is_hr_stereo)
1115 hr222_update_analog_audio_level(chip, 1, i);
943 } 1116 }
944 } 1117 }
945 1118
@@ -963,90 +1136,125 @@ int pcxhr_create_mixer(struct pcxhr_mgr *mgr)
963 temp = pcxhr_control_analog_level; 1136 temp = pcxhr_control_analog_level;
964 temp.name = "Master Playback Volume"; 1137 temp.name = "Master Playback Volume";
965 temp.private_value = 0; /* playback */ 1138 temp.private_value = 0; /* playback */
966 temp.tlv.p = db_scale_analog_playback; 1139 if (mgr->is_hr_stereo)
967 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) 1140 temp.tlv.p = db_scale_a_hr222_playback;
1141 else
1142 temp.tlv.p = db_scale_analog_playback;
1143 err = snd_ctl_add(chip->card,
1144 snd_ctl_new1(&temp, chip));
1145 if (err < 0)
968 return err; 1146 return err;
1147
969 /* output mute controls */ 1148 /* output mute controls */
970 if ((err = snd_ctl_add(chip->card, 1149 err = snd_ctl_add(chip->card,
971 snd_ctl_new1(&pcxhr_control_output_switch, 1150 snd_ctl_new1(&pcxhr_control_output_switch,
972 chip))) < 0) 1151 chip));
1152 if (err < 0)
973 return err; 1153 return err;
974 1154
975 temp = snd_pcxhr_pcm_vol; 1155 temp = snd_pcxhr_pcm_vol;
976 temp.name = "PCM Playback Volume"; 1156 temp.name = "PCM Playback Volume";
977 temp.count = PCXHR_PLAYBACK_STREAMS; 1157 temp.count = PCXHR_PLAYBACK_STREAMS;
978 temp.private_value = 0; /* playback */ 1158 temp.private_value = 0; /* playback */
979 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) 1159 err = snd_ctl_add(chip->card,
1160 snd_ctl_new1(&temp, chip));
1161 if (err < 0)
980 return err; 1162 return err;
981 1163
982 if ((err = snd_ctl_add(chip->card, 1164 err = snd_ctl_add(chip->card,
983 snd_ctl_new1(&pcxhr_control_pcm_switch, 1165 snd_ctl_new1(&pcxhr_control_pcm_switch, chip));
984 chip))) < 0) 1166 if (err < 0)
985 return err; 1167 return err;
986 1168
987 /* IEC958 controls */ 1169 /* IEC958 controls */
988 if ((err = snd_ctl_add(chip->card, 1170 err = snd_ctl_add(chip->card,
989 snd_ctl_new1(&pcxhr_control_playback_iec958_mask, 1171 snd_ctl_new1(&pcxhr_control_playback_iec958_mask,
990 chip))) < 0) 1172 chip));
1173 if (err < 0)
991 return err; 1174 return err;
992 if ((err = snd_ctl_add(chip->card, 1175
993 snd_ctl_new1(&pcxhr_control_playback_iec958, 1176 err = snd_ctl_add(chip->card,
994 chip))) < 0) 1177 snd_ctl_new1(&pcxhr_control_playback_iec958,
1178 chip));
1179 if (err < 0)
995 return err; 1180 return err;
996 } 1181 }
997 if (chip->nb_streams_capt) { 1182 if (chip->nb_streams_capt) {
998 /* analog input level control only on first two chips !*/ 1183 /* analog input level control */
999 temp = pcxhr_control_analog_level; 1184 temp = pcxhr_control_analog_level;
1000 temp.name = "Master Capture Volume"; 1185 temp.name = "Line Capture Volume";
1001 temp.private_value = 1; /* capture */ 1186 temp.private_value = 1; /* capture */
1002 temp.tlv.p = db_scale_analog_capture; 1187 if (mgr->is_hr_stereo)
1003 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) 1188 temp.tlv.p = db_scale_a_hr222_capture;
1189 else
1190 temp.tlv.p = db_scale_analog_capture;
1191
1192 err = snd_ctl_add(chip->card,
1193 snd_ctl_new1(&temp, chip));
1194 if (err < 0)
1004 return err; 1195 return err;
1005 1196
1006 temp = snd_pcxhr_pcm_vol; 1197 temp = snd_pcxhr_pcm_vol;
1007 temp.name = "PCM Capture Volume"; 1198 temp.name = "PCM Capture Volume";
1008 temp.count = 1; 1199 temp.count = 1;
1009 temp.private_value = 1; /* capture */ 1200 temp.private_value = 1; /* capture */
1010 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) 1201
1202 err = snd_ctl_add(chip->card,
1203 snd_ctl_new1(&temp, chip));
1204 if (err < 0)
1011 return err; 1205 return err;
1206
1012 /* Audio source */ 1207 /* Audio source */
1013 if ((err = snd_ctl_add(chip->card, 1208 err = snd_ctl_add(chip->card,
1014 snd_ctl_new1(&pcxhr_control_audio_src, 1209 snd_ctl_new1(&pcxhr_control_audio_src, chip));
1015 chip))) < 0) 1210 if (err < 0)
1016 return err; 1211 return err;
1212
1017 /* IEC958 controls */ 1213 /* IEC958 controls */
1018 if ((err = snd_ctl_add(chip->card, 1214 err = snd_ctl_add(chip->card,
1019 snd_ctl_new1(&pcxhr_control_capture_iec958_mask, 1215 snd_ctl_new1(&pcxhr_control_capture_iec958_mask,
1020 chip))) < 0) 1216 chip));
1217 if (err < 0)
1021 return err; 1218 return err;
1022 if ((err = snd_ctl_add(chip->card, 1219
1023 snd_ctl_new1(&pcxhr_control_capture_iec958, 1220 err = snd_ctl_add(chip->card,
1024 chip))) < 0) 1221 snd_ctl_new1(&pcxhr_control_capture_iec958,
1222 chip));
1223 if (err < 0)
1025 return err; 1224 return err;
1225
1226 if (mgr->is_hr_stereo) {
1227 err = hr222_add_mic_controls(chip);
1228 if (err < 0)
1229 return err;
1230 }
1026 } 1231 }
1027 /* monitoring only if playback and capture device available */ 1232 /* monitoring only if playback and capture device available */
1028 if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) { 1233 if (chip->nb_streams_capt > 0 && chip->nb_streams_play > 0) {
1029 /* monitoring */ 1234 /* monitoring */
1030 if ((err = snd_ctl_add(chip->card, 1235 err = snd_ctl_add(chip->card,
1031 snd_ctl_new1(&pcxhr_control_monitor_vol, 1236 snd_ctl_new1(&pcxhr_control_monitor_vol, chip));
1032 chip))) < 0) 1237 if (err < 0)
1033 return err; 1238 return err;
1034 if ((err = snd_ctl_add(chip->card, 1239
1035 snd_ctl_new1(&pcxhr_control_monitor_sw, 1240 err = snd_ctl_add(chip->card,
1036 chip))) < 0) 1241 snd_ctl_new1(&pcxhr_control_monitor_sw, chip));
1242 if (err < 0)
1037 return err; 1243 return err;
1038 } 1244 }
1039 1245
1040 if (i == 0) { 1246 if (i == 0) {
1041 /* clock mode only one control per pcxhr */ 1247 /* clock mode only one control per pcxhr */
1042 if ((err = snd_ctl_add(chip->card, 1248 err = snd_ctl_add(chip->card,
1043 snd_ctl_new1(&pcxhr_control_clock_type, 1249 snd_ctl_new1(&pcxhr_control_clock_type, mgr));
1044 mgr))) < 0) 1250 if (err < 0)
1045 return err; 1251 return err;
1046 /* non standard control used to scan the external clock presence/frequencies */ 1252 /* non standard control used to scan
1047 if ((err = snd_ctl_add(chip->card, 1253 * the external clock presence/frequencies
1048 snd_ctl_new1(&pcxhr_control_clock_rate, 1254 */
1049 mgr))) < 0) 1255 err = snd_ctl_add(chip->card,
1256 snd_ctl_new1(&pcxhr_control_clock_rate, mgr));
1257 if (err < 0)
1050 return err; 1258 return err;
1051 } 1259 }
1052 1260
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index e9f0706ed3e4..3caacfb9d8e0 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -172,7 +172,7 @@ MODULE_PARM_DESC(opl3_port, "OPL3 port # for Riptide driver.");
172 172
173#define MAX_WRITE_RETRY 10 /* cmd interface limits */ 173#define MAX_WRITE_RETRY 10 /* cmd interface limits */
174#define MAX_ERROR_COUNT 10 174#define MAX_ERROR_COUNT 10
175#define CMDIF_TIMEOUT 500000 175#define CMDIF_TIMEOUT 50000
176#define RESET_TRIES 5 176#define RESET_TRIES 5
177 177
178#define READ_PORT_ULONG(p) inl((unsigned long)&(p)) 178#define READ_PORT_ULONG(p) inl((unsigned long)&(p))
@@ -1754,7 +1754,7 @@ snd_riptide_interrupt(int irq, void *dev_id)
1754 if (IS_EOBIRQ(cif->hwport) || IS_EOSIRQ(cif->hwport) || 1754 if (IS_EOBIRQ(cif->hwport) || IS_EOSIRQ(cif->hwport) ||
1755 IS_EOCIRQ(cif->hwport)) { 1755 IS_EOCIRQ(cif->hwport)) {
1756 chip->handled_irqs++; 1756 chip->handled_irqs++;
1757 tasklet_hi_schedule(&chip->riptide_tq); 1757 tasklet_schedule(&chip->riptide_tq);
1758 } 1758 }
1759 if (chip->rmidi && IS_MPUIRQ(cif->hwport)) { 1759 if (chip->rmidi && IS_MPUIRQ(cif->hwport)) {
1760 chip->handled_irqs++; 1760 chip->handled_irqs++;
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 736246f98acc..44d0c15e2b71 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -1452,7 +1452,7 @@ static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int i
1452 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) 1452 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1453 return -1; 1453 return -1;
1454 1454
1455 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1); 1455 sprintf(hdsp->midi[id].rmidi->name, "HDSP MIDI %d", id+1);
1456 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id]; 1456 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1457 1457
1458 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output); 1458 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
@@ -3750,7 +3750,7 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
3750 } 3750 }
3751 } 3751 }
3752 if (hdsp->use_midi_tasklet && schedule) 3752 if (hdsp->use_midi_tasklet && schedule)
3753 tasklet_hi_schedule(&hdsp->midi_tasklet); 3753 tasklet_schedule(&hdsp->midi_tasklet);
3754 return IRQ_HANDLED; 3754 return IRQ_HANDLED;
3755} 3755}
3756 3756
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 98762f909d64..71231cf1b2b0 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -1293,7 +1293,7 @@ static int __devinit snd_hdspm_create_midi (struct snd_card *card,
1293 if (err < 0) 1293 if (err < 0)
1294 return err; 1294 return err;
1295 1295
1296 sprintf (hdspm->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1); 1296 sprintf(hdspm->midi[id].rmidi->name, "HDSPM MIDI %d", id+1);
1297 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; 1297 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
1298 1298
1299 snd_rawmidi_set_ops(hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, 1299 snd_rawmidi_set_ops(hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
@@ -3476,7 +3476,7 @@ static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
3476 schedule = 1; 3476 schedule = 1;
3477 } 3477 }
3478 if (schedule) 3478 if (schedule)
3479 tasklet_hi_schedule(&hdspm->midi_tasklet); 3479 tasklet_schedule(&hdspm->midi_tasklet);
3480 return IRQ_HANDLED; 3480 return IRQ_HANDLED;
3481} 3481}
3482 3482