Merge branch 'topic/asoc' into for-linus
[safe/jmp/linux-2.6] / sound / soc / codecs / wm8753.c
index 8c4df44..b59f349 100644 (file)
@@ -2,8 +2,7 @@
  * wm8753.c  --  WM8753 ALSA Soc Audio driver
  *
  * Copyright 2003 Wolfson Microelectronics PLC.
- * Author: Liam Girdwood
- *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ * Author: Liam Girdwood <lrg@slimlogic.co.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
@@ -40,6 +39,8 @@
 #include <linux/pm.h>
 #include <linux/i2c.h>
 #include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/slab.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -51,9 +52,6 @@
 
 #include "wm8753.h"
 
-#define AUDIO_NAME "wm8753"
-#define WM8753_VERSION "0.16"
-
 static int caps_charge = 2000;
 module_param(caps_charge, int, 0);
 MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)");
@@ -61,12 +59,6 @@ MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)");
 static void wm8753_set_dai_mode(struct snd_soc_codec *codec,
        unsigned int mode);
 
-/* codec private data */
-struct wm8753_priv {
-       unsigned int sysclk;
-       unsigned int pcmclk;
-};
-
 /*
  * wm8753 register cache
  * We can't read the WM8753 register space when we
@@ -88,7 +80,15 @@ static const u16 wm8753_reg[] = {
        0x0097, 0x0097, 0x0000, 0x0004,
        0x0000, 0x0083, 0x0024, 0x01ba,
        0x0000, 0x0083, 0x0024, 0x01ba,
-       0x0000, 0x0000
+       0x0000, 0x0000, 0x0000
+};
+
+/* codec private data */
+struct wm8753_priv {
+       unsigned int sysclk;
+       unsigned int pcmclk;
+       struct snd_soc_codec codec;
+       u16 reg_cache[ARRAY_SIZE(wm8753_reg)];
 };
 
 /*
@@ -98,7 +98,7 @@ static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec *codec,
        unsigned int reg)
 {
        u16 *cache = codec->reg_cache;
-       if (reg < 1 || reg > (ARRAY_SIZE(wm8753_reg) + 1))
+       if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
                return -1;
        return cache[reg - 1];
 }
@@ -110,7 +110,7 @@ static inline void wm8753_write_reg_cache(struct snd_soc_codec *codec,
        unsigned int reg, unsigned int value)
 {
        u16 *cache = codec->reg_cache;
-       if (reg < 1 || reg > 0x3f)
+       if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
                return;
        cache[reg - 1] = value;
 }
@@ -340,21 +340,6 @@ SOC_ENUM("ADC Data Select", wm8753_enum[27]),
 SOC_ENUM("ROUT2 Phase", wm8753_enum[28]),
 };
 
-/* add non dapm controls */
-static int wm8753_add_controls(struct snd_soc_codec *codec)
-{
-       int err, i;
-
-       for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) {
-               err = snd_ctl_add(codec->card,
-                               snd_soc_cnew(&wm8753_snd_controls[i],
-                                               codec, NULL));
-               if (err < 0)
-                       return err;
-       }
-       return 0;
-}
-
 /*
  * _DAPM_ Controls
  */
@@ -611,6 +596,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
 
        /* Mono Capture mixer-mux */
        {"Capture Right Mixer", "Stereo", "Capture Right Mux"},
+       {"Capture Left Mixer", "Stereo", "Capture Left Mux"},
        {"Capture Left Mixer", "Analogue Mix Left", "Capture Left Mux"},
        {"Capture Left Mixer", "Analogue Mix Left", "Capture Right Mux"},
        {"Capture Right Mixer", "Analogue Mix Right", "Capture Left Mux"},
@@ -688,7 +674,6 @@ static int wm8753_add_widgets(struct snd_soc_codec *codec)
 
        snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_new_widgets(codec);
        return 0;
 }
 
@@ -719,7 +704,7 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int target,
 
        if ((Ndiv < 6) || (Ndiv > 12))
                printk(KERN_WARNING
-                       "wm8753: unsupported N = %d\n", Ndiv);
+                       "wm8753: unsupported N = %u\n", Ndiv);
 
        pll_div->n = Ndiv;
        Nmod = target % source;
@@ -739,8 +724,8 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int target,
        pll_div->k = K;
 }
 
-static int wm8753_set_dai_pll(struct snd_soc_dai *codec_dai,
-               int pll_id, unsigned int freq_in, unsigned int freq_out)
+static int wm8753_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
+               int source, unsigned int freq_in, unsigned int freq_out)
 {
        u16 reg, enable;
        int offset;
@@ -866,7 +851,7 @@ static int wm8753_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8753_priv *wm8753 = codec->private_data;
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 11289600:
@@ -923,12 +908,13 @@ static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai *codec_dai,
  * Set PCM DAI bit size and sample rate.
  */
 static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream,
-       struct snd_pcm_hw_params *params)
+                               struct snd_pcm_hw_params *params,
+                               struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
-       struct snd_soc_codec *codec = socdev->codec;
-       struct wm8753_priv *wm8753 = codec->private_data;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
        u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3;
        u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f;
 
@@ -1156,12 +1142,13 @@ static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
  * Set PCM DAI bit size and sample rate.
  */
 static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream,
-       struct snd_pcm_hw_params *params)
+                               struct snd_pcm_hw_params *params,
+                               struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
-       struct snd_soc_codec *codec = socdev->codec;
-       struct wm8753_priv *wm8753 = codec->private_data;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
        u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0;
        u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3;
        int coeff;
@@ -1315,6 +1302,51 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec,
  * 3. Voice disabled - HIFI over HIFI
  * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture
  */
+static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = {
+       .hw_params      = wm8753_i2s_hw_params,
+       .digital_mute   = wm8753_mute,
+       .set_fmt        = wm8753_mode1h_set_dai_fmt,
+       .set_clkdiv     = wm8753_set_dai_clkdiv,
+       .set_pll        = wm8753_set_dai_pll,
+       .set_sysclk     = wm8753_set_dai_sysclk,
+};
+
+static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = {
+       .hw_params      = wm8753_pcm_hw_params,
+       .digital_mute   = wm8753_mute,
+       .set_fmt        = wm8753_mode1v_set_dai_fmt,
+       .set_clkdiv     = wm8753_set_dai_clkdiv,
+       .set_pll        = wm8753_set_dai_pll,
+       .set_sysclk     = wm8753_set_dai_sysclk,
+};
+
+static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = {
+       .hw_params      = wm8753_pcm_hw_params,
+       .digital_mute   = wm8753_mute,
+       .set_fmt        = wm8753_mode2_set_dai_fmt,
+       .set_clkdiv     = wm8753_set_dai_clkdiv,
+       .set_pll        = wm8753_set_dai_pll,
+       .set_sysclk     = wm8753_set_dai_sysclk,
+};
+
+static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3        = {
+       .hw_params      = wm8753_i2s_hw_params,
+       .digital_mute   = wm8753_mute,
+       .set_fmt        = wm8753_mode3_4_set_dai_fmt,
+       .set_clkdiv     = wm8753_set_dai_clkdiv,
+       .set_pll        = wm8753_set_dai_pll,
+       .set_sysclk     = wm8753_set_dai_sysclk,
+};
+
+static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4        = {
+       .hw_params      = wm8753_i2s_hw_params,
+       .digital_mute   = wm8753_mute,
+       .set_fmt        = wm8753_mode3_4_set_dai_fmt,
+       .set_clkdiv     = wm8753_set_dai_clkdiv,
+       .set_pll        = wm8753_set_dai_pll,
+       .set_sysclk     = wm8753_set_dai_sysclk,
+};
+
 static const struct snd_soc_dai wm8753_all_dai[] = {
 /* DAI HiFi mode 1 */
 {      .name = "WM8753 HiFi",
@@ -1324,22 +1356,14 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
                .channels_min = 1,
                .channels_max = 2,
                .rates = WM8753_RATES,
-               .formats = WM8753_FORMATS,},
+               .formats = WM8753_FORMATS},
        .capture = { /* dummy for fast DAI switching */
                .stream_name = "Capture",
                .channels_min = 1,
                .channels_max = 2,
                .rates = WM8753_RATES,
-               .formats = WM8753_FORMATS,},
-       .ops = {
-               .hw_params = wm8753_i2s_hw_params,},
-       .dai_ops = {
-               .digital_mute = wm8753_mute,
-               .set_fmt = wm8753_mode1h_set_dai_fmt,
-               .set_clkdiv = wm8753_set_dai_clkdiv,
-               .set_pll = wm8753_set_dai_pll,
-               .set_sysclk = wm8753_set_dai_sysclk,
-       },
+               .formats = WM8753_FORMATS},
+       .ops = &wm8753_dai_ops_hifi_mode1,
 },
 /* DAI Voice mode 1 */
 {      .name = "WM8753 Voice",
@@ -1356,15 +1380,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
                .channels_max = 2,
                .rates = WM8753_RATES,
                .formats = WM8753_FORMATS,},
-       .ops = {
-               .hw_params = wm8753_pcm_hw_params,},
-       .dai_ops = {
-               .digital_mute = wm8753_mute,
-               .set_fmt = wm8753_mode1v_set_dai_fmt,
-               .set_clkdiv = wm8753_set_dai_clkdiv,
-               .set_pll = wm8753_set_dai_pll,
-               .set_sysclk = wm8753_set_dai_sysclk,
-       },
+       .ops = &wm8753_dai_ops_voice_mode1,
 },
 /* DAI HiFi mode 2 - dummy */
 {      .name = "WM8753 HiFi",
@@ -1385,15 +1401,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
                .channels_max = 2,
                .rates = WM8753_RATES,
                .formats = WM8753_FORMATS,},
-       .ops = {
-               .hw_params = wm8753_pcm_hw_params,},
-       .dai_ops = {
-               .digital_mute = wm8753_mute,
-               .set_fmt = wm8753_mode2_set_dai_fmt,
-               .set_clkdiv = wm8753_set_dai_clkdiv,
-               .set_pll = wm8753_set_dai_pll,
-               .set_sysclk = wm8753_set_dai_sysclk,
-       },
+       .ops = &wm8753_dai_ops_voice_mode2,
 },
 /* DAI HiFi mode 3 */
 {      .name = "WM8753 HiFi",
@@ -1410,15 +1418,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
                .channels_max = 2,
                .rates = WM8753_RATES,
                .formats = WM8753_FORMATS,},
-       .ops = {
-               .hw_params = wm8753_i2s_hw_params,},
-       .dai_ops = {
-               .digital_mute = wm8753_mute,
-               .set_fmt = wm8753_mode3_4_set_dai_fmt,
-               .set_clkdiv = wm8753_set_dai_clkdiv,
-               .set_pll = wm8753_set_dai_pll,
-               .set_sysclk = wm8753_set_dai_sysclk,
-       },
+       .ops = &wm8753_dai_ops_hifi_mode3,
 },
 /* DAI Voice mode 3 - dummy */
 {      .name = "WM8753 Voice",
@@ -1439,15 +1439,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
                .channels_max = 2,
                .rates = WM8753_RATES,
                .formats = WM8753_FORMATS,},
-       .ops = {
-               .hw_params = wm8753_i2s_hw_params,},
-       .dai_ops = {
-               .digital_mute = wm8753_mute,
-               .set_fmt = wm8753_mode3_4_set_dai_fmt,
-               .set_clkdiv = wm8753_set_dai_clkdiv,
-               .set_pll = wm8753_set_dai_pll,
-               .set_sysclk = wm8753_set_dai_sysclk,
-       },
+       .ops = &wm8753_dai_ops_hifi_mode4,
 },
 /* DAI Voice mode 4 - dummy */
 {      .name = "WM8753 Voice",
@@ -1455,7 +1447,14 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
 },
 };
 
-struct snd_soc_dai wm8753_dai[2];
+struct snd_soc_dai wm8753_dai[] = {
+       {
+               .name = "WM8753 DAI 0",
+       },
+       {
+               .name = "WM8753 DAI 1",
+       },
+};
 EXPORT_SYMBOL_GPL(wm8753_dai);
 
 static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode)
@@ -1463,30 +1462,35 @@ static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode)
        if (mode < 4) {
                int playback_active, capture_active, codec_active, pop_wait;
                void *private_data;
+               struct list_head list;
 
                playback_active = wm8753_dai[0].playback.active;
                capture_active = wm8753_dai[0].capture.active;
                codec_active = wm8753_dai[0].active;
                private_data = wm8753_dai[0].private_data;
                pop_wait = wm8753_dai[0].pop_wait;
+               list = wm8753_dai[0].list;
                wm8753_dai[0] = wm8753_all_dai[mode << 1];
                wm8753_dai[0].playback.active = playback_active;
                wm8753_dai[0].capture.active = capture_active;
                wm8753_dai[0].active = codec_active;
                wm8753_dai[0].private_data = private_data;
                wm8753_dai[0].pop_wait = pop_wait;
+               wm8753_dai[0].list = list;
 
                playback_active = wm8753_dai[1].playback.active;
                capture_active = wm8753_dai[1].capture.active;
                codec_active = wm8753_dai[1].active;
                private_data = wm8753_dai[1].private_data;
                pop_wait = wm8753_dai[1].pop_wait;
+               list = wm8753_dai[1].list;
                wm8753_dai[1] = wm8753_all_dai[(mode << 1) + 1];
                wm8753_dai[1].playback.active = playback_active;
                wm8753_dai[1].capture.active = capture_active;
                wm8753_dai[1].active = codec_active;
                wm8753_dai[1].private_data = private_data;
                wm8753_dai[1].pop_wait = pop_wait;
+               wm8753_dai[1].list = list;
        }
        wm8753_dai[0].codec = codec;
        wm8753_dai[1].codec = codec;
@@ -1502,11 +1506,7 @@ static void wm8753_work(struct work_struct *work)
 static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->codec;
-
-       /* we only need to suspend if we are a valid card */
-       if (!codec->card)
-               return 0;
+       struct snd_soc_codec *codec = socdev->card->codec;
 
        wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
@@ -1515,19 +1515,20 @@ static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
 static int wm8753_resume(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->codec;
+       struct snd_soc_codec *codec = socdev->card->codec;
        int i;
        u8 data[2];
        u16 *cache = codec->reg_cache;
 
-       /* we only need to resume if we are a valid card */
-       if (!codec->card)
-               return 0;
-
        /* Sync reg_cache with the hardware */
        for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) {
                if (i + 1 == WM8753_RESET)
                        continue;
+
+               /* No point in writing hardware default values back */
+               if (cache[i] == wm8753_reg[i])
+                       continue;
+
                data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001);
                data[1] = cache[i] & 0x00ff;
                codec->hw_write(codec->control_data, data, 2);
@@ -1546,44 +1547,120 @@ static int wm8753_resume(struct platform_device *pdev)
        return 0;
 }
 
+static struct snd_soc_codec *wm8753_codec;
+
+static int wm8753_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec;
+       int ret = 0;
+
+       if (!wm8753_codec) {
+               dev_err(&pdev->dev, "WM8753 codec not yet registered\n");
+               return -EINVAL;
+       }
+
+       socdev->card->codec = wm8753_codec;
+       codec = wm8753_codec;
+
+       wm8753_set_dai_mode(codec, 0);
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               printk(KERN_ERR "wm8753: failed to create pcms\n");
+               goto pcm_err;
+       }
+
+       snd_soc_add_controls(codec, wm8753_snd_controls,
+                            ARRAY_SIZE(wm8753_snd_controls));
+       wm8753_add_widgets(codec);
+
+       return 0;
+
+pcm_err:
+       return ret;
+}
+
 /*
- * initialise the WM8753 driver
- * register the mixer and dsp interfaces with the kernel
+ * This function forces any delayed work to be queued and run.
  */
-static int wm8753_init(struct snd_soc_device *socdev)
+static int run_delayed_work(struct delayed_work *dwork)
 {
-       struct snd_soc_codec *codec = socdev->codec;
-       int reg, ret = 0;
+       int ret;
+
+       /* cancel any work waiting to be queued. */
+       ret = cancel_delayed_work(dwork);
+
+       /* if there was any work waiting then we run it now and
+        * wait for it's completion */
+       if (ret) {
+               schedule_delayed_work(dwork, 0);
+               flush_scheduled_work();
+       }
+       return ret;
+}
+
+/* power down chip */
+static int wm8753_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_wm8753 = {
+       .probe =        wm8753_probe,
+       .remove =       wm8753_remove,
+       .suspend =      wm8753_suspend,
+       .resume =       wm8753_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753);
+
+static int wm8753_register(struct wm8753_priv *wm8753)
+{
+       int ret, i;
+       struct snd_soc_codec *codec = &wm8753->codec;
+       u16 reg;
+
+       if (wm8753_codec) {
+               dev_err(codec->dev, "Multiple WM8753 devices not supported\n");
+               ret = -EINVAL;
+               goto err;
+       }
+
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
 
        codec->name = "WM8753";
        codec->owner = THIS_MODULE;
        codec->read = wm8753_read_reg_cache;
        codec->write = wm8753_write;
+       codec->bias_level = SND_SOC_BIAS_STANDBY;
        codec->set_bias_level = wm8753_set_bias_level;
        codec->dai = wm8753_dai;
        codec->num_dai = 2;
-       codec->reg_cache_size = ARRAY_SIZE(wm8753_reg);
-       codec->reg_cache = kmemdup(wm8753_reg, sizeof(wm8753_reg), GFP_KERNEL);
-
-       if (codec->reg_cache == NULL)
-               return -ENOMEM;
-
-       wm8753_set_dai_mode(codec, 0);
+       codec->reg_cache_size = ARRAY_SIZE(wm8753->reg_cache) + 1;
+       codec->reg_cache = &wm8753->reg_cache;
+       snd_soc_codec_set_drvdata(codec, wm8753);
 
-       wm8753_reset(codec);
+       memcpy(codec->reg_cache, wm8753_reg, sizeof(wm8753->reg_cache));
+       INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
 
-       /* register pcms */
-       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       ret = wm8753_reset(codec);
        if (ret < 0) {
-               printk(KERN_ERR "wm8753: failed to create pcms\n");
-               goto pcm_err;
+               dev_err(codec->dev, "Failed to issue reset\n");
+               goto err;
        }
 
        /* charge output caps */
        wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
-       codec->bias_level = SND_SOC_BIAS_STANDBY;
        schedule_delayed_work(&codec->delayed_work,
-               msecs_to_jiffies(caps_charge));
+                             msecs_to_jiffies(caps_charge));
 
        /* set the update bits */
        reg = wm8753_read_reg_cache(codec, WM8753_LDAC);
@@ -1607,59 +1684,70 @@ static int wm8753_init(struct snd_soc_device *socdev)
        reg = wm8753_read_reg_cache(codec, WM8753_RINVOL);
        wm8753_write(codec, WM8753_RINVOL, reg | 0x0100);
 
-       wm8753_add_controls(codec);
-       wm8753_add_widgets(codec);
-       ret = snd_soc_register_card(socdev);
-       if (ret < 0) {
-               printk(KERN_ERR "wm8753: failed to register card\n");
-               goto card_err;
+       wm8753_codec = codec;
+
+       for (i = 0; i < ARRAY_SIZE(wm8753_dai); i++)
+               wm8753_dai[i].dev = codec->dev;
+
+       ret = snd_soc_register_codec(codec);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to register codec: %d\n", ret);
+               goto err;
        }
 
-       return ret;
+       ret = snd_soc_register_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai));
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to register DAIs: %d\n", ret);
+               goto err_codec;
+       }
 
-card_err:
-       snd_soc_free_pcms(socdev);
-       snd_soc_dapm_free(socdev);
-pcm_err:
-       kfree(codec->reg_cache);
+       return 0;
+
+err_codec:
+       run_delayed_work(&codec->delayed_work);
+       snd_soc_unregister_codec(codec);
+err:
+       kfree(wm8753);
        return ret;
 }
 
-/* If the i2c layer weren't so broken, we could pass this kind of data
-   around */
-static struct snd_soc_device *wm8753_socdev;
+static void wm8753_unregister(struct wm8753_priv *wm8753)
+{
+       wm8753_set_bias_level(&wm8753->codec, SND_SOC_BIAS_OFF);
+       run_delayed_work(&wm8753->codec.delayed_work);
+       snd_soc_unregister_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai));
+       snd_soc_unregister_codec(&wm8753->codec);
+       kfree(wm8753);
+       wm8753_codec = NULL;
+}
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
 
-/*
- * WM8753 2 wire address is determined by GPIO5
- * state during powerup.
- *    low  = 0x1a
- *    high = 0x1b
- */
-
 static int wm8753_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
 {
-       struct snd_soc_device *socdev = wm8753_socdev;
-       struct snd_soc_codec *codec = socdev->codec;
-       int ret;
+       struct snd_soc_codec *codec;
+       struct wm8753_priv *wm8753;
+
+       wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL);
+       if (wm8753 == NULL)
+               return -ENOMEM;
 
-       i2c_set_clientdata(i2c, codec);
-       codec->control_data = i2c;
+        codec = &wm8753->codec;
+        codec->hw_write = (hw_write_t)i2c_master_send;
+        codec->control_data = i2c;
+        i2c_set_clientdata(i2c, wm8753);
 
-       ret = wm8753_init(socdev);
-       if (ret < 0)
-               pr_err("failed to initialise WM8753\n");
+        codec->dev = &i2c->dev;
 
-       return ret;
+       return wm8753_register(wm8753);
 }
 
 static int wm8753_i2c_remove(struct i2c_client *client)
 {
-       struct snd_soc_codec *codec = i2c_get_clientdata(client);
-       kfree(codec->reg_cache);
-       return 0;
+        struct wm8753_priv *wm8753 = i2c_get_clientdata(client);
+        wm8753_unregister(wm8753);
+        return 0;
 }
 
 static const struct i2c_device_id wm8753_i2c_id[] = {
@@ -1670,147 +1758,104 @@ MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id);
 
 static struct i2c_driver wm8753_i2c_driver = {
        .driver = {
-               .name = "WM8753 I2C Codec",
+               .name = "wm8753",
                .owner = THIS_MODULE,
        },
        .probe =    wm8753_i2c_probe,
        .remove =   wm8753_i2c_remove,
        .id_table = wm8753_i2c_id,
 };
+#endif
 
-static int wm8753_add_i2c_device(struct platform_device *pdev,
-                                const struct wm8753_setup_data *setup)
+#if defined(CONFIG_SPI_MASTER)
+static int wm8753_spi_write(struct spi_device *spi, const char *data, int len)
 {
-       struct i2c_board_info info;
-       struct i2c_adapter *adapter;
-       struct i2c_client *client;
-       int ret;
+       struct spi_transfer t;
+       struct spi_message m;
+       u8 msg[2];
 
-       ret = i2c_add_driver(&wm8753_i2c_driver);
-       if (ret != 0) {
-               dev_err(&pdev->dev, "can't add i2c driver\n");
-               return ret;
-       }
+       if (len <= 0)
+               return 0;
 
-       memset(&info, 0, sizeof(struct i2c_board_info));
-       info.addr = setup->i2c_address;
-       strlcpy(info.type, "wm8753", I2C_NAME_SIZE);
+       msg[0] = data[0];
+       msg[1] = data[1];
 
-       adapter = i2c_get_adapter(setup->i2c_bus);
-       if (!adapter) {
-               dev_err(&pdev->dev, "can't get i2c adapter %d\n",
-                       setup->i2c_bus);
-               goto err_driver;
-       }
+       spi_message_init(&m);
+       memset(&t, 0, (sizeof t));
 
-       client = i2c_new_device(adapter, &info);
-       i2c_put_adapter(adapter);
-       if (!client) {
-               dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
-                       (unsigned int)info.addr);
-               goto err_driver;
-       }
+       t.tx_buf = &msg[0];
+       t.len = len;
 
-       return 0;
+       spi_message_add_tail(&t, &m);
+       spi_sync(spi, &m);
 
-err_driver:
-       i2c_del_driver(&wm8753_i2c_driver);
-       return -ENODEV;
+       return len;
 }
-#endif
 
-static int wm8753_probe(struct platform_device *pdev)
+static int __devinit wm8753_spi_probe(struct spi_device *spi)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct wm8753_setup_data *setup;
        struct snd_soc_codec *codec;
        struct wm8753_priv *wm8753;
-       int ret = 0;
-
-       pr_info("WM8753 Audio Codec %s", WM8753_VERSION);
-
-       setup = socdev->codec_data;
-       codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
-       if (codec == NULL)
-               return -ENOMEM;
 
        wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL);
-       if (wm8753 == NULL) {
-               kfree(codec);
+       if (wm8753 == NULL)
                return -ENOMEM;
-       }
 
-       codec->private_data = wm8753;
-       socdev->codec = codec;
-       mutex_init(&codec->mutex);
-       INIT_LIST_HEAD(&codec->dapm_widgets);
-       INIT_LIST_HEAD(&codec->dapm_paths);
-       wm8753_socdev = socdev;
-       INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
+       codec = &wm8753->codec;
+       codec->control_data = spi;
+       codec->hw_write = (hw_write_t)wm8753_spi_write;
+       codec->dev = &spi->dev;
 
-#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
-       if (setup->i2c_address) {
-               codec->hw_write = (hw_write_t)i2c_master_send;
-               ret = wm8753_add_i2c_device(pdev, setup);
-       }
-#else
-               /* Add other interfaces here */
-#endif
+       dev_set_drvdata(&spi->dev, wm8753);
 
-       if (ret != 0) {
-               kfree(codec->private_data);
-               kfree(codec);
-       }
-       return ret;
+       return wm8753_register(wm8753);
 }
 
-/*
- * This function forces any delayed work to be queued and run.
- */
-static int run_delayed_work(struct delayed_work *dwork)
+static int __devexit wm8753_spi_remove(struct spi_device *spi)
 {
-       int ret;
+       struct wm8753_priv *wm8753 = dev_get_drvdata(&spi->dev);
+       wm8753_unregister(wm8753);
+       return 0;
+}
 
-       /* cancel any work waiting to be queued. */
-       ret = cancel_delayed_work(dwork);
+static struct spi_driver wm8753_spi_driver = {
+       .driver = {
+               .name   = "wm8753",
+               .bus    = &spi_bus_type,
+               .owner  = THIS_MODULE,
+       },
+       .probe          = wm8753_spi_probe,
+       .remove         = __devexit_p(wm8753_spi_remove),
+};
+#endif
 
-       /* if there was any work waiting then we run it now and
-        * wait for it's completion */
-       if (ret) {
-               schedule_delayed_work(dwork, 0);
-               flush_scheduled_work();
-       }
-       return ret;
+static int __init wm8753_modinit(void)
+{
+       int ret;
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       ret = i2c_add_driver(&wm8753_i2c_driver);
+       if (ret != 0)
+               pr_err("Failed to register WM8753 I2C driver: %d\n", ret);
+#endif
+#if defined(CONFIG_SPI_MASTER)
+       ret = spi_register_driver(&wm8753_spi_driver);
+       if (ret != 0)
+               pr_err("Failed to register WM8753 SPI driver: %d\n", ret);
+#endif
+       return 0;
 }
+module_init(wm8753_modinit);
 
-/* power down chip */
-static int wm8753_remove(struct platform_device *pdev)
+static void __exit wm8753_exit(void)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->codec;
-
-       if (codec->control_data)
-               wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF);
-       run_delayed_work(&codec->delayed_work);
-       snd_soc_free_pcms(socdev);
-       snd_soc_dapm_free(socdev);
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
-       i2c_unregister_device(codec->control_data);
        i2c_del_driver(&wm8753_i2c_driver);
 #endif
-       kfree(codec->private_data);
-       kfree(codec);
-
-       return 0;
+#if defined(CONFIG_SPI_MASTER)
+       spi_unregister_driver(&wm8753_spi_driver);
+#endif
 }
-
-struct snd_soc_codec_device soc_codec_dev_wm8753 = {
-       .probe =        wm8753_probe,
-       .remove =       wm8753_remove,
-       .suspend =      wm8753_suspend,
-       .resume =       wm8753_resume,
-};
-EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753);
+module_exit(wm8753_exit);
 
 MODULE_DESCRIPTION("ASoC WM8753 driver");
 MODULE_AUTHOR("Liam Girdwood");