]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - sound/soc/codecs/wm8753.c
ASoC: codecs: wm8753: Fix register cache incoherency
[mv-sheeva.git] / sound / soc / codecs / wm8753.c
index b59f349c52184fc9bf83a975f8e921f2fda92632..87caae59e939c78465750f470d5d4ce35ee505d3 100644 (file)
@@ -57,7 +57,7 @@ module_param(caps_charge, int, 0);
 MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)");
 
 static void wm8753_set_dai_mode(struct snd_soc_codec *codec,
-       unsigned int mode);
+               struct snd_soc_dai *dai, unsigned int hifi);
 
 /*
  * wm8753 register cache
@@ -65,79 +65,33 @@ static void wm8753_set_dai_mode(struct snd_soc_codec *codec,
  * are using 2 wire for device control, so we cache them instead.
  */
 static const u16 wm8753_reg[] = {
-       0x0008, 0x0000, 0x000a, 0x000a,
-       0x0033, 0x0000, 0x0007, 0x00ff,
-       0x00ff, 0x000f, 0x000f, 0x007b,
-       0x0000, 0x0032, 0x0000, 0x00c3,
-       0x00c3, 0x00c0, 0x0000, 0x0000,
+       0x0000, 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, 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, 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, 0x0000
 };
 
 /* codec private data */
 struct wm8753_priv {
+       enum snd_soc_control_type control_type;
        unsigned int sysclk;
        unsigned int pcmclk;
-       struct snd_soc_codec codec;
-       u16 reg_cache[ARRAY_SIZE(wm8753_reg)];
+       int dai_func;
 };
 
-/*
- * read wm8753 register cache
- */
-static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec *codec,
-       unsigned int reg)
-{
-       u16 *cache = codec->reg_cache;
-       if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
-               return -1;
-       return cache[reg - 1];
-}
-
-/*
- * write wm8753 register cache
- */
-static inline void wm8753_write_reg_cache(struct snd_soc_codec *codec,
-       unsigned int reg, unsigned int value)
-{
-       u16 *cache = codec->reg_cache;
-       if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
-               return;
-       cache[reg - 1] = value;
-}
-
-/*
- * write to the WM8753 register space
- */
-static int wm8753_write(struct snd_soc_codec *codec, unsigned int reg,
-       unsigned int value)
-{
-       u8 data[2];
-
-       /* data is
-        *   D15..D9 WM8753 register offset
-        *   D8...D0 register data
-        */
-       data[0] = (reg << 1) | ((value >> 8) & 0x0001);
-       data[1] = value & 0x00ff;
-
-       wm8753_write_reg_cache(codec, reg, value);
-       if (codec->hw_write(codec->control_data, data, 2) == 2)
-               return 0;
-       else
-               return -EIO;
-}
-
-#define wm8753_reset(c) wm8753_write(c, WM8753_RESET, 0)
+#define wm8753_reset(c) snd_soc_write(c, WM8753_RESET, 0)
 
 /*
  * WM8753 Controls
@@ -217,7 +171,7 @@ static int wm8753_get_dai(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec =  snd_kcontrol_chip(kcontrol);
-       int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL);
+       int mode = snd_soc_read(codec, WM8753_IOCTL);
 
        ucontrol->value.integer.value[0] = (mode & 0xc) >> 2;
        return 0;
@@ -227,7 +181,8 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec =  snd_kcontrol_chip(kcontrol);
-       int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL);
+       int mode = snd_soc_read(codec, WM8753_IOCTL);
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
 
        if (((mode & 0xc) >> 2) == ucontrol->value.integer.value[0])
                return 0;
@@ -235,8 +190,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol,
        mode &= 0xfff3;
        mode |= (ucontrol->value.integer.value[0] << 2);
 
-       wm8753_write(codec, WM8753_IOCTL, mode);
-       wm8753_set_dai_mode(codec, ucontrol->value.integer.value[0]);
+       wm8753->dai_func =  ucontrol->value.integer.value[0];
        return 1;
 }
 
@@ -737,17 +691,17 @@ static int wm8753_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
        if (pll_id == WM8753_PLL1) {
                offset = 0;
                enable = 0x10;
-               reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xffef;
+               reg = snd_soc_read(codec, WM8753_CLOCK) & 0xffef;
        } else {
                offset = 4;
                enable = 0x8;
-               reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfff7;
+               reg = snd_soc_read(codec, WM8753_CLOCK) & 0xfff7;
        }
 
        if (!freq_in || !freq_out) {
                /* disable PLL  */
-               wm8753_write(codec, WM8753_PLL1CTL1 + offset, 0x0026);
-               wm8753_write(codec, WM8753_CLOCK, reg);
+               snd_soc_write(codec, WM8753_PLL1CTL1 + offset, 0x0026);
+               snd_soc_write(codec, WM8753_CLOCK, reg);
                return 0;
        } else {
                u16 value = 0;
@@ -758,20 +712,20 @@ static int wm8753_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
                /* set up N and K PLL divisor ratios */
                /* bits 8:5 = PLL_N, bits 3:0 = PLL_K[21:18] */
                value = (pll_div.n << 5) + ((pll_div.k & 0x3c0000) >> 18);
-               wm8753_write(codec, WM8753_PLL1CTL2 + offset, value);
+               snd_soc_write(codec, WM8753_PLL1CTL2 + offset, value);
 
                /* bits 8:0 = PLL_K[17:9] */
                value = (pll_div.k & 0x03fe00) >> 9;
-               wm8753_write(codec, WM8753_PLL1CTL3 + offset, value);
+               snd_soc_write(codec, WM8753_PLL1CTL3 + offset, value);
 
                /* bits 8:0 = PLL_K[8:0] */
                value = pll_div.k & 0x0001ff;
-               wm8753_write(codec, WM8753_PLL1CTL4 + offset, value);
+               snd_soc_write(codec, WM8753_PLL1CTL4 + offset, value);
 
                /* set PLL as input and enable */
-               wm8753_write(codec, WM8753_PLL1CTL1 + offset, 0x0027 |
+               snd_soc_write(codec, WM8753_PLL1CTL1 + offset, 0x0027 |
                        (pll_div.div2 << 3));
-               wm8753_write(codec, WM8753_CLOCK, reg | enable);
+               snd_soc_write(codec, WM8753_CLOCK, reg | enable);
        }
        return 0;
 }
@@ -878,7 +832,7 @@ static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01ec;
+       u16 voice = snd_soc_read(codec, WM8753_PCM) & 0x01ec;
 
        /* interface format */
        switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
@@ -900,7 +854,14 @@ static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai *codec_dai,
                return -EINVAL;
        }
 
-       wm8753_write(codec, WM8753_PCM, voice);
+       snd_soc_write(codec, WM8753_PCM, voice);
+       return 0;
+}
+
+static int wm8753_pcm_startup(struct snd_pcm_substream *substream,
+                               struct snd_soc_dai *dai)
+{
+       wm8753_set_dai_mode(dai->codec, dai, 0);
        return 0;
 }
 
@@ -912,11 +873,10 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream,
                                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->card->codec;
+       struct snd_soc_codec *codec = rtd->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;
+       u16 voice = snd_soc_read(codec, WM8753_PCM) & 0x01f3;
+       u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x017f;
 
        /* bit size */
        switch (params_format(params)) {
@@ -936,9 +896,9 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream,
        /* sample rate */
        if (params_rate(params) * 384 == wm8753->pcmclk)
                srate |= 0x80;
-       wm8753_write(codec, WM8753_SRATE1, srate);
+       snd_soc_write(codec, WM8753_SRATE1, srate);
 
-       wm8753_write(codec, WM8753_PCM, voice);
+       snd_soc_write(codec, WM8753_PCM, voice);
        return 0;
 }
 
@@ -951,8 +911,8 @@ static int wm8753_pcm_set_dai_fmt(struct snd_soc_dai *codec_dai,
        struct snd_soc_codec *codec = codec_dai->codec;
        u16 voice, ioctl;
 
-       voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x011f;
-       ioctl = wm8753_read_reg_cache(codec, WM8753_IOCTL) & 0x015d;
+       voice = snd_soc_read(codec, WM8753_PCM) & 0x011f;
+       ioctl = snd_soc_read(codec, WM8753_IOCTL) & 0x015d;
 
        /* set master/slave audio interface */
        switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -1006,8 +966,8 @@ static int wm8753_pcm_set_dai_fmt(struct snd_soc_dai *codec_dai,
                return -EINVAL;
        }
 
-       wm8753_write(codec, WM8753_PCM, voice);
-       wm8753_write(codec, WM8753_IOCTL, ioctl);
+       snd_soc_write(codec, WM8753_PCM, voice);
+       snd_soc_write(codec, WM8753_IOCTL, ioctl);
        return 0;
 }
 
@@ -1019,16 +979,16 @@ static int wm8753_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
 
        switch (div_id) {
        case WM8753_PCMDIV:
-               reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0x003f;
-               wm8753_write(codec, WM8753_CLOCK, reg | div);
+               reg = snd_soc_read(codec, WM8753_CLOCK) & 0x003f;
+               snd_soc_write(codec, WM8753_CLOCK, reg | div);
                break;
        case WM8753_BCLKDIV:
-               reg = wm8753_read_reg_cache(codec, WM8753_SRATE2) & 0x01c7;
-               wm8753_write(codec, WM8753_SRATE2, reg | div);
+               reg = snd_soc_read(codec, WM8753_SRATE2) & 0x01c7;
+               snd_soc_write(codec, WM8753_SRATE2, reg | div);
                break;
        case WM8753_VXCLKDIV:
-               reg = wm8753_read_reg_cache(codec, WM8753_SRATE2) & 0x003f;
-               wm8753_write(codec, WM8753_SRATE2, reg | div);
+               reg = snd_soc_read(codec, WM8753_SRATE2) & 0x003f;
+               snd_soc_write(codec, WM8753_SRATE2, reg | div);
                break;
        default:
                return -EINVAL;
@@ -1043,7 +1003,7 @@ static int wm8753_hdac_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01e0;
+       u16 hifi = snd_soc_read(codec, WM8753_HIFI) & 0x01e0;
 
        /* interface format */
        switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
@@ -1065,7 +1025,7 @@ static int wm8753_hdac_set_dai_fmt(struct snd_soc_dai *codec_dai,
                return -EINVAL;
        }
 
-       wm8753_write(codec, WM8753_HIFI, hifi);
+       snd_soc_write(codec, WM8753_HIFI, hifi);
        return 0;
 }
 
@@ -1078,8 +1038,8 @@ static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
        struct snd_soc_codec *codec = codec_dai->codec;
        u16 ioctl, hifi;
 
-       hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x011f;
-       ioctl = wm8753_read_reg_cache(codec, WM8753_IOCTL) & 0x00ae;
+       hifi = snd_soc_read(codec, WM8753_HIFI) & 0x011f;
+       ioctl = snd_soc_read(codec, WM8753_IOCTL) & 0x00ae;
 
        /* set master/slave audio interface */
        switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -1133,8 +1093,15 @@ static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
                return -EINVAL;
        }
 
-       wm8753_write(codec, WM8753_HIFI, hifi);
-       wm8753_write(codec, WM8753_IOCTL, ioctl);
+       snd_soc_write(codec, WM8753_HIFI, hifi);
+       snd_soc_write(codec, WM8753_IOCTL, ioctl);
+       return 0;
+}
+
+static int wm8753_i2s_startup(struct snd_pcm_substream *substream,
+                               struct snd_soc_dai *dai)
+{
+       wm8753_set_dai_mode(dai->codec, dai, 1);
        return 0;
 }
 
@@ -1146,11 +1113,10 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream,
                                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->card->codec;
+       struct snd_soc_codec *codec = rtd->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;
+       u16 srate = snd_soc_read(codec, WM8753_SRATE1) & 0x01c0;
+       u16 hifi = snd_soc_read(codec, WM8753_HIFI) & 0x01f3;
        int coeff;
 
        /* is digital filter coefficient valid ? */
@@ -1159,7 +1125,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream,
                printk(KERN_ERR "wm8753 invalid MCLK or rate\n");
                return coeff;
        }
-       wm8753_write(codec, WM8753_SRATE1, srate | (coeff_div[coeff].sr << 1) |
+       snd_soc_write(codec, WM8753_SRATE1, srate | (coeff_div[coeff].sr << 1) |
                coeff_div[coeff].usb);
 
        /* bit size */
@@ -1177,7 +1143,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream,
                break;
        }
 
-       wm8753_write(codec, WM8753_HIFI, hifi);
+       snd_soc_write(codec, WM8753_HIFI, hifi);
        return 0;
 }
 
@@ -1188,8 +1154,8 @@ static int wm8753_mode1v_set_dai_fmt(struct snd_soc_dai *codec_dai,
        u16 clock;
 
        /* set clk source as pcmclk */
-       clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb;
-       wm8753_write(codec, WM8753_CLOCK, clock);
+       clock = snd_soc_read(codec, WM8753_CLOCK) & 0xfffb;
+       snd_soc_write(codec, WM8753_CLOCK, clock);
 
        if (wm8753_vdac_adc_set_dai_fmt(codec_dai, fmt) < 0)
                return -EINVAL;
@@ -1211,8 +1177,8 @@ static int wm8753_mode2_set_dai_fmt(struct snd_soc_dai *codec_dai,
        u16 clock;
 
        /* set clk source as pcmclk */
-       clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb;
-       wm8753_write(codec, WM8753_CLOCK, clock);
+       clock = snd_soc_read(codec, WM8753_CLOCK) & 0xfffb;
+       snd_soc_write(codec, WM8753_CLOCK, clock);
 
        if (wm8753_vdac_adc_set_dai_fmt(codec_dai, fmt) < 0)
                return -EINVAL;
@@ -1226,8 +1192,8 @@ static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_dai *codec_dai,
        u16 clock;
 
        /* set clk source as mclk */
-       clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb;
-       wm8753_write(codec, WM8753_CLOCK, clock | 0x4);
+       clock = snd_soc_read(codec, WM8753_CLOCK) & 0xfffb;
+       snd_soc_write(codec, WM8753_CLOCK, clock | 0x4);
 
        if (wm8753_hdac_set_dai_fmt(codec_dai, fmt) < 0)
                return -EINVAL;
@@ -1239,19 +1205,19 @@ static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_dai *codec_dai,
 static int wm8753_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
-       u16 mute_reg = wm8753_read_reg_cache(codec, WM8753_DAC) & 0xfff7;
+       u16 mute_reg = snd_soc_read(codec, WM8753_DAC) & 0xfff7;
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
 
        /* the digital mute covers the HiFi and Voice DAC's on the WM8753.
         * make sure we check if they are not both active when we mute */
-       if (mute && dai->id == 1) {
-               if (!wm8753_dai[WM8753_DAI_VOICE].playback.active ||
-                       !wm8753_dai[WM8753_DAI_HIFI].playback.active)
-                       wm8753_write(codec, WM8753_DAC, mute_reg | 0x8);
+       if (mute && wm8753->dai_func == 1) {
+               if (!codec->active)
+                       snd_soc_write(codec, WM8753_DAC, mute_reg | 0x8);
        } else {
                if (mute)
-                       wm8753_write(codec, WM8753_DAC, mute_reg | 0x8);
+                       snd_soc_write(codec, WM8753_DAC, mute_reg | 0x8);
                else
-                       wm8753_write(codec, WM8753_DAC, mute_reg);
+                       snd_soc_write(codec, WM8753_DAC, mute_reg);
        }
 
        return 0;
@@ -1260,23 +1226,23 @@ static int wm8753_mute(struct snd_soc_dai *dai, int mute)
 static int wm8753_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
-       u16 pwr_reg = wm8753_read_reg_cache(codec, WM8753_PWR1) & 0xfe3e;
+       u16 pwr_reg = snd_soc_read(codec, WM8753_PWR1) & 0xfe3e;
 
        switch (level) {
        case SND_SOC_BIAS_ON:
                /* set vmid to 50k and unmute dac */
-               wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x00c0);
+               snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x00c0);
                break;
        case SND_SOC_BIAS_PREPARE:
                /* set vmid to 5k for quick power up */
-               wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x01c1);
+               snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x01c1);
                break;
        case SND_SOC_BIAS_STANDBY:
                /* mute dac and set vmid to 500k, enable VREF */
-               wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x0141);
+               snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x0141);
                break;
        case SND_SOC_BIAS_OFF:
-               wm8753_write(codec, WM8753_PWR1, 0x0001);
+               snd_soc_write(codec, WM8753_PWR1, 0x0001);
                break;
        }
        codec->bias_level = level;
@@ -1303,6 +1269,7 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec,
  * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture
  */
 static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = {
+       .startup = wm8753_i2s_startup,
        .hw_params      = wm8753_i2s_hw_params,
        .digital_mute   = wm8753_mute,
        .set_fmt        = wm8753_mode1h_set_dai_fmt,
@@ -1312,6 +1279,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = {
 };
 
 static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = {
+       .startup = wm8753_pcm_startup,
        .hw_params      = wm8753_pcm_hw_params,
        .digital_mute   = wm8753_mute,
        .set_fmt        = wm8753_mode1v_set_dai_fmt,
@@ -1321,6 +1289,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = {
 };
 
 static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = {
+       .startup = wm8753_pcm_startup,
        .hw_params      = wm8753_pcm_hw_params,
        .digital_mute   = wm8753_mute,
        .set_fmt        = wm8753_mode2_set_dai_fmt,
@@ -1330,6 +1299,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = {
 };
 
 static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3        = {
+       .startup = wm8753_i2s_startup,
        .hw_params      = wm8753_i2s_hw_params,
        .digital_mute   = wm8753_mute,
        .set_fmt        = wm8753_mode3_4_set_dai_fmt,
@@ -1339,6 +1309,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3   = {
 };
 
 static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4        = {
+       .startup = wm8753_i2s_startup,
        .hw_params      = wm8753_i2s_hw_params,
        .digital_mute   = wm8753_mute,
        .set_fmt        = wm8753_mode3_4_set_dai_fmt,
@@ -1347,10 +1318,9 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4  = {
        .set_sysclk     = wm8753_set_dai_sysclk,
 };
 
-static const struct snd_soc_dai wm8753_all_dai[] = {
+static struct snd_soc_dai_driver wm8753_all_dai[] = {
 /* DAI HiFi mode 1 */
-{      .name = "WM8753 HiFi",
-       .id = 1,
+{      .name = "wm8753-hifi",
        .playback = {
                .stream_name = "HiFi Playback",
                .channels_min = 1,
@@ -1366,8 +1336,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
        .ops = &wm8753_dai_ops_hifi_mode1,
 },
 /* DAI Voice mode 1 */
-{      .name = "WM8753 Voice",
-       .id = 1,
+{      .name = "wm8753-voice",
        .playback = {
                .stream_name = "Voice Playback",
                .channels_min = 1,
@@ -1383,12 +1352,10 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
        .ops = &wm8753_dai_ops_voice_mode1,
 },
 /* DAI HiFi mode 2 - dummy */
-{      .name = "WM8753 HiFi",
-       .id = 2,
+{      .name = "wm8753-hifi",
 },
 /* DAI Voice mode 2 */
-{      .name = "WM8753 Voice",
-       .id = 2,
+{      .name = "wm8753-voice",
        .playback = {
                .stream_name = "Voice Playback",
                .channels_min = 1,
@@ -1404,8 +1371,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
        .ops = &wm8753_dai_ops_voice_mode2,
 },
 /* DAI HiFi mode 3 */
-{      .name = "WM8753 HiFi",
-       .id = 3,
+{      .name = "wm8753-hifi",
        .playback = {
                .stream_name = "HiFi Playback",
                .channels_min = 1,
@@ -1421,12 +1387,10 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
        .ops = &wm8753_dai_ops_hifi_mode3,
 },
 /* DAI Voice mode 3 - dummy */
-{      .name = "WM8753 Voice",
-       .id = 3,
+{      .name = "wm8753-voice",
 },
 /* DAI HiFi mode 4 */
-{      .name = "WM8753 HiFi",
-       .id = 4,
+{      .name = "wm8753-hifi",
        .playback = {
                .stream_name = "HiFi Playback",
                .channels_min = 1,
@@ -1442,58 +1406,31 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
        .ops = &wm8753_dai_ops_hifi_mode4,
 },
 /* DAI Voice mode 4 - dummy */
-{      .name = "WM8753 Voice",
-       .id = 4,
+{      .name = "wm8753-voice",
 },
 };
 
-struct snd_soc_dai wm8753_dai[] = {
+static struct snd_soc_dai_driver wm8753_dai[] = {
        {
-               .name = "WM8753 DAI 0",
+               .name = "wm8753-aif0",
        },
        {
-               .name = "WM8753 DAI 1",
+               .name = "wm8753-aif1",
        },
 };
-EXPORT_SYMBOL_GPL(wm8753_dai);
 
-static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode)
+static void wm8753_set_dai_mode(struct snd_soc_codec *codec,
+               struct snd_soc_dai *dai, unsigned int hifi)
 {
-       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;
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
+
+       if (wm8753->dai_func < 4) {
+               if (hifi)
+                       dai->driver = &wm8753_all_dai[wm8753->dai_func << 1];
+               else
+                       dai->driver = &wm8753_all_dai[(wm8753->dai_func << 1) + 1];
        }
-       wm8753_dai[0].codec = codec;
-       wm8753_dai[1].codec = codec;
+       snd_soc_write(codec, WM8753_IOCTL, wm8753->dai_func);
 }
 
 static void wm8753_work(struct work_struct *work)
@@ -1503,35 +1440,27 @@ static void wm8753_work(struct work_struct *work)
        wm8753_set_bias_level(codec, codec->bias_level);
 }
 
-static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
+static int wm8753_suspend(struct snd_soc_codec *codec, pm_message_t state)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
-
        wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
 }
 
-static int wm8753_resume(struct platform_device *pdev)
+static int wm8753_resume(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
+       u16 *reg_cache = codec->reg_cache;
        int i;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
 
        /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) {
-               if (i + 1 == WM8753_RESET)
+       for (i = 1; i < ARRAY_SIZE(wm8753_reg); i++) {
+               if (i == WM8753_RESET)
                        continue;
 
                /* No point in writing hardware default values back */
-               if (cache[i] == wm8753_reg[i])
+               if (reg_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);
+               snd_soc_write(codec, i, reg_cache[i]);
        }
 
        wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
@@ -1547,41 +1476,6 @@ 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;
-}
-
 /*
  * This function forces any delayed work to be queued and run.
  */
@@ -1601,248 +1495,172 @@ static int run_delayed_work(struct delayed_work *dwork)
        return ret;
 }
 
-/* power down chip */
-static int wm8753_remove(struct platform_device *pdev)
+static int wm8753_probe(struct snd_soc_codec *codec)
 {
-       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);
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
+       int ret;
 
-static int wm8753_register(struct wm8753_priv *wm8753)
-{
-       int ret, i;
-       struct snd_soc_codec *codec = &wm8753->codec;
-       u16 reg;
+       INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
 
-       if (wm8753_codec) {
-               dev_err(codec->dev, "Multiple WM8753 devices not supported\n");
-               ret = -EINVAL;
-               goto err;
+       ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8753->control_type);
+       if (ret < 0) {
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               return ret;
        }
 
-       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_cache) + 1;
-       codec->reg_cache = &wm8753->reg_cache;
-       snd_soc_codec_set_drvdata(codec, wm8753);
-
-       memcpy(codec->reg_cache, wm8753_reg, sizeof(wm8753->reg_cache));
-       INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
-
        ret = wm8753_reset(codec);
        if (ret < 0) {
-               dev_err(codec->dev, "Failed to issue reset\n");
-               goto err;
+               dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
+               return ret;
        }
 
+       wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       wm8753->dai_func = 0;
+
        /* charge output caps */
        wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
        schedule_delayed_work(&codec->delayed_work,
                              msecs_to_jiffies(caps_charge));
 
        /* set the update bits */
-       reg = wm8753_read_reg_cache(codec, WM8753_LDAC);
-       wm8753_write(codec, WM8753_LDAC, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_RDAC);
-       wm8753_write(codec, WM8753_RDAC, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_LADC);
-       wm8753_write(codec, WM8753_LADC, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_RADC);
-       wm8753_write(codec, WM8753_RADC, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_LOUT1V);
-       wm8753_write(codec, WM8753_LOUT1V, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_ROUT1V);
-       wm8753_write(codec, WM8753_ROUT1V, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_LOUT2V);
-       wm8753_write(codec, WM8753_LOUT2V, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_ROUT2V);
-       wm8753_write(codec, WM8753_ROUT2V, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_LINVOL);
-       wm8753_write(codec, WM8753_LINVOL, reg | 0x0100);
-       reg = wm8753_read_reg_cache(codec, WM8753_RINVOL);
-       wm8753_write(codec, WM8753_RINVOL, reg | 0x0100);
-
-       wm8753_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;
-       }
+       snd_soc_update_bits(codec, WM8753_LDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_RDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_LDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_RDAC, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_LOUT1V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_ROUT1V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_LOUT2V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_ROUT2V, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_LINVOL, 0x0100, 0x0100);
+       snd_soc_update_bits(codec, WM8753_RINVOL, 0x0100, 0x0100);
 
-       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;
-       }
+       snd_soc_add_controls(codec, wm8753_snd_controls,
+                            ARRAY_SIZE(wm8753_snd_controls));
+       wm8753_add_widgets(codec);
 
        return 0;
-
-err_codec:
-       run_delayed_work(&codec->delayed_work);
-       snd_soc_unregister_codec(codec);
-err:
-       kfree(wm8753);
-       return ret;
 }
 
-static void wm8753_unregister(struct wm8753_priv *wm8753)
+/* power down chip */
+static int wm8753_remove(struct snd_soc_codec *codec)
 {
-       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;
+       run_delayed_work(&codec->delayed_work);
+       wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+       return 0;
 }
 
-#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+static struct snd_soc_codec_driver soc_codec_dev_wm8753 = {
+       .probe =        wm8753_probe,
+       .remove =       wm8753_remove,
+       .suspend =      wm8753_suspend,
+       .resume =       wm8753_resume,
+       .set_bias_level = wm8753_set_bias_level,
+       .reg_cache_size = ARRAY_SIZE(wm8753_reg),
+       .reg_word_size = sizeof(u16),
+       .reg_cache_default = wm8753_reg,
+};
 
-static int wm8753_i2c_probe(struct i2c_client *i2c,
-                           const struct i2c_device_id *id)
+#if defined(CONFIG_SPI_MASTER)
+static int __devinit wm8753_spi_probe(struct spi_device *spi)
 {
-       struct snd_soc_codec *codec;
        struct wm8753_priv *wm8753;
+       int ret;
 
        wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL);
        if (wm8753 == NULL)
                return -ENOMEM;
 
-        codec = &wm8753->codec;
-        codec->hw_write = (hw_write_t)i2c_master_send;
-        codec->control_data = i2c;
-        i2c_set_clientdata(i2c, wm8753);
-
-        codec->dev = &i2c->dev;
+       wm8753->control_type = SND_SOC_SPI;
+       spi_set_drvdata(spi, wm8753);
 
-       return wm8753_register(wm8753);
+       ret = snd_soc_register_codec(&spi->dev,
+                       &soc_codec_dev_wm8753, wm8753_dai, ARRAY_SIZE(wm8753_dai));
+       if (ret < 0)
+               kfree(wm8753);
+       return ret;
 }
 
-static int wm8753_i2c_remove(struct i2c_client *client)
+static int __devexit wm8753_spi_remove(struct spi_device *spi)
 {
-        struct wm8753_priv *wm8753 = i2c_get_clientdata(client);
-        wm8753_unregister(wm8753);
-        return 0;
+       snd_soc_unregister_codec(&spi->dev);
+       kfree(spi_get_drvdata(spi));
+       return 0;
 }
 
-static const struct i2c_device_id wm8753_i2c_id[] = {
-       { "wm8753", 0 },
-       { }
-};
-MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id);
-
-static struct i2c_driver wm8753_i2c_driver = {
+static struct spi_driver wm8753_spi_driver = {
        .driver = {
-               .name = "wm8753",
-               .owner = THIS_MODULE,
+               .name   = "wm8753-codec",
+               .owner  = THIS_MODULE,
        },
-       .probe =    wm8753_i2c_probe,
-       .remove =   wm8753_i2c_remove,
-       .id_table = wm8753_i2c_id,
+       .probe          = wm8753_spi_probe,
+       .remove         = __devexit_p(wm8753_spi_remove),
 };
-#endif
+#endif /* CONFIG_SPI_MASTER */
 
-#if defined(CONFIG_SPI_MASTER)
-static int wm8753_spi_write(struct spi_device *spi, const char *data, int len)
-{
-       struct spi_transfer t;
-       struct spi_message m;
-       u8 msg[2];
-
-       if (len <= 0)
-               return 0;
-
-       msg[0] = data[0];
-       msg[1] = data[1];
-
-       spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
-
-       t.tx_buf = &msg[0];
-       t.len = len;
-
-       spi_message_add_tail(&t, &m);
-       spi_sync(spi, &m);
-
-       return len;
-}
-
-static int __devinit wm8753_spi_probe(struct spi_device *spi)
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+static __devinit int wm8753_i2c_probe(struct i2c_client *i2c,
+                                     const struct i2c_device_id *id)
 {
-       struct snd_soc_codec *codec;
        struct wm8753_priv *wm8753;
+       int ret;
 
        wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL);
        if (wm8753 == NULL)
                return -ENOMEM;
 
-       codec = &wm8753->codec;
-       codec->control_data = spi;
-       codec->hw_write = (hw_write_t)wm8753_spi_write;
-       codec->dev = &spi->dev;
+       i2c_set_clientdata(i2c, wm8753);
+       wm8753->control_type = SND_SOC_I2C;
 
-       dev_set_drvdata(&spi->dev, wm8753);
-
-       return wm8753_register(wm8753);
+       ret =  snd_soc_register_codec(&i2c->dev,
+                       &soc_codec_dev_wm8753, wm8753_dai, ARRAY_SIZE(wm8753_dai));
+       if (ret < 0)
+               kfree(wm8753);
+       return ret;
 }
 
-static int __devexit wm8753_spi_remove(struct spi_device *spi)
+static __devexit int wm8753_i2c_remove(struct i2c_client *client)
 {
-       struct wm8753_priv *wm8753 = dev_get_drvdata(&spi->dev);
-       wm8753_unregister(wm8753);
+       snd_soc_unregister_codec(&client->dev);
+       kfree(i2c_get_clientdata(client));
        return 0;
 }
 
-static struct spi_driver wm8753_spi_driver = {
+static const struct i2c_device_id wm8753_i2c_id[] = {
+       { "wm8753", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id);
+
+static struct i2c_driver wm8753_i2c_driver = {
        .driver = {
-               .name   = "wm8753",
-               .bus    = &spi_bus_type,
-               .owner  = THIS_MODULE,
+               .name = "wm8753-codec",
+               .owner = THIS_MODULE,
        },
-       .probe          = wm8753_spi_probe,
-       .remove         = __devexit_p(wm8753_spi_remove),
+       .probe =    wm8753_i2c_probe,
+       .remove =   __devexit_p(wm8753_i2c_remove),
+       .id_table = wm8753_i2c_id,
 };
 #endif
 
 static int __init wm8753_modinit(void)
 {
-       int ret;
+       int ret = 0;
 #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);
+       if (ret != 0) {
+               printk(KERN_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);
+       if (ret != 0) {
+               printk(KERN_ERR "Failed to register wm8753 SPI driver: %d\n",
+                      ret);
+       }
 #endif
-       return 0;
+       return ret;
 }
 module_init(wm8753_modinit);