diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
new file mode 100644
index 0000000..ff7d725
--- /dev/null
+++ b/sound/soc/Kconfig
@@ -0,0 +1,30 @@
+#
+# SoC audio configuration
+#
+
+menu "SoC audio support"
+
+config SND_SOC
+	tristate "SoC audio support"
+	---help---
+
+	  If you want SoC support, you should say Y here and also to the
+	  specific driver for your SoC below. You will also need to select the 
+	  specific codec(s) attached to the SoC
+
+	  This SoC audio support can also be built as a module.  If so, the module
+	  will be called snd-soc-core.
+
+# All the supported Soc's
+menu "Soc Platforms"
+depends on SND_SOC
+source "sound/soc/pxa/Kconfig"
+endmenu
+
+# Supported codecs
+menu "Soc Codecs"
+depends on SND_SOC
+source "sound/soc/codecs/Kconfig"
+endmenu
+
+endmenu
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
new file mode 100644
index 0000000..0837687
--- /dev/null
+++ b/sound/soc/Makefile
@@ -0,0 +1,5 @@
+
+snd-soc-core-objs := soc-core.o soc-dapm.o
+
+obj-$(CONFIG_SND_SOC)	+= snd-soc-core.o
+obj-$(CONFIG_SND_SOC)	+= pxa/ codecs/
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
new file mode 100644
index 0000000..f9f5302
--- /dev/null
+++ b/sound/soc/codecs/Kconfig
@@ -0,0 +1,60 @@
+config SND_SOC_AC97_CODEC
+	tristate "SoC generic AC97 support"
+	depends SND_SOC
+	help
+	  Say Y or M if you want generic AC97 support. This is not required
+	  for the AC97 codecs listed below.
+
+config SND_SOC_WM8731
+	tristate "SoC driver for the WM8731 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the WM8731 codec.
+ 
+config SND_SOC_WM8750
+	tristate "SoC driver for the WM8750 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the WM8750 codec.
+	  
+config SND_SOC_WM8753
+	tristate "SoC driver for the WM8753 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the WM8753 codec.
+	  
+config SND_SOC_WM8772
+	tristate "SoC driver for the WM8772 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the WM8772 codec.
+	  
+config SND_SOC_WM8971
+	tristate "SoC driver for the WM8971 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the WM8971 codec.
+
+config SND_SOC_WM9713
+	tristate "SoC driver for the WM9713 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the WM9713 codec.
+
+config SND_SOC_WM9712
+	tristate "SoC driver for the WM9712 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the WM9712 codec.
+
+config SND_SOC_UDA1380
+	tristate "SoC driver for the UDA1380 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the UDA1380 codec.
+	  
+config SND_SOC_AK4535
+	tristate "SoC driver for the AK4535 codec"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support the AK4535 codec.
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
new file mode 100644
index 0000000..26476da
--- /dev/null
+++ b/sound/soc/codecs/Makefile
@@ -0,0 +1,21 @@
+snd-soc-ac97-objs := ac97.o
+snd-soc-wm8731-objs := wm8731.o
+snd-soc-wm8750-objs := wm8750.o
+snd-soc-wm8753-objs := wm8753.o
+snd-soc-wm8772-objs := wm8772.o
+snd-soc-wm8971-objs := wm8971.o
+snd-soc-uda1380-objs := uda1380.o
+snd-soc-ak4535-objs := ak4535.o
+snd-soc-wm9713-objs := wm9713.o
+snd-soc-wm9712-objs := wm9712.o
+
+obj-$(CONFIG_SND_SOC_AC97_CODEC)	+= snd-soc-ac97.o
+obj-$(CONFIG_SND_SOC_WM8731)	+= snd-soc-wm8731.o
+obj-$(CONFIG_SND_SOC_WM8750)	+= snd-soc-wm8750.o
+obj-$(CONFIG_SND_SOC_WM8753)	+= snd-soc-wm8753.o
+obj-$(CONFIG_SND_SOC_WM8772)	+= snd-soc-wm8772.o
+obj-$(CONFIG_SND_SOC_WM8971)	+= snd-soc-wm8971.o
+obj-$(CONFIG_SND_SOC_UDA1380)	+= snd-soc-uda1380.o
+obj-$(CONFIG_SND_SOC_AK4535)	+= snd-soc-ak4535.o
+obj-$(CONFIG_SND_SOC_WM9713)	+= snd-soc-wm9713.o
+obj-$(CONFIG_SND_SOC_WM9712)	+= snd-soc-wm9712.o
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
new file mode 100644
index 0000000..fd97663
--- /dev/null
+++ b/sound/soc/codecs/ac97.c
@@ -0,0 +1,164 @@
+/*
+ * ac97.c  --  ALSA Soc AC97 codec support
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    17th Oct 2005   Initial version.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/ac97_codec.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+
+#define AC97_VERSION "0.5"
+
+#define AC97_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+	
+#define AC97_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
+	
+#define AC97_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S18_3LE | SNDRV_PCM_FORMAT_S20_3LE)
+
+/* may need to expand this */
+static struct snd_soc_hw_mode soc_ac97[] = {
+	{0, 0,	AC97_PCM_FORMATS,	AC97_RATES},
+};
+
+static int ac97_prepare(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	
+	int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+		  AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
+	return snd_ac97_set_rate(codec->ac97, reg, runtime->rate);
+}
+
+static struct snd_soc_pcm_codec ac97_soc_client = {
+	.name = "AC97 HiFi",
+	.playback = {
+		.sname = "AC97 Playback",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.capture = {
+		.sname = "AC97 Capture",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.nplayback = 1,
+	.ncapture = 1,
+	.ops = {
+		.prepare = ac97_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(soc_ac97),
+		.hmodes = &soc_ac97[0],},
+};
+
+static unsigned int ac97_read(struct snd_soc_codec *codec, 
+	unsigned int reg)
+{
+	return soc_ac97_ops.read(codec->ac97, reg);
+}
+
+static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
+	unsigned int val)
+{
+	soc_ac97_ops.write(codec->ac97, reg, val);
+	return 0;
+}
+
+static int ac97_soc_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec;
+	ac97_bus_t *ac97_bus;
+	ac97_template_t ac97_template;
+	int ret = 0;
+
+	printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
+
+	if ((socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	codec = socdev->codec;
+	
+	codec->name = "AC97";
+	codec->owner = THIS_MODULE;
+	codec->pcms = &ac97_soc_client;
+	codec->npcms = 1;
+	codec->write = ac97_write;
+	codec->read = ac97_read;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+		
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0)
+		goto err;
+		
+	/* add codec as bus device for standard ac97 */
+	if((ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus)) < 0)
+		goto bus_err;
+	
+	memset(&ac97_template, 0, sizeof(ac97_template));
+	if((ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97)) < 0)
+		goto bus_err;
+
+	snd_soc_register_card(socdev);
+	return 0;
+	
+bus_err:	
+	snd_soc_free_pcms(socdev);
+	
+err:
+	kfree(socdev->codec->reg_cache);
+	kfree(socdev->codec);
+	socdev->codec = NULL;
+	return ret;
+}
+
+static int ac97_soc_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	
+	if(codec == NULL)
+		return 0;
+	
+	snd_soc_free_pcms(socdev);
+	kfree(socdev->codec->reg_cache);
+	kfree(socdev->codec);
+	
+	return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_ac97= {
+	.probe = 	ac97_soc_probe,
+	.remove = 	ac97_soc_remove,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_ac97);
+
+MODULE_DESCRIPTION("Soc Generic AC97 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
+
diff --git a/sound/soc/codecs/ac97.h b/sound/soc/codecs/ac97.h
new file mode 100644
index 0000000..3393fc6
--- /dev/null
+++ b/sound/soc/codecs/ac97.h
@@ -0,0 +1,18 @@
+/*
+ * linux/sound/codecs/ac97.h -- ALSA SoC Layer
+ *
+ * Author:		Liam Girdwood
+ * Created:		Dec 1st 2005
+ * Copyright:	Wolfson Microelectronics. PLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+ 
+#ifndef __LINUX_SND_SOC_AC97_H
+#define __LINUX_SND_SOC_AC97_H
+
+extern struct snd_soc_codec_device soc_codec_dev_ac97;
+
+#endif
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
new file mode 100644
index 0000000..19414a6
--- /dev/null
+++ b/sound/soc/codecs/ak4535.c
@@ -0,0 +1,655 @@
+/*
+ * ak4535.c  --  AK4535 ALSA Soc Audio driver
+ *
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Author: Richard Purdie <richard@openedhand.com>
+ *
+ * Based on wm8753.c by Liam Girdwood
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include "ak4535.h"
+
+#define AUDIO_NAME "ak4535"
+#define AK4535_VERSION "0.1"
+
+struct snd_soc_codec_device soc_codec_dev_ak4535;
+
+/*
+ * ak4535 register cache
+ */
+static const u16 ak4535_reg[AK4535_CACHEREGNUM] = {
+    0x0000, 0x0080, 0x0000, 0x0003, 
+    0x0002, 0x0000, 0x0011, 0x0001, 
+    0x0000, 0x0040, 0x0036, 0x0010,
+    0x0000, 0x0000, 0x0057, 0x0000,
+};
+
+#define AK4535_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_CBS_CFS | \
+	SND_SOC_HWFMT_NB_NF)
+
+#define AK4535_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+	
+#define AK4535_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000)
+	
+static struct snd_soc_hw_mode ak4535_hwfmt[] = {
+	/* codec frame and clock slave modes */
+	{AK4535_HWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		AK4535_RATES, AK4535_DIR, 0, SND_SOC_FS(256), 
+		SND_SOC_FSB(64) | SND_SOC_FSB(32)},
+};
+
+
+/*
+ * read ak4535 register cache
+ */
+static inline unsigned int ak4535_read_reg_cache(struct snd_soc_codec * codec,
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg >= AK4535_CACHEREGNUM)
+		return -1;
+	return cache[reg];
+}
+
+/*
+ * write ak4535 register cache
+ */
+static inline void ak4535_write_reg_cache(struct snd_soc_codec * codec,
+	u16 reg, unsigned int value)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg >= AK4535_CACHEREGNUM)
+		return;
+	cache[reg] = value;
+}
+
+/*
+ * write to the AK4535 register space
+ */
+static int ak4535_write(struct snd_soc_codec * codec, unsigned int reg, 
+	unsigned int value)
+{
+	u8 data[2];
+	
+	/* data is 
+	 *   D15..D8 AK4535 register offset
+	 *   D7...D0 register data
+	 */
+	data[0] = reg & 0xff;
+	data[1] = value & 0xff;
+
+	ak4535_write_reg_cache (codec, reg, value);
+	if (codec->hw_write(codec->control_data, data, 2) == 2)
+		return 0;
+	else
+		return -1;
+}
+
+static const char* ak4535_mono_gain[] = {"+6dB", "-17dB"};
+static const char* ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"};
+static const char* ak4535_hp_out[] = {"Stereo", "Mono"};
+static const char* ak4535_deemp[] = {"44.1kHz", "Off", "48kHz", "32kHz"};
+static const char* ak4535_mic_select[] = {"Internal", "External"};
+
+static const struct soc_enum ak4535_enum[] = {
+	SOC_ENUM_SINGLE(AK4535_SIG1, 7, 2, ak4535_mono_gain),
+	SOC_ENUM_SINGLE(AK4535_SIG1, 6, 2, ak4535_mono_out),
+	SOC_ENUM_SINGLE(AK4535_MODE2, 2, 2, ak4535_hp_out),
+	SOC_ENUM_SINGLE(AK4535_DAC, 0, 4, ak4535_deemp),
+	SOC_ENUM_SINGLE(AK4535_MIC, 1, 2, ak4535_mic_select),
+};
+
+static const snd_kcontrol_new_t ak4535_snd_controls[] = {
+	SOC_SINGLE("ALC2 Switch", AK4535_SIG1, 1, 1, 0),
+	SOC_ENUM("Mono 1 Output", ak4535_enum[1]),
+	SOC_ENUM("Mono 1 Gain", ak4535_enum[0]),
+	SOC_ENUM("Headphone Output", ak4535_enum[2]),
+	SOC_ENUM("Playback Deemphasis", ak4535_enum[3]),
+	SOC_SINGLE("Bass Volume", AK4535_DAC, 2, 3, 0),
+	SOC_SINGLE("Mic Boost (+20dB) Switch", AK4535_MIC, 0, 1, 0),
+	SOC_ENUM("Mic Select", ak4535_enum[4]),
+	SOC_SINGLE("ALC Operation Time", AK4535_TIMER, 0, 3, 0),
+	SOC_SINGLE("ALC Recovery Time", AK4535_TIMER, 2, 3, 0),
+	SOC_SINGLE("ALC ZC Time", AK4535_TIMER, 4, 3, 0),
+	SOC_SINGLE("ALC 1 Switch", AK4535_ALC1, 5, 1, 0),
+	SOC_SINGLE("ALC 2 Switch", AK4535_ALC1, 6, 1, 0),
+	SOC_SINGLE("ALC Volume", AK4535_ALC2, 0, 127, 0),
+	SOC_SINGLE("Capture Volume", AK4535_PGA, 0, 127, 0),
+	SOC_SINGLE("Left Playback Volume", AK4535_LATT, 0, 127, 1),
+	SOC_SINGLE("Right Playback Volume", AK4535_RATT, 0, 127, 1),
+	SOC_SINGLE("AUX Bypass Volume", AK4535_VOL, 0, 15, 0),
+	SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0),
+};
+
+/* add non dapm controls */
+static int ak4535_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(ak4535_snd_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+			snd_soc_cnew(&ak4535_snd_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	
+	return 0;
+}
+
+/* Mono 1 Mixer */
+static const snd_kcontrol_new_t ak4535_mono1_mixer_controls[] = {
+	SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0),
+	SOC_DAPM_SINGLE("Mono Playback Switch", AK4535_SIG1, 5, 1, 0),
+};
+
+/* Stereo Mixer */
+static const snd_kcontrol_new_t ak4535_stereo_mixer_controls[] = {
+	SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG2, 4, 1, 0),
+	SOC_DAPM_SINGLE("Playback Switch", AK4535_SIG2, 7, 1, 0),
+	SOC_DAPM_SINGLE("Aux Bypass Switch", AK4535_SIG2, 5, 1, 0),
+};
+
+/* Input Mixer */
+static const snd_kcontrol_new_t ak4535_input_mixer_controls[] = {
+	SOC_DAPM_SINGLE("Mic Capture Switch", AK4535_MIC, 2, 1, 0),
+	SOC_DAPM_SINGLE("Aux Capture Switch", AK4535_MIC, 5, 1, 0),
+};
+
+/* Input mux */
+static const snd_kcontrol_new_t ak4535_input_mux_control = 
+	SOC_DAPM_ENUM("Input Select", ak4535_enum[0]);
+
+/* HP L switch */
+static const snd_kcontrol_new_t ak4535_hpl_control = 
+	SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 1, 1, 1);
+
+/* HP R switch */
+static const snd_kcontrol_new_t ak4535_hpr_control = 
+	SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 0, 1, 1);
+
+/* Speaker switch */
+static const snd_kcontrol_new_t ak4535_spk_control = 
+	SOC_DAPM_SINGLE("Switch", AK4535_MODE2, 0, 0, 0);
+	
+/* mono 2 switch */
+static const snd_kcontrol_new_t ak4535_mono2_control = 
+	SOC_DAPM_SINGLE("Switch", AK4535_SIG1, 0, 1, 0);
+
+/* Line out switch */
+static const snd_kcontrol_new_t ak4535_line_control = 
+	SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 6, 1, 0);
+
+/* ak4535 dapm widgets */
+static const struct snd_soc_dapm_widget ak4535_dapm_widgets[] = {	
+	SND_SOC_DAPM_CLOCK("AK4535 Clock", AK4535_PM1, 7, 1),
+	SND_SOC_DAPM_MUTE("DAC Mute", AK4535_DAC, 5, 1),
+	SND_SOC_DAPM_MIXER("Stereo Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+		&ak4535_stereo_mixer_controls[0], ARRAY_SIZE(ak4535_stereo_mixer_controls)),
+	SND_SOC_DAPM_MIXER("Mono1 Mixer", SND_SOC_DAPM_NOPM, 0, 0,
+		&ak4535_mono1_mixer_controls[0], ARRAY_SIZE(ak4535_mono1_mixer_controls)),
+	SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+		&ak4535_input_mixer_controls[0], ARRAY_SIZE(ak4535_mono1_mixer_controls)),
+	SND_SOC_DAPM_MUX("Input Mux", SND_SOC_DAPM_NOPM, 0, 0, &ak4535_input_mux_control),
+	SND_SOC_DAPM_DAC("DAC", "Playback", AK4535_PM2, 0, 0, NULL, 0),
+	SND_SOC_DAPM_SWITCH("Mono 2 Enable", SND_SOC_DAPM_NOPM, 0, 0, &ak4535_mono2_control),
+	SND_SOC_DAPM_SWITCH("Speaker Enable", SND_SOC_DAPM_NOPM, 0, 0, &ak4535_spk_control),
+	SND_SOC_DAPM_SWITCH("Line Out Enable", SND_SOC_DAPM_NOPM, 0, 0, &ak4535_line_control),
+	SND_SOC_DAPM_SWITCH("Left HP Enable", SND_SOC_DAPM_NOPM, 0, 0, &ak4535_hpl_control),
+	SND_SOC_DAPM_SWITCH("Right HP Enable", SND_SOC_DAPM_NOPM, 0, 0, &ak4535_hpr_control),
+	SND_SOC_DAPM_OUTPUT("LOUT"),
+	SND_SOC_DAPM_OUTPUT("HPL"),
+	SND_SOC_DAPM_OUTPUT("ROUT"),
+	SND_SOC_DAPM_OUTPUT("HPR"),
+	SND_SOC_DAPM_OUTPUT("SPP"),
+	SND_SOC_DAPM_OUTPUT("SPN"),
+	SND_SOC_DAPM_OUTPUT("MOUT1"),
+	SND_SOC_DAPM_OUTPUT("MOUT2"),
+	SND_SOC_DAPM_OUTPUT("MICOUT"),
+	SND_SOC_DAPM_ADC("ADC", "Capture", AK4535_PM1, 0, 1, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Spk Amp", AK4535_PM2, 3, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("HP R Amp", AK4535_PM2, 1, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("HP L Amp", AK4535_PM2, 2, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Mic", AK4535_PM1, 1, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Line Out", AK4535_PM1, 4, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Mono Out", AK4535_PM1, 3, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("AUX In", AK4535_PM1, 2, 0, NULL, 0),
+
+	SND_SOC_DAPM_MICBIAS("Mic Int Bias", AK4535_MIC, 3, 0),
+	SND_SOC_DAPM_MICBIAS("Mic Ext Bias", AK4535_MIC, 4, 0),
+	SND_SOC_DAPM_INPUT("MICIN"),
+	SND_SOC_DAPM_INPUT("MICEXT"),
+	SND_SOC_DAPM_INPUT("AUX"),
+	SND_SOC_DAPM_INPUT("MIN"),
+	SND_SOC_DAPM_INPUT("AIN"),
+};
+
+static const char* intercon[][3] = {
+	/*stereo mixer */
+	{"Stereo Mixer", "Playback Switch", "DAC"},
+	{"Stereo Mixer", "Mic Sidetone Switch", "Mic"},
+	{"Stereo Mixer", "Aux Bypass Switch", "AUX In"},
+	
+	/* mono1 mixer */
+	{"Mono1 Mixer", "Mic Sidetone Switch", "Mic"},
+	{"Mono1 Mixer", "Mono Playback Switch", "DAC"},
+	
+	/* mono2 mixer */
+	{"Mono2 Mixer", "Mono Playback Switch", "Stereo Mixer"},
+	
+	/* Mic */
+	{"AIN", NULL, "Mic"},
+	{"Input Mux", "Internal", "Mic Int Bias"},
+	{"Input Mux", "External", "Mic Ext Bias"},
+	{"Mic Int Bias", NULL, "MICIN"},
+	{"Mic Ext Bias", NULL, "MICEXT"},
+	{"MICOUT", NULL, "Input Mux"},
+	
+	/* line out */
+	{"LOUT", "Switch", "Line"},
+	{"ROUT", "Switch", "Line Out Enable"},
+	{"Line Out Enable", NULL, "Line Out"}, 
+	{"Line Out", NULL, "Stereo Mixer"},
+	
+	/* mono1 out */
+	{"MOUT1", NULL, "Mono Out"},
+	{"Mono Out", NULL, "Mono Mixer"},
+	
+	/* left HP */
+	{"HPL", "Switch", "Left HP Enable"},
+	{"Left HP Enable", NULL, "HP L Amp"},
+	{"HP L Amp", NULL, "Stereo Mixer"},
+	
+	/* right HP */
+	{"HPR", "Switch", "Right HP Enable"},
+	{"Right HP Enable", NULL, "HP R Amp"},
+	{"HP R Amp", NULL, "Stereo Mixer"},
+	
+	/* speaker */
+	{"SPP", "Switch", "Speaker Enable"},
+	{"SPN", "Switch", "Speaker Enable"},
+	{"Speaker Enable", NULL, "Spk Amp"},
+	{"Spk Amp", NULL, "MIN"},
+	
+	/* mono 2 */
+	{"MOUT2", "Switch", "Mono 2 Enable"},
+	{"Mono 2 Enable", NULL, "Stereo Mixer"},
+	
+	/* Aux In */
+	{"Aux In", NULL, "AUX"},
+	
+	/* ADC */
+	{"ADC", NULL, "Input Mixer"},
+	{"Input Mixer", "Mic Capture Switch", "Mic"},
+	{"Input Mixer", "Aux Capture Switch", "Aux In"},
+	
+	/* terminator */
+	{NULL, NULL, NULL},
+};
+
+static int ak4535_add_widgets(struct snd_soc_codec *codec)
+{
+	int i;
+	
+	for(i = 0; i < ARRAY_SIZE(ak4535_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &ak4535_dapm_widgets[i]);
+	}
+	
+	/* set up audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_new_widgets(codec);
+	return 0;
+}
+
+static int ak4535_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u8 mode = 0, mode2;
+	int bfs, fs;
+	
+	mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2);
+	bfs = SND_SOC_FSB_INT(rtd->pcm_c->hw_runtime.hwbfs);
+	fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+	snd_assert(bfs, return -ENODEV);
+	snd_assert(fs, return -ENODEV);
+	
+	/* interface format */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+	case SND_SOC_HWFMT_I2S:
+		mode = 0x0002;
+		break;
+	case SND_SOC_HWFMT_LEFT_J:
+		mode = 0x0001;
+		break;
+	}
+
+	/* set fs */
+	switch(fs) {
+	case 1024:
+		mode2 |= (0x3 << 5);
+		break;
+	case 512:
+		mode2 |= (0x2 << 5);
+		break;
+	case 256:
+		mode2 |= (0x1 << 5);
+		break;
+	}
+	
+	/* bfs */
+	if (bfs == 64)
+		mode |= 0x4;
+	
+	/* set rate */
+	ak4535_write(codec, AK4535_MODE1, mode);
+	ak4535_write(codec, AK4535_MODE2, mode2);
+
+	return 0;
+}
+
+static unsigned int ak4535_config_sysclk(struct snd_soc_pcm_codec *pcm_codec, 
+	int rate, unsigned int clk)
+{
+	unsigned int low, high;
+	
+	/* min codec fs is 256, max is 1024 */
+	low = rate << 8;
+	high = rate << 10;
+	
+	if(low >= 1792000 && high <= 12288000) {
+		pcm_codec->mclk = clk;
+		return clk;
+	}
+	
+	return 0;
+}
+
+static int ak4535_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			/* vref/mid, clk and osc on, dac unmute, active */
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* everything off except vref/vmid, dac mute, inactive */
+			ak4535_write(codec, AK4535_PM1, 0x80);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			/* everything off, inactive */
+			ak4535_write(codec, AK4535_PM1, 0x0);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static struct snd_soc_pcm_codec ak4535_pcm_client = {
+	.name = "AK4535",
+	.playback = {
+		.sname = "Playback",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.nplayback = 1,
+	.capture = {
+		.sname = "Capture",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.ncapture = 1,
+	.config_sysclk = ak4535_config_sysclk,
+	.ops = {
+		.prepare = ak4535_pcm_prepare,
+	},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(ak4535_hwfmt),
+		.hmodes = &ak4535_hwfmt[0],
+	},
+};
+
+static int ak4535_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	ak4535_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int ak4535_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+	u8 data[2];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (i = 0; i < ARRAY_SIZE(ak4535_reg); i++) {
+		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
+		data[1] = cache[i] & 0x00ff;
+		codec->hw_write(codec->control_data, data, 2);
+	}
+	ak4535_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	ak4535_dapm_event(codec, codec->suspend_dapm_state);
+	return 0;
+}
+
+/*
+ * initialise the AK4535 driver
+ * register the mixer and dsp interfaces with the kernel 
+ */
+static int ak4535_init(struct snd_soc_device* socdev)
+{
+	struct snd_soc_codec* codec = socdev->codec;
+	int ret = 0;
+
+	codec->name = "AK4535";
+	codec->owner = THIS_MODULE;
+	codec->read = ak4535_read_reg_cache;
+	codec->write = ak4535_write;
+	codec->dapm_event = ak4535_dapm_event;
+	codec->pcms = &ak4535_pcm_client;
+	codec->npcms = 1;
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(ak4535_reg), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	memcpy(codec->reg_cache, ak4535_reg, sizeof(u16) * ARRAY_SIZE(ak4535_reg));
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0) {
+		kfree(codec->reg_cache);
+		return ret;
+	}
+	
+	/* power on device */
+	ak4535_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	
+	ak4535_add_controls(codec);
+	ak4535_add_widgets(codec);
+	snd_soc_register_card(socdev);
+	
+	return 0;
+}
+
+static struct snd_soc_device *ak4535_socdev;
+
+#ifdef CONFIG_I2C
+
+#define I2C_DRIVERID_AK4535 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver ak4535_i2c_driver;
+static struct i2c_client client_template;
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+
+static int ak4535_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+	struct snd_soc_device *socdev = ak4535_socdev;
+	struct ak4535_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec = socdev->codec;
+	struct i2c_client *i2c;
+	int ret;
+
+	if (addr != setup->i2c_address)
+		return -ENODEV;
+
+	client_template.adapter = adap;
+	client_template.addr = addr;
+
+	if ((i2c = kzalloc(sizeof(struct i2c_client), GFP_KERNEL)) == NULL){
+		kfree(codec);
+		return -ENOMEM;
+	}
+	memcpy(i2c, &client_template, sizeof(struct i2c_client));
+
+	i2c_set_clientdata(i2c, codec);
+
+	codec->control_data = i2c;
+
+	if((ret = i2c_attach_client(i2c)) < 0) {
+		printk(KERN_ERR "failed to attach codec at addr %x\n", addr);
+		kfree(i2c);
+		return ret;
+	}
+
+	ak4535_init(socdev);
+
+	return 0;
+}
+
+static int ak4535_i2c_detach(struct i2c_client *client)
+{
+	struct snd_soc_codec* codec = i2c_get_clientdata(client);
+
+	i2c_detach_client(client);
+
+	kfree(codec->reg_cache);
+	kfree(client);
+
+	return 0;
+}
+
+static int ak4535_i2c_attach(struct i2c_adapter *adap)
+{
+	return i2c_probe(adap, &addr_data, ak4535_codec_probe);
+}
+
+/* corgi i2c codec control layer */
+static struct i2c_driver ak4535_i2c_driver = {
+	.driver = {
+		.name = "AK4535 I2C Codec",
+		.owner = THIS_MODULE,
+	},
+	.id =             I2C_DRIVERID_AK4535,
+	.attach_adapter = ak4535_i2c_attach,
+	.detach_client =  ak4535_i2c_detach,
+	.command =        NULL,
+};
+
+static struct i2c_client client_template = {
+	.name =   "AK4535",
+	.driver = &ak4535_i2c_driver,
+};
+#endif
+
+static int ak4535_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct ak4535_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION);
+
+	if ((codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+
+	socdev->codec = codec;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+
+	ak4535_socdev = socdev;
+#ifdef CONFIG_I2C
+	if (setup->i2c_address) {
+		normal_i2c[0] = setup->i2c_address;
+		codec->hw_write = (hw_write_t)i2c_master_send;
+		if ((ret = i2c_add_driver(&ak4535_i2c_driver)) != 0)
+			printk(KERN_ERR "can't add i2c driver");
+	} 
+#else		
+	/* Add other interfaces here */
+#endif
+	return ret;
+}
+
+/* power down chip */
+static int ak4535_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	if (codec->control_data)
+		ak4535_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+
+	snd_soc_free_pcms(socdev);
+	snd_soc_dapm_free(socdev);
+#ifdef CONFIG_I2C
+	i2c_del_driver(&ak4535_i2c_driver);
+#endif
+	kfree(codec);
+
+	return 0;
+}
+
+
+struct snd_soc_codec_device soc_codec_dev_ak4535 = {
+	.probe = 	ak4535_probe,
+	.remove = 	ak4535_remove,
+	.suspend = 	ak4535_suspend,
+	.resume =	ak4535_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_ak4535);
+
+MODULE_DESCRIPTION("Soc AK4535 driver");
+MODULE_AUTHOR("Richard Purdie");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ak4535.h b/sound/soc/codecs/ak4535.h
new file mode 100644
index 0000000..f638e78
--- /dev/null
+++ b/sound/soc/codecs/ak4535.h
@@ -0,0 +1,45 @@
+/*
+ * ak4535.h  --  AK4535 Soc Audio driver
+ *
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Author: Richard Purdie <richard@openedhand.com>
+ *
+ * Based on wm8753.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _AK4535_H
+#define _AK4535_H
+
+/* AK4535 register space */
+
+#define AK4535_PM1		0x0
+#define AK4535_PM2		0x1
+#define AK4535_SIG1		0x2
+#define AK4535_SIG2		0x3
+#define AK4535_MODE1	0x4
+#define AK4535_MODE2	0x5
+#define AK4535_DAC		0x6
+#define AK4535_MIC		0x7
+#define AK4535_TIMER	0x8
+#define AK4535_ALC1		0x9
+#define AK4535_ALC2		0xa
+#define AK4535_PGA		0xb
+#define AK4535_LATT		0xc
+#define AK4535_RATT		0xd
+#define AK4535_VOL		0xe
+#define AK4535_STATUS	0xf
+
+#define AK4535_CACHEREGNUM 	0x10
+
+struct ak4535_setup_data {
+	unsigned short i2c_address;
+};
+
+extern struct snd_soc_codec_device soc_codec_dev_ak4535;
+
+#endif
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
new file mode 100644
index 0000000..675b790
--- /dev/null
+++ b/sound/soc/codecs/uda1380.c
@@ -0,0 +1,546 @@
+/*
+ * uda1380.c - Philips UDA1380 ALSA SoC audio driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Modified by Richard Purdie <richard@openedhand.com> to fit into SoC
+ * codec model.
+ * 
+ * Copyright (c) 2005 Giorgio Padrin <giorgio@mandarinlogiq.org>
+ * Copyright 2005 Openedhand Ltd.
+ */
+
+#include <sound/driver.h>
+ 
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/ioctl.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/initval.h>
+#include <sound/info.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include "uda1380.h"
+
+#define UDA1380_VERSION "0.2"
+
+/*
+ * uda1380 register cache
+ */
+static const u16 uda1380_reg[UDA1380_CACHEREGNUM] = {
+    0x0502, 0x0000, 0x0000, 0x3f3f, 
+    0x0202, 0x0000, 0x0000, 0x0000,
+    0x0000, 0x0000, 0x0000, 0x0000,
+    0x0000, 0x0000, 0x0000, 0x0000,
+    0x0000, 0xff00, 0x0000, 0x4800,
+    0x0000, 0x0000, 0x0000, 0x0000,
+    0x0000, 0x0000, 0x0000, 0x0000,
+    0x0000, 0x0000, 0x0000, 0x0000,
+    0x0000, 0x8000, 0x0002, 0x0000,
+};
+
+#define UDA1380_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_CBS_CFS | \
+	 SND_SOC_HWFMT_NB_NF)
+	 
+#define UDA1380_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+	
+#define UDA1380_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000)	
+
+static struct snd_soc_hw_mode uda1380_hwfmt[] = {
+	/* slave rates capture & playback */
+	{UDA1380_HWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		UDA1380_RATES, UDA1380_DIR, 0, SND_SOC_FS(256), 
+		SND_SOC_FSB(64)},
+		
+	/* slave rates playback */
+	{UDA1380_HWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000, SND_SOC_HWDIR_PLAYBACK,
+		0, SND_SOC_FS(256),  SND_SOC_FSB(64)},
+};
+
+
+/*
+ * read uda1380 register cache
+ */
+static inline unsigned int uda1380_read_reg_cache(struct snd_soc_codec * codec,
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg == UDA1380_RESET) 
+		return 0;
+	if (reg >= UDA1380_CACHEREGNUM)
+		return -1;
+	return cache[reg];
+}
+
+/*
+ * write uda1380 register cache
+ */
+static inline void uda1380_write_reg_cache(struct snd_soc_codec * codec,
+	u16 reg, unsigned int value)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg >= UDA1380_CACHEREGNUM)
+		return;
+	cache[reg] = value;
+}
+
+/*
+ * write to the UDA1380 register space
+ */
+static int uda1380_write(struct snd_soc_codec * codec, unsigned int reg, 
+	unsigned int value)
+{
+	u8 data[3];
+	
+	/* data is 
+	 *   data[0] is register offset
+	 *   data[1] is MS byte
+	 *   data[2] is LS byte
+	 */
+	data[0] = reg;
+	data[1] = (value & 0xff00) >> 8;
+	data[2] = value & 0x00ff;
+
+	uda1380_write_reg_cache (codec, reg, value);
+	if (codec->hw_write(codec->control_data, data, 3) == 3)
+		return 0;
+	else
+		return -1;
+}
+
+#define uda1380_reset(c)	uda1380_write(c, UDA1380_RESET, 0)
+
+/* declarations of ALSA reg_elem_int controls */
+static const char* uda1380_deemp[] = {"None", "32kHz", "44.1kHz", "48kHz", "96kHz"};
+static const char* uda1380_input_sel[] = {"Line", "Mic"};
+
+static const struct soc_enum uda1380_enum[] = {
+	SOC_ENUM_DOUBLE(UDA1380_DEEMP, 0, 8, 5, uda1380_deemp),
+	SOC_ENUM_SINGLE(UDA1380_ADC, 3, 2, uda1380_input_sel),
+};
+
+static const snd_kcontrol_new_t uda1380_snd_controls[] = {
+	SOC_DOUBLE("Playback Volume", UDA1380_MVOL, 0, 8, 127, 0),
+	SOC_DOUBLE("Treble Volume", UDA1380_MODE, 4, 12, 3, 0),
+	SOC_DOUBLE("Bass Volume", UDA1380_MODE, 0, 8, 15, 0),
+	SOC_ENUM("Playback De-emphasis", uda1380_enum[0]),
+	SOC_DOUBLE("Capture Volume", UDA1380_DEC, 0, 8, 127, 0),
+	SOC_DOUBLE("Line Capture Volume", UDA1380_PGA, 0, 8, 15, 0),
+	SOC_SINGLE("Mic Capture Volume", UDA1380_PGA, 8, 11, 0),
+	SOC_DOUBLE("Playback Switch", UDA1380_DEEMP, 3, 11, 1, 0),
+	SOC_SINGLE("Capture Switch", UDA1380_PGA, 15, 1, 0),
+	SOC_SINGLE("AGC Timing", UDA1380_AGC, 8, 7, 0),
+	SOC_SINGLE("AGC Target level", UDA1380_AGC, 2, 3, 1),
+	SOC_SINGLE("AGC Switch", UDA1380_AGC, 0, 1, 0),
+};
+
+/* add non dapm controls */
+static int uda1380_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(uda1380_snd_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+			snd_soc_cnew(&uda1380_snd_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	
+	return 0;
+}
+
+/* Input mux */
+static const snd_kcontrol_new_t uda1380_input_mux_control =
+	SOC_DAPM_ENUM("Input Select", uda1380_enum[1]);
+
+static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
+	SND_SOC_DAPM_MUTE("DAC Mute", UDA1380_DEEMP, 14, 0),
+	SND_SOC_DAPM_MUX("Input Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+		&uda1380_input_mux_control),
+	SND_SOC_DAPM_VOLUME("Left PGA", UDA1380_PM, 3, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Right PGA", UDA1380_PM, 1, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Mic LNA", UDA1380_PM, 4, 0, NULL, 0),
+	SND_SOC_DAPM_ADC("Left ADC", "Left Capture", UDA1380_PM, 2, 0, NULL, 0),
+	SND_SOC_DAPM_ADC("Right ADC", "Right Capture", UDA1380_PM, 0, 0, NULL, 0),
+	SND_SOC_DAPM_INPUT("VINM"),
+	SND_SOC_DAPM_INPUT("VINL"),
+	SND_SOC_DAPM_INPUT("VINR"),
+	SND_SOC_DAPM_MIXER("Analog Mixer", UDA1380_PM, 6, 0, NULL, 0),
+	SND_SOC_DAPM_OUTPUT("VOUTLHP"),
+	SND_SOC_DAPM_OUTPUT("VOUTRHP"),
+	SND_SOC_DAPM_OUTPUT("VOUTL"),
+	SND_SOC_DAPM_OUTPUT("VOUTR"),
+	SND_SOC_DAPM_DAC("DAC", "Playback", UDA1380_PM, 10, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("HeadPhone Driver", UDA1380_PM, 13, 0, NULL, 0),
+};
+
+static const char* intercon[][3] = {
+	
+	/* analog mixer setup is different from diagram for dapm */
+	{"HeadPhone Driver", NULL, "Analog Mixer"},
+	{"VOUTR", NULL, "Analog Mixer"},
+	{"VOUTL", NULL, "Analog Mixer"},
+	{"Analog Mixer", NULL, "VINR"},
+	{"Analog Mixer", NULL, "VINL"},
+	{"Analog Mixer", NULL, "DAC"},
+		
+	/* headphone driver */
+	{"VOUTLHP", NULL, "HeadPhone Driver"},
+	{"VOUTRHP", NULL, "HeadPhone Driver"},
+	
+	/* input mux */
+	{"Left ADC", NULL, "Input Mux"},
+	{"Input Mux", "Mic", "Mic LNA"},
+	{"Input Mux", "Line", "Left PGA"},
+	
+	/* right input */
+	{"Right ADC", NULL, "Right PGA"},
+
+	/* inputs */
+	{"Mic LNA", NULL, "VINM"},
+	{"Left PGA", NULL, "VINL"},
+	{"Right PGA", NULL, "VINR"},
+};
+
+static int uda1380_add_widgets(struct snd_soc_codec *codec)
+{
+	int i;
+	
+	for(i = 0; i < ARRAY_SIZE(uda1380_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &uda1380_dapm_widgets[i]);
+	}
+	
+	/* set up audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_new_widgets(codec);
+	return 0;
+}
+
+static int uda1380_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)		
+		uda1380_write(codec, UDA1380_CLK, R00_EN_DAC | R00_EN_INT | clk);
+	else
+		uda1380_write(codec, UDA1380_CLK, R00_EN_ADC | R00_EN_DEC | clk);
+
+	return 0;
+}
+
+static void uda1380_pcm_shutdown(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)		
+		uda1380_write(codec, UDA1380_CLK, ~(R00_EN_DAC | R00_EN_INT) & clk);
+	else
+		uda1380_write(codec, UDA1380_CLK, ~(R00_EN_ADC | R00_EN_DEC) & clk);
+}
+
+static unsigned int uda1380_config_sysclk(struct snd_soc_pcm_codec *pcm_codec, 
+	int rate, unsigned int clk)
+{
+	unsigned int low, high;
+	
+	/* min codec fs is 256, max is 768 */
+	low = rate << 8;
+	high = rate * 768;
+	
+	/* todo - need to quantify sysclk limits */
+	if(low >= 1792000 && high <= 12288000) {
+		pcm_codec->mclk = clk;
+		return clk;
+	}
+	
+	return 0;
+}
+
+static int uda1380_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			break;
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* everything off except internal bias */
+			uda1380_write(codec, UDA1380_PM, R02_PON_BIAS);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			/* everything off, inactive */
+			uda1380_write(codec, UDA1380_PM, 0x0);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static struct snd_soc_pcm_codec uda1380_pcm_client = {
+	.name = "UDA1380",
+	.playback = {
+		.sname = "Playback",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.nplayback = 1,
+	.capture = {
+		.sname = "Capture",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.ncapture = 1,
+	.config_sysclk = uda1380_config_sysclk,
+	.ops = {
+		.prepare = uda1380_pcm_prepare,
+		.shutdown = uda1380_pcm_shutdown,
+	},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(uda1380_hwfmt),
+		.hmodes = &uda1380_hwfmt[0],
+	},
+};
+
+static int uda1380_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	uda1380_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int uda1380_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+	u8 data[2];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (i = 0; i < ARRAY_SIZE(uda1380_reg); i++) {
+		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
+		data[1] = cache[i] & 0x00ff;
+		codec->hw_write(codec->control_data, data, 2);
+	}
+	uda1380_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	uda1380_dapm_event(codec, codec->suspend_dapm_state);
+	return 0;
+}
+
+/*
+ * initialise the UDA1380 driver
+ * register the mixer and dsp interfaces with the kernel 
+ */
+static int uda1380_init(struct snd_soc_device* socdev)
+{
+	struct snd_soc_codec* codec = socdev->codec;
+	int ret = 0;
+
+	codec->name = "UDA1380";
+	codec->owner = THIS_MODULE;
+	codec->read = uda1380_read_reg_cache;
+	codec->write = uda1380_write;
+	codec->dapm_event = uda1380_dapm_event;
+	codec->pcms = &uda1380_pcm_client;
+	codec->npcms = 1;
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(uda1380_reg), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	memcpy(codec->reg_cache, uda1380_reg, sizeof(u16) * ARRAY_SIZE(uda1380_reg));
+	
+	uda1380_reset(codec);
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0) {
+		kfree(codec->reg_cache);
+		return ret;
+	}
+	
+	/* power on device */
+	uda1380_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	uda1380_write(codec, UDA1380_CLK, 0);
+	
+	/* uda1380 init */
+	uda1380_add_controls(codec);
+	uda1380_add_widgets(codec);
+	snd_soc_register_card(socdev);
+	
+	return 0;
+}
+
+static struct snd_soc_device *uda1380_socdev;
+
+#ifdef CONFIG_I2C
+
+#define I2C_DRIVERID_UDA1380 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver uda1380_i2c_driver;
+static struct i2c_client client_template;
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+
+static int uda1380_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+	struct snd_soc_device *socdev = uda1380_socdev;
+	struct uda1380_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec = socdev->codec;
+	struct i2c_client *i2c;
+	int ret;
+
+	if (addr != setup->i2c_address)
+		return -ENODEV;
+
+	client_template.adapter = adap;
+	client_template.addr = addr;
+
+	if ((i2c = kzalloc(sizeof(struct i2c_client), GFP_KERNEL)) == NULL){
+		kfree(codec);
+		return -ENOMEM;
+	}
+	memcpy(i2c, &client_template, sizeof(struct i2c_client));
+
+	i2c_set_clientdata(i2c, codec);
+
+	codec->control_data = i2c;
+
+	if((ret = i2c_attach_client(i2c)) < 0) {
+		printk(KERN_ERR "failed to attach codec at addr %x\n", addr);
+		kfree(i2c);
+		return ret;
+	}
+
+	uda1380_init(socdev);
+	return 0;
+}
+
+static int uda1380_i2c_detach(struct i2c_client *client)
+{
+	struct snd_soc_codec* codec = i2c_get_clientdata(client);
+
+	i2c_detach_client(client);
+	kfree(codec->reg_cache);
+	kfree(client);
+
+	return 0;
+}
+
+static int uda1380_i2c_attach(struct i2c_adapter *adap)
+{
+	return i2c_probe(adap, &addr_data, uda1380_codec_probe);
+}
+
+/* corgi i2c codec control layer */
+static struct i2c_driver uda1380_i2c_driver = {
+	.driver = {
+		.name =  "UDA1380 I2C Codec",
+		.owner = THIS_MODULE,
+	},
+	.id =             I2C_DRIVERID_UDA1380,
+	.attach_adapter = uda1380_i2c_attach,
+	.detach_client =  uda1380_i2c_detach,
+	.command =        NULL,
+};
+
+static struct i2c_client client_template = {
+	.name =   "UDA1380",
+	.driver = &uda1380_i2c_driver,
+};
+#endif
+
+static int uda1380_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct uda1380_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	printk(KERN_INFO "UDA1380 Audio Codec %s", UDA1380_VERSION);
+
+	if ((codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+
+	socdev->codec = codec;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+
+	uda1380_socdev = socdev;
+#ifdef CONFIG_I2C
+	if (setup->i2c_address) {
+		normal_i2c[0] = setup->i2c_address;
+		codec->hw_write = (hw_write_t)i2c_master_send;
+		if ((ret = i2c_add_driver(&uda1380_i2c_driver)) != 0)
+			printk(KERN_ERR "can't add i2c driver");
+	} 
+#else		
+	/* Add other interfaces here */
+#endif
+	return ret;
+}
+
+/* power down chip */
+static int uda1380_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	if (codec->control_data)
+		uda1380_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+
+	snd_soc_free_pcms(socdev);
+	snd_soc_dapm_free(socdev);
+#ifdef CONFIG_I2C
+	i2c_del_driver(&uda1380_i2c_driver);
+#endif
+	kfree(codec);
+
+	return 0;
+}
+
+
+struct snd_soc_codec_device soc_codec_dev_uda1380 = {
+	.probe = 	uda1380_probe,
+	.remove = 	uda1380_remove,
+	.suspend = 	uda1380_suspend,
+	.resume =	uda1380_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_uda1380);
+
+MODULE_AUTHOR("Giorgio Padrin");
+MODULE_DESCRIPTION("Audio support for codec Philips UDA1380");
+MODULE_LICENSE("GPL");
+
diff --git a/sound/soc/codecs/uda1380.h b/sound/soc/codecs/uda1380.h
new file mode 100644
index 0000000..fa24d51
--- /dev/null
+++ b/sound/soc/codecs/uda1380.h
@@ -0,0 +1,55 @@
+/*
+ * Audio support for Philips UDA1380
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Copyright (c) 2005 Giorgio Padrin <giorgio@mandarinlogiq.org>
+ */
+
+#define UDA1380_CLK		0x00
+#define UDA1380_IFACE	0x01
+#define UDA1380_PM		0x02
+#define UDA1380_AMIX	0x03
+#define UDA1380_HP		0x04
+#define UDA1380_MVOL	0x10
+#define UDA1380_MIXVOL	0x11
+#define UDA1380_MODE	0x12
+#define UDA1380_DEEMP	0x13
+#define UDA1380_MIXER	0x14
+#define UDA1380_INTSTAT	0x18
+#define UDA1380_DEC		0x20
+#define UDA1380_PGA		0x21
+#define UDA1380_ADC		0x22
+#define UDA1380_AGC		0x23
+#define UDA1380_DECSTAT	0x28
+#define UDA1380_RESET	0x7f
+
+#define UDA1380_CACHEREGNUM 0x24
+
+/* Register flags */
+#define R00_EN_ADC	0x0800
+#define R00_EN_DEC	0x0400
+#define R00_EN_DAC	0x0200
+#define R00_EN_INT	0x0100
+#define R02_PON_HP	0x2000
+#define R02_PON_DAC	0x0400
+#define R02_PON_BIAS	0x0100
+#define R02_PON_LNA	0x0010
+#define R02_PON_PGAL	0x0008
+#define R02_PON_ADCL	0x0004
+#define R02_PON_PGAR	0x0002
+#define R02_PON_ADCR	0x0001
+#define R13_MTM		0x4000
+#define R21_MT_ADC	0x8000
+#define R22_SEL_LNA	0x0008
+#define R22_SEL_MIC	0x0004
+#define R22_SKIP_DCFIL	0x0002
+#define R23_AGC_EN	0x0001
+
+struct uda1380_setup_data {
+	unsigned short i2c_address;
+};
+
+extern struct snd_soc_codec_device soc_codec_dev_uda1380;
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
new file mode 100644
index 0000000..78bff4f
--- /dev/null
+++ b/sound/soc/codecs/wm8731.c
@@ -0,0 +1,695 @@
+/*
+ * wm8731.c  --  WM8731 ALSA Soc Audio driver
+ *
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Author: Richard Purdie <richard@openedhand.com>
+ *
+ * Based on wm8753.c by Liam Girdwood
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include "wm8731.h"
+
+#define AUDIO_NAME "wm8731"
+#define WM8731_VERSION "0.7"
+
+/*
+ * Debug
+ */
+ 
+#define PFX AUDIO_NAME
+#define WM8731_DEBUG 0
+
+#ifdef WM8731_DEBUG
+#define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
+#else
+#define dbg(format, arg...) do {} while (0)
+#endif
+#define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
+
+struct snd_soc_codec_device soc_codec_dev_wm8731;	
+	
+/*
+ * wm8731 register cache
+ * We can't read the WM8731 register space when we are
+ * using 2 wire for device control, so we cache them instead. 
+ * There is no point in caching the reset register
+ */
+static const u16 wm8731_reg[WM8731_CACHEREGNUM] = {
+    0x0097, 0x0097, 0x0079, 0x0079, 
+    0x000a, 0x0008, 0x009f, 0x000a, 
+    0x0000, 0x0000
+};
+
+#define WM8731_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | \
+	SND_SOC_HWFMT_IB_IF)
+
+#define WM8731_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+	
+#define WM8731_FSB \
+	(SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4) | \
+	SND_SOC_FSBD(8) | SND_SOC_FSBD(16))
+	
+#define WM8731_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+	
+#define WM8731_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | SNDRV_PCM_FORMAT_S24_3LE)
+
+static struct snd_soc_hw_mode wm8731_hwfmt[] = {
+	/* codec frame and clock master modes */
+	{WM8731_HWFMT | SND_SOC_HWFMT_CBM_CFM, SND_SOC_HWTDM_LRDW(0,0),
+		WM8731_PCM_FORMATS, SNDRV_PCM_RATE_8000, WM8731_DIR, SND_SOC_HW_BFS_DIV,
+		SND_SOC_FS(1536), WM8731_FSB},
+	{WM8731_HWFMT | SND_SOC_HWFMT_CBM_CFM, SND_SOC_HWTDM_LRDW(0,0),
+		WM8731_PCM_FORMATS, SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, WM8731_DIR, 
+		SND_SOC_HW_BFS_DIV, SND_SOC_FS(256), WM8731_FSB},
+	{WM8731_HWFMT | SND_SOC_HWFMT_CBM_CFM, SND_SOC_HWTDM_LRDW(0,0),
+		WM8731_PCM_FORMATS, SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000, WM8731_DIR, 
+		SND_SOC_HW_BFS_DIV, SND_SOC_FS(128), SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4)},
+	
+	/* codec frame and clock slave modes */	
+	{WM8731_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), WM8731_PCM_FORMATS, 
+		WM8731_RATES, WM8731_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS_ALL, SND_SOC_FSBD_ALL},
+};
+
+/*
+ * read wm8731 register cache
+ */
+static inline unsigned int wm8731_read_reg_cache(struct snd_soc_codec * codec,
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg == WM8731_RESET) 
+		return 0;
+	if (reg >= WM8731_CACHEREGNUM)
+		return -1;
+	return cache[reg];
+}
+
+/*
+ * write wm8731 register cache
+ */
+static inline void wm8731_write_reg_cache(struct snd_soc_codec * codec,
+	u16 reg, unsigned int value)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg >= WM8731_CACHEREGNUM)
+		return;
+	cache[reg] = value;
+}
+
+/*
+ * write to the WM8731 register space
+ */
+static int wm8731_write(struct snd_soc_codec * codec, unsigned int reg, 
+	unsigned int value)
+{
+	u8 data[2];
+	
+	/* data is 
+	 *   D15..D9 WM8753 register offset
+	 *   D8...D0 register data
+	 */
+	data[0] = (reg << 1) | ((value >> 8) & 0x0001);
+	data[1] = value & 0x00ff;
+
+	wm8731_write_reg_cache (codec, reg, value);
+	if (codec->hw_write(codec->control_data, data, 2) == 2)
+		return 0;
+	else
+		return -1;
+}
+
+#define wm8731_reset(c)	wm8731_write(c, WM8731_RESET, 0)
+
+static const char* wm8731_input_select[] = {"Line In", "Mic"};
+static const char* wm8731_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
+
+static const struct soc_enum wm8731_enum[] = {
+	SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select),
+	SOC_ENUM_SINGLE(WM8731_APDIGI, 1, 4, wm8731_deemph),
+};
+
+static const snd_kcontrol_new_t wm8731_snd_controls[] = {
+
+SOC_DOUBLE_R("Playback Volume", WM8731_LOUT1V, WM8731_ROUT1V, 0, 127, 0),
+SOC_DOUBLE_R("Playback Switch", WM8731_LOUT1V, WM8731_ROUT1V, 7, 1, 0),
+
+SOC_DOUBLE_R("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0),
+SOC_DOUBLE_R("Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1),
+
+SOC_SINGLE("Mic Boost (+20dB)", WM8731_APANA, 0, 1, 0),
+SOC_SINGLE("Capture Mic Switch", WM8731_APANA, 1, 1, 0),
+
+SOC_SINGLE("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1),
+
+SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1),
+SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0),
+	
+SOC_ENUM("Playback De-emphasis", wm8731_enum[1]),
+};
+
+/* add non dapm controls */
+static int wm8731_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm8731_snd_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	
+	return 0;
+}
+
+
+/* Output Mixer */
+static const snd_kcontrol_new_t wm8731_output_mixer_controls[] = {
+SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
+SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
+SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
+};
+
+/* Input mux */
+static const snd_kcontrol_new_t wm8731_input_mux_controls = 
+SOC_DAPM_ENUM("Input Select", wm8731_enum[0]);
+
+
+static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
+SND_SOC_DAPM_CLOCK("WM8731 Clock", WM8731_PWR, 6, 1),
+SND_SOC_DAPM_CLOCK("WM8731 Osc", WM8731_PWR, 5, 1),
+SND_SOC_DAPM_MUTE("DAC Mute", WM8731_APDIGI, 3, 0),
+SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, &wm8731_output_mixer_controls[0], 
+	ARRAY_SIZE(wm8731_output_mixer_controls)),
+SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8731_PWR, 3, 1, NULL, 0),
+SND_SOC_DAPM_OUTPUT("LOUT"),
+SND_SOC_DAPM_OUTPUT("LHPOUT"),
+SND_SOC_DAPM_OUTPUT("ROUT"),
+SND_SOC_DAPM_OUTPUT("LRHPOUT"),
+SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731_PWR, 2, 1, NULL, 0),
+SND_SOC_DAPM_MUX("Input Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8731_input_mux_controls),
+SND_SOC_DAPM_VOLUME("Line Input", WM8731_PWR, 0, 1, NULL, 0),
+SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR, 1, 1),
+SND_SOC_DAPM_INPUT("MICIN"),
+SND_SOC_DAPM_INPUT("RLINEIN"),
+SND_SOC_DAPM_INPUT("LLINEIN"),
+};
+
+static const char* intercon[][3] = {
+	/* output mixer */
+	{"Output Mixer", "Line Bypass Switch", "Line Input"},
+	{"Output Mixer", "HiFi Playback Switch", "DAC"},
+	{"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
+	
+	/* outputs */
+	{"RHPOUT", NULL, "Output Mixer"},
+	{"ROUT", NULL, "Output Mixer"},
+	{"LHPOUT", NULL, "Output Mixer"},
+	{"LOUT", NULL, "Output Mixer"},
+	
+	/* input mux */
+	{"Input Mux", "Line In", "Line Input"},
+	{"Input Mux", "Mic", "Mic Bias"},
+	
+	/* outputs */
+	{"Line Input", NULL, "LLINEIN"},
+	{"Line Input", NULL, "RLINEIN"},
+	{"Mic Bias", NULL, "MICIN"},
+	
+	/* terminator */
+	{NULL, NULL, NULL},
+};
+
+static int wm8731_add_widgets(struct snd_soc_codec *codec)
+{
+	int i;
+	
+	for(i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
+	}
+	
+	/* set up audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_new_widgets(codec);
+	return 0;
+}
+
+struct _coeff_div {
+	u32 mclk;
+	u16 fs;
+	u16 coeff;
+};
+
+/* codec mclk clock divider coefficients */
+static const struct _coeff_div coeff_div[] = {
+	{12288000, 384, 0x18},
+	{12288000, 256, 0x0},
+	{11289600, 256, 0x20},
+	{12288000, 128, 0x1c},
+	{11289600, 128, 0x3c},
+	{12288000, 1536, 0x0c},
+	{12288000, 768, 0x14},
+	{11289000, 1024, 0x30},
+	{11289000, 512, 0x34},
+};
+
+static int get_coeff(struct snd_soc_pcm_codec* pcm_codec, int fs)
+{
+	int i;
+	
+	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
+		if (coeff_div[i].mclk == pcm_codec->mclk && coeff_div[i].fs == fs)
+			return coeff_div[i].coeff;
+	}
+	return 0;
+}
+
+static unsigned int wm8731_config_sysclk(struct snd_soc_pcm_codec* pcm_codec, 
+	int rate, unsigned int clk)
+{	
+	switch(rate){
+	case 8000:
+	case 16000:
+	case 32000:
+	case 48000:
+	case 96000:
+		if (clk == 12288000 || clk == 18432000)
+			pcm_codec->mclk = clk;
+		break;
+	case 11025:
+	case 22050:
+	case 44100:
+	case 88200:
+		if (clk == 11289600 || clk == 16934400)
+			pcm_codec->mclk = clk;
+		break;
+	default:
+		pcm_codec->mclk = 0;
+	}
+	return pcm_codec->mclk;
+}
+
+static int wm8731_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 iface = 0, bfs, fs, srate;
+	
+	bfs = SND_SOC_FSBD_INT(rtd->pcm_c->hw_runtime.hwbfs);
+	fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+	srate = get_coeff(rtd->pcm_c, fs);
+
+	/* set master/slave audio interface */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK) {
+		case SND_SOC_HWFMT_CBM_CFM:
+			iface |= 0x0040;
+			break;
+		case SND_SOC_HWFMT_CBS_CFS:
+			break;
+	}
+	
+	/* interface format */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+		case SND_SOC_HWFMT_I2S:
+			iface |= 0x0002;
+			break;
+		case SND_SOC_HWFMT_RIGHT_J:
+			break;
+		case SND_SOC_HWFMT_LEFT_J:
+			iface |= 0x0001;
+			break;
+		case SND_SOC_HWFMT_DSP_A:
+			iface |= 0x0003;
+			break;
+		case SND_SOC_HWFMT_DSP_B:
+			iface |= 0x0013;
+			break;
+	}
+	
+	/* bit size */
+	switch(rtd->pcm_c->hw_runtime.hwpcmfmt) {
+		case SNDRV_PCM_FORMAT_S16_LE:
+			break;
+		case SNDRV_PCM_FORMAT_S20_3LE:
+			iface |= 0x0004;
+			break;
+		case SNDRV_PCM_FORMAT_S24_3LE:
+			iface |= 0x0008;
+			break;
+		case SNDRV_PCM_FORMAT_S32_LE:
+			iface |= 0x000c;
+			break;
+	}
+
+	/* clock inversion */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK) {
+		case SND_SOC_HWFMT_NB_NF:
+			break;
+		case SND_SOC_HWFMT_IB_IF:
+			iface |= 0x0090;
+			break;
+		case SND_SOC_HWFMT_IB_NF:
+			iface |= 0x0080;
+			break;
+		case SND_SOC_HWFMT_NB_IF:
+			iface |= 0x0010;
+			break;
+	}
+
+	/* set bclk divisor rate */
+	switch (bfs) {
+		case 1:
+			break;
+		case 4:
+			srate = (0x1 << 7);
+			break;
+		case 8:
+			srate = (0x2 << 7);
+			break;
+		case 16:
+			srate = (0x3 << 7);
+			break;
+	}
+			
+	/* set rate */
+	wm8731_write(codec, WM8731_SRATE, srate);
+	wm8731_write(codec, WM8731_IFACE, iface);
+
+	return 0;
+}
+
+static int wm8731_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			/* vref/mid, clk and osc on, dac unmute, active */
+			wm8731_write(codec, WM8731_ACTIVE, 0x0001);
+			break;
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* everything off except vref/vmid, dac mute, inactive */
+			wm8731_write(codec, WM8731_ACTIVE, 0x0);
+			wm8731_write(codec, WM8731_PWR, 0xff7f);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			/* everything off, dac mute, inactive */
+			wm8731_write(codec, WM8731_ACTIVE, 0x0);
+			wm8731_write(codec, WM8731_PWR, 0xffff);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static struct snd_soc_pcm_codec wm8731_pcm_client = {
+	.name = "WM8731",
+	.playback = {
+		.sname = "Playback",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.nplayback = 1,
+	.capture = {
+		.sname = "Capture",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.ncapture = 1,
+	.config_sysclk = wm8731_config_sysclk,
+	.ops = {
+		.prepare = wm8731_pcm_prepare,
+	},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8731_hwfmt),
+		.hmodes = &wm8731_hwfmt[0],
+	},
+};
+
+static int wm8731_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int wm8731_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+	u8 data[2];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) {
+		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
+		data[1] = cache[i] & 0x00ff;
+		codec->hw_write(codec->control_data, data, 2);
+	}
+	wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	wm8731_dapm_event(codec, codec->suspend_dapm_state);
+	return 0;
+}
+
+/*
+ * initialise the WM8731 driver
+ * register the mixer and dsp interfaces with the kernel 
+ */
+static int wm8731_init(struct snd_soc_device* socdev)
+{
+	struct snd_soc_codec* codec = socdev->codec;
+	int reg, ret = 0;
+
+	codec->name = "WM8731";
+	codec->owner = THIS_MODULE;
+	codec->read = wm8731_read_reg_cache;
+	codec->write = wm8731_write;
+	codec->dapm_event = wm8731_dapm_event;
+	codec->pcms = &wm8731_pcm_client;
+	codec->npcms = 1;
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(wm8731_reg), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	memcpy(codec->reg_cache, wm8731_reg, sizeof(u16) * ARRAY_SIZE(wm8731_reg));
+	
+	wm8731_reset(codec);
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0) {
+		kfree(codec->reg_cache);
+		return ret;
+	}
+	
+	/* power on device */
+	wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	
+	/* set the update bits */
+	reg = wm8731_read_reg_cache(codec, WM8731_LOUT1V);
+	wm8731_write(codec, WM8731_LOUT1V, reg | 0x0100);
+	reg = wm8731_read_reg_cache(codec, WM8731_ROUT1V);
+	wm8731_write(codec, WM8731_ROUT1V, reg | 0x0100);
+	reg = wm8731_read_reg_cache(codec, WM8731_LINVOL);
+	wm8731_write(codec, WM8731_LINVOL, reg | 0x0100);
+	reg = wm8731_read_reg_cache(codec, WM8731_RINVOL);
+	wm8731_write(codec, WM8731_RINVOL, reg | 0x0100);
+
+	wm8731_add_controls(codec);
+	wm8731_add_widgets(codec);
+	snd_soc_register_card(socdev);
+	
+	return 0;
+}
+
+static struct snd_soc_device *wm8731_socdev;
+
+#ifdef CONFIG_I2C
+
+/*
+ * WM8731 2 wire address is determined by GPIO5
+ * state during powerup.
+ *    low  = 0x1a
+ *    high = 0x1b
+ */
+#define I2C_DRIVERID_WM8731 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver wm8731_i2c_driver;
+static struct i2c_client client_template;
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+
+static int wm8731_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+	struct snd_soc_device *socdev = wm8731_socdev;
+	struct wm8731_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec = socdev->codec;
+	struct i2c_client *i2c;
+	int ret;
+
+	if (addr != setup->i2c_address)
+		return -ENODEV;
+
+	client_template.adapter = adap;
+	client_template.addr = addr;
+
+	if ((i2c = kzalloc(sizeof(struct i2c_client), GFP_KERNEL)) == NULL){
+		kfree(codec);
+		return -ENOMEM;
+	}
+	memcpy(i2c, &client_template, sizeof(struct i2c_client));
+
+	i2c_set_clientdata(i2c, codec);
+
+	codec->control_data = i2c;
+
+	if((ret = i2c_attach_client(i2c)) < 0) {
+		err("failed to attach codec at addr %x\n", addr);
+		kfree(i2c);
+		return ret;
+	}
+
+	wm8731_init(socdev);
+
+	return 0;
+}
+
+static int wm8731_i2c_detach(struct i2c_client *client)
+{
+	struct snd_soc_codec* codec = i2c_get_clientdata(client);
+
+	i2c_detach_client(client);
+
+	kfree(codec->reg_cache);
+	kfree(client);
+
+	return 0;
+}
+
+static int wm8731_i2c_attach(struct i2c_adapter *adap)
+{
+	return i2c_probe(adap, &addr_data, wm8731_codec_probe);
+}
+
+/* corgi i2c codec control layer */
+static struct i2c_driver wm8731_i2c_driver = {
+	.driver = {
+		.name = "WM8731 I2C Codec",
+		.owner = THIS_MODULE,
+	},
+	.id =             I2C_DRIVERID_WM8731,
+	.attach_adapter = wm8731_i2c_attach,
+	.detach_client =  wm8731_i2c_detach,
+	.command =        NULL,
+};
+
+static struct i2c_client client_template = {
+	.name =   "WM8731",
+	.driver = &wm8731_i2c_driver,
+};
+#endif
+
+static int wm8731_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct wm8731_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	info("WM8731 Audio Codec %s", WM8731_VERSION);
+
+	if ((codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+
+	socdev->codec = codec;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+
+	wm8731_socdev = socdev;
+#ifdef CONFIG_I2C
+	if (setup->i2c_address) {
+		normal_i2c[0] = setup->i2c_address;
+		codec->hw_write = (hw_write_t)i2c_master_send;
+		if ((ret = i2c_add_driver(&wm8731_i2c_driver)) != 0)
+			printk(KERN_ERR "can't add i2c driver");
+	} 
+#else		
+	/* Add other interfaces here */
+#endif
+	return ret;
+}
+
+/* power down chip */
+static int wm8731_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	if (codec->control_data)
+		wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+
+	snd_soc_free_pcms(socdev);
+	snd_soc_dapm_free(socdev);
+#ifdef CONFIG_I2C
+	i2c_del_driver(&wm8731_i2c_driver);
+#endif
+	kfree(codec);
+
+	return 0;
+}
+
+
+struct snd_soc_codec_device soc_codec_dev_wm8731 = {
+	.probe = 	wm8731_probe,
+	.remove = 	wm8731_remove,
+	.suspend = 	wm8731_suspend,
+	.resume =	wm8731_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731);
+
+MODULE_DESCRIPTION("Soc WM8731 driver");
+MODULE_AUTHOR("Richard Purdie");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8731.h b/sound/soc/codecs/wm8731.h
new file mode 100644
index 0000000..88f5660
--- /dev/null
+++ b/sound/soc/codecs/wm8731.h
@@ -0,0 +1,40 @@
+/*
+ * wm8731.h  --  WM8731 Soc Audio driver
+ *
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Author: Richard Purdie <richard@openedhand.com>
+ *
+ * Based on wm8753.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _WM8731_H
+#define _WM8731_H
+
+/* WM8731 register space */
+
+#define WM8731_LINVOL   0x00
+#define WM8731_RINVOL   0x01
+#define WM8731_LOUT1V   0x02
+#define WM8731_ROUT1V   0x03
+#define WM8731_APANA    0x04
+#define WM8731_APDIGI   0x05
+#define WM8731_PWR      0x06
+#define WM8731_IFACE    0x07
+#define WM8731_SRATE    0x08
+#define WM8731_ACTIVE   0x09
+#define WM8731_RESET	0x0f
+
+#define WM8731_CACHEREGNUM 	10
+
+struct wm8731_setup_data {
+	unsigned short i2c_address;
+};
+
+extern struct snd_soc_codec_device soc_codec_dev_wm8731;
+
+#endif
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
new file mode 100644
index 0000000..2dc7511
--- /dev/null
+++ b/sound/soc/codecs/wm8750.c
@@ -0,0 +1,983 @@
+/*
+ * wm8750.c -- WM8750 ALSA SoC audio driver
+ * 
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Author: Richard Purdie <richard@openedhand.com>
+ *
+ * Based on WM8753.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include "wm8750.h"
+
+#define AUDIO_NAME "WM8750"
+#define WM8750_VERSION "0.7"
+
+/*
+ * Debug
+ */
+ 
+#define PFX AUDIO_NAME
+#define WM8750_DEBUG 0
+
+#ifdef WM8750_DEBUG
+#define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
+#else
+#define dbg(format, arg...) do {} while (0)
+#endif
+#define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
+
+static struct workqueue_struct *wm8750_workq = NULL;
+static struct work_struct wm8750_dapm_work;
+
+/*
+ * wm8750 register cache
+ * We can't read the WM8750 register space when we 
+ * are using 2 wire for device control, so we cache them instead. 
+ */
+static const u16 wm8750_reg[] = {
+	0x0097, 0x0097, 0x0079, 0x0079,  /*  0 */
+	0x0000, 0x0008, 0x0000, 0x000a,  /*  4 */
+	0x0000, 0x0000, 0x00ff, 0x00ff,  /*  8 */
+	0x000f, 0x000f, 0x0000, 0x0000,  /* 12 */
+	0x0000, 0x007b, 0x0000, 0x0032,  /* 16 */
+	0x0000, 0x00c3, 0x00c3, 0x00c0,  /* 20 */
+	0x0000, 0x0000, 0x0000, 0x0000,  /* 24 */
+	0x0000, 0x0000, 0x0000, 0x0000,  /* 28 */
+	0x0000, 0x0000, 0x0050, 0x0050,  /* 32 */
+	0x0050, 0x0050, 0x0050, 0x0050,  /* 36 */
+	0x0079, 0x0079, 0x0079,          /* 40 */
+};
+
+#define WM8750_HIFI_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | \
+	SND_SOC_HWFMT_IB_IF)
+
+#define WM8750_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+
+#define WM8750_HIFI_FS \
+	(SND_SOC_FS(1536) | SND_SOC_FS(1408) | SND_SOC_FS(1024) | \
+	SND_SOC_FS(768) |SND_SOC_FS(512) | SND_SOC_FS(384) | SND_SOC_FS(256) | \
+	SND_SOC_FS(192) | SND_SOC_FS(128))
+
+#define WM8750_HIFI_FSB \
+	(SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4) | \
+	SND_SOC_FSBD(8) | SND_SOC_FSBD(16))
+	
+#define WM8750_HIFI_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+	
+#define WM8750_HIFI_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | SNDRV_PCM_FORMAT_S24_3LE)
+
+static struct snd_soc_hw_mode wm8750_hwfmt[] = {
+	/* common codec frame and clock master modes */
+	{WM8750_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8750_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_8000, 
+		WM8750_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(1536), WM8750_HIFI_FSB},
+	{WM8750_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8750_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_11025, 
+		WM8750_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(1024), WM8750_HIFI_FSB},
+	{WM8750_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8750_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_16000, 
+		WM8750_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(768), WM8750_HIFI_FSB},
+	{WM8750_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8750_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_22050, 
+		WM8750_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(512), WM8750_HIFI_FSB},	
+	{WM8750_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8750_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_44100 | 
+		SNDRV_PCM_RATE_48000, WM8750_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256), 
+		WM8750_HIFI_FSB},
+	{WM8750_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8750_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_88200 | 
+		SNDRV_PCM_RATE_96000, WM8750_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(128), 
+		WM8750_HIFI_FSB},
+
+	/* codec frame and clock slave modes */
+	{WM8750_HIFI_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), 
+		WM8750_HIFI_PCM_FORMATS, WM8750_HIFI_RATES, WM8750_DIR, 
+		SND_SOC_HW_BFS_DIV, SND_SOC_FS_ALL, SND_SOC_FSBD_ALL},
+};
+
+/*
+ * read wm8750 register cache
+ */
+static inline unsigned int wm8750_read_reg_cache(struct snd_soc_codec * codec, 
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg > WM8750_CACHE_REGNUM)
+		return -1;
+	return cache[reg];
+}
+
+/*
+ * write wm8750 register cache
+ */
+static inline void wm8750_write_reg_cache(struct snd_soc_codec * codec, 
+	unsigned int reg, unsigned int value)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg > WM8750_CACHE_REGNUM)
+		return;
+	cache[reg] = value;
+}
+
+static int wm8750_write(struct snd_soc_codec * codec, unsigned int reg, 
+	unsigned int value)
+{
+	u8 data[2];
+	
+	/* data is 
+	 *   D15..D9 WM8753 register offset
+	 *   D8...D0 register data
+	 */
+	data[0] = (reg << 1) | ((value >> 8) & 0x0001);
+	data[1] = value & 0x00ff;
+
+	wm8750_write_reg_cache (codec, reg, value);
+	if (codec->hw_write(codec->control_data, data, 2) == 2)
+		return 0;
+	else
+		return -1;
+}
+
+#define wm8750_reset(c)	wm8750_write(c, WM8750_RESET, 0)
+
+/*
+ * WM8750 Controls
+ */
+static const char* wm8750_bass[] = {"Linear Control", "Adaptive Boost"};
+static const char* wm8750_bass_filter[] = { "130Hz @ 48kHz", "200Hz @ 48kHz" };
+static const char* wm8750_treble[] = {"8kHz", "4kHz"};
+static const char* wm8750_3d_lc[] = {"200Hz", "500Hz"};
+static const char* wm8750_3d_uc[] = {"2.2kHz", "1.5kHz"};
+static const char* wm8750_3d_func[] = {"Capture", "Playback"};
+static const char* wm8750_alc_func[] = {"Off", "Right", "Left", "Stereo"};
+static const char* wm8750_ng_type[] = {"Constant PGA Gain", "Mute ADC Output"};
+static const char* wm8750_line_mux[] = {"Line 1", "Line 2", "Line 3", "PGA", "Differential"};
+static const char* wm8750_pga_sel[] = {"Line 1", "Line 2", "Line 3", "Differential"};
+static const char* wm8750_out3[] = {"VREF", "ROUT1 + Vol", "MonoOut", "ROUT1"};
+static const char* wm8750_diff_sel[] = {"Line 1", "Line 2"};
+static const char* wm8750_adcpol[] = {"Normal", "L Invert", "R Invert", "L + R Invert"};
+static const char* wm8750_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
+static const char* wm8750_mono_mux[] = {"Stereo", "Mono (Left)", "Mono (Right)", "Digital Mono"};
+
+static const struct soc_enum wm8750_enum[] = {
+SOC_ENUM_SINGLE(WM8750_BASS, 7, 2, wm8750_bass),
+SOC_ENUM_SINGLE(WM8750_BASS, 6, 2, wm8750_bass_filter),
+SOC_ENUM_SINGLE(WM8750_TREBLE, 6, 2, wm8750_treble),
+SOC_ENUM_SINGLE(WM8750_3D, 5, 2, wm8750_3d_lc),
+SOC_ENUM_SINGLE(WM8750_3D, 6, 2, wm8750_3d_uc),
+SOC_ENUM_SINGLE(WM8750_3D, 7, 2, wm8750_3d_func),
+SOC_ENUM_SINGLE(WM8750_ALC1, 7, 4, wm8750_alc_func),
+SOC_ENUM_SINGLE(WM8750_NGATE, 1, 2, wm8750_ng_type),
+SOC_ENUM_SINGLE(WM8750_LOUTM1, 0, 5, wm8750_line_mux),
+SOC_ENUM_SINGLE(WM8750_ROUTM1, 0, 5, wm8750_line_mux),
+SOC_ENUM_SINGLE(WM8750_LADCIN, 6, 4, wm8750_pga_sel), /* 10 */
+SOC_ENUM_SINGLE(WM8750_RADCIN, 6, 4, wm8750_pga_sel),
+SOC_ENUM_SINGLE(WM8750_ADCTL2, 7, 4, wm8750_out3),
+SOC_ENUM_SINGLE(WM8750_ADCIN, 8, 2, wm8750_diff_sel),
+SOC_ENUM_SINGLE(WM8750_ADCDAC, 5, 4, wm8750_adcpol),
+SOC_ENUM_SINGLE(WM8750_ADCDAC, 1, 4, wm8750_deemph),
+SOC_ENUM_SINGLE(WM8750_ADCIN, 6, 4, wm8750_mono_mux), /* 16 */
+
+};
+
+static const snd_kcontrol_new_t wm8750_snd_controls[] = {
+
+SOC_DOUBLE_R("Capture Volume", WM8750_LINVOL, WM8750_RINVOL, 0, 63, 0),
+SOC_DOUBLE_R("Capture ZC Switch", WM8750_LINVOL, WM8750_RINVOL, 6, 1, 0),
+SOC_DOUBLE_R("Capture Switch", WM8750_LINVOL, WM8750_RINVOL, 7, 1, 1),
+
+SOC_DOUBLE_R("Out1 Playback ZC Switch", WM8750_LOUT1V, WM8750_ROUT1V, 7, 1, 0),
+SOC_DOUBLE_R("Out2 Playback ZC Switch", WM8750_LOUT2V, WM8750_ROUT2V, 7, 1, 0),
+
+SOC_ENUM("Playback De-emphasis", wm8750_enum[15]),
+
+SOC_ENUM("Capture Polarity", wm8750_enum[14]),
+SOC_SINGLE("Playback 6dB Attenuate", WM8750_ADCDAC, 7, 1, 0),
+SOC_SINGLE("Capture 6dB Attenuate", WM8750_ADCDAC, 8, 1, 0),
+
+SOC_DOUBLE_R("PCM Volume", WM8750_LDAC, WM8750_RDAC, 0, 255, 0),
+
+SOC_ENUM("Bass Boost", wm8750_enum[0]),
+SOC_ENUM("Bass Filter", wm8750_enum[1]),
+SOC_SINGLE("Bass Volume", WM8750_BASS, 0, 15, 1),
+
+SOC_SINGLE("Treble Volume", WM8750_TREBLE, 0, 15, 0),
+SOC_ENUM("Treble Cut-off", wm8750_enum[2]),
+
+SOC_SINGLE("3D Switch", WM8750_3D, 0, 1, 0),
+SOC_SINGLE("3D Volume", WM8750_3D, 1, 15, 0),
+SOC_ENUM("3D Lower Cut-off", wm8750_enum[3]),
+SOC_ENUM("3D Upper Cut-off", wm8750_enum[4]),
+SOC_ENUM("3D Mode", wm8750_enum[5]),
+
+SOC_SINGLE("ALC Capture Target Volume", WM8750_ALC1, 0, 7, 0),
+SOC_SINGLE("ALC Capture Max Volume", WM8750_ALC1, 4, 7, 0),
+SOC_ENUM("ALC Capture Function", wm8750_enum[6]),
+SOC_SINGLE("ALC Capture ZC Switch", WM8750_ALC2, 7, 1, 0),
+SOC_SINGLE("ALC Capture Hold Time", WM8750_ALC2, 0, 15, 0),
+SOC_SINGLE("ALC Capture Decay Time", WM8750_ALC3, 4, 15, 0),
+SOC_SINGLE("ALC Capture Attack Time", WM8750_ALC3, 0, 15, 0),
+SOC_SINGLE("ALC Capture NG Threshold", WM8750_NGATE, 3, 31, 0),
+SOC_ENUM("ALC Capture NG Type", wm8750_enum[4]),
+SOC_SINGLE("ALC Capture NG Switch", WM8750_NGATE, 0, 1, 0),
+
+SOC_SINGLE("Left ADC Capture Volume", WM8750_LADC, 0, 255, 0),
+SOC_SINGLE("Right ADC Capture Volume", WM8750_RADC, 0, 255, 0),
+
+SOC_SINGLE("ZC Timeout Switch", WM8750_ADCTL1, 0, 1, 0),
+SOC_SINGLE("Playback Invert Switch", WM8750_ADCTL1, 1, 1, 0),
+
+SOC_SINGLE("Right Out2 Playback Invert Switch", WM8750_ADCTL2, 4, 1, 0),
+
+
+/* Unimplemented */
+/* ADCDAC Bit 0 - ADCHPD */
+/* ADCDAC Bit 4 - HPOR */
+/* ADCTL1 Bit 2,3 - DATSEL */
+/* ADCTL1 Bit 4,5 - DMONOMIX */
+/* ADCTL1 Bit 6,7 - VSEL */
+/* ADCTL2 Bit 2 - LRCM */
+/* ADCTL2 Bit 3 - TRI */
+/* ADCTL3 Bit 5 - HPFLREN */
+/* ADCTL3 Bit 6 - VROI */
+/* ADCTL3 Bit 7,8 - ADCLRM */
+/* ADCIN Bit 4 - LDCM */ 
+/* ADCIN Bit 5 - RDCM */
+
+SOC_DOUBLE_R("Mic Boost", WM8750_LADCIN, WM8750_RADCIN, 4, 3, 0),
+
+SOC_DOUBLE_R("Bypass Left Playback Volume", WM8750_LOUTM1, WM8750_LOUTM2, 4, 7, 1),
+SOC_DOUBLE_R("Bypass Right Playback Volume", WM8750_ROUTM1, WM8750_ROUTM2, 4, 7, 1),
+SOC_DOUBLE_R("Bypass Mono Playback Volume", WM8750_MOUTM1, WM8750_MOUTM2, 4, 7, 1), 
+
+SOC_SINGLE("Mono Playback ZC Switch", WM8750_MOUTV, 7, 1, 0),
+
+SOC_DOUBLE_R("Out1 Playback Volume", WM8750_LOUT1V, WM8750_ROUT1V, 0, 127, 0),
+SOC_DOUBLE_R("Out2 Playback Volume", WM8750_LOUT2V, WM8750_ROUT2V, 0, 127, 0),
+
+SOC_SINGLE("Mono Playback Volume", WM8750_MOUTV, 0, 127, 0),
+
+};
+
+/* add non dapm controls */
+static int wm8750_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm8750_snd_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	return 0;
+}
+
+/*
+ * DAPM Controls
+ */
+
+/* Left Mixer */
+static const snd_kcontrol_new_t wm8750_left_mixer_controls[] = {
+SOC_DAPM_SINGLE("Playback Switch", WM8750_LOUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Left Bypass Switch", WM8750_LOUTM1, 7, 1, 0),
+SOC_DAPM_SINGLE("Right Playback Switch", WM8750_LOUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Right Bypass Switch", WM8750_LOUTM2, 7, 1, 0),
+};
+
+/* Right Mixer */
+static const snd_kcontrol_new_t wm8750_right_mixer_controls[] = {
+SOC_DAPM_SINGLE("Left Playback Switch", WM8750_ROUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Left Bypass Switch", WM8750_ROUTM1, 7, 1, 0),
+SOC_DAPM_SINGLE("Playback Switch", WM8750_ROUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Right Bypass Switch", WM8750_ROUTM2, 7, 1, 0),
+};
+
+/* Mono Mixer */
+static const snd_kcontrol_new_t wm8750_mono_mixer_controls[] = {
+SOC_DAPM_SINGLE("Left Playback Switch", WM8750_MOUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Left Bypass Switch", WM8750_MOUTM1, 7, 1, 0),
+SOC_DAPM_SINGLE("Right Playback Switch", WM8750_MOUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Right Bypass Switch", WM8750_MOUTM2, 7, 1, 0),
+};
+
+/* Left Line Mux */
+static const snd_kcontrol_new_t wm8750_left_line_controls =
+SOC_DAPM_ENUM("Route", wm8750_enum[8]);
+
+/* Right Line Mux */
+static const snd_kcontrol_new_t wm8750_right_line_controls =
+SOC_DAPM_ENUM("Route", wm8750_enum[9]);
+
+/* Left PGA Mux */
+static const snd_kcontrol_new_t wm8750_left_pga_controls =
+SOC_DAPM_ENUM("Route", wm8750_enum[10]);
+
+/* Right PGA Mux */
+static const snd_kcontrol_new_t wm8750_right_pga_controls =
+SOC_DAPM_ENUM("Route", wm8750_enum[11]);
+
+/* Out 3 Mux */
+static const snd_kcontrol_new_t wm8750_out3_controls =
+SOC_DAPM_ENUM("Route", wm8750_enum[12]);
+
+/* Differential Mux */
+static const snd_kcontrol_new_t wm8750_diffmux_controls =
+SOC_DAPM_ENUM("Route", wm8750_enum[13]);
+
+/* Mono ADC Mux */
+static const snd_kcontrol_new_t wm8750_monomux_controls =
+SOC_DAPM_ENUM("Route", wm8750_enum[16]);
+
+static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
+	SND_SOC_DAPM_CLOCK("WM8750 Clock", WM8750_PWR1, 0, 1),
+	SND_SOC_DAPM_MUTE("DAC Mute", WM8750_ADCDAC, 3, 0),
+	SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_DAPM_NOPM, 0, 0,
+		&wm8750_left_mixer_controls[0], ARRAY_SIZE(wm8750_left_mixer_controls)),
+	SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+		&wm8750_right_mixer_controls[0], ARRAY_SIZE(wm8750_right_mixer_controls)),
+	SND_SOC_DAPM_MIXER("Mono Mixer", WM8750_PWR2, 2, 0, 
+		&wm8750_mono_mixer_controls[0], ARRAY_SIZE(wm8750_mono_mixer_controls)),
+
+	SND_SOC_DAPM_VOLUME("Right Out 2", WM8750_PWR2, 3, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Left Out 2", WM8750_PWR2, 4, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Right Out 1", WM8750_PWR2, 5, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Left Out 1", WM8750_PWR2, 6, 0, NULL, 0),
+	SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8750_PWR2, 7, 0, NULL, 0),
+	SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8750_PWR2, 8, 0, NULL, 0),
+
+	SND_SOC_DAPM_MICBIAS("Mic Bias", WM8750_PWR1, 1, 0),
+	SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8750_PWR1, 2, 0, NULL, 0),
+	SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8750_PWR1, 3, 0, NULL, 0),
+
+	SND_SOC_DAPM_MUX("Left PGA Mux", WM8750_PWR1, 5, 0, &wm8750_left_pga_controls),
+	SND_SOC_DAPM_MUX("Right PGA Mux", WM8750_PWR1, 4, 0, &wm8750_right_pga_controls),
+	SND_SOC_DAPM_MUX("Left Line Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8750_left_line_controls),
+	SND_SOC_DAPM_MUX("Right Line Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8750_right_line_controls),
+
+	SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8750_out3_controls),
+	SND_SOC_DAPM_VOLUME("Out 3", WM8750_PWR2, 1, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Mono Out 1", WM8750_PWR2, 2, 0, NULL, 0),
+	
+	SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8750_diffmux_controls),
+	SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8750_monomux_controls),
+	SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8750_monomux_controls),
+
+	SND_SOC_DAPM_OUTPUT("LOUT1"),
+	SND_SOC_DAPM_OUTPUT("ROUT1"),
+	SND_SOC_DAPM_OUTPUT("LOUT2"),
+	SND_SOC_DAPM_OUTPUT("ROUT2"),
+	SND_SOC_DAPM_OUTPUT("MONO"),
+	SND_SOC_DAPM_OUTPUT("OUT3"),
+
+	SND_SOC_DAPM_INPUT("LINPUT1"),
+	SND_SOC_DAPM_INPUT("LINPUT2"),
+	SND_SOC_DAPM_INPUT("LINPUT3"),
+	SND_SOC_DAPM_INPUT("RINPUT1"),
+	SND_SOC_DAPM_INPUT("RINPUT2"),
+	SND_SOC_DAPM_INPUT("RINPUT3"),
+};
+
+static const char* intercon[][3] = {
+	/* left mixer */
+	{"Left Mixer", "Playback Switch", "Left DAC"},
+	{"Left Mixer", "Left Bypass Switch", "Left Line Mux"},
+	{"Left Mixer", "Right Playback Switch", "Right DAC"},
+	{"Left Mixer", "Right Bypass Switch", "Right Line Mux"},
+
+	/* right mixer */
+	{"Right Mixer", "Left Playback Switch", "Left DAC"},
+	{"Right Mixer", "Left Bypass Switch", "Left Line Mux"},
+	{"Right Mixer", "Playback Switch", "Right DAC"},
+	{"Right Mixer", "Right Bypass Switch", "Right Line Mux"},
+
+	/* left out 1 */
+	{"Left Out 1", NULL, "Left Mixer"},
+	{"LOUT1", NULL, "Left Out 1"},
+
+	/* left out 2 */
+	{"Left Out 2", NULL, "Left Mixer"},
+	{"LOUT2", NULL, "Left Out 2"},
+	
+	/* right out 1 */
+	{"Right Out 1", NULL, "Right Mixer"},
+	{"ROUT1", NULL, "Right Out 1"},
+
+	/* right out 2 */
+	{"Right Out 2", NULL, "Right Mixer"},
+	{"ROUT2", NULL, "Right Out 2"},
+
+	/* mono mixer */
+	{"Mono Mixer", "Left Playback Switch", "Left DAC"},
+	{"Mono Mixer", "Left Bypass Switch", "Left Line Mux"},
+	{"Mono Mixer", "Right Playback Switch", "Right DAC"},
+	{"Mono Mixer", "Right Bypass Switch", "Right Line Mux"},
+	
+	/* mono out */
+	{"Mono Out 1", NULL, "Mono Mixer"},
+	{"MONO1", NULL, "Mono Out 1"},
+
+	/* out 3 */
+	{"Out3 Mux", "VREF", "VREF"},
+	{"Out3 Mux", "ROUT1 + Vol", "ROUT1"},
+	{"Out3 Mux", "ROUT1", "Right Mixer"},
+	{"Out3 Mux", "MonoOut", "MONO1"},
+	{"Out 3", NULL, "Out3 Mux"},
+	{"OUT3", NULL, "Out 3"},
+
+	/* Left Line Mux */
+	{"Left Line Mux", "Line 1", "LINPUT1"},
+	{"Left Line Mux", "Line 2", "LINPUT2"},
+	{"Left Line Mux", "Line 3", "LINPUT3"},
+	{"Left Line Mux", "PGA", "Left PGA Mux"},
+	{"Left Line Mux", "Differential", "Differential Mux"},
+
+	/* Right Line Mux */
+	{"Right Line Mux", "Line 1", "RINPUT1"},
+	{"Right Line Mux", "Line 2", "RINPUT2"},
+	{"Right Line Mux", "Line 3", "RINPUT3"},
+	{"Right Line Mux", "PGA", "Right PGA Mux"},
+	{"Right Line Mux", "Differential", "Differential Mux"},
+
+	/* Left PGA Mux */
+	{"Left PGA Mux", "Line 1", "LINPUT1"},
+	{"Left PGA Mux", "Line 2", "LINPUT2"},
+	{"Left PGA Mux", "Line 3", "LINPUT3"},
+	{"Left PGA Mux", "Differential", "Differential Mux"},
+
+	/* Right PGA Mux */
+	{"Right PGA Mux", "Line 1", "RINPUT1"},
+	{"Right PGA Mux", "Line 2", "RINPUT2"},
+	{"Right PGA Mux", "Line 3", "RINPUT3"},
+	{"Right PGA Mux", "Differential", "Differential Mux"},
+
+	/* Differential Mux */
+	{"Differential Mux", "Line 1", "LINPUT1"},
+	{"Differential Mux", "Line 1", "RINPUT1"},
+	{"Differential Mux", "Line 2", "LINPUT2"},
+	{"Differential Mux", "Line 2", "RINPUT2"},
+
+	/* Left ADC Mux */
+	{"Left ADC Mux", "Stereo", "Left PGA Mux"},
+	{"Left ADC Mux", "Mono (Left)", "Left PGA Mux"},
+	{"Left ADC Mux", "Digital Mono", "Left PGA Mux"},
+
+	/* Right ADC Mux */
+	{"Right ADC Mux", "Stereo", "Right PGA Mux"},
+	{"Right ADC Mux", "Mono (Right)", "Right PGA Mux"},
+	{"Right ADC Mux", "Digital Mono", "Right PGA Mux"},
+
+	/* ADC */
+	{"Left ADC", NULL, "Left ADC Mux"},
+	{"Right ADC", NULL, "Right ADC Mux"},
+	
+	/* terminator */
+	{NULL, NULL, NULL},
+};
+
+static int wm8750_add_widgets(struct snd_soc_codec *codec)
+{
+	int i;
+	
+	for(i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
+	}
+	
+	/* set up audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+
+	snd_soc_dapm_new_widgets(codec);
+	return 0;
+}
+
+struct _coeff_div {
+	u32 mclk;
+	u16 fs;
+	u16 coeff;
+};
+
+/* codec mclk clock divider coefficients */
+static const struct _coeff_div coeff_div[] = {
+	{12288000, 384, 0x18},
+	{12288000, 256, 0x0},
+	{11289600, 256, 0x20},
+	{12288000, 128, 0x1c},
+	{11289600, 128, 0x3c},
+	{12288000, 1536, 0x0c},
+	{12288000, 768, 0x14},
+	{11289000, 1024, 0x30},
+	{11289000, 512, 0x34},
+};
+
+static int get_coeff(struct snd_soc_pcm_codec *pcm_codec, int fs)
+{
+	int i;
+	
+	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
+		if (coeff_div[i].mclk == pcm_codec->mclk && coeff_div[i].fs == fs)
+			return coeff_div[i].coeff;
+	}
+	return 0;
+}
+
+static unsigned int wm8750_config_sysclk(struct snd_soc_pcm_codec *pcm_codec, 
+	int rate, unsigned int clk)
+{
+	switch(rate){
+	case 8000:
+	case 16000:
+	case 32000:
+	case 48000:
+	case 96000:
+		if (clk == 12288000 || clk == 18432000)
+			pcm_codec->mclk = clk;
+		break;
+	case 11025:
+	case 22050:
+	case 44100:
+	case 88200:
+		if (clk == 11289600 || clk == 16934400)
+			pcm_codec->mclk = clk;
+		break;
+	default:
+		pcm_codec->mclk = 0;
+	}
+	
+	return pcm_codec->mclk;
+}
+
+static int wm8750_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 iface = 0, fs, bfs, srate;
+	
+	bfs = SND_SOC_FSB_INT(rtd->pcm_c->hw_runtime.hwbfs);
+	fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+	srate = get_coeff(rtd->pcm_c, fs);
+
+	/* set master/slave audio interface */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK) {
+		case SND_SOC_HWFMT_CBM_CFM:
+			iface = 0x0040;
+			break;
+		case SND_SOC_HWFMT_CBS_CFS:
+			break;
+	}
+	
+	/* interface format */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+		case SND_SOC_HWFMT_I2S:
+			iface |= 0x0002;
+			break;
+		case SND_SOC_HWFMT_RIGHT_J:
+			break;
+		case SND_SOC_HWFMT_LEFT_J:
+			iface |= 0x0001;
+			break;
+		case SND_SOC_HWFMT_DSP_A:
+			iface |= 0x0003;
+			break;
+		case SND_SOC_HWFMT_DSP_B:
+			iface |= 0x0013;
+			break;
+	}
+		
+	/* bit size */
+	switch(rtd->pcm_c->hw_runtime.hwpcmfmt) {
+		case SNDRV_PCM_FORMAT_S16_LE:
+			break;
+		case SNDRV_PCM_FORMAT_S20_3LE:
+			iface |= 0x0004;
+			break;
+		case SNDRV_PCM_FORMAT_S24_3LE:
+			iface |= 0x0008;
+			break;
+		case SNDRV_PCM_FORMAT_S32_LE:
+			iface |= 0x000c;
+			break;
+	}
+
+	/* clock inversion */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK) {
+		case SND_SOC_HWFMT_NB_NF:
+			break;
+		case SND_SOC_HWFMT_IB_IF:
+			iface |= 0x0090;
+			break;
+		case SND_SOC_HWFMT_IB_NF:
+			iface |= 0x0080;
+			break;
+		case SND_SOC_HWFMT_NB_IF:
+			iface |= 0x0010;
+			break;
+	}
+	
+	/* set bclk divisor rate */
+	switch (bfs) {
+		case 1:
+			break;
+		case 4:
+			srate |= (0x1 << 7);
+			break;
+		case 8:
+			srate |= (0x2 << 7);
+			break;
+		case 16:
+			srate |= (0x3 << 7);
+			break;
+	}		
+	
+	/* set rate */
+	wm8750_write(codec, WM8750_SRATE, srate);
+	wm8750_write(codec, WM8750_IFACE, iface);
+	
+	return 0;
+}
+
+static int wm8750_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	u16 pwr_reg = wm8750_read_reg_cache(codec, WM8750_PWR1) & 0xfe3f;
+	
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			/* set vmid to 50k and unmute dac */
+			wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x00c0);
+			break;
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			/* set vmid to 5k for quick power up */
+			wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x01c0);
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* mute dac and set vmid to 500k, enable VREF */
+			wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x0140);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			wm8750_write(codec, WM8750_PWR1, 0x0000);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static struct snd_soc_pcm_codec wm8750_pcm_client = {
+	.name = "WM8750",
+	.playback = {
+		.sname = "Playback",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.nplayback = 1,
+	.capture = {
+		.sname = "Capture",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.ncapture = 1,
+	.config_sysclk = wm8750_config_sysclk,
+	.ops = {
+		.prepare = wm8750_pcm_prepare,
+	},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8750_hwfmt),
+		.hmodes = &wm8750_hwfmt[0],
+	},
+};
+
+static void wm8750_work(void *data)
+{
+	struct snd_soc_codec *codec = (struct snd_soc_codec *)data;
+	wm8750_dapm_event(codec, codec->dapm_state);
+}
+
+static int wm8750_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int wm8750_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+	u8 data[2];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (i = 0; i < ARRAY_SIZE(wm8750_reg); i++) {
+		if (i == WM8750_RESET)
+			continue;
+		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
+		data[1] = cache[i] & 0x00ff;
+		codec->hw_write(codec->control_data, data, 2);
+	}
+	
+	wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	
+	/* charge wm8750 caps */
+	if(codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
+		wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
+		codec->dapm_state = SNDRV_CTL_POWER_D0;
+		queue_delayed_work(wm8750_workq, &wm8750_dapm_work, msecs_to_jiffies(1000));
+	}
+	
+	return 0;
+}
+
+/*
+ * initialise the WM8750 driver
+ * register the mixer and dsp interfaces with the kernel 
+ */
+static int wm8750_init(struct snd_soc_device* socdev)
+{
+	struct snd_soc_codec* codec = socdev->codec;
+	int reg, ret = 0;
+
+	codec->name = "WM8750";
+	codec->owner = THIS_MODULE;
+	codec->read = wm8750_read_reg_cache;
+	codec->write = wm8750_write;
+	codec->dapm_event = wm8750_dapm_event;
+	codec->pcms = &wm8750_pcm_client;
+	codec->npcms = 1;
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(wm8750_reg), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	memcpy(codec->reg_cache, wm8750_reg, sizeof(u16) * ARRAY_SIZE(wm8750_reg));
+	
+	wm8750_reset(codec);
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0) {
+		kfree(codec->reg_cache);
+		return ret;
+	}
+	
+	/* charge output caps */
+	wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
+	codec->dapm_state = SNDRV_CTL_POWER_D3hot;
+	queue_delayed_work(wm8750_workq, &wm8750_dapm_work, msecs_to_jiffies(1000));
+
+	/* set the update bits */
+	reg = wm8750_read_reg_cache(codec, WM8750_LDAC);
+	wm8750_write(codec, WM8750_LDAC, reg | 0x0100);
+	reg = wm8750_read_reg_cache(codec, WM8750_RDAC);
+	wm8750_write(codec, WM8750_RDAC, reg | 0x0100);
+	reg = wm8750_read_reg_cache(codec, WM8750_LOUT1V);
+	wm8750_write(codec, WM8750_LOUT1V, reg | 0x0100);
+	reg = wm8750_read_reg_cache(codec, WM8750_ROUT1V);
+	wm8750_write(codec, WM8750_ROUT1V, reg | 0x0100);
+	reg = wm8750_read_reg_cache(codec, WM8750_LOUT2V);
+	wm8750_write(codec, WM8750_LOUT2V, reg | 0x0100);
+	reg = wm8750_read_reg_cache(codec, WM8750_ROUT2V);
+	wm8750_write(codec, WM8750_ROUT2V, reg | 0x0100);
+	reg = wm8750_read_reg_cache(codec, WM8750_LINVOL);
+	wm8750_write(codec, WM8750_LINVOL, reg | 0x0100);
+	reg = wm8750_read_reg_cache(codec, WM8750_RINVOL);
+	wm8750_write(codec, WM8750_RINVOL, reg | 0x0100);
+
+	wm8750_add_controls(codec);
+	wm8750_add_widgets(codec);
+	snd_soc_register_card(socdev);
+
+	return 0;
+}
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+static struct snd_soc_device *wm8750_socdev;
+
+#ifdef CONFIG_I2C
+
+/*
+ * WM8731 2 wire address is determined by GPIO5
+ * state during powerup.
+ *    low  = 0x1a
+ *    high = 0x1b
+ */
+#define I2C_DRIVERID_WM8750 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver wm8750_i2c_driver;
+static struct i2c_client client_template;
+
+static int wm8750_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+	struct snd_soc_device *socdev = wm8750_socdev;
+	struct wm8750_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec = socdev->codec;
+	struct i2c_client *i2c;
+	int ret;
+
+	if (addr != setup->i2c_address)
+		return -ENODEV;
+
+	client_template.adapter = adap;
+	client_template.addr = addr;
+
+	if ((i2c = kzalloc(sizeof(struct i2c_client), GFP_KERNEL)) == NULL){
+		kfree(codec);
+		return -ENOMEM;
+	}
+	memcpy(i2c, &client_template, sizeof(struct i2c_client));
+
+	i2c_set_clientdata(i2c, codec);
+
+	codec->control_data = i2c;
+
+	if((ret = i2c_attach_client(i2c)) < 0) {
+		err("failed to attach codec at addr %x\n", addr);
+		kfree(i2c);
+		return ret;
+	}
+
+	wm8750_init(socdev);
+
+	return 0;
+}
+
+static int wm8750_i2c_detach(struct i2c_client *client)
+{
+	struct snd_soc_codec* codec = i2c_get_clientdata(client);
+
+	i2c_detach_client(client);
+
+	kfree(codec->reg_cache);
+	kfree(client);
+
+	return 0;
+}
+
+static int wm8750_i2c_attach(struct i2c_adapter *adap)
+{
+	return i2c_probe(adap, &addr_data, wm8750_codec_probe);
+}
+
+/* corgi i2c codec control layer */
+static struct i2c_driver wm8750_i2c_driver = {
+	.driver = {
+		.name = "WM8750 I2C Codec",
+		.owner = THIS_MODULE,
+	},
+	.id =             I2C_DRIVERID_WM8750,
+	.attach_adapter = wm8750_i2c_attach,
+	.detach_client =  wm8750_i2c_detach,
+	.command =        NULL,
+};
+
+static struct i2c_client client_template = {
+	.name =   "WM8750",
+	.driver = &wm8750_i2c_driver,
+};
+#endif
+
+static int wm8750_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct wm8750_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	info("WM8750 Audio Codec %s", WM8750_VERSION);
+
+	if ((codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+
+	socdev->codec = codec;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+	wm8750_socdev = socdev;
+	INIT_WORK(&wm8750_dapm_work, wm8750_work, codec);
+	if((wm8750_workq = create_workqueue("wm8750")) == NULL) {
+		kfree(codec);
+		return -ENOMEM;
+	}
+#ifdef CONFIG_I2C
+	if (setup->i2c_address) {
+		normal_i2c[0] = setup->i2c_address;
+		codec->hw_write = (hw_write_t)i2c_master_send;
+		if ((ret = i2c_add_driver(&wm8750_i2c_driver)) != 0)
+			printk(KERN_ERR "can't add i2c driver");
+	}
+#else
+		/* Add other interfaces here */
+#endif
+
+	return ret;
+}
+
+/* power down chip */
+static int wm8750_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	if (codec->control_data)
+		wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	if(wm8750_workq)
+		destroy_workqueue(wm8750_workq);
+	snd_soc_free_pcms(socdev);
+	snd_soc_dapm_free(socdev);
+#ifdef CONFIG_I2C
+	i2c_del_driver(&wm8750_i2c_driver);
+#endif
+	kfree(codec);
+
+	return 0;
+}
+
+
+struct snd_soc_codec_device soc_codec_dev_wm8750 = {
+	.probe = 	wm8750_probe,
+	.remove = 	wm8750_remove,
+	.suspend = 	wm8750_suspend,
+	.resume =	wm8750_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750);
+
+MODULE_DESCRIPTION("Soc WM8750 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8750.h b/sound/soc/codecs/wm8750.h
new file mode 100644
index 0000000..b93b63d
--- /dev/null
+++ b/sound/soc/codecs/wm8750.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Author: Richard Purdie <richard@openedhand.com>
+ *
+ * Based on WM8753.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef _WM8750_H
+#define _WM8750_H
+
+/* WM8750 register space */
+
+#define WM8750_LINVOL    0x00
+#define WM8750_RINVOL    0x01
+#define WM8750_LOUT1V    0x02
+#define WM8750_ROUT1V    0x03
+#define WM8750_ADCDAC    0x05
+#define WM8750_IFACE     0x07
+#define WM8750_SRATE     0x08
+#define WM8750_LDAC      0x0a
+#define WM8750_RDAC      0x0b
+#define WM8750_BASS      0x0c
+#define WM8750_TREBLE    0x0d
+#define WM8750_RESET     0x0f
+#define WM8750_3D        0x10
+#define WM8750_ALC1      0x11
+#define WM8750_ALC2      0x12
+#define WM8750_ALC3      0x13
+#define WM8750_NGATE     0x14
+#define WM8750_LADC      0x15
+#define WM8750_RADC      0x16
+#define WM8750_ADCTL1    0x17
+#define WM8750_ADCTL2    0x18
+#define WM8750_PWR1      0x19
+#define WM8750_PWR2      0x1a
+#define WM8750_ADCTL3    0x1b
+#define WM8750_ADCIN     0x1f
+#define WM8750_LADCIN    0x20
+#define WM8750_RADCIN    0x21
+#define WM8750_LOUTM1    0x22
+#define WM8750_LOUTM2    0x23
+#define WM8750_ROUTM1    0x24
+#define WM8750_ROUTM2    0x25
+#define WM8750_MOUTM1    0x26
+#define WM8750_MOUTM2    0x27
+#define WM8750_LOUT2V    0x28
+#define WM8750_ROUT2V    0x29
+#define WM8750_MOUTV     0x2a
+
+#define WM8750_CACHE_REGNUM 0x2a
+
+struct wm8750_setup_data {
+	unsigned short i2c_address;
+	unsigned int mclk;
+};
+
+extern struct snd_soc_codec_device soc_codec_dev_wm8750;
+
+#endif
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
new file mode 100644
index 0000000..1406e2f
--- /dev/null
+++ b/sound/soc/codecs/wm8753.c
@@ -0,0 +1,1424 @@
+/*
+ * wm8753.c  --  WM8753 ALSA Soc Audio driver
+ *
+ * Copyright 2003 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ * Notes:
+ *  The WM8753 is a low power, high quality stereo codec with integrated PCM
+ *  codec designed for portable digital telephony applications.
+ * 
+ * TODO:
+ *  o Fix voice in master mode.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include "wm8753.h"
+
+#define AUDIO_NAME "wm8753"
+#define WM8753_VERSION "0.8"
+
+/*
+ * Debug
+ */
+ 
+#define PFX AUDIO_NAME
+#define WM8753_DEBUG 0
+
+#ifdef WM8753_DEBUG
+#define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
+#else
+#define dbg(format, arg...) do {} while (0)
+#endif
+#define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
+
+static struct workqueue_struct *wm8753_workq = NULL;
+static struct work_struct wm8753_dapm_work;
+
+/*
+ * wm8753 register cache
+ * We can't read the WM8753 register space when we 
+ * are using 2 wire for device control, so we cache them instead. 
+ */
+static const u16 wm8753_reg[] = {
+	0x0008, 0x0000, 0x000a, 0x000a,  
+	0x0033, 0x0000, 0x0007, 0x00ff,
+	0x00ff, 0x000f, 0x000f, 0x007b, 
+	0x0000, 0x0032, 0x0000, 0x00c3,
+	0x00c3, 0x00c0, 0x0000, 0x0000,
+	0x0000, 0x0000, 0x0000, 0x0000,
+	0x0000, 0x0000, 0x0000, 0x0000,
+	0x0000, 0x0000, 0x0000, 0x0055, 
+	0x0005, 0x0050, 0x0055, 0x0050,
+	0x0055, 0x0050, 0x0055, 0x0079, 
+	0x0079, 0x0079, 0x0079, 0x0079,
+	0x0000, 0x0000, 0x0000, 0x0000, 
+	0x0097, 0x0097, 0x0000, 0x0004,
+	0x0000, 0x0083, 0x0024, 0x01ba,
+	0x0000, 0x0083, 0x0024, 0x01ba, 
+	0x0000, 0x0000
+};
+
+#define WM8753_HIFI_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | \
+	SND_SOC_HWFMT_IB_IF)
+
+#define WM8753_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+
+#define WM8753_HIFI_FS \
+	(SND_SOC_FS(1536) | SND_SOC_FS(1408) | SND_SOC_FS(1024) | \
+	SND_SOC_FS(768) |SND_SOC_FS(512) | SND_SOC_FS(384) | SND_SOC_FS(256) | \
+	SND_SOC_FS(192) | SND_SOC_FS(128))
+
+#define WM8753_HIFI_FSB \
+	(SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4) | \
+	SND_SOC_FSBD(8) | SND_SOC_FSBD(16))
+	
+#define WM8753_HIFI_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+	
+#define WM8753_HIFI_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | SNDRV_PCM_FORMAT_S24_3LE)
+/*
+ * HiFi modes
+ */
+static struct snd_soc_hw_mode wm8753_hifi[] = {
+	/* codec frame and clock master modes */
+	{WM8753_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8753_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_8000, 
+		WM8753_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(1536), WM8753_HIFI_FSB},
+	{WM8753_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8753_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_11025, 
+		WM8753_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(1024), WM8753_HIFI_FSB},
+	{WM8753_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8753_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_16000, 
+		WM8753_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(768), WM8753_HIFI_FSB},
+	{WM8753_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8753_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_22050, 
+		WM8753_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(512), WM8753_HIFI_FSB},	
+	{WM8753_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8753_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_44100 | 
+		SNDRV_PCM_RATE_48000, WM8753_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256), 
+		WM8753_HIFI_FSB},
+	{WM8753_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8753_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_88200 | 
+		SNDRV_PCM_RATE_96000, WM8753_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(128), 
+		WM8753_HIFI_FSB},
+
+	/* codec frame and clock slave modes */
+	{WM8753_HIFI_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), 
+		WM8753_HIFI_PCM_FORMATS, WM8753_HIFI_RATES, WM8753_DIR, 
+		SND_SOC_HW_BFS_DIV, SND_SOC_FS_ALL, SND_SOC_FSBD_ALL},
+
+};
+
+#define WM8753_VOICE_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	SND_SOC_HWFMT_DSP_A | SND_SOC_HWFMT_DSP_B |  SND_SOC_HWFMT_NB_NF | \
+	SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | SND_SOC_HWFMT_IB_IF)
+
+#define WM8753_VOICE_FS \
+	(SND_SOC_FS(384) | SND_SOC_FS(256))
+
+#define WM8753_VOICE_FSB \
+	(SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4) | \
+	SND_SOC_FSBD(8) | SND_SOC_FSBD(16))
+	
+#define WM8753_VOICE_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000)
+	
+#define WM8753_VOICE_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | SNDRV_PCM_FORMAT_S24_3LE)
+
+/*
+ * Voice modes
+ */
+static struct snd_soc_hw_mode wm8753_voice[] = {
+	
+	/* master modes */
+	{WM8753_VOICE_HWFMT | SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8753_VOICE_PCM_FORMATS, WM8753_VOICE_RATES, 
+		WM8753_DIR, SND_SOC_HW_BFS_DIV, WM8753_VOICE_FS, WM8753_VOICE_FSB},
+		
+	/* slave modes */
+	{WM8753_VOICE_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), 
+		WM8753_VOICE_PCM_FORMATS, WM8753_VOICE_RATES, WM8753_DIR, 
+		SND_SOC_HW_BFS_DIV, SND_SOC_FS_ALL, SND_SOC_FSB_ALL},
+};
+
+/*
+ * read wm8753 register cache
+ */
+static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec * codec, 
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+	if(reg < 1 || reg > (ARRAY_SIZE(wm8753_reg) + 1))
+		return -1;
+	return cache[reg - 1];
+}
+
+/*
+ * write wm8753 register cache
+ */
+static inline void wm8753_write_reg_cache(struct snd_soc_codec * codec, 
+	unsigned int reg, unsigned int value)
+{
+	u16 *cache = codec->reg_cache;
+	if(reg < 1 || reg > (ARRAY_SIZE(wm8753_reg) + 1))
+		return;
+	cache[reg - 1] = value;
+}
+
+/*
+ * write to the WM8753 register space
+ */
+static int wm8753_write(struct snd_soc_codec * codec, unsigned int reg,
+	unsigned int value)
+{
+	u8 data[2];
+	
+	/* data is 
+	 *   D15..D9 WM8753 register offset
+	 *   D8...D0 register data
+	 */
+	data[0] = (reg << 1) | ((value >> 8) & 0x0001);
+	data[1] = value & 0x00ff;
+
+	wm8753_write_reg_cache (codec, reg, value);
+	if (codec->hw_write(codec->control_data, data, 2) == 2)
+		return 0;
+	else
+		return -1;
+}
+
+#define wm8753_reset(c) wm8753_write(c, WM8753_RESET, 0)
+
+/*
+ * WM8753 Controls
+ */
+static const char* wm8753_base[] = {"Linear Control", "Adaptive Boost"};
+static const char* wm8753_base_filter[] = 
+	{"130Hz @ 48kHz", "200Hz @ 48kHz", "100Hz @ 16kHz", "400Hz @ 48kHz", 
+	"100Hz @ 8kHz", "200Hz @ 8kHz"};
+static const char* wm8753_treble[] = {"8kHz", "4kHz"};
+static const char* wm8753_alc_func[] = {"Off", "Right", "Left", "Stereo"};
+static const char* wm8753_ng_type[] = {"Constant PGA Gain", "Mute ADC Output"};
+static const char* wm8753_3d_func[] = {"Capture", "Playback"};
+static const char* wm8753_3d_uc[] = {"2.2kHz", "1.5kHz"};
+static const char* wm8753_3d_lc[] = {"200Hz", "500Hz"};
+static const char* wm8753_deemp[] = {"None", "32kHz", "44.1kHz", "48kHz"};
+static const char* wm8753_mono_mix[] = {"Stereo", "Left", "Right", "Mono"};
+static const char* wm8753_dac_phase[] = {"Non Inverted", "Inverted"};
+static const char* wm8753_line_mix[] = {"Line 1 + 2", "Line 1 - 2", 
+	"Line 1", "Line 2"};
+static const char* wm8753_mono_mux[] = {"Line Mix", "Rx Mix"};
+static const char* wm8753_right_mux[] = {"Line 2", "Rx Mix"};
+static const char* wm8753_left_mux[] = {"Line 1", "Rx Mix"};
+static const char* wm8753_rxmsel[] = {"RXP - RXN", "RXP + RXN", "RXP", "RXN"};
+static const char* wm8753_sidetone_mux[] = {"Left PGA", "Mic 1", "Mic 2", "Right PGA"};
+static const char* wm8753_mono2_src[] = {"Inverted Mono 1", "Left", "Right", "Left + Right"};
+static const char* wm8753_out3[] = {"VREF", "ROUT2", "Left + Right"};
+static const char* wm8753_out4[] = {"VREF", "Capture ST", "LOUT2"};
+static const char* wm8753_radcsel[] = {"PGA", "Line or RXP-RXN", "Sidetone"};
+static const char* wm8753_ladcsel[] = {"PGA", "Line or RXP-RXN", "Line"};
+static const char* wm8753_mono_adc[] = {"Stereo", "Analogue Mix Left", "Analogue Mix Right",
+	"Digital Mono Mix"};
+static const char* wm8753_adc_hp[] = {"3.4Hz @ 48kHz", "82Hz @ 16k", "82Hz @ 8kHz", "170Hz @ 8kHz"};
+static const char* wm8753_adc_filter[] = {"HiFi", "Voice"};
+static const char* wm8753_mic_sel[] = {"Mic 1", "Mic 2", "Mic 3"};
+
+static const struct soc_enum wm8753_enum[] = {
+SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base),		// 0
+SOC_ENUM_SINGLE(WM8753_BASS, 4, 6, wm8753_base_filter),	// 1
+SOC_ENUM_SINGLE(WM8753_TREBLE, 6, 2, wm8753_treble), 	// 2
+SOC_ENUM_SINGLE(WM8753_ALC1, 7, 4, wm8753_alc_func),	// 3
+SOC_ENUM_SINGLE(WM8753_NGATE, 1, 2, wm8753_ng_type),	// 4
+SOC_ENUM_SINGLE(WM8753_3D, 7, 2, wm8753_3d_func),		// 5
+SOC_ENUM_SINGLE(WM8753_3D, 6, 2, wm8753_3d_uc),			// 6
+SOC_ENUM_SINGLE(WM8753_3D, 5, 2, wm8753_3d_lc),			// 7
+SOC_ENUM_SINGLE(WM8753_DAC, 1, 4, wm8753_deemp),		// 8
+SOC_ENUM_SINGLE(WM8753_DAC, 4, 4, wm8753_mono_mix),		// 9
+SOC_ENUM_SINGLE(WM8753_DAC, 6, 2, wm8753_dac_phase),	// 10
+SOC_ENUM_SINGLE(WM8753_INCTL1, 3, 4, wm8753_line_mix),	// 11
+SOC_ENUM_SINGLE(WM8753_INCTL1, 2, 2, wm8753_mono_mux),	// 12
+SOC_ENUM_SINGLE(WM8753_INCTL1, 1, 2, wm8753_right_mux),	// 13
+SOC_ENUM_SINGLE(WM8753_INCTL1, 0, 2, wm8753_left_mux),	// 14
+SOC_ENUM_SINGLE(WM8753_INCTL2, 6, 4, wm8753_rxmsel),	// 15
+SOC_ENUM_SINGLE(WM8753_INCTL2, 4, 4, wm8753_sidetone_mux),// 16
+SOC_ENUM_SINGLE(WM8753_OUTCTL, 7, 4, wm8753_mono2_src),	// 17
+SOC_ENUM_SINGLE(WM8753_OUTCTL, 0, 3, wm8753_out3),		// 18
+SOC_ENUM_SINGLE(WM8753_ADCTL2, 7, 3, wm8753_out4),		// 19
+SOC_ENUM_SINGLE(WM8753_ADCIN, 2, 3, wm8753_radcsel),	// 20
+SOC_ENUM_SINGLE(WM8753_ADCIN, 0, 3, wm8753_ladcsel),	// 21
+SOC_ENUM_SINGLE(WM8753_ADCIN, 4, 4, wm8753_mono_adc),	// 22
+SOC_ENUM_SINGLE(WM8753_ADC, 2, 4, wm8753_adc_hp),		// 23
+SOC_ENUM_SINGLE(WM8753_ADC, 4, 2, wm8753_adc_filter),	// 24
+SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel),	// 25
+};
+
+static const snd_kcontrol_new_t wm8753_snd_controls[] = {
+SOC_DOUBLE_R("PCM Volume", WM8753_LDAC, WM8753_RDAC, 0, 255, 0),
+
+SOC_DOUBLE_R("ADC Capture Volume", WM8753_LADC, WM8753_RADC, 0, 63, 0),
+SOC_DOUBLE_R("ADC Capture Switch", WM8753_LADC, WM8753_RADC, 7, 1, 0),
+SOC_DOUBLE_R("ADC Capture ZC Switch", WM8753_LADC, WM8753_RADC, 6, 1, 0),	
+	
+SOC_DOUBLE_R("Out1 Playback Volume", WM8753_LOUT1V, WM8753_ROUT1V, 0, 127, 0),
+SOC_DOUBLE_R("Out2 Playback Volume", WM8753_LOUT2V, WM8753_ROUT2V, 0, 127, 0),
+
+SOC_SINGLE("Mono Playback Volume", WM8753_MOUTV, 0, 127, 0),
+	
+SOC_DOUBLE_R("Bypass Playback Volume", WM8753_LOUTM1, WM8753_ROUTM1, 4, 7, 1),	
+SOC_DOUBLE_R("Sidetone Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 4, 7, 1),	
+SOC_DOUBLE_R("Voice Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 0, 7, 1),
+
+SOC_DOUBLE_R("Out1 Playback ZC Switch", WM8753_LOUT1V, WM8753_ROUT1V, 7, 1, 0),	
+SOC_DOUBLE_R("Out2 Playback ZC Switch", WM8753_LOUT2V, WM8753_ROUT2V, 7, 1, 0),	
+	
+SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1),
+SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1),
+SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 4, 7, 1),
+SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0),
+
+SOC_ENUM("Bass Boost", wm8753_enum[0]),
+SOC_ENUM("Bass Filter", wm8753_enum[1]),
+SOC_SINGLE("Bass Volume", WM8753_BASS, 0, 7, 1),
+
+SOC_SINGLE("Treble Volume", WM8753_TREBLE, 0, 7, 0),
+SOC_ENUM("Treble Cut-off", wm8753_enum[2]),
+
+SOC_DOUBLE("Sidetone Capture Volume", WM8753_RECMIX1, 0, 4, 7, 1),
+SOC_SINGLE("Voice Sidetone Capture Volume", WM8753_RECMIX2, 0, 7, 1),
+
+SOC_DOUBLE_R("Capture Volume", WM8753_LINVOL, WM8753_RINVOL, 0, 63, 0),
+SOC_DOUBLE_R("Capture ZC Switch", WM8753_LINVOL, WM8753_RINVOL, 6, 1, 0),
+SOC_DOUBLE_R("Capture Switch", WM8753_LINVOL, WM8753_RINVOL, 7, 1, 0),
+
+SOC_ENUM("Capture Filter Select", wm8753_enum[23]),
+SOC_ENUM("Capture Filter Cut-off", wm8753_enum[24]),
+SOC_SINGLE("Capture Filter Switch", WM8753_ADC, 0, 1, 1),
+
+SOC_SINGLE("ALC Capture Target Volume", WM8753_ALC1, 0, 7, 0),
+SOC_SINGLE("ALC Capture Max Volume", WM8753_ALC1, 4, 7, 0),
+SOC_ENUM("ALC Capture Function", wm8753_enum[3]),
+SOC_SINGLE("ALC Capture ZC Switch", WM8753_ALC2, 8, 1, 0),
+SOC_SINGLE("ALC Capture Hold Time", WM8753_ALC2, 0, 15, 1),
+SOC_SINGLE("ALC Capture Decay Time", WM8753_ALC3, 4, 15, 1),
+SOC_SINGLE("ALC Capture Attack Time", WM8753_ALC3, 0, 15, 0),
+SOC_SINGLE("ALC Capture NG Threshold", WM8753_NGATE, 3, 31, 0),
+SOC_ENUM("ALC Capture NG Type", wm8753_enum[4]),
+SOC_SINGLE("ALC Capture NG Switch", WM8753_NGATE, 0, 1, 0),
+
+SOC_ENUM("3D Function", wm8753_enum[5]),
+SOC_ENUM("3D Upper Cut-off", wm8753_enum[6]),
+SOC_ENUM("3D Lower Cut-off", wm8753_enum[7]),
+SOC_SINGLE("3D Volume", WM8753_3D, 1, 15, 0),
+SOC_SINGLE("3D Switch", WM8753_3D, 0, 1, 0),
+
+SOC_SINGLE("Capture 6dB Attenuate", WM8753_ADCTL1, 2, 1, 0),
+SOC_SINGLE("Playback 6dB Attenuate", WM8753_ADCTL1, 1, 1, 0),
+
+SOC_ENUM("De-emphasis", wm8753_enum[8]),
+SOC_ENUM("Playback Mono Mix", wm8753_enum[9]),
+SOC_ENUM("Playback Phase", wm8753_enum[10]),
+
+SOC_SINGLE("Mic2 Capture Volume", WM8753_INCTL1, 7, 3, 0),
+SOC_SINGLE("Mic1 Capture Volume", WM8753_INCTL1, 5, 3, 0),
+};
+
+/* add non dapm controls */
+static int wm8753_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm8753_snd_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	return 0;
+}
+
+/*
+ * _DAPM_ Controls
+ */
+
+/* Left Mixer */
+static const snd_kcontrol_new_t wm8753_left_mixer_controls[] = {
+SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_LOUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_LOUTM2, 7, 1, 0),
+SOC_DAPM_SINGLE("Left Playback Switch", WM8753_LOUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_LOUTM1, 7, 1, 0),
+};
+
+/* Right mixer */
+static const snd_kcontrol_new_t wm8753_right_mixer_controls[] = {
+SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_ROUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_ROUTM2, 7, 1, 0),
+SOC_DAPM_SINGLE("Right Playback Switch", WM8753_ROUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_ROUTM1, 7, 1, 0),
+};
+
+/* Mono mixer */
+static const snd_kcontrol_new_t wm8753_mono_mixer_controls[] = {
+SOC_DAPM_SINGLE("Left Playback Switch", WM8753_MOUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Right Playback Switch", WM8753_MOUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_MOUTM2, 4, 1, 0),
+SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_MOUTM2, 7, 1, 0),
+SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_ROUTM1, 7, 1, 0),
+};
+
+/* Mono 2 Mux */
+static const snd_kcontrol_new_t wm8753_mono2_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[17]);
+
+/* Out 3 Mux */
+static const snd_kcontrol_new_t wm8753_out3_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[18]);
+
+/* Out 4 Mux */
+static const snd_kcontrol_new_t wm8753_out4_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[19]);
+
+/* ADC Mono Mix */
+static const snd_kcontrol_new_t wm8753_adc_mono_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[22]);
+
+/* Record mixer */
+static const snd_kcontrol_new_t wm8753_record_mixer_controls[] = {
+SOC_DAPM_SINGLE("Voice Capture Switch", WM8753_RECMIX2, 3, 1, 0),
+SOC_DAPM_SINGLE("Left Capture Switch", WM8753_RECMIX1, 3, 1, 0),
+SOC_DAPM_SINGLE("Right Capture Switch", WM8753_RECMIX1, 7, 1, 0),
+};
+
+/* Left ADC mux */
+static const snd_kcontrol_new_t wm8753_adc_left_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[21]);
+
+/* Right ADC mux */
+static const snd_kcontrol_new_t wm8753_adc_right_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[20]);
+
+/* MIC mux */
+static const snd_kcontrol_new_t wm8753_mic_mux_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[16]);
+
+/* ALC mixer */
+static const snd_kcontrol_new_t wm8753_alc_mixer_controls[] = {
+SOC_DAPM_SINGLE("Line Capture Switch", WM8753_INCTL2, 3, 1, 0),
+SOC_DAPM_SINGLE("Mic2 Capture Switch", WM8753_INCTL2, 2, 1, 0),
+SOC_DAPM_SINGLE("Mic1 Capture Switch", WM8753_INCTL2, 1, 1, 0),
+SOC_DAPM_SINGLE("Rx Capture Switch", WM8753_INCTL2, 0, 1, 0),
+};
+
+/* Left Line mux */
+static const snd_kcontrol_new_t wm8753_line_left_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[14]);
+
+/* Right Line mux */
+static const snd_kcontrol_new_t wm8753_line_right_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[13]);
+
+/* Mono Line mux */
+static const snd_kcontrol_new_t wm8753_line_mono_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[12]);
+
+/* Line mux and mixer */
+static const snd_kcontrol_new_t wm8753_line_mux_mix_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[11]);
+
+/* Rx mux and mixer */
+static const snd_kcontrol_new_t wm8753_rx_mux_mix_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[15]);
+
+/* Mic Selector Mux */
+static const snd_kcontrol_new_t wm8753_mic_sel_mux_controls =
+SOC_DAPM_ENUM("Route", wm8753_enum[25]);
+
+static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
+SND_SOC_DAPM_CLOCK("WM8753 Clock", WM8753_PWR1, 0, 1),
+SND_SOC_DAPM_MUTE("DAC Mute", WM8753_DAC, 3, 0),
+SND_SOC_DAPM_MICBIAS("Mic Bias", WM8753_PWR1, 5, 0),
+SND_SOC_DAPM_MIXER("Left Mixer", WM8753_PWR4, 0, 0, &wm8753_left_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_left_mixer_controls)),
+SND_SOC_DAPM_VOLUME("Left Out 1", WM8753_PWR3, 8, 0, NULL, 0),	
+SND_SOC_DAPM_VOLUME("Left Out 2", WM8753_PWR3, 6, 0, NULL, 0),
+SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", WM8753_PWR1, 3, 0, NULL, 0),
+SND_SOC_DAPM_OUTPUT("LOUT1"),
+SND_SOC_DAPM_OUTPUT("LOUT2"),
+SND_SOC_DAPM_MIXER("Right Mixer", WM8753_PWR4, 1, 0, &wm8753_right_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_right_mixer_controls)),
+SND_SOC_DAPM_VOLUME("Right Out 1", WM8753_PWR3, 7, 0, NULL, 0),
+SND_SOC_DAPM_VOLUME("Right Out 2", WM8753_PWR3, 5, 0, NULL, 0),
+SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", WM8753_PWR1, 2, 0, NULL, 0),
+SND_SOC_DAPM_OUTPUT("ROUT1"),
+SND_SOC_DAPM_OUTPUT("ROUT2"),
+SND_SOC_DAPM_MIXER("Mono Mixer", WM8753_PWR4, 2, 0, &wm8753_mono_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_mono_mixer_controls)),
+SND_SOC_DAPM_VOLUME("Mono Out 1", WM8753_PWR3, 2, 0, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mono Out 2", WM8753_PWR3, 1, 0, NULL, 0),
+SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", WM8753_PWR1, 4, 0, NULL, 0),
+SND_SOC_DAPM_OUTPUT("MONO1"),
+SND_SOC_DAPM_MUX("Mono 2 Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8753_mono2_controls),
+SND_SOC_DAPM_OUTPUT("MONO2"),
+SND_SOC_DAPM_MIXER("Out3 Left + Right", -1, 0, 0, NULL, 0),
+SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8753_out3_controls),
+SND_SOC_DAPM_VOLUME("Out 3", WM8753_PWR3, 4, 0, NULL, 0),
+SND_SOC_DAPM_OUTPUT("OUT3"),
+SND_SOC_DAPM_MUX("Out4 Mux", SND_SOC_DAPM_NOPM, 0, 0, &wm8753_out4_controls),
+SND_SOC_DAPM_VOLUME("Out 4", WM8753_PWR3, 3, 0, NULL, 0),
+SND_SOC_DAPM_OUTPUT("OUT4"),
+SND_SOC_DAPM_MIXER("Playback Mixer", WM8753_PWR4, 3, 0, &wm8753_record_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_record_mixer_controls)),
+SND_SOC_DAPM_ADC("Left ADC", "Left Voice Capture", WM8753_PWR2, 3, 0, NULL, 0),
+SND_SOC_DAPM_ADC("Right ADC", "Right Voice Capture", WM8753_PWR2, 2, 0, NULL, 0),
+SND_SOC_DAPM_MUX("Capture Left Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_adc_mono_controls),
+SND_SOC_DAPM_MUX("Capture Right Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_adc_mono_controls),
+SND_SOC_DAPM_MUX("Capture Left Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_adc_left_controls),
+SND_SOC_DAPM_MUX("Capture Right Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_adc_right_controls),
+SND_SOC_DAPM_MUX("Mic Sidetone Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_mic_mux_controls),
+SND_SOC_DAPM_VOLUME("Left Capture Volume", WM8753_PWR2, 5, 0, NULL, 0),
+SND_SOC_DAPM_VOLUME("Right Capture Volume", WM8753_PWR2, 4, 0, NULL, 0),
+SND_SOC_DAPM_MIXER("ALC Mixer", WM8753_PWR2, 6, 0, &wm8753_alc_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_alc_mixer_controls)),
+SND_SOC_DAPM_MUX("Line Left Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_line_left_controls),
+SND_SOC_DAPM_MUX("Line Right Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_line_right_controls),
+SND_SOC_DAPM_MUX("Line Mono Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_line_mono_controls),
+SND_SOC_DAPM_MUX("Line Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_line_mux_mix_controls),
+SND_SOC_DAPM_MUX("Rx Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_rx_mux_mix_controls),
+SND_SOC_DAPM_VOLUME("Mic 1 Volume", WM8753_PWR2, 8, 0, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mic 2 Volume", WM8753_PWR2, 7, 0, NULL, 0),
+SND_SOC_DAPM_MUX("Mic Selection Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm8753_mic_sel_mux_controls),
+SND_SOC_DAPM_INPUT("LINE1"),
+SND_SOC_DAPM_INPUT("LINE2"),
+SND_SOC_DAPM_INPUT("RXP"),
+SND_SOC_DAPM_INPUT("RXN"),
+SND_SOC_DAPM_INPUT("ACIN"),
+SND_SOC_DAPM_INPUT("ACOP"),
+SND_SOC_DAPM_INPUT("MIC1N"),
+SND_SOC_DAPM_INPUT("MIC1"),
+SND_SOC_DAPM_INPUT("MIC2N"),
+SND_SOC_DAPM_INPUT("MIC2"),
+};
+
+static const char* intercon[][3] = {
+	/* left mixer */
+	{"Left Mixer", "Left Playback Switch", "Left DAC"},
+	{"Left Mixer", "Voice Playback Switch", "Voice DAC"},
+	{"Left Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
+	{"Left Mixer", "Bypass Playback Switch", "Line Left Mux"},
+	
+	/* right mixer */
+	{"Right Mixer", "Right Playback Switch", "Right DAC"},
+	{"Right Mixer", "Voice Playback Switch", "Voice DAC"},
+	{"Right Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
+	{"Right Mixer", "Bypass Playback Switch", "Line Right Mux"},
+	
+	/* mono mixer */
+	{"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
+	{"Mono Mixer", "Left Playback Switch", "Left DAC"},
+	{"Mono Mixer", "Right Playback Switch", "Right DAC"},
+	{"Mono Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"},
+	{"Mono Mixer", "Bypass Playback Switch", "Line Mono Mux"},
+	
+	/* left out */
+	{"Left Out 1", NULL, "Left Mixer"},
+	{"Left Out 2", NULL, "Left Mixer"},
+	{"LOUT1", NULL, "Left Out 1"},
+	{"LOUT2", NULL, "Left Out 2"},
+
+	/* right out */
+	{"Right Out 1", NULL, "Right Mixer"},
+	{"Right Out 2", NULL, "Right Mixer"},
+	{"ROUT1", NULL, "Right Out 1"},
+	{"ROUT2", NULL, "Right Out 2"},
+	
+	/* mono 1 out */
+	{"Mono Out 1", NULL, "Mono Mixer"},
+	{"MONO1", NULL, "Mono Out 1"},
+	
+	/* mono 2 out */
+	{"Mono 2 Mux", "Left + Right", "Out3 Left + Right"},
+	{"Mono 2 Mux", "Inverted Mono 1", "MONO1"},
+	{"Mono 2 Mux", "Left", "Left Mixer"},
+	{"Mono 2 Mux", "Right", "Right Mixer"},
+	{"Mono Out 2", NULL, "Mono 2 Mux"},
+	{"MONO2", NULL, "Mono Out 2"},
+	
+	/* out 3 */
+	{"Out3 Left + Right", NULL, "Left Mixer"},
+	{"Out3 Left + Right", NULL, "Right Mixer"},
+	{"Out3 Mux", "VREF", "VREF"},
+	{"Out3 Mux", "Left + Right", "Out3 Left + Right"},
+	{"Out3 Mux", "ROUT2", "ROUT2"},
+	{"Out 3", NULL, "Out3 Mux"},
+	{"OUT3", NULL, "Out 3"},
+	
+	/* out 4 */
+	{"Out4 Mux", "VREF", "VREF"},
+	{"Out4 Mux", "Capture ST", "Capture ST Mixer"},
+	{"Out4 Mux", "LOUT2", "LOUT2"},
+	{"Out 4", NULL, "Out4 Mux"},
+	{"OUT4", NULL, "Out 4"},
+	
+	/* record mixer  */
+	{"Playback Mixer", "Left Capture Switch", "Left Mixer"},
+	{"Playback Mixer", "Voice Capture Switch", "Mono Mixer"},
+	{"Playback Mixer", "Right Capture Switch", "Right Mixer"},
+	
+	/* Mic/SideTone Mux */
+	{"Mic Sidetone Mux", "Left PGA", "Left Capture Volume"},
+	{"Mic Sidetone Mux", "Right PGA", "Right Capture Volume"},
+	{"Mic Sidetone Mux", "Mic 1", "Mic 1 Volume"},
+	{"Mic Sidetone Mux", "Mic 2", "Mic 2 Volume"},
+	
+	/* Capture Left Mux */
+	{"Capture Left Mux", "PGA", "Left Capture Volume"},
+	{"Capture Left Mux", "Line or RXP-RXN", "Line Left Mux"},
+	{"Capture Left Mux", "Line", "LINE1"},
+	
+	/* Capture Right Mux */
+	{"Capture Right Mux", "PGA", "Right Capture Volume"},
+	{"Capture Right Mux", "Line or RXP-RXN", "Line Right Mux"},
+	{"Capture Right Mux", "Sidetone", "Capture ST Mixer"},
+	
+	/* Mono Capture mixer-mux */
+	{"Capture Right Mixer", "Stereo", "Capture Right Mux"},
+	{"Capture Left Mixer", "Analogue Mix Left", "Capture Left Mux"},
+	{"Capture Left Mixer", "Analogue Mix Left", "Capture Right Mux"},
+	{"Capture Right Mixer", "Analogue Mix Right", "Capture Left Mux"},
+	{"Capture Right Mixer", "Analogue Mix Right", "Capture Right Mux"},
+	{"Capture Left Mixer", "Digital Mono Mix", "Capture Left Mux"},
+	{"Capture Left Mixer", "Digital Mono Mix", "Capture Right Mux"},
+	{"Capture Right Mixer", "Digital Mono Mix", "Capture Left Mux"},
+	{"Capture Right Mixer", "Digital Mono Mix", "Capture Right Mux"},
+	
+	/* ADC */
+	{"Left ADC", NULL, "Capture Left Mixer"},
+	{"Right ADC", NULL, "Capture Right Mixer"},
+
+	/* Left Capture Volume */
+	{"Left Capture Volume", NULL, "ACIN"},
+	
+	/* Right Capture Volume */
+	{"Right Capture Volume", NULL, "Mic 2 Volume"},
+
+	/* ALC Mixer */
+	{"ALC Mixer", "Line Capture Switch", "Line Mixer"},
+	{"ALC Mixer", "Mic2 Capture Switch", "Mic 2 Volume"},
+	{"ALC Mixer", "Mic1 Capture Switch", "Mic 1 Volume"},
+	{"ALC Mixer", "Rx Capture Switch", "Rx Mixer"},
+	
+	/* Line Left Mux */
+	{"Line Left Mux", "Line 1", "LINE1"},
+	{"Line Left Mux", "Rx Mix", "Rx Mixer"},
+	
+	/* Line Right Mux */
+	{"Line Right Mux", "Line 2", "LINE2"},
+	{"Line Right Mux", "Rx Mix", "Rx Mixer"},
+	
+	/* Line Mono Mux */
+	{"Line Mono Mux", "Line Mix", "Line Mixer"},
+	{"Line Mono Mux", "Rx Mix", "Rx Mixer"},
+	
+	/* Line Mixer/Mux */
+	{"Line Mixer", "Line 1 + 2", "LINE1"},
+	{"Line Mixer", "Line 1 - 2", "LINE1"},
+	{"Line Mixer", "Line 1 + 2", "LINE2"},
+	{"Line Mixer", "Line 1 - 2", "LINE2"},
+	{"Line Mixer", "Line 1", "LINE1"},
+	{"Line Mixer", "Line 2", "LINE2"},
+	
+	/* Rx Mixer/Mux */
+	{"Rx Mixer", "RXP - RXN", "RXP"},
+	{"Rx Mixer", "RXP + RXN", "RXP"},
+	{"Rx Mixer", "RXP - RXN", "RXN"},
+	{"Rx Mixer", "RXP + RXN", "RXN"},
+	{"Rx Mixer", "RXP", "RXP"},
+	{"Rx Mixer", "RXN", "RXN"},
+	
+	/* Mic 1 Volume */
+	{"Mic 1 Volume", NULL, "MIC1N"},
+	{"Mic 1 Volume", NULL, "Mic Selection Mux"},
+	
+	/* Mic 2 Volume */
+	{"Mic 2 Volume", NULL, "MIC2N"},
+	{"Mic 2 Volume", NULL, "MIC2"},
+	
+	/* Mic Selector Mux */
+	{"Mic Selection Mux", "Mic 1", "MIC1"},
+	{"Mic Selection Mux", "Mic 2", "MIC2N"},
+	{"Mic Selection Mux", "Mic 3", "MIC2"},
+	
+	/* ACOP */
+	{"ACOP", NULL, "ALC Mixer"},
+	
+	/* terminator */
+	{NULL, NULL, NULL},
+};
+
+static int wm8753_add_widgets(struct snd_soc_codec *codec)
+{
+	int i;
+
+	for(i = 0; i < ARRAY_SIZE(wm8753_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &wm8753_dapm_widgets[i]);
+	}
+
+	/* set up audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+
+	snd_soc_dapm_new_widgets(codec);
+	return 0;
+}
+
+/* PLL divisors */
+struct _pll_div {
+	u32 mclk;	/* ext clock */
+	u32 hz;		/* pll out freq */
+	u32 n;
+	u32 k;
+};
+
+/* 
+ * PLL divisors -
+ */
+static const struct _pll_div pll_div[] = {
+   {13000000,	12288000,	0x7,    0x23F54A},
+   {13000000,	11289600,	0x6,    0x3CA2F5},	
+   {12000000,	12288000,	0x8,    0x0C49BA},
+   {12000000,	11289600,	0x7,    0x21B08A},
+   {12288000,	12288000,	0x0,    0x000000},
+   {12288000,	11289600,	0x7,	0x166667},
+   {0, 0, 0, 0}  /* must be last */
+};
+
+static u32 wm8753_config_pll(struct snd_soc_codec *codec, 
+	struct snd_soc_pcm_codec *pcm_codec, int pll, u32 speed)
+{
+	u16 reg;
+
+    if (pll == 1) {
+		reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xffef;
+        if (!speed || pll == pcm_codec->mclk) {
+            /* disable PLL1  */
+            wm8753_write(codec, WM8753_PLL1CTL1, 0x0026);
+			wm8753_write(codec, WM8753_CLOCK, reg);
+        } else {
+            u16 value = 0;
+            int i = 0;   
+       
+            /* if we cant match, then use good values for N and K */
+            for (;i < ARRAY_SIZE(pll_div); i++) {
+                if (pll_div[i].mclk == pcm_codec->mclk && pll_div[i].hz == speed)
+                    break;
+            }
+    
+            /* set up N and K PLL divisor ratios */
+            /* bits 8:5 = PLL_N, bits 3:0 = PLL_K[21:18] */
+            value = (pll_div[i].n << 5) + ((pll_div[i].k & 0x3c0000) >> 18);  
+            wm8753_write(codec, WM8753_PLL1CTL2, value);
+     
+            /* bits 8:0 = PLL_K[17:9] */
+            value = (pll_div[i].k & 0x03fe00) >> 9;
+            wm8753_write(codec, WM8753_PLL1CTL3, value);
+    
+            /* bits 8:0 = PLL_K[8:0] */
+            value = pll_div[i].k & 0x0001ff;
+            wm8753_write(codec, WM8753_PLL1CTL4, value);
+     
+            /* set PLL1 as input and enable */
+            wm8753_write(codec, WM8753_PLL1CTL1, 0x0027);
+			wm8753_write(codec, WM8753_CLOCK, reg | 0x0010);
+        }
+    } else {
+		reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfff7;
+        if (!speed || pll == pcm_codec->mclk) {
+            /* disable PLL2  */
+            wm8753_write(codec, WM8753_PLL2CTL1, 0x0026);
+			wm8753_write(codec, WM8753_CLOCK, reg);
+        } else {
+            u16 value = 0;
+            int i = 0;   
+       
+            /* if we cant match, then use good values for N and K */
+            for (;i < ARRAY_SIZE(pll_div); i++) {
+                if (pll_div[i].mclk == pcm_codec->mclk && pll_div[i].hz == speed)
+                    break;
+            }
+			
+            /* set up N and K PLL divisor ratios */
+            /* bits 8:5 = PLL_N, bits 3:0 = PLL_K[21:18] */
+            value = (pll_div[i].n << 5) + ((pll_div[i].k & 0x3c0000) >> 18);  
+            wm8753_write(codec, WM8753_PLL2CTL2, value);
+     
+            /* bits 8:0 = PLL_K[17:9] */
+            value = (pll_div[i].k & 0x03fe00) >> 9;
+            wm8753_write(codec, WM8753_PLL2CTL3, value);
+    
+            /* bits 8:0 = PLL_K[8:0] */
+            value = pll_div[i].k & 0x0001ff;
+            wm8753_write(codec, WM8753_PLL2CTL4, value);
+     
+            /* set PLL1 as input and enable */
+            wm8753_write(codec, WM8753_PLL2CTL1, 0x0027);
+			wm8753_write(codec, WM8753_CLOCK, reg | 0x0008);
+        }
+    }
+	return speed;
+}
+
+struct _coeff_div {
+	u32 mclk;
+	u32 rate;
+	u16 fs;
+	u16 coeff;
+};
+
+/* codec hifi mclk clock divider coefficients */
+static const struct _coeff_div coeff_div[] = {
+	{12288000, 32000, 384, 0x18},
+	{12288000, 48000, 256, 0x0},
+	{11289600, 44100, 256, 0x20},
+	{12288000, 96000, 128, 0x1c},
+	{11289600, 88200, 128, 0x3c},
+	{12288000, 8000, 1536, 0x0c},
+	{12288000, 16000, 768, 0x14},
+	{11289600, 11025, 1024, 0x30},
+	{11289600, 22050, 512, 0x34},
+};
+
+static int get_coeff(int mclk, int rate)
+{
+	int i;
+	
+	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
+		if (coeff_div[i].rate == rate)
+			return coeff_div[i].coeff;
+	}
+	return 0;
+}
+
+static int get_pll(int fs, int rate)
+{
+	int i;
+	
+	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
+		if (coeff_div[i].fs == fs && !(coeff_div[i].mclk % rate))
+			return coeff_div[i].mclk;
+	}
+	return 0;
+}
+
+static unsigned int wm8753_config_hsysclk(struct snd_soc_pcm_codec *pcm_codec, 
+	int rate, unsigned int clk)
+{	
+	switch(rate){
+	case 8000:
+	case 16000:
+	case 32000:
+	case 48000:
+	case 96000:
+		pcm_codec->mclk = clk;
+		return 12288000;
+	case 11025:
+	case 22050:
+	case 44100:
+	case 88200:
+		pcm_codec->mclk = clk;
+		return 11289600;
+	default:
+		pcm_codec->mclk = 0;
+	}
+	
+	return 0;	
+}
+
+static unsigned int wm8753_config_vsysclk(struct snd_soc_pcm_codec *pcm_codec, 
+	int rate, unsigned int clk)
+{
+	pcm_codec->mclk = clk;
+	return rate << 8;
+}
+
+static int wm8753_pcm_voice_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 voice = 0, ioctl, srate, srate2, fs, bfs;
+	unsigned int pll = 0;
+	
+	bfs = SND_SOC_FSBD_INT(rtd->pcm_c->hw_runtime.hwbfs);
+	fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+//printk("fs %d bfs %d\n", fs, bfs);	
+	/* set master/slave audio interface */
+	ioctl = wm8753_read_reg_cache(codec, WM8753_IOCTL) & 0x01f1;
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK) {
+		case SND_SOC_HWFMT_CBM_CFM:
+			ioctl |= 0x0002;
+		case SND_SOC_HWFMT_CBM_CFS:
+			voice |= 0x0040;
+			pll = fs * snd_soc_get_rate(rtd->pcm_c->hw_runtime.hwpcmrate);
+			break;
+		case SND_SOC_HWFMT_CBS_CFS:
+			pll = get_pll(fs, snd_soc_get_rate(rtd->pcm_c->hw_runtime.hwpcmrate));
+			break;
+	}
+	printk("pll %d rate %d\n", pll, snd_soc_get_rate(rtd->pcm_c->hw_runtime.hwpcmrate));
+	/* enable PLL */
+	if(wm8753_config_pll(codec, rtd->pcm_c, 2, pll) != pll) {
+		err("could not set pll to %d Hz", pll);
+		return -ENODEV;
+	}
+	
+	/* interface format */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+		case SND_SOC_HWFMT_I2S:
+			voice |= 0x0002;
+			break;
+		case SND_SOC_HWFMT_RIGHT_J:
+			break;
+		case SND_SOC_HWFMT_LEFT_J:
+			voice |= 0x0001;
+			break;
+		case SND_SOC_HWFMT_DSP_A:
+			voice |= 0x0003;
+			break;
+		case SND_SOC_HWFMT_DSP_B:
+			voice |= 0x0013;
+			break;
+	}
+	
+	/* bit size */
+	switch(rtd->pcm_c->hw_runtime.hwpcmfmt) {
+		case SNDRV_PCM_FORMAT_S16_LE:
+			break;
+		case SNDRV_PCM_FORMAT_S20_3LE:
+			voice |= 0x0004;
+			break;
+		case SNDRV_PCM_FORMAT_S24_3LE:
+			voice |= 0x0008;
+			break;
+		case SNDRV_PCM_FORMAT_S32_LE:
+			voice |= 0x000c;
+			break;
+	}
+	
+	/* set bclk divisor rate */
+	srate2 = wm8753_read_reg_cache(codec, WM8753_SRATE2) & 0x003f;
+	switch (bfs) {
+		case 1:
+			break;
+		case 2:
+			srate2 |= (0x1 << 6);
+			break;
+		case 4:
+			srate2 |= (0x2 << 6);
+			break;
+		case 8:
+			srate2 |= (0x3 << 6);
+			break;
+		case 16:
+			srate2 |= (0x4 << 6);
+			break;
+	}		
+	wm8753_write(codec, WM8753_SRATE2, srate2);
+
+	srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f;
+	if(rtd->pcm_c->hw_runtime.hwfs & SND_SOC_FS(384))
+		srate |= 0x80;
+	wm8753_write(codec, WM8753_SRATE1, srate);
+	
+	/* clock inversion */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK) {
+		case SND_SOC_HWFMT_IB_IF:
+			voice |= 0x0090;
+			break;
+		case SND_SOC_HWFMT_IB_NF:
+			voice |= 0x0080;
+			break;
+		case SND_SOC_HWFMT_NB_IF:
+			voice |= 0x0010;
+			break;
+	}
+//printk("voice %x %x ioctl %x %x srate2 %x %x srate1 %x %x\n", 
+//	WM8753_PCM, voice, WM8753_IOCTL, ioctl, WM8753_SRATE2, srate2, WM8753_SRATE1, srate);	
+	wm8753_write(codec, WM8753_IOCTL, ioctl);
+	wm8753_write(codec, WM8753_PCM, voice);
+	return 0;
+}
+
+static int wm8753_pcm_hifi_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 hifi = 0, ioctl, srate, coeff = 0, fs, bfs;
+	unsigned int pll = 0, rate;
+	
+	bfs = SND_SOC_FSBD_INT(rtd->pcm_c->hw_runtime.hwbfs);
+	fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+	rate = snd_soc_get_rate(rtd->pcm_c->hw_runtime.hwpcmrate);
+	
+	/* set master/slave audio interface */
+	ioctl = wm8753_read_reg_cache(codec, WM8753_IOCTL) & 0x00f2;
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK) {
+		case SND_SOC_HWFMT_CBM_CFM:
+			ioctl |= 0x0001;
+		case SND_SOC_HWFMT_CBM_CFS:
+			hifi |= 0x0040;
+			pll = fs * rate;
+			break;
+		case SND_SOC_HWFMT_CBS_CFS:
+			pll = get_pll(fs, rate);
+			break;
+	}
+	coeff = get_coeff(pll, rate);
+
+	/* enable PLL */
+	if(wm8753_config_pll(codec, rtd->pcm_c, 1, pll) != pll) {
+		err("could not set pll to %d Hz", pll);
+		return -ENODEV;
+	}
+	
+	/* interface format */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+		case SND_SOC_HWFMT_I2S:
+			hifi |= 0x0002;
+			break;
+		case SND_SOC_HWFMT_RIGHT_J:
+			break;
+		case SND_SOC_HWFMT_LEFT_J:
+			hifi |= 0x0001;
+			break;
+		case SND_SOC_HWFMT_DSP_A:
+			hifi |= 0x0003;
+			break;
+		case SND_SOC_HWFMT_DSP_B:
+			hifi |= 0x0013;
+			break;
+	}
+	
+	/* bit size */
+	switch(rtd->pcm_c->hw_runtime.hwpcmfmt) {
+		case SNDRV_PCM_FORMAT_S16_LE:
+			break;
+		case SNDRV_PCM_FORMAT_S20_3LE:
+			hifi |= 0x0004;
+			break;
+		case SNDRV_PCM_FORMAT_S24_3LE:
+			hifi |= 0x0008;
+			break;
+		case SNDRV_PCM_FORMAT_S32_LE:
+			hifi |= 0x000c;
+			break;
+	}
+
+	/* set bclk divisor rate */
+	srate = wm8753_read_reg_cache(codec, WM8753_SRATE2) & 0x01c7;
+	if(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CBM_CFM || 
+		rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CBM_CFS) {
+		switch (bfs) {
+		case 1:
+			break;
+		case 2:
+			srate |= (0x1 << 3);
+			break;
+		case 4:
+			srate |= (0x2 << 3);
+			break;
+		case 8:
+			srate |= (0x3 << 3);
+			break;
+		case 16:
+			srate |= (0x4 << 3);
+			break;
+		}
+	}
+			
+	wm8753_write(codec, WM8753_SRATE2, srate);
+	wm8753_write(codec, WM8753_SRATE1, coeff);
+	
+	/* clock inversion */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK) {
+		case SND_SOC_HWFMT_IB_IF:
+			hifi |= 0x0090;
+			break;
+		case SND_SOC_HWFMT_IB_NF:
+			hifi |= 0x0080;
+			break;
+		case SND_SOC_HWFMT_NB_IF:
+			hifi |= 0x0010;
+			break;
+	}
+	wm8753_write(codec, WM8753_IOCTL, ioctl | 0x0008);
+	wm8753_write(codec, WM8753_HIFI, hifi);
+	return 0;
+}
+
+static int wm8753_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	u16 pwr_reg = wm8753_read_reg_cache(codec, WM8753_PWR1) & 0xfe3f;
+
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			/* set vmid to 50k and unmute dac */
+			wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x00c0);
+			break;
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			/* set vmid to 5k for quick power up */
+			wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x01c0);
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* mute dac and set vmid to 500k, enable VREF */
+			wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x0140);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			wm8753_write(codec, WM8753_PWR1, 0x0001);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static struct snd_soc_pcm_codec wm8753_pcm_clients[] = {
+{	.name = "WM8753 Voice",
+	.playback = {
+		.sname = "Voice Playback",
+		.channels_min = 1,
+		.channels_max = 1,},
+	.capture = {
+		.sname = "Voice Capture",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.nplayback = 1,
+	.ncapture = 1,
+	.config_sysclk = wm8753_config_vsysclk,
+	.ops = {
+		.prepare = wm8753_pcm_voice_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8753_voice),
+		.hmodes = &wm8753_voice[0],
+		},},
+{	.name = "WM8753 HiFi",
+	.playback = {
+		.sname = "HiFi Playback",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.nplayback = 1,
+	.config_sysclk = wm8753_config_hsysclk,
+	.ops = {
+		.prepare = wm8753_pcm_hifi_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8753_hifi),
+		.hmodes = &wm8753_hifi[0],},},
+};
+
+static void wm8753_work(void *data)
+{
+	struct snd_soc_codec *codec = (struct snd_soc_codec *)data;
+	wm8753_dapm_event(codec, codec->dapm_state);
+}
+
+static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int wm8753_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+	u8 data[2];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) {
+		if (i + 1 == WM8753_RESET)
+			continue;
+		data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001);
+		data[1] = cache[i] & 0x00ff;
+		codec->hw_write(codec->control_data, data, 2);
+	}
+	
+	wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+		
+	/* charge wm8753 caps */
+	if(codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
+		wm8753_dapm_event(codec, SNDRV_CTL_POWER_D2);
+		codec->dapm_state = SNDRV_CTL_POWER_D0;
+		queue_delayed_work(wm8753_workq, &wm8753_dapm_work, msecs_to_jiffies(1000));
+	}
+	
+	return 0;
+}
+
+/*
+ * initialise the WM8753 driver
+ * register the mixer and dsp interfaces with the kernel 
+ */
+static int wm8753_init(struct snd_soc_device* socdev)
+{
+	struct snd_soc_codec* codec = socdev->codec;
+	int reg, ret = 0;
+
+	codec->name = "WM8753";
+	codec->owner = THIS_MODULE;
+	codec->read = wm8753_read_reg_cache;
+	codec->write = wm8753_write;
+	codec->dapm_event = wm8753_dapm_event;
+	codec->pcms = wm8753_pcm_clients;
+	codec->npcms = 2;
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(wm8753_reg), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	memcpy(codec->reg_cache, wm8753_reg, sizeof(u16) * ARRAY_SIZE(wm8753_reg));
+	
+	wm8753_reset(codec);
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0) {
+		kfree(codec->reg_cache);
+		return ret;
+	}
+
+	/* charge output caps */
+	wm8753_dapm_event(codec, SNDRV_CTL_POWER_D2);
+	codec->dapm_state = SNDRV_CTL_POWER_D3hot;
+	queue_delayed_work(wm8753_workq, &wm8753_dapm_work, msecs_to_jiffies(1000));
+
+	/* set the update bits */
+	reg = wm8753_read_reg_cache(codec, WM8753_LDAC);
+	wm8753_write(codec, WM8753_LDAC, reg | 0x0100);
+	reg = wm8753_read_reg_cache(codec, WM8753_RDAC);
+	wm8753_write(codec, WM8753_RDAC, reg | 0x0100);
+	reg = wm8753_read_reg_cache(codec, WM8753_LOUT1V);
+	wm8753_write(codec, WM8753_LOUT1V, reg | 0x0100);
+	reg = wm8753_read_reg_cache(codec, WM8753_ROUT1V);
+	wm8753_write(codec, WM8753_ROUT1V, reg | 0x0100);
+	reg = wm8753_read_reg_cache(codec, WM8753_LOUT2V);
+	wm8753_write(codec, WM8753_LOUT2V, reg | 0x0100);
+	reg = wm8753_read_reg_cache(codec, WM8753_ROUT2V);
+	wm8753_write(codec, WM8753_ROUT2V, reg | 0x0100);
+	reg = wm8753_read_reg_cache(codec, WM8753_LINVOL);
+	wm8753_write(codec, WM8753_LINVOL, reg | 0x0100);
+	reg = wm8753_read_reg_cache(codec, WM8753_RINVOL);
+	wm8753_write(codec, WM8753_RINVOL, reg | 0x0100);
+
+	wm8753_add_controls(codec);
+	wm8753_add_widgets(codec);
+	snd_soc_register_card(socdev);
+
+	return ret;
+}
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+static struct snd_soc_device *wm8753_socdev;
+
+#ifdef CONFIG_I2C
+
+/*
+ * WM8753 2 wire address is determined by GPIO5
+ * state during powerup.
+ *    low  = 0x1a
+ *    high = 0x1b
+ */
+#define I2C_DRIVERID_WM8753 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver wm8753_i2c_driver;
+static struct i2c_client client_template;
+
+static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+	struct snd_soc_device *socdev = wm8753_socdev;
+	struct wm8753_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec = socdev->codec;
+	struct i2c_client *i2c;
+	int ret;
+
+	if (addr != setup->i2c_address)
+		return -ENODEV;
+
+	client_template.adapter = adap;
+	client_template.addr = addr;
+
+	if ((i2c = kzalloc(sizeof(struct i2c_client), GFP_KERNEL)) == NULL){
+		kfree(codec);
+		return -ENOMEM;
+	}
+	memcpy(i2c, &client_template, sizeof(struct i2c_client));
+
+	i2c_set_clientdata(i2c, codec);
+
+	codec->control_data = i2c;
+
+	if((ret = i2c_attach_client(i2c)) < 0) {
+		err("failed to attach codec at addr %x\n", addr);
+		kfree(i2c);
+		return ret;
+	}
+
+	wm8753_init(socdev);
+
+	return 0;
+}
+
+static int wm8753_i2c_detach(struct i2c_client *client)
+{
+	struct snd_soc_codec* codec = i2c_get_clientdata(client);
+
+	i2c_detach_client(client);
+	kfree(codec->reg_cache);
+	kfree(client);
+
+	return 0;
+}
+
+static int wm8753_i2c_attach(struct i2c_adapter *adap)
+{
+	return i2c_probe(adap, &addr_data, wm8753_codec_probe);
+}
+
+/* corgi i2c codec control layer */
+static struct i2c_driver wm8753_i2c_driver = {
+	.driver = {
+		.name = "WM8753 I2C Codec",
+		.owner = THIS_MODULE,
+	},
+	.id =             I2C_DRIVERID_WM8753,
+	.attach_adapter = wm8753_i2c_attach,
+	.detach_client =  wm8753_i2c_detach,
+	.command =        NULL,
+};
+
+static struct i2c_client client_template = {
+	.name =   "WM8753",
+	.driver = &wm8753_i2c_driver,
+};
+#endif
+
+static int wm8753_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct wm8753_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	info("WM8753 Audio Codec %s", WM8753_VERSION);
+
+	if ((codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+
+	socdev->codec = codec;
+	
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+	wm8753_socdev = socdev;
+	INIT_WORK(&wm8753_dapm_work, wm8753_work, codec);
+	if((wm8753_workq = create_workqueue("wm8753")) == NULL) {
+		kfree(codec);
+		return -ENOMEM;
+	}
+#ifdef CONFIG_I2C	
+	if (setup->i2c_address) {
+		normal_i2c[0] = setup->i2c_address;
+		codec->hw_write = (hw_write_t)i2c_master_send;
+		if ((ret = i2c_add_driver(&wm8753_i2c_driver)) != 0)
+			printk(KERN_ERR "can't add i2c driver");
+	}
+#else
+		/* Add other interfaces here */
+#endif
+	return ret;
+}
+
+/* power down chip */
+static int wm8753_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	if (codec->control_data)
+		wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	if(wm8753_workq)
+		destroy_workqueue(wm8753_workq);
+	snd_soc_free_pcms(socdev);
+	snd_soc_dapm_free(socdev);
+#ifdef CONFIG_I2C
+	i2c_del_driver(&wm8753_i2c_driver);
+#endif
+	kfree(codec);
+
+	return 0;
+}
+
+
+struct snd_soc_codec_device soc_codec_dev_wm8753 = {
+	.probe = 	wm8753_probe,
+	.remove = 	wm8753_remove,
+	.suspend = 	wm8753_suspend,
+	.resume =	wm8753_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753);
+
+MODULE_DESCRIPTION("Soc WM8753 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8753.h b/sound/soc/codecs/wm8753.h
new file mode 100644
index 0000000..522bd79
--- /dev/null
+++ b/sound/soc/codecs/wm8753.h
@@ -0,0 +1,87 @@
+/*
+ * wm8753.h  --  audio driver for WM8753
+ *
+ * Copyright 2003 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef _WM8753_H
+#define _WM8753_H
+
+/* WM8753 register space */
+
+#define WM8753_DAC		0x01
+#define WM8753_ADC		0x02
+#define WM8753_PCM		0x03
+#define WM8753_HIFI		0x04
+#define WM8753_IOCTL	0x05
+#define WM8753_SRATE1	0x06
+#define WM8753_SRATE2	0x07
+#define WM8753_LDAC		0x08
+#define WM8753_RDAC		0x09
+#define WM8753_BASS		0x0a
+#define WM8753_TREBLE	0x0b
+#define WM8753_ALC1		0x0c
+#define WM8753_ALC2		0x0d
+#define WM8753_ALC3		0x0e
+#define WM8753_NGATE	0x0f
+#define WM8753_LADC		0x10
+#define WM8753_RADC		0x11
+#define WM8753_ADCTL1	0x12
+#define WM8753_3D		0x13
+#define WM8753_PWR1		0x14
+#define WM8753_PWR2		0x15
+#define WM8753_PWR3		0x16
+#define WM8753_PWR4		0x17
+#define WM8753_ID		0x18
+#define WM8753_INTPOL	0x19
+#define WM8753_INTEN	0x1a
+#define WM8753_GPIO1	0x1b
+#define WM8753_GPIO2	0x1c
+#define WM8753_RESET	0x1f
+#define WM8753_RECMIX1	0x20
+#define WM8753_RECMIX2	0x21
+#define WM8753_LOUTM1	0x22
+#define WM8753_LOUTM2	0x23
+#define WM8753_ROUTM1	0x24
+#define WM8753_ROUTM2	0x25
+#define WM8753_MOUTM1	0x26
+#define WM8753_MOUTM2	0x27
+#define WM8753_LOUT1V	0x28
+#define WM8753_ROUT1V	0x29
+#define WM8753_LOUT2V	0x2a
+#define WM8753_ROUT2V	0x2b
+#define WM8753_MOUTV	0x2c
+#define WM8753_OUTCTL	0x2d
+#define WM8753_ADCIN	0x2e
+#define WM8753_INCTL1	0x2f
+#define WM8753_INCTL2	0x30
+#define WM8753_LINVOL	0x31
+#define WM8753_RINVOL	0x32
+#define WM8753_MICBIAS	0x33
+#define WM8753_CLOCK	0x34
+#define WM8753_PLL1CTL1	0x35
+#define WM8753_PLL1CTL2	0x36
+#define WM8753_PLL1CTL3	0x37
+#define WM8753_PLL1CTL4	0x38
+#define WM8753_PLL2CTL1	0x39
+#define WM8753_PLL2CTL2	0x3a
+#define WM8753_PLL2CTL3	0x3b
+#define WM8753_PLL2CTL4	0x3c
+#define WM8753_BIASCTL	0x3d
+#define WM8753_ADCTL2	0x3f
+
+struct wm8753_setup_data {
+	unsigned short i2c_address;
+};
+
+extern struct snd_soc_codec_device soc_codec_dev_wm8753;
+
+#endif
diff --git a/sound/soc/codecs/wm8772.c b/sound/soc/codecs/wm8772.c
new file mode 100644
index 0000000..3f214d1
--- /dev/null
+++ b/sound/soc/codecs/wm8772.c
@@ -0,0 +1,578 @@
+/*
+ * wm8772.c  --  WM8772 ALSA Soc Audio driver
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+ 
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include "wm8772.h"
+
+#define AUDIO_NAME "WM8772"
+#define WM8772_VERSION "0.3"
+	
+/*
+ * wm8772 register cache
+ * We can't read the WM8772 register space when we 
+ * are using 2 wire for device control, so we cache them instead. 
+ */
+static const u16 wm8772_reg[] = {
+	0x00ff, 0x00ff, 0x0120, 0x0000,  /*  0 */
+	0x00ff, 0x00ff, 0x00ff, 0x00ff,  /*  4 */
+	0x00ff, 0x0000, 0x0080, 0x0040,  /*  8 */
+	0x0000
+};
+
+#define WM8772_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	 SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_IB_NF)
+
+#define WM8772_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+
+#define WM8772_PRATES \
+	(SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
+	 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
+	 
+#define WM8772_CRATES \
+	(SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
+	 SNDRV_PCM_RATE_96000)
+
+static struct snd_soc_hw_mode wm8772_hwfmt[] = {
+	/* common codec frame and clock master modes */
+	{WM8772_HWFMT | SND_SOC_HWFMT_CBM_CFM, SND_SOC_HWTDM_LRDW(0,0),
+		SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_32000, WM8772_DIR, 
+		0, SND_SOC_FS(768) | SND_SOC_FS(512) | SND_SOC_FS(384) |
+		SND_SOC_FS(256) | SND_SOC_FS(192) | SND_SOC_FS(128), SND_SOC_FSB(64)},
+	{WM8772_HWFMT | SND_SOC_HWFMT_CBM_CFM, SND_SOC_HWTDM_LRDW(0,0),
+		SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_44100, WM8772_DIR, 
+		0, SND_SOC_FS(768) | SND_SOC_FS(512) | SND_SOC_FS(384) |
+		SND_SOC_FS(256) | SND_SOC_FS(192) | SND_SOC_FS(128), SND_SOC_FSB(64)},
+	{WM8772_HWFMT | SND_SOC_HWFMT_CBM_CFM, SND_SOC_HWTDM_LRDW(0,0),
+		SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_48000, WM8772_DIR, 
+		0, SND_SOC_FS(768) | SND_SOC_FS(512) | SND_SOC_FS(384) |
+		SND_SOC_FS(256) | SND_SOC_FS(192) | SND_SOC_FS(128), SND_SOC_FSB(64)},
+	{WM8772_HWFMT | SND_SOC_HWFMT_CBM_CFM, SND_SOC_HWTDM_LRDW(0,0),
+		SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_96000, WM8772_DIR, 
+		0, SND_SOC_FS(384) | SND_SOC_FS(256) | SND_SOC_FS(192) | 
+		SND_SOC_FS(128), SND_SOC_FSB(64)},
+	{WM8772_HWFMT | SND_SOC_HWFMT_CBM_CFM, SND_SOC_HWTDM_LRDW(0,0),
+		SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_192000, SND_SOC_HWDIR_PLAYBACK, 
+		0, SND_SOC_FS(192) | SND_SOC_FS(128), SND_SOC_FSB(64)},
+		
+	/* slave mode */
+	{WM8772_HWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		WM8772_PRATES, SND_SOC_HWDIR_PLAYBACK, 0, SND_SOC_FS_ALL, SND_SOC_FSB_ALL},
+	{WM8772_HWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		WM8772_CRATES, SND_SOC_HWDIR_CAPTURE, 0, SND_SOC_FS_ALL, SND_SOC_FSB_ALL},
+};
+
+/*
+ * read wm8772 register cache
+ */
+static inline unsigned int wm8772_read_reg_cache(struct snd_soc_codec * codec, 
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg > WM8772_CACHE_REGNUM)
+		return -1;
+	return cache[reg];
+}
+
+/*
+ * write wm8772 register cache
+ */
+static inline void wm8772_write_reg_cache(struct snd_soc_codec * codec, 
+	unsigned int reg, unsigned int value)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg > WM8772_CACHE_REGNUM)
+		return;
+	cache[reg] = value;
+}
+
+static int wm8772_write(struct snd_soc_codec * codec, unsigned int reg, 
+	unsigned int value)
+{
+	u8 data[2];
+
+	/* data is 
+	 *   D15..D9 WM8772 register offset
+	 *   D8...D0 register data
+	 */
+	data[0] = (reg << 1) | ((value >> 8) & 0x0001);
+	data[1] = value & 0x00ff;
+
+	wm8772_write_reg_cache (codec, reg, value);
+	if (codec->hw_write(codec->control_data, data, 2) == 2)
+		return 0;
+	else
+		return -1;
+}
+
+#define wm8772_reset(c)	wm8772_write(c, WM8772_RESET, 0)
+
+/*
+ * WM8772 Controls
+ */
+static const char* wm8772_zero_flag[] = {"All Ch", "Ch 1", "Ch 2", "Ch3"};
+
+static const struct soc_enum wm8772_enum[] = {
+SOC_ENUM_SINGLE(WM8772_DACCTRL, 0, 4, wm8772_zero_flag),
+};
+
+static const snd_kcontrol_new_t wm8772_snd_controls[] = {
+
+SOC_SINGLE("Left1 Playback Volume", WM8772_LDAC1VOL, 0, 255, 0),
+SOC_SINGLE("Left2 Playback Volume", WM8772_LDAC2VOL, 0, 255, 0),
+SOC_SINGLE("Left3 Playback Volume", WM8772_LDAC3VOL, 0, 255, 0),
+SOC_SINGLE("Right1 Playback Volume", WM8772_RDAC1VOL, 0, 255, 0),
+SOC_SINGLE("Right1 Playback Volume", WM8772_RDAC2VOL, 0, 255, 0),
+SOC_SINGLE("Right1 Playback Volume", WM8772_RDAC3VOL, 0, 255, 0),
+SOC_SINGLE("Master Playback Volume", WM8772_MDACVOL, 0, 255, 0),
+
+SOC_SINGLE("Playback Switch", WM8772_DACCH, 0, 1, 0),
+SOC_SINGLE("Capture Switch", WM8772_ADCCTRL, 2, 1, 0),
+	
+SOC_SINGLE("Demp1 Playback Switch", WM8772_DACCTRL, 6, 1, 0),
+SOC_SINGLE("Demp2 Playback Switch", WM8772_DACCTRL, 7, 1, 0),
+SOC_SINGLE("Demp3 Playback Switch", WM8772_DACCTRL, 8, 1, 0),
+
+SOC_SINGLE("Phase Invert 1 Switch", WM8772_IFACE, 6, 1, 0),
+SOC_SINGLE("Phase Invert 2 Switch", WM8772_IFACE, 7, 1, 0),
+SOC_SINGLE("Phase Invert 3 Switch", WM8772_IFACE, 8, 1, 0),
+	
+SOC_SINGLE("Playback ZC Switch", WM8772_DACCTRL, 0, 1, 0),
+
+SOC_SINGLE("Capture High Pass Switch", WM8772_ADCCTRL, 3, 1, 0),
+};
+
+/* add non dapm controls */
+static int wm8772_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(wm8772_snd_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm8772_snd_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	return 0;
+}
+
+/* valid wm8772 mclk frequencies */
+static const int freq_table[5][6] = {
+	{4096000, 6144000, 8192000, 12288000, 16384000, 24576000},
+	{5644800, 8467000, 11289600, 16934000, 22579200, 33868800},
+	{6144000, 9216000, 12288000, 18432000, 24576000, 36864000},
+	{12288000, 18432000, 24576000, 36864000, 0, 0},
+	{24576000, 36864000, 0, 0, 0},
+};
+
+static unsigned int check_freq(int rate, unsigned int freq)
+{
+	int i;
+	
+	for(i = 0; i < 6; i++) {
+		if(freq == freq_table[i][rate])
+			return freq;
+	}
+	return 0;
+}
+
+static unsigned int wm8772_config_sysclk(struct snd_soc_pcm_codec *pcm_codec, 
+	int rate, unsigned int clk)
+{
+	switch(rate){
+	case 32000:
+		pcm_codec->mclk = check_freq(0, clk);
+		break;
+	case 44100:
+		pcm_codec->mclk = check_freq(1, clk);
+		break;
+	case 48000:
+		pcm_codec->mclk = check_freq(2, clk);
+		break;
+	case 96000:
+		pcm_codec->mclk = check_freq(3, clk);
+		break;
+	case 192000:
+		pcm_codec->mclk = check_freq(4, clk);
+		break;
+	default:
+		pcm_codec->mclk = 0;
+	}
+	return pcm_codec->mclk;
+}
+
+static int wm8772_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 diface = wm8772_read_reg_cache(codec, WM8772_IFACE) & 0xffc0;
+	u16 diface_ctrl = wm8772_read_reg_cache(codec, WM8772_DACRATE) & 0xfe1f;
+	u16 aiface = 0;
+	u16 aiface_ctrl = wm8772_read_reg_cache(codec, WM8772_ADCCTRL) & 0xfcff;
+	int fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+		
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		
+		/* set master/slave audio interface */
+		switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK) {
+			case SND_SOC_HWFMT_CBM_CFM:
+				diface_ctrl |= 0x0010;
+				break;
+			case SND_SOC_HWFMT_CBS_CFS:
+				break;
+		}
+		
+		/* interface format */
+		switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+			case SND_SOC_HWFMT_I2S:
+				diface |= 0x0002;
+				break;
+			case SND_SOC_HWFMT_RIGHT_J:
+				break;
+			case SND_SOC_HWFMT_LEFT_J:
+				diface |= 0x0001;
+				break;
+			case SND_SOC_HWFMT_DSP_A:
+				diface |= 0x0003;
+				break;
+			case SND_SOC_HWFMT_DSP_B:
+				diface |= 0x0007;
+				break;
+		}
+			
+		/* bit size */
+		switch(rtd->pcm_c->hw_runtime.hwpcmfmt) {
+			case SNDRV_PCM_FORMAT_S16_LE:
+				break;
+			case SNDRV_PCM_FORMAT_S20_3LE:
+				diface |= 0x0010;
+				break;
+			case SNDRV_PCM_FORMAT_S24_3LE:
+				diface |= 0x0020;
+				break;
+			case SNDRV_PCM_FORMAT_S32_LE:
+				diface |= 0x0030;
+				break;
+		}
+	
+		/* clock inversion */
+		switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK) {
+			case SND_SOC_HWFMT_NB_NF:
+				break;
+			case SND_SOC_HWFMT_IB_NF:
+				diface |= 0x0008;
+				break;
+		}
+		
+		/* set rate */
+		switch(fs) {
+		case 768:
+			diface_ctrl |= (0x5 << 6);
+			break;
+		case 512:
+			diface_ctrl |= (0x4 << 6);
+			break;
+		case 384:
+			diface_ctrl |= (0x3 << 6);
+			break;
+		case 256:
+			diface_ctrl |= (0x2 << 6);
+			break;
+		case 192:
+			diface_ctrl |= (0x1 << 6);
+			break;
+		}
+		
+		wm8772_write(codec, WM8772_DACRATE, diface_ctrl);
+		wm8772_write(codec, WM8772_IFACE, diface);
+		
+	} else {
+		
+		/* set master/slave audio interface */
+		switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK) {
+			case SND_SOC_HWFMT_CBM_CFM:
+				aiface |= 0x0010;
+				break;
+			case SND_SOC_HWFMT_CBS_CFS:
+				break;
+		}
+		
+		/* interface format */
+		switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+			case SND_SOC_HWFMT_I2S:
+				aiface |= 0x0002;
+				break;
+			case SND_SOC_HWFMT_RIGHT_J:
+				break;
+			case SND_SOC_HWFMT_LEFT_J:
+				aiface |= 0x0001;
+				break;
+			case SND_SOC_HWFMT_DSP_A:
+				aiface |= 0x0003;
+				break;
+			case SND_SOC_HWFMT_DSP_B:
+				aiface |= 0x0003;
+				aiface_ctrl |= 0x0010;
+				break;
+		}
+			
+		/* bit size */
+		switch(rtd->pcm_c->hw_runtime.hwpcmfmt) {
+			case SNDRV_PCM_FORMAT_S16_LE:
+				break;
+			case SNDRV_PCM_FORMAT_S20_3LE:
+				aiface |= 0x0004;
+				break;
+			case SNDRV_PCM_FORMAT_S24_3LE:
+				aiface |= 0x0008;
+				break;
+			case SNDRV_PCM_FORMAT_S32_LE:
+				aiface |= 0x000c;
+				break;
+		}
+	
+		/* clock inversion */
+		switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK) {
+			case SND_SOC_HWFMT_NB_NF:
+				break;
+			case SND_SOC_HWFMT_IB_NF:
+				aiface_ctrl |= 0x0020;
+				break;
+		}
+		
+		/* set rate */
+		switch(fs) {
+		case 768:
+			aiface |= (0x5 << 5);
+			break;
+		case 512:
+			aiface |= (0x4 << 5);
+			break;
+		case 384:
+			aiface |= (0x3 << 5);
+			break;
+		case 256:
+			aiface |= (0x2 << 5);
+			break;
+		}
+		
+		wm8772_write(codec, WM8772_ADCCTRL, aiface_ctrl);
+		wm8772_write(codec, WM8772_ADCRATE, aiface);
+	}
+
+	return 0;
+}
+
+static int wm8772_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	u16 master = wm8772_read_reg_cache(codec, WM8772_DACRATE) & 0xffe0;
+	
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			/* vref/mid, clk and osc on, dac unmute, active */
+			wm8772_write(codec, WM8772_DACRATE, master);
+			break;
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* everything off except vref/vmid, dac mute, inactive */
+			wm8772_write(codec, WM8772_DACRATE, master | 0x0f);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			/* everything off, dac mute, inactive */
+			wm8772_write(codec, WM8772_DACRATE, master | 0x1f);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static struct snd_soc_pcm_codec wm8772_pcm_client = {
+	.name = "WM8772",
+	.playback = {
+		.sname = "Playback",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.nplayback = 3,
+	.capture = {
+		.sname = "Capture",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.ncapture = 1,
+	.config_sysclk = wm8772_config_sysclk,
+	.ops = {
+		.prepare = wm8772_pcm_prepare,
+	},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8772_hwfmt),
+		.hmodes = &wm8772_hwfmt[0],
+	},
+};
+
+static int wm8772_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	wm8772_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int wm8772_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+	u8 data[2];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (i = 0; i < ARRAY_SIZE(wm8772_reg); i++) {
+		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
+		data[1] = cache[i] & 0x00ff;
+		codec->hw_write(codec->control_data, data, 2);
+	}
+	wm8772_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	wm8772_dapm_event(codec, codec->suspend_dapm_state);
+	return 0;
+}
+
+/*
+ * initialise the WM8772 driver
+ * register the mixer and dsp interfaces with the kernel 
+ */
+static int wm8772_init(struct snd_soc_device* socdev)
+{
+	struct snd_soc_codec* codec = socdev->codec;
+	int reg, ret = 0;
+
+	codec->name = "WM8772";
+	codec->owner = THIS_MODULE;
+	codec->read = wm8772_read_reg_cache;
+	codec->write = wm8772_write;
+	codec->dapm_event = wm8772_dapm_event;
+	codec->pcms = &wm8772_pcm_client;
+	codec->npcms = 1;
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(wm8772_reg), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	memcpy(codec->reg_cache, wm8772_reg, sizeof(u16) * ARRAY_SIZE(wm8772_reg));
+	
+	wm8772_reset(codec);
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0) {
+		kfree(codec->reg_cache);
+		return ret;
+	}
+	
+	/* power on device */
+	wm8772_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	
+	/* set the update bits */
+	reg = wm8772_read_reg_cache(codec, WM8772_MDACVOL);
+	wm8772_write(codec, WM8772_MDACVOL, reg | 0x0100);
+	reg = wm8772_read_reg_cache(codec, WM8772_LDAC1VOL);
+	wm8772_write(codec, WM8772_LDAC1VOL, reg | 0x0100);
+	reg = wm8772_read_reg_cache(codec, WM8772_LDAC2VOL);
+	wm8772_write(codec, WM8772_LDAC2VOL, reg | 0x0100);
+	reg = wm8772_read_reg_cache(codec, WM8772_LDAC3VOL);
+	wm8772_write(codec, WM8772_LDAC3VOL, reg | 0x0100);
+	reg = wm8772_read_reg_cache(codec, WM8772_RDAC1VOL);
+	wm8772_write(codec, WM8772_RDAC1VOL, reg | 0x0100);
+	reg = wm8772_read_reg_cache(codec, WM8772_RDAC2VOL);
+	wm8772_write(codec, WM8772_RDAC2VOL, reg | 0x0100);
+	reg = wm8772_read_reg_cache(codec, WM8772_RDAC3VOL);
+	wm8772_write(codec, WM8772_RDAC3VOL, reg | 0x0100);
+
+	wm8772_add_controls(codec);
+	snd_soc_register_card(socdev);
+	
+	return 0;
+}
+
+static struct snd_soc_device *wm8772_socdev;
+
+static int wm8772_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct wm8772_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	printk(KERN_INFO "WM8772 Audio Codec %s", WM8772_VERSION);
+
+	if ((codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+
+	socdev->codec = codec;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+
+	wm8772_socdev = socdev;
+	
+	/* Add other interfaces here */
+#warning do 3 wire device probe here and then call wm8772_init()
+	
+	return ret;
+}
+
+/* power down chip */
+static int wm8772_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	if (codec->control_data)
+		wm8772_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+
+	snd_soc_free_pcms(socdev);
+	kfree(codec);
+
+	return 0;
+}
+
+
+struct snd_soc_codec_device soc_codec_dev_wm8772 = {
+	.probe = 	wm8772_probe,
+	.remove = 	wm8772_remove,
+	.suspend = 	wm8772_suspend,
+	.resume =	wm8772_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8772);
+
+MODULE_DESCRIPTION("Soc WM8772 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8772.h b/sound/soc/codecs/wm8772.h
new file mode 100644
index 0000000..e1c1a3d
--- /dev/null
+++ b/sound/soc/codecs/wm8772.h
@@ -0,0 +1,39 @@
+/*
+ * wm8772.h  --  audio driver for WM8772
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef _WM8772_H
+#define _WM8772_H
+
+/* WM8772 register space */
+
+#define WM8772_LDAC1VOL   0x00
+#define WM8772_RDAC1VOL   0x01
+#define WM8772_DACCH      0x02
+#define WM8772_IFACE      0x03
+#define WM8772_LDAC2VOL   0x04
+#define WM8772_RDAC2VOL   0x05
+#define WM8772_LDAC3VOL   0x06
+#define WM8772_RDAC3VOL   0x07
+#define WM8772_MDACVOL    0x08
+#define WM8772_DACCTRL    0x09
+#define WM8772_DACRATE    0x0a
+#define WM8772_ADCRATE    0x0b
+#define WM8772_ADCCTRL    0x0c
+#define WM8772_RESET	  0x1f
+
+#define WM8772_CACHE_REGNUM 	10
+
+extern struct snd_soc_codec_device soc_codec_dev_wm8772;
+
+#endif
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
new file mode 100644
index 0000000..fc69e75
--- /dev/null
+++ b/sound/soc/codecs/wm8971.c
@@ -0,0 +1,919 @@
+/*
+ * wm8971.c  --  WM8971 ALSA SoC Audio driver
+ *
+ * Copyright 2005 Lab126, Inc.
+ * 
+ * Author: Kenneth Kiraly <kiraly@lab126.com>
+ *
+ * Based on wm8753.c by Liam Girdwood
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include "wm8971.h"
+
+#define AUDIO_NAME "wm8971"
+#define WM8971_VERSION "0.5"
+
+
+#define PFX AUDIO_NAME
+#undef	WM8971_DEBUG
+
+#ifdef WM8971_DEBUG
+#define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
+#else
+#define dbg(format, arg...) do {} while (0)
+#endif
+#define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
+
+#define	WM8971_REG_COUNT		43
+
+static struct workqueue_struct *wm8971_workq = NULL;
+static struct work_struct wm8971_dapm_work;
+
+
+/*
+ * wm8971 register cache
+ * We can't read the WM8971 register space when we 
+ * are using 2 wire for device control, so we cache them instead. 
+ */
+static const u16 wm8971_reg[] = {
+	0x0097, 0x0097, 0x0079, 0x0079,  /*  0 */
+	0x0000, 0x0008, 0x0000, 0x000a,  /*  4 */
+	0x0000, 0x0000, 0x00ff, 0x00ff,  /*  8 */
+	0x000f, 0x000f, 0x0000, 0x0000,  /* 12 */
+	0x0000, 0x007b, 0x0000, 0x0032,  /* 16 */
+	0x0000, 0x00c3, 0x00c3, 0x00c0,  /* 20 */
+	0x0000, 0x0000, 0x0000, 0x0000,  /* 24 */
+	0x0000, 0x0000, 0x0000, 0x0000,  /* 28 */
+	0x0000, 0x0000, 0x0050, 0x0050,  /* 32 */
+	0x0050, 0x0050, 0x0050, 0x0050,  /* 36 */
+	0x0079, 0x0079, 0x0079,          /* 40 */
+};
+
+#define WM8971_HIFI_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | \
+	SND_SOC_HWFMT_IB_IF)
+
+#define WM8971_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+
+#define WM8971_HIFI_FS \
+	(SND_SOC_FS(1536) | SND_SOC_FS(1408) | SND_SOC_FS(1024) | \
+	SND_SOC_FS(768) |SND_SOC_FS(512) | SND_SOC_FS(384) | SND_SOC_FS(256) | \
+	SND_SOC_FS(192) | SND_SOC_FS(128))
+
+#define WM8971_HIFI_FSB \
+	(SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4) | \
+	SND_SOC_FSBD(8) | SND_SOC_FSBD(16))
+	
+#define WM8971_HIFI_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+	
+#define WM8971_HIFI_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | SNDRV_PCM_FORMAT_S24_3LE)
+
+static struct snd_soc_hw_mode wm8971_audio[] = {
+	/* common codec frame and clock master modes */
+	{WM8971_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8971_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_8000, 
+		WM8971_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(1536), WM8971_HIFI_FSB},
+	{WM8971_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8971_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_11025, 
+		WM8971_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(1024), WM8971_HIFI_FSB},
+	{WM8971_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8971_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_16000, 
+		WM8971_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(768), WM8971_HIFI_FSB},
+	{WM8971_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8971_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_22050, 
+		WM8971_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(512), WM8971_HIFI_FSB},	
+	{WM8971_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8971_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_44100 | 
+		SNDRV_PCM_RATE_48000, WM8971_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256), 
+		WM8971_HIFI_FSB},
+	{WM8971_HIFI_HWFMT | SND_SOC_HWFMT_CBM_CFM, 
+		SND_SOC_HWTDM_LRDW(0,0), WM8971_HIFI_PCM_FORMATS, SNDRV_PCM_RATE_88200 | 
+		SNDRV_PCM_RATE_96000, WM8971_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(128), 
+		WM8971_HIFI_FSB},
+
+	/* codec frame and clock slave modes */
+	{WM8971_HIFI_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), 
+		WM8971_HIFI_PCM_FORMATS, WM8971_HIFI_RATES, WM8971_DIR, 
+		SND_SOC_HW_BFS_DIV, SND_SOC_FS_ALL, SND_SOC_FSBD_ALL},
+};
+
+static inline unsigned int wm8971_read_reg_cache(struct snd_soc_codec * codec, 
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg < WM8971_REG_COUNT)
+		return cache[reg];
+
+	return -1;
+}
+
+static inline void wm8971_write_reg_cache(struct snd_soc_codec * codec, 
+	unsigned int reg, unsigned int value)
+{
+	u16 *cache = codec->reg_cache;
+	if (reg < WM8971_REG_COUNT)
+		cache[reg] = value;
+}
+
+static int wm8971_write(struct snd_soc_codec * codec, unsigned int reg,
+	unsigned int value)
+{
+	u8 data[2];
+	
+	/* data is 
+	 *   D15..D9 WM8753 register offset
+	 *   D8...D0 register data
+	 */
+	data[0] = (reg << 1) | ((value >> 8) & 0x0001);
+	data[1] = value & 0x00ff;
+
+	wm8971_write_reg_cache (codec, reg, value);
+	if (codec->hw_write(codec->control_data, data, 2) == 2)
+		return 0;
+	else
+		return -1;
+}
+
+#define wm8971_reset(c)	wm8971_write(c, WM8971_RESET, 0)
+
+/* WM8971 Controls */
+static const char *wm8971_bass[] = { "Linear Control", "Adaptive Boost" };
+static const char *wm8971_bass_filter[] = { "130Hz @ 48kHz", "200Hz @ 48kHz" };
+static const char *wm8971_treble[] = { "8kHz", "4kHz" };
+static const char *wm8971_alc_func[] = { "Off", "Right", "Left", "Stereo" };
+static const char *wm8971_ng_type[] = { "Constant PGA Gain", "Mute ADC Output" };
+static const char *wm8971_deemp[] = { "None", "32kHz", "44.1kHz", "48kHz" };
+static const char* wm8971_mono_mux[] = {"Stereo", "Mono (Left)", "Mono (Right)", "Digital Mono"};
+static const char *wm8971_dac_phase[] = { "Non Inverted", "Inverted" };
+static const char* wm8971_lline_mux[] = {"Line", "NC", "NC", "PGA", "Differential"};
+static const char* wm8971_rline_mux[] = {"Line", "Mic", "NC", "PGA", "Differential"};
+static const char* wm8971_lpga_sel[] = {"Line", "NC", "NC", "Differential"};
+static const char* wm8971_rpga_sel[] = {"Line", "Mic", "NC", "Differential"};
+static const char* wm8971_adcpol[] = {"Normal", "L Invert", "R Invert", "L + R Invert"};
+
+static const struct soc_enum wm8971_enum[] = {
+	SOC_ENUM_SINGLE(WM8971_BASS, 7, 2, wm8971_bass),			/* 0 */
+	SOC_ENUM_SINGLE(WM8971_BASS, 6, 2, wm8971_bass_filter),
+	SOC_ENUM_SINGLE(WM8971_TREBLE, 6, 2, wm8971_treble),
+	SOC_ENUM_SINGLE(WM8971_ALC1, 7, 4, wm8971_alc_func),
+	SOC_ENUM_SINGLE(WM8971_NGATE, 1, 2, wm8971_ng_type),        /* 4 */
+	SOC_ENUM_SINGLE(WM8971_ADCDAC, 1, 4, wm8971_deemp),
+	SOC_ENUM_SINGLE(WM8971_ADCTL1, 4, 4, wm8971_mono_mux),
+	SOC_ENUM_SINGLE(WM8971_ADCTL1, 1, 2, wm8971_dac_phase),
+	SOC_ENUM_SINGLE(WM8971_LOUTM1, 0, 5, wm8971_lline_mux),     /* 8 */
+	SOC_ENUM_SINGLE(WM8971_ROUTM1, 0, 5, wm8971_rline_mux),
+	SOC_ENUM_SINGLE(WM8971_LADCIN, 6, 4, wm8971_lpga_sel),
+	SOC_ENUM_SINGLE(WM8971_RADCIN, 6, 4, wm8971_rpga_sel),
+	SOC_ENUM_SINGLE(WM8971_ADCDAC, 5, 4, wm8971_adcpol),        /* 12 */
+	SOC_ENUM_SINGLE(WM8971_ADCIN, 6, 4, wm8971_mono_mux),
+};
+
+
+static const snd_kcontrol_new_t wm8971_snd_controls[] = {
+	SOC_DOUBLE_R("Capture Volume", WM8971_LINVOL, WM8971_RINVOL, 0, 63, 0),
+	SOC_DOUBLE_R("Capture ZC Switch", WM8971_LINVOL, WM8971_RINVOL, 6, 1, 0),
+	SOC_DOUBLE_R("Capture Switch", WM8971_LINVOL, WM8971_RINVOL, 7, 1, 1),
+
+	SOC_DOUBLE_R("Out1 Playback ZC Switch", WM8971_LOUT1V, WM8971_ROUT1V, 7, 1, 0),
+	SOC_DOUBLE_R("Out2 Playback ZC Switch", WM8971_LOUT2V, WM8971_ROUT2V, 7, 1, 0),
+	SOC_SINGLE("Mono Playback ZC Switch", WM8971_MOUTV, 7, 1, 0),
+	
+	SOC_DOUBLE_R("PCM Volume", WM8971_LDAC, WM8971_RDAC, 0, 255, 0),
+	
+	SOC_DOUBLE_R("Bypass Left Playback Volume", WM8971_LOUTM1, WM8971_LOUTM2, 4, 7, 1),
+	SOC_DOUBLE_R("Bypass Right Playback Volume", WM8971_ROUTM1, WM8971_ROUTM2, 4, 7, 1),
+	SOC_DOUBLE_R("Bypass Mono Playback Volume", WM8971_MOUTM1, WM8971_MOUTM2, 4, 7, 1), 
+
+	SOC_DOUBLE_R("Out1 Playback Volume", WM8971_LOUT1V, WM8971_ROUT1V, 0, 127, 0),
+	SOC_DOUBLE_R("Out2 Playback Volume", WM8971_LOUT2V, WM8971_ROUT2V, 0, 127, 0),
+	
+	SOC_ENUM("Bass Boost", wm8971_enum[0]),
+	SOC_ENUM("Bass Filter", wm8971_enum[1]),
+	SOC_SINGLE("Bass Volume", WM8971_BASS, 0, 7, 1),
+
+	SOC_SINGLE("Treble Volume", WM8971_TREBLE, 0, 7, 0),
+	SOC_ENUM("Treble Cut-off", wm8971_enum[2]),
+
+	SOC_SINGLE("Capture Filter Switch", WM8971_ADCDAC, 0, 1, 1),
+
+	SOC_SINGLE("ALC Target Volume", WM8971_ALC1, 0, 7, 0),
+	SOC_SINGLE("ALC Max Volume", WM8971_ALC1, 4, 7, 0),
+
+	SOC_SINGLE("ALC Capture Target Volume", WM8971_ALC1, 0, 7, 0),
+	SOC_SINGLE("ALC Capture Max Volume", WM8971_ALC1, 4, 7, 0),
+	SOC_ENUM("ALC Capture Function", wm8971_enum[3]),
+	SOC_SINGLE("ALC Capture ZC Switch", WM8971_ALC2, 7, 1, 0),
+	SOC_SINGLE("ALC Capture Hold Time", WM8971_ALC2, 0, 15, 0),
+	SOC_SINGLE("ALC Capture Decay Time", WM8971_ALC3, 4, 15, 0),
+	SOC_SINGLE("ALC Capture Attack Time", WM8971_ALC3, 0, 15, 0),
+	SOC_SINGLE("ALC Capture NG Threshold", WM8971_NGATE, 3, 31, 0),
+	SOC_ENUM("ALC Capture NG Type", wm8971_enum[4]),
+	SOC_SINGLE("ALC Capture NG Switch", WM8971_NGATE, 0, 1, 0),
+
+	SOC_SINGLE("Capture 6dB Attenuate", WM8971_ADCDAC, 8, 1, 0),
+	SOC_SINGLE("Playback 6dB Attenuate", WM8971_ADCDAC, 7, 1, 0),
+
+    SOC_ENUM("Playback De-emphasis", wm8971_enum[5]),
+	SOC_ENUM("Playback Function", wm8971_enum[6]),
+	SOC_ENUM("Playback Phase", wm8971_enum[7]),
+	
+	SOC_DOUBLE_R("Mic Boost", WM8971_LADCIN, WM8971_RADCIN, 4, 3, 0),
+};
+
+
+/* add non-DAPM controls */
+static int wm8971_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(wm8971_snd_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm8971_snd_controls[i],codec, NULL))) < 0) {
+			return err;
+		}
+	}
+
+	return 0;
+}
+
+/*
+ * DAPM Controls
+ */
+
+/* Left Mixer */
+static const snd_kcontrol_new_t wm8971_left_mixer_controls[] = {
+SOC_DAPM_SINGLE("Playback Switch", WM8971_LOUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Left Bypass Switch", WM8971_LOUTM1, 7, 1, 0),
+SOC_DAPM_SINGLE("Right Playback Switch", WM8971_LOUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Right Bypass Switch", WM8971_LOUTM2, 7, 1, 0),
+};
+
+/* Right Mixer */
+static const snd_kcontrol_new_t wm8971_right_mixer_controls[] = {
+SOC_DAPM_SINGLE("Left Playback Switch", WM8971_ROUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Left Bypass Switch", WM8971_ROUTM1, 7, 1, 0),
+SOC_DAPM_SINGLE("Playback Switch", WM8971_ROUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Right Bypass Switch", WM8971_ROUTM2, 7, 1, 0),
+};
+
+/* Mono Mixer */
+static const snd_kcontrol_new_t wm8971_mono_mixer_controls[] = {
+SOC_DAPM_SINGLE("Left Playback Switch", WM8971_MOUTM1, 8, 1, 0),
+SOC_DAPM_SINGLE("Left Bypass Switch", WM8971_MOUTM1, 7, 1, 0),
+SOC_DAPM_SINGLE("Right Playback Switch", WM8971_MOUTM2, 8, 1, 0),
+SOC_DAPM_SINGLE("Right Bypass Switch", WM8971_MOUTM2, 7, 1, 0),
+};
+
+/* Left Line Mux */
+static const snd_kcontrol_new_t wm8971_left_line_controls =
+SOC_DAPM_ENUM("Route", wm8971_enum[8]);
+
+/* Right Line Mux */
+static const snd_kcontrol_new_t wm8971_right_line_controls =
+SOC_DAPM_ENUM("Route", wm8971_enum[9]);
+
+/* Left PGA Mux */
+static const snd_kcontrol_new_t wm8971_left_pga_controls =
+SOC_DAPM_ENUM("Route", wm8971_enum[10]);
+
+/* Right PGA Mux */
+static const snd_kcontrol_new_t wm8971_right_pga_controls =
+SOC_DAPM_ENUM("Route", wm8971_enum[11]);
+
+/* Mono ADC Mux */
+static const snd_kcontrol_new_t wm8971_monomux_controls =
+SOC_DAPM_ENUM("Route", wm8971_enum[13]);
+
+static const struct snd_soc_dapm_widget wm8971_dapm_widgets[] = {
+	SND_SOC_DAPM_CLOCK("WM8971 Clock", WM8971_PWR1, 0, 1),
+	SND_SOC_DAPM_MUTE("DAC Mute", WM8971_ADCDAC, 3, 0),
+	SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+		&wm8971_left_mixer_controls[0], ARRAY_SIZE(wm8971_left_mixer_controls)),
+	SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_DAPM_NOPM, 0, 0, 
+		&wm8971_right_mixer_controls[0], ARRAY_SIZE(wm8971_right_mixer_controls)),
+	SND_SOC_DAPM_MIXER("Mono Mixer", WM8971_PWR2, 2, 0, 
+		&wm8971_mono_mixer_controls[0], ARRAY_SIZE(wm8971_mono_mixer_controls)),
+
+	SND_SOC_DAPM_VOLUME("Right Out 2", WM8971_PWR2, 3, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Left Out 2", WM8971_PWR2, 4, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Right Out 1", WM8971_PWR2, 5, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Left Out 1", WM8971_PWR2, 6, 0, NULL, 0),
+	SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8971_PWR2, 7, 0, NULL, 0),
+	SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8971_PWR2, 8, 0, NULL, 0),
+	SND_SOC_DAPM_VOLUME("Mono Out 1", WM8971_PWR2, 2, 0, NULL, 0),
+	
+	SND_SOC_DAPM_MICBIAS("Mic Bias", WM8971_PWR1, 1, 0),
+	SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8971_PWR1, 2, 0, NULL, 0),
+	SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8971_PWR1, 3, 0, NULL, 0),
+
+	SND_SOC_DAPM_MUX("Left PGA Mux", WM8971_PWR1, 5, 0, 
+		&wm8971_left_pga_controls),
+	SND_SOC_DAPM_MUX("Right PGA Mux", WM8971_PWR1, 4, 0, 
+		&wm8971_right_pga_controls),
+	SND_SOC_DAPM_MUX("Left Line Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+		&wm8971_left_line_controls),
+	SND_SOC_DAPM_MUX("Right Line Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+		&wm8971_right_line_controls),
+
+	SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+		&wm8971_monomux_controls),
+	SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+		&wm8971_monomux_controls),
+
+	SND_SOC_DAPM_OUTPUT("LOUT1"),
+	SND_SOC_DAPM_OUTPUT("ROUT1"),
+	SND_SOC_DAPM_OUTPUT("LOUT2"),
+	SND_SOC_DAPM_OUTPUT("ROUT2"),
+	SND_SOC_DAPM_OUTPUT("MONO"),
+
+	SND_SOC_DAPM_INPUT("LINPUT1"),
+	SND_SOC_DAPM_INPUT("RINPUT1"),
+	SND_SOC_DAPM_INPUT("MIC"),
+};
+
+static const char* intercon[][3] = {
+	/* left mixer */
+	{"Left Mixer", "Playback Switch", "Left DAC"},
+	{"Left Mixer", "Left Bypass Switch", "Left Line Mux"},
+	{"Left Mixer", "Right Playback Switch", "Right DAC"},
+	{"Left Mixer", "Right Bypass Switch", "Right Line Mux"},
+
+	/* right mixer */
+	{"Right Mixer", "Left Playback Switch", "Left DAC"},
+	{"Right Mixer", "Left Bypass Switch", "Left Line Mux"},
+	{"Right Mixer", "Playback Switch", "Right DAC"},
+	{"Right Mixer", "Right Bypass Switch", "Right Line Mux"},
+
+	/* left out 1 */
+	{"Left Out 1", NULL, "Left Mixer"},
+	{"LOUT1", NULL, "Left Out 1"},
+
+	/* left out 2 */
+	{"Left Out 2", NULL, "Left Mixer"},
+	{"LOUT2", NULL, "Left Out 2"},
+	
+	/* right out 1 */
+	{"Right Out 1", NULL, "Right Mixer"},
+	{"ROUT1", NULL, "Right Out 1"},
+
+	/* right out 2 */
+	{"Right Out 2", NULL, "Right Mixer"},
+	{"ROUT2", NULL, "Right Out 2"},
+
+	/* mono mixer */
+	{"Mono Mixer", "Left Playback Switch", "Left DAC"},
+	{"Mono Mixer", "Left Bypass Switch", "Left Line Mux"},
+	{"Mono Mixer", "Right Playback Switch", "Right DAC"},
+	{"Mono Mixer", "Right Bypass Switch", "Right Line Mux"},
+	
+	/* mono out */
+	{"Mono Out", NULL, "Mono Mixer"},
+	{"MONO1", NULL, "Mono Out"},
+
+	/* Left Line Mux */
+	{"Left Line Mux", "Line", "LINPUT1"},
+	{"Left Line Mux", "PGA", "Left PGA Mux"},
+	{"Left Line Mux", "Differential", "Differential Mux"},
+
+	/* Right Line Mux */
+	{"Right Line Mux", "Line", "RINPUT1"},
+	{"Right Line Mux", "Mic", "MIC"},
+	{"Right Line Mux", "PGA", "Right PGA Mux"},
+	{"Right Line Mux", "Differential", "Differential Mux"},
+
+	/* Left PGA Mux */
+	{"Left PGA Mux", "Line", "LINPUT1"},
+	{"Left PGA Mux", "Differential", "Differential Mux"},
+
+	/* Right PGA Mux */
+	{"Right PGA Mux", "Line", "RINPUT1"},
+	{"Right PGA Mux", "Differential", "Differential Mux"},
+
+	/* Differential Mux */
+	{"Differential Mux", "Line", "LINPUT1"},
+	{"Differential Mux", "Line", "RINPUT1"},
+
+	/* Left ADC Mux */
+	{"Left ADC Mux", "Stereo", "Left PGA Mux"},
+	{"Left ADC Mux", "Mono (Left)", "Left PGA Mux"},
+	{"Left ADC Mux", "Digital Mono", "Left PGA Mux"},
+
+	/* Right ADC Mux */
+	{"Right ADC Mux", "Stereo", "Right PGA Mux"},
+	{"Right ADC Mux", "Mono (Right)", "Right PGA Mux"},
+	{"Right ADC Mux", "Digital Mono", "Right PGA Mux"},
+
+	/* ADC */
+	{"Left ADC", NULL, "Left ADC Mux"},
+	{"Right ADC", NULL, "Right ADC Mux"},
+
+	/* terminator */
+	{NULL, NULL, NULL},
+};
+
+static int wm8971_add_widgets(struct snd_soc_codec *codec)
+{
+	int i;
+	
+	for(i = 0; i < ARRAY_SIZE(wm8971_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &wm8971_dapm_widgets[i]);
+	}
+	
+	/* set up audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_new_widgets(codec);
+	return 0;
+}
+
+struct _coeff_div {
+	u32 mclk;
+	u16 fs;
+	u16 coeff;
+};
+
+/* codec mclk clock divider coefficients */
+static const struct _coeff_div coeff_div[] = {
+	{12288000, 384, 0x18},
+	{12288000, 256, 0x0},
+	{11289600, 256, 0x20},
+	{12288000, 128, 0x1c},
+	{11289600, 128, 0x3c},
+	{12288000, 1536, 0x0c},
+	{12288000, 768, 0x14},
+	{11289000, 1024, 0x30},
+	{11289000, 512, 0x34},
+};
+
+static int get_coeff(struct snd_soc_pcm_codec *pcm_codec, int fs)
+{
+	int i;
+	
+	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
+		if (coeff_div[i].mclk == pcm_codec->mclk && coeff_div[i].fs == fs)
+			return coeff_div[i].coeff;
+	}
+	return 0;
+}
+
+static unsigned int wm8971_config_sysclk(struct snd_soc_pcm_codec *pcm_codec, 
+	int rate, unsigned int clk)
+{
+	switch(rate){
+	case 8000:
+	case 16000:
+	case 32000:
+	case 48000:
+	case 96000:
+		if (clk == 12288000 || clk == 18432000)
+			pcm_codec->mclk = clk;
+		break;
+	case 11025:
+	case 22050:
+	case 44100:
+	case 88200:
+		if (clk == 11289600 || clk == 16934400)
+			pcm_codec->mclk = clk;
+		break;
+	default:
+		pcm_codec->mclk = 0;
+	}
+	
+	return pcm_codec->mclk;
+}
+
+static int wm8971_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 iface = 0, fs, bfs, srate;
+	
+	bfs = SND_SOC_FSB_INT(rtd->pcm_c->hw_runtime.hwbfs);
+	fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+	srate = get_coeff(rtd->pcm_c, fs);
+
+	/* set master/slave audio interface */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK) {
+		case SND_SOC_HWFMT_CBM_CFM:
+			iface |= 0x0040;
+			break;
+		case SND_SOC_HWFMT_CBS_CFS:
+			break;
+	}
+	
+	/* interface format */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+		case SND_SOC_HWFMT_I2S:
+			iface |= 0x0002;
+			break;
+		case SND_SOC_HWFMT_RIGHT_J:
+			break;
+		case SND_SOC_HWFMT_LEFT_J:
+			iface |= 0x0001;
+			break;
+		case SND_SOC_HWFMT_DSP_A:
+			iface |= 0x0003;
+			break;
+		case SND_SOC_HWFMT_DSP_B:
+			iface |= 0x0013;
+			break;
+	}
+		
+	/* bit size */
+	switch(rtd->pcm_c->hw_runtime.hwpcmfmt) {
+		case SNDRV_PCM_FORMAT_S16_LE:
+			break;
+		case SNDRV_PCM_FORMAT_S20_3LE:
+			iface |= 0x0004;
+			break;
+		case SNDRV_PCM_FORMAT_S24_3LE:
+			iface |= 0x0008;
+			break;
+		case SNDRV_PCM_FORMAT_S32_LE:
+			iface |= 0x000c;
+			break;
+	}
+
+	/* clock inversion */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK) {
+		case SND_SOC_HWFMT_NB_NF:
+			break;
+		case SND_SOC_HWFMT_IB_IF:
+			iface |= 0x0090;
+			break;
+		case SND_SOC_HWFMT_IB_NF:
+			iface |= 0x0080;
+			break;
+		case SND_SOC_HWFMT_NB_IF:
+			iface |= 0x0010;
+			break;
+	}
+	
+	/* set bclk divisor rate */
+	switch (bfs) {
+		case 1:
+			break;
+		case 4:
+			srate |= (0x1 << 7);
+			break;
+		case 8:
+			srate |= (0x2 << 7);
+			break;
+		case 16:
+			srate |= (0x3 << 7);
+			break;
+	}		
+	
+	/* set rate */
+	wm8971_write(codec, WM8971_SRATE, srate);
+	wm8971_write(codec, WM8971_AUDIO, iface);
+	
+	return 0;
+}
+
+static int wm8971_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	u16 pwr_reg = wm8971_read_reg_cache(codec, WM8971_PWR1) & 0xfe3f;
+
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			/* set vmid to 50k and unmute dac */
+			wm8971_write(codec, WM8971_PWR1, pwr_reg | 0x00c0);
+			break;
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			/* set vmid to 5k for quick power up */
+			wm8971_write(codec, WM8971_PWR1, pwr_reg | 0x01c0);
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* mute dac and set vmid to 500k, enable VREF */
+			wm8971_write(codec, WM8971_PWR1, pwr_reg | 0x0140);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			wm8971_write(codec, WM8971_PWR1, 0x0000);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static struct snd_soc_pcm_codec wm8971_pcm_client = {
+	.name = "WM8971",
+	.playback = {
+		.sname = "Playback",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.nplayback = 1,
+	.capture = {
+		.sname = "Capture",
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+	.ncapture = 1,
+	.config_sysclk = wm8971_config_sysclk,
+	.ops = {
+		.prepare = wm8971_pcm_prepare,
+	},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8971_audio),
+		.hmodes = &wm8971_audio[0],
+	},
+};
+
+static void wm8971_work(void *data)
+{
+	struct snd_soc_codec *codec = (struct snd_soc_codec *)data;
+	wm8971_dapm_event(codec, codec->dapm_state);
+}
+
+static int wm8971_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	wm8971_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int wm8971_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+	u8 data[2];
+	u16 *cache = codec->reg_cache;
+
+	/* Sync reg_cache with the hardware */
+	for (i = 0; i < ARRAY_SIZE(wm8971_reg); i++) {
+		if (i + 1 == WM8971_RESET)
+			continue;
+		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
+		data[1] = cache[i] & 0x00ff;
+		codec->hw_write(codec->control_data, data, 2);
+	}
+		
+	wm8971_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+		
+	/* charge wm8971 caps */
+	if(codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
+		wm8971_dapm_event(codec, SNDRV_CTL_POWER_D2);
+		codec->dapm_state = SNDRV_CTL_POWER_D0;
+		queue_delayed_work(wm8971_workq, &wm8971_dapm_work, msecs_to_jiffies(1000));
+	}
+	
+	return 0;
+}
+
+static int wm8971_init(struct snd_soc_device* socdev)
+{
+	struct snd_soc_codec* codec = socdev->codec;
+	int reg, ret = 0;
+
+	codec->name = "WM8971";
+	codec->owner = THIS_MODULE;
+	codec->read = wm8971_read_reg_cache;
+	codec->write = wm8971_write;
+	codec->dapm_event = wm8971_dapm_event;
+	codec->pcms = &wm8971_pcm_client;
+	codec->npcms = 1;
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(wm8971_reg), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	memcpy(codec->reg_cache, wm8971_reg, sizeof(u16) * ARRAY_SIZE(wm8971_reg));
+	
+	wm8971_reset(codec);
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0) {
+		kfree(codec->reg_cache);
+		return ret;
+	}
+	
+	/* charge output caps */
+	wm8971_dapm_event(codec, SNDRV_CTL_POWER_D2);
+	codec->dapm_state = SNDRV_CTL_POWER_D3hot;
+	queue_delayed_work(wm8971_workq, &wm8971_dapm_work, msecs_to_jiffies(1000));
+	
+
+	/* set the update bits */
+	reg = wm8971_read_reg_cache(codec, WM8971_LDAC);
+	wm8971_write(codec, WM8971_LDAC, reg | 0x0100);
+	reg = wm8971_read_reg_cache(codec, WM8971_RDAC);
+	wm8971_write(codec, WM8971_RDAC, reg | 0x0100);
+
+	reg = wm8971_read_reg_cache(codec, WM8971_LOUT1V);
+	wm8971_write(codec, WM8971_LOUT1V, reg | 0x0100);
+	reg = wm8971_read_reg_cache(codec, WM8971_ROUT1V);
+	wm8971_write(codec, WM8971_ROUT1V, reg | 0x0100);
+
+	reg = wm8971_read_reg_cache(codec, WM8971_LOUT2V);
+	wm8971_write(codec, WM8971_LOUT2V, reg | 0x0100);
+	reg = wm8971_read_reg_cache(codec, WM8971_ROUT2V);
+	wm8971_write(codec, WM8971_ROUT2V, reg | 0x0100);
+
+	reg = wm8971_read_reg_cache(codec, WM8971_LINVOL);
+	wm8971_write(codec, WM8971_LINVOL, reg | 0x0100);
+	reg = wm8971_read_reg_cache(codec, WM8971_RINVOL);
+	wm8971_write(codec, WM8971_RINVOL, reg | 0x0100);
+
+	wm8971_add_controls(codec);
+	wm8971_add_widgets(codec);
+	snd_soc_register_card(socdev);
+
+	return 0;
+}
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+static struct snd_soc_device *wm8971_socdev;
+	
+#ifdef CONFIG_I2C
+
+/*
+ * WM8731 2 wire address is determined by GPIO5
+ * state during powerup.
+ *    low  = 0x1a
+ *    high = 0x1b
+ */
+#define I2C_DRIVERID_WM8971 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver wm8971_i2c_driver;
+static struct i2c_client client_template;
+
+static int wm8971_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+	struct snd_soc_device *socdev = wm8971_socdev;
+	struct wm8971_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec = socdev->codec;
+	struct i2c_client *i2c;
+	int ret;
+
+	if (addr != setup->i2c_address)
+		return -ENODEV;
+
+	client_template.adapter = adap;
+	client_template.addr = addr;
+
+	if ((i2c = kzalloc(sizeof(struct i2c_client), GFP_KERNEL)) == NULL){
+		kfree(codec);
+		return -ENOMEM;
+	}
+	memcpy(i2c, &client_template, sizeof(struct i2c_client));
+
+	i2c_set_clientdata(i2c, codec);
+
+	codec->control_data = i2c;
+
+	if((ret = i2c_attach_client(i2c)) < 0) {
+		err("failed to attach codec at addr %x\n", addr);
+		kfree(i2c);
+		return ret;
+	}
+
+	wm8971_init(socdev);
+
+	return 0;
+}
+
+static int wm8971_i2c_detach(struct i2c_client *client)
+{
+	struct snd_soc_codec* codec = i2c_get_clientdata(client);
+
+	i2c_detach_client(client);
+	kfree(codec->reg_cache);
+	kfree(client);
+
+	return 0;
+}
+
+static int wm8971_i2c_attach(struct i2c_adapter *adap)
+{
+	return i2c_probe(adap, &addr_data, wm8971_codec_probe);
+}
+
+/* corgi i2c codec control layer */
+static struct i2c_driver wm8971_i2c_driver = {
+	.driver = {
+		.name = "WM8971 I2C Codec",
+		.owner = THIS_MODULE,
+	},
+	.id =             I2C_DRIVERID_WM8971,
+	.attach_adapter = wm8971_i2c_attach,
+	.detach_client =  wm8971_i2c_detach,
+	.command =        NULL,
+};
+
+static struct i2c_client client_template = {
+	.name =   "WM8971",
+	.driver = &wm8971_i2c_driver,
+};
+#endif
+
+static int wm8971_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct wm8971_setup_data *setup = socdev->codec_data;
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	info("WM8971 Audio Codec %s", WM8971_VERSION);
+
+	if ((codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+
+	socdev->codec = codec;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+	wm8971_socdev = socdev;
+	
+	INIT_WORK(&wm8971_dapm_work, wm8971_work, codec);
+	if((wm8971_workq = create_workqueue("wm8971")) == NULL) {
+		kfree(codec);
+		return -ENOMEM;
+	}
+#ifdef CONFIG_I2C	
+	if (setup->i2c_address) {
+		normal_i2c[0] = setup->i2c_address;
+		codec->hw_write = (hw_write_t)i2c_master_send;
+		if ((ret = i2c_add_driver(&wm8971_i2c_driver)) != 0)
+			printk(KERN_ERR "can't add i2c driver");
+	}
+#else
+		/* Add other interfaces here */
+#endif
+
+	return ret;
+}
+
+/* power down chip */
+static int wm8971_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	if (codec->control_data)
+		wm8971_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	if(wm8971_workq)
+		destroy_workqueue(wm8971_workq);
+	snd_soc_free_pcms(socdev);
+	snd_soc_dapm_free(socdev);
+#ifdef CONFIG_I2C
+	i2c_del_driver(&wm8971_i2c_driver);
+#endif
+	kfree(codec);
+
+	return 0;
+}
+
+
+struct snd_soc_codec_device soc_codec_dev_wm8971 = {
+	.probe = 	wm8971_probe,
+	.remove = 	wm8971_remove,
+	.suspend = 	wm8971_suspend,
+	.resume =	wm8971_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8971);
+
+MODULE_DESCRIPTION("SoC WM8971 driver");
+MODULE_AUTHOR("Lab126");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8971.h b/sound/soc/codecs/wm8971.h
new file mode 100644
index 0000000..98b05fc
--- /dev/null
+++ b/sound/soc/codecs/wm8971.h
@@ -0,0 +1,61 @@
+/*
+ * wm8971.h  --  audio driver for WM8971
+ *
+ * Copyright 2005 Lab126, Inc.
+ *
+ * Author: Kenneth Kiraly <kiraly@lab126.com>
+ * 
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _WM8971_H
+#define _WM8971_H
+
+#define WM8971_LINVOL	0x00
+#define WM8971_RINVOL	0x01
+#define WM8971_LOUT1V	0x02
+#define WM8971_ROUT1V	0x03
+#define WM8971_ADCDAC	0x05
+#define WM8971_AUDIO	0x07
+#define WM8971_SRATE	0x08
+#define WM8971_LDAC		0x0a
+#define WM8971_RDAC		0x0b
+#define WM8971_BASS		0x0c
+#define WM8971_TREBLE	0x0d
+#define WM8971_RESET	0x0f
+#define WM8971_ALC1		0x11
+#define	WM8971_ALC2		0x12
+#define	WM8971_ALC3		0x13
+#define WM8971_NGATE	0x14
+#define WM8971_LADC		0x15
+#define WM8971_RADC		0x16
+#define	WM8971_ADCTL1	0x17
+#define	WM8971_ADCTL2	0x18
+#define WM8971_PWR1		0x19
+#define WM8971_PWR2		0x1a
+#define	WM8971_ADCTL3	0x1b
+#define WM8971_ADCIN	0x1f
+#define	WM8971_LADCIN	0x20
+#define	WM8971_RADCIN	0x21
+#define WM8971_LOUTM1	0x22
+#define WM8971_LOUTM2	0x23
+#define WM8971_ROUTM1	0x24
+#define WM8971_ROUTM2	0x25
+#define WM8971_MOUTM1	0x26
+#define WM8971_MOUTM2	0x27
+#define WM8971_LOUT2V	0x28
+#define WM8971_ROUT2V	0x29
+#define WM8971_MOUTV	0x2A
+
+struct wm8971_setup_data {
+	unsigned short i2c_address;
+};
+
+extern struct snd_soc_codec_device soc_codec_dev_wm8971;
+
+#endif
+
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
new file mode 100644
index 0000000..a85e57e
--- /dev/null
+++ b/sound/soc/codecs/wm9712.c
@@ -0,0 +1,686 @@
+/*
+ * wm9712.c  --  ALSA Soc WM9712 codec support
+ *
+ * Copyright 2006 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    4th Feb 2006   Initial version.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/ac97_codec.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#define WM9712_VERSION "0.1"
+
+#define AC97_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+	
+#define AC97_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
+	
+#define AC97_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S18_3LE | SNDRV_PCM_FORMAT_S20_3LE)
+
+/* may need to expand this */
+static struct snd_soc_hw_mode soc_ac97[] = {
+	{0, 0,	AC97_PCM_FORMATS,	AC97_RATES},
+};
+
+/*
+ * WM9712 register cache
+ */
+static const u16 wm9712_reg[] = {
+	0x6174, 0x8000, 0x8000, 0x8000, // 6  
+	0xf0f0, 0xaaa0, 0xc008, 0x6808, // e
+	0xe808, 0xaaa0, 0xad00, 0x8000, // 16
+	0xe808, 0x3000, 0x8000, 0x0000, // 1e
+	0x0000, 0x0000, 0x0000, 0x000f, // 26
+	0x0405, 0x0410, 0xbb80, 0xbb80, // 2e
+	0x0000, 0xbb80, 0x0000, 0x0000, // 36
+	0x0000, 0x2000, 0x0000, 0x0000, // 3e
+	0x0000, 0x0000, 0x0000, 0x0000, // 46
+	0x0000, 0x0000, 0xf83e, 0xffff, // 4e
+	0x0000, 0x0000, 0x0000, 0xf83e, // 56
+	0x0008, 0x0000, 0x0000, 0x0000, // 5e
+	0xb032, 0x3e00, 0x0000, 0x0000, // 66
+	0x0000, 0x0000, 0x0000, 0x0000, // 6e
+	0x0000, 0x0000, 0x0000, 0x0006, // 76
+	0x0001, 0x0000, 0x574d, 0x4c12, // 7e
+};
+
+static const char* wm9712_alc_select[] = {"None", "Left", "Right", "Stereo"};
+static const char* wm9712_alc_mux[] = {"Stereo", "Left", "Right", "None"};
+static const char* wm9712_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
+static const char* wm9712_spk_src[] = {"Speaker Mix", "Headphone Mix"};
+static const char* wm9712_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
+static const char* wm9712_base[] = {"Linear Control", "Adaptive Boost"};
+static const char* wm9712_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
+static const char* wm9712_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
+static const char* wm9712_rec_sel[] = 
+	{"Mic", "NC", "NC", "Speaker Mixer", "Line", "Headphone Mixer", "Phone Mixer", "Phone"};
+static const char* wm9712_ng_type[] = {"Constant Gain", "Mute"};
+static const char* wm9712_diff_sel[] = {"Mic", "Line"};
+
+static const struct soc_enum wm9712_enum[] = {
+SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9712_alc_select),
+SOC_ENUM_SINGLE(AC97_VIDEO, 12, 4, wm9712_alc_mux),
+SOC_ENUM_SINGLE(AC97_AUX, 9, 4, wm9712_out3_src),
+SOC_ENUM_SINGLE(AC97_AUX, 8, 2, wm9712_spk_src),
+SOC_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9712_rec_adc),
+SOC_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9712_base),
+SOC_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9712_rec_gain),
+SOC_ENUM_SINGLE(AC97_MIC, 5, 4, wm9712_mic),
+SOC_ENUM_SINGLE(AC97_REC_SEL, 8, 8, wm9712_rec_sel),
+SOC_ENUM_SINGLE(AC97_REC_SEL, 0, 8, wm9712_rec_sel),
+SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9712_ng_type),
+SOC_ENUM_SINGLE(0x5c, 8, 2, wm9712_diff_sel),
+};
+
+static const struct snd_kcontrol_new wm9712_snd_ac97_controls[] = {
+SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1),
+SOC_SINGLE("Speaker Playback Switch", AC97_MASTER, 15, 1, 1),
+SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
+SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE,15, 1, 1),	
+
+SOC_SINGLE("Speaker Playback ZC Switch", AC97_MASTER, 7, 1, 0),
+SOC_SINGLE("Speaker Playback Invert Switch", AC97_MASTER, 6, 1, 0),
+SOC_SINGLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 7, 1, 0),
+SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
+SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 0),
+
+SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
+SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
+SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
+SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
+SOC_ENUM("ALC Function", wm9712_enum[0]),
+SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
+SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
+SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
+SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
+SOC_ENUM("ALC NG Type", wm9712_enum[10]),
+SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
+
+SOC_SINGLE("Mic Headphone  Volume", AC97_VIDEO, 12, 7, 1),
+SOC_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
+
+SOC_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
+SOC_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
+SOC_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
+
+SOC_SINGLE("PCBeep Bypass Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
+SOC_SINGLE("PCBeep Bypass Speaker Volume", AC97_PC_BEEP, 8, 7, 1),
+SOC_SINGLE("PCBeep Bypass Phone Volume", AC97_PC_BEEP, 4, 7, 1),
+
+SOC_SINGLE("Aux Playback Headphone Volume", AC97_CD, 12, 7, 1),
+SOC_SINGLE("Aux Playback Speaker Volume", AC97_CD, 8, 7, 1),
+SOC_SINGLE("Aux Playback Phone Volume", AC97_CD, 4, 7, 1),
+
+SOC_SINGLE("Phone Volume", AC97_PHONE, 0, 15, 0),
+SOC_DOUBLE("Line Capture Volume", AC97_LINE, 8, 0, 31, 1),
+
+SOC_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
+SOC_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
+
+SOC_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
+SOC_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
+SOC_SINGLE("3D Playback Volume", AC97_3D_CONTROL, 0, 15, 0),
+
+SOC_ENUM("Bass Control", wm9712_enum[5]),
+SOC_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
+SOC_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
+SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
+SOC_SINGLE("Bass Volume", AC97_MASTER_TONE, 8, 15, 0),
+SOC_SINGLE("Treble Volume", AC97_MASTER_TONE, 0, 15, 0),
+
+SOC_SINGLE("Capture ADC Switch", AC97_REC_GAIN, 15, 1, 1),
+SOC_ENUM("Capture Volume Steps", wm9712_enum[6]),
+SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
+SOC_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
+
+SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
+SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
+SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
+};
+
+
+/* add non dapm controls */
+static int wm9712_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(wm9712_snd_ac97_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm9712_snd_ac97_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	return 0;
+}
+
+/* Headphone Mixers */
+static const snd_kcontrol_new_t wm9712_hp_mixer_controls[] = {
+	SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 15, 1, 1),
+	SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 15, 1, 1),
+	SOC_DAPM_SINGLE("Phone Bypass Switch", AC97_PHONE, 15, 1, 1),
+	SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 15, 1, 1),
+	SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1),
+	SOC_DAPM_SINGLE("Mic Sidetone Switch", AC97_VIDEO, 15, 1, 1),
+};
+
+/* Speaker Mixer */
+static const snd_kcontrol_new_t wm9712_speaker_mixer_controls[] = {
+	SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 11, 1, 1),
+	SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 11, 1, 1),
+	SOC_DAPM_SINGLE("Phone Bypass Switch", AC97_PHONE, 14, 1, 1),
+	SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 14, 1, 1),
+	SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 14, 1, 1),
+};
+
+/* Phone Mixer */
+static const snd_kcontrol_new_t wm9712_phone_mixer_controls[] = {
+	SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 7, 1, 1),
+	SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 7, 1, 1),
+	SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 13, 1, 1),
+	SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 13, 1, 1),
+	SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_MIC, 14, 1, 1),
+	SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_MIC, 13, 1, 1),
+};
+
+/* ALC headphone mux */
+static const snd_kcontrol_new_t wm9712_alc_mux_controls =
+SOC_DAPM_ENUM("Route", wm9712_enum[1]);
+
+/* out 3 mux */
+static const snd_kcontrol_new_t wm9712_out3_mux_controls =
+SOC_DAPM_ENUM("Route", wm9712_enum[2]);
+
+/* spk mux */
+static const snd_kcontrol_new_t wm9712_spk_mux_controls =
+SOC_DAPM_ENUM("Route", wm9712_enum[3]);
+
+/* Capture to Phone mux */
+static const snd_kcontrol_new_t wm9712_capture_phone_mux_controls =
+SOC_DAPM_ENUM("Route", wm9712_enum[4]);
+
+/* Capture left select */
+static const snd_kcontrol_new_t wm9712_capture_selectl_controls =
+SOC_DAPM_ENUM("Route", wm9712_enum[8]);
+
+/* Capture right select */
+static const snd_kcontrol_new_t wm9712_capture_selectr_controls =
+SOC_DAPM_ENUM("Route", wm9712_enum[9]);
+
+/* Mic select */
+static const snd_kcontrol_new_t wm9712_mic_src_controls =
+SOC_DAPM_ENUM("Route", wm9712_enum[7]);
+
+/* diff select */
+static const snd_kcontrol_new_t wm9712_diff_sel_controls =
+SOC_DAPM_ENUM("Route", wm9712_enum[11]);
+
+static const struct snd_soc_dapm_widget wm9712_dapm_widgets[] = {
+SND_SOC_DAPM_MUX("ALC Sidetone Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9712_alc_mux_controls),
+SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9712_out3_mux_controls),
+SND_SOC_DAPM_MUX("Speaker Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9712_spk_mux_controls),
+SND_SOC_DAPM_MUX("Capture Phone Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9712_capture_phone_mux_controls),
+SND_SOC_DAPM_MUX("Left Capture Select", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9712_capture_selectl_controls),
+SND_SOC_DAPM_MUX("Right Capture Select", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9712_capture_selectr_controls),
+SND_SOC_DAPM_MUX("Mic Select Source", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9712_mic_src_controls),
+SND_SOC_DAPM_MUX("Differential Source", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9712_diff_sel_controls),
+SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
+SND_SOC_DAPM_MIXER("HP Mixer", AC97_INT_PAGING, 9, 1, &wm9712_hp_mixer_controls[0], 
+	ARRAY_SIZE(wm9712_hp_mixer_controls)),
+SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_INT_PAGING, 8, 1, NULL, 0),
+SND_SOC_DAPM_MIXER("Phone Mixer", AC97_INT_PAGING, 6, 1, &wm9712_phone_mixer_controls[0], 
+	ARRAY_SIZE(wm9712_phone_mixer_controls)),
+SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_INT_PAGING, 7, 1, &wm9712_speaker_mixer_controls[0], 
+	ARRAY_SIZE(wm9712_speaker_mixer_controls)),
+SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
+SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_INT_PAGING, 14, 1, NULL, 0),
+SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_INT_PAGING, 13, 1, NULL, 0),
+SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
+SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_INT_PAGING, 12, 1, NULL, 0),
+SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_INT_PAGING, 11, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Headphone PGA", AC97_INT_PAGING, 4, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Speaker PGA", AC97_INT_PAGING, 3, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Out 3 PGA", AC97_INT_PAGING, 5, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Line PGA", AC97_INT_PAGING, 2, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Phone PGA", AC97_INT_PAGING, 1, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mic PGA", AC97_INT_PAGING, 0, 1, NULL, 0),
+SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_INT_PAGING, 10, 1),
+SND_SOC_DAPM_OUTPUT("MONOOUT"),
+SND_SOC_DAPM_OUTPUT("HPOUTL"),
+SND_SOC_DAPM_OUTPUT("HPOUTR"),
+SND_SOC_DAPM_OUTPUT("LOUT2"),
+SND_SOC_DAPM_OUTPUT("ROUT2"),
+SND_SOC_DAPM_OUTPUT("OUT3"),
+SND_SOC_DAPM_INPUT("LINEINL"),
+SND_SOC_DAPM_INPUT("LINEINR"),
+SND_SOC_DAPM_INPUT("PHONE"),
+SND_SOC_DAPM_INPUT("PCBEEP"),
+SND_SOC_DAPM_INPUT("MIC1"),
+SND_SOC_DAPM_INPUT("MIC2"),
+};
+
+static const char* intercon[][3] = {
+	/* virtual mixer - mixes left & right channels for spk and mono */
+	{"AC97 Mixer", NULL, "Left DAC"},
+	{"AC97 Mixer", NULL, "Right DAC"},
+	
+	/* HP mixer */
+	{"HP Mixer", "PCBeep Bypass Switch", "PCBEEP"},
+	{"HP Mixer", "Aux Playback Switch",  "Aux DAC"},
+	{"HP Mixer", "Phone Bypass Switch",  "Phone PGA"},
+	{"HP Mixer", "Line Bypass Switch",   "Line PGA"},
+	{"HP Mixer", "PCM Playback Switch",  "AC97 Mixer"},
+	{"HP Mixer", "Mic Sidetone Switch",  "Mic PGA"},
+	{"HP Mixer", NULL,  "ALC Sidetone Mux"},
+	{"Right HP Mixer", NULL, "HP Mixer"},
+	
+	/* speaker mixer */
+	{"Speaker Mixer", "PCBeep Bypass Switch", "PCBEEP"},
+	{"Speaker Mixer", "Line Bypass Switch",   "Line PGA"},
+	{"Speaker Mixer", "PCM Playback Switch",  "AC97 Mixer"},
+	{"Speaker Mixer", "Phone Bypass Switch",  "Phone PGA"},
+	{"Speaker Mixer", "Aux Playback Switch",  "Aux DAC"},
+	
+	/* Phone mixer */
+	{"Phone Mixer", "PCBeep Bypass Switch",  "PCBEEP"},
+	{"Phone Mixer", "Line Bypass Switch",    "Line PGA"},
+	{"Phone Mixer", "Aux Playback Switch",   "Aux DAC"},
+	{"Phone Mixer", "PCM Playback Switch",   "AC97 Mixer"},
+	{"Phone Mixer", "Mic 1 Sidetone Switch", "Mic PGA"},
+	{"Phone Mixer", "Mic 2 Sidetone Switch", "Mic PGA"},
+	
+	/* inputs */
+	{"Line PGA", NULL, "LINEINL"},
+	{"Line PGA", NULL, "LINEINR"},
+	{"Phone PGA", NULL, "PHONE"},
+	{"Mic PGA", NULL, "MIC1"},
+	{"Mic PGA", NULL, "MIC2"},
+	 
+	/* left capture selector */
+	{"Left Capture Select", "Mic", "MIC1"},
+	{"Left Capture Select", "Speaker Mixer", "Speaker Mixer"},
+	{"Left Capture Select", "Line", "LINEINL"},
+	{"Left Capture Select", "Headphone Mixer", "HP Mixer"},
+	{"Left Capture Select", "Phone Mixer", "Phone Mixer"},
+	{"Left Capture Select", "Phone", "PHONE"},
+	
+	/* right capture selector */
+	{"Right Capture Select", "Mic", "MIC2"},
+	{"Right Capture Select", "Speaker Mixer", "Speaker Mixer"},
+	{"Right Capture Select", "Line", "LINEINR"},
+	{"Right Capture Select", "Headphone Mixer", "Right HP Mixer"},
+	{"Right Capture Select", "Phone Mixer", "Phone Mixer"},
+	{"Right Capture Select", "Phone", "PHONE"},
+	
+	/* ALC Sidetone */
+	{"ALC Sidetone Mux", "Stereo", "Left Capture Select"},
+	{"ALC Sidetone Mux", "Stereo", "Right Capture Select"},
+	{"ALC Sidetone Mux", "Left", "Left Capture Select"},
+	{"ALC Sidetone Mux", "Right", "Right Capture Select"},
+	
+	/* ADC's */
+	{"Left ADC", NULL, "Left Capture Select"},
+	{"Right ADC", NULL, "Right Capture Select"},
+	
+	/* outputs */
+	{"MONOOUT", NULL, "Phone Mixer"},
+	{"HPOUTL", NULL, "Headphone PGA"},
+	{"Headphone PGA", NULL, "HP Mixer"},
+	{"HPOUTR", NULL, "Headphone PGA"},
+	{"Headphone PGA", NULL, "Right HP Mixer"},
+	
+	/* mono hp mixer */
+	{"Mono HP Mixer", NULL, "HP Mixer"},
+	{"Mono HP Mixer", NULL, "Right HP Mixer"},
+	
+	/* Out3 Mux */
+	{"Out3 Mux", "Left", "HP Mixer"},
+	{"Out3 Mux", "Mono", "Phone Mixer"},
+	{"Out3 Mux", "Left + Right", "Mono HP Mixer"},
+	{"Out 3 PGA", NULL, "Out3 Mux"},
+	{"OUT3", NULL, "Out 3 PGA"},
+	
+	/* speaker Mux */
+	{"Speaker Mux", "Speaker Mix", "Speaker Mixer"},
+	{"Speaker Mux", "Headphone Mix", "Mono HP Mixer"},
+	{"Speaker PGA", NULL, "Speaker Mux"},
+	{"LOUT2", NULL, "Speaker PGA"},
+	{"ROUT2", NULL, "Speaker PGA"},
+	
+	{NULL, NULL, NULL},
+};
+
+static int wm9712_add_widgets(struct snd_soc_codec *codec)
+{
+	int i;
+
+	for(i = 0; i < ARRAY_SIZE(wm9712_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &wm9712_dapm_widgets[i]);
+	}
+
+	/* set up audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+
+	snd_soc_dapm_new_widgets(codec);
+	return 0;
+}
+
+static unsigned int ac97_read(struct snd_soc_codec *codec, 
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+
+	if (reg == AC97_RESET || reg == AC97_GPIO_STATUS || 
+		reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
+		reg == AC97_REC_GAIN)
+		return soc_ac97_ops.read(codec->ac97, reg);
+	else {
+		reg = reg >> 1;
+		
+		if(reg > (ARRAY_SIZE(wm9712_reg)))
+			return -EIO;
+		
+		return cache[reg];
+	}
+}
+
+static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
+	unsigned int val)
+{
+	u16 *cache = codec->reg_cache;
+
+	soc_ac97_ops.write(codec->ac97, reg, val);
+	reg = reg >> 1;
+	if(reg <= (ARRAY_SIZE(wm9712_reg)))
+		cache[reg] = val;
+	
+	return 0;
+}
+
+static int ac97_prepare(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	int reg;
+	u16 vra;
+	
+	vra = ac97_read(codec, AC97_EXTENDED_STATUS);
+	ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		reg = AC97_PCM_FRONT_DAC_RATE;
+	else
+		reg = AC97_PCM_LR_ADC_RATE;
+
+	return ac97_write(codec, reg, runtime->rate);
+}
+
+static int ac97_aux_prepare(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 vra, xsle;
+	
+	vra = ac97_read(codec, AC97_EXTENDED_STATUS);
+	ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
+	xsle = ac97_read(codec, AC97_PCI_SID);
+	ac97_write(codec, AC97_PCI_SID, xsle | 0x8000);
+	
+	if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
+		return -ENODEV;
+
+	return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
+}
+
+static struct snd_soc_pcm_codec wm9712_soc_client[] = {
+{
+	.name = "AC97 HiFi",
+	.playback = {
+		.sname = "HiFi Playback",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.capture = {
+		.sname = "HiFi Capture",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.nplayback = 1,
+	.ncapture = 1,
+	.ops = {
+		.prepare = ac97_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(soc_ac97),
+		.hmodes = &soc_ac97[0],},
+	},
+	{
+	.name = "AC97 Aux",
+	.playback = {
+		.sname = "Aux Playback",
+		.channels_min = 1,
+		.channels_max = 1,},
+	.nplayback = 1,
+	.ops = {
+		.prepare = ac97_aux_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(soc_ac97),
+		.hmodes = &soc_ac97[0],},
+	},
+};
+
+static int wm9712_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	u16 reg;
+
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			/* liam - maybe enable thermal shutdown */
+			reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xdfff;
+			ac97_write(codec, AC97_EXTENDED_MID, reg);
+			//reg = ac97_read(codec, AC97_POWERDOWN) & 0xdfff;
+			//ac97_write(codec, AC97_POWERDOWN, reg);
+			break;
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* enable master bias and vmid */
+			reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xbbff;
+			ac97_write(codec, AC97_EXTENDED_MID, reg);
+			ac97_write(codec, AC97_POWERDOWN, 0x0000);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			/* disable everything including AC link */
+			ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
+			ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
+			ac97_write(codec, AC97_POWERDOWN, 0xffff);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static int wm9712_reset(struct snd_soc_codec *codec, int try_warm)
+{
+	if(try_warm && soc_ac97_ops.warm_reset) {
+		soc_ac97_ops.warm_reset(codec->ac97);
+		if(!(ac97_read(codec, 0) & 0x8000)) 
+			return 1;
+	}
+	
+	soc_ac97_ops.reset(codec->ac97);
+	if(ac97_read(codec, 0) & 0x8000)
+		goto err;
+	return 0;
+	
+err:
+	printk(KERN_ERR "WM9712 AC97 reset failed\n");
+	return -EIO;
+}
+
+static int wm9712_soc_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int wm9712_soc_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i, ret;
+	u16 *cache = codec->reg_cache;
+	
+	if((ret = wm9712_reset(codec, 1)) < 0){
+		printk(KERN_ERR "could not reset AC97 codec\n");
+		return ret;
+	}
+	
+	wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+
+	if(ret == 0){
+		/* Sync reg_cache with the hardware after cold reset */
+		for (i = 2; i < ARRAY_SIZE(wm9712_reg) << 1; i+=2) {
+			if (i == AC97_INT_PAGING || i == AC97_POWERDOWN || 
+				(i > 0x58 && i != 0x5c))
+				continue; 
+			soc_ac97_ops.write(codec->ac97, i, cache[i>>1]);
+		}
+	}
+	
+	if(codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
+		wm9712_dapm_event(codec, SNDRV_CTL_POWER_D0);
+	
+	return ret;
+}
+
+static int wm9712_soc_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	printk(KERN_INFO "WM9711/WM9712 SoC Audio Codec %s\n", WM9712_VERSION);
+
+	if ((socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	codec = socdev->codec;
+	
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(wm9712_reg), GFP_KERNEL)) == NULL){
+		kfree(codec->ac97);
+		kfree(socdev->codec);
+		socdev->codec = NULL;
+		return -ENOMEM;
+	}
+	memcpy(codec->reg_cache, wm9712_reg, sizeof(u16) * ARRAY_SIZE(wm9712_reg));
+	
+	codec->name = "WM9712";
+	codec->owner = THIS_MODULE;
+	codec->pcms = wm9712_soc_client;
+	codec->npcms = ARRAY_SIZE(wm9712_soc_client);
+	codec->write = ac97_write;
+	codec->read = ac97_read;
+	codec->dapm_event = wm9712_dapm_event;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+	
+	if((ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0)) < 0)
+		goto err;
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0)
+		goto pcm_err;
+
+	if((ret = wm9712_reset(codec, 0)) < 0)	{
+		printk(KERN_ERR "AC97 link error\n");
+		goto reset_err;
+	}
+
+	/* set alc mux to none */
+	ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000);
+
+	wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	wm9712_add_controls(codec);
+	wm9712_add_widgets(codec);
+	snd_soc_register_card(socdev);
+	return 0;
+
+reset_err:	
+	snd_soc_free_pcms(socdev);
+	
+pcm_err:	
+	snd_soc_free_ac97_codec(codec);
+	
+err:
+	kfree(socdev->codec->reg_cache);
+	kfree(socdev->codec);
+	socdev->codec = NULL;
+	return ret;
+}
+
+static int wm9712_soc_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	if(codec == NULL)
+		return 0;
+
+	snd_soc_dapm_free(socdev);
+	snd_soc_free_pcms(socdev);
+	snd_soc_free_ac97_codec(codec);
+	kfree(codec->reg_cache);
+	kfree(codec);
+	return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_wm9712= {
+	.probe = 	wm9712_soc_probe,
+	.remove = 	wm9712_soc_remove,
+	.suspend =	wm9712_soc_suspend,
+	.resume =	wm9712_soc_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm9712);
+
+MODULE_DESCRIPTION("Soc WM9711/WM9712 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
+
diff --git a/sound/soc/codecs/wm9712.h b/sound/soc/codecs/wm9712.h
new file mode 100644
index 0000000..a168ea2
--- /dev/null
+++ b/sound/soc/codecs/wm9712.h
@@ -0,0 +1,10 @@
+/*
+ * wm9712.h  --  WM9712 Soc Audio driver
+ */
+
+#ifndef _WM9712_H
+#define _WM9712_H
+
+extern struct snd_soc_codec_device soc_codec_dev_wm9712;
+	
+#endif
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
new file mode 100644
index 0000000..725a7ef
--- /dev/null
+++ b/sound/soc/codecs/wm9713.c
@@ -0,0 +1,989 @@
+/*
+ * wm9713.c  --  ALSA Soc WM9713 codec support
+ *
+ * Copyright 2006 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    4th Feb 2006   Initial version.
+ * 
+ *  Features:-
+ * 
+ *   o Support for AC97 Codec, Voice DAC and Aux DAC
+ *   o Support for DAPM
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/ac97_codec.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#define WM9713_VERSION "0.2"
+
+#define AC97_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+	
+#define AC97_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000)
+	
+#define AC97_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S18_3LE | SNDRV_PCM_FORMAT_S20_3LE)
+
+/* may need to expand this */
+static struct snd_soc_hw_mode soc_ac97[] = {
+	{0, 0,	AC97_PCM_FORMATS,	AC97_RATES},
+};
+
+#define WM9713_VOICE_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	SND_SOC_HWFMT_DSP_A | SND_SOC_HWFMT_DSP_B |  SND_SOC_HWFMT_NB_NF | \
+	SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | SND_SOC_HWFMT_IB_IF)
+
+#define WM9713_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+
+#define WM9713_VOICE_FS \
+	(SND_SOC_FS(384) | SND_SOC_FS(256))
+
+#define WM9713_VOICE_FSB \
+	(SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4) | \
+	SND_SOC_FSBD(8) | SND_SOC_FSBD(16))
+	
+#define WM9713_VOICE_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_32000 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
+	
+#define WM9713_VOICE_PCM_FORMATS \
+	(SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | SNDRV_PCM_FORMAT_S24_3LE)
+
+/*
+ * Voice modes
+ */
+static struct snd_soc_hw_mode wm9713_voice[] = {
+	
+	/* master modes */
+	{WM9713_VOICE_HWFMT | SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS, 
+		SND_SOC_HWTDM_LRDW(0,0), WM9713_VOICE_PCM_FORMATS, WM9713_VOICE_RATES, 
+		WM9713_DIR, SND_SOC_HW_BFS_DIV, WM9713_VOICE_FS, WM9713_VOICE_FSB},
+		
+	/* slave modes */
+	{WM9713_VOICE_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), 
+		WM9713_VOICE_PCM_FORMATS, WM9713_VOICE_RATES, WM9713_DIR, 
+		SND_SOC_HW_BFS_DIV, SND_SOC_FS_ALL, SND_SOC_FSB_ALL},
+};
+
+/*
+ * WM9713 register cache
+ */
+static const u16 wm9713_reg[] = {
+	0x6174, 0x8080, 0x8080, 0x8080, // 6  
+	0xc880, 0xe808, 0xe808, 0x0808, // e
+	0x00da, 0x8000, 0xd600, 0xaaa0, // 16
+	0xaaa0, 0xaaa0, 0x0000, 0x0000, // 1e
+	0x0f0f, 0x0040, 0x0000, 0x7f00, // 26
+	0x0405, 0x0410, 0xbb80, 0xbb80, // 2e
+	0x0000, 0xbb80, 0x0000, 0x4523, // 36
+	0x0000, 0x2000, 0xfeff, 0xffff, // 3e
+	0x0000, 0x0000, 0x0080, 0x0000, // 46
+	0x0000, 0x0000, 0xfffe, 0xffff, // 4e
+	0x0000, 0x0000, 0x0000, 0xfffe, // 56
+	0x4000, 0x0000, 0x0000, 0x0000, // 5e
+	0xb032, 0x3e00, 0x0000, 0x0000, // 66
+	0x0000, 0x0000, 0x0000, 0x0000, // 6e
+	0x0000, 0x0000, 0x0000, 0x0006, // 76
+	0x0001, 0x0000, 0x574d, 0x4c13, // 7e
+};
+
+static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
+static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
+static const char* wm9713_rec_src[] = 
+	{"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker", 
+	"Mono Out", "Zh"};
+static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
+static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
+static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv"};
+static const char* wm9713_spk_pga[] = 
+	{"Vmid", "Zh", "Headphone", "Speaker", "Inv", "NC", "NC", "NC"};
+static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone", "NC"};
+static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
+static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
+static const char* wm9713_dac_inv[] = 
+	{"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone", 
+	"Headphone Mono", "NC", "Vmid"};
+static const char* wm9713_bass[] = {"Linear Control", "Adaptive Boost"};
+static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
+static const char* wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"};
+
+static const struct soc_enum wm9713_enum[] = {
+SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */
+SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */
+SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),  /* record mux mono 2 */
+SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src),  /* record mux left 3 */
+SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src),  /* record mux right 4*/
+SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */
+SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/
+SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */
+SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */
+SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */
+SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 4, wm9713_hp_pga), /* headphone left input 10 */
+SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 4, wm9713_hp_pga), /* headphone right input 11 */
+SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */
+SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */
+SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */ 
+SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */
+SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */
+SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */
+SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */
+};
+
+static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = {
+SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1),
+SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1),
+SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
+SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE,15, 7, 1, 1),
+SOC_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
+SOC_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
+SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
+SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
+
+SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
+SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
+
+SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
+SOC_ENUM("Capture Volume Steps", wm9713_enum[5]),
+SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
+SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
+
+SOC_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
+SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
+SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
+
+SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
+SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
+SOC_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
+SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
+SOC_ENUM("ALC Function", wm9713_enum[6]),
+SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
+SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
+SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
+SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
+SOC_ENUM("ALC NG Type", wm9713_enum[17]),
+SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
+
+SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0),
+SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
+SOC_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
+SOC_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
+SOC_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
+SOC_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
+
+SOC_SINGLE("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1),
+SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1),
+SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
+SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1),
+
+SOC_SINGLE("PC Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1),
+SOC_SINGLE("PC Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1),
+SOC_SINGLE("PC Beep Playback Mono Volume", AC97_AUX, 4, 7, 1),
+
+SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1),
+SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1),
+SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1),
+
+SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1),
+SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1),
+SOC_SINGLE("Aux Playback Mono Volume", AC97_REC_SEL, 4, 7, 1),
+
+SOC_ENUM("Bass Control", wm9713_enum[16]),
+SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
+SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
+SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
+SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
+SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
+
+SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
+SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
+SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
+};
+
+/* add non dapm controls */
+static int wm9713_add_controls(struct snd_soc_codec *codec)
+{
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(wm9713_snd_ac97_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm9713_snd_ac97_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	return 0;
+}
+
+/* Headphone Mixers */
+static const snd_kcontrol_new_t wm9713_hp_mixer_controls[] = {
+SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 15, 1, 1),	
+SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 15, 1, 1),
+SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 15, 1, 1),
+SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 15, 1, 1),
+SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 15, 1, 1),
+SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 15, 1, 1),
+};
+
+/* headphone capture mux */
+static const snd_kcontrol_new_t wm9713_hp_rec_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[1]);
+
+/* headphone mic mux */
+static const snd_kcontrol_new_t wm9713_hp_mic_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[0]);
+
+/* Speaker Mixer */
+static const snd_kcontrol_new_t wm9713_speaker_mixer_controls[] = {
+SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 11, 1, 1),	
+SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1),
+SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1),
+SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1),
+SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1),
+SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1),
+};
+
+/* Mono Mixer */
+static const snd_kcontrol_new_t wm9713_mono_mixer_controls[] = {
+SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 7, 1, 1),	
+SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1),
+SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1),
+SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1),
+SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1),
+SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1),
+SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1),
+SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1),
+};
+
+/* mono mic mux */
+static const snd_kcontrol_new_t wm9713_mono_mic_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[2]);
+
+/* mono output mux */
+static const snd_kcontrol_new_t wm9713_mono_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[7]);
+
+/* speaker left output mux */
+static const snd_kcontrol_new_t wm9713_hp_spkl_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[8]);
+
+/* speaker right output mux */
+static const snd_kcontrol_new_t wm9713_hp_spkr_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[9]);
+
+/* headphone left output mux */
+static const snd_kcontrol_new_t wm9713_hpl_out_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[10]);
+
+/* headphone right output mux */
+static const snd_kcontrol_new_t wm9713_hpr_out_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[11]);
+
+/* Out3 mux */
+static const snd_kcontrol_new_t wm9713_out3_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[12]);
+
+/* Out4 mux */
+static const snd_kcontrol_new_t wm9713_out4_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[13]);
+
+/* DAC inv mux 1 */
+static const snd_kcontrol_new_t wm9713_dac_inv1_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[14]);
+
+/* DAC inv mux 2 */
+static const snd_kcontrol_new_t wm9713_dac_inv2_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[15]);
+
+/* Capture source left */
+static const snd_kcontrol_new_t wm9713_rec_srcl_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[3]);
+
+/* Capture source right */
+static const snd_kcontrol_new_t wm9713_rec_srcr_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[4]);
+
+/* mic source */
+static const snd_kcontrol_new_t wm9713_mic_sel_mux_controls =
+SOC_DAPM_ENUM("Route", wm9713_enum[18]);
+
+static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = {
+SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_hp_rec_mux_controls),
+SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_hp_mic_mux_controls),
+SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_mono_mic_mux_controls),
+SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_mono_mux_controls),
+SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_hp_spkl_mux_controls),
+SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_hp_spkr_mux_controls),
+SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_hpl_out_mux_controls),
+SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_hpr_out_mux_controls),
+SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_out3_mux_controls),
+SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_out4_mux_controls),
+SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_dac_inv1_mux_controls),
+SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_dac_inv2_mux_controls),
+SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_rec_srcl_mux_controls),
+SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_rec_srcr_mux_controls),
+SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_DAPM_NOPM, 0, 0, 
+	&wm9713_mic_sel_mux_controls),
+SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_EXTENDED_MID, 3, 1, 
+	&wm9713_hp_mixer_controls[0], ARRAY_SIZE(wm9713_hp_mixer_controls)),
+SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_EXTENDED_MID, 2, 1, 
+	&wm9713_hp_mixer_controls[0], ARRAY_SIZE(wm9713_hp_mixer_controls)),
+SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1, 
+	&wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)),
+SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1, 
+	&wm9713_speaker_mixer_controls[0], ARRAY_SIZE(wm9713_speaker_mixer_controls)),
+SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1, NULL, 0),
+SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1, NULL, 0),
+SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),
+SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1, NULL, 0),
+SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1, NULL, 0),
+SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_EXTENDED_MID, 5, 1, NULL, 0),
+SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_EXTENDED_MID, 4, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0),
+SND_SOC_DAPM_VOLUME("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0),
+SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1),
+SND_SOC_DAPM_OUTPUT("MONO"),
+SND_SOC_DAPM_OUTPUT("HPL"),
+SND_SOC_DAPM_OUTPUT("HPR"),
+SND_SOC_DAPM_OUTPUT("SPKL"),
+SND_SOC_DAPM_OUTPUT("SPKR"),
+SND_SOC_DAPM_OUTPUT("OUT3"),
+SND_SOC_DAPM_OUTPUT("OUT4"),
+SND_SOC_DAPM_INPUT("LINEL"),
+SND_SOC_DAPM_INPUT("LINER"),
+SND_SOC_DAPM_INPUT("MONOIN"),
+SND_SOC_DAPM_INPUT("PCBEEP"),
+SND_SOC_DAPM_INPUT("MIC1"),
+SND_SOC_DAPM_INPUT("MIC2A"),
+SND_SOC_DAPM_INPUT("MIC2B"),
+};
+
+static const char* intercon[][3] = {
+	/* left HP mixer */
+	{"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
+	{"Left HP Mixer", "Voice Playback Switch",   "Voice DAC"},
+	{"Left HP Mixer", "Aux Playback Switch",     "Aux DAC"},
+	{"Left HP Mixer", "Bypass Playback Switch",  "Left Line In"},
+	{"Left HP Mixer", "PCM Playback Switch",     "Left DAC"},
+	{"Left HP Mixer", "MonoIn Playback Switch",  "Mono In"},
+	{"Left HP Mixer", NULL,  "Capture Headphone Mux"},
+	
+	/* right HP mixer */
+	{"Right HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
+	{"Right HP Mixer", "Voice Playback Switch",   "Voice DAC"},
+	{"Right HP Mixer", "Aux Playback Switch",     "Aux DAC"},
+	{"Right HP Mixer", "Bypass Playback Switch",  "Right Line In"},
+	{"Right HP Mixer", "PCM Playback Switch",     "Right DAC"},
+	{"Right HP Mixer", "MonoIn Playback Switch",  "Mono In"},
+	{"Right HP Mixer", NULL,  "Capture Headphone Mux"},
+	
+	/* virtual mixer - mixes left & right channels for spk and mono */
+	{"AC97 Mixer", NULL, "Left DAC"},
+	{"AC97 Mixer", NULL, "Right DAC"},
+	{"Line Mixer", NULL, "Right Line In"},
+	{"Line Mixer", NULL, "Left Line In"},
+	
+	/* speaker mixer */
+	{"Speaker Mixer", "PC Beep Playback Switch", "PCBEEP"},
+	{"Speaker Mixer", "Voice Playback Switch",   "Voice DAC"},
+	{"Speaker Mixer", "Aux Playback Switch",     "Aux DAC"},
+	{"Speaker Mixer", "Bypass Playback Switch",  "Line Mixer"},
+	{"Speaker Mixer", "PCM Playback Switch",     "AC97 Mixer"},
+	{"Speaker Mixer", "MonoIn Playback Switch",  "Mono In"},
+	
+	/* mono mixer */
+	{"Mono Mixer", "PC Beep Playback Switch", "PCBEEP"},
+	{"Mono Mixer", "Voice Playback Switch",   "Voice DAC"},
+	{"Mono Mixer", "Aux Playback Switch",     "Aux DAC"},
+	{"Mono Mixer", "Bypass Playback Switch",  "Line Mixer"},
+	{"Mono Mixer", "PCM Playback Switch",     "AC97 Mixer"},
+	{"Mono Mixer", NULL,  "Capture Mono Mux"},
+	
+	/* DAC inv mux 1 */
+	{"DAC Inv Mux 1", "Mono", "Mono Mixer"},
+	{"DAC Inv Mux 1", "Speaker", "Speaker Mixer"},
+	{"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"},
+	{"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"},
+	{"DAC Inv Mux 1", "Headphone Mono", "Left HP Mixer"},
+	{"DAC Inv Mux 1", "Headphone Mono", "Right HP Mixer"},
+	
+	/* DAC inv mux 2 */
+	{"DAC Inv Mux 2", "Mono", "Mono Mixer"},
+	{"DAC Inv Mux 2", "Speaker", "Speaker Mixer"},
+	{"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"},
+	{"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"},
+	{"DAC Inv Mux 2", "Headphone Mono", "Left HP Mixer"},
+	{"DAC Inv Mux 2", "Headphone Mono", "Right HP Mixer"},
+	
+	/* headphone left mux */
+	{"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
+	
+	/* headphone right mux */
+	{"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
+	
+	/* speaker left mux */
+	{"Left Speaker Out Mux", "Headphone", "Left HP Mixer"},
+	{"Left Speaker Out Mux", "Speaker", "Speaker Mixer"},
+	{"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"},
+	
+	/* speaker right mux */
+	{"Right Speaker Out Mux", "Headphone", "Right HP Mixer"},
+	{"Right Speaker Out Mux", "Speaker", "Speaker Mixer"},
+	{"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"},
+	
+	/* mono mux */
+	{"Mono Out Mux", "Mono", "Mono Mixer"},
+	{"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
+	
+	/* out 3 mux */
+	{"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"}, 
+	
+	/* out 4 mux */
+	{"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
+	
+	/* output pga */
+	{"HPL", NULL, "Left Headphone"},
+	{"Left Headphone", NULL, "Left Headphone Out Mux"},
+	{"HPR", NULL, "Right Headphone"},
+	{"Right Headphone", NULL, "Right Headphone Out Mux"},
+	{"OUT3", NULL, "Out 3"},
+	{"Out 3", NULL, "Out 3 Mux"},
+	{"OUT4", NULL, "Out 4"},
+	{"Out 4", NULL, "Out 4 Mux"},
+	{"SPKL", NULL, "Left Speaker"},
+	{"Left Speaker", NULL, "Left Speaker Out Mux"},
+	{"SPKR", NULL, "Right Speaker"},
+	{"Right Speaker", NULL, "Right Speaker Out Mux"},
+	{"MONO", NULL, "Mono Out"},
+	{"Mono Out", NULL, "Mono Out Mux"},
+		
+	/* input pga */
+	{"Left Line In", NULL, "LINEL"},
+	{"Right Line In", NULL, "LINER"},
+	{"Mono In", NULL, "MONOIN"},
+	{"Mic A PGA", NULL, "Mic A Pre Amp"},
+	{"Mic B PGA", NULL, "Mic B Pre Amp"},
+	
+	/* left capture select */
+	{"Left Capture Source", "Mic 1", "Mic A Pre Amp"},
+	{"Left Capture Source", "Mic 2", "Mic B Pre Amp"},
+	{"Left Capture Source", "Line", "LINEL"},
+	{"Left Capture Source", "Mono In", "MONOIN"},
+	{"Left Capture Source", "Headphone", "Left HP Mixer"},
+	{"Left Capture Source", "Speaker", "Speaker Mixer"},
+	{"Left Capture Source", "Mono Out", "Mono Mixer"},
+	
+	/* right capture select */
+	{"Right Capture Source", "Mic 1", "Mic A Pre Amp"},
+	{"Right Capture Source", "Mic 2", "Mic B Pre Amp"},
+	{"Right Capture Source", "Line", "LINER"},
+	{"Right Capture Source", "Mono In", "MONOIN"},
+	{"Right Capture Source", "Headphone", "Right HP Mixer"},
+	{"Right Capture Source", "Speaker", "Speaker Mixer"},
+	{"Right Capture Source", "Mono Out", "Mono Mixer"},
+	
+	/* left ADC */
+	{"Left ADC", NULL, "Left Capture Source"},
+	
+	/* right ADC */
+	{"Right ADC", NULL, "Right Capture Source"},
+	
+	/* mic */
+	{"Mic A Pre Amp", NULL, "Mic A Source"},
+	{"Mic A Source", "Mic 1", "MIC1"},
+	{"Mic A Source", "Mic 2 A", "MIC2A"},
+	{"Mic A Source", "Mic 2 B", "MIC2B"},
+	{"Mic B Pre Amp", NULL, "Mic B Source"},
+	{"Mic B Source", NULL, "MIC2B"},
+	
+	/* headphone capture */
+	{"Capture Headphone Mux", "Stereo", "Left Capture Source"},
+	{"Capture Headphone Mux", "Stereo", "Right Capture Source"},
+	{"Capture Headphone Mux", "Left", "Left Capture Source"},
+	{"Capture Headphone Mux", "Right", "Right Capture Source"},
+	
+	/* mono capture */
+	{"Capture Mono Mux", "Stereo", "Left Capture Source"},
+	{"Capture Mono Mux", "Stereo", "Right Capture Source"},
+	{"Capture Mono Mux", "Left", "Left Capture Source"},
+	{"Capture Mono Mux", "Right", "Right Capture Source"},
+	
+	{NULL, NULL, NULL},
+	
+};
+
+static int wm9713_add_widgets(struct snd_soc_codec *codec)
+{
+	int i;
+
+	for(i = 0; i < ARRAY_SIZE(wm9713_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &wm9713_dapm_widgets[i]);
+	}
+
+	/* set up audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+
+	snd_soc_dapm_new_widgets(codec);
+	return 0;
+}
+
+static unsigned int ac97_read(struct snd_soc_codec *codec, 
+	unsigned int reg)
+{
+	u16 *cache = codec->reg_cache;
+
+	if (reg == AC97_RESET || reg == AC97_GPIO_STATUS || 
+		reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
+		reg == AC97_CD)
+		return soc_ac97_ops.read(codec->ac97, reg);
+	else {
+		reg = reg >> 1;
+		
+		if(reg > (ARRAY_SIZE(wm9713_reg)))
+			return -EIO;
+		
+		return cache[reg];
+	}
+}
+
+static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
+	unsigned int val)
+{
+	u16 *cache = codec->reg_cache;
+
+	soc_ac97_ops.write(codec->ac97, reg, val);
+	reg = reg >> 1;
+	if(reg <= (ARRAY_SIZE(wm9713_reg)))
+		cache[reg] = val;
+	
+	return 0;
+}
+
+static int ac97_prepare(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	int reg;
+	u16 vra;
+	
+	vra = ac97_read(codec, AC97_EXTENDED_STATUS);
+	ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		reg = AC97_PCM_FRONT_DAC_RATE;
+	else
+		reg = AC97_PCM_LR_ADC_RATE;
+
+	return ac97_write(codec, reg, runtime->rate);
+}
+
+static int ac97_aux_prepare(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 vra, xsle;
+	
+	vra = ac97_read(codec, AC97_EXTENDED_STATUS);
+	ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
+	xsle = ac97_read(codec, AC97_PCI_SID);
+	ac97_write(codec, AC97_PCI_SID, xsle | 0x8000);
+	
+	if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
+		return -ENODEV;
+
+	return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
+}
+
+static unsigned int wm9713_config_vsysclk(struct snd_soc_pcm_codec *pcm_codec, 
+	int rate, unsigned int clk)
+{
+	pcm_codec->mclk = clk;
+	return rate << 8;
+}
+
+static int wm9713_voice_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->codec;
+	u16 reg = 0x8000, bfs, fs;
+		
+	bfs = SND_SOC_FSBD_INT(rtd->pcm_c->hw_runtime.hwbfs);
+	fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+	
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK){
+	case SND_SOC_HWFMT_CBM_CFM:
+		reg |= 0x4000;
+		break;
+	case SND_SOC_HWFMT_CBM_CFS:
+		reg |= 0x6000;
+		break;
+	case SND_SOC_HWFMT_CBS_CFS:
+		reg |= 0x0200;
+		break;
+	}
+	
+	/* clock inversion */
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK) {
+	case SND_SOC_HWFMT_IB_IF:
+		reg |= 0x00c0;
+		break;
+	case SND_SOC_HWFMT_IB_NF:
+		reg |= 0x0080;
+		break;
+	case SND_SOC_HWFMT_NB_IF:
+		reg |= 0x0040;
+		break;
+	}
+	
+	switch(rtd->pcm_c->hw_runtime.hwfmt & SND_SOC_HWFMT_FORMAT_MASK) {
+	case SND_SOC_HWFMT_I2S:
+		reg |= 0x0002;
+		break;
+	case SND_SOC_HWFMT_RIGHT_J:
+		break;
+	case SND_SOC_HWFMT_LEFT_J:
+		reg |= 0x0001;
+		break;
+	case SND_SOC_HWFMT_DSP_A:
+		reg |= 0x0003;
+		break;
+	case SND_SOC_HWFMT_DSP_B:
+		reg |= 0x0043;
+		break;
+	}
+	
+	switch(rtd->pcm_c->hw_runtime.hwpcmfmt) {
+	case SNDRV_PCM_FORMAT_S16_LE:
+		break;
+	case SNDRV_PCM_FORMAT_S20_3LE:
+		reg |= 0x0004;
+		break;
+	case SNDRV_PCM_FORMAT_S24_3LE:
+		reg |= 0x0008;
+		break;
+	case SNDRV_PCM_FORMAT_S32_LE:
+		reg |= 0x000c;
+		break;
+	}
+	
+	switch (bfs) {
+	case 2:
+		reg |= (0x1 << 9);
+		break;
+	case 4:
+		reg |= (0x2 << 9);
+		break;
+	case 8:
+		reg |= (0x3 << 9);
+		break;
+	case 16:
+		reg |= (0x4 << 9);
+		break;
+	}		
+	
+	/* enable PCM interface in master mode */
+	ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
+
+	/* sample rate */
+	reg = ac97_read(codec, AC97_HANDSET_RATE) &0xe0ff;
+	switch(snd_soc_get_rate(rtd->pcm_c->hw_runtime.hwpcmrate)){
+	case 8000:
+		reg |= (0xb << 8);
+		break;
+	case 16000:
+		reg |= (0x5 << 8);
+		break;
+	case 32000:
+		reg |= (0x2 << 8);
+		break;
+	case 48000:
+		reg |= (0x1 << 8);
+		break;
+	}
+	ac97_write(codec, AC97_HANDSET_RATE, reg | rtd->pcm_c->hw_runtime.priv);
+	return 0;
+}
+
+static struct snd_soc_pcm_codec wm9713_soc_client[] = {
+{
+	.name = "AC97 HiFi",
+	.playback = {
+		.sname = "HiFi Playback",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.capture = {
+		.sname = "HiFi Capture",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.nplayback = 1,
+	.ncapture = 1,
+	.ops = {
+		.prepare = ac97_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(soc_ac97),
+		.hmodes = &soc_ac97[0],},},
+	{
+	.name = "AC97 Aux",
+	.playback = {
+		.sname = "Aux Playback",
+		.channels_min = 1,
+		.channels_max = 1,},
+	.nplayback = 1,
+	.ops = {
+		.prepare = ac97_aux_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(soc_ac97),
+		.hmodes = &soc_ac97[0],},
+	},
+	{
+	.name = "WM9713 Voice",
+	.playback = {
+		.sname = "Voice Playback",
+		.channels_min = 1,
+		.channels_max = 1,},
+	.nplayback = 1,
+	.capture = {
+		.sname = "Voice Capture",
+		.channels_min = 1,
+		.channels_max = 1,},
+	.ncapture = 1,
+	.config_sysclk = wm9713_config_vsysclk,
+	.ops = {
+		.prepare = wm9713_voice_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm9713_voice),
+		.hmodes = &wm9713_voice[0],},
+	},
+};
+
+static int wm9713_reset(struct snd_soc_codec *codec, int try_warm)
+{
+	if(try_warm && soc_ac97_ops.warm_reset) {
+		soc_ac97_ops.warm_reset(codec->ac97);
+		if(!(ac97_read(codec, 0) & 0x8000)) 
+			return 1;
+	}
+	
+	soc_ac97_ops.reset(codec->ac97);
+	if(ac97_read(codec, 0) & 0x8000)
+		return -EIO;
+	return 0;
+}
+
+static int wm9713_dapm_event(struct snd_soc_codec *codec, int event)
+{
+	u16 reg;
+	
+	switch (event) {
+		case SNDRV_CTL_POWER_D0: /* full On */
+			/* liam - maybe enable thermal shutdown */
+			reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xdfff;
+			ac97_write(codec, AC97_EXTENDED_MID, reg);
+			//reg = ac97_read(codec, AC97_POWERDOWN) & 0xdfff;
+			//ac97_write(codec, AC97_POWERDOWN, reg);
+			break;
+		case SNDRV_CTL_POWER_D1: /* partial On */
+		case SNDRV_CTL_POWER_D2: /* partial On */
+			break;
+		case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+			/* enable master bias and vmid */
+			reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xbbff;
+			ac97_write(codec, AC97_EXTENDED_MID, reg);
+			ac97_write(codec, AC97_POWERDOWN, 0x0000);
+			break;
+		case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+			/* disable everything including AC link */
+			ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
+			ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
+			ac97_write(codec, AC97_POWERDOWN, 0xffff);
+			break;
+	}
+	codec->dapm_state = event;
+	return 0;
+}
+
+static int wm9713_soc_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+
+	wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+	return 0;
+}
+
+static int wm9713_soc_resume(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	int i, ret;
+	u16 *cache = codec->reg_cache;
+	
+	if((ret = wm9713_reset(codec, 1)) < 0){
+		printk(KERN_ERR "could not reset AC97 codec\n");
+		return ret;
+	}
+	
+	wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+
+	/* only sychronise the codec if warm reset failed */
+	if(ret == 0) {
+		for (i = 2; i < ARRAY_SIZE(wm9713_reg) << 1; i+=2) {
+			if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID ||
+				i == AC97_EXTENDED_MSTATUS || i > 0x66)
+				continue; 
+			soc_ac97_ops.write(codec->ac97, i, cache[i>>1]);
+		}
+	}
+	
+	if(codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
+		wm9713_dapm_event(codec, SNDRV_CTL_POWER_D0);
+	
+	return ret;
+}
+
+static int wm9713_soc_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec;
+	int ret = 0;
+
+	printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION);
+
+	if ((socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	codec = socdev->codec;
+	
+	if ((codec->reg_cache = 
+			kzalloc(sizeof(u16) * ARRAY_SIZE(wm9713_reg), GFP_KERNEL)) == NULL){
+		kfree(socdev->codec);
+		socdev->codec = NULL;
+		return -ENOMEM;
+	}
+	memcpy(codec->reg_cache, wm9713_reg, sizeof(u16) * ARRAY_SIZE(wm9713_reg));
+
+	codec->name = "WM9713";
+	codec->owner = THIS_MODULE;
+	codec->pcms = wm9713_soc_client;
+	codec->npcms = ARRAY_SIZE(wm9713_soc_client);
+	codec->write = ac97_write;
+	codec->read = ac97_read;
+	codec->dapm_event = wm9713_dapm_event;
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+
+	if((ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0)) < 0)
+		goto err;
+
+	/* register pcms */
+	if((ret = snd_soc_new_pcms(socdev)) < 0)
+		goto pcm_err;
+		
+	/* do a cold reset for the controller and then try 
+	 * a warm reset followed by an optional cold reset for codec */
+	wm9713_reset(codec, 0);
+	if((ret = wm9713_reset(codec, 1)) < 0)	{
+		printk(KERN_ERR "AC97 link error\n");
+		goto reset_err;
+	}
+
+	wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+	wm9713_add_controls(codec);
+	wm9713_add_widgets(codec);
+	snd_soc_register_card(socdev);
+	return 0;
+	
+reset_err:	
+	snd_soc_free_pcms(socdev);
+	
+pcm_err:	
+	snd_soc_free_ac97_codec(codec);
+	
+err:
+	kfree(socdev->codec->reg_cache);
+	kfree(socdev->codec);
+	socdev->codec = NULL;
+	return ret;
+}
+
+static int wm9713_soc_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec* codec = socdev->codec;
+	
+	if(codec == NULL)
+		return 0;
+	
+	snd_soc_dapm_free(socdev);
+	snd_soc_free_pcms(socdev);
+	snd_soc_free_ac97_codec(codec);
+	kfree(codec->reg_cache);
+	kfree(codec);
+	return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_wm9713= {
+	.probe = 	wm9713_soc_probe,
+	.remove = 	wm9713_soc_remove,
+	.suspend =	wm9713_soc_suspend,
+	.resume = 	wm9713_soc_resume,
+};
+
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713);
+
+MODULE_DESCRIPTION("Soc WM9713/WM9714 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
+
diff --git a/sound/soc/codecs/wm9713.h b/sound/soc/codecs/wm9713.h
new file mode 100644
index 0000000..99f16d1
--- /dev/null
+++ b/sound/soc/codecs/wm9713.h
@@ -0,0 +1,10 @@
+/*
+ * wm9713.h  --  WM9713 Soc Audio driver
+ */
+
+#ifndef _WM9713_H
+#define _WM9713_H
+
+extern struct snd_soc_codec_device soc_codec_dev_wm9713;
+	
+#endif
diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig
new file mode 100644
index 0000000..a3cec54
--- /dev/null
+++ b/sound/soc/pxa/Kconfig
@@ -0,0 +1,84 @@
+menu "SoC Audio for the Intel PXA2xx"
+
+config SND_PXA2xx_SOC
+	tristate "SoC Audio for the Intel PXA2xx chip"
+	depends on ARCH_PXA && SND
+	select SND_PCM
+	help
+	  Say Y or M if you want to add support for codecs attached to
+	  the PXA2xx AC97, I2S or SSP interface. You will also need
+	  to select the audio interfaces to support below.
+
+config SND_PXA2xx_AC97
+	tristate
+	select SND_AC97_CODEC
+
+config SND_PXA2xx_SOC_AC97
+	tristate
+	select SND_AC97_BUS
+	  
+config SND_PXA2xx_SOC_I2S
+	tristate
+
+config SND_PXA2xx_SOC_SSP
+	tristate
+	select PXA_SSP
+	
+config SND_PXA2xx_SOC_MAINSTONE
+	tristate "SoC AC97 Audio support for Intel Mainstone"
+	depends on SND_PXA2xx_SOC
+	select SND_PXA2xx_AC97
+	help
+	  Say Y if you want to add support for generic AC97 SoC audio on Mainstone.
+
+config SND_PXA2xx_SOC_MAINSTONE_WM8753
+	tristate "SoC I2S/SSP Audio support for Intel Mainstone - WM8753"
+	depends on SND_PXA2xx_SOC
+	select SND_PXA2xx_SOC_I2S
+	select SND_PXA2xx_SOC_SSP
+	help
+	  Say Y if you want to add support for SoC audio on Mainstone
+	  with the WM8753.
+	  
+config SND_PXA2xx_SOC_MAINSTONE_WM9713
+	tristate "SoC I2S/SSP Audio support for Intel Mainstone - WM9713"
+	depends on SND_PXA2xx_SOC
+	select SND_PXA2xx_SOC_AC97
+	select SND_PXA2xx_SOC_SSP
+	help
+	  Say Y if you want to add support for SoC voice audio on Mainstone
+	  with the WM9713.
+
+config SND_PXA2xx_SOC_MAINSTONE_WM9712
+	tristate "SoC I2S/SSP Audio support for Intel Mainstone - WM9712"
+	depends on SND_PXA2xx_SOC
+	select SND_PXA2xx_SOC_AC97
+	help
+	  Say Y if you want to add support for SoC voice audio on Mainstone
+	  with the WM9712.
+
+config SND_PXA2xx_SOC_CORGI
+	tristate "SoC Audio support for Corgi"
+	depends on SND_PXA2xx_SOC
+	select SND_PXA2xx_SOC_I2S
+	help
+	  Say Y if you want to add support for SoC audio on Sharp
+	  Zaurus SL-C7x0 models.
+
+config SND_PXA2xx_SOC_SPITZ
+	tristate "SoC Audio support for Spitz"
+	depends on SND_PXA2xx_SOC
+	select SND_PXA2xx_SOC_I2S
+	help
+	  Say Y if you want to add support for SoC audio on Sharp
+	  Zaurus SL-Cxx00 models.
+
+config SND_PXA2xx_SOC_TOSA
+	tristate "SoC AC97 Audio support for Tosa"
+	depends on SND_PXA2xx_SOC
+	select SND_PXA2xx_SOC_AC97
+	help
+	  Say Y if you want to add support for SoC audio on Sharp
+	  Zaurus SL-C6000x models.
+
+endmenu
diff --git a/sound/soc/pxa/Makefile b/sound/soc/pxa/Makefile
new file mode 100644
index 0000000..b09334c
--- /dev/null
+++ b/sound/soc/pxa/Makefile
@@ -0,0 +1,26 @@
+# PXA Platform Support
+snd-soc-pxa2xx-objs := pxa2xx-pcm.o
+snd-soc-pxa2xx-ac97-objs := pxa2xx-ac97.o
+snd-soc-pxa2xx-i2s-objs := pxa2xx-i2s.o
+snd-soc-pxa2xx-ssp-objs := pxa2xx-ssp.o
+
+obj-$(CONFIG_SND_PXA2xx_SOC) += snd-soc-pxa2xx.o
+obj-$(CONFIG_SND_PXA2xx_SOC_AC97) += snd-soc-pxa2xx-ac97.o
+obj-$(CONFIG_SND_PXA2xx_SOC_I2S) += snd-soc-pxa2xx-i2s.o
+obj-$(CONFIG_SND_PXA2xx_SOC_SSP) += snd-soc-pxa2xx-ssp.o
+
+# PXA Machine Support
+snd-soc-corgi-objs := corgi.o
+snd-soc-mainstone-wm8753-objs := mainstone_wm8753.o
+snd-soc-mainstone-wm9713-objs := mainstone_wm9713.o
+snd-soc-mainstone-wm9712-objs := mainstone_wm9712.o
+snd-soc-tosa-objs := tosa.o
+snd-soc-spitz-objs := spitz.o
+
+obj-$(CONFIG_SND_PXA2xx_SOC_CORGI) += snd-soc-corgi.o
+obj-$(CONFIG_SND_PXA2xx_SOC_MAINSTONE_WM8753) += snd-soc-mainstone-wm8753.o
+obj-$(CONFIG_SND_PXA2xx_SOC_MAINSTONE_WM9713) += snd-soc-mainstone-wm9713.o
+obj-$(CONFIG_SND_PXA2xx_SOC_MAINSTONE_WM9712) += snd-soc-mainstone-wm9712.o
+obj-$(CONFIG_SND_PXA2xx_SOC_TOSA) += snd-soc-tosa.o
+obj-$(CONFIG_SND_PXA2xx_SOC_SPITZ) += snd-soc-spitz.o
+
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
new file mode 100644
index 0000000..8dc768a
--- /dev/null
+++ b/sound/soc/pxa/corgi.c
@@ -0,0 +1,310 @@
+/*
+ * corgi.c  --  SoC audio for Corgi
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Copyright 2005 Openedhand Ltd.
+ * 
+ * Authors: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
+ *          Richard Purdie <richard@openedhand.com>
+ * 
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    30th Nov 2005   Initial version.
+ * 
+ */
+ 
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/hardware/scoop.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/corgi.h>
+#include <asm/arch/audio.h>
+
+#include "../codecs/wm8731.h"
+#include "pxa2xx-pcm.h"
+
+#define CORGI_HP        0
+#define CORGI_MIC       1
+#define CORGI_LINE      2
+#define CORGI_HEADSET   3
+#define CORGI_HP_OFF    4
+#define CORGI_SPK_AUTO  0
+#define CORGI_SPK_ON    1
+#define CORGI_SPK_OFF   2
+
+static int corgi_jack_func = 0;
+static int corgi_spk_func = 0;
+
+#define READ_GPIO_BIT(x)    (GPLR(x) & GPIO_bit(x))
+
+static void corgi_ext_control(struct snd_soc_codec *codec)
+{
+	int spk = 0, mic = 0, line = 0, hp = 0;
+	
+	/* set up jack connection */
+	switch(corgi_jack_func) {
+	case CORGI_HP:
+		hp = 1;
+		break;
+	case CORGI_MIC:
+		mic = 1;
+		break;
+	case CORGI_LINE:
+		line = 1;
+		break;
+	case CORGI_HEADSET:
+		hp = 1;
+		mic = 1;
+		break;
+	}
+
+	if ((READ_GPIO_BIT(CORGI_GPIO_AK_INT) && (corgi_spk_func == CORGI_SPK_AUTO))
+			|| (corgi_spk_func == CORGI_SPK_ON))
+		spk = 1;
+
+	snd_soc_dapm_set_endpoint(codec, "Ext Spk", spk);
+	snd_soc_dapm_set_endpoint(codec, "Mic Jack", mic);
+	snd_soc_dapm_set_endpoint(codec, "Line Jack", line);
+	snd_soc_dapm_set_endpoint(codec, "Headphone Jack", hp);
+	snd_soc_dapm_new_widgets(codec);
+}
+
+static int corgi_startup(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_codec *codec = rtd->socdev->codec;
+
+	/* check the jack status at stream startup */	
+	corgi_ext_control(codec);
+	return 0;
+}
+
+static struct snd_soc_ops corgi_ops = {
+	.startup = corgi_startup,
+};
+
+static int corgi_get_jack(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.integer.value[0] = corgi_jack_func;
+	return 0;
+}
+
+static int corgi_set_jack(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{	
+	struct snd_soc_codec *codec =  snd_kcontrol_chip(kcontrol);
+	corgi_jack_func = ucontrol->value.integer.value[0];
+	corgi_ext_control(codec);
+	return 0;
+}
+
+static int corgi_get_spk(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.integer.value[0] = corgi_spk_func;
+	return 0;
+}
+
+static int corgi_set_spk(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec =  snd_kcontrol_chip(kcontrol);
+	corgi_spk_func = ucontrol->value.integer.value[0];
+	corgi_ext_control(codec);
+	return 0;
+}
+
+/* corgi dapm event handlers */
+static int corgi_hp_event(struct snd_soc_dapm_widget* w, int power)
+{
+	if (power){
+		set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_L);
+		set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_R);
+	} else {
+		reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_L);
+		reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_R);
+	}
+	return 0;
+}
+
+static int corgi_amp_event(struct snd_soc_dapm_widget* w, int power)
+{
+	if (power)
+		set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_APM_ON);
+	else
+		reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_APM_ON);
+		
+	return 0;
+}
+
+static int corgi_mic_event(struct snd_soc_dapm_widget* w, int power)
+{
+	if (power)
+		set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MIC_BIAS);
+	else
+		reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MIC_BIAS);
+	
+	return 0;
+}
+
+/* corgi machine dapm widgets */
+static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
+SND_SOC_DAPM_HP("Headphone Jack", corgi_hp_event),
+SND_SOC_DAPM_MIC("Mic Jack", corgi_mic_event),
+SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event),
+SND_SOC_DAPM_LINE("Line Jack", NULL),
+};
+
+/* Corgi machine interconnections */
+static const char* intercon[][3] = {
+	
+	/* headphone connected to LHPOUT1, RHPOUT1 */
+	{"Headphone Jack", NULL, "LHPOUT"},
+	{"Headphone Jack", NULL, "RHPOUT"},
+	
+	/* speaker connected to LOUT, ROUT */
+	{"Ext Spk", NULL, "ROUT"},
+	{"Ext Spk", NULL, "LOUT"},
+	
+	/* mic is connected to LINEIN - with bias */
+	{"LLINEIN", NULL, "Mic Bias"},
+	{"Mic Bias", NULL, "Mic Jack"},
+	
+	/* line is connected to LINEIN - no bias */
+	{"LLINEIN", NULL, "Line Jack"},
+
+	{NULL, NULL, NULL},
+};
+
+static const char* jack_function[] = {"Headphone", "Mic", "Line", "Headset", "Off"};
+static const char* spk_function[] = {"Auto", "On", "Off"};
+static const struct soc_enum corgi_enum[] = {
+	SOC_ENUM_SINGLE_EXT(5, jack_function),
+	SOC_ENUM_SINGLE_EXT(3, spk_function),
+};
+
+static const snd_kcontrol_new_t wm8731_corgi_controls[] = {
+	SOC_ENUM_EXT("Jack Function", corgi_enum[0], corgi_get_jack, corgi_set_jack),
+	SOC_ENUM_EXT("Speaker Function", corgi_enum[1], corgi_get_spk, corgi_set_spk),
+};
+
+/*
+ * Logic for a wm8731 as connected on a Sharp SL-C7x0 Device
+ */
+static int corgi_wm8731_init(struct snd_soc_codec *codec)
+{
+	int i, err;
+
+	snd_soc_dapm_set_endpoint(codec, "RLINEIN", 0);
+
+	/* Add corgi specific controls */
+	for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm8731_corgi_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+
+	/* Add corgi specific widgets */
+	for(i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
+	}
+	
+	/* Set up corgi specific audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_sync_endpoints(codec);
+	return 0;
+}
+
+unsigned int corgi_config_sysclk(struct snd_soc_pcm_runtime *rtd, 
+	int rate, unsigned int hwfmt)
+{
+	if(hwfmt & SND_SOC_HWFMT_CBS_CFS) {
+		if(rtd->pcm_i->config_sysclk)
+			return rtd->pcm_i->config_sysclk(rtd->pcm_i, rate, 0);
+	} else {
+		/* corgi has a 12.235MHz sysclk - we round to a nice audio 12.288 */
+		if(rtd->pcm_c->config_sysclk)
+			return rtd->pcm_c->config_sysclk(rtd->pcm_c, rate, 12288000);
+	}
+	
+	return 0;
+}
+
+static struct snd_soc_machine_config codecs = {
+	.name = "WM8731", 
+	.sname = "WM8731",
+	.iface = &pxa_i2s_interface,
+	.init = corgi_wm8731_init,
+	.config_sysclk = corgi_config_sysclk,
+};
+
+static struct snd_soc_machine snd_soc_machine_corgi = {
+	.name = "Corgi",
+	.config = &codecs,
+	.nconfigs = 1,
+	.ops = &corgi_ops,
+};
+
+static struct wm8731_setup_data corgi_wm8731_setup = {
+	.i2c_address = 0x1b,
+};
+
+static struct snd_soc_device corgi_snd_devdata = {
+	.machine = &snd_soc_machine_corgi,
+	.platform = &pxa2xx_soc_platform,
+	.codec_dev = &soc_codec_dev_wm8731,
+	.codec_data = &corgi_wm8731_setup,
+};
+
+static struct platform_device *corgi_snd_device;
+
+static int __init corgi_init(void) 
+{
+	int ret;
+
+	pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN);
+
+	corgi_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!corgi_snd_device) {
+		free_irq(CORGI_IRQ_GPIO_AK_INT, corgi_snd_device);
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(corgi_snd_device, &corgi_snd_devdata);
+	corgi_snd_devdata.dev = &corgi_snd_device->dev;
+	ret = platform_device_add(corgi_snd_device);
+
+	if (ret)
+		platform_device_put(corgi_snd_device);
+
+	return ret;
+}
+
+static void __exit corgi_exit(void) 
+{
+	platform_device_unregister(corgi_snd_device);
+}
+
+module_init(corgi_init);
+module_exit(corgi_exit);
+
+/* Module information */ 
+MODULE_AUTHOR("Richard Purdie");
+MODULE_DESCRIPTION("ALSA SoC Corgi");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/mainstone.c b/sound/soc/pxa/mainstone.c
new file mode 100644
index 0000000..93fc5de
--- /dev/null
+++ b/sound/soc/pxa/mainstone.c
@@ -0,0 +1,128 @@
+/*
+ * mainstone.c  --  SoC audio for Mainstone
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  Mainstone audio amplifier code taken from arch/arm/mach-pxa/mainstone.c
+ *  Copyright:	MontaVista Software Inc.
+ * 
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    30th Oct 2005   Initial version.
+ * 
+ */
+ 
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/mainstone.h>
+#include <asm/arch/audio.h>
+
+#include "../codecs/ac97.h"
+#include "pxa2xx-pcm.h"
+
+static struct snd_soc_machine mainstone;
+static long mst_audio_suspend_mask;
+
+static int mainstone_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	mst_audio_suspend_mask = MST_MSCWR2;
+	MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_resume(struct platform_device *pdev)
+{
+	MST_MSCWR2 &= mst_audio_suspend_mask | ~MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_probe(struct platform_device *pdev)
+{
+	MST_MSCWR2 &= ~MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_remove(struct platform_device *pdev)
+{
+	MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static struct snd_soc_machine_config codecs[] = {
+{
+	.name = "AC97", 
+	.sname = "AC97 HiFi", 
+	.iface = &pxa_ac97_interface[0],
+},
+{
+	.name = "AC97 Aux", 
+	.sname = "AC97 Aux",
+	.iface = &pxa_ac97_interface[1],
+},
+};
+
+static struct snd_soc_machine mainstone = {
+	.name = "Mainstone",
+	.probe = mainstone_probe,
+	.remove = mainstone_remove,
+	.suspend_pre = mainstone_suspend,
+	.resume_post = mainstone_resume,
+	.config = codecs,
+	.nconfigs = ARRAY_SIZE(codecs),
+};
+
+static struct snd_soc_device mainstone_snd_devdata = {
+	.machine = &mainstone,
+	.platform = &pxa2xx_soc_platform,
+	.codec_dev = &soc_codec_dev_ac97,
+};
+
+static struct platform_device *mainstone_snd_device;
+
+static int __init mainstone_init(void) 
+{
+	int ret;
+
+	mainstone_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!mainstone_snd_device)
+		return -ENOMEM;
+
+	platform_set_drvdata(mainstone_snd_device, &mainstone_snd_devdata);
+	mainstone_snd_devdata.dev = &mainstone_snd_device->dev;
+	ret = platform_device_add(mainstone_snd_device);
+
+	if (ret)
+		platform_device_put(mainstone_snd_device);
+
+	return ret;
+}
+
+static void __exit mainstone_exit(void) 
+{
+	platform_device_unregister(mainstone_snd_device);
+}
+
+module_init(mainstone_init);
+module_exit(mainstone_exit);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("ALSA SoC Mainstone");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/mainstone_wm8753.c b/sound/soc/pxa/mainstone_wm8753.c
new file mode 100644
index 0000000..8dda76d
--- /dev/null
+++ b/sound/soc/pxa/mainstone_wm8753.c
@@ -0,0 +1,245 @@
+/*
+ * mainstone.c  --  SoC audio for Mainstone
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  Mainstone audio amplifier code taken from arch/arm/mach-pxa/mainstone.c
+ *  Copyright:	MontaVista Software Inc.
+ * 
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    30th Oct 2005   Initial version.
+ * 
+ */
+ 
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/mainstone.h>
+#include <asm/arch/audio.h>
+
+#include "../codecs/wm8753.h"
+#include "pxa2xx-pcm.h"
+
+static struct snd_soc_machine mainstone;
+
+static int mainstone_startup(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	
+	if(rtd->pcm_i->type == SND_SOC_SSP && rtd->pcm_i->id == 1) {
+		/* enable USB on the go MUX so we can use SSPFRM2 */
+		MST_MSCWR2 |= MST_MSCWR2_USB_OTG_SEL;
+		MST_MSCWR2 &= ~MST_MSCWR2_USB_OTG_RST;
+	}
+	return 0;
+}
+
+static void mainstone_shutdown(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+			
+	if(rtd->pcm_i->type == SND_SOC_SSP && rtd->pcm_i->id == 1) {
+		/* disable USB on the go MUX so we can use ttyS0 */
+		MST_MSCWR2 &= ~MST_MSCWR2_USB_OTG_SEL;
+		MST_MSCWR2 |= MST_MSCWR2_USB_OTG_RST;
+	}
+}
+
+static struct snd_soc_ops mainstone_ops = {
+	.startup = mainstone_startup,
+	.shutdown = mainstone_shutdown,
+};
+
+static long mst_audio_suspend_mask;
+
+static int mainstone_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	mst_audio_suspend_mask = MST_MSCWR2;
+	MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_resume(struct platform_device *pdev)
+{
+	MST_MSCWR2 &= mst_audio_suspend_mask | ~MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_probe(struct platform_device *pdev)
+{
+	MST_MSCWR2 &= ~MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_remove(struct platform_device *pdev)
+{
+	MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+/* example machine interconnections */
+static const char* intercon[][3] = {
+	
+	/* mic is connected to mic1 - with bias */
+	{"MIC1", NULL, "Mic Bias"},
+	{"MIC1N", NULL, "Mic Bias"},
+	{"Mic Bias", NULL, "Mic1 Jack"},
+	{"Mic Bias", NULL, "Mic1 Jack"},
+	
+	{"ACIN", NULL, "ACOP"},
+	{NULL, NULL, NULL},
+};
+
+/* headphone detect support on my board */
+static const char * hp_pol[] = {"Headphone", "Speaker"};
+static const struct soc_enum wm8753_enum =
+	SOC_ENUM_SINGLE(WM8753_OUTCTL, 1, 2, hp_pol);
+
+static const snd_kcontrol_new_t wm8753_mainstone_controls[] = {
+	SOC_SINGLE("Headphone Detect Switch", WM8753_OUTCTL, 6, 1, 0),
+	SOC_ENUM("Headphone Detect Polarity", wm8753_enum),
+};
+
+/*
+ * This is an example machine initialisation for a wm8753 connected to a 
+ * Mainstone II. It is missing logic to detect hp/mic insertions and logic
+ * to re-route the audio in such an event.
+ */
+
+static int mainstone_wm8753_init(struct snd_soc_codec *codec)
+{
+	int i, err;
+		
+	/* set up mainstone codec pins */
+	snd_soc_dapm_set_endpoint(codec, "RXP", 0);
+	snd_soc_dapm_set_endpoint(codec, "RXN", 0);
+	snd_soc_dapm_set_endpoint(codec, "MIC2", 0);
+	
+	/* add mainstone specific controls */
+	for (i = 0; i < ARRAY_SIZE(wm8753_mainstone_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm8753_mainstone_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+	
+	/* set up mainstone specific audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_sync_endpoints(codec);
+	return 0;
+}
+
+unsigned int mainstone_config_sysclk(struct snd_soc_pcm_runtime *rtd, 
+	int rate, unsigned int hwfmt)
+{
+	if(hwfmt & SND_SOC_HWFMT_CBS_CFS) {
+		if(rtd->pcm_i->config_sysclk)
+			return rtd->pcm_i->config_sysclk(rtd->pcm_i, rate, 0);
+	} else {
+		/* wm8753 has pll that generates mclk from 13MHz xtal */
+		if(rtd->pcm_c->config_sysclk)
+			return rtd->pcm_c->config_sysclk(rtd->pcm_c, rate, 13000000);
+	}
+	
+	return 0;
+}
+
+unsigned int mainstone_config_vsysclk(struct snd_soc_pcm_runtime *rtd, 
+	int rate, unsigned int hwfmt)
+{
+	/* wm8753 has pll that generates mclk from 13MHz xtal */
+	if(rtd->pcm_c->config_sysclk)
+		return rtd->pcm_c->config_sysclk(rtd->pcm_c, rate, 13000000);
+	
+	return 0;
+}
+
+static struct snd_soc_machine_config codecs[] = {
+{
+	.name = "WM8753", 
+	.sname = "WM8753 HiFi",
+	.iface = &pxa_i2s_interface,
+	.init = mainstone_wm8753_init,
+	.config_sysclk = mainstone_config_sysclk,
+},
+{
+	.name = "WM8753", 
+	.sname = "WM8753 Voice",
+	.iface = &pxa_ssp_interface[1],
+	.config_sysclk = mainstone_config_vsysclk,
+},
+};
+
+static struct snd_soc_machine mainstone = {
+	.name = "Mainstone",
+	.probe = mainstone_probe,
+	.remove = mainstone_remove,
+	.suspend_pre = mainstone_suspend,
+	.resume_post = mainstone_resume,
+	.ops = &mainstone_ops,
+	.config = codecs,
+	.nconfigs = ARRAY_SIZE(codecs),
+};
+
+static struct wm8753_setup_data corgi_wm8753_setup = {
+	.i2c_address = 0x1a,
+};
+
+static struct snd_soc_device mainstone_snd_devdata = {
+	.machine = &mainstone,
+	.platform = &pxa2xx_soc_platform,
+	.codec_dev = &soc_codec_dev_wm8753,
+	.codec_data = &corgi_wm8753_setup,
+};
+
+static struct platform_device *mainstone_snd_device;
+
+static int __init mainstone_init(void) 
+{
+	int ret;
+
+	mainstone_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!mainstone_snd_device)
+		return -ENOMEM;
+
+	platform_set_drvdata(mainstone_snd_device, &mainstone_snd_devdata);
+	mainstone_snd_devdata.dev = &mainstone_snd_device->dev;
+	ret = platform_device_add(mainstone_snd_device);
+
+	if (ret)
+		platform_device_put(mainstone_snd_device);
+
+	return ret;
+}
+
+static void __exit mainstone_exit(void) 
+{
+	platform_device_unregister(mainstone_snd_device);
+}
+
+module_init(mainstone_init);
+module_exit(mainstone_exit);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("ALSA SoC Mainstone");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/mainstone_wm9712.c b/sound/soc/pxa/mainstone_wm9712.c
new file mode 100644
index 0000000..e634f37
--- /dev/null
+++ b/sound/soc/pxa/mainstone_wm9712.c
@@ -0,0 +1,173 @@
+/*
+ * mainstone.c  --  SoC audio for Mainstone
+ *
+ * Copyright 2006 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  Mainstone audio amplifier code taken from arch/arm/mach-pxa/mainstone.c
+ *  Copyright:	MontaVista Software Inc.
+ * 
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    29th Jan 2006   Initial version.
+ * 
+ */
+ 
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/mainstone.h>
+#include <asm/arch/audio.h>
+
+#include "../codecs/wm9712.h"
+#include "pxa2xx-pcm.h"
+
+static struct snd_soc_machine mainstone;
+static long mst_audio_suspend_mask;
+
+static int mainstone_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	mst_audio_suspend_mask = MST_MSCWR2;
+	MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_resume(struct platform_device *pdev)
+{
+	MST_MSCWR2 &= mst_audio_suspend_mask | ~MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_probe(struct platform_device *pdev)
+{
+	MST_MSCWR2 &= ~MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_remove(struct platform_device *pdev)
+{
+	MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+/* mainstone machine dapm widgets */
+static const struct snd_soc_dapm_widget mainstone_dapm_widgets[] = {
+	SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
+};
+
+
+/* example machine interconnections */
+static const char* intercon[][3] = {
+	
+	/* mic is connected to mic1 - with bias */
+	{"MIC1", NULL, "Mic Bias"},
+	{"Mic Bias", NULL, "Mic (Internal)"},
+	
+	{NULL, NULL, NULL},
+};
+
+/*
+ * This is an example machine initialisation for a wm8753 connected to a 
+ * Mainstone II. It is missing logic to detect hp/mic insertions and logic
+ * to re-route the audio in such an event.
+ */
+
+static int mainstone_wm9712_init(struct snd_soc_codec *codec)
+{
+	int i;
+		
+	/* set up mainstone codec pins */
+	snd_soc_dapm_set_endpoint(codec, "RXP", 0);
+	snd_soc_dapm_set_endpoint(codec, "RXN", 0);
+	//snd_soc_dapm_set_endpoint(codec, "MIC2", 0);
+		
+	/* Add mainstone specific widgets */
+	for(i = 0; i < ARRAY_SIZE(mainstone_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &mainstone_dapm_widgets[i]);
+	}
+	
+	/* set up mainstone specific audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_sync_endpoints(codec);
+	return 0;
+}
+
+static struct snd_soc_machine_config codecs[] = {
+{
+	.name = "AC97", 
+	.sname = "AC97 HiFi", 
+	.iface = &pxa_ac97_interface[0],
+	.init = mainstone_wm9712_init,
+},
+{
+	.name = "AC97 Aux", 
+	.sname = "AC97 Aux",
+	.iface = &pxa_ac97_interface[1],
+},
+};
+
+static struct snd_soc_machine mainstone = {
+	.name = "Mainstone",
+	.probe = mainstone_probe,
+	.remove = mainstone_remove,
+	.suspend_pre = mainstone_suspend,
+	.resume_post = mainstone_resume,
+	.config = codecs,
+	.nconfigs = ARRAY_SIZE(codecs),
+};
+
+static struct snd_soc_device mainstone_snd_ac97_devdata = {
+	.machine = &mainstone,
+	.platform = &pxa2xx_soc_platform,
+	.codec_dev = &soc_codec_dev_wm9712,
+};
+
+static struct platform_device *mainstone_snd_ac97_device;
+
+static int __init mainstone_init(void) 
+{
+	int ret;
+
+	mainstone_snd_ac97_device = platform_device_alloc("soc-audio", -1);
+	if (!mainstone_snd_ac97_device)
+		return -ENOMEM;
+	
+	platform_set_drvdata(mainstone_snd_ac97_device, &mainstone_snd_ac97_devdata);
+	mainstone_snd_ac97_devdata.dev = &mainstone_snd_ac97_device->dev;
+		
+	if((ret = platform_device_add(mainstone_snd_ac97_device)) != 0)
+		platform_device_put(mainstone_snd_ac97_device);
+
+	return ret;
+}
+
+static void __exit mainstone_exit(void) 
+{
+	platform_device_unregister(mainstone_snd_ac97_device);
+}
+
+module_init(mainstone_init);
+module_exit(mainstone_exit);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("ALSA SoC Mainstone");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/mainstone_wm9713.c b/sound/soc/pxa/mainstone_wm9713.c
new file mode 100644
index 0000000..6e80852
--- /dev/null
+++ b/sound/soc/pxa/mainstone_wm9713.c
@@ -0,0 +1,223 @@
+/*
+ * mainstone.c  --  SoC audio for Mainstone
+ *
+ * Copyright 2006 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  Mainstone audio amplifier code taken from arch/arm/mach-pxa/mainstone.c
+ *  Copyright:	MontaVista Software Inc.
+ * 
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    29th Jan 2006   Initial version.
+ * 
+ */
+ 
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/mainstone.h>
+#include <asm/arch/audio.h>
+
+#include "../codecs/wm9713.h"
+#include "pxa2xx-pcm.h"
+
+static struct snd_soc_machine mainstone;
+
+static int mainstone_startup(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	
+	if(rtd->pcm_i->type == SND_SOC_SSP && rtd->pcm_i->id == 1) {
+		/* enable USB on the go MUX so we can use SSPFRM2 */
+		MST_MSCWR2 |= MST_MSCWR2_USB_OTG_SEL;
+		MST_MSCWR2 &= ~MST_MSCWR2_USB_OTG_RST;
+	}
+	return 0;
+}
+
+static void mainstone_shutdown(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+			
+	if(rtd->pcm_i->type == SND_SOC_SSP && rtd->pcm_i->id == 1) {
+		/* disable USB on the go MUX so we can use ttyS0 */
+		MST_MSCWR2 &= ~MST_MSCWR2_USB_OTG_SEL;
+		MST_MSCWR2 |= MST_MSCWR2_USB_OTG_RST;
+	}
+}
+
+static struct snd_soc_ops mainstone_ops = {
+	.startup = mainstone_startup,
+	.shutdown = mainstone_shutdown,
+};
+
+static long mst_audio_suspend_mask;
+
+static int mainstone_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	mst_audio_suspend_mask = MST_MSCWR2;
+	MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_resume(struct platform_device *pdev)
+{
+	MST_MSCWR2 &= mst_audio_suspend_mask | ~MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_probe(struct platform_device *pdev)
+{
+	MST_MSCWR2 &= ~MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+static int mainstone_remove(struct platform_device *pdev)
+{
+	MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+	return 0;
+}
+
+/* mainstone machine dapm widgets */
+static const struct snd_soc_dapm_widget mainstone_dapm_widgets[] = {
+	SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
+};
+
+
+/* example machine interconnections */
+static const char* intercon[][3] = {
+	
+	/* mic is connected to mic1 - with bias */
+	{"MIC1", NULL, "Mic Bias"},
+	{"Mic Bias", NULL, "Mic (Internal)"},
+	
+	{NULL, NULL, NULL},
+};
+
+/*
+ * This is an example machine initialisation for a wm9713 connected to a 
+ * Mainstone II. It is missing logic to detect hp/mic insertions and logic
+ * to re-route the audio in such an event.
+ */
+
+static int mainstone_wm9713_init(struct snd_soc_codec *codec)
+{
+	int i;
+		
+	/* set up mainstone codec pins */
+	snd_soc_dapm_set_endpoint(codec, "RXP", 0);
+	snd_soc_dapm_set_endpoint(codec, "RXN", 0);
+	//snd_soc_dapm_set_endpoint(codec, "MIC2", 0);
+		
+	/* Add mainstone specific widgets */
+	for(i = 0; i < ARRAY_SIZE(mainstone_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &mainstone_dapm_widgets[i]);
+	}
+	
+	/* set up mainstone specific audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_sync_endpoints(codec);
+	return 0;
+}
+
+unsigned int mainstone_config_sysclk(struct snd_soc_pcm_runtime *rtd, 
+	int rate, unsigned int hwfmt)
+{
+	if(hwfmt & SND_SOC_HWFMT_CBS_CFS) {
+		if(rtd->pcm_i->config_sysclk)
+			return rtd->pcm_i->config_sysclk(rtd->pcm_i, rate, 0);
+	} else {
+		/* wm9713 has pll that generates mclk from 13MHz xtal */
+		if(rtd->pcm_c->config_sysclk)
+			return rtd->pcm_c->config_sysclk(rtd->pcm_c, rate, 13000000);
+	}
+	return 0;
+}
+
+static struct snd_soc_machine_config codecs[] = {
+{
+	.name = "AC97", 
+	.sname = "AC97 HiFi", 
+	.iface = &pxa_ac97_interface[0],
+	.init = mainstone_wm9713_init,
+},
+{
+	.name = "AC97 Aux", 
+	.sname = "AC97 Aux",
+	.iface = &pxa_ac97_interface[1],
+},
+{
+	.name = "WM9713", 
+	.sname = "WM9713 Voice",
+	.iface = &pxa_ssp_interface[1],
+	.config_sysclk = mainstone_config_sysclk,
+},
+};
+
+static struct snd_soc_machine mainstone = {
+	.name = "Mainstone",
+	.probe = mainstone_probe,
+	.remove = mainstone_remove,
+	.suspend_pre = mainstone_suspend,
+	.resume_post = mainstone_resume,
+	.ops = &mainstone_ops,
+	.config = codecs,
+	.nconfigs = ARRAY_SIZE(codecs),
+};
+
+static struct snd_soc_device mainstone_snd_ac97_devdata = {
+	.machine = &mainstone,
+	.platform = &pxa2xx_soc_platform,
+	.codec_dev = &soc_codec_dev_wm9713,
+};
+
+static struct platform_device *mainstone_snd_ac97_device;
+
+static int __init mainstone_init(void) 
+{
+	int ret;
+
+	mainstone_snd_ac97_device = platform_device_alloc("soc-audio", -1);
+	if (!mainstone_snd_ac97_device)
+		return -ENOMEM;
+	
+	platform_set_drvdata(mainstone_snd_ac97_device, &mainstone_snd_ac97_devdata);
+	mainstone_snd_ac97_devdata.dev = &mainstone_snd_ac97_device->dev;
+		
+	if((ret = platform_device_add(mainstone_snd_ac97_device)) != 0)
+		platform_device_put(mainstone_snd_ac97_device);
+
+	return ret;
+}
+
+static void __exit mainstone_exit(void) 
+{
+	platform_device_unregister(mainstone_snd_ac97_device);
+}
+
+module_init(mainstone_init);
+module_exit(mainstone_exit);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("ALSA SoC Mainstone");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
new file mode 100644
index 0000000..b8c9548
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -0,0 +1,454 @@
+/*
+ * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip.
+ *
+ * Author:	Nicolas Pitre
+ * Created:	Dec 02, 2004
+ * Copyright:	MontaVista Software Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/wait.h>
+#include <linux/delay.h>
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/ac97_codec.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+
+#include <asm/irq.h>
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/audio.h>
+
+#include "pxa2xx-pcm.h"
+
+static DECLARE_MUTEX(car_mutex);
+static DECLARE_WAIT_QUEUE_HEAD(gsr_wq);
+static volatile long gsr_bits;
+
+#define AC97_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+	
+#define AC97_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
+
+/* may need to expand this */
+static struct snd_soc_hw_mode pxa2xx_ac97[] = {
+	{0, 0,	SNDRV_PCM_FORMAT_S16_LE,	AC97_RATES},
+};
+
+/*
+ * Beware PXA27x bugs:
+ *
+ *   o Slot 12 read from modem space will hang controller.
+ *   o CDONE, SDONE interrupt fails after any slot 12 IO.
+ *
+ * We therefore have an hybrid approach for waiting on SDONE (interrupt or
+ * 1 jiffy timeout if interrupt never comes).
+ */ 
+
+static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
+{
+	unsigned short val = -1;
+	volatile u32 *reg_addr;
+
+	down(&car_mutex);
+
+	/* set up primary or secondary codec/modem space */
+#ifdef CONFIG_PXA27x
+	reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
+#else
+	if (reg == AC97_GPIO_STATUS)
+		reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE;
+	else
+		reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
+#endif
+	reg_addr += (reg >> 1);
+
+#ifndef CONFIG_PXA27x
+	if (reg == AC97_GPIO_STATUS) {
+		/* read from controller cache */
+		val = *reg_addr;
+		goto out;
+	}
+#endif
+	
+	/* start read access across the ac97 link */
+	GSR = GSR_CDONE | GSR_SDONE;
+	gsr_bits = 0;
+	val = *reg_addr;
+
+	wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
+	if (!((GSR | gsr_bits) & GSR_SDONE)) {
+		printk(KERN_ERR "%s: read error (ac97_reg=%x GSR=%#lx)\n",
+				__FUNCTION__, reg, GSR | gsr_bits);
+		val = -1;
+		goto out;
+	}
+
+	/* valid data now */
+	GSR = GSR_CDONE | GSR_SDONE;
+	gsr_bits = 0;
+	val = *reg_addr;			
+	/* but we've just started another cycle... */
+	wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
+
+out:	up(&car_mutex);
+	return val;
+}
+
+static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
+{
+	volatile u32 *reg_addr;
+
+	down(&car_mutex);
+
+	/* set up primary or secondary codec/modem space */
+#ifdef CONFIG_PXA27x
+	reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
+#else
+	if (reg == AC97_GPIO_STATUS)
+		reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE;
+	else
+		reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
+#endif
+	reg_addr += (reg >> 1);
+
+	GSR = GSR_CDONE | GSR_SDONE;
+	gsr_bits = 0;
+	*reg_addr = val;
+	wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1);
+	if (!((GSR | gsr_bits) & GSR_CDONE))
+		printk(KERN_ERR "%s: write error (ac97_reg=%x GSR=%#lx)\n",
+				__FUNCTION__, reg, GSR | gsr_bits);
+
+	up(&car_mutex);
+}
+
+static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
+{
+	gsr_bits = 0;
+	
+#ifdef CONFIG_PXA27x
+	/* warm reset broken on Bulverde,
+	   so manually keep AC97 reset high */
+	pxa_gpio_mode(113 | GPIO_OUT | GPIO_DFLT_HIGH); 
+	udelay(10);
+	GCR |= GCR_WARM_RST;
+	pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
+	udelay(500);
+#else
+	GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN;
+	wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
+#endif			
+
+	if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
+		printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
+				 __FUNCTION__, gsr_bits);
+	
+	GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
+	GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
+}
+
+
+static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
+{
+	GCR &=  GCR_COLD_RST;  /* clear everything but nCRST */
+	GCR &= ~GCR_COLD_RST;  /* then assert nCRST */
+
+	gsr_bits = 0;
+#ifdef CONFIG_PXA27x
+	/* PXA27x Developers Manual section 13.5.2.2.1 */
+	pxa_set_cken(1 << 31, 1);
+	udelay(5);
+	pxa_set_cken(1 << 31, 0);
+	GCR = GCR_COLD_RST;
+	udelay(50);
+#else
+	GCR = GCR_COLD_RST;
+	GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
+	wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
+#endif
+
+	if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
+		printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
+				 __FUNCTION__, gsr_bits);		
+ 
+	GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
+	GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
+}
+
+static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id, struct pt_regs *regs)
+{
+	long status;
+
+	status = GSR;
+	if (status) {
+		GSR = status;
+		gsr_bits |= status;
+		wake_up(&gsr_wq);
+
+#ifdef CONFIG_PXA27x
+		/* Although we don't use those we still need to clear them
+		   since they tend to spuriously trigger when MMC is used
+		   (hardware bug? go figure)... */
+		MISR = MISR_EOC;
+		PISR = PISR_EOC;
+		MCSR = MCSR_EOC;
+#endif
+
+		return IRQ_HANDLED;
+	}
+
+	return IRQ_NONE;
+}
+
+struct snd_ac97_bus_ops soc_ac97_ops = {
+	.read	= pxa2xx_ac97_read,
+	.write	= pxa2xx_ac97_write,
+	.warm_reset	= pxa2xx_ac97_warm_reset,
+	.reset	= pxa2xx_ac97_cold_reset,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ac97_pcm_stereo_out = {
+	.name			= "AC97 PCM Stereo out",
+	.dev_addr		= __PREG(PCDR),
+	.drcmr			= &DRCMRTXPCDR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ac97_pcm_stereo_in = {
+	.name			= "AC97 PCM Stereo in",
+	.dev_addr		= __PREG(PCDR),
+	.drcmr			= &DRCMRRXPCDR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ac97_pcm_mono_out = {
+	.name			= "AC97 PCM Mono out",
+	.dev_addr		= __PREG(PCDR),
+	.drcmr			= &DRCMRTXPCDR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ac97_pcm_mono_in = {
+	.name			= "AC97 PCM Mono in",
+	.dev_addr		= __PREG(PCDR),
+	.drcmr			= &DRCMRRXPCDR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ac97_pcm_aux_mono_out = {
+	.name			= "AC97 Aux PCM (Slot 5) Mono out",
+	.dev_addr		= __PREG(MODR),
+	.drcmr			= &DRCMRTXMODR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ac97_pcm_aux_mono_in = {
+	.name			= "AC97 Aux PCM (Slot 5) Mono in",
+	.dev_addr		= __PREG(MODR),
+	.drcmr			= &DRCMRRXMODR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ac97_pcm_mic_mono_in = {
+	.name			= "AC97 Mic PCM (Slot 6) Mono in",
+	.dev_addr		= __PREG(MCDR),
+	.drcmr			= &DRCMRRXMCDR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+#ifdef CONFIG_PM
+static int pxa2xx_ac97_suspend(struct platform_device *pdev, struct snd_soc_pcm_interface *pcm_i)
+{
+	GCR |= GCR_ACLINK_OFF;
+	pxa_set_cken(CKEN2_AC97, 0);
+	return 0;
+}
+
+static int pxa2xx_ac97_resume(struct platform_device *pdev, struct snd_soc_pcm_interface *pcm_i)
+{
+	pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
+	pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
+	pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
+	pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
+#ifdef CONFIG_PXA27x
+	/* Use GPIO 113 as AC97 Reset on Bulverde */
+	pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
+#endif
+	pxa_set_cken(CKEN2_AC97, 1);
+	return 0;
+}
+
+#else
+#define pxa2xx_ac97_suspend	NULL
+#define pxa2xx_ac97_resume	NULL
+#endif
+
+static int pxa2xx_ac97_probe(struct platform_device *pdev)
+{
+	int ret;
+	
+	ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL);
+	if (ret < 0)
+		goto err;
+
+	pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
+	pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
+	pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
+	pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
+#ifdef CONFIG_PXA27x
+	/* Use GPIO 113 as AC97 Reset on Bulverde */
+	pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
+#endif
+	pxa_set_cken(CKEN2_AC97, 1);
+	return 0;
+
+ err:
+	if (CKEN & CKEN2_AC97) {
+		GCR |= GCR_ACLINK_OFF;
+		free_irq(IRQ_AC97, NULL);
+		pxa_set_cken(CKEN2_AC97, 0);
+	}
+	return ret;
+}
+
+static void pxa2xx_ac97_remove(struct platform_device *pdev)
+{
+	GCR |= GCR_ACLINK_OFF;
+	free_irq(IRQ_AC97, NULL);
+	pxa_set_cken(CKEN2_AC97, 0);
+}
+
+static int pxa2xx_ac97_hw_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		if (params_channels(params) == 2)
+			rtd->pcm_i->platform_data = &pxa2xx_ac97_pcm_stereo_out;
+		else
+			rtd->pcm_i->platform_data = &pxa2xx_ac97_pcm_mono_out;
+	} else {
+		if (params_channels(params) == 2)
+			rtd->pcm_i->platform_data = &pxa2xx_ac97_pcm_stereo_in;
+		else
+			rtd->pcm_i->platform_data = &pxa2xx_ac97_pcm_mono_in;
+	}
+
+	return 0;
+}
+
+static int pxa2xx_ac97_hw_aux_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		rtd->pcm_i->platform_data = &pxa2xx_ac97_pcm_aux_mono_out;
+	else
+		rtd->pcm_i->platform_data = &pxa2xx_ac97_pcm_aux_mono_in;
+
+	return 0;
+}
+
+static int pxa2xx_ac97_hw_mic_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		return -ENODEV;
+	else
+		rtd->pcm_i->platform_data = &pxa2xx_ac97_pcm_mic_mono_in;
+
+	return 0;
+}
+
+/* 
+ * There is only 1 physical AC97 interface for pxa2xx, but it
+ * has extra fifo's that can be used for aux DACs and ADCs.
+ */
+struct snd_soc_pcm_interface pxa_ac97_interface[] = {
+{
+	.name = "pxa2xx-ac97",
+	.id = 0,
+	.type = SND_SOC_AC97,
+	.probe = pxa2xx_ac97_probe,
+	.remove = pxa2xx_ac97_remove,
+	.suspend = pxa2xx_ac97_suspend,
+	.resume = pxa2xx_ac97_resume,
+	.playback = {
+		.sname = "AC97 Playback",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.capture = {
+		.sname = "AC97 Capture",
+		.channels_min = 1,
+		.channels_max = 2,},
+	.ops = {
+		.hw_params = pxa2xx_ac97_hw_params,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(pxa2xx_ac97),
+		.hmodes = &pxa2xx_ac97[0],},
+},
+{
+	.name = "pxa2xx-ac97-aux",
+	.id = 1,
+	.type = SND_SOC_AC97,
+	.playback = {
+		.sname = "AC97 Aux Playback",
+		.channels_min = 1,
+		.channels_max = 1,},
+	.capture = {
+		.sname = "AC97 Aux Capture",
+		.channels_min = 1,
+		.channels_max = 1,},
+	.ops = {
+		.hw_params = pxa2xx_ac97_hw_aux_params,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(pxa2xx_ac97),
+		.hmodes = &pxa2xx_ac97[0],},
+},
+{
+	.name = "pxa2xx-ac97-mic",
+	.id = 2,
+	.type = SND_SOC_AC97,
+	.capture = {
+		.sname = "AC97 Mic Capture",
+		.channels_min = 1,
+		.channels_max = 1,},
+	.ops = {
+		.hw_params = pxa2xx_ac97_hw_mic_params,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(pxa2xx_ac97),
+		.hmodes = &pxa2xx_ac97[0],},},
+};
+
+EXPORT_SYMBOL_GPL(pxa_ac97_interface);
+EXPORT_SYMBOL_GPL(soc_ac97_ops);
+
+MODULE_AUTHOR("Nicolas Pitre");
+MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c
new file mode 100644
index 0000000..1d014c9
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-i2s.c
@@ -0,0 +1,299 @@
+/*
+ * pxa2xx-i2s.c  --  ALSA Soc Audio Layer
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    12th Aug 2005   Initial version.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+
+#include <asm/hardware.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/audio.h>
+
+#include "pxa2xx-pcm.h"
+
+/* used to disable sysclk if external crystal is used */
+static int extclk = 1;
+module_param(extclk, int, 0);
+MODULE_PARM_DESC(extclk, "set to 1 to disable pxa2xx i2s sysclk");
+
+static DECLARE_MUTEX(pxa_i2s_sem);
+
+struct pxa_i2s_port {
+	int i2s_open;
+	u32 sadiv;
+	u32 sacr0;
+	u32 sacr1;
+	u32 saimr;
+	int master;
+};
+static struct pxa_i2s_port pxa_i2s;
+
+#define PXA_I2S_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_NB_NF)
+
+#define PXA_I2S_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+	
+#define PXA_I2S_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+
+/* priv is divider */
+static struct snd_soc_hw_mode pxa2xx_i2s[] = {
+	/* codec frame and clock slave modes */
+	{PXA_I2S_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_8000, PXA_I2S_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256),
+		SND_SOC_FSBD(4), 0x48},
+	{PXA_I2S_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_11025, PXA_I2S_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256),
+		SND_SOC_FSBD(4), 0x34},
+	{PXA_I2S_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_16000, PXA_I2S_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256),
+		SND_SOC_FSBD(4), 0x24},
+	{PXA_I2S_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_22050, PXA_I2S_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256),
+		SND_SOC_FSBD(4), 0x1a},
+	{PXA_I2S_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_44100, PXA_I2S_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256),
+		SND_SOC_FSBD(4), 0xd},
+	{PXA_I2S_HWFMT | SND_SOC_HWFMT_CBS_CFS, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_48000, PXA_I2S_DIR, SND_SOC_HW_BFS_DIV, SND_SOC_FS(256),
+		SND_SOC_FSBD(4), 0xc},
+
+	/* codec frame slave and clock master mode */
+	{PXA_I2S_HWFMT | SND_SOC_HWFMT_CBM_CFS, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		PXA_I2S_RATES, PXA_I2S_DIR, 0, SND_SOC_FS_ALL, SND_SOC_FSB(64)},
+
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_i2s_pcm_stereo_out = {
+	.name			= "I2S PCM Stereo out",
+	.dev_addr		= __PREG(SADR),
+	.drcmr			= &DRCMRTXSADR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_i2s_pcm_stereo_in = {
+	.name			= "I2S PCM Stereo in",
+	.dev_addr		= __PREG(SADR),
+	.drcmr			= &DRCMRRXSADR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_gpio_t gpio_bus[] = {
+	{ /* I2S SoC Slave */
+		.rx = GPIO29_SDATA_IN_I2S_MD,
+		.tx = GPIO30_SDATA_OUT_I2S_MD,
+		.clk = GPIO28_BITCLK_IN_I2S_MD,
+		.frm = GPIO31_SYNC_I2S_MD,
+	},
+	{ /* I2S SoC Master */
+		.sys = GPIO32_SYSCLK_I2S_MD,
+		.rx = GPIO29_SDATA_IN_I2S_MD,
+		.tx = GPIO30_SDATA_OUT_I2S_MD,
+		.clk = GPIO28_BITCLK_OUT_I2S_MD,
+		.frm = GPIO31_SYNC_I2S_MD,
+	},
+};
+
+static int pxa2xx_i2s_startup(snd_pcm_substream_t *substream)
+{	
+	down(&pxa_i2s_sem);
+	if(!pxa_i2s.i2s_open) {
+		SACR0 |= SACR0_RST;
+		SACR0 = 0;
+	}
+	pxa_i2s.i2s_open++;
+	up(&pxa_i2s_sem);
+	return 0;
+}
+
+/* wait for I2S controller to be ready */
+static int pxa_i2s_wait(void)
+{
+	int i;
+	/* flush the Rx FIFO */
+	for(i = 0; i < 16; i++)
+		SADR;
+	return 0;
+}
+
+static int pxa2xx_i2s_hw_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+
+	pxa_i2s.master = 0;
+	if(rtd->pcm_i->hw_runtime.hwfmt & SND_SOC_HWFMT_CBS_CFS)
+		pxa_i2s.master = 1;
+	
+	if (pxa_i2s.master && !extclk)
+		pxa_gpio_mode(gpio_bus[pxa_i2s.master].sys);
+
+	pxa_gpio_mode(gpio_bus[pxa_i2s.master].rx);
+	pxa_gpio_mode(gpio_bus[pxa_i2s.master].tx);
+	pxa_gpio_mode(gpio_bus[pxa_i2s.master].frm);
+	pxa_gpio_mode(gpio_bus[pxa_i2s.master].clk);
+	pxa_set_cken(CKEN8_I2S, 1);
+	pxa_i2s_wait();
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		rtd->pcm_i->platform_data = &pxa2xx_i2s_pcm_stereo_out;
+	else
+		rtd->pcm_i->platform_data = &pxa2xx_i2s_pcm_stereo_in;
+	
+	/* is port used by another stream */
+	if (SACR0 & SACR0_ENB) {
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+			SACR1 &= ~SACR1_DRPL;
+			SAIMR |= SAIMR_TFS;
+		} else {
+			SACR1 &= ~SACR1_DREC;
+			SAIMR |= SAIMR_RFS;
+		}
+	} else {
+		SACR0 = 0;
+		SACR1 = 0;
+		SAIMR = SACR1_DRPL | SACR1_DREC;
+		if (pxa_i2s.master)
+			SACR0 |= SACR0_BCKD;
+		
+		SACR0 |= SACR0_RFTH(14) | SACR0_TFTH(1);
+	
+		if (rtd->pcm_i->hw_runtime.hwfmt & SND_SOC_HWFMT_LEFT_J)
+			SACR1 |= SACR1_AMSL;
+	
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+			SACR1 &= ~SACR1_DRPL;
+			SAIMR |= SAIMR_TFS;
+		} else {
+			SACR1 &= ~SACR1_DREC;
+			SAIMR |= SAIMR_RFS;
+		}
+	}
+
+	SADIV = rtd->pcm_i->hw_runtime.priv;
+	SACR0 |= SACR0_ENB;
+	rtd->pcm_i->active = 1;
+	return 0;
+}
+
+static void pxa2xx_i2s_shutdown(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+
+	down(&pxa_i2s_sem);
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		SACR1 |= SACR1_DRPL;
+		SAIMR &= ~SAIMR_TFS;
+	} else {
+		SACR1 |= SACR1_DREC;
+		SAIMR &= ~SAIMR_RFS;
+	}
+
+	if (SACR1 & (SACR1_DREC | SACR1_DRPL)) {
+		SACR0 &= ~SACR0_ENB;
+		pxa_i2s_wait();
+		pxa_set_cken(CKEN8_I2S, 0);
+		rtd->pcm_i->active = 0;
+	}
+	pxa_i2s.i2s_open--;
+	up(&pxa_i2s_sem);
+}
+
+#ifdef CONFIG_PM
+static int pxa2xx_i2s_suspend(struct platform_device *dev, struct snd_soc_pcm_interface *pcm_i)
+{
+	if(!pcm_i->active)
+		return 0;
+
+	/* disable link and store registers */
+	SACR0 &= ~SACR0_ENB;
+	pxa_i2s_wait();
+	pxa_i2s.sacr0 = SACR0;
+	pxa_i2s.sacr1 = SACR1;
+	pxa_i2s.saimr = SAIMR;
+	pxa_i2s.sadiv = SADIV;
+	pxa_set_cken(CKEN8_I2S, 0);
+	return 0;
+}
+
+static int pxa2xx_i2s_resume(struct platform_device *pdev, struct snd_soc_pcm_interface *pcm_i)
+{
+	if(!pcm_i->active)
+		return 0;
+
+	pxa_set_cken(CKEN8_I2S, 1);
+	pxa_i2s_wait();
+	
+	SACR0 = pxa_i2s.sacr0;
+	SACR1 = pxa_i2s.sacr1;
+	SAIMR = pxa_i2s.saimr;
+	SADIV = pxa_i2s.sadiv;
+	SACR0 |= SACR0_ENB;
+
+	return 0;
+}
+
+#else
+#define pxa2xx_i2s_suspend	NULL
+#define pxa2xx_i2s_resume	NULL
+#endif
+
+static unsigned int pxa_i2s_config_sysclk(struct snd_soc_pcm_interface *iface,
+	int rate, unsigned int clk)
+{
+	return rate << 8;
+}	
+
+struct snd_soc_pcm_interface pxa_i2s_interface = {
+	.name = "pxa2xx-i2s",
+	.id = 0,
+	.type = SND_SOC_I2S,
+	.suspend = pxa2xx_i2s_suspend,
+	.resume = pxa2xx_i2s_resume,
+	.config_sysclk = pxa_i2s_config_sysclk,
+	.playback = {
+		.channels_min = 2,
+		.channels_max = 2,},
+	.capture = {
+		.channels_min = 2,
+		.channels_max = 2,},
+	.ops = {
+		.startup = pxa2xx_i2s_startup,
+		.shutdown = pxa2xx_i2s_shutdown,
+		.hw_params = pxa2xx_i2s_hw_params,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(pxa2xx_i2s),
+		.hmodes = &pxa2xx_i2s[0],},
+};
+
+EXPORT_SYMBOL_GPL(pxa_i2s_interface);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("pxa2xx I2S SoC Interface");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/pxa2xx-pcm.c b/sound/soc/pxa/pxa2xx-pcm.c
new file mode 100644
index 0000000..93ba0aa
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-pcm.c
@@ -0,0 +1,400 @@
+/*
+ * linux/sound/arm/pxa2xx-pcm.c -- ALSA PCM interface for the Intel PXA2xx chip
+ *
+ * Author:	Nicolas Pitre
+ * Created:	Nov 30, 2004
+ * Copyright:	(C) 2004 MontaVista Software, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include <asm/dma.h>
+#include <asm/hardware.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/audio.h>
+
+#include "pxa2xx-pcm.h"
+
+static const snd_pcm_hardware_t pxa2xx_pcm_hardware = {
+	.info			= SNDRV_PCM_INFO_MMAP |
+				  SNDRV_PCM_INFO_MMAP_VALID |
+				  SNDRV_PCM_INFO_INTERLEAVED |
+				  SNDRV_PCM_INFO_PAUSE,
+	.formats		= SNDRV_PCM_FMTBIT_S16_LE,
+	.period_bytes_min	= 32,
+	.period_bytes_max	= 8192 - 32,
+	.periods_min		= 1,
+	.periods_max		= PAGE_SIZE/sizeof(pxa_dma_desc),
+	.buffer_bytes_max	= 128 * 1024,
+	.fifo_size		= 32,
+};
+
+struct pxa2xx_runtime_data {
+	int dma_ch;
+	pxa2xx_pcm_dma_params_t *params;
+	pxa_dma_desc *dma_desc_array;
+	dma_addr_t dma_desc_array_phys;
+};
+
+static void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id, struct pt_regs *regs)
+{
+	snd_pcm_substream_t *substream = dev_id;
+	struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
+	int dcsr;
+	
+	dcsr = DCSR(dma_ch);
+	DCSR(dma_ch) = dcsr & ~DCSR_STOPIRQEN;
+
+	if (dcsr & DCSR_ENDINTR) {
+		snd_pcm_period_elapsed(substream);
+	} else {
+		printk( KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
+			prtd->params->name, dma_ch, dcsr );
+	}
+}
+
+static int pxa2xx_pcm_hw_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct pxa2xx_runtime_data *prtd = runtime->private_data;
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	size_t totsize = params_buffer_bytes(params);
+	size_t period = params_period_bytes(params);
+	pxa2xx_pcm_dma_params_t *dma = rtd->pcm_i->platform_data;
+	pxa_dma_desc *dma_desc;
+	dma_addr_t dma_buff_phys, next_desc_phys;
+	int ret;
+	
+	/* this may get called several times by oss emulation with different params */
+	if(prtd->params == NULL) {
+		prtd->params = dma;
+		if((ret = pxa_request_dma(prtd->params->name, DMA_PRIO_LOW,
+			      pxa2xx_pcm_dma_irq, substream)) < 0)
+			return ret;
+		prtd->dma_ch = ret;
+	} else if(prtd->params != dma) {
+		pxa_free_dma(prtd->dma_ch);
+		prtd->params = dma;
+		if((ret = pxa_request_dma(prtd->params->name, DMA_PRIO_LOW,
+			      pxa2xx_pcm_dma_irq, substream)) < 0)
+			return ret;
+		prtd->dma_ch = ret;
+	}
+
+	snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
+	runtime->dma_bytes = totsize;
+
+	dma_desc = prtd->dma_desc_array;
+	next_desc_phys = prtd->dma_desc_array_phys;
+	dma_buff_phys = runtime->dma_addr;
+	do {
+		next_desc_phys += sizeof(pxa_dma_desc);
+		dma_desc->ddadr = next_desc_phys;
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+			dma_desc->dsadr = dma_buff_phys;
+			dma_desc->dtadr = prtd->params->dev_addr;
+		} else {
+			dma_desc->dsadr = prtd->params->dev_addr;
+			dma_desc->dtadr = dma_buff_phys;
+		}
+		if (period > totsize)
+			period = totsize;
+		dma_desc->dcmd = prtd->params->dcmd | period | DCMD_ENDIRQEN;
+		dma_desc++;
+		dma_buff_phys += period;
+	} while (totsize -= period);
+	dma_desc[-1].ddadr = prtd->dma_desc_array_phys;
+
+	return 0;
+}
+
+static int pxa2xx_pcm_hw_free(snd_pcm_substream_t *substream)
+{
+	struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
+ 
+	if(prtd && prtd->params)
+		*prtd->params->drcmr = 0;
+	
+	if(prtd->dma_ch) {
+		snd_pcm_set_runtime_buffer(substream, NULL);
+		pxa_free_dma(prtd->dma_ch);
+		prtd->dma_ch = 0;
+	}
+	
+	return 0;
+}
+
+static int pxa2xx_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
+
+	DCSR(prtd->dma_ch) &= ~DCSR_RUN;
+	DCSR(prtd->dma_ch) = 0;
+	DCMD(prtd->dma_ch) = 0;
+	*prtd->params->drcmr = prtd->dma_ch | DRCMR_MAPVLD;
+
+	return 0;
+}
+
+static int pxa2xx_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
+{
+	struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
+	int ret = 0;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		DDADR(prtd->dma_ch) = prtd->dma_desc_array_phys;
+		DCSR(prtd->dma_ch) = DCSR_RUN;
+		break;
+
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		DCSR(prtd->dma_ch) &= ~DCSR_RUN;
+		break;
+
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		DCSR(prtd->dma_ch) |= DCSR_RUN;
+		break;
+
+	default:
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+static snd_pcm_uframes_t pxa2xx_pcm_pointer(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct pxa2xx_runtime_data *prtd = runtime->private_data;
+	
+	dma_addr_t ptr = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+			 DSADR(prtd->dma_ch) : DTADR(prtd->dma_ch);
+	snd_pcm_uframes_t x = bytes_to_frames(runtime, ptr - runtime->dma_addr);
+
+	if (x == runtime->buffer_size)
+		x = 0;
+	return x;
+}
+
+static int
+pxa2xx_pcm_hw_rule_mult32(snd_pcm_hw_params_t *params, snd_pcm_hw_rule_t *rule)
+{
+	snd_interval_t *i = hw_param_interval(params, rule->var);
+	int changed = 0;
+
+	if (i->min & 31) {
+		i->min = (i->min & ~31) + 32;
+		i->openmin = 0;
+		changed = 1;
+	}
+
+	if (i->max & 31) {
+		i->max &= ~31;
+		i->openmax = 0;
+		changed = 1;
+	}
+
+	return changed;
+}
+
+static int pxa2xx_pcm_open(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct pxa2xx_runtime_data *prtd;
+	int ret;
+
+	snd_soc_set_runtime_hw(substream, &pxa2xx_pcm_hardware);
+
+	/*
+	 * For mysterious reasons (and despite what the manual says)
+	 * playback samples are lost if the DMA count is not a multiple
+	 * of the DMA burst size.  Let's add a rule to enforce that.
+	 */
+	ret = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
+				  pxa2xx_pcm_hw_rule_mult32, NULL,
+				  SNDRV_PCM_HW_PARAM_PERIOD_BYTES, -1);
+	if (ret)
+		goto out;
+
+	ret = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
+				  pxa2xx_pcm_hw_rule_mult32, NULL,
+				  SNDRV_PCM_HW_PARAM_BUFFER_BYTES, -1);
+	if (ret)
+		goto out;
+
+	if((prtd = kzalloc(sizeof(struct pxa2xx_runtime_data), GFP_KERNEL)) == NULL) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	
+	prtd->dma_desc_array =
+		dma_alloc_writecombine(substream->pcm->card->dev, PAGE_SIZE,
+				       &prtd->dma_desc_array_phys, GFP_KERNEL);
+	if (!prtd->dma_desc_array)
+		goto err1;
+
+	runtime->private_data = prtd;
+	return 0;
+
+ err1:
+	kfree(prtd);
+ out:
+	return ret;
+}
+
+static int pxa2xx_pcm_close(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct pxa2xx_runtime_data *prtd = runtime->private_data;
+
+	dma_free_writecombine(substream->pcm->card->dev, PAGE_SIZE,
+			      prtd->dma_desc_array, prtd->dma_desc_array_phys);
+	kfree(prtd);
+	return 0;
+}
+
+static int
+pxa2xx_pcm_mmap(snd_pcm_substream_t *substream, struct vm_area_struct *vma)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	return dma_mmap_writecombine(substream->pcm->card->dev, vma,
+				     runtime->dma_area,
+				     runtime->dma_addr,
+				     runtime->dma_bytes);
+}
+
+snd_pcm_ops_t pxa2xx_pcm_ops = {
+	.open		= pxa2xx_pcm_open,
+	.close		= pxa2xx_pcm_close,
+	.ioctl		= snd_pcm_lib_ioctl,
+	.hw_params	= pxa2xx_pcm_hw_params,
+	.hw_free	= pxa2xx_pcm_hw_free,
+	.prepare	= pxa2xx_pcm_prepare,
+	.trigger	= pxa2xx_pcm_trigger,
+	.pointer	= pxa2xx_pcm_pointer,
+	.mmap		= pxa2xx_pcm_mmap,
+};
+
+static int pxa2xx_pcm_preallocate_dma_buffer(snd_pcm_t *pcm, int stream)
+{
+	snd_pcm_substream_t *substream = pcm->streams[stream].substream;
+	struct snd_dma_buffer *buf = &substream->dma_buffer;
+	size_t size = pxa2xx_pcm_hardware.buffer_bytes_max;
+	buf->dev.type = SNDRV_DMA_TYPE_DEV;
+	buf->dev.dev = pcm->card->dev;
+	buf->private_data = NULL;
+	buf->area = dma_alloc_writecombine(pcm->card->dev, size,
+					   &buf->addr, GFP_KERNEL);
+	if (!buf->area)
+		return -ENOMEM;
+	buf->bytes = size;
+	return 0;
+}
+
+static void pxa2xx_pcm_free_dma_buffers(snd_pcm_t *pcm)
+{
+	snd_pcm_substream_t *substream;
+	struct snd_dma_buffer *buf;
+	int stream;
+
+	for (stream = 0; stream < 2; stream++) {
+		substream = pcm->streams[stream].substream;
+		if (!substream)
+			continue;
+			
+		buf = &substream->dma_buffer;
+		if (!buf->area)
+			continue;
+		
+		dma_free_writecombine(pcm->card->dev, buf->bytes,
+				      buf->area, buf->addr);
+		buf->area = NULL;	
+	}
+}
+
+static u64 pxa2xx_pcm_dmamask = 0xffffffff;
+
+int pxa2xx_pcm_new(snd_card_t *card, struct snd_soc_pcm_codec *pcm_c, snd_pcm_t *pcm)
+{
+	int ret = 0;
+
+	if (!card->dev->dma_mask)
+		card->dev->dma_mask = &pxa2xx_pcm_dmamask;
+	if (!card->dev->coherent_dma_mask)
+		card->dev->coherent_dma_mask = 0xffffffff;
+
+	if (pcm_c->nplayback) {
+		ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_PLAYBACK);
+		if (ret)
+			goto out;
+	}
+
+	if (pcm_c->ncapture) {
+		ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_CAPTURE);
+		if (ret)
+			goto out;
+	}
+ out:
+	return ret;
+}
+
+static int pxa2xx_pcm_suspend(struct platform_device *pdev, struct snd_soc_pcm_interface *iface)
+{
+	snd_pcm_runtime_t *runtime = iface->runtime;
+	struct pxa2xx_runtime_data *prtd;
+
+	if(!runtime)
+		return 0;
+	
+	prtd = runtime->private_data;
+	DCSR(prtd->dma_ch) &= ~DCSR_RUN;
+	return 0;
+}
+
+static int pxa2xx_pcm_resume(struct platform_device *pdev, struct snd_soc_pcm_interface *iface)
+{
+	snd_pcm_runtime_t *runtime = iface->runtime;
+	struct pxa2xx_runtime_data *prtd;
+
+	if(!runtime)
+		return 0;
+		
+	prtd = runtime->private_data;
+	DCMD(prtd->dma_ch) = 0;
+	*prtd->params->drcmr = prtd->dma_ch | DRCMR_MAPVLD;
+	DDADR(prtd->dma_ch) = prtd->dma_desc_array_phys;
+	DCSR(prtd->dma_ch) |= DCSR_RUN;	
+	return 0;
+}	
+
+struct snd_soc_platform pxa2xx_soc_platform = {
+	.name		= "pxa2xx-audio",
+	.pcm_ops 	= &pxa2xx_pcm_ops,
+	.pcm_new	= pxa2xx_pcm_new,
+	.pcm_free	= pxa2xx_pcm_free_dma_buffers,
+	.suspend	= pxa2xx_pcm_suspend,
+	.resume		= pxa2xx_pcm_resume,
+};
+
+EXPORT_SYMBOL_GPL(pxa2xx_soc_platform);
+
+MODULE_AUTHOR("Nicolas Pitre");
+MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/pxa2xx-pcm.h b/sound/soc/pxa/pxa2xx-pcm.h
new file mode 100644
index 0000000..b28c91f
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-pcm.h
@@ -0,0 +1,32 @@
+/*
+ * linux/sound/arm/pxa2xx-pcm.h -- ALSA PCM interface for the Intel PXA2xx chip
+ *
+ * Author:	Nicolas Pitre
+ * Created:	Nov 30, 2004
+ * Copyright:	MontaVista Software, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+typedef struct {
+	char *name;			/* stream identifier */
+	u32 dcmd;			/* DMA descriptor dcmd field */
+	volatile u32 *drcmr;		/* the DMA request channel to use */
+	u32 dev_addr;			/* device physical address for DMA */
+} pxa2xx_pcm_dma_params_t;
+
+typedef struct {
+	u32 sys;
+	u32	rx;
+	u32 tx;
+	u32 clk;
+	u32 frm;
+} pxa2xx_gpio_t;
+
+extern struct snd_soc_pcm_interface pxa_ac97_interface[3];
+extern struct snd_soc_pcm_interface pxa_i2s_interface;
+extern struct snd_soc_pcm_interface pxa_ssp_interface[3];
+extern struct snd_soc_platform pxa2xx_soc_platform;
+extern ac97_bus_ops_t pxa2xx_ac97_ops;
diff --git a/sound/soc/pxa/pxa2xx-ssp.c b/sound/soc/pxa/pxa2xx-ssp.c
new file mode 100644
index 0000000..4fc6718
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-ssp.c
@@ -0,0 +1,564 @@
+/*
+ * pxa2xx-ssp.c  --  ALSA Soc Audio Layer
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    12th Aug 2005   Initial version.
+ * 
+ * TODO:
+ *  o Fix master mode
+ *  o Add support for other clocks
+ *  o Add network mode support
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+
+#include <asm/hardware.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/audio.h>
+#include <asm/arch/ssp.h>
+
+#include "pxa2xx-pcm.h"
+
+/* liam - move to pxa-regs.h */
+#define SSACD_P1	__REG(0x4100003C)
+#define SSACD_P2	__REG(0x4170003C)
+#define SSACD_P3	__REG(0x4190003C)
+#define SSACD_P(x) (*(((x) == 1) ? &SSACD_P1 : ((x) == 2) ? &SSACD_P2 : ((x) == 3) ? &SSACD_P3 : NULL))
+
+/*
+ * SSP sysclock frequency in Hz
+ * Neither default pxa2xx PLL clocks are good for audio, hence pxa27x
+ * has audio clock. I would recommend using the pxa27x audio clock or an external
+ * clock or making the codec master
+ */
+#ifdef CONFIG_PXA27x
+static int sysclk = 13000000;
+#else
+static int sysclk = 1843200;
+#endif
+module_param(sysclk, int, 0);
+MODULE_PARM_DESC(sysclk, "sysclk frequency in Hz");
+#warning need param for each port
+/*
+ * SSP sysclock source.
+ * sysclk is ignored if audio clock is used
+ */
+#ifdef CONFIG_PXA27x
+static int clksrc = 0; // liam - fix for 3
+#else
+static int clksrc = 0;
+#endif
+module_param(clksrc, int, 0);
+MODULE_PARM_DESC(clksrc, "sysclk source, 0 = internal PLL, 1 = ext, 2 = network, 3 = audio clock");
+
+/*
+ * SSP GPIO's
+ */
+#define GPIO26_SSP1RX_MD	(26 | GPIO_ALT_FN_1_IN)
+#define GPIO25_SSP1TX_MD	(25 | GPIO_ALT_FN_2_OUT)
+#define GPIO23_SSP1CLKS_MD	(23 | GPIO_ALT_FN_2_IN)
+#define GPIO24_SSP1FRMS_MD	(24 | GPIO_ALT_FN_2_IN)
+#define GPIO23_SSP1CLKM_MD	(23 | GPIO_ALT_FN_2_OUT)
+#define GPIO24_SSP1FRMM_MD	(24 | GPIO_ALT_FN_2_OUT) 
+ 
+#define GPIO11_SSP2RX_MD	(11 | GPIO_ALT_FN_2_IN)
+#define GPIO13_SSP2TX_MD	(13 | GPIO_ALT_FN_1_OUT)
+#define GPIO22_SSP2CLKS_MD	(22 | GPIO_ALT_FN_3_IN)
+#define GPIO88_SSP2FRMS_MD	(88 | GPIO_ALT_FN_3_IN)
+#define GPIO22_SSP2CLKM_MD	(22 | GPIO_ALT_FN_3_OUT)
+#define GPIO88_SSP2FRMM_MD	(88 | GPIO_ALT_FN_3_OUT)
+
+#define GPIO82_SSP3RX_MD	(82 | GPIO_ALT_FN_1_IN)
+#define GPIO81_SSP3TX_MD	(81 | GPIO_ALT_FN_1_OUT)
+#define GPIO84_SSP3CLKS_MD	(84 | GPIO_ALT_FN_1_IN)
+#define GPIO83_SSP3FRMS_MD	(83 | GPIO_ALT_FN_1_IN)
+#define GPIO84_SSP3CLKM_MD	(84 | GPIO_ALT_FN_1_OUT)
+#define GPIO83_SSP3FRMM_MD	(83 | GPIO_ALT_FN_1_OUT)
+
+#define PXA_SSP_MHWFMT \
+	(SND_SOC_HWFMT_DSP_B  |SND_SOC_HWFMT_CBS_CFS | SND_SOC_HWFMT_CBM_CFS | \
+	SND_SOC_HWFMT_CBS_CFM | SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_NB_IF)
+	
+#define PXA_SSP_SHWFMT \
+	(SND_SOC_HWFMT_DSP_B  |SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS | \
+	SND_SOC_HWFMT_CBS_CFM | SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_NB_IF)
+
+#define PXA_SSP_DIR \
+	(SND_SOC_HWDIR_PLAYBACK | SND_SOC_HWDIR_CAPTURE)
+
+#define PXA_SSP_RATES \
+	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+	SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
+	SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
+
+/*
+ * SSP modes
+ */
+static struct snd_soc_hw_mode pxa2xx_ssp[] = {
+	/* port slave clk & frame modes */
+	{PXA_SSP_SHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		PXA_SSP_RATES, PXA_SSP_DIR, 0, SND_SOC_FS_ALL, SND_SOC_FSB_ALL},
+	
+	/* port master clk & frame modes */
+#ifdef CONFIG_PXA27x
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_8000, PXA_SSP_DIR, 0, SND_SOC_FS(256), SND_SOC_FSB(64)},
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_11025, PXA_SSP_DIR, 0, SND_SOC_FS(256), SND_SOC_FSB(64)},
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_16000, PXA_SSP_DIR, 0, SND_SOC_FS(256), SND_SOC_FSB(64)},
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_22050, PXA_SSP_DIR, 0, SND_SOC_FS(256), SND_SOC_FSB(64)},
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_32000, PXA_SSP_DIR, 0, SND_SOC_FS(256), SND_SOC_FSB(64)},
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_44100, PXA_SSP_DIR, 0, SND_SOC_FS(256), SND_SOC_FSB(64)},
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_48000, PXA_SSP_DIR, 0, SND_SOC_FS(256), SND_SOC_FSB(64)},
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_88200, PXA_SSP_DIR, 0, SND_SOC_FS(128), SND_SOC_FSB(64)},
+	{PXA_SSP_MHWFMT, SND_SOC_HWTDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE, 
+		SNDRV_PCM_RATE_96000, PXA_SSP_DIR, 0, SND_SOC_FS(128), SND_SOC_FSB(64)},
+#endif	
+};
+
+static struct ssp_dev ssp[3];
+#ifdef CONFIG_PM
+static struct ssp_state ssp_state[3];
+#endif
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp1_pcm_mono_out = {
+	.name			= "SSP1 PCM Mono out",
+	.dev_addr		= __PREG(SSDR_P1),
+	.drcmr			= &DRCMRTXSSDR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp1_pcm_mono_in = {
+	.name			= "SSP1 PCM Mono in",
+	.dev_addr		= __PREG(SSDR_P1),
+	.drcmr			= &DRCMRRXSSDR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp1_pcm_stereo_out = {
+	.name			= "SSP1 PCM Stereo out",
+	.dev_addr		= __PREG(SSDR_P1),
+	.drcmr			= &DRCMRTXSSDR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp1_pcm_stereo_in = {
+	.name			= "SSP1 PCM Stereo in",
+	.dev_addr		= __PREG(SSDR_P1),
+	.drcmr			= &DRCMRRXSSDR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp2_pcm_mono_out = {
+	.name			= "SSP2 PCM Mono out",
+	.dev_addr		= __PREG(SSDR_P2),
+	.drcmr			= &DRCMRTXSS2DR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp2_pcm_mono_in = {
+	.name			= "SSP2 PCM Mono in",
+	.dev_addr		= __PREG(SSDR_P2),
+	.drcmr			= &DRCMRRXSS2DR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp2_pcm_stereo_out = {
+	.name			= "SSP2 PCM Stereo out",
+	.dev_addr		= __PREG(SSDR_P2),
+	.drcmr			= &DRCMRTXSS2DR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp2_pcm_stereo_in = {
+	.name			= "SSP2 PCM Stereo in",
+	.dev_addr		= __PREG(SSDR_P2),
+	.drcmr			= &DRCMRRXSS2DR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp3_pcm_mono_out = {
+	.name			= "SSP3 PCM Mono out",
+	.dev_addr		= __PREG(SSDR_P3),
+	.drcmr			= &DRCMRTXSS3DR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp3_pcm_mono_in = {
+	.name			= "SSP3 PCM Mono in",
+	.dev_addr		= __PREG(SSDR_P3),
+	.drcmr			= &DRCMRRXSS3DR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp3_pcm_stereo_out = {
+	.name			= "SSP3 PCM Stereo out",
+	.dev_addr		= __PREG(SSDR_P3),
+	.drcmr			= &DRCMRTXSS3DR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_ssp3_pcm_stereo_in = {
+	.name			= "SSP3 PCM Stereo in",
+	.dev_addr		= __PREG(SSDR_P3),
+	.drcmr			= &DRCMRRXSS3DR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST32 | DCMD_WIDTH4,
+};
+
+static pxa2xx_pcm_dma_params_t *ssp_dma_params[3][4] = {
+	{&pxa2xx_ssp1_pcm_mono_out, &pxa2xx_ssp1_pcm_mono_in,
+	&pxa2xx_ssp1_pcm_stereo_out,&pxa2xx_ssp1_pcm_stereo_in,},
+	{&pxa2xx_ssp2_pcm_mono_out, &pxa2xx_ssp2_pcm_mono_in,
+	&pxa2xx_ssp2_pcm_stereo_out, &pxa2xx_ssp2_pcm_stereo_in,},
+	{&pxa2xx_ssp3_pcm_mono_out, &pxa2xx_ssp3_pcm_mono_in,
+	&pxa2xx_ssp3_pcm_stereo_out,&pxa2xx_ssp3_pcm_stereo_in,},
+};
+
+static pxa2xx_gpio_t ssp_gpios[3][2] = {
+	{{ /* SSP1 Slave */	
+		.rx = GPIO26_SSP1RX_MD,
+		.tx = GPIO25_SSP1TX_MD,
+		.clk = GPIO23_SSP1CLKS_MD,
+		.frm = GPIO24_SSP1FRMS_MD,
+	},
+	{ /* SSP1 Master */	
+		.rx = GPIO26_SSP1RX_MD,
+		.tx = GPIO25_SSP1TX_MD,
+		.clk = GPIO23_SSP1CLKM_MD,
+		.frm = GPIO24_SSP1FRMM_MD,
+	}},
+	{{ /* SSP2 Slave */	
+		.rx = GPIO11_SSP2RX_MD,
+		.tx = GPIO13_SSP2TX_MD,
+		.clk = GPIO22_SSP2CLKS_MD,
+		.frm = GPIO88_SSP2FRMS_MD,
+	},
+	{ /* SSP2 Master */	
+		.rx = GPIO11_SSP2RX_MD,
+		.tx = GPIO13_SSP2TX_MD,
+		.clk = GPIO22_SSP2CLKM_MD,
+		.frm = GPIO88_SSP2FRMM_MD,
+	}},
+	{{ /* SSP3 Slave */	
+		.rx = GPIO82_SSP3RX_MD,
+		.tx = GPIO81_SSP3TX_MD,
+		.clk = GPIO84_SSP3CLKS_MD,
+		.frm = GPIO83_SSP3FRMS_MD,
+	},
+	{ /* SSP3 Master */	
+		.rx = GPIO82_SSP3RX_MD,
+		.tx = GPIO81_SSP3TX_MD,
+		.clk = GPIO84_SSP3CLKM_MD,
+		.frm = GPIO83_SSP3FRMM_MD,
+	}},
+};
+
+static int pxa2xx_ssp_startup(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	int ret = 0;
+	
+	if((ret = ssp_init (&ssp[rtd->pcm_i->id], rtd->pcm_i->id + 1, SSP_NO_IRQ)) < 0)
+		return ret;
+	
+	ssp_disable(&ssp[rtd->pcm_i->id]);
+	return ret;
+}
+
+static void pxa2xx_ssp_shutdown(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+
+	ssp_disable(&ssp[rtd->pcm_i->id]);
+	ssp_exit(&ssp[rtd->pcm_i->id]);
+	rtd->pcm_i->active = 0;
+}
+
+#ifdef CONFIG_PM
+static int pxa2xx_ssp_suspend(struct platform_device *pdev, struct snd_soc_pcm_interface *pcm_i)
+{
+	int ret = 0;
+	
+	if(!pcm_i->active)
+		return 0;
+		
+	ssp_save_state(&ssp[pcm_i->id], &ssp_state[pcm_i->id]);
+	return ret;
+}
+
+static int pxa2xx_ssp_resume(struct platform_device *pdev, struct snd_soc_pcm_interface *pcm_i)
+{
+	int ret = 0;
+	
+	if(!pcm_i->active)
+		return 0;
+		
+	ssp_restore_state(&ssp[pcm_i->id], &ssp_state[pcm_i->id]);
+	return ret;
+}
+
+#else
+#define pxa2xx_ssp_suspend	NULL
+#define pxa2xx_ssp_resume	NULL
+#endif
+
+static unsigned int pxa_ssp_config_sysclk(struct snd_soc_pcm_interface *iface,
+	int rate, unsigned int clk)
+{
+	/* audio clock ? (divide by 1) */
+	if (clksrc == 3) {
+		switch(rate){
+		case 8000:
+		case 16000:
+		case 32000:
+		case 48000:
+		case 96000:
+			return 12288000;
+			break;
+		case 11025:
+		case 22050:
+		case 44100:
+		case 88200:
+			return 11289600;
+		break;
+		}
+	}
+
+	/* pll */
+	return sysclk;
+}	
+
+#ifdef CONFIG_PXA27x
+static u32 pxa27x_set_audio_clk(unsigned int rate, unsigned int fs)
+{
+	u32 aclk = 0, div = 0;
+	
+	switch(rate){
+	case 8000:
+	case 16000:
+	case 32000:
+	case 48000:
+	case 96000:
+		aclk = 0x2 << 4;
+		div = 12288000 / (rate * fs);
+		break;
+	case 11025:
+	case 22050:
+	case 44100:
+	case 88200:
+		aclk = 0x1 << 4;
+		div = 11289600 / (rate * fs);
+		break;
+	}
+	
+	aclk |= generic_ffs(div) - 1;
+	return aclk;
+}
+#endif
+
+static inline int get_scr(int srate)
+{
+	if(srate == 0)
+		return 0;
+	return (sysclk / srate) - 1;
+}
+
+static int pxa2xx_ssp_hw_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	int master = 0, dma = 0, fs;
+	u32 ssp_mode = 0, ssp_setup = 0, psp_mode = 0, rate = 0;
+	
+	fs = SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs);
+	if(rtd->pcm_i->hw_runtime.hwfmt & SND_SOC_HWFMT_CBS_CFS)
+		master = 1;
+
+	pxa_gpio_mode(ssp_gpios[rtd->pcm_i->id][master].rx);
+	pxa_gpio_mode(ssp_gpios[rtd->pcm_i->id][master].tx);
+	pxa_gpio_mode(ssp_gpios[rtd->pcm_i->id][master].frm);
+	pxa_gpio_mode(ssp_gpios[rtd->pcm_i->id][master].clk);
+	
+	if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
+		dma = 1;
+	if (params_channels(params) == 2)
+		dma += 2;
+	rtd->pcm_i->platform_data = ssp_dma_params[rtd->pcm_i->id][dma];
+
+	/* bit size */
+	switch(rtd->pcm_i->hw_runtime.hwpcmfmt) {
+		case SNDRV_PCM_FORMAT_S16_LE:
+			ssp_mode |= 0xf;
+			break;
+		case SNDRV_PCM_FORMAT_S20_3LE:
+			ssp_mode |= 0x100003;
+			break;
+		case SNDRV_PCM_FORMAT_S24_3LE:
+			ssp_mode |= 0x100007;
+			break;
+		case SNDRV_PCM_FORMAT_S32_LE:
+			ssp_mode |= 0x10000f;
+			break;
+	}
+
+	ssp_mode |= SSCR0_PSP;
+	ssp_setup = SSCR1_RxTresh(14) | SSCR1_TxTresh(1) | SSCR1_TRAIL |
+				SSCR1_TSRE | SSCR1_RSRE | SSCR1_TIE | SSCR1_RIE;
+
+	switch(rtd->pcm_i->hw_runtime.hwfmt & SND_SOC_HWFMT_CLOCK_MASK) {
+	case SND_SOC_HWFMT_CBM_CFM:
+		ssp_setup |= (SSCR1_SCLKDIR | SSCR1_SFRMDIR);
+		break;
+	case SND_SOC_HWFMT_CBM_CFS:
+		ssp_setup |= SSCR1_SCLKDIR;
+		break;
+	case SND_SOC_HWFMT_CBS_CFM:
+		ssp_setup |= SSCR1_SFRMDIR;
+		break;
+	}
+
+	switch(rtd->pcm_i->hw_runtime.hwfmt & SND_SOC_HWFMT_INV_MASK){
+	case SND_SOC_HWFMT_NB_NF:
+		psp_mode |= SSPSP_SFRMP;
+		break;
+	}
+	
+	if (rtd->pcm_i->hw_runtime.hwfmt & SND_SOC_HWFMT_DSP_A)
+		psp_mode |= SSPSP_SCMODE(2);
+	if (rtd->pcm_i->hw_runtime.hwfmt & SND_SOC_HWFMT_DSP_B)
+		psp_mode |= SSPSP_SCMODE(3);
+	psp_mode |= SSPSP_SFRMDLY(32);
+
+	switch(clksrc) {
+	case 2: /* network clock */
+		ssp_mode |= SSCR0_NCS | (1 << 31);
+	case 1: /* external clock */
+		ssp_mode |= SSCR0_ECS;
+	case 0: /* internal clock */
+	 	rate = get_scr(snd_soc_get_rate(rtd->pcm_c->hw_runtime.hwpcmrate));
+	 	break;
+#ifdef CONFIG_PXA27x
+	case 3: /* audio clock */
+		ssp_mode |= (1 << 30);
+		SSACD_P(rtd->pcm_i->id) = (0x1 << 3) |
+			pxa27x_set_audio_clk(snd_soc_get_rate(rtd->pcm_c->hw_runtime.hwpcmrate), fs);
+	 	break;
+#endif
+	}
+	
+	ssp_disable(&ssp[rtd->pcm_i->id]);
+	ssp_config(&ssp[rtd->pcm_i->id], ssp_mode, ssp_setup, psp_mode,
+		SSCR0_SerClkDiv(rate));
+//printk("mode %x setup %x psp %x clk %x\n", ssp_mode, ssp_setup, psp_mode,
+//		SSCR0_SerClkDiv(rate));
+	ssp_enable(&ssp[rtd->pcm_i->id]);
+	rtd->pcm_i->active = 1;
+	return 0;
+}
+
+struct snd_soc_pcm_interface pxa_ssp_interface[] = {
+	{	.name = "pxa2xx-ssp1",
+		.id = 0,
+		.type = SND_SOC_SSP,
+		.suspend = pxa2xx_ssp_suspend,
+		.resume = pxa2xx_ssp_resume,
+		.config_sysclk = pxa_ssp_config_sysclk,
+		.playback = {
+			.channels_min = 1,
+			.channels_max = 2,},
+		.capture = {
+			.channels_min = 1,
+			.channels_max = 2,},
+		.ops = {
+			.startup = pxa2xx_ssp_startup,
+			.shutdown = pxa2xx_ssp_shutdown,
+			.hw_params = pxa2xx_ssp_hw_params,},
+		.hw = {
+			.hmodes = &pxa2xx_ssp[0],
+			.num_hmodes = ARRAY_SIZE(pxa2xx_ssp),},
+	},
+	{	.name = "pxa2xx-ssp2",
+		.id = 1,
+		.type = SND_SOC_SSP,
+		.suspend = pxa2xx_ssp_suspend,
+		.resume = pxa2xx_ssp_resume,
+		.config_sysclk = pxa_ssp_config_sysclk,
+		.playback = {
+			.channels_min = 1,
+			.channels_max = 2,},
+		.capture = {
+			.channels_min = 1,
+			.channels_max = 2,},
+		.ops = {
+			.startup = pxa2xx_ssp_startup,
+			.shutdown = pxa2xx_ssp_shutdown,
+			.hw_params = pxa2xx_ssp_hw_params,},
+		.hw = {
+			.hmodes = &pxa2xx_ssp[0],
+			.num_hmodes = ARRAY_SIZE(pxa2xx_ssp),},
+	},
+	{	.name = "pxa2xx-ssp3",
+		.id = 2,
+		.type = SND_SOC_SSP,
+		.suspend = pxa2xx_ssp_suspend,
+		.resume = pxa2xx_ssp_resume,
+		.config_sysclk = pxa_ssp_config_sysclk,
+		.playback = {
+			.channels_min = 1,
+			.channels_max = 2,},
+		.capture = {
+			.channels_min = 1,
+			.channels_max = 2,},
+		.ops = {
+			.startup = pxa2xx_ssp_startup,
+			.shutdown = pxa2xx_ssp_shutdown,
+			.hw_params = pxa2xx_ssp_hw_params,},
+		.hw = {
+			.hmodes = &pxa2xx_ssp[0],
+			.num_hmodes = ARRAY_SIZE(pxa2xx_ssp),},
+	},
+};
+
+EXPORT_SYMBOL_GPL(pxa_ssp_interface);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("pxa2xx SSP/PCM SoC Interface");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
new file mode 100644
index 0000000..a3b59aa
--- /dev/null
+++ b/sound/soc/pxa/spitz.c
@@ -0,0 +1,336 @@
+/*
+ * spitz.c  --  SoC audio for Sharp SL-Cxx00 models Spitz, Borzoi and Akita
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Copyright 2005 Openedhand Ltd.
+ * 
+ * Authors: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
+ *          Richard Purdie <richard@openedhand.com>
+ * 
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    30th Nov 2005   Initial version.
+ * 
+ */
+ 
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/hardware/scoop.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/akita.h>
+#include <asm/arch/spitz.h>
+#include <asm/mach-types.h>
+#include "../codecs/wm8750.h"
+#include "pxa2xx-pcm.h"
+
+#define SPITZ_HP        0
+#define SPITZ_MIC       1
+#define SPITZ_LINE      2
+#define SPITZ_HEADSET   3
+#define SPITZ_HP_OFF    4
+#define SPITZ_SPK_AUTO  0
+#define SPITZ_SPK_ON    1
+#define SPITZ_SPK_OFF   2
+
+static int spitz_jack_func = 0;
+static int spitz_spk_func = 0;
+static int ld2ro = 0; /* left DAC to R mixer status - for headset */
+
+#define READ_GPIO_BIT(x)    (GPLR(x) & GPIO_bit(x))
+
+static void spitz_ext_control(struct snd_soc_codec *codec)
+{
+	if ((spitz_spk_func == SPITZ_SPK_ON) || ((spitz_spk_func == SPITZ_SPK_AUTO)
+			&& READ_GPIO_BIT(SPITZ_GPIO_AK_INT)))
+		snd_soc_dapm_set_endpoint(codec, "Ext Spk", 1);
+	else
+		snd_soc_dapm_set_endpoint(codec, "Ext Spk", 0);
+
+	/* set up jack connection */
+	switch(spitz_jack_func) {
+	case SPITZ_HP:
+		/* enable and unmute hp jack, disable mic bias */
+		snd_soc_dapm_set_endpoint(codec, "Headset Headphone Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
+		set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
+		set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
+		break;
+	case SPITZ_MIC:
+		/* enable mic jack and bias, mute hp */
+		snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Headset Headphone Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
+		reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
+		reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
+		break;
+	case SPITZ_LINE:
+		/* enable line jack, disable mic bias and mute hp */
+		snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Headset Headphone Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Line Jack", 1);
+		reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
+		reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
+		break;
+	case SPITZ_HEADSET:
+		/* enable and unmute headset jack enable mic bias, mute L hp */
+		snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
+		snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Headset Headphone Jack", 1);
+		reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
+		set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
+		break;
+	case SPITZ_HP_OFF:
+
+		/* jack removed, everything off */
+		snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Headset Headphone Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
+		snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
+		reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
+		reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
+		break;
+	}
+	snd_soc_dapm_sync_endpoints(codec);
+}
+
+static int spitz_startup(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_codec *codec = rtd->socdev->codec;
+
+	/* check the jack status at stream startup */	
+	ld2ro = codec->read(codec, WM8750_ROUTM1);
+	spitz_ext_control(codec);
+	return 0;
+}
+
+static struct snd_soc_ops spitz_ops = {
+	.startup = spitz_startup,
+};
+
+static int spitz_get_jack(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.integer.value[0] = spitz_jack_func;
+	return 0;
+}
+
+static int spitz_set_jack(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{	
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	spitz_jack_func = ucontrol->value.integer.value[0];
+	spitz_ext_control(codec);
+	return 0;
+}
+
+static int spitz_get_spk(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.integer.value[0] = spitz_spk_func;
+	return 0;
+}
+
+static int spitz_set_spk(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec =  snd_kcontrol_chip(kcontrol);
+	spitz_spk_func = ucontrol->value.integer.value[0];
+	spitz_ext_control(codec);
+	return 0;
+}
+
+static int spitz_mic_bias(struct snd_soc_dapm_widget* w, int power)
+{
+	if (machine_is_borzoi() || machine_is_spitz()) {	
+		if(power)
+			set_scoop_gpio(&spitzscoop2_device.dev, SPITZ_SCP2_MIC_BIAS);
+		else
+			reset_scoop_gpio(&spitzscoop2_device.dev, SPITZ_SCP2_MIC_BIAS);
+	}
+	
+	if(machine_is_akita()){
+		if(power)
+			akita_set_ioexp(&akitaioexp_device.dev, AKITA_IOEXP_MIC_BIAS);
+		else
+			akita_reset_ioexp(&akitaioexp_device.dev, AKITA_IOEXP_MIC_BIAS);
+	}
+	return 0;
+}
+
+/* spitz machine dapm widgets */
+static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
+	SND_SOC_DAPM_HP("Headphone Jack", NULL),
+	SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
+	SND_SOC_DAPM_SPK("Ext Spk", NULL),
+	SND_SOC_DAPM_LINE("Line Jack", NULL),
+	
+	/* headset is a mic and mono headphone */
+	SND_SOC_DAPM_HP("Headset Headphone Jack", NULL),
+};
+
+/* Spitz machine audio interconnections */
+static const char* intercon[][3] = {
+	
+	/* headphone connected to LOUT1, ROUT1 */
+	{"Headphone Jack", NULL, "LOUT1"},
+	{"Headphone Jack", NULL, "ROUT1"},
+	
+	/* headset connected to ROUT1 and LINPUT1 with bias (def below) */
+	{"Headset Headphone Jack", NULL, "ROUT1"},
+	
+	/* ext speaker connected to LOUT2, ROUT2  */
+	{"Ext Spk", NULL , "ROUT2"},
+	{"Ext Spk", NULL , "LOUT2"},
+	
+	/* mic is connected to input 1 - with bias */
+	{"LINPUT1", NULL, "Mic Bias"},
+	{"Mic Bias", NULL, "Mic Jack"},
+	
+	/* line is connected to input 1 - no bias */
+	{"LINPUT1", NULL, "Line Jack"},
+
+	{NULL, NULL, NULL},
+};
+
+static const char* jack_function[] = {"Headphone", "Mic", "Line", "Headset", "Off"};
+static const char* spk_function[] = {"Auto", "On", "Off"};
+static const struct soc_enum spitz_enum[] = {
+	SOC_ENUM_SINGLE_EXT(5, jack_function),
+	SOC_ENUM_SINGLE_EXT(3, spk_function),
+};
+
+static const snd_kcontrol_new_t wm8750_spitz_controls[] = {
+	SOC_ENUM_EXT("Jack Function", spitz_enum[0], spitz_get_jack, spitz_set_jack),
+	SOC_ENUM_EXT("Speaker Function", spitz_enum[1], spitz_get_spk, spitz_set_spk),
+};
+
+/*
+ * Logic for a wm8750 as connected on a Sharp SL-Cxx00 Device
+ */
+static int spitz_wm8750_init(struct snd_soc_codec *codec)
+{
+	int i, err;
+
+	snd_soc_dapm_set_endpoint(codec, "RINPUT1", 0);
+	snd_soc_dapm_set_endpoint(codec, "LINPUT2", 0);
+	snd_soc_dapm_set_endpoint(codec, "RINPUT2", 0);
+	snd_soc_dapm_set_endpoint(codec, "LINPUT3", 0);
+	snd_soc_dapm_set_endpoint(codec, "RINPUT3", 0);
+	snd_soc_dapm_set_endpoint(codec, "OUT3", 0);
+	snd_soc_dapm_set_endpoint(codec, "MONO", 0);
+
+	/* Add spitz specific controls */
+	for (i = 0; i < ARRAY_SIZE(wm8750_spitz_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&wm8750_spitz_controls[i], codec, NULL))) < 0)
+			return err;
+	}
+
+	/* Add spitz specific widgets */
+	for(i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
+	}
+	
+	/* Set up spitz specific audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_sync_endpoints(codec);
+	return 0;
+}
+
+unsigned int spitz_config_sysclk(struct snd_soc_pcm_runtime *rtd, 
+	int rate, unsigned int hwfmt)
+{
+	if(hwfmt & SND_SOC_HWFMT_CBS_CFS) {
+		if(rtd->pcm_i->config_sysclk)
+			return rtd->pcm_i->config_sysclk(rtd->pcm_i, rate, 0);
+	} else {
+		/* spitz has a 12.235MHz sysclk - we round to a nice audio 12.288 */
+		if(rtd->pcm_c->config_sysclk)
+			return rtd->pcm_c->config_sysclk(rtd->pcm_c, rate, 12288000);
+	}
+	
+	return 0;
+}
+
+static struct snd_soc_machine_config codecs = {
+	.name = "wm8750", 
+	.sname = "WM8750",
+	.iface = &pxa_i2s_interface,
+	.init = spitz_wm8750_init,
+	.config_sysclk = spitz_config_sysclk,
+};
+
+static struct snd_soc_machine snd_soc_machine_spitz = {
+	.name = "Spitz",
+	.config = &codecs,
+	.nconfigs = 1,
+	.ops = &spitz_ops,
+};
+
+static struct wm8750_setup_data spitz_wm8750_setup = {
+	.i2c_address = 0x1b,
+};
+
+static struct snd_soc_device spitz_snd_devdata = {
+	.machine = &snd_soc_machine_spitz,
+	.platform = &pxa2xx_soc_platform,
+	.codec_dev = &soc_codec_dev_wm8750,
+	.codec_data = &spitz_wm8750_setup,
+};
+
+static struct platform_device *spitz_snd_device;
+
+static int __init spitz_init(void) 
+{
+	int ret;
+
+	pxa_gpio_mode(SPITZ_GPIO_AK_INT | GPIO_IN);
+
+	spitz_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!spitz_snd_device) {
+		free_irq(SPITZ_IRQ_GPIO_AK_INT, spitz_snd_device);
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(spitz_snd_device, &spitz_snd_devdata);
+	spitz_snd_devdata.dev = &spitz_snd_device->dev;
+	ret = platform_device_add(spitz_snd_device);
+	
+	if (ret)
+		platform_device_put(spitz_snd_device);
+
+	return ret;
+}
+
+static void __exit spitz_exit(void) 
+{
+	platform_device_unregister(spitz_snd_device);
+}
+
+module_init(spitz_init);
+module_exit(spitz_exit);
+
+MODULE_AUTHOR("Richard Purdie");
+MODULE_DESCRIPTION("ALSA SoC Spitz");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/tosa.c b/sound/soc/pxa/tosa.c
new file mode 100644
index 0000000..98fa37f
--- /dev/null
+++ b/sound/soc/pxa/tosa.c
@@ -0,0 +1,258 @@
+/*
+ * tosa.c  --  SoC audio for Tosa
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Copyright 2005 Openedhand Ltd.
+ * 
+ * Authors: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
+ *          Richard Purdie <richard@openedhand.com>
+ * 
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    30th Nov 2005   Initial version.
+ * 
+ * GPIO's
+ *  1 - Jack Insertion 
+ *  5 - Hookswitch (headset answer/hang up switch)
+ * 
+ */
+ 
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/audio.h>
+
+#include "../codecs/wm9712.h"
+#include "pxa2xx-pcm.h"
+
+static struct snd_soc_machine tosa;
+
+#define TOSA_HP        0
+#define TOSA_MIC_INT   1
+#define TOSA_HEADSET   2
+#define TOSA_HP_OFF    3
+#define TOSA_SPK_AUTO  0
+#define TOSA_SPK_ON    1
+#define TOSA_SPK_OFF   2
+
+static int tosa_jack_func = 0;
+static int tosa_spk_func = 0;
+
+#define READ_GPIO_BIT(x)    (GPLR(x) & GPIO_bit(x))
+
+static void tosa_ext_control(struct snd_soc_codec *codec)
+{
+	int spk = 0, mic_int = 0, hp = 0, hs = 0;
+	
+	/* set up jack connection */
+	switch(tosa_jack_func) {
+	case TOSA_HP:
+		hp = 1;
+		break;
+	case TOSA_MIC_INT:
+		mic_int = 1;
+		break;
+	case TOSA_HEADSET:
+		hs = 1;
+		break;
+	}
+
+/* FIXME for auto speaker on tosa */
+	//if ((READ_GPIO_BIT(TOSA_GPIO_AK_INT) && (tosa_spk_func == TOSA_SPK_AUTO))
+	//		|| (tosa_spk_func == TOSA_SPK_ON))
+		spk = 1;
+
+	snd_soc_dapm_set_endpoint(codec, "Speaker", spk);
+	snd_soc_dapm_set_endpoint(codec, "Mic (Internal)", mic_int);
+	snd_soc_dapm_set_endpoint(codec, "Headphone Jack", hp);
+	snd_soc_dapm_set_endpoint(codec, "Headset Jack", hs);
+	snd_soc_dapm_sync_endpoints(codec);
+}
+
+static int tosa_startup(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_codec *codec = rtd->socdev->codec;
+
+	/* check the jack status at stream startup */	
+	tosa_ext_control(codec);
+	return 0;
+}
+
+static struct snd_soc_ops tosa_ops = {
+	.startup = tosa_startup,
+};
+
+static int tosa_get_jack(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.integer.value[0] = tosa_jack_func;
+	return 0;
+}
+
+static int tosa_set_jack(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{	
+	struct snd_soc_codec *codec =  snd_kcontrol_chip(kcontrol);
+	tosa_jack_func = ucontrol->value.integer.value[0];
+	tosa_ext_control(codec);
+	return 0;
+}
+
+static int tosa_get_spk(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.integer.value[0] = tosa_spk_func;
+	return 0;
+}
+
+static int tosa_set_spk(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec =  snd_kcontrol_chip(kcontrol);
+	tosa_spk_func = ucontrol->value.integer.value[0];
+	tosa_ext_control(codec);
+	return 0;
+}
+
+/* tosa machine dapm widgets */
+static const struct snd_soc_dapm_widget tosa_dapm_widgets[] = {
+SND_SOC_DAPM_HP("Headphone Jack", NULL),
+SND_SOC_DAPM_HP("Headset Jack", NULL),
+SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
+SND_SOC_DAPM_SPK("Speaker", NULL),
+};
+
+/* example machine interconnections */
+static const char* intercon[][3] = {
+	
+	/* headphone connected to HPOUTL, HPOUTR */
+	{"Headphone Jack", NULL, "HPOUTL"},
+	{"Headphone Jack", NULL, "HPOUTR"},
+	
+	/* ext speaker connected to LOUT2, ROUT2 */
+	{"Speaker", NULL, "LOUT2"},
+	{"Speaker", NULL, "ROUT2"},
+	
+	/* internal mic is connected to mic1, mic2 differential - with bias */
+	{"MIC1", NULL, "Mic Bias"},
+	{"MIC2", NULL, "Mic Bias"},
+	{"Mic Bias", NULL, "Mic (Internal)"},
+	
+	/* headset is connected to HPOUTR, and LINEINR with bias */
+	{"Headset Jack", NULL, "HPOUTR"},
+	{"LINEINR", NULL, "Mic Bias"},
+	{"Mic Bias", NULL, "Headset Jack"},
+	
+	{NULL, NULL, NULL},
+};
+
+static const char* jack_function[] = {"Headphone", "Mic", "Line", "Headset", "Off"};
+static const char* spk_function[] = {"Auto", "On", "Off"};
+static const struct soc_enum tosa_enum[] = {
+	SOC_ENUM_SINGLE_EXT(5, jack_function),
+	SOC_ENUM_SINGLE_EXT(3, spk_function),
+};
+
+static const snd_kcontrol_new_t tosa_controls[] = {
+	SOC_ENUM_EXT("Jack Function", tosa_enum[0], tosa_get_jack, tosa_set_jack),
+	SOC_ENUM_EXT("Speaker Function", tosa_enum[1], tosa_get_spk, tosa_set_spk),
+};
+
+static int tosa_ac97_init(struct snd_soc_codec *codec)
+{
+	int i, err;
+	
+	snd_soc_dapm_set_endpoint(codec, "OUT3", 0);
+	snd_soc_dapm_set_endpoint(codec, "MONOOUT", 0);
+	
+	/* add tosa specific controls */
+	for (i = 0; i < ARRAY_SIZE(tosa_controls); i++) {
+		if ((err = snd_ctl_add(codec->card, 
+				snd_soc_cnew(&tosa_controls[i],codec, NULL))) < 0)
+			return err;
+	}
+
+	/* add tosa specific widgets */
+	for(i = 0; i < ARRAY_SIZE(tosa_dapm_widgets); i++) {
+		snd_soc_dapm_new_control(codec, &tosa_dapm_widgets[i]);
+	}
+	
+	/* set up tosa specific audio path interconnects */
+	for(i = 0; intercon[i][0] != NULL; i++) {
+		snd_soc_dapm_connect_input(codec, intercon[i][0], intercon[i][1], intercon[i][2]);
+	}
+	
+	snd_soc_dapm_sync_endpoints(codec);
+	return 0;
+}
+
+static struct snd_soc_machine_config codecs[] = {
+{
+	.name = "AC97", 
+	.sname = "AC97 HiFi", 
+	.iface = &pxa_ac97_interface[0],
+	.init = tosa_ac97_init,
+},
+{
+	.name = "AC97 Aux", 
+	.sname = "AC97 Aux",
+	.iface = &pxa_ac97_interface[1],
+},
+};
+
+static struct snd_soc_machine tosa = {
+	.name = "Tosa",
+	.config = codecs,
+	.nconfigs = ARRAY_SIZE(codecs),
+	.ops = &tosa_ops,
+};
+
+static struct snd_soc_device tosa_snd_devdata = {
+	.machine = &tosa,
+	.platform = &pxa2xx_soc_platform,
+	.codec_dev = &soc_codec_dev_wm9712,
+};
+
+static struct platform_device *tosa_snd_device;
+
+static int __init tosa_init(void) 
+{
+	int ret;
+
+	tosa_snd_device = platform_device_alloc("soc-audio", -1);
+	if (!tosa_snd_device)
+		return -ENOMEM;
+
+	platform_set_drvdata(tosa_snd_device, &tosa_snd_devdata);
+	tosa_snd_devdata.dev = &tosa_snd_device->dev;
+	ret = platform_device_add(tosa_snd_device);
+
+	if (ret)
+		platform_device_put(tosa_snd_device);
+
+	return ret;
+}
+
+static void __exit tosa_exit(void) 
+{
+	platform_device_unregister(tosa_snd_device);
+}
+
+module_init(tosa_init);
+module_exit(tosa_exit);
+
+/* Module information */ 
+MODULE_AUTHOR("Richard Purdie");
+MODULE_DESCRIPTION("ALSA SoC Tosa");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
new file mode 100644
index 0000000..5576124
--- /dev/null
+++ b/sound/soc/soc-core.c
@@ -0,0 +1,1585 @@
+/*
+ * soc-core.c  --  ALSA SoC Audio Layer
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    12th Aug 2005   Initial version.
+ *    25th Oct 2005   Working Codec, Interface and Platform registration.
+ *
+ *  TODO:
+ *   o Add hw rules to enforce rates, etc.
+ *   o More testing with other codecs/machines.
+ *   o Add more codecs and platforms to ensure good API coverage.
+ *   o Support TDM on PCM and I2S
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/bitops.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+/* debug */
+#define SOC_DEBUG 0
+#if SOC_DEBUG
+#define dbg(format, arg...) printk(format, ## arg)
+#else
+#define dbg(format, arg...)
+#endif
+
+#define iface_name(x) \
+	(((x) == SND_SOC_AC97) ? "ac97" : \
+	((x) == SND_SOC_I2S) ? "i2s" : \
+	((x) == SND_SOC_SSP) ? "ssp" : NULL)
+	
+static DECLARE_MUTEX(soc_pcm_sem);
+
+static const unsigned int rates[] = {
+	5512, 8000, 11025, 16000, 22050, 32000, 44100,
+	48000, 64000, 88200, 96000, 176400, 192000
+};
+
+static const unsigned char formats[] = {
+	8, 8, 16, 16, 16, 16, 24, 24, 24, 24, 32, 32, 32, 32, 32, 32, 64, 64,
+	16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 20, 20, 20, 20, 20,
+	18, 18, 18, 18
+};
+
+/* unregister ac97 codec */
+static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
+{
+	if (codec->ac97->dev.bus)
+		device_unregister(&codec->ac97->dev);
+	return 0;
+}
+
+/* stop no dev release warning */
+static void soc_ac97_device_release(struct device * dev)
+{
+}
+
+/* register ac97 codec to bus */
+static int soc_ac97_dev_register(struct snd_soc_codec *codec)
+{
+	int err;
+
+	codec->ac97->dev.bus = &ac97_bus_type;
+	codec->ac97->dev.parent = NULL;
+	codec->ac97->dev.release = soc_ac97_device_release;
+
+	snprintf(codec->ac97->dev.bus_id, BUS_ID_SIZE, "%d-%d:%s",
+		 codec->card->number, 0, codec->name);
+	if ((err = device_register(&codec->ac97->dev)) < 0) {
+		snd_printk(KERN_ERR "Can't register ac97 bus\n");
+		codec->ac97->dev.bus = NULL;
+		return err;
+	}
+	return 0;
+}
+
+/* get rate format from rate */
+static inline int soc_get_rate_format(int rate)
+{
+	int i;	
+	
+	for (i = 0; i < ARRAY_SIZE(rates); i++) {
+		if(rates[i] == rate)
+			return 1 << i;
+	}
+	return 0;
+}
+
+/* get FS from rate and mclk */
+static inline int soc_get_fs(int rate, unsigned int mclk, 
+	unsigned int hwfmt, unsigned int ihwfs, unsigned int chwfs)
+{
+	unsigned int i, fs_, fs;
+	int diff;
+	fs = mclk / rate;
+
+	/* return all fs if the slave doesn't mind the value of fs */
+	if(hwfmt & SND_SOC_HWFMT_CBM_CFM) {
+		if(ihwfs == SND_SOC_FS_ALL)
+			return SND_SOC_FS_ALL;
+	} else {
+		if(chwfs == SND_SOC_FS_ALL) {
+			return SND_SOC_FS_ALL;
+		}
+	}
+			
+	/* find the nearest matching value */
+	for(i = 1; i <= 32; i++) {
+		fs_ = 64 * i;
+		diff = fs_ - fs;
+		/* we have some tolerance for clocks that are not exact */
+		if(diff <= 3 && diff >= -3)
+			return fs_;
+	}
+	return 0;
+}
+
+/* gets a audio system mclk for the given parameters */
+static unsigned int soc_get_mclk(struct snd_soc_pcm_runtime *rtd, int rate,
+	unsigned int hwfmt)
+{
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_machine *machine = socdev->machine;
+	int i;
+		
+	for(i = 0; i < machine->nconfigs; i++) {
+		if(machine->config[i].iface == rtd->pcm_i && 
+			machine->config[i].config_sysclk)
+			return machine->config[i].config_sysclk(rtd, rate, hwfmt);
+	}
+	return 0;
+}
+
+static inline int soc_get_format(unsigned int hwpcmfmt)
+{
+	if (hwpcmfmt < ARRAY_SIZE(formats))
+		return formats[hwpcmfmt];
+	return 0;
+}
+
+/* changes a bitclk multiplier to divider */ 
+static u16 soc_bfs_mult_to_div(u16 bfs, int rate, unsigned int mclk,
+	unsigned int hwpcmfmt, unsigned int word)
+{
+	int i, j;
+	u16 bfs_ = 0;
+	unsigned int size = soc_get_format(hwpcmfmt), min = 0;
+	
+	if(!size)
+		return 0;
+		
+	/* the minimum bit clock that has enough bandwidth */	
+	min = size * rate * word;
+
+	for (i = 0; i < 16; i++) {
+		if((bfs >> i) & 0x1) {
+			j = rate * SND_SOC_FSB_INT(1<<i);
+			if(j >= min)
+				bfs_ |= SND_SOC_FSBD(mclk/j);
+		} 	
+	}
+
+	return bfs_;
+}
+
+/* changes a bitclk divider to multiplier */ 
+static u16 soc_bfs_div_to_mult(u16 bfs, int rate, unsigned int mclk,
+	unsigned int hwpcmfmt, unsigned int word)
+{
+	int i, j;
+	u16 bfs_ = 0;
+	unsigned int size = soc_get_format(hwpcmfmt), min = 0;
+	
+	if(!size)
+		return 0;
+		
+	/* the minimum bit clock that has enough bandwidth */	
+	min = size * rate * word;
+	
+	for (i = 0; i < 16; i++) {
+		if((bfs >> i) & 0x1) {
+			j = mclk / SND_SOC_FSBD_INT(1<<i);
+			if(j >= min)
+				bfs_ |= SND_SOC_FSB(j/rate);
+		} 	
+	}
+
+	return bfs_;
+}
+
+/* Matches codec and DAI hardware parameters */
+static int soc_hw_match_params(snd_pcm_substream_t *substream, 
+	snd_pcm_hw_params_t *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_hw_mode *c = NULL; 
+	struct snd_soc_hw_mode *i = NULL; 
+	unsigned int fs, mclk, cbfs, ibfs, rate = params_rate(params), word;
+	u16 hwfmt = 0;
+	int j, k;
+
+	/* try and find a match from the codec and interface DAI descriptions */
+	for (j = 0; j < rtd->pcm_c->hw.num_hmodes; j++) {
+		for (k = 0; k < rtd->pcm_i->hw.num_hmodes; k++) {
+			c = &rtd->pcm_c->hw.hmodes[j];
+			i = &rtd->pcm_i->hw.hmodes[k];
+
+			if(!(c->hwpcmrate & i->hwpcmrate & soc_get_rate_format(rate))) {
+				dbg("soc: DAI[%d:%d] failed to match rate\n", j, k);
+				continue;
+			}
+		
+			hwfmt = c->hwfmt & i->hwfmt;
+			if (!(hwfmt & SND_SOC_HWFMT_FORMAT_MASK)) {
+				dbg("soc: DAI[%d:%d] failed to match format\n", j, k);
+				continue;
+			}
+	
+			if (!(hwfmt & SND_SOC_HWFMT_CLOCK_MASK)) {
+				dbg("soc: DAI[%d:%d] failed to match clock\n", j, k);
+				continue;
+			}
+
+			if (!(hwfmt & SND_SOC_HWFMT_INV_MASK)) {
+				dbg("soc: DAI[%d:%d] failed to match invert\n", j, k);
+				continue;
+			}
+		
+			if (!(c->hwpcmfmt & i->hwpcmfmt)) {
+				dbg("soc: DAI[%d:%d] failed to match pcm format\n", j, k);
+				continue;
+			}
+					
+			if(!(c->hwpcmdir & i->hwpcmdir)) {
+				dbg("soc: DAI[%d:%d] failed to match direction\n", j, k);
+				continue;
+			}
+		
+			/* liam - still need to add tdm selection */
+			rtd->pcm_i->hw_runtime.hwfmt = rtd->pcm_c->hw_runtime.hwfmt = 
+				1 << (generic_ffs(hwfmt & SND_SOC_HWFMT_FORMAT_MASK) -1) | 
+				1 << (generic_ffs(hwfmt & SND_SOC_HWFMT_CLOCK_MASK) - 1) |
+				1 << (generic_ffs(hwfmt & SND_SOC_HWFMT_INV_MASK) - 1);
+				
+			/* calculate clocking */	
+			mclk = soc_get_mclk(rtd, rate, hwfmt);
+			fs = soc_get_fs(rate, mclk, hwfmt, i->hwfs, c->hwfs);
+			
+			if(fs != SND_SOC_FS_ALL) {
+				if(!(SND_SOC_FS(fs) & i->hwfs & c->hwfs)) {
+					dbg("soc: DAI[%d:%d] failed to match FS\n", j, k);
+					dbg("soc: FS %x iface %x codec %x\n", SND_SOC_FS(fs), i->hwfs, c->hwfs);
+					dbg("soc: mclk %d hwfmt %x\n", mclk, hwfmt);
+					continue;
+				}
+			
+				rtd->pcm_i->hw_runtime.hwfs = rtd->pcm_c->hw_runtime.hwfs = 
+					SND_SOC_FS(fs);
+			} else
+				rtd->pcm_i->hw_runtime.hwfs = rtd->pcm_c->hw_runtime.hwfs =
+					SND_SOC_FS_ALL;
+				
+			/* calculate word size (per channel) */	
+			rtd->pcm_c->hw_runtime.hwpcmfmt = rtd->pcm_i->hw_runtime.hwpcmfmt =
+				params_format(params);
+			word = params_channels(params);
+			if(rtd->pcm_i->hw_runtime.hwfmt & 
+				(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_RIGHT_J | SND_SOC_HWFMT_LEFT_J))
+				word <<= 1;
+				
+			/* calculate bfs */
+			if(c->hwflags & i->hwflags & SND_SOC_HW_BFS_DIV) {
+				/* i & c bfs dividers */
+				rtd->pcm_i->hw_runtime.hwbfs = rtd->pcm_c->hw_runtime.hwbfs = 
+					1 << (generic_fls(c->hwbfs & i->hwbfs));
+			} else if (c->hwflags & SND_SOC_HW_BFS_DIV) {
+				/* normalise bfs c & i */
+				cbfs = soc_bfs_div_to_mult(c->hwbfs, rate, mclk, 
+						rtd->pcm_c->hw_runtime.hwpcmfmt, word);
+				rtd->pcm_i->hw_runtime.hwbfs = 
+					1 << (generic_ffs(cbfs & i->hwbfs) - 1);
+				ibfs = soc_bfs_mult_to_div(i->hwbfs, rate, mclk, 
+						rtd->pcm_c->hw_runtime.hwpcmfmt, word);
+				rtd->pcm_c->hw_runtime.hwbfs = 
+					1 << (generic_fls(c->hwbfs & ibfs) - 1);
+			} else if (i->hwflags & SND_SOC_HW_BFS_DIV) {
+				/* normalise bfs c & i */
+				cbfs = soc_bfs_mult_to_div(c->hwbfs, rate, mclk, 
+						rtd->pcm_c->hw_runtime.hwpcmfmt, word);
+				rtd->pcm_i->hw_runtime.hwbfs = 
+					1 << (generic_fls(cbfs & i->hwbfs) -1);
+				ibfs = soc_bfs_div_to_mult(i->hwbfs, rate, mclk, 
+						rtd->pcm_c->hw_runtime.hwpcmfmt, word);
+				rtd->pcm_c->hw_runtime.hwbfs = 
+					1 << (generic_ffs(c->hwbfs & ibfs) -1);
+			} else {
+				/* i & c bfs rate multipliers */
+				rtd->pcm_i->hw_runtime.hwbfs = rtd->pcm_c->hw_runtime.hwbfs = 
+					1 << (generic_ffs(c->hwbfs & i->hwbfs));
+			}
+
+			if(!rtd->pcm_i->hw_runtime.hwbfs || !rtd->pcm_c->hw_runtime.hwbfs) {
+				dbg("soc: DAI[%d:%d] failed to match BFS\n", j, k);
+				dbg("soc: iface %x codec %x\n", rtd->pcm_i->hw_runtime.hwbfs, 
+					rtd->pcm_c->hw_runtime.hwbfs);
+				dbg("soc: mclk %d hwfmt %x\n", mclk, hwfmt);
+				continue;
+			}
+				
+			goto found;
+		}
+	}
+	printk(KERN_ERR "soc: no matching hw interface config found\n");
+	return -EINVAL;
+
+found:
+	/* we have matching DAI's, so complete the runtime info */
+	rtd->pcm_c->hw_runtime.hwpcmrate = rtd->pcm_i->hw_runtime.hwpcmrate = 
+		soc_get_rate_format(rate);
+		
+	rtd->pcm_c->hw_runtime.priv = c->priv;
+	rtd->pcm_i->hw_runtime.priv = i->priv;
+#if SOC_DEBUG 
+	/* for debug atm */
+	printk("soc: DAI[%d:%d] Match OK\n", j, k);
+	printk(KERN_INFO "soc: codec fs %d bfs %d format %x\n", 
+		rtd->pcm_c->hw_runtime.hwfs, rtd->pcm_c->hw_runtime.hwbfs, 
+		rtd->pcm_c->hw_runtime.hwfmt);
+	printk(KERN_INFO "soc: iface fs %d bfs %d format %x\n",	
+		rtd->pcm_i->hw_runtime.hwfs, rtd->pcm_i->hw_runtime.hwbfs, 
+		rtd->pcm_i->hw_runtime.hwfmt);
+	
+	if(c->hwflags & SND_SOC_HW_BFS_DIV)
+		printk(KERN_INFO "soc: mclk %d bclk %d\n", 
+		SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs) * params_rate(params),
+		(SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs) * params_rate(params)) / 
+			SND_SOC_FSBD_INT(rtd->pcm_c->hw_runtime.hwbfs));
+	else
+		printk(KERN_INFO "soc: mclk %d bclk %d\n", 
+		SND_SOC_FS_INT(rtd->pcm_c->hw_runtime.hwfs) * params_rate(params),
+		params_rate(params) * SND_SOC_FSB_INT(rtd->pcm_c->hw_runtime.hwbfs));
+	
+	printk(KERN_INFO "soc: audio rate %d chn %d\n", params_rate(params), 
+		params_channels(params));	
+#endif	
+	return 0;
+}
+
+static inline u32 get_rates(struct snd_soc_hw_mode *modes, int nmodes)
+{
+	int i;
+	u32 rates = 0;
+	
+	for(i = 0; i < nmodes; i++)
+		rates |= modes[i].hwpcmrate;
+
+	return rates;
+}
+
+static inline u64 get_formats(struct snd_soc_hw_mode *modes, int nmodes)
+{
+	int i;
+	u64 formats = 0;
+	
+	for(i = 0; i < nmodes; i++)
+		formats |= modes[i].hwpcmfmt;
+
+	return formats;
+}
+
+/* Initialize the runtime->hw record, private data can be allocated */
+static int soc_pcm_open(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct snd_soc_machine *machine = socdev->machine; 
+	struct snd_soc_platform *platform = socdev->platform;
+	struct snd_soc_pcm_codec *pcm_c = rtd->pcm_c;
+	struct snd_soc_pcm_interface *pcm_i = rtd->pcm_i;
+	int ret = 0;
+
+	down(&soc_pcm_sem);
+	runtime->hw.rates = get_rates(pcm_c->hw.hmodes, pcm_c->hw.num_hmodes) & 
+		get_rates(pcm_i->hw.hmodes, pcm_i->hw.num_hmodes);
+	runtime->hw.formats = get_formats(pcm_c->hw.hmodes, pcm_c->hw.num_hmodes) & 
+		get_formats(pcm_i->hw.hmodes, pcm_i->hw.num_hmodes);
+	
+	/* Check that the codec and SoC audio interface's are compatible */
+	if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		runtime->hw.rate_min = max(rtd->pcm_c->playback.rate_min, rtd->pcm_i->playback.rate_min);
+		runtime->hw.rate_max = min(rtd->pcm_c->playback.rate_max, rtd->pcm_i->playback.rate_max);
+		runtime->hw.channels_min = max(rtd->pcm_c->playback.channels_min, rtd->pcm_i->playback.channels_min);
+		runtime->hw.channels_max = min(rtd->pcm_c->playback.channels_max, rtd->pcm_i->playback.channels_max);
+	} else {
+		runtime->hw.rate_min = max(rtd->pcm_c->capture.rate_min, rtd->pcm_i->capture.rate_min);
+		runtime->hw.rate_max = min(rtd->pcm_c->capture.rate_max, rtd->pcm_i->capture.rate_max);
+		runtime->hw.channels_min = max(rtd->pcm_c->capture.channels_min, rtd->pcm_i->capture.channels_min);
+		runtime->hw.channels_max = min(rtd->pcm_c->capture.channels_max, rtd->pcm_i->capture.channels_max);
+	}
+
+	/* will the codec and interface work together ? */
+	snd_pcm_limit_hw_rates(runtime);
+	if (!runtime->hw.rates) {
+		printk(KERN_ERR "soc: %s <-> %s No matching rates\n", rtd->pcm_c->name, rtd->pcm_i->name);
+		up(&soc_pcm_sem);
+		return -ENODEV;
+	}
+	if(!runtime->hw.formats) {
+		printk(KERN_ERR "soc: %s <-> %s No matching formats\n", rtd->pcm_c->name, rtd->pcm_i->name);
+		up(&soc_pcm_sem);
+		return -ENODEV;
+	}
+	if(!runtime->hw.channels_min || !runtime->hw.channels_max) {
+		printk(KERN_ERR "soc: %s <-> %s No matching channels\n", rtd->pcm_c->name, rtd->pcm_i->name);
+		up(&soc_pcm_sem);
+		return -ENODEV;
+	}
+	printk(KERN_INFO "soc: %s <-> %s info:\n", rtd->pcm_c->name, rtd->pcm_i->name);
+	/* tmp debug */
+	printk(KERN_INFO "soc: rate mask 0x%x \nsoc: min ch %d max ch %d\nsoc: min rate %d max rate %d\n",
+		runtime->hw.rates, runtime->hw.channels_min,
+		runtime->hw.channels_max, runtime->hw.rate_min, runtime->hw.rate_max);
+
+	if(rtd->pcm_i->ops.startup) {
+		if((ret = rtd->pcm_i->ops.startup(substream)) < 0) {
+			printk(KERN_ERR "soc: can't open interface %s\n", rtd->pcm_i->name);
+			goto ops_err;
+		}
+	}
+
+	if(platform->pcm_ops->open) {
+		if((ret = platform->pcm_ops->open(substream)) < 0) {
+			printk(KERN_ERR "soc: can't open platform %s\n", platform->name);
+			goto platform_err;
+		}
+	}
+
+	if(machine->ops && machine->ops->startup) {
+		if((ret = machine->ops->startup(substream)) < 0) {
+			printk(KERN_ERR "soc: %s startup failed\n", machine->name);
+			goto machine_err;
+		}
+	}
+
+	if(rtd->pcm_c->ops.startup) {
+		if((ret = rtd->pcm_c->ops.startup(substream)) < 0) {
+			printk(KERN_ERR "soc: can't open codec %s\n", rtd->pcm_c->name);
+			goto pcm_err;
+		}
+	}
+
+	rtd->pcm_i->runtime = runtime;
+	socdev->codec->active++;
+	up(&soc_pcm_sem);
+	return ret;
+
+pcm_err:
+	if(rtd->pcm_c->ops.shutdown)
+		rtd->pcm_c->ops.shutdown(substream);
+	
+machine_err:
+	if(machine->ops && machine->ops->shutdown)
+		machine->ops->shutdown(substream);
+	
+platform_err:
+	if(platform->pcm_ops->close)
+		platform->pcm_ops->close(substream);
+
+ops_err:
+	if(rtd->pcm_i->ops.shutdown)
+		rtd->pcm_i->ops.shutdown(substream);	
+	
+	up(&soc_pcm_sem);
+	return ret;
+}
+
+/* private data can be freed here */
+static int soc_pcm_close(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_machine *machine = socdev->machine; 
+	struct snd_soc_platform *platform = socdev->platform;
+
+	down(&soc_pcm_sem);
+	if(rtd->pcm_i->ops.shutdown)
+		rtd->pcm_i->ops.shutdown(substream);
+	
+	if(rtd->pcm_c->ops.shutdown)
+		rtd->pcm_c->ops.shutdown(substream);
+	
+	if(machine->ops && machine->ops->shutdown)
+		machine->ops->shutdown(substream);
+	
+	if(platform->pcm_ops->close)
+		platform->pcm_ops->close(substream);
+	rtd->pcm_i->runtime = NULL;
+	up(&soc_pcm_sem);
+	return 0;
+}
+
+/* called when pcm is prepared, can set format, sample rate; 
+ * non atomic, can be called multiple times, can refer to runtime info*/
+static int soc_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_platform *platform = socdev->platform;
+	int ret = 0;
+
+	down(&soc_pcm_sem);
+	if(platform->pcm_ops->prepare)
+		if((ret = platform->pcm_ops->prepare(substream)) < 0)
+			goto out;
+
+	if(rtd->pcm_c->ops.prepare)
+		if((ret = rtd->pcm_c->ops.prepare(substream)) < 0)
+			goto out;
+
+	if(rtd->pcm_i->ops.prepare)
+		ret = rtd->pcm_i->ops.prepare(substream);
+
+out:
+	up(&soc_pcm_sem);
+	return ret;
+}
+
+static int soc_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_platform *platform = socdev->platform;
+	int ret = 0;
+
+	if(rtd->pcm_c->ops.trigger)
+		if((ret = rtd->pcm_c->ops.trigger(substream, cmd)) < 0)
+			return ret;
+
+	if(rtd->pcm_i->ops.trigger)
+		if((ret = rtd->pcm_i->ops.trigger(substream, cmd)) < 0)
+			return ret;
+	
+	if(platform->pcm_ops->trigger)
+		if((ret = platform->pcm_ops->trigger(substream, cmd)) < 0)
+			return ret;
+
+	return ret;
+}
+
+/* called when hw params is set by app, can be called multiple times
+ * alloc buffers (using snd_pcm_lib_* ), non-atomic, hw setup
+ */
+static int soc_pcm_hw_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_platform *platform = socdev->platform;
+	struct snd_soc_codec *codec = socdev->codec;
+	int ret = 0;
+
+	down(&soc_pcm_sem);
+	/* prepare hw non AC97 only */
+	if(rtd->pcm_i->type != SND_SOC_AC97) {
+		if((ret = soc_hw_match_params(substream, params)) < 0)
+			goto out;
+	}
+
+	if(rtd->pcm_c->ops.hw_params) {
+		if((ret = rtd->pcm_c->ops.hw_params(substream, params)) < 0) {
+			printk(KERN_ERR "soc: can't set codec %s hw params\n", rtd->pcm_c->name);
+			goto codec_err;
+		}
+	}
+
+	if(rtd->pcm_i->ops.hw_params) {
+		if((ret = rtd->pcm_i->ops.hw_params(substream, params)) < 0) {
+			printk(KERN_ERR "soc: can't set interface %s hw params\n", rtd->pcm_i->name);
+			goto interface_err;
+		}
+	}
+
+	if(platform->pcm_ops->hw_params) {
+		if((ret = platform->pcm_ops->hw_params(substream, params)) < 0) {
+			printk(KERN_ERR "soc: can't set platform %s hw params\n", platform->name);
+			goto platform_err;
+		}
+	}
+
+	if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		rtd->pcm_c->playback.active = 1;
+	else
+		rtd->pcm_c->capture.active = 1;
+	rtd->pcm_c->active = 1;
+	
+	if(codec->dapm_state != SNDRV_CTL_POWER_D0) {
+
+		if(codec->dapm_event)
+			codec->dapm_event(codec, SNDRV_CTL_POWER_D1);
+		snd_soc_dapm_codec_event(codec, SNDRV_CTL_POWER_D0);
+		if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			snd_soc_dapm_stream_event(codec, rtd->pcm_c->playback.sname, 
+				SND_SOC_DAPM_STREAM_START);
+		else
+			snd_soc_dapm_stream_event(codec, rtd->pcm_c->capture.sname, 
+				SND_SOC_DAPM_STREAM_START);
+		
+		if(codec->dapm_event)
+			codec->dapm_event(codec, SNDRV_CTL_POWER_D0);
+		snd_soc_dapm_codec_mute(codec, 0);
+		codec->dapm_state = SNDRV_CTL_POWER_D0;
+	} else {
+		if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			snd_soc_dapm_stream_event(codec, rtd->pcm_c->playback.sname, 
+				SND_SOC_DAPM_STREAM_START);
+		else
+			snd_soc_dapm_stream_event(codec, rtd->pcm_c->capture.sname, 
+				SND_SOC_DAPM_STREAM_START);
+	}
+out:
+	up(&soc_pcm_sem);
+	return ret;
+	
+platform_err:
+	if(platform->pcm_ops->hw_free)
+		platform->pcm_ops->hw_free(substream);
+	
+interface_err:
+	if(rtd->pcm_i->ops.hw_free)
+		rtd->pcm_i->ops.hw_free(substream);
+	
+codec_err:
+	if(rtd->pcm_c->ops.hw_free)
+		rtd->pcm_c->ops.hw_free(substream);
+	
+	up(&soc_pcm_sem);
+	return ret;
+}
+
+/* free buffers, can be called multiple times */
+static int soc_pcm_hw_free(snd_pcm_substream_t *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_device *socdev = rtd->socdev;
+	struct snd_soc_platform *platform = socdev->platform;
+	struct snd_soc_codec *codec = socdev->codec;
+
+	down(&soc_pcm_sem);
+	
+	if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		rtd->pcm_c->playback.active = 0;
+	else
+		rtd->pcm_c->capture.active = 0;
+		
+	if(rtd->pcm_c->ops.hw_free)
+		rtd->pcm_c->ops.hw_free(substream);
+	
+	if(rtd->pcm_i->ops.hw_free)
+		rtd->pcm_i->ops.hw_free(substream);
+	
+	if(platform->pcm_ops->hw_free)
+		platform->pcm_ops->hw_free(substream);
+
+	if(!rtd->pcm_c->active)
+		goto out;
+		
+	if(rtd->pcm_c->playback.active == 0 && rtd->pcm_c->capture.active == 0) {
+		rtd->pcm_c->active = 0;
+		codec->active--;
+	}
+
+	if(codec->active == 0) {
+		snd_soc_dapm_codec_mute(codec, 1);
+		snd_soc_dapm_codec_event(codec, SNDRV_CTL_POWER_D3hot);
+		
+		if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			snd_soc_dapm_stream_event(codec, rtd->pcm_c->playback.sname, 
+				SND_SOC_DAPM_STREAM_STOP);
+		else
+			snd_soc_dapm_stream_event(codec, rtd->pcm_c->capture.sname, 
+				SND_SOC_DAPM_STREAM_STOP);
+	
+		if(codec->dapm_event)
+			codec->dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+		codec->dapm_state = SNDRV_CTL_POWER_D3hot;
+	} else {
+		if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			snd_soc_dapm_stream_event(codec, rtd->pcm_c->playback.sname, 
+				SND_SOC_DAPM_STREAM_STOP);
+		else
+			snd_soc_dapm_stream_event(codec, rtd->pcm_c->capture.sname, 
+				SND_SOC_DAPM_STREAM_STOP);
+	}
+	
+out:
+	up(&soc_pcm_sem);
+	return 0;
+}
+
+static snd_pcm_ops_t soc_pcm_ops = {
+	.open		= soc_pcm_open,
+	.close		= soc_pcm_close,
+	.hw_params	= soc_pcm_hw_params,
+	.hw_free	= soc_pcm_hw_free,
+	.prepare	= soc_pcm_prepare,
+	.trigger	= soc_pcm_trigger,
+};
+
+#ifdef CONFIG_PM
+/* powers down audio subsystem */
+static int soc_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ 	struct snd_soc_machine *machine = socdev->machine;
+ 	struct snd_soc_platform *platform = socdev->platform;
+ 	struct snd_soc_codec_device* codec_dev = socdev->codec_dev;
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+	
+	snd_soc_dapm_codec_mute(codec, 1);
+	codec->suspend_dapm_state = codec->dapm_state;
+
+	if (machine->suspend_pre)
+		machine->suspend_pre(pdev, state);
+
+	for(i = 0; i < machine->nconfigs; i++) {
+		struct snd_soc_pcm_interface  *iface = machine->config[i].iface;
+
+		if (platform->suspend)
+			platform->suspend(pdev, iface);
+
+		if (iface->suspend && iface->type != SND_SOC_AC97)
+			iface->suspend(pdev, iface);
+	}
+
+	for(i = 0; i < codec->npcms; i++) {
+		char *stream = codec->pcms[i].playback.sname;
+		if(stream != NULL)
+			snd_soc_dapm_stream_event(codec, stream, SND_SOC_DAPM_STREAM_SUSPEND);
+		stream = codec->pcms[i].capture.sname;
+		if(stream != NULL)
+			snd_soc_dapm_stream_event(codec, stream, SND_SOC_DAPM_STREAM_SUSPEND);
+	}
+
+	if (codec_dev->suspend)
+		codec_dev->suspend(pdev, state);
+	
+	for(i = 0; i < machine->nconfigs; i++) {
+		struct snd_soc_pcm_interface  *iface = machine->config[i].iface;
+		if (iface->suspend && iface->type == SND_SOC_AC97)
+			iface->suspend(pdev, iface);
+	}
+
+	if (machine->suspend_post)
+		machine->suspend_post(pdev, state);
+
+	return 0;
+}
+
+/* powers up audio subsystem */
+static int soc_resume(struct platform_device *pdev)
+{
+ 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ 	struct snd_soc_machine *machine = socdev->machine;
+ 	struct snd_soc_platform *platform = socdev->platform;
+ 	struct snd_soc_codec_device* codec_dev = socdev->codec_dev;
+	struct snd_soc_codec* codec = socdev->codec;
+	int i;
+
+	if (machine->resume_pre)
+		machine->resume_pre(pdev);
+
+	for(i = 0; i < machine->nconfigs; i++) {
+		struct snd_soc_pcm_interface  *iface = machine->config[i].iface;
+		if (iface->resume && iface->type == SND_SOC_AC97)
+			iface->resume(pdev, iface);
+	}
+
+	snd_soc_dapm_codec_event(codec, SNDRV_CTL_POWER_D3hot);
+	if (codec_dev->resume)
+		codec_dev->resume(pdev);
+
+	for(i = 0; i < codec->npcms; i++) {
+		char* stream = codec->pcms[i].playback.sname;
+		if(stream != NULL)
+			snd_soc_dapm_stream_event(codec, stream, SND_SOC_DAPM_STREAM_RESUME);
+		stream = codec->pcms[i].capture.sname;
+		if(stream != NULL)
+			snd_soc_dapm_stream_event(codec, stream, SND_SOC_DAPM_STREAM_RESUME);	
+	}
+
+	if(codec->active) {
+		snd_soc_dapm_codec_event(codec, SNDRV_CTL_POWER_D0);
+		snd_soc_dapm_codec_mute(codec, 0);
+	}
+
+	for(i = 0; i < machine->nconfigs; i++) {
+		struct snd_soc_pcm_interface  *iface = machine->config[i].iface;
+		if (iface->resume && iface->type != SND_SOC_AC97)
+			iface->resume(pdev, iface);
+		if (platform->resume)
+			platform->resume(pdev, iface);
+	}
+
+	if (machine->resume_post)
+		machine->resume_post(pdev);
+
+	return 0;
+}
+
+#else
+#define soc_suspend	NULL
+#define soc_resume	NULL
+#endif
+
+/* probes a new socdev */
+static int soc_probe(struct platform_device *pdev)
+{
+	int ret = 0, i;
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_machine *machine = socdev->machine;
+	struct snd_soc_platform *platform = socdev->platform;
+	struct snd_soc_codec_device* codec_dev = socdev->codec_dev;
+
+	if (machine->probe && ((ret = machine->probe(pdev)) < 0))
+		return ret;
+	
+	for (i = 0; i < machine->nconfigs; i++) {
+		struct snd_soc_pcm_interface  *iface = machine->config[i].iface;
+		if (iface->probe && ((ret = iface->probe(pdev)) < 0))
+			goto iface_err;
+	}
+
+	if (codec_dev->probe && ((ret = codec_dev->probe(pdev)) < 0))
+		goto codec_err;
+
+	if (platform->probe && ((ret = platform->probe(pdev)) < 0))
+		goto platform_err;
+
+	return 0;
+	
+platform_err:
+	if (platform->remove)
+		platform->remove(pdev);
+		
+codec_err:
+	if (codec_dev->remove)
+		codec_dev->remove(pdev);
+
+iface_err:
+	for (i--; i > 0; i--) {
+		struct snd_soc_pcm_interface  *iface = machine->config[i].iface;
+		if (iface->remove) 
+			iface->remove(pdev);
+	}
+	
+	if (machine->remove)
+		machine->remove(pdev);
+
+	return ret;
+}
+
+/* removes a socdev */
+static int soc_remove(struct platform_device *pdev)
+{
+	int i;
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_machine *machine = socdev->machine;
+	struct snd_soc_platform *platform = socdev->platform;
+	struct snd_soc_codec_device* codec_dev = socdev->codec_dev;
+
+	if (platform->remove)
+		platform->remove(pdev);
+
+	if (codec_dev->remove)
+		codec_dev->remove(pdev);
+		
+	for (i = 0; i < machine->nconfigs; i++) {
+		struct snd_soc_pcm_interface  *iface = machine->config[i].iface;
+		if (iface->remove)
+			iface->remove(pdev);
+	}
+
+	if (machine->remove)
+		machine->remove(pdev);
+	
+	return 0;
+}
+
+static struct platform_driver soc_driver = {
+	.driver		= {
+		.name		= "soc-audio",
+	},
+	.probe		= soc_probe,
+	.remove		= soc_remove,
+	.suspend	= soc_suspend,
+	.resume		= soc_resume,
+};
+
+/* create a new pcm */
+static int soc_new_pcm(struct snd_soc_device *socdev, 
+	struct snd_soc_pcm_codec *pcm_c, struct snd_soc_pcm_interface *iface, 
+	int num)
+{
+	struct snd_soc_codec *codec = socdev->codec;
+	struct snd_soc_pcm_runtime *rtd;
+	snd_pcm_t *pcm;
+	char new_name[32];
+	int ret = 0;
+
+	if((rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	rtd->pcm_i = iface;
+	rtd->socdev = socdev;
+	rtd->pcm_c = pcm_c;
+
+	/* check client and interface hw capabilities */
+	sprintf(new_name, "%s-%s-%d", pcm_c->name, iface_name(iface->type), num);
+
+	if((ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, pcm_c->nplayback, pcm_c->ncapture, &pcm)) < 0) {
+		printk(KERN_ERR "soc: can't create pcm for codec %s\n", codec->name);
+		return ret;
+	}
+
+	iface->socdev = socdev;
+	pcm->private_data = rtd;
+
+	soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
+	soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
+	soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
+
+	if (pcm_c->nplayback)
+		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
+
+	if (pcm_c->ncapture)
+		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
+
+	if((ret = socdev->platform->pcm_new(codec->card, pcm_c, pcm)) < 0) {
+		printk(KERN_ERR "soc: platform pcm constructor failed\n");
+		return ret;
+	}
+
+	pcm->private_free = socdev->platform->pcm_free;
+	printk(KERN_INFO "soc: %s <-> %s mapping ok\n", pcm_c->name, iface->name);
+	return ret;
+}
+
+/* finds and creates pcms */
+static int soc_find_pcms(struct snd_soc_device *socdev)
+{
+	struct snd_soc_codec *codec = socdev->codec;
+	struct snd_soc_machine *machine = socdev->machine;
+	int n = 0, i, j;
+
+	for(i = 0; i < machine->nconfigs; i++) {
+		for(j = 0; j < codec->npcms; j++) {
+			if(!strcmp(codec->pcms[j].name, machine->config[i].sname)) {
+				soc_new_pcm(socdev, &codec->pcms[j], machine->config[i].iface, n);
+				n++;
+			}
+		}			
+	}
+	
+	return n;
+}
+
+/**
+ * snd_soc_new_ac97_codec - initailise AC97 device
+ * @codec: audio codec
+ * @ops: AC97 bus operations
+ * @num: AC97 codec number
+ *
+ * Initialises AC97 codec resources for use by ad-hoc devices only.
+ */
+int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, 
+	struct snd_ac97_bus_ops *ops, int num)
+{
+	if((codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+	
+	if((codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL)) == NULL) {
+		kfree(codec->ac97);
+		codec->ac97 = NULL;
+		return -ENOMEM;
+	}
+	
+	codec->ac97->bus->ops = ops;
+	codec->ac97->num = num;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
+
+/**
+ * snd_soc_free_ac97_codec - free AC97 codec device
+ * @codec: audio codec
+ *
+ * Frees AC97 codec device resources.
+ */
+void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
+{
+	kfree(codec->ac97->bus);
+	kfree(codec->ac97);
+	codec->ac97 = NULL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
+
+/**
+ * snd_soc_update_bits - update codec register bits
+ * @codec: audio codec
+ * @reg: codec register
+ * @mask: register mask
+ * @value: new value
+ *
+ * Writes new register value.
+ *
+ * Returns 1 for change else 0.
+ */
+int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
+				unsigned short mask, unsigned short value)
+{
+	int change;
+	unsigned short old, new;
+
+	old = snd_soc_read(codec, reg);
+	new = (old & ~mask) | value;
+	change = old != new;
+	if (change)
+		snd_soc_write(codec, reg, new);
+
+	return change;
+}
+EXPORT_SYMBOL_GPL(snd_soc_update_bits);
+
+/**
+ * snd_soc_test_bits - test register for change
+ * @codec: audio codec
+ * @reg: codec register
+ * @mask: register mask
+ * @value: new value
+ *
+ * Tests a register with a new value and checks if the new value is
+ * different from the old value.
+ *
+ * Returns 1 for change else 0.
+ */
+int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
+				unsigned short mask, unsigned short value)
+{
+	int change;
+	unsigned short old, new;
+
+	old = snd_soc_read(codec, reg);
+	new = (old & ~mask) | value;
+	change = old != new;
+
+	return change;
+}
+EXPORT_SYMBOL_GPL(snd_soc_test_bits);
+
+/**
+ * snd_soc_get_rate - get int sample rate
+ * @hwpcmrate: the hardware pcm rate
+ *
+ * Returns the audio rate integaer value, else 0.
+ */
+int snd_soc_get_rate(int hwpcmrate)
+{	
+	int rate = generic_ffs(hwpcmrate) - 1;
+	
+	if (rate > ARRAY_SIZE(rates))
+		return 0;
+	return rates[rate];
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_rate);
+
+/**
+ * snd_soc_new_pcms - create new sound card and pcms
+ * @socdev: the SoC audio device
+ *
+ * Create a new sound card based upon the codec and interface pcms.
+ *
+ * Returns 0 for success, else error.
+ */
+int snd_soc_new_pcms(struct snd_soc_device *socdev)
+{
+	struct snd_soc_codec *codec = socdev->codec;
+	int ret = 0;
+
+	/* register a sound card */
+	codec->card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, codec->owner, 0);
+	if (!codec->card) {
+		printk(KERN_ERR "soc: can't create sound card for codec %s\n", codec->name);
+		return -ENODEV;
+	}
+
+	codec->card->dev = socdev->dev;
+	codec->card->private_data = codec;
+	strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
+
+	if(soc_find_pcms(socdev) == 0){
+		printk(KERN_ERR "soc: couldn't find any pcms for %s\n", codec->name);
+		return -ENODEV;
+	}
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
+
+/**
+ * snd_soc_register_card - register sound card
+ * @socdev: the SoC audio device
+ *
+ * Register a SoC sound card. Also registers an AC97 device if the 
+ * codec is AC97 for ad hoc devices.
+ *
+ * Returns 0 for success, else error.
+ */
+int snd_soc_register_card(struct snd_soc_device *socdev)
+{
+	struct snd_soc_codec *codec = socdev->codec;
+	struct snd_soc_machine *machine = socdev->machine;
+	int ret = 0, i, ac97 = 0;
+	
+	for(i = 0; i < codec->npcms; i++) {
+		if(socdev->machine->config[i].init)
+			socdev->machine->config[i].init(codec);
+		if(socdev->machine->config[i].iface->type == SND_SOC_AC97)
+			ac97 = 1;
+	}
+	snprintf(codec->card->shortname, sizeof(codec->card->shortname),
+		 "%s", machine->name);
+	snprintf(codec->card->longname, sizeof(codec->card->longname),
+		 "%s (%s)", machine->name, codec->name);
+	
+	if((ret = snd_card_register(codec->card)) < 0) {
+		printk(KERN_ERR "soc: failed to register soundcard for codec %s\n", 
+				codec->name);
+		return ret;
+	}
+	
+	if(ac97)
+		soc_ac97_dev_register(codec);
+	
+	snd_soc_dapm_sys_add(socdev->dev);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_register_card);
+
+/**
+ * snd_soc_free_pcms - free sound card and pcms
+ * @socdev: the SoC audio device
+ *
+ * Frees sound card and pcms associated with the socdev.
+ * Also unregister the codec if it is an AC97 device.
+ */
+void snd_soc_free_pcms(struct snd_soc_device *socdev)
+{
+	struct snd_soc_codec *codec = socdev->codec;
+
+	if(codec->ac97)
+		soc_ac97_dev_unregister(codec);
+	if(codec->card)
+		snd_card_free(codec->card);
+}
+EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
+
+/**
+ * snd_soc_set_runtime_hw - set the runtime hardware parameters
+ * @substream: the pcm substream
+ * @hw: the hardware parameters
+ *
+ * Sets the substream runtime hardware parameters.
+ */
+int snd_soc_set_runtime_hw(snd_pcm_substream_t *substream, 
+	const snd_pcm_hardware_t *hw)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	runtime->hw.info = hw->info;
+	runtime->hw.formats = hw->formats;
+	runtime->hw.period_bytes_min = hw->period_bytes_min;
+	runtime->hw.period_bytes_max = hw->period_bytes_max;
+	runtime->hw.periods_min = hw->periods_min;
+	runtime->hw.periods_max = hw->periods_max;
+	runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
+	runtime->hw.fifo_size = hw->fifo_size;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hw);
+
+/**
+ * snd_soc_cnew - create new control
+ * @_template: control template
+ * @data: control private data
+ * @lnng_name: control long name
+ *
+ * Create a new mixer control from a template control.
+ *
+ * Returns 0 for success, else error.
+ */
+snd_kcontrol_t *snd_soc_cnew(const snd_kcontrol_new_t *_template, 
+	void *data, char *long_name)
+{
+	snd_kcontrol_new_t template;
+	
+	memcpy(&template, _template, sizeof(template));
+	if(long_name)
+		template.name = long_name;
+	template.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
+	template.index = 0;
+	
+	return snd_ctl_new1(&template, data);
+}
+EXPORT_SYMBOL_GPL(snd_soc_cnew);
+
+/**
+ * snd_soc_info_enum_double - enumerated double mixer info callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to provide information about a double enumerated 
+ * mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_info_enum_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
+	uinfo->value.enumerated.items = e->mask;
+	
+	if (uinfo->value.enumerated.item > e->mask - 1)
+		uinfo->value.enumerated.item = e->mask - 1;
+	strcpy(uinfo->value.enumerated.name, e->texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
+
+/**
+ * snd_soc_get_enum_double - enumerated double mixer get callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to get the value of a double enumerated mixer. 
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_get_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	unsigned short val, bitmask;
+	
+	for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
+		;
+	val = snd_soc_read(codec, e->reg);
+	ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
+	if (e->shift_l != e->shift_r)
+		ucontrol->value.enumerated.item[1] = (val >> e->shift_r) & (bitmask - 1);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
+
+/**
+ * snd_soc_put_enum_double - enumerated double mixer put callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to set the value of a double enumerated mixer. 
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_put_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	unsigned short val;
+	unsigned short mask, bitmask;
+	
+	for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
+		;
+	if (ucontrol->value.enumerated.item[0] > e->mask - 1)
+		return -EINVAL;
+	val = ucontrol->value.enumerated.item[0] << e->shift_l;
+	mask = (bitmask - 1) << e->shift_l;
+	if (e->shift_l != e->shift_r) {
+		if (ucontrol->value.enumerated.item[1] > e->mask - 1)
+			return -EINVAL;
+		val |= ucontrol->value.enumerated.item[1] << e->shift_r;
+		mask |= (bitmask - 1) << e->shift_r;
+	}
+	
+	return snd_soc_update_bits(codec, e->reg, mask, val);
+}
+EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
+
+/**
+ * snd_soc_info_enum_ext - external enumerated single mixer info callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to provide information about an external enumerated
+ * single mixer.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_info_enum_ext(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = e->mask;
+	
+	if (uinfo->value.enumerated.item > e->mask - 1)
+		uinfo->value.enumerated.item = e->mask - 1;
+	strcpy(uinfo->value.enumerated.name, e->texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
+
+/**
+ * snd_soc_info_volsw_ext - external single mixer info callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to provide information about a single external mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_info_volsw_ext(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	int mask = kcontrol->private_value;
+
+	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+	uinfo->count = 1;
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = mask;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
+
+/**
+ * snd_soc_info_bool_ext - external single boolean mixer info callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to provide information about a single boolean external mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_info_bool_ext(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+	uinfo->count = 1;
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = 1;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_info_bool_ext);
+
+/**
+ * snd_soc_info_volsw - single mixer info callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to provide information about a single mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_info_volsw(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	int mask = (kcontrol->private_value >> 16) & 0xff;
+	int shift = (kcontrol->private_value >> 8) & 0x0f;
+	int rshift = (kcontrol->private_value >> 12) & 0x0f;
+
+	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+	uinfo->count = shift == rshift ? 1 : 2;
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = mask;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
+
+/**
+ * snd_soc_get_volsw - single mixer get callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to get the value of a single mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_get_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	int reg = kcontrol->private_value & 0xff;
+	int shift = (kcontrol->private_value >> 8) & 0x0f;
+	int rshift = (kcontrol->private_value >> 12) & 0x0f;
+	int mask = (kcontrol->private_value >> 16) & 0xff;
+	int invert = (kcontrol->private_value >> 24) & 0x01;
+
+	ucontrol->value.integer.value[0] = (snd_soc_read(codec, reg) >> shift) & mask;
+	if (shift != rshift)
+		ucontrol->value.integer.value[1] = (snd_soc_read(codec, reg) >> rshift) & mask;
+	if (invert) {
+		ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+		if (shift != rshift)
+			ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
+
+/**
+ * snd_soc_put_volsw - single mixer put callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to set the value of a single mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_put_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	int reg = kcontrol->private_value & 0xff;
+	int shift = (kcontrol->private_value >> 8) & 0x0f;
+	int rshift = (kcontrol->private_value >> 12) & 0x0f;
+	int mask = (kcontrol->private_value >> 16) & 0xff;
+	int invert = (kcontrol->private_value >> 24) & 0x01;
+	int err;
+	unsigned short val, val2, val_mask;
+	
+	val = (ucontrol->value.integer.value[0] & mask);
+	if (invert)
+		val = mask - val;
+	val_mask = mask << shift;
+	val = val << shift;
+	if (shift != rshift) {
+		val2 = (ucontrol->value.integer.value[1] & mask);
+		if (invert)
+			val2 = mask - val2;
+		val_mask |= mask << rshift;
+		val |= val2 << rshift;
+	}
+	err = snd_soc_update_bits(codec, reg, val_mask, val);
+	return err;
+}
+EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
+
+/**
+ * snd_soc_info_volsw_2r - double mixer info callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to provide information about a double mixer control that
+ * spans 2 codec registers.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_info_volsw_2r(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	int mask = (kcontrol->private_value >> 12) & 0xff;
+
+	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+	uinfo->count = 2;
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = mask;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
+
+/**
+ * snd_soc_get_volsw_2r - double mixer get callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to get the value of a double mixer control that spans 2 registers.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_get_volsw_2r(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	int reg = kcontrol->private_value & 0xff;
+	int reg2 = (kcontrol->private_value >> 24) & 0xff;
+	int shift = (kcontrol->private_value >> 8) & 0x0f;
+	int mask = (kcontrol->private_value >> 12) & 0xff;
+	int invert = (kcontrol->private_value >> 20) & 0x01;
+
+	ucontrol->value.integer.value[0] = (snd_soc_read(codec, reg) >> shift) & mask;
+	ucontrol->value.integer.value[1] = (snd_soc_read(codec, reg2) >> shift) & mask;
+	if (invert) {
+		ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+		ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
+
+/**
+ * snd_soc_put_volsw_2r - double mixer set callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to set the value of a double mixer control that spans 2 registers.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_put_volsw_2r(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	int reg = kcontrol->private_value & 0xff;
+	int reg2 = (kcontrol->private_value >> 24) & 0xff;
+	int shift = (kcontrol->private_value >> 8) & 0x0f;
+	int mask = (kcontrol->private_value >> 12) & 0xff;
+	int invert = (kcontrol->private_value >> 20) & 0x01;
+	int err;
+	unsigned short val, val2, val_mask;
+	
+	val_mask = mask << shift;
+	val = (ucontrol->value.integer.value[0] & mask);
+	val2 = (ucontrol->value.integer.value[1] & mask);
+	
+	if (invert) {
+		val = mask - val;
+		val2 = mask - val2;
+	}
+	
+	val = val << shift;
+	val2 = val2 << shift;
+	
+	if((err = snd_soc_update_bits(codec, reg, val_mask, val)) < 0)
+		return err;
+	
+	err = snd_soc_update_bits(codec, reg2, val_mask, val2);
+	return err;
+}
+EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
+
+static int __devinit snd_soc_init(void)
+{
+	printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
+	return platform_driver_register(&soc_driver);
+}
+
+static void snd_soc_exit(void)
+{
+ 	platform_driver_unregister(&soc_driver);
+}
+
+module_init(snd_soc_init);
+module_exit(snd_soc_exit);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("ALSA SoC Core");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
new file mode 100644
index 0000000..0fad572
--- /dev/null
+++ b/sound/soc/soc-dapm.c
@@ -0,0 +1,1293 @@
+/*
+ * soc-dapm.c  --  ALSA SoC Dynamic Audio Power Management
+ *
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ *  Revision history
+ *    12th Aug 2005   Initial version.
+ *    25th Oct 2005   Implemented path power domain.
+ *    18th Dec 2005   Implemented machine and stream level power domain.
+ *
+ *  Features:
+ *    o Changes power status of internal codec blocks depending on the 
+ *      dynamic configuration of codec internal audio paths and active
+ *      DAC's/ADC's.
+ *    o Platform power domain - can support external components i.e. amps and
+ *      mic/meadphone insertion events.
+ *    o Automatic Mic Bias support
+ *    o Jack insertion power event initiation - e.g. hp insertion will enable
+ *      outputs, dacs, etc
+ * 
+ *  Todo:
+ *    o DPM power change sequencing - allow for configurable per codec sequences
+ *    o Support for analogue bias optimisation.
+ *    o Support for reduced codec oversampling rates.
+ *    o Support for reduced codec bias currents.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/bitops.h>
+#include <linux/platform_device.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+/* debug */
+#define DAPM_DEBUG 0
+#if DAPM_DEBUG
+#define dump_dapm(codec, action) dbg_dump_dapm(codec, action)
+#define dbg(format, arg...) printk(format, ## arg)
+#else
+#define dump_dapm(codec, action)
+#define dbg(format, arg...)
+#endif
+
+static int dapm_up_seq[] = {
+	snd_soc_dapm_micbias, snd_soc_dapm_adc, snd_soc_dapm_mux,
+	snd_soc_dapm_dac, snd_soc_dapm_mixer, snd_soc_dapm_volume, snd_soc_dapm_mute
+};
+static int dapm_down_seq[] = {
+	snd_soc_dapm_volume, snd_soc_dapm_mixer, snd_soc_dapm_dac, snd_soc_dapm_mute,
+	snd_soc_dapm_adc, snd_soc_dapm_micbias, snd_soc_dapm_mux
+};
+
+
+static int dapm_status = 1;
+module_param(dapm_status, int, 0);
+MODULE_PARM_DESC(dapm_status, "enable DPM sysfs entries");
+
+/* create a new dapm widget */
+static struct snd_soc_dapm_widget *dapm_cnew_widget(
+	const struct snd_soc_dapm_widget *_widget)
+{
+	struct snd_soc_dapm_widget* widget;
+	widget = kmalloc(sizeof(struct snd_soc_dapm_widget), GFP_KERNEL);
+	if (!widget)
+		return NULL;
+	
+	memcpy(widget, _widget, sizeof(struct snd_soc_dapm_widget));
+	return widget;
+}
+
+/* set up initial codec paths */  
+static void dapm_set_path_status(struct snd_soc_dapm_widget *w, 
+	struct snd_soc_dapm_path *p, int i)
+{	
+	switch (w->id) {
+	case snd_soc_dapm_switch:
+	case snd_soc_dapm_mixer: {
+		int val;
+		int reg = w->kcontrols[i].private_value & 0xff;
+		int shift = (w->kcontrols[i].private_value >> 8) & 0x0f;
+		int mask = (w->kcontrols[i].private_value >> 16) & 0xff;
+		int invert = (w->kcontrols[i].private_value >> 24) & 0x01;
+		
+		val = snd_soc_read(w->codec, reg);
+		val = (val >> shift) & mask;
+	
+		if((invert && !val) || (!invert && val))
+			p->connect = 1;
+		else
+			p->connect = 0;
+	}
+	break;
+	case snd_soc_dapm_mux: {
+		struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
+		int val, item, bitmask;
+		
+		for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
+		;
+		val = snd_soc_read(w->codec, e->reg);
+		item = (val >> e->shift_l) & (bitmask - 1);
+		
+		p->connect = 0;
+		for (i = 0; i < e->mask; i++) {
+			if (!(strcmp(p->name, e->texts[i])) && item == i)
+				p->connect = 1;
+		}
+	}
+	break;
+	/* does not effect routing - always connected */
+	case snd_soc_dapm_volume:
+	case snd_soc_dapm_output:
+	case snd_soc_dapm_adc:
+	case snd_soc_dapm_input:
+	case snd_soc_dapm_dac:
+	case snd_soc_dapm_clock:
+	case snd_soc_dapm_vref:	
+	case snd_soc_dapm_micbias:
+		p->connect = 1;
+	case snd_soc_dapm_mute:
+	/* does effect routing - dynamically connected */
+	case snd_soc_dapm_hp:
+	case snd_soc_dapm_mic:
+	case snd_soc_dapm_spk:
+	case snd_soc_dapm_line:
+		p->connect = 0;
+	break;
+	}
+}	
+
+/* connect mux widget to it's interconnecting audio paths */
+static int dapm_connect_mux(struct snd_soc_codec *codec, 
+	struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, 
+	struct snd_soc_dapm_path *path, const char *control_name, 
+	const snd_kcontrol_new_t *kcontrol)
+{
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	int i;
+	
+	for (i = 0; i < e->mask; i++) {
+		if (!(strcmp(control_name, e->texts[i]))) {
+			list_add(&path->list, &codec->dapm_paths);
+			list_add(&path->list_out, &dest->inputs);
+			list_add(&path->list_in, &src->outputs);
+			path->name = (char*)e->texts[i];
+			dapm_set_path_status(dest, path, 0);
+			return 0;
+		}
+	}
+
+	return -ENODEV;
+}
+
+/* connect mixer widget to it's interconnecting audio paths */
+static int dapm_connect_mixer(struct snd_soc_codec *codec, 
+	struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, 
+	struct snd_soc_dapm_path *path, const char *control_name)
+{
+	int i;
+	
+	/* search for mixer kcontrol */
+	for (i = 0; i < dest->num_kcontrols; i++) {		
+		if(!strcmp(control_name, dest->kcontrols[i].name)) {
+			list_add(&path->list, &codec->dapm_paths);
+			list_add(&path->list_out, &dest->inputs);
+			list_add(&path->list_in, &src->outputs);
+			path->name = dest->kcontrols[i].name;
+			dapm_set_path_status(dest, path, i);
+			return 0;
+		}			
+	}
+	return -ENODEV;
+}
+
+/* update dapm codec register bits */
+static int dapm_update_bits(struct snd_soc_dapm_widget *widget, int power)
+{
+	int change;
+	unsigned short old, new;
+	struct snd_soc_codec *codec = widget->codec;
+	
+	if(widget->reg < 0 || widget->id == snd_soc_dapm_input ||
+		widget->id == snd_soc_dapm_output ||
+		widget->id == snd_soc_dapm_hp ||
+		widget->id == snd_soc_dapm_mic ||
+		widget->id == snd_soc_dapm_line ||
+		widget->id == snd_soc_dapm_spk)
+		return 0;
+	
+	widget->power = power;
+	if(widget->invert)
+		power = (power ? 0:1);
+	
+	old = snd_soc_read(codec, widget->reg);
+	new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
+	
+	change = old != new;
+	if (change)
+		snd_soc_write(codec, widget->reg, new);
+
+	return change;
+}
+
+/* ramps the volume up or down to minimise pops before or after a power event */
+static int dapm_set_volume(struct snd_soc_dapm_widget *widget, int power)
+{
+	const snd_kcontrol_new_t *k = widget->kcontrols;
+	
+	if(widget->muted && !power)
+		return 0;
+	if(!widget->muted && power)
+		return 0;
+	
+	if(widget->num_kcontrols && k) {
+		int reg = k->private_value & 0xff;
+		int shift = (k->private_value >> 8) & 0x0f;
+		int mask = (k->private_value >> 16) & 0xff;
+		int invert = (k->private_value >> 24) & 0x01;
+		
+		if (power) {
+			int i;
+			/* power up has happended, increase volume to last level */
+			if(invert) {
+				for (i = mask; i > widget->value; i--)
+					snd_soc_update_bits(widget->codec, reg, mask, i);
+			} else {
+				for (i = 0; i < widget->value; i++)
+					snd_soc_update_bits(widget->codec, reg, mask, i);
+			}
+			widget->muted = 0;
+		} else {
+			/* power down is about to occur, decrease volume to mute */
+			int val = snd_soc_read(widget->codec, reg);
+			int i = widget->value = (val >> shift) & mask;
+			if(invert) {
+				for (; i < mask; i++)
+					snd_soc_update_bits(widget->codec, reg, mask, i);
+			} else {
+				for (; i > 0; i--)
+					snd_soc_update_bits(widget->codec, reg, mask, i);
+			}
+			widget->muted = 1;
+		}
+	}
+	return 0;
+}
+
+/* create new dapm mixer control */
+static int dapm_new_mixer(struct snd_soc_codec *codec, 
+	struct snd_soc_dapm_widget *w)
+{
+	int i, ret = 0;
+	char name[32];
+	struct list_head *lp;
+	struct snd_soc_dapm_path *path;
+	
+	/* add kcontrol */
+	for (i = 0; i < w->num_kcontrols; i++) {
+			
+		/* match name */
+		list_for_each(lp, &w->inputs)
+		{
+			path = list_entry(lp, struct snd_soc_dapm_path, list_out);
+			
+			/* mixer/mux paths name must match control name */
+			if (path->name != (char*)w->kcontrols[i].name) 
+				continue;
+				
+			/* add dapm control with long name */
+			snprintf(name, 32, "%s %s", w->name, w->kcontrols[i].name);
+			path->long_name = kstrdup (name, GFP_KERNEL);
+			if(path->long_name == NULL)
+				return -ENOMEM;
+			
+			path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w, path->long_name);
+			if ((ret = snd_ctl_add(codec->card, path->kcontrol)) < 0) {
+				printk(KERN_ERR "soc: failed to add dapm kcontrol %s\n", 
+						path->long_name);
+				kfree(path->long_name);
+				path->long_name = NULL;
+				return ret;
+			}
+		}
+	}
+	return ret;
+}
+
+/* create new dapm mux control */
+static int dapm_new_mux(struct snd_soc_codec *codec, struct snd_soc_dapm_widget *w)
+{
+	struct list_head *lp;
+	struct snd_soc_dapm_path *path = NULL;
+	snd_kcontrol_t *kcontrol;
+	int ret = 0;
+	
+	if(!w->num_kcontrols) {
+		printk(KERN_ERR "soc: mux %s has no controls\n", w->name);
+		return -EINVAL;
+	}
+	
+	kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
+	if ((ret = snd_ctl_add(codec->card, kcontrol)) < 0) {
+		printk(KERN_ERR "soc: failed to add kcontrol %s\n", w->name);
+		return ret;
+	}
+
+	list_for_each(lp, &w->inputs)
+	{
+		path = list_entry(lp, struct snd_soc_dapm_path, list_out);
+		path->kcontrol = kcontrol;
+	}
+	
+	return ret;
+}
+
+/* create new dapm volume control */
+static int dapm_new_volume(struct snd_soc_codec *codec, 
+	struct snd_soc_dapm_widget *w)
+{
+	snd_kcontrol_t *kcontrol;
+	int ret = 0;
+	
+	if(!w->num_kcontrols)
+		return -EINVAL;
+	
+	kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
+	if ((ret = snd_ctl_add(codec->card, kcontrol)) < 0) {
+		printk(KERN_ERR "soc: failed to add kcontrol %s\n", w->name);
+		return ret;
+	}
+	
+	return ret;
+}
+
+/* reset 'walked' bit for each dapm path */
+static void dapm_clear_walk(struct snd_soc_codec *codec)
+{
+	struct snd_soc_dapm_path *p = NULL;
+	struct list_head *l = NULL;
+		
+	list_for_each(l, &codec->dapm_paths)
+	{
+		p = list_entry(l, struct snd_soc_dapm_path, list);
+		p->walked = 0;		
+	}
+}
+
+/*
+ * Recursively check for a completed path to an active or physically connected
+ * output widget. Returns number of complete paths.
+ */
+static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
+{
+	struct list_head *lp;
+	struct snd_soc_dapm_path *path = NULL;
+	int con = 0;
+
+	if(widget->id == snd_soc_dapm_adc && widget->active)
+		return 1;
+	
+	if(widget->connected) {
+		/* connected pin ? */
+		if(widget->id == snd_soc_dapm_output && !widget->ext)
+			return 1;
+		
+		/* connected jack or spk ? */	
+		if(widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
+			widget->id == snd_soc_dapm_line)
+			return 1;
+	}
+	
+	list_for_each(lp, &widget->outputs)
+	{
+		path = list_entry(lp, struct snd_soc_dapm_path, list_in);
+		if(path->walked)
+			continue;
+	
+		if (path->out && path->connect) {
+			path->walked = 1;
+			con += is_connected_output_ep(path->out);
+		}
+	}
+	
+	return con;
+}
+
+/*
+ * Recursively check for a completed path to an active or physically connected
+ * input widget. Returns number of complete paths.
+ */
+static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
+{
+	struct list_head *lp;
+	struct snd_soc_dapm_path *path = NULL;
+	int con = 0;
+	
+	/* active stream ? */
+	if(widget->id == snd_soc_dapm_dac && widget->active)
+		return 1;
+		
+	if(widget->connected) {
+		/* connected pin ? */
+		if(widget->id == snd_soc_dapm_input && !widget->ext)
+			return 1;
+	
+		/* connected jack ? */		
+		if(widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line)
+			return 1;
+	}
+	
+	list_for_each(lp, &widget->inputs)
+	{
+		path = list_entry(lp, struct snd_soc_dapm_path, list_out);
+		if(path->walked)
+			continue;
+	
+		if (path->in && path->connect) {
+			path->walked = 1;
+			con += is_connected_input_ep(path->in);
+		}
+	}
+	
+	return con;
+}
+
+/*
+ * Scan each dapm widget for complete audio path. 
+ * A complete path is a route that has valid endpoints i.e.:-
+ * 
+ *  o DAC to output pin.
+ *  o Input Pin to ADC.
+ *  o Input pin to Output pin (bypass, sidetone)
+ *  o DAC to ADC.
+ */ 
+int dapm_power_widgets(struct snd_soc_codec *codec, int event)
+{
+	struct snd_soc_dapm_widget *w;
+	struct list_head *l;
+	int in, out, pm = 0, i, c = 1, *seq = NULL;
+
+	if(event == SND_SOC_DAPM_STREAM_START) {
+		c = ARRAY_SIZE(dapm_up_seq);
+		seq = dapm_up_seq;
+	} else if (event == SND_SOC_DAPM_STREAM_STOP) {
+		c = ARRAY_SIZE(dapm_down_seq);
+		seq = dapm_down_seq;
+	}
+	
+	for(i = 0; i < c; i++){
+		list_for_each(l, &codec->dapm_widgets)
+		{
+			w = list_entry(l, struct snd_soc_dapm_widget, list);
+			
+			if(seq && seq[i] && w->id != seq[i])
+				continue;
+			
+			if(w->id == snd_soc_dapm_vref || w->id == snd_soc_dapm_clock ||
+				w->id == snd_soc_dapm_mute)
+				continue;
+			
+			if(w->id == snd_soc_dapm_adc && w->active) {
+				in = is_connected_input_ep(w);
+				dapm_clear_walk(w->codec);
+				pm = (in != 0) ? 1 : 0;
+				dapm_update_bits(w, pm);
+				continue;
+			}
+			
+			if(w->id == snd_soc_dapm_dac && w->active) {
+				out = is_connected_output_ep(w);
+				dapm_clear_walk(w->codec);
+				pm = (out != 0) ? 1 : 0;
+				dapm_update_bits(w, pm);
+				continue;
+			}
+			
+			if(w->id == snd_soc_dapm_volume) {
+				int on;
+				in = is_connected_input_ep(w);
+				dapm_clear_walk(w->codec);
+				out = is_connected_output_ep(w);
+				dapm_clear_walk(w->codec);
+				pm = on = (out != 0 && in != 0) ? 1 : 0;
+				
+				if(!on)
+					dapm_set_volume(w, on); /* lower volume to reduce pops */
+				dapm_update_bits(w, pm);
+				if(on) 
+					dapm_set_volume(w, on); /* restore volume from zero */
+				
+				continue;
+			}
+			in = is_connected_input_ep(w);
+			dapm_clear_walk(w->codec);
+			out = is_connected_output_ep(w);
+			dapm_clear_walk(w->codec);
+			pm = (out != 0 && in != 0) ? 1 : 0;
+			
+			dapm_update_bits(w, pm);
+			if(w->ext_event)
+				w->ext_event(w, pm);
+		}
+	}
+	
+	return 0;
+}
+
+#if DAPM_DEBUG
+static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
+{
+	struct snd_soc_dapm_widget *w = NULL;
+	struct snd_soc_dapm_path *p = NULL;
+	struct list_head *l = NULL, *lp = NULL;
+	int in, out;
+	
+	printk("DAPM %s %s\n", codec->name, action);
+	
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w = list_entry(l, struct snd_soc_dapm_widget, list);
+		if (w->name && w->reg > 0 && 
+			w->id != snd_soc_dapm_input && w->id != snd_soc_dapm_output) {
+				in = is_connected_input_ep(w);
+				dapm_clear_walk(w->codec);
+				out = is_connected_output_ep(w);
+				dapm_clear_walk(w->codec);
+				printk("%s: %s  in %d out %d\n", w->name, 
+					w->power ? "On":"Off",in, out);
+				
+				list_for_each(lp, &w->inputs)
+				{
+					p = list_entry(lp, struct snd_soc_dapm_path, list_out);
+					if (p->connect)
+						printk(" in  %s %s\n", p->name ? p->name : "static", 
+							p->in->name);
+				}
+				list_for_each(lp, &w->outputs)
+				{
+					p = list_entry(lp, struct snd_soc_dapm_path, list_in);
+					if (p->connect)
+						printk(" out %s %s\n", p->name ? p->name : "static", 
+							p->out->name);
+				}
+				
+		}
+	}
+}
+#endif
+
+/* test and update the power status of a mux widget */
+static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget, 
+	snd_kcontrol_t *kcontrol, int mask, int val, struct soc_enum* e)
+{
+	struct list_head *l;
+	struct snd_soc_dapm_path *path;
+	
+	if(widget->id != snd_soc_dapm_mux)
+		return -ENODEV; 
+
+	if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
+		return 0;
+	
+	/* find dapm widget path assoc with kcontrol */
+	list_for_each(l, &widget->codec->dapm_paths)
+	{
+		path = list_entry(l, struct snd_soc_dapm_path, list);
+		if (path->kcontrol != kcontrol)
+			continue;
+
+		if(!path->name || ! e->texts[val])
+			continue;
+
+		/* we now need to match the string in the enum to the path */
+		if (!(strcmp(path->name, e->texts[val])))
+			path->connect = 1; /* new connection */
+		else
+			path->connect = 0; /* old connection must be powered down */	
+	}
+
+	dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);			
+	return 0;
+}
+
+/* test and update the power status of a mixer widget */
+static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, 
+	snd_kcontrol_t *kcontrol, int reg, int val_mask, int val, int invert)
+{
+	struct list_head *l;
+	struct snd_soc_dapm_path *path;
+
+	if(widget->id != snd_soc_dapm_mixer)
+		return -ENODEV; 
+
+	if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
+		return 0;
+	
+	/* find dapm widget path assoc with kcontrol */
+	list_for_each(l, &widget->codec->dapm_paths)
+	{
+		path = list_entry(l, struct snd_soc_dapm_path, list);
+		if (path->kcontrol != kcontrol)
+			continue;
+			
+		/* found, now check type */
+		if (val)
+			path->connect = invert ? 0:1; /* new connection */
+		else
+			path->connect = invert ? 1:0; /* old connection must be powered down */
+		break;
+		
+	}
+
+	dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
+	return 0;
+}
+
+/* show dapm paths in sys fs */
+static ssize_t dapm_path_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct snd_soc_device *devdata = dev_get_drvdata(dev);
+	struct snd_soc_codec* codec = devdata->codec;
+	struct snd_soc_dapm_widget *w = NULL;
+	struct snd_soc_dapm_path *p = NULL;
+	struct list_head *l = NULL, *lp = NULL;
+	int in, out, count = 0;
+	
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w = list_entry(l, struct snd_soc_dapm_widget, list);
+		if (w->name) {
+				in = is_connected_input_ep(w);
+				dapm_clear_walk(w->codec);
+				out = is_connected_output_ep(w);
+				dapm_clear_walk(w->codec);
+				count += sprintf(buf + count, "%s: %s  in %d out %d\n", 
+					w->name, w->power ? "On":"Off",in, out);
+				
+				list_for_each(lp, &w->inputs)
+				{
+					p = list_entry(lp, struct snd_soc_dapm_path, list_out);
+					if (p->connect)
+						count += sprintf(buf + count, " in  %s %s\n", 
+							p->name ? p->name : "static", p->in->name);
+				}
+				list_for_each(lp, &w->outputs)
+				{
+					p = list_entry(lp, struct snd_soc_dapm_path, list_in);
+					if (p->connect)
+						count += sprintf(buf + count," out %s %s\n", 
+							p->name ? p->name : "static", p->out->name);
+				}
+				
+		}
+	}
+	return count;
+}
+
+/* show dapm widget status in sys fs */
+static ssize_t dapm_widget_show(struct device *dev, 
+	struct device_attribute *attr, char *buf)
+{
+	struct snd_soc_device *devdata = dev_get_drvdata(dev);
+	struct snd_soc_codec* codec = devdata->codec;
+	struct snd_soc_dapm_widget *w = NULL;
+	struct list_head *l = NULL;
+	int count = 0;
+	char *state = "not set";
+
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w = list_entry(l, struct snd_soc_dapm_widget, list);
+		if (w->name && w->reg > 0 && 
+			w->id != snd_soc_dapm_input && w->id != snd_soc_dapm_output)
+			count += sprintf(buf + count, "%s: %s\n", w->name, 
+				w->power ? "On":"Off");
+	}
+	switch(codec->dapm_state){
+	case SNDRV_CTL_POWER_D0:
+		state = "D0";
+		break;
+	case SNDRV_CTL_POWER_D1:
+		state = "D1";
+		break;
+	case SNDRV_CTL_POWER_D2:
+		state = "D2";
+		break;
+	case SNDRV_CTL_POWER_D3hot:
+		state = "D3hot";
+		break;
+	case SNDRV_CTL_POWER_D3cold:
+		state = "D3cold";
+		break;
+	}
+	count += sprintf(buf + count, "PM State: %s\n", state);
+	
+	return count;
+}
+
+static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
+static DEVICE_ATTR(dapm_path, 0444, dapm_path_show, NULL);
+		     
+int snd_soc_dapm_sys_add(struct device *dev) 
+{
+	int ret;
+	
+	if (dapm_status) {
+		if((ret = device_create_file(dev, &dev_attr_dapm_widget)) < 0)
+			return ret;
+		if((ret = device_create_file(dev, &dev_attr_dapm_path)) < 0)
+			return ret;
+	}
+		
+	return 0;
+}	     
+
+static void snd_soc_dapm_sys_remove(struct device *dev) 
+{
+	if (dapm_status) {
+		device_remove_file(dev, &dev_attr_dapm_widget);
+		device_remove_file(dev, &dev_attr_dapm_path);
+	}
+} 
+
+/* free all dapm widgets and resources */
+void dapm_free_widgets(struct snd_soc_codec *codec)
+{
+	struct snd_soc_dapm_widget *w, *lw = NULL;
+	struct snd_soc_dapm_path *p, *lp = NULL;
+	struct list_head *l;
+
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w =  list_entry(l, struct snd_soc_dapm_widget, list);
+		if (lw)
+			kfree(lw);
+		lw = w;
+	}
+	kfree(lw);
+	
+	list_for_each(l, &codec->dapm_paths)
+	{
+		p =  list_entry(l, struct snd_soc_dapm_path, list);
+		if(p->long_name)
+			kfree(p->long_name);
+		if (lp)
+			kfree(lp);
+		lp = p;
+	}
+	kfree(lp);
+}
+
+/**
+ * snd_soc_dapm_sync_endpoints - scan and power dapm paths 
+ * @codec: audio codec
+ *
+ * Walks all dapm audio paths and powers widgets according to their
+ * stream or path usage.  
+ * 
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_sync_endpoints(struct snd_soc_codec *codec)
+{
+	return dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_endpoints);
+
+/**
+ * snd_soc_dapm_connect_input - connect dapm widgets
+ * @codec: audio codec
+ * @target: name of target widget
+ * @control: mixer control name
+ * @source: name of source name
+ *
+ * Connects 2 dapm widgets together via a named audio path. The target is 
+ * the widget receiving the audio signal, whilst the source is the sender
+ * of the audio signal.
+ * 
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_connect_input(struct snd_soc_codec *codec, const char *target, 
+	const char * control, const char *source)
+{
+	struct snd_soc_dapm_path *path;
+	struct snd_soc_dapm_widget *src = NULL, *dest = NULL, *w;
+	struct list_head *l;
+	int ret = 0;
+
+	/* find src and dest widgets */
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w = list_entry(l, struct snd_soc_dapm_widget, list);
+		
+		if(!(strcmp(w->name, target))) {
+			dest = w;
+			continue;
+		}
+		if(!(strcmp(w->name, source))) {
+			src = w;
+		}				
+	}
+
+	if(src == NULL || dest == NULL)
+		return -ENODEV;
+	
+	path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
+	if (!path)
+		return -ENOMEM;	
+
+	path->in = src;
+	path->out = dest;
+	INIT_LIST_HEAD(&path->list);
+	INIT_LIST_HEAD(&path->list_in);
+	INIT_LIST_HEAD(&path->list_out);
+
+	/* check for external widgets */
+	if(dest->id == snd_soc_dapm_input) {	
+		if (src->id == snd_soc_dapm_micbias || src->id == snd_soc_dapm_mic ||
+			dest->id == snd_soc_dapm_line)
+			dest->ext = 1;
+	}
+	if(src->id == snd_soc_dapm_output) {	
+		if (dest->id == snd_soc_dapm_spk || dest->id == snd_soc_dapm_hp ||
+			dest->id == snd_soc_dapm_line)
+			src->ext = 1;
+	}
+	
+	/* connect static paths */
+	if(control == NULL) {
+		list_add(&path->list, &codec->dapm_paths);
+		list_add(&path->list_out, &dest->inputs);
+		list_add(&path->list_in, &src->outputs);
+		path->connect = 1;
+		return 0;
+	}
+
+	/* connect dynamic paths */
+	switch(dest->id) {
+	case snd_soc_dapm_adc:
+	case snd_soc_dapm_dac:
+	case snd_soc_dapm_volume:
+	case snd_soc_dapm_input:
+	case snd_soc_dapm_output:
+	case snd_soc_dapm_clock:
+	case snd_soc_dapm_vref:
+	case snd_soc_dapm_micbias:
+	case snd_soc_dapm_mute:
+		list_add(&path->list, &codec->dapm_paths);
+		list_add(&path->list_out, &dest->inputs);
+		list_add(&path->list_in, &src->outputs);
+		path->connect = 1;
+		return 0;
+	case snd_soc_dapm_mux:
+		if((ret = dapm_connect_mux(codec, src, dest, path, control, 
+			&dest->kcontrols[0])) != 0)
+			goto err;
+		break;
+	case snd_soc_dapm_switch:
+	case snd_soc_dapm_mixer:
+		if((ret = dapm_connect_mixer(codec, src, dest, path, control)) != 0)
+			goto err;
+		break;
+	case snd_soc_dapm_hp:
+	case snd_soc_dapm_mic:
+	case snd_soc_dapm_line:
+	case snd_soc_dapm_spk:
+		list_add(&path->list, &codec->dapm_paths);
+		list_add(&path->list_out, &dest->inputs);
+		list_add(&path->list_in, &src->outputs);
+		path->connect = 0;
+		return 0;
+	}
+	return 0;
+
+err:
+	printk(KERN_WARNING "soc: no dapm match for %s --> %s --> %s\n", source, 
+		control, target); 
+	kfree(path);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_connect_input);
+
+/**
+ * snd_soc_dapm_new_widgets - add new dapm widgets
+ * @codec: audio codec
+ *
+ * Checks the codec for any new dapm widgets and creates them if found.
+ * 
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
+{
+	struct snd_soc_dapm_widget *w = NULL;
+	struct list_head *lw;
+	
+	list_for_each(lw, &codec->dapm_widgets)
+	{
+		w = list_entry(lw, struct snd_soc_dapm_widget, list);
+		
+		if(w->new)
+			continue;
+		
+		switch(w->id) {
+		case snd_soc_dapm_switch:
+		case snd_soc_dapm_mixer:
+			dapm_new_mixer(codec, w);
+			break;
+		case snd_soc_dapm_mux:
+			dapm_new_mux(codec, w);
+			break;
+		case snd_soc_dapm_adc:
+		case snd_soc_dapm_dac:
+		case snd_soc_dapm_volume:
+			dapm_new_volume(codec, w);
+			break;
+		case snd_soc_dapm_input:
+		case snd_soc_dapm_output:
+		case snd_soc_dapm_clock:
+		case snd_soc_dapm_vref:
+		case snd_soc_dapm_micbias:
+		case snd_soc_dapm_mute:
+		case snd_soc_dapm_spk:
+		case snd_soc_dapm_hp:
+		case snd_soc_dapm_mic:
+		case snd_soc_dapm_line:
+			break;
+		}
+		w->new = 1;
+	}
+	
+	dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
+
+/**
+ * snd_soc_dapm_get_volsw - dapm mixer get callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to get the value of a dapm mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_get_volsw(snd_kcontrol_t * kcontrol, 
+	snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
+	int reg = kcontrol->private_value & 0xff;
+	int shift = (kcontrol->private_value >> 8) & 0x0f;
+	int rshift = (kcontrol->private_value >> 12) & 0x0f;
+	int mask = (kcontrol->private_value >> 16) & 0xff;
+	int invert = (kcontrol->private_value >> 24) & 0x01;
+
+	if(widget->id == snd_soc_dapm_volume && !widget->power) {
+		ucontrol->value.integer.value[0] = widget->value;
+		return 0;
+	}
+	
+	ucontrol->value.integer.value[0] = 
+		(snd_soc_read(widget->codec, reg) >> shift) & mask;
+	if (shift != rshift)
+		ucontrol->value.integer.value[1] = 
+			(snd_soc_read(widget->codec, reg) >> rshift) & mask;
+	if (invert) {
+		ucontrol->value.integer.value[0] = 
+			mask - ucontrol->value.integer.value[0];
+		if (shift != rshift)
+			ucontrol->value.integer.value[1] = 
+				mask - ucontrol->value.integer.value[1];
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
+
+/**
+ * snd_soc_dapm_put_volsw - dapm mixer set callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to set the value of a dapm mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_put_volsw(snd_kcontrol_t * kcontrol, 
+	snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
+	int reg = kcontrol->private_value & 0xff;
+	int shift = (kcontrol->private_value >> 8) & 0x0f;
+	int rshift = (kcontrol->private_value >> 12) & 0x0f;
+	int mask = (kcontrol->private_value >> 16) & 0xff;
+	int invert = (kcontrol->private_value >> 24) & 0x01;
+	unsigned short val, val2, val_mask;
+	
+	val = (ucontrol->value.integer.value[0] & mask);
+	if (invert)
+		val = mask - val;
+	val_mask = mask << shift;
+	val = val << shift;
+	if (shift != rshift) {
+		val2 = (ucontrol->value.integer.value[1] & mask);
+		if (invert)
+			val2 = mask - val2;
+		val_mask |= mask << rshift;
+		val |= val2 << rshift;
+	}
+	
+	if(widget->id == snd_soc_dapm_volume && !widget->power) {
+		widget->value = val;
+		return 1;
+	}
+	
+	dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
+	return snd_soc_update_bits(widget->codec, reg, val_mask, val);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
+
+/**
+ * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to get the value of a dapm enumerated double mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_get_enum_double(snd_kcontrol_t * kcontrol, 
+	snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	unsigned short val, bitmask;
+	
+	for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
+		;
+	val = snd_soc_read(widget->codec, e->reg);
+	ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
+	if (e->shift_l != e->shift_r)
+		ucontrol->value.enumerated.item[1] = (val >> e->shift_r) & (bitmask - 1);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
+
+/**
+ * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to set the value of a dapm enumerated double mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_put_enum_double(snd_kcontrol_t * kcontrol, 
+	snd_ctl_elem_value_t * ucontrol)
+{
+	struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	unsigned short val, mux;
+	unsigned short mask, bitmask;
+	
+	for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
+		;
+	if (ucontrol->value.enumerated.item[0] > e->mask - 1)
+		return -EINVAL;
+	mux = ucontrol->value.enumerated.item[0];
+	val = mux << e->shift_l;
+	mask = (bitmask - 1) << e->shift_l;
+	if (e->shift_l != e->shift_r) {
+		if (ucontrol->value.enumerated.item[1] > e->mask - 1)
+			return -EINVAL;
+		val |= ucontrol->value.enumerated.item[1] << e->shift_r;
+		mask |= (bitmask - 1) << e->shift_r;
+	}
+
+	dapm_mux_update_power(widget, kcontrol, mask, mux, e);
+	return snd_soc_update_bits(widget->codec, e->reg, mask, val);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
+
+/**
+ * snd_soc_dapm_new_control - create new dapm control
+ * @codec: audio codec
+ * @widget: widget template
+ *
+ * Creates a new dapm control based upon the template.
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_new_control(struct snd_soc_codec *codec, 
+	const struct snd_soc_dapm_widget *widget)
+{
+	struct snd_soc_dapm_widget *w;
+
+	if ((w = dapm_cnew_widget(widget)) == NULL)
+		return -ENOMEM;
+
+	w->codec = codec;
+	INIT_LIST_HEAD(&w->inputs);
+	INIT_LIST_HEAD(&w->outputs);
+	INIT_LIST_HEAD(&w->list);
+	list_add(&w->list, &codec->dapm_widgets);
+
+	/* machine layer set ups unconnected pins and insertions */
+	w->connected = 1;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
+
+/**
+ * snd_soc_dapm_stream_event - send a stream event to the dapm core
+ * @codec: audio codec
+ * @stream: stream name
+ * @event: stream event
+ *
+ * Sends a stream event to the dapm core. The core then makes any
+ * necessary widget power changes.
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, 
+	char *stream, int event)
+{
+	struct snd_soc_dapm_widget *w;
+	struct list_head *l = NULL;
+	
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w = list_entry(l, struct snd_soc_dapm_widget, list);
+
+		if (!w->sname)
+			continue;
+		dbg("widget %s\n %s stream %s event %d\n",w->name, w->sname, stream, event);
+		if (strstr(w->sname, stream)) {
+			switch(event) {
+			case SND_SOC_DAPM_STREAM_START:
+				w->active = 1;
+				break;
+			case SND_SOC_DAPM_STREAM_STOP:
+				w->active = 0;
+				break;
+			case SND_SOC_DAPM_STREAM_SUSPEND:
+				if (w->active)
+					w->suspend = 1;	
+				w->active = 0;
+				break;
+			case SND_SOC_DAPM_STREAM_RESUME:
+				if(w->suspend) {
+					w->active = 1;
+					w->suspend = 0;
+				}
+				break;
+			case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
+				break;
+			case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
+				break;
+			}
+		}					
+	}
+	
+	dapm_power_widgets(codec, event);
+	dump_dapm(codec, __FUNCTION__);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
+
+/**
+ * snd_soc_dapm_codec_event - send a codec event to the dapm core
+ * @codec: audio codec
+ * @event: codec event
+ *
+ * Sends a codec event to the dapm core. The core then makes any
+ * necessary widget power changes. Codec power domain is changed
+ * i.e. clocks, core voltage
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_codec_event(struct snd_soc_codec *codec, int event)
+{
+	struct snd_soc_dapm_widget *w;
+	struct list_head *l = NULL;	
+	int pm = 0;
+
+	if(event == SNDRV_CTL_POWER_D0)
+		pm = 1;
+	else if(event == SNDRV_CTL_POWER_D3hot)
+		pm = 0;
+		
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w = list_entry(l, struct snd_soc_dapm_widget, list);
+		if(w->id == snd_soc_dapm_vref || w->id == snd_soc_dapm_clock)
+			dapm_update_bits(w, pm);
+	}
+	
+	dump_dapm(codec, __FUNCTION__);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_codec_event);
+
+
+/**
+ * snd_soc_dapm_codec_mute - control the codec digital mute
+ * @codec: audio codec
+ * @mute: mute/unmute
+ *
+ * Controls the codec digital mute - used to reduce pop and click noises.
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_codec_mute(struct snd_soc_codec *codec, int mute)
+{
+	struct snd_soc_dapm_widget *w;
+	struct list_head *l = NULL;	
+
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w = list_entry(l, struct snd_soc_dapm_widget, list);
+
+		if(w->id == snd_soc_dapm_mute)
+			dapm_update_bits(w, mute);
+	}
+	
+	dump_dapm(codec, __FUNCTION__);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_codec_mute);
+
+/**
+ * snd_soc_dapm_set_endpoint - set audio endpoint status
+ * @codec: audio codec
+ * @endpoint: audio signal endpoint (or start point)
+ * @status: point status
+ *
+ * Set audio endpoint status - connected or disconnected.
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec, 
+	char *endpoint, int status)
+{
+	struct snd_soc_dapm_widget *w;
+	struct list_head *l = NULL;	
+
+	list_for_each(l, &codec->dapm_widgets)
+	{
+		w = list_entry(l, struct snd_soc_dapm_widget, list);
+
+		if(!strcmp(w->name, endpoint)) {
+			w->connected = status;
+		}
+	}
+	
+	return 0;	
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint);
+
+/**
+ * snd_soc_dapm_free - free dapm resources
+ * @socdev: SoC device
+ *
+ * Free all dapm widgets and resources.
+ */
+void snd_soc_dapm_free(struct snd_soc_device *socdev)
+{
+	struct snd_soc_codec *codec = socdev->codec;
+
+	snd_soc_dapm_sys_remove(socdev->dev);
+	dapm_free_widgets(codec);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("ALSA SoC DPM");
+MODULE_LICENSE("GPL");
diff --git a/include/sound/soc.h b/include/sound/soc.h
new file mode 100644
index 0000000..e9ddf41
--- /dev/null
+++ b/include/sound/soc.h
@@ -0,0 +1,426 @@
+/*
+ * linux/sound/soc.h -- ALSA SoC Layer
+ *
+ * Author:		Liam Girdwood
+ * Created:		Aug 11th 2005
+ * Copyright:	Wolfson Microelectronics. PLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+ 
+#ifndef __LINUX_SND_SOC_H
+#define __LINUX_SND_SOC_H
+
+#include <linux/platform_device.h>
+#include <linux/types.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/control.h>
+#include <sound/ac97_codec.h>
+
+#define SND_SOC_VERSION "0.10rc4"
+
+/*
+ * Convenience kcontrol builders
+ */
+
+#define SOC_SINGLE_VALUE(reg,shift,mask,invert) ((reg) | ((shift) << 8) | ((shift) << 12) | ((mask) << 16) | ((invert) << 24))
+#define SOC_SINGLE_VALUE_EXT(reg,mask,invert) ((reg) | ((mask) << 16) | ((invert) << 31))
+#define SOC_SINGLE(xname, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_volsw, \
+  .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
+  .private_value =  SOC_SINGLE_VALUE(reg, shift, mask, invert) }
+#define SOC_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .info = snd_soc_info_volsw, \
+  .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
+  .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) }
+#define SOC_DOUBLE_R(xname, reg_left, reg_right, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .info = snd_soc_info_volsw_2r, \
+  .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
+  .private_value = (reg_left) | ((shift) << 8)  | ((mask) << 12) | ((invert) << 20) | ((reg_right) << 24) }
+#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \
+{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
+  .mask = xmask, .texts = xtexts }
+#define SOC_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \
+	SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts)
+#define SOC_ENUM_SINGLE_EXT(xmask, xtexts) \
+{ .mask = xmask, .texts = xtexts }
+#define SOC_ENUM(xname, xenum) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_enum_double, \
+  .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
+  .private_value = (unsigned long)&xenum }
+#define SOC_SINGLE_EXT(xname, xreg, xmask, xinvert, xhandler_get, xhandler_put) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_volsw_ext, \
+  .get = xhandler_get, .put = xhandler_put, \
+  .private_value =  SOC_SINGLE_VALUE_EXT(xreg, xmask, xinvert) }
+#define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_bool_ext, \
+  .get = xhandler_get, .put = xhandler_put, \
+  .private_value = xdata }
+#define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_enum_ext, \
+  .get = xhandler_get, .put = xhandler_put, \
+  .private_value = (unsigned long)&xenum }
+  
+/*
+ * Audio interface types
+ */
+#define SND_SOC_AC97	0x1
+#define SND_SOC_I2S		0x2
+#define SND_SOC_SSP		0x4
+
+/*
+ * hw interface formats
+ */
+#define SND_SOC_HWFMT_I2S		(1 << 0)	/* I2S mode */
+#define SND_SOC_HWFMT_RIGHT_J	(1 << 1)	/* Right justified mode */
+#define SND_SOC_HWFMT_LEFT_J	(1 << 2)	/* Left Justified mode */
+#define SND_SOC_HWFMT_DSP_A		(1 << 3)	/* L data msb after FRM */
+#define SND_SOC_HWFMT_DSP_B		(1 << 4)	/* L data msb during FRM */
+#define SND_SOC_HWFMT_AC97		(1 << 5)	/* AC97 */
+
+/*
+ * hw signal inversions
+ */
+#define SND_SOC_HWFMT_NB_NF		(1 << 8)	/* normal bit clock + frame */
+#define SND_SOC_HWFMT_NB_IF		(1 << 9)	/* normal bclk + inv frm */
+#define SND_SOC_HWFMT_IB_NF		(1 << 10)	/* invert bclk + nor frm */
+#define SND_SOC_HWFMT_IB_IF		(1 << 11)	/* invert bclk + frm */
+
+/*
+ * hw clock masters
+ * This is wrt the codec, the inverse is true for the interface
+ * i.e. if the codec is clk and frm master then the interface is 
+ * clk and frame slave.
+ */
+#define SND_SOC_HWFMT_CBM_CFM		(1 << 12)	/* codec clk & frm master */
+#define SND_SOC_HWFMT_CBS_CFM		(1 << 13)	/* codec clk slave & frm master */
+#define SND_SOC_HWFMT_CBM_CFS		(1 << 14)	/* codec clk master & frame slave */
+#define SND_SOC_HWFMT_CBS_CFS		(1 << 15)	/* codec clk & frm slave */
+
+#define SND_SOC_HWFMT_FORMAT_MASK		0x00ff
+#define SND_SOC_HWFMT_INV_MASK			0x0f00
+#define SND_SOC_HWFMT_CLOCK_MASK		0xf000
+
+/*
+ * hw audio direction
+ */
+#define SND_SOC_HWDIR_PLAYBACK		0x1
+#define SND_SOC_HWDIR_CAPTURE		0x2
+
+/* 
+ * Time Division Multiplexing (TDM) Slots 
+ * Left and Right data word positions
+ * This is measured in words and not bits. The word size is the
+ * number of bits in a sample e.g. 16, 18, 20, 24, 32, etc.
+ */
+#define SND_SOC_HWTDM_LRDW(l,r)	((l << 8) | r)
+
+/* 
+ * hw clock ratios
+ * bit clock can either be a generated by dividing mclk or
+ * by multiplying sample rate, hence there are 2 definitions below
+ * depending on codec type.
+ */
+/* ratio of sample rate to mclk/sysclk */
+#define SND_SOC_FS(x)			(1 << ((x - 128) / 64))	/* ratio mclk:srate */
+#define SND_SOC_FS_ALL			0xffffffff	/* all mclk supported */
+#define SND_SOC_FS_INT(x)		(((generic_ffs(x) - 1) * 64) + 128)
+
+/* bit clock dividers */
+#define SND_SOC_FSBD(x)			(1 << (x - 1))	/* ratio mclk:bclk */
+#define SND_SOC_FSBD_INT(x)		generic_ffs(x)
+#define SND_SOC_FSBD_ALL		0xffff /* all bit clock dividers supported */
+
+/* bit clock ratio to sample rate */
+#define SND_SOC_FSB(x)			(1 << ((x - 16) / 16))
+#define SND_SOC_FSB_INT(x)		(((generic_ffs(x) - 1) * 16) + 16)
+#define SND_SOC_FSB_ALL			SND_SOC_FSBD_ALL	/* all bclk ratios supported */
+
+/*
+ * hw flags
+ */
+#define SND_SOC_HW_BFS_DIV	0x1	/* use bfs mclk divider mode, else sample rate ratio */
+
+/*
+ * AC97 codec ID's bitmask
+ */
+#define SND_SOC_AC97_ID0	(1 << 0)
+#define SND_SOC_AC97_ID1	(1 << 1)
+#define SND_SOC_AC97_ID2	(1 << 2)
+#define SND_SOC_AC97_ID3	(1 << 3)
+
+struct snd_soc_device;
+struct snd_soc_pcm_stream;
+struct snd_soc_ops;
+struct snd_soc_hw_mode;
+struct snd_soc_hw_bus;
+struct snd_soc_pcm_codec;
+struct snd_soc_pcm_interface;
+struct snd_soc_codec;
+struct snd_soc_machine_config;
+struct soc_enum;
+struct snd_soc_ac97_ops;
+	
+typedef int (*hw_write_t)(void *,const char* ,int);
+typedef int (*hw_read_t)(void *,char* ,int);
+
+extern struct snd_ac97_bus_ops soc_ac97_ops;
+
+/* pcm <-> interface connect */
+void snd_soc_free_pcms(struct snd_soc_device *socdev);
+int snd_soc_new_pcms(struct snd_soc_device *socdev);
+int snd_soc_register_card(struct snd_soc_device *socdev);
+
+/* set runtime hw params */
+int snd_soc_set_runtime_hw(snd_pcm_substream_t *substream, 
+	const snd_pcm_hardware_t *hw);
+int snd_soc_get_rate(int rate);
+
+/* codec IO */
+#define snd_soc_read(codec, reg) codec->read(codec, reg)
+#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
+
+/* codec register bit access */
+int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
+				unsigned short mask, unsigned short value);
+int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
+				unsigned short mask, unsigned short value);
+
+int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, 
+	struct snd_ac97_bus_ops *ops, int num);
+void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
+
+/*
+ *Controls
+ */
+snd_kcontrol_t *snd_soc_cnew(const snd_kcontrol_new_t *_template, 
+	void *data, char *long_name);
+
+int snd_soc_info_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo);
+int snd_soc_info_enum_ext(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo);
+int snd_soc_get_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_put_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_info_volsw(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo);
+int snd_soc_info_volsw_ext(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo);
+int snd_soc_info_bool_ext(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo);
+int snd_soc_get_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_put_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_info_volsw_2r(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo);
+int snd_soc_get_volsw_2r(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_put_volsw_2r(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+	
+/* SoC supported stream types */
+struct snd_soc_pcm_stream {
+	char *sname;
+	unsigned int rate_min;		/* min rate */
+	unsigned int rate_max;		/* max rate */
+	unsigned int channels_min;	/* min channels */
+	unsigned int channels_max;	/* max channels */
+	unsigned int active:1;		/* stream is in use */
+};
+
+/* SoC audio ops */
+struct snd_soc_ops {
+	int (*startup)(snd_pcm_substream_t *);
+	void (*shutdown)(snd_pcm_substream_t *);
+	int (*hw_params)(snd_pcm_substream_t *, snd_pcm_hw_params_t *);
+	int (*hw_free)(snd_pcm_substream_t *);
+	int (*prepare)(snd_pcm_substream_t *);
+	int (*trigger)(snd_pcm_substream_t *, int);
+};
+
+/* SoC hardware mode */
+struct snd_soc_hw_mode {
+	unsigned int hwfmt:16;		/* SND_SOC_HWFMT_* */
+	unsigned int hwtdm:16;		/* SND_SOC_HWTDM_* */
+	unsigned int hwpcmfmt:6; 	/* SNDRV_PCM_FORMAT_* */
+	unsigned int hwpcmrate:16;	/* SND_SOC_HWRATE_* */
+	unsigned int hwpcmdir:2;	/* SND_SOC_HWDIR_* */
+	unsigned int hwflags:8;		/* hw flags */
+	unsigned int hwfs:32;		/* mclk to rate dividers */ 
+	unsigned int hwbfs:16;		/* mclk to bclk dividers */
+	unsigned long priv;	/* private mode data */
+};
+
+/* SoC hardware bus and all modes */
+struct snd_soc_hw_bus {
+	int num_hmodes;				/* number of hw modes */
+	struct snd_soc_hw_mode *hmodes;	/* array of supported audio hw modes */	
+};
+
+/* SoC Codec pcm stream */
+struct snd_soc_pcm_codec {
+	char *name;
+
+	/* codec pcm capabilities */
+	struct snd_soc_pcm_stream playback;
+	struct snd_soc_pcm_stream capture;
+	struct snd_soc_hw_bus hw;
+	int nplayback;
+	int ncapture;
+	
+	/* runtime info */
+	struct snd_soc_hw_mode hw_runtime;
+	struct snd_soc_ops ops;
+	struct snd_soc_platdev_data *platdev_data;
+	unsigned int (*config_sysclk)(struct snd_soc_pcm_codec*, int rate, 
+		unsigned int clk);
+	unsigned int mclk;
+	unsigned int active;
+	
+	/* private data */
+	void *priv;
+	void (*private_free)(snd_pcm_runtime_t *runtime);
+};
+
+/* SoC platform audio port interface */
+struct snd_soc_pcm_interface {
+	
+	/* interface description */
+	char *name;
+	unsigned int id;
+	unsigned char type;
+	
+	/* interface callbacks */
+	int (*probe)(struct platform_device *pdev);
+	void (*remove)(struct platform_device *pdev);
+	int (*suspend)(struct platform_device *pdev, struct snd_soc_pcm_interface *iface);
+	int (*resume)(struct platform_device *pdev, struct snd_soc_pcm_interface *iface);
+	unsigned int (*config_sysclk)(struct snd_soc_pcm_interface *iface, 
+		int rate, unsigned int clk);
+		
+	/* interface pcm capabilities */
+	struct snd_soc_pcm_stream capture;
+	struct snd_soc_pcm_stream playback;
+	struct snd_soc_hw_bus hw;
+	
+	/* runtime info */
+	struct snd_soc_pcm_runtime *soc_runtime;
+	struct snd_soc_hw_mode hw_runtime;
+	struct snd_soc_ops ops;
+	struct snd_soc_device *socdev;
+	snd_pcm_runtime_t *runtime;
+	unsigned char active:1;
+	unsigned int mclk;
+	
+	/* private data */
+	void *platform_data;
+};
+
+/* SoC Codec interface */
+struct snd_soc_codec {
+	char *name;
+	struct module *owner;
+	
+	/* callbacks */
+	int (*dapm_event)(struct snd_soc_codec *codec, int event);
+	
+	/* runtime */
+	snd_card_t *card;
+	struct snd_ac97 *ac97;  /* for ad-hoc ac97 devices */
+	
+	void *private_data;
+	unsigned int active;
+	unsigned int pcm_devs;
+	unsigned int dapm_state;
+	unsigned int suspend_dapm_state;
+
+	/* codec IO */
+	void *control_data; /* codec control (i2c/3wire) data */
+	unsigned int (*read)(struct snd_soc_codec *, unsigned int);
+	int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
+	hw_write_t hw_write;
+	hw_read_t hw_read;
+	void *reg_cache;
+	
+	/* dapm */
+	struct list_head dapm_widgets;
+	struct list_head dapm_paths;
+	
+	/* codec pcms */
+	struct snd_soc_pcm_codec *pcms;
+	unsigned int npcms;
+};
+
+struct snd_soc_codec_device {
+	int (*probe)(struct platform_device *pdev);
+	int (*remove)(struct platform_device *pdev);
+	int (*suspend)(struct platform_device *pdev, pm_message_t state);
+	int (*resume)(struct platform_device *pdev);
+};
+
+/* SoC platform interface */
+struct snd_soc_platform {
+	char *name;
+	
+	int (*probe)(struct platform_device *pdev);
+	int (*remove)(struct platform_device *pdev);
+	int (*suspend)(struct platform_device *pdev, struct snd_soc_pcm_interface *iface);
+	int (*resume)(struct platform_device *pdev, struct snd_soc_pcm_interface *iface);
+	int (*pcm_new)(snd_card_t *, struct snd_soc_pcm_codec *, snd_pcm_t *);
+	void (*pcm_free)(snd_pcm_t *);
+	snd_pcm_ops_t *pcm_ops;
+};
+
+/* SoC machine configuration */
+struct snd_soc_machine_config {
+	char *name;			/* Codec name */
+	char *sname;		/* Stream name */
+	struct snd_soc_pcm_interface* iface;
+	u32 flags;			/* preference flags */
+
+	/* codec/machine specific init - e.g. add machine controls */
+	int (*init)(struct snd_soc_codec *codec);
+	unsigned int (*config_sysclk)(struct snd_soc_pcm_runtime *rtd, 
+		int rate, unsigned int hwfmt);
+};
+
+/* SoC machine interface */
+struct snd_soc_machine {
+	char *name;
+	
+	int (*probe)(struct platform_device *pdev);
+	int (*remove)(struct platform_device *pdev);
+	int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
+	int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
+	int (*resume_pre)(struct platform_device *pdev);
+	int (*resume_post)(struct platform_device *pdev);
+	
+	struct snd_soc_ops *ops;
+	struct snd_soc_machine_config *config;
+	int nconfigs;
+};
+
+/* SoC Device */
+struct snd_soc_device {
+	struct device *dev;
+	struct snd_soc_machine *machine;
+	struct snd_soc_platform *platform;
+	struct snd_soc_codec *codec;
+	struct snd_soc_codec_device *codec_dev;
+	void *codec_data;
+};
+
+/* runtime chn data */
+struct snd_soc_pcm_runtime {
+	struct snd_soc_pcm_codec *pcm_c;
+	struct snd_soc_pcm_interface *pcm_i;
+	struct snd_soc_device *socdev;
+};
+
+/* enumerated kcontrol */
+struct soc_enum {
+	unsigned short reg;
+	unsigned short reg2;
+	unsigned char shift_l;
+	unsigned char shift_r;
+	unsigned int mask;
+	const char **texts;
+	void *dapm;
+};
+
+#endif
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
new file mode 100644
index 0000000..944012f
--- /dev/null
+++ b/include/sound/soc-dapm.h
@@ -0,0 +1,222 @@
+/*
+ * linux/sound/soc-dapm.h -- ALSA SoC Dynamic Audio Power Management
+ *
+ * Author:		Liam Girdwood
+ * Created:		Aug 11th 2005
+ * Copyright:	Wolfson Microelectronics. PLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+ 
+#ifndef __LINUX_SND_SOC_DAPM_H
+#define __LINUX_SND_SOC_DAPM_H
+
+#include <linux/device.h>
+#include <linux/types.h>
+#include <sound/control.h>
+#include <sound/soc.h>
+
+#define SND_SOC_DAPM_NOPM	-1
+
+/*
+ * SoC dynamic audio power managment
+ *
+ * We can have upto 4 power domains
+ * 	1. Codec domain - VREF, VMID
+ *     Usually controlled at codec probe/remove, although can be set
+ *     at stream time if power is not needed for sidetone, etc.
+ *  2. Platform/Machine domain - physically connected inputs and outputs
+ *     Is platform/machine and user action specific, is set in the .asoundrc file and
+ *     by userspace e.g when HP are inserted
+ *  3. Path domain - Internal codec path mixers
+ *     Are automatically set when mixer and mux settings are
+ *     changed by the user.
+ *  4. Stream domain - DAC's and ADC's.
+ *     Enabled when stream playback/capture is started.  
+ */
+
+/* codec domain - vmid, vref handled by the codec driver */  
+#define SND_SOC_DAPM_CLOCK(wname, preg, pshift, pinvert) \
+{.id = snd_soc_dapm_clock, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = NULL, .num_kcontrols = 0}
+/* not a true power register, but is used by dapm to minimise pops */ 
+#define SND_SOC_DAPM_MUTE(wname, preg, pshift, pinvert) \
+{.id = snd_soc_dapm_mute, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = NULL, .num_kcontrols = 0}
+ 
+/* platform domain */
+#define SND_SOC_DAPM_INPUT(wname) \
+{.id = snd_soc_dapm_input, .name = wname, .kcontrols = NULL, \
+ .num_kcontrols = 0}
+#define SND_SOC_DAPM_OUTPUT(wname) \
+{.id = snd_soc_dapm_output, .name = wname, .kcontrols = NULL, \
+ .num_kcontrols = 0}
+#define SND_SOC_DAPM_MIC(wname, wevent) \
+{.id = snd_soc_dapm_mic, .name = wname, .kcontrols = NULL, \
+ .num_kcontrols = 0, .ext_event = wevent}
+#define SND_SOC_DAPM_HP(wname, wevent) \
+{.id = snd_soc_dapm_hp, .name = wname, .kcontrols = NULL, \
+ .num_kcontrols = 0, .ext_event = wevent}
+#define SND_SOC_DAPM_SPK(wname, wevent) \
+{.id = snd_soc_dapm_spk, .name = wname, .kcontrols = NULL, \
+ .num_kcontrols = 0, .ext_event = wevent}
+#define SND_SOC_DAPM_LINE(wname, wevent) \
+{.id = snd_soc_dapm_line, .name = wname, .kcontrols = NULL, \
+ .num_kcontrols = 0, .ext_event = wevent}
+ 
+/* path domain */
+#define SND_SOC_DAPM_VOLUME(wname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dapm_volume, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
+#define SND_SOC_DAPM_MIXER(wname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dapm_mixer, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols} 
+#define SND_SOC_DAPM_MICBIAS(wname, preg, pshift, pinvert) \
+{.id = snd_soc_dapm_micbias, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = NULL, .num_kcontrols = 0}
+#define SND_SOC_DAPM_SWITCH(wname, preg, pshift, pinvert, wcontrols) \
+{.id = snd_soc_dapm_switch, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = 1} 
+#define SND_SOC_DAPM_MUX(wname, preg, pshift, pinvert, wcontrols) \
+{.id = snd_soc_dapm_mux, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = 1} 
+
+/* stream domain */
+#define SND_SOC_DAPM_DAC(wname, stname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
+#define SND_SOC_DAPM_ADC(wname, stname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
+
+/* dapm kcontrol types */
+#define SOC_DAPM_SINGLE(xname, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_volsw, \
+  .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
+  .private_value =  SOC_SINGLE_VALUE(reg, shift, mask, invert) }
+#define SOC_DAPM_DOUBLE(xname, reg, shift_left, shift_right, mask, invert, power) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .info = snd_soc_info_volsw, \
+  .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
+  .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) }
+#define SOC_DAPM_ENUM(xname, xenum) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_enum_double, \
+  .get = snd_soc_dapm_get_enum_double, .put = snd_soc_dapm_put_enum_double, \
+  .private_value = (unsigned long)&xenum }
+
+/* dapm stream operations */
+#define SND_SOC_DAPM_STREAM_NOP			0x0
+#define SND_SOC_DAPM_STREAM_START		0x1
+#define SND_SOC_DAPM_STREAM_STOP		0x2
+#define SND_SOC_DAPM_STREAM_SUSPEND		0x4
+#define SND_SOC_DAPM_STREAM_RESUME		0x8
+#define SND_SOC_DAPM_STREAM_PAUSE_PUSH	0x10
+#define SND_SOC_DAPM_STREAM_PAUSE_RELEASE	0x20  
+
+struct snd_soc_dapm_widget;
+enum snd_soc_dapm_type;
+struct snd_soc_dapm_path;
+struct snd_soc_dapm_pin;
+	
+/* dapm controls */
+int snd_soc_dapm_put_volsw(snd_kcontrol_t * kcontrol, 
+	snd_ctl_elem_value_t * ucontrol);
+int snd_soc_dapm_get_volsw(snd_kcontrol_t * kcontrol, 
+	snd_ctl_elem_value_t * ucontrol);
+int snd_soc_dapm_get_enum_double(snd_kcontrol_t * kcontrol, 
+	snd_ctl_elem_value_t * ucontrol);
+int snd_soc_dapm_put_enum_double(snd_kcontrol_t * kcontrol, 
+	snd_ctl_elem_value_t * ucontrol);
+int snd_soc_dapm_new_control(struct snd_soc_codec *codec, 
+	const struct snd_soc_dapm_widget *widget);
+
+/* dapm path setup */
+int snd_soc_dapm_connect_input(struct snd_soc_codec *codec, 
+	const char *target_name, const char *control_name, const char *src_name);
+int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec);
+void snd_soc_dapm_free(struct snd_soc_device *socdev);
+
+/* dapm events */
+int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, char *stream, 
+	int event);
+int snd_soc_dapm_codec_event(struct snd_soc_codec *codec, int event);
+int snd_soc_dapm_codec_mute(struct snd_soc_codec *codec, int mute);
+
+/* dapm sys fs - used by the core */
+int snd_soc_dapm_sys_add(struct device *dev);
+
+/* dapm audio endpoint control */
+int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec, 
+	char *pin, int status);
+int snd_soc_dapm_sync_endpoints(struct snd_soc_codec *codec);
+
+
+/* dapm widget types */
+enum snd_soc_dapm_type {
+	snd_soc_dapm_input = 0,
+	snd_soc_dapm_output,
+	snd_soc_dapm_mux,
+	snd_soc_dapm_mixer,
+	snd_soc_dapm_volume,
+	snd_soc_dapm_adc,
+	snd_soc_dapm_dac,
+	snd_soc_dapm_clock,
+	snd_soc_dapm_vref,
+	snd_soc_dapm_micbias,
+	snd_soc_dapm_mute,
+	snd_soc_dapm_mic,
+	snd_soc_dapm_hp,
+	snd_soc_dapm_spk,
+	snd_soc_dapm_line,
+	snd_soc_dapm_switch,
+};
+
+/* dapm audio path */
+struct snd_soc_dapm_path {
+	char *name;
+	char *long_name;
+	struct snd_soc_dapm_widget *in;
+	struct snd_soc_dapm_widget *out;
+	snd_kcontrol_t *kcontrol;
+	
+	u8 connect:1;	/* applies to widget inputs only */
+	u8 walked:1;	/* path has been walked */
+	
+	struct list_head list_in;
+	struct list_head list_out;
+	struct list_head list;
+};
+
+/* dapm widget */
+struct snd_soc_dapm_widget {
+	enum snd_soc_dapm_type id;
+	char *name;
+	char *sname;
+	struct snd_soc_codec *codec;
+	struct list_head list;
+	
+	/* dapm control */
+	short reg;						/* negative reg = no direct dapm */
+	unsigned char shift;
+	unsigned int value;				/* widget saved value */
+	unsigned char power:1;			/* block power status */
+	unsigned char invert:1;
+	unsigned char active:1;			/* active stream on DAC, ADC's */
+	unsigned char connected:1;		/* connected codec pin */
+	unsigned char new:1;			/* cnew complete */
+	unsigned char ext:1;			/* has external widgets */
+	unsigned char muted:1;			/* muted for pop reduction */
+	unsigned char suspend:1;		/* was active before suspend */
+	int (*ext_event)(struct snd_soc_dapm_widget*, int);
+	
+	/* kcontrols that relate to this widget */
+	int num_kcontrols;
+	const snd_kcontrol_new_t * kcontrols;
+	
+	/* widget input and outputs */
+	struct list_head inputs;
+	struct list_head outputs;
+};
+
+#endif
diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
index b0b3ea7..f389d16 100644
--- a/include/sound/ac97_codec.h
+++ b/include/sound/ac97_codec.h
@@ -407,6 +407,7 @@ struct snd_ac97_build_ops {
 
 struct snd_ac97_bus_ops {
 	void (*reset) (struct snd_ac97 *ac97);
+	void (*warm_reset) (struct snd_ac97 *ac97);
 	void (*write) (struct snd_ac97 *ac97, unsigned short reg, unsigned short val);
 	unsigned short (*read) (struct snd_ac97 *ac97, unsigned short reg);
 	void (*wait) (struct snd_ac97 *ac97);
diff --git a/sound/Makefile b/sound/Makefile
index f352bb2..213e267 100644
--- a/sound/Makefile
+++ b/sound/Makefile
@@ -4,7 +4,7 @@
 obj-$(CONFIG_SOUND) += soundcore.o
 obj-$(CONFIG_SOUND_PRIME) += oss/
 obj-$(CONFIG_DMASOUND) += oss/
-obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/
+obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/ soc/
 
 ifeq ($(CONFIG_SND),y)
   obj-y += last.o
diff --git a/sound/Kconfig b/sound/Kconfig
index b65ee47..76cfa2f 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -74,6 +74,8 @@ source "sound/sparc/Kconfig"
 
 source "sound/parisc/Kconfig"
 
+source "sound/soc/Kconfig"
+
 endmenu
 
 menu "Open Sound System"
diff --git a/Documentation/sound/alsa/SoC/dapm.txt b/Documentation/sound/alsa/SoC/dapm.txt
new file mode 100644
index 0000000..806b7d1
--- /dev/null
+++ b/Documentation/sound/alsa/SoC/dapm.txt
@@ -0,0 +1,60 @@
+Dynamic Audio Power Managment for Portable Devices
+==================================================
+
+Dynamic Audio Power Managment (DAPM) is designed to allow portable Linux devices
+to use the minimum amount of power within the audio subsystem at all times. It
+is independent of other kernel PM and as such, can easily co-exist with the 
+other PM systems.
+
+DAPM is also completely transparent to all user space applications as all power
+switching is done within the ASoC core. No code changes or recompiling are
+required for user space applications. DAPM makes power switching desicions based
+upon any audio stream (capture/playback) activity and audio mixer settings
+within the device.
+
+DAPM spans the whole machine. It covers power control within the entire audio
+subsystem, this includes internal codec power blocks and machine level power
+systems.
+
+There are 4 power domains within DAPM 
+
+   1. Codec domain - VREF, VMID
+      Usually controlled at codec probe/remove and suspend/resume, although 
+      can be set at stream time if power is not needed for sidetone, etc.
+      
+   2. Platform/Machine domain - physically connected inputs and outputs
+      Is platform/machine and user action specific, is set in the .asoundrc file and
+      by userspace e.g when HP are inserted
+      
+   3. Path domain - Internal codec path mixers
+      Are automatically set when mixer and mux settings are
+      changed by the user.
+      
+   4. Stream domain - DAC's and ADC's.
+      Enabled when stream playback/capture is started.  
+
+
+All DAPM power switching descisons are made automatically by consulting an audio
+routing map of the whole machine. This map is specific to each machine and 
+consists of the interconnections between every audio component (including
+internal codec components). All audio components that effect power are called
+widgets hereafter.
+
+Audio widgets fall into a number of types:-
+
+ o Mixer      - Mixes several analog signals into a single analog signal.
+ o Mux        - An analog switch that outputs only 1 of it's inputs.
+ o Volume     - A gain or attenuation widget. Also called a PGA.
+ o ADC        - Analog to Digital Converter
+ o DAC        - Digital to Analog Converter
+ o Switch     - An analog switch
+ o Input      - A codec input pin
+ o Output     - A codec output pin
+ o Headphone  - Headphone (and optional Jack)
+ o Mic        - Mic (and optional Jack)
+ o Line       - Line Input/Output (and optional Jack)
+ o Speaker    - Speaker
+
+Each widget is defined in include/sound/soc-dpm.h
+
+  
\ No newline at end of file
