aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/aoa/core/gpio-feature.c3
-rw-r--r--sound/aoa/fabrics/layout.c4
-rw-r--r--sound/aoa/soundbus/i2sbus/core.c2
-rw-r--r--sound/arm/pxa2xx-ac97-lib.c31
-rw-r--r--sound/arm/pxa2xx-ac97.c2
-rw-r--r--sound/arm/pxa2xx-pcm.c10
-rw-r--r--sound/atmel/ac97c.c1
-rw-r--r--sound/core/compress_offload.c57
-rw-r--r--sound/core/init.c4
-rw-r--r--sound/core/jack.c19
-rw-r--r--sound/core/memalloc.c57
-rw-r--r--sound/core/pcm.c4
-rw-r--r--sound/core/pcm_dmaengine.c22
-rw-r--r--sound/core/pcm_native.c10
-rw-r--r--sound/core/sound.c22
-rw-r--r--sound/drivers/opl3/opl3_midi.c5
-rw-r--r--sound/drivers/pcsp/pcsp.c5
-rw-r--r--sound/firewire/Kconfig15
-rw-r--r--sound/firewire/Makefile2
-rw-r--r--sound/firewire/amdtp.c213
-rw-r--r--sound/firewire/amdtp.h46
-rw-r--r--sound/firewire/cmp.c50
-rw-r--r--sound/firewire/dice-interface.h371
-rw-r--r--sound/firewire/dice.c1494
-rw-r--r--sound/firewire/fcp.c2
-rw-r--r--sound/firewire/isight.c43
-rw-r--r--sound/firewire/lib.c24
-rw-r--r--sound/firewire/lib.h7
-rw-r--r--sound/firewire/scs1x.c8
-rw-r--r--sound/firewire/speakers.c16
-rw-r--r--sound/i2c/other/ak4114.c8
-rw-r--r--sound/i2c/other/ak4xxx-adda.c2
-rw-r--r--sound/isa/cmi8328.c2
-rw-r--r--sound/isa/msnd/msnd_pinnacle.c4
-rw-r--r--sound/isa/sb/sb16_csp.c1
-rw-r--r--sound/isa/wavefront/wavefront_synth.c2
-rw-r--r--sound/mips/ad1843.c2
-rw-r--r--sound/oss/sb_ess.c2
-rw-r--r--sound/pci/ac97/ac97_codec.c1
-rw-r--r--sound/pci/ad1889.c2
-rw-r--r--sound/pci/ali5451/ali5451.c2
-rw-r--r--sound/pci/asihpi/asihpi.c9
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c2
-rw-r--r--sound/pci/au88x0/au88x0_synth.c29
-rw-r--r--sound/pci/azt3328.c14
-rw-r--r--sound/pci/cs5535audio/cs5535audio_olpc.c4
-rw-r--r--sound/pci/ctxfi/ctdaio.c4
-rw-r--r--sound/pci/ctxfi/cthardware.c6
-rw-r--r--sound/pci/emu10k1/emufx.c76
-rw-r--r--sound/pci/hda/hda_auto_parser.c2
-rw-r--r--sound/pci/hda/hda_beep.c5
-rw-r--r--sound/pci/hda/hda_codec.c56
-rw-r--r--sound/pci/hda/hda_codec.h1
-rw-r--r--sound/pci/hda/hda_eld.c220
-rw-r--r--sound/pci/hda/hda_generic.c18
-rw-r--r--sound/pci/hda/hda_generic.h3
-rw-r--r--sound/pci/hda/hda_intel.c45
-rw-r--r--sound/pci/hda/hda_jack.c2
-rw-r--r--sound/pci/hda/hda_jack.h1
-rw-r--r--sound/pci/hda/hda_local.h27
-rw-r--r--sound/pci/hda/patch_analog.c54
-rw-r--r--sound/pci/hda/patch_ca0132.c2
-rw-r--r--sound/pci/hda/patch_cirrus.c84
-rw-r--r--sound/pci/hda/patch_conexant.c106
-rw-r--r--sound/pci/hda/patch_hdmi.c1023
-rw-r--r--sound/pci/hda/patch_realtek.c356
-rw-r--r--sound/pci/hda/patch_sigmatel.c536
-rw-r--r--sound/pci/ice1712/psc724.c4
-rw-r--r--sound/pci/ice1712/quartet.c2
-rw-r--r--sound/pci/ice1712/wm8766.c3
-rw-r--r--sound/pci/ice1712/wm8776.c5
-rw-r--r--sound/pci/intel8x0.c17
-rw-r--r--sound/pci/lola/lola.c2
-rw-r--r--sound/pci/lx6464es/lx6464es.c4
-rw-r--r--sound/pci/lx6464es/lx_core.c4
-rw-r--r--sound/pci/rme96.c10
-rw-r--r--sound/pci/rme9652/hdsp.c1
-rw-r--r--sound/pci/rme9652/hdspm.c7
-rw-r--r--sound/ppc/pmac.c2
-rw-r--r--sound/ppc/snd_ps3.c6
-rw-r--r--sound/ppc/tumbler.c1
-rw-r--r--sound/soc/Makefile2
-rw-r--r--sound/soc/atmel/atmel-pcm.c13
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c2
-rw-r--r--sound/soc/atmel/atmel_wm8904.c8
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c1
-rw-r--r--sound/soc/blackfin/bf5xx-ac97-pcm.c11
-rw-r--r--sound/soc/blackfin/bf5xx-i2s-pcm.c10
-rw-r--r--sound/soc/blackfin/bf5xx-i2s.c1
-rw-r--r--sound/soc/blackfin/bf5xx-sport.c32
-rw-r--r--sound/soc/blackfin/bf6xx-i2s.c1
-rw-r--r--sound/soc/cirrus/Kconfig2
-rw-r--r--sound/soc/cirrus/ep93xx-pcm.c13
-rw-r--r--sound/soc/codecs/88pm860x-codec.c78
-rw-r--r--sound/soc/codecs/88pm860x-codec.h117
-rw-r--r--sound/soc/codecs/ab8500-codec.c99
-rw-r--r--sound/soc/codecs/adau1373.c298
-rw-r--r--sound/soc/codecs/adav80x.c147
-rw-r--r--sound/soc/codecs/ak4104.c11
-rw-r--r--sound/soc/codecs/ak4641.c2
-rw-r--r--sound/soc/codecs/ak4642.c4
-rw-r--r--sound/soc/codecs/alc5632.c2
-rw-r--r--sound/soc/codecs/arizona.c23
-rw-r--r--sound/soc/codecs/cq93vc.c46
-rw-r--r--sound/soc/codecs/cs4271.c1
-rw-r--r--sound/soc/codecs/cs42l52.c93
-rw-r--r--sound/soc/codecs/cs42l52.h4
-rw-r--r--sound/soc/codecs/cs42l73.c114
-rw-r--r--sound/soc/codecs/cs42l73.h105
-rw-r--r--sound/soc/codecs/max98088.c632
-rw-r--r--sound/soc/codecs/max98095.c486
-rw-r--r--sound/soc/codecs/max9850.c39
-rw-r--r--sound/soc/codecs/mc13783.c137
-rw-r--r--sound/soc/codecs/ml26124.c2
-rw-r--r--sound/soc/codecs/pcm1681.c3
-rw-r--r--sound/soc/codecs/pcm1792a.c3
-rw-r--r--sound/soc/codecs/rt5640.c31
-rw-r--r--sound/soc/codecs/si476x.c64
-rw-r--r--sound/soc/codecs/sn95031.c35
-rw-r--r--sound/soc/codecs/tas5086.c173
-rw-r--r--sound/soc/codecs/tlv320aic23.c84
-rw-r--r--sound/soc/codecs/tlv320aic26.c139
-rw-r--r--sound/soc/codecs/tlv320aic26.h5
-rw-r--r--sound/soc/codecs/tlv320aic32x4.c101
-rw-r--r--sound/soc/codecs/tlv320aic3x.c238
-rw-r--r--sound/soc/codecs/tpa6130a2.c53
-rw-r--r--sound/soc/codecs/twl4030.c80
-rw-r--r--sound/soc/codecs/twl6040.c26
-rw-r--r--sound/soc/codecs/wm0010.c11
-rw-r--r--sound/soc/codecs/wm2000.c15
-rw-r--r--sound/soc/codecs/wm5100.c3
-rw-r--r--sound/soc/codecs/wm5102.c8
-rw-r--r--sound/soc/codecs/wm5110.c20
-rw-r--r--sound/soc/codecs/wm8350.c2
-rw-r--r--sound/soc/codecs/wm8400.c95
-rw-r--r--sound/soc/codecs/wm8580.c2
-rw-r--r--sound/soc/codecs/wm8776.c3
-rw-r--r--sound/soc/codecs/wm8900.c11
-rw-r--r--sound/soc/codecs/wm8904.c5
-rw-r--r--sound/soc/codecs/wm8958-dsp2.c2
-rw-r--r--sound/soc/codecs/wm8962.c238
-rw-r--r--sound/soc/codecs/wm8996.c14
-rw-r--r--sound/soc/codecs/wm8997.c10
-rw-r--r--sound/soc/codecs/wm9713.c3
-rw-r--r--sound/soc/codecs/wm_adsp.c49
-rw-r--r--sound/soc/codecs/wm_hubs.c3
-rw-r--r--sound/soc/davinci/Kconfig18
-rw-r--r--sound/soc/davinci/Makefile1
-rw-r--r--sound/soc/davinci/davinci-evm.c188
-rw-r--r--sound/soc/davinci/davinci-mcasp.c169
-rw-r--r--sound/soc/davinci/davinci-mcasp.h12
-rw-r--r--sound/soc/davinci/davinci-pcm.c12
-rw-r--r--sound/soc/fsl/eukrea-tlv320.c15
-rw-r--r--sound/soc/fsl/fsl_dma.c11
-rw-r--r--sound/soc/fsl/fsl_spdif.c23
-rw-r--r--sound/soc/fsl/fsl_ssi.c22
-rw-r--r--sound/soc/fsl/imx-audmux.c9
-rw-r--r--sound/soc/fsl/imx-mc13783.c3
-rw-r--r--sound/soc/fsl/imx-pcm-dma.c4
-rw-r--r--sound/soc/fsl/imx-pcm-fiq.c63
-rw-r--r--sound/soc/fsl/imx-sgtl5000.c11
-rw-r--r--sound/soc/fsl/imx-spdif.c4
-rw-r--r--sound/soc/fsl/imx-ssi.c26
-rw-r--r--sound/soc/fsl/imx-ssi.h2
-rw-r--r--sound/soc/fsl/imx-wm8962.c7
-rw-r--r--sound/soc/fsl/mpc5200_dma.c12
-rw-r--r--sound/soc/fsl/mpc5200_psc_ac97.c2
-rw-r--r--sound/soc/fsl/mpc8610_hpcd.c1
-rw-r--r--sound/soc/fsl/p1022_ds.c1
-rw-r--r--sound/soc/fsl/p1022_rdk.c1
-rw-r--r--sound/soc/generic/simple-card.c5
-rw-r--r--sound/soc/jz4740/jz4740-pcm.c12
-rw-r--r--sound/soc/kirkwood/kirkwood-dma.c15
-rw-r--r--sound/soc/kirkwood/kirkwood-i2s.c108
-rw-r--r--sound/soc/kirkwood/kirkwood-openrd.c2
-rw-r--r--sound/soc/kirkwood/kirkwood-t5325.c2
-rw-r--r--sound/soc/kirkwood/kirkwood.h4
-rw-r--r--sound/soc/mid-x86/mfld_machine.c10
-rw-r--r--sound/soc/mid-x86/sst_platform.c6
-rw-r--r--sound/soc/mxs/mxs-saif.c42
-rw-r--r--sound/soc/mxs/mxs-saif.h5
-rw-r--r--sound/soc/mxs/mxs-sgtl5000.c20
-rw-r--r--sound/soc/nuc900/nuc900-pcm.c9
-rw-r--r--sound/soc/omap/Kconfig4
-rw-r--r--sound/soc/omap/n810.c7
-rw-r--r--sound/soc/omap/omap-mcpdm.c12
-rw-r--r--sound/soc/omap/omap-pcm.c11
-rw-r--r--sound/soc/omap/omap-twl4030.c5
-rw-r--r--sound/soc/pxa/brownstone.c1
-rw-r--r--sound/soc/pxa/corgi.c1
-rw-r--r--sound/soc/pxa/e740_wm9705.c1
-rw-r--r--sound/soc/pxa/e750_wm9705.c1
-rw-r--r--sound/soc/pxa/e800_wm9712.c1
-rw-r--r--sound/soc/pxa/imote2.c1
-rw-r--r--sound/soc/pxa/mioa701_wm9713.c1
-rw-r--r--sound/soc/pxa/mmp-pcm.c3
-rw-r--r--sound/soc/pxa/mmp-sspa.c5
-rw-r--r--sound/soc/pxa/palm27x.c1
-rw-r--r--sound/soc/pxa/poodle.c1
-rw-r--r--sound/soc/pxa/pxa2xx-ac97.c56
-rw-r--r--sound/soc/pxa/pxa2xx-i2s.c3
-rw-r--r--sound/soc/pxa/pxa2xx-pcm.c11
-rw-r--r--sound/soc/pxa/tosa.c1
-rw-r--r--sound/soc/pxa/ttc-dkb.c1
-rw-r--r--sound/soc/s6000/s6000-pcm.c12
-rw-r--r--sound/soc/samsung/Kconfig2
-rw-r--r--sound/soc/samsung/ac97.c6
-rw-r--r--sound/soc/samsung/bells.c1
-rw-r--r--sound/soc/samsung/dma.c11
-rw-r--r--sound/soc/samsung/i2s.c25
-rw-r--r--sound/soc/samsung/idma.c11
-rw-r--r--sound/soc/samsung/s3c-i2s-v2.c6
-rw-r--r--sound/soc/samsung/smdk_wm8994.c14
-rw-r--r--sound/soc/sh/Kconfig1
-rw-r--r--sound/soc/sh/rcar/adg.c11
-rw-r--r--sound/soc/sh/rcar/core.c81
-rw-r--r--sound/soc/sh/rcar/gen.c261
-rw-r--r--sound/soc/sh/rcar/rsnd.h9
-rw-r--r--sound/soc/sh/rcar/scu.c15
-rw-r--r--sound/soc/sh/rcar/ssi.c55
-rw-r--r--sound/soc/sh/siu_dai.c3
-rw-r--r--sound/soc/soc-cache.c269
-rw-r--r--sound/soc/soc-core.c377
-rw-r--r--sound/soc/soc-dapm.c144
-rw-r--r--sound/soc/soc-devres.c86
-rw-r--r--sound/soc/soc-generic-dmaengine-pcm.c107
-rw-r--r--sound/soc/soc-io.c26
-rw-r--r--sound/soc/soc-jack.c7
-rw-r--r--sound/soc/soc-pcm.c71
-rw-r--r--sound/soc/soc-utils.c6
-rw-r--r--sound/soc/spear/spdif_in.c12
-rw-r--r--sound/soc/spear/spdif_out.c14
-rw-r--r--sound/soc/tegra/tegra20_i2s.c6
-rw-r--r--sound/soc/tegra/tegra20_spdif.c6
-rw-r--r--sound/soc/tegra/tegra30_ahub.c119
-rw-r--r--sound/soc/tegra/tegra30_ahub.h38
-rw-r--r--sound/soc/tegra/tegra30_i2s.c55
-rw-r--r--sound/soc/tegra/tegra30_i2s.h7
-rw-r--r--sound/soc/tegra/tegra_asoc_utils.c2
-rw-r--r--sound/soc/tegra/tegra_asoc_utils.h1
-rw-r--r--sound/soc/tegra/tegra_pcm.c1
-rw-r--r--sound/soc/txx9/txx9aclc.c9
-rw-r--r--sound/sound_core.c17
-rw-r--r--sound/sparc/cs4231.c13
-rw-r--r--sound/usb/6fire/chip.c2
-rw-r--r--sound/usb/caiaq/control.c92
-rw-r--r--sound/usb/caiaq/device.c25
-rw-r--r--sound/usb/caiaq/device.h5
-rw-r--r--sound/usb/card.c22
-rw-r--r--sound/usb/card.h12
-rw-r--r--sound/usb/endpoint.c139
-rw-r--r--sound/usb/endpoint.h4
-rw-r--r--sound/usb/helper.c1
-rw-r--r--sound/usb/mixer.c4
-rw-r--r--sound/usb/mixer_quirks.c90
-rw-r--r--sound/usb/pcm.c40
-rw-r--r--sound/usb/stream.c33
-rw-r--r--sound/usb/usbaudio.h1
-rw-r--r--sound/usb/usx2y/us122l.c4
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c22
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c7
261 files changed, 8725 insertions, 4075 deletions
diff --git a/sound/aoa/core/gpio-feature.c b/sound/aoa/core/gpio-feature.c
index faa317490545..f34153962d07 100644
--- a/sound/aoa/core/gpio-feature.c
+++ b/sound/aoa/core/gpio-feature.c
@@ -10,8 +10,9 @@
10 * registers. 10 * registers.
11 */ 11 */
12 12
13#include <asm/pmac_feature.h> 13#include <linux/of_irq.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <asm/pmac_feature.h>
15#include "../aoa.h" 16#include "../aoa.h"
16 17
17/* TODO: these are lots of global variables 18/* TODO: these are lots of global variables
diff --git a/sound/aoa/fabrics/layout.c b/sound/aoa/fabrics/layout.c
index 61ab640e195f..9dc5806d23dd 100644
--- a/sound/aoa/fabrics/layout.c
+++ b/sound/aoa/fabrics/layout.c
@@ -644,7 +644,7 @@ static int n##_control_put(struct snd_kcontrol *kcontrol, \
644 struct snd_ctl_elem_value *ucontrol) \ 644 struct snd_ctl_elem_value *ucontrol) \
645{ \ 645{ \
646 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \ 646 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
647 if (gpio->methods && gpio->methods->get_##n) \ 647 if (gpio->methods && gpio->methods->set_##n) \
648 gpio->methods->set_##n(gpio, \ 648 gpio->methods->set_##n(gpio, \
649 !!ucontrol->value.integer.value[0]); \ 649 !!ucontrol->value.integer.value[0]); \
650 return 1; \ 650 return 1; \
@@ -1135,7 +1135,7 @@ static int aoa_fabric_layout_resume(struct soundbus_dev *sdev)
1135{ 1135{
1136 struct layout_dev *ldev = dev_get_drvdata(&sdev->ofdev.dev); 1136 struct layout_dev *ldev = dev_get_drvdata(&sdev->ofdev.dev);
1137 1137
1138 if (ldev->gpio.methods && ldev->gpio.methods->all_amps_off) 1138 if (ldev->gpio.methods && ldev->gpio.methods->all_amps_restore)
1139 ldev->gpio.methods->all_amps_restore(&ldev->gpio); 1139 ldev->gpio.methods->all_amps_restore(&ldev->gpio);
1140 1140
1141 return 0; 1141 return 0;
diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
index 15e76131b501..467836057ee5 100644
--- a/sound/aoa/soundbus/i2sbus/core.c
+++ b/sound/aoa/soundbus/i2sbus/core.c
@@ -11,6 +11,8 @@
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/dma-mapping.h> 13#include <linux/dma-mapping.h>
14#include <linux/of_address.h>
15#include <linux/of_irq.h>
14 16
15#include <sound/core.h> 17#include <sound/core.h>
16 18
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c
index e6f4633b8dd5..66de90ed30ca 100644
--- a/sound/arm/pxa2xx-ac97-lib.c
+++ b/sound/arm/pxa2xx-ac97-lib.c
@@ -117,8 +117,7 @@ static inline void pxa_ac97_warm_pxa25x(void)
117{ 117{
118 gsr_bits = 0; 118 gsr_bits = 0;
119 119
120 GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN; 120 GCR |= GCR_WARM_RST;
121 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
122} 121}
123 122
124static inline void pxa_ac97_cold_pxa25x(void) 123static inline void pxa_ac97_cold_pxa25x(void)
@@ -129,8 +128,6 @@ static inline void pxa_ac97_cold_pxa25x(void)
129 gsr_bits = 0; 128 gsr_bits = 0;
130 129
131 GCR = GCR_COLD_RST; 130 GCR = GCR_COLD_RST;
132 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
133 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
134} 131}
135#endif 132#endif
136 133
@@ -149,8 +146,6 @@ static inline void pxa_ac97_warm_pxa27x(void)
149 146
150static inline void pxa_ac97_cold_pxa27x(void) 147static inline void pxa_ac97_cold_pxa27x(void)
151{ 148{
152 unsigned int timeout;
153
154 GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 149 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
155 GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 150 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
156 151
@@ -161,29 +156,20 @@ static inline void pxa_ac97_cold_pxa27x(void)
161 udelay(5); 156 udelay(5);
162 clk_disable(ac97conf_clk); 157 clk_disable(ac97conf_clk);
163 GCR = GCR_COLD_RST | GCR_WARM_RST; 158 GCR = GCR_COLD_RST | GCR_WARM_RST;
164 timeout = 100; /* wait for the codec-ready bit to be set */
165 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
166 mdelay(1);
167} 159}
168#endif 160#endif
169 161
170#ifdef CONFIG_PXA3xx 162#ifdef CONFIG_PXA3xx
171static inline void pxa_ac97_warm_pxa3xx(void) 163static inline void pxa_ac97_warm_pxa3xx(void)
172{ 164{
173 int timeout = 100;
174
175 gsr_bits = 0; 165 gsr_bits = 0;
176 166
177 /* Can't use interrupts */ 167 /* Can't use interrupts */
178 GCR |= GCR_WARM_RST; 168 GCR |= GCR_WARM_RST;
179 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
180 mdelay(1);
181} 169}
182 170
183static inline void pxa_ac97_cold_pxa3xx(void) 171static inline void pxa_ac97_cold_pxa3xx(void)
184{ 172{
185 int timeout = 1000;
186
187 /* Hold CLKBPB for 100us */ 173 /* Hold CLKBPB for 100us */
188 GCR = 0; 174 GCR = 0;
189 GCR = GCR_CLKBPB; 175 GCR = GCR_CLKBPB;
@@ -199,14 +185,13 @@ static inline void pxa_ac97_cold_pxa3xx(void)
199 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 185 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
200 186
201 GCR = GCR_WARM_RST | GCR_COLD_RST; 187 GCR = GCR_WARM_RST | GCR_COLD_RST;
202 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
203 mdelay(10);
204} 188}
205#endif 189#endif
206 190
207bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97) 191bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97)
208{ 192{
209 unsigned long gsr; 193 unsigned long gsr;
194 unsigned int timeout = 100;
210 195
211#ifdef CONFIG_PXA25x 196#ifdef CONFIG_PXA25x
212 if (cpu_is_pxa25x()) 197 if (cpu_is_pxa25x())
@@ -223,7 +208,11 @@ bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97)
223 pxa_ac97_warm_pxa3xx(); 208 pxa_ac97_warm_pxa3xx();
224 else 209 else
225#endif 210#endif
226 BUG(); 211 snd_BUG();
212
213 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
214 mdelay(1);
215
227 gsr = GSR | gsr_bits; 216 gsr = GSR | gsr_bits;
228 if (!(gsr & (GSR_PCR | GSR_SCR))) { 217 if (!(gsr & (GSR_PCR | GSR_SCR))) {
229 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", 218 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
@@ -239,6 +228,7 @@ EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset);
239bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97) 228bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
240{ 229{
241 unsigned long gsr; 230 unsigned long gsr;
231 unsigned int timeout = 1000;
242 232
243#ifdef CONFIG_PXA25x 233#ifdef CONFIG_PXA25x
244 if (cpu_is_pxa25x()) 234 if (cpu_is_pxa25x())
@@ -255,7 +245,10 @@ bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
255 pxa_ac97_cold_pxa3xx(); 245 pxa_ac97_cold_pxa3xx();
256 else 246 else
257#endif 247#endif
258 BUG(); 248 snd_BUG();
249
250 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
251 mdelay(1);
259 252
260 gsr = GSR | gsr_bits; 253 gsr = GSR | gsr_bits;
261 if (!(gsr & (GSR_PCR | GSR_SCR))) { 254 if (!(gsr & (GSR_PCR | GSR_SCR))) {
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index 5066a3768b28..9a2ac1e0f77a 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -185,7 +185,7 @@ static int pxa2xx_ac97_probe(struct platform_device *dev)
185 goto err; 185 goto err;
186 186
187 card->dev = &dev->dev; 187 card->dev = &dev->dev;
188 strncpy(card->driver, dev->dev.driver->name, sizeof(card->driver)); 188 strlcpy(card->driver, dev->dev.driver->name, sizeof(card->driver));
189 189
190 ret = pxa2xx_pcm_new(card, &pxa2xx_ac97_pcm_client, &pxa2xx_ac97_pcm); 190 ret = pxa2xx_pcm_new(card, &pxa2xx_ac97_pcm_client, &pxa2xx_ac97_pcm);
191 if (ret) 191 if (ret)
diff --git a/sound/arm/pxa2xx-pcm.c b/sound/arm/pxa2xx-pcm.c
index 69a2455b4472..e6c727b317fb 100644
--- a/sound/arm/pxa2xx-pcm.c
+++ b/sound/arm/pxa2xx-pcm.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/dma-mapping.h>
14#include <linux/dmaengine.h> 15#include <linux/dmaengine.h>
15 16
16#include <sound/core.h> 17#include <sound/core.h>
@@ -83,8 +84,6 @@ static struct snd_pcm_ops pxa2xx_pcm_ops = {
83 .mmap = pxa2xx_pcm_mmap, 84 .mmap = pxa2xx_pcm_mmap,
84}; 85};
85 86
86static u64 pxa2xx_pcm_dmamask = 0xffffffff;
87
88int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client, 87int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
89 struct snd_pcm **rpcm) 88 struct snd_pcm **rpcm)
90{ 89{
@@ -100,10 +99,9 @@ int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
100 pcm->private_data = client; 99 pcm->private_data = client;
101 pcm->private_free = pxa2xx_pcm_free_dma_buffers; 100 pcm->private_free = pxa2xx_pcm_free_dma_buffers;
102 101
103 if (!card->dev->dma_mask) 102 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
104 card->dev->dma_mask = &pxa2xx_pcm_dmamask; 103 if (ret)
105 if (!card->dev->coherent_dma_mask) 104 goto out;
106 card->dev->coherent_dma_mask = 0xffffffff;
107 105
108 if (play) { 106 if (play) {
109 int stream = SNDRV_PCM_STREAM_PLAYBACK; 107 int stream = SNDRV_PCM_STREAM_PLAYBACK;
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
index ae63d22c0f88..c5f0ddd729b3 100644
--- a/sound/atmel/ac97c.c
+++ b/sound/atmel/ac97c.c
@@ -34,7 +34,6 @@
34#include <linux/dw_dmac.h> 34#include <linux/dw_dmac.h>
35 35
36#include <mach/cpu.h> 36#include <mach/cpu.h>
37#include <mach/gpio.h>
38 37
39#ifdef CONFIG_ARCH_AT91 38#ifdef CONFIG_ARCH_AT91
40#include <mach/hardware.h> 39#include <mach/hardware.h>
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index bea523a5d852..9d518ac73eea 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -384,8 +384,7 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
384 return -EFAULT; 384 return -EFAULT;
385 385
386 mutex_lock(&stream->device->lock); 386 mutex_lock(&stream->device->lock);
387 if (stream->runtime->state == SNDRV_PCM_STATE_PAUSED || 387 if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
388 stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
389 retval = -EBADFD; 388 retval = -EBADFD;
390 goto out; 389 goto out;
391 } 390 }
@@ -680,14 +679,48 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
680 return -EPERM; 679 return -EPERM;
681 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); 680 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP);
682 if (!retval) { 681 if (!retval) {
683 stream->runtime->state = SNDRV_PCM_STATE_SETUP; 682 snd_compr_drain_notify(stream);
684 wake_up(&stream->runtime->sleep);
685 stream->runtime->total_bytes_available = 0; 683 stream->runtime->total_bytes_available = 0;
686 stream->runtime->total_bytes_transferred = 0; 684 stream->runtime->total_bytes_transferred = 0;
687 } 685 }
688 return retval; 686 return retval;
689} 687}
690 688
689static int snd_compress_wait_for_drain(struct snd_compr_stream *stream)
690{
691 int ret;
692
693 /*
694 * We are called with lock held. So drop the lock while we wait for
695 * drain complete notfication from the driver
696 *
697 * It is expected that driver will notify the drain completion and then
698 * stream will be moved to SETUP state, even if draining resulted in an
699 * error. We can trigger next track after this.
700 */
701 stream->runtime->state = SNDRV_PCM_STATE_DRAINING;
702 mutex_unlock(&stream->device->lock);
703
704 /* we wait for drain to complete here, drain can return when
705 * interruption occurred, wait returned error or success.
706 * For the first two cases we don't do anything different here and
707 * return after waking up
708 */
709
710 ret = wait_event_interruptible(stream->runtime->sleep,
711 (stream->runtime->state != SNDRV_PCM_STATE_DRAINING));
712 if (ret == -ERESTARTSYS)
713 pr_debug("wait aborted by a signal");
714 else if (ret)
715 pr_debug("wait for drain failed with %d\n", ret);
716
717
718 wake_up(&stream->runtime->sleep);
719 mutex_lock(&stream->device->lock);
720
721 return ret;
722}
723
691static int snd_compr_drain(struct snd_compr_stream *stream) 724static int snd_compr_drain(struct snd_compr_stream *stream)
692{ 725{
693 int retval; 726 int retval;
@@ -695,12 +728,15 @@ static int snd_compr_drain(struct snd_compr_stream *stream)
695 if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || 728 if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
696 stream->runtime->state == SNDRV_PCM_STATE_SETUP) 729 stream->runtime->state == SNDRV_PCM_STATE_SETUP)
697 return -EPERM; 730 return -EPERM;
731
698 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); 732 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN);
699 if (!retval) { 733 if (retval) {
700 stream->runtime->state = SNDRV_PCM_STATE_DRAINING; 734 pr_debug("SND_COMPR_TRIGGER_DRAIN failed %d\n", retval);
701 wake_up(&stream->runtime->sleep); 735 wake_up(&stream->runtime->sleep);
736 return retval;
702 } 737 }
703 return retval; 738
739 return snd_compress_wait_for_drain(stream);
704} 740}
705 741
706static int snd_compr_next_track(struct snd_compr_stream *stream) 742static int snd_compr_next_track(struct snd_compr_stream *stream)
@@ -736,9 +772,14 @@ static int snd_compr_partial_drain(struct snd_compr_stream *stream)
736 return -EPERM; 772 return -EPERM;
737 773
738 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN); 774 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN);
775 if (retval) {
776 pr_debug("Partial drain returned failure\n");
777 wake_up(&stream->runtime->sleep);
778 return retval;
779 }
739 780
740 stream->next_track = false; 781 stream->next_track = false;
741 return retval; 782 return snd_compress_wait_for_drain(stream);
742} 783}
743 784
744static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 785static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
diff --git a/sound/core/init.c b/sound/core/init.c
index 6b9087115da2..1351f22f651c 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -66,7 +66,7 @@ static int module_slot_match(struct module *module, int idx)
66#ifdef MODULE 66#ifdef MODULE
67 const char *s1, *s2; 67 const char *s1, *s2;
68 68
69 if (!module || !module->name || !slots[idx]) 69 if (!module || !*module->name || !slots[idx])
70 return 0; 70 return 0;
71 71
72 s1 = module->name; 72 s1 = module->name;
@@ -597,7 +597,7 @@ static void snd_card_set_id_no_lock(struct snd_card *card, const char *src,
597 /* last resort... */ 597 /* last resort... */
598 snd_printk(KERN_ERR "unable to set card id (%s)\n", id); 598 snd_printk(KERN_ERR "unable to set card id (%s)\n", id);
599 if (card->proc_root->name) 599 if (card->proc_root->name)
600 strcpy(card->id, card->proc_root->name); 600 strlcpy(card->id, card->proc_root->name, sizeof(card->id));
601} 601}
602 602
603/** 603/**
diff --git a/sound/core/jack.c b/sound/core/jack.c
index b35fe7345c20..8658578eb584 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -34,12 +34,12 @@ static int jack_switch_types[SND_JACK_SWITCH_TYPES] = {
34 SW_LINEIN_INSERT, 34 SW_LINEIN_INSERT,
35}; 35};
36 36
37static int snd_jack_dev_free(struct snd_device *device) 37static int snd_jack_dev_disconnect(struct snd_device *device)
38{ 38{
39 struct snd_jack *jack = device->device_data; 39 struct snd_jack *jack = device->device_data;
40 40
41 if (jack->private_free) 41 if (!jack->input_dev)
42 jack->private_free(jack); 42 return 0;
43 43
44 /* If the input device is registered with the input subsystem 44 /* If the input device is registered with the input subsystem
45 * then we need to use a different deallocator. */ 45 * then we need to use a different deallocator. */
@@ -47,6 +47,18 @@ static int snd_jack_dev_free(struct snd_device *device)
47 input_unregister_device(jack->input_dev); 47 input_unregister_device(jack->input_dev);
48 else 48 else
49 input_free_device(jack->input_dev); 49 input_free_device(jack->input_dev);
50 jack->input_dev = NULL;
51 return 0;
52}
53
54static int snd_jack_dev_free(struct snd_device *device)
55{
56 struct snd_jack *jack = device->device_data;
57
58 if (jack->private_free)
59 jack->private_free(jack);
60
61 snd_jack_dev_disconnect(device);
50 62
51 kfree(jack->id); 63 kfree(jack->id);
52 kfree(jack); 64 kfree(jack);
@@ -110,6 +122,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
110 static struct snd_device_ops ops = { 122 static struct snd_device_ops ops = {
111 .dev_free = snd_jack_dev_free, 123 .dev_free = snd_jack_dev_free,
112 .dev_register = snd_jack_dev_register, 124 .dev_register = snd_jack_dev_register,
125 .dev_disconnect = snd_jack_dev_disconnect,
113 }; 126 };
114 127
115 jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL); 128 jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index bdf826f4fe0c..5e1c7bc73b29 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -30,6 +30,7 @@
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
33#include <linux/genalloc.h>
33#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
34#include <linux/mutex.h> 35#include <linux/mutex.h>
35#include <sound/memalloc.h> 36#include <sound/memalloc.h>
@@ -157,6 +158,47 @@ static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
157 dec_snd_pages(pg); 158 dec_snd_pages(pg);
158 dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma); 159 dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
159} 160}
161
162#ifdef CONFIG_GENERIC_ALLOCATOR
163/**
164 * snd_malloc_dev_iram - allocate memory from on-chip internal ram
165 * @dmab: buffer allocation record to store the allocated data
166 * @size: number of bytes to allocate from the iram
167 *
168 * This function requires iram phandle provided via of_node
169 */
170static void snd_malloc_dev_iram(struct snd_dma_buffer *dmab, size_t size)
171{
172 struct device *dev = dmab->dev.dev;
173 struct gen_pool *pool = NULL;
174
175 dmab->area = NULL;
176 dmab->addr = 0;
177
178 if (dev->of_node)
179 pool = of_get_named_gen_pool(dev->of_node, "iram", 0);
180
181 if (!pool)
182 return;
183
184 /* Assign the pool into private_data field */
185 dmab->private_data = pool;
186
187 dmab->area = gen_pool_dma_alloc(pool, size, &dmab->addr);
188}
189
190/**
191 * snd_free_dev_iram - free allocated specific memory from on-chip internal ram
192 * @dmab: buffer allocation record to store the allocated data
193 */
194static void snd_free_dev_iram(struct snd_dma_buffer *dmab)
195{
196 struct gen_pool *pool = dmab->private_data;
197
198 if (pool && dmab->area)
199 gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes);
200}
201#endif /* CONFIG_GENERIC_ALLOCATOR */
160#endif /* CONFIG_HAS_DMA */ 202#endif /* CONFIG_HAS_DMA */
161 203
162/* 204/*
@@ -197,6 +239,16 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
197 dmab->addr = 0; 239 dmab->addr = 0;
198 break; 240 break;
199#ifdef CONFIG_HAS_DMA 241#ifdef CONFIG_HAS_DMA
242#ifdef CONFIG_GENERIC_ALLOCATOR
243 case SNDRV_DMA_TYPE_DEV_IRAM:
244 snd_malloc_dev_iram(dmab, size);
245 if (dmab->area)
246 break;
247 /* Internal memory might have limited size and no enough space,
248 * so if we fail to malloc, try to fetch memory traditionally.
249 */
250 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
251#endif /* CONFIG_GENERIC_ALLOCATOR */
200 case SNDRV_DMA_TYPE_DEV: 252 case SNDRV_DMA_TYPE_DEV:
201 dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr); 253 dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
202 break; 254 break;
@@ -269,6 +321,11 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
269 snd_free_pages(dmab->area, dmab->bytes); 321 snd_free_pages(dmab->area, dmab->bytes);
270 break; 322 break;
271#ifdef CONFIG_HAS_DMA 323#ifdef CONFIG_HAS_DMA
324#ifdef CONFIG_GENERIC_ALLOCATOR
325 case SNDRV_DMA_TYPE_DEV_IRAM:
326 snd_free_dev_iram(dmab);
327 break;
328#endif /* CONFIG_GENERIC_ALLOCATOR */
272 case SNDRV_DMA_TYPE_DEV: 329 case SNDRV_DMA_TYPE_DEV:
273 snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); 330 snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
274 break; 331 break;
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 17f45e8aa89c..e1e9e0c999fe 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -49,6 +49,8 @@ static struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
49 struct snd_pcm *pcm; 49 struct snd_pcm *pcm;
50 50
51 list_for_each_entry(pcm, &snd_pcm_devices, list) { 51 list_for_each_entry(pcm, &snd_pcm_devices, list) {
52 if (pcm->internal)
53 continue;
52 if (pcm->card == card && pcm->device == device) 54 if (pcm->card == card && pcm->device == device)
53 return pcm; 55 return pcm;
54 } 56 }
@@ -60,6 +62,8 @@ static int snd_pcm_next(struct snd_card *card, int device)
60 struct snd_pcm *pcm; 62 struct snd_pcm *pcm;
61 63
62 list_for_each_entry(pcm, &snd_pcm_devices, list) { 64 list_for_each_entry(pcm, &snd_pcm_devices, list) {
65 if (pcm->internal)
66 continue;
63 if (pcm->card == card && pcm->device > device) 67 if (pcm->card == card && pcm->device > device)
64 return pcm->device; 68 return pcm->device;
65 else if (pcm->card->number > card->number) 69 else if (pcm->card->number > card->number)
diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
index aa924d9b7986..94d08733cb38 100644
--- a/sound/core/pcm_dmaengine.c
+++ b/sound/core/pcm_dmaengine.c
@@ -63,23 +63,19 @@ int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream,
63 struct dma_slave_config *slave_config) 63 struct dma_slave_config *slave_config)
64{ 64{
65 enum dma_slave_buswidth buswidth; 65 enum dma_slave_buswidth buswidth;
66 int bits;
66 67
67 switch (params_format(params)) { 68 bits = snd_pcm_format_physical_width(params_format(params));
68 case SNDRV_PCM_FORMAT_S8: 69 if (bits < 8 || bits > 64)
70 return -EINVAL;
71 else if (bits == 8)
69 buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE; 72 buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
70 break; 73 else if (bits == 16)
71 case SNDRV_PCM_FORMAT_S16_LE:
72 buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES; 74 buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
73 break; 75 else if (bits <= 32)
74 case SNDRV_PCM_FORMAT_S18_3LE:
75 case SNDRV_PCM_FORMAT_S20_3LE:
76 case SNDRV_PCM_FORMAT_S24_LE:
77 case SNDRV_PCM_FORMAT_S32_LE:
78 buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; 76 buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
79 break; 77 else
80 default: 78 buswidth = DMA_SLAVE_BUSWIDTH_8_BYTES;
81 return -EINVAL;
82 }
83 79
84 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 80 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
85 slave_config->direction = DMA_MEM_TO_DEV; 81 slave_config->direction = DMA_MEM_TO_DEV;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index a68d4c6d702c..01a5e05ede95 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -2428,6 +2428,7 @@ static int snd_pcm_hwsync(struct snd_pcm_substream *substream)
2428 case SNDRV_PCM_STATE_DRAINING: 2428 case SNDRV_PCM_STATE_DRAINING:
2429 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) 2429 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
2430 goto __badfd; 2430 goto __badfd;
2431 /* Fall through */
2431 case SNDRV_PCM_STATE_RUNNING: 2432 case SNDRV_PCM_STATE_RUNNING:
2432 if ((err = snd_pcm_update_hw_ptr(substream)) < 0) 2433 if ((err = snd_pcm_update_hw_ptr(substream)) < 0)
2433 break; 2434 break;
@@ -2460,6 +2461,7 @@ static int snd_pcm_delay(struct snd_pcm_substream *substream,
2460 case SNDRV_PCM_STATE_DRAINING: 2461 case SNDRV_PCM_STATE_DRAINING:
2461 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) 2462 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
2462 goto __badfd; 2463 goto __badfd;
2464 /* Fall through */
2463 case SNDRV_PCM_STATE_RUNNING: 2465 case SNDRV_PCM_STATE_RUNNING:
2464 if ((err = snd_pcm_update_hw_ptr(substream)) < 0) 2466 if ((err = snd_pcm_update_hw_ptr(substream)) < 0)
2465 break; 2467 break;
@@ -3199,6 +3201,14 @@ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
3199 struct vm_area_struct *area) 3201 struct vm_area_struct *area)
3200{ 3202{
3201 area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; 3203 area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
3204#ifdef CONFIG_GENERIC_ALLOCATOR
3205 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_IRAM) {
3206 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
3207 return remap_pfn_range(area, area->vm_start,
3208 substream->dma_buffer.addr >> PAGE_SHIFT,
3209 area->vm_end - area->vm_start, area->vm_page_prot);
3210 }
3211#endif /* CONFIG_GENERIC_ALLOCATOR */
3202#ifdef ARCH_HAS_DMA_MMAP_COHERENT 3212#ifdef ARCH_HAS_DMA_MMAP_COHERENT
3203 if (!substream->ops->page && 3213 if (!substream->ops->page &&
3204 substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV) 3214 substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV)
diff --git a/sound/core/sound.c b/sound/core/sound.c
index f002bd911dae..437c25ea6403 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -153,7 +153,7 @@ static int snd_open(struct inode *inode, struct file *file)
153{ 153{
154 unsigned int minor = iminor(inode); 154 unsigned int minor = iminor(inode);
155 struct snd_minor *mptr = NULL; 155 struct snd_minor *mptr = NULL;
156 const struct file_operations *old_fops; 156 const struct file_operations *new_fops;
157 int err = 0; 157 int err = 0;
158 158
159 if (minor >= ARRAY_SIZE(snd_minors)) 159 if (minor >= ARRAY_SIZE(snd_minors))
@@ -167,24 +167,14 @@ static int snd_open(struct inode *inode, struct file *file)
167 return -ENODEV; 167 return -ENODEV;
168 } 168 }
169 } 169 }
170 old_fops = file->f_op; 170 new_fops = fops_get(mptr->f_ops);
171 file->f_op = fops_get(mptr->f_ops);
172 if (file->f_op == NULL) {
173 file->f_op = old_fops;
174 err = -ENODEV;
175 }
176 mutex_unlock(&sound_mutex); 171 mutex_unlock(&sound_mutex);
177 if (err < 0) 172 if (!new_fops)
178 return err; 173 return -ENODEV;
174 replace_fops(file, new_fops);
179 175
180 if (file->f_op->open) { 176 if (file->f_op->open)
181 err = file->f_op->open(inode, file); 177 err = file->f_op->open(inode, file);
182 if (err) {
183 fops_put(file->f_op);
184 file->f_op = fops_get(old_fops);
185 }
186 }
187 fops_put(old_fops);
188 return err; 178 return err;
189} 179}
190 180
diff --git a/sound/drivers/opl3/opl3_midi.c b/sound/drivers/opl3/opl3_midi.c
index 0c796bcbc0a3..6c6d09a51f42 100644
--- a/sound/drivers/opl3/opl3_midi.c
+++ b/sound/drivers/opl3/opl3_midi.c
@@ -390,6 +390,11 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
390 voice = snd_opl3_oss_map[chan->number]; 390 voice = snd_opl3_oss_map[chan->number];
391 } 391 }
392 392
393 if (voice < 0) {
394 spin_unlock_irqrestore(&opl3->voice_lock, flags);
395 return;
396 }
397
393 if (voice < MAX_OPL2_VOICES) { 398 if (voice < MAX_OPL2_VOICES) {
394 /* Left register block for voices 0 .. 8 */ 399 /* Left register block for voices 0 .. 8 */
395 reg_side = OPL3_LEFT; 400 reg_side = OPL3_LEFT;
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index 1c19cd7ad26e..328bd29264ce 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -46,8 +46,9 @@ static int snd_pcsp_create(struct snd_card *card)
46 int err; 46 int err;
47 int div, min_div, order; 47 int div, min_div, order;
48 48
49 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
50
49 if (!nopcm) { 51 if (!nopcm) {
50 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
51 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) { 52 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) {
52 printk(KERN_ERR "PCSP: Timer resolution is not sufficient " 53 printk(KERN_ERR "PCSP: Timer resolution is not sufficient "
53 "(%linS)\n", tp.tv_nsec); 54 "(%linS)\n", tp.tv_nsec);
@@ -187,8 +188,8 @@ static int pcsp_probe(struct platform_device *dev)
187static int pcsp_remove(struct platform_device *dev) 188static int pcsp_remove(struct platform_device *dev)
188{ 189{
189 struct snd_pcsp *chip = platform_get_drvdata(dev); 190 struct snd_pcsp *chip = platform_get_drvdata(dev);
190 alsa_card_pcsp_exit(chip);
191 pcspkr_input_remove(chip->input_dev); 191 pcspkr_input_remove(chip->input_dev);
192 alsa_card_pcsp_exit(chip);
192 return 0; 193 return 0;
193} 194}
194 195
diff --git a/sound/firewire/Kconfig b/sound/firewire/Kconfig
index ea063e1f8722..b3e274fe4a77 100644
--- a/sound/firewire/Kconfig
+++ b/sound/firewire/Kconfig
@@ -11,6 +11,21 @@ config SND_FIREWIRE_LIB
11 tristate 11 tristate
12 depends on SND_PCM 12 depends on SND_PCM
13 13
14config SND_DICE
15 tristate "DICE-based DACs (EXPERIMENTAL)"
16 select SND_HWDEP
17 select SND_PCM
18 select SND_FIREWIRE_LIB
19 help
20 Say Y here to include support for many DACs based on the DICE
21 chip family (DICE-II/Jr/Mini) from TC Applied Technologies.
22
23 At the moment, this driver supports playback only. If you
24 want to use devices that support capturing, use FFADO instead.
25
26 To compile this driver as a module, choose M here: the module
27 will be called snd-dice.
28
14config SND_FIREWIRE_SPEAKERS 29config SND_FIREWIRE_SPEAKERS
15 tristate "FireWire speakers" 30 tristate "FireWire speakers"
16 select SND_PCM 31 select SND_PCM
diff --git a/sound/firewire/Makefile b/sound/firewire/Makefile
index 460179df5bb5..509955061d30 100644
--- a/sound/firewire/Makefile
+++ b/sound/firewire/Makefile
@@ -1,10 +1,12 @@
1snd-firewire-lib-objs := lib.o iso-resources.o packets-buffer.o \ 1snd-firewire-lib-objs := lib.o iso-resources.o packets-buffer.o \
2 fcp.o cmp.o amdtp.o 2 fcp.o cmp.o amdtp.o
3snd-dice-objs := dice.o
3snd-firewire-speakers-objs := speakers.o 4snd-firewire-speakers-objs := speakers.o
4snd-isight-objs := isight.o 5snd-isight-objs := isight.o
5snd-scs1x-objs := scs1x.o 6snd-scs1x-objs := scs1x.o
6 7
7obj-$(CONFIG_SND_FIREWIRE_LIB) += snd-firewire-lib.o 8obj-$(CONFIG_SND_FIREWIRE_LIB) += snd-firewire-lib.o
9obj-$(CONFIG_SND_DICE) += snd-dice.o
8obj-$(CONFIG_SND_FIREWIRE_SPEAKERS) += snd-firewire-speakers.o 10obj-$(CONFIG_SND_FIREWIRE_SPEAKERS) += snd-firewire-speakers.o
9obj-$(CONFIG_SND_ISIGHT) += snd-isight.o 11obj-$(CONFIG_SND_ISIGHT) += snd-isight.o
10obj-$(CONFIG_SND_SCS1X) += snd-scs1x.o 12obj-$(CONFIG_SND_SCS1X) += snd-scs1x.o
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index ea995af6d049..d3226892ad6b 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -42,9 +42,6 @@ static void pcm_period_tasklet(unsigned long data);
42int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit, 42int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
43 enum cip_out_flags flags) 43 enum cip_out_flags flags)
44{ 44{
45 if (flags != CIP_NONBLOCKING)
46 return -EINVAL;
47
48 s->unit = fw_unit_get(unit); 45 s->unit = fw_unit_get(unit);
49 s->flags = flags; 46 s->flags = flags;
50 s->context = ERR_PTR(-1); 47 s->context = ERR_PTR(-1);
@@ -62,73 +59,91 @@ EXPORT_SYMBOL(amdtp_out_stream_init);
62 */ 59 */
63void amdtp_out_stream_destroy(struct amdtp_out_stream *s) 60void amdtp_out_stream_destroy(struct amdtp_out_stream *s)
64{ 61{
65 WARN_ON(!IS_ERR(s->context)); 62 WARN_ON(amdtp_out_stream_running(s));
66 mutex_destroy(&s->mutex); 63 mutex_destroy(&s->mutex);
67 fw_unit_put(s->unit); 64 fw_unit_put(s->unit);
68} 65}
69EXPORT_SYMBOL(amdtp_out_stream_destroy); 66EXPORT_SYMBOL(amdtp_out_stream_destroy);
70 67
68const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = {
69 [CIP_SFC_32000] = 8,
70 [CIP_SFC_44100] = 8,
71 [CIP_SFC_48000] = 8,
72 [CIP_SFC_88200] = 16,
73 [CIP_SFC_96000] = 16,
74 [CIP_SFC_176400] = 32,
75 [CIP_SFC_192000] = 32,
76};
77EXPORT_SYMBOL(amdtp_syt_intervals);
78
71/** 79/**
72 * amdtp_out_stream_set_rate - set the sample rate 80 * amdtp_out_stream_set_parameters - set stream parameters
73 * @s: the AMDTP output stream to configure 81 * @s: the AMDTP output stream to configure
74 * @rate: the sample rate 82 * @rate: the sample rate
83 * @pcm_channels: the number of PCM samples in each data block, to be encoded
84 * as AM824 multi-bit linear audio
85 * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels)
75 * 86 *
76 * The sample rate must be set before the stream is started, and must not be 87 * The parameters must be set before the stream is started, and must not be
77 * changed while the stream is running. 88 * changed while the stream is running.
78 */ 89 */
79void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate) 90void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
91 unsigned int rate,
92 unsigned int pcm_channels,
93 unsigned int midi_ports)
80{ 94{
81 static const struct { 95 static const unsigned int rates[] = {
82 unsigned int rate; 96 [CIP_SFC_32000] = 32000,
83 unsigned int syt_interval; 97 [CIP_SFC_44100] = 44100,
84 } rate_info[] = { 98 [CIP_SFC_48000] = 48000,
85 [CIP_SFC_32000] = { 32000, 8, }, 99 [CIP_SFC_88200] = 88200,
86 [CIP_SFC_44100] = { 44100, 8, }, 100 [CIP_SFC_96000] = 96000,
87 [CIP_SFC_48000] = { 48000, 8, }, 101 [CIP_SFC_176400] = 176400,
88 [CIP_SFC_88200] = { 88200, 16, }, 102 [CIP_SFC_192000] = 192000,
89 [CIP_SFC_96000] = { 96000, 16, },
90 [CIP_SFC_176400] = { 176400, 32, },
91 [CIP_SFC_192000] = { 192000, 32, },
92 }; 103 };
93 unsigned int sfc; 104 unsigned int sfc;
94 105
95 if (WARN_ON(!IS_ERR(s->context))) 106 if (WARN_ON(amdtp_out_stream_running(s)))
96 return; 107 return;
97 108
98 for (sfc = 0; sfc < ARRAY_SIZE(rate_info); ++sfc) 109 for (sfc = 0; sfc < CIP_SFC_COUNT; ++sfc)
99 if (rate_info[sfc].rate == rate) { 110 if (rates[sfc] == rate)
100 s->sfc = sfc; 111 goto sfc_found;
101 s->syt_interval = rate_info[sfc].syt_interval;
102 return;
103 }
104 WARN_ON(1); 112 WARN_ON(1);
113 return;
114
115sfc_found:
116 s->dual_wire = (s->flags & CIP_HI_DUALWIRE) && sfc > CIP_SFC_96000;
117 if (s->dual_wire) {
118 sfc -= 2;
119 rate /= 2;
120 pcm_channels *= 2;
121 }
122 s->sfc = sfc;
123 s->data_block_quadlets = pcm_channels + DIV_ROUND_UP(midi_ports, 8);
124 s->pcm_channels = pcm_channels;
125 s->midi_ports = midi_ports;
126
127 s->syt_interval = amdtp_syt_intervals[sfc];
128
129 /* default buffering in the device */
130 s->transfer_delay = TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE;
131 if (s->flags & CIP_BLOCKING)
132 /* additional buffering needed to adjust for no-data packets */
133 s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate;
105} 134}
106EXPORT_SYMBOL(amdtp_out_stream_set_rate); 135EXPORT_SYMBOL(amdtp_out_stream_set_parameters);
107 136
108/** 137/**
109 * amdtp_out_stream_get_max_payload - get the stream's packet size 138 * amdtp_out_stream_get_max_payload - get the stream's packet size
110 * @s: the AMDTP output stream 139 * @s: the AMDTP output stream
111 * 140 *
112 * This function must not be called before the stream has been configured 141 * This function must not be called before the stream has been configured
113 * with amdtp_out_stream_set_hw_params(), amdtp_out_stream_set_pcm(), and 142 * with amdtp_out_stream_set_parameters().
114 * amdtp_out_stream_set_midi().
115 */ 143 */
116unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s) 144unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s)
117{ 145{
118 static const unsigned int max_data_blocks[] = { 146 return 8 + s->syt_interval * s->data_block_quadlets * 4;
119 [CIP_SFC_32000] = 4,
120 [CIP_SFC_44100] = 6,
121 [CIP_SFC_48000] = 6,
122 [CIP_SFC_88200] = 12,
123 [CIP_SFC_96000] = 12,
124 [CIP_SFC_176400] = 23,
125 [CIP_SFC_192000] = 24,
126 };
127
128 s->data_block_quadlets = s->pcm_channels;
129 s->data_block_quadlets += DIV_ROUND_UP(s->midi_ports, 8);
130
131 return 8 + max_data_blocks[s->sfc] * 4 * s->data_block_quadlets;
132} 147}
133EXPORT_SYMBOL(amdtp_out_stream_get_max_payload); 148EXPORT_SYMBOL(amdtp_out_stream_get_max_payload);
134 149
@@ -138,19 +153,26 @@ static void amdtp_write_s16(struct amdtp_out_stream *s,
138static void amdtp_write_s32(struct amdtp_out_stream *s, 153static void amdtp_write_s32(struct amdtp_out_stream *s,
139 struct snd_pcm_substream *pcm, 154 struct snd_pcm_substream *pcm,
140 __be32 *buffer, unsigned int frames); 155 __be32 *buffer, unsigned int frames);
156static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s,
157 struct snd_pcm_substream *pcm,
158 __be32 *buffer, unsigned int frames);
159static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s,
160 struct snd_pcm_substream *pcm,
161 __be32 *buffer, unsigned int frames);
141 162
142/** 163/**
143 * amdtp_out_stream_set_pcm_format - set the PCM format 164 * amdtp_out_stream_set_pcm_format - set the PCM format
144 * @s: the AMDTP output stream to configure 165 * @s: the AMDTP output stream to configure
145 * @format: the format of the ALSA PCM device 166 * @format: the format of the ALSA PCM device
146 * 167 *
147 * The sample format must be set before the stream is started, and must not be 168 * The sample format must be set after the other paramters (rate/PCM channels/
148 * changed while the stream is running. 169 * MIDI) and before the stream is started, and must not be changed while the
170 * stream is running.
149 */ 171 */
150void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s, 172void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
151 snd_pcm_format_t format) 173 snd_pcm_format_t format)
152{ 174{
153 if (WARN_ON(!IS_ERR(s->context))) 175 if (WARN_ON(amdtp_out_stream_running(s)))
154 return; 176 return;
155 177
156 switch (format) { 178 switch (format) {
@@ -158,10 +180,16 @@ void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
158 WARN_ON(1); 180 WARN_ON(1);
159 /* fall through */ 181 /* fall through */
160 case SNDRV_PCM_FORMAT_S16: 182 case SNDRV_PCM_FORMAT_S16:
161 s->transfer_samples = amdtp_write_s16; 183 if (s->dual_wire)
184 s->transfer_samples = amdtp_write_s16_dualwire;
185 else
186 s->transfer_samples = amdtp_write_s16;
162 break; 187 break;
163 case SNDRV_PCM_FORMAT_S32: 188 case SNDRV_PCM_FORMAT_S32:
164 s->transfer_samples = amdtp_write_s32; 189 if (s->dual_wire)
190 s->transfer_samples = amdtp_write_s32_dualwire;
191 else
192 s->transfer_samples = amdtp_write_s32;
165 break; 193 break;
166 } 194 }
167} 195}
@@ -248,7 +276,7 @@ static unsigned int calculate_syt(struct amdtp_out_stream *s,
248 s->last_syt_offset = syt_offset; 276 s->last_syt_offset = syt_offset;
249 277
250 if (syt_offset < TICKS_PER_CYCLE) { 278 if (syt_offset < TICKS_PER_CYCLE) {
251 syt_offset += TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE; 279 syt_offset += s->transfer_delay;
252 syt = (cycle + syt_offset / TICKS_PER_CYCLE) << 12; 280 syt = (cycle + syt_offset / TICKS_PER_CYCLE) << 12;
253 syt += syt_offset % TICKS_PER_CYCLE; 281 syt += syt_offset % TICKS_PER_CYCLE;
254 282
@@ -268,7 +296,7 @@ static void amdtp_write_s32(struct amdtp_out_stream *s,
268 296
269 channels = s->pcm_channels; 297 channels = s->pcm_channels;
270 src = (void *)runtime->dma_area + 298 src = (void *)runtime->dma_area +
271 s->pcm_buffer_pointer * (runtime->frame_bits / 8); 299 frames_to_bytes(runtime, s->pcm_buffer_pointer);
272 remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer; 300 remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
273 frame_step = s->data_block_quadlets - channels; 301 frame_step = s->data_block_quadlets - channels;
274 302
@@ -294,7 +322,7 @@ static void amdtp_write_s16(struct amdtp_out_stream *s,
294 322
295 channels = s->pcm_channels; 323 channels = s->pcm_channels;
296 src = (void *)runtime->dma_area + 324 src = (void *)runtime->dma_area +
297 s->pcm_buffer_pointer * (runtime->frame_bits / 8); 325 frames_to_bytes(runtime, s->pcm_buffer_pointer);
298 remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer; 326 remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
299 frame_step = s->data_block_quadlets - channels; 327 frame_step = s->data_block_quadlets - channels;
300 328
@@ -310,6 +338,68 @@ static void amdtp_write_s16(struct amdtp_out_stream *s,
310 } 338 }
311} 339}
312 340
341static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s,
342 struct snd_pcm_substream *pcm,
343 __be32 *buffer, unsigned int frames)
344{
345 struct snd_pcm_runtime *runtime = pcm->runtime;
346 unsigned int channels, frame_adjust_1, frame_adjust_2, i, c;
347 const u32 *src;
348
349 channels = s->pcm_channels;
350 src = (void *)runtime->dma_area +
351 s->pcm_buffer_pointer * (runtime->frame_bits / 8);
352 frame_adjust_1 = channels - 1;
353 frame_adjust_2 = 1 - (s->data_block_quadlets - channels);
354
355 channels /= 2;
356 for (i = 0; i < frames; ++i) {
357 for (c = 0; c < channels; ++c) {
358 *buffer = cpu_to_be32((*src >> 8) | 0x40000000);
359 src++;
360 buffer += 2;
361 }
362 buffer -= frame_adjust_1;
363 for (c = 0; c < channels; ++c) {
364 *buffer = cpu_to_be32((*src >> 8) | 0x40000000);
365 src++;
366 buffer += 2;
367 }
368 buffer -= frame_adjust_2;
369 }
370}
371
372static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s,
373 struct snd_pcm_substream *pcm,
374 __be32 *buffer, unsigned int frames)
375{
376 struct snd_pcm_runtime *runtime = pcm->runtime;
377 unsigned int channels, frame_adjust_1, frame_adjust_2, i, c;
378 const u16 *src;
379
380 channels = s->pcm_channels;
381 src = (void *)runtime->dma_area +
382 s->pcm_buffer_pointer * (runtime->frame_bits / 8);
383 frame_adjust_1 = channels - 1;
384 frame_adjust_2 = 1 - (s->data_block_quadlets - channels);
385
386 channels /= 2;
387 for (i = 0; i < frames; ++i) {
388 for (c = 0; c < channels; ++c) {
389 *buffer = cpu_to_be32((*src << 8) | 0x40000000);
390 src++;
391 buffer += 2;
392 }
393 buffer -= frame_adjust_1;
394 for (c = 0; c < channels; ++c) {
395 *buffer = cpu_to_be32((*src << 8) | 0x40000000);
396 src++;
397 buffer += 2;
398 }
399 buffer -= frame_adjust_2;
400 }
401}
402
313static void amdtp_fill_pcm_silence(struct amdtp_out_stream *s, 403static void amdtp_fill_pcm_silence(struct amdtp_out_stream *s,
314 __be32 *buffer, unsigned int frames) 404 __be32 *buffer, unsigned int frames)
315{ 405{
@@ -344,8 +434,17 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
344 return; 434 return;
345 index = s->packet_index; 435 index = s->packet_index;
346 436
347 data_blocks = calculate_data_blocks(s);
348 syt = calculate_syt(s, cycle); 437 syt = calculate_syt(s, cycle);
438 if (!(s->flags & CIP_BLOCKING)) {
439 data_blocks = calculate_data_blocks(s);
440 } else {
441 if (syt != 0xffff) {
442 data_blocks = s->syt_interval;
443 } else {
444 data_blocks = 0;
445 syt = 0xffffff;
446 }
447 }
349 448
350 buffer = s->buffer.packets[index].buffer; 449 buffer = s->buffer.packets[index].buffer;
351 buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) | 450 buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
@@ -386,6 +485,9 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
386 s->packet_index = index; 485 s->packet_index = index;
387 486
388 if (pcm) { 487 if (pcm) {
488 if (s->dual_wire)
489 data_blocks *= 2;
490
389 ptr = s->pcm_buffer_pointer + data_blocks; 491 ptr = s->pcm_buffer_pointer + data_blocks;
390 if (ptr >= pcm->runtime->buffer_size) 492 if (ptr >= pcm->runtime->buffer_size)
391 ptr -= pcm->runtime->buffer_size; 493 ptr -= pcm->runtime->buffer_size;
@@ -455,9 +557,8 @@ static int queue_initial_skip_packets(struct amdtp_out_stream *s)
455 * @speed: firewire speed code 557 * @speed: firewire speed code
456 * 558 *
457 * The stream cannot be started until it has been configured with 559 * The stream cannot be started until it has been configured with
458 * amdtp_out_stream_set_hw_params(), amdtp_out_stream_set_pcm(), and 560 * amdtp_out_stream_set_parameters() and amdtp_out_stream_set_pcm_format(),
459 * amdtp_out_stream_set_midi(); and it must be started before any 561 * and it must be started before any PCM or MIDI device can be started.
460 * PCM or MIDI device can be started.
461 */ 562 */
462int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed) 563int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
463{ 564{
@@ -477,7 +578,7 @@ int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
477 578
478 mutex_lock(&s->mutex); 579 mutex_lock(&s->mutex);
479 580
480 if (WARN_ON(!IS_ERR(s->context) || 581 if (WARN_ON(amdtp_out_stream_running(s) ||
481 (!s->pcm_channels && !s->midi_ports))) { 582 (!s->pcm_channels && !s->midi_ports))) {
482 err = -EBADFD; 583 err = -EBADFD;
483 goto err_unlock; 584 goto err_unlock;
@@ -573,7 +674,7 @@ void amdtp_out_stream_stop(struct amdtp_out_stream *s)
573{ 674{
574 mutex_lock(&s->mutex); 675 mutex_lock(&s->mutex);
575 676
576 if (IS_ERR(s->context)) { 677 if (!amdtp_out_stream_running(s)) {
577 mutex_unlock(&s->mutex); 678 mutex_unlock(&s->mutex);
578 return; 679 return;
579 } 680 }
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index f6103d68c4b1..839ebf812d79 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -1,6 +1,7 @@
1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED 1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED 2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED
3 3
4#include <linux/err.h>
4#include <linux/interrupt.h> 5#include <linux/interrupt.h>
5#include <linux/mutex.h> 6#include <linux/mutex.h>
6#include "packets-buffer.h" 7#include "packets-buffer.h"
@@ -11,9 +12,18 @@
11 * sample_rate/8000 samples, with rounding up or down to adjust 12 * sample_rate/8000 samples, with rounding up or down to adjust
12 * for clock skew and left-over fractional samples. This should 13 * for clock skew and left-over fractional samples. This should
13 * be used if supported by the device. 14 * be used if supported by the device.
15 * @CIP_BLOCKING: In blocking mode, each packet contains either zero or
16 * SYT_INTERVAL samples, with these two types alternating so that
17 * the overall sample rate comes out right.
18 * @CIP_HI_DUALWIRE: At rates above 96 kHz, pretend that the stream runs
19 * at half the actual sample rate with twice the number of channels;
20 * two samples of a channel are stored consecutively in the packet.
21 * Requires blocking mode and SYT_INTERVAL-aligned PCM buffer size.
14 */ 22 */
15enum cip_out_flags { 23enum cip_out_flags {
16 CIP_NONBLOCKING = 0, 24 CIP_NONBLOCKING = 0x00,
25 CIP_BLOCKING = 0x01,
26 CIP_HI_DUALWIRE = 0x02,
17}; 27};
18 28
19/** 29/**
@@ -27,6 +37,7 @@ enum cip_sfc {
27 CIP_SFC_96000 = 4, 37 CIP_SFC_96000 = 4,
28 CIP_SFC_176400 = 5, 38 CIP_SFC_176400 = 5,
29 CIP_SFC_192000 = 6, 39 CIP_SFC_192000 = 6,
40 CIP_SFC_COUNT
30}; 41};
31 42
32#define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \ 43#define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
@@ -43,6 +54,7 @@ struct amdtp_out_stream {
43 struct mutex mutex; 54 struct mutex mutex;
44 55
45 enum cip_sfc sfc; 56 enum cip_sfc sfc;
57 bool dual_wire;
46 unsigned int data_block_quadlets; 58 unsigned int data_block_quadlets;
47 unsigned int pcm_channels; 59 unsigned int pcm_channels;
48 unsigned int midi_ports; 60 unsigned int midi_ports;
@@ -51,6 +63,7 @@ struct amdtp_out_stream {
51 __be32 *buffer, unsigned int frames); 63 __be32 *buffer, unsigned int frames);
52 64
53 unsigned int syt_interval; 65 unsigned int syt_interval;
66 unsigned int transfer_delay;
54 unsigned int source_node_id_field; 67 unsigned int source_node_id_field;
55 struct iso_packets_buffer buffer; 68 struct iso_packets_buffer buffer;
56 69
@@ -74,7 +87,10 @@ int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
74 enum cip_out_flags flags); 87 enum cip_out_flags flags);
75void amdtp_out_stream_destroy(struct amdtp_out_stream *s); 88void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
76 89
77void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate); 90void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
91 unsigned int rate,
92 unsigned int pcm_channels,
93 unsigned int midi_ports);
78unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s); 94unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
79 95
80int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed); 96int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
@@ -87,31 +103,11 @@ void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
87unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s); 103unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
88void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s); 104void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
89 105
90/** 106extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
91 * amdtp_out_stream_set_pcm - configure format of PCM samples
92 * @s: the AMDTP output stream to be configured
93 * @pcm_channels: the number of PCM samples in each data block, to be encoded
94 * as AM824 multi-bit linear audio
95 *
96 * This function must not be called while the stream is running.
97 */
98static inline void amdtp_out_stream_set_pcm(struct amdtp_out_stream *s,
99 unsigned int pcm_channels)
100{
101 s->pcm_channels = pcm_channels;
102}
103 107
104/** 108static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
105 * amdtp_out_stream_set_midi - configure format of MIDI data
106 * @s: the AMDTP output stream to be configured
107 * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels)
108 *
109 * This function must not be called while the stream is running.
110 */
111static inline void amdtp_out_stream_set_midi(struct amdtp_out_stream *s,
112 unsigned int midi_ports)
113{ 109{
114 s->midi_ports = midi_ports; 110 return !IS_ERR(s->context);
115} 111}
116 112
117/** 113/**
diff --git a/sound/firewire/cmp.c b/sound/firewire/cmp.c
index 645cb0ba4293..efdbf585e404 100644
--- a/sound/firewire/cmp.c
+++ b/sound/firewire/cmp.c
@@ -48,9 +48,6 @@ static int pcr_modify(struct cmp_connection *c,
48 int (*check)(struct cmp_connection *c, __be32 pcr), 48 int (*check)(struct cmp_connection *c, __be32 pcr),
49 enum bus_reset_handling bus_reset_handling) 49 enum bus_reset_handling bus_reset_handling)
50{ 50{
51 struct fw_device *device = fw_parent_device(c->resources.unit);
52 int generation = c->resources.generation;
53 int rcode, errors = 0;
54 __be32 old_arg, buffer[2]; 51 __be32 old_arg, buffer[2];
55 int err; 52 int err;
56 53
@@ -59,36 +56,31 @@ static int pcr_modify(struct cmp_connection *c,
59 old_arg = buffer[0]; 56 old_arg = buffer[0];
60 buffer[1] = modify(c, buffer[0]); 57 buffer[1] = modify(c, buffer[0]);
61 58
62 rcode = fw_run_transaction( 59 err = snd_fw_transaction(
63 device->card, TCODE_LOCK_COMPARE_SWAP, 60 c->resources.unit, TCODE_LOCK_COMPARE_SWAP,
64 device->node_id, generation, device->max_speed,
65 CSR_REGISTER_BASE + CSR_IPCR(c->pcr_index), 61 CSR_REGISTER_BASE + CSR_IPCR(c->pcr_index),
66 buffer, 8); 62 buffer, 8,
67 63 FW_FIXED_GENERATION | c->resources.generation);
68 if (rcode == RCODE_COMPLETE) { 64
69 if (buffer[0] == old_arg) /* success? */ 65 if (err < 0) {
70 break; 66 if (err == -EAGAIN &&
71 67 bus_reset_handling == SUCCEED_ON_BUS_RESET)
72 if (check) { 68 err = 0;
73 err = check(c, buffer[0]); 69 return err;
74 if (err < 0) 70 }
75 return err; 71
76 } 72 if (buffer[0] == old_arg) /* success? */
77 } else if (rcode == RCODE_GENERATION) 73 break;
78 goto bus_reset; 74
79 else if (rcode_is_permanent_error(rcode) || ++errors >= 3) 75 if (check) {
80 goto io_error; 76 err = check(c, buffer[0]);
77 if (err < 0)
78 return err;
79 }
81 } 80 }
82 c->last_pcr_value = buffer[1]; 81 c->last_pcr_value = buffer[1];
83 82
84 return 0; 83 return 0;
85
86io_error:
87 cmp_error(c, "transaction failed: %s\n", fw_rcode_string(rcode));
88 return -EIO;
89
90bus_reset:
91 return bus_reset_handling == ABORT_ON_BUS_RESET ? -EAGAIN : 0;
92} 84}
93 85
94 86
@@ -108,7 +100,7 @@ int cmp_connection_init(struct cmp_connection *c,
108 100
109 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST, 101 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
110 CSR_REGISTER_BASE + CSR_IMPR, 102 CSR_REGISTER_BASE + CSR_IMPR,
111 &impr_be, 4); 103 &impr_be, 4, 0);
112 if (err < 0) 104 if (err < 0)
113 return err; 105 return err;
114 impr = be32_to_cpu(impr_be); 106 impr = be32_to_cpu(impr_be);
diff --git a/sound/firewire/dice-interface.h b/sound/firewire/dice-interface.h
new file mode 100644
index 000000000000..27b044f84c81
--- /dev/null
+++ b/sound/firewire/dice-interface.h
@@ -0,0 +1,371 @@
1#ifndef SOUND_FIREWIRE_DICE_INTERFACE_H_INCLUDED
2#define SOUND_FIREWIRE_DICE_INTERFACE_H_INCLUDED
3
4/*
5 * DICE device interface definitions
6 */
7
8/*
9 * Generally, all registers can be read like memory, i.e., with quadlet read or
10 * block read transactions with at least quadlet-aligned offset and length.
11 * Writes are not allowed except where noted; quadlet-sized registers must be
12 * written with a quadlet write transaction.
13 *
14 * All values are in big endian. The DICE firmware runs on a little-endian CPU
15 * and just byte-swaps _all_ quadlets on the bus, so values without endianness
16 * (e.g. strings) get scrambled and must be byte-swapped again by the driver.
17 */
18
19/*
20 * Streaming is handled by the "DICE driver" interface. Its registers are
21 * located in this private address space.
22 */
23#define DICE_PRIVATE_SPACE 0xffffe0000000uLL
24
25/*
26 * The registers are organized in several sections, which are organized
27 * separately to allow them to be extended individually. Whether a register is
28 * supported can be detected by checking its offset against its section's size.
29 *
30 * The section offset values are relative to DICE_PRIVATE_SPACE; the offset/
31 * size values are measured in quadlets. Read-only.
32 */
33#define DICE_GLOBAL_OFFSET 0x00
34#define DICE_GLOBAL_SIZE 0x04
35#define DICE_TX_OFFSET 0x08
36#define DICE_TX_SIZE 0x0c
37#define DICE_RX_OFFSET 0x10
38#define DICE_RX_SIZE 0x14
39#define DICE_EXT_SYNC_OFFSET 0x18
40#define DICE_EXT_SYNC_SIZE 0x1c
41#define DICE_UNUSED2_OFFSET 0x20
42#define DICE_UNUSED2_SIZE 0x24
43
44/*
45 * Global settings.
46 */
47
48/*
49 * Stores the full 64-bit address (node ID and offset in the node's address
50 * space) where the device will send notifications. Must be changed with
51 * a compare/swap transaction by the owner. This register is automatically
52 * cleared on a bus reset.
53 */
54#define GLOBAL_OWNER 0x000
55#define OWNER_NO_OWNER 0xffff000000000000uLL
56#define OWNER_NODE_SHIFT 48
57
58/*
59 * A bitmask with asynchronous events; read-only. When any event(s) happen,
60 * the bits of previous events are cleared, and the value of this register is
61 * also written to the address stored in the owner register.
62 */
63#define GLOBAL_NOTIFICATION 0x008
64/* Some registers in the Rx/Tx sections may have changed. */
65#define NOTIFY_RX_CFG_CHG 0x00000001
66#define NOTIFY_TX_CFG_CHG 0x00000002
67/* Lock status of the current clock source may have changed. */
68#define NOTIFY_LOCK_CHG 0x00000010
69/* Write to the clock select register has been finished. */
70#define NOTIFY_CLOCK_ACCEPTED 0x00000020
71/* Lock status of some clock source has changed. */
72#define NOTIFY_EXT_STATUS 0x00000040
73/* Other bits may be used for device-specific events. */
74
75/*
76 * A name that can be customized for each device; read/write. Padded with zero
77 * bytes. Quadlets are byte-swapped. The encoding is whatever the host driver
78 * happens to be using.
79 */
80#define GLOBAL_NICK_NAME 0x00c
81#define NICK_NAME_SIZE 64
82
83/*
84 * The current sample rate and clock source; read/write. Whether a clock
85 * source or sample rate is supported is device-specific; the internal clock
86 * source is always available. Low/mid/high = up to 48/96/192 kHz. This
87 * register can be changed even while streams are running.
88 */
89#define GLOBAL_CLOCK_SELECT 0x04c
90#define CLOCK_SOURCE_MASK 0x000000ff
91#define CLOCK_SOURCE_AES1 0x00000000
92#define CLOCK_SOURCE_AES2 0x00000001
93#define CLOCK_SOURCE_AES3 0x00000002
94#define CLOCK_SOURCE_AES4 0x00000003
95#define CLOCK_SOURCE_AES_ANY 0x00000004
96#define CLOCK_SOURCE_ADAT 0x00000005
97#define CLOCK_SOURCE_TDIF 0x00000006
98#define CLOCK_SOURCE_WC 0x00000007
99#define CLOCK_SOURCE_ARX1 0x00000008
100#define CLOCK_SOURCE_ARX2 0x00000009
101#define CLOCK_SOURCE_ARX3 0x0000000a
102#define CLOCK_SOURCE_ARX4 0x0000000b
103#define CLOCK_SOURCE_INTERNAL 0x0000000c
104#define CLOCK_RATE_MASK 0x0000ff00
105#define CLOCK_RATE_32000 0x00000000
106#define CLOCK_RATE_44100 0x00000100
107#define CLOCK_RATE_48000 0x00000200
108#define CLOCK_RATE_88200 0x00000300
109#define CLOCK_RATE_96000 0x00000400
110#define CLOCK_RATE_176400 0x00000500
111#define CLOCK_RATE_192000 0x00000600
112#define CLOCK_RATE_ANY_LOW 0x00000700
113#define CLOCK_RATE_ANY_MID 0x00000800
114#define CLOCK_RATE_ANY_HIGH 0x00000900
115#define CLOCK_RATE_NONE 0x00000a00
116#define CLOCK_RATE_SHIFT 8
117
118/*
119 * Enable streaming; read/write. Writing a non-zero value (re)starts all
120 * streams that have a valid iso channel set; zero stops all streams. The
121 * streams' parameters must be configured before starting. This register is
122 * automatically cleared on a bus reset.
123 */
124#define GLOBAL_ENABLE 0x050
125
126/*
127 * Status of the sample clock; read-only.
128 */
129#define GLOBAL_STATUS 0x054
130/* The current clock source is locked. */
131#define STATUS_SOURCE_LOCKED 0x00000001
132/* The actual sample rate; CLOCK_RATE_32000-_192000 or _NONE. */
133#define STATUS_NOMINAL_RATE_MASK 0x0000ff00
134
135/*
136 * Status of all clock sources; read-only.
137 */
138#define GLOBAL_EXTENDED_STATUS 0x058
139/*
140 * The _LOCKED bits always show the current status; any change generates
141 * a notification.
142 */
143#define EXT_STATUS_AES1_LOCKED 0x00000001
144#define EXT_STATUS_AES2_LOCKED 0x00000002
145#define EXT_STATUS_AES3_LOCKED 0x00000004
146#define EXT_STATUS_AES4_LOCKED 0x00000008
147#define EXT_STATUS_ADAT_LOCKED 0x00000010
148#define EXT_STATUS_TDIF_LOCKED 0x00000020
149#define EXT_STATUS_ARX1_LOCKED 0x00000040
150#define EXT_STATUS_ARX2_LOCKED 0x00000080
151#define EXT_STATUS_ARX3_LOCKED 0x00000100
152#define EXT_STATUS_ARX4_LOCKED 0x00000200
153#define EXT_STATUS_WC_LOCKED 0x00000400
154/*
155 * The _SLIP bits do not generate notifications; a set bit indicates that an
156 * error occurred since the last time when this register was read with
157 * a quadlet read transaction.
158 */
159#define EXT_STATUS_AES1_SLIP 0x00010000
160#define EXT_STATUS_AES2_SLIP 0x00020000
161#define EXT_STATUS_AES3_SLIP 0x00040000
162#define EXT_STATUS_AES4_SLIP 0x00080000
163#define EXT_STATUS_ADAT_SLIP 0x00100000
164#define EXT_STATUS_TDIF_SLIP 0x00200000
165#define EXT_STATUS_ARX1_SLIP 0x00400000
166#define EXT_STATUS_ARX2_SLIP 0x00800000
167#define EXT_STATUS_ARX3_SLIP 0x01000000
168#define EXT_STATUS_ARX4_SLIP 0x02000000
169#define EXT_STATUS_WC_SLIP 0x04000000
170
171/*
172 * The measured rate of the current clock source, in Hz; read-only.
173 */
174#define GLOBAL_SAMPLE_RATE 0x05c
175
176/*
177 * The version of the DICE driver specification that this device conforms to;
178 * read-only.
179 */
180#define GLOBAL_VERSION 0x060
181
182/* Some old firmware versions do not have the following global registers: */
183
184/*
185 * Supported sample rates and clock sources; read-only.
186 */
187#define GLOBAL_CLOCK_CAPABILITIES 0x064
188#define CLOCK_CAP_RATE_32000 0x00000001
189#define CLOCK_CAP_RATE_44100 0x00000002
190#define CLOCK_CAP_RATE_48000 0x00000004
191#define CLOCK_CAP_RATE_88200 0x00000008
192#define CLOCK_CAP_RATE_96000 0x00000010
193#define CLOCK_CAP_RATE_176400 0x00000020
194#define CLOCK_CAP_RATE_192000 0x00000040
195#define CLOCK_CAP_SOURCE_AES1 0x00010000
196#define CLOCK_CAP_SOURCE_AES2 0x00020000
197#define CLOCK_CAP_SOURCE_AES3 0x00040000
198#define CLOCK_CAP_SOURCE_AES4 0x00080000
199#define CLOCK_CAP_SOURCE_AES_ANY 0x00100000
200#define CLOCK_CAP_SOURCE_ADAT 0x00200000
201#define CLOCK_CAP_SOURCE_TDIF 0x00400000
202#define CLOCK_CAP_SOURCE_WC 0x00800000
203#define CLOCK_CAP_SOURCE_ARX1 0x01000000
204#define CLOCK_CAP_SOURCE_ARX2 0x02000000
205#define CLOCK_CAP_SOURCE_ARX3 0x04000000
206#define CLOCK_CAP_SOURCE_ARX4 0x08000000
207#define CLOCK_CAP_SOURCE_INTERNAL 0x10000000
208
209/*
210 * Names of all clock sources; read-only. Quadlets are byte-swapped. Names
211 * are separated with one backslash, the list is terminated with two
212 * backslashes. Unused clock sources are included.
213 */
214#define GLOBAL_CLOCK_SOURCE_NAMES 0x068
215#define CLOCK_SOURCE_NAMES_SIZE 256
216
217/*
218 * Capture stream settings. This section includes the number/size registers
219 * and the registers of all streams.
220 */
221
222/*
223 * The number of supported capture streams; read-only.
224 */
225#define TX_NUMBER 0x000
226
227/*
228 * The size of one stream's register block, in quadlets; read-only. The
229 * registers of the first stream follow immediately afterwards; the registers
230 * of the following streams are offset by this register's value.
231 */
232#define TX_SIZE 0x004
233
234/*
235 * The isochronous channel number on which packets are sent, or -1 if the
236 * stream is not to be used; read/write.
237 */
238#define TX_ISOCHRONOUS 0x008
239
240/*
241 * The number of audio channels; read-only. There will be one quadlet per
242 * channel; the first channel is the first quadlet in a data block.
243 */
244#define TX_NUMBER_AUDIO 0x00c
245
246/*
247 * The number of MIDI ports, 0-8; read-only. If > 0, there will be one
248 * additional quadlet in each data block, following the audio quadlets.
249 */
250#define TX_NUMBER_MIDI 0x010
251
252/*
253 * The speed at which the packets are sent, SCODE_100-_400; read/write.
254 */
255#define TX_SPEED 0x014
256
257/*
258 * Names of all audio channels; read-only. Quadlets are byte-swapped. Names
259 * are separated with one backslash, the list is terminated with two
260 * backslashes.
261 */
262#define TX_NAMES 0x018
263#define TX_NAMES_SIZE 256
264
265/*
266 * Audio IEC60958 capabilities; read-only. Bitmask with one bit per audio
267 * channel.
268 */
269#define TX_AC3_CAPABILITIES 0x118
270
271/*
272 * Send audio data with IEC60958 label; read/write. Bitmask with one bit per
273 * audio channel. This register can be changed even while the stream is
274 * running.
275 */
276#define TX_AC3_ENABLE 0x11c
277
278/*
279 * Playback stream settings. This section includes the number/size registers
280 * and the registers of all streams.
281 */
282
283/*
284 * The number of supported playback streams; read-only.
285 */
286#define RX_NUMBER 0x000
287
288/*
289 * The size of one stream's register block, in quadlets; read-only. The
290 * registers of the first stream follow immediately afterwards; the registers
291 * of the following streams are offset by this register's value.
292 */
293#define RX_SIZE 0x004
294
295/*
296 * The isochronous channel number on which packets are received, or -1 if the
297 * stream is not to be used; read/write.
298 */
299#define RX_ISOCHRONOUS 0x008
300
301/*
302 * Index of first quadlet to be interpreted; read/write. If > 0, that many
303 * quadlets at the beginning of each data block will be ignored, and all the
304 * audio and MIDI quadlets will follow.
305 */
306#define RX_SEQ_START 0x00c
307
308/*
309 * The number of audio channels; read-only. There will be one quadlet per
310 * channel.
311 */
312#define RX_NUMBER_AUDIO 0x010
313
314/*
315 * The number of MIDI ports, 0-8; read-only. If > 0, there will be one
316 * additional quadlet in each data block, following the audio quadlets.
317 */
318#define RX_NUMBER_MIDI 0x014
319
320/*
321 * Names of all audio channels; read-only. Quadlets are byte-swapped. Names
322 * are separated with one backslash, the list is terminated with two
323 * backslashes.
324 */
325#define RX_NAMES 0x018
326#define RX_NAMES_SIZE 256
327
328/*
329 * Audio IEC60958 capabilities; read-only. Bitmask with one bit per audio
330 * channel.
331 */
332#define RX_AC3_CAPABILITIES 0x118
333
334/*
335 * Receive audio data with IEC60958 label; read/write. Bitmask with one bit
336 * per audio channel. This register can be changed even while the stream is
337 * running.
338 */
339#define RX_AC3_ENABLE 0x11c
340
341/*
342 * Extended synchronization information.
343 * This section can be read completely with a block read request.
344 */
345
346/*
347 * Current clock source; read-only.
348 */
349#define EXT_SYNC_CLOCK_SOURCE 0x000
350
351/*
352 * Clock source is locked (boolean); read-only.
353 */
354#define EXT_SYNC_LOCKED 0x004
355
356/*
357 * Current sample rate (CLOCK_RATE_* >> CLOCK_RATE_SHIFT), _32000-_192000 or
358 * _NONE; read-only.
359 */
360#define EXT_SYNC_RATE 0x008
361
362/*
363 * ADAT user data bits; read-only.
364 */
365#define EXT_SYNC_ADAT_USER_DATA 0x00c
366/* The data bits, if available. */
367#define ADAT_USER_DATA_MASK 0x0f
368/* The data bits are not available. */
369#define ADAT_USER_DATA_NO_DATA 0x10
370
371#endif
diff --git a/sound/firewire/dice.c b/sound/firewire/dice.c
new file mode 100644
index 000000000000..57bcd31fcc12
--- /dev/null
+++ b/sound/firewire/dice.c
@@ -0,0 +1,1494 @@
1/*
2 * TC Applied Technologies Digital Interface Communications Engine driver
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
8#include <linux/compat.h>
9#include <linux/completion.h>
10#include <linux/delay.h>
11#include <linux/device.h>
12#include <linux/firewire.h>
13#include <linux/firewire-constants.h>
14#include <linux/jiffies.h>
15#include <linux/module.h>
16#include <linux/mod_devicetable.h>
17#include <linux/mutex.h>
18#include <linux/slab.h>
19#include <linux/spinlock.h>
20#include <linux/wait.h>
21#include <sound/control.h>
22#include <sound/core.h>
23#include <sound/firewire.h>
24#include <sound/hwdep.h>
25#include <sound/info.h>
26#include <sound/initval.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include "amdtp.h"
30#include "iso-resources.h"
31#include "lib.h"
32#include "dice-interface.h"
33
34
35struct dice {
36 struct snd_card *card;
37 struct fw_unit *unit;
38 spinlock_t lock;
39 struct mutex mutex;
40 unsigned int global_offset;
41 unsigned int rx_offset;
42 unsigned int clock_caps;
43 unsigned int rx_channels[3];
44 unsigned int rx_midi_ports[3];
45 struct fw_address_handler notification_handler;
46 int owner_generation;
47 int dev_lock_count; /* > 0 driver, < 0 userspace */
48 bool dev_lock_changed;
49 bool global_enabled;
50 struct completion clock_accepted;
51 wait_queue_head_t hwdep_wait;
52 u32 notification_bits;
53 struct fw_iso_resources resources;
54 struct amdtp_out_stream stream;
55};
56
57MODULE_DESCRIPTION("DICE driver");
58MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
59MODULE_LICENSE("GPL v2");
60
61static const unsigned int dice_rates[] = {
62 /* mode 0 */
63 [0] = 32000,
64 [1] = 44100,
65 [2] = 48000,
66 /* mode 1 */
67 [3] = 88200,
68 [4] = 96000,
69 /* mode 2 */
70 [5] = 176400,
71 [6] = 192000,
72};
73
74static unsigned int rate_to_index(unsigned int rate)
75{
76 unsigned int i;
77
78 for (i = 0; i < ARRAY_SIZE(dice_rates); ++i)
79 if (dice_rates[i] == rate)
80 return i;
81
82 return 0;
83}
84
85static unsigned int rate_index_to_mode(unsigned int rate_index)
86{
87 return ((int)rate_index - 1) / 2;
88}
89
90static void dice_lock_changed(struct dice *dice)
91{
92 dice->dev_lock_changed = true;
93 wake_up(&dice->hwdep_wait);
94}
95
96static int dice_try_lock(struct dice *dice)
97{
98 int err;
99
100 spin_lock_irq(&dice->lock);
101
102 if (dice->dev_lock_count < 0) {
103 err = -EBUSY;
104 goto out;
105 }
106
107 if (dice->dev_lock_count++ == 0)
108 dice_lock_changed(dice);
109 err = 0;
110
111out:
112 spin_unlock_irq(&dice->lock);
113
114 return err;
115}
116
117static void dice_unlock(struct dice *dice)
118{
119 spin_lock_irq(&dice->lock);
120
121 if (WARN_ON(dice->dev_lock_count <= 0))
122 goto out;
123
124 if (--dice->dev_lock_count == 0)
125 dice_lock_changed(dice);
126
127out:
128 spin_unlock_irq(&dice->lock);
129}
130
131static inline u64 global_address(struct dice *dice, unsigned int offset)
132{
133 return DICE_PRIVATE_SPACE + dice->global_offset + offset;
134}
135
136// TODO: rx index
137static inline u64 rx_address(struct dice *dice, unsigned int offset)
138{
139 return DICE_PRIVATE_SPACE + dice->rx_offset + offset;
140}
141
142static int dice_owner_set(struct dice *dice)
143{
144 struct fw_device *device = fw_parent_device(dice->unit);
145 __be64 *buffer;
146 int err, errors = 0;
147
148 buffer = kmalloc(2 * 8, GFP_KERNEL);
149 if (!buffer)
150 return -ENOMEM;
151
152 for (;;) {
153 buffer[0] = cpu_to_be64(OWNER_NO_OWNER);
154 buffer[1] = cpu_to_be64(
155 ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
156 dice->notification_handler.offset);
157
158 dice->owner_generation = device->generation;
159 smp_rmb(); /* node_id vs. generation */
160 err = snd_fw_transaction(dice->unit,
161 TCODE_LOCK_COMPARE_SWAP,
162 global_address(dice, GLOBAL_OWNER),
163 buffer, 2 * 8,
164 FW_FIXED_GENERATION |
165 dice->owner_generation);
166
167 if (err == 0) {
168 if (buffer[0] != cpu_to_be64(OWNER_NO_OWNER)) {
169 dev_err(&dice->unit->device,
170 "device is already in use\n");
171 err = -EBUSY;
172 }
173 break;
174 }
175 if (err != -EAGAIN || ++errors >= 3)
176 break;
177
178 msleep(20);
179 }
180
181 kfree(buffer);
182
183 return err;
184}
185
186static int dice_owner_update(struct dice *dice)
187{
188 struct fw_device *device = fw_parent_device(dice->unit);
189 __be64 *buffer;
190 int err;
191
192 if (dice->owner_generation == -1)
193 return 0;
194
195 buffer = kmalloc(2 * 8, GFP_KERNEL);
196 if (!buffer)
197 return -ENOMEM;
198
199 buffer[0] = cpu_to_be64(OWNER_NO_OWNER);
200 buffer[1] = cpu_to_be64(
201 ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
202 dice->notification_handler.offset);
203
204 dice->owner_generation = device->generation;
205 smp_rmb(); /* node_id vs. generation */
206 err = snd_fw_transaction(dice->unit, TCODE_LOCK_COMPARE_SWAP,
207 global_address(dice, GLOBAL_OWNER),
208 buffer, 2 * 8,
209 FW_FIXED_GENERATION | dice->owner_generation);
210
211 if (err == 0) {
212 if (buffer[0] != cpu_to_be64(OWNER_NO_OWNER)) {
213 dev_err(&dice->unit->device,
214 "device is already in use\n");
215 err = -EBUSY;
216 }
217 } else if (err == -EAGAIN) {
218 err = 0; /* try again later */
219 }
220
221 kfree(buffer);
222
223 if (err < 0)
224 dice->owner_generation = -1;
225
226 return err;
227}
228
229static void dice_owner_clear(struct dice *dice)
230{
231 struct fw_device *device = fw_parent_device(dice->unit);
232 __be64 *buffer;
233
234 buffer = kmalloc(2 * 8, GFP_KERNEL);
235 if (!buffer)
236 return;
237
238 buffer[0] = cpu_to_be64(
239 ((u64)device->card->node_id << OWNER_NODE_SHIFT) |
240 dice->notification_handler.offset);
241 buffer[1] = cpu_to_be64(OWNER_NO_OWNER);
242 snd_fw_transaction(dice->unit, TCODE_LOCK_COMPARE_SWAP,
243 global_address(dice, GLOBAL_OWNER),
244 buffer, 2 * 8, FW_QUIET |
245 FW_FIXED_GENERATION | dice->owner_generation);
246
247 kfree(buffer);
248
249 dice->owner_generation = -1;
250}
251
252static int dice_enable_set(struct dice *dice)
253{
254 __be32 value;
255 int err;
256
257 value = cpu_to_be32(1);
258 err = snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
259 global_address(dice, GLOBAL_ENABLE),
260 &value, 4,
261 FW_FIXED_GENERATION | dice->owner_generation);
262 if (err < 0)
263 return err;
264
265 dice->global_enabled = true;
266
267 return 0;
268}
269
270static void dice_enable_clear(struct dice *dice)
271{
272 __be32 value;
273
274 if (!dice->global_enabled)
275 return;
276
277 value = 0;
278 snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
279 global_address(dice, GLOBAL_ENABLE),
280 &value, 4, FW_QUIET |
281 FW_FIXED_GENERATION | dice->owner_generation);
282
283 dice->global_enabled = false;
284}
285
286static void dice_notification(struct fw_card *card, struct fw_request *request,
287 int tcode, int destination, int source,
288 int generation, unsigned long long offset,
289 void *data, size_t length, void *callback_data)
290{
291 struct dice *dice = callback_data;
292 u32 bits;
293 unsigned long flags;
294
295 if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
296 fw_send_response(card, request, RCODE_TYPE_ERROR);
297 return;
298 }
299 if ((offset & 3) != 0) {
300 fw_send_response(card, request, RCODE_ADDRESS_ERROR);
301 return;
302 }
303
304 bits = be32_to_cpup(data);
305
306 spin_lock_irqsave(&dice->lock, flags);
307 dice->notification_bits |= bits;
308 spin_unlock_irqrestore(&dice->lock, flags);
309
310 fw_send_response(card, request, RCODE_COMPLETE);
311
312 if (bits & NOTIFY_CLOCK_ACCEPTED)
313 complete(&dice->clock_accepted);
314 wake_up(&dice->hwdep_wait);
315}
316
317static int dice_rate_constraint(struct snd_pcm_hw_params *params,
318 struct snd_pcm_hw_rule *rule)
319{
320 struct dice *dice = rule->private;
321 const struct snd_interval *channels =
322 hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS);
323 struct snd_interval *rate =
324 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
325 struct snd_interval allowed_rates = {
326 .min = UINT_MAX, .max = 0, .integer = 1
327 };
328 unsigned int i, mode;
329
330 for (i = 0; i < ARRAY_SIZE(dice_rates); ++i) {
331 mode = rate_index_to_mode(i);
332 if ((dice->clock_caps & (1 << i)) &&
333 snd_interval_test(channels, dice->rx_channels[mode])) {
334 allowed_rates.min = min(allowed_rates.min,
335 dice_rates[i]);
336 allowed_rates.max = max(allowed_rates.max,
337 dice_rates[i]);
338 }
339 }
340
341 return snd_interval_refine(rate, &allowed_rates);
342}
343
344static int dice_channels_constraint(struct snd_pcm_hw_params *params,
345 struct snd_pcm_hw_rule *rule)
346{
347 struct dice *dice = rule->private;
348 const struct snd_interval *rate =
349 hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE);
350 struct snd_interval *channels =
351 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
352 struct snd_interval allowed_channels = {
353 .min = UINT_MAX, .max = 0, .integer = 1
354 };
355 unsigned int i, mode;
356
357 for (i = 0; i < ARRAY_SIZE(dice_rates); ++i)
358 if ((dice->clock_caps & (1 << i)) &&
359 snd_interval_test(rate, dice_rates[i])) {
360 mode = rate_index_to_mode(i);
361 allowed_channels.min = min(allowed_channels.min,
362 dice->rx_channels[mode]);
363 allowed_channels.max = max(allowed_channels.max,
364 dice->rx_channels[mode]);
365 }
366
367 return snd_interval_refine(channels, &allowed_channels);
368}
369
370static int dice_open(struct snd_pcm_substream *substream)
371{
372 static const struct snd_pcm_hardware hardware = {
373 .info = SNDRV_PCM_INFO_MMAP |
374 SNDRV_PCM_INFO_MMAP_VALID |
375 SNDRV_PCM_INFO_BATCH |
376 SNDRV_PCM_INFO_INTERLEAVED |
377 SNDRV_PCM_INFO_BLOCK_TRANSFER,
378 .formats = AMDTP_OUT_PCM_FORMAT_BITS,
379 .channels_min = UINT_MAX,
380 .channels_max = 0,
381 .buffer_bytes_max = 16 * 1024 * 1024,
382 .period_bytes_min = 1,
383 .period_bytes_max = UINT_MAX,
384 .periods_min = 1,
385 .periods_max = UINT_MAX,
386 };
387 struct dice *dice = substream->private_data;
388 struct snd_pcm_runtime *runtime = substream->runtime;
389 unsigned int i;
390 int err;
391
392 err = dice_try_lock(dice);
393 if (err < 0)
394 goto error;
395
396 runtime->hw = hardware;
397
398 for (i = 0; i < ARRAY_SIZE(dice_rates); ++i)
399 if (dice->clock_caps & (1 << i))
400 runtime->hw.rates |=
401 snd_pcm_rate_to_rate_bit(dice_rates[i]);
402 snd_pcm_limit_hw_rates(runtime);
403
404 for (i = 0; i < 3; ++i)
405 if (dice->rx_channels[i]) {
406 runtime->hw.channels_min = min(runtime->hw.channels_min,
407 dice->rx_channels[i]);
408 runtime->hw.channels_max = max(runtime->hw.channels_max,
409 dice->rx_channels[i]);
410 }
411
412 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
413 dice_rate_constraint, dice,
414 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
415 if (err < 0)
416 goto err_lock;
417 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
418 dice_channels_constraint, dice,
419 SNDRV_PCM_HW_PARAM_RATE, -1);
420 if (err < 0)
421 goto err_lock;
422
423 err = snd_pcm_hw_constraint_step(runtime, 0,
424 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32);
425 if (err < 0)
426 goto err_lock;
427 err = snd_pcm_hw_constraint_step(runtime, 0,
428 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);
429 if (err < 0)
430 goto err_lock;
431
432 err = snd_pcm_hw_constraint_minmax(runtime,
433 SNDRV_PCM_HW_PARAM_PERIOD_TIME,
434 5000, UINT_MAX);
435 if (err < 0)
436 goto err_lock;
437
438 err = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
439 if (err < 0)
440 goto err_lock;
441
442 return 0;
443
444err_lock:
445 dice_unlock(dice);
446error:
447 return err;
448}
449
450static int dice_close(struct snd_pcm_substream *substream)
451{
452 struct dice *dice = substream->private_data;
453
454 dice_unlock(dice);
455
456 return 0;
457}
458
459static int dice_stream_start_packets(struct dice *dice)
460{
461 int err;
462
463 if (amdtp_out_stream_running(&dice->stream))
464 return 0;
465
466 err = amdtp_out_stream_start(&dice->stream, dice->resources.channel,
467 fw_parent_device(dice->unit)->max_speed);
468 if (err < 0)
469 return err;
470
471 err = dice_enable_set(dice);
472 if (err < 0) {
473 amdtp_out_stream_stop(&dice->stream);
474 return err;
475 }
476
477 return 0;
478}
479
480static int dice_stream_start(struct dice *dice)
481{
482 __be32 channel;
483 int err;
484
485 if (!dice->resources.allocated) {
486 err = fw_iso_resources_allocate(&dice->resources,
487 amdtp_out_stream_get_max_payload(&dice->stream),
488 fw_parent_device(dice->unit)->max_speed);
489 if (err < 0)
490 goto error;
491
492 channel = cpu_to_be32(dice->resources.channel);
493 err = snd_fw_transaction(dice->unit,
494 TCODE_WRITE_QUADLET_REQUEST,
495 rx_address(dice, RX_ISOCHRONOUS),
496 &channel, 4, 0);
497 if (err < 0)
498 goto err_resources;
499 }
500
501 err = dice_stream_start_packets(dice);
502 if (err < 0)
503 goto err_rx_channel;
504
505 return 0;
506
507err_rx_channel:
508 channel = cpu_to_be32((u32)-1);
509 snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
510 rx_address(dice, RX_ISOCHRONOUS), &channel, 4, 0);
511err_resources:
512 fw_iso_resources_free(&dice->resources);
513error:
514 return err;
515}
516
517static void dice_stream_stop_packets(struct dice *dice)
518{
519 if (amdtp_out_stream_running(&dice->stream)) {
520 dice_enable_clear(dice);
521 amdtp_out_stream_stop(&dice->stream);
522 }
523}
524
525static void dice_stream_stop(struct dice *dice)
526{
527 __be32 channel;
528
529 dice_stream_stop_packets(dice);
530
531 if (!dice->resources.allocated)
532 return;
533
534 channel = cpu_to_be32((u32)-1);
535 snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
536 rx_address(dice, RX_ISOCHRONOUS), &channel, 4, 0);
537
538 fw_iso_resources_free(&dice->resources);
539}
540
541static int dice_change_rate(struct dice *dice, unsigned int clock_rate)
542{
543 __be32 value;
544 int err;
545
546 reinit_completion(&dice->clock_accepted);
547
548 value = cpu_to_be32(clock_rate | CLOCK_SOURCE_ARX1);
549 err = snd_fw_transaction(dice->unit, TCODE_WRITE_QUADLET_REQUEST,
550 global_address(dice, GLOBAL_CLOCK_SELECT),
551 &value, 4, 0);
552 if (err < 0)
553 return err;
554
555 if (!wait_for_completion_timeout(&dice->clock_accepted,
556 msecs_to_jiffies(100)))
557 dev_warn(&dice->unit->device, "clock change timed out\n");
558
559 return 0;
560}
561
562static int dice_hw_params(struct snd_pcm_substream *substream,
563 struct snd_pcm_hw_params *hw_params)
564{
565 struct dice *dice = substream->private_data;
566 unsigned int rate_index, mode;
567 int err;
568
569 mutex_lock(&dice->mutex);
570 dice_stream_stop(dice);
571 mutex_unlock(&dice->mutex);
572
573 err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
574 params_buffer_bytes(hw_params));
575 if (err < 0)
576 return err;
577
578 rate_index = rate_to_index(params_rate(hw_params));
579 err = dice_change_rate(dice, rate_index << CLOCK_RATE_SHIFT);
580 if (err < 0)
581 return err;
582
583 mode = rate_index_to_mode(rate_index);
584 amdtp_out_stream_set_parameters(&dice->stream,
585 params_rate(hw_params),
586 params_channels(hw_params),
587 dice->rx_midi_ports[mode]);
588 amdtp_out_stream_set_pcm_format(&dice->stream,
589 params_format(hw_params));
590
591 return 0;
592}
593
594static int dice_hw_free(struct snd_pcm_substream *substream)
595{
596 struct dice *dice = substream->private_data;
597
598 mutex_lock(&dice->mutex);
599 dice_stream_stop(dice);
600 mutex_unlock(&dice->mutex);
601
602 return snd_pcm_lib_free_vmalloc_buffer(substream);
603}
604
605static int dice_prepare(struct snd_pcm_substream *substream)
606{
607 struct dice *dice = substream->private_data;
608 int err;
609
610 mutex_lock(&dice->mutex);
611
612 if (amdtp_out_streaming_error(&dice->stream))
613 dice_stream_stop_packets(dice);
614
615 err = dice_stream_start(dice);
616 if (err < 0) {
617 mutex_unlock(&dice->mutex);
618 return err;
619 }
620
621 mutex_unlock(&dice->mutex);
622
623 amdtp_out_stream_pcm_prepare(&dice->stream);
624
625 return 0;
626}
627
628static int dice_trigger(struct snd_pcm_substream *substream, int cmd)
629{
630 struct dice *dice = substream->private_data;
631 struct snd_pcm_substream *pcm;
632
633 switch (cmd) {
634 case SNDRV_PCM_TRIGGER_START:
635 pcm = substream;
636 break;
637 case SNDRV_PCM_TRIGGER_STOP:
638 pcm = NULL;
639 break;
640 default:
641 return -EINVAL;
642 }
643 amdtp_out_stream_pcm_trigger(&dice->stream, pcm);
644
645 return 0;
646}
647
648static snd_pcm_uframes_t dice_pointer(struct snd_pcm_substream *substream)
649{
650 struct dice *dice = substream->private_data;
651
652 return amdtp_out_stream_pcm_pointer(&dice->stream);
653}
654
655static int dice_create_pcm(struct dice *dice)
656{
657 static struct snd_pcm_ops ops = {
658 .open = dice_open,
659 .close = dice_close,
660 .ioctl = snd_pcm_lib_ioctl,
661 .hw_params = dice_hw_params,
662 .hw_free = dice_hw_free,
663 .prepare = dice_prepare,
664 .trigger = dice_trigger,
665 .pointer = dice_pointer,
666 .page = snd_pcm_lib_get_vmalloc_page,
667 .mmap = snd_pcm_lib_mmap_vmalloc,
668 };
669 struct snd_pcm *pcm;
670 int err;
671
672 err = snd_pcm_new(dice->card, "DICE", 0, 1, 0, &pcm);
673 if (err < 0)
674 return err;
675 pcm->private_data = dice;
676 strcpy(pcm->name, dice->card->shortname);
677 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->ops = &ops;
678
679 return 0;
680}
681
682static long dice_hwdep_read(struct snd_hwdep *hwdep, char __user *buf,
683 long count, loff_t *offset)
684{
685 struct dice *dice = hwdep->private_data;
686 DEFINE_WAIT(wait);
687 union snd_firewire_event event;
688
689 spin_lock_irq(&dice->lock);
690
691 while (!dice->dev_lock_changed && dice->notification_bits == 0) {
692 prepare_to_wait(&dice->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
693 spin_unlock_irq(&dice->lock);
694 schedule();
695 finish_wait(&dice->hwdep_wait, &wait);
696 if (signal_pending(current))
697 return -ERESTARTSYS;
698 spin_lock_irq(&dice->lock);
699 }
700
701 memset(&event, 0, sizeof(event));
702 if (dice->dev_lock_changed) {
703 event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
704 event.lock_status.status = dice->dev_lock_count > 0;
705 dice->dev_lock_changed = false;
706
707 count = min(count, (long)sizeof(event.lock_status));
708 } else {
709 event.dice_notification.type = SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION;
710 event.dice_notification.notification = dice->notification_bits;
711 dice->notification_bits = 0;
712
713 count = min(count, (long)sizeof(event.dice_notification));
714 }
715
716 spin_unlock_irq(&dice->lock);
717
718 if (copy_to_user(buf, &event, count))
719 return -EFAULT;
720
721 return count;
722}
723
724static unsigned int dice_hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
725 poll_table *wait)
726{
727 struct dice *dice = hwdep->private_data;
728 unsigned int events;
729
730 poll_wait(file, &dice->hwdep_wait, wait);
731
732 spin_lock_irq(&dice->lock);
733 if (dice->dev_lock_changed || dice->notification_bits != 0)
734 events = POLLIN | POLLRDNORM;
735 else
736 events = 0;
737 spin_unlock_irq(&dice->lock);
738
739 return events;
740}
741
742static int dice_hwdep_get_info(struct dice *dice, void __user *arg)
743{
744 struct fw_device *dev = fw_parent_device(dice->unit);
745 struct snd_firewire_get_info info;
746
747 memset(&info, 0, sizeof(info));
748 info.type = SNDRV_FIREWIRE_TYPE_DICE;
749 info.card = dev->card->index;
750 *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);
751 *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);
752 strlcpy(info.device_name, dev_name(&dev->device),
753 sizeof(info.device_name));
754
755 if (copy_to_user(arg, &info, sizeof(info)))
756 return -EFAULT;
757
758 return 0;
759}
760
761static int dice_hwdep_lock(struct dice *dice)
762{
763 int err;
764
765 spin_lock_irq(&dice->lock);
766
767 if (dice->dev_lock_count == 0) {
768 dice->dev_lock_count = -1;
769 err = 0;
770 } else {
771 err = -EBUSY;
772 }
773
774 spin_unlock_irq(&dice->lock);
775
776 return err;
777}
778
779static int dice_hwdep_unlock(struct dice *dice)
780{
781 int err;
782
783 spin_lock_irq(&dice->lock);
784
785 if (dice->dev_lock_count == -1) {
786 dice->dev_lock_count = 0;
787 err = 0;
788 } else {
789 err = -EBADFD;
790 }
791
792 spin_unlock_irq(&dice->lock);
793
794 return err;
795}
796
797static int dice_hwdep_release(struct snd_hwdep *hwdep, struct file *file)
798{
799 struct dice *dice = hwdep->private_data;
800
801 spin_lock_irq(&dice->lock);
802 if (dice->dev_lock_count == -1)
803 dice->dev_lock_count = 0;
804 spin_unlock_irq(&dice->lock);
805
806 return 0;
807}
808
809static int dice_hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,
810 unsigned int cmd, unsigned long arg)
811{
812 struct dice *dice = hwdep->private_data;
813
814 switch (cmd) {
815 case SNDRV_FIREWIRE_IOCTL_GET_INFO:
816 return dice_hwdep_get_info(dice, (void __user *)arg);
817 case SNDRV_FIREWIRE_IOCTL_LOCK:
818 return dice_hwdep_lock(dice);
819 case SNDRV_FIREWIRE_IOCTL_UNLOCK:
820 return dice_hwdep_unlock(dice);
821 default:
822 return -ENOIOCTLCMD;
823 }
824}
825
826#ifdef CONFIG_COMPAT
827static int dice_hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
828 unsigned int cmd, unsigned long arg)
829{
830 return dice_hwdep_ioctl(hwdep, file, cmd,
831 (unsigned long)compat_ptr(arg));
832}
833#else
834#define dice_hwdep_compat_ioctl NULL
835#endif
836
837static int dice_create_hwdep(struct dice *dice)
838{
839 static const struct snd_hwdep_ops ops = {
840 .read = dice_hwdep_read,
841 .release = dice_hwdep_release,
842 .poll = dice_hwdep_poll,
843 .ioctl = dice_hwdep_ioctl,
844 .ioctl_compat = dice_hwdep_compat_ioctl,
845 };
846 struct snd_hwdep *hwdep;
847 int err;
848
849 err = snd_hwdep_new(dice->card, "DICE", 0, &hwdep);
850 if (err < 0)
851 return err;
852 strcpy(hwdep->name, "DICE");
853 hwdep->iface = SNDRV_HWDEP_IFACE_FW_DICE;
854 hwdep->ops = ops;
855 hwdep->private_data = dice;
856 hwdep->exclusive = true;
857
858 return 0;
859}
860
861static int dice_proc_read_mem(struct dice *dice, void *buffer,
862 unsigned int offset_q, unsigned int quadlets)
863{
864 unsigned int i;
865 int err;
866
867 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
868 DICE_PRIVATE_SPACE + 4 * offset_q,
869 buffer, 4 * quadlets, 0);
870 if (err < 0)
871 return err;
872
873 for (i = 0; i < quadlets; ++i)
874 be32_to_cpus(&((u32 *)buffer)[i]);
875
876 return 0;
877}
878
879static const char *str_from_array(const char *const strs[], unsigned int count,
880 unsigned int i)
881{
882 if (i < count)
883 return strs[i];
884 else
885 return "(unknown)";
886}
887
888static void dice_proc_fixup_string(char *s, unsigned int size)
889{
890 unsigned int i;
891
892 for (i = 0; i < size; i += 4)
893 cpu_to_le32s((u32 *)(s + i));
894
895 for (i = 0; i < size - 2; ++i) {
896 if (s[i] == '\0')
897 return;
898 if (s[i] == '\\' && s[i + 1] == '\\') {
899 s[i + 2] = '\0';
900 return;
901 }
902 }
903 s[size - 1] = '\0';
904}
905
906static void dice_proc_read(struct snd_info_entry *entry,
907 struct snd_info_buffer *buffer)
908{
909 static const char *const section_names[5] = {
910 "global", "tx", "rx", "ext_sync", "unused2"
911 };
912 static const char *const clock_sources[] = {
913 "aes1", "aes2", "aes3", "aes4", "aes", "adat", "tdif",
914 "wc", "arx1", "arx2", "arx3", "arx4", "internal"
915 };
916 static const char *const rates[] = {
917 "32000", "44100", "48000", "88200", "96000", "176400", "192000",
918 "any low", "any mid", "any high", "none"
919 };
920 struct dice *dice = entry->private_data;
921 u32 sections[ARRAY_SIZE(section_names) * 2];
922 struct {
923 u32 number;
924 u32 size;
925 } tx_rx_header;
926 union {
927 struct {
928 u32 owner_hi, owner_lo;
929 u32 notification;
930 char nick_name[NICK_NAME_SIZE];
931 u32 clock_select;
932 u32 enable;
933 u32 status;
934 u32 extended_status;
935 u32 sample_rate;
936 u32 version;
937 u32 clock_caps;
938 char clock_source_names[CLOCK_SOURCE_NAMES_SIZE];
939 } global;
940 struct {
941 u32 iso;
942 u32 number_audio;
943 u32 number_midi;
944 u32 speed;
945 char names[TX_NAMES_SIZE];
946 u32 ac3_caps;
947 u32 ac3_enable;
948 } tx;
949 struct {
950 u32 iso;
951 u32 seq_start;
952 u32 number_audio;
953 u32 number_midi;
954 char names[RX_NAMES_SIZE];
955 u32 ac3_caps;
956 u32 ac3_enable;
957 } rx;
958 struct {
959 u32 clock_source;
960 u32 locked;
961 u32 rate;
962 u32 adat_user_data;
963 } ext_sync;
964 } buf;
965 unsigned int quadlets, stream, i;
966
967 if (dice_proc_read_mem(dice, sections, 0, ARRAY_SIZE(sections)) < 0)
968 return;
969 snd_iprintf(buffer, "sections:\n");
970 for (i = 0; i < ARRAY_SIZE(section_names); ++i)
971 snd_iprintf(buffer, " %s: offset %u, size %u\n",
972 section_names[i],
973 sections[i * 2], sections[i * 2 + 1]);
974
975 quadlets = min_t(u32, sections[1], sizeof(buf.global) / 4);
976 if (dice_proc_read_mem(dice, &buf.global, sections[0], quadlets) < 0)
977 return;
978 snd_iprintf(buffer, "global:\n");
979 snd_iprintf(buffer, " owner: %04x:%04x%08x\n",
980 buf.global.owner_hi >> 16,
981 buf.global.owner_hi & 0xffff, buf.global.owner_lo);
982 snd_iprintf(buffer, " notification: %08x\n", buf.global.notification);
983 dice_proc_fixup_string(buf.global.nick_name, NICK_NAME_SIZE);
984 snd_iprintf(buffer, " nick name: %s\n", buf.global.nick_name);
985 snd_iprintf(buffer, " clock select: %s %s\n",
986 str_from_array(clock_sources, ARRAY_SIZE(clock_sources),
987 buf.global.clock_select & CLOCK_SOURCE_MASK),
988 str_from_array(rates, ARRAY_SIZE(rates),
989 (buf.global.clock_select & CLOCK_RATE_MASK)
990 >> CLOCK_RATE_SHIFT));
991 snd_iprintf(buffer, " enable: %u\n", buf.global.enable);
992 snd_iprintf(buffer, " status: %slocked %s\n",
993 buf.global.status & STATUS_SOURCE_LOCKED ? "" : "un",
994 str_from_array(rates, ARRAY_SIZE(rates),
995 (buf.global.status &
996 STATUS_NOMINAL_RATE_MASK)
997 >> CLOCK_RATE_SHIFT));
998 snd_iprintf(buffer, " ext status: %08x\n", buf.global.extended_status);
999 snd_iprintf(buffer, " sample rate: %u\n", buf.global.sample_rate);
1000 snd_iprintf(buffer, " version: %u.%u.%u.%u\n",
1001 (buf.global.version >> 24) & 0xff,
1002 (buf.global.version >> 16) & 0xff,
1003 (buf.global.version >> 8) & 0xff,
1004 (buf.global.version >> 0) & 0xff);
1005 if (quadlets >= 90) {
1006 snd_iprintf(buffer, " clock caps:");
1007 for (i = 0; i <= 6; ++i)
1008 if (buf.global.clock_caps & (1 << i))
1009 snd_iprintf(buffer, " %s", rates[i]);
1010 for (i = 0; i <= 12; ++i)
1011 if (buf.global.clock_caps & (1 << (16 + i)))
1012 snd_iprintf(buffer, " %s", clock_sources[i]);
1013 snd_iprintf(buffer, "\n");
1014 dice_proc_fixup_string(buf.global.clock_source_names,
1015 CLOCK_SOURCE_NAMES_SIZE);
1016 snd_iprintf(buffer, " clock source names: %s\n",
1017 buf.global.clock_source_names);
1018 }
1019
1020 if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
1021 return;
1022 quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx));
1023 for (stream = 0; stream < tx_rx_header.number; ++stream) {
1024 if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
1025 stream * tx_rx_header.size,
1026 quadlets) < 0)
1027 break;
1028 snd_iprintf(buffer, "tx %u:\n", stream);
1029 snd_iprintf(buffer, " iso channel: %d\n", (int)buf.tx.iso);
1030 snd_iprintf(buffer, " audio channels: %u\n",
1031 buf.tx.number_audio);
1032 snd_iprintf(buffer, " midi ports: %u\n", buf.tx.number_midi);
1033 snd_iprintf(buffer, " speed: S%u\n", 100u << buf.tx.speed);
1034 if (quadlets >= 68) {
1035 dice_proc_fixup_string(buf.tx.names, TX_NAMES_SIZE);
1036 snd_iprintf(buffer, " names: %s\n", buf.tx.names);
1037 }
1038 if (quadlets >= 70) {
1039 snd_iprintf(buffer, " ac3 caps: %08x\n",
1040 buf.tx.ac3_caps);
1041 snd_iprintf(buffer, " ac3 enable: %08x\n",
1042 buf.tx.ac3_enable);
1043 }
1044 }
1045
1046 if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
1047 return;
1048 quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx));
1049 for (stream = 0; stream < tx_rx_header.number; ++stream) {
1050 if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
1051 stream * tx_rx_header.size,
1052 quadlets) < 0)
1053 break;
1054 snd_iprintf(buffer, "rx %u:\n", stream);
1055 snd_iprintf(buffer, " iso channel: %d\n", (int)buf.rx.iso);
1056 snd_iprintf(buffer, " sequence start: %u\n", buf.rx.seq_start);
1057 snd_iprintf(buffer, " audio channels: %u\n",
1058 buf.rx.number_audio);
1059 snd_iprintf(buffer, " midi ports: %u\n", buf.rx.number_midi);
1060 if (quadlets >= 68) {
1061 dice_proc_fixup_string(buf.rx.names, RX_NAMES_SIZE);
1062 snd_iprintf(buffer, " names: %s\n", buf.rx.names);
1063 }
1064 if (quadlets >= 70) {
1065 snd_iprintf(buffer, " ac3 caps: %08x\n",
1066 buf.rx.ac3_caps);
1067 snd_iprintf(buffer, " ac3 enable: %08x\n",
1068 buf.rx.ac3_enable);
1069 }
1070 }
1071
1072 quadlets = min_t(u32, sections[7], sizeof(buf.ext_sync) / 4);
1073 if (quadlets >= 4) {
1074 if (dice_proc_read_mem(dice, &buf.ext_sync,
1075 sections[6], 4) < 0)
1076 return;
1077 snd_iprintf(buffer, "ext status:\n");
1078 snd_iprintf(buffer, " clock source: %s\n",
1079 str_from_array(clock_sources,
1080 ARRAY_SIZE(clock_sources),
1081 buf.ext_sync.clock_source));
1082 snd_iprintf(buffer, " locked: %u\n", buf.ext_sync.locked);
1083 snd_iprintf(buffer, " rate: %s\n",
1084 str_from_array(rates, ARRAY_SIZE(rates),
1085 buf.ext_sync.rate));
1086 snd_iprintf(buffer, " adat user data: ");
1087 if (buf.ext_sync.adat_user_data & ADAT_USER_DATA_NO_DATA)
1088 snd_iprintf(buffer, "-\n");
1089 else
1090 snd_iprintf(buffer, "%x\n",
1091 buf.ext_sync.adat_user_data);
1092 }
1093}
1094
1095static void dice_create_proc(struct dice *dice)
1096{
1097 struct snd_info_entry *entry;
1098
1099 if (!snd_card_proc_new(dice->card, "dice", &entry))
1100 snd_info_set_text_ops(entry, dice, dice_proc_read);
1101}
1102
1103static void dice_card_free(struct snd_card *card)
1104{
1105 struct dice *dice = card->private_data;
1106
1107 amdtp_out_stream_destroy(&dice->stream);
1108 fw_core_remove_address_handler(&dice->notification_handler);
1109 mutex_destroy(&dice->mutex);
1110}
1111
1112#define OUI_WEISS 0x001c6a
1113
1114#define DICE_CATEGORY_ID 0x04
1115#define WEISS_CATEGORY_ID 0x00
1116
1117static int dice_interface_check(struct fw_unit *unit)
1118{
1119 static const int min_values[10] = {
1120 10, 0x64 / 4,
1121 10, 0x18 / 4,
1122 10, 0x18 / 4,
1123 0, 0,
1124 0, 0,
1125 };
1126 struct fw_device *device = fw_parent_device(unit);
1127 struct fw_csr_iterator it;
1128 int key, value, vendor = -1, model = -1, err;
1129 unsigned int category, i;
1130 __be32 pointers[ARRAY_SIZE(min_values)];
1131 __be32 tx_data[4];
1132 __be32 version;
1133
1134 /*
1135 * Check that GUID and unit directory are constructed according to DICE
1136 * rules, i.e., that the specifier ID is the GUID's OUI, and that the
1137 * GUID chip ID consists of the 8-bit category ID, the 10-bit product
1138 * ID, and a 22-bit serial number.
1139 */
1140 fw_csr_iterator_init(&it, unit->directory);
1141 while (fw_csr_iterator_next(&it, &key, &value)) {
1142 switch (key) {
1143 case CSR_SPECIFIER_ID:
1144 vendor = value;
1145 break;
1146 case CSR_MODEL:
1147 model = value;
1148 break;
1149 }
1150 }
1151 if (vendor == OUI_WEISS)
1152 category = WEISS_CATEGORY_ID;
1153 else
1154 category = DICE_CATEGORY_ID;
1155 if (device->config_rom[3] != ((vendor << 8) | category) ||
1156 device->config_rom[4] >> 22 != model)
1157 return -ENODEV;
1158
1159 /*
1160 * Check that the sub address spaces exist and are located inside the
1161 * private address space. The minimum values are chosen so that all
1162 * minimally required registers are included.
1163 */
1164 err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
1165 DICE_PRIVATE_SPACE,
1166 pointers, sizeof(pointers), 0);
1167 if (err < 0)
1168 return -ENODEV;
1169 for (i = 0; i < ARRAY_SIZE(pointers); ++i) {
1170 value = be32_to_cpu(pointers[i]);
1171 if (value < min_values[i] || value >= 0x40000)
1172 return -ENODEV;
1173 }
1174
1175 /* We support playback only. Let capture devices be handled by FFADO. */
1176 err = snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
1177 DICE_PRIVATE_SPACE +
1178 be32_to_cpu(pointers[2]) * 4,
1179 tx_data, sizeof(tx_data), 0);
1180 if (err < 0 || (tx_data[0] && tx_data[3]))
1181 return -ENODEV;
1182
1183 /*
1184 * Check that the implemented DICE driver specification major version
1185 * number matches.
1186 */
1187 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
1188 DICE_PRIVATE_SPACE +
1189 be32_to_cpu(pointers[0]) * 4 + GLOBAL_VERSION,
1190 &version, 4, 0);
1191 if (err < 0)
1192 return -ENODEV;
1193 if ((version & cpu_to_be32(0xff000000)) != cpu_to_be32(0x01000000)) {
1194 dev_err(&unit->device,
1195 "unknown DICE version: 0x%08x\n", be32_to_cpu(version));
1196 return -ENODEV;
1197 }
1198
1199 return 0;
1200}
1201
1202static int highest_supported_mode_rate(struct dice *dice, unsigned int mode)
1203{
1204 int i;
1205
1206 for (i = ARRAY_SIZE(dice_rates) - 1; i >= 0; --i)
1207 if ((dice->clock_caps & (1 << i)) &&
1208 rate_index_to_mode(i) == mode)
1209 return i;
1210
1211 return -1;
1212}
1213
1214static int dice_read_mode_params(struct dice *dice, unsigned int mode)
1215{
1216 __be32 values[2];
1217 int rate_index, err;
1218
1219 rate_index = highest_supported_mode_rate(dice, mode);
1220 if (rate_index < 0) {
1221 dice->rx_channels[mode] = 0;
1222 dice->rx_midi_ports[mode] = 0;
1223 return 0;
1224 }
1225
1226 err = dice_change_rate(dice, rate_index << CLOCK_RATE_SHIFT);
1227 if (err < 0)
1228 return err;
1229
1230 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
1231 rx_address(dice, RX_NUMBER_AUDIO),
1232 values, 2 * 4, 0);
1233 if (err < 0)
1234 return err;
1235
1236 dice->rx_channels[mode] = be32_to_cpu(values[0]);
1237 dice->rx_midi_ports[mode] = be32_to_cpu(values[1]);
1238
1239 return 0;
1240}
1241
1242static int dice_read_params(struct dice *dice)
1243{
1244 __be32 pointers[6];
1245 __be32 value;
1246 int mode, err;
1247
1248 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
1249 DICE_PRIVATE_SPACE,
1250 pointers, sizeof(pointers), 0);
1251 if (err < 0)
1252 return err;
1253
1254 dice->global_offset = be32_to_cpu(pointers[0]) * 4;
1255 dice->rx_offset = be32_to_cpu(pointers[4]) * 4;
1256
1257 /* some very old firmwares don't tell about their clock support */
1258 if (be32_to_cpu(pointers[1]) * 4 >= GLOBAL_CLOCK_CAPABILITIES + 4) {
1259 err = snd_fw_transaction(
1260 dice->unit, TCODE_READ_QUADLET_REQUEST,
1261 global_address(dice, GLOBAL_CLOCK_CAPABILITIES),
1262 &value, 4, 0);
1263 if (err < 0)
1264 return err;
1265 dice->clock_caps = be32_to_cpu(value);
1266 } else {
1267 /* this should be supported by any device */
1268 dice->clock_caps = CLOCK_CAP_RATE_44100 |
1269 CLOCK_CAP_RATE_48000 |
1270 CLOCK_CAP_SOURCE_ARX1 |
1271 CLOCK_CAP_SOURCE_INTERNAL;
1272 }
1273
1274 for (mode = 2; mode >= 0; --mode) {
1275 err = dice_read_mode_params(dice, mode);
1276 if (err < 0)
1277 return err;
1278 }
1279
1280 return 0;
1281}
1282
1283static void dice_card_strings(struct dice *dice)
1284{
1285 struct snd_card *card = dice->card;
1286 struct fw_device *dev = fw_parent_device(dice->unit);
1287 char vendor[32], model[32];
1288 unsigned int i;
1289 int err;
1290
1291 strcpy(card->driver, "DICE");
1292
1293 strcpy(card->shortname, "DICE");
1294 BUILD_BUG_ON(NICK_NAME_SIZE < sizeof(card->shortname));
1295 err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
1296 global_address(dice, GLOBAL_NICK_NAME),
1297 card->shortname, sizeof(card->shortname), 0);
1298 if (err >= 0) {
1299 /* DICE strings are returned in "always-wrong" endianness */
1300 BUILD_BUG_ON(sizeof(card->shortname) % 4 != 0);
1301 for (i = 0; i < sizeof(card->shortname); i += 4)
1302 swab32s((u32 *)&card->shortname[i]);
1303 card->shortname[sizeof(card->shortname) - 1] = '\0';
1304 }
1305
1306 strcpy(vendor, "?");
1307 fw_csr_string(dev->config_rom + 5, CSR_VENDOR, vendor, sizeof(vendor));
1308 strcpy(model, "?");
1309 fw_csr_string(dice->unit->directory, CSR_MODEL, model, sizeof(model));
1310 snprintf(card->longname, sizeof(card->longname),
1311 "%s %s (serial %u) at %s, S%d",
1312 vendor, model, dev->config_rom[4] & 0x3fffff,
1313 dev_name(&dice->unit->device), 100 << dev->max_speed);
1314
1315 strcpy(card->mixername, "DICE");
1316}
1317
1318static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
1319{
1320 struct snd_card *card;
1321 struct dice *dice;
1322 __be32 clock_sel;
1323 int err;
1324
1325 err = dice_interface_check(unit);
1326 if (err < 0)
1327 return err;
1328
1329 err = snd_card_create(-1, NULL, THIS_MODULE, sizeof(*dice), &card);
1330 if (err < 0)
1331 return err;
1332 snd_card_set_dev(card, &unit->device);
1333
1334 dice = card->private_data;
1335 dice->card = card;
1336 spin_lock_init(&dice->lock);
1337 mutex_init(&dice->mutex);
1338 dice->unit = unit;
1339 init_completion(&dice->clock_accepted);
1340 init_waitqueue_head(&dice->hwdep_wait);
1341
1342 dice->notification_handler.length = 4;
1343 dice->notification_handler.address_callback = dice_notification;
1344 dice->notification_handler.callback_data = dice;
1345 err = fw_core_add_address_handler(&dice->notification_handler,
1346 &fw_high_memory_region);
1347 if (err < 0)
1348 goto err_mutex;
1349
1350 err = dice_owner_set(dice);
1351 if (err < 0)
1352 goto err_notification_handler;
1353
1354 err = dice_read_params(dice);
1355 if (err < 0)
1356 goto err_owner;
1357
1358 err = fw_iso_resources_init(&dice->resources, unit);
1359 if (err < 0)
1360 goto err_owner;
1361 dice->resources.channels_mask = 0x00000000ffffffffuLL;
1362
1363 err = amdtp_out_stream_init(&dice->stream, unit,
1364 CIP_BLOCKING | CIP_HI_DUALWIRE);
1365 if (err < 0)
1366 goto err_resources;
1367
1368 card->private_free = dice_card_free;
1369
1370 dice_card_strings(dice);
1371
1372 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
1373 global_address(dice, GLOBAL_CLOCK_SELECT),
1374 &clock_sel, 4, 0);
1375 if (err < 0)
1376 goto error;
1377 clock_sel &= cpu_to_be32(~CLOCK_SOURCE_MASK);
1378 clock_sel |= cpu_to_be32(CLOCK_SOURCE_ARX1);
1379 err = snd_fw_transaction(unit, TCODE_WRITE_QUADLET_REQUEST,
1380 global_address(dice, GLOBAL_CLOCK_SELECT),
1381 &clock_sel, 4, 0);
1382 if (err < 0)
1383 goto error;
1384
1385 err = dice_create_pcm(dice);
1386 if (err < 0)
1387 goto error;
1388
1389 err = dice_create_hwdep(dice);
1390 if (err < 0)
1391 goto error;
1392
1393 dice_create_proc(dice);
1394
1395 err = snd_card_register(card);
1396 if (err < 0)
1397 goto error;
1398
1399 dev_set_drvdata(&unit->device, dice);
1400
1401 return 0;
1402
1403err_resources:
1404 fw_iso_resources_destroy(&dice->resources);
1405err_owner:
1406 dice_owner_clear(dice);
1407err_notification_handler:
1408 fw_core_remove_address_handler(&dice->notification_handler);
1409err_mutex:
1410 mutex_destroy(&dice->mutex);
1411error:
1412 snd_card_free(card);
1413 return err;
1414}
1415
1416static void dice_remove(struct fw_unit *unit)
1417{
1418 struct dice *dice = dev_get_drvdata(&unit->device);
1419
1420 amdtp_out_stream_pcm_abort(&dice->stream);
1421
1422 snd_card_disconnect(dice->card);
1423
1424 mutex_lock(&dice->mutex);
1425
1426 dice_stream_stop(dice);
1427 dice_owner_clear(dice);
1428
1429 mutex_unlock(&dice->mutex);
1430
1431 snd_card_free_when_closed(dice->card);
1432}
1433
1434static void dice_bus_reset(struct fw_unit *unit)
1435{
1436 struct dice *dice = dev_get_drvdata(&unit->device);
1437
1438 /*
1439 * On a bus reset, the DICE firmware disables streaming and then goes
1440 * off contemplating its own navel for hundreds of milliseconds before
1441 * it can react to any of our attempts to reenable streaming. This
1442 * means that we lose synchronization anyway, so we force our streams
1443 * to stop so that the application can restart them in an orderly
1444 * manner.
1445 */
1446 amdtp_out_stream_pcm_abort(&dice->stream);
1447
1448 mutex_lock(&dice->mutex);
1449
1450 dice->global_enabled = false;
1451 dice_stream_stop_packets(dice);
1452
1453 dice_owner_update(dice);
1454
1455 fw_iso_resources_update(&dice->resources);
1456
1457 mutex_unlock(&dice->mutex);
1458}
1459
1460#define DICE_INTERFACE 0x000001
1461
1462static const struct ieee1394_device_id dice_id_table[] = {
1463 {
1464 .match_flags = IEEE1394_MATCH_VERSION,
1465 .version = DICE_INTERFACE,
1466 },
1467 { }
1468};
1469MODULE_DEVICE_TABLE(ieee1394, dice_id_table);
1470
1471static struct fw_driver dice_driver = {
1472 .driver = {
1473 .owner = THIS_MODULE,
1474 .name = KBUILD_MODNAME,
1475 .bus = &fw_bus_type,
1476 },
1477 .probe = dice_probe,
1478 .update = dice_bus_reset,
1479 .remove = dice_remove,
1480 .id_table = dice_id_table,
1481};
1482
1483static int __init alsa_dice_init(void)
1484{
1485 return driver_register(&dice_driver.driver);
1486}
1487
1488static void __exit alsa_dice_exit(void)
1489{
1490 driver_unregister(&dice_driver.driver);
1491}
1492
1493module_init(alsa_dice_init);
1494module_exit(alsa_dice_exit);
diff --git a/sound/firewire/fcp.c b/sound/firewire/fcp.c
index ec578b5ad8da..860c08073c59 100644
--- a/sound/firewire/fcp.c
+++ b/sound/firewire/fcp.c
@@ -90,7 +90,7 @@ int fcp_avc_transaction(struct fw_unit *unit,
90 : TCODE_WRITE_BLOCK_REQUEST; 90 : TCODE_WRITE_BLOCK_REQUEST;
91 ret = snd_fw_transaction(t.unit, tcode, 91 ret = snd_fw_transaction(t.unit, tcode,
92 CSR_REGISTER_BASE + CSR_FCP_COMMAND, 92 CSR_REGISTER_BASE + CSR_FCP_COMMAND,
93 (void *)command, command_size); 93 (void *)command, command_size, 0);
94 if (ret < 0) 94 if (ret < 0)
95 break; 95 break;
96 96
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
index 58a5afefdc69..fd42e6b315e6 100644
--- a/sound/firewire/isight.c
+++ b/sound/firewire/isight.c
@@ -217,7 +217,7 @@ static void isight_packet(struct fw_iso_context *context, u32 cycle,
217 217
218static int isight_connect(struct isight *isight) 218static int isight_connect(struct isight *isight)
219{ 219{
220 int ch, err, rcode, errors = 0; 220 int ch, err;
221 __be32 value; 221 __be32 value;
222 222
223retry_after_bus_reset: 223retry_after_bus_reset:
@@ -230,27 +230,19 @@ retry_after_bus_reset:
230 } 230 }
231 231
232 value = cpu_to_be32(ch | (isight->device->max_speed << SPEED_SHIFT)); 232 value = cpu_to_be32(ch | (isight->device->max_speed << SPEED_SHIFT));
233 for (;;) { 233 err = snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST,
234 rcode = fw_run_transaction( 234 isight->audio_base + REG_ISO_TX_CONFIG,
235 isight->device->card, 235 &value, 4, FW_FIXED_GENERATION |
236 TCODE_WRITE_QUADLET_REQUEST, 236 isight->resources.generation);
237 isight->device->node_id, 237 if (err == -EAGAIN) {
238 isight->resources.generation, 238 fw_iso_resources_free(&isight->resources);
239 isight->device->max_speed, 239 goto retry_after_bus_reset;
240 isight->audio_base + REG_ISO_TX_CONFIG, 240 } else if (err < 0) {
241 &value, 4); 241 goto err_resources;
242 if (rcode == RCODE_COMPLETE) {
243 return 0;
244 } else if (rcode == RCODE_GENERATION) {
245 fw_iso_resources_free(&isight->resources);
246 goto retry_after_bus_reset;
247 } else if (rcode_is_permanent_error(rcode) || ++errors >= 3) {
248 err = -EIO;
249 goto err_resources;
250 }
251 msleep(5);
252 } 242 }
253 243
244 return 0;
245
254err_resources: 246err_resources:
255 fw_iso_resources_free(&isight->resources); 247 fw_iso_resources_free(&isight->resources);
256error: 248error:
@@ -315,17 +307,19 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
315static int reg_read(struct isight *isight, int offset, __be32 *value) 307static int reg_read(struct isight *isight, int offset, __be32 *value)
316{ 308{
317 return snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST, 309 return snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST,
318 isight->audio_base + offset, value, 4); 310 isight->audio_base + offset, value, 4, 0);
319} 311}
320 312
321static int reg_write(struct isight *isight, int offset, __be32 value) 313static int reg_write(struct isight *isight, int offset, __be32 value)
322{ 314{
323 return snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST, 315 return snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST,
324 isight->audio_base + offset, &value, 4); 316 isight->audio_base + offset, &value, 4, 0);
325} 317}
326 318
327static void isight_stop_streaming(struct isight *isight) 319static void isight_stop_streaming(struct isight *isight)
328{ 320{
321 __be32 value;
322
329 if (!isight->context) 323 if (!isight->context)
330 return; 324 return;
331 325
@@ -333,7 +327,10 @@ static void isight_stop_streaming(struct isight *isight)
333 fw_iso_context_destroy(isight->context); 327 fw_iso_context_destroy(isight->context);
334 isight->context = NULL; 328 isight->context = NULL;
335 fw_iso_resources_free(&isight->resources); 329 fw_iso_resources_free(&isight->resources);
336 reg_write(isight, REG_AUDIO_ENABLE, 0); 330 value = 0;
331 snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST,
332 isight->audio_base + REG_AUDIO_ENABLE,
333 &value, 4, FW_QUIET);
337} 334}
338 335
339static int isight_hw_free(struct snd_pcm_substream *substream) 336static int isight_hw_free(struct snd_pcm_substream *substream)
diff --git a/sound/firewire/lib.c b/sound/firewire/lib.c
index 14eb41498372..7409edba9f06 100644
--- a/sound/firewire/lib.c
+++ b/sound/firewire/lib.c
@@ -11,7 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include "lib.h" 12#include "lib.h"
13 13
14#define ERROR_RETRY_DELAY_MS 5 14#define ERROR_RETRY_DELAY_MS 20
15 15
16/** 16/**
17 * snd_fw_transaction - send a request and wait for its completion 17 * snd_fw_transaction - send a request and wait for its completion
@@ -20,6 +20,9 @@
20 * @offset: the address in the target's address space 20 * @offset: the address in the target's address space
21 * @buffer: input/output data 21 * @buffer: input/output data
22 * @length: length of @buffer 22 * @length: length of @buffer
23 * @flags: use %FW_FIXED_GENERATION and add the generation value to attempt the
24 * request only in that generation; use %FW_QUIET to suppress error
25 * messages
23 * 26 *
24 * Submits an asynchronous request to the target device, and waits for the 27 * Submits an asynchronous request to the target device, and waits for the
25 * response. The node ID and the current generation are derived from @unit. 28 * response. The node ID and the current generation are derived from @unit.
@@ -27,14 +30,18 @@
27 * Returns zero on success, or a negative error code. 30 * Returns zero on success, or a negative error code.
28 */ 31 */
29int snd_fw_transaction(struct fw_unit *unit, int tcode, 32int snd_fw_transaction(struct fw_unit *unit, int tcode,
30 u64 offset, void *buffer, size_t length) 33 u64 offset, void *buffer, size_t length,
34 unsigned int flags)
31{ 35{
32 struct fw_device *device = fw_parent_device(unit); 36 struct fw_device *device = fw_parent_device(unit);
33 int generation, rcode, tries = 0; 37 int generation, rcode, tries = 0;
34 38
39 generation = flags & FW_GENERATION_MASK;
35 for (;;) { 40 for (;;) {
36 generation = device->generation; 41 if (!(flags & FW_FIXED_GENERATION)) {
37 smp_rmb(); /* node_id vs. generation */ 42 generation = device->generation;
43 smp_rmb(); /* node_id vs. generation */
44 }
38 rcode = fw_run_transaction(device->card, tcode, 45 rcode = fw_run_transaction(device->card, tcode,
39 device->node_id, generation, 46 device->node_id, generation,
40 device->max_speed, offset, 47 device->max_speed, offset,
@@ -43,9 +50,14 @@ int snd_fw_transaction(struct fw_unit *unit, int tcode,
43 if (rcode == RCODE_COMPLETE) 50 if (rcode == RCODE_COMPLETE)
44 return 0; 51 return 0;
45 52
53 if (rcode == RCODE_GENERATION && (flags & FW_FIXED_GENERATION))
54 return -EAGAIN;
55
46 if (rcode_is_permanent_error(rcode) || ++tries >= 3) { 56 if (rcode_is_permanent_error(rcode) || ++tries >= 3) {
47 dev_err(&unit->device, "transaction failed: %s\n", 57 if (!(flags & FW_QUIET))
48 fw_rcode_string(rcode)); 58 dev_err(&unit->device,
59 "transaction failed: %s\n",
60 fw_rcode_string(rcode));
49 return -EIO; 61 return -EIO;
50 } 62 }
51 63
diff --git a/sound/firewire/lib.h b/sound/firewire/lib.h
index aef301476ea9..02cfabc9c3c4 100644
--- a/sound/firewire/lib.h
+++ b/sound/firewire/lib.h
@@ -6,8 +6,13 @@
6 6
7struct fw_unit; 7struct fw_unit;
8 8
9#define FW_GENERATION_MASK 0x00ff
10#define FW_FIXED_GENERATION 0x0100
11#define FW_QUIET 0x0200
12
9int snd_fw_transaction(struct fw_unit *unit, int tcode, 13int snd_fw_transaction(struct fw_unit *unit, int tcode,
10 u64 offset, void *buffer, size_t length); 14 u64 offset, void *buffer, size_t length,
15 unsigned int flags);
11 16
12/* returns true if retrying the transaction would not make sense */ 17/* returns true if retrying the transaction would not make sense */
13static inline bool rcode_is_permanent_error(int rcode) 18static inline bool rcode_is_permanent_error(int rcode)
diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
index 505fc8123199..858023cf4298 100644
--- a/sound/firewire/scs1x.c
+++ b/sound/firewire/scs1x.c
@@ -369,7 +369,7 @@ static int scs_init_hss_address(struct scs *scs)
369 data = cpu_to_be64(((u64)HSS1394_TAG_CHANGE_ADDRESS << 56) | 369 data = cpu_to_be64(((u64)HSS1394_TAG_CHANGE_ADDRESS << 56) |
370 scs->hss_handler.offset); 370 scs->hss_handler.offset);
371 err = snd_fw_transaction(scs->unit, TCODE_WRITE_BLOCK_REQUEST, 371 err = snd_fw_transaction(scs->unit, TCODE_WRITE_BLOCK_REQUEST,
372 HSS1394_ADDRESS, &data, 8); 372 HSS1394_ADDRESS, &data, 8, 0);
373 if (err < 0) 373 if (err < 0)
374 dev_err(&scs->unit->device, "HSS1394 communication failed\n"); 374 dev_err(&scs->unit->device, "HSS1394 communication failed\n");
375 375
@@ -455,12 +455,16 @@ err_card:
455static void scs_update(struct fw_unit *unit) 455static void scs_update(struct fw_unit *unit)
456{ 456{
457 struct scs *scs = dev_get_drvdata(&unit->device); 457 struct scs *scs = dev_get_drvdata(&unit->device);
458 int generation;
458 __be64 data; 459 __be64 data;
459 460
460 data = cpu_to_be64(((u64)HSS1394_TAG_CHANGE_ADDRESS << 56) | 461 data = cpu_to_be64(((u64)HSS1394_TAG_CHANGE_ADDRESS << 56) |
461 scs->hss_handler.offset); 462 scs->hss_handler.offset);
463 generation = fw_parent_device(unit)->generation;
464 smp_rmb(); /* node_id vs. generation */
462 snd_fw_transaction(scs->unit, TCODE_WRITE_BLOCK_REQUEST, 465 snd_fw_transaction(scs->unit, TCODE_WRITE_BLOCK_REQUEST,
463 HSS1394_ADDRESS, &data, 8); 466 HSS1394_ADDRESS, &data, 8,
467 FW_FIXED_GENERATION | generation);
464} 468}
465 469
466static void scs_remove(struct fw_unit *unit) 470static void scs_remove(struct fw_unit *unit)
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c
index fe9e6e2f2c5b..cc8bc3a51bc1 100644
--- a/sound/firewire/speakers.c
+++ b/sound/firewire/speakers.c
@@ -52,7 +52,6 @@ struct fwspk {
52 struct mutex mutex; 52 struct mutex mutex;
53 struct cmp_connection connection; 53 struct cmp_connection connection;
54 struct amdtp_out_stream stream; 54 struct amdtp_out_stream stream;
55 bool stream_running;
56 bool mute; 55 bool mute;
57 s16 volume[6]; 56 s16 volume[6];
58 s16 volume_min; 57 s16 volume_min;
@@ -188,10 +187,9 @@ static int fwspk_close(struct snd_pcm_substream *substream)
188 187
189static void fwspk_stop_stream(struct fwspk *fwspk) 188static void fwspk_stop_stream(struct fwspk *fwspk)
190{ 189{
191 if (fwspk->stream_running) { 190 if (amdtp_out_stream_running(&fwspk->stream)) {
192 amdtp_out_stream_stop(&fwspk->stream); 191 amdtp_out_stream_stop(&fwspk->stream);
193 cmp_connection_break(&fwspk->connection); 192 cmp_connection_break(&fwspk->connection);
194 fwspk->stream_running = false;
195 } 193 }
196} 194}
197 195
@@ -246,8 +244,10 @@ static int fwspk_hw_params(struct snd_pcm_substream *substream,
246 if (err < 0) 244 if (err < 0)
247 goto error; 245 goto error;
248 246
249 amdtp_out_stream_set_rate(&fwspk->stream, params_rate(hw_params)); 247 amdtp_out_stream_set_parameters(&fwspk->stream,
250 amdtp_out_stream_set_pcm(&fwspk->stream, params_channels(hw_params)); 248 params_rate(hw_params),
249 params_channels(hw_params),
250 0);
251 251
252 amdtp_out_stream_set_pcm_format(&fwspk->stream, 252 amdtp_out_stream_set_pcm_format(&fwspk->stream,
253 params_format(hw_params)); 253 params_format(hw_params));
@@ -285,7 +285,7 @@ static int fwspk_prepare(struct snd_pcm_substream *substream)
285 if (amdtp_out_streaming_error(&fwspk->stream)) 285 if (amdtp_out_streaming_error(&fwspk->stream))
286 fwspk_stop_stream(fwspk); 286 fwspk_stop_stream(fwspk);
287 287
288 if (!fwspk->stream_running) { 288 if (!amdtp_out_stream_running(&fwspk->stream)) {
289 err = cmp_connection_establish(&fwspk->connection, 289 err = cmp_connection_establish(&fwspk->connection,
290 amdtp_out_stream_get_max_payload(&fwspk->stream)); 290 amdtp_out_stream_get_max_payload(&fwspk->stream));
291 if (err < 0) 291 if (err < 0)
@@ -296,8 +296,6 @@ static int fwspk_prepare(struct snd_pcm_substream *substream)
296 fwspk->connection.speed); 296 fwspk->connection.speed);
297 if (err < 0) 297 if (err < 0)
298 goto err_connection; 298 goto err_connection;
299
300 fwspk->stream_running = true;
301 } 299 }
302 300
303 mutex_unlock(&fwspk->mutex); 301 mutex_unlock(&fwspk->mutex);
@@ -647,7 +645,7 @@ static u32 fwspk_read_firmware_version(struct fw_unit *unit)
647 int err; 645 int err;
648 646
649 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST, 647 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
650 OXFORD_FIRMWARE_ID_ADDRESS, &data, 4); 648 OXFORD_FIRMWARE_ID_ADDRESS, &data, 4, 0);
651 return err >= 0 ? be32_to_cpu(data) : 0; 649 return err >= 0 ? be32_to_cpu(data) : 0;
652} 650}
653 651
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index 5bf4fca19e48..15ae0250eace 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -60,7 +60,7 @@ static void reg_dump(struct ak4114 *ak4114)
60 60
61 printk(KERN_DEBUG "AK4114 REG DUMP:\n"); 61 printk(KERN_DEBUG "AK4114 REG DUMP:\n");
62 for (i = 0; i < 0x20; i++) 62 for (i = 0; i < 0x20; i++)
63 printk(KERN_DEBUG "reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < sizeof(ak4114->regmap) ? ak4114->regmap[i] : 0); 63 printk(KERN_DEBUG "reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < ARRAY_SIZE(ak4114->regmap) ? ak4114->regmap[i] : 0);
64} 64}
65#endif 65#endif
66 66
@@ -81,7 +81,7 @@ static int snd_ak4114_dev_free(struct snd_device *device)
81 81
82int snd_ak4114_create(struct snd_card *card, 82int snd_ak4114_create(struct snd_card *card,
83 ak4114_read_t *read, ak4114_write_t *write, 83 ak4114_read_t *read, ak4114_write_t *write,
84 const unsigned char pgm[7], const unsigned char txcsb[5], 84 const unsigned char pgm[6], const unsigned char txcsb[5],
85 void *private_data, struct ak4114 **r_ak4114) 85 void *private_data, struct ak4114 **r_ak4114)
86{ 86{
87 struct ak4114 *chip; 87 struct ak4114 *chip;
@@ -101,7 +101,7 @@ int snd_ak4114_create(struct snd_card *card,
101 chip->private_data = private_data; 101 chip->private_data = private_data;
102 INIT_DELAYED_WORK(&chip->work, ak4114_stats); 102 INIT_DELAYED_WORK(&chip->work, ak4114_stats);
103 103
104 for (reg = 0; reg < 7; reg++) 104 for (reg = 0; reg < 6; reg++)
105 chip->regmap[reg] = pgm[reg]; 105 chip->regmap[reg] = pgm[reg];
106 for (reg = 0; reg < 5; reg++) 106 for (reg = 0; reg < 5; reg++)
107 chip->txcsb[reg] = txcsb[reg]; 107 chip->txcsb[reg] = txcsb[reg];
@@ -142,7 +142,7 @@ static void ak4114_init_regs(struct ak4114 *chip)
142 /* release reset, but leave powerdown */ 142 /* release reset, but leave powerdown */
143 reg_write(chip, AK4114_REG_PWRDN, (old | AK4114_RST) & ~AK4114_PWN); 143 reg_write(chip, AK4114_REG_PWRDN, (old | AK4114_RST) & ~AK4114_PWN);
144 udelay(200); 144 udelay(200);
145 for (reg = 1; reg < 7; reg++) 145 for (reg = 1; reg < 6; reg++)
146 reg_write(chip, reg, chip->regmap[reg]); 146 reg_write(chip, reg, chip->regmap[reg]);
147 for (reg = 0; reg < 5; reg++) 147 for (reg = 0; reg < 5; reg++)
148 reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]); 148 reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]);
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c
index ed726d1569e8..f3735e64791c 100644
--- a/sound/i2c/other/ak4xxx-adda.c
+++ b/sound/i2c/other/ak4xxx-adda.c
@@ -583,7 +583,7 @@ static int ak4xxx_capture_source_info(struct snd_kcontrol *kcontrol,
583 if (idx >= num_names) 583 if (idx >= num_names)
584 return -EINVAL; 584 return -EINVAL;
585 input_names = ak->adc_info[mixer_ch].input_names; 585 input_names = ak->adc_info[mixer_ch].input_names;
586 strncpy(uinfo->value.enumerated.name, input_names[idx], 586 strlcpy(uinfo->value.enumerated.name, input_names[idx],
587 sizeof(uinfo->value.enumerated.name)); 587 sizeof(uinfo->value.enumerated.name));
588 return 0; 588 return 0;
589} 589}
diff --git a/sound/isa/cmi8328.c b/sound/isa/cmi8328.c
index f84f073fc1e8..ab6b2dc043f1 100644
--- a/sound/isa/cmi8328.c
+++ b/sound/isa/cmi8328.c
@@ -126,6 +126,7 @@ static void snd_cmi8328_cfg_write(u16 port, u8 reg, u8 val)
126 outb(val, port + 3); /* yes, value goes to the same port as index */ 126 outb(val, port + 3); /* yes, value goes to the same port as index */
127} 127}
128 128
129#ifdef CONFIG_PM
129static void snd_cmi8328_cfg_save(u16 port, u8 cfg[]) 130static void snd_cmi8328_cfg_save(u16 port, u8 cfg[])
130{ 131{
131 cfg[0] = snd_cmi8328_cfg_read(port, CFG1); 132 cfg[0] = snd_cmi8328_cfg_read(port, CFG1);
@@ -139,6 +140,7 @@ static void snd_cmi8328_cfg_restore(u16 port, u8 cfg[])
139 snd_cmi8328_cfg_write(port, CFG2, cfg[1]); 140 snd_cmi8328_cfg_write(port, CFG2, cfg[1]);
140 snd_cmi8328_cfg_write(port, CFG3, cfg[2]); 141 snd_cmi8328_cfg_write(port, CFG3, cfg[2]);
141} 142}
143#endif /* CONFIG_PM */
142 144
143static int snd_cmi8328_mixer(struct snd_wss *chip) 145static int snd_cmi8328_mixer(struct snd_wss *chip)
144{ 146{
diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c
index 81aeb934261a..0a90bd6ae232 100644
--- a/sound/isa/msnd/msnd_pinnacle.c
+++ b/sound/isa/msnd/msnd_pinnacle.c
@@ -73,9 +73,11 @@
73#ifdef MSND_CLASSIC 73#ifdef MSND_CLASSIC
74# include "msnd_classic.h" 74# include "msnd_classic.h"
75# define LOGNAME "msnd_classic" 75# define LOGNAME "msnd_classic"
76# define DEV_NAME "msnd-classic"
76#else 77#else
77# include "msnd_pinnacle.h" 78# include "msnd_pinnacle.h"
78# define LOGNAME "snd_msnd_pinnacle" 79# define LOGNAME "snd_msnd_pinnacle"
80# define DEV_NAME "msnd-pinnacle"
79#endif 81#endif
80 82
81static void set_default_audio_parameters(struct snd_msnd *chip) 83static void set_default_audio_parameters(struct snd_msnd *chip)
@@ -1067,8 +1069,6 @@ static int snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
1067 return 0; 1069 return 0;
1068} 1070}
1069 1071
1070#define DEV_NAME "msnd-pinnacle"
1071
1072static struct isa_driver snd_msnd_driver = { 1072static struct isa_driver snd_msnd_driver = {
1073 .match = snd_msnd_isa_match, 1073 .match = snd_msnd_isa_match,
1074 .probe = snd_msnd_isa_probe, 1074 .probe = snd_msnd_isa_probe,
diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c
index c1aa21edcb65..48da2276683d 100644
--- a/sound/isa/sb/sb16_csp.c
+++ b/sound/isa/sb/sb16_csp.c
@@ -208,6 +208,7 @@ static int snd_sb_csp_ioctl(struct snd_hwdep * hw, struct file *file, unsigned i
208 switch (cmd) { 208 switch (cmd) {
209 /* get information */ 209 /* get information */
210 case SNDRV_SB_CSP_IOCTL_INFO: 210 case SNDRV_SB_CSP_IOCTL_INFO:
211 memset(&info, 0, sizeof(info));
211 *info.codec_name = *p->codec_name; 212 *info.codec_name = *p->codec_name;
212 info.func_nr = p->func_nr; 213 info.func_nr = p->func_nr;
213 info.acc_format = p->acc_format; 214 info.acc_format = p->acc_format;
diff --git a/sound/isa/wavefront/wavefront_synth.c b/sound/isa/wavefront/wavefront_synth.c
index a2f87f9488ee..e5db001363ee 100644
--- a/sound/isa/wavefront/wavefront_synth.c
+++ b/sound/isa/wavefront/wavefront_synth.c
@@ -1196,7 +1196,7 @@ wavefront_send_multisample (snd_wavefront_t *dev, wavefront_patch_info *header)
1196 int num_samples; 1196 int num_samples;
1197 unsigned char *msample_hdr; 1197 unsigned char *msample_hdr;
1198 1198
1199 msample_hdr = kmalloc(sizeof(WF_MSAMPLE_BYTES), GFP_KERNEL); 1199 msample_hdr = kmalloc(WF_MSAMPLE_BYTES, GFP_KERNEL);
1200 if (! msample_hdr) 1200 if (! msample_hdr)
1201 return -ENOMEM; 1201 return -ENOMEM;
1202 1202
diff --git a/sound/mips/ad1843.c b/sound/mips/ad1843.c
index c624510ec374..586907500ca5 100644
--- a/sound/mips/ad1843.c
+++ b/sound/mips/ad1843.c
@@ -276,7 +276,7 @@ static void ad1843_write_multi(struct snd_ad1843 *ad1843, int argcount, ...)
276 if (reg == -1) 276 if (reg == -1)
277 reg = fp->reg; 277 reg = fp->reg;
278 else 278 else
279 BUG_ON(reg != fp->reg); 279 WARN_ON(reg != fp->reg);
280 m = ((1 << fp->nbits) - 1) << fp->lo_bit; 280 m = ((1 << fp->nbits) - 1) << fp->lo_bit;
281 mask |= m; 281 mask |= m;
282 bits |= (value << fp->lo_bit) & m; 282 bits |= (value << fp->lo_bit) & m;
diff --git a/sound/oss/sb_ess.c b/sound/oss/sb_ess.c
index c0be085e4a20..0e7254bde4c2 100644
--- a/sound/oss/sb_ess.c
+++ b/sound/oss/sb_ess.c
@@ -1544,7 +1544,7 @@ static int ess_has_rec_mixer (int submodel)
1544 return 1; 1544 return 1;
1545 default: 1545 default:
1546 return 0; 1546 return 0;
1547 }; 1547 }
1548}; 1548};
1549 1549
1550#ifdef FKS_LOGGING 1550#ifdef FKS_LOGGING
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 445ca481d8d3..bf578ba2677e 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -175,6 +175,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = {
175{ 0x54524106, 0xffffffff, "TR28026", NULL, NULL }, 175{ 0x54524106, 0xffffffff, "TR28026", NULL, NULL },
176{ 0x54524108, 0xffffffff, "TR28028", patch_tritech_tr28028, NULL }, // added by xin jin [07/09/99] 176{ 0x54524108, 0xffffffff, "TR28028", patch_tritech_tr28028, NULL }, // added by xin jin [07/09/99]
177{ 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)] 177{ 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)]
178{ 0x54584e03, 0xffffffff, "TLV320AIC27", NULL, NULL },
178{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL }, 179{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL },
179{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF 180{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF
180{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF 181{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index d2b9d617aee5..b680d03e2419 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -739,7 +739,7 @@ snd_ad1889_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffe
739 reg = ad1889_readw(chip, AD_DS_WADA); 739 reg = ad1889_readw(chip, AD_DS_WADA);
740 snd_iprintf(buffer, "Right: %s, -%d dB\n", 740 snd_iprintf(buffer, "Right: %s, -%d dB\n",
741 (reg & AD_DS_WADA_RWAM) ? "mute" : "unmute", 741 (reg & AD_DS_WADA_RWAM) ? "mute" : "unmute",
742 ((reg & AD_DS_WADA_RWAA) >> 8) * 3); 742 (reg & AD_DS_WADA_RWAA) * 3);
743 743
744 reg = ad1889_readw(chip, AD_DS_WAS); 744 reg = ad1889_readw(chip, AD_DS_WAS);
745 snd_iprintf(buffer, "Wave samplerate: %u Hz\n", reg); 745 snd_iprintf(buffer, "Wave samplerate: %u Hz\n", reg);
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index 3dfa12b670eb..c6835a3d64fb 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -855,7 +855,6 @@ static void snd_ali_disable_spdif_out(struct snd_ali *codec)
855static void snd_ali_update_ptr(struct snd_ali *codec, int channel) 855static void snd_ali_update_ptr(struct snd_ali *codec, int channel)
856{ 856{
857 struct snd_ali_voice *pvoice; 857 struct snd_ali_voice *pvoice;
858 struct snd_pcm_runtime *runtime;
859 struct snd_ali_channel_control *pchregs; 858 struct snd_ali_channel_control *pchregs;
860 unsigned int old, mask; 859 unsigned int old, mask;
861#ifdef ALI_DEBUG 860#ifdef ALI_DEBUG
@@ -872,7 +871,6 @@ static void snd_ali_update_ptr(struct snd_ali *codec, int channel)
872 return; 871 return;
873 872
874 pvoice = &codec->synth.voices[channel]; 873 pvoice = &codec->synth.voices[channel];
875 runtime = pvoice->substream->runtime;
876 874
877 udelay(100); 875 udelay(100);
878 spin_lock(&codec->reg_lock); 876 spin_lock(&codec->reg_lock);
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
index dc632cdc3870..5f2acd35dcb9 100644
--- a/sound/pci/asihpi/asihpi.c
+++ b/sound/pci/asihpi/asihpi.c
@@ -1913,6 +1913,7 @@ static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1913 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol); 1913 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1914 */ 1914 */
1915 u32 h_control = kcontrol->private_value; 1915 u32 h_control = kcontrol->private_value;
1916 unsigned int idx;
1916 u16 band; 1917 u16 band;
1917 u16 tuner_bands[HPI_TUNER_BAND_LAST]; 1918 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1918 u32 num_bands = 0; 1919 u32 num_bands = 0;
@@ -1920,7 +1921,10 @@ static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1920 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands, 1921 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1921 HPI_TUNER_BAND_LAST); 1922 HPI_TUNER_BAND_LAST);
1922 1923
1923 band = tuner_bands[ucontrol->value.enumerated.item[0]]; 1924 idx = ucontrol->value.enumerated.item[0];
1925 if (idx >= ARRAY_SIZE(tuner_bands))
1926 idx = ARRAY_SIZE(tuner_bands) - 1;
1927 band = tuner_bands[idx];
1924 hpi_handle_error(hpi_tuner_set_band(h_control, band)); 1928 hpi_handle_error(hpi_tuner_set_band(h_control, band));
1925 1929
1926 return 1; 1930 return 1;
@@ -2383,7 +2387,8 @@ static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,
2383 struct snd_card_asihpi *asihpi = 2387 struct snd_card_asihpi *asihpi =
2384 (struct snd_card_asihpi *)(kcontrol->private_data); 2388 (struct snd_card_asihpi *)(kcontrol->private_data);
2385 struct clk_cache *clkcache = &asihpi->cc; 2389 struct clk_cache *clkcache = &asihpi->cc;
2386 int change, item; 2390 unsigned int item;
2391 int change;
2387 u32 h_control = kcontrol->private_value; 2392 u32 h_control = kcontrol->private_value;
2388 2393
2389 change = 1; 2394 change = 1;
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index b46dc9b24dbd..9fb03b4ea925 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -671,7 +671,7 @@ static int snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
671 return err; 671 return err;
672 break; 672 break;
673#endif 673#endif
674 }; 674 }
675 675
676 if (VORTEX_PCM_TYPE(pcm) == VORTEX_PCM_SPDIF) { 676 if (VORTEX_PCM_TYPE(pcm) == VORTEX_PCM_SPDIF) {
677 for (i = 0; i < ARRAY_SIZE(snd_vortex_mixer_spdif); i++) { 677 for (i = 0; i < ARRAY_SIZE(snd_vortex_mixer_spdif); i++) {
diff --git a/sound/pci/au88x0/au88x0_synth.c b/sound/pci/au88x0/au88x0_synth.c
index 8bef47311e45..922a84bba2ef 100644
--- a/sound/pci/au88x0/au88x0_synth.c
+++ b/sound/pci/au88x0/au88x0_synth.c
@@ -219,7 +219,6 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
219 */ 219 */
220 hwwrite(vortex->mmio, WT_RUN(wt), val); 220 hwwrite(vortex->mmio, WT_RUN(wt), val);
221 return 0xc; 221 return 0xc;
222 break;
223 case 1: /* param 0 */ 222 case 1: /* param 0 */
224 /* 223 /*
225 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", 224 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
@@ -227,7 +226,6 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
227 */ 226 */
228 hwwrite(vortex->mmio, WT_PARM(wt, 0), val); 227 hwwrite(vortex->mmio, WT_PARM(wt, 0), val);
229 return 0xc; 228 return 0xc;
230 break;
231 case 2: /* param 1 */ 229 case 2: /* param 1 */
232 /* 230 /*
233 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", 231 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
@@ -235,7 +233,6 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
235 */ 233 */
236 hwwrite(vortex->mmio, WT_PARM(wt, 1), val); 234 hwwrite(vortex->mmio, WT_PARM(wt, 1), val);
237 return 0xc; 235 return 0xc;
238 break;
239 case 3: /* param 2 */ 236 case 3: /* param 2 */
240 /* 237 /*
241 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", 238 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
@@ -243,7 +240,6 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
243 */ 240 */
244 hwwrite(vortex->mmio, WT_PARM(wt, 2), val); 241 hwwrite(vortex->mmio, WT_PARM(wt, 2), val);
245 return 0xc; 242 return 0xc;
246 break;
247 case 4: /* param 3 */ 243 case 4: /* param 3 */
248 /* 244 /*
249 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", 245 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
@@ -251,7 +247,6 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
251 */ 247 */
252 hwwrite(vortex->mmio, WT_PARM(wt, 3), val); 248 hwwrite(vortex->mmio, WT_PARM(wt, 3), val);
253 return 0xc; 249 return 0xc;
254 break;
255 case 6: /* mute */ 250 case 6: /* mute */
256 /* 251 /*
257 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", 252 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
@@ -259,20 +254,17 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
259 */ 254 */
260 hwwrite(vortex->mmio, WT_MUTE(wt), val); 255 hwwrite(vortex->mmio, WT_MUTE(wt), val);
261 return 0xc; 256 return 0xc;
262 break;
263 case 0xb: 257 case 0xb:
264 { /* delay */ 258 /* delay */
265 /* 259 /*
266 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", 260 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
267 WT_DELAY(wt,0), (int)val); 261 WT_DELAY(wt,0), (int)val);
268 */ 262 */
269 hwwrite(vortex->mmio, WT_DELAY(wt, 3), val); 263 hwwrite(vortex->mmio, WT_DELAY(wt, 3), val);
270 hwwrite(vortex->mmio, WT_DELAY(wt, 2), val); 264 hwwrite(vortex->mmio, WT_DELAY(wt, 2), val);
271 hwwrite(vortex->mmio, WT_DELAY(wt, 1), val); 265 hwwrite(vortex->mmio, WT_DELAY(wt, 1), val);
272 hwwrite(vortex->mmio, WT_DELAY(wt, 0), val); 266 hwwrite(vortex->mmio, WT_DELAY(wt, 0), val);
273 return 0xc; 267 return 0xc;
274 }
275 break;
276 /* Global WT block parameters */ 268 /* Global WT block parameters */
277 case 5: /* sramp */ 269 case 5: /* sramp */
278 ecx = WT_SRAMP(wt); 270 ecx = WT_SRAMP(wt);
@@ -291,7 +283,6 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
291 break; 283 break;
292 default: 284 default:
293 return 0; 285 return 0;
294 break;
295 } 286 }
296 /* 287 /*
297 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", ecx, (int)val); 288 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", ecx, (int)val);
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index c8e121611593..1aef7128f7ca 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -715,14 +715,14 @@ snd_azf3328_mixer_ac97_read(struct snd_ac97 *ac97, unsigned short reg_ac97)
715 const struct snd_azf3328 *chip = ac97->private_data; 715 const struct snd_azf3328 *chip = ac97->private_data;
716 unsigned short reg_azf = snd_azf3328_mixer_ac97_map_reg_idx(reg_ac97); 716 unsigned short reg_azf = snd_azf3328_mixer_ac97_map_reg_idx(reg_ac97);
717 unsigned short reg_val = 0; 717 unsigned short reg_val = 0;
718 bool unsupported = 0; 718 bool unsupported = false;
719 719
720 snd_azf3328_dbgmixer( 720 snd_azf3328_dbgmixer(
721 "snd_azf3328_mixer_ac97_read reg_ac97 %u\n", 721 "snd_azf3328_mixer_ac97_read reg_ac97 %u\n",
722 reg_ac97 722 reg_ac97
723 ); 723 );
724 if (reg_azf & AZF_AC97_REG_UNSUPPORTED) 724 if (reg_azf & AZF_AC97_REG_UNSUPPORTED)
725 unsupported = 1; 725 unsupported = true;
726 else { 726 else {
727 if (reg_azf & AZF_AC97_REG_REAL_IO_READ) 727 if (reg_azf & AZF_AC97_REG_REAL_IO_READ)
728 reg_val = snd_azf3328_mixer_inw(chip, 728 reg_val = snd_azf3328_mixer_inw(chip,
@@ -759,7 +759,7 @@ snd_azf3328_mixer_ac97_read(struct snd_ac97 *ac97, unsigned short reg_ac97)
759 reg_val = azf_emulated_ac97_vendor_id & 0xffff; 759 reg_val = azf_emulated_ac97_vendor_id & 0xffff;
760 break; 760 break;
761 default: 761 default:
762 unsupported = 1; 762 unsupported = true;
763 break; 763 break;
764 } 764 }
765 } 765 }
@@ -776,14 +776,14 @@ snd_azf3328_mixer_ac97_write(struct snd_ac97 *ac97,
776{ 776{
777 const struct snd_azf3328 *chip = ac97->private_data; 777 const struct snd_azf3328 *chip = ac97->private_data;
778 unsigned short reg_azf = snd_azf3328_mixer_ac97_map_reg_idx(reg_ac97); 778 unsigned short reg_azf = snd_azf3328_mixer_ac97_map_reg_idx(reg_ac97);
779 bool unsupported = 0; 779 bool unsupported = false;
780 780
781 snd_azf3328_dbgmixer( 781 snd_azf3328_dbgmixer(
782 "snd_azf3328_mixer_ac97_write reg_ac97 %u val %u\n", 782 "snd_azf3328_mixer_ac97_write reg_ac97 %u val %u\n",
783 reg_ac97, val 783 reg_ac97, val
784 ); 784 );
785 if (reg_azf & AZF_AC97_REG_UNSUPPORTED) 785 if (reg_azf & AZF_AC97_REG_UNSUPPORTED)
786 unsupported = 1; 786 unsupported = true;
787 else { 787 else {
788 if (reg_azf & AZF_AC97_REG_REAL_IO_WRITE) 788 if (reg_azf & AZF_AC97_REG_REAL_IO_WRITE)
789 snd_azf3328_mixer_outw( 789 snd_azf3328_mixer_outw(
@@ -808,7 +808,7 @@ snd_azf3328_mixer_ac97_write(struct snd_ac97 *ac97,
808 */ 808 */
809 break; 809 break;
810 default: 810 default:
811 unsupported = 1; 811 unsupported = true;
812 break; 812 break;
813 } 813 }
814 } 814 }
@@ -1559,7 +1559,7 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1559 struct snd_azf3328_codec_data *codec = runtime->private_data; 1559 struct snd_azf3328_codec_data *codec = runtime->private_data;
1560 int result = 0; 1560 int result = 0;
1561 u16 flags1; 1561 u16 flags1;
1562 bool previously_muted = 0; 1562 bool previously_muted = false;
1563 bool is_main_mixer_playback_codec = (AZF_CODEC_PLAYBACK == codec->type); 1563 bool is_main_mixer_playback_codec = (AZF_CODEC_PLAYBACK == codec->type);
1564 1564
1565 snd_azf3328_dbgcalls("snd_azf3328_pcm_trigger cmd %d\n", cmd); 1565 snd_azf3328_dbgcalls("snd_azf3328_pcm_trigger cmd %d\n", cmd);
diff --git a/sound/pci/cs5535audio/cs5535audio_olpc.c b/sound/pci/cs5535audio/cs5535audio_olpc.c
index da1cb9c4c76c..e6a44507d557 100644
--- a/sound/pci/cs5535audio/cs5535audio_olpc.c
+++ b/sound/pci/cs5535audio/cs5535audio_olpc.c
@@ -161,13 +161,13 @@ int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
161 /* drop the original AD1888 HPF control */ 161 /* drop the original AD1888 HPF control */
162 memset(&elem, 0, sizeof(elem)); 162 memset(&elem, 0, sizeof(elem));
163 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 163 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
164 strncpy(elem.name, "High Pass Filter Enable", sizeof(elem.name)); 164 strlcpy(elem.name, "High Pass Filter Enable", sizeof(elem.name));
165 snd_ctl_remove_id(card, &elem); 165 snd_ctl_remove_id(card, &elem);
166 166
167 /* drop the original V_REFOUT control */ 167 /* drop the original V_REFOUT control */
168 memset(&elem, 0, sizeof(elem)); 168 memset(&elem, 0, sizeof(elem));
169 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 169 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
170 strncpy(elem.name, "V_REFOUT Enable", sizeof(elem.name)); 170 strlcpy(elem.name, "V_REFOUT Enable", sizeof(elem.name));
171 snd_ctl_remove_id(card, &elem); 171 snd_ctl_remove_id(card, &elem);
172 172
173 /* add the OLPC-specific controls */ 173 /* add the OLPC-specific controls */
diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c
index 0c00eb4088ef..84f86bf63b8f 100644
--- a/sound/pci/ctxfi/ctdaio.c
+++ b/sound/pci/ctxfi/ctdaio.c
@@ -33,7 +33,7 @@ struct daio_rsc_idx {
33 unsigned short right; 33 unsigned short right;
34}; 34};
35 35
36struct daio_rsc_idx idx_20k1[NUM_DAIOTYP] = { 36static struct daio_rsc_idx idx_20k1[NUM_DAIOTYP] = {
37 [LINEO1] = {.left = 0x00, .right = 0x01}, 37 [LINEO1] = {.left = 0x00, .right = 0x01},
38 [LINEO2] = {.left = 0x18, .right = 0x19}, 38 [LINEO2] = {.left = 0x18, .right = 0x19},
39 [LINEO3] = {.left = 0x08, .right = 0x09}, 39 [LINEO3] = {.left = 0x08, .right = 0x09},
@@ -44,7 +44,7 @@ struct daio_rsc_idx idx_20k1[NUM_DAIOTYP] = {
44 [SPDIFI1] = {.left = 0x95, .right = 0x9d}, 44 [SPDIFI1] = {.left = 0x95, .right = 0x9d},
45}; 45};
46 46
47struct daio_rsc_idx idx_20k2[NUM_DAIOTYP] = { 47static struct daio_rsc_idx idx_20k2[NUM_DAIOTYP] = {
48 [LINEO1] = {.left = 0x40, .right = 0x41}, 48 [LINEO1] = {.left = 0x40, .right = 0x41},
49 [LINEO2] = {.left = 0x60, .right = 0x61}, 49 [LINEO2] = {.left = 0x60, .right = 0x61},
50 [LINEO3] = {.left = 0x50, .right = 0x51}, 50 [LINEO3] = {.left = 0x50, .right = 0x51},
diff --git a/sound/pci/ctxfi/cthardware.c b/sound/pci/ctxfi/cthardware.c
index 110b8ace6d8a..a689f2552706 100644
--- a/sound/pci/ctxfi/cthardware.c
+++ b/sound/pci/ctxfi/cthardware.c
@@ -69,7 +69,8 @@ unsigned int get_field(unsigned int data, unsigned int field)
69{ 69{
70 int i; 70 int i;
71 71
72 BUG_ON(!field); 72 if (WARN_ON(!field))
73 return 0;
73 /* @field should always be greater than 0 */ 74 /* @field should always be greater than 0 */
74 for (i = 0; !(field & (1 << i)); ) 75 for (i = 0; !(field & (1 << i)); )
75 i++; 76 i++;
@@ -81,7 +82,8 @@ void set_field(unsigned int *data, unsigned int field, unsigned int value)
81{ 82{
82 int i; 83 int i;
83 84
84 BUG_ON(!field); 85 if (WARN_ON(!field))
86 return;
85 /* @field should always be greater than 0 */ 87 /* @field should always be greater than 0 */
86 for (i = 0; !(field & (1 << i)); ) 88 for (i = 0; !(field & (1 << i)); )
87 i++; 89 i++;
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 0275209ca82e..1f9c7c4bbcd8 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -1182,15 +1182,20 @@ static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)
1182 u32 *gpr_map; 1182 u32 *gpr_map;
1183 mm_segment_t seg; 1183 mm_segment_t seg;
1184 1184
1185 if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL || 1185 err = -ENOMEM;
1186 (icode->gpr_map = (u_int32_t __user *) 1186 icode = kzalloc(sizeof(*icode), GFP_KERNEL);
1187 kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t), 1187 if (!icode)
1188 GFP_KERNEL)) == NULL || 1188 return err;
1189 (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, 1189
1190 sizeof(*controls), GFP_KERNEL)) == NULL) { 1190 icode->gpr_map = (u_int32_t __user *) kcalloc(512 + 256 + 256 + 2 * 1024,
1191 err = -ENOMEM; 1191 sizeof(u_int32_t), GFP_KERNEL);
1192 goto __err; 1192 if (!icode->gpr_map)
1193 } 1193 goto __err_gpr;
1194 controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
1195 sizeof(*controls), GFP_KERNEL);
1196 if (!controls)
1197 goto __err_ctrls;
1198
1194 gpr_map = (u32 __force *)icode->gpr_map; 1199 gpr_map = (u32 __force *)icode->gpr_map;
1195 1200
1196 icode->tram_data_map = icode->gpr_map + 512; 1201 icode->tram_data_map = icode->gpr_map + 512;
@@ -1741,12 +1746,12 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1741 emu->support_tlv = 0; /* clear again */ 1746 emu->support_tlv = 0; /* clear again */
1742 snd_leave_user(seg); 1747 snd_leave_user(seg);
1743 1748
1744 __err: 1749__err:
1745 kfree(controls); 1750 kfree(controls);
1746 if (icode != NULL) { 1751__err_ctrls:
1747 kfree((void __force *)icode->gpr_map); 1752 kfree((void __force *)icode->gpr_map);
1748 kfree(icode); 1753__err_gpr:
1749 } 1754 kfree(icode);
1750 return err; 1755 return err;
1751} 1756}
1752 1757
@@ -1813,18 +1818,26 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
1813 u32 *gpr_map; 1818 u32 *gpr_map;
1814 mm_segment_t seg; 1819 mm_segment_t seg;
1815 1820
1816 if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL) 1821 err = -ENOMEM;
1817 return -ENOMEM; 1822 icode = kzalloc(sizeof(*icode), GFP_KERNEL);
1818 if ((icode->gpr_map = (u_int32_t __user *) 1823 if (!icode)
1819 kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t), 1824 return err;
1820 GFP_KERNEL)) == NULL || 1825
1821 (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, 1826 icode->gpr_map = (u_int32_t __user *) kcalloc(256 + 160 + 160 + 2 * 512,
1822 sizeof(struct snd_emu10k1_fx8010_control_gpr), 1827 sizeof(u_int32_t), GFP_KERNEL);
1823 GFP_KERNEL)) == NULL || 1828 if (!icode->gpr_map)
1824 (ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL)) == NULL) { 1829 goto __err_gpr;
1825 err = -ENOMEM; 1830
1826 goto __err; 1831 controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
1827 } 1832 sizeof(struct snd_emu10k1_fx8010_control_gpr),
1833 GFP_KERNEL);
1834 if (!controls)
1835 goto __err_ctrls;
1836
1837 ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL);
1838 if (!ipcm)
1839 goto __err_ipcm;
1840
1828 gpr_map = (u32 __force *)icode->gpr_map; 1841 gpr_map = (u32 __force *)icode->gpr_map;
1829 1842
1830 icode->tram_data_map = icode->gpr_map + 256; 1843 icode->tram_data_map = icode->gpr_map + 256;
@@ -2363,13 +2376,14 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
2363 snd_leave_user(seg); 2376 snd_leave_user(seg);
2364 if (err >= 0) 2377 if (err >= 0)
2365 err = snd_emu10k1_ipcm_poke(emu, ipcm); 2378 err = snd_emu10k1_ipcm_poke(emu, ipcm);
2366 __err: 2379__err:
2367 kfree(ipcm); 2380 kfree(ipcm);
2381__err_ipcm:
2368 kfree(controls); 2382 kfree(controls);
2369 if (icode != NULL) { 2383__err_ctrls:
2370 kfree((void __force *)icode->gpr_map); 2384 kfree((void __force *)icode->gpr_map);
2371 kfree(icode); 2385__err_gpr:
2372 } 2386 kfree(icode);
2373 return err; 2387 return err;
2374} 2388}
2375 2389
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c
index 48a9d004d6d9..853c6a69e29e 100644
--- a/sound/pci/hda/hda_auto_parser.c
+++ b/sound/pci/hda/hda_auto_parser.c
@@ -638,7 +638,7 @@ static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
638 /* don't add channel suffix for Headphone controls */ 638 /* don't add channel suffix for Headphone controls */
639 int idx = get_hp_label_index(codec, nid, cfg->hp_pins, 639 int idx = get_hp_label_index(codec, nid, cfg->hp_pins,
640 cfg->hp_outs); 640 cfg->hp_outs);
641 if (idx >= 0) 641 if (idx >= 0 && indexp)
642 *indexp = idx; 642 *indexp = idx;
643 sfx = ""; 643 sfx = "";
644 } 644 }
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 63c99090a4ec..98bce9830be0 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -110,6 +110,7 @@ static int snd_hda_beep_event(struct input_dev *dev, unsigned int type,
110 case SND_BELL: 110 case SND_BELL:
111 if (hz) 111 if (hz)
112 hz = 1000; 112 hz = 1000;
113 /* fallthru */
113 case SND_TONE: 114 case SND_TONE:
114 if (beep->linear_tone) 115 if (beep->linear_tone)
115 beep->tone = beep_linear_tone(beep, hz); 116 beep->tone = beep_linear_tone(beep, hz);
@@ -151,10 +152,8 @@ static int snd_hda_do_attach(struct hda_beep *beep)
151 int err; 152 int err;
152 153
153 input_dev = input_allocate_device(); 154 input_dev = input_allocate_device();
154 if (!input_dev) { 155 if (!input_dev)
155 printk(KERN_INFO "hda_beep: unable to allocate input device\n");
156 return -ENOMEM; 156 return -ENOMEM;
157 }
158 157
159 /* setup digital beep device */ 158 /* setup digital beep device */
160 input_dev->name = "HDA Digital PCBeep"; 159 input_dev->name = "HDA Digital PCBeep";
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 5b6c4e3c92ca..afb90f48867f 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -565,7 +565,7 @@ int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
565 range_val = !!(parm & (1 << (shift-1))); /* ranges */ 565 range_val = !!(parm & (1 << (shift-1))); /* ranges */
566 val = parm & mask; 566 val = parm & mask;
567 if (val == 0 && null_count++) { /* no second chance */ 567 if (val == 0 && null_count++) { /* no second chance */
568 snd_printk(KERN_WARNING "hda_codec: " 568 snd_printdd("hda_codec: "
569 "invalid CONNECT_LIST verb %x[%i]:%x\n", 569 "invalid CONNECT_LIST verb %x[%i]:%x\n",
570 nid, i, parm); 570 nid, i, parm);
571 return 0; 571 return 0;
@@ -2579,9 +2579,6 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2579 cancel_delayed_work_sync(&codec->jackpoll_work); 2579 cancel_delayed_work_sync(&codec->jackpoll_work);
2580#ifdef CONFIG_PM 2580#ifdef CONFIG_PM
2581 cancel_delayed_work_sync(&codec->power_work); 2581 cancel_delayed_work_sync(&codec->power_work);
2582 codec->power_on = 0;
2583 codec->power_transition = 0;
2584 codec->power_jiffies = jiffies;
2585 flush_workqueue(bus->workq); 2582 flush_workqueue(bus->workq);
2586#endif 2583#endif
2587 snd_hda_ctls_clear(codec); 2584 snd_hda_ctls_clear(codec);
@@ -2634,8 +2631,7 @@ static int map_slaves(struct hda_codec *codec, const char * const *slaves,
2634 items = codec->mixers.list; 2631 items = codec->mixers.list;
2635 for (i = 0; i < codec->mixers.used; i++) { 2632 for (i = 0; i < codec->mixers.used; i++) {
2636 struct snd_kcontrol *sctl = items[i].kctl; 2633 struct snd_kcontrol *sctl = items[i].kctl;
2637 if (!sctl || !sctl->id.name || 2634 if (!sctl || sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER)
2638 sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER)
2639 continue; 2635 continue;
2640 for (s = slaves; *s; s++) { 2636 for (s = slaves; *s; s++) {
2641 char tmpname[sizeof(sctl->id.name)]; 2637 char tmpname[sizeof(sctl->id.name)];
@@ -2662,7 +2658,7 @@ static int check_slave_present(void *data, struct snd_kcontrol *sctl)
2662} 2658}
2663 2659
2664/* guess the value corresponding to 0dB */ 2660/* guess the value corresponding to 0dB */
2665static int get_kctl_0dB_offset(struct snd_kcontrol *kctl) 2661static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
2666{ 2662{
2667 int _tlv[4]; 2663 int _tlv[4];
2668 const int *tlv = NULL; 2664 const int *tlv = NULL;
@@ -2677,8 +2673,19 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl)
2677 set_fs(fs); 2673 set_fs(fs);
2678 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) 2674 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
2679 tlv = kctl->tlv.p; 2675 tlv = kctl->tlv.p;
2680 if (tlv && tlv[0] == SNDRV_CTL_TLVT_DB_SCALE) 2676 if (tlv && tlv[0] == SNDRV_CTL_TLVT_DB_SCALE) {
2681 val = -tlv[2] / tlv[3]; 2677 int step = tlv[3];
2678 step &= ~TLV_DB_SCALE_MUTE;
2679 if (!step)
2680 return -1;
2681 if (*step_to_check && *step_to_check != step) {
2682 snd_printk(KERN_ERR "hda_codec: Mismatching dB step for vmaster slave (%d!=%d)\n",
2683 *step_to_check, step);
2684 return -1;
2685 }
2686 *step_to_check = step;
2687 val = -tlv[2] / step;
2688 }
2682 return val; 2689 return val;
2683} 2690}
2684 2691
@@ -2699,7 +2706,7 @@ static int put_kctl_with_value(struct snd_kcontrol *kctl, int val)
2699/* initialize the slave volume with 0dB */ 2706/* initialize the slave volume with 0dB */
2700static int init_slave_0dB(void *data, struct snd_kcontrol *slave) 2707static int init_slave_0dB(void *data, struct snd_kcontrol *slave)
2701{ 2708{
2702 int offset = get_kctl_0dB_offset(slave); 2709 int offset = get_kctl_0dB_offset(slave, data);
2703 if (offset > 0) 2710 if (offset > 0)
2704 put_kctl_with_value(slave, offset); 2711 put_kctl_with_value(slave, offset);
2705 return 0; 2712 return 0;
@@ -2760,9 +2767,11 @@ int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
2760 2767
2761 /* init with master mute & zero volume */ 2768 /* init with master mute & zero volume */
2762 put_kctl_with_value(kctl, 0); 2769 put_kctl_with_value(kctl, 0);
2763 if (init_slave_vol) 2770 if (init_slave_vol) {
2771 int step = 0;
2764 map_slaves(codec, slaves, suffix, 2772 map_slaves(codec, slaves, suffix,
2765 tlv ? init_slave_0dB : init_slave_unmute, kctl); 2773 tlv ? init_slave_0dB : init_slave_unmute, &step);
2774 }
2766 2775
2767 if (ctl_ret) 2776 if (ctl_ret)
2768 *ctl_ret = kctl; 2777 *ctl_ret = kctl;
@@ -4864,8 +4873,8 @@ static void hda_power_work(struct work_struct *work)
4864 spin_unlock(&codec->power_lock); 4873 spin_unlock(&codec->power_lock);
4865 4874
4866 state = hda_call_codec_suspend(codec, true); 4875 state = hda_call_codec_suspend(codec, true);
4867 codec->pm_down_notified = 0; 4876 if (!codec->pm_down_notified &&
4868 if (!bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) { 4877 !bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) {
4869 codec->pm_down_notified = 1; 4878 codec->pm_down_notified = 1;
4870 hda_call_pm_notify(bus, false); 4879 hda_call_pm_notify(bus, false);
4871 } 4880 }
@@ -5395,11 +5404,6 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
5395 snd_hda_codec_setup_stream(codec, 5404 snd_hda_codec_setup_stream(codec,
5396 mout->hp_out_nid[i], 5405 mout->hp_out_nid[i],
5397 stream_tag, 0, format); 5406 stream_tag, 0, format);
5398 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
5399 if (!mout->no_share_stream && mout->extra_out_nid[i])
5400 snd_hda_codec_setup_stream(codec,
5401 mout->extra_out_nid[i],
5402 stream_tag, 0, format);
5403 5407
5404 /* surrounds */ 5408 /* surrounds */
5405 for (i = 1; i < mout->num_dacs; i++) { 5409 for (i = 1; i < mout->num_dacs; i++) {
@@ -5410,6 +5414,20 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
5410 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, 5414 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
5411 0, format); 5415 0, format);
5412 } 5416 }
5417
5418 /* extra surrounds */
5419 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) {
5420 int ch = 0;
5421 if (!mout->extra_out_nid[i])
5422 break;
5423 if (chs >= (i + 1) * 2)
5424 ch = i * 2;
5425 else if (!mout->no_share_stream)
5426 break;
5427 snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i],
5428 stream_tag, ch, format);
5429 }
5430
5413 return 0; 5431 return 0;
5414} 5432}
5415EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare); 5433EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 7aa9870040c1..77db69480c19 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -698,6 +698,7 @@ struct hda_bus {
698 unsigned int in_reset:1; /* during reset operation */ 698 unsigned int in_reset:1; /* during reset operation */
699 unsigned int power_keep_link_on:1; /* don't power off HDA link */ 699 unsigned int power_keep_link_on:1; /* don't power off HDA link */
700 unsigned int no_response_fallback:1; /* don't fallback at RIRB error */ 700 unsigned int no_response_fallback:1; /* don't fallback at RIRB error */
701 unsigned int avoid_link_reset:1; /* don't reset link at runtime PM */
701 702
702 int primary_dig_out_type; /* primary digital out PCM type */ 703 int primary_dig_out_type; /* primary digital out PCM type */
703}; 704};
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index d0d7ac1e99d2..79ca80f6c77a 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -2,6 +2,7 @@
2 * Generic routines and proc interface for ELD(EDID Like Data) information 2 * Generic routines and proc interface for ELD(EDID Like Data) information
3 * 3 *
4 * Copyright(c) 2008 Intel Corporation. 4 * Copyright(c) 2008 Intel Corporation.
5 * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi>
5 * 6 *
6 * Authors: 7 * Authors:
7 * Wu Fengguang <wfg@linux.intel.com> 8 * Wu Fengguang <wfg@linux.intel.com>
@@ -478,10 +479,9 @@ static void hdmi_print_sad_info(int i, struct cea_sad *a,
478 snd_iprintf(buffer, "sad%d_profile\t\t%d\n", i, a->profile); 479 snd_iprintf(buffer, "sad%d_profile\t\t%d\n", i, a->profile);
479} 480}
480 481
481static void hdmi_print_eld_info(struct snd_info_entry *entry, 482void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
482 struct snd_info_buffer *buffer) 483 struct snd_info_buffer *buffer)
483{ 484{
484 struct hdmi_eld *eld = entry->private_data;
485 struct parsed_hdmi_eld *e = &eld->info; 485 struct parsed_hdmi_eld *e = &eld->info;
486 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; 486 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
487 int i; 487 int i;
@@ -500,13 +500,10 @@ static void hdmi_print_eld_info(struct snd_info_entry *entry,
500 [4 ... 7] = "reserved" 500 [4 ... 7] = "reserved"
501 }; 501 };
502 502
503 mutex_lock(&eld->lock);
504 snd_iprintf(buffer, "monitor_present\t\t%d\n", eld->monitor_present); 503 snd_iprintf(buffer, "monitor_present\t\t%d\n", eld->monitor_present);
505 snd_iprintf(buffer, "eld_valid\t\t%d\n", eld->eld_valid); 504 snd_iprintf(buffer, "eld_valid\t\t%d\n", eld->eld_valid);
506 if (!eld->eld_valid) { 505 if (!eld->eld_valid)
507 mutex_unlock(&eld->lock);
508 return; 506 return;
509 }
510 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name); 507 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name);
511 snd_iprintf(buffer, "connection_type\t\t%s\n", 508 snd_iprintf(buffer, "connection_type\t\t%s\n",
512 eld_connection_type_names[e->conn_type]); 509 eld_connection_type_names[e->conn_type]);
@@ -528,13 +525,11 @@ static void hdmi_print_eld_info(struct snd_info_entry *entry,
528 525
529 for (i = 0; i < e->sad_count; i++) 526 for (i = 0; i < e->sad_count; i++)
530 hdmi_print_sad_info(i, e->sad + i, buffer); 527 hdmi_print_sad_info(i, e->sad + i, buffer);
531 mutex_unlock(&eld->lock);
532} 528}
533 529
534static void hdmi_write_eld_info(struct snd_info_entry *entry, 530void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
535 struct snd_info_buffer *buffer) 531 struct snd_info_buffer *buffer)
536{ 532{
537 struct hdmi_eld *eld = entry->private_data;
538 struct parsed_hdmi_eld *e = &eld->info; 533 struct parsed_hdmi_eld *e = &eld->info;
539 char line[64]; 534 char line[64];
540 char name[64]; 535 char name[64];
@@ -542,7 +537,6 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
542 long long val; 537 long long val;
543 unsigned int n; 538 unsigned int n;
544 539
545 mutex_lock(&eld->lock);
546 while (!snd_info_get_line(buffer, line, sizeof(line))) { 540 while (!snd_info_get_line(buffer, line, sizeof(line))) {
547 if (sscanf(line, "%s %llx", name, &val) != 2) 541 if (sscanf(line, "%s %llx", name, &val) != 2)
548 continue; 542 continue;
@@ -594,38 +588,7 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
594 e->sad_count = n + 1; 588 e->sad_count = n + 1;
595 } 589 }
596 } 590 }
597 mutex_unlock(&eld->lock);
598}
599
600
601int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
602 int index)
603{
604 char name[32];
605 struct snd_info_entry *entry;
606 int err;
607
608 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
609 err = snd_card_proc_new(codec->bus->card, name, &entry);
610 if (err < 0)
611 return err;
612
613 snd_info_set_text_ops(entry, eld, hdmi_print_eld_info);
614 entry->c.text.write = hdmi_write_eld_info;
615 entry->mode |= S_IWUSR;
616 eld->proc_entry = entry;
617
618 return 0;
619}
620
621void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld)
622{
623 if (!codec->bus->shutdown && eld->proc_entry) {
624 snd_device_free(codec->bus->card, eld->proc_entry);
625 eld->proc_entry = NULL;
626 }
627} 591}
628
629#endif /* CONFIG_PROC_FS */ 592#endif /* CONFIG_PROC_FS */
630 593
631/* update PCM info based on ELD */ 594/* update PCM info based on ELD */
@@ -671,3 +634,174 @@ void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
671 hinfo->maxbps = min(hinfo->maxbps, maxbps); 634 hinfo->maxbps = min(hinfo->maxbps, maxbps);
672 hinfo->channels_max = min(hinfo->channels_max, channels_max); 635 hinfo->channels_max = min(hinfo->channels_max, channels_max);
673} 636}
637
638
639/* ATI/AMD specific stuff (ELD emulation) */
640
641#define ATI_VERB_SET_AUDIO_DESCRIPTOR 0x776
642#define ATI_VERB_SET_SINK_INFO_INDEX 0x780
643#define ATI_VERB_GET_SPEAKER_ALLOCATION 0xf70
644#define ATI_VERB_GET_AUDIO_DESCRIPTOR 0xf76
645#define ATI_VERB_GET_AUDIO_VIDEO_DELAY 0xf7b
646#define ATI_VERB_GET_SINK_INFO_INDEX 0xf80
647#define ATI_VERB_GET_SINK_INFO_DATA 0xf81
648
649#define ATI_SPKALLOC_SPKALLOC 0x007f
650#define ATI_SPKALLOC_TYPE_HDMI 0x0100
651#define ATI_SPKALLOC_TYPE_DISPLAYPORT 0x0200
652
653/* first three bytes are just standard SAD */
654#define ATI_AUDIODESC_CHANNELS 0x00000007
655#define ATI_AUDIODESC_RATES 0x0000ff00
656#define ATI_AUDIODESC_LPCM_STEREO_RATES 0xff000000
657
658/* in standard HDMI VSDB format */
659#define ATI_DELAY_VIDEO_LATENCY 0x000000ff
660#define ATI_DELAY_AUDIO_LATENCY 0x0000ff00
661
662enum ati_sink_info_idx {
663 ATI_INFO_IDX_MANUFACTURER_ID = 0,
664 ATI_INFO_IDX_PRODUCT_ID = 1,
665 ATI_INFO_IDX_SINK_DESC_LEN = 2,
666 ATI_INFO_IDX_PORT_ID_LOW = 3,
667 ATI_INFO_IDX_PORT_ID_HIGH = 4,
668 ATI_INFO_IDX_SINK_DESC_FIRST = 5,
669 ATI_INFO_IDX_SINK_DESC_LAST = 22, /* max len 18 bytes */
670};
671
672int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
673 unsigned char *buf, int *eld_size, bool rev3_or_later)
674{
675 int spkalloc, ati_sad, aud_synch;
676 int sink_desc_len = 0;
677 int pos, i;
678
679 /* ATI/AMD does not have ELD, emulate it */
680
681 spkalloc = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SPEAKER_ALLOCATION, 0);
682
683 if (spkalloc <= 0) {
684 snd_printd(KERN_INFO "HDMI ATI/AMD: no speaker allocation for ELD\n");
685 return -EINVAL;
686 }
687
688 memset(buf, 0, ELD_FIXED_BYTES + ELD_MAX_MNL + ELD_MAX_SAD * 3);
689
690 /* version */
691 buf[0] = ELD_VER_CEA_861D << 3;
692
693 /* speaker allocation from EDID */
694 buf[7] = spkalloc & ATI_SPKALLOC_SPKALLOC;
695
696 /* is DisplayPort? */
697 if (spkalloc & ATI_SPKALLOC_TYPE_DISPLAYPORT)
698 buf[5] |= 0x04;
699
700 pos = ELD_FIXED_BYTES;
701
702 if (rev3_or_later) {
703 int sink_info;
704
705 snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PORT_ID_LOW);
706 sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
707 put_unaligned_le32(sink_info, buf + 8);
708
709 snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PORT_ID_HIGH);
710 sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
711 put_unaligned_le32(sink_info, buf + 12);
712
713 snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_MANUFACTURER_ID);
714 sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
715 put_unaligned_le16(sink_info, buf + 16);
716
717 snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PRODUCT_ID);
718 sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
719 put_unaligned_le16(sink_info, buf + 18);
720
721 snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_SINK_DESC_LEN);
722 sink_desc_len = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
723
724 if (sink_desc_len > ELD_MAX_MNL) {
725 snd_printd(KERN_INFO "HDMI ATI/AMD: Truncating HDMI sink description with length %d\n",
726 sink_desc_len);
727 sink_desc_len = ELD_MAX_MNL;
728 }
729
730 buf[4] |= sink_desc_len;
731
732 for (i = 0; i < sink_desc_len; i++) {
733 snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_SINK_DESC_FIRST + i);
734 buf[pos++] = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
735 }
736 }
737
738 for (i = AUDIO_CODING_TYPE_LPCM; i <= AUDIO_CODING_TYPE_WMAPRO; i++) {
739 if (i == AUDIO_CODING_TYPE_SACD || i == AUDIO_CODING_TYPE_DST)
740 continue; /* not handled by ATI/AMD */
741
742 snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_AUDIO_DESCRIPTOR, i << 3);
743 ati_sad = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_AUDIO_DESCRIPTOR, 0);
744
745 if (ati_sad <= 0)
746 continue;
747
748 if (ati_sad & ATI_AUDIODESC_RATES) {
749 /* format is supported, copy SAD as-is */
750 buf[pos++] = (ati_sad & 0x0000ff) >> 0;
751 buf[pos++] = (ati_sad & 0x00ff00) >> 8;
752 buf[pos++] = (ati_sad & 0xff0000) >> 16;
753 }
754
755 if (i == AUDIO_CODING_TYPE_LPCM
756 && (ati_sad & ATI_AUDIODESC_LPCM_STEREO_RATES)
757 && (ati_sad & ATI_AUDIODESC_LPCM_STEREO_RATES) >> 16 != (ati_sad & ATI_AUDIODESC_RATES)) {
758 /* for PCM there is a separate stereo rate mask */
759 buf[pos++] = ((ati_sad & 0x000000ff) & ~ATI_AUDIODESC_CHANNELS) | 0x1;
760 /* rates from the extra byte */
761 buf[pos++] = (ati_sad & 0xff000000) >> 24;
762 buf[pos++] = (ati_sad & 0x00ff0000) >> 16;
763 }
764 }
765
766 if (pos == ELD_FIXED_BYTES + sink_desc_len) {
767 snd_printd(KERN_INFO "HDMI ATI/AMD: no audio descriptors for ELD\n");
768 return -EINVAL;
769 }
770
771 /*
772 * HDMI VSDB latency format:
773 * separately for both audio and video:
774 * 0 field not valid or unknown latency
775 * [1..251] msecs = (x-1)*2 (max 500ms with x = 251 = 0xfb)
776 * 255 audio/video not supported
777 *
778 * HDA latency format:
779 * single value indicating video latency relative to audio:
780 * 0 unknown or 0ms
781 * [1..250] msecs = x*2 (max 500ms with x = 250 = 0xfa)
782 * [251..255] reserved
783 */
784 aud_synch = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_AUDIO_VIDEO_DELAY, 0);
785 if ((aud_synch & ATI_DELAY_VIDEO_LATENCY) && (aud_synch & ATI_DELAY_AUDIO_LATENCY)) {
786 int video_latency_hdmi = (aud_synch & ATI_DELAY_VIDEO_LATENCY);
787 int audio_latency_hdmi = (aud_synch & ATI_DELAY_AUDIO_LATENCY) >> 8;
788
789 if (video_latency_hdmi <= 0xfb && audio_latency_hdmi <= 0xfb &&
790 video_latency_hdmi > audio_latency_hdmi)
791 buf[6] = video_latency_hdmi - audio_latency_hdmi;
792 /* else unknown/invalid or 0ms or video ahead of audio, so use zero */
793 }
794
795 /* SAD count */
796 buf[5] |= ((pos - ELD_FIXED_BYTES - sink_desc_len) / 3) << 4;
797
798 /* Baseline ELD block length is 4-byte aligned */
799 pos = round_up(pos, 4);
800
801 /* Baseline ELD length (4-byte header is not counted in) */
802 buf[2] = (pos - 4) / 4;
803
804 *eld_size = pos;
805
806 return 0;
807}
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index ac41e9cdc976..3067ed4fe3b2 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -549,11 +549,15 @@ static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec,
549static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec, 549static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec,
550 struct nid_path *path) 550 struct nid_path *path)
551{ 551{
552 struct hda_gen_spec *spec = codec->spec;
552 int i; 553 int i;
553 554
554 for (i = path->depth - 1; i >= 0; i--) { 555 for (i = path->depth - 1; i >= 0; i--) {
555 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT)) 556 hda_nid_t nid = path->path[i];
556 return path->path[i]; 557 if ((spec->out_vol_mask >> nid) & 1)
558 continue;
559 if (nid_has_volume(codec, nid, HDA_OUTPUT))
560 return nid;
557 } 561 }
558 return 0; 562 return 0;
559} 563}
@@ -792,10 +796,10 @@ static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
792 if (spec->own_eapd_ctl || 796 if (spec->own_eapd_ctl ||
793 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)) 797 !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
794 return; 798 return;
795 if (codec->inv_eapd)
796 enable = !enable;
797 if (spec->keep_eapd_on && !enable) 799 if (spec->keep_eapd_on && !enable)
798 return; 800 return;
801 if (codec->inv_eapd)
802 enable = !enable;
799 snd_hda_codec_update_cache(codec, pin, 0, 803 snd_hda_codec_update_cache(codec, pin, 0,
800 AC_VERB_SET_EAPD_BTLENABLE, 804 AC_VERB_SET_EAPD_BTLENABLE,
801 enable ? 0x02 : 0x00); 805 enable ? 0x02 : 0x00);
@@ -3531,7 +3535,7 @@ static int create_capture_mixers(struct hda_codec *codec)
3531 if (!multi) 3535 if (!multi)
3532 err = create_single_cap_vol_ctl(codec, n, vol, sw, 3536 err = create_single_cap_vol_ctl(codec, n, vol, sw,
3533 inv_dmic); 3537 inv_dmic);
3534 else if (!multi_cap_vol) 3538 else if (!multi_cap_vol && !inv_dmic)
3535 err = create_bind_cap_vol_ctl(codec, n, vol, sw); 3539 err = create_bind_cap_vol_ctl(codec, n, vol, sw);
3536 else 3540 else
3537 err = create_multi_cap_vol_ctl(codec); 3541 err = create_multi_cap_vol_ctl(codec);
@@ -4475,9 +4479,11 @@ int snd_hda_gen_build_controls(struct hda_codec *codec)
4475 true, &spec->vmaster_mute.sw_kctl); 4479 true, &spec->vmaster_mute.sw_kctl);
4476 if (err < 0) 4480 if (err < 0)
4477 return err; 4481 return err;
4478 if (spec->vmaster_mute.hook) 4482 if (spec->vmaster_mute.hook) {
4479 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, 4483 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4480 spec->vmaster_mute_enum); 4484 spec->vmaster_mute_enum);
4485 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4486 }
4481 } 4487 }
4482 4488
4483 free_kctls(spec); /* no longer needed */ 4489 free_kctls(spec); /* no longer needed */
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
index 48d44026705b..7e45cb44d151 100644
--- a/sound/pci/hda/hda_generic.h
+++ b/sound/pci/hda/hda_generic.h
@@ -242,6 +242,9 @@ struct hda_gen_spec {
242 /* additional mute flags (only effective with auto_mute_via_amp=1) */ 242 /* additional mute flags (only effective with auto_mute_via_amp=1) */
243 u64 mute_bits; 243 u64 mute_bits;
244 244
245 /* bitmask for skipping volume controls */
246 u64 out_vol_mask;
247
245 /* badness tables for output path evaluations */ 248 /* badness tables for output path evaluations */
246 const struct badness_table *main_out_badness; 249 const struct badness_table *main_out_badness;
247 const struct badness_table *extra_out_badness; 250 const struct badness_table *extra_out_badness;
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 6e61a019aa5e..7a09404579a7 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -169,6 +169,7 @@ MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
169 "{Intel, PPT}," 169 "{Intel, PPT},"
170 "{Intel, LPT}," 170 "{Intel, LPT},"
171 "{Intel, LPT_LP}," 171 "{Intel, LPT_LP},"
172 "{Intel, WPT_LP},"
172 "{Intel, HPT}," 173 "{Intel, HPT},"
173 "{Intel, PBG}," 174 "{Intel, PBG},"
174 "{Intel, SCH}," 175 "{Intel, SCH},"
@@ -568,6 +569,7 @@ enum {
568 AZX_DRIVER_ICH, 569 AZX_DRIVER_ICH,
569 AZX_DRIVER_PCH, 570 AZX_DRIVER_PCH,
570 AZX_DRIVER_SCH, 571 AZX_DRIVER_SCH,
572 AZX_DRIVER_HDMI,
571 AZX_DRIVER_ATI, 573 AZX_DRIVER_ATI,
572 AZX_DRIVER_ATIHDMI, 574 AZX_DRIVER_ATIHDMI,
573 AZX_DRIVER_ATIHDMI_NS, 575 AZX_DRIVER_ATIHDMI_NS,
@@ -612,6 +614,11 @@ enum {
612#define AZX_DCAPS_INTEL_PCH \ 614#define AZX_DCAPS_INTEL_PCH \
613 (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_PM_RUNTIME) 615 (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_PM_RUNTIME)
614 616
617#define AZX_DCAPS_INTEL_HASWELL \
618 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_ALIGN_BUFSIZE | \
619 AZX_DCAPS_COUNT_LPIB_DELAY | AZX_DCAPS_PM_RUNTIME | \
620 AZX_DCAPS_I915_POWERWELL)
621
615/* quirks for ATI SB / AMD Hudson */ 622/* quirks for ATI SB / AMD Hudson */
616#define AZX_DCAPS_PRESET_ATI_SB \ 623#define AZX_DCAPS_PRESET_ATI_SB \
617 (AZX_DCAPS_ATI_SNOOP | AZX_DCAPS_NO_TCSEL | \ 624 (AZX_DCAPS_ATI_SNOOP | AZX_DCAPS_NO_TCSEL | \
@@ -642,6 +649,7 @@ static char *driver_short_names[] = {
642 [AZX_DRIVER_ICH] = "HDA Intel", 649 [AZX_DRIVER_ICH] = "HDA Intel",
643 [AZX_DRIVER_PCH] = "HDA Intel PCH", 650 [AZX_DRIVER_PCH] = "HDA Intel PCH",
644 [AZX_DRIVER_SCH] = "HDA Intel MID", 651 [AZX_DRIVER_SCH] = "HDA Intel MID",
652 [AZX_DRIVER_HDMI] = "HDA Intel HDMI",
645 [AZX_DRIVER_ATI] = "HDA ATI SB", 653 [AZX_DRIVER_ATI] = "HDA ATI SB",
646 [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI", 654 [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
647 [AZX_DRIVER_ATIHDMI_NS] = "HDA ATI HDMI", 655 [AZX_DRIVER_ATIHDMI_NS] = "HDA ATI HDMI",
@@ -906,12 +914,12 @@ static void azx_update_rirb(struct azx *chip)
906 chip->rirb.res[addr] = res; 914 chip->rirb.res[addr] = res;
907 smp_wmb(); 915 smp_wmb();
908 chip->rirb.cmds[addr]--; 916 chip->rirb.cmds[addr]--;
909 } else 917 } else if (printk_ratelimit()) {
910 snd_printk(KERN_ERR SFX "%s: spurious response %#x:%#x, " 918 snd_printk(KERN_ERR SFX "%s: spurious response %#x:%#x, last cmd=%#08x\n",
911 "last cmd=%#08x\n",
912 pci_name(chip->pci), 919 pci_name(chip->pci),
913 res, res_ex, 920 res, res_ex,
914 chip->last_cmd[addr]); 921 chip->last_cmd[addr]);
922 }
915 } 923 }
916} 924}
917 925
@@ -2986,7 +2994,8 @@ static int azx_runtime_suspend(struct device *dev)
2986 STATESTS_INT_MASK); 2994 STATESTS_INT_MASK);
2987 2995
2988 azx_stop_chip(chip); 2996 azx_stop_chip(chip);
2989 azx_enter_link_reset(chip); 2997 if (!chip->bus->avoid_link_reset)
2998 azx_enter_link_reset(chip);
2990 azx_clear_irq_pending(chip); 2999 azx_clear_irq_pending(chip);
2991 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) 3000 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
2992 hda_display_power(false); 3001 hda_display_power(false);
@@ -3985,16 +3994,16 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
3985 /* Lynx Point-LP */ 3994 /* Lynx Point-LP */
3986 { PCI_DEVICE(0x8086, 0x9c21), 3995 { PCI_DEVICE(0x8086, 0x9c21),
3987 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, 3996 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
3997 /* Wildcat Point-LP */
3998 { PCI_DEVICE(0x8086, 0x9ca0),
3999 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
3988 /* Haswell */ 4000 /* Haswell */
3989 { PCI_DEVICE(0x8086, 0x0a0c), 4001 { PCI_DEVICE(0x8086, 0x0a0c),
3990 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH | 4002 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
3991 AZX_DCAPS_I915_POWERWELL },
3992 { PCI_DEVICE(0x8086, 0x0c0c), 4003 { PCI_DEVICE(0x8086, 0x0c0c),
3993 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH | 4004 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
3994 AZX_DCAPS_I915_POWERWELL },
3995 { PCI_DEVICE(0x8086, 0x0d0c), 4005 { PCI_DEVICE(0x8086, 0x0d0c),
3996 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH | 4006 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
3997 AZX_DCAPS_I915_POWERWELL },
3998 /* 5 Series/3400 */ 4007 /* 5 Series/3400 */
3999 { PCI_DEVICE(0x8086, 0x3b56), 4008 { PCI_DEVICE(0x8086, 0x3b56),
4000 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, 4009 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
@@ -4074,6 +4083,22 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
4074 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, 4083 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4075 { PCI_DEVICE(0x1002, 0xaa48), 4084 { PCI_DEVICE(0x1002, 0xaa48),
4076 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, 4085 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4086 { PCI_DEVICE(0x1002, 0xaa50),
4087 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4088 { PCI_DEVICE(0x1002, 0xaa58),
4089 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4090 { PCI_DEVICE(0x1002, 0xaa60),
4091 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4092 { PCI_DEVICE(0x1002, 0xaa68),
4093 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4094 { PCI_DEVICE(0x1002, 0xaa80),
4095 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4096 { PCI_DEVICE(0x1002, 0xaa88),
4097 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4098 { PCI_DEVICE(0x1002, 0xaa90),
4099 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4100 { PCI_DEVICE(0x1002, 0xaa98),
4101 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
4077 { PCI_DEVICE(0x1002, 0x9902), 4102 { PCI_DEVICE(0x1002, 0x9902),
4078 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, 4103 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI },
4079 { PCI_DEVICE(0x1002, 0xaaa0), 4104 { PCI_DEVICE(0x1002, 0xaaa0),
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index 05b3e3e9108f..afe594411a56 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -286,7 +286,7 @@ void snd_hda_jack_report_sync(struct hda_codec *codec)
286 jack = codec->jacktbl.list; 286 jack = codec->jacktbl.list;
287 for (i = 0; i < codec->jacktbl.used; i++, jack++) 287 for (i = 0; i < codec->jacktbl.used; i++, jack++)
288 if (jack->nid) { 288 if (jack->nid) {
289 if (!jack->kctl) 289 if (!jack->kctl || jack->block_report)
290 continue; 290 continue;
291 state = get_jack_plug_state(jack->pin_sense); 291 state = get_jack_plug_state(jack->pin_sense);
292 snd_kctl_jack_report(codec->bus->card, jack->kctl, state); 292 snd_kctl_jack_report(codec->bus->card, jack->kctl, state);
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
index 379420c44eef..46e1ea83ce3c 100644
--- a/sound/pci/hda/hda_jack.h
+++ b/sound/pci/hda/hda_jack.h
@@ -28,6 +28,7 @@ struct hda_jack_tbl {
28 unsigned int jack_detect:1; /* capable of jack-detection? */ 28 unsigned int jack_detect:1; /* capable of jack-detection? */
29 unsigned int jack_dirty:1; /* needs to update? */ 29 unsigned int jack_dirty:1; /* needs to update? */
30 unsigned int phantom_jack:1; /* a fixed, always present port? */ 30 unsigned int phantom_jack:1; /* a fixed, always present port? */
31 unsigned int block_report:1; /* in a transitional state - do not report to userspace */
31 hda_nid_t gating_jack; /* valid when gating jack plugged */ 32 hda_nid_t gating_jack; /* valid when gating jack plugged */
32 hda_nid_t gated_jack; /* gated is dependent on this jack */ 33 hda_nid_t gated_jack; /* gated is dependent on this jack */
33 struct snd_kcontrol *kctl; /* assigned kctl for jack-detection */ 34 struct snd_kcontrol *kctl; /* assigned kctl for jack-detection */
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 2e7493ef8ee0..d398b648bb5d 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -428,6 +428,7 @@ enum {
428 HDA_FIXUP_ACT_PROBE, 428 HDA_FIXUP_ACT_PROBE,
429 HDA_FIXUP_ACT_INIT, 429 HDA_FIXUP_ACT_INIT,
430 HDA_FIXUP_ACT_BUILD, 430 HDA_FIXUP_ACT_BUILD,
431 HDA_FIXUP_ACT_FREE,
431}; 432};
432 433
433int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list); 434int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
@@ -751,10 +752,6 @@ struct hdmi_eld {
751 int eld_size; 752 int eld_size;
752 char eld_buffer[ELD_MAX_SIZE]; 753 char eld_buffer[ELD_MAX_SIZE];
753 struct parsed_hdmi_eld info; 754 struct parsed_hdmi_eld info;
754 struct mutex lock;
755#ifdef CONFIG_PROC_FS
756 struct snd_info_entry *proc_entry;
757#endif
758}; 755};
759 756
760int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid); 757int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
@@ -766,21 +763,15 @@ void snd_hdmi_show_eld(struct parsed_hdmi_eld *e);
766void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e, 763void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
767 struct hda_pcm_stream *hinfo); 764 struct hda_pcm_stream *hinfo);
768 765
766int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
767 unsigned char *buf, int *eld_size,
768 bool rev3_or_later);
769
769#ifdef CONFIG_PROC_FS 770#ifdef CONFIG_PROC_FS
770int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld, 771void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
771 int index); 772 struct snd_info_buffer *buffer);
772void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld); 773void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
773#else 774 struct snd_info_buffer *buffer);
774static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
775 struct hdmi_eld *eld,
776 int index)
777{
778 return 0;
779}
780static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
781 struct hdmi_eld *eld)
782{
783}
784#endif 775#endif
785 776
786#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80 777#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 0cbdd87dde6d..1a83559f4cbd 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -139,6 +139,18 @@ static int ad198x_suspend(struct hda_codec *codec)
139} 139}
140#endif 140#endif
141 141
142/* follow EAPD via vmaster hook */
143static void ad_vmaster_eapd_hook(void *private_data, int enabled)
144{
145 struct hda_codec *codec = private_data;
146 struct ad198x_spec *spec = codec->spec;
147
148 if (!spec->eapd_nid)
149 return;
150 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
151 AC_VERB_SET_EAPD_BTLENABLE,
152 enabled ? 0x02 : 0x00);
153}
142 154
143/* 155/*
144 * Automatic parse of I/O pins from the BIOS configuration 156 * Automatic parse of I/O pins from the BIOS configuration
@@ -219,8 +231,14 @@ static int alloc_ad_spec(struct hda_codec *codec)
219static void ad_fixup_inv_jack_detect(struct hda_codec *codec, 231static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
220 const struct hda_fixup *fix, int action) 232 const struct hda_fixup *fix, int action)
221{ 233{
222 if (action == HDA_FIXUP_ACT_PRE_PROBE) 234 struct ad198x_spec *spec = codec->spec;
235
236 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
223 codec->inv_jack_detect = 1; 237 codec->inv_jack_detect = 1;
238 spec->gen.keep_eapd_on = 1;
239 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
240 spec->eapd_nid = 0x1b;
241 }
224} 242}
225 243
226enum { 244enum {
@@ -465,19 +483,6 @@ static int patch_ad1983(struct hda_codec *codec)
465 * AD1981 HD specific 483 * AD1981 HD specific
466 */ 484 */
467 485
468/* follow EAPD via vmaster hook */
469static void ad_vmaster_eapd_hook(void *private_data, int enabled)
470{
471 struct hda_codec *codec = private_data;
472 struct ad198x_spec *spec = codec->spec;
473
474 if (!spec->eapd_nid)
475 return;
476 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
477 AC_VERB_SET_EAPD_BTLENABLE,
478 enabled ? 0x02 : 0x00);
479}
480
481static void ad1981_fixup_hp_eapd(struct hda_codec *codec, 486static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
482 const struct hda_fixup *fix, int action) 487 const struct hda_fixup *fix, int action)
483{ 488{
@@ -968,6 +973,18 @@ static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
968 } 973 }
969} 974}
970 975
976static void ad1884_fixup_thinkpad(struct hda_codec *codec,
977 const struct hda_fixup *fix, int action)
978{
979 struct ad198x_spec *spec = codec->spec;
980
981 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
982 spec->gen.keep_eapd_on = 1;
983 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
984 spec->eapd_nid = 0x12;
985 }
986}
987
971/* set magic COEFs for dmic */ 988/* set magic COEFs for dmic */
972static const struct hda_verb ad1884_dmic_init_verbs[] = { 989static const struct hda_verb ad1884_dmic_init_verbs[] = {
973 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7}, 990 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
@@ -979,6 +996,7 @@ enum {
979 AD1884_FIXUP_AMP_OVERRIDE, 996 AD1884_FIXUP_AMP_OVERRIDE,
980 AD1884_FIXUP_HP_EAPD, 997 AD1884_FIXUP_HP_EAPD,
981 AD1884_FIXUP_DMIC_COEF, 998 AD1884_FIXUP_DMIC_COEF,
999 AD1884_FIXUP_THINKPAD,
982 AD1884_FIXUP_HP_TOUCHSMART, 1000 AD1884_FIXUP_HP_TOUCHSMART,
983}; 1001};
984 1002
@@ -997,6 +1015,12 @@ static const struct hda_fixup ad1884_fixups[] = {
997 .type = HDA_FIXUP_VERBS, 1015 .type = HDA_FIXUP_VERBS,
998 .v.verbs = ad1884_dmic_init_verbs, 1016 .v.verbs = ad1884_dmic_init_verbs,
999 }, 1017 },
1018 [AD1884_FIXUP_THINKPAD] = {
1019 .type = HDA_FIXUP_FUNC,
1020 .v.func = ad1884_fixup_thinkpad,
1021 .chained = true,
1022 .chain_id = AD1884_FIXUP_DMIC_COEF,
1023 },
1000 [AD1884_FIXUP_HP_TOUCHSMART] = { 1024 [AD1884_FIXUP_HP_TOUCHSMART] = {
1001 .type = HDA_FIXUP_VERBS, 1025 .type = HDA_FIXUP_VERBS,
1002 .v.verbs = ad1884_dmic_init_verbs, 1026 .v.verbs = ad1884_dmic_init_verbs,
@@ -1008,7 +1032,7 @@ static const struct hda_fixup ad1884_fixups[] = {
1008static const struct snd_pci_quirk ad1884_fixup_tbl[] = { 1032static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1009 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART), 1033 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
1010 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD), 1034 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1011 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_DMIC_COEF), 1035 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
1012 {} 1036 {}
1013}; 1037};
1014 1038
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 6e9876f27d95..54d14793725a 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -759,7 +759,7 @@ struct ca0132_spec {
759/* 759/*
760 * CA0132 codec access 760 * CA0132 codec access
761 */ 761 */
762unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid, 762static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid,
763 unsigned int verb, unsigned int parm, unsigned int *res) 763 unsigned int verb, unsigned int parm, unsigned int *res)
764{ 764{
765 unsigned int response; 765 unsigned int response;
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 18d972501585..fc492ac24caa 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -47,6 +47,10 @@ struct cs_spec {
47 unsigned int spdif_present:1; 47 unsigned int spdif_present:1;
48 unsigned int sense_b:1; 48 unsigned int sense_b:1;
49 hda_nid_t vendor_nid; 49 hda_nid_t vendor_nid;
50
51 /* for MBP SPDIF control */
52 int (*spdif_sw_put)(struct snd_kcontrol *kcontrol,
53 struct snd_ctl_elem_value *ucontrol);
50}; 54};
51 55
52/* available models with CS420x */ 56/* available models with CS420x */
@@ -331,10 +335,21 @@ static int cs_init(struct hda_codec *codec)
331 return 0; 335 return 0;
332} 336}
333 337
338static int cs_build_controls(struct hda_codec *codec)
339{
340 int err;
341
342 err = snd_hda_gen_build_controls(codec);
343 if (err < 0)
344 return err;
345 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
346 return 0;
347}
348
334#define cs_free snd_hda_gen_free 349#define cs_free snd_hda_gen_free
335 350
336static const struct hda_codec_ops cs_patch_ops = { 351static const struct hda_codec_ops cs_patch_ops = {
337 .build_controls = snd_hda_gen_build_controls, 352 .build_controls = cs_build_controls,
338 .build_pcms = snd_hda_gen_build_pcms, 353 .build_pcms = snd_hda_gen_build_pcms,
339 .init = cs_init, 354 .init = cs_init,
340 .free = cs_free, 355 .free = cs_free,
@@ -597,18 +612,27 @@ static int patch_cs420x(struct hda_codec *codec)
597 * Its layout is no longer compatible with CS4206/CS4207 612 * Its layout is no longer compatible with CS4206/CS4207
598 */ 613 */
599enum { 614enum {
615 CS4208_MAC_AUTO,
600 CS4208_MBA6, 616 CS4208_MBA6,
617 CS4208_MBP11,
601 CS4208_GPIO0, 618 CS4208_GPIO0,
602}; 619};
603 620
604static const struct hda_model_fixup cs4208_models[] = { 621static const struct hda_model_fixup cs4208_models[] = {
605 { .id = CS4208_GPIO0, .name = "gpio0" }, 622 { .id = CS4208_GPIO0, .name = "gpio0" },
606 { .id = CS4208_MBA6, .name = "mba6" }, 623 { .id = CS4208_MBA6, .name = "mba6" },
624 { .id = CS4208_MBP11, .name = "mbp11" },
607 {} 625 {}
608}; 626};
609 627
610static const struct snd_pci_quirk cs4208_fixup_tbl[] = { 628static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
611 /* codec SSID */ 629 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS4208_MAC_AUTO),
630 {} /* terminator */
631};
632
633/* codec SSID matching */
634static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
635 SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
612 SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6), 636 SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
613 SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6), 637 SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6),
614 {} /* terminator */ 638 {} /* terminator */
@@ -626,6 +650,50 @@ static void cs4208_fixup_gpio0(struct hda_codec *codec,
626 } 650 }
627} 651}
628 652
653static const struct hda_fixup cs4208_fixups[];
654
655/* remap the fixup from codec SSID and apply it */
656static void cs4208_fixup_mac(struct hda_codec *codec,
657 const struct hda_fixup *fix, int action)
658{
659 if (action != HDA_FIXUP_ACT_PRE_PROBE)
660 return;
661 snd_hda_pick_fixup(codec, NULL, cs4208_mac_fixup_tbl, cs4208_fixups);
662 if (codec->fixup_id < 0 || codec->fixup_id == CS4208_MAC_AUTO)
663 codec->fixup_id = CS4208_GPIO0; /* default fixup */
664 snd_hda_apply_fixup(codec, action);
665}
666
667static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671 struct cs_spec *spec = codec->spec;
672 hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0];
673 int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0;
674
675 snd_hda_set_pin_ctl_cache(codec, pin, pinctl);
676 return spec->spdif_sw_put(kcontrol, ucontrol);
677}
678
679/* hook the SPDIF switch */
680static void cs4208_fixup_spdif_switch(struct hda_codec *codec,
681 const struct hda_fixup *fix, int action)
682{
683 if (action == HDA_FIXUP_ACT_BUILD) {
684 struct cs_spec *spec = codec->spec;
685 struct snd_kcontrol *kctl;
686
687 if (!spec->gen.autocfg.dig_out_pins[0])
688 return;
689 kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch");
690 if (!kctl)
691 return;
692 spec->spdif_sw_put = kctl->put;
693 kctl->put = cs4208_spdif_sw_put;
694 }
695}
696
629static const struct hda_fixup cs4208_fixups[] = { 697static const struct hda_fixup cs4208_fixups[] = {
630 [CS4208_MBA6] = { 698 [CS4208_MBA6] = {
631 .type = HDA_FIXUP_PINS, 699 .type = HDA_FIXUP_PINS,
@@ -633,10 +701,20 @@ static const struct hda_fixup cs4208_fixups[] = {
633 .chained = true, 701 .chained = true,
634 .chain_id = CS4208_GPIO0, 702 .chain_id = CS4208_GPIO0,
635 }, 703 },
704 [CS4208_MBP11] = {
705 .type = HDA_FIXUP_FUNC,
706 .v.func = cs4208_fixup_spdif_switch,
707 .chained = true,
708 .chain_id = CS4208_GPIO0,
709 },
636 [CS4208_GPIO0] = { 710 [CS4208_GPIO0] = {
637 .type = HDA_FIXUP_FUNC, 711 .type = HDA_FIXUP_FUNC,
638 .v.func = cs4208_fixup_gpio0, 712 .v.func = cs4208_fixup_gpio0,
639 }, 713 },
714 [CS4208_MAC_AUTO] = {
715 .type = HDA_FIXUP_FUNC,
716 .v.func = cs4208_fixup_mac,
717 },
640}; 718};
641 719
642/* correct the 0dB offset of input pins */ 720/* correct the 0dB offset of input pins */
@@ -660,6 +738,8 @@ static int patch_cs4208(struct hda_codec *codec)
660 return -ENOMEM; 738 return -ENOMEM;
661 739
662 spec->gen.automute_hook = cs_automute; 740 spec->gen.automute_hook = cs_automute;
741 /* exclude NID 0x10 (HP) from output volumes due to different steps */
742 spec->gen.out_vol_mask = 1ULL << 0x10;
663 743
664 snd_hda_pick_fixup(codec, cs4208_models, cs4208_fixup_tbl, 744 snd_hda_pick_fixup(codec, cs4208_models, cs4208_fixup_tbl,
665 cs4208_fixups); 745 cs4208_fixups);
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 4edd2d0f9a3c..c205bb1747fd 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -3208,11 +3208,17 @@ static int cx_auto_init(struct hda_codec *codec)
3208 return 0; 3208 return 0;
3209} 3209}
3210 3210
3211static void cx_auto_free(struct hda_codec *codec)
3212{
3213 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
3214 snd_hda_gen_free(codec);
3215}
3216
3211static const struct hda_codec_ops cx_auto_patch_ops = { 3217static const struct hda_codec_ops cx_auto_patch_ops = {
3212 .build_controls = cx_auto_build_controls, 3218 .build_controls = cx_auto_build_controls,
3213 .build_pcms = snd_hda_gen_build_pcms, 3219 .build_pcms = snd_hda_gen_build_pcms,
3214 .init = cx_auto_init, 3220 .init = cx_auto_init,
3215 .free = snd_hda_gen_free, 3221 .free = cx_auto_free,
3216 .unsol_event = snd_hda_jack_unsol_event, 3222 .unsol_event = snd_hda_jack_unsol_event,
3217#ifdef CONFIG_PM 3223#ifdef CONFIG_PM
3218 .check_power_status = snd_hda_gen_check_power_status, 3224 .check_power_status = snd_hda_gen_check_power_status,
@@ -3231,8 +3237,85 @@ enum {
3231 CXT_FIXUP_INC_MIC_BOOST, 3237 CXT_FIXUP_INC_MIC_BOOST,
3232 CXT_FIXUP_HEADPHONE_MIC_PIN, 3238 CXT_FIXUP_HEADPHONE_MIC_PIN,
3233 CXT_FIXUP_HEADPHONE_MIC, 3239 CXT_FIXUP_HEADPHONE_MIC,
3240 CXT_FIXUP_GPIO1,
3241 CXT_FIXUP_THINKPAD_ACPI,
3234}; 3242};
3235 3243
3244#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
3245
3246#include <linux/thinkpad_acpi.h>
3247
3248static int (*led_set_func)(int, bool);
3249
3250static void update_tpacpi_mute_led(void *private_data, int enabled)
3251{
3252 struct hda_codec *codec = private_data;
3253 struct conexant_spec *spec = codec->spec;
3254
3255 if (spec->dynamic_eapd)
3256 cx_auto_vmaster_hook(private_data, enabled);
3257
3258 if (led_set_func)
3259 led_set_func(TPACPI_LED_MUTE, !enabled);
3260}
3261
3262static void update_tpacpi_micmute_led(struct hda_codec *codec,
3263 struct snd_ctl_elem_value *ucontrol)
3264{
3265 if (!ucontrol || !led_set_func)
3266 return;
3267 if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
3268 /* TODO: How do I verify if it's a mono or stereo here? */
3269 bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1];
3270 led_set_func(TPACPI_LED_MICMUTE, !val);
3271 }
3272}
3273
3274static void cxt_fixup_thinkpad_acpi(struct hda_codec *codec,
3275 const struct hda_fixup *fix, int action)
3276{
3277 struct conexant_spec *spec = codec->spec;
3278
3279 bool removefunc = false;
3280
3281 if (action == HDA_FIXUP_ACT_PROBE) {
3282 if (!led_set_func)
3283 led_set_func = symbol_request(tpacpi_led_set);
3284 if (!led_set_func) {
3285 snd_printk(KERN_WARNING "Failed to find thinkpad-acpi symbol tpacpi_led_set\n");
3286 return;
3287 }
3288
3289 removefunc = true;
3290 if (led_set_func(TPACPI_LED_MUTE, false) >= 0) {
3291 spec->gen.vmaster_mute.hook = update_tpacpi_mute_led;
3292 removefunc = false;
3293 }
3294 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) {
3295 if (spec->gen.num_adc_nids > 1)
3296 snd_printdd("Skipping micmute LED control due to several ADCs");
3297 else {
3298 spec->gen.cap_sync_hook = update_tpacpi_micmute_led;
3299 removefunc = false;
3300 }
3301 }
3302 }
3303
3304 if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
3305 symbol_put(tpacpi_led_set);
3306 led_set_func = NULL;
3307 }
3308}
3309
3310#else
3311
3312static void cxt_fixup_thinkpad_acpi(struct hda_codec *codec,
3313 const struct hda_fixup *fix, int action)
3314{
3315}
3316
3317#endif
3318
3236static void cxt_fixup_stereo_dmic(struct hda_codec *codec, 3319static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
3237 const struct hda_fixup *fix, int action) 3320 const struct hda_fixup *fix, int action)
3238{ 3321{
@@ -3343,6 +3426,8 @@ static const struct hda_fixup cxt_fixups[] = {
3343 [CXT_PINCFG_LENOVO_TP410] = { 3426 [CXT_PINCFG_LENOVO_TP410] = {
3344 .type = HDA_FIXUP_PINS, 3427 .type = HDA_FIXUP_PINS,
3345 .v.pins = cxt_pincfg_lenovo_tp410, 3428 .v.pins = cxt_pincfg_lenovo_tp410,
3429 .chained = true,
3430 .chain_id = CXT_FIXUP_THINKPAD_ACPI,
3346 }, 3431 },
3347 [CXT_PINCFG_LEMOTE_A1004] = { 3432 [CXT_PINCFG_LEMOTE_A1004] = {
3348 .type = HDA_FIXUP_PINS, 3433 .type = HDA_FIXUP_PINS,
@@ -3375,6 +3460,19 @@ static const struct hda_fixup cxt_fixups[] = {
3375 .type = HDA_FIXUP_FUNC, 3460 .type = HDA_FIXUP_FUNC,
3376 .v.func = cxt_fixup_headphone_mic, 3461 .v.func = cxt_fixup_headphone_mic,
3377 }, 3462 },
3463 [CXT_FIXUP_GPIO1] = {
3464 .type = HDA_FIXUP_VERBS,
3465 .v.verbs = (const struct hda_verb[]) {
3466 { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
3467 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
3468 { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
3469 { }
3470 },
3471 },
3472 [CXT_FIXUP_THINKPAD_ACPI] = {
3473 .type = HDA_FIXUP_FUNC,
3474 .v.func = cxt_fixup_thinkpad_acpi,
3475 },
3378}; 3476};
3379 3477
3380static const struct snd_pci_quirk cxt5051_fixups[] = { 3478static const struct snd_pci_quirk cxt5051_fixups[] = {
@@ -3384,6 +3482,7 @@ static const struct snd_pci_quirk cxt5051_fixups[] = {
3384 3482
3385static const struct snd_pci_quirk cxt5066_fixups[] = { 3483static const struct snd_pci_quirk cxt5066_fixups[] = {
3386 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC), 3484 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
3485 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1),
3387 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN), 3486 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
3388 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), 3487 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3389 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), 3488 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
@@ -3496,7 +3595,7 @@ static int patch_conexant_auto(struct hda_codec *codec)
3496 return 0; 3595 return 0;
3497 3596
3498 error: 3597 error:
3499 snd_hda_gen_free(codec); 3598 cx_auto_free(codec);
3500 return err; 3599 return err;
3501} 3600}
3502 3601
@@ -3557,6 +3656,8 @@ static const struct hda_codec_preset snd_hda_preset_conexant[] = {
3557 .patch = patch_conexant_auto }, 3656 .patch = patch_conexant_auto },
3558 { .id = 0x14f15115, .name = "CX20757", 3657 { .id = 0x14f15115, .name = "CX20757",
3559 .patch = patch_conexant_auto }, 3658 .patch = patch_conexant_auto },
3659 { .id = 0x14f151d7, .name = "CX20952",
3660 .patch = patch_conexant_auto },
3560 {} /* terminator */ 3661 {} /* terminator */
3561}; 3662};
3562 3663
@@ -3583,6 +3684,7 @@ MODULE_ALIAS("snd-hda-codec-id:14f15111");
3583MODULE_ALIAS("snd-hda-codec-id:14f15113"); 3684MODULE_ALIAS("snd-hda-codec-id:14f15113");
3584MODULE_ALIAS("snd-hda-codec-id:14f15114"); 3685MODULE_ALIAS("snd-hda-codec-id:14f15114");
3585MODULE_ALIAS("snd-hda-codec-id:14f15115"); 3686MODULE_ALIAS("snd-hda-codec-id:14f15115");
3687MODULE_ALIAS("snd-hda-codec-id:14f151d7");
3586 3688
3587MODULE_LICENSE("GPL"); 3689MODULE_LICENSE("GPL");
3588MODULE_DESCRIPTION("Conexant HD-audio codec"); 3690MODULE_DESCRIPTION("Conexant HD-audio codec");
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 7ea0245fc6bd..08407bed093e 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -6,6 +6,7 @@
6 * Copyright (c) 2006 ATI Technologies Inc. 6 * Copyright (c) 2006 ATI Technologies Inc.
7 * Copyright (c) 2008 NVIDIA Corp. All rights reserved. 7 * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
8 * Copyright (c) 2008 Wei Ni <wni@nvidia.com> 8 * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
9 * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi>
9 * 10 *
10 * Authors: 11 * Authors:
11 * Wu Fengguang <wfg@linux.intel.com> 12 * Wu Fengguang <wfg@linux.intel.com>
@@ -45,6 +46,7 @@ module_param(static_hdmi_pcm, bool, 0644);
45MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); 46MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
46 47
47#define is_haswell(codec) ((codec)->vendor_id == 0x80862807) 48#define is_haswell(codec) ((codec)->vendor_id == 0x80862807)
49#define is_valleyview(codec) ((codec)->vendor_id == 0x80862882)
48 50
49struct hdmi_spec_per_cvt { 51struct hdmi_spec_per_cvt {
50 hda_nid_t cvt_nid; 52 hda_nid_t cvt_nid;
@@ -63,9 +65,11 @@ struct hdmi_spec_per_pin {
63 hda_nid_t pin_nid; 65 hda_nid_t pin_nid;
64 int num_mux_nids; 66 int num_mux_nids;
65 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; 67 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
68 hda_nid_t cvt_nid;
66 69
67 struct hda_codec *codec; 70 struct hda_codec *codec;
68 struct hdmi_eld sink_eld; 71 struct hdmi_eld sink_eld;
72 struct mutex lock;
69 struct delayed_work work; 73 struct delayed_work work;
70 struct snd_kcontrol *eld_ctl; 74 struct snd_kcontrol *eld_ctl;
71 int repoll_count; 75 int repoll_count;
@@ -75,6 +79,42 @@ struct hdmi_spec_per_pin {
75 bool chmap_set; /* channel-map override by ALSA API? */ 79 bool chmap_set; /* channel-map override by ALSA API? */
76 unsigned char chmap[8]; /* ALSA API channel-map */ 80 unsigned char chmap[8]; /* ALSA API channel-map */
77 char pcm_name[8]; /* filled in build_pcm callbacks */ 81 char pcm_name[8]; /* filled in build_pcm callbacks */
82#ifdef CONFIG_PROC_FS
83 struct snd_info_entry *proc_entry;
84#endif
85};
86
87struct cea_channel_speaker_allocation;
88
89/* operations used by generic code that can be overridden by patches */
90struct hdmi_ops {
91 int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
92 unsigned char *buf, int *eld_size);
93
94 /* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
95 int (*pin_get_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
96 int asp_slot);
97 int (*pin_set_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid,
98 int asp_slot, int channel);
99
100 void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
101 int ca, int active_channels, int conn_type);
102
103 /* enable/disable HBR (HD passthrough) */
104 int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr);
105
106 int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
107 hda_nid_t pin_nid, u32 stream_tag, int format);
108
109 /* Helpers for producing the channel map TLVs. These can be overridden
110 * for devices that have non-standard mapping requirements. */
111 int (*chmap_cea_alloc_validate_get_type)(struct cea_channel_speaker_allocation *cap,
112 int channels);
113 void (*cea_alloc_to_tlv_chmap)(struct cea_channel_speaker_allocation *cap,
114 unsigned int *chmap, int channels);
115
116 /* check that the user-given chmap is supported */
117 int (*chmap_validate)(int ca, int channels, unsigned char *chmap);
78}; 118};
79 119
80struct hdmi_spec { 120struct hdmi_spec {
@@ -88,8 +128,9 @@ struct hdmi_spec {
88 unsigned int channels_max; /* max over all cvts */ 128 unsigned int channels_max; /* max over all cvts */
89 129
90 struct hdmi_eld temp_eld; 130 struct hdmi_eld temp_eld;
131 struct hdmi_ops ops;
91 /* 132 /*
92 * Non-generic ATI/NVIDIA specific 133 * Non-generic VIA/NVIDIA specific
93 */ 134 */
94 struct hda_multi_out multiout; 135 struct hda_multi_out multiout;
95 struct hda_pcm_stream pcm_playback; 136 struct hda_pcm_stream pcm_playback;
@@ -348,17 +389,19 @@ static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
348{ 389{
349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
350 struct hdmi_spec *spec = codec->spec; 391 struct hdmi_spec *spec = codec->spec;
392 struct hdmi_spec_per_pin *per_pin;
351 struct hdmi_eld *eld; 393 struct hdmi_eld *eld;
352 int pin_idx; 394 int pin_idx;
353 395
354 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 396 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
355 397
356 pin_idx = kcontrol->private_value; 398 pin_idx = kcontrol->private_value;
357 eld = &get_pin(spec, pin_idx)->sink_eld; 399 per_pin = get_pin(spec, pin_idx);
400 eld = &per_pin->sink_eld;
358 401
359 mutex_lock(&eld->lock); 402 mutex_lock(&per_pin->lock);
360 uinfo->count = eld->eld_valid ? eld->eld_size : 0; 403 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
361 mutex_unlock(&eld->lock); 404 mutex_unlock(&per_pin->lock);
362 405
363 return 0; 406 return 0;
364} 407}
@@ -368,15 +411,17 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
368{ 411{
369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370 struct hdmi_spec *spec = codec->spec; 413 struct hdmi_spec *spec = codec->spec;
414 struct hdmi_spec_per_pin *per_pin;
371 struct hdmi_eld *eld; 415 struct hdmi_eld *eld;
372 int pin_idx; 416 int pin_idx;
373 417
374 pin_idx = kcontrol->private_value; 418 pin_idx = kcontrol->private_value;
375 eld = &get_pin(spec, pin_idx)->sink_eld; 419 per_pin = get_pin(spec, pin_idx);
420 eld = &per_pin->sink_eld;
376 421
377 mutex_lock(&eld->lock); 422 mutex_lock(&per_pin->lock);
378 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) { 423 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
379 mutex_unlock(&eld->lock); 424 mutex_unlock(&per_pin->lock);
380 snd_BUG(); 425 snd_BUG();
381 return -EINVAL; 426 return -EINVAL;
382 } 427 }
@@ -386,7 +431,7 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
386 if (eld->eld_valid) 431 if (eld->eld_valid)
387 memcpy(ucontrol->value.bytes.data, eld->eld_buffer, 432 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
388 eld->eld_size); 433 eld->eld_size);
389 mutex_unlock(&eld->lock); 434 mutex_unlock(&per_pin->lock);
390 435
391 return 0; 436 return 0;
392} 437}
@@ -477,6 +522,68 @@ static void hdmi_set_channel_count(struct hda_codec *codec,
477 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); 522 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
478} 523}
479 524
525/*
526 * ELD proc files
527 */
528
529#ifdef CONFIG_PROC_FS
530static void print_eld_info(struct snd_info_entry *entry,
531 struct snd_info_buffer *buffer)
532{
533 struct hdmi_spec_per_pin *per_pin = entry->private_data;
534
535 mutex_lock(&per_pin->lock);
536 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
537 mutex_unlock(&per_pin->lock);
538}
539
540static void write_eld_info(struct snd_info_entry *entry,
541 struct snd_info_buffer *buffer)
542{
543 struct hdmi_spec_per_pin *per_pin = entry->private_data;
544
545 mutex_lock(&per_pin->lock);
546 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
547 mutex_unlock(&per_pin->lock);
548}
549
550static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
551{
552 char name[32];
553 struct hda_codec *codec = per_pin->codec;
554 struct snd_info_entry *entry;
555 int err;
556
557 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
558 err = snd_card_proc_new(codec->bus->card, name, &entry);
559 if (err < 0)
560 return err;
561
562 snd_info_set_text_ops(entry, per_pin, print_eld_info);
563 entry->c.text.write = write_eld_info;
564 entry->mode |= S_IWUSR;
565 per_pin->proc_entry = entry;
566
567 return 0;
568}
569
570static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
571{
572 if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) {
573 snd_device_free(per_pin->codec->bus->card, per_pin->proc_entry);
574 per_pin->proc_entry = NULL;
575 }
576}
577#else
578static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
579 int index)
580{
581 return 0;
582}
583static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
584{
585}
586#endif
480 587
481/* 588/*
482 * Channel mapping routines 589 * Channel mapping routines
@@ -577,74 +684,91 @@ static void hdmi_debug_channel_mapping(struct hda_codec *codec,
577 hda_nid_t pin_nid) 684 hda_nid_t pin_nid)
578{ 685{
579#ifdef CONFIG_SND_DEBUG_VERBOSE 686#ifdef CONFIG_SND_DEBUG_VERBOSE
687 struct hdmi_spec *spec = codec->spec;
580 int i; 688 int i;
581 int slot; 689 int channel;
582 690
583 for (i = 0; i < 8; i++) { 691 for (i = 0; i < 8; i++) {
584 slot = snd_hda_codec_read(codec, pin_nid, 0, 692 channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i);
585 AC_VERB_GET_HDMI_CHAN_SLOT, i);
586 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", 693 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
587 slot >> 4, slot & 0xf); 694 channel, i);
588 } 695 }
589#endif 696#endif
590} 697}
591 698
592
593static void hdmi_std_setup_channel_mapping(struct hda_codec *codec, 699static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
594 hda_nid_t pin_nid, 700 hda_nid_t pin_nid,
595 bool non_pcm, 701 bool non_pcm,
596 int ca) 702 int ca)
597{ 703{
704 struct hdmi_spec *spec = codec->spec;
705 struct cea_channel_speaker_allocation *ch_alloc;
598 int i; 706 int i;
599 int err; 707 int err;
600 int order; 708 int order;
601 int non_pcm_mapping[8]; 709 int non_pcm_mapping[8];
602 710
603 order = get_channel_allocation_order(ca); 711 order = get_channel_allocation_order(ca);
712 ch_alloc = &channel_allocations[order];
604 713
605 if (hdmi_channel_mapping[ca][1] == 0) { 714 if (hdmi_channel_mapping[ca][1] == 0) {
606 for (i = 0; i < channel_allocations[order].channels; i++) 715 int hdmi_slot = 0;
607 hdmi_channel_mapping[ca][i] = i | (i << 4); 716 /* fill actual channel mappings in ALSA channel (i) order */
608 for (; i < 8; i++) 717 for (i = 0; i < ch_alloc->channels; i++) {
609 hdmi_channel_mapping[ca][i] = 0xf | (i << 4); 718 while (!ch_alloc->speakers[7 - hdmi_slot] && !WARN_ON(hdmi_slot >= 8))
719 hdmi_slot++; /* skip zero slots */
720
721 hdmi_channel_mapping[ca][i] = (i << 4) | hdmi_slot++;
722 }
723 /* fill the rest of the slots with ALSA channel 0xf */
724 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++)
725 if (!ch_alloc->speakers[7 - hdmi_slot])
726 hdmi_channel_mapping[ca][i++] = (0xf << 4) | hdmi_slot;
610 } 727 }
611 728
612 if (non_pcm) { 729 if (non_pcm) {
613 for (i = 0; i < channel_allocations[order].channels; i++) 730 for (i = 0; i < ch_alloc->channels; i++)
614 non_pcm_mapping[i] = i | (i << 4); 731 non_pcm_mapping[i] = (i << 4) | i;
615 for (; i < 8; i++) 732 for (; i < 8; i++)
616 non_pcm_mapping[i] = 0xf | (i << 4); 733 non_pcm_mapping[i] = (0xf << 4) | i;
617 } 734 }
618 735
619 for (i = 0; i < 8; i++) { 736 for (i = 0; i < 8; i++) {
620 err = snd_hda_codec_write(codec, pin_nid, 0, 737 int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i];
621 AC_VERB_SET_HDMI_CHAN_SLOT, 738 int hdmi_slot = slotsetup & 0x0f;
622 non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i]); 739 int channel = (slotsetup & 0xf0) >> 4;
740 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel);
623 if (err) { 741 if (err) {
624 snd_printdd(KERN_NOTICE 742 snd_printdd(KERN_NOTICE
625 "HDMI: channel mapping failed\n"); 743 "HDMI: channel mapping failed\n");
626 break; 744 break;
627 } 745 }
628 } 746 }
629
630 hdmi_debug_channel_mapping(codec, pin_nid);
631} 747}
632 748
633struct channel_map_table { 749struct channel_map_table {
634 unsigned char map; /* ALSA API channel map position */ 750 unsigned char map; /* ALSA API channel map position */
635 unsigned char cea_slot; /* CEA slot value */
636 int spk_mask; /* speaker position bit mask */ 751 int spk_mask; /* speaker position bit mask */
637}; 752};
638 753
639static struct channel_map_table map_tables[] = { 754static struct channel_map_table map_tables[] = {
640 { SNDRV_CHMAP_FL, 0x00, FL }, 755 { SNDRV_CHMAP_FL, FL },
641 { SNDRV_CHMAP_FR, 0x01, FR }, 756 { SNDRV_CHMAP_FR, FR },
642 { SNDRV_CHMAP_RL, 0x04, RL }, 757 { SNDRV_CHMAP_RL, RL },
643 { SNDRV_CHMAP_RR, 0x05, RR }, 758 { SNDRV_CHMAP_RR, RR },
644 { SNDRV_CHMAP_LFE, 0x02, LFE }, 759 { SNDRV_CHMAP_LFE, LFE },
645 { SNDRV_CHMAP_FC, 0x03, FC }, 760 { SNDRV_CHMAP_FC, FC },
646 { SNDRV_CHMAP_RLC, 0x06, RLC }, 761 { SNDRV_CHMAP_RLC, RLC },
647 { SNDRV_CHMAP_RRC, 0x07, RRC }, 762 { SNDRV_CHMAP_RRC, RRC },
763 { SNDRV_CHMAP_RC, RC },
764 { SNDRV_CHMAP_FLC, FLC },
765 { SNDRV_CHMAP_FRC, FRC },
766 { SNDRV_CHMAP_TFL, FLH },
767 { SNDRV_CHMAP_TFR, FRH },
768 { SNDRV_CHMAP_FLW, FLW },
769 { SNDRV_CHMAP_FRW, FRW },
770 { SNDRV_CHMAP_TC, TC },
771 { SNDRV_CHMAP_TFC, FCH },
648 {} /* terminator */ 772 {} /* terminator */
649}; 773};
650 774
@@ -660,25 +784,19 @@ static int to_spk_mask(unsigned char c)
660} 784}
661 785
662/* from ALSA API channel position to CEA slot */ 786/* from ALSA API channel position to CEA slot */
663static int to_cea_slot(unsigned char c) 787static int to_cea_slot(int ordered_ca, unsigned char pos)
664{ 788{
665 struct channel_map_table *t = map_tables; 789 int mask = to_spk_mask(pos);
666 for (; t->map; t++) { 790 int i;
667 if (t->map == c)
668 return t->cea_slot;
669 }
670 return 0x0f;
671}
672 791
673/* from CEA slot to ALSA API channel position */ 792 if (mask) {
674static int from_cea_slot(unsigned char c) 793 for (i = 0; i < 8; i++) {
675{ 794 if (channel_allocations[ordered_ca].speakers[7 - i] == mask)
676 struct channel_map_table *t = map_tables; 795 return i;
677 for (; t->map; t++) { 796 }
678 if (t->cea_slot == c)
679 return t->map;
680 } 797 }
681 return 0; 798
799 return -1;
682} 800}
683 801
684/* from speaker bit mask to ALSA API channel position */ 802/* from speaker bit mask to ALSA API channel position */
@@ -692,6 +810,14 @@ static int spk_to_chmap(int spk)
692 return 0; 810 return 0;
693} 811}
694 812
813/* from CEA slot to ALSA API channel position */
814static int from_cea_slot(int ordered_ca, unsigned char slot)
815{
816 int mask = channel_allocations[ordered_ca].speakers[7 - slot];
817
818 return spk_to_chmap(mask);
819}
820
695/* get the CA index corresponding to the given ALSA API channel map */ 821/* get the CA index corresponding to the given ALSA API channel map */
696static int hdmi_manual_channel_allocation(int chs, unsigned char *map) 822static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
697{ 823{
@@ -718,18 +844,29 @@ static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
718/* set up the channel slots for the given ALSA API channel map */ 844/* set up the channel slots for the given ALSA API channel map */
719static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec, 845static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
720 hda_nid_t pin_nid, 846 hda_nid_t pin_nid,
721 int chs, unsigned char *map) 847 int chs, unsigned char *map,
848 int ca)
722{ 849{
723 int i; 850 struct hdmi_spec *spec = codec->spec;
724 for (i = 0; i < 8; i++) { 851 int ordered_ca = get_channel_allocation_order(ca);
725 int val, err; 852 int alsa_pos, hdmi_slot;
726 if (i < chs) 853 int assignments[8] = {[0 ... 7] = 0xf};
727 val = to_cea_slot(map[i]); 854
728 else 855 for (alsa_pos = 0; alsa_pos < chs; alsa_pos++) {
729 val = 0xf; 856
730 val |= (i << 4); 857 hdmi_slot = to_cea_slot(ordered_ca, map[alsa_pos]);
731 err = snd_hda_codec_write(codec, pin_nid, 0, 858
732 AC_VERB_SET_HDMI_CHAN_SLOT, val); 859 if (hdmi_slot < 0)
860 continue; /* unassigned channel */
861
862 assignments[hdmi_slot] = alsa_pos;
863 }
864
865 for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) {
866 int err;
867
868 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot,
869 assignments[hdmi_slot]);
733 if (err) 870 if (err)
734 return -EINVAL; 871 return -EINVAL;
735 } 872 }
@@ -740,9 +877,10 @@ static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
740static void hdmi_setup_fake_chmap(unsigned char *map, int ca) 877static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
741{ 878{
742 int i; 879 int i;
880 int ordered_ca = get_channel_allocation_order(ca);
743 for (i = 0; i < 8; i++) { 881 for (i = 0; i < 8; i++) {
744 if (i < channel_allocations[ca].channels) 882 if (i < channel_allocations[ordered_ca].channels)
745 map[i] = from_cea_slot((hdmi_channel_mapping[ca][i] >> 4) & 0x0f); 883 map[i] = from_cea_slot(ordered_ca, hdmi_channel_mapping[ca][i] & 0x0f);
746 else 884 else
747 map[i] = 0; 885 map[i] = 0;
748 } 886 }
@@ -755,11 +893,29 @@ static void hdmi_setup_channel_mapping(struct hda_codec *codec,
755{ 893{
756 if (!non_pcm && chmap_set) { 894 if (!non_pcm && chmap_set) {
757 hdmi_manual_setup_channel_mapping(codec, pin_nid, 895 hdmi_manual_setup_channel_mapping(codec, pin_nid,
758 channels, map); 896 channels, map, ca);
759 } else { 897 } else {
760 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca); 898 hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca);
761 hdmi_setup_fake_chmap(map, ca); 899 hdmi_setup_fake_chmap(map, ca);
762 } 900 }
901
902 hdmi_debug_channel_mapping(codec, pin_nid);
903}
904
905static int hdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
906 int asp_slot, int channel)
907{
908 return snd_hda_codec_write(codec, pin_nid, 0,
909 AC_VERB_SET_HDMI_CHAN_SLOT,
910 (channel << 4) | asp_slot);
911}
912
913static int hdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
914 int asp_slot)
915{
916 return (snd_hda_codec_read(codec, pin_nid, 0,
917 AC_VERB_GET_HDMI_CHAN_SLOT,
918 asp_slot) & 0xf0) >> 4;
763} 919}
764 920
765/* 921/*
@@ -883,52 +1039,29 @@ static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
883 return true; 1039 return true;
884} 1040}
885 1041
886static void hdmi_setup_audio_infoframe(struct hda_codec *codec, 1042static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
887 struct hdmi_spec_per_pin *per_pin, 1043 hda_nid_t pin_nid,
888 bool non_pcm) 1044 int ca, int active_channels,
1045 int conn_type)
889{ 1046{
890 hda_nid_t pin_nid = per_pin->pin_nid;
891 int channels = per_pin->channels;
892 struct hdmi_eld *eld;
893 int ca;
894 union audio_infoframe ai; 1047 union audio_infoframe ai;
895 1048
896 if (!channels) 1049 if (conn_type == 0) { /* HDMI */
897 return;
898
899 if (is_haswell(codec))
900 snd_hda_codec_write(codec, pin_nid, 0,
901 AC_VERB_SET_AMP_GAIN_MUTE,
902 AMP_OUT_UNMUTE);
903
904 eld = &per_pin->sink_eld;
905 if (!eld->monitor_present)
906 return;
907
908 if (!non_pcm && per_pin->chmap_set)
909 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
910 else
911 ca = hdmi_channel_allocation(eld, channels);
912 if (ca < 0)
913 ca = 0;
914
915 memset(&ai, 0, sizeof(ai));
916 if (eld->info.conn_type == 0) { /* HDMI */
917 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi; 1050 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
918 1051
919 hdmi_ai->type = 0x84; 1052 hdmi_ai->type = 0x84;
920 hdmi_ai->ver = 0x01; 1053 hdmi_ai->ver = 0x01;
921 hdmi_ai->len = 0x0a; 1054 hdmi_ai->len = 0x0a;
922 hdmi_ai->CC02_CT47 = channels - 1; 1055 hdmi_ai->CC02_CT47 = active_channels - 1;
923 hdmi_ai->CA = ca; 1056 hdmi_ai->CA = ca;
924 hdmi_checksum_audio_infoframe(hdmi_ai); 1057 hdmi_checksum_audio_infoframe(hdmi_ai);
925 } else if (eld->info.conn_type == 1) { /* DisplayPort */ 1058 } else if (conn_type == 1) { /* DisplayPort */
926 struct dp_audio_infoframe *dp_ai = &ai.dp; 1059 struct dp_audio_infoframe *dp_ai = &ai.dp;
927 1060
928 dp_ai->type = 0x84; 1061 dp_ai->type = 0x84;
929 dp_ai->len = 0x1b; 1062 dp_ai->len = 0x1b;
930 dp_ai->ver = 0x11 << 2; 1063 dp_ai->ver = 0x11 << 2;
931 dp_ai->CC02_CT47 = channels - 1; 1064 dp_ai->CC02_CT47 = active_channels - 1;
932 dp_ai->CA = ca; 1065 dp_ai->CA = ca;
933 } else { 1066 } else {
934 snd_printd("HDMI: unknown connection type at pin %d\n", 1067 snd_printd("HDMI: unknown connection type at pin %d\n",
@@ -943,35 +1076,71 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
943 */ 1076 */
944 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes, 1077 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
945 sizeof(ai))) { 1078 sizeof(ai))) {
946 snd_printdd("hdmi_setup_audio_infoframe: " 1079 snd_printdd("hdmi_pin_setup_infoframe: "
947 "pin=%d channels=%d\n", 1080 "pin=%d channels=%d ca=0x%02x\n",
948 pin_nid, 1081 pin_nid,
949 channels); 1082 active_channels, ca);
950 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
951 channels, per_pin->chmap,
952 per_pin->chmap_set);
953 hdmi_stop_infoframe_trans(codec, pin_nid); 1083 hdmi_stop_infoframe_trans(codec, pin_nid);
954 hdmi_fill_audio_infoframe(codec, pin_nid, 1084 hdmi_fill_audio_infoframe(codec, pin_nid,
955 ai.bytes, sizeof(ai)); 1085 ai.bytes, sizeof(ai));
956 hdmi_start_infoframe_trans(codec, pin_nid); 1086 hdmi_start_infoframe_trans(codec, pin_nid);
957 } else {
958 /* For non-pcm audio switch, setup new channel mapping
959 * accordingly */
960 if (per_pin->non_pcm != non_pcm)
961 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
962 channels, per_pin->chmap,
963 per_pin->chmap_set);
964 } 1087 }
1088}
1089
1090static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
1091 struct hdmi_spec_per_pin *per_pin,
1092 bool non_pcm)
1093{
1094 struct hdmi_spec *spec = codec->spec;
1095 hda_nid_t pin_nid = per_pin->pin_nid;
1096 int channels = per_pin->channels;
1097 int active_channels;
1098 struct hdmi_eld *eld;
1099 int ca, ordered_ca;
1100
1101 if (!channels)
1102 return;
1103
1104 if (is_haswell(codec))
1105 snd_hda_codec_write(codec, pin_nid, 0,
1106 AC_VERB_SET_AMP_GAIN_MUTE,
1107 AMP_OUT_UNMUTE);
1108
1109 eld = &per_pin->sink_eld;
1110 if (!eld->monitor_present)
1111 return;
1112
1113 if (!non_pcm && per_pin->chmap_set)
1114 ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
1115 else
1116 ca = hdmi_channel_allocation(eld, channels);
1117 if (ca < 0)
1118 ca = 0;
1119
1120 ordered_ca = get_channel_allocation_order(ca);
1121 active_channels = channel_allocations[ordered_ca].channels;
1122
1123 hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels);
1124
1125 /*
1126 * always configure channel mapping, it may have been changed by the
1127 * user in the meantime
1128 */
1129 hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
1130 channels, per_pin->chmap,
1131 per_pin->chmap_set);
1132
1133 spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
1134 eld->info.conn_type);
965 1135
966 per_pin->non_pcm = non_pcm; 1136 per_pin->non_pcm = non_pcm;
967} 1137}
968 1138
969
970/* 1139/*
971 * Unsolicited events 1140 * Unsolicited events
972 */ 1141 */
973 1142
974static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); 1143static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
975 1144
976static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) 1145static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
977{ 1146{
@@ -997,8 +1166,8 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
997 if (pin_idx < 0) 1166 if (pin_idx < 0)
998 return; 1167 return;
999 1168
1000 hdmi_present_sense(get_pin(spec, pin_idx), 1); 1169 if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
1001 snd_hda_jack_report_sync(codec); 1170 snd_hda_jack_report_sync(codec);
1002} 1171}
1003 1172
1004static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 1173static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
@@ -1069,26 +1238,25 @@ static void haswell_verify_D0(struct hda_codec *codec,
1069#define is_hbr_format(format) \ 1238#define is_hbr_format(format) \
1070 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7) 1239 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
1071 1240
1072static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, 1241static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
1073 hda_nid_t pin_nid, u32 stream_tag, int format) 1242 bool hbr)
1074{ 1243{
1075 int pinctl; 1244 int pinctl, new_pinctl;
1076 int new_pinctl = 0;
1077
1078 if (is_haswell(codec))
1079 haswell_verify_D0(codec, cvt_nid, pin_nid);
1080 1245
1081 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) { 1246 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
1082 pinctl = snd_hda_codec_read(codec, pin_nid, 0, 1247 pinctl = snd_hda_codec_read(codec, pin_nid, 0,
1083 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 1248 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1084 1249
1250 if (pinctl < 0)
1251 return hbr ? -EINVAL : 0;
1252
1085 new_pinctl = pinctl & ~AC_PINCTL_EPT; 1253 new_pinctl = pinctl & ~AC_PINCTL_EPT;
1086 if (is_hbr_format(format)) 1254 if (hbr)
1087 new_pinctl |= AC_PINCTL_EPT_HBR; 1255 new_pinctl |= AC_PINCTL_EPT_HBR;
1088 else 1256 else
1089 new_pinctl |= AC_PINCTL_EPT_NATIVE; 1257 new_pinctl |= AC_PINCTL_EPT_NATIVE;
1090 1258
1091 snd_printdd("hdmi_setup_stream: " 1259 snd_printdd("hdmi_pin_hbr_setup: "
1092 "NID=0x%x, %spinctl=0x%x\n", 1260 "NID=0x%x, %spinctl=0x%x\n",
1093 pin_nid, 1261 pin_nid,
1094 pinctl == new_pinctl ? "" : "new-", 1262 pinctl == new_pinctl ? "" : "new-",
@@ -1098,11 +1266,26 @@ static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1098 snd_hda_codec_write(codec, pin_nid, 0, 1266 snd_hda_codec_write(codec, pin_nid, 0,
1099 AC_VERB_SET_PIN_WIDGET_CONTROL, 1267 AC_VERB_SET_PIN_WIDGET_CONTROL,
1100 new_pinctl); 1268 new_pinctl);
1269 } else if (hbr)
1270 return -EINVAL;
1101 1271
1102 } 1272 return 0;
1103 if (is_hbr_format(format) && !new_pinctl) { 1273}
1274
1275static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1276 hda_nid_t pin_nid, u32 stream_tag, int format)
1277{
1278 struct hdmi_spec *spec = codec->spec;
1279 int err;
1280
1281 if (is_haswell(codec))
1282 haswell_verify_D0(codec, cvt_nid, pin_nid);
1283
1284 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
1285
1286 if (err) {
1104 snd_printdd("hdmi_setup_stream: HBR is not supported\n"); 1287 snd_printdd("hdmi_setup_stream: HBR is not supported\n");
1105 return -EINVAL; 1288 return err;
1106 } 1289 }
1107 1290
1108 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format); 1291 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
@@ -1148,7 +1331,16 @@ static int hdmi_choose_cvt(struct hda_codec *codec,
1148 return 0; 1331 return 0;
1149} 1332}
1150 1333
1151static void haswell_config_cvts(struct hda_codec *codec, 1334/* Intel HDMI workaround to fix audio routing issue:
1335 * For some Intel display codecs, pins share the same connection list.
1336 * So a conveter can be selected by multiple pins and playback on any of these
1337 * pins will generate sound on the external display, because audio flows from
1338 * the same converter to the display pipeline. Also muting one pin may make
1339 * other pins have no sound output.
1340 * So this function assures that an assigned converter for a pin is not selected
1341 * by any other pins.
1342 */
1343static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1152 hda_nid_t pin_nid, int mux_idx) 1344 hda_nid_t pin_nid, int mux_idx)
1153{ 1345{
1154 struct hdmi_spec *spec = codec->spec; 1346 struct hdmi_spec *spec = codec->spec;
@@ -1219,6 +1411,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1219 per_cvt = get_cvt(spec, cvt_idx); 1411 per_cvt = get_cvt(spec, cvt_idx);
1220 /* Claim converter */ 1412 /* Claim converter */
1221 per_cvt->assigned = 1; 1413 per_cvt->assigned = 1;
1414 per_pin->cvt_nid = per_cvt->cvt_nid;
1222 hinfo->nid = per_cvt->cvt_nid; 1415 hinfo->nid = per_cvt->cvt_nid;
1223 1416
1224 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, 1417 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
@@ -1226,8 +1419,8 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1226 mux_idx); 1419 mux_idx);
1227 1420
1228 /* configure unused pins to choose other converters */ 1421 /* configure unused pins to choose other converters */
1229 if (is_haswell(codec)) 1422 if (is_haswell(codec) || is_valleyview(codec))
1230 haswell_config_cvts(codec, per_pin->pin_nid, mux_idx); 1423 intel_not_share_assigned_cvt(codec, per_pin->pin_nid, mux_idx);
1231 1424
1232 snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid); 1425 snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
1233 1426
@@ -1285,8 +1478,9 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1285 return 0; 1478 return 0;
1286} 1479}
1287 1480
1288static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) 1481static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1289{ 1482{
1483 struct hda_jack_tbl *jack;
1290 struct hda_codec *codec = per_pin->codec; 1484 struct hda_codec *codec = per_pin->codec;
1291 struct hdmi_spec *spec = codec->spec; 1485 struct hdmi_spec *spec = codec->spec;
1292 struct hdmi_eld *eld = &spec->temp_eld; 1486 struct hdmi_eld *eld = &spec->temp_eld;
@@ -1303,7 +1497,9 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1303 int present = snd_hda_pin_sense(codec, pin_nid); 1497 int present = snd_hda_pin_sense(codec, pin_nid);
1304 bool update_eld = false; 1498 bool update_eld = false;
1305 bool eld_changed = false; 1499 bool eld_changed = false;
1500 bool ret;
1306 1501
1502 mutex_lock(&per_pin->lock);
1307 pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); 1503 pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
1308 if (pin_eld->monitor_present) 1504 if (pin_eld->monitor_present)
1309 eld->eld_valid = !!(present & AC_PINSENSE_ELDV); 1505 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
@@ -1315,7 +1511,7 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1315 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid); 1511 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid);
1316 1512
1317 if (eld->eld_valid) { 1513 if (eld->eld_valid) {
1318 if (snd_hdmi_get_eld(codec, pin_nid, eld->eld_buffer, 1514 if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer,
1319 &eld->eld_size) < 0) 1515 &eld->eld_size) < 0)
1320 eld->eld_valid = false; 1516 eld->eld_valid = false;
1321 else { 1517 else {
@@ -1333,11 +1529,10 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1333 queue_delayed_work(codec->bus->workq, 1529 queue_delayed_work(codec->bus->workq,
1334 &per_pin->work, 1530 &per_pin->work,
1335 msecs_to_jiffies(300)); 1531 msecs_to_jiffies(300));
1336 return; 1532 goto unlock;
1337 } 1533 }
1338 } 1534 }
1339 1535
1340 mutex_lock(&pin_eld->lock);
1341 if (pin_eld->eld_valid && !eld->eld_valid) { 1536 if (pin_eld->eld_valid && !eld->eld_valid) {
1342 update_eld = true; 1537 update_eld = true;
1343 eld_changed = true; 1538 eld_changed = true;
@@ -1354,20 +1549,29 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1354 pin_eld->eld_size = eld->eld_size; 1549 pin_eld->eld_size = eld->eld_size;
1355 pin_eld->info = eld->info; 1550 pin_eld->info = eld->info;
1356 1551
1357 /* Haswell-specific workaround: re-setup when the transcoder is 1552 /*
1358 * changed during the stream playback 1553 * Re-setup pin and infoframe. This is needed e.g. when
1554 * - sink is first plugged-in (infoframe is not set up if !monitor_present)
1555 * - transcoder can change during stream playback on Haswell
1359 */ 1556 */
1360 if (is_haswell(codec) && 1557 if (eld->eld_valid && !old_eld_valid && per_pin->setup)
1361 eld->eld_valid && !old_eld_valid && per_pin->setup)
1362 hdmi_setup_audio_infoframe(codec, per_pin, 1558 hdmi_setup_audio_infoframe(codec, per_pin,
1363 per_pin->non_pcm); 1559 per_pin->non_pcm);
1364 } 1560 }
1365 mutex_unlock(&pin_eld->lock);
1366 1561
1367 if (eld_changed) 1562 if (eld_changed)
1368 snd_ctl_notify(codec->bus->card, 1563 snd_ctl_notify(codec->bus->card,
1369 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, 1564 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
1370 &per_pin->eld_ctl->id); 1565 &per_pin->eld_ctl->id);
1566 unlock:
1567 ret = !repoll || !pin_eld->monitor_present || pin_eld->eld_valid;
1568
1569 jack = snd_hda_jack_tbl_get(codec, pin_nid);
1570 if (jack)
1571 jack->block_report = !ret;
1572
1573 mutex_unlock(&per_pin->lock);
1574 return ret;
1371} 1575}
1372 1576
1373static void hdmi_repoll_eld(struct work_struct *work) 1577static void hdmi_repoll_eld(struct work_struct *work)
@@ -1378,7 +1582,8 @@ static void hdmi_repoll_eld(struct work_struct *work)
1378 if (per_pin->repoll_count++ > 6) 1582 if (per_pin->repoll_count++ > 6)
1379 per_pin->repoll_count = 0; 1583 per_pin->repoll_count = 0;
1380 1584
1381 hdmi_present_sense(per_pin, per_pin->repoll_count); 1585 if (hdmi_present_sense(per_pin, per_pin->repoll_count))
1586 snd_hda_jack_report_sync(per_pin->codec);
1382} 1587}
1383 1588
1384static void intel_haswell_fixup_connect_list(struct hda_codec *codec, 1589static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
@@ -1538,14 +1743,14 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1538 bool non_pcm; 1743 bool non_pcm;
1539 1744
1540 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); 1745 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
1746 mutex_lock(&per_pin->lock);
1541 per_pin->channels = substream->runtime->channels; 1747 per_pin->channels = substream->runtime->channels;
1542 per_pin->setup = true; 1748 per_pin->setup = true;
1543 1749
1544 hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
1545
1546 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); 1750 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
1751 mutex_unlock(&per_pin->lock);
1547 1752
1548 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); 1753 return spec->ops.setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
1549} 1754}
1550 1755
1551static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 1756static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
@@ -1581,11 +1786,14 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1581 per_pin = get_pin(spec, pin_idx); 1786 per_pin = get_pin(spec, pin_idx);
1582 1787
1583 snd_hda_spdif_ctls_unassign(codec, pin_idx); 1788 snd_hda_spdif_ctls_unassign(codec, pin_idx);
1789
1790 mutex_lock(&per_pin->lock);
1584 per_pin->chmap_set = false; 1791 per_pin->chmap_set = false;
1585 memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); 1792 memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
1586 1793
1587 per_pin->setup = false; 1794 per_pin->setup = false;
1588 per_pin->channels = 0; 1795 per_pin->channels = 0;
1796 mutex_unlock(&per_pin->lock);
1589 } 1797 }
1590 1798
1591 return 0; 1799 return 0;
@@ -1614,14 +1822,40 @@ static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
1614 return 0; 1822 return 0;
1615} 1823}
1616 1824
1825static int hdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
1826 int channels)
1827{
1828 /* If the speaker allocation matches the channel count, it is OK.*/
1829 if (cap->channels != channels)
1830 return -1;
1831
1832 /* all channels are remappable freely */
1833 return SNDRV_CTL_TLVT_CHMAP_VAR;
1834}
1835
1836static void hdmi_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap,
1837 unsigned int *chmap, int channels)
1838{
1839 int count = 0;
1840 int c;
1841
1842 for (c = 7; c >= 0; c--) {
1843 int spk = cap->speakers[c];
1844 if (!spk)
1845 continue;
1846
1847 chmap[count++] = spk_to_chmap(spk);
1848 }
1849
1850 WARN_ON(count != channels);
1851}
1852
1617static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1853static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1618 unsigned int size, unsigned int __user *tlv) 1854 unsigned int size, unsigned int __user *tlv)
1619{ 1855{
1620 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); 1856 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
1621 struct hda_codec *codec = info->private_data; 1857 struct hda_codec *codec = info->private_data;
1622 struct hdmi_spec *spec = codec->spec; 1858 struct hdmi_spec *spec = codec->spec;
1623 const unsigned int valid_mask =
1624 FL | FR | RL | RR | LFE | FC | RLC | RRC;
1625 unsigned int __user *dst; 1859 unsigned int __user *dst;
1626 int chs, count = 0; 1860 int chs, count = 0;
1627 1861
@@ -1632,18 +1866,19 @@ static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1632 size -= 8; 1866 size -= 8;
1633 dst = tlv + 2; 1867 dst = tlv + 2;
1634 for (chs = 2; chs <= spec->channels_max; chs++) { 1868 for (chs = 2; chs <= spec->channels_max; chs++) {
1635 int i, c; 1869 int i;
1636 struct cea_channel_speaker_allocation *cap; 1870 struct cea_channel_speaker_allocation *cap;
1637 cap = channel_allocations; 1871 cap = channel_allocations;
1638 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) { 1872 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) {
1639 int chs_bytes = chs * 4; 1873 int chs_bytes = chs * 4;
1640 if (cap->channels != chs) 1874 int type = spec->ops.chmap_cea_alloc_validate_get_type(cap, chs);
1641 continue; 1875 unsigned int tlv_chmap[8];
1642 if (cap->spk_mask & ~valid_mask) 1876
1877 if (type < 0)
1643 continue; 1878 continue;
1644 if (size < 8) 1879 if (size < 8)
1645 return -ENOMEM; 1880 return -ENOMEM;
1646 if (put_user(SNDRV_CTL_TLVT_CHMAP_VAR, dst) || 1881 if (put_user(type, dst) ||
1647 put_user(chs_bytes, dst + 1)) 1882 put_user(chs_bytes, dst + 1))
1648 return -EFAULT; 1883 return -EFAULT;
1649 dst += 2; 1884 dst += 2;
@@ -1653,14 +1888,10 @@ static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1653 return -ENOMEM; 1888 return -ENOMEM;
1654 size -= chs_bytes; 1889 size -= chs_bytes;
1655 count += chs_bytes; 1890 count += chs_bytes;
1656 for (c = 7; c >= 0; c--) { 1891 spec->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs);
1657 int spk = cap->speakers[c]; 1892 if (copy_to_user(dst, tlv_chmap, chs_bytes))
1658 if (!spk) 1893 return -EFAULT;
1659 continue; 1894 dst += chs;
1660 if (put_user(spk_to_chmap(spk), dst))
1661 return -EFAULT;
1662 dst++;
1663 }
1664 } 1895 }
1665 } 1896 }
1666 if (put_user(count, tlv + 1)) 1897 if (put_user(count, tlv + 1))
@@ -1694,7 +1925,7 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
1694 unsigned int ctl_idx; 1925 unsigned int ctl_idx;
1695 struct snd_pcm_substream *substream; 1926 struct snd_pcm_substream *substream;
1696 unsigned char chmap[8]; 1927 unsigned char chmap[8];
1697 int i, ca, prepared = 0; 1928 int i, err, ca, prepared = 0;
1698 1929
1699 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 1930 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1700 substream = snd_pcm_chmap_substream(info, ctl_idx); 1931 substream = snd_pcm_chmap_substream(info, ctl_idx);
@@ -1718,10 +1949,17 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
1718 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap); 1949 ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
1719 if (ca < 0) 1950 if (ca < 0)
1720 return -EINVAL; 1951 return -EINVAL;
1952 if (spec->ops.chmap_validate) {
1953 err = spec->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap);
1954 if (err)
1955 return err;
1956 }
1957 mutex_lock(&per_pin->lock);
1721 per_pin->chmap_set = true; 1958 per_pin->chmap_set = true;
1722 memcpy(per_pin->chmap, chmap, sizeof(chmap)); 1959 memcpy(per_pin->chmap, chmap, sizeof(chmap));
1723 if (prepared) 1960 if (prepared)
1724 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); 1961 hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
1962 mutex_unlock(&per_pin->lock);
1725 1963
1726 return 0; 1964 return 0;
1727} 1965}
@@ -1838,12 +2076,11 @@ static int generic_hdmi_init_per_pins(struct hda_codec *codec)
1838 2076
1839 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2077 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1840 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2078 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1841 struct hdmi_eld *eld = &per_pin->sink_eld;
1842 2079
1843 per_pin->codec = codec; 2080 per_pin->codec = codec;
1844 mutex_init(&eld->lock); 2081 mutex_init(&per_pin->lock);
1845 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld); 2082 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
1846 snd_hda_eld_proc_new(codec, eld, pin_idx); 2083 eld_proc_new(per_pin, pin_idx);
1847 } 2084 }
1848 return 0; 2085 return 0;
1849} 2086}
@@ -1884,10 +2121,9 @@ static void generic_hdmi_free(struct hda_codec *codec)
1884 2121
1885 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2122 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1886 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2123 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1887 struct hdmi_eld *eld = &per_pin->sink_eld;
1888 2124
1889 cancel_delayed_work(&per_pin->work); 2125 cancel_delayed_work(&per_pin->work);
1890 snd_hda_eld_proc_free(codec, eld); 2126 eld_proc_free(per_pin);
1891 } 2127 }
1892 2128
1893 flush_workqueue(codec->bus->workq); 2129 flush_workqueue(codec->bus->workq);
@@ -1924,6 +2160,17 @@ static const struct hda_codec_ops generic_hdmi_patch_ops = {
1924#endif 2160#endif
1925}; 2161};
1926 2162
2163static const struct hdmi_ops generic_standard_hdmi_ops = {
2164 .pin_get_eld = snd_hdmi_get_eld,
2165 .pin_get_slot_channel = hdmi_pin_get_slot_channel,
2166 .pin_set_slot_channel = hdmi_pin_set_slot_channel,
2167 .pin_setup_infoframe = hdmi_pin_setup_infoframe,
2168 .pin_hbr_setup = hdmi_pin_hbr_setup,
2169 .setup_stream = hdmi_setup_stream,
2170 .chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type,
2171 .cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap,
2172};
2173
1927 2174
1928static void intel_haswell_fixup_connect_list(struct hda_codec *codec, 2175static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
1929 hda_nid_t nid) 2176 hda_nid_t nid)
@@ -2006,6 +2253,7 @@ static int patch_generic_hdmi(struct hda_codec *codec)
2006 if (spec == NULL) 2253 if (spec == NULL)
2007 return -ENOMEM; 2254 return -ENOMEM;
2008 2255
2256 spec->ops = generic_standard_hdmi_ops;
2009 codec->spec = spec; 2257 codec->spec = spec;
2010 hdmi_array_init(spec, 4); 2258 hdmi_array_init(spec, 4);
2011 2259
@@ -2561,49 +2809,398 @@ static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
2561} 2809}
2562 2810
2563/* 2811/*
2564 * ATI-specific implementations 2812 * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
2565 * 2813 * - 0x10de0015
2566 * FIXME: we may omit the whole this and use the generic code once after 2814 * - 0x10de0040
2567 * it's confirmed to work. 2815 */
2816static int nvhdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
2817 int channels)
2818{
2819 if (cap->ca_index == 0x00 && channels == 2)
2820 return SNDRV_CTL_TLVT_CHMAP_FIXED;
2821
2822 return hdmi_chmap_cea_alloc_validate_get_type(cap, channels);
2823}
2824
2825static int nvhdmi_chmap_validate(int ca, int chs, unsigned char *map)
2826{
2827 if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
2828 return -EINVAL;
2829
2830 return 0;
2831}
2832
2833static int patch_nvhdmi(struct hda_codec *codec)
2834{
2835 struct hdmi_spec *spec;
2836 int err;
2837
2838 err = patch_generic_hdmi(codec);
2839 if (err)
2840 return err;
2841
2842 spec = codec->spec;
2843
2844 spec->ops.chmap_cea_alloc_validate_get_type =
2845 nvhdmi_chmap_cea_alloc_validate_get_type;
2846 spec->ops.chmap_validate = nvhdmi_chmap_validate;
2847
2848 return 0;
2849}
2850
2851/*
2852 * ATI/AMD-specific implementations
2568 */ 2853 */
2569 2854
2570#define ATIHDMI_CVT_NID 0x02 /* audio converter */ 2855#define is_amdhdmi_rev3_or_later(codec) \
2571#define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */ 2856 ((codec)->vendor_id == 0x1002aa01 && ((codec)->revision_id & 0xff00) >= 0x0300)
2857#define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
2858
2859/* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
2860#define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
2861#define ATI_VERB_SET_DOWNMIX_INFO 0x772
2862#define ATI_VERB_SET_MULTICHANNEL_01 0x777
2863#define ATI_VERB_SET_MULTICHANNEL_23 0x778
2864#define ATI_VERB_SET_MULTICHANNEL_45 0x779
2865#define ATI_VERB_SET_MULTICHANNEL_67 0x77a
2866#define ATI_VERB_SET_HBR_CONTROL 0x77c
2867#define ATI_VERB_SET_MULTICHANNEL_1 0x785
2868#define ATI_VERB_SET_MULTICHANNEL_3 0x786
2869#define ATI_VERB_SET_MULTICHANNEL_5 0x787
2870#define ATI_VERB_SET_MULTICHANNEL_7 0x788
2871#define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
2872#define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
2873#define ATI_VERB_GET_DOWNMIX_INFO 0xf72
2874#define ATI_VERB_GET_MULTICHANNEL_01 0xf77
2875#define ATI_VERB_GET_MULTICHANNEL_23 0xf78
2876#define ATI_VERB_GET_MULTICHANNEL_45 0xf79
2877#define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
2878#define ATI_VERB_GET_HBR_CONTROL 0xf7c
2879#define ATI_VERB_GET_MULTICHANNEL_1 0xf85
2880#define ATI_VERB_GET_MULTICHANNEL_3 0xf86
2881#define ATI_VERB_GET_MULTICHANNEL_5 0xf87
2882#define ATI_VERB_GET_MULTICHANNEL_7 0xf88
2883#define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
2884
2885/* AMD specific HDA cvt verbs */
2886#define ATI_VERB_SET_RAMP_RATE 0x770
2887#define ATI_VERB_GET_RAMP_RATE 0xf70
2888
2889#define ATI_OUT_ENABLE 0x1
2890
2891#define ATI_MULTICHANNEL_MODE_PAIRED 0
2892#define ATI_MULTICHANNEL_MODE_SINGLE 1
2893
2894#define ATI_HBR_CAPABLE 0x01
2895#define ATI_HBR_ENABLE 0x10
2896
2897static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
2898 unsigned char *buf, int *eld_size)
2899{
2900 /* call hda_eld.c ATI/AMD-specific function */
2901 return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
2902 is_amdhdmi_rev3_or_later(codec));
2903}
2904
2905static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca,
2906 int active_channels, int conn_type)
2907{
2908 snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
2909}
2910
2911static int atihdmi_paired_swap_fc_lfe(int pos)
2912{
2913 /*
2914 * ATI/AMD have automatic FC/LFE swap built-in
2915 * when in pairwise mapping mode.
2916 */
2917
2918 switch (pos) {
2919 /* see channel_allocations[].speakers[] */
2920 case 2: return 3;
2921 case 3: return 2;
2922 default: break;
2923 }
2924
2925 return pos;
2926}
2572 2927
2573static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2928static int atihdmi_paired_chmap_validate(int ca, int chs, unsigned char *map)
2574 struct hda_codec *codec, 2929{
2575 unsigned int stream_tag, 2930 struct cea_channel_speaker_allocation *cap;
2576 unsigned int format, 2931 int i, j;
2577 struct snd_pcm_substream *substream) 2932
2933 /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
2934
2935 cap = &channel_allocations[get_channel_allocation_order(ca)];
2936 for (i = 0; i < chs; ++i) {
2937 int mask = to_spk_mask(map[i]);
2938 bool ok = false;
2939 bool companion_ok = false;
2940
2941 if (!mask)
2942 continue;
2943
2944 for (j = 0 + i % 2; j < 8; j += 2) {
2945 int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
2946 if (cap->speakers[chan_idx] == mask) {
2947 /* channel is in a supported position */
2948 ok = true;
2949
2950 if (i % 2 == 0 && i + 1 < chs) {
2951 /* even channel, check the odd companion */
2952 int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
2953 int comp_mask_req = to_spk_mask(map[i+1]);
2954 int comp_mask_act = cap->speakers[comp_chan_idx];
2955
2956 if (comp_mask_req == comp_mask_act)
2957 companion_ok = true;
2958 else
2959 return -EINVAL;
2960 }
2961 break;
2962 }
2963 }
2964
2965 if (!ok)
2966 return -EINVAL;
2967
2968 if (companion_ok)
2969 i++; /* companion channel already checked */
2970 }
2971
2972 return 0;
2973}
2974
2975static int atihdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
2976 int hdmi_slot, int stream_channel)
2977{
2978 int verb;
2979 int ati_channel_setup = 0;
2980
2981 if (hdmi_slot > 7)
2982 return -EINVAL;
2983
2984 if (!has_amd_full_remap_support(codec)) {
2985 hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
2986
2987 /* In case this is an odd slot but without stream channel, do not
2988 * disable the slot since the corresponding even slot could have a
2989 * channel. In case neither have a channel, the slot pair will be
2990 * disabled when this function is called for the even slot. */
2991 if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
2992 return 0;
2993
2994 hdmi_slot -= hdmi_slot % 2;
2995
2996 if (stream_channel != 0xf)
2997 stream_channel -= stream_channel % 2;
2998 }
2999
3000 verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
3001
3002 /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
3003
3004 if (stream_channel != 0xf)
3005 ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
3006
3007 return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
3008}
3009
3010static int atihdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid,
3011 int asp_slot)
3012{
3013 bool was_odd = false;
3014 int ati_asp_slot = asp_slot;
3015 int verb;
3016 int ati_channel_setup;
3017
3018 if (asp_slot > 7)
3019 return -EINVAL;
3020
3021 if (!has_amd_full_remap_support(codec)) {
3022 ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
3023 if (ati_asp_slot % 2 != 0) {
3024 ati_asp_slot -= 1;
3025 was_odd = true;
3026 }
3027 }
3028
3029 verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
3030
3031 ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
3032
3033 if (!(ati_channel_setup & ATI_OUT_ENABLE))
3034 return 0xf;
3035
3036 return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
3037}
3038
3039static int atihdmi_paired_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap,
3040 int channels)
3041{
3042 int c;
3043
3044 /*
3045 * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
3046 * we need to take that into account (a single channel may take 2
3047 * channel slots if we need to carry a silent channel next to it).
3048 * On Rev3+ AMD codecs this function is not used.
3049 */
3050 int chanpairs = 0;
3051
3052 /* We only produce even-numbered channel count TLVs */
3053 if ((channels % 2) != 0)
3054 return -1;
3055
3056 for (c = 0; c < 7; c += 2) {
3057 if (cap->speakers[c] || cap->speakers[c+1])
3058 chanpairs++;
3059 }
3060
3061 if (chanpairs * 2 != channels)
3062 return -1;
3063
3064 return SNDRV_CTL_TLVT_CHMAP_PAIRED;
3065}
3066
3067static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap,
3068 unsigned int *chmap, int channels)
3069{
3070 /* produce paired maps for pre-rev3 ATI/AMD codecs */
3071 int count = 0;
3072 int c;
3073
3074 for (c = 7; c >= 0; c--) {
3075 int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
3076 int spk = cap->speakers[chan];
3077 if (!spk) {
3078 /* add N/A channel if the companion channel is occupied */
3079 if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
3080 chmap[count++] = SNDRV_CHMAP_NA;
3081
3082 continue;
3083 }
3084
3085 chmap[count++] = spk_to_chmap(spk);
3086 }
3087
3088 WARN_ON(count != channels);
3089}
3090
3091static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3092 bool hbr)
3093{
3094 int hbr_ctl, hbr_ctl_new;
3095
3096 hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
3097 if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
3098 if (hbr)
3099 hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
3100 else
3101 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
3102
3103 snd_printdd("atihdmi_pin_hbr_setup: "
3104 "NID=0x%x, %shbr-ctl=0x%x\n",
3105 pin_nid,
3106 hbr_ctl == hbr_ctl_new ? "" : "new-",
3107 hbr_ctl_new);
3108
3109 if (hbr_ctl != hbr_ctl_new)
3110 snd_hda_codec_write(codec, pin_nid, 0,
3111 ATI_VERB_SET_HBR_CONTROL,
3112 hbr_ctl_new);
3113
3114 } else if (hbr)
3115 return -EINVAL;
3116
3117 return 0;
3118}
3119
3120static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
3121 hda_nid_t pin_nid, u32 stream_tag, int format)
3122{
3123
3124 if (is_amdhdmi_rev3_or_later(codec)) {
3125 int ramp_rate = 180; /* default as per AMD spec */
3126 /* disable ramp-up/down for non-pcm as per AMD spec */
3127 if (format & AC_FMT_TYPE_NON_PCM)
3128 ramp_rate = 0;
3129
3130 snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
3131 }
3132
3133 return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
3134}
3135
3136
3137static int atihdmi_init(struct hda_codec *codec)
2578{ 3138{
2579 struct hdmi_spec *spec = codec->spec; 3139 struct hdmi_spec *spec = codec->spec;
2580 struct hdmi_spec_per_cvt *per_cvt = get_cvt(spec, 0); 3140 int pin_idx, err;
2581 int chans = substream->runtime->channels;
2582 int i, err;
2583 3141
2584 err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format, 3142 err = generic_hdmi_init(codec);
2585 substream); 3143
2586 if (err < 0) 3144 if (err)
2587 return err; 3145 return err;
2588 snd_hda_codec_write(codec, per_cvt->cvt_nid, 0, 3146
2589 AC_VERB_SET_CVT_CHAN_COUNT, chans - 1); 3147 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2590 /* FIXME: XXX */ 3148 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2591 for (i = 0; i < chans; i++) { 3149
2592 snd_hda_codec_write(codec, per_cvt->cvt_nid, 0, 3150 /* make sure downmix information in infoframe is zero */
2593 AC_VERB_SET_HDMI_CHAN_SLOT, 3151 snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
2594 (i << 4) | i); 3152
3153 /* enable channel-wise remap mode if supported */
3154 if (has_amd_full_remap_support(codec))
3155 snd_hda_codec_write(codec, per_pin->pin_nid, 0,
3156 ATI_VERB_SET_MULTICHANNEL_MODE,
3157 ATI_MULTICHANNEL_MODE_SINGLE);
2595 } 3158 }
3159
2596 return 0; 3160 return 0;
2597} 3161}
2598 3162
2599static int patch_atihdmi(struct hda_codec *codec) 3163static int patch_atihdmi(struct hda_codec *codec)
2600{ 3164{
2601 struct hdmi_spec *spec; 3165 struct hdmi_spec *spec;
2602 int err = patch_simple_hdmi(codec, ATIHDMI_CVT_NID, ATIHDMI_PIN_NID); 3166 struct hdmi_spec_per_cvt *per_cvt;
2603 if (err < 0) 3167 int err, cvt_idx;
3168
3169 err = patch_generic_hdmi(codec);
3170
3171 if (err)
2604 return err; 3172 return err;
3173
3174 codec->patch_ops.init = atihdmi_init;
3175
2605 spec = codec->spec; 3176 spec = codec->spec;
2606 spec->pcm_playback.ops.prepare = atihdmi_playback_pcm_prepare; 3177
3178 spec->ops.pin_get_eld = atihdmi_pin_get_eld;
3179 spec->ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
3180 spec->ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
3181 spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
3182 spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
3183 spec->ops.setup_stream = atihdmi_setup_stream;
3184
3185 if (!has_amd_full_remap_support(codec)) {
3186 /* override to ATI/AMD-specific versions with pairwise mapping */
3187 spec->ops.chmap_cea_alloc_validate_get_type =
3188 atihdmi_paired_chmap_cea_alloc_validate_get_type;
3189 spec->ops.cea_alloc_to_tlv_chmap = atihdmi_paired_cea_alloc_to_tlv_chmap;
3190 spec->ops.chmap_validate = atihdmi_paired_chmap_validate;
3191 }
3192
3193 /* ATI/AMD converters do not advertise all of their capabilities */
3194 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
3195 per_cvt = get_cvt(spec, cvt_idx);
3196 per_cvt->channels_max = max(per_cvt->channels_max, 8u);
3197 per_cvt->rates |= SUPPORTED_RATES;
3198 per_cvt->formats |= SUPPORTED_FORMATS;
3199 per_cvt->maxbps = max(per_cvt->maxbps, 24u);
3200 }
3201
3202 spec->channels_max = max(spec->channels_max, 8u);
3203
2607 return 0; 3204 return 0;
2608} 3205}
2609 3206
@@ -2623,7 +3220,7 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
2623{ .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi }, 3220{ .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
2624{ .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi }, 3221{ .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
2625{ .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi }, 3222{ .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
2626{ .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi }, 3223{ .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_atihdmi },
2627{ .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi }, 3224{ .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
2628{ .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi }, 3225{ .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
2629{ .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi }, 3226{ .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
@@ -2632,30 +3229,30 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
2632{ .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, 3229{ .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2633{ .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, 3230{ .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
2634{ .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x }, 3231{ .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
2635{ .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi }, 3232{ .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_nvhdmi },
2636{ .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi }, 3233{ .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_nvhdmi },
2637{ .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi }, 3234{ .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_nvhdmi },
2638{ .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi }, 3235{ .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_nvhdmi },
2639{ .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi }, 3236{ .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_nvhdmi },
2640{ .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi }, 3237{ .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_nvhdmi },
2641{ .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi }, 3238{ .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_nvhdmi },
2642{ .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi }, 3239{ .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_nvhdmi },
2643{ .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi }, 3240{ .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_nvhdmi },
2644{ .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi }, 3241{ .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_nvhdmi },
2645{ .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi }, 3242{ .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_nvhdmi },
2646/* 17 is known to be absent */ 3243/* 17 is known to be absent */
2647{ .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi }, 3244{ .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_nvhdmi },
2648{ .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi }, 3245{ .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_nvhdmi },
2649{ .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi }, 3246{ .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_nvhdmi },
2650{ .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi }, 3247{ .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_nvhdmi },
2651{ .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi }, 3248{ .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_nvhdmi },
2652{ .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi }, 3249{ .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_nvhdmi },
2653{ .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi }, 3250{ .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_nvhdmi },
2654{ .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi }, 3251{ .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_nvhdmi },
2655{ .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi }, 3252{ .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_nvhdmi },
2656{ .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi }, 3253{ .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_nvhdmi },
2657{ .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_generic_hdmi }, 3254{ .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_nvhdmi },
2658{ .id = 0x10de0060, .name = "GPU 60 HDMI/DP", .patch = patch_generic_hdmi }, 3255{ .id = 0x10de0060, .name = "GPU 60 HDMI/DP", .patch = patch_nvhdmi },
2659{ .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch }, 3256{ .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
2660{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch }, 3257{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
2661{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, 3258{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
@@ -2671,6 +3268,7 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
2671{ .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi }, 3268{ .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi },
2672{ .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi }, 3269{ .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi },
2673{ .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi }, 3270{ .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi },
3271{ .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi },
2674{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi }, 3272{ .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
2675{} /* terminator */ 3273{} /* terminator */
2676}; 3274};
@@ -2725,6 +3323,7 @@ MODULE_ALIAS("snd-hda-codec-id:80862805");
2725MODULE_ALIAS("snd-hda-codec-id:80862806"); 3323MODULE_ALIAS("snd-hda-codec-id:80862806");
2726MODULE_ALIAS("snd-hda-codec-id:80862807"); 3324MODULE_ALIAS("snd-hda-codec-id:80862807");
2727MODULE_ALIAS("snd-hda-codec-id:80862880"); 3325MODULE_ALIAS("snd-hda-codec-id:80862880");
3326MODULE_ALIAS("snd-hda-codec-id:80862882");
2728MODULE_ALIAS("snd-hda-codec-id:808629fb"); 3327MODULE_ALIAS("snd-hda-codec-id:808629fb");
2729 3328
2730MODULE_LICENSE("GPL"); 3329MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 0e303b99a47c..04d1e6be600e 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -554,8 +554,6 @@ do_sku:
554 nid = portd; 554 nid = portd;
555 else if (tmp == 3) 555 else if (tmp == 3)
556 nid = porti; 556 nid = porti;
557 else
558 return 1;
559 if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins, 557 if (found_in_nid_list(nid, spec->gen.autocfg.line_out_pins,
560 spec->gen.autocfg.line_outs)) 558 spec->gen.autocfg.line_outs))
561 return 1; 559 return 1;
@@ -579,26 +577,35 @@ static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
579/* 577/*
580 * COEF access helper functions 578 * COEF access helper functions
581 */ 579 */
582static int alc_read_coef_idx(struct hda_codec *codec, 580
583 unsigned int coef_idx) 581static int alc_read_coefex_idx(struct hda_codec *codec,
582 hda_nid_t nid,
583 unsigned int coef_idx)
584{ 584{
585 unsigned int val; 585 unsigned int val;
586 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 586 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX,
587 coef_idx); 587 coef_idx);
588 val = snd_hda_codec_read(codec, 0x20, 0, 588 val = snd_hda_codec_read(codec, nid, 0,
589 AC_VERB_GET_PROC_COEF, 0); 589 AC_VERB_GET_PROC_COEF, 0);
590 return val; 590 return val;
591} 591}
592 592
593static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx, 593#define alc_read_coef_idx(codec, coef_idx) \
594 alc_read_coefex_idx(codec, 0x20, coef_idx)
595
596static void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
597 unsigned int coef_idx,
594 unsigned int coef_val) 598 unsigned int coef_val)
595{ 599{
596 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 600 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX,
597 coef_idx); 601 coef_idx);
598 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, 602 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PROC_COEF,
599 coef_val); 603 coef_val);
600} 604}
601 605
606#define alc_write_coef_idx(codec, coef_idx, coef_val) \
607 alc_write_coefex_idx(codec, 0x20, coef_idx, coef_val)
608
602/* a special bypass for COEF 0; read the cached value at the second time */ 609/* a special bypass for COEF 0; read the cached value at the second time */
603static unsigned int alc_get_coef0(struct hda_codec *codec) 610static unsigned int alc_get_coef0(struct hda_codec *codec)
604{ 611{
@@ -831,7 +838,11 @@ static inline void alc_shutup(struct hda_codec *codec)
831 snd_hda_shutup_pins(codec); 838 snd_hda_shutup_pins(codec);
832} 839}
833 840
834#define alc_free snd_hda_gen_free 841static void alc_free(struct hda_codec *codec)
842{
843 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
844 snd_hda_gen_free(codec);
845}
835 846
836#ifdef CONFIG_PM 847#ifdef CONFIG_PM
837static void alc_power_eapd(struct hda_codec *codec) 848static void alc_power_eapd(struct hda_codec *codec)
@@ -1043,6 +1054,7 @@ enum {
1043 ALC880_FIXUP_UNIWILL, 1054 ALC880_FIXUP_UNIWILL,
1044 ALC880_FIXUP_UNIWILL_DIG, 1055 ALC880_FIXUP_UNIWILL_DIG,
1045 ALC880_FIXUP_Z71V, 1056 ALC880_FIXUP_Z71V,
1057 ALC880_FIXUP_ASUS_W5A,
1046 ALC880_FIXUP_3ST_BASE, 1058 ALC880_FIXUP_3ST_BASE,
1047 ALC880_FIXUP_3ST, 1059 ALC880_FIXUP_3ST,
1048 ALC880_FIXUP_3ST_DIG, 1060 ALC880_FIXUP_3ST_DIG,
@@ -1213,6 +1225,26 @@ static const struct hda_fixup alc880_fixups[] = {
1213 { } 1225 { }
1214 } 1226 }
1215 }, 1227 },
1228 [ALC880_FIXUP_ASUS_W5A] = {
1229 .type = HDA_FIXUP_PINS,
1230 .v.pins = (const struct hda_pintbl[]) {
1231 /* set up the whole pins as BIOS is utterly broken */
1232 { 0x14, 0x0121411f }, /* HP */
1233 { 0x15, 0x411111f0 }, /* N/A */
1234 { 0x16, 0x411111f0 }, /* N/A */
1235 { 0x17, 0x411111f0 }, /* N/A */
1236 { 0x18, 0x90a60160 }, /* mic */
1237 { 0x19, 0x411111f0 }, /* N/A */
1238 { 0x1a, 0x411111f0 }, /* N/A */
1239 { 0x1b, 0x411111f0 }, /* N/A */
1240 { 0x1c, 0x411111f0 }, /* N/A */
1241 { 0x1d, 0x411111f0 }, /* N/A */
1242 { 0x1e, 0xb743111e }, /* SPDIF out */
1243 { }
1244 },
1245 .chained = true,
1246 .chain_id = ALC880_FIXUP_GPIO1,
1247 },
1216 [ALC880_FIXUP_3ST_BASE] = { 1248 [ALC880_FIXUP_3ST_BASE] = {
1217 .type = HDA_FIXUP_PINS, 1249 .type = HDA_FIXUP_PINS,
1218 .v.pins = (const struct hda_pintbl[]) { 1250 .v.pins = (const struct hda_pintbl[]) {
@@ -1334,6 +1366,7 @@ static const struct hda_fixup alc880_fixups[] = {
1334 1366
1335static const struct snd_pci_quirk alc880_fixup_tbl[] = { 1367static const struct snd_pci_quirk alc880_fixup_tbl[] = {
1336 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810), 1368 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
1369 SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS W5A", ALC880_FIXUP_ASUS_W5A),
1337 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V), 1370 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
1338 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1), 1371 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
1339 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2), 1372 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
@@ -2388,6 +2421,7 @@ static const struct hda_verb alc268_beep_init_verbs[] = {
2388enum { 2421enum {
2389 ALC268_FIXUP_INV_DMIC, 2422 ALC268_FIXUP_INV_DMIC,
2390 ALC268_FIXUP_HP_EAPD, 2423 ALC268_FIXUP_HP_EAPD,
2424 ALC268_FIXUP_SPDIF,
2391}; 2425};
2392 2426
2393static const struct hda_fixup alc268_fixups[] = { 2427static const struct hda_fixup alc268_fixups[] = {
@@ -2402,6 +2436,13 @@ static const struct hda_fixup alc268_fixups[] = {
2402 {} 2436 {}
2403 } 2437 }
2404 }, 2438 },
2439 [ALC268_FIXUP_SPDIF] = {
2440 .type = HDA_FIXUP_PINS,
2441 .v.pins = (const struct hda_pintbl[]) {
2442 { 0x1e, 0x014b1180 }, /* enable SPDIF out */
2443 {}
2444 }
2445 },
2405}; 2446};
2406 2447
2407static const struct hda_model_fixup alc268_fixup_models[] = { 2448static const struct hda_model_fixup alc268_fixup_models[] = {
@@ -2411,6 +2452,7 @@ static const struct hda_model_fixup alc268_fixup_models[] = {
2411}; 2452};
2412 2453
2413static const struct snd_pci_quirk alc268_fixup_tbl[] = { 2454static const struct snd_pci_quirk alc268_fixup_tbl[] = {
2455 SND_PCI_QUIRK(0x1025, 0x0139, "Acer TravelMate 6293", ALC268_FIXUP_SPDIF),
2414 SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC), 2456 SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC),
2415 /* below is codec SSID since multiple Toshiba laptops have the 2457 /* below is codec SSID since multiple Toshiba laptops have the
2416 * same PCI SSID 1179:ff00 2458 * same PCI SSID 1179:ff00
@@ -2539,7 +2581,9 @@ enum {
2539 ALC269_TYPE_ALC282, 2581 ALC269_TYPE_ALC282,
2540 ALC269_TYPE_ALC283, 2582 ALC269_TYPE_ALC283,
2541 ALC269_TYPE_ALC284, 2583 ALC269_TYPE_ALC284,
2584 ALC269_TYPE_ALC285,
2542 ALC269_TYPE_ALC286, 2585 ALC269_TYPE_ALC286,
2586 ALC269_TYPE_ALC255,
2543}; 2587};
2544 2588
2545/* 2589/*
@@ -2558,6 +2602,7 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
2558 case ALC269_TYPE_ALC269VC: 2602 case ALC269_TYPE_ALC269VC:
2559 case ALC269_TYPE_ALC280: 2603 case ALC269_TYPE_ALC280:
2560 case ALC269_TYPE_ALC284: 2604 case ALC269_TYPE_ALC284:
2605 case ALC269_TYPE_ALC285:
2561 ssids = alc269va_ssids; 2606 ssids = alc269va_ssids;
2562 break; 2607 break;
2563 case ALC269_TYPE_ALC269VB: 2608 case ALC269_TYPE_ALC269VB:
@@ -2565,6 +2610,7 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
2565 case ALC269_TYPE_ALC282: 2610 case ALC269_TYPE_ALC282:
2566 case ALC269_TYPE_ALC283: 2611 case ALC269_TYPE_ALC283:
2567 case ALC269_TYPE_ALC286: 2612 case ALC269_TYPE_ALC286:
2613 case ALC269_TYPE_ALC255:
2568 ssids = alc269_ssids; 2614 ssids = alc269_ssids;
2569 break; 2615 break;
2570 default: 2616 default:
@@ -2652,7 +2698,7 @@ static void alc283_shutup(struct hda_codec *codec)
2652 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); 2698 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2653 2699
2654 if (hp_pin_sense) 2700 if (hp_pin_sense)
2655 msleep(85); 2701 msleep(100);
2656 2702
2657 snd_hda_codec_write(codec, hp_pin, 0, 2703 snd_hda_codec_write(codec, hp_pin, 0,
2658 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0); 2704 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
@@ -2661,7 +2707,7 @@ static void alc283_shutup(struct hda_codec *codec)
2661 alc_write_coef_idx(codec, 0x46, val | (3 << 12)); 2707 alc_write_coef_idx(codec, 0x46, val | (3 << 12));
2662 2708
2663 if (hp_pin_sense) 2709 if (hp_pin_sense)
2664 msleep(85); 2710 msleep(100);
2665 snd_hda_shutup_pins(codec); 2711 snd_hda_shutup_pins(codec);
2666 alc_write_coef_idx(codec, 0x43, 0x9614); 2712 alc_write_coef_idx(codec, 0x43, 0x9614);
2667} 2713}
@@ -2819,6 +2865,15 @@ static void alc269_fixup_hweq(struct hda_codec *codec,
2819 alc_write_coef_idx(codec, 0x1e, coef | 0x80); 2865 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
2820} 2866}
2821 2867
2868static void alc269_fixup_headset_mic(struct hda_codec *codec,
2869 const struct hda_fixup *fix, int action)
2870{
2871 struct alc_spec *spec = codec->spec;
2872
2873 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2874 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
2875}
2876
2822static void alc271_fixup_dmic(struct hda_codec *codec, 2877static void alc271_fixup_dmic(struct hda_codec *codec,
2823 const struct hda_fixup *fix, int action) 2878 const struct hda_fixup *fix, int action)
2824{ 2879{
@@ -2935,6 +2990,23 @@ static void alc269_fixup_mic_mute_hook(void *private_data, int enabled)
2935 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval); 2990 snd_hda_set_pin_ctl_cache(codec, spec->mute_led_nid, pinval);
2936} 2991}
2937 2992
2993/* Make sure the led works even in runtime suspend */
2994static unsigned int led_power_filter(struct hda_codec *codec,
2995 hda_nid_t nid,
2996 unsigned int power_state)
2997{
2998 struct alc_spec *spec = codec->spec;
2999
3000 if (power_state != AC_PWRST_D3 || nid != spec->mute_led_nid)
3001 return power_state;
3002
3003 /* Set pin ctl again, it might have just been set to 0 */
3004 snd_hda_set_pin_ctl(codec, nid,
3005 snd_hda_codec_get_pin_target(codec, nid));
3006
3007 return AC_PWRST_D0;
3008}
3009
2938static void alc269_fixup_hp_mute_led(struct hda_codec *codec, 3010static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
2939 const struct hda_fixup *fix, int action) 3011 const struct hda_fixup *fix, int action)
2940{ 3012{
@@ -2954,6 +3026,7 @@ static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
2954 spec->mute_led_nid = pin - 0x0a + 0x18; 3026 spec->mute_led_nid = pin - 0x0a + 0x18;
2955 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook; 3027 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2956 spec->gen.vmaster_mute_enum = 1; 3028 spec->gen.vmaster_mute_enum = 1;
3029 codec->power_filter = led_power_filter;
2957 snd_printd("Detected mute LED for %x:%d\n", spec->mute_led_nid, 3030 snd_printd("Detected mute LED for %x:%d\n", spec->mute_led_nid,
2958 spec->mute_led_polarity); 3031 spec->mute_led_polarity);
2959 break; 3032 break;
@@ -2969,6 +3042,7 @@ static void alc269_fixup_hp_mute_led_mic1(struct hda_codec *codec,
2969 spec->mute_led_nid = 0x18; 3042 spec->mute_led_nid = 0x18;
2970 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook; 3043 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2971 spec->gen.vmaster_mute_enum = 1; 3044 spec->gen.vmaster_mute_enum = 1;
3045 codec->power_filter = led_power_filter;
2972 } 3046 }
2973} 3047}
2974 3048
@@ -2981,6 +3055,7 @@ static void alc269_fixup_hp_mute_led_mic2(struct hda_codec *codec,
2981 spec->mute_led_nid = 0x19; 3055 spec->mute_led_nid = 0x19;
2982 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook; 3056 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
2983 spec->gen.vmaster_mute_enum = 1; 3057 spec->gen.vmaster_mute_enum = 1;
3058 codec->power_filter = led_power_filter;
2984 } 3059 }
2985} 3060}
2986 3061
@@ -3043,6 +3118,19 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec)
3043 int val; 3118 int val;
3044 3119
3045 switch (codec->vendor_id) { 3120 switch (codec->vendor_id) {
3121 case 0x10ec0255:
3122 /* LDO and MISC control */
3123 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3124 /* UAJ function set to menual mode */
3125 alc_write_coef_idx(codec, 0x45, 0xd089);
3126 /* Direct Drive HP Amp control(Set to verb control)*/
3127 val = alc_read_coefex_idx(codec, 0x57, 0x05);
3128 alc_write_coefex_idx(codec, 0x57, 0x05, val & ~(1<<14));
3129 /* Set MIC2 Vref gate with HP */
3130 alc_write_coef_idx(codec, 0x06, 0x6104);
3131 /* Direct Drive HP Amp control */
3132 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8aa6);
3133 break;
3046 case 0x10ec0283: 3134 case 0x10ec0283:
3047 alc_write_coef_idx(codec, 0x1b, 0x0c0b); 3135 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3048 alc_write_coef_idx(codec, 0x45, 0xc429); 3136 alc_write_coef_idx(codec, 0x45, 0xc429);
@@ -3074,6 +3162,14 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3074 int val; 3162 int val;
3075 3163
3076 switch (codec->vendor_id) { 3164 switch (codec->vendor_id) {
3165 case 0x10ec0255:
3166 alc_write_coef_idx(codec, 0x45, 0xc489);
3167 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3168 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8aa6);
3169 /* Set MIC2 Vref gate to normal */
3170 alc_write_coef_idx(codec, 0x06, 0x6100);
3171 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3172 break;
3077 case 0x10ec0283: 3173 case 0x10ec0283:
3078 alc_write_coef_idx(codec, 0x45, 0xc429); 3174 alc_write_coef_idx(codec, 0x45, 0xc429);
3079 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); 3175 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
@@ -3105,6 +3201,12 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3105static void alc_headset_mode_default(struct hda_codec *codec) 3201static void alc_headset_mode_default(struct hda_codec *codec)
3106{ 3202{
3107 switch (codec->vendor_id) { 3203 switch (codec->vendor_id) {
3204 case 0x10ec0255:
3205 alc_write_coef_idx(codec, 0x45, 0xc089);
3206 alc_write_coef_idx(codec, 0x45, 0xc489);
3207 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8ea6);
3208 alc_write_coef_idx(codec, 0x49, 0x0049);
3209 break;
3108 case 0x10ec0283: 3210 case 0x10ec0283:
3109 alc_write_coef_idx(codec, 0x06, 0x2100); 3211 alc_write_coef_idx(codec, 0x06, 0x2100);
3110 alc_write_coef_idx(codec, 0x32, 0x4ea3); 3212 alc_write_coef_idx(codec, 0x32, 0x4ea3);
@@ -3128,6 +3230,12 @@ static void alc_headset_mode_default(struct hda_codec *codec)
3128static void alc_headset_mode_ctia(struct hda_codec *codec) 3230static void alc_headset_mode_ctia(struct hda_codec *codec)
3129{ 3231{
3130 switch (codec->vendor_id) { 3232 switch (codec->vendor_id) {
3233 case 0x10ec0255:
3234 /* Set to CTIA type */
3235 alc_write_coef_idx(codec, 0x45, 0xd489);
3236 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3237 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8ea6);
3238 break;
3131 case 0x10ec0283: 3239 case 0x10ec0283:
3132 alc_write_coef_idx(codec, 0x45, 0xd429); 3240 alc_write_coef_idx(codec, 0x45, 0xd429);
3133 alc_write_coef_idx(codec, 0x1b, 0x0c2b); 3241 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
@@ -3150,6 +3258,12 @@ static void alc_headset_mode_ctia(struct hda_codec *codec)
3150static void alc_headset_mode_omtp(struct hda_codec *codec) 3258static void alc_headset_mode_omtp(struct hda_codec *codec)
3151{ 3259{
3152 switch (codec->vendor_id) { 3260 switch (codec->vendor_id) {
3261 case 0x10ec0255:
3262 /* Set to OMTP Type */
3263 alc_write_coef_idx(codec, 0x45, 0xe489);
3264 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
3265 alc_write_coefex_idx(codec, 0x57, 0x03, 0x8ea6);
3266 break;
3153 case 0x10ec0283: 3267 case 0x10ec0283:
3154 alc_write_coef_idx(codec, 0x45, 0xe429); 3268 alc_write_coef_idx(codec, 0x45, 0xe429);
3155 alc_write_coef_idx(codec, 0x1b, 0x0c2b); 3269 alc_write_coef_idx(codec, 0x1b, 0x0c2b);
@@ -3175,6 +3289,15 @@ static void alc_determine_headset_type(struct hda_codec *codec)
3175 struct alc_spec *spec = codec->spec; 3289 struct alc_spec *spec = codec->spec;
3176 3290
3177 switch (codec->vendor_id) { 3291 switch (codec->vendor_id) {
3292 case 0x10ec0255:
3293 /* combo jack auto switch control(Check type)*/
3294 alc_write_coef_idx(codec, 0x45, 0xd089);
3295 /* combo jack auto switch control(Vref conteol) */
3296 alc_write_coef_idx(codec, 0x49, 0x0149);
3297 msleep(300);
3298 val = alc_read_coef_idx(codec, 0x46);
3299 is_ctia = (val & 0x0070) == 0x0070;
3300 break;
3178 case 0x10ec0283: 3301 case 0x10ec0283:
3179 alc_write_coef_idx(codec, 0x45, 0xd029); 3302 alc_write_coef_idx(codec, 0x45, 0xd029);
3180 msleep(300); 3303 msleep(300);
@@ -3221,8 +3344,10 @@ static void alc_update_headset_mode(struct hda_codec *codec)
3221 else 3344 else
3222 new_headset_mode = ALC_HEADSET_MODE_HEADPHONE; 3345 new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;
3223 3346
3224 if (new_headset_mode == spec->current_headset_mode) 3347 if (new_headset_mode == spec->current_headset_mode) {
3348 snd_hda_gen_update_outputs(codec);
3225 return; 3349 return;
3350 }
3226 3351
3227 switch (new_headset_mode) { 3352 switch (new_headset_mode) {
3228 case ALC_HEADSET_MODE_UNPLUGGED: 3353 case ALC_HEADSET_MODE_UNPLUGGED:
@@ -3321,6 +3446,21 @@ static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec,
3321 alc_fixup_headset_mode(codec, fix, action); 3446 alc_fixup_headset_mode(codec, fix, action);
3322} 3447}
3323 3448
3449static void alc_fixup_headset_mode_alc255(struct hda_codec *codec,
3450 const struct hda_fixup *fix, int action)
3451{
3452 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3453 /* Set to iphone type */
3454 alc_write_coef_idx(codec, 0x1b, 0x880b);
3455 alc_write_coef_idx(codec, 0x45, 0xd089);
3456 alc_write_coef_idx(codec, 0x1b, 0x080b);
3457 alc_write_coef_idx(codec, 0x46, 0x0004);
3458 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3459 msleep(30);
3460 }
3461 alc_fixup_headset_mode(codec, fix, action);
3462}
3463
3324static void alc_fixup_headset_mode_alc668(struct hda_codec *codec, 3464static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
3325 const struct hda_fixup *fix, int action) 3465 const struct hda_fixup *fix, int action)
3326{ 3466{
@@ -3434,7 +3574,11 @@ static void alc283_fixup_chromebook(struct hda_codec *codec,
3434 switch (action) { 3574 switch (action) {
3435 case HDA_FIXUP_ACT_PRE_PROBE: 3575 case HDA_FIXUP_ACT_PRE_PROBE:
3436 alc283_chromebook_caps(codec); 3576 alc283_chromebook_caps(codec);
3577 /* Disable AA-loopback as it causes white noise */
3578 spec->gen.mixer_nid = 0;
3437 spec->gen.hp_automute_hook = alc283_hp_automute_hook; 3579 spec->gen.hp_automute_hook = alc283_hp_automute_hook;
3580 break;
3581 case HDA_FIXUP_ACT_INIT:
3438 /* MIC2-VREF control */ 3582 /* MIC2-VREF control */
3439 /* Set to manual mode */ 3583 /* Set to manual mode */
3440 val = alc_read_coef_idx(codec, 0x06); 3584 val = alc_read_coef_idx(codec, 0x06);
@@ -3496,6 +3640,83 @@ static void alc282_fixup_asus_tx300(struct hda_codec *codec,
3496 } 3640 }
3497} 3641}
3498 3642
3643static void alc290_fixup_mono_speakers(struct hda_codec *codec,
3644 const struct hda_fixup *fix, int action)
3645{
3646 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3647 /* Remove DAC node 0x03, as it seems to be
3648 giving mono output */
3649 snd_hda_override_wcaps(codec, 0x03, 0);
3650}
3651
3652#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
3653
3654#include <linux/thinkpad_acpi.h>
3655
3656static int (*led_set_func)(int, bool);
3657
3658static void update_tpacpi_mute_led(void *private_data, int enabled)
3659{
3660 if (led_set_func)
3661 led_set_func(TPACPI_LED_MUTE, !enabled);
3662}
3663
3664static void update_tpacpi_micmute_led(struct hda_codec *codec,
3665 struct snd_ctl_elem_value *ucontrol)
3666{
3667 if (!ucontrol || !led_set_func)
3668 return;
3669 if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
3670 /* TODO: How do I verify if it's a mono or stereo here? */
3671 bool val = ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1];
3672 led_set_func(TPACPI_LED_MICMUTE, !val);
3673 }
3674}
3675
3676static void alc_fixup_thinkpad_acpi(struct hda_codec *codec,
3677 const struct hda_fixup *fix, int action)
3678{
3679 struct alc_spec *spec = codec->spec;
3680 bool removefunc = false;
3681
3682 if (action == HDA_FIXUP_ACT_PROBE) {
3683 if (!led_set_func)
3684 led_set_func = symbol_request(tpacpi_led_set);
3685 if (!led_set_func) {
3686 snd_printk(KERN_WARNING "Failed to find thinkpad-acpi symbol tpacpi_led_set\n");
3687 return;
3688 }
3689
3690 removefunc = true;
3691 if (led_set_func(TPACPI_LED_MUTE, false) >= 0) {
3692 spec->gen.vmaster_mute.hook = update_tpacpi_mute_led;
3693 removefunc = false;
3694 }
3695 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) {
3696 if (spec->gen.num_adc_nids > 1)
3697 snd_printdd("Skipping micmute LED control due to several ADCs");
3698 else {
3699 spec->gen.cap_sync_hook = update_tpacpi_micmute_led;
3700 removefunc = false;
3701 }
3702 }
3703 }
3704
3705 if (led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
3706 symbol_put(tpacpi_led_set);
3707 led_set_func = NULL;
3708 }
3709}
3710
3711#else
3712
3713static void alc_fixup_thinkpad_acpi(struct hda_codec *codec,
3714 const struct hda_fixup *fix, int action)
3715{
3716}
3717
3718#endif
3719
3499enum { 3720enum {
3500 ALC269_FIXUP_SONY_VAIO, 3721 ALC269_FIXUP_SONY_VAIO,
3501 ALC275_FIXUP_SONY_VAIO_GPIO2, 3722 ALC275_FIXUP_SONY_VAIO_GPIO2,
@@ -3507,6 +3728,7 @@ enum {
3507 ALC271_FIXUP_DMIC, 3728 ALC271_FIXUP_DMIC,
3508 ALC269_FIXUP_PCM_44K, 3729 ALC269_FIXUP_PCM_44K,
3509 ALC269_FIXUP_STEREO_DMIC, 3730 ALC269_FIXUP_STEREO_DMIC,
3731 ALC269_FIXUP_HEADSET_MIC,
3510 ALC269_FIXUP_QUANTA_MUTE, 3732 ALC269_FIXUP_QUANTA_MUTE,
3511 ALC269_FIXUP_LIFEBOOK, 3733 ALC269_FIXUP_LIFEBOOK,
3512 ALC269_FIXUP_AMIC, 3734 ALC269_FIXUP_AMIC,
@@ -3519,9 +3741,11 @@ enum {
3519 ALC269_FIXUP_HP_GPIO_LED, 3741 ALC269_FIXUP_HP_GPIO_LED,
3520 ALC269_FIXUP_INV_DMIC, 3742 ALC269_FIXUP_INV_DMIC,
3521 ALC269_FIXUP_LENOVO_DOCK, 3743 ALC269_FIXUP_LENOVO_DOCK,
3744 ALC286_FIXUP_SONY_MIC_NO_PRESENCE,
3522 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT, 3745 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
3523 ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, 3746 ALC269_FIXUP_DELL1_MIC_NO_PRESENCE,
3524 ALC269_FIXUP_DELL2_MIC_NO_PRESENCE, 3747 ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
3748 ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
3525 ALC269_FIXUP_HEADSET_MODE, 3749 ALC269_FIXUP_HEADSET_MODE,
3526 ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC, 3750 ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC,
3527 ALC269_FIXUP_ASUS_X101_FUNC, 3751 ALC269_FIXUP_ASUS_X101_FUNC,
@@ -3531,10 +3755,15 @@ enum {
3531 ALC271_FIXUP_HP_GATE_MIC_JACK, 3755 ALC271_FIXUP_HP_GATE_MIC_JACK,
3532 ALC269_FIXUP_ACER_AC700, 3756 ALC269_FIXUP_ACER_AC700,
3533 ALC269_FIXUP_LIMIT_INT_MIC_BOOST, 3757 ALC269_FIXUP_LIMIT_INT_MIC_BOOST,
3758 ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED,
3534 ALC269VB_FIXUP_ORDISSIMO_EVE2, 3759 ALC269VB_FIXUP_ORDISSIMO_EVE2,
3535 ALC283_FIXUP_CHROME_BOOK, 3760 ALC283_FIXUP_CHROME_BOOK,
3536 ALC282_FIXUP_ASUS_TX300, 3761 ALC282_FIXUP_ASUS_TX300,
3537 ALC283_FIXUP_INT_MIC, 3762 ALC283_FIXUP_INT_MIC,
3763 ALC290_FIXUP_MONO_SPEAKERS,
3764 ALC269_FIXUP_THINKPAD_ACPI,
3765 ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
3766 ALC255_FIXUP_HEADSET_MODE,
3538}; 3767};
3539 3768
3540static const struct hda_fixup alc269_fixups[] = { 3769static const struct hda_fixup alc269_fixups[] = {
@@ -3603,6 +3832,10 @@ static const struct hda_fixup alc269_fixups[] = {
3603 .type = HDA_FIXUP_FUNC, 3832 .type = HDA_FIXUP_FUNC,
3604 .v.func = alc269_fixup_stereo_dmic, 3833 .v.func = alc269_fixup_stereo_dmic,
3605 }, 3834 },
3835 [ALC269_FIXUP_HEADSET_MIC] = {
3836 .type = HDA_FIXUP_FUNC,
3837 .v.func = alc269_fixup_headset_mic,
3838 },
3606 [ALC269_FIXUP_QUANTA_MUTE] = { 3839 [ALC269_FIXUP_QUANTA_MUTE] = {
3607 .type = HDA_FIXUP_FUNC, 3840 .type = HDA_FIXUP_FUNC,
3608 .v.func = alc269_fixup_quanta_mute, 3841 .v.func = alc269_fixup_quanta_mute,
@@ -3712,6 +3945,15 @@ static const struct hda_fixup alc269_fixups[] = {
3712 .chained = true, 3945 .chained = true,
3713 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC 3946 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
3714 }, 3947 },
3948 [ALC269_FIXUP_DELL3_MIC_NO_PRESENCE] = {
3949 .type = HDA_FIXUP_PINS,
3950 .v.pins = (const struct hda_pintbl[]) {
3951 { 0x1a, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3952 { }
3953 },
3954 .chained = true,
3955 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
3956 },
3715 [ALC269_FIXUP_HEADSET_MODE] = { 3957 [ALC269_FIXUP_HEADSET_MODE] = {
3716 .type = HDA_FIXUP_FUNC, 3958 .type = HDA_FIXUP_FUNC,
3717 .v.func = alc_fixup_headset_mode, 3959 .v.func = alc_fixup_headset_mode,
@@ -3720,6 +3962,15 @@ static const struct hda_fixup alc269_fixups[] = {
3720 .type = HDA_FIXUP_FUNC, 3962 .type = HDA_FIXUP_FUNC,
3721 .v.func = alc_fixup_headset_mode_no_hp_mic, 3963 .v.func = alc_fixup_headset_mode_no_hp_mic,
3722 }, 3964 },
3965 [ALC286_FIXUP_SONY_MIC_NO_PRESENCE] = {
3966 .type = HDA_FIXUP_PINS,
3967 .v.pins = (const struct hda_pintbl[]) {
3968 { 0x18, 0x01a1913c }, /* use as headset mic, without its own jack detect */
3969 { }
3970 },
3971 .chained = true,
3972 .chain_id = ALC269_FIXUP_HEADSET_MIC
3973 },
3723 [ALC269_FIXUP_ASUS_X101_FUNC] = { 3974 [ALC269_FIXUP_ASUS_X101_FUNC] = {
3724 .type = HDA_FIXUP_FUNC, 3975 .type = HDA_FIXUP_FUNC,
3725 .v.func = alc269_fixup_x101_headset_mic, 3976 .v.func = alc269_fixup_x101_headset_mic,
@@ -3777,6 +4028,12 @@ static const struct hda_fixup alc269_fixups[] = {
3777 .type = HDA_FIXUP_FUNC, 4028 .type = HDA_FIXUP_FUNC,
3778 .v.func = alc269_fixup_limit_int_mic_boost, 4029 .v.func = alc269_fixup_limit_int_mic_boost,
3779 }, 4030 },
4031 [ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED] = {
4032 .type = HDA_FIXUP_FUNC,
4033 .v.func = alc269_fixup_limit_int_mic_boost,
4034 .chained = true,
4035 .chain_id = ALC269_FIXUP_HP_MUTE_LED_MIC1,
4036 },
3780 [ALC269VB_FIXUP_ORDISSIMO_EVE2] = { 4037 [ALC269VB_FIXUP_ORDISSIMO_EVE2] = {
3781 .type = HDA_FIXUP_PINS, 4038 .type = HDA_FIXUP_PINS,
3782 .v.pins = (const struct hda_pintbl[]) { 4039 .v.pins = (const struct hda_pintbl[]) {
@@ -3804,6 +4061,32 @@ static const struct hda_fixup alc269_fixups[] = {
3804 .chained = true, 4061 .chained = true,
3805 .chain_id = ALC269_FIXUP_LIMIT_INT_MIC_BOOST 4062 .chain_id = ALC269_FIXUP_LIMIT_INT_MIC_BOOST
3806 }, 4063 },
4064 [ALC290_FIXUP_MONO_SPEAKERS] = {
4065 .type = HDA_FIXUP_FUNC,
4066 .v.func = alc290_fixup_mono_speakers,
4067 .chained = true,
4068 .chain_id = ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
4069 },
4070 [ALC269_FIXUP_THINKPAD_ACPI] = {
4071 .type = HDA_FIXUP_FUNC,
4072 .v.func = alc_fixup_thinkpad_acpi,
4073 .chained = true,
4074 .chain_id = ALC269_FIXUP_LIMIT_INT_MIC_BOOST
4075 },
4076 [ALC255_FIXUP_DELL1_MIC_NO_PRESENCE] = {
4077 .type = HDA_FIXUP_PINS,
4078 .v.pins = (const struct hda_pintbl[]) {
4079 { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4080 { 0x1a, 0x01a1913d }, /* use as headphone mic, without its own jack detect */
4081 { }
4082 },
4083 .chained = true,
4084 .chain_id = ALC255_FIXUP_HEADSET_MODE
4085 },
4086 [ALC255_FIXUP_HEADSET_MODE] = {
4087 .type = HDA_FIXUP_FUNC,
4088 .v.func = alc_fixup_headset_mode_alc255,
4089 },
3807}; 4090};
3808 4091
3809static const struct snd_pci_quirk alc269_fixup_tbl[] = { 4092static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -3845,12 +4128,16 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3845 SND_PCI_QUIRK(0x1028, 0x0608, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4128 SND_PCI_QUIRK(0x1028, 0x0608, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3846 SND_PCI_QUIRK(0x1028, 0x0609, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4129 SND_PCI_QUIRK(0x1028, 0x0609, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
3847 SND_PCI_QUIRK(0x1028, 0x0613, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4130 SND_PCI_QUIRK(0x1028, 0x0613, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4131 SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_MONO_SPEAKERS),
4132 SND_PCI_QUIRK(0x1028, 0x061f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4133 SND_PCI_QUIRK(0x1028, 0x063f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
3848 SND_PCI_QUIRK(0x1028, 0x15cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE), 4134 SND_PCI_QUIRK(0x1028, 0x15cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3849 SND_PCI_QUIRK(0x1028, 0x15cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE), 4135 SND_PCI_QUIRK(0x1028, 0x15cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
3850 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2), 4136 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
3851 SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED), 4137 SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED),
3852 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4138 SND_PCI_QUIRK(0x103c, 0x1973, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
3853 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4139 SND_PCI_QUIRK(0x103c, 0x1983, "HP Pavilion", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4140 SND_PCI_QUIRK(0x103c, 0x218b, "HP", ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED),
3854 SND_PCI_QUIRK(0x103c, 0x21ed, "HP Falco Chromebook", ALC283_FIXUP_CHROME_BOOK), 4141 SND_PCI_QUIRK(0x103c, 0x21ed, "HP Falco Chromebook", ALC283_FIXUP_CHROME_BOOK),
3855 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED), 4142 SND_PCI_QUIRK_VENDOR(0x103c, "HP", ALC269_FIXUP_HP_MUTE_LED),
3856 SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300), 4143 SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
@@ -3867,6 +4154,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3867 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), 4154 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
3868 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC), 4155 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
3869 SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101), 4156 SND_PCI_QUIRK(0x1043, 0x8516, "ASUS X101CH", ALC269_FIXUP_ASUS_X101),
4157 SND_PCI_QUIRK(0x104d, 0x90b6, "Sony VAIO Pro 13", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
3870 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), 4158 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
3871 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), 4159 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
3872 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), 4160 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
@@ -3885,7 +4173,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3885 SND_PCI_QUIRK(0x17aa, 0x2208, "Thinkpad T431s", ALC269_FIXUP_LENOVO_DOCK), 4173 SND_PCI_QUIRK(0x17aa, 0x2208, "Thinkpad T431s", ALC269_FIXUP_LENOVO_DOCK),
3886 SND_PCI_QUIRK(0x17aa, 0x220c, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4174 SND_PCI_QUIRK(0x17aa, 0x220c, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3887 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4175 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3888 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4176 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad", ALC269_FIXUP_THINKPAD_ACPI),
3889 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4177 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3890 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4178 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3891 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC), 4179 SND_PCI_QUIRK(0x17aa, 0x501a, "Thinkpad", ALC283_FIXUP_INT_MIC),
@@ -3952,6 +4240,7 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
3952 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"}, 4240 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
3953 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"}, 4241 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
3954 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"}, 4242 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
4243 {.id = ALC269_FIXUP_HEADSET_MIC, .name = "headset-mic"},
3955 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"}, 4244 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
3956 {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"}, 4245 {.id = ALC269_FIXUP_HP_GPIO_LED, .name = "hp-gpio-led"},
3957 {.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"}, 4246 {.id = ALC269_FIXUP_DELL1_MIC_NO_PRESENCE, .name = "dell-headset-multi"},
@@ -4072,9 +4361,16 @@ static int patch_alc269(struct hda_codec *codec)
4072 case 0x10ec0292: 4361 case 0x10ec0292:
4073 spec->codec_variant = ALC269_TYPE_ALC284; 4362 spec->codec_variant = ALC269_TYPE_ALC284;
4074 break; 4363 break;
4364 case 0x10ec0285:
4365 case 0x10ec0293:
4366 spec->codec_variant = ALC269_TYPE_ALC285;
4367 break;
4075 case 0x10ec0286: 4368 case 0x10ec0286:
4076 spec->codec_variant = ALC269_TYPE_ALC286; 4369 spec->codec_variant = ALC269_TYPE_ALC286;
4077 break; 4370 break;
4371 case 0x10ec0255:
4372 spec->codec_variant = ALC269_TYPE_ALC255;
4373 break;
4078 } 4374 }
4079 4375
4080 if (snd_hda_codec_read(codec, 0x51, 0, AC_VERB_PARAMETERS, 0) == 0x10ec5505) { 4376 if (snd_hda_codec_read(codec, 0x51, 0, AC_VERB_PARAMETERS, 0) == 0x10ec5505) {
@@ -4362,6 +4658,25 @@ static void alc272_fixup_mario(struct hda_codec *codec,
4362 "hda_codec: failed to override amp caps for NID 0x2\n"); 4658 "hda_codec: failed to override amp caps for NID 0x2\n");
4363} 4659}
4364 4660
4661static const struct snd_pcm_chmap_elem asus_pcm_2_1_chmaps[] = {
4662 { .channels = 2,
4663 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
4664 { .channels = 4,
4665 .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
4666 SNDRV_CHMAP_NA, SNDRV_CHMAP_LFE } }, /* LFE only on right */
4667 { }
4668};
4669
4670/* override the 2.1 chmap */
4671static void alc662_fixup_bass_chmap(struct hda_codec *codec,
4672 const struct hda_fixup *fix, int action)
4673{
4674 if (action == HDA_FIXUP_ACT_BUILD) {
4675 struct alc_spec *spec = codec->spec;
4676 spec->gen.pcm_rec[0].stream[0].chmap = asus_pcm_2_1_chmaps;
4677 }
4678}
4679
4365enum { 4680enum {
4366 ALC662_FIXUP_ASPIRE, 4681 ALC662_FIXUP_ASPIRE,
4367 ALC662_FIXUP_IDEAPAD, 4682 ALC662_FIXUP_IDEAPAD,
@@ -4382,6 +4697,7 @@ enum {
4382 ALC662_FIXUP_INV_DMIC, 4697 ALC662_FIXUP_INV_DMIC,
4383 ALC668_FIXUP_DELL_MIC_NO_PRESENCE, 4698 ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
4384 ALC668_FIXUP_HEADSET_MODE, 4699 ALC668_FIXUP_HEADSET_MODE,
4700 ALC662_FIXUP_BASS_CHMAP,
4385}; 4701};
4386 4702
4387static const struct hda_fixup alc662_fixups[] = { 4703static const struct hda_fixup alc662_fixups[] = {
@@ -4556,6 +4872,12 @@ static const struct hda_fixup alc662_fixups[] = {
4556 .type = HDA_FIXUP_FUNC, 4872 .type = HDA_FIXUP_FUNC,
4557 .v.func = alc_fixup_headset_mode_alc668, 4873 .v.func = alc_fixup_headset_mode_alc668,
4558 }, 4874 },
4875 [ALC662_FIXUP_BASS_CHMAP] = {
4876 .type = HDA_FIXUP_FUNC,
4877 .v.func = alc662_fixup_bass_chmap,
4878 .chained = true,
4879 .chain_id = ALC662_FIXUP_ASUS_MODE4
4880 },
4559}; 4881};
4560 4882
4561static const struct snd_pci_quirk alc662_fixup_tbl[] = { 4883static const struct snd_pci_quirk alc662_fixup_tbl[] = {
@@ -4568,7 +4890,10 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
4568 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), 4890 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
4569 SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 4891 SND_PCI_QUIRK(0x1028, 0x05d8, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4570 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 4892 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4893 SND_PCI_QUIRK(0x1028, 0x0626, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4571 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), 4894 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
4895 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_CHMAP),
4896 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_BASS_CHMAP),
4572 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), 4897 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
4573 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), 4898 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
4574 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), 4899 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
@@ -4787,6 +5112,7 @@ static int patch_alc680(struct hda_codec *codec)
4787static const struct hda_codec_preset snd_hda_preset_realtek[] = { 5112static const struct hda_codec_preset snd_hda_preset_realtek[] = {
4788 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 }, 5113 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
4789 { .id = 0x10ec0233, .name = "ALC233", .patch = patch_alc269 }, 5114 { .id = 0x10ec0233, .name = "ALC233", .patch = patch_alc269 },
5115 { .id = 0x10ec0255, .name = "ALC255", .patch = patch_alc269 },
4790 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 }, 5116 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
4791 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 }, 5117 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
4792 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, 5118 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
@@ -4800,9 +5126,11 @@ static const struct hda_codec_preset snd_hda_preset_realtek[] = {
4800 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 }, 5126 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
4801 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 }, 5127 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
4802 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 }, 5128 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
5129 { .id = 0x10ec0285, .name = "ALC285", .patch = patch_alc269 },
4803 { .id = 0x10ec0286, .name = "ALC286", .patch = patch_alc269 }, 5130 { .id = 0x10ec0286, .name = "ALC286", .patch = patch_alc269 },
4804 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 }, 5131 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
4805 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 }, 5132 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
5133 { .id = 0x10ec0293, .name = "ALC293", .patch = patch_alc269 },
4806 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", 5134 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
4807 .patch = patch_alc861 }, 5135 .patch = patch_alc861 },
4808 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, 5136 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index fba0cef1c47f..d2cc0041d9d3 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -100,6 +100,7 @@ enum {
100 STAC_92HD83XXX_HEADSET_JACK, 100 STAC_92HD83XXX_HEADSET_JACK,
101 STAC_92HD83XXX_HP, 101 STAC_92HD83XXX_HP,
102 STAC_HP_ENVY_BASS, 102 STAC_HP_ENVY_BASS,
103 STAC_HP_BNB13_EQ,
103 STAC_92HD83XXX_MODELS 104 STAC_92HD83XXX_MODELS
104}; 105};
105 106
@@ -2091,8 +2092,10 @@ static void stac92hd83xxx_fixup_hp_mic_led(struct hda_codec *codec,
2091{ 2092{
2092 struct sigmatel_spec *spec = codec->spec; 2093 struct sigmatel_spec *spec = codec->spec;
2093 2094
2094 if (action == HDA_FIXUP_ACT_PRE_PROBE) 2095 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2095 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */ 2096 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */
2097 codec->bus->avoid_link_reset = 1;
2098 }
2096} 2099}
2097 2100
2098static void stac92hd83xxx_fixup_headset_jack(struct hda_codec *codec, 2101static void stac92hd83xxx_fixup_headset_jack(struct hda_codec *codec,
@@ -2104,6 +2107,434 @@ static void stac92hd83xxx_fixup_headset_jack(struct hda_codec *codec,
2104 spec->headset_jack = 1; 2107 spec->headset_jack = 1;
2105} 2108}
2106 2109
2110static const struct hda_verb hp_bnb13_eq_verbs[] = {
2111 /* 44.1KHz base */
2112 { 0x22, 0x7A6, 0x3E },
2113 { 0x22, 0x7A7, 0x68 },
2114 { 0x22, 0x7A8, 0x17 },
2115 { 0x22, 0x7A9, 0x3E },
2116 { 0x22, 0x7AA, 0x68 },
2117 { 0x22, 0x7AB, 0x17 },
2118 { 0x22, 0x7AC, 0x00 },
2119 { 0x22, 0x7AD, 0x80 },
2120 { 0x22, 0x7A6, 0x83 },
2121 { 0x22, 0x7A7, 0x2F },
2122 { 0x22, 0x7A8, 0xD1 },
2123 { 0x22, 0x7A9, 0x83 },
2124 { 0x22, 0x7AA, 0x2F },
2125 { 0x22, 0x7AB, 0xD1 },
2126 { 0x22, 0x7AC, 0x01 },
2127 { 0x22, 0x7AD, 0x80 },
2128 { 0x22, 0x7A6, 0x3E },
2129 { 0x22, 0x7A7, 0x68 },
2130 { 0x22, 0x7A8, 0x17 },
2131 { 0x22, 0x7A9, 0x3E },
2132 { 0x22, 0x7AA, 0x68 },
2133 { 0x22, 0x7AB, 0x17 },
2134 { 0x22, 0x7AC, 0x02 },
2135 { 0x22, 0x7AD, 0x80 },
2136 { 0x22, 0x7A6, 0x7C },
2137 { 0x22, 0x7A7, 0xC6 },
2138 { 0x22, 0x7A8, 0x0C },
2139 { 0x22, 0x7A9, 0x7C },
2140 { 0x22, 0x7AA, 0xC6 },
2141 { 0x22, 0x7AB, 0x0C },
2142 { 0x22, 0x7AC, 0x03 },
2143 { 0x22, 0x7AD, 0x80 },
2144 { 0x22, 0x7A6, 0xC3 },
2145 { 0x22, 0x7A7, 0x25 },
2146 { 0x22, 0x7A8, 0xAF },
2147 { 0x22, 0x7A9, 0xC3 },
2148 { 0x22, 0x7AA, 0x25 },
2149 { 0x22, 0x7AB, 0xAF },
2150 { 0x22, 0x7AC, 0x04 },
2151 { 0x22, 0x7AD, 0x80 },
2152 { 0x22, 0x7A6, 0x3E },
2153 { 0x22, 0x7A7, 0x85 },
2154 { 0x22, 0x7A8, 0x73 },
2155 { 0x22, 0x7A9, 0x3E },
2156 { 0x22, 0x7AA, 0x85 },
2157 { 0x22, 0x7AB, 0x73 },
2158 { 0x22, 0x7AC, 0x05 },
2159 { 0x22, 0x7AD, 0x80 },
2160 { 0x22, 0x7A6, 0x85 },
2161 { 0x22, 0x7A7, 0x39 },
2162 { 0x22, 0x7A8, 0xC7 },
2163 { 0x22, 0x7A9, 0x85 },
2164 { 0x22, 0x7AA, 0x39 },
2165 { 0x22, 0x7AB, 0xC7 },
2166 { 0x22, 0x7AC, 0x06 },
2167 { 0x22, 0x7AD, 0x80 },
2168 { 0x22, 0x7A6, 0x3C },
2169 { 0x22, 0x7A7, 0x90 },
2170 { 0x22, 0x7A8, 0xB0 },
2171 { 0x22, 0x7A9, 0x3C },
2172 { 0x22, 0x7AA, 0x90 },
2173 { 0x22, 0x7AB, 0xB0 },
2174 { 0x22, 0x7AC, 0x07 },
2175 { 0x22, 0x7AD, 0x80 },
2176 { 0x22, 0x7A6, 0x7A },
2177 { 0x22, 0x7A7, 0xC6 },
2178 { 0x22, 0x7A8, 0x39 },
2179 { 0x22, 0x7A9, 0x7A },
2180 { 0x22, 0x7AA, 0xC6 },
2181 { 0x22, 0x7AB, 0x39 },
2182 { 0x22, 0x7AC, 0x08 },
2183 { 0x22, 0x7AD, 0x80 },
2184 { 0x22, 0x7A6, 0xC4 },
2185 { 0x22, 0x7A7, 0xE9 },
2186 { 0x22, 0x7A8, 0xDC },
2187 { 0x22, 0x7A9, 0xC4 },
2188 { 0x22, 0x7AA, 0xE9 },
2189 { 0x22, 0x7AB, 0xDC },
2190 { 0x22, 0x7AC, 0x09 },
2191 { 0x22, 0x7AD, 0x80 },
2192 { 0x22, 0x7A6, 0x3D },
2193 { 0x22, 0x7A7, 0xE1 },
2194 { 0x22, 0x7A8, 0x0D },
2195 { 0x22, 0x7A9, 0x3D },
2196 { 0x22, 0x7AA, 0xE1 },
2197 { 0x22, 0x7AB, 0x0D },
2198 { 0x22, 0x7AC, 0x0A },
2199 { 0x22, 0x7AD, 0x80 },
2200 { 0x22, 0x7A6, 0x89 },
2201 { 0x22, 0x7A7, 0xB6 },
2202 { 0x22, 0x7A8, 0xEB },
2203 { 0x22, 0x7A9, 0x89 },
2204 { 0x22, 0x7AA, 0xB6 },
2205 { 0x22, 0x7AB, 0xEB },
2206 { 0x22, 0x7AC, 0x0B },
2207 { 0x22, 0x7AD, 0x80 },
2208 { 0x22, 0x7A6, 0x39 },
2209 { 0x22, 0x7A7, 0x9D },
2210 { 0x22, 0x7A8, 0xFE },
2211 { 0x22, 0x7A9, 0x39 },
2212 { 0x22, 0x7AA, 0x9D },
2213 { 0x22, 0x7AB, 0xFE },
2214 { 0x22, 0x7AC, 0x0C },
2215 { 0x22, 0x7AD, 0x80 },
2216 { 0x22, 0x7A6, 0x76 },
2217 { 0x22, 0x7A7, 0x49 },
2218 { 0x22, 0x7A8, 0x15 },
2219 { 0x22, 0x7A9, 0x76 },
2220 { 0x22, 0x7AA, 0x49 },
2221 { 0x22, 0x7AB, 0x15 },
2222 { 0x22, 0x7AC, 0x0D },
2223 { 0x22, 0x7AD, 0x80 },
2224 { 0x22, 0x7A6, 0xC8 },
2225 { 0x22, 0x7A7, 0x80 },
2226 { 0x22, 0x7A8, 0xF5 },
2227 { 0x22, 0x7A9, 0xC8 },
2228 { 0x22, 0x7AA, 0x80 },
2229 { 0x22, 0x7AB, 0xF5 },
2230 { 0x22, 0x7AC, 0x0E },
2231 { 0x22, 0x7AD, 0x80 },
2232 { 0x22, 0x7A6, 0x40 },
2233 { 0x22, 0x7A7, 0x00 },
2234 { 0x22, 0x7A8, 0x00 },
2235 { 0x22, 0x7A9, 0x40 },
2236 { 0x22, 0x7AA, 0x00 },
2237 { 0x22, 0x7AB, 0x00 },
2238 { 0x22, 0x7AC, 0x0F },
2239 { 0x22, 0x7AD, 0x80 },
2240 { 0x22, 0x7A6, 0x90 },
2241 { 0x22, 0x7A7, 0x68 },
2242 { 0x22, 0x7A8, 0xF1 },
2243 { 0x22, 0x7A9, 0x90 },
2244 { 0x22, 0x7AA, 0x68 },
2245 { 0x22, 0x7AB, 0xF1 },
2246 { 0x22, 0x7AC, 0x10 },
2247 { 0x22, 0x7AD, 0x80 },
2248 { 0x22, 0x7A6, 0x34 },
2249 { 0x22, 0x7A7, 0x47 },
2250 { 0x22, 0x7A8, 0x6C },
2251 { 0x22, 0x7A9, 0x34 },
2252 { 0x22, 0x7AA, 0x47 },
2253 { 0x22, 0x7AB, 0x6C },
2254 { 0x22, 0x7AC, 0x11 },
2255 { 0x22, 0x7AD, 0x80 },
2256 { 0x22, 0x7A6, 0x6F },
2257 { 0x22, 0x7A7, 0x97 },
2258 { 0x22, 0x7A8, 0x0F },
2259 { 0x22, 0x7A9, 0x6F },
2260 { 0x22, 0x7AA, 0x97 },
2261 { 0x22, 0x7AB, 0x0F },
2262 { 0x22, 0x7AC, 0x12 },
2263 { 0x22, 0x7AD, 0x80 },
2264 { 0x22, 0x7A6, 0xCB },
2265 { 0x22, 0x7A7, 0xB8 },
2266 { 0x22, 0x7A8, 0x94 },
2267 { 0x22, 0x7A9, 0xCB },
2268 { 0x22, 0x7AA, 0xB8 },
2269 { 0x22, 0x7AB, 0x94 },
2270 { 0x22, 0x7AC, 0x13 },
2271 { 0x22, 0x7AD, 0x80 },
2272 { 0x22, 0x7A6, 0x40 },
2273 { 0x22, 0x7A7, 0x00 },
2274 { 0x22, 0x7A8, 0x00 },
2275 { 0x22, 0x7A9, 0x40 },
2276 { 0x22, 0x7AA, 0x00 },
2277 { 0x22, 0x7AB, 0x00 },
2278 { 0x22, 0x7AC, 0x14 },
2279 { 0x22, 0x7AD, 0x80 },
2280 { 0x22, 0x7A6, 0x95 },
2281 { 0x22, 0x7A7, 0x76 },
2282 { 0x22, 0x7A8, 0x5B },
2283 { 0x22, 0x7A9, 0x95 },
2284 { 0x22, 0x7AA, 0x76 },
2285 { 0x22, 0x7AB, 0x5B },
2286 { 0x22, 0x7AC, 0x15 },
2287 { 0x22, 0x7AD, 0x80 },
2288 { 0x22, 0x7A6, 0x31 },
2289 { 0x22, 0x7A7, 0xAC },
2290 { 0x22, 0x7A8, 0x31 },
2291 { 0x22, 0x7A9, 0x31 },
2292 { 0x22, 0x7AA, 0xAC },
2293 { 0x22, 0x7AB, 0x31 },
2294 { 0x22, 0x7AC, 0x16 },
2295 { 0x22, 0x7AD, 0x80 },
2296 { 0x22, 0x7A6, 0x6A },
2297 { 0x22, 0x7A7, 0x89 },
2298 { 0x22, 0x7A8, 0xA5 },
2299 { 0x22, 0x7A9, 0x6A },
2300 { 0x22, 0x7AA, 0x89 },
2301 { 0x22, 0x7AB, 0xA5 },
2302 { 0x22, 0x7AC, 0x17 },
2303 { 0x22, 0x7AD, 0x80 },
2304 { 0x22, 0x7A6, 0xCE },
2305 { 0x22, 0x7A7, 0x53 },
2306 { 0x22, 0x7A8, 0xCF },
2307 { 0x22, 0x7A9, 0xCE },
2308 { 0x22, 0x7AA, 0x53 },
2309 { 0x22, 0x7AB, 0xCF },
2310 { 0x22, 0x7AC, 0x18 },
2311 { 0x22, 0x7AD, 0x80 },
2312 { 0x22, 0x7A6, 0x40 },
2313 { 0x22, 0x7A7, 0x00 },
2314 { 0x22, 0x7A8, 0x00 },
2315 { 0x22, 0x7A9, 0x40 },
2316 { 0x22, 0x7AA, 0x00 },
2317 { 0x22, 0x7AB, 0x00 },
2318 { 0x22, 0x7AC, 0x19 },
2319 { 0x22, 0x7AD, 0x80 },
2320 /* 48KHz base */
2321 { 0x22, 0x7A6, 0x3E },
2322 { 0x22, 0x7A7, 0x88 },
2323 { 0x22, 0x7A8, 0xDC },
2324 { 0x22, 0x7A9, 0x3E },
2325 { 0x22, 0x7AA, 0x88 },
2326 { 0x22, 0x7AB, 0xDC },
2327 { 0x22, 0x7AC, 0x1A },
2328 { 0x22, 0x7AD, 0x80 },
2329 { 0x22, 0x7A6, 0x82 },
2330 { 0x22, 0x7A7, 0xEE },
2331 { 0x22, 0x7A8, 0x46 },
2332 { 0x22, 0x7A9, 0x82 },
2333 { 0x22, 0x7AA, 0xEE },
2334 { 0x22, 0x7AB, 0x46 },
2335 { 0x22, 0x7AC, 0x1B },
2336 { 0x22, 0x7AD, 0x80 },
2337 { 0x22, 0x7A6, 0x3E },
2338 { 0x22, 0x7A7, 0x88 },
2339 { 0x22, 0x7A8, 0xDC },
2340 { 0x22, 0x7A9, 0x3E },
2341 { 0x22, 0x7AA, 0x88 },
2342 { 0x22, 0x7AB, 0xDC },
2343 { 0x22, 0x7AC, 0x1C },
2344 { 0x22, 0x7AD, 0x80 },
2345 { 0x22, 0x7A6, 0x7D },
2346 { 0x22, 0x7A7, 0x09 },
2347 { 0x22, 0x7A8, 0x28 },
2348 { 0x22, 0x7A9, 0x7D },
2349 { 0x22, 0x7AA, 0x09 },
2350 { 0x22, 0x7AB, 0x28 },
2351 { 0x22, 0x7AC, 0x1D },
2352 { 0x22, 0x7AD, 0x80 },
2353 { 0x22, 0x7A6, 0xC2 },
2354 { 0x22, 0x7A7, 0xE5 },
2355 { 0x22, 0x7A8, 0xB4 },
2356 { 0x22, 0x7A9, 0xC2 },
2357 { 0x22, 0x7AA, 0xE5 },
2358 { 0x22, 0x7AB, 0xB4 },
2359 { 0x22, 0x7AC, 0x1E },
2360 { 0x22, 0x7AD, 0x80 },
2361 { 0x22, 0x7A6, 0x3E },
2362 { 0x22, 0x7A7, 0xA3 },
2363 { 0x22, 0x7A8, 0x1F },
2364 { 0x22, 0x7A9, 0x3E },
2365 { 0x22, 0x7AA, 0xA3 },
2366 { 0x22, 0x7AB, 0x1F },
2367 { 0x22, 0x7AC, 0x1F },
2368 { 0x22, 0x7AD, 0x80 },
2369 { 0x22, 0x7A6, 0x84 },
2370 { 0x22, 0x7A7, 0xCA },
2371 { 0x22, 0x7A8, 0xF1 },
2372 { 0x22, 0x7A9, 0x84 },
2373 { 0x22, 0x7AA, 0xCA },
2374 { 0x22, 0x7AB, 0xF1 },
2375 { 0x22, 0x7AC, 0x20 },
2376 { 0x22, 0x7AD, 0x80 },
2377 { 0x22, 0x7A6, 0x3C },
2378 { 0x22, 0x7A7, 0xD5 },
2379 { 0x22, 0x7A8, 0x9C },
2380 { 0x22, 0x7A9, 0x3C },
2381 { 0x22, 0x7AA, 0xD5 },
2382 { 0x22, 0x7AB, 0x9C },
2383 { 0x22, 0x7AC, 0x21 },
2384 { 0x22, 0x7AD, 0x80 },
2385 { 0x22, 0x7A6, 0x7B },
2386 { 0x22, 0x7A7, 0x35 },
2387 { 0x22, 0x7A8, 0x0F },
2388 { 0x22, 0x7A9, 0x7B },
2389 { 0x22, 0x7AA, 0x35 },
2390 { 0x22, 0x7AB, 0x0F },
2391 { 0x22, 0x7AC, 0x22 },
2392 { 0x22, 0x7AD, 0x80 },
2393 { 0x22, 0x7A6, 0xC4 },
2394 { 0x22, 0x7A7, 0x87 },
2395 { 0x22, 0x7A8, 0x45 },
2396 { 0x22, 0x7A9, 0xC4 },
2397 { 0x22, 0x7AA, 0x87 },
2398 { 0x22, 0x7AB, 0x45 },
2399 { 0x22, 0x7AC, 0x23 },
2400 { 0x22, 0x7AD, 0x80 },
2401 { 0x22, 0x7A6, 0x3E },
2402 { 0x22, 0x7A7, 0x0A },
2403 { 0x22, 0x7A8, 0x78 },
2404 { 0x22, 0x7A9, 0x3E },
2405 { 0x22, 0x7AA, 0x0A },
2406 { 0x22, 0x7AB, 0x78 },
2407 { 0x22, 0x7AC, 0x24 },
2408 { 0x22, 0x7AD, 0x80 },
2409 { 0x22, 0x7A6, 0x88 },
2410 { 0x22, 0x7A7, 0xE2 },
2411 { 0x22, 0x7A8, 0x05 },
2412 { 0x22, 0x7A9, 0x88 },
2413 { 0x22, 0x7AA, 0xE2 },
2414 { 0x22, 0x7AB, 0x05 },
2415 { 0x22, 0x7AC, 0x25 },
2416 { 0x22, 0x7AD, 0x80 },
2417 { 0x22, 0x7A6, 0x3A },
2418 { 0x22, 0x7A7, 0x1A },
2419 { 0x22, 0x7A8, 0xA3 },
2420 { 0x22, 0x7A9, 0x3A },
2421 { 0x22, 0x7AA, 0x1A },
2422 { 0x22, 0x7AB, 0xA3 },
2423 { 0x22, 0x7AC, 0x26 },
2424 { 0x22, 0x7AD, 0x80 },
2425 { 0x22, 0x7A6, 0x77 },
2426 { 0x22, 0x7A7, 0x1D },
2427 { 0x22, 0x7A8, 0xFB },
2428 { 0x22, 0x7A9, 0x77 },
2429 { 0x22, 0x7AA, 0x1D },
2430 { 0x22, 0x7AB, 0xFB },
2431 { 0x22, 0x7AC, 0x27 },
2432 { 0x22, 0x7AD, 0x80 },
2433 { 0x22, 0x7A6, 0xC7 },
2434 { 0x22, 0x7A7, 0xDA },
2435 { 0x22, 0x7A8, 0xE5 },
2436 { 0x22, 0x7A9, 0xC7 },
2437 { 0x22, 0x7AA, 0xDA },
2438 { 0x22, 0x7AB, 0xE5 },
2439 { 0x22, 0x7AC, 0x28 },
2440 { 0x22, 0x7AD, 0x80 },
2441 { 0x22, 0x7A6, 0x40 },
2442 { 0x22, 0x7A7, 0x00 },
2443 { 0x22, 0x7A8, 0x00 },
2444 { 0x22, 0x7A9, 0x40 },
2445 { 0x22, 0x7AA, 0x00 },
2446 { 0x22, 0x7AB, 0x00 },
2447 { 0x22, 0x7AC, 0x29 },
2448 { 0x22, 0x7AD, 0x80 },
2449 { 0x22, 0x7A6, 0x8E },
2450 { 0x22, 0x7A7, 0xD7 },
2451 { 0x22, 0x7A8, 0x22 },
2452 { 0x22, 0x7A9, 0x8E },
2453 { 0x22, 0x7AA, 0xD7 },
2454 { 0x22, 0x7AB, 0x22 },
2455 { 0x22, 0x7AC, 0x2A },
2456 { 0x22, 0x7AD, 0x80 },
2457 { 0x22, 0x7A6, 0x35 },
2458 { 0x22, 0x7A7, 0x26 },
2459 { 0x22, 0x7A8, 0xC6 },
2460 { 0x22, 0x7A9, 0x35 },
2461 { 0x22, 0x7AA, 0x26 },
2462 { 0x22, 0x7AB, 0xC6 },
2463 { 0x22, 0x7AC, 0x2B },
2464 { 0x22, 0x7AD, 0x80 },
2465 { 0x22, 0x7A6, 0x71 },
2466 { 0x22, 0x7A7, 0x28 },
2467 { 0x22, 0x7A8, 0xDE },
2468 { 0x22, 0x7A9, 0x71 },
2469 { 0x22, 0x7AA, 0x28 },
2470 { 0x22, 0x7AB, 0xDE },
2471 { 0x22, 0x7AC, 0x2C },
2472 { 0x22, 0x7AD, 0x80 },
2473 { 0x22, 0x7A6, 0xCA },
2474 { 0x22, 0x7A7, 0xD9 },
2475 { 0x22, 0x7A8, 0x3A },
2476 { 0x22, 0x7A9, 0xCA },
2477 { 0x22, 0x7AA, 0xD9 },
2478 { 0x22, 0x7AB, 0x3A },
2479 { 0x22, 0x7AC, 0x2D },
2480 { 0x22, 0x7AD, 0x80 },
2481 { 0x22, 0x7A6, 0x40 },
2482 { 0x22, 0x7A7, 0x00 },
2483 { 0x22, 0x7A8, 0x00 },
2484 { 0x22, 0x7A9, 0x40 },
2485 { 0x22, 0x7AA, 0x00 },
2486 { 0x22, 0x7AB, 0x00 },
2487 { 0x22, 0x7AC, 0x2E },
2488 { 0x22, 0x7AD, 0x80 },
2489 { 0x22, 0x7A6, 0x93 },
2490 { 0x22, 0x7A7, 0x5E },
2491 { 0x22, 0x7A8, 0xD8 },
2492 { 0x22, 0x7A9, 0x93 },
2493 { 0x22, 0x7AA, 0x5E },
2494 { 0x22, 0x7AB, 0xD8 },
2495 { 0x22, 0x7AC, 0x2F },
2496 { 0x22, 0x7AD, 0x80 },
2497 { 0x22, 0x7A6, 0x32 },
2498 { 0x22, 0x7A7, 0xB7 },
2499 { 0x22, 0x7A8, 0xB1 },
2500 { 0x22, 0x7A9, 0x32 },
2501 { 0x22, 0x7AA, 0xB7 },
2502 { 0x22, 0x7AB, 0xB1 },
2503 { 0x22, 0x7AC, 0x30 },
2504 { 0x22, 0x7AD, 0x80 },
2505 { 0x22, 0x7A6, 0x6C },
2506 { 0x22, 0x7A7, 0xA1 },
2507 { 0x22, 0x7A8, 0x28 },
2508 { 0x22, 0x7A9, 0x6C },
2509 { 0x22, 0x7AA, 0xA1 },
2510 { 0x22, 0x7AB, 0x28 },
2511 { 0x22, 0x7AC, 0x31 },
2512 { 0x22, 0x7AD, 0x80 },
2513 { 0x22, 0x7A6, 0xCD },
2514 { 0x22, 0x7A7, 0x48 },
2515 { 0x22, 0x7A8, 0x4F },
2516 { 0x22, 0x7A9, 0xCD },
2517 { 0x22, 0x7AA, 0x48 },
2518 { 0x22, 0x7AB, 0x4F },
2519 { 0x22, 0x7AC, 0x32 },
2520 { 0x22, 0x7AD, 0x80 },
2521 { 0x22, 0x7A6, 0x40 },
2522 { 0x22, 0x7A7, 0x00 },
2523 { 0x22, 0x7A8, 0x00 },
2524 { 0x22, 0x7A9, 0x40 },
2525 { 0x22, 0x7AA, 0x00 },
2526 { 0x22, 0x7AB, 0x00 },
2527 { 0x22, 0x7AC, 0x33 },
2528 { 0x22, 0x7AD, 0x80 },
2529 /* common */
2530 { 0x22, 0x782, 0xC1 },
2531 { 0x22, 0x771, 0x2C },
2532 { 0x22, 0x772, 0x2C },
2533 { 0x22, 0x788, 0x04 },
2534 { 0x01, 0x7B0, 0x08 },
2535 {}
2536};
2537
2107static const struct hda_fixup stac92hd83xxx_fixups[] = { 2538static const struct hda_fixup stac92hd83xxx_fixups[] = {
2108 [STAC_92HD83XXX_REF] = { 2539 [STAC_92HD83XXX_REF] = {
2109 .type = HDA_FIXUP_PINS, 2540 .type = HDA_FIXUP_PINS,
@@ -2172,6 +2603,12 @@ static const struct hda_fixup stac92hd83xxx_fixups[] = {
2172 {} 2603 {}
2173 }, 2604 },
2174 }, 2605 },
2606 [STAC_HP_BNB13_EQ] = {
2607 .type = HDA_FIXUP_VERBS,
2608 .v.verbs = hp_bnb13_eq_verbs,
2609 .chained = true,
2610 .chain_id = STAC_92HD83XXX_HP_MIC_LED,
2611 },
2175}; 2612};
2176 2613
2177static const struct hda_model_fixup stac92hd83xxx_models[] = { 2614static const struct hda_model_fixup stac92hd83xxx_models[] = {
@@ -2187,6 +2624,7 @@ static const struct hda_model_fixup stac92hd83xxx_models[] = {
2187 { .id = STAC_92HD83XXX_HP_MIC_LED, .name = "hp-mic-led" }, 2624 { .id = STAC_92HD83XXX_HP_MIC_LED, .name = "hp-mic-led" },
2188 { .id = STAC_92HD83XXX_HEADSET_JACK, .name = "headset-jack" }, 2625 { .id = STAC_92HD83XXX_HEADSET_JACK, .name = "headset-jack" },
2189 { .id = STAC_HP_ENVY_BASS, .name = "hp-envy-bass" }, 2626 { .id = STAC_HP_ENVY_BASS, .name = "hp-envy-bass" },
2627 { .id = STAC_HP_BNB13_EQ, .name = "hp-bnb13-eq" },
2190 {} 2628 {}
2191}; 2629};
2192 2630
@@ -2233,7 +2671,101 @@ static const struct snd_pci_quirk stac92hd83xxx_fixup_tbl[] = {
2233 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1888, 2671 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1888,
2234 "HP Envy Spectre", STAC_HP_ENVY_BASS), 2672 "HP Envy Spectre", STAC_HP_ENVY_BASS),
2235 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df, 2673 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df,
2236 "HP Folio", STAC_92HD83XXX_HP_MIC_LED), 2674 "HP Folio", STAC_HP_BNB13_EQ),
2675 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18F8,
2676 "HP bNB13", STAC_HP_BNB13_EQ),
2677 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1909,
2678 "HP bNB13", STAC_HP_BNB13_EQ),
2679 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x190A,
2680 "HP bNB13", STAC_HP_BNB13_EQ),
2681 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1940,
2682 "HP bNB13", STAC_HP_BNB13_EQ),
2683 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1941,
2684 "HP bNB13", STAC_HP_BNB13_EQ),
2685 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1942,
2686 "HP bNB13", STAC_HP_BNB13_EQ),
2687 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1943,
2688 "HP bNB13", STAC_HP_BNB13_EQ),
2689 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1944,
2690 "HP bNB13", STAC_HP_BNB13_EQ),
2691 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1945,
2692 "HP bNB13", STAC_HP_BNB13_EQ),
2693 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1946,
2694 "HP bNB13", STAC_HP_BNB13_EQ),
2695 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1948,
2696 "HP bNB13", STAC_HP_BNB13_EQ),
2697 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1949,
2698 "HP bNB13", STAC_HP_BNB13_EQ),
2699 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194A,
2700 "HP bNB13", STAC_HP_BNB13_EQ),
2701 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194B,
2702 "HP bNB13", STAC_HP_BNB13_EQ),
2703 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194C,
2704 "HP bNB13", STAC_HP_BNB13_EQ),
2705 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194E,
2706 "HP bNB13", STAC_HP_BNB13_EQ),
2707 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194F,
2708 "HP bNB13", STAC_HP_BNB13_EQ),
2709 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1950,
2710 "HP bNB13", STAC_HP_BNB13_EQ),
2711 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1951,
2712 "HP bNB13", STAC_HP_BNB13_EQ),
2713 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x195A,
2714 "HP bNB13", STAC_HP_BNB13_EQ),
2715 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x195B,
2716 "HP bNB13", STAC_HP_BNB13_EQ),
2717 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x195C,
2718 "HP bNB13", STAC_HP_BNB13_EQ),
2719 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1991,
2720 "HP bNB13", STAC_HP_BNB13_EQ),
2721 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2103,
2722 "HP bNB13", STAC_HP_BNB13_EQ),
2723 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2104,
2724 "HP bNB13", STAC_HP_BNB13_EQ),
2725 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2105,
2726 "HP bNB13", STAC_HP_BNB13_EQ),
2727 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2106,
2728 "HP bNB13", STAC_HP_BNB13_EQ),
2729 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2107,
2730 "HP bNB13", STAC_HP_BNB13_EQ),
2731 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2108,
2732 "HP bNB13", STAC_HP_BNB13_EQ),
2733 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2109,
2734 "HP bNB13", STAC_HP_BNB13_EQ),
2735 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x210A,
2736 "HP bNB13", STAC_HP_BNB13_EQ),
2737 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x210B,
2738 "HP bNB13", STAC_HP_BNB13_EQ),
2739 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x211C,
2740 "HP bNB13", STAC_HP_BNB13_EQ),
2741 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x211D,
2742 "HP bNB13", STAC_HP_BNB13_EQ),
2743 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x211E,
2744 "HP bNB13", STAC_HP_BNB13_EQ),
2745 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x211F,
2746 "HP bNB13", STAC_HP_BNB13_EQ),
2747 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2120,
2748 "HP bNB13", STAC_HP_BNB13_EQ),
2749 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2121,
2750 "HP bNB13", STAC_HP_BNB13_EQ),
2751 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2122,
2752 "HP bNB13", STAC_HP_BNB13_EQ),
2753 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2123,
2754 "HP bNB13", STAC_HP_BNB13_EQ),
2755 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x213E,
2756 "HP bNB13", STAC_HP_BNB13_EQ),
2757 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x213F,
2758 "HP bNB13", STAC_HP_BNB13_EQ),
2759 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2140,
2760 "HP bNB13", STAC_HP_BNB13_EQ),
2761 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x21B2,
2762 "HP bNB13", STAC_HP_BNB13_EQ),
2763 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x21B3,
2764 "HP bNB13", STAC_HP_BNB13_EQ),
2765 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x21B5,
2766 "HP bNB13", STAC_HP_BNB13_EQ),
2767 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x21B6,
2768 "HP bNB13", STAC_HP_BNB13_EQ),
2237 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x1900, 2769 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x1900,
2238 "HP", STAC_92HD83XXX_HP_MIC_LED), 2770 "HP", STAC_92HD83XXX_HP_MIC_LED),
2239 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x2000, 2771 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x2000,
diff --git a/sound/pci/ice1712/psc724.c b/sound/pci/ice1712/psc724.c
index 302ac6ddd545..4019cf27d117 100644
--- a/sound/pci/ice1712/psc724.c
+++ b/sound/pci/ice1712/psc724.c
@@ -203,12 +203,12 @@ static void psc724_set_jack_state(struct snd_ice1712 *ice, bool hp_connected)
203 /* notify about master speaker mute change */ 203 /* notify about master speaker mute change */
204 memset(&elem_id, 0, sizeof(elem_id)); 204 memset(&elem_id, 0, sizeof(elem_id));
205 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 205 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
206 strncpy(elem_id.name, "Master Speakers Playback Switch", 206 strlcpy(elem_id.name, "Master Speakers Playback Switch",
207 sizeof(elem_id.name)); 207 sizeof(elem_id.name));
208 kctl = snd_ctl_find_id(ice->card, &elem_id); 208 kctl = snd_ctl_find_id(ice->card, &elem_id);
209 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 209 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
210 /* and headphone mute change */ 210 /* and headphone mute change */
211 strncpy(elem_id.name, spec->wm8776.ctl[WM8776_CTL_HP_SW].name, 211 strlcpy(elem_id.name, spec->wm8776.ctl[WM8776_CTL_HP_SW].name,
212 sizeof(elem_id.name)); 212 sizeof(elem_id.name));
213 kctl = snd_ctl_find_id(ice->card, &elem_id); 213 kctl = snd_ctl_find_id(ice->card, &elem_id);
214 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 214 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
diff --git a/sound/pci/ice1712/quartet.c b/sound/pci/ice1712/quartet.c
index 975e0357bd5a..71c6003ef338 100644
--- a/sound/pci/ice1712/quartet.c
+++ b/sound/pci/ice1712/quartet.c
@@ -203,6 +203,7 @@ static const char * const ext_clock_names[3] = {"IEC958 In", "Word Clock 1xFS",
203#define AK4620_DEEMVOL_REG 0x03 203#define AK4620_DEEMVOL_REG 0x03
204#define AK4620_SMUTE (1<<7) 204#define AK4620_SMUTE (1<<7)
205 205
206#ifdef CONFIG_PROC_FS
206/* 207/*
207 * Conversion from int value to its binary form. Used for debugging. 208 * Conversion from int value to its binary form. Used for debugging.
208 * The output buffer must be allocated prior to calling the function. 209 * The output buffer must be allocated prior to calling the function.
@@ -227,6 +228,7 @@ static char *get_binary(char *buffer, int value)
227 buffer[pos] = '\0'; 228 buffer[pos] = '\0';
228 return buffer; 229 return buffer;
229} 230}
231#endif /* CONFIG_PROC_FS */
230 232
231/* 233/*
232 * Initial setup of the conversion array GPIO <-> rate 234 * Initial setup of the conversion array GPIO <-> rate
diff --git a/sound/pci/ice1712/wm8766.c b/sound/pci/ice1712/wm8766.c
index e473f8a88f9c..21b373b2e260 100644
--- a/sound/pci/ice1712/wm8766.c
+++ b/sound/pci/ice1712/wm8766.c
@@ -253,7 +253,8 @@ static int snd_wm8766_ctl_get(struct snd_kcontrol *kcontrol,
253 } 253 }
254 if (wm->ctl[n].flags & WM8766_FLAG_INVERT) { 254 if (wm->ctl[n].flags & WM8766_FLAG_INVERT) {
255 val1 = wm->ctl[n].max - (val1 - wm->ctl[n].min); 255 val1 = wm->ctl[n].max - (val1 - wm->ctl[n].min);
256 val2 = wm->ctl[n].max - (val2 - wm->ctl[n].min); 256 if (wm->ctl[n].flags & WM8766_FLAG_STEREO)
257 val2 = wm->ctl[n].max - (val2 - wm->ctl[n].min);
257 } 258 }
258 ucontrol->value.integer.value[0] = val1; 259 ucontrol->value.integer.value[0] = val1;
259 if (wm->ctl[n].flags & WM8766_FLAG_STEREO) 260 if (wm->ctl[n].flags & WM8766_FLAG_STEREO)
diff --git a/sound/pci/ice1712/wm8776.c b/sound/pci/ice1712/wm8776.c
index a3c05fe5daf9..e66c0da62014 100644
--- a/sound/pci/ice1712/wm8776.c
+++ b/sound/pci/ice1712/wm8776.c
@@ -52,7 +52,7 @@ static void snd_wm8776_activate_ctl(struct snd_wm8776 *wm,
52 unsigned int index_offset; 52 unsigned int index_offset;
53 53
54 memset(&elem_id, 0, sizeof(elem_id)); 54 memset(&elem_id, 0, sizeof(elem_id));
55 strncpy(elem_id.name, ctl_name, sizeof(elem_id.name)); 55 strlcpy(elem_id.name, ctl_name, sizeof(elem_id.name));
56 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 56 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
57 kctl = snd_ctl_find_id(card, &elem_id); 57 kctl = snd_ctl_find_id(card, &elem_id);
58 if (!kctl) 58 if (!kctl)
@@ -526,7 +526,8 @@ static int snd_wm8776_ctl_get(struct snd_kcontrol *kcontrol,
526 } 526 }
527 if (wm->ctl[n].flags & WM8776_FLAG_INVERT) { 527 if (wm->ctl[n].flags & WM8776_FLAG_INVERT) {
528 val1 = wm->ctl[n].max - (val1 - wm->ctl[n].min); 528 val1 = wm->ctl[n].max - (val1 - wm->ctl[n].min);
529 val2 = wm->ctl[n].max - (val2 - wm->ctl[n].min); 529 if (wm->ctl[n].flags & WM8776_FLAG_STEREO)
530 val2 = wm->ctl[n].max - (val2 - wm->ctl[n].min);
530 } 531 }
531 ucontrol->value.integer.value[0] = val1; 532 ucontrol->value.integer.value[0] = val1;
532 if (wm->ctl[n].flags & WM8776_FLAG_STEREO) 533 if (wm->ctl[n].flags & WM8776_FLAG_STEREO)
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 59c8aaebb91e..08d8733604a2 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -1541,17 +1541,16 @@ static int snd_intel8x0_pcm1(struct intel8x0 *chip, int device,
1541 snd_dma_pci_data(chip->pci), 1541 snd_dma_pci_data(chip->pci),
1542 rec->prealloc_size, rec->prealloc_max_size); 1542 rec->prealloc_size, rec->prealloc_max_size);
1543 1543
1544 if (rec->ac97_idx == ICHD_PCMOUT && rec->playback_ops) { 1544 if (rec->playback_ops &&
1545 rec->playback_ops->open == snd_intel8x0_playback_open) {
1545 struct snd_pcm_chmap *chmap; 1546 struct snd_pcm_chmap *chmap;
1546 int chs = 2; 1547 int chs = 2;
1547 if (rec->ac97_idx == ICHD_PCMOUT) { 1548 if (chip->multi8)
1548 if (chip->multi8) 1549 chs = 8;
1549 chs = 8; 1550 else if (chip->multi6)
1550 else if (chip->multi6) 1551 chs = 6;
1551 chs = 6; 1552 else if (chip->multi4)
1552 else if (chip->multi4) 1553 chs = 4;
1553 chs = 4;
1554 }
1555 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, 1554 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1556 snd_pcm_alt_chmaps, chs, 0, 1555 snd_pcm_alt_chmaps, chs, 0,
1557 &chmap); 1556 &chmap);
diff --git a/sound/pci/lola/lola.c b/sound/pci/lola/lola.c
index 7307d97186cb..0568540dc8d3 100644
--- a/sound/pci/lola/lola.c
+++ b/sound/pci/lola/lola.c
@@ -463,7 +463,7 @@ static int lola_parse_tree(struct lola *chip)
463 463
464 err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val); 464 err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
465 if (err < 0) { 465 if (err < 0) {
466 printk(KERN_ERR SFX "Can't read FUNCTION_TYPE for 0x%x\n", nid); 466 printk(KERN_ERR SFX "Can't read FUNCTION_TYPE\n");
467 return err; 467 return err;
468 } 468 }
469 if (val != 1) { 469 if (val != 1) {
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c
index 3230e57f246c..5fcaaa6da4a8 100644
--- a/sound/pci/lx6464es/lx6464es.c
+++ b/sound/pci/lx6464es/lx6464es.c
@@ -453,8 +453,8 @@ static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
453 lower_32_bits(buf), upper_32_bits(buf), 453 lower_32_bits(buf), upper_32_bits(buf),
454 &buffer_index); 454 &buffer_index);
455 455
456 snd_printdd(LXP "starting: buffer index %x on %p (%d bytes)\n", 456 snd_printdd(LXP "starting: buffer index %x on 0x%lx (%d bytes)\n",
457 buffer_index, (void *)buf, period_bytes); 457 buffer_index, (unsigned long)buf, period_bytes);
458 buf += period_bytes; 458 buf += period_bytes;
459 } 459 }
460 460
diff --git a/sound/pci/lx6464es/lx_core.c b/sound/pci/lx6464es/lx_core.c
index 633c8607d053..626ecad4dae7 100644
--- a/sound/pci/lx6464es/lx_core.c
+++ b/sound/pci/lx6464es/lx_core.c
@@ -1191,8 +1191,8 @@ static int lx_interrupt_request_new_buffer(struct lx6464es *chip,
1191 unpack_pointer(buf, &buf_lo, &buf_hi); 1191 unpack_pointer(buf, &buf_lo, &buf_hi);
1192 err = lx_buffer_give(chip, 0, is_capture, period_bytes, buf_lo, buf_hi, 1192 err = lx_buffer_give(chip, 0, is_capture, period_bytes, buf_lo, buf_hi,
1193 &buffer_index); 1193 &buffer_index);
1194 snd_printdd(LXP "interrupt: gave buffer index %x on %p (%d bytes)\n", 1194 snd_printdd(LXP "interrupt: gave buffer index %x on 0x%lx (%d bytes)\n",
1195 buffer_index, (void *)buf, period_bytes); 1195 buffer_index, (unsigned long)buf, period_bytes);
1196 1196
1197 lx_stream->frame_pos = next_pos; 1197 lx_stream->frame_pos = next_pos;
1198 spin_unlock_irqrestore(&chip->lock, flags); 1198 spin_unlock_irqrestore(&chip->lock, flags);
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index bb9ebc5543d7..0236363c301f 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -350,9 +350,8 @@ snd_rme96_playback_copy(struct snd_pcm_substream *substream,
350 struct rme96 *rme96 = snd_pcm_substream_chip(substream); 350 struct rme96 *rme96 = snd_pcm_substream_chip(substream);
351 count <<= rme96->playback_frlog; 351 count <<= rme96->playback_frlog;
352 pos <<= rme96->playback_frlog; 352 pos <<= rme96->playback_frlog;
353 copy_from_user_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, src, 353 return copy_from_user_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, src,
354 count); 354 count);
355 return 0;
356} 355}
357 356
358static int 357static int
@@ -365,9 +364,8 @@ snd_rme96_capture_copy(struct snd_pcm_substream *substream,
365 struct rme96 *rme96 = snd_pcm_substream_chip(substream); 364 struct rme96 *rme96 = snd_pcm_substream_chip(substream);
366 count <<= rme96->capture_frlog; 365 count <<= rme96->capture_frlog;
367 pos <<= rme96->capture_frlog; 366 pos <<= rme96->capture_frlog;
368 copy_to_user_fromio(dst, rme96->iobase + RME96_IO_REC_BUFFER + pos, 367 return copy_to_user_fromio(dst, rme96->iobase + RME96_IO_REC_BUFFER + pos,
369 count); 368 count);
370 return 0;
371} 369}
372 370
373/* 371/*
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 4f255dfee450..f59a321a6d6a 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -4845,6 +4845,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4845 if ((err = hdsp_get_iobox_version(hdsp)) < 0) 4845 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4846 return err; 4846 return err;
4847 } 4847 }
4848 memset(&hdsp_version, 0, sizeof(hdsp_version));
4848 hdsp_version.io_type = hdsp->io_type; 4849 hdsp_version.io_type = hdsp->io_type;
4849 hdsp_version.firmware_rev = hdsp->firmware_rev; 4850 hdsp_version.firmware_rev = hdsp->firmware_rev;
4850 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) 4851 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 3cde55b753e2..e98dc008de0b 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -3996,7 +3996,6 @@ static int hdspm_tco_sync_check(struct hdspm *hdspm)
3996 return 1; 3996 return 1;
3997 } 3997 }
3998 return 0; 3998 return 0;
3999 break;
4000 case AES32: 3999 case AES32:
4001 status = hdspm_read(hdspm, HDSPM_statusRegister); 4000 status = hdspm_read(hdspm, HDSPM_statusRegister);
4002 if (status & HDSPM_tcoLockAes) { 4001 if (status & HDSPM_tcoLockAes) {
@@ -4006,9 +4005,6 @@ static int hdspm_tco_sync_check(struct hdspm *hdspm)
4006 return 1; 4005 return 1;
4007 } 4006 }
4008 return 0; 4007 return 0;
4009
4010 break;
4011
4012 case RayDAT: 4008 case RayDAT:
4013 case AIO: 4009 case AIO:
4014 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); 4010 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
@@ -4018,7 +4014,6 @@ static int hdspm_tco_sync_check(struct hdspm *hdspm)
4018 if (status & 0x4000000) 4014 if (status & 0x4000000)
4019 return 1; /* Lock */ 4015 return 1; /* Lock */
4020 return 0; /* No signal */ 4016 return 0; /* No signal */
4021 break;
4022 4017
4023 default: 4018 default:
4024 break; 4019 break;
@@ -6405,7 +6400,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6405 memset(&hdspm_version, 0, sizeof(hdspm_version)); 6400 memset(&hdspm_version, 0, sizeof(hdspm_version));
6406 6401
6407 hdspm_version.card_type = hdspm->io_type; 6402 hdspm_version.card_type = hdspm->io_type;
6408 strncpy(hdspm_version.cardname, hdspm->card_name, 6403 strlcpy(hdspm_version.cardname, hdspm->card_name,
6409 sizeof(hdspm_version.cardname)); 6404 sizeof(hdspm_version.cardname));
6410 hdspm_version.serial = hdspm->serial; 6405 hdspm_version.serial = hdspm->serial;
6411 hdspm_version.firmware_rev = hdspm->firmware_rev; 6406 hdspm_version.firmware_rev = hdspm->firmware_rev;
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index c93fbbb201fe..7a43c0c38316 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -28,6 +28,8 @@
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/dma-mapping.h> 30#include <linux/dma-mapping.h>
31#include <linux/of_address.h>
32#include <linux/of_irq.h>
31#include <sound/core.h> 33#include <sound/core.h>
32#include "pmac.h" 34#include "pmac.h"
33#include <sound/pcm_params.h> 35#include <sound/pcm_params.h>
diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
index 8c7dcbe0118d..ebb76f2d90d7 100644
--- a/sound/ppc/snd_ps3.c
+++ b/sound/ppc/snd_ps3.c
@@ -933,8 +933,10 @@ static int snd_ps3_driver_probe(struct ps3_system_bus_device *dev)
933 int i, ret; 933 int i, ret;
934 u64 lpar_addr, lpar_size; 934 u64 lpar_addr, lpar_size;
935 935
936 BUG_ON(!firmware_has_feature(FW_FEATURE_PS3_LV1)); 936 if (WARN_ON(!firmware_has_feature(FW_FEATURE_PS3_LV1)))
937 BUG_ON(dev->match_id != PS3_MATCH_ID_SOUND); 937 return -ENODEV;
938 if (WARN_ON(dev->match_id != PS3_MATCH_ID_SOUND))
939 return -ENODEV;
938 940
939 the_card.ps3_dev = dev; 941 the_card.ps3_dev = dev;
940 942
diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c
index b23354a4ceca..b9ffc17a4799 100644
--- a/sound/ppc/tumbler.c
+++ b/sound/ppc/tumbler.c
@@ -31,6 +31,7 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/of_irq.h>
34#include <sound/core.h> 35#include <sound/core.h>
35#include <asm/io.h> 36#include <asm/io.h>
36#include <asm/irq.h> 37#include <asm/irq.h>
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 61a64d281905..8b9e70105dd2 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,5 +1,5 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o 1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o
2snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o 2snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o
3 3
4ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),) 4ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),)
5snd-soc-core-objs += soc-generic-dmaengine-pcm.o 5snd-soc-core-objs += soc-generic-dmaengine-pcm.o
diff --git a/sound/soc/atmel/atmel-pcm.c b/sound/soc/atmel/atmel-pcm.c
index 3109db7b9017..8ae3fa5ac60a 100644
--- a/sound/soc/atmel/atmel-pcm.c
+++ b/sound/soc/atmel/atmel-pcm.c
@@ -50,7 +50,7 @@ static int atmel_pcm_preallocate_dma_buffer(struct snd_pcm *pcm,
50 buf->area = dma_alloc_coherent(pcm->card->dev, size, 50 buf->area = dma_alloc_coherent(pcm->card->dev, size,
51 &buf->addr, GFP_KERNEL); 51 &buf->addr, GFP_KERNEL);
52 pr_debug("atmel-pcm: alloc dma buffer: area=%p, addr=%p, size=%zu\n", 52 pr_debug("atmel-pcm: alloc dma buffer: area=%p, addr=%p, size=%zu\n",
53 (void *)buf->area, (void *)buf->addr, size); 53 (void *)buf->area, (void *)(long)buf->addr, size);
54 54
55 if (!buf->area) 55 if (!buf->area)
56 return -ENOMEM; 56 return -ENOMEM;
@@ -68,18 +68,15 @@ int atmel_pcm_mmap(struct snd_pcm_substream *substream,
68} 68}
69EXPORT_SYMBOL_GPL(atmel_pcm_mmap); 69EXPORT_SYMBOL_GPL(atmel_pcm_mmap);
70 70
71static u64 atmel_pcm_dmamask = DMA_BIT_MASK(32);
72
73int atmel_pcm_new(struct snd_soc_pcm_runtime *rtd) 71int atmel_pcm_new(struct snd_soc_pcm_runtime *rtd)
74{ 72{
75 struct snd_card *card = rtd->card->snd_card; 73 struct snd_card *card = rtd->card->snd_card;
76 struct snd_pcm *pcm = rtd->pcm; 74 struct snd_pcm *pcm = rtd->pcm;
77 int ret = 0; 75 int ret;
78 76
79 if (!card->dev->dma_mask) 77 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
80 card->dev->dma_mask = &atmel_pcm_dmamask; 78 if (ret)
81 if (!card->dev->coherent_dma_mask) 79 return ret;
82 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
83 80
84 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 81 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
85 pr_debug("atmel-pcm: allocating PCM playback DMA buffer\n"); 82 pr_debug("atmel-pcm: allocating PCM playback DMA buffer\n");
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index bb53dea85b17..8697cedccd21 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -777,7 +777,7 @@ static int asoc_ssc_init(struct device *dev)
777 if (ret) { 777 if (ret) {
778 dev_err(dev, "Could not register PCM: %d\n", ret); 778 dev_err(dev, "Could not register PCM: %d\n", ret);
779 goto err_unregister_dai; 779 goto err_unregister_dai;
780 }; 780 }
781 781
782 return 0; 782 return 0;
783 783
diff --git a/sound/soc/atmel/atmel_wm8904.c b/sound/soc/atmel/atmel_wm8904.c
index 7222380131ea..b4e36901a40b 100644
--- a/sound/soc/atmel/atmel_wm8904.c
+++ b/sound/soc/atmel/atmel_wm8904.c
@@ -12,7 +12,6 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/of.h> 13#include <linux/of.h>
14#include <linux/of_device.h> 14#include <linux/of_device.h>
15#include <linux/pinctrl/consumer.h>
16 15
17#include <sound/soc.h> 16#include <sound/soc.h>
18 17
@@ -155,15 +154,8 @@ static int atmel_asoc_wm8904_probe(struct platform_device *pdev)
155 struct snd_soc_card *card = &atmel_asoc_wm8904_card; 154 struct snd_soc_card *card = &atmel_asoc_wm8904_card;
156 struct snd_soc_dai_link *dailink = &atmel_asoc_wm8904_dailink; 155 struct snd_soc_dai_link *dailink = &atmel_asoc_wm8904_dailink;
157 struct clk *clk_src; 156 struct clk *clk_src;
158 struct pinctrl *pinctrl;
159 int id, ret; 157 int id, ret;
160 158
161 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
162 if (IS_ERR(pinctrl)) {
163 dev_err(&pdev->dev, "failed to request pinctrl\n");
164 return PTR_ERR(pinctrl);
165 }
166
167 card->dev = &pdev->dev; 159 card->dev = &pdev->dev;
168 ret = atmel_asoc_wm8904_dt_init(pdev); 160 ret = atmel_asoc_wm8904_dt_init(pdev);
169 if (ret) { 161 if (ret) {
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index 802717eccbd0..f15bff1548f8 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -37,6 +37,7 @@
37#include <linux/interrupt.h> 37#include <linux/interrupt.h>
38#include <linux/platform_device.h> 38#include <linux/platform_device.h>
39#include <linux/i2c.h> 39#include <linux/i2c.h>
40#include <linux/of.h>
40 41
41#include <linux/atmel-ssc.h> 42#include <linux/atmel-ssc.h>
42 43
diff --git a/sound/soc/blackfin/bf5xx-ac97-pcm.c b/sound/soc/blackfin/bf5xx-ac97-pcm.c
index 53f84085bf1f..1d4c676eb6cc 100644
--- a/sound/soc/blackfin/bf5xx-ac97-pcm.c
+++ b/sound/soc/blackfin/bf5xx-ac97-pcm.c
@@ -415,19 +415,16 @@ static void bf5xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
415 } 415 }
416} 416}
417 417
418static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
419
420static int bf5xx_pcm_ac97_new(struct snd_soc_pcm_runtime *rtd) 418static int bf5xx_pcm_ac97_new(struct snd_soc_pcm_runtime *rtd)
421{ 419{
422 struct snd_card *card = rtd->card->snd_card; 420 struct snd_card *card = rtd->card->snd_card;
423 struct snd_pcm *pcm = rtd->pcm; 421 struct snd_pcm *pcm = rtd->pcm;
424 int ret = 0; 422 int ret;
425 423
426 pr_debug("%s enter\n", __func__); 424 pr_debug("%s enter\n", __func__);
427 if (!card->dev->dma_mask) 425 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
428 card->dev->dma_mask = &bf5xx_pcm_dmamask; 426 if (ret)
429 if (!card->dev->coherent_dma_mask) 427 return ret;
430 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
431 428
432 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 429 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
433 ret = bf5xx_pcm_preallocate_dma_buffer(pcm, 430 ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
diff --git a/sound/soc/blackfin/bf5xx-i2s-pcm.c b/sound/soc/blackfin/bf5xx-i2s-pcm.c
index 9cb4a80df98e..2a5b43417fd5 100644
--- a/sound/soc/blackfin/bf5xx-i2s-pcm.c
+++ b/sound/soc/blackfin/bf5xx-i2s-pcm.c
@@ -323,18 +323,16 @@ static struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
323 .silence = bf5xx_pcm_silence, 323 .silence = bf5xx_pcm_silence,
324}; 324};
325 325
326static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
327
328static int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd) 326static int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd)
329{ 327{
330 struct snd_card *card = rtd->card->snd_card; 328 struct snd_card *card = rtd->card->snd_card;
331 size_t size = bf5xx_pcm_hardware.buffer_bytes_max; 329 size_t size = bf5xx_pcm_hardware.buffer_bytes_max;
330 int ret;
332 331
333 pr_debug("%s enter\n", __func__); 332 pr_debug("%s enter\n", __func__);
334 if (!card->dev->dma_mask) 333 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
335 card->dev->dma_mask = &bf5xx_pcm_dmamask; 334 if (ret)
336 if (!card->dev->coherent_dma_mask) 335 return ret;
337 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
338 336
339 return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, 337 return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
340 SNDRV_DMA_TYPE_DEV, card->dev, size, size); 338 SNDRV_DMA_TYPE_DEV, card->dev, size, size);
diff --git a/sound/soc/blackfin/bf5xx-i2s.c b/sound/soc/blackfin/bf5xx-i2s.c
index 9a174fc47d39..39d774839b3e 100644
--- a/sound/soc/blackfin/bf5xx-i2s.c
+++ b/sound/soc/blackfin/bf5xx-i2s.c
@@ -121,6 +121,7 @@ static int bf5xx_i2s_hw_params(struct snd_pcm_substream *substream,
121 bf5xx_i2s->tcr2 |= 7; 121 bf5xx_i2s->tcr2 |= 7;
122 bf5xx_i2s->rcr2 |= 7; 122 bf5xx_i2s->rcr2 |= 7;
123 sport_handle->wdsize = 1; 123 sport_handle->wdsize = 1;
124 break;
124 case SNDRV_PCM_FORMAT_S16_LE: 125 case SNDRV_PCM_FORMAT_S16_LE:
125 bf5xx_i2s->tcr2 |= 15; 126 bf5xx_i2s->tcr2 |= 15;
126 bf5xx_i2s->rcr2 |= 15; 127 bf5xx_i2s->rcr2 |= 15;
diff --git a/sound/soc/blackfin/bf5xx-sport.c b/sound/soc/blackfin/bf5xx-sport.c
index 695351241db8..9dfa1241ea66 100644
--- a/sound/soc/blackfin/bf5xx-sport.c
+++ b/sound/soc/blackfin/bf5xx-sport.c
@@ -179,8 +179,9 @@ static inline int sport_hook_rx_dummy(struct sport_device *sport)
179 struct dmasg *desc, temp_desc; 179 struct dmasg *desc, temp_desc;
180 unsigned long flags; 180 unsigned long flags;
181 181
182 BUG_ON(sport->dummy_rx_desc == NULL); 182 if (WARN_ON(!sport->dummy_rx_desc) ||
183 BUG_ON(sport->curr_rx_desc == sport->dummy_rx_desc); 183 WARN_ON(sport->curr_rx_desc == sport->dummy_rx_desc))
184 return -EINVAL;
184 185
185 /* Maybe the dummy buffer descriptor ring is damaged */ 186 /* Maybe the dummy buffer descriptor ring is damaged */
186 sport->dummy_rx_desc->next_desc_addr = sport->dummy_rx_desc + 1; 187 sport->dummy_rx_desc->next_desc_addr = sport->dummy_rx_desc + 1;
@@ -250,8 +251,9 @@ int sport_rx_start(struct sport_device *sport)
250 return -EBUSY; 251 return -EBUSY;
251 if (sport->tx_run) { 252 if (sport->tx_run) {
252 /* tx is running, rx is not running */ 253 /* tx is running, rx is not running */
253 BUG_ON(sport->dma_rx_desc == NULL); 254 if (WARN_ON(!sport->dma_rx_desc) ||
254 BUG_ON(sport->curr_rx_desc != sport->dummy_rx_desc); 255 WARN_ON(sport->curr_rx_desc != sport->dummy_rx_desc))
256 return -EINVAL;
255 local_irq_save(flags); 257 local_irq_save(flags);
256 while ((get_dma_curr_desc_ptr(sport->dma_rx_chan) - 258 while ((get_dma_curr_desc_ptr(sport->dma_rx_chan) -
257 sizeof(struct dmasg)) != sport->dummy_rx_desc) 259 sizeof(struct dmasg)) != sport->dummy_rx_desc)
@@ -298,8 +300,9 @@ static inline int sport_hook_tx_dummy(struct sport_device *sport)
298 struct dmasg *desc, temp_desc; 300 struct dmasg *desc, temp_desc;
299 unsigned long flags; 301 unsigned long flags;
300 302
301 BUG_ON(sport->dummy_tx_desc == NULL); 303 if (WARN_ON(!sport->dummy_tx_desc) ||
302 BUG_ON(sport->curr_tx_desc == sport->dummy_tx_desc); 304 WARN_ON(sport->curr_tx_desc == sport->dummy_tx_desc))
305 return -EINVAL;
303 306
304 sport->dummy_tx_desc->next_desc_addr = sport->dummy_tx_desc + 1; 307 sport->dummy_tx_desc->next_desc_addr = sport->dummy_tx_desc + 1;
305 308
@@ -331,8 +334,9 @@ int sport_tx_start(struct sport_device *sport)
331 if (sport->tx_run) 334 if (sport->tx_run)
332 return -EBUSY; 335 return -EBUSY;
333 if (sport->rx_run) { 336 if (sport->rx_run) {
334 BUG_ON(sport->dma_tx_desc == NULL); 337 if (WARN_ON(!sport->dma_tx_desc) ||
335 BUG_ON(sport->curr_tx_desc != sport->dummy_tx_desc); 338 WARN_ON(sport->curr_tx_desc != sport->dummy_tx_desc))
339 return -EINVAL;
336 /* Hook the normal buffer descriptor */ 340 /* Hook the normal buffer descriptor */
337 local_irq_save(flags); 341 local_irq_save(flags);
338 while ((get_dma_curr_desc_ptr(sport->dma_tx_chan) - 342 while ((get_dma_curr_desc_ptr(sport->dma_tx_chan) -
@@ -767,7 +771,8 @@ static irqreturn_t err_handler(int irq, void *dev_id)
767int sport_set_rx_callback(struct sport_device *sport, 771int sport_set_rx_callback(struct sport_device *sport,
768 void (*rx_callback)(void *), void *rx_data) 772 void (*rx_callback)(void *), void *rx_data)
769{ 773{
770 BUG_ON(rx_callback == NULL); 774 if (WARN_ON(!rx_callback))
775 return -EINVAL;
771 sport->rx_callback = rx_callback; 776 sport->rx_callback = rx_callback;
772 sport->rx_data = rx_data; 777 sport->rx_data = rx_data;
773 778
@@ -778,7 +783,8 @@ EXPORT_SYMBOL(sport_set_rx_callback);
778int sport_set_tx_callback(struct sport_device *sport, 783int sport_set_tx_callback(struct sport_device *sport,
779 void (*tx_callback)(void *), void *tx_data) 784 void (*tx_callback)(void *), void *tx_data)
780{ 785{
781 BUG_ON(tx_callback == NULL); 786 if (WARN_ON(!tx_callback))
787 return -EINVAL;
782 sport->tx_callback = tx_callback; 788 sport->tx_callback = tx_callback;
783 sport->tx_data = tx_data; 789 sport->tx_data = tx_data;
784 790
@@ -789,7 +795,8 @@ EXPORT_SYMBOL(sport_set_tx_callback);
789int sport_set_err_callback(struct sport_device *sport, 795int sport_set_err_callback(struct sport_device *sport,
790 void (*err_callback)(void *), void *err_data) 796 void (*err_callback)(void *), void *err_data)
791{ 797{
792 BUG_ON(err_callback == NULL); 798 if (WARN_ON(!err_callback))
799 return -EINVAL;
793 sport->err_callback = err_callback; 800 sport->err_callback = err_callback;
794 sport->err_data = err_data; 801 sport->err_data = err_data;
795 802
@@ -856,7 +863,8 @@ struct sport_device *sport_init(struct platform_device *pdev,
856 863
857 param.wdsize = wdsize; 864 param.wdsize = wdsize;
858 param.dummy_count = dummy_count; 865 param.dummy_count = dummy_count;
859 BUG_ON(param.wdsize == 0 || param.dummy_count == 0); 866 if (WARN_ON(param.wdsize == 0 || param.dummy_count == 0))
867 return NULL;
860 868
861 ret = sport_config_pdev(pdev, &param); 869 ret = sport_config_pdev(pdev, &param);
862 if (ret) 870 if (ret)
diff --git a/sound/soc/blackfin/bf6xx-i2s.c b/sound/soc/blackfin/bf6xx-i2s.c
index c02405cc007d..5810a0603f2f 100644
--- a/sound/soc/blackfin/bf6xx-i2s.c
+++ b/sound/soc/blackfin/bf6xx-i2s.c
@@ -88,6 +88,7 @@ static int bfin_i2s_hw_params(struct snd_pcm_substream *substream,
88 case SNDRV_PCM_FORMAT_S8: 88 case SNDRV_PCM_FORMAT_S8:
89 param.spctl |= 0x70; 89 param.spctl |= 0x70;
90 sport->wdsize = 1; 90 sport->wdsize = 1;
91 break;
91 case SNDRV_PCM_FORMAT_S16_LE: 92 case SNDRV_PCM_FORMAT_S16_LE:
92 param.spctl |= 0xf0; 93 param.spctl |= 0xf0;
93 sport->wdsize = 2; 94 sport->wdsize = 2;
diff --git a/sound/soc/cirrus/Kconfig b/sound/soc/cirrus/Kconfig
index 2c20f01e1f7e..06f938deda15 100644
--- a/sound/soc/cirrus/Kconfig
+++ b/sound/soc/cirrus/Kconfig
@@ -1,6 +1,6 @@
1config SND_EP93XX_SOC 1config SND_EP93XX_SOC
2 tristate "SoC Audio support for the Cirrus Logic EP93xx series" 2 tristate "SoC Audio support for the Cirrus Logic EP93xx series"
3 depends on ARCH_EP93XX && SND_SOC 3 depends on (ARCH_EP93XX || COMPILE_TEST) && SND_SOC
4 select SND_SOC_GENERIC_DMAENGINE_PCM 4 select SND_SOC_GENERIC_DMAENGINE_PCM
5 help 5 help
6 Say Y or M if you want to add support for codecs attached to 6 Say Y or M if you want to add support for codecs attached to
diff --git a/sound/soc/cirrus/ep93xx-pcm.c b/sound/soc/cirrus/ep93xx-pcm.c
index 0e9f56e0d4b2..cfe517e68009 100644
--- a/sound/soc/cirrus/ep93xx-pcm.c
+++ b/sound/soc/cirrus/ep93xx-pcm.c
@@ -57,9 +57,22 @@ static bool ep93xx_pcm_dma_filter(struct dma_chan *chan, void *filter_param)
57 return false; 57 return false;
58} 58}
59 59
60static struct dma_chan *ep93xx_compat_request_channel(
61 struct snd_soc_pcm_runtime *rtd,
62 struct snd_pcm_substream *substream)
63{
64 struct snd_dmaengine_dai_dma_data *dma_data;
65
66 dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
67
68 return snd_dmaengine_pcm_request_channel(ep93xx_pcm_dma_filter,
69 dma_data);
70}
71
60static const struct snd_dmaengine_pcm_config ep93xx_dmaengine_pcm_config = { 72static const struct snd_dmaengine_pcm_config ep93xx_dmaengine_pcm_config = {
61 .pcm_hardware = &ep93xx_pcm_hardware, 73 .pcm_hardware = &ep93xx_pcm_hardware,
62 .compat_filter_fn = ep93xx_pcm_dma_filter, 74 .compat_filter_fn = ep93xx_pcm_dma_filter,
75 .compat_request_channel = ep93xx_compat_request_channel,
63 .prealloc_buffer_size = 131072, 76 .prealloc_buffer_size = 131072,
64}; 77};
65 78
diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c
index 8af04343cc1a..75d0ad5d2dcb 100644
--- a/sound/soc/codecs/88pm860x-codec.c
+++ b/sound/soc/codecs/88pm860x-codec.c
@@ -16,6 +16,7 @@
16#include <linux/mfd/88pm860x.h> 16#include <linux/mfd/88pm860x.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/regmap.h>
19#include <sound/core.h> 20#include <sound/core.h>
20#include <sound/pcm.h> 21#include <sound/pcm.h>
21#include <sound/pcm_params.h> 22#include <sound/pcm_params.h>
@@ -140,6 +141,7 @@ struct pm860x_priv {
140 unsigned int filter; 141 unsigned int filter;
141 struct snd_soc_codec *codec; 142 struct snd_soc_codec *codec;
142 struct i2c_client *i2c; 143 struct i2c_client *i2c;
144 struct regmap *regmap;
143 struct pm860x_chip *chip; 145 struct pm860x_chip *chip;
144 struct pm860x_det det; 146 struct pm860x_det det;
145 147
@@ -269,48 +271,6 @@ static struct st_gain st_table[] = {
269 { -86, 29, 0}, { -56, 30, 0}, { -28, 31, 0}, { 0, 0, 0}, 271 { -86, 29, 0}, { -56, 30, 0}, { -28, 31, 0}, { 0, 0, 0},
270}; 272};
271 273
272static int pm860x_volatile(unsigned int reg)
273{
274 BUG_ON(reg >= REG_CACHE_SIZE);
275
276 switch (reg) {
277 case PM860X_AUDIO_SUPPLIES_2:
278 return 1;
279 }
280
281 return 0;
282}
283
284static unsigned int pm860x_read_reg_cache(struct snd_soc_codec *codec,
285 unsigned int reg)
286{
287 unsigned char *cache = codec->reg_cache;
288
289 BUG_ON(reg >= REG_CACHE_SIZE);
290
291 if (pm860x_volatile(reg))
292 return cache[reg];
293
294 reg += REG_CACHE_BASE;
295
296 return pm860x_reg_read(codec->control_data, reg);
297}
298
299static int pm860x_write_reg_cache(struct snd_soc_codec *codec,
300 unsigned int reg, unsigned int value)
301{
302 unsigned char *cache = codec->reg_cache;
303
304 BUG_ON(reg >= REG_CACHE_SIZE);
305
306 if (!pm860x_volatile(reg))
307 cache[reg] = (unsigned char)value;
308
309 reg += REG_CACHE_BASE;
310
311 return pm860x_reg_write(codec->control_data, reg, value);
312}
313
314static int snd_soc_get_volsw_2r_st(struct snd_kcontrol *kcontrol, 274static int snd_soc_get_volsw_2r_st(struct snd_kcontrol *kcontrol,
315 struct snd_ctl_elem_value *ucontrol) 275 struct snd_ctl_elem_value *ucontrol)
316{ 276{
@@ -349,6 +309,9 @@ static int snd_soc_put_volsw_2r_st(struct snd_kcontrol *kcontrol,
349 val = ucontrol->value.integer.value[0]; 309 val = ucontrol->value.integer.value[0];
350 val2 = ucontrol->value.integer.value[1]; 310 val2 = ucontrol->value.integer.value[1];
351 311
312 if (val >= ARRAY_SIZE(st_table) || val2 >= ARRAY_SIZE(st_table))
313 return -EINVAL;
314
352 err = snd_soc_update_bits(codec, reg, 0x3f, st_table[val].m); 315 err = snd_soc_update_bits(codec, reg, 0x3f, st_table[val].m);
353 if (err < 0) 316 if (err < 0)
354 return err; 317 return err;
@@ -1166,6 +1129,7 @@ static int pm860x_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
1166static int pm860x_set_bias_level(struct snd_soc_codec *codec, 1129static int pm860x_set_bias_level(struct snd_soc_codec *codec,
1167 enum snd_soc_bias_level level) 1130 enum snd_soc_bias_level level)
1168{ 1131{
1132 struct pm860x_priv *pm860x = snd_soc_codec_get_drvdata(codec);
1169 int data; 1133 int data;
1170 1134
1171 switch (level) { 1135 switch (level) {
@@ -1179,17 +1143,17 @@ static int pm860x_set_bias_level(struct snd_soc_codec *codec,
1179 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1143 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1180 /* Enable Audio PLL & Audio section */ 1144 /* Enable Audio PLL & Audio section */
1181 data = AUDIO_PLL | AUDIO_SECTION_ON; 1145 data = AUDIO_PLL | AUDIO_SECTION_ON;
1182 pm860x_reg_write(codec->control_data, REG_MISC2, data); 1146 pm860x_reg_write(pm860x->i2c, REG_MISC2, data);
1183 udelay(300); 1147 udelay(300);
1184 data = AUDIO_PLL | AUDIO_SECTION_RESET 1148 data = AUDIO_PLL | AUDIO_SECTION_RESET
1185 | AUDIO_SECTION_ON; 1149 | AUDIO_SECTION_ON;
1186 pm860x_reg_write(codec->control_data, REG_MISC2, data); 1150 pm860x_reg_write(pm860x->i2c, REG_MISC2, data);
1187 } 1151 }
1188 break; 1152 break;
1189 1153
1190 case SND_SOC_BIAS_OFF: 1154 case SND_SOC_BIAS_OFF:
1191 data = AUDIO_PLL | AUDIO_SECTION_RESET | AUDIO_SECTION_ON; 1155 data = AUDIO_PLL | AUDIO_SECTION_RESET | AUDIO_SECTION_ON;
1192 pm860x_set_bits(codec->control_data, REG_MISC2, data, 0); 1156 pm860x_set_bits(pm860x->i2c, REG_MISC2, data, 0);
1193 break; 1157 break;
1194 } 1158 }
1195 codec->dapm.bias_level = level; 1159 codec->dapm.bias_level = level;
@@ -1319,17 +1283,17 @@ int pm860x_hs_jack_detect(struct snd_soc_codec *codec,
1319 pm860x->det.lo_shrt = lo_shrt; 1283 pm860x->det.lo_shrt = lo_shrt;
1320 1284
1321 if (det & SND_JACK_HEADPHONE) 1285 if (det & SND_JACK_HEADPHONE)
1322 pm860x_set_bits(codec->control_data, REG_HS_DET, 1286 pm860x_set_bits(pm860x->i2c, REG_HS_DET,
1323 EN_HS_DET, EN_HS_DET); 1287 EN_HS_DET, EN_HS_DET);
1324 /* headset short detect */ 1288 /* headset short detect */
1325 if (hs_shrt) { 1289 if (hs_shrt) {
1326 data = CLR_SHORT_HS2 | CLR_SHORT_HS1; 1290 data = CLR_SHORT_HS2 | CLR_SHORT_HS1;
1327 pm860x_set_bits(codec->control_data, REG_SHORTS, data, data); 1291 pm860x_set_bits(pm860x->i2c, REG_SHORTS, data, data);
1328 } 1292 }
1329 /* Lineout short detect */ 1293 /* Lineout short detect */
1330 if (lo_shrt) { 1294 if (lo_shrt) {
1331 data = CLR_SHORT_LO2 | CLR_SHORT_LO1; 1295 data = CLR_SHORT_LO2 | CLR_SHORT_LO1;
1332 pm860x_set_bits(codec->control_data, REG_SHORTS, data, data); 1296 pm860x_set_bits(pm860x->i2c, REG_SHORTS, data, data);
1333 } 1297 }
1334 1298
1335 /* sync status */ 1299 /* sync status */
@@ -1347,7 +1311,7 @@ int pm860x_mic_jack_detect(struct snd_soc_codec *codec,
1347 pm860x->det.mic_det = det; 1311 pm860x->det.mic_det = det;
1348 1312
1349 if (det & SND_JACK_MICROPHONE) 1313 if (det & SND_JACK_MICROPHONE)
1350 pm860x_set_bits(codec->control_data, REG_MIC_DET, 1314 pm860x_set_bits(pm860x->i2c, REG_MIC_DET,
1351 MICDET_MASK, MICDET_MASK); 1315 MICDET_MASK, MICDET_MASK);
1352 1316
1353 /* sync status */ 1317 /* sync status */
@@ -1363,7 +1327,7 @@ static int pm860x_probe(struct snd_soc_codec *codec)
1363 1327
1364 pm860x->codec = codec; 1328 pm860x->codec = codec;
1365 1329
1366 codec->control_data = pm860x->i2c; 1330 codec->control_data = pm860x->regmap;
1367 1331
1368 for (i = 0; i < 4; i++) { 1332 for (i = 0; i < 4; i++) {
1369 ret = request_threaded_irq(pm860x->irq[i], NULL, 1333 ret = request_threaded_irq(pm860x->irq[i], NULL,
@@ -1377,14 +1341,6 @@ static int pm860x_probe(struct snd_soc_codec *codec)
1377 1341
1378 pm860x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1342 pm860x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1379 1343
1380 ret = pm860x_bulk_read(codec->control_data, REG_CACHE_BASE,
1381 REG_CACHE_SIZE, codec->reg_cache);
1382 if (ret < 0) {
1383 dev_err(codec->dev, "Failed to fill register cache: %d\n",
1384 ret);
1385 goto out;
1386 }
1387
1388 return 0; 1344 return 0;
1389 1345
1390out: 1346out:
@@ -1407,10 +1363,6 @@ static int pm860x_remove(struct snd_soc_codec *codec)
1407static struct snd_soc_codec_driver soc_codec_dev_pm860x = { 1363static struct snd_soc_codec_driver soc_codec_dev_pm860x = {
1408 .probe = pm860x_probe, 1364 .probe = pm860x_probe,
1409 .remove = pm860x_remove, 1365 .remove = pm860x_remove,
1410 .read = pm860x_read_reg_cache,
1411 .write = pm860x_write_reg_cache,
1412 .reg_cache_size = REG_CACHE_SIZE,
1413 .reg_word_size = sizeof(u8),
1414 .set_bias_level = pm860x_set_bias_level, 1366 .set_bias_level = pm860x_set_bias_level,
1415 1367
1416 .controls = pm860x_snd_controls, 1368 .controls = pm860x_snd_controls,
@@ -1436,6 +1388,8 @@ static int pm860x_codec_probe(struct platform_device *pdev)
1436 pm860x->chip = chip; 1388 pm860x->chip = chip;
1437 pm860x->i2c = (chip->id == CHIP_PM8607) ? chip->client 1389 pm860x->i2c = (chip->id == CHIP_PM8607) ? chip->client
1438 : chip->companion; 1390 : chip->companion;
1391 pm860x->regmap = (chip->id == CHIP_PM8607) ? chip->regmap
1392 : chip->regmap_companion;
1439 platform_set_drvdata(pdev, pm860x); 1393 platform_set_drvdata(pdev, pm860x);
1440 1394
1441 for (i = 0; i < 4; i++) { 1395 for (i = 0; i < 4; i++) {
diff --git a/sound/soc/codecs/88pm860x-codec.h b/sound/soc/codecs/88pm860x-codec.h
index 3364ba4a3607..f7282f4f4a79 100644
--- a/sound/soc/codecs/88pm860x-codec.h
+++ b/sound/soc/codecs/88pm860x-codec.h
@@ -12,67 +12,66 @@
12#ifndef __88PM860X_H 12#ifndef __88PM860X_H
13#define __88PM860X_H 13#define __88PM860X_H
14 14
15/* The offset of these registers are 0xb0 */ 15#define PM860X_PCM_IFACE_1 0xb0
16#define PM860X_PCM_IFACE_1 0x00 16#define PM860X_PCM_IFACE_2 0xb1
17#define PM860X_PCM_IFACE_2 0x01 17#define PM860X_PCM_IFACE_3 0xb2
18#define PM860X_PCM_IFACE_3 0x02 18#define PM860X_PCM_RATE 0xb3
19#define PM860X_PCM_RATE 0x03 19#define PM860X_EC_PATH 0xb4
20#define PM860X_EC_PATH 0x04 20#define PM860X_SIDETONE_L_GAIN 0xb5
21#define PM860X_SIDETONE_L_GAIN 0x05 21#define PM860X_SIDETONE_R_GAIN 0xb6
22#define PM860X_SIDETONE_R_GAIN 0x06 22#define PM860X_SIDETONE_SHIFT 0xb7
23#define PM860X_SIDETONE_SHIFT 0x07 23#define PM860X_ADC_OFFSET_1 0xb8
24#define PM860X_ADC_OFFSET_1 0x08 24#define PM860X_ADC_OFFSET_2 0xb9
25#define PM860X_ADC_OFFSET_2 0x09 25#define PM860X_DMIC_DELAY 0xba
26#define PM860X_DMIC_DELAY 0x0a
27 26
28#define PM860X_I2S_IFACE_1 0x0b 27#define PM860X_I2S_IFACE_1 0xbb
29#define PM860X_I2S_IFACE_2 0x0c 28#define PM860X_I2S_IFACE_2 0xbc
30#define PM860X_I2S_IFACE_3 0x0d 29#define PM860X_I2S_IFACE_3 0xbd
31#define PM860X_I2S_IFACE_4 0x0e 30#define PM860X_I2S_IFACE_4 0xbe
32#define PM860X_EQUALIZER_N0_1 0x0f 31#define PM860X_EQUALIZER_N0_1 0xbf
33#define PM860X_EQUALIZER_N0_2 0x10 32#define PM860X_EQUALIZER_N0_2 0xc0
34#define PM860X_EQUALIZER_N1_1 0x11 33#define PM860X_EQUALIZER_N1_1 0xc1
35#define PM860X_EQUALIZER_N1_2 0x12 34#define PM860X_EQUALIZER_N1_2 0xc2
36#define PM860X_EQUALIZER_D1_1 0x13 35#define PM860X_EQUALIZER_D1_1 0xc3
37#define PM860X_EQUALIZER_D1_2 0x14 36#define PM860X_EQUALIZER_D1_2 0xc4
38#define PM860X_LOFI_GAIN_LEFT 0x15 37#define PM860X_LOFI_GAIN_LEFT 0xc5
39#define PM860X_LOFI_GAIN_RIGHT 0x16 38#define PM860X_LOFI_GAIN_RIGHT 0xc6
40#define PM860X_HIFIL_GAIN_LEFT 0x17 39#define PM860X_HIFIL_GAIN_LEFT 0xc7
41#define PM860X_HIFIL_GAIN_RIGHT 0x18 40#define PM860X_HIFIL_GAIN_RIGHT 0xc8
42#define PM860X_HIFIR_GAIN_LEFT 0x19 41#define PM860X_HIFIR_GAIN_LEFT 0xc9
43#define PM860X_HIFIR_GAIN_RIGHT 0x1a 42#define PM860X_HIFIR_GAIN_RIGHT 0xca
44#define PM860X_DAC_OFFSET 0x1b 43#define PM860X_DAC_OFFSET 0xcb
45#define PM860X_OFFSET_LEFT_1 0x1c 44#define PM860X_OFFSET_LEFT_1 0xcc
46#define PM860X_OFFSET_LEFT_2 0x1d 45#define PM860X_OFFSET_LEFT_2 0xcd
47#define PM860X_OFFSET_RIGHT_1 0x1e 46#define PM860X_OFFSET_RIGHT_1 0xce
48#define PM860X_OFFSET_RIGHT_2 0x1f 47#define PM860X_OFFSET_RIGHT_2 0xcf
49#define PM860X_ADC_ANA_1 0x20 48#define PM860X_ADC_ANA_1 0xd0
50#define PM860X_ADC_ANA_2 0x21 49#define PM860X_ADC_ANA_2 0xd1
51#define PM860X_ADC_ANA_3 0x22 50#define PM860X_ADC_ANA_3 0xd2
52#define PM860X_ADC_ANA_4 0x23 51#define PM860X_ADC_ANA_4 0xd3
53#define PM860X_ANA_TO_ANA 0x24 52#define PM860X_ANA_TO_ANA 0xd4
54#define PM860X_HS1_CTRL 0x25 53#define PM860X_HS1_CTRL 0xd5
55#define PM860X_HS2_CTRL 0x26 54#define PM860X_HS2_CTRL 0xd6
56#define PM860X_LO1_CTRL 0x27 55#define PM860X_LO1_CTRL 0xd7
57#define PM860X_LO2_CTRL 0x28 56#define PM860X_LO2_CTRL 0xd8
58#define PM860X_EAR_CTRL_1 0x29 57#define PM860X_EAR_CTRL_1 0xd9
59#define PM860X_EAR_CTRL_2 0x2a 58#define PM860X_EAR_CTRL_2 0xda
60#define PM860X_AUDIO_SUPPLIES_1 0x2b 59#define PM860X_AUDIO_SUPPLIES_1 0xdb
61#define PM860X_AUDIO_SUPPLIES_2 0x2c 60#define PM860X_AUDIO_SUPPLIES_2 0xdc
62#define PM860X_ADC_EN_1 0x2d 61#define PM860X_ADC_EN_1 0xdd
63#define PM860X_ADC_EN_2 0x2e 62#define PM860X_ADC_EN_2 0xde
64#define PM860X_DAC_EN_1 0x2f 63#define PM860X_DAC_EN_1 0xdf
65#define PM860X_DAC_EN_2 0x31 64#define PM860X_DAC_EN_2 0xe1
66#define PM860X_AUDIO_CAL_1 0x32 65#define PM860X_AUDIO_CAL_1 0xe2
67#define PM860X_AUDIO_CAL_2 0x33 66#define PM860X_AUDIO_CAL_2 0xe3
68#define PM860X_AUDIO_CAL_3 0x34 67#define PM860X_AUDIO_CAL_3 0xe4
69#define PM860X_AUDIO_CAL_4 0x35 68#define PM860X_AUDIO_CAL_4 0xe5
70#define PM860X_AUDIO_CAL_5 0x36 69#define PM860X_AUDIO_CAL_5 0xe6
71#define PM860X_ANA_INPUT_SEL_1 0x37 70#define PM860X_ANA_INPUT_SEL_1 0xe7
72#define PM860X_ANA_INPUT_SEL_2 0x38 71#define PM860X_ANA_INPUT_SEL_2 0xe8
73 72
74#define PM860X_PCM_IFACE_4 0x39 73#define PM860X_PCM_IFACE_4 0xe9
75#define PM860X_I2S_IFACE_5 0x3a 74#define PM860X_I2S_IFACE_5 0xea
76 75
77#define PM860X_SHORTS 0x3b 76#define PM860X_SHORTS 0x3b
78#define PM860X_PLL_ADJ_1 0x3c 77#define PM860X_PLL_ADJ_1 0x3c
diff --git a/sound/soc/codecs/ab8500-codec.c b/sound/soc/codecs/ab8500-codec.c
index b8ba0adacfce..21ae8d4fdbfb 100644
--- a/sound/soc/codecs/ab8500-codec.c
+++ b/sound/soc/codecs/ab8500-codec.c
@@ -126,6 +126,8 @@ struct ab8500_codec_drvdata_dbg {
126 126
127/* Private data for AB8500 device-driver */ 127/* Private data for AB8500 device-driver */
128struct ab8500_codec_drvdata { 128struct ab8500_codec_drvdata {
129 struct regmap *regmap;
130
129 /* Sidetone */ 131 /* Sidetone */
130 long *sid_fir_values; 132 long *sid_fir_values;
131 enum sid_state sid_status; 133 enum sid_state sid_status;
@@ -166,49 +168,35 @@ static inline const char *amic_type_str(enum amic_type type)
166 */ 168 */
167 169
168/* Read a register from the audio-bank of AB8500 */ 170/* Read a register from the audio-bank of AB8500 */
169static unsigned int ab8500_codec_read_reg(struct snd_soc_codec *codec, 171static int ab8500_codec_read_reg(void *context, unsigned int reg,
170 unsigned int reg) 172 unsigned int *value)
171{ 173{
174 struct device *dev = context;
172 int status; 175 int status;
173 unsigned int value = 0;
174 176
175 u8 value8; 177 u8 value8;
176 status = abx500_get_register_interruptible(codec->dev, AB8500_AUDIO, 178 status = abx500_get_register_interruptible(dev, AB8500_AUDIO,
177 reg, &value8); 179 reg, &value8);
178 if (status < 0) { 180 *value = (unsigned int)value8;
179 dev_err(codec->dev,
180 "%s: ERROR: Register (0x%02x:0x%02x) read failed (%d).\n",
181 __func__, (u8)AB8500_AUDIO, (u8)reg, status);
182 } else {
183 dev_dbg(codec->dev,
184 "%s: Read 0x%02x from register 0x%02x:0x%02x\n",
185 __func__, value8, (u8)AB8500_AUDIO, (u8)reg);
186 value = (unsigned int)value8;
187 }
188 181
189 return value; 182 return status;
190} 183}
191 184
192/* Write to a register in the audio-bank of AB8500 */ 185/* Write to a register in the audio-bank of AB8500 */
193static int ab8500_codec_write_reg(struct snd_soc_codec *codec, 186static int ab8500_codec_write_reg(void *context, unsigned int reg,
194 unsigned int reg, unsigned int value) 187 unsigned int value)
195{ 188{
196 int status; 189 struct device *dev = context;
197
198 status = abx500_set_register_interruptible(codec->dev, AB8500_AUDIO,
199 reg, value);
200 if (status < 0)
201 dev_err(codec->dev,
202 "%s: ERROR: Register (%02x:%02x) write failed (%d).\n",
203 __func__, (u8)AB8500_AUDIO, (u8)reg, status);
204 else
205 dev_dbg(codec->dev,
206 "%s: Wrote 0x%02x into register %02x:%02x\n",
207 __func__, (u8)value, (u8)AB8500_AUDIO, (u8)reg);
208 190
209 return status; 191 return abx500_set_register_interruptible(dev, AB8500_AUDIO,
192 reg, value);
210} 193}
211 194
195static const struct regmap_config ab8500_codec_regmap = {
196 .reg_read = ab8500_codec_read_reg,
197 .reg_write = ab8500_codec_write_reg,
198};
199
212/* 200/*
213 * Controls - DAPM 201 * Controls - DAPM
214 */ 202 */
@@ -1225,13 +1213,18 @@ static int anc_status_control_put(struct snd_kcontrol *kcontrol,
1225 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev); 1213 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
1226 struct device *dev = codec->dev; 1214 struct device *dev = codec->dev;
1227 bool apply_fir, apply_iir; 1215 bool apply_fir, apply_iir;
1228 int req, status; 1216 unsigned int req;
1217 int status;
1229 1218
1230 dev_dbg(dev, "%s: Enter.\n", __func__); 1219 dev_dbg(dev, "%s: Enter.\n", __func__);
1231 1220
1232 mutex_lock(&drvdata->anc_lock); 1221 mutex_lock(&drvdata->anc_lock);
1233 1222
1234 req = ucontrol->value.integer.value[0]; 1223 req = ucontrol->value.integer.value[0];
1224 if (req >= ARRAY_SIZE(enum_anc_state)) {
1225 status = -EINVAL;
1226 goto cleanup;
1227 }
1235 if (req != ANC_APPLY_FIR_IIR && req != ANC_APPLY_FIR && 1228 if (req != ANC_APPLY_FIR_IIR && req != ANC_APPLY_FIR &&
1236 req != ANC_APPLY_IIR) { 1229 req != ANC_APPLY_IIR) {
1237 dev_err(dev, "%s: ERROR: Unsupported status to set '%s'!\n", 1230 dev_err(dev, "%s: ERROR: Unsupported status to set '%s'!\n",
@@ -2307,17 +2300,17 @@ static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
2307 case 0: 2300 case 0:
2308 break; 2301 break;
2309 case 1: 2302 case 1:
2310 slot = find_first_bit((unsigned long *)&tx_mask, 32); 2303 slot = ffs(tx_mask);
2311 snd_soc_update_bits(codec, AB8500_DASLOTCONF1, mask, slot); 2304 snd_soc_update_bits(codec, AB8500_DASLOTCONF1, mask, slot);
2312 snd_soc_update_bits(codec, AB8500_DASLOTCONF3, mask, slot); 2305 snd_soc_update_bits(codec, AB8500_DASLOTCONF3, mask, slot);
2313 snd_soc_update_bits(codec, AB8500_DASLOTCONF2, mask, slot); 2306 snd_soc_update_bits(codec, AB8500_DASLOTCONF2, mask, slot);
2314 snd_soc_update_bits(codec, AB8500_DASLOTCONF4, mask, slot); 2307 snd_soc_update_bits(codec, AB8500_DASLOTCONF4, mask, slot);
2315 break; 2308 break;
2316 case 2: 2309 case 2:
2317 slot = find_first_bit((unsigned long *)&tx_mask, 32); 2310 slot = ffs(tx_mask);
2318 snd_soc_update_bits(codec, AB8500_DASLOTCONF1, mask, slot); 2311 snd_soc_update_bits(codec, AB8500_DASLOTCONF1, mask, slot);
2319 snd_soc_update_bits(codec, AB8500_DASLOTCONF3, mask, slot); 2312 snd_soc_update_bits(codec, AB8500_DASLOTCONF3, mask, slot);
2320 slot = find_next_bit((unsigned long *)&tx_mask, 32, slot + 1); 2313 slot = fls(tx_mask);
2321 snd_soc_update_bits(codec, AB8500_DASLOTCONF2, mask, slot); 2314 snd_soc_update_bits(codec, AB8500_DASLOTCONF2, mask, slot);
2322 snd_soc_update_bits(codec, AB8500_DASLOTCONF4, mask, slot); 2315 snd_soc_update_bits(codec, AB8500_DASLOTCONF4, mask, slot);
2323 break; 2316 break;
@@ -2348,18 +2341,18 @@ static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
2348 case 0: 2341 case 0:
2349 break; 2342 break;
2350 case 1: 2343 case 1:
2351 slot = find_first_bit((unsigned long *)&rx_mask, 32); 2344 slot = ffs(rx_mask);
2352 snd_soc_update_bits(codec, AB8500_ADSLOTSEL(slot), 2345 snd_soc_update_bits(codec, AB8500_ADSLOTSEL(slot),
2353 AB8500_MASK_SLOT(slot), 2346 AB8500_MASK_SLOT(slot),
2354 AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot)); 2347 AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot));
2355 break; 2348 break;
2356 case 2: 2349 case 2:
2357 slot = find_first_bit((unsigned long *)&rx_mask, 32); 2350 slot = ffs(rx_mask);
2358 snd_soc_update_bits(codec, 2351 snd_soc_update_bits(codec,
2359 AB8500_ADSLOTSEL(slot), 2352 AB8500_ADSLOTSEL(slot),
2360 AB8500_MASK_SLOT(slot), 2353 AB8500_MASK_SLOT(slot),
2361 AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot)); 2354 AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot));
2362 slot = find_next_bit((unsigned long *)&rx_mask, 32, slot + 1); 2355 slot = fls(rx_mask);
2363 snd_soc_update_bits(codec, 2356 snd_soc_update_bits(codec,
2364 AB8500_ADSLOTSEL(slot), 2357 AB8500_ADSLOTSEL(slot),
2365 AB8500_MASK_SLOT(slot), 2358 AB8500_MASK_SLOT(slot),
@@ -2480,9 +2473,13 @@ static int ab8500_codec_probe(struct snd_soc_codec *codec)
2480 2473
2481 dev_dbg(dev, "%s: Enter.\n", __func__); 2474 dev_dbg(dev, "%s: Enter.\n", __func__);
2482 2475
2476 snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
2477
2483 /* Setup AB8500 according to board-settings */ 2478 /* Setup AB8500 according to board-settings */
2484 pdata = dev_get_platdata(dev->parent); 2479 pdata = dev_get_platdata(dev->parent);
2485 2480
2481 codec->control_data = drvdata->regmap;
2482
2486 if (np) { 2483 if (np) {
2487 if (!pdata) 2484 if (!pdata)
2488 pdata = devm_kzalloc(dev, 2485 pdata = devm_kzalloc(dev,
@@ -2527,12 +2524,10 @@ static int ab8500_codec_probe(struct snd_soc_codec *codec)
2527 } 2524 }
2528 2525
2529 /* Override HW-defaults */ 2526 /* Override HW-defaults */
2530 ab8500_codec_write_reg(codec, 2527 snd_soc_write(codec, AB8500_ANACONF5,
2531 AB8500_ANACONF5, 2528 BIT(AB8500_ANACONF5_HSAUTOEN));
2532 BIT(AB8500_ANACONF5_HSAUTOEN)); 2529 snd_soc_write(codec, AB8500_SHORTCIRCONF,
2533 ab8500_codec_write_reg(codec, 2530 BIT(AB8500_SHORTCIRCONF_HSZCDDIS));
2534 AB8500_SHORTCIRCONF,
2535 BIT(AB8500_SHORTCIRCONF_HSZCDDIS));
2536 2531
2537 /* Add filter controls */ 2532 /* Add filter controls */
2538 status = snd_soc_add_codec_controls(codec, ab8500_filter_controls, 2533 status = snd_soc_add_codec_controls(codec, ab8500_filter_controls,
@@ -2562,9 +2557,6 @@ static int ab8500_codec_probe(struct snd_soc_codec *codec)
2562 2557
2563static struct snd_soc_codec_driver ab8500_codec_driver = { 2558static struct snd_soc_codec_driver ab8500_codec_driver = {
2564 .probe = ab8500_codec_probe, 2559 .probe = ab8500_codec_probe,
2565 .read = ab8500_codec_read_reg,
2566 .write = ab8500_codec_write_reg,
2567 .reg_word_size = sizeof(u8),
2568 .controls = ab8500_ctrls, 2560 .controls = ab8500_ctrls,
2569 .num_controls = ARRAY_SIZE(ab8500_ctrls), 2561 .num_controls = ARRAY_SIZE(ab8500_ctrls),
2570 .dapm_widgets = ab8500_dapm_widgets, 2562 .dapm_widgets = ab8500_dapm_widgets,
@@ -2583,10 +2575,21 @@ static int ab8500_codec_driver_probe(struct platform_device *pdev)
2583 /* Create driver private-data struct */ 2575 /* Create driver private-data struct */
2584 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_codec_drvdata), 2576 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_codec_drvdata),
2585 GFP_KERNEL); 2577 GFP_KERNEL);
2578 if (!drvdata)
2579 return -ENOMEM;
2586 drvdata->sid_status = SID_UNCONFIGURED; 2580 drvdata->sid_status = SID_UNCONFIGURED;
2587 drvdata->anc_status = ANC_UNCONFIGURED; 2581 drvdata->anc_status = ANC_UNCONFIGURED;
2588 dev_set_drvdata(&pdev->dev, drvdata); 2582 dev_set_drvdata(&pdev->dev, drvdata);
2589 2583
2584 drvdata->regmap = devm_regmap_init(&pdev->dev, NULL, &pdev->dev,
2585 &ab8500_codec_regmap);
2586 if (IS_ERR(drvdata->regmap)) {
2587 status = PTR_ERR(drvdata->regmap);
2588 dev_err(&pdev->dev, "%s: Failed to allocate regmap: %d\n",
2589 __func__, status);
2590 return status;
2591 }
2592
2590 dev_dbg(&pdev->dev, "%s: Register codec.\n", __func__); 2593 dev_dbg(&pdev->dev, "%s: Register codec.\n", __func__);
2591 status = snd_soc_register_codec(&pdev->dev, &ab8500_codec_driver, 2594 status = snd_soc_register_codec(&pdev->dev, &ab8500_codec_driver,
2592 ab8500_codec_dai, 2595 ab8500_codec_dai,
@@ -2601,7 +2604,7 @@ static int ab8500_codec_driver_probe(struct platform_device *pdev)
2601 2604
2602static int ab8500_codec_driver_remove(struct platform_device *pdev) 2605static int ab8500_codec_driver_remove(struct platform_device *pdev)
2603{ 2606{
2604 dev_info(&pdev->dev, "%s Enter.\n", __func__); 2607 dev_dbg(&pdev->dev, "%s Enter.\n", __func__);
2605 2608
2606 snd_soc_unregister_codec(&pdev->dev); 2609 snd_soc_unregister_codec(&pdev->dev);
2607 2610
diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
index 1aa10ddf3a61..59654b1e7f3f 100644
--- a/sound/soc/codecs/adau1373.c
+++ b/sound/soc/codecs/adau1373.c
@@ -32,6 +32,7 @@ struct adau1373_dai {
32}; 32};
33 33
34struct adau1373 { 34struct adau1373 {
35 struct regmap *regmap;
35 struct adau1373_dai dais[3]; 36 struct adau1373_dai dais[3];
36}; 37};
37 38
@@ -73,7 +74,6 @@ struct adau1373 {
73#define ADAU1373_PLL_CTRL4(x) (0x2c + (x) * 7) 74#define ADAU1373_PLL_CTRL4(x) (0x2c + (x) * 7)
74#define ADAU1373_PLL_CTRL5(x) (0x2d + (x) * 7) 75#define ADAU1373_PLL_CTRL5(x) (0x2d + (x) * 7)
75#define ADAU1373_PLL_CTRL6(x) (0x2e + (x) * 7) 76#define ADAU1373_PLL_CTRL6(x) (0x2e + (x) * 7)
76#define ADAU1373_PLL_CTRL7(x) (0x2f + (x) * 7)
77#define ADAU1373_HEADDECT 0x36 77#define ADAU1373_HEADDECT 0x36
78#define ADAU1373_ADC_DAC_STATUS 0x37 78#define ADAU1373_ADC_DAC_STATUS 0x37
79#define ADAU1373_ADC_CTRL 0x3c 79#define ADAU1373_ADC_CTRL 0x3c
@@ -152,37 +152,172 @@ struct adau1373 {
152#define ADAU1373_EP_CTRL_MICBIAS1_OFFSET 4 152#define ADAU1373_EP_CTRL_MICBIAS1_OFFSET 4
153#define ADAU1373_EP_CTRL_MICBIAS2_OFFSET 2 153#define ADAU1373_EP_CTRL_MICBIAS2_OFFSET 2
154 154
155static const uint8_t adau1373_default_regs[] = { 155static const struct reg_default adau1373_reg_defaults[] = {
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00 */ 156 { ADAU1373_INPUT_MODE, 0x00 },
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 157 { ADAU1373_AINL_CTRL(0), 0x00 },
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10 */ 158 { ADAU1373_AINR_CTRL(0), 0x00 },
159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 159 { ADAU1373_AINL_CTRL(1), 0x00 },
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20 */ 160 { ADAU1373_AINR_CTRL(1), 0x00 },
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 161 { ADAU1373_AINL_CTRL(2), 0x00 },
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* 0x30 */ 162 { ADAU1373_AINR_CTRL(2), 0x00 },
163 0x00, 0x00, 0x00, 0x80, 0x00, 0x01, 0x00, 0x00, 163 { ADAU1373_AINL_CTRL(3), 0x00 },
164 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x00, /* 0x40 */ 164 { ADAU1373_AINR_CTRL(3), 0x00 },
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 165 { ADAU1373_LLINE_OUT(0), 0x00 },
166 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, /* 0x50 */ 166 { ADAU1373_RLINE_OUT(0), 0x00 },
167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 167 { ADAU1373_LLINE_OUT(1), 0x00 },
168 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */ 168 { ADAU1373_RLINE_OUT(1), 0x00 },
169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 169 { ADAU1373_LSPK_OUT, 0x00 },
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 */ 170 { ADAU1373_RSPK_OUT, 0x00 },
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 171 { ADAU1373_LHP_OUT, 0x00 },
172 0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0x80 */ 172 { ADAU1373_RHP_OUT, 0x00 },
173 0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00, 173 { ADAU1373_ADC_GAIN, 0x00 },
174 0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0x90 */ 174 { ADAU1373_LADC_MIXER, 0x00 },
175 0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00, 175 { ADAU1373_RADC_MIXER, 0x00 },
176 0x78, 0x18, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, /* 0xa0 */ 176 { ADAU1373_LLINE1_MIX, 0x00 },
177 0x00, 0xc0, 0x88, 0x7a, 0xdf, 0x20, 0x00, 0x00, 177 { ADAU1373_RLINE1_MIX, 0x00 },
178 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0 */ 178 { ADAU1373_LLINE2_MIX, 0x00 },
179 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 179 { ADAU1373_RLINE2_MIX, 0x00 },
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */ 180 { ADAU1373_LSPK_MIX, 0x00 },
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 181 { ADAU1373_RSPK_MIX, 0x00 },
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 */ 182 { ADAU1373_LHP_MIX, 0x00 },
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 183 { ADAU1373_RHP_MIX, 0x00 },
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, /* 0xe0 */ 184 { ADAU1373_EP_MIX, 0x00 },
185 0x00, 0x1f, 0x0f, 0x00, 0x00, 185 { ADAU1373_HP_CTRL, 0x00 },
186 { ADAU1373_HP_CTRL2, 0x00 },
187 { ADAU1373_LS_CTRL, 0x00 },
188 { ADAU1373_EP_CTRL, 0x00 },
189 { ADAU1373_MICBIAS_CTRL1, 0x00 },
190 { ADAU1373_MICBIAS_CTRL2, 0x00 },
191 { ADAU1373_OUTPUT_CTRL, 0x00 },
192 { ADAU1373_PWDN_CTRL1, 0x00 },
193 { ADAU1373_PWDN_CTRL2, 0x00 },
194 { ADAU1373_PWDN_CTRL3, 0x00 },
195 { ADAU1373_DPLL_CTRL(0), 0x00 },
196 { ADAU1373_PLL_CTRL1(0), 0x00 },
197 { ADAU1373_PLL_CTRL2(0), 0x00 },
198 { ADAU1373_PLL_CTRL3(0), 0x00 },
199 { ADAU1373_PLL_CTRL4(0), 0x00 },
200 { ADAU1373_PLL_CTRL5(0), 0x00 },
201 { ADAU1373_PLL_CTRL6(0), 0x02 },
202 { ADAU1373_DPLL_CTRL(1), 0x00 },
203 { ADAU1373_PLL_CTRL1(1), 0x00 },
204 { ADAU1373_PLL_CTRL2(1), 0x00 },
205 { ADAU1373_PLL_CTRL3(1), 0x00 },
206 { ADAU1373_PLL_CTRL4(1), 0x00 },
207 { ADAU1373_PLL_CTRL5(1), 0x00 },
208 { ADAU1373_PLL_CTRL6(1), 0x02 },
209 { ADAU1373_HEADDECT, 0x00 },
210 { ADAU1373_ADC_CTRL, 0x00 },
211 { ADAU1373_CLK_SRC_DIV(0), 0x00 },
212 { ADAU1373_CLK_SRC_DIV(1), 0x00 },
213 { ADAU1373_DAI(0), 0x0a },
214 { ADAU1373_DAI(1), 0x0a },
215 { ADAU1373_DAI(2), 0x0a },
216 { ADAU1373_BCLKDIV(0), 0x00 },
217 { ADAU1373_BCLKDIV(1), 0x00 },
218 { ADAU1373_BCLKDIV(2), 0x00 },
219 { ADAU1373_SRC_RATIOA(0), 0x00 },
220 { ADAU1373_SRC_RATIOB(0), 0x00 },
221 { ADAU1373_SRC_RATIOA(1), 0x00 },
222 { ADAU1373_SRC_RATIOB(1), 0x00 },
223 { ADAU1373_SRC_RATIOA(2), 0x00 },
224 { ADAU1373_SRC_RATIOB(2), 0x00 },
225 { ADAU1373_DEEMP_CTRL, 0x00 },
226 { ADAU1373_SRC_DAI_CTRL(0), 0x08 },
227 { ADAU1373_SRC_DAI_CTRL(1), 0x08 },
228 { ADAU1373_SRC_DAI_CTRL(2), 0x08 },
229 { ADAU1373_DIN_MIX_CTRL(0), 0x00 },
230 { ADAU1373_DIN_MIX_CTRL(1), 0x00 },
231 { ADAU1373_DIN_MIX_CTRL(2), 0x00 },
232 { ADAU1373_DIN_MIX_CTRL(3), 0x00 },
233 { ADAU1373_DIN_MIX_CTRL(4), 0x00 },
234 { ADAU1373_DOUT_MIX_CTRL(0), 0x00 },
235 { ADAU1373_DOUT_MIX_CTRL(1), 0x00 },
236 { ADAU1373_DOUT_MIX_CTRL(2), 0x00 },
237 { ADAU1373_DOUT_MIX_CTRL(3), 0x00 },
238 { ADAU1373_DOUT_MIX_CTRL(4), 0x00 },
239 { ADAU1373_DAI_PBL_VOL(0), 0x00 },
240 { ADAU1373_DAI_PBR_VOL(0), 0x00 },
241 { ADAU1373_DAI_PBL_VOL(1), 0x00 },
242 { ADAU1373_DAI_PBR_VOL(1), 0x00 },
243 { ADAU1373_DAI_PBL_VOL(2), 0x00 },
244 { ADAU1373_DAI_PBR_VOL(2), 0x00 },
245 { ADAU1373_DAI_RECL_VOL(0), 0x00 },
246 { ADAU1373_DAI_RECR_VOL(0), 0x00 },
247 { ADAU1373_DAI_RECL_VOL(1), 0x00 },
248 { ADAU1373_DAI_RECR_VOL(1), 0x00 },
249 { ADAU1373_DAI_RECL_VOL(2), 0x00 },
250 { ADAU1373_DAI_RECR_VOL(2), 0x00 },
251 { ADAU1373_DAC1_PBL_VOL, 0x00 },
252 { ADAU1373_DAC1_PBR_VOL, 0x00 },
253 { ADAU1373_DAC2_PBL_VOL, 0x00 },
254 { ADAU1373_DAC2_PBR_VOL, 0x00 },
255 { ADAU1373_ADC_RECL_VOL, 0x00 },
256 { ADAU1373_ADC_RECR_VOL, 0x00 },
257 { ADAU1373_DMIC_RECL_VOL, 0x00 },
258 { ADAU1373_DMIC_RECR_VOL, 0x00 },
259 { ADAU1373_VOL_GAIN1, 0x00 },
260 { ADAU1373_VOL_GAIN2, 0x00 },
261 { ADAU1373_VOL_GAIN3, 0x00 },
262 { ADAU1373_HPF_CTRL, 0x00 },
263 { ADAU1373_BASS1, 0x00 },
264 { ADAU1373_BASS2, 0x00 },
265 { ADAU1373_DRC(0) + 0x0, 0x78 },
266 { ADAU1373_DRC(0) + 0x1, 0x18 },
267 { ADAU1373_DRC(0) + 0x2, 0x00 },
268 { ADAU1373_DRC(0) + 0x3, 0x00 },
269 { ADAU1373_DRC(0) + 0x4, 0x00 },
270 { ADAU1373_DRC(0) + 0x5, 0xc0 },
271 { ADAU1373_DRC(0) + 0x6, 0x00 },
272 { ADAU1373_DRC(0) + 0x7, 0x00 },
273 { ADAU1373_DRC(0) + 0x8, 0x00 },
274 { ADAU1373_DRC(0) + 0x9, 0xc0 },
275 { ADAU1373_DRC(0) + 0xa, 0x88 },
276 { ADAU1373_DRC(0) + 0xb, 0x7a },
277 { ADAU1373_DRC(0) + 0xc, 0xdf },
278 { ADAU1373_DRC(0) + 0xd, 0x20 },
279 { ADAU1373_DRC(0) + 0xe, 0x00 },
280 { ADAU1373_DRC(0) + 0xf, 0x00 },
281 { ADAU1373_DRC(1) + 0x0, 0x78 },
282 { ADAU1373_DRC(1) + 0x1, 0x18 },
283 { ADAU1373_DRC(1) + 0x2, 0x00 },
284 { ADAU1373_DRC(1) + 0x3, 0x00 },
285 { ADAU1373_DRC(1) + 0x4, 0x00 },
286 { ADAU1373_DRC(1) + 0x5, 0xc0 },
287 { ADAU1373_DRC(1) + 0x6, 0x00 },
288 { ADAU1373_DRC(1) + 0x7, 0x00 },
289 { ADAU1373_DRC(1) + 0x8, 0x00 },
290 { ADAU1373_DRC(1) + 0x9, 0xc0 },
291 { ADAU1373_DRC(1) + 0xa, 0x88 },
292 { ADAU1373_DRC(1) + 0xb, 0x7a },
293 { ADAU1373_DRC(1) + 0xc, 0xdf },
294 { ADAU1373_DRC(1) + 0xd, 0x20 },
295 { ADAU1373_DRC(1) + 0xe, 0x00 },
296 { ADAU1373_DRC(1) + 0xf, 0x00 },
297 { ADAU1373_DRC(2) + 0x0, 0x78 },
298 { ADAU1373_DRC(2) + 0x1, 0x18 },
299 { ADAU1373_DRC(2) + 0x2, 0x00 },
300 { ADAU1373_DRC(2) + 0x3, 0x00 },
301 { ADAU1373_DRC(2) + 0x4, 0x00 },
302 { ADAU1373_DRC(2) + 0x5, 0xc0 },
303 { ADAU1373_DRC(2) + 0x6, 0x00 },
304 { ADAU1373_DRC(2) + 0x7, 0x00 },
305 { ADAU1373_DRC(2) + 0x8, 0x00 },
306 { ADAU1373_DRC(2) + 0x9, 0xc0 },
307 { ADAU1373_DRC(2) + 0xa, 0x88 },
308 { ADAU1373_DRC(2) + 0xb, 0x7a },
309 { ADAU1373_DRC(2) + 0xc, 0xdf },
310 { ADAU1373_DRC(2) + 0xd, 0x20 },
311 { ADAU1373_DRC(2) + 0xe, 0x00 },
312 { ADAU1373_DRC(2) + 0xf, 0x00 },
313 { ADAU1373_3D_CTRL1, 0x00 },
314 { ADAU1373_3D_CTRL2, 0x00 },
315 { ADAU1373_FDSP_SEL1, 0x00 },
316 { ADAU1373_FDSP_SEL2, 0x00 },
317 { ADAU1373_FDSP_SEL2, 0x00 },
318 { ADAU1373_FDSP_SEL4, 0x00 },
319 { ADAU1373_DIGMICCTRL, 0x00 },
320 { ADAU1373_DIGEN, 0x00 },
186}; 321};
187 322
188static const unsigned int adau1373_out_tlv[] = { 323static const unsigned int adau1373_out_tlv[] = {
@@ -418,6 +553,7 @@ static int adau1373_pll_event(struct snd_soc_dapm_widget *w,
418 struct snd_kcontrol *kcontrol, int event) 553 struct snd_kcontrol *kcontrol, int event)
419{ 554{
420 struct snd_soc_codec *codec = w->codec; 555 struct snd_soc_codec *codec = w->codec;
556 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
421 unsigned int pll_id = w->name[3] - '1'; 557 unsigned int pll_id = w->name[3] - '1';
422 unsigned int val; 558 unsigned int val;
423 559
@@ -426,7 +562,7 @@ static int adau1373_pll_event(struct snd_soc_dapm_widget *w,
426 else 562 else
427 val = 0; 563 val = 0;
428 564
429 snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id), 565 regmap_update_bits(adau1373->regmap, ADAU1373_PLL_CTRL6(pll_id),
430 ADAU1373_PLL_CTRL6_PLL_EN, val); 566 ADAU1373_PLL_CTRL6_PLL_EN, val);
431 567
432 if (SND_SOC_DAPM_EVENT_ON(event)) 568 if (SND_SOC_DAPM_EVENT_ON(event))
@@ -938,7 +1074,7 @@ static int adau1373_hw_params(struct snd_pcm_substream *substream,
938 1074
939 adau1373_dai->enable_src = (div != 0); 1075 adau1373_dai->enable_src = (div != 0);
940 1076
941 snd_soc_update_bits(codec, ADAU1373_BCLKDIV(dai->id), 1077 regmap_update_bits(adau1373->regmap, ADAU1373_BCLKDIV(dai->id),
942 ADAU1373_BCLKDIV_SR_MASK | ADAU1373_BCLKDIV_BCLK_MASK, 1078 ADAU1373_BCLKDIV_SR_MASK | ADAU1373_BCLKDIV_BCLK_MASK,
943 (div << 2) | ADAU1373_BCLKDIV_64); 1079 (div << 2) | ADAU1373_BCLKDIV_64);
944 1080
@@ -959,7 +1095,7 @@ static int adau1373_hw_params(struct snd_pcm_substream *substream,
959 return -EINVAL; 1095 return -EINVAL;
960 } 1096 }
961 1097
962 return snd_soc_update_bits(codec, ADAU1373_DAI(dai->id), 1098 return regmap_update_bits(adau1373->regmap, ADAU1373_DAI(dai->id),
963 ADAU1373_DAI_WLEN_MASK, ctrl); 1099 ADAU1373_DAI_WLEN_MASK, ctrl);
964} 1100}
965 1101
@@ -1016,7 +1152,7 @@ static int adau1373_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1016 return -EINVAL; 1152 return -EINVAL;
1017 } 1153 }
1018 1154
1019 snd_soc_update_bits(codec, ADAU1373_DAI(dai->id), 1155 regmap_update_bits(adau1373->regmap, ADAU1373_DAI(dai->id),
1020 ~ADAU1373_DAI_WLEN_MASK, ctrl); 1156 ~ADAU1373_DAI_WLEN_MASK, ctrl);
1021 1157
1022 return 0; 1158 return 0;
@@ -1039,7 +1175,7 @@ static int adau1373_set_dai_sysclk(struct snd_soc_dai *dai,
1039 adau1373_dai->sysclk = freq; 1175 adau1373_dai->sysclk = freq;
1040 adau1373_dai->clk_src = clk_id; 1176 adau1373_dai->clk_src = clk_id;
1041 1177
1042 snd_soc_update_bits(dai->codec, ADAU1373_BCLKDIV(dai->id), 1178 regmap_update_bits(adau1373->regmap, ADAU1373_BCLKDIV(dai->id),
1043 ADAU1373_BCLKDIV_SOURCE, clk_id << 5); 1179 ADAU1373_BCLKDIV_SOURCE, clk_id << 5);
1044 1180
1045 return 0; 1181 return 0;
@@ -1120,6 +1256,7 @@ static struct snd_soc_dai_driver adau1373_dai_driver[] = {
1120static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id, 1256static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id,
1121 int source, unsigned int freq_in, unsigned int freq_out) 1257 int source, unsigned int freq_in, unsigned int freq_out)
1122{ 1258{
1259 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
1123 unsigned int dpll_div = 0; 1260 unsigned int dpll_div = 0;
1124 unsigned int x, r, n, m, i, j, mode; 1261 unsigned int x, r, n, m, i, j, mode;
1125 1262
@@ -1187,36 +1324,36 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id,
1187 1324
1188 if (dpll_div) { 1325 if (dpll_div) {
1189 dpll_div = 11 - dpll_div; 1326 dpll_div = 11 - dpll_div;
1190 snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id), 1327 regmap_update_bits(adau1373->regmap, ADAU1373_PLL_CTRL6(pll_id),
1191 ADAU1373_PLL_CTRL6_DPLL_BYPASS, 0); 1328 ADAU1373_PLL_CTRL6_DPLL_BYPASS, 0);
1192 } else { 1329 } else {
1193 snd_soc_update_bits(codec, ADAU1373_PLL_CTRL6(pll_id), 1330 regmap_update_bits(adau1373->regmap, ADAU1373_PLL_CTRL6(pll_id),
1194 ADAU1373_PLL_CTRL6_DPLL_BYPASS, 1331 ADAU1373_PLL_CTRL6_DPLL_BYPASS,
1195 ADAU1373_PLL_CTRL6_DPLL_BYPASS); 1332 ADAU1373_PLL_CTRL6_DPLL_BYPASS);
1196 } 1333 }
1197 1334
1198 snd_soc_write(codec, ADAU1373_DPLL_CTRL(pll_id), 1335 regmap_write(adau1373->regmap, ADAU1373_DPLL_CTRL(pll_id),
1199 (source << 4) | dpll_div); 1336 (source << 4) | dpll_div);
1200 snd_soc_write(codec, ADAU1373_PLL_CTRL1(pll_id), (m >> 8) & 0xff); 1337 regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL1(pll_id), (m >> 8) & 0xff);
1201 snd_soc_write(codec, ADAU1373_PLL_CTRL2(pll_id), m & 0xff); 1338 regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL2(pll_id), m & 0xff);
1202 snd_soc_write(codec, ADAU1373_PLL_CTRL3(pll_id), (n >> 8) & 0xff); 1339 regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL3(pll_id), (n >> 8) & 0xff);
1203 snd_soc_write(codec, ADAU1373_PLL_CTRL4(pll_id), n & 0xff); 1340 regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL4(pll_id), n & 0xff);
1204 snd_soc_write(codec, ADAU1373_PLL_CTRL5(pll_id), 1341 regmap_write(adau1373->regmap, ADAU1373_PLL_CTRL5(pll_id),
1205 (r << 3) | (x << 1) | mode); 1342 (r << 3) | (x << 1) | mode);
1206 1343
1207 /* Set sysclk to pll_rate / 4 */ 1344 /* Set sysclk to pll_rate / 4 */
1208 snd_soc_update_bits(codec, ADAU1373_CLK_SRC_DIV(pll_id), 0x3f, 0x09); 1345 regmap_update_bits(adau1373->regmap, ADAU1373_CLK_SRC_DIV(pll_id), 0x3f, 0x09);
1209 1346
1210 return 0; 1347 return 0;
1211} 1348}
1212 1349
1213static void adau1373_load_drc_settings(struct snd_soc_codec *codec, 1350static void adau1373_load_drc_settings(struct adau1373 *adau1373,
1214 unsigned int nr, uint8_t *drc) 1351 unsigned int nr, uint8_t *drc)
1215{ 1352{
1216 unsigned int i; 1353 unsigned int i;
1217 1354
1218 for (i = 0; i < ADAU1373_DRC_SIZE; ++i) 1355 for (i = 0; i < ADAU1373_DRC_SIZE; ++i)
1219 snd_soc_write(codec, ADAU1373_DRC(nr) + i, drc[i]); 1356 regmap_write(adau1373->regmap, ADAU1373_DRC(nr) + i, drc[i]);
1220} 1357}
1221 1358
1222static bool adau1373_valid_micbias(enum adau1373_micbias_voltage micbias) 1359static bool adau1373_valid_micbias(enum adau1373_micbias_voltage micbias)
@@ -1235,13 +1372,14 @@ static bool adau1373_valid_micbias(enum adau1373_micbias_voltage micbias)
1235 1372
1236static int adau1373_probe(struct snd_soc_codec *codec) 1373static int adau1373_probe(struct snd_soc_codec *codec)
1237{ 1374{
1375 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
1238 struct adau1373_platform_data *pdata = codec->dev->platform_data; 1376 struct adau1373_platform_data *pdata = codec->dev->platform_data;
1239 bool lineout_differential = false; 1377 bool lineout_differential = false;
1240 unsigned int val; 1378 unsigned int val;
1241 int ret; 1379 int ret;
1242 int i; 1380 int i;
1243 1381
1244 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 1382 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
1245 if (ret) { 1383 if (ret) {
1246 dev_err(codec->dev, "failed to set cache I/O: %d\n", ret); 1384 dev_err(codec->dev, "failed to set cache I/O: %d\n", ret);
1247 return ret; 1385 return ret;
@@ -1256,7 +1394,7 @@ static int adau1373_probe(struct snd_soc_codec *codec)
1256 return -EINVAL; 1394 return -EINVAL;
1257 1395
1258 for (i = 0; i < pdata->num_drc; ++i) { 1396 for (i = 0; i < pdata->num_drc; ++i) {
1259 adau1373_load_drc_settings(codec, i, 1397 adau1373_load_drc_settings(adau1373, i,
1260 pdata->drc_setting[i]); 1398 pdata->drc_setting[i]);
1261 } 1399 }
1262 1400
@@ -1268,18 +1406,18 @@ static int adau1373_probe(struct snd_soc_codec *codec)
1268 if (pdata->input_differential[i]) 1406 if (pdata->input_differential[i])
1269 val |= BIT(i); 1407 val |= BIT(i);
1270 } 1408 }
1271 snd_soc_write(codec, ADAU1373_INPUT_MODE, val); 1409 regmap_write(adau1373->regmap, ADAU1373_INPUT_MODE, val);
1272 1410
1273 val = 0; 1411 val = 0;
1274 if (pdata->lineout_differential) 1412 if (pdata->lineout_differential)
1275 val |= ADAU1373_OUTPUT_CTRL_LDIFF; 1413 val |= ADAU1373_OUTPUT_CTRL_LDIFF;
1276 if (pdata->lineout_ground_sense) 1414 if (pdata->lineout_ground_sense)
1277 val |= ADAU1373_OUTPUT_CTRL_LNFBEN; 1415 val |= ADAU1373_OUTPUT_CTRL_LNFBEN;
1278 snd_soc_write(codec, ADAU1373_OUTPUT_CTRL, val); 1416 regmap_write(adau1373->regmap, ADAU1373_OUTPUT_CTRL, val);
1279 1417
1280 lineout_differential = pdata->lineout_differential; 1418 lineout_differential = pdata->lineout_differential;
1281 1419
1282 snd_soc_write(codec, ADAU1373_EP_CTRL, 1420 regmap_write(adau1373->regmap, ADAU1373_EP_CTRL,
1283 (pdata->micbias1 << ADAU1373_EP_CTRL_MICBIAS1_OFFSET) | 1421 (pdata->micbias1 << ADAU1373_EP_CTRL_MICBIAS1_OFFSET) |
1284 (pdata->micbias2 << ADAU1373_EP_CTRL_MICBIAS2_OFFSET)); 1422 (pdata->micbias2 << ADAU1373_EP_CTRL_MICBIAS2_OFFSET));
1285 } 1423 }
@@ -1289,7 +1427,7 @@ static int adau1373_probe(struct snd_soc_codec *codec)
1289 ARRAY_SIZE(adau1373_lineout2_controls)); 1427 ARRAY_SIZE(adau1373_lineout2_controls));
1290 } 1428 }
1291 1429
1292 snd_soc_write(codec, ADAU1373_ADC_CTRL, 1430 regmap_write(adau1373->regmap, ADAU1373_ADC_CTRL,
1293 ADAU1373_ADC_CTRL_RESET_FORCE | ADAU1373_ADC_CTRL_PEAK_DETECT); 1431 ADAU1373_ADC_CTRL_RESET_FORCE | ADAU1373_ADC_CTRL_PEAK_DETECT);
1294 1432
1295 return 0; 1433 return 0;
@@ -1298,17 +1436,19 @@ static int adau1373_probe(struct snd_soc_codec *codec)
1298static int adau1373_set_bias_level(struct snd_soc_codec *codec, 1436static int adau1373_set_bias_level(struct snd_soc_codec *codec,
1299 enum snd_soc_bias_level level) 1437 enum snd_soc_bias_level level)
1300{ 1438{
1439 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
1440
1301 switch (level) { 1441 switch (level) {
1302 case SND_SOC_BIAS_ON: 1442 case SND_SOC_BIAS_ON:
1303 break; 1443 break;
1304 case SND_SOC_BIAS_PREPARE: 1444 case SND_SOC_BIAS_PREPARE:
1305 break; 1445 break;
1306 case SND_SOC_BIAS_STANDBY: 1446 case SND_SOC_BIAS_STANDBY:
1307 snd_soc_update_bits(codec, ADAU1373_PWDN_CTRL3, 1447 regmap_update_bits(adau1373->regmap, ADAU1373_PWDN_CTRL3,
1308 ADAU1373_PWDN_CTRL3_PWR_EN, ADAU1373_PWDN_CTRL3_PWR_EN); 1448 ADAU1373_PWDN_CTRL3_PWR_EN, ADAU1373_PWDN_CTRL3_PWR_EN);
1309 break; 1449 break;
1310 case SND_SOC_BIAS_OFF: 1450 case SND_SOC_BIAS_OFF:
1311 snd_soc_update_bits(codec, ADAU1373_PWDN_CTRL3, 1451 regmap_update_bits(adau1373->regmap, ADAU1373_PWDN_CTRL3,
1312 ADAU1373_PWDN_CTRL3_PWR_EN, 0); 1452 ADAU1373_PWDN_CTRL3_PWR_EN, 0);
1313 break; 1453 break;
1314 } 1454 }
@@ -1324,17 +1464,49 @@ static int adau1373_remove(struct snd_soc_codec *codec)
1324 1464
1325static int adau1373_suspend(struct snd_soc_codec *codec) 1465static int adau1373_suspend(struct snd_soc_codec *codec)
1326{ 1466{
1327 return adau1373_set_bias_level(codec, SND_SOC_BIAS_OFF); 1467 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
1468 int ret;
1469
1470 ret = adau1373_set_bias_level(codec, SND_SOC_BIAS_OFF);
1471 regcache_cache_only(adau1373->regmap, true);
1472
1473 return ret;
1328} 1474}
1329 1475
1330static int adau1373_resume(struct snd_soc_codec *codec) 1476static int adau1373_resume(struct snd_soc_codec *codec)
1331{ 1477{
1478 struct adau1373 *adau1373 = snd_soc_codec_get_drvdata(codec);
1479
1480 regcache_cache_only(adau1373->regmap, false);
1332 adau1373_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1481 adau1373_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1333 snd_soc_cache_sync(codec); 1482 regcache_sync(adau1373->regmap);
1334 1483
1335 return 0; 1484 return 0;
1336} 1485}
1337 1486
1487static bool adau1373_register_volatile(struct device *dev, unsigned int reg)
1488{
1489 switch (reg) {
1490 case ADAU1373_SOFT_RESET:
1491 case ADAU1373_ADC_DAC_STATUS:
1492 return true;
1493 default:
1494 return false;
1495 }
1496}
1497
1498static const struct regmap_config adau1373_regmap_config = {
1499 .val_bits = 8,
1500 .reg_bits = 8,
1501
1502 .volatile_reg = adau1373_register_volatile,
1503 .max_register = ADAU1373_SOFT_RESET,
1504
1505 .cache_type = REGCACHE_RBTREE,
1506 .reg_defaults = adau1373_reg_defaults,
1507 .num_reg_defaults = ARRAY_SIZE(adau1373_reg_defaults),
1508};
1509
1338static struct snd_soc_codec_driver adau1373_codec_driver = { 1510static struct snd_soc_codec_driver adau1373_codec_driver = {
1339 .probe = adau1373_probe, 1511 .probe = adau1373_probe,
1340 .remove = adau1373_remove, 1512 .remove = adau1373_remove,
@@ -1342,9 +1514,6 @@ static struct snd_soc_codec_driver adau1373_codec_driver = {
1342 .resume = adau1373_resume, 1514 .resume = adau1373_resume,
1343 .set_bias_level = adau1373_set_bias_level, 1515 .set_bias_level = adau1373_set_bias_level,
1344 .idle_bias_off = true, 1516 .idle_bias_off = true,
1345 .reg_cache_size = ARRAY_SIZE(adau1373_default_regs),
1346 .reg_cache_default = adau1373_default_regs,
1347 .reg_word_size = sizeof(uint8_t),
1348 1517
1349 .set_pll = adau1373_set_pll, 1518 .set_pll = adau1373_set_pll,
1350 1519
@@ -1366,6 +1535,13 @@ static int adau1373_i2c_probe(struct i2c_client *client,
1366 if (!adau1373) 1535 if (!adau1373)
1367 return -ENOMEM; 1536 return -ENOMEM;
1368 1537
1538 adau1373->regmap = devm_regmap_init_i2c(client,
1539 &adau1373_regmap_config);
1540 if (IS_ERR(adau1373->regmap))
1541 return PTR_ERR(adau1373->regmap);
1542
1543 regmap_write(adau1373->regmap, ADAU1373_SOFT_RESET, 0x00);
1544
1369 dev_set_drvdata(&client->dev, adau1373); 1545 dev_set_drvdata(&client->dev, adau1373);
1370 1546
1371 ret = snd_soc_register_codec(&client->dev, &adau1373_codec_driver, 1547 ret = snd_soc_register_codec(&client->dev, &adau1373_codec_driver,
diff --git a/sound/soc/codecs/adav80x.c b/sound/soc/codecs/adav80x.c
index 15b012d0f226..14a7c169d004 100644
--- a/sound/soc/codecs/adav80x.c
+++ b/sound/soc/codecs/adav80x.c
@@ -115,22 +115,34 @@
115 115
116#define ADAV80X_PLL_OUTE_SYSCLKPD(x) BIT(2 - (x)) 116#define ADAV80X_PLL_OUTE_SYSCLKPD(x) BIT(2 - (x))
117 117
118static u8 adav80x_default_regs[] = { 118static struct reg_default adav80x_reg_defaults[] = {
119 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x01, 0x80, 0x26, 0x00, 0x00, 119 { ADAV80X_PLAYBACK_CTRL, 0x01 },
120 0x02, 0x40, 0x20, 0x00, 0x09, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 120 { ADAV80X_AUX_IN_CTRL, 0x01 },
121 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd1, 0x92, 0xb1, 0x37, 121 { ADAV80X_REC_CTRL, 0x02 },
122 0x48, 0xd2, 0xfb, 0xca, 0xd2, 0x15, 0xe8, 0x29, 0xb9, 0x6a, 0xda, 0x2b, 122 { ADAV80X_AUX_OUT_CTRL, 0x01 },
123 0xb7, 0xc0, 0x11, 0x65, 0x5c, 0xf6, 0xff, 0x8d, 0x00, 0x00, 0x00, 0x00, 123 { ADAV80X_DPATH_CTRL1, 0xc0 },
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 124 { ADAV80X_DPATH_CTRL2, 0x11 },
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x00, 0x00, 125 { ADAV80X_DAC_CTRL1, 0x00 },
126 0x00, 0xe8, 0x46, 0xe1, 0x5b, 0xd3, 0x43, 0x77, 0x93, 0xa7, 0x44, 0xee, 126 { ADAV80X_DAC_CTRL2, 0x00 },
127 0x32, 0x12, 0xc0, 0x11, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3f, 0x3f, 127 { ADAV80X_DAC_CTRL3, 0x00 },
128 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 128 { ADAV80X_DAC_L_VOL, 0xff },
129 0x00, 0x00, 0x00, 0x00, 0x52, 0x00, 129 { ADAV80X_DAC_R_VOL, 0xff },
130 { ADAV80X_PGA_L_VOL, 0x00 },
131 { ADAV80X_PGA_R_VOL, 0x00 },
132 { ADAV80X_ADC_CTRL1, 0x00 },
133 { ADAV80X_ADC_CTRL2, 0x00 },
134 { ADAV80X_ADC_L_VOL, 0xff },
135 { ADAV80X_ADC_R_VOL, 0xff },
136 { ADAV80X_PLL_CTRL1, 0x00 },
137 { ADAV80X_PLL_CTRL2, 0x00 },
138 { ADAV80X_ICLK_CTRL1, 0x00 },
139 { ADAV80X_ICLK_CTRL2, 0x00 },
140 { ADAV80X_PLL_CLK_SRC, 0x00 },
141 { ADAV80X_PLL_OUTE, 0x00 },
130}; 142};
131 143
132struct adav80x { 144struct adav80x {
133 enum snd_soc_control_type control_type; 145 struct regmap *regmap;
134 146
135 enum adav80x_clk_src clk_src; 147 enum adav80x_clk_src clk_src;
136 unsigned int sysclk; 148 unsigned int sysclk;
@@ -298,7 +310,7 @@ static int adav80x_set_deemph(struct snd_soc_codec *codec)
298 val = ADAV80X_DAC_CTRL2_DEEMPH_NONE; 310 val = ADAV80X_DAC_CTRL2_DEEMPH_NONE;
299 } 311 }
300 312
301 return snd_soc_update_bits(codec, ADAV80X_DAC_CTRL2, 313 return regmap_update_bits(adav80x->regmap, ADAV80X_DAC_CTRL2,
302 ADAV80X_DAC_CTRL2_DEEMPH_MASK, val); 314 ADAV80X_DAC_CTRL2_DEEMPH_MASK, val);
303} 315}
304 316
@@ -394,10 +406,11 @@ static int adav80x_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
394 return -EINVAL; 406 return -EINVAL;
395 } 407 }
396 408
397 snd_soc_update_bits(codec, adav80x_port_ctrl_regs[dai->id][0], 409 regmap_update_bits(adav80x->regmap, adav80x_port_ctrl_regs[dai->id][0],
398 ADAV80X_CAPTURE_MODE_MASK | ADAV80X_CAPTURE_MODE_MASTER, 410 ADAV80X_CAPTURE_MODE_MASK | ADAV80X_CAPTURE_MODE_MASTER,
399 capture); 411 capture);
400 snd_soc_write(codec, adav80x_port_ctrl_regs[dai->id][1], playback); 412 regmap_write(adav80x->regmap, adav80x_port_ctrl_regs[dai->id][1],
413 playback);
401 414
402 adav80x->dai_fmt[dai->id] = fmt & SND_SOC_DAIFMT_FORMAT_MASK; 415 adav80x->dai_fmt[dai->id] = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
403 416
@@ -407,6 +420,7 @@ static int adav80x_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
407static int adav80x_set_adc_clock(struct snd_soc_codec *codec, 420static int adav80x_set_adc_clock(struct snd_soc_codec *codec,
408 unsigned int sample_rate) 421 unsigned int sample_rate)
409{ 422{
423 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
410 unsigned int val; 424 unsigned int val;
411 425
412 if (sample_rate <= 48000) 426 if (sample_rate <= 48000)
@@ -414,7 +428,7 @@ static int adav80x_set_adc_clock(struct snd_soc_codec *codec,
414 else 428 else
415 val = ADAV80X_ADC_CTRL1_MODULATOR_64FS; 429 val = ADAV80X_ADC_CTRL1_MODULATOR_64FS;
416 430
417 snd_soc_update_bits(codec, ADAV80X_ADC_CTRL1, 431 regmap_update_bits(adav80x->regmap, ADAV80X_ADC_CTRL1,
418 ADAV80X_ADC_CTRL1_MODULATOR_MASK, val); 432 ADAV80X_ADC_CTRL1_MODULATOR_MASK, val);
419 433
420 return 0; 434 return 0;
@@ -423,6 +437,7 @@ static int adav80x_set_adc_clock(struct snd_soc_codec *codec,
423static int adav80x_set_dac_clock(struct snd_soc_codec *codec, 437static int adav80x_set_dac_clock(struct snd_soc_codec *codec,
424 unsigned int sample_rate) 438 unsigned int sample_rate)
425{ 439{
440 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
426 unsigned int val; 441 unsigned int val;
427 442
428 if (sample_rate <= 48000) 443 if (sample_rate <= 48000)
@@ -430,7 +445,7 @@ static int adav80x_set_dac_clock(struct snd_soc_codec *codec,
430 else 445 else
431 val = ADAV80X_DAC_CTRL2_DIV2 | ADAV80X_DAC_CTRL2_INTERPOL_128FS; 446 val = ADAV80X_DAC_CTRL2_DIV2 | ADAV80X_DAC_CTRL2_INTERPOL_128FS;
432 447
433 snd_soc_update_bits(codec, ADAV80X_DAC_CTRL2, 448 regmap_update_bits(adav80x->regmap, ADAV80X_DAC_CTRL2,
434 ADAV80X_DAC_CTRL2_DIV_MASK | ADAV80X_DAC_CTRL2_INTERPOL_MASK, 449 ADAV80X_DAC_CTRL2_DIV_MASK | ADAV80X_DAC_CTRL2_INTERPOL_MASK,
435 val); 450 val);
436 451
@@ -440,6 +455,7 @@ static int adav80x_set_dac_clock(struct snd_soc_codec *codec,
440static int adav80x_set_capture_pcm_format(struct snd_soc_codec *codec, 455static int adav80x_set_capture_pcm_format(struct snd_soc_codec *codec,
441 struct snd_soc_dai *dai, snd_pcm_format_t format) 456 struct snd_soc_dai *dai, snd_pcm_format_t format)
442{ 457{
458 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
443 unsigned int val; 459 unsigned int val;
444 460
445 switch (format) { 461 switch (format) {
@@ -459,7 +475,7 @@ static int adav80x_set_capture_pcm_format(struct snd_soc_codec *codec,
459 return -EINVAL; 475 return -EINVAL;
460 } 476 }
461 477
462 snd_soc_update_bits(codec, adav80x_port_ctrl_regs[dai->id][0], 478 regmap_update_bits(adav80x->regmap, adav80x_port_ctrl_regs[dai->id][0],
463 ADAV80X_CAPTURE_WORD_LEN_MASK, val); 479 ADAV80X_CAPTURE_WORD_LEN_MASK, val);
464 480
465 return 0; 481 return 0;
@@ -491,7 +507,7 @@ static int adav80x_set_playback_pcm_format(struct snd_soc_codec *codec,
491 return -EINVAL; 507 return -EINVAL;
492 } 508 }
493 509
494 snd_soc_update_bits(codec, adav80x_port_ctrl_regs[dai->id][1], 510 regmap_update_bits(adav80x->regmap, adav80x_port_ctrl_regs[dai->id][1],
495 ADAV80X_PLAYBACK_MODE_MASK, val); 511 ADAV80X_PLAYBACK_MODE_MASK, val);
496 512
497 return 0; 513 return 0;
@@ -554,8 +570,10 @@ static int adav80x_set_sysclk(struct snd_soc_codec *codec,
554 ADAV80X_ICLK_CTRL1_ICLK2_SRC(clk_id); 570 ADAV80X_ICLK_CTRL1_ICLK2_SRC(clk_id);
555 iclk_ctrl2 = ADAV80X_ICLK_CTRL2_ICLK1_SRC(clk_id); 571 iclk_ctrl2 = ADAV80X_ICLK_CTRL2_ICLK1_SRC(clk_id);
556 572
557 snd_soc_write(codec, ADAV80X_ICLK_CTRL1, iclk_ctrl1); 573 regmap_write(adav80x->regmap, ADAV80X_ICLK_CTRL1,
558 snd_soc_write(codec, ADAV80X_ICLK_CTRL2, iclk_ctrl2); 574 iclk_ctrl1);
575 regmap_write(adav80x->regmap, ADAV80X_ICLK_CTRL2,
576 iclk_ctrl2);
559 577
560 snd_soc_dapm_sync(&codec->dapm); 578 snd_soc_dapm_sync(&codec->dapm);
561 } 579 }
@@ -575,10 +593,12 @@ static int adav80x_set_sysclk(struct snd_soc_codec *codec,
575 mask = ADAV80X_PLL_OUTE_SYSCLKPD(clk_id); 593 mask = ADAV80X_PLL_OUTE_SYSCLKPD(clk_id);
576 594
577 if (freq == 0) { 595 if (freq == 0) {
578 snd_soc_update_bits(codec, ADAV80X_PLL_OUTE, mask, mask); 596 regmap_update_bits(adav80x->regmap, ADAV80X_PLL_OUTE,
597 mask, mask);
579 adav80x->sysclk_pd[clk_id] = true; 598 adav80x->sysclk_pd[clk_id] = true;
580 } else { 599 } else {
581 snd_soc_update_bits(codec, ADAV80X_PLL_OUTE, mask, 0); 600 regmap_update_bits(adav80x->regmap, ADAV80X_PLL_OUTE,
601 mask, 0);
582 adav80x->sysclk_pd[clk_id] = false; 602 adav80x->sysclk_pd[clk_id] = false;
583 } 603 }
584 604
@@ -650,9 +670,9 @@ static int adav80x_set_pll(struct snd_soc_codec *codec, int pll_id,
650 return -EINVAL; 670 return -EINVAL;
651 } 671 }
652 672
653 snd_soc_update_bits(codec, ADAV80X_PLL_CTRL1, ADAV80X_PLL_CTRL1_PLLDIV, 673 regmap_update_bits(adav80x->regmap, ADAV80X_PLL_CTRL1,
654 pll_ctrl1); 674 ADAV80X_PLL_CTRL1_PLLDIV, pll_ctrl1);
655 snd_soc_update_bits(codec, ADAV80X_PLL_CTRL2, 675 regmap_update_bits(adav80x->regmap, ADAV80X_PLL_CTRL2,
656 ADAV80X_PLL_CTRL2_PLL_MASK(pll_id), pll_ctrl2); 676 ADAV80X_PLL_CTRL2_PLL_MASK(pll_id), pll_ctrl2);
657 677
658 if (source != adav80x->pll_src) { 678 if (source != adav80x->pll_src) {
@@ -661,7 +681,7 @@ static int adav80x_set_pll(struct snd_soc_codec *codec, int pll_id,
661 else 681 else
662 pll_src = ADAV80X_PLL_CLK_SRC_PLL_XIN(pll_id); 682 pll_src = ADAV80X_PLL_CLK_SRC_PLL_XIN(pll_id);
663 683
664 snd_soc_update_bits(codec, ADAV80X_PLL_CLK_SRC, 684 regmap_update_bits(adav80x->regmap, ADAV80X_PLL_CLK_SRC,
665 ADAV80X_PLL_CLK_SRC_PLL_MASK(pll_id), pll_src); 685 ADAV80X_PLL_CLK_SRC_PLL_MASK(pll_id), pll_src);
666 686
667 adav80x->pll_src = source; 687 adav80x->pll_src = source;
@@ -675,6 +695,7 @@ static int adav80x_set_pll(struct snd_soc_codec *codec, int pll_id,
675static int adav80x_set_bias_level(struct snd_soc_codec *codec, 695static int adav80x_set_bias_level(struct snd_soc_codec *codec,
676 enum snd_soc_bias_level level) 696 enum snd_soc_bias_level level)
677{ 697{
698 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
678 unsigned int mask = ADAV80X_DAC_CTRL1_PD; 699 unsigned int mask = ADAV80X_DAC_CTRL1_PD;
679 700
680 switch (level) { 701 switch (level) {
@@ -683,10 +704,12 @@ static int adav80x_set_bias_level(struct snd_soc_codec *codec,
683 case SND_SOC_BIAS_PREPARE: 704 case SND_SOC_BIAS_PREPARE:
684 break; 705 break;
685 case SND_SOC_BIAS_STANDBY: 706 case SND_SOC_BIAS_STANDBY:
686 snd_soc_update_bits(codec, ADAV80X_DAC_CTRL1, mask, 0x00); 707 regmap_update_bits(adav80x->regmap, ADAV80X_DAC_CTRL1, mask,
708 0x00);
687 break; 709 break;
688 case SND_SOC_BIAS_OFF: 710 case SND_SOC_BIAS_OFF:
689 snd_soc_update_bits(codec, ADAV80X_DAC_CTRL1, mask, mask); 711 regmap_update_bits(adav80x->regmap, ADAV80X_DAC_CTRL1, mask,
712 mask);
690 break; 713 break;
691 } 714 }
692 715
@@ -780,7 +803,7 @@ static int adav80x_probe(struct snd_soc_codec *codec)
780 int ret; 803 int ret;
781 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 804 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
782 805
783 ret = snd_soc_codec_set_cache_io(codec, 7, 9, adav80x->control_type); 806 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
784 if (ret) { 807 if (ret) {
785 dev_err(codec->dev, "failed to set cache I/O: %d\n", ret); 808 dev_err(codec->dev, "failed to set cache I/O: %d\n", ret);
786 return ret; 809 return ret;
@@ -791,23 +814,31 @@ static int adav80x_probe(struct snd_soc_codec *codec)
791 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL2"); 814 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL2");
792 815
793 /* Power down S/PDIF receiver, since it is currently not supported */ 816 /* Power down S/PDIF receiver, since it is currently not supported */
794 snd_soc_write(codec, ADAV80X_PLL_OUTE, 0x20); 817 regmap_write(adav80x->regmap, ADAV80X_PLL_OUTE, 0x20);
795 /* Disable DAC zero flag */ 818 /* Disable DAC zero flag */
796 snd_soc_write(codec, ADAV80X_DAC_CTRL3, 0x6); 819 regmap_write(adav80x->regmap, ADAV80X_DAC_CTRL3, 0x6);
797 820
798 return adav80x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 821 return adav80x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
799} 822}
800 823
801static int adav80x_suspend(struct snd_soc_codec *codec) 824static int adav80x_suspend(struct snd_soc_codec *codec)
802{ 825{
803 return adav80x_set_bias_level(codec, SND_SOC_BIAS_OFF); 826 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
827 int ret;
828
829 ret = adav80x_set_bias_level(codec, SND_SOC_BIAS_OFF);
830 regcache_cache_only(adav80x->regmap, true);
831
832 return ret;
804} 833}
805 834
806static int adav80x_resume(struct snd_soc_codec *codec) 835static int adav80x_resume(struct snd_soc_codec *codec)
807{ 836{
837 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
838
839 regcache_cache_only(adav80x->regmap, false);
808 adav80x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 840 adav80x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
809 codec->cache_sync = 1; 841 regcache_sync(adav80x->regmap);
810 snd_soc_cache_sync(codec);
811 842
812 return 0; 843 return 0;
813} 844}
@@ -827,10 +858,6 @@ static struct snd_soc_codec_driver adav80x_codec_driver = {
827 .set_pll = adav80x_set_pll, 858 .set_pll = adav80x_set_pll,
828 .set_sysclk = adav80x_set_sysclk, 859 .set_sysclk = adav80x_set_sysclk,
829 860
830 .reg_word_size = sizeof(u8),
831 .reg_cache_size = ARRAY_SIZE(adav80x_default_regs),
832 .reg_cache_default = adav80x_default_regs,
833
834 .controls = adav80x_controls, 861 .controls = adav80x_controls,
835 .num_controls = ARRAY_SIZE(adav80x_controls), 862 .num_controls = ARRAY_SIZE(adav80x_controls),
836 .dapm_widgets = adav80x_dapm_widgets, 863 .dapm_widgets = adav80x_dapm_widgets,
@@ -839,18 +866,21 @@ static struct snd_soc_codec_driver adav80x_codec_driver = {
839 .num_dapm_routes = ARRAY_SIZE(adav80x_dapm_routes), 866 .num_dapm_routes = ARRAY_SIZE(adav80x_dapm_routes),
840}; 867};
841 868
842static int adav80x_bus_probe(struct device *dev, 869static int adav80x_bus_probe(struct device *dev, struct regmap *regmap)
843 enum snd_soc_control_type control_type)
844{ 870{
845 struct adav80x *adav80x; 871 struct adav80x *adav80x;
846 int ret; 872 int ret;
847 873
874 if (IS_ERR(regmap))
875 return PTR_ERR(regmap);
876
848 adav80x = kzalloc(sizeof(*adav80x), GFP_KERNEL); 877 adav80x = kzalloc(sizeof(*adav80x), GFP_KERNEL);
849 if (!adav80x) 878 if (!adav80x)
850 return -ENOMEM; 879 return -ENOMEM;
851 880
881
852 dev_set_drvdata(dev, adav80x); 882 dev_set_drvdata(dev, adav80x);
853 adav80x->control_type = control_type; 883 adav80x->regmap = regmap;
854 884
855 ret = snd_soc_register_codec(dev, &adav80x_codec_driver, 885 ret = snd_soc_register_codec(dev, &adav80x_codec_driver,
856 adav80x_dais, ARRAY_SIZE(adav80x_dais)); 886 adav80x_dais, ARRAY_SIZE(adav80x_dais));
@@ -868,6 +898,19 @@ static int adav80x_bus_remove(struct device *dev)
868} 898}
869 899
870#if defined(CONFIG_SPI_MASTER) 900#if defined(CONFIG_SPI_MASTER)
901static const struct regmap_config adav80x_spi_regmap_config = {
902 .val_bits = 8,
903 .pad_bits = 1,
904 .reg_bits = 7,
905 .read_flag_mask = 0x01,
906
907 .max_register = ADAV80X_PLL_OUTE,
908
909 .cache_type = REGCACHE_RBTREE,
910 .reg_defaults = adav80x_reg_defaults,
911 .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults),
912};
913
871static const struct spi_device_id adav80x_spi_id[] = { 914static const struct spi_device_id adav80x_spi_id[] = {
872 { "adav801", 0 }, 915 { "adav801", 0 },
873 { } 916 { }
@@ -876,7 +919,8 @@ MODULE_DEVICE_TABLE(spi, adav80x_spi_id);
876 919
877static int adav80x_spi_probe(struct spi_device *spi) 920static int adav80x_spi_probe(struct spi_device *spi)
878{ 921{
879 return adav80x_bus_probe(&spi->dev, SND_SOC_SPI); 922 return adav80x_bus_probe(&spi->dev,
923 devm_regmap_init_spi(spi, &adav80x_spi_regmap_config));
880} 924}
881 925
882static int adav80x_spi_remove(struct spi_device *spi) 926static int adav80x_spi_remove(struct spi_device *spi)
@@ -896,6 +940,18 @@ static struct spi_driver adav80x_spi_driver = {
896#endif 940#endif
897 941
898#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 942#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
943static const struct regmap_config adav80x_i2c_regmap_config = {
944 .val_bits = 8,
945 .pad_bits = 1,
946 .reg_bits = 7,
947
948 .max_register = ADAV80X_PLL_OUTE,
949
950 .cache_type = REGCACHE_RBTREE,
951 .reg_defaults = adav80x_reg_defaults,
952 .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults),
953};
954
899static const struct i2c_device_id adav80x_i2c_id[] = { 955static const struct i2c_device_id adav80x_i2c_id[] = {
900 { "adav803", 0 }, 956 { "adav803", 0 },
901 { } 957 { }
@@ -905,7 +961,8 @@ MODULE_DEVICE_TABLE(i2c, adav80x_i2c_id);
905static int adav80x_i2c_probe(struct i2c_client *client, 961static int adav80x_i2c_probe(struct i2c_client *client,
906 const struct i2c_device_id *id) 962 const struct i2c_device_id *id)
907{ 963{
908 return adav80x_bus_probe(&client->dev, SND_SOC_I2C); 964 return adav80x_bus_probe(&client->dev,
965 devm_regmap_init_i2c(client, &adav80x_i2c_regmap_config));
909} 966}
910 967
911static int adav80x_i2c_remove(struct i2c_client *client) 968static int adav80x_i2c_remove(struct i2c_client *client)
diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c
index 71059c07ae7b..b4819dcd4f4d 100644
--- a/sound/soc/codecs/ak4104.c
+++ b/sound/soc/codecs/ak4104.c
@@ -45,8 +45,6 @@
45#define AK4104_TX_TXE (1 << 0) 45#define AK4104_TX_TXE (1 << 0)
46#define AK4104_TX_V (1 << 1) 46#define AK4104_TX_V (1 << 1)
47 47
48#define DRV_NAME "ak4104-codec"
49
50struct ak4104_private { 48struct ak4104_private {
51 struct regmap *regmap; 49 struct regmap *regmap;
52}; 50};
@@ -291,12 +289,19 @@ static const struct of_device_id ak4104_of_match[] = {
291}; 289};
292MODULE_DEVICE_TABLE(of, ak4104_of_match); 290MODULE_DEVICE_TABLE(of, ak4104_of_match);
293 291
292static const struct spi_device_id ak4104_id_table[] = {
293 { "ak4104", 0 },
294 { }
295};
296MODULE_DEVICE_TABLE(spi, ak4104_id_table);
297
294static struct spi_driver ak4104_spi_driver = { 298static struct spi_driver ak4104_spi_driver = {
295 .driver = { 299 .driver = {
296 .name = DRV_NAME, 300 .name = "ak4104",
297 .owner = THIS_MODULE, 301 .owner = THIS_MODULE,
298 .of_match_table = ak4104_of_match, 302 .of_match_table = ak4104_of_match,
299 }, 303 },
304 .id_table = ak4104_id_table,
300 .probe = ak4104_spi_probe, 305 .probe = ak4104_spi_probe,
301 .remove = ak4104_spi_remove, 306 .remove = ak4104_spi_remove,
302}; 307};
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c
index 5f9af1fb76e8..49cc5f6d6dba 100644
--- a/sound/soc/codecs/ak4641.c
+++ b/sound/soc/codecs/ak4641.c
@@ -328,7 +328,7 @@ static int ak4641_i2s_hw_params(struct snd_pcm_substream *substream,
328 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 328 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
329 ak4641->playback_fs = rate; 329 ak4641->playback_fs = rate;
330 ak4641_set_deemph(codec); 330 ak4641_set_deemph(codec);
331 }; 331 }
332 332
333 return 0; 333 return 0;
334} 334}
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 2d0378709702..090d499bb7eb 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -257,7 +257,7 @@ static int ak4642_dai_startup(struct snd_pcm_substream *substream,
257 * This operation came from example code of 257 * This operation came from example code of
258 * "ASAHI KASEI AK4642" (japanese) manual p94. 258 * "ASAHI KASEI AK4642" (japanese) manual p94.
259 */ 259 */
260 snd_soc_write(codec, SG_SL1, PMMP | MGAIN0); 260 snd_soc_update_bits(codec, SG_SL1, PMMP | MGAIN0, PMMP | MGAIN0);
261 snd_soc_write(codec, TIMER, ZTM(0x3) | WTM(0x3)); 261 snd_soc_write(codec, TIMER, ZTM(0x3) | WTM(0x3));
262 snd_soc_write(codec, ALC_CTL1, ALC | LMTH0); 262 snd_soc_write(codec, ALC_CTL1, ALC | LMTH0);
263 snd_soc_update_bits(codec, PW_MGMT1, PMADL, PMADL); 263 snd_soc_update_bits(codec, PW_MGMT1, PMADL, PMADL);
@@ -352,7 +352,6 @@ static int ak4642_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
352 */ 352 */
353 default: 353 default:
354 return -EINVAL; 354 return -EINVAL;
355 break;
356 } 355 }
357 snd_soc_update_bits(codec, MD_CTL1, DIF_MASK, data); 356 snd_soc_update_bits(codec, MD_CTL1, DIF_MASK, data);
358 357
@@ -405,7 +404,6 @@ static int ak4642_dai_hw_params(struct snd_pcm_substream *substream,
405 break; 404 break;
406 default: 405 default:
407 return -EINVAL; 406 return -EINVAL;
408 break;
409 } 407 }
410 snd_soc_update_bits(codec, MD_CTL2, FS_MASK, rate); 408 snd_soc_update_bits(codec, MD_CTL2, FS_MASK, rate);
411 409
diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c
index f2e62e45f912..19e9f222d09c 100644
--- a/sound/soc/codecs/alc5632.c
+++ b/sound/soc/codecs/alc5632.c
@@ -614,7 +614,7 @@ struct _pll_div {
614}; 614};
615 615
616/* Note : pll code from original alc5632 driver. Not sure of how good it is */ 616/* Note : pll code from original alc5632 driver. Not sure of how good it is */
617/* usefull only for master mode */ 617/* useful only for master mode */
618static const struct _pll_div codec_master_pll_div[] = { 618static const struct _pll_div codec_master_pll_div[] = {
619 619
620 { 2048000, 8192000, 0x0ea0}, 620 { 2048000, 8192000, 0x0ea0},
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index 657808ba1418..6f05b17d1965 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -1477,21 +1477,25 @@ static void arizona_enable_fll(struct arizona_fll *fll,
1477{ 1477{
1478 struct arizona *arizona = fll->arizona; 1478 struct arizona *arizona = fll->arizona;
1479 int ret; 1479 int ret;
1480 bool use_sync = false;
1480 1481
1481 /* 1482 /*
1482 * If we have both REFCLK and SYNCCLK then enable both, 1483 * If we have both REFCLK and SYNCCLK then enable both,
1483 * otherwise apply the SYNCCLK settings to REFCLK. 1484 * otherwise apply the SYNCCLK settings to REFCLK.
1484 */ 1485 */
1485 if (fll->ref_src >= 0 && fll->ref_src != fll->sync_src) { 1486 if (fll->ref_src >= 0 && fll->ref_freq &&
1487 fll->ref_src != fll->sync_src) {
1486 regmap_update_bits(arizona->regmap, fll->base + 5, 1488 regmap_update_bits(arizona->regmap, fll->base + 5,
1487 ARIZONA_FLL1_OUTDIV_MASK, 1489 ARIZONA_FLL1_OUTDIV_MASK,
1488 ref->outdiv << ARIZONA_FLL1_OUTDIV_SHIFT); 1490 ref->outdiv << ARIZONA_FLL1_OUTDIV_SHIFT);
1489 1491
1490 arizona_apply_fll(arizona, fll->base, ref, fll->ref_src, 1492 arizona_apply_fll(arizona, fll->base, ref, fll->ref_src,
1491 false); 1493 false);
1492 if (fll->sync_src >= 0) 1494 if (fll->sync_src >= 0) {
1493 arizona_apply_fll(arizona, fll->base + 0x10, sync, 1495 arizona_apply_fll(arizona, fll->base + 0x10, sync,
1494 fll->sync_src, true); 1496 fll->sync_src, true);
1497 use_sync = true;
1498 }
1495 } else if (fll->sync_src >= 0) { 1499 } else if (fll->sync_src >= 0) {
1496 regmap_update_bits(arizona->regmap, fll->base + 5, 1500 regmap_update_bits(arizona->regmap, fll->base + 5,
1497 ARIZONA_FLL1_OUTDIV_MASK, 1501 ARIZONA_FLL1_OUTDIV_MASK,
@@ -1511,7 +1515,7 @@ static void arizona_enable_fll(struct arizona_fll *fll,
1511 * Increase the bandwidth if we're not using a low frequency 1515 * Increase the bandwidth if we're not using a low frequency
1512 * sync source. 1516 * sync source.
1513 */ 1517 */
1514 if (fll->sync_src >= 0 && fll->sync_freq > 100000) 1518 if (use_sync && fll->sync_freq > 100000)
1515 regmap_update_bits(arizona->regmap, fll->base + 0x17, 1519 regmap_update_bits(arizona->regmap, fll->base + 0x17,
1516 ARIZONA_FLL1_SYNC_BW, 0); 1520 ARIZONA_FLL1_SYNC_BW, 0);
1517 else 1521 else
@@ -1526,8 +1530,7 @@ static void arizona_enable_fll(struct arizona_fll *fll,
1526 1530
1527 regmap_update_bits(arizona->regmap, fll->base + 1, 1531 regmap_update_bits(arizona->regmap, fll->base + 1,
1528 ARIZONA_FLL1_ENA, ARIZONA_FLL1_ENA); 1532 ARIZONA_FLL1_ENA, ARIZONA_FLL1_ENA);
1529 if (fll->ref_src >= 0 && fll->sync_src >= 0 && 1533 if (use_sync)
1530 fll->ref_src != fll->sync_src)
1531 regmap_update_bits(arizona->regmap, fll->base + 0x11, 1534 regmap_update_bits(arizona->regmap, fll->base + 0x11,
1532 ARIZONA_FLL1_SYNC_ENA, 1535 ARIZONA_FLL1_SYNC_ENA,
1533 ARIZONA_FLL1_SYNC_ENA); 1536 ARIZONA_FLL1_SYNC_ENA);
@@ -1561,10 +1564,12 @@ int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
1561 if (fll->ref_src == source && fll->ref_freq == Fref) 1564 if (fll->ref_src == source && fll->ref_freq == Fref)
1562 return 0; 1565 return 0;
1563 1566
1564 if (fll->fout && Fref > 0) { 1567 if (fll->fout) {
1565 ret = arizona_calc_fll(fll, &ref, Fref, fll->fout); 1568 if (Fref > 0) {
1566 if (ret != 0) 1569 ret = arizona_calc_fll(fll, &ref, Fref, fll->fout);
1567 return ret; 1570 if (ret != 0)
1571 return ret;
1572 }
1568 1573
1569 if (fll->sync_src >= 0) { 1574 if (fll->sync_src >= 0) {
1570 ret = arizona_calc_fll(fll, &sync, fll->sync_freq, 1575 ret = arizona_calc_fll(fll, &sync, fll->sync_freq,
diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c
index 23316c887b19..43737a27d79c 100644
--- a/sound/soc/codecs/cq93vc.c
+++ b/sound/soc/codecs/cq93vc.c
@@ -38,24 +38,6 @@
38#include <sound/soc.h> 38#include <sound/soc.h>
39#include <sound/initval.h> 39#include <sound/initval.h>
40 40
41static inline unsigned int cq93vc_read(struct snd_soc_codec *codec,
42 unsigned int reg)
43{
44 struct davinci_vc *davinci_vc = codec->control_data;
45
46 return readl(davinci_vc->base + reg);
47}
48
49static inline int cq93vc_write(struct snd_soc_codec *codec, unsigned int reg,
50 unsigned int value)
51{
52 struct davinci_vc *davinci_vc = codec->control_data;
53
54 writel(value, davinci_vc->base + reg);
55
56 return 0;
57}
58
59static const struct snd_kcontrol_new cq93vc_snd_controls[] = { 41static const struct snd_kcontrol_new cq93vc_snd_controls[] = {
60 SOC_SINGLE("PGA Capture Volume", DAVINCI_VC_REG05, 0, 0x03, 0), 42 SOC_SINGLE("PGA Capture Volume", DAVINCI_VC_REG05, 0, 0x03, 0),
61 SOC_SINGLE("Mono DAC Playback Volume", DAVINCI_VC_REG09, 0, 0x3f, 0), 43 SOC_SINGLE("Mono DAC Playback Volume", DAVINCI_VC_REG09, 0, 0x3f, 0),
@@ -64,13 +46,15 @@ static const struct snd_kcontrol_new cq93vc_snd_controls[] = {
64static int cq93vc_mute(struct snd_soc_dai *dai, int mute) 46static int cq93vc_mute(struct snd_soc_dai *dai, int mute)
65{ 47{
66 struct snd_soc_codec *codec = dai->codec; 48 struct snd_soc_codec *codec = dai->codec;
67 u8 reg = cq93vc_read(codec, DAVINCI_VC_REG09) & ~DAVINCI_VC_REG09_MUTE; 49 u8 reg;
68 50
69 if (mute) 51 if (mute)
70 cq93vc_write(codec, DAVINCI_VC_REG09, 52 reg = DAVINCI_VC_REG09_MUTE;
71 reg | DAVINCI_VC_REG09_MUTE);
72 else 53 else
73 cq93vc_write(codec, DAVINCI_VC_REG09, reg); 54 reg = 0;
55
56 snd_soc_update_bits(codec, DAVINCI_VC_REG09, DAVINCI_VC_REG09_MUTE,
57 reg);
74 58
75 return 0; 59 return 0;
76} 60}
@@ -79,7 +63,7 @@ static int cq93vc_set_dai_sysclk(struct snd_soc_dai *codec_dai,
79 int clk_id, unsigned int freq, int dir) 63 int clk_id, unsigned int freq, int dir)
80{ 64{
81 struct snd_soc_codec *codec = codec_dai->codec; 65 struct snd_soc_codec *codec = codec_dai->codec;
82 struct davinci_vc *davinci_vc = codec->control_data; 66 struct davinci_vc *davinci_vc = codec->dev->platform_data;
83 67
84 switch (freq) { 68 switch (freq) {
85 case 22579200: 69 case 22579200:
@@ -97,18 +81,18 @@ static int cq93vc_set_bias_level(struct snd_soc_codec *codec,
97{ 81{
98 switch (level) { 82 switch (level) {
99 case SND_SOC_BIAS_ON: 83 case SND_SOC_BIAS_ON:
100 cq93vc_write(codec, DAVINCI_VC_REG12, 84 snd_soc_write(codec, DAVINCI_VC_REG12,
101 DAVINCI_VC_REG12_POWER_ALL_ON); 85 DAVINCI_VC_REG12_POWER_ALL_ON);
102 break; 86 break;
103 case SND_SOC_BIAS_PREPARE: 87 case SND_SOC_BIAS_PREPARE:
104 break; 88 break;
105 case SND_SOC_BIAS_STANDBY: 89 case SND_SOC_BIAS_STANDBY:
106 cq93vc_write(codec, DAVINCI_VC_REG12, 90 snd_soc_write(codec, DAVINCI_VC_REG12,
107 DAVINCI_VC_REG12_POWER_ALL_OFF); 91 DAVINCI_VC_REG12_POWER_ALL_OFF);
108 break; 92 break;
109 case SND_SOC_BIAS_OFF: 93 case SND_SOC_BIAS_OFF:
110 /* force all power off */ 94 /* force all power off */
111 cq93vc_write(codec, DAVINCI_VC_REG12, 95 snd_soc_write(codec, DAVINCI_VC_REG12,
112 DAVINCI_VC_REG12_POWER_ALL_OFF); 96 DAVINCI_VC_REG12_POWER_ALL_OFF);
113 break; 97 break;
114 } 98 }
@@ -154,11 +138,9 @@ static int cq93vc_probe(struct snd_soc_codec *codec)
154 struct davinci_vc *davinci_vc = codec->dev->platform_data; 138 struct davinci_vc *davinci_vc = codec->dev->platform_data;
155 139
156 davinci_vc->cq93vc.codec = codec; 140 davinci_vc->cq93vc.codec = codec;
157 codec->control_data = davinci_vc; 141 codec->control_data = davinci_vc->regmap;
158 142
159 /* Set controls */ 143 snd_soc_codec_set_cache_io(codec, 32, 32, SND_SOC_REGMAP);
160 snd_soc_add_codec_controls(codec, cq93vc_snd_controls,
161 ARRAY_SIZE(cq93vc_snd_controls));
162 144
163 /* Off, with power on */ 145 /* Off, with power on */
164 cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 146 cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
@@ -174,12 +156,12 @@ static int cq93vc_remove(struct snd_soc_codec *codec)
174} 156}
175 157
176static struct snd_soc_codec_driver soc_codec_dev_cq93vc = { 158static struct snd_soc_codec_driver soc_codec_dev_cq93vc = {
177 .read = cq93vc_read,
178 .write = cq93vc_write,
179 .set_bias_level = cq93vc_set_bias_level, 159 .set_bias_level = cq93vc_set_bias_level,
180 .probe = cq93vc_probe, 160 .probe = cq93vc_probe,
181 .remove = cq93vc_remove, 161 .remove = cq93vc_remove,
182 .resume = cq93vc_resume, 162 .resume = cq93vc_resume,
163 .controls = cq93vc_snd_controls,
164 .num_controls = ARRAY_SIZE(cq93vc_snd_controls),
183}; 165};
184 166
185static int cq93vc_platform_probe(struct platform_device *pdev) 167static int cq93vc_platform_probe(struct platform_device *pdev)
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
index a20f1bb8f071..f6e953454bc0 100644
--- a/sound/soc/codecs/cs4271.c
+++ b/sound/soc/codecs/cs4271.c
@@ -25,6 +25,7 @@
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
28#include <linux/of.h>
28#include <linux/of_device.h> 29#include <linux/of_device.h>
29#include <linux/of_gpio.h> 30#include <linux/of_gpio.h>
30#include <sound/pcm.h> 31#include <sound/pcm.h>
diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c
index be2ba1b6fe4a..8b427c977083 100644
--- a/sound/soc/codecs/cs42l52.c
+++ b/sound/soc/codecs/cs42l52.c
@@ -17,6 +17,7 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/gpio.h>
20#include <linux/pm.h> 21#include <linux/pm.h>
21#include <linux/i2c.h> 22#include <linux/i2c.h>
22#include <linux/input.h> 23#include <linux/input.h>
@@ -1116,40 +1117,6 @@ static int cs42l52_probe(struct snd_soc_codec *codec)
1116 cs42l52->sysclk = CS42L52_DEFAULT_CLK; 1117 cs42l52->sysclk = CS42L52_DEFAULT_CLK;
1117 cs42l52->config.format = CS42L52_DEFAULT_FORMAT; 1118 cs42l52->config.format = CS42L52_DEFAULT_FORMAT;
1118 1119
1119 /* Set Platform MICx CFG */
1120 snd_soc_update_bits(codec, CS42L52_MICA_CTL,
1121 CS42L52_MIC_CTL_TYPE_MASK,
1122 cs42l52->pdata.mica_cfg <<
1123 CS42L52_MIC_CTL_TYPE_SHIFT);
1124
1125 snd_soc_update_bits(codec, CS42L52_MICB_CTL,
1126 CS42L52_MIC_CTL_TYPE_MASK,
1127 cs42l52->pdata.micb_cfg <<
1128 CS42L52_MIC_CTL_TYPE_SHIFT);
1129
1130 /* if Single Ended, Get Mic_Select */
1131 if (cs42l52->pdata.mica_cfg)
1132 snd_soc_update_bits(codec, CS42L52_MICA_CTL,
1133 CS42L52_MIC_CTL_MIC_SEL_MASK,
1134 cs42l52->pdata.mica_sel <<
1135 CS42L52_MIC_CTL_MIC_SEL_SHIFT);
1136 if (cs42l52->pdata.micb_cfg)
1137 snd_soc_update_bits(codec, CS42L52_MICB_CTL,
1138 CS42L52_MIC_CTL_MIC_SEL_MASK,
1139 cs42l52->pdata.micb_sel <<
1140 CS42L52_MIC_CTL_MIC_SEL_SHIFT);
1141
1142 /* Set Platform Charge Pump Freq */
1143 snd_soc_update_bits(codec, CS42L52_CHARGE_PUMP,
1144 CS42L52_CHARGE_PUMP_MASK,
1145 cs42l52->pdata.chgfreq <<
1146 CS42L52_CHARGE_PUMP_SHIFT);
1147
1148 /* Set Platform Bias Level */
1149 snd_soc_update_bits(codec, CS42L52_IFACE_CTL2,
1150 CS42L52_IFACE_CTL2_BIAS_LVL,
1151 cs42l52->pdata.micbias_lvl);
1152
1153 return ret; 1120 return ret;
1154} 1121}
1155 1122
@@ -1205,6 +1172,7 @@ static int cs42l52_i2c_probe(struct i2c_client *i2c_client,
1205 const struct i2c_device_id *id) 1172 const struct i2c_device_id *id)
1206{ 1173{
1207 struct cs42l52_private *cs42l52; 1174 struct cs42l52_private *cs42l52;
1175 struct cs42l52_platform_data *pdata = dev_get_platdata(&i2c_client->dev);
1208 int ret; 1176 int ret;
1209 unsigned int devid = 0; 1177 unsigned int devid = 0;
1210 unsigned int reg; 1178 unsigned int reg;
@@ -1222,11 +1190,22 @@ static int cs42l52_i2c_probe(struct i2c_client *i2c_client,
1222 return ret; 1190 return ret;
1223 } 1191 }
1224 1192
1225 i2c_set_clientdata(i2c_client, cs42l52); 1193 if (pdata)
1194 cs42l52->pdata = *pdata;
1195
1196 if (cs42l52->pdata.reset_gpio) {
1197 ret = gpio_request_one(cs42l52->pdata.reset_gpio,
1198 GPIOF_OUT_INIT_HIGH, "CS42L52 /RST");
1199 if (ret < 0) {
1200 dev_err(&i2c_client->dev, "Failed to request /RST %d: %d\n",
1201 cs42l52->pdata.reset_gpio, ret);
1202 return ret;
1203 }
1204 gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 0);
1205 gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 1);
1206 }
1226 1207
1227 if (dev_get_platdata(&i2c_client->dev)) 1208 i2c_set_clientdata(i2c_client, cs42l52);
1228 memcpy(&cs42l52->pdata, dev_get_platdata(&i2c_client->dev),
1229 sizeof(cs42l52->pdata));
1230 1209
1231 ret = regmap_register_patch(cs42l52->regmap, cs42l52_threshold_patch, 1210 ret = regmap_register_patch(cs42l52->regmap, cs42l52_threshold_patch,
1232 ARRAY_SIZE(cs42l52_threshold_patch)); 1211 ARRAY_SIZE(cs42l52_threshold_patch));
@@ -1244,7 +1223,43 @@ static int cs42l52_i2c_probe(struct i2c_client *i2c_client,
1244 return ret; 1223 return ret;
1245 } 1224 }
1246 1225
1247 regcache_cache_only(cs42l52->regmap, true); 1226 dev_info(&i2c_client->dev, "Cirrus Logic CS42L52, Revision: %02X\n",
1227 reg & 0xFF);
1228
1229 /* Set Platform Data */
1230 if (cs42l52->pdata.mica_cfg)
1231 regmap_update_bits(cs42l52->regmap, CS42L52_MICA_CTL,
1232 CS42L52_MIC_CTL_TYPE_MASK,
1233 cs42l52->pdata.mica_cfg <<
1234 CS42L52_MIC_CTL_TYPE_SHIFT);
1235
1236 if (cs42l52->pdata.micb_cfg)
1237 regmap_update_bits(cs42l52->regmap, CS42L52_MICB_CTL,
1238 CS42L52_MIC_CTL_TYPE_MASK,
1239 cs42l52->pdata.micb_cfg <<
1240 CS42L52_MIC_CTL_TYPE_SHIFT);
1241
1242 if (cs42l52->pdata.mica_sel)
1243 regmap_update_bits(cs42l52->regmap, CS42L52_MICA_CTL,
1244 CS42L52_MIC_CTL_MIC_SEL_MASK,
1245 cs42l52->pdata.mica_sel <<
1246 CS42L52_MIC_CTL_MIC_SEL_SHIFT);
1247 if (cs42l52->pdata.micb_sel)
1248 regmap_update_bits(cs42l52->regmap, CS42L52_MICB_CTL,
1249 CS42L52_MIC_CTL_MIC_SEL_MASK,
1250 cs42l52->pdata.micb_sel <<
1251 CS42L52_MIC_CTL_MIC_SEL_SHIFT);
1252
1253 if (cs42l52->pdata.chgfreq)
1254 regmap_update_bits(cs42l52->regmap, CS42L52_CHARGE_PUMP,
1255 CS42L52_CHARGE_PUMP_MASK,
1256 cs42l52->pdata.chgfreq <<
1257 CS42L52_CHARGE_PUMP_SHIFT);
1258
1259 if (cs42l52->pdata.micbias_lvl)
1260 regmap_update_bits(cs42l52->regmap, CS42L52_IFACE_CTL2,
1261 CS42L52_IFACE_CTL2_BIAS_LVL,
1262 cs42l52->pdata.micbias_lvl);
1248 1263
1249 ret = snd_soc_register_codec(&i2c_client->dev, 1264 ret = snd_soc_register_codec(&i2c_client->dev,
1250 &soc_codec_dev_cs42l52, &cs42l52_dai, 1); 1265 &soc_codec_dev_cs42l52, &cs42l52_dai, 1);
diff --git a/sound/soc/codecs/cs42l52.h b/sound/soc/codecs/cs42l52.h
index 4277012c4719..6fb8f00f4191 100644
--- a/sound/soc/codecs/cs42l52.h
+++ b/sound/soc/codecs/cs42l52.h
@@ -179,7 +179,7 @@
179#define CS42L52_MICB_CTL 0x11 179#define CS42L52_MICB_CTL 0x11
180#define CS42L52_MIC_CTL_MIC_SEL_MASK 0xBF 180#define CS42L52_MIC_CTL_MIC_SEL_MASK 0xBF
181#define CS42L52_MIC_CTL_MIC_SEL_SHIFT 6 181#define CS42L52_MIC_CTL_MIC_SEL_SHIFT 6
182#define CS42L52_MIC_CTL_TYPE_MASK 0xDF 182#define CS42L52_MIC_CTL_TYPE_MASK 0x20
183#define CS42L52_MIC_CTL_TYPE_SHIFT 5 183#define CS42L52_MIC_CTL_TYPE_SHIFT 5
184 184
185 185
@@ -269,6 +269,6 @@
269#define CS42L52_FIX_BITS1 0x3E 269#define CS42L52_FIX_BITS1 0x3E
270#define CS42L52_FIX_BITS2 0x47 270#define CS42L52_FIX_BITS2 0x47
271 271
272#define CS42L52_MAX_REGISTER 0x34 272#define CS42L52_MAX_REGISTER 0x47
273 273
274#endif 274#endif
diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index 3b20c86cdb01..549d5d6a3fef 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -17,6 +17,7 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/of_gpio.h>
20#include <linux/pm.h> 21#include <linux/pm.h>
21#include <linux/i2c.h> 22#include <linux/i2c.h>
22#include <linux/regmap.h> 23#include <linux/regmap.h>
@@ -28,6 +29,7 @@
28#include <sound/soc-dapm.h> 29#include <sound/soc-dapm.h>
29#include <sound/initval.h> 30#include <sound/initval.h>
30#include <sound/tlv.h> 31#include <sound/tlv.h>
32#include <sound/cs42l73.h>
31#include "cs42l73.h" 33#include "cs42l73.h"
32 34
33struct sp_config { 35struct sp_config {
@@ -35,6 +37,7 @@ struct sp_config {
35 u32 srate; 37 u32 srate;
36}; 38};
37struct cs42l73_private { 39struct cs42l73_private {
40 struct cs42l73_platform_data pdata;
38 struct sp_config config[3]; 41 struct sp_config config[3];
39 struct regmap *regmap; 42 struct regmap *regmap;
40 u32 sysclk; 43 u32 sysclk;
@@ -310,15 +313,6 @@ static const struct soc_enum ng_delay_enum =
310 SOC_ENUM_SINGLE(CS42L73_NGCAB, 0, 313 SOC_ENUM_SINGLE(CS42L73_NGCAB, 0,
311 ARRAY_SIZE(cs42l73_ng_delay_text), cs42l73_ng_delay_text); 314 ARRAY_SIZE(cs42l73_ng_delay_text), cs42l73_ng_delay_text);
312 315
313static const char * const charge_pump_freq_text[] = {
314 "0", "1", "2", "3", "4",
315 "5", "6", "7", "8", "9",
316 "10", "11", "12", "13", "14", "15" };
317
318static const struct soc_enum charge_pump_enum =
319 SOC_ENUM_SINGLE(CS42L73_CPFCHC, 4,
320 ARRAY_SIZE(charge_pump_freq_text), charge_pump_freq_text);
321
322static const char * const cs42l73_mono_mix_texts[] = { 316static const char * const cs42l73_mono_mix_texts[] = {
323 "Left", "Right", "Mono Mix"}; 317 "Left", "Right", "Mono Mix"};
324 318
@@ -511,8 +505,6 @@ static const struct snd_kcontrol_new cs42l73_snd_controls[] = {
511 SOC_SINGLE("NG Threshold", CS42L73_NGCAB, 2, 7, 0), 505 SOC_SINGLE("NG Threshold", CS42L73_NGCAB, 2, 7, 0),
512 SOC_ENUM("NG Delay", ng_delay_enum), 506 SOC_ENUM("NG Delay", ng_delay_enum),
513 507
514 SOC_ENUM("Charge Pump Frequency", charge_pump_enum),
515
516 SOC_DOUBLE_R_TLV("XSP-IP Volume", 508 SOC_DOUBLE_R_TLV("XSP-IP Volume",
517 CS42L73_XSPAIPAA, CS42L73_XSPBIPBA, 0, 0x3F, 1, 509 CS42L73_XSPAIPAA, CS42L73_XSPBIPBA, 0, 0x3F, 1,
518 attn_tlv), 510 attn_tlv),
@@ -1055,11 +1047,11 @@ static int cs42l73_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1055 1047
1056 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1048 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1057 case SND_SOC_DAIFMT_CBM_CFM: 1049 case SND_SOC_DAIFMT_CBM_CFM:
1058 mmcc |= MS_MASTER; 1050 mmcc |= CS42L73_MS_MASTER;
1059 break; 1051 break;
1060 1052
1061 case SND_SOC_DAIFMT_CBS_CFS: 1053 case SND_SOC_DAIFMT_CBS_CFS:
1062 mmcc &= ~MS_MASTER; 1054 mmcc &= ~CS42L73_MS_MASTER;
1063 break; 1055 break;
1064 1056
1065 default: 1057 default:
@@ -1071,11 +1063,11 @@ static int cs42l73_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1071 1063
1072 switch (format) { 1064 switch (format) {
1073 case SND_SOC_DAIFMT_I2S: 1065 case SND_SOC_DAIFMT_I2S:
1074 spc &= ~SPDIF_PCM; 1066 spc &= ~CS42L73_SPDIF_PCM;
1075 break; 1067 break;
1076 case SND_SOC_DAIFMT_DSP_A: 1068 case SND_SOC_DAIFMT_DSP_A:
1077 case SND_SOC_DAIFMT_DSP_B: 1069 case SND_SOC_DAIFMT_DSP_B:
1078 if (mmcc & MS_MASTER) { 1070 if (mmcc & CS42L73_MS_MASTER) {
1079 dev_err(codec->dev, 1071 dev_err(codec->dev,
1080 "PCM format in slave mode only\n"); 1072 "PCM format in slave mode only\n");
1081 return -EINVAL; 1073 return -EINVAL;
@@ -1085,25 +1077,25 @@ static int cs42l73_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1085 "PCM format is not supported on ASP port\n"); 1077 "PCM format is not supported on ASP port\n");
1086 return -EINVAL; 1078 return -EINVAL;
1087 } 1079 }
1088 spc |= SPDIF_PCM; 1080 spc |= CS42L73_SPDIF_PCM;
1089 break; 1081 break;
1090 default: 1082 default:
1091 return -EINVAL; 1083 return -EINVAL;
1092 } 1084 }
1093 1085
1094 if (spc & SPDIF_PCM) { 1086 if (spc & CS42L73_SPDIF_PCM) {
1095 /* Clear PCM mode, clear PCM_BIT_ORDER bit for MSB->LSB */ 1087 /* Clear PCM mode, clear PCM_BIT_ORDER bit for MSB->LSB */
1096 spc &= ~(PCM_MODE_MASK | PCM_BIT_ORDER); 1088 spc &= ~(CS42L73_PCM_MODE_MASK | CS42L73_PCM_BIT_ORDER);
1097 switch (format) { 1089 switch (format) {
1098 case SND_SOC_DAIFMT_DSP_B: 1090 case SND_SOC_DAIFMT_DSP_B:
1099 if (inv == SND_SOC_DAIFMT_IB_IF) 1091 if (inv == SND_SOC_DAIFMT_IB_IF)
1100 spc |= PCM_MODE0; 1092 spc |= CS42L73_PCM_MODE0;
1101 if (inv == SND_SOC_DAIFMT_IB_NF) 1093 if (inv == SND_SOC_DAIFMT_IB_NF)
1102 spc |= PCM_MODE1; 1094 spc |= CS42L73_PCM_MODE1;
1103 break; 1095 break;
1104 case SND_SOC_DAIFMT_DSP_A: 1096 case SND_SOC_DAIFMT_DSP_A:
1105 if (inv == SND_SOC_DAIFMT_IB_IF) 1097 if (inv == SND_SOC_DAIFMT_IB_IF)
1106 spc |= PCM_MODE1; 1098 spc |= CS42L73_PCM_MODE1;
1107 break; 1099 break;
1108 default: 1100 default:
1109 return -EINVAL; 1101 return -EINVAL;
@@ -1163,7 +1155,7 @@ static int cs42l73_pcm_hw_params(struct snd_pcm_substream *substream,
1163 int mclk_coeff; 1155 int mclk_coeff;
1164 int srate = params_rate(params); 1156 int srate = params_rate(params);
1165 1157
1166 if (priv->config[id].mmcc & MS_MASTER) { 1158 if (priv->config[id].mmcc & CS42L73_MS_MASTER) {
1167 /* CS42L73 Master */ 1159 /* CS42L73 Master */
1168 /* MCLK -> srate */ 1160 /* MCLK -> srate */
1169 mclk_coeff = 1161 mclk_coeff =
@@ -1182,13 +1174,13 @@ static int cs42l73_pcm_hw_params(struct snd_pcm_substream *substream,
1182 priv->config[id].spc &= 0xFC; 1174 priv->config[id].spc &= 0xFC;
1183 /* Use SCLK=64*Fs if internal MCLK >= 6.4MHz */ 1175 /* Use SCLK=64*Fs if internal MCLK >= 6.4MHz */
1184 if (priv->mclk >= 6400000) 1176 if (priv->mclk >= 6400000)
1185 priv->config[id].spc |= MCK_SCLK_64FS; 1177 priv->config[id].spc |= CS42L73_MCK_SCLK_64FS;
1186 else 1178 else
1187 priv->config[id].spc |= MCK_SCLK_MCLK; 1179 priv->config[id].spc |= CS42L73_MCK_SCLK_MCLK;
1188 } else { 1180 } else {
1189 /* CS42L73 Slave */ 1181 /* CS42L73 Slave */
1190 priv->config[id].spc &= 0xFC; 1182 priv->config[id].spc &= 0xFC;
1191 priv->config[id].spc |= MCK_SCLK_64FS; 1183 priv->config[id].spc |= CS42L73_MCK_SCLK_64FS;
1192 } 1184 }
1193 /* Update ASRCs */ 1185 /* Update ASRCs */
1194 priv->config[id].srate = srate; 1186 priv->config[id].srate = srate;
@@ -1208,8 +1200,8 @@ static int cs42l73_set_bias_level(struct snd_soc_codec *codec,
1208 1200
1209 switch (level) { 1201 switch (level) {
1210 case SND_SOC_BIAS_ON: 1202 case SND_SOC_BIAS_ON:
1211 snd_soc_update_bits(codec, CS42L73_DMMCC, MCLKDIS, 0); 1203 snd_soc_update_bits(codec, CS42L73_DMMCC, CS42L73_MCLKDIS, 0);
1212 snd_soc_update_bits(codec, CS42L73_PWRCTL1, PDN, 0); 1204 snd_soc_update_bits(codec, CS42L73_PWRCTL1, CS42L73_PDN, 0);
1213 break; 1205 break;
1214 1206
1215 case SND_SOC_BIAS_PREPARE: 1207 case SND_SOC_BIAS_PREPARE:
@@ -1220,11 +1212,11 @@ static int cs42l73_set_bias_level(struct snd_soc_codec *codec,
1220 regcache_cache_only(cs42l73->regmap, false); 1212 regcache_cache_only(cs42l73->regmap, false);
1221 regcache_sync(cs42l73->regmap); 1213 regcache_sync(cs42l73->regmap);
1222 } 1214 }
1223 snd_soc_update_bits(codec, CS42L73_PWRCTL1, PDN, 1); 1215 snd_soc_update_bits(codec, CS42L73_PWRCTL1, CS42L73_PDN, 1);
1224 break; 1216 break;
1225 1217
1226 case SND_SOC_BIAS_OFF: 1218 case SND_SOC_BIAS_OFF:
1227 snd_soc_update_bits(codec, CS42L73_PWRCTL1, PDN, 1); 1219 snd_soc_update_bits(codec, CS42L73_PWRCTL1, CS42L73_PDN, 1);
1228 if (cs42l73->shutdwn_delay > 0) { 1220 if (cs42l73->shutdwn_delay > 0) {
1229 mdelay(cs42l73->shutdwn_delay); 1221 mdelay(cs42l73->shutdwn_delay);
1230 cs42l73->shutdwn_delay = 0; 1222 cs42l73->shutdwn_delay = 0;
@@ -1233,7 +1225,7 @@ static int cs42l73_set_bias_level(struct snd_soc_codec *codec,
1233 * down. 1225 * down.
1234 */ 1226 */
1235 } 1227 }
1236 snd_soc_update_bits(codec, CS42L73_DMMCC, MCLKDIS, 1); 1228 snd_soc_update_bits(codec, CS42L73_DMMCC, CS42L73_MCLKDIS, 1);
1237 break; 1229 break;
1238 } 1230 }
1239 codec->dapm.bias_level = level; 1231 codec->dapm.bias_level = level;
@@ -1367,11 +1359,16 @@ static int cs42l73_probe(struct snd_soc_codec *codec)
1367 return ret; 1359 return ret;
1368 } 1360 }
1369 1361
1370 regcache_cache_only(cs42l73->regmap, true);
1371
1372 cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1362 cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1373 1363
1374 cs42l73->mclksel = CS42L73_CLKID_MCLK1; /* MCLK1 as master clk */ 1364 /* Set Charge Pump Frequency */
1365 if (cs42l73->pdata.chgfreq)
1366 snd_soc_update_bits(codec, CS42L73_CPFCHC,
1367 CS42L73_CHARGEPUMP_MASK,
1368 cs42l73->pdata.chgfreq << 4);
1369
1370 /* MCLK1 as master clk */
1371 cs42l73->mclksel = CS42L73_CLKID_MCLK1;
1375 cs42l73->mclk = 0; 1372 cs42l73->mclk = 0;
1376 1373
1377 return ret; 1374 return ret;
@@ -1415,9 +1412,11 @@ static int cs42l73_i2c_probe(struct i2c_client *i2c_client,
1415 const struct i2c_device_id *id) 1412 const struct i2c_device_id *id)
1416{ 1413{
1417 struct cs42l73_private *cs42l73; 1414 struct cs42l73_private *cs42l73;
1415 struct cs42l73_platform_data *pdata = dev_get_platdata(&i2c_client->dev);
1418 int ret; 1416 int ret;
1419 unsigned int devid = 0; 1417 unsigned int devid = 0;
1420 unsigned int reg; 1418 unsigned int reg;
1419 u32 val32;
1421 1420
1422 cs42l73 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l73_private), 1421 cs42l73 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l73_private),
1423 GFP_KERNEL); 1422 GFP_KERNEL);
@@ -1426,14 +1425,49 @@ static int cs42l73_i2c_probe(struct i2c_client *i2c_client,
1426 return -ENOMEM; 1425 return -ENOMEM;
1427 } 1426 }
1428 1427
1429 i2c_set_clientdata(i2c_client, cs42l73);
1430
1431 cs42l73->regmap = devm_regmap_init_i2c(i2c_client, &cs42l73_regmap); 1428 cs42l73->regmap = devm_regmap_init_i2c(i2c_client, &cs42l73_regmap);
1432 if (IS_ERR(cs42l73->regmap)) { 1429 if (IS_ERR(cs42l73->regmap)) {
1433 ret = PTR_ERR(cs42l73->regmap); 1430 ret = PTR_ERR(cs42l73->regmap);
1434 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); 1431 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret);
1435 return ret; 1432 return ret;
1436 } 1433 }
1434
1435 if (pdata) {
1436 cs42l73->pdata = *pdata;
1437 } else {
1438 pdata = devm_kzalloc(&i2c_client->dev,
1439 sizeof(struct cs42l73_platform_data),
1440 GFP_KERNEL);
1441 if (!pdata) {
1442 dev_err(&i2c_client->dev, "could not allocate pdata\n");
1443 return -ENOMEM;
1444 }
1445 if (i2c_client->dev.of_node) {
1446 if (of_property_read_u32(i2c_client->dev.of_node,
1447 "chgfreq", &val32) >= 0)
1448 pdata->chgfreq = val32;
1449 }
1450 pdata->reset_gpio = of_get_named_gpio(i2c_client->dev.of_node,
1451 "reset-gpio", 0);
1452 cs42l73->pdata = *pdata;
1453 }
1454
1455 i2c_set_clientdata(i2c_client, cs42l73);
1456
1457 if (cs42l73->pdata.reset_gpio) {
1458 ret = gpio_request_one(cs42l73->pdata.reset_gpio,
1459 GPIOF_OUT_INIT_HIGH, "CS42L73 /RST");
1460 if (ret < 0) {
1461 dev_err(&i2c_client->dev, "Failed to request /RST %d: %d\n",
1462 cs42l73->pdata.reset_gpio, ret);
1463 return ret;
1464 }
1465 gpio_set_value_cansleep(cs42l73->pdata.reset_gpio, 0);
1466 gpio_set_value_cansleep(cs42l73->pdata.reset_gpio, 1);
1467 }
1468
1469 regcache_cache_bypass(cs42l73->regmap, true);
1470
1437 /* initialize codec */ 1471 /* initialize codec */
1438 ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_AB, &reg); 1472 ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_AB, &reg);
1439 devid = (reg & 0xFF) << 12; 1473 devid = (reg & 0xFF) << 12;
@@ -1444,7 +1478,6 @@ static int cs42l73_i2c_probe(struct i2c_client *i2c_client,
1444 ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_E, &reg); 1478 ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_E, &reg);
1445 devid |= (reg & 0xF0) >> 4; 1479 devid |= (reg & 0xF0) >> 4;
1446 1480
1447
1448 if (devid != CS42L73_DEVID) { 1481 if (devid != CS42L73_DEVID) {
1449 ret = -ENODEV; 1482 ret = -ENODEV;
1450 dev_err(&i2c_client->dev, 1483 dev_err(&i2c_client->dev,
@@ -1462,7 +1495,7 @@ static int cs42l73_i2c_probe(struct i2c_client *i2c_client,
1462 dev_info(&i2c_client->dev, 1495 dev_info(&i2c_client->dev,
1463 "Cirrus Logic CS42L73, Revision: %02X\n", reg & 0xFF); 1496 "Cirrus Logic CS42L73, Revision: %02X\n", reg & 0xFF);
1464 1497
1465 regcache_cache_only(cs42l73->regmap, true); 1498 regcache_cache_bypass(cs42l73->regmap, false);
1466 1499
1467 ret = snd_soc_register_codec(&i2c_client->dev, 1500 ret = snd_soc_register_codec(&i2c_client->dev,
1468 &soc_codec_dev_cs42l73, cs42l73_dai, 1501 &soc_codec_dev_cs42l73, cs42l73_dai,
@@ -1478,6 +1511,12 @@ static int cs42l73_i2c_remove(struct i2c_client *client)
1478 return 0; 1511 return 0;
1479} 1512}
1480 1513
1514static const struct of_device_id cs42l73_of_match[] = {
1515 { .compatible = "cirrus,cs42l73", },
1516 {},
1517};
1518MODULE_DEVICE_TABLE(of, cs42l73_of_match);
1519
1481static const struct i2c_device_id cs42l73_id[] = { 1520static const struct i2c_device_id cs42l73_id[] = {
1482 {"cs42l73", 0}, 1521 {"cs42l73", 0},
1483 {} 1522 {}
@@ -1489,6 +1528,7 @@ static struct i2c_driver cs42l73_i2c_driver = {
1489 .driver = { 1528 .driver = {
1490 .name = "cs42l73", 1529 .name = "cs42l73",
1491 .owner = THIS_MODULE, 1530 .owner = THIS_MODULE,
1531 .of_match_table = cs42l73_of_match,
1492 }, 1532 },
1493 .id_table = cs42l73_id, 1533 .id_table = cs42l73_id,
1494 .probe = cs42l73_i2c_probe, 1534 .probe = cs42l73_i2c_probe,
diff --git a/sound/soc/codecs/cs42l73.h b/sound/soc/codecs/cs42l73.h
index f30a4c4d62e6..45746186a678 100644
--- a/sound/soc/codecs/cs42l73.h
+++ b/sound/soc/codecs/cs42l73.h
@@ -128,59 +128,60 @@
128/* Bitfield Definitions */ 128/* Bitfield Definitions */
129 129
130/* CS42L73_PWRCTL1 */ 130/* CS42L73_PWRCTL1 */
131#define PDN_ADCB (1 << 7) 131#define CS42L73_PDN_ADCB (1 << 7)
132#define PDN_DMICB (1 << 6) 132#define CS42L73_PDN_DMICB (1 << 6)
133#define PDN_ADCA (1 << 5) 133#define CS42L73_PDN_ADCA (1 << 5)
134#define PDN_DMICA (1 << 4) 134#define CS42L73_PDN_DMICA (1 << 4)
135#define PDN_LDO (1 << 2) 135#define CS42L73_PDN_LDO (1 << 2)
136#define DISCHG_FILT (1 << 1) 136#define CS42L73_DISCHG_FILT (1 << 1)
137#define PDN (1 << 0) 137#define CS42L73_PDN (1 << 0)
138 138
139/* CS42L73_PWRCTL2 */ 139/* CS42L73_PWRCTL2 */
140#define PDN_MIC2_BIAS (1 << 7) 140#define CS42L73_PDN_MIC2_BIAS (1 << 7)
141#define PDN_MIC1_BIAS (1 << 6) 141#define CS42L73_PDN_MIC1_BIAS (1 << 6)
142#define PDN_VSP (1 << 4) 142#define CS42L73_PDN_VSP (1 << 4)
143#define PDN_ASP_SDOUT (1 << 3) 143#define CS42L73_PDN_ASP_SDOUT (1 << 3)
144#define PDN_ASP_SDIN (1 << 2) 144#define CS42L73_PDN_ASP_SDIN (1 << 2)
145#define PDN_XSP_SDOUT (1 << 1) 145#define CS42L73_PDN_XSP_SDOUT (1 << 1)
146#define PDN_XSP_SDIN (1 << 0) 146#define CS42L73_PDN_XSP_SDIN (1 << 0)
147 147
148/* CS42L73_PWRCTL3 */ 148/* CS42L73_PWRCTL3 */
149#define PDN_THMS (1 << 5) 149#define CS42L73_PDN_THMS (1 << 5)
150#define PDN_SPKLO (1 << 4) 150#define CS42L73_PDN_SPKLO (1 << 4)
151#define PDN_EAR (1 << 3) 151#define CS42L73_PDN_EAR (1 << 3)
152#define PDN_SPK (1 << 2) 152#define CS42L73_PDN_SPK (1 << 2)
153#define PDN_LO (1 << 1) 153#define CS42L73_PDN_LO (1 << 1)
154#define PDN_HP (1 << 0) 154#define CS42L73_PDN_HP (1 << 0)
155 155
156/* Thermal Overload Detect. Requires interrupt ... */ 156/* Thermal Overload Detect. Requires interrupt ... */
157#define THMOVLD_150C 0 157#define CS42L73_THMOVLD_150C 0
158#define THMOVLD_132C 1 158#define CS42L73_THMOVLD_132C 1
159#define THMOVLD_115C 2 159#define CS42L73_THMOVLD_115C 2
160#define THMOVLD_098C 3 160#define CS42L73_THMOVLD_098C 3
161 161
162#define CS42L73_CHARGEPUMP_MASK (0xF0)
162 163
163/* CS42L73_ASPC, CS42L73_XSPC, CS42L73_VSPC */ 164/* CS42L73_ASPC, CS42L73_XSPC, CS42L73_VSPC */
164#define SP_3ST (1 << 7) 165#define CS42L73_SP_3ST (1 << 7)
165#define SPDIF_I2S (0 << 6) 166#define CS42L73_SPDIF_I2S (0 << 6)
166#define SPDIF_PCM (1 << 6) 167#define CS42L73_SPDIF_PCM (1 << 6)
167#define PCM_MODE0 (0 << 4) 168#define CS42L73_PCM_MODE0 (0 << 4)
168#define PCM_MODE1 (1 << 4) 169#define CS42L73_PCM_MODE1 (1 << 4)
169#define PCM_MODE2 (2 << 4) 170#define CS42L73_PCM_MODE2 (2 << 4)
170#define PCM_MODE_MASK (3 << 4) 171#define CS42L73_PCM_MODE_MASK (3 << 4)
171#define PCM_BIT_ORDER (1 << 3) 172#define CS42L73_PCM_BIT_ORDER (1 << 3)
172#define MCK_SCLK_64FS (0 << 0) 173#define CS42L73_MCK_SCLK_64FS (0 << 0)
173#define MCK_SCLK_MCLK (2 << 0) 174#define CS42L73_MCK_SCLK_MCLK (2 << 0)
174#define MCK_SCLK_PREMCLK (3 << 0) 175#define CS42L73_MCK_SCLK_PREMCLK (3 << 0)
175 176
176/* CS42L73_xSPMMCC */ 177/* CS42L73_xSPMMCC */
177#define MS_MASTER (1 << 7) 178#define CS42L73_MS_MASTER (1 << 7)
178 179
179 180
180/* CS42L73_DMMCC */ 181/* CS42L73_DMMCC */
181#define MCLKDIS (1 << 0) 182#define CS42L73_MCLKDIS (1 << 0)
182#define MCLKSEL_MCLK2 (1 << 4) 183#define CS42L73_MCLKSEL_MCLK2 (1 << 4)
183#define MCLKSEL_MCLK1 (0 << 4) 184#define CS42L73_MCLKSEL_MCLK1 (0 << 4)
184 185
185/* CS42L73 MCLK derived from MCLK1 or MCLK2 */ 186/* CS42L73 MCLK derived from MCLK1 or MCLK2 */
186#define CS42L73_CLKID_MCLK1 0 187#define CS42L73_CLKID_MCLK1 0
@@ -194,28 +195,26 @@
194#define CS42L73_VSP 2 195#define CS42L73_VSP 2
195 196
196/* IS1, IM1 */ 197/* IS1, IM1 */
197#define MIC2_SDET (1 << 6) 198#define CS42L73_MIC2_SDET (1 << 6)
198#define THMOVLD (1 << 4) 199#define CS42L73_THMOVLD (1 << 4)
199#define DIGMIXOVFL (1 << 3) 200#define CS42L73_DIGMIXOVFL (1 << 3)
200#define IPBOVFL (1 << 1) 201#define CS42L73_IPBOVFL (1 << 1)
201#define IPAOVFL (1 << 0) 202#define CS42L73_IPAOVFL (1 << 0)
202 203
203/* Analog Softramp */ 204/* Analog Softramp */
204#define ANLGOSFT (1 << 0) 205#define CS42L73_ANLGOSFT (1 << 0)
205 206
206/* HP A/B Analog Mute */ 207/* HP A/B Analog Mute */
207#define HPA_MUTE (1 << 7) 208#define CS42L73_HPA_MUTE (1 << 7)
208/* LO A/B Analog Mute */ 209/* LO A/B Analog Mute */
209#define LOA_MUTE (1 << 7) 210#define CS42L73_LOA_MUTE (1 << 7)
210/* Digital Mute */ 211/* Digital Mute */
211#define HLAD_MUTE (1 << 0) 212#define CS42L73_HLAD_MUTE (1 << 0)
212#define HLBD_MUTE (1 << 1) 213#define CS42L73_HLBD_MUTE (1 << 1)
213#define SPKD_MUTE (1 << 2) 214#define CS42L73_SPKD_MUTE (1 << 2)
214#define ESLD_MUTE (1 << 3) 215#define CS42L73_ESLD_MUTE (1 << 3)
215 216
216/* Misc defines for codec */ 217/* Misc defines for codec */
217#define CS42L73_RESET_GPIO 143
218
219#define CS42L73_DEVID 0x00042A73 218#define CS42L73_DEVID 0x00042A73
220#define CS42L73_MCLKX_MIN 5644800 219#define CS42L73_MCLKX_MIN 5644800
221#define CS42L73_MCLKX_MAX 38400000 220#define CS42L73_MCLKX_MAX 38400000
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 566a367c94fa..53d7dab4e054 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -15,6 +15,7 @@
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/pm.h> 16#include <linux/pm.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/regmap.h>
18#include <sound/core.h> 19#include <sound/core.h>
19#include <sound/pcm.h> 20#include <sound/pcm.h>
20#include <sound/pcm_params.h> 21#include <sound/pcm_params.h>
@@ -38,294 +39,223 @@ struct max98088_cdata {
38}; 39};
39 40
40struct max98088_priv { 41struct max98088_priv {
41 enum max98088_type devtype; 42 struct regmap *regmap;
42 struct max98088_pdata *pdata; 43 enum max98088_type devtype;
43 unsigned int sysclk; 44 struct max98088_pdata *pdata;
44 struct max98088_cdata dai[2]; 45 unsigned int sysclk;
45 int eq_textcnt; 46 struct max98088_cdata dai[2];
46 const char **eq_texts; 47 int eq_textcnt;
47 struct soc_enum eq_enum; 48 const char **eq_texts;
48 u8 ina_state; 49 struct soc_enum eq_enum;
49 u8 inb_state; 50 u8 ina_state;
50 unsigned int ex_mode; 51 u8 inb_state;
51 unsigned int digmic; 52 unsigned int ex_mode;
52 unsigned int mic1pre; 53 unsigned int digmic;
53 unsigned int mic2pre; 54 unsigned int mic1pre;
54 unsigned int extmic_mode; 55 unsigned int mic2pre;
56 unsigned int extmic_mode;
55}; 57};
56 58
57static const u8 max98088_reg[M98088_REG_CNT] = { 59static const struct reg_default max98088_reg[] = {
58 0x00, /* 00 IRQ status */ 60 { 0xf, 0x00 }, /* 0F interrupt enable */
59 0x00, /* 01 MIC status */ 61
60 0x00, /* 02 jack status */ 62 { 0x10, 0x00 }, /* 10 master clock */
61 0x00, /* 03 battery voltage */ 63 { 0x11, 0x00 }, /* 11 DAI1 clock mode */
62 0x00, /* 04 */ 64 { 0x12, 0x00 }, /* 12 DAI1 clock control */
63 0x00, /* 05 */ 65 { 0x13, 0x00 }, /* 13 DAI1 clock control */
64 0x00, /* 06 */ 66 { 0x14, 0x00 }, /* 14 DAI1 format */
65 0x00, /* 07 */ 67 { 0x15, 0x00 }, /* 15 DAI1 clock */
66 0x00, /* 08 */ 68 { 0x16, 0x00 }, /* 16 DAI1 config */
67 0x00, /* 09 */ 69 { 0x17, 0x00 }, /* 17 DAI1 TDM */
68 0x00, /* 0A */ 70 { 0x18, 0x00 }, /* 18 DAI1 filters */
69 0x00, /* 0B */ 71 { 0x19, 0x00 }, /* 19 DAI2 clock mode */
70 0x00, /* 0C */ 72 { 0x1a, 0x00 }, /* 1A DAI2 clock control */
71 0x00, /* 0D */ 73 { 0x1b, 0x00 }, /* 1B DAI2 clock control */
72 0x00, /* 0E */ 74 { 0x1c, 0x00 }, /* 1C DAI2 format */
73 0x00, /* 0F interrupt enable */ 75 { 0x1d, 0x00 }, /* 1D DAI2 clock */
74 76 { 0x1e, 0x00 }, /* 1E DAI2 config */
75 0x00, /* 10 master clock */ 77 { 0x1f, 0x00 }, /* 1F DAI2 TDM */
76 0x00, /* 11 DAI1 clock mode */ 78
77 0x00, /* 12 DAI1 clock control */ 79 { 0x20, 0x00 }, /* 20 DAI2 filters */
78 0x00, /* 13 DAI1 clock control */ 80 { 0x21, 0x00 }, /* 21 data config */
79 0x00, /* 14 DAI1 format */ 81 { 0x22, 0x00 }, /* 22 DAC mixer */
80 0x00, /* 15 DAI1 clock */ 82 { 0x23, 0x00 }, /* 23 left ADC mixer */
81 0x00, /* 16 DAI1 config */ 83 { 0x24, 0x00 }, /* 24 right ADC mixer */
82 0x00, /* 17 DAI1 TDM */ 84 { 0x25, 0x00 }, /* 25 left HP mixer */
83 0x00, /* 18 DAI1 filters */ 85 { 0x26, 0x00 }, /* 26 right HP mixer */
84 0x00, /* 19 DAI2 clock mode */ 86 { 0x27, 0x00 }, /* 27 HP control */
85 0x00, /* 1A DAI2 clock control */ 87 { 0x28, 0x00 }, /* 28 left REC mixer */
86 0x00, /* 1B DAI2 clock control */ 88 { 0x29, 0x00 }, /* 29 right REC mixer */
87 0x00, /* 1C DAI2 format */ 89 { 0x2a, 0x00 }, /* 2A REC control */
88 0x00, /* 1D DAI2 clock */ 90 { 0x2b, 0x00 }, /* 2B left SPK mixer */
89 0x00, /* 1E DAI2 config */ 91 { 0x2c, 0x00 }, /* 2C right SPK mixer */
90 0x00, /* 1F DAI2 TDM */ 92 { 0x2d, 0x00 }, /* 2D SPK control */
91 93 { 0x2e, 0x00 }, /* 2E sidetone */
92 0x00, /* 20 DAI2 filters */ 94 { 0x2f, 0x00 }, /* 2F DAI1 playback level */
93 0x00, /* 21 data config */ 95
94 0x00, /* 22 DAC mixer */ 96 { 0x30, 0x00 }, /* 30 DAI1 playback level */
95 0x00, /* 23 left ADC mixer */ 97 { 0x31, 0x00 }, /* 31 DAI2 playback level */
96 0x00, /* 24 right ADC mixer */ 98 { 0x32, 0x00 }, /* 32 DAI2 playbakc level */
97 0x00, /* 25 left HP mixer */ 99 { 0x33, 0x00 }, /* 33 left ADC level */
98 0x00, /* 26 right HP mixer */ 100 { 0x34, 0x00 }, /* 34 right ADC level */
99 0x00, /* 27 HP control */ 101 { 0x35, 0x00 }, /* 35 MIC1 level */
100 0x00, /* 28 left REC mixer */ 102 { 0x36, 0x00 }, /* 36 MIC2 level */
101 0x00, /* 29 right REC mixer */ 103 { 0x37, 0x00 }, /* 37 INA level */
102 0x00, /* 2A REC control */ 104 { 0x38, 0x00 }, /* 38 INB level */
103 0x00, /* 2B left SPK mixer */ 105 { 0x39, 0x00 }, /* 39 left HP volume */
104 0x00, /* 2C right SPK mixer */ 106 { 0x3a, 0x00 }, /* 3A right HP volume */
105 0x00, /* 2D SPK control */ 107 { 0x3b, 0x00 }, /* 3B left REC volume */
106 0x00, /* 2E sidetone */ 108 { 0x3c, 0x00 }, /* 3C right REC volume */
107 0x00, /* 2F DAI1 playback level */ 109 { 0x3d, 0x00 }, /* 3D left SPK volume */
108 110 { 0x3e, 0x00 }, /* 3E right SPK volume */
109 0x00, /* 30 DAI1 playback level */ 111 { 0x3f, 0x00 }, /* 3F MIC config */
110 0x00, /* 31 DAI2 playback level */ 112
111 0x00, /* 32 DAI2 playbakc level */ 113 { 0x40, 0x00 }, /* 40 MIC threshold */
112 0x00, /* 33 left ADC level */ 114 { 0x41, 0x00 }, /* 41 excursion limiter filter */
113 0x00, /* 34 right ADC level */ 115 { 0x42, 0x00 }, /* 42 excursion limiter threshold */
114 0x00, /* 35 MIC1 level */ 116 { 0x43, 0x00 }, /* 43 ALC */
115 0x00, /* 36 MIC2 level */ 117 { 0x44, 0x00 }, /* 44 power limiter threshold */
116 0x00, /* 37 INA level */ 118 { 0x45, 0x00 }, /* 45 power limiter config */
117 0x00, /* 38 INB level */ 119 { 0x46, 0x00 }, /* 46 distortion limiter config */
118 0x00, /* 39 left HP volume */ 120 { 0x47, 0x00 }, /* 47 audio input */
119 0x00, /* 3A right HP volume */ 121 { 0x48, 0x00 }, /* 48 microphone */
120 0x00, /* 3B left REC volume */ 122 { 0x49, 0x00 }, /* 49 level control */
121 0x00, /* 3C right REC volume */ 123 { 0x4a, 0x00 }, /* 4A bypass switches */
122 0x00, /* 3D left SPK volume */ 124 { 0x4b, 0x00 }, /* 4B jack detect */
123 0x00, /* 3E right SPK volume */ 125 { 0x4c, 0x00 }, /* 4C input enable */
124 0x00, /* 3F MIC config */ 126 { 0x4d, 0x00 }, /* 4D output enable */
125 127 { 0x4e, 0xF0 }, /* 4E bias control */
126 0x00, /* 40 MIC threshold */ 128 { 0x4f, 0x00 }, /* 4F DAC power */
127 0x00, /* 41 excursion limiter filter */ 129
128 0x00, /* 42 excursion limiter threshold */ 130 { 0x50, 0x0F }, /* 50 DAC power */
129 0x00, /* 43 ALC */ 131 { 0x51, 0x00 }, /* 51 system */
130 0x00, /* 44 power limiter threshold */ 132 { 0x52, 0x00 }, /* 52 DAI1 EQ1 */
131 0x00, /* 45 power limiter config */ 133 { 0x53, 0x00 }, /* 53 DAI1 EQ1 */
132 0x00, /* 46 distortion limiter config */ 134 { 0x54, 0x00 }, /* 54 DAI1 EQ1 */
133 0x00, /* 47 audio input */ 135 { 0x55, 0x00 }, /* 55 DAI1 EQ1 */
134 0x00, /* 48 microphone */ 136 { 0x56, 0x00 }, /* 56 DAI1 EQ1 */
135 0x00, /* 49 level control */ 137 { 0x57, 0x00 }, /* 57 DAI1 EQ1 */
136 0x00, /* 4A bypass switches */ 138 { 0x58, 0x00 }, /* 58 DAI1 EQ1 */
137 0x00, /* 4B jack detect */ 139 { 0x59, 0x00 }, /* 59 DAI1 EQ1 */
138 0x00, /* 4C input enable */ 140 { 0x5a, 0x00 }, /* 5A DAI1 EQ1 */
139 0x00, /* 4D output enable */ 141 { 0x5b, 0x00 }, /* 5B DAI1 EQ1 */
140 0xF0, /* 4E bias control */ 142 { 0x5c, 0x00 }, /* 5C DAI1 EQ2 */
141 0x00, /* 4F DAC power */ 143 { 0x5d, 0x00 }, /* 5D DAI1 EQ2 */
142 144 { 0x5e, 0x00 }, /* 5E DAI1 EQ2 */
143 0x0F, /* 50 DAC power */ 145 { 0x5f, 0x00 }, /* 5F DAI1 EQ2 */
144 0x00, /* 51 system */ 146
145 0x00, /* 52 DAI1 EQ1 */ 147 { 0x60, 0x00 }, /* 60 DAI1 EQ2 */
146 0x00, /* 53 DAI1 EQ1 */ 148 { 0x61, 0x00 }, /* 61 DAI1 EQ2 */
147 0x00, /* 54 DAI1 EQ1 */ 149 { 0x62, 0x00 }, /* 62 DAI1 EQ2 */
148 0x00, /* 55 DAI1 EQ1 */ 150 { 0x63, 0x00 }, /* 63 DAI1 EQ2 */
149 0x00, /* 56 DAI1 EQ1 */ 151 { 0x64, 0x00 }, /* 64 DAI1 EQ2 */
150 0x00, /* 57 DAI1 EQ1 */ 152 { 0x65, 0x00 }, /* 65 DAI1 EQ2 */
151 0x00, /* 58 DAI1 EQ1 */ 153 { 0x66, 0x00 }, /* 66 DAI1 EQ3 */
152 0x00, /* 59 DAI1 EQ1 */ 154 { 0x67, 0x00 }, /* 67 DAI1 EQ3 */
153 0x00, /* 5A DAI1 EQ1 */ 155 { 0x68, 0x00 }, /* 68 DAI1 EQ3 */
154 0x00, /* 5B DAI1 EQ1 */ 156 { 0x69, 0x00 }, /* 69 DAI1 EQ3 */
155 0x00, /* 5C DAI1 EQ2 */ 157 { 0x6a, 0x00 }, /* 6A DAI1 EQ3 */
156 0x00, /* 5D DAI1 EQ2 */ 158 { 0x6b, 0x00 }, /* 6B DAI1 EQ3 */
157 0x00, /* 5E DAI1 EQ2 */ 159 { 0x6c, 0x00 }, /* 6C DAI1 EQ3 */
158 0x00, /* 5F DAI1 EQ2 */ 160 { 0x6d, 0x00 }, /* 6D DAI1 EQ3 */
159 161 { 0x6e, 0x00 }, /* 6E DAI1 EQ3 */
160 0x00, /* 60 DAI1 EQ2 */ 162 { 0x6f, 0x00 }, /* 6F DAI1 EQ3 */
161 0x00, /* 61 DAI1 EQ2 */ 163
162 0x00, /* 62 DAI1 EQ2 */ 164 { 0x70, 0x00 }, /* 70 DAI1 EQ4 */
163 0x00, /* 63 DAI1 EQ2 */ 165 { 0x71, 0x00 }, /* 71 DAI1 EQ4 */
164 0x00, /* 64 DAI1 EQ2 */ 166 { 0x72, 0x00 }, /* 72 DAI1 EQ4 */
165 0x00, /* 65 DAI1 EQ2 */ 167 { 0x73, 0x00 }, /* 73 DAI1 EQ4 */
166 0x00, /* 66 DAI1 EQ3 */ 168 { 0x74, 0x00 }, /* 74 DAI1 EQ4 */
167 0x00, /* 67 DAI1 EQ3 */ 169 { 0x75, 0x00 }, /* 75 DAI1 EQ4 */
168 0x00, /* 68 DAI1 EQ3 */ 170 { 0x76, 0x00 }, /* 76 DAI1 EQ4 */
169 0x00, /* 69 DAI1 EQ3 */ 171 { 0x77, 0x00 }, /* 77 DAI1 EQ4 */
170 0x00, /* 6A DAI1 EQ3 */ 172 { 0x78, 0x00 }, /* 78 DAI1 EQ4 */
171 0x00, /* 6B DAI1 EQ3 */ 173 { 0x79, 0x00 }, /* 79 DAI1 EQ4 */
172 0x00, /* 6C DAI1 EQ3 */ 174 { 0x7a, 0x00 }, /* 7A DAI1 EQ5 */
173 0x00, /* 6D DAI1 EQ3 */ 175 { 0x7b, 0x00 }, /* 7B DAI1 EQ5 */
174 0x00, /* 6E DAI1 EQ3 */ 176 { 0x7c, 0x00 }, /* 7C DAI1 EQ5 */
175 0x00, /* 6F DAI1 EQ3 */ 177 { 0x7d, 0x00 }, /* 7D DAI1 EQ5 */
176 178 { 0x7e, 0x00 }, /* 7E DAI1 EQ5 */
177 0x00, /* 70 DAI1 EQ4 */ 179 { 0x7f, 0x00 }, /* 7F DAI1 EQ5 */
178 0x00, /* 71 DAI1 EQ4 */ 180
179 0x00, /* 72 DAI1 EQ4 */ 181 { 0x80, 0x00 }, /* 80 DAI1 EQ5 */
180 0x00, /* 73 DAI1 EQ4 */ 182 { 0x81, 0x00 }, /* 81 DAI1 EQ5 */
181 0x00, /* 74 DAI1 EQ4 */ 183 { 0x82, 0x00 }, /* 82 DAI1 EQ5 */
182 0x00, /* 75 DAI1 EQ4 */ 184 { 0x83, 0x00 }, /* 83 DAI1 EQ5 */
183 0x00, /* 76 DAI1 EQ4 */ 185 { 0x84, 0x00 }, /* 84 DAI2 EQ1 */
184 0x00, /* 77 DAI1 EQ4 */ 186 { 0x85, 0x00 }, /* 85 DAI2 EQ1 */
185 0x00, /* 78 DAI1 EQ4 */ 187 { 0x86, 0x00 }, /* 86 DAI2 EQ1 */
186 0x00, /* 79 DAI1 EQ4 */ 188 { 0x87, 0x00 }, /* 87 DAI2 EQ1 */
187 0x00, /* 7A DAI1 EQ5 */ 189 { 0x88, 0x00 }, /* 88 DAI2 EQ1 */
188 0x00, /* 7B DAI1 EQ5 */ 190 { 0x89, 0x00 }, /* 89 DAI2 EQ1 */
189 0x00, /* 7C DAI1 EQ5 */ 191 { 0x8a, 0x00 }, /* 8A DAI2 EQ1 */
190 0x00, /* 7D DAI1 EQ5 */ 192 { 0x8b, 0x00 }, /* 8B DAI2 EQ1 */
191 0x00, /* 7E DAI1 EQ5 */ 193 { 0x8c, 0x00 }, /* 8C DAI2 EQ1 */
192 0x00, /* 7F DAI1 EQ5 */ 194 { 0x8d, 0x00 }, /* 8D DAI2 EQ1 */
193 195 { 0x8e, 0x00 }, /* 8E DAI2 EQ2 */
194 0x00, /* 80 DAI1 EQ5 */ 196 { 0x8f, 0x00 }, /* 8F DAI2 EQ2 */
195 0x00, /* 81 DAI1 EQ5 */ 197
196 0x00, /* 82 DAI1 EQ5 */ 198 { 0x90, 0x00 }, /* 90 DAI2 EQ2 */
197 0x00, /* 83 DAI1 EQ5 */ 199 { 0x91, 0x00 }, /* 91 DAI2 EQ2 */
198 0x00, /* 84 DAI2 EQ1 */ 200 { 0x92, 0x00 }, /* 92 DAI2 EQ2 */
199 0x00, /* 85 DAI2 EQ1 */ 201 { 0x93, 0x00 }, /* 93 DAI2 EQ2 */
200 0x00, /* 86 DAI2 EQ1 */ 202 { 0x94, 0x00 }, /* 94 DAI2 EQ2 */
201 0x00, /* 87 DAI2 EQ1 */ 203 { 0x95, 0x00 }, /* 95 DAI2 EQ2 */
202 0x00, /* 88 DAI2 EQ1 */ 204 { 0x96, 0x00 }, /* 96 DAI2 EQ2 */
203 0x00, /* 89 DAI2 EQ1 */ 205 { 0x97, 0x00 }, /* 97 DAI2 EQ2 */
204 0x00, /* 8A DAI2 EQ1 */ 206 { 0x98, 0x00 }, /* 98 DAI2 EQ3 */
205 0x00, /* 8B DAI2 EQ1 */ 207 { 0x99, 0x00 }, /* 99 DAI2 EQ3 */
206 0x00, /* 8C DAI2 EQ1 */ 208 { 0x9a, 0x00 }, /* 9A DAI2 EQ3 */
207 0x00, /* 8D DAI2 EQ1 */ 209 { 0x9b, 0x00 }, /* 9B DAI2 EQ3 */
208 0x00, /* 8E DAI2 EQ2 */ 210 { 0x9c, 0x00 }, /* 9C DAI2 EQ3 */
209 0x00, /* 8F DAI2 EQ2 */ 211 { 0x9d, 0x00 }, /* 9D DAI2 EQ3 */
210 212 { 0x9e, 0x00 }, /* 9E DAI2 EQ3 */
211 0x00, /* 90 DAI2 EQ2 */ 213 { 0x9f, 0x00 }, /* 9F DAI2 EQ3 */
212 0x00, /* 91 DAI2 EQ2 */ 214
213 0x00, /* 92 DAI2 EQ2 */ 215 { 0xa0, 0x00 }, /* A0 DAI2 EQ3 */
214 0x00, /* 93 DAI2 EQ2 */ 216 { 0xa1, 0x00 }, /* A1 DAI2 EQ3 */
215 0x00, /* 94 DAI2 EQ2 */ 217 { 0xa2, 0x00 }, /* A2 DAI2 EQ4 */
216 0x00, /* 95 DAI2 EQ2 */ 218 { 0xa3, 0x00 }, /* A3 DAI2 EQ4 */
217 0x00, /* 96 DAI2 EQ2 */ 219 { 0xa4, 0x00 }, /* A4 DAI2 EQ4 */
218 0x00, /* 97 DAI2 EQ2 */ 220 { 0xa5, 0x00 }, /* A5 DAI2 EQ4 */
219 0x00, /* 98 DAI2 EQ3 */ 221 { 0xa6, 0x00 }, /* A6 DAI2 EQ4 */
220 0x00, /* 99 DAI2 EQ3 */ 222 { 0xa7, 0x00 }, /* A7 DAI2 EQ4 */
221 0x00, /* 9A DAI2 EQ3 */ 223 { 0xa8, 0x00 }, /* A8 DAI2 EQ4 */
222 0x00, /* 9B DAI2 EQ3 */ 224 { 0xa9, 0x00 }, /* A9 DAI2 EQ4 */
223 0x00, /* 9C DAI2 EQ3 */ 225 { 0xaa, 0x00 }, /* AA DAI2 EQ4 */
224 0x00, /* 9D DAI2 EQ3 */ 226 { 0xab, 0x00 }, /* AB DAI2 EQ4 */
225 0x00, /* 9E DAI2 EQ3 */ 227 { 0xac, 0x00 }, /* AC DAI2 EQ5 */
226 0x00, /* 9F DAI2 EQ3 */ 228 { 0xad, 0x00 }, /* AD DAI2 EQ5 */
227 229 { 0xae, 0x00 }, /* AE DAI2 EQ5 */
228 0x00, /* A0 DAI2 EQ3 */ 230 { 0xaf, 0x00 }, /* AF DAI2 EQ5 */
229 0x00, /* A1 DAI2 EQ3 */ 231
230 0x00, /* A2 DAI2 EQ4 */ 232 { 0xb0, 0x00 }, /* B0 DAI2 EQ5 */
231 0x00, /* A3 DAI2 EQ4 */ 233 { 0xb1, 0x00 }, /* B1 DAI2 EQ5 */
232 0x00, /* A4 DAI2 EQ4 */ 234 { 0xb2, 0x00 }, /* B2 DAI2 EQ5 */
233 0x00, /* A5 DAI2 EQ4 */ 235 { 0xb3, 0x00 }, /* B3 DAI2 EQ5 */
234 0x00, /* A6 DAI2 EQ4 */ 236 { 0xb4, 0x00 }, /* B4 DAI2 EQ5 */
235 0x00, /* A7 DAI2 EQ4 */ 237 { 0xb5, 0x00 }, /* B5 DAI2 EQ5 */
236 0x00, /* A8 DAI2 EQ4 */ 238 { 0xb6, 0x00 }, /* B6 DAI1 biquad */
237 0x00, /* A9 DAI2 EQ4 */ 239 { 0xb7, 0x00 }, /* B7 DAI1 biquad */
238 0x00, /* AA DAI2 EQ4 */ 240 { 0xb8 ,0x00 }, /* B8 DAI1 biquad */
239 0x00, /* AB DAI2 EQ4 */ 241 { 0xb9, 0x00 }, /* B9 DAI1 biquad */
240 0x00, /* AC DAI2 EQ5 */ 242 { 0xba, 0x00 }, /* BA DAI1 biquad */
241 0x00, /* AD DAI2 EQ5 */ 243 { 0xbb, 0x00 }, /* BB DAI1 biquad */
242 0x00, /* AE DAI2 EQ5 */ 244 { 0xbc, 0x00 }, /* BC DAI1 biquad */
243 0x00, /* AF DAI2 EQ5 */ 245 { 0xbd, 0x00 }, /* BD DAI1 biquad */
244 246 { 0xbe, 0x00 }, /* BE DAI1 biquad */
245 0x00, /* B0 DAI2 EQ5 */ 247 { 0xbf, 0x00 }, /* BF DAI1 biquad */
246 0x00, /* B1 DAI2 EQ5 */ 248
247 0x00, /* B2 DAI2 EQ5 */ 249 { 0xc0, 0x00 }, /* C0 DAI2 biquad */
248 0x00, /* B3 DAI2 EQ5 */ 250 { 0xc1, 0x00 }, /* C1 DAI2 biquad */
249 0x00, /* B4 DAI2 EQ5 */ 251 { 0xc2, 0x00 }, /* C2 DAI2 biquad */
250 0x00, /* B5 DAI2 EQ5 */ 252 { 0xc3, 0x00 }, /* C3 DAI2 biquad */
251 0x00, /* B6 DAI1 biquad */ 253 { 0xc4, 0x00 }, /* C4 DAI2 biquad */
252 0x00, /* B7 DAI1 biquad */ 254 { 0xc5, 0x00 }, /* C5 DAI2 biquad */
253 0x00, /* B8 DAI1 biquad */ 255 { 0xc6, 0x00 }, /* C6 DAI2 biquad */
254 0x00, /* B9 DAI1 biquad */ 256 { 0xc7, 0x00 }, /* C7 DAI2 biquad */
255 0x00, /* BA DAI1 biquad */ 257 { 0xc8, 0x00 }, /* C8 DAI2 biquad */
256 0x00, /* BB DAI1 biquad */ 258 { 0xc9, 0x00 }, /* C9 DAI2 biquad */
257 0x00, /* BC DAI1 biquad */
258 0x00, /* BD DAI1 biquad */
259 0x00, /* BE DAI1 biquad */
260 0x00, /* BF DAI1 biquad */
261
262 0x00, /* C0 DAI2 biquad */
263 0x00, /* C1 DAI2 biquad */
264 0x00, /* C2 DAI2 biquad */
265 0x00, /* C3 DAI2 biquad */
266 0x00, /* C4 DAI2 biquad */
267 0x00, /* C5 DAI2 biquad */
268 0x00, /* C6 DAI2 biquad */
269 0x00, /* C7 DAI2 biquad */
270 0x00, /* C8 DAI2 biquad */
271 0x00, /* C9 DAI2 biquad */
272 0x00, /* CA */
273 0x00, /* CB */
274 0x00, /* CC */
275 0x00, /* CD */
276 0x00, /* CE */
277 0x00, /* CF */
278
279 0x00, /* D0 */
280 0x00, /* D1 */
281 0x00, /* D2 */
282 0x00, /* D3 */
283 0x00, /* D4 */
284 0x00, /* D5 */
285 0x00, /* D6 */
286 0x00, /* D7 */
287 0x00, /* D8 */
288 0x00, /* D9 */
289 0x00, /* DA */
290 0x70, /* DB */
291 0x00, /* DC */
292 0x00, /* DD */
293 0x00, /* DE */
294 0x00, /* DF */
295
296 0x00, /* E0 */
297 0x00, /* E1 */
298 0x00, /* E2 */
299 0x00, /* E3 */
300 0x00, /* E4 */
301 0x00, /* E5 */
302 0x00, /* E6 */
303 0x00, /* E7 */
304 0x00, /* E8 */
305 0x00, /* E9 */
306 0x00, /* EA */
307 0x00, /* EB */
308 0x00, /* EC */
309 0x00, /* ED */
310 0x00, /* EE */
311 0x00, /* EF */
312
313 0x00, /* F0 */
314 0x00, /* F1 */
315 0x00, /* F2 */
316 0x00, /* F3 */
317 0x00, /* F4 */
318 0x00, /* F5 */
319 0x00, /* F6 */
320 0x00, /* F7 */
321 0x00, /* F8 */
322 0x00, /* F9 */
323 0x00, /* FA */
324 0x00, /* FB */
325 0x00, /* FC */
326 0x00, /* FD */
327 0x00, /* FE */
328 0x00, /* FF */
329}; 259};
330 260
331static struct { 261static struct {
@@ -606,11 +536,28 @@ static struct {
606 { 0xFF, 0x00, 1 }, /* FF */ 536 { 0xFF, 0x00, 1 }, /* FF */
607}; 537};
608 538
609static int max98088_volatile_register(struct snd_soc_codec *codec, unsigned int reg) 539static bool max98088_readable_register(struct device *dev, unsigned int reg)
540{
541 return max98088_access[reg].readable;
542}
543
544static bool max98088_volatile_register(struct device *dev, unsigned int reg)
610{ 545{
611 return max98088_access[reg].vol; 546 return max98088_access[reg].vol;
612} 547}
613 548
549static const struct regmap_config max98088_regmap = {
550 .reg_bits = 8,
551 .val_bits = 8,
552
553 .readable_reg = max98088_readable_register,
554 .volatile_reg = max98088_volatile_register,
555 .max_register = 0xff,
556
557 .reg_defaults = max98088_reg,
558 .num_reg_defaults = ARRAY_SIZE(max98088_reg),
559 .cache_type = REGCACHE_RBTREE,
560};
614 561
615/* 562/*
616 * Load equalizer DSP coefficient configurations registers 563 * Load equalizer DSP coefficient configurations registers
@@ -621,8 +568,9 @@ static void m98088_eq_band(struct snd_soc_codec *codec, unsigned int dai,
621 unsigned int eq_reg; 568 unsigned int eq_reg;
622 unsigned int i; 569 unsigned int i;
623 570
624 BUG_ON(band > 4); 571 if (WARN_ON(band > 4) ||
625 BUG_ON(dai > 1); 572 WARN_ON(dai > 1))
573 return;
626 574
627 /* Load the base register address */ 575 /* Load the base register address */
628 eq_reg = dai ? M98088_REG_84_DAI2_EQ_BASE : M98088_REG_52_DAI1_EQ_BASE; 576 eq_reg = dai ? M98088_REG_84_DAI2_EQ_BASE : M98088_REG_52_DAI1_EQ_BASE;
@@ -962,7 +910,8 @@ static int max98088_line_pga(struct snd_soc_dapm_widget *w,
962 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec); 910 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
963 u8 *state; 911 u8 *state;
964 912
965 BUG_ON(!((channel == 1) || (channel == 2))); 913 if (WARN_ON(!(channel == 1 || channel == 2)))
914 return -EINVAL;
966 915
967 switch (line) { 916 switch (line) {
968 case LINE_INA: 917 case LINE_INA:
@@ -1610,58 +1559,34 @@ static int max98088_dai2_digital_mute(struct snd_soc_dai *codec_dai, int mute)
1610 return 0; 1559 return 0;
1611} 1560}
1612 1561
1613static void max98088_sync_cache(struct snd_soc_codec *codec)
1614{
1615 u8 *reg_cache = codec->reg_cache;
1616 int i;
1617
1618 if (!codec->cache_sync)
1619 return;
1620
1621 codec->cache_only = 0;
1622
1623 /* write back cached values if they're writeable and
1624 * different from the hardware default.
1625 */
1626 for (i = 1; i < codec->driver->reg_cache_size; i++) {
1627 if (!max98088_access[i].writable)
1628 continue;
1629
1630 if (reg_cache[i] == max98088_reg[i])
1631 continue;
1632
1633 snd_soc_write(codec, i, reg_cache[i]);
1634 }
1635
1636 codec->cache_sync = 0;
1637}
1638
1639static int max98088_set_bias_level(struct snd_soc_codec *codec, 1562static int max98088_set_bias_level(struct snd_soc_codec *codec,
1640 enum snd_soc_bias_level level) 1563 enum snd_soc_bias_level level)
1641{ 1564{
1642 switch (level) { 1565 struct max98088_priv *max98088 = snd_soc_codec_get_drvdata(codec);
1643 case SND_SOC_BIAS_ON: 1566
1644 break; 1567 switch (level) {
1645 1568 case SND_SOC_BIAS_ON:
1646 case SND_SOC_BIAS_PREPARE: 1569 break;
1647 break; 1570
1648 1571 case SND_SOC_BIAS_PREPARE:
1649 case SND_SOC_BIAS_STANDBY: 1572 break;
1650 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 1573
1651 max98088_sync_cache(codec); 1574 case SND_SOC_BIAS_STANDBY:
1652 1575 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
1653 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN, 1576 regcache_sync(max98088->regmap);
1654 M98088_MBEN, M98088_MBEN); 1577
1655 break; 1578 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN,
1656 1579 M98088_MBEN, M98088_MBEN);
1657 case SND_SOC_BIAS_OFF: 1580 break;
1658 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN, 1581
1659 M98088_MBEN, 0); 1582 case SND_SOC_BIAS_OFF:
1660 codec->cache_sync = 1; 1583 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN,
1661 break; 1584 M98088_MBEN, 0);
1662 } 1585 regcache_mark_dirty(max98088->regmap);
1663 codec->dapm.bias_level = level; 1586 break;
1664 return 0; 1587 }
1588 codec->dapm.bias_level = level;
1589 return 0;
1665} 1590}
1666 1591
1667#define MAX98088_RATES SNDRV_PCM_RATE_8000_96000 1592#define MAX98088_RATES SNDRV_PCM_RATE_8000_96000
@@ -1988,9 +1913,9 @@ static int max98088_probe(struct snd_soc_codec *codec)
1988 struct max98088_cdata *cdata; 1913 struct max98088_cdata *cdata;
1989 int ret = 0; 1914 int ret = 0;
1990 1915
1991 codec->cache_sync = 1; 1916 regcache_mark_dirty(max98088->regmap);
1992 1917
1993 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 1918 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1994 if (ret != 0) { 1919 if (ret != 0) {
1995 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 1920 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1996 return ret; 1921 return ret;
@@ -2048,9 +1973,6 @@ static int max98088_probe(struct snd_soc_codec *codec)
2048 1973
2049 max98088_handle_pdata(codec); 1974 max98088_handle_pdata(codec);
2050 1975
2051 snd_soc_add_codec_controls(codec, max98088_snd_controls,
2052 ARRAY_SIZE(max98088_snd_controls));
2053
2054err_access: 1976err_access:
2055 return ret; 1977 return ret;
2056} 1978}
@@ -2066,15 +1988,13 @@ static int max98088_remove(struct snd_soc_codec *codec)
2066} 1988}
2067 1989
2068static struct snd_soc_codec_driver soc_codec_dev_max98088 = { 1990static struct snd_soc_codec_driver soc_codec_dev_max98088 = {
2069 .probe = max98088_probe, 1991 .probe = max98088_probe,
2070 .remove = max98088_remove, 1992 .remove = max98088_remove,
2071 .suspend = max98088_suspend, 1993 .suspend = max98088_suspend,
2072 .resume = max98088_resume, 1994 .resume = max98088_resume,
2073 .set_bias_level = max98088_set_bias_level, 1995 .set_bias_level = max98088_set_bias_level,
2074 .reg_cache_size = ARRAY_SIZE(max98088_reg), 1996 .controls = max98088_snd_controls,
2075 .reg_word_size = sizeof(u8), 1997 .num_controls = ARRAY_SIZE(max98088_snd_controls),
2076 .reg_cache_default = max98088_reg,
2077 .volatile_register = max98088_volatile_register,
2078 .dapm_widgets = max98088_dapm_widgets, 1998 .dapm_widgets = max98088_dapm_widgets,
2079 .num_dapm_widgets = ARRAY_SIZE(max98088_dapm_widgets), 1999 .num_dapm_widgets = ARRAY_SIZE(max98088_dapm_widgets),
2080 .dapm_routes = max98088_audio_map, 2000 .dapm_routes = max98088_audio_map,
@@ -2082,7 +2002,7 @@ static struct snd_soc_codec_driver soc_codec_dev_max98088 = {
2082}; 2002};
2083 2003
2084static int max98088_i2c_probe(struct i2c_client *i2c, 2004static int max98088_i2c_probe(struct i2c_client *i2c,
2085 const struct i2c_device_id *id) 2005 const struct i2c_device_id *id)
2086{ 2006{
2087 struct max98088_priv *max98088; 2007 struct max98088_priv *max98088;
2088 int ret; 2008 int ret;
@@ -2092,6 +2012,10 @@ static int max98088_i2c_probe(struct i2c_client *i2c,
2092 if (max98088 == NULL) 2012 if (max98088 == NULL)
2093 return -ENOMEM; 2013 return -ENOMEM;
2094 2014
2015 max98088->regmap = devm_regmap_init_i2c(i2c, &max98088_regmap);
2016 if (IS_ERR(max98088->regmap))
2017 return PTR_ERR(max98088->regmap);
2018
2095 max98088->devtype = id->driver_data; 2019 max98088->devtype = id->driver_data;
2096 2020
2097 i2c_set_clientdata(i2c, max98088); 2021 i2c_set_clientdata(i2c, max98088);
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 41cdd1642970..67244315c721 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -39,6 +39,7 @@ struct max98095_cdata {
39}; 39};
40 40
41struct max98095_priv { 41struct max98095_priv {
42 struct regmap *regmap;
42 enum max98095_type devtype; 43 enum max98095_type devtype;
43 struct max98095_pdata *pdata; 44 struct max98095_pdata *pdata;
44 unsigned int sysclk; 45 unsigned int sysclk;
@@ -56,263 +57,145 @@ struct max98095_priv {
56 struct snd_soc_jack *mic_jack; 57 struct snd_soc_jack *mic_jack;
57}; 58};
58 59
59static const u8 max98095_reg_def[M98095_REG_CNT] = { 60static const struct reg_default max98095_reg_def[] = {
60 0x00, /* 00 */ 61 { 0xf, 0x00 }, /* 0F */
61 0x00, /* 01 */ 62 { 0x10, 0x00 }, /* 10 */
62 0x00, /* 02 */ 63 { 0x11, 0x00 }, /* 11 */
63 0x00, /* 03 */ 64 { 0x12, 0x00 }, /* 12 */
64 0x00, /* 04 */ 65 { 0x13, 0x00 }, /* 13 */
65 0x00, /* 05 */ 66 { 0x14, 0x00 }, /* 14 */
66 0x00, /* 06 */ 67 { 0x15, 0x00 }, /* 15 */
67 0x00, /* 07 */ 68 { 0x16, 0x00 }, /* 16 */
68 0x00, /* 08 */ 69 { 0x17, 0x00 }, /* 17 */
69 0x00, /* 09 */ 70 { 0x18, 0x00 }, /* 18 */
70 0x00, /* 0A */ 71 { 0x19, 0x00 }, /* 19 */
71 0x00, /* 0B */ 72 { 0x1a, 0x00 }, /* 1A */
72 0x00, /* 0C */ 73 { 0x1b, 0x00 }, /* 1B */
73 0x00, /* 0D */ 74 { 0x1c, 0x00 }, /* 1C */
74 0x00, /* 0E */ 75 { 0x1d, 0x00 }, /* 1D */
75 0x00, /* 0F */ 76 { 0x1e, 0x00 }, /* 1E */
76 0x00, /* 10 */ 77 { 0x1f, 0x00 }, /* 1F */
77 0x00, /* 11 */ 78 { 0x20, 0x00 }, /* 20 */
78 0x00, /* 12 */ 79 { 0x21, 0x00 }, /* 21 */
79 0x00, /* 13 */ 80 { 0x22, 0x00 }, /* 22 */
80 0x00, /* 14 */ 81 { 0x23, 0x00 }, /* 23 */
81 0x00, /* 15 */ 82 { 0x24, 0x00 }, /* 24 */
82 0x00, /* 16 */ 83 { 0x25, 0x00 }, /* 25 */
83 0x00, /* 17 */ 84 { 0x26, 0x00 }, /* 26 */
84 0x00, /* 18 */ 85 { 0x27, 0x00 }, /* 27 */
85 0x00, /* 19 */ 86 { 0x28, 0x00 }, /* 28 */
86 0x00, /* 1A */ 87 { 0x29, 0x00 }, /* 29 */
87 0x00, /* 1B */ 88 { 0x2a, 0x00 }, /* 2A */
88 0x00, /* 1C */ 89 { 0x2b, 0x00 }, /* 2B */
89 0x00, /* 1D */ 90 { 0x2c, 0x00 }, /* 2C */
90 0x00, /* 1E */ 91 { 0x2d, 0x00 }, /* 2D */
91 0x00, /* 1F */ 92 { 0x2e, 0x00 }, /* 2E */
92 0x00, /* 20 */ 93 { 0x2f, 0x00 }, /* 2F */
93 0x00, /* 21 */ 94 { 0x30, 0x00 }, /* 30 */
94 0x00, /* 22 */ 95 { 0x31, 0x00 }, /* 31 */
95 0x00, /* 23 */ 96 { 0x32, 0x00 }, /* 32 */
96 0x00, /* 24 */ 97 { 0x33, 0x00 }, /* 33 */
97 0x00, /* 25 */ 98 { 0x34, 0x00 }, /* 34 */
98 0x00, /* 26 */ 99 { 0x35, 0x00 }, /* 35 */
99 0x00, /* 27 */ 100 { 0x36, 0x00 }, /* 36 */
100 0x00, /* 28 */ 101 { 0x37, 0x00 }, /* 37 */
101 0x00, /* 29 */ 102 { 0x38, 0x00 }, /* 38 */
102 0x00, /* 2A */ 103 { 0x39, 0x00 }, /* 39 */
103 0x00, /* 2B */ 104 { 0x3a, 0x00 }, /* 3A */
104 0x00, /* 2C */ 105 { 0x3b, 0x00 }, /* 3B */
105 0x00, /* 2D */ 106 { 0x3c, 0x00 }, /* 3C */
106 0x00, /* 2E */ 107 { 0x3d, 0x00 }, /* 3D */
107 0x00, /* 2F */ 108 { 0x3e, 0x00 }, /* 3E */
108 0x00, /* 30 */ 109 { 0x3f, 0x00 }, /* 3F */
109 0x00, /* 31 */ 110 { 0x40, 0x00 }, /* 40 */
110 0x00, /* 32 */ 111 { 0x41, 0x00 }, /* 41 */
111 0x00, /* 33 */ 112 { 0x42, 0x00 }, /* 42 */
112 0x00, /* 34 */ 113 { 0x43, 0x00 }, /* 43 */
113 0x00, /* 35 */ 114 { 0x44, 0x00 }, /* 44 */
114 0x00, /* 36 */ 115 { 0x45, 0x00 }, /* 45 */
115 0x00, /* 37 */ 116 { 0x46, 0x00 }, /* 46 */
116 0x00, /* 38 */ 117 { 0x47, 0x00 }, /* 47 */
117 0x00, /* 39 */ 118 { 0x48, 0x00 }, /* 48 */
118 0x00, /* 3A */ 119 { 0x49, 0x00 }, /* 49 */
119 0x00, /* 3B */ 120 { 0x4a, 0x00 }, /* 4A */
120 0x00, /* 3C */ 121 { 0x4b, 0x00 }, /* 4B */
121 0x00, /* 3D */ 122 { 0x4c, 0x00 }, /* 4C */
122 0x00, /* 3E */ 123 { 0x4d, 0x00 }, /* 4D */
123 0x00, /* 3F */ 124 { 0x4e, 0x00 }, /* 4E */
124 0x00, /* 40 */ 125 { 0x4f, 0x00 }, /* 4F */
125 0x00, /* 41 */ 126 { 0x50, 0x00 }, /* 50 */
126 0x00, /* 42 */ 127 { 0x51, 0x00 }, /* 51 */
127 0x00, /* 43 */ 128 { 0x52, 0x00 }, /* 52 */
128 0x00, /* 44 */ 129 { 0x53, 0x00 }, /* 53 */
129 0x00, /* 45 */ 130 { 0x54, 0x00 }, /* 54 */
130 0x00, /* 46 */ 131 { 0x55, 0x00 }, /* 55 */
131 0x00, /* 47 */ 132 { 0x56, 0x00 }, /* 56 */
132 0x00, /* 48 */ 133 { 0x57, 0x00 }, /* 57 */
133 0x00, /* 49 */ 134 { 0x58, 0x00 }, /* 58 */
134 0x00, /* 4A */ 135 { 0x59, 0x00 }, /* 59 */
135 0x00, /* 4B */ 136 { 0x5a, 0x00 }, /* 5A */
136 0x00, /* 4C */ 137 { 0x5b, 0x00 }, /* 5B */
137 0x00, /* 4D */ 138 { 0x5c, 0x00 }, /* 5C */
138 0x00, /* 4E */ 139 { 0x5d, 0x00 }, /* 5D */
139 0x00, /* 4F */ 140 { 0x5e, 0x00 }, /* 5E */
140 0x00, /* 50 */ 141 { 0x5f, 0x00 }, /* 5F */
141 0x00, /* 51 */ 142 { 0x60, 0x00 }, /* 60 */
142 0x00, /* 52 */ 143 { 0x61, 0x00 }, /* 61 */
143 0x00, /* 53 */ 144 { 0x62, 0x00 }, /* 62 */
144 0x00, /* 54 */ 145 { 0x63, 0x00 }, /* 63 */
145 0x00, /* 55 */ 146 { 0x64, 0x00 }, /* 64 */
146 0x00, /* 56 */ 147 { 0x65, 0x00 }, /* 65 */
147 0x00, /* 57 */ 148 { 0x66, 0x00 }, /* 66 */
148 0x00, /* 58 */ 149 { 0x67, 0x00 }, /* 67 */
149 0x00, /* 59 */ 150 { 0x68, 0x00 }, /* 68 */
150 0x00, /* 5A */ 151 { 0x69, 0x00 }, /* 69 */
151 0x00, /* 5B */ 152 { 0x6a, 0x00 }, /* 6A */
152 0x00, /* 5C */ 153 { 0x6b, 0x00 }, /* 6B */
153 0x00, /* 5D */ 154 { 0x6c, 0x00 }, /* 6C */
154 0x00, /* 5E */ 155 { 0x6d, 0x00 }, /* 6D */
155 0x00, /* 5F */ 156 { 0x6e, 0x00 }, /* 6E */
156 0x00, /* 60 */ 157 { 0x6f, 0x00 }, /* 6F */
157 0x00, /* 61 */ 158 { 0x70, 0x00 }, /* 70 */
158 0x00, /* 62 */ 159 { 0x71, 0x00 }, /* 71 */
159 0x00, /* 63 */ 160 { 0x72, 0x00 }, /* 72 */
160 0x00, /* 64 */ 161 { 0x73, 0x00 }, /* 73 */
161 0x00, /* 65 */ 162 { 0x74, 0x00 }, /* 74 */
162 0x00, /* 66 */ 163 { 0x75, 0x00 }, /* 75 */
163 0x00, /* 67 */ 164 { 0x76, 0x00 }, /* 76 */
164 0x00, /* 68 */ 165 { 0x77, 0x00 }, /* 77 */
165 0x00, /* 69 */ 166 { 0x78, 0x00 }, /* 78 */
166 0x00, /* 6A */ 167 { 0x79, 0x00 }, /* 79 */
167 0x00, /* 6B */ 168 { 0x7a, 0x00 }, /* 7A */
168 0x00, /* 6C */ 169 { 0x7b, 0x00 }, /* 7B */
169 0x00, /* 6D */ 170 { 0x7c, 0x00 }, /* 7C */
170 0x00, /* 6E */ 171 { 0x7d, 0x00 }, /* 7D */
171 0x00, /* 6F */ 172 { 0x7e, 0x00 }, /* 7E */
172 0x00, /* 70 */ 173 { 0x7f, 0x00 }, /* 7F */
173 0x00, /* 71 */ 174 { 0x80, 0x00 }, /* 80 */
174 0x00, /* 72 */ 175 { 0x81, 0x00 }, /* 81 */
175 0x00, /* 73 */ 176 { 0x82, 0x00 }, /* 82 */
176 0x00, /* 74 */ 177 { 0x83, 0x00 }, /* 83 */
177 0x00, /* 75 */ 178 { 0x84, 0x00 }, /* 84 */
178 0x00, /* 76 */ 179 { 0x85, 0x00 }, /* 85 */
179 0x00, /* 77 */ 180 { 0x86, 0x00 }, /* 86 */
180 0x00, /* 78 */ 181 { 0x87, 0x00 }, /* 87 */
181 0x00, /* 79 */ 182 { 0x88, 0x00 }, /* 88 */
182 0x00, /* 7A */ 183 { 0x89, 0x00 }, /* 89 */
183 0x00, /* 7B */ 184 { 0x8a, 0x00 }, /* 8A */
184 0x00, /* 7C */ 185 { 0x8b, 0x00 }, /* 8B */
185 0x00, /* 7D */ 186 { 0x8c, 0x00 }, /* 8C */
186 0x00, /* 7E */ 187 { 0x8d, 0x00 }, /* 8D */
187 0x00, /* 7F */ 188 { 0x8e, 0x00 }, /* 8E */
188 0x00, /* 80 */ 189 { 0x8f, 0x00 }, /* 8F */
189 0x00, /* 81 */ 190 { 0x90, 0x00 }, /* 90 */
190 0x00, /* 82 */ 191 { 0x91, 0x00 }, /* 91 */
191 0x00, /* 83 */ 192 { 0x92, 0x30 }, /* 92 */
192 0x00, /* 84 */ 193 { 0x93, 0xF0 }, /* 93 */
193 0x00, /* 85 */ 194 { 0x94, 0x00 }, /* 94 */
194 0x00, /* 86 */ 195 { 0x95, 0x00 }, /* 95 */
195 0x00, /* 87 */ 196 { 0x96, 0x3F }, /* 96 */
196 0x00, /* 88 */ 197 { 0x97, 0x00 }, /* 97 */
197 0x00, /* 89 */ 198 { 0xff, 0x00 }, /* FF */
198 0x00, /* 8A */
199 0x00, /* 8B */
200 0x00, /* 8C */
201 0x00, /* 8D */
202 0x00, /* 8E */
203 0x00, /* 8F */
204 0x00, /* 90 */
205 0x00, /* 91 */
206 0x30, /* 92 */
207 0xF0, /* 93 */
208 0x00, /* 94 */
209 0x00, /* 95 */
210 0x3F, /* 96 */
211 0x00, /* 97 */
212 0x00, /* 98 */
213 0x00, /* 99 */
214 0x00, /* 9A */
215 0x00, /* 9B */
216 0x00, /* 9C */
217 0x00, /* 9D */
218 0x00, /* 9E */
219 0x00, /* 9F */
220 0x00, /* A0 */
221 0x00, /* A1 */
222 0x00, /* A2 */
223 0x00, /* A3 */
224 0x00, /* A4 */
225 0x00, /* A5 */
226 0x00, /* A6 */
227 0x00, /* A7 */
228 0x00, /* A8 */
229 0x00, /* A9 */
230 0x00, /* AA */
231 0x00, /* AB */
232 0x00, /* AC */
233 0x00, /* AD */
234 0x00, /* AE */
235 0x00, /* AF */
236 0x00, /* B0 */
237 0x00, /* B1 */
238 0x00, /* B2 */
239 0x00, /* B3 */
240 0x00, /* B4 */
241 0x00, /* B5 */
242 0x00, /* B6 */
243 0x00, /* B7 */
244 0x00, /* B8 */
245 0x00, /* B9 */
246 0x00, /* BA */
247 0x00, /* BB */
248 0x00, /* BC */
249 0x00, /* BD */
250 0x00, /* BE */
251 0x00, /* BF */
252 0x00, /* C0 */
253 0x00, /* C1 */
254 0x00, /* C2 */
255 0x00, /* C3 */
256 0x00, /* C4 */
257 0x00, /* C5 */
258 0x00, /* C6 */
259 0x00, /* C7 */
260 0x00, /* C8 */
261 0x00, /* C9 */
262 0x00, /* CA */
263 0x00, /* CB */
264 0x00, /* CC */
265 0x00, /* CD */
266 0x00, /* CE */
267 0x00, /* CF */
268 0x00, /* D0 */
269 0x00, /* D1 */
270 0x00, /* D2 */
271 0x00, /* D3 */
272 0x00, /* D4 */
273 0x00, /* D5 */
274 0x00, /* D6 */
275 0x00, /* D7 */
276 0x00, /* D8 */
277 0x00, /* D9 */
278 0x00, /* DA */
279 0x00, /* DB */
280 0x00, /* DC */
281 0x00, /* DD */
282 0x00, /* DE */
283 0x00, /* DF */
284 0x00, /* E0 */
285 0x00, /* E1 */
286 0x00, /* E2 */
287 0x00, /* E3 */
288 0x00, /* E4 */
289 0x00, /* E5 */
290 0x00, /* E6 */
291 0x00, /* E7 */
292 0x00, /* E8 */
293 0x00, /* E9 */
294 0x00, /* EA */
295 0x00, /* EB */
296 0x00, /* EC */
297 0x00, /* ED */
298 0x00, /* EE */
299 0x00, /* EF */
300 0x00, /* F0 */
301 0x00, /* F1 */
302 0x00, /* F2 */
303 0x00, /* F3 */
304 0x00, /* F4 */
305 0x00, /* F5 */
306 0x00, /* F6 */
307 0x00, /* F7 */
308 0x00, /* F8 */
309 0x00, /* F9 */
310 0x00, /* FA */
311 0x00, /* FB */
312 0x00, /* FC */
313 0x00, /* FD */
314 0x00, /* FE */
315 0x00, /* FF */
316}; 199};
317 200
318static struct { 201static struct {
@@ -577,14 +460,14 @@ static struct {
577 { 0xFF, 0x00 }, /* FF */ 460 { 0xFF, 0x00 }, /* FF */
578}; 461};
579 462
580static int max98095_readable(struct snd_soc_codec *codec, unsigned int reg) 463static bool max98095_readable(struct device *dev, unsigned int reg)
581{ 464{
582 if (reg >= M98095_REG_CNT) 465 if (reg >= M98095_REG_CNT)
583 return 0; 466 return 0;
584 return max98095_access[reg].readable != 0; 467 return max98095_access[reg].readable != 0;
585} 468}
586 469
587static int max98095_volatile(struct snd_soc_codec *codec, unsigned int reg) 470static bool max98095_volatile(struct device *dev, unsigned int reg)
588{ 471{
589 if (reg > M98095_REG_MAX_CACHED) 472 if (reg > M98095_REG_MAX_CACHED)
590 return 1; 473 return 1;
@@ -611,22 +494,18 @@ static int max98095_volatile(struct snd_soc_codec *codec, unsigned int reg)
611 return 0; 494 return 0;
612} 495}
613 496
614/* 497static const struct regmap_config max98095_regmap = {
615 * Filter coefficients are in a separate register segment 498 .reg_bits = 8,
616 * and they share the address space of the normal registers. 499 .val_bits = 8,
617 * The coefficient registers do not need or share the cache.
618 */
619static int max98095_hw_write(struct snd_soc_codec *codec, unsigned int reg,
620 unsigned int value)
621{
622 int ret;
623 500
624 codec->cache_bypass = 1; 501 .reg_defaults = max98095_reg_def,
625 ret = snd_soc_write(codec, reg, value); 502 .num_reg_defaults = ARRAY_SIZE(max98095_reg_def),
626 codec->cache_bypass = 0; 503 .max_register = M98095_0FF_REV_ID,
504 .cache_type = REGCACHE_RBTREE,
627 505
628 return ret ? -EIO : 0; 506 .readable_reg = max98095_readable,
629} 507 .volatile_reg = max98095_volatile,
508};
630 509
631/* 510/*
632 * Load equalizer DSP coefficient configurations registers 511 * Load equalizer DSP coefficient configurations registers
@@ -637,8 +516,9 @@ static void m98095_eq_band(struct snd_soc_codec *codec, unsigned int dai,
637 unsigned int eq_reg; 516 unsigned int eq_reg;
638 unsigned int i; 517 unsigned int i;
639 518
640 BUG_ON(band > 4); 519 if (WARN_ON(band > 4) ||
641 BUG_ON(dai > 1); 520 WARN_ON(dai > 1))
521 return;
642 522
643 /* Load the base register address */ 523 /* Load the base register address */
644 eq_reg = dai ? M98095_142_DAI2_EQ_BASE : M98095_110_DAI1_EQ_BASE; 524 eq_reg = dai ? M98095_142_DAI2_EQ_BASE : M98095_110_DAI1_EQ_BASE;
@@ -648,8 +528,8 @@ static void m98095_eq_band(struct snd_soc_codec *codec, unsigned int dai,
648 528
649 /* Step through the registers and coefs */ 529 /* Step through the registers and coefs */
650 for (i = 0; i < M98095_COEFS_PER_BAND; i++) { 530 for (i = 0; i < M98095_COEFS_PER_BAND; i++) {
651 max98095_hw_write(codec, eq_reg++, M98095_BYTE1(coefs[i])); 531 snd_soc_write(codec, eq_reg++, M98095_BYTE1(coefs[i]));
652 max98095_hw_write(codec, eq_reg++, M98095_BYTE0(coefs[i])); 532 snd_soc_write(codec, eq_reg++, M98095_BYTE0(coefs[i]));
653 } 533 }
654} 534}
655 535
@@ -662,8 +542,9 @@ static void m98095_biquad_band(struct snd_soc_codec *codec, unsigned int dai,
662 unsigned int bq_reg; 542 unsigned int bq_reg;
663 unsigned int i; 543 unsigned int i;
664 544
665 BUG_ON(band > 1); 545 if (WARN_ON(band > 1) ||
666 BUG_ON(dai > 1); 546 WARN_ON(dai > 1))
547 return;
667 548
668 /* Load the base register address */ 549 /* Load the base register address */
669 bq_reg = dai ? M98095_17E_DAI2_BQ_BASE : M98095_174_DAI1_BQ_BASE; 550 bq_reg = dai ? M98095_17E_DAI2_BQ_BASE : M98095_174_DAI1_BQ_BASE;
@@ -673,8 +554,8 @@ static void m98095_biquad_band(struct snd_soc_codec *codec, unsigned int dai,
673 554
674 /* Step through the registers and coefs */ 555 /* Step through the registers and coefs */
675 for (i = 0; i < M98095_COEFS_PER_BAND; i++) { 556 for (i = 0; i < M98095_COEFS_PER_BAND; i++) {
676 max98095_hw_write(codec, bq_reg++, M98095_BYTE1(coefs[i])); 557 snd_soc_write(codec, bq_reg++, M98095_BYTE1(coefs[i]));
677 max98095_hw_write(codec, bq_reg++, M98095_BYTE0(coefs[i])); 558 snd_soc_write(codec, bq_reg++, M98095_BYTE0(coefs[i]));
678 } 559 }
679} 560}
680 561
@@ -1011,7 +892,8 @@ static int max98095_line_pga(struct snd_soc_dapm_widget *w,
1011 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 892 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
1012 u8 *state; 893 u8 *state;
1013 894
1014 BUG_ON(!((channel == 1) || (channel == 2))); 895 if (WARN_ON(!(channel == 1 || channel == 2)))
896 return -EINVAL;
1015 897
1016 state = &max98095->lin_state; 898 state = &max98095->lin_state;
1017 899
@@ -1285,14 +1167,6 @@ static const struct snd_soc_dapm_route max98095_audio_map[] = {
1285 {"MIC2 Input", NULL, "MIC2"}, 1167 {"MIC2 Input", NULL, "MIC2"},
1286}; 1168};
1287 1169
1288static int max98095_add_widgets(struct snd_soc_codec *codec)
1289{
1290 snd_soc_add_codec_controls(codec, max98095_snd_controls,
1291 ARRAY_SIZE(max98095_snd_controls));
1292
1293 return 0;
1294}
1295
1296/* codec mclk clock divider coefficients */ 1170/* codec mclk clock divider coefficients */
1297static const struct { 1171static const struct {
1298 u32 rate; 1172 u32 rate;
@@ -1748,6 +1622,7 @@ static int max98095_dai3_set_fmt(struct snd_soc_dai *codec_dai,
1748static int max98095_set_bias_level(struct snd_soc_codec *codec, 1622static int max98095_set_bias_level(struct snd_soc_codec *codec,
1749 enum snd_soc_bias_level level) 1623 enum snd_soc_bias_level level)
1750{ 1624{
1625 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
1751 int ret; 1626 int ret;
1752 1627
1753 switch (level) { 1628 switch (level) {
@@ -1759,7 +1634,7 @@ static int max98095_set_bias_level(struct snd_soc_codec *codec,
1759 1634
1760 case SND_SOC_BIAS_STANDBY: 1635 case SND_SOC_BIAS_STANDBY:
1761 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1636 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1762 ret = snd_soc_cache_sync(codec); 1637 ret = regcache_sync(max98095->regmap);
1763 1638
1764 if (ret != 0) { 1639 if (ret != 0) {
1765 dev_err(codec->dev, "Failed to sync cache: %d\n", ret); 1640 dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
@@ -1774,7 +1649,7 @@ static int max98095_set_bias_level(struct snd_soc_codec *codec,
1774 case SND_SOC_BIAS_OFF: 1649 case SND_SOC_BIAS_OFF:
1775 snd_soc_update_bits(codec, M98095_090_PWR_EN_IN, 1650 snd_soc_update_bits(codec, M98095_090_PWR_EN_IN,
1776 M98095_MBEN, 0); 1651 M98095_MBEN, 0);
1777 codec->cache_sync = 1; 1652 regcache_mark_dirty(max98095->regmap);
1778 break; 1653 break;
1779 } 1654 }
1780 codec->dapm.bias_level = level; 1655 codec->dapm.bias_level = level;
@@ -1863,12 +1738,13 @@ static int max98095_put_eq_enum(struct snd_kcontrol *kcontrol,
1863 struct max98095_pdata *pdata = max98095->pdata; 1738 struct max98095_pdata *pdata = max98095->pdata;
1864 int channel = max98095_get_eq_channel(kcontrol->id.name); 1739 int channel = max98095_get_eq_channel(kcontrol->id.name);
1865 struct max98095_cdata *cdata; 1740 struct max98095_cdata *cdata;
1866 int sel = ucontrol->value.integer.value[0]; 1741 unsigned int sel = ucontrol->value.integer.value[0];
1867 struct max98095_eq_cfg *coef_set; 1742 struct max98095_eq_cfg *coef_set;
1868 int fs, best, best_val, i; 1743 int fs, best, best_val, i;
1869 int regmask, regsave; 1744 int regmask, regsave;
1870 1745
1871 BUG_ON(channel > 1); 1746 if (WARN_ON(channel > 1))
1747 return -EINVAL;
1872 1748
1873 if (!pdata || !max98095->eq_textcnt) 1749 if (!pdata || !max98095->eq_textcnt)
1874 return 0; 1750 return 0;
@@ -2016,7 +1892,7 @@ static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
2016 struct max98095_pdata *pdata = max98095->pdata; 1892 struct max98095_pdata *pdata = max98095->pdata;
2017 int channel = max98095_get_bq_channel(codec, kcontrol->id.name); 1893 int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
2018 struct max98095_cdata *cdata; 1894 struct max98095_cdata *cdata;
2019 int sel = ucontrol->value.integer.value[0]; 1895 unsigned int sel = ucontrol->value.integer.value[0];
2020 struct max98095_biquad_cfg *coef_set; 1896 struct max98095_biquad_cfg *coef_set;
2021 int fs, best, best_val, i; 1897 int fs, best, best_val, i;
2022 int regmask, regsave; 1898 int regmask, regsave;
@@ -2341,7 +2217,7 @@ static int max98095_reset(struct snd_soc_codec *codec)
2341 /* Reset to hardware default for registers, as there is not 2217 /* Reset to hardware default for registers, as there is not
2342 * a soft reset hardware control register */ 2218 * a soft reset hardware control register */
2343 for (i = M98095_010_HOST_INT_CFG; i < M98095_REG_MAX_CACHED; i++) { 2219 for (i = M98095_010_HOST_INT_CFG; i < M98095_REG_MAX_CACHED; i++) {
2344 ret = snd_soc_write(codec, i, max98095_reg_def[i]); 2220 ret = snd_soc_write(codec, i, snd_soc_read(codec, i));
2345 if (ret < 0) { 2221 if (ret < 0) {
2346 dev_err(codec->dev, "Failed to reset: %d\n", ret); 2222 dev_err(codec->dev, "Failed to reset: %d\n", ret);
2347 return ret; 2223 return ret;
@@ -2358,7 +2234,7 @@ static int max98095_probe(struct snd_soc_codec *codec)
2358 struct i2c_client *client; 2234 struct i2c_client *client;
2359 int ret = 0; 2235 int ret = 0;
2360 2236
2361 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 2237 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
2362 if (ret != 0) { 2238 if (ret != 0) {
2363 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 2239 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
2364 return ret; 2240 return ret;
@@ -2447,8 +2323,6 @@ static int max98095_probe(struct snd_soc_codec *codec)
2447 snd_soc_update_bits(codec, M98095_097_PWR_SYS, M98095_SHDNRUN, 2323 snd_soc_update_bits(codec, M98095_097_PWR_SYS, M98095_SHDNRUN,
2448 M98095_SHDNRUN); 2324 M98095_SHDNRUN);
2449 2325
2450 max98095_add_widgets(codec);
2451
2452 return 0; 2326 return 0;
2453 2327
2454err_irq: 2328err_irq:
@@ -2480,11 +2354,8 @@ static struct snd_soc_codec_driver soc_codec_dev_max98095 = {
2480 .suspend = max98095_suspend, 2354 .suspend = max98095_suspend,
2481 .resume = max98095_resume, 2355 .resume = max98095_resume,
2482 .set_bias_level = max98095_set_bias_level, 2356 .set_bias_level = max98095_set_bias_level,
2483 .reg_cache_size = ARRAY_SIZE(max98095_reg_def), 2357 .controls = max98095_snd_controls,
2484 .reg_word_size = sizeof(u8), 2358 .num_controls = ARRAY_SIZE(max98095_snd_controls),
2485 .reg_cache_default = max98095_reg_def,
2486 .readable_register = max98095_readable,
2487 .volatile_register = max98095_volatile,
2488 .dapm_widgets = max98095_dapm_widgets, 2359 .dapm_widgets = max98095_dapm_widgets,
2489 .num_dapm_widgets = ARRAY_SIZE(max98095_dapm_widgets), 2360 .num_dapm_widgets = ARRAY_SIZE(max98095_dapm_widgets),
2490 .dapm_routes = max98095_audio_map, 2361 .dapm_routes = max98095_audio_map,
@@ -2502,6 +2373,13 @@ static int max98095_i2c_probe(struct i2c_client *i2c,
2502 if (max98095 == NULL) 2373 if (max98095 == NULL)
2503 return -ENOMEM; 2374 return -ENOMEM;
2504 2375
2376 max98095->regmap = devm_regmap_init_i2c(i2c, &max98095_regmap);
2377 if (IS_ERR(max98095->regmap)) {
2378 ret = PTR_ERR(max98095->regmap);
2379 dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret);
2380 return ret;
2381 }
2382
2505 max98095->devtype = id->driver_data; 2383 max98095->devtype = id->driver_data;
2506 i2c_set_clientdata(i2c, max98095); 2384 i2c_set_clientdata(i2c, max98095);
2507 max98095->pdata = i2c->dev.platform_data; 2385 max98095->pdata = i2c->dev.platform_data;
diff --git a/sound/soc/codecs/max9850.c b/sound/soc/codecs/max9850.c
index 58c38a5b481c..c5dd61785f8d 100644
--- a/sound/soc/codecs/max9850.c
+++ b/sound/soc/codecs/max9850.c
@@ -18,6 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/regmap.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
22#include <sound/pcm.h> 23#include <sound/pcm.h>
23#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
@@ -27,18 +28,26 @@
27#include "max9850.h" 28#include "max9850.h"
28 29
29struct max9850_priv { 30struct max9850_priv {
31 struct regmap *regmap;
30 unsigned int sysclk; 32 unsigned int sysclk;
31}; 33};
32 34
33/* max9850 register cache */ 35/* max9850 register cache */
34static const u8 max9850_reg[MAX9850_CACHEREGNUM] = { 36static const struct reg_default max9850_reg[] = {
35 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 37 { 2, 0x0c },
38 { 3, 0x00 },
39 { 4, 0x00 },
40 { 5, 0x00 },
41 { 6, 0x00 },
42 { 7, 0x00 },
43 { 8, 0x00 },
44 { 9, 0x00 },
45 { 10, 0x00 },
36}; 46};
37 47
38/* these registers are not used at the moment but provided for the sake of 48/* these registers are not used at the moment but provided for the sake of
39 * completeness */ 49 * completeness */
40static int max9850_volatile_register(struct snd_soc_codec *codec, 50static bool max9850_volatile_register(struct device *dev, unsigned int reg)
41 unsigned int reg)
42{ 51{
43 switch (reg) { 52 switch (reg) {
44 case MAX9850_STATUSA: 53 case MAX9850_STATUSA:
@@ -49,6 +58,15 @@ static int max9850_volatile_register(struct snd_soc_codec *codec,
49 } 58 }
50} 59}
51 60
61static const struct regmap_config max9850_regmap = {
62 .reg_bits = 8,
63 .val_bits = 8,
64
65 .max_register = MAX9850_DIGITAL_AUDIO,
66 .volatile_reg = max9850_volatile_register,
67 .cache_type = REGCACHE_RBTREE,
68};
69
52static const unsigned int max9850_tlv[] = { 70static const unsigned int max9850_tlv[] = {
53 TLV_DB_RANGE_HEAD(4), 71 TLV_DB_RANGE_HEAD(4),
54 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0), 72 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0),
@@ -225,6 +243,7 @@ static int max9850_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
225static int max9850_set_bias_level(struct snd_soc_codec *codec, 243static int max9850_set_bias_level(struct snd_soc_codec *codec,
226 enum snd_soc_bias_level level) 244 enum snd_soc_bias_level level)
227{ 245{
246 struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec);
228 int ret; 247 int ret;
229 248
230 switch (level) { 249 switch (level) {
@@ -234,7 +253,7 @@ static int max9850_set_bias_level(struct snd_soc_codec *codec,
234 break; 253 break;
235 case SND_SOC_BIAS_STANDBY: 254 case SND_SOC_BIAS_STANDBY:
236 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 255 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
237 ret = snd_soc_cache_sync(codec); 256 ret = regcache_sync(max9850->regmap);
238 if (ret) { 257 if (ret) {
239 dev_err(codec->dev, 258 dev_err(codec->dev,
240 "Failed to sync cache: %d\n", ret); 259 "Failed to sync cache: %d\n", ret);
@@ -295,7 +314,7 @@ static int max9850_probe(struct snd_soc_codec *codec)
295{ 314{
296 int ret; 315 int ret;
297 316
298 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 317 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
299 if (ret < 0) { 318 if (ret < 0) {
300 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 319 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
301 return ret; 320 return ret;
@@ -316,10 +335,6 @@ static struct snd_soc_codec_driver soc_codec_dev_max9850 = {
316 .suspend = max9850_suspend, 335 .suspend = max9850_suspend,
317 .resume = max9850_resume, 336 .resume = max9850_resume,
318 .set_bias_level = max9850_set_bias_level, 337 .set_bias_level = max9850_set_bias_level,
319 .reg_cache_size = ARRAY_SIZE(max9850_reg),
320 .reg_word_size = sizeof(u8),
321 .reg_cache_default = max9850_reg,
322 .volatile_register = max9850_volatile_register,
323 338
324 .controls = max9850_controls, 339 .controls = max9850_controls,
325 .num_controls = ARRAY_SIZE(max9850_controls), 340 .num_controls = ARRAY_SIZE(max9850_controls),
@@ -340,6 +355,10 @@ static int max9850_i2c_probe(struct i2c_client *i2c,
340 if (max9850 == NULL) 355 if (max9850 == NULL)
341 return -ENOMEM; 356 return -ENOMEM;
342 357
358 max9850->regmap = devm_regmap_init_i2c(i2c, &max9850_regmap);
359 if (IS_ERR(max9850->regmap))
360 return PTR_ERR(max9850->regmap);
361
343 i2c_set_clientdata(i2c, max9850); 362 i2c_set_clientdata(i2c, max9850);
344 363
345 ret = snd_soc_register_codec(&i2c->dev, 364 ret = snd_soc_register_codec(&i2c->dev,
diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c
index ea141e1d6f28..bae60164c7b7 100644
--- a/sound/soc/codecs/mc13783.c
+++ b/sound/soc/codecs/mc13783.c
@@ -30,16 +30,10 @@
30#include <sound/soc.h> 30#include <sound/soc.h>
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include <sound/soc-dapm.h> 32#include <sound/soc-dapm.h>
33#include <linux/regmap.h>
33 34
34#include "mc13783.h" 35#include "mc13783.h"
35 36
36#define MC13783_AUDIO_RX0 36
37#define MC13783_AUDIO_RX1 37
38#define MC13783_AUDIO_TX 38
39#define MC13783_SSI_NETWORK 39
40#define MC13783_AUDIO_CODEC 40
41#define MC13783_AUDIO_DAC 41
42
43#define AUDIO_RX0_ALSPEN (1 << 5) 37#define AUDIO_RX0_ALSPEN (1 << 5)
44#define AUDIO_RX0_ALSPSEL (1 << 7) 38#define AUDIO_RX0_ALSPSEL (1 << 7)
45#define AUDIO_RX0_ADDCDC (1 << 21) 39#define AUDIO_RX0_ADDCDC (1 << 21)
@@ -95,45 +89,12 @@
95 89
96struct mc13783_priv { 90struct mc13783_priv {
97 struct mc13xxx *mc13xxx; 91 struct mc13xxx *mc13xxx;
92 struct regmap *regmap;
98 93
99 enum mc13783_ssi_port adc_ssi_port; 94 enum mc13783_ssi_port adc_ssi_port;
100 enum mc13783_ssi_port dac_ssi_port; 95 enum mc13783_ssi_port dac_ssi_port;
101}; 96};
102 97
103static unsigned int mc13783_read(struct snd_soc_codec *codec,
104 unsigned int reg)
105{
106 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
107 unsigned int value = 0;
108
109 mc13xxx_lock(priv->mc13xxx);
110
111 mc13xxx_reg_read(priv->mc13xxx, reg, &value);
112
113 mc13xxx_unlock(priv->mc13xxx);
114
115 return value;
116}
117
118static int mc13783_write(struct snd_soc_codec *codec,
119 unsigned int reg, unsigned int value)
120{
121 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
122 int ret;
123
124 mc13xxx_lock(priv->mc13xxx);
125
126 ret = mc13xxx_reg_write(priv->mc13xxx, reg, value);
127
128 /* include errata fix for spi audio problems */
129 if (reg == MC13783_AUDIO_CODEC || reg == MC13783_AUDIO_DAC)
130 ret = mc13xxx_reg_write(priv->mc13xxx, reg, value);
131
132 mc13xxx_unlock(priv->mc13xxx);
133
134 return ret;
135}
136
137/* Mapping between sample rates and register value */ 98/* Mapping between sample rates and register value */
138static unsigned int mc13783_rates[] = { 99static unsigned int mc13783_rates[] = {
139 8000, 11025, 12000, 16000, 100 8000, 11025, 12000, 16000,
@@ -382,7 +343,7 @@ static int mc13783_set_tdm_slot_dac(struct snd_soc_dai *dai,
382 break; 343 break;
383 default: 344 default:
384 return -EINVAL; 345 return -EINVAL;
385 }; 346 }
386 347
387 snd_soc_update_bits(codec, MC13783_SSI_NETWORK, mask, val); 348 snd_soc_update_bits(codec, MC13783_SSI_NETWORK, mask, val);
388 349
@@ -466,6 +427,29 @@ static const struct snd_kcontrol_new right_input_mux =
466static const struct snd_kcontrol_new samp_ctl = 427static const struct snd_kcontrol_new samp_ctl =
467 SOC_DAPM_SINGLE("Switch", MC13783_AUDIO_RX0, 3, 1, 0); 428 SOC_DAPM_SINGLE("Switch", MC13783_AUDIO_RX0, 3, 1, 0);
468 429
430static const char * const speaker_amp_source_text[] = {
431 "CODEC", "Right"
432};
433static const SOC_ENUM_SINGLE_DECL(speaker_amp_source, MC13783_AUDIO_RX0, 4,
434 speaker_amp_source_text);
435static const struct snd_kcontrol_new speaker_amp_source_mux =
436 SOC_DAPM_ENUM("Speaker Amp Source MUX", speaker_amp_source);
437
438static const char * const headset_amp_source_text[] = {
439 "CODEC", "Mixer"
440};
441
442static const SOC_ENUM_SINGLE_DECL(headset_amp_source, MC13783_AUDIO_RX0, 11,
443 headset_amp_source_text);
444static const struct snd_kcontrol_new headset_amp_source_mux =
445 SOC_DAPM_ENUM("Headset Amp Source MUX", headset_amp_source);
446
447static const struct snd_kcontrol_new cdcout_ctl =
448 SOC_DAPM_SINGLE("Switch", MC13783_AUDIO_RX0, 18, 1, 0);
449
450static const struct snd_kcontrol_new adc_bypass_ctl =
451 SOC_DAPM_SINGLE("Switch", MC13783_AUDIO_CODEC, 16, 1, 0);
452
469static const struct snd_kcontrol_new lamp_ctl = 453static const struct snd_kcontrol_new lamp_ctl =
470 SOC_DAPM_SINGLE("Switch", MC13783_AUDIO_RX0, 5, 1, 0); 454 SOC_DAPM_SINGLE("Switch", MC13783_AUDIO_RX0, 5, 1, 0);
471 455
@@ -503,12 +487,22 @@ static const struct snd_soc_dapm_widget mc13783_dapm_widgets[] = {
503 SND_SOC_DAPM_VIRT_MUX("PGA Right Input Mux", SND_SOC_NOPM, 0, 0, 487 SND_SOC_DAPM_VIRT_MUX("PGA Right Input Mux", SND_SOC_NOPM, 0, 0,
504 &right_input_mux), 488 &right_input_mux),
505 489
490 SND_SOC_DAPM_MUX("Speaker Amp Source MUX", SND_SOC_NOPM, 0, 0,
491 &speaker_amp_source_mux),
492
493 SND_SOC_DAPM_MUX("Headset Amp Source MUX", SND_SOC_NOPM, 0, 0,
494 &headset_amp_source_mux),
495
506 SND_SOC_DAPM_PGA("PGA Left Input", SND_SOC_NOPM, 0, 0, NULL, 0), 496 SND_SOC_DAPM_PGA("PGA Left Input", SND_SOC_NOPM, 0, 0, NULL, 0),
507 SND_SOC_DAPM_PGA("PGA Right Input", SND_SOC_NOPM, 0, 0, NULL, 0), 497 SND_SOC_DAPM_PGA("PGA Right Input", SND_SOC_NOPM, 0, 0, NULL, 0),
508 498
509 SND_SOC_DAPM_ADC("ADC", "Capture", MC13783_AUDIO_CODEC, 11, 0), 499 SND_SOC_DAPM_ADC("ADC", "Capture", MC13783_AUDIO_CODEC, 11, 0),
510 SND_SOC_DAPM_SUPPLY("ADC_Reset", MC13783_AUDIO_CODEC, 15, 0, NULL, 0), 500 SND_SOC_DAPM_SUPPLY("ADC_Reset", MC13783_AUDIO_CODEC, 15, 0, NULL, 0),
511 501
502 SND_SOC_DAPM_PGA("Voice CODEC PGA", MC13783_AUDIO_RX1, 0, 0, NULL, 0),
503 SND_SOC_DAPM_SWITCH("Voice CODEC Bypass", MC13783_AUDIO_CODEC, 16, 0,
504 &adc_bypass_ctl),
505
512/* Output */ 506/* Output */
513 SND_SOC_DAPM_SUPPLY("DAC_E", MC13783_AUDIO_DAC, 11, 0, NULL, 0), 507 SND_SOC_DAPM_SUPPLY("DAC_E", MC13783_AUDIO_DAC, 11, 0, NULL, 0),
514 SND_SOC_DAPM_SUPPLY("DAC_Reset", MC13783_AUDIO_DAC, 15, 0, NULL, 0), 508 SND_SOC_DAPM_SUPPLY("DAC_Reset", MC13783_AUDIO_DAC, 15, 0, NULL, 0),
@@ -516,10 +510,15 @@ static const struct snd_soc_dapm_widget mc13783_dapm_widgets[] = {
516 SND_SOC_DAPM_OUTPUT("RXOUTR"), 510 SND_SOC_DAPM_OUTPUT("RXOUTR"),
517 SND_SOC_DAPM_OUTPUT("HSL"), 511 SND_SOC_DAPM_OUTPUT("HSL"),
518 SND_SOC_DAPM_OUTPUT("HSR"), 512 SND_SOC_DAPM_OUTPUT("HSR"),
513 SND_SOC_DAPM_OUTPUT("LSPL"),
519 SND_SOC_DAPM_OUTPUT("LSP"), 514 SND_SOC_DAPM_OUTPUT("LSP"),
520 SND_SOC_DAPM_OUTPUT("SP"), 515 SND_SOC_DAPM_OUTPUT("SP"),
516 SND_SOC_DAPM_OUTPUT("CDCOUT"),
521 517
522 SND_SOC_DAPM_SWITCH("Speaker Amp", MC13783_AUDIO_RX0, 3, 0, &samp_ctl), 518 SND_SOC_DAPM_SWITCH("CDCOUT Switch", MC13783_AUDIO_RX0, 18, 0,
519 &cdcout_ctl),
520 SND_SOC_DAPM_SWITCH("Speaker Amp Switch", MC13783_AUDIO_RX0, 3, 0,
521 &samp_ctl),
523 SND_SOC_DAPM_SWITCH("Loudspeaker Amp", SND_SOC_NOPM, 0, 0, &lamp_ctl), 522 SND_SOC_DAPM_SWITCH("Loudspeaker Amp", SND_SOC_NOPM, 0, 0, &lamp_ctl),
524 SND_SOC_DAPM_SWITCH("Headset Amp Left", MC13783_AUDIO_RX0, 10, 0, 523 SND_SOC_DAPM_SWITCH("Headset Amp Left", MC13783_AUDIO_RX0, 10, 0,
525 &hlamp_ctl), 524 &hlamp_ctl),
@@ -554,20 +553,28 @@ static struct snd_soc_dapm_route mc13783_routes[] = {
554 { "ADC", NULL, "PGA Right Input"}, 553 { "ADC", NULL, "PGA Right Input"},
555 { "ADC", NULL, "ADC_Reset"}, 554 { "ADC", NULL, "ADC_Reset"},
556 555
556 { "Voice CODEC PGA", "Voice CODEC Bypass", "ADC" },
557
558 { "Speaker Amp Source MUX", "CODEC", "Voice CODEC PGA"},
559 { "Speaker Amp Source MUX", "Right", "DAC PGA"},
560
561 { "Headset Amp Source MUX", "CODEC", "Voice CODEC PGA"},
562 { "Headset Amp Source MUX", "Mixer", "DAC PGA"},
563
557/* Output */ 564/* Output */
558 { "HSL", NULL, "Headset Amp Left" }, 565 { "HSL", NULL, "Headset Amp Left" },
559 { "HSR", NULL, "Headset Amp Right"}, 566 { "HSR", NULL, "Headset Amp Right"},
560 { "RXOUTL", NULL, "Line out Amp Left"}, 567 { "RXOUTL", NULL, "Line out Amp Left"},
561 { "RXOUTR", NULL, "Line out Amp Right"}, 568 { "RXOUTR", NULL, "Line out Amp Right"},
562 { "SP", NULL, "Speaker Amp"}, 569 { "SP", "Speaker Amp Switch", "Speaker Amp Source MUX"},
563 { "Speaker Amp", NULL, "DAC PGA"}, 570 { "LSP", "Loudspeaker Amp", "Speaker Amp Source MUX"},
564 { "LSP", NULL, "DAC PGA"}, 571 { "HSL", "Headset Amp Left", "Headset Amp Source MUX"},
565 { "Headset Amp Left", NULL, "DAC PGA"}, 572 { "HSR", "Headset Amp Right", "Headset Amp Source MUX"},
566 { "Headset Amp Right", NULL, "DAC PGA"},
567 { "Line out Amp Left", NULL, "DAC PGA"}, 573 { "Line out Amp Left", NULL, "DAC PGA"},
568 { "Line out Amp Right", NULL, "DAC PGA"}, 574 { "Line out Amp Right", NULL, "DAC PGA"},
569 { "DAC PGA", NULL, "DAC"}, 575 { "DAC PGA", NULL, "DAC"},
570 { "DAC", NULL, "DAC_E"}, 576 { "DAC", NULL, "DAC_E"},
577 { "CDCOUT", "CDCOUT Switch", "Voice CODEC PGA"},
571}; 578};
572 579
573static const char * const mc13783_3d_mixer[] = {"Stereo", "Phase Mix", 580static const char * const mc13783_3d_mixer[] = {"Stereo", "Phase Mix",
@@ -580,15 +587,39 @@ static const struct soc_enum mc13783_enum_3d_mixer =
580static struct snd_kcontrol_new mc13783_control_list[] = { 587static struct snd_kcontrol_new mc13783_control_list[] = {
581 SOC_SINGLE("Loudspeaker enable", MC13783_AUDIO_RX0, 5, 1, 0), 588 SOC_SINGLE("Loudspeaker enable", MC13783_AUDIO_RX0, 5, 1, 0),
582 SOC_SINGLE("PCM Playback Volume", MC13783_AUDIO_RX1, 6, 15, 0), 589 SOC_SINGLE("PCM Playback Volume", MC13783_AUDIO_RX1, 6, 15, 0),
590 SOC_SINGLE("PCM Playback Switch", MC13783_AUDIO_RX1, 5, 1, 0),
583 SOC_DOUBLE("PCM Capture Volume", MC13783_AUDIO_TX, 19, 14, 31, 0), 591 SOC_DOUBLE("PCM Capture Volume", MC13783_AUDIO_TX, 19, 14, 31, 0),
584 SOC_ENUM("3D Control", mc13783_enum_3d_mixer), 592 SOC_ENUM("3D Control", mc13783_enum_3d_mixer),
593
594 SOC_SINGLE("CDCOUT Switch", MC13783_AUDIO_RX0, 18, 1, 0),
595 SOC_SINGLE("Earpiece Amp Switch", MC13783_AUDIO_RX0, 3, 1, 0),
596 SOC_DOUBLE("Headset Amp Switch", MC13783_AUDIO_RX0, 10, 9, 1, 0),
597 SOC_DOUBLE("Line out Amp Switch", MC13783_AUDIO_RX0, 16, 15, 1, 0),
598
599 SOC_SINGLE("PCM Capture Mixin Switch", MC13783_AUDIO_RX0, 22, 1, 0),
600 SOC_SINGLE("Line in Capture Mixin Switch", MC13783_AUDIO_RX0, 23, 1, 0),
601
602 SOC_SINGLE("CODEC Capture Volume", MC13783_AUDIO_RX1, 1, 15, 0),
603 SOC_SINGLE("CODEC Capture Mixin Switch", MC13783_AUDIO_RX0, 21, 1, 0),
604
605 SOC_SINGLE("Line in Capture Volume", MC13783_AUDIO_RX1, 12, 15, 0),
606 SOC_SINGLE("Line in Capture Switch", MC13783_AUDIO_RX1, 10, 1, 0),
607
608 SOC_SINGLE("MC1 Capture Bias Switch", MC13783_AUDIO_TX, 0, 1, 0),
609 SOC_SINGLE("MC2 Capture Bias Switch", MC13783_AUDIO_TX, 1, 1, 0),
585}; 610};
586 611
587static int mc13783_probe(struct snd_soc_codec *codec) 612static int mc13783_probe(struct snd_soc_codec *codec)
588{ 613{
589 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec); 614 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
615 int ret;
590 616
591 mc13xxx_lock(priv->mc13xxx); 617 codec->control_data = dev_get_regmap(codec->dev->parent, NULL);
618 ret = snd_soc_codec_set_cache_io(codec, 8, 24, SND_SOC_REGMAP);
619 if (ret != 0) {
620 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
621 return ret;
622 }
592 623
593 /* these are the reset values */ 624 /* these are the reset values */
594 mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_RX0, 0x25893); 625 mc13xxx_reg_write(priv->mc13xxx, MC13783_AUDIO_RX0, 0x25893);
@@ -612,8 +643,6 @@ static int mc13783_probe(struct snd_soc_codec *codec)
612 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC, 643 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC,
613 0, AUDIO_SSI_SEL); 644 0, AUDIO_SSI_SEL);
614 645
615 mc13xxx_unlock(priv->mc13xxx);
616
617 return 0; 646 return 0;
618} 647}
619 648
@@ -621,13 +650,9 @@ static int mc13783_remove(struct snd_soc_codec *codec)
621{ 650{
622 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec); 651 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
623 652
624 mc13xxx_lock(priv->mc13xxx);
625
626 /* Make sure VAUDIOON is off */ 653 /* Make sure VAUDIOON is off */
627 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_RX0, 0x3, 0); 654 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_RX0, 0x3, 0);
628 655
629 mc13xxx_unlock(priv->mc13xxx);
630
631 return 0; 656 return 0;
632} 657}
633 658
@@ -717,8 +742,6 @@ static struct snd_soc_dai_driver mc13783_dai_sync[] = {
717static struct snd_soc_codec_driver soc_codec_dev_mc13783 = { 742static struct snd_soc_codec_driver soc_codec_dev_mc13783 = {
718 .probe = mc13783_probe, 743 .probe = mc13783_probe,
719 .remove = mc13783_remove, 744 .remove = mc13783_remove,
720 .read = mc13783_read,
721 .write = mc13783_write,
722 .controls = mc13783_control_list, 745 .controls = mc13783_control_list,
723 .num_controls = ARRAY_SIZE(mc13783_control_list), 746 .num_controls = ARRAY_SIZE(mc13783_control_list),
724 .dapm_widgets = mc13783_dapm_widgets, 747 .dapm_widgets = mc13783_dapm_widgets,
diff --git a/sound/soc/codecs/ml26124.c b/sound/soc/codecs/ml26124.c
index 26118828782b..185fa3bc3052 100644
--- a/sound/soc/codecs/ml26124.c
+++ b/sound/soc/codecs/ml26124.c
@@ -342,6 +342,8 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream,
342 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec); 342 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
343 int i = get_coeff(priv->mclk, params_rate(hw_params)); 343 int i = get_coeff(priv->mclk, params_rate(hw_params));
344 344
345 if (i < 0)
346 return i;
345 priv->substream = substream; 347 priv->substream = substream;
346 priv->rate = params_rate(hw_params); 348 priv->rate = params_rate(hw_params);
347 349
diff --git a/sound/soc/codecs/pcm1681.c b/sound/soc/codecs/pcm1681.c
index 651ce0923675..73f9c3630e2c 100644
--- a/sound/soc/codecs/pcm1681.c
+++ b/sound/soc/codecs/pcm1681.c
@@ -21,6 +21,7 @@
21#include <linux/gpio.h> 21#include <linux/gpio.h>
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/regmap.h> 23#include <linux/regmap.h>
24#include <linux/of.h>
24#include <linux/of_device.h> 25#include <linux/of_device.h>
25#include <linux/of_gpio.h> 26#include <linux/of_gpio.h>
26#include <sound/pcm.h> 27#include <sound/pcm.h>
@@ -270,7 +271,7 @@ MODULE_DEVICE_TABLE(of, pcm1681_dt_ids);
270static const struct regmap_config pcm1681_regmap = { 271static const struct regmap_config pcm1681_regmap = {
271 .reg_bits = 8, 272 .reg_bits = 8,
272 .val_bits = 8, 273 .val_bits = 8,
273 .max_register = ARRAY_SIZE(pcm1681_reg_defaults) + 1, 274 .max_register = 0x13,
274 .reg_defaults = pcm1681_reg_defaults, 275 .reg_defaults = pcm1681_reg_defaults,
275 .num_reg_defaults = ARRAY_SIZE(pcm1681_reg_defaults), 276 .num_reg_defaults = ARRAY_SIZE(pcm1681_reg_defaults),
276 .writeable_reg = pcm1681_writeable_reg, 277 .writeable_reg = pcm1681_writeable_reg,
diff --git a/sound/soc/codecs/pcm1792a.c b/sound/soc/codecs/pcm1792a.c
index 2a8eccf64c76..7146653a8e16 100644
--- a/sound/soc/codecs/pcm1792a.c
+++ b/sound/soc/codecs/pcm1792a.c
@@ -28,6 +28,7 @@
28#include <sound/initval.h> 28#include <sound/initval.h>
29#include <sound/soc.h> 29#include <sound/soc.h>
30#include <sound/tlv.h> 30#include <sound/tlv.h>
31#include <linux/of.h>
31#include <linux/of_device.h> 32#include <linux/of_device.h>
32 33
33#include "pcm1792a.h" 34#include "pcm1792a.h"
@@ -188,7 +189,7 @@ MODULE_DEVICE_TABLE(of, pcm1792a_of_match);
188static const struct regmap_config pcm1792a_regmap = { 189static const struct regmap_config pcm1792a_regmap = {
189 .reg_bits = 8, 190 .reg_bits = 8,
190 .val_bits = 8, 191 .val_bits = 8,
191 .max_register = 24, 192 .max_register = 23,
192 .reg_defaults = pcm1792a_reg_defaults, 193 .reg_defaults = pcm1792a_reg_defaults,
193 .num_reg_defaults = ARRAY_SIZE(pcm1792a_reg_defaults), 194 .num_reg_defaults = ARRAY_SIZE(pcm1792a_reg_defaults),
194 .writeable_reg = pcm1792a_writeable_reg, 195 .writeable_reg = pcm1792a_writeable_reg,
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index c26a8f814b18..a3fb41179636 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -21,6 +21,7 @@
21#include <linux/of_gpio.h> 21#include <linux/of_gpio.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
24#include <linux/acpi.h>
24#include <sound/core.h> 25#include <sound/core.h>
25#include <sound/pcm.h> 26#include <sound/pcm.h>
26#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
@@ -926,7 +927,7 @@ static int rt5640_set_dmic2_event(struct snd_soc_dapm_widget *w,
926 return 0; 927 return 0;
927} 928}
928 929
929void hp_amp_power_on(struct snd_soc_codec *codec) 930static void hp_amp_power_on(struct snd_soc_codec *codec)
930{ 931{
931 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 932 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
932 933
@@ -1603,13 +1604,14 @@ static int rt5640_hw_params(struct snd_pcm_substream *substream,
1603 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1604 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1604 struct snd_soc_codec *codec = rtd->codec; 1605 struct snd_soc_codec *codec = rtd->codec;
1605 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 1606 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1606 unsigned int val_len = 0, val_clk, mask_clk, dai_sel; 1607 unsigned int val_len = 0, val_clk, mask_clk;
1607 int pre_div, bclk_ms, frame_size; 1608 int dai_sel, pre_div, bclk_ms, frame_size;
1608 1609
1609 rt5640->lrck[dai->id] = params_rate(params); 1610 rt5640->lrck[dai->id] = params_rate(params);
1610 pre_div = get_clk_info(rt5640->sysclk, rt5640->lrck[dai->id]); 1611 pre_div = get_clk_info(rt5640->sysclk, rt5640->lrck[dai->id]);
1611 if (pre_div < 0) { 1612 if (pre_div < 0) {
1612 dev_err(codec->dev, "Unsupported clock setting\n"); 1613 dev_err(codec->dev, "Unsupported clock setting %d for DAI %d\n",
1614 rt5640->lrck[dai->id], dai->id);
1613 return -EINVAL; 1615 return -EINVAL;
1614 } 1616 }
1615 frame_size = snd_soc_params_to_frame_size(params); 1617 frame_size = snd_soc_params_to_frame_size(params);
@@ -1673,7 +1675,8 @@ static int rt5640_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1673{ 1675{
1674 struct snd_soc_codec *codec = dai->codec; 1676 struct snd_soc_codec *codec = dai->codec;
1675 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 1677 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1676 unsigned int reg_val = 0, dai_sel; 1678 unsigned int reg_val = 0;
1679 int dai_sel;
1677 1680
1678 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1681 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1679 case SND_SOC_DAIFMT_CBM_CFM: 1682 case SND_SOC_DAIFMT_CBM_CFM:
@@ -1977,13 +1980,20 @@ static int rt5640_suspend(struct snd_soc_codec *codec)
1977 rt5640_reset(codec); 1980 rt5640_reset(codec);
1978 regcache_cache_only(rt5640->regmap, true); 1981 regcache_cache_only(rt5640->regmap, true);
1979 regcache_mark_dirty(rt5640->regmap); 1982 regcache_mark_dirty(rt5640->regmap);
1983 if (gpio_is_valid(rt5640->pdata.ldo1_en))
1984 gpio_set_value_cansleep(rt5640->pdata.ldo1_en, 0);
1980 1985
1981 return 0; 1986 return 0;
1982} 1987}
1983 1988
1984static int rt5640_resume(struct snd_soc_codec *codec) 1989static int rt5640_resume(struct snd_soc_codec *codec)
1985{ 1990{
1986 rt5640_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1991 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1992
1993 if (gpio_is_valid(rt5640->pdata.ldo1_en)) {
1994 gpio_set_value_cansleep(rt5640->pdata.ldo1_en, 1);
1995 msleep(400);
1996 }
1987 1997
1988 return 0; 1998 return 0;
1989} 1999}
@@ -2080,6 +2090,14 @@ static const struct i2c_device_id rt5640_i2c_id[] = {
2080}; 2090};
2081MODULE_DEVICE_TABLE(i2c, rt5640_i2c_id); 2091MODULE_DEVICE_TABLE(i2c, rt5640_i2c_id);
2082 2092
2093#ifdef CONFIG_ACPI
2094static struct acpi_device_id rt5640_acpi_match[] = {
2095 { "INT33CA", 0 },
2096 { },
2097};
2098MODULE_DEVICE_TABLE(acpi, rt5640_acpi_match);
2099#endif
2100
2083static int rt5640_parse_dt(struct rt5640_priv *rt5640, struct device_node *np) 2101static int rt5640_parse_dt(struct rt5640_priv *rt5640, struct device_node *np)
2084{ 2102{
2085 rt5640->pdata.in1_diff = of_property_read_bool(np, 2103 rt5640->pdata.in1_diff = of_property_read_bool(np,
@@ -2199,6 +2217,7 @@ static struct i2c_driver rt5640_i2c_driver = {
2199 .driver = { 2217 .driver = {
2200 .name = "rt5640", 2218 .name = "rt5640",
2201 .owner = THIS_MODULE, 2219 .owner = THIS_MODULE,
2220 .acpi_match_table = ACPI_PTR(rt5640_acpi_match),
2202 }, 2221 },
2203 .probe = rt5640_i2c_probe, 2222 .probe = rt5640_i2c_probe,
2204 .remove = rt5640_i2c_remove, 2223 .remove = rt5640_i2c_remove,
diff --git a/sound/soc/codecs/si476x.c b/sound/soc/codecs/si476x.c
index 38f3b105c17d..52e7cb08434b 100644
--- a/sound/soc/codecs/si476x.c
+++ b/sound/soc/codecs/si476x.c
@@ -60,48 +60,6 @@ enum si476x_pcm_format {
60 SI476X_PCM_FORMAT_S24_LE = 6, 60 SI476X_PCM_FORMAT_S24_LE = 6,
61}; 61};
62 62
63static unsigned int si476x_codec_read(struct snd_soc_codec *codec,
64 unsigned int reg)
65{
66 int err;
67 unsigned int val;
68 struct si476x_core *core = codec->control_data;
69
70 si476x_core_lock(core);
71 if (!si476x_core_is_powered_up(core))
72 regcache_cache_only(core->regmap, true);
73
74 err = regmap_read(core->regmap, reg, &val);
75
76 if (!si476x_core_is_powered_up(core))
77 regcache_cache_only(core->regmap, false);
78 si476x_core_unlock(core);
79
80 if (err < 0)
81 return err;
82
83 return val;
84}
85
86static int si476x_codec_write(struct snd_soc_codec *codec,
87 unsigned int reg, unsigned int val)
88{
89 int err;
90 struct si476x_core *core = codec->control_data;
91
92 si476x_core_lock(core);
93 if (!si476x_core_is_powered_up(core))
94 regcache_cache_only(core->regmap, true);
95
96 err = regmap_write(core->regmap, reg, val);
97
98 if (!si476x_core_is_powered_up(core))
99 regcache_cache_only(core->regmap, false);
100 si476x_core_unlock(core);
101
102 return err;
103}
104
105static const struct snd_soc_dapm_widget si476x_dapm_widgets[] = { 63static const struct snd_soc_dapm_widget si476x_dapm_widgets[] = {
106SND_SOC_DAPM_OUTPUT("LOUT"), 64SND_SOC_DAPM_OUTPUT("LOUT"),
107SND_SOC_DAPM_OUTPUT("ROUT"), 65SND_SOC_DAPM_OUTPUT("ROUT"),
@@ -115,6 +73,7 @@ static const struct snd_soc_dapm_route si476x_dapm_routes[] = {
115static int si476x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai, 73static int si476x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai,
116 unsigned int fmt) 74 unsigned int fmt)
117{ 75{
76 struct si476x_core *core = i2c_mfd_cell_to_core(codec_dai->dev);
118 int err; 77 int err;
119 u16 format = 0; 78 u16 format = 0;
120 79
@@ -178,9 +137,14 @@ static int si476x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai,
178 return -EINVAL; 137 return -EINVAL;
179 } 138 }
180 139
140 si476x_core_lock(core);
141
181 err = snd_soc_update_bits(codec_dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT, 142 err = snd_soc_update_bits(codec_dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT,
182 SI476X_DIGITAL_IO_OUTPUT_FORMAT_MASK, 143 SI476X_DIGITAL_IO_OUTPUT_FORMAT_MASK,
183 format); 144 format);
145
146 si476x_core_unlock(core);
147
184 if (err < 0) { 148 if (err < 0) {
185 dev_err(codec_dai->codec->dev, "Failed to set output format\n"); 149 dev_err(codec_dai->codec->dev, "Failed to set output format\n");
186 return err; 150 return err;
@@ -193,6 +157,7 @@ static int si476x_codec_hw_params(struct snd_pcm_substream *substream,
193 struct snd_pcm_hw_params *params, 157 struct snd_pcm_hw_params *params,
194 struct snd_soc_dai *dai) 158 struct snd_soc_dai *dai)
195{ 159{
160 struct si476x_core *core = i2c_mfd_cell_to_core(dai->dev);
196 int rate, width, err; 161 int rate, width, err;
197 162
198 rate = params_rate(params); 163 rate = params_rate(params);
@@ -218,11 +183,13 @@ static int si476x_codec_hw_params(struct snd_pcm_substream *substream,
218 return -EINVAL; 183 return -EINVAL;
219 } 184 }
220 185
186 si476x_core_lock(core);
187
221 err = snd_soc_write(dai->codec, SI476X_DIGITAL_IO_OUTPUT_SAMPLE_RATE, 188 err = snd_soc_write(dai->codec, SI476X_DIGITAL_IO_OUTPUT_SAMPLE_RATE,
222 rate); 189 rate);
223 if (err < 0) { 190 if (err < 0) {
224 dev_err(dai->codec->dev, "Failed to set sample rate\n"); 191 dev_err(dai->codec->dev, "Failed to set sample rate\n");
225 return err; 192 goto out;
226 } 193 }
227 194
228 err = snd_soc_update_bits(dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT, 195 err = snd_soc_update_bits(dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT,
@@ -231,15 +198,18 @@ static int si476x_codec_hw_params(struct snd_pcm_substream *substream,
231 (width << SI476X_DIGITAL_IO_SAMPLE_SIZE_SHIFT)); 198 (width << SI476X_DIGITAL_IO_SAMPLE_SIZE_SHIFT));
232 if (err < 0) { 199 if (err < 0) {
233 dev_err(dai->codec->dev, "Failed to set output width\n"); 200 dev_err(dai->codec->dev, "Failed to set output width\n");
234 return err; 201 goto out;
235 } 202 }
236 203
237 return 0; 204out:
205 si476x_core_unlock(core);
206
207 return err;
238} 208}
239 209
240static int si476x_codec_probe(struct snd_soc_codec *codec) 210static int si476x_codec_probe(struct snd_soc_codec *codec)
241{ 211{
242 codec->control_data = i2c_mfd_cell_to_core(codec->dev); 212 codec->control_data = dev_get_regmap(codec->dev->parent, NULL);
243 return 0; 213 return 0;
244} 214}
245 215
@@ -268,8 +238,6 @@ static struct snd_soc_dai_driver si476x_dai = {
268 238
269static struct snd_soc_codec_driver soc_codec_dev_si476x = { 239static struct snd_soc_codec_driver soc_codec_dev_si476x = {
270 .probe = si476x_codec_probe, 240 .probe = si476x_codec_probe,
271 .read = si476x_codec_read,
272 .write = si476x_codec_write,
273 .dapm_widgets = si476x_dapm_widgets, 241 .dapm_widgets = si476x_dapm_widgets,
274 .num_dapm_widgets = ARRAY_SIZE(si476x_dapm_widgets), 242 .num_dapm_widgets = ARRAY_SIZE(si476x_dapm_widgets),
275 .dapm_routes = si476x_dapm_routes, 243 .dapm_routes = si476x_dapm_routes,
diff --git a/sound/soc/codecs/sn95031.c b/sound/soc/codecs/sn95031.c
index dba26e63844e..13045f2af4d3 100644
--- a/sound/soc/codecs/sn95031.c
+++ b/sound/soc/codecs/sn95031.c
@@ -164,30 +164,28 @@ static unsigned int sn95031_get_mic_bias(struct snd_soc_codec *codec)
164} 164}
165/*end - adc helper functions */ 165/*end - adc helper functions */
166 166
167static inline unsigned int sn95031_read(struct snd_soc_codec *codec, 167static int sn95031_read(void *ctx, unsigned int reg, unsigned int *val)
168 unsigned int reg)
169{ 168{
170 u8 value = 0; 169 u8 value = 0;
171 int ret; 170 int ret;
172 171
173 ret = intel_scu_ipc_ioread8(reg, &value); 172 ret = intel_scu_ipc_ioread8(reg, &value);
174 if (ret) 173 if (ret == 0)
175 pr_err("read of %x failed, err %d\n", reg, ret); 174 *val = value;
176 return value;
177 175
176 return ret;
178} 177}
179 178
180static inline int sn95031_write(struct snd_soc_codec *codec, 179static int sn95031_write(void *ctx, unsigned int reg, unsigned int value)
181 unsigned int reg, unsigned int value)
182{ 180{
183 int ret; 181 return intel_scu_ipc_iowrite8(reg, value);
184
185 ret = intel_scu_ipc_iowrite8(reg, value);
186 if (ret)
187 pr_err("write of %x failed, err %d\n", reg, ret);
188 return ret;
189} 182}
190 183
184static const struct regmap_config sn95031_regmap = {
185 .reg_read = sn95031_read,
186 .reg_write = sn95031_write,
187};
188
191static int sn95031_set_vaud_bias(struct snd_soc_codec *codec, 189static int sn95031_set_vaud_bias(struct snd_soc_codec *codec,
192 enum snd_soc_bias_level level) 190 enum snd_soc_bias_level level)
193{ 191{
@@ -827,6 +825,8 @@ static int sn95031_codec_probe(struct snd_soc_codec *codec)
827{ 825{
828 pr_debug("codec_probe called\n"); 826 pr_debug("codec_probe called\n");
829 827
828 snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
829
830 /* PCM interface config 830 /* PCM interface config
831 * This sets the pcm rx slot conguration to max 6 slots 831 * This sets the pcm rx slot conguration to max 6 slots
832 * for max 4 dais (2 stereo and 2 mono) 832 * for max 4 dais (2 stereo and 2 mono)
@@ -886,8 +886,6 @@ static int sn95031_codec_remove(struct snd_soc_codec *codec)
886static struct snd_soc_codec_driver sn95031_codec = { 886static struct snd_soc_codec_driver sn95031_codec = {
887 .probe = sn95031_codec_probe, 887 .probe = sn95031_codec_probe,
888 .remove = sn95031_codec_remove, 888 .remove = sn95031_codec_remove,
889 .read = sn95031_read,
890 .write = sn95031_write,
891 .set_bias_level = sn95031_set_vaud_bias, 889 .set_bias_level = sn95031_set_vaud_bias,
892 .idle_bias_off = true, 890 .idle_bias_off = true,
893 .dapm_widgets = sn95031_dapm_widgets, 891 .dapm_widgets = sn95031_dapm_widgets,
@@ -898,7 +896,14 @@ static struct snd_soc_codec_driver sn95031_codec = {
898 896
899static int sn95031_device_probe(struct platform_device *pdev) 897static int sn95031_device_probe(struct platform_device *pdev)
900{ 898{
899 struct regmap *regmap;
900
901 pr_debug("codec device probe called for %s\n", dev_name(&pdev->dev)); 901 pr_debug("codec device probe called for %s\n", dev_name(&pdev->dev));
902
903 regmap = devm_regmap_init(&pdev->dev, NULL, NULL, &sn95031_regmap);
904 if (IS_ERR(regmap))
905 return PTR_ERR(regmap);
906
902 return snd_soc_register_codec(&pdev->dev, &sn95031_codec, 907 return snd_soc_register_codec(&pdev->dev, &sn95031_codec,
903 sn95031_dais, ARRAY_SIZE(sn95031_dais)); 908 sn95031_dais, ARRAY_SIZE(sn95031_dais));
904} 909}
diff --git a/sound/soc/codecs/tas5086.c b/sound/soc/codecs/tas5086.c
index 6d31d88f7204..a895a5e4bdf2 100644
--- a/sound/soc/codecs/tas5086.c
+++ b/sound/soc/codecs/tas5086.c
@@ -37,6 +37,7 @@
37#include <linux/i2c.h> 37#include <linux/i2c.h>
38#include <linux/regmap.h> 38#include <linux/regmap.h>
39#include <linux/spi/spi.h> 39#include <linux/spi/spi.h>
40#include <linux/of.h>
40#include <linux/of_device.h> 41#include <linux/of_device.h>
41#include <linux/of_gpio.h> 42#include <linux/of_gpio.h>
42#include <sound/pcm.h> 43#include <sound/pcm.h>
@@ -244,6 +245,8 @@ struct tas5086_private {
244 unsigned int mclk, sclk; 245 unsigned int mclk, sclk;
245 unsigned int format; 246 unsigned int format;
246 bool deemph; 247 bool deemph;
248 unsigned int charge_period;
249 unsigned int pwm_start_mid_z;
247 /* Current sample rate for de-emphasis control */ 250 /* Current sample rate for de-emphasis control */
248 int rate; 251 int rate;
249 /* GPIO driving Reset pin, if any */ 252 /* GPIO driving Reset pin, if any */
@@ -429,7 +432,7 @@ static int tas5086_hw_params(struct snd_pcm_substream *substream,
429 default: 432 default:
430 dev_err(codec->dev, "Invalid bit width\n"); 433 dev_err(codec->dev, "Invalid bit width\n");
431 return -EINVAL; 434 return -EINVAL;
432 }; 435 }
433 436
434 ret = regmap_write(priv->regmap, TAS5086_SERIAL_DATA_IF, val); 437 ret = regmap_write(priv->regmap, TAS5086_SERIAL_DATA_IF, val);
435 if (ret < 0) 438 if (ret < 0)
@@ -456,6 +459,75 @@ static int tas5086_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
456 return regmap_write(priv->regmap, TAS5086_SOFT_MUTE, val); 459 return regmap_write(priv->regmap, TAS5086_SOFT_MUTE, val);
457} 460}
458 461
462static void tas5086_reset(struct tas5086_private *priv)
463{
464 if (gpio_is_valid(priv->gpio_nreset)) {
465 /* Reset codec - minimum assertion time is 400ns */
466 gpio_direction_output(priv->gpio_nreset, 0);
467 udelay(1);
468 gpio_set_value(priv->gpio_nreset, 1);
469
470 /* Codec needs ~15ms to wake up */
471 msleep(15);
472 }
473}
474
475/* charge period values in microseconds */
476static const int tas5086_charge_period[] = {
477 13000, 16900, 23400, 31200, 41600, 54600, 72800, 96200,
478 130000, 156000, 234000, 312000, 416000, 546000, 728000, 962000,
479 1300000, 169000, 2340000, 3120000, 4160000, 5460000, 7280000, 9620000,
480};
481
482static int tas5086_init(struct device *dev, struct tas5086_private *priv)
483{
484 int ret, i;
485
486 /*
487 * If any of the channels is configured to start in Mid-Z mode,
488 * configure 'part 1' of the PWM starts to use Mid-Z, and tell
489 * all configured mid-z channels to start start under 'part 1'.
490 */
491 if (priv->pwm_start_mid_z)
492 regmap_write(priv->regmap, TAS5086_PWM_START,
493 TAS5086_PWM_START_MIDZ_FOR_START_1 |
494 priv->pwm_start_mid_z);
495
496 /* lookup and set split-capacitor charge period */
497 if (priv->charge_period == 0) {
498 regmap_write(priv->regmap, TAS5086_SPLIT_CAP_CHARGE, 0);
499 } else {
500 i = index_in_array(tas5086_charge_period,
501 ARRAY_SIZE(tas5086_charge_period),
502 priv->charge_period);
503 if (i >= 0)
504 regmap_write(priv->regmap, TAS5086_SPLIT_CAP_CHARGE,
505 i + 0x08);
506 else
507 dev_warn(dev,
508 "Invalid split-cap charge period of %d ns.\n",
509 priv->charge_period);
510 }
511
512 /* enable factory trim */
513 ret = regmap_write(priv->regmap, TAS5086_OSC_TRIM, 0x00);
514 if (ret < 0)
515 return ret;
516
517 /* start all channels */
518 ret = regmap_write(priv->regmap, TAS5086_SYS_CONTROL_2, 0x20);
519 if (ret < 0)
520 return ret;
521
522 /* mute all channels for now */
523 ret = regmap_write(priv->regmap, TAS5086_SOFT_MUTE,
524 TAS5086_SOFT_MUTE_ALL);
525 if (ret < 0)
526 return ret;
527
528 return 0;
529}
530
459/* TAS5086 controls */ 531/* TAS5086 controls */
460static const DECLARE_TLV_DB_SCALE(tas5086_dac_tlv, -10350, 50, 1); 532static const DECLARE_TLV_DB_SCALE(tas5086_dac_tlv, -10350, 50, 1);
461 533
@@ -691,14 +763,39 @@ static struct snd_soc_dai_driver tas5086_dai = {
691}; 763};
692 764
693#ifdef CONFIG_PM 765#ifdef CONFIG_PM
766static int tas5086_soc_suspend(struct snd_soc_codec *codec)
767{
768 struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
769 int ret;
770
771 /* Shut down all channels */
772 ret = regmap_write(priv->regmap, TAS5086_SYS_CONTROL_2, 0x60);
773 if (ret < 0)
774 return ret;
775
776 return 0;
777}
778
694static int tas5086_soc_resume(struct snd_soc_codec *codec) 779static int tas5086_soc_resume(struct snd_soc_codec *codec)
695{ 780{
696 struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec); 781 struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
782 int ret;
783
784 tas5086_reset(priv);
785 regcache_mark_dirty(priv->regmap);
786
787 ret = tas5086_init(codec->dev, priv);
788 if (ret < 0)
789 return ret;
790
791 ret = regcache_sync(priv->regmap);
792 if (ret < 0)
793 return ret;
697 794
698 /* Restore codec state */ 795 return 0;
699 return regcache_sync(priv->regmap);
700} 796}
701#else 797#else
798#define tas5086_soc_suspend NULL
702#define tas5086_soc_resume NULL 799#define tas5086_soc_resume NULL
703#endif /* CONFIG_PM */ 800#endif /* CONFIG_PM */
704 801
@@ -710,23 +807,19 @@ static const struct of_device_id tas5086_dt_ids[] = {
710MODULE_DEVICE_TABLE(of, tas5086_dt_ids); 807MODULE_DEVICE_TABLE(of, tas5086_dt_ids);
711#endif 808#endif
712 809
713/* charge period values in microseconds */
714static const int tas5086_charge_period[] = {
715 13000, 16900, 23400, 31200, 41600, 54600, 72800, 96200,
716 130000, 156000, 234000, 312000, 416000, 546000, 728000, 962000,
717 1300000, 169000, 2340000, 3120000, 4160000, 5460000, 7280000, 9620000,
718};
719
720static int tas5086_probe(struct snd_soc_codec *codec) 810static int tas5086_probe(struct snd_soc_codec *codec)
721{ 811{
722 struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec); 812 struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec);
723 int charge_period = 1300000; /* hardware default is 1300 ms */
724 u8 pwm_start_mid_z = 0;
725 int i, ret; 813 int i, ret;
726 814
815 priv->pwm_start_mid_z = 0;
816 priv->charge_period = 1300000; /* hardware default is 1300 ms */
817
727 if (of_match_device(of_match_ptr(tas5086_dt_ids), codec->dev)) { 818 if (of_match_device(of_match_ptr(tas5086_dt_ids), codec->dev)) {
728 struct device_node *of_node = codec->dev->of_node; 819 struct device_node *of_node = codec->dev->of_node;
729 of_property_read_u32(of_node, "ti,charge-period", &charge_period); 820
821 of_property_read_u32(of_node, "ti,charge-period",
822 &priv->charge_period);
730 823
731 for (i = 0; i < 6; i++) { 824 for (i = 0; i < 6; i++) {
732 char name[25]; 825 char name[25];
@@ -735,43 +828,11 @@ static int tas5086_probe(struct snd_soc_codec *codec)
735 "ti,mid-z-channel-%d", i + 1); 828 "ti,mid-z-channel-%d", i + 1);
736 829
737 if (of_get_property(of_node, name, NULL) != NULL) 830 if (of_get_property(of_node, name, NULL) != NULL)
738 pwm_start_mid_z |= 1 << i; 831 priv->pwm_start_mid_z |= 1 << i;
739 } 832 }
740 } 833 }
741 834
742 /* 835 ret = tas5086_init(codec->dev, priv);
743 * If any of the channels is configured to start in Mid-Z mode,
744 * configure 'part 1' of the PWM starts to use Mid-Z, and tell
745 * all configured mid-z channels to start start under 'part 1'.
746 */
747 if (pwm_start_mid_z)
748 regmap_write(priv->regmap, TAS5086_PWM_START,
749 TAS5086_PWM_START_MIDZ_FOR_START_1 |
750 pwm_start_mid_z);
751
752 /* lookup and set split-capacitor charge period */
753 if (charge_period == 0) {
754 regmap_write(priv->regmap, TAS5086_SPLIT_CAP_CHARGE, 0);
755 } else {
756 i = index_in_array(tas5086_charge_period,
757 ARRAY_SIZE(tas5086_charge_period),
758 charge_period);
759 if (i >= 0)
760 regmap_write(priv->regmap, TAS5086_SPLIT_CAP_CHARGE,
761 i + 0x08);
762 else
763 dev_warn(codec->dev,
764 "Invalid split-cap charge period of %d ns.\n",
765 charge_period);
766 }
767
768 /* enable factory trim */
769 ret = regmap_write(priv->regmap, TAS5086_OSC_TRIM, 0x00);
770 if (ret < 0)
771 return ret;
772
773 /* start all channels */
774 ret = regmap_write(priv->regmap, TAS5086_SYS_CONTROL_2, 0x20);
775 if (ret < 0) 836 if (ret < 0)
776 return ret; 837 return ret;
777 838
@@ -780,12 +841,6 @@ static int tas5086_probe(struct snd_soc_codec *codec)
780 if (ret < 0) 841 if (ret < 0)
781 return ret; 842 return ret;
782 843
783 /* mute all channels for now */
784 ret = regmap_write(priv->regmap, TAS5086_SOFT_MUTE,
785 TAS5086_SOFT_MUTE_ALL);
786 if (ret < 0)
787 return ret;
788
789 return 0; 844 return 0;
790} 845}
791 846
@@ -803,6 +858,7 @@ static int tas5086_remove(struct snd_soc_codec *codec)
803static struct snd_soc_codec_driver soc_codec_dev_tas5086 = { 858static struct snd_soc_codec_driver soc_codec_dev_tas5086 = {
804 .probe = tas5086_probe, 859 .probe = tas5086_probe,
805 .remove = tas5086_remove, 860 .remove = tas5086_remove,
861 .suspend = tas5086_soc_suspend,
806 .resume = tas5086_soc_resume, 862 .resume = tas5086_soc_resume,
807 .controls = tas5086_controls, 863 .controls = tas5086_controls,
808 .num_controls = ARRAY_SIZE(tas5086_controls), 864 .num_controls = ARRAY_SIZE(tas5086_controls),
@@ -862,17 +918,8 @@ static int tas5086_i2c_probe(struct i2c_client *i2c,
862 if (devm_gpio_request(dev, gpio_nreset, "TAS5086 Reset")) 918 if (devm_gpio_request(dev, gpio_nreset, "TAS5086 Reset"))
863 gpio_nreset = -EINVAL; 919 gpio_nreset = -EINVAL;
864 920
865 if (gpio_is_valid(gpio_nreset)) {
866 /* Reset codec - minimum assertion time is 400ns */
867 gpio_direction_output(gpio_nreset, 0);
868 udelay(1);
869 gpio_set_value(gpio_nreset, 1);
870
871 /* Codec needs ~15ms to wake up */
872 msleep(15);
873 }
874
875 priv->gpio_nreset = gpio_nreset; 921 priv->gpio_nreset = gpio_nreset;
922 tas5086_reset(priv);
876 923
877 /* The TAS5086 always returns 0x03 in its TAS5086_DEV_ID register */ 924 /* The TAS5086 always returns 0x03 in its TAS5086_DEV_ID register */
878 ret = regmap_read(priv->regmap, TAS5086_DEV_ID, &i); 925 ret = regmap_read(priv->regmap, TAS5086_DEV_ID, &i);
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index 31762ebdd774..5d430cc56f51 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -24,6 +24,7 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/pm.h> 25#include <linux/pm.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/regmap.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include <sound/pcm.h> 30#include <sound/pcm.h>
@@ -37,11 +38,27 @@
37/* 38/*
38 * AIC23 register cache 39 * AIC23 register cache
39 */ 40 */
40static const u16 tlv320aic23_reg[] = { 41static const struct reg_default tlv320aic23_reg[] = {
41 0x0097, 0x0097, 0x00F9, 0x00F9, /* 0 */ 42 { 0, 0x0097 },
42 0x001A, 0x0004, 0x0007, 0x0001, /* 4 */ 43 { 1, 0x0097 },
43 0x0020, 0x0000, 0x0000, 0x0000, /* 8 */ 44 { 2, 0x00F9 },
44 0x0000, 0x0000, 0x0000, 0x0000, /* 12 */ 45 { 3, 0x00F9 },
46 { 4, 0x001A },
47 { 5, 0x0004 },
48 { 6, 0x0007 },
49 { 7, 0x0001 },
50 { 8, 0x0020 },
51 { 9, 0x0000 },
52};
53
54static const struct regmap_config tlv320aic23_regmap = {
55 .reg_bits = 7,
56 .val_bits = 9,
57
58 .max_register = TLV320AIC23_RESET,
59 .reg_defaults = tlv320aic23_reg,
60 .num_reg_defaults = ARRAY_SIZE(tlv320aic23_reg),
61 .cache_type = REGCACHE_RBTREE,
45}; 62};
46 63
47static const char *rec_src_text[] = { "Line", "Mic" }; 64static const char *rec_src_text[] = { "Line", "Mic" };
@@ -171,7 +188,7 @@ static const struct snd_soc_dapm_route tlv320aic23_intercon[] = {
171 188
172/* AIC23 driver data */ 189/* AIC23 driver data */
173struct aic23 { 190struct aic23 {
174 enum snd_soc_control_type control_type; 191 struct regmap *regmap;
175 int mclk; 192 int mclk;
176 int requested_adc; 193 int requested_adc;
177 int requested_dac; 194 int requested_dac;
@@ -532,7 +549,9 @@ static int tlv320aic23_suspend(struct snd_soc_codec *codec)
532 549
533static int tlv320aic23_resume(struct snd_soc_codec *codec) 550static int tlv320aic23_resume(struct snd_soc_codec *codec)
534{ 551{
535 snd_soc_cache_sync(codec); 552 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
553 regcache_mark_dirty(aic23->regmap);
554 regcache_sync(aic23->regmap);
536 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 555 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
537 556
538 return 0; 557 return 0;
@@ -540,10 +559,9 @@ static int tlv320aic23_resume(struct snd_soc_codec *codec)
540 559
541static int tlv320aic23_probe(struct snd_soc_codec *codec) 560static int tlv320aic23_probe(struct snd_soc_codec *codec)
542{ 561{
543 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
544 int ret; 562 int ret;
545 563
546 ret = snd_soc_codec_set_cache_io(codec, 7, 9, aic23->control_type); 564 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
547 if (ret < 0) { 565 if (ret < 0) {
548 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 566 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
549 return ret; 567 return ret;
@@ -552,16 +570,6 @@ static int tlv320aic23_probe(struct snd_soc_codec *codec)
552 /* Reset codec */ 570 /* Reset codec */
553 snd_soc_write(codec, TLV320AIC23_RESET, 0); 571 snd_soc_write(codec, TLV320AIC23_RESET, 0);
554 572
555 /* Write the register default value to cache for reserved registers,
556 * so the write to the these registers are suppressed by the cache
557 * restore code when it skips writes of default registers.
558 */
559 snd_soc_cache_write(codec, 0x0A, 0);
560 snd_soc_cache_write(codec, 0x0B, 0);
561 snd_soc_cache_write(codec, 0x0C, 0);
562 snd_soc_cache_write(codec, 0x0D, 0);
563 snd_soc_cache_write(codec, 0x0E, 0);
564
565 /* power on device */ 573 /* power on device */
566 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 574 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
567 575
@@ -586,9 +594,6 @@ static int tlv320aic23_probe(struct snd_soc_codec *codec)
586 594
587 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x1); 595 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x1);
588 596
589 snd_soc_add_codec_controls(codec, tlv320aic23_snd_controls,
590 ARRAY_SIZE(tlv320aic23_snd_controls));
591
592 return 0; 597 return 0;
593} 598}
594 599
@@ -599,21 +604,19 @@ static int tlv320aic23_remove(struct snd_soc_codec *codec)
599} 604}
600 605
601static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = { 606static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = {
602 .reg_cache_size = ARRAY_SIZE(tlv320aic23_reg),
603 .reg_word_size = sizeof(u16),
604 .reg_cache_default = tlv320aic23_reg,
605 .probe = tlv320aic23_probe, 607 .probe = tlv320aic23_probe,
606 .remove = tlv320aic23_remove, 608 .remove = tlv320aic23_remove,
607 .suspend = tlv320aic23_suspend, 609 .suspend = tlv320aic23_suspend,
608 .resume = tlv320aic23_resume, 610 .resume = tlv320aic23_resume,
609 .set_bias_level = tlv320aic23_set_bias_level, 611 .set_bias_level = tlv320aic23_set_bias_level,
612 .controls = tlv320aic23_snd_controls,
613 .num_controls = ARRAY_SIZE(tlv320aic23_snd_controls),
610 .dapm_widgets = tlv320aic23_dapm_widgets, 614 .dapm_widgets = tlv320aic23_dapm_widgets,
611 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets), 615 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
612 .dapm_routes = tlv320aic23_intercon, 616 .dapm_routes = tlv320aic23_intercon,
613 .num_dapm_routes = ARRAY_SIZE(tlv320aic23_intercon), 617 .num_dapm_routes = ARRAY_SIZE(tlv320aic23_intercon),
614}; 618};
615 619
616#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
617/* 620/*
618 * If the i2c layer weren't so broken, we could pass this kind of data 621 * If the i2c layer weren't so broken, we could pass this kind of data
619 * around 622 * around
@@ -631,8 +634,11 @@ static int tlv320aic23_codec_probe(struct i2c_client *i2c,
631 if (aic23 == NULL) 634 if (aic23 == NULL)
632 return -ENOMEM; 635 return -ENOMEM;
633 636
637 aic23->regmap = devm_regmap_init_i2c(i2c, &tlv320aic23_regmap);
638 if (IS_ERR(aic23->regmap))
639 return PTR_ERR(aic23->regmap);
640
634 i2c_set_clientdata(i2c, aic23); 641 i2c_set_clientdata(i2c, aic23);
635 aic23->control_type = SND_SOC_I2C;
636 642
637 ret = snd_soc_register_codec(&i2c->dev, 643 ret = snd_soc_register_codec(&i2c->dev,
638 &soc_codec_dev_tlv320aic23, &tlv320aic23_dai, 1); 644 &soc_codec_dev_tlv320aic23, &tlv320aic23_dai, 1);
@@ -660,29 +666,7 @@ static struct i2c_driver tlv320aic23_i2c_driver = {
660 .id_table = tlv320aic23_id, 666 .id_table = tlv320aic23_id,
661}; 667};
662 668
663#endif 669module_i2c_driver(tlv320aic23_i2c_driver);
664
665static int __init tlv320aic23_modinit(void)
666{
667 int ret;
668#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
669 ret = i2c_add_driver(&tlv320aic23_i2c_driver);
670 if (ret != 0) {
671 printk(KERN_ERR "Failed to register TLV320AIC23 I2C driver: %d\n",
672 ret);
673 }
674#endif
675 return ret;
676}
677module_init(tlv320aic23_modinit);
678
679static void __exit tlv320aic23_exit(void)
680{
681#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
682 i2c_del_driver(&tlv320aic23_i2c_driver);
683#endif
684}
685module_exit(tlv320aic23_exit);
686 670
687MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver"); 671MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver");
688MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>"); 672MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index 7b8f3d965f43..94a658fa6d97 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -29,6 +29,7 @@ MODULE_LICENSE("GPL");
29/* AIC26 driver private data */ 29/* AIC26 driver private data */
30struct aic26 { 30struct aic26 {
31 struct spi_device *spi; 31 struct spi_device *spi;
32 struct regmap *regmap;
32 struct snd_soc_codec *codec; 33 struct snd_soc_codec *codec;
33 int master; 34 int master;
34 int datfm; 35 int datfm;
@@ -40,85 +41,6 @@ struct aic26 {
40 int keyclick_len; 41 int keyclick_len;
41}; 42};
42 43
43/* ---------------------------------------------------------------------
44 * Register access routines
45 */
46static unsigned int aic26_reg_read(struct snd_soc_codec *codec,
47 unsigned int reg)
48{
49 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
50 u16 *cache = codec->reg_cache;
51 u16 cmd, value;
52 u8 buffer[2];
53 int rc;
54
55 if (reg >= AIC26_NUM_REGS) {
56 WARN_ON_ONCE(1);
57 return 0;
58 }
59
60 /* Do SPI transfer; first 16bits are command; remaining is
61 * register contents */
62 cmd = AIC26_READ_COMMAND_WORD(reg);
63 buffer[0] = (cmd >> 8) & 0xff;
64 buffer[1] = cmd & 0xff;
65 rc = spi_write_then_read(aic26->spi, buffer, 2, buffer, 2);
66 if (rc) {
67 dev_err(&aic26->spi->dev, "AIC26 reg read error\n");
68 return -EIO;
69 }
70 value = (buffer[0] << 8) | buffer[1];
71
72 /* Update the cache before returning with the value */
73 cache[reg] = value;
74 return value;
75}
76
77static unsigned int aic26_reg_read_cache(struct snd_soc_codec *codec,
78 unsigned int reg)
79{
80 u16 *cache = codec->reg_cache;
81
82 if (reg >= AIC26_NUM_REGS) {
83 WARN_ON_ONCE(1);
84 return 0;
85 }
86
87 return cache[reg];
88}
89
90static int aic26_reg_write(struct snd_soc_codec *codec, unsigned int reg,
91 unsigned int value)
92{
93 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
94 u16 *cache = codec->reg_cache;
95 u16 cmd;
96 u8 buffer[4];
97 int rc;
98
99 if (reg >= AIC26_NUM_REGS) {
100 WARN_ON_ONCE(1);
101 return -EINVAL;
102 }
103
104 /* Do SPI transfer; first 16bits are command; remaining is data
105 * to write into register */
106 cmd = AIC26_WRITE_COMMAND_WORD(reg);
107 buffer[0] = (cmd >> 8) & 0xff;
108 buffer[1] = cmd & 0xff;
109 buffer[2] = value >> 8;
110 buffer[3] = value;
111 rc = spi_write(aic26->spi, buffer, 4);
112 if (rc) {
113 dev_err(&aic26->spi->dev, "AIC26 reg read error\n");
114 return -EIO;
115 }
116
117 /* update cache before returning */
118 cache[reg] = value;
119 return 0;
120}
121
122static const struct snd_soc_dapm_widget tlv320aic26_dapm_widgets[] = { 44static const struct snd_soc_dapm_widget tlv320aic26_dapm_widgets[] = {
123SND_SOC_DAPM_INPUT("MICIN"), 45SND_SOC_DAPM_INPUT("MICIN"),
124SND_SOC_DAPM_INPUT("AUX"), 46SND_SOC_DAPM_INPUT("AUX"),
@@ -195,19 +117,15 @@ static int aic26_hw_params(struct snd_pcm_substream *substream,
195 snd_soc_write(codec, AIC26_REG_PLL_PROG2, reg); 117 snd_soc_write(codec, AIC26_REG_PLL_PROG2, reg);
196 118
197 /* Audio Control 3 (master mode, fsref rate) */ 119 /* Audio Control 3 (master mode, fsref rate) */
198 reg = aic26_reg_read_cache(codec, AIC26_REG_AUDIO_CTRL3);
199 reg &= ~0xf800;
200 if (aic26->master) 120 if (aic26->master)
201 reg |= 0x0800; 121 reg = 0x0800;
202 if (fsref == 48000) 122 if (fsref == 48000)
203 reg |= 0x2000; 123 reg = 0x2000;
204 snd_soc_write(codec, AIC26_REG_AUDIO_CTRL3, reg); 124 snd_soc_update_bits(codec, AIC26_REG_AUDIO_CTRL3, 0xf800, reg);
205 125
206 /* Audio Control 1 (FSref divisor) */ 126 /* Audio Control 1 (FSref divisor) */
207 reg = aic26_reg_read_cache(codec, AIC26_REG_AUDIO_CTRL1); 127 reg = wlen | aic26->datfm | (divisor << 3) | divisor;
208 reg &= ~0x0fff; 128 snd_soc_update_bits(codec, AIC26_REG_AUDIO_CTRL1, 0xfff, reg);
209 reg |= wlen | aic26->datfm | (divisor << 3) | divisor;
210 snd_soc_write(codec, AIC26_REG_AUDIO_CTRL1, reg);
211 129
212 return 0; 130 return 0;
213} 131}
@@ -219,16 +137,16 @@ static int aic26_mute(struct snd_soc_dai *dai, int mute)
219{ 137{
220 struct snd_soc_codec *codec = dai->codec; 138 struct snd_soc_codec *codec = dai->codec;
221 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); 139 struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
222 u16 reg = aic26_reg_read_cache(codec, AIC26_REG_DAC_GAIN); 140 u16 reg;
223 141
224 dev_dbg(&aic26->spi->dev, "aic26_mute(dai=%p, mute=%i)\n", 142 dev_dbg(&aic26->spi->dev, "aic26_mute(dai=%p, mute=%i)\n",
225 dai, mute); 143 dai, mute);
226 144
227 if (mute) 145 if (mute)
228 reg |= 0x8080; 146 reg = 0x8080;
229 else 147 else
230 reg &= ~0x8080; 148 reg = 0;
231 snd_soc_write(codec, AIC26_REG_DAC_GAIN, reg); 149 snd_soc_update_bits(codec, AIC26_REG_DAC_GAIN, 0x8000, reg);
232 150
233 return 0; 151 return 0;
234} 152}
@@ -346,7 +264,7 @@ static ssize_t aic26_keyclick_show(struct device *dev,
346 struct aic26 *aic26 = dev_get_drvdata(dev); 264 struct aic26 *aic26 = dev_get_drvdata(dev);
347 int val, amp, freq, len; 265 int val, amp, freq, len;
348 266
349 val = aic26_reg_read_cache(aic26->codec, AIC26_REG_AUDIO_CTRL2); 267 val = snd_soc_read(aic26->codec, AIC26_REG_AUDIO_CTRL2);
350 amp = (val >> 12) & 0x7; 268 amp = (val >> 12) & 0x7;
351 freq = (125 << ((val >> 8) & 0x7)) >> 1; 269 freq = (125 << ((val >> 8) & 0x7)) >> 1;
352 len = 2 * (1 + ((val >> 4) & 0xf)); 270 len = 2 * (1 + ((val >> 4) & 0xf));
@@ -360,11 +278,9 @@ static ssize_t aic26_keyclick_set(struct device *dev,
360 const char *buf, size_t count) 278 const char *buf, size_t count)
361{ 279{
362 struct aic26 *aic26 = dev_get_drvdata(dev); 280 struct aic26 *aic26 = dev_get_drvdata(dev);
363 int val;
364 281
365 val = aic26_reg_read_cache(aic26->codec, AIC26_REG_AUDIO_CTRL2); 282 snd_soc_update_bits(aic26->codec, AIC26_REG_AUDIO_CTRL2,
366 val |= 0x8000; 283 0x8000, 0x800);
367 snd_soc_write(aic26->codec, AIC26_REG_AUDIO_CTRL2, val);
368 284
369 return count; 285 return count;
370} 286}
@@ -377,7 +293,9 @@ static DEVICE_ATTR(keyclick, 0644, aic26_keyclick_show, aic26_keyclick_set);
377static int aic26_probe(struct snd_soc_codec *codec) 293static int aic26_probe(struct snd_soc_codec *codec)
378{ 294{
379 struct aic26 *aic26 = dev_get_drvdata(codec->dev); 295 struct aic26 *aic26 = dev_get_drvdata(codec->dev);
380 int ret, err, i, reg; 296 int ret, reg;
297
298 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
381 299
382 aic26->codec = codec; 300 aic26->codec = codec;
383 301
@@ -393,37 +311,30 @@ static int aic26_probe(struct snd_soc_codec *codec)
393 reg |= 0x0800; /* set master mode */ 311 reg |= 0x0800; /* set master mode */
394 snd_soc_write(codec, AIC26_REG_AUDIO_CTRL3, reg); 312 snd_soc_write(codec, AIC26_REG_AUDIO_CTRL3, reg);
395 313
396 /* Fill register cache */
397 for (i = 0; i < codec->driver->reg_cache_size; i++)
398 snd_soc_read(codec, i);
399
400 /* Register the sysfs files for debugging */ 314 /* Register the sysfs files for debugging */
401 /* Create SysFS files */ 315 /* Create SysFS files */
402 ret = device_create_file(codec->dev, &dev_attr_keyclick); 316 ret = device_create_file(codec->dev, &dev_attr_keyclick);
403 if (ret) 317 if (ret)
404 dev_info(codec->dev, "error creating sysfs files\n"); 318 dev_info(codec->dev, "error creating sysfs files\n");
405 319
406 /* register controls */
407 dev_dbg(codec->dev, "Registering controls\n");
408 err = snd_soc_add_codec_controls(codec, aic26_snd_controls,
409 ARRAY_SIZE(aic26_snd_controls));
410 WARN_ON(err < 0);
411
412 return 0; 320 return 0;
413} 321}
414 322
415static struct snd_soc_codec_driver aic26_soc_codec_dev = { 323static struct snd_soc_codec_driver aic26_soc_codec_dev = {
416 .probe = aic26_probe, 324 .probe = aic26_probe,
417 .read = aic26_reg_read, 325 .controls = aic26_snd_controls,
418 .write = aic26_reg_write, 326 .num_controls = ARRAY_SIZE(aic26_snd_controls),
419 .reg_cache_size = AIC26_NUM_REGS,
420 .reg_word_size = sizeof(u16),
421 .dapm_widgets = tlv320aic26_dapm_widgets, 327 .dapm_widgets = tlv320aic26_dapm_widgets,
422 .num_dapm_widgets = ARRAY_SIZE(tlv320aic26_dapm_widgets), 328 .num_dapm_widgets = ARRAY_SIZE(tlv320aic26_dapm_widgets),
423 .dapm_routes = tlv320aic26_dapm_routes, 329 .dapm_routes = tlv320aic26_dapm_routes,
424 .num_dapm_routes = ARRAY_SIZE(tlv320aic26_dapm_routes), 330 .num_dapm_routes = ARRAY_SIZE(tlv320aic26_dapm_routes),
425}; 331};
426 332
333static const struct regmap_config aic26_regmap = {
334 .reg_bits = 16,
335 .val_bits = 16,
336};
337
427/* --------------------------------------------------------------------- 338/* ---------------------------------------------------------------------
428 * SPI device portion of driver: probe and release routines and SPI 339 * SPI device portion of driver: probe and release routines and SPI
429 * driver registration. 340 * driver registration.
@@ -440,6 +351,10 @@ static int aic26_spi_probe(struct spi_device *spi)
440 if (!aic26) 351 if (!aic26)
441 return -ENOMEM; 352 return -ENOMEM;
442 353
354 aic26->regmap = devm_regmap_init_spi(spi, &aic26_regmap);
355 if (IS_ERR(aic26->regmap))
356 return PTR_ERR(aic26->regmap);
357
443 /* Initialize the driver data */ 358 /* Initialize the driver data */
444 aic26->spi = spi; 359 aic26->spi = spi;
445 dev_set_drvdata(&spi->dev, aic26); 360 dev_set_drvdata(&spi->dev, aic26);
diff --git a/sound/soc/codecs/tlv320aic26.h b/sound/soc/codecs/tlv320aic26.h
index 67f19c3bebe6..629b85e75409 100644
--- a/sound/soc/codecs/tlv320aic26.h
+++ b/sound/soc/codecs/tlv320aic26.h
@@ -9,10 +9,7 @@
9#define _TLV320AIC16_H_ 9#define _TLV320AIC16_H_
10 10
11/* AIC26 Registers */ 11/* AIC26 Registers */
12#define AIC26_READ_COMMAND_WORD(addr) ((1 << 15) | (addr << 5)) 12#define AIC26_PAGE_ADDR(page, offset) ((page << 11) | offset << 5)
13#define AIC26_WRITE_COMMAND_WORD(addr) ((0 << 15) | (addr << 5))
14#define AIC26_PAGE_ADDR(page, offset) ((page << 6) | offset)
15#define AIC26_NUM_REGS AIC26_PAGE_ADDR(3, 0)
16 13
17/* Page 0: Auxiliary data registers */ 14/* Page 0: Auxiliary data registers */
18#define AIC26_REG_BAT1 AIC26_PAGE_ADDR(0, 0x05) 15#define AIC26_REG_BAT1 AIC26_PAGE_ADDR(0, 0x05)
diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c
index 2ed57d4aa445..18cdcca9014c 100644
--- a/sound/soc/codecs/tlv320aic32x4.c
+++ b/sound/soc/codecs/tlv320aic32x4.c
@@ -60,9 +60,8 @@ struct aic32x4_rate_divs {
60}; 60};
61 61
62struct aic32x4_priv { 62struct aic32x4_priv {
63 struct regmap *regmap;
63 u32 sysclk; 64 u32 sysclk;
64 u8 page_no;
65 void *control_data;
66 u32 power_cfg; 65 u32 power_cfg;
67 u32 micpga_routing; 66 u32 micpga_routing;
68 bool swapdacs; 67 bool swapdacs;
@@ -262,67 +261,25 @@ static const struct snd_soc_dapm_route aic32x4_dapm_routes[] = {
262 {"Right ADC", NULL, "Right Input Mixer"}, 261 {"Right ADC", NULL, "Right Input Mixer"},
263}; 262};
264 263
265static inline int aic32x4_change_page(struct snd_soc_codec *codec, 264static const struct regmap_range_cfg aic32x4_regmap_pages[] = {
266 unsigned int new_page) 265 {
267{ 266 .selector_reg = 0,
268 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); 267 .selector_mask = 0xff,
269 u8 data[2]; 268 .window_start = 0,
270 int ret; 269 .window_len = 128,
271 270 .range_min = AIC32X4_PAGE1,
272 data[0] = 0x00; 271 .range_max = AIC32X4_PAGE1 + 127,
273 data[1] = new_page & 0xff; 272 },
274 273};
275 ret = codec->hw_write(codec->control_data, data, 2);
276 if (ret == 2) {
277 aic32x4->page_no = new_page;
278 return 0;
279 } else {
280 return ret;
281 }
282}
283
284static int aic32x4_write(struct snd_soc_codec *codec, unsigned int reg,
285 unsigned int val)
286{
287 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
288 unsigned int page = reg / 128;
289 unsigned int fixed_reg = reg % 128;
290 u8 data[2];
291 int ret;
292
293 /* A write to AIC32X4_PSEL is really a non-explicit page change */
294 if (reg == AIC32X4_PSEL)
295 return aic32x4_change_page(codec, val);
296
297 if (aic32x4->page_no != page) {
298 ret = aic32x4_change_page(codec, page);
299 if (ret != 0)
300 return ret;
301 }
302
303 data[0] = fixed_reg & 0xff;
304 data[1] = val & 0xff;
305
306 if (codec->hw_write(codec->control_data, data, 2) == 2)
307 return 0;
308 else
309 return -EIO;
310}
311 274
312static unsigned int aic32x4_read(struct snd_soc_codec *codec, unsigned int reg) 275static const struct regmap_config aic32x4_regmap = {
313{ 276 .reg_bits = 8,
314 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); 277 .val_bits = 8,
315 unsigned int page = reg / 128;
316 unsigned int fixed_reg = reg % 128;
317 int ret;
318 278
319 if (aic32x4->page_no != page) { 279 .max_register = AIC32X4_RMICPGAVOL,
320 ret = aic32x4_change_page(codec, page); 280 .ranges = aic32x4_regmap_pages,
321 if (ret != 0) 281 .num_ranges = ARRAY_SIZE(aic32x4_regmap_pages),
322 return ret; 282};
323 }
324 return i2c_smbus_read_byte_data(codec->control_data, fixed_reg & 0xff);
325}
326 283
327static inline int aic32x4_get_divs(int mclk, int rate) 284static inline int aic32x4_get_divs(int mclk, int rate)
328{ 285{
@@ -617,16 +574,10 @@ static int aic32x4_probe(struct snd_soc_codec *codec)
617{ 574{
618 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); 575 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
619 u32 tmp_reg; 576 u32 tmp_reg;
620 int ret;
621 577
622 codec->hw_write = (hw_write_t) i2c_master_send; 578 snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
623 codec->control_data = aic32x4->control_data;
624 579
625 if (aic32x4->rstn_gpio >= 0) { 580 if (aic32x4->rstn_gpio >= 0) {
626 ret = devm_gpio_request_one(codec->dev, aic32x4->rstn_gpio,
627 GPIOF_OUT_INIT_LOW, "tlv320aic32x4 rstn");
628 if (ret != 0)
629 return ret;
630 ndelay(10); 581 ndelay(10);
631 gpio_set_value(aic32x4->rstn_gpio, 1); 582 gpio_set_value(aic32x4->rstn_gpio, 1);
632 } 583 }
@@ -692,8 +643,6 @@ static int aic32x4_remove(struct snd_soc_codec *codec)
692} 643}
693 644
694static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = { 645static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = {
695 .read = aic32x4_read,
696 .write = aic32x4_write,
697 .probe = aic32x4_probe, 646 .probe = aic32x4_probe,
698 .remove = aic32x4_remove, 647 .remove = aic32x4_remove,
699 .suspend = aic32x4_suspend, 648 .suspend = aic32x4_suspend,
@@ -720,7 +669,10 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c,
720 if (aic32x4 == NULL) 669 if (aic32x4 == NULL)
721 return -ENOMEM; 670 return -ENOMEM;
722 671
723 aic32x4->control_data = i2c; 672 aic32x4->regmap = devm_regmap_init_i2c(i2c, &aic32x4_regmap);
673 if (IS_ERR(aic32x4->regmap))
674 return PTR_ERR(aic32x4->regmap);
675
724 i2c_set_clientdata(i2c, aic32x4); 676 i2c_set_clientdata(i2c, aic32x4);
725 677
726 if (pdata) { 678 if (pdata) {
@@ -735,6 +687,13 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c,
735 aic32x4->rstn_gpio = -1; 687 aic32x4->rstn_gpio = -1;
736 } 688 }
737 689
690 if (aic32x4->rstn_gpio >= 0) {
691 ret = devm_gpio_request_one(&i2c->dev, aic32x4->rstn_gpio,
692 GPIOF_OUT_INIT_LOW, "tlv320aic32x4 rstn");
693 if (ret != 0)
694 return ret;
695 }
696
738 ret = snd_soc_register_codec(&i2c->dev, 697 ret = snd_soc_register_codec(&i2c->dev,
739 &soc_codec_dev_aic32x4, &aic32x4_dai, 1); 698 &soc_codec_dev_aic32x4, &aic32x4_dai, 1);
740 return ret; 699 return ret;
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 6e3f269243e0..546d16b7d38f 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -40,6 +40,7 @@
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41#include <linux/gpio.h> 41#include <linux/gpio.h>
42#include <linux/regulator/consumer.h> 42#include <linux/regulator/consumer.h>
43#include <linux/of.h>
43#include <linux/of_gpio.h> 44#include <linux/of_gpio.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
45#include <sound/core.h> 46#include <sound/core.h>
@@ -72,9 +73,9 @@ struct aic3x_disable_nb {
72/* codec private data */ 73/* codec private data */
73struct aic3x_priv { 74struct aic3x_priv {
74 struct snd_soc_codec *codec; 75 struct snd_soc_codec *codec;
76 struct regmap *regmap;
75 struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES]; 77 struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES];
76 struct aic3x_disable_nb disable_nb[AIC3X_NUM_SUPPLIES]; 78 struct aic3x_disable_nb disable_nb[AIC3X_NUM_SUPPLIES];
77 enum snd_soc_control_type control_type;
78 struct aic3x_setup_data *setup; 79 struct aic3x_setup_data *setup;
79 unsigned int sysclk; 80 unsigned int sysclk;
80 struct list_head list; 81 struct list_head list;
@@ -90,41 +91,45 @@ struct aic3x_priv {
90 enum aic3x_micbias_voltage micbias_vg; 91 enum aic3x_micbias_voltage micbias_vg;
91}; 92};
92 93
93/* 94static const struct reg_default aic3x_reg[] = {
94 * AIC3X register cache 95 { 0, 0x00 }, { 1, 0x00 }, { 2, 0x00 }, { 3, 0x10 },
95 * We can't read the AIC3X register space when we are 96 { 4, 0x04 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
96 * using 2 wire for device control, so we cache them instead. 97 { 8, 0x00 }, { 9, 0x00 }, { 10, 0x00 }, { 11, 0x01 },
97 * There is no point in caching the reset register 98 { 12, 0x00 }, { 13, 0x00 }, { 14, 0x00 }, { 15, 0x80 },
98 */ 99 { 16, 0x80 }, { 17, 0xff }, { 18, 0xff }, { 19, 0x78 },
99static const u8 aic3x_reg[AIC3X_CACHEREGNUM] = { 100 { 20, 0x78 }, { 21, 0x78 }, { 22, 0x78 }, { 23, 0x78 },
100 0x00, 0x00, 0x00, 0x10, /* 0 */ 101 { 24, 0x78 }, { 25, 0x00 }, { 26, 0x00 }, { 27, 0xfe },
101 0x04, 0x00, 0x00, 0x00, /* 4 */ 102 { 28, 0x00 }, { 29, 0x00 }, { 30, 0xfe }, { 31, 0x00 },
102 0x00, 0x00, 0x00, 0x01, /* 8 */ 103 { 32, 0x18 }, { 33, 0x18 }, { 34, 0x00 }, { 35, 0x00 },
103 0x00, 0x00, 0x00, 0x80, /* 12 */ 104 { 36, 0x00 }, { 37, 0x00 }, { 38, 0x00 }, { 39, 0x00 },
104 0x80, 0xff, 0xff, 0x78, /* 16 */ 105 { 40, 0x00 }, { 41, 0x00 }, { 42, 0x00 }, { 43, 0x80 },
105 0x78, 0x78, 0x78, 0x78, /* 20 */ 106 { 44, 0x80 }, { 45, 0x00 }, { 46, 0x00 }, { 47, 0x00 },
106 0x78, 0x00, 0x00, 0xfe, /* 24 */ 107 { 48, 0x00 }, { 49, 0x00 }, { 50, 0x00 }, { 51, 0x04 },
107 0x00, 0x00, 0xfe, 0x00, /* 28 */ 108 { 52, 0x00 }, { 53, 0x00 }, { 54, 0x00 }, { 55, 0x00 },
108 0x18, 0x18, 0x00, 0x00, /* 32 */ 109 { 56, 0x00 }, { 57, 0x00 }, { 58, 0x04 }, { 59, 0x00 },
109 0x00, 0x00, 0x00, 0x00, /* 36 */ 110 { 60, 0x00 }, { 61, 0x00 }, { 62, 0x00 }, { 63, 0x00 },
110 0x00, 0x00, 0x00, 0x80, /* 40 */ 111 { 64, 0x00 }, { 65, 0x04 }, { 66, 0x00 }, { 67, 0x00 },
111 0x80, 0x00, 0x00, 0x00, /* 44 */ 112 { 68, 0x00 }, { 69, 0x00 }, { 70, 0x00 }, { 71, 0x00 },
112 0x00, 0x00, 0x00, 0x04, /* 48 */ 113 { 72, 0x04 }, { 73, 0x00 }, { 74, 0x00 }, { 75, 0x00 },
113 0x00, 0x00, 0x00, 0x00, /* 52 */ 114 { 76, 0x00 }, { 77, 0x00 }, { 78, 0x00 }, { 79, 0x00 },
114 0x00, 0x00, 0x04, 0x00, /* 56 */ 115 { 80, 0x00 }, { 81, 0x00 }, { 82, 0x00 }, { 83, 0x00 },
115 0x00, 0x00, 0x00, 0x00, /* 60 */ 116 { 84, 0x00 }, { 85, 0x00 }, { 86, 0x00 }, { 87, 0x00 },
116 0x00, 0x04, 0x00, 0x00, /* 64 */ 117 { 88, 0x00 }, { 89, 0x00 }, { 90, 0x00 }, { 91, 0x00 },
117 0x00, 0x00, 0x00, 0x00, /* 68 */ 118 { 92, 0x00 }, { 93, 0x00 }, { 94, 0x00 }, { 95, 0x00 },
118 0x04, 0x00, 0x00, 0x00, /* 72 */ 119 { 96, 0x00 }, { 97, 0x00 }, { 98, 0x00 }, { 99, 0x00 },
119 0x00, 0x00, 0x00, 0x00, /* 76 */ 120 { 100, 0x00 }, { 101, 0x00 }, { 102, 0x02 }, { 103, 0x00 },
120 0x00, 0x00, 0x00, 0x00, /* 80 */ 121 { 104, 0x00 }, { 105, 0x00 }, { 106, 0x00 }, { 107, 0x00 },
121 0x00, 0x00, 0x00, 0x00, /* 84 */ 122 { 108, 0x00 }, { 109, 0x00 },
122 0x00, 0x00, 0x00, 0x00, /* 88 */ 123};
123 0x00, 0x00, 0x00, 0x00, /* 92 */ 124
124 0x00, 0x00, 0x00, 0x00, /* 96 */ 125static const struct regmap_config aic3x_regmap = {
125 0x00, 0x00, 0x02, 0x00, /* 100 */ 126 .reg_bits = 8,
126 0x00, 0x00, 0x00, 0x00, /* 104 */ 127 .val_bits = 8,
127 0x00, 0x00, /* 108 */ 128
129 .max_register = DAC_ICC_ADJ,
130 .reg_defaults = aic3x_reg,
131 .num_reg_defaults = ARRAY_SIZE(aic3x_reg),
132 .cache_type = REGCACHE_RBTREE,
128}; 133};
129 134
130#define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \ 135#define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \
@@ -674,6 +679,8 @@ static const struct snd_soc_dapm_route intercon[] = {
674 /* Left Input */ 679 /* Left Input */
675 {"Left Line1L Mux", "single-ended", "LINE1L"}, 680 {"Left Line1L Mux", "single-ended", "LINE1L"},
676 {"Left Line1L Mux", "differential", "LINE1L"}, 681 {"Left Line1L Mux", "differential", "LINE1L"},
682 {"Left Line1R Mux", "single-ended", "LINE1R"},
683 {"Left Line1R Mux", "differential", "LINE1R"},
677 684
678 {"Left Line2L Mux", "single-ended", "LINE2L"}, 685 {"Left Line2L Mux", "single-ended", "LINE2L"},
679 {"Left Line2L Mux", "differential", "LINE2L"}, 686 {"Left Line2L Mux", "differential", "LINE2L"},
@@ -690,6 +697,8 @@ static const struct snd_soc_dapm_route intercon[] = {
690 /* Right Input */ 697 /* Right Input */
691 {"Right Line1R Mux", "single-ended", "LINE1R"}, 698 {"Right Line1R Mux", "single-ended", "LINE1R"},
692 {"Right Line1R Mux", "differential", "LINE1R"}, 699 {"Right Line1R Mux", "differential", "LINE1R"},
700 {"Right Line1L Mux", "single-ended", "LINE1L"},
701 {"Right Line1L Mux", "differential", "LINE1L"},
693 702
694 {"Right Line2R Mux", "single-ended", "LINE2R"}, 703 {"Right Line2R Mux", "single-ended", "LINE2R"},
695 {"Right Line2R Mux", "differential", "LINE2R"}, 704 {"Right Line2R Mux", "differential", "LINE2R"},
@@ -824,12 +833,6 @@ static int aic3x_add_widgets(struct snd_soc_codec *codec)
824 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 833 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
825 struct snd_soc_dapm_context *dapm = &codec->dapm; 834 struct snd_soc_dapm_context *dapm = &codec->dapm;
826 835
827 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
828 ARRAY_SIZE(aic3x_dapm_widgets));
829
830 /* set up audio path interconnects */
831 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
832
833 if (aic3x->model == AIC3X_MODEL_3007) { 836 if (aic3x->model == AIC3X_MODEL_3007) {
834 snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets, 837 snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets,
835 ARRAY_SIZE(aic3007_dapm_widgets)); 838 ARRAY_SIZE(aic3007_dapm_widgets));
@@ -1078,29 +1081,6 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
1078 return 0; 1081 return 0;
1079} 1082}
1080 1083
1081static int aic3x_init_3007(struct snd_soc_codec *codec)
1082{
1083 u8 tmp1, tmp2, *cache = codec->reg_cache;
1084
1085 /*
1086 * There is no need to cache writes to undocumented page 0xD but
1087 * respective page 0 register cache entries must be preserved
1088 */
1089 tmp1 = cache[0xD];
1090 tmp2 = cache[0x8];
1091 /* Class-D speaker driver init; datasheet p. 46 */
1092 snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x0D);
1093 snd_soc_write(codec, 0xD, 0x0D);
1094 snd_soc_write(codec, 0x8, 0x5C);
1095 snd_soc_write(codec, 0x8, 0x5D);
1096 snd_soc_write(codec, 0x8, 0x5C);
1097 snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x00);
1098 cache[0xD] = tmp1;
1099 cache[0x8] = tmp2;
1100
1101 return 0;
1102}
1103
1104static int aic3x_regulator_event(struct notifier_block *nb, 1084static int aic3x_regulator_event(struct notifier_block *nb,
1105 unsigned long event, void *data) 1085 unsigned long event, void *data)
1106{ 1086{
@@ -1115,7 +1095,7 @@ static int aic3x_regulator_event(struct notifier_block *nb,
1115 */ 1095 */
1116 if (gpio_is_valid(aic3x->gpio_reset)) 1096 if (gpio_is_valid(aic3x->gpio_reset))
1117 gpio_set_value(aic3x->gpio_reset, 0); 1097 gpio_set_value(aic3x->gpio_reset, 0);
1118 aic3x->codec->cache_sync = 1; 1098 regcache_mark_dirty(aic3x->regmap);
1119 } 1099 }
1120 1100
1121 return 0; 1101 return 0;
@@ -1124,8 +1104,7 @@ static int aic3x_regulator_event(struct notifier_block *nb,
1124static int aic3x_set_power(struct snd_soc_codec *codec, int power) 1104static int aic3x_set_power(struct snd_soc_codec *codec, int power)
1125{ 1105{
1126 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 1106 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
1127 int i, ret; 1107 int ret;
1128 u8 *cache = codec->reg_cache;
1129 1108
1130 if (power) { 1109 if (power) {
1131 ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies), 1110 ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
@@ -1133,12 +1112,6 @@ static int aic3x_set_power(struct snd_soc_codec *codec, int power)
1133 if (ret) 1112 if (ret)
1134 goto out; 1113 goto out;
1135 aic3x->power = 1; 1114 aic3x->power = 1;
1136 /*
1137 * Reset release and cache sync is necessary only if some
1138 * supply was off or if there were cached writes
1139 */
1140 if (!codec->cache_sync)
1141 goto out;
1142 1115
1143 if (gpio_is_valid(aic3x->gpio_reset)) { 1116 if (gpio_is_valid(aic3x->gpio_reset)) {
1144 udelay(1); 1117 udelay(1);
@@ -1146,12 +1119,8 @@ static int aic3x_set_power(struct snd_soc_codec *codec, int power)
1146 } 1119 }
1147 1120
1148 /* Sync reg_cache with the hardware */ 1121 /* Sync reg_cache with the hardware */
1149 codec->cache_only = 0; 1122 regcache_cache_only(aic3x->regmap, false);
1150 for (i = AIC3X_SAMPLE_RATE_SEL_REG; i < ARRAY_SIZE(aic3x_reg); i++) 1123 regcache_sync(aic3x->regmap);
1151 snd_soc_write(codec, i, cache[i]);
1152 if (aic3x->model == AIC3X_MODEL_3007)
1153 aic3x_init_3007(codec);
1154 codec->cache_sync = 0;
1155 } else { 1124 } else {
1156 /* 1125 /*
1157 * Do soft reset to this codec instance in order to clear 1126 * Do soft reset to this codec instance in order to clear
@@ -1159,10 +1128,10 @@ static int aic3x_set_power(struct snd_soc_codec *codec, int power)
1159 * remain on 1128 * remain on
1160 */ 1129 */
1161 snd_soc_write(codec, AIC3X_RESET, SOFT_RESET); 1130 snd_soc_write(codec, AIC3X_RESET, SOFT_RESET);
1162 codec->cache_sync = 1; 1131 regcache_mark_dirty(aic3x->regmap);
1163 aic3x->power = 0; 1132 aic3x->power = 0;
1164 /* HW writes are needless when bias is off */ 1133 /* HW writes are needless when bias is off */
1165 codec->cache_only = 1; 1134 regcache_cache_only(aic3x->regmap, true);
1166 ret = regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), 1135 ret = regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies),
1167 aic3x->supplies); 1136 aic3x->supplies);
1168 } 1137 }
@@ -1317,7 +1286,6 @@ static int aic3x_init(struct snd_soc_codec *codec)
1317 snd_soc_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL); 1286 snd_soc_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
1318 1287
1319 if (aic3x->model == AIC3X_MODEL_3007) { 1288 if (aic3x->model == AIC3X_MODEL_3007) {
1320 aic3x_init_3007(codec);
1321 snd_soc_write(codec, CLASSD_CTRL, 0); 1289 snd_soc_write(codec, CLASSD_CTRL, 0);
1322 } 1290 }
1323 1291
@@ -1345,29 +1313,12 @@ static int aic3x_probe(struct snd_soc_codec *codec)
1345 INIT_LIST_HEAD(&aic3x->list); 1313 INIT_LIST_HEAD(&aic3x->list);
1346 aic3x->codec = codec; 1314 aic3x->codec = codec;
1347 1315
1348 ret = snd_soc_codec_set_cache_io(codec, 8, 8, aic3x->control_type); 1316 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1349 if (ret != 0) { 1317 if (ret != 0) {
1350 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 1318 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1351 return ret; 1319 return ret;
1352 } 1320 }
1353 1321
1354 if (gpio_is_valid(aic3x->gpio_reset) &&
1355 !aic3x_is_shared_reset(aic3x)) {
1356 ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset");
1357 if (ret != 0)
1358 goto err_gpio;
1359 gpio_direction_output(aic3x->gpio_reset, 0);
1360 }
1361
1362 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
1363 aic3x->supplies[i].supply = aic3x_supply_names[i];
1364
1365 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(aic3x->supplies),
1366 aic3x->supplies);
1367 if (ret != 0) {
1368 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
1369 goto err_get;
1370 }
1371 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) { 1322 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) {
1372 aic3x->disable_nb[i].nb.notifier_call = aic3x_regulator_event; 1323 aic3x->disable_nb[i].nb.notifier_call = aic3x_regulator_event;
1373 aic3x->disable_nb[i].aic3x = aic3x; 1324 aic3x->disable_nb[i].aic3x = aic3x;
@@ -1381,7 +1332,7 @@ static int aic3x_probe(struct snd_soc_codec *codec)
1381 } 1332 }
1382 } 1333 }
1383 1334
1384 codec->cache_only = 1; 1335 regcache_mark_dirty(aic3x->regmap);
1385 aic3x_init(codec); 1336 aic3x_init(codec);
1386 1337
1387 if (aic3x->setup) { 1338 if (aic3x->setup) {
@@ -1392,8 +1343,6 @@ static int aic3x_probe(struct snd_soc_codec *codec)
1392 (aic3x->setup->gpio_func[1] & 0xf) << 4); 1343 (aic3x->setup->gpio_func[1] & 0xf) << 4);
1393 } 1344 }
1394 1345
1395 snd_soc_add_codec_controls(codec, aic3x_snd_controls,
1396 ARRAY_SIZE(aic3x_snd_controls));
1397 if (aic3x->model == AIC3X_MODEL_3007) 1346 if (aic3x->model == AIC3X_MODEL_3007)
1398 snd_soc_add_codec_controls(codec, &aic3x_classd_amp_gain_ctrl, 1); 1347 snd_soc_add_codec_controls(codec, &aic3x_classd_amp_gain_ctrl, 1);
1399 1348
@@ -1424,12 +1373,6 @@ err_notif:
1424 while (i--) 1373 while (i--)
1425 regulator_unregister_notifier(aic3x->supplies[i].consumer, 1374 regulator_unregister_notifier(aic3x->supplies[i].consumer,
1426 &aic3x->disable_nb[i].nb); 1375 &aic3x->disable_nb[i].nb);
1427 regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1428err_get:
1429 if (gpio_is_valid(aic3x->gpio_reset) &&
1430 !aic3x_is_shared_reset(aic3x))
1431 gpio_free(aic3x->gpio_reset);
1432err_gpio:
1433 return ret; 1376 return ret;
1434} 1377}
1435 1378
@@ -1440,15 +1383,9 @@ static int aic3x_remove(struct snd_soc_codec *codec)
1440 1383
1441 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF); 1384 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
1442 list_del(&aic3x->list); 1385 list_del(&aic3x->list);
1443 if (gpio_is_valid(aic3x->gpio_reset) &&
1444 !aic3x_is_shared_reset(aic3x)) {
1445 gpio_set_value(aic3x->gpio_reset, 0);
1446 gpio_free(aic3x->gpio_reset);
1447 }
1448 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) 1386 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
1449 regulator_unregister_notifier(aic3x->supplies[i].consumer, 1387 regulator_unregister_notifier(aic3x->supplies[i].consumer,
1450 &aic3x->disable_nb[i].nb); 1388 &aic3x->disable_nb[i].nb);
1451 regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1452 1389
1453 return 0; 1390 return 0;
1454} 1391}
@@ -1456,13 +1393,16 @@ static int aic3x_remove(struct snd_soc_codec *codec)
1456static struct snd_soc_codec_driver soc_codec_dev_aic3x = { 1393static struct snd_soc_codec_driver soc_codec_dev_aic3x = {
1457 .set_bias_level = aic3x_set_bias_level, 1394 .set_bias_level = aic3x_set_bias_level,
1458 .idle_bias_off = true, 1395 .idle_bias_off = true,
1459 .reg_cache_size = ARRAY_SIZE(aic3x_reg),
1460 .reg_word_size = sizeof(u8),
1461 .reg_cache_default = aic3x_reg,
1462 .probe = aic3x_probe, 1396 .probe = aic3x_probe,
1463 .remove = aic3x_remove, 1397 .remove = aic3x_remove,
1464 .suspend = aic3x_suspend, 1398 .suspend = aic3x_suspend,
1465 .resume = aic3x_resume, 1399 .resume = aic3x_resume,
1400 .controls = aic3x_snd_controls,
1401 .num_controls = ARRAY_SIZE(aic3x_snd_controls),
1402 .dapm_widgets = aic3x_dapm_widgets,
1403 .num_dapm_widgets = ARRAY_SIZE(aic3x_dapm_widgets),
1404 .dapm_routes = intercon,
1405 .num_dapm_routes = ARRAY_SIZE(intercon),
1466}; 1406};
1467 1407
1468/* 1408/*
@@ -1479,6 +1419,16 @@ static const struct i2c_device_id aic3x_i2c_id[] = {
1479}; 1419};
1480MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id); 1420MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
1481 1421
1422static const struct reg_default aic3007_class_d[] = {
1423 /* Class-D speaker driver init; datasheet p. 46 */
1424 { AIC3X_PAGE_SELECT, 0x0D },
1425 { 0xD, 0x0D },
1426 { 0x8, 0x5C },
1427 { 0x8, 0x5D },
1428 { 0x8, 0x5C },
1429 { AIC3X_PAGE_SELECT, 0x00 },
1430};
1431
1482/* 1432/*
1483 * If the i2c layer weren't so broken, we could pass this kind of data 1433 * If the i2c layer weren't so broken, we could pass this kind of data
1484 * around 1434 * around
@@ -1490,7 +1440,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
1490 struct aic3x_priv *aic3x; 1440 struct aic3x_priv *aic3x;
1491 struct aic3x_setup_data *ai3x_setup; 1441 struct aic3x_setup_data *ai3x_setup;
1492 struct device_node *np = i2c->dev.of_node; 1442 struct device_node *np = i2c->dev.of_node;
1493 int ret; 1443 int ret, i;
1494 u32 value; 1444 u32 value;
1495 1445
1496 aic3x = devm_kzalloc(&i2c->dev, sizeof(struct aic3x_priv), GFP_KERNEL); 1446 aic3x = devm_kzalloc(&i2c->dev, sizeof(struct aic3x_priv), GFP_KERNEL);
@@ -1499,7 +1449,13 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
1499 return -ENOMEM; 1449 return -ENOMEM;
1500 } 1450 }
1501 1451
1502 aic3x->control_type = SND_SOC_I2C; 1452 aic3x->regmap = devm_regmap_init_i2c(i2c, &aic3x_regmap);
1453 if (IS_ERR(aic3x->regmap)) {
1454 ret = PTR_ERR(aic3x->regmap);
1455 return ret;
1456 }
1457
1458 regcache_cache_only(aic3x->regmap, true);
1503 1459
1504 i2c_set_clientdata(i2c, aic3x); 1460 i2c_set_clientdata(i2c, aic3x);
1505 if (pdata) { 1461 if (pdata) {
@@ -1551,14 +1507,54 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
1551 1507
1552 aic3x->model = id->driver_data; 1508 aic3x->model = id->driver_data;
1553 1509
1510 if (gpio_is_valid(aic3x->gpio_reset) &&
1511 !aic3x_is_shared_reset(aic3x)) {
1512 ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset");
1513 if (ret != 0)
1514 goto err;
1515 gpio_direction_output(aic3x->gpio_reset, 0);
1516 }
1517
1518 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
1519 aic3x->supplies[i].supply = aic3x_supply_names[i];
1520
1521 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(aic3x->supplies),
1522 aic3x->supplies);
1523 if (ret != 0) {
1524 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
1525 goto err_gpio;
1526 }
1527
1528 if (aic3x->model == AIC3X_MODEL_3007) {
1529 ret = regmap_register_patch(aic3x->regmap, aic3007_class_d,
1530 ARRAY_SIZE(aic3007_class_d));
1531 if (ret != 0)
1532 dev_err(&i2c->dev, "Failed to init class D: %d\n",
1533 ret);
1534 }
1535
1554 ret = snd_soc_register_codec(&i2c->dev, 1536 ret = snd_soc_register_codec(&i2c->dev,
1555 &soc_codec_dev_aic3x, &aic3x_dai, 1); 1537 &soc_codec_dev_aic3x, &aic3x_dai, 1);
1556 return ret; 1538 return ret;
1539
1540err_gpio:
1541 if (gpio_is_valid(aic3x->gpio_reset) &&
1542 !aic3x_is_shared_reset(aic3x))
1543 gpio_free(aic3x->gpio_reset);
1544err:
1545 return ret;
1557} 1546}
1558 1547
1559static int aic3x_i2c_remove(struct i2c_client *client) 1548static int aic3x_i2c_remove(struct i2c_client *client)
1560{ 1549{
1550 struct aic3x_priv *aic3x = i2c_get_clientdata(client);
1551
1561 snd_soc_unregister_codec(&client->dev); 1552 snd_soc_unregister_codec(&client->dev);
1553 if (gpio_is_valid(aic3x->gpio_reset) &&
1554 !aic3x_is_shared_reset(aic3x)) {
1555 gpio_set_value(aic3x->gpio_reset, 0);
1556 gpio_free(aic3x->gpio_reset);
1557 }
1562 return 0; 1558 return 0;
1563} 1559}
1564 1560
diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index c58bee8346ce..b27c396037d4 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -30,6 +30,7 @@
30#include <sound/tpa6130a2-plat.h> 30#include <sound/tpa6130a2-plat.h>
31#include <sound/soc.h> 31#include <sound/soc.h>
32#include <sound/tlv.h> 32#include <sound/tlv.h>
33#include <linux/of_gpio.h>
33 34
34#include "tpa6130a2.h" 35#include "tpa6130a2.h"
35 36
@@ -55,7 +56,8 @@ static int tpa6130a2_i2c_read(int reg)
55 struct tpa6130a2_data *data; 56 struct tpa6130a2_data *data;
56 int val; 57 int val;
57 58
58 BUG_ON(tpa6130a2_client == NULL); 59 if (WARN_ON(!tpa6130a2_client))
60 return -EINVAL;
59 data = i2c_get_clientdata(tpa6130a2_client); 61 data = i2c_get_clientdata(tpa6130a2_client);
60 62
61 /* If powered off, return the cached value */ 63 /* If powered off, return the cached value */
@@ -77,7 +79,8 @@ static int tpa6130a2_i2c_write(int reg, u8 value)
77 struct tpa6130a2_data *data; 79 struct tpa6130a2_data *data;
78 int val = 0; 80 int val = 0;
79 81
80 BUG_ON(tpa6130a2_client == NULL); 82 if (WARN_ON(!tpa6130a2_client))
83 return -EINVAL;
81 data = i2c_get_clientdata(tpa6130a2_client); 84 data = i2c_get_clientdata(tpa6130a2_client);
82 85
83 if (data->power_state) { 86 if (data->power_state) {
@@ -98,7 +101,8 @@ static u8 tpa6130a2_read(int reg)
98{ 101{
99 struct tpa6130a2_data *data; 102 struct tpa6130a2_data *data;
100 103
101 BUG_ON(tpa6130a2_client == NULL); 104 if (WARN_ON(!tpa6130a2_client))
105 return 0;
102 data = i2c_get_clientdata(tpa6130a2_client); 106 data = i2c_get_clientdata(tpa6130a2_client);
103 107
104 return data->regs[reg]; 108 return data->regs[reg];
@@ -109,7 +113,8 @@ static int tpa6130a2_initialize(void)
109 struct tpa6130a2_data *data; 113 struct tpa6130a2_data *data;
110 int i, ret = 0; 114 int i, ret = 0;
111 115
112 BUG_ON(tpa6130a2_client == NULL); 116 if (WARN_ON(!tpa6130a2_client))
117 return -EINVAL;
113 data = i2c_get_clientdata(tpa6130a2_client); 118 data = i2c_get_clientdata(tpa6130a2_client);
114 119
115 for (i = 1; i < TPA6130A2_REG_VERSION; i++) { 120 for (i = 1; i < TPA6130A2_REG_VERSION; i++) {
@@ -127,7 +132,8 @@ static int tpa6130a2_power(u8 power)
127 u8 val; 132 u8 val;
128 int ret = 0; 133 int ret = 0;
129 134
130 BUG_ON(tpa6130a2_client == NULL); 135 if (WARN_ON(!tpa6130a2_client))
136 return -EINVAL;
131 data = i2c_get_clientdata(tpa6130a2_client); 137 data = i2c_get_clientdata(tpa6130a2_client);
132 138
133 mutex_lock(&data->mutex); 139 mutex_lock(&data->mutex);
@@ -193,7 +199,8 @@ static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
193 unsigned int mask = (1 << fls(max)) - 1; 199 unsigned int mask = (1 << fls(max)) - 1;
194 unsigned int invert = mc->invert; 200 unsigned int invert = mc->invert;
195 201
196 BUG_ON(tpa6130a2_client == NULL); 202 if (WARN_ON(!tpa6130a2_client))
203 return -EINVAL;
197 data = i2c_get_clientdata(tpa6130a2_client); 204 data = i2c_get_clientdata(tpa6130a2_client);
198 205
199 mutex_lock(&data->mutex); 206 mutex_lock(&data->mutex);
@@ -223,7 +230,8 @@ static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol,
223 unsigned int val = (ucontrol->value.integer.value[0] & mask); 230 unsigned int val = (ucontrol->value.integer.value[0] & mask);
224 unsigned int val_reg; 231 unsigned int val_reg;
225 232
226 BUG_ON(tpa6130a2_client == NULL); 233 if (WARN_ON(!tpa6130a2_client))
234 return -EINVAL;
227 data = i2c_get_clientdata(tpa6130a2_client); 235 data = i2c_get_clientdata(tpa6130a2_client);
228 236
229 if (invert) 237 if (invert)
@@ -364,30 +372,33 @@ static int tpa6130a2_probe(struct i2c_client *client,
364{ 372{
365 struct device *dev; 373 struct device *dev;
366 struct tpa6130a2_data *data; 374 struct tpa6130a2_data *data;
367 struct tpa6130a2_platform_data *pdata; 375 struct tpa6130a2_platform_data *pdata = client->dev.platform_data;
376 struct device_node *np = client->dev.of_node;
368 const char *regulator; 377 const char *regulator;
369 int ret; 378 int ret;
370 379
371 dev = &client->dev; 380 dev = &client->dev;
372 381
373 if (client->dev.platform_data == NULL) {
374 dev_err(dev, "Platform data not set\n");
375 dump_stack();
376 return -ENODEV;
377 }
378
379 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); 382 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
380 if (data == NULL) { 383 if (data == NULL) {
381 dev_err(dev, "Can not allocate memory\n"); 384 dev_err(dev, "Can not allocate memory\n");
382 return -ENOMEM; 385 return -ENOMEM;
383 } 386 }
384 387
388 if (pdata) {
389 data->power_gpio = pdata->power_gpio;
390 } else if (np) {
391 data->power_gpio = of_get_named_gpio(np, "power-gpio", 0);
392 } else {
393 dev_err(dev, "Platform data not set\n");
394 dump_stack();
395 return -ENODEV;
396 }
397
385 tpa6130a2_client = client; 398 tpa6130a2_client = client;
386 399
387 i2c_set_clientdata(tpa6130a2_client, data); 400 i2c_set_clientdata(tpa6130a2_client, data);
388 401
389 pdata = client->dev.platform_data;
390 data->power_gpio = pdata->power_gpio;
391 data->id = id->driver_data; 402 data->id = id->driver_data;
392 403
393 mutex_init(&data->mutex); 404 mutex_init(&data->mutex);
@@ -466,10 +477,20 @@ static const struct i2c_device_id tpa6130a2_id[] = {
466}; 477};
467MODULE_DEVICE_TABLE(i2c, tpa6130a2_id); 478MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
468 479
480#if IS_ENABLED(CONFIG_OF)
481static const struct of_device_id tpa6130a2_of_match[] = {
482 { .compatible = "ti,tpa6130a2", },
483 { .compatible = "ti,tpa6140a2" },
484 {},
485};
486MODULE_DEVICE_TABLE(of, tpa6130a2_of_match);
487#endif
488
469static struct i2c_driver tpa6130a2_i2c_driver = { 489static struct i2c_driver tpa6130a2_i2c_driver = {
470 .driver = { 490 .driver = {
471 .name = "tpa6130a2", 491 .name = "tpa6130a2",
472 .owner = THIS_MODULE, 492 .owner = THIS_MODULE,
493 .of_match_table = of_match_ptr(tpa6130a2_of_match),
473 }, 494 },
474 .probe = tpa6130a2_probe, 495 .probe = tpa6130a2_probe,
475 .remove = tpa6130a2_remove, 496 .remove = tpa6130a2_remove,
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 1e3884d6b3fb..dfc51bb425da 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -46,13 +46,7 @@
46/* TWL4030 PMBR1 Register GPIO6 mux bits */ 46/* TWL4030 PMBR1 Register GPIO6 mux bits */
47#define TWL4030_GPIO6_PWM0_MUTE(value) ((value & 0x03) << 2) 47#define TWL4030_GPIO6_PWM0_MUTE(value) ((value & 0x03) << 2)
48 48
49/* Shadow register used by the audio driver */ 49#define TWL4030_CACHEREGNUM (TWL4030_REG_MISC_SET_2 + 1)
50#define TWL4030_REG_SW_SHADOW 0x4A
51#define TWL4030_CACHEREGNUM (TWL4030_REG_SW_SHADOW + 1)
52
53/* TWL4030_REG_SW_SHADOW (0x4A) Fields */
54#define TWL4030_HFL_EN 0x01
55#define TWL4030_HFR_EN 0x02
56 50
57/* 51/*
58 * twl4030 register cache & default register settings 52 * twl4030 register cache & default register settings
@@ -132,7 +126,6 @@ static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = {
132 0x00, /* REG_VIBRA_PWM_SET (0x47) */ 126 0x00, /* REG_VIBRA_PWM_SET (0x47) */
133 0x00, /* REG_ANAMIC_GAIN (0x48) */ 127 0x00, /* REG_ANAMIC_GAIN (0x48) */
134 0x00, /* REG_MISC_SET_2 (0x49) */ 128 0x00, /* REG_MISC_SET_2 (0x49) */
135 0x00, /* REG_SW_SHADOW (0x4A) - Shadow, non HW register */
136}; 129};
137 130
138/* codec private data */ 131/* codec private data */
@@ -198,42 +191,41 @@ static int twl4030_write(struct snd_soc_codec *codec,
198 int write_to_reg = 0; 191 int write_to_reg = 0;
199 192
200 twl4030_write_reg_cache(codec, reg, value); 193 twl4030_write_reg_cache(codec, reg, value);
201 if (likely(reg < TWL4030_REG_SW_SHADOW)) { 194 /* Decide if the given register can be written */
202 /* Decide if the given register can be written */ 195 switch (reg) {
203 switch (reg) { 196 case TWL4030_REG_EAR_CTL:
204 case TWL4030_REG_EAR_CTL: 197 if (twl4030->earpiece_enabled)
205 if (twl4030->earpiece_enabled)
206 write_to_reg = 1;
207 break;
208 case TWL4030_REG_PREDL_CTL:
209 if (twl4030->predrivel_enabled)
210 write_to_reg = 1;
211 break;
212 case TWL4030_REG_PREDR_CTL:
213 if (twl4030->predriver_enabled)
214 write_to_reg = 1;
215 break;
216 case TWL4030_REG_PRECKL_CTL:
217 if (twl4030->carkitl_enabled)
218 write_to_reg = 1;
219 break;
220 case TWL4030_REG_PRECKR_CTL:
221 if (twl4030->carkitr_enabled)
222 write_to_reg = 1;
223 break;
224 case TWL4030_REG_HS_GAIN_SET:
225 if (twl4030->hsl_enabled || twl4030->hsr_enabled)
226 write_to_reg = 1;
227 break;
228 default:
229 /* All other register can be written */
230 write_to_reg = 1; 198 write_to_reg = 1;
231 break; 199 break;
232 } 200 case TWL4030_REG_PREDL_CTL:
233 if (write_to_reg) 201 if (twl4030->predrivel_enabled)
234 return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, 202 write_to_reg = 1;
235 value, reg); 203 break;
204 case TWL4030_REG_PREDR_CTL:
205 if (twl4030->predriver_enabled)
206 write_to_reg = 1;
207 break;
208 case TWL4030_REG_PRECKL_CTL:
209 if (twl4030->carkitl_enabled)
210 write_to_reg = 1;
211 break;
212 case TWL4030_REG_PRECKR_CTL:
213 if (twl4030->carkitr_enabled)
214 write_to_reg = 1;
215 break;
216 case TWL4030_REG_HS_GAIN_SET:
217 if (twl4030->hsl_enabled || twl4030->hsr_enabled)
218 write_to_reg = 1;
219 break;
220 default:
221 /* All other register can be written */
222 write_to_reg = 1;
223 break;
236 } 224 }
225 if (write_to_reg)
226 return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
227 value, reg);
228
237 return 0; 229 return 0;
238} 230}
239 231
@@ -532,7 +524,7 @@ SOC_DAPM_ENUM("Route", twl4030_handsfreel_enum);
532 524
533/* Handsfree Left virtual mute */ 525/* Handsfree Left virtual mute */
534static const struct snd_kcontrol_new twl4030_dapm_handsfreelmute_control = 526static const struct snd_kcontrol_new twl4030_dapm_handsfreelmute_control =
535 SOC_DAPM_SINGLE("Switch", TWL4030_REG_SW_SHADOW, 0, 1, 0); 527 SOC_DAPM_SINGLE_VIRT("Switch", 1);
536 528
537/* Handsfree Right */ 529/* Handsfree Right */
538static const char *twl4030_handsfreer_texts[] = 530static const char *twl4030_handsfreer_texts[] =
@@ -548,7 +540,7 @@ SOC_DAPM_ENUM("Route", twl4030_handsfreer_enum);
548 540
549/* Handsfree Right virtual mute */ 541/* Handsfree Right virtual mute */
550static const struct snd_kcontrol_new twl4030_dapm_handsfreermute_control = 542static const struct snd_kcontrol_new twl4030_dapm_handsfreermute_control =
551 SOC_DAPM_SINGLE("Switch", TWL4030_REG_SW_SHADOW, 1, 1, 0); 543 SOC_DAPM_SINGLE_VIRT("Switch", 1);
552 544
553/* Vibra */ 545/* Vibra */
554/* Vibra audio path selection */ 546/* Vibra audio path selection */
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index 3c79dbb6c323..f2f4bcb2ff71 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -54,12 +54,7 @@ enum twl6040_dai_id {
54#define TWL6040_OUTHF_0dB 0x03 54#define TWL6040_OUTHF_0dB 0x03
55#define TWL6040_OUTHF_M52dB 0x1D 55#define TWL6040_OUTHF_M52dB 0x1D
56 56
57/* Shadow register used by the driver */ 57#define TWL6040_CACHEREGNUM (TWL6040_REG_STATUS + 1)
58#define TWL6040_REG_SW_SHADOW 0x2F
59#define TWL6040_CACHEREGNUM (TWL6040_REG_SW_SHADOW + 1)
60
61/* TWL6040_REG_SW_SHADOW (0x2F) fields */
62#define TWL6040_EAR_PATH_ENABLE 0x01
63 58
64struct twl6040_jack_data { 59struct twl6040_jack_data {
65 struct snd_soc_jack *jack; 60 struct snd_soc_jack *jack;
@@ -135,8 +130,6 @@ static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = {
135 0x00, /* REG_HFOTRIM 0x2C */ 130 0x00, /* REG_HFOTRIM 0x2C */
136 0x09, /* REG_ACCCTL 0x2D */ 131 0x09, /* REG_ACCCTL 0x2D */
137 0x00, /* REG_STATUS 0x2E (ro) */ 132 0x00, /* REG_STATUS 0x2E (ro) */
138
139 0x00, /* REG_SW_SHADOW 0x2F - Shadow, non HW register */
140}; 133};
141 134
142/* List of registers to be restored after power up */ 135/* List of registers to be restored after power up */
@@ -220,12 +213,8 @@ static int twl6040_read_reg_volatile(struct snd_soc_codec *codec,
220 if (reg >= TWL6040_CACHEREGNUM) 213 if (reg >= TWL6040_CACHEREGNUM)
221 return -EIO; 214 return -EIO;
222 215
223 if (likely(reg < TWL6040_REG_SW_SHADOW)) { 216 value = twl6040_reg_read(twl6040, reg);
224 value = twl6040_reg_read(twl6040, reg); 217 twl6040_write_reg_cache(codec, reg, value);
225 twl6040_write_reg_cache(codec, reg, value);
226 } else {
227 value = twl6040_read_reg_cache(codec, reg);
228 }
229 218
230 return value; 219 return value;
231} 220}
@@ -246,7 +235,7 @@ static bool twl6040_is_path_unmuted(struct snd_soc_codec *codec,
246 return priv->dl2_unmuted; 235 return priv->dl2_unmuted;
247 default: 236 default:
248 return 1; 237 return 1;
249 }; 238 }
250} 239}
251 240
252/* 241/*
@@ -261,8 +250,7 @@ static int twl6040_write(struct snd_soc_codec *codec,
261 return -EIO; 250 return -EIO;
262 251
263 twl6040_write_reg_cache(codec, reg, value); 252 twl6040_write_reg_cache(codec, reg, value);
264 if (likely(reg < TWL6040_REG_SW_SHADOW) && 253 if (twl6040_is_path_unmuted(codec, reg))
265 twl6040_is_path_unmuted(codec, reg))
266 return twl6040_reg_write(twl6040, reg, value); 254 return twl6040_reg_write(twl6040, reg, value);
267 else 255 else
268 return 0; 256 return 0;
@@ -555,7 +543,7 @@ static const struct snd_kcontrol_new hfr_mux_controls =
555 SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]); 543 SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]);
556 544
557static const struct snd_kcontrol_new ep_path_enable_control = 545static const struct snd_kcontrol_new ep_path_enable_control =
558 SOC_DAPM_SINGLE("Switch", TWL6040_REG_SW_SHADOW, 0, 1, 0); 546 SOC_DAPM_SINGLE_VIRT("Switch", 1);
559 547
560static const struct snd_kcontrol_new auxl_switch_control = 548static const struct snd_kcontrol_new auxl_switch_control =
561 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0); 549 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0);
@@ -1100,7 +1088,7 @@ static void twl6040_mute_path(struct snd_soc_codec *codec, enum twl6040_dai_id i
1100 break; 1088 break;
1101 default: 1089 default:
1102 break; 1090 break;
1103 }; 1091 }
1104} 1092}
1105 1093
1106static int twl6040_digital_mute(struct snd_soc_dai *dai, int mute) 1094static int twl6040_digital_mute(struct snd_soc_dai *dai, int mute)
diff --git a/sound/soc/codecs/wm0010.c b/sound/soc/codecs/wm0010.c
index d5ebcb00019b..71ce3159a62e 100644
--- a/sound/soc/codecs/wm0010.c
+++ b/sound/soc/codecs/wm0010.c
@@ -372,7 +372,8 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_codec *codec)
372 offset = 0; 372 offset = 0;
373 dsp = inforec->dsp_target; 373 dsp = inforec->dsp_target;
374 wm0010->boot_failed = false; 374 wm0010->boot_failed = false;
375 BUG_ON(!list_empty(&xfer_list)); 375 if (WARN_ON(!list_empty(&xfer_list)))
376 return -EINVAL;
376 init_completion(&done); 377 init_completion(&done);
377 378
378 /* First record should be INFO */ 379 /* First record should be INFO */
@@ -793,11 +794,11 @@ static int wm0010_set_sysclk(struct snd_soc_codec *codec, int source,
793 wm0010->max_spi_freq = 0; 794 wm0010->max_spi_freq = 0;
794 } else { 795 } else {
795 for (i = 0; i < ARRAY_SIZE(pll_clock_map); i++) 796 for (i = 0; i < ARRAY_SIZE(pll_clock_map); i++)
796 if (freq >= pll_clock_map[i].max_sysclk) 797 if (freq >= pll_clock_map[i].max_sysclk) {
798 wm0010->max_spi_freq = pll_clock_map[i].max_pll_spi_speed;
799 wm0010->pll_clkctrl1 = pll_clock_map[i].pll_clkctrl1;
797 break; 800 break;
798 801 }
799 wm0010->max_spi_freq = pll_clock_map[i].max_pll_spi_speed;
800 wm0010->pll_clkctrl1 = pll_clock_map[i].pll_clkctrl1;
801 } 802 }
802 803
803 return 0; 804 return 0;
diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index 7fefd766b582..8ae50274ea8f 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -137,7 +137,8 @@ static int wm2000_power_up(struct i2c_client *i2c, int analogue)
137 unsigned long rate; 137 unsigned long rate;
138 int ret; 138 int ret;
139 139
140 BUG_ON(wm2000->anc_mode != ANC_OFF); 140 if (WARN_ON(wm2000->anc_mode != ANC_OFF))
141 return -EINVAL;
141 142
142 dev_dbg(&i2c->dev, "Beginning power up\n"); 143 dev_dbg(&i2c->dev, "Beginning power up\n");
143 144
@@ -277,7 +278,8 @@ static int wm2000_enter_bypass(struct i2c_client *i2c, int analogue)
277{ 278{
278 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev); 279 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
279 280
280 BUG_ON(wm2000->anc_mode != ANC_ACTIVE); 281 if (WARN_ON(wm2000->anc_mode != ANC_ACTIVE))
282 return -EINVAL;
281 283
282 if (analogue) { 284 if (analogue) {
283 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL, 285 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
@@ -315,7 +317,8 @@ static int wm2000_exit_bypass(struct i2c_client *i2c, int analogue)
315{ 317{
316 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev); 318 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
317 319
318 BUG_ON(wm2000->anc_mode != ANC_BYPASS); 320 if (WARN_ON(wm2000->anc_mode != ANC_BYPASS))
321 return -EINVAL;
319 322
320 wm2000_write(i2c, WM2000_REG_SYS_CTL1, 0); 323 wm2000_write(i2c, WM2000_REG_SYS_CTL1, 0);
321 324
@@ -349,7 +352,8 @@ static int wm2000_enter_standby(struct i2c_client *i2c, int analogue)
349{ 352{
350 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev); 353 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
351 354
352 BUG_ON(wm2000->anc_mode != ANC_ACTIVE); 355 if (WARN_ON(wm2000->anc_mode != ANC_ACTIVE))
356 return -EINVAL;
353 357
354 if (analogue) { 358 if (analogue) {
355 wm2000_write(i2c, WM2000_REG_ANA_VMID_PD_TIME, 248 / 4); 359 wm2000_write(i2c, WM2000_REG_ANA_VMID_PD_TIME, 248 / 4);
@@ -392,7 +396,8 @@ static int wm2000_exit_standby(struct i2c_client *i2c, int analogue)
392{ 396{
393 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev); 397 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
394 398
395 BUG_ON(wm2000->anc_mode != ANC_STANDBY); 399 if (WARN_ON(wm2000->anc_mode != ANC_STANDBY))
400 return -EINVAL;
396 401
397 wm2000_write(i2c, WM2000_REG_SYS_CTL1, 0); 402 wm2000_write(i2c, WM2000_REG_SYS_CTL1, 0);
398 403
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c
index ac1745d030d6..4cf91deabc02 100644
--- a/sound/soc/codecs/wm5100.c
+++ b/sound/soc/codecs/wm5100.c
@@ -1972,7 +1972,8 @@ static void wm5100_set_detect_mode(struct wm5100_priv *wm5100, int the_mode)
1972{ 1972{
1973 struct wm5100_jack_mode *mode = &wm5100->pdata.jack_modes[the_mode]; 1973 struct wm5100_jack_mode *mode = &wm5100->pdata.jack_modes[the_mode];
1974 1974
1975 BUG_ON(the_mode >= ARRAY_SIZE(wm5100->pdata.jack_modes)); 1975 if (WARN_ON(the_mode >= ARRAY_SIZE(wm5100->pdata.jack_modes)))
1976 return;
1976 1977
1977 gpio_set_value_cansleep(wm5100->pdata.hp_pol, mode->hp_pol); 1978 gpio_set_value_cansleep(wm5100->pdata.hp_pol, mode->hp_pol);
1978 regmap_update_bits(wm5100->regmap, WM5100_ACCESSORY_DETECT_MODE_1, 1979 regmap_update_bits(wm5100->regmap, WM5100_ACCESSORY_DETECT_MODE_1,
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index 8bbddc151aa8..a08e8bf6d07c 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -685,13 +685,13 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
685ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 685ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
686ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 686ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
687 687
688SND_SOC_BYTES_MASK("EQ1 Coefficeints", ARIZONA_EQ1_1, 21, 688SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21,
689 ARIZONA_EQ1_ENA_MASK), 689 ARIZONA_EQ1_ENA_MASK),
690SND_SOC_BYTES_MASK("EQ2 Coefficeints", ARIZONA_EQ2_1, 21, 690SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
691 ARIZONA_EQ2_ENA_MASK), 691 ARIZONA_EQ2_ENA_MASK),
692SND_SOC_BYTES_MASK("EQ3 Coefficeints", ARIZONA_EQ3_1, 21, 692SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
693 ARIZONA_EQ3_ENA_MASK), 693 ARIZONA_EQ3_ENA_MASK),
694SND_SOC_BYTES_MASK("EQ4 Coefficeints", ARIZONA_EQ4_1, 21, 694SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
695 ARIZONA_EQ4_ENA_MASK), 695 ARIZONA_EQ4_ENA_MASK),
696 696
697SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 697SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index bbd64384ca1c..f2d1094424b9 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -101,13 +101,13 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
101ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 101ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
102ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 102ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
103 103
104SND_SOC_BYTES_MASK("EQ1 Coefficeints", ARIZONA_EQ1_1, 21, 104SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21,
105 ARIZONA_EQ1_ENA_MASK), 105 ARIZONA_EQ1_ENA_MASK),
106SND_SOC_BYTES_MASK("EQ2 Coefficeints", ARIZONA_EQ2_1, 21, 106SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
107 ARIZONA_EQ2_ENA_MASK), 107 ARIZONA_EQ2_ENA_MASK),
108SND_SOC_BYTES_MASK("EQ3 Coefficeints", ARIZONA_EQ3_1, 21, 108SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
109 ARIZONA_EQ3_ENA_MASK), 109 ARIZONA_EQ3_ENA_MASK),
110SND_SOC_BYTES_MASK("EQ4 Coefficeints", ARIZONA_EQ4_1, 21, 110SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
111 ARIZONA_EQ4_ENA_MASK), 111 ARIZONA_EQ4_ENA_MASK),
112 112
113SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 113SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
@@ -983,24 +983,36 @@ static const struct snd_soc_dapm_route wm5110_dapm_routes[] = {
983 ARIZONA_MUX_ROUTES("ASRC2L", "ASRC2L"), 983 ARIZONA_MUX_ROUTES("ASRC2L", "ASRC2L"),
984 ARIZONA_MUX_ROUTES("ASRC2R", "ASRC2R"), 984 ARIZONA_MUX_ROUTES("ASRC2R", "ASRC2R"),
985 985
986 { "AEC Loopback", "HPOUT1L", "OUT1L" },
987 { "AEC Loopback", "HPOUT1R", "OUT1R" },
986 { "HPOUT1L", NULL, "OUT1L" }, 988 { "HPOUT1L", NULL, "OUT1L" },
987 { "HPOUT1R", NULL, "OUT1R" }, 989 { "HPOUT1R", NULL, "OUT1R" },
988 990
991 { "AEC Loopback", "HPOUT2L", "OUT2L" },
992 { "AEC Loopback", "HPOUT2R", "OUT2R" },
989 { "HPOUT2L", NULL, "OUT2L" }, 993 { "HPOUT2L", NULL, "OUT2L" },
990 { "HPOUT2R", NULL, "OUT2R" }, 994 { "HPOUT2R", NULL, "OUT2R" },
991 995
996 { "AEC Loopback", "HPOUT3L", "OUT3L" },
997 { "AEC Loopback", "HPOUT3R", "OUT3R" },
992 { "HPOUT3L", NULL, "OUT3L" }, 998 { "HPOUT3L", NULL, "OUT3L" },
993 { "HPOUT3R", NULL, "OUT3L" }, 999 { "HPOUT3R", NULL, "OUT3L" },
994 1000
1001 { "AEC Loopback", "SPKOUTL", "OUT4L" },
995 { "SPKOUTLN", NULL, "OUT4L" }, 1002 { "SPKOUTLN", NULL, "OUT4L" },
996 { "SPKOUTLP", NULL, "OUT4L" }, 1003 { "SPKOUTLP", NULL, "OUT4L" },
997 1004
1005 { "AEC Loopback", "SPKOUTR", "OUT4R" },
998 { "SPKOUTRN", NULL, "OUT4R" }, 1006 { "SPKOUTRN", NULL, "OUT4R" },
999 { "SPKOUTRP", NULL, "OUT4R" }, 1007 { "SPKOUTRP", NULL, "OUT4R" },
1000 1008
1009 { "AEC Loopback", "SPKDAT1L", "OUT5L" },
1010 { "AEC Loopback", "SPKDAT1R", "OUT5R" },
1001 { "SPKDAT1L", NULL, "OUT5L" }, 1011 { "SPKDAT1L", NULL, "OUT5L" },
1002 { "SPKDAT1R", NULL, "OUT5R" }, 1012 { "SPKDAT1R", NULL, "OUT5R" },
1003 1013
1014 { "AEC Loopback", "SPKDAT2L", "OUT6L" },
1015 { "AEC Loopback", "SPKDAT2R", "OUT6R" },
1004 { "SPKDAT2L", NULL, "OUT6L" }, 1016 { "SPKDAT2L", NULL, "OUT6L" },
1005 { "SPKDAT2R", NULL, "OUT6R" }, 1017 { "SPKDAT2R", NULL, "OUT6R" },
1006 1018
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index af1318ddb062..a183dcf3d5c1 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -274,7 +274,7 @@ static int pga_event(struct snd_soc_dapm_widget *w,
274 break; 274 break;
275 275
276 default: 276 default:
277 BUG(); 277 WARN(1, "Invalid shift %d\n", w->shift);
278 return -1; 278 return -1;
279 } 279 }
280 280
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index d2a092850283..48dc7d2fee36 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -32,13 +32,6 @@
32 32
33#include "wm8400.h" 33#include "wm8400.h"
34 34
35/* Fake register for internal state */
36#define WM8400_INTDRIVBITS (WM8400_REGISTER_COUNT + 1)
37#define WM8400_INMIXL_PWR 0
38#define WM8400_AINLMUX_PWR 1
39#define WM8400_INMIXR_PWR 2
40#define WM8400_AINRMUX_PWR 3
41
42static struct regulator_bulk_data power[] = { 35static struct regulator_bulk_data power[] = {
43 { 36 {
44 .supply = "I2S1VDD", 37 .supply = "I2S1VDD",
@@ -74,32 +67,6 @@ struct wm8400_priv {
74 int fll_in, fll_out; 67 int fll_in, fll_out;
75}; 68};
76 69
77static inline unsigned int wm8400_read(struct snd_soc_codec *codec,
78 unsigned int reg)
79{
80 struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
81
82 if (reg == WM8400_INTDRIVBITS)
83 return wm8400->fake_register;
84 else
85 return wm8400_reg_read(wm8400->wm8400, reg);
86}
87
88/*
89 * write to the wm8400 register space
90 */
91static int wm8400_write(struct snd_soc_codec *codec, unsigned int reg,
92 unsigned int value)
93{
94 struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
95
96 if (reg == WM8400_INTDRIVBITS) {
97 wm8400->fake_register = value;
98 return 0;
99 } else
100 return wm8400_set_bits(wm8400->wm8400, reg, 0xffff, value);
101}
102
103static void wm8400_codec_reset(struct snd_soc_codec *codec) 70static void wm8400_codec_reset(struct snd_soc_codec *codec)
104{ 71{
105 struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec); 72 struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
@@ -352,32 +319,6 @@ SOC_SINGLE("RIN34 Mute Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
352 * _DAPM_ Controls 319 * _DAPM_ Controls
353 */ 320 */
354 321
355static int inmixer_event (struct snd_soc_dapm_widget *w,
356 struct snd_kcontrol *kcontrol, int event)
357{
358 u16 reg, fakepower;
359
360 reg = snd_soc_read(w->codec, WM8400_POWER_MANAGEMENT_2);
361 fakepower = snd_soc_read(w->codec, WM8400_INTDRIVBITS);
362
363 if (fakepower & ((1 << WM8400_INMIXL_PWR) |
364 (1 << WM8400_AINLMUX_PWR))) {
365 reg |= WM8400_AINL_ENA;
366 } else {
367 reg &= ~WM8400_AINL_ENA;
368 }
369
370 if (fakepower & ((1 << WM8400_INMIXR_PWR) |
371 (1 << WM8400_AINRMUX_PWR))) {
372 reg |= WM8400_AINR_ENA;
373 } else {
374 reg &= ~WM8400_AINR_ENA;
375 }
376 snd_soc_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg);
377
378 return 0;
379}
380
381static int outmixer_event (struct snd_soc_dapm_widget *w, 322static int outmixer_event (struct snd_soc_dapm_widget *w,
382 struct snd_kcontrol * kcontrol, int event) 323 struct snd_kcontrol * kcontrol, int event)
383{ 324{
@@ -658,27 +599,26 @@ SND_SOC_DAPM_MIXER("RIN34 PGA", WM8400_POWER_MANAGEMENT_2,
658 0, &wm8400_dapm_rin34_pga_controls[0], 599 0, &wm8400_dapm_rin34_pga_controls[0],
659 ARRAY_SIZE(wm8400_dapm_rin34_pga_controls)), 600 ARRAY_SIZE(wm8400_dapm_rin34_pga_controls)),
660 601
602SND_SOC_DAPM_SUPPLY("INL", WM8400_POWER_MANAGEMENT_2, WM8400_AINL_ENA_SHIFT,
603 0, NULL, 0),
604SND_SOC_DAPM_SUPPLY("INR", WM8400_POWER_MANAGEMENT_2, WM8400_AINR_ENA_SHIFT,
605 0, NULL, 0),
606
661/* INMIXL */ 607/* INMIXL */
662SND_SOC_DAPM_MIXER_E("INMIXL", WM8400_INTDRIVBITS, WM8400_INMIXL_PWR, 0, 608SND_SOC_DAPM_MIXER("INMIXL", SND_SOC_NOPM, 0, 0,
663 &wm8400_dapm_inmixl_controls[0], 609 &wm8400_dapm_inmixl_controls[0],
664 ARRAY_SIZE(wm8400_dapm_inmixl_controls), 610 ARRAY_SIZE(wm8400_dapm_inmixl_controls)),
665 inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
666 611
667/* AINLMUX */ 612/* AINLMUX */
668SND_SOC_DAPM_MUX_E("AILNMUX", WM8400_INTDRIVBITS, WM8400_AINLMUX_PWR, 0, 613SND_SOC_DAPM_MUX("AILNMUX", SND_SOC_NOPM, 0, 0, &wm8400_dapm_ainlmux_controls),
669 &wm8400_dapm_ainlmux_controls, inmixer_event,
670 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
671 614
672/* INMIXR */ 615/* INMIXR */
673SND_SOC_DAPM_MIXER_E("INMIXR", WM8400_INTDRIVBITS, WM8400_INMIXR_PWR, 0, 616SND_SOC_DAPM_MIXER("INMIXR", SND_SOC_NOPM, 0, 0,
674 &wm8400_dapm_inmixr_controls[0], 617 &wm8400_dapm_inmixr_controls[0],
675 ARRAY_SIZE(wm8400_dapm_inmixr_controls), 618 ARRAY_SIZE(wm8400_dapm_inmixr_controls)),
676 inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
677 619
678/* AINRMUX */ 620/* AINRMUX */
679SND_SOC_DAPM_MUX_E("AIRNMUX", WM8400_INTDRIVBITS, WM8400_AINRMUX_PWR, 0, 621SND_SOC_DAPM_MUX("AIRNMUX", SND_SOC_NOPM, 0, 0, &wm8400_dapm_ainrmux_controls),
680 &wm8400_dapm_ainrmux_controls, inmixer_event,
681 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
682 622
683/* Output Side */ 623/* Output Side */
684/* DACs */ 624/* DACs */
@@ -789,11 +729,13 @@ static const struct snd_soc_dapm_route wm8400_dapm_routes[] = {
789 {"LIN34 PGA", "LIN3 Switch", "LIN3"}, 729 {"LIN34 PGA", "LIN3 Switch", "LIN3"},
790 {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"}, 730 {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"},
791 /* INMIXL */ 731 /* INMIXL */
732 {"INMIXL", NULL, "INL"},
792 {"INMIXL", "Record Left Volume", "LOMIX"}, 733 {"INMIXL", "Record Left Volume", "LOMIX"},
793 {"INMIXL", "LIN2 Volume", "LIN2"}, 734 {"INMIXL", "LIN2 Volume", "LIN2"},
794 {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"}, 735 {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"},
795 {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"}, 736 {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"},
796 /* AILNMUX */ 737 /* AILNMUX */
738 {"AILNMUX", NULL, "INL"},
797 {"AILNMUX", "INMIXL Mix", "INMIXL"}, 739 {"AILNMUX", "INMIXL Mix", "INMIXL"},
798 {"AILNMUX", "DIFFINL Mix", "LIN12 PGA"}, 740 {"AILNMUX", "DIFFINL Mix", "LIN12 PGA"},
799 {"AILNMUX", "DIFFINL Mix", "LIN34 PGA"}, 741 {"AILNMUX", "DIFFINL Mix", "LIN34 PGA"},
@@ -808,12 +750,14 @@ static const struct snd_soc_dapm_route wm8400_dapm_routes[] = {
808 /* RIN34 PGA */ 750 /* RIN34 PGA */
809 {"RIN34 PGA", "RIN3 Switch", "RIN3"}, 751 {"RIN34 PGA", "RIN3 Switch", "RIN3"},
810 {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"}, 752 {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"},
811 /* INMIXL */ 753 /* INMIXR */
754 {"INMIXR", NULL, "INR"},
812 {"INMIXR", "Record Right Volume", "ROMIX"}, 755 {"INMIXR", "Record Right Volume", "ROMIX"},
813 {"INMIXR", "RIN2 Volume", "RIN2"}, 756 {"INMIXR", "RIN2 Volume", "RIN2"},
814 {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"}, 757 {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"},
815 {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"}, 758 {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"},
816 /* AIRNMUX */ 759 /* AIRNMUX */
760 {"AIRNMUX", NULL, "INR"},
817 {"AIRNMUX", "INMIXR Mix", "INMIXR"}, 761 {"AIRNMUX", "INMIXR Mix", "INMIXR"},
818 {"AIRNMUX", "DIFFINR Mix", "RIN12 PGA"}, 762 {"AIRNMUX", "DIFFINR Mix", "RIN12 PGA"},
819 {"AIRNMUX", "DIFFINR Mix", "RIN34 PGA"}, 763 {"AIRNMUX", "DIFFINR Mix", "RIN34 PGA"},
@@ -1365,9 +1309,12 @@ static int wm8400_codec_probe(struct snd_soc_codec *codec)
1365 return -ENOMEM; 1309 return -ENOMEM;
1366 1310
1367 snd_soc_codec_set_drvdata(codec, priv); 1311 snd_soc_codec_set_drvdata(codec, priv);
1368 codec->control_data = priv->wm8400 = wm8400; 1312 priv->wm8400 = wm8400;
1313 codec->control_data = wm8400->regmap;
1369 priv->codec = codec; 1314 priv->codec = codec;
1370 1315
1316 snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1317
1371 ret = devm_regulator_bulk_get(wm8400->dev, 1318 ret = devm_regulator_bulk_get(wm8400->dev,
1372 ARRAY_SIZE(power), &power[0]); 1319 ARRAY_SIZE(power), &power[0]);
1373 if (ret != 0) { 1320 if (ret != 0) {
@@ -1414,8 +1361,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8400 = {
1414 .remove = wm8400_codec_remove, 1361 .remove = wm8400_codec_remove,
1415 .suspend = wm8400_suspend, 1362 .suspend = wm8400_suspend,
1416 .resume = wm8400_resume, 1363 .resume = wm8400_resume,
1417 .read = snd_soc_read,
1418 .write = wm8400_write,
1419 .set_bias_level = wm8400_set_bias_level, 1364 .set_bias_level = wm8400_set_bias_level,
1420 1365
1421 .controls = wm8400_snd_controls, 1366 .controls = wm8400_snd_controls,
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 5e9c40fa7eb2..08a414b57b1e 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -736,7 +736,7 @@ static int wm8580_set_sysclk(struct snd_soc_dai *dai, int clk_id,
736 break; 736 break;
737 737
738 default: 738 default:
739 BUG_ON("Unknown DAI driver ID\n"); 739 WARN(1, "Unknown DAI driver ID\n");
740 return -EINVAL; 740 return -EINVAL;
741 } 741 }
742 742
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index f31017ed1381..942d58e455f3 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -325,7 +325,8 @@ static int wm8776_set_sysclk(struct snd_soc_dai *dai,
325 struct snd_soc_codec *codec = dai->codec; 325 struct snd_soc_codec *codec = dai->codec;
326 struct wm8776_priv *wm8776 = snd_soc_codec_get_drvdata(codec); 326 struct wm8776_priv *wm8776 = snd_soc_codec_get_drvdata(codec);
327 327
328 BUG_ON(dai->driver->id >= ARRAY_SIZE(wm8776->sysclk)); 328 if (WARN_ON(dai->driver->id >= ARRAY_SIZE(wm8776->sysclk)))
329 return -EINVAL;
329 330
330 wm8776->sysclk[dai->driver->id] = freq; 331 wm8776->sysclk[dai->driver->id] = freq;
331 332
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index 7c8257c5a17b..734209e252c3 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -279,7 +279,8 @@ static int wm8900_hp_event(struct snd_soc_dapm_widget *w,
279 break; 279 break;
280 280
281 default: 281 default:
282 BUG(); 282 WARN(1, "Invalid event %d\n", event);
283 break;
283 } 284 }
284 285
285 return 0; 286 return 0;
@@ -691,7 +692,8 @@ static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
691 unsigned int K, Ndiv, Nmod, target; 692 unsigned int K, Ndiv, Nmod, target;
692 unsigned int div; 693 unsigned int div;
693 694
694 BUG_ON(!Fout); 695 if (WARN_ON(!Fout))
696 return -EINVAL;
695 697
696 /* The FLL must run at 90-100MHz which is then scaled down to 698 /* The FLL must run at 90-100MHz which is then scaled down to
697 * the output value by FLLCLK_DIV. */ 699 * the output value by FLLCLK_DIV. */
@@ -742,8 +744,9 @@ static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
742 /* Move down to proper range now rounding is done */ 744 /* Move down to proper range now rounding is done */
743 fll_div->k = K / 10; 745 fll_div->k = K / 10;
744 746
745 BUG_ON(target != Fout * (fll_div->fllclk_div << 2)); 747 if (WARN_ON(target != Fout * (fll_div->fllclk_div << 2)) ||
746 BUG_ON(!K && target != Fref * fll_div->fll_ratio * fll_div->n); 748 WARN_ON(!K && target != Fref * fll_div->fll_ratio * fll_div->n))
749 return -EINVAL;
747 750
748 return 0; 751 return 0;
749} 752}
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 4dfa8dceeabf..3938fb1c203e 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -658,7 +658,8 @@ SOC_SINGLE_TLV("EQ5 Volume", WM8904_EQ6, 0, 24, 0, eq_tlv),
658static int cp_event(struct snd_soc_dapm_widget *w, 658static int cp_event(struct snd_soc_dapm_widget *w,
659 struct snd_kcontrol *kcontrol, int event) 659 struct snd_kcontrol *kcontrol, int event)
660{ 660{
661 BUG_ON(event != SND_SOC_DAPM_POST_PMU); 661 if (WARN_ON(event != SND_SOC_DAPM_POST_PMU))
662 return -EINVAL;
662 663
663 /* Maximum startup time */ 664 /* Maximum startup time */
664 udelay(500); 665 udelay(500);
@@ -740,7 +741,7 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
740 dcs_r = 3; 741 dcs_r = 3;
741 break; 742 break;
742 default: 743 default:
743 BUG(); 744 WARN(1, "Invalid reg %d\n", reg);
744 return -EINVAL; 745 return -EINVAL;
745 } 746 }
746 747
diff --git a/sound/soc/codecs/wm8958-dsp2.c b/sound/soc/codecs/wm8958-dsp2.c
index b0710d817a65..b7488f190d2b 100644
--- a/sound/soc/codecs/wm8958-dsp2.c
+++ b/sound/soc/codecs/wm8958-dsp2.c
@@ -348,7 +348,7 @@ static void wm8958_dsp_apply(struct snd_soc_codec *codec, int path, int start)
348 aif = 1; 348 aif = 1;
349 break; 349 break;
350 default: 350 default:
351 BUG(); 351 WARN(1, "Invalid path %d\n", path);
352 return; 352 return;
353 } 353 }
354 354
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 11d80f3b6137..543c5c2631b6 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -1758,6 +1758,9 @@ SOC_DOUBLE_R_TLV("EQ4 Volume", WM8962_EQ3, WM8962_EQ23,
1758 WM8962_EQL_B4_GAIN_SHIFT, 31, 0, eq_tlv), 1758 WM8962_EQL_B4_GAIN_SHIFT, 31, 0, eq_tlv),
1759SOC_DOUBLE_R_TLV("EQ5 Volume", WM8962_EQ3, WM8962_EQ23, 1759SOC_DOUBLE_R_TLV("EQ5 Volume", WM8962_EQ3, WM8962_EQ23,
1760 WM8962_EQL_B5_GAIN_SHIFT, 31, 0, eq_tlv), 1760 WM8962_EQL_B5_GAIN_SHIFT, 31, 0, eq_tlv),
1761SND_SOC_BYTES("EQL Coefficients", WM8962_EQ4, 18),
1762SND_SOC_BYTES("EQR Coefficients", WM8962_EQ24, 18),
1763
1761 1764
1762SOC_SINGLE("3D Switch", WM8962_THREED1, 0, 1, 0), 1765SOC_SINGLE("3D Switch", WM8962_THREED1, 0, 1, 0),
1763SND_SOC_BYTES_MASK("3D Coefficients", WM8962_THREED1, 4, WM8962_THREED_ENA), 1766SND_SOC_BYTES_MASK("3D Coefficients", WM8962_THREED1, 4, WM8962_THREED_ENA),
@@ -1775,6 +1778,11 @@ WM8962_DSP2_ENABLE("HPF2 Switch", WM8962_HPF2_ENA_SHIFT),
1775SND_SOC_BYTES("HPF Coefficients", WM8962_LHPF2, 1), 1778SND_SOC_BYTES("HPF Coefficients", WM8962_LHPF2, 1),
1776WM8962_DSP2_ENABLE("HD Bass Switch", WM8962_HDBASS_ENA_SHIFT), 1779WM8962_DSP2_ENABLE("HD Bass Switch", WM8962_HDBASS_ENA_SHIFT),
1777SND_SOC_BYTES("HD Bass Coefficients", WM8962_HDBASS_AI_1, 30), 1780SND_SOC_BYTES("HD Bass Coefficients", WM8962_HDBASS_AI_1, 30),
1781
1782SOC_DOUBLE("ALC Switch", WM8962_ALC1, WM8962_ALCL_ENA_SHIFT,
1783 WM8962_ALCR_ENA_SHIFT, 1, 0),
1784SND_SOC_BYTES_MASK("ALC Coefficients", WM8962_ALC1, 4,
1785 WM8962_ALCL_ENA_MASK | WM8962_ALCR_ENA_MASK),
1778}; 1786};
1779 1787
1780static const struct snd_kcontrol_new wm8962_spk_mono_controls[] = { 1788static const struct snd_kcontrol_new wm8962_spk_mono_controls[] = {
@@ -1845,7 +1853,7 @@ static int cp_event(struct snd_soc_dapm_widget *w,
1845 break; 1853 break;
1846 1854
1847 default: 1855 default:
1848 BUG(); 1856 WARN(1, "Invalid event %d\n", event);
1849 return -EINVAL; 1857 return -EINVAL;
1850 } 1858 }
1851 1859
@@ -1937,7 +1945,7 @@ static int hp_event(struct snd_soc_dapm_widget *w,
1937 break; 1945 break;
1938 1946
1939 default: 1947 default:
1940 BUG(); 1948 WARN(1, "Invalid event %d\n", event);
1941 return -EINVAL; 1949 return -EINVAL;
1942 1950
1943 } 1951 }
@@ -1966,7 +1974,7 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
1966 reg = WM8962_SPKOUTL_VOLUME; 1974 reg = WM8962_SPKOUTL_VOLUME;
1967 break; 1975 break;
1968 default: 1976 default:
1969 BUG(); 1977 WARN(1, "Invalid shift %d\n", w->shift);
1970 return -EINVAL; 1978 return -EINVAL;
1971 } 1979 }
1972 1980
@@ -1974,7 +1982,7 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
1974 case SND_SOC_DAPM_POST_PMU: 1982 case SND_SOC_DAPM_POST_PMU:
1975 return snd_soc_write(codec, reg, snd_soc_read(codec, reg)); 1983 return snd_soc_write(codec, reg, snd_soc_read(codec, reg));
1976 default: 1984 default:
1977 BUG(); 1985 WARN(1, "Invalid event %d\n", event);
1978 return -EINVAL; 1986 return -EINVAL;
1979 } 1987 }
1980} 1988}
@@ -1997,7 +2005,7 @@ static int dsp2_event(struct snd_soc_dapm_widget *w,
1997 break; 2005 break;
1998 2006
1999 default: 2007 default:
2000 BUG(); 2008 WARN(1, "Invalid event %d\n", event);
2001 return -EINVAL; 2009 return -EINVAL;
2002 } 2010 }
2003 2011
@@ -3242,7 +3250,7 @@ static void wm8962_free_beep(struct snd_soc_codec *codec)
3242} 3250}
3243#endif 3251#endif
3244 3252
3245static void wm8962_set_gpio_mode(struct snd_soc_codec *codec, int gpio) 3253static void wm8962_set_gpio_mode(struct wm8962_priv *wm8962, int gpio)
3246{ 3254{
3247 int mask = 0; 3255 int mask = 0;
3248 int val = 0; 3256 int val = 0;
@@ -3263,8 +3271,8 @@ static void wm8962_set_gpio_mode(struct snd_soc_codec *codec, int gpio)
3263 } 3271 }
3264 3272
3265 if (mask) 3273 if (mask)
3266 snd_soc_update_bits(codec, WM8962_ANALOGUE_CLOCKING1, 3274 regmap_update_bits(wm8962->regmap, WM8962_ANALOGUE_CLOCKING1,
3267 mask, val); 3275 mask, val);
3268} 3276}
3269 3277
3270#ifdef CONFIG_GPIOLIB 3278#ifdef CONFIG_GPIOLIB
@@ -3276,7 +3284,6 @@ static inline struct wm8962_priv *gpio_to_wm8962(struct gpio_chip *chip)
3276static int wm8962_gpio_request(struct gpio_chip *chip, unsigned offset) 3284static int wm8962_gpio_request(struct gpio_chip *chip, unsigned offset)
3277{ 3285{
3278 struct wm8962_priv *wm8962 = gpio_to_wm8962(chip); 3286 struct wm8962_priv *wm8962 = gpio_to_wm8962(chip);
3279 struct snd_soc_codec *codec = wm8962->codec;
3280 3287
3281 /* The WM8962 GPIOs aren't linearly numbered. For simplicity 3288 /* The WM8962 GPIOs aren't linearly numbered. For simplicity
3282 * we export linear numbers and error out if the unsupported 3289 * we export linear numbers and error out if the unsupported
@@ -3292,7 +3299,7 @@ static int wm8962_gpio_request(struct gpio_chip *chip, unsigned offset)
3292 return -EINVAL; 3299 return -EINVAL;
3293 } 3300 }
3294 3301
3295 wm8962_set_gpio_mode(codec, offset + 1); 3302 wm8962_set_gpio_mode(wm8962, offset + 1);
3296 3303
3297 return 0; 3304 return 0;
3298} 3305}
@@ -3376,8 +3383,7 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3376{ 3383{
3377 int ret; 3384 int ret;
3378 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3385 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3379 struct wm8962_pdata *pdata = &wm8962->pdata; 3386 int i;
3380 int i, trigger, irq_pol;
3381 bool dmicclk, dmicdat; 3387 bool dmicclk, dmicdat;
3382 3388
3383 wm8962->codec = codec; 3389 wm8962->codec = codec;
@@ -3409,75 +3415,6 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3409 } 3415 }
3410 } 3416 }
3411 3417
3412 /* SYSCLK defaults to on; make sure it is off so we can safely
3413 * write to registers if the device is declocked.
3414 */
3415 snd_soc_update_bits(codec, WM8962_CLOCKING2, WM8962_SYSCLK_ENA, 0);
3416
3417 /* Ensure we have soft control over all registers */
3418 snd_soc_update_bits(codec, WM8962_CLOCKING2,
3419 WM8962_CLKREG_OVD, WM8962_CLKREG_OVD);
3420
3421 /* Ensure that the oscillator and PLLs are disabled */
3422 snd_soc_update_bits(codec, WM8962_PLL2,
3423 WM8962_OSC_ENA | WM8962_PLL2_ENA | WM8962_PLL3_ENA,
3424 0);
3425
3426 /* Apply static configuration for GPIOs */
3427 for (i = 0; i < ARRAY_SIZE(pdata->gpio_init); i++)
3428 if (pdata->gpio_init[i]) {
3429 wm8962_set_gpio_mode(codec, i + 1);
3430 snd_soc_write(codec, 0x200 + i,
3431 pdata->gpio_init[i] & 0xffff);
3432 }
3433
3434
3435 /* Put the speakers into mono mode? */
3436 if (pdata->spk_mono)
3437 snd_soc_update_bits(codec, WM8962_CLASS_D_CONTROL_2,
3438 WM8962_SPK_MONO_MASK, WM8962_SPK_MONO);
3439
3440 /* Micbias setup, detection enable and detection
3441 * threasholds. */
3442 if (pdata->mic_cfg)
3443 snd_soc_update_bits(codec, WM8962_ADDITIONAL_CONTROL_4,
3444 WM8962_MICDET_ENA |
3445 WM8962_MICDET_THR_MASK |
3446 WM8962_MICSHORT_THR_MASK |
3447 WM8962_MICBIAS_LVL,
3448 pdata->mic_cfg);
3449
3450 /* Latch volume update bits */
3451 snd_soc_update_bits(codec, WM8962_LEFT_INPUT_VOLUME,
3452 WM8962_IN_VU, WM8962_IN_VU);
3453 snd_soc_update_bits(codec, WM8962_RIGHT_INPUT_VOLUME,
3454 WM8962_IN_VU, WM8962_IN_VU);
3455 snd_soc_update_bits(codec, WM8962_LEFT_ADC_VOLUME,
3456 WM8962_ADC_VU, WM8962_ADC_VU);
3457 snd_soc_update_bits(codec, WM8962_RIGHT_ADC_VOLUME,
3458 WM8962_ADC_VU, WM8962_ADC_VU);
3459 snd_soc_update_bits(codec, WM8962_LEFT_DAC_VOLUME,
3460 WM8962_DAC_VU, WM8962_DAC_VU);
3461 snd_soc_update_bits(codec, WM8962_RIGHT_DAC_VOLUME,
3462 WM8962_DAC_VU, WM8962_DAC_VU);
3463 snd_soc_update_bits(codec, WM8962_SPKOUTL_VOLUME,
3464 WM8962_SPKOUT_VU, WM8962_SPKOUT_VU);
3465 snd_soc_update_bits(codec, WM8962_SPKOUTR_VOLUME,
3466 WM8962_SPKOUT_VU, WM8962_SPKOUT_VU);
3467 snd_soc_update_bits(codec, WM8962_HPOUTL_VOLUME,
3468 WM8962_HPOUT_VU, WM8962_HPOUT_VU);
3469 snd_soc_update_bits(codec, WM8962_HPOUTR_VOLUME,
3470 WM8962_HPOUT_VU, WM8962_HPOUT_VU);
3471
3472 /* Stereo control for EQ */
3473 snd_soc_update_bits(codec, WM8962_EQ1, WM8962_EQ_SHARED_COEFF, 0);
3474
3475 /* Don't debouce interrupts so we don't need SYSCLK */
3476 snd_soc_update_bits(codec, WM8962_IRQ_DEBOUNCE,
3477 WM8962_FLL_LOCK_DB | WM8962_PLL3_LOCK_DB |
3478 WM8962_PLL2_LOCK_DB | WM8962_TEMP_SHUT_DB,
3479 0);
3480
3481 wm8962_add_widgets(codec); 3418 wm8962_add_widgets(codec);
3482 3419
3483 /* Save boards having to disable DMIC when not in use */ 3420 /* Save boards having to disable DMIC when not in use */
@@ -3506,36 +3443,6 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3506 wm8962_init_beep(codec); 3443 wm8962_init_beep(codec);
3507 wm8962_init_gpio(codec); 3444 wm8962_init_gpio(codec);
3508 3445
3509 if (wm8962->irq) {
3510 if (pdata->irq_active_low) {
3511 trigger = IRQF_TRIGGER_LOW;
3512 irq_pol = WM8962_IRQ_POL;
3513 } else {
3514 trigger = IRQF_TRIGGER_HIGH;
3515 irq_pol = 0;
3516 }
3517
3518 snd_soc_update_bits(codec, WM8962_INTERRUPT_CONTROL,
3519 WM8962_IRQ_POL, irq_pol);
3520
3521 ret = request_threaded_irq(wm8962->irq, NULL, wm8962_irq,
3522 trigger | IRQF_ONESHOT,
3523 "wm8962", codec->dev);
3524 if (ret != 0) {
3525 dev_err(codec->dev, "Failed to request IRQ %d: %d\n",
3526 wm8962->irq, ret);
3527 wm8962->irq = 0;
3528 /* Non-fatal */
3529 } else {
3530 /* Enable some IRQs by default */
3531 snd_soc_update_bits(codec,
3532 WM8962_INTERRUPT_STATUS_2_MASK,
3533 WM8962_FLL_LOCK_EINT |
3534 WM8962_TEMP_SHUT_EINT |
3535 WM8962_FIFOS_ERR_EINT, 0);
3536 }
3537 }
3538
3539 return 0; 3446 return 0;
3540} 3447}
3541 3448
@@ -3544,9 +3451,6 @@ static int wm8962_remove(struct snd_soc_codec *codec)
3544 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3451 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3545 int i; 3452 int i;
3546 3453
3547 if (wm8962->irq)
3548 free_irq(wm8962->irq, codec);
3549
3550 cancel_delayed_work_sync(&wm8962->mic_work); 3454 cancel_delayed_work_sync(&wm8962->mic_work);
3551 3455
3552 wm8962_free_gpio(codec); 3456 wm8962_free_gpio(codec);
@@ -3619,7 +3523,7 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
3619 struct wm8962_pdata *pdata = dev_get_platdata(&i2c->dev); 3523 struct wm8962_pdata *pdata = dev_get_platdata(&i2c->dev);
3620 struct wm8962_priv *wm8962; 3524 struct wm8962_priv *wm8962;
3621 unsigned int reg; 3525 unsigned int reg;
3622 int ret, i; 3526 int ret, i, irq_pol, trigger;
3623 3527
3624 wm8962 = devm_kzalloc(&i2c->dev, sizeof(struct wm8962_priv), 3528 wm8962 = devm_kzalloc(&i2c->dev, sizeof(struct wm8962_priv),
3625 GFP_KERNEL); 3529 GFP_KERNEL);
@@ -3704,6 +3608,77 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
3704 goto err_enable; 3608 goto err_enable;
3705 } 3609 }
3706 3610
3611 /* SYSCLK defaults to on; make sure it is off so we can safely
3612 * write to registers if the device is declocked.
3613 */
3614 regmap_update_bits(wm8962->regmap, WM8962_CLOCKING2,
3615 WM8962_SYSCLK_ENA, 0);
3616
3617 /* Ensure we have soft control over all registers */
3618 regmap_update_bits(wm8962->regmap, WM8962_CLOCKING2,
3619 WM8962_CLKREG_OVD, WM8962_CLKREG_OVD);
3620
3621 /* Ensure that the oscillator and PLLs are disabled */
3622 regmap_update_bits(wm8962->regmap, WM8962_PLL2,
3623 WM8962_OSC_ENA | WM8962_PLL2_ENA | WM8962_PLL3_ENA,
3624 0);
3625
3626 /* Apply static configuration for GPIOs */
3627 for (i = 0; i < ARRAY_SIZE(wm8962->pdata.gpio_init); i++)
3628 if (wm8962->pdata.gpio_init[i]) {
3629 wm8962_set_gpio_mode(wm8962, i + 1);
3630 regmap_write(wm8962->regmap, 0x200 + i,
3631 wm8962->pdata.gpio_init[i] & 0xffff);
3632 }
3633
3634
3635 /* Put the speakers into mono mode? */
3636 if (wm8962->pdata.spk_mono)
3637 regmap_update_bits(wm8962->regmap, WM8962_CLASS_D_CONTROL_2,
3638 WM8962_SPK_MONO_MASK, WM8962_SPK_MONO);
3639
3640 /* Micbias setup, detection enable and detection
3641 * threasholds. */
3642 if (wm8962->pdata.mic_cfg)
3643 regmap_update_bits(wm8962->regmap, WM8962_ADDITIONAL_CONTROL_4,
3644 WM8962_MICDET_ENA |
3645 WM8962_MICDET_THR_MASK |
3646 WM8962_MICSHORT_THR_MASK |
3647 WM8962_MICBIAS_LVL,
3648 wm8962->pdata.mic_cfg);
3649
3650 /* Latch volume update bits */
3651 regmap_update_bits(wm8962->regmap, WM8962_LEFT_INPUT_VOLUME,
3652 WM8962_IN_VU, WM8962_IN_VU);
3653 regmap_update_bits(wm8962->regmap, WM8962_RIGHT_INPUT_VOLUME,
3654 WM8962_IN_VU, WM8962_IN_VU);
3655 regmap_update_bits(wm8962->regmap, WM8962_LEFT_ADC_VOLUME,
3656 WM8962_ADC_VU, WM8962_ADC_VU);
3657 regmap_update_bits(wm8962->regmap, WM8962_RIGHT_ADC_VOLUME,
3658 WM8962_ADC_VU, WM8962_ADC_VU);
3659 regmap_update_bits(wm8962->regmap, WM8962_LEFT_DAC_VOLUME,
3660 WM8962_DAC_VU, WM8962_DAC_VU);
3661 regmap_update_bits(wm8962->regmap, WM8962_RIGHT_DAC_VOLUME,
3662 WM8962_DAC_VU, WM8962_DAC_VU);
3663 regmap_update_bits(wm8962->regmap, WM8962_SPKOUTL_VOLUME,
3664 WM8962_SPKOUT_VU, WM8962_SPKOUT_VU);
3665 regmap_update_bits(wm8962->regmap, WM8962_SPKOUTR_VOLUME,
3666 WM8962_SPKOUT_VU, WM8962_SPKOUT_VU);
3667 regmap_update_bits(wm8962->regmap, WM8962_HPOUTL_VOLUME,
3668 WM8962_HPOUT_VU, WM8962_HPOUT_VU);
3669 regmap_update_bits(wm8962->regmap, WM8962_HPOUTR_VOLUME,
3670 WM8962_HPOUT_VU, WM8962_HPOUT_VU);
3671
3672 /* Stereo control for EQ */
3673 regmap_update_bits(wm8962->regmap, WM8962_EQ1,
3674 WM8962_EQ_SHARED_COEFF, 0);
3675
3676 /* Don't debouce interrupts so we don't need SYSCLK */
3677 regmap_update_bits(wm8962->regmap, WM8962_IRQ_DEBOUNCE,
3678 WM8962_FLL_LOCK_DB | WM8962_PLL3_LOCK_DB |
3679 WM8962_PLL2_LOCK_DB | WM8962_TEMP_SHUT_DB,
3680 0);
3681
3707 if (wm8962->pdata.in4_dc_measure) { 3682 if (wm8962->pdata.in4_dc_measure) {
3708 ret = regmap_register_patch(wm8962->regmap, 3683 ret = regmap_register_patch(wm8962->regmap,
3709 wm8962_dc_measure, 3684 wm8962_dc_measure,
@@ -3714,6 +3689,37 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
3714 ret); 3689 ret);
3715 } 3690 }
3716 3691
3692 if (wm8962->irq) {
3693 if (wm8962->pdata.irq_active_low) {
3694 trigger = IRQF_TRIGGER_LOW;
3695 irq_pol = WM8962_IRQ_POL;
3696 } else {
3697 trigger = IRQF_TRIGGER_HIGH;
3698 irq_pol = 0;
3699 }
3700
3701 regmap_update_bits(wm8962->regmap, WM8962_INTERRUPT_CONTROL,
3702 WM8962_IRQ_POL, irq_pol);
3703
3704 ret = devm_request_threaded_irq(&i2c->dev, wm8962->irq, NULL,
3705 wm8962_irq,
3706 trigger | IRQF_ONESHOT,
3707 "wm8962", &i2c->dev);
3708 if (ret != 0) {
3709 dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n",
3710 wm8962->irq, ret);
3711 wm8962->irq = 0;
3712 /* Non-fatal */
3713 } else {
3714 /* Enable some IRQs by default */
3715 regmap_update_bits(wm8962->regmap,
3716 WM8962_INTERRUPT_STATUS_2_MASK,
3717 WM8962_FLL_LOCK_EINT |
3718 WM8962_TEMP_SHUT_EINT |
3719 WM8962_FIFOS_ERR_EINT, 0);
3720 }
3721 }
3722
3717 pm_runtime_enable(&i2c->dev); 3723 pm_runtime_enable(&i2c->dev);
3718 pm_request_idle(&i2c->dev); 3724 pm_request_idle(&i2c->dev);
3719 3725
@@ -3722,6 +3728,8 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
3722 if (ret < 0) 3728 if (ret < 0)
3723 goto err_enable; 3729 goto err_enable;
3724 3730
3731 regcache_cache_only(wm8962->regmap, true);
3732
3725 /* The drivers should power up as needed */ 3733 /* The drivers should power up as needed */
3726 regulator_bulk_disable(ARRAY_SIZE(wm8962->supplies), wm8962->supplies); 3734 regulator_bulk_disable(ARRAY_SIZE(wm8962->supplies), wm8962->supplies);
3727 3735
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c
index 46fe83d2b224..1a7655b0aa22 100644
--- a/sound/soc/codecs/wm8996.c
+++ b/sound/soc/codecs/wm8996.c
@@ -438,6 +438,8 @@ static int wm8996_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
438 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); 438 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
439 int block = wm8996_get_retune_mobile_block(kcontrol->id.name); 439 int block = wm8996_get_retune_mobile_block(kcontrol->id.name);
440 440
441 if (block < 0)
442 return block;
441 ucontrol->value.enumerated.item[0] = wm8996->retune_mobile_cfg[block]; 443 ucontrol->value.enumerated.item[0] = wm8996->retune_mobile_cfg[block];
442 444
443 return 0; 445 return 0;
@@ -608,7 +610,7 @@ static int bg_event(struct snd_soc_dapm_widget *w,
608 wm8996_bg_disable(codec); 610 wm8996_bg_disable(codec);
609 break; 611 break;
610 default: 612 default:
611 BUG(); 613 WARN(1, "Invalid event %d\n", event);
612 ret = -EINVAL; 614 ret = -EINVAL;
613 } 615 }
614 616
@@ -625,7 +627,7 @@ static int cp_event(struct snd_soc_dapm_widget *w,
625 msleep(5); 627 msleep(5);
626 break; 628 break;
627 default: 629 default:
628 BUG(); 630 WARN(1, "Invalid event %d\n", event);
629 ret = -EINVAL; 631 ret = -EINVAL;
630 } 632 }
631 633
@@ -646,7 +648,7 @@ static int rmv_short_event(struct snd_soc_dapm_widget *w,
646 wm8996->hpout_pending |= w->shift; 648 wm8996->hpout_pending |= w->shift;
647 break; 649 break;
648 default: 650 default:
649 BUG(); 651 WARN(1, "Invalid event %d\n", event);
650 return -EINVAL; 652 return -EINVAL;
651 } 653 }
652 654
@@ -767,7 +769,7 @@ static int dcs_start(struct snd_soc_dapm_widget *w,
767 wm8996->dcs_pending |= 1 << w->shift; 769 wm8996->dcs_pending |= 1 << w->shift;
768 break; 770 break;
769 default: 771 default:
770 BUG(); 772 WARN(1, "Invalid event %d\n", event);
771 return -EINVAL; 773 return -EINVAL;
772 } 774 }
773 775
@@ -1656,7 +1658,7 @@ static int wm8996_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1656 lrclk_rx_reg = WM8996_AIF2_RX_LRCLK_2; 1658 lrclk_rx_reg = WM8996_AIF2_RX_LRCLK_2;
1657 break; 1659 break;
1658 default: 1660 default:
1659 BUG(); 1661 WARN(1, "Invalid dai id %d\n", dai->id);
1660 return -EINVAL; 1662 return -EINVAL;
1661 } 1663 }
1662 1664
@@ -1768,7 +1770,7 @@ static int wm8996_hw_params(struct snd_pcm_substream *substream,
1768 dsp_shift = WM8996_DSP2_DIV_SHIFT; 1770 dsp_shift = WM8996_DSP2_DIV_SHIFT;
1769 break; 1771 break;
1770 default: 1772 default:
1771 BUG(); 1773 WARN(1, "Invalid dai id %d\n", dai->id);
1772 return -EINVAL; 1774 return -EINVAL;
1773 } 1775 }
1774 1776
diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c
index 6ec3de3efa4f..1392bb3c9254 100644
--- a/sound/soc/codecs/wm8997.c
+++ b/sound/soc/codecs/wm8997.c
@@ -170,13 +170,13 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
170ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 170ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
171ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 171ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
172 172
173SND_SOC_BYTES_MASK("EQ1 Coefficeints", ARIZONA_EQ1_1, 21, 173SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21,
174 ARIZONA_EQ1_ENA_MASK), 174 ARIZONA_EQ1_ENA_MASK),
175SND_SOC_BYTES_MASK("EQ2 Coefficeints", ARIZONA_EQ2_1, 21, 175SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
176 ARIZONA_EQ2_ENA_MASK), 176 ARIZONA_EQ2_ENA_MASK),
177SND_SOC_BYTES_MASK("EQ3 Coefficeints", ARIZONA_EQ3_1, 21, 177SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
178 ARIZONA_EQ3_ENA_MASK), 178 ARIZONA_EQ3_ENA_MASK),
179SND_SOC_BYTES_MASK("EQ4 Coefficeints", ARIZONA_EQ4_1, 21, 179SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
180 ARIZONA_EQ4_ENA_MASK), 180 ARIZONA_EQ4_ENA_MASK),
181 181
182SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 182SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
@@ -887,7 +887,7 @@ static const struct snd_soc_dapm_route wm8997_dapm_routes[] = {
887 ARIZONA_MIXER_ROUTES("Mic Mute Mixer", "Mic"), 887 ARIZONA_MIXER_ROUTES("Mic Mute Mixer", "Mic"),
888 888
889 ARIZONA_MUX_ROUTES("ISRC1INT1", "ISRC1INT1"), 889 ARIZONA_MUX_ROUTES("ISRC1INT1", "ISRC1INT1"),
890 ARIZONA_MUX_ROUTES("ISRC1INT2", "ISRC2INT2"), 890 ARIZONA_MUX_ROUTES("ISRC1INT2", "ISRC1INT2"),
891 891
892 ARIZONA_MUX_ROUTES("ISRC1DEC1", "ISRC1DEC1"), 892 ARIZONA_MUX_ROUTES("ISRC1DEC1", "ISRC1DEC1"),
893 ARIZONA_MUX_ROUTES("ISRC1DEC2", "ISRC1DEC2"), 893 ARIZONA_MUX_ROUTES("ISRC1DEC2", "ISRC1DEC2"),
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index a53e175c015a..acea8927905b 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -221,7 +221,8 @@ static int wm9713_voice_shutdown(struct snd_soc_dapm_widget *w,
221 struct snd_soc_codec *codec = w->codec; 221 struct snd_soc_codec *codec = w->codec;
222 u16 status, rate; 222 u16 status, rate;
223 223
224 BUG_ON(event != SND_SOC_DAPM_PRE_PMD); 224 if (WARN_ON(event != SND_SOC_DAPM_PRE_PMD))
225 return -EINVAL;
225 226
226 /* Gracefully shut down the voice interface. */ 227 /* Gracefully shut down the voice interface. */
227 status = ac97_read(codec, AC97_EXTENDED_MID) | 0x1000; 228 status = ac97_read(codec, AC97_EXTENDED_MID) | 0x1000;
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index b38f3506418f..46ec0e9744d4 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -341,6 +341,8 @@ static struct wm_adsp_region const *wm_adsp_find_region(struct wm_adsp *dsp,
341static unsigned int wm_adsp_region_to_reg(struct wm_adsp_region const *region, 341static unsigned int wm_adsp_region_to_reg(struct wm_adsp_region const *region,
342 unsigned int offset) 342 unsigned int offset)
343{ 343{
344 if (WARN_ON(!region))
345 return offset;
344 switch (region->type) { 346 switch (region->type) {
345 case WMFW_ADSP1_PM: 347 case WMFW_ADSP1_PM:
346 return region->base + (offset * 3); 348 return region->base + (offset * 3);
@@ -353,7 +355,7 @@ static unsigned int wm_adsp_region_to_reg(struct wm_adsp_region const *region,
353 case WMFW_ADSP1_ZM: 355 case WMFW_ADSP1_ZM:
354 return region->base + (offset * 2); 356 return region->base + (offset * 2);
355 default: 357 default:
356 WARN_ON(NULL != "Unknown memory region type"); 358 WARN(1, "Unknown memory region type");
357 return offset; 359 return offset;
358 } 360 }
359} 361}
@@ -396,11 +398,12 @@ static int wm_coeff_write_control(struct snd_kcontrol *kcontrol,
396 ret = regmap_raw_write(adsp->regmap, reg, scratch, 398 ret = regmap_raw_write(adsp->regmap, reg, scratch,
397 ctl->len); 399 ctl->len);
398 if (ret) { 400 if (ret) {
399 adsp_err(adsp, "Failed to write %zu bytes to %x\n", 401 adsp_err(adsp, "Failed to write %zu bytes to %x: %d\n",
400 ctl->len, reg); 402 ctl->len, reg, ret);
401 kfree(scratch); 403 kfree(scratch);
402 return ret; 404 return ret;
403 } 405 }
406 adsp_dbg(adsp, "Wrote %zu bytes to %x\n", ctl->len, reg);
404 407
405 kfree(scratch); 408 kfree(scratch);
406 409
@@ -450,11 +453,12 @@ static int wm_coeff_read_control(struct snd_kcontrol *kcontrol,
450 453
451 ret = regmap_raw_read(adsp->regmap, reg, scratch, ctl->len); 454 ret = regmap_raw_read(adsp->regmap, reg, scratch, ctl->len);
452 if (ret) { 455 if (ret) {
453 adsp_err(adsp, "Failed to read %zu bytes from %x\n", 456 adsp_err(adsp, "Failed to read %zu bytes from %x: %d\n",
454 ctl->len, reg); 457 ctl->len, reg, ret);
455 kfree(scratch); 458 kfree(scratch);
456 return ret; 459 return ret;
457 } 460 }
461 adsp_dbg(adsp, "Read %zu bytes from %x\n", ctl->len, reg);
458 462
459 memcpy(buf, scratch, ctl->len); 463 memcpy(buf, scratch, ctl->len);
460 kfree(scratch); 464 kfree(scratch);
@@ -568,6 +572,7 @@ static int wm_adsp_load(struct wm_adsp *dsp)
568 file, header->ver); 572 file, header->ver);
569 goto out_fw; 573 goto out_fw;
570 } 574 }
575 adsp_info(dsp, "Firmware version: %d\n", header->ver);
571 576
572 if (header->core != dsp->type) { 577 if (header->core != dsp->type) {
573 adsp_err(dsp, "%s: invalid core %d != %d\n", 578 adsp_err(dsp, "%s: invalid core %d != %d\n",
@@ -602,7 +607,7 @@ static int wm_adsp_load(struct wm_adsp *dsp)
602 break; 607 break;
603 608
604 default: 609 default:
605 BUG_ON(NULL == "Unknown DSP type"); 610 WARN(1, "Unknown DSP type");
606 goto out_fw; 611 goto out_fw;
607 } 612 }
608 613
@@ -642,27 +647,22 @@ static int wm_adsp_load(struct wm_adsp *dsp)
642 reg = offset; 647 reg = offset;
643 break; 648 break;
644 case WMFW_ADSP1_PM: 649 case WMFW_ADSP1_PM:
645 BUG_ON(!mem);
646 region_name = "PM"; 650 region_name = "PM";
647 reg = wm_adsp_region_to_reg(mem, offset); 651 reg = wm_adsp_region_to_reg(mem, offset);
648 break; 652 break;
649 case WMFW_ADSP1_DM: 653 case WMFW_ADSP1_DM:
650 BUG_ON(!mem);
651 region_name = "DM"; 654 region_name = "DM";
652 reg = wm_adsp_region_to_reg(mem, offset); 655 reg = wm_adsp_region_to_reg(mem, offset);
653 break; 656 break;
654 case WMFW_ADSP2_XM: 657 case WMFW_ADSP2_XM:
655 BUG_ON(!mem);
656 region_name = "XM"; 658 region_name = "XM";
657 reg = wm_adsp_region_to_reg(mem, offset); 659 reg = wm_adsp_region_to_reg(mem, offset);
658 break; 660 break;
659 case WMFW_ADSP2_YM: 661 case WMFW_ADSP2_YM:
660 BUG_ON(!mem);
661 region_name = "YM"; 662 region_name = "YM";
662 reg = wm_adsp_region_to_reg(mem, offset); 663 reg = wm_adsp_region_to_reg(mem, offset);
663 break; 664 break;
664 case WMFW_ADSP1_ZM: 665 case WMFW_ADSP1_ZM:
665 BUG_ON(!mem);
666 region_name = "ZM"; 666 region_name = "ZM";
667 reg = wm_adsp_region_to_reg(mem, offset); 667 reg = wm_adsp_region_to_reg(mem, offset);
668 break; 668 break;
@@ -689,7 +689,8 @@ static int wm_adsp_load(struct wm_adsp *dsp)
689 &buf_list); 689 &buf_list);
690 if (!buf) { 690 if (!buf) {
691 adsp_err(dsp, "Out of memory\n"); 691 adsp_err(dsp, "Out of memory\n");
692 return -ENOMEM; 692 ret = -ENOMEM;
693 goto out_fw;
693 } 694 }
694 695
695 ret = regmap_raw_write_async(regmap, reg, buf->buf, 696 ret = regmap_raw_write_async(regmap, reg, buf->buf,
@@ -901,10 +902,8 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
901 break; 902 break;
902 } 903 }
903 904
904 if (mem == NULL) { 905 if (WARN_ON(!mem))
905 BUG_ON(mem != NULL);
906 return -EINVAL; 906 return -EINVAL;
907 }
908 907
909 switch (dsp->type) { 908 switch (dsp->type) {
910 case WMFW_ADSP1: 909 case WMFW_ADSP1:
@@ -998,7 +997,7 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
998 break; 997 break;
999 998
1000 default: 999 default:
1001 BUG_ON(NULL == "Unknown DSP type"); 1000 WARN(1, "Unknown DSP type");
1002 return -EINVAL; 1001 return -EINVAL;
1003 } 1002 }
1004 1003
@@ -1062,6 +1061,7 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1062 if (i + 1 < algs) { 1061 if (i + 1 < algs) {
1063 region->len = be32_to_cpu(adsp1_alg[i + 1].dm); 1062 region->len = be32_to_cpu(adsp1_alg[i + 1].dm);
1064 region->len -= be32_to_cpu(adsp1_alg[i].dm); 1063 region->len -= be32_to_cpu(adsp1_alg[i].dm);
1064 region->len *= 4;
1065 wm_adsp_create_control(dsp, region); 1065 wm_adsp_create_control(dsp, region);
1066 } else { 1066 } else {
1067 adsp_warn(dsp, "Missing length info for region DM with ID %x\n", 1067 adsp_warn(dsp, "Missing length info for region DM with ID %x\n",
@@ -1079,6 +1079,7 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1079 if (i + 1 < algs) { 1079 if (i + 1 < algs) {
1080 region->len = be32_to_cpu(adsp1_alg[i + 1].zm); 1080 region->len = be32_to_cpu(adsp1_alg[i + 1].zm);
1081 region->len -= be32_to_cpu(adsp1_alg[i].zm); 1081 region->len -= be32_to_cpu(adsp1_alg[i].zm);
1082 region->len *= 4;
1082 wm_adsp_create_control(dsp, region); 1083 wm_adsp_create_control(dsp, region);
1083 } else { 1084 } else {
1084 adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", 1085 adsp_warn(dsp, "Missing length info for region ZM with ID %x\n",
@@ -1108,6 +1109,7 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1108 if (i + 1 < algs) { 1109 if (i + 1 < algs) {
1109 region->len = be32_to_cpu(adsp2_alg[i + 1].xm); 1110 region->len = be32_to_cpu(adsp2_alg[i + 1].xm);
1110 region->len -= be32_to_cpu(adsp2_alg[i].xm); 1111 region->len -= be32_to_cpu(adsp2_alg[i].xm);
1112 region->len *= 4;
1111 wm_adsp_create_control(dsp, region); 1113 wm_adsp_create_control(dsp, region);
1112 } else { 1114 } else {
1113 adsp_warn(dsp, "Missing length info for region XM with ID %x\n", 1115 adsp_warn(dsp, "Missing length info for region XM with ID %x\n",
@@ -1125,6 +1127,7 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1125 if (i + 1 < algs) { 1127 if (i + 1 < algs) {
1126 region->len = be32_to_cpu(adsp2_alg[i + 1].ym); 1128 region->len = be32_to_cpu(adsp2_alg[i + 1].ym);
1127 region->len -= be32_to_cpu(adsp2_alg[i].ym); 1129 region->len -= be32_to_cpu(adsp2_alg[i].ym);
1130 region->len *= 4;
1128 wm_adsp_create_control(dsp, region); 1131 wm_adsp_create_control(dsp, region);
1129 } else { 1132 } else {
1130 adsp_warn(dsp, "Missing length info for region YM with ID %x\n", 1133 adsp_warn(dsp, "Missing length info for region YM with ID %x\n",
@@ -1142,6 +1145,7 @@ static int wm_adsp_setup_algs(struct wm_adsp *dsp)
1142 if (i + 1 < algs) { 1145 if (i + 1 < algs) {
1143 region->len = be32_to_cpu(adsp2_alg[i + 1].zm); 1146 region->len = be32_to_cpu(adsp2_alg[i + 1].zm);
1144 region->len -= be32_to_cpu(adsp2_alg[i].zm); 1147 region->len -= be32_to_cpu(adsp2_alg[i].zm);
1148 region->len *= 4;
1145 wm_adsp_create_control(dsp, region); 1149 wm_adsp_create_control(dsp, region);
1146 } else { 1150 } else {
1147 adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", 1151 adsp_warn(dsp, "Missing length info for region ZM with ID %x\n",
@@ -1313,8 +1317,8 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
1313 le32_to_cpu(blk->len)); 1317 le32_to_cpu(blk->len));
1314 if (ret != 0) { 1318 if (ret != 0) {
1315 adsp_err(dsp, 1319 adsp_err(dsp,
1316 "%s.%d: Failed to write to %x in %s\n", 1320 "%s.%d: Failed to write to %x in %s: %d\n",
1317 file, blocks, reg, region_name); 1321 file, blocks, reg, region_name, ret);
1318 } 1322 }
1319 } 1323 }
1320 1324
@@ -1358,6 +1362,7 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
1358 struct snd_soc_codec *codec = w->codec; 1362 struct snd_soc_codec *codec = w->codec;
1359 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); 1363 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec);
1360 struct wm_adsp *dsp = &dsps[w->shift]; 1364 struct wm_adsp *dsp = &dsps[w->shift];
1365 struct wm_adsp_alg_region *alg_region;
1361 struct wm_coeff_ctl *ctl; 1366 struct wm_coeff_ctl *ctl;
1362 int ret; 1367 int ret;
1363 int val; 1368 int val;
@@ -1435,6 +1440,14 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
1435 1440
1436 list_for_each_entry(ctl, &dsp->ctl_list, list) 1441 list_for_each_entry(ctl, &dsp->ctl_list, list)
1437 ctl->enabled = 0; 1442 ctl->enabled = 0;
1443
1444 while (!list_empty(&dsp->alg_regions)) {
1445 alg_region = list_first_entry(&dsp->alg_regions,
1446 struct wm_adsp_alg_region,
1447 list);
1448 list_del(&alg_region->list);
1449 kfree(alg_region);
1450 }
1438 break; 1451 break;
1439 1452
1440 default: 1453 default:
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index 8b50e5958de5..b371066dd5bc 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -530,6 +530,7 @@ static int hp_supply_event(struct snd_soc_dapm_widget *w,
530 hubs->hp_startup_mode); 530 hubs->hp_startup_mode);
531 break; 531 break;
532 } 532 }
533 break;
533 534
534 case SND_SOC_DAPM_PRE_PMD: 535 case SND_SOC_DAPM_PRE_PMD:
535 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1, 536 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
@@ -610,7 +611,7 @@ static int earpiece_event(struct snd_soc_dapm_widget *w,
610 break; 611 break;
611 612
612 default: 613 default:
613 BUG(); 614 WARN(1, "Invalid event %d\n", event);
614 break; 615 break;
615 } 616 }
616 617
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
index c82f89c9475b..95970f5db3ec 100644
--- a/sound/soc/davinci/Kconfig
+++ b/sound/soc/davinci/Kconfig
@@ -1,9 +1,10 @@
1config SND_DAVINCI_SOC 1config SND_DAVINCI_SOC
2 tristate "SoC Audio for the TI DAVINCI chip" 2 tristate "SoC Audio for the TI DAVINCI or AM33XX chip"
3 depends on ARCH_DAVINCI 3 depends on ARCH_DAVINCI || SOC_AM33XX
4 help 4 help
5 Platform driver for daVinci or AM33xx
5 Say Y or M if you want to add support for codecs attached to 6 Say Y or M if you want to add support for codecs attached to
6 the DAVINCI AC97 or I2S interface. You will also need 7 the DAVINCI AC97, I2S, or McASP interface. You will also need
7 to select the audio interfaces to support below. 8 to select the audio interfaces to support below.
8 9
9config SND_DAVINCI_SOC_I2S 10config SND_DAVINCI_SOC_I2S
@@ -15,6 +16,17 @@ config SND_DAVINCI_SOC_MCASP
15config SND_DAVINCI_SOC_VCIF 16config SND_DAVINCI_SOC_VCIF
16 tristate 17 tristate
17 18
19config SND_AM33XX_SOC_EVM
20 tristate "SoC Audio for the AM33XX chip based boards"
21 depends on SND_DAVINCI_SOC && SOC_AM33XX
22 select SND_SOC_TLV320AIC3X
23 select SND_DAVINCI_SOC_MCASP
24 help
25 Say Y or M if you want to add support for SoC audio on AM33XX
26 boards using McASP and TLV320AIC3X codec. For example AM335X-EVM,
27 AM335X-EVMSK, and BeagelBone with AudioCape boards have this
28 setup.
29
18config SND_DAVINCI_SOC_EVM 30config SND_DAVINCI_SOC_EVM
19 tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM" 31 tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM"
20 depends on SND_DAVINCI_SOC 32 depends on SND_DAVINCI_SOC
diff --git a/sound/soc/davinci/Makefile b/sound/soc/davinci/Makefile
index a396ab6d6d5e..bc81e79fc301 100644
--- a/sound/soc/davinci/Makefile
+++ b/sound/soc/davinci/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_SND_DAVINCI_SOC_VCIF) += snd-soc-davinci-vcif.o
13snd-soc-evm-objs := davinci-evm.o 13snd-soc-evm-objs := davinci-evm.o
14 14
15obj-$(CONFIG_SND_DAVINCI_SOC_EVM) += snd-soc-evm.o 15obj-$(CONFIG_SND_DAVINCI_SOC_EVM) += snd-soc-evm.o
16obj-$(CONFIG_SND_AM33XX_SOC_EVM) += snd-soc-evm.o
16obj-$(CONFIG_SND_DM6467_SOC_EVM) += snd-soc-evm.o 17obj-$(CONFIG_SND_DM6467_SOC_EVM) += snd-soc-evm.o
17obj-$(CONFIG_SND_DA830_SOC_EVM) += snd-soc-evm.o 18obj-$(CONFIG_SND_DA830_SOC_EVM) += snd-soc-evm.o
18obj-$(CONFIG_SND_DA850_SOC_EVM) += snd-soc-evm.o 19obj-$(CONFIG_SND_DA850_SOC_EVM) += snd-soc-evm.o
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index fd7c45b9ed5a..623eb5e7c089 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -16,6 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/platform_data/edma.h> 17#include <linux/platform_data/edma.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/of_platform.h>
19#include <sound/core.h> 20#include <sound/core.h>
20#include <sound/pcm.h> 21#include <sound/pcm.h>
21#include <sound/soc.h> 22#include <sound/soc.h>
@@ -23,10 +24,16 @@
23#include <asm/dma.h> 24#include <asm/dma.h>
24#include <asm/mach-types.h> 25#include <asm/mach-types.h>
25 26
27#include <linux/edma.h>
28
26#include "davinci-pcm.h" 29#include "davinci-pcm.h"
27#include "davinci-i2s.h" 30#include "davinci-i2s.h"
28#include "davinci-mcasp.h" 31#include "davinci-mcasp.h"
29 32
33struct snd_soc_card_drvdata_davinci {
34 unsigned sysclk;
35};
36
30#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \ 37#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
31 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF) 38 SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
32static int evm_hw_params(struct snd_pcm_substream *substream, 39static int evm_hw_params(struct snd_pcm_substream *substream,
@@ -35,27 +42,11 @@ static int evm_hw_params(struct snd_pcm_substream *substream,
35 struct snd_soc_pcm_runtime *rtd = substream->private_data; 42 struct snd_soc_pcm_runtime *rtd = substream->private_data;
36 struct snd_soc_dai *codec_dai = rtd->codec_dai; 43 struct snd_soc_dai *codec_dai = rtd->codec_dai;
37 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 44 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
45 struct snd_soc_codec *codec = rtd->codec;
46 struct snd_soc_card *soc_card = codec->card;
38 int ret = 0; 47 int ret = 0;
39 unsigned sysclk; 48 unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *)
40 49 snd_soc_card_get_drvdata(soc_card))->sysclk;
41 /* ASP1 on DM355 EVM is clocked by an external oscillator */
42 if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm() ||
43 machine_is_davinci_dm365_evm())
44 sysclk = 27000000;
45
46 /* ASP0 in DM6446 EVM is clocked by U55, as configured by
47 * board-dm644x-evm.c using GPIOs from U18. There are six
48 * options; here we "know" we use a 48 KHz sample rate.
49 */
50 else if (machine_is_davinci_evm())
51 sysclk = 12288000;
52
53 else if (machine_is_davinci_da830_evm() ||
54 machine_is_davinci_da850_evm())
55 sysclk = 24576000;
56
57 else
58 return -EINVAL;
59 50
60 /* set codec DAI configuration */ 51 /* set codec DAI configuration */
61 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT); 52 ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
@@ -133,13 +124,22 @@ static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
133{ 124{
134 struct snd_soc_codec *codec = rtd->codec; 125 struct snd_soc_codec *codec = rtd->codec;
135 struct snd_soc_dapm_context *dapm = &codec->dapm; 126 struct snd_soc_dapm_context *dapm = &codec->dapm;
127 struct device_node *np = codec->card->dev->of_node;
128 int ret;
136 129
137 /* Add davinci-evm specific widgets */ 130 /* Add davinci-evm specific widgets */
138 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets, 131 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
139 ARRAY_SIZE(aic3x_dapm_widgets)); 132 ARRAY_SIZE(aic3x_dapm_widgets));
140 133
141 /* Set up davinci-evm specific audio path audio_map */ 134 if (np) {
142 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); 135 ret = snd_soc_of_parse_audio_routing(codec->card,
136 "ti,audio-routing");
137 if (ret)
138 return ret;
139 } else {
140 /* Set up davinci-evm specific audio path audio_map */
141 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
142 }
143 143
144 /* not connected */ 144 /* not connected */
145 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT"); 145 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
@@ -243,35 +243,65 @@ static struct snd_soc_dai_link da850_evm_dai = {
243}; 243};
244 244
245/* davinci dm6446 evm audio machine driver */ 245/* davinci dm6446 evm audio machine driver */
246/*
247 * ASP0 in DM6446 EVM is clocked by U55, as configured by
248 * board-dm644x-evm.c using GPIOs from U18. There are six
249 * options; here we "know" we use a 48 KHz sample rate.
250 */
251static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = {
252 .sysclk = 12288000,
253};
254
246static struct snd_soc_card dm6446_snd_soc_card_evm = { 255static struct snd_soc_card dm6446_snd_soc_card_evm = {
247 .name = "DaVinci DM6446 EVM", 256 .name = "DaVinci DM6446 EVM",
248 .owner = THIS_MODULE, 257 .owner = THIS_MODULE,
249 .dai_link = &dm6446_evm_dai, 258 .dai_link = &dm6446_evm_dai,
250 .num_links = 1, 259 .num_links = 1,
260 .drvdata = &dm6446_snd_soc_card_drvdata,
251}; 261};
252 262
253/* davinci dm355 evm audio machine driver */ 263/* davinci dm355 evm audio machine driver */
264/* ASP1 on DM355 EVM is clocked by an external oscillator */
265static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = {
266 .sysclk = 27000000,
267};
268
254static struct snd_soc_card dm355_snd_soc_card_evm = { 269static struct snd_soc_card dm355_snd_soc_card_evm = {
255 .name = "DaVinci DM355 EVM", 270 .name = "DaVinci DM355 EVM",
256 .owner = THIS_MODULE, 271 .owner = THIS_MODULE,
257 .dai_link = &dm355_evm_dai, 272 .dai_link = &dm355_evm_dai,
258 .num_links = 1, 273 .num_links = 1,
274 .drvdata = &dm355_snd_soc_card_drvdata,
259}; 275};
260 276
261/* davinci dm365 evm audio machine driver */ 277/* davinci dm365 evm audio machine driver */
278static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = {
279 .sysclk = 27000000,
280};
281
262static struct snd_soc_card dm365_snd_soc_card_evm = { 282static struct snd_soc_card dm365_snd_soc_card_evm = {
263 .name = "DaVinci DM365 EVM", 283 .name = "DaVinci DM365 EVM",
264 .owner = THIS_MODULE, 284 .owner = THIS_MODULE,
265 .dai_link = &dm365_evm_dai, 285 .dai_link = &dm365_evm_dai,
266 .num_links = 1, 286 .num_links = 1,
287 .drvdata = &dm365_snd_soc_card_drvdata,
267}; 288};
268 289
269/* davinci dm6467 evm audio machine driver */ 290/* davinci dm6467 evm audio machine driver */
291static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = {
292 .sysclk = 27000000,
293};
294
270static struct snd_soc_card dm6467_snd_soc_card_evm = { 295static struct snd_soc_card dm6467_snd_soc_card_evm = {
271 .name = "DaVinci DM6467 EVM", 296 .name = "DaVinci DM6467 EVM",
272 .owner = THIS_MODULE, 297 .owner = THIS_MODULE,
273 .dai_link = dm6467_evm_dai, 298 .dai_link = dm6467_evm_dai,
274 .num_links = ARRAY_SIZE(dm6467_evm_dai), 299 .num_links = ARRAY_SIZE(dm6467_evm_dai),
300 .drvdata = &dm6467_snd_soc_card_drvdata,
301};
302
303static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = {
304 .sysclk = 24576000,
275}; 305};
276 306
277static struct snd_soc_card da830_snd_soc_card = { 307static struct snd_soc_card da830_snd_soc_card = {
@@ -279,6 +309,11 @@ static struct snd_soc_card da830_snd_soc_card = {
279 .owner = THIS_MODULE, 309 .owner = THIS_MODULE,
280 .dai_link = &da830_evm_dai, 310 .dai_link = &da830_evm_dai,
281 .num_links = 1, 311 .num_links = 1,
312 .drvdata = &da830_snd_soc_card_drvdata,
313};
314
315static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = {
316 .sysclk = 24576000,
282}; 317};
283 318
284static struct snd_soc_card da850_snd_soc_card = { 319static struct snd_soc_card da850_snd_soc_card = {
@@ -286,8 +321,101 @@ static struct snd_soc_card da850_snd_soc_card = {
286 .owner = THIS_MODULE, 321 .owner = THIS_MODULE,
287 .dai_link = &da850_evm_dai, 322 .dai_link = &da850_evm_dai,
288 .num_links = 1, 323 .num_links = 1,
324 .drvdata = &da850_snd_soc_card_drvdata,
325};
326
327#if defined(CONFIG_OF)
328
329/*
330 * The struct is used as place holder. It will be completely
331 * filled with data from dt node.
332 */
333static struct snd_soc_dai_link evm_dai_tlv320aic3x = {
334 .name = "TLV320AIC3X",
335 .stream_name = "AIC3X",
336 .codec_dai_name = "tlv320aic3x-hifi",
337 .ops = &evm_ops,
338 .init = evm_aic3x_init,
339};
340
341static const struct of_device_id davinci_evm_dt_ids[] = {
342 {
343 .compatible = "ti,da830-evm-audio",
344 .data = (void *) &evm_dai_tlv320aic3x,
345 },
346 { /* sentinel */ }
347};
348MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids);
349
350/* davinci evm audio machine driver */
351static struct snd_soc_card evm_soc_card = {
352 .owner = THIS_MODULE,
353 .num_links = 1,
289}; 354};
290 355
356static int davinci_evm_probe(struct platform_device *pdev)
357{
358 struct device_node *np = pdev->dev.of_node;
359 const struct of_device_id *match =
360 of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev);
361 struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data;
362 struct snd_soc_card_drvdata_davinci *drvdata = NULL;
363 int ret = 0;
364
365 evm_soc_card.dai_link = dai;
366
367 dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0);
368 if (!dai->codec_of_node)
369 return -EINVAL;
370
371 dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
372 if (!dai->cpu_of_node)
373 return -EINVAL;
374
375 dai->platform_of_node = dai->cpu_of_node;
376
377 evm_soc_card.dev = &pdev->dev;
378 ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model");
379 if (ret)
380 return ret;
381
382 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
383 if (!drvdata)
384 return -ENOMEM;
385
386 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
387 if (ret < 0)
388 return -EINVAL;
389
390 snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
391 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
392
393 if (ret)
394 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
395
396 return ret;
397}
398
399static int davinci_evm_remove(struct platform_device *pdev)
400{
401 struct snd_soc_card *card = platform_get_drvdata(pdev);
402
403 snd_soc_unregister_card(card);
404
405 return 0;
406}
407
408static struct platform_driver davinci_evm_driver = {
409 .probe = davinci_evm_probe,
410 .remove = davinci_evm_remove,
411 .driver = {
412 .name = "davinci_evm",
413 .owner = THIS_MODULE,
414 .of_match_table = of_match_ptr(davinci_evm_dt_ids),
415 },
416};
417#endif
418
291static struct platform_device *evm_snd_device; 419static struct platform_device *evm_snd_device;
292 420
293static int __init evm_init(void) 421static int __init evm_init(void)
@@ -296,6 +424,15 @@ static int __init evm_init(void)
296 int index; 424 int index;
297 int ret; 425 int ret;
298 426
427 /*
428 * If dtb is there, the devices will be created dynamically.
429 * Only register platfrom driver structure.
430 */
431#if defined(CONFIG_OF)
432 if (of_have_populated_dt())
433 return platform_driver_register(&davinci_evm_driver);
434#endif
435
299 if (machine_is_davinci_evm()) { 436 if (machine_is_davinci_evm()) {
300 evm_snd_dev_data = &dm6446_snd_soc_card_evm; 437 evm_snd_dev_data = &dm6446_snd_soc_card_evm;
301 index = 0; 438 index = 0;
@@ -331,6 +468,13 @@ static int __init evm_init(void)
331 468
332static void __exit evm_exit(void) 469static void __exit evm_exit(void)
333{ 470{
471#if defined(CONFIG_OF)
472 if (of_have_populated_dt()) {
473 platform_driver_unregister(&davinci_evm_driver);
474 return;
475 }
476#endif
477
334 platform_device_unregister(evm_snd_device); 478 platform_device_unregister(evm_snd_device);
335} 479}
336 480
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 32ddb7fe5034..71e14bb3a8cd 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -1001,18 +1001,40 @@ static const struct snd_soc_component_driver davinci_mcasp_component = {
1001 .name = "davinci-mcasp", 1001 .name = "davinci-mcasp",
1002}; 1002};
1003 1003
1004/* Some HW specific values and defaults. The rest is filled in from DT. */
1005static struct snd_platform_data dm646x_mcasp_pdata = {
1006 .tx_dma_offset = 0x400,
1007 .rx_dma_offset = 0x400,
1008 .asp_chan_q = EVENTQ_0,
1009 .version = MCASP_VERSION_1,
1010};
1011
1012static struct snd_platform_data da830_mcasp_pdata = {
1013 .tx_dma_offset = 0x2000,
1014 .rx_dma_offset = 0x2000,
1015 .asp_chan_q = EVENTQ_0,
1016 .version = MCASP_VERSION_2,
1017};
1018
1019static struct snd_platform_data omap2_mcasp_pdata = {
1020 .tx_dma_offset = 0,
1021 .rx_dma_offset = 0,
1022 .asp_chan_q = EVENTQ_0,
1023 .version = MCASP_VERSION_3,
1024};
1025
1004static const struct of_device_id mcasp_dt_ids[] = { 1026static const struct of_device_id mcasp_dt_ids[] = {
1005 { 1027 {
1006 .compatible = "ti,dm646x-mcasp-audio", 1028 .compatible = "ti,dm646x-mcasp-audio",
1007 .data = (void *)MCASP_VERSION_1, 1029 .data = &dm646x_mcasp_pdata,
1008 }, 1030 },
1009 { 1031 {
1010 .compatible = "ti,da830-mcasp-audio", 1032 .compatible = "ti,da830-mcasp-audio",
1011 .data = (void *)MCASP_VERSION_2, 1033 .data = &da830_mcasp_pdata,
1012 }, 1034 },
1013 { 1035 {
1014 .compatible = "ti,omap2-mcasp-audio", 1036 .compatible = "ti,am33xx-mcasp-audio",
1015 .data = (void *)MCASP_VERSION_3, 1037 .data = &omap2_mcasp_pdata,
1016 }, 1038 },
1017 { /* sentinel */ } 1039 { /* sentinel */ }
1018}; 1040};
@@ -1025,9 +1047,9 @@ static struct snd_platform_data *davinci_mcasp_set_pdata_from_of(
1025 struct snd_platform_data *pdata = NULL; 1047 struct snd_platform_data *pdata = NULL;
1026 const struct of_device_id *match = 1048 const struct of_device_id *match =
1027 of_match_device(mcasp_dt_ids, &pdev->dev); 1049 of_match_device(mcasp_dt_ids, &pdev->dev);
1050 struct of_phandle_args dma_spec;
1028 1051
1029 const u32 *of_serial_dir32; 1052 const u32 *of_serial_dir32;
1030 u8 *of_serial_dir;
1031 u32 val; 1053 u32 val;
1032 int i, ret = 0; 1054 int i, ret = 0;
1033 1055
@@ -1035,20 +1057,13 @@ static struct snd_platform_data *davinci_mcasp_set_pdata_from_of(
1035 pdata = pdev->dev.platform_data; 1057 pdata = pdev->dev.platform_data;
1036 return pdata; 1058 return pdata;
1037 } else if (match) { 1059 } else if (match) {
1038 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 1060 pdata = (struct snd_platform_data *) match->data;
1039 if (!pdata) {
1040 ret = -ENOMEM;
1041 goto nodata;
1042 }
1043 } else { 1061 } else {
1044 /* control shouldn't reach here. something is wrong */ 1062 /* control shouldn't reach here. something is wrong */
1045 ret = -EINVAL; 1063 ret = -EINVAL;
1046 goto nodata; 1064 goto nodata;
1047 } 1065 }
1048 1066
1049 if (match->data)
1050 pdata->version = (u8)((int)match->data);
1051
1052 ret = of_property_read_u32(np, "op-mode", &val); 1067 ret = of_property_read_u32(np, "op-mode", &val);
1053 if (ret >= 0) 1068 if (ret >= 0)
1054 pdata->op_mode = val; 1069 pdata->op_mode = val;
@@ -1065,35 +1080,46 @@ static struct snd_platform_data *davinci_mcasp_set_pdata_from_of(
1065 pdata->tdm_slots = val; 1080 pdata->tdm_slots = val;
1066 } 1081 }
1067 1082
1068 ret = of_property_read_u32(np, "num-serializer", &val);
1069 if (ret >= 0)
1070 pdata->num_serializer = val;
1071
1072 of_serial_dir32 = of_get_property(np, "serial-dir", &val); 1083 of_serial_dir32 = of_get_property(np, "serial-dir", &val);
1073 val /= sizeof(u32); 1084 val /= sizeof(u32);
1074 if (val != pdata->num_serializer) {
1075 dev_err(&pdev->dev,
1076 "num-serializer(%d) != serial-dir size(%d)\n",
1077 pdata->num_serializer, val);
1078 ret = -EINVAL;
1079 goto nodata;
1080 }
1081
1082 if (of_serial_dir32) { 1085 if (of_serial_dir32) {
1083 of_serial_dir = devm_kzalloc(&pdev->dev, 1086 u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
1084 (sizeof(*of_serial_dir) * val), 1087 (sizeof(*of_serial_dir) * val),
1085 GFP_KERNEL); 1088 GFP_KERNEL);
1086 if (!of_serial_dir) { 1089 if (!of_serial_dir) {
1087 ret = -ENOMEM; 1090 ret = -ENOMEM;
1088 goto nodata; 1091 goto nodata;
1089 } 1092 }
1090 1093
1091 for (i = 0; i < pdata->num_serializer; i++) 1094 for (i = 0; i < val; i++)
1092 of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]); 1095 of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
1093 1096
1097 pdata->num_serializer = val;
1094 pdata->serial_dir = of_serial_dir; 1098 pdata->serial_dir = of_serial_dir;
1095 } 1099 }
1096 1100
1101 ret = of_property_match_string(np, "dma-names", "tx");
1102 if (ret < 0)
1103 goto nodata;
1104
1105 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1106 &dma_spec);
1107 if (ret < 0)
1108 goto nodata;
1109
1110 pdata->tx_dma_channel = dma_spec.args[0];
1111
1112 ret = of_property_match_string(np, "dma-names", "rx");
1113 if (ret < 0)
1114 goto nodata;
1115
1116 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1117 &dma_spec);
1118 if (ret < 0)
1119 goto nodata;
1120
1121 pdata->rx_dma_channel = dma_spec.args[0];
1122
1097 ret = of_property_read_u32(np, "tx-num-evt", &val); 1123 ret = of_property_read_u32(np, "tx-num-evt", &val);
1098 if (ret >= 0) 1124 if (ret >= 0)
1099 pdata->txnumevt = val; 1125 pdata->txnumevt = val;
@@ -1124,7 +1150,7 @@ nodata:
1124static int davinci_mcasp_probe(struct platform_device *pdev) 1150static int davinci_mcasp_probe(struct platform_device *pdev)
1125{ 1151{
1126 struct davinci_pcm_dma_params *dma_data; 1152 struct davinci_pcm_dma_params *dma_data;
1127 struct resource *mem, *ioarea, *res; 1153 struct resource *mem, *ioarea, *res, *dat;
1128 struct snd_platform_data *pdata; 1154 struct snd_platform_data *pdata;
1129 struct davinci_audio_dev *dev; 1155 struct davinci_audio_dev *dev;
1130 int ret; 1156 int ret;
@@ -1145,10 +1171,15 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1145 return -EINVAL; 1171 return -EINVAL;
1146 } 1172 }
1147 1173
1148 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1174 mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
1149 if (!mem) { 1175 if (!mem) {
1150 dev_err(&pdev->dev, "no mem resource?\n"); 1176 dev_warn(dev->dev,
1151 return -ENODEV; 1177 "\"mpu\" mem resource not found, using index 0\n");
1178 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1179 if (!mem) {
1180 dev_err(&pdev->dev, "no mem resource?\n");
1181 return -ENODEV;
1182 }
1152 } 1183 }
1153 1184
1154 ioarea = devm_request_mem_region(&pdev->dev, mem->start, 1185 ioarea = devm_request_mem_region(&pdev->dev, mem->start,
@@ -1182,40 +1213,36 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1182 dev->rxnumevt = pdata->rxnumevt; 1213 dev->rxnumevt = pdata->rxnumevt;
1183 dev->dev = &pdev->dev; 1214 dev->dev = &pdev->dev;
1184 1215
1216 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
1217 if (!dat)
1218 dat = mem;
1219
1185 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]; 1220 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
1186 dma_data->asp_chan_q = pdata->asp_chan_q; 1221 dma_data->asp_chan_q = pdata->asp_chan_q;
1187 dma_data->ram_chan_q = pdata->ram_chan_q; 1222 dma_data->ram_chan_q = pdata->ram_chan_q;
1188 dma_data->sram_pool = pdata->sram_pool; 1223 dma_data->sram_pool = pdata->sram_pool;
1189 dma_data->sram_size = pdata->sram_size_playback; 1224 dma_data->sram_size = pdata->sram_size_playback;
1190 dma_data->dma_addr = (dma_addr_t) (pdata->tx_dma_offset + 1225 dma_data->dma_addr = dat->start + pdata->tx_dma_offset;
1191 mem->start);
1192 1226
1193 /* first TX, then RX */
1194 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 1227 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1195 if (!res) { 1228 if (res)
1196 dev_err(&pdev->dev, "no DMA resource\n"); 1229 dma_data->channel = res->start;
1197 ret = -ENODEV; 1230 else
1198 goto err_release_clk; 1231 dma_data->channel = pdata->tx_dma_channel;
1199 }
1200
1201 dma_data->channel = res->start;
1202 1232
1203 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]; 1233 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_CAPTURE];
1204 dma_data->asp_chan_q = pdata->asp_chan_q; 1234 dma_data->asp_chan_q = pdata->asp_chan_q;
1205 dma_data->ram_chan_q = pdata->ram_chan_q; 1235 dma_data->ram_chan_q = pdata->ram_chan_q;
1206 dma_data->sram_pool = pdata->sram_pool; 1236 dma_data->sram_pool = pdata->sram_pool;
1207 dma_data->sram_size = pdata->sram_size_capture; 1237 dma_data->sram_size = pdata->sram_size_capture;
1208 dma_data->dma_addr = (dma_addr_t)(pdata->rx_dma_offset + 1238 dma_data->dma_addr = dat->start + pdata->rx_dma_offset;
1209 mem->start);
1210 1239
1211 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 1240 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1212 if (!res) { 1241 if (res)
1213 dev_err(&pdev->dev, "no DMA resource\n"); 1242 dma_data->channel = res->start;
1214 ret = -ENODEV; 1243 else
1215 goto err_release_clk; 1244 dma_data->channel = pdata->rx_dma_channel;
1216 }
1217 1245
1218 dma_data->channel = res->start;
1219 dev_set_drvdata(&pdev->dev, dev); 1246 dev_set_drvdata(&pdev->dev, dev);
1220 ret = snd_soc_register_component(&pdev->dev, &davinci_mcasp_component, 1247 ret = snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
1221 &davinci_mcasp_dai[pdata->op_mode], 1); 1248 &davinci_mcasp_dai[pdata->op_mode], 1);
@@ -1251,12 +1278,51 @@ static int davinci_mcasp_remove(struct platform_device *pdev)
1251 return 0; 1278 return 0;
1252} 1279}
1253 1280
1281#ifdef CONFIG_PM_SLEEP
1282static int davinci_mcasp_suspend(struct device *dev)
1283{
1284 struct davinci_audio_dev *a = dev_get_drvdata(dev);
1285 void __iomem *base = a->base;
1286
1287 a->context.txfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_TXFMCTL_REG);
1288 a->context.rxfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_RXFMCTL_REG);
1289 a->context.txfmt = mcasp_get_reg(base + DAVINCI_MCASP_TXFMT_REG);
1290 a->context.rxfmt = mcasp_get_reg(base + DAVINCI_MCASP_RXFMT_REG);
1291 a->context.aclkxctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKXCTL_REG);
1292 a->context.aclkrctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKRCTL_REG);
1293 a->context.pdir = mcasp_get_reg(base + DAVINCI_MCASP_PDIR_REG);
1294
1295 return 0;
1296}
1297
1298static int davinci_mcasp_resume(struct device *dev)
1299{
1300 struct davinci_audio_dev *a = dev_get_drvdata(dev);
1301 void __iomem *base = a->base;
1302
1303 mcasp_set_reg(base + DAVINCI_MCASP_TXFMCTL_REG, a->context.txfmtctl);
1304 mcasp_set_reg(base + DAVINCI_MCASP_RXFMCTL_REG, a->context.rxfmtctl);
1305 mcasp_set_reg(base + DAVINCI_MCASP_TXFMT_REG, a->context.txfmt);
1306 mcasp_set_reg(base + DAVINCI_MCASP_RXFMT_REG, a->context.rxfmt);
1307 mcasp_set_reg(base + DAVINCI_MCASP_ACLKXCTL_REG, a->context.aclkxctl);
1308 mcasp_set_reg(base + DAVINCI_MCASP_ACLKRCTL_REG, a->context.aclkrctl);
1309 mcasp_set_reg(base + DAVINCI_MCASP_PDIR_REG, a->context.pdir);
1310
1311 return 0;
1312}
1313#endif
1314
1315SIMPLE_DEV_PM_OPS(davinci_mcasp_pm_ops,
1316 davinci_mcasp_suspend,
1317 davinci_mcasp_resume);
1318
1254static struct platform_driver davinci_mcasp_driver = { 1319static struct platform_driver davinci_mcasp_driver = {
1255 .probe = davinci_mcasp_probe, 1320 .probe = davinci_mcasp_probe,
1256 .remove = davinci_mcasp_remove, 1321 .remove = davinci_mcasp_remove,
1257 .driver = { 1322 .driver = {
1258 .name = "davinci-mcasp", 1323 .name = "davinci-mcasp",
1259 .owner = THIS_MODULE, 1324 .owner = THIS_MODULE,
1325 .pm = &davinci_mcasp_pm_ops,
1260 .of_match_table = mcasp_dt_ids, 1326 .of_match_table = mcasp_dt_ids,
1261 }, 1327 },
1262}; 1328};
@@ -1266,4 +1332,3 @@ module_platform_driver(davinci_mcasp_driver);
1266MODULE_AUTHOR("Steve Chen"); 1332MODULE_AUTHOR("Steve Chen");
1267MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface"); 1333MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface");
1268MODULE_LICENSE("GPL"); 1334MODULE_LICENSE("GPL");
1269
diff --git a/sound/soc/davinci/davinci-mcasp.h b/sound/soc/davinci/davinci-mcasp.h
index a9ac0c11da71..a2e27e1c32f3 100644
--- a/sound/soc/davinci/davinci-mcasp.h
+++ b/sound/soc/davinci/davinci-mcasp.h
@@ -43,6 +43,18 @@ struct davinci_audio_dev {
43 /* McASP FIFO related */ 43 /* McASP FIFO related */
44 u8 txnumevt; 44 u8 txnumevt;
45 u8 rxnumevt; 45 u8 rxnumevt;
46
47#ifdef CONFIG_PM_SLEEP
48 struct {
49 u32 txfmtctl;
50 u32 rxfmtctl;
51 u32 txfmt;
52 u32 rxfmt;
53 u32 aclkxctl;
54 u32 aclkrctl;
55 u32 pdir;
56 } context;
57#endif
46}; 58};
47 59
48#endif /* DAVINCI_MCASP_H */ 60#endif /* DAVINCI_MCASP_H */
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
index 8460edce1c3b..fa64cd85204f 100644
--- a/sound/soc/davinci/davinci-pcm.c
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -267,10 +267,9 @@ static int allocate_sram(struct snd_pcm_substream *substream,
267 return 0; 267 return 0;
268 268
269 ppcm->period_bytes_max = size; 269 ppcm->period_bytes_max = size;
270 iram_virt = (void *)gen_pool_alloc(sram_pool, size); 270 iram_virt = gen_pool_dma_alloc(sram_pool, size, &iram_phys);
271 if (!iram_virt) 271 if (!iram_virt)
272 goto exit1; 272 goto exit1;
273 iram_phys = gen_pool_virt_to_phys(sram_pool, (unsigned)iram_virt);
274 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL); 273 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL);
275 if (!iram_dma) 274 if (!iram_dma)
276 goto exit2; 275 goto exit2;
@@ -844,18 +843,15 @@ static void davinci_pcm_free(struct snd_pcm *pcm)
844 } 843 }
845} 844}
846 845
847static u64 davinci_pcm_dmamask = DMA_BIT_MASK(32);
848
849static int davinci_pcm_new(struct snd_soc_pcm_runtime *rtd) 846static int davinci_pcm_new(struct snd_soc_pcm_runtime *rtd)
850{ 847{
851 struct snd_card *card = rtd->card->snd_card; 848 struct snd_card *card = rtd->card->snd_card;
852 struct snd_pcm *pcm = rtd->pcm; 849 struct snd_pcm *pcm = rtd->pcm;
853 int ret; 850 int ret;
854 851
855 if (!card->dev->dma_mask) 852 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
856 card->dev->dma_mask = &davinci_pcm_dmamask; 853 if (ret)
857 if (!card->dev->coherent_dma_mask) 854 return ret;
858 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
859 855
860 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 856 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
861 ret = davinci_pcm_preallocate_dma_buffer(pcm, 857 ret = davinci_pcm_preallocate_dma_buffer(pcm,
diff --git a/sound/soc/fsl/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
index 9a4a0ca2c1de..5983740be123 100644
--- a/sound/soc/fsl/eukrea-tlv320.c
+++ b/sound/soc/fsl/eukrea-tlv320.c
@@ -42,7 +42,8 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
42 SND_SOC_DAIFMT_NB_NF | 42 SND_SOC_DAIFMT_NB_NF |
43 SND_SOC_DAIFMT_CBM_CFM); 43 SND_SOC_DAIFMT_CBM_CFM);
44 if (ret) { 44 if (ret) {
45 pr_err("%s: failed set cpu dai format\n", __func__); 45 dev_err(cpu_dai->dev,
46 "Failed to set the cpu dai format.\n");
46 return ret; 47 return ret;
47 } 48 }
48 49
@@ -50,14 +51,16 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
50 SND_SOC_DAIFMT_NB_NF | 51 SND_SOC_DAIFMT_NB_NF |
51 SND_SOC_DAIFMT_CBM_CFM); 52 SND_SOC_DAIFMT_CBM_CFM);
52 if (ret) { 53 if (ret) {
53 pr_err("%s: failed set codec dai format\n", __func__); 54 dev_err(cpu_dai->dev,
55 "Failed to set the codec format.\n");
54 return ret; 56 return ret;
55 } 57 }
56 58
57 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 59 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
58 CODEC_CLOCK, SND_SOC_CLOCK_OUT); 60 CODEC_CLOCK, SND_SOC_CLOCK_OUT);
59 if (ret) { 61 if (ret) {
60 pr_err("%s: failed setting codec sysclk\n", __func__); 62 dev_err(cpu_dai->dev,
63 "Failed to set the codec sysclk.\n");
61 return ret; 64 return ret;
62 } 65 }
63 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0); 66 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
@@ -65,7 +68,8 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
65 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0, 68 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
66 SND_SOC_CLOCK_IN); 69 SND_SOC_CLOCK_IN);
67 if (ret) { 70 if (ret) {
68 pr_err("can't set CPU system clock IMX_SSP_SYS_CLK\n"); 71 dev_err(cpu_dai->dev,
72 "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n");
69 return ret; 73 return ret;
70 } 74 }
71 75
@@ -155,7 +159,8 @@ static struct platform_driver eukrea_tlv320_driver = {
155 .owner = THIS_MODULE, 159 .owner = THIS_MODULE,
156 }, 160 },
157 .probe = eukrea_tlv320_probe, 161 .probe = eukrea_tlv320_probe,
158 .remove = eukrea_tlv320_remove,}; 162 .remove = eukrea_tlv320_remove,
163};
159 164
160module_platform_driver(eukrea_tlv320_driver); 165module_platform_driver(eukrea_tlv320_driver);
161 166
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 9cc5c1f82f09..fb9bb9eb5ca3 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -21,6 +21,8 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/gfp.h> 23#include <linux/gfp.h>
24#include <linux/of_address.h>
25#include <linux/of_irq.h>
24#include <linux/of_platform.h> 26#include <linux/of_platform.h>
25#include <linux/list.h> 27#include <linux/list.h>
26#include <linux/slab.h> 28#include <linux/slab.h>
@@ -298,14 +300,11 @@ static int fsl_dma_new(struct snd_soc_pcm_runtime *rtd)
298{ 300{
299 struct snd_card *card = rtd->card->snd_card; 301 struct snd_card *card = rtd->card->snd_card;
300 struct snd_pcm *pcm = rtd->pcm; 302 struct snd_pcm *pcm = rtd->pcm;
301 static u64 fsl_dma_dmamask = DMA_BIT_MASK(36);
302 int ret; 303 int ret;
303 304
304 if (!card->dev->dma_mask) 305 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(36));
305 card->dev->dma_mask = &fsl_dma_dmamask; 306 if (ret)
306 307 return ret;
307 if (!card->dev->coherent_dma_mask)
308 card->dev->coherent_dma_mask = fsl_dma_dmamask;
309 308
310 /* Some codecs have separate DAIs for playback and capture, so we 309 /* Some codecs have separate DAIs for playback and capture, so we
311 * should allocate a DMA buffer only for the streams that are valid. 310 * should allocate a DMA buffer only for the streams that are valid.
diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
index 3920c3e849ce..55193a5596ca 100644
--- a/sound/soc/fsl/fsl_spdif.c
+++ b/sound/soc/fsl/fsl_spdif.c
@@ -963,7 +963,7 @@ static bool fsl_spdif_readable_reg(struct device *dev, unsigned int reg)
963 return true; 963 return true;
964 default: 964 default:
965 return false; 965 return false;
966 }; 966 }
967} 967}
968 968
969static bool fsl_spdif_writeable_reg(struct device *dev, unsigned int reg) 969static bool fsl_spdif_writeable_reg(struct device *dev, unsigned int reg)
@@ -982,7 +982,7 @@ static bool fsl_spdif_writeable_reg(struct device *dev, unsigned int reg)
982 return true; 982 return true;
983 default: 983 default:
984 return false; 984 return false;
985 }; 985 }
986} 986}
987 987
988static const struct regmap_config fsl_spdif_regmap_config = { 988static const struct regmap_config fsl_spdif_regmap_config = {
@@ -1107,11 +1107,6 @@ static int fsl_spdif_probe(struct platform_device *pdev)
1107 1107
1108 /* Get the addresses and IRQ */ 1108 /* Get the addresses and IRQ */
1109 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1109 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1110 if (IS_ERR(res)) {
1111 dev_err(&pdev->dev, "could not determine device resources\n");
1112 return PTR_ERR(res);
1113 }
1114
1115 regs = devm_ioremap_resource(&pdev->dev, res); 1110 regs = devm_ioremap_resource(&pdev->dev, res);
1116 if (IS_ERR(regs)) 1111 if (IS_ERR(regs))
1117 return PTR_ERR(regs); 1112 return PTR_ERR(regs);
@@ -1172,23 +1167,16 @@ static int fsl_spdif_probe(struct platform_device *pdev)
1172 /* Register with ASoC */ 1167 /* Register with ASoC */
1173 dev_set_drvdata(&pdev->dev, spdif_priv); 1168 dev_set_drvdata(&pdev->dev, spdif_priv);
1174 1169
1175 ret = snd_soc_register_component(&pdev->dev, &fsl_spdif_component, 1170 ret = devm_snd_soc_register_component(&pdev->dev, &fsl_spdif_component,
1176 &spdif_priv->cpu_dai_drv, 1); 1171 &spdif_priv->cpu_dai_drv, 1);
1177 if (ret) { 1172 if (ret) {
1178 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret); 1173 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
1179 return ret; 1174 return ret;
1180 } 1175 }
1181 1176
1182 ret = imx_pcm_dma_init(pdev); 1177 ret = imx_pcm_dma_init(pdev);
1183 if (ret) { 1178 if (ret)
1184 dev_err(&pdev->dev, "imx_pcm_dma_init failed: %d\n", ret); 1179 dev_err(&pdev->dev, "imx_pcm_dma_init failed: %d\n", ret);
1185 goto error_component;
1186 }
1187
1188 return ret;
1189
1190error_component:
1191 snd_soc_unregister_component(&pdev->dev);
1192 1180
1193 return ret; 1181 return ret;
1194} 1182}
@@ -1196,7 +1184,6 @@ error_component:
1196static int fsl_spdif_remove(struct platform_device *pdev) 1184static int fsl_spdif_remove(struct platform_device *pdev)
1197{ 1185{
1198 imx_pcm_dma_exit(pdev); 1186 imx_pcm_dma_exit(pdev);
1199 snd_soc_unregister_component(&pdev->dev);
1200 1187
1201 return 0; 1188 return 0;
1202} 1189}
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index c6b743978d5e..35e277379b86 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -469,19 +469,12 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
469 * parameters, then the second stream may be 469 * parameters, then the second stream may be
470 * constrained to the wrong sample rate or size. 470 * constrained to the wrong sample rate or size.
471 */ 471 */
472 if (!first_runtime->sample_bits) { 472 if (first_runtime->sample_bits) {
473 dev_err(substream->pcm->card->dev, 473 snd_pcm_hw_constraint_minmax(substream->runtime,
474 "set sample size in %s stream first\n", 474 SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
475 substream->stream ==
476 SNDRV_PCM_STREAM_PLAYBACK
477 ? "capture" : "playback");
478 return -EAGAIN;
479 }
480
481 snd_pcm_hw_constraint_minmax(substream->runtime,
482 SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
483 first_runtime->sample_bits, 475 first_runtime->sample_bits,
484 first_runtime->sample_bits); 476 first_runtime->sample_bits);
477 }
485 } 478 }
486 479
487 ssi_private->second_stream = substream; 480 ssi_private->second_stream = substream;
@@ -748,7 +741,7 @@ static void fsl_ssi_ac97_init(void)
748 fsl_ssi_setup(fsl_ac97_data); 741 fsl_ssi_setup(fsl_ac97_data);
749} 742}
750 743
751void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg, 744static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
752 unsigned short val) 745 unsigned short val)
753{ 746{
754 struct ccsr_ssi *ssi = fsl_ac97_data->ssi; 747 struct ccsr_ssi *ssi = fsl_ac97_data->ssi;
@@ -770,7 +763,7 @@ void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
770 udelay(100); 763 udelay(100);
771} 764}
772 765
773unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97, 766static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
774 unsigned short reg) 767 unsigned short reg)
775{ 768{
776 struct ccsr_ssi *ssi = fsl_ac97_data->ssi; 769 struct ccsr_ssi *ssi = fsl_ac97_data->ssi;
@@ -936,7 +929,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
936 ssi_private->ssi_phys = res.start; 929 ssi_private->ssi_phys = res.start;
937 930
938 ssi_private->irq = irq_of_parse_and_map(np, 0); 931 ssi_private->irq = irq_of_parse_and_map(np, 0);
939 if (ssi_private->irq == NO_IRQ) { 932 if (!ssi_private->irq) {
940 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); 933 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name);
941 return -ENXIO; 934 return -ENXIO;
942 } 935 }
@@ -1135,7 +1128,6 @@ static int fsl_ssi_remove(struct platform_device *pdev)
1135 if (ssi_private->ssi_on_imx) 1128 if (ssi_private->ssi_on_imx)
1136 imx_pcm_dma_exit(pdev); 1129 imx_pcm_dma_exit(pdev);
1137 snd_soc_unregister_component(&pdev->dev); 1130 snd_soc_unregister_component(&pdev->dev);
1138 dev_set_drvdata(&pdev->dev, NULL);
1139 device_remove_file(&pdev->dev, &ssi_private->dev_attr); 1131 device_remove_file(&pdev->dev, &ssi_private->dev_attr);
1140 if (ssi_private->ssi_on_imx) 1132 if (ssi_private->ssi_on_imx)
1141 clk_disable_unprepare(ssi_private->clk); 1133 clk_disable_unprepare(ssi_private->clk);
diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index d3bf71a0ec56..ac869931d7f1 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -66,13 +66,10 @@ static ssize_t audmux_read_file(struct file *file, char __user *user_buf,
66 size_t count, loff_t *ppos) 66 size_t count, loff_t *ppos)
67{ 67{
68 ssize_t ret; 68 ssize_t ret;
69 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 69 char *buf;
70 int port = (int)file->private_data; 70 int port = (int)file->private_data;
71 u32 pdcr, ptcr; 71 u32 pdcr, ptcr;
72 72
73 if (!buf)
74 return -ENOMEM;
75
76 if (audmux_clk) { 73 if (audmux_clk) {
77 ret = clk_prepare_enable(audmux_clk); 74 ret = clk_prepare_enable(audmux_clk);
78 if (ret) 75 if (ret)
@@ -85,6 +82,10 @@ static ssize_t audmux_read_file(struct file *file, char __user *user_buf,
85 if (audmux_clk) 82 if (audmux_clk)
86 clk_disable_unprepare(audmux_clk); 83 clk_disable_unprepare(audmux_clk);
87 84
85 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
86 if (!buf)
87 return -ENOMEM;
88
88 ret = snprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n", 89 ret = snprintf(buf, PAGE_SIZE, "PDCR: %08x\nPTCR: %08x\n",
89 pdcr, ptcr); 90 pdcr, ptcr);
90 91
diff --git a/sound/soc/fsl/imx-mc13783.c b/sound/soc/fsl/imx-mc13783.c
index a3d60d4bea4c..79cee782dbbf 100644
--- a/sound/soc/fsl/imx-mc13783.c
+++ b/sound/soc/fsl/imx-mc13783.c
@@ -112,7 +112,7 @@ static int imx_mc13783_probe(struct platform_device *pdev)
112 return ret; 112 return ret;
113 } 113 }
114 114
115 if (machine_is_mx31_3ds()) { 115 if (machine_is_mx31_3ds() || machine_is_mx31moboard()) {
116 imx_audmux_v2_configure_port(MX31_AUDMUX_PORT4_SSI_PINS_4, 116 imx_audmux_v2_configure_port(MX31_AUDMUX_PORT4_SSI_PINS_4,
117 IMX_AUDMUX_V2_PTCR_SYN, 117 IMX_AUDMUX_V2_PTCR_SYN,
118 IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0) | 118 IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0) |
@@ -160,6 +160,7 @@ static struct platform_driver imx_mc13783_audio_driver = {
160 .driver = { 160 .driver = {
161 .name = "imx_mc13783", 161 .name = "imx_mc13783",
162 .owner = THIS_MODULE, 162 .owner = THIS_MODULE,
163 .pm = &snd_soc_pm_ops,
163 }, 164 },
164 .probe = imx_mc13783_probe, 165 .probe = imx_mc13783_probe,
165 .remove = imx_mc13783_remove 166 .remove = imx_mc13783_remove
diff --git a/sound/soc/fsl/imx-pcm-dma.c b/sound/soc/fsl/imx-pcm-dma.c
index 4dc1296688e9..aee23077080a 100644
--- a/sound/soc/fsl/imx-pcm-dma.c
+++ b/sound/soc/fsl/imx-pcm-dma.c
@@ -25,12 +25,10 @@
25 25
26static bool filter(struct dma_chan *chan, void *param) 26static bool filter(struct dma_chan *chan, void *param)
27{ 27{
28 struct snd_dmaengine_dai_dma_data *dma_data = param;
29
30 if (!imx_dma_is_general_purpose(chan)) 28 if (!imx_dma_is_general_purpose(chan))
31 return false; 29 return false;
32 30
33 chan->private = dma_data->filter_data; 31 chan->private = param;
34 32
35 return true; 33 return true;
36} 34}
diff --git a/sound/soc/fsl/imx-pcm-fiq.c b/sound/soc/fsl/imx-pcm-fiq.c
index 34043c55f2a6..c75d43bb2e92 100644
--- a/sound/soc/fsl/imx-pcm-fiq.c
+++ b/sound/soc/fsl/imx-pcm-fiq.c
@@ -39,12 +39,11 @@ struct imx_pcm_runtime_data {
39 unsigned int period; 39 unsigned int period;
40 int periods; 40 int periods;
41 unsigned long offset; 41 unsigned long offset;
42 unsigned long last_offset;
43 unsigned long size;
44 struct hrtimer hrt; 42 struct hrtimer hrt;
45 int poll_time_ns; 43 int poll_time_ns;
46 struct snd_pcm_substream *substream; 44 struct snd_pcm_substream *substream;
47 atomic_t running; 45 atomic_t playing;
46 atomic_t capturing;
48}; 47};
49 48
50static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt) 49static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
@@ -52,11 +51,9 @@ static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
52 struct imx_pcm_runtime_data *iprtd = 51 struct imx_pcm_runtime_data *iprtd =
53 container_of(hrt, struct imx_pcm_runtime_data, hrt); 52 container_of(hrt, struct imx_pcm_runtime_data, hrt);
54 struct snd_pcm_substream *substream = iprtd->substream; 53 struct snd_pcm_substream *substream = iprtd->substream;
55 struct snd_pcm_runtime *runtime = substream->runtime;
56 struct pt_regs regs; 54 struct pt_regs regs;
57 unsigned long delta;
58 55
59 if (!atomic_read(&iprtd->running)) 56 if (!atomic_read(&iprtd->playing) && !atomic_read(&iprtd->capturing))
60 return HRTIMER_NORESTART; 57 return HRTIMER_NORESTART;
61 58
62 get_fiq_regs(&regs); 59 get_fiq_regs(&regs);
@@ -66,19 +63,7 @@ static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
66 else 63 else
67 iprtd->offset = regs.ARM_r9 & 0xffff; 64 iprtd->offset = regs.ARM_r9 & 0xffff;
68 65
69 /* How much data have we transferred since the last period report? */ 66 snd_pcm_period_elapsed(substream);
70 if (iprtd->offset >= iprtd->last_offset)
71 delta = iprtd->offset - iprtd->last_offset;
72 else
73 delta = runtime->buffer_size + iprtd->offset
74 - iprtd->last_offset;
75
76 /* If we've transferred at least a period then report it and
77 * reset our poll time */
78 if (delta >= iprtd->period) {
79 snd_pcm_period_elapsed(substream);
80 iprtd->last_offset = iprtd->offset;
81 }
82 67
83 hrtimer_forward_now(hrt, ns_to_ktime(iprtd->poll_time_ns)); 68 hrtimer_forward_now(hrt, ns_to_ktime(iprtd->poll_time_ns));
84 69
@@ -95,11 +80,9 @@ static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,
95 struct snd_pcm_runtime *runtime = substream->runtime; 80 struct snd_pcm_runtime *runtime = substream->runtime;
96 struct imx_pcm_runtime_data *iprtd = runtime->private_data; 81 struct imx_pcm_runtime_data *iprtd = runtime->private_data;
97 82
98 iprtd->size = params_buffer_bytes(params);
99 iprtd->periods = params_periods(params); 83 iprtd->periods = params_periods(params);
100 iprtd->period = params_period_bytes(params) ; 84 iprtd->period = params_period_bytes(params);
101 iprtd->offset = 0; 85 iprtd->offset = 0;
102 iprtd->last_offset = 0;
103 iprtd->poll_time_ns = 1000000000 / params_rate(params) * 86 iprtd->poll_time_ns = 1000000000 / params_rate(params) *
104 params_period_size(params); 87 params_period_size(params);
105 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); 88 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
@@ -124,7 +107,6 @@ static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream)
124 return 0; 107 return 0;
125} 108}
126 109
127static int fiq_enable;
128static int imx_pcm_fiq; 110static int imx_pcm_fiq;
129 111
130static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 112static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -136,23 +118,27 @@ static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
136 case SNDRV_PCM_TRIGGER_START: 118 case SNDRV_PCM_TRIGGER_START:
137 case SNDRV_PCM_TRIGGER_RESUME: 119 case SNDRV_PCM_TRIGGER_RESUME:
138 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 120 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
139 atomic_set(&iprtd->running, 1); 121 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
122 atomic_set(&iprtd->playing, 1);
123 else
124 atomic_set(&iprtd->capturing, 1);
140 hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns), 125 hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns),
141 HRTIMER_MODE_REL); 126 HRTIMER_MODE_REL);
142 if (++fiq_enable == 1) 127 enable_fiq(imx_pcm_fiq);
143 enable_fiq(imx_pcm_fiq);
144
145 break; 128 break;
146 129
147 case SNDRV_PCM_TRIGGER_STOP: 130 case SNDRV_PCM_TRIGGER_STOP:
148 case SNDRV_PCM_TRIGGER_SUSPEND: 131 case SNDRV_PCM_TRIGGER_SUSPEND:
149 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 132 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
150 atomic_set(&iprtd->running, 0); 133 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
151 134 atomic_set(&iprtd->playing, 0);
152 if (--fiq_enable == 0) 135 else
136 atomic_set(&iprtd->capturing, 0);
137 if (!atomic_read(&iprtd->playing) &&
138 !atomic_read(&iprtd->capturing))
153 disable_fiq(imx_pcm_fiq); 139 disable_fiq(imx_pcm_fiq);
154
155 break; 140 break;
141
156 default: 142 default:
157 return -EINVAL; 143 return -EINVAL;
158 } 144 }
@@ -200,7 +186,8 @@ static int snd_imx_open(struct snd_pcm_substream *substream)
200 186
201 iprtd->substream = substream; 187 iprtd->substream = substream;
202 188
203 atomic_set(&iprtd->running, 0); 189 atomic_set(&iprtd->playing, 0);
190 atomic_set(&iprtd->capturing, 0);
204 hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 191 hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
205 iprtd->hrt.function = snd_hrtimer_callback; 192 iprtd->hrt.function = snd_hrtimer_callback;
206 193
@@ -272,18 +259,16 @@ static int imx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
272 return 0; 259 return 0;
273} 260}
274 261
275static u64 imx_pcm_dmamask = DMA_BIT_MASK(32);
276
277static int imx_pcm_new(struct snd_soc_pcm_runtime *rtd) 262static int imx_pcm_new(struct snd_soc_pcm_runtime *rtd)
278{ 263{
279 struct snd_card *card = rtd->card->snd_card; 264 struct snd_card *card = rtd->card->snd_card;
280 struct snd_pcm *pcm = rtd->pcm; 265 struct snd_pcm *pcm = rtd->pcm;
281 int ret = 0; 266 int ret;
267
268 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
269 if (ret)
270 return ret;
282 271
283 if (!card->dev->dma_mask)
284 card->dev->dma_mask = &imx_pcm_dmamask;
285 if (!card->dev->coherent_dma_mask)
286 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
287 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 272 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
288 ret = imx_pcm_preallocate_dma_buffer(pcm, 273 ret = imx_pcm_preallocate_dma_buffer(pcm,
289 SNDRV_PCM_STREAM_PLAYBACK); 274 SNDRV_PCM_STREAM_PLAYBACK);
diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c
index 46c5b4fdfc52..f2beae78969f 100644
--- a/sound/soc/fsl/imx-sgtl5000.c
+++ b/sound/soc/fsl/imx-sgtl5000.c
@@ -62,7 +62,7 @@ static int imx_sgtl5000_probe(struct platform_device *pdev)
62 struct device_node *ssi_np, *codec_np; 62 struct device_node *ssi_np, *codec_np;
63 struct platform_device *ssi_pdev; 63 struct platform_device *ssi_pdev;
64 struct i2c_client *codec_dev; 64 struct i2c_client *codec_dev;
65 struct imx_sgtl5000_data *data; 65 struct imx_sgtl5000_data *data = NULL;
66 int int_port, ext_port; 66 int int_port, ext_port;
67 int ret; 67 int ret;
68 68
@@ -128,7 +128,7 @@ static int imx_sgtl5000_probe(struct platform_device *pdev)
128 goto fail; 128 goto fail;
129 } 129 }
130 130
131 data->codec_clk = devm_clk_get(&codec_dev->dev, NULL); 131 data->codec_clk = clk_get(&codec_dev->dev, NULL);
132 if (IS_ERR(data->codec_clk)) { 132 if (IS_ERR(data->codec_clk)) {
133 ret = PTR_ERR(data->codec_clk); 133 ret = PTR_ERR(data->codec_clk);
134 goto fail; 134 goto fail;
@@ -159,7 +159,7 @@ static int imx_sgtl5000_probe(struct platform_device *pdev)
159 data->card.dapm_widgets = imx_sgtl5000_dapm_widgets; 159 data->card.dapm_widgets = imx_sgtl5000_dapm_widgets;
160 data->card.num_dapm_widgets = ARRAY_SIZE(imx_sgtl5000_dapm_widgets); 160 data->card.num_dapm_widgets = ARRAY_SIZE(imx_sgtl5000_dapm_widgets);
161 161
162 ret = snd_soc_register_card(&data->card); 162 ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
163 if (ret) { 163 if (ret) {
164 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); 164 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
165 goto fail; 165 goto fail;
@@ -172,6 +172,8 @@ static int imx_sgtl5000_probe(struct platform_device *pdev)
172 return 0; 172 return 0;
173 173
174fail: 174fail:
175 if (data && !IS_ERR(data->codec_clk))
176 clk_put(data->codec_clk);
175 if (ssi_np) 177 if (ssi_np)
176 of_node_put(ssi_np); 178 of_node_put(ssi_np);
177 if (codec_np) 179 if (codec_np)
@@ -184,7 +186,7 @@ static int imx_sgtl5000_remove(struct platform_device *pdev)
184{ 186{
185 struct imx_sgtl5000_data *data = platform_get_drvdata(pdev); 187 struct imx_sgtl5000_data *data = platform_get_drvdata(pdev);
186 188
187 snd_soc_unregister_card(&data->card); 189 clk_put(data->codec_clk);
188 190
189 return 0; 191 return 0;
190} 192}
@@ -199,6 +201,7 @@ static struct platform_driver imx_sgtl5000_driver = {
199 .driver = { 201 .driver = {
200 .name = "imx-sgtl5000", 202 .name = "imx-sgtl5000",
201 .owner = THIS_MODULE, 203 .owner = THIS_MODULE,
204 .pm = &snd_soc_pm_ops,
202 .of_match_table = imx_sgtl5000_dt_ids, 205 .of_match_table = imx_sgtl5000_dt_ids,
203 }, 206 },
204 .probe = imx_sgtl5000_probe, 207 .probe = imx_sgtl5000_probe,
diff --git a/sound/soc/fsl/imx-spdif.c b/sound/soc/fsl/imx-spdif.c
index 816013b0ebba..8499d5292f08 100644
--- a/sound/soc/fsl/imx-spdif.c
+++ b/sound/soc/fsl/imx-spdif.c
@@ -87,7 +87,7 @@ static int imx_spdif_audio_probe(struct platform_device *pdev)
87 if (ret) 87 if (ret)
88 goto error_dir; 88 goto error_dir;
89 89
90 ret = snd_soc_register_card(&data->card); 90 ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
91 if (ret) { 91 if (ret) {
92 dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret); 92 dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret);
93 goto error_dir; 93 goto error_dir;
@@ -119,8 +119,6 @@ static int imx_spdif_audio_remove(struct platform_device *pdev)
119 if (data->txdev) 119 if (data->txdev)
120 platform_device_unregister(data->txdev); 120 platform_device_unregister(data->txdev);
121 121
122 snd_soc_unregister_card(&data->card);
123
124 return 0; 122 return 0;
125} 123}
126 124
diff --git a/sound/soc/fsl/imx-ssi.c b/sound/soc/fsl/imx-ssi.c
index f58bcd85c07f..f5f248c91c16 100644
--- a/sound/soc/fsl/imx-ssi.c
+++ b/sound/soc/fsl/imx-ssi.c
@@ -600,22 +600,19 @@ static int imx_ssi_probe(struct platform_device *pdev)
600 ssi->fiq_params.dma_params_rx = &ssi->dma_params_rx; 600 ssi->fiq_params.dma_params_rx = &ssi->dma_params_rx;
601 ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx; 601 ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx;
602 602
603 ret = imx_pcm_fiq_init(pdev, &ssi->fiq_params); 603 ssi->fiq_init = imx_pcm_fiq_init(pdev, &ssi->fiq_params);
604 if (ret) 604 ssi->dma_init = imx_pcm_dma_init(pdev);
605 goto failed_pcm_fiq;
606 605
607 ret = imx_pcm_dma_init(pdev); 606 if (ssi->fiq_init && ssi->dma_init) {
608 if (ret) 607 ret = ssi->fiq_init;
609 goto failed_pcm_dma; 608 goto failed_pcm;
609 }
610 610
611 return 0; 611 return 0;
612 612
613failed_pcm_dma: 613failed_pcm:
614 imx_pcm_fiq_exit(pdev);
615failed_pcm_fiq:
616 snd_soc_unregister_component(&pdev->dev); 614 snd_soc_unregister_component(&pdev->dev);
617failed_register: 615failed_register:
618 release_mem_region(res->start, resource_size(res));
619 clk_disable_unprepare(ssi->clk); 616 clk_disable_unprepare(ssi->clk);
620failed_clk: 617failed_clk:
621 snd_soc_set_ac97_ops(NULL); 618 snd_soc_set_ac97_ops(NULL);
@@ -625,18 +622,19 @@ failed_clk:
625 622
626static int imx_ssi_remove(struct platform_device *pdev) 623static int imx_ssi_remove(struct platform_device *pdev)
627{ 624{
628 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
629 struct imx_ssi *ssi = platform_get_drvdata(pdev); 625 struct imx_ssi *ssi = platform_get_drvdata(pdev);
630 626
631 imx_pcm_dma_exit(pdev); 627 if (!ssi->dma_init)
632 imx_pcm_fiq_exit(pdev); 628 imx_pcm_dma_exit(pdev);
629
630 if (!ssi->fiq_init)
631 imx_pcm_fiq_exit(pdev);
633 632
634 snd_soc_unregister_component(&pdev->dev); 633 snd_soc_unregister_component(&pdev->dev);
635 634
636 if (ssi->flags & IMX_SSI_USE_AC97) 635 if (ssi->flags & IMX_SSI_USE_AC97)
637 ac97_ssi = NULL; 636 ac97_ssi = NULL;
638 637
639 release_mem_region(res->start, resource_size(res));
640 clk_disable_unprepare(ssi->clk); 638 clk_disable_unprepare(ssi->clk);
641 snd_soc_set_ac97_ops(NULL); 639 snd_soc_set_ac97_ops(NULL);
642 640
diff --git a/sound/soc/fsl/imx-ssi.h b/sound/soc/fsl/imx-ssi.h
index fb1616ba8c59..560c40fc9ebb 100644
--- a/sound/soc/fsl/imx-ssi.h
+++ b/sound/soc/fsl/imx-ssi.h
@@ -211,6 +211,8 @@ struct imx_ssi {
211 struct imx_dma_data filter_data_rx; 211 struct imx_dma_data filter_data_rx;
212 struct imx_pcm_fiq_params fiq_params; 212 struct imx_pcm_fiq_params fiq_params;
213 213
214 int fiq_init;
215 int dma_init;
214 int enabled; 216 int enabled;
215}; 217};
216 218
diff --git a/sound/soc/fsl/imx-wm8962.c b/sound/soc/fsl/imx-wm8962.c
index cd106aa39984..61e48852b9e8 100644
--- a/sound/soc/fsl/imx-wm8962.c
+++ b/sound/soc/fsl/imx-wm8962.c
@@ -266,7 +266,7 @@ static int imx_wm8962_probe(struct platform_device *pdev)
266 data->card.late_probe = imx_wm8962_late_probe; 266 data->card.late_probe = imx_wm8962_late_probe;
267 data->card.set_bias_level = imx_wm8962_set_bias_level; 267 data->card.set_bias_level = imx_wm8962_set_bias_level;
268 268
269 ret = snd_soc_register_card(&data->card); 269 ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
270 if (ret) { 270 if (ret) {
271 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); 271 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
272 goto clk_fail; 272 goto clk_fail;
@@ -279,8 +279,7 @@ static int imx_wm8962_probe(struct platform_device *pdev)
279 return 0; 279 return 0;
280 280
281clk_fail: 281clk_fail:
282 if (!IS_ERR(data->codec_clk)) 282 clk_disable_unprepare(data->codec_clk);
283 clk_disable_unprepare(data->codec_clk);
284fail: 283fail:
285 if (ssi_np) 284 if (ssi_np)
286 of_node_put(ssi_np); 285 of_node_put(ssi_np);
@@ -296,7 +295,6 @@ static int imx_wm8962_remove(struct platform_device *pdev)
296 295
297 if (!IS_ERR(data->codec_clk)) 296 if (!IS_ERR(data->codec_clk))
298 clk_disable_unprepare(data->codec_clk); 297 clk_disable_unprepare(data->codec_clk);
299 snd_soc_unregister_card(&data->card);
300 298
301 return 0; 299 return 0;
302} 300}
@@ -311,6 +309,7 @@ static struct platform_driver imx_wm8962_driver = {
311 .driver = { 309 .driver = {
312 .name = "imx-wm8962", 310 .name = "imx-wm8962",
313 .owner = THIS_MODULE, 311 .owner = THIS_MODULE,
312 .pm = &snd_soc_pm_ops,
314 .of_match_table = imx_wm8962_dt_ids, 313 .of_match_table = imx_wm8962_dt_ids,
315 }, 314 },
316 .probe = imx_wm8962_probe, 315 .probe = imx_wm8962_probe,
diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
index 2a847ca494b5..71bf2f248cd4 100644
--- a/sound/soc/fsl/mpc5200_dma.c
+++ b/sound/soc/fsl/mpc5200_dma.c
@@ -10,6 +10,8 @@
10#include <linux/of_device.h> 10#include <linux/of_device.h>
11#include <linux/dma-mapping.h> 11#include <linux/dma-mapping.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/of_address.h>
14#include <linux/of_irq.h>
13#include <linux/of_platform.h> 15#include <linux/of_platform.h>
14 16
15#include <sound/soc.h> 17#include <sound/soc.h>
@@ -299,7 +301,6 @@ static struct snd_pcm_ops psc_dma_ops = {
299 .hw_params = psc_dma_hw_params, 301 .hw_params = psc_dma_hw_params,
300}; 302};
301 303
302static u64 psc_dma_dmamask = DMA_BIT_MASK(32);
303static int psc_dma_new(struct snd_soc_pcm_runtime *rtd) 304static int psc_dma_new(struct snd_soc_pcm_runtime *rtd)
304{ 305{
305 struct snd_card *card = rtd->card->snd_card; 306 struct snd_card *card = rtd->card->snd_card;
@@ -307,15 +308,14 @@ static int psc_dma_new(struct snd_soc_pcm_runtime *rtd)
307 struct snd_pcm *pcm = rtd->pcm; 308 struct snd_pcm *pcm = rtd->pcm;
308 struct psc_dma *psc_dma = snd_soc_dai_get_drvdata(rtd->cpu_dai); 309 struct psc_dma *psc_dma = snd_soc_dai_get_drvdata(rtd->cpu_dai);
309 size_t size = psc_dma_hardware.buffer_bytes_max; 310 size_t size = psc_dma_hardware.buffer_bytes_max;
310 int rc = 0; 311 int rc;
311 312
312 dev_dbg(rtd->platform->dev, "psc_dma_new(card=%p, dai=%p, pcm=%p)\n", 313 dev_dbg(rtd->platform->dev, "psc_dma_new(card=%p, dai=%p, pcm=%p)\n",
313 card, dai, pcm); 314 card, dai, pcm);
314 315
315 if (!card->dev->dma_mask) 316 rc = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
316 card->dev->dma_mask = &psc_dma_dmamask; 317 if (rc)
317 if (!card->dev->coherent_dma_mask) 318 return rc;
318 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
319 319
320 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 320 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
321 rc = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->card->dev, 321 rc = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->card->dev,
diff --git a/sound/soc/fsl/mpc5200_psc_ac97.c b/sound/soc/fsl/mpc5200_psc_ac97.c
index 3ef7a0c92efa..24eafa2cfbf4 100644
--- a/sound/soc/fsl/mpc5200_psc_ac97.c
+++ b/sound/soc/fsl/mpc5200_psc_ac97.c
@@ -291,7 +291,7 @@ static int psc_ac97_of_probe(struct platform_device *op)
291 291
292 rc = snd_soc_set_ac97_ops(&psc_ac97_ops); 292 rc = snd_soc_set_ac97_ops(&psc_ac97_ops);
293 if (rc != 0) { 293 if (rc != 0) {
294 dev_err(&op->dev, "Failed to set AC'97 ops: %d\n", ret); 294 dev_err(&op->dev, "Failed to set AC'97 ops: %d\n", rc);
295 return rc; 295 return rc;
296 } 296 }
297 297
diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c
index 228c52e71440..fa756d05b2f7 100644
--- a/sound/soc/fsl/mpc8610_hpcd.c
+++ b/sound/soc/fsl/mpc8610_hpcd.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/of_address.h>
15#include <linux/of_device.h> 16#include <linux/of_device.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <sound/soc.h> 18#include <sound/soc.h>
diff --git a/sound/soc/fsl/p1022_ds.c b/sound/soc/fsl/p1022_ds.c
index ba59c23a137b..f75c3cf0e6de 100644
--- a/sound/soc/fsl/p1022_ds.c
+++ b/sound/soc/fsl/p1022_ds.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/of_address.h>
15#include <linux/of_device.h> 16#include <linux/of_device.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <sound/soc.h> 18#include <sound/soc.h>
diff --git a/sound/soc/fsl/p1022_rdk.c b/sound/soc/fsl/p1022_rdk.c
index f21551911533..9d89bb028621 100644
--- a/sound/soc/fsl/p1022_rdk.c
+++ b/sound/soc/fsl/p1022_rdk.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/of_address.h>
22#include <linux/of_device.h> 23#include <linux/of_device.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <sound/soc.h> 25#include <sound/soc.h>
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 8c49147db84c..b2fbb7075a6c 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -27,6 +27,11 @@ static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
27 if (!ret && daifmt) 27 if (!ret && daifmt)
28 ret = snd_soc_dai_set_fmt(dai, daifmt); 28 ret = snd_soc_dai_set_fmt(dai, daifmt);
29 29
30 if (ret == -ENOTSUPP) {
31 dev_dbg(dai->dev, "ASoC: set_fmt is not supported\n");
32 ret = 0;
33 }
34
30 if (!ret && set->sysclk) 35 if (!ret && set->sysclk)
31 ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0); 36 ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
32 37
diff --git a/sound/soc/jz4740/jz4740-pcm.c b/sound/soc/jz4740/jz4740-pcm.c
index 710059292318..1d7ef28585e1 100644
--- a/sound/soc/jz4740/jz4740-pcm.c
+++ b/sound/soc/jz4740/jz4740-pcm.c
@@ -297,19 +297,15 @@ static void jz4740_pcm_free(struct snd_pcm *pcm)
297 } 297 }
298} 298}
299 299
300static u64 jz4740_pcm_dmamask = DMA_BIT_MASK(32);
301
302static int jz4740_pcm_new(struct snd_soc_pcm_runtime *rtd) 300static int jz4740_pcm_new(struct snd_soc_pcm_runtime *rtd)
303{ 301{
304 struct snd_card *card = rtd->card->snd_card; 302 struct snd_card *card = rtd->card->snd_card;
305 struct snd_pcm *pcm = rtd->pcm; 303 struct snd_pcm *pcm = rtd->pcm;
306 int ret = 0; 304 int ret;
307
308 if (!card->dev->dma_mask)
309 card->dev->dma_mask = &jz4740_pcm_dmamask;
310 305
311 if (!card->dev->coherent_dma_mask) 306 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
312 card->dev->coherent_dma_mask = DMA_BIT_MASK(32); 307 if (ret)
308 return ret;
313 309
314 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 310 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
315 ret = jz4740_pcm_preallocate_dma_buffer(pcm, 311 ret = jz4740_pcm_preallocate_dma_buffer(pcm,
diff --git a/sound/soc/kirkwood/kirkwood-dma.c b/sound/soc/kirkwood/kirkwood-dma.c
index b238434f92b0..4af1936cf0f4 100644
--- a/sound/soc/kirkwood/kirkwood-dma.c
+++ b/sound/soc/kirkwood/kirkwood-dma.c
@@ -29,9 +29,7 @@
29#define KIRKWOOD_FORMATS \ 29#define KIRKWOOD_FORMATS \
30 (SNDRV_PCM_FMTBIT_S16_LE | \ 30 (SNDRV_PCM_FMTBIT_S16_LE | \
31 SNDRV_PCM_FMTBIT_S24_LE | \ 31 SNDRV_PCM_FMTBIT_S24_LE | \
32 SNDRV_PCM_FMTBIT_S32_LE | \ 32 SNDRV_PCM_FMTBIT_S32_LE)
33 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE | \
34 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE)
35 33
36static struct kirkwood_dma_data *kirkwood_priv(struct snd_pcm_substream *subs) 34static struct kirkwood_dma_data *kirkwood_priv(struct snd_pcm_substream *subs)
37{ 35{
@@ -59,8 +57,6 @@ static struct snd_pcm_hardware kirkwood_dma_snd_hw = {
59 .fifo_size = 0, 57 .fifo_size = 0,
60}; 58};
61 59
62static u64 kirkwood_dma_dmamask = DMA_BIT_MASK(32);
63
64static irqreturn_t kirkwood_dma_irq(int irq, void *dev_id) 60static irqreturn_t kirkwood_dma_irq(int irq, void *dev_id)
65{ 61{
66 struct kirkwood_dma_data *priv = dev_id; 62 struct kirkwood_dma_data *priv = dev_id;
@@ -161,7 +157,7 @@ static int kirkwood_dma_open(struct snd_pcm_substream *substream)
161 * Enable Error interrupts. We're only ack'ing them but 157 * Enable Error interrupts. We're only ack'ing them but
162 * it's useful for diagnostics 158 * it's useful for diagnostics
163 */ 159 */
164 writel((unsigned long)-1, priv->io + KIRKWOOD_ERR_MASK); 160 writel((unsigned int)-1, priv->io + KIRKWOOD_ERR_MASK);
165 } 161 }
166 162
167 dram = mv_mbus_dram_info(); 163 dram = mv_mbus_dram_info();
@@ -292,10 +288,9 @@ static int kirkwood_dma_new(struct snd_soc_pcm_runtime *rtd)
292 struct snd_pcm *pcm = rtd->pcm; 288 struct snd_pcm *pcm = rtd->pcm;
293 int ret; 289 int ret;
294 290
295 if (!card->dev->dma_mask) 291 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
296 card->dev->dma_mask = &kirkwood_dma_dmamask; 292 if (ret)
297 if (!card->dev->coherent_dma_mask) 293 return ret;
298 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
299 294
300 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 295 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
301 ret = kirkwood_dma_preallocate_dma_buffer(pcm, 296 ret = kirkwood_dma_preallocate_dma_buffer(pcm,
diff --git a/sound/soc/kirkwood/kirkwood-i2s.c b/sound/soc/kirkwood/kirkwood-i2s.c
index 0f3d73d4ef48..d34d91743e3f 100644
--- a/sound/soc/kirkwood/kirkwood-i2s.c
+++ b/sound/soc/kirkwood/kirkwood-i2s.c
@@ -103,7 +103,7 @@ static void kirkwood_set_rate(struct snd_soc_dai *dai,
103{ 103{
104 uint32_t clks_ctrl; 104 uint32_t clks_ctrl;
105 105
106 if (rate == 44100 || rate == 48000 || rate == 96000) { 106 if (IS_ERR(priv->extclk)) {
107 /* use internal dco for the supported rates 107 /* use internal dco for the supported rates
108 * defined in kirkwood_i2s_dai */ 108 * defined in kirkwood_i2s_dai */
109 dev_dbg(dai->dev, "%s: dco set rate = %lu\n", 109 dev_dbg(dai->dev, "%s: dco set rate = %lu\n",
@@ -160,9 +160,11 @@ static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream,
160 case SNDRV_PCM_FORMAT_S16_LE: 160 case SNDRV_PCM_FORMAT_S16_LE:
161 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16; 161 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16;
162 ctl_play = KIRKWOOD_PLAYCTL_SIZE_16_C | 162 ctl_play = KIRKWOOD_PLAYCTL_SIZE_16_C |
163 KIRKWOOD_PLAYCTL_I2S_EN; 163 KIRKWOOD_PLAYCTL_I2S_EN |
164 KIRKWOOD_PLAYCTL_SPDIF_EN;
164 ctl_rec = KIRKWOOD_RECCTL_SIZE_16_C | 165 ctl_rec = KIRKWOOD_RECCTL_SIZE_16_C |
165 KIRKWOOD_RECCTL_I2S_EN; 166 KIRKWOOD_RECCTL_I2S_EN |
167 KIRKWOOD_RECCTL_SPDIF_EN;
166 break; 168 break;
167 /* 169 /*
168 * doesn't work... S20_3LE != kirkwood 20bit format ? 170 * doesn't work... S20_3LE != kirkwood 20bit format ?
@@ -178,9 +180,11 @@ static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream,
178 case SNDRV_PCM_FORMAT_S24_LE: 180 case SNDRV_PCM_FORMAT_S24_LE:
179 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24; 181 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24;
180 ctl_play = KIRKWOOD_PLAYCTL_SIZE_24 | 182 ctl_play = KIRKWOOD_PLAYCTL_SIZE_24 |
181 KIRKWOOD_PLAYCTL_I2S_EN; 183 KIRKWOOD_PLAYCTL_I2S_EN |
184 KIRKWOOD_PLAYCTL_SPDIF_EN;
182 ctl_rec = KIRKWOOD_RECCTL_SIZE_24 | 185 ctl_rec = KIRKWOOD_RECCTL_SIZE_24 |
183 KIRKWOOD_RECCTL_I2S_EN; 186 KIRKWOOD_RECCTL_I2S_EN |
187 KIRKWOOD_RECCTL_SPDIF_EN;
184 break; 188 break;
185 case SNDRV_PCM_FORMAT_S32_LE: 189 case SNDRV_PCM_FORMAT_S32_LE:
186 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32; 190 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32;
@@ -240,6 +244,11 @@ static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream,
240 ctl); 244 ctl);
241 } 245 }
242 246
247 if (dai->id == 0)
248 ctl &= ~KIRKWOOD_PLAYCTL_SPDIF_EN; /* i2s */
249 else
250 ctl &= ~KIRKWOOD_PLAYCTL_I2S_EN; /* spdif */
251
243 switch (cmd) { 252 switch (cmd) {
244 case SNDRV_PCM_TRIGGER_START: 253 case SNDRV_PCM_TRIGGER_START:
245 /* configure */ 254 /* configure */
@@ -258,7 +267,8 @@ static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream,
258 267
259 case SNDRV_PCM_TRIGGER_STOP: 268 case SNDRV_PCM_TRIGGER_STOP:
260 /* stop audio, disable interrupts */ 269 /* stop audio, disable interrupts */
261 ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE; 270 ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
271 KIRKWOOD_PLAYCTL_SPDIF_MUTE;
262 writel(ctl, priv->io + KIRKWOOD_PLAYCTL); 272 writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
263 273
264 value = readl(priv->io + KIRKWOOD_INT_MASK); 274 value = readl(priv->io + KIRKWOOD_INT_MASK);
@@ -272,13 +282,15 @@ static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream,
272 282
273 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 283 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
274 case SNDRV_PCM_TRIGGER_SUSPEND: 284 case SNDRV_PCM_TRIGGER_SUSPEND:
275 ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE; 285 ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
286 KIRKWOOD_PLAYCTL_SPDIF_MUTE;
276 writel(ctl, priv->io + KIRKWOOD_PLAYCTL); 287 writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
277 break; 288 break;
278 289
279 case SNDRV_PCM_TRIGGER_RESUME: 290 case SNDRV_PCM_TRIGGER_RESUME:
280 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 291 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
281 ctl &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE); 292 ctl &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
293 KIRKWOOD_PLAYCTL_SPDIF_MUTE);
282 writel(ctl, priv->io + KIRKWOOD_PLAYCTL); 294 writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
283 break; 295 break;
284 296
@@ -301,7 +313,13 @@ static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream,
301 case SNDRV_PCM_TRIGGER_START: 313 case SNDRV_PCM_TRIGGER_START:
302 /* configure */ 314 /* configure */
303 ctl = priv->ctl_rec; 315 ctl = priv->ctl_rec;
304 value = ctl & ~KIRKWOOD_RECCTL_I2S_EN; 316 if (dai->id == 0)
317 ctl &= ~KIRKWOOD_RECCTL_SPDIF_EN; /* i2s */
318 else
319 ctl &= ~KIRKWOOD_RECCTL_I2S_EN; /* spdif */
320
321 value = ctl & ~(KIRKWOOD_RECCTL_I2S_EN |
322 KIRKWOOD_RECCTL_SPDIF_EN);
305 writel(value, priv->io + KIRKWOOD_RECCTL); 323 writel(value, priv->io + KIRKWOOD_RECCTL);
306 324
307 /* enable interrupts */ 325 /* enable interrupts */
@@ -361,9 +379,8 @@ static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
361 return 0; 379 return 0;
362} 380}
363 381
364static int kirkwood_i2s_probe(struct snd_soc_dai *dai) 382static int kirkwood_i2s_init(struct kirkwood_dma_data *priv)
365{ 383{
366 struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
367 unsigned long value; 384 unsigned long value;
368 unsigned int reg_data; 385 unsigned int reg_data;
369 386
@@ -404,9 +421,10 @@ static const struct snd_soc_dai_ops kirkwood_i2s_dai_ops = {
404 .set_fmt = kirkwood_i2s_set_fmt, 421 .set_fmt = kirkwood_i2s_set_fmt,
405}; 422};
406 423
407 424static struct snd_soc_dai_driver kirkwood_i2s_dai[2] = {
408static struct snd_soc_dai_driver kirkwood_i2s_dai = { 425 {
409 .probe = kirkwood_i2s_probe, 426 .name = "i2s",
427 .id = 0,
410 .playback = { 428 .playback = {
411 .channels_min = 1, 429 .channels_min = 1,
412 .channels_max = 2, 430 .channels_max = 2,
@@ -422,10 +440,53 @@ static struct snd_soc_dai_driver kirkwood_i2s_dai = {
422 .formats = KIRKWOOD_I2S_FORMATS, 440 .formats = KIRKWOOD_I2S_FORMATS,
423 }, 441 },
424 .ops = &kirkwood_i2s_dai_ops, 442 .ops = &kirkwood_i2s_dai_ops,
443 },
444 {
445 .name = "spdif",
446 .id = 1,
447 .playback = {
448 .channels_min = 1,
449 .channels_max = 2,
450 .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
451 SNDRV_PCM_RATE_96000,
452 .formats = KIRKWOOD_I2S_FORMATS,
453 },
454 .capture = {
455 .channels_min = 1,
456 .channels_max = 2,
457 .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
458 SNDRV_PCM_RATE_96000,
459 .formats = KIRKWOOD_I2S_FORMATS,
460 },
461 .ops = &kirkwood_i2s_dai_ops,
462 },
425}; 463};
426 464
427static struct snd_soc_dai_driver kirkwood_i2s_dai_extclk = { 465static struct snd_soc_dai_driver kirkwood_i2s_dai_extclk[2] = {
428 .probe = kirkwood_i2s_probe, 466 {
467 .name = "i2s",
468 .id = 0,
469 .playback = {
470 .channels_min = 1,
471 .channels_max = 2,
472 .rates = SNDRV_PCM_RATE_8000_192000 |
473 SNDRV_PCM_RATE_CONTINUOUS |
474 SNDRV_PCM_RATE_KNOT,
475 .formats = KIRKWOOD_I2S_FORMATS,
476 },
477 .capture = {
478 .channels_min = 1,
479 .channels_max = 2,
480 .rates = SNDRV_PCM_RATE_8000_192000 |
481 SNDRV_PCM_RATE_CONTINUOUS |
482 SNDRV_PCM_RATE_KNOT,
483 .formats = KIRKWOOD_I2S_FORMATS,
484 },
485 .ops = &kirkwood_i2s_dai_ops,
486 },
487 {
488 .name = "spdif",
489 .id = 1,
429 .playback = { 490 .playback = {
430 .channels_min = 1, 491 .channels_min = 1,
431 .channels_max = 2, 492 .channels_max = 2,
@@ -443,6 +504,7 @@ static struct snd_soc_dai_driver kirkwood_i2s_dai_extclk = {
443 .formats = KIRKWOOD_I2S_FORMATS, 504 .formats = KIRKWOOD_I2S_FORMATS,
444 }, 505 },
445 .ops = &kirkwood_i2s_dai_ops, 506 .ops = &kirkwood_i2s_dai_ops,
507 },
446}; 508};
447 509
448static const struct snd_soc_component_driver kirkwood_i2s_component = { 510static const struct snd_soc_component_driver kirkwood_i2s_component = {
@@ -452,7 +514,7 @@ static const struct snd_soc_component_driver kirkwood_i2s_component = {
452static int kirkwood_i2s_dev_probe(struct platform_device *pdev) 514static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
453{ 515{
454 struct kirkwood_asoc_platform_data *data = pdev->dev.platform_data; 516 struct kirkwood_asoc_platform_data *data = pdev->dev.platform_data;
455 struct snd_soc_dai_driver *soc_dai = &kirkwood_i2s_dai; 517 struct snd_soc_dai_driver *soc_dai = kirkwood_i2s_dai;
456 struct kirkwood_dma_data *priv; 518 struct kirkwood_dma_data *priv;
457 struct resource *mem; 519 struct resource *mem;
458 struct device_node *np = pdev->dev.of_node; 520 struct device_node *np = pdev->dev.of_node;
@@ -496,14 +558,17 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
496 return err; 558 return err;
497 559
498 priv->extclk = devm_clk_get(&pdev->dev, "extclk"); 560 priv->extclk = devm_clk_get(&pdev->dev, "extclk");
499 if (!IS_ERR(priv->extclk)) { 561 if (IS_ERR(priv->extclk)) {
562 if (PTR_ERR(priv->extclk) == -EPROBE_DEFER)
563 return -EPROBE_DEFER;
564 } else {
500 if (priv->extclk == priv->clk) { 565 if (priv->extclk == priv->clk) {
501 devm_clk_put(&pdev->dev, priv->extclk); 566 devm_clk_put(&pdev->dev, priv->extclk);
502 priv->extclk = ERR_PTR(-EINVAL); 567 priv->extclk = ERR_PTR(-EINVAL);
503 } else { 568 } else {
504 dev_info(&pdev->dev, "found external clock\n"); 569 dev_info(&pdev->dev, "found external clock\n");
505 clk_prepare_enable(priv->extclk); 570 clk_prepare_enable(priv->extclk);
506 soc_dai = &kirkwood_i2s_dai_extclk; 571 soc_dai = kirkwood_i2s_dai_extclk;
507 } 572 }
508 } 573 }
509 574
@@ -521,7 +586,7 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
521 } 586 }
522 587
523 err = snd_soc_register_component(&pdev->dev, &kirkwood_i2s_component, 588 err = snd_soc_register_component(&pdev->dev, &kirkwood_i2s_component,
524 soc_dai, 1); 589 soc_dai, 2);
525 if (err) { 590 if (err) {
526 dev_err(&pdev->dev, "snd_soc_register_component failed\n"); 591 dev_err(&pdev->dev, "snd_soc_register_component failed\n");
527 goto err_component; 592 goto err_component;
@@ -532,6 +597,9 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
532 dev_err(&pdev->dev, "snd_soc_register_platform failed\n"); 597 dev_err(&pdev->dev, "snd_soc_register_platform failed\n");
533 goto err_platform; 598 goto err_platform;
534 } 599 }
600
601 kirkwood_i2s_init(priv);
602
535 return 0; 603 return 0;
536 err_platform: 604 err_platform:
537 snd_soc_unregister_component(&pdev->dev); 605 snd_soc_unregister_component(&pdev->dev);
diff --git a/sound/soc/kirkwood/kirkwood-openrd.c b/sound/soc/kirkwood/kirkwood-openrd.c
index 025be0e97164..65f2a5b9ec3b 100644
--- a/sound/soc/kirkwood/kirkwood-openrd.c
+++ b/sound/soc/kirkwood/kirkwood-openrd.c
@@ -52,7 +52,7 @@ static struct snd_soc_dai_link openrd_client_dai[] = {
52{ 52{
53 .name = "CS42L51", 53 .name = "CS42L51",
54 .stream_name = "CS42L51 HiFi", 54 .stream_name = "CS42L51 HiFi",
55 .cpu_dai_name = "mvebu-audio", 55 .cpu_dai_name = "i2s",
56 .platform_name = "mvebu-audio", 56 .platform_name = "mvebu-audio",
57 .codec_dai_name = "cs42l51-hifi", 57 .codec_dai_name = "cs42l51-hifi",
58 .codec_name = "cs42l51-codec.0-004a", 58 .codec_name = "cs42l51-codec.0-004a",
diff --git a/sound/soc/kirkwood/kirkwood-t5325.c b/sound/soc/kirkwood/kirkwood-t5325.c
index 27545b0c4856..d213832b0c72 100644
--- a/sound/soc/kirkwood/kirkwood-t5325.c
+++ b/sound/soc/kirkwood/kirkwood-t5325.c
@@ -68,7 +68,7 @@ static struct snd_soc_dai_link t5325_dai[] = {
68{ 68{
69 .name = "ALC5621", 69 .name = "ALC5621",
70 .stream_name = "ALC5621 HiFi", 70 .stream_name = "ALC5621 HiFi",
71 .cpu_dai_name = "mvebu-audio", 71 .cpu_dai_name = "i2s",
72 .platform_name = "mvebu-audio", 72 .platform_name = "mvebu-audio",
73 .codec_dai_name = "alc5621-hifi", 73 .codec_dai_name = "alc5621-hifi",
74 .codec_name = "alc562x-codec.0-001a", 74 .codec_name = "alc562x-codec.0-001a",
diff --git a/sound/soc/kirkwood/kirkwood.h b/sound/soc/kirkwood/kirkwood.h
index f8e1ccc1c58c..bf23afbba1d7 100644
--- a/sound/soc/kirkwood/kirkwood.h
+++ b/sound/soc/kirkwood/kirkwood.h
@@ -123,8 +123,8 @@
123/* need to find where they come from */ 123/* need to find where they come from */
124#define KIRKWOOD_SND_MIN_PERIODS 8 124#define KIRKWOOD_SND_MIN_PERIODS 8
125#define KIRKWOOD_SND_MAX_PERIODS 16 125#define KIRKWOOD_SND_MAX_PERIODS 16
126#define KIRKWOOD_SND_MIN_PERIOD_BYTES 0x4000 126#define KIRKWOOD_SND_MIN_PERIOD_BYTES 0x800
127#define KIRKWOOD_SND_MAX_PERIOD_BYTES 0x4000 127#define KIRKWOOD_SND_MAX_PERIOD_BYTES 0x8000
128#define KIRKWOOD_SND_MAX_BUFFER_BYTES (KIRKWOOD_SND_MAX_PERIOD_BYTES \ 128#define KIRKWOOD_SND_MAX_BUFFER_BYTES (KIRKWOOD_SND_MAX_PERIOD_BYTES \
129 * KIRKWOOD_SND_MAX_PERIODS) 129 * KIRKWOOD_SND_MAX_PERIODS)
130 130
diff --git a/sound/soc/mid-x86/mfld_machine.c b/sound/soc/mid-x86/mfld_machine.c
index ee363845759e..d3d4c32434f7 100644
--- a/sound/soc/mid-x86/mfld_machine.c
+++ b/sound/soc/mid-x86/mfld_machine.c
@@ -400,7 +400,7 @@ static int snd_mfld_mc_probe(struct platform_device *pdev)
400 } 400 }
401 /* register the soc card */ 401 /* register the soc card */
402 snd_soc_card_mfld.dev = &pdev->dev; 402 snd_soc_card_mfld.dev = &pdev->dev;
403 ret_val = snd_soc_register_card(&snd_soc_card_mfld); 403 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_mfld);
404 if (ret_val) { 404 if (ret_val) {
405 pr_debug("snd_soc_register_card failed %d\n", ret_val); 405 pr_debug("snd_soc_register_card failed %d\n", ret_val);
406 return ret_val; 406 return ret_val;
@@ -410,20 +410,12 @@ static int snd_mfld_mc_probe(struct platform_device *pdev)
410 return 0; 410 return 0;
411} 411}
412 412
413static int snd_mfld_mc_remove(struct platform_device *pdev)
414{
415 pr_debug("snd_mfld_mc_remove called\n");
416 snd_soc_unregister_card(&snd_soc_card_mfld);
417 return 0;
418}
419
420static struct platform_driver snd_mfld_mc_driver = { 413static struct platform_driver snd_mfld_mc_driver = {
421 .driver = { 414 .driver = {
422 .owner = THIS_MODULE, 415 .owner = THIS_MODULE,
423 .name = "msic_audio", 416 .name = "msic_audio",
424 }, 417 },
425 .probe = snd_mfld_mc_probe, 418 .probe = snd_mfld_mc_probe,
426 .remove = snd_mfld_mc_remove,
427}; 419};
428 420
429module_platform_driver(snd_mfld_mc_driver); 421module_platform_driver(snd_mfld_mc_driver);
diff --git a/sound/soc/mid-x86/sst_platform.c b/sound/soc/mid-x86/sst_platform.c
index 392fc0b8f5b8..b6b5eb698d33 100644
--- a/sound/soc/mid-x86/sst_platform.c
+++ b/sound/soc/mid-x86/sst_platform.c
@@ -40,7 +40,8 @@ static DEFINE_MUTEX(sst_lock);
40 40
41int sst_register_dsp(struct sst_device *dev) 41int sst_register_dsp(struct sst_device *dev)
42{ 42{
43 BUG_ON(!dev); 43 if (WARN_ON(!dev))
44 return -EINVAL;
44 if (!try_module_get(dev->dev->driver->owner)) 45 if (!try_module_get(dev->dev->driver->owner))
45 return -ENODEV; 46 return -ENODEV;
46 mutex_lock(&sst_lock); 47 mutex_lock(&sst_lock);
@@ -59,7 +60,8 @@ EXPORT_SYMBOL_GPL(sst_register_dsp);
59 60
60int sst_unregister_dsp(struct sst_device *dev) 61int sst_unregister_dsp(struct sst_device *dev)
61{ 62{
62 BUG_ON(!dev); 63 if (WARN_ON(!dev))
64 return -EINVAL;
63 if (dev != sst) 65 if (dev != sst)
64 return -EINVAL; 66 return -EINVAL;
65 67
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index b56b8a0e8deb..54e622acac33 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -494,6 +494,7 @@ static int mxs_saif_trigger(struct snd_pcm_substream *substream, int cmd,
494 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); 494 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
495 struct mxs_saif *master_saif; 495 struct mxs_saif *master_saif;
496 u32 delay; 496 u32 delay;
497 int ret;
497 498
498 master_saif = mxs_saif_get_master(saif); 499 master_saif = mxs_saif_get_master(saif);
499 if (!master_saif) 500 if (!master_saif)
@@ -503,23 +504,37 @@ static int mxs_saif_trigger(struct snd_pcm_substream *substream, int cmd,
503 case SNDRV_PCM_TRIGGER_START: 504 case SNDRV_PCM_TRIGGER_START:
504 case SNDRV_PCM_TRIGGER_RESUME: 505 case SNDRV_PCM_TRIGGER_RESUME:
505 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 506 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
507 if (saif->state == MXS_SAIF_STATE_RUNNING)
508 return 0;
509
506 dev_dbg(cpu_dai->dev, "start\n"); 510 dev_dbg(cpu_dai->dev, "start\n");
507 511
508 clk_enable(master_saif->clk); 512 ret = clk_enable(master_saif->clk);
509 if (!master_saif->mclk_in_use) 513 if (ret) {
510 __raw_writel(BM_SAIF_CTRL_RUN, 514 dev_err(saif->dev, "Failed to enable master clock\n");
511 master_saif->base + SAIF_CTRL + MXS_SET_ADDR); 515 return ret;
516 }
512 517
513 /* 518 /*
514 * If the saif's master is not himself, we also need to enable 519 * If the saif's master is not himself, we also need to enable
515 * itself clk for its internal basic logic to work. 520 * itself clk for its internal basic logic to work.
516 */ 521 */
517 if (saif != master_saif) { 522 if (saif != master_saif) {
518 clk_enable(saif->clk); 523 ret = clk_enable(saif->clk);
524 if (ret) {
525 dev_err(saif->dev, "Failed to enable master clock\n");
526 clk_disable(master_saif->clk);
527 return ret;
528 }
529
519 __raw_writel(BM_SAIF_CTRL_RUN, 530 __raw_writel(BM_SAIF_CTRL_RUN,
520 saif->base + SAIF_CTRL + MXS_SET_ADDR); 531 saif->base + SAIF_CTRL + MXS_SET_ADDR);
521 } 532 }
522 533
534 if (!master_saif->mclk_in_use)
535 __raw_writel(BM_SAIF_CTRL_RUN,
536 master_saif->base + SAIF_CTRL + MXS_SET_ADDR);
537
523 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 538 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
524 /* 539 /*
525 * write data to saif data register to trigger 540 * write data to saif data register to trigger
@@ -543,6 +558,7 @@ static int mxs_saif_trigger(struct snd_pcm_substream *substream, int cmd,
543 } 558 }
544 559
545 master_saif->ongoing = 1; 560 master_saif->ongoing = 1;
561 saif->state = MXS_SAIF_STATE_RUNNING;
546 562
547 dev_dbg(saif->dev, "CTRL 0x%x STAT 0x%x\n", 563 dev_dbg(saif->dev, "CTRL 0x%x STAT 0x%x\n",
548 __raw_readl(saif->base + SAIF_CTRL), 564 __raw_readl(saif->base + SAIF_CTRL),
@@ -555,6 +571,9 @@ static int mxs_saif_trigger(struct snd_pcm_substream *substream, int cmd,
555 case SNDRV_PCM_TRIGGER_SUSPEND: 571 case SNDRV_PCM_TRIGGER_SUSPEND:
556 case SNDRV_PCM_TRIGGER_STOP: 572 case SNDRV_PCM_TRIGGER_STOP:
557 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 573 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
574 if (saif->state == MXS_SAIF_STATE_STOPPED)
575 return 0;
576
558 dev_dbg(cpu_dai->dev, "stop\n"); 577 dev_dbg(cpu_dai->dev, "stop\n");
559 578
560 /* wait a while for the current sample to complete */ 579 /* wait a while for the current sample to complete */
@@ -575,6 +594,7 @@ static int mxs_saif_trigger(struct snd_pcm_substream *substream, int cmd,
575 } 594 }
576 595
577 master_saif->ongoing = 0; 596 master_saif->ongoing = 0;
597 saif->state = MXS_SAIF_STATE_STOPPED;
578 598
579 break; 599 break;
580 default: 600 default:
@@ -768,8 +788,8 @@ static int mxs_saif_probe(struct platform_device *pdev)
768 dev_warn(&pdev->dev, "failed to init clocks\n"); 788 dev_warn(&pdev->dev, "failed to init clocks\n");
769 } 789 }
770 790
771 ret = snd_soc_register_component(&pdev->dev, &mxs_saif_component, 791 ret = devm_snd_soc_register_component(&pdev->dev, &mxs_saif_component,
772 &mxs_saif_dai, 1); 792 &mxs_saif_dai, 1);
773 if (ret) { 793 if (ret) {
774 dev_err(&pdev->dev, "register DAI failed\n"); 794 dev_err(&pdev->dev, "register DAI failed\n");
775 return ret; 795 return ret;
@@ -778,21 +798,15 @@ static int mxs_saif_probe(struct platform_device *pdev)
778 ret = mxs_pcm_platform_register(&pdev->dev); 798 ret = mxs_pcm_platform_register(&pdev->dev);
779 if (ret) { 799 if (ret) {
780 dev_err(&pdev->dev, "register PCM failed: %d\n", ret); 800 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
781 goto failed_pdev_alloc; 801 return ret;
782 } 802 }
783 803
784 return 0; 804 return 0;
785
786failed_pdev_alloc:
787 snd_soc_unregister_component(&pdev->dev);
788
789 return ret;
790} 805}
791 806
792static int mxs_saif_remove(struct platform_device *pdev) 807static int mxs_saif_remove(struct platform_device *pdev)
793{ 808{
794 mxs_pcm_platform_unregister(&pdev->dev); 809 mxs_pcm_platform_unregister(&pdev->dev);
795 snd_soc_unregister_component(&pdev->dev);
796 810
797 return 0; 811 return 0;
798} 812}
diff --git a/sound/soc/mxs/mxs-saif.h b/sound/soc/mxs/mxs-saif.h
index 53eaa4bf0e27..fbaf7badfdfb 100644
--- a/sound/soc/mxs/mxs-saif.h
+++ b/sound/soc/mxs/mxs-saif.h
@@ -124,6 +124,11 @@ struct mxs_saif {
124 124
125 u32 fifo_underrun; 125 u32 fifo_underrun;
126 u32 fifo_overrun; 126 u32 fifo_overrun;
127
128 enum {
129 MXS_SAIF_STATE_STOPPED,
130 MXS_SAIF_STATE_RUNNING,
131 } state;
127}; 132};
128 133
129extern int mxs_saif_put_mclk(unsigned int saif_id); 134extern int mxs_saif_put_mclk(unsigned int saif_id);
diff --git a/sound/soc/mxs/mxs-sgtl5000.c b/sound/soc/mxs/mxs-sgtl5000.c
index 4bb273786ff3..61822cc53bd3 100644
--- a/sound/soc/mxs/mxs-sgtl5000.c
+++ b/sound/soc/mxs/mxs-sgtl5000.c
@@ -122,14 +122,12 @@ static struct snd_soc_card mxs_sgtl5000 = {
122 .num_links = ARRAY_SIZE(mxs_sgtl5000_dai), 122 .num_links = ARRAY_SIZE(mxs_sgtl5000_dai),
123}; 123};
124 124
125static int mxs_sgtl5000_probe_dt(struct platform_device *pdev) 125static int mxs_sgtl5000_probe(struct platform_device *pdev)
126{ 126{
127 struct snd_soc_card *card = &mxs_sgtl5000;
128 int ret, i;
127 struct device_node *np = pdev->dev.of_node; 129 struct device_node *np = pdev->dev.of_node;
128 struct device_node *saif_np[2], *codec_np; 130 struct device_node *saif_np[2], *codec_np;
129 int i;
130
131 if (!np)
132 return 1; /* no device tree */
133 131
134 saif_np[0] = of_parse_phandle(np, "saif-controllers", 0); 132 saif_np[0] = of_parse_phandle(np, "saif-controllers", 0);
135 saif_np[1] = of_parse_phandle(np, "saif-controllers", 1); 133 saif_np[1] = of_parse_phandle(np, "saif-controllers", 1);
@@ -152,18 +150,6 @@ static int mxs_sgtl5000_probe_dt(struct platform_device *pdev)
152 of_node_put(saif_np[0]); 150 of_node_put(saif_np[0]);
153 of_node_put(saif_np[1]); 151 of_node_put(saif_np[1]);
154 152
155 return 0;
156}
157
158static int mxs_sgtl5000_probe(struct platform_device *pdev)
159{
160 struct snd_soc_card *card = &mxs_sgtl5000;
161 int ret;
162
163 ret = mxs_sgtl5000_probe_dt(pdev);
164 if (ret < 0)
165 return ret;
166
167 /* 153 /*
168 * Set an init clock(11.28Mhz) for sgtl5000 initialization(i2c r/w). 154 * Set an init clock(11.28Mhz) for sgtl5000 initialization(i2c r/w).
169 * The Sgtl5000 sysclk is derived from saif0 mclk and it's range 155 * The Sgtl5000 sysclk is derived from saif0 mclk and it's range
diff --git a/sound/soc/nuc900/nuc900-pcm.c b/sound/soc/nuc900/nuc900-pcm.c
index c894ff0f2580..f588ee45b4fd 100644
--- a/sound/soc/nuc900/nuc900-pcm.c
+++ b/sound/soc/nuc900/nuc900-pcm.c
@@ -314,16 +314,15 @@ static void nuc900_dma_free_dma_buffers(struct snd_pcm *pcm)
314 snd_pcm_lib_preallocate_free_for_all(pcm); 314 snd_pcm_lib_preallocate_free_for_all(pcm);
315} 315}
316 316
317static u64 nuc900_pcm_dmamask = DMA_BIT_MASK(32);
318static int nuc900_dma_new(struct snd_soc_pcm_runtime *rtd) 317static int nuc900_dma_new(struct snd_soc_pcm_runtime *rtd)
319{ 318{
320 struct snd_card *card = rtd->card->snd_card; 319 struct snd_card *card = rtd->card->snd_card;
321 struct snd_pcm *pcm = rtd->pcm; 320 struct snd_pcm *pcm = rtd->pcm;
321 int ret;
322 322
323 if (!card->dev->dma_mask) 323 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
324 card->dev->dma_mask = &nuc900_pcm_dmamask; 324 if (ret)
325 if (!card->dev->coherent_dma_mask) 325 return ret;
326 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
327 326
328 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 327 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
329 card->dev, 4 * 1024, (4 * 1024) - 1); 328 card->dev, 4 * 1024, (4 * 1024) - 1);
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index daa78a0095fa..4a07f7179690 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -1,6 +1,6 @@
1config SND_OMAP_SOC 1config SND_OMAP_SOC
2 tristate "SoC Audio for the Texas Instruments OMAP chips" 2 tristate "SoC Audio for the Texas Instruments OMAP chips"
3 depends on (ARCH_OMAP && DMA_OMAP) || (ARCH_ARM && COMPILE_TEST) 3 depends on (ARCH_OMAP && DMA_OMAP) || (ARM && COMPILE_TEST)
4 select SND_DMAENGINE_PCM 4 select SND_DMAENGINE_PCM
5 5
6config SND_OMAP_SOC_DMIC 6config SND_OMAP_SOC_DMIC
@@ -26,7 +26,7 @@ config SND_OMAP_SOC_N810
26 26
27config SND_OMAP_SOC_RX51 27config SND_OMAP_SOC_RX51
28 tristate "SoC Audio support for Nokia RX-51" 28 tristate "SoC Audio support for Nokia RX-51"
29 depends on SND_OMAP_SOC && ARCH_ARM && (MACH_NOKIA_RX51 || COMPILE_TEST) 29 depends on SND_OMAP_SOC && ARM && (MACH_NOKIA_RX51 || COMPILE_TEST)
30 select SND_OMAP_SOC_MCBSP 30 select SND_OMAP_SOC_MCBSP
31 select SND_SOC_TLV320AIC3X 31 select SND_SOC_TLV320AIC3X
32 select SND_SOC_TPA6130A2 32 select SND_SOC_TPA6130A2
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
index 5e8d640d314f..6d216cb6c19b 100644
--- a/sound/soc/omap/n810.c
+++ b/sound/soc/omap/n810.c
@@ -344,8 +344,11 @@ static int __init n810_soc_init(void)
344 clk_set_parent(sys_clkout2_src, func96m_clk); 344 clk_set_parent(sys_clkout2_src, func96m_clk);
345 clk_set_rate(sys_clkout2, 12000000); 345 clk_set_rate(sys_clkout2, 12000000);
346 346
347 BUG_ON((gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) || 347 if (WARN_ON((gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) ||
348 (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0)); 348 (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0))) {
349 err = -EINVAL;
350 goto err4;
351 }
349 352
350 gpio_direction_output(N810_HEADSET_AMP_GPIO, 0); 353 gpio_direction_output(N810_HEADSET_AMP_GPIO, 0);
351 gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0); 354 gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0);
diff --git a/sound/soc/omap/omap-mcpdm.c b/sound/soc/omap/omap-mcpdm.c
index 90d2a7cd2563..cd9ee167959d 100644
--- a/sound/soc/omap/omap-mcpdm.c
+++ b/sound/soc/omap/omap-mcpdm.c
@@ -490,14 +490,9 @@ static int asoc_mcpdm_probe(struct platform_device *pdev)
490 490
491 mcpdm->dev = &pdev->dev; 491 mcpdm->dev = &pdev->dev;
492 492
493 return snd_soc_register_component(&pdev->dev, &omap_mcpdm_component, 493 return devm_snd_soc_register_component(&pdev->dev,
494 &omap_mcpdm_dai, 1); 494 &omap_mcpdm_component,
495} 495 &omap_mcpdm_dai, 1);
496
497static int asoc_mcpdm_remove(struct platform_device *pdev)
498{
499 snd_soc_unregister_component(&pdev->dev);
500 return 0;
501} 496}
502 497
503static const struct of_device_id omap_mcpdm_of_match[] = { 498static const struct of_device_id omap_mcpdm_of_match[] = {
@@ -514,7 +509,6 @@ static struct platform_driver asoc_mcpdm_driver = {
514 }, 509 },
515 510
516 .probe = asoc_mcpdm_probe, 511 .probe = asoc_mcpdm_probe,
517 .remove = asoc_mcpdm_remove,
518}; 512};
519 513
520module_platform_driver(asoc_mcpdm_driver); 514module_platform_driver(asoc_mcpdm_driver);
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c
index a11405de86e8..b8fa9862e54c 100644
--- a/sound/soc/omap/omap-pcm.c
+++ b/sound/soc/omap/omap-pcm.c
@@ -156,8 +156,6 @@ static struct snd_pcm_ops omap_pcm_ops = {
156 .mmap = omap_pcm_mmap, 156 .mmap = omap_pcm_mmap,
157}; 157};
158 158
159static u64 omap_pcm_dmamask = DMA_BIT_MASK(64);
160
161static int omap_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, 159static int omap_pcm_preallocate_dma_buffer(struct snd_pcm *pcm,
162 int stream) 160 int stream)
163{ 161{
@@ -202,12 +200,11 @@ static int omap_pcm_new(struct snd_soc_pcm_runtime *rtd)
202{ 200{
203 struct snd_card *card = rtd->card->snd_card; 201 struct snd_card *card = rtd->card->snd_card;
204 struct snd_pcm *pcm = rtd->pcm; 202 struct snd_pcm *pcm = rtd->pcm;
205 int ret = 0; 203 int ret;
206 204
207 if (!card->dev->dma_mask) 205 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(64));
208 card->dev->dma_mask = &omap_pcm_dmamask; 206 if (ret)
209 if (!card->dev->coherent_dma_mask) 207 return ret;
210 card->dev->coherent_dma_mask = DMA_BIT_MASK(64);
211 208
212 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 209 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
213 ret = omap_pcm_preallocate_dma_buffer(pcm, 210 ret = omap_pcm_preallocate_dma_buffer(pcm,
diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4030.c
index 2a9324f794d8..6a8d6b5f160d 100644
--- a/sound/soc/omap/omap-twl4030.c
+++ b/sound/soc/omap/omap-twl4030.c
@@ -338,9 +338,9 @@ static int omap_twl4030_probe(struct platform_device *pdev)
338 } 338 }
339 339
340 snd_soc_card_set_drvdata(card, priv); 340 snd_soc_card_set_drvdata(card, priv);
341 ret = snd_soc_register_card(card); 341 ret = devm_snd_soc_register_card(&pdev->dev, card);
342 if (ret) { 342 if (ret) {
343 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 343 dev_err(&pdev->dev, "devm_snd_soc_register_card() failed: %d\n",
344 ret); 344 ret);
345 return ret; 345 return ret;
346 } 346 }
@@ -357,7 +357,6 @@ static int omap_twl4030_remove(struct platform_device *pdev)
357 snd_soc_jack_free_gpios(&priv->hs_jack, 357 snd_soc_jack_free_gpios(&priv->hs_jack,
358 ARRAY_SIZE(hs_jack_gpios), 358 ARRAY_SIZE(hs_jack_gpios),
359 hs_jack_gpios); 359 hs_jack_gpios);
360 snd_soc_unregister_card(card);
361 360
362 return 0; 361 return 0;
363} 362}
diff --git a/sound/soc/pxa/brownstone.c b/sound/soc/pxa/brownstone.c
index 5b7d969f89a9..08acdc236bf8 100644
--- a/sound/soc/pxa/brownstone.c
+++ b/sound/soc/pxa/brownstone.c
@@ -163,6 +163,7 @@ static struct platform_driver mmp_driver = {
163 .driver = { 163 .driver = {
164 .name = "brownstone-audio", 164 .name = "brownstone-audio",
165 .owner = THIS_MODULE, 165 .owner = THIS_MODULE,
166 .pm = &snd_soc_pm_ops,
166 }, 167 },
167 .probe = brownstone_probe, 168 .probe = brownstone_probe,
168 .remove = brownstone_remove, 169 .remove = brownstone_remove,
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index f4cce1e80112..1853d41034bf 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -329,6 +329,7 @@ static struct platform_driver corgi_driver = {
329 .driver = { 329 .driver = {
330 .name = "corgi-audio", 330 .name = "corgi-audio",
331 .owner = THIS_MODULE, 331 .owner = THIS_MODULE,
332 .pm = &snd_soc_pm_ops,
332 }, 333 },
333 .probe = corgi_probe, 334 .probe = corgi_probe,
334 .remove = corgi_remove, 335 .remove = corgi_remove,
diff --git a/sound/soc/pxa/e740_wm9705.c b/sound/soc/pxa/e740_wm9705.c
index 70d799b13f0d..44b5c09d296b 100644
--- a/sound/soc/pxa/e740_wm9705.c
+++ b/sound/soc/pxa/e740_wm9705.c
@@ -178,6 +178,7 @@ static struct platform_driver e740_driver = {
178 .driver = { 178 .driver = {
179 .name = "e740-audio", 179 .name = "e740-audio",
180 .owner = THIS_MODULE, 180 .owner = THIS_MODULE,
181 .pm = &snd_soc_pm_ops,
181 }, 182 },
182 .probe = e740_probe, 183 .probe = e740_probe,
183 .remove = e740_remove, 184 .remove = e740_remove,
diff --git a/sound/soc/pxa/e750_wm9705.c b/sound/soc/pxa/e750_wm9705.c
index f94d2ab51351..c34e447eb991 100644
--- a/sound/soc/pxa/e750_wm9705.c
+++ b/sound/soc/pxa/e750_wm9705.c
@@ -160,6 +160,7 @@ static struct platform_driver e750_driver = {
160 .driver = { 160 .driver = {
161 .name = "e750-audio", 161 .name = "e750-audio",
162 .owner = THIS_MODULE, 162 .owner = THIS_MODULE,
163 .pm = &snd_soc_pm_ops,
163 }, 164 },
164 .probe = e750_probe, 165 .probe = e750_probe,
165 .remove = e750_remove, 166 .remove = e750_remove,
diff --git a/sound/soc/pxa/e800_wm9712.c b/sound/soc/pxa/e800_wm9712.c
index 8768a640dd71..3137f800b43f 100644
--- a/sound/soc/pxa/e800_wm9712.c
+++ b/sound/soc/pxa/e800_wm9712.c
@@ -150,6 +150,7 @@ static struct platform_driver e800_driver = {
150 .driver = { 150 .driver = {
151 .name = "e800-audio", 151 .name = "e800-audio",
152 .owner = THIS_MODULE, 152 .owner = THIS_MODULE,
153 .pm = &snd_soc_pm_ops,
153 }, 154 },
154 .probe = e800_probe, 155 .probe = e800_probe,
155 .remove = e800_remove, 156 .remove = e800_remove,
diff --git a/sound/soc/pxa/imote2.c b/sound/soc/pxa/imote2.c
index eef1f7b7b38e..fd2f4eda1fd3 100644
--- a/sound/soc/pxa/imote2.c
+++ b/sound/soc/pxa/imote2.c
@@ -91,6 +91,7 @@ static struct platform_driver imote2_driver = {
91 .driver = { 91 .driver = {
92 .name = "imote2-audio", 92 .name = "imote2-audio",
93 .owner = THIS_MODULE, 93 .owner = THIS_MODULE,
94 .pm = &snd_soc_pm_ops,
94 }, 95 },
95 .probe = imote2_probe, 96 .probe = imote2_probe,
96 .remove = imote2_remove, 97 .remove = imote2_remove,
diff --git a/sound/soc/pxa/mioa701_wm9713.c b/sound/soc/pxa/mioa701_wm9713.c
index bbea7780eac6..160c5245448f 100644
--- a/sound/soc/pxa/mioa701_wm9713.c
+++ b/sound/soc/pxa/mioa701_wm9713.c
@@ -215,6 +215,7 @@ static struct platform_driver mioa701_wm9713_driver = {
215 .driver = { 215 .driver = {
216 .name = "mioa701-wm9713", 216 .name = "mioa701-wm9713",
217 .owner = THIS_MODULE, 217 .owner = THIS_MODULE,
218 .pm = &snd_soc_pm_ops,
218 }, 219 },
219}; 220};
220 221
diff --git a/sound/soc/pxa/mmp-pcm.c b/sound/soc/pxa/mmp-pcm.c
index 8235e231d89c..7929e19b0ef5 100644
--- a/sound/soc/pxa/mmp-pcm.c
+++ b/sound/soc/pxa/mmp-pcm.c
@@ -201,10 +201,9 @@ static int mmp_pcm_preallocate_dma_buffer(struct snd_pcm_substream *substream,
201 if (!gpool) 201 if (!gpool)
202 return -ENOMEM; 202 return -ENOMEM;
203 203
204 buf->area = (unsigned char *)gen_pool_alloc(gpool, size); 204 buf->area = gen_pool_dma_alloc(gpool, size, &buf->addr);
205 if (!buf->area) 205 if (!buf->area)
206 return -ENOMEM; 206 return -ENOMEM;
207 buf->addr = gen_pool_virt_to_phys(gpool, (unsigned long)buf->area);
208 buf->bytes = size; 207 buf->bytes = size;
209 return 0; 208 return 0;
210} 209}
diff --git a/sound/soc/pxa/mmp-sspa.c b/sound/soc/pxa/mmp-sspa.c
index 41752a5fe3b0..5bf5f1f7cac5 100644
--- a/sound/soc/pxa/mmp-sspa.c
+++ b/sound/soc/pxa/mmp-sspa.c
@@ -455,8 +455,8 @@ static int asoc_mmp_sspa_probe(struct platform_device *pdev)
455 priv->dai_fmt = (unsigned int) -1; 455 priv->dai_fmt = (unsigned int) -1;
456 platform_set_drvdata(pdev, priv); 456 platform_set_drvdata(pdev, priv);
457 457
458 return snd_soc_register_component(&pdev->dev, &mmp_sspa_component, 458 return devm_snd_soc_register_component(&pdev->dev, &mmp_sspa_component,
459 &mmp_sspa_dai, 1); 459 &mmp_sspa_dai, 1);
460} 460}
461 461
462static int asoc_mmp_sspa_remove(struct platform_device *pdev) 462static int asoc_mmp_sspa_remove(struct platform_device *pdev)
@@ -466,7 +466,6 @@ static int asoc_mmp_sspa_remove(struct platform_device *pdev)
466 clk_disable(priv->audio_clk); 466 clk_disable(priv->audio_clk);
467 clk_put(priv->audio_clk); 467 clk_put(priv->audio_clk);
468 clk_put(priv->sysclk); 468 clk_put(priv->sysclk);
469 snd_soc_unregister_component(&pdev->dev);
470 return 0; 469 return 0;
471} 470}
472 471
diff --git a/sound/soc/pxa/palm27x.c b/sound/soc/pxa/palm27x.c
index e1ffcdd9a649..3284c4b901cb 100644
--- a/sound/soc/pxa/palm27x.c
+++ b/sound/soc/pxa/palm27x.c
@@ -181,6 +181,7 @@ static struct platform_driver palm27x_wm9712_driver = {
181 .driver = { 181 .driver = {
182 .name = "palm27x-asoc", 182 .name = "palm27x-asoc",
183 .owner = THIS_MODULE, 183 .owner = THIS_MODULE,
184 .pm = &snd_soc_pm_ops,
184 }, 185 },
185}; 186};
186 187
diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c
index fafe46355c31..c93e138d8dc3 100644
--- a/sound/soc/pxa/poodle.c
+++ b/sound/soc/pxa/poodle.c
@@ -303,6 +303,7 @@ static struct platform_driver poodle_driver = {
303 .driver = { 303 .driver = {
304 .name = "poodle-audio", 304 .name = "poodle-audio",
305 .owner = THIS_MODULE, 305 .owner = THIS_MODULE,
306 .pm = &snd_soc_pm_ops,
306 }, 307 },
307 .probe = poodle_probe, 308 .probe = poodle_probe,
308 .remove = poodle_remove, 309 .remove = poodle_remove,
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index f1059d999de6..ae956e3f4b9d 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -89,33 +89,6 @@ static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = {
89 .filter_data = &pxa2xx_ac97_pcm_aux_mic_mono_req, 89 .filter_data = &pxa2xx_ac97_pcm_aux_mic_mono_req,
90}; 90};
91 91
92#ifdef CONFIG_PM
93static int pxa2xx_ac97_suspend(struct snd_soc_dai *dai)
94{
95 return pxa2xx_ac97_hw_suspend();
96}
97
98static int pxa2xx_ac97_resume(struct snd_soc_dai *dai)
99{
100 return pxa2xx_ac97_hw_resume();
101}
102
103#else
104#define pxa2xx_ac97_suspend NULL
105#define pxa2xx_ac97_resume NULL
106#endif
107
108static int pxa2xx_ac97_probe(struct snd_soc_dai *dai)
109{
110 return pxa2xx_ac97_hw_probe(to_platform_device(dai->dev));
111}
112
113static int pxa2xx_ac97_remove(struct snd_soc_dai *dai)
114{
115 pxa2xx_ac97_hw_remove(to_platform_device(dai->dev));
116 return 0;
117}
118
119static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream, 92static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream,
120 struct snd_pcm_hw_params *params, 93 struct snd_pcm_hw_params *params,
121 struct snd_soc_dai *cpu_dai) 94 struct snd_soc_dai *cpu_dai)
@@ -185,10 +158,6 @@ static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
185{ 158{
186 .name = "pxa2xx-ac97", 159 .name = "pxa2xx-ac97",
187 .ac97_control = 1, 160 .ac97_control = 1,
188 .probe = pxa2xx_ac97_probe,
189 .remove = pxa2xx_ac97_remove,
190 .suspend = pxa2xx_ac97_suspend,
191 .resume = pxa2xx_ac97_resume,
192 .playback = { 161 .playback = {
193 .stream_name = "AC97 Playback", 162 .stream_name = "AC97 Playback",
194 .channels_min = 2, 163 .channels_min = 2,
@@ -246,6 +215,12 @@ static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
246 return -ENXIO; 215 return -ENXIO;
247 } 216 }
248 217
218 ret = pxa2xx_ac97_hw_probe(pdev);
219 if (ret) {
220 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret);
221 return ret;
222 }
223
249 ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops); 224 ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops);
250 if (ret != 0) 225 if (ret != 0)
251 return ret; 226 return ret;
@@ -262,15 +237,34 @@ static int pxa2xx_ac97_dev_remove(struct platform_device *pdev)
262{ 237{
263 snd_soc_unregister_component(&pdev->dev); 238 snd_soc_unregister_component(&pdev->dev);
264 snd_soc_set_ac97_ops(NULL); 239 snd_soc_set_ac97_ops(NULL);
240 pxa2xx_ac97_hw_remove(pdev);
265 return 0; 241 return 0;
266} 242}
267 243
244#ifdef CONFIG_PM_SLEEP
245static int pxa2xx_ac97_dev_suspend(struct device *dev)
246{
247 return pxa2xx_ac97_hw_suspend();
248}
249
250static int pxa2xx_ac97_dev_resume(struct device *dev)
251{
252 return pxa2xx_ac97_hw_resume();
253}
254
255static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops,
256 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume);
257#endif
258
268static struct platform_driver pxa2xx_ac97_driver = { 259static struct platform_driver pxa2xx_ac97_driver = {
269 .probe = pxa2xx_ac97_dev_probe, 260 .probe = pxa2xx_ac97_dev_probe,
270 .remove = pxa2xx_ac97_dev_remove, 261 .remove = pxa2xx_ac97_dev_remove,
271 .driver = { 262 .driver = {
272 .name = "pxa2xx-ac97", 263 .name = "pxa2xx-ac97",
273 .owner = THIS_MODULE, 264 .owner = THIS_MODULE,
265#ifdef CONFIG_PM_SLEEP
266 .pm = &pxa2xx_ac97_pm_ops,
267#endif
274 }, 268 },
275}; 269};
276 270
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c
index d5340a088858..c0d648d3339f 100644
--- a/sound/soc/pxa/pxa2xx-i2s.c
+++ b/sound/soc/pxa/pxa2xx-i2s.c
@@ -165,7 +165,8 @@ static int pxa2xx_i2s_hw_params(struct snd_pcm_substream *substream,
165{ 165{
166 struct snd_dmaengine_dai_dma_data *dma_data; 166 struct snd_dmaengine_dai_dma_data *dma_data;
167 167
168 BUG_ON(IS_ERR(clk_i2s)); 168 if (WARN_ON(IS_ERR(clk_i2s)))
169 return -EINVAL;
169 clk_prepare_enable(clk_i2s); 170 clk_prepare_enable(clk_i2s);
170 clk_ena = 1; 171 clk_ena = 1;
171 pxa_i2s_wait(); 172 pxa_i2s_wait();
diff --git a/sound/soc/pxa/pxa2xx-pcm.c b/sound/soc/pxa/pxa2xx-pcm.c
index 806da27b8b67..d58b09f4f7a4 100644
--- a/sound/soc/pxa/pxa2xx-pcm.c
+++ b/sound/soc/pxa/pxa2xx-pcm.c
@@ -87,18 +87,15 @@ static struct snd_pcm_ops pxa2xx_pcm_ops = {
87 .mmap = pxa2xx_pcm_mmap, 87 .mmap = pxa2xx_pcm_mmap,
88}; 88};
89 89
90static u64 pxa2xx_pcm_dmamask = DMA_BIT_MASK(32);
91
92static int pxa2xx_soc_pcm_new(struct snd_soc_pcm_runtime *rtd) 90static int pxa2xx_soc_pcm_new(struct snd_soc_pcm_runtime *rtd)
93{ 91{
94 struct snd_card *card = rtd->card->snd_card; 92 struct snd_card *card = rtd->card->snd_card;
95 struct snd_pcm *pcm = rtd->pcm; 93 struct snd_pcm *pcm = rtd->pcm;
96 int ret = 0; 94 int ret;
97 95
98 if (!card->dev->dma_mask) 96 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
99 card->dev->dma_mask = &pxa2xx_pcm_dmamask; 97 if (ret)
100 if (!card->dev->coherent_dma_mask) 98 return ret;
101 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
102 99
103 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 100 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
104 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 101 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
diff --git a/sound/soc/pxa/tosa.c b/sound/soc/pxa/tosa.c
index a3fe19123f07..1d9c2ed223bc 100644
--- a/sound/soc/pxa/tosa.c
+++ b/sound/soc/pxa/tosa.c
@@ -275,6 +275,7 @@ static struct platform_driver tosa_driver = {
275 .driver = { 275 .driver = {
276 .name = "tosa-audio", 276 .name = "tosa-audio",
277 .owner = THIS_MODULE, 277 .owner = THIS_MODULE,
278 .pm = &snd_soc_pm_ops,
278 }, 279 },
279 .probe = tosa_probe, 280 .probe = tosa_probe,
280 .remove = tosa_remove, 281 .remove = tosa_remove,
diff --git a/sound/soc/pxa/ttc-dkb.c b/sound/soc/pxa/ttc-dkb.c
index 13c9ee0cb83b..0b535b570622 100644
--- a/sound/soc/pxa/ttc-dkb.c
+++ b/sound/soc/pxa/ttc-dkb.c
@@ -160,6 +160,7 @@ static struct platform_driver ttc_dkb_driver = {
160 .driver = { 160 .driver = {
161 .name = "ttc-dkb-audio", 161 .name = "ttc-dkb-audio",
162 .owner = THIS_MODULE, 162 .owner = THIS_MODULE,
163 .pm = &snd_soc_pm_ops,
163 }, 164 },
164 .probe = ttc_dkb_probe, 165 .probe = ttc_dkb_probe,
165 .remove = ttc_dkb_remove, 166 .remove = ttc_dkb_remove,
diff --git a/sound/soc/s6000/s6000-pcm.c b/sound/soc/s6000/s6000-pcm.c
index d0740a762963..d219880815c0 100644
--- a/sound/soc/s6000/s6000-pcm.c
+++ b/sound/soc/s6000/s6000-pcm.c
@@ -90,7 +90,8 @@ static void s6000_pcm_enqueue_dma(struct snd_pcm_substream *substream)
90 return; 90 return;
91 } 91 }
92 92
93 BUG_ON(period_size & 15); 93 if (WARN_ON(period_size & 15))
94 return;
94 s6dmac_put_fifo(DMA_MASK_DMAC(channel), DMA_INDEX_CHNL(channel), 95 s6dmac_put_fifo(DMA_MASK_DMAC(channel), DMA_INDEX_CHNL(channel),
95 src, dst, period_size); 96 src, dst, period_size);
96 97
@@ -444,8 +445,6 @@ static void s6000_pcm_free(struct snd_pcm *pcm)
444 snd_pcm_lib_preallocate_free_for_all(pcm); 445 snd_pcm_lib_preallocate_free_for_all(pcm);
445} 446}
446 447
447static u64 s6000_pcm_dmamask = DMA_BIT_MASK(32);
448
449static int s6000_pcm_new(struct snd_soc_pcm_runtime *runtime) 448static int s6000_pcm_new(struct snd_soc_pcm_runtime *runtime)
450{ 449{
451 struct snd_card *card = runtime->card->snd_card; 450 struct snd_card *card = runtime->card->snd_card;
@@ -456,10 +455,9 @@ static int s6000_pcm_new(struct snd_soc_pcm_runtime *runtime)
456 params = snd_soc_dai_get_dma_data(runtime->cpu_dai, 455 params = snd_soc_dai_get_dma_data(runtime->cpu_dai,
457 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream); 456 pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
458 457
459 if (!card->dev->dma_mask) 458 res = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
460 card->dev->dma_mask = &s6000_pcm_dmamask; 459 if (res)
461 if (!card->dev->coherent_dma_mask) 460 return res;
462 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
463 461
464 if (params->dma_in) { 462 if (params->dma_in) {
465 s6dmac_disable_chan(DMA_MASK_DMAC(params->dma_in), 463 s6dmac_disable_chan(DMA_MASK_DMAC(params->dma_in),
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
index 2eea1840315d..37459dfd168d 100644
--- a/sound/soc/samsung/Kconfig
+++ b/sound/soc/samsung/Kconfig
@@ -2,7 +2,7 @@ config SND_SOC_SAMSUNG
2 tristate "ASoC support for Samsung" 2 tristate "ASoC support for Samsung"
3 depends on PLAT_SAMSUNG 3 depends on PLAT_SAMSUNG
4 select S3C64XX_DMA if ARCH_S3C64XX 4 select S3C64XX_DMA if ARCH_S3C64XX
5 select S3C2410_DMA if ARCH_S3C24XX 5 select S3C24XX_DMA if ARCH_S3C24XX
6 help 6 help
7 Say Y or M if you want to add support for codecs attached to 7 Say Y or M if you want to add support for codecs attached to
8 the Samsung SoCs' Audio interfaces. You will also need to 8 the Samsung SoCs' Audio interfaces. You will also need to
diff --git a/sound/soc/samsung/ac97.c b/sound/soc/samsung/ac97.c
index 2acf987844e8..350ba23a9893 100644
--- a/sound/soc/samsung/ac97.c
+++ b/sound/soc/samsung/ac97.c
@@ -74,7 +74,7 @@ static void s3c_ac97_activate(struct snd_ac97 *ac97)
74 if (stat == S3C_AC97_GLBSTAT_MAINSTATE_ACTIVE) 74 if (stat == S3C_AC97_GLBSTAT_MAINSTATE_ACTIVE)
75 return; /* Return if already active */ 75 return; /* Return if already active */
76 76
77 INIT_COMPLETION(s3c_ac97.done); 77 reinit_completion(&s3c_ac97.done);
78 78
79 ac_glbctrl = readl(s3c_ac97.regs + S3C_AC97_GLBCTRL); 79 ac_glbctrl = readl(s3c_ac97.regs + S3C_AC97_GLBCTRL);
80 ac_glbctrl = S3C_AC97_GLBCTRL_ACLINKON; 80 ac_glbctrl = S3C_AC97_GLBCTRL_ACLINKON;
@@ -103,7 +103,7 @@ static unsigned short s3c_ac97_read(struct snd_ac97 *ac97,
103 103
104 s3c_ac97_activate(ac97); 104 s3c_ac97_activate(ac97);
105 105
106 INIT_COMPLETION(s3c_ac97.done); 106 reinit_completion(&s3c_ac97.done);
107 107
108 ac_codec_cmd = readl(s3c_ac97.regs + S3C_AC97_CODEC_CMD); 108 ac_codec_cmd = readl(s3c_ac97.regs + S3C_AC97_CODEC_CMD);
109 ac_codec_cmd = S3C_AC97_CODEC_CMD_READ | AC_CMD_ADDR(reg); 109 ac_codec_cmd = S3C_AC97_CODEC_CMD_READ | AC_CMD_ADDR(reg);
@@ -140,7 +140,7 @@ static void s3c_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
140 140
141 s3c_ac97_activate(ac97); 141 s3c_ac97_activate(ac97);
142 142
143 INIT_COMPLETION(s3c_ac97.done); 143 reinit_completion(&s3c_ac97.done);
144 144
145 ac_codec_cmd = readl(s3c_ac97.regs + S3C_AC97_CODEC_CMD); 145 ac_codec_cmd = readl(s3c_ac97.regs + S3C_AC97_CODEC_CMD);
146 ac_codec_cmd = AC_CMD_ADDR(reg) | AC_CMD_DATA(val); 146 ac_codec_cmd = AC_CMD_ADDR(reg) | AC_CMD_DATA(val);
diff --git a/sound/soc/samsung/bells.c b/sound/soc/samsung/bells.c
index 29e246803626..84f5d8b76679 100644
--- a/sound/soc/samsung/bells.c
+++ b/sound/soc/samsung/bells.c
@@ -356,6 +356,7 @@ static struct snd_soc_dapm_widget bells_widgets[] = {
356 356
357static struct snd_soc_dapm_route bells_routes[] = { 357static struct snd_soc_dapm_route bells_routes[] = {
358 { "Sub CLK_SYS", NULL, "OPCLK" }, 358 { "Sub CLK_SYS", NULL, "OPCLK" },
359 { "CLKIN", NULL, "OPCLK" },
359 360
360 { "DMIC", NULL, "MICBIAS2" }, 361 { "DMIC", NULL, "MICBIAS2" },
361 { "IN2L", NULL, "DMIC" }, 362 { "IN2L", NULL, "DMIC" },
diff --git a/sound/soc/samsung/dma.c b/sound/soc/samsung/dma.c
index 9338d11e9216..fe2748b494d4 100644
--- a/sound/soc/samsung/dma.c
+++ b/sound/soc/samsung/dma.c
@@ -406,20 +406,17 @@ static void dma_free_dma_buffers(struct snd_pcm *pcm)
406 } 406 }
407} 407}
408 408
409static u64 dma_mask = DMA_BIT_MASK(32);
410
411static int dma_new(struct snd_soc_pcm_runtime *rtd) 409static int dma_new(struct snd_soc_pcm_runtime *rtd)
412{ 410{
413 struct snd_card *card = rtd->card->snd_card; 411 struct snd_card *card = rtd->card->snd_card;
414 struct snd_pcm *pcm = rtd->pcm; 412 struct snd_pcm *pcm = rtd->pcm;
415 int ret = 0; 413 int ret;
416 414
417 pr_debug("Entered %s\n", __func__); 415 pr_debug("Entered %s\n", __func__);
418 416
419 if (!card->dev->dma_mask) 417 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
420 card->dev->dma_mask = &dma_mask; 418 if (ret)
421 if (!card->dev->coherent_dma_mask) 419 return ret;
422 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
423 420
424 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 421 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
425 ret = preallocate_dma_buffer(pcm, 422 ret = preallocate_dma_buffer(pcm,
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index b302f3b7a587..a5cbdb4f1655 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -702,13 +702,6 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
702 } 702 }
703 writel(mod, i2s->addr + I2SMOD); 703 writel(mod, i2s->addr + I2SMOD);
704 704
705 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
706 snd_soc_dai_set_dma_data(dai, substream,
707 (void *)&i2s->dma_playback);
708 else
709 snd_soc_dai_set_dma_data(dai, substream,
710 (void *)&i2s->dma_capture);
711
712 i2s->frmclk = params_rate(params); 705 i2s->frmclk = params_rate(params);
713 706
714 return 0; 707 return 0;
@@ -970,6 +963,8 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
970 } 963 }
971 clk_prepare_enable(i2s->clk); 964 clk_prepare_enable(i2s->clk);
972 965
966 snd_soc_dai_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
967
973 if (other) { 968 if (other) {
974 other->addr = i2s->addr; 969 other->addr = i2s->addr;
975 other->clk = i2s->clk; 970 other->clk = i2s->clk;
@@ -1060,7 +1055,7 @@ static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
1060 i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops; 1055 i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
1061 i2s->i2s_dai_drv.suspend = i2s_suspend; 1056 i2s->i2s_dai_drv.suspend = i2s_suspend;
1062 i2s->i2s_dai_drv.resume = i2s_resume; 1057 i2s->i2s_dai_drv.resume = i2s_resume;
1063 i2s->i2s_dai_drv.playback.channels_min = 2; 1058 i2s->i2s_dai_drv.playback.channels_min = 1;
1064 i2s->i2s_dai_drv.playback.channels_max = 2; 1059 i2s->i2s_dai_drv.playback.channels_max = 2;
1065 i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES; 1060 i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
1066 i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS; 1061 i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
@@ -1073,7 +1068,7 @@ static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
1073 dev_set_drvdata(&i2s->pdev->dev, i2s); 1068 dev_set_drvdata(&i2s->pdev->dev, i2s);
1074 } else { /* Create a new platform_device for Secondary */ 1069 } else { /* Create a new platform_device for Secondary */
1075 i2s->pdev = platform_device_alloc("samsung-i2s-sec", -1); 1070 i2s->pdev = platform_device_alloc("samsung-i2s-sec", -1);
1076 if (IS_ERR(i2s->pdev)) 1071 if (!i2s->pdev)
1077 return NULL; 1072 return NULL;
1078 1073
1079 i2s->pdev->dev.parent = &pdev->dev; 1074 i2s->pdev->dev.parent = &pdev->dev;
@@ -1143,9 +1138,9 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1143 dev_err(&pdev->dev, "Unable to get drvdata\n"); 1138 dev_err(&pdev->dev, "Unable to get drvdata\n");
1144 return -EFAULT; 1139 return -EFAULT;
1145 } 1140 }
1146 snd_soc_register_component(&sec_dai->pdev->dev, 1141 devm_snd_soc_register_component(&sec_dai->pdev->dev,
1147 &samsung_i2s_component, 1142 &samsung_i2s_component,
1148 &sec_dai->i2s_dai_drv, 1); 1143 &sec_dai->i2s_dai_drv, 1);
1149 samsung_asoc_dma_platform_register(&pdev->dev); 1144 samsung_asoc_dma_platform_register(&pdev->dev);
1150 return 0; 1145 return 0;
1151 } 1146 }
@@ -1258,8 +1253,9 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1258 goto err; 1253 goto err;
1259 } 1254 }
1260 1255
1261 snd_soc_register_component(&pri_dai->pdev->dev, &samsung_i2s_component, 1256 devm_snd_soc_register_component(&pri_dai->pdev->dev,
1262 &pri_dai->i2s_dai_drv, 1); 1257 &samsung_i2s_component,
1258 &pri_dai->i2s_dai_drv, 1);
1263 1259
1264 pm_runtime_enable(&pdev->dev); 1260 pm_runtime_enable(&pdev->dev);
1265 1261
@@ -1294,7 +1290,6 @@ static int samsung_i2s_remove(struct platform_device *pdev)
1294 i2s->sec_dai = NULL; 1290 i2s->sec_dai = NULL;
1295 1291
1296 samsung_asoc_dma_platform_unregister(&pdev->dev); 1292 samsung_asoc_dma_platform_unregister(&pdev->dev);
1297 snd_soc_unregister_component(&pdev->dev);
1298 1293
1299 return 0; 1294 return 0;
1300} 1295}
diff --git a/sound/soc/samsung/idma.c b/sound/soc/samsung/idma.c
index ce1e1e16f250..e4f318fc2f82 100644
--- a/sound/soc/samsung/idma.c
+++ b/sound/soc/samsung/idma.c
@@ -383,18 +383,15 @@ static int preallocate_idma_buffer(struct snd_pcm *pcm, int stream)
383 return 0; 383 return 0;
384} 384}
385 385
386static u64 idma_mask = DMA_BIT_MASK(32);
387
388static int idma_new(struct snd_soc_pcm_runtime *rtd) 386static int idma_new(struct snd_soc_pcm_runtime *rtd)
389{ 387{
390 struct snd_card *card = rtd->card->snd_card; 388 struct snd_card *card = rtd->card->snd_card;
391 struct snd_pcm *pcm = rtd->pcm; 389 struct snd_pcm *pcm = rtd->pcm;
392 int ret = 0; 390 int ret;
393 391
394 if (!card->dev->dma_mask) 392 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
395 card->dev->dma_mask = &idma_mask; 393 if (ret)
396 if (!card->dev->coherent_dma_mask) 394 return ret;
397 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
398 395
399 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 396 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
400 ret = preallocate_idma_buffer(pcm, 397 ret = preallocate_idma_buffer(pcm,
diff --git a/sound/soc/samsung/s3c-i2s-v2.c b/sound/soc/samsung/s3c-i2s-v2.c
index e5e81b111001..fefc56100349 100644
--- a/sound/soc/samsung/s3c-i2s-v2.c
+++ b/sound/soc/samsung/s3c-i2s-v2.c
@@ -31,11 +31,7 @@
31#undef S3C_IIS_V2_SUPPORTED 31#undef S3C_IIS_V2_SUPPORTED
32 32
33#if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413) \ 33#if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413) \
34 || defined(CONFIG_CPU_S5PV210) 34 || defined(CONFIG_ARCH_S3C64XX) || defined(CONFIG_CPU_S5PV210)
35#define S3C_IIS_V2_SUPPORTED
36#endif
37
38#ifdef CONFIG_PLAT_S3C64XX
39#define S3C_IIS_V2_SUPPORTED 35#define S3C_IIS_V2_SUPPORTED
40#endif 36#endif
41 37
diff --git a/sound/soc/samsung/smdk_wm8994.c b/sound/soc/samsung/smdk_wm8994.c
index 5fd7a05a9b9e..b072bd107b31 100644
--- a/sound/soc/samsung/smdk_wm8994.c
+++ b/sound/soc/samsung/smdk_wm8994.c
@@ -9,6 +9,7 @@
9 9
10#include "../codecs/wm8994.h" 10#include "../codecs/wm8994.h"
11#include <sound/pcm_params.h> 11#include <sound/pcm_params.h>
12#include <sound/soc.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/of.h> 14#include <linux/of.h>
14#include <linux/of_device.h> 15#include <linux/of_device.h>
@@ -193,7 +194,7 @@ static int smdk_audio_probe(struct platform_device *pdev)
193 194
194 platform_set_drvdata(pdev, board); 195 platform_set_drvdata(pdev, board);
195 196
196 ret = snd_soc_register_card(card); 197 ret = devm_snd_soc_register_card(&pdev->dev, card);
197 198
198 if (ret) 199 if (ret)
199 dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret); 200 dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
@@ -201,23 +202,14 @@ static int smdk_audio_probe(struct platform_device *pdev)
201 return ret; 202 return ret;
202} 203}
203 204
204static int smdk_audio_remove(struct platform_device *pdev)
205{
206 struct snd_soc_card *card = platform_get_drvdata(pdev);
207
208 snd_soc_unregister_card(card);
209
210 return 0;
211}
212
213static struct platform_driver smdk_audio_driver = { 205static struct platform_driver smdk_audio_driver = {
214 .driver = { 206 .driver = {
215 .name = "smdk-audio-wm8894", 207 .name = "smdk-audio-wm8894",
216 .owner = THIS_MODULE, 208 .owner = THIS_MODULE,
217 .of_match_table = of_match_ptr(samsung_wm8994_of_match), 209 .of_match_table = of_match_ptr(samsung_wm8994_of_match),
210 .pm = &snd_soc_pm_ops,
218 }, 211 },
219 .probe = smdk_audio_probe, 212 .probe = smdk_audio_probe,
220 .remove = smdk_audio_remove,
221}; 213};
222 214
223module_platform_driver(smdk_audio_driver); 215module_platform_driver(smdk_audio_driver);
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index 56d8ff6a402d..14011d90d70a 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -37,7 +37,6 @@ config SND_SOC_SH4_SIU
37config SND_SOC_RCAR 37config SND_SOC_RCAR
38 tristate "R-Car series SRU/SCU/SSIU/SSI support" 38 tristate "R-Car series SRU/SCU/SSIU/SSI support"
39 select SND_SIMPLE_CARD 39 select SND_SIMPLE_CARD
40 select RCAR_CLK_ADG
41 help 40 help
42 This option enables R-Car SUR/SCU/SSIU/SSI sound support 41 This option enables R-Car SUR/SCU/SSIU/SSI sound support
43 42
diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c
index d80deb7ccf13..9430097979a5 100644
--- a/sound/soc/sh/rcar/adg.c
+++ b/sound/soc/sh/rcar/adg.c
@@ -8,7 +8,6 @@
8 * for more details. 8 * for more details.
9 */ 9 */
10#include <linux/sh_clk.h> 10#include <linux/sh_clk.h>
11#include <mach/clock.h>
12#include "rsnd.h" 11#include "rsnd.h"
13 12
14#define CLKA 0 13#define CLKA 0
@@ -22,6 +21,7 @@ struct rsnd_adg {
22 21
23 int rate_of_441khz_div_6; 22 int rate_of_441khz_div_6;
24 int rate_of_48khz_div_6; 23 int rate_of_48khz_div_6;
24 u32 ckr;
25}; 25};
26 26
27#define for_each_rsnd_clk(pos, adg, i) \ 27#define for_each_rsnd_clk(pos, adg, i) \
@@ -116,6 +116,11 @@ int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate)
116 116
117found_clock: 117found_clock:
118 118
119 /* see rsnd_adg_ssi_clk_init() */
120 rsnd_mod_bset(mod, SSICKR, 0x00FF0000, adg->ckr);
121 rsnd_mod_write(mod, BRRA, 0x00000002); /* 1/6 */
122 rsnd_mod_write(mod, BRRB, 0x00000002); /* 1/6 */
123
119 /* 124 /*
120 * This "mod" = "ssi" here. 125 * This "mod" = "ssi" here.
121 * we can get "ssi id" from mod 126 * we can get "ssi id" from mod
@@ -182,9 +187,7 @@ static void rsnd_adg_ssi_clk_init(struct rsnd_priv *priv, struct rsnd_adg *adg)
182 } 187 }
183 } 188 }
184 189
185 rsnd_priv_bset(priv, SSICKR, 0x00FF0000, ckr); 190 adg->ckr = ckr;
186 rsnd_priv_write(priv, BRRA, 0x00000002); /* 1/6 */
187 rsnd_priv_write(priv, BRRB, 0x00000002); /* 1/6 */
188} 191}
189 192
190int rsnd_adg_probe(struct platform_device *pdev, 193int rsnd_adg_probe(struct platform_device *pdev,
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index a35706028514..78c35b44fc04 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -94,6 +94,7 @@
94 * 94 *
95 */ 95 */
96#include <linux/pm_runtime.h> 96#include <linux/pm_runtime.h>
97#include <linux/shdma-base.h>
97#include "rsnd.h" 98#include "rsnd.h"
98 99
99#define RSND_RATES SNDRV_PCM_RATE_8000_96000 100#define RSND_RATES SNDRV_PCM_RATE_8000_96000
@@ -103,54 +104,9 @@
103 * rsnd_platform functions 104 * rsnd_platform functions
104 */ 105 */
105#define rsnd_platform_call(priv, dai, func, param...) \ 106#define rsnd_platform_call(priv, dai, func, param...) \
106 (!(priv->info->func) ? -ENODEV : \ 107 (!(priv->info->func) ? 0 : \
107 priv->info->func(param)) 108 priv->info->func(param))
108 109
109
110/*
111 * basic function
112 */
113u32 rsnd_read(struct rsnd_priv *priv,
114 struct rsnd_mod *mod, enum rsnd_reg reg)
115{
116 void __iomem *base = rsnd_gen_reg_get(priv, mod, reg);
117
118 BUG_ON(!base);
119
120 return ioread32(base);
121}
122
123void rsnd_write(struct rsnd_priv *priv,
124 struct rsnd_mod *mod,
125 enum rsnd_reg reg, u32 data)
126{
127 void __iomem *base = rsnd_gen_reg_get(priv, mod, reg);
128 struct device *dev = rsnd_priv_to_dev(priv);
129
130 BUG_ON(!base);
131
132 dev_dbg(dev, "w %p : %08x\n", base, data);
133
134 iowrite32(data, base);
135}
136
137void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod,
138 enum rsnd_reg reg, u32 mask, u32 data)
139{
140 void __iomem *base = rsnd_gen_reg_get(priv, mod, reg);
141 struct device *dev = rsnd_priv_to_dev(priv);
142 u32 val;
143
144 BUG_ON(!base);
145
146 val = ioread32(base);
147 val &= ~mask;
148 val |= data & mask;
149 iowrite32(val, base);
150
151 dev_dbg(dev, "s %p : %08x\n", base, val);
152}
153
154/* 110/*
155 * rsnd_mod functions 111 * rsnd_mod functions
156 */ 112 */
@@ -254,13 +210,6 @@ int rsnd_dma_available(struct rsnd_dma *dma)
254 return !!dma->chan; 210 return !!dma->chan;
255} 211}
256 212
257static bool rsnd_dma_filter(struct dma_chan *chan, void *param)
258{
259 chan->private = param;
260
261 return true;
262}
263
264int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, 213int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
265 int is_play, int id, 214 int is_play, int id,
266 int (*inquiry)(struct rsnd_dma *dma, 215 int (*inquiry)(struct rsnd_dma *dma,
@@ -268,7 +217,9 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
268 int (*complete)(struct rsnd_dma *dma)) 217 int (*complete)(struct rsnd_dma *dma))
269{ 218{
270 struct device *dev = rsnd_priv_to_dev(priv); 219 struct device *dev = rsnd_priv_to_dev(priv);
220 struct dma_slave_config cfg;
271 dma_cap_mask_t mask; 221 dma_cap_mask_t mask;
222 int ret;
272 223
273 if (dma->chan) { 224 if (dma->chan) {
274 dev_err(dev, "it already has dma channel\n"); 225 dev_err(dev, "it already has dma channel\n");
@@ -278,15 +229,23 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
278 dma_cap_zero(mask); 229 dma_cap_zero(mask);
279 dma_cap_set(DMA_SLAVE, mask); 230 dma_cap_set(DMA_SLAVE, mask);
280 231
281 dma->slave.shdma_slave.slave_id = id; 232 dma->chan = dma_request_slave_channel_compat(mask, shdma_chan_filter,
282 233 (void *)id, dev,
283 dma->chan = dma_request_channel(mask, rsnd_dma_filter, 234 is_play ? "tx" : "rx");
284 &dma->slave.shdma_slave);
285 if (!dma->chan) { 235 if (!dma->chan) {
286 dev_err(dev, "can't get dma channel\n"); 236 dev_err(dev, "can't get dma channel\n");
287 return -EIO; 237 return -EIO;
288 } 238 }
289 239
240 cfg.slave_id = id;
241 cfg.dst_addr = 0; /* use default addr when playback */
242 cfg.src_addr = 0; /* use default addr when capture */
243 cfg.direction = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
244
245 ret = dmaengine_slave_config(dma->chan, &cfg);
246 if (ret < 0)
247 goto rsnd_dma_init_err;
248
290 dma->dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE; 249 dma->dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
291 dma->priv = priv; 250 dma->priv = priv;
292 dma->inquiry = inquiry; 251 dma->inquiry = inquiry;
@@ -294,6 +253,11 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
294 INIT_WORK(&dma->work, rsnd_dma_do_work); 253 INIT_WORK(&dma->work, rsnd_dma_do_work);
295 254
296 return 0; 255 return 0;
256
257rsnd_dma_init_err:
258 rsnd_dma_quit(priv, dma);
259
260 return ret;
297} 261}
298 262
299void rsnd_dma_quit(struct rsnd_priv *priv, 263void rsnd_dma_quit(struct rsnd_priv *priv,
@@ -363,6 +327,9 @@ int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
363 327
364struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id) 328struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id)
365{ 329{
330 if ((id < 0) || (id >= rsnd_dai_nr(priv)))
331 return NULL;
332
366 return priv->rdai + id; 333 return priv->rdai + id;
367} 334}
368 335
diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c
index babb203b43b7..61212ee97c28 100644
--- a/sound/soc/sh/rcar/gen.c
+++ b/sound/soc/sh/rcar/gen.c
@@ -11,6 +11,11 @@
11#include "rsnd.h" 11#include "rsnd.h"
12 12
13struct rsnd_gen_ops { 13struct rsnd_gen_ops {
14 int (*probe)(struct platform_device *pdev,
15 struct rcar_snd_info *info,
16 struct rsnd_priv *priv);
17 void (*remove)(struct platform_device *pdev,
18 struct rsnd_priv *priv);
14 int (*path_init)(struct rsnd_priv *priv, 19 int (*path_init)(struct rsnd_priv *priv,
15 struct rsnd_dai *rdai, 20 struct rsnd_dai *rdai,
16 struct rsnd_dai_stream *io); 21 struct rsnd_dai_stream *io);
@@ -19,21 +24,97 @@ struct rsnd_gen_ops {
19 struct rsnd_dai_stream *io); 24 struct rsnd_dai_stream *io);
20}; 25};
21 26
22struct rsnd_gen_reg_map {
23 int index; /* -1 : not supported */
24 u32 offset_id; /* offset of ssi0, ssi1, ssi2... */
25 u32 offset_adr; /* offset of SSICR, SSISR, ... */
26};
27
28struct rsnd_gen { 27struct rsnd_gen {
29 void __iomem *base[RSND_BASE_MAX]; 28 void __iomem *base[RSND_BASE_MAX];
30 29
31 struct rsnd_gen_reg_map reg_map[RSND_REG_MAX];
32 struct rsnd_gen_ops *ops; 30 struct rsnd_gen_ops *ops;
31
32 struct regmap *regmap;
33 struct regmap_field *regs[RSND_REG_MAX];
33}; 34};
34 35
35#define rsnd_priv_to_gen(p) ((struct rsnd_gen *)(p)->gen) 36#define rsnd_priv_to_gen(p) ((struct rsnd_gen *)(p)->gen)
36 37
38#define RSND_REG_SET(gen, id, reg_id, offset, _id_offset, _id_size) \
39 [id] = { \
40 .reg = (unsigned int)gen->base[reg_id] + offset, \
41 .lsb = 0, \
42 .msb = 31, \
43 .id_size = _id_size, \
44 .id_offset = _id_offset, \
45 }
46
47/*
48 * basic function
49 */
50static int rsnd_regmap_write32(void *context, const void *_data, size_t count)
51{
52 struct rsnd_priv *priv = context;
53 struct device *dev = rsnd_priv_to_dev(priv);
54 u32 *data = (u32 *)_data;
55 u32 val = data[1];
56 void __iomem *reg = (void *)data[0];
57
58 iowrite32(val, reg);
59
60 dev_dbg(dev, "w %p : %08x\n", reg, val);
61
62 return 0;
63}
64
65static int rsnd_regmap_read32(void *context,
66 const void *_data, size_t reg_size,
67 void *_val, size_t val_size)
68{
69 struct rsnd_priv *priv = context;
70 struct device *dev = rsnd_priv_to_dev(priv);
71 u32 *data = (u32 *)_data;
72 u32 *val = (u32 *)_val;
73 void __iomem *reg = (void *)data[0];
74
75 *val = ioread32(reg);
76
77 dev_dbg(dev, "r %p : %08x\n", reg, *val);
78
79 return 0;
80}
81
82static struct regmap_bus rsnd_regmap_bus = {
83 .write = rsnd_regmap_write32,
84 .read = rsnd_regmap_read32,
85 .reg_format_endian_default = REGMAP_ENDIAN_NATIVE,
86 .val_format_endian_default = REGMAP_ENDIAN_NATIVE,
87};
88
89u32 rsnd_read(struct rsnd_priv *priv,
90 struct rsnd_mod *mod, enum rsnd_reg reg)
91{
92 struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
93 u32 val;
94
95 regmap_fields_read(gen->regs[reg], rsnd_mod_id(mod), &val);
96
97 return val;
98}
99
100void rsnd_write(struct rsnd_priv *priv,
101 struct rsnd_mod *mod,
102 enum rsnd_reg reg, u32 data)
103{
104 struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
105
106 regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data);
107}
108
109void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod,
110 enum rsnd_reg reg, u32 mask, u32 data)
111{
112 struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
113
114 regmap_fields_update_bits(gen->regs[reg], rsnd_mod_id(mod),
115 mask, data);
116}
117
37/* 118/*
38 * Gen2 119 * Gen2
39 * will be filled in the future 120 * will be filled in the future
@@ -98,44 +179,64 @@ static int rsnd_gen1_path_exit(struct rsnd_priv *priv,
98 return ret; 179 return ret;
99} 180}
100 181
101static struct rsnd_gen_ops rsnd_gen1_ops = { 182/* single address mapping */
102 .path_init = rsnd_gen1_path_init, 183#define RSND_GEN1_S_REG(gen, reg, id, offset) \
103 .path_exit = rsnd_gen1_path_exit, 184 RSND_REG_SET(gen, RSND_REG_##id, RSND_GEN1_##reg, offset, 0, 9)
104};
105 185
106#define RSND_GEN1_REG_MAP(g, s, i, oi, oa) \ 186/* multi address mapping */
107 do { \ 187#define RSND_GEN1_M_REG(gen, reg, id, offset, _id_offset) \
108 (g)->reg_map[RSND_REG_##i].index = RSND_GEN1_##s; \ 188 RSND_REG_SET(gen, RSND_REG_##id, RSND_GEN1_##reg, offset, _id_offset, 9)
109 (g)->reg_map[RSND_REG_##i].offset_id = oi; \
110 (g)->reg_map[RSND_REG_##i].offset_adr = oa; \
111 } while (0)
112 189
113static void rsnd_gen1_reg_map_init(struct rsnd_gen *gen) 190static int rsnd_gen1_regmap_init(struct rsnd_priv *priv, struct rsnd_gen *gen)
114{ 191{
115 RSND_GEN1_REG_MAP(gen, SRU, SRC_ROUTE_SEL, 0x0, 0x00); 192 int i;
116 RSND_GEN1_REG_MAP(gen, SRU, SRC_TMG_SEL0, 0x0, 0x08); 193 struct device *dev = rsnd_priv_to_dev(priv);
117 RSND_GEN1_REG_MAP(gen, SRU, SRC_TMG_SEL1, 0x0, 0x0c); 194 struct regmap_config regc;
118 RSND_GEN1_REG_MAP(gen, SRU, SRC_TMG_SEL2, 0x0, 0x10); 195 struct reg_field regf[RSND_REG_MAX] = {
119 RSND_GEN1_REG_MAP(gen, SRU, SRC_CTRL, 0x0, 0xc0); 196 RSND_GEN1_S_REG(gen, SRU, SRC_ROUTE_SEL, 0x00),
120 RSND_GEN1_REG_MAP(gen, SRU, SSI_MODE0, 0x0, 0xD0); 197 RSND_GEN1_S_REG(gen, SRU, SRC_TMG_SEL0, 0x08),
121 RSND_GEN1_REG_MAP(gen, SRU, SSI_MODE1, 0x0, 0xD4); 198 RSND_GEN1_S_REG(gen, SRU, SRC_TMG_SEL1, 0x0c),
122 RSND_GEN1_REG_MAP(gen, SRU, BUSIF_MODE, 0x4, 0x20); 199 RSND_GEN1_S_REG(gen, SRU, SRC_TMG_SEL2, 0x10),
123 RSND_GEN1_REG_MAP(gen, SRU, BUSIF_ADINR, 0x40, 0x214); 200 RSND_GEN1_S_REG(gen, SRU, SRC_CTRL, 0xc0),
124 201 RSND_GEN1_S_REG(gen, SRU, SSI_MODE0, 0xD0),
125 RSND_GEN1_REG_MAP(gen, ADG, BRRA, 0x0, 0x00); 202 RSND_GEN1_S_REG(gen, SRU, SSI_MODE1, 0xD4),
126 RSND_GEN1_REG_MAP(gen, ADG, BRRB, 0x0, 0x04); 203 RSND_GEN1_M_REG(gen, SRU, BUSIF_MODE, 0x20, 0x4),
127 RSND_GEN1_REG_MAP(gen, ADG, SSICKR, 0x0, 0x08); 204 RSND_GEN1_M_REG(gen, SRU, BUSIF_ADINR, 0x214, 0x40),
128 RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL0, 0x0, 0x0c); 205
129 RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL1, 0x0, 0x10); 206 RSND_GEN1_S_REG(gen, ADG, BRRA, 0x00),
130 RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL3, 0x0, 0x18); 207 RSND_GEN1_S_REG(gen, ADG, BRRB, 0x04),
131 RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL4, 0x0, 0x1c); 208 RSND_GEN1_S_REG(gen, ADG, SSICKR, 0x08),
132 RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL5, 0x0, 0x20); 209 RSND_GEN1_S_REG(gen, ADG, AUDIO_CLK_SEL0, 0x0c),
133 210 RSND_GEN1_S_REG(gen, ADG, AUDIO_CLK_SEL1, 0x10),
134 RSND_GEN1_REG_MAP(gen, SSI, SSICR, 0x40, 0x00); 211 RSND_GEN1_S_REG(gen, ADG, AUDIO_CLK_SEL3, 0x18),
135 RSND_GEN1_REG_MAP(gen, SSI, SSISR, 0x40, 0x04); 212 RSND_GEN1_S_REG(gen, ADG, AUDIO_CLK_SEL4, 0x1c),
136 RSND_GEN1_REG_MAP(gen, SSI, SSITDR, 0x40, 0x08); 213 RSND_GEN1_S_REG(gen, ADG, AUDIO_CLK_SEL5, 0x20),
137 RSND_GEN1_REG_MAP(gen, SSI, SSIRDR, 0x40, 0x0c); 214
138 RSND_GEN1_REG_MAP(gen, SSI, SSIWSR, 0x40, 0x20); 215 RSND_GEN1_M_REG(gen, SSI, SSICR, 0x00, 0x40),
216 RSND_GEN1_M_REG(gen, SSI, SSISR, 0x04, 0x40),
217 RSND_GEN1_M_REG(gen, SSI, SSITDR, 0x08, 0x40),
218 RSND_GEN1_M_REG(gen, SSI, SSIRDR, 0x0c, 0x40),
219 RSND_GEN1_M_REG(gen, SSI, SSIWSR, 0x20, 0x40),
220 };
221
222 memset(&regc, 0, sizeof(regc));
223 regc.reg_bits = 32;
224 regc.val_bits = 32;
225
226 gen->regmap = devm_regmap_init(dev, &rsnd_regmap_bus, priv, &regc);
227 if (IS_ERR(gen->regmap)) {
228 dev_err(dev, "regmap error %ld\n", PTR_ERR(gen->regmap));
229 return PTR_ERR(gen->regmap);
230 }
231
232 for (i = 0; i < RSND_REG_MAX; i++) {
233 gen->regs[i] = devm_regmap_field_alloc(dev, gen->regmap, regf[i]);
234 if (IS_ERR(gen->regs[i]))
235 return PTR_ERR(gen->regs[i]);
236
237 }
238
239 return 0;
139} 240}
140 241
141static int rsnd_gen1_probe(struct platform_device *pdev, 242static int rsnd_gen1_probe(struct platform_device *pdev,
@@ -147,6 +248,7 @@ static int rsnd_gen1_probe(struct platform_device *pdev,
147 struct resource *sru_res; 248 struct resource *sru_res;
148 struct resource *adg_res; 249 struct resource *adg_res;
149 struct resource *ssi_res; 250 struct resource *ssi_res;
251 int ret;
150 252
151 /* 253 /*
152 * map address 254 * map address
@@ -163,8 +265,9 @@ static int rsnd_gen1_probe(struct platform_device *pdev,
163 IS_ERR(gen->base[RSND_GEN1_SSI])) 265 IS_ERR(gen->base[RSND_GEN1_SSI]))
164 return -ENODEV; 266 return -ENODEV;
165 267
166 gen->ops = &rsnd_gen1_ops; 268 ret = rsnd_gen1_regmap_init(priv, gen);
167 rsnd_gen1_reg_map_init(gen); 269 if (ret < 0)
270 return ret;
168 271
169 dev_dbg(dev, "Gen1 device probed\n"); 272 dev_dbg(dev, "Gen1 device probed\n");
170 dev_dbg(dev, "SRU : %08x => %p\n", sru_res->start, 273 dev_dbg(dev, "SRU : %08x => %p\n", sru_res->start,
@@ -183,6 +286,13 @@ static void rsnd_gen1_remove(struct platform_device *pdev,
183{ 286{
184} 287}
185 288
289static struct rsnd_gen_ops rsnd_gen1_ops = {
290 .probe = rsnd_gen1_probe,
291 .remove = rsnd_gen1_remove,
292 .path_init = rsnd_gen1_path_init,
293 .path_exit = rsnd_gen1_path_exit,
294};
295
186/* 296/*
187 * Gen 297 * Gen
188 */ 298 */
@@ -204,46 +314,12 @@ int rsnd_gen_path_exit(struct rsnd_priv *priv,
204 return gen->ops->path_exit(priv, rdai, io); 314 return gen->ops->path_exit(priv, rdai, io);
205} 315}
206 316
207void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
208 struct rsnd_mod *mod,
209 enum rsnd_reg reg)
210{
211 struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
212 struct device *dev = rsnd_priv_to_dev(priv);
213 int index;
214 u32 offset_id, offset_adr;
215
216 if (reg >= RSND_REG_MAX) {
217 dev_err(dev, "rsnd_reg reg error\n");
218 return NULL;
219 }
220
221 index = gen->reg_map[reg].index;
222 offset_id = gen->reg_map[reg].offset_id;
223 offset_adr = gen->reg_map[reg].offset_adr;
224
225 if (index < 0) {
226 dev_err(dev, "unsupported reg access %d\n", reg);
227 return NULL;
228 }
229
230 if (offset_id && mod)
231 offset_id *= rsnd_mod_id(mod);
232
233 /*
234 * index/offset were set on gen1/gen2
235 */
236
237 return gen->base[index] + offset_id + offset_adr;
238}
239
240int rsnd_gen_probe(struct platform_device *pdev, 317int rsnd_gen_probe(struct platform_device *pdev,
241 struct rcar_snd_info *info, 318 struct rcar_snd_info *info,
242 struct rsnd_priv *priv) 319 struct rsnd_priv *priv)
243{ 320{
244 struct device *dev = rsnd_priv_to_dev(priv); 321 struct device *dev = rsnd_priv_to_dev(priv);
245 struct rsnd_gen *gen; 322 struct rsnd_gen *gen;
246 int i;
247 323
248 gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL); 324 gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL);
249 if (!gen) { 325 if (!gen) {
@@ -251,30 +327,23 @@ int rsnd_gen_probe(struct platform_device *pdev,
251 return -ENOMEM; 327 return -ENOMEM;
252 } 328 }
253 329
254 priv->gen = gen;
255
256 /*
257 * see
258 * rsnd_reg_get()
259 * rsnd_gen_probe()
260 */
261 for (i = 0; i < RSND_REG_MAX; i++)
262 gen->reg_map[i].index = -1;
263
264 /*
265 * init each module
266 */
267 if (rsnd_is_gen1(priv)) 330 if (rsnd_is_gen1(priv))
268 return rsnd_gen1_probe(pdev, info, priv); 331 gen->ops = &rsnd_gen1_ops;
269 332
270 dev_err(dev, "unknown generation R-Car sound device\n"); 333 if (!gen->ops) {
334 dev_err(dev, "unknown generation R-Car sound device\n");
335 return -ENODEV;
336 }
271 337
272 return -ENODEV; 338 priv->gen = gen;
339
340 return gen->ops->probe(pdev, info, priv);
273} 341}
274 342
275void rsnd_gen_remove(struct platform_device *pdev, 343void rsnd_gen_remove(struct platform_device *pdev,
276 struct rsnd_priv *priv) 344 struct rsnd_priv *priv)
277{ 345{
278 if (rsnd_is_gen1(priv)) 346 struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
279 rsnd_gen1_remove(pdev, priv); 347
348 gen->ops->remove(pdev, priv);
280} 349}
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h
index 9cc6986a8cfb..9e463e50e7e6 100644
--- a/sound/soc/sh/rcar/rsnd.h
+++ b/sound/soc/sh/rcar/rsnd.h
@@ -78,10 +78,6 @@ struct rsnd_dai_stream;
78#define rsnd_mod_bset(m, r, s, d) \ 78#define rsnd_mod_bset(m, r, s, d) \
79 rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d) 79 rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
80 80
81#define rsnd_priv_read(p, r) rsnd_read(p, NULL, RSND_REG_##r)
82#define rsnd_priv_write(p, r, d) rsnd_write(p, NULL, RSND_REG_##r, d)
83#define rsnd_priv_bset(p, r, s, d) rsnd_bset(p, NULL, RSND_REG_##r, s, d)
84
85u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg); 81u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
86void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod, 82void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
87 enum rsnd_reg reg, u32 data); 83 enum rsnd_reg reg, u32 data);
@@ -220,8 +216,8 @@ int rsnd_gen_path_exit(struct rsnd_priv *priv,
220void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, 216void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
221 struct rsnd_mod *mod, 217 struct rsnd_mod *mod,
222 enum rsnd_reg reg); 218 enum rsnd_reg reg);
223#define rsnd_is_gen1(s) ((s)->info->flags & RSND_GEN1) 219#define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1)
224#define rsnd_is_gen2(s) ((s)->info->flags & RSND_GEN2) 220#define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2)
225 221
226/* 222/*
227 * R-Car ADG 223 * R-Car ADG
@@ -285,6 +281,7 @@ int rsnd_scu_probe(struct platform_device *pdev,
285void rsnd_scu_remove(struct platform_device *pdev, 281void rsnd_scu_remove(struct platform_device *pdev,
286 struct rsnd_priv *priv); 282 struct rsnd_priv *priv);
287struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id); 283struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id);
284bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod);
288#define rsnd_scu_nr(priv) ((priv)->scu_nr) 285#define rsnd_scu_nr(priv) ((priv)->scu_nr)
289 286
290/* 287/*
diff --git a/sound/soc/sh/rcar/scu.c b/sound/soc/sh/rcar/scu.c
index 2df2e9150b89..f4453e33a847 100644
--- a/sound/soc/sh/rcar/scu.c
+++ b/sound/soc/sh/rcar/scu.c
@@ -146,20 +146,26 @@ static int rsnd_scu_set_hpbif(struct rsnd_priv *priv,
146 return 0; 146 return 0;
147} 147}
148 148
149bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod)
150{
151 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
152 u32 flags = rsnd_scu_mode_flags(scu);
153
154 return !!(flags & RSND_SCU_USE_HPBIF);
155}
156
149static int rsnd_scu_start(struct rsnd_mod *mod, 157static int rsnd_scu_start(struct rsnd_mod *mod,
150 struct rsnd_dai *rdai, 158 struct rsnd_dai *rdai,
151 struct rsnd_dai_stream *io) 159 struct rsnd_dai_stream *io)
152{ 160{
153 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 161 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
154 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
155 struct device *dev = rsnd_priv_to_dev(priv); 162 struct device *dev = rsnd_priv_to_dev(priv);
156 u32 flags = rsnd_scu_mode_flags(scu);
157 int ret; 163 int ret;
158 164
159 /* 165 /*
160 * SCU will be used if it has RSND_SCU_USE_HPBIF flags 166 * SCU will be used if it has RSND_SCU_USE_HPBIF flags
161 */ 167 */
162 if (!(flags & RSND_SCU_USE_HPBIF)) { 168 if (!rsnd_scu_hpbif_is_enable(mod)) {
163 /* it use PIO transter */ 169 /* it use PIO transter */
164 dev_dbg(dev, "%s%d is not used\n", 170 dev_dbg(dev, "%s%d is not used\n",
165 rsnd_mod_name(mod), rsnd_mod_id(mod)); 171 rsnd_mod_name(mod), rsnd_mod_id(mod));
@@ -192,7 +198,8 @@ static struct rsnd_mod_ops rsnd_scu_ops = {
192 198
193struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id) 199struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id)
194{ 200{
195 BUG_ON(id < 0 || id >= rsnd_scu_nr(priv)); 201 if (WARN_ON(id < 0 || id >= rsnd_scu_nr(priv)))
202 id = 0;
196 203
197 return &((struct rsnd_scu *)(priv->scu) + id)->mod; 204 return &((struct rsnd_scu *)(priv->scu) + id)->mod;
198} 205}
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c
index fae26d3f79d2..5ac20cd5e006 100644
--- a/sound/soc/sh/rcar/ssi.c
+++ b/sound/soc/sh/rcar/ssi.c
@@ -101,29 +101,30 @@ struct rsnd_ssiu {
101#define rsnd_ssi_to_ssiu(ssi)\ 101#define rsnd_ssi_to_ssiu(ssi)\
102 (((struct rsnd_ssiu *)((ssi) - rsnd_mod_id(&(ssi)->mod))) - 1) 102 (((struct rsnd_ssiu *)((ssi) - rsnd_mod_id(&(ssi)->mod))) - 1)
103 103
104static void rsnd_ssi_mode_init(struct rsnd_priv *priv, 104static void rsnd_ssi_mode_set(struct rsnd_priv *priv,
105 struct rsnd_ssiu *ssiu) 105 struct rsnd_dai *rdai,
106 struct rsnd_ssi *ssi)
106{ 107{
107 struct device *dev = rsnd_priv_to_dev(priv); 108 struct device *dev = rsnd_priv_to_dev(priv);
108 struct rsnd_ssi *ssi; 109 struct rsnd_mod *scu;
110 struct rsnd_ssiu *ssiu = rsnd_ssi_to_ssiu(ssi);
111 int id = rsnd_mod_id(&ssi->mod);
109 u32 flags; 112 u32 flags;
110 u32 val; 113 u32 val;
111 int i; 114
115 scu = rsnd_scu_mod_get(priv, rsnd_mod_id(&ssi->mod));
112 116
113 /* 117 /*
114 * SSI_MODE0 118 * SSI_MODE0
115 */ 119 */
116 ssiu->ssi_mode0 = 0; 120
117 for_each_rsnd_ssi(ssi, priv, i) { 121 /* see also BUSIF_MODE */
118 flags = rsnd_ssi_mode_flags(ssi); 122 if (rsnd_scu_hpbif_is_enable(scu)) {
119 123 ssiu->ssi_mode0 &= ~(1 << id);
120 /* see also BUSIF_MODE */ 124 dev_dbg(dev, "SSI%d uses DEPENDENT mode\n", id);
121 if (!(flags & RSND_SSI_DEPENDENT)) { 125 } else {
122 ssiu->ssi_mode0 |= (1 << i); 126 ssiu->ssi_mode0 |= (1 << id);
123 dev_dbg(dev, "SSI%d uses INDEPENDENT mode\n", i); 127 dev_dbg(dev, "SSI%d uses INDEPENDENT mode\n", id);
124 } else {
125 dev_dbg(dev, "SSI%d uses DEPENDENT mode\n", i);
126 }
127 } 128 }
128 129
129 /* 130 /*
@@ -132,7 +133,7 @@ static void rsnd_ssi_mode_init(struct rsnd_priv *priv,
132#define ssi_parent_set(p, sync, adg, ext) \ 133#define ssi_parent_set(p, sync, adg, ext) \
133 do { \ 134 do { \
134 ssi->parent = ssiu->ssi + p; \ 135 ssi->parent = ssiu->ssi + p; \
135 if (flags & RSND_SSI_CLK_FROM_ADG) \ 136 if (rsnd_rdai_is_clk_master(rdai)) \
136 val = adg; \ 137 val = adg; \
137 else \ 138 else \
138 val = ext; \ 139 val = ext; \
@@ -140,15 +141,11 @@ static void rsnd_ssi_mode_init(struct rsnd_priv *priv,
140 val |= sync; \ 141 val |= sync; \
141 } while (0) 142 } while (0)
142 143
143 ssiu->ssi_mode1 = 0; 144 flags = rsnd_ssi_mode_flags(ssi);
144 for_each_rsnd_ssi(ssi, priv, i) { 145 if (flags & RSND_SSI_CLK_PIN_SHARE) {
145 flags = rsnd_ssi_mode_flags(ssi);
146
147 if (!(flags & RSND_SSI_CLK_PIN_SHARE))
148 continue;
149 146
150 val = 0; 147 val = 0;
151 switch (i) { 148 switch (id) {
152 case 1: 149 case 1:
153 ssi_parent_set(0, (1 << 4), (0x2 << 0), (0x1 << 0)); 150 ssi_parent_set(0, (1 << 4), (0x2 << 0), (0x1 << 0));
154 break; 151 break;
@@ -165,11 +162,6 @@ static void rsnd_ssi_mode_init(struct rsnd_priv *priv,
165 162
166 ssiu->ssi_mode1 |= val; 163 ssiu->ssi_mode1 |= val;
167 } 164 }
168}
169
170static void rsnd_ssi_mode_set(struct rsnd_ssi *ssi)
171{
172 struct rsnd_ssiu *ssiu = rsnd_ssi_to_ssiu(ssi);
173 165
174 rsnd_mod_write(&ssi->mod, SSI_MODE0, ssiu->ssi_mode0); 166 rsnd_mod_write(&ssi->mod, SSI_MODE0, ssiu->ssi_mode0);
175 rsnd_mod_write(&ssi->mod, SSI_MODE1, ssiu->ssi_mode1); 167 rsnd_mod_write(&ssi->mod, SSI_MODE1, ssiu->ssi_mode1);
@@ -379,7 +371,7 @@ static int rsnd_ssi_init(struct rsnd_mod *mod,
379 ssi->cr_own = cr; 371 ssi->cr_own = cr;
380 ssi->err = -1; /* ignore 1st error */ 372 ssi->err = -1; /* ignore 1st error */
381 373
382 rsnd_ssi_mode_set(ssi); 374 rsnd_ssi_mode_set(priv, rdai, ssi);
383 375
384 dev_dbg(dev, "%s.%d init\n", rsnd_mod_name(mod), rsnd_mod_id(mod)); 376 dev_dbg(dev, "%s.%d init\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
385 377
@@ -619,7 +611,8 @@ struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv,
619 611
620struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id) 612struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
621{ 613{
622 BUG_ON(id < 0 || id >= rsnd_ssi_nr(priv)); 614 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
615 id = 0;
623 616
624 return &(((struct rsnd_ssiu *)(priv->ssiu))->ssi + id)->mod; 617 return &(((struct rsnd_ssiu *)(priv->ssiu))->ssi + id)->mod;
625} 618}
@@ -706,8 +699,6 @@ int rsnd_ssi_probe(struct platform_device *pdev,
706 rsnd_mod_init(priv, &ssi->mod, ops, i); 699 rsnd_mod_init(priv, &ssi->mod, ops, i);
707 } 700 }
708 701
709 rsnd_ssi_mode_init(priv, ssiu);
710
711 dev_dbg(dev, "ssi probed\n"); 702 dev_dbg(dev, "ssi probed\n");
712 703
713 return 0; 704 return 0;
diff --git a/sound/soc/sh/siu_dai.c b/sound/soc/sh/siu_dai.c
index 9dc24ffa892a..d55babee14f8 100644
--- a/sound/soc/sh/siu_dai.c
+++ b/sound/soc/sh/siu_dai.c
@@ -543,7 +543,8 @@ static void siu_dai_shutdown(struct snd_pcm_substream *substream,
543 /* Stop the siu if the other stream is not using it */ 543 /* Stop the siu if the other stream is not using it */
544 if (!port_info->play_cap) { 544 if (!port_info->play_cap) {
545 /* during stmread or stmwrite ? */ 545 /* during stmread or stmwrite ? */
546 BUG_ON(port_info->playback.rw_flg || port_info->capture.rw_flg); 546 if (WARN_ON(port_info->playback.rw_flg || port_info->capture.rw_flg))
547 return;
547 siu_dai_spbstop(port_info); 548 siu_dai_spbstop(port_info);
548 siu_dai_stop(port_info); 549 siu_dai_stop(port_info);
549 } 550 }
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index e72f55428f0b..375dc6dfba4e 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -11,12 +11,9 @@
11 * option) any later version. 11 * option) any later version.
12 */ 12 */
13 13
14#include <linux/i2c.h>
15#include <linux/spi/spi.h>
16#include <sound/soc.h> 14#include <sound/soc.h>
17#include <linux/bitmap.h>
18#include <linux/rbtree.h>
19#include <linux/export.h> 15#include <linux/export.h>
16#include <linux/slab.h>
20 17
21#include <trace/events/asoc.h> 18#include <trace/events/asoc.h>
22 19
@@ -39,7 +36,8 @@ static bool snd_soc_set_cache_val(void *base, unsigned int idx,
39 break; 36 break;
40 } 37 }
41 default: 38 default:
42 BUG(); 39 WARN(1, "Invalid word_size %d\n", word_size);
40 break;
43 } 41 }
44 return false; 42 return false;
45} 43}
@@ -60,132 +58,49 @@ static unsigned int snd_soc_get_cache_val(const void *base, unsigned int idx,
60 return cache[idx]; 58 return cache[idx];
61 } 59 }
62 default: 60 default:
63 BUG(); 61 WARN(1, "Invalid word_size %d\n", word_size);
62 break;
64 } 63 }
65 /* unreachable */ 64 /* unreachable */
66 return -1; 65 return -1;
67} 66}
68 67
69static int snd_soc_flat_cache_sync(struct snd_soc_codec *codec) 68int snd_soc_cache_init(struct snd_soc_codec *codec)
70{ 69{
71 int i; 70 const struct snd_soc_codec_driver *codec_drv = codec->driver;
72 int ret; 71 size_t reg_size;
73 const struct snd_soc_codec_driver *codec_drv;
74 unsigned int val;
75 72
76 codec_drv = codec->driver; 73 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
77 for (i = 0; i < codec_drv->reg_cache_size; ++i) {
78 ret = snd_soc_cache_read(codec, i, &val);
79 if (ret)
80 return ret;
81 if (codec->reg_def_copy)
82 if (snd_soc_get_cache_val(codec->reg_def_copy,
83 i, codec_drv->reg_word_size) == val)
84 continue;
85
86 WARN_ON(!snd_soc_codec_writable_register(codec, i));
87 74
88 ret = snd_soc_write(codec, i, val); 75 mutex_init(&codec->cache_rw_mutex);
89 if (ret)
90 return ret;
91 dev_dbg(codec->dev, "ASoC: Synced register %#x, value = %#x\n",
92 i, val);
93 }
94 return 0;
95}
96
97static int snd_soc_flat_cache_write(struct snd_soc_codec *codec,
98 unsigned int reg, unsigned int value)
99{
100 snd_soc_set_cache_val(codec->reg_cache, reg, value,
101 codec->driver->reg_word_size);
102 return 0;
103}
104
105static int snd_soc_flat_cache_read(struct snd_soc_codec *codec,
106 unsigned int reg, unsigned int *value)
107{
108 *value = snd_soc_get_cache_val(codec->reg_cache, reg,
109 codec->driver->reg_word_size);
110 return 0;
111}
112 76
113static int snd_soc_flat_cache_exit(struct snd_soc_codec *codec) 77 dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n",
114{ 78 codec->name);
115 if (!codec->reg_cache)
116 return 0;
117 kfree(codec->reg_cache);
118 codec->reg_cache = NULL;
119 return 0;
120}
121 79
122static int snd_soc_flat_cache_init(struct snd_soc_codec *codec) 80 if (codec_drv->reg_cache_default)
123{ 81 codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
124 if (codec->reg_def_copy) 82 reg_size, GFP_KERNEL);
125 codec->reg_cache = kmemdup(codec->reg_def_copy,
126 codec->reg_size, GFP_KERNEL);
127 else 83 else
128 codec->reg_cache = kzalloc(codec->reg_size, GFP_KERNEL); 84 codec->reg_cache = kzalloc(reg_size, GFP_KERNEL);
129 if (!codec->reg_cache) 85 if (!codec->reg_cache)
130 return -ENOMEM; 86 return -ENOMEM;
131 87
132 return 0; 88 return 0;
133} 89}
134 90
135/* an array of all supported compression types */
136static const struct snd_soc_cache_ops cache_types[] = {
137 /* Flat *must* be the first entry for fallback */
138 {
139 .id = SND_SOC_FLAT_COMPRESSION,
140 .name = "flat",
141 .init = snd_soc_flat_cache_init,
142 .exit = snd_soc_flat_cache_exit,
143 .read = snd_soc_flat_cache_read,
144 .write = snd_soc_flat_cache_write,
145 .sync = snd_soc_flat_cache_sync
146 },
147};
148
149int snd_soc_cache_init(struct snd_soc_codec *codec)
150{
151 int i;
152
153 for (i = 0; i < ARRAY_SIZE(cache_types); ++i)
154 if (cache_types[i].id == codec->compress_type)
155 break;
156
157 /* Fall back to flat compression */
158 if (i == ARRAY_SIZE(cache_types)) {
159 dev_warn(codec->dev, "ASoC: Could not match compress type: %d\n",
160 codec->compress_type);
161 i = 0;
162 }
163
164 mutex_init(&codec->cache_rw_mutex);
165 codec->cache_ops = &cache_types[i];
166
167 if (codec->cache_ops->init) {
168 if (codec->cache_ops->name)
169 dev_dbg(codec->dev, "ASoC: Initializing %s cache for %s codec\n",
170 codec->cache_ops->name, codec->name);
171 return codec->cache_ops->init(codec);
172 }
173 return -ENOSYS;
174}
175
176/* 91/*
177 * NOTE: keep in mind that this function might be called 92 * NOTE: keep in mind that this function might be called
178 * multiple times. 93 * multiple times.
179 */ 94 */
180int snd_soc_cache_exit(struct snd_soc_codec *codec) 95int snd_soc_cache_exit(struct snd_soc_codec *codec)
181{ 96{
182 if (codec->cache_ops && codec->cache_ops->exit) { 97 dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n",
183 if (codec->cache_ops->name) 98 codec->name);
184 dev_dbg(codec->dev, "ASoC: Destroying %s cache for %s codec\n", 99 if (!codec->reg_cache)
185 codec->cache_ops->name, codec->name); 100 return 0;
186 return codec->cache_ops->exit(codec); 101 kfree(codec->reg_cache);
187 } 102 codec->reg_cache = NULL;
188 return -ENOSYS; 103 return 0;
189} 104}
190 105
191/** 106/**
@@ -198,18 +113,15 @@ int snd_soc_cache_exit(struct snd_soc_codec *codec)
198int snd_soc_cache_read(struct snd_soc_codec *codec, 113int snd_soc_cache_read(struct snd_soc_codec *codec,
199 unsigned int reg, unsigned int *value) 114 unsigned int reg, unsigned int *value)
200{ 115{
201 int ret; 116 if (!value)
117 return -EINVAL;
202 118
203 mutex_lock(&codec->cache_rw_mutex); 119 mutex_lock(&codec->cache_rw_mutex);
204 120 *value = snd_soc_get_cache_val(codec->reg_cache, reg,
205 if (value && codec->cache_ops && codec->cache_ops->read) { 121 codec->driver->reg_word_size);
206 ret = codec->cache_ops->read(codec, reg, value);
207 mutex_unlock(&codec->cache_rw_mutex);
208 return ret;
209 }
210
211 mutex_unlock(&codec->cache_rw_mutex); 122 mutex_unlock(&codec->cache_rw_mutex);
212 return -ENOSYS; 123
124 return 0;
213} 125}
214EXPORT_SYMBOL_GPL(snd_soc_cache_read); 126EXPORT_SYMBOL_GPL(snd_soc_cache_read);
215 127
@@ -223,20 +135,42 @@ EXPORT_SYMBOL_GPL(snd_soc_cache_read);
223int snd_soc_cache_write(struct snd_soc_codec *codec, 135int snd_soc_cache_write(struct snd_soc_codec *codec,
224 unsigned int reg, unsigned int value) 136 unsigned int reg, unsigned int value)
225{ 137{
138 mutex_lock(&codec->cache_rw_mutex);
139 snd_soc_set_cache_val(codec->reg_cache, reg, value,
140 codec->driver->reg_word_size);
141 mutex_unlock(&codec->cache_rw_mutex);
142
143 return 0;
144}
145EXPORT_SYMBOL_GPL(snd_soc_cache_write);
146
147static int snd_soc_flat_cache_sync(struct snd_soc_codec *codec)
148{
149 int i;
226 int ret; 150 int ret;
151 const struct snd_soc_codec_driver *codec_drv;
152 unsigned int val;
227 153
228 mutex_lock(&codec->cache_rw_mutex); 154 codec_drv = codec->driver;
155 for (i = 0; i < codec_drv->reg_cache_size; ++i) {
156 ret = snd_soc_cache_read(codec, i, &val);
157 if (ret)
158 return ret;
159 if (codec_drv->reg_cache_default)
160 if (snd_soc_get_cache_val(codec_drv->reg_cache_default,
161 i, codec_drv->reg_word_size) == val)
162 continue;
229 163
230 if (codec->cache_ops && codec->cache_ops->write) { 164 WARN_ON(!snd_soc_codec_writable_register(codec, i));
231 ret = codec->cache_ops->write(codec, reg, value);
232 mutex_unlock(&codec->cache_rw_mutex);
233 return ret;
234 }
235 165
236 mutex_unlock(&codec->cache_rw_mutex); 166 ret = snd_soc_write(codec, i, val);
237 return -ENOSYS; 167 if (ret)
168 return ret;
169 dev_dbg(codec->dev, "ASoC: Synced register %#x, value = %#x\n",
170 i, val);
171 }
172 return 0;
238} 173}
239EXPORT_SYMBOL_GPL(snd_soc_cache_write);
240 174
241/** 175/**
242 * snd_soc_cache_sync: Sync the register cache with the hardware. 176 * snd_soc_cache_sync: Sync the register cache with the hardware.
@@ -249,92 +183,19 @@ EXPORT_SYMBOL_GPL(snd_soc_cache_write);
249 */ 183 */
250int snd_soc_cache_sync(struct snd_soc_codec *codec) 184int snd_soc_cache_sync(struct snd_soc_codec *codec)
251{ 185{
186 const char *name = "flat";
252 int ret; 187 int ret;
253 const char *name;
254 188
255 if (!codec->cache_sync) { 189 if (!codec->cache_sync)
256 return 0; 190 return 0;
257 }
258
259 if (!codec->cache_ops || !codec->cache_ops->sync)
260 return -ENOSYS;
261 191
262 if (codec->cache_ops->name) 192 dev_dbg(codec->dev, "ASoC: Syncing cache for %s codec\n",
263 name = codec->cache_ops->name; 193 codec->name);
264 else
265 name = "unknown";
266
267 if (codec->cache_ops->name)
268 dev_dbg(codec->dev, "ASoC: Syncing %s cache for %s codec\n",
269 codec->cache_ops->name, codec->name);
270 trace_snd_soc_cache_sync(codec, name, "start"); 194 trace_snd_soc_cache_sync(codec, name, "start");
271 ret = codec->cache_ops->sync(codec); 195 ret = snd_soc_flat_cache_sync(codec);
272 if (!ret) 196 if (!ret)
273 codec->cache_sync = 0; 197 codec->cache_sync = 0;
274 trace_snd_soc_cache_sync(codec, name, "end"); 198 trace_snd_soc_cache_sync(codec, name, "end");
275 return ret; 199 return ret;
276} 200}
277EXPORT_SYMBOL_GPL(snd_soc_cache_sync); 201EXPORT_SYMBOL_GPL(snd_soc_cache_sync);
278
279static int snd_soc_get_reg_access_index(struct snd_soc_codec *codec,
280 unsigned int reg)
281{
282 const struct snd_soc_codec_driver *codec_drv;
283 unsigned int min, max, index;
284
285 codec_drv = codec->driver;
286 min = 0;
287 max = codec_drv->reg_access_size - 1;
288 do {
289 index = (min + max) / 2;
290 if (codec_drv->reg_access_default[index].reg == reg)
291 return index;
292 if (codec_drv->reg_access_default[index].reg < reg)
293 min = index + 1;
294 else
295 max = index;
296 } while (min <= max);
297 return -1;
298}
299
300int snd_soc_default_volatile_register(struct snd_soc_codec *codec,
301 unsigned int reg)
302{
303 int index;
304
305 if (reg >= codec->driver->reg_cache_size)
306 return 1;
307 index = snd_soc_get_reg_access_index(codec, reg);
308 if (index < 0)
309 return 0;
310 return codec->driver->reg_access_default[index].vol;
311}
312EXPORT_SYMBOL_GPL(snd_soc_default_volatile_register);
313
314int snd_soc_default_readable_register(struct snd_soc_codec *codec,
315 unsigned int reg)
316{
317 int index;
318
319 if (reg >= codec->driver->reg_cache_size)
320 return 1;
321 index = snd_soc_get_reg_access_index(codec, reg);
322 if (index < 0)
323 return 0;
324 return codec->driver->reg_access_default[index].read;
325}
326EXPORT_SYMBOL_GPL(snd_soc_default_readable_register);
327
328int snd_soc_default_writable_register(struct snd_soc_codec *codec,
329 unsigned int reg)
330{
331 int index;
332
333 if (reg >= codec->driver->reg_cache_size)
334 return 1;
335 index = snd_soc_get_reg_access_index(codec, reg);
336 if (index < 0)
337 return 0;
338 return codec->driver->reg_access_default[index].write;
339}
340EXPORT_SYMBOL_GPL(snd_soc_default_writable_register);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4d0561312f3b..4e53d87e881d 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -662,6 +662,8 @@ int snd_soc_suspend(struct device *dev)
662 codec->cache_sync = 1; 662 codec->cache_sync = 1;
663 if (codec->using_regmap) 663 if (codec->using_regmap)
664 regcache_mark_dirty(codec->control_data); 664 regcache_mark_dirty(codec->control_data);
665 /* deactivate pins to sleep state */
666 pinctrl_pm_select_sleep_state(codec->dev);
665 break; 667 break;
666 default: 668 default:
667 dev_dbg(codec->dev, 669 dev_dbg(codec->dev,
@@ -679,6 +681,9 @@ int snd_soc_suspend(struct device *dev)
679 681
680 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) 682 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
681 cpu_dai->driver->suspend(cpu_dai); 683 cpu_dai->driver->suspend(cpu_dai);
684
685 /* deactivate pins to sleep state */
686 pinctrl_pm_select_sleep_state(cpu_dai->dev);
682 } 687 }
683 688
684 if (card->suspend_post) 689 if (card->suspend_post)
@@ -807,6 +812,16 @@ int snd_soc_resume(struct device *dev)
807 if (list_empty(&card->codec_dev_list)) 812 if (list_empty(&card->codec_dev_list))
808 return 0; 813 return 0;
809 814
815 /* activate pins from sleep state */
816 for (i = 0; i < card->num_rtd; i++) {
817 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
818 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
819 if (cpu_dai->active)
820 pinctrl_pm_select_default_state(cpu_dai->dev);
821 if (codec_dai->active)
822 pinctrl_pm_select_default_state(codec_dai->dev);
823 }
824
810 /* AC97 devices might have other drivers hanging off them so 825 /* AC97 devices might have other drivers hanging off them so
811 * need to resume immediately. Other drivers don't have that 826 * need to resume immediately. Other drivers don't have that
812 * problem and may take a substantial amount of time to resume 827 * problem and may take a substantial amount of time to resume
@@ -1380,7 +1395,6 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1380 return -ENODEV; 1395 return -ENODEV;
1381 1396
1382 list_add(&cpu_dai->dapm.list, &card->dapm_list); 1397 list_add(&cpu_dai->dapm.list, &card->dapm_list);
1383 snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai);
1384 } 1398 }
1385 1399
1386 if (cpu_dai->driver->probe) { 1400 if (cpu_dai->driver->probe) {
@@ -1590,17 +1604,13 @@ static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1590 soc_remove_codec(codec); 1604 soc_remove_codec(codec);
1591} 1605}
1592 1606
1593static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, 1607static int snd_soc_init_codec_cache(struct snd_soc_codec *codec)
1594 enum snd_soc_compress_type compress_type)
1595{ 1608{
1596 int ret; 1609 int ret;
1597 1610
1598 if (codec->cache_init) 1611 if (codec->cache_init)
1599 return 0; 1612 return 0;
1600 1613
1601 /* override the compress_type if necessary */
1602 if (compress_type && codec->compress_type != compress_type)
1603 codec->compress_type = compress_type;
1604 ret = snd_soc_cache_init(codec); 1614 ret = snd_soc_cache_init(codec);
1605 if (ret < 0) { 1615 if (ret < 0) {
1606 dev_err(codec->dev, 1616 dev_err(codec->dev,
@@ -1615,8 +1625,6 @@ static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1615static int snd_soc_instantiate_card(struct snd_soc_card *card) 1625static int snd_soc_instantiate_card(struct snd_soc_card *card)
1616{ 1626{
1617 struct snd_soc_codec *codec; 1627 struct snd_soc_codec *codec;
1618 struct snd_soc_codec_conf *codec_conf;
1619 enum snd_soc_compress_type compress_type;
1620 struct snd_soc_dai_link *dai_link; 1628 struct snd_soc_dai_link *dai_link;
1621 int ret, i, order, dai_fmt; 1629 int ret, i, order, dai_fmt;
1622 1630
@@ -1640,19 +1648,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1640 list_for_each_entry(codec, &codec_list, list) { 1648 list_for_each_entry(codec, &codec_list, list) {
1641 if (codec->cache_init) 1649 if (codec->cache_init)
1642 continue; 1650 continue;
1643 /* by default we don't override the compress_type */ 1651 ret = snd_soc_init_codec_cache(codec);
1644 compress_type = 0;
1645 /* check to see if we need to override the compress_type */
1646 for (i = 0; i < card->num_configs; ++i) {
1647 codec_conf = &card->codec_conf[i];
1648 if (!strcmp(codec->name, codec_conf->dev_name)) {
1649 compress_type = codec_conf->compress_type;
1650 if (compress_type && compress_type
1651 != codec->compress_type)
1652 break;
1653 }
1654 }
1655 ret = snd_soc_init_codec_cache(codec, compress_type);
1656 if (ret < 0) 1652 if (ret < 0)
1657 goto base_error; 1653 goto base_error;
1658 } 1654 }
@@ -1948,6 +1944,14 @@ int snd_soc_poweroff(struct device *dev)
1948 1944
1949 snd_soc_dapm_shutdown(card); 1945 snd_soc_dapm_shutdown(card);
1950 1946
1947 /* deactivate pins to sleep state */
1948 for (i = 0; i < card->num_rtd; i++) {
1949 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1950 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
1951 pinctrl_pm_select_sleep_state(codec_dai->dev);
1952 pinctrl_pm_select_sleep_state(cpu_dai->dev);
1953 }
1954
1951 return 0; 1955 return 0;
1952} 1956}
1953EXPORT_SYMBOL_GPL(snd_soc_poweroff); 1957EXPORT_SYMBOL_GPL(snd_soc_poweroff);
@@ -2298,13 +2302,6 @@ unsigned int snd_soc_write(struct snd_soc_codec *codec,
2298} 2302}
2299EXPORT_SYMBOL_GPL(snd_soc_write); 2303EXPORT_SYMBOL_GPL(snd_soc_write);
2300 2304
2301unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
2302 unsigned int reg, const void *data, size_t len)
2303{
2304 return codec->bulk_write_raw(codec, reg, data, len);
2305}
2306EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
2307
2308/** 2305/**
2309 * snd_soc_update_bits - update codec register bits 2306 * snd_soc_update_bits - update codec register bits
2310 * @codec: audio codec 2307 * @codec: audio codec
@@ -2577,8 +2574,9 @@ int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2577 2574
2578 if (uinfo->value.enumerated.item > e->max - 1) 2575 if (uinfo->value.enumerated.item > e->max - 1)
2579 uinfo->value.enumerated.item = e->max - 1; 2576 uinfo->value.enumerated.item = e->max - 1;
2580 strcpy(uinfo->value.enumerated.name, 2577 strlcpy(uinfo->value.enumerated.name,
2581 e->texts[uinfo->value.enumerated.item]); 2578 e->texts[uinfo->value.enumerated.item],
2579 sizeof(uinfo->value.enumerated.name));
2582 return 0; 2580 return 0;
2583} 2581}
2584EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); 2582EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
@@ -3577,6 +3575,22 @@ int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
3577EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); 3575EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
3578 3576
3579/** 3577/**
3578 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
3579 * @dai: DAI
3580 * @ratio Ratio of BCLK to Sample rate.
3581 *
3582 * Configures the DAI for a preset BCLK to sample rate ratio.
3583 */
3584int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
3585{
3586 if (dai->driver && dai->driver->ops->set_bclk_ratio)
3587 return dai->driver->ops->set_bclk_ratio(dai, ratio);
3588 else
3589 return -EINVAL;
3590}
3591EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
3592
3593/**
3580 * snd_soc_dai_set_fmt - configure DAI hardware audio format. 3594 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3581 * @dai: DAI 3595 * @dai: DAI
3582 * @fmt: SND_SOC_DAIFMT_ format value. 3596 * @fmt: SND_SOC_DAIFMT_ format value.
@@ -3776,6 +3790,16 @@ int snd_soc_register_card(struct snd_soc_card *card)
3776 if (ret != 0) 3790 if (ret != 0)
3777 soc_cleanup_card_debugfs(card); 3791 soc_cleanup_card_debugfs(card);
3778 3792
3793 /* deactivate pins to sleep state */
3794 for (i = 0; i < card->num_rtd; i++) {
3795 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
3796 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
3797 if (!codec_dai->active)
3798 pinctrl_pm_select_sleep_state(codec_dai->dev);
3799 if (!cpu_dai->active)
3800 pinctrl_pm_select_sleep_state(cpu_dai->dev);
3801 }
3802
3779 return ret; 3803 return ret;
3780} 3804}
3781EXPORT_SYMBOL_GPL(snd_soc_register_card); 3805EXPORT_SYMBOL_GPL(snd_soc_register_card);
@@ -4021,6 +4045,113 @@ static void snd_soc_unregister_dais(struct device *dev, size_t count)
4021} 4045}
4022 4046
4023/** 4047/**
4048 * snd_soc_register_component - Register a component with the ASoC core
4049 *
4050 */
4051static int
4052__snd_soc_register_component(struct device *dev,
4053 struct snd_soc_component *cmpnt,
4054 const struct snd_soc_component_driver *cmpnt_drv,
4055 struct snd_soc_dai_driver *dai_drv,
4056 int num_dai, bool allow_single_dai)
4057{
4058 int ret;
4059
4060 dev_dbg(dev, "component register %s\n", dev_name(dev));
4061
4062 if (!cmpnt) {
4063 dev_err(dev, "ASoC: Failed to connecting component\n");
4064 return -ENOMEM;
4065 }
4066
4067 cmpnt->name = fmt_single_name(dev, &cmpnt->id);
4068 if (!cmpnt->name) {
4069 dev_err(dev, "ASoC: Failed to simplifying name\n");
4070 return -ENOMEM;
4071 }
4072
4073 cmpnt->dev = dev;
4074 cmpnt->driver = cmpnt_drv;
4075 cmpnt->dai_drv = dai_drv;
4076 cmpnt->num_dai = num_dai;
4077
4078 /*
4079 * snd_soc_register_dai() uses fmt_single_name(), and
4080 * snd_soc_register_dais() uses fmt_multiple_name()
4081 * for dai->name which is used for name based matching
4082 *
4083 * this function is used from cpu/codec.
4084 * allow_single_dai flag can ignore "codec" driver reworking
4085 * since it had been used snd_soc_register_dais(),
4086 */
4087 if ((1 == num_dai) && allow_single_dai)
4088 ret = snd_soc_register_dai(dev, dai_drv);
4089 else
4090 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4091 if (ret < 0) {
4092 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4093 goto error_component_name;
4094 }
4095
4096 mutex_lock(&client_mutex);
4097 list_add(&cmpnt->list, &component_list);
4098 mutex_unlock(&client_mutex);
4099
4100 dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name);
4101
4102 return ret;
4103
4104error_component_name:
4105 kfree(cmpnt->name);
4106
4107 return ret;
4108}
4109
4110int snd_soc_register_component(struct device *dev,
4111 const struct snd_soc_component_driver *cmpnt_drv,
4112 struct snd_soc_dai_driver *dai_drv,
4113 int num_dai)
4114{
4115 struct snd_soc_component *cmpnt;
4116
4117 cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL);
4118 if (!cmpnt) {
4119 dev_err(dev, "ASoC: Failed to allocate memory\n");
4120 return -ENOMEM;
4121 }
4122
4123 return __snd_soc_register_component(dev, cmpnt, cmpnt_drv,
4124 dai_drv, num_dai, true);
4125}
4126EXPORT_SYMBOL_GPL(snd_soc_register_component);
4127
4128/**
4129 * snd_soc_unregister_component - Unregister a component from the ASoC core
4130 *
4131 */
4132void snd_soc_unregister_component(struct device *dev)
4133{
4134 struct snd_soc_component *cmpnt;
4135
4136 list_for_each_entry(cmpnt, &component_list, list) {
4137 if (dev == cmpnt->dev)
4138 goto found;
4139 }
4140 return;
4141
4142found:
4143 snd_soc_unregister_dais(dev, cmpnt->num_dai);
4144
4145 mutex_lock(&client_mutex);
4146 list_del(&cmpnt->list);
4147 mutex_unlock(&client_mutex);
4148
4149 dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name);
4150 kfree(cmpnt->name);
4151}
4152EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
4153
4154/**
4024 * snd_soc_add_platform - Add a platform to the ASoC core 4155 * snd_soc_add_platform - Add a platform to the ASoC core
4025 * @dev: The parent device for the platform 4156 * @dev: The parent device for the platform
4026 * @platform: The platform to add 4157 * @platform: The platform to add
@@ -4166,7 +4297,6 @@ int snd_soc_register_codec(struct device *dev,
4166 struct snd_soc_dai_driver *dai_drv, 4297 struct snd_soc_dai_driver *dai_drv,
4167 int num_dai) 4298 int num_dai)
4168{ 4299{
4169 size_t reg_size;
4170 struct snd_soc_codec *codec; 4300 struct snd_soc_codec *codec;
4171 int ret, i; 4301 int ret, i;
4172 4302
@@ -4183,11 +4313,6 @@ int snd_soc_register_codec(struct device *dev,
4183 goto fail_codec; 4313 goto fail_codec;
4184 } 4314 }
4185 4315
4186 if (codec_drv->compress_type)
4187 codec->compress_type = codec_drv->compress_type;
4188 else
4189 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
4190
4191 codec->write = codec_drv->write; 4316 codec->write = codec_drv->write;
4192 codec->read = codec_drv->read; 4317 codec->read = codec_drv->read;
4193 codec->volatile_register = codec_drv->volatile_register; 4318 codec->volatile_register = codec_drv->volatile_register;
@@ -4204,35 +4329,6 @@ int snd_soc_register_codec(struct device *dev,
4204 codec->num_dai = num_dai; 4329 codec->num_dai = num_dai;
4205 mutex_init(&codec->mutex); 4330 mutex_init(&codec->mutex);
4206 4331
4207 /* allocate CODEC register cache */
4208 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
4209 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
4210 codec->reg_size = reg_size;
4211 /* it is necessary to make a copy of the default register cache
4212 * because in the case of using a compression type that requires
4213 * the default register cache to be marked as the
4214 * kernel might have freed the array by the time we initialize
4215 * the cache.
4216 */
4217 if (codec_drv->reg_cache_default) {
4218 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
4219 reg_size, GFP_KERNEL);
4220 if (!codec->reg_def_copy) {
4221 ret = -ENOMEM;
4222 goto fail_codec_name;
4223 }
4224 }
4225 }
4226
4227 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
4228 if (!codec->volatile_register)
4229 codec->volatile_register = snd_soc_default_volatile_register;
4230 if (!codec->readable_register)
4231 codec->readable_register = snd_soc_default_readable_register;
4232 if (!codec->writable_register)
4233 codec->writable_register = snd_soc_default_writable_register;
4234 }
4235
4236 for (i = 0; i < num_dai; i++) { 4332 for (i = 0; i < num_dai; i++) {
4237 fixup_codec_formats(&dai_drv[i].playback); 4333 fixup_codec_formats(&dai_drv[i].playback);
4238 fixup_codec_formats(&dai_drv[i].capture); 4334 fixup_codec_formats(&dai_drv[i].capture);
@@ -4242,10 +4338,12 @@ int snd_soc_register_codec(struct device *dev,
4242 list_add(&codec->list, &codec_list); 4338 list_add(&codec->list, &codec_list);
4243 mutex_unlock(&client_mutex); 4339 mutex_unlock(&client_mutex);
4244 4340
4245 /* register any DAIs */ 4341 /* register component */
4246 ret = snd_soc_register_dais(dev, dai_drv, num_dai); 4342 ret = __snd_soc_register_component(dev, &codec->component,
4343 &codec_drv->component_driver,
4344 dai_drv, num_dai, false);
4247 if (ret < 0) { 4345 if (ret < 0) {
4248 dev_err(codec->dev, "ASoC: Failed to regster DAIs: %d\n", ret); 4346 dev_err(codec->dev, "ASoC: Failed to regster component: %d\n", ret);
4249 goto fail_codec_name; 4347 goto fail_codec_name;
4250 } 4348 }
4251 4349
@@ -4280,7 +4378,7 @@ void snd_soc_unregister_codec(struct device *dev)
4280 return; 4378 return;
4281 4379
4282found: 4380found:
4283 snd_soc_unregister_dais(dev, codec->num_dai); 4381 snd_soc_unregister_component(dev);
4284 4382
4285 mutex_lock(&client_mutex); 4383 mutex_lock(&client_mutex);
4286 list_del(&codec->list); 4384 list_del(&codec->list);
@@ -4289,98 +4387,11 @@ found:
4289 dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name); 4387 dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name);
4290 4388
4291 snd_soc_cache_exit(codec); 4389 snd_soc_cache_exit(codec);
4292 kfree(codec->reg_def_copy);
4293 kfree(codec->name); 4390 kfree(codec->name);
4294 kfree(codec); 4391 kfree(codec);
4295} 4392}
4296EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 4393EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
4297 4394
4298
4299/**
4300 * snd_soc_register_component - Register a component with the ASoC core
4301 *
4302 */
4303int snd_soc_register_component(struct device *dev,
4304 const struct snd_soc_component_driver *cmpnt_drv,
4305 struct snd_soc_dai_driver *dai_drv,
4306 int num_dai)
4307{
4308 struct snd_soc_component *cmpnt;
4309 int ret;
4310
4311 dev_dbg(dev, "component register %s\n", dev_name(dev));
4312
4313 cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL);
4314 if (!cmpnt) {
4315 dev_err(dev, "ASoC: Failed to allocate memory\n");
4316 return -ENOMEM;
4317 }
4318
4319 cmpnt->name = fmt_single_name(dev, &cmpnt->id);
4320 if (!cmpnt->name) {
4321 dev_err(dev, "ASoC: Failed to simplifying name\n");
4322 return -ENOMEM;
4323 }
4324
4325 cmpnt->dev = dev;
4326 cmpnt->driver = cmpnt_drv;
4327 cmpnt->num_dai = num_dai;
4328
4329 /*
4330 * snd_soc_register_dai() uses fmt_single_name(), and
4331 * snd_soc_register_dais() uses fmt_multiple_name()
4332 * for dai->name which is used for name based matching
4333 */
4334 if (1 == num_dai)
4335 ret = snd_soc_register_dai(dev, dai_drv);
4336 else
4337 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4338 if (ret < 0) {
4339 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4340 goto error_component_name;
4341 }
4342
4343 mutex_lock(&client_mutex);
4344 list_add(&cmpnt->list, &component_list);
4345 mutex_unlock(&client_mutex);
4346
4347 dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name);
4348
4349 return ret;
4350
4351error_component_name:
4352 kfree(cmpnt->name);
4353
4354 return ret;
4355}
4356EXPORT_SYMBOL_GPL(snd_soc_register_component);
4357
4358/**
4359 * snd_soc_unregister_component - Unregister a component from the ASoC core
4360 *
4361 */
4362void snd_soc_unregister_component(struct device *dev)
4363{
4364 struct snd_soc_component *cmpnt;
4365
4366 list_for_each_entry(cmpnt, &component_list, list) {
4367 if (dev == cmpnt->dev)
4368 goto found;
4369 }
4370 return;
4371
4372found:
4373 snd_soc_unregister_dais(dev, cmpnt->num_dai);
4374
4375 mutex_lock(&client_mutex);
4376 list_del(&cmpnt->list);
4377 mutex_unlock(&client_mutex);
4378
4379 dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name);
4380 kfree(cmpnt->name);
4381}
4382EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
4383
4384/* Retrieve a card's name from device tree */ 4395/* Retrieve a card's name from device tree */
4385int snd_soc_of_parse_card_name(struct snd_soc_card *card, 4396int snd_soc_of_parse_card_name(struct snd_soc_card *card,
4386 const char *propname) 4397 const char *propname)
@@ -4568,6 +4579,60 @@ unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
4568} 4579}
4569EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); 4580EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
4570 4581
4582int snd_soc_of_get_dai_name(struct device_node *of_node,
4583 const char **dai_name)
4584{
4585 struct snd_soc_component *pos;
4586 struct of_phandle_args args;
4587 int ret;
4588
4589 ret = of_parse_phandle_with_args(of_node, "sound-dai",
4590 "#sound-dai-cells", 0, &args);
4591 if (ret)
4592 return ret;
4593
4594 ret = -EPROBE_DEFER;
4595
4596 mutex_lock(&client_mutex);
4597 list_for_each_entry(pos, &component_list, list) {
4598 if (pos->dev->of_node != args.np)
4599 continue;
4600
4601 if (pos->driver->of_xlate_dai_name) {
4602 ret = pos->driver->of_xlate_dai_name(pos, &args, dai_name);
4603 } else {
4604 int id = -1;
4605
4606 switch (args.args_count) {
4607 case 0:
4608 id = 0; /* same as dai_drv[0] */
4609 break;
4610 case 1:
4611 id = args.args[0];
4612 break;
4613 default:
4614 /* not supported */
4615 break;
4616 }
4617
4618 if (id < 0 || id >= pos->num_dai) {
4619 ret = -EINVAL;
4620 } else {
4621 *dai_name = pos->dai_drv[id].name;
4622 ret = 0;
4623 }
4624 }
4625
4626 break;
4627 }
4628 mutex_unlock(&client_mutex);
4629
4630 of_node_put(args.np);
4631
4632 return ret;
4633}
4634EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
4635
4571static int __init snd_soc_init(void) 4636static int __init snd_soc_init(void)
4572{ 4637{
4573#ifdef CONFIG_DEBUG_FS 4638#ifdef CONFIG_DEBUG_FS
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index c17c14c394df..dcade130157f 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -59,31 +59,31 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
59/* dapm power sequences - make this per codec in the future */ 59/* dapm power sequences - make this per codec in the future */
60static int dapm_up_seq[] = { 60static int dapm_up_seq[] = {
61 [snd_soc_dapm_pre] = 0, 61 [snd_soc_dapm_pre] = 0,
62 [snd_soc_dapm_supply] = 1,
63 [snd_soc_dapm_regulator_supply] = 1, 62 [snd_soc_dapm_regulator_supply] = 1,
64 [snd_soc_dapm_clock_supply] = 1, 63 [snd_soc_dapm_clock_supply] = 1,
65 [snd_soc_dapm_micbias] = 2, 64 [snd_soc_dapm_supply] = 2,
65 [snd_soc_dapm_micbias] = 3,
66 [snd_soc_dapm_dai_link] = 2, 66 [snd_soc_dapm_dai_link] = 2,
67 [snd_soc_dapm_dai_in] = 3, 67 [snd_soc_dapm_dai_in] = 4,
68 [snd_soc_dapm_dai_out] = 3, 68 [snd_soc_dapm_dai_out] = 4,
69 [snd_soc_dapm_aif_in] = 3, 69 [snd_soc_dapm_aif_in] = 4,
70 [snd_soc_dapm_aif_out] = 3, 70 [snd_soc_dapm_aif_out] = 4,
71 [snd_soc_dapm_mic] = 4, 71 [snd_soc_dapm_mic] = 5,
72 [snd_soc_dapm_mux] = 5, 72 [snd_soc_dapm_mux] = 6,
73 [snd_soc_dapm_virt_mux] = 5, 73 [snd_soc_dapm_virt_mux] = 6,
74 [snd_soc_dapm_value_mux] = 5, 74 [snd_soc_dapm_value_mux] = 6,
75 [snd_soc_dapm_dac] = 6, 75 [snd_soc_dapm_dac] = 7,
76 [snd_soc_dapm_switch] = 7, 76 [snd_soc_dapm_switch] = 8,
77 [snd_soc_dapm_mixer] = 7, 77 [snd_soc_dapm_mixer] = 8,
78 [snd_soc_dapm_mixer_named_ctl] = 7, 78 [snd_soc_dapm_mixer_named_ctl] = 8,
79 [snd_soc_dapm_pga] = 8, 79 [snd_soc_dapm_pga] = 9,
80 [snd_soc_dapm_adc] = 9, 80 [snd_soc_dapm_adc] = 10,
81 [snd_soc_dapm_out_drv] = 10, 81 [snd_soc_dapm_out_drv] = 11,
82 [snd_soc_dapm_hp] = 10, 82 [snd_soc_dapm_hp] = 11,
83 [snd_soc_dapm_spk] = 10, 83 [snd_soc_dapm_spk] = 11,
84 [snd_soc_dapm_line] = 10, 84 [snd_soc_dapm_line] = 11,
85 [snd_soc_dapm_kcontrol] = 11, 85 [snd_soc_dapm_kcontrol] = 12,
86 [snd_soc_dapm_post] = 12, 86 [snd_soc_dapm_post] = 13,
87}; 87};
88 88
89static int dapm_down_seq[] = { 89static int dapm_down_seq[] = {
@@ -109,10 +109,10 @@ static int dapm_down_seq[] = {
109 [snd_soc_dapm_dai_in] = 10, 109 [snd_soc_dapm_dai_in] = 10,
110 [snd_soc_dapm_dai_out] = 10, 110 [snd_soc_dapm_dai_out] = 10,
111 [snd_soc_dapm_dai_link] = 11, 111 [snd_soc_dapm_dai_link] = 11,
112 [snd_soc_dapm_clock_supply] = 12,
113 [snd_soc_dapm_regulator_supply] = 12,
114 [snd_soc_dapm_supply] = 12, 112 [snd_soc_dapm_supply] = 12,
115 [snd_soc_dapm_post] = 13, 113 [snd_soc_dapm_clock_supply] = 13,
114 [snd_soc_dapm_regulator_supply] = 13,
115 [snd_soc_dapm_post] = 14,
116}; 116};
117 117
118static void pop_wait(u32 pop_time) 118static void pop_wait(u32 pop_time)
@@ -409,6 +409,12 @@ static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w)
409 mutex_unlock(&w->platform->mutex); 409 mutex_unlock(&w->platform->mutex);
410} 410}
411 411
412static void soc_dapm_async_complete(struct snd_soc_dapm_context *dapm)
413{
414 if (dapm->codec && dapm->codec->using_regmap)
415 regmap_async_complete(dapm->codec->control_data);
416}
417
412static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w, 418static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
413 unsigned short reg, unsigned int mask, unsigned int value) 419 unsigned short reg, unsigned int mask, unsigned int value)
414{ 420{
@@ -417,8 +423,9 @@ static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
417 int ret; 423 int ret;
418 424
419 if (w->codec && w->codec->using_regmap) { 425 if (w->codec && w->codec->using_regmap) {
420 ret = regmap_update_bits_check(w->codec->control_data, 426 ret = regmap_update_bits_check_async(w->codec->control_data,
421 reg, mask, value, &change); 427 reg, mask, value,
428 &change);
422 if (ret != 0) 429 if (ret != 0)
423 return ret; 430 return ret;
424 } else { 431 } else {
@@ -499,18 +506,22 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
499 int val; 506 int val;
500 struct soc_mixer_control *mc = (struct soc_mixer_control *) 507 struct soc_mixer_control *mc = (struct soc_mixer_control *)
501 w->kcontrol_news[i].private_value; 508 w->kcontrol_news[i].private_value;
502 unsigned int reg = mc->reg; 509 int reg = mc->reg;
503 unsigned int shift = mc->shift; 510 unsigned int shift = mc->shift;
504 int max = mc->max; 511 int max = mc->max;
505 unsigned int mask = (1 << fls(max)) - 1; 512 unsigned int mask = (1 << fls(max)) - 1;
506 unsigned int invert = mc->invert; 513 unsigned int invert = mc->invert;
507 514
508 val = soc_widget_read(w, reg); 515 if (reg != SND_SOC_NOPM) {
509 val = (val >> shift) & mask; 516 val = soc_widget_read(w, reg);
510 if (invert) 517 val = (val >> shift) & mask;
511 val = max - val; 518 if (invert)
519 val = max - val;
520 p->connect = !!val;
521 } else {
522 p->connect = 0;
523 }
512 524
513 p->connect = !!val;
514 } 525 }
515 break; 526 break;
516 case snd_soc_dapm_mux: { 527 case snd_soc_dapm_mux: {
@@ -1197,6 +1208,8 @@ int dapm_regulator_event(struct snd_soc_dapm_widget *w,
1197{ 1208{
1198 int ret; 1209 int ret;
1199 1210
1211 soc_dapm_async_complete(w->dapm);
1212
1200 if (SND_SOC_DAPM_EVENT_ON(event)) { 1213 if (SND_SOC_DAPM_EVENT_ON(event)) {
1201 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { 1214 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) {
1202 ret = regulator_allow_bypass(w->regulator, false); 1215 ret = regulator_allow_bypass(w->regulator, false);
@@ -1230,6 +1243,8 @@ int dapm_clock_event(struct snd_soc_dapm_widget *w,
1230 if (!w->clk) 1243 if (!w->clk)
1231 return -EIO; 1244 return -EIO;
1232 1245
1246 soc_dapm_async_complete(w->dapm);
1247
1233#ifdef CONFIG_HAVE_CLK 1248#ifdef CONFIG_HAVE_CLK
1234 if (SND_SOC_DAPM_EVENT_ON(event)) { 1249 if (SND_SOC_DAPM_EVENT_ON(event)) {
1235 return clk_prepare_enable(w->clk); 1250 return clk_prepare_enable(w->clk);
@@ -1412,7 +1427,7 @@ static void dapm_seq_check_event(struct snd_soc_card *card,
1412 power = 0; 1427 power = 0;
1413 break; 1428 break;
1414 default: 1429 default:
1415 BUG(); 1430 WARN(1, "Unknown event %d\n", event);
1416 return; 1431 return;
1417 } 1432 }
1418 1433
@@ -1422,6 +1437,7 @@ static void dapm_seq_check_event(struct snd_soc_card *card,
1422 if (w->event && (w->event_flags & event)) { 1437 if (w->event && (w->event_flags & event)) {
1423 pop_dbg(w->dapm->dev, card->pop_time, "pop test : %s %s\n", 1438 pop_dbg(w->dapm->dev, card->pop_time, "pop test : %s %s\n",
1424 w->name, ev_name); 1439 w->name, ev_name);
1440 soc_dapm_async_complete(w->dapm);
1425 trace_snd_soc_dapm_widget_event_start(w, event); 1441 trace_snd_soc_dapm_widget_event_start(w, event);
1426 ret = w->event(w, NULL, event); 1442 ret = w->event(w, NULL, event);
1427 trace_snd_soc_dapm_widget_event_done(w, event); 1443 trace_snd_soc_dapm_widget_event_done(w, event);
@@ -1444,7 +1460,7 @@ static void dapm_seq_run_coalesced(struct snd_soc_card *card,
1444 power_list)->reg; 1460 power_list)->reg;
1445 1461
1446 list_for_each_entry(w, pending, power_list) { 1462 list_for_each_entry(w, pending, power_list) {
1447 BUG_ON(reg != w->reg); 1463 WARN_ON(reg != w->reg);
1448 w->power = w->new_power; 1464 w->power = w->new_power;
1449 1465
1450 mask |= w->mask << w->shift; 1466 mask |= w->mask << w->shift;
@@ -1494,6 +1510,7 @@ static void dapm_seq_run(struct snd_soc_card *card,
1494 struct list_head *list, int event, bool power_up) 1510 struct list_head *list, int event, bool power_up)
1495{ 1511{
1496 struct snd_soc_dapm_widget *w, *n; 1512 struct snd_soc_dapm_widget *w, *n;
1513 struct snd_soc_dapm_context *d;
1497 LIST_HEAD(pending); 1514 LIST_HEAD(pending);
1498 int cur_sort = -1; 1515 int cur_sort = -1;
1499 int cur_subseq = -1; 1516 int cur_subseq = -1;
@@ -1524,6 +1541,9 @@ static void dapm_seq_run(struct snd_soc_card *card,
1524 cur_subseq); 1541 cur_subseq);
1525 } 1542 }
1526 1543
1544 if (cur_dapm && w->dapm != cur_dapm)
1545 soc_dapm_async_complete(cur_dapm);
1546
1527 INIT_LIST_HEAD(&pending); 1547 INIT_LIST_HEAD(&pending);
1528 cur_sort = -1; 1548 cur_sort = -1;
1529 cur_subseq = INT_MIN; 1549 cur_subseq = INT_MIN;
@@ -1582,6 +1602,10 @@ static void dapm_seq_run(struct snd_soc_card *card,
1582 cur_dapm->seq_notifier(cur_dapm, 1602 cur_dapm->seq_notifier(cur_dapm,
1583 i, cur_subseq); 1603 i, cur_subseq);
1584 } 1604 }
1605
1606 list_for_each_entry(d, &card->dapm_list, list) {
1607 soc_dapm_async_complete(d);
1608 }
1585} 1609}
1586 1610
1587static void dapm_widget_update(struct snd_soc_card *card) 1611static void dapm_widget_update(struct snd_soc_card *card)
@@ -1840,6 +1864,7 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event)
1840 */ 1864 */
1841 switch (w->id) { 1865 switch (w->id) {
1842 case snd_soc_dapm_siggen: 1866 case snd_soc_dapm_siggen:
1867 case snd_soc_dapm_vmid:
1843 break; 1868 break;
1844 case snd_soc_dapm_supply: 1869 case snd_soc_dapm_supply:
1845 case snd_soc_dapm_regulator_supply: 1870 case snd_soc_dapm_regulator_supply:
@@ -1949,7 +1974,7 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1949 w->active ? "active" : "inactive"); 1974 w->active ? "active" : "inactive");
1950 1975
1951 list_for_each_entry(p, &w->sources, list_sink) { 1976 list_for_each_entry(p, &w->sources, list_sink) {
1952 if (p->connected && !p->connected(w, p->sink)) 1977 if (p->connected && !p->connected(w, p->source))
1953 continue; 1978 continue;
1954 1979
1955 if (p->connect) 1980 if (p->connect)
@@ -2001,7 +2026,7 @@ static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
2001 level = "Off\n"; 2026 level = "Off\n";
2002 break; 2027 break;
2003 default: 2028 default:
2004 BUG(); 2029 WARN(1, "Unknown bias_level %d\n", dapm->bias_level);
2005 level = "Unknown\n"; 2030 level = "Unknown\n";
2006 break; 2031 break;
2007 } 2032 }
@@ -2791,7 +2816,7 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2791 struct snd_soc_card *card = codec->card; 2816 struct snd_soc_card *card = codec->card;
2792 struct soc_mixer_control *mc = 2817 struct soc_mixer_control *mc =
2793 (struct soc_mixer_control *)kcontrol->private_value; 2818 (struct soc_mixer_control *)kcontrol->private_value;
2794 unsigned int reg = mc->reg; 2819 int reg = mc->reg;
2795 unsigned int shift = mc->shift; 2820 unsigned int shift = mc->shift;
2796 int max = mc->max; 2821 int max = mc->max;
2797 unsigned int mask = (1 << fls(max)) - 1; 2822 unsigned int mask = (1 << fls(max)) - 1;
@@ -2804,7 +2829,7 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2804 kcontrol->id.name); 2829 kcontrol->id.name);
2805 2830
2806 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 2831 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2807 if (dapm_kcontrol_is_powered(kcontrol)) 2832 if (dapm_kcontrol_is_powered(kcontrol) && reg != SND_SOC_NOPM)
2808 val = (snd_soc_read(codec, reg) >> shift) & mask; 2833 val = (snd_soc_read(codec, reg) >> shift) & mask;
2809 else 2834 else
2810 val = dapm_kcontrol_get_value(kcontrol); 2835 val = dapm_kcontrol_get_value(kcontrol);
@@ -2835,7 +2860,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2835 struct snd_soc_card *card = codec->card; 2860 struct snd_soc_card *card = codec->card;
2836 struct soc_mixer_control *mc = 2861 struct soc_mixer_control *mc =
2837 (struct soc_mixer_control *)kcontrol->private_value; 2862 (struct soc_mixer_control *)kcontrol->private_value;
2838 unsigned int reg = mc->reg; 2863 int reg = mc->reg;
2839 unsigned int shift = mc->shift; 2864 unsigned int shift = mc->shift;
2840 int max = mc->max; 2865 int max = mc->max;
2841 unsigned int mask = (1 << fls(max)) - 1; 2866 unsigned int mask = (1 << fls(max)) - 1;
@@ -2857,19 +2882,24 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2857 2882
2858 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 2883 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2859 2884
2860 dapm_kcontrol_set_value(kcontrol, val); 2885 change = dapm_kcontrol_set_value(kcontrol, val);
2861 2886
2862 mask = mask << shift; 2887 if (reg != SND_SOC_NOPM) {
2863 val = val << shift; 2888 mask = mask << shift;
2889 val = val << shift;
2890
2891 change = snd_soc_test_bits(codec, reg, mask, val);
2892 }
2864 2893
2865 change = snd_soc_test_bits(codec, reg, mask, val);
2866 if (change) { 2894 if (change) {
2867 update.kcontrol = kcontrol; 2895 if (reg != SND_SOC_NOPM) {
2868 update.reg = reg; 2896 update.kcontrol = kcontrol;
2869 update.mask = mask; 2897 update.reg = reg;
2870 update.val = val; 2898 update.mask = mask;
2899 update.val = val;
2871 2900
2872 card->update = &update; 2901 card->update = &update;
2902 }
2873 2903
2874 soc_dapm_mixer_update_power(card, kcontrol, connect); 2904 soc_dapm_mixer_update_power(card, kcontrol, connect);
2875 2905
@@ -3329,8 +3359,9 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3329 u64 fmt; 3359 u64 fmt;
3330 int ret; 3360 int ret;
3331 3361
3332 BUG_ON(!config); 3362 if (WARN_ON(!config) ||
3333 BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks)); 3363 WARN_ON(list_empty(&w->sources) || list_empty(&w->sinks)))
3364 return -EINVAL;
3334 3365
3335 /* We only support a single source and sink, pick the first */ 3366 /* We only support a single source and sink, pick the first */
3336 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path, 3367 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path,
@@ -3338,9 +3369,10 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3338 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path, 3369 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,
3339 list_source); 3370 list_source);
3340 3371
3341 BUG_ON(!source_p || !sink_p); 3372 if (WARN_ON(!source_p || !sink_p) ||
3342 BUG_ON(!sink_p->source || !source_p->sink); 3373 WARN_ON(!sink_p->source || !source_p->sink) ||
3343 BUG_ON(!source_p->source || !sink_p->sink); 3374 WARN_ON(!source_p->source || !sink_p->sink))
3375 return -EINVAL;
3344 3376
3345 source = source_p->source->priv; 3377 source = source_p->source->priv;
3346 sink = sink_p->sink->priv; 3378 sink = sink_p->sink->priv;
@@ -3416,7 +3448,7 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3416 break; 3448 break;
3417 3449
3418 default: 3450 default:
3419 BUG(); 3451 WARN(1, "Unknown event %d\n", event);
3420 return -EINVAL; 3452 return -EINVAL;
3421 } 3453 }
3422 3454
@@ -3495,6 +3527,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3495 if (!w) { 3527 if (!w) {
3496 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n", 3528 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3497 dai->driver->playback.stream_name); 3529 dai->driver->playback.stream_name);
3530 return -ENOMEM;
3498 } 3531 }
3499 3532
3500 w->priv = dai; 3533 w->priv = dai;
@@ -3513,6 +3546,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3513 if (!w) { 3546 if (!w) {
3514 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n", 3547 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3515 dai->driver->capture.stream_name); 3548 dai->driver->capture.stream_name);
3549 return -ENOMEM;
3516 } 3550 }
3517 3551
3518 w->priv = dai; 3552 w->priv = dai;
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
new file mode 100644
index 000000000000..b1d732255c02
--- /dev/null
+++ b/sound/soc/soc-devres.c
@@ -0,0 +1,86 @@
1/*
2 * soc-devres.c -- ALSA SoC Audio Layer devres functions
3 *
4 * Copyright (C) 2013 Linaro Ltd
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <sound/soc.h>
15
16static void devm_component_release(struct device *dev, void *res)
17{
18 snd_soc_unregister_component(*(struct device **)res);
19}
20
21/**
22 * devm_snd_soc_register_component - resource managed component registration
23 * @dev: Device used to manage component
24 * @cmpnt_drv: Component driver
25 * @dai_drv: DAI driver
26 * @num_dai: Number of DAIs to register
27 *
28 * Register a component with automatic unregistration when the device is
29 * unregistered.
30 */
31int devm_snd_soc_register_component(struct device *dev,
32 const struct snd_soc_component_driver *cmpnt_drv,
33 struct snd_soc_dai_driver *dai_drv, int num_dai)
34{
35 struct device **ptr;
36 int ret;
37
38 ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
39 if (!ptr)
40 return -ENOMEM;
41
42 ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
43 if (ret == 0) {
44 *ptr = dev;
45 devres_add(dev, ptr);
46 } else {
47 devres_free(ptr);
48 }
49
50 return ret;
51}
52EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
53
54static void devm_card_release(struct device *dev, void *res)
55{
56 snd_soc_unregister_card(*(struct snd_soc_card **)res);
57}
58
59/**
60 * devm_snd_soc_register_card - resource managed card registration
61 * @dev: Device used to manage card
62 * @card: Card to register
63 *
64 * Register a card with automatic unregistration when the device is
65 * unregistered.
66 */
67int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
68{
69 struct device **ptr;
70 int ret;
71
72 ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
73 if (!ptr)
74 return -ENOMEM;
75
76 ret = snd_soc_register_card(card);
77 if (ret == 0) {
78 *ptr = dev;
79 devres_add(dev, ptr);
80 } else {
81 devres_free(ptr);
82 }
83
84 return ret;
85}
86EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index e29ec3cd84b1..cbc9c96ce1f4 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -25,7 +25,7 @@
25#include <sound/dmaengine_pcm.h> 25#include <sound/dmaengine_pcm.h>
26 26
27struct dmaengine_pcm { 27struct dmaengine_pcm {
28 struct dma_chan *chan[SNDRV_PCM_STREAM_CAPTURE + 1]; 28 struct dma_chan *chan[SNDRV_PCM_STREAM_LAST + 1];
29 const struct snd_dmaengine_pcm_config *config; 29 const struct snd_dmaengine_pcm_config *config;
30 struct snd_soc_platform platform; 30 struct snd_soc_platform platform;
31 unsigned int flags; 31 unsigned int flags;
@@ -36,6 +36,15 @@ static struct dmaengine_pcm *soc_platform_to_pcm(struct snd_soc_platform *p)
36 return container_of(p, struct dmaengine_pcm, platform); 36 return container_of(p, struct dmaengine_pcm, platform);
37} 37}
38 38
39static struct device *dmaengine_dma_dev(struct dmaengine_pcm *pcm,
40 struct snd_pcm_substream *substream)
41{
42 if (!pcm->chan[substream->stream])
43 return NULL;
44
45 return pcm->chan[substream->stream]->device->dev;
46}
47
39/** 48/**
40 * snd_dmaengine_pcm_prepare_slave_config() - Generic prepare_slave_config callback 49 * snd_dmaengine_pcm_prepare_slave_config() - Generic prepare_slave_config callback
41 * @substream: PCM substream 50 * @substream: PCM substream
@@ -75,12 +84,21 @@ static int dmaengine_pcm_hw_params(struct snd_pcm_substream *substream,
75 struct snd_soc_pcm_runtime *rtd = substream->private_data; 84 struct snd_soc_pcm_runtime *rtd = substream->private_data;
76 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform); 85 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform);
77 struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream); 86 struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream);
87 int (*prepare_slave_config)(struct snd_pcm_substream *substream,
88 struct snd_pcm_hw_params *params,
89 struct dma_slave_config *slave_config);
78 struct dma_slave_config slave_config; 90 struct dma_slave_config slave_config;
79 int ret; 91 int ret;
80 92
81 if (pcm->config->prepare_slave_config) { 93 memset(&slave_config, 0, sizeof(slave_config));
82 ret = pcm->config->prepare_slave_config(substream, params, 94
83 &slave_config); 95 if (!pcm->config)
96 prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config;
97 else
98 prepare_slave_config = pcm->config->prepare_slave_config;
99
100 if (prepare_slave_config) {
101 ret = prepare_slave_config(substream, params, &slave_config);
84 if (ret) 102 if (ret)
85 return ret; 103 return ret;
86 104
@@ -92,28 +110,54 @@ static int dmaengine_pcm_hw_params(struct snd_pcm_substream *substream,
92 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); 110 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
93} 111}
94 112
95static int dmaengine_pcm_open(struct snd_pcm_substream *substream) 113static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substream)
96{ 114{
97 struct snd_soc_pcm_runtime *rtd = substream->private_data; 115 struct snd_soc_pcm_runtime *rtd = substream->private_data;
98 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform); 116 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform);
117 struct device *dma_dev = dmaengine_dma_dev(pcm, substream);
99 struct dma_chan *chan = pcm->chan[substream->stream]; 118 struct dma_chan *chan = pcm->chan[substream->stream];
119 struct snd_dmaengine_dai_dma_data *dma_data;
120 struct dma_slave_caps dma_caps;
121 struct snd_pcm_hardware hw;
100 int ret; 122 int ret;
101 123
102 ret = snd_soc_set_runtime_hwparams(substream, 124 if (pcm->config && pcm->config->pcm_hardware)
125 return snd_soc_set_runtime_hwparams(substream,
103 pcm->config->pcm_hardware); 126 pcm->config->pcm_hardware);
104 if (ret)
105 return ret;
106 127
107 return snd_dmaengine_pcm_open(substream, chan); 128 dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
129
130 memset(&hw, 0, sizeof(hw));
131 hw.info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
132 SNDRV_PCM_INFO_INTERLEAVED;
133 hw.periods_min = 2;
134 hw.periods_max = UINT_MAX;
135 hw.period_bytes_min = 256;
136 hw.period_bytes_max = dma_get_max_seg_size(dma_dev);
137 hw.buffer_bytes_max = SIZE_MAX;
138 hw.fifo_size = dma_data->fifo_size;
139
140 ret = dma_get_slave_caps(chan, &dma_caps);
141 if (ret == 0) {
142 if (dma_caps.cmd_pause)
143 hw.info |= SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME;
144 }
145
146 return snd_soc_set_runtime_hwparams(substream, &hw);
108} 147}
109 148
110static struct device *dmaengine_dma_dev(struct dmaengine_pcm *pcm, 149static int dmaengine_pcm_open(struct snd_pcm_substream *substream)
111 struct snd_pcm_substream *substream)
112{ 150{
113 if (!pcm->chan[substream->stream]) 151 struct snd_soc_pcm_runtime *rtd = substream->private_data;
114 return NULL; 152 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform);
153 struct dma_chan *chan = pcm->chan[substream->stream];
154 int ret;
115 155
116 return pcm->chan[substream->stream]->device->dev; 156 ret = dmaengine_pcm_set_runtime_hwparams(substream);
157 if (ret)
158 return ret;
159
160 return snd_dmaengine_pcm_open(substream, chan);
117} 161}
118 162
119static void dmaengine_pcm_free(struct snd_pcm *pcm) 163static void dmaengine_pcm_free(struct snd_pcm *pcm)
@@ -126,6 +170,9 @@ static struct dma_chan *dmaengine_pcm_compat_request_channel(
126 struct snd_pcm_substream *substream) 170 struct snd_pcm_substream *substream)
127{ 171{
128 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform); 172 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform);
173 struct snd_dmaengine_dai_dma_data *dma_data;
174
175 dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
129 176
130 if ((pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX) && pcm->chan[0]) 177 if ((pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX) && pcm->chan[0])
131 return pcm->chan[0]; 178 return pcm->chan[0];
@@ -134,22 +181,42 @@ static struct dma_chan *dmaengine_pcm_compat_request_channel(
134 return pcm->config->compat_request_channel(rtd, substream); 181 return pcm->config->compat_request_channel(rtd, substream);
135 182
136 return snd_dmaengine_pcm_request_channel(pcm->config->compat_filter_fn, 183 return snd_dmaengine_pcm_request_channel(pcm->config->compat_filter_fn,
137 snd_soc_dai_get_dma_data(rtd->cpu_dai, substream)); 184 dma_data->filter_data);
138} 185}
139 186
140static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd) 187static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
141{ 188{
142 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform); 189 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform);
143 const struct snd_dmaengine_pcm_config *config = pcm->config; 190 const struct snd_dmaengine_pcm_config *config = pcm->config;
191 struct device *dev = rtd->platform->dev;
192 struct snd_dmaengine_dai_dma_data *dma_data;
144 struct snd_pcm_substream *substream; 193 struct snd_pcm_substream *substream;
194 size_t prealloc_buffer_size;
195 size_t max_buffer_size;
145 unsigned int i; 196 unsigned int i;
146 int ret; 197 int ret;
147 198
199 if (config && config->prealloc_buffer_size) {
200 prealloc_buffer_size = config->prealloc_buffer_size;
201 max_buffer_size = config->pcm_hardware->buffer_bytes_max;
202 } else {
203 prealloc_buffer_size = 512 * 1024;
204 max_buffer_size = SIZE_MAX;
205 }
206
207
148 for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_CAPTURE; i++) { 208 for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_CAPTURE; i++) {
149 substream = rtd->pcm->streams[i].substream; 209 substream = rtd->pcm->streams[i].substream;
150 if (!substream) 210 if (!substream)
151 continue; 211 continue;
152 212
213 dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
214
215 if (!pcm->chan[i] &&
216 (pcm->flags & SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME))
217 pcm->chan[i] = dma_request_slave_channel(dev,
218 dma_data->chan_name);
219
153 if (!pcm->chan[i] && (pcm->flags & SND_DMAENGINE_PCM_FLAG_COMPAT)) { 220 if (!pcm->chan[i] && (pcm->flags & SND_DMAENGINE_PCM_FLAG_COMPAT)) {
154 pcm->chan[i] = dmaengine_pcm_compat_request_channel(rtd, 221 pcm->chan[i] = dmaengine_pcm_compat_request_channel(rtd,
155 substream); 222 substream);
@@ -163,10 +230,10 @@ static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
163 } 230 }
164 231
165 ret = snd_pcm_lib_preallocate_pages(substream, 232 ret = snd_pcm_lib_preallocate_pages(substream,
166 SNDRV_DMA_TYPE_DEV, 233 SNDRV_DMA_TYPE_DEV_IRAM,
167 dmaengine_dma_dev(pcm, substream), 234 dmaengine_dma_dev(pcm, substream),
168 config->prealloc_buffer_size, 235 prealloc_buffer_size,
169 config->pcm_hardware->buffer_bytes_max); 236 max_buffer_size);
170 if (ret) 237 if (ret)
171 goto err_free; 238 goto err_free;
172 } 239 }
@@ -222,7 +289,9 @@ static void dmaengine_pcm_request_chan_of(struct dmaengine_pcm *pcm,
222{ 289{
223 unsigned int i; 290 unsigned int i;
224 291
225 if ((pcm->flags & SND_DMAENGINE_PCM_FLAG_NO_DT) || !dev->of_node) 292 if ((pcm->flags & (SND_DMAENGINE_PCM_FLAG_NO_DT |
293 SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME)) ||
294 !dev->of_node)
226 return; 295 return;
227 296
228 if (pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX) { 297 if (pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX) {
diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
index 122c0c18b9dd..4f11d23f2062 100644
--- a/sound/soc/soc-io.c
+++ b/sound/soc/soc-io.c
@@ -65,31 +65,6 @@ static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
65 return val; 65 return val;
66} 66}
67 67
68/* Primitive bulk write support for soc-cache. The data pointed to by
69 * `data' needs to already be in the form the hardware expects. Any
70 * data written through this function will not go through the cache as
71 * it only handles writing to volatile or out of bounds registers.
72 *
73 * This is currently only supported for devices using the regmap API
74 * wrappers.
75 */
76static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec,
77 unsigned int reg,
78 const void *data, size_t len)
79{
80 /* To ensure that we don't get out of sync with the cache, check
81 * whether the base register is volatile or if we've directly asked
82 * to bypass the cache. Out of bounds registers are considered
83 * volatile.
84 */
85 if (!codec->cache_bypass
86 && !snd_soc_codec_volatile_register(codec, reg)
87 && reg < codec->driver->reg_cache_size)
88 return -EINVAL;
89
90 return regmap_raw_write(codec->control_data, reg, data, len);
91}
92
93/** 68/**
94 * snd_soc_codec_set_cache_io: Set up standard I/O functions. 69 * snd_soc_codec_set_cache_io: Set up standard I/O functions.
95 * 70 *
@@ -119,7 +94,6 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
119 memset(&config, 0, sizeof(config)); 94 memset(&config, 0, sizeof(config));
120 codec->write = hw_write; 95 codec->write = hw_write;
121 codec->read = hw_read; 96 codec->read = hw_read;
122 codec->bulk_write_raw = snd_soc_hw_bulk_write_raw;
123 97
124 config.reg_bits = addr_bits; 98 config.reg_bits = addr_bits;
125 config.val_bits = data_bits; 99 config.val_bits = data_bits;
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index 71358e3b54d9..23d43dac91da 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -65,6 +65,7 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
65 struct snd_soc_codec *codec; 65 struct snd_soc_codec *codec;
66 struct snd_soc_dapm_context *dapm; 66 struct snd_soc_dapm_context *dapm;
67 struct snd_soc_jack_pin *pin; 67 struct snd_soc_jack_pin *pin;
68 unsigned int sync = 0;
68 int enable; 69 int enable;
69 70
70 trace_snd_soc_jack_report(jack, mask, status); 71 trace_snd_soc_jack_report(jack, mask, status);
@@ -92,12 +93,16 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
92 snd_soc_dapm_enable_pin(dapm, pin->pin); 93 snd_soc_dapm_enable_pin(dapm, pin->pin);
93 else 94 else
94 snd_soc_dapm_disable_pin(dapm, pin->pin); 95 snd_soc_dapm_disable_pin(dapm, pin->pin);
96
97 /* we need to sync for this case only */
98 sync = 1;
95 } 99 }
96 100
97 /* Report before the DAPM sync to help users updating micbias status */ 101 /* Report before the DAPM sync to help users updating micbias status */
98 blocking_notifier_call_chain(&jack->notifier, jack->status, jack); 102 blocking_notifier_call_chain(&jack->notifier, jack->status, jack);
99 103
100 snd_soc_dapm_sync(dapm); 104 if (sync)
105 snd_soc_dapm_sync(dapm);
101 106
102 snd_jack_report(jack->jack, jack->status); 107 snd_jack_report(jack->jack, jack->status);
103 108
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 330c9a6b5cb5..42782c01e413 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -19,6 +19,7 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/pinctrl/consumer.h>
22#include <linux/pm_runtime.h> 23#include <linux/pm_runtime.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <linux/workqueue.h> 25#include <linux/workqueue.h>
@@ -183,6 +184,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
183 struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver; 184 struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver;
184 int ret = 0; 185 int ret = 0;
185 186
187 pinctrl_pm_select_default_state(cpu_dai->dev);
188 pinctrl_pm_select_default_state(codec_dai->dev);
186 pm_runtime_get_sync(cpu_dai->dev); 189 pm_runtime_get_sync(cpu_dai->dev);
187 pm_runtime_get_sync(codec_dai->dev); 190 pm_runtime_get_sync(codec_dai->dev);
188 pm_runtime_get_sync(platform->dev); 191 pm_runtime_get_sync(platform->dev);
@@ -190,7 +193,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
190 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 193 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
191 194
192 /* startup the audio subsystem */ 195 /* startup the audio subsystem */
193 if (cpu_dai->driver->ops->startup) { 196 if (cpu_dai->driver->ops && cpu_dai->driver->ops->startup) {
194 ret = cpu_dai->driver->ops->startup(substream, cpu_dai); 197 ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
195 if (ret < 0) { 198 if (ret < 0) {
196 dev_err(cpu_dai->dev, "ASoC: can't open interface" 199 dev_err(cpu_dai->dev, "ASoC: can't open interface"
@@ -208,7 +211,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
208 } 211 }
209 } 212 }
210 213
211 if (codec_dai->driver->ops->startup) { 214 if (codec_dai->driver->ops && codec_dai->driver->ops->startup) {
212 ret = codec_dai->driver->ops->startup(substream, codec_dai); 215 ret = codec_dai->driver->ops->startup(substream, codec_dai);
213 if (ret < 0) { 216 if (ret < 0) {
214 dev_err(codec_dai->dev, "ASoC: can't open codec" 217 dev_err(codec_dai->dev, "ASoC: can't open codec"
@@ -317,6 +320,10 @@ out:
317 pm_runtime_put(platform->dev); 320 pm_runtime_put(platform->dev);
318 pm_runtime_put(codec_dai->dev); 321 pm_runtime_put(codec_dai->dev);
319 pm_runtime_put(cpu_dai->dev); 322 pm_runtime_put(cpu_dai->dev);
323 if (!codec_dai->active)
324 pinctrl_pm_select_sleep_state(codec_dai->dev);
325 if (!cpu_dai->active)
326 pinctrl_pm_select_sleep_state(cpu_dai->dev);
320 327
321 return ret; 328 return ret;
322} 329}
@@ -426,6 +433,10 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
426 pm_runtime_put(platform->dev); 433 pm_runtime_put(platform->dev);
427 pm_runtime_put(codec_dai->dev); 434 pm_runtime_put(codec_dai->dev);
428 pm_runtime_put(cpu_dai->dev); 435 pm_runtime_put(cpu_dai->dev);
436 if (!codec_dai->active)
437 pinctrl_pm_select_sleep_state(codec_dai->dev);
438 if (!cpu_dai->active)
439 pinctrl_pm_select_sleep_state(cpu_dai->dev);
429 440
430 return 0; 441 return 0;
431} 442}
@@ -463,7 +474,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
463 } 474 }
464 } 475 }
465 476
466 if (codec_dai->driver->ops->prepare) { 477 if (codec_dai->driver->ops && codec_dai->driver->ops->prepare) {
467 ret = codec_dai->driver->ops->prepare(substream, codec_dai); 478 ret = codec_dai->driver->ops->prepare(substream, codec_dai);
468 if (ret < 0) { 479 if (ret < 0) {
469 dev_err(codec_dai->dev, "ASoC: DAI prepare error: %d\n", 480 dev_err(codec_dai->dev, "ASoC: DAI prepare error: %d\n",
@@ -472,7 +483,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
472 } 483 }
473 } 484 }
474 485
475 if (cpu_dai->driver->ops->prepare) { 486 if (cpu_dai->driver->ops && cpu_dai->driver->ops->prepare) {
476 ret = cpu_dai->driver->ops->prepare(substream, cpu_dai); 487 ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
477 if (ret < 0) { 488 if (ret < 0) {
478 dev_err(cpu_dai->dev, "ASoC: DAI prepare error: %d\n", 489 dev_err(cpu_dai->dev, "ASoC: DAI prepare error: %d\n",
@@ -523,7 +534,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
523 } 534 }
524 } 535 }
525 536
526 if (codec_dai->driver->ops->hw_params) { 537 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_params) {
527 ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai); 538 ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai);
528 if (ret < 0) { 539 if (ret < 0) {
529 dev_err(codec_dai->dev, "ASoC: can't set %s hw params:" 540 dev_err(codec_dai->dev, "ASoC: can't set %s hw params:"
@@ -532,7 +543,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
532 } 543 }
533 } 544 }
534 545
535 if (cpu_dai->driver->ops->hw_params) { 546 if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_params) {
536 ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai); 547 ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
537 if (ret < 0) { 548 if (ret < 0) {
538 dev_err(cpu_dai->dev, "ASoC: %s hw params failed: %d\n", 549 dev_err(cpu_dai->dev, "ASoC: %s hw params failed: %d\n",
@@ -559,11 +570,11 @@ out:
559 return ret; 570 return ret;
560 571
561platform_err: 572platform_err:
562 if (cpu_dai->driver->ops->hw_free) 573 if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
563 cpu_dai->driver->ops->hw_free(substream, cpu_dai); 574 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
564 575
565interface_err: 576interface_err:
566 if (codec_dai->driver->ops->hw_free) 577 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
567 codec_dai->driver->ops->hw_free(substream, codec_dai); 578 codec_dai->driver->ops->hw_free(substream, codec_dai);
568 579
569codec_err: 580codec_err:
@@ -600,10 +611,10 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
600 platform->driver->ops->hw_free(substream); 611 platform->driver->ops->hw_free(substream);
601 612
602 /* now free hw params for the DAIs */ 613 /* now free hw params for the DAIs */
603 if (codec_dai->driver->ops->hw_free) 614 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
604 codec_dai->driver->ops->hw_free(substream, codec_dai); 615 codec_dai->driver->ops->hw_free(substream, codec_dai);
605 616
606 if (cpu_dai->driver->ops->hw_free) 617 if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
607 cpu_dai->driver->ops->hw_free(substream, cpu_dai); 618 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
608 619
609 mutex_unlock(&rtd->pcm_mutex); 620 mutex_unlock(&rtd->pcm_mutex);
@@ -618,7 +629,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
618 struct snd_soc_dai *codec_dai = rtd->codec_dai; 629 struct snd_soc_dai *codec_dai = rtd->codec_dai;
619 int ret; 630 int ret;
620 631
621 if (codec_dai->driver->ops->trigger) { 632 if (codec_dai->driver->ops && codec_dai->driver->ops->trigger) {
622 ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai); 633 ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai);
623 if (ret < 0) 634 if (ret < 0)
624 return ret; 635 return ret;
@@ -630,7 +641,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
630 return ret; 641 return ret;
631 } 642 }
632 643
633 if (cpu_dai->driver->ops->trigger) { 644 if (cpu_dai->driver->ops && cpu_dai->driver->ops->trigger) {
634 ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai); 645 ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
635 if (ret < 0) 646 if (ret < 0)
636 return ret; 647 return ret;
@@ -647,19 +658,20 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
647 struct snd_soc_dai *codec_dai = rtd->codec_dai; 658 struct snd_soc_dai *codec_dai = rtd->codec_dai;
648 int ret; 659 int ret;
649 660
650 if (codec_dai->driver->ops->bespoke_trigger) { 661 if (codec_dai->driver->ops &&
662 codec_dai->driver->ops->bespoke_trigger) {
651 ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai); 663 ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai);
652 if (ret < 0) 664 if (ret < 0)
653 return ret; 665 return ret;
654 } 666 }
655 667
656 if (platform->driver->bespoke_trigger) { 668 if (platform->driver->ops && platform->driver->bespoke_trigger) {
657 ret = platform->driver->bespoke_trigger(substream, cmd); 669 ret = platform->driver->bespoke_trigger(substream, cmd);
658 if (ret < 0) 670 if (ret < 0)
659 return ret; 671 return ret;
660 } 672 }
661 673
662 if (cpu_dai->driver->ops->bespoke_trigger) { 674 if (cpu_dai->driver->ops && cpu_dai->driver->ops->bespoke_trigger) {
663 ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai); 675 ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai);
664 if (ret < 0) 676 if (ret < 0)
665 return ret; 677 return ret;
@@ -684,10 +696,10 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
684 if (platform->driver->ops && platform->driver->ops->pointer) 696 if (platform->driver->ops && platform->driver->ops->pointer)
685 offset = platform->driver->ops->pointer(substream); 697 offset = platform->driver->ops->pointer(substream);
686 698
687 if (cpu_dai->driver->ops->delay) 699 if (cpu_dai->driver->ops && cpu_dai->driver->ops->delay)
688 delay += cpu_dai->driver->ops->delay(substream, cpu_dai); 700 delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
689 701
690 if (codec_dai->driver->ops->delay) 702 if (codec_dai->driver->ops && codec_dai->driver->ops->delay)
691 delay += codec_dai->driver->ops->delay(substream, codec_dai); 703 delay += codec_dai->driver->ops->delay(substream, codec_dai);
692 704
693 if (platform->driver->delay) 705 if (platform->driver->delay)
@@ -721,7 +733,7 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
721 list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients); 733 list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
722 list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients); 734 list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients);
723 735
724 dev_dbg(fe->dev, " connected new DPCM %s path %s %s %s\n", 736 dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n",
725 stream ? "capture" : "playback", fe->dai_link->name, 737 stream ? "capture" : "playback", fe->dai_link->name,
726 stream ? "<-" : "->", be->dai_link->name); 738 stream ? "<-" : "->", be->dai_link->name);
727 739
@@ -749,7 +761,7 @@ static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
749 if (dpcm->fe == fe) 761 if (dpcm->fe == fe)
750 continue; 762 continue;
751 763
752 dev_dbg(fe->dev, " reparent %s path %s %s %s\n", 764 dev_dbg(fe->dev, "reparent %s path %s %s %s\n",
753 stream ? "capture" : "playback", 765 stream ? "capture" : "playback",
754 dpcm->fe->dai_link->name, 766 dpcm->fe->dai_link->name,
755 stream ? "<-" : "->", dpcm->be->dai_link->name); 767 stream ? "<-" : "->", dpcm->be->dai_link->name);
@@ -773,7 +785,7 @@ static void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
773 if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE) 785 if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE)
774 continue; 786 continue;
775 787
776 dev_dbg(fe->dev, " freed DSP %s path %s %s %s\n", 788 dev_dbg(fe->dev, "freed DSP %s path %s %s %s\n",
777 stream ? "capture" : "playback", fe->dai_link->name, 789 stream ? "capture" : "playback", fe->dai_link->name,
778 stream ? "<-" : "->", dpcm->be->dai_link->name); 790 stream ? "<-" : "->", dpcm->be->dai_link->name);
779 791
@@ -1037,6 +1049,12 @@ static int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
1037 struct snd_pcm_substream *be_substream = 1049 struct snd_pcm_substream *be_substream =
1038 snd_soc_dpcm_get_substream(be, stream); 1050 snd_soc_dpcm_get_substream(be, stream);
1039 1051
1052 if (!be_substream) {
1053 dev_err(be->dev, "ASoC: no backend %s stream\n",
1054 stream ? "capture" : "playback");
1055 continue;
1056 }
1057
1040 /* is this op for this BE ? */ 1058 /* is this op for this BE ? */
1041 if (!snd_soc_dpcm_be_can_update(fe, be, stream)) 1059 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1042 continue; 1060 continue;
@@ -1054,7 +1072,8 @@ static int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
1054 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE)) 1072 (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
1055 continue; 1073 continue;
1056 1074
1057 dev_dbg(be->dev, "ASoC: open BE %s\n", be->dai_link->name); 1075 dev_dbg(be->dev, "ASoC: open %s BE %s\n",
1076 stream ? "capture" : "playback", be->dai_link->name);
1058 1077
1059 be_substream->runtime = be->dpcm[stream].runtime; 1078 be_substream->runtime = be->dpcm[stream].runtime;
1060 err = soc_pcm_open(be_substream); 1079 err = soc_pcm_open(be_substream);
@@ -1673,7 +1692,7 @@ static int soc_pcm_ioctl(struct snd_pcm_substream *substream,
1673 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1692 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1674 struct snd_soc_platform *platform = rtd->platform; 1693 struct snd_soc_platform *platform = rtd->platform;
1675 1694
1676 if (platform->driver->ops->ioctl) 1695 if (platform->driver->ops && platform->driver->ops->ioctl)
1677 return platform->driver->ops->ioctl(substream, cmd, arg); 1696 return platform->driver->ops->ioctl(substream, cmd, arg);
1678 return snd_pcm_lib_ioctl(substream, cmd, arg); 1697 return snd_pcm_lib_ioctl(substream, cmd, arg);
1679} 1698}
@@ -1934,8 +1953,8 @@ int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
1934 1953
1935 dev_dbg(be->dev, "ASoC: BE digital mute %s\n", be->dai_link->name); 1954 dev_dbg(be->dev, "ASoC: BE digital mute %s\n", be->dai_link->name);
1936 1955
1937 if (drv->ops->digital_mute && dai->playback_active) 1956 if (drv->ops && drv->ops->digital_mute && dai->playback_active)
1938 drv->ops->digital_mute(dai, mute); 1957 drv->ops->digital_mute(dai, mute);
1939 } 1958 }
1940 1959
1941 return 0; 1960 return 0;
@@ -2116,7 +2135,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2116 2135
2117 pcm->private_free = platform->driver->pcm_free; 2136 pcm->private_free = platform->driver->pcm_free;
2118out: 2137out:
2119 dev_info(rtd->card->dev, " %s <-> %s mapping ok\n", codec_dai->name, 2138 dev_info(rtd->card->dev, "%s <-> %s mapping ok\n", codec_dai->name,
2120 cpu_dai->name); 2139 cpu_dai->name);
2121 return ret; 2140 return ret;
2122} 2141}
@@ -2224,7 +2243,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);
2224int snd_soc_platform_trigger(struct snd_pcm_substream *substream, 2243int snd_soc_platform_trigger(struct snd_pcm_substream *substream,
2225 int cmd, struct snd_soc_platform *platform) 2244 int cmd, struct snd_soc_platform *platform)
2226{ 2245{
2227 if (platform->driver->ops->trigger) 2246 if (platform->driver->ops && platform->driver->ops->trigger)
2228 return platform->driver->ops->trigger(substream, cmd); 2247 return platform->driver->ops->trigger(substream, cmd);
2229 return 0; 2248 return 0;
2230} 2249}
diff --git a/sound/soc/soc-utils.c b/sound/soc/soc-utils.c
index 29b211e9c060..5e633659c1b3 100644
--- a/sound/soc/soc-utils.c
+++ b/sound/soc/soc-utils.c
@@ -75,7 +75,11 @@ static const struct snd_pcm_hardware dummy_dma_hardware = {
75 75
76static int dummy_dma_open(struct snd_pcm_substream *substream) 76static int dummy_dma_open(struct snd_pcm_substream *substream)
77{ 77{
78 snd_soc_set_runtime_hwparams(substream, &dummy_dma_hardware); 78 struct snd_soc_pcm_runtime *rtd = substream->private_data;
79
80 /* BE's dont need dummy params */
81 if (!rtd->dai_link->no_pcm)
82 snd_soc_set_runtime_hwparams(substream, &dummy_dma_hardware);
79 83
80 return 0; 84 return 0;
81} 85}
diff --git a/sound/soc/spear/spdif_in.c b/sound/soc/spear/spdif_in.c
index 63acfeb4b69d..21a8c954af1c 100644
--- a/sound/soc/spear/spdif_in.c
+++ b/sound/soc/spear/spdif_in.c
@@ -257,20 +257,12 @@ static int spdif_in_probe(struct platform_device *pdev)
257 return ret; 257 return ret;
258 } 258 }
259 259
260 return snd_soc_register_component(&pdev->dev, &spdif_in_component, 260 return devm_snd_soc_register_component(&pdev->dev, &spdif_in_component,
261 &spdif_in_dai, 1); 261 &spdif_in_dai, 1);
262}
263
264static int spdif_in_remove(struct platform_device *pdev)
265{
266 snd_soc_unregister_component(&pdev->dev);
267
268 return 0;
269} 262}
270 263
271static struct platform_driver spdif_in_driver = { 264static struct platform_driver spdif_in_driver = {
272 .probe = spdif_in_probe, 265 .probe = spdif_in_probe,
273 .remove = spdif_in_remove,
274 .driver = { 266 .driver = {
275 .name = "spdif-in", 267 .name = "spdif-in",
276 .owner = THIS_MODULE, 268 .owner = THIS_MODULE,
diff --git a/sound/soc/spear/spdif_out.c b/sound/soc/spear/spdif_out.c
index 2fdf68c98d22..b6ef6f78dc78 100644
--- a/sound/soc/spear/spdif_out.c
+++ b/sound/soc/spear/spdif_out.c
@@ -280,7 +280,6 @@ static int spdif_out_probe(struct platform_device *pdev)
280 struct spdif_out_dev *host; 280 struct spdif_out_dev *host;
281 struct spear_spdif_platform_data *pdata; 281 struct spear_spdif_platform_data *pdata;
282 struct resource *res; 282 struct resource *res;
283 int ret;
284 283
285 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); 284 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
286 if (!host) { 285 if (!host) {
@@ -307,16 +306,8 @@ static int spdif_out_probe(struct platform_device *pdev)
307 306
308 dev_set_drvdata(&pdev->dev, host); 307 dev_set_drvdata(&pdev->dev, host);
309 308
310 ret = snd_soc_register_component(&pdev->dev, &spdif_out_component, 309 return devm_snd_soc_register_component(&pdev->dev, &spdif_out_component,
311 &spdif_out_dai, 1); 310 &spdif_out_dai, 1);
312 return ret;
313}
314
315static int spdif_out_remove(struct platform_device *pdev)
316{
317 snd_soc_unregister_component(&pdev->dev);
318
319 return 0;
320} 311}
321 312
322#ifdef CONFIG_PM 313#ifdef CONFIG_PM
@@ -357,7 +348,6 @@ static SIMPLE_DEV_PM_OPS(spdif_out_dev_pm_ops, spdif_out_suspend, \
357 348
358static struct platform_driver spdif_out_driver = { 349static struct platform_driver spdif_out_driver = {
359 .probe = spdif_out_probe, 350 .probe = spdif_out_probe,
360 .remove = spdif_out_remove,
361 .driver = { 351 .driver = {
362 .name = "spdif-out", 352 .name = "spdif-out",
363 .owner = THIS_MODULE, 353 .owner = THIS_MODULE,
diff --git a/sound/soc/tegra/tegra20_i2s.c b/sound/soc/tegra/tegra20_i2s.c
index 52af7f6fb37f..364bf6a907e1 100644
--- a/sound/soc/tegra/tegra20_i2s.c
+++ b/sound/soc/tegra/tegra20_i2s.c
@@ -297,7 +297,7 @@ static bool tegra20_i2s_wr_rd_reg(struct device *dev, unsigned int reg)
297 return true; 297 return true;
298 default: 298 default:
299 return false; 299 return false;
300 }; 300 }
301} 301}
302 302
303static bool tegra20_i2s_volatile_reg(struct device *dev, unsigned int reg) 303static bool tegra20_i2s_volatile_reg(struct device *dev, unsigned int reg)
@@ -310,7 +310,7 @@ static bool tegra20_i2s_volatile_reg(struct device *dev, unsigned int reg)
310 return true; 310 return true;
311 default: 311 default:
312 return false; 312 return false;
313 }; 313 }
314} 314}
315 315
316static bool tegra20_i2s_precious_reg(struct device *dev, unsigned int reg) 316static bool tegra20_i2s_precious_reg(struct device *dev, unsigned int reg)
@@ -321,7 +321,7 @@ static bool tegra20_i2s_precious_reg(struct device *dev, unsigned int reg)
321 return true; 321 return true;
322 default: 322 default:
323 return false; 323 return false;
324 }; 324 }
325} 325}
326 326
327static const struct regmap_config tegra20_i2s_regmap_config = { 327static const struct regmap_config tegra20_i2s_regmap_config = {
diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
index 551b3c93ce93..08bc6931c7c7 100644
--- a/sound/soc/tegra/tegra20_spdif.c
+++ b/sound/soc/tegra/tegra20_spdif.c
@@ -213,7 +213,7 @@ static bool tegra20_spdif_wr_rd_reg(struct device *dev, unsigned int reg)
213 return true; 213 return true;
214 default: 214 default:
215 return false; 215 return false;
216 }; 216 }
217} 217}
218 218
219static bool tegra20_spdif_volatile_reg(struct device *dev, unsigned int reg) 219static bool tegra20_spdif_volatile_reg(struct device *dev, unsigned int reg)
@@ -234,7 +234,7 @@ static bool tegra20_spdif_volatile_reg(struct device *dev, unsigned int reg)
234 return true; 234 return true;
235 default: 235 default:
236 return false; 236 return false;
237 }; 237 }
238} 238}
239 239
240static bool tegra20_spdif_precious_reg(struct device *dev, unsigned int reg) 240static bool tegra20_spdif_precious_reg(struct device *dev, unsigned int reg)
@@ -247,7 +247,7 @@ static bool tegra20_spdif_precious_reg(struct device *dev, unsigned int reg)
247 return true; 247 return true;
248 default: 248 default:
249 return false; 249 return false;
250 }; 250 }
251} 251}
252 252
253static const struct regmap_config tegra20_spdif_regmap_config = { 253static const struct regmap_config tegra20_spdif_regmap_config = {
diff --git a/sound/soc/tegra/tegra30_ahub.c b/sound/soc/tegra/tegra30_ahub.c
index d554d46d08b5..31154338c1eb 100644
--- a/sound/soc/tegra/tegra30_ahub.c
+++ b/sound/soc/tegra/tegra30_ahub.c
@@ -100,6 +100,7 @@ int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif,
100{ 100{
101 int channel; 101 int channel;
102 u32 reg, val; 102 u32 reg, val;
103 struct tegra30_ahub_cif_conf cif_conf;
103 104
104 channel = find_first_zero_bit(ahub->rx_usage, 105 channel = find_first_zero_bit(ahub->rx_usage,
105 TEGRA30_AHUB_CHANNEL_CTRL_COUNT); 106 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
@@ -123,15 +124,21 @@ int tegra30_ahub_allocate_rx_fifo(enum tegra30_ahub_rxcif *rxcif,
123 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16; 124 TEGRA30_AHUB_CHANNEL_CTRL_RX_PACK_16;
124 tegra30_apbif_write(reg, val); 125 tegra30_apbif_write(reg, val);
125 126
127 cif_conf.threshold = 0;
128 cif_conf.audio_channels = 2;
129 cif_conf.client_channels = 2;
130 cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
131 cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
132 cif_conf.expand = 0;
133 cif_conf.stereo_conv = 0;
134 cif_conf.replicate = 0;
135 cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_RX;
136 cif_conf.truncate = 0;
137 cif_conf.mono_conv = 0;
138
126 reg = TEGRA30_AHUB_CIF_RX_CTRL + 139 reg = TEGRA30_AHUB_CIF_RX_CTRL +
127 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE); 140 (channel * TEGRA30_AHUB_CIF_RX_CTRL_STRIDE);
128 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) | 141 ahub->soc_data->set_audio_cif(ahub->regmap_apbif, reg, &cif_conf);
129 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
130 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
131 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
132 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
133 TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX;
134 tegra30_apbif_write(reg, val);
135 142
136 return 0; 143 return 0;
137} 144}
@@ -183,6 +190,7 @@ int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif,
183{ 190{
184 int channel; 191 int channel;
185 u32 reg, val; 192 u32 reg, val;
193 struct tegra30_ahub_cif_conf cif_conf;
186 194
187 channel = find_first_zero_bit(ahub->tx_usage, 195 channel = find_first_zero_bit(ahub->tx_usage,
188 TEGRA30_AHUB_CHANNEL_CTRL_COUNT); 196 TEGRA30_AHUB_CHANNEL_CTRL_COUNT);
@@ -206,15 +214,21 @@ int tegra30_ahub_allocate_tx_fifo(enum tegra30_ahub_txcif *txcif,
206 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16; 214 TEGRA30_AHUB_CHANNEL_CTRL_TX_PACK_16;
207 tegra30_apbif_write(reg, val); 215 tegra30_apbif_write(reg, val);
208 216
217 cif_conf.threshold = 0;
218 cif_conf.audio_channels = 2;
219 cif_conf.client_channels = 2;
220 cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
221 cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
222 cif_conf.expand = 0;
223 cif_conf.stereo_conv = 0;
224 cif_conf.replicate = 0;
225 cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_TX;
226 cif_conf.truncate = 0;
227 cif_conf.mono_conv = 0;
228
209 reg = TEGRA30_AHUB_CIF_TX_CTRL + 229 reg = TEGRA30_AHUB_CIF_TX_CTRL +
210 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE); 230 (channel * TEGRA30_AHUB_CIF_TX_CTRL_STRIDE);
211 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) | 231 ahub->soc_data->set_audio_cif(ahub->regmap_apbif, reg, &cif_conf);
212 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
213 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
214 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 |
215 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16 |
216 TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX;
217 tegra30_apbif_write(reg, val);
218 232
219 return 0; 233 return 0;
220} 234}
@@ -346,7 +360,7 @@ static bool tegra30_ahub_apbif_wr_rd_reg(struct device *dev, unsigned int reg)
346 return true; 360 return true;
347 default: 361 default:
348 break; 362 break;
349 }; 363 }
350 364
351 if (REG_IN_ARRAY(reg, CHANNEL_CTRL) || 365 if (REG_IN_ARRAY(reg, CHANNEL_CTRL) ||
352 REG_IN_ARRAY(reg, CHANNEL_CLEAR) || 366 REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
@@ -381,7 +395,7 @@ static bool tegra30_ahub_apbif_volatile_reg(struct device *dev,
381 return true; 395 return true;
382 default: 396 default:
383 break; 397 break;
384 }; 398 }
385 399
386 if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) || 400 if (REG_IN_ARRAY(reg, CHANNEL_CLEAR) ||
387 REG_IN_ARRAY(reg, CHANNEL_STATUS) || 401 REG_IN_ARRAY(reg, CHANNEL_STATUS) ||
@@ -437,13 +451,21 @@ static const struct regmap_config tegra30_ahub_ahub_regmap_config = {
437 451
438static struct tegra30_ahub_soc_data soc_data_tegra30 = { 452static struct tegra30_ahub_soc_data soc_data_tegra30 = {
439 .clk_list_mask = CLK_LIST_MASK_TEGRA30, 453 .clk_list_mask = CLK_LIST_MASK_TEGRA30,
454 .set_audio_cif = tegra30_ahub_set_cif,
440}; 455};
441 456
442static struct tegra30_ahub_soc_data soc_data_tegra114 = { 457static struct tegra30_ahub_soc_data soc_data_tegra114 = {
443 .clk_list_mask = CLK_LIST_MASK_TEGRA114, 458 .clk_list_mask = CLK_LIST_MASK_TEGRA114,
459 .set_audio_cif = tegra30_ahub_set_cif,
460};
461
462static struct tegra30_ahub_soc_data soc_data_tegra124 = {
463 .clk_list_mask = CLK_LIST_MASK_TEGRA114,
464 .set_audio_cif = tegra124_ahub_set_cif,
444}; 465};
445 466
446static const struct of_device_id tegra30_ahub_of_match[] = { 467static const struct of_device_id tegra30_ahub_of_match[] = {
468 { .compatible = "nvidia,tegra124-ahub", .data = &soc_data_tegra124 },
447 { .compatible = "nvidia,tegra114-ahub", .data = &soc_data_tegra114 }, 469 { .compatible = "nvidia,tegra114-ahub", .data = &soc_data_tegra114 },
448 { .compatible = "nvidia,tegra30-ahub", .data = &soc_data_tegra30 }, 470 { .compatible = "nvidia,tegra30-ahub", .data = &soc_data_tegra30 },
449 {}, 471 {},
@@ -497,6 +519,7 @@ static int tegra30_ahub_probe(struct platform_device *pdev)
497 } 519 }
498 dev_set_drvdata(&pdev->dev, ahub); 520 dev_set_drvdata(&pdev->dev, ahub);
499 521
522 ahub->soc_data = soc_data;
500 ahub->dev = &pdev->dev; 523 ahub->dev = &pdev->dev;
501 524
502 ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio"); 525 ahub->clk_d_audio = clk_get(&pdev->dev, "d_audio");
@@ -669,6 +692,70 @@ static struct platform_driver tegra30_ahub_driver = {
669}; 692};
670module_platform_driver(tegra30_ahub_driver); 693module_platform_driver(tegra30_ahub_driver);
671 694
695void tegra30_ahub_set_cif(struct regmap *regmap, unsigned int reg,
696 struct tegra30_ahub_cif_conf *conf)
697{
698 unsigned int value;
699
700 value = (conf->threshold <<
701 TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
702 ((conf->audio_channels - 1) <<
703 TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
704 ((conf->client_channels - 1) <<
705 TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
706 (conf->audio_bits <<
707 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) |
708 (conf->client_bits <<
709 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) |
710 (conf->expand <<
711 TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT) |
712 (conf->stereo_conv <<
713 TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) |
714 (conf->replicate <<
715 TEGRA30_AUDIOCIF_CTRL_REPLICATE_SHIFT) |
716 (conf->direction <<
717 TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT) |
718 (conf->truncate <<
719 TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT) |
720 (conf->mono_conv <<
721 TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT);
722
723 regmap_write(regmap, reg, value);
724}
725EXPORT_SYMBOL_GPL(tegra30_ahub_set_cif);
726
727void tegra124_ahub_set_cif(struct regmap *regmap, unsigned int reg,
728 struct tegra30_ahub_cif_conf *conf)
729{
730 unsigned int value;
731
732 value = (conf->threshold <<
733 TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) |
734 ((conf->audio_channels - 1) <<
735 TEGRA124_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) |
736 ((conf->client_channels - 1) <<
737 TEGRA124_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) |
738 (conf->audio_bits <<
739 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_SHIFT) |
740 (conf->client_bits <<
741 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_SHIFT) |
742 (conf->expand <<
743 TEGRA30_AUDIOCIF_CTRL_EXPAND_SHIFT) |
744 (conf->stereo_conv <<
745 TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) |
746 (conf->replicate <<
747 TEGRA30_AUDIOCIF_CTRL_REPLICATE_SHIFT) |
748 (conf->direction <<
749 TEGRA30_AUDIOCIF_CTRL_DIRECTION_SHIFT) |
750 (conf->truncate <<
751 TEGRA30_AUDIOCIF_CTRL_TRUNCATE_SHIFT) |
752 (conf->mono_conv <<
753 TEGRA30_AUDIOCIF_CTRL_MONO_CONV_SHIFT);
754
755 regmap_write(regmap, reg, value);
756}
757EXPORT_SYMBOL_GPL(tegra124_ahub_set_cif);
758
672MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); 759MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
673MODULE_DESCRIPTION("Tegra30 AHUB driver"); 760MODULE_DESCRIPTION("Tegra30 AHUB driver");
674MODULE_LICENSE("GPL v2"); 761MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/tegra/tegra30_ahub.h b/sound/soc/tegra/tegra30_ahub.h
index 09766cdc45ca..d67321d90faa 100644
--- a/sound/soc/tegra/tegra30_ahub.h
+++ b/sound/soc/tegra/tegra30_ahub.h
@@ -25,16 +25,30 @@
25#define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US 0xf 25#define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US 0xf
26#define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK (TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) 26#define TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK (TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT)
27 27
28#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT 24
29#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US 0x3f
30#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK (TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US << TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT)
31
28/* Channel count minus 1 */ 32/* Channel count minus 1 */
29#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT 24 33#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT 24
30#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US 7 34#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US 7
31#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) 35#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT)
32 36
33/* Channel count minus 1 */ 37/* Channel count minus 1 */
38#define TEGRA124_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT 20
39#define TEGRA124_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US 0xf
40#define TEGRA124_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK (TEGRA124_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US << TEGRA124_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT)
41
42/* Channel count minus 1 */
34#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT 16 43#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT 16
35#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US 7 44#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US 7
36#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) 45#define TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT)
37 46
47/* Channel count minus 1 */
48#define TEGRA124_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT 16
49#define TEGRA124_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US 0xf
50#define TEGRA124_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK (TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT)
51
38#define TEGRA30_AUDIOCIF_BITS_4 0 52#define TEGRA30_AUDIOCIF_BITS_4 0
39#define TEGRA30_AUDIOCIF_BITS_8 1 53#define TEGRA30_AUDIOCIF_BITS_8 1
40#define TEGRA30_AUDIOCIF_BITS_12 2 54#define TEGRA30_AUDIOCIF_BITS_12 2
@@ -86,7 +100,7 @@
86#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_CH1 (TEGRA30_AUDIOCIF_STEREO_CONV_CH1 << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) 100#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_CH1 (TEGRA30_AUDIOCIF_STEREO_CONV_CH1 << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT)
87#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_AVG (TEGRA30_AUDIOCIF_STEREO_CONV_AVG << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT) 101#define TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_AVG (TEGRA30_AUDIOCIF_STEREO_CONV_AVG << TEGRA30_AUDIOCIF_CTRL_STEREO_CONV_SHIFT)
88 102
89#define TEGRA30_AUDIOCIF_CTRL_REPLICATE 3 103#define TEGRA30_AUDIOCIF_CTRL_REPLICATE_SHIFT 3
90 104
91#define TEGRA30_AUDIOCIF_DIRECTION_TX 0 105#define TEGRA30_AUDIOCIF_DIRECTION_TX 0
92#define TEGRA30_AUDIOCIF_DIRECTION_RX 1 106#define TEGRA30_AUDIOCIF_DIRECTION_RX 1
@@ -468,8 +482,30 @@ extern int tegra30_ahub_set_rx_cif_source(enum tegra30_ahub_rxcif rxcif,
468 enum tegra30_ahub_txcif txcif); 482 enum tegra30_ahub_txcif txcif);
469extern int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif); 483extern int tegra30_ahub_unset_rx_cif_source(enum tegra30_ahub_rxcif rxcif);
470 484
485struct tegra30_ahub_cif_conf {
486 unsigned int threshold;
487 unsigned int audio_channels;
488 unsigned int client_channels;
489 unsigned int audio_bits;
490 unsigned int client_bits;
491 unsigned int expand;
492 unsigned int stereo_conv;
493 unsigned int replicate;
494 unsigned int direction;
495 unsigned int truncate;
496 unsigned int mono_conv;
497};
498
499void tegra30_ahub_set_cif(struct regmap *regmap, unsigned int reg,
500 struct tegra30_ahub_cif_conf *conf);
501void tegra124_ahub_set_cif(struct regmap *regmap, unsigned int reg,
502 struct tegra30_ahub_cif_conf *conf);
503
471struct tegra30_ahub_soc_data { 504struct tegra30_ahub_soc_data {
472 u32 clk_list_mask; 505 u32 clk_list_mask;
506 void (*set_audio_cif)(struct regmap *regmap,
507 unsigned int reg,
508 struct tegra30_ahub_cif_conf *conf);
473 /* 509 /*
474 * FIXME: There are many more differences in HW, such as: 510 * FIXME: There are many more differences in HW, such as:
475 * - More APBIF channels. 511 * - More APBIF channels.
diff --git a/sound/soc/tegra/tegra30_i2s.c b/sound/soc/tegra/tegra30_i2s.c
index 47565fd04505..231a785b3921 100644
--- a/sound/soc/tegra/tegra30_i2s.c
+++ b/sound/soc/tegra/tegra30_i2s.c
@@ -30,6 +30,7 @@
30#include <linux/io.h> 30#include <linux/io.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/of.h> 32#include <linux/of.h>
33#include <linux/of_device.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
35#include <linux/regmap.h> 36#include <linux/regmap.h>
@@ -179,6 +180,7 @@ static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
179 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai); 180 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
180 unsigned int mask, val, reg; 181 unsigned int mask, val, reg;
181 int ret, sample_size, srate, i2sclock, bitcnt; 182 int ret, sample_size, srate, i2sclock, bitcnt;
183 struct tegra30_ahub_cif_conf cif_conf;
182 184
183 if (params_channels(params) != 2) 185 if (params_channels(params) != 2)
184 return -EINVAL; 186 return -EINVAL;
@@ -217,21 +219,26 @@ static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
217 219
218 regmap_write(i2s->regmap, TEGRA30_I2S_TIMING, val); 220 regmap_write(i2s->regmap, TEGRA30_I2S_TIMING, val);
219 221
220 val = (0 << TEGRA30_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT) | 222 cif_conf.threshold = 0;
221 (1 << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT) | 223 cif_conf.audio_channels = 2;
222 (1 << TEGRA30_AUDIOCIF_CTRL_CLIENT_CHANNELS_SHIFT) | 224 cif_conf.client_channels = 2;
223 TEGRA30_AUDIOCIF_CTRL_AUDIO_BITS_16 | 225 cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
224 TEGRA30_AUDIOCIF_CTRL_CLIENT_BITS_16; 226 cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
227 cif_conf.expand = 0;
228 cif_conf.stereo_conv = 0;
229 cif_conf.replicate = 0;
230 cif_conf.truncate = 0;
231 cif_conf.mono_conv = 0;
225 232
226 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 233 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
227 val |= TEGRA30_AUDIOCIF_CTRL_DIRECTION_RX; 234 cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_RX;
228 reg = TEGRA30_I2S_CIF_RX_CTRL; 235 reg = TEGRA30_I2S_CIF_RX_CTRL;
229 } else { 236 } else {
230 val |= TEGRA30_AUDIOCIF_CTRL_DIRECTION_TX; 237 cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_TX;
231 reg = TEGRA30_I2S_CIF_TX_CTRL; 238 reg = TEGRA30_I2S_CIF_TX_CTRL;
232 } 239 }
233 240
234 regmap_write(i2s->regmap, reg, val); 241 i2s->soc_data->set_audio_cif(i2s->regmap, reg, &cif_conf);
235 242
236 val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) | 243 val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) |
237 (1 << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT); 244 (1 << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT);
@@ -369,7 +376,7 @@ static bool tegra30_i2s_wr_rd_reg(struct device *dev, unsigned int reg)
369 return true; 376 return true;
370 default: 377 default:
371 return false; 378 return false;
372 }; 379 }
373} 380}
374 381
375static bool tegra30_i2s_volatile_reg(struct device *dev, unsigned int reg) 382static bool tegra30_i2s_volatile_reg(struct device *dev, unsigned int reg)
@@ -382,7 +389,7 @@ static bool tegra30_i2s_volatile_reg(struct device *dev, unsigned int reg)
382 return true; 389 return true;
383 default: 390 default:
384 return false; 391 return false;
385 }; 392 }
386} 393}
387 394
388static const struct regmap_config tegra30_i2s_regmap_config = { 395static const struct regmap_config tegra30_i2s_regmap_config = {
@@ -396,9 +403,24 @@ static const struct regmap_config tegra30_i2s_regmap_config = {
396 .cache_type = REGCACHE_RBTREE, 403 .cache_type = REGCACHE_RBTREE,
397}; 404};
398 405
406static const struct tegra30_i2s_soc_data tegra30_i2s_config = {
407 .set_audio_cif = tegra30_ahub_set_cif,
408};
409
410static const struct tegra30_i2s_soc_data tegra124_i2s_config = {
411 .set_audio_cif = tegra124_ahub_set_cif,
412};
413
414static const struct of_device_id tegra30_i2s_of_match[] = {
415 { .compatible = "nvidia,tegra124-i2s", .data = &tegra124_i2s_config },
416 { .compatible = "nvidia,tegra30-i2s", .data = &tegra30_i2s_config },
417 {},
418};
419
399static int tegra30_i2s_platform_probe(struct platform_device *pdev) 420static int tegra30_i2s_platform_probe(struct platform_device *pdev)
400{ 421{
401 struct tegra30_i2s *i2s; 422 struct tegra30_i2s *i2s;
423 const struct of_device_id *match;
402 u32 cif_ids[2]; 424 u32 cif_ids[2];
403 struct resource *mem, *memregion; 425 struct resource *mem, *memregion;
404 void __iomem *regs; 426 void __iomem *regs;
@@ -412,6 +434,14 @@ static int tegra30_i2s_platform_probe(struct platform_device *pdev)
412 } 434 }
413 dev_set_drvdata(&pdev->dev, i2s); 435 dev_set_drvdata(&pdev->dev, i2s);
414 436
437 match = of_match_device(tegra30_i2s_of_match, &pdev->dev);
438 if (!match) {
439 dev_err(&pdev->dev, "Error: No device match found\n");
440 ret = -ENODEV;
441 goto err;
442 }
443 i2s->soc_data = (struct tegra30_i2s_soc_data *)match->data;
444
415 i2s->dai = tegra30_i2s_dai_template; 445 i2s->dai = tegra30_i2s_dai_template;
416 i2s->dai.name = dev_name(&pdev->dev); 446 i2s->dai.name = dev_name(&pdev->dev);
417 447
@@ -539,11 +569,6 @@ static int tegra30_i2s_resume(struct device *dev)
539} 569}
540#endif 570#endif
541 571
542static const struct of_device_id tegra30_i2s_of_match[] = {
543 { .compatible = "nvidia,tegra30-i2s", },
544 {},
545};
546
547static const struct dev_pm_ops tegra30_i2s_pm_ops = { 572static const struct dev_pm_ops tegra30_i2s_pm_ops = {
548 SET_RUNTIME_PM_OPS(tegra30_i2s_runtime_suspend, 573 SET_RUNTIME_PM_OPS(tegra30_i2s_runtime_suspend,
549 tegra30_i2s_runtime_resume, NULL) 574 tegra30_i2s_runtime_resume, NULL)
diff --git a/sound/soc/tegra/tegra30_i2s.h b/sound/soc/tegra/tegra30_i2s.h
index bea23afe3b9f..4d0b0a30dbfb 100644
--- a/sound/soc/tegra/tegra30_i2s.h
+++ b/sound/soc/tegra/tegra30_i2s.h
@@ -225,7 +225,14 @@
225#define TEGRA30_I2S_LCOEF_COEF_MASK_US 0xffff 225#define TEGRA30_I2S_LCOEF_COEF_MASK_US 0xffff
226#define TEGRA30_I2S_LCOEF_COEF_MASK (TEGRA30_I2S_LCOEF_COEF_MASK_US << TEGRA30_I2S_LCOEF_COEF_SHIFT) 226#define TEGRA30_I2S_LCOEF_COEF_MASK (TEGRA30_I2S_LCOEF_COEF_MASK_US << TEGRA30_I2S_LCOEF_COEF_SHIFT)
227 227
228struct tegra30_i2s_soc_data {
229 void (*set_audio_cif)(struct regmap *regmap,
230 unsigned int reg,
231 struct tegra30_ahub_cif_conf *conf);
232};
233
228struct tegra30_i2s { 234struct tegra30_i2s {
235 const struct tegra30_i2s_soc_data *soc_data;
229 struct snd_soc_dai_driver dai; 236 struct snd_soc_dai_driver dai;
230 int cif_id; 237 int cif_id;
231 struct clk *clk_i2s; 238 struct clk *clk_i2s;
diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c
index d173880f290d..1be311c51a18 100644
--- a/sound/soc/tegra/tegra_asoc_utils.c
+++ b/sound/soc/tegra/tegra_asoc_utils.c
@@ -182,6 +182,8 @@ int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data,
182 data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA30; 182 data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA30;
183 else if (of_machine_is_compatible("nvidia,tegra114")) 183 else if (of_machine_is_compatible("nvidia,tegra114"))
184 data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA114; 184 data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA114;
185 else if (of_machine_is_compatible("nvidia,tegra124"))
186 data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA124;
185 else { 187 else {
186 dev_err(data->dev, "SoC unknown to Tegra ASoC utils\n"); 188 dev_err(data->dev, "SoC unknown to Tegra ASoC utils\n");
187 return -EINVAL; 189 return -EINVAL;
diff --git a/sound/soc/tegra/tegra_asoc_utils.h b/sound/soc/tegra/tegra_asoc_utils.h
index 19fdcafed32f..9577121ce971 100644
--- a/sound/soc/tegra/tegra_asoc_utils.h
+++ b/sound/soc/tegra/tegra_asoc_utils.h
@@ -30,6 +30,7 @@ enum tegra_asoc_utils_soc {
30 TEGRA_ASOC_UTILS_SOC_TEGRA20, 30 TEGRA_ASOC_UTILS_SOC_TEGRA20,
31 TEGRA_ASOC_UTILS_SOC_TEGRA30, 31 TEGRA_ASOC_UTILS_SOC_TEGRA30,
32 TEGRA_ASOC_UTILS_SOC_TEGRA114, 32 TEGRA_ASOC_UTILS_SOC_TEGRA114,
33 TEGRA_ASOC_UTILS_SOC_TEGRA124,
33}; 34};
34 35
35struct tegra_asoc_utils_data { 36struct tegra_asoc_utils_data {
diff --git a/sound/soc/tegra/tegra_pcm.c b/sound/soc/tegra/tegra_pcm.c
index f056f632557c..7b2d23ba69b3 100644
--- a/sound/soc/tegra/tegra_pcm.c
+++ b/sound/soc/tegra/tegra_pcm.c
@@ -56,7 +56,6 @@ static const struct snd_pcm_hardware tegra_pcm_hardware = {
56static const struct snd_dmaengine_pcm_config tegra_dmaengine_pcm_config = { 56static const struct snd_dmaengine_pcm_config tegra_dmaengine_pcm_config = {
57 .pcm_hardware = &tegra_pcm_hardware, 57 .pcm_hardware = &tegra_pcm_hardware,
58 .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, 58 .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
59 .compat_filter_fn = NULL,
60 .prealloc_buffer_size = PAGE_SIZE * 8, 59 .prealloc_buffer_size = PAGE_SIZE * 8,
61}; 60};
62 61
diff --git a/sound/soc/txx9/txx9aclc.c b/sound/soc/txx9/txx9aclc.c
index 45a6428cba8d..fbd077f4de72 100644
--- a/sound/soc/txx9/txx9aclc.c
+++ b/sound/soc/txx9/txx9aclc.c
@@ -115,8 +115,8 @@ static void txx9aclc_dma_complete(void *arg)
115 spin_lock_irqsave(&dmadata->dma_lock, flags); 115 spin_lock_irqsave(&dmadata->dma_lock, flags);
116 if (dmadata->frag_count >= 0) { 116 if (dmadata->frag_count >= 0) {
117 dmadata->dmacount--; 117 dmadata->dmacount--;
118 BUG_ON(dmadata->dmacount < 0); 118 if (!WARN_ON(dmadata->dmacount < 0))
119 tasklet_schedule(&dmadata->tasklet); 119 tasklet_schedule(&dmadata->tasklet);
120 } 120 }
121 spin_unlock_irqrestore(&dmadata->dma_lock, flags); 121 spin_unlock_irqrestore(&dmadata->dma_lock, flags);
122} 122}
@@ -181,7 +181,10 @@ static void txx9aclc_dma_tasklet(unsigned long data)
181 spin_unlock_irqrestore(&dmadata->dma_lock, flags); 181 spin_unlock_irqrestore(&dmadata->dma_lock, flags);
182 return; 182 return;
183 } 183 }
184 BUG_ON(dmadata->dmacount >= NR_DMA_CHAIN); 184 if (WARN_ON(dmadata->dmacount >= NR_DMA_CHAIN)) {
185 spin_unlock_irqrestore(&dmadata->dma_lock, flags);
186 return;
187 }
185 while (dmadata->dmacount < NR_DMA_CHAIN) { 188 while (dmadata->dmacount < NR_DMA_CHAIN) {
186 dmadata->dmacount++; 189 dmadata->dmacount++;
187 spin_unlock_irqrestore(&dmadata->dma_lock, flags); 190 spin_unlock_irqrestore(&dmadata->dma_lock, flags);
diff --git a/sound/sound_core.c b/sound/sound_core.c
index 45759f4cca75..11e953a1fa45 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -626,31 +626,20 @@ static int soundcore_open(struct inode *inode, struct file *file)
626 if (s) 626 if (s)
627 new_fops = fops_get(s->unit_fops); 627 new_fops = fops_get(s->unit_fops);
628 } 628 }
629 spin_unlock(&sound_loader_lock);
629 if (new_fops) { 630 if (new_fops) {
630 /* 631 /*
631 * We rely upon the fact that we can't be unloaded while the 632 * We rely upon the fact that we can't be unloaded while the
632 * subdriver is there, so if ->open() is successful we can 633 * subdriver is there.
633 * safely drop the reference counter and if it is not we can
634 * revert to old ->f_op. Ugly, indeed, but that's the cost of
635 * switching ->f_op in the first place.
636 */ 634 */
637 int err = 0; 635 int err = 0;
638 const struct file_operations *old_fops = file->f_op; 636 replace_fops(file, new_fops);
639 file->f_op = new_fops;
640 spin_unlock(&sound_loader_lock);
641 637
642 if (file->f_op->open) 638 if (file->f_op->open)
643 err = file->f_op->open(inode,file); 639 err = file->f_op->open(inode,file);
644 640
645 if (err) {
646 fops_put(file->f_op);
647 file->f_op = fops_get(old_fops);
648 }
649
650 fops_put(old_fops);
651 return err; 641 return err;
652 } 642 }
653 spin_unlock(&sound_loader_lock);
654 return -ENODEV; 643 return -ENODEV;
655} 644}
656 645
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index 54aaad2a10f5..dbb1b625eb2f 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -429,7 +429,8 @@ static void snd_cs4231_advance_dma(struct cs4231_dma_control *dma_cont,
429 unsigned int period_size = snd_pcm_lib_period_bytes(substream); 429 unsigned int period_size = snd_pcm_lib_period_bytes(substream);
430 unsigned int offset = period_size * (*periods_sent); 430 unsigned int offset = period_size * (*periods_sent);
431 431
432 BUG_ON(period_size >= (1 << 24)); 432 if (WARN_ON(period_size >= (1 << 24)))
433 return;
433 434
434 if (dma_cont->request(dma_cont, 435 if (dma_cont->request(dma_cont,
435 runtime->dma_addr + offset, period_size)) 436 runtime->dma_addr + offset, period_size))
@@ -906,18 +907,24 @@ static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream)
906 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); 907 struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
907 struct snd_pcm_runtime *runtime = substream->runtime; 908 struct snd_pcm_runtime *runtime = substream->runtime;
908 unsigned long flags; 909 unsigned long flags;
910 int ret = 0;
909 911
910 spin_lock_irqsave(&chip->lock, flags); 912 spin_lock_irqsave(&chip->lock, flags);
911 913
912 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | 914 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE |
913 CS4231_PLAYBACK_PIO); 915 CS4231_PLAYBACK_PIO);
914 916
915 BUG_ON(runtime->period_size > 0xffff + 1); 917 if (WARN_ON(runtime->period_size > 0xffff + 1)) {
918 ret = -EINVAL;
919 goto out;
920 }
916 921
917 chip->p_periods_sent = 0; 922 chip->p_periods_sent = 0;
923
924out:
918 spin_unlock_irqrestore(&chip->lock, flags); 925 spin_unlock_irqrestore(&chip->lock, flags);
919 926
920 return 0; 927 return ret;
921} 928}
922 929
923static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream, 930static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream,
diff --git a/sound/usb/6fire/chip.c b/sound/usb/6fire/chip.c
index c39c77978468..66edc4a7917f 100644
--- a/sound/usb/6fire/chip.c
+++ b/sound/usb/6fire/chip.c
@@ -101,7 +101,7 @@ static int usb6fire_chip_probe(struct usb_interface *intf,
101 usb_set_intfdata(intf, chips[i]); 101 usb_set_intfdata(intf, chips[i]);
102 mutex_unlock(&register_mutex); 102 mutex_unlock(&register_mutex);
103 return 0; 103 return 0;
104 } else if (regidx < 0) 104 } else if (!devices[i] && regidx < 0)
105 regidx = i; 105 regidx = i;
106 } 106 }
107 if (regidx < 0) { 107 if (regidx < 0) {
diff --git a/sound/usb/caiaq/control.c b/sound/usb/caiaq/control.c
index ae6b50f9ed56..f65fc0987cfb 100644
--- a/sound/usb/caiaq/control.c
+++ b/sound/usb/caiaq/control.c
@@ -28,6 +28,7 @@
28#include "control.h" 28#include "control.h"
29 29
30#define CNT_INTVAL 0x10000 30#define CNT_INTVAL 0x10000
31#define MASCHINE_BANK_SIZE 32
31 32
32static int control_info(struct snd_kcontrol *kcontrol, 33static int control_info(struct snd_kcontrol *kcontrol,
33 struct snd_ctl_elem_info *uinfo) 34 struct snd_ctl_elem_info *uinfo)
@@ -105,6 +106,10 @@ static int control_put(struct snd_kcontrol *kcontrol,
105 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1)) 106 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1))
106 cmd = EP1_CMD_DIMM_LEDS; 107 cmd = EP1_CMD_DIMM_LEDS;
107 108
109 if (cdev->chip.usb_id ==
110 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER))
111 cmd = EP1_CMD_DIMM_LEDS;
112
108 if (pos & CNT_INTVAL) { 113 if (pos & CNT_INTVAL) {
109 int i = pos & ~CNT_INTVAL; 114 int i = pos & ~CNT_INTVAL;
110 115
@@ -121,6 +126,20 @@ static int control_put(struct snd_kcontrol *kcontrol,
121 usb_sndbulkpipe(cdev->chip.dev, 8), 126 usb_sndbulkpipe(cdev->chip.dev, 8),
122 cdev->ep8_out_buf, sizeof(cdev->ep8_out_buf), 127 cdev->ep8_out_buf, sizeof(cdev->ep8_out_buf),
123 &actual_len, 200); 128 &actual_len, 200);
129 } else if (cdev->chip.usb_id ==
130 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER)) {
131
132 int bank = 0;
133 int offset = 0;
134
135 if (i >= MASCHINE_BANK_SIZE) {
136 bank = 0x1e;
137 offset = MASCHINE_BANK_SIZE;
138 }
139
140 snd_usb_caiaq_send_command_bank(cdev, cmd, bank,
141 cdev->control_state + offset,
142 MASCHINE_BANK_SIZE);
124 } else { 143 } else {
125 snd_usb_caiaq_send_command(cdev, cmd, 144 snd_usb_caiaq_send_command(cdev, cmd,
126 cdev->control_state, sizeof(cdev->control_state)); 145 cdev->control_state, sizeof(cdev->control_state));
@@ -490,6 +509,74 @@ static struct caiaq_controller kontrols4_controller[] = {
490 { "LED: FX2: Mode", 133 | CNT_INTVAL }, 509 { "LED: FX2: Mode", 133 | CNT_INTVAL },
491}; 510};
492 511
512static struct caiaq_controller maschine_controller[] = {
513 { "LED: Pad 1", 3 | CNT_INTVAL },
514 { "LED: Pad 2", 2 | CNT_INTVAL },
515 { "LED: Pad 3", 1 | CNT_INTVAL },
516 { "LED: Pad 4", 0 | CNT_INTVAL },
517 { "LED: Pad 5", 7 | CNT_INTVAL },
518 { "LED: Pad 6", 6 | CNT_INTVAL },
519 { "LED: Pad 7", 5 | CNT_INTVAL },
520 { "LED: Pad 8", 4 | CNT_INTVAL },
521 { "LED: Pad 9", 11 | CNT_INTVAL },
522 { "LED: Pad 10", 10 | CNT_INTVAL },
523 { "LED: Pad 11", 9 | CNT_INTVAL },
524 { "LED: Pad 12", 8 | CNT_INTVAL },
525 { "LED: Pad 13", 15 | CNT_INTVAL },
526 { "LED: Pad 14", 14 | CNT_INTVAL },
527 { "LED: Pad 15", 13 | CNT_INTVAL },
528 { "LED: Pad 16", 12 | CNT_INTVAL },
529
530 { "LED: Mute", 16 | CNT_INTVAL },
531 { "LED: Solo", 17 | CNT_INTVAL },
532 { "LED: Select", 18 | CNT_INTVAL },
533 { "LED: Duplicate", 19 | CNT_INTVAL },
534 { "LED: Navigate", 20 | CNT_INTVAL },
535 { "LED: Pad Mode", 21 | CNT_INTVAL },
536 { "LED: Pattern", 22 | CNT_INTVAL },
537 { "LED: Scene", 23 | CNT_INTVAL },
538
539 { "LED: Shift", 24 | CNT_INTVAL },
540 { "LED: Erase", 25 | CNT_INTVAL },
541 { "LED: Grid", 26 | CNT_INTVAL },
542 { "LED: Right Bottom", 27 | CNT_INTVAL },
543 { "LED: Rec", 28 | CNT_INTVAL },
544 { "LED: Play", 29 | CNT_INTVAL },
545 { "LED: Left Bottom", 32 | CNT_INTVAL },
546 { "LED: Restart", 33 | CNT_INTVAL },
547
548 { "LED: Group A", 41 | CNT_INTVAL },
549 { "LED: Group B", 40 | CNT_INTVAL },
550 { "LED: Group C", 37 | CNT_INTVAL },
551 { "LED: Group D", 36 | CNT_INTVAL },
552 { "LED: Group E", 39 | CNT_INTVAL },
553 { "LED: Group F", 38 | CNT_INTVAL },
554 { "LED: Group G", 35 | CNT_INTVAL },
555 { "LED: Group H", 34 | CNT_INTVAL },
556
557 { "LED: Auto Write", 42 | CNT_INTVAL },
558 { "LED: Snap", 43 | CNT_INTVAL },
559 { "LED: Right Top", 44 | CNT_INTVAL },
560 { "LED: Left Top", 45 | CNT_INTVAL },
561 { "LED: Sampling", 46 | CNT_INTVAL },
562 { "LED: Browse", 47 | CNT_INTVAL },
563 { "LED: Step", 48 | CNT_INTVAL },
564 { "LED: Control", 49 | CNT_INTVAL },
565
566 { "LED: Top Button 1", 57 | CNT_INTVAL },
567 { "LED: Top Button 2", 56 | CNT_INTVAL },
568 { "LED: Top Button 3", 55 | CNT_INTVAL },
569 { "LED: Top Button 4", 54 | CNT_INTVAL },
570 { "LED: Top Button 5", 53 | CNT_INTVAL },
571 { "LED: Top Button 6", 52 | CNT_INTVAL },
572 { "LED: Top Button 7", 51 | CNT_INTVAL },
573 { "LED: Top Button 8", 50 | CNT_INTVAL },
574
575 { "LED: Note Repeat", 58 | CNT_INTVAL },
576
577 { "Backlight Display", 59 | CNT_INTVAL }
578};
579
493static int add_controls(struct caiaq_controller *c, int num, 580static int add_controls(struct caiaq_controller *c, int num,
494 struct snd_usb_caiaqdev *cdev) 581 struct snd_usb_caiaqdev *cdev)
495{ 582{
@@ -553,6 +640,11 @@ int snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *cdev)
553 ret = add_controls(kontrols4_controller, 640 ret = add_controls(kontrols4_controller,
554 ARRAY_SIZE(kontrols4_controller), cdev); 641 ARRAY_SIZE(kontrols4_controller), cdev);
555 break; 642 break;
643
644 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
645 ret = add_controls(maschine_controller,
646 ARRAY_SIZE(maschine_controller), cdev);
647 break;
556 } 648 }
557 649
558 return ret; 650 return ret;
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index 1a61dd12fe38..bc55f708a696 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -235,6 +235,31 @@ int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *cdev,
235 cdev->ep1_out_buf, len+1, &actual_len, 200); 235 cdev->ep1_out_buf, len+1, &actual_len, 200);
236} 236}
237 237
238int snd_usb_caiaq_send_command_bank(struct snd_usb_caiaqdev *cdev,
239 unsigned char command,
240 unsigned char bank,
241 const unsigned char *buffer,
242 int len)
243{
244 int actual_len;
245 struct usb_device *usb_dev = cdev->chip.dev;
246
247 if (!usb_dev)
248 return -EIO;
249
250 if (len > EP1_BUFSIZE - 2)
251 len = EP1_BUFSIZE - 2;
252
253 if (buffer && len > 0)
254 memcpy(cdev->ep1_out_buf+2, buffer, len);
255
256 cdev->ep1_out_buf[0] = command;
257 cdev->ep1_out_buf[1] = bank;
258
259 return usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, 1),
260 cdev->ep1_out_buf, len+2, &actual_len, 200);
261}
262
238int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *cdev, 263int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *cdev,
239 int rate, int depth, int bpp) 264 int rate, int depth, int bpp)
240{ 265{
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index ad102fac6942..ab0f7520a99b 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -128,5 +128,10 @@ int snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *cdev,
128 unsigned char command, 128 unsigned char command,
129 const unsigned char *buffer, 129 const unsigned char *buffer,
130 int len); 130 int len);
131int snd_usb_caiaq_send_command_bank(struct snd_usb_caiaqdev *cdev,
132 unsigned char command,
133 unsigned char bank,
134 const unsigned char *buffer,
135 int len);
131 136
132#endif /* CAIAQ_DEVICE_H */ 137#endif /* CAIAQ_DEVICE_H */
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 64952e2d3ed1..d979050e6a6a 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -79,7 +79,6 @@ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card *
79/* Vendor/product IDs for this card */ 79/* Vendor/product IDs for this card */
80static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; 80static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
81static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; 81static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
82static int nrpacks = 8; /* max. number of packets per urb */
83static int device_setup[SNDRV_CARDS]; /* device parameter for this card */ 82static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
84static bool ignore_ctl_error; 83static bool ignore_ctl_error;
85static bool autoclock = true; 84static bool autoclock = true;
@@ -94,8 +93,6 @@ module_param_array(vid, int, NULL, 0444);
94MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device."); 93MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device.");
95module_param_array(pid, int, NULL, 0444); 94module_param_array(pid, int, NULL, 0444);
96MODULE_PARM_DESC(pid, "Product ID for the USB audio device."); 95MODULE_PARM_DESC(pid, "Product ID for the USB audio device.");
97module_param(nrpacks, int, 0644);
98MODULE_PARM_DESC(nrpacks, "Max. number of packets per URB.");
99module_param_array(device_setup, int, NULL, 0444); 96module_param_array(device_setup, int, NULL, 0444);
100MODULE_PARM_DESC(device_setup, "Specific device setup (if needed)."); 97MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
101module_param(ignore_ctl_error, bool, 0444); 98module_param(ignore_ctl_error, bool, 0444);
@@ -349,6 +346,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
349 case USB_SPEED_LOW: 346 case USB_SPEED_LOW:
350 case USB_SPEED_FULL: 347 case USB_SPEED_FULL:
351 case USB_SPEED_HIGH: 348 case USB_SPEED_HIGH:
349 case USB_SPEED_WIRELESS:
352 case USB_SPEED_SUPER: 350 case USB_SPEED_SUPER:
353 break; 351 break;
354 default: 352 default:
@@ -374,7 +372,6 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
374 chip->dev = dev; 372 chip->dev = dev;
375 chip->card = card; 373 chip->card = card;
376 chip->setup = device_setup[idx]; 374 chip->setup = device_setup[idx];
377 chip->nrpacks = nrpacks;
378 chip->autoclock = autoclock; 375 chip->autoclock = autoclock;
379 chip->probing = 1; 376 chip->probing = 1;
380 377
@@ -754,19 +751,4 @@ static struct usb_driver usb_audio_driver = {
754 .supports_autosuspend = 1, 751 .supports_autosuspend = 1,
755}; 752};
756 753
757static int __init snd_usb_audio_init(void) 754module_usb_driver(usb_audio_driver);
758{
759 if (nrpacks < 1 || nrpacks > MAX_PACKS) {
760 printk(KERN_WARNING "invalid nrpacks value.\n");
761 return -EINVAL;
762 }
763 return usb_register(&usb_audio_driver);
764}
765
766static void __exit snd_usb_audio_cleanup(void)
767{
768 usb_deregister(&usb_audio_driver);
769}
770
771module_init(snd_usb_audio_init);
772module_exit(snd_usb_audio_cleanup);
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 5ecacaa90b53..9867ab866857 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -2,11 +2,11 @@
2#define __USBAUDIO_CARD_H 2#define __USBAUDIO_CARD_H
3 3
4#define MAX_NR_RATES 1024 4#define MAX_NR_RATES 1024
5#define MAX_PACKS 20 5#define MAX_PACKS 6 /* per URB */
6#define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */ 6#define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */
7#define MAX_URBS 8 7#define MAX_URBS 12
8#define SYNC_URBS 4 /* always four urbs for sync */ 8#define SYNC_URBS 4 /* always four urbs for sync */
9#define MAX_QUEUE 24 /* try not to exceed this queue length, in ms */ 9#define MAX_QUEUE 18 /* try not to exceed this queue length, in ms */
10 10
11struct audioformat { 11struct audioformat {
12 struct list_head list; 12 struct list_head list;
@@ -87,6 +87,7 @@ struct snd_usb_endpoint {
87 unsigned int phase; /* phase accumulator */ 87 unsigned int phase; /* phase accumulator */
88 unsigned int maxpacksize; /* max packet size in bytes */ 88 unsigned int maxpacksize; /* max packet size in bytes */
89 unsigned int maxframesize; /* max packet size in frames */ 89 unsigned int maxframesize; /* max packet size in frames */
90 unsigned int max_urb_frames; /* max URB size in frames */
90 unsigned int curpacksize; /* current packet size in bytes (for capture) */ 91 unsigned int curpacksize; /* current packet size in bytes (for capture) */
91 unsigned int curframesize; /* current packet size in frames (for capture) */ 92 unsigned int curframesize; /* current packet size in frames (for capture) */
92 unsigned int syncmaxsize; /* sync endpoint packet size */ 93 unsigned int syncmaxsize; /* sync endpoint packet size */
@@ -95,7 +96,7 @@ struct snd_usb_endpoint {
95 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ 96 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */
96 unsigned char silence_value; 97 unsigned char silence_value;
97 unsigned int stride; 98 unsigned int stride;
98 int iface, alt_idx; 99 int iface, altsetting;
99 int skip_packets; /* quirks for devices to ignore the first n packets 100 int skip_packets; /* quirks for devices to ignore the first n packets
100 in a stream */ 101 in a stream */
101 102
@@ -116,6 +117,8 @@ struct snd_usb_substream {
116 unsigned int channels_max; /* max channels in the all audiofmts */ 117 unsigned int channels_max; /* max channels in the all audiofmts */
117 unsigned int cur_rate; /* current rate (for hw_params callback) */ 118 unsigned int cur_rate; /* current rate (for hw_params callback) */
118 unsigned int period_bytes; /* current period bytes (for hw_params callback) */ 119 unsigned int period_bytes; /* current period bytes (for hw_params callback) */
120 unsigned int period_frames; /* current frames per period */
121 unsigned int buffer_periods; /* current periods per buffer */
119 unsigned int altset_idx; /* USB data format: index of alternate setting */ 122 unsigned int altset_idx; /* USB data format: index of alternate setting */
120 unsigned int txfr_quirk:1; /* allow sub-frame alignment */ 123 unsigned int txfr_quirk:1; /* allow sub-frame alignment */
121 unsigned int fmt_type; /* USB audio format type (1-3) */ 124 unsigned int fmt_type; /* USB audio format type (1-3) */
@@ -125,6 +128,7 @@ struct snd_usb_substream {
125 128
126 unsigned int hwptr_done; /* processed byte position in the buffer */ 129 unsigned int hwptr_done; /* processed byte position in the buffer */
127 unsigned int transfer_done; /* processed frames since last period update */ 130 unsigned int transfer_done; /* processed frames since last period update */
131 unsigned int frame_limit; /* limits number of packets in URB */
128 132
129 /* data and sync endpoints for this stream */ 133 /* data and sync endpoints for this stream */
130 unsigned int ep_num; /* the endpoint number */ 134 unsigned int ep_num; /* the endpoint number */
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 93e970f2b3c0..b9ba0fcc45df 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -33,7 +33,6 @@
33#include "pcm.h" 33#include "pcm.h"
34#include "quirks.h" 34#include "quirks.h"
35 35
36#define EP_FLAG_ACTIVATED 0
37#define EP_FLAG_RUNNING 1 36#define EP_FLAG_RUNNING 1
38#define EP_FLAG_STOPPING 2 37#define EP_FLAG_STOPPING 2
39 38
@@ -426,9 +425,9 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
426 list_for_each_entry(ep, &chip->ep_list, list) { 425 list_for_each_entry(ep, &chip->ep_list, list) {
427 if (ep->ep_num == ep_num && 426 if (ep->ep_num == ep_num &&
428 ep->iface == alts->desc.bInterfaceNumber && 427 ep->iface == alts->desc.bInterfaceNumber &&
429 ep->alt_idx == alts->desc.bAlternateSetting) { 428 ep->altsetting == alts->desc.bAlternateSetting) {
430 snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n", 429 snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n",
431 ep_num, ep->iface, ep->alt_idx, ep); 430 ep_num, ep->iface, ep->altsetting, ep);
432 goto __exit_unlock; 431 goto __exit_unlock;
433 } 432 }
434 } 433 }
@@ -447,7 +446,7 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
447 ep->type = type; 446 ep->type = type;
448 ep->ep_num = ep_num; 447 ep->ep_num = ep_num;
449 ep->iface = alts->desc.bInterfaceNumber; 448 ep->iface = alts->desc.bInterfaceNumber;
450 ep->alt_idx = alts->desc.bAlternateSetting; 449 ep->altsetting = alts->desc.bAlternateSetting;
451 INIT_LIST_HEAD(&ep->ready_playback_urbs); 450 INIT_LIST_HEAD(&ep->ready_playback_urbs);
452 ep_num &= USB_ENDPOINT_NUMBER_MASK; 451 ep_num &= USB_ENDPOINT_NUMBER_MASK;
453 452
@@ -574,11 +573,14 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
574 snd_pcm_format_t pcm_format, 573 snd_pcm_format_t pcm_format,
575 unsigned int channels, 574 unsigned int channels,
576 unsigned int period_bytes, 575 unsigned int period_bytes,
576 unsigned int frames_per_period,
577 unsigned int periods_per_buffer,
577 struct audioformat *fmt, 578 struct audioformat *fmt,
578 struct snd_usb_endpoint *sync_ep) 579 struct snd_usb_endpoint *sync_ep)
579{ 580{
580 unsigned int maxsize, i, urb_packs, total_packs, packs_per_ms; 581 unsigned int maxsize, minsize, packs_per_ms, max_packs_per_urb;
581 int is_playback = usb_pipeout(ep->pipe); 582 unsigned int max_packs_per_period, urbs_per_period, urb_packs;
583 unsigned int max_urbs, i;
582 int frame_bits = snd_pcm_format_physical_width(pcm_format) * channels; 584 int frame_bits = snd_pcm_format_physical_width(pcm_format) * channels;
583 585
584 if (pcm_format == SNDRV_PCM_FORMAT_DSD_U16_LE && fmt->dsd_dop) { 586 if (pcm_format == SNDRV_PCM_FORMAT_DSD_U16_LE && fmt->dsd_dop) {
@@ -611,58 +613,67 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
611 else 613 else
612 ep->curpacksize = maxsize; 614 ep->curpacksize = maxsize;
613 615
614 if (snd_usb_get_speed(ep->chip->dev) != USB_SPEED_FULL) 616 if (snd_usb_get_speed(ep->chip->dev) != USB_SPEED_FULL) {
615 packs_per_ms = 8 >> ep->datainterval; 617 packs_per_ms = 8 >> ep->datainterval;
616 else 618 max_packs_per_urb = MAX_PACKS_HS;
617 packs_per_ms = 1;
618
619 if (is_playback && !snd_usb_endpoint_implicit_feedback_sink(ep)) {
620 urb_packs = max(ep->chip->nrpacks, 1);
621 urb_packs = min(urb_packs, (unsigned int) MAX_PACKS);
622 } else { 619 } else {
623 urb_packs = 1; 620 packs_per_ms = 1;
621 max_packs_per_urb = MAX_PACKS;
624 } 622 }
623 if (sync_ep && !snd_usb_endpoint_implicit_feedback_sink(ep))
624 max_packs_per_urb = min(max_packs_per_urb,
625 1U << sync_ep->syncinterval);
626 max_packs_per_urb = max(1u, max_packs_per_urb >> ep->datainterval);
625 627
626 urb_packs *= packs_per_ms; 628 /*
629 * Capture endpoints need to use small URBs because there's no way
630 * to tell in advance where the next period will end, and we don't
631 * want the next URB to complete much after the period ends.
632 *
633 * Playback endpoints with implicit sync much use the same parameters
634 * as their corresponding capture endpoint.
635 */
636 if (usb_pipein(ep->pipe) ||
637 snd_usb_endpoint_implicit_feedback_sink(ep)) {
627 638
628 if (sync_ep && !snd_usb_endpoint_implicit_feedback_sink(ep)) 639 /* make capture URBs <= 1 ms and smaller than a period */
629 urb_packs = min(urb_packs, 1U << sync_ep->syncinterval); 640 urb_packs = min(max_packs_per_urb, packs_per_ms);
641 while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
642 urb_packs >>= 1;
643 ep->nurbs = MAX_URBS;
630 644
631 /* decide how many packets to be used */ 645 /*
632 if (is_playback && !snd_usb_endpoint_implicit_feedback_sink(ep)) { 646 * Playback endpoints without implicit sync are adjusted so that
633 unsigned int minsize, maxpacks; 647 * a period fits as evenly as possible in the smallest number of
648 * URBs. The total number of URBs is adjusted to the size of the
649 * ALSA buffer, subject to the MAX_URBS and MAX_QUEUE limits.
650 */
651 } else {
634 /* determine how small a packet can be */ 652 /* determine how small a packet can be */
635 minsize = (ep->freqn >> (16 - ep->datainterval)) 653 minsize = (ep->freqn >> (16 - ep->datainterval)) *
636 * (frame_bits >> 3); 654 (frame_bits >> 3);
637 /* with sync from device, assume it can be 12% lower */ 655 /* with sync from device, assume it can be 12% lower */
638 if (sync_ep) 656 if (sync_ep)
639 minsize -= minsize >> 3; 657 minsize -= minsize >> 3;
640 minsize = max(minsize, 1u); 658 minsize = max(minsize, 1u);
641 total_packs = (period_bytes + minsize - 1) / minsize;
642 /* we need at least two URBs for queueing */
643 if (total_packs < 2) {
644 total_packs = 2;
645 } else {
646 /* and we don't want too long a queue either */
647 maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
648 total_packs = min(total_packs, maxpacks);
649 }
650 } else {
651 while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
652 urb_packs >>= 1;
653 total_packs = MAX_URBS * urb_packs;
654 }
655 659
656 ep->nurbs = (total_packs + urb_packs - 1) / urb_packs; 660 /* how many packets will contain an entire ALSA period? */
657 if (ep->nurbs > MAX_URBS) { 661 max_packs_per_period = DIV_ROUND_UP(period_bytes, minsize);
658 /* too much... */ 662
659 ep->nurbs = MAX_URBS; 663 /* how many URBs will contain a period? */
660 total_packs = MAX_URBS * urb_packs; 664 urbs_per_period = DIV_ROUND_UP(max_packs_per_period,
661 } else if (ep->nurbs < 2) { 665 max_packs_per_urb);
662 /* too little - we need at least two packets 666 /* how many packets are needed in each URB? */
663 * to ensure contiguous playback/capture 667 urb_packs = DIV_ROUND_UP(max_packs_per_period, urbs_per_period);
664 */ 668
665 ep->nurbs = 2; 669 /* limit the number of frames in a single URB */
670 ep->max_urb_frames = DIV_ROUND_UP(frames_per_period,
671 urbs_per_period);
672
673 /* try to use enough URBs to contain an entire ALSA buffer */
674 max_urbs = min((unsigned) MAX_URBS,
675 MAX_QUEUE * packs_per_ms / urb_packs);
676 ep->nurbs = min(max_urbs, urbs_per_period * periods_per_buffer);
666 } 677 }
667 678
668 /* allocate and initialize data urbs */ 679 /* allocate and initialize data urbs */
@@ -670,8 +681,7 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
670 struct snd_urb_ctx *u = &ep->urb[i]; 681 struct snd_urb_ctx *u = &ep->urb[i];
671 u->index = i; 682 u->index = i;
672 u->ep = ep; 683 u->ep = ep;
673 u->packets = (i + 1) * total_packs / ep->nurbs 684 u->packets = urb_packs;
674 - i * total_packs / ep->nurbs;
675 u->buffer_size = maxsize * u->packets; 685 u->buffer_size = maxsize * u->packets;
676 686
677 if (fmt->fmt_type == UAC_FORMAT_TYPE_II) 687 if (fmt->fmt_type == UAC_FORMAT_TYPE_II)
@@ -703,8 +713,7 @@ out_of_memory:
703/* 713/*
704 * configure a sync endpoint 714 * configure a sync endpoint
705 */ 715 */
706static int sync_ep_set_params(struct snd_usb_endpoint *ep, 716static int sync_ep_set_params(struct snd_usb_endpoint *ep)
707 struct audioformat *fmt)
708{ 717{
709 int i; 718 int i;
710 719
@@ -748,6 +757,8 @@ out_of_memory:
748 * @pcm_format: the audio fomat. 757 * @pcm_format: the audio fomat.
749 * @channels: the number of audio channels. 758 * @channels: the number of audio channels.
750 * @period_bytes: the number of bytes in one alsa period. 759 * @period_bytes: the number of bytes in one alsa period.
760 * @period_frames: the number of frames in one alsa period.
761 * @buffer_periods: the number of periods in one alsa buffer.
751 * @rate: the frame rate. 762 * @rate: the frame rate.
752 * @fmt: the USB audio format information 763 * @fmt: the USB audio format information
753 * @sync_ep: the sync endpoint to use, if any 764 * @sync_ep: the sync endpoint to use, if any
@@ -760,6 +771,8 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
760 snd_pcm_format_t pcm_format, 771 snd_pcm_format_t pcm_format,
761 unsigned int channels, 772 unsigned int channels,
762 unsigned int period_bytes, 773 unsigned int period_bytes,
774 unsigned int period_frames,
775 unsigned int buffer_periods,
763 unsigned int rate, 776 unsigned int rate,
764 struct audioformat *fmt, 777 struct audioformat *fmt,
765 struct snd_usb_endpoint *sync_ep) 778 struct snd_usb_endpoint *sync_ep)
@@ -793,10 +806,11 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
793 switch (ep->type) { 806 switch (ep->type) {
794 case SND_USB_ENDPOINT_TYPE_DATA: 807 case SND_USB_ENDPOINT_TYPE_DATA:
795 err = data_ep_set_params(ep, pcm_format, channels, 808 err = data_ep_set_params(ep, pcm_format, channels,
796 period_bytes, fmt, sync_ep); 809 period_bytes, period_frames,
810 buffer_periods, fmt, sync_ep);
797 break; 811 break;
798 case SND_USB_ENDPOINT_TYPE_SYNC: 812 case SND_USB_ENDPOINT_TYPE_SYNC:
799 err = sync_ep_set_params(ep, fmt); 813 err = sync_ep_set_params(ep);
800 break; 814 break;
801 default: 815 default:
802 err = -EINVAL; 816 err = -EINVAL;
@@ -931,28 +945,21 @@ void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep)
931 * 945 *
932 * @ep: the endpoint to deactivate 946 * @ep: the endpoint to deactivate
933 * 947 *
934 * If the endpoint is not currently in use, this functions will select the 948 * If the endpoint is not currently in use, this functions will
935 * alternate interface setting 0 for the interface of this endpoint. 949 * deactivate its associated URBs.
936 * 950 *
937 * In case of any active users, this functions does nothing. 951 * In case of any active users, this functions does nothing.
938 *
939 * Returns an error if usb_set_interface() failed, 0 in all other
940 * cases.
941 */ 952 */
942int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep) 953void snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep)
943{ 954{
944 if (!ep) 955 if (!ep)
945 return -EINVAL; 956 return;
946
947 deactivate_urbs(ep, true);
948 wait_clear_urbs(ep);
949 957
950 if (ep->use_count != 0) 958 if (ep->use_count != 0)
951 return 0; 959 return;
952
953 clear_bit(EP_FLAG_ACTIVATED, &ep->flags);
954 960
955 return 0; 961 deactivate_urbs(ep, true);
962 wait_clear_urbs(ep);
956} 963}
957 964
958/** 965/**
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
index 2287adf5ca59..1c7e8ee48abc 100644
--- a/sound/usb/endpoint.h
+++ b/sound/usb/endpoint.h
@@ -12,6 +12,8 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
12 snd_pcm_format_t pcm_format, 12 snd_pcm_format_t pcm_format,
13 unsigned int channels, 13 unsigned int channels,
14 unsigned int period_bytes, 14 unsigned int period_bytes,
15 unsigned int period_frames,
16 unsigned int buffer_periods,
15 unsigned int rate, 17 unsigned int rate,
16 struct audioformat *fmt, 18 struct audioformat *fmt,
17 struct snd_usb_endpoint *sync_ep); 19 struct snd_usb_endpoint *sync_ep);
@@ -20,7 +22,7 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep);
20void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep); 22void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep);
21void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep); 23void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep);
22int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep); 24int snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
23int snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep); 25void snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep);
24void snd_usb_endpoint_free(struct list_head *head); 26void snd_usb_endpoint_free(struct list_head *head);
25 27
26int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep); 28int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep);
diff --git a/sound/usb/helper.c b/sound/usb/helper.c
index 620902463c6e..51ed1ac825fd 100644
--- a/sound/usb/helper.c
+++ b/sound/usb/helper.c
@@ -118,6 +118,7 @@ unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
118{ 118{
119 switch (snd_usb_get_speed(chip->dev)) { 119 switch (snd_usb_get_speed(chip->dev)) {
120 case USB_SPEED_HIGH: 120 case USB_SPEED_HIGH:
121 case USB_SPEED_WIRELESS:
121 case USB_SPEED_SUPER: 122 case USB_SPEED_SUPER:
122 if (get_endpoint(alts, 0)->bInterval >= 1 && 123 if (get_endpoint(alts, 0)->bInterval >= 1 &&
123 get_endpoint(alts, 0)->bInterval <= 4) 124 get_endpoint(alts, 0)->bInterval <= 4)
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 95558ef4a7a0..44b0ba4feab3 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1151,14 +1151,14 @@ static void check_no_speaker_on_headset(struct snd_kcontrol *kctl,
1151 const char *names_to_check[] = { 1151 const char *names_to_check[] = {
1152 "Headset", "headset", "Headphone", "headphone", NULL}; 1152 "Headset", "headset", "Headphone", "headphone", NULL};
1153 const char **s; 1153 const char **s;
1154 bool found = 0; 1154 bool found = false;
1155 1155
1156 if (strcmp("Speaker", kctl->id.name)) 1156 if (strcmp("Speaker", kctl->id.name))
1157 return; 1157 return;
1158 1158
1159 for (s = names_to_check; *s; s++) 1159 for (s = names_to_check; *s; s++)
1160 if (strstr(card->shortname, *s)) { 1160 if (strstr(card->shortname, *s)) {
1161 found = 1; 1161 found = true;
1162 break; 1162 break;
1163 } 1163 }
1164 1164
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index d42a584cf829..3454262358b3 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -433,6 +433,89 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
433 } 433 }
434} 434}
435 435
436/* EMU0204 */
437static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
438 struct snd_ctl_elem_info *uinfo)
439{
440 static const char *texts[2] = {"1/2",
441 "3/4"
442 };
443
444 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
445 uinfo->count = 1;
446 uinfo->value.enumerated.items = 2;
447 if (uinfo->value.enumerated.item > 1)
448 uinfo->value.enumerated.item = 1;
449 strcpy(uinfo->value.enumerated.name,
450 texts[uinfo->value.enumerated.item]);
451
452 return 0;
453}
454
455static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_value *ucontrol)
457{
458 ucontrol->value.enumerated.item[0] = kcontrol->private_value;
459 return 0;
460}
461
462static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
463 struct snd_ctl_elem_value *ucontrol)
464{
465 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
466 unsigned int value = ucontrol->value.enumerated.item[0];
467 int err, changed;
468 unsigned char buf[2];
469
470 if (value > 1)
471 return -EINVAL;
472
473 buf[0] = 0x01;
474 buf[1] = value ? 0x02 : 0x01;
475
476 changed = value != kcontrol->private_value;
477 down_read(&mixer->chip->shutdown_rwsem);
478 if (mixer->chip->shutdown) {
479 err = -ENODEV;
480 goto out;
481 }
482 err = snd_usb_ctl_msg(mixer->chip->dev,
483 usb_sndctrlpipe(mixer->chip->dev, 0), UAC_SET_CUR,
484 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
485 0x0400, 0x0e00, buf, 2);
486 out:
487 up_read(&mixer->chip->shutdown_rwsem);
488 if (err < 0)
489 return err;
490 kcontrol->private_value = value;
491 return changed;
492}
493
494
495static struct snd_kcontrol_new snd_emu0204_controls[] = {
496 {
497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
498 .name = "Front Jack Channels",
499 .info = snd_emu0204_ch_switch_info,
500 .get = snd_emu0204_ch_switch_get,
501 .put = snd_emu0204_ch_switch_put,
502 .private_value = 0,
503 },
504};
505
506static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
507{
508 int i, err;
509
510 for (i = 0; i < ARRAY_SIZE(snd_emu0204_controls); ++i) {
511 err = snd_ctl_add(mixer->chip->card,
512 snd_ctl_new1(&snd_emu0204_controls[i], mixer));
513 if (err < 0)
514 return err;
515 }
516
517 return 0;
518}
436/* ASUS Xonar U1 / U3 controls */ 519/* ASUS Xonar U1 / U3 controls */
437 520
438static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, 521static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
@@ -1545,6 +1628,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
1545 snd_audigy2nx_proc_read); 1628 snd_audigy2nx_proc_read);
1546 break; 1629 break;
1547 1630
1631 /* EMU0204 */
1632 case USB_ID(0x041e, 0x3f19):
1633 err = snd_emu0204_controls_create(mixer);
1634 if (err < 0)
1635 break;
1636 break;
1637
1548 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ 1638 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
1549 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */ 1639 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
1550 err = snd_c400_create_mixer(mixer); 1640 err = snd_c400_create_mixer(mixer);
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index b375d58871e7..ca3256d6fde3 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -241,16 +241,17 @@ static int start_endpoints(struct snd_usb_substream *subs, bool can_sleep)
241 struct snd_usb_endpoint *ep = subs->sync_endpoint; 241 struct snd_usb_endpoint *ep = subs->sync_endpoint;
242 242
243 if (subs->data_endpoint->iface != subs->sync_endpoint->iface || 243 if (subs->data_endpoint->iface != subs->sync_endpoint->iface ||
244 subs->data_endpoint->alt_idx != subs->sync_endpoint->alt_idx) { 244 subs->data_endpoint->altsetting != subs->sync_endpoint->altsetting) {
245 err = usb_set_interface(subs->dev, 245 err = usb_set_interface(subs->dev,
246 subs->sync_endpoint->iface, 246 subs->sync_endpoint->iface,
247 subs->sync_endpoint->alt_idx); 247 subs->sync_endpoint->altsetting);
248 if (err < 0) { 248 if (err < 0) {
249 clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags);
249 snd_printk(KERN_ERR 250 snd_printk(KERN_ERR
250 "%d:%d:%d: cannot set interface (%d)\n", 251 "%d:%d:%d: cannot set interface (%d)\n",
251 subs->dev->devnum, 252 subs->dev->devnum,
252 subs->sync_endpoint->iface, 253 subs->sync_endpoint->iface,
253 subs->sync_endpoint->alt_idx, err); 254 subs->sync_endpoint->altsetting, err);
254 return -EIO; 255 return -EIO;
255 } 256 }
256 } 257 }
@@ -282,22 +283,6 @@ static void stop_endpoints(struct snd_usb_substream *subs, bool wait)
282 } 283 }
283} 284}
284 285
285static int deactivate_endpoints(struct snd_usb_substream *subs)
286{
287 int reta, retb;
288
289 reta = snd_usb_endpoint_deactivate(subs->sync_endpoint);
290 retb = snd_usb_endpoint_deactivate(subs->data_endpoint);
291
292 if (reta < 0)
293 return reta;
294
295 if (retb < 0)
296 return retb;
297
298 return 0;
299}
300
301static int search_roland_implicit_fb(struct usb_device *dev, int ifnum, 286static int search_roland_implicit_fb(struct usb_device *dev, int ifnum,
302 unsigned int altsetting, 287 unsigned int altsetting,
303 struct usb_host_interface **alts, 288 struct usb_host_interface **alts,
@@ -595,6 +580,7 @@ static int configure_sync_endpoint(struct snd_usb_substream *subs)
595 subs->pcm_format, 580 subs->pcm_format,
596 subs->channels, 581 subs->channels,
597 subs->period_bytes, 582 subs->period_bytes,
583 0, 0,
598 subs->cur_rate, 584 subs->cur_rate,
599 subs->cur_audiofmt, 585 subs->cur_audiofmt,
600 NULL); 586 NULL);
@@ -631,6 +617,7 @@ static int configure_sync_endpoint(struct snd_usb_substream *subs)
631 subs->pcm_format, 617 subs->pcm_format,
632 sync_fp->channels, 618 sync_fp->channels,
633 sync_period_bytes, 619 sync_period_bytes,
620 0, 0,
634 subs->cur_rate, 621 subs->cur_rate,
635 sync_fp, 622 sync_fp,
636 NULL); 623 NULL);
@@ -653,6 +640,8 @@ static int configure_endpoint(struct snd_usb_substream *subs)
653 subs->pcm_format, 640 subs->pcm_format,
654 subs->channels, 641 subs->channels,
655 subs->period_bytes, 642 subs->period_bytes,
643 subs->period_frames,
644 subs->buffer_periods,
656 subs->cur_rate, 645 subs->cur_rate,
657 subs->cur_audiofmt, 646 subs->cur_audiofmt,
658 subs->sync_endpoint); 647 subs->sync_endpoint);
@@ -689,6 +678,8 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
689 678
690 subs->pcm_format = params_format(hw_params); 679 subs->pcm_format = params_format(hw_params);
691 subs->period_bytes = params_period_bytes(hw_params); 680 subs->period_bytes = params_period_bytes(hw_params);
681 subs->period_frames = params_period_size(hw_params);
682 subs->buffer_periods = params_periods(hw_params);
692 subs->channels = params_channels(hw_params); 683 subs->channels = params_channels(hw_params);
693 subs->cur_rate = params_rate(hw_params); 684 subs->cur_rate = params_rate(hw_params);
694 685
@@ -730,7 +721,8 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
730 down_read(&subs->stream->chip->shutdown_rwsem); 721 down_read(&subs->stream->chip->shutdown_rwsem);
731 if (!subs->stream->chip->shutdown) { 722 if (!subs->stream->chip->shutdown) {
732 stop_endpoints(subs, true); 723 stop_endpoints(subs, true);
733 deactivate_endpoints(subs); 724 snd_usb_endpoint_deactivate(subs->sync_endpoint);
725 snd_usb_endpoint_deactivate(subs->data_endpoint);
734 } 726 }
735 up_read(&subs->stream->chip->shutdown_rwsem); 727 up_read(&subs->stream->chip->shutdown_rwsem);
736 return snd_pcm_lib_free_vmalloc_buffer(substream); 728 return snd_pcm_lib_free_vmalloc_buffer(substream);
@@ -1363,6 +1355,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
1363 frames = 0; 1355 frames = 0;
1364 urb->number_of_packets = 0; 1356 urb->number_of_packets = 0;
1365 spin_lock_irqsave(&subs->lock, flags); 1357 spin_lock_irqsave(&subs->lock, flags);
1358 subs->frame_limit += ep->max_urb_frames;
1366 for (i = 0; i < ctx->packets; i++) { 1359 for (i = 0; i < ctx->packets; i++) {
1367 if (ctx->packet_size[i]) 1360 if (ctx->packet_size[i])
1368 counts = ctx->packet_size[i]; 1361 counts = ctx->packet_size[i];
@@ -1377,6 +1370,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
1377 subs->transfer_done += counts; 1370 subs->transfer_done += counts;
1378 if (subs->transfer_done >= runtime->period_size) { 1371 if (subs->transfer_done >= runtime->period_size) {
1379 subs->transfer_done -= runtime->period_size; 1372 subs->transfer_done -= runtime->period_size;
1373 subs->frame_limit = 0;
1380 period_elapsed = 1; 1374 period_elapsed = 1;
1381 if (subs->fmt_type == UAC_FORMAT_TYPE_II) { 1375 if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
1382 if (subs->transfer_done > 0) { 1376 if (subs->transfer_done > 0) {
@@ -1399,8 +1393,10 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
1399 break; 1393 break;
1400 } 1394 }
1401 } 1395 }
1402 if (period_elapsed && 1396 /* finish at the period boundary or after enough frames */
1403 !snd_usb_endpoint_implicit_feedback_sink(subs->data_endpoint)) /* finish at the period boundary */ 1397 if ((period_elapsed ||
1398 subs->transfer_done >= subs->frame_limit) &&
1399 !snd_usb_endpoint_implicit_feedback_sink(ep))
1404 break; 1400 break;
1405 } 1401 }
1406 bytes = frames * ep->stride; 1402 bytes = frames * ep->stride;
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index c4339f97226b..2fb71be5e100 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -273,16 +273,14 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits,
273 SNDRV_CHMAP_TSL, /* top side left */ 273 SNDRV_CHMAP_TSL, /* top side left */
274 SNDRV_CHMAP_TSR, /* top side right */ 274 SNDRV_CHMAP_TSR, /* top side right */
275 SNDRV_CHMAP_BC, /* bottom center */ 275 SNDRV_CHMAP_BC, /* bottom center */
276 SNDRV_CHMAP_BLC, /* bottom left center */ 276 SNDRV_CHMAP_RLC, /* back left of center */
277 SNDRV_CHMAP_BRC, /* bottom right center */ 277 SNDRV_CHMAP_RRC, /* back right of center */
278 0 /* terminator */ 278 0 /* terminator */
279 }; 279 };
280 struct snd_pcm_chmap_elem *chmap; 280 struct snd_pcm_chmap_elem *chmap;
281 const unsigned int *maps; 281 const unsigned int *maps;
282 int c; 282 int c;
283 283
284 if (!bits)
285 return NULL;
286 if (channels > ARRAY_SIZE(chmap->map)) 284 if (channels > ARRAY_SIZE(chmap->map))
287 return NULL; 285 return NULL;
288 286
@@ -293,9 +291,19 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits,
293 maps = protocol == UAC_VERSION_2 ? uac2_maps : uac1_maps; 291 maps = protocol == UAC_VERSION_2 ? uac2_maps : uac1_maps;
294 chmap->channels = channels; 292 chmap->channels = channels;
295 c = 0; 293 c = 0;
296 for (; bits && *maps; maps++, bits >>= 1) { 294
297 if (bits & 1) 295 if (bits) {
298 chmap->map[c++] = *maps; 296 for (; bits && *maps; maps++, bits >>= 1)
297 if (bits & 1)
298 chmap->map[c++] = *maps;
299 } else {
300 /* If we're missing wChannelConfig, then guess something
301 to make sure the channel map is not skipped entirely */
302 if (channels == 1)
303 chmap->map[c++] = SNDRV_CHMAP_MONO;
304 else
305 for (; c < channels && *maps; maps++)
306 chmap->map[c++] = *maps;
299 } 307 }
300 308
301 for (; c < channels; c++) 309 for (; c < channels; c++)
@@ -579,6 +587,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
579 587
580 num_channels = as->bNrChannels; 588 num_channels = as->bNrChannels;
581 format = le32_to_cpu(as->bmFormats); 589 format = le32_to_cpu(as->bmFormats);
590 chconfig = le32_to_cpu(as->bmChannelConfig);
582 591
583 /* lookup the terminal associated to this interface 592 /* lookup the terminal associated to this interface
584 * to extract the clock */ 593 * to extract the clock */
@@ -586,7 +595,8 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
586 as->bTerminalLink); 595 as->bTerminalLink);
587 if (input_term) { 596 if (input_term) {
588 clock = input_term->bCSourceID; 597 clock = input_term->bCSourceID;
589 chconfig = le32_to_cpu(input_term->bmChannelConfig); 598 if (!chconfig && (num_channels == input_term->bNrChannels))
599 chconfig = le32_to_cpu(input_term->bmChannelConfig);
590 break; 600 break;
591 } 601 }
592 602
@@ -652,7 +662,6 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
652 * (fp->maxpacksize & 0x7ff); 662 * (fp->maxpacksize & 0x7ff);
653 fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no); 663 fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no);
654 fp->clock = clock; 664 fp->clock = clock;
655 fp->chmap = convert_chmap(num_channels, chconfig, protocol);
656 665
657 /* some quirks for attributes here */ 666 /* some quirks for attributes here */
658 667
@@ -688,12 +697,16 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
688 /* ok, let's parse further... */ 697 /* ok, let's parse further... */
689 if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream) < 0) { 698 if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream) < 0) {
690 kfree(fp->rate_table); 699 kfree(fp->rate_table);
691 kfree(fp->chmap);
692 kfree(fp); 700 kfree(fp);
693 fp = NULL; 701 fp = NULL;
694 continue; 702 continue;
695 } 703 }
696 704
705 /* Create chmap */
706 if (fp->channels != num_channels)
707 chconfig = 0;
708 fp->chmap = convert_chmap(fp->channels, chconfig, protocol);
709
697 snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint); 710 snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint);
698 err = snd_usb_add_audio_stream(chip, stream, fp); 711 err = snd_usb_add_audio_stream(chip, stream, fp);
699 if (err < 0) { 712 if (err < 0) {
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index caabe9b3af49..5d2fe0530745 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -55,7 +55,6 @@ struct snd_usb_audio {
55 struct list_head mixer_list; /* list of mixer interfaces */ 55 struct list_head mixer_list; /* list of mixer interfaces */
56 56
57 int setup; /* from the 'device_setup' module param */ 57 int setup; /* from the 'device_setup' module param */
58 int nrpacks; /* from the 'nrpacks' module param */
59 bool autoclock; /* from the 'autoclock' module param */ 58 bool autoclock; /* from the 'autoclock' module param */
60 59
61 struct usb_host_interface *ctrl_intf; /* the audio control interface */ 60 struct usb_host_interface *ctrl_intf; /* the audio control interface */
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index d0323a693ba2..999550bbad40 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -262,7 +262,9 @@ static int usb_stream_hwdep_mmap(struct snd_hwdep *hw,
262 } 262 }
263 263
264 area->vm_ops = &usb_stream_hwdep_vm_ops; 264 area->vm_ops = &usb_stream_hwdep_vm_ops;
265 area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; 265 area->vm_flags |= VM_DONTDUMP;
266 if (!read)
267 area->vm_flags |= VM_DONTEXPAND;
266 area->vm_private_data = us122l; 268 area->vm_private_data = us122l;
267 atomic_inc(&us122l->mmap_count); 269 atomic_inc(&us122l->mmap_count);
268out: 270out:
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index 63fb5219f0f8..6234a51625b1 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -299,19 +299,6 @@ static void usX2Y_error_urb_status(struct usX2Ydev *usX2Y,
299 usX2Y_clients_stop(usX2Y); 299 usX2Y_clients_stop(usX2Y);
300} 300}
301 301
302static void usX2Y_error_sequence(struct usX2Ydev *usX2Y,
303 struct snd_usX2Y_substream *subs, struct urb *urb)
304{
305 snd_printk(KERN_ERR
306"Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n"
307"Most probably some urb of usb-frame %i is still missing.\n"
308"Cause could be too long delays in usb-hcd interrupt handling.\n",
309 usb_get_current_frame_number(usX2Y->dev),
310 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out",
311 usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame);
312 usX2Y_clients_stop(usX2Y);
313}
314
315static void i_usX2Y_urb_complete(struct urb *urb) 302static void i_usX2Y_urb_complete(struct urb *urb)
316{ 303{
317 struct snd_usX2Y_substream *subs = urb->context; 304 struct snd_usX2Y_substream *subs = urb->context;
@@ -328,12 +315,9 @@ static void i_usX2Y_urb_complete(struct urb *urb)
328 usX2Y_error_urb_status(usX2Y, subs, urb); 315 usX2Y_error_urb_status(usX2Y, subs, urb);
329 return; 316 return;
330 } 317 }
331 if (likely((urb->start_frame & 0xFFFF) == (usX2Y->wait_iso_frame & 0xFFFF))) 318
332 subs->completed_urb = urb; 319 subs->completed_urb = urb;
333 else { 320
334 usX2Y_error_sequence(usX2Y, subs, urb);
335 return;
336 }
337 { 321 {
338 struct snd_usX2Y_substream *capsubs = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE], 322 struct snd_usX2Y_substream *capsubs = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE],
339 *playbacksubs = usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; 323 *playbacksubs = usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index f2a1acdc4d83..814d0e887c62 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -244,13 +244,8 @@ static void i_usX2Y_usbpcm_urb_complete(struct urb *urb)
244 usX2Y_error_urb_status(usX2Y, subs, urb); 244 usX2Y_error_urb_status(usX2Y, subs, urb);
245 return; 245 return;
246 } 246 }
247 if (likely((urb->start_frame & 0xFFFF) == (usX2Y->wait_iso_frame & 0xFFFF)))
248 subs->completed_urb = urb;
249 else {
250 usX2Y_error_sequence(usX2Y, subs, urb);
251 return;
252 }
253 247
248 subs->completed_urb = urb;
254 capsubs = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]; 249 capsubs = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE];
255 capsubs2 = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2]; 250 capsubs2 = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2];
256 playbacksubs = usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]; 251 playbacksubs = usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];