ASoC: Implement WM8903 oversampling rate controls
[deliverable/linux.git] / sound / soc / codecs / wm8903.c
index bf08282d5ee56384023d7055ff3b355d817d8e05..542c7c4868ba20ecef8365520c9cee86d37ea9bf 100644 (file)
@@ -29,7 +29,6 @@
 #include <sound/pcm_params.h>
 #include <sound/tlv.h>
 #include <sound/soc.h>
-#include <sound/soc-dapm.h>
 #include <sound/initval.h>
 #include <sound/wm8903.h>
 
@@ -213,10 +212,11 @@ static u16 wm8903_reg_defaults[] = {
 };
 
 struct wm8903_priv {
-       struct snd_soc_codec codec;
+
        u16 reg_cache[ARRAY_SIZE(wm8903_reg_defaults)];
 
        int sysclk;
+       int irq;
 
        /* Reference counts */
        int class_w_users;
@@ -252,7 +252,6 @@ static int wm8903_volatile_register(unsigned int reg)
 static int wm8903_run_sequence(struct snd_soc_codec *codec, unsigned int start)
 {
        u16 reg[5];
-       struct i2c_client *i2c = codec->control_data;
        struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
 
        BUG_ON(start > 48);
@@ -262,7 +261,7 @@ static int wm8903_run_sequence(struct snd_soc_codec *codec, unsigned int start)
        snd_soc_write(codec, WM8903_WRITE_SEQUENCER_0,
                      reg[0] | WM8903_WSEQ_ENA);
 
-       dev_dbg(&i2c->dev, "Starting sequence at %d\n", start);
+       dev_dbg(codec->dev, "Starting sequence at %d\n", start);
 
        snd_soc_write(codec, WM8903_WRITE_SEQUENCER_3,
                     start | WM8903_WSEQ_START);
@@ -277,7 +276,7 @@ static int wm8903_run_sequence(struct snd_soc_codec *codec, unsigned int start)
                reg[4] = snd_soc_read(codec, WM8903_WRITE_SEQUENCER_4);
        } while (reg[4] & WM8903_WSEQ_BUSY);
 
-       dev_dbg(&i2c->dev, "Sequence complete\n");
+       dev_dbg(codec->dev, "Sequence complete\n");
 
        /* Disable the sequencer again if we enabled it */
        snd_soc_write(codec, WM8903_WRITE_SEQUENCER_0, reg[0]);
@@ -422,7 +421,6 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol,
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
        struct snd_soc_codec *codec = widget->codec;
        struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
-       struct i2c_client *i2c = codec->control_data;
        u16 reg;
        int ret;
 
@@ -431,7 +429,7 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol,
        /* Turn it off if we're about to enable bypass */
        if (ucontrol->value.integer.value[0]) {
                if (wm8903->class_w_users == 0) {
-                       dev_dbg(&i2c->dev, "Disabling Class W\n");
+                       dev_dbg(codec->dev, "Disabling Class W\n");
                        snd_soc_write(codec, WM8903_CLASS_W_0, reg &
                                     ~(WM8903_CP_DYN_FREQ | WM8903_CP_DYN_V));
                }
@@ -444,14 +442,14 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol,
        /* If we've just disabled the last bypass path turn Class W on */
        if (!ucontrol->value.integer.value[0]) {
                if (wm8903->class_w_users == 1) {
-                       dev_dbg(&i2c->dev, "Enabling Class W\n");
+                       dev_dbg(codec->dev, "Enabling Class W\n");
                        snd_soc_write(codec, WM8903_CLASS_W_0, reg |
                                     WM8903_CP_DYN_FREQ | WM8903_CP_DYN_V);
                }
                wm8903->class_w_users--;
        }
 
-       dev_dbg(&i2c->dev, "Bypass use count now %d\n",
+       dev_dbg(codec->dev, "Bypass use count now %d\n",
                wm8903->class_w_users);
 
        return ret;
@@ -476,6 +474,23 @@ static const DECLARE_TLV_DB_SCALE(drc_tlv_min, 0, 600, 0);
 static const DECLARE_TLV_DB_SCALE(drc_tlv_max, 1200, 600, 0);
 static const DECLARE_TLV_DB_SCALE(drc_tlv_startup, -300, 50, 0);
 
+static const char *hpf_mode_text[] = {
+       "Hi-fi", "Voice 1", "Voice 2", "Voice 3"
+};
+
+static const struct soc_enum hpf_mode =
+       SOC_ENUM_SINGLE(WM8903_ADC_DIGITAL_0, 5, 4, hpf_mode_text);
+
+static const char *osr_text[] = {
+       "Low power", "High performance"
+};
+
+static const struct soc_enum adc_osr =
+       SOC_ENUM_SINGLE(WM8903_ANALOGUE_ADC_0, 0, 2, osr_text);
+
+static const struct soc_enum dac_osr =
+       SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_1, 0, 2, osr_text);
+
 static const char *drc_slope_text[] = {
        "1", "1/2", "1/4", "1/8", "1/16", "0"
 };
@@ -614,6 +629,9 @@ SOC_SINGLE("Right Input PGA Common Mode Switch", WM8903_ANALOGUE_RIGHT_INPUT_1,
           6, 1, 0),
 
 /* ADCs */
+SOC_ENUM("ADC OSR", adc_osr),
+SOC_SINGLE("HPF Switch", WM8903_ADC_DIGITAL_0, 4, 1, 0),
+SOC_ENUM("HPF Mode", hpf_mode),
 SOC_SINGLE("DRC Switch", WM8903_DRC_0, 15, 1, 0),
 SOC_ENUM("DRC Compressor Slope R0", drc_slope_r0),
 SOC_ENUM("DRC Compressor Slope R1", drc_slope_r1),
@@ -643,6 +661,7 @@ SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8903_DAC_DIGITAL_0, 4, 8,
               12, 0, digital_sidetone_tlv),
 
 /* DAC */
+SOC_ENUM("DAC OSR", dac_osr),
 SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8903_DAC_DIGITAL_VOLUME_LEFT,
                 WM8903_DAC_DIGITAL_VOLUME_RIGHT, 1, 120, 0, digital_tlv),
 SOC_ENUM("DAC Soft Mute Rate", soft_mute),
@@ -924,10 +943,11 @@ static const struct snd_soc_dapm_route intercon[] = {
 
 static int wm8903_add_widgets(struct snd_soc_codec *codec)
 {
-       snd_soc_dapm_new_controls(codec, wm8903_dapm_widgets,
-                                 ARRAY_SIZE(wm8903_dapm_widgets));
+       struct snd_soc_dapm_context *dapm = &codec->dapm;
 
-       snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
+       snd_soc_dapm_new_controls(dapm, wm8903_dapm_widgets,
+                                 ARRAY_SIZE(wm8903_dapm_widgets));
+       snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
 
        return 0;
 }
@@ -935,7 +955,6 @@ static int wm8903_add_widgets(struct snd_soc_codec *codec)
 static int wm8903_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
-       struct i2c_client *i2c = codec->control_data;
        u16 reg, reg2;
 
        switch (level) {
@@ -948,7 +967,7 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
                break;
 
        case SND_SOC_BIAS_STANDBY:
-               if (codec->bias_level == SND_SOC_BIAS_OFF) {
+               if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
                        snd_soc_write(codec, WM8903_CLOCK_RATES_2,
                                     WM8903_CLK_SYS_ENA);
 
@@ -974,7 +993,7 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
                        /* By default no bypass paths are enabled so
                         * enable Class W support.
                         */
-                       dev_dbg(&i2c->dev, "Enabling Class W\n");
+                       dev_dbg(codec->dev, "Enabling Class W\n");
                        snd_soc_write(codec, WM8903_CLASS_W_0, reg |
                                     WM8903_CP_DYN_FREQ | WM8903_CP_DYN_V);
                }
@@ -993,7 +1012,7 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
                break;
        }
 
-       codec->bias_level = level;
+       codec->dapm.bias_level = level;
 
        return 0;
 }
@@ -1228,10 +1247,8 @@ static int wm8903_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 snd_soc_codec *codec = rtd->codec;
        struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
-       struct i2c_client *i2c = codec->control_data;
        struct snd_pcm_runtime *master_runtime;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -1245,7 +1262,7 @@ static int wm8903_startup(struct snd_pcm_substream *substream,
        if (wm8903->master_substream) {
                master_runtime = wm8903->master_substream->runtime;
 
-               dev_dbg(&i2c->dev, "Constraining to %d bits\n",
+               dev_dbg(codec->dev, "Constraining to %d bits\n",
                        master_runtime->sample_bits);
 
                snd_pcm_hw_constraint_minmax(substream->runtime,
@@ -1264,8 +1281,7 @@ static void wm8903_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;
        struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -1284,10 +1300,8 @@ static int wm8903_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 wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
-       struct i2c_client *i2c = codec->control_data;
        int fs = params_rate(params);
        int bclk;
        int bclk_div;
@@ -1306,7 +1320,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
        u16 dac_digital1 = snd_soc_read(codec, WM8903_DAC_DIGITAL_1);
 
        if (substream == wm8903->slave_substream) {
-               dev_dbg(&i2c->dev, "Ignoring hw_params for slave substream\n");
+               dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n");
                return 0;
        }
 
@@ -1332,7 +1346,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
                switch (sample_rates[dsp_config].rate) {
                case 88200:
                case 96000:
-                       dev_err(&i2c->dev, "%dHz unsupported by ADC\n",
+                       dev_err(codec->dev, "%dHz unsupported by ADC\n",
                                fs);
                        return -EINVAL;
 
@@ -1340,7 +1354,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
                        break;
                }
 
-       dev_dbg(&i2c->dev, "DSP fs = %dHz\n", sample_rates[dsp_config].rate);
+       dev_dbg(codec->dev, "DSP fs = %dHz\n", sample_rates[dsp_config].rate);
        clock1 &= ~WM8903_SAMPLE_RATE_MASK;
        clock1 |= sample_rates[dsp_config].value;
 
@@ -1366,7 +1380,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
-       dev_dbg(&i2c->dev, "MCLK = %dHz, target sample rate = %dHz\n",
+       dev_dbg(codec->dev, "MCLK = %dHz, target sample rate = %dHz\n",
                wm8903->sysclk, fs);
 
        /* We may not have an MCLK which allows us to generate exactly
@@ -1401,12 +1415,12 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
        clock1 |= clk_sys_ratios[clk_config].rate << WM8903_CLK_SYS_RATE_SHIFT;
        clock1 |= clk_sys_ratios[clk_config].mode << WM8903_CLK_SYS_MODE_SHIFT;
 
-       dev_dbg(&i2c->dev, "CLK_SYS_RATE=%x, CLK_SYS_MODE=%x div=%d\n",
+       dev_dbg(codec->dev, "CLK_SYS_RATE=%x, CLK_SYS_MODE=%x div=%d\n",
                clk_sys_ratios[clk_config].rate,
                clk_sys_ratios[clk_config].mode,
                clk_sys_ratios[clk_config].div);
 
-       dev_dbg(&i2c->dev, "Actual CLK_SYS = %dHz\n", clk_sys);
+       dev_dbg(codec->dev, "Actual CLK_SYS = %dHz\n", clk_sys);
 
        /* We may not get quite the right frequency if using
         * approximate clocks so look for the closest match that is
@@ -1428,7 +1442,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
        aif2 &= ~WM8903_BCLK_DIV_MASK;
        aif3 &= ~WM8903_LRCLK_RATE_MASK;
 
-       dev_dbg(&i2c->dev, "BCLK ratio %d for %dHz - actual BCLK = %dHz\n",
+       dev_dbg(codec->dev, "BCLK ratio %d for %dHz - actual BCLK = %dHz\n",
                bclk_divs[bclk_div].ratio / 10, bclk,
                (clk_sys * 10) / bclk_divs[bclk_div].ratio);
 
@@ -1504,8 +1518,8 @@ EXPORT_SYMBOL_GPL(wm8903_mic_detect);
 
 static irqreturn_t wm8903_irq(int irq, void *data)
 {
-       struct wm8903_priv *wm8903 = data;
-       struct snd_soc_codec *codec = &wm8903->codec;
+       struct snd_soc_codec *codec = data;
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
        int mic_report;
        int int_pol;
        int int_val = 0;
@@ -1586,8 +1600,8 @@ static struct snd_soc_dai_ops wm8903_dai_ops = {
        .set_sysclk     = wm8903_set_dai_sysclk,
 };
 
-struct snd_soc_dai wm8903_dai = {
-       .name = "WM8903",
+static struct snd_soc_dai_driver wm8903_dai = {
+       .name = "wm8903-hifi",
        .playback = {
                .stream_name = "Playback",
                .channels_min = 2,
@@ -1605,23 +1619,16 @@ struct snd_soc_dai wm8903_dai = {
        .ops = &wm8903_dai_ops,
        .symmetric_rates = 1,
 };
-EXPORT_SYMBOL_GPL(wm8903_dai);
 
-static int wm8903_suspend(struct platform_device *pdev, pm_message_t state)
+static int wm8903_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;
-
        wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
 
        return 0;
 }
 
-static int wm8903_resume(struct platform_device *pdev)
+static int wm8903_resume(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
-       struct i2c_client *i2c = codec->control_data;
        int i;
        u16 *reg_cache = codec->reg_cache;
        u16 *tmp_cache = kmemdup(reg_cache, sizeof(wm8903_reg_defaults),
@@ -1637,65 +1644,37 @@ static int wm8903_resume(struct platform_device *pdev)
                                snd_soc_write(codec, i, tmp_cache[i]);
                kfree(tmp_cache);
        } else {
-               dev_err(&i2c->dev, "Failed to allocate temporary cache\n");
+               dev_err(codec->dev, "Failed to allocate temporary cache\n");
        }
 
        return 0;
 }
 
-static struct snd_soc_codec *wm8903_codec;
-
-static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
-                                     const struct i2c_device_id *id)
+static int wm8903_probe(struct snd_soc_codec *codec)
 {
-       struct wm8903_platform_data *pdata = dev_get_platdata(&i2c->dev);
-       struct wm8903_priv *wm8903;
-       struct snd_soc_codec *codec;
+       struct wm8903_platform_data *pdata = dev_get_platdata(codec->dev);
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
        int ret, i;
        int trigger, irq_pol;
        u16 val;
 
-       wm8903 = kzalloc(sizeof(struct wm8903_priv), GFP_KERNEL);
-       if (wm8903 == NULL)
-               return -ENOMEM;
-
-       codec = &wm8903->codec;
-
-       mutex_init(&codec->mutex);
-       INIT_LIST_HEAD(&codec->dapm_widgets);
-       INIT_LIST_HEAD(&codec->dapm_paths);
-
-       codec->dev = &i2c->dev;
-       codec->name = "WM8903";
-       codec->owner = THIS_MODULE;
-       codec->bias_level = SND_SOC_BIAS_OFF;
-       codec->set_bias_level = wm8903_set_bias_level;
-       codec->dai = &wm8903_dai;
-       codec->num_dai = 1;
-       codec->reg_cache_size = ARRAY_SIZE(wm8903->reg_cache);
-       codec->reg_cache = &wm8903->reg_cache[0];
-       snd_soc_codec_set_drvdata(codec, wm8903);
-       codec->volatile_register = wm8903_volatile_register;
        init_completion(&wm8903->wseq);
 
-       i2c_set_clientdata(i2c, codec);
-       codec->control_data = i2c;
-
        ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
        if (ret != 0) {
-               dev_err(&i2c->dev, "Failed to set cache I/O: %d\n", ret);
-               goto err;
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               return ret;
        }
 
        val = snd_soc_read(codec, WM8903_SW_RESET_AND_ID);
        if (val != wm8903_reg_defaults[WM8903_SW_RESET_AND_ID]) {
-               dev_err(&i2c->dev,
+               dev_err(codec->dev,
                        "Device with ID register %x is not a WM8903\n", val);
                return -ENODEV;
        }
 
        val = snd_soc_read(codec, WM8903_REVISION_NUMBER);
-       dev_info(&i2c->dev, "WM8903 revision %d\n",
+       dev_info(codec->dev, "WM8903 revision %d\n",
                 val & WM8903_CHIP_REV_MASK);
 
        wm8903_reset(codec);
@@ -1721,7 +1700,7 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
                wm8903->mic_delay = pdata->micdet_delay;
        }
        
-       if (i2c->irq) {
+       if (wm8903->irq) {
                if (pdata && pdata->irq_active_low) {
                        trigger = IRQF_TRIGGER_LOW;
                        irq_pol = WM8903_IRQ_POL;
@@ -1733,13 +1712,13 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
                snd_soc_update_bits(codec, WM8903_INTERRUPT_CONTROL,
                                    WM8903_IRQ_POL, irq_pol);
                
-               ret = request_threaded_irq(i2c->irq, NULL, wm8903_irq,
+               ret = request_threaded_irq(wm8903->irq, NULL, wm8903_irq,
                                           trigger | IRQF_ONESHOT,
-                                          "wm8903", wm8903);
+                                          "wm8903", codec);
                if (ret != 0) {
-                       dev_err(&i2c->dev, "Failed to request IRQ: %d\n",
+                       dev_err(codec->dev, "Failed to request IRQ: %d\n",
                                ret);
-                       goto err;
+                       return ret;
                }
 
                /* Enable write sequencer interrupts */
@@ -1781,133 +1760,96 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
        val |= WM8903_DAC_MUTEMODE;
        snd_soc_write(codec, WM8903_DAC_DIGITAL_1, val);
 
-       wm8903_dai.dev = &i2c->dev;
-       wm8903_codec = codec;
-
-       ret = snd_soc_register_codec(codec);
-       if (ret != 0) {
-               dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
-               goto err_irq;
-       }
-
-       ret = snd_soc_register_dai(&wm8903_dai);
-       if (ret != 0) {
-               dev_err(&i2c->dev, "Failed to register DAI: %d\n", ret);
-               goto err_codec;
-       }
-
-       return ret;
+       snd_soc_add_controls(codec, wm8903_snd_controls,
+                               ARRAY_SIZE(wm8903_snd_controls));
+       wm8903_add_widgets(codec);
 
-err_codec:
-       snd_soc_unregister_codec(codec);
-err_irq:
-       if (i2c->irq)
-               free_irq(i2c->irq, wm8903);
-err:
-       wm8903_codec = NULL;
-       kfree(wm8903);
        return ret;
 }
 
-static __devexit int wm8903_i2c_remove(struct i2c_client *client)
+/* power down chip */
+static int wm8903_remove(struct snd_soc_codec *codec)
 {
-       struct snd_soc_codec *codec = i2c_get_clientdata(client);
-       struct wm8903_priv *priv = snd_soc_codec_get_drvdata(codec);
+       wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
+}
 
-       snd_soc_unregister_dai(&wm8903_dai);
-       snd_soc_unregister_codec(codec);
+static struct snd_soc_codec_driver soc_codec_dev_wm8903 = {
+       .probe =        wm8903_probe,
+       .remove =       wm8903_remove,
+       .suspend =      wm8903_suspend,
+       .resume =       wm8903_resume,
+       .set_bias_level = wm8903_set_bias_level,
+       .reg_cache_size = ARRAY_SIZE(wm8903_reg_defaults),
+       .reg_word_size = sizeof(u16),
+       .reg_cache_default = wm8903_reg_defaults,
+       .volatile_register = wm8903_volatile_register,
+};
 
-       wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
+                                     const struct i2c_device_id *id)
+{
+       struct wm8903_priv *wm8903;
+       int ret;
 
-       if (client->irq)
-               free_irq(client->irq, priv);
+       wm8903 = kzalloc(sizeof(struct wm8903_priv), GFP_KERNEL);
+       if (wm8903 == NULL)
+               return -ENOMEM;
 
-       kfree(priv);
+       i2c_set_clientdata(i2c, wm8903);
+       wm8903->irq = i2c->irq;
 
-       wm8903_codec = NULL;
-       wm8903_dai.dev = NULL;
+       ret = snd_soc_register_codec(&i2c->dev,
+                       &soc_codec_dev_wm8903, &wm8903_dai, 1);
+       if (ret < 0)
+               kfree(wm8903);
+       return ret;
+}
 
+static __devexit int wm8903_i2c_remove(struct i2c_client *client)
+{
+       snd_soc_unregister_codec(&client->dev);
+       kfree(i2c_get_clientdata(client));
        return 0;
 }
 
-/* i2c codec control layer */
 static const struct i2c_device_id wm8903_i2c_id[] = {
-       { "wm8903", 0 },
-       { }
+       { "wm8903", 0 },
+       { }
 };
 MODULE_DEVICE_TABLE(i2c, wm8903_i2c_id);
 
 static struct i2c_driver wm8903_i2c_driver = {
        .driver = {
-               .name = "WM8903",
+               .name = "wm8903-codec",
                .owner = THIS_MODULE,
        },
-       .probe    = wm8903_i2c_probe,
-       .remove   = __devexit_p(wm8903_i2c_remove),
+       .probe =    wm8903_i2c_probe,
+       .remove =   __devexit_p(wm8903_i2c_remove),
        .id_table = wm8903_i2c_id,
 };
+#endif
 
-static int wm8903_probe(struct platform_device *pdev)
+static int __init wm8903_modinit(void)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        int ret = 0;
-
-       if (!wm8903_codec) {
-               dev_err(&pdev->dev, "I2C device not yet probed\n");
-               goto err;
-       }
-
-       socdev->card->codec = wm8903_codec;
-
-       /* 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");
-               goto err;
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       ret = i2c_add_driver(&wm8903_i2c_driver);
+       if (ret != 0) {
+               printk(KERN_ERR "Failed to register wm8903 I2C driver: %d\n",
+                      ret);
        }
-
-       snd_soc_add_controls(socdev->card->codec, wm8903_snd_controls,
-                               ARRAY_SIZE(wm8903_snd_controls));
-       wm8903_add_widgets(socdev->card->codec);
-
+#endif
        return ret;
-
-err:
-       return ret;
-}
-
-/* power down chip */
-static int wm8903_remove(struct platform_device *pdev)
-{
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
-
-       if (codec->control_data)
-               wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
-
-       snd_soc_free_pcms(socdev);
-       snd_soc_dapm_free(socdev);
-
-       return 0;
-}
-
-struct snd_soc_codec_device soc_codec_dev_wm8903 = {
-       .probe =        wm8903_probe,
-       .remove =       wm8903_remove,
-       .suspend =      wm8903_suspend,
-       .resume =       wm8903_resume,
-};
-EXPORT_SYMBOL_GPL(soc_codec_dev_wm8903);
-
-static int __init wm8903_modinit(void)
-{
-       return i2c_add_driver(&wm8903_i2c_driver);
 }
 module_init(wm8903_modinit);
 
 static void __exit wm8903_exit(void)
 {
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
        i2c_del_driver(&wm8903_i2c_driver);
+#endif
 }
 module_exit(wm8903_exit);
 
This page took 0.031598 seconds and 5 git commands to generate.