diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig
index 3e5f69b..c0458a9 100644
--- a/arch/arm/mach-pxa/Kconfig
+++ b/arch/arm/mach-pxa/Kconfig
@@ -105,4 +105,8 @@ config PXA_SHARP_Cxx00
 	help
 	  Enable common support for Sharp Cxx00 models
 
+config PXA_SSP
+	tristate
+	help
+	  Enable support for PXA2xx SSP ports
 endif
diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile
index f609a0f..61902d6 100644
--- a/arch/arm/mach-pxa/Makefile
+++ b/arch/arm/mach-pxa/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_LEDS) += $(led-y)
 
 # Misc features
 obj-$(CONFIG_PM) += pm.o sleep.o
+obj-$(CONFIG_PXA_SSP) += ssp.o
 
 ifeq ($(CONFIG_PXA27x),y)
 obj-$(CONFIG_PM) += standby.o
diff --git a/arch/arm/mach-pxa/mainstone.c b/arch/arm/mach-pxa/mainstone.c
index 85fdb5b..033e1b7 100644
--- a/arch/arm/mach-pxa/mainstone.c
+++ b/arch/arm/mach-pxa/mainstone.c
@@ -20,6 +20,7 @@
 #include <linux/sched.h>
 #include <linux/bitops.h>
 #include <linux/fb.h>
+#include <sound/soc.h>
 
 #include <asm/types.h>
 #include <asm/setup.h>
@@ -152,15 +153,34 @@ static struct platform_device smc91x_dev
 
 static int mst_audio_startup(snd_pcm_substream_t *substream, void *priv)
 {
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		MST_MSCWR2 &= ~MST_MSCWR2_AC97_SPKROFF;
+		
+	if(pcm_i->type == SND_SOC_SSP && 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 mst_audio_shutdown(snd_pcm_substream_t *substream, void *priv)
 {
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		MST_MSCWR2 |= MST_MSCWR2_AC97_SPKROFF;
+		
+	if(pcm_i->type == SND_SOC_SSP && 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 long mst_audio_suspend_mask;
@@ -184,7 +204,7 @@ static pxa2xx_audio_ops_t mst_audio_ops 
 };
 
 static struct platform_device mst_audio_device = {
-	.name		= "pxa2xx-ac97",
+	.name		= "pxa2xx-audio",
 	.id		= -1,
 	.dev		= { .platform_data = &mst_audio_ops },
 };
diff --git a/arch/arm/mach-pxa/ssp.c b/arch/arm/mach-pxa/ssp.c
index 4d826c0..f707643 100644
--- a/arch/arm/mach-pxa/ssp.c
+++ b/arch/arm/mach-pxa/ssp.c
@@ -19,6 +19,8 @@
  *   22nd Aug 2003 Initial version.
  *   20th Dec 2004 Added ssp_config for changing port config without
  *                 closing the port.
+ *    4th Aug 2005 Added option to disable irq handler registration and 
+ *                 cleaned up irq and clock detection. 
  */
 
 #include <linux/module.h>
@@ -37,6 +39,26 @@
 
 #define PXA_SSP_PORTS 	3
 
+struct ssp_info_ {
+	int irq;
+	u32 clock;
+};
+
+/*
+ * SSP port clock and IRQ settings
+ */
+static const struct ssp_info_ ssp_info[PXA_SSP_PORTS] = {
+#if defined (CONFIG_PXA27x)
+	{IRQ_SSP,	CKEN23_SSP1},
+	{IRQ_SSP2,	CKEN3_SSP2},
+	{IRQ_SSP3,	CKEN4_SSP3},
+#else
+	{IRQ_SSP,	CKEN3_SSP},
+	{IRQ_NSSP,	CKEN9_NSSP},
+	{IRQ_ASSP,	CKEN10_ASSP},
+#endif
+};
+	
 static DECLARE_MUTEX(sem);
 static int use_count[PXA_SSP_PORTS] = {0, 0, 0};
 
@@ -210,9 +232,9 @@ int ssp_config(struct ssp_dev *dev, u32 
  *   %-EBUSY	if the resources are already in use
  *   %0		on success
  */
-int ssp_init(struct ssp_dev *dev, u32 port)
+int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags)
 {
-	int ret, irq;
+	int ret;
 
 	if (port > PXA_SSP_PORTS || port == 0)
 		return -ENODEV;
@@ -229,61 +251,20 @@ int ssp_init(struct ssp_dev *dev, u32 po
 		up(&sem);
 		return -EBUSY;
 	}
-
-	switch (port) {
-		case 1:
-			irq = IRQ_SSP;
-			break;
-#if defined (CONFIG_PXA27x)
-		case 2:
-			irq = IRQ_SSP2;
-			break;
-		case 3:
-			irq = IRQ_SSP3;
-			break;
-#else
-		case 2:
-			irq = IRQ_NSSP;
-			break;
-		case 3:
-			irq = IRQ_ASSP;
-			break;
-#endif
-		default:
-			return -ENODEV;
-	}
-
 	dev->port = port;
-
-	ret = request_irq(irq, ssp_interrupt, 0, "SSP", dev);
-	if (ret)
-		goto out_region;
-
+	
+	/* do we need to get irq */
+	if (!(init_flags & SSP_NO_IRQ)) {
+		ret = request_irq(ssp_info[port-1].irq, ssp_interrupt,
+				0, "SSP", dev);
+	    	if (ret)
+			goto out_region;
+	    	dev->irq = ssp_info[port-1].irq;
+	} else
+		dev->irq = 0;
+	
 	/* turn on SSP port clock */
-	switch (dev->port) {
-#if defined (CONFIG_PXA27x)
-		case 1:
-			pxa_set_cken(CKEN23_SSP1, 1);
-			break;
-		case 2:
-			pxa_set_cken(CKEN3_SSP2, 1);
-			break;
-		case 3:
-			pxa_set_cken(CKEN4_SSP3, 1);
-			break;
-#else
-		case 1:
-			pxa_set_cken(CKEN3_SSP, 1);
-			break;
-		case 2:
-			pxa_set_cken(CKEN9_NSSP, 1);
-			break;
-		case 3:
-			pxa_set_cken(CKEN10_ASSP, 1);
-			break;
-#endif
-	}
-
+	pxa_set_cken(ssp_info[port-1].clock, 1);
 	up(&sem);
 	return 0;
 
@@ -301,46 +282,17 @@ out_region:
  */
 void ssp_exit(struct ssp_dev *dev)
 {
-	int irq;
-
 	down(&sem);
 	SSCR0_P(dev->port) &= ~SSCR0_SSE;
 
-	/* find irq, save power and turn off SSP port clock */
-	switch (dev->port) {
-#if defined (CONFIG_PXA27x)
-		case 1:
-			irq = IRQ_SSP;
-			pxa_set_cken(CKEN23_SSP1, 0);
-			break;
-		case 2:
-			irq = IRQ_SSP2;
-			pxa_set_cken(CKEN3_SSP2, 0);
-			break;
-		case 3:
-			irq = IRQ_SSP3;
-			pxa_set_cken(CKEN4_SSP3, 0);
-			break;
-#else
-		case 1:
-			irq = IRQ_SSP;
-			pxa_set_cken(CKEN3_SSP, 0);
-			break;
-		case 2:
-			irq = IRQ_NSSP;
-			pxa_set_cken(CKEN9_NSSP, 0);
-			break;
-		case 3:
-			irq = IRQ_ASSP;
-			pxa_set_cken(CKEN10_ASSP, 0);
-			break;
-#endif
-		default:
-			printk(KERN_WARNING "SSP: tried to close invalid port\n");
-			return;
+    	if (dev->port > PXA_SSP_PORTS || dev->port == 0) {
+		printk(KERN_WARNING "SSP: tried to close invalid port\n");
+		return;
 	}
-
-	free_irq(irq, dev);
+	
+	pxa_set_cken(ssp_info[dev->port-1].clock, 0);
+	if (dev->irq)
+		free_irq(dev->irq, dev);
 	release_mem_region(__PREG(SSCR0_P(dev->port)), 0x2c);
 	use_count[dev->port - 1]--;
 	up(&sem);
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 21d55ed..2989820 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -95,4 +95,40 @@ config TOUCHSCREEN_HP600
 	  To compile this driver as a module, choose M here: the
 	  module will be called hp680_ts_input.
 
+config TOUCHSCREEN_WM97XX
+	tristate "Support for WM97xx AC97 touchscreen codecs"
+	depends SND_AC97_CODEC
+
+config TOUCHSCREEN_WM9713
+	tristate "WM9713 Touchscreen interface support"
+	depends on TOUCHSCREEN_WM97XX 
+	help
+	  Say Y here if you have the wm9713 touchscreen.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called wm9713.
+	
+config TOUCHSCREEN_WM9705
+	tristate "WM9705/12 Touchscreen interface support"
+	depends on TOUCHSCREEN_WM97XX 
+	help
+	  Say Y here if you have the wm9705/12 touchscreen.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called wm9705.
+	  
+config TOUCHSCREEN_WM97XX_PXA
+	tristate "WM97xx PXA accelerated touch"
+	depends on TOUCHSCREEN_WM97XX && ARCH_PXA
+	help
+	  Say Y here for continuous mode touch on the PXA
+
+	  If unsure, say N
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pxa-wm97xx
 endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 6842869..1d8c1d3 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -11,3 +11,7 @@ obj-$(CONFIG_TOUCHSCREEN_ELO)	+= elo.o
 obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
 obj-$(CONFIG_TOUCHSCREEN_MK712)	+= mk712.o
 obj-$(CONFIG_TOUCHSCREEN_HP600)	+= hp680_ts_input.o
+obj-$(CONFIG_TOUCHSCREEN_WM97XX)    += wm97xx-core.o
+obj-$(CONFIG_TOUCHSCREEN_WM9713)    += wm9713.o
+obj-$(CONFIG_TOUCHSCREEN_WM9705)    += wm9705.o
+obj-$(CONFIG_TOUCHSCREEN_WM97XX_PXA)   += pxa-wm97xx.o
diff --git a/drivers/input/touchscreen/pxa-wm97xx.c b/drivers/input/touchscreen/pxa-wm97xx.c
new file mode 100644
index 0000000..f9a338d
--- /dev/null
+++ b/drivers/input/touchscreen/pxa-wm97xx.c
@@ -0,0 +1,292 @@
+/*
+ * pxa-wm97xx.c  --  pxa2xx Continuous Touch screen driver for 
+ *                   Wolfson WM97xx AC97 Codecs.
+ *
+ * Copyright 2004 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ * Parts Copyright : Ian Molton <spyro@f2s.com>
+ *                   Andrew Zabolotny <zap@homelink.ru>
+ *
+ *  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.
+ *
+ *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
+ *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
+ *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+ *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
+ *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
+ *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  You should have received a copy of the  GNU General Public License along
+ *  with this program; if not, write  to the Free Software Foundation, Inc.,
+ *  675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Notes:
+ *     This code uses an API exposed by ac97_plugin_wm97xx to capture touch
+ *     data in a continuous manner on the Intel XScale archictecture
+ * 
+ *  Features:
+ *       - codecs supported:- WM9705, WM9712, WM9713
+ *       - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x
+ *
+ *  Revision history
+ *    18th Aug 2004   Initial version.
+ *    26th Jul 2005   Improved continous read back and added FIFO flushing.
+ * 
+ */
+
+#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/wm97xx.h>
+#include <asm/io.h>
+#include <asm/arch/pxa-regs.h>
+
+#define TS_NAME			"pxa_wm97xx"
+#define WM_TS_VERSION		"0.10"
+
+#define WM97XX_PXA_SLOT		5
+
+/*
+ * Debug
+ */ 
+#if 0
+#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg)
+#else	/* 
+ */
+#define dbg(format, arg...)
+#endif	/* 
+ */
+#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg)
+
+struct continuous {
+	u16 id;    /* codec id */
+	u8 code;   /* continuous code */
+	u8 reads;  /* number of coord reads per read cycle */
+	u32 speed; /* number of coords per second */
+};
+
+#define WM_READS(sp) ((sp / HZ) + 1)
+
+static const struct continuous cinfo[] = {
+	{WM9705_ID2, 0, WM_READS(94), 94},
+	{WM9705_ID2, 1, WM_READS(188), 188},
+	{WM9705_ID2, 2, WM_READS(375), 375},
+	{WM9705_ID2, 3, WM_READS(750), 750},
+	{WM9712_ID2, 0, WM_READS(94), 94},
+	{WM9712_ID2, 1, WM_READS(188), 188},
+	{WM9712_ID2, 2, WM_READS(375), 375},
+	{WM9712_ID2, 3, WM_READS(750), 750},
+	{WM9713_ID2, 0, WM_READS(94), 94},
+	{WM9713_ID2, 1, WM_READS(120), 120},
+	{WM9713_ID2, 2, WM_READS(154), 154},
+	{WM9713_ID2, 3, WM_READS(188), 188},
+};
+
+/* continuous speed index */
+static int sp_idx = 0;
+
+static struct wm97xx_platform_drv pxa_wm97xx;
+static u16 last = 0, tries = 0;
+
+/*
+ * Pen sampling frequency (Hz) in continuous mode.
+ */
+static int cont_rate = 200;
+module_param(cont_rate, int, 0);
+MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");
+
+/*
+ * Pen down detection.
+ * 
+ * This driver can either poll or use an interrupt to indicate a pen down
+ * event. If the irq request fails then it will fall back to polling mode.  
+ */
+static int pen_int = 1;
+module_param(pen_int, int, 0);
+MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)");
+
+/*
+ * Pressure readback.
+ * 
+ * Set to 1 to read back pen down pressure 
+ */
+static int pressure = 0;
+module_param(pressure, int, 0);
+MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)");
+
+
+/* flush AC97 slot 5 FIFO on pxa machines */
+#ifdef CONFIG_PXA27x
+static void pxa_wm97xx_pen_up (struct wm97xx* wm)
+{
+	set_current_state(TASK_INTERRUPTIBLE);
+	schedule_timeout(1);
+
+	while (MISR & (1 << 2))
+		MODR;
+}
+#else
+static void pxa_wm97xx_pen_up (struct wm97xx* wm)
+{
+	int count = 16;
+	set_current_state(TASK_INTERRUPTIBLE);
+	schedule_timeout(1);
+	
+	while (count < 16) {
+		MODR;
+		count--;
+	}
+}
+#endif
+
+static int pxa_wm97xx_pen_down (struct wm97xx* wm)
+{
+	u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;
+	int reads = 0;
+
+	/* data is never immediately available after pen down irq */
+	set_current_state(TASK_INTERRUPTIBLE);
+	schedule_timeout(1);
+	
+	if (tries > 5){
+		tries = 0;
+		return RC_PENUP;
+	}
+	
+	x = MODR;
+	if (x == last) {
+		tries++;
+		return RC_AGAIN;
+	}
+	last = x;
+	do {
+		if (reads)
+			x= MODR;
+		y= MODR;
+		if (pressure)
+			p = MODR;
+
+		/* are samples valid */
+		if ((x & 0x7000) != WM97XX_ADCSEL_X || 
+			(y & 0x7000) != WM97XX_ADCSEL_Y ||
+			(p & 0x7000) != WM97XX_ADCSEL_PRES)
+			goto up;
+		
+		/* coordinate is good */
+		tries = 0;
+		printk("x %x y %x p %x\n", x,y,p);
+		input_report_abs (&wm->input_dev, ABS_X, x & 0xfff);
+		input_report_abs (&wm->input_dev, ABS_Y, y & 0xfff);
+		input_report_abs (&wm->input_dev, ABS_PRESSURE, p & 0xfff);
+		input_sync (&wm->input_dev);
+		reads++;
+	} while (reads < cinfo[sp_idx].reads);
+up:
+	return RC_PENDOWN | RC_AGAIN;
+}
+
+static int pxa_wm97xx_probe(struct wm97xx* wm)
+{
+	int idx = 0;
+    
+	/* check we have a codec */
+	if (wm->ac97 == NULL)
+		return -ENODEV;
+	
+	/* Go you big red fire engine */
+	for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) {
+		if (wm->id != cinfo[idx].id)
+			continue;
+		sp_idx = idx;
+		if (cont_rate <= cinfo[idx].speed)
+			break;
+	}
+	pxa_wm97xx.acc_rate = cinfo[sp_idx].code;
+	info("pxa2xx accelerated touchscreen driver, %d samples (sec)", cinfo[sp_idx].speed);
+	  
+	/* codec specific irq config */
+	if (pen_int) {
+		switch (wm->id) {
+			case WM9705_ID2:
+				wm97xx_request_pen_irq(wm, IRQ_GPIO(4));
+				set_irq_type(IRQ_GPIO(4), IRQT_BOTHEDGE);
+				break;
+			case WM9712_ID2:
+			case WM9713_ID2:
+				/* enable pen down interrupt */
+				/* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */
+				if (wm97xx_request_pen_irq(wm, MAINSTONE_AC97_IRQ) == 0) {
+					wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,
+						WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_STICKY, WM97XX_GPIO_WAKE);
+					wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT,
+						WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_NOTSTICKY, WM97XX_GPIO_NOWAKE);
+				} else
+					pen_int = 0;
+				break;
+			default:
+				warn("pen down irq not supported on this device");
+				pen_int = 0;
+				break;
+		}
+	}
+	return 0;
+}
+
+static void pxa_wm97xx_remove(struct wm97xx* wm)
+{
+    /* codec specific deconfig */
+	if (pen_int) {
+		switch (wm->id & 0xffff) {
+			case WM9705_ID2:
+				wm97xx_free_pen_irq(wm);
+				break;
+			case WM9712_ID2:
+			case WM9713_ID2:
+				/* disable interrupt */
+				wm97xx_free_pen_irq(wm);
+				break;
+		}
+	}
+}
+
+static struct wm97xx_platform_drv pxa_wm97xx = {
+	.id = 0x4c00,
+	.mask = 0xff00,
+	.acc_slot = WM97XX_PXA_SLOT,
+	.acc_pen_down = pxa_wm97xx_pen_down,
+	.acc_pen_up = pxa_wm97xx_pen_up,
+	.probe = pxa_wm97xx_probe,
+	.remove = pxa_wm97xx_remove,
+};
+
+static int __init pxa_wm97xx_ts_init(void)
+{
+	wm97xx_register_platform_drv(&pxa_wm97xx);
+	return 0;
+}
+
+static void __exit pxa_wm97xx_ts_exit(void)
+{
+	wm97xx_unregister_platform_drv(&pxa_wm97xx);
+}
+
+/* Module information */
+MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
+MODULE_DESCRIPTION("wm97xx continuous touch driver for pxa2xx");
+MODULE_LICENSE("GPL");
+
+module_init(pxa_wm97xx_ts_init);
+module_exit(pxa_wm97xx_ts_exit);
diff --git a/drivers/input/touchscreen/wm9705.c b/drivers/input/touchscreen/wm9705.c
new file mode 100644
index 0000000..9d83bb5
--- /dev/null
+++ b/drivers/input/touchscreen/wm9705.c
@@ -0,0 +1,529 @@
+/*
+ * wm9705.c  --  Codec driver for Wolfson WM9705/WM9712 AC97 Codecs.
+ *
+ * Copyright 2003, 2004, 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ * Parts Copyright : Ian Molton <spyro@f2s.com>
+ *                   Andrew Zabolotny <zap@homelink.ru>
+ *                   Russell King <rmk@arm.linux.org.uk>
+ *
+ *  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.
+ *
+ *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
+ *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
+ *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+ *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
+ *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
+ *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  You should have received a copy of the  GNU General Public License along
+ *  with this program; if not, write  to the Free Software Foundation, Inc.,
+ *  675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/input.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+#include <linux/wm97xx.h>
+
+#define TS_NAME			"wm97xx"
+#define WM9705_VERSION		"0.49"
+#define DEFAULT_PRESSURE	0xb0c0
+
+/*
+ * Debug
+ */
+#if 0
+#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg)
+#else
+#define dbg(format, arg...)
+#endif
+#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg)
+
+/*
+ * Module parameters
+ */
+
+/*
+ * WM9705 - Set internal pull up for pen detect.
+ *
+ * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive)
+ * i.e. pull up resistance = 64k Ohms / rpu.
+ *
+ * Adjust this value if you are having problems with pen detect not
+ * detecting any down evenwm->
+ */
+static int rpu;
+module_param(rpu, int, 0);
+MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
+
+/*
+ * Set current used for pressure measurement.
+ *
+ * Set pil = 2 to use 400uA
+ *     pil = 1 to use 200uA and
+ *     pil = 0 to disable pressure measurement.
+ *
+ * This is used to increase the range of values returned by the adc
+ * when measureing touchpanel pressure.
+ */
+static int pil = 0;
+module_param(pil, int, 0);
+MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
+
+/*
+ * Set threshold for pressure measurement.
+ *
+ * Pen down pressure below threshold is ignored.
+ */
+static int pressure = DEFAULT_PRESSURE & 0xfff;
+module_param(pressure, int, 0);
+MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
+
+/*
+ * Set adc sample delay.
+ *
+ * For accurate touchpanel measurements, some settling time may be
+ * required between the switch matrix applying a voltage across the
+ * touchpanel plate and the ADC sampling the signal.
+ *
+ * This delay can be set by setting delay = n, where n is the array
+ * position of the delay in the array delay_table below.
+ * Long delays > 1ms are supported for completeness, but are not
+ * recommended.
+ */
+static int delay = 4;
+module_param(delay, int, 0);
+MODULE_PARM_DESC(delay, "Set adc sample delay.");
+
+/*
+ * WM9705 - Pen detect comparator threshold.
+ *
+ * 0 to Vmid in 15 steps, 0 = use zero power comparator with Vmid threshold
+ * i.e. 1 =  Vmid/15 threshold
+ *      15 =  Vmid/1 threshold
+ *
+ * Adjust this value if you are having problems with pen detect not
+ * detecting any down events.
+ */
+static int pdd = 8;
+module_param(pdd, int, 0);
+MODULE_PARM_DESC(pdd, "Set pen detect comparator threshold");
+
+/*
+ * WM9712 - Set five_wire = 1 to use a 5 wire touchscreen.
+ *
+ * NOTE: Five wire mode does not allow for readback of pressure.
+ */
+static int five_wire;
+module_param(five_wire, int, 0);
+MODULE_PARM_DESC(five_wire, "Set to '1' to use 5-wire touchscreen.");
+
+/*
+ * Touchscreen absolute values
+ *
+ * These parameters are used to help the input layer discard out of
+ * range readings and reduce jitter etc. 
+ * 
+ *   o min, max:- indicate the min and max values your touch screen returns
+ *   o fuzz:- use a higher number to reduce jitter
+ *  	
+ * The default values correspond to Mainstone II in QVGA mode
+ *	
+ * Please read 
+ * Documentation/input/input-programming.txt for more details.	
+ */
+
+static int abs_x[3] = {350,3900,5};
+module_param_array(abs_x, int, NULL, 0);
+MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
+
+static int abs_y[3] = {320,3750,40};
+module_param_array(abs_y, int, NULL, 0);
+MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
+
+static int abs_p[3] = {0,150,4};
+module_param_array(abs_p, int, NULL, 0);
+MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");
+
+/*
+ * ADC sample delay times in uS
+ */
+static const int delay_table[] = {
+	21,    // 1 AC97 Link frames
+	42,    // 2
+	84,    // 4
+	167,   // 8
+	333,   // 16
+	667,   // 32
+	1000,  // 48
+	1333,  // 64
+	2000,  // 96
+	2667,  // 128
+	3333,  // 160
+	4000,  // 192
+	4667,  // 224
+	5333,  // 256
+	6000,  // 288
+	0      // No delay, switch matrix always on
+};
+
+/*
+ * Delay after issuing a POLL command.
+ *
+ * The delay is 3 AC97 link frames + the touchpanel settling delay
+ */
+static inline void poll_delay(int d)
+{
+	udelay (3 * AC97_LINK_FRAME + delay_table [d]);
+}
+
+/*
+ * set up the physical settings of the WM9705
+ */
+static void init_wm9705_phy(struct wm97xx* wm)
+{
+	wm->dig1 = 0;
+	wm->dig2 = WM97XX_RPR;
+	
+	/*
+	* mute VIDEO and AUX as they share X and Y touchscreen
+	* inputs on the WM9705 
+	*/
+	wm97xx_reg_write(wm, AC97_AUX, 0x8000);
+	wm97xx_reg_write(wm, AC97_VIDEO, 0x8000);
+	
+	/* touchpanel pressure current*/
+	if  (pil == 2) {
+		wm->dig2 |= WM9705_PIL;
+		dbg("setting pressure measurement current to 400uA.");
+	} else if (pil) 
+		dbg("setting pressure measurement current to 200uA.");
+	if(!pil)
+		pressure = 0;
+	
+	/* polling mode sample settling delay */
+	if (delay!=4) {
+		if (delay < 0 || delay > 15) {
+		    dbg("supplied delay out of range.");
+		    delay = 4;
+		}
+	}
+	wm->dig1 &= 0xff0f;
+	wm->dig1 |= WM97XX_DELAY(delay);
+	dbg("setting adc sample delay to %d u Secs.", delay_table[delay]);
+	
+	/* WM9705 pdd */
+	wm->dig2 |= (pdd & 0x000f);
+	dbg("setting pdd to Vmid/%d", 1 - (pdd & 0x000f));
+	
+	wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig1);
+	wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig2);     
+}
+
+/*
+ * set up the physical settings of the WM9712
+ */
+static void init_wm9712_phy(struct wm97xx* wm)
+{
+	wm->dig1 = 0;
+	wm->dig2 = WM97XX_RPR | WM9712_RPU(1);
+	
+	/* WM9712 rpu */
+	if (rpu) {
+		wm->dig2 &= 0xffc0;
+		wm->dig2 |= WM9712_RPU(rpu);
+		dbg("setting pen detect pull-up to %d Ohms",64000 / rpu);
+	}
+	
+	/* touchpanel pressure current*/
+	if  (pil == 2) {
+		wm->dig2 |= WM9712_PIL;
+		dbg("setting pressure measurement current to 400uA.");
+	} else if (pil) 
+		dbg("setting pressure measurement current to 200uA.");
+	if(!pil)
+		pressure = 0;
+	
+	/* WM9712 five wire */
+	if (five_wire) {
+		wm->dig2 |= WM9712_45W;
+		dbg("setting 5-wire touchscreen mode.");
+	}
+	
+	/* polling mode sample settling delay */
+	if (delay!=4) {
+		if (delay < 0 || delay > 15) {
+		    dbg("supplied delay out of range.");
+		    delay = 4;
+		}
+	}
+	wm->dig1 &= 0xff0f;
+	wm->dig1 |= WM97XX_DELAY(delay);
+	dbg("setting adc sample delay to %d u Secs.", delay_table[delay]);
+	
+	wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig1);
+	wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig2);     
+}
+
+static void wm97xx_digitiser_ioctl(struct wm97xx* wm, int cmd)
+{
+	u16 val = 0;
+	
+	switch(cmd) {
+		case WM97XX_DIG_START:
+			val = wm->dig2 | WM97XX_PRP_DET_DIG;
+			wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig2 = val);
+			wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
+			break;
+		case WM97XX_DIG_STOP:
+			val = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER2);
+			wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, val & ~WM97XX_PRP_DET_DIG);
+			break;
+		case WM97XX_DIG_SAVE:
+			wm->dig1 = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1);
+			wm->dig2 = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER2);
+			break;
+		case WM97XX_DIG_RESTORE:
+			wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig1);
+			wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig2);
+			break;
+		case WM97XX_AUX_PREPARE:
+			wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0);
+			wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG);
+			break;
+		case WM97XX_PHY_INIT:
+			if (wm->id == WM9705_ID2)
+				init_wm9705_phy(wm);
+			else
+				init_wm9712_phy(wm);
+			break;
+	}
+}
+
+static inline int is_pden (struct wm97xx* wm)
+{
+	int pden = 0;
+		
+	switch (wm->id) {
+		case WM9705_ID2:
+			pden = wm->dig2 & WM9705_PDEN;
+			break;
+		case WM9712_ID2:
+			pden = wm->dig2 & WM9712_PDEN;
+			break;
+	}
+	return pden;
+}
+
+/*
+ * Read a sample from the WM9705 adc in polling mode.
+ */
+static int wm9705_poll_sample (struct wm97xx* wm, int adcsel, int *sample)
+{
+	int timeout = 5 * delay;
+	
+	if (!wm->pen_probably_down) {
+		u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
+		if (!(data & WM97XX_PEN_DOWN))
+			return RC_PENUP;
+		wm->pen_probably_down = 1;
+	}
+	
+	/* set up digitiser */
+	if (adcsel & 0x8000)
+		adcsel = ((adcsel & 0x7fff) + 3) << 12;
+	wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, adcsel | WM97XX_POLL | WM97XX_DELAY(delay));
+	
+	/* wait 3 AC97 time slots + delay for conversion */
+	poll_delay (delay);
+	
+	/* wait for POLL to go low */
+	while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL) && timeout) {
+		udelay(AC97_LINK_FRAME);
+		timeout--;
+	}
+	
+	if (timeout <= 0) {
+		/* If PDEN is set, we can get a timeout when pen goes up */
+		if (is_pden(wm))
+			wm->pen_probably_down = 0;
+		else
+			dbg ("adc sample timeout");
+		return 0;
+	}
+	
+	*sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
+	
+	/* check we have correct sample */
+	if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) {
+		dbg ("adc wrong sample, read %x got %x", adcsel,
+		*sample & WM97XX_ADCSEL_MASK);
+		return 0;
+	}
+	
+	if (!(*sample & WM97XX_PEN_DOWN)) {
+		wm->pen_probably_down = 0;
+		return RC_PENUP;
+	}
+	
+	return RC_VALID;
+}
+
+/*
+ * Sample the WM9713 touchscreen in polling mode
+ */
+static int wm9705_poll_touch(struct wm97xx* wm, struct wm97xx_data *data)
+{
+	int rc;
+	
+	if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_X, &data->x)) != RC_VALID)
+		return rc;
+	if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y)) != RC_VALID)
+		return rc;
+	if (pil && !five_wire) {
+		if ((rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_PRES, &data->p)) != RC_VALID)
+			return rc;
+	} else
+		data->p = DEFAULT_PRESSURE;
+	
+	return RC_VALID;
+}
+
+/*
+ * Enable WM9705 continuous mode, i.e. touch data is streamed across an AC97 slot
+ */
+static void wm9705_acc_enable (struct wm97xx* wm, int enable)
+{
+	u16 dig1, dig2;
+	
+	dig1 = wm->dig1;
+	dig2 = wm->dig2;
+	
+	if (enable) {
+		/* continous mode */
+		dbg("Enabling continous mode");
+		dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK |
+			WM97XX_DELAY_MASK | WM97XX_SLT_MASK);
+		dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN |
+			WM97XX_DELAY (delay) |
+			WM97XX_SLT (wm->acc->acc_slot) |
+			WM97XX_RATE (wm->acc->acc_rate);
+		if (pil)
+			dig1 |= WM97XX_ADCSEL_PRES;
+		if (wm->id == WM9712_ID2)
+			dig2 |= WM9712_PDEN;
+		else
+			dig2 |= WM9705_PDEN;
+	} else {
+		dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN);
+		if (wm->id == WM9712_ID2)
+			dig2 &= ~WM9712_PDEN;
+		else
+			dig2 &= ~WM9705_PDEN;
+	}
+	
+	wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig1 = dig1);
+	wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig2 = dig2);
+}
+
+static int wm9705_probe(struct wm97xx *wm)
+{
+	memset (&wm->input_dev, 0, sizeof (struct input_dev));
+	if (wm->id == WM9705_ID2) {
+		wm->input_dev.name = "wm9705 touchscreen";
+		info("detected a wm9705 codec");
+	} else {
+		wm->input_dev.name = "wm9712 touchscreen";
+		info("detected a wm9712 codec");
+	}
+	wm->input_dev.open = wm97xx_ts_input_open;
+	wm->input_dev.close = wm97xx_ts_input_close;
+	set_bit(EV_ABS, wm->input_dev.evbit);
+	set_bit(ABS_X, wm->input_dev.absbit);
+	set_bit(ABS_Y, wm->input_dev.absbit);
+	set_bit(ABS_PRESSURE, wm->input_dev.absbit);
+	wm->input_dev.absmax[ABS_X] = abs_x[1];
+	wm->input_dev.absmax[ABS_Y] = abs_y[1];
+	wm->input_dev.absmax[ABS_PRESSURE] = abs_p[1];
+	wm->input_dev.absmin[ABS_X] = abs_x[0];
+	wm->input_dev.absmin[ABS_Y] = abs_y[0];
+	wm->input_dev.absmin[ABS_PRESSURE] = abs_p[0];
+	wm->input_dev.absfuzz[ABS_X] = abs_x[2];
+	wm->input_dev.absfuzz[ABS_Y] = abs_y[2];
+	wm->input_dev.absfuzz[ABS_PRESSURE] = abs_p[2];
+	wm->input_dev.private = wm;
+	input_register_device(&wm->input_dev);
+	
+	/* set up physical characteristics */
+	if (wm->id == WM9705_ID2)
+		init_wm9705_phy(wm);
+	else
+		init_wm9712_phy(wm);
+	
+	return 0;
+}
+
+static void wm9705_remove(struct  wm97xx *wm)
+{
+	if(wm->id) {
+		input_unregister_device(&wm->input_dev);
+		wm->id = 0;
+	}
+}
+
+static struct wm97xx_codec_drv wm9705_codec = {
+	.id = WM9705_ID2,
+	.probe = wm9705_probe,
+	.remove = wm9705_remove,
+	.poll_sample = wm9705_poll_sample,
+	.poll_touch = wm9705_poll_touch,
+	.acc_enable = wm9705_acc_enable,
+	.digitiser_ioctl = wm97xx_digitiser_ioctl,
+};
+
+static struct wm97xx_codec_drv wm9712_codec = {
+	.id = WM9712_ID2,
+	.probe = wm9705_probe,
+	.remove = wm9705_remove,
+	.poll_sample = wm9705_poll_sample,
+	.poll_touch = wm9705_poll_touch,
+	.acc_enable = wm9705_acc_enable,
+	.digitiser_ioctl = wm97xx_digitiser_ioctl,
+};
+
+static int __init wm9705_ts_init(void)
+{
+	wm97xx_register_codec_drv(&wm9705_codec);
+	wm97xx_register_codec_drv(&wm9712_codec);
+	return 0;
+}
+
+static void __exit wm9705_ts_exit(void)
+{
+	wm97xx_unregister_codec_drv(&wm9705_codec);
+	wm97xx_unregister_codec_drv(&wm9712_codec);
+}
+
+/* Module information */
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("WM9705/12 Touch Screen Driver");
+MODULE_LICENSE("GPL");
+
+module_init(wm9705_ts_init);
+module_exit(wm9705_ts_exit);
diff --git a/drivers/input/touchscreen/wm9713.c b/drivers/input/touchscreen/wm9713.c
new file mode 100644
index 0000000..1d9b211
--- /dev/null
+++ b/drivers/input/touchscreen/wm9713.c
@@ -0,0 +1,432 @@
+/*
+ * wm9713.c  --  Codec driver for Wolfson WM9713 AC97 Codec.
+ *
+ * Copyright 2003, 2004, 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ * Parts Copyright : Ian Molton <spyro@f2s.com>
+ *                   Andrew Zabolotny <zap@homelink.ru>
+ *                   Russell King <rmk@arm.linux.org.uk>
+ *
+ *  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.
+ *
+ *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
+ *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
+ *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+ *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
+ *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
+ *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAand/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.
+ *
+ *  You should have received a copy of the  GNU General Public License along
+ *  with this program; if not, write  to the Free Software Foundation, Inc.,
+ *  675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/input.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+#include <linux/wm97xx.h>
+
+#define TS_NAME			"wm97xx"
+#define WM9713_VERSION		"0.49"
+#define DEFAULT_PRESSURE	0xb0c0
+
+/*
+ * Debug
+ */
+#if 0
+#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg)
+#else
+#define dbg(format, arg...)
+#endif
+#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg)
+
+/*
+ * Module parameters
+ */
+
+/*
+ * WM9713 - Set internal pull up for pen detect.
+ *
+ * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive)
+ * i.e. pull up resistance = 64k Ohms / rpu.
+ *
+ * Adjust this value if you are having problems with pen detect not
+ * detecting any down evenwm->
+ */
+static int rpu;
+module_param(rpu, int, 0);
+MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
+
+/*
+ * Set current used for pressure measurement.
+ *
+ * Set pil = 2 to use 400uA
+ *     pil = 1 to use 200uA and
+ *     pil = 0 to disable pressure measurement.
+ *
+ * This is used to increase the range of values returned by the adc
+ * when measureing touchpanel pressure.
+ */
+static int pil = 0;
+module_param(pil, int, 0);
+MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
+
+/*
+ * Set threshold for pressure measurement.
+ *
+ * Pen down pressure below threshold is ignored.
+ */
+static int pressure = DEFAULT_PRESSURE & 0xfff;
+module_param(pressure, int, 0);
+MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
+
+/*
+ * Set adc sample delay.
+ *
+ * For accurate touchpanel measurements, some settling time may be
+ * required between the switch matrix applying a voltage across the
+ * touchpanel plate and the ADC sampling the signal.
+ *
+ * This delay can be set by setting delay = n, where n is the array
+ * position of the delay in the array delay_table below.
+ * Long delays > 1ms are supported for completeness, but are not
+ * recommended.
+ */
+static int delay = 4;
+module_param(delay, int, 0);
+MODULE_PARM_DESC(delay, "Set adc sample delay.");
+
+/*
+ * Touchscreen absolute values
+ *
+ * These parameters are used to help the input layer discard out of
+ * range readings and reduce jitter etc. 
+ * 
+ *   o min, max:- indicate the min and max values your touch screen returns
+ *   o fuzz:- use a higher number to reduce jitter
+ *  	
+ * The default values correspond to Mainstone II in QVGA mode
+ *	
+ * Please read 
+ * Documentation/input/input-programming.txt for more details.	
+ */
+
+static int abs_x[3] = {350,3900,5};
+module_param_array(abs_x, int, NULL, 0);
+MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
+
+static int abs_y[3] = {320,3750,40};
+module_param_array(abs_y, int, NULL, 0);
+MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
+
+static int abs_p[3] = {0,150,4};
+module_param_array(abs_p, int, NULL, 0);
+MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");
+
+/*
+ * ADC sample delay times in uS
+ */
+static const int delay_table[] = {
+	21,    // 1 AC97 Link frames
+	42,    // 2
+	84,    // 4
+	167,   // 8
+	333,   // 16
+	667,   // 32
+	1000,  // 48
+	1333,  // 64
+	2000,  // 96
+	2667,  // 128
+	3333,  // 160
+	4000,  // 192
+	4667,  // 224
+	5333,  // 256
+	6000,  // 288
+	0      // No delay, switch matrix always on
+};
+
+/*
+ * Delay after issuing a POLL command.
+ *
+ * The delay is 3 AC97 link frames + the touchpanel settling delay
+ */
+static inline void poll_delay(int d)
+{
+	udelay (3 * AC97_LINK_FRAME + delay_table [d]);
+}
+
+/*
+ * set up the physical settings of the WM9713 
+ */
+static void init_wm9713_phy(struct wm97xx* wm)
+{
+	u16 dig1 = 0, dig2, dig3;
+	
+	/* default values */
+	dig2 = WM97XX_DELAY(4) | WM97XX_SLT(5);
+	dig3= WM9712_RPU(1);
+      
+	/* rpu */
+	if (rpu) {
+		dig3 &= 0xffc0;
+		dig3 |= WM9712_RPU(rpu);
+		info("setting pen detect pull-up to %d Ohms",64000 / rpu);
+	}
+      
+	/* touchpanel pressure */
+	if (pil == 2) {
+		dig3 |= WM9712_PIL;
+		info("setting pressure measurement current to 400uA.");
+	} else if (pil) 
+		info ("setting pressure measurement current to 200uA.");
+	if(!pil)
+		pressure = 0;
+      
+	/* sample settling delay */
+	if (delay!=4) {
+		if (delay < 0 || delay > 15) {
+			info ("supplied delay out of range.");
+			delay = 4;
+			info("setting adc sample delay to %d u Secs.", delay_table[delay]);
+		}
+	}
+	dig2 &= 0xff0f;
+	dig2 |= WM97XX_DELAY(delay);
+
+	wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig1 = dig1);
+	wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig2 = dig2);
+	wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig3 = dig3);
+	wm97xx_reg_write(wm, AC97_GPIO_STICKY, 0x0);
+}
+
+static void wm9713_digitiser_ioctl(struct wm97xx* wm, int cmd)
+{
+	u16 val = 0;
+	
+	switch(cmd){
+		case WM97XX_DIG_START:	
+			val = wm97xx_reg_read(wm, AC97_EXTENDED_MID);
+			wm97xx_reg_write(wm, AC97_EXTENDED_MID, val & 0x7fff);
+			val = wm97xx_reg_read(wm, AC97_WM9713_DIG3);
+			wm97xx_reg_write(wm, AC97_WM9713_DIG3, val | WM97XX_PRP_DET_DIG);
+			wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
+			break;
+		case WM97XX_DIG_STOP:
+			val = wm97xx_reg_read(wm, AC97_WM9713_DIG3);
+			wm97xx_reg_write(wm, AC97_WM9713_DIG3, val & ~WM97XX_PRP_DET_DIG);
+			val = wm97xx_reg_read(wm, AC97_EXTENDED_MID);
+			wm97xx_reg_write(wm, AC97_EXTENDED_MID, val | 0x8000);
+			break;
+		case WM97XX_DIG_SAVE:
+			wm->dig1 =wm97xx_reg_read(wm, AC97_WM9713_DIG1);
+			wm->dig2 =wm97xx_reg_read(wm, AC97_WM9713_DIG2);
+			wm->dig3 =wm97xx_reg_read(wm, AC97_WM9713_DIG3);
+			break;
+		case WM97XX_DIG_RESTORE:
+			wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig1);
+			wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig2);
+			wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig3);
+			break;
+		case WM97XX_AUX_PREPARE:
+			wm97xx_reg_write(wm, AC97_WM9713_DIG1, 0);
+			wm97xx_reg_write(wm, AC97_WM9713_DIG2, 0);
+			wm97xx_reg_write(wm, AC97_WM9713_DIG3, WM97XX_PRP_DET_DIG);
+			break;
+		case WM97XX_PHY_INIT:
+			init_wm9713_phy(wm);
+			break;
+	}
+}
+
+static inline int is_pden (struct wm97xx* wm)
+{
+	return wm->dig3 & WM9713_PDEN;
+}
+
+/*
+ * Read a sample from the WM9713 adc in polling mode.
+ */
+static int wm9713_poll_sample (struct wm97xx* wm, int adcsel, int *sample)
+{
+	u16 dig1;
+	int timeout = 5 * delay;
+
+	if (!wm->pen_probably_down) {
+		u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
+		if (!(data & WM97XX_PEN_DOWN))
+			return RC_PENUP;
+		wm->pen_probably_down = 1;
+	}
+
+	/* set up digitiser */
+	if (adcsel & 0x8000)
+		adcsel = 1 << ((adcsel & 0x7fff) + 3);
+	
+	dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1);
+	dig1 &= ~WM9713_ADCSEL_MASK; 
+	wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1 | adcsel |WM9713_POLL); 
+
+	/* wait 3 AC97 time slots + delay for conversion */
+	poll_delay(delay);
+
+	/* wait for POLL to go low */
+	while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL) && timeout) {
+		udelay(AC97_LINK_FRAME);
+		timeout--;
+	}
+	
+	if (timeout <= 0) {
+		/* If PDEN is set, we can get a timeout when pen goes up */
+		if (is_pden (wm))
+			wm->pen_probably_down = 0;
+		else
+			dbg ("adc sample timeout");
+		return RC_PENUP;
+	}
+	*sample =wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
+
+	/* check we have correct sample */
+	if ((*sample & WM97XX_ADCSRC_MASK) != generic_ffs(adcsel >> 1) << 12) {
+		dbg ("adc wrong sample, read %x got %x", adcsel,
+		     *sample & WM97XX_ADCSRC_MASK);
+		return RC_PENUP;
+	}
+
+	if (!(*sample & WM97XX_PEN_DOWN)) {
+		wm->pen_probably_down = 0;
+		return RC_PENUP;
+	}
+
+	return RC_VALID;
+}
+
+/*
+ * Sample the WM9713 touchscreen in polling mode
+ */
+static int wm9713_poll_touch(struct wm97xx* wm, struct wm97xx_data *data)
+{
+	int rc;
+
+	if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_X, &data->x)) != RC_VALID)
+		return rc;
+	if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_Y, &data->y)) != RC_VALID)
+		return rc;
+	if (pil) {
+		if ((rc = wm9713_poll_sample(wm, WM9713_ADCSEL_PRES, &data->p)) != RC_VALID)
+			return rc;
+	} else
+		data->p = DEFAULT_PRESSURE;
+
+	return RC_VALID;
+}
+
+/*
+ * Enable WM9713 continuous mode, i.e. touch data is streamed across an AC97 slot
+ */
+static void wm9713_acc_enable (struct wm97xx* wm, int enable)
+{
+	u16 dig1, dig2, dig3;
+
+	dig1 = wm->dig1;
+	dig2 = wm->dig2;
+	dig3 = wm->dig3;
+
+	if (enable) {
+		/* continous mode */
+		dig1 &= ~WM9713_ADCSEL_MASK;
+		dig1 |= WM9713_CTC | WM9713_COO | WM9713_ADCSEL_X | WM9713_ADCSEL_Y; 
+        if (pil)
+		dig1 |= WM9713_ADCSEL_PRES;
+		dig2 &= ~(WM97XX_DELAY_MASK | WM97XX_SLT_MASK  | WM97XX_CM_RATE_MASK);
+		dig2 |= WM97XX_SLEN | WM97XX_DELAY (delay) | 
+		WM97XX_SLT (wm->acc->acc_slot) | WM97XX_RATE (wm->acc->acc_rate);
+		dig3 |= WM9713_PDEN;
+	} else {
+		dig1 &= ~(WM9713_CTC | WM9713_COO);
+		dig2 &= ~WM97XX_SLEN;
+		dig3 &= ~WM9713_PDEN;
+	}
+
+	wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig1 = dig1);
+	wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig2 = dig2);
+	wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig3 = dig3);
+}
+
+static int wm9713_probe(struct wm97xx *wm)
+{
+	memset (&wm->input_dev, 0, sizeof (struct input_dev));
+	info("detected a wm9713 codec");
+	wm->input_dev.name = "wm9713 touchscreen";
+	wm->input_dev.open = wm97xx_ts_input_open;
+	wm->input_dev.close = wm97xx_ts_input_close;
+	set_bit(EV_ABS, wm->input_dev.evbit);
+	set_bit(ABS_X, wm->input_dev.absbit);
+	set_bit(ABS_Y, wm->input_dev.absbit);
+	set_bit(ABS_PRESSURE, wm->input_dev.absbit);
+	wm->input_dev.absmax[ABS_X] = abs_x[1];
+	wm->input_dev.absmax[ABS_Y] = abs_y[1];
+	wm->input_dev.absmax[ABS_PRESSURE] = abs_p[1];
+	wm->input_dev.absmin[ABS_X] = abs_x[0];
+	wm->input_dev.absmin[ABS_Y] = abs_y[0];
+	wm->input_dev.absmin[ABS_PRESSURE] = abs_p[0];
+	wm->input_dev.absfuzz[ABS_X] = abs_x[2];
+	wm->input_dev.absfuzz[ABS_Y] = abs_y[2];
+	wm->input_dev.absfuzz[ABS_PRESSURE] = abs_p[2];
+	wm->input_dev.private = wm;
+	input_register_device(&wm->input_dev);
+
+	/* set up physical characteristics */
+	init_wm9713_phy(wm);
+	return 0;
+}
+
+static void wm9713_remove(struct wm97xx *wm)
+{
+	if(wm->id) {
+		input_unregister_device(&wm->input_dev);
+		wm->id = 0;
+	}
+}
+
+static struct wm97xx_codec_drv wm9713_codec = {
+	.id = 	WM9713_ID2,
+	.probe = wm9713_probe,
+	.remove = wm9713_remove,
+	.poll_sample = wm9713_poll_sample,
+	.poll_touch = wm9713_poll_touch,
+	.acc_enable = wm9713_acc_enable,
+	.digitiser_ioctl = wm9713_digitiser_ioctl,
+};
+
+static int __init wm9713_ts_init(void)
+{
+	wm97xx_register_codec_drv(&wm9713_codec);
+	return 0;
+}
+
+static void __exit wm9713_ts_exit(void)
+{
+	wm97xx_unregister_codec_drv(&wm9713_codec);
+}
+
+/* Module information */
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("WM9713 Touch Screen Driver");
+MODULE_LICENSE("GPL");
+
+module_init(wm9713_ts_init);
+module_exit(wm9713_ts_exit);
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
new file mode 100644
index 0000000..5b0a305
--- /dev/null
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -0,0 +1,939 @@
+/*
+ * wm97xx-core.c  --  Touch screen driver core for Wolfson WM9705, WM9712
+ *                           and WM9713 AC97 Codecs.
+ *
+ * Copyright 2003, 2004, 2005 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ * Parts Copyright : Ian Molton <spyro@f2s.com>
+ *                   Andrew Zabolotny <zap@homelink.ru>
+ *                   Russell King <rmk@arm.linux.org.uk>
+ *
+ *  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.
+ *
+ *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
+ *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
+ *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+ *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
+ *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
+ *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  You should have received a copy of the  GNU General Public License along
+ *  with this program; if not, write  to the Free Software Foundation, Inc.,
+ *  675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Notes:
+ *
+ *  Features:
+ *       - supports WM9705, WM9712, WM9713
+ *       - polling mode
+ *       - continuous mode (arch-dependent)
+ *       - adjustable rpu/dpp settings
+ *       - adjustable pressure current
+ *       - adjustable sample settle delay
+ *       - 4 and 5 wire touchscreens (5 wire is WM9712 only)
+ *       - pen down detection
+ *       - battery monitor
+ *       - sample AUX adc's
+ *       - power management
+ *       - codec GPIO
+ *       - codec event notification
+ *
+ *  Revision history
+ *    7th May 2003   Initial version.
+ *    6th June 2003  Added non module support and AC97 registration.
+ *   18th June 2003  Added AUX adc sampling.
+ *   23rd June 2003  Did some minimal reformatting, fixed a couple of
+ *                   codec_seming bugs and noted a race to fix.
+ *   24th June 2003  Added power management and fixed race condition.
+ *   10th July 2003  Changed to a misc device.
+ *   31st July 2003  Moved TS_EVENT and TS_CAL to wm97xx.h
+ *    8th Aug  2003  Added option for read() calling wm97xx_sample_touch()
+ *                   because some ac97_read/ac_97_write call schedule()
+ *    7th Nov  2003  Added Input touch event interface, stanley.cai@intel.com
+ *   13th Nov  2003  Removed h3600 touch interface, added interrupt based
+ *                   pen down notification and implemented continous mode
+ *                   on XScale arch.
+ *   16th Nov  2003  Ian Molton <spyro@f2s.com>
+ *                   Modified so that it suits the new 2.6 driver model.
+ *   25th Jan  2004  Andrew Zabolotny <zap@homelink.ru>
+ *                   Implemented IRQ-driven pen down detection, implemented
+ *                   the private API meant to be exposed to platform-specific
+ *                   drivers, reorganized the driver so that it supports
+ *                   an arbitrary number of devices.
+ *    1st Feb  2004  Moved continuous mode handling to a separate
+ *                   architecture-dependent file. For now only PXA
+ *                   built-in AC97 controller is supported (pxa-ac97-wm97xx.c).
+ *    11th Feb 2004  Reduced CPU usage by keeping a cached copy of both
+ *                   digitizer registers instead of reading them every time.
+ *                   A reorganization of the whole code for better
+ *                   error handling.
+ *    17th Apr 2004  Added BMON support.
+ *    17th Nov 2004  Added codec GPIO, codec event handling (real and virtual
+ *                   GPIOs) and 2.6 power management. 
+ *    29th Nov 2004  Added WM9713 support.
+ *     4th Jul 2005  Moved codec specific code out to seperate files.
+ */  
+    
+#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/string.h>
+#include <linux/proc_fs.h>
+#include <linux/pm.h>
+#include <linux/interrupt.h>
+#include <linux/bitops.h>
+#include <linux/workqueue.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/wm97xx.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+    
+#define TS_NAME			"wm97xx"
+#define WM_CORE_VERSION		"0.50"
+#define DEFAULT_PRESSURE	0xb0c0
+
+static DECLARE_MUTEX(codec_sem);
+static DECLARE_MUTEX(drv_sem);
+static LIST_HEAD(codecs);
+static LIST_HEAD(codec_drivers);
+static LIST_HEAD(platform_drivers);
+
+/*
+ * WM97xx - enable/disable AUX ADC sysfs 
+ */
+static int aux_sys = 1;
+module_param(aux_sys, int, 0);
+MODULE_PARM_DESC(aux_sys, "enable AUX ADC sysfs entries");
+
+/*
+ * WM97xx - enable/disable codec status sysfs 
+ */
+static int status_sys = 1;
+module_param(status_sys, int, 0);
+MODULE_PARM_DESC(status_sys, "enable codec status sysfs entries");
+
+/*
+ * Debug
+ */ 
+#if 0
+#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg)
+#else	/* 
+ */
+#define dbg(format, arg...)
+#endif	/* 
+ */
+#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg)
+
+inline unsigned int wm97xx_reg_read(struct wm97xx *wm, unsigned int reg) 
+{    
+	if (wm->ac97)
+		return wm->ac97->bus->ops->read(wm->ac97, reg);
+	else
+		return -1;
+}
+
+inline void wm97xx_reg_write(struct wm97xx *wm, unsigned int reg, unsigned int val) 
+{
+	if (wm->ac97)
+		wm->ac97->bus->ops->write(wm->ac97, reg, val);
+}
+
+
+/**
+ *	wm97xx_read_aux_adc - Read the aux adc.
+ *	@wm: wm97xx device.
+ *  @adcsel: codec ADC to be read
+ *
+ *	Reads the selected AUX ADC.
+ */ 
+
+int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel) 
+{
+	int power_adc = 0, auxval;
+	u16 power = 0;
+
+	/* get codec */ 
+	down(&codec_sem);
+
+	/* When the touchscreen is not in use, we may have to power up the AUX ADC
+	 * before we can use sample the AUX inputs->
+	 */ 
+	if (wm->id == WM9713_ID2 && 
+	    (power = wm97xx_reg_read(wm, AC97_EXTENDED_MID)) & 0x8000) {
+		power_adc = 1;
+		wm97xx_reg_write(wm, AC97_EXTENDED_MID, power & 0x7fff);
+	}
+
+	/* Prepare the codec for AUX reading */ 
+	wm->codec->digitiser_ioctl(wm, WM97XX_DIG_SAVE);
+	wm->codec->digitiser_ioctl(wm, WM97XX_AUX_PREPARE);
+
+	/* Turn polling mode on to read AUX ADC */ 
+	wm->pen_probably_down = 1;
+	wm->codec->poll_sample(wm, adcsel, &auxval);
+    
+	if (power_adc)
+		wm97xx_reg_write(wm, AC97_EXTENDED_MID, power | 0x8000);
+    
+	wm->pen_probably_down = 0;
+	wm->codec->digitiser_ioctl(wm, WM97XX_DIG_RESTORE);
+    
+	up(&codec_sem);
+	return auxval & 0xfff;
+}
+
+#define WM97XX_AUX_ATTR(name,input) \
+static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf)   \
+{ \
+	struct wm97xx *wm = (struct wm97xx*)dev->driver_data; \
+	return sprintf(buf, "%d\n", wm97xx_read_aux_adc(wm, input)); \
+} \
+static DEVICE_ATTR(name, 0444, name##_show, NULL)
+		     
+WM97XX_AUX_ATTR(aux1, WM97XX_AUX_ID1);
+WM97XX_AUX_ATTR(aux2, WM97XX_AUX_ID2);
+WM97XX_AUX_ATTR(aux3, WM97XX_AUX_ID3);
+WM97XX_AUX_ATTR(aux4, WM97XX_AUX_ID4);
+
+#define WM97XX_STATUS_ATTR(name) \
+static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf)   \
+{ \
+	struct wm97xx *wm = (struct wm97xx*)dev->driver_data; \
+	return sprintf(buf, "%d\n", wm97xx_reg_read(wm, AC97_GPIO_STATUS)); \
+} \
+static DEVICE_ATTR(name, 0444, name##_show, NULL)
+		     
+WM97XX_STATUS_ATTR(status);
+
+static int wm97xx_sys_add(struct device *dev) 
+{
+	if (aux_sys) {
+		device_create_file(dev, &dev_attr_aux1);    
+		device_create_file(dev, &dev_attr_aux2);
+		device_create_file(dev, &dev_attr_aux3);
+		device_create_file(dev, &dev_attr_aux4);
+	}
+	if (status_sys)
+		device_create_file(dev, &dev_attr_status);
+	return 0;
+}	     
+
+static void wm97xx_sys_remove(struct device *dev) 
+{
+	if (status_sys)
+		device_remove_file(dev, &dev_attr_status);
+	if (aux_sys) {
+		device_remove_file(dev, &dev_attr_aux1);
+		device_remove_file(dev, &dev_attr_aux2);
+		device_remove_file(dev, &dev_attr_aux3);
+		device_remove_file(dev, &dev_attr_aux4);
+	}
+} 
+
+/**
+ *	wm97xx_get_gpio - Get the status of a codec GPIO.
+ *	@wm: wm97xx device.
+ *  @gpio: gpio
+ *
+ *	Get the status of a codec GPIO pin
+ */ 
+
+wm97xx_gpio_status_t wm97xx_get_gpio(struct wm97xx *wm, u32 gpio) 
+{
+	u16 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
+
+	if (status & gpio)
+		return WM97XX_GPIO_HIGH;
+	else
+		return WM97XX_GPIO_LOW; 
+}
+
+/**
+ *	wm97xx_set_gpio - Set the status of a codec GPIO.
+ *	@wm: wm97xx device.
+ *  @gpio: gpio
+ *  
+ *
+ *	Set the status of a codec GPIO pin
+ */
+
+void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
+				wm97xx_gpio_status_t status) 
+{
+	u16 reg; 
+	
+	down(&codec_sem);
+	reg = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
+
+	if (status & WM97XX_GPIO_HIGH)
+		reg |= gpio;
+	else
+		reg &= ~gpio;
+
+	if (wm->id == WM9712_ID2) 
+		wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg << 1);
+	else
+		wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg);     
+	up(&codec_sem); 
+}	     
+
+/*
+ * Codec GPIO pin configuration, this set's pin direction, polarity,
+ * stickyness and wake up.
+ */ 
+void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, wm97xx_gpio_dir_t dir,
+		   wm97xx_gpio_pol_t pol, wm97xx_gpio_sticky_t sticky,
+		   wm97xx_gpio_wake_t wake)
+{
+	u16 reg;
+	
+	down(&codec_sem);
+	reg = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
+
+	if (pol == WM97XX_GPIO_POL_HIGH) 
+		reg |= gpio; 
+	else
+		reg &= ~gpio;
+
+	wm97xx_reg_write(wm, AC97_GPIO_POLARITY, reg);
+	reg = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
+
+	if (sticky == WM97XX_GPIO_STICKY) 
+		reg |= gpio; 
+	else
+		reg &= ~gpio;
+
+	wm97xx_reg_write(wm, AC97_GPIO_STICKY, reg);
+	reg = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
+
+	if (wake == WM97XX_GPIO_WAKE) 
+		reg |= gpio; 
+	else
+		reg &= ~gpio;
+
+	wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, reg);
+	reg = wm97xx_reg_read(wm, AC97_GPIO_CFG);
+
+	if (dir == WM97XX_GPIO_IN) 
+		reg |= gpio; 
+	else
+		reg &= ~gpio;
+
+	wm97xx_reg_write(wm, AC97_GPIO_CFG, reg);
+	up(&codec_sem); 
+}
+
+/*
+ * Allow wm97xx platform drivers to use the codec PENDOWN gpio signal 
+ * as a pen down interrupt source. The PENDOWN signal is usually 
+ * routed via a cpu irq/gpio.
+ */ 
+int wm97xx_request_pen_irq(struct wm97xx *wm, int irq) 
+{
+	down(&codec_sem); 
+	if (!wm->pen_irq)
+		wm->pen_irq = irq;
+	
+	wm->pen_irq_ref_count++;
+	up(&codec_sem); 
+	return 0; 
+}	     
+
+void wm97xx_free_pen_irq(struct wm97xx *wm) 
+{
+	down(&codec_sem);
+    	wm->pen_irq_ref_count--;
+	up(&codec_sem); 
+}	     
+
+/*
+ * Handle a pen down interrupt.
+ */ 
+static void wm97xx_pen_irq_worker(void *ptr) 
+{		     
+	struct wm97xx *wm = (struct wm97xx *) ptr;
+	
+	/* do we need to enable the touch panel reader */ 
+	if (wm->id == WM9705_ID2) {
+		if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) & WM97XX_PEN_DOWN)
+			wm->pen_is_down = 1;
+		else
+			wm->pen_is_down = 0;
+		wake_up_interruptible(&wm->pen_irq_wait); 
+	} else {
+		u16 status, pol;
+		down(&codec_sem);
+		status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
+		pol = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
+	    
+		if (WM97XX_GPIO_13 & pol & status) {
+			wm->pen_is_down = 1;
+			wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol & ~WM97XX_GPIO_13);	    
+		} else {
+			wm->pen_is_down = 0;
+		    wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol | WM97XX_GPIO_13);
+		}
+		
+		if (wm->id == WM9712_ID2)
+			wm97xx_reg_write(wm, AC97_GPIO_STATUS, (status & ~WM97XX_GPIO_13) << 1);
+		else
+			wm97xx_reg_write(wm, AC97_GPIO_STATUS, status & ~WM97XX_GPIO_13);
+		up(&codec_sem);
+		wake_up_interruptible(&wm->pen_irq_wait); 
+	}
+	
+	if (!wm->pen_is_down && wm->acc && wm->acc->acc_pen_up)
+		wm->acc->acc_pen_up(wm);
+	
+	enable_irq(wm->pen_irq);
+}
+
+/*
+ * Codec PENDOWN irq handler
+ *
+ * We have to disable the codec interrupt in the handler because it can 
+ * take upto 1ms to clear the interrupt source. The interrupt is then enabled
+ * again in the slow handler when the source has been cleared.
+ */ 
+static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id, 
+					struct pt_regs *regs) 
+{
+	struct wm97xx *wm = (struct wm97xx *) dev_id;
+	disable_irq(wm->pen_irq);
+	queue_work(wm->pen_irq_workq, &wm->pen_event_work);
+	return IRQ_HANDLED; 
+}
+
+/*
+ * initialise pen IRQ handler and workqueue
+ */ 
+static int wm97xx_init_pen_irq(struct wm97xx *wm) 
+{
+	u16 reg;
+
+	INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker, wm);
+	if ((wm->pen_irq_workq = 
+		create_singlethread_workqueue("kwm97pen")) == NULL) {
+		err("could not create pen irq work queue");
+		wm->pen_irq = 0; 
+		return -EINVAL; 
+	}
+
+	if (request_irq (wm->pen_irq, wm97xx_pen_interrupt, SA_SHIRQ, "wm97xx-pen", wm)) {
+		err("could not register codec pen down interrupt, will poll for pen down");
+		destroy_workqueue(wm->pen_irq_workq);
+		wm->pen_irq = 0; 
+		return -EINVAL; 
+	}
+
+	/* enable PEN down on wm9712/13 */ 
+	if (wm->id != WM9705_ID2) {
+		reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
+		wm97xx_reg_write(wm, AC97_MISC_AFE, reg & 0xfffb);
+		reg = wm97xx_reg_read(wm, 0x5a);
+		wm97xx_reg_write(wm, 0x5a, reg & ~0x0001); 
+	}
+	
+	return 0; 
+}
+
+/* Private struct for communication between struct wm97xx_tshread and wm97xx_read_samples */ 
+struct ts_state {		     
+	int sleep_time; 
+	int min_sleep_time; 
+}; 
+
+static int wm97xx_read_samples(struct wm97xx *wm, struct ts_state *state) 
+{
+	struct wm97xx_data data; 
+	int rc;
+
+	down(&codec_sem);
+	if (wm->acc)
+		rc = wm->acc->acc_pen_down(wm);
+	else 
+		rc = wm->codec->poll_touch(wm, &data);
+	
+	if (rc & RC_PENUP) {
+		if (wm->pen_is_down) {
+			wm->pen_is_down = 0; 
+			dbg("pen up");
+			input_report_abs(&wm->input_dev, ABS_PRESSURE, 0);
+			input_sync(&wm->input_dev); 
+		} else if (!(rc & RC_AGAIN)) {
+			/* We need high frequency updates only while pen is down,
+			* the user never will be able to touch screen faster than
+			* a few times per second... On the other hand, when the
+			* user is actively working with the touchscreen we don't
+			* want to lose the quick response. So we will slowly
+			* increase sleep time after the pen is up and quicky
+			* restore it to ~one task switch when pen is down again.
+			*/ 
+			if (state->sleep_time < HZ / 10) 
+				state->sleep_time++; 
+		}
+
+	} else if (rc & RC_VALID) {
+		printk("pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n",
+			data.x >> 12, data.x & 0xfff, data.y >> 12,
+			data.y & 0xfff, data.p >> 12, data.p & 0xfff);
+		input_report_abs(&wm->input_dev, ABS_X, data.x & 0xfff);
+		input_report_abs(&wm->input_dev, ABS_Y, data.y & 0xfff);
+		input_report_abs(&wm->input_dev, ABS_PRESSURE, data.p & 0xfff);
+		input_sync(&wm->input_dev); 
+		wm->pen_is_down = 1;
+		state->sleep_time = state->min_sleep_time; 
+	} else if (rc & RC_PENDOWN) {
+		dbg("pen down"); 
+		wm->pen_is_down = 1;
+		state->sleep_time = state->min_sleep_time; 
+	}
+
+	up(&codec_sem); 
+	return rc; 
+}
+
+/*
+* The touchscreen sample reader thread.
+*/ 
+static int wm97xx_ts_read(void *data) 
+{
+	int rc; 
+	struct ts_state state;
+	struct wm97xx *wm = (struct wm97xx *) data; 
+
+	/* set up thread context */ 
+	wm->ts_task = current;
+	daemonize("kwm97xxts");
+
+	if (wm->codec == NULL) {
+		wm->ts_task = NULL;
+		printk(KERN_ERR "codec is NULL, bailing\n"); 
+	}
+
+	complete(&wm->ts_init); 
+	wm->pen_is_down = 0;
+	state.min_sleep_time = HZ >= 100 ? HZ / 100 : 1;
+	if (state.min_sleep_time < 1) 
+		state.min_sleep_time = 1;
+	state.sleep_time = state.min_sleep_time; 
+
+	/* touch reader loop */ 
+	while (wm->ts_task) {
+		do {
+			rc = wm97xx_read_samples(wm, &state);
+		} while (rc & RC_AGAIN);
+		
+		if (!wm->pen_is_down && wm->pen_irq) {
+			/* Nice, we don't have to poll for pen down event */ 
+			wait_event_interruptible(wm->pen_irq_wait, wm->pen_is_down);		    
+		} else {
+			set_task_state(current, TASK_INTERRUPTIBLE);
+			schedule_timeout(state.sleep_time); 
+		}
+	}
+	complete_and_exit(&wm->ts_exit, 0); 
+}
+
+/**
+ *	wm97xx_ts_input_open - Open the touch screen input device.
+ *	@idev:	Input device to be opened.
+ *
+ *	Called by the input sub system to open a wm97xx touchscreen device.
+ *  Starts the touchscreen thread and touch digitiser.
+ */ 
+int wm97xx_ts_input_open(struct input_dev *idev) 
+{
+	int ret = 0;
+	struct wm97xx *wm = (struct wm97xx *) idev->private;
+
+	down(&drv_sem);
+	if (wm->codec == NULL) {
+		printk("error: wm->codec == NULL\n");
+		up(&drv_sem); 
+		return -ENODEV; 
+	}
+
+	if (wm->ac97 == NULL) {	
+		printk("error: wm->ac97 == NULL\n");
+		up(&drv_sem); 
+		return -ENODEV; 
+	}
+	up(&drv_sem); 
+
+	down(&codec_sem); 
+	/* first time opened ? */ 
+	if (wm->ts_use_count++ == 0) {
+		/* start touchscreen thread */ 
+		init_completion(&wm->ts_init);
+		init_completion(&wm->ts_exit);
+		ret = kernel_thread(wm97xx_ts_read, wm, CLONE_KERNEL);
+
+		if (ret >= 0) {
+			wait_for_completion(&wm->ts_init);
+			if (wm->ts_task == NULL) 
+				ret = -EINVAL; 
+		} else {
+			up(&codec_sem); 
+			return ret;
+		}
+
+		/* start digitiser */
+		if (wm->acc && wm->acc->acc_pen_down)
+			wm->codec->acc_enable(wm, 1);
+		wm->codec->digitiser_ioctl(wm, WM97XX_DIG_START);
+
+		/* init pen down/up irq handling */ 
+		if (wm->pen_irq) {
+			wm97xx_init_pen_irq(wm); 
+
+			if (wm->pen_irq == 0) {
+				/* we failed to get an irq for pen down events,
+				 * so we resort to polling. kickstart the reader */ 
+				wm->pen_is_down = 1;
+				wake_up_interruptible(&wm->pen_irq_wait); 
+			}
+		}
+	}
+	     
+	up(&codec_sem); 
+	return 0; 
+}
+
+/**
+ *	wm97xx_ts_input_close - Close the touch screen input device.
+ *	@idev:	Input device to be closed.
+ *
+ *	Called by the input sub system to close a wm97xx touchscreen device.
+ *  Kills the touchscreen thread and stops the touch digitiser.
+ */
+
+void wm97xx_ts_input_close(struct input_dev *idev) 
+{
+	struct wm97xx *wm = (struct wm97xx *) idev->private;
+		
+	down(&codec_sem);
+	if (--wm->ts_use_count == 0) {
+		/* destroy workqueues and free irqs */ 
+		if (wm->pen_irq) {
+			free_irq(wm->pen_irq, wm);
+			destroy_workqueue(wm->pen_irq_workq);
+			if (wm->pen_irq_ref_count == 0)
+		    		wm->pen_irq = 0;
+		}
+		
+		/* kill thread */ 
+		if (wm->ts_task) {
+			wm->ts_task = NULL; 
+			wm->pen_is_down = 1;
+			wake_up_interruptible(&wm->pen_irq_wait);
+			wait_for_completion(&wm->ts_exit);
+			wm->pen_is_down = 0; 
+		}
+
+		/* stop digitiser */
+		wm->codec->digitiser_ioctl(wm, WM97XX_DIG_STOP);
+		if (wm->acc && wm->acc->acc_pen_down)
+			wm->codec->acc_enable(wm, 0);
+	}
+	up(&codec_sem); 
+}
+
+static int wm97xx_suspend(struct device * dev, pm_message_t state, u32 level) 
+{
+	int ret = 0;
+	struct wm97xx *wm = dev_get_drvdata(dev);
+
+	if (wm->codec) 
+		ret = wm->codec->codec_suspend(wm, state.event, level);
+
+	return ret; 
+}
+
+static int wm97xx_resume(struct device *dev, u32 level) 
+{
+	int ret = 0;
+	struct wm97xx *wm = dev_get_drvdata(dev);
+
+	if (wm->codec) 
+		ret = wm->codec->codec_resume(wm, level);
+
+	return ret; 
+}
+
+static int wm97xx_remove(struct device *dev) 
+{
+	struct wm97xx *wm = dev_get_drvdata(dev);
+	struct list_head *l;
+	struct wm97xx_codec_drv *c;
+	struct wm97xx_platform_drv *p;
+
+	down(&drv_sem); 
+	
+	/* Stop touch reader thread */ 
+	if (wm->ts_task) {
+		wm->ts_task = NULL; 
+		wm->pen_is_down = 1;
+		wake_up_interruptible(&wm->pen_irq_wait);
+		wait_for_completion(&wm->ts_exit); 
+	}
+
+	/* call remove() on any attached platform drivers */
+	list_for_each(l, &platform_drivers) {
+		p = list_entry(l, struct wm97xx_platform_drv, list);
+		if (p->wm != wm)
+			continue;
+		p->remove(wm);
+	}
+
+	/* call remove on our attached codec driver */
+	list_for_each(l, &codec_drivers) {
+		c = list_entry(l, struct wm97xx_codec_drv, list);
+		if (wm->codec != c)
+			continue;
+		c->remove(wm);
+		wm97xx_sys_add(wm->dev);
+		break;
+	}
+
+	list_del(&wm->list);
+	kfree(wm);
+
+	up(&drv_sem); 
+	return 0; 
+}
+
+static int wm97xx_probe(struct device *dev) 
+{
+	struct wm97xx* wm;
+	struct list_head *l;
+	struct wm97xx_codec_drv* c;
+	struct wm97xx_platform_drv* p;
+	int ret = 0;
+
+	down(&drv_sem);
+	if (!(wm = kmalloc(sizeof(struct wm97xx), GFP_KERNEL)))
+		return -ENOMEM;
+	memset(wm, 0, sizeof(struct wm97xx));
+	init_waitqueue_head(&wm->pen_irq_wait); 
+	wm->dev = dev; 
+	dev->driver_data = wm;
+	wm->ac97 = dev->platform_data;
+
+	/* check that we have a supported codec */
+	if (wm97xx_reg_read(wm, AC97_VENDOR_ID1) != WM97XX_ID1) {
+		kfree(wm);
+		return -ENODEV;
+	}
+	wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2);
+	INIT_LIST_HEAD(&wm->plist);
+
+	/* check and probe wm97xx codec driver */
+	list_add(&wm->list, &codecs);
+	list_for_each(l, &codec_drivers) {
+		c = list_entry(l, struct wm97xx_codec_drv, list);
+		if (wm->id != c->id)
+			continue;
+		if(c->probe(wm) == 0) {
+			wm->codec = c;
+			wm97xx_sys_add(wm->dev);
+			break;
+		}
+	}
+
+	/* check and probe each matching wm97xx platform drivers */
+	list_for_each(l, &platform_drivers) {
+		p = list_entry(l, struct wm97xx_platform_drv, list);
+		if ((wm->id ^ p->id) & p->mask)
+			continue;
+		if(p->probe(wm) == 0) {
+			list_add(&p->plist, &wm->plist);
+		}
+	}
+
+	up(&drv_sem); 
+	return ret; 
+}
+
+static struct device_driver wm97xx_driver = {
+	.name = 	"WM97", 
+	.bus = 		&ac97_bus_type, 
+	.owner = 	THIS_MODULE, 
+	.probe = 	wm97xx_probe, 
+	.remove = 	wm97xx_remove, 
+	.suspend = 	wm97xx_suspend, 
+	.resume =	wm97xx_resume, 
+};
+
+/**
+ *	wm97xx_register_codec_drv - Register a wm97xx codec driver.
+ *	@codec_drv:	codec driver to be Registered.
+ *
+ *	Register @codec_drv with the wm97xx core.
+ */
+
+int wm97xx_register_codec_drv(struct wm97xx_codec_drv *codec_drv) 
+{
+	struct list_head *l;
+	struct wm97xx* wm;
+
+	down(&drv_sem);
+	INIT_LIST_HEAD(&codec_drv->list);
+	list_add(&codec_drv->list, &codec_drivers);
+
+	list_for_each(l, &codecs)
+	{
+		wm = list_entry(l, struct wm97xx, list);
+		if(wm->codec != NULL || wm->id != codec_drv->id)
+			continue;
+		if(codec_drv->probe(wm) == 0) {
+			wm->codec = codec_drv;
+			wm97xx_sys_add(wm->dev); 
+			break;
+		}
+	}
+
+	up(&drv_sem);
+	return 0;
+}
+
+/**
+ *	wm97xx_unregister_codec - Unregister a wm97xx codec driver.
+ *	@codec_drv:	codec driver to be unregistered.
+ *
+ *	Unregister @codec_drv driver with the wm97xx core.
+ */
+
+void wm97xx_unregister_codec_drv(struct wm97xx_codec_drv *codec_drv) 
+{
+	struct list_head *l;
+	struct wm97xx *wm;
+
+	down(&drv_sem); 
+	list_del_init(&codec_drv->list);
+	list_for_each(l, &codecs)
+	{
+		wm = list_entry(l, struct wm97xx, list);
+		if (wm->codec == codec_drv) {
+			codec_drv->remove(wm);
+			wm97xx_sys_remove(wm->dev);
+			wm->codec = NULL;
+		}
+	}
+	up(&drv_sem);
+}
+
+/**
+ *	wm97xx_register_platform_drv - Register a new wm97xx platform driver.
+ *	@platform_drv:	Platform driver to be registered.
+ *
+ *	Register @platform_drv driver with the wm97xx core and probe the device
+ *  if a matching supported codec is found.
+ */
+
+int wm97xx_register_platform_drv(struct wm97xx_platform_drv *platform_drv) 
+{
+	struct list_head *l;
+	struct wm97xx* wm;
+
+	down(&drv_sem);
+	INIT_LIST_HEAD(&platform_drv->list);
+	list_add(&platform_drv->list, &platform_drivers);
+
+	list_for_each(l, &codecs)
+	{
+		wm = list_entry(l, struct wm97xx, list);
+		if ((wm->id ^ platform_drv->id) & platform_drv->mask)
+			continue;
+		if(platform_drv->probe(wm) == 0) {
+			list_add(&platform_drv->plist, &wm->plist);
+			if(!wm->acc && platform_drv->acc_pen_down)
+				wm->acc = platform_drv;
+		}
+	}
+	up(&drv_sem);
+	return 0;
+}
+
+/**
+ *	wm97xx_unregister_platform_drv - Unregister a wm97xx platform driver.
+ *	@platform_drv:	Platform driver to be unregistered.
+ *
+ *	Unregister @platform_drv driver with the wm97xx core and call it's
+ *  remove function if it's attached to a codec.
+ */
+
+void wm97xx_unregister_platform_drv(struct wm97xx_platform_drv *platform_drv) 
+{	
+	struct list_head *l, *ap;
+	struct wm97xx *wm;
+	struct wm97xx_platform_drv *p;
+
+	down(&drv_sem); 
+	list_del_init(&platform_drv->list);
+	list_for_each(l, &codecs)
+	{
+		wm = list_entry(l, struct wm97xx, list);
+			
+		/* now search the attached platform devices */
+		list_for_each(ap, &wm->plist) {
+			p = list_entry(ap, struct wm97xx_platform_drv, plist);
+			if (p == platform_drv) {
+				p->remove(wm);
+				if (platform_drv == wm->acc)
+					wm->acc = NULL;
+				list_del(&p->plist);
+				break;
+			}
+		}
+	}
+	up(&drv_sem);
+}
+
+static int __init wm97xx_init(void) 
+{
+	info("version %s liam.girdwood@wolfsonmicro.com", WM_CORE_VERSION);
+	return driver_register(&wm97xx_driver); 
+}
+
+static void __exit wm97xx_exit(void) 
+{
+	driver_unregister(&wm97xx_driver); 
+}
+
+EXPORT_SYMBOL_GPL(wm97xx_reg_read);
+EXPORT_SYMBOL_GPL(wm97xx_reg_write);
+EXPORT_SYMBOL_GPL(wm97xx_get_gpio);
+EXPORT_SYMBOL_GPL(wm97xx_set_gpio);
+EXPORT_SYMBOL_GPL(wm97xx_config_gpio);
+EXPORT_SYMBOL_GPL(wm97xx_request_pen_irq);
+EXPORT_SYMBOL_GPL(wm97xx_free_pen_irq);
+EXPORT_SYMBOL_GPL(wm97xx_ts_input_open);
+EXPORT_SYMBOL_GPL(wm97xx_ts_input_close);
+EXPORT_SYMBOL_GPL(wm97xx_register_codec_drv);
+EXPORT_SYMBOL_GPL(wm97xx_unregister_codec_drv);
+EXPORT_SYMBOL_GPL(wm97xx_register_platform_drv);
+EXPORT_SYMBOL_GPL(wm97xx_unregister_platform_drv);
+EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc);
+
+module_init(wm97xx_init); 
+module_exit(wm97xx_exit);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver");
+MODULE_LICENSE("GPL");
diff --git a/include/asm-arm/arch-pxa/ssp.h b/include/asm-arm/arch-pxa/ssp.h
index 6ec67b0..949878c 100644
--- a/include/asm-arm/arch-pxa/ssp.h
+++ b/include/asm-arm/arch-pxa/ssp.h
@@ -18,6 +18,11 @@
 #ifndef SSP_H
 #define SSP_H
 
+/*
+ * SSP initialisation flags
+ */
+#define SSP_NO_IRQ	0x1		/* don't register an irq handler in SSP driver */
+
 struct ssp_state {
 	u32	cr0;
 	u32 cr1;
@@ -31,6 +36,7 @@ struct ssp_dev {
 	u32 flags;
 	u32 psp_flags;
 	u32 speed;
+	int irq;
 };
 
 int ssp_write_word(struct ssp_dev *dev, u32 data);
@@ -40,7 +46,7 @@ void ssp_enable(struct ssp_dev *dev);
 void ssp_disable(struct ssp_dev *dev);
 void ssp_save_state(struct ssp_dev *dev, struct ssp_state *ssp);
 void ssp_restore_state(struct ssp_dev *dev, struct ssp_state *ssp);
-int ssp_init(struct ssp_dev *dev, u32 port);
+int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags);
 int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 speed);
 void ssp_exit(struct ssp_dev *dev);
 
diff --git a/include/linux/wm97xx.h b/include/linux/wm97xx.h
new file mode 100644
index 0000000..17437a4
--- /dev/null
+++ b/include/linux/wm97xx.h
@@ -0,0 +1,312 @@
+/*
+ * Register bits and API for Wolfson WM97xx series of codecs
+ */
+
+#ifndef _LINUX_WM97XX_H
+#define _LINUX_WM97XX_H
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/ac97_codec.h>
+#include <sound/initval.h>
+#include <linux/types.h>
+#include <linux/input.h>	/* Input device layer */
+
+/*
+ * WM97xx AC97 Touchscreen registers
+ */
+#define AC97_WM97XX_DIGITISER1		0x76
+#define AC97_WM97XX_DIGITISER2		0x78
+#define AC97_WM97XX_DIGITISER_RD 	0x7a
+#define AC97_WM9713_DIG1			0x74
+#define AC97_WM9713_DIG2			AC97_WM97XX_DIGITISER1
+#define AC97_WM9713_DIG3			AC97_WM97XX_DIGITISER2
+
+/*
+ * WM97xx register bits
+ */
+#define WM97XX_POLL			0x8000	/* initiate a polling measurement */
+#define WM97XX_ADCSEL_X		0x1000	/* x coord measurement */
+#define WM97XX_ADCSEL_Y		0x2000	/* y coord measurement */
+#define WM97XX_ADCSEL_PRES	0x3000	/* pressure measurement */
+#define WM97XX_ADCSEL_MASK	0x7000
+#define WM97XX_COO			0x0800	/* enable coordinate mode */
+#define WM97XX_CTC			0x0400	/* enable continuous mode */
+#define WM97XX_CM_RATE_93	0x0000	/* 93.75Hz continuous rate */
+#define WM97XX_CM_RATE_187	0x0100	/* 187.5Hz continuous rate */
+#define WM97XX_CM_RATE_375	0x0200	/* 375Hz continuous rate */
+#define WM97XX_CM_RATE_750	0x0300	/* 750Hz continuous rate */
+#define WM97XX_CM_RATE_8K	0x00f0	/* 8kHz continuous rate */
+#define WM97XX_CM_RATE_12K	0x01f0	/* 12kHz continuous rate */
+#define WM97XX_CM_RATE_24K	0x02f0	/* 24kHz continuous rate */
+#define WM97XX_CM_RATE_48K	0x03f0	/* 48kHz continuous rate */
+#define WM97XX_CM_RATE_MASK	0x03f0
+#define WM97XX_RATE(i)		(((i & 3) << 8) | ((i & 4) ? 0xf0 : 0))
+#define WM97XX_DELAY(i)		((i << 4) & 0x00f0)	/* sample delay times */
+#define WM97XX_DELAY_MASK	0x00f0
+#define WM97XX_SLEN			0x0008	/* slot read back enable */
+#define WM97XX_SLT(i)		((i - 5) & 0x7)	/* touchpanel slot selection (5-11) */
+#define WM97XX_SLT_MASK		0x0007
+#define WM97XX_PRP_DETW		0x4000	/* pen detect on, digitiser off, wake up */
+#define WM97XX_PRP_DET		0x8000	/* pen detect on, digitiser off, no wake up */
+#define WM97XX_PRP_DET_DIG	0xc000	/* pen detect on, digitiser on */
+#define WM97XX_RPR			0x2000	/* wake up on pen down */
+#define WM97XX_PEN_DOWN		0x8000	/* pen is down */
+#define WM97XX_ADCSRC_MASK	0x7000	/* ADC source mask */
+
+#define WM97XX_AUX_ID1		0x8001
+#define WM97XX_AUX_ID2		0x8002
+#define WM97XX_AUX_ID3		0x8003
+#define WM97XX_AUX_ID4		0x8004
+
+
+/* WM9712 Bits */
+#define WM9712_45W			0x1000	/* set for 5-wire touchscreen */
+#define WM9712_PDEN			0x0800	/* measure only when pen down */
+#define WM9712_WAIT			0x0200	/* wait until adc is read before next sample */
+#define WM9712_PIL			0x0100	/* current used for pressure measurement. set 400uA else 200uA */
+#define WM9712_MASK_HI		0x0040	/* hi on mask pin (47) stops conversions */
+#define WM9712_MASK_EDGE	0x0080	/* rising/falling edge on pin delays sample */
+#define	WM9712_MASK_SYNC	0x00c0	/* rising/falling edge on mask initiates sample */
+#define WM9712_RPU(i)		(i&0x3f)	/* internal pull up on pen detect (64k / rpu) */
+#define WM9712_PD(i)		(0x1 << i)	/* power management */
+
+/* WM9712 Registers */
+#define AC97_WM9712_POWER	0x24
+#define AC97_WM9712_REV		0x58
+
+/* WM9705 Bits */
+#define WM9705_PDEN			0x1000	/* measure only when pen is down */
+#define WM9705_PINV			0x0800	/* inverts sense of pen down output */
+#define WM9705_BSEN			0x0400	/* BUSY flag enable, pin47 is 1 when busy */
+#define WM9705_BINV			0x0200	/* invert BUSY (pin47) output */
+#define WM9705_WAIT			0x0100	/* wait until adc is read before next sample */
+#define WM9705_PIL			0x0080	/* current used for pressure measurement. set 400uA else 200uA */
+#define WM9705_PHIZ			0x0040	/* set PHONE and PCBEEP inputs to high impedance */
+#define WM9705_MASK_HI		0x0010	/* hi on mask stops conversions */
+#define WM9705_MASK_EDGE	0x0020	/* rising/falling edge on pin delays sample */
+#define	WM9705_MASK_SYNC	0x0030	/* rising/falling edge on mask initiates sample */
+#define WM9705_PDD(i)		(i & 0x000f)	/* pen detect comparator threshold */
+
+
+/* WM9713 Bits */
+#define WM9713_PDPOL		0x0400	/* Pen down polarity */
+#define WM9713_POLL			0x0200	/* initiate a polling measurement */
+#define WM9713_CTC			0x0100	/* enable continuous mode */
+#define WM9713_ADCSEL_X		0x0002	/* X measurement */
+#define WM9713_ADCSEL_Y		0x0004	/* Y measurement */
+#define WM9713_ADCSEL_PRES	0x0008	/* Pressure measurement */
+#define WM9713_COO			0x0001	/* enable coordinate mode */
+#define WM9713_PDEN			0x0800	/* measure only when pen down */
+#define WM9713_ADCSEL_MASK	0x00fe	/* ADC selection mask */
+
+/* AUX ADC ID's */
+#define TS_COMP1			0x0
+#define TS_COMP2			0x1
+#define TS_BMON				0x2
+#define TS_WIPER			0x3
+
+/* ID numbers */
+#define WM97XX_ID1			0x574d
+#define WM9712_ID2			0x4c12
+#define WM9705_ID2			0x4c05
+#define WM9713_ID2			0x4c13
+
+/* Codec GPIO's */
+#define WM97XX_MAX_GPIO		16
+#define WM97XX_GPIO_1		(1 << 1)
+#define WM97XX_GPIO_2		(1 << 2)
+#define WM97XX_GPIO_3		(1 << 3)
+#define WM97XX_GPIO_4		(1 << 4)
+#define WM97XX_GPIO_5		(1 << 5)
+#define WM97XX_GPIO_6		(1 << 6)
+#define WM97XX_GPIO_7		(1 << 7)
+#define WM97XX_GPIO_8		(1 << 8)
+#define WM97XX_GPIO_9		(1 << 9)
+#define WM97XX_GPIO_10		(1 << 10)
+#define WM97XX_GPIO_11		(1 << 11)
+#define WM97XX_GPIO_12		(1 << 12)
+#define WM97XX_GPIO_13		(1 << 13)
+#define WM97XX_GPIO_14		(1 << 14)
+#define WM97XX_GPIO_15		(1 << 15)
+
+
+#define AC97_LINK_FRAME		21	/* time in uS for AC97 link frame */
+
+
+/*---------------- Return codes from sample reading functions ---------------*/
+
+/* More data is available; call the sample gathering function again */
+#define RC_AGAIN			0x00000001
+/* The returned sample is valid */
+#define RC_VALID			0x00000002
+/* The pen is up (the first RC_VALID without RC_PENUP means pen is down) */
+#define RC_PENUP			0x00000004
+/* The pen is down (RC_VALID implies RC_PENDOWN, but sometimes it is helpful
+   to tell the handler that the pen is down but we don't know yet his coords,
+   so the handler should not sleep or wait for pendown irq) */
+#define RC_PENDOWN			0x00000008
+
+/* The wm97xx driver provides a private API for writing platform-specific
+ * drivers. 
+ */
+
+/* The structure used to return arch specific sampled data into */
+struct wm97xx_data {
+    int x;
+    int y;
+    int p;
+};
+
+/* Codec GPIO status
+ */
+typedef enum {
+    WM97XX_GPIO_HIGH,
+    WM97XX_GPIO_LOW
+} wm97xx_gpio_status_t;
+
+/* Codec GPIO direction
+ */
+typedef enum {
+    WM97XX_GPIO_IN,
+    WM97XX_GPIO_OUT
+} wm97xx_gpio_dir_t;
+
+/* Codec GPIO polarity
+ */
+typedef enum {
+    WM97XX_GPIO_POL_HIGH,
+    WM97XX_GPIO_POL_LOW
+} wm97xx_gpio_pol_t;
+
+/* Codec GPIO sticky
+ */
+typedef enum {
+    WM97XX_GPIO_STICKY,
+    WM97XX_GPIO_NOTSTICKY
+} wm97xx_gpio_sticky_t;
+
+/* Codec GPIO wake
+ */
+typedef enum {
+    WM97XX_GPIO_WAKE,
+    WM97XX_GPIO_NOWAKE
+} wm97xx_gpio_wake_t;
+
+
+/*
+ * Digitiser ioctl commands
+ */
+#define WM97XX_DIG_START	0x1
+#define WM97XX_DIG_STOP		0x2
+#define WM97XX_DIG_SAVE		0x3
+#define WM97XX_DIG_RESTORE	0x4
+#define WM97XX_PHY_INIT		0x5
+#define WM97XX_AUX_PREPARE	0x6
+
+struct wm97xx;
+
+/*
+ * Codec driver interface - allows mapping to WM9705/12/13 and newer codecs
+ */
+struct wm97xx_codec_drv {
+	u16 id;
+	int (*probe) (struct wm97xx *);
+	void (*remove) (struct wm97xx *);
+	int (*poll_sample) (struct wm97xx *, int adcsel, int *sample);	/* read 1 sample */
+	int (*poll_touch) (struct wm97xx *, struct wm97xx_data *);	/* read X,Y,[P] in poll */
+	int (*codec_suspend) (struct wm97xx *, u32 state, u32 level);
+	int (*codec_resume) (struct wm97xx *, u32 level);
+	void (*acc_enable) (struct wm97xx *, int enable);
+	void (*digitiser_ioctl) (struct wm97xx *, int cmd);
+	struct wm97xx* wm;
+	struct list_head list;
+};
+
+/*
+ * Platform driver interface - allows mapping to host system
+ * 
+ * Platform interface provides access for accelerated touch and platform
+ * specific GPIOS and AUX adc measurements.
+ *
+ */
+struct wm97xx_platform_drv {
+	u16 id;
+	u16 mask;
+	int acc_slot; /* AC97 slot used for acc touch data */
+	int acc_rate; /* acc touch data rate */
+	int (*acc_pen_down) (struct wm97xx *);	/* called when pen is down */
+	void (*acc_pen_up) (struct wm97xx *); /* called when pen goes up */
+	int (*probe) (struct wm97xx *);
+	void (*remove) (struct wm97xx *);
+	struct wm97xx* wm;
+	struct list_head list;
+	struct list_head plist;
+};
+
+struct wm97xx {
+	u16 dig1, dig2, dig3, id;	/* Cached codec registers */
+	struct wm97xx_codec_drv *codec;	/* attached codec driver*/
+	struct input_dev input_dev;	/* touchscreen input device */
+	ac97_t *ac97;			/* ALSA codec access */
+	struct device *dev;		/* ALSA device */
+	struct list_head list;
+	struct completion ts_init;
+	struct completion ts_exit;
+	struct task_struct *ts_task;
+	struct list_head plist;  /* list of attached platform drivers */
+	struct wm97xx_platform_drv *acc; /* accelerated touch driver */
+	unsigned int pen_irq;	/* Pen IRQ number in use */
+	wait_queue_head_t pen_irq_wait;	/* Pen IRQ wait queue */
+	int pen_irq_ref_count;		/* Number of pen irq users */
+	struct workqueue_struct *pen_irq_workq;
+	struct work_struct pen_event_work;
+	unsigned int ts_use_count;
+	unsigned pen_is_down:1;	/* Pen is down */
+	unsigned aux_waiting:1;	/* aux measurement waiting */
+	unsigned pen_probably_down:1;	/* used in polling mode */
+#if defined(CONFIG_PM)
+	unsigned phone_pga:5;	/* PGA settings for PM */
+	unsigned line_pga:16;
+	unsigned mic_pga:16;
+#endif
+};
+
+int wm97xx_register_codec_drv(struct wm97xx_codec_drv *codec_drv);
+void wm97xx_unregister_codec_drv(struct wm97xx_codec_drv *codec_drv);
+
+int wm97xx_register_platform_drv(struct wm97xx_platform_drv *platform_drv);
+void wm97xx_unregister_platform_drv(struct wm97xx_platform_drv *platform_drv);
+
+
+/* Codec PEN IRQ access
+ * The codec can additionally generate an IRQ (using a dedicated pin) 
+ * for Pen down events. This is used to enable and disable codec 
+ * Pen down IRQ's
+ */
+int wm97xx_request_pen_irq(struct wm97xx *wm, int irq);
+void wm97xx_free_pen_irq(struct wm97xx *wm);
+
+/* Codec GPIO access (not supported on WM9705)
+ * This can be used to set/get codec GPIO and Virtual GPIO status.
+ */
+wm97xx_gpio_status_t wm97xx_get_gpio(struct wm97xx *wm, u32 gpio);
+void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
+			  wm97xx_gpio_status_t status);
+void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio,
+				     wm97xx_gpio_dir_t dir,
+				     wm97xx_gpio_pol_t pol,
+				     wm97xx_gpio_sticky_t sticky,
+				     wm97xx_gpio_wake_t wake);
+
+void wm97xx_ts_input_close(struct input_dev *idev);
+int wm97xx_ts_input_open(struct input_dev *idev);
+
+unsigned int wm97xx_reg_read(struct wm97xx *wm, unsigned int reg);
+void wm97xx_reg_write(struct wm97xx *wm, unsigned int reg,
+		      unsigned int val);
+
+int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel);
+
+#endif
diff --git a/include/sound/soc-dpm.h b/include/sound/soc-dpm.h
new file mode 100644
index 0000000..df6094d
--- /dev/null
+++ b/include/sound/soc-dpm.h
@@ -0,0 +1,150 @@
+/*
+ * linux/sound/soc-dpm.h -- ALSA SoC Dynamic 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_DPM_H
+#define __LINUX_SND_SOC_DPM_H
+
+#include <linux/device.h>
+#include <linux/types.h>
+#include <sound/control.h>
+#include <sound/soc.h>
+
+/*
+ * SoC dynamic 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 domain - physically connected inputs and outputs
+ *     Is platform 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 */  
+#define SND_SOC_DPM_CODEC(wname) \
+{.id = snd_soc_dpm_codec, .name = wname}
+  
+/* platform domain */
+#define SND_SOC_DPM_INPUT(wname) \
+{.id = snd_soc_dpm_input, .name = wname, .kcontrols = NULL, \
+ .num_kcontrols = 0}
+#define SND_SOC_DPM_OUTPUT(wname) \
+{.id = snd_soc_dpm_output, .name = wname, .kcontrols = NULL, \
+ .num_kcontrols = 0}
+ 
+/* path domain */
+#define SND_SOC_DPM_VOLUME(wname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dpm_volume, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
+#define SND_SOC_DPM_MUX(wname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dpm_mux, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert,	.kcontrols = wcontrols, .num_kcontrols = wncontrols} 
+#define SND_SOC_DPM_MIXER(wname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dpm_mixer, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols} 
+#define SND_SOC_DPM_MIC(wname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dpm_mic, .name = wname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols} 
+
+/* stream domain */
+#define SND_SOC_DPM_DAC(wname, stname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dpm_dac, .name = wname, .sname = stname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
+#define SND_SOC_DPM_ADC(wname, stname, preg, pshift, pinvert, wcontrols, wncontrols) \
+{.id = snd_soc_dpm_adc, .name = wname, .sname = stname, .reg = preg, .shift = pshift, \
+ .invert = pinvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
+
+#define SOC_DPM_SINGLE(xname, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_volsw, \
+  .get = snd_soc_dpm_get_volsw, .put = snd_soc_dpm_put_volsw, \
+  .private_value =  SOC_SINGLE_VALUE(reg, shift, mask, invert) }
+#define SOC_DPM_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_dpm_get_volsw, .put = snd_soc_dpm_put_volsw, \
+  .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) }
+#define SOC_DPM_ENUM(xname, xenum) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_soc_info_enum_double, \
+  .get = snd_soc_dpm_get_enum_double, .put = snd_soc_dpm_put_enum_double, \
+  .private_value = (unsigned long)&xenum }
+  
+typedef struct snd_soc_dpm_widget snd_soc_dpm_widget_t;
+typedef enum snd_soc_dpm_type snd_soc_dpm_type_t;
+typedef struct snd_soc_dpm_path snd_soc_dpm_path_t;
+	
+int snd_soc_dpm_put_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_dpm_get_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_dpm_get_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_dpm_put_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
+int snd_soc_dpm_new_control(snd_soc_codec_t *codec, const snd_soc_dpm_widget_t *widget);
+int snd_soc_dpm_connect_input(snd_soc_codec_t *codec, char *target_name, 
+	char *control_name, char *src_name);
+int snd_soc_dpm_sync(snd_soc_codec_t *codec);
+
+enum snd_soc_dpm_type {
+	snd_soc_dpm_input = 0,
+	snd_soc_dpm_output,
+	snd_soc_dpm_mux,
+	snd_soc_dpm_mixer,
+	snd_soc_dpm_volume,
+	snd_soc_dpm_adc,
+	snd_soc_dpm_dac,
+	snd_soc_dpm_codec,
+};
+
+struct snd_soc_dpm_path {
+	char *name;
+	char *long_name;
+	snd_soc_dpm_widget_t *in;
+	snd_soc_dpm_widget_t *out;
+	snd_kcontrol_t *kcontrol;
+	
+	u8 connect:1; /* applies to widget inputs only */
+	u8 checked:1;   /* path has been checked */
+	u8 walked:1;		/* path has been walked */
+	
+	struct list_head list_in;
+	struct list_head list_out;
+	struct list_head list;
+};
+
+struct snd_soc_dpm_widget {
+	snd_soc_dpm_type_t id;
+	char *name;
+	char *sname;
+	snd_soc_codec_t *codec;
+	struct list_head list;
+	
+	/* dpm control */
+	unsigned short reg;
+	unsigned char shift;
+	unsigned char status;			/* block rules status */ 
+	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;	
+	
+	/* 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/soc.h b/include/sound/soc.h
new file mode 100644
index 0000000..eb7c2a3
--- /dev/null
+++ b/include/sound/soc.h
@@ -0,0 +1,279 @@
+/*
+ * 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/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>
+
+/*
+ * Convenience kcontrol builders
+ */
+
+#define SOC_SINGLE_VALUE(reg,shift,mask,invert) ((reg) | ((shift) << 8) | ((shift) << 12) | ((mask) << 16) | ((invert) << 24))
+#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, power) \
+{ .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_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(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 }
+
+ 
+/*
+ * Audio interface types
+ */
+#define SND_SOC_AC97		0x1
+#define SND_SOC_I2S			0x2
+#define SND_SOC_SSP			0x3
+
+/*
+ * 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 */
+
+/*
+ * hw signal inversions
+ */
+#define SND_SOC_HWFMT_NB_NF			(1 << 24)	/* normal bit clock + frame */
+#define SND_SOC_HWFMT_NB_IF			(1 << 25)	/* normal bclk + inv frm */
+#define SND_SOC_HWFMT_IB_NF			(1 << 26)	/* invert bclk + nor frm */
+#define SND_SOC_HWFMT_IB_IF			(1 << 27)	/* invert bclc + 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 << 28)	/* codec clk & frm master */
+#define SND_SOC_HWFMT_CBS_CFM		(1 << 29)	/* codec clk slave & frm master */
+#define SND_SOC_HWFMT_CBM_CFS		(1 << 30)	/* codec clk master & frame slave */
+#define SND_SOC_HWFMT_CBS_CFS		(1 << 31)	/* codec clk & frm slave */
+
+
+#define SND_SOC_FORMAT_MASK		0x000000ff
+#define SND_SOC_INV_MASK		0x0f000000
+#define SND_SOC_CLOCK_MASK		0xf0000000
+
+#define SND_SOC_HWBITS(x)		(1 << (x - 1))	/* sample size in bits */
+
+/*
+ * Codec IO
+ */
+#define snd_soc_read(codec, reg) codec->read(reg)
+#define snd_soc_write(codec, reg, value) codec->write(reg, value)
+
+typedef struct snd_soc_codec snd_soc_codec_t;
+typedef struct snd_soc_pcm_codec snd_soc_pcm_codec_t;
+typedef struct snd_soc_platform snd_soc_platform_t;
+typedef struct snd_soc_pcm_interface snd_soc_pcm_interface_t;
+typedef struct snd_soc_pcm_stream snd_soc_pcm_stream_t;
+typedef struct snd_soc_ops snd_soc_ops_t;
+typedef struct snd_soc_hw_bus snd_soc_hw_bus_t;
+typedef struct snd_soc_hw_mode snd_soc_hw_mode_t;
+
+/*
+ * Queries SoC layer for available interface
+ */
+int snd_soc_iface_query(int iface_type, int num);
+
+int snd_soc_register_codec(snd_soc_codec_t *codec);
+void snd_soc_unregister_codec(snd_soc_codec_t *codec);
+
+int snd_soc_register_platform(snd_soc_platform_t *platform);
+void snd_soc_unregister_platform(snd_soc_platform_t *platform);
+
+int snd_soc_register_interface(snd_soc_pcm_interface_t *iface);
+void snd_soc_unregister_interface(snd_soc_pcm_interface_t *iface);
+
+int snd_soc_pcm_new(snd_soc_codec_t *codec, int dev_no, snd_soc_pcm_codec_t *pcm_c, 
+		snd_pcm_t **rpcm, int play, int capt, int iface_type, int num);
+
+int snd_soc_set_runtime_hw(snd_pcm_substream_t *substream, 
+	const snd_pcm_hardware_t *hw);
+
+int snd_soc_update_bits(snd_soc_codec_t *codec, unsigned short reg,
+				unsigned short mask, unsigned short value);
+				
+int snd_soc_test_bits(snd_soc_codec_t *codec, unsigned short reg,
+				unsigned short mask, unsigned short value);
+
+/*
+ *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_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_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);
+
+/* SoC supported stream types */
+struct snd_soc_pcm_stream {
+	char *sname;
+	unsigned int rates;		/* SNDRV_PCM_RATE_* */
+	u64 formats;			/* SNDRV_PCM_FMTBIT_* */
+	unsigned int rate_min;		/* min rate */
+	unsigned int rate_max;		/* max rate */
+	unsigned int channels_min;	/* min channels */
+	unsigned int channels_max;	/* max channels */
+};
+
+/* 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 {
+	u32 hformat;	/* SND_SOC_HWFMT_* */
+	u32 hbits;		/* SND_SOC_HWBITS() */
+	u32 rate;		/* sample rate */
+	u32 fs;			/* ratio of rate:bclk */ 
+	long priv1;		/* private mode data 1 */
+	long priv2;		/* private mode data 2 */
+	long priv3;		/* private mode data 3 */
+};
+
+/* SoC hardware bus and all modes */
+struct snd_soc_hw_bus {
+	int num_hmodes;				/* number of hw modes */
+	snd_soc_hw_mode_t *hmodes;	/* array of supported audio hw modes */	
+};
+
+/* SoC Codec pcm stream */
+struct snd_soc_pcm_codec {
+	char *name;
+
+	/* codec pcm capabilities */
+	snd_soc_pcm_stream_t playback;
+	snd_soc_pcm_stream_t capture;
+	snd_soc_hw_bus_t hw;
+	
+	/* runtime info */
+	snd_soc_hw_mode_t hw_runtime;
+	snd_soc_ops_t ops;
+	snd_soc_pcm_interface_t *pcm_i;
+	
+	/* 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;
+	
+	int probed;
+	int (*probe)(snd_soc_pcm_interface_t *interface);
+	void (*remove)(snd_soc_pcm_interface_t *interface);
+	int (*suspend)(snd_soc_pcm_interface_t *interface, pm_message_t state);
+	int (*resume)(snd_soc_pcm_interface_t *interface);
+	
+	/* interface pcm capabilities */
+	snd_soc_pcm_stream_t capture;
+	snd_soc_pcm_stream_t playback;
+	snd_soc_hw_bus_t hw;
+	
+	/* runtime info */
+	snd_soc_hw_mode_t hw_runtime;
+	snd_soc_pcm_codec_t *pcm_c;
+	snd_soc_ops_t ops;
+	snd_card_t *card;
+	ac97_t *ac97;
+	
+	/* private data */
+	void *platform_data;
+	
+	struct list_head list;
+};
+
+/* SoC Codec interface */
+struct snd_soc_codec {
+	char *name;
+	char *longname;
+	struct module *owner;
+		
+	int probed;
+	int (*probe)(snd_soc_codec_t *codec);
+	void (*remove)(snd_soc_codec_t *codec);
+	int (*suspend)(snd_soc_codec_t *codec, pm_message_t state);
+	int (*resume)(snd_soc_codec_t *codec);
+	
+	snd_card_t *card;
+	snd_pcm_t *pcm;
+	struct platform_device pdev;
+	snd_soc_pcm_interface_t *interface;
+	void *private_data;
+	
+	unsigned int (*read)(u16);
+	int (*write)(u16, unsigned int);
+	
+	struct list_head list;
+	struct list_head dpm_widgets;
+	struct list_head dpm_paths;
+};
+
+/* SoC platform interface */
+struct snd_soc_platform {
+	char *name;
+	
+	int	(*probe)(struct device * dev);
+	int	(*remove)(struct device * dev);
+	struct bus_type	* bus;
+	int (*pcm_new)(snd_card_t *, snd_soc_pcm_codec_t *, int, int, snd_pcm_t *);
+	snd_pcm_ops_t *pcm_ops;
+};
+
+struct soc_enum {
+	unsigned short reg;
+	unsigned char shift_l;
+	unsigned char shift_r;
+	unsigned int mask;
+	const char **texts;
+	void *dpm;
+};
+
+#endif
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/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/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..11d39f5
--- /dev/null
+++ b/sound/soc/Makefile
@@ -0,0 +1,5 @@
+
+snd-soc-core-objs := soc-core.o soc-dpm.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..b58d51f
--- /dev/null
+++ b/sound/soc/codecs/Kconfig
@@ -0,0 +1,30 @@
+config SND_SOC_AC97_CODEC
+	tristate "SoC AC97 support"
+	depends SND_SOC
+	help
+	  Say Y or M if you want to support AC97 codecs under ALSA SoC.
+
+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_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_WM9713_VOICE
+	tristate "SoC driver for the WM9713 Voice codec"
+	depends SND_SOC
+	depends SND_SOC_AC97_CODEC
+	help
+	  Say Y or M if you want to support the WM9713 voice codec.
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
new file mode 100644
index 0000000..1c564aa
--- /dev/null
+++ b/sound/soc/codecs/Makefile
@@ -0,0 +1,11 @@
+snd-soc-ac97-objs := ac97.o
+snd-soc-wm8753-objs := wm8753.o
+snd-soc-wm8731-objs := wm8731.o
+snd-soc-wm8750-objs := wm8750.o
+snd-soc-wm9713-voice-objs := wm9713-voice.o
+
+obj-$(CONFIG_SND_SOC_AC97_CODEC)	+= snd-soc-ac97.o
+obj-$(CONFIG_SND_SOC_WM8753)	+= snd-soc-wm8753.o
+obj-$(CONFIG_SND_SOC_WM8731)	+= snd-soc-wm8731.o
+obj-$(CONFIG_SND_SOC_WM8750)	+= snd-soc-wm8750.o
+obj-$(CONFIG_SND_SOC_WM9713_VOICE)	+= snd-soc-wm9713-voice.o
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
new file mode 100644
index 0000000..c4e1885
--- /dev/null
+++ b/sound/soc/codecs/ac97.c
@@ -0,0 +1,127 @@
+/*
+ * 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 <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/ac97_codec.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+
+static int ac97_soc_add_widgets(snd_soc_codec_t * codec)
+{
+	return 0;
+}
+
+static void ac97_soc_device_release(struct device * dev)
+{
+}
+
+static int ac97_soc_suspend(snd_soc_codec_t *codec, pm_message_t state)
+{
+	snd_soc_pcm_interface_t *i = codec->interface;
+	snd_ac97_suspend(i->ac97);
+	return 0;
+}	
+
+static int ac97_soc_resume(snd_soc_codec_t *codec)
+{
+	snd_soc_pcm_interface_t *i = codec->interface;
+	snd_ac97_resume(i->ac97);
+	return 0;
+}
+
+static snd_soc_pcm_codec_t ac97_soc_client = {
+	.name = "AC97 Audio",
+	.playback = {
+		.sname = "AC97 Playback",
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 2,},
+	.capture = {
+		.sname = "AC97 Capture",
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | 
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 2,},
+};
+
+static snd_soc_codec_t ac97_soc_codec;
+static snd_pcm_t *pcm_ac97;
+
+static int ac97_soc_probe(snd_soc_codec_t *codec)
+{
+	int ret;
+
+	if(snd_soc_iface_query(SND_SOC_AC97, 0))
+		return -ENODEV;
+	
+	if((ret = snd_soc_pcm_new(codec, 0, &ac97_soc_client, 
+		&pcm_ac97, 1, 1, SND_SOC_AC97, 0)) < 0)
+		return ret;
+	
+	ac97_soc_add_widgets(&ac97_soc_codec);
+
+	return ret;
+}
+
+/* 
+ * unregister interfaces and clean up
+ */
+static void ac97_soc_remove(snd_soc_codec_t *codec)
+{
+	printk("%s %s %d\n",  __FILE__, __FUNCTION__, __LINE__);
+}
+
+static snd_soc_codec_t ac97_soc_codec = {
+	.name = "SoC AC97",
+	.longname = "ALSA SoC Generic AC97 Codec",
+	.owner = THIS_MODULE,
+	.pdev = {
+		.name		= "SoC AC97 Codec",
+		.id		= -1,
+		.dev		= {.release = ac97_soc_device_release},
+	},
+	.probe = ac97_soc_probe,
+	.remove = ac97_soc_remove,
+	.suspend = ac97_soc_suspend,
+	.resume = ac97_soc_resume,
+};	
+
+static int __init ac97_init(void)
+{	
+	return snd_soc_register_codec(&ac97_soc_codec);
+}
+
+static void __exit ac97_exit(void)
+{
+	snd_soc_unregister_codec(&ac97_soc_codec);
+}
+
+module_init(ac97_init);
+module_exit(ac97_exit);
+
+MODULE_DESCRIPTION("Soc Generic AC97 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
new file mode 100644
index 0000000..03a6b9d
--- /dev/null
+++ b/sound/soc/codecs/wm8731.c
@@ -0,0 +1,655 @@
+/*
+ * wm8731.c  --  WM8731 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/i2c.h>
+#include <linux/pm.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-dpm.h>
+#include <sound/initval.h>
+#include <asm/hardware/scoop.h>
+#include <asm/arch/corgi.h>
+
+#include "wm8731.h"
+
+#define AUDIO_NAME "wm8731"
+#define WM8731_VERSION "0.1"
+
+
+/*
+ * 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)
+
+
+
+/* 
+ * WM8731 2 wire address is determined during powerup.
+ *    low  = WM8731_2W_ADDR1
+ *    high = WM8731_2W_ADDR2
+ */
+#define WM8731_2W_ADDR1	0x1a
+#define WM8731_2W_ADDR2	0x1b
+#define I2C_DRIVERID_WM8731 0xf2fe
+
+
+static unsigned short normal_i2c[] = { WM8731_2W_ADDR1, WM8731_2W_ADDR2,
+                                       I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+struct wm8731_ {
+	struct i2c_client *i2c;
+	snd_pcm_t *pcm_hifi;
+};
+static struct wm8731_ 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. 
+ */
+static u16 reg_cache[WM8731_RESET+1] = {
+    0x0023, 0x0023, 0x0121, 0x0121, 
+    0x0012, 0x0000, 0x0000, 0x0000, 
+    0x0000, 0x0000, 0x0000, 0x0000, 
+    0x0000, 0x0000, 0x0000, 0x0000
+};
+
+#define WM8731_HIFI_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBS_CFS | \
+	SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | \
+	SND_SOC_HWFMT_IB_IF)
+/*
+ * priv1 is srate register setting
+ */
+static snd_soc_hw_mode_t wm8731_hifi[] = {
+
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 8000 ,  64, 0x000c}, //256
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 8000,   96, 0x000e}, //384
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 8000 , 128, 0x004c}, //512
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 8000,  192, 0x004e}, //768
+
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 32000,  64, 0x0018}, //256
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 32000,  96, 0x001a}, //384
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 32000, 128, 0x0058}, //512
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 32000, 192, 0x005a}, //768
+
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 44100,  64, 0x0020}, //256
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 44100,  96, 0x0022}, //384
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 44100, 128, 0x0060}, //512
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 44100, 192, 0x0062}, //768
+
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 48000,  64, 0x0000}, //256
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 48000,  96, 0x0002}, //384
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 48000, 128, 0x0040}, //512
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 48000, 192, 0x0042}, //768
+
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 88200,  32, 0x003c}, //128
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 88200,  48, 0x003e}, //192
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 88200,  64, 0x007c}, //256
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 88200,  96, 0x007e}, //384
+
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 96000,  32, 0x001c}, //128
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 96000,  48, 0x001e}, //192
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 96000,  64, 0x005c}, //256
+	{WM8731_HIFI_HWFMT, SND_SOC_HWBITS(16), 96000,  96, 0x005e}, //384
+};
+
+
+/*
+ * read wm8731 register cache
+ */
+static inline unsigned int wm8731_read_reg_cache(u16 reg)
+{
+	return reg_cache[reg];
+}
+
+/*
+ * write wm8731 register cache
+ */
+static inline void wm8731_write_reg_cache(u16 reg, unsigned int value)
+{
+	printk("wm8731: Writing %x to %x\n", value, reg);
+	reg_cache[reg] = value;
+}
+
+static struct i2c_client client_template;
+static int wm8731_reset(struct i2c_client *client);
+	
+/*
+ * Attach WM8731 2 wire client 
+ */
+static int wm8731_i2c_probe(struct i2c_adapter *adap, int addr, int kind)
+{		 
+    client_template.adapter = adap;
+    client_template.addr = addr;
+	
+    if ((wm8731.i2c = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)) == NULL)
+        return -ENOMEM;
+
+    memcpy(wm8731.i2c, &client_template, sizeof(struct i2c_client));
+	//wm8731_2w_client->data = (void*)&wm8731;
+	
+	if (wm8731_reset(wm8731.i2c) != 0) {
+		kfree (wm8731.i2c);
+		err("cannot reset the WM8731");
+		return -EIO;
+	}
+
+    return i2c_attach_client(wm8731.i2c);
+}
+
+static int wm8731_i2c_detach(struct i2c_client *client)
+{
+	i2c_detach_client(client);
+	kfree(client);
+	return 0;
+}
+
+static int wm8731_i2c_attach(struct i2c_adapter *adap)
+{
+	return i2c_probe(adap, &addr_data, wm8731_i2c_probe);
+}
+
+/* WM8731 2 Wire layer */ 
+static struct i2c_driver wm8731_i2c_driver = {
+	name:           "i2c wm8731 driver",
+	id:             I2C_DRIVERID_WM8731,
+	flags:          I2C_DF_NOTIFY,
+	attach_adapter: wm8731_i2c_attach,
+	detach_client:  wm8731_i2c_detach,
+	command:        NULL,
+};
+
+static struct i2c_client client_template = {
+	name:   "WM8731",
+	flags:  I2C_CLIENT_ALLOW_USE,
+	driver: &wm8731_i2c_driver,
+};
+
+/*
+ * write to the WM8731 register space
+ */
+static int wm8731_2w_write(struct i2c_client *client, u8 reg, u16 value)
+{
+	u8 data[2];
+
+	/* data is 
+	 *   D15..D9 WM8731 register offset
+	 *   D8...D0 register data
+	 */
+	data[0] = (reg << 1) | ((value >> 8) & 0x0001);
+	data[1] = value & 0x00ff;
+
+	wm8731_write_reg_cache (reg, value);
+	if (i2c_master_send(client, data, 2) == 2)
+		return 0;
+	else
+		return -1;
+}
+
+static int wm8731_write (u16 reg, unsigned int value)
+{
+	return wm8731_2w_write(wm8731.i2c, reg, value);	
+}
+
+/* 
+ * reset the WM8731
+ */
+static int wm8731_reset(struct i2c_client *client)
+{
+	return wm8731_2w_write (client, WM8731_RESET, 0);
+}
+
+static const char* wm8731_sidetone_att[] = {"-6dB", "-9dB", "-12dB", "-15dB"};
+
+/*
+static const char* wm8731_base[] = {"Linear Control", "Adaptive Boost"};
+static const char* wm8731_base_filter[] = 
+	{"130Hz @ 48kHz", "200Hz @ 48kHz", "100Hz @ 16kHz", "400Hz @ 48kHz", 
+	"100Hz @ 8kHz", "200Hz @ 8kHz"};
+static const char* wm8731_treble[] = {"8kHz", "4kHz"};
+static const char* wm8731_alc_func[] = {"Off", "Right", "Left", "Stereo"};
+static const char* wm8731_ng_type[] = {"Constant PGA Gain", "Mute ADC Output"};
+static const char* wm8731_3d_func[] = {"Capture", "Playback"};
+static const char* wm8731_3d_uc[] = {"2.2kHz", "1.5kHz"};
+static const char* wm8731_3d_lc[] = {"200Hz", "500Hz"};
+static const char* wm8731_deemp[] = {"None", "32kHz", "44.1kHz", "48kHz"};
+static const char* wm8731_mono_mix[] = {"Stereo", "Left", "Right", "Mono"};
+static const char* wm8731_dac_phase[] = {"Non Inverted", "Inverted"};
+static const char* wm8731_line_mix[] = {"Line 1 + 2", "Line 1 - 2", 
+	"Line 1", "Line 2"};
+static const char* wm8731_mono_mux[] = {"Line Mix", "Rx Mix"};
+static const char* wm8731_right_mux[] = {"Line 2", "Rx Mix"};
+static const char* wm8731_left_mux[] = {"Line 1", "Rx Mix"};
+static const char* wm8731_rxmsel[] = {"RXP - RXN", "RXP + RXN", "RXP", "RXN"};
+static const char* wm8731_sidetone_mux[] = {"Left PGA", "Mic 1", "Mic 2", "Right PGA"};
+static const char* wm8731_mono2_src[] = {"Inverted Mono 1", "Left", "Right", "Left + Right"};
+static const char* wm8731_out3[] = {"VREF", "ROUT2", "Left + Right"};
+static const char* wm8731_out4[] = {"VREF", "LOUT2", "Left + Right"};
+static const char* wm8731_radcsel[] = {"PGA", "Line 2 or RXP-RXN", "Left + Right + Mono Mix"};
+static const char* wm8731_ladcsel[] = {"PGA", "Line 1 or RXP-RXN", "Line 1 DC"};
+static const char* wm8731_mono_adc[] = {"Stereo", "Analogue Mix Left", "Analogue Mix Right",
+	"Digital Mono Mix"};
+static const char* wm8731_adc_hp[] = {"3.4Hz @ 48kHz", "82Hz @ 16k", "82Hz @ 8kHz", "170Hz @ 8kHz"};
+static const char* wm8731_adc_filter[] = {"HiFi", "Voice"};
+
+static const struct soc_enum wm8731_enum[] = {
+SOC_ENUM_SINGLE(WM8731_BASS, 7, 2, wm8731_base),
+SOC_ENUM_SINGLE(WM8731_BASS, 4, 6, wm8731_base_filter),
+SOC_ENUM_SINGLE(WM8731_TREBLE, 6, 2, wm8731_treble),
+SOC_ENUM_SINGLE(WM8731_ALC1, 7, 4, wm8731_alc_func),
+SOC_ENUM_SINGLE(WM8731_NGATE, 1, 2, wm8731_ng_type),
+SOC_ENUM_SINGLE(WM8731_3D, 7, 2, wm8731_3d_func),
+SOC_ENUM_SINGLE(WM8731_3D, 6, 2, wm8731_3d_uc),
+SOC_ENUM_SINGLE(WM8731_3D, 5, 2, wm8731_3d_lc),
+SOC_ENUM_SINGLE(WM8731_DAC, 1, 4, wm8731_deemp),
+SOC_ENUM_SINGLE(WM8731_DAC, 4, 4, wm8731_mono_mix),
+SOC_ENUM_SINGLE(WM8731_DAC, 6, 2, wm8731_dac_phase),
+SOC_ENUM_SINGLE(WM8731_INCTL1, 3, 4, wm8731_line_mix),
+SOC_ENUM_SINGLE(WM8731_INCTL1, 2, 2, wm8731_mono_mux),
+SOC_ENUM_SINGLE(WM8731_INCTL1, 1, 2, wm8731_right_mux),
+SOC_ENUM_SINGLE(WM8731_INCTL1, 0, 2, wm8731_left_mux),
+SOC_ENUM_SINGLE(WM8731_INCTL2, 6, 4, wm8731_rxmsel),
+SOC_ENUM_SINGLE(WM8731_INCTL2, 4, 4, wm8731_sidetone_mux),
+SOC_ENUM_SINGLE(WM8731_OUTCTL, 7, 4, wm8731_mono2_src),
+SOC_ENUM_SINGLE(WM8731_OUTCTL, 0, 3, wm8731_out3),
+SOC_ENUM_SINGLE(WM8731_OUTCTL, 0, 3, wm8731_out4),
+SOC_ENUM_SINGLE(WM8731_ADCIN, 2, 3, wm8731_radcsel),
+SOC_ENUM_SINGLE(WM8731_ADCIN, 0, 3, wm8731_ladcsel),
+SOC_ENUM_SINGLE(WM8731_ADCIN, 4, 4, wm8731_mono_adc),
+SOC_ENUM_SINGLE(WM8731_ADC, 2, 4, wm8731_adc_hp),
+SOC_ENUM_SINGLE(WM8731_ADC, 4, 2, wm8731_adc_filter),
+};*/
+
+static const struct soc_enum wm8731_enum[] = {
+	SOC_ENUM_SINGLE(WM8731_APANA, 6, 2, wm8731_sidetone_att),
+};
+
+static const snd_kcontrol_new_t wm8731_snd_controls[] = {
+SOC_SINGLE("Left Out 1 Volume", WM8731_LOUT1V, 0, 127, 0),
+SOC_SINGLE("Left Out 1 ZC Switch", WM8731_LOUT1V, 7, 1, 0),
+SOC_SINGLE("Right Out 1 Volume", WM8731_ROUT1V, 0, 127, 0),
+SOC_SINGLE("Right Out 1 ZC Switch", WM8731_ROUT1V, 7, 1, 0),
+
+SOC_SINGLE("Capture Left Volume", WM8731_LINVOL, 0, 31, 0),
+SOC_SINGLE("Capture Left Switch", WM8731_LINVOL, 7, 1, 1),
+SOC_SINGLE("Capture Right Volume", WM8731_RINVOL, 0, 31, 0),
+SOC_SINGLE("Capture Right Switch", WM8731_RINVOL, 7, 1, 1),
+
+SOC_ENUM("Sidetone Attenuation", wm8731_enum[0]),
+SOC_SINGLE("Sidetone Switch", WM8731_APANA, 5, 1, 1),
+};
+
+/*
+Mic Boost Switch
+Mic Switch 
+*/
+
+
+
+	/*
+
+
+SOC_SINGLE("Right Out 2 Volume", WM8731_ROUT2V, 0, 127, 0),
+SOC_SINGLE("Right Out 2 ZC Switch", WM8731_ROUT2V, 7, 1, 0),
+
+SOC_SINGLE("Right Mux Right Mixer Volume", WM8731_ROUTM1, 4, 7, 1),
+
+SOC_SINGLE("Sidetone Right Mixer Volume", WM8731_ROUTM2, 4, 7, 1),
+SOC_SINGLE("Voice Right Mixer Volume", WM8731_ROUTM2, 0, 7, 1),
+
+SOC_SINGLE("Mono Mux Mono Mixer Volume", WM8731_MOUTM1, 4, 7, 1),
+SOC_SINGLE("Sidetone Mono Mixer Volume", WM8731_MOUTM2, 4, 7, 1),
+SOC_SINGLE("Voice Mono Mixer Volume", WM8731_MOUTM2, 4, 7, 1),
+
+SOC_SINGLE("Mono Volume", WM8731_MOUTV, 0, 127, 0),
+SOC_SINGLE("Mono ZC Switch", WM8731_MOUTV, 7, 1, 0),
+SOC_ENUM("Mono 2 Out", wm8731_enum[17]),
+
+
+SOC_SINGLE("Capture Right Mix Switch", WM8731_RECMIX1, 7, 1, 0),
+SOC_SINGLE("Capture Right Mix Volume", WM8731_RECMIX1, 4, 7, 1),
+SOC_SINGLE("Capture Left Mix Switch", WM8731_RECMIX1, 3, 1, 0),
+SOC_SINGLE("Capture Left Mix Volume", WM8731_RECMIX1, 0, 7, 1),
+SOC_SINGLE("Capture Mono Mix Switch", WM8731_RECMIX2, 3, 1, 0),
+SOC_SINGLE("Capture Mono Mix Volume", WM8731_RECMIX2, 0, 7, 1),
+
+
+
+SOC_ENUM("Capture Mono Mix", wm8731_enum[20]),
+SOC_ENUM("Capture Filter Select", wm8731_enum[22]),
+SOC_ENUM("Capture Filter Cut-off", wm8731_enum[21]),
+SOC_SINGLE("Capture Filter Switch", WM8731_ADC, 0, 1, 1),
+
+SOC_SINGLE("ALC Target Volume", WM8731_ALC1, 0, 7, 0),
+SOC_SINGLE("ALC Max Volume", WM8731_ALC1, 4, 7, 0),
+SOC_ENUM("ALC Function", wm8731_enum[3]),
+SOC_SINGLE("ALC ZC Switch", WM8731_ALC2, 8, 1, 0),
+SOC_SINGLE("ALC Hold Time", WM8731_ALC2, 0, 15, 1),
+SOC_SINGLE("ALC Decay Time", WM8731_ALC3, 4, 15, 1),
+SOC_SINGLE("ALC Attack Time", WM8731_ALC3, 0, 15, 0),
+SOC_SINGLE("ALC NG Threshold", WM8731_NGATE, 3, 31, 0),
+SOC_ENUM("ALC NG Type", wm8731_enum[4]),
+SOC_SINGLE("ALC NG Switch", WM8731_NGATE, 0, 1, 0),
+
+SOC_ENUM("3D Function", wm8731_enum[5]),
+SOC_ENUM("3D Upper Cut-off", wm8731_enum[6]),
+SOC_ENUM("3D Lower Cut-off", wm8731_enum[7]),
+SOC_SINGLE("3D Volume", WM8731_3D, 1, 15, 0),
+SOC_SINGLE("3D Switch", WM8731_3D, 0, 1, 0),
+
+SOC_SINGLE("ADC 6dB Attenuate", WM8731_ADCTL1, 2, 1, 0),
+SOC_SINGLE("DAC 6dB Attenuate", WM8731_ADCTL1, 1, 1, 0),
+
+SOC_ENUM("De-emphasis", wm8731_enum[8]),
+SOC_SINGLE("DAC Switch", WM8731_DAC, 3, 1, 1),
+
+SOC_ENUM("DAC Mono Mix", wm8731_enum[9]),
+SOC_ENUM("DAC Phase", wm8731_enum[10]),
+
+SOC_ENUM("Line Mix Select", wm8731_enum[11]),
+SOC_ENUM("Mono Mux Select", wm8731_enum[12]),
+SOC_ENUM("Right Mux Select", wm8731_enum[13]),
+SOC_ENUM("Left Mux Select", wm8731_enum[14]),
+
+SOC_ENUM("Differential Mix", wm8731_enum[15]),
+SOC_ENUM("Mic Sidetone Mux", wm8731_enum[16]),
+SOC_SINGLE("ALC Mix Line Switch", WM8731_INCTL2, 3, 1, 0),
+SOC_SINGLE("ALC Mix Mic 2 Switch", WM8731_INCTL2, 2, 1, 0),
+SOC_SINGLE("ALC Mix Mic 1 Switch", WM8731_INCTL2, 1, 1, 0),
+SOC_SINGLE("ALC Mix Rx Switch", WM8731_INCTL2, 0, 1, 0),
+
+SOC_ENUM("Out3 Output", wm8731_enum[18]),
+SOC_ENUM("Out4 Output", wm8731_enum[19]),
+
+SOC_SINGLE("Mic 1 Amp Switch", WM8731_PWR2, 8, 1, 0),
+SOC_SINGLE("Mic 2 Amp Switch", WM8731_PWR2, 7, 1, 0),
+SOC_SINGLE("Mic 2 Volume", WM8731_INCTL1, 7, 3, 0),
+SOC_SINGLE("Mic 1 Volume", WM8731_INCTL1, 5, 3, 0),
+
+};*/
+
+/* add non dpm controls */
+static int wm8731_add_controls(snd_soc_codec_t *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;
+	}
+}
+
+/*
+ * Power up the codec -- WE ARE NOW ALMOST DOING THIS IN DPM
+ */
+static int wm8731_power_up(snd_pcm_substream_t *substream)
+{	
+	mdelay(1);
+	if (wm8731_2w_write(wm8731.i2c, WM8731_PWR, 0x00) != 0)
+		return -EIO;
+
+	return 0;
+}
+
+/* WE CAN USE DPM IN NEAR FUTURE */
+static int wm8731_power_down(snd_pcm_substream_t *substream)
+{
+	if (wm8731_2w_write(wm8731.i2c, WM8731_PWR, 0x0f0) != 0) {
+ 		err("could not powerdown WM8731");
+		return -EIO;
+	}
+	return 0;
+}
+
+
+static int wm8731_pcm_hifi_startup(snd_pcm_substream_t *substream)
+{
+	wm8731_power_up(substream);
+	return 0;
+}
+
+static void wm8731_pcm_hifi_shutdown(snd_pcm_substream_t *substream)
+{	
+	wm8731_power_down(substream);
+}
+
+static int wm8731_pcm_hifi_prepare(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	u16 iface = 0;
+	
+	/* set master/slave audio interface */
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_CLOCK_MASK) {
+		case SND_SOC_HWFMT_CBM_CFM:
+			iface |= 0x0020;
+			break;
+		case SND_SOC_HWFMT_CBM_CFS:
+			break;
+	}
+	
+	/* interface format */
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_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(pcm_c->hw_runtime.hbits) {
+		case SND_SOC_HWBITS(16):
+			break;
+		case SND_SOC_HWBITS(20):
+			iface |= 0x0004;
+			break;
+		case SND_SOC_HWBITS(24):
+			iface |= 0x0008;
+			break;
+		case SND_SOC_HWBITS(32):
+			iface |= 0x000c;
+			break;
+	}
+
+	/* clock inversion */
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_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;
+	}
+	
+	if (wm8731_2w_write(wm8731.i2c, WM8731_ACTIVE, 0x00) != 0)
+		return -EIO;
+
+	/* set rate */
+	wm8731_2w_write(wm8731.i2c, WM8731_SRATE, pcm_c->hw_runtime.priv1);
+
+	wm8731_2w_write(wm8731.i2c, WM8731_IFACE, iface);
+
+	if (wm8731_2w_write(wm8731.i2c, WM8731_ACTIVE, 0x01) != 0)
+		return -EIO;
+
+	return 0;
+}
+
+static void wm8731_device_release(struct device * dev)
+{
+}
+
+static snd_soc_pcm_codec_t wm8731_pcm_hifi_client = {
+	.name = "WM8731 PCM Codec",
+	.playback = {
+		.sname = "HiFi Playback",
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 |
+		SNDRV_PCM_RATE_96000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 2,},
+/*	.capture = {
+		.sname = "Voice Capture",
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | 
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 |
+		SNDRV_PCM_RATE_96000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 2,},*/
+	.ops = {
+		.startup = wm8731_pcm_hifi_startup,
+		.shutdown = wm8731_pcm_hifi_shutdown,
+		.prepare = wm8731_pcm_hifi_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8731_hifi),
+		.hmodes = &wm8731_hifi[0],},
+};
+
+static snd_soc_codec_t wm8731_soc_codec;
+
+/*
+ * initialise the WM8731 driver
+ * register the mixer and dsp interfaces with the kernel 
+ */
+static int wm8731_probe(snd_soc_codec_t *codec)
+{
+	int ret;
+	int dev_no = 0;
+	int reg;
+	
+	info("WM8731 Audio Codec %s", WM8731_VERSION);
+
+	
+	/* check platform for interfaces */
+	if(snd_soc_iface_query(SND_SOC_I2S, 0)) {
+		err("I2S interface not available");
+		return -ENODEV;
+	}
+	
+	if((ret = snd_soc_pcm_new(codec, dev_no++, &wm8731_pcm_hifi_client, 
+		&wm8731.pcm_hifi, 1, 0, SND_SOC_I2S, 0)) < 0)
+			return ret;
+
+	if ((ret = i2c_add_driver(&wm8731_i2c_driver)) != 0) {
+		err("can't add i2c driver");
+		return ret;
+	}
+
+	reg = wm8731_read_reg_cache(WM8731_PWR);
+	wm8731_2w_write(wm8731.i2c, WM8731_PWR, reg);
+
+	reg = wm8731_read_reg_cache(WM8731_APANA);
+	wm8731_2w_write(wm8731.i2c, WM8731_APANA, reg);
+	reg = wm8731_read_reg_cache(WM8731_APDIGI);
+	wm8731_2w_write(wm8731.i2c, WM8731_APDIGI, reg);
+	
+	/* set the update bits */
+	reg = wm8731_read_reg_cache(WM8731_LOUT1V);
+	wm8731_2w_write(wm8731.i2c, WM8731_LOUT1V, reg | 0x0100);
+	reg = wm8731_read_reg_cache(WM8731_ROUT1V);
+	wm8731_2w_write(wm8731.i2c, WM8731_ROUT1V, reg | 0x0100);
+	reg = wm8731_read_reg_cache(WM8731_LINVOL);
+	wm8731_2w_write(wm8731.i2c, WM8731_LINVOL, reg | 0x0100);
+	reg = wm8731_read_reg_cache(WM8731_RINVOL);
+	wm8731_2w_write(wm8731.i2c, WM8731_RINVOL, reg | 0x0100);
+
+	wm8731_add_controls(&wm8731_soc_codec);
+	//wm8731_add_widgets(&wm8731_soc_codec);
+
+	set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_APM_ON | CORGI_SCP_MUTE_L | CORGI_SCP_MUTE_R );	//  All on
+
+	return ret;
+}
+
+/* 
+ * unregister interfaces and clean up
+ */
+static void wm8731_remove(snd_soc_codec_t *codec)
+{
+	i2c_del_driver(&wm8731_i2c_driver);
+}
+
+static snd_soc_codec_t wm8731_soc_codec = {
+	.name = "WM8731",
+	.longname = "wm8731 long name",
+	.owner = THIS_MODULE,
+	.pdev = {
+		.name		= "wm8731 pdev",
+		.id		= -1,
+		.dev		= {
+			.release = wm8731_device_release,
+		},
+	},
+	.probe = wm8731_probe,
+	.remove = wm8731_remove,
+	.read = wm8731_read_reg_cache,
+	.write = wm8731_write,
+};	
+
+static int __init wm8731_init(void)
+{	
+	return snd_soc_register_codec(&wm8731_soc_codec);
+}
+
+static void __exit wm8731_exit(void)
+{
+	snd_soc_unregister_codec(&wm8731_soc_codec);
+}
+
+module_init(wm8731_init);
+module_exit(wm8731_exit);
+
+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..c0c3894
--- /dev/null
+++ b/sound/soc/codecs/wm8731.h
@@ -0,0 +1,56 @@
+/*
+ * 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
+
+
+/* Voice DAC sample rates */
+#define WM8731_VD8K		(0x6 << 6)
+#define WM8731_VD12K	(0x5 << 6)
+#define WM8731_VD16K	(0x2 << 6)
+#define WM8731_VD24K	(0x4 << 6)
+#define WM8731_VD48K	(0x0 << 6)
+
+
+/* Hifi ADC/DAC sample rates */
+#define WM8731_A8D8		0x0006
+#define WM8731_A8D48	0x0004
+#define WM8731_A12D12	0x0008
+#define WM8731_A16D16	0x000a
+#define WM8731_A24D24	0x001c
+#define WM8731_A32D32	0x000c
+#define WM8731_A48D8	0x0002
+#define WM8731_A48D48	0x0000
+#define WM8731_A96D96	0x000e
+
+struct wm8731_mixer_t {
+	int dev_mixer;
+};
+
+#endif
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
new file mode 100644
index 0000000..42afeee
--- /dev/null
+++ b/sound/soc/codecs/wm8753.c
@@ -0,0 +1,1356 @@
+/*
+ * wm8753.c  --  WM8753 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.
+ */
+
+#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/i2c.h>
+#include <linux/pm.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-dpm.h>
+#include <sound/initval.h>
+
+#include "wm8753.h"
+
+#define AUDIO_NAME "wm8753"
+#define WM8753_VERSION "0.1"
+
+
+/*
+ * 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 int hifi = 1;
+module_param(hifi, int, 0);
+MODULE_PARM_DESC(hifi, "enable AUX ADC sysfs entries");
+
+static int voice = 1;
+module_param(voice, int, 0);
+MODULE_PARM_DESC(voice, "enable codec status sysfs entries");
+
+	
+/* 
+ * WM8753 2 wire address is determined by GPIO5
+ * state during powerup.
+ *    low  = WM8753_2W_ADDR1
+ *    high = WM8753_2W_ADDR2
+ */
+#define WM8753_2W_ADDR1	0x1a
+#define WM8753_2W_ADDR2	0x1b
+#define I2C_DRIVERID_WM8753 0xfefe
+
+
+static unsigned short normal_i2c[] = { WM8753_2W_ADDR1, WM8753_2W_ADDR2,
+                                       I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+struct wm8753_ {
+	struct i2c_client *i2c;
+	snd_pcm_t *pcm_voice;
+	snd_pcm_t *pcm_hifi;
+};
+static struct wm8753_ wm8753;
+
+/*
+ * 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 u16 reg_cache[] = {
+    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
+};
+
+/* PLL divisors */
+struct _pll_div {
+	u32 hz;
+	u32 n;
+	u32 k;
+};
+
+/* 
+ * MCLCK crystal frequency
+ */
+#define MCLK_13MHZ
+
+static struct _pll_div pll_div[] = {
+#ifdef MCLK_13MHZ	
+   {12288000,    0x7,    0x23F54A},
+   {11289600,    0x6,    0x3CA2F5},
+#endif
+#ifdef MCLK_12MHZ	
+   {12288000,    0x8,    0x0C49BA},
+   {11289600,    0x7,    0x21B08A},
+#endif
+#ifdef MCLK_12_288MHZ
+   {12288000,	0x0,    0x000000},
+   {11289600,	0x7,	0x166667},
+#endif
+   {0,           0,      0}  /* must be last */
+};
+
+#define WM8753_HIFI_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J | SND_SOC_HWFMT_RIGHT_J | \
+	SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS | SND_SOC_HWFMT_CBS_CFS | \
+	SND_SOC_HWFMT_NB_NF | SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | \
+	SND_SOC_HWFMT_IB_IF)
+
+/*
+ * priv1 is pll/mclk freq
+ * priv2 is bits[15..8] = MCLK divisor, bits[7..0] = sr
+ */
+static snd_soc_hw_mode_t wm8753_hifi[] = {
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		8000,	768,	12288000, 	0x020c},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		8000,	384,	12288000, 	0x040c},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		8000,	192,	12288000, 	0x080c},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		8000,	96,		12288000, 	0x100c},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		11025,	512,	11289600,	0x0230},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		11025,	256,	11289600,	0x0430},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		11025, 	128,	11289600,	0x0830},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		11025,	64,		11289600,	0x1030},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		12000, 	512,	12288000,   0x0210},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		12000, 	256,	12288000,   0x0410},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		12000, 	128,	12288000,   0x0810},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		12000, 	64,		12288000,   0x1010},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		16000, 	384,	12288000,   0x0214},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		16000, 	192,	12288000,   0x0414},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		16000, 	96,		12288000,   0x0814},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		16000, 	48, 	12288000,   0x1014},
+
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		22050, 	512,	11289600,   0x0034},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		22050, 	256,	11289600,   0x0234},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		22050, 	128,	11289600,   0x0434},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		22050, 	64,		11289600,   0x0834},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		22050, 	32,		11289600,   0x1034},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		24000, 	512,	12288000,   0x0038},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		24000, 	256,	12288000,   0x0238},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		24000, 	128,	12288000,   0x0438},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		24000, 	64,		12288000,   0x0838},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		24000, 	32,		12288000,   0x1038},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		32000, 	384,	12288000,	0x0018},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		32000, 	192,	12288000,	0x0218},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		32000, 	96,		12288000,	0x0418},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		32000, 	48,		12288000,	0x0818},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		44100, 	256,	11289600,  	0x0020},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		44100, 	128,	11289600,  	0x0220},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		44100, 	64,		11289600,  	0x0420},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		44100, 	32,		11289600,  	0x0820},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		48000, 	256,	12288000,  	0x0000},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		48000, 	128,	12288000,  	0x0200},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		48000, 	64,		12288000,  	0x0400},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		48000, 	32,		12288000,  	0x0800},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		88200, 	128,	11289600,   0x003c},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		88200, 	64,		11289600,   0x023c},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		88200, 	32,		11289600,   0x043c},
+	
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		96000, 	128,	12288000,   0x001c},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		96000, 	64,		12288000,   0x021c},
+	{WM8753_HIFI_HWFMT, 	SND_SOC_HWBITS(16),		96000, 	32,		12288000,   0x041c},
+};
+
+#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_CBM_CFM | \
+	SND_SOC_HWFMT_CBM_CFS | SND_SOC_HWFMT_CBS_CFS | SND_SOC_HWFMT_NB_NF | \
+	SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | SND_SOC_HWFMT_IB_IF)
+
+/*
+ * priv1 is pll/mclk freq
+ * priv2 is bits[15..8] = PCM divisor, bits[7..0] = psr
+ */
+static snd_soc_hw_mode_t wm8753_voice[] = {
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		48000,	256,	12288000, 	0x0000},
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		44100,	256,	11289600, 	0x0000},
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		32000,	384,	12288000, 	0x0001},
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		24000,	256,	12288000, 	0x0400},
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		22050,	256,	11289600, 	0x0400},
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		16000,	256,	12288000, 	0x0200},
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		16000,	384,	12288000, 	0x0401},
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		8000,	256,	12288000, 	0x0600},
+	{WM8753_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		8000,	384,	12288000, 	0x0501},
+};
+
+/*
+ * read wm8753 register cache
+ */
+static inline unsigned int wm8753_read_reg_cache(u16 reg)
+{
+	if(reg < 1 || reg > (ARRAY_SIZE(reg_cache) + 1))
+		return -1;
+	return reg_cache[reg - 1];
+}
+
+/*
+ * write wm8753 register cache
+ */
+static inline void wm8753_write_reg_cache(u16 reg, unsigned int value)
+{
+	if(reg < 1 || reg > (ARRAY_SIZE(reg_cache) + 1))
+		return;
+	reg_cache[reg - 1] = value;
+}
+
+static struct i2c_client client_template;
+static int wm8753_reset(struct i2c_client *client);
+	
+/*
+ * Attach WM8753 2 wire client 
+ */
+static int wm8753_i2c_probe(struct i2c_adapter *adap, int addr, int kind)
+{		 
+    client_template.adapter = adap;
+    client_template.addr = addr;
+	
+    if ((wm8753.i2c = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)) == NULL)
+        return -ENOMEM;
+
+    memcpy(wm8753.i2c, &client_template, sizeof(struct i2c_client));
+	//wm8753_2w_client->data = (void*)&wm8753;
+	
+	if (wm8753_reset(wm8753.i2c) != 0) {
+		kfree (wm8753.i2c);  //liam - looks like somebody is still using this.....
+		err("cannot reset the WM8753");
+		return -EIO;
+	}
+
+    return i2c_attach_client(wm8753.i2c);
+}
+
+static int wm8753_i2c_detach(struct i2c_client *client)
+{
+	i2c_detach_client(client);
+	kfree(client);
+	return 0;
+}
+
+static int wm8753_i2c_attach(struct i2c_adapter *adap)
+{
+	return i2c_probe(adap, &addr_data, wm8753_i2c_probe);
+}
+
+/* WM8753 2 Wire layer */ 
+static struct i2c_driver wm8753_i2c_driver = {
+	name:           "i2c wm8753 driver",
+	id:             I2C_DRIVERID_WM8753,
+	flags:          I2C_DF_NOTIFY,
+	attach_adapter: wm8753_i2c_attach,
+	detach_client:  wm8753_i2c_detach,
+	command:        NULL,
+};
+
+static struct i2c_client client_template = {
+	name:   "WM8753",
+	flags:  I2C_CLIENT_ALLOW_USE,
+	driver: &wm8753_i2c_driver,
+};
+
+/*
+ * write to the WM8753 register space
+ */
+static int wm8753_2w_write(struct i2c_client *client, u8 reg, u16 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 (reg, value);
+	if (i2c_master_send(client, data, 2) == 2)
+		return 0;
+	else
+		return -1;
+}
+
+static int wm8753_write (u16 reg, unsigned int value)
+{
+	return wm8753_2w_write(wm8753.i2c, reg, value);	
+}
+
+/* 
+ * reset the WM8753
+ */
+static int wm8753_reset(struct i2c_client *client)
+{
+	return wm8753_2w_write (client, 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),
+SOC_ENUM_SINGLE(WM8753_BASS, 4, 6, wm8753_base_filter),
+SOC_ENUM_SINGLE(WM8753_TREBLE, 6, 2, wm8753_treble),
+SOC_ENUM_SINGLE(WM8753_ALC1, 7, 4, wm8753_alc_func),
+SOC_ENUM_SINGLE(WM8753_NGATE, 1, 2, wm8753_ng_type),
+SOC_ENUM_SINGLE(WM8753_3D, 7, 2, wm8753_3d_func),
+SOC_ENUM_SINGLE(WM8753_3D, 6, 2, wm8753_3d_uc),
+SOC_ENUM_SINGLE(WM8753_3D, 5, 2, wm8753_3d_lc),
+SOC_ENUM_SINGLE(WM8753_DAC, 1, 4, wm8753_deemp),
+SOC_ENUM_SINGLE(WM8753_DAC, 4, 4, wm8753_mono_mix),
+SOC_ENUM_SINGLE(WM8753_DAC, 6, 2, wm8753_dac_phase),
+SOC_ENUM_SINGLE(WM8753_INCTL1, 3, 4, wm8753_line_mix),
+SOC_ENUM_SINGLE(WM8753_INCTL1, 2, 2, wm8753_mono_mux),
+SOC_ENUM_SINGLE(WM8753_INCTL1, 1, 2, wm8753_right_mux),
+SOC_ENUM_SINGLE(WM8753_INCTL1, 0, 2, wm8753_left_mux),
+SOC_ENUM_SINGLE(WM8753_INCTL2, 6, 4, wm8753_rxmsel),
+SOC_ENUM_SINGLE(WM8753_INCTL2, 4, 4, wm8753_sidetone_mux),
+SOC_ENUM_SINGLE(WM8753_OUTCTL, 7, 4, wm8753_mono2_src),
+SOC_ENUM_SINGLE(WM8753_OUTCTL, 0, 3, wm8753_out3),
+SOC_ENUM_SINGLE(WM8753_OUTCTL, 0, 3, wm8753_out4),
+SOC_ENUM_SINGLE(WM8753_ADCIN, 2, 3, wm8753_radcsel),
+SOC_ENUM_SINGLE(WM8753_ADCIN, 0, 3, wm8753_ladcsel),
+SOC_ENUM_SINGLE(WM8753_ADCIN, 4, 4, wm8753_mono_adc),
+SOC_ENUM_SINGLE(WM8753_ADC, 2, 4, wm8753_adc_hp),
+SOC_ENUM_SINGLE(WM8753_ADC, 4, 2, wm8753_adc_filter),
+SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel),
+};
+
+static const snd_kcontrol_new_t wm8753_snd_controls[] = {
+SOC_SINGLE("Left PCM Volume", WM8753_LDAC, 0, 255, 0),
+SOC_SINGLE("Right PCM Volume", WM8753_RDAC, 0, 255, 0),
+	
+SOC_SINGLE("Left ADC Volume", WM8753_LADC, 0, 63, 0),
+SOC_SINGLE("Left ADC Switch", WM8753_LADC, 7, 1, 0),
+SOC_SINGLE("Left ADC ZC Switch", WM8753_LADC, 6, 1, 0),
+SOC_SINGLE("Right ADC Volume", WM8753_RADC, 0, 63, 0),
+SOC_SINGLE("Right ADC Switch", WM8753_RADC, 7, 1, 0),
+SOC_SINGLE("Right ADC ZC Switch", WM8753_RADC, 6, 1, 0),
+
+SOC_SINGLE("Left Out 1 Volume", WM8753_LOUT1V, 0, 127, 0),
+SOC_SINGLE("Left Out 1 ZC Switch", WM8753_LOUT1V, 7, 1, 0),
+SOC_SINGLE("Left Out 2 Volume", WM8753_LOUT2V, 0, 127, 0),
+SOC_SINGLE("Left Out 2 ZC Switch", WM8753_LOUT2V, 7, 1, 0),
+	
+SOC_SINGLE("Left Mux Left Mixer Volume", WM8753_LOUTM1, 4, 7, 1),
+
+SOC_SINGLE("Sidetone Left Mixer Volume", WM8753_LOUTM2, 4, 7, 1),
+SOC_SINGLE("Voice Left Mixer Volume", WM8753_LOUTM2, 0, 7, 1),
+
+SOC_SINGLE("Right Out 1 Volume", WM8753_ROUT1V, 0, 127, 0),
+SOC_SINGLE("Right Out 1 ZC Switch", WM8753_ROUT1V, 7, 1, 0),
+SOC_SINGLE("Right Out 2 Volume", WM8753_ROUT2V, 0, 127, 0),
+SOC_SINGLE("Right Out 2 ZC Switch", WM8753_ROUT2V, 7, 1, 0),
+
+SOC_SINGLE("Right Mux Right Mixer Volume", WM8753_ROUTM1, 4, 7, 1),
+
+SOC_SINGLE("Sidetone Right Mixer Volume", WM8753_ROUTM2, 4, 7, 1),
+SOC_SINGLE("Voice Right Mixer Volume", WM8753_ROUTM2, 0, 7, 1),
+
+SOC_SINGLE("Mono Mux Mono Mixer Volume", WM8753_MOUTM1, 4, 7, 1),
+SOC_SINGLE("Sidetone Mono Mixer Volume", WM8753_MOUTM2, 4, 7, 1),
+SOC_SINGLE("Voice Mono Mixer Volume", WM8753_MOUTM2, 4, 7, 1),
+
+SOC_SINGLE("Mono Volume", WM8753_MOUTV, 0, 127, 0),
+SOC_SINGLE("Mono 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_SINGLE("Capture ST Right Mix Volume", WM8753_RECMIX1, 4, 7, 1),
+SOC_SINGLE("Capture ST Left Mix Volume", WM8753_RECMIX1, 0, 7, 1),
+SOC_SINGLE("Capture ST Voice Mix Volume", WM8753_RECMIX2, 0, 7, 1),
+
+SOC_SINGLE("Capture Left Volume", WM8753_LINVOL, 0, 63, 0),
+SOC_SINGLE("Capture Left ZC Switch", WM8753_LINVOL, 6, 1, 0),
+SOC_SINGLE("Capture Left Switch", WM8753_LINVOL, 7, 1, 1),
+SOC_SINGLE("Capture Right Volume", WM8753_RINVOL, 0, 63, 0),
+SOC_SINGLE("Capture Right ZC Switch", WM8753_RINVOL, 6, 1, 0),
+SOC_SINGLE("Capture Right Switch", WM8753_RINVOL, 7, 1, 1),
+
+SOC_ENUM("Capture Mono Mix", wm8753_enum[20]),
+SOC_ENUM("Capture Filter Select", wm8753_enum[22]),
+SOC_ENUM("Capture Filter Cut-off", wm8753_enum[21]),
+SOC_SINGLE("Capture Filter Switch", WM8753_ADC, 0, 1, 1),
+
+SOC_SINGLE("ALC Target Volume", WM8753_ALC1, 0, 7, 0),
+SOC_SINGLE("ALC Max Volume", WM8753_ALC1, 4, 7, 0),
+SOC_ENUM("ALC Function", wm8753_enum[3]),
+SOC_SINGLE("ALC ZC Switch", WM8753_ALC2, 8, 1, 0),
+SOC_SINGLE("ALC Hold Time", WM8753_ALC2, 0, 15, 1),
+SOC_SINGLE("ALC Decay Time", WM8753_ALC3, 4, 15, 1),
+SOC_SINGLE("ALC Attack Time", WM8753_ALC3, 0, 15, 0),
+SOC_SINGLE("ALC NG Threshold", WM8753_NGATE, 3, 31, 0),
+SOC_ENUM("ALC NG Type", wm8753_enum[4]),
+SOC_SINGLE("ALC 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("ADC 6dB Attenuate", WM8753_ADCTL1, 2, 1, 0),
+SOC_SINGLE("DAC 6dB Attenuate", WM8753_ADCTL1, 1, 1, 0),
+
+SOC_ENUM("De-emphasis", wm8753_enum[8]),
+SOC_SINGLE("DAC Switch", WM8753_DAC, 3, 1, 1),
+
+SOC_ENUM("DAC Mono Mix", wm8753_enum[9]),
+SOC_ENUM("DAC Phase", wm8753_enum[10]),
+
+SOC_SINGLE("Mic 2 Volume", WM8753_INCTL1, 7, 3, 0),
+SOC_SINGLE("Mic 1 Volume", WM8753_INCTL1, 5, 3, 0),
+};
+
+/* add non dpm controls */
+static int wm8753_add_controls(snd_soc_codec_t *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;
+}
+
+/*
+ * DPM Controls
+ */
+
+/* Left Mixer */
+static const snd_kcontrol_new_t wm8753_left_mixer_controls[] = {
+SOC_DPM_SINGLE("Voice Switch", WM8753_LOUTM2, 8, 1, 0),
+SOC_DPM_SINGLE("Sidetone Switch", WM8753_LOUTM2, 7, 1, 0),
+SOC_DPM_SINGLE("DAC Switch", WM8753_LOUTM1, 8, 1, 0),
+SOC_DPM_SINGLE("Capture Mux Switch", WM8753_LOUTM1, 7, 1, 0),
+};
+
+/* Right mixer */
+static const snd_kcontrol_new_t wm8753_right_mixer_controls[] = {
+SOC_DPM_SINGLE("Voice Switch", WM8753_ROUTM2, 8, 1, 0),
+SOC_DPM_SINGLE("Sidetone Switch", WM8753_ROUTM2, 7, 1, 0),
+SOC_DPM_SINGLE("DAC Switch", WM8753_ROUTM1, 8, 1, 0),
+SOC_DPM_SINGLE("Capture Mux Switch", WM8753_ROUTM1, 7, 1, 0),
+};
+
+/* Mono mixer */
+static const snd_kcontrol_new_t wm8753_mono_mixer_controls[] = {
+SOC_DPM_SINGLE("Left Switch", WM8753_MOUTM1, 8, 1, 0),
+SOC_DPM_SINGLE("Right Switch", WM8753_MOUTM2, 8, 1, 0),
+SOC_DPM_SINGLE("DAC Switch", WM8753_MOUTM2, 4, 1, 0),
+SOC_DPM_SINGLE("Sidetone Switch", WM8753_MOUTM2, 7, 1, 0),
+SOC_DPM_SINGLE("Capture Mux Switch", WM8753_ROUTM1, 7, 1, 0),
+};
+
+/* Mono 2 Mux */
+static const snd_kcontrol_new_t wm8753_mono2_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[17]),
+};
+
+/* Out 3 Mux */
+static const snd_kcontrol_new_t wm8753_out3_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[18]),
+};
+
+/* Out 4 Mux */
+static const snd_kcontrol_new_t wm8753_out4_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[19]),
+};
+
+/* ADC Mono Mix */
+static const snd_kcontrol_new_t wm8753_adc_mono_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[9]),
+};
+
+/* ST Record mixer */
+static const snd_kcontrol_new_t wm8753_record_mixer_controls[] = {
+SOC_DPM_SINGLE("Voice Switch", WM8753_RECMIX2, 3, 1, 0),
+SOC_DPM_SINGLE("Left Switch", WM8753_RECMIX1, 3, 1, 0),
+SOC_DPM_SINGLE("Right Switch", WM8753_RECMIX1, 7, 1, 0),
+};
+
+/* Left ADC mux */
+static const snd_kcontrol_new_t wm8753_adc_left_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[20]),
+};
+
+/* Right ADC mux */
+static const snd_kcontrol_new_t wm8753_adc_right_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[21]),
+};
+
+/* MIC mux */
+static const snd_kcontrol_new_t wm8753_mic_mux_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[16]),
+};
+
+/* ALC mixer */
+static const snd_kcontrol_new_t wm8753_alc_mixer_controls[] = {
+SOC_DPM_SINGLE("Line Switch", WM8753_INCTL2, 3, 1, 0),
+SOC_DPM_SINGLE("Mic 2 Switch", WM8753_INCTL2, 2, 1, 0),
+SOC_DPM_SINGLE("Mic 1 Switch", WM8753_INCTL2, 1, 1, 0),
+SOC_DPM_SINGLE("Rx Switch", WM8753_INCTL2, 0, 1, 0),
+};
+
+/* Left Line mux */
+static const snd_kcontrol_new_t wm8753_line_left_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[14]),
+};
+
+/* Right Line mux */
+static const snd_kcontrol_new_t wm8753_line_right_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[13]),
+};
+
+/* Mono Line mux */
+static const snd_kcontrol_new_t wm8753_line_mono_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[12]),
+};
+
+/* Line mux and mixer */
+static const snd_kcontrol_new_t wm8753_line_mux_mix_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[11]),
+};
+
+/* Rx mux and mixer */
+static const snd_kcontrol_new_t wm8753_rx_mux_mix_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[15]),
+};
+
+/* Mic Selector Mux */
+static const snd_kcontrol_new_t wm8753_mic_sel_mux_controls[] = {
+SOC_DPM_ENUM("Source", wm8753_enum[25]),
+};
+
+static const snd_soc_dpm_widget_t wm8753_dpm_widgets[] = {
+SND_SOC_DPM_MIXER("Left Mixer", WM8753_PWR4, 0, 0, &wm8753_left_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_left_mixer_controls)),
+SND_SOC_DPM_VOLUME("Left Out 1", WM8753_PWR3, 8, 0, NULL, 0),
+SND_SOC_DPM_VOLUME("Left Out 2", WM8753_PWR3, 6, 0, NULL, 0),
+SND_SOC_DPM_DAC("Left DAC", "Left HiFi Playback", WM8753_PWR1, 3, 0, NULL, 0),
+SND_SOC_DPM_OUTPUT("LOUT1"),
+SND_SOC_DPM_OUTPUT("LOUT2"),
+SND_SOC_DPM_MIXER("Right Mixer", WM8753_PWR4, 1, 0, &wm8753_right_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_right_mixer_controls)),
+SND_SOC_DPM_VOLUME("Right Out 1", WM8753_PWR3, 7, 0, NULL, 0),
+SND_SOC_DPM_VOLUME("Right Out 2", WM8753_PWR3, 5, 0, NULL, 0),
+SND_SOC_DPM_DAC("Right DAC", "Right HiFi Playback", WM8753_PWR1, 2, 0, NULL, 0),
+SND_SOC_DPM_OUTPUT("ROUT1"),
+SND_SOC_DPM_OUTPUT("ROUT2"),
+SND_SOC_DPM_MIXER("Mono Mixer", WM8753_PWR4, 2, 0, &wm8753_mono_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_mono_mixer_controls)),
+SND_SOC_DPM_VOLUME("Mono Out 1", WM8753_PWR3, 2, 0, NULL, 0),
+SND_SOC_DPM_VOLUME("Mono Out 2", WM8753_PWR3, 1, 0, NULL, 0),
+SND_SOC_DPM_DAC("Voice DAC", "Voice Playback", WM8753_PWR1, 4, 0, NULL, 0),
+SND_SOC_DPM_OUTPUT("MONO1"),
+SND_SOC_DPM_MUX("Mono 2 Mux", -1, 0, 0, &wm8753_mono2_controls[0], 
+	ARRAY_SIZE(wm8753_mono2_controls)),
+SND_SOC_DPM_OUTPUT("MONO2"),
+SND_SOC_DPM_MIXER("Out3 Left + Right", -1, 0, 0, NULL, 0),
+SND_SOC_DPM_MUX("Out3 Mux", -1, 0, 0, &wm8753_out3_controls[0], 
+	ARRAY_SIZE(wm8753_out3_controls)),
+SND_SOC_DPM_VOLUME("Out 3", WM8753_PWR3, 4, 0, NULL, 0),
+SND_SOC_DPM_OUTPUT("OUT3"),
+SND_SOC_DPM_MUX("Out4 Mux", -1, 0, 0, &wm8753_out4_controls[0], 
+	ARRAY_SIZE(wm8753_out4_controls)),
+SND_SOC_DPM_VOLUME("Out 4", WM8753_PWR3, 3, 0, NULL, 0),
+SND_SOC_DPM_OUTPUT("OUT4"),
+SND_SOC_DPM_MIXER("Capture ST Mixer", WM8753_PWR4, 3, 0, &wm8753_record_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_record_mixer_controls)),
+SND_SOC_DPM_ADC("Left ADC", "Left Voice Capture", WM8753_PWR2, 3, 0, NULL, 0),
+SND_SOC_DPM_ADC("Right ADC", "Right Voice Capture", WM8753_PWR2, 2, 0, NULL, 0),
+SND_SOC_DPM_MUX("Capture Left Mixer", -1, 0, 0, &wm8753_adc_mono_controls[0], 
+	ARRAY_SIZE(wm8753_adc_mono_controls)),
+SND_SOC_DPM_MUX("Capture Right Mixer", -1, 0, 0, &wm8753_adc_mono_controls[0], 
+	ARRAY_SIZE(wm8753_adc_mono_controls)),
+SND_SOC_DPM_MUX("Capture Left Mux", -1, 0, 0, &wm8753_adc_left_controls[0], 
+	ARRAY_SIZE(wm8753_adc_left_controls)),
+SND_SOC_DPM_MUX("Capture Right Mux", -1, 0, 0, &wm8753_adc_right_controls[0], 
+	ARRAY_SIZE(wm8753_adc_right_controls)),
+SND_SOC_DPM_MUX("MIC ST Mux", -1, 0, 0, &wm8753_mic_mux_controls[0], 
+	ARRAY_SIZE(wm8753_mic_mux_controls)),
+SND_SOC_DPM_VOLUME("Left Capture Volume", WM8753_PWR2, 5, 0, NULL, 0),
+SND_SOC_DPM_VOLUME("Right Capture Volume", WM8753_PWR2, 4, 0, NULL, 0),
+SND_SOC_DPM_MIXER("ALC Mixer", WM8753_PWR2, 6, 0, &wm8753_alc_mixer_controls[0], 
+	ARRAY_SIZE(wm8753_alc_mixer_controls)),
+SND_SOC_DPM_MUX("Line Left Mux", -1, 0, 0, &wm8753_line_left_controls[0], 
+	ARRAY_SIZE(wm8753_line_left_controls)),
+SND_SOC_DPM_MUX("Line Right Mux", -1, 0, 0, &wm8753_line_right_controls[0], 
+	ARRAY_SIZE(wm8753_line_right_controls)),
+SND_SOC_DPM_MUX("Line Mono Mux", -1, 0, 0, &wm8753_line_mono_controls[0], 
+	ARRAY_SIZE(wm8753_line_mono_controls)),
+SND_SOC_DPM_MUX("Line Mixer", -1, 0, 0, &wm8753_line_mux_mix_controls[0], 
+	ARRAY_SIZE(wm8753_line_mux_mix_controls)),
+SND_SOC_DPM_MUX("Rx Mixer", -1, 0, 0, &wm8753_rx_mux_mix_controls[0], 
+	ARRAY_SIZE(wm8753_rx_mux_mix_controls)),
+SND_SOC_DPM_VOLUME("Mic 1 Volume", WM8753_PWR2, 8, 0, NULL, 0),
+SND_SOC_DPM_VOLUME("Mic 2 Volume", WM8753_PWR2, 7, 0, NULL, 0),
+SND_SOC_DPM_MUX("Mic Selection Mux", -1, 0, 0, &wm8753_mic_sel_mux_controls[0], 
+	ARRAY_SIZE(wm8753_mic_sel_mux_controls)),
+SND_SOC_DPM_INPUT("LINE1"),
+SND_SOC_DPM_INPUT("LINE2"),
+SND_SOC_DPM_INPUT("RXP"),
+SND_SOC_DPM_INPUT("RXN"),
+SND_SOC_DPM_INPUT("ACIN"),
+SND_SOC_DPM_INPUT("ACOP"),
+SND_SOC_DPM_INPUT("MIC1N"),
+SND_SOC_DPM_INPUT("MIC1"),
+SND_SOC_DPM_INPUT("MIC2N"),
+SND_SOC_DPM_INPUT("MIC2"),
+};
+
+/*
+ * VERY EXPERIMENTAL - 
+ */
+static int wm8753_add_widgets(snd_soc_codec_t *codec)
+{
+	int i;
+	
+	for(i = 0; i < ARRAY_SIZE(wm8753_dpm_widgets); i++) {
+		snd_soc_dpm_new_control(codec, &wm8753_dpm_widgets[i]);
+	}
+	
+	/* set up audio path interconnects */
+	
+	/* left mixer */
+	snd_soc_dpm_connect_input(codec, "Left Mixer", "DAC Switch", "Left DAC");
+	snd_soc_dpm_connect_input(codec, "Left Mixer", "Voice Switch", "Voice DAC");
+	snd_soc_dpm_connect_input(codec, "Left Mixer", "Sidetone Switch", "MIC ST Mux");
+	snd_soc_dpm_connect_input(codec, "Left Mixer", "Capture Mux Switch", "Line Left Mux");
+	
+	/* right mixer */
+	snd_soc_dpm_connect_input(codec, "Right Mixer", "DAC Switch", "Right DAC");
+	snd_soc_dpm_connect_input(codec, "Right Mixer", "Voice Switch", "Voice DAC");
+	snd_soc_dpm_connect_input(codec, "Right Mixer", "Sidetone Switch", "MIC ST Mux");
+	snd_soc_dpm_connect_input(codec, "Right Mixer", "Capture Mux Switch", "Line Right Mux");
+	
+	/* mono mixer */
+	snd_soc_dpm_connect_input(codec, "Mono Mixer", "DAC Switch", "Voice DAC");
+	snd_soc_dpm_connect_input(codec, "Mono Mixer", "Left Switch", "Left DAC");
+	snd_soc_dpm_connect_input(codec, "Mono Mixer", "Right Switch", "Right DAC");
+	snd_soc_dpm_connect_input(codec, "Mono Mixer", "Sidetone Switch", "MIC ST Mux");
+	snd_soc_dpm_connect_input(codec, "Mono Mixer", "Capture Mux Switch", "Line Mono Mux");
+	
+	/* left out */
+	snd_soc_dpm_connect_input(codec, "Left Out 1", NULL, "Left Mixer");
+	snd_soc_dpm_connect_input(codec, "Left Out 2", NULL, "Left Mixer");
+	snd_soc_dpm_connect_input(codec, "LOUT1", NULL, "Left Out 1");
+	snd_soc_dpm_connect_input(codec, "LOUT2", NULL, "Left Out 2");
+
+	
+	/* right out */
+	snd_soc_dpm_connect_input(codec, "Right Out 1", NULL, "Right Mixer");
+	snd_soc_dpm_connect_input(codec, "Right Out 2", NULL, "Right Mixer");
+	snd_soc_dpm_connect_input(codec, "ROUT1", NULL, "Right Out 1");
+	snd_soc_dpm_connect_input(codec, "ROUT2", NULL, "Right Out 2");
+	
+	/* mono 1 out */
+	snd_soc_dpm_connect_input(codec, "Mono Out 1", NULL, "Mono Mixer");
+	snd_soc_dpm_connect_input(codec, "MONO1", NULL, "Mono Out 1");
+	
+	/* mono 2 out */
+	snd_soc_dpm_connect_input(codec, "Mono 2 Mux", "Left + Right", "Out3 Left + Right");
+	snd_soc_dpm_connect_input(codec, "Mono 2 Mux", "Inverted Mono 1", "MONO1");
+	snd_soc_dpm_connect_input(codec, "Mono 2 Mux", "Left", "Left Mixer");
+	snd_soc_dpm_connect_input(codec, "Mono 2 Mux", "Right", "Right Mixer");
+	snd_soc_dpm_connect_input(codec, "Mono Out 2", NULL, "Mono 2 Mux");
+	snd_soc_dpm_connect_input(codec, "MONO2", NULL, "Mono Out 2");
+	
+	/* out 3 */
+	snd_soc_dpm_connect_input(codec, "Out3 Left + Right", NULL, "Left Mixer");
+	snd_soc_dpm_connect_input(codec, "Out3 Left + Right", NULL, "Right Mixer");
+	snd_soc_dpm_connect_input(codec, "Out3 Mux", "VREF", "VREF");
+	snd_soc_dpm_connect_input(codec, "Out3 Mux", "Left + Right", "Out3 Left + Right");
+	snd_soc_dpm_connect_input(codec, "Out3 Mux", "ROUT2", "ROUT2");
+	snd_soc_dpm_connect_input(codec, "Out 3", NULL, "Out3 Mux");
+	snd_soc_dpm_connect_input(codec, "OUT3", NULL, "Out 3");
+	
+	/* out 4 */
+	snd_soc_dpm_connect_input(codec, "Out4 Mux", "VREF", "VREF");
+	snd_soc_dpm_connect_input(codec, "Out4 Mux", "Capture ST", "Capture ST Mixer");
+	snd_soc_dpm_connect_input(codec, "Out4 Mux", "LOUT2", "LOUT2");
+	snd_soc_dpm_connect_input(codec, "Out 4", NULL, "Out4 Mux");
+	snd_soc_dpm_connect_input(codec, "OUT4", NULL, "Out 4");
+	
+	/* record mixer - Capture ST */
+	snd_soc_dpm_connect_input(codec, "Capture ST Mixer", "Left Switch", "Left Mixer");
+	snd_soc_dpm_connect_input(codec, "Capture ST Mixer", "Voice Switch", "Mono Mixer");
+	snd_soc_dpm_connect_input(codec, "Capture ST Mixer", "Right Switch", "Right Mixer");
+	
+	/* Mic/SideTone Mux */
+	snd_soc_dpm_connect_input(codec, "Mic Mux", "Left PGA", "Left Capture Volume");
+	snd_soc_dpm_connect_input(codec, "Mic Mux", "Right PGA", "Right Capture Volume");
+	snd_soc_dpm_connect_input(codec, "Mic Mux", "Mic 1", "Mic 1 Volume");
+	snd_soc_dpm_connect_input(codec, "Mic Mux", "Mic 2", "Mic 2 Volume");
+	
+	/* Capture Left Mux */
+	snd_soc_dpm_connect_input(codec, "Capture Left Mux", "PGA", "Left Capture Volume");
+	snd_soc_dpm_connect_input(codec, "Capture Left Mux", "Line or RXP-RXN", "Line Left Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Left Mux", "Line", "LINE1");
+	
+	/* Capture Right Mux */
+	snd_soc_dpm_connect_input(codec, "Capture Right Mux", "PGA", "Right Capture Volume");
+	snd_soc_dpm_connect_input(codec, "Capture Right Mux", "Line or RXP-RXN", "Line Right Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Right Mux", "Sidetone", "Capture ST Mixer");
+	
+	/* Mono Capture mixer-mux */
+	snd_soc_dpm_connect_input(codec, "Capture Right Mixer", "Stereo", "Capture Right Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Left Mixer", "Analogue Mix Left", "Capture Left Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Left Mixer", "Analogue Mix Left", "Capture Right Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Right Mixer", "Analogue Mix Right", "Capture Left Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Right Mixer", "Analogue Mix Right", "Capture Right Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Left Mixer", "Digital Mono Mix", "Capture Left Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Left Mixer", "Digital Mono Mix", "Capture Right Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Right Mixer", "Digital Mono Mix", "Capture Left Mux");
+	snd_soc_dpm_connect_input(codec, "Capture Right Mixer", "Digital Mono Mix", "Capture Right Mux");
+	
+	/* ADC */
+	snd_soc_dpm_connect_input(codec, "Left ADC", NULL, "Capture Left Mixer");
+	snd_soc_dpm_connect_input(codec, "Right ADC", NULL, "Capture Right Mixer");
+
+	/* Left Capture Volume */
+	snd_soc_dpm_connect_input(codec, "Left Capture Volume", NULL, "ACIN");
+	
+	/* Right Capture Volume */
+	snd_soc_dpm_connect_input(codec, "Right Capture Volume", NULL, "Mic 2 Volume");
+
+	/* ALC Mixer */
+	snd_soc_dpm_connect_input(codec, "ALC Mixer", "Line Switch", "Line Mixer");
+	snd_soc_dpm_connect_input(codec, "ALC Mixer", "Mic 2 Switch", "Mic 2 Volume");
+	snd_soc_dpm_connect_input(codec, "ALC Mixer", "Mic 1 Switch", "Mic 1 Volume");
+	snd_soc_dpm_connect_input(codec, "ALC Mixer", "Rx Switch", "Rx Mixer");
+	
+	/* Line Left Mux */
+	snd_soc_dpm_connect_input(codec, "Line Left Mux", "Line 1", "LINE1");
+	snd_soc_dpm_connect_input(codec, "Line Left Mux", "Rx Mix", "Rx Mixer");
+	
+	/* Line Right Mux */
+	snd_soc_dpm_connect_input(codec, "Line Right Mux", "Line 2", "LINE2");
+	snd_soc_dpm_connect_input(codec, "Line Right Mux", "Rx Mix", "Rx Mixer");
+	
+	/* Line Mono Mux */
+	snd_soc_dpm_connect_input(codec, "Line Mono Mux", "Line Mix", "Line Mixer");
+	snd_soc_dpm_connect_input(codec, "Line Mono Mux", "Rx Mix", "Rx Mixer");
+	
+	/* Line Mixer/Mux */
+	snd_soc_dpm_connect_input(codec, "Line Mixer", "Line 1 + 2", "LINE1");
+	snd_soc_dpm_connect_input(codec, "Line Mixer", "Line 1 - 2", "LINE1");
+	snd_soc_dpm_connect_input(codec, "Line Mixer", "Line 1 + 2", "LINE2");
+	snd_soc_dpm_connect_input(codec, "Line Mixer", "Line 1 - 2", "LINE2");
+	snd_soc_dpm_connect_input(codec, "Line Mixer", "Line 1", "LINE1");
+	snd_soc_dpm_connect_input(codec, "Line Mixer", "Line 2", "LINE2");
+	
+	/* Rx Mixer/Mux */
+	snd_soc_dpm_connect_input(codec, "Rx Mixer", "RXP - RXN", "RXP");
+	snd_soc_dpm_connect_input(codec, "Rx Mixer", "RXP + RXN", "RXP");
+	snd_soc_dpm_connect_input(codec, "Rx Mixer", "RXP - RXN", "RXN");
+	snd_soc_dpm_connect_input(codec, "Rx Mixer", "RXP + RXN", "RXN");
+	snd_soc_dpm_connect_input(codec, "Rx Mixer", "RXP", "RXP");
+	snd_soc_dpm_connect_input(codec, "Rx Mixer", "RXN", "RXN");
+	
+	/* Mic 1 Volume */
+	snd_soc_dpm_connect_input(codec, "Mic 1 Volume", NULL, "MIC1N");
+	snd_soc_dpm_connect_input(codec, "Mic 1 Volume", NULL, "Mic Selection Mux");
+	
+	/* Mic 2 Volume */
+	snd_soc_dpm_connect_input(codec, "Mic 2 Volume", NULL, "MIC2N");
+	snd_soc_dpm_connect_input(codec, "Mic 2 Volume", NULL, "MIC2");
+	
+	/* Mic Selector Mux */
+	snd_soc_dpm_connect_input(codec, "Mic Selection Mux", "Mic 1", "MIC1");
+	snd_soc_dpm_connect_input(codec, "Mic Selection Mux", "Mic 2", "MIC2N");
+	snd_soc_dpm_connect_input(codec, "Mic Selection Mux", "Mic 3", "MIC2");
+	
+	/* ACOP */
+	snd_soc_dpm_connect_input(codec, "ACOP", NULL, "ALC Mixer");
+	
+	/* ACIN --> ACOP */
+	// liam - make this a mod param
+	snd_soc_dpm_connect_input(codec, "ACIN", NULL, "ACOP");
+	
+	snd_soc_dpm_sync(codec);
+	return 0;
+}
+
+/*
+ * set the PLL2 to generate 12.288MHz and then div by 6 to generate
+ * DAC/ADC clocks from 12MHz MCLK 
+ */
+static u32 wm8753_config_pll(int pll, u32 speed)
+{
+	u16 clk;
+	printk("config pll %d %d\n", pll, speed);
+
+    if (pll == 1) {
+		clk = wm8753_read_reg_cache(WM8753_CLOCK) & 0x0010;
+        if (!speed) {
+            /* disable PLL1  */
+            wm8753_2w_write(wm8753.i2c, WM8753_PLL1CTL1, 0x0026);
+			wm8753_2w_write(wm8753.i2c, WM8753_CLOCK, clk);
+        } 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].hz == speed)
+                    break;
+            }
+			
+			/* do we need to enable the PLL ? */
+			if (!pll_div[i].n) {
+				wm8753_2w_write(wm8753.i2c, WM8753_CLOCK, 0x0);
+				return 0;
+			}
+    
+            /* 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_2w_write(wm8753.i2c, WM8753_PLL1CTL2, value);
+     
+            /* bits 8:0 = PLL_K[17:9] */
+            value = (pll_div[i].k & 0x03fe00) >> 9;
+            wm8753_2w_write(wm8753.i2c, WM8753_PLL1CTL3, value);
+    
+            /* bits 8:0 = PLL_K[8:0] */
+            value = pll_div[i].k & 0x0001ff;
+            wm8753_2w_write(wm8753.i2c, WM8753_PLL1CTL4, value);
+     
+            /* set PLL1 as input and enable */
+            wm8753_2w_write(wm8753.i2c, WM8753_PLL1CTL1, 0x0027);
+			wm8753_2w_write(wm8753.i2c, WM8753_CLOCK, clk | 0x0010);
+        }
+    } else {
+		clk = wm8753_read_reg_cache(WM8753_CLOCK) & 0x0008;
+        if (!speed) {
+            /* disable PLL2  */
+            wm8753_2w_write(wm8753.i2c, WM8753_PLL2CTL1, 0x0026);
+			wm8753_2w_write(wm8753.i2c, WM8753_CLOCK, clk);
+        } 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].hz == speed)
+                    break;
+            }
+			
+    		/* do we need to enable the PLL ? */
+			if (!pll_div[i].n) {
+				wm8753_2w_write(wm8753.i2c, WM8753_CLOCK, 0x0);
+				return 0;
+			}
+			
+            /* 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_2w_write(wm8753.i2c, WM8753_PLL2CTL2, value);
+     
+            /* bits 8:0 = PLL_K[17:9] */
+            value = (pll_div[i].k & 0x03fe00) >> 9;
+            wm8753_2w_write(wm8753.i2c, WM8753_PLL2CTL3, value);
+    
+            /* bits 8:0 = PLL_K[8:0] */
+            value = pll_div[i].k & 0x0001ff;
+            wm8753_2w_write(wm8753.i2c, WM8753_PLL2CTL4, value);
+     
+            /* set PLL1 as input and enable */
+            wm8753_2w_write(wm8753.i2c, WM8753_PLL2CTL1, 0x0027);
+			wm8753_2w_write(wm8753.i2c, WM8753_CLOCK, clk | 0x0008);
+        }
+    }
+	return speed;
+}
+
+
+/*
+ * Power up the codec -- WE ARE NOW ALMOST DOING THIS IN DPM
+ */
+static int wm8753_power_up(snd_pcm_substream_t *substream)
+{	
+	u16 pwr = 0xfc;
+	
+	/* set Vmid to 5kOhm, enable VREF and VDAC */
+	if (wm8753_2w_write(wm8753.i2c, WM8753_PWR1, 0x0100 | pwr) != 0)
+		return -EIO;
+
+	/* enable MIC1 preamp, ALC mix and left ADC */
+	//if (wm8753_2w_write(wm8753.i2c, WM8753_PWR2, 0x01ff) != 0)	
+	//	return -EIO;
+	
+	/* enable LOUT 1, ROUT1, MONO1 */
+	//if (wm8753_2w_write(wm8753.i2c, WM8753_PWR3, 0x01ff) != 0)
+	//	return -EIO;
+	
+	/* enable left, mono mixer */
+	//if (wm8753_2w_write(wm8753.i2c, WM8753_PWR4, 0x0000) != 0)
+	//	return -EIO;
+	
+	/* let WM8753 powerup and then set Vmid to 50kOhm */
+	mdelay(1);
+	if (wm8753_2w_write(wm8753.i2c, WM8753_PWR1, pwr) != 0)
+		return -EIO;
+	
+	return 0;
+}
+
+/* WE CAN USE DPM IN NEAR FUTURE */
+static int wm8753_power_down(snd_pcm_substream_t *substream)
+{
+	if ((wm8753_2w_write(wm8753.i2c, WM8753_PWR1, 0x0100) != 0) &&
+		(wm8753_2w_write(wm8753.i2c, WM8753_PWR2, 0x0000) != 0) &&
+		(wm8753_2w_write(wm8753.i2c, WM8753_PWR3, 0x0000) != 0) &&
+		(wm8753_2w_write(wm8753.i2c, WM8753_PWR4, 0x0000) != 0)) {
+			err("could not powerdown WM8753");
+			return -EIO;
+		}
+	return 0;
+}
+
+static int wm8753_pcm_voice_startup(snd_pcm_substream_t *substream)
+{
+	//snd_pcm_runtime_t *runtime = substream->runtime;
+
+	return 0;
+}
+
+static void wm8753_pcm_voice_shutdown(snd_pcm_substream_t *substream)
+{
+	wm8753_power_down(substream);
+}
+
+static int wm8753_pcm_voice_prepare(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	u16 voice = 0, ioctl, clock, srate;
+	
+	/* enable PLL */
+	wm8753_config_pll(2, pcm_c->hw_runtime.priv1);
+	
+	/* set master/slave audio interface */
+	ioctl = wm8753_read_reg_cache(WM8753_IOCTL) & 0x01f1;
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_CLOCK_MASK) {
+		case SND_SOC_HWFMT_CBM_CFM:
+			voice |= 0x0040;
+			ioctl |= 0x0002;
+			break;
+		case SND_SOC_HWFMT_CBM_CFS:
+			voice |= 0x0040;
+			break;
+	}
+	
+	/* interface format */
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_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(pcm_c->hw_runtime.hbits) {
+		case SND_SOC_HWBITS(16):
+			break;
+		case SND_SOC_HWBITS(20):
+			voice |= 0x0004;
+			break;
+		case SND_SOC_HWBITS(24):
+			voice |= 0x0008;
+			break;
+		case SND_SOC_HWBITS(32):
+			voice |= 0x000c;
+			break;
+	}
+	
+	/* set rate */
+	clock = wm8753_read_reg_cache(WM8753_CLOCK) & 0x003f;
+	clock |= (pcm_c->hw_runtime.priv2 & 0xff00) >> 2;
+	wm8753_2w_write(wm8753.i2c, WM8753_CLOCK, clock);
+
+	srate = wm8753_read_reg_cache(WM8753_SRATE1) & 0x017f;
+	srate |= (pcm_c->hw_runtime. priv2 & 0xff) << 7;
+	wm8753_2w_write(wm8753.i2c, WM8753_SRATE1, srate);
+	
+	/* clock inversion */
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_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;
+	}
+	wm8753_2w_write(wm8753.i2c, WM8753_IOCTL, ioctl);
+	wm8753_2w_write(wm8753.i2c, WM8753_PCM, voice);
+	return 0;
+}
+
+static int wm8753_pcm_hifi_startup(snd_pcm_substream_t *substream)
+{
+	wm8753_power_up(substream);
+	return 0;
+}
+
+static void wm8753_pcm_hifi_shutdown(snd_pcm_substream_t *substream)
+{	
+	wm8753_power_down(substream);
+}
+
+static int wm8753_pcm_hifi_prepare(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	u16 hifi = 0, ioctl, srate;
+	
+	/* enable PLL */
+	wm8753_config_pll(1, pcm_c->hw_runtime.priv1);
+	
+	/* set master/slave audio interface */
+	ioctl = wm8753_read_reg_cache(WM8753_IOCTL) & 0x00f2;
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_CLOCK_MASK) {
+		case SND_SOC_HWFMT_CBM_CFM:
+			hifi |= 0x0040;
+			ioctl |= 0x0001;
+			break;
+		case SND_SOC_HWFMT_CBM_CFS:
+			hifi |= 0x0040;
+			break;
+	}
+	
+	/* interface format */
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_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(pcm_c->hw_runtime.hbits) {
+		case SND_SOC_HWBITS(16):
+			break;
+		case SND_SOC_HWBITS(20):
+			hifi |= 0x0004;
+			break;
+		case SND_SOC_HWBITS(24):
+			hifi |= 0x0008;
+			break;
+		case SND_SOC_HWBITS(32):
+			hifi |= 0x000c;
+			break;
+	}
+	
+	/* set rate */
+	srate = wm8753_read_reg_cache(WM8753_SRATE2) & 0x01c7;
+	switch ((pcm_c->hw_runtime.priv2 & 0xff00) >> 8){
+		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_2w_write(wm8753.i2c, WM8753_SRATE2, srate);
+	srate = (pcm_c->hw_runtime. priv2 & 0xff) << 1;
+	wm8753_2w_write(wm8753.i2c, WM8753_SRATE1, srate);
+	
+	/* clock inversion */
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_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_2w_write(wm8753.i2c, WM8753_IOCTL, ioctl | 0x0008);
+	wm8753_2w_write(wm8753.i2c, WM8753_HIFI, hifi);
+	return 0;
+}
+
+static void wm8753_device_release(struct device * dev)
+{
+}
+
+static snd_soc_pcm_codec_t wm8753_pcm_voice_client = {
+	.name = "WM8753 Voice",
+	.playback = {
+		.sname = "Voice Playback",
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 1,},
+	.capture = {
+		.sname = "Voice Capture",
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | 
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 |
+		SNDRV_PCM_RATE_96000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 2,},
+	.ops = {
+		.startup = wm8753_pcm_voice_startup,
+		.shutdown = wm8753_pcm_voice_shutdown,
+		.prepare = wm8753_pcm_voice_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8753_voice),
+		.hmodes = &wm8753_voice[0],
+		},
+};
+
+static snd_soc_pcm_codec_t wm8753_pcm_hifi_client = {
+	.name = "WM8753 Hifi",
+	.playback = {
+		.sname = "HiFi Playback",
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 |
+		SNDRV_PCM_RATE_96000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 2,},
+	.ops = {
+		.startup = wm8753_pcm_hifi_startup,
+		.shutdown = wm8753_pcm_hifi_shutdown,
+		.prepare = wm8753_pcm_hifi_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm8753_hifi),
+		.hmodes = &wm8753_hifi[0],},
+};
+
+static snd_soc_codec_t wm8753_soc_codec;
+
+/*
+ * initialise the WM8753 driver
+ * register the mixer and dsp interfaces with the kernel 
+ */
+static int wm8753_probe(snd_soc_codec_t *codec)
+{
+	int ret;
+	int dev_no = 0;
+	int reg;
+	
+	info("WM8753 Audio Codec %s", WM8753_VERSION);
+	if(!hifi && !voice) {
+		err("no interfaces selected");
+		return -ENODEV;
+	}
+	
+	/* check platform for interfaces */
+	if(voice && snd_soc_iface_query(SND_SOC_SSP, 1)) {
+		err("voice interface not available");
+		voice = 0;
+	}
+	if(hifi && snd_soc_iface_query(SND_SOC_I2S, 0)) {
+		err("HiFi interface not available");
+		hifi = 0;
+	}
+	if(!hifi && !voice) {
+		err("no interfaces available");
+		return -ENODEV;
+	}
+
+	if (voice) {
+		if((ret = snd_soc_pcm_new(codec, dev_no++, &wm8753_pcm_voice_client, 
+				&wm8753.pcm_voice, 1, 1, SND_SOC_SSP, 1)) < 0)
+			return ret;
+	}
+		
+	if (hifi) {
+		if((ret = snd_soc_pcm_new(codec, dev_no++, &wm8753_pcm_hifi_client, 
+				&wm8753.pcm_hifi, 1, 0, SND_SOC_I2S, 0)) < 0)
+			return ret;
+	}
+
+	if ((ret = i2c_add_driver(&wm8753_i2c_driver)) != 0) {
+		err("can't add i2c driver");
+		return ret;
+	}
+	
+	/* set the update bits */
+	reg = wm8753_read_reg_cache(WM8753_LDAC);
+	wm8753_2w_write(wm8753.i2c, WM8753_LDAC, reg | 0x0100);
+	reg = wm8753_read_reg_cache(WM8753_RDAC);
+	wm8753_2w_write(wm8753.i2c, WM8753_RDAC, reg | 0x0100);
+	reg = wm8753_read_reg_cache(WM8753_LOUT1V);
+	wm8753_2w_write(wm8753.i2c, WM8753_LOUT1V, reg | 0x0100);
+	reg = wm8753_read_reg_cache(WM8753_ROUT1V);
+	wm8753_2w_write(wm8753.i2c, WM8753_ROUT1V, reg | 0x0100);
+	reg = wm8753_read_reg_cache(WM8753_LOUT2V);
+	wm8753_2w_write(wm8753.i2c, WM8753_LOUT2V, reg | 0x0100);
+	reg = wm8753_read_reg_cache(WM8753_ROUT2V);
+	wm8753_2w_write(wm8753.i2c, WM8753_ROUT2V, reg | 0x0100);
+	reg = wm8753_read_reg_cache(WM8753_LINVOL);
+	wm8753_2w_write(wm8753.i2c, WM8753_LINVOL, reg | 0x0100);
+	reg = wm8753_read_reg_cache(WM8753_RINVOL);
+	wm8753_2w_write(wm8753.i2c, WM8753_RINVOL, reg | 0x0100);
+	
+	wm8753_add_controls(&wm8753_soc_codec);
+	wm8753_add_widgets(&wm8753_soc_codec);
+
+	return ret;
+}
+
+/* 
+ * unregister interfaces and clean up
+ */
+static void wm8753_remove(snd_soc_codec_t *codec)
+{
+	i2c_del_driver(&wm8753_i2c_driver);
+}
+
+static snd_soc_codec_t wm8753_soc_codec = {
+	.name = "WM8753",
+	.longname = "wm8753 long name",
+	.owner = THIS_MODULE,
+	.pdev = {
+		.name		= "wm8753 pdev",
+		.id		= -1,
+		.dev		= {.release = wm8753_device_release},
+	},
+	.probe = wm8753_probe,
+	.remove = wm8753_remove,
+	.read = wm8753_read_reg_cache,
+	.write = wm8753_write,
+};	
+
+static int __init wm8753_init(void)
+{	
+	return snd_soc_register_codec(&wm8753_soc_codec);
+}
+
+static void __exit wm8753_exit(void)
+{
+	printk("%s %s %d\n",  __FILE__, __FUNCTION__, __LINE__);
+	snd_soc_unregister_codec(&wm8753_soc_codec);
+}
+
+module_init(wm8753_init);
+module_exit(wm8753_exit);
+
+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..ec7451b
--- /dev/null
+++ b/sound/soc/codecs/wm8753.h
@@ -0,0 +1,104 @@
+/*
+ * 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
+
+/* Voice DAC sample rates */
+#define WM8753_VD8K		(0x6 << 6)
+#define WM8753_VD12K	(0x5 << 6)
+#define WM8753_VD16K	(0x2 << 6)
+#define WM8753_VD24K	(0x4 << 6)
+#define WM8753_VD48K	(0x0 << 6)
+
+
+/* Hifi ADC/DAC sample rates */
+#define WM8753_A8D8		0x0006
+#define WM8753_A8D48	0x0004
+#define WM8753_A12D12	0x0008
+#define WM8753_A16D16	0x000a
+#define WM8753_A24D24	0x001c
+#define WM8753_A32D32	0x000c
+#define WM8753_A48D8	0x0002
+#define WM8753_A48D48	0x0000
+#define WM8753_A96D96	0x000e
+
+struct wm8753_mixer_t {
+	int dev_mixer;
+};
+
+#endif
diff --git a/sound/soc/codecs/wm9713-voice.c b/sound/soc/codecs/wm9713-voice.c
new file mode 100644
index 0000000..1b1445f
--- /dev/null
+++ b/sound/soc/codecs/wm9713-voice.c
@@ -0,0 +1,277 @@
+/*
+ * wm9713-voice.c  --  PXA WM9713 PCM 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.
+ *
+ *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
+ *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
+ *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+ *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
+ *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
+ *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  You should have received a copy of the  GNU General Public License along
+ *  with this program; if not, write  to the Free Software Foundation, Inc.,
+ *  675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  Revision history
+ *    1st Aug 2005   Initial 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/wm97xx.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/initval.h>
+
+#define NAME		"wm9713-voice"
+#define VERSION		"0.1"
+
+/*
+ * Debug
+ */ 
+#if 0
+#define dbg(format, arg...) printk(KERN_DEBUG TS_NAME ": " format "\n" , ## arg)
+#else	/* 
+ */
+#define dbg(format, arg...)
+#endif	/* 
+ */
+#define err(format, arg...) printk(KERN_ERR TS_NAME ": " format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO TS_NAME ": " format "\n" , ## arg)
+#define warn(format, arg...) printk(KERN_WARNING TS_NAME ": " format "\n" , ## arg)
+
+#define WM9713_PCM_8K		(0xb << 8)
+#define WM9713_PCM_12K		(0x7 << 8)
+#define WM9713_PCM_16K		(0x5 << 8)
+#define WM9713_PCM_24K		(0x3 << 8)
+#define WM9713_PCM_32K		(0x2 << 8)
+#define WM9713_PCM_48K		(0x1 << 8)
+#define WM9713_PCM_96K		(0x0 << 8)
+
+#define WM9713_VOICE_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_RIGHT_J | SND_SOC_HWFMT_LEFT_J | \
+	SND_SOC_HWFMT_DSP_A | SND_SOC_HWFMT_DSP_B | SND_SOC_HWFMT_CBM_CFM | \
+	SND_SOC_HWFMT_CBM_CFS | SND_SOC_HWFMT_CBS_CFS | SND_SOC_HWFMT_NB_NF | \
+	SND_SOC_HWFMT_NB_IF | SND_SOC_HWFMT_IB_NF | SND_SOC_HWFMT_IB_IF)
+
+/*
+ * priv1 is pcm clock divider
+ */
+static snd_soc_hw_mode_t wm9713_voice[] = {
+	{WM9713_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		48000,	256,	WM9713_PCM_48K, },
+	{WM9713_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		32000,	384,	WM9713_PCM_32K,},
+	{WM9713_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		24000,	256,	WM9713_PCM_24K,},
+	{WM9713_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		16000,	256,	WM9713_PCM_16K,},
+	{WM9713_VOICE_HWFMT, 	SND_SOC_HWBITS(16),		8000,	256,	WM9713_PCM_8K,},
+};
+	
+struct wm9713_pcm {
+	int pcm_rate;
+	struct wm97xx *wm;
+	snd_pcm_t *pcm_voice;
+};
+
+static struct wm9713_pcm wm9713;
+
+static int wm9713_voice_startup(snd_pcm_substream_t *substream)
+{
+	int reg;
+
+	/* power up clock control and voice DAC */
+	reg = wm97xx_reg_read(wm9713.wm, AC97_POWERDOWN); 
+	wm97xx_reg_write(wm9713.wm, AC97_POWERDOWN, reg & ~0x2000);
+	reg = wm97xx_reg_read(wm9713.wm, AC97_EXTENDED_MID); 
+	wm97xx_reg_write(wm9713.wm, AC97_EXTENDED_MID, reg & ~0x1000);
+
+	return 0;
+}
+
+static void wm9713_voice_shutdown(snd_pcm_substream_t *substream)
+{
+}
+
+static int wm9713_voice_prepare(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	u16 reg = 0x8000;
+
+	switch(pcm_c->hw_runtime.hformat & SND_SOC_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(pcm_c->hw_runtime.hformat & SND_SOC_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(pcm_c->hw_runtime.hformat & SND_SOC_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(pcm_c->hw_runtime.hbits) {
+		case SND_SOC_HWBITS(16):
+			break;
+		case SND_SOC_HWBITS(20):
+			reg |= 0x0004;
+			break;
+		case SND_SOC_HWBITS(24):
+			reg |= 0x0008;
+			break;
+		case SND_SOC_HWBITS(32):
+			reg |= 0x000c;
+			break;
+	}
+	/* enable PCM interface in master mode */
+	wm97xx_reg_write(wm9713.wm, AC97_CENTER_LFE_MASTER, reg);
+	
+	/* sample rate */
+	reg = wm97xx_reg_read(wm9713.wm, AC97_HANDSET_RATE) &0xe0ff;
+	wm97xx_reg_write(wm9713.wm, AC97_HANDSET_RATE, reg | pcm_c->hw_runtime.priv1);
+	return 0;
+}
+
+static snd_soc_pcm_codec_t wm9713_voice_client = {
+	.name = "WM9713 Voice",
+	.playback = {
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 1,},
+	.capture = {
+		.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | 
+		SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 |
+		SNDRV_PCM_RATE_96000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+		.channels_min = 1,
+		.channels_max = 1,},
+	.ops = {
+		.startup = wm9713_voice_startup,
+		.shutdown = wm9713_voice_shutdown,
+		.prepare = wm9713_voice_prepare,},
+	.hw = {
+		.num_hmodes = ARRAY_SIZE(wm9713_voice),
+		.hmodes = &wm9713_voice[0],
+		},
+};
+
+static void wm9713_device_release(struct device * dev)
+{
+}
+
+static snd_soc_codec_t wm9713_soc_codec;
+
+static int wm9713_soc_probe(snd_soc_codec_t *codec)
+{
+	int ret;
+
+	ret = snd_soc_pcm_new(codec, 0, &wm9713_voice_client, 
+			&wm9713.pcm_voice, 1, 1, SND_SOC_SSP, 1);
+	return ret;
+}
+
+static void wm9713_soc_remove(snd_soc_codec_t *codec)
+{
+}
+
+static snd_soc_codec_t wm9713_soc_codec = {
+	.name = "WM9713 Voice",
+	.longname = "wm9713 voice long",
+	.owner = THIS_MODULE,
+	.pdev = {
+		.name		= "wm9713 pl",
+		.id		= -1,
+		.dev		= {.release = wm9713_device_release},
+	},
+	.probe = wm9713_soc_probe,
+	.remove = wm9713_soc_remove,
+};
+
+static int wm97xx_wm9713_probe(struct wm97xx* wm)
+{	
+	if (wm->ac97 == NULL)
+		return -ENODEV;
+	
+	wm9713.wm = wm;
+	return snd_soc_register_codec(&wm9713_soc_codec);
+}
+
+static void wm97xx_wm9713_remove(struct wm97xx* wm)
+{
+	snd_soc_unregister_codec(&wm9713_soc_codec);
+	wm9713.wm = NULL;
+}
+
+static struct wm97xx_platform_drv pxa_wm9713 = {
+	.id = 0x4c13,
+	.mask = 0xffff,
+	.probe = 	wm97xx_wm9713_probe,
+	.remove = 	wm97xx_wm9713_remove,
+};
+
+static int __init pxa_wm9713_init(void)
+{
+	wm97xx_register_platform_drv(&pxa_wm9713);
+	return 0;
+}
+
+static void __exit pxa_wm9713_exit(void)
+{
+	wm97xx_unregister_platform_drv(&pxa_wm9713);
+}
+
+/* Module information */
+MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
+MODULE_DESCRIPTION("pxa2xx WM9713 PCM driver");
+MODULE_LICENSE("GPL");
+
+module_init(pxa_wm9713_init);
+module_exit(pxa_wm9713_exit);
diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig
new file mode 100644
index 0000000..7b4eb22
--- /dev/null
+++ b/sound/soc/pxa/Kconfig
@@ -0,0 +1,35 @@
+config SND_PXA2xx_SOC
+	tristate "SoC Audio for the Intel PXA2xx chip"
+	depends on ARCH_PXA && SND
+	select SND_AC97_CODEC
+	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_SOC_AC97
+	tristate "SoC AC97 driver for the Intel PXA2xx chip"
+	depends on SND_PXA2xx_SOC
+	select SND_AC97_CODEC
+	select SND_PCM
+	help
+	  Say Y or M if you want to add support for AC97 codecs attached to
+	  the PXA2xx AC97 interface.
+	  
+config SND_PXA2xx_SOC_I2S
+	tristate "SoC I2S driver for the Intel PXA2xx chip"
+	depends on SND_PXA2xx_SOC
+	select SND_PCM
+	help
+	  Say Y or M if you want to add support for I2S codecs attached to
+	  the PXA2xx I2S interface.
+	  
+config SND_PXA2xx_SOC_SSP
+	tristate "SoC SSP driver for the Intel PXA2xx chip"
+	depends on SND_PXA2xx_SOC
+	select SND_PCM
+	select PXA_SSP
+	help
+	  Say Y or M if you want to add support for PCM codecs attached to
+	  the PXA2xx SSP interface.
diff --git a/sound/soc/pxa/Makefile b/sound/soc/pxa/Makefile
new file mode 100644
index 0000000..d6f1fe5
--- /dev/null
+++ b/sound/soc/pxa/Makefile
@@ -0,0 +1,10 @@
+
+snd-pxa2xx-soc-objs := pxa2xx-pcm.o 
+snd-pxa2xx-soc-ac97-objs := pxa2xx-ac97.o 
+snd-pxa2xx-soc-i2s-objs := pxa2xx-i2s.o 
+snd-pxa2xx-soc-ssp-objs := pxa2xx-ssp.o
+
+obj-$(CONFIG_SND_PXA2xx_SOC) += snd-pxa2xx-soc.o
+obj-$(CONFIG_SND_PXA2xx_SOC_AC97) += snd-pxa2xx-soc-ac97.o
+obj-$(CONFIG_SND_PXA2xx_SOC_I2S) += snd-pxa2xx-soc-i2s.o
+obj-$(CONFIG_SND_PXA2xx_SOC_SSP) += snd-pxa2xx-soc-ssp.o
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
new file mode 100644
index 0000000..d729da8
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -0,0 +1,396 @@
+/*
+ * 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/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;
+
+/*
+ * 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(ac97_t *ac97, unsigned short reg)
+{
+	unsigned short val = -1;
+	volatile unsigned long *reg_addr;
+
+	down(&car_mutex);
+
+	/* set up primary or secondary codec/modem space */
+#ifdef CONFIG_PXA27x
+	reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE;
+#else
+	if (reg == AC97_GPIO_STATUS)
+		reg_addr = (ac97->num & 1) ? &SMC_REG_BASE : &PMC_REG_BASE;
+	else
+		reg_addr = (ac97->num & 1) ? &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=%d 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(ac97_t *ac97, unsigned short reg, unsigned short val)
+{
+	volatile unsigned long *reg_addr;
+
+	down(&car_mutex);
+
+	/* set up primary or secondary codec/modem space */
+#ifdef CONFIG_PXA27x
+	reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE;
+#else
+	if (reg == AC97_GPIO_STATUS)
+		reg_addr = (ac97->num & 1) ? &SMC_REG_BASE : &PMC_REG_BASE;
+	else
+		reg_addr = (ac97->num & 1) ? &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=%d GSR=%#lx)\n",
+				__FUNCTION__, reg, GSR | gsr_bits);
+
+	up(&car_mutex);
+}
+
+static void pxa2xx_ac97_reset(ac97_t *ac97)
+{
+	/* First, try cold reset */
+	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);
+
+		/* let's try warm reset */
+		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 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;
+}
+
+static ac97_bus_ops_t pxa2xx_ac97_ops = {
+	.read	= pxa2xx_ac97_read,
+	.write	= pxa2xx_ac97_write,
+	.reset	= pxa2xx_ac97_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_BURST32 | DCMD_WIDTH4,
+};
+
+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_BURST32 | DCMD_WIDTH4,
+};
+
+#ifdef CONFIG_PM
+
+static int pxa2xx_ac97_suspend(snd_soc_pcm_interface_t *interface, pm_message_t state)
+{
+	snd_card_t *card = interface->card;
+	
+	if (card->power_state != SNDRV_CTL_POWER_D3cold) {
+		pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
+		
+		if (platform_ops && platform_ops->suspend)
+			platform_ops->suspend(platform_ops->priv);
+		GCR |= GCR_ACLINK_OFF;
+		pxa_set_cken(CKEN2_AC97, 0);
+	}
+	
+	return 0;
+}
+
+static int pxa2xx_ac97_resume(snd_soc_pcm_interface_t *interface)
+{
+	snd_card_t *card = interface->card;
+
+	if (card->power_state != SNDRV_CTL_POWER_D0) {
+		pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
+		pxa_set_cken(CKEN2_AC97, 1);
+		if (platform_ops && platform_ops->resume)
+			platform_ops->resume(platform_ops->priv);
+	}
+	return 0;
+}
+
+#else
+#define pxa2xx_ac97_suspend	NULL
+#define pxa2xx_ac97_resume	NULL
+#endif
+
+static int pxa2xx_ac97_probe(snd_soc_pcm_interface_t *interface)
+{
+	ac97_bus_t *ac97_bus;
+	ac97_template_t ac97_template;
+	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);
+
+	ret = snd_ac97_bus(interface->card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus);
+	if (ret)
+		return ret;
+	memset(&ac97_template, 0, sizeof(ac97_template));
+	ret = snd_ac97_mixer(ac97_bus, &ac97_template, &interface->ac97);
+
+	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(snd_soc_pcm_interface_t *interface)
+{
+	GCR |= GCR_ACLINK_OFF;
+	free_irq(IRQ_AC97, NULL);
+	pxa_set_cken(CKEN2_AC97, 0);
+}
+
+static int pxa2xx_ac97_prepare(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	
+	int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+		  AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
+	return snd_ac97_set_rate(pcm_i->ac97, reg, runtime->rate);
+}
+
+static int pxa2xx_ac97_hw_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		if (params_channels(params) == 2)
+			pcm_i->platform_data = &pxa2xx_ac97_pcm_stereo_out;
+		else
+			pcm_i->platform_data = &pxa2xx_ac97_pcm_mono_out;
+	} else {
+		if (params_channels(params) == 2)
+			pcm_i->platform_data = &pxa2xx_ac97_pcm_stereo_in;
+		else
+			pcm_i->platform_data = &pxa2xx_ac97_pcm_mono_in;
+	}
+
+	return 0;
+}
+
+static snd_soc_pcm_interface_t 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 = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | 
+			SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |
+			SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 2,
+			.channels_max = 2,},
+		.capture = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | 
+			SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |
+			SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 2,
+			.channels_max = 2,},
+		.ops = {
+			.prepare = pxa2xx_ac97_prepare,
+			.hw_params = pxa2xx_ac97_hw_params,},
+	},
+};
+
+static int __init pxa2xx_ac97_init(void)
+{
+	return snd_soc_register_interface(pxa_ac97_interface);
+}
+
+static void __exit pxa2xx_ac97_exit(void)
+{
+	snd_soc_unregister_interface(pxa_ac97_interface);
+}
+
+EXPORT_SYMBOL_GPL(pxa_ac97_interface);
+
+module_init(pxa2xx_ac97_init);
+module_exit(pxa2xx_ac97_exit);
+
+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..5dffc04
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-i2s.c
@@ -0,0 +1,316 @@
+/*
+ * 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"
+
+#define PXA_I2S_HWFMT \
+	(SND_SOC_HWFMT_I2S | SND_SOC_HWFMT_LEFT_J  | SND_SOC_HWFMT_CBS_CFS | \
+	SND_SOC_HWFMT_CBM_CFS | SND_SOC_HWFMT_NB_NF)
+
+/*
+ * priv1 is sadiv
+ * priv2 is bits[15..8] = MCLK divisor, bits[7..0] = sr
+ */
+static snd_soc_hw_mode_t pxa2xx_i2s[] = {
+	{PXA_I2S_HWFMT, 	SND_SOC_HWBITS(16),		8000,	64,		0x00000048},
+	{PXA_I2S_HWFMT, 	SND_SOC_HWBITS(16),		11025,	64,		0x00000034},
+	{PXA_I2S_HWFMT, 	SND_SOC_HWBITS(16),		16000,	64,		0x00000024},
+	{PXA_I2S_HWFMT, 	SND_SOC_HWBITS(16),		22050,	64,		0x0000001a},
+	{PXA_I2S_HWFMT, 	SND_SOC_HWBITS(16),		44100,	64,		0x0000000d},
+	{PXA_I2S_HWFMT, 	SND_SOC_HWBITS(16),		48000,	64,		0x0000000c},
+};
+
+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_pcm_dma_params_t pxa2xx_i2s_pcm_mono_out = {
+	.name			= "I2S PCM Mono out",
+	.dev_addr		= __PREG(SADR),
+	.drcmr			= &DRCMRTXSADR,
+	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+static pxa2xx_pcm_dma_params_t pxa2xx_i2s_pcm_mono_in = {
+	.name			= "I2S PCM Mono in",
+	.dev_addr		= __PREG(SADR),
+	.drcmr			= &DRCMRRXSADR,
+	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
+				  DCMD_BURST16 | DCMD_WIDTH2,
+};
+
+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 */
+		.rx = GPIO29_SDATA_IN_I2S_MD,
+		.tx = GPIO30_SDATA_OUT_I2S_MD,
+		.clk = GPIO28_BITCLK_OUT_I2S_MD,
+		.frm = GPIO31_SYNC_I2S_MD,
+	},
+};
+
+static u32 get_sadiv(int rate)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(pxa2xx_i2s); i++) {
+		if (pxa2xx_i2s[i].rate == rate)
+			break;
+	}
+	return pxa2xx_i2s[i].priv1;
+};
+
+static int pxa2xx_i2s_startup(snd_pcm_substream_t *substream)
+{	
+	return 0;
+}
+
+/* do we need 2 waits..... - needs more testing */
+static int pxa_i2s_wait_ready(void)
+{
+	int i;
+	/* flush the Rx FIFO */
+	for(i = 0; i < 16; i++)
+		SADR;
+	return 0;
+}
+
+static int pxa_i2s_wait_close(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)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	int master = 0;
+	
+	if(pcm_i->hw_runtime.hformat & SND_SOC_HWFMT_CBS_CFS)
+		master = 1;
+		
+	pxa_gpio_mode(gpio_bus[master].rx);
+	pxa_gpio_mode(gpio_bus[master].tx);
+	pxa_gpio_mode(gpio_bus[master].frm);
+	pxa_gpio_mode(gpio_bus[master].clk);
+	pxa_set_cken(CKEN8_I2S, 1);
+	pxa_i2s_wait_ready();
+	
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		if (params_channels(params) == 2)
+			pcm_i->platform_data = &pxa2xx_i2s_pcm_stereo_out;
+		else
+			pcm_i->platform_data = &pxa2xx_i2s_pcm_mono_out;
+	} else {
+		if (params_channels(params) == 2)
+			pcm_i->platform_data = &pxa2xx_i2s_pcm_stereo_in;
+		else
+			pcm_i->platform_data = &pxa2xx_i2s_pcm_mono_in;
+	}
+	printk("hw sub rate %d chn %d\n", params_rate(params), params_channels(params));
+	return 0;
+}
+
+static void pxa2xx_i2s_shutdown(snd_pcm_substream_t *substream)
+{
+
+	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)) {
+		pxa_i2s_wait_close();
+		SACR0 &= ~SACR0_ENB;
+		pxa_set_cken(CKEN8_I2S, 0);
+	}
+}
+
+static int pxa2xx_i2s_prepare(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	int master = 0;
+	
+	if(pcm_i->hw_runtime.hformat & SND_SOC_HWFMT_CBS_CFS)
+		master = 1;
+	
+	/* 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 (master)
+			SACR0 |= SACR0_BCKD;
+		
+		SACR0 |= SACR0_RFTH(14) | SACR0_TFTH(1);
+	
+		if (pcm_i->hw_runtime.hformat & 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 = get_sadiv(pcm_i->hw_runtime.rate);
+		SACR0 |= SACR0_ENB;
+	}
+	
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int pxa2xx_i2s_suspend(snd_soc_pcm_interface_t *interface, pm_message_t state)
+{
+	int ret = 0;
+
+	//if (interface->card && level == SUSPEND_DISABLE)
+		//ret = pxa2xx_ac97_do_suspend(card, SNDRV_CTL_POWER_D3cold);
+
+	return ret;
+}
+
+static int pxa2xx_i2s_resume(snd_soc_pcm_interface_t *interface)
+{
+	int ret = 0;
+
+	//if (interface->card && level == RESUME_ENABLE)
+		//ret = pxa2xx_ac97_do_resume(card, SNDRV_CTL_POWER_D0);
+
+	return ret;
+}
+
+#else
+#define pxa2xx_i2s_suspend	NULL
+#define pxa2xx_i2s_resume	NULL
+#endif
+
+static int pxa2xx_i2s_probe(snd_soc_pcm_interface_t *interface)
+{
+	return 0;
+}
+
+static void pxa2xx_i2s_remove(snd_soc_pcm_interface_t *interface)
+{
+}
+
+static snd_soc_pcm_interface_t pxa_i2s_interface[] = {
+	{	.name = "pxa2xx-i2s",
+		.id = 0,
+		.type = SND_SOC_I2S,
+		.probe = pxa2xx_i2s_probe,
+		.remove = pxa2xx_i2s_remove,
+		.suspend = pxa2xx_i2s_suspend,
+		.resume = pxa2xx_i2s_resume,
+		.playback = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | 
+			SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |
+			SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 2,
+			.channels_max = 2,},
+		.capture = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | 
+			SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |
+			SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 2,
+			.channels_max = 2,},
+		.ops = {
+			.startup = pxa2xx_i2s_startup,
+			.shutdown = pxa2xx_i2s_shutdown,
+			.prepare = pxa2xx_i2s_prepare,
+			.hw_params = pxa2xx_i2s_hw_params,},
+		.hw = {
+			.num_hmodes = ARRAY_SIZE(pxa2xx_i2s),
+			.hmodes = &pxa2xx_i2s[0],},
+	},
+};
+
+static int __init pxa2xx_soc_i2s_init(void)
+{
+	snd_soc_register_interface(pxa_i2s_interface);
+	return 0;
+}
+
+static void __exit pxa2xx_soc_i2s_exit(void)
+{
+	snd_soc_unregister_interface(pxa_i2s_interface);
+}
+
+EXPORT_SYMBOL_GPL(pxa_i2s_interface);
+
+module_init(pxa2xx_soc_i2s_init);
+module_exit(pxa2xx_soc_i2s_exit);
+
+/* 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..5cfad9c
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-pcm.c
@@ -0,0 +1,399 @@
+/*
+ * 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/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 struct device* pxa2xx_dev = NULL;
+static pxa2xx_audio_ops_t *platform_ops = NULL;
+
+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 *rtd = 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",
+			rtd->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;
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	struct pxa2xx_runtime_data *rtd = runtime->private_data;
+	size_t totsize = params_buffer_bytes(params);
+	size_t period = params_period_bytes(params);
+	pxa2xx_pcm_dma_params_t *dma = 
+		(pxa2xx_pcm_dma_params_t*)pcm_c->pcm_i->platform_data;
+	pxa_dma_desc *dma_desc;
+	dma_addr_t dma_buff_phys, next_desc_phys;
+	int ret;
+	
+	rtd->params = dma;
+	ret = pxa_request_dma(rtd->params->name, DMA_PRIO_LOW,
+			      pxa2xx_pcm_dma_irq, substream);
+	if (ret < 0)
+		return ret;
+	rtd->dma_ch = ret;
+	
+	snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
+	runtime->dma_bytes = totsize;
+
+	dma_desc = rtd->dma_desc_array;
+	next_desc_phys = rtd->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 = rtd->params->dev_addr;
+		} else {
+			dma_desc->dsadr = rtd->params->dev_addr;
+			dma_desc->dtadr = dma_buff_phys;
+		}
+		if (period > totsize)
+			period = totsize;
+		dma_desc->dcmd = rtd->params->dcmd | period | DCMD_ENDIRQEN;
+		dma_desc++;
+		dma_buff_phys += period;
+	} while (totsize -= period);
+	dma_desc[-1].ddadr = rtd->dma_desc_array_phys;
+
+	return 0;
+}
+
+static int pxa2xx_pcm_hw_free(snd_pcm_substream_t *substream)
+{
+	struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
+ 
+	if(rtd && rtd->params)
+		*rtd->params->drcmr = 0;
+	
+	if(rtd->dma_ch) {
+		snd_pcm_set_runtime_buffer(substream, NULL);
+		pxa_free_dma(rtd->dma_ch);
+		rtd->dma_ch = 0;
+	}
+	
+	return 0;
+}
+
+static int pxa2xx_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	struct pxa2xx_runtime_data *rtd = runtime->private_data;
+
+	DCSR(rtd->dma_ch) &= ~DCSR_RUN;
+	DCSR(rtd->dma_ch) = 0;
+	DCMD(rtd->dma_ch) = 0;
+	*rtd->params->drcmr = rtd->dma_ch | DRCMR_MAPVLD;
+
+	return 0;
+}
+
+static int pxa2xx_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
+{
+	struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
+	int ret = 0;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		DDADR(rtd->dma_ch) = rtd->dma_desc_array_phys;
+		DCSR(rtd->dma_ch) = DCSR_RUN;
+		break;
+
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		DCSR(rtd->dma_ch) &= ~DCSR_RUN;
+		break;
+
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		DCSR(rtd->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 *rtd = runtime->private_data;
+	dma_addr_t ptr = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+			 DSADR(rtd->dma_ch) : DTADR(rtd->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 *rtd;
+	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;
+
+	ret = -ENOMEM;
+	rtd = kmalloc(sizeof(*rtd), GFP_KERNEL);
+	if (!rtd)
+		goto out;
+	memset(rtd, 0, sizeof(struct pxa2xx_runtime_data));
+	rtd->dma_desc_array =
+		dma_alloc_writecombine(substream->pcm->card->dev, PAGE_SIZE,
+				       &rtd->dma_desc_array_phys, GFP_KERNEL);
+	if (!rtd->dma_desc_array)
+		goto err1;
+
+	runtime->private_data = rtd;
+
+	if (platform_ops && platform_ops->startup)
+		platform_ops->startup(substream, platform_ops->priv);
+	return ret;
+
+ err1:
+	kfree(rtd);
+ out:
+	return ret;
+}
+
+static int pxa2xx_pcm_close(snd_pcm_substream_t *substream)
+{
+	struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
+	
+	if (platform_ops && platform_ops->shutdown)
+		platform_ops->shutdown(substream, platform_ops->priv);
+		
+	dma_free_writecombine(substream->pcm->card->dev, PAGE_SIZE,
+			      rtd->dma_desc_array, rtd->dma_desc_array_phys);
+	kfree(rtd);
+	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, snd_soc_pcm_codec_t *pcm_c,
+	int play, int capt, snd_pcm_t *pcm)
+{
+	int ret = 0;
+
+	pcm->private_free = pxa2xx_pcm_free_dma_buffers;
+	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 (play) {
+		ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_PLAYBACK);
+		if (ret)
+			goto out;
+	}
+
+	if (capt) {
+		ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_CAPTURE);
+		if (ret)
+			goto out;
+	}
+ out:
+	return ret;
+}
+
+snd_soc_platform_t pxa2xx_soc_platform;
+
+static int pxa2xx_soc_probe(struct device *dev)
+{
+	pxa2xx_dev = dev;
+	platform_ops = pxa2xx_dev->platform_data;
+	return 0;
+}
+
+static int pxa2xx_soc_remove(struct device *dev)
+{
+	pxa2xx_dev = NULL;
+	platform_ops = NULL;
+	return 0;
+}
+
+static int __init pxa2xx_soc_init(void)
+{
+	return snd_soc_register_platform(&pxa2xx_soc_platform);
+}
+
+static void __exit pxa2xx_soc_exit(void)
+{
+	snd_soc_unregister_platform(&pxa2xx_soc_platform);
+}
+
+snd_soc_platform_t pxa2xx_soc_platform = {
+	.name		= "pxa2xx-audio",
+	.bus		= &platform_bus_type,
+	.probe		= pxa2xx_soc_probe,
+	.remove		= pxa2xx_soc_remove,
+	.pcm_ops 	= &pxa2xx_pcm_ops,
+	.pcm_new	= pxa2xx_pcm_new,
+};
+
+module_init(pxa2xx_soc_init);
+module_exit(pxa2xx_soc_exit);
+
+EXPORT_SYMBOL(pxa2xx_pcm_new);
+
+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..eebe005
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-pcm.h
@@ -0,0 +1,26 @@
+/*
+ * 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 unsigned long *drcmr;		/* the DMA request channel to use */
+	u32 dev_addr;			/* device physical address for DMA */
+} pxa2xx_pcm_dma_params_t;
+
+typedef struct {
+	u32	rx;
+	u32 tx;
+	u32 clk;
+	u32 frm;
+} pxa2xx_gpio_t;
+
diff --git a/sound/soc/pxa/pxa2xx-ssp.c b/sound/soc/pxa/pxa2xx-ssp.c
new file mode 100644
index 0000000..7df14f4
--- /dev/null
+++ b/sound/soc/pxa/pxa2xx-ssp.c
@@ -0,0 +1,458 @@
+/*
+ * 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.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/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"
+
+/*
+ * 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_HWFMT \
+	(SND_SOC_HWFMT_DSP_B  |SND_SOC_HWFMT_CBM_CFM | SND_SOC_HWFMT_CBM_CFS | \
+	SND_SOC_HWFMT_CBS_CFM | SND_SOC_HWFMT_CBS_CFS | SND_SOC_HWFMT_NB_NF | \
+	SND_SOC_HWFMT_NB_IF)
+
+/*
+ * priv1 is scr divider when in master mode
+ * -- liam, need some method of "doesn't matter" for fs, maybe 0  
+ */
+static snd_soc_hw_mode_t pxa2xx_ssp[] = {
+	{PXA_SSP_HWFMT, 	SND_SOC_HWBITS(16),		8000,	256,	1626},
+	{PXA_SSP_HWFMT, 	SND_SOC_HWBITS(16),		8000,	384,	1626}, 
+	{PXA_SSP_HWFMT, 	SND_SOC_HWBITS(16),		11025,	256,	1180},
+	{PXA_SSP_HWFMT, 	SND_SOC_HWBITS(16),		16000,	256,	813},
+	{PXA_SSP_HWFMT, 	SND_SOC_HWBITS(16),		22050,	256,	590},
+	{PXA_SSP_HWFMT, 	SND_SOC_HWBITS(16),		44100,	256,	295},
+	{PXA_SSP_HWFMT, 	SND_SOC_HWBITS(16),		48000,	256,	271},
+};
+
+static struct ssp_dev ssp[3];
+
+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)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	int ret = 0;
+	
+	if((ret = ssp_init (&ssp[pcm_i->id], pcm_i->id + 1, SSP_NO_IRQ)) < 0)
+		return ret;
+	
+	ssp_disable(&ssp[pcm_i->id]);
+	return ret;
+}
+
+static void pxa2xx_ssp_shutdown(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+
+	ssp_disable(&ssp[pcm_i->id]);
+	ssp_exit(&ssp[pcm_i->id]);
+}
+
+#ifdef CONFIG_PM
+static int pxa2xx_ssp_suspend(snd_soc_pcm_interface_t *interface, pm_message_t state)
+{
+	int ret = 0;
+
+	//if (interface->card && level == SUSPEND_DISABLE)
+		//ret = pxa2xx_ac97_do_suspend(card, SNDRV_CTL_POWER_D3cold);
+
+	return ret;
+}
+
+static int pxa2xx_ssp_resume(snd_soc_pcm_interface_t *interface)
+{
+	int ret = 0;
+
+	//if (interface->card && level == RESUME_ENABLE)
+		//ret = pxa2xx_ac97_do_resume(card, SNDRV_CTL_POWER_D0);
+
+	return ret;
+}
+
+#else
+#define pxa2xx_ssp_suspend	NULL
+#define pxa2xx_ssp_resume	NULL
+#endif
+
+static int pxa2xx_ssp_hw_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	int master = 0, dma = 0;
+	
+	if(pcm_i->hw_runtime.hformat & SND_SOC_HWFMT_CBS_CFS)
+		master = 1;
+	
+	pxa_gpio_mode(ssp_gpios[pcm_i->id][master].rx);
+	pxa_gpio_mode(ssp_gpios[pcm_i->id][master].tx);
+	pxa_gpio_mode(ssp_gpios[pcm_i->id][master].frm);
+	pxa_gpio_mode(ssp_gpios[pcm_i->id][master].clk);
+	
+	
+	if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
+		dma = 1;
+	if (params_channels(params) == 2)
+		dma += 2;
+	pcm_i->platform_data = ssp_dma_params[pcm_i->id][dma];
+	
+	return 0;
+}
+
+static int pxa2xx_ssp_prepare(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	u32 ssp_mode = 0, ssp_setup = 0, psp_mode = 0;
+	int bits = generic_ffs(pcm_i->hw_runtime.hbits);
+	
+	ssp_mode = SSCR0_PSP | SSCR0_DataSize(bits);
+	ssp_setup = SSCR1_RxTresh(14) | SSCR1_TxTresh(1) | SSCR1_TRAIL |
+				SSCR1_TSRE | SSCR1_RSRE | SSCR1_TIE | SSCR1_RIE;
+	
+	switch(pcm_i->hw_runtime.hformat & SND_SOC_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(pcm_i->hw_runtime.hformat & SND_SOC_INV_MASK){
+		case SND_SOC_HWFMT_NB_NF:
+			psp_mode |= SSPSP_SFRMP;
+			break;
+	}
+	if (pcm_i->hw_runtime.hformat & SND_SOC_HWFMT_DSP_A)
+		psp_mode |= SSPSP_SCMODE(2);
+	if (pcm_i->hw_runtime.hformat & SND_SOC_HWFMT_DSP_B)
+		psp_mode |= SSPSP_SCMODE(3);
+
+	ssp_disable(&ssp[pcm_i->id]);
+	ssp_config(&ssp[pcm_i->id], ssp_mode, ssp_setup, psp_mode,
+					SSCR0_SerClkDiv(pcm_i->hw_runtime.priv1));
+	ssp_enable(&ssp[pcm_i->id]);
+	
+	return 0;
+}
+
+static int pxa2xx_ssp_probe(snd_soc_pcm_interface_t *interface)
+{
+	return 0;
+}
+
+static void pxa2xx_ssp_remove(snd_soc_pcm_interface_t *interface)
+{
+}
+
+
+static snd_soc_pcm_interface_t pxa_ssp_interfaces[] = {
+	{	.name = "pxa2xx-ssp1",
+		.id = 0,
+		.type = SND_SOC_SSP,
+		.probe = pxa2xx_ssp_probe,
+		.remove = pxa2xx_ssp_remove,
+		.suspend = pxa2xx_ssp_suspend,
+		.resume = pxa2xx_ssp_resume,
+		.playback = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 1,
+			.channels_max = 1,},
+		.capture = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 1,
+			.channels_max = 2,},
+		.ops = {
+			.startup = pxa2xx_ssp_startup,
+			.shutdown = pxa2xx_ssp_shutdown,
+			.prepare = pxa2xx_ssp_prepare,
+			.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,
+		.probe = pxa2xx_ssp_probe,
+		.remove = pxa2xx_ssp_remove,
+		.suspend = pxa2xx_ssp_suspend,
+		.resume = pxa2xx_ssp_resume,
+		.playback = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 1,
+			.channels_max = 1,},
+		.capture = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 1,
+			.channels_max = 1,},
+		.ops = {
+			.startup = pxa2xx_ssp_startup,
+			.shutdown = pxa2xx_ssp_shutdown,
+			.prepare = pxa2xx_ssp_prepare,
+			.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,
+		.probe = pxa2xx_ssp_probe,
+		.remove = pxa2xx_ssp_remove,
+		.suspend = pxa2xx_ssp_suspend,
+		.resume = pxa2xx_ssp_resume,
+		.playback = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 1,
+			.channels_max = 1,},
+		.capture = {
+			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
+			.formats = SNDRV_PCM_FMTBIT_S16_LE,
+			.channels_min = 1,
+			.channels_max = 1,},
+		.ops = {
+			.startup = pxa2xx_ssp_startup,
+			.shutdown = pxa2xx_ssp_shutdown,
+			.prepare = pxa2xx_ssp_prepare,
+			.hw_params = pxa2xx_ssp_hw_params,},
+		.hw = {
+			.hmodes = &pxa2xx_ssp[0],
+			.num_hmodes = ARRAY_SIZE(pxa2xx_ssp),},
+	},
+};
+
+static int __init pxa2xx_soc_ssp_init(void)
+{
+	snd_soc_register_interface(&pxa_ssp_interfaces[0]);
+	snd_soc_register_interface(&pxa_ssp_interfaces[1]);
+	snd_soc_register_interface(&pxa_ssp_interfaces[2]);
+	return 0;
+}
+
+static void __exit pxa2xx_soc_ssp_exit(void)
+{
+	snd_soc_unregister_interface(&pxa_ssp_interfaces[2]);
+	snd_soc_unregister_interface(&pxa_ssp_interfaces[1]);
+	snd_soc_unregister_interface(&pxa_ssp_interfaces[0]);
+}
+
+EXPORT_SYMBOL_GPL(pxa_ssp_interfaces);
+
+module_init(pxa2xx_soc_ssp_init);
+module_exit(pxa2xx_soc_ssp_exit);
+
+/* 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/soc-core.c b/sound/soc/soc-core.c
new file mode 100644
index 0000000..69b3f3c
--- /dev/null
+++ b/sound/soc/soc-core.c
@@ -0,0 +1,789 @@
+/*
+ * 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.
+ *
+ *  TODO:
+ *   o Check return values for interface and codec calbacks
+ *   o Should probably add hw rules to enforce rates, etc.
+ *   o Testing.....
+ *   o Add more codecs and platforms to ensure good API coverage.
+ */
+
+#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/i2c.h>
+#include <linux/pm.h>
+#include <linux/bitops.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-dpm.h>
+#include <sound/initval.h>
+
+#define SND_SOC_VERSION "0.2"
+
+#define iface_name(x) \
+	(((x) == SND_SOC_AC97) ? "ac97" : \
+	((x) == SND_SOC_I2S) ? "i2s" : \
+	((x) == SND_SOC_SSP) ? "ssp" : NULL)
+
+static DECLARE_MUTEX(soc_sem);
+static LIST_HEAD(codecs);
+static LIST_HEAD(interfaces);
+static struct snd_soc_platform *platform = NULL;
+
+
+int snd_soc_update_bits(snd_soc_codec_t *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;
+}
+
+int snd_soc_test_bits(snd_soc_codec_t *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;
+}
+
+
+static int soc_match_hw(snd_soc_hw_mode_t *c, snd_soc_hw_mode_t *i, int rate, int fs)
+{
+	if (c->rate != i->rate)
+		return 0;
+	
+	if (c->rate != rate)
+		return 0;
+	
+	if (c->fs != i->fs)
+		return 0;
+	
+	if (!(c->hformat & i->hformat & SND_SOC_FORMAT_MASK))
+		return 0;
+	
+	if (!(c->hformat & i->hformat & SND_SOC_CLOCK_MASK))
+		return 0;
+	
+	if (!(c->hformat & i->hformat & SND_SOC_INV_MASK))
+		return 0;
+	
+	if (i->fs < fs)
+		return i->fs;
+	return 0;
+}
+
+static int soc_check_hw_params(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *params)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	int fs = 2048, i, j, match = 0;	
+	
+	for (i = 0; i < pcm_c->hw.num_hmodes; i++) {
+		for (j = 0; j < pcm_i->hw.num_hmodes; j++) {
+			if (soc_match_hw(&pcm_c->hw.hmodes[i], &pcm_i->hw.hmodes[j], 
+					params_rate(params), fs)) {
+				pcm_c->hw_runtime = pcm_c->hw.hmodes[i];
+				pcm_i->hw_runtime = pcm_i->hw.hmodes[j];
+				fs = pcm_c->hw.hmodes[i].fs;
+				match = 1;
+			}
+		}
+	}
+	
+	if (!match) {
+		printk(KERN_ERR "Can't match codec and interface capabilities\n");
+		return -EINVAL;
+	}
+	
+	pcm_i->hw_runtime.hformat =
+		1 << (generic_ffs(pcm_i->hw_runtime.hformat & pcm_c->hw_runtime.hformat & SND_SOC_FORMAT_MASK) -1) | 
+		1 << (generic_ffs(pcm_i->hw_runtime.hformat & pcm_c->hw_runtime.hformat & SND_SOC_CLOCK_MASK) - 1) |
+		1 << (generic_ffs(pcm_i->hw_runtime.hformat & pcm_c->hw_runtime.hformat & SND_SOC_INV_MASK) - 1);
+
+	pcm_i->hw_runtime.hbits = pcm_i->hw_runtime.hbits & pcm_c->hw_runtime.hbits;
+	pcm_c->hw_runtime.hformat = pcm_i->hw_runtime.hformat;
+	pcm_c->hw_runtime.hbits = pcm_i->hw_runtime.hbits;
+	
+	printk(KERN_INFO "codec rate %d fs %d format %x\n", pcm_c->hw_runtime.rate, 
+		pcm_c->hw_runtime.fs, pcm_c->hw_runtime.hformat);
+	printk(KERN_INFO "iface rate %d fs %d format %x\n", pcm_i->hw_runtime.rate, 
+		pcm_i->hw_runtime.fs, pcm_i->hw_runtime.hformat);
+	printk(KERN_INFO "audio rate %d chn %d\n", params_rate(params), params_channels(params));	
+	
+	return 0;
+}
+
+static int soc_pcm_open(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	snd_pcm_runtime_t *runtime = substream->runtime;
+
+	/* Check that the codec and SoC audio interface's are compatible */
+	if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		runtime->hw.rates = pcm_c->playback.rates & pcm_i->playback.rates;
+		runtime->hw.formats = pcm_c->playback.formats & pcm_i->playback.formats;
+		runtime->hw.rate_min = max(pcm_c->playback.rate_min, pcm_i->playback.rate_min);
+		runtime->hw.rate_max = min(pcm_c->playback.rate_max, pcm_i->playback.rate_max);
+		runtime->hw.channels_min = max(pcm_c->playback.channels_min, pcm_i->playback.channels_min);
+		runtime->hw.channels_max = min(pcm_c->playback.channels_max, pcm_i->playback.channels_max);
+	} else {
+		runtime->hw.rates = pcm_c->capture.rates & pcm_i->capture.rates;
+		runtime->hw.formats = pcm_c->capture.formats & pcm_i->capture.formats;
+		runtime->hw.rate_min = max(pcm_c->capture.rate_min, pcm_i->capture.rate_min);
+		runtime->hw.rate_max = min(pcm_c->capture.rate_max, pcm_i->capture.rate_max);
+		runtime->hw.channels_min = max(pcm_c->capture.channels_min, pcm_i->capture.channels_min);
+		runtime->hw.channels_max = min(pcm_c->capture.channels_max, pcm_i->capture.channels_max);
+	}
+	snd_pcm_limit_hw_rates(runtime);
+	if (!runtime->hw.rates) {
+		printk(KERN_ERR "%s <-> %s No matching rates\n", pcm_c->name, pcm_i->name);
+		return -ENODEV;
+	}
+	if(!runtime->hw.formats) {
+		printk(KERN_ERR "%s <-> %s No matching formats\n", pcm_c->name, pcm_i->name);
+		return -ENODEV;
+	}
+	if(!runtime->hw.channels_min || !runtime->hw.channels_max) {
+		printk(KERN_ERR "%s <-> %s No matching channels\n", pcm_c->name, pcm_i->name);
+		return -ENODEV;
+	}
+	printk(KERN_INFO "%s <-> %s info:\n", pcm_c->name, pcm_i->name);
+	printk(KERN_INFO "rates %x n\nmin ch %d max ch %d\nmin 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(pcm_i->ops.startup)
+		pcm_i->ops.startup(substream);
+	
+	if(platform->pcm_ops->open)
+		platform->pcm_ops->open(substream);
+	
+	if(pcm_c->ops.startup)
+		pcm_c->ops.startup(substream);
+
+	return 0;
+}
+
+static int soc_pcm_close(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+
+	if(pcm_i->ops.shutdown)
+		pcm_i->ops.shutdown(substream);
+	
+	if(pcm_c->ops.shutdown)
+		pcm_c->ops.shutdown(substream);
+	
+	if(platform->pcm_ops->close)
+		platform->pcm_ops->close(substream);
+
+	return 0;
+}
+
+static int soc_pcm_prepare(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	
+	if(platform->pcm_ops->prepare)
+		platform->pcm_ops->prepare(substream);
+	
+	if(pcm_c->ops.prepare)
+		pcm_c->ops.prepare(substream);
+	
+	if(pcm_i->ops.prepare)
+		pcm_i->ops.prepare(substream);
+
+	return 0;
+}
+
+static int soc_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+
+	if(pcm_c->ops.trigger)
+		pcm_c->ops.trigger(substream, cmd);
+	
+	if(pcm_i->ops.trigger)
+		pcm_i->ops.trigger(substream, cmd);
+	
+	if(platform->pcm_ops->trigger)
+		platform->pcm_ops->trigger(substream, cmd);
+
+	return 0;
+}
+
+static int soc_pcm_hw_params(snd_pcm_substream_t *substream,
+				snd_pcm_hw_params_t *params)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	int ret;
+
+	/* prepare hw non AC97 only */
+	if(pcm_i->type != SND_SOC_AC97) {
+		if((ret = soc_check_hw_params(substream, params)) < 0)
+			return ret;
+	}
+	
+	if(pcm_c->ops.hw_params)
+		pcm_c->ops.hw_params(substream, params);
+	
+	if(pcm_i->ops.hw_params)
+		pcm_i->ops.hw_params(substream, params);
+	
+	if(platform->pcm_ops->hw_params)
+		platform->pcm_ops->hw_params(substream, params);
+	
+	return 0;
+}
+
+static int soc_pcm_hw_free(snd_pcm_substream_t *substream)
+{
+	snd_soc_pcm_codec_t *pcm_c = substream->private_data;
+	snd_soc_pcm_interface_t *pcm_i = pcm_c->pcm_i;
+	
+	if(pcm_c->ops.hw_free)
+		pcm_c->ops.hw_free(substream);
+	
+	if(pcm_i->ops.hw_free)
+		pcm_i->ops.hw_free(substream);
+	
+	if(platform->pcm_ops->hw_free)
+		platform->pcm_ops->hw_free(substream);
+	
+	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
+/*
+ * SUSPEND_NOTIFY - mute outputs
+ * SUSPEND_DISABLE - power down chip
+ */
+static int soc_suspend(snd_card_t *card, pm_message_t state)
+{
+	snd_soc_codec_t *c = card->pm_private_data;
+	snd_soc_pcm_interface_t *i = c->interface;
+	
+	snd_pcm_suspend_all(c->pcm);
+	if(c->suspend)
+		c->suspend(c, state);
+	if(i->suspend)
+		i->suspend(i, state);
+	snd_power_change_state(card, SNDRV_CTL_POWER_D3cold);
+	
+	return 0;
+}
+
+static int soc_resume(snd_card_t * card)
+{
+	snd_soc_codec_t *c = card->pm_private_data;
+	snd_soc_pcm_interface_t *i = c->interface;
+	
+	if(c->resume)
+		c->resume(c);
+	if(i->resume)
+		i->resume(i);
+	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+
+	return 0;
+}
+
+#else
+#define soc_suspend	NULL
+#define soc_resume	NULL
+#endif
+
+static int soc_probe_codec(snd_soc_codec_t *codec)
+{
+	int ret = 0;
+	
+	if(codec->probed)
+		return 0;
+	
+	/* register a sound card */
+	codec->card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, codec->owner, 0);
+	if (!codec->card)
+		return -ENODEV;
+
+	platform_device_register(&codec->pdev);
+	codec->card->dev = &codec->pdev.dev;
+	strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
+		
+	if((ret = codec->probe(codec)) < 0)
+		goto err;
+	if(!codec->interface)
+		goto err;
+		
+	snprintf(codec->card->shortname, sizeof(codec->card->shortname),
+		 "%s", codec->name);
+	snprintf(codec->card->longname, sizeof(codec->card->longname),
+		 "%s (%s)", codec->longname, "SoC");
+	
+	if((ret = snd_card_register(codec->card)) < 0)
+		goto err;
+		
+	if(codec->interface->probe)
+		if((ret = codec->interface->probe(codec->interface)) < 0)
+			goto err;
+
+	snd_card_set_pm_callback(codec->card, soc_suspend, soc_resume, codec);		     
+	codec->probed = 1;
+
+	return 0;
+	
+err:
+	snd_card_free(codec->card);
+	platform_device_unregister(&codec->pdev);
+	codec->card = NULL;
+	return ret;
+}
+
+static void soc_free_dpm_widgets(snd_soc_codec_t *codec)
+{
+	snd_soc_dpm_widget_t *w, *lw = NULL;
+	snd_soc_dpm_path_t *p, *lp = NULL;
+	struct list_head *l;
+	
+	list_for_each(l, &codec->dpm_widgets)
+	{
+		w =  list_entry(l, snd_soc_dpm_widget_t, list);
+		if (lw)
+			kfree(lw);
+		lw = w;
+	}
+	kfree(lw);
+	
+	list_for_each(l, &codec->dpm_paths)
+	{
+		p =  list_entry(l, snd_soc_dpm_path_t, list);
+		if(p->long_name)
+			kfree(p->long_name);
+		if (lp)
+			kfree(lp);
+		lp = p;
+	}
+	kfree(lp);
+}
+
+static int soc_remove_codec(snd_soc_codec_t *codec)
+{	
+	if (!codec->probed)
+		return 0;
+	
+	if (codec->card) {
+		snd_card_free(codec->card);
+		platform_device_unregister(&codec->pdev);
+		codec->card = NULL;
+	}
+
+	if(codec->interface->remove)
+		codec->interface->remove(codec->interface);
+	codec->remove(codec);
+	
+	/* free any DPM objects */
+	soc_free_dpm_widgets(codec);
+	codec->probed = 0;
+	return 0;
+}
+
+int snd_soc_register_codec(snd_soc_codec_t *codec)
+{
+	down(&soc_sem);
+	INIT_LIST_HEAD(&codec->list);
+	INIT_LIST_HEAD(&codec->dpm_widgets);
+	INIT_LIST_HEAD(&codec->dpm_paths);
+	list_add(&codec->list, &codecs);
+
+	up(&soc_sem);
+	if (platform)
+		return soc_probe_codec(codec);
+	
+	return 0;
+}
+
+void snd_soc_unregister_codec(snd_soc_codec_t *codec)
+{
+	down(&soc_sem); 
+	list_del_init(&codec->list);
+	soc_remove_codec(codec);	
+	up(&soc_sem);
+}
+
+int snd_soc_register_interface(snd_soc_pcm_interface_t *iface)
+{	
+	down (&soc_sem);
+	INIT_LIST_HEAD(&iface->list);
+	list_add(&iface->list, &interfaces);
+	up(&soc_sem);
+	return 0;
+}
+
+void snd_soc_unregister_interface(snd_soc_pcm_interface_t *iface)
+{
+	down(&soc_sem);
+	list_del_init(&iface->list);
+	//if (platform && iface->remove) 
+	//	iface->remove(iface);
+	up(&soc_sem);	
+}
+
+static struct device_driver soc_pdrv;
+
+int snd_soc_register_platform(snd_soc_platform_t *p)
+{
+	struct list_head *l;
+	snd_soc_codec_t *c;
+	int ret;
+		
+	down(&soc_sem);
+	if(platform) {
+		up(&soc_sem);
+		return -EBUSY;
+	}
+	platform = p;
+	soc_pcm_ops.mmap = p->pcm_ops->mmap;
+	soc_pcm_ops.pointer = p->pcm_ops->pointer;
+	soc_pcm_ops.ioctl = p->pcm_ops->ioctl;
+	soc_pdrv.bus = p->bus;
+	soc_pdrv.name = p->name;
+	soc_pdrv.probe = p->probe;
+	soc_pdrv.remove = p->remove;
+	up(&soc_sem);	
+		
+	if((ret = driver_register(&soc_pdrv)) < 0) {
+		printk(KERN_ERR "SoC: Failed to register platform %s\n", p->name);
+		return ret;
+	}
+	
+	list_for_each(l, &codecs) {
+		c = list_entry(l, snd_soc_codec_t, list);
+		ret = soc_probe_codec(c);
+		if (ret < 0)
+			printk(KERN_ERR "SoC: Probe of codec %s failed\n", c->name);
+	}
+	
+	return 0;
+}
+
+void snd_soc_unregister_platform(snd_soc_platform_t *platform)
+{
+	struct list_head *l;
+	snd_soc_codec_t *c;
+
+	down(&soc_sem);
+	list_for_each(l, &codecs) {
+		c = list_entry(l, snd_soc_codec_t, list);
+		soc_remove_codec(c);
+	}
+	up(&soc_sem);
+	
+	driver_unregister(&soc_pdrv);
+	
+	down(&soc_sem);
+	platform = NULL;
+	up(&soc_sem);	
+}
+
+int snd_soc_pcm_new(snd_soc_codec_t *codec, int dev_no, snd_soc_pcm_codec_t *pcm_c, 
+		snd_pcm_t **rpcm, int play, int capt, int iface_type, int num)
+{
+	snd_pcm_t *pcm;
+	snd_card_t *card = codec->card;
+	int ret;
+	struct list_head *l;
+	snd_soc_pcm_interface_t *i = NULL;
+	char name[32];
+		
+	down(&soc_sem);
+	list_for_each(l, &interfaces) {
+		i = list_entry(l, snd_soc_pcm_interface_t, list);
+		if (i->type == iface_type && i->id == num){
+			if (i->pcm_c){
+				up(&soc_sem);
+				return -EBUSY;
+			} else
+				break;	
+		}
+	}
+	
+	/* check client and interface hw capabilities */
+	pcm_c->pcm_i = i;
+	i->card = card;
+	i->pcm_c = pcm_c;
+	codec->interface = i;
+	sprintf(name, "%s-%s-%d", pcm_c->name, iface_name(iface_type), num);
+	ret = snd_pcm_new(card, name, dev_no, play, capt, &pcm);
+	if (ret)
+		goto err;
+
+	pcm->private_data = pcm_c;
+	if (play)
+		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
+
+	if (capt)
+		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
+
+	if((ret = platform->pcm_new(card, pcm_c, play, capt, pcm)) < 0)
+		goto err;
+	codec->pcm = pcm;
+	if (rpcm)
+		*rpcm = pcm;
+
+	printk(KERN_INFO "%s <-> %s mapping ok\n", pcm_c->name, i->name);
+	up(&soc_sem);
+	return 0;
+	
+err:
+	pcm_c->pcm_i = NULL;
+	i->card = NULL;
+	i->pcm_c = NULL;
+	codec->interface = NULL;
+	up(&soc_sem);
+	return ret;
+}
+
+int snd_soc_iface_query(int iface_type, int num)
+{
+	struct list_head *l;
+	snd_soc_pcm_interface_t *i;
+
+	down(&soc_sem);
+	list_for_each(l, &interfaces) {
+		i = list_entry(l, snd_soc_pcm_interface_t, list);
+		if (i->type == iface_type && i->id == num){
+			up(&soc_sem);
+			return 0;
+		}
+	}
+	up(&soc_sem);
+	return -ENODEV;
+}
+
+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;
+}
+
+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;
+	snd_runtime_check(!template.index, return NULL);
+	//template.index = codec->num;
+	return snd_ctl_new1(&template, data);
+}
+
+/*
+ * Controls
+ */
+
+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;
+}
+
+int snd_soc_dpm_get_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	snd_soc_dpm_widget_t *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;
+}
+
+int snd_soc_put_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	snd_soc_codec_t *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);
+}
+
+/* volume and switch controls */
+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;
+}
+
+int snd_soc_get_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	snd_soc_codec_t *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;
+}
+
+int snd_soc_put_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	snd_soc_codec_t *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;
+}
+
+static int __init snd_soc_init(void) 
+{
+	printk(KERN_INFO "version %s liam.girdwood@wolfsonmicro.com\n", SND_SOC_VERSION);
+	return 0;
+}
+
+static void __exit snd_soc_exit(void) 
+{
+}
+
+module_init(snd_soc_init); 
+module_exit(snd_soc_exit);
+
+EXPORT_SYMBOL_GPL(snd_soc_register_codec);
+EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
+EXPORT_SYMBOL_GPL(snd_soc_register_platform);
+EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
+EXPORT_SYMBOL_GPL(snd_soc_pcm_new);
+EXPORT_SYMBOL_GPL(snd_soc_iface_query);
+EXPORT_SYMBOL_GPL(snd_soc_register_interface);
+EXPORT_SYMBOL_GPL(snd_soc_unregister_interface);
+EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hw);
+EXPORT_SYMBOL_GPL(snd_soc_cnew);
+EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
+EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
+EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
+EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
+EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
+EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
+EXPORT_SYMBOL_GPL(snd_soc_update_bits);
+EXPORT_SYMBOL_GPL(snd_soc_test_bits);
+
+
+/* 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-dpm.c b/sound/soc/soc-dpm.c
new file mode 100644
index 0000000..13d423d
--- /dev/null
+++ b/sound/soc/soc-dpm.c
@@ -0,0 +1,721 @@
+/*
+ * soc-dpm.c  --  ALSA Soc Dynamic 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.
+ */
+
+#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/i2c.h>
+#include <linux/pm.h>
+#include <linux/bitops.h>
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc-dpm.h>
+#include <sound/initval.h>
+
+static snd_soc_dpm_widget_t *snd_soc_cnew_widget(const snd_soc_dpm_widget_t *_widget)
+{
+	snd_soc_dpm_widget_t* widget;
+	widget = kmalloc(sizeof(snd_soc_dpm_widget_t), GFP_KERNEL);
+	if (!widget)
+		return NULL;
+	
+	memcpy(widget, _widget, sizeof(snd_soc_dpm_widget_t));
+	return widget;
+}
+
+int snd_soc_dpm_new_control(snd_soc_codec_t *codec, const snd_soc_dpm_widget_t *widget)
+{
+	snd_soc_dpm_widget_t *w;
+	
+	if ((w = snd_soc_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->dpm_widgets);
+	
+	// liam - remove when implemented
+	w->active = 1; // liam - set by stream ops
+	w->connected = 1; // liam - set by .asoundrc extension
+	
+	return 0;
+}
+
+static void dpm_set_path_status(snd_soc_dpm_widget_t *w, 
+	snd_soc_dpm_path_t *p, int i)
+{	
+	switch (w->id)
+	{
+		case snd_soc_dpm_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 = (reg >> shift) & mask;
+		
+			if((invert && !val) || (!invert && val))
+				p->connect = 1;
+			else
+				p->connect = 0;
+		}
+		break;
+		case snd_soc_dpm_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;
+		/* dont affect routing - always connected */
+		case snd_soc_dpm_volume:
+		case snd_soc_dpm_output:
+		case snd_soc_dpm_adc:
+		case snd_soc_dpm_input:
+		case snd_soc_dpm_dac:
+		case snd_soc_dpm_codec:
+			p->connect = 1;
+		break;
+	}
+	//printk("* %s --> %s %s\n", w->name, p->name, p->connect ? "connect" : "disconnect");
+}	
+
+static int dpm_connect_mux(snd_soc_codec_t *codec, snd_soc_dpm_widget_t *src, snd_soc_dpm_widget_t *dest,
+	snd_soc_dpm_path_t *path, char *control_name, const snd_kcontrol_new_t *kcontrol)
+{
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	int i;
+	
+//printk("control name %s\n", dest->kcontrols[0].name);
+	
+	for (i = 0; i < e->mask; i++) {
+		if (!(strcmp(control_name, e->texts[i]))) {
+			list_add(&path->list, &codec->dpm_paths);
+			list_add(&path->list_out, &dest->inputs);
+			list_add(&path->list_in, &src->outputs);
+			path->name = (char*)e->texts[i];
+			dpm_set_path_status(dest, path, 0);
+//			printk("path name %s\n", path->name);
+			return 0;
+		}
+	}
+
+	return -ENODEV;
+}
+
+static int dpm_connect_mixer(snd_soc_codec_t *codec, snd_soc_dpm_widget_t *src, snd_soc_dpm_widget_t *dest,
+	snd_soc_dpm_path_t *path, 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->dpm_paths);
+			list_add(&path->list_out, &dest->inputs);
+			list_add(&path->list_in, &src->outputs);
+			path->name = dest->kcontrols[i].name;
+			dpm_set_path_status(dest, path, i);
+			return 0;
+		}			
+	}
+	return -ENODEV;
+}
+
+int snd_soc_dpm_connect_input(snd_soc_codec_t *codec, char *dest_name, 
+	char * control_name, char *src_name)
+{
+	snd_soc_dpm_path_t *path;
+	snd_soc_dpm_widget_t *src = NULL, *dest = NULL, *w;
+	struct list_head *l;
+	int ret = 0;
+
+	/* find src and dest widgets */
+	list_for_each(l, &codec->dpm_widgets)
+	{
+		w = list_entry(l, snd_soc_dpm_widget_t, list);
+		
+		if(!(strcmp(w->name, dest_name))) {
+			dest = w;
+			continue;
+		}
+		if(!(strcmp(w->name, src_name))) {
+			src = w;
+		}				
+	}
+
+	if(src == NULL || dest == NULL)
+		return -ENODEV;
+	
+	path = kmalloc(sizeof(snd_soc_dpm_path_t), GFP_KERNEL);
+	if (!path)
+		return -ENOMEM;
+	memset(path, 0, sizeof(snd_soc_dpm_path_t));
+	path->in = src;
+	path->out = dest;
+	INIT_LIST_HEAD(&path->list);
+	INIT_LIST_HEAD(&path->list_in);
+	INIT_LIST_HEAD(&path->list_out);
+
+	if(control_name == NULL) {
+		list_add(&path->list, &codec->dpm_paths);
+		list_add(&path->list_out, &dest->inputs);
+		list_add(&path->list_in, &src->outputs);
+//printk("src %s %p --> dest %s %p\n", src->name, src, dest->name, dest);
+		path->connect = 1;
+		return 0;
+	}
+
+	switch(dest->id) {
+		case snd_soc_dpm_adc:
+		case snd_soc_dpm_dac:
+		case snd_soc_dpm_codec:
+		case snd_soc_dpm_volume:
+		case snd_soc_dpm_input:
+		case snd_soc_dpm_output:
+			list_add(&path->list, &codec->dpm_paths);
+			list_add(&path->list_out, &dest->inputs);
+			list_add(&path->list_in, &src->outputs);
+			path->connect = 1;
+			return 0;
+		case snd_soc_dpm_mux:
+			if((ret = dpm_connect_mux(codec, src, dest, path, control_name, &dest->kcontrols[0])) != 0)
+				goto err;
+			break;
+		case snd_soc_dpm_mixer:
+			if((ret = dpm_connect_mixer(codec, src, dest, path, control_name)) != 0)
+				goto err;
+			break;
+	}
+	return 0;
+
+err:
+	printk(KERN_WARNING "No match for %s --> %s --> %s\n", src_name, 
+		control_name, dest_name); 
+	kfree(path);
+	return ret;
+}
+
+
+static int snd_soc_dpm_update_bits(snd_soc_dpm_widget_t *widget, int power)
+{
+	int change;
+	unsigned short old, new;
+	snd_soc_codec_t *codec = widget->codec;
+	
+	if(power)
+		power = 1;
+	
+	old = snd_soc_read(codec, widget->reg);
+	new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
+	
+	change = old != new;
+	//printk("test power %d block %s change %d\n", power, widget->name, change);
+	if (change) {
+		snd_soc_write(codec, widget->reg, new);
+		printk("**power block %s %d\n", widget->name, power);
+	}
+	return change;
+}
+
+/*
+ * Create DPM kcontrols
+ */
+#warning NEED to Sync with startup values and create paths and correct PM status
+int snd_soc_dpm_sync(snd_soc_codec_t *codec)
+{
+	snd_soc_dpm_path_t *path;
+	snd_soc_dpm_widget_t *w = NULL;
+	struct list_head *lw, *lp;
+	int i, err;
+	char name[32];
+		
+	list_for_each(lw, &codec->dpm_widgets)
+	{
+		w = list_entry(lw, snd_soc_dpm_widget_t, list);
+		
+		/* add kcontrol */
+		for (i = 0; i < w->num_kcontrols; i++) {
+			
+			/* match name */
+			list_for_each(lp, &w->inputs)
+			{
+				path = list_entry(lp, snd_soc_dpm_path_t, list_out);
+				if (path->name == (char*)w->kcontrols[i].name) {
+					/* add dpm control with long name */
+					snprintf(name, 32, "%s %s", w->name, w->kcontrols[i].name);
+					path->long_name = kstrdup (name, GFP_KERNEL);
+					path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w, path->long_name);
+					if ((err = snd_ctl_add(codec->card, path->kcontrol)) < 0)
+						return err;
+				}	
+			}
+		}
+	}
+	return 0;
+}
+
+/*
+ * Reset 'checked' bit for each path
+ */
+static void snd_soc_dpm_clear_paths(snd_soc_codec_t *codec)
+{
+	snd_soc_dpm_path_t *p = NULL;
+	struct list_head *l = NULL;
+		
+	list_for_each(l, &codec->dpm_paths)
+	{
+		p = list_entry(l, snd_soc_dpm_path_t, list);
+		p->checked = 0;		
+	}
+}
+
+/*
+ * Reset 'checked' bit for each path
+ */
+static void snd_soc_dpm_clear_walk(snd_soc_codec_t *codec)
+{
+	snd_soc_dpm_path_t *p = NULL;
+	struct list_head *l = NULL;
+		
+	list_for_each(l, &codec->dpm_paths)
+	{
+		p = list_entry(l, snd_soc_dpm_path_t, list);
+		p->walked = 0;		
+	}
+}
+
+/*
+ * Check for a completed path to an active or physically connected output widget
+ */
+static int is_connected_output_ep(snd_soc_dpm_widget_t *widget)
+{
+	struct list_head *lp;
+	snd_soc_dpm_path_t *path = NULL;
+	int con = 0;
+
+	if(widget->id == snd_soc_dpm_adc && widget->active)
+		return 1;
+	if(widget->id == snd_soc_dpm_output && widget->connected)
+		return 1;
+	
+	list_for_each(lp, &widget->outputs)
+	{
+		path = list_entry(lp, snd_soc_dpm_path_t, list_in);
+		if(path->walked) {
+			con++;
+			continue;
+		}
+	
+		if (path->out && path->connect) {
+			path->walked = 1;
+			con += is_connected_output_ep(path->out);
+		}
+	}
+	
+	return con;
+}
+
+/*
+ * Check for a completed path to an active or physically connected input widget
+ */
+static int is_connected_input_ep(snd_soc_dpm_widget_t *widget)
+{
+	struct list_head *lp;
+	snd_soc_dpm_path_t *path = NULL;
+	int con = 0;
+	
+	if(widget->id == snd_soc_dpm_dac && widget->active)
+		return 1;
+	if(widget->id == snd_soc_dpm_input && widget->connected)
+		return 1;
+	
+	list_for_each(lp, &widget->inputs)
+	{
+		path = list_entry(lp, snd_soc_dpm_path_t, list_out);
+		if(path->walked) {
+			con++;
+			continue;
+		}
+	
+		if (path->in && path->connect) {
+			path->walked = 1;
+			con += is_connected_input_ep(path->in);
+		}
+	}
+	
+	return con;
+}
+
+
+/*
+ * Check each widgets input and output paths and determine it's new power
+ * state.
+ */
+static int snd_soc_dpm_check_widget(snd_soc_dpm_widget_t *widget, int power)
+{
+	snd_soc_dpm_path_t *path = NULL;
+	struct list_head *lp;
+	int in = 0, out = 0;
+	
+//printk("w name %s id %d pwr %d reg %d\n", widget->name, widget->id, power, widget->reg); 	
+
+	switch(widget->id) {
+		case snd_soc_dpm_dac: /* end point */
+			
+			widget->active = 1; // liam - set by stream ops
+		
+			out = is_connected_output_ep(widget);
+			snd_soc_dpm_clear_walk(widget->codec);
+		//	printk("dac widget %s in %d out %d pwr %d\n", widget->name, in, out, power);
+			if(!out)
+				power = widget->active = 0;
+			else
+				power = widget->active;
+		
+			list_for_each(lp, &widget->outputs)
+			{
+				path = list_entry(lp, snd_soc_dpm_path_t, list_in);
+				if(path->checked)
+					continue;
+		
+				if (path->out && path->connect) {
+					path->checked = 1;
+					snd_soc_dpm_check_widget(path->out, power);
+				}
+			}
+			
+			break;
+		case snd_soc_dpm_input: /* end point */
+			
+			widget->connected = 1; // liam - set by .asoundrc extension
+		
+			out = is_connected_output_ep(widget);
+			snd_soc_dpm_clear_walk(widget->codec);
+		//	printk("in widget %s in %d out %d pwr %d\n", widget->name, in, out, power);
+			if(!out)
+				power = 0;
+			
+			list_for_each(lp, &widget->outputs)
+			{
+				path = list_entry(lp, snd_soc_dpm_path_t, list_in);
+				if(path->checked)
+					continue; 	
+				
+				if (path->out && path->connect) {
+					path->checked = 1;
+					snd_soc_dpm_check_widget(path->out, power);
+				}
+			}
+			
+			break;
+		case snd_soc_dpm_adc: /* end point */
+			
+			widget->active = 1; //liam - set by stream ops
+		
+			in = is_connected_input_ep(widget);
+			snd_soc_dpm_clear_walk(widget->codec);
+		//	printk("adc widget %s in %d out %d pwr %d\n", widget->name, in, out, power);
+			if(!in)
+				power = widget->active = 0;
+			else
+				power = widget->active;
+			
+			list_for_each(lp, &widget->inputs)
+			{
+				path = list_entry(lp, snd_soc_dpm_path_t, list_out);
+				
+				if(path->checked)
+					continue;
+			
+				if (path->in && path->connect) {
+					path->checked = 1;
+					snd_soc_dpm_check_widget(path->in, power);
+				}
+			}
+			
+			break;
+		case snd_soc_dpm_output: /* end point */
+			
+			widget->connected = 1; // liam - set by .asoundrc extension
+		
+			in = is_connected_input_ep(widget);
+			snd_soc_dpm_clear_walk(widget->codec);
+		//	printk("out widget %s in %d out %d pwr %d\n", widget->name, in, out, power);
+			if(!in)
+				power = 0;
+			
+			list_for_each(lp, &widget->inputs)
+			{
+				path = list_entry(lp, snd_soc_dpm_path_t, list_out);
+				
+				if(path->checked)
+					continue;
+			
+				if (path->in && path->connect) {
+					path->checked = 1;
+					snd_soc_dpm_check_widget(path->in, power);
+				}
+			}
+			break;
+		case snd_soc_dpm_volume:
+		case snd_soc_dpm_mixer:
+		case snd_soc_dpm_codec:
+		case snd_soc_dpm_mux:
+			in = is_connected_input_ep(widget);
+			out = is_connected_output_ep(widget);
+			snd_soc_dpm_clear_walk(widget->codec);
+			if(!in || !out)
+				power = 0;
+			else
+				power = 1;
+//printk("widget %s in %d out %d pwr %d\n", widget->name, in, out, power);		
+			list_for_each(lp, &widget->inputs)
+			{
+				path = list_entry(lp, snd_soc_dpm_path_t, list_out);
+			//	printk("  in* %s\n", path->in->name);
+				if(path->checked)
+					continue;
+		
+				if (path->in && path->connect) {
+					path->checked = 1;
+			//		printk("  in %s\n", path->in->name);
+					snd_soc_dpm_check_widget(path->in, power);
+				}
+			}
+			list_for_each(lp, &widget->outputs)
+			{
+				path = list_entry(lp, snd_soc_dpm_path_t, list_in);
+	//			printk("  out* %s path to %s\n", path->name, path->out->name);
+				if(path->checked)
+					continue;
+				
+				if (path->out) {
+					path->checked = 1;
+		//			printk("  out %s path to %s\n", path->name, path->out->name);
+					snd_soc_dpm_check_widget(path->out, power);
+				}
+			}
+			break;
+	}
+	//printk("in %d out %d\n", in, out);
+	snd_soc_dpm_update_bits(widget, power);
+	return power;
+}
+
+#if 0
+static snd_soc_dpm_widget_t * snd_soc_dpm_find_stream(snd_soc_codec_t *codec, 
+	char* name)
+{
+	snd_soc_dpm_widget_t *w = NULL;
+	struct list_head *l = NULL;
+		
+	list_for_each(l, &codec->dpm_widgets)
+	{
+		w = list_entry(l, snd_soc_dpm_widget_t, list);
+		if (!strcmp(name, w->name))
+			return w;			
+	}
+	
+	return NULL;
+}
+#endif
+
+static int dpm_mux_update_power(snd_soc_dpm_widget_t *widget, 
+	snd_kcontrol_t *kcontrol, int mask, int val, struct soc_enum* e)
+{
+	int i = 0;
+
+	if(widget->id != snd_soc_dpm_mux)
+		return -ENODEV; 
+		
+	if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
+		return 0;
+		
+	/* we now need to match the string in the enum to the path */
+//	for (i = 0; i < e->mask; i++) {
+//		if (!(strcmp(p->name, e->texts[i]))) {
+			
+//			dpm_set_path_status(dest, path, 0);
+//			printk("path name %s\n", path->name);
+//			return 0;
+//		}
+//	}
+						
+	snd_soc_dpm_clear_paths(widget->codec);
+	return 0;
+}
+
+static int dpm_mixer_update_power(snd_soc_dpm_widget_t *widget, 
+	snd_kcontrol_t *kcontrol, int reg, int val_mask, int val)
+{
+	struct list_head *l;
+	snd_soc_dpm_path_t *path;
+
+	if(widget->id != snd_soc_dpm_mixer)
+		return -ENODEV; 
+	
+	if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
+		return 0;
+	
+	/* find dpm widget path assoc with kcontrol */
+	list_for_each(l, &widget->codec->dpm_paths)
+	{
+		path = list_entry(l, snd_soc_dpm_path_t, list);
+		if (path->kcontrol != kcontrol)
+			continue;
+			
+		/* found, now check type */
+		if (val) { // liam - need to check invert bit
+			/* new connection */
+			printk("\n\n\nnew connection\n");
+			path->connect = 1;
+			snd_soc_dpm_check_widget(widget, 1);
+		} else {
+			/* old connection must be powered down */
+			printk("\n\n\nbreak connection\n");
+			path->connect = 0;
+			snd_soc_dpm_check_widget(path->in, 0);
+			printk("\n\n\nbreak connection2\n");
+			snd_soc_dpm_check_widget(widget, 0);
+		}
+		break;
+	}
+	
+	snd_soc_dpm_clear_paths(widget->codec);
+	return 0;
+}
+
+int snd_soc_dpm_get_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	snd_soc_dpm_widget_t *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;
+
+	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;
+}
+
+int snd_soc_dpm_put_volsw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	snd_soc_dpm_widget_t *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;
+	}
+	
+	dpm_mixer_update_power(widget, kcontrol, reg, val_mask, val);
+	return snd_soc_update_bits(widget->codec, reg, val_mask, val);
+}
+
+int snd_soc_get_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	snd_soc_codec_t *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;
+}
+
+int snd_soc_dpm_put_enum_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	snd_soc_dpm_widget_t *widget = 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;
+	}
+	
+	dpm_mux_update_power(widget, kcontrol, mask, val, e);
+	return snd_soc_update_bits(widget->codec, e->reg, mask, val);
+}
+
+EXPORT_SYMBOL_GPL(snd_soc_dpm_put_volsw);
+EXPORT_SYMBOL_GPL(snd_soc_dpm_get_volsw);
+EXPORT_SYMBOL_GPL(snd_soc_dpm_connect_input);
+EXPORT_SYMBOL_GPL(snd_soc_dpm_new_control);
+EXPORT_SYMBOL_GPL(snd_soc_dpm_sync);
+EXPORT_SYMBOL_GPL(snd_soc_dpm_put_enum_double);
+EXPORT_SYMBOL_GPL(snd_soc_dpm_get_enum_double);
+
+/* Module information */ 
+MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
+MODULE_DESCRIPTION("ALSA SoC DPM");
+MODULE_LICENSE("GPL");

