]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - sound/soc/codecs/twl4030.c
ASoC: multi-component - ASoC Multi-Component Support
[mirror_ubuntu-jammy-kernel.git] / sound / soc / codecs / twl4030.c
index 520ffd6536c3c44a46fcff4cc811d4408f234fc2..898430f44f9def4551c1f0a05b3258f37728d576 100644 (file)
 #include <sound/initval.h>
 #include <sound/tlv.h>
 
-#include "twl4030.h"
+/* Register descriptions are here */
+#include <linux/mfd/twl4030-codec.h>
+
+/* Shadow register used by the audio driver */
+#define TWL4030_REG_SW_SHADOW          0x4A
+#define TWL4030_CACHEREGNUM    (TWL4030_REG_SW_SHADOW + 1)
+
+/* TWL4030_REG_SW_SHADOW (0x4A) Fields */
+#define TWL4030_HFL_EN                 0x01
+#define TWL4030_HFR_EN                 0x02
 
 /*
  * twl4030 register cache & default register settings
  */
 static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = {
        0x00, /* this register not used         */
-       0x91, /* REG_CODEC_MODE         (0x1)   */
-       0xc3, /* REG_OPTION             (0x2)   */
+       0x00, /* REG_CODEC_MODE         (0x1)   */
+       0x00, /* REG_OPTION             (0x2)   */
        0x00, /* REG_UNKNOWN            (0x3)   */
        0x00, /* REG_MICBIAS_CTL        (0x4)   */
-       0x20, /* REG_ANAMICL            (0x5)   */
+       0x00, /* REG_ANAMICL            (0x5)   */
        0x00, /* REG_ANAMICR            (0x6)   */
        0x00, /* REG_AVADC_CTL          (0x7)   */
        0x00, /* REG_ADCMICSEL          (0x8)   */
        0x00, /* REG_DIGMIXING          (0x9)   */
-       0x0c, /* REG_ATXL1PGA           (0xA)   */
-       0x0c, /* REG_ATXR1PGA           (0xB)   */
-       0x00, /* REG_AVTXL2PGA          (0xC)   */
-       0x00, /* REG_AVTXR2PGA          (0xD)   */
+       0x0f, /* REG_ATXL1PGA           (0xA)   */
+       0x0f, /* REG_ATXR1PGA           (0xB)   */
+       0x0f, /* REG_AVTXL2PGA          (0xC)   */
+       0x0f, /* REG_AVTXR2PGA          (0xD)   */
        0x00, /* REG_AUDIO_IF           (0xE)   */
        0x00, /* REG_VOICE_IF           (0xF)   */
-       0x00, /* REG_ARXR1PGA           (0x10)  */
-       0x00, /* REG_ARXL1PGA           (0x11)  */
-       0x6c, /* REG_ARXR2PGA           (0x12)  */
-       0x6c, /* REG_ARXL2PGA           (0x13)  */
-       0x00, /* REG_VRXPGA             (0x14)  */
+       0x3f, /* REG_ARXR1PGA           (0x10)  */
+       0x3f, /* REG_ARXL1PGA           (0x11)  */
+       0x3f, /* REG_ARXR2PGA           (0x12)  */
+       0x3f, /* REG_ARXL2PGA           (0x13)  */
+       0x25, /* REG_VRXPGA             (0x14)  */
        0x00, /* REG_VSTPGA             (0x15)  */
        0x00, /* REG_VRX2ARXPGA         (0x16)  */
        0x00, /* REG_AVDAC_CTL          (0x17)  */
        0x00, /* REG_ARX2VTXPGA         (0x18)  */
-       0x00, /* REG_ARXL1_APGA_CTL     (0x19)  */
-       0x00, /* REG_ARXR1_APGA_CTL     (0x1A)  */
-       0x4a, /* REG_ARXL2_APGA_CTL     (0x1B)  */
-       0x4a, /* REG_ARXR2_APGA_CTL     (0x1C)  */
+       0x32, /* REG_ARXL1_APGA_CTL     (0x19)  */
+       0x32, /* REG_ARXR1_APGA_CTL     (0x1A)  */
+       0x32, /* REG_ARXL2_APGA_CTL     (0x1B)  */
+       0x32, /* REG_ARXR2_APGA_CTL     (0x1C)  */
        0x00, /* REG_ATX2ARXPGA         (0x1D)  */
        0x00, /* REG_BT_IF              (0x1E)  */
-       0x00, /* REG_BTPGA              (0x1F)  */
+       0x55, /* REG_BTPGA              (0x1F)  */
        0x00, /* REG_BTSTPGA            (0x20)  */
        0x00, /* REG_EAR_CTL            (0x21)  */
        0x00, /* REG_HS_SEL             (0x22)  */
@@ -85,32 +94,32 @@ static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = {
        0x00, /* REG_PRECKR_CTL         (0x28)  */
        0x00, /* REG_HFL_CTL            (0x29)  */
        0x00, /* REG_HFR_CTL            (0x2A)  */
-       0x00, /* REG_ALC_CTL            (0x2B)  */
+       0x05, /* REG_ALC_CTL            (0x2B)  */
        0x00, /* REG_ALC_SET1           (0x2C)  */
        0x00, /* REG_ALC_SET2           (0x2D)  */
        0x00, /* REG_BOOST_CTL          (0x2E)  */
        0x00, /* REG_SOFTVOL_CTL        (0x2F)  */
-       0x00, /* REG_DTMF_FREQSEL       (0x30)  */
+       0x13, /* REG_DTMF_FREQSEL       (0x30)  */
        0x00, /* REG_DTMF_TONEXT1H      (0x31)  */
        0x00, /* REG_DTMF_TONEXT1L      (0x32)  */
        0x00, /* REG_DTMF_TONEXT2H      (0x33)  */
        0x00, /* REG_DTMF_TONEXT2L      (0x34)  */
-       0x00, /* REG_DTMF_TONOFF        (0x35)  */
-       0x00, /* REG_DTMF_WANONOFF      (0x36)  */
+       0x79, /* REG_DTMF_TONOFF        (0x35)  */
+       0x11, /* REG_DTMF_WANONOFF      (0x36)  */
        0x00, /* REG_I2S_RX_SCRAMBLE_H  (0x37)  */
        0x00, /* REG_I2S_RX_SCRAMBLE_M  (0x38)  */
        0x00, /* REG_I2S_RX_SCRAMBLE_L  (0x39)  */
        0x06, /* REG_APLL_CTL           (0x3A)  */
        0x00, /* REG_DTMF_CTL           (0x3B)  */
-       0x00, /* REG_DTMF_PGA_CTL2      (0x3C)  */
-       0x00, /* REG_DTMF_PGA_CTL1      (0x3D)  */
+       0x44, /* REG_DTMF_PGA_CTL2      (0x3C)  */
+       0x69, /* REG_DTMF_PGA_CTL1      (0x3D)  */
        0x00, /* REG_MISC_SET_1         (0x3E)  */
        0x00, /* REG_PCMBTMUX           (0x3F)  */
        0x00, /* not used               (0x40)  */
        0x00, /* not used               (0x41)  */
        0x00, /* not used               (0x42)  */
        0x00, /* REG_RX_PATH_SEL        (0x43)  */
-       0x00, /* REG_VDL_APGA_CTL       (0x44)  */
+       0x32, /* REG_VDL_APGA_CTL       (0x44)  */
        0x00, /* REG_VIBRA_CTL          (0x45)  */
        0x00, /* REG_VIBRA_SET          (0x46)  */
        0x00, /* REG_VIBRA_PWM_SET      (0x47)  */
@@ -124,6 +133,8 @@ struct twl4030_priv {
        struct snd_soc_codec codec;
 
        unsigned int codec_powered;
+
+       /* reference counts of AIF/APLL users */
        unsigned int apll_enabled;
 
        struct snd_pcm_substream *master_substream;
@@ -136,9 +147,14 @@ struct twl4030_priv {
 
        unsigned int sysclk;
 
-       /* Headset output state handling */
-       unsigned int hsl_enabled;
-       unsigned int hsr_enabled;
+       /* Output (with associated amp) states */
+       u8 hsl_enabled, hsr_enabled;
+       u8 earpiece_enabled;
+       u8 predrivel_enabled, predriver_enabled;
+       u8 carkitl_enabled, carkitr_enabled;
+
+       /* Delay needed after enabling the digimic interface */
+       unsigned int digimic_delay;
 };
 
 /*
@@ -174,17 +190,52 @@ static inline void twl4030_write_reg_cache(struct snd_soc_codec *codec,
 static int twl4030_write(struct snd_soc_codec *codec,
                        unsigned int reg, unsigned int value)
 {
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
+       int write_to_reg = 0;
+
        twl4030_write_reg_cache(codec, reg, value);
-       if (likely(reg < TWL4030_REG_SW_SHADOW))
-               return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value,
-                                           reg);
-       else
-               return 0;
+       if (likely(reg < TWL4030_REG_SW_SHADOW)) {
+               /* Decide if the given register can be written */
+               switch (reg) {
+               case TWL4030_REG_EAR_CTL:
+                       if (twl4030->earpiece_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_PREDL_CTL:
+                       if (twl4030->predrivel_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_PREDR_CTL:
+                       if (twl4030->predriver_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_PRECKL_CTL:
+                       if (twl4030->carkitl_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_PRECKR_CTL:
+                       if (twl4030->carkitr_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_HS_GAIN_SET:
+                       if (twl4030->hsl_enabled || twl4030->hsr_enabled)
+                               write_to_reg = 1;
+                       break;
+               default:
+                       /* All other register can be written */
+                       write_to_reg = 1;
+                       break;
+               }
+               if (write_to_reg)
+                       return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
+                                                   value, reg);
+       }
+       return 0;
 }
 
 static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
 {
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        int mode;
 
        if (enable == twl4030->codec_powered)
@@ -205,58 +256,87 @@ static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
        udelay(10);
 }
 
-static void twl4030_init_chip(struct snd_soc_codec *codec)
+static inline void twl4030_check_defaults(struct snd_soc_codec *codec)
 {
-       u8 *cache = codec->reg_cache;
-       int i;
+       int i, difference = 0;
+       u8 val;
+
+       dev_dbg(codec->dev, "Checking TWL audio default configuration\n");
+       for (i = 1; i <= TWL4030_REG_MISC_SET_2; i++) {
+               twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val, i);
+               if (val != twl4030_reg[i]) {
+                       difference++;
+                       dev_dbg(codec->dev,
+                                "Reg 0x%02x: chip: 0x%02x driver: 0x%02x\n",
+                                i, val, twl4030_reg[i]);
+               }
+       }
+       dev_dbg(codec->dev, "Found %d non maching registers. %s\n",
+                difference, difference ? "Not OK" : "OK");
+}
 
-       /* clear CODECPDZ prior to setting register defaults */
-       twl4030_codec_enable(codec, 0);
+static inline void twl4030_reset_registers(struct snd_soc_codec *codec)
+{
+       int i;
 
        /* set all audio section registers to reasonable defaults */
        for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++)
                if (i != TWL4030_REG_APLL_CTL)
-                       twl4030_write(codec, i, cache[i]);
+                       twl4030_write(codec, i, twl4030_reg[i]);
 
 }
 
-static void twl4030_apll_enable(struct snd_soc_codec *codec, int enable)
+static void twl4030_init_chip(struct snd_soc_codec *codec)
 {
-       struct twl4030_priv *twl4030 = codec->private_data;
-       int status;
+       struct twl4030_codec_audio_data *pdata = dev_get_platdata(codec->dev);
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
+       u8 reg, byte;
+       int i = 0;
 
-       if (enable == twl4030->apll_enabled)
-               return;
+       /* Check defaults, if instructed before anything else */
+       if (pdata && pdata->check_defaults)
+               twl4030_check_defaults(codec);
 
-       if (enable)
-               /* Enable PLL */
-               status = twl4030_codec_enable_resource(TWL4030_CODEC_RES_APLL);
-       else
-               /* Disable PLL */
-               status = twl4030_codec_disable_resource(TWL4030_CODEC_RES_APLL);
+       /* Reset registers, if no setup data or if instructed to do so */
+       if (!pdata || (pdata && pdata->reset_registers))
+               twl4030_reset_registers(codec);
 
-       if (status >= 0)
-               twl4030_write_reg_cache(codec, TWL4030_REG_APLL_CTL, status);
+       /* Refresh APLL_CTL register from HW */
+       twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte,
+                           TWL4030_REG_APLL_CTL);
+       twl4030_write_reg_cache(codec, TWL4030_REG_APLL_CTL, byte);
 
-       twl4030->apll_enabled = enable;
-}
+       /* anti-pop when changing analog gain */
+       reg = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1);
+       twl4030_write(codec, TWL4030_REG_MISC_SET_1,
+               reg | TWL4030_SMOOTH_ANAVOL_EN);
 
-static void twl4030_power_up(struct snd_soc_codec *codec)
-{
-       struct twl4030_priv *twl4030 = codec->private_data;
-       u8 anamicl, regmisc1, byte;
-       int i = 0;
+       twl4030_write(codec, TWL4030_REG_OPTION,
+               TWL4030_ATXL1_EN | TWL4030_ATXR1_EN |
+               TWL4030_ARXL2_EN | TWL4030_ARXR2_EN);
+
+       /* REG_ARXR2_APGA_CTL reset according to the TRM: 0dB, DA_EN */
+       twl4030_write(codec, TWL4030_REG_ARXR2_APGA_CTL, 0x32);
 
-       if (twl4030->codec_powered)
+       /* Machine dependent setup */
+       if (!pdata)
                return;
 
-       /* set CODECPDZ to turn on codec */
-       twl4030_codec_enable(codec, 1);
+       twl4030->digimic_delay = pdata->digimic_delay;
+
+       reg = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
+       reg &= ~TWL4030_RAMP_DELAY;
+       reg |= (pdata->ramp_delay_value << 2);
+       twl4030_write_reg_cache(codec, TWL4030_REG_HS_POPN_SET, reg);
 
        /* initiate offset cancellation */
-       anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL);
+       twl4030_codec_enable(codec, 1);
+
+       reg = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL);
+       reg &= ~TWL4030_OFFSET_CNCL_SEL;
+       reg |= pdata->offset_cncl_path;
        twl4030_write(codec, TWL4030_REG_ANAMICL,
-               anamicl | TWL4030_CNCL_OFFSET_START);
+               reg | TWL4030_CNCL_OFFSET_START);
 
        /* wait for offset cancellation to complete */
        do {
@@ -271,23 +351,28 @@ static void twl4030_power_up(struct snd_soc_codec *codec)
        /* Make sure that the reg_cache has the same value as the HW */
        twl4030_write_reg_cache(codec, TWL4030_REG_ANAMICL, byte);
 
-       /* anti-pop when changing analog gain */
-       regmisc1 = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1);
-       twl4030_write(codec, TWL4030_REG_MISC_SET_1,
-               regmisc1 | TWL4030_SMOOTH_ANAVOL_EN);
-
-       /* toggle CODECPDZ as per TRM */
        twl4030_codec_enable(codec, 0);
-       twl4030_codec_enable(codec, 1);
 }
 
-/*
- * Unconditional power down
- */
-static void twl4030_power_down(struct snd_soc_codec *codec)
+static void twl4030_apll_enable(struct snd_soc_codec *codec, int enable)
 {
-       /* power down */
-       twl4030_codec_enable(codec, 0);
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
+       int status = -1;
+
+       if (enable) {
+               twl4030->apll_enabled++;
+               if (twl4030->apll_enabled == 1)
+                       status = twl4030_codec_enable_resource(
+                                                       TWL4030_CODEC_RES_APLL);
+       } else {
+               twl4030->apll_enabled--;
+               if (!twl4030->apll_enabled)
+                       status = twl4030_codec_disable_resource(
+                                                       TWL4030_CODEC_RES_APLL);
+       }
+
+       if (status >= 0)
+               twl4030_write_reg_cache(codec, TWL4030_REG_APLL_CTL, status);
 }
 
 /* Earpiece */
@@ -461,10 +546,11 @@ static const struct snd_kcontrol_new twl4030_dapm_abypassl2_control =
 static const struct snd_kcontrol_new twl4030_dapm_abypassv_control =
        SOC_DAPM_SINGLE("Switch", TWL4030_REG_VDL_APGA_CTL, 2, 1, 0);
 
-/* Digital bypass gain, 0 mutes the bypass */
+/* Digital bypass gain, mute instead of -30dB */
 static const unsigned int twl4030_dapm_dbypass_tlv[] = {
-       TLV_DB_RANGE_HEAD(2),
-       0, 3, TLV_DB_SCALE_ITEM(-2400, 0, 1),
+       TLV_DB_RANGE_HEAD(3),
+       0, 1, TLV_DB_SCALE_ITEM(-3000, 600, 1),
+       2, 3, TLV_DB_SCALE_ITEM(-2400, 0, 0),
        4, 7, TLV_DB_SCALE_ITEM(-1800, 600, 0),
 };
 
@@ -492,60 +578,30 @@ static const struct snd_kcontrol_new twl4030_dapm_dbypassv_control =
                        TWL4030_REG_VSTPGA, 0, 0x29, 0,
                        twl4030_dapm_dbypassv_tlv);
 
-static int micpath_event(struct snd_soc_dapm_widget *w,
-       struct snd_kcontrol *kcontrol, int event)
-{
-       struct soc_enum *e = (struct soc_enum *)w->kcontrols->private_value;
-       unsigned char adcmicsel, micbias_ctl;
-
-       adcmicsel = twl4030_read_reg_cache(w->codec, TWL4030_REG_ADCMICSEL);
-       micbias_ctl = twl4030_read_reg_cache(w->codec, TWL4030_REG_MICBIAS_CTL);
-       /* Prepare the bits for the given TX path:
-        * shift_l == 0: TX1 microphone path
-        * shift_l == 2: TX2 microphone path */
-       if (e->shift_l) {
-               /* TX2 microphone path */
-               if (adcmicsel & TWL4030_TX2IN_SEL)
-                       micbias_ctl |= TWL4030_MICBIAS2_CTL; /* digimic */
-               else
-                       micbias_ctl &= ~TWL4030_MICBIAS2_CTL;
-       } else {
-               /* TX1 microphone path */
-               if (adcmicsel & TWL4030_TX1IN_SEL)
-                       micbias_ctl |= TWL4030_MICBIAS1_CTL; /* digimic */
-               else
-                       micbias_ctl &= ~TWL4030_MICBIAS1_CTL;
-       }
-
-       twl4030_write(w->codec, TWL4030_REG_MICBIAS_CTL, micbias_ctl);
-
-       return 0;
-}
-
 /*
  * Output PGA builder:
  * Handle the muting and unmuting of the given output (turning off the
  * amplifier associated with the output pin)
- * On mute bypass the reg_cache and mute the volume
- * On unmute: restore the register content
+ * On mute bypass the reg_cache and write 0 to the register
+ * On unmute: restore the register content from the reg_cache
  * Outputs handled in this way:  Earpiece, PreDrivL/R, CarkitL/R
  */
 #define TWL4030_OUTPUT_PGA(pin_name, reg, mask)                                \
 static int pin_name##pga_event(struct snd_soc_dapm_widget *w,          \
                struct snd_kcontrol *kcontrol, int event)               \
 {                                                                      \
-       u8 reg_val;                                                     \
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); \
                                                                        \
        switch (event) {                                                \
        case SND_SOC_DAPM_POST_PMU:                                     \
+               twl4030->pin_name##_enabled = 1;                        \
                twl4030_write(w->codec, reg,                            \
                        twl4030_read_reg_cache(w->codec, reg));         \
                break;                                                  \
        case SND_SOC_DAPM_POST_PMD:                                     \
-               reg_val = twl4030_read_reg_cache(w->codec, reg);        \
-               twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,    \
-                                       reg_val & (~mask),              \
-                                       reg);                           \
+               twl4030->pin_name##_enabled = 0;                        \
+               twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,            \
+                                       0, reg);                        \
                break;                                                  \
        }                                                               \
        return 0;                                                       \
@@ -636,13 +692,36 @@ static int apll_event(struct snd_soc_dapm_widget *w,
        return 0;
 }
 
-static void headset_ramp(struct snd_soc_codec *codec, int ramp)
+static int aif_event(struct snd_soc_dapm_widget *w,
+               struct snd_kcontrol *kcontrol, int event)
 {
-       struct snd_soc_device *socdev = codec->socdev;
-       struct twl4030_setup_data *setup = socdev->codec_data;
+       u8 audio_if;
+
+       audio_if = twl4030_read_reg_cache(w->codec, TWL4030_REG_AUDIO_IF);
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               /* Enable AIF */
+               /* enable the PLL before we use it to clock the DAI */
+               twl4030_apll_enable(w->codec, 1);
 
+               twl4030_write(w->codec, TWL4030_REG_AUDIO_IF,
+                                               audio_if | TWL4030_AIF_EN);
+               break;
+       case SND_SOC_DAPM_POST_PMD:
+               /* disable the DAI before we stop it's source PLL */
+               twl4030_write(w->codec, TWL4030_REG_AUDIO_IF,
+                                               audio_if &  ~TWL4030_AIF_EN);
+               twl4030_apll_enable(w->codec, 0);
+               break;
+       }
+       return 0;
+}
+
+static void headset_ramp(struct snd_soc_codec *codec, int ramp)
+{
+       struct twl4030_codec_audio_data *pdata = codec->dev->platform_data;
        unsigned char hs_gain, hs_pop;
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        /* Base values for ramp delay calculation: 2^19 - 2^26 */
        unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304,
                                    8388608, 16777216, 33554432, 67108864};
@@ -652,9 +731,9 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 
        /* Enable external mute control, this dramatically reduces
         * the pop-noise */
-       if (setup && setup->hs_extmute) {
-               if (setup->set_hs_extmute) {
-                       setup->set_hs_extmute(1);
+       if (pdata && pdata->hs_extmute) {
+               if (pdata->set_hs_extmute) {
+                       pdata->set_hs_extmute(1);
                } else {
                        hs_pop |= TWL4030_EXTMUTE;
                        twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
@@ -665,7 +744,10 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
                /* Headset ramp-up according to the TRM */
                hs_pop |= TWL4030_VMID_EN;
                twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
-               twl4030_write(codec, TWL4030_REG_HS_GAIN_SET, hs_gain);
+               /* Actually write to the register */
+               twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
+                                       hs_gain,
+                                       TWL4030_REG_HS_GAIN_SET);
                hs_pop |= TWL4030_RAMP_EN;
                twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
                /* Wait ramp delay time + 1, so the VMID can settle */
@@ -689,9 +771,9 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
        }
 
        /* Disable external mute */
-       if (setup && setup->hs_extmute) {
-               if (setup->set_hs_extmute) {
-                       setup->set_hs_extmute(0);
+       if (pdata && pdata->hs_extmute) {
+               if (pdata->set_hs_extmute) {
+                       pdata->set_hs_extmute(0);
                } else {
                        hs_pop &= ~TWL4030_EXTMUTE;
                        twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
@@ -702,7 +784,7 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 static int headsetlpga_event(struct snd_soc_dapm_widget *w,
                struct snd_kcontrol *kcontrol, int event)
 {
-       struct twl4030_priv *twl4030 = w->codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
 
        switch (event) {
        case SND_SOC_DAPM_POST_PMU:
@@ -726,7 +808,7 @@ static int headsetlpga_event(struct snd_soc_dapm_widget *w,
 static int headsetrpga_event(struct snd_soc_dapm_widget *w,
                struct snd_kcontrol *kcontrol, int event)
 {
-       struct twl4030_priv *twl4030 = w->codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
 
        switch (event) {
        case SND_SOC_DAPM_POST_PMU:
@@ -747,6 +829,16 @@ static int headsetrpga_event(struct snd_soc_dapm_widget *w,
        return 0;
 }
 
+static int digimic_event(struct snd_soc_dapm_widget *w,
+               struct snd_kcontrol *kcontrol, int event)
+{
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
+
+       if (twl4030->digimic_delay)
+               mdelay(twl4030->digimic_delay);
+       return 0;
+}
+
 /*
  * Some of the gain controls in TWL (mostly those which are associated with
  * the outputs) are implemented in an interesting way:
@@ -918,7 +1010,7 @@ static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
        unsigned short val;
        unsigned short mask, bitmask;
@@ -1036,6 +1128,16 @@ static const struct soc_enum twl4030_vibradir_enum =
                        ARRAY_SIZE(twl4030_vibradir_texts),
                        twl4030_vibradir_texts);
 
+/* Digimic Left and right swapping */
+static const char *twl4030_digimicswap_texts[] = {
+       "Not swapped", "Swapped",
+};
+
+static const struct soc_enum twl4030_digimicswap_enum =
+       SOC_ENUM_SINGLE(TWL4030_REG_MISC_SET_1, 0,
+                       ARRAY_SIZE(twl4030_digimicswap_texts),
+                       twl4030_digimicswap_texts);
+
 static const struct snd_kcontrol_new twl4030_snd_controls[] = {
        /* Codec operation mode control */
        SOC_ENUM_EXT("Codec Operation Mode", twl4030_op_modes_enum,
@@ -1112,6 +1214,8 @@ static const struct snd_kcontrol_new twl4030_snd_controls[] = {
 
        SOC_ENUM("Vibra H-bridge mode", twl4030_vibradirmode_enum),
        SOC_ENUM("Vibra H-bridge direction", twl4030_vibradir_enum),
+
+       SOC_ENUM("Digimic LR Swap", twl4030_digimicswap_enum),
 };
 
 static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
@@ -1128,8 +1232,6 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
        SND_SOC_DAPM_INPUT("DIGIMIC1"),
 
        /* Outputs */
-       SND_SOC_DAPM_OUTPUT("OUTL"),
-       SND_SOC_DAPM_OUTPUT("OUTR"),
        SND_SOC_DAPM_OUTPUT("EARPIECE"),
        SND_SOC_DAPM_OUTPUT("PREDRIVEL"),
        SND_SOC_DAPM_OUTPUT("PREDRIVER"),
@@ -1141,6 +1243,11 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
        SND_SOC_DAPM_OUTPUT("HFR"),
        SND_SOC_DAPM_OUTPUT("VIBRA"),
 
+       /* AIF and APLL clocks for running DAIs (including loopback) */
+       SND_SOC_DAPM_OUTPUT("Virtual HiFi OUT"),
+       SND_SOC_DAPM_INPUT("Virtual HiFi IN"),
+       SND_SOC_DAPM_OUTPUT("Virtual Voice OUT"),
+
        /* DACs */
        SND_SOC_DAPM_DAC("DAC Right1", "Right Front HiFi Playback",
                        SND_SOC_NOPM, 0, 0),
@@ -1204,7 +1311,8 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
        SND_SOC_DAPM_SUPPLY("APLL Enable", SND_SOC_NOPM, 0, 0, apll_event,
                            SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
 
-       SND_SOC_DAPM_SUPPLY("AIF Enable", TWL4030_REG_AUDIO_IF, 0, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF Enable", SND_SOC_NOPM, 0, 0, aif_event,
+                           SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
 
        /* Output MIXER controls */
        /* Earpiece */
@@ -1291,14 +1399,10 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
        /* Analog/Digital mic path selection.
           TX1 Left/Right: either analog Left/Right or Digimic0
           TX2 Left/Right: either analog Left/Right or Digimic1 */
-       SND_SOC_DAPM_MUX_E("TX1 Capture Route", SND_SOC_NOPM, 0, 0,
-               &twl4030_dapm_micpathtx1_control, micpath_event,
-               SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD|
-               SND_SOC_DAPM_POST_REG),
-       SND_SOC_DAPM_MUX_E("TX2 Capture Route", SND_SOC_NOPM, 0, 0,
-               &twl4030_dapm_micpathtx2_control, micpath_event,
-               SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD|
-               SND_SOC_DAPM_POST_REG),
+       SND_SOC_DAPM_MUX("TX1 Capture Route", SND_SOC_NOPM, 0, 0,
+               &twl4030_dapm_micpathtx1_control),
+       SND_SOC_DAPM_MUX("TX2 Capture Route", SND_SOC_NOPM, 0, 0,
+               &twl4030_dapm_micpathtx2_control),
 
        /* Analog input mixers for the capture amplifiers */
        SND_SOC_DAPM_MIXER("Analog Left",
@@ -1315,10 +1419,17 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
        SND_SOC_DAPM_PGA("ADC Physical Right",
                TWL4030_REG_AVADC_CTL, 1, 0, NULL, 0),
 
-       SND_SOC_DAPM_PGA("Digimic0 Enable",
-               TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0),
-       SND_SOC_DAPM_PGA("Digimic1 Enable",
-               TWL4030_REG_ADCMICSEL, 3, 0, NULL, 0),
+       SND_SOC_DAPM_PGA_E("Digimic0 Enable",
+               TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0,
+               digimic_event, SND_SOC_DAPM_POST_PMU),
+       SND_SOC_DAPM_PGA_E("Digimic1 Enable",
+               TWL4030_REG_ADCMICSEL, 3, 0, NULL, 0,
+               digimic_event, SND_SOC_DAPM_POST_PMU),
+
+       SND_SOC_DAPM_SUPPLY("micbias1 select", TWL4030_REG_MICBIAS_CTL, 5, 0,
+                           NULL, 0),
+       SND_SOC_DAPM_SUPPLY("micbias2 select", TWL4030_REG_MICBIAS_CTL, 6, 0,
+                           NULL, 0),
 
        SND_SOC_DAPM_MICBIAS("Mic Bias 1", TWL4030_REG_MICBIAS_CTL, 0, 0),
        SND_SOC_DAPM_MICBIAS("Mic Bias 2", TWL4030_REG_MICBIAS_CTL, 1, 0),
@@ -1334,14 +1445,13 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"Digital Voice Playback Mixer", NULL, "DAC Voice"},
 
        /* Supply for the digital part (APLL) */
-       {"Digital R1 Playback Mixer", NULL, "APLL Enable"},
-       {"Digital L1 Playback Mixer", NULL, "APLL Enable"},
-       {"Digital R2 Playback Mixer", NULL, "APLL Enable"},
-       {"Digital L2 Playback Mixer", NULL, "APLL Enable"},
        {"Digital Voice Playback Mixer", NULL, "APLL Enable"},
 
-       {"Digital R1 Playback Mixer", NULL, "AIF Enable"},
-       {"Digital L1 Playback Mixer", NULL, "AIF Enable"},
+       {"DAC Left1", NULL, "AIF Enable"},
+       {"DAC Right1", NULL, "AIF Enable"},
+       {"DAC Left2", NULL, "AIF Enable"},
+       {"DAC Right1", NULL, "AIF Enable"},
+
        {"Digital R2 Playback Mixer", NULL, "AIF Enable"},
        {"Digital L2 Playback Mixer", NULL, "AIF Enable"},
 
@@ -1411,8 +1521,14 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"Vibra Mux", "AudioR2", "DAC Right2"},
 
        /* outputs */
-       {"OUTL", NULL, "Analog L2 Playback Mixer"},
-       {"OUTR", NULL, "Analog R2 Playback Mixer"},
+       /* Must be always connected (for AIF and APLL) */
+       {"Virtual HiFi OUT", NULL, "DAC Left1"},
+       {"Virtual HiFi OUT", NULL, "DAC Right1"},
+       {"Virtual HiFi OUT", NULL, "DAC Left2"},
+       {"Virtual HiFi OUT", NULL, "DAC Right2"},
+       /* Must be always connected (for APLL) */
+       {"Virtual Voice OUT", NULL, "Digital Voice Playback Mixer"},
+       /* Physical outputs */
        {"EARPIECE", NULL, "Earpiece PGA"},
        {"PREDRIVEL", NULL, "PredriveL PGA"},
        {"PREDRIVER", NULL, "PredriveR PGA"},
@@ -1426,6 +1542,12 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"VIBRA", NULL, "Vibra Route"},
 
        /* Capture path */
+       /* Must be always connected (for AIF and APLL) */
+       {"ADC Virtual Left1", NULL, "Virtual HiFi IN"},
+       {"ADC Virtual Right1", NULL, "Virtual HiFi IN"},
+       {"ADC Virtual Left2", NULL, "Virtual HiFi IN"},
+       {"ADC Virtual Right2", NULL, "Virtual HiFi IN"},
+       /* Physical inputs */
        {"Analog Left", "Main Mic Capture Switch", "MAINMIC"},
        {"Analog Left", "Headset Mic Capture Switch", "HSMIC"},
        {"Analog Left", "AUXL Capture Switch", "AUXL"},
@@ -1440,6 +1562,9 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"Digimic0 Enable", NULL, "DIGIMIC0"},
        {"Digimic1 Enable", NULL, "DIGIMIC1"},
 
+       {"DIGIMIC0", NULL, "micbias1 select"},
+       {"DIGIMIC1", NULL, "micbias2 select"},
+
        /* TX1 Left capture path */
        {"TX1 Capture Route", "Analog", "ADC Physical Left"},
        {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
@@ -1458,11 +1583,6 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"ADC Virtual Left2", NULL, "TX2 Capture Route"},
        {"ADC Virtual Right2", NULL, "TX2 Capture Route"},
 
-       {"ADC Virtual Left1", NULL, "APLL Enable"},
-       {"ADC Virtual Right1", NULL, "APLL Enable"},
-       {"ADC Virtual Left2", NULL, "APLL Enable"},
-       {"ADC Virtual Right2", NULL, "APLL Enable"},
-
        {"ADC Virtual Left1", NULL, "AIF Enable"},
        {"ADC Virtual Right1", NULL, "AIF Enable"},
        {"ADC Virtual Left2", NULL, "AIF Enable"},
@@ -1519,10 +1639,10 @@ static int twl4030_set_bias_level(struct snd_soc_codec *codec,
                break;
        case SND_SOC_BIAS_STANDBY:
                if (codec->bias_level == SND_SOC_BIAS_OFF)
-                       twl4030_power_up(codec);
+                       twl4030_codec_enable(codec, 1);
                break;
        case SND_SOC_BIAS_OFF:
-               twl4030_power_down(codec);
+               twl4030_codec_enable(codec, 0);
                break;
        }
        codec->bias_level = level;
@@ -1586,9 +1706,8 @@ static int twl4030_startup(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 twl4030_priv *twl4030 = codec->private_data;
+       struct snd_soc_codec *codec = rtd->codec;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
        if (twl4030->master_substream) {
                twl4030->slave_substream = substream;
@@ -1617,9 +1736,8 @@ static void twl4030_shutdown(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 twl4030_priv *twl4030 = codec->private_data;
+       struct snd_soc_codec *codec = rtd->codec;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
        if (twl4030->master_substream == substream)
                twl4030->master_substream = twl4030->slave_substream;
@@ -1643,9 +1761,8 @@ static int twl4030_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 twl4030_priv *twl4030 = codec->private_data;
+       struct snd_soc_codec *codec = rtd->codec;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        u8 mode, old_mode, format, old_format;
 
         /* If the substream has 4 channel, do the necessary setup */
@@ -1708,13 +1825,6 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
-       if (mode != old_mode) {
-               /* change rate and set CODECPDZ */
-               twl4030_codec_enable(codec, 0);
-               twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
-               twl4030_codec_enable(codec, 1);
-       }
-
        /* sample size */
        old_format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
        format = old_format;
@@ -1732,16 +1842,20 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
-       if (format != old_format) {
-
-               /* clear CODECPDZ before changing format (codec requirement) */
-               twl4030_codec_enable(codec, 0);
-
-               /* change format */
-               twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
-
-               /* set CODECPDZ afterwards */
-               twl4030_codec_enable(codec, 1);
+       if (format != old_format || mode != old_mode) {
+               if (twl4030->codec_powered) {
+                       /*
+                        * If the codec is powered, than we need to toggle the
+                        * codec power.
+                        */
+                       twl4030_codec_enable(codec, 0);
+                       twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
+                       twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
+                       twl4030_codec_enable(codec, 1);
+               } else {
+                       twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
+                       twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
+               }
        }
 
        /* Store the important parameters for the DAI configuration and set
@@ -1765,7 +1879,7 @@ static int twl4030_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 twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 19200000:
@@ -1791,6 +1905,7 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai,
                             unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        u8 old_format, format;
 
        /* get format */
@@ -1825,15 +1940,17 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai,
        }
 
        if (format != old_format) {
-
-               /* clear CODECPDZ before changing format (codec requirement) */
-               twl4030_codec_enable(codec, 0);
-
-               /* change format */
-               twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
-
-               /* set CODECPDZ afterwards */
-               twl4030_codec_enable(codec, 1);
+               if (twl4030->codec_powered) {
+                       /*
+                        * If the codec is powered, than we need to toggle the
+                        * codec power.
+                        */
+                       twl4030_codec_enable(codec, 0);
+                       twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
+                       twl4030_codec_enable(codec, 1);
+               } else {
+                       twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
+               }
        }
 
        return 0;
@@ -1878,9 +1995,8 @@ static int twl4030_voice_startup(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 twl4030_priv *twl4030 = codec->private_data;
+       struct snd_soc_codec *codec = rtd->codec;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        u8 mode;
 
        /* If the system master clock is not 26MHz, the voice PCM interface is
@@ -1912,8 +2028,7 @@ static void twl4030_voice_shutdown(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;
 
        /* Enable voice digital filters */
        twl4030_voice_enable(codec, substream->stream, 0);
@@ -1923,8 +2038,8 @@ static int twl4030_voice_hw_params(struct snd_pcm_substream *substream,
                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->card->codec;
+       struct snd_soc_codec *codec = rtd->codec;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        u8 old_mode, mode;
 
        /* Enable voice digital filters */
@@ -1949,10 +2064,17 @@ static int twl4030_voice_hw_params(struct snd_pcm_substream *substream,
        }
 
        if (mode != old_mode) {
-               /* change rate and set CODECPDZ */
-               twl4030_codec_enable(codec, 0);
-               twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
-               twl4030_codec_enable(codec, 1);
+               if (twl4030->codec_powered) {
+                       /*
+                        * If the codec is powered, than we need to toggle the
+                        * codec power.
+                        */
+                       twl4030_codec_enable(codec, 0);
+                       twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
+                       twl4030_codec_enable(codec, 1);
+               } else {
+                       twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
+               }
        }
 
        return 0;
@@ -1962,7 +2084,7 @@ static int twl4030_voice_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 twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
        if (freq != 26000000) {
                dev_err(codec->dev, "Unsupported APLL mclk: %u, the Voice"
@@ -1982,6 +2104,7 @@ static int twl4030_voice_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        u8 old_format, format;
 
        /* get format */
@@ -2013,10 +2136,17 @@ static int twl4030_voice_set_dai_fmt(struct snd_soc_dai *codec_dai,
        }
 
        if (format != old_format) {
-               /* change format and set CODECPDZ */
-               twl4030_codec_enable(codec, 0);
-               twl4030_write(codec, TWL4030_REG_VOICE_IF, format);
-               twl4030_codec_enable(codec, 1);
+               if (twl4030->codec_powered) {
+                       /*
+                        * If the codec is powered, than we need to toggle the
+                        * codec power.
+                        */
+                       twl4030_codec_enable(codec, 0);
+                       twl4030_write(codec, TWL4030_REG_VOICE_IF, format);
+                       twl4030_codec_enable(codec, 1);
+               } else {
+                       twl4030_write(codec, TWL4030_REG_VOICE_IF, format);
+               }
        }
 
        return 0;
@@ -2038,7 +2168,7 @@ static int twl4030_voice_set_tristate(struct snd_soc_dai *dai, int tristate)
 #define TWL4030_RATES   (SNDRV_PCM_RATE_8000_48000)
 #define TWL4030_FORMATS         (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE)
 
-static struct snd_soc_dai_ops twl4030_dai_ops = {
+static struct snd_soc_dai_ops twl4030_dai_hifi_ops = {
        .startup        = twl4030_startup,
        .shutdown       = twl4030_shutdown,
        .hw_params      = twl4030_hw_params,
@@ -2056,9 +2186,9 @@ static struct snd_soc_dai_ops twl4030_dai_voice_ops = {
        .set_tristate   = twl4030_voice_set_tristate,
 };
 
-struct snd_soc_dai twl4030_dai[] = {
+static struct snd_soc_dai_driver twl4030_dai[] = {
 {
-       .name = "twl4030",
+       .name = "twl4030-hifi",
        .playback = {
                .stream_name = "HiFi Playback",
                .channels_min = 2,
@@ -2071,10 +2201,10 @@ struct snd_soc_dai twl4030_dai[] = {
                .channels_max = 4,
                .rates = TWL4030_RATES,
                .formats = TWL4030_FORMATS,},
-       .ops = &twl4030_dai_ops,
+       .ops = &twl4030_dai_hifi_ops,
 },
 {
-       .name = "twl4030 Voice",
+       .name = "twl4030-voice",
        .playback = {
                .stream_name = "Voice Playback",
                .channels_min = 1,
@@ -2090,180 +2220,90 @@ struct snd_soc_dai twl4030_dai[] = {
        .ops = &twl4030_dai_voice_ops,
 },
 };
-EXPORT_SYMBOL_GPL(twl4030_dai);
 
-static int twl4030_soc_suspend(struct platform_device *pdev, pm_message_t state)
+static int twl4030_soc_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;
-
        twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
-
        return 0;
 }
 
-static int twl4030_soc_resume(struct platform_device *pdev)
+static int twl4030_soc_resume(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
-
        twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       twl4030_set_bias_level(codec, codec->suspend_bias_level);
        return 0;
 }
 
-static struct snd_soc_codec *twl4030_codec;
-
-static int twl4030_soc_probe(struct platform_device *pdev)
+static int twl4030_soc_probe(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct twl4030_setup_data *setup = socdev->codec_data;
-       struct snd_soc_codec *codec;
        struct twl4030_priv *twl4030;
-       int ret;
-
-       BUG_ON(!twl4030_codec);
-
-       codec = twl4030_codec;
-       twl4030 = codec->private_data;
-       socdev->card->codec = codec;
 
-       /* Configuration for headset ramp delay from setup data */
-       if (setup) {
-               unsigned char hs_pop;
-
-               if (setup->sysclk != twl4030->sysclk)
-                       dev_warn(&pdev->dev,
-                                "Mismatch in APLL mclk: %u (configured: %u)\n",
-                                setup->sysclk, twl4030->sysclk);
-
-               hs_pop = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
-               hs_pop &= ~TWL4030_RAMP_DELAY;
-               hs_pop |= (setup->ramp_delay_value << 2);
-               twl4030_write_reg_cache(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
+       twl4030 = kzalloc(sizeof(struct twl4030_priv), GFP_KERNEL);
+       if (twl4030 == NULL) {
+               printk("Can not allocate memroy\n");
+               return -ENOMEM;
        }
+       snd_soc_codec_set_drvdata(codec, twl4030);
+       /* Set the defaults, and power up the codec */
+       twl4030->sysclk = twl4030_codec_get_mclk() / 1000;
+       codec->bias_level = SND_SOC_BIAS_OFF;
+       codec->idle_bias_off = 1;
 
-       /* register pcms */
-       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
-       if (ret < 0) {
-               dev_err(&pdev->dev, "failed to create pcms\n");
-               return ret;
-       }
+       twl4030_init_chip(codec);
 
        snd_soc_add_controls(codec, twl4030_snd_controls,
                                ARRAY_SIZE(twl4030_snd_controls));
        twl4030_add_widgets(codec);
-
        return 0;
 }
 
-static int twl4030_soc_remove(struct platform_device *pdev)
+static int twl4030_soc_remove(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
-
        twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
-       snd_soc_free_pcms(socdev);
-       snd_soc_dapm_free(socdev);
-
        return 0;
 }
 
+static struct snd_soc_codec_driver soc_codec_dev_twl4030 = {
+       .probe = twl4030_soc_probe,
+       .remove = twl4030_soc_remove,
+       .suspend = twl4030_soc_suspend,
+       .resume = twl4030_soc_resume,
+       .read = twl4030_read_reg_cache,
+       .write = twl4030_write,
+       .set_bias_level = twl4030_set_bias_level,
+       .reg_cache_size = sizeof(twl4030_reg),
+       .reg_word_size = sizeof(u8),
+       .reg_cache_default = twl4030_reg,
+};
+
 static int __devinit twl4030_codec_probe(struct platform_device *pdev)
 {
        struct twl4030_codec_audio_data *pdata = pdev->dev.platform_data;
-       struct snd_soc_codec *codec;
-       struct twl4030_priv *twl4030;
-       int ret;
 
        if (!pdata) {
                dev_err(&pdev->dev, "platform_data is missing\n");
                return -EINVAL;
        }
 
-       twl4030 = kzalloc(sizeof(struct twl4030_priv), GFP_KERNEL);
-       if (twl4030 == NULL) {
-               dev_err(&pdev->dev, "Can not allocate memroy\n");
-               return -ENOMEM;
-       }
-
-       codec = &twl4030->codec;
-       codec->private_data = twl4030;
-       codec->dev = &pdev->dev;
-       twl4030_dai[0].dev = &pdev->dev;
-       twl4030_dai[1].dev = &pdev->dev;
-
-       mutex_init(&codec->mutex);
-       INIT_LIST_HEAD(&codec->dapm_widgets);
-       INIT_LIST_HEAD(&codec->dapm_paths);
-
-       codec->name = "twl4030";
-       codec->owner = THIS_MODULE;
-       codec->read = twl4030_read_reg_cache;
-       codec->write = twl4030_write;
-       codec->set_bias_level = twl4030_set_bias_level;
-       codec->dai = twl4030_dai;
-       codec->num_dai = ARRAY_SIZE(twl4030_dai);
-       codec->reg_cache_size = sizeof(twl4030_reg);
-       codec->reg_cache = kmemdup(twl4030_reg, sizeof(twl4030_reg),
-                                       GFP_KERNEL);
-       if (codec->reg_cache == NULL) {
-               ret = -ENOMEM;
-               goto error_cache;
-       }
-
-       platform_set_drvdata(pdev, twl4030);
-       twl4030_codec = codec;
-
-       /* Set the defaults, and power up the codec */
-       twl4030->sysclk = twl4030_codec_get_mclk() / 1000;
-       twl4030_init_chip(codec);
-       codec->bias_level = SND_SOC_BIAS_OFF;
-       twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
-       ret = snd_soc_register_codec(codec);
-       if (ret != 0) {
-               dev_err(codec->dev, "Failed to register codec: %d\n", ret);
-               goto error_codec;
-       }
-
-       ret = snd_soc_register_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai));
-       if (ret != 0) {
-               dev_err(codec->dev, "Failed to register DAIs: %d\n", ret);
-               snd_soc_unregister_codec(codec);
-               goto error_codec;
-       }
-
-       return 0;
-
-error_codec:
-       twl4030_power_down(codec);
-       kfree(codec->reg_cache);
-error_cache:
-       kfree(twl4030);
-       return ret;
+       return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl4030,
+                       twl4030_dai, ARRAY_SIZE(twl4030_dai));
 }
 
 static int __devexit twl4030_codec_remove(struct platform_device *pdev)
 {
-       struct twl4030_priv *twl4030 = platform_get_drvdata(pdev);
+       struct twl4030_priv *twl4030 = dev_get_drvdata(&pdev->dev);
 
-       snd_soc_unregister_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai));
-       snd_soc_unregister_codec(&twl4030->codec);
-       kfree(twl4030->codec.reg_cache);
+       snd_soc_unregister_codec(&pdev->dev);
        kfree(twl4030);
-
-       twl4030_codec = NULL;
        return 0;
 }
 
-MODULE_ALIAS("platform:twl4030_codec_audio");
+MODULE_ALIAS("platform:twl4030-codec");
 
 static struct platform_driver twl4030_codec_driver = {
        .probe          = twl4030_codec_probe,
        .remove         = __devexit_p(twl4030_codec_remove),
        .driver         = {
-               .name   = "twl4030_codec_audio",
+               .name   = "twl4030-codec",
                .owner  = THIS_MODULE,
        },
 };
@@ -2280,14 +2320,6 @@ static void __exit twl4030_exit(void)
 }
 module_exit(twl4030_exit);
 
-struct snd_soc_codec_device soc_codec_dev_twl4030 = {
-       .probe = twl4030_soc_probe,
-       .remove = twl4030_soc_remove,
-       .suspend = twl4030_soc_suspend,
-       .resume = twl4030_soc_resume,
-};
-EXPORT_SYMBOL_GPL(soc_codec_dev_twl4030);
-
 MODULE_DESCRIPTION("ASoC TWL4030 codec driver");
 MODULE_AUTHOR("Steve Sakoman");
 MODULE_LICENSE("GPL");