Merge commit 'v2.6.27-rc5' into tip/oprofile
[safe/jmp/linux-2.6] / sound / soc / codecs / wm8750.c
index 62423f4..dd1f554 100644 (file)
 #define AUDIO_NAME "WM8750"
 #define WM8750_VERSION "0.12"
 
-/*
- * Debug
- */
-
-#define WM8750_DEBUG 0
-
-#ifdef WM8750_DEBUG
-#define dbg(format, arg...) \
-       printk(KERN_DEBUG AUDIO_NAME ": " format "\n" , ## arg)
-#else
-#define dbg(format, arg...) do {} while (0)
-#endif
-#define err(format, arg...) \
-       printk(KERN_ERR AUDIO_NAME ": " format "\n" , ## arg)
-#define info(format, arg...) \
-       printk(KERN_INFO AUDIO_NAME ": " format "\n" , ## arg)
-#define warn(format, arg...) \
-       printk(KERN_WARNING AUDIO_NAME ": " format "\n" , ## arg)
-
 /* codec private data */
 struct wm8750_priv {
        unsigned int sysclk;
@@ -367,8 +348,9 @@ static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
        SND_SOC_DAPM_OUTPUT("ROUT1"),
        SND_SOC_DAPM_OUTPUT("LOUT2"),
        SND_SOC_DAPM_OUTPUT("ROUT2"),
-       SND_SOC_DAPM_OUTPUT("MONO"),
+       SND_SOC_DAPM_OUTPUT("MONO1"),
        SND_SOC_DAPM_OUTPUT("OUT3"),
+       SND_SOC_DAPM_OUTPUT("VREF"),
 
        SND_SOC_DAPM_INPUT("LINPUT1"),
        SND_SOC_DAPM_INPUT("LINPUT2"),
@@ -378,7 +360,7 @@ static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
        SND_SOC_DAPM_INPUT("RINPUT3"),
 };
 
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
        /* left mixer */
        {"Left Mixer", "Playback Switch", "Left DAC"},
        {"Left Mixer", "Left Bypass Switch", "Left Line Mux"},
@@ -470,22 +452,14 @@ static const char *audio_map[][3] = {
        /* ADC */
        {"Left ADC", NULL, "Left ADC Mux"},
        {"Right ADC", NULL, "Right ADC Mux"},
-
-       /* terminator */
-       {NULL, NULL, NULL},
 };
 
 static int wm8750_add_widgets(struct snd_soc_codec *codec)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
+                                 ARRAY_SIZE(wm8750_dapm_widgets));
 
-       /* set up audio path audio_mapnects */
-       for (i = 0; audio_map[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
        snd_soc_dapm_new_widgets(codec);
        return 0;
@@ -563,7 +537,7 @@ static inline int get_coeff(int mclk, int rate)
        return -EINVAL;
 }
 
-static int wm8750_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+static int wm8750_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;
@@ -581,7 +555,7 @@ static int wm8750_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
        return -EINVAL;
 }
 
-static int wm8750_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8750_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -674,7 +648,7 @@ static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream,
        return 0;
 }
 
-static int wm8750_mute(struct snd_soc_codec_dai *dai, int mute)
+static int wm8750_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
        u16 mute_reg = wm8750_read_reg_cache(codec, WM8750_ADCDAC) & 0xfff7;
@@ -719,7 +693,7 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
 #define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
        SNDRV_PCM_FMTBIT_S24_LE)
 
-struct snd_soc_codec_dai wm8750_dai = {
+struct snd_soc_dai wm8750_dai = {
        .name = "WM8750",
        .playback = {
                .stream_name = "Playback",
@@ -806,7 +780,7 @@ static int wm8750_init(struct snd_soc_device *socdev)
        codec->set_bias_level = wm8750_set_bias_level;
        codec->dai = &wm8750_dai;
        codec->num_dai = 1;
-       codec->reg_cache_size = sizeof(wm8750_reg);
+       codec->reg_cache_size = ARRAY_SIZE(wm8750_reg);
        codec->reg_cache = kmemdup(wm8750_reg, sizeof(wm8750_reg), GFP_KERNEL);
        if (codec->reg_cache == NULL)
                return -ENOMEM;
@@ -895,28 +869,26 @@ static int wm8750_codec_probe(struct i2c_adapter *adap, int addr, int kind)
        client_template.addr = addr;
 
        i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
-       if (i2c == NULL) {
-               kfree(codec);
+       if (i2c == NULL)
                return -ENOMEM;
-       }
+
        i2c_set_clientdata(i2c, codec);
        codec->control_data = i2c;
 
        ret = i2c_attach_client(i2c);
        if (ret < 0) {
-               err("failed to attach codec at addr %x\n", addr);
+               pr_err("failed to attach codec at addr %x\n", addr);
                goto err;
        }
 
        ret = wm8750_init(socdev);
        if (ret < 0) {
-       err("failed to initialise WM8750\n");
+               pr_err("failed to initialise WM8750\n");
                goto err;
        }
        return ret;
 
 err:
-       kfree(codec);
        kfree(i2c);
        return ret;
 }
@@ -961,7 +933,7 @@ static int wm8750_probe(struct platform_device *pdev)
        struct wm8750_priv *wm8750;
        int ret = 0;
 
-       info("WM8750 Audio Codec %s", WM8750_VERSION);
+       pr_info("WM8750 Audio Codec %s", WM8750_VERSION);
        codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
        if (codec == NULL)
                return -ENOMEM;
@@ -992,6 +964,10 @@ static int wm8750_probe(struct platform_device *pdev)
                /* Add other interfaces here */
 #endif
 
+       if (ret != 0) {
+               kfree(codec->private_data);
+               kfree(codec);
+       }
        return ret;
 }